API / @aionbuilders/nabu/extend

CommandRegistry

Class Stability: stable Stable contract

Holds the commands of an editor (nabu.commands is its public face): registers them from the extensions, resolves the keymap and the key chords at keydown, and answers list, get, has and run.

Note Not exported by name: you reach it through nabu.commands.

Related guide: Commands and keymap →

Import

TypeScript
import { CommandRegistry } from '@aionbuilders/nabu/extend';

Constructor

TypeScript
new CommandRegistry(nabu: Nabu, options?: CommandRegistryOptions)
Parameters of the constructor
ParameterTypeDefaultDescription
nabuNabun/an/a
optionsoptionalCommandRegistryOptions{}n/a

Properties

platform

TypeScript
platform: Platform

Methods

context()

TypeScript
context(event?: KeyboardEvent | null): CommandContext

Build the context a command sees: the core fields, then the facts of the extensions.

Parameters of context
ParameterTypeDefaultDescription
eventoptionalKeyboardEvent | nullnulln/a

get()

TypeScript
get(id: string, ctx?: CommandContext): CommandInfo | null
Parameters of get
ParameterTypeDescription
idstringn/a
ctxoptionalCommandContextn/a

has()

TypeScript
has(id: string): boolean
Parameters of has
ParameterTypeDescription
idstringn/a

invoke()

TypeScript
invoke(entry: CommandEntry, data?: any): any

Run a command from the bus (nabu.exec(id, data)): no key press, ctx.event is null, when is not checked.

Parameters of invoke
ParameterTypeDescription
entryCommandEntryn/a
dataoptionalanyn/a

list()

TypeScript
list(ctx?: CommandContext): CommandInfo[]

Every command, in registration order, as a plain snapshot (for a help sheet, a palette). Function labels and when are evaluated with ctx (default: the current context, event: null).

Parameters of list
ParameterTypeDescription
ctxoptionalCommandContextn/a

offer()

TypeScript
offer(id: string, ctx?: CommandContext): boolean

Open the confirmation of a command from code (a button, a menu, a palette, a typed trigger), as if its key had been pressed where when holds. This is the public way to start a confirmation, since nabu.exec(id) runs at once:

  • the command has a confirm: its prompt opens (hold, invite or choose, see CommandConfirm), exactly as for a key press: nabu.pendingCommand, the CommandInvite / CommandChooser components, keyboard handling and cancellations. Nothing has run yet; the command runs when the user confirms. invite expects its first key again and hold expects its first key to be held (counting from that press); both lapse after the invite timeout (5 s) when no key comes, and need the command to have a key (else nothing opens);
  • the command has NO confirm: there is nothing to ask, so it simply runs, like nabu.exec(id), when checked.

Returns true when a confirmation opened, or when a command without confirmation ran; false when nothing happened: unknown id (warning), when is false, no option for a choose, no key for a hold / invite, or a command without confirmation whose run returned false.

Parameters of offer
ParameterTypeDescription
idstring

command id

ctxoptionalCommandContext

default: the current context (event: null)

run()

TypeScript
run(id: string, data?: any): Promise<PulseEvent> | undefined

Run a command by id, like nabu.exec(id, data) (which it calls).

Parameters of run
ParameterTypeDescription
idstringn/a
dataoptionalanyn/a

Source: src/lib/utils/commands.js:92