@sdeck/plugin 0.3.1 → 0.4.1
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 +7 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +200 -5
- package/dist/index.js.map +13 -10
- package/dist/manifest.d.ts +10 -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 +15 -1
- package/src/manifest.ts +23 -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/create.d.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { Permission } from "./permissions.ts";
|
|
2
|
+
import { type Action, type ActionDef, type Deactivate, type Onboarding, type OptionSource, type PluginCommand, type PluginContext, type PluginDef, type StateDef, type Trigger, type TriggerDef } from "./plugin.ts";
|
|
3
|
+
import type { InferSettings, SelectOption, SettingsSchema } from "./settings.ts";
|
|
4
|
+
/** A plugin's context with its own settings typed. */
|
|
5
|
+
export interface TypedContext<S extends SettingsSchema> extends PluginContext {
|
|
6
|
+
settings(): InferSettings<S>;
|
|
7
|
+
}
|
|
8
|
+
/** What every part of the plugin needs to know about it. */
|
|
9
|
+
export interface PluginBase<S extends SettingsSchema, P extends Permission> extends Pick<PluginDef, "id" | "name" | "version" | "description" | "author" | "homepage" | "namespace"> {
|
|
10
|
+
/** As on a plugin definition. Its parts can only need what is listed here. */
|
|
11
|
+
permissions?: readonly P[];
|
|
12
|
+
settings?: S;
|
|
13
|
+
}
|
|
14
|
+
/** The rest of it: the parts it offers. */
|
|
15
|
+
export interface PluginParts<S extends SettingsSchema> {
|
|
16
|
+
actions: readonly Action[];
|
|
17
|
+
/** What `plugin.state` made, and plain definitions. */
|
|
18
|
+
state?: readonly (StateHandle<unknown> | StateDef)[];
|
|
19
|
+
triggers?: readonly Trigger[];
|
|
20
|
+
/** What `plugin.source` made. */
|
|
21
|
+
sources?: readonly Source[];
|
|
22
|
+
commands?: readonly PluginCommand[];
|
|
23
|
+
onboarding?: Onboarding;
|
|
24
|
+
activate?(context: TypedContext<S>): void | Deactivate | Promise<void | Deactivate>;
|
|
25
|
+
}
|
|
26
|
+
/** Choices for `setting.pick`, `setting.text` and `setting.groups`. */
|
|
27
|
+
export interface Source {
|
|
28
|
+
readonly id: string;
|
|
29
|
+
readonly load: OptionSource;
|
|
30
|
+
}
|
|
31
|
+
/** A live value of the plugin, published as `<namespace>.<id>`. */
|
|
32
|
+
export interface StateHandle<T> {
|
|
33
|
+
readonly def: StateDef;
|
|
34
|
+
/** Its name in expressions: `weather.temperature`. */
|
|
35
|
+
readonly key: string;
|
|
36
|
+
/** It as text in a look: `{{weather.temperature}}`. */
|
|
37
|
+
readonly template: string;
|
|
38
|
+
/** Publishes a value; `undefined` while there is none. Does nothing while the plugin is off. */
|
|
39
|
+
set(value: T | undefined): void;
|
|
40
|
+
get(): T | undefined;
|
|
41
|
+
/** In a component: the value, kept up to date. */
|
|
42
|
+
use(): T | undefined;
|
|
43
|
+
}
|
|
44
|
+
type StateOptions<S extends SettingsSchema, P, T> = Omit<StateDef, "id" | "name" | "type" | "permissions" | "poll" | "start"> & {
|
|
45
|
+
permissions?: readonly P[];
|
|
46
|
+
poll?: {
|
|
47
|
+
everyMs: number;
|
|
48
|
+
read(context: TypedContext<S>): T | undefined | Promise<T | undefined>;
|
|
49
|
+
};
|
|
50
|
+
start?(set: (value: T | undefined) => void, context: TypedContext<S>): (() => void) | void;
|
|
51
|
+
};
|
|
52
|
+
type MakeState<S extends SettingsSchema, P, T> = (id: string, name: string, options?: StateOptions<S, P, T>) => StateHandle<T>;
|
|
53
|
+
export interface PluginBuilder<S extends SettingsSchema, P extends Permission> {
|
|
54
|
+
readonly id: string;
|
|
55
|
+
readonly namespace: string;
|
|
56
|
+
/** The plugin's context while it runs, `undefined` while it is off. */
|
|
57
|
+
readonly context: TypedContext<S> | undefined;
|
|
58
|
+
/** An action, as `defineAction` makes it. */
|
|
59
|
+
action<const A extends SettingsSchema = Record<never, never>>(def: ActionDef<A, TypedContext<S>, P>): Action;
|
|
60
|
+
/** A trigger, as `defineTrigger` makes it. */
|
|
61
|
+
trigger<const T extends SettingsSchema = Record<never, never>>(def: TriggerDef<T, TypedContext<S>, P>): Trigger;
|
|
62
|
+
/** Live values, by type. */
|
|
63
|
+
readonly state: {
|
|
64
|
+
number: MakeState<S, P, number>;
|
|
65
|
+
string: MakeState<S, P, string>;
|
|
66
|
+
boolean: MakeState<S, P, boolean>;
|
|
67
|
+
json<T>(id: string, name: string, options?: StateOptions<S, P, T>): StateHandle<T>;
|
|
68
|
+
};
|
|
69
|
+
/** Choices fetched when a form opens. Pass it to `setting.pick`. */
|
|
70
|
+
source(id: string, load: (context: TypedContext<S>, settings: Readonly<Record<string, unknown>>) => SelectOption[] | Promise<SelectOption[]>): Source;
|
|
71
|
+
/** A button in the plugin's settings. */
|
|
72
|
+
command(def: PluginCommand<TypedContext<S>, P>): PluginCommand;
|
|
73
|
+
/** The finished plugin, for the module's default export. Only the parts listed are in it. */
|
|
74
|
+
define(parts: PluginParts<S>): PluginDef;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Starts a plugin:
|
|
78
|
+
*
|
|
79
|
+
* ```ts
|
|
80
|
+
* const plugin = createPlugin({
|
|
81
|
+
* id: "sdeck-plugin-weather",
|
|
82
|
+
* name: "Weather",
|
|
83
|
+
* version: "1.0.0",
|
|
84
|
+
* permissions: [Permissions.network],
|
|
85
|
+
* settings: { city: setting.text("City", { required: true }) },
|
|
86
|
+
* });
|
|
87
|
+
*
|
|
88
|
+
* const temperature = plugin.state.number("temperature", "Temperature", {
|
|
89
|
+
* unit: "°C",
|
|
90
|
+
* poll: { everyMs: 60_000, read: (context) => fetchTemperature(context.settings().city) },
|
|
91
|
+
* });
|
|
92
|
+
*
|
|
93
|
+
* const now = plugin.action({
|
|
94
|
+
* id: "now",
|
|
95
|
+
* name: "Temperature",
|
|
96
|
+
* display: true,
|
|
97
|
+
* look: () => iconLook({ icon: "lucide/sun", background: "#1e293b", caption: temperature.template }),
|
|
98
|
+
* });
|
|
99
|
+
*
|
|
100
|
+
* export default plugin.define({ actions: [now], state: [temperature] });
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export declare function createPlugin<const S extends SettingsSchema = Record<never, never>, const P extends Permission = never>(base: PluginBase<S, P>): PluginBuilder<S, P>;
|
|
104
|
+
export {};
|
|
105
|
+
//# sourceMappingURL=create.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EACL,KAAK,MAAM,EACX,KAAK,SAAS,EACd,KAAK,UAAU,EAIf,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,SAAS,EAEd,KAAK,QAAQ,EACb,KAAK,OAAO,EACZ,KAAK,UAAU,EAChB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEjF,sDAAsD;AACtD,MAAM,WAAW,Y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,MAAM,CAAC;IACV,yCAAyC;IACzC,OAAO,CAAC,GAAG,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,aAAa,CAAC;IAC/D,6FAA6F;IAC7F,MAAM,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;CAC1C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,YAAY,CAC1B,KAAK,CAAC,CAAC,SAAS,cAAc,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EACrD,KAAK,CAAC,CAAC,SAAS,UAAU,GAAG,KAAK,EAClC,IAAI,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,CA+D7C"}
|
package/dist/fields.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Short, typed ways to write settings. They return the same plain fields as writing them by hand,
|
|
3
|
+
* so both can be mixed.
|
|
4
|
+
*/
|
|
5
|
+
import type { BooleanField, ColorField, GroupsField, ImageField, NumberField, PageField, SecretField, SelectField, SelectOption, SlotsField, TextField } from "./settings.ts";
|
|
6
|
+
type Options<F> = Omit<F, "type" | "label">;
|
|
7
|
+
/** Choices as `{ value: "What people read" }`, or a list where their order matters. */
|
|
8
|
+
export type Choices<V extends string> = Readonly<Record<V, string>> | readonly {
|
|
9
|
+
readonly value: V;
|
|
10
|
+
readonly label: string;
|
|
11
|
+
}[];
|
|
12
|
+
/** A select whose value is one of `V`. */
|
|
13
|
+
export interface ChoiceField<V extends string> extends Omit<SelectField, "options" | "source"> {
|
|
14
|
+
options: readonly {
|
|
15
|
+
readonly value: V;
|
|
16
|
+
readonly label: string;
|
|
17
|
+
}[];
|
|
18
|
+
}
|
|
19
|
+
/** One of a plugin's option sources: its name, or what `plugin.source()` returned. */
|
|
20
|
+
export type SourceRef = string | {
|
|
21
|
+
readonly id: string;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Builds settings:
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* settings: {
|
|
28
|
+
* room: setting.text("Room", { default: "Office", required: true }),
|
|
29
|
+
* mode: setting.select("Mode", { set: "Set a level", mute: "Mute" }),
|
|
30
|
+
* level: setting.number("Level", { min: 0, max: 100, visibleIf: { mode: "set" } }),
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare const setting: {
|
|
35
|
+
readonly text: (label: string, options?: Options<TextField>) => TextField;
|
|
36
|
+
readonly number: (label: string, options?: Options<NumberField>) => NumberField;
|
|
37
|
+
readonly boolean: (label: string, options?: Options<BooleanField>) => BooleanField;
|
|
38
|
+
/** A `#rrggbb` colour. */
|
|
39
|
+
readonly color: (label: string, options?: Options<ColorField>) => ColorField;
|
|
40
|
+
/** One of a few fixed choices; its value has their exact type. */
|
|
41
|
+
readonly select: <const V extends string>(label: string, choices: Choices<V>, options?: Omit<Options<ChoiceField<V>>, "options" | "default"> & {
|
|
42
|
+
default?: NoInfer<V>;
|
|
43
|
+
}) => ChoiceField<V>;
|
|
44
|
+
/** A choice from what one of the plugin's option sources returns when the form opens. */
|
|
45
|
+
readonly pick: (label: string, source: SourceRef, options?: Omit<Options<SelectField>, "options" | "source"> & {
|
|
46
|
+
/** Choices shown before the fetched ones (`{ "": "The one in use" }`). */
|
|
47
|
+
first?: Readonly<Record<string, string>> | readonly SelectOption[];
|
|
48
|
+
}) => SelectField & {
|
|
49
|
+
source: string;
|
|
50
|
+
};
|
|
51
|
+
/** One of the user's pages. */
|
|
52
|
+
readonly page: (label: string, options?: Options<PageField>) => PageField;
|
|
53
|
+
/** Keys, touch sensors and the window. */
|
|
54
|
+
readonly slots: (label: string, options?: Options<SlotsField>) => SlotsField;
|
|
55
|
+
readonly image: (label: string, options?: Options<ImageField>) => ImageField;
|
|
56
|
+
/** Named sets of options. Only for a plugin's own settings. */
|
|
57
|
+
readonly groups: (label: string, source: SourceRef, options?: Omit<Options<GroupsField>, "source">) => GroupsField;
|
|
58
|
+
/** A password or token, kept out of the config. Only for a plugin's own settings. */
|
|
59
|
+
readonly secret: (label: string, options?: Options<SecretField>) => SecretField;
|
|
60
|
+
};
|
|
61
|
+
export {};
|
|
62
|
+
//# sourceMappingURL=fields.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../src/fields.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EACV,YAAY,EACZ,UAAU,EACV,WAAW,EACX,UAAU,EACV,WAAW,EACX,SAAS,EACT,WAAW,EACX,WAAW,EACX,YAAY,EACZ,UAAU,EACV,SAAS,EACV,MAAM,eAAe,CAAC;AAEvB,KAAK,OAAO,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC;AAE5C,uFAAuF;AACvF,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,MAAM,IAChC,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,GAC3B,SAAS;IAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EAAE,CAAC;AAE7D,0CAA0C;AAC1C,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,MAAM,CAAE,SAAQ,IAAI,CAAC,WAAW,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC5F,OAAO,EAAE,SAAS;QAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CACnE;AAED,sFAAsF;AACtF,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AAYzD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AAC,OAAO,CAAC,WAAW,CAAC,EAAE,QAAQ,CAAC,KAC7C,WAAW;IAGd,qFAAqF;aACrF,MAAM,UAAQ,MAAM,YAAY,OAAO,CAAC,WAAW,CAAC,KAAG,WAAW;CAG1D,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,10 +6,13 @@
|
|
|
6
6
|
export * from "@sdeck/app";
|
|
7
7
|
export { type HostBridge, HostBridgeContext, useExpression, useHostState, useImage, useRunAction, useTemplate, useVariable, } from "./bridge.ts";
|
|
8
8
|
export { type ConnectionOptions, type ConnectionState, type Link, ManagedConnection, PermanentError, } from "./connection.ts";
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
9
|
+
export { createPlugin, type PluginBase, type PluginBuilder, type PluginParts, type Source, type StateHandle, type TypedContext, } from "./create.ts";
|
|
10
|
+
export { type ChoiceField, type Choices, type SourceRef, setting } from "./fields.ts";
|
|
11
|
+
export { HOST_MODULES, type ManifestResult, manifestIcon, PLUGIN_KEYWORD, type PluginManifest, parseManifest, SUPPORTED_API_VERSIONS, } from "./manifest.ts";
|
|
12
|
+
export { PERMISSION_TEXTS, PERMISSIONS, type Permission, PermissionError, Permissions, type PermissionText, } from "./permissions.ts";
|
|
13
|
+
export { type Action, type ActionDef, type ActionProps, checkPlugin, type Deactivate, type DeckControls, defineAction, definePlugin, defineTrigger, type Onboarding, type OnboardingStep, type OptionSource, type Overlay, type OverlayProps, onSettingsChange, PLUGIN_API_VERSION, type PluginCommand, type PluginContext, type PluginDef, pluginNamespace, type RunContext, type RunFn, type RunOutcome, type RunResult, type SlotKind, type StarterPage, type StateDef, type StatusLevel, type Trigger, type TriggerContext, type TriggerDef, } from "./plugin.ts";
|
|
12
14
|
export { type BooleanField, behaviorFields, type ColorField, checkSchema, defaultValue, type FieldValue, type GroupsField, type ImageField, type InferSettings, isFieldVisible, liveSettings, type NumberField, type OptionGroup, optionGroups, type PageField, resolveSettings, type SecretField, type SelectField, type SelectOption, type SettingField, type SettingsSchema, type SettingValue, type SlotsField, slotList, type TextField, } from "./settings.ts";
|
|
13
|
-
export { Shared } from "./shared.ts";
|
|
15
|
+
export { following, Shared, useShared } from "./shared.ts";
|
|
14
16
|
export { fitText, layoutText, type TextLayout, type TextLayoutOptions, type TextRow, } from "./text.ts";
|
|
17
|
+
export { checkSettings, type StandardSchema, type Validator } from "./validate.ts";
|
|
15
18
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,YAAY,CAAC;AAC3B,OAAO,EACL,KAAK,UAAU,EACf,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,WAAW,GACZ,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,IAAI,EACT,iBAAiB,EACjB,cAAc,GACf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,YAAY,EACZ,KAAK,cAAc,EACnB,cAAc,EACd,KAAK,cAAc,EACnB,aAAa,EACb,sBAAsB,GACvB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,KAAK,UAAU,EACf,eAAe,EACf,KAAK,cAAc,GACpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,KAAK,MAAM,EACX,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,WAAW,EACX,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,OAAO,EACZ,KAAK,YAAY,EACjB,kBAAkB,EAClB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,eAAe,EACf,KAAK,UAAU,EACf,KAAK,KAAK,EACV,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,KAAK,OAAO,EACZ,KAAK,cAAc,EACnB,KAAK,UAAU,GAChB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,KAAK,YAAY,EACjB,cAAc,EACd,KAAK,UAAU,EACf,WAAW,EACX,YAAY,EACZ,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,cAAc,EACd,YAAY,EACZ,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,YAAY,EACZ,KAAK,SAAS,EACd,eAAe,EACf,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,QAAQ,EACR,KAAK,SAAS,GACf,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,YAAY,CAAC;AAC3B,OAAO,EACL,KAAK,UAAU,EACf,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,WAAW,GACZ,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,IAAI,EACT,iBAAiB,EACjB,cAAc,GACf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,YAAY,EACZ,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,MAAM,EACX,KAAK,WAAW,EAChB,KAAK,YAAY,GAClB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,KAAK,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B,KAAK,UAAU,EACf,QAAQ,EACR,KAAK,SAAS,GACf,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EACL,OAAO,EACP,UAAU,EACV,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,OAAO,GACb,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,aAAa,EAAE,KAAK,cAAc,EAAE,KAAK,SAAS,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -248,6 +248,21 @@ class ManagedConnection {
|
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
250
|
// src/permissions.ts
|
|
251
|
+
var Permissions = {
|
|
252
|
+
network: "network",
|
|
253
|
+
filesystem: "filesystem",
|
|
254
|
+
process: "process",
|
|
255
|
+
shell: "shell",
|
|
256
|
+
input: "input",
|
|
257
|
+
clipboard: "clipboard",
|
|
258
|
+
audio: "audio",
|
|
259
|
+
environment: "environment",
|
|
260
|
+
variables: "variables",
|
|
261
|
+
state: "state",
|
|
262
|
+
actions: "actions",
|
|
263
|
+
overlay: "overlay",
|
|
264
|
+
native: "native"
|
|
265
|
+
};
|
|
251
266
|
var PERMISSION_TEXTS = {
|
|
252
267
|
network: {
|
|
253
268
|
name: "Network",
|
|
@@ -456,6 +471,10 @@ function checkSchema(schema, sources = {}) {
|
|
|
456
471
|
if (!(other in schema))
|
|
457
472
|
problems.push(`setting "${key}" depends on unknown "${other}"`);
|
|
458
473
|
}
|
|
474
|
+
const { validate } = field;
|
|
475
|
+
if (validate !== undefined && typeof validate !== "function" && !("~standard" in validate)) {
|
|
476
|
+
problems.push(`setting "${key}": validate must be a function or a Standard Schema`);
|
|
477
|
+
}
|
|
459
478
|
if (field.visibleIf !== undefined) {
|
|
460
479
|
for (const other of Object.keys(field.visibleIf)) {
|
|
461
480
|
if (!(other in schema))
|
|
@@ -467,7 +486,7 @@ function checkSchema(schema, sources = {}) {
|
|
|
467
486
|
}
|
|
468
487
|
|
|
469
488
|
// src/plugin.ts
|
|
470
|
-
var PLUGIN_API_VERSION =
|
|
489
|
+
var PLUGIN_API_VERSION = 3;
|
|
471
490
|
var ID = /^(@[a-z0-9][\w.-]*\/)?[a-z0-9][\w.-]*$/;
|
|
472
491
|
var NAMESPACE = /^[a-z][\w-]{0,31}$/;
|
|
473
492
|
var LOCAL_ID = /^[\w.-]+$/;
|
|
@@ -683,7 +702,121 @@ function checkOnboarding(def) {
|
|
|
683
702
|
}
|
|
684
703
|
return problems;
|
|
685
704
|
}
|
|
705
|
+
function onSettingsChange(context, listener) {
|
|
706
|
+
let before = JSON.stringify(context.settings());
|
|
707
|
+
return context.onSettings(() => {
|
|
708
|
+
const now = JSON.stringify(context.settings());
|
|
709
|
+
if (now === before)
|
|
710
|
+
return;
|
|
711
|
+
before = now;
|
|
712
|
+
listener();
|
|
713
|
+
});
|
|
714
|
+
}
|
|
686
715
|
|
|
716
|
+
// src/create.ts
|
|
717
|
+
function createPlugin(base) {
|
|
718
|
+
const namespace = pluginNamespace(base);
|
|
719
|
+
let context;
|
|
720
|
+
const makeState = (type) => (id, name, options = {}) => {
|
|
721
|
+
const key = `${namespace}.${id}`;
|
|
722
|
+
return {
|
|
723
|
+
def: { ...options, id, name, type },
|
|
724
|
+
key,
|
|
725
|
+
template: `{{${key}}}`,
|
|
726
|
+
set: (value) => context?.state.set(id, value),
|
|
727
|
+
get: () => context?.state.get(key),
|
|
728
|
+
use: () => useHostState(key)
|
|
729
|
+
};
|
|
730
|
+
};
|
|
731
|
+
return {
|
|
732
|
+
id: base.id,
|
|
733
|
+
namespace,
|
|
734
|
+
get context() {
|
|
735
|
+
return context;
|
|
736
|
+
},
|
|
737
|
+
action: (def) => defineAction(def),
|
|
738
|
+
trigger: (def) => defineTrigger(def),
|
|
739
|
+
state: {
|
|
740
|
+
number: makeState("number"),
|
|
741
|
+
string: makeState("string"),
|
|
742
|
+
boolean: makeState("boolean"),
|
|
743
|
+
json: makeState("json")
|
|
744
|
+
},
|
|
745
|
+
source: (id, load) => ({ id, load }),
|
|
746
|
+
command: (def) => def,
|
|
747
|
+
define: ({ state, sources, activate, ...parts }) => definePlugin({
|
|
748
|
+
...base,
|
|
749
|
+
...parts,
|
|
750
|
+
...state && { state: state.map((s) => ("def" in s) ? s.def : s) },
|
|
751
|
+
...sources && {
|
|
752
|
+
optionSources: Object.fromEntries(sources.map((s) => [s.id, s.load]))
|
|
753
|
+
},
|
|
754
|
+
activate: async (given) => {
|
|
755
|
+
context = given;
|
|
756
|
+
let stop;
|
|
757
|
+
try {
|
|
758
|
+
stop = await activate?.(context) ?? undefined;
|
|
759
|
+
} catch (error) {
|
|
760
|
+
context = undefined;
|
|
761
|
+
throw error;
|
|
762
|
+
}
|
|
763
|
+
return async () => {
|
|
764
|
+
try {
|
|
765
|
+
await stop?.();
|
|
766
|
+
} finally {
|
|
767
|
+
context = undefined;
|
|
768
|
+
}
|
|
769
|
+
};
|
|
770
|
+
}
|
|
771
|
+
})
|
|
772
|
+
};
|
|
773
|
+
}
|
|
774
|
+
// src/fields.ts
|
|
775
|
+
var sourceId = (source) => typeof source === "string" ? source : source.id;
|
|
776
|
+
function optionList(choices) {
|
|
777
|
+
if (Array.isArray(choices))
|
|
778
|
+
return choices;
|
|
779
|
+
return Object.entries(choices).map(([value, label]) => ({
|
|
780
|
+
value,
|
|
781
|
+
label
|
|
782
|
+
}));
|
|
783
|
+
}
|
|
784
|
+
var setting = {
|
|
785
|
+
text(label, options) {
|
|
786
|
+
return { ...options, type: "text", label };
|
|
787
|
+
},
|
|
788
|
+
number(label, options) {
|
|
789
|
+
return { ...options, type: "number", label };
|
|
790
|
+
},
|
|
791
|
+
boolean(label, options) {
|
|
792
|
+
return { ...options, type: "boolean", label };
|
|
793
|
+
},
|
|
794
|
+
color(label, options) {
|
|
795
|
+
return { ...options, type: "color", label };
|
|
796
|
+
},
|
|
797
|
+
select(label, choices, options) {
|
|
798
|
+
return { ...options, type: "select", label, options: optionList(choices) };
|
|
799
|
+
},
|
|
800
|
+
pick(label, source, options) {
|
|
801
|
+
const { first = [], ...rest } = options ?? {};
|
|
802
|
+
return { ...rest, type: "select", label, options: optionList(first), source: sourceId(source) };
|
|
803
|
+
},
|
|
804
|
+
page(label, options) {
|
|
805
|
+
return { ...options, type: "page", label };
|
|
806
|
+
},
|
|
807
|
+
slots(label, options) {
|
|
808
|
+
return { ...options, type: "slots", label };
|
|
809
|
+
},
|
|
810
|
+
image(label, options) {
|
|
811
|
+
return { ...options, type: "image", label };
|
|
812
|
+
},
|
|
813
|
+
groups(label, source, options) {
|
|
814
|
+
return { ...options, type: "groups", label, source: sourceId(source) };
|
|
815
|
+
},
|
|
816
|
+
secret(label, options) {
|
|
817
|
+
return { ...options, type: "secret", label };
|
|
818
|
+
}
|
|
819
|
+
};
|
|
687
820
|
// src/manifest.ts
|
|
688
821
|
var PLUGIN_KEYWORD = "sdeck-plugin";
|
|
689
822
|
var HOST_MODULES = [
|
|
@@ -696,7 +829,12 @@ var HOST_MODULES = [
|
|
|
696
829
|
"@sdeck/engine",
|
|
697
830
|
"@sdeck/schema"
|
|
698
831
|
];
|
|
699
|
-
var SUPPORTED_API_VERSIONS = [1, PLUGIN_API_VERSION];
|
|
832
|
+
var SUPPORTED_API_VERSIONS = [1, 2, PLUGIN_API_VERSION];
|
|
833
|
+
var ICON = /^(?:icon:)?([a-z0-9]{1,12}\/[A-Za-z0-9-]{1,80}(?:#[0-9a-fA-F]{6})?)$/;
|
|
834
|
+
function manifestIcon(pkg) {
|
|
835
|
+
const icon = pkg?.sdeck?.icon;
|
|
836
|
+
return typeof icon === "string" ? ICON.exec(icon)?.[1] : undefined;
|
|
837
|
+
}
|
|
700
838
|
function parseManifest(pkg) {
|
|
701
839
|
if (!pkg || typeof pkg !== "object")
|
|
702
840
|
return { ok: false, error: "package.json is not an object" };
|
|
@@ -711,10 +849,11 @@ function parseManifest(pkg) {
|
|
|
711
849
|
if (typeof apiVersion !== "number" || !SUPPORTED_API_VERSIONS.includes(apiVersion)) {
|
|
712
850
|
return {
|
|
713
851
|
ok: false,
|
|
714
|
-
error: `${p.name} targets plugin API ${String(apiVersion)}, this host supports ${SUPPORTED_API_VERSIONS.join("
|
|
852
|
+
error: typeof apiVersion === "number" && apiVersion > PLUGIN_API_VERSION ? `${p.name} needs a newer version of sdeck (plugin API ${apiVersion})` : `${p.name} targets plugin API ${String(apiVersion)}, this host supports ${SUPPORTED_API_VERSIONS.join(", ")}`
|
|
715
853
|
};
|
|
716
854
|
}
|
|
717
855
|
const entry = typeof sdeck.entry === "string" ? sdeck.entry : typeof p.main === "string" ? p.main : "index.js";
|
|
856
|
+
const icon = manifestIcon(pkg);
|
|
718
857
|
return {
|
|
719
858
|
ok: true,
|
|
720
859
|
manifest: {
|
|
@@ -722,11 +861,14 @@ function parseManifest(pkg) {
|
|
|
722
861
|
version: typeof p.version === "string" ? p.version : "0.0.0",
|
|
723
862
|
...typeof p.description === "string" && { description: p.description },
|
|
724
863
|
entry,
|
|
725
|
-
apiVersion
|
|
864
|
+
apiVersion,
|
|
865
|
+
...icon && { icon }
|
|
726
866
|
}
|
|
727
867
|
};
|
|
728
868
|
}
|
|
729
869
|
// src/shared.ts
|
|
870
|
+
import { useCallback as useCallback2, useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
871
|
+
|
|
730
872
|
class Shared {
|
|
731
873
|
#listeners = new Set;
|
|
732
874
|
#start;
|
|
@@ -757,6 +899,20 @@ class Shared {
|
|
|
757
899
|
};
|
|
758
900
|
}
|
|
759
901
|
}
|
|
902
|
+
function useShared(shared) {
|
|
903
|
+
return useSyncExternalStore2(useCallback2((changed) => shared.listen(changed), [shared]), () => shared.last);
|
|
904
|
+
}
|
|
905
|
+
var following = (shared, pick) => (set) => {
|
|
906
|
+
const update = (value) => set(value === undefined || value === null ? undefined : pick(value));
|
|
907
|
+
let heard = false;
|
|
908
|
+
const stop = shared.listen((value) => {
|
|
909
|
+
heard = true;
|
|
910
|
+
update(value);
|
|
911
|
+
});
|
|
912
|
+
if (!heard && shared.last !== undefined)
|
|
913
|
+
update(shared.last);
|
|
914
|
+
return stop;
|
|
915
|
+
};
|
|
760
916
|
// src/text.ts
|
|
761
917
|
function emWidth(char) {
|
|
762
918
|
if (/[ᄀ-ᇿ⺀-鿿가-豈--⦆]/.test(char))
|
|
@@ -891,6 +1047,37 @@ function layoutText(text, options) {
|
|
|
891
1047
|
function fitText(text, { height, ...options }) {
|
|
892
1048
|
return layoutText(text, { ...options, rows: [{ top: 0, height }] }).size;
|
|
893
1049
|
}
|
|
1050
|
+
// src/validate.ts
|
|
1051
|
+
var isSchema = (v) => ("~standard" in v);
|
|
1052
|
+
async function problem(field, value) {
|
|
1053
|
+
const empty = Array.isArray(value) ? value.length === 0 : String(value ?? "").trim() === "";
|
|
1054
|
+
if (empty)
|
|
1055
|
+
return field.required ? "this is required" : undefined;
|
|
1056
|
+
const validate = field.validate;
|
|
1057
|
+
if (!validate || typeof value === "string" && value.includes("{{"))
|
|
1058
|
+
return;
|
|
1059
|
+
if (!isSchema(validate))
|
|
1060
|
+
return await validate(value) || undefined;
|
|
1061
|
+
const { issues } = await validate["~standard"].validate(value);
|
|
1062
|
+
return issues?.[0]?.message;
|
|
1063
|
+
}
|
|
1064
|
+
async function checkSettings(schema, settings) {
|
|
1065
|
+
const found = {};
|
|
1066
|
+
for (const [key, field] of Object.entries(schema)) {
|
|
1067
|
+
if (!field.required && !field.validate)
|
|
1068
|
+
continue;
|
|
1069
|
+
if (!isFieldVisible(field, settings))
|
|
1070
|
+
continue;
|
|
1071
|
+
try {
|
|
1072
|
+
const text = await problem(field, settings[key]);
|
|
1073
|
+
if (text)
|
|
1074
|
+
found[key] = text;
|
|
1075
|
+
} catch (error) {
|
|
1076
|
+
found[key] = error instanceof Error ? error.message : String(error);
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
return found;
|
|
1080
|
+
}
|
|
894
1081
|
export {
|
|
895
1082
|
HOST_MODULES,
|
|
896
1083
|
HostBridgeContext,
|
|
@@ -901,30 +1088,38 @@ export {
|
|
|
901
1088
|
PLUGIN_KEYWORD,
|
|
902
1089
|
PermanentError,
|
|
903
1090
|
PermissionError,
|
|
1091
|
+
Permissions,
|
|
904
1092
|
SUPPORTED_API_VERSIONS,
|
|
905
1093
|
Shared,
|
|
906
1094
|
behaviorFields,
|
|
907
1095
|
checkPlugin,
|
|
908
1096
|
checkSchema,
|
|
1097
|
+
checkSettings,
|
|
1098
|
+
createPlugin,
|
|
909
1099
|
defaultValue,
|
|
910
1100
|
defineAction,
|
|
911
1101
|
definePlugin,
|
|
912
1102
|
defineTrigger,
|
|
913
1103
|
fitText,
|
|
1104
|
+
following,
|
|
914
1105
|
isFieldVisible,
|
|
915
1106
|
layoutText,
|
|
916
1107
|
liveSettings,
|
|
1108
|
+
manifestIcon,
|
|
1109
|
+
onSettingsChange,
|
|
917
1110
|
optionGroups,
|
|
918
1111
|
parseManifest,
|
|
919
1112
|
pluginNamespace,
|
|
920
1113
|
resolveSettings,
|
|
1114
|
+
setting,
|
|
921
1115
|
slotList,
|
|
922
1116
|
useExpression,
|
|
923
1117
|
useHostState,
|
|
924
1118
|
useImage,
|
|
925
1119
|
useRunAction,
|
|
1120
|
+
useShared,
|
|
926
1121
|
useTemplate,
|
|
927
1122
|
useVariable
|
|
928
1123
|
};
|
|
929
1124
|
|
|
930
|
-
//# debugId=
|
|
1125
|
+
//# debugId=3BB837D3775A167464756E2164756E21
|