Skip to content

CommandDeclaration

The description of a command that a plugin passes to ctx.commands.register.

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 Parameter Default type Description
A never the type of the arguments of the command
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.

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

Availability

available() or unavailable(reason)


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>.


readonly placements?: readonly Placement[];

Where the command appears, besides being available by its name.


readonly propose: (state, args, draft) =>
| void
| ChangeDraft
| DraftBuilder;

States which change the command makes.

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

| void | ChangeDraft | DraftBuilder

the builder, or a ChangeDraft


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.


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.


readonly undoName?: string;

The name of the undo step that the command makes, as the Undo menu shows it.