@garretapp/sdk 0.1.1 → 0.1.3

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.
@@ -187,7 +187,11 @@ function getGarret() {
187
187
  active: true,
188
188
  onActiveChange: () => () => {
189
189
  },
190
- onOpenSettings: () => () => {
190
+ setCommands: () => {
191
+ },
192
+ onCommand: () => () => {
193
+ },
194
+ setTitle: () => {
191
195
  },
192
196
  surfaces: { open: nope, onClosed: () => () => {
193
197
  } },
@@ -43,6 +43,11 @@ interface SharedApi {
43
43
  storage: StorageApi;
44
44
  secrets: SecretsApi;
45
45
  }
46
+ /** A frame ⋯-menu command a widget declares via `setCommands` (dispatched back through `onCommand`). */
47
+ interface WidgetCommand {
48
+ id: string;
49
+ label: string;
50
+ }
46
51
  /** Options for opening a floating sibling surface. All fields optional; sizes in px. */
47
52
  interface SurfaceOpenOptions {
48
53
  /** initial props delivered to the opened surface as `g.props`; structured-cloned, so each surface
@@ -115,8 +120,12 @@ interface GarretPlatform {
115
120
  /** false when the board is ambient/idle — pause rAF/animations, throttle polling. */
116
121
  active: boolean;
117
122
  onActiveChange(cb: (active: boolean) => void): () => void;
118
- /** The host (frame ⋯→Settings) asks this widget to open its own config UI. */
119
- onOpenSettings(cb: () => void): () => void;
123
+ /** Declare the commands this widget wants in the frame's menu. The host renders them and dispatches
124
+ * the chosen one to `onCommand` — one generic mechanism (settings, refresh, or anything you invent). */
125
+ setCommands(commands: WidgetCommand[]): void;
126
+ onCommand(cb: (id: string) => void): () => void;
127
+ /** Set this placement's title in the board frame header (persisted in the board config). */
128
+ setTitle(title: string): void;
120
129
  /** Open sibling surfaces (same package) as floating windows. Requires the `windows` capability. */
121
130
  surfaces: SurfaceApi;
122
131
  /** Controls for this UI's own surface window (no-op for a board-placed widget). */
@@ -43,6 +43,11 @@ interface SharedApi {
43
43
  storage: StorageApi;
44
44
  secrets: SecretsApi;
45
45
  }
46
+ /** A frame ⋯-menu command a widget declares via `setCommands` (dispatched back through `onCommand`). */
47
+ interface WidgetCommand {
48
+ id: string;
49
+ label: string;
50
+ }
46
51
  /** Options for opening a floating sibling surface. All fields optional; sizes in px. */
47
52
  interface SurfaceOpenOptions {
48
53
  /** initial props delivered to the opened surface as `g.props`; structured-cloned, so each surface
@@ -115,8 +120,12 @@ interface GarretPlatform {
115
120
  /** false when the board is ambient/idle — pause rAF/animations, throttle polling. */
116
121
  active: boolean;
117
122
  onActiveChange(cb: (active: boolean) => void): () => void;
118
- /** The host (frame ⋯→Settings) asks this widget to open its own config UI. */
119
- onOpenSettings(cb: () => void): () => void;
123
+ /** Declare the commands this widget wants in the frame's menu. The host renders them and dispatches
124
+ * the chosen one to `onCommand` — one generic mechanism (settings, refresh, or anything you invent). */
125
+ setCommands(commands: WidgetCommand[]): void;
126
+ onCommand(cb: (id: string) => void): () => void;
127
+ /** Set this placement's title in the board frame header (persisted in the board config). */
128
+ setTitle(title: string): void;
120
129
  /** Open sibling surfaces (same package) as floating windows. Requires the `windows` capability. */
121
130
  surfaces: SurfaceApi;
122
131
  /** Controls for this UI's own surface window (no-op for a board-placed widget). */
package/dist/react.cjs CHANGED
@@ -220,7 +220,11 @@ function getGarret() {
220
220
  active: true,
221
221
  onActiveChange: () => () => {
222
222
  },
223
- onOpenSettings: () => () => {
223
+ setCommands: () => {
224
+ },
225
+ onCommand: () => () => {
226
+ },
227
+ setTitle: () => {
224
228
  },
225
229
  surfaces: { open: nope, onClosed: () => () => {
226
230
  } },
@@ -422,11 +426,15 @@ function useActive() {
422
426
  react.useEffect(() => g.onActiveChange(setActive), [g]);
423
427
  return active;
424
428
  }
425
- function useOpenSettings(cb) {
429
+ function useWidgetMenu(items) {
426
430
  const g = getGarret();
427
- const ref = react.useRef(cb);
428
- ref.current = cb;
429
- react.useEffect(() => g.onOpenSettings(() => ref.current()), [g]);
431
+ const ref = react.useRef(items);
432
+ ref.current = items;
433
+ const key = items.map((i) => `${i.id}:${i.label}`).join("|");
434
+ react.useEffect(() => {
435
+ g.setCommands(ref.current.map((i) => ({ id: i.id, label: i.label })));
436
+ return g.onCommand((id) => ref.current.find((i) => i.id === id)?.run());
437
+ }, [g, key]);
430
438
  }
431
439
  function useInstanceConfig(defaults) {
432
440
  const g = getGarret();
@@ -491,6 +499,6 @@ exports.useGarret = useGarret;
491
499
  exports.useHost = useHost;
492
500
  exports.useHostEvent = useHostEvent;
493
501
  exports.useInstanceConfig = useInstanceConfig;
494
- exports.useOpenSettings = useOpenSettings;
495
502
  exports.useProps = useProps;
496
503
  exports.useStream = useStream;
504
+ exports.useWidgetMenu = useWidgetMenu;
package/dist/react.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { G as GarretError, E as EventMap, H as HostClient, f as StreamCall } from './types-BxSYAH_H.cjs';
2
- import { G as GarretPlatform } from './platform-DnI7gJTx.cjs';
3
- export { S as SurfaceApi, a as SurfaceHandle, b as SurfaceOpenOptions, W as WindowControls } from './platform-DnI7gJTx.cjs';
2
+ import { G as GarretPlatform } from './platform-qz2Ef0Rp.cjs';
3
+ export { S as SurfaceApi, a as SurfaceHandle, b as SurfaceOpenOptions, W as WindowControls } from './platform-qz2Ef0Rp.cjs';
4
4
  import { ReactNode } from 'react';
5
5
  import './protocol-Do0BJdeE.cjs';
6
6
 
@@ -110,8 +110,14 @@ declare function useStream<Chunk, Result = void>(factory: () => StreamCall<Chunk
110
110
  declare function useConfig<T>(): [T, (patch: Partial<T>) => void, (value: T) => void];
111
111
  /** Board activity — `false` when ambient/idle. Gate polling / rAF / animations on it. */
112
112
  declare function useActive(): boolean;
113
- /** Run `cb` when the host (frame ⋯→Settings) asks this widget to reveal its own config UI. */
114
- declare function useOpenSettings(cb: () => void): void;
113
+ /** Declarative frame ⋯-menu: pass items with inline handlers. Registers them with the host (id +
114
+ * label) and runs the matching `run` when the user picks one. One generic mechanism — no bespoke
115
+ * per-action hooks. Example: `useWidgetMenu([{ id: 'refresh', label: 'Refresh', run: reload }])`. */
116
+ declare function useWidgetMenu(items: {
117
+ id: string;
118
+ label: string;
119
+ run: () => void;
120
+ }[]): void;
115
121
  /** Per-placement config backed by `g.instanceStorage` (isolated per widget instance). Loads once the
116
122
  * runtime binds (calls before bind reject); `set` writes through to storage + state. `loaded` gates
117
123
  * the first data fetch so you don't fetch with defaults before the saved config arrives. */
@@ -126,4 +132,4 @@ declare function useInstanceConfig<T extends Record<string, unknown>>(defaults:
126
132
  * time), so this re-renders when the runtime binds. The `T` is an unchecked cast — validate it yourself. */
127
133
  declare function useProps<T = Record<string, unknown>>(): T;
128
134
 
129
- export { Accordion, Badge, Dot, EmptyState, ErrorState, Field, FieldGroup, GarretError, GarretPlatform, Item, NumberInput, Scroll, Select, SettingsPanel, type StreamStatus, Switch, TextInput, type Tone, type UseStreamResult, useActive, useConfig, useGarret, useHost, useHostEvent, useInstanceConfig, useOpenSettings, useProps, useStream };
135
+ export { Accordion, Badge, Dot, EmptyState, ErrorState, Field, FieldGroup, GarretError, GarretPlatform, Item, NumberInput, Scroll, Select, SettingsPanel, type StreamStatus, Switch, TextInput, type Tone, type UseStreamResult, useActive, useConfig, useGarret, useHost, useHostEvent, useInstanceConfig, useProps, useStream, useWidgetMenu };
package/dist/react.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { G as GarretError, E as EventMap, H as HostClient, f as StreamCall } from './types-BxSYAH_H.js';
2
- import { G as GarretPlatform } from './platform-CZHtdUK0.js';
3
- export { S as SurfaceApi, a as SurfaceHandle, b as SurfaceOpenOptions, W as WindowControls } from './platform-CZHtdUK0.js';
2
+ import { G as GarretPlatform } from './platform-Bbj2Vh3W.js';
3
+ export { S as SurfaceApi, a as SurfaceHandle, b as SurfaceOpenOptions, W as WindowControls } from './platform-Bbj2Vh3W.js';
4
4
  import { ReactNode } from 'react';
5
5
  import './protocol-Do0BJdeE.js';
6
6
 
@@ -110,8 +110,14 @@ declare function useStream<Chunk, Result = void>(factory: () => StreamCall<Chunk
110
110
  declare function useConfig<T>(): [T, (patch: Partial<T>) => void, (value: T) => void];
111
111
  /** Board activity — `false` when ambient/idle. Gate polling / rAF / animations on it. */
112
112
  declare function useActive(): boolean;
113
- /** Run `cb` when the host (frame ⋯→Settings) asks this widget to reveal its own config UI. */
114
- declare function useOpenSettings(cb: () => void): void;
113
+ /** Declarative frame ⋯-menu: pass items with inline handlers. Registers them with the host (id +
114
+ * label) and runs the matching `run` when the user picks one. One generic mechanism — no bespoke
115
+ * per-action hooks. Example: `useWidgetMenu([{ id: 'refresh', label: 'Refresh', run: reload }])`. */
116
+ declare function useWidgetMenu(items: {
117
+ id: string;
118
+ label: string;
119
+ run: () => void;
120
+ }[]): void;
115
121
  /** Per-placement config backed by `g.instanceStorage` (isolated per widget instance). Loads once the
116
122
  * runtime binds (calls before bind reject); `set` writes through to storage + state. `loaded` gates
117
123
  * the first data fetch so you don't fetch with defaults before the saved config arrives. */
@@ -126,4 +132,4 @@ declare function useInstanceConfig<T extends Record<string, unknown>>(defaults:
126
132
  * time), so this re-renders when the runtime binds. The `T` is an unchecked cast — validate it yourself. */
127
133
  declare function useProps<T = Record<string, unknown>>(): T;
128
134
 
129
- export { Accordion, Badge, Dot, EmptyState, ErrorState, Field, FieldGroup, GarretError, GarretPlatform, Item, NumberInput, Scroll, Select, SettingsPanel, type StreamStatus, Switch, TextInput, type Tone, type UseStreamResult, useActive, useConfig, useGarret, useHost, useHostEvent, useInstanceConfig, useOpenSettings, useProps, useStream };
135
+ export { Accordion, Badge, Dot, EmptyState, ErrorState, Field, FieldGroup, GarretError, GarretPlatform, Item, NumberInput, Scroll, Select, SettingsPanel, type StreamStatus, Switch, TextInput, type Tone, type UseStreamResult, useActive, useConfig, useGarret, useHost, useHostEvent, useInstanceConfig, useProps, useStream, useWidgetMenu };
package/dist/react.js CHANGED
@@ -1,4 +1,4 @@
1
- import { getGarret, getRuntime, getHostTransport, createHostClient, getInstanceId } from './chunk-ZJYHRC5C.js';
1
+ import { getGarret, getRuntime, getHostTransport, createHostClient, getInstanceId } from './chunk-AIGAFJFB.js';
2
2
  import { GarretError } from './chunk-ENIDFSMM.js';
3
3
  export { GarretError } from './chunk-ENIDFSMM.js';
4
4
  import { useState, useMemo, useEffect, useRef, useCallback } from 'react';
@@ -191,11 +191,15 @@ function useActive() {
191
191
  useEffect(() => g.onActiveChange(setActive), [g]);
192
192
  return active;
193
193
  }
194
- function useOpenSettings(cb) {
194
+ function useWidgetMenu(items) {
195
195
  const g = getGarret();
196
- const ref = useRef(cb);
197
- ref.current = cb;
198
- useEffect(() => g.onOpenSettings(() => ref.current()), [g]);
196
+ const ref = useRef(items);
197
+ ref.current = items;
198
+ const key = items.map((i) => `${i.id}:${i.label}`).join("|");
199
+ useEffect(() => {
200
+ g.setCommands(ref.current.map((i) => ({ id: i.id, label: i.label })));
201
+ return g.onCommand((id) => ref.current.find((i) => i.id === id)?.run());
202
+ }, [g, key]);
199
203
  }
200
204
  function useInstanceConfig(defaults) {
201
205
  const g = getGarret();
@@ -239,4 +243,4 @@ function useProps() {
239
243
  return props;
240
244
  }
241
245
 
242
- export { Accordion, Badge, Dot, EmptyState, ErrorState, Field, FieldGroup, Item, NumberInput, Scroll, Select, SettingsPanel, Switch, TextInput, useActive, useConfig, useGarret, useHost, useHostEvent, useInstanceConfig, useOpenSettings, useProps, useStream };
246
+ export { Accordion, Badge, Dot, EmptyState, ErrorState, Field, FieldGroup, Item, NumberInput, Scroll, Select, SettingsPanel, Switch, TextInput, useActive, useConfig, useGarret, useHost, useHostEvent, useInstanceConfig, useProps, useStream, useWidgetMenu };
package/dist/ui.cjs CHANGED
@@ -215,7 +215,11 @@ function getGarret() {
215
215
  active: true,
216
216
  onActiveChange: () => () => {
217
217
  },
218
- onOpenSettings: () => () => {
218
+ setCommands: () => {
219
+ },
220
+ onCommand: () => () => {
221
+ },
222
+ setTitle: () => {
219
223
  },
220
224
  surfaces: { open: nope, onClosed: () => () => {
221
225
  } },
package/dist/ui.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { T as Transport } from './protocol-Do0BJdeE.cjs';
2
2
  import { E as EventMap, H as HostClient } from './types-BxSYAH_H.cjs';
3
3
  export { C as Capability, G as GarretError, M as Manifest, S as Stream, f as StreamCall, g as defineConfig, h as defineManifest } from './types-BxSYAH_H.cjs';
4
- export { G as GarretPlatform, c as GarretRuntime, d as SecretsApi, e as ServiceClient, f as StorageApi, S as SurfaceApi, a as SurfaceHandle, b as SurfaceOpenOptions, W as WindowControls, g as getGarret, h as getHostTransport, i as getInstanceId, j as getRuntime } from './platform-DnI7gJTx.cjs';
4
+ export { G as GarretPlatform, c as GarretRuntime, d as SecretsApi, e as ServiceClient, f as StorageApi, S as SurfaceApi, a as SurfaceHandle, b as SurfaceOpenOptions, W as WindowControls, g as getGarret, h as getHostTransport, i as getInstanceId, j as getRuntime } from './platform-qz2Ef0Rp.cjs';
5
5
 
6
6
  /**
7
7
  * UI-side host client — a typed proxy over the wire (protocol.ts). Every call returns ONE handle
package/dist/ui.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { T as Transport } from './protocol-Do0BJdeE.js';
2
2
  import { E as EventMap, H as HostClient } from './types-BxSYAH_H.js';
3
3
  export { C as Capability, G as GarretError, M as Manifest, S as Stream, f as StreamCall, g as defineConfig, h as defineManifest } from './types-BxSYAH_H.js';
4
- export { G as GarretPlatform, c as GarretRuntime, d as SecretsApi, e as ServiceClient, f as StorageApi, S as SurfaceApi, a as SurfaceHandle, b as SurfaceOpenOptions, W as WindowControls, g as getGarret, h as getHostTransport, i as getInstanceId, j as getRuntime } from './platform-CZHtdUK0.js';
4
+ export { G as GarretPlatform, c as GarretRuntime, d as SecretsApi, e as ServiceClient, f as StorageApi, S as SurfaceApi, a as SurfaceHandle, b as SurfaceOpenOptions, W as WindowControls, g as getGarret, h as getHostTransport, i as getInstanceId, j as getRuntime } from './platform-Bbj2Vh3W.js';
5
5
 
6
6
  /**
7
7
  * UI-side host client — a typed proxy over the wire (protocol.ts). Every call returns ONE handle
package/dist/ui.js CHANGED
@@ -1,3 +1,3 @@
1
1
  export { defineConfig, defineManifest } from './chunk-RZJO3X6O.js';
2
- export { createHostClient, getGarret, getHostTransport, getInstanceId, getRuntime } from './chunk-ZJYHRC5C.js';
2
+ export { createHostClient, getGarret, getHostTransport, getInstanceId, getRuntime } from './chunk-AIGAFJFB.js';
3
3
  export { GarretError } from './chunk-ENIDFSMM.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@garretapp/sdk",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Build extensions for Garret — one SDK for both web widgets and full-access native extensions. Host runtime (defineHost), UI client + React hooks. See docs/garret.html.",
5
5
  "license": "MIT",
6
6
  "author": "Sudharsan Selvaraj",