@sdeck/plugin 0.1.0 → 0.3.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/bridge.d.ts +8 -2
- package/dist/bridge.d.ts.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +303 -2725
- package/dist/index.js.map +10 -29
- package/dist/permissions.d.ts +31 -0
- package/dist/permissions.d.ts.map +1 -0
- package/dist/plugin.d.ts +83 -10
- package/dist/plugin.d.ts.map +1 -1
- package/dist/settings.d.ts +52 -3
- package/dist/settings.d.ts.map +1 -1
- package/dist/text.d.ts +44 -0
- package/dist/text.d.ts.map +1 -0
- package/dist/ui.d.ts +4 -0
- package/dist/ui.d.ts.map +1 -0
- package/package.json +4 -4
- package/src/bridge.ts +8 -2
- package/src/index.ts +24 -2
- package/src/permissions.ts +125 -0
- package/src/plugin.ts +105 -28
- package/src/settings.ts +108 -7
- package/src/text.ts +192 -0
- package/src/ui.ts +3 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a plugin can ask to do. The user decides about each permission separately, and a plugin
|
|
3
|
+
* gets nothing it did not ask for and nothing the user did not allow.
|
|
4
|
+
*/
|
|
5
|
+
export type Permission = "network" | "filesystem" | "process" | "shell" | "input" | "clipboard" | "audio" | "environment" | "variables" | "state" | "actions" | "overlay" | "native";
|
|
6
|
+
/** A permission as the user reads it. */
|
|
7
|
+
export interface PermissionText {
|
|
8
|
+
name: string;
|
|
9
|
+
/** What allowing it makes possible. */
|
|
10
|
+
description: string;
|
|
11
|
+
/** Finishes "the plugin is not allowed to …". */
|
|
12
|
+
action: string;
|
|
13
|
+
/** Allowing it lets the plugin do nearly anything the user can. */
|
|
14
|
+
powerful?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/** Every permission, in the order the UI lists them. */
|
|
17
|
+
export declare const PERMISSION_TEXTS: Readonly<Record<Permission, PermissionText>>;
|
|
18
|
+
export declare const PERMISSIONS: readonly Permission[];
|
|
19
|
+
/** Thrown when a plugin does something the user has not allowed. The message is for the user. */
|
|
20
|
+
export declare class PermissionError extends Error {
|
|
21
|
+
readonly permission: Permission;
|
|
22
|
+
readonly name = "PermissionError";
|
|
23
|
+
/** As Node's file system reports a refused path, so libraries treat it the same way. */
|
|
24
|
+
readonly code = "EACCES";
|
|
25
|
+
constructor(
|
|
26
|
+
/** The plugin's name or id. */
|
|
27
|
+
plugin: string, permission: Permission,
|
|
28
|
+
/** What was refused, when that helps (a path, an address). */
|
|
29
|
+
detail?: string);
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=permissions.d.ts.map
|
|
@@ -0,0 +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"}
|
package/dist/plugin.d.ts
CHANGED
|
@@ -2,17 +2,13 @@ import type { SlotInfo } from "@sdeck/app";
|
|
|
2
2
|
import type { ExecSource, StateValueType } from "@sdeck/engine";
|
|
3
3
|
import type { Look, NavigateTarget } from "@sdeck/schema";
|
|
4
4
|
import type { ComponentType } from "react";
|
|
5
|
+
import { type Permission } from "./permissions.ts";
|
|
5
6
|
import { type InferSettings, type SelectOption, type SettingsSchema } from "./settings.ts";
|
|
7
|
+
import type { TextRow } from "./text.ts";
|
|
6
8
|
/** Bumped when the plugin contract changes incompatibly. Hosts refuse plugins built for another. */
|
|
7
9
|
export declare const PLUGIN_API_VERSION = 2;
|
|
8
10
|
/** Where an action can be placed. */
|
|
9
11
|
export type SlotKind = "key" | "sensor" | "window";
|
|
10
|
-
/**
|
|
11
|
-
* What a plugin declares it does. Shown to the user before enabling it. Plugins run in the host
|
|
12
|
-
* process, so this is information, not a sandbox.
|
|
13
|
-
*/
|
|
14
|
-
export type Permission = "shell" | "process" | "filesystem" | "network" | "input" | "audio" | "clipboard";
|
|
15
|
-
export declare const PERMISSIONS: readonly Permission[];
|
|
16
12
|
/** Given to a plugin's `activate`, its actions, state providers and triggers. */
|
|
17
13
|
export interface PluginContext {
|
|
18
14
|
readonly pluginId: string;
|
|
@@ -36,24 +32,74 @@ export interface PluginContext {
|
|
|
36
32
|
/** Live state: `set` publishes `<namespace>.<id>`, `get` reads any key (`system.cpu`). */
|
|
37
33
|
readonly state: {
|
|
38
34
|
set(id: string, value: unknown): void;
|
|
35
|
+
/** Keys of other plugins need the `state` permission. */
|
|
39
36
|
get(key: string): unknown;
|
|
37
|
+
/**
|
|
38
|
+
* Calls `listener` whenever one of `keys` changes, and keeps them up to date meanwhile (`get`
|
|
39
|
+
* alone does not). Returns a function that stops. Same permission as `get`.
|
|
40
|
+
*/
|
|
41
|
+
watch(keys: readonly string[], listener: () => void): () => void;
|
|
42
|
+
};
|
|
43
|
+
/** Pictures and text on top of the user's buttons. Needs the `overlay` permission. */
|
|
44
|
+
readonly overlays: {
|
|
45
|
+
/** Shows `overlay` on every deck, replacing this plugin's overlay called `id`. */
|
|
46
|
+
show(id: string, overlay: Overlay): void;
|
|
47
|
+
hide(id: string): void;
|
|
40
48
|
};
|
|
41
49
|
/** Emits `<namespace>:<event>` on the event bus (workflows can trigger on it). */
|
|
42
50
|
emit(event: string, payload?: unknown): void;
|
|
43
|
-
/** Global user variables. */
|
|
51
|
+
/** Global user variables. Needs the `variables` permission. */
|
|
44
52
|
readonly vars: {
|
|
45
53
|
get(name: string): unknown;
|
|
46
54
|
set(name: string, value: unknown): void;
|
|
47
55
|
};
|
|
48
56
|
}
|
|
57
|
+
/** Something drawn as one picture across several slots. The last one shown is on top. */
|
|
58
|
+
export interface Overlay {
|
|
59
|
+
/**
|
|
60
|
+
* The slots it covers: `key:0`, `sensor:1`, `window` (as a `slots` setting gives them). Leaving
|
|
61
|
+
* it out, or an empty list, covers the entire deck. Slots a deck does not have are skipped, and
|
|
62
|
+
* touch sensors show no text.
|
|
63
|
+
*/
|
|
64
|
+
slots?: readonly string[];
|
|
65
|
+
/** Shown on this page only (default: every page). */
|
|
66
|
+
page?: string;
|
|
67
|
+
/**
|
|
68
|
+
* What happens between slots, where a deck shows nothing. `keep`: the picture runs on behind
|
|
69
|
+
* the gaps, as through a window. `close`: slots are drawn as if they touched, so nothing is
|
|
70
|
+
* lost, which suits text. Default `keep`.
|
|
71
|
+
*/
|
|
72
|
+
gaps?: "keep" | "close";
|
|
73
|
+
/**
|
|
74
|
+
* Draws it, at the size of the whole overlay. Every slot draws all of it and shows its own
|
|
75
|
+
* part, so it must look the same in each: keep state outside, or in `@sdeck/plugin` hooks.
|
|
76
|
+
* Transparent parts show the buttons; `null` draws nothing.
|
|
77
|
+
*/
|
|
78
|
+
content: ComponentType<OverlayProps>;
|
|
79
|
+
}
|
|
80
|
+
export interface OverlayProps {
|
|
81
|
+
/** The size of the whole overlay. On a Neo these are pixels, and a key is 96×96. */
|
|
82
|
+
width: number;
|
|
83
|
+
height: number;
|
|
84
|
+
/**
|
|
85
|
+
* The rows of keys, or the window, it lies over, from the top, and how wide each is. Text reads best when no line is cut by the gap
|
|
86
|
+
* between two of them: `layoutText` places it so.
|
|
87
|
+
*/
|
|
88
|
+
rows: readonly TextRow[];
|
|
89
|
+
}
|
|
49
90
|
/** How a plugin's status reads: fine, needing attention, or failing. */
|
|
50
91
|
export type StatusLevel = "ok" | "info" | "error";
|
|
51
|
-
/** Something the user can run from the plugin's
|
|
92
|
+
/** Something the user can run from the plugin's settings (sign in, reconnect). */
|
|
52
93
|
export interface PluginCommand {
|
|
53
94
|
/** Unique within the plugin. */
|
|
54
95
|
id: string;
|
|
55
96
|
name: string;
|
|
56
97
|
description?: string;
|
|
98
|
+
/**
|
|
99
|
+
* What it needs, out of the plugin's `permissions` (default: all of them; `[]` for nothing).
|
|
100
|
+
* Without them it is refused.
|
|
101
|
+
*/
|
|
102
|
+
permissions?: readonly Permission[];
|
|
57
103
|
/** What it returns, if a string, is opened in the user's browser. Throw to fail. */
|
|
58
104
|
run(context: PluginContext): unknown | Promise<unknown>;
|
|
59
105
|
}
|
|
@@ -178,9 +224,19 @@ export interface ActionDef<S extends SettingsSchema = SettingsSchema> {
|
|
|
178
224
|
slots?: readonly SlotKind[];
|
|
179
225
|
/** Settings shown in the UI, as a form. */
|
|
180
226
|
settings?: S;
|
|
227
|
+
/**
|
|
228
|
+
* What it needs, out of the plugin's `permissions` (default: all of them; `[]` for nothing).
|
|
229
|
+
* Without them it cannot run or draw itself.
|
|
230
|
+
*/
|
|
231
|
+
permissions?: readonly Permission[];
|
|
232
|
+
/**
|
|
233
|
+
* It only shows something. It is offered for buttons, but not as a step of a workflow or
|
|
234
|
+
* gesture, and needs no `run`.
|
|
235
|
+
*/
|
|
236
|
+
display?: boolean;
|
|
181
237
|
/**
|
|
182
238
|
* Does the work, without drawing anything: it can run from a key, a trigger or a workflow.
|
|
183
|
-
* Throw to fail. An action needs `run`, `component`, or both
|
|
239
|
+
* Throw to fail. An action needs `run`, `component`, or both, unless it is `display`.
|
|
184
240
|
*/
|
|
185
241
|
run?(context: RunContext<S>): RunResult | void | Promise<RunResult | void>;
|
|
186
242
|
/**
|
|
@@ -202,6 +258,8 @@ export interface Action {
|
|
|
202
258
|
readonly icon?: string;
|
|
203
259
|
readonly slots: readonly SlotKind[];
|
|
204
260
|
readonly settings: SettingsSchema;
|
|
261
|
+
readonly permissions?: readonly Permission[];
|
|
262
|
+
readonly display?: boolean;
|
|
205
263
|
readonly run?: RunFn;
|
|
206
264
|
readonly component?: ComponentType<ActionProps>;
|
|
207
265
|
readonly look?: (settings: Record<string, unknown>) => Look;
|
|
@@ -214,6 +272,11 @@ export interface StateDef {
|
|
|
214
272
|
type: StateValueType;
|
|
215
273
|
unit?: string;
|
|
216
274
|
description?: string;
|
|
275
|
+
/**
|
|
276
|
+
* What reading it needs, out of the plugin's `permissions` (default: all of them; `[]` for nothing).
|
|
277
|
+
* Without them it has no value.
|
|
278
|
+
*/
|
|
279
|
+
permissions?: readonly Permission[];
|
|
217
280
|
/** Read every `everyMs` while something shows or waits on the value. */
|
|
218
281
|
poll?: {
|
|
219
282
|
everyMs: number;
|
|
@@ -235,6 +298,11 @@ export interface TriggerDef<S extends SettingsSchema = SettingsSchema> {
|
|
|
235
298
|
name: string;
|
|
236
299
|
description?: string;
|
|
237
300
|
settings?: S;
|
|
301
|
+
/**
|
|
302
|
+
* What it needs, out of the plugin's `permissions` (default: all of them; `[]` for nothing).
|
|
303
|
+
* Without them it never fires.
|
|
304
|
+
*/
|
|
305
|
+
permissions?: readonly Permission[];
|
|
238
306
|
/** Starts watching; returns a function that stops. */
|
|
239
307
|
subscribe(context: TriggerContext<S>): (() => void) | void;
|
|
240
308
|
}
|
|
@@ -243,6 +311,7 @@ export interface Trigger {
|
|
|
243
311
|
readonly name: string;
|
|
244
312
|
readonly description?: string;
|
|
245
313
|
readonly settings: SettingsSchema;
|
|
314
|
+
readonly permissions?: readonly Permission[];
|
|
246
315
|
readonly subscribe: (context: TriggerContext) => (() => void) | undefined;
|
|
247
316
|
}
|
|
248
317
|
/**
|
|
@@ -267,10 +336,14 @@ export interface PluginDef {
|
|
|
267
336
|
state?: readonly StateDef[];
|
|
268
337
|
triggers?: readonly Trigger[];
|
|
269
338
|
optionSources?: Readonly<Record<string, OptionSource>>;
|
|
339
|
+
/**
|
|
340
|
+
* Everything the plugin asks to be allowed to do. The user decides about each one, and can
|
|
341
|
+
* change their mind at any time: handle being refused. What is not listed is never allowed.
|
|
342
|
+
*/
|
|
270
343
|
permissions?: readonly Permission[];
|
|
271
344
|
/** The plugin's own settings (a server address, a token), shown on its page. */
|
|
272
345
|
settings?: SettingsSchema;
|
|
273
|
-
/** Buttons
|
|
346
|
+
/** Buttons in the plugin's settings. */
|
|
274
347
|
commands?: readonly PluginCommand[];
|
|
275
348
|
/**
|
|
276
349
|
* How to set the plugin up, step by step, shown after it is installed. Without it, Studio asks
|
package/dist/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,cAAc,EACpB,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin.d.ts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C;IACpC,gFAAgF;IAChF,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,wCAAwC;IACxC,QAAQ,CAAC,EAAE,SAAS,aAAa,EAAE,CAAC;IACpC;;;OAGG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,wFAAwF;IAExF,QAAQ,CAAC,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,GAAG,UAAU,GAAG,OAAO,CAAC,IAAI,GAAG,UAAU,CAAC,CAAC;CACnF;AAMD,qDAAqD;AACrD,wBAAgB,eAAe,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,GAAG,WAAW,CAAC,GAAG,MAAM,CAShF;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,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"}
|
package/dist/settings.d.ts
CHANGED
|
@@ -8,6 +8,11 @@ interface FieldBase {
|
|
|
8
8
|
label: string;
|
|
9
9
|
/** Help text under the field. */
|
|
10
10
|
description?: string;
|
|
11
|
+
/**
|
|
12
|
+
* It only changes how the button looks. It is asked for on a button, but not in a step of a
|
|
13
|
+
* workflow or gesture, where nothing is drawn.
|
|
14
|
+
*/
|
|
15
|
+
appearance?: boolean;
|
|
11
16
|
/**
|
|
12
17
|
* Shown only while other fields have these values: `{ to: "page" }` or
|
|
13
18
|
* `{ mode: ["a", "b"] }`. Hidden fields keep their value.
|
|
@@ -23,6 +28,11 @@ export interface TextField extends FieldBase {
|
|
|
23
28
|
source?: string;
|
|
24
29
|
/** Other fields the suggestions depend on, passed to the source. */
|
|
25
30
|
dependsOn?: readonly string[];
|
|
31
|
+
/**
|
|
32
|
+
* `{{templates}}` in it reach `run` as they were written, for drawing with `useTemplate` so the
|
|
33
|
+
* text follows their values. Ones that read the run itself (`event`, `loop`…) are filled in.
|
|
34
|
+
*/
|
|
35
|
+
live?: boolean;
|
|
26
36
|
}
|
|
27
37
|
export interface NumberField extends FieldBase {
|
|
28
38
|
type: "number";
|
|
@@ -73,29 +83,68 @@ export interface SelectField extends FieldBase {
|
|
|
73
83
|
export interface PageField extends FieldBase {
|
|
74
84
|
type: "page";
|
|
75
85
|
default?: string;
|
|
86
|
+
/** Offers choosing no page (an empty value), under this name: `Every page`. */
|
|
87
|
+
none?: string;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Keys, touch sensors and the window, picked on a picture of the deck: `key:0`, `sensor:1`,
|
|
91
|
+
* `window`. An empty list stands for the entire deck.
|
|
92
|
+
*/
|
|
93
|
+
export interface SlotsField extends FieldBase {
|
|
94
|
+
type: "slots";
|
|
95
|
+
default?: readonly string[];
|
|
76
96
|
}
|
|
77
97
|
/** An image: an `http(s)` URL or a `data:` URI (the UI accepts a URL or a file). */
|
|
78
98
|
export interface ImageField extends FieldBase {
|
|
79
99
|
type: "image";
|
|
80
100
|
default?: string;
|
|
101
|
+
/** As on a text field: `{{spotify.art}}` reaches `run` as written. */
|
|
102
|
+
live?: boolean;
|
|
103
|
+
}
|
|
104
|
+
/** A named set the user made of options, from a `groups` field. */
|
|
105
|
+
export interface OptionGroup {
|
|
106
|
+
/** Stays the same when the group is renamed; refer to the group by it. */
|
|
107
|
+
id: string;
|
|
108
|
+
name: string;
|
|
109
|
+
/** The chosen options' values. */
|
|
110
|
+
members: readonly string[];
|
|
111
|
+
}
|
|
112
|
+
/** Named sets of options the user puts together (rooms of lights), only for a plugin's own settings. */
|
|
113
|
+
export interface GroupsField extends FieldBase {
|
|
114
|
+
type: "groups";
|
|
115
|
+
/** The plugin's `optionSources` entry that lists what a group can contain. */
|
|
116
|
+
source: string;
|
|
117
|
+
/** What a group contains, for the form, e.g. `lights` (default: `items`). */
|
|
118
|
+
noun?: string;
|
|
119
|
+
default?: readonly OptionGroup[];
|
|
81
120
|
}
|
|
82
|
-
export type SettingField = TextField | NumberField | BooleanField | ColorField | SelectField | PageField | ImageField | SecretField;
|
|
121
|
+
export type SettingField = TextField | NumberField | BooleanField | ColorField | SelectField | PageField | SlotsField | ImageField | GroupsField | SecretField;
|
|
83
122
|
export type SettingsSchema = Readonly<Record<string, SettingField>>;
|
|
84
123
|
/** The value type of one field. */
|
|
85
|
-
export type FieldValue<F extends SettingField> = F extends NumberField ? number : F extends BooleanField ? boolean : F extends SelectField ? F extends {
|
|
124
|
+
export type FieldValue<F extends SettingField> = F extends NumberField ? number : F extends BooleanField ? boolean : F extends GroupsField ? readonly OptionGroup[] : F extends SlotsField ? readonly string[] : F extends SelectField ? F extends {
|
|
86
125
|
source: string;
|
|
87
126
|
} ? string : F["options"][number]["value"] : string;
|
|
127
|
+
/** A value of any field. */
|
|
128
|
+
export type SettingValue = Primitive | readonly OptionGroup[] | readonly string[];
|
|
88
129
|
/** The settings object an action receives for a schema. */
|
|
89
130
|
export type InferSettings<S extends SettingsSchema> = {
|
|
90
131
|
-readonly [K in keyof S]: FieldValue<S[K]>;
|
|
91
132
|
};
|
|
92
133
|
/** The value a field takes when nothing (valid) is stored. */
|
|
93
|
-
export declare function defaultValue(field: SettingField):
|
|
134
|
+
export declare function defaultValue(field: SettingField): SettingValue;
|
|
135
|
+
/** The valid groups in a stored value, or `undefined` if it isn't a list. */
|
|
136
|
+
export declare function optionGroups(value: unknown): OptionGroup[] | undefined;
|
|
137
|
+
/** The slots in a stored value, or `undefined` if it isn't a list. */
|
|
138
|
+
export declare function slotList(value: unknown): string[] | undefined;
|
|
94
139
|
/**
|
|
95
140
|
* Stored settings, made safe: every field of `schema` is present and of the right type (invalid
|
|
96
141
|
* or missing values get the default, numbers are clamped), and unknown keys are dropped.
|
|
97
142
|
*/
|
|
98
143
|
export declare function resolveSettings<S extends SettingsSchema>(schema: S, stored: Readonly<Record<string, unknown>> | undefined): InferSettings<S>;
|
|
144
|
+
/** The fields that change what an action does, without those for how its button looks. */
|
|
145
|
+
export declare function behaviorFields(schema: SettingsSchema): SettingsSchema;
|
|
146
|
+
/** The settings whose templates are left for the action to keep up to date. */
|
|
147
|
+
export declare function liveSettings(schema: SettingsSchema): string[];
|
|
99
148
|
/** Whether `field` is shown for these (resolved) settings. */
|
|
100
149
|
export declare function isFieldVisible(field: SettingField, settings: Readonly<Record<string, unknown>>): boolean;
|
|
101
150
|
/**
|
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;AAEH,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAE3C,UAAU,SAAS;IACjB,2CAA2C;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,iCAAiC;IACjC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;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;IAC1C,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,oEAA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;AAED,6EAA6E;AAC7E,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,EAAE,GAAG,SAAS,CAetE;AAID,sEAAsE;AACtE,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,EAAE,GAAG,SAAS,CAG7D;AA4BD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,cAAc,EACtD,MAAM,EAAE,CAAC,EACT,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,SAAS,GACpD,aAAa,CAAC,CAAC,CAAC,CAIlB;AAED,0FAA0F;AAC1F,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,GAAG,cAAc,CAErE;AAED,+EAA+E;AAC/E,wBAAgB,YAAY,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,EAAE,CAI7D;AAED,8DAA8D;AAC9D,wBAAgB,cAAc,CAC5B,KAAK,EAAE,YAAY,EACnB,QAAQ,EAAE,QAAQ,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,CA2CV"}
|
package/dist/text.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** Choosing a text size without laying the text out. */
|
|
2
|
+
/** A stretch of height text can be in, such as one row of keys. */
|
|
3
|
+
export interface TextRow {
|
|
4
|
+
top: number;
|
|
5
|
+
height: number;
|
|
6
|
+
/** Where it starts and how wide it is, when that is not all of the width. */
|
|
7
|
+
left?: number;
|
|
8
|
+
width?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface TextLayoutOptions {
|
|
11
|
+
width: number;
|
|
12
|
+
/** Each line goes into one of these, whole: pass an overlay's `rows`. */
|
|
13
|
+
rows: readonly TextRow[];
|
|
14
|
+
/** The smallest size to go down to, even if the text then does not fit (default 8). */
|
|
15
|
+
min?: number;
|
|
16
|
+
/** The largest size (default: whatever fits). */
|
|
17
|
+
max?: number;
|
|
18
|
+
/** Line height, as a multiple of the size (default 1.2). */
|
|
19
|
+
lineHeight?: number;
|
|
20
|
+
/** Where lines go when there is room to spare (default `middle`). */
|
|
21
|
+
position?: "top" | "middle" | "bottom";
|
|
22
|
+
}
|
|
23
|
+
export interface TextLayout {
|
|
24
|
+
size: number;
|
|
25
|
+
/** The lines: where they are in the text, and the place each one has. */
|
|
26
|
+
lines: {
|
|
27
|
+
text: string;
|
|
28
|
+
start: number;
|
|
29
|
+
end: number;
|
|
30
|
+
top: number;
|
|
31
|
+
left: number;
|
|
32
|
+
width: number;
|
|
33
|
+
}[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Breaks text into lines and finds the largest font size at which they fit. It goes by how wide
|
|
37
|
+
* characters of the built-in font usually are, so leave a little room at the sides.
|
|
38
|
+
*/
|
|
39
|
+
export declare function layoutText(text: string, options: TextLayoutOptions): TextLayout;
|
|
40
|
+
/** The largest font size at which `text`, wrapped between words, fits a box. */
|
|
41
|
+
export declare function fitText(text: string, { height, ...options }: Omit<TextLayoutOptions, "rows" | "position"> & {
|
|
42
|
+
height: number;
|
|
43
|
+
}): number;
|
|
44
|
+
//# sourceMappingURL=text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../src/text.ts"],"names":[],"mappings":"AAAA,wDAAwD;AAiExD,mEAAmE;AACnE,MAAM,WAAW,OAAO;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,6EAA6E;IAC7E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,yEAAyE;IACzE,IAAI,EAAE,SAAS,OAAO,EAAE,CAAC;IACzB,uFAAuF;IACvF,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,iDAAiD;IACjD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,4DAA4D;IAC5D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qEAAqE;IACrE,QAAQ,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,QAAQ,CAAC;CACxC;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,yEAAyE;IACzE,KAAK,EAAE;QACL,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;KACf,EAAE,CAAC;CACL;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAG,UAAU,CA8E/E;AAED,gFAAgF;AAChF,wBAAgB,OAAO,CACrB,IAAI,EAAE,MAAM,EACZ,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,EAAE,IAAI,CAAC,iBAAiB,EAAE,MAAM,GAAG,UAAU,CAAC,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GACxF,MAAM,CAER"}
|
package/dist/ui.d.ts
ADDED
package/dist/ui.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ui.d.ts","sourceRoot":"","sources":["../src/ui.ts"],"names":[],"mappings":"AAAA,qGAAqG;AACrG,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sdeck/plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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.3.0",
|
|
29
|
+
"@sdeck/engine": "0.3.0",
|
|
30
|
+
"@sdeck/schema": "0.3.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"react": ">=19.3"
|
package/src/bridge.ts
CHANGED
|
@@ -75,7 +75,10 @@ function useWatched<T>(paths: readonly string[], read: () => T): T {
|
|
|
75
75
|
return useSyncExternalStore(subscribe, snapshot);
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
/**
|
|
78
|
+
/**
|
|
79
|
+
* The value of an expression (`system.cpu > 80`, `vars.mode`), kept up to date. Values the plugin
|
|
80
|
+
* is not allowed to read (`state`, `variables`) are missing.
|
|
81
|
+
*/
|
|
79
82
|
export function useExpression(source: string): unknown {
|
|
80
83
|
const bridge = useBridge();
|
|
81
84
|
const expression = useMemo(() => compile(source), [source]);
|
|
@@ -111,7 +114,10 @@ export function useVariable(name: string): [unknown, (value: unknown) => void] {
|
|
|
111
114
|
return [value, set];
|
|
112
115
|
}
|
|
113
116
|
|
|
114
|
-
/**
|
|
117
|
+
/**
|
|
118
|
+
* Runs an action from a component (`run("@sdeck/plugin-system", "open", {...})`).
|
|
119
|
+
* Other plugins' actions need the `actions` permission.
|
|
120
|
+
*/
|
|
115
121
|
export function useRunAction(): HostBridge["run"] {
|
|
116
122
|
return useBridge().run;
|
|
117
123
|
}
|
package/src/index.ts
CHANGED
|
@@ -29,6 +29,13 @@ export {
|
|
|
29
29
|
parseManifest,
|
|
30
30
|
SUPPORTED_API_VERSIONS,
|
|
31
31
|
} from "./manifest.ts";
|
|
32
|
+
export {
|
|
33
|
+
PERMISSION_TEXTS,
|
|
34
|
+
PERMISSIONS,
|
|
35
|
+
type Permission,
|
|
36
|
+
PermissionError,
|
|
37
|
+
type PermissionText,
|
|
38
|
+
} from "./permissions.ts";
|
|
32
39
|
export {
|
|
33
40
|
type Action,
|
|
34
41
|
type ActionDef,
|
|
@@ -42,8 +49,8 @@ export {
|
|
|
42
49
|
type Onboarding,
|
|
43
50
|
type OnboardingStep,
|
|
44
51
|
type OptionSource,
|
|
45
|
-
|
|
46
|
-
type
|
|
52
|
+
type Overlay,
|
|
53
|
+
type OverlayProps,
|
|
47
54
|
PLUGIN_API_VERSION,
|
|
48
55
|
type PluginCommand,
|
|
49
56
|
type PluginContext,
|
|
@@ -63,14 +70,19 @@ export {
|
|
|
63
70
|
} from "./plugin.ts";
|
|
64
71
|
export {
|
|
65
72
|
type BooleanField,
|
|
73
|
+
behaviorFields,
|
|
66
74
|
type ColorField,
|
|
67
75
|
checkSchema,
|
|
68
76
|
defaultValue,
|
|
69
77
|
type FieldValue,
|
|
78
|
+
type GroupsField,
|
|
70
79
|
type ImageField,
|
|
71
80
|
type InferSettings,
|
|
72
81
|
isFieldVisible,
|
|
82
|
+
liveSettings,
|
|
73
83
|
type NumberField,
|
|
84
|
+
type OptionGroup,
|
|
85
|
+
optionGroups,
|
|
74
86
|
type PageField,
|
|
75
87
|
resolveSettings,
|
|
76
88
|
type SecretField,
|
|
@@ -78,6 +90,16 @@ export {
|
|
|
78
90
|
type SelectOption,
|
|
79
91
|
type SettingField,
|
|
80
92
|
type SettingsSchema,
|
|
93
|
+
type SettingValue,
|
|
94
|
+
type SlotsField,
|
|
95
|
+
slotList,
|
|
81
96
|
type TextField,
|
|
82
97
|
} from "./settings.ts";
|
|
83
98
|
export { Shared } from "./shared.ts";
|
|
99
|
+
export {
|
|
100
|
+
fitText,
|
|
101
|
+
layoutText,
|
|
102
|
+
type TextLayout,
|
|
103
|
+
type TextLayoutOptions,
|
|
104
|
+
type TextRow,
|
|
105
|
+
} from "./text.ts";
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a plugin can ask to do. The user decides about each permission separately, and a plugin
|
|
3
|
+
* gets nothing it did not ask for and nothing the user did not allow.
|
|
4
|
+
*/
|
|
5
|
+
export type Permission =
|
|
6
|
+
| "network"
|
|
7
|
+
| "filesystem"
|
|
8
|
+
| "process"
|
|
9
|
+
| "shell"
|
|
10
|
+
| "input"
|
|
11
|
+
| "clipboard"
|
|
12
|
+
| "audio"
|
|
13
|
+
| "environment"
|
|
14
|
+
| "variables"
|
|
15
|
+
| "state"
|
|
16
|
+
| "actions"
|
|
17
|
+
| "overlay"
|
|
18
|
+
| "native";
|
|
19
|
+
|
|
20
|
+
/** A permission as the user reads it. */
|
|
21
|
+
export interface PermissionText {
|
|
22
|
+
name: string;
|
|
23
|
+
/** What allowing it makes possible. */
|
|
24
|
+
description: string;
|
|
25
|
+
/** Finishes "the plugin is not allowed to …". */
|
|
26
|
+
action: string;
|
|
27
|
+
/** Allowing it lets the plugin do nearly anything the user can. */
|
|
28
|
+
powerful?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Every permission, in the order the UI lists them. */
|
|
32
|
+
export const PERMISSION_TEXTS: Readonly<Record<Permission, PermissionText>> = {
|
|
33
|
+
network: {
|
|
34
|
+
name: "Network",
|
|
35
|
+
description: "Connect to the internet and to devices on your network.",
|
|
36
|
+
action: "use the network",
|
|
37
|
+
},
|
|
38
|
+
filesystem: {
|
|
39
|
+
name: "Files",
|
|
40
|
+
description: "Read and change your files. Its own data folder is always allowed.",
|
|
41
|
+
action: "use files outside its own folder",
|
|
42
|
+
},
|
|
43
|
+
process: {
|
|
44
|
+
name: "Start programs",
|
|
45
|
+
description: "Open apps and run programs that are installed on this computer.",
|
|
46
|
+
action: "start programs",
|
|
47
|
+
powerful: true,
|
|
48
|
+
},
|
|
49
|
+
shell: {
|
|
50
|
+
name: "Run commands",
|
|
51
|
+
description: "Run any command line. Commands can do everything you can.",
|
|
52
|
+
action: "run commands",
|
|
53
|
+
powerful: true,
|
|
54
|
+
},
|
|
55
|
+
input: {
|
|
56
|
+
name: "Keyboard and mouse",
|
|
57
|
+
description: "Press keys, type text and control media playback.",
|
|
58
|
+
action: "press keys",
|
|
59
|
+
},
|
|
60
|
+
clipboard: {
|
|
61
|
+
name: "Clipboard",
|
|
62
|
+
description: "Read and change what you copied.",
|
|
63
|
+
action: "use the clipboard",
|
|
64
|
+
},
|
|
65
|
+
audio: {
|
|
66
|
+
name: "Sound",
|
|
67
|
+
description: "Change volumes, mute apps and switch audio devices.",
|
|
68
|
+
action: "control sound",
|
|
69
|
+
},
|
|
70
|
+
environment: {
|
|
71
|
+
name: "Environment variables",
|
|
72
|
+
description: "Read environment variables, which can contain keys and tokens.",
|
|
73
|
+
action: "read environment variables",
|
|
74
|
+
},
|
|
75
|
+
variables: {
|
|
76
|
+
name: "Your variables",
|
|
77
|
+
description: "Read and change the variables your workflows use.",
|
|
78
|
+
action: "use your variables",
|
|
79
|
+
},
|
|
80
|
+
state: {
|
|
81
|
+
name: "Other plugins' values",
|
|
82
|
+
description: "Read live values from other plugins, such as the app in front.",
|
|
83
|
+
action: "read other plugins' values",
|
|
84
|
+
},
|
|
85
|
+
actions: {
|
|
86
|
+
name: "Other plugins' actions",
|
|
87
|
+
description: "Run actions of other plugins, with the permissions those have.",
|
|
88
|
+
action: "run other plugins' actions",
|
|
89
|
+
powerful: true,
|
|
90
|
+
},
|
|
91
|
+
overlay: {
|
|
92
|
+
name: "Draw over buttons",
|
|
93
|
+
description: "Show images and text on top of any of your buttons.",
|
|
94
|
+
action: "draw over your buttons",
|
|
95
|
+
},
|
|
96
|
+
native: {
|
|
97
|
+
name: "Native code",
|
|
98
|
+
description: "Load compiled code, which sdeck cannot limit in any way.",
|
|
99
|
+
action: "load native code",
|
|
100
|
+
powerful: true,
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export const PERMISSIONS = Object.keys(PERMISSION_TEXTS) as readonly Permission[];
|
|
105
|
+
|
|
106
|
+
/** Thrown when a plugin does something the user has not allowed. The message is for the user. */
|
|
107
|
+
export class PermissionError extends Error {
|
|
108
|
+
override readonly name = "PermissionError";
|
|
109
|
+
/** As Node's file system reports a refused path, so libraries treat it the same way. */
|
|
110
|
+
readonly code = "EACCES";
|
|
111
|
+
|
|
112
|
+
constructor(
|
|
113
|
+
/** The plugin's name or id. */
|
|
114
|
+
plugin: string,
|
|
115
|
+
readonly permission: Permission,
|
|
116
|
+
/** What was refused, when that helps (a path, an address). */
|
|
117
|
+
detail?: string,
|
|
118
|
+
) {
|
|
119
|
+
const { name, action } = PERMISSION_TEXTS[permission];
|
|
120
|
+
super(
|
|
121
|
+
`${plugin} is not allowed to ${action}${detail ? ` (${detail})` : ""}. ` +
|
|
122
|
+
`Allow "${name}" in the plugin's permissions.`,
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
}
|