@t3mode/plugin-sdk 0.0.0-stage → 1.0.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.
@@ -0,0 +1,67 @@
1
+ export type LogLevel = "debug" | "info" | "warn" | "error";
2
+ export interface BooleanOption {
3
+ readonly type: "boolean";
4
+ readonly label: string;
5
+ readonly description?: string;
6
+ readonly default: boolean;
7
+ }
8
+ export interface SelectOption<V extends string = string> {
9
+ readonly type: "select";
10
+ readonly label: string;
11
+ readonly description?: string;
12
+ readonly choices: ReadonlyArray<{
13
+ readonly value: V;
14
+ readonly label: string;
15
+ }>;
16
+ readonly default: V;
17
+ }
18
+ export type OptionSpec = BooleanOption | SelectOption;
19
+ export type OptionsSpec = Readonly<Record<string, OptionSpec>>;
20
+ export type OptionValues<O extends OptionsSpec> = { readonly [K in keyof O]: O[K] extends SelectOption<infer V> ? V : boolean; };
21
+ /** Shown on the settings page next to each running plugin. */
22
+ export interface PluginReport {
23
+ readonly state: "active" | "waiting";
24
+ readonly detail: string;
25
+ }
26
+ export interface PluginApi<O extends OptionsSpec = OptionsSpec> {
27
+ /** The id from the plugin's manifest.json. */
28
+ readonly id: string;
29
+ readonly options: OptionValues<O>;
30
+ /** Adds a stylesheet, removed when the plugin stops. */
31
+ readonly css: (text: string) => void;
32
+ /** Runs `callback` now and after DOM changes and route changes, at most once per frame. */
33
+ readonly observe: (callback: () => void) => void;
34
+ readonly listen: <E extends Event = Event>(target: EventTarget, type: string, handler: (event: E) => void, options?: AddEventListenerOptions) => void;
35
+ readonly interval: (callback: () => void, ms: number) => void;
36
+ /** Creates an element owned by the plugin. It is removed when the plugin stops. */
37
+ readonly element: <K extends keyof HTMLElementTagNameMap>(tag: K) => HTMLElementTagNameMap[K];
38
+ readonly onCleanup: (cleanup: () => void) => void;
39
+ /** JSON in localStorage, namespaced to the plugin. Lives as long as T3 Code's own UI state. */
40
+ readonly storage: {
41
+ readonly get: <T>(key: string, fallback: T) => T;
42
+ readonly set: (key: string, value: unknown) => void;
43
+ };
44
+ readonly log: (level: LogLevel, message: string) => void;
45
+ readonly report: (report: PluginReport) => void;
46
+ /** The first element matching any of the selectors, tried in order: newest markup first. */
47
+ readonly queryFirst: <E extends Element = HTMLElement>(candidates: ReadonlyArray<string>) => E | null;
48
+ /** The thread on screen as T3 Code keys it, `<environmentId>:<threadId>`, or null off a thread. */
49
+ readonly currentThreadKey: (hash?: string) => string | null;
50
+ /**
51
+ * T3 Code's React state, read from the fiber React attaches to DOM nodes. Component names are
52
+ * minified, so lookups match on the shape of the data, and return undefined when it changed.
53
+ */
54
+ readonly react: {
55
+ /** Props of the closest ancestor component (inclusive) whose props pass `test`. */
56
+ readonly findPropsUp: (node: Element, test: (props: Record<string, unknown>) => boolean, maxDepth?: number) => Record<string, unknown> | undefined;
57
+ /** The first hook state in the tree under the root of `node` that passes `test`. */
58
+ readonly findHookState: <T>(node: Element, test: (value: unknown) => value is T, budget?: number) => T | undefined;
59
+ };
60
+ }
61
+ export interface PluginDefinition<O extends OptionsSpec = OptionsSpec> {
62
+ readonly options: O;
63
+ /** Called on start and again after any option change (the plugin is restarted). */
64
+ start(api: PluginApi<O>): void;
65
+ }
66
+ /** Returns the definition unchanged, typing `api.options` from `options`. */
67
+ export declare const definePlugin: <const O extends OptionsSpec>(definition: PluginDefinition<O>) => PluginDefinition<O>;
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ // src/index.ts
2
+ /** Returns the definition unchanged, typing `api.options` from `options`. */
3
+ const definePlugin = (definition) => definition;
4
+ export { definePlugin };
package/package.json CHANGED
@@ -1,6 +1,23 @@
1
1
  {
2
2
  "name": "@t3mode/plugin-sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.0",
4
+ "description": "definePlugin and the plugin API types for t3mode, the plugin loader for T3 Code",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "type": "module",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "devDependencies": {
16
+ "vite-plus": "1.4.0"
17
+ },
18
+ "scripts": {
19
+ "build": "vp pack",
20
+ "typecheck": "effect-tsgo tsc --noEmit -p ."
21
+ },
22
+ "types": "./dist/index.d.ts"
6
23
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.