@ng-native/device 0.22.1 → 0.23.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/dist/accessibility.d.ts +7 -0
- package/dist/accessibility.js +14 -2
- package/dist/accessibility.js.map +1 -1
- package/dist/app-lifecycle.d.ts +49 -0
- package/dist/app-lifecycle.js +67 -0
- package/dist/app-lifecycle.js.map +1 -0
- package/dist/app-state.d.ts +2 -0
- package/dist/app-state.js +2 -0
- package/dist/app-state.js.map +1 -1
- package/dist/app-windows.d.ts +321 -0
- package/dist/app-windows.js +526 -0
- package/dist/app-windows.js.map +1 -0
- package/dist/color-scheme.d.ts +2 -0
- package/dist/color-scheme.js +2 -0
- package/dist/color-scheme.js.map +1 -1
- package/dist/conditions.d.ts +11 -3
- package/dist/conditions.js +42 -9
- package/dist/conditions.js.map +1 -1
- package/dist/control-size.d.ts +6 -0
- package/dist/control-size.js +2 -0
- package/dist/control-size.js.map +1 -0
- package/dist/deep-links.d.ts +3 -1
- package/dist/deep-links.js +3 -1
- package/dist/deep-links.js.map +1 -1
- package/dist/desktop-options.d.ts +73 -0
- package/dist/desktop-options.js +182 -0
- package/dist/desktop-options.js.map +1 -0
- package/dist/desktop-permissions.d.ts +30 -0
- package/dist/desktop-permissions.js +169 -0
- package/dist/desktop-permissions.js.map +1 -0
- package/dist/dev-menu.d.ts +2 -2
- package/dist/dev-menu.js +3 -5
- package/dist/dev-menu.js.map +1 -1
- package/dist/dialogs.d.ts +9 -7
- package/dist/dialogs.js +15 -10
- package/dist/dialogs.js.map +1 -1
- package/dist/direction.d.ts +2 -0
- package/dist/direction.js +2 -0
- package/dist/direction.js.map +1 -1
- package/dist/dock.d.ts +48 -0
- package/dist/dock.js +70 -0
- package/dist/dock.js.map +1 -0
- package/dist/drag-and-drop.d.ts +67 -0
- package/dist/drag-and-drop.js +74 -0
- package/dist/drag-and-drop.js.map +1 -0
- package/dist/expo-view-name.d.ts +16 -0
- package/dist/expo-view-name.js +22 -0
- package/dist/expo-view-name.js.map +1 -0
- package/dist/hardware-back.d.ts +3 -10
- package/dist/hardware-back.js +4 -1
- package/dist/hardware-back.js.map +1 -1
- package/dist/index.d.ts +26 -2
- package/dist/index.js +26 -2
- package/dist/index.js.map +1 -1
- package/dist/interaction-observer.d.ts +117 -0
- package/dist/interaction-observer.js +241 -0
- package/dist/interaction-observer.js.map +1 -0
- package/dist/keyboard.d.ts +2 -8
- package/dist/keyboard.js +3 -0
- package/dist/keyboard.js.map +1 -1
- package/dist/layout-animation.d.ts +3 -1
- package/dist/layout-animation.js +3 -1
- package/dist/layout-animation.js.map +1 -1
- package/dist/menu-model.d.ts +108 -0
- package/dist/menu-model.js +259 -0
- package/dist/menu-model.js.map +1 -0
- package/dist/menu-template.d.ts +19 -0
- package/dist/menu-template.js +31 -0
- package/dist/menu-template.js.map +1 -0
- package/dist/menus.d.ts +225 -0
- package/dist/menus.js +341 -0
- package/dist/menus.js.map +1 -0
- package/dist/navigation-bar.d.ts +2 -12
- package/dist/navigation-bar.js +4 -1
- package/dist/navigation-bar.js.map +1 -1
- package/dist/os-support.d.ts +42 -0
- package/dist/os-support.js +207 -0
- package/dist/os-support.js.map +1 -0
- package/dist/os.d.ts +26 -5
- package/dist/os.js +35 -7
- package/dist/os.js.map +1 -1
- package/dist/own-host.d.ts +27 -0
- package/dist/own-host.js +79 -0
- package/dist/own-host.js.map +1 -0
- package/dist/processes.d.ts +116 -0
- package/dist/processes.js +177 -0
- package/dist/processes.js.map +1 -0
- package/dist/react-native.d.ts +19 -0
- package/dist/react-native.js.map +1 -1
- package/dist/safe-area.d.ts +12 -1
- package/dist/safe-area.js +16 -2
- package/dist/safe-area.js.map +1 -1
- package/dist/screen.d.ts +2 -0
- package/dist/screen.js +2 -0
- package/dist/screen.js.map +1 -1
- package/dist/sharing.d.ts +3 -1
- package/dist/sharing.js +8 -1
- package/dist/sharing.js.map +1 -1
- package/dist/shell.d.ts +33 -0
- package/dist/shell.js +73 -0
- package/dist/shell.js.map +1 -0
- package/dist/shortcut.d.ts +49 -0
- package/dist/shortcut.js +92 -0
- package/dist/shortcut.js.map +1 -0
- package/dist/sidebar-selection.d.ts +8 -0
- package/dist/sidebar-selection.js +9 -0
- package/dist/sidebar-selection.js.map +1 -0
- package/dist/spawn-rules.d.ts +108 -0
- package/dist/spawn-rules.js +313 -0
- package/dist/spawn-rules.js.map +1 -0
- package/dist/split-views.d.ts +7 -0
- package/dist/split-views.js +21 -0
- package/dist/split-views.js.map +1 -0
- package/dist/status-bar.d.ts +2 -12
- package/dist/status-bar.js +3 -0
- package/dist/status-bar.js.map +1 -1
- package/dist/tray.d.ts +63 -0
- package/dist/tray.js +76 -0
- package/dist/tray.js.map +1 -0
- package/dist/undo-stack.d.ts +64 -0
- package/dist/undo-stack.js +110 -0
- package/dist/undo-stack.js.map +1 -0
- package/dist/vibration.d.ts +3 -14
- package/dist/vibration.js +4 -1
- package/dist/vibration.js.map +1 -1
- package/dist/window-navigator.d.ts +25 -0
- package/dist/window-navigator.js +7 -0
- package/dist/window-navigator.js.map +1 -0
- package/dist/window-restore.d.ts +45 -0
- package/dist/window-restore.js +66 -0
- package/dist/window-restore.js.map +1 -0
- package/package.json +10 -2
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Menus as data, shared by every OS: the menu bar every desktop app gets, how an app's
|
|
3
|
+
* `<menu-bar>` merges into it, and the token a `<menu-item>` registers itself through.
|
|
4
|
+
*
|
|
5
|
+
* `@ng-native/components` builds this from `<menu-group>` and `<menu-item>`, a
|
|
6
|
+
* `<native-header-item [menu]>` reads it, and each OS draws it: the desktop host as the menu bar,
|
|
7
|
+
* iPadOS through UIMenuBuilder. The rules live here, in TypeScript, so every OS follows the same
|
|
8
|
+
* ones; only what AppKit adds itself (Services' contents, Spelling, Substitutions, Dictation and
|
|
9
|
+
* Emoji) is left to the desktop host.
|
|
10
|
+
*/
|
|
11
|
+
import { InjectionToken, computed, signal } from '@angular/core';
|
|
12
|
+
const SEPARATOR = { separator: true };
|
|
13
|
+
export const isSeparator = (entry) => 'separator' in entry;
|
|
14
|
+
/**
|
|
15
|
+
* The menu bar every desktop app gets: App, File, Edit, View, Window and Help, each item with its
|
|
16
|
+
* role and standard shortcut. `Settings...` is in it until the merge, which keeps it only when the
|
|
17
|
+
* app gives it a handler. File holds Print... (`mod+p`), which prints the key window unless the app
|
|
18
|
+
* gives a `print` item a handler.
|
|
19
|
+
*/
|
|
20
|
+
export function defaultMenuBar(appName) {
|
|
21
|
+
const item = (label, menuRole, shortcut) => shortcut ? { label, menuRole, shortcut } : { label, menuRole };
|
|
22
|
+
return [
|
|
23
|
+
{
|
|
24
|
+
label: appName,
|
|
25
|
+
menuRole: 'app',
|
|
26
|
+
items: [
|
|
27
|
+
item(`About ${appName}`, 'about'),
|
|
28
|
+
SEPARATOR,
|
|
29
|
+
item('Settings...', 'settings', 'mod+,'),
|
|
30
|
+
SEPARATOR,
|
|
31
|
+
item('Services', 'services'),
|
|
32
|
+
SEPARATOR,
|
|
33
|
+
item(`Hide ${appName}`, 'hide', 'mod+h'),
|
|
34
|
+
item('Hide Others', 'hideOthers', 'mod+alt+h'),
|
|
35
|
+
item('Show All', 'showAll'),
|
|
36
|
+
SEPARATOR,
|
|
37
|
+
item(`Quit ${appName}`, 'quit', 'mod+q'),
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
{ label: 'File', menuRole: 'file', items: [item('Print...', 'print', 'mod+p')] },
|
|
41
|
+
{
|
|
42
|
+
label: 'Edit',
|
|
43
|
+
menuRole: 'edit',
|
|
44
|
+
items: [
|
|
45
|
+
item('Undo', 'undo', 'mod+z'),
|
|
46
|
+
item('Redo', 'redo', 'mod+shift+z'),
|
|
47
|
+
SEPARATOR,
|
|
48
|
+
item('Cut', 'cut', 'mod+x'),
|
|
49
|
+
item('Copy', 'copy', 'mod+c'),
|
|
50
|
+
item('Paste', 'paste', 'mod+v'),
|
|
51
|
+
item('Select All', 'selectAll', 'mod+a'),
|
|
52
|
+
SEPARATOR,
|
|
53
|
+
item('Find', 'find', 'mod+f'),
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
label: 'View',
|
|
58
|
+
menuRole: 'view',
|
|
59
|
+
items: [
|
|
60
|
+
// Their keys are each OS's own, which `navigationShortcut` gives: not a `mod` chord.
|
|
61
|
+
item('Back', 'back'),
|
|
62
|
+
item('Forward', 'forward'),
|
|
63
|
+
SEPARATOR,
|
|
64
|
+
item('Show Sidebar', 'toggleSidebar', 'ctrl+mod+s'),
|
|
65
|
+
item('Enter Full Screen', 'toggleFullScreen', 'ctrl+mod+f'),
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
label: 'Window',
|
|
70
|
+
menuRole: 'window',
|
|
71
|
+
items: [
|
|
72
|
+
// An app with a File menu has it at the end of that menu instead, as a Mac app does.
|
|
73
|
+
item('Close Window', 'close', 'mod+w'),
|
|
74
|
+
item('Minimize', 'minimize', 'mod+m'),
|
|
75
|
+
item('Zoom', 'zoom'),
|
|
76
|
+
SEPARATOR,
|
|
77
|
+
item('Bring All to Front', 'bringAllToFront'),
|
|
78
|
+
],
|
|
79
|
+
},
|
|
80
|
+
{ label: 'Help', menuRole: 'help', items: [] },
|
|
81
|
+
];
|
|
82
|
+
}
|
|
83
|
+
/** Every item with a `menuRole`, by role, read through submenus and sections. */
|
|
84
|
+
function byRole(groups) {
|
|
85
|
+
const found = new Map();
|
|
86
|
+
const walk = (entries) => {
|
|
87
|
+
for (const entry of entries) {
|
|
88
|
+
if (isSeparator(entry))
|
|
89
|
+
continue;
|
|
90
|
+
if (entry.menuRole && !found.has(entry.menuRole))
|
|
91
|
+
found.set(entry.menuRole, entry);
|
|
92
|
+
if (entry.items)
|
|
93
|
+
walk(entry.items);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
for (const group of groups)
|
|
97
|
+
walk(group.items);
|
|
98
|
+
return found;
|
|
99
|
+
}
|
|
100
|
+
/** `entries` without the items `drop` names, and with no separator leading, trailing or doubled. */
|
|
101
|
+
function tidy(entries, drop) {
|
|
102
|
+
const kept = [];
|
|
103
|
+
for (const entry of entries) {
|
|
104
|
+
if (isSeparator(entry)) {
|
|
105
|
+
if (kept.length && !isSeparator(kept[kept.length - 1]))
|
|
106
|
+
kept.push(entry);
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (drop(entry))
|
|
110
|
+
continue;
|
|
111
|
+
kept.push(entry.items ? { ...entry, items: tidy(entry.items, drop) } : entry);
|
|
112
|
+
}
|
|
113
|
+
while (kept.length && isSeparator(kept[kept.length - 1]))
|
|
114
|
+
kept.pop();
|
|
115
|
+
return kept;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* The app's groups, each added to the default menu it names or set aside to go after App (a
|
|
119
|
+
* `file` group with no default File menu) or after View. The items for the default File menu are
|
|
120
|
+
* kept apart, to go before its own.
|
|
121
|
+
*/
|
|
122
|
+
function placeAppGroups(merged, app, defaultFile, moved) {
|
|
123
|
+
const afterApp = [];
|
|
124
|
+
const afterView = [];
|
|
125
|
+
let fileItems = [];
|
|
126
|
+
for (const group of app) {
|
|
127
|
+
const items = tidy(group.items, moved);
|
|
128
|
+
const standard = merged.find((one) => group.menuRole && one.menuRole === group.menuRole);
|
|
129
|
+
if (standard && standard === defaultFile)
|
|
130
|
+
fileItems = joined(fileItems, items);
|
|
131
|
+
else if (standard)
|
|
132
|
+
standard.items = joined(standard.items, items);
|
|
133
|
+
// A group whose items all replaced defaults: an empty menu is not worth a place in the bar.
|
|
134
|
+
else if (items.length)
|
|
135
|
+
(group.menuRole === 'file' ? afterApp : afterView).push({ ...group, items });
|
|
136
|
+
}
|
|
137
|
+
return { afterApp, afterView, fileItems };
|
|
138
|
+
}
|
|
139
|
+
/** `items` after `entries`, with a separator between when both have any. */
|
|
140
|
+
function joined(entries, items) {
|
|
141
|
+
return entries.length && items.length
|
|
142
|
+
? [...entries, SEPARATOR, ...items]
|
|
143
|
+
: [...entries, ...items];
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* The File menu: the app's items, then Close Window when it moved there, then the defaults
|
|
147
|
+
* (Print...), each part apart.
|
|
148
|
+
*/
|
|
149
|
+
function fileMenu(own, close, defaults) {
|
|
150
|
+
return tidy([...own, SEPARATOR, ...(close ? [close, SEPARATOR] : []), ...defaults], () => false);
|
|
151
|
+
}
|
|
152
|
+
/** The Window menu's Close Window (or the app's `close` item), taken out of it. */
|
|
153
|
+
function takeClose(groups) {
|
|
154
|
+
const window = groups.find((group) => group.menuRole === 'window');
|
|
155
|
+
const close = window?.items.find((entry) => !isSeparator(entry) && entry.menuRole === 'close');
|
|
156
|
+
if (!window || !close || isSeparator(close))
|
|
157
|
+
return undefined;
|
|
158
|
+
window.items = tidy(window.items, (item) => item === close);
|
|
159
|
+
return close;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* The menu bar an app ends up with, from the defaults and its `<menu-bar>`:
|
|
163
|
+
*
|
|
164
|
+
* - An app item with a `menuRole` replaces the default item with that role, where the default is,
|
|
165
|
+
* and leaves the group it was written in.
|
|
166
|
+
* - `Settings...` shows only when the app gives a `settings` item a handler.
|
|
167
|
+
* - A group whose `menuRole` names a default menu adds its items to the end of that menu; a `file`
|
|
168
|
+
* group's go before Print..., which stays last, as on a Mac.
|
|
169
|
+
* - A `file` group with no default File menu goes after the App menu, and any other group after
|
|
170
|
+
* View, in the order the app wrote them. A group left with no items is left out.
|
|
171
|
+
* - With a `file` group, the Window menu's Close Window (or the app's own `close` item) moves to
|
|
172
|
+
* the File menu, after the app's items and before the defaults.
|
|
173
|
+
*/
|
|
174
|
+
export function mergeMenuBar(defaults, app) {
|
|
175
|
+
const replacing = byRole(app);
|
|
176
|
+
const defaultRoles = byRole(defaults);
|
|
177
|
+
const settings = replacing.get('settings');
|
|
178
|
+
const replace = (entries) => entries.map((entry) => {
|
|
179
|
+
if (isSeparator(entry))
|
|
180
|
+
return entry;
|
|
181
|
+
const own = entry.menuRole && replacing.get(entry.menuRole);
|
|
182
|
+
if (own)
|
|
183
|
+
return own;
|
|
184
|
+
return entry.items ? { ...entry, items: replace(entry.items) } : entry;
|
|
185
|
+
});
|
|
186
|
+
const merged = defaults.map((group) => ({
|
|
187
|
+
...group,
|
|
188
|
+
items: tidy(replace(group.items), (item) => item.menuRole === 'settings' && !settings?.select),
|
|
189
|
+
}));
|
|
190
|
+
const moved = (item) => Boolean(item.menuRole && defaultRoles.has(item.menuRole));
|
|
191
|
+
const defaultFile = merged.find((group) => group.menuRole === 'file');
|
|
192
|
+
const { afterApp, afterView, fileItems } = placeAppGroups(merged, app, defaultFile, moved);
|
|
193
|
+
const file = defaultFile ?? afterApp[0];
|
|
194
|
+
if (file) {
|
|
195
|
+
const close = app.some((group) => group.menuRole === 'file') ? takeClose(merged) : undefined;
|
|
196
|
+
file.items = fileMenu(defaultFile ? fileItems : file.items, close, defaultFile?.items ?? []);
|
|
197
|
+
}
|
|
198
|
+
const at = (role) => merged.findIndex((group) => group.menuRole === role) + 1;
|
|
199
|
+
merged.splice(at('view'), 0, ...afterView);
|
|
200
|
+
merged.splice(at('app'), 0, ...afterApp);
|
|
201
|
+
return merged;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* A menu model for a container to provide as `MENU_MODEL`. `order` compares two places, negative
|
|
205
|
+
* for the first one earlier; places it cannot compare keep the order they registered in.
|
|
206
|
+
*/
|
|
207
|
+
export function createMenuModel(order) {
|
|
208
|
+
const registered = signal([], /* @ts-ignore */
|
|
209
|
+
...(ngDevMode ? [{ debugName: "registered" }] : /* istanbul ignore next */ []));
|
|
210
|
+
return {
|
|
211
|
+
entries: computed(() => {
|
|
212
|
+
const all = registered();
|
|
213
|
+
const sorted = order ? [...all].sort((a, b) => order(a.place, b.place)) : all;
|
|
214
|
+
return sorted.map((one) => one.entry());
|
|
215
|
+
}),
|
|
216
|
+
register(entry, place) {
|
|
217
|
+
const one = { entry, place };
|
|
218
|
+
registered.update((all) => [...all, one]);
|
|
219
|
+
return () => registered.update((all) => all.filter((each) => each !== one));
|
|
220
|
+
},
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
/** Where a node is in its tree: each ancestor's index in its parent, from the root down. */
|
|
224
|
+
function placeOf(node) {
|
|
225
|
+
const path = [];
|
|
226
|
+
let at = node;
|
|
227
|
+
while (at.parent) {
|
|
228
|
+
path.unshift(at.parent.childList.indexOf(at));
|
|
229
|
+
at = at.parent;
|
|
230
|
+
}
|
|
231
|
+
return { root: at, path };
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Which of two elements comes first in the tree: negative for `a`. Elements in different trees, or
|
|
235
|
+
* not in one yet, compare equal, and keep the order they registered in.
|
|
236
|
+
*/
|
|
237
|
+
export function treeOrder(a, b) {
|
|
238
|
+
if (!a || !b)
|
|
239
|
+
return 0;
|
|
240
|
+
const first = placeOf(a);
|
|
241
|
+
const second = placeOf(b);
|
|
242
|
+
if (first.root !== second.root)
|
|
243
|
+
return 0;
|
|
244
|
+
for (let i = 0; i < Math.min(first.path.length, second.path.length); i++) {
|
|
245
|
+
const step = first.path[i] - second.path[i];
|
|
246
|
+
if (step)
|
|
247
|
+
return step;
|
|
248
|
+
}
|
|
249
|
+
return first.path.length - second.path.length;
|
|
250
|
+
}
|
|
251
|
+
/** A menu model whose entries keep their places in the template. */
|
|
252
|
+
export const menuModelInTreeOrder = () => createMenuModel(treeOrder);
|
|
253
|
+
/**
|
|
254
|
+
* Where a `<menu-item>` registers itself: the menu it is written in, which a `<menu-group>`, a
|
|
255
|
+
* submenu or a `<native-header-item [menu]>` template provides. There is none at the root, so an
|
|
256
|
+
* item outside a menu is told so by its own injection.
|
|
257
|
+
*/
|
|
258
|
+
export const MENU_MODEL = new InjectionToken('angular-native.menuModel');
|
|
259
|
+
//# sourceMappingURL=menu-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"menu-model.js","sourceR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AC;IACvB,MAAM,KAAK,GAAG,OAAO,CAAC,CAAa,CAAC,CAAC;IACrC,MAAM,MAAM,GAAG,OAAO,CAAC,CAAa,CAAC,CAAC;IACtC,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI;QAAE,OAAO,CAAC,CAAC;IACzC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QACzE,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAE,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAE,CAAC;QAC9C,IAAI,IAAI;YAAE,OAAO,IAAI,CAAC;IACxB,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;AAChD,CAAC;AAED,oEAAoE;AACpE,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAc,EAAE,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;AAEhF;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,cAAc,CAAY,0BAA0B,CAAC,CAAC","sourcesContent":["/**\n * Menus as data, shared by every OS: the menu bar every desktop app gets, how an app's\n * `<menu-bar>` merges into it, and the token a `<menu-item>` registers itself through.\n *\n * `@ng-native/components` builds this from `<menu-group>` and `<menu-item>`, a\n * `<native-header-item [menu]>` reads it, and each OS draws it: the desktop host as the menu bar,\n * iPadOS through UIMenuBuilder. The rules live here, in TypeScript, so every OS follows the same\n * ones; only what AppKit adds itself (Services' contents, Spelling, Substitutions, Dictation and\n * Emoji) is left to the desktop host.\n */\nimport { InjectionToken, computed, signal, type Signal } from '@angular/core';\n\n/** A standard menu a `<menu-group menuRole>` adds its items to. */\nexport type MenuGroupRole = 'app' | 'file' | 'edit' | 'view' | 'window' | 'help';\n\n/**\n * What an item is for, where the OS has a standard one: an item with a `menuRole` replaces that\n * role's default item, and without a handler does what the OS does for it.\n */\nexport type MenuRole =\n | 'about'\n | 'settings'\n | 'services'\n | 'hide'\n | 'hideOthers'\n | 'showAll'\n | 'quit'\n | 'undo'\n | 'redo'\n | 'cut'\n | 'copy'\n | 'paste'\n | 'selectAll'\n | 'find'\n | 'toggleSidebar'\n | 'toggleFullScreen'\n | 'back'\n | 'forward'\n | 'minimize'\n | 'zoom'\n | 'bringAllToFront'\n | 'close'\n | 'print';\n\n/** One item in a menu. */\nexport interface MenuItemModel {\n readonly label: string;\n readonly menuRole?: MenuRole;\n /** `mod+s`, as `parseShortcut` reads it. */\n readonly shortcut?: string;\n readonly disabled?: boolean;\n /** A check mark, where the item is a toggle. */\n readonly checked?: boolean;\n readonly destructive?: boolean;\n readonly subtitle?: string;\n /** An SF Symbol, shown on Apple's OSes. */\n readonly sfSymbol?: string;\n /** A drawable resource's name, shown on Android. */\n readonly icon?: string;\n /**\n * The standard menu a top-level `<menu-group menuRole>` adds its items to, for a group written\n * in a `<menu-bar>`: what becomes `MenuGroupModel.menuRole`.\n */\n readonly group?: MenuGroupRole;\n /** A submenu, or with `inline` a section of the menu the item is in. */\n readonly items?: readonly MenuEntry[];\n readonly inline?: boolean;\n /** What choosing it does. Left out on an item with a `menuRole`, the OS does it. */\n readonly select?: () => void;\n}\n\n/** A line between items. */\nexport interface MenuSeparator {\n readonly separator: true;\n}\n\nexport type MenuEntry = MenuItemModel | MenuSeparator;\n\n/** One menu in the menu bar. */\nexport interface MenuGroupModel {\n readonly label: string;\n readonly menuRole?: MenuGroupRole;\n readonly items: readonly MenuEntry[];\n}\n\nconst SEPARATOR: MenuSeparator = { separator: true };\n\nexport const isSeparator = (entry: MenuEntry): entry is MenuSeparator => 'separator' in entry;\n\n/**\n * The menu bar every desktop app gets: App, File, Edit, View, Window and Help, each item with its\n * role and standard shortcut. `Settings...` is in it until the merge, which keeps it only when the\n * app gives it a handler. File holds Print... (`mod+p`), which prints the key window unless the app\n * gives a `print` item a handler.\n */\nexport function defaultMenuBar(appName: string): MenuGroupModel[] {\n const item = (label: string, menuRole: MenuRole, shortcut?: string): MenuItemModel =>\n shortcut ? { label, menuRole, shortcut } : { label, menuRole };\n return [\n {\n label: appName,\n menuRole: 'app',\n items: [\n item(`About ${appName}`, 'about'),\n SEPARATOR,\n item('Settings...', 'settings', 'mod+,'),\n SEPARATOR,\n item('Services', 'services'),\n SEPARATOR,\n item(`Hide ${appName}`, 'hide', 'mod+h'),\n item('Hide Others', 'hideOthers', 'mod+alt+h'),\n item('Show All', 'showAll'),\n SEPARATOR,\n item(`Quit ${appName}`, 'quit', 'mod+q'),\n ],\n },\n { label: 'File', menuRole: 'file', items: [item('Print...', 'print', 'mod+p')] },\n {\n label: 'Edit',\n menuRole: 'edit',\n items: [\n item('Undo', 'undo', 'mod+z'),\n item('Redo', 'redo', 'mod+shift+z'),\n SEPARATOR,\n item('Cut', 'cut', 'mod+x'),\n item('Copy', 'copy', 'mod+c'),\n item('Paste', 'paste', 'mod+v'),\n item('Select All', 'selectAll', 'mod+a'),\n SEPARATOR,\n item('Find', 'find', 'mod+f'),\n ],\n },\n {\n label: 'View',\n menuRole: 'view',\n items: [\n // Their keys are each OS's own, which `navigationShortcut` gives: not a `mod` chord.\n item('Back', 'back'),\n item('Forward', 'forward'),\n SEPARATOR,\n item('Show Sidebar', 'toggleSidebar', 'ctrl+mod+s'),\n item('Enter Full Screen', 'toggleFullScreen', 'ctrl+mod+f'),\n ],\n },\n {\n label: 'Window',\n menuRole: 'window',\n items: [\n // An app with a File menu has it at the end of that menu instead, as a Mac app does.\n item('Close Window', 'close', 'mod+w'),\n item('Minimize', 'minimize', 'mod+m'),\n item('Zoom', 'zoom'),\n SEPARATOR,\n item('Bring All to Front', 'bringAllToFront'),\n ],\n },\n { label: 'Help', menuRole: 'help', items: [] },\n ];\n}\n\n/** Every item with a `menuRole`, by role, read through submenus and sections. */\nfunction byRole(groups: readonly MenuGroupModel[]): Map<MenuRole, MenuItemModel> {\n const found = new Map<MenuRole, MenuItemModel>();\n const walk = (entries: readonly MenuEntry[]) => {\n for (const entry of entries) {\n if (isSeparator(entry)) continue;\n if (entry.menuRole && !found.has(entry.menuRole)) found.set(entry.menuRole, entry);\n if (entry.items) walk(entry.items);\n }\n };\n for (const group of groups) walk(group.items);\n return found;\n}\n\n/** `entries` without the items `drop` names, and with no separator leading, trailing or doubled. */\nfunction tidy(entries: readonly MenuEntry[], drop: (item: MenuItemModel) => boolean): MenuEntry[] {\n const kept: MenuEntry[] = [];\n for (const entry of entries) {\n if (isSeparator(entry)) {\n if (kept.length && !isSeparator(kept[kept.length - 1]!)) kept.push(entry);\n continue;\n }\n if (drop(entry)) continue;\n kept.push(entry.items ? { ...entry, items: tidy(entry.items, drop) } : entry);\n }\n while (kept.length && isSeparator(kept[kept.length - 1]!)) kept.pop();\n return kept;\n}\n\ntype MergedGroup = { label: string; menuRole?: MenuGroupRole; items: MenuEntry[] };\n\n/**\n * The app's groups, each added to the default menu it names or set aside to go after App (a\n * `file` group with no default File menu) or after View. The items for the default File menu are\n * kept apart, to go before its own.\n */\nfunction placeAppGroups(\n merged: MergedGroup[],\n app: readonly MenuGroupModel[],\n defaultFile: MergedGroup | undefined,\n moved: (item: MenuItemModel) => boolean,\n): { afterApp: MergedGroup[]; afterView: MergedGroup[]; fileItems: MenuEntry[] } {\n const afterApp: MergedGroup[] = [];\n const afterView: MergedGroup[] = [];\n let fileItems: MenuEntry[] = [];\n for (const group of app) {\n const items = tidy(group.items, moved);\n const standard = merged.find((one) => group.menuRole && one.menuRole === group.menuRole);\n if (standard && standard === defaultFile) fileItems = joined(fileItems, items);\n else if (standard) standard.items = joined(standard.items, items);\n // A group whose items all replaced defaults: an empty menu is not worth a place in the bar.\n else if (items.length)\n (group.menuRole === 'file' ? afterApp : afterView).push({ ...group, items });\n }\n return { afterApp, afterView, fileItems };\n}\n\n/** `items` after `entries`, with a separator between when both have any. */\nfunction joined(entries: readonly MenuEntry[], items: readonly MenuEntry[]): MenuEntry[] {\n return entries.length && items.length\n ? [...entries, SEPARATOR, ...items]\n : [...entries, ...items];\n}\n\n/**\n * The File menu: the app's items, then Close Window when it moved there, then the defaults\n * (Print...), each part apart.\n */\nfunction fileMenu(\n own: readonly MenuEntry[],\n close: MenuItemModel | undefined,\n defaults: readonly MenuEntry[],\n): MenuEntry[] {\n return tidy([...own, SEPARATOR, ...(close ? [close, SEPARATOR] : []), ...defaults], () => false);\n}\n\n/** The Window menu's Close Window (or the app's `close` item), taken out of it. */\nfunction takeClose(\n groups: { menuRole?: MenuGroupRole; items: MenuEntry[] }[],\n): MenuItemModel | undefined {\n const window = groups.find((group) => group.menuRole === 'window');\n const close = window?.items.find((entry) => !isSeparator(entry) && entry.menuRole === 'close');\n if (!window || !close || isSeparator(close)) return undefined;\n window.items = tidy(window.items, (item) => item === close);\n return close;\n}\n\n/**\n * The menu bar an app ends up with, from the defaults and its `<menu-bar>`:\n *\n * - An app item with a `menuRole` replaces the default item with that role, where the default is,\n * and leaves the group it was written in.\n * - `Settings...` shows only when the app gives a `settings` item a handler.\n * - A group whose `menuRole` names a default menu adds its items to the end of that menu; a `file`\n * group's go before Print..., which stays last, as on a Mac.\n * - A `file` group with no default File menu goes after the App menu, and any other group after\n * View, in the order the app wrote them. A group left with no items is left out.\n * - With a `file` group, the Window menu's Close Window (or the app's own `close` item) moves to\n * the File menu, after the app's items and before the defaults.\n */\nexport function mergeMenuBar(\n defaults: readonly MenuGroupModel[],\n app: readonly MenuGroupModel[],\n): MenuGroupModel[] {\n const replacing = byRole(app);\n const defaultRoles = byRole(defaults);\n const settings = replacing.get('settings');\n const replace = (entries: readonly MenuEntry[]): MenuEntry[] =>\n entries.map((entry) => {\n if (isSeparator(entry)) return entry;\n const own = entry.menuRole && replacing.get(entry.menuRole);\n if (own) return own;\n return entry.items ? { ...entry, items: replace(entry.items) } : entry;\n });\n const merged: MergedGroup[] = defaults.map((group) => ({\n ...group,\n items: tidy(replace(group.items), (item) => item.menuRole === 'settings' && !settings?.select),\n }));\n const moved = (item: MenuItemModel) => Boolean(item.menuRole && defaultRoles.has(item.menuRole));\n const defaultFile = merged.find((group) => group.menuRole === 'file');\n const { afterApp, afterView, fileItems } = placeAppGroups(merged, app, defaultFile, moved);\n const file = defaultFile ?? afterApp[0];\n if (file) {\n const close = app.some((group) => group.menuRole === 'file') ? takeClose(merged) : undefined;\n file.items = fileMenu(defaultFile ? fileItems : file.items, close, defaultFile?.items ?? []);\n }\n const at = (role: MenuGroupRole) => merged.findIndex((group) => group.menuRole === role) + 1;\n merged.splice(at('view'), 0, ...afterView);\n merged.splice(at('app'), 0, ...afterApp);\n return merged;\n}\n\n/**\n * The entries a menu's `<menu-item>`s registered, in the order they registered. Each item\n * registers a signal of itself, so a changed label or a toggled check reaches the menu, and the\n * function `register` answers takes it out again as the item goes.\n */\nexport interface MenuModel {\n readonly entries: Signal<readonly MenuEntry[]>;\n /**\n * Add `entry`, at `place` where the container can order places: an item an `@if` shows later\n * takes its place in the template, not the end.\n */\n register(entry: Signal<MenuEntry>, place?: unknown): () => void;\n}\n\n/**\n * A menu model for a container to provide as `MENU_MODEL`. `order` compares two places, negative\n * for the first one earlier; places it cannot compare keep the order they registered in.\n */\nexport function createMenuModel(order?: (a: unknown, b: unknown) => number): MenuModel {\n type Registered = { entry: Signal<MenuEntry>; place: unknown };\n const registered = signal<readonly Registered[]>([]);\n return {\n entries: computed(() => {\n const all = registered();\n const sorted = order ? [...all].sort((a, b) => order(a.place, b.place)) : all;\n return sorted.map((one) => one.entry());\n }),\n register(entry, place) {\n const one: Registered = { entry, place };\n registered.update((all) => [...all, one]);\n return () => registered.update((all) => all.filter((each) => each !== one));\n },\n };\n}\n\n/** Just enough of a node to find its place: its parent, and the parent's children in order. */\ninterface TreeNode {\n readonly parent: TreeNode | null;\n readonly childList: readonly TreeNode[];\n}\n\n/** Where a node is in its tree: each ancestor's index in its parent, from the root down. */\nfunction placeOf(node: TreeNode): { root: TreeNode; path: number[] } {\n const path: number[] = [];\n let at = node;\n while (at.parent) {\n path.unshift(at.parent.childList.indexOf(at));\n at = at.parent;\n }\n return { root: at, path };\n}\n\n/**\n * Which of two elements comes first in the tree: negative for `a`. Elements in different trees, or\n * not in one yet, compare equal, and keep the order they registered in.\n */\nexport function treeOrder(a: unknown, b: unknown): number {\n if (!a || !b) return 0;\n const first = placeOf(a as TreeNode);\n const second = placeOf(b as TreeNode);\n if (first.root !== second.root) return 0;\n for (let i = 0; i < Math.min(first.path.length, second.path.length); i++) {\n const step = first.path[i]! - second.path[i]!;\n if (step) return step;\n }\n return first.path.length - second.path.length;\n}\n\n/** A menu model whose entries keep their places in the template. */\nexport const menuModelInTreeOrder = (): MenuModel => createMenuModel(treeOrder);\n\n/**\n * Where a `<menu-item>` registers itself: the menu it is written in, which a `<menu-group>`, a\n * submenu or a `<native-header-item [menu]>` template provides. There is none at the root, so an\n * item outside a menu is told so by its own injection.\n */\nexport const MENU_MODEL = new InjectionToken<MenuModel>('angular-native.menuModel');\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A menu written as a template of `<menu-item>`s, as `[contextMenu]` and
|
|
3
|
+
* `<native-header-item [menu]>` take one: the items are made outside the app's tree, where they
|
|
4
|
+
* draw nothing and only register with the menu model given to them.
|
|
5
|
+
*/
|
|
6
|
+
import { Injector, type TemplateRef } from '@angular/core';
|
|
7
|
+
import { type MenuModel } from './menu-model.ts';
|
|
8
|
+
export interface MenuTemplate {
|
|
9
|
+
/** What the template's items registered, in the order they are written. */
|
|
10
|
+
readonly model: MenuModel;
|
|
11
|
+
/** Destroy the items, which takes them out of the model. */
|
|
12
|
+
destroy(): void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Make `template`'s items under `injector`, attached to the app so their bindings stay live. They
|
|
16
|
+
* sit in an element of their own that is never committed, so an item an `@if` shows later has a
|
|
17
|
+
* place among the others to take, rather than going to the end.
|
|
18
|
+
*/
|
|
19
|
+
export declare function buildMenuTemplate(template: TemplateRef<unknown>, injector: Injector): MenuTemplate;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A menu written as a template of `<menu-item>`s, as `[contextMenu]` and
|
|
3
|
+
* `<native-header-item [menu]>` take one: the items are made outside the app's tree, where they
|
|
4
|
+
* draw nothing and only register with the menu model given to them.
|
|
5
|
+
*/
|
|
6
|
+
import { ApplicationRef, Injector, RendererFactory2, } from '@angular/core';
|
|
7
|
+
import { MENU_MODEL, menuModelInTreeOrder } from "./menu-model.js";
|
|
8
|
+
/**
|
|
9
|
+
* Make `template`'s items under `injector`, attached to the app so their bindings stay live. They
|
|
10
|
+
* sit in an element of their own that is never committed, so an item an `@if` shows later has a
|
|
11
|
+
* place among the others to take, rather than going to the end.
|
|
12
|
+
*/
|
|
13
|
+
export function buildMenuTemplate(template, injector) {
|
|
14
|
+
const app = injector.get(ApplicationRef);
|
|
15
|
+
const model = menuModelInTreeOrder();
|
|
16
|
+
const view = template.createEmbeddedView({}, Injector.create({ providers: [{ provide: MENU_MODEL, useValue: model }], parent: injector }));
|
|
17
|
+
const renderer = injector.get(RendererFactory2).createRenderer(null, null);
|
|
18
|
+
const holder = renderer.createElement('view');
|
|
19
|
+
for (const node of view.rootNodes)
|
|
20
|
+
renderer.appendChild(holder, node);
|
|
21
|
+
app.attachView(view);
|
|
22
|
+
view.detectChanges();
|
|
23
|
+
return {
|
|
24
|
+
model,
|
|
25
|
+
destroy: () => {
|
|
26
|
+
app.detachView(view);
|
|
27
|
+
view.destroy();
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=menu-template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"menu-template.js","sourceRoot":"","sources":["../src/menu-template.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,cAAc,EACd,QAAQ,EACR,gBAAgB,GAGjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAkB,MAAM,iBAAiB,CAAC;AASnF;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAC/B,QAA8B,EAC9B,QAAkB;IAElB,MAAM,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IACzC,MAAM,KAAK,GAAG,oBAAoB,EAAE,CAAC;IACrC,MAAM,IAAI,GAA6B,QAAQ,CAAC,kBAAkB,CAChE,EAAE,EACF,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAC7F,CAAC;IACF,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC3E,MAAM,MAAM,GAAY,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IACvD,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,SAAS;QAAE,QAAQ,CAAC,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACtE,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IACrB,IAAI,CAAC,aAAa,EAAE,CAAC;IACrB,OAAO;QACL,KAAK;QACL,OAAO,EAAE,GAAG,EAAE;YACZ,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;YACrB,IAAI,CAAC,OAAO,EAAE,CAAC;QACjB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/**\n * A menu written as a template of `<menu-item>`s, as `[contextMenu]` and\n * `<native-header-item [menu]>` take one: the items are made outside the app's tree, where they\n * draw nothing and only register with the menu model given to them.\n */\nimport {\n ApplicationRef,\n Injector,\n RendererFactory2,\n type EmbeddedViewRef,\n type TemplateRef,\n} from '@angular/core';\nimport { MENU_MODEL, menuModelInTreeOrder, type MenuModel } from './menu-model.ts';\n\nexport interface MenuTemplate {\n /** What the template's items registered, in the order they are written. */\n readonly model: MenuModel;\n /** Destroy the items, which takes them out of the model. */\n destroy(): void;\n}\n\n/**\n * Make `template`'s items under `injector`, attached to the app so their bindings stay live. They\n * sit in an element of their own that is never committed, so an item an `@if` shows later has a\n * place among the others to take, rather than going to the end.\n */\nexport function buildMenuTemplate(\n template: TemplateRef<unknown>,\n injector: Injector,\n): MenuTemplate {\n const app = injector.get(ApplicationRef);\n const model = menuModelInTreeOrder();\n const view: EmbeddedViewRef<unknown> = template.createEmbeddedView(\n {},\n Injector.create({ providers: [{ provide: MENU_MODEL, useValue: model }], parent: injector }),\n );\n const renderer = injector.get(RendererFactory2).createRenderer(null, null);\n const holder: unknown = renderer.createElement('view');\n for (const node of view.rootNodes) renderer.appendChild(holder, node);\n app.attachView(view);\n view.detectChanges();\n return {\n model,\n destroy: () => {\n app.detachView(view);\n view.destroy();\n },\n };\n}\n"]}
|
package/dist/menus.d.ts
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Menus and keyboard shortcuts as the host receives them: the menu bar, the shortcuts that are in
|
|
3
|
+
* no menu, and the form a menu takes on its way to native, which a context menu shares.
|
|
4
|
+
*
|
|
5
|
+
* The host contract, on the `NgNativeMenus` module:
|
|
6
|
+
* - `setMenuBar(groups)`: the whole merged menu bar, each time it changes. The desktop host draws
|
|
7
|
+
* it as the main menu, iPadOS through UIMenuBuilder. Each item has an `id`; an item with a
|
|
8
|
+
* `menuRole` and no `id`'s action is the OS's own (Copy, Quit).
|
|
9
|
+
* - `setShortcuts(shortcuts)`: every shortcut the app listens for outside the menu bar, each with
|
|
10
|
+
* its `id`, its chord read for the OS, and a `label` and `group` for Android's Keyboard Shortcuts
|
|
11
|
+
* helper. On iPhone and Android the menu bar's own shortcuts are in it too, since no bar is drawn.
|
|
12
|
+
* - It sends `ngNativeMenus` events on `DeviceEventEmitter`: `{ type: 'menuSelect', id }` for a menu
|
|
13
|
+
* bar item, and `{ type: 'shortcut', id, textInputFocused }` for a chord pressed.
|
|
14
|
+
* - Its constants say whether it draws a menu bar (`menuBar`) and the app's name (`appName`).
|
|
15
|
+
* - On Android it is an Expo module: the constants are properties, it sends the same events through
|
|
16
|
+
* its own `addListener('ngNativeMenus', ...)`, and it has `setContextMenu(nativeID, entries)`,
|
|
17
|
+
* since React Native's Android view drops a `contextMenu` prop it does not know.
|
|
18
|
+
* - On iOS it is a TurboModule with `setContextMenu(nativeID, entries)` too, for the same reason.
|
|
19
|
+
* React Native's iOS view sends no event it does not know either, so the module sends the item
|
|
20
|
+
* chosen as `{ type: 'contextMenuSelect', nativeID, id }`.
|
|
21
|
+
* - Where it draws context menus, `setTakesLongPress(nativeID, takes)` names a view inside one
|
|
22
|
+
* whose own `(longPress)` takes a long press first: a long press there opens no menu around it,
|
|
23
|
+
* as the innermost handler wins in a native app. A right-click still opens the menu on Android.
|
|
24
|
+
* iOS tells a long press from a secondary click only by the gesture, so an iPad pointer's
|
|
25
|
+
* secondary click there opens none either.
|
|
26
|
+
*/
|
|
27
|
+
import { InjectionToken, type Signal } from '@angular/core';
|
|
28
|
+
import { type MenuEntry, type MenuGroupModel } from './menu-model.ts';
|
|
29
|
+
import { type ParsedShortcut, type ShortcutOs } from './shortcut.ts';
|
|
30
|
+
import * as i0 from "@angular/core";
|
|
31
|
+
/** A menu entry as the host receives it. */
|
|
32
|
+
export type NativeMenuEntry = {
|
|
33
|
+
readonly separator: true;
|
|
34
|
+
} | {
|
|
35
|
+
readonly id: string;
|
|
36
|
+
readonly label: string;
|
|
37
|
+
readonly menuRole?: string;
|
|
38
|
+
/** On an item with a `menuRole`: the app handles it, and the OS does not. */
|
|
39
|
+
readonly handled?: true;
|
|
40
|
+
readonly shortcut?: ParsedShortcut;
|
|
41
|
+
readonly disabled?: boolean;
|
|
42
|
+
readonly checked?: boolean;
|
|
43
|
+
readonly destructive?: boolean;
|
|
44
|
+
readonly subtitle?: string;
|
|
45
|
+
readonly sfSymbol?: string;
|
|
46
|
+
readonly icon?: string;
|
|
47
|
+
readonly inline?: boolean;
|
|
48
|
+
readonly items?: readonly NativeMenuEntry[];
|
|
49
|
+
};
|
|
50
|
+
/** A menu ready for the host, and what each id it was given does. */
|
|
51
|
+
export interface SerializedMenu {
|
|
52
|
+
readonly entries: NativeMenuEntry[];
|
|
53
|
+
readonly actions: ReadonlyMap<string, () => void>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The id a menu item with `select` is sent under: the same for as long as the handler is, and no
|
|
57
|
+
* other handler's. `<menu-item>` keeps one handler for its life, so a host that reports a choice
|
|
58
|
+
* from a menu it drew before the items changed still runs that item, or nothing once it has gone,
|
|
59
|
+
* never the item that has taken its place.
|
|
60
|
+
*/
|
|
61
|
+
export declare function menuActionId(select: () => void): string;
|
|
62
|
+
/**
|
|
63
|
+
* `entries` as the host takes them: an id for each item, its shortcut read for `os`, and the
|
|
64
|
+
* handlers by id. An item with a handler is named by it (`menuActionId`); one without, which the
|
|
65
|
+
* app never runs, by its place (`2.0.1`).
|
|
66
|
+
*/
|
|
67
|
+
export declare function serializeMenu(entries: readonly MenuEntry[], os: ShortcutOs, prefix?: string): SerializedMenu;
|
|
68
|
+
/** A shortcut as the host receives it. */
|
|
69
|
+
export interface NativeShortcut {
|
|
70
|
+
readonly id: string;
|
|
71
|
+
readonly chord: ParsedShortcut;
|
|
72
|
+
/** What Android's Keyboard Shortcuts helper lists it as. */
|
|
73
|
+
readonly label: string;
|
|
74
|
+
/** The heading it is listed under there: its menu's label, or the app's name. */
|
|
75
|
+
readonly group: string;
|
|
76
|
+
}
|
|
77
|
+
export type NativeMenuEvent = {
|
|
78
|
+
readonly type: 'menuSelect';
|
|
79
|
+
readonly id: string;
|
|
80
|
+
} | {
|
|
81
|
+
readonly type: 'shortcut';
|
|
82
|
+
readonly id: string;
|
|
83
|
+
readonly textInputFocused?: boolean;
|
|
84
|
+
}
|
|
85
|
+
/** An item chosen in the context menu of the view with `nativeID` (iOS). */
|
|
86
|
+
| {
|
|
87
|
+
readonly type: 'contextMenuSelect';
|
|
88
|
+
readonly nativeID: string;
|
|
89
|
+
readonly id: string;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Back or forward, from whichever input the OS has for it: View > Back and Forward and their
|
|
93
|
+
* keys, a two-finger swipe, mouse buttons 4 and 5, the toolbar's chevrons and their history
|
|
94
|
+
* menus. `surface` is the window it was in, and `steps` how many entries (one where absent).
|
|
95
|
+
*/
|
|
96
|
+
| {
|
|
97
|
+
readonly type: 'navigate';
|
|
98
|
+
readonly direction: 'back' | 'forward';
|
|
99
|
+
readonly surface?: number;
|
|
100
|
+
readonly steps?: number;
|
|
101
|
+
};
|
|
102
|
+
/** A window's history as the host draws it: the titles behind and ahead, nearest first. */
|
|
103
|
+
export interface NativeWindowHistory {
|
|
104
|
+
readonly back: readonly string[];
|
|
105
|
+
readonly forward: readonly string[];
|
|
106
|
+
}
|
|
107
|
+
/** The host's menu module. */
|
|
108
|
+
export interface NativeMenus {
|
|
109
|
+
/** Whether the host draws a menu bar: macOS, and iPadOS. */
|
|
110
|
+
readonly menuBar: boolean;
|
|
111
|
+
readonly appName: string;
|
|
112
|
+
setMenuBar(groups: readonly {
|
|
113
|
+
label: string;
|
|
114
|
+
menuRole?: string;
|
|
115
|
+
items: NativeMenuEntry[];
|
|
116
|
+
}[]): void;
|
|
117
|
+
setShortcuts(shortcuts: readonly NativeShortcut[]): void;
|
|
118
|
+
/** The history of the window on `surface`, for its back and forward chevrons. Desktop only. */
|
|
119
|
+
setHistory?(surface: number, history: NativeWindowHistory): void;
|
|
120
|
+
/**
|
|
121
|
+
* The context menu of the view with `nativeID`, or null to take it away. Android and iOS, whose
|
|
122
|
+
* views read no `contextMenu` prop: the host finds the view by its `nativeID`.
|
|
123
|
+
*/
|
|
124
|
+
setContextMenu?(nativeID: string, entries: readonly NativeMenuEntry[] | null): void;
|
|
125
|
+
/**
|
|
126
|
+
* Whether the view with `nativeID` takes a long press itself, so a context menu around it does
|
|
127
|
+
* not open on one there. Android and iOS, beside `setContextMenu`.
|
|
128
|
+
*/
|
|
129
|
+
setTakesLongPress?(nativeID: string, takes: boolean): void;
|
|
130
|
+
subscribe(listener: (event: NativeMenuEvent) => void): () => void;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* The host's menu module: a TurboModule (the desktop host, iOS), or else Android's Expo module.
|
|
134
|
+
* Null where there is neither, as in Expo Go.
|
|
135
|
+
*/
|
|
136
|
+
export declare function menusSource(): NativeMenus | null;
|
|
137
|
+
/**
|
|
138
|
+
* The menus and shortcuts an app has, sent to the host as they change. `<menu-bar>` and
|
|
139
|
+
* `[shortcut]` in `@ng-native/components` register here; an app rarely injects it.
|
|
140
|
+
*/
|
|
141
|
+
export declare class Menus {
|
|
142
|
+
/** Overridden in a test with a fake host. */
|
|
143
|
+
static readonly SOURCE: InjectionToken<NativeMenus | null>;
|
|
144
|
+
private readonly native;
|
|
145
|
+
private readonly os;
|
|
146
|
+
/** Whether the host has the module: shortcuts from a hardware keyboard, and menus. */
|
|
147
|
+
readonly available: Signal<boolean>;
|
|
148
|
+
/** Whether the menu bar is drawn: macOS and iPadOS. Elsewhere its shortcuts still work. */
|
|
149
|
+
readonly menuBarShown: Signal<boolean>;
|
|
150
|
+
/**
|
|
151
|
+
* Whether the host takes a `[contextMenu]` by the view's `nativeID` through `setContextMenu`
|
|
152
|
+
* (Android and iOS) rather than as the view's `contextMenu` prop. Where it does, it draws the
|
|
153
|
+
* menu on a long press.
|
|
154
|
+
*/
|
|
155
|
+
readonly contextMenuByNativeId: boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Whether the host, which draws context menus on a long press, can be told which views inside
|
|
158
|
+
* one take a long press themselves (`setTakesLongPress`).
|
|
159
|
+
*/
|
|
160
|
+
readonly longPressByNativeId: boolean;
|
|
161
|
+
/**
|
|
162
|
+
* Say whether the view with `nativeID` takes a long press itself: one there then opens no
|
|
163
|
+
* context menu around it.
|
|
164
|
+
*/
|
|
165
|
+
setTakesLongPress(nativeID: string, takes: boolean): void;
|
|
166
|
+
/** The `nativeID`s sent with a context menu, and with a long press of their own. */
|
|
167
|
+
private readonly withContextMenu;
|
|
168
|
+
private readonly longPressTakers;
|
|
169
|
+
/**
|
|
170
|
+
* Whether the host opens a context menu on a long press of the view whose `nativeID`s, from it
|
|
171
|
+
* outwards, are `chain`: as it decides, the nearest view with a menu, unless one on the way takes
|
|
172
|
+
* the long press itself. A `(longPress)` around that view leaves the hold to the menu, which the
|
|
173
|
+
* host opens after its own long-press timeout.
|
|
174
|
+
*/
|
|
175
|
+
opensContextMenu(chain: Iterable<string | null>): boolean;
|
|
176
|
+
/** What choosing an item does, by the `nativeID` of the view whose menu it is in. */
|
|
177
|
+
private readonly contextMenuChoices;
|
|
178
|
+
/**
|
|
179
|
+
* Send the context menu of the view with `nativeID`, or null to take it away. `choose` runs with
|
|
180
|
+
* the item's `id` where the host sends the choice itself (iOS) rather than through the view.
|
|
181
|
+
*/
|
|
182
|
+
setContextMenu(nativeID: string, entries: readonly NativeMenuEntry[] | null, choose?: (id: string) => void): void;
|
|
183
|
+
private readonly bars;
|
|
184
|
+
private readonly shortcuts;
|
|
185
|
+
/** The app's groups, from every `<menu-bar>`, in the order they registered. */
|
|
186
|
+
private readonly appGroups;
|
|
187
|
+
/** The menu bar as it is drawn: the OS's defaults with the app's merged in. */
|
|
188
|
+
readonly menuBar: Signal<MenuGroupModel[]>;
|
|
189
|
+
private readonly sentBar;
|
|
190
|
+
/**
|
|
191
|
+
* The shortcuts sent to the host: every `[shortcut]`, and where no menu bar is drawn, every
|
|
192
|
+
* menu bar item the app gave a shortcut and a handler, so a hardware keyboard still has them.
|
|
193
|
+
*/
|
|
194
|
+
private readonly sentShortcuts;
|
|
195
|
+
private readonly unsubscribe;
|
|
196
|
+
constructor();
|
|
197
|
+
/**
|
|
198
|
+
* Add a `<menu-bar>`'s groups, each a `MenuItemModel` with `items` and its `group` role. Answers
|
|
199
|
+
* the function that takes them out again, as the `<menu-bar>` goes.
|
|
200
|
+
*/
|
|
201
|
+
addMenuBar(groups: Signal<readonly MenuEntry[]>): () => void;
|
|
202
|
+
/**
|
|
203
|
+
* Listen for `shortcut`, pressed anywhere in the app: `mod+k`, as `parseShortcut` reads it.
|
|
204
|
+
* `label` is what Android's Keyboard Shortcuts helper lists it as. Answers the function that
|
|
205
|
+
* stops listening.
|
|
206
|
+
*/
|
|
207
|
+
addShortcut(shortcut: Signal<string>, label: Signal<string>, press: () => void): () => void;
|
|
208
|
+
private readonly navigators;
|
|
209
|
+
/**
|
|
210
|
+
* Hear the OS's back and forward commands. `@ng-native/router` listens, and moves through the
|
|
211
|
+
* history of the window each was in, `steps` entries (one, but for a pick from a chevron's
|
|
212
|
+
* history menu). Answers the function that stops listening.
|
|
213
|
+
*/
|
|
214
|
+
onNavigate(listener: (direction: 'back' | 'forward', surface?: number, steps?: number) => void): () => void;
|
|
215
|
+
/**
|
|
216
|
+
* Tell the host the history of the window on `surface`, which its toolbar's back and forward
|
|
217
|
+
* chevrons and their menus show. `@ng-native/router` calls it. Does nothing where the host has
|
|
218
|
+
* no chevrons.
|
|
219
|
+
*/
|
|
220
|
+
setHistory(surface: number, history: NativeWindowHistory): void;
|
|
221
|
+
private hostSaid;
|
|
222
|
+
ngOnDestroy(): void;
|
|
223
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<Menus, never>;
|
|
224
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
225
|
+
}
|