@sdeck/plugin 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/create.d.ts +105 -0
- package/dist/create.d.ts.map +1 -0
- package/dist/fields.d.ts +62 -0
- package/dist/fields.d.ts.map +1 -0
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +191 -4
- package/dist/index.js.map +13 -10
- package/dist/manifest.d.ts +3 -3
- package/dist/manifest.d.ts.map +1 -1
- package/dist/permissions.d.ts +16 -0
- package/dist/permissions.d.ts.map +1 -1
- package/dist/plugin.d.ts +28 -20
- package/dist/plugin.d.ts.map +1 -1
- package/dist/settings.d.ts +20 -11
- package/dist/settings.d.ts.map +1 -1
- package/dist/shared.d.ts +11 -0
- package/dist/shared.d.ts.map +1 -1
- package/dist/validate.d.ts +33 -0
- package/dist/validate.d.ts.map +1 -0
- package/package.json +4 -4
- package/src/create.ts +223 -0
- package/src/fields.ts +112 -0
- package/src/index.ts +14 -1
- package/src/manifest.ts +8 -5
- package/src/permissions.ts +17 -0
- package/src/plugin.ts +45 -20
- package/src/settings.ts +24 -11
- package/src/shared.ts +33 -0
- package/src/validate.ts +61 -0
package/dist/permissions.d.ts
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
3
3
|
* gets nothing it did not ask for and nothing the user did not allow.
|
|
4
4
|
*/
|
|
5
5
|
export type Permission = "network" | "filesystem" | "process" | "shell" | "input" | "clipboard" | "audio" | "environment" | "variables" | "state" | "actions" | "overlay" | "native";
|
|
6
|
+
/** Every permission by name, for `permissions: [Permissions.network]`. */
|
|
7
|
+
export declare const Permissions: {
|
|
8
|
+
readonly network: "network";
|
|
9
|
+
readonly filesystem: "filesystem";
|
|
10
|
+
readonly process: "process";
|
|
11
|
+
readonly shell: "shell";
|
|
12
|
+
readonly input: "input";
|
|
13
|
+
readonly clipboard: "clipboard";
|
|
14
|
+
readonly audio: "audio";
|
|
15
|
+
readonly environment: "environment";
|
|
16
|
+
readonly variables: "variables";
|
|
17
|
+
readonly state: "state";
|
|
18
|
+
readonly actions: "actions";
|
|
19
|
+
readonly overlay: "overlay";
|
|
20
|
+
readonly native: "native";
|
|
21
|
+
};
|
|
6
22
|
/** A permission as the user reads it. */
|
|
7
23
|
export interface PermissionText {
|
|
8
24
|
name: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permissions.d.ts","sourceRoot":"","sources":["../src/permissions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,UAAU,GAClB,SAAS,GACT,YAAY,GACZ,SAAS,GACT,OAAO,GACP,OAAO,GACP,WAAW,GACX,OAAO,GACP,aAAa,GACb,WAAW,GACX,OAAO,GACP,SAAS,GACT,SAAS,GACT,QAAQ,CAAC;AAEb,yCAAyC;AACzC,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,uCAAuC;IACvC,WAAW,EAAE,MAAM,CAAC;IACpB,iDAAiD;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,mEAAmE;IACnE,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,wDAAwD;AACxD,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,cAAc,CAAC,CAsEzE,CAAC;AAEF,eAAO,MAAM,WAAW,EAAoC,SAAS,UAAU,EAAE,CAAC;AAElF,iGAAiG;AACjG,qBAAa,eAAgB,SAAQ,KAAK;IAQtC,QAAQ,CAAC,UAAU,EAAE,UAAU;IAPjC,SAAkB,IAAI,qBAAqB;IAC3C,wFAAwF;IACxF,QAAQ,CAAC,IAAI,YAAY;IAEzB;IACE,+BAA+B;IAC/B,MAAM,EAAE,MAAM,EACL,UAAU,EAAE,UAAU;IAC/B,8DAA8D;IAC9D,MAAM,CAAC,EAAE,MAAM,EAOhB;CACF"}
|
|
1
|
+
{"version":3,"file":"permissions.d.ts","sourceRoot":"","sources":["../src/permissions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,UAAU,GAClB,SAAS,GACT,YAAY,GACZ,SAAS,GACT,OAAO,GACP,OAAO,GACP,WAAW,GACX,OAAO,GACP,aAAa,GACb,WAAW,GACX,OAAO,GACP,SAAS,GACT,SAAS,GACT,QAAQ,CAAC;AAEb,0EAA0E;AAC1E,eAAO,MAAM,WAAW;sBACb,SAAS;yBACN,YAAY;sBACf,SAAS;oBACX,OAAO;oBACP,OAAO;wBACH,WAAW;oBACf,OAAO;0BACD,aAAa;wBACf,WAAW;oBACf,OAAO;sBACL,SAAS;sBACT,SAAS;qBACV,QAAQ;CAC2B,CAAC;AAE9C,yCAAyC;AACzC,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,uCAAuC;IACvC,WAAW,EAAE,MAAM,CAAC;IACpB,iDAAiD;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,mEAAmE;IACnE,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,wDAAwD;AACxD,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,cAAc,CAAC,CAsEzE,CAAC;AAEF,eAAO,MAAM,WAAW,EAAoC,SAAS,UAAU,EAAE,CAAC;AAElF,iGAAiG;AACjG,qBAAa,eAAgB,SAAQ,KAAK;IAQtC,QAAQ,CAAC,UAAU,EAAE,UAAU;IAPjC,SAAkB,IAAI,qBAAqB;IAC3C,wFAAwF;IACxF,QAAQ,CAAC,IAAI,YAAY;IAEzB;IACE,+BAA+B;IAC/B,MAAM,EAAE,MAAM,EACL,UAAU,EAAE,UAAU;IAC/B,8DAA8D;IAC9D,MAAM,CAAC,EAAE,MAAM,EAOhB;CACF"}
|
package/dist/plugin.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { type Permission } from "./permissions.ts";
|
|
|
6
6
|
import { type InferSettings, type SelectOption, type SettingsSchema } from "./settings.ts";
|
|
7
7
|
import type { TextRow } from "./text.ts";
|
|
8
8
|
/** Bumped when the plugin contract changes incompatibly. Hosts refuse plugins built for another. */
|
|
9
|
-
export declare const PLUGIN_API_VERSION =
|
|
9
|
+
export declare const PLUGIN_API_VERSION = 3;
|
|
10
10
|
/** Where an action can be placed. */
|
|
11
11
|
export type SlotKind = "key" | "sensor" | "window";
|
|
12
12
|
/** Given to a plugin's `activate`, its actions, state providers and triggers. */
|
|
@@ -90,7 +90,7 @@ export interface OverlayProps {
|
|
|
90
90
|
/** How a plugin's status reads: fine, needing attention, or failing. */
|
|
91
91
|
export type StatusLevel = "ok" | "info" | "error";
|
|
92
92
|
/** Something the user can run from the plugin's settings (sign in, reconnect). */
|
|
93
|
-
export interface PluginCommand {
|
|
93
|
+
export interface PluginCommand<C = PluginContext, P extends Permission = Permission> {
|
|
94
94
|
/** Unique within the plugin. */
|
|
95
95
|
id: string;
|
|
96
96
|
name: string;
|
|
@@ -99,9 +99,9 @@ export interface PluginCommand {
|
|
|
99
99
|
* What it needs, out of the plugin's `permissions` (default: all of them; `[]` for nothing).
|
|
100
100
|
* Without them it is refused.
|
|
101
101
|
*/
|
|
102
|
-
permissions?: readonly
|
|
102
|
+
permissions?: readonly P[];
|
|
103
103
|
/** What it returns, if a string, is opened in the user's browser. Throw to fail. */
|
|
104
|
-
run(context:
|
|
104
|
+
run(context: C): unknown | Promise<unknown>;
|
|
105
105
|
}
|
|
106
106
|
/**
|
|
107
107
|
* One step of setting a plugin up. Studio walks the user through the steps right after the plugin
|
|
@@ -163,20 +163,20 @@ export interface Onboarding {
|
|
|
163
163
|
starterPage?: StarterPage | false;
|
|
164
164
|
}
|
|
165
165
|
/** Props of an action's component. */
|
|
166
|
-
export interface ActionProps<S extends SettingsSchema = SettingsSchema> {
|
|
166
|
+
export interface ActionProps<S extends SettingsSchema = SettingsSchema, C = PluginContext> {
|
|
167
167
|
/** This placement's settings, resolved against the schema (always complete and typed). */
|
|
168
168
|
settings: InferSettings<S>;
|
|
169
169
|
/** Saves changed settings for this placement (persisted and shown in the UI). */
|
|
170
170
|
setSettings(patch: Partial<InferSettings<S>>): void;
|
|
171
171
|
/** Where the action is drawn. */
|
|
172
172
|
slot: SlotInfo;
|
|
173
|
-
plugin:
|
|
173
|
+
plugin: C;
|
|
174
174
|
}
|
|
175
175
|
/** Given to an action's `run`. */
|
|
176
|
-
export interface RunContext<S extends SettingsSchema = SettingsSchema> {
|
|
176
|
+
export interface RunContext<S extends SettingsSchema = SettingsSchema, C = PluginContext> {
|
|
177
177
|
/** Settings with `{{templates}}` already resolved, then checked against the schema. */
|
|
178
178
|
settings: InferSettings<S>;
|
|
179
|
-
plugin:
|
|
179
|
+
plugin: C;
|
|
180
180
|
/** What started the run (a key, a trigger, a workflow…). */
|
|
181
181
|
source: ExecSource;
|
|
182
182
|
/** Aborted when the execution is cancelled. Long work should stop. */
|
|
@@ -208,7 +208,7 @@ export interface RunOutcome {
|
|
|
208
208
|
label?: string;
|
|
209
209
|
}
|
|
210
210
|
export type RunResult = RunOutcome | undefined;
|
|
211
|
-
export interface ActionDef<S extends SettingsSchema = SettingsSchema> {
|
|
211
|
+
export interface ActionDef<S extends SettingsSchema = SettingsSchema, C = PluginContext, P extends Permission = Permission> {
|
|
212
212
|
/** Unique within the plugin, e.g. `"clock"`. */
|
|
213
213
|
id: string;
|
|
214
214
|
name: string;
|
|
@@ -228,7 +228,7 @@ export interface ActionDef<S extends SettingsSchema = SettingsSchema> {
|
|
|
228
228
|
* What it needs, out of the plugin's `permissions` (default: all of them; `[]` for nothing).
|
|
229
229
|
* Without them it cannot run or draw itself.
|
|
230
230
|
*/
|
|
231
|
-
permissions?: readonly
|
|
231
|
+
permissions?: readonly P[];
|
|
232
232
|
/**
|
|
233
233
|
* It only shows something. It is offered for buttons, but not as a step of a workflow or
|
|
234
234
|
* gesture, and needs no `run`.
|
|
@@ -238,15 +238,18 @@ export interface ActionDef<S extends SettingsSchema = SettingsSchema> {
|
|
|
238
238
|
* Does the work, without drawing anything: it can run from a key, a trigger or a workflow.
|
|
239
239
|
* Throw to fail. An action needs `run`, `component`, or both, unless it is `display`.
|
|
240
240
|
*/
|
|
241
|
-
run?(context: RunContext<S>): RunResult | void | Promise<RunResult | void>;
|
|
241
|
+
run?(context: RunContext<S, C>): RunResult | void | Promise<RunResult | void>;
|
|
242
242
|
/**
|
|
243
243
|
* Draws the action itself (it then handles its own input). It runs inside the deck's React
|
|
244
244
|
* tree, so the `@sdeck/app` hooks and components work as in any app. Without it, the host
|
|
245
245
|
* draws the button's look and runs `run` on press.
|
|
246
246
|
*/
|
|
247
|
-
component?: ComponentType<ActionProps<S>>;
|
|
248
|
-
/**
|
|
249
|
-
|
|
247
|
+
component?: ComponentType<ActionProps<S, C>>;
|
|
248
|
+
/**
|
|
249
|
+
* The look a new button with this action starts with (default: its name on a dark key). `slot` is
|
|
250
|
+
* where it is drawn: the window is much wider than a key, and a touch sensor shows no text.
|
|
251
|
+
*/
|
|
252
|
+
look?(settings: InferSettings<S>, slot: SlotKind): Look;
|
|
250
253
|
}
|
|
251
254
|
export type RunFn = (context: RunContext) => RunResult | undefined | Promise<RunResult | undefined>;
|
|
252
255
|
/** An action with its settings type erased, as stored on a plugin. */
|
|
@@ -262,7 +265,7 @@ export interface Action {
|
|
|
262
265
|
readonly display?: boolean;
|
|
263
266
|
readonly run?: RunFn;
|
|
264
267
|
readonly component?: ComponentType<ActionProps>;
|
|
265
|
-
readonly look?: (settings: Record<string, unknown
|
|
268
|
+
readonly look?: (settings: Record<string, unknown>, slot: SlotKind) => Look;
|
|
266
269
|
}
|
|
267
270
|
/** A live value the plugin publishes as `<namespace>.<id>`. */
|
|
268
271
|
export interface StateDef {
|
|
@@ -286,13 +289,13 @@ export interface StateDef {
|
|
|
286
289
|
start?(set: (value: unknown) => void, context: PluginContext): (() => void) | void;
|
|
287
290
|
}
|
|
288
291
|
/** Given to a trigger's `subscribe`. */
|
|
289
|
-
export interface TriggerContext<S extends SettingsSchema = SettingsSchema> {
|
|
292
|
+
export interface TriggerContext<S extends SettingsSchema = SettingsSchema, C = PluginContext> {
|
|
290
293
|
settings: InferSettings<S>;
|
|
291
|
-
plugin:
|
|
294
|
+
plugin: C;
|
|
292
295
|
/** Starts the trigger's workflow; `event` becomes `event` in its expressions. */
|
|
293
296
|
fire(event?: unknown): void;
|
|
294
297
|
}
|
|
295
|
-
export interface TriggerDef<S extends SettingsSchema = SettingsSchema> {
|
|
298
|
+
export interface TriggerDef<S extends SettingsSchema = SettingsSchema, C = PluginContext, P extends Permission = Permission> {
|
|
296
299
|
/** Unique within the plugin; the trigger type is `<plugin id>:<id>`. */
|
|
297
300
|
id: string;
|
|
298
301
|
name: string;
|
|
@@ -302,9 +305,9 @@ export interface TriggerDef<S extends SettingsSchema = SettingsSchema> {
|
|
|
302
305
|
* What it needs, out of the plugin's `permissions` (default: all of them; `[]` for nothing).
|
|
303
306
|
* Without them it never fires.
|
|
304
307
|
*/
|
|
305
|
-
permissions?: readonly
|
|
308
|
+
permissions?: readonly P[];
|
|
306
309
|
/** Starts watching; returns a function that stops. */
|
|
307
|
-
subscribe(context: TriggerContext<S>): (() => void) | void;
|
|
310
|
+
subscribe(context: TriggerContext<S, C>): (() => void) | void;
|
|
308
311
|
}
|
|
309
312
|
export interface Trigger {
|
|
310
313
|
readonly id: string;
|
|
@@ -374,4 +377,9 @@ export declare function defineTrigger<const S extends SettingsSchema = Record<ne
|
|
|
374
377
|
export declare function definePlugin(def: PluginDef): PluginDef;
|
|
375
378
|
/** Problems with something that should be a plugin (empty when it is fine). */
|
|
376
379
|
export declare function checkPlugin(value: unknown): string[];
|
|
380
|
+
/**
|
|
381
|
+
* Calls `listener` when the plugin's settings have other values than before, such as to connect
|
|
382
|
+
* again. `onSettings` also tells of saves that changed nothing. Returns a function that stops.
|
|
383
|
+
*/
|
|
384
|
+
export declare function onSettingsChange(context: PluginContext, listener: () => void): () => void;
|
|
377
385
|
//# sourceMappingURL=plugin.d.ts.map
|
package/dist/plugin.d.ts.map
CH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AY,CAAC,KAAK,CAAC,CAAC,SAAS,cAAc,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EAChF,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,GAChB,MAAM,CAMR;AAED,kDAAkD;AAClD,wBAAgB,aAAa,CAAC,KAAK,CAAC,CAAC,SAAS,cAAc,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EACjF,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,GACjB,OAAO,CAET;AAED,4FAA4F;AAC5F,wBAAgB,YAAY,CAAC,GAAG,EAAE,SAAS,GAAG,SAAS,CAMtD;AA8BD,+EAA+E;AAC/E,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,EAAE,CAyHpD;AAuCD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAQzF"}
|
package/dist/settings.d.ts
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
* Action settings are described by a plain-data schema. The host turns it into a form in the
|
|
3
3
|
* configuration UI, and `resolveSettings` turns whatever is stored into well-typed values.
|
|
4
4
|
*/
|
|
5
|
+
import type { Validator } from "./validate.ts";
|
|
5
6
|
type Primitive = string | number | boolean;
|
|
6
|
-
interface FieldBase {
|
|
7
|
+
interface FieldBase<T = unknown> {
|
|
7
8
|
/** Label shown in the configuration UI. */
|
|
8
9
|
label: string;
|
|
9
10
|
/** Help text under the field. */
|
|
@@ -13,13 +14,21 @@ interface FieldBase {
|
|
|
13
14
|
* workflow or gesture, where nothing is drawn.
|
|
14
15
|
*/
|
|
15
16
|
appearance?: boolean;
|
|
17
|
+
/** It cannot be left empty: the action does not run until it is filled in. */
|
|
18
|
+
required?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Checks what was entered: a function that returns what is wrong (`"must be a URL"`), or a
|
|
21
|
+
* schema from zod, valibot or another Standard Schema library. The form shows it, and the action
|
|
22
|
+
* does not run until it is fixed. Values with `{{templates}}` are checked when it runs.
|
|
23
|
+
*/
|
|
24
|
+
validate?: Validator<T>;
|
|
16
25
|
/**
|
|
17
26
|
* Shown only while other fields have these values: `{ to: "page" }` or
|
|
18
27
|
* `{ mode: ["a", "b"] }`. Hidden fields keep their value.
|
|
19
28
|
*/
|
|
20
29
|
visibleIf?: Readonly<Record<string, Primitive | readonly Primitive[]>>;
|
|
21
30
|
}
|
|
22
|
-
export interface TextField extends FieldBase {
|
|
31
|
+
export interface TextField extends FieldBase<string> {
|
|
23
32
|
type: "text";
|
|
24
33
|
default?: string;
|
|
25
34
|
placeholder?: string;
|
|
@@ -34,14 +43,14 @@ export interface TextField extends FieldBase {
|
|
|
34
43
|
*/
|
|
35
44
|
live?: boolean;
|
|
36
45
|
}
|
|
37
|
-
export interface NumberField extends FieldBase {
|
|
46
|
+
export interface NumberField extends FieldBase<number> {
|
|
38
47
|
type: "number";
|
|
39
48
|
default?: number;
|
|
40
49
|
min?: number;
|
|
41
50
|
max?: number;
|
|
42
51
|
step?: number;
|
|
43
52
|
}
|
|
44
|
-
export interface BooleanField extends FieldBase {
|
|
53
|
+
export interface BooleanField extends FieldBase<boolean> {
|
|
45
54
|
type: "boolean";
|
|
46
55
|
default?: boolean;
|
|
47
56
|
}
|
|
@@ -49,13 +58,13 @@ export interface BooleanField extends FieldBase {
|
|
|
49
58
|
* A password or token, only for a plugin's own settings. It is kept in the host's secrets file
|
|
50
59
|
* (never in the config, so it is safe to share or commit) and the UI never reads it back.
|
|
51
60
|
*/
|
|
52
|
-
export interface SecretField extends FieldBase {
|
|
61
|
+
export interface SecretField extends FieldBase<string> {
|
|
53
62
|
type: "secret";
|
|
54
63
|
default?: string;
|
|
55
64
|
placeholder?: string;
|
|
56
65
|
}
|
|
57
66
|
/** A `#rrggbb` colour. */
|
|
58
|
-
export interface ColorField extends FieldBase {
|
|
67
|
+
export interface ColorField extends FieldBase<string> {
|
|
59
68
|
type: "color";
|
|
60
69
|
default?: string;
|
|
61
70
|
}
|
|
@@ -63,7 +72,7 @@ export interface SelectOption {
|
|
|
63
72
|
value: string;
|
|
64
73
|
label: string;
|
|
65
74
|
}
|
|
66
|
-
export interface SelectField extends FieldBase {
|
|
75
|
+
export interface SelectField extends FieldBase<string> {
|
|
67
76
|
type: "select";
|
|
68
77
|
/** Fixed options. With `source`, shown before the fetched ones. */
|
|
69
78
|
options: readonly SelectOption[];
|
|
@@ -80,7 +89,7 @@ export interface SelectField extends FieldBase {
|
|
|
80
89
|
default?: string;
|
|
81
90
|
}
|
|
82
91
|
/** The name of one of the user's pages (the UI shows a page picker). */
|
|
83
|
-
export interface PageField extends FieldBase {
|
|
92
|
+
export interface PageField extends FieldBase<string> {
|
|
84
93
|
type: "page";
|
|
85
94
|
default?: string;
|
|
86
95
|
/** Offers choosing no page (an empty value), under this name: `Every page`. */
|
|
@@ -90,12 +99,12 @@ export interface PageField extends FieldBase {
|
|
|
90
99
|
* Keys, touch sensors and the window, picked on a picture of the deck: `key:0`, `sensor:1`,
|
|
91
100
|
* `window`. An empty list stands for the entire deck.
|
|
92
101
|
*/
|
|
93
|
-
export interface SlotsField extends FieldBase {
|
|
102
|
+
export interface SlotsField extends FieldBase<readonly string[]> {
|
|
94
103
|
type: "slots";
|
|
95
104
|
default?: readonly string[];
|
|
96
105
|
}
|
|
97
106
|
/** An image: an `http(s)` URL or a `data:` URI (the UI accepts a URL or a file). */
|
|
98
|
-
export interface ImageField extends FieldBase {
|
|
107
|
+
export interface ImageField extends FieldBase<string> {
|
|
99
108
|
type: "image";
|
|
100
109
|
default?: string;
|
|
101
110
|
/** As on a text field: `{{spotify.art}}` reaches `run` as written. */
|
|
@@ -110,7 +119,7 @@ export interface OptionGroup {
|
|
|
110
119
|
members: readonly string[];
|
|
111
120
|
}
|
|
112
121
|
/** Named sets of options the user puts together (rooms of lights), only for a plugin's own settings. */
|
|
113
|
-
export interface GroupsField extends FieldBase {
|
|
122
|
+
export interface GroupsField extends FieldBase<readonly OptionGroup[]> {
|
|
114
123
|
type: "groups";
|
|
115
124
|
/** The plugin's `optionSources` entry that lists what a group can contain. */
|
|
116
125
|
source: string;
|
package/dist/settings.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../src/settings.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../src/settings.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAE3C,UAAU,SAAS,CAAC,CAAC,GAAG,OAAO;IAC7B,2CAA2C;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,iCAAiC;IACjC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IACxB;;;OAGG;IACH,SAAS,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,SAAS,SAAS,EAAE,CAAC,CAAC,CAAC;CACxE;AAED,MAAM,WAAW,SAAU,SAAQ,SAAS,CAAC,MAAM,CAAC;IAClD,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,wFAAwF;IACxF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oEAAoE;IACpE,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9B;;;OAGG;IACH,IAAI,CAAC,EA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AQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAC1C,OAAO,CAMT;AAED;;;GAGG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,cAAc,EACtB,OAAO,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAM,GAC9C,MAAM,EAAE,CA+CV"}
|
package/dist/shared.d.ts
CHANGED
|
@@ -6,4 +6,15 @@ export declare class Shared<T> {
|
|
|
6
6
|
get last(): T | undefined;
|
|
7
7
|
listen(listener: (value: T) => void): () => void;
|
|
8
8
|
}
|
|
9
|
+
/** The latest value of a {@link Shared} in a component, which keeps it started meanwhile. */
|
|
10
|
+
export declare function useShared<T>(shared: Shared<T>): T | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* A live value read from a {@link Shared}, for the `start` of a state. `undefined` while the source
|
|
13
|
+
* has nothing.
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* plugin.state.string("track", "Track", { start: following(player, (p) => p.track) });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare const following: <T, V>(shared: Shared<T>, pick: (value: NonNullable<T>) => V | undefined) => (set: (value: V | undefined) => void) => (() => void);
|
|
9
20
|
//# sourceMappingURL=shared.d.ts.map
|
package/dist/shared.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAEA,oFAAoF;AACpF,qBAAa,MAAM,CAAC,CAAC;;IAMnB,YAAY,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,KAAK,MAAM,IAAI,EAE1D;IAED,yDAAyD;IACzD,IAAI,IAAI,IAAI,CAAC,GAAG,SAAS,CAExB;IAED,MAAM,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI,CAgB/C;CACF;AAED,6FAA6F;AAC7F,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS,CAK7D;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,GACnB,CAAC,EAAE,CAAC,UAAU,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,SAAS,WAClE,CAAC,KAAK,EAAE,CAAC,GAAG,SAAS,KAAK,IAAI,KAAG,CAAC,MAAM,IAAI,CAWjD,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checking what the user entered. Fields say what is wrong in a sentence, or leave it to a schema
|
|
3
|
+
* from any library that follows Standard Schema (zod, valibot, arktype), without depending on one.
|
|
4
|
+
*/
|
|
5
|
+
import { type SettingsSchema } from "./settings.ts";
|
|
6
|
+
/** The part of https://standardschema.dev that checking a value needs. */
|
|
7
|
+
export interface StandardSchema {
|
|
8
|
+
readonly "~standard": {
|
|
9
|
+
readonly version: 1;
|
|
10
|
+
readonly vendor: string;
|
|
11
|
+
validate(value: unknown): StandardResult | Promise<StandardResult>;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
type StandardResult = {
|
|
15
|
+
readonly value: unknown;
|
|
16
|
+
readonly issues?: undefined;
|
|
17
|
+
} | {
|
|
18
|
+
readonly issues: readonly {
|
|
19
|
+
readonly message: string;
|
|
20
|
+
}[];
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Says what is wrong with a value, or nothing when it is fine. A schema only checks: what it would
|
|
24
|
+
* turn the value into is not used.
|
|
25
|
+
*/
|
|
26
|
+
export type Validator<T> = ((value: T) => string | undefined | void | Promise<string | undefined | void>) | StandardSchema;
|
|
27
|
+
/**
|
|
28
|
+
* What is wrong with `settings` (as `resolveSettings` gives them), by field. Fields that are not
|
|
29
|
+
* shown, and empty ones that are not `required`, are fine.
|
|
30
|
+
*/
|
|
31
|
+
export declare function checkSettings(schema: SettingsSchema, settings: Readonly<Record<string, unknown>>): Promise<Record<string, string>>;
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAqC,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAEvF,0EAA0E;AAC1E,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,WAAW,EAAE;QACpB,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;QACpB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;KACpE,CAAC;CACH;AAED,KAAK,cAAc,GACf;IAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,CAAA;CAAE,GACxD;IAAE,QAAQ,CAAC,MAAM,EAAE,SAAS;QAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;CAAE,CAAC;AAEjE;;;GAGG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IAErB,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC,CAAC,GAAG,cAAc,CAAC;AAelG;;;GAGG;AACH,wBAAsB,aAAa,CACjC,MAAM,EAAE,cAAc,EACtB,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAC1C,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAajC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sdeck/plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "SDK for sdeck plugins: actions that run headless or draw with React, live state, triggers and option sources.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"test": "bun test"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@sdeck/app": "0.
|
|
29
|
-
"@sdeck/engine": "0.
|
|
30
|
-
"@sdeck/schema": "0.
|
|
28
|
+
"@sdeck/app": "0.4.0",
|
|
29
|
+
"@sdeck/engine": "0.4.0",
|
|
30
|
+
"@sdeck/schema": "0.4.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"react": ">=19.3"
|
package/src/create.ts
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `createPlugin`: the parts of a plugin made from one object that knows its settings, permissions
|
|
3
|
+
* and namespace, so that each part is checked against them. What it makes is what `definePlugin`,
|
|
4
|
+
* `defineAction` and `defineTrigger` make.
|
|
5
|
+
*/
|
|
6
|
+
import { useHostState } from "./bridge.ts";
|
|
7
|
+
import type { Permission } from "./permissions.ts";
|
|
8
|
+
import {
|
|
9
|
+
type Action,
|
|
10
|
+
type ActionDef,
|
|
11
|
+
type Deactivate,
|
|
12
|
+
defineAction,
|
|
13
|
+
definePlugin,
|
|
14
|
+
defineTrigger,
|
|
15
|
+
type Onboarding,
|
|
16
|
+
type OptionSource,
|
|
17
|
+
type PluginCommand,
|
|
18
|
+
type PluginContext,
|
|
19
|
+
type PluginDef,
|
|
20
|
+
pluginNamespace,
|
|
21
|
+
type StateDef,
|
|
22
|
+
type Trigger,
|
|
23
|
+
type TriggerDef,
|
|
24
|
+
} from "./plugin.ts";
|
|
25
|
+
import type { InferSettings, SelectOption, SettingsSchema } from "./settings.ts";
|
|
26
|
+
|
|
27
|
+
/** A plugin's context with its own settings typed. */
|
|
28
|
+
export interface TypedContext<S extends SettingsSchema> extends PluginContext {
|
|
29
|
+
settings(): InferSettings<S>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** What every part of the plugin needs to know about it. */
|
|
33
|
+
export interface PluginBase<S extends SettingsSchema, P extends Permission>
|
|
34
|
+
extends Pick<
|
|
35
|
+
PluginDef,
|
|
36
|
+
"id" | "name" | "version" | "description" | "author" | "homepage" | "namespace"
|
|
37
|
+
> {
|
|
38
|
+
/** As on a plugin definition. Its parts can only need what is listed here. */
|
|
39
|
+
permissions?: readonly P[];
|
|
40
|
+
settings?: S;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The rest of it: the parts it offers. */
|
|
44
|
+
export interface PluginParts<S extends SettingsSchema> {
|
|
45
|
+
actions: readonly Action[];
|
|
46
|
+
/** What `plugin.state` made, and plain definitions. */
|
|
47
|
+
state?: readonly (StateHandle<unknown> | StateDef)[];
|
|
48
|
+
triggers?: readonly Trigger[];
|
|
49
|
+
/** What `plugin.source` made. */
|
|
50
|
+
sources?: readonly Source[];
|
|
51
|
+
commands?: readonly PluginCommand[];
|
|
52
|
+
onboarding?: Onboarding;
|
|
53
|
+
// biome-ignore lint/suspicious/noConfusingVoidType: lets `activate` simply not return anything.
|
|
54
|
+
activate?(context: TypedContext<S>): void | Deactivate | Promise<void | Deactivate>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Choices for `setting.pick`, `setting.text` and `setting.groups`. */
|
|
58
|
+
export interface Source {
|
|
59
|
+
readonly id: string;
|
|
60
|
+
readonly load: OptionSource;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** A live value of the plugin, published as `<namespace>.<id>`. */
|
|
64
|
+
export interface StateHandle<T> {
|
|
65
|
+
readonly def: StateDef;
|
|
66
|
+
/** Its name in expressions: `weather.temperature`. */
|
|
67
|
+
readonly key: string;
|
|
68
|
+
/** It as text in a look: `{{weather.temperature}}`. */
|
|
69
|
+
readonly template: string;
|
|
70
|
+
/** Publishes a value; `undefined` while there is none. Does nothing while the plugin is off. */
|
|
71
|
+
set(value: T | undefined): void;
|
|
72
|
+
get(): T | undefined;
|
|
73
|
+
/** In a component: the value, kept up to date. */
|
|
74
|
+
use(): T | undefined;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
type StateOptions<S extends SettingsSchema, P, T> = Omit<
|
|
78
|
+
StateDef,
|
|
79
|
+
"id" | "name" | "type" | "permissions" | "poll" | "start"
|
|
80
|
+
> & {
|
|
81
|
+
permissions?: readonly P[];
|
|
82
|
+
poll?: {
|
|
83
|
+
everyMs: number;
|
|
84
|
+
read(context: TypedContext<S>): T | undefined | Promise<T | undefined>;
|
|
85
|
+
};
|
|
86
|
+
// biome-ignore lint/suspicious/noConfusingVoidType: lets `start` simply not return anything.
|
|
87
|
+
start?(set: (value: T | undefined) => void, context: TypedContext<S>): (() => void) | void;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
type MakeState<S extends SettingsSchema, P, T> = (
|
|
91
|
+
id: string,
|
|
92
|
+
name: string,
|
|
93
|
+
options?: StateOptions<S, P, T>,
|
|
94
|
+
) => StateHandle<T>;
|
|
95
|
+
|
|
96
|
+
export interface PluginBuilder<S extends SettingsSchema, P extends Permission> {
|
|
97
|
+
readonly id: string;
|
|
98
|
+
readonly namespace: string;
|
|
99
|
+
/** The plugin's context while it runs, `undefined` while it is off. */
|
|
100
|
+
readonly context: TypedContext<S> | undefined;
|
|
101
|
+
/** An action, as `defineAction` makes it. */
|
|
102
|
+
action<const A extends SettingsSchema = Record<never, never>>(
|
|
103
|
+
def: ActionDef<A, TypedContext<S>, P>,
|
|
104
|
+
): Action;
|
|
105
|
+
/** A trigger, as `defineTrigger` makes it. */
|
|
106
|
+
trigger<const T extends SettingsSchema = Record<never, never>>(
|
|
107
|
+
def: TriggerDef<T, TypedContext<S>, P>,
|
|
108
|
+
): Trigger;
|
|
109
|
+
/** Live values, by type. */
|
|
110
|
+
readonly state: {
|
|
111
|
+
number: MakeState<S, P, number>;
|
|
112
|
+
string: MakeState<S, P, string>;
|
|
113
|
+
boolean: MakeState<S, P, boolean>;
|
|
114
|
+
json<T>(id: string, name: string, options?: StateOptions<S, P, T>): StateHandle<T>;
|
|
115
|
+
};
|
|
116
|
+
/** Choices fetched when a form opens. Pass it to `setting.pick`. */
|
|
117
|
+
source(
|
|
118
|
+
id: string,
|
|
119
|
+
load: (
|
|
120
|
+
context: TypedContext<S>,
|
|
121
|
+
settings: Readonly<Record<string, unknown>>,
|
|
122
|
+
) => SelectOption[] | Promise<SelectOption[]>,
|
|
123
|
+
): Source;
|
|
124
|
+
/** A button in the plugin's settings. */
|
|
125
|
+
command(def: PluginCommand<TypedContext<S>, P>): PluginCommand;
|
|
126
|
+
/** The finished plugin, for the module's default export. Only the parts listed are in it. */
|
|
127
|
+
define(parts: PluginParts<S>): PluginDef;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Starts a plugin:
|
|
132
|
+
*
|
|
133
|
+
* ```ts
|
|
134
|
+
* const plugin = createPlugin({
|
|
135
|
+
* id: "sdeck-plugin-weather",
|
|
136
|
+
* name: "Weather",
|
|
137
|
+
* version: "1.0.0",
|
|
138
|
+
* permissions: [Permissions.network],
|
|
139
|
+
* settings: { city: setting.text("City", { required: true }) },
|
|
140
|
+
* });
|
|
141
|
+
*
|
|
142
|
+
* const temperature = plugin.state.number("temperature", "Temperature", {
|
|
143
|
+
* unit: "°C",
|
|
144
|
+
* poll: { everyMs: 60_000, read: (context) => fetchTemperature(context.settings().city) },
|
|
145
|
+
* });
|
|
146
|
+
*
|
|
147
|
+
* const now = plugin.action({
|
|
148
|
+
* id: "now",
|
|
149
|
+
* name: "Temperature",
|
|
150
|
+
* display: true,
|
|
151
|
+
* look: () => iconLook({ icon: "lucide/sun", background: "#1e293b", caption: temperature.template }),
|
|
152
|
+
* });
|
|
153
|
+
*
|
|
154
|
+
* export default plugin.define({ actions: [now], state: [temperature] });
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
export function createPlugin<
|
|
158
|
+
const S extends SettingsSchema = Record<never, never>,
|
|
159
|
+
const P extends Permission = never,
|
|
160
|
+
>(base: PluginBase<S, P>): PluginBuilder<S, P> {
|
|
161
|
+
type Context = TypedContext<S>;
|
|
162
|
+
const namespace = pluginNamespace(base);
|
|
163
|
+
let context: Context | undefined;
|
|
164
|
+
|
|
165
|
+
const makeState =
|
|
166
|
+
(type: StateDef["type"]) =>
|
|
167
|
+
<T>(id: string, name: string, options: StateOptions<S, P, T> = {}): StateHandle<T> => {
|
|
168
|
+
const key = `${namespace}.${id}`;
|
|
169
|
+
return {
|
|
170
|
+
def: { ...options, id, name, type } as StateDef,
|
|
171
|
+
key,
|
|
172
|
+
template: `{{${key}}}`,
|
|
173
|
+
set: (value) => context?.state.set(id, value),
|
|
174
|
+
get: () => context?.state.get(key) as T | undefined,
|
|
175
|
+
use: () => useHostState(key) as T | undefined,
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
return {
|
|
180
|
+
id: base.id,
|
|
181
|
+
namespace,
|
|
182
|
+
get context() {
|
|
183
|
+
return context;
|
|
184
|
+
},
|
|
185
|
+
// The context every part gets at run time is the plugin's own: only its type is narrowed.
|
|
186
|
+
action: (def) => defineAction(def as unknown as ActionDef),
|
|
187
|
+
trigger: (def) => defineTrigger(def as unknown as TriggerDef),
|
|
188
|
+
state: {
|
|
189
|
+
number: makeState("number"),
|
|
190
|
+
string: makeState("string"),
|
|
191
|
+
boolean: makeState("boolean"),
|
|
192
|
+
json: makeState("json"),
|
|
193
|
+
},
|
|
194
|
+
source: (id, load) => ({ id, load: load as unknown as OptionSource }),
|
|
195
|
+
command: (def) => def as unknown as PluginCommand,
|
|
196
|
+
define: ({ state, sources, activate, ...parts }) =>
|
|
197
|
+
definePlugin({
|
|
198
|
+
...base,
|
|
199
|
+
...parts,
|
|
200
|
+
...(state && { state: state.map((s) => ("def" in s ? s.def : s)) }),
|
|
201
|
+
...(sources && {
|
|
202
|
+
optionSources: Object.fromEntries(sources.map((s) => [s.id, s.load])),
|
|
203
|
+
}),
|
|
204
|
+
activate: async (given) => {
|
|
205
|
+
context = given as Context;
|
|
206
|
+
let stop: Deactivate | undefined;
|
|
207
|
+
try {
|
|
208
|
+
stop = (await activate?.(context)) ?? undefined;
|
|
209
|
+
} catch (error) {
|
|
210
|
+
context = undefined;
|
|
211
|
+
throw error;
|
|
212
|
+
}
|
|
213
|
+
return async () => {
|
|
214
|
+
try {
|
|
215
|
+
await stop?.();
|
|
216
|
+
} finally {
|
|
217
|
+
context = undefined;
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
},
|
|
221
|
+
}),
|
|
222
|
+
};
|
|
223
|
+
}
|