@edenapp/tablets 0.12.1 → 0.14.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/README.md CHANGED
@@ -1,11 +1,12 @@
1
1
  # @edenapp/tablets
2
2
 
3
- Tiny renderer toolkit for Eden apps. It provides runtime helpers for Eden’s system context menu and file picker without wiring IPC directly.
3
+ Tiny renderer toolkit for Eden apps. It provides runtime helpers for Eden’s system context menu, file picker, and notifications without wiring IPC directly.
4
4
 
5
5
  ## What it does
6
6
 
7
7
  - Provides `contextMenu` runtime helper for opening/closing menus.
8
8
  - Provides `filePicker` async helpers for opening and saving file paths.
9
+ - Provides `notification` helpers with automatically routed action callbacks.
9
10
  - Provides menu builder helpers (`menu`, `button`, `title`, `separator`, `when`).
10
11
 
11
12
  ## Install
@@ -69,3 +70,34 @@ const savePath = await filePicker.saveFile({
69
70
  filters: [{ name: "Markdown", extensions: ["md"] }],
70
71
  });
71
72
  ```
73
+
74
+ ## Notifications
75
+
76
+ ```ts
77
+ import { notification } from "@edenapp/tablets";
78
+
79
+ await notification.push("Saved", "Your changes were saved.", {
80
+ type: "success",
81
+ });
82
+
83
+ await notification.push(
84
+ "Update ready",
85
+ "Restart to apply the update.",
86
+ [
87
+ {
88
+ label: "Restart",
89
+ onClick: async () => restartApp(),
90
+ },
91
+ {
92
+ label: "Later",
93
+ dismissOnClick: false,
94
+ onClick: () => scheduleReminder(),
95
+ },
96
+ ],
97
+ { timeout: 10_000 },
98
+ );
99
+ ```
100
+
101
+ Tablets generates action IDs and routes clicks back to the callback that created
102
+ each action. Actions dismiss the notification after a click by default. Set
103
+ `dismissOnClick: false` to keep the action active until the notification closes.
package/dist/index.d.ts CHANGED
@@ -2,4 +2,5 @@ export * from "./context-menu";
2
2
  export * from "./file-picker";
3
3
  export * from "./frame";
4
4
  export * from "./menu";
5
+ export * from "./notification";
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC"}
package/dist/index.js CHANGED
@@ -2,4 +2,5 @@ export * from "./context-menu";
2
2
  export * from "./file-picker";
3
3
  export * from "./frame";
4
4
  export * from "./menu";
5
+ export * from "./notification";
5
6
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { Notification, NotificationType } from "@edenapp/types";
2
+ export interface NotificationActionOptions {
3
+ label: string;
4
+ onClick: () => Promise<void> | void;
5
+ dismissOnClick?: boolean;
6
+ }
7
+ export interface NotificationPushOptions {
8
+ timeout?: number;
9
+ type?: NotificationType;
10
+ }
11
+ export interface EdenNotificationAPI {
12
+ push(title: string, message: string, options?: NotificationPushOptions): Promise<Notification>;
13
+ push(title: string, message: string, actions: NotificationActionOptions[], options?: NotificationPushOptions): Promise<Notification>;
14
+ }
15
+ export declare const notification: EdenNotificationAPI;
16
+ //# sourceMappingURL=notification.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notification.d.ts","sourceRoot":"","sources":["../src/notification.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,YAAY,EACZ,gBAAgB,EACjB,MAAM,gBAAgB,CAAC;AAExB,MAAM,WAAW,yBAAyB;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACpC,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,uBAAuB;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,gBAAgB,CAAC;CACzB;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,CACF,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,uBAAuB,GAChC,OAAO,CAAC,YAAY,CAAC,CAAC;IACzB,IAAI,CACF,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,yBAAyB,EAAE,EACpC,OAAO,CAAC,EAAE,uBAAuB,GAChC,OAAO,CAAC,YAAY,CAAC,CAAC;CAC1B;AAkKD,eAAO,MAAM,YAAY,EAAE,mBAA8B,CAAC"}
@@ -0,0 +1,112 @@
1
+ const actionsById = new Map();
2
+ const notificationsById = new Map();
3
+ let actionIdCounter = 0;
4
+ let subscriptionPromise;
5
+ const getEdenAPI = () => {
6
+ if (typeof window === "undefined") {
7
+ throw new Error("notification can only be used in a browser environment.");
8
+ }
9
+ const api = window.edenAPI;
10
+ if (!api) {
11
+ throw new Error("edenAPI is not available on window.");
12
+ }
13
+ return api;
14
+ };
15
+ const forgetNotification = (pending) => {
16
+ pending.active = false;
17
+ for (const actionId of pending.actionIds) {
18
+ actionsById.delete(actionId);
19
+ }
20
+ pending.actionIds.clear();
21
+ if (pending.notificationId) {
22
+ notificationsById.delete(pending.notificationId);
23
+ }
24
+ };
25
+ const handleActionClicked = (payload) => {
26
+ const action = actionsById.get(payload.actionId);
27
+ if (!action)
28
+ return;
29
+ if (!action.notification.notificationId) {
30
+ action.notification.notificationId = payload.notificationId;
31
+ notificationsById.set(payload.notificationId, action.notification);
32
+ }
33
+ if (action.dismissOnClick) {
34
+ forgetNotification(action.notification);
35
+ }
36
+ try {
37
+ const result = action.onClick();
38
+ if (result && typeof result.then === "function") {
39
+ void result.catch((error) => {
40
+ console.error("Notification action handler failed:", error);
41
+ });
42
+ }
43
+ }
44
+ catch (error) {
45
+ console.error("Notification action handler failed:", error);
46
+ }
47
+ };
48
+ const handleNotificationRemoved = (payload) => {
49
+ const pending = notificationsById.get(payload.id);
50
+ if (pending) {
51
+ forgetNotification(pending);
52
+ }
53
+ };
54
+ const ensureSubscribed = async () => {
55
+ if (!subscriptionPromise) {
56
+ const edenAPI = getEdenAPI();
57
+ subscriptionPromise = Promise.all([
58
+ edenAPI.subscribe("notification/action-clicked", handleActionClicked),
59
+ edenAPI.subscribe("notification/removed", handleNotificationRemoved),
60
+ ])
61
+ .then(() => undefined)
62
+ .catch((error) => {
63
+ subscriptionPromise = undefined;
64
+ throw error;
65
+ });
66
+ }
67
+ await subscriptionPromise;
68
+ };
69
+ const generateActionId = () => `tablets-notification-${Date.now()}-${++actionIdCounter}`;
70
+ const push = async (title, message, actionsOrOptions = {}, maybeOptions = {}) => {
71
+ const actions = Array.isArray(actionsOrOptions) ? actionsOrOptions : [];
72
+ const options = Array.isArray(actionsOrOptions)
73
+ ? maybeOptions
74
+ : actionsOrOptions;
75
+ const pending = { active: true, actionIds: new Set() };
76
+ if (actions.length > 0) {
77
+ await ensureSubscribed();
78
+ }
79
+ const transportActions = actions.map((action) => {
80
+ const id = generateActionId();
81
+ pending.actionIds.add(id);
82
+ actionsById.set(id, {
83
+ dismissOnClick: action.dismissOnClick !== false,
84
+ notification: pending,
85
+ onClick: action.onClick,
86
+ });
87
+ return {
88
+ id,
89
+ label: action.label,
90
+ dismissOnClick: action.dismissOnClick,
91
+ };
92
+ });
93
+ try {
94
+ const result = await getEdenAPI().shellCommand("notification/push", {
95
+ title,
96
+ message,
97
+ ...options,
98
+ ...(transportActions.length > 0 ? { actions: transportActions } : {}),
99
+ });
100
+ pending.notificationId = result.id;
101
+ if (pending.active && pending.actionIds.size > 0) {
102
+ notificationsById.set(result.id, pending);
103
+ }
104
+ return result;
105
+ }
106
+ catch (error) {
107
+ forgetNotification(pending);
108
+ throw error;
109
+ }
110
+ };
111
+ export const notification = { push };
112
+ //# sourceMappingURL=notification.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notification.js","sourceRoot":"","sources":["../src/notification.ts"],"names":[],"mappings":"AA2DA,MAAM,WAAW,GAAG,IAAI,GAAG,EAAwB,CAAC;AACpD,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAA+B,CAAC;AACjE,IAAI,eAAe,GAAG,CAAC,CAAC;AACxB,IAAI,mBAA8C,CAAC;AAEnD,MAAM,UAAU,GAAG,GAAqB,EAAE;IACxC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;IAC7E,CAAC;IAED,MAAM,GAAG,GAAI,MAAyC,CAAC,OAAO,CAAC;IAC/D,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IACzD,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,CAAC,OAA4B,EAAE,EAAE;IAC1D,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC;IACvB,KAAK,MAAM,QAAQ,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;QACzC,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC/B,CAAC;IACD,OAAO,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IAC1B,IA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-1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edenapp/tablets",
3
- "version": "0.12.1",
3
+ "version": "0.14.0",
4
4
  "description": "Context menu utilities for Eden apps",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -18,11 +18,13 @@
18
18
  "dependencies": {},
19
19
  "devDependencies": {
20
20
  "typescript": "^6.0.3",
21
- "@edenapp/types": "0.12.1"
21
+ "vitest": "^4.1.10",
22
+ "@edenapp/types": "0.14.0"
22
23
  },
23
24
  "keywords": [
24
25
  "eden",
25
26
  "context-menu",
27
+ "notification",
26
28
  "renderer",
27
29
  "ipc"
28
30
  ],
@@ -35,6 +37,7 @@
35
37
  },
36
38
  "scripts": {
37
39
  "build": "tsc",
38
- "clean": "rm -rf dist"
40
+ "clean": "rm -rf dist",
41
+ "test": "vitest run src"
39
42
  }
40
43
  }