Skip to content

plugin-api/CommandRegistry#

baseCommandId()#

function baseCommandId(id): string;

The id without its per-plot suffix: nuclei.peaks.copy-table@plot-3 is nuclei.peaks.copy-table.

Parameters#

Parameter Type
id string

Returns#

string


keyScopesOverlap()#

function keyScopesOverlap(a, b): boolean;

Whether two key scopes can be live at the same moment, so one chord in both is ambiguous.

Parameters#

Parameter Type
a KeyScope | undefined
b KeyScope | undefined

Returns#

boolean


normalizeKeybinding()#

function normalizeKeybinding(binding): string;

Normalise a stored binding so equal chords compare equal.

Args: binding: Mod+Shift+K, mod+[, ?, Esc and so on. ? is read as shift+/.

Returns: Modifiers sorted, the key folded to its canonical token, all lowercase.

Parameters#

Parameter Type
binding string

Returns#

string


resolveCommandLabel()#

function resolveCommandLabel(def): string;

The enforced display name: "{scope}: {command}".

Parameters#

Parameter Type
def CommandDef

Returns#

string


resolveCommandScope()#

function resolveCommandScope(def): string;

The qualifier alone.

Parameters#

Parameter Type
def CommandDef

Returns#

string


resolveCommandTitle()#

function resolveCommandTitle(def): string;

The command part alone, with any accidental scope prefix removed. Titles given as functions are re-evaluated on every read.

Parameters#

Parameter Type
def CommandDef

Returns#

string


useCommands()#

function useCommands(hasCapability?, active?): CommandDef[];

React hook returning the currently-visible commands, re-rendering on any registry change. Live subscription matters: plugins load sequentially and late (after the backend handshake), so commands can register while the palette is already open. With active false (a closed palette) it returns nothing and does not subscribe: every undoable edit bumps the registry.

Parameters#

Parameter Type
hasCapability? (capability) => boolean
active? boolean

Returns#

CommandDef[]


commandsRegistry#

const commandsRegistry: CommandRegistry;

CommandDef#

Properties#

blockedInText?#

optional blockedInText?: boolean;

Not while the user is typing in a field (page navigation chords, which the field may use).

capability?#

optional capability?: string;

Device capability gate, mirroring TuneOperationDef.

capture?#

optional capture?: boolean;

Dispatch in the capture phase, for chords an editor would otherwise consume (mod+k).

category?#

optional category?: string;

extraKeybindings?#

optional extraKeybindings?: string[];

More chords for the same command (mod+y beside mod+shift+z for redo).

icon?#

optional icon?: ComponentType;

id#

id: string;

nuclei.<area>.<verb> for core, plugin:<shortId>.<verb> for plugins.

isEnabled?#

optional isEnabled?: () => boolean;

Display-time predicate — shown greyed out and not invocable.

Returns#

boolean

isVisible?#

optional isVisible?: () => boolean;

Display-time predicate — hidden rows are not listed and cannot be run by key.

Returns#

boolean

keybinding?#

optional keybinding?: string;

e.g. mod+shift+r, or a bare key such as f. Dispatched from one listener so conflicts are detectable.

keyScope?#

optional keyScope?: KeyScope;

Where the keybinding is live. Required for a bare key. NOT scope, which is the display qualifier of the title.

keywords?#

optional keywords?: string[];

order?#

optional order?: number;

plotHostId?#

optional plotHostId?: string;

For a per-plot command: the plot host it belongs to, so only the active plot's runs.

run#

run: () => void | Promise<void>;
Returns#

void | Promise<void>

scope#

scope: string | (() => string);

The qualifier in "{scope}: {command}" — the localized page title for page-bound built-ins, the plugin's display name for plugin commands (injected by the bundle loader's proxy, so a plugin cannot spoof another plugin's scope), or one explicit word for genuinely global commands.

Resolved at DISPLAY time, hence the thunk: page titles are localized and plugin translations can land after the command registers.

title#

title: string | (() => string);

The command part ONLY — "Save as…", never "Reports: Save as…". The "{scope}: {command}" display name is composed by the registry, so authors cannot get the format wrong and cannot skip the scope.

Lazy thunk or plain string. A thunk is required whenever the title comes from i18n: plugin translations register into plugin:${shortId} and can land after the command does, and core titles must re-resolve on a language change. Same pattern as TuneOperationDef.label.


KeybindingConflict#

Properties#

commandIds#

commandIds: string[];

keybinding#

keybinding: string;

KeybindingOverrides#

type KeybindingOverrides = Record<string, string | null>;

The user's chord for a command id: a chord, or null for "unbound".


KeyScope#

type KeyScope = 
  | "global"
  | "plot"
  | "plot1d"
  | "plot2d"
  | `tool:${string}`
  | `editor:${string}`;

Where a keybinding is live.

  • undefined: the app, outside a dialog. Modified chords also work while typing.
  • 'global': also inside a dialog.
  • 'plot', 'plot1d', 'plot2d': only while that plot is the active surface (it, or its sidebar, has focus, or the pointer is over it with nothing focused).
  • 'tool:<id>': only while plot tool <id> is active on the active plot.
  • 'editor:<id>': only while that editor has the keyboard; it suspends plot scope.