CommandDeclaration
The description of a command that a plugin passes to ctx.commands.register.
Example
Section titled “Example”ctx.commands.register({ id: 'com.example.cleanup/uppercase', title: 'Make the title uppercase', args: { type: 'object', properties: { id: { type: 'string' } }, required: ['id'] }, placements: ['row-menu'], can: (state, focus) => (focus.row ? available() : unavailable('Select a row first')), propose: (state, args, draft) => { const row = state.row(args.id); if (row) draft.update(row.id, { title: row.title.toUpperCase() }); return draft; },});Type Parameters
Section titled “Type Parameters”| Type Parameter | Default type | Description |
|---|---|---|
A |
never |
the type of the arguments of the command |
Properties
Section titled “Properties”readonly args: object;A JSON Schema that describes the arguments of the command.
readonly can?: (state, focus, args) => Availability;States whether the command can be used in the current context.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
state |
StateView |
the state of the library |
focus |
Focus |
the row and the outline that are current |
args |
A | undefined |
the arguments of the command, when they are known |
Returns
Section titled “Returns”available() or unavailable(reason)
discardable?
Section titled “discardable?”readonly discardable?: boolean;When true, the changes of the command are not a step of undo by themselves, and undo goes back past them. An example is an empty journal entry that is left behind.
readonly icon?: string;The name of an icon for the command.
readonly id: string;The id of the command, written <plugin id>/<name>.
placements?
Section titled “placements?”readonly placements?: readonly Placement[];Where the command appears, besides being available by its name.
propose
Section titled “propose”readonly propose: (state, args, draft) => | void | ChangeDraft | DraftBuilder;States which change the command makes.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
state |
StateView |
the state of the library |
args |
A |
the arguments of the command |
draft |
DraftBuilder |
the builder with which to describe the change |
Returns
Section titled “Returns”| void
| ChangeDraft
| DraftBuilder
the builder, or a ChangeDraft
shortcut?
Section titled “shortcut?”readonly shortcut?: string;A keyboard shortcut for the command.
readonly title: string | (() => string);The name that the person reads. It is a text, or a function that the app calls each time it draws the menu, so that the title follows the language of the app.
topics?
Section titled “topics?”readonly topics?: readonly string[];The topics of the deltas that the command makes, for example row.insert. When it is given, the app only calls the hooks that listen to these topics, which saves work.
undoName?
Section titled “undoName?”readonly undoName?: string;The name of the undo step that the command makes, as the Undo menu shows it.
