PluginUi
Talks to the person, and adds elements to the screen. The questions (confirm, prompt, password, pick) return a promise with the answer, and a question never blocks a change that is in progress. The other methods add elements to the screen: a message, a card with a progress bar, an entry in the sidebar, a panel, a new way of displaying an outline, an item in the / menu, and small marks on rows. The panels and the outline types are drawn from components such as stack, text, board and card, which are methods of this object. Requires ui.
Example
Section titled “Example”Ask a question, then show a message
const answer = await ctx.ui.confirm({ title: 'Archive this outline?', message: 'You can restore it later.', action: 'Archive',});if (answer.confirmed) ctx.ui.notice({ text: 'Archived' });Extends
Section titled “Extends”Methods
Section titled “Methods”alert()
Section titled “alert()”alert(definition): object;Shows a card over the page. The card can have a progress bar: progress goes from 0 to 1, and the card has no bar when progress is left out. The card stays until the plugin calls dispose.
detail is a small line below the text, and actions are up to four buttons, each of which runs a command of the plugin.
When the plugin calls update, a detail that is left out stays as it is, and undefined removes it. actions replace the old buttons, and undefined removes them.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
definition |
{ actions?: readonly AlertAction[]; detail?: string; icon?: string; id: string; progress?: number; text: string; } |
id identifies the card, text is its message, detail is the small line below it, progress is the progress bar, icon is an optional icon, and actions is the list of buttons |
definition.actions? |
readonly AlertAction[] |
- |
definition.detail? |
string |
- |
definition.icon? |
string |
- |
definition.id |
string |
- |
definition.progress? |
number |
- |
definition.text |
string |
- |
Returns
Section titled “Returns”object
an object with update(patch), which changes the card, and dispose(), which removes it
| Name | Type |
|---|---|
dispose() |
() => void |
update() |
(patch) => void |
Example
Section titled “Example”const card = ctx.ui.alert({ id: 'import', text: 'Importing', progress: 0 });card.update({ progress: 0.5 });card.dispose();board()
Section titled “board()”board(props, children): PanelNode;Displays a board: a row of columns that hold cards, which the person can drag from one column to another.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
props |
{ add?: PanelHandler<{ }>; addTitle?: string; } |
add is invoked when the person presses the button that creates a column, and addTitle is the text of that button. |
props.add? |
PanelHandler<{ }> |
- |
props.addTitle? |
string |
- |
children |
Children |
the columns of the board, made with column |
Returns
Section titled “Returns”the node
Inherited from
Section titled “Inherited from”button()
Section titled “button()”button(props): PanelNode;Displays a button. Pressing it invokes action, or runs the request given as intent. The optional role, which is either destructive or cancel, adjusts the appearance of the button.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
props |
Pressable & object |
title is the text of the button, role adjusts its appearance, and action or intent is what happens when it is pressed. |
Returns
Section titled “Returns”the node
Inherited from
Section titled “Inherited from”card()
Section titled “card()”card(props): PanelNode;Displays one card of a column. Most properties are handlers: tap is invoked with { card } when the card is pressed, open with { card } when its title is double-clicked, edit with { card, title } when the person has typed a new title, and drag with { card, column, before } when the card is dragged and dropped on a column or on another card. While editing is true, the title is displayed as an editable field.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
props |
{ done?: boolean; drag?: PanelHandler<{ before?: string; card: string; column?: string; }>; edit?: PanelHandler<{ card: string; title: string; }>; editing?: boolean; id: string; open?: PanelHandler<{ card: string; }>; subtitle?: string; tap?: PanelHandler<{ card: string; }>; title: string; } |
id identifies the card, title is its text, subtitle is an optional second line, done marks the card as completed, and tap, open, edit, drag and editing are described above. |
props.done? |
boolean |
- |
props.drag? |
PanelHandler<{ before?: string; card: string; column?: string; }> |
- |
props.edit? |
PanelHandler<{ card: string; title: string; }> |
- |
props.editing? |
boolean |
- |
props.id |
string |
- |
props.open? |
PanelHandler<{ card: string; }> |
- |
props.subtitle? |
string |
- |
props.tap? |
PanelHandler<{ card: string; }> |
- |
props.title |
string |
- |
Returns
Section titled “Returns”the node
Inherited from
Section titled “Inherited from”chart()
Section titled “chart()”chart(props): PanelNode;Displays a chart, drawn as bars or as lines depending on kind. Each entry of series supplies a list of numbers and, optionally, a label.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
props |
{ kind?: "bar" | "line"; label?: string; series: readonly object[]; } |
kind is bar or line, label is an optional title, and series is the list of data series. |
props.kind? |
"bar" | "line" |
- |
props.label? |
string |
- |
props.series |
readonly object[] |
- |
Returns
Section titled “Returns”the node
Inherited from
Section titled “Inherited from”column()
Section titled “column()”column(props, children): PanelNode;Displays one column of a board, with a header that shows its title and, optionally, the number of cards. Most properties are handlers: drop is invoked with { card, column } when a card is dropped on the column, add with { column } when the person presses the + button, open with { column } when the title is double-clicked, and edit with { column, title } when the person has typed a new title. While editing is true, the title is displayed as an editable field.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
props |
{ add?: PanelHandler<{ column: string; }>; count?: number; drop?: PanelHandler<{ card: string; column: string; }>; edit?: PanelHandler<{ column: string; title: string; }>; editing?: boolean; id: string; open?: PanelHandler<{ column: string; }>; title: string; } |
id identifies the column, title and count appear in its header, and drop, add, open, edit and editing are described above. |
props.add? |
PanelHandler<{ column: string; }> |
- |
props.count? |
number |
- |
props.drop? |
PanelHandler<{ card: string; column: string; }> |
- |
props.edit? |
PanelHandler<{ column: string; title: string; }> |
- |
props.editing? |
boolean |
- |
props.id |
string |
- |
props.open? |
PanelHandler<{ column: string; }> |
- |
props.title |
string |
- |
children |
Children |
the cards of the column, made with card |
Returns
Section titled “Returns”the node
Inherited from
Section titled “Inherited from”confirm()
Section titled “confirm()”confirm(options): Promise<{ confirmed: boolean;}>;Asks the person a question that is answered with yes or no, and waits for the answer.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options |
{ action?: string; message?: string; title: string; } |
title is the question, message is an optional explanation below it, and action is the text of the button that means yes. The app writes “OK” when no action is given |
options.action? |
string |
- |
options.message? |
string |
- |
options.title |
string |
- |
Returns
Section titled “Returns”Promise<{
confirmed: boolean;
}>
{ confirmed: true } when the person agreed, and { confirmed: false } otherwise
decorate()
Section titled “decorate()”decorate(options, decorate): object;Adds small marks to rows: at most a badge, a pill, an icon at the start and a text at the end. decorate has to return the same result for the same row, because the app calls it again only when the row changes. facets lists the facets whose change makes the app call it again.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options |
{ facets?: readonly Pick<FacetRef<unknown>, "key">[]; on: "row"; } |
on is row, and facets lists the facets whose change makes the function run again |
options.facets? |
readonly Pick<FacetRef<unknown>, "key">[] |
- |
options.on |
"row" |
- |
decorate |
(row) => | void | Decoration | undefined |
receives a row and returns the marks to draw, or nothing |
Returns
Section titled “Returns”object
an object with dispose(), which removes the decoration
| Name | Type |
|---|---|
dispose() |
() => void |
divider()
Section titled “divider()”divider(props?): PanelNode;Draws a thin line between the components that surround it.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
props? |
Record<never, never> |
an empty object, because a divider has no properties. |
Returns
Section titled “Returns”the node
Inherited from
Section titled “Inherited from”field()
Section titled “field()”field(props): PanelNode;Displays an editable field with a label. The optional kind restricts the content to text or to numbers, and action is invoked with { value } each time the content changes.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
props |
{ action?: PanelHandler<{ value: string | number; }>; kind?: "number" | "text"; label: string; value?: string | number; } |
label is the text of the field, value is its current content, kind is text or number, and action receives { value } when the content changes. |
props.action? |
PanelHandler<{ value: string | number; }> |
- |
props.kind? |
"number" | "text" |
- |
props.label |
string |
- |
props.value? |
string | number |
- |
Returns
Section titled “Returns”the node
Inherited from
Section titled “Inherited from”icon()
Section titled “icon()”icon(props): PanelNode;Displays an icon chosen by name.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
props |
{ name: string; } |
name is the name of the icon. |
props.name |
string |
- |
Returns
Section titled “Returns”the node
Inherited from
Section titled “Inherited from”list()
Section titled “list()”list(props, children): PanelNode;Displays its children one below the other. The children are normally row components.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
props |
Record<never, never> |
an empty object, because a list has no properties. |
children |
Children |
the components of the list |
Returns
Section titled “Returns”the node
Inherited from
Section titled “Inherited from”notice()
Section titled “notice()”notice(options): void;Shows a short message to the person.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options |
{ level?: "info" | "error"; text: string; } |
text is the message, and level is info or error |
options.level? |
"info" | "error" |
- |
options.text |
string |
- |
Returns
Section titled “Returns”void
outlineIcon()
Section titled “outlineIcon()”outlineIcon(definition): object;Puts a small button next to an outline in the sidebar, such as a lock. When the person presses the button, the app runs command, a command of the plugin, with args. A plugin can have one button for each outline.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
definition |
{ args?: unknown; command: string; icon: string; outline: string; title: string; } |
outline is the id of the outline, icon and title describe the button, and command and args identify the command that the button runs |
definition.args? |
unknown |
- |
definition.command |
string |
- |
definition.icon |
string |
- |
definition.outline |
string |
- |
definition.title |
string |
- |
Returns
Section titled “Returns”object
an object with update(patch), which changes the button, and dispose(), which removes it
| Name | Type |
|---|---|
dispose() |
() => void |
update() |
(patch) => void |
outlineType()
Section titled “outlineType()”outlineType(definition): object;Adds a new way to display an outline, such as a board or a calendar. The render function receives the rows of the outline and returns a tree of panel components. To react when the person interacts with the display, for example by dropping a card, the plugin puts a function on a component. The app gives the screen an id for that function, and it calls the function when the screen sends the id back, together with the data of the interaction and { outline }.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
definition |
{ icon?: string; id: string; render: (outline) => PanelNode; title: string; } |
id identifies the type, title and icon describe it, and render receives an outline and returns the tree of components to draw |
definition.icon? |
string |
- |
definition.id |
string |
- |
definition.render |
(outline) => PanelNode |
- |
definition.title |
string |
- |
Returns
Section titled “Returns”object
an object with dispose(), which removes the type
| Name | Type |
|---|---|
dispose() |
() => void |
panel()
Section titled “panel()”panel(definition): object;Adds a panel, which is a page that is drawn from panel components. The app draws the panel again after each action. A component that carries an action receives a function: Button { action: () => … }.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
definition |
{ id: string; render: () => PanelNode; title: string; } |
id identifies the panel, title is its text, and render returns the tree of components to draw |
definition.id |
string |
- |
definition.render |
() => PanelNode |
- |
definition.title |
string |
- |
Returns
Section titled “Returns”object
an object with dispose(), which removes the panel
| Name | Type |
|---|---|
dispose() |
() => void |
password()
Section titled “password()”password(options): Promise< | { value: string;} | { cancelled: true;}>;Asks the person for a secret in a window that hides what is typed. With confirm: true, the window asks for the secret twice and accepts it only when the two entries are the same.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options |
{ action?: string; confirm?: boolean; message?: string; title: string; } |
title is the question, message is an optional explanation, confirm asks the person to type the secret twice, and action is the text of the button that validates |
options.action? |
string |
- |
options.confirm? |
boolean |
- |
options.message? |
string |
- |
options.title |
string |
- |
Returns
Section titled “Returns”Promise<
| {
value: string;
}
| {
cancelled: true;
}>
{ value } with the secret, or { cancelled: true }
pick()
Section titled “pick()”pick(options): Promise< | { id: string;} | { cancelled: true;}>;Asks the person to choose one of several options, and waits for the answer.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options |
{ choices: readonly object[]; title: string; } |
title is the question, and choices is the list of options, each with an id and a label that the person reads |
options.choices |
readonly object[] |
- |
options.title |
string |
- |
Returns
Section titled “Returns”Promise<
| {
id: string;
}
| {
cancelled: true;
}>
{ id } with the id of the chosen option, or { cancelled: true } when the person dismissed the question
Example
Section titled “Example”const answer = await ctx.ui.pick({ title: 'Export as', choices: [{ id: 'md', label: 'Markdown' }, { id: 'txt', label: 'Plain text' }],});if ('id' in answer) ctx.log('info', answer.id);picker()
Section titled “picker()”picker(props): PanelNode;Lets the person choose one option from a list. The app invokes action with { value } when the selection changes.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
props |
{ action?: PanelHandler<{ value: string; }>; label: string; options: readonly (readonly [string, string])[]; value: string; } |
label is the text of the control, value is the current selection, options is an array of [value, label] pairs, and action receives { value } when the selection changes. |
props.action? |
PanelHandler<{ value: string; }> |
- |
props.label |
string |
- |
props.options |
readonly (readonly [string, string])[] |
- |
props.value |
string |
- |
Returns
Section titled “Returns”the node
Inherited from
Section titled “Inherited from”progress()
Section titled “progress()”progress(props): PanelNode;Displays a progress bar. The value is the completed percentage, between 0 and 100. The optional label is the text that assistive technologies announce.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
props |
{ label?: string; value: number; } |
value is the completed percentage, and label is the text for assistive technologies. |
props.label? |
string |
- |
props.value |
number |
- |
Returns
Section titled “Returns”the node
Inherited from
Section titled “Inherited from”prompt()
Section titled “prompt()”prompt(options): Promise< | { value: string;} | { cancelled: true;}>;Asks the person to type a text, and waits for the answer.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options |
{ message?: string; title: string; value?: string; } |
title is the question, message is an optional explanation below it, and value is the text that the field contains when the question appears |
options.message? |
string |
- |
options.title |
string |
- |
options.value? |
string |
- |
Returns
Section titled “Returns”Promise<
| {
value: string;
}
| {
cancelled: true;
}>
{ value } with the text that the person typed, or { cancelled: true } when the person dismissed the question
Example
Section titled “Example”const answer = await ctx.ui.prompt({ title: 'Name of the new outline' });if ('value' in answer) ctx.log('info', answer.value);row(props): PanelNode;Displays one entry of a list: a title, with an optional subtitle, and an optional accessory text at the end of the line. A row can be pressed, in which case the app invokes action or runs the request given as intent.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
props |
Pressable & object |
title is the main text, subtitle is a second line, accessory is a short text at the end of the line, and action or intent is what happens when the row is pressed. |
Returns
Section titled “Returns”the node
Inherited from
Section titled “Inherited from”sidebarEntry()
Section titled “sidebarEntry()”sidebarEntry(definition): object;Adds an entry to the sidebar. When panel is given, pressing the entry opens that panel.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
definition |
{ icon?: string; id: string; panel?: string; title: string; } |
id identifies the entry, title is its text, icon is an optional icon, and panel is the id of the panel that the entry opens |
definition.icon? |
string |
- |
definition.id |
string |
- |
definition.panel? |
string |
- |
definition.title |
string |
- |
Returns
Section titled “Returns”object
an object with dispose(), which removes the entry
| Name | Type |
|---|---|
dispose() |
() => void |
slashItem()
Section titled “slashItem()”slashItem(definition): object;Adds an item to the menu that opens when the person types / in a note. The menu shows the title, the description and the icon of the item. When the person picks the item, the app calls apply with the text of the note, the position of the / and the position of the caret, and apply returns the new text and the new position of the caret.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
definition |
{ apply: (text, start, caret) => object; desc: string; icon?: string; id: string; title: string; } |
id identifies the item, title, desc and icon describe it, and apply receives the text, the position of the / and the position of the caret, and returns the new text and caret |
definition.apply |
(text, start, caret) => object |
- |
definition.desc |
string |
- |
definition.icon? |
string |
- |
definition.id |
string |
- |
definition.title |
string |
- |
Returns
Section titled “Returns”object
an object with dispose(), which removes the item
| Name | Type |
|---|---|
dispose() |
() => void |
spacer()
Section titled “spacer()”spacer(props?): PanelNode;Leaves an empty space between components.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
props? |
Record<never, never> |
an empty object, because a spacer has no properties. |
Returns
Section titled “Returns”the node
Inherited from
Section titled “Inherited from”stack()
Section titled “stack()”stack(props, children): PanelNode;Arranges its children in a row or in a column, depending on axis, with a fixed space between them.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
props |
{ axis?: "horizontal" | "vertical"; gap?: number; } |
axis selects the direction, horizontal or vertical, and gap sets the space between two children, in pixels. |
props.axis? |
"horizontal" | "vertical" |
- |
props.gap? |
number |
- |
children |
Children |
the components to arrange |
Returns
Section titled “Returns”the node
Inherited from
Section titled “Inherited from”statusItem()
Section titled “statusItem()”statusItem(definition): object;Puts text in the status bar. The app calls the text function again each time it draws the bar.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
definition |
{ icon?: string; id: string; text: () => string; } |
id identifies the item, text is the function that returns the text, and icon is an optional icon |
definition.icon? |
string |
- |
definition.id |
string |
- |
definition.text |
() => string |
- |
Returns
Section titled “Returns”object
an object with dispose(), which removes the item
| Name | Type |
|---|---|
dispose() |
() => void |
text()
Section titled “text()”text(props): PanelNode;Displays a piece of text. The optional style selects its appearance: title renders a larger and bolder text, and caption renders a smaller and muted one. Without a style, the text has the ordinary appearance.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
props |
{ style?: string; text: string; } |
text is the text to display, and style is its appearance. |
props.style? |
string |
- |
props.text |
string |
- |
Returns
Section titled “Returns”the node
Inherited from
Section titled “Inherited from”toggle()
Section titled “toggle()”toggle(props): PanelNode;Displays a switch with a label. The app invokes action with { value } each time the person flips the switch.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
props |
{ action?: PanelHandler<{ value: boolean; }>; label: string; value?: boolean; } |
label is the text next to the switch, value is its current state, and action receives { value } when the person changes it. |
props.action? |
PanelHandler<{ value: boolean; }> |
- |
props.label |
string |
- |
props.value? |
boolean |
- |
Returns
Section titled “Returns”the node
