Settings
Typed settings that become a form in Studio.
The settings of an action become a form in Studio, and arrive typed in run and component.
Make them with setting:
settings: {
mode: setting.select("Mode", { set: "Set a level", mute: "Mute" }), // "set" | "mute"
level: setting.number("Level", { min: 0, max: 100, visibleIf: { mode: "set" } }),
device: setting.pick("Device", devices, { first: { "": "The one in use" } }),
},setting. | Options |
|---|---|
text | placeholder, multiline, source (suggestions), dependsOn |
number | min, max, step |
boolean | |
color | #rrggbb |
select | a few fixed choices, as { value: "Label" } or a list |
pick | choices from a source; first, dependsOn |
page | one of the user's pages; none: "Every page" offers no page |
slots | keys, sensors and the window; an empty list is the entire deck |
image | a URL, a file, or an icon |
groups | plugin settings only; named sets of options from a source |
secret | plugin settings only; kept outside the config |
Every field can have a label, a description and appearance: true, for one that only changes
how the button looks (a background, a caption). Workflow steps and gestures leave those out.
visibleIf: { mode: "set" } shows a field only while another has that value.
Choices from a source
A source fetches choices when the form opens (OBS scenes, devices):
const devices = plugin.source("devices", async (context) =>
(await listDevices(context.settings().address)).map((d) => ({ value: d.id, label: d.name })),
);
export default plugin.define({ actions: [play], sources: [devices] });Give it to setting.pick, to setting.groups, or as source: devices.id to setting.text, where it
only suggests. A field that dependsOn others is asked for after them, and its source receives their
values as its second argument.
Checking what is entered
required: true refuses an empty field. validate says what is wrong with a value, or returns
nothing when it is fine:
settings: {
address: setting.text("Address", {
required: true,
validate: (text) => (URL.canParse(text) ? undefined : "must be a URL"),
}),
},It can be async, and it can be a schema from zod, valibot or any other Standard Schema library, which you then add to your plugin's dependencies:
import { z } from "zod";
const email = setting.text("Email", { validate: z.email("must be an email address") });Studio shows the problem under the field, and the action fails with it until it is fixed, so run
does not have to check again. Fields that are hidden or empty are not checked, and a value with
{{templates}} is checked when the action runs, with what they gave. A schema only checks: what it
would turn the value into is not used.
More about fields
live: true on a text or image field leaves its {{templates}} as they were written, so what
you draw with useTemplate keeps following the values. Templates that read the run itself
(event, loop…) are still filled in.
A groups field lets users put options together under a name (rooms of lights). It arrives as
{ id, name, members }[], where members are option values. Refer to a group by its id, so
renaming it breaks nothing.