Fields, parts and actions¶
What a plug-in adds to the views and pages of Initiative's items: tasks,
calendar events and posts
(ITEM_KINDS). Initiative draws all of it with its own components, so no
plug-in code runs in a reader's browser, and the community's managers place
it; a plug-in never places itself. Any plug-in may declare them, container or
declarative.
Metadata is what the plug-in keeps on an item or on its own install: values
by key (a lowercase letter, then lowercase letters, digits, _ and .), held
by Initiative. A container writes them with its installation token
(client.metadata, in Call Initiative); for a declarative plug-in, Initiative writes them
from the plug-in's expressions (Declarative integrations).
Initiative enforces its sizes: a value of at most 8192 bytes as JSON,
32 keys and 64 KiB on one item, and 256 keys and 1 MiB on the install. A
string of at most 255 characters can be found by.
A field says how one metadata key is shown. Initiative draws the value with
its own component for kind and computes its plain text itself, so a field
filters, sorts and exports with no call to the plug-in.
kind |
The value |
|---|---|
text |
a string |
number |
a number |
date |
"YYYY-MM-DD" |
datetime |
ISO 8601, with its offset |
link |
{ url, text? } |
badge |
{ text, tone? } |
scale |
a number from 0 to 100, or { value, max } |
checkbox |
a boolean |
url |
an address, as a string |
currency |
a number, in the field's currency |
select |
the value of one of the field's options |
multi_select |
a list of them |
user_reference |
a person: the install's own reference for them |
A scale is drawn as a number, stars or a bar. Written as { value, max }, it
is kept as value ÷ max × 100: { value: 3, max: 5 } is 60. A
user_reference is the id Initiative gives the person wherever the plug-in
reads one, such as a task's assignees or the community's roster.
fields: {
"demo.link": { name: { en: "Demo" }, kind: "link", on: ["task"], description: { en: "The task's demo" } },
"demo.opened": { name: { en: "Opened" }, kind: "number", on: ["task"] },
"demo.budget": { name: { en: "Budget" }, kind: "currency", currency: "EUR", on: ["task"] },
"demo.stage": {
name: { en: "Stage" },
kind: "select",
on: ["task"],
options: [
{ value: "draft", label: { en: "Draft" } },
{ value: "live", label: { en: "Live" }, color: "#2f9e44" },
],
},
},
on is the item kinds it is offered on; description is the line the view
editor's Add picker shows; tone is a badge's tone when its value names none
(accent, positive, negative, warning, neutral, muted). A currency
field names its ISO 4217 code in currency. A select or multi_select field
lists its options, up to 24, each a value (a letter or a digit, then up to
63 letters, digits, _ and -, unique among them), a
label in the reader's language and an optional color as #rrggbb.
A list field, list: true, holds several values: its value is a list of
elements, each one value of the field's kind with a ref of 1 to 255
characters that tells it from the others. Any kind but multi_select, whose
one value is already several, may be a list. A link or badge element is the
kind's own object with its ref, such as { ref, url, text? }; a scale
element is { ref, value, max? }, out of 100 without max; every other kind's
element is { ref, value }. Initiative keeps each element as a value of its
own, held to the size of one value, and finds an element by its ref.
States say what state a value is in, in the plug-in's own words: up to 4
facets, each with up to 12 keys. A value names a key of each facet it is in as
state, and Initiative draws one badge per facet, labelled in the reader's
language. A list element, and a link, badge or { value, max } scale
value, carries state beside its other properties; any other value that
carries one is written as an element is, without the ref: { value, state }.
fields: {
"tracker.issues": {
name: { en: "Issues" },
kind: "link",
list: true,
on: ["task"],
states: {
status: {
name: { en: "Status" },
values: { open: { label: { en: "Open" }, tone: "positive" }, closed: { label: { en: "Closed" }, tone: "muted" } },
},
},
actions: ["unlink"],
},
},
// an element: { ref: "12", url: "https://tracker.example/issues/12", text: "#12", state: { status: "open" } }
A list field's actions are offered on each of its elements, and each is
offered on every item kind the field is. They are a declarative plug-in's: an
action run from an element reads the element's ref as element, and a
container's handler is told the item alone.
An action runs on one item, from a part's button, from the item's own menu
with menu: true, or from an element of a list field that offers it. A
container plug-in's action names one of its write endpoints: Initiative calls
it as the installation, with viewer and subject set, and the handler does
the work, usually writing metadata. A declarative plug-in's names an endpoint,
a write, or both, and Initiative does the work itself. Either way Initiative
then answers the reader with the item's metadata as it stands. With confirm,
Initiative asks first. Who may run it is a permission (see "Who may use what").
params names the endpoint's params Initiative asks the reader for before it
runs the action, in a form drawn from their own declarations: each one's type,
label, and options or options_from. The endpoint is sent the reader's
answers and nothing else, so every param it requires is among them.
actions: {
"new-link": { name: { en: "New link" }, endpoint: "create-link", params: ["url"], on: ["task"], menu: true },
},
A part is a tree of Initiative's components bound to the plug-in's fields and actions, at most 50 nodes and 4 deep. Initiative places at most 3 of a plug-in's parts on one item.
| Component | Props | Holds nodes |
|---|---|---|
section |
title?, collapsed? |
yes |
stack |
direction? (row, column), gap? (none, small, medium, large), wrap? |
yes |
field |
field: a field's key. Its label and value. |
no |
value |
field: a field's key. Its value alone. |
no |
text |
text, tone? |
no |
button |
action: an action's id; variant? (primary, secondary, ghost) |
no |
Every field and action a part names must be offered on each kind in the
part's on. A text node's text may name {item.id}, the item's id, and
{settings.<key>}, one of the plug-in's settings, which
Initiative fills in when it draws the part; validateManifest refuses any
other {…}. A tree is plain data, { type, props?, children? }, or JSX
through the SDK's runtime, which the build turns into the same data:
/** @jsxImportSource initiative-plugin-sdk */
import { Button, Field, Section, Stack, Text, Value } from "initiative-plugin-sdk/parts";
parts: {
demo: {
name: { en: "Demo" },
on: ["task"],
tree: (
<Section title={{ en: "Demo" }}>
<Field field="demo.link" />
<Stack direction="row" gap="small">
<Value field="demo.opened" />
<Text text={{ en: "times opened" }} tone="muted" />
</Stack>
<Button action="new-link" />
</Section>
),
},
},
The pragma, or "jsx": "react-jsx" and "jsxImportSource":
"initiative-plugin-sdk" in tsconfig.json, selects the runtime. A fragment's
children join the node that holds it, and null and false children are left
out. key is JSX's own and is not passed on, which is why a field is named by
field.