@sdeck/plugin 0.0.0-stage → 0.2.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 +48 -0
- package/dist/bridge.d.ts.map +1 -0
- package/dist/connection.d.ts +44 -0
- package/dist/connection.d.ts.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +774 -0
- package/dist/index.js.map +17 -0
- package/dist/manifest.d.ts +45 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/permissions.d.ts +31 -0
- package/dist/permissions.d.ts.map +1 -0
- package/dist/plugin.d.ts +332 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/settings.d.ts +135 -0
- package/dist/settings.d.ts.map +1 -0
- package/dist/shared.d.ts +9 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/ui.d.ts +4 -0
- package/dist/ui.d.ts.map +1 -0
- package/package.json +41 -4
- package/src/bridge.ts +134 -0
- package/src/connection.ts +206 -0
- package/src/index.ts +93 -0
- package/src/manifest.ts +85 -0
- package/src/permissions.ts +119 -0
- package/src/plugin.ts +571 -0
- package/src/settings.ts +293 -0
- package/src/shared.ts +34 -0
- package/src/ui.ts +3 -0
- package/README.md +0 -3
package/dist/bridge.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Live state for action components. The host provides a `HostBridge` around every slot; these
|
|
3
|
+
* hooks subscribe to exactly what they read and re-render when it changes.
|
|
4
|
+
*/
|
|
5
|
+
import { type Scope } from "@sdeck/engine";
|
|
6
|
+
export interface HostBridge {
|
|
7
|
+
/**
|
|
8
|
+
* Watches state keys and variables behind expression paths (`system.cpu`, `vars.mode`).
|
|
9
|
+
* Starts providers as needed. Returns a function that stops watching.
|
|
10
|
+
*/
|
|
11
|
+
watch(paths: readonly string[], listener: () => void): () => void;
|
|
12
|
+
/** The current expression scope (state namespaces, `vars`, `self`…). */
|
|
13
|
+
scope(): Scope;
|
|
14
|
+
/** Runs a plugin action as a workflow step would (recorded in the history). */
|
|
15
|
+
run(plugin: string, action: string, settings?: Record<string, unknown>): Promise<unknown>;
|
|
16
|
+
/** Sets a global variable. */
|
|
17
|
+
setVariable(name: string, value: unknown): void;
|
|
18
|
+
/**
|
|
19
|
+
* What to draw for an image source (an icon reference, a URL or a `data:` URI), or
|
|
20
|
+
* `undefined` while it loads. `color` applies to icons.
|
|
21
|
+
*/
|
|
22
|
+
image(src: string, color?: string): string | undefined;
|
|
23
|
+
/** Called when an image finishes loading. */
|
|
24
|
+
watchImages(listener: () => void): () => void;
|
|
25
|
+
}
|
|
26
|
+
export declare const HostBridgeContext: import("react").Context<HostBridge | undefined>;
|
|
27
|
+
/**
|
|
28
|
+
* The value of an expression (`system.cpu > 80`, `vars.mode`), kept up to date. Values the plugin
|
|
29
|
+
* is not allowed to read (`state`, `variables`) are missing.
|
|
30
|
+
*/
|
|
31
|
+
export declare function useExpression(source: string): unknown;
|
|
32
|
+
/** A `{{template}}` rendered to text, kept up to date: `useTemplate("CPU {{system.cpu}}%")`. */
|
|
33
|
+
export declare function useTemplate(source: string): string;
|
|
34
|
+
/** A live state value by key (`system.cpu`). */
|
|
35
|
+
export declare function useHostState(key: string): unknown;
|
|
36
|
+
/** A global variable and a setter for it. */
|
|
37
|
+
export declare function useVariable(name: string): [unknown, (value: unknown) => void];
|
|
38
|
+
/**
|
|
39
|
+
* Runs an action from a component (`run("@sdeck/plugin-system", "open", {...})`).
|
|
40
|
+
* Other plugins' actions need the `actions` permission.
|
|
41
|
+
*/
|
|
42
|
+
export declare function useRunAction(): HostBridge["run"];
|
|
43
|
+
/**
|
|
44
|
+
* An image ready to draw with `<img src>`: an icon (`icon:lucide/play`, `icon:si/SiDiscord`) in
|
|
45
|
+
* `color`, a URL or a `data:` URI. `undefined` until it has loaded.
|
|
46
|
+
*/
|
|
47
|
+
export declare function useImage(src: string, color?: string): string | undefined;
|
|
48
|
+
//# s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AAI,CAAC,CAM7E;AAED;;;GAGG;AACH,wBAAgB,YAAY,IAAI,UAAU,CAAC,KAAK,CAAC,CAEhD;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAKxE"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A connection to another program or service, opened only while something needs it and reopened
|
|
3
|
+
* when it drops. Plugins hold it while their state is watched or a trigger listens, and borrow it
|
|
4
|
+
* to run actions.
|
|
5
|
+
*/
|
|
6
|
+
export interface Link<C> {
|
|
7
|
+
/** What callers use. */
|
|
8
|
+
value: C;
|
|
9
|
+
close(): void;
|
|
10
|
+
}
|
|
11
|
+
/** Retrying cannot help (a wrong password, nothing configured) until something changes. */
|
|
12
|
+
export declare class PermanentError extends Error {
|
|
13
|
+
}
|
|
14
|
+
export type ConnectionState = "connecting" | "connected" | "disconnected";
|
|
15
|
+
export interface ConnectionOptions<C> {
|
|
16
|
+
/**
|
|
17
|
+
* Opens the connection. Call `lost` if it drops later. `signal` aborts when nobody wants it
|
|
18
|
+
* any more.
|
|
19
|
+
*/
|
|
20
|
+
open(lost: (error: Error) => void, signal: AbortSignal): Promise<Link<C>>;
|
|
21
|
+
onStatus?: (state: ConnectionState, error?: Error) => void;
|
|
22
|
+
/** How long it stays open after the last holder leaves (default 3000). */
|
|
23
|
+
lingerMs?: number;
|
|
24
|
+
/** First and longest pause between attempts (default 1000 and 30000). */
|
|
25
|
+
retry?: {
|
|
26
|
+
minMs: number;
|
|
27
|
+
maxMs: number;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export declare class ManagedConnection<C> {
|
|
31
|
+
#private;
|
|
32
|
+
constructor(options: ConnectionOptions<C>);
|
|
33
|
+
/** The open connection, if there is one. */
|
|
34
|
+
get current(): C | undefined;
|
|
35
|
+
/** Keeps the connection wanted until the returned function is called. */
|
|
36
|
+
hold(): () => void;
|
|
37
|
+
/** Runs `use` with the connection, opening it first if needed. */
|
|
38
|
+
with<T>(use: (value: C) => T | Promise<T>, timeoutMs?: number): Promise<T>;
|
|
39
|
+
/** Starts over (the settings changed). */
|
|
40
|
+
restart(): void;
|
|
41
|
+
/** Closes it for good, whoever holds it. */
|
|
42
|
+
close(): void;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=connection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,IAAI,CAAC,CAAC;IACrB,wBAAwB;IACxB,KAAK,EAAE,CAAC,CAAC;IACT,KAAK,IAAI,IAAI,CAAC;CACf;AAED,2FAA2F;AAC3F,qBAAa,cAAe,SAAQ,KAAK;CAAG;AAE5C,MAAM,MAAM,eAAe,GAAG,YAAY,GAAG,WAAW,GAAG,cAAc,CAAC;AAE1E,MAAM,WAAW,iBAAiB,CAAC,CAAC;IAClC;;;OAGG;IACH,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1E,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,EAAE,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC;IAC3D,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,yEAAyE;IACzE,KAAK,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CAC1C;AAOD,qBAAa,iBAAiB,CAAC,CAAC;;IAY9B,YAAY,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAGxC;IAED,4CAA4C;IAC5C,IAAI,OAAO,IAAI,CAAC,GAAG,SAAS,CAE3B;IAED,yEAAyE;IACzE,IAAI,IAAI,MAAM,IAAI,CAYjB;IAED,kEAAkE;IAC5D,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EAAE,SAAS,SAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAO7E;IAED,0CAA0C;IAC1C,OAAO,IAAI,IAAI,CAKd;IAED,4CAA4C;IAC5C,KAAK,IAAI,IAAI,CAKZ;CA6GF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@sdeck/plugin`: everything a plugin needs. Define actions that run headless (from keys,
|
|
3
|
+
* triggers and workflows) or draw themselves with React, publish live state, offer trigger types,
|
|
4
|
+
* and use the `@sdeck/app` hooks and components (re-exported here) for input and navigation.
|
|
5
|
+
*/
|
|
6
|
+
export * from "@sdeck/app";
|
|
7
|
+
export { type HostBridge, HostBridgeContext, useExpression, useHostState, useImage, useRunAction, useTemplate, useVariable, } from "./bridge.ts";
|
|
8
|
+
export { type ConnectionOptions, type ConnectionState, type Link, ManagedConnection, PermanentError, } from "./connection.ts";
|
|
9
|
+
export { HOST_MODULES, type ManifestResult, PLUGIN_KEYWORD, type PluginManifest, parseManifest, SUPPORTED_API_VERSIONS, } from "./manifest.ts";
|
|
10
|
+
export { PERMISSION_TEXTS, PERMISSIONS, type Permission, PermissionError, type PermissionText, } from "./permissions.ts";
|
|
11
|
+
export { type Action, type ActionDef, type ActionProps, checkPlugin, type Deactivate, type DeckControls, defineAction, definePlugin, defineTrigger, type Onboarding, type OnboardingStep, type OptionSource, 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
|
+
export { type BooleanField, behaviorFields, type ColorField, checkSchema, defaultValue, type FieldValue, type GroupsField, type ImageField, type InferSettings, isFieldVisible, type NumberField, type OptionGroup, optionGroups, type PageField, resolveSettings, type SecretField, type SelectField, type SelectOption, type SettingField, type SettingsSchema, type SettingValue, type TextField, } from "./settings.ts";
|
|
13
|
+
export { Shared } from "./shared.ts";
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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,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,KAA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