pi-extension-utils 0.2.0 → 0.2.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/README.md CHANGED
@@ -22,8 +22,23 @@ const client = connect(pi, { ctx, clientId: "my-extension" });
22
22
  client.widgets.set("belowEditor", "status", (tui, theme) => component, { order: 10 });
23
23
  client.widgets.remove("belowEditor", "status");
24
24
 
25
+ // Run a custom fullscreen UI: widgets are blanked before mount and
26
+ // restored afterwards, even if the component throws.
27
+ const result = await client.ui.fullscreen<string | null>(
28
+ (tui, theme, keybindings, done) => new MyOverlayComponent(tui, theme, done),
29
+ );
30
+
31
+ // Lower-level lease, for manual control over the blank/restore window.
25
32
  const lease = client.fullscreen.acquire();
26
33
  lease.release();
34
+
35
+ // Reminders (host absorbed from pi-reminders): fire-and-forget emits;
36
+ // list() resolves { reminders: [], count: 0 } when no host is present.
37
+ client.reminders.upsert({ id: "my-reminder", text: "...", source: "my-extension" });
38
+ client.reminders.remove("my-reminder");
39
+ client.reminders.clearSource("my-extension");
40
+ const { reminders } = await client.reminders.list();
41
+
27
42
  client.dispose();
28
43
 
29
44
  const log = createLogger("my-extension");
@@ -11,6 +11,11 @@ export interface WidgetSetOptions {
11
11
  export interface FullscreenLease {
12
12
  release(): void;
13
13
  }
14
+ /**
15
+ * Factory signature accepted by `ctx.ui.custom`. Typed structurally so the
16
+ * client does not depend on pi-tui types directly.
17
+ */
18
+ export type FullscreenComponentFactory<T> = (tui: unknown, theme: unknown, keybindings: unknown, done: (result: T) => void) => unknown;
14
19
  export interface RemindersClient {
15
20
  upsert(intent: ReminderIntent): void;
16
21
  remove(source: string, key: string): void;
@@ -28,6 +33,14 @@ export interface UtilsClient {
28
33
  fullscreen: {
29
34
  acquire(): FullscreenLease;
30
35
  };
36
+ ui: {
37
+ /**
38
+ * Run a full-screen custom UI: acquires a fullscreen lease (blanking
39
+ * coordinated widgets), shows the component via `ctx.ui.custom`, and
40
+ * releases the lease in a finally — even if the component throws.
41
+ */
42
+ fullscreen<T>(factory: FullscreenComponentFactory<T>): Promise<T>;
43
+ };
31
44
  reminders: RemindersClient;
32
45
  dispose(): void;
33
46
  }
@@ -104,6 +104,21 @@ export function connect(pi, opts) {
104
104
  };
105
105
  },
106
106
  },
107
+ ui: {
108
+ async fullscreen(factory) {
109
+ const ui = opts.ctx.ui;
110
+ if (typeof ui.custom !== "function") {
111
+ throw new Error("pi-extension-utils: ui.fullscreen requires an interactive UI (ctx.ui.custom is unavailable)");
112
+ }
113
+ const lease = client.fullscreen.acquire();
114
+ try {
115
+ return await ui.custom(factory);
116
+ }
117
+ finally {
118
+ lease.release();
119
+ }
120
+ },
121
+ },
107
122
  reminders: {
108
123
  upsert(intent) {
109
124
  if (disposed)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-extension-utils",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Shared Pi extension utilities for coordinated widgets, fullscreen leases, and logging.",
5
5
  "type": "module",
6
6
  "main": "./dist/src/index.js",