@edenapp/tablets 0.5.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/LICENSE +21 -0
- package/README.md +54 -0
- package/dist/context-menu.d.ts +24 -0
- package/dist/context-menu.d.ts.map +1 -0
- package/dist/context-menu.js +145 -0
- package/dist/context-menu.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/menu.d.ts +40 -0
- package/dist/menu.d.ts.map +1 -0
- package/dist/menu.js +41 -0
- package/dist/menu.js.map +1 -0
- package/package.json +35 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Dariusz Majnert
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# @edenapp/tablets
|
|
2
|
+
|
|
3
|
+
Tiny context menu toolkit for Eden renderer apps. It provides a small runtime helper and menu builder so apps can open Eden’s system context menu without wiring IPC directly.
|
|
4
|
+
|
|
5
|
+
## What it does
|
|
6
|
+
|
|
7
|
+
- Provides `contextMenu` runtime helper for opening/closing menus.
|
|
8
|
+
- Provides menu builder helpers (`menu`, `button`, `title`, `separator`, `when`).
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pnpm add @edenapp/tablets
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @edenapp/tablets
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
yarn add @edenapp/tablets
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Basic usage
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { contextMenu, menu, button, title } from "@edenapp/tablets";
|
|
28
|
+
|
|
29
|
+
const appMenu = menu((app: { id: string; name: string }) => [
|
|
30
|
+
title(app.name),
|
|
31
|
+
button("open", "Open", () => console.log("open", app.id)),
|
|
32
|
+
button("remove", "Remove", () => console.log("remove", app.id), {
|
|
33
|
+
danger: true,
|
|
34
|
+
}),
|
|
35
|
+
]);
|
|
36
|
+
|
|
37
|
+
// Build a standard HTML/JS onContextMenu event handler for your component/element
|
|
38
|
+
const onContextMenu = appMenu.handler({
|
|
39
|
+
id: "com.example.app",
|
|
40
|
+
name: "Example",
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Example usage (React/Solid/JSX):
|
|
44
|
+
// <div onContextMenu={onContextMenu}>Right-click me</div>
|
|
45
|
+
|
|
46
|
+
// Or open at a specific position
|
|
47
|
+
void appMenu.show(
|
|
48
|
+
{ id: "com.example.app", name: "Example" },
|
|
49
|
+
{ left: 120, top: 80 },
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
// Close the active menu
|
|
53
|
+
void contextMenu.close();
|
|
54
|
+
```
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ContextMenuItem, ContextMenuOpenArgs, ContextMenuPosition, ContextMenuResult } from "@edenapp/types";
|
|
2
|
+
export type ContextMenuActionItem = Extract<ContextMenuItem, {
|
|
3
|
+
type: "item";
|
|
4
|
+
}> & {
|
|
5
|
+
onSelect?: () => Promise<void> | void;
|
|
6
|
+
};
|
|
7
|
+
export type ContextMenuAction = ContextMenuActionItem | Exclude<ContextMenuItem, {
|
|
8
|
+
type: "item";
|
|
9
|
+
}>;
|
|
10
|
+
export interface ContextMenuOpenOptions extends Omit<ContextMenuOpenArgs, "items" | "position"> {
|
|
11
|
+
items: ContextMenuAction[];
|
|
12
|
+
position?: ContextMenuPosition;
|
|
13
|
+
event?: MouseEvent | TouchEvent | PointerEvent;
|
|
14
|
+
onDismiss?: () => Promise<void> | void;
|
|
15
|
+
onClose?: () => Promise<void> | void;
|
|
16
|
+
}
|
|
17
|
+
export interface EdenContextMenuAPI {
|
|
18
|
+
open: (options: ContextMenuOpenOptions) => Promise<ContextMenuResult>;
|
|
19
|
+
openAtCursor: (options: Omit<ContextMenuOpenOptions, "position" | "event">) => Promise<ContextMenuResult>;
|
|
20
|
+
createHandler: (getOptions: (event: MouseEvent | TouchEvent | PointerEvent) => ContextMenuOpenOptions) => (event: MouseEvent | TouchEvent | PointerEvent) => void;
|
|
21
|
+
close: (requestId?: string) => Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
export declare const contextMenu: EdenContextMenuAPI;
|
|
24
|
+
//# sourceMappingURL=context-menu.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-menu.d.ts","sourceRoot":"","sources":["../src/context-menu.ts"],"names":[],"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MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9C;AAkLD,eAAO,MAAM,WAAW,EAAE,kBAKzB,CAAC"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
const getEdenAPI = () => {
|
|
2
|
+
if (typeof window === "undefined") {
|
|
3
|
+
throw new Error("contextMenu can only be used in a browser environment.");
|
|
4
|
+
}
|
|
5
|
+
const api = window.edenAPI;
|
|
6
|
+
if (!api) {
|
|
7
|
+
throw new Error("edenAPI is not available on window.");
|
|
8
|
+
}
|
|
9
|
+
return api;
|
|
10
|
+
};
|
|
11
|
+
const contextMenuPending = new Map();
|
|
12
|
+
let contextMenuSubscribed = false;
|
|
13
|
+
let lastPointer = null;
|
|
14
|
+
let pointerTracking = false;
|
|
15
|
+
const trackPointer = (x, y) => {
|
|
16
|
+
lastPointer = { x, y };
|
|
17
|
+
};
|
|
18
|
+
const pointerHandler = (event) => {
|
|
19
|
+
trackPointer(event.clientX, event.clientY);
|
|
20
|
+
};
|
|
21
|
+
const touchHandler = (event) => {
|
|
22
|
+
const touch = event.touches[0] || event.changedTouches[0];
|
|
23
|
+
if (touch) {
|
|
24
|
+
trackPointer(touch.clientX, touch.clientY);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const ensurePointerTracking = () => {
|
|
28
|
+
if (pointerTracking || typeof window === "undefined")
|
|
29
|
+
return;
|
|
30
|
+
pointerTracking = true;
|
|
31
|
+
window.addEventListener("pointermove", pointerHandler, { passive: true });
|
|
32
|
+
window.addEventListener("mousemove", pointerHandler, { passive: true });
|
|
33
|
+
window.addEventListener("touchstart", touchHandler, { passive: true });
|
|
34
|
+
window.addEventListener("touchmove", touchHandler, { passive: true });
|
|
35
|
+
};
|
|
36
|
+
const resolvePositionFromEvent = (event) => {
|
|
37
|
+
if (!event)
|
|
38
|
+
return undefined;
|
|
39
|
+
if ("clientX" in event && "clientY" in event) {
|
|
40
|
+
return { left: event.clientX, top: event.clientY };
|
|
41
|
+
}
|
|
42
|
+
if ("touches" in event) {
|
|
43
|
+
const touch = event.touches[0] || event.changedTouches[0];
|
|
44
|
+
if (touch) {
|
|
45
|
+
return { left: touch.clientX, top: touch.clientY };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return undefined;
|
|
49
|
+
};
|
|
50
|
+
const stripAction = (item) => {
|
|
51
|
+
if (item.type !== "item")
|
|
52
|
+
return item;
|
|
53
|
+
const { onSelect, ...rest } = item;
|
|
54
|
+
return rest;
|
|
55
|
+
};
|
|
56
|
+
const ensureContextMenuSubscribed = async () => {
|
|
57
|
+
if (contextMenuSubscribed)
|
|
58
|
+
return;
|
|
59
|
+
contextMenuSubscribed = true;
|
|
60
|
+
const edenAPI = getEdenAPI();
|
|
61
|
+
await edenAPI.subscribe("context-menu/closed", (payload) => {
|
|
62
|
+
const resolver = contextMenuPending.get(payload.requestId);
|
|
63
|
+
if (resolver) {
|
|
64
|
+
contextMenuPending.delete(payload.requestId);
|
|
65
|
+
resolver(payload);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
const openContextMenu = async (options) => {
|
|
70
|
+
ensurePointerTracking();
|
|
71
|
+
await ensureContextMenuSubscribed();
|
|
72
|
+
const position = options.position ||
|
|
73
|
+
resolvePositionFromEvent(options.event) ||
|
|
74
|
+
(lastPointer ? { left: lastPointer.x, top: lastPointer.y } : undefined) || {
|
|
75
|
+
left: Math.round(window.innerWidth / 2),
|
|
76
|
+
top: Math.round(window.innerHeight / 2),
|
|
77
|
+
};
|
|
78
|
+
const edenAPI = getEdenAPI();
|
|
79
|
+
const { requestId } = await edenAPI.shellCommand("context-menu/open", {
|
|
80
|
+
title: options.title,
|
|
81
|
+
position,
|
|
82
|
+
items: options.items.map(stripAction),
|
|
83
|
+
});
|
|
84
|
+
return new Promise((resolve) => {
|
|
85
|
+
contextMenuPending.set(requestId, (result) => {
|
|
86
|
+
const run = async () => {
|
|
87
|
+
try {
|
|
88
|
+
if (result.itemId) {
|
|
89
|
+
const selected = options.items.find((item) => item.type === "item" && item.id === result.itemId);
|
|
90
|
+
if (selected?.onSelect) {
|
|
91
|
+
await selected.onSelect();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
else if (result.reason === "dismiss" && options.onDismiss) {
|
|
95
|
+
await options.onDismiss();
|
|
96
|
+
}
|
|
97
|
+
if (options.onClose) {
|
|
98
|
+
await options.onClose();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
console.error("Context menu handler failed:", error);
|
|
103
|
+
}
|
|
104
|
+
finally {
|
|
105
|
+
resolve(result);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
void run();
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
const openContextMenuAtCursor = async (options) => {
|
|
113
|
+
return openContextMenu({ ...options });
|
|
114
|
+
};
|
|
115
|
+
const createContextMenuHandler = (getOptions) => {
|
|
116
|
+
ensurePointerTracking();
|
|
117
|
+
return (event) => {
|
|
118
|
+
if ("preventDefault" in event &&
|
|
119
|
+
typeof event.preventDefault === "function") {
|
|
120
|
+
event.preventDefault();
|
|
121
|
+
}
|
|
122
|
+
if ("stopPropagation" in event &&
|
|
123
|
+
typeof event.stopPropagation === "function") {
|
|
124
|
+
event.stopPropagation();
|
|
125
|
+
}
|
|
126
|
+
const options = getOptions(event);
|
|
127
|
+
void openContextMenu({ ...options, event }).catch((error) => {
|
|
128
|
+
console.error("Failed to open context menu:", error);
|
|
129
|
+
if (options.onClose) {
|
|
130
|
+
void options.onClose();
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
const closeContextMenu = async (requestId) => {
|
|
136
|
+
const edenAPI = getEdenAPI();
|
|
137
|
+
await edenAPI.shellCommand("context-menu/close", { requestId });
|
|
138
|
+
};
|
|
139
|
+
export const contextMenu = {
|
|
140
|
+
open: openContextMenu,
|
|
141
|
+
openAtCursor: openContextMenuAtCursor,
|
|
142
|
+
createHandler: createContextMenuHandler,
|
|
143
|
+
close: closeContextMenu,
|
|
144
|
+
};
|
|
145
|
+
//# sourceMappingURL=context-menu.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-menu.js","sourceRoot":"","sources":["../src/context-menu.ts"],"names":[],"mappings":"AAgDA,MAAM,UAAU,GAAG,GAAqB,EAAE;IACxC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;IAC5E,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,IAAI,GAAG,EAG/B,CAAC;AACJ,IAAI,qBAAqB,GAAG,KAAK,CAAC;AAClC,IAAI,WAAW,GAAoC,IAAI,CAAC;AACxD,IAAI,eAAe,GAAG,KAAK,CAAC;AAE5B,MAAM,YAAY,GAAG,CAAC,CAAS,EAAE,CAAS,EAAE,EAAE;IAC5C,WAAW,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AACzB,CAAC,CAAC;AAEF,MAAM,cAAc,GAAG,CAAC,KAAgC,EAAE,EAAE;IAC1D,YAAY,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;AAC7C,CAAC,CAAC;AAEF,MAAM,YAAY,GAAG,CAAC,KAAiB,EAAE,EAAE;IACzC,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;IAC1D,IAAI,KAAK,EAAE,CAAC;QACV,YAAY,CAAC,KAAK,CAAC,OAAO,EAAE,KAA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,eAAe;IACrB,YAAY,EAAE,uBAAuB;IACrC,aAAa,EAAE,wBAAwB;IACvC,KAAK,EAAE,gBAAgB;CACxB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ,CAAC"}
|
package/dist/menu.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ContextMenuIconName } from "@edenapp/types";
|
|
2
|
+
import { type ContextMenuAction } from "./context-menu";
|
|
3
|
+
type MenuTitle = {
|
|
4
|
+
__brand: "title";
|
|
5
|
+
text: string;
|
|
6
|
+
};
|
|
7
|
+
export type MenuElement = ContextMenuAction | MenuTitle | null | undefined | false;
|
|
8
|
+
/** Menu title - will be extracted and used as the context menu title */
|
|
9
|
+
export declare const title: (text: string) => MenuTitle;
|
|
10
|
+
/** Menu button */
|
|
11
|
+
export declare const button: (id: string, label: string, onSelect: () => void | Promise<void>, opts?: {
|
|
12
|
+
icon?: ContextMenuIconName;
|
|
13
|
+
danger?: boolean;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
}) => ContextMenuAction;
|
|
16
|
+
/** Menu separator */
|
|
17
|
+
export declare const separator: () => ContextMenuAction;
|
|
18
|
+
/** Conditional item - returns ifTrue when condition is true, ifFalse otherwise */
|
|
19
|
+
export declare const when: <T>(condition: boolean, ifTrue: T, ifFalse?: T) => T | null;
|
|
20
|
+
type Position = {
|
|
21
|
+
left: number;
|
|
22
|
+
top: number;
|
|
23
|
+
};
|
|
24
|
+
export interface Menu<T> {
|
|
25
|
+
/** Show context menu with data */
|
|
26
|
+
show(data: T, position?: Position): Promise<void>;
|
|
27
|
+
/** Create event handler for onContextMenu */
|
|
28
|
+
handler(data: T | (() => T)): (e: MouseEvent) => void;
|
|
29
|
+
/** Get menu config (for advanced use) */
|
|
30
|
+
build(data: T): {
|
|
31
|
+
title?: string;
|
|
32
|
+
items: ContextMenuAction[];
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Create a menu object with .show() and .handler() methods.
|
|
37
|
+
*/
|
|
38
|
+
export declare const menu: <T>(factory: (data: T) => MenuElement[]) => Menu<T>;
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=menu.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"menu.d.ts","sourceRoot":"","sources":["../src/menu.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,KAAK,iBAAiB,EAAe,MAAM,gBAAgB,CAAC;AAErE,KAAK,SAAS,GAAG;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AACpD,MAAM,MAAM,WAAW,GACnB,iBAAiB,GACjB,SAAS,GACT,IAAI,GACJ,SAAS,GACT,KAAK,CAAC;AAEV,wEAAwE;AACxE,eAAO,MAAM,KAAK,SAAU,MAAM,KAAG,SAAyC,CAAC;AAE/E,kBAAkB;AAClB,eAAO,MAAM,MAAM,OACb,MAAM,SACH,MAAM,YACH,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,SAC7B;IAAE,IAAI,CAAC,EAAE,mBAAmB,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,KAC1E,iBAAqE,CAAC;AAEzE,qBAAqB;AACrB,eAAO,MAAM,SAAS,QAAO,iBAA4C,CAAC;AAE1E,kFAAkF;AAClF,eAAO,MAAM,IAAI,GAAI,CAAC,aACT,OAAO,UACV,CAAC,YACC,CAAC,KACV,CAAC,GAAG,IAAgD,CAAC;AA0BxD,KAAK,QAAQ,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9C,MAAM,WAAW,IAAI,CAAC,CAAC;IACrB,kCAAkC;IAClC,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClD,6CAA6C;IAC7C,OAAO,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,UAAU,KAAK,IAAI,CAAC;IACtD,yCAAyC;IACzC,KAAK,CAAC,IAAI,EAAE,CAAC,GAAG;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,iBAAiB,EAAE,CAAA;KAAE,CAAC;CAChE;AAED;;GAEG;AACH,eAAO,MAAM,IAAI,GAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,KAAK,WAAW,EAAE,KAAG,IAAI,CAAC,CAAC,CAanE,CAAC"}
|
package/dist/menu.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { contextMenu } from "./context-menu";
|
|
2
|
+
/** Menu title - will be extracted and used as the context menu title */
|
|
3
|
+
export const title = (text) => ({ __brand: "title", text });
|
|
4
|
+
/** Menu button */
|
|
5
|
+
export const button = (id, label, onSelect, opts) => ({ type: "item", id, label, onSelect, ...opts });
|
|
6
|
+
/** Menu separator */
|
|
7
|
+
export const separator = () => ({ type: "separator" });
|
|
8
|
+
/** Conditional item - returns ifTrue when condition is true, ifFalse otherwise */
|
|
9
|
+
export const when = (condition, ifTrue, ifFalse) => (condition ? ifTrue : (ifFalse ?? null));
|
|
10
|
+
/**
|
|
11
|
+
* Create a menu factory from an array of elements.
|
|
12
|
+
* Extracts title, filters nulls, returns { title, items } format.
|
|
13
|
+
*/
|
|
14
|
+
const buildMenu = (factory) => {
|
|
15
|
+
return (data) => {
|
|
16
|
+
const elements = factory(data);
|
|
17
|
+
const titleEl = elements.find((el) => el != null &&
|
|
18
|
+
typeof el === "object" &&
|
|
19
|
+
"__brand" in el &&
|
|
20
|
+
el.__brand === "title");
|
|
21
|
+
const items = elements.filter((el) => el != null && typeof el === "object" && !("__brand" in el));
|
|
22
|
+
return { title: titleEl?.text, items };
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Create a menu object with .show() and .handler() methods.
|
|
27
|
+
*/
|
|
28
|
+
export const menu = (factory) => {
|
|
29
|
+
const build = buildMenu(factory);
|
|
30
|
+
return {
|
|
31
|
+
build,
|
|
32
|
+
show: async (data, position) => {
|
|
33
|
+
await contextMenu.open({ ...build(data), position });
|
|
34
|
+
},
|
|
35
|
+
handler: (data) => {
|
|
36
|
+
const getData = typeof data === "function" ? data : () => data;
|
|
37
|
+
return contextMenu.createHandler(() => build(getData()));
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=menu.js.map
|
package/dist/menu.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"menu.js","sourceRoot":"","sources":["../src/menu.ts"],"names":[],"mappings":"AACA,OAAO,EAA0B,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAUrE,wEAAwE;AACxE,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,IAAY,EAAa,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;AAE/E,kBAAkB;AAClB,MAAM,CAAC,MAAM,MAAM,GAAG,CACpB,EAAU,EACV,KAAa,EACb,QAAoC,EACpC,IAA2E,EACxD,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,QA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AM,WAAW,CAAC,IAAI,CAAC,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;QACvD,CAAC;QACD,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;YAChB,MAAM,OAAO,GACX,OAAO,IAAI,KAAK,UAAU,CAAC,CAAC,CAAE,IAAgB,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC;YAC9D,OAAO,WAAW,CAAC,aAAa,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QAC3D,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@edenapp/tablets",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "Context menu utilities for Eden apps",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"typescript": "^5.3.0",
|
|
21
|
+
"@edenapp/types": "0.5.0"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"eden",
|
|
25
|
+
"context-menu",
|
|
26
|
+
"renderer",
|
|
27
|
+
"ipc"
|
|
28
|
+
],
|
|
29
|
+
"author": "Dariusz Majnert",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsc",
|
|
33
|
+
"clean": "rm -rf dist"
|
|
34
|
+
}
|
|
35
|
+
}
|