@ng-native/device 0.22.2 → 0.24.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 +5 -0
- package/dist/color-scheme.js +16 -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,108 @@
|
|
|
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, type Signal } from '@angular/core';
|
|
12
|
+
/** A standard menu a `<menu-group menuRole>` adds its items to. */
|
|
13
|
+
export type MenuGroupRole = 'app' | 'file' | 'edit' | 'view' | 'window' | 'help';
|
|
14
|
+
/**
|
|
15
|
+
* What an item is for, where the OS has a standard one: an item with a `menuRole` replaces that
|
|
16
|
+
* role's default item, and without a handler does what the OS does for it.
|
|
17
|
+
*/
|
|
18
|
+
export type MenuRole = 'about' | 'settings' | 'services' | 'hide' | 'hideOthers' | 'showAll' | 'quit' | 'undo' | 'redo' | 'cut' | 'copy' | 'paste' | 'selectAll' | 'find' | 'toggleSidebar' | 'toggleFullScreen' | 'back' | 'forward' | 'minimize' | 'zoom' | 'bringAllToFront' | 'close' | 'print';
|
|
19
|
+
/** One item in a menu. */
|
|
20
|
+
export interface MenuItemModel {
|
|
21
|
+
readonly label: string;
|
|
22
|
+
readonly menuRole?: MenuRole;
|
|
23
|
+
/** `mod+s`, as `parseShortcut` reads it. */
|
|
24
|
+
readonly shortcut?: string;
|
|
25
|
+
readonly disabled?: boolean;
|
|
26
|
+
/** A check mark, where the item is a toggle. */
|
|
27
|
+
readonly checked?: boolean;
|
|
28
|
+
readonly destructive?: boolean;
|
|
29
|
+
readonly subtitle?: string;
|
|
30
|
+
/** An SF Symbol, shown on Apple's OSes. */
|
|
31
|
+
readonly sfSymbol?: string;
|
|
32
|
+
/** A drawable resource's name, shown on Android. */
|
|
33
|
+
readonly icon?: string;
|
|
34
|
+
/**
|
|
35
|
+
* The standard menu a top-level `<menu-group menuRole>` adds its items to, for a group written
|
|
36
|
+
* in a `<menu-bar>`: what becomes `MenuGroupModel.menuRole`.
|
|
37
|
+
*/
|
|
38
|
+
readonly group?: MenuGroupRole;
|
|
39
|
+
/** A submenu, or with `inline` a section of the menu the item is in. */
|
|
40
|
+
readonly items?: readonly MenuEntry[];
|
|
41
|
+
readonly inline?: boolean;
|
|
42
|
+
/** What choosing it does. Left out on an item with a `menuRole`, the OS does it. */
|
|
43
|
+
readonly select?: () => void;
|
|
44
|
+
}
|
|
45
|
+
/** A line between items. */
|
|
46
|
+
export interface MenuSeparator {
|
|
47
|
+
readonly separator: true;
|
|
48
|
+
}
|
|
49
|
+
export type MenuEntry = MenuItemModel | MenuSeparator;
|
|
50
|
+
/** One menu in the menu bar. */
|
|
51
|
+
export interface MenuGroupModel {
|
|
52
|
+
readonly label: string;
|
|
53
|
+
readonly menuRole?: MenuGroupRole;
|
|
54
|
+
readonly items: readonly MenuEntry[];
|
|
55
|
+
}
|
|
56
|
+
export declare const isSeparator: (entry: MenuEntry) => entry is MenuSeparator;
|
|
57
|
+
/**
|
|
58
|
+
* The menu bar every desktop app gets: App, File, Edit, View, Window and Help, each item with its
|
|
59
|
+
* role and standard shortcut. `Settings...` is in it until the merge, which keeps it only when the
|
|
60
|
+
* app gives it a handler. File holds Print... (`mod+p`), which prints the key window unless the app
|
|
61
|
+
* gives a `print` item a handler.
|
|
62
|
+
*/
|
|
63
|
+
export declare function defaultMenuBar(appName: string): MenuGroupModel[];
|
|
64
|
+
/**
|
|
65
|
+
* The menu bar an app ends up with, from the defaults and its `<menu-bar>`:
|
|
66
|
+
*
|
|
67
|
+
* - An app item with a `menuRole` replaces the default item with that role, where the default is,
|
|
68
|
+
* and leaves the group it was written in.
|
|
69
|
+
* - `Settings...` shows only when the app gives a `settings` item a handler.
|
|
70
|
+
* - A group whose `menuRole` names a default menu adds its items to the end of that menu; a `file`
|
|
71
|
+
* group's go before Print..., which stays last, as on a Mac.
|
|
72
|
+
* - A `file` group with no default File menu goes after the App menu, and any other group after
|
|
73
|
+
* View, in the order the app wrote them. A group left with no items is left out.
|
|
74
|
+
* - With a `file` group, the Window menu's Close Window (or the app's own `close` item) moves to
|
|
75
|
+
* the File menu, after the app's items and before the defaults.
|
|
76
|
+
*/
|
|
77
|
+
export declare function mergeMenuBar(defaults: readonly MenuGroupModel[], app: readonly MenuGroupModel[]): MenuGroupModel[];
|
|
78
|
+
/**
|
|
79
|
+
* The entries a menu's `<menu-item>`s registered, in the order they registered. Each item
|
|
80
|
+
* registers a signal of itself, so a changed label or a toggled check reaches the menu, and the
|
|
81
|
+
* function `register` answers takes it out again as the item goes.
|
|
82
|
+
*/
|
|
83
|
+
export interface MenuModel {
|
|
84
|
+
readonly entries: Signal<readonly MenuEntry[]>;
|
|
85
|
+
/**
|
|
86
|
+
* Add `entry`, at `place` where the container can order places: an item an `@if` shows later
|
|
87
|
+
* takes its place in the template, not the end.
|
|
88
|
+
*/
|
|
89
|
+
register(entry: Signal<MenuEntry>, place?: unknown): () => void;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* A menu model for a container to provide as `MENU_MODEL`. `order` compares two places, negative
|
|
93
|
+
* for the first one earlier; places it cannot compare keep the order they registered in.
|
|
94
|
+
*/
|
|
95
|
+
export declare function createMenuModel(order?: (a: unknown, b: unknown) => number): MenuModel;
|
|
96
|
+
/**
|
|
97
|
+
* Which of two elements comes first in the tree: negative for `a`. Elements in different trees, or
|
|
98
|
+
* not in one yet, compare equal, and keep the order they registered in.
|
|
99
|
+
*/
|
|
100
|
+
export declare function treeOrder(a: unknown, b: unknown): number;
|
|
101
|
+
/** A menu model whose entries keep their places in the template. */
|
|
102
|
+
export declare const menuModelInTreeOrder: () => MenuModel;
|
|
103
|
+
/**
|
|
104
|
+
* Where a `<menu-item>` registers itself: the menu it is written in, which a `<menu-group>`, a
|
|
105
|
+
* submenu or a `<native-header-item [menu]>` template provides. There is none at the root, so an
|
|
106
|
+
* item outside a menu is told so by its own injection.
|
|
107
|
+
*/
|
|
108
|
+
export declare const MENU_MODEL: InjectionToken<MenuModel>;
|
|
@@ -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","sourceRoot":"","sources":["../src/menu-model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAe,MAAM,eAAe,CAAC;AA2E9E,MAAM,SAAS,GAAkB,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AAErD,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAgB,EAA0B,EAAE,CAAC,WAAW,IAAI,KAAK,CAAC;AAE9F;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,OAAe;IAC5C,MAAM,IAAI,GAAG,CAAC,KAAa,EAAE,QAAkB,EAAE,QAAiB,EAAiB,EAAE,CACnF,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;IACjE,OAAO;QACL;YACE,KAAK,EAAE,OAAO;YACd,QAAQ,EAAE,KAAK;YACf,KAAK,EAAE;gBACL,IAAI,CAAC,SAAS,OAAO,EAAE,EAAE,OAAO,CAAC;gBACjC,SAAS;gBACT,IAAI,CAAC,aAAa,EAAE,UAAU,EAAE,OAAO,CAAC;gBACxC,SAAS;gBACT,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC;gBAC5B,SAAS;gBACT,IAAI,CAAC,QAAQ,OAAO,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC;gBACxC,IAAI,CAAC,aAAa,EAAE,YAAY,EAAE,WAAW,CAAC;gBAC9C,IAAI,CAAC,UAAU,EAAE,SAAS,CAAC;gBAC3B,SAAS;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AE,CAAC,MAAM,CAAC;IACjB,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;AAC5B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,CAAU,EAAE,CAAU;IAC9C,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;QAAE,OAAO,CAAC,CAAC;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"]}
|