@bridgebrew/shell 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/browser/approvals.tsx +373 -0
- package/browser/browser.tsx +2020 -0
- package/browser/css.d.ts +2 -0
- package/browser/errors.tsx +552 -0
- package/browser/keep-focus.ts +65 -0
- package/browser/look.css +118 -0
- package/browser/look.ts +218 -0
- package/browser/mobile.css +305 -0
- package/browser/mobile.tsx +1528 -0
- package/browser/node-actions.ts +29 -0
- package/browser/notifications.ts +1264 -0
- package/browser/page-slot.ts +48 -0
- package/browser/restart-screen.tsx +156 -0
- package/browser/shell-state.ts +1800 -0
- package/browser/shell.d.ts +924 -0
- package/browser/shortcuts.ts +528 -0
- package/browser/theme-controls.tsx +379 -0
- package/browser/transition.ts +140 -0
- package/browser/tsconfig.json +15 -0
- package/browser/view-scopes.ts +75 -0
- package/browser/wallpaper-ink.ts +167 -0
- package/browser/window.css +9 -0
- package/package.json +89 -4
- package/tsconfig.json +5 -0
- package/README.md +0 -3
|
@@ -0,0 +1,1528 @@
|
|
|
1
|
+
// The shell on a phone (research-020 B, C; owner, 16 October 2026: dedicated mobile screens, the navigation in a burger
|
|
2
|
+
// menu). No rail, no sidebar, no window manager, no overlay: one screen at a time, full screen, under a header holding
|
|
3
|
+
// the burger (or Back while an item is open) and the screen's title. With no screen chosen, the workspace's home: its
|
|
4
|
+
// views as a list. The burger opens a drawer with the same views (a screen whose manifest entry says `"mobile": true`
|
|
5
|
+
// shows its plugin's `mobileScreen` entry, any other its desktop `screen`, marked "Desktop view", D4), the workspaces
|
|
6
|
+
// and the mode.
|
|
7
|
+
// A phone: a narrow window with a coarse pointer; `localStorage['bridge.mobile']` forces it on or off (a desktop
|
|
8
|
+
// browser trying it, a tablet); a frame named `bridge-phone` is one, whatever the rest (Design system's phone preview,
|
|
9
|
+
// research-070: the name stays with the frame across its navigations, and no other page is affected).
|
|
10
|
+
import * as React from 'react';
|
|
11
|
+
import type { Context } from 'cordis';
|
|
12
|
+
import {
|
|
13
|
+
Dialog,
|
|
14
|
+
DialogContent,
|
|
15
|
+
DialogTitle,
|
|
16
|
+
Icon,
|
|
17
|
+
SegmentGroup,
|
|
18
|
+
SidebarTree,
|
|
19
|
+
SidebarTreeItem,
|
|
20
|
+
Slider,
|
|
21
|
+
getClientAppearance,
|
|
22
|
+
getInitials,
|
|
23
|
+
setMode,
|
|
24
|
+
setPreference,
|
|
25
|
+
subscribeClientAppearance,
|
|
26
|
+
} from '@bridge/ui';
|
|
27
|
+
import { modeColour, tileColourOf, tileShapeStyles } from '@bridge/kernel/look';
|
|
28
|
+
import { blocksOn, pathTo, viewOf, type Shell, type View } from './shell-state.ts';
|
|
29
|
+
import './mobile.css';
|
|
30
|
+
|
|
31
|
+
const mobileKey = 'bridge.mobile';
|
|
32
|
+
/** The workspace shown last on this phone, where the home screen app opens. */
|
|
33
|
+
const lastKey = 'bridge.mobile.workspace';
|
|
34
|
+
const query = '(max-width: 640px) and (pointer: coarse)';
|
|
35
|
+
|
|
36
|
+
/** The name of a frame that shows the phone's shell, whatever the device. */
|
|
37
|
+
export const phoneFrameName = 'bridge-phone';
|
|
38
|
+
|
|
39
|
+
/** Whether this page shows the phone's shell: a frame named `bridge-phone` does; else `bridge.mobile` set to `on` or
|
|
40
|
+
* `off` decides, else the media query. */
|
|
41
|
+
export const isMobile = () => {
|
|
42
|
+
if (typeof window !== 'undefined' && window.name === phoneFrameName) return true;
|
|
43
|
+
let forced: string | null = null;
|
|
44
|
+
try {
|
|
45
|
+
forced = localStorage.getItem(mobileKey);
|
|
46
|
+
} catch {
|
|
47
|
+
/* the media query */
|
|
48
|
+
}
|
|
49
|
+
if (forced === 'on') return true;
|
|
50
|
+
if (forced === 'off') return false;
|
|
51
|
+
return typeof matchMedia === 'function' && matchMedia(query).matches;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/** `isMobile()`, followed live (the window resized, the phone turned, the setting changed in another tab). */
|
|
55
|
+
export function useMobile() {
|
|
56
|
+
return React.useSyncExternalStore(
|
|
57
|
+
React.useCallback((listener: () => void) => {
|
|
58
|
+
const media = typeof matchMedia === 'function' ? matchMedia(query) : undefined;
|
|
59
|
+
media?.addEventListener('change', listener);
|
|
60
|
+
window.addEventListener('storage', listener);
|
|
61
|
+
return () => {
|
|
62
|
+
media?.removeEventListener('change', listener);
|
|
63
|
+
window.removeEventListener('storage', listener);
|
|
64
|
+
};
|
|
65
|
+
}, []),
|
|
66
|
+
isMobile,
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** The open state of the drawer (shared by the header's burger and the frame that draws the drawer) or of the phone's
|
|
71
|
+
* settings sheet over it, kept in the history state under `key`. Open, it is an entry of the history (the same URL):
|
|
72
|
+
* the phone's Back (Android's button, the swipe) closes it rather than leaving the screen. `close(then)` goes back off
|
|
73
|
+
* that entry first, then runs `then` (a view chosen in the drawer), so it leaves no entry behind; with `above` (the
|
|
74
|
+
* sheet over the drawer) open, that one first: its entry holds the drawer's marker, so going back once would stop there. */
|
|
75
|
+
export function drawerState(
|
|
76
|
+
key: 'bridgeDrawer' | 'bridgeSettings' | 'bridgeWorkspaces',
|
|
77
|
+
above?: { get(): boolean; close(then?: () => void): void },
|
|
78
|
+
) {
|
|
79
|
+
let open = false;
|
|
80
|
+
let marker = 0;
|
|
81
|
+
let after: (() => void) | undefined;
|
|
82
|
+
// `stay`: the drawer kept open past its entry gone back off, with no entry of its own (`marker` 0) from there: the
|
|
83
|
+
// shell writes the history of the workspace it opens (its last screen, in place or as a new entry), over which an
|
|
84
|
+
// entry of the drawer's would be lost; Back then goes on under it, and the drawer closes by its own controls.
|
|
85
|
+
let keep = false;
|
|
86
|
+
const listeners = new Set<() => void>();
|
|
87
|
+
const emit = () => {
|
|
88
|
+
for (const listener of listeners) listener();
|
|
89
|
+
};
|
|
90
|
+
if (typeof window !== 'undefined')
|
|
91
|
+
window.addEventListener('popstate', () => {
|
|
92
|
+
if (
|
|
93
|
+
!open ||
|
|
94
|
+
marker === 0 ||
|
|
95
|
+
(history.state as Record<string, unknown> | null)?.[key] === marker
|
|
96
|
+
)
|
|
97
|
+
return;
|
|
98
|
+
if (keep) {
|
|
99
|
+
keep = false;
|
|
100
|
+
const then = after;
|
|
101
|
+
after = undefined;
|
|
102
|
+
marker = 0;
|
|
103
|
+
setTimeout(() => then?.(), 0);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
open = false;
|
|
107
|
+
emit();
|
|
108
|
+
const then = after;
|
|
109
|
+
after = undefined;
|
|
110
|
+
// Once every `popstate` listener ran (the shell's `followUrl` reads the URL gone back to): `then` changing the
|
|
111
|
+
// view or the workspace meanwhile would be undone by it.
|
|
112
|
+
if (then) setTimeout(then, 0);
|
|
113
|
+
});
|
|
114
|
+
const state = {
|
|
115
|
+
get: () => open,
|
|
116
|
+
open() {
|
|
117
|
+
if (open) return;
|
|
118
|
+
open = true;
|
|
119
|
+
marker = Date.now();
|
|
120
|
+
history.pushState({ ...(history.state as object | null), [key]: marker }, '', location.href);
|
|
121
|
+
emit();
|
|
122
|
+
},
|
|
123
|
+
close(then?: () => void): void {
|
|
124
|
+
if (above?.get()) return above.close(() => state.close(then));
|
|
125
|
+
if (!open) return then?.();
|
|
126
|
+
if ((history.state as Record<string, unknown> | null)?.[key] === marker) {
|
|
127
|
+
after = then;
|
|
128
|
+
history.back();
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
open = false;
|
|
132
|
+
emit();
|
|
133
|
+
then?.();
|
|
134
|
+
},
|
|
135
|
+
/** As `close(then)`, but still open on what `then` leads to (another workspace), without closing in between. */
|
|
136
|
+
stay(then: () => void): void {
|
|
137
|
+
if (above?.get()) return above.close(() => state.stay(then));
|
|
138
|
+
if (!open || (history.state as Record<string, unknown> | null)?.[key] !== marker)
|
|
139
|
+
return then();
|
|
140
|
+
keep = true;
|
|
141
|
+
after = then;
|
|
142
|
+
history.back();
|
|
143
|
+
},
|
|
144
|
+
subscribe(listener: () => void) {
|
|
145
|
+
listeners.add(listener);
|
|
146
|
+
return () => {
|
|
147
|
+
listeners.delete(listener);
|
|
148
|
+
};
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
return state;
|
|
152
|
+
}
|
|
153
|
+
const settingsSheet = drawerState('bridgeSettings');
|
|
154
|
+
/** The workspaces' sheet over the floating menu (the `tree` menu style), opened from its title. */
|
|
155
|
+
const workspaceSheet = drawerState('bridgeWorkspaces');
|
|
156
|
+
const drawer = drawerState('bridgeDrawer', {
|
|
157
|
+
get: () => settingsSheet.get() || workspaceSheet.get(),
|
|
158
|
+
close: (then) => (settingsSheet.get() ? settingsSheet : workspaceSheet).close(then),
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
/** How the phone's menu reaches the tree's nodes, chosen in its settings and kept on this device: `pages`, as iOS's
|
|
162
|
+
* Settings (a node's page lists its views, then its child nodes, each opening its own page, Back going up one);
|
|
163
|
+
* `tree`, as Linear's (a floating panel of the node's views, the whole tree on a page of its own, each node unfolded
|
|
164
|
+
* by its triangle). */
|
|
165
|
+
type MenuStyle = 'pages' | 'tree';
|
|
166
|
+
const menuKey = 'bridge.mobile.menu';
|
|
167
|
+
const menuStyle = (() => {
|
|
168
|
+
const listeners = new Set<() => void>();
|
|
169
|
+
return {
|
|
170
|
+
get(): MenuStyle {
|
|
171
|
+
try {
|
|
172
|
+
return localStorage.getItem(menuKey) === 'pages' ? 'pages' : 'tree';
|
|
173
|
+
} catch {
|
|
174
|
+
return 'tree';
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
set(style: MenuStyle) {
|
|
178
|
+
try {
|
|
179
|
+
localStorage.setItem(menuKey, style);
|
|
180
|
+
} catch {
|
|
181
|
+
/* not kept */
|
|
182
|
+
}
|
|
183
|
+
for (const listener of listeners) listener();
|
|
184
|
+
},
|
|
185
|
+
subscribe(listener: () => void) {
|
|
186
|
+
listeners.add(listener);
|
|
187
|
+
return () => {
|
|
188
|
+
listeners.delete(listener);
|
|
189
|
+
};
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
})();
|
|
193
|
+
|
|
194
|
+
type Tree = ReturnType<Shell['get']>['nodes'];
|
|
195
|
+
/** Node `id` and its ancestors. */
|
|
196
|
+
const chainOf = (tree: Tree, id: string) => {
|
|
197
|
+
const chain = new Set<string>();
|
|
198
|
+
for (
|
|
199
|
+
let at = tree?.nodes.find((node) => node.id === id);
|
|
200
|
+
at && !chain.has(at.id);
|
|
201
|
+
at = tree?.nodes.find((node) => node.id === at!.parent)
|
|
202
|
+
)
|
|
203
|
+
chain.add(at.id);
|
|
204
|
+
return chain;
|
|
205
|
+
};
|
|
206
|
+
/** Node `parent`'s children as the sidebar lists them: an archived one only on the way to the node `shown`. */
|
|
207
|
+
const childrenOf = (tree: Tree, parent: string, shown: string) => {
|
|
208
|
+
const chain = chainOf(tree, shown);
|
|
209
|
+
return (tree?.nodes ?? []).filter(
|
|
210
|
+
(node) =>
|
|
211
|
+
(node.parent ?? 'root') === parent &&
|
|
212
|
+
node.id !== 'root' &&
|
|
213
|
+
(!node.archived || chain.has(node.id)),
|
|
214
|
+
);
|
|
215
|
+
};
|
|
216
|
+
/** A node's icon, as the sidebar's: a project's `folder-root`, a plain node's `folder`. */
|
|
217
|
+
const nodeIcon = (tree: Tree, id: string) => (tree?.projects?.[id] ? 'folder-root' : 'folder');
|
|
218
|
+
|
|
219
|
+
type Direction = 'push' | 'pop' | 'swap';
|
|
220
|
+
/** How the phone moves from `was` to `next`: an item opened deeper (`push`, iOS's slide from the right: from the list,
|
|
221
|
+
* or under the item open), back to the list or to the item above (`pop`), another item or another screen of the
|
|
222
|
+
* drawer (`swap`, a cross-fade); none for another workspace (the shell's own transition) or a state with the same
|
|
223
|
+
* view. */
|
|
224
|
+
const directionOf = (
|
|
225
|
+
was: ReturnType<Shell['get']>,
|
|
226
|
+
next: ReturnType<Shell['get']>,
|
|
227
|
+
): Direction | undefined => {
|
|
228
|
+
if (was.current?.slug !== next.current?.slug) return undefined;
|
|
229
|
+
const a = viewOf(was);
|
|
230
|
+
const b = viewOf(next);
|
|
231
|
+
if (JSON.stringify(a) === JSON.stringify(b)) return undefined;
|
|
232
|
+
const same =
|
|
233
|
+
a.node === b.node && a.screen?.plugin === b.screen?.plugin && a.screen?.id === b.screen?.id;
|
|
234
|
+
if (same && !a.utility && !b.utility) {
|
|
235
|
+
// Deeper: an item opened from the list (none before), or under the one open (`mail/m2` under `mail`).
|
|
236
|
+
const deeper = (from?: string, to?: string) =>
|
|
237
|
+
to !== undefined && (from === undefined || to.startsWith(`${from}/`));
|
|
238
|
+
if (deeper(a.item, b.item)) return 'push';
|
|
239
|
+
if (deeper(b.item, a.item)) return 'pop';
|
|
240
|
+
if (b.item !== undefined && a.item !== b.item) return 'swap';
|
|
241
|
+
}
|
|
242
|
+
return 'swap';
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
/** A view as a key, for comparing two. */
|
|
246
|
+
const viewKey = (view: View) => JSON.stringify(viewOf(view));
|
|
247
|
+
/** The view one level up `view` in its tree (the phone's Back): an item's parent item (`mail/m2` → `mail`), else the
|
|
248
|
+
* screen without its item, else its parent screen; none on a top screen. */
|
|
249
|
+
export const parentView = (
|
|
250
|
+
screens: ReturnType<Shell['get']>['screens'],
|
|
251
|
+
view: View,
|
|
252
|
+
): View | undefined => {
|
|
253
|
+
const { node, screen, item } = view;
|
|
254
|
+
if (!screen || view.utility) return undefined;
|
|
255
|
+
if (item !== undefined) {
|
|
256
|
+
const cut = item.lastIndexOf('/');
|
|
257
|
+
return cut > 0 ? { node, screen, item: item.slice(0, cut) } : { node, screen };
|
|
258
|
+
}
|
|
259
|
+
const path = screens ? pathTo(screens, screen) : [];
|
|
260
|
+
return path.length > 1
|
|
261
|
+
? { node, screen: { plugin: screen.plugin, id: path.at(-2)!.id } }
|
|
262
|
+
: undefined;
|
|
263
|
+
};
|
|
264
|
+
const show = (shell: Shell, { node, screen, item }: View) => {
|
|
265
|
+
if (!screen) return;
|
|
266
|
+
if (item !== undefined) shell.setScreen(screen, node, item);
|
|
267
|
+
else shell.setScreen(screen, node);
|
|
268
|
+
};
|
|
269
|
+
/** Up one level from the view shown: back through the history when the entry before is that view (iOS's swipe goes
|
|
270
|
+
* there too), else to it. */
|
|
271
|
+
const goUp = (shell: Shell, up: View) => {
|
|
272
|
+
if ((history.state as Record<string, unknown> | null)?.bridgeFrom === viewKey(up)) history.back();
|
|
273
|
+
else show(shell, up);
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
/** On a phone, the shell's state reaches the page through a view transition when the view changes (./mobile.css
|
|
277
|
+
* draws it): `get` and `subscribe` give the state shown, which moves to the shell's own inside
|
|
278
|
+
* `document.startViewTransition`, so the browser has the screen before and after to animate. Elsewhere (the
|
|
279
|
+
* desktop, a browser without view transitions, reduced motion) every change passes through at once. The shell's own
|
|
280
|
+
* code keeps its state; `shell.get()` gives the shown one only while a transition waits, at most a frame behind.
|
|
281
|
+
* Returns what removes its window listener. */
|
|
282
|
+
export function transitions(shell: Shell) {
|
|
283
|
+
const read = shell.get;
|
|
284
|
+
const listen = shell.subscribe;
|
|
285
|
+
let shown = read();
|
|
286
|
+
let pending = false;
|
|
287
|
+
const listeners = new Set<() => void>();
|
|
288
|
+
const emit = () => {
|
|
289
|
+
for (const listener of listeners) listener();
|
|
290
|
+
};
|
|
291
|
+
const reduced = () =>
|
|
292
|
+
typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
293
|
+
// A Back the browser animated itself (iOS Safari's edge swipe: its popstate says hasUAVisualTransition): the change
|
|
294
|
+
// it brings passes through at once, never animated a second time. Listened to here, before the shell's `followUrl`
|
|
295
|
+
// (an effect, later), and in the capture phase, so it is known when that change comes.
|
|
296
|
+
let browserAnimated = false;
|
|
297
|
+
const browserBack = (event: PopStateEvent) => {
|
|
298
|
+
browserAnimated =
|
|
299
|
+
(event as PopStateEvent & { hasUAVisualTransition?: boolean }).hasUAVisualTransition === true;
|
|
300
|
+
// Its change comes while it is dispatched: a Back that changed nothing leaves no mark for the next change.
|
|
301
|
+
if (browserAnimated) setTimeout(() => (browserAnimated = false), 0);
|
|
302
|
+
};
|
|
303
|
+
if (typeof window !== 'undefined') window.addEventListener('popstate', browserBack, true);
|
|
304
|
+
// Each history entry the shell adds says which view it was added from (`bridgeFrom`): the phone's Back goes back
|
|
305
|
+
// through the history only to its parent there. An entry gone back to keeps its own.
|
|
306
|
+
let was = viewKey(read());
|
|
307
|
+
listen(() => {
|
|
308
|
+
const now = viewKey(read());
|
|
309
|
+
if (
|
|
310
|
+
now !== was &&
|
|
311
|
+
isMobile() &&
|
|
312
|
+
(history.state as Record<string, unknown> | null)?.bridgeFrom === undefined
|
|
313
|
+
)
|
|
314
|
+
history.replaceState(
|
|
315
|
+
{ ...(history.state as object | null), bridgeFrom: was },
|
|
316
|
+
'',
|
|
317
|
+
location.href,
|
|
318
|
+
);
|
|
319
|
+
was = now;
|
|
320
|
+
if (pending) return;
|
|
321
|
+
const next = read();
|
|
322
|
+
const animatedAlready = browserAnimated;
|
|
323
|
+
browserAnimated = false;
|
|
324
|
+
const direction =
|
|
325
|
+
!animatedAlready && isMobile() && !reduced() && 'startViewTransition' in document
|
|
326
|
+
? directionOf(shown, next)
|
|
327
|
+
: undefined;
|
|
328
|
+
if (!direction) {
|
|
329
|
+
shown = next;
|
|
330
|
+
emit();
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
pending = true;
|
|
334
|
+
const root = document.documentElement;
|
|
335
|
+
root.dataset.transition = direction;
|
|
336
|
+
const transition = (
|
|
337
|
+
document as Document & {
|
|
338
|
+
startViewTransition(update: () => Promise<void>): { finished: Promise<void> };
|
|
339
|
+
}
|
|
340
|
+
).startViewTransition(() => {
|
|
341
|
+
pending = false;
|
|
342
|
+
shown = read();
|
|
343
|
+
emit();
|
|
344
|
+
// React renders a store's change in a microtask; a timer runs after it (frames do not run meanwhile, so no
|
|
345
|
+
// requestAnimationFrame here): the browser then takes the new screen.
|
|
346
|
+
return new Promise<void>((resolve) => setTimeout(resolve, 0));
|
|
347
|
+
});
|
|
348
|
+
void transition.finished.finally(() => {
|
|
349
|
+
if (root.dataset.transition === direction) delete root.dataset.transition;
|
|
350
|
+
});
|
|
351
|
+
});
|
|
352
|
+
// The shell's own state but while a transition waits: a listener of the shell's that ran before this one reads the
|
|
353
|
+
// state it was told of (the desktop's windows writing the URL), not the one shown before.
|
|
354
|
+
shell.get = () => (pending ? shown : read());
|
|
355
|
+
shell.subscribe = (listener) => {
|
|
356
|
+
listeners.add(listener);
|
|
357
|
+
return () => {
|
|
358
|
+
listeners.delete(listener);
|
|
359
|
+
};
|
|
360
|
+
};
|
|
361
|
+
// The shell reloaded (or a test done): its window listener goes with it.
|
|
362
|
+
return () => {
|
|
363
|
+
if (typeof window !== 'undefined') window.removeEventListener('popstate', browserBack, true);
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/** Whether a screen has a phone variant: its manifest entry says `"mobile": true` (research-020 C), each screen for
|
|
368
|
+
* itself. A tree not loaded yet: none known. */
|
|
369
|
+
export const hasVariant = (
|
|
370
|
+
screens: ReturnType<Shell['get']>['screens'],
|
|
371
|
+
screen: { plugin: string; id: string },
|
|
372
|
+
) => !!screens && pathTo(screens, screen).at(-1)?.mobile === true;
|
|
373
|
+
/** The key a phone screen's actions and chrome are kept under: its plugin and its screen. */
|
|
374
|
+
const keyOf = ({ plugin, id }: { plugin: string; id: string }) => `${plugin} ${id}`;
|
|
375
|
+
|
|
376
|
+
type Parts = {
|
|
377
|
+
window: Record<string, unknown> & { 'aria-label': string };
|
|
378
|
+
body: React.ReactNode;
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
/** A button a phone screen gives the shell (research-020, iOS 26's layout): the shell draws it, in glass, where its
|
|
382
|
+
* `placement` says: `top`, in the capsule at the top right (the screen's actions: compose, more); `primary`, the round
|
|
383
|
+
* button at the bottom right, beside the bar of screens (the screen's main action: a new contact, a new session). The
|
|
384
|
+
* shell draws them itself so the app can later draw them natively (Liquid Glass on iOS, Material on Android). */
|
|
385
|
+
export interface MobileAction {
|
|
386
|
+
id: string;
|
|
387
|
+
label: string;
|
|
388
|
+
icon: string;
|
|
389
|
+
placement?: 'top' | 'primary';
|
|
390
|
+
onSelect: () => void;
|
|
391
|
+
disabled?: boolean;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/** The actions each phone screen gave (by `keyOf`), followed by the frame. */
|
|
395
|
+
const actions = (() => {
|
|
396
|
+
let byScreen = new Map<string, readonly MobileAction[]>();
|
|
397
|
+
const listeners = new Set<() => void>();
|
|
398
|
+
return {
|
|
399
|
+
get: () => byScreen,
|
|
400
|
+
set(key: string, list: readonly MobileAction[]) {
|
|
401
|
+
byScreen = new Map(byScreen).set(key, list);
|
|
402
|
+
for (const listener of listeners) listener();
|
|
403
|
+
},
|
|
404
|
+
subscribe(listener: () => void) {
|
|
405
|
+
listeners.add(listener);
|
|
406
|
+
return () => {
|
|
407
|
+
listeners.delete(listener);
|
|
408
|
+
};
|
|
409
|
+
},
|
|
410
|
+
};
|
|
411
|
+
})();
|
|
412
|
+
|
|
413
|
+
/** Whether each phone screen (by `keyOf`) asked to go without the bottom bar: a form of its own over its list
|
|
414
|
+
* (a new contact), whose buttons the bar would cover. */
|
|
415
|
+
const barless = (() => {
|
|
416
|
+
let keys = new Set<string>();
|
|
417
|
+
const listeners = new Set<() => void>();
|
|
418
|
+
return {
|
|
419
|
+
get: () => keys,
|
|
420
|
+
set(key: string, hidden: boolean) {
|
|
421
|
+
if (keys.has(key) === hidden) return;
|
|
422
|
+
keys = new Set(keys);
|
|
423
|
+
if (hidden) keys.add(key);
|
|
424
|
+
else keys.delete(key);
|
|
425
|
+
for (const listener of listeners) listener();
|
|
426
|
+
},
|
|
427
|
+
subscribe(listener: () => void) {
|
|
428
|
+
listeners.add(listener);
|
|
429
|
+
return () => {
|
|
430
|
+
listeners.delete(listener);
|
|
431
|
+
};
|
|
432
|
+
},
|
|
433
|
+
};
|
|
434
|
+
})();
|
|
435
|
+
|
|
436
|
+
/** What the shell adds to a phone screen's owner (`mobileScreen`): `setActions`, the buttons it wants drawn (an empty
|
|
437
|
+
* list removes them; the screen does so when it unmounts); `setChrome({ bar: false })`, no bottom bar while the screen
|
|
438
|
+
* shows a form of its own (`{}` gives it back, as the screen does when it unmounts). */
|
|
439
|
+
export const mobileOwner = (screen: { plugin: string; id: string }) => ({
|
|
440
|
+
setActions: (list: readonly MobileAction[]) => actions.set(keyOf(screen), list),
|
|
441
|
+
setChrome: (chrome: { bar?: boolean }) => barless.set(keyOf(screen), chrome.bar === false),
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
function useActions(screen: { plugin: string; id: string } | undefined) {
|
|
445
|
+
const all = React.useSyncExternalStore(actions.subscribe, actions.get);
|
|
446
|
+
return (screen && all.get(keyOf(screen))) || [];
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/** A glass control (./mobile.css `.mobile-glass`): a round button, or a capsule of buttons. */
|
|
450
|
+
const glass = 'mobile-glass';
|
|
451
|
+
|
|
452
|
+
function GlassButton({
|
|
453
|
+
label,
|
|
454
|
+
icon,
|
|
455
|
+
onSelect,
|
|
456
|
+
disabled,
|
|
457
|
+
size = 48,
|
|
458
|
+
className,
|
|
459
|
+
}: {
|
|
460
|
+
label: string;
|
|
461
|
+
icon: string;
|
|
462
|
+
onSelect: () => void;
|
|
463
|
+
disabled?: boolean | undefined;
|
|
464
|
+
size?: number;
|
|
465
|
+
className?: string;
|
|
466
|
+
}) {
|
|
467
|
+
return (
|
|
468
|
+
<button
|
|
469
|
+
type="button"
|
|
470
|
+
aria-label={label}
|
|
471
|
+
disabled={disabled}
|
|
472
|
+
onClick={onSelect}
|
|
473
|
+
style={{ width: size, height: size }}
|
|
474
|
+
className={`${glass} mobile-press flex shrink-0 items-center justify-center rounded-full disabled:opacity-40 ${className ?? ''}`}
|
|
475
|
+
>
|
|
476
|
+
<Icon name={icon} size={Math.round(size * 0.46)} />
|
|
477
|
+
</button>
|
|
478
|
+
);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/** The top of a phone screen: on a top screen its large title, left, and its `top` actions in a capsule, right; in an
|
|
482
|
+
* item or a utility screen, Back in a round glass button, the title small and centred, the actions. A desktop view (no phone variant, D4)
|
|
483
|
+
* says so under its title. Nothing draws behind: the screen's own background. */
|
|
484
|
+
function Header({
|
|
485
|
+
shell,
|
|
486
|
+
view,
|
|
487
|
+
title,
|
|
488
|
+
top,
|
|
489
|
+
}: {
|
|
490
|
+
shell: Shell;
|
|
491
|
+
view: View;
|
|
492
|
+
title: string;
|
|
493
|
+
top: readonly MobileAction[];
|
|
494
|
+
}) {
|
|
495
|
+
const { screens } = React.useSyncExternalStore(shell.subscribe, shell.get);
|
|
496
|
+
const { screen } = view;
|
|
497
|
+
const desktop = screen !== undefined && !view.utility && !hasVariant(screens, screen);
|
|
498
|
+
// A utility screen (Settings opened from a prompt) has no bar: Back closes it, back to the view under it.
|
|
499
|
+
const up = parentView(screens, view);
|
|
500
|
+
const back = view.utility !== undefined || (up !== undefined && !desktop);
|
|
501
|
+
const capsule = top.length > 0 && (
|
|
502
|
+
<div className={`${glass} flex h-12 shrink-0 items-center rounded-full px-1`}>
|
|
503
|
+
{top.map((action) => (
|
|
504
|
+
<button
|
|
505
|
+
key={action.id}
|
|
506
|
+
type="button"
|
|
507
|
+
aria-label={action.label}
|
|
508
|
+
disabled={action.disabled}
|
|
509
|
+
onClick={action.onSelect}
|
|
510
|
+
className="mobile-press flex size-11 items-center justify-center rounded-full disabled:opacity-40"
|
|
511
|
+
>
|
|
512
|
+
<Icon name={action.icon} size={22} />
|
|
513
|
+
</button>
|
|
514
|
+
))}
|
|
515
|
+
</div>
|
|
516
|
+
);
|
|
517
|
+
return (
|
|
518
|
+
<header
|
|
519
|
+
data-slot="mobile-header"
|
|
520
|
+
className="relative z-10 shrink-0 px-4 pt-[calc(env(safe-area-inset-top)+0.5rem)] pb-2 [view-transition-name:mobile-header]"
|
|
521
|
+
>
|
|
522
|
+
{back ? (
|
|
523
|
+
<div className="flex h-12 items-center gap-3">
|
|
524
|
+
<GlassButton
|
|
525
|
+
label="Back"
|
|
526
|
+
icon="chevron-left"
|
|
527
|
+
onSelect={() => (view.utility || !up ? shell.closeUtility() : goUp(shell, up))}
|
|
528
|
+
/>
|
|
529
|
+
<h1 className="m-0 min-w-0 flex-1 truncate text-center text-[17px] font-semibold">
|
|
530
|
+
{title}
|
|
531
|
+
</h1>
|
|
532
|
+
{capsule || <span className="size-12 shrink-0" />}
|
|
533
|
+
</div>
|
|
534
|
+
) : (
|
|
535
|
+
<div className="flex min-h-12 items-center gap-3">
|
|
536
|
+
<div className="min-w-0 flex-1">
|
|
537
|
+
<h1 className="m-0 truncate text-[32px] leading-tight font-bold tracking-tight">
|
|
538
|
+
{title}
|
|
539
|
+
</h1>
|
|
540
|
+
{desktop && (
|
|
541
|
+
<p className="m-0 text-xs text-secondary">Desktop view, not made for a phone</p>
|
|
542
|
+
)}
|
|
543
|
+
</div>
|
|
544
|
+
{capsule}
|
|
545
|
+
</div>
|
|
546
|
+
)}
|
|
547
|
+
</header>
|
|
548
|
+
);
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
/** The bar at the bottom of a top screen (iOS 26's floating tab bar; research-020 O5 reopened, owner, 17 October
|
|
552
|
+
* 2026): a glass capsule with the node's first screens that have a phone variant, the one shown lit, and "More",
|
|
553
|
+
* which opens the drawer (every view, the workspaces, the mode); beside it, the screen's `primary` action, round. */
|
|
554
|
+
function BottomBar({ shell, primary }: { shell: Shell; primary: MobileAction | undefined }) {
|
|
555
|
+
const state = React.useSyncExternalStore(shell.subscribe, shell.get);
|
|
556
|
+
const view = viewOf(state);
|
|
557
|
+
const node = view.node;
|
|
558
|
+
const { screens, nodes } = state;
|
|
559
|
+
// The node's blocks as the sidebar lists them (research-067), the first four with a phone variant.
|
|
560
|
+
const laid = screens ? blocksOn(screens, nodes, node) : { top: [], sections: [] };
|
|
561
|
+
const tabs = [...laid.top, ...laid.sections.flatMap((section) => section.blocks)]
|
|
562
|
+
.filter((block) => hasVariant(screens, { plugin: block.plugin, id: block.screen.id }))
|
|
563
|
+
.slice(0, 4);
|
|
564
|
+
return (
|
|
565
|
+
<div
|
|
566
|
+
data-slot="mobile-bottom"
|
|
567
|
+
className="pointer-events-none absolute inset-x-0 bottom-0 flex items-end gap-3 px-4 pb-[max(env(safe-area-inset-bottom),0.75rem)]"
|
|
568
|
+
>
|
|
569
|
+
{/* What scrolls under the bar blurs more the lower it goes (iOS 26's edge): a blurred layer faded out upwards. */}
|
|
570
|
+
<span aria-hidden="true" className="mobile-edge-blur absolute inset-x-0 bottom-0 -z-10" />
|
|
571
|
+
<nav
|
|
572
|
+
aria-label="Screens"
|
|
573
|
+
// Named for the view transitions on the glass itself, not on a parent: an element with a view-transition name
|
|
574
|
+
// is a backdrop root, and the glass inside it would blur nothing.
|
|
575
|
+
className={`${glass} pointer-events-auto flex h-[62px] min-w-0 flex-1 items-center gap-0.5 rounded-full px-1.5 [view-transition-name:mobile-bottom]`}
|
|
576
|
+
>
|
|
577
|
+
{tabs.map((block) => {
|
|
578
|
+
const shown = view.screen?.plugin === block.plugin && view.screen.id === block.screen.id;
|
|
579
|
+
return (
|
|
580
|
+
<button
|
|
581
|
+
key={`${block.plugin} ${block.screen.id}`}
|
|
582
|
+
type="button"
|
|
583
|
+
aria-current={shown ? 'page' : undefined}
|
|
584
|
+
// oxlint-disable-next-line bridge/screen-change-reads-click -- a phone has no ⌘, ⌥ or middle click, nor windows to open beside
|
|
585
|
+
onClick={() => shell.setScreen({ plugin: block.plugin, id: block.screen.id }, node)}
|
|
586
|
+
className="mobile-press mobile-tab relative flex h-[52px] min-w-0 flex-1 flex-col items-center justify-center gap-0.5 rounded-full"
|
|
587
|
+
>
|
|
588
|
+
{/* The lit pill: one named element, so a view transition slides it from the tab left to the tab chosen. */}
|
|
589
|
+
{shown && (
|
|
590
|
+
<span
|
|
591
|
+
aria-hidden="true"
|
|
592
|
+
className="mobile-tab-pill absolute inset-0 rounded-[22px]"
|
|
593
|
+
/>
|
|
594
|
+
)}
|
|
595
|
+
<Icon name={block.screen.icon ?? 'square'} size={22} className="relative" />
|
|
596
|
+
<span className="relative max-w-full truncate px-2 text-[10px] font-medium">
|
|
597
|
+
{block.screen.title}
|
|
598
|
+
</span>
|
|
599
|
+
</button>
|
|
600
|
+
);
|
|
601
|
+
})}
|
|
602
|
+
<button
|
|
603
|
+
type="button"
|
|
604
|
+
aria-label="More"
|
|
605
|
+
onClick={() => drawer.open()}
|
|
606
|
+
className="mobile-press mobile-tab flex h-[52px] min-w-0 flex-1 flex-col items-center justify-center gap-0.5 rounded-full"
|
|
607
|
+
>
|
|
608
|
+
<Icon name="ellipsis" size={22} />
|
|
609
|
+
<span className="text-[10px] font-medium">More</span>
|
|
610
|
+
</button>
|
|
611
|
+
</nav>
|
|
612
|
+
{primary && (
|
|
613
|
+
<GlassButton
|
|
614
|
+
label={primary.label}
|
|
615
|
+
icon={primary.icon}
|
|
616
|
+
onSelect={primary.onSelect}
|
|
617
|
+
disabled={primary.disabled}
|
|
618
|
+
size={62}
|
|
619
|
+
className="pointer-events-auto mobile-primary [view-transition-name:mobile-primary]"
|
|
620
|
+
/>
|
|
621
|
+
)}
|
|
622
|
+
</div>
|
|
623
|
+
);
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
/** A desktop view's title: its screen's (its items' own names, as `plugin:sessions/en/index`, mean nothing here). */
|
|
627
|
+
const desktopTitle = (shell: Shell, view: View) => {
|
|
628
|
+
const { screen } = view;
|
|
629
|
+
const { screens } = shell.get();
|
|
630
|
+
if (!screen || view.utility || !screens || hasVariant(screens, screen)) return undefined;
|
|
631
|
+
return pathTo(screens, screen).at(-1)?.title;
|
|
632
|
+
};
|
|
633
|
+
|
|
634
|
+
/** A screen's frame on the phone: the header, the screen (it scrolls alone), and on a top screen the bottom bar floating
|
|
635
|
+
* over it; with no screen chosen, the workspace's home (its views). `--mobile-inset-bottom`: how much of the screen's
|
|
636
|
+
* bottom the bar covers, for its scrolling list's last rows (`padding-bottom`). */
|
|
637
|
+
function MobileWindow({ shell, view, window, body }: { shell: Shell; view: View } & Parts) {
|
|
638
|
+
const home = view.screen === undefined && view.utility === undefined;
|
|
639
|
+
const title = home
|
|
640
|
+
? (shell.get().current?.title ?? 'Bridge')
|
|
641
|
+
: (desktopTitle(shell, view) ?? window['aria-label']);
|
|
642
|
+
const list = useActions(view.utility ? undefined : view.screen);
|
|
643
|
+
const top = list.filter((action) => (action.placement ?? 'top') === 'top');
|
|
644
|
+
const primary = list.find((action) => action.placement === 'primary');
|
|
645
|
+
const { screens } = React.useSyncExternalStore(shell.subscribe, shell.get);
|
|
646
|
+
// On a top screen, and on a desktop view whatever it shows (its items are its own: the bar is its way out).
|
|
647
|
+
const desktop = view.screen !== undefined && !hasVariant(screens, view.screen);
|
|
648
|
+
const hidden = React.useSyncExternalStore(barless.subscribe, barless.get);
|
|
649
|
+
const bar =
|
|
650
|
+
!view.utility &&
|
|
651
|
+
(view.item === undefined || desktop) &&
|
|
652
|
+
!(view.screen && hidden.has(keyOf(view.screen)));
|
|
653
|
+
return (
|
|
654
|
+
<div
|
|
655
|
+
{...window}
|
|
656
|
+
data-mobile=""
|
|
657
|
+
style={
|
|
658
|
+
{
|
|
659
|
+
'--mobile-inset-bottom': bar
|
|
660
|
+
? 'calc(max(env(safe-area-inset-bottom), 0.75rem) + 74px)'
|
|
661
|
+
: 'env(safe-area-inset-bottom)',
|
|
662
|
+
} as React.CSSProperties
|
|
663
|
+
}
|
|
664
|
+
className="relative flex min-h-0 min-w-0 flex-1 flex-col bg-background"
|
|
665
|
+
>
|
|
666
|
+
<Header shell={shell} view={view} title={title} top={top} />
|
|
667
|
+
<div className="flex min-h-0 flex-1 flex-col bg-background [view-transition-name:mobile-screen]">
|
|
668
|
+
{home ? (
|
|
669
|
+
<div className="min-h-0 flex-1 overflow-y-auto pt-1 pb-(--mobile-inset-bottom)">
|
|
670
|
+
<Views shell={shell} />
|
|
671
|
+
</div>
|
|
672
|
+
) : (
|
|
673
|
+
body
|
|
674
|
+
)}
|
|
675
|
+
</div>
|
|
676
|
+
{bar && <BottomBar shell={shell} primary={primary} />}
|
|
677
|
+
</div>
|
|
678
|
+
);
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
export const mobileFrame = (shell: Shell, view: View) => (parts: Parts) => (
|
|
682
|
+
<MobileWindow shell={shell} view={view} {...parts} />
|
|
683
|
+
);
|
|
684
|
+
|
|
685
|
+
/** The views the shell knows of, by plugin key then screen id (`ctx.sidebar.items`, the boot kernel's), set by `apply`:
|
|
686
|
+
* the items a plugin lists under its screens, and its choices of destinations (`navigation`). */
|
|
687
|
+
const noItems = new Map();
|
|
688
|
+
let sidebarItems: Context['sidebarItems'] = {
|
|
689
|
+
get: () => noItems,
|
|
690
|
+
subscribe: () => () => {},
|
|
691
|
+
navigation: { get: () => noItems, subscribe: () => () => {} },
|
|
692
|
+
};
|
|
693
|
+
export const setSidebarItems = (service: Context['sidebarItems']) => {
|
|
694
|
+
sidebarItems = service;
|
|
695
|
+
};
|
|
696
|
+
function useSidebarItems() {
|
|
697
|
+
React.useSyncExternalStore(sidebarItems.subscribe, sidebarItems.get);
|
|
698
|
+
React.useSyncExternalStore(sidebarItems.navigation.subscribe, sidebarItems.navigation.get);
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
type ScreenNode = ReturnType<Shell['get']>['path'][number];
|
|
702
|
+
type Item = { id: string; title: string; icon?: string; children?: readonly Item[] };
|
|
703
|
+
/** A row of the menu under node `node`, as the sidebar has it (research-067): a view or one of its child screens, or
|
|
704
|
+
* (`item`) an item its plugin lists under that screen. */
|
|
705
|
+
type Entry = { plugin: string; screen: ScreenNode; node: string; item?: Item };
|
|
706
|
+
const entryKey = (entry: Entry) => `${entry.plugin} ${entry.screen.id} ${entry.item?.id ?? ''}`;
|
|
707
|
+
const entryTitle = (entry: Entry) => entry.item?.title ?? entry.screen.title;
|
|
708
|
+
const entryIcon = (entry: Entry) =>
|
|
709
|
+
entry.item ? (entry.item.icon ?? 'book-open') : (entry.screen.icon ?? 'square');
|
|
710
|
+
/** What is under `entry`, as the sidebar shows it: a screen's choice of destinations (`navigation`, when more than
|
|
711
|
+
* one), else its child screens then its items; an item's children. */
|
|
712
|
+
// ponytail: every item at once, where the sidebar shows ten then "More…"; fold them when a plugin lists hundreds.
|
|
713
|
+
const below = (entry: Entry): Entry[] => {
|
|
714
|
+
const at = (item: Item): Entry => ({ ...entry, item });
|
|
715
|
+
if (entry.item) return (entry.item.children ?? []).map(at);
|
|
716
|
+
const choices = sidebarItems.navigation
|
|
717
|
+
.get()
|
|
718
|
+
.get(entry.plugin)
|
|
719
|
+
?.get(JSON.stringify([entry.screen.id, entry.node]))?.items;
|
|
720
|
+
if (choices)
|
|
721
|
+
return choices.length > 1
|
|
722
|
+
? choices.map(({ id, title, icon }) => at({ id, title, ...(icon !== undefined && { icon }) }))
|
|
723
|
+
: [];
|
|
724
|
+
return [
|
|
725
|
+
...(entry.screen.children ?? []).map((screen): Entry => ({
|
|
726
|
+
plugin: entry.plugin,
|
|
727
|
+
screen,
|
|
728
|
+
node: entry.node,
|
|
729
|
+
})),
|
|
730
|
+
...(sidebarItems.get().get(entry.plugin)?.get(entry.screen.id) ?? []).map(at),
|
|
731
|
+
];
|
|
732
|
+
};
|
|
733
|
+
/** A screen's only destination (`navigation` with one choice, listed under it as nothing): the sidebar opens the screen
|
|
734
|
+
* on it, so does the menu. */
|
|
735
|
+
const soleChoice = (entry: Entry): Item | undefined => {
|
|
736
|
+
const choices = sidebarItems.navigation
|
|
737
|
+
.get()
|
|
738
|
+
.get(entry.plugin)
|
|
739
|
+
?.get(JSON.stringify([entry.screen.id, entry.node]))?.items;
|
|
740
|
+
return choices?.length === 1 ? { id: choices[0]!.id, title: choices[0]!.title } : undefined;
|
|
741
|
+
};
|
|
742
|
+
/** Opens `entry` as iOS opens a deep link: through each level above it not shown yet (its parent screens, its parent
|
|
743
|
+
* items), one history entry each, so Back (the button, the swipe) goes up the tree, not to the screen before. */
|
|
744
|
+
export const openEntry = (shell: Shell, entry: Entry) => {
|
|
745
|
+
const { plugin, screen, node } = entry;
|
|
746
|
+
const item = entry.item ?? soleChoice(entry);
|
|
747
|
+
const { screens } = shell.get();
|
|
748
|
+
const chain: View[] = [
|
|
749
|
+
{ node, screen: { plugin, id: screen.id }, ...(item && { item: item.id }) },
|
|
750
|
+
];
|
|
751
|
+
for (let up = parentView(screens, chain[0]!); up; up = parentView(screens, up)) chain.unshift(up);
|
|
752
|
+
const shown = viewKey(shell.get());
|
|
753
|
+
const from = chain.findIndex((view) => viewKey(view) === shown);
|
|
754
|
+
for (const view of chain.slice(from + 1)) show(shell, view);
|
|
755
|
+
};
|
|
756
|
+
/** Whether the view shown is `entry` (an item: it or one under it). */
|
|
757
|
+
const shows = (view: View, { plugin, screen, node, item }: Entry) =>
|
|
758
|
+
view.node === node &&
|
|
759
|
+
view.screen?.plugin === plugin &&
|
|
760
|
+
view.screen.id === screen.id &&
|
|
761
|
+
(!item || view.item === item.id || !!view.item?.startsWith(`${item.id}/`));
|
|
762
|
+
/** Whether the view shown is under `entry`: one of its child screens, or one of its items. */
|
|
763
|
+
const holds = (state: ReturnType<Shell['get']>, entry: Entry) => {
|
|
764
|
+
const view = viewOf(state);
|
|
765
|
+
if (view.node !== entry.node || view.screen?.plugin !== entry.plugin) return false;
|
|
766
|
+
if (entry.item)
|
|
767
|
+
return view.screen.id === entry.screen.id && !!view.item?.startsWith(`${entry.item.id}/`);
|
|
768
|
+
if (view.screen.id === entry.screen.id) return view.item !== undefined;
|
|
769
|
+
return (
|
|
770
|
+
!!state.screens &&
|
|
771
|
+
pathTo(state.screens, view.screen).some((each) => each.id === entry.screen.id)
|
|
772
|
+
);
|
|
773
|
+
};
|
|
774
|
+
const desktopEntry = (screens: ReturnType<Shell['get']>['screens'], entry: Entry) =>
|
|
775
|
+
!entry.item && !hasVariant(screens, { plugin: entry.plugin, id: entry.screen.id });
|
|
776
|
+
|
|
777
|
+
/** A row of the `pages` menu (and the home's): a tap opens it, or with `push` and rows under it, its page (`›`). */
|
|
778
|
+
function EntryRow({
|
|
779
|
+
shell,
|
|
780
|
+
entry,
|
|
781
|
+
go,
|
|
782
|
+
push,
|
|
783
|
+
}: {
|
|
784
|
+
shell: Shell;
|
|
785
|
+
entry: Entry;
|
|
786
|
+
go: (action: () => void) => void;
|
|
787
|
+
push?: ((entry: Entry) => void) | undefined;
|
|
788
|
+
}) {
|
|
789
|
+
const state = React.useSyncExternalStore(shell.subscribe, shell.get);
|
|
790
|
+
useSidebarItems();
|
|
791
|
+
const deeper = push && below(entry).length > 0;
|
|
792
|
+
return (
|
|
793
|
+
<button
|
|
794
|
+
type="button"
|
|
795
|
+
aria-current={shows(viewOf(state), entry) ? 'page' : undefined}
|
|
796
|
+
onClick={() => (deeper ? push(entry) : go(() => openEntry(shell, entry)))}
|
|
797
|
+
className="flex min-h-12 items-center gap-3 rounded-lg px-2 text-left text-[16px] active:bg-hover aria-[current=page]:bg-selected"
|
|
798
|
+
>
|
|
799
|
+
<Icon name={entryIcon(entry)} size={20} />
|
|
800
|
+
<span className="min-w-0 flex-1 truncate">{entryTitle(entry)}</span>
|
|
801
|
+
{desktopEntry(state.screens, entry) && <DesktopMark />}
|
|
802
|
+
{deeper && <Icon name="chevron-right" size={18} className="shrink-0 text-secondary" />}
|
|
803
|
+
</button>
|
|
804
|
+
);
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
/** A row of the `tree` menu: a tap opens it, its triangle unfolds the rows under it; unfolded at first when the view
|
|
808
|
+
* shown is under it. */
|
|
809
|
+
function EntryTree({
|
|
810
|
+
shell,
|
|
811
|
+
entry,
|
|
812
|
+
depth,
|
|
813
|
+
go,
|
|
814
|
+
}: {
|
|
815
|
+
shell: Shell;
|
|
816
|
+
entry: Entry;
|
|
817
|
+
depth: number;
|
|
818
|
+
go: (action: () => void) => void;
|
|
819
|
+
}) {
|
|
820
|
+
const state = React.useSyncExternalStore(shell.subscribe, shell.get);
|
|
821
|
+
useSidebarItems();
|
|
822
|
+
const [open, setOpen] = React.useState(() => holds(state, entry));
|
|
823
|
+
const kids = below(entry);
|
|
824
|
+
return (
|
|
825
|
+
<SidebarTreeItem
|
|
826
|
+
guide
|
|
827
|
+
label={entryTitle(entry)}
|
|
828
|
+
icon={<Icon name={entryIcon(entry)} size={18} />}
|
|
829
|
+
depth={depth}
|
|
830
|
+
className="h-11 text-[16px]"
|
|
831
|
+
active={shows(viewOf(state), entry) && !holds(state, entry)}
|
|
832
|
+
expanded={kids.length ? open : undefined}
|
|
833
|
+
onExpandedChange={setOpen}
|
|
834
|
+
trailing={desktopEntry(state.screens, entry) ? <DesktopMark /> : undefined}
|
|
835
|
+
onSelect={() => go(() => openEntry(shell, entry))}
|
|
836
|
+
>
|
|
837
|
+
{kids.length
|
|
838
|
+
? kids.map((kid) => (
|
|
839
|
+
<EntryTree key={entryKey(kid)} shell={shell} entry={kid} depth={depth + 1} go={go} />
|
|
840
|
+
))
|
|
841
|
+
: undefined}
|
|
842
|
+
</SidebarTreeItem>
|
|
843
|
+
);
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
/** Node `node`'s blocks as the sidebar lists them (research-067), as rows: above the sections, then root's sections. */
|
|
847
|
+
const entriesOn = (state: ReturnType<Shell['get']>, node: string) => {
|
|
848
|
+
const { screens, nodes } = state;
|
|
849
|
+
const laid = screens ? blocksOn(screens, nodes, node) : undefined;
|
|
850
|
+
const entries = (blocks: NonNullable<ReturnType<Shell['get']>['screens']>['root']) =>
|
|
851
|
+
blocks.map((block): Entry => ({ plugin: block.plugin, screen: block.screen, node }));
|
|
852
|
+
return laid
|
|
853
|
+
? [
|
|
854
|
+
{ id: '', title: '', entries: entries(laid.top) },
|
|
855
|
+
...laid.sections.map((section) => ({
|
|
856
|
+
id: section.id,
|
|
857
|
+
title: section.title,
|
|
858
|
+
entries: entries(section.blocks),
|
|
859
|
+
})),
|
|
860
|
+
].filter((group) => group.entries.length > 0)
|
|
861
|
+
: [];
|
|
862
|
+
};
|
|
863
|
+
|
|
864
|
+
/** The node's views, grouped as the sidebar groups them (its sections): rows (`EntryRow`), or with `style` `tree` a tree
|
|
865
|
+
* (`EntryTree`). */
|
|
866
|
+
function Views({
|
|
867
|
+
shell,
|
|
868
|
+
node: chosen,
|
|
869
|
+
style,
|
|
870
|
+
push,
|
|
871
|
+
go = (action) => action(),
|
|
872
|
+
}: {
|
|
873
|
+
shell: Shell;
|
|
874
|
+
/** The node whose views these are; the one shown by default. */
|
|
875
|
+
node?: string;
|
|
876
|
+
style?: MenuStyle;
|
|
877
|
+
push?: (entry: Entry) => void;
|
|
878
|
+
go?: (action: () => void) => void;
|
|
879
|
+
}) {
|
|
880
|
+
const state = React.useSyncExternalStore(shell.subscribe, shell.get);
|
|
881
|
+
const view = viewOf(state);
|
|
882
|
+
const node = chosen ?? view.utility?.node ?? view.node;
|
|
883
|
+
return entriesOn(state, node).map((group) => (
|
|
884
|
+
<nav key={group.id} aria-label={group.title || 'Views'} className="flex flex-col px-2 pb-2">
|
|
885
|
+
{group.title && (
|
|
886
|
+
<h2 className="m-0 px-2 pt-3 pb-1 text-xs font-medium tracking-wide text-secondary uppercase">
|
|
887
|
+
{group.title}
|
|
888
|
+
</h2>
|
|
889
|
+
)}
|
|
890
|
+
{style === 'tree' ? (
|
|
891
|
+
<SidebarTree variant="navigation" indent={24} aria-label={group.title || 'Views'}>
|
|
892
|
+
{group.entries.map((entry) => (
|
|
893
|
+
<EntryTree key={entryKey(entry)} shell={shell} entry={entry} depth={0} go={go} />
|
|
894
|
+
))}
|
|
895
|
+
</SidebarTree>
|
|
896
|
+
) : (
|
|
897
|
+
group.entries.map((entry) => (
|
|
898
|
+
<EntryRow key={entryKey(entry)} shell={shell} entry={entry} go={go} push={push} />
|
|
899
|
+
))
|
|
900
|
+
)}
|
|
901
|
+
</nav>
|
|
902
|
+
));
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
const modes = [
|
|
906
|
+
{ id: 'light', label: 'Light' },
|
|
907
|
+
{ id: 'dark', label: 'Dark' },
|
|
908
|
+
{ id: 'system', label: 'System' },
|
|
909
|
+
] as const;
|
|
910
|
+
|
|
911
|
+
/** This device's text size on a phone (Look's `phoneTextSize`, a client preference): the kit's text steps follow it
|
|
912
|
+
* (./mobile.css `--phone-text`). Unset or out of its range: 16, a phone's body. */
|
|
913
|
+
const textSizes = { min: 11, max: 22, unset: 16 };
|
|
914
|
+
const textSizeOf = (value: unknown) =>
|
|
915
|
+
typeof value === 'number' && value >= textSizes.min && value <= textSizes.max
|
|
916
|
+
? Math.round(value)
|
|
917
|
+
: textSizes.unset;
|
|
918
|
+
|
|
919
|
+
/** The text size, set in the phone menu: the size moved shows at once, kept once the thumb is let go. */
|
|
920
|
+
export function TextSize({ size }: { size: number }) {
|
|
921
|
+
const [shown, setShown] = React.useState(size);
|
|
922
|
+
React.useEffect(() => setShown(size), [size]);
|
|
923
|
+
React.useEffect(() => {
|
|
924
|
+
document.documentElement.style.setProperty('--phone-text', `${shown}px`);
|
|
925
|
+
}, [shown]);
|
|
926
|
+
// Closed with a size moved but not let go (Back mid-drag): the page goes back to the size kept, unless the frame
|
|
927
|
+
// left with it (its own cleanup already dropped the size).
|
|
928
|
+
const kept = React.useRef(size);
|
|
929
|
+
kept.current = size;
|
|
930
|
+
React.useEffect(
|
|
931
|
+
() => () => {
|
|
932
|
+
const root = document.documentElement.style;
|
|
933
|
+
if (root.getPropertyValue('--phone-text'))
|
|
934
|
+
root.setProperty('--phone-text', `${kept.current}px`);
|
|
935
|
+
},
|
|
936
|
+
[],
|
|
937
|
+
);
|
|
938
|
+
return (
|
|
939
|
+
<div className="flex flex-col gap-1 pb-3">
|
|
940
|
+
<div className="flex items-baseline justify-between">
|
|
941
|
+
<span id="phone-text-size" className="text-sm">
|
|
942
|
+
Text size
|
|
943
|
+
</span>
|
|
944
|
+
<span className="text-xs text-secondary tabular-nums">{shown} px</span>
|
|
945
|
+
</div>
|
|
946
|
+
<div className="flex items-center gap-3">
|
|
947
|
+
<span aria-hidden="true" className="text-[13px] text-secondary">
|
|
948
|
+
A
|
|
949
|
+
</span>
|
|
950
|
+
<Slider
|
|
951
|
+
aria-labelledby="phone-text-size"
|
|
952
|
+
min={textSizes.min}
|
|
953
|
+
max={textSizes.max}
|
|
954
|
+
step={1}
|
|
955
|
+
value={shown}
|
|
956
|
+
onValueChange={setShown}
|
|
957
|
+
onValueCommitted={(next) => {
|
|
958
|
+
const report = (error: unknown) => console.error('phone text size not kept:', error);
|
|
959
|
+
void setPreference('phoneTextSize', next === textSizes.unset ? undefined : next)
|
|
960
|
+
.then((error) => error && report(error))
|
|
961
|
+
.catch(report);
|
|
962
|
+
}}
|
|
963
|
+
/>
|
|
964
|
+
<span aria-hidden="true" className="text-[22px] text-secondary">
|
|
965
|
+
A
|
|
966
|
+
</span>
|
|
967
|
+
</div>
|
|
968
|
+
</div>
|
|
969
|
+
);
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
/** The part of the page the user sees (`visualViewport`): on iOS the keyboard covers the bottom of a fixed layout without
|
|
973
|
+
* resizing it, so the frame takes this height and top, and a prompt at the bottom of a screen stays above the
|
|
974
|
+
* keyboard. Absent (an older browser): the whole window. */
|
|
975
|
+
function useVisibleBox() {
|
|
976
|
+
const [box, setBox] = React.useState<{ height: number; top: number }>();
|
|
977
|
+
React.useEffect(() => {
|
|
978
|
+
const viewport = window.visualViewport;
|
|
979
|
+
if (!viewport) return;
|
|
980
|
+
const follow = () => setBox({ height: viewport.height, top: viewport.offsetTop });
|
|
981
|
+
follow();
|
|
982
|
+
viewport.addEventListener('resize', follow);
|
|
983
|
+
viewport.addEventListener('scroll', follow);
|
|
984
|
+
return () => {
|
|
985
|
+
viewport.removeEventListener('resize', follow);
|
|
986
|
+
viewport.removeEventListener('scroll', follow);
|
|
987
|
+
};
|
|
988
|
+
}, []);
|
|
989
|
+
return box;
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
/** The phone's frame: the current screen, full screen (`main`), and the drawer the burger opens. */
|
|
993
|
+
export function MobileFrame({
|
|
994
|
+
shell,
|
|
995
|
+
renderSlot,
|
|
996
|
+
}: {
|
|
997
|
+
shell: Shell;
|
|
998
|
+
renderSlot: (key: 'main', props: object) => React.ReactNode;
|
|
999
|
+
}) {
|
|
1000
|
+
const open = React.useSyncExternalStore(drawer.subscribe, drawer.get);
|
|
1001
|
+
const style = React.useSyncExternalStore(menuStyle.subscribe, menuStyle.get);
|
|
1002
|
+
const { current, workspaces } = React.useSyncExternalStore(shell.subscribe, shell.get);
|
|
1003
|
+
const mode = React.useSyncExternalStore(
|
|
1004
|
+
subscribeClientAppearance,
|
|
1005
|
+
() => getClientAppearance().prefs.mode ?? 'system',
|
|
1006
|
+
);
|
|
1007
|
+
const textSize = React.useSyncExternalStore(subscribeClientAppearance, () =>
|
|
1008
|
+
textSizeOf(getClientAppearance().prefs.phoneTextSize),
|
|
1009
|
+
);
|
|
1010
|
+
React.useEffect(() => {
|
|
1011
|
+
const root = document.documentElement.style;
|
|
1012
|
+
root.setProperty('--phone-text', `${textSize}px`);
|
|
1013
|
+
return () => {
|
|
1014
|
+
root.removeProperty('--phone-text');
|
|
1015
|
+
};
|
|
1016
|
+
}, [textSize]);
|
|
1017
|
+
const box = useVisibleBox();
|
|
1018
|
+
// The home screen app opens at the Bridge's root (its manifest's `start_url`): there, the workspace used last on this
|
|
1019
|
+
// phone rather than the first one; each workspace shown is remembered.
|
|
1020
|
+
const slug = current?.slug;
|
|
1021
|
+
React.useEffect(() => {
|
|
1022
|
+
if (slug === undefined) return;
|
|
1023
|
+
let last: string | null = null;
|
|
1024
|
+
try {
|
|
1025
|
+
last = localStorage.getItem(lastKey);
|
|
1026
|
+
} catch {
|
|
1027
|
+
/* none */
|
|
1028
|
+
}
|
|
1029
|
+
if (
|
|
1030
|
+
location.pathname === '/' &&
|
|
1031
|
+
last &&
|
|
1032
|
+
last !== slug &&
|
|
1033
|
+
workspaces.some((each) => each.slug === last)
|
|
1034
|
+
) {
|
|
1035
|
+
shell.setCurrent(last);
|
|
1036
|
+
history.replaceState(history.state, '', `/${last}/`);
|
|
1037
|
+
return;
|
|
1038
|
+
}
|
|
1039
|
+
try {
|
|
1040
|
+
localStorage.setItem(lastKey, slug);
|
|
1041
|
+
} catch {
|
|
1042
|
+
/* not kept */
|
|
1043
|
+
}
|
|
1044
|
+
}, [slug, workspaces.length]);
|
|
1045
|
+
return (
|
|
1046
|
+
<div
|
|
1047
|
+
data-slot="shell"
|
|
1048
|
+
data-mobile=""
|
|
1049
|
+
style={box && { height: box.height, top: box.top, bottom: 'auto' }}
|
|
1050
|
+
className="fixed inset-0 flex flex-col overflow-hidden bg-background text-foreground antialiased"
|
|
1051
|
+
>
|
|
1052
|
+
<main data-slot="shell-stage" className="flex min-h-0 flex-1 flex-col">
|
|
1053
|
+
{renderSlot('main', {})}
|
|
1054
|
+
</main>
|
|
1055
|
+
<Dialog open={open} onOpenChange={(next) => (next ? drawer.open() : drawer.close())}>
|
|
1056
|
+
<DialogContent
|
|
1057
|
+
// The floating panel: no dimmed screen behind it, its glass over the screen as it is (a tap outside still closes).
|
|
1058
|
+
backdropClassName={style === 'tree' ? 'bg-transparent' : ''}
|
|
1059
|
+
className={
|
|
1060
|
+
style === 'tree'
|
|
1061
|
+
? // A floating glass panel over the bottom bar, grown from it (./mobile.css `.mobile-panel`): the screen still shows around it.
|
|
1062
|
+
'mobile-drawer mobile-panel top-auto right-2 bottom-[calc(env(safe-area-inset-bottom)+0.5rem)] left-2 flex max-h-[85dvh] w-auto max-w-none translate-x-0 translate-y-0 flex-col overflow-hidden rounded-3xl p-0'
|
|
1063
|
+
: 'mobile-drawer top-0 left-0 h-full max-h-none w-full max-w-none translate-x-0 translate-y-0 rounded-none pt-[env(safe-area-inset-top)] pb-[env(safe-area-inset-bottom)] pr-[env(safe-area-inset-right)] pl-[env(safe-area-inset-left)] transition-transform duration-300 ease-out data-[ending-style]:-translate-x-full data-[starting-style]:-translate-x-full'
|
|
1064
|
+
}
|
|
1065
|
+
>
|
|
1066
|
+
<Menu shell={shell} style={style} />
|
|
1067
|
+
{/* Inside the drawer: dialogs of their own, nested, so a tap in them does not close the drawer. */}
|
|
1068
|
+
{style === 'tree' && <WorkspaceSheet shell={shell} />}
|
|
1069
|
+
<PhoneSettings textSize={textSize} mode={mode} style={style} />
|
|
1070
|
+
</DialogContent>
|
|
1071
|
+
</Dialog>
|
|
1072
|
+
</div>
|
|
1073
|
+
);
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
/** A view of the menu with no phone variant: it opens its desktop screen. */
|
|
1077
|
+
function DesktopMark() {
|
|
1078
|
+
return (
|
|
1079
|
+
<span className="flex shrink-0 items-center text-secondary">
|
|
1080
|
+
<Icon name="smartphone-off" size={14} />
|
|
1081
|
+
<span className="sr-only">Desktop view</span>
|
|
1082
|
+
</span>
|
|
1083
|
+
);
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
/** A row of the menu that opens a page: its icon, its title, a `›`. */
|
|
1087
|
+
function PageRow({ icon, title, onSelect }: { icon: string; title: string; onSelect: () => void }) {
|
|
1088
|
+
return (
|
|
1089
|
+
<button
|
|
1090
|
+
type="button"
|
|
1091
|
+
onClick={onSelect}
|
|
1092
|
+
className="flex min-h-12 items-center gap-3 rounded-lg px-2 text-left text-[16px] active:bg-hover"
|
|
1093
|
+
>
|
|
1094
|
+
<Icon name={icon} size={20} />
|
|
1095
|
+
<span className="min-w-0 flex-1 truncate">{title}</span>
|
|
1096
|
+
<Icon name="chevron-right" size={18} className="shrink-0 text-secondary" />
|
|
1097
|
+
</button>
|
|
1098
|
+
);
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
/** A page of the `pages` menu: a node's (its views, then its child nodes), or a row's (it, then the rows under it). */
|
|
1102
|
+
type Page = { node: string } | { entry: Entry };
|
|
1103
|
+
|
|
1104
|
+
/** The drawer's content: with `pages`, a page (a node's views, then its child nodes; a view's rows under it), each
|
|
1105
|
+
* row with rows under it opening its own page in the drawer, Back going up one; with `tree`, the node's views as a
|
|
1106
|
+
* tree and a row opening the tree's page. The workspaces. It opens on the node shown. */
|
|
1107
|
+
function Menu({ shell, style }: { shell: Shell; style: MenuStyle }) {
|
|
1108
|
+
const state = React.useSyncExternalStore(shell.subscribe, shell.get);
|
|
1109
|
+
useSidebarItems();
|
|
1110
|
+
const { current, nodes } = state;
|
|
1111
|
+
// Admin is the header's settings button, as the rail's; the others are listed.
|
|
1112
|
+
const admin = state.workspaces.find((each) => each.slug === 'admin');
|
|
1113
|
+
const workspaces = state.workspaces.filter((each) => each.slug !== 'admin');
|
|
1114
|
+
// Another workspace to go to (from Admin, the only one there is).
|
|
1115
|
+
const elsewhere = workspaces.some((each) => each.slug !== current?.slug);
|
|
1116
|
+
const view = viewOf(state);
|
|
1117
|
+
const shown = view.utility?.node ?? view.node;
|
|
1118
|
+
// Mounted at each opening (the dialog drops its content closed): back on the node shown.
|
|
1119
|
+
const [pages, setPages] = React.useState<Page[]>([{ node: shown }]);
|
|
1120
|
+
const [direction, setDirection] = React.useState<'push' | 'pop'>();
|
|
1121
|
+
// As the desktop sidebar (`tree`): the workspace's views, then its node tree.
|
|
1122
|
+
const page: Page = style === 'pages' ? pages.at(-1)! : { node: 'root' };
|
|
1123
|
+
const nodeTitle = (id: string) =>
|
|
1124
|
+
id === 'root'
|
|
1125
|
+
? (current?.title ?? 'Bridge')
|
|
1126
|
+
: (nodes?.nodes.find((each) => each.id === id)?.title ?? id);
|
|
1127
|
+
const titleOf = (each: Page) => ('node' in each ? nodeTitle(each.node) : entryTitle(each.entry));
|
|
1128
|
+
const parentOf = (id: string) =>
|
|
1129
|
+
id === 'root' ? undefined : (nodes?.nodes.find((each) => each.id === id)?.parent ?? 'root');
|
|
1130
|
+
// Back: the page this one was opened from, else the node's parent.
|
|
1131
|
+
const above: Page | undefined =
|
|
1132
|
+
pages.length > 1
|
|
1133
|
+
? pages.at(-2)
|
|
1134
|
+
: 'node' in page && parentOf(page.node) !== undefined
|
|
1135
|
+
? { node: parentOf(page.node)! }
|
|
1136
|
+
: undefined;
|
|
1137
|
+
const push = (next: Page) => {
|
|
1138
|
+
setDirection('push');
|
|
1139
|
+
setPages((was) => [...was, next]);
|
|
1140
|
+
};
|
|
1141
|
+
const pop = () => {
|
|
1142
|
+
setDirection('pop');
|
|
1143
|
+
setPages((was) => (was.length > 1 ? was.slice(0, -1) : above ? [above] : was));
|
|
1144
|
+
};
|
|
1145
|
+
const back = style === 'pages' && above !== undefined;
|
|
1146
|
+
const kids = 'node' in page ? childrenOf(nodes, page.node, shown) : [];
|
|
1147
|
+
const iconButton =
|
|
1148
|
+
'mobile-press flex size-11 shrink-0 items-center justify-center rounded-full text-secondary active:bg-hover';
|
|
1149
|
+
return (
|
|
1150
|
+
<div
|
|
1151
|
+
data-mobile=""
|
|
1152
|
+
// The header over the list, which scrolls under it and fades out there (./mobile.css `.mobile-menu-page`).
|
|
1153
|
+
className="mobile-menu relative flex h-full min-h-0 flex-1 flex-col overflow-hidden"
|
|
1154
|
+
>
|
|
1155
|
+
<div className="absolute inset-x-0 top-0 z-10 flex h-13 items-center gap-1 pr-2 pl-4">
|
|
1156
|
+
{back ? (
|
|
1157
|
+
<button
|
|
1158
|
+
type="button"
|
|
1159
|
+
onClick={pop}
|
|
1160
|
+
className="mobile-press -ml-2 flex h-11 min-w-0 flex-1 items-center gap-0.5 text-[17px] text-accent"
|
|
1161
|
+
>
|
|
1162
|
+
<Icon name="chevron-left" size={24} className="shrink-0" />
|
|
1163
|
+
<span className="truncate">{titleOf(above)}</span>
|
|
1164
|
+
</button>
|
|
1165
|
+
) : style === 'tree' && elsewhere ? (
|
|
1166
|
+
<DialogTitle className="m-0 min-w-0 flex-1">
|
|
1167
|
+
<button
|
|
1168
|
+
type="button"
|
|
1169
|
+
onClick={workspaceSheet.open}
|
|
1170
|
+
className="mobile-press flex max-w-full items-center gap-1 text-[22px]"
|
|
1171
|
+
>
|
|
1172
|
+
<span className="truncate">{current?.title ?? 'Bridge'}</span>
|
|
1173
|
+
<Icon name="chevrons-up-down" size={18} className="shrink-0 text-secondary" />
|
|
1174
|
+
</button>
|
|
1175
|
+
</DialogTitle>
|
|
1176
|
+
) : (
|
|
1177
|
+
<DialogTitle className="min-w-0 flex-1 truncate text-[22px]">{titleOf(page)}</DialogTitle>
|
|
1178
|
+
)}
|
|
1179
|
+
<button
|
|
1180
|
+
type="button"
|
|
1181
|
+
aria-label="Phone settings"
|
|
1182
|
+
onClick={settingsSheet.open}
|
|
1183
|
+
className={iconButton}
|
|
1184
|
+
>
|
|
1185
|
+
<Icon name="settings-2" size={22} />
|
|
1186
|
+
</button>
|
|
1187
|
+
{admin !== undefined && (
|
|
1188
|
+
<button
|
|
1189
|
+
type="button"
|
|
1190
|
+
aria-label={admin.title}
|
|
1191
|
+
aria-current={current?.slug === admin.slug ? 'page' : undefined}
|
|
1192
|
+
// The panel stays open on Admin; the pages close, as on their other workspace changes (their pages are
|
|
1193
|
+
// the workspace's).
|
|
1194
|
+
onClick={() =>
|
|
1195
|
+
drawer[style === 'tree' ? 'stay' : 'close'](() => switchTo(shell, admin.slug))
|
|
1196
|
+
}
|
|
1197
|
+
className={iconButton}
|
|
1198
|
+
>
|
|
1199
|
+
<Icon name="settings" size={22} />
|
|
1200
|
+
</button>
|
|
1201
|
+
)}
|
|
1202
|
+
{/* Full screen, the drawer has no outside to tap: it closes here, or with Back. */}
|
|
1203
|
+
<button
|
|
1204
|
+
type="button"
|
|
1205
|
+
aria-label="Close"
|
|
1206
|
+
onClick={() => drawer.close()}
|
|
1207
|
+
className={iconButton}
|
|
1208
|
+
>
|
|
1209
|
+
<Icon name="x" size={22} />
|
|
1210
|
+
</button>
|
|
1211
|
+
</div>
|
|
1212
|
+
<div
|
|
1213
|
+
key={'node' in page ? page.node : entryKey(page.entry)}
|
|
1214
|
+
data-direction={direction}
|
|
1215
|
+
className="mobile-menu-page min-h-0 flex-1 overflow-y-auto overscroll-contain pt-13 pb-4"
|
|
1216
|
+
>
|
|
1217
|
+
{back && (
|
|
1218
|
+
<DialogTitle className="m-0 truncate px-4 pb-2 text-[28px] leading-tight font-bold tracking-tight">
|
|
1219
|
+
{titleOf(page)}
|
|
1220
|
+
</DialogTitle>
|
|
1221
|
+
)}
|
|
1222
|
+
{'entry' in page ? (
|
|
1223
|
+
// The row itself first (its screen, its item), then the rows under it.
|
|
1224
|
+
<nav aria-label={entryTitle(page.entry)} className="flex flex-col px-2 pb-2">
|
|
1225
|
+
<EntryRow shell={shell} entry={page.entry} go={drawer.close} />
|
|
1226
|
+
{below(page.entry).map((entry) => (
|
|
1227
|
+
<EntryRow
|
|
1228
|
+
key={entryKey(entry)}
|
|
1229
|
+
shell={shell}
|
|
1230
|
+
entry={entry}
|
|
1231
|
+
go={drawer.close}
|
|
1232
|
+
push={(next) => push({ entry: next })}
|
|
1233
|
+
/>
|
|
1234
|
+
))}
|
|
1235
|
+
</nav>
|
|
1236
|
+
) : (
|
|
1237
|
+
<Views
|
|
1238
|
+
shell={shell}
|
|
1239
|
+
node={page.node}
|
|
1240
|
+
style={style}
|
|
1241
|
+
go={drawer.close}
|
|
1242
|
+
push={(next) => push({ entry: next })}
|
|
1243
|
+
/>
|
|
1244
|
+
)}
|
|
1245
|
+
{style === 'pages' && kids.length > 0 && (
|
|
1246
|
+
<nav aria-label="Nodes" className="flex flex-col px-2 pb-2">
|
|
1247
|
+
<h2 className="m-0 px-2 pt-3 pb-1 text-xs font-medium tracking-wide text-secondary uppercase">
|
|
1248
|
+
Nodes
|
|
1249
|
+
</h2>
|
|
1250
|
+
{kids.map((kid) => (
|
|
1251
|
+
<PageRow
|
|
1252
|
+
key={kid.id}
|
|
1253
|
+
icon={nodeIcon(nodes, kid.id)}
|
|
1254
|
+
title={kid.title}
|
|
1255
|
+
onSelect={() => push({ node: kid.id })}
|
|
1256
|
+
/>
|
|
1257
|
+
))}
|
|
1258
|
+
</nav>
|
|
1259
|
+
)}
|
|
1260
|
+
{style === 'tree' && <NodeTree shell={shell} />}
|
|
1261
|
+
</div>
|
|
1262
|
+
{style === 'pages' && elsewhere && (
|
|
1263
|
+
<nav
|
|
1264
|
+
aria-label="Workspaces"
|
|
1265
|
+
className="flex flex-col border-t border-border px-2 pt-2 pb-2"
|
|
1266
|
+
>
|
|
1267
|
+
<h2 className="m-0 px-2 pt-2 pb-1 text-xs font-medium tracking-wide text-secondary uppercase">
|
|
1268
|
+
Workspaces
|
|
1269
|
+
</h2>
|
|
1270
|
+
{workspaces.map((workspace) => (
|
|
1271
|
+
<button
|
|
1272
|
+
key={workspace.slug}
|
|
1273
|
+
type="button"
|
|
1274
|
+
aria-current={workspace.slug === current?.slug ? 'page' : undefined}
|
|
1275
|
+
onClick={() => drawer.close(() => switchTo(shell, workspace.slug))}
|
|
1276
|
+
className="flex min-h-11 items-center rounded-lg px-2 text-left text-[15px] active:bg-hover aria-[current=page]:font-semibold"
|
|
1277
|
+
>
|
|
1278
|
+
{workspace.title}
|
|
1279
|
+
</button>
|
|
1280
|
+
))}
|
|
1281
|
+
</nav>
|
|
1282
|
+
)}
|
|
1283
|
+
</div>
|
|
1284
|
+
);
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
/** As the rail does: the workspace, and its URL in the history. */
|
|
1288
|
+
function switchTo(shell: Shell, slug: string) {
|
|
1289
|
+
shell.setCurrent(slug);
|
|
1290
|
+
if (!location.pathname.startsWith(`/${slug}/`)) history.pushState(null, '', `/${slug}/`);
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
/** The workspaces in a sheet from the bottom, over the floating menu (the `tree` style): the current one checked, a tap
|
|
1294
|
+
* on another closes the menu on it. */
|
|
1295
|
+
function WorkspaceSheet({ shell }: { shell: Shell }) {
|
|
1296
|
+
const open = React.useSyncExternalStore(workspaceSheet.subscribe, workspaceSheet.get);
|
|
1297
|
+
const { current, workspaces } = React.useSyncExternalStore(shell.subscribe, shell.get);
|
|
1298
|
+
return (
|
|
1299
|
+
<Dialog
|
|
1300
|
+
open={open}
|
|
1301
|
+
onOpenChange={(next) => (next ? workspaceSheet.open() : workspaceSheet.close())}
|
|
1302
|
+
>
|
|
1303
|
+
<DialogContent className="top-auto bottom-0 left-0 flex max-h-[70dvh] w-full max-w-none translate-x-0 translate-y-0 flex-col phone-sheet rounded-none rounded-t-3xl p-0 pb-[max(env(safe-area-inset-bottom),1rem)] transition-transform duration-300 ease-out data-[ending-style]:translate-y-full data-[starting-style]:translate-y-full">
|
|
1304
|
+
<div data-mobile="" className="flex min-h-0 flex-col overflow-y-auto overscroll-contain">
|
|
1305
|
+
<span
|
|
1306
|
+
aria-hidden="true"
|
|
1307
|
+
className="mx-auto mt-2 block h-1.5 w-10 shrink-0 rounded-full bg-border"
|
|
1308
|
+
/>
|
|
1309
|
+
<DialogTitle className="m-0 px-5 pt-3 pb-1 text-sm font-normal text-secondary">
|
|
1310
|
+
Workspaces
|
|
1311
|
+
</DialogTitle>
|
|
1312
|
+
<nav aria-label="Workspaces" className="flex flex-col px-2 pb-2">
|
|
1313
|
+
{workspaces
|
|
1314
|
+
.filter((each) => each.slug !== 'admin')
|
|
1315
|
+
.map((workspace) => (
|
|
1316
|
+
<button
|
|
1317
|
+
key={workspace.slug}
|
|
1318
|
+
type="button"
|
|
1319
|
+
aria-current={workspace.slug === current?.slug ? 'page' : undefined}
|
|
1320
|
+
onClick={() =>
|
|
1321
|
+
workspace.slug === current?.slug
|
|
1322
|
+
? workspaceSheet.close()
|
|
1323
|
+
: drawer.stay(() => switchTo(shell, workspace.slug))
|
|
1324
|
+
}
|
|
1325
|
+
className="flex min-h-14 items-center gap-3 rounded-lg px-3 text-left text-[17px] active:bg-hover"
|
|
1326
|
+
>
|
|
1327
|
+
<WorkspaceAvatar workspace={workspace} />
|
|
1328
|
+
<span className="min-w-0 flex-1 truncate">{workspace.title}</span>
|
|
1329
|
+
{workspace.slug === current?.slug && (
|
|
1330
|
+
<Icon name="check" size={20} className="shrink-0 text-accent" />
|
|
1331
|
+
)}
|
|
1332
|
+
</button>
|
|
1333
|
+
))}
|
|
1334
|
+
</nav>
|
|
1335
|
+
</div>
|
|
1336
|
+
</DialogContent>
|
|
1337
|
+
</Dialog>
|
|
1338
|
+
);
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
/** A workspace's avatar, as its tile in the rail (./../rail/browser.tsx `Tile`): its look's colour and shape, else its
|
|
1342
|
+
* slug's colour, its initials. */
|
|
1343
|
+
function WorkspaceAvatar({
|
|
1344
|
+
workspace,
|
|
1345
|
+
}: {
|
|
1346
|
+
workspace: ReturnType<Shell['get']>['workspaces'][number];
|
|
1347
|
+
}) {
|
|
1348
|
+
const shape = workspace.look?.shape;
|
|
1349
|
+
return (
|
|
1350
|
+
<span
|
|
1351
|
+
aria-hidden="true"
|
|
1352
|
+
style={
|
|
1353
|
+
{
|
|
1354
|
+
'--tile':
|
|
1355
|
+
modeColour(workspace.look?.tile, tileColourOf(workspace.slug)) ??
|
|
1356
|
+
tileColourOf(workspace.slug),
|
|
1357
|
+
...(shape !== undefined && Object.hasOwn(tileShapeStyles, shape)
|
|
1358
|
+
? tileShapeStyles[shape]
|
|
1359
|
+
: {}),
|
|
1360
|
+
} as React.CSSProperties
|
|
1361
|
+
}
|
|
1362
|
+
className="grid size-9 shrink-0 place-items-center rounded-[10px] bg-(--tile) text-sm font-semibold text-white"
|
|
1363
|
+
>
|
|
1364
|
+
{getInitials(workspace.title)}
|
|
1365
|
+
</span>
|
|
1366
|
+
);
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1369
|
+
/** The workspace's node tree in the floating menu (the `tree` style), as the desktop sidebar's: each node unfolds by its
|
|
1370
|
+
* triangle to its views, then its child nodes; a tap on a node shows it, on a view opens it. Unfolded down to the node
|
|
1371
|
+
* shown. */
|
|
1372
|
+
function NodeTree({ shell }: { shell: Shell }) {
|
|
1373
|
+
const state = React.useSyncExternalStore(shell.subscribe, shell.get);
|
|
1374
|
+
const { nodes } = state;
|
|
1375
|
+
const view = viewOf(state);
|
|
1376
|
+
const shown = view.utility?.node ?? view.node;
|
|
1377
|
+
const [unfolded, setUnfolded] = React.useState(() => chainOf(nodes, shown));
|
|
1378
|
+
const fold = (id: string, to: boolean) =>
|
|
1379
|
+
setUnfolded((was) => {
|
|
1380
|
+
const next = new Set(was);
|
|
1381
|
+
if (to) next.add(id);
|
|
1382
|
+
else next.delete(id);
|
|
1383
|
+
return next;
|
|
1384
|
+
});
|
|
1385
|
+
const rows = (parent: string, depth: number): React.ReactNode =>
|
|
1386
|
+
childrenOf(nodes, parent, shown).map((node) => {
|
|
1387
|
+
const entries = entriesOn(state, node.id).flatMap((group) => group.entries);
|
|
1388
|
+
const under = entries.length > 0 || childrenOf(nodes, node.id, shown).length > 0;
|
|
1389
|
+
return (
|
|
1390
|
+
<SidebarTreeItem
|
|
1391
|
+
guide
|
|
1392
|
+
key={node.id}
|
|
1393
|
+
label={node.title}
|
|
1394
|
+
icon={<Icon name={nodeIcon(nodes, node.id)} size={18} />}
|
|
1395
|
+
depth={depth}
|
|
1396
|
+
className="h-11 text-[16px]"
|
|
1397
|
+
active={node.id === shown && !view.screen}
|
|
1398
|
+
expanded={under ? unfolded.has(node.id) : undefined}
|
|
1399
|
+
onExpandedChange={(to) => fold(node.id, to)}
|
|
1400
|
+
onSelect={() => drawer.close(() => shell.setNode(node.id))}
|
|
1401
|
+
>
|
|
1402
|
+
{under ? (
|
|
1403
|
+
<>
|
|
1404
|
+
{entries.map((entry) => (
|
|
1405
|
+
<EntryTree
|
|
1406
|
+
key={entryKey(entry)}
|
|
1407
|
+
shell={shell}
|
|
1408
|
+
entry={entry}
|
|
1409
|
+
depth={depth + 1}
|
|
1410
|
+
go={drawer.close}
|
|
1411
|
+
/>
|
|
1412
|
+
))}
|
|
1413
|
+
{rows(node.id, depth + 1)}
|
|
1414
|
+
</>
|
|
1415
|
+
) : undefined}
|
|
1416
|
+
</SidebarTreeItem>
|
|
1417
|
+
);
|
|
1418
|
+
});
|
|
1419
|
+
if (childrenOf(nodes, 'root', shown).length === 0) return null;
|
|
1420
|
+
return (
|
|
1421
|
+
<nav aria-label="Nodes" className="flex flex-col px-2 pb-2">
|
|
1422
|
+
<SidebarTree variant="navigation" indent={24} aria-label="Nodes">
|
|
1423
|
+
{rows('root', 0)}
|
|
1424
|
+
</SidebarTree>
|
|
1425
|
+
</nav>
|
|
1426
|
+
);
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
/** The phone's settings (the gear beside the workspace's title in the drawer; after a phone app's settings): a sheet from
|
|
1430
|
+
* the bottom over the drawer, with this device's text size, a sample drawn at it, and the mode. Both are this device's
|
|
1431
|
+
* (client preferences), also in Settings, Look, Mine. */
|
|
1432
|
+
function PhoneSettings({
|
|
1433
|
+
textSize,
|
|
1434
|
+
mode,
|
|
1435
|
+
style,
|
|
1436
|
+
}: {
|
|
1437
|
+
textSize: number;
|
|
1438
|
+
mode: unknown;
|
|
1439
|
+
style: MenuStyle;
|
|
1440
|
+
}) {
|
|
1441
|
+
const open = React.useSyncExternalStore(settingsSheet.subscribe, settingsSheet.get);
|
|
1442
|
+
return (
|
|
1443
|
+
<Dialog
|
|
1444
|
+
open={open}
|
|
1445
|
+
onOpenChange={(next) => (next ? settingsSheet.open() : settingsSheet.close())}
|
|
1446
|
+
>
|
|
1447
|
+
<DialogContent className="top-auto bottom-0 left-0 flex max-h-[92dvh] w-full max-w-none translate-x-0 translate-y-0 flex-col phone-sheet rounded-none rounded-t-3xl p-0 pb-[max(env(safe-area-inset-bottom),1rem)] transition-transform duration-300 ease-out data-[ending-style]:translate-y-full data-[starting-style]:translate-y-full">
|
|
1448
|
+
<div data-mobile="" className="flex min-h-0 flex-col overflow-y-auto overscroll-contain">
|
|
1449
|
+
<span
|
|
1450
|
+
aria-hidden="true"
|
|
1451
|
+
className="mx-auto mt-2 block h-1.5 w-10 shrink-0 rounded-full bg-border"
|
|
1452
|
+
/>
|
|
1453
|
+
<header className="flex shrink-0 items-center gap-2 px-4 pt-2 pb-3">
|
|
1454
|
+
<span className="w-16" />
|
|
1455
|
+
<DialogTitle className="m-0 flex-1 text-center text-[17px] font-semibold">
|
|
1456
|
+
Settings
|
|
1457
|
+
</DialogTitle>
|
|
1458
|
+
<button
|
|
1459
|
+
type="button"
|
|
1460
|
+
onClick={() => settingsSheet.close()}
|
|
1461
|
+
className="flex h-10 w-16 items-center justify-end text-[17px] font-semibold text-accent"
|
|
1462
|
+
>
|
|
1463
|
+
Done
|
|
1464
|
+
</button>
|
|
1465
|
+
</header>
|
|
1466
|
+
<section aria-labelledby="phone-settings-text" className="px-4 pb-4">
|
|
1467
|
+
<h2 id="phone-settings-text" className="m-0 px-1 pb-1.5 text-xs text-secondary">
|
|
1468
|
+
Text
|
|
1469
|
+
</h2>
|
|
1470
|
+
<div className="phone-card rounded-2xl px-4 pt-3">
|
|
1471
|
+
<p className="m-0 text-sm">The quick brown fox jumps over the lazy dog.</p>
|
|
1472
|
+
<p className="m-0 pt-1 pb-3 text-xs text-secondary">
|
|
1473
|
+
Messages, lists and their details follow this size, on this device.
|
|
1474
|
+
</p>
|
|
1475
|
+
<TextSize size={textSize} />
|
|
1476
|
+
</div>
|
|
1477
|
+
</section>
|
|
1478
|
+
<section aria-labelledby="phone-settings-menu" className="px-4 pb-4">
|
|
1479
|
+
<h2 id="phone-settings-menu" className="m-0 px-1 pb-1.5 text-xs text-secondary">
|
|
1480
|
+
Menu
|
|
1481
|
+
</h2>
|
|
1482
|
+
<div className="phone-card flex flex-col gap-2 rounded-2xl p-3">
|
|
1483
|
+
<SegmentGroup
|
|
1484
|
+
aria-labelledby="phone-settings-menu"
|
|
1485
|
+
fullWidth
|
|
1486
|
+
size="lg"
|
|
1487
|
+
items={[
|
|
1488
|
+
{ value: 'pages', label: 'Pages' },
|
|
1489
|
+
{ value: 'tree', label: 'Panel and tree' },
|
|
1490
|
+
]}
|
|
1491
|
+
value={style}
|
|
1492
|
+
onValueChange={(next) => menuStyle.set(next === 'tree' ? 'tree' : 'pages')}
|
|
1493
|
+
/>
|
|
1494
|
+
<p className="m-0 px-1 text-xs text-secondary">
|
|
1495
|
+
{style === 'tree'
|
|
1496
|
+
? 'A floating panel with the views; every node on a page of its own, unfolded by its triangle.'
|
|
1497
|
+
: "Each node's page lists its views, then its nodes; Back goes up one."}
|
|
1498
|
+
</p>
|
|
1499
|
+
</div>
|
|
1500
|
+
</section>
|
|
1501
|
+
<section aria-labelledby="phone-settings-mode" className="px-4 pb-2">
|
|
1502
|
+
<h2 id="phone-settings-mode" className="m-0 px-1 pb-1.5 text-xs text-secondary">
|
|
1503
|
+
Appearance
|
|
1504
|
+
</h2>
|
|
1505
|
+
<div
|
|
1506
|
+
role="radiogroup"
|
|
1507
|
+
aria-label="Mode"
|
|
1508
|
+
className="phone-card flex gap-1 rounded-2xl p-1"
|
|
1509
|
+
>
|
|
1510
|
+
{modes.map((each) => (
|
|
1511
|
+
<button
|
|
1512
|
+
key={each.id}
|
|
1513
|
+
type="button"
|
|
1514
|
+
role="radio"
|
|
1515
|
+
aria-checked={mode === each.id}
|
|
1516
|
+
onClick={() => void setMode(each.id)}
|
|
1517
|
+
className="phone-choice flex-1 rounded-xl py-2.5 text-sm aria-checked:font-medium"
|
|
1518
|
+
>
|
|
1519
|
+
{each.label}
|
|
1520
|
+
</button>
|
|
1521
|
+
))}
|
|
1522
|
+
</div>
|
|
1523
|
+
</section>
|
|
1524
|
+
</div>
|
|
1525
|
+
</DialogContent>
|
|
1526
|
+
</Dialog>
|
|
1527
|
+
);
|
|
1528
|
+
}
|