CommandRegistry
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
import { CommandRegistry } from '@aionbuilders/nabu/extend';Constructor
new CommandRegistry(nabu: Nabu, options?: CommandRegistryOptions)| Parameter | Type | Default | Description |
|---|---|---|---|
nabu | Nabu | n/a | n/a |
optionsoptional | CommandRegistryOptions | {} | n/a |
Properties
platform
platform: PlatformMethods
context()
context(event?: KeyboardEvent | null): CommandContextBuild the context a command sees: the core fields, then the facts of the extensions.
| Parameter | Type | Default | Description |
|---|---|---|---|
eventoptional | KeyboardEvent | null | null | n/a |
get()
get(id: string, ctx?: CommandContext): CommandInfo | null| Parameter | Type | Description |
|---|---|---|
id | string | n/a |
ctxoptional | CommandContext | n/a |
has()
has(id: string): boolean| Parameter | Type | Description |
|---|---|---|
id | string | n/a |
invoke()
invoke(entry: CommandEntry, data?: any): anyRun a command from the bus (nabu.exec(id, data)): no key press, ctx.event is null, when is not checked.
| Parameter | Type | Description |
|---|---|---|
entry | CommandEntry | n/a |
dataoptional | any | n/a |
list()
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).
| Parameter | Type | Description |
|---|---|---|
ctxoptional | CommandContext | n/a |
offer()
offer(id: string, ctx?: CommandContext): booleanOpen 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,inviteorchoose, seeCommandConfirm), exactly as for a key press:nabu.pendingCommand, theCommandInvite/CommandChoosercomponents, keyboard handling and cancellations. Nothing has run yet; the command runs when the user confirms.inviteexpects its first key again andholdexpects its first key to be held (counting from that press); both lapse after theinvitetimeout (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, likenabu.exec(id),whenchecked.
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.
| Parameter | Type | Description |
|---|---|---|
id | string | command id |
ctxoptional | CommandContext | default: the current context ( |
run()
run(id: string, data?: any): Promise<PulseEvent> | undefinedRun a command by id, like nabu.exec(id, data) (which it calls).
| Parameter | Type | Description |
|---|---|---|
id | string | n/a |
dataoptional | any | n/a |
Source: src/lib/utils/commands.js:92