The parts of a plugin
createPlugin, and what it makes.
createPlugin takes what the plugin is. What it returns makes the parts, and define puts them
together:
import { createPlugin, Permissions, setting } from "@sdeck/plugin";
import { iconLook } from "@sdeck/schema";
const plugin = createPlugin({
id: "sdeck-plugin-weather", // the package's name
name: "Weather",
version: "1.0.0",
permissions: [Permissions.network],
settings: { city: setting.text("City", { required: true }) },
});
const temperature = plugin.state.number("temperature", "Temperature", {
unit: "°C",
poll: { everyMs: 60_000, read: (context) => fetchTemperature(context.settings().city) },
});
const now = plugin.action({
id: "now",
name: "Temperature",
display: true,
look: () => iconLook({ icon: "lucide/sun", color: "#fbbf24", caption: temperature.template }),
});
export default plugin.define({ actions: [now], state: [temperature] });| Makes | What |
|---|---|
plugin.action | Something a button does or shows |
plugin.state.number, string, boolean, json | A live value |
plugin.trigger | Something that starts workflows |
plugin.source | Choices for a setting |
plugin.command | A button in the plugin's settings |
Everything is checked against everything else as you type: context.settings().city is a string,
a part can only ask for a permission the plugin lists, and renaming a live value in one place
renames it in every look that uses its template or key. Only the parts given to define are in
the plugin. plugin.context is the running plugin's context, for code outside of them.
The helpers return plain objects, and definePlugin, defineAction and defineTrigger take the
same ones written by hand. Plugins made that way keep working.