Skip to content

PluginCommands

Registers commands. A command is an action that has a name. The person can run it from the command palette, from a menu or with a keyboard shortcut. register creates a command, and core holds the commands that come with the app.

A command that adds one work session to a row

const sessions = ctx.facets.define<number>({
key: 'com.example.pomodoro/sessions',
on: 'row',
merge: 'counter',
schema: { type: 'integer', minimum: 0 },
});
const addSession = ctx.commands.register<{ id: string }>({
id: 'com.example.pomodoro/add-session',
title: 'Add a work session',
placements: ['row-menu'],
args: { type: 'object', properties: { id: { type: 'string' } }, required: ['id'] },
propose(state, args, draft) {
const row = state.row(args.id);
if (!row) throw new Error(`There is no row ${args.id}`);
draft.facet(args.id, sessions).set((sessions.of(row) ?? 0) + 1);
return draft;
},
});
readonly core: Readonly<{
audit: Readonly<{
grant: Command<{
epoch: number;
keys: string;
outline: string;
to: string[];
}>;
}>;
core: Readonly<{
createOutline: Command<{
area?: string | null;
id?: string;
note?: string;
title?: string;
}>;
deleteRows: Command<{
ids: string[];
}>;
insertRow: Command<{
anchor?: string | null;
facets?: Record<string, unknown>;
how?: "after" | "before" | "child";
id?: string;
marker?: Marker;
note?: string | null;
outline: string;
title?: string;
}>;
modifyOutline: Command<{
archived?: boolean;
id: string;
note?: string;
starred?: boolean;
title?: string;
}>;
modifyRow: Command<{
id: string;
marker?: Marker;
note?: string | null;
title?: string;
}>;
moveRow: Command<{
id: string;
target: string;
where: "after" | "first" | "before" | "inside";
}>;
moveRowToOutline: Command<{
id: string;
outline: string;
}>;
redo: Command<{
scope?: string;
}>;
removeFacet: Command<{
key: string;
target: Target;
}>;
setFacet: Command<{
key: string;
target: Target;
value: unknown;
}>;
undo: Command<{
scope?: string;
}>;
}>;
journal: Readonly<{
leaveEntry: Command<{
id: string;
}>;
setDay: Command<{
day: string;
id: string;
}>;
setJournal: Command<{
on: boolean;
outline: string;
}>;
}>;
links: Readonly<{
link: Command<{
field: "title" | "note";
id: string;
name: string;
outline: string;
text: string;
}>;
}>;
media: Readonly<{
addAttachment: Command<{
attachment: Attachment;
id: string;
}>;
removeAttachment: Command<{
attachment: string;
id: string;
}>;
updateAttachment: Command<{
attachment: Attachment;
id: string;
}>;
}>;
numbering: Readonly<{
numberAll: Command<{
outline: string;
}>;
numberList: Command<{
id: string;
on: boolean;
}>;
numberRows: Command<{
ids: string[];
on: boolean;
}>;
numberSection: Command<{
id: string;
on: boolean;
}>;
}>;
schedule: Readonly<{
advance: Command<{
id: string;
}>;
clear: Command<{
field?: "when" | "due";
id: string;
reopen?: boolean;
}>;
dismissAlert: Command<{
id: string;
}>;
moveOccurrence: Command<{
id: string;
reopen?: boolean;
}>;
setAlert: Command<{
id: string;
minutes: number | null;
reopen?: boolean;
}>;
setDate: Command<{
date: string | null;
field: "when" | "due";
id: string;
reopen?: boolean;
time?: string;
}>;
setRepeat: Command<{
id: string;
reopen?: boolean;
rule: string | null;
settle?: boolean;
}>;
setRepeatFrom: Command<{
from: "schedule" | "completion";
id: string;
}>;
setTime: Command<{
field: "when" | "due";
id: string;
reopen?: boolean;
time: string | null;
}>;
snoozeAlert: Command<{
id: string;
minutes: number;
}>;
}>;
sharing: Readonly<{
assign: Command<{
id: string;
person?: string;
}>;
}>;
tags: Readonly<{
addTag: Command<{
id: string;
tag: string;
}>;
removeTag: Command<{
id: string;
tag: string;
}>;
renameTag: Command<{
from: string;
to: string | null;
}>;
}>;
tasks: Readonly<{
complete: Command<{
id: string;
}>;
setPriority: Command<{
id: string;
priority: "high" | "normal" | "low";
}>;
setShowDone: Command<{
on: boolean;
outline: string;
}>;
setStatus: Command<{
id: string;
status: "cancelled" | "done" | "open";
}>;
setTask: Command<{
id: string;
on: boolean;
}>;
toggleAll: Command<{
outline: string;
}>;
}>;
views: Readonly<{
addColumn: Command<{
name: string;
outline: string;
type: "number" | "text" | "status" | "date" | "crm";
}>;
moveColumn: Command<{
before: string | null;
column: string;
outline: string;
}>;
pasteColumn: Command<{
after: string;
before: string;
column: string | null;
id: string;
names?: Record<string, string>;
text: string;
}>;
removeColumn: Command<{
column: string;
outline: string;
}>;
setCell: Command<{
column: string;
id: string;
value: string;
}>;
setPresentation: Command<{
outline: string;
presentation: string;
}>;
setTitleColumn: Command<{
name?: string;
outline: string;
width?: number | null;
}>;
updateColumn: Command<{
column: string;
name?: string;
outline: string;
type?: "number" | "text" | "status" | "date" | "crm";
width?: number | null;
}>;
}>;
}>;

The commands that come with the app. ctx.commands.core.tasks.setTask({ id, on }) builds the request for one of them. The command property of a command is its id.

register<A>(declaration): object;

Creates a command. Each run of the command is one step of undo.

Type Parameter Default type Description
A never the type of the arguments of the command
Parameter Type Description
declaration CommandDeclaration<A> describes the command: its id, written <plugin id>/<name>, its title, the arguments that it accepts (args, written as a JSON Schema), a can function that says whether the command can be used in the current context, and a propose function that says which change the command makes. It can also have placements (where the command appears), icon, shortcut, undoName and discardable

object

an object with the id of the command, intent(args), which builds the request without running it, and dispose(), which removes the command

Name Type
id string
dispose() () => void
intent() (args) => Intent