@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
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
|
+
}
|
package/dist/menus.js
ADDED
|
@@ -0,0 +1,341 @@
|
|
|
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, Service, computed, effect, inject, signal, } from '@angular/core';
|
|
28
|
+
import { defaultMenuBar, isSeparator, mergeMenuBar, } from "./menu-model.js";
|
|
29
|
+
import { injectOs } from "./os.js";
|
|
30
|
+
import { reactNative } from "./react-native.js";
|
|
31
|
+
import { isEditingShortcut, navigationShortcut, parseShortcut, } from "./shortcut.js";
|
|
32
|
+
import * as i0 from "@angular/core";
|
|
33
|
+
const actionIds = new WeakMap();
|
|
34
|
+
let actionsNamed = 0;
|
|
35
|
+
/**
|
|
36
|
+
* The id a menu item with `select` is sent under: the same for as long as the handler is, and no
|
|
37
|
+
* other handler's. `<menu-item>` keeps one handler for its life, so a host that reports a choice
|
|
38
|
+
* from a menu it drew before the items changed still runs that item, or nothing once it has gone,
|
|
39
|
+
* never the item that has taken its place.
|
|
40
|
+
*/
|
|
41
|
+
export function menuActionId(select) {
|
|
42
|
+
let id = actionIds.get(select);
|
|
43
|
+
if (id === undefined)
|
|
44
|
+
actionIds.set(select, (id = `a${++actionsNamed}`));
|
|
45
|
+
return id;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* `entries` as the host takes them: an id for each item, its shortcut read for `os`, and the
|
|
49
|
+
* handlers by id. An item with a handler is named by it (`menuActionId`); one without, which the
|
|
50
|
+
* app never runs, by its place (`2.0.1`).
|
|
51
|
+
*/
|
|
52
|
+
export function serializeMenu(entries, os, prefix = '') {
|
|
53
|
+
const actions = new Map();
|
|
54
|
+
const walk = (list, at) => list.map((entry, index) => {
|
|
55
|
+
if (isSeparator(entry))
|
|
56
|
+
return { separator: true };
|
|
57
|
+
const place = `${at}${index}`;
|
|
58
|
+
const { select, shortcut, items, group: _group, ...rest } = entry;
|
|
59
|
+
const id = select ? menuActionId(select) : place;
|
|
60
|
+
if (select)
|
|
61
|
+
actions.set(id, select);
|
|
62
|
+
return {
|
|
63
|
+
id,
|
|
64
|
+
...rest,
|
|
65
|
+
// A role item the app handles: the host sends its select rather than doing the role.
|
|
66
|
+
...(select && entry.menuRole && { handled: true }),
|
|
67
|
+
...(shortcut
|
|
68
|
+
? { shortcut: parseShortcut(shortcut, os) }
|
|
69
|
+
: (entry.menuRole === 'back' || entry.menuRole === 'forward') && {
|
|
70
|
+
shortcut: navigationShortcut(entry.menuRole, os),
|
|
71
|
+
}),
|
|
72
|
+
...(items && { items: walk(items, `${place}.`) }),
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
return { entries: walk(entries, prefix), actions };
|
|
76
|
+
}
|
|
77
|
+
/** Android's `NgNativeMenus`, an Expo module, where React Native has no TurboModule of the name. */
|
|
78
|
+
function expoMenusModule() {
|
|
79
|
+
const modules = globalThis.expo?.modules;
|
|
80
|
+
return modules?.['NgNativeMenus'];
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The host's menu module: a TurboModule (the desktop host, iOS), or else Android's Expo module.
|
|
84
|
+
* Null where there is neither, as in Expo Go.
|
|
85
|
+
*/
|
|
86
|
+
export function menusSource() {
|
|
87
|
+
const native = reactNative();
|
|
88
|
+
const turbo = native?.TurboModuleRegistry?.get?.('NgNativeMenus');
|
|
89
|
+
const expo = turbo ? undefined : expoMenusModule();
|
|
90
|
+
const module = turbo ?? expo;
|
|
91
|
+
if (!module)
|
|
92
|
+
return null;
|
|
93
|
+
const constants = module.getConstants?.() ?? module;
|
|
94
|
+
// An Expo module sends its events itself; a TurboModule's come through DeviceEventEmitter.
|
|
95
|
+
const listen = (hear) => expo
|
|
96
|
+
? expo.addListener?.('ngNativeMenus', hear)
|
|
97
|
+
: native?.DeviceEventEmitter?.addListener('ngNativeMenus', hear);
|
|
98
|
+
return {
|
|
99
|
+
menuBar: constants.menuBar === true,
|
|
100
|
+
appName: constants.appName ?? '',
|
|
101
|
+
setMenuBar: (groups) => module.setMenuBar?.(groups),
|
|
102
|
+
setShortcuts: (shortcuts) => module.setShortcuts?.(shortcuts),
|
|
103
|
+
setHistory: (surface, history) => module.setHistory?.(surface, history),
|
|
104
|
+
...contextMenuMethods(module),
|
|
105
|
+
subscribe: (listener) => {
|
|
106
|
+
const subscription = listen((event) => listener(event));
|
|
107
|
+
return () => subscription?.remove();
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/** The context menu methods a module has, bound, and none it lacks: a host without them reads props. */
|
|
112
|
+
function contextMenuMethods(module) {
|
|
113
|
+
const setContextMenu = module.setContextMenu?.bind(module);
|
|
114
|
+
const setTakesLongPress = module.setTakesLongPress?.bind(module);
|
|
115
|
+
return {
|
|
116
|
+
...(setContextMenu && { setContextMenu }),
|
|
117
|
+
...(setTakesLongPress && { setTakesLongPress }),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/** The `ShortcutOs` an `OS` reads shortcuts as. */
|
|
121
|
+
const shortcutOs = (os) => os === 'android' || os === 'macos' || os === 'web' ? os : 'ios';
|
|
122
|
+
/**
|
|
123
|
+
* The menus and shortcuts an app has, sent to the host as they change. `<menu-bar>` and
|
|
124
|
+
* `[shortcut]` in `@ng-native/components` register here; an app rarely injects it.
|
|
125
|
+
*/
|
|
126
|
+
export class Menus {
|
|
127
|
+
/** Overridden in a test with a fake host. */
|
|
128
|
+
static SOURCE = new InjectionToken('angular-native.menusSource', {
|
|
129
|
+
factory: menusSource,
|
|
130
|
+
});
|
|
131
|
+
native = inject(Menus.SOURCE);
|
|
132
|
+
os = shortcutOs(injectOs());
|
|
133
|
+
/** Whether the host has the module: shortcuts from a hardware keyboard, and menus. */
|
|
134
|
+
available = signal(this.native !== null).asReadonly();
|
|
135
|
+
/** Whether the menu bar is drawn: macOS and iPadOS. Elsewhere its shortcuts still work. */
|
|
136
|
+
menuBarShown = signal(this.native?.menuBar === true).asReadonly();
|
|
137
|
+
/**
|
|
138
|
+
* Whether the host takes a `[contextMenu]` by the view's `nativeID` through `setContextMenu`
|
|
139
|
+
* (Android and iOS) rather than as the view's `contextMenu` prop. Where it does, it draws the
|
|
140
|
+
* menu on a long press.
|
|
141
|
+
*/
|
|
142
|
+
contextMenuByNativeId = this.native?.setContextMenu !== undefined;
|
|
143
|
+
/**
|
|
144
|
+
* Whether the host, which draws context menus on a long press, can be told which views inside
|
|
145
|
+
* one take a long press themselves (`setTakesLongPress`).
|
|
146
|
+
*/
|
|
147
|
+
longPressByNativeId = this.contextMenuByNativeId && this.native?.setTakesLongPress !== undefined;
|
|
148
|
+
/**
|
|
149
|
+
* Say whether the view with `nativeID` takes a long press itself: one there then opens no
|
|
150
|
+
* context menu around it.
|
|
151
|
+
*/
|
|
152
|
+
setTakesLongPress(nativeID, takes) {
|
|
153
|
+
if (takes)
|
|
154
|
+
this.longPressTakers.add(nativeID);
|
|
155
|
+
else
|
|
156
|
+
this.longPressTakers.delete(nativeID);
|
|
157
|
+
this.native?.setTakesLongPress?.(nativeID, takes);
|
|
158
|
+
}
|
|
159
|
+
/** The `nativeID`s sent with a context menu, and with a long press of their own. */
|
|
160
|
+
withContextMenu = new Set();
|
|
161
|
+
longPressTakers = new Set();
|
|
162
|
+
/**
|
|
163
|
+
* Whether the host opens a context menu on a long press of the view whose `nativeID`s, from it
|
|
164
|
+
* outwards, are `chain`: as it decides, the nearest view with a menu, unless one on the way takes
|
|
165
|
+
* the long press itself. A `(longPress)` around that view leaves the hold to the menu, which the
|
|
166
|
+
* host opens after its own long-press timeout.
|
|
167
|
+
*/
|
|
168
|
+
opensContextMenu(chain) {
|
|
169
|
+
for (const nativeID of chain) {
|
|
170
|
+
if (nativeID === null)
|
|
171
|
+
continue;
|
|
172
|
+
if (this.withContextMenu.has(nativeID))
|
|
173
|
+
return true;
|
|
174
|
+
if (this.longPressTakers.has(nativeID))
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
/** What choosing an item does, by the `nativeID` of the view whose menu it is in. */
|
|
180
|
+
contextMenuChoices = new Map();
|
|
181
|
+
/**
|
|
182
|
+
* Send the context menu of the view with `nativeID`, or null to take it away. `choose` runs with
|
|
183
|
+
* the item's `id` where the host sends the choice itself (iOS) rather than through the view.
|
|
184
|
+
*/
|
|
185
|
+
setContextMenu(nativeID, entries, choose) {
|
|
186
|
+
if (entries && choose)
|
|
187
|
+
this.contextMenuChoices.set(nativeID, choose);
|
|
188
|
+
else
|
|
189
|
+
this.contextMenuChoices.delete(nativeID);
|
|
190
|
+
if (entries?.length)
|
|
191
|
+
this.withContextMenu.add(nativeID);
|
|
192
|
+
else
|
|
193
|
+
this.withContextMenu.delete(nativeID);
|
|
194
|
+
this.native?.setContextMenu?.(nativeID, entries);
|
|
195
|
+
}
|
|
196
|
+
bars = signal([], /* @ts-ignore */
|
|
197
|
+
...(ngDevMode ? [{ debugName: "bars" }] : /* istanbul ignore next */ []));
|
|
198
|
+
shortcuts = signal([], /* @ts-ignore */
|
|
199
|
+
...(ngDevMode ? [{ debugName: "shortcuts" }] : /* istanbul ignore next */ []));
|
|
200
|
+
/** The app's groups, from every `<menu-bar>`, in the order they registered. */
|
|
201
|
+
appGroups = computed(() => this.bars()
|
|
202
|
+
.flatMap((bar) => bar())
|
|
203
|
+
.flatMap((entry) => isSeparator(entry)
|
|
204
|
+
? []
|
|
205
|
+
: [
|
|
206
|
+
{
|
|
207
|
+
label: entry.label,
|
|
208
|
+
...(entry.group && { menuRole: entry.group }),
|
|
209
|
+
items: entry.items ?? [],
|
|
210
|
+
},
|
|
211
|
+
]), /* @ts-ignore */
|
|
212
|
+
...(ngDevMode ? [{ debugName: "appGroups" }] : /* istanbul ignore next */ []));
|
|
213
|
+
/** The menu bar as it is drawn: the OS's defaults with the app's merged in. */
|
|
214
|
+
menuBar = computed(() => mergeMenuBar(defaultMenuBar(this.native?.appName || 'App'), this.appGroups()), /* @ts-ignore */
|
|
215
|
+
...(ngDevMode ? [{ debugName: "menuBar" }] : /* istanbul ignore next */ []));
|
|
216
|
+
sentBar = computed(() => {
|
|
217
|
+
const groups = this.menuBar();
|
|
218
|
+
const actions = new Map();
|
|
219
|
+
const sent = groups.map((group, index) => {
|
|
220
|
+
const menu = serializeMenu(group.items, this.os, `${index}.`);
|
|
221
|
+
menu.actions.forEach((action, id) => actions.set(id, action));
|
|
222
|
+
return {
|
|
223
|
+
label: group.label,
|
|
224
|
+
...(group.menuRole && { menuRole: group.menuRole }),
|
|
225
|
+
items: menu.entries,
|
|
226
|
+
};
|
|
227
|
+
});
|
|
228
|
+
return { sent, actions };
|
|
229
|
+
}, /* @ts-ignore */
|
|
230
|
+
...(ngDevMode ? [{ debugName: "sentBar" }] : /* istanbul ignore next */ []));
|
|
231
|
+
/**
|
|
232
|
+
* The shortcuts sent to the host: every `[shortcut]`, and where no menu bar is drawn, every
|
|
233
|
+
* menu bar item the app gave a shortcut and a handler, so a hardware keyboard still has them.
|
|
234
|
+
*/
|
|
235
|
+
sentShortcuts = computed(() => {
|
|
236
|
+
const presses = new Map();
|
|
237
|
+
const editing = new Set();
|
|
238
|
+
const sent = [];
|
|
239
|
+
const add = (id, shortcut, label, group, press) => {
|
|
240
|
+
presses.set(id, press);
|
|
241
|
+
if (isEditingShortcut(shortcut, this.os))
|
|
242
|
+
editing.add(id);
|
|
243
|
+
sent.push({ id, chord: parseShortcut(shortcut, this.os), label, group });
|
|
244
|
+
};
|
|
245
|
+
this.shortcuts().forEach((one, index) => add(`s${index}`, one.shortcut(), one.label(), this.native?.appName || 'App', one.press));
|
|
246
|
+
if (!this.menuBarShown()) {
|
|
247
|
+
const walk = (entries, group, at) => entries.forEach((entry, index) => {
|
|
248
|
+
if (isSeparator(entry))
|
|
249
|
+
return;
|
|
250
|
+
if (entry.shortcut && entry.select && !entry.disabled) {
|
|
251
|
+
add(`m${at}${index}`, entry.shortcut, entry.label, group, entry.select);
|
|
252
|
+
}
|
|
253
|
+
if (entry.items)
|
|
254
|
+
walk(entry.items, group, `${at}${index}.`);
|
|
255
|
+
});
|
|
256
|
+
this.appGroups().forEach((group, index) => walk(group.items, group.label, `${index}.`));
|
|
257
|
+
}
|
|
258
|
+
return { sent, presses, editing };
|
|
259
|
+
}, /* @ts-ignore */
|
|
260
|
+
...(ngDevMode ? [{ debugName: "sentShortcuts" }] : /* istanbul ignore next */ []));
|
|
261
|
+
unsubscribe = this.native?.subscribe((event) => this.hostSaid(event)) ?? null;
|
|
262
|
+
constructor() {
|
|
263
|
+
const native = this.native;
|
|
264
|
+
if (!native) {
|
|
265
|
+
// Read for nothing, so a shortcut the app gets wrong throws where there is no host too, and
|
|
266
|
+
// not first on a device that has one.
|
|
267
|
+
effect(() => this.sentShortcuts());
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
effect(() => {
|
|
271
|
+
if (this.menuBarShown())
|
|
272
|
+
native.setMenuBar(this.sentBar().sent);
|
|
273
|
+
});
|
|
274
|
+
effect(() => native.setShortcuts(this.sentShortcuts().sent));
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Add a `<menu-bar>`'s groups, each a `MenuItemModel` with `items` and its `group` role. Answers
|
|
278
|
+
* the function that takes them out again, as the `<menu-bar>` goes.
|
|
279
|
+
*/
|
|
280
|
+
addMenuBar(groups) {
|
|
281
|
+
this.bars.update((all) => [...all, groups]);
|
|
282
|
+
return () => this.bars.update((all) => all.filter((one) => one !== groups));
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Listen for `shortcut`, pressed anywhere in the app: `mod+k`, as `parseShortcut` reads it.
|
|
286
|
+
* `label` is what Android's Keyboard Shortcuts helper lists it as. Answers the function that
|
|
287
|
+
* stops listening.
|
|
288
|
+
*/
|
|
289
|
+
addShortcut(shortcut, label, press) {
|
|
290
|
+
const registered = { shortcut, label, press };
|
|
291
|
+
this.shortcuts.update((all) => [...all, registered]);
|
|
292
|
+
return () => this.shortcuts.update((all) => all.filter((one) => one !== registered));
|
|
293
|
+
}
|
|
294
|
+
navigators = new Set();
|
|
295
|
+
/**
|
|
296
|
+
* Hear the OS's back and forward commands. `@ng-native/router` listens, and moves through the
|
|
297
|
+
* history of the window each was in, `steps` entries (one, but for a pick from a chevron's
|
|
298
|
+
* history menu). Answers the function that stops listening.
|
|
299
|
+
*/
|
|
300
|
+
onNavigate(listener) {
|
|
301
|
+
this.navigators.add(listener);
|
|
302
|
+
return () => void this.navigators.delete(listener);
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Tell the host the history of the window on `surface`, which its toolbar's back and forward
|
|
306
|
+
* chevrons and their menus show. `@ng-native/router` calls it. Does nothing where the host has
|
|
307
|
+
* no chevrons.
|
|
308
|
+
*/
|
|
309
|
+
setHistory(surface, history) {
|
|
310
|
+
this.native?.setHistory?.(surface, history);
|
|
311
|
+
}
|
|
312
|
+
hostSaid(event) {
|
|
313
|
+
if (event.type === 'navigate') {
|
|
314
|
+
const steps = event.steps ?? 1;
|
|
315
|
+
this.navigators.forEach((listener) => listener(event.direction, event.surface, steps));
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
if (event.type === 'menuSelect') {
|
|
319
|
+
this.sentBar().actions.get(event.id)?.();
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
if (event.type === 'contextMenuSelect') {
|
|
323
|
+
this.contextMenuChoices.get(event.nativeID)?.(event.id);
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
const { presses, editing } = this.sentShortcuts();
|
|
327
|
+
// The editing keys belong to a focused text input: the app's shortcut on one waits.
|
|
328
|
+
if (event.textInputFocused && editing.has(event.id))
|
|
329
|
+
return;
|
|
330
|
+
presses.get(event.id)?.();
|
|
331
|
+
}
|
|
332
|
+
ngOnDestroy() {
|
|
333
|
+
this.unsubscribe?.();
|
|
334
|
+
}
|
|
335
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: Menus, deps: [], target: i0.ɵɵFactoryTarget.Service });
|
|
336
|
+
static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.2.0", ngImport: i0, type: Menus });
|
|
337
|
+
}
|
|
338
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: Menus, decorators: [{
|
|
339
|
+
type: Service
|
|
340
|
+
}], ctorParameters: () => [] });
|
|
341
|
+
//# sourceMappingURL=menus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"menus.js","sourceRoot":"","sources":["../src/menus.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,EACL,cAAc,EACd,OAAO,EACP,QAAQ,EACR,MAAM,EACN,MAAM,EACN,MAAM,GAEP,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,cAAc,EACd,WAAW,EACX,YAAY,GAGb,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,GAGd,MAAM,eAAe,CAAC;;AA4BvB,MAAM,SAAS,GAAG,IAAI,OAAO,EAAsB,CAAC;AACpD,IAAI,YAAY,GAAG,CAAC,CAAC;AAErB;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,MAAkB;IAC7C,IAAI,EAAE,GAAG,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC/B,IAAI,EAAE,KAAK,SAAS;QAAE,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC;IACzE,OAAO,EAAE,CAAC;AACZ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAC3B,OAA6B,EAC7B,EAAc,EACd,MAAM,GAAG,EAAE;IAEX,MAAM,OAAO,GAAG,IAAI,GAAG,EAAsB,CAAC;IAC9C,MAAM,IAAI,GAAG,CAAC,IAA0B,EAAE,EAAU,EAAqB,EAAE,CACzE,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QACxB,IAAI,WAAW,CAAC,KAAK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CAAC,CAAC;YACxD,OAAO;QACT,CAAC;QACD,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;QAClD,oFAAoF;QACpF,IAAI,KAAK,CAAC,gBAAgB,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YAAE,OAAO;QAC5D,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IAC5B,CAAC;IAED,WAAW;QACT,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;IACvB,CAAC;uGAtOU,KAAK;wGAAL,KAAK;;2FAAL,KAAK;kBADjB,OAAO","sourcesContent":["/**\n * Menus and keyboard shortcuts as the host receives them: the menu bar, the shortcuts that are in\n * no menu, and the form a menu takes on its way to native, which a context menu shares.\n *\n * The host contract, on the `NgNativeMenus` module:\n * - `setMenuBar(groups)`: the whole merged menu bar, each time it changes. The desktop host draws\n * it as the main menu, iPadOS through UIMenuBuilder. Each item has an `id`; an item with a\n * `menuRole` and no `id`'s action is the OS's own (Copy, Quit).\n * - `setShortcuts(shortcuts)`: every shortcut the app listens for outside the menu bar, each with\n * its `id`, its chord read for the OS, and a `label` and `group` for Android's Keyboard Shortcuts\n * helper. On iPhone and Android the menu bar's own shortcuts are in it too, since no bar is drawn.\n * - It sends `ngNativeMenus` events on `DeviceEventEmitter`: `{ type: 'menuSelect', id }` for a menu\n * bar item, and `{ type: 'shortcut', id, textInputFocused }` for a chord pressed.\n * - Its constants say whether it draws a menu bar (`menuBar`) and the app's name (`appName`).\n * - On Android it is an Expo module: the constants are properties, it sends the same events through\n * its own `addListener('ngNativeMenus', ...)`, and it has `setContextMenu(nativeID, entries)`,\n * since React Native's Android view drops a `contextMenu` prop it does not know.\n * - On iOS it is a TurboModule with `setContextMenu(nativeID, entries)` too, for the same reason.\n * React Native's iOS view sends no event it does not know either, so the module sends the item\n * chosen as `{ type: 'contextMenuSelect', nativeID, id }`.\n * - Where it draws context menus, `setTakesLongPress(nativeID, takes)` names a view inside one\n * whose own `(longPress)` takes a long press first: a long press there opens no menu around it,\n * as the innermost handler wins in a native app. A right-click still opens the menu on Android.\n * iOS tells a long press from a secondary click only by the gesture, so an iPad pointer's\n * secondary click there opens none either.\n */\nimport {\n InjectionToken,\n Service,\n computed,\n effect,\n inject,\n signal,\n type Signal,\n} from '@angular/core';\nimport {\n defaultMenuBar,\n isSeparator,\n mergeMenuBar,\n type MenuEntry,\n type MenuGroupModel,\n} from './menu-model.ts';\nimport { injectOs } from './os.ts';\nimport { reactNative } from './react-native.ts';\nimport {\n isEditingShortcut,\n navigationShortcut,\n parseShortcut,\n type ParsedShortcut,\n type ShortcutOs,\n} from './shortcut.ts';\n\n/** A menu entry as the host receives it. */\nexport type NativeMenuEntry =\n | { readonly separator: true }\n | {\n readonly id: string;\n readonly label: string;\n readonly menuRole?: string;\n /** On an item with a `menuRole`: the app handles it, and the OS does not. */\n readonly handled?: true;\n readonly shortcut?: ParsedShortcut;\n readonly disabled?: boolean;\n readonly checked?: boolean;\n readonly destructive?: boolean;\n readonly subtitle?: string;\n readonly sfSymbol?: string;\n readonly icon?: string;\n readonly inline?: boolean;\n readonly items?: readonly NativeMenuEntry[];\n };\n\n/** A menu ready for the host, and what each id it was given does. */\nexport interface SerializedMenu {\n readonly entries: NativeMenuEntry[];\n readonly actions: ReadonlyMap<string, () => void>;\n}\n\nconst actionIds = new WeakMap<() => void, string>();\nlet actionsNamed = 0;\n\n/**\n * The id a menu item with `select` is sent under: the same for as long as the handler is, and no\n * other handler's. `<menu-item>` keeps one handler for its life, so a host that reports a choice\n * from a menu it drew before the items changed still runs that item, or nothing once it has gone,\n * never the item that has taken its place.\n */\nexport function menuActionId(select: () => void): string {\n let id = actionIds.get(select);\n if (id === undefined) actionIds.set(select, (id = `a${++actionsNamed}`));\n return id;\n}\n\n/**\n * `entries` as the host takes them: an id for each item, its shortcut read for `os`, and the\n * handlers by id. An item with a handler is named by it (`menuActionId`); one without, which the\n * app never runs, by its place (`2.0.1`).\n */\nexport function serializeMenu(\n entries: readonly MenuEntry[],\n os: ShortcutOs,\n prefix = '',\n): SerializedMenu {\n const actions = new Map<string, () => void>();\n const walk = (list: readonly MenuEntry[], at: string): NativeMenuEntry[] =>\n list.map((entry, index) => {\n if (isSeparator(entry)) return { separator: true };\n const place = `${at}${index}`;\n const { select, shortcut, items, group: _group, ...rest } = entry;\n const id = select ? menuActionId(select) : place;\n if (select) actions.set(id, select);\n return {\n id,\n ...rest,\n // A role item the app handles: the host sends its select rather than doing the role.\n ...(select && entry.menuRole && { handled: true }),\n ...(shortcut\n ? { shortcut: parseShortcut(shortcut, os) }\n : (entry.menuRole === 'back' || entry.menuRole === 'forward') && {\n shortcut: navigationShortcut(entry.menuRole, os),\n }),\n ...(items && { items: walk(items, `${place}.`) }),\n };\n });\n return { entries: walk(entries, prefix), actions };\n}\n\n/** A shortcut as the host receives it. */\nexport interface NativeShortcut {\n readonly id: string;\n readonly chord: ParsedShortcut;\n /** What Android's Keyboard Shortcuts helper lists it as. */\n readonly label: string;\n /** The heading it is listed under there: its menu's label, or the app's name. */\n readonly group: string;\n}\n\nexport type NativeMenuEvent =\n | { readonly type: 'menuSelect'; readonly id: string }\n | { readonly type: 'shortcut'; readonly id: string; readonly textInputFocused?: boolean }\n /** An item chosen in the context menu of the view with `nativeID` (iOS). */\n | { readonly type: 'contextMenuSelect'; readonly nativeID: string; readonly id: string }\n /**\n * Back or forward, from whichever input the OS has for it: View > Back and Forward and their\n * keys, a two-finger swipe, mouse buttons 4 and 5, the toolbar's chevrons and their history\n * menus. `surface` is the window it was in, and `steps` how many entries (one where absent).\n */\n | {\n readonly type: 'navigate';\n readonly direction: 'back' | 'forward';\n readonly surface?: number;\n readonly steps?: number;\n };\n\n/** A window's history as the host draws it: the titles behind and ahead, nearest first. */\nexport interface NativeWindowHistory {\n readonly back: readonly string[];\n readonly forward: readonly string[];\n}\n\n/** The host's menu module. */\nexport interface NativeMenus {\n /** Whether the host draws a menu bar: macOS, and iPadOS. */\n readonly menuBar: boolean;\n readonly appName: string;\n setMenuBar(\n groups: readonly { label: string; menuRole?: string; items: NativeMenuEntry[] }[],\n ): void;\n setShortcuts(shortcuts: readonly NativeShortcut[]): void;\n /** The history of the window on `surface`, for its back and forward chevrons. Desktop only. */\n setHistory?(surface: number, history: NativeWindowHistory): void;\n /**\n * The context menu of the view with `nativeID`, or null to take it away. Android and iOS, whose\n * views read no `contextMenu` prop: the host finds the view by its `nativeID`.\n */\n setContextMenu?(nativeID: string, entries: readonly NativeMenuEntry[] | null): void;\n /**\n * Whether the view with `nativeID` takes a long press itself, so a context menu around it does\n * not open on one there. Android and iOS, beside `setContextMenu`.\n */\n setTakesLongPress?(nativeID: string, takes: boolean): void;\n subscribe(listener: (event: NativeMenuEvent) => void): () => void;\n}\n\ninterface MenusModule {\n getConstants?(): { menuBar?: boolean; appName?: string };\n /** An Expo module's constants, which are its properties. */\n readonly menuBar?: boolean;\n readonly appName?: string;\n setMenuBar?(groups: unknown): void;\n setShortcuts?(shortcuts: unknown): void;\n setHistory?(surface: number, history: unknown): void;\n setContextMenu?(nativeID: string, entries: unknown): void;\n setTakesLongPress?(nativeID: string, takes: boolean): void;\n /** An Expo module's own events. */\n addListener?(event: string, listener: (event: unknown) => void): { remove(): void };\n}\n\n/** Android's `NgNativeMenus`, an Expo module, where React Native has no TurboModule of the name. */\nfunction expoMenusModule(): MenusModule | undefined {\n const modules = (globalThis as { expo?: { modules?: Record<string, unknown> } }).expo?.modules;\n return modules?.['NgNativeMenus'] as MenusModule | undefined;\n}\n\n/**\n * The host's menu module: a TurboModule (the desktop host, iOS), or else Android's Expo module.\n * Null where there is neither, as in Expo Go.\n */\nexport function menusSource(): NativeMenus | null {\n const native = reactNative();\n const turbo = native?.TurboModuleRegistry?.get?.('NgNativeMenus') as\n MenusModule | null | undefined;\n const expo = turbo ? undefined : expoMenusModule();\n const module = turbo ?? expo;\n if (!module) return null;\n const constants = module.getConstants?.() ?? module;\n // An Expo module sends its events itself; a TurboModule's come through DeviceEventEmitter.\n const listen = (hear: (event: unknown) => void) =>\n expo\n ? expo.addListener?.('ngNativeMenus', hear)\n : native?.DeviceEventEmitter?.addListener('ngNativeMenus', hear);\n return {\n menuBar: constants.menuBar === true,\n appName: constants.appName ?? '',\n setMenuBar: (groups) => module.setMenuBar?.(groups),\n setShortcuts: (shortcuts) => module.setShortcuts?.(shortcuts),\n setHistory: (surface, history) => module.setHistory?.(surface, history),\n ...contextMenuMethods(module),\n subscribe: (listener) => {\n const subscription = listen((event) => listener(event as NativeMenuEvent));\n return () => subscription?.remove();\n },\n };\n}\n\n/** The context menu methods a module has, bound, and none it lacks: a host without them reads props. */\nfunction contextMenuMethods(\n module: MenusModule,\n): Pick<NativeMenus, 'setContextMenu' | 'setTakesLongPress'> {\n const setContextMenu = module.setContextMenu?.bind(module);\n const setTakesLongPress = module.setTakesLongPress?.bind(module);\n return {\n ...(setContextMenu && { setContextMenu }),\n ...(setTakesLongPress && { setTakesLongPress }),\n };\n}\n\n/** The `ShortcutOs` an `OS` reads shortcuts as. */\nconst shortcutOs = (os: string): ShortcutOs =>\n os === 'android' || os === 'macos' || os === 'web' ? os : 'ios';\n\n/** A `[shortcut]` registered with `KeyboardShortcuts`. */\ninterface Registered {\n readonly shortcut: Signal<string>;\n readonly label: Signal<string>;\n readonly press: () => void;\n}\n\n/**\n * The menus and shortcuts an app has, sent to the host as they change. `<menu-bar>` and\n * `[shortcut]` in `@ng-native/components` register here; an app rarely injects it.\n */\n@Service()\nexport class Menus {\n /** Overridden in a test with a fake host. */\n static readonly SOURCE = new InjectionToken<NativeMenus | null>('angular-native.menusSource', {\n factory: menusSource,\n });\n\n private readonly native = inject(Menus.SOURCE);\n private readonly os = shortcutOs(injectOs());\n\n /** Whether the host has the module: shortcuts from a hardware keyboard, and menus. */\n readonly available: Signal<boolean> = signal(this.native !== null).asReadonly();\n\n /** Whether the menu bar is drawn: macOS and iPadOS. Elsewhere its shortcuts still work. */\n readonly menuBarShown: Signal<boolean> = signal(this.native?.menuBar === true).asReadonly();\n\n /**\n * Whether the host takes a `[contextMenu]` by the view's `nativeID` through `setContextMenu`\n * (Android and iOS) rather than as the view's `contextMenu` prop. Where it does, it draws the\n * menu on a long press.\n */\n readonly contextMenuByNativeId: boolean = this.native?.setContextMenu !== undefined;\n\n /**\n * Whether the host, which draws context menus on a long press, can be told which views inside\n * one take a long press themselves (`setTakesLongPress`).\n */\n readonly longPressByNativeId: boolean =\n this.contextMenuByNativeId && this.native?.setTakesLongPress !== undefined;\n\n /**\n * Say whether the view with `nativeID` takes a long press itself: one there then opens no\n * context menu around it.\n */\n setTakesLongPress(nativeID: string, takes: boolean): void {\n if (takes) this.longPressTakers.add(nativeID);\n else this.longPressTakers.delete(nativeID);\n this.native?.setTakesLongPress?.(nativeID, takes);\n }\n\n /** The `nativeID`s sent with a context menu, and with a long press of their own. */\n private readonly withContextMenu = new Set<string>();\n private readonly longPressTakers = new Set<string>();\n\n /**\n * Whether the host opens a context menu on a long press of the view whose `nativeID`s, from it\n * outwards, are `chain`: as it decides, the nearest view with a menu, unless one on the way takes\n * the long press itself. A `(longPress)` around that view leaves the hold to the menu, which the\n * host opens after its own long-press timeout.\n */\n opensContextMenu(chain: Iterable<string | null>): boolean {\n for (const nativeID of chain) {\n if (nativeID === null) continue;\n if (this.withContextMenu.has(nativeID)) return true;\n if (this.longPressTakers.has(nativeID)) return false;\n }\n return false;\n }\n\n /** What choosing an item does, by the `nativeID` of the view whose menu it is in. */\n private readonly contextMenuChoices = new Map<string, (id: string) => void>();\n\n /**\n * Send the context menu of the view with `nativeID`, or null to take it away. `choose` runs with\n * the item's `id` where the host sends the choice itself (iOS) rather than through the view.\n */\n setContextMenu(\n nativeID: string,\n entries: readonly NativeMenuEntry[] | null,\n choose?: (id: string) => void,\n ): void {\n if (entries && choose) this.contextMenuChoices.set(nativeID, choose);\n else this.contextMenuChoices.delete(nativeID);\n if (entries?.length) this.withContextMenu.add(nativeID);\n else this.withContextMenu.delete(nativeID);\n this.native?.setContextMenu?.(nativeID, entries);\n }\n\n private readonly bars = signal<readonly Signal<readonly MenuEntry[]>[]>([]);\n private readonly shortcuts = signal<readonly Registered[]>([]);\n\n /** The app's groups, from every `<menu-bar>`, in the order they registered. */\n private readonly appGroups = computed<MenuGroupModel[]>(() =>\n this.bars()\n .flatMap((bar) => bar())\n .flatMap((entry) =>\n isSeparator(entry)\n ? []\n : [\n {\n label: entry.label,\n ...(entry.group && { menuRole: entry.group }),\n items: entry.items ?? [],\n },\n ],\n ),\n );\n\n /** The menu bar as it is drawn: the OS's defaults with the app's merged in. */\n readonly menuBar: Signal<MenuGroupModel[]> = computed(() =>\n mergeMenuBar(defaultMenuBar(this.native?.appName || 'App'), this.appGroups()),\n );\n\n private readonly sentBar = computed(() => {\n const groups = this.menuBar();\n const actions = new Map<string, () => void>();\n const sent = groups.map((group, index) => {\n const menu = serializeMenu(group.items, this.os, `${index}.`);\n menu.actions.forEach((action, id) => actions.set(id, action));\n return {\n label: group.label,\n ...(group.menuRole && { menuRole: group.menuRole }),\n items: menu.entries,\n };\n });\n return { sent, actions };\n });\n\n /**\n * The shortcuts sent to the host: every `[shortcut]`, and where no menu bar is drawn, every\n * menu bar item the app gave a shortcut and a handler, so a hardware keyboard still has them.\n */\n private readonly sentShortcuts = computed(() => {\n const presses = new Map<string, () => void>();\n const editing = new Set<string>();\n const sent: NativeShortcut[] = [];\n const add = (id: string, shortcut: string, label: string, group: string, press: () => void) => {\n presses.set(id, press);\n if (isEditingShortcut(shortcut, this.os)) editing.add(id);\n sent.push({ id, chord: parseShortcut(shortcut, this.os), label, group });\n };\n this.shortcuts().forEach((one, index) =>\n add(`s${index}`, one.shortcut(), one.label(), this.native?.appName || 'App', one.press),\n );\n if (!this.menuBarShown()) {\n const walk = (entries: readonly MenuEntry[], group: string, at: string) =>\n entries.forEach((entry, index) => {\n if (isSeparator(entry)) return;\n if (entry.shortcut && entry.select && !entry.disabled) {\n add(`m${at}${index}`, entry.shortcut, entry.label, group, entry.select);\n }\n if (entry.items) walk(entry.items, group, `${at}${index}.`);\n });\n this.appGroups().forEach((group, index) => walk(group.items, group.label, `${index}.`));\n }\n return { sent, presses, editing };\n });\n\n private readonly unsubscribe = this.native?.subscribe((event) => this.hostSaid(event)) ?? null;\n\n constructor() {\n const native = this.native;\n if (!native) {\n // Read for nothing, so a shortcut the app gets wrong throws where there is no host too, and\n // not first on a device that has one.\n effect(() => this.sentShortcuts());\n return;\n }\n effect(() => {\n if (this.menuBarShown()) native.setMenuBar(this.sentBar().sent);\n });\n effect(() => native.setShortcuts(this.sentShortcuts().sent));\n }\n\n /**\n * Add a `<menu-bar>`'s groups, each a `MenuItemModel` with `items` and its `group` role. Answers\n * the function that takes them out again, as the `<menu-bar>` goes.\n */\n addMenuBar(groups: Signal<readonly MenuEntry[]>): () => void {\n this.bars.update((all) => [...all, groups]);\n return () => this.bars.update((all) => all.filter((one) => one !== groups));\n }\n\n /**\n * Listen for `shortcut`, pressed anywhere in the app: `mod+k`, as `parseShortcut` reads it.\n * `label` is what Android's Keyboard Shortcuts helper lists it as. Answers the function that\n * stops listening.\n */\n addShortcut(shortcut: Signal<string>, label: Signal<string>, press: () => void): () => void {\n const registered: Registered = { shortcut, label, press };\n this.shortcuts.update((all) => [...all, registered]);\n return () => this.shortcuts.update((all) => all.filter((one) => one !== registered));\n }\n\n private readonly navigators = new Set<\n (direction: 'back' | 'forward', surface?: number, steps?: number) => void\n >();\n\n /**\n * Hear the OS's back and forward commands. `@ng-native/router` listens, and moves through the\n * history of the window each was in, `steps` entries (one, but for a pick from a chevron's\n * history menu). Answers the function that stops listening.\n */\n onNavigate(\n listener: (direction: 'back' | 'forward', surface?: number, steps?: number) => void,\n ): () => void {\n this.navigators.add(listener);\n return () => void this.navigators.delete(listener);\n }\n\n /**\n * Tell the host the history of the window on `surface`, which its toolbar's back and forward\n * chevrons and their menus show. `@ng-native/router` calls it. Does nothing where the host has\n * no chevrons.\n */\n setHistory(surface: number, history: NativeWindowHistory): void {\n this.native?.setHistory?.(surface, history);\n }\n\n private hostSaid(event: NativeMenuEvent): void {\n if (event.type === 'navigate') {\n const steps = event.steps ?? 1;\n this.navigators.forEach((listener) => listener(event.direction, event.surface, steps));\n return;\n }\n if (event.type === 'menuSelect') {\n this.sentBar().actions.get(event.id)?.();\n return;\n }\n if (event.type === 'contextMenuSelect') {\n this.contextMenuChoices.get(event.nativeID)?.(event.id);\n return;\n }\n const { presses, editing } = this.sentShortcuts();\n // The editing keys belong to a focused text input: the app's shortcut on one waits.\n if (event.textInputFocused && editing.has(event.id)) return;\n presses.get(event.id)?.();\n }\n\n ngOnDestroy(): void {\n this.unsubscribe?.();\n }\n}\n"]}
|
package/dist/navigation-bar.d.ts
CHANGED
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Android's navigation bar: the colour of its buttons, and whether it is there at all.
|
|
3
|
-
*
|
|
4
|
-
* The same stack of claims as `StatusBar`, so a video player can hide the bar while it is open and
|
|
5
|
-
* the screen behind gets the bar back when it closes. `style: 'auto'` follows `ColorScheme`, a
|
|
6
|
-
* theme the app sets included, and a fixed style holds through a scheme change.
|
|
7
|
-
*
|
|
8
|
-
* Driven through `expo-navigation-bar`'s native module, reached by name so nothing here imports the
|
|
9
|
-
* package. Expo Go carries it; a development build has it once the app installs
|
|
10
|
-
* `expo-navigation-bar`. Without it, and on iOS, which has no navigation bar, every claim is kept
|
|
11
|
-
* but changes nothing.
|
|
12
|
-
*/
|
|
13
1
|
import { InjectionToken, type Signal } from '@angular/core';
|
|
14
2
|
import * as i0 from "@angular/core";
|
|
15
3
|
/**
|
|
@@ -45,6 +33,8 @@ export declare class NavigationBar {
|
|
|
45
33
|
/** Overridden in a test to watch the bar without one on screen. */
|
|
46
34
|
static readonly SOURCE: InjectionToken<NavigationBarSource>;
|
|
47
35
|
private readonly source;
|
|
36
|
+
/** Whether there is a navigation bar to style: on Android alone. */
|
|
37
|
+
readonly available: Signal<boolean>;
|
|
48
38
|
/** This app, among the apps claiming the bar: its scheme is what an `auto` style it claims follows. */
|
|
49
39
|
private readonly owner;
|
|
50
40
|
/** Every app's claims on this bar: the window is the runtime's, not an app's. */
|