@octane-xplat/app-menu 0.0.1 → 0.20.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,129 @@
1
+ /**
2
+ * Native desktop application menu bar API — the top-level menu owned by the
3
+ * application (NSApp.mainMenu on macOS, the GApplication menubar on GTK4,
4
+ * native buttons and MenuFlyouts above Windows window content).
5
+ * Distinct from in-window DropdownMenu/ContextMenu surfaces and from
6
+ * tray/status-bar icons.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { appMenu } from '@octane-xplat/app-menu'
11
+ *
12
+ * const handle = appMenu.install([
13
+ * { type: 'submenu', key: 'file', label: 'File', items: [
14
+ * { type: 'action', key: 'new', label: 'New', accelerator: 'Mod+N', onSelect: newDocument },
15
+ * { type: 'separator', key: 'after-new' },
16
+ * { type: 'role', key: 'quit', role: 'quit' },
17
+ * ]},
18
+ * ])
19
+ * // Later: handle.update(nextMenus) or handle.dispose()
20
+ * ```
21
+ */
22
+ /** Standard item behavior the platform menu engine already owns — no
23
+ * callback, no custom accelerator. `quit` only appears inside the automatic
24
+ * macOS application menu; GTK supplies its application action. Windows
25
+ * explicitly rejects every role; use action callbacks on that host. */
26
+ export type AppMenuRole = 'undo' | 'redo' | 'cut' | 'copy' | 'paste' | 'selectAll' | 'minimize' | 'close' | 'quit';
27
+ /** A plain menu item that runs `onSelect` when activated.
28
+ * @example
29
+ * ```ts
30
+ * const open: AppMenuAction = {
31
+ * type: 'action', key: 'open', label: 'Open…',
32
+ * accelerator: 'Mod+O', onSelect: () => openFile(),
33
+ * }
34
+ * ``` */
35
+ export interface AppMenuAction {
36
+ type: 'action';
37
+ /** Stable identity among sibling entries; unique per parent menu. */
38
+ key: string;
39
+ label: string;
40
+ /** `'Mod+Shift+Z'`-style accelerator — see the package accelerator grammar. */
41
+ accelerator?: string;
42
+ isDisabled?: boolean;
43
+ onSelect(): void;
44
+ }
45
+ /** A checkable menu item. Controlled: activation reports the *next* value via
46
+ * `onValueChange(!value)`; the native check mark only moves when the app
47
+ * installs a new `value` through `update()`.
48
+ * @example
49
+ * ```ts
50
+ * const sidebar: AppMenuCheckbox = {
51
+ * type: 'checkbox', key: 'sidebar', label: 'Sidebar',
52
+ * value: showSidebar, accelerator: 'Mod+Shift+S',
53
+ * onValueChange: (next) => setSidebar(next),
54
+ * }
55
+ * ``` */
56
+ export interface AppMenuCheckbox {
57
+ type: 'checkbox';
58
+ key: string;
59
+ label: string;
60
+ value: boolean;
61
+ accelerator?: string;
62
+ isDisabled?: boolean;
63
+ onValueChange(value: boolean): void;
64
+ }
65
+ /** A separator row. Leading, trailing and repeated separators collapse on
66
+ * every platform (GTK sections require it). */
67
+ export interface AppMenuSeparator {
68
+ type: 'separator';
69
+ key: string;
70
+ }
71
+ /** A nested menu. Menu-bar entries are always submenus; nested submenus are
72
+ * allowed inside them. Submenus cannot be disabled — GMenu has no such
73
+ * concept. */
74
+ export interface AppMenuSubmenu {
75
+ type: 'submenu';
76
+ key: string;
77
+ label: string;
78
+ items: readonly AppMenuEntry[];
79
+ }
80
+ /** A standard item the platform owns: fixed default label (overridable via
81
+ * `label`), fixed accelerator, native behavior. See the package role matrix
82
+ * for per-platform behavior.
83
+ * @example
84
+ * ```ts
85
+ * const copy: AppMenuRoleItem = { type: 'role', key: 'copy', role: 'copy' }
86
+ * ``` */
87
+ export interface AppMenuRoleItem {
88
+ type: 'role';
89
+ key: string;
90
+ role: AppMenuRole;
91
+ /** Overrides the default English label. */
92
+ label?: string;
93
+ }
94
+ /** One menu entry — action, checkbox, separator, submenu or platform role. */
95
+ export type AppMenuEntry = AppMenuAction | AppMenuCheckbox | AppMenuSeparator | AppMenuSubmenu | AppMenuRoleItem;
96
+ /** Per-platform install options. Namespaced: other platforms ignore
97
+ * `options.macos` rather than erroring. */
98
+ export interface AppMenuOptions {
99
+ macos?: {
100
+ /** Extra entries inserted into the automatic application menu, between
101
+ * the About item and the Hide/Show All group. */
102
+ applicationItems?: readonly AppMenuEntry[];
103
+ };
104
+ }
105
+ /** Handle for the installed menu. `update` replaces the whole tree
106
+ * (validated synchronously before any native write); `dispose` restores the
107
+ * previous menu bar and is idempotent. */
108
+ export interface AppMenu {
109
+ update(menus: readonly AppMenuSubmenu[], options?: AppMenuOptions): void;
110
+ dispose(): void;
111
+ readonly isDisposed: boolean;
112
+ }
113
+ /** The flat capability service. `supported` is a cheap sync check evaluated
114
+ * on each read; `isAvailable()` is the authoritative async probe. `install`
115
+ * throws `UnavailabilityError('appMenu')` on absent platforms and
116
+ * `Error('An app menu is already installed; update or dispose it first')`
117
+ * while another handle is live — one owner per process.
118
+ * @example
119
+ * ```ts
120
+ * import { appMenu } from '@octane-xplat/app-menu'
121
+ * if (appMenu.supported) {
122
+ * const handle = appMenu.install(menus)
123
+ * }
124
+ * ``` */
125
+ export interface AppMenuService {
126
+ readonly supported: boolean;
127
+ isAvailable(): Promise<boolean>;
128
+ install(menus: readonly AppMenuSubmenu[], options?: AppMenuOptions): AppMenu;
129
+ }