@jskit-ai/shell-web 0.2.9 → 0.2.11

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.
Files changed (69) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/fixtures/adaptive-shell/src/App.vue +2 -0
  3. package/fixtures/adaptive-shell/src/RecordListPage.vue +22 -0
  4. package/fixtures/adaptive-shell/src/RecordPage.vue +30 -0
  5. package/fixtures/adaptive-shell/src/ScreenPage.vue +7 -3
  6. package/fixtures/adaptive-shell/src/SettingsPage.vue +24 -0
  7. package/fixtures/adaptive-shell/src/main.js +60 -55
  8. package/fixtures/adaptive-shell/src/records.js +13 -0
  9. package/fixtures/adaptive-shell/src/theme/index.js +3 -0
  10. package/locales/en.json +1 -0
  11. package/package.json +17 -5
  12. package/patterns/application-shell/PATTERN.md +3 -1
  13. package/patterns/application-shell/example/expected-existing/src/pages/home/index.vue +5 -18
  14. package/patterns/application-shell/example/expected-existing/src/views/NotFound.vue +14 -0
  15. package/patterns/application-shell/example/src/pages/home/index.vue +21 -57
  16. package/patterns/application-shell/example/src/pages/home/settings/general/index.vue +24 -19
  17. package/patterns/application-shell/example/src/pages/home/settings.vue +27 -84
  18. package/patterns/application-shell/example/src/views/NotFound.vue +15 -0
  19. package/patterns/page-and-placement/example/src/components/SyncStatusElement.vue +2 -2
  20. package/patterns/page-and-placement/example/src/pages/home/reports/activity.vue +1 -1
  21. package/patterns/page-and-placement/example/src/pages/home/reports/overview.vue +1 -1
  22. package/patterns/page-and-placement/example/src/pages/home/reports.vue +6 -3
  23. package/patterns/page-and-placement/example/src/placement.js +1 -1
  24. package/src/client/components/ShellErrorHost.vue +13 -15
  25. package/src/client/components/ShellLayout.vue +388 -186
  26. package/src/client/components/ShellListDetail.vue +77 -0
  27. package/src/client/components/ShellMenuLinkItem.vue +10 -24
  28. package/src/client/components/ShellNavigationItem.vue +175 -0
  29. package/src/client/components/ShellNavigationScope.vue +18 -0
  30. package/src/client/components/ShellOutlet.vue +1 -1
  31. package/src/client/components/ShellOutletMenuWidget.vue +2 -2
  32. package/src/client/components/ShellPageAction.vue +91 -0
  33. package/src/client/components/ShellPageActions.vue +32 -0
  34. package/src/client/components/ShellSurfaceAwareMenuLinkItem.vue +10 -24
  35. package/src/client/components/ShellTabLinkItem.vue +77 -3
  36. package/src/client/composables/useShellDrawer.js +28 -18
  37. package/src/client/composables/useShellPageTitle.js +15 -0
  38. package/src/client/composables/useShellRouteTransition.js +1 -1
  39. package/src/client/composables/useShellWindowSizeClass.js +21 -0
  40. package/src/client/error/presentation.js +3 -5
  41. package/src/client/index.js +7 -0
  42. package/src/client/lib/menuIcons.js +21 -65
  43. package/src/client/navigation/documentNavigation.js +38 -0
  44. package/src/client/navigation/shellNavigationRuntime.js +480 -0
  45. package/src/client/navigation/useShellNavigation.js +94 -0
  46. package/src/client/providers/ShellWebClientProvider.js +11 -0
  47. package/src/client/support/drawerPresentation.js +9 -4
  48. package/src/client/support/drawerWidth.js +18 -1
  49. package/src/client/support/navigationPresentation.js +40 -0
  50. package/src/client/support/shellLayoutClass.js +6 -25
  51. package/src/client/support/windowSizeClass.js +29 -0
  52. package/src/test/adaptiveShellSmoke.js +43 -16
  53. package/src/test/shellNavigation.js +32 -0
  54. package/test/adaptiveShell.browser.test.js +207 -111
  55. package/test/clientUpdate.test.js +6 -1
  56. package/test/drawerPresentation.test.js +7 -7
  57. package/test/errorPresentation.test.js +4 -5
  58. package/test/materialBaselines.browser.test.js +96 -0
  59. package/test/menuIcons.test.js +14 -22
  60. package/test/outletMenuWidgetContract.test.js +2 -3
  61. package/test/playwrightContract.test.js +3 -1
  62. package/test/provider.test.js +9 -1
  63. package/test/settingsPlacementContract.test.js +33 -28
  64. package/test/shellGestureSupport.test.js +21 -9
  65. package/test/translation.test.js +2 -2
  66. package/test/useShellDrawer.test.js +20 -5
  67. package/test/useShellRouteTransition.test.js +3 -3
  68. package/patterns/application-shell/example/src/pages/home/settings/index.vue +0 -7
  69. package/src/client/components/ShellNavigationTooltip.vue +0 -39
@@ -0,0 +1,480 @@
1
+ import { shallowRef } from "vue";
2
+ import { NavigationFailureType, isNavigationFailure } from "vue-router";
3
+ import { staysOnSamePage } from "@jskit-ai/kernel/client";
4
+ import { isRecord } from "@jskit-ai/kernel/shared/support/normalize";
5
+ import { pageDocument, pageWindow } from "../browser.js";
6
+
7
+ const SHELL_NAVIGATION_RUNTIME_KEY = "jskit.shell-web.runtime.navigation.client";
8
+ // The tab's trail rides in each history entry's state: a refresh keeps it, a new tab or a pasted link starts empty,
9
+ // and the browser's Back and Forward bring back the trail each entry had.
10
+ const TRAIL_STATE_KEY = "jskitTrail";
11
+ const FOCUS_RETRY_MS = 100;
12
+ const FOCUS_ATTEMPTS = 15;
13
+ const PAGE_TITLE_ID = "jskit-shell-page-title";
14
+
15
+ /**
16
+ * A page's declared parent: the nearest `meta.jskit.parent` from the page's own route record up through its layout
17
+ * records, stopping below the surface root. A string is a path on the page's own surface (`:param` segments come from
18
+ * the current route); `{ surface, path }` names another surface. Null on a top-level destination.
19
+ * @param {readonly import("vue-router").RouteRecordNormalized[]} matched
20
+ * @returns {{ record: import("vue-router").RouteRecordNormalized, surface: string, path: string } | null}
21
+ */
22
+ function resolvePageParent(matched) {
23
+ for (let index = matched.length - 1; index >= 0; index -= 1) {
24
+ const record = matched[index];
25
+ const jskitMeta = isRecord(record.meta?.jskit) ? record.meta.jskit : {};
26
+ if (jskitMeta.surface) {
27
+ return null;
28
+ }
29
+ const parent = jskitMeta.parent;
30
+ if (typeof parent === "string" && parent.trim()) {
31
+ return {
32
+ record,
33
+ surface: "",
34
+ path: parent.trim()
35
+ };
36
+ }
37
+ if (isRecord(parent) && String(parent.path || "").trim()) {
38
+ return {
39
+ record,
40
+ surface: String(parent.surface || "").trim(),
41
+ path: String(parent.path).trim()
42
+ };
43
+ }
44
+ }
45
+ return null;
46
+ }
47
+
48
+ /**
49
+ * A page's declared app bar title: the nearest `meta.jskit.title`, a message key or plain text; "" when none.
50
+ * @param {readonly import("vue-router").RouteRecordNormalized[]} matched
51
+ */
52
+ function resolvePageTitle(matched) {
53
+ for (let index = matched.length - 1; index >= 0; index -= 1) {
54
+ const title = matched[index].meta?.jskit?.title;
55
+ if (typeof title === "string" && title.trim()) {
56
+ return title.trim();
57
+ }
58
+ }
59
+ return "";
60
+ }
61
+
62
+ function normalizeTrail(value) {
63
+ if (!Array.isArray(value)) {
64
+ return [];
65
+ }
66
+ return value
67
+ .filter((step) => isRecord(step) && typeof step.path === "string" && step.path.startsWith("/"))
68
+ .map((step) => ({
69
+ path: step.path,
70
+ scroll: {
71
+ left: Number(step.scroll?.left) || 0,
72
+ top: Number(step.scroll?.top) || 0
73
+ }
74
+ }));
75
+ }
76
+
77
+ function cssAttributeValue(value) {
78
+ return String(value).replace(/["\\]/gu, "\\$&");
79
+ }
80
+
81
+ /**
82
+ * The shell's Up navigation (Material's Up and Back model): one trail per browser tab, kept in history state.
83
+ * In-app navigation to another inner page pushes the page left; same-page changes, replacements and top-level
84
+ * destinations do not, and a top-level destination resets it. Up returns to the trail's last page when it still
85
+ * opens, otherwise to the page's declared parent, never to sign-in or outside the app; it restores that page's scroll
86
+ * and focuses the element that opened the page left, or the page title.
87
+ * @param {object} options
88
+ * @param {import("vue-router").Router} options.router
89
+ */
90
+ function createShellNavigationRuntime({ router }) {
91
+ const trail = shallowRef([]);
92
+ const pageTitleSource = shallowRef(null);
93
+ const visibleParentPanes = shallowRef(0);
94
+ const removeHooks = [];
95
+ let current = {
96
+ id: "",
97
+ trail: [],
98
+ fallback: null,
99
+ position: -1
100
+ };
101
+ let pending = null;
102
+ let leavingScroll = null;
103
+ let mountedShells = 0;
104
+ let focusTimer = null;
105
+ let sequence = 0;
106
+
107
+ function nextEntryId() {
108
+ sequence += 1;
109
+ return `${Date.now().toString(36)}-${sequence}`;
110
+ }
111
+
112
+ function samePage(to, from) {
113
+ if (to.path === from.path) {
114
+ return true;
115
+ }
116
+ return staysOnSamePage(to, from) && resolvePageParent(to.matched)?.record === resolvePageParent(from.matched)?.record;
117
+ }
118
+
119
+ function opens(path) {
120
+ const resolved = router.resolve(path);
121
+ return resolved.matched.length > 0 && resolved.name !== "not-found";
122
+ }
123
+
124
+ function sameLocation(left, right) {
125
+ return router.resolve(left).fullPath === router.resolve(right).fullPath;
126
+ }
127
+
128
+ function pushedTrail(to, from) {
129
+ if (from.matched.length === 0 || mountedShells === 0) {
130
+ return [];
131
+ }
132
+ if (samePage(to, from)) {
133
+ return current.trail;
134
+ }
135
+ if (!resolvePageParent(to.matched)) {
136
+ return [];
137
+ }
138
+ return [
139
+ ...current.trail,
140
+ {
141
+ path: from.fullPath,
142
+ scroll: leavingScroll || {
143
+ left: 0,
144
+ top: 0
145
+ }
146
+ }
147
+ ];
148
+ }
149
+
150
+ function replacedTrail(steps, to) {
151
+ if (!resolvePageParent(to.matched)) {
152
+ return [];
153
+ }
154
+ const top = steps.at(-1);
155
+ if (top && router.resolve(top.path).path === to.path) {
156
+ return steps.slice(0, -1);
157
+ }
158
+ return steps;
159
+ }
160
+
161
+ function clearFocusTimer() {
162
+ if (focusTimer !== null) {
163
+ pageWindow()?.clearTimeout(focusTimer);
164
+ focusTimer = null;
165
+ }
166
+ }
167
+
168
+ function findOpener(documentRef, leftPath) {
169
+ const resolved = router.resolve(leftPath);
170
+ const hrefs = [...new Set([resolved.href, router.resolve(resolved.path).href])];
171
+ for (const href of hrefs) {
172
+ const value = cssAttributeValue(href);
173
+ const candidates = documentRef.querySelectorAll(`[data-jskit-opens="${value}"], main a[href="${value}"]`);
174
+ for (const candidate of candidates) {
175
+ if (candidate.getClientRects().length > 0) {
176
+ return candidate;
177
+ }
178
+ }
179
+ }
180
+ return null;
181
+ }
182
+
183
+ // After Up or Back, focus the element that opened the page left, or else the page title.
184
+ function scheduleFocus(leftPath) {
185
+ clearFocusTimer();
186
+ const windowRef = pageWindow();
187
+ if (!windowRef) {
188
+ return;
189
+ }
190
+ let attempts = 0;
191
+ const tryFocus = () => {
192
+ focusTimer = null;
193
+ const documentRef = pageDocument();
194
+ if (!documentRef) {
195
+ return;
196
+ }
197
+ const opener = findOpener(documentRef, leftPath);
198
+ if (opener) {
199
+ opener.focus({ preventScroll: true });
200
+ return;
201
+ }
202
+ attempts += 1;
203
+ if (attempts < FOCUS_ATTEMPTS) {
204
+ focusTimer = windowRef.setTimeout(tryFocus, FOCUS_RETRY_MS);
205
+ return;
206
+ }
207
+ documentRef.getElementById(PAGE_TITLE_ID)?.focus({ preventScroll: true });
208
+ };
209
+ focusTimer = windowRef.setTimeout(tryFocus, 0);
210
+ }
211
+
212
+ function handleBeforeEach(to, from) {
213
+ if (pending && !pending.redirected && pending.fallback && to.redirectedFrom && sameLocation(to.redirectedFrom.fullPath, pending.target)) {
214
+ // The trail's page now redirects (no access, workspace left): go to the declared parent instead.
215
+ pending = {
216
+ ...pending,
217
+ target: pending.fallback.path,
218
+ trail: pending.fallback.trail,
219
+ scroll: null,
220
+ fallback: null,
221
+ redirected: true
222
+ };
223
+ return pending.target;
224
+ }
225
+ const windowRef = pageWindow();
226
+ if (windowRef && from.matched.length > 0) {
227
+ leavingScroll = {
228
+ left: windowRef.scrollX,
229
+ top: windowRef.scrollY
230
+ };
231
+ const state = windowRef.history.state;
232
+ if (isRecord(state) && state.restoreScroll) {
233
+ // The position Up returned to has been used; a later replacement of this entry must not reuse it.
234
+ const { restoreScroll: _used, ...rest } = state;
235
+ windowRef.history.replaceState(rest, "");
236
+ }
237
+ }
238
+ return true;
239
+ }
240
+
241
+ function handleAfterEach(to, from, failure) {
242
+ const windowRef = pageWindow();
243
+ if (!windowRef) {
244
+ return;
245
+ }
246
+ if (failure) {
247
+ const plan = pending;
248
+ pending = null;
249
+ if (plan?.fallback && !plan.redirected && isNavigationFailure(failure, NavigationFailureType.aborted)) {
250
+ // The trail's page refused to open: go to the declared parent instead.
251
+ navigate({
252
+ target: plan.fallback.path,
253
+ trail: plan.fallback.trail,
254
+ scroll: null,
255
+ focusPath: plan.focusPath,
256
+ fallback: null,
257
+ replace: plan.replace,
258
+ redirected: true
259
+ });
260
+ }
261
+ return;
262
+ }
263
+
264
+ const state = isRecord(windowRef.history.state) ? windowRef.history.state : {};
265
+ const stored = isRecord(state[TRAIL_STATE_KEY]) ? state[TRAIL_STATE_KEY] : null;
266
+ let entry;
267
+ let fallback = null;
268
+ let focusPath = "";
269
+ if (pending) {
270
+ entry = {
271
+ id: nextEntryId(),
272
+ trail: pending.trail
273
+ };
274
+ fallback = pending.fallback;
275
+ focusPath = pending.focusPath;
276
+ pending = null;
277
+ } else if (stored && stored.id && stored.id !== current.id) {
278
+ // A refresh, or the browser's Back or Forward: the entry keeps the trail it had.
279
+ entry = {
280
+ id: String(stored.id),
281
+ trail: normalizeTrail(stored.trail)
282
+ };
283
+ if (Number(state.position) < current.position) {
284
+ focusPath = from.fullPath;
285
+ }
286
+ } else if (stored && stored.id === current.id) {
287
+ entry = {
288
+ id: current.id,
289
+ trail: replacedTrail(current.trail, to)
290
+ };
291
+ } else {
292
+ entry = {
293
+ id: nextEntryId(),
294
+ trail: pushedTrail(to, from)
295
+ };
296
+ }
297
+
298
+ windowRef.history.replaceState({
299
+ ...state,
300
+ [TRAIL_STATE_KEY]: entry
301
+ }, "");
302
+ current = {
303
+ ...entry,
304
+ fallback,
305
+ position: Number(state.position)
306
+ };
307
+ trail.value = entry.trail;
308
+ if (focusPath) {
309
+ scheduleFocus(focusPath);
310
+ }
311
+ }
312
+
313
+ function navigate(plan) {
314
+ pending = plan;
315
+ const location = router.resolve(plan.target);
316
+ const destination = {
317
+ path: location.path,
318
+ query: location.query,
319
+ hash: location.hash,
320
+ state: plan.scroll ? { restoreScroll: plan.scroll } : {}
321
+ };
322
+ return plan.replace ? router.replace(destination) : router.push(destination);
323
+ }
324
+
325
+ function install() {
326
+ removeHooks.push(router.beforeEach(handleBeforeEach), router.afterEach(handleAfterEach));
327
+ }
328
+
329
+ function dispose() {
330
+ for (const remove of removeHooks.splice(0)) {
331
+ remove();
332
+ }
333
+ clearFocusTimer();
334
+ }
335
+
336
+ /**
337
+ * Up: the trail's last page when it still opens, otherwise the declared parent.
338
+ * @param {string} parentTarget The page's declared parent, resolved to a path; "" when it has none.
339
+ */
340
+ function up(parentTarget) {
341
+ const steps = current.trail;
342
+ const top = steps.at(-1);
343
+ const rest = steps.slice(0, -1);
344
+ const focusPath = router.currentRoute.value.fullPath;
345
+ const fallback = parentTarget && opens(parentTarget) ? { path: parentTarget, trail: rest } : null;
346
+ if (top && opens(top.path)) {
347
+ return navigate({
348
+ target: top.path,
349
+ trail: rest,
350
+ scroll: top.scroll,
351
+ focusPath,
352
+ fallback,
353
+ replace: false,
354
+ redirected: false
355
+ });
356
+ }
357
+ if (fallback) {
358
+ return navigate({
359
+ target: fallback.path,
360
+ trail: rest,
361
+ scroll: null,
362
+ focusPath,
363
+ fallback: null,
364
+ replace: false,
365
+ redirected: false
366
+ });
367
+ }
368
+ return Promise.resolve();
369
+ }
370
+
371
+ /**
372
+ * Leaves a finished page (Save or Cancel on a new or edit page) by replacing its entry, so neither Up nor Back
373
+ * reopens it: to `target` when given, otherwise back to where it was opened from, or else its declared parent.
374
+ * @param {import("vue-router").RouteLocationRaw} target
375
+ * @param {string} parentTarget
376
+ */
377
+ function finish(target, parentTarget) {
378
+ const top = current.trail.at(-1);
379
+ const destination = target || (top && opens(top.path) ? top.path : parentTarget);
380
+ if (!destination) {
381
+ return Promise.resolve();
382
+ }
383
+ const resolved = router.resolve(destination);
384
+ const returning = Boolean(top && router.resolve(top.path).path === resolved.path);
385
+ return navigate({
386
+ target: resolved.fullPath,
387
+ trail: replacedTrail(current.trail, resolved),
388
+ scroll: returning ? top.scroll : null,
389
+ focusPath: returning ? router.currentRoute.value.fullPath : "",
390
+ fallback: null,
391
+ replace: true,
392
+ redirected: false
393
+ });
394
+ }
395
+
396
+ /**
397
+ * A page Up returned to says its record is gone or forbidden: replace it with the parent of the page Up left.
398
+ * Elsewhere the page shows its own not-found state.
399
+ */
400
+ function pageUnavailable() {
401
+ const fallback = current.fallback;
402
+ if (!fallback) {
403
+ return false;
404
+ }
405
+ current = {
406
+ ...current,
407
+ fallback: null
408
+ };
409
+ void navigate({
410
+ target: fallback.path,
411
+ trail: fallback.trail,
412
+ scroll: null,
413
+ focusPath: "",
414
+ fallback: null,
415
+ replace: true,
416
+ redirected: true
417
+ });
418
+ return true;
419
+ }
420
+
421
+ /**
422
+ * Shows a title in the app bar while the caller lives; returns its release.
423
+ * @param {() => string} source
424
+ */
425
+ function setPageTitle(source) {
426
+ pageTitleSource.value = source;
427
+ return () => {
428
+ if (pageTitleSource.value === source) {
429
+ pageTitleSource.value = null;
430
+ }
431
+ };
432
+ }
433
+
434
+ /** Marks a parent pane as visible beside the page (list-detail), so the page shows no Up arrow; returns its release. */
435
+ function showParentPane() {
436
+ visibleParentPanes.value += 1;
437
+ let released = false;
438
+ return () => {
439
+ if (!released) {
440
+ released = true;
441
+ visibleParentPanes.value -= 1;
442
+ }
443
+ };
444
+ }
445
+
446
+ /** Counts a mounted shell layout: only pages inside the shell enter the trail. Returns its release. */
447
+ function attachShell() {
448
+ mountedShells += 1;
449
+ let released = false;
450
+ return () => {
451
+ if (!released) {
452
+ released = true;
453
+ mountedShells -= 1;
454
+ }
455
+ };
456
+ }
457
+
458
+ return {
459
+ trail,
460
+ pageTitleSource,
461
+ visibleParentPanes,
462
+ install,
463
+ dispose,
464
+ up,
465
+ finish,
466
+ pageUnavailable,
467
+ setPageTitle,
468
+ showParentPane,
469
+ attachShell
470
+ };
471
+ }
472
+
473
+ export {
474
+ PAGE_TITLE_ID,
475
+ SHELL_NAVIGATION_RUNTIME_KEY,
476
+ TRAIL_STATE_KEY,
477
+ createShellNavigationRuntime,
478
+ resolvePageParent,
479
+ resolvePageTitle
480
+ };
@@ -0,0 +1,94 @@
1
+ import { computed, inject } from "vue";
2
+ import { useRoute, useRouter } from "vue-router";
3
+ import { SHELL_NAVIGATION_RUNTIME_KEY, resolvePageParent } from "./shellNavigationRuntime.js";
4
+ import { usePaths } from "./usePaths.js";
5
+
6
+ function resolvedNothing() {
7
+ return Promise.resolve();
8
+ }
9
+
10
+ function releaseNothing() {}
11
+
12
+ /**
13
+ * The navigation of an application without shell-web's provider: no trail, so Up goes to the declared parent through
14
+ * the router and finishing a page replaces it with its target.
15
+ * @type {any}
16
+ */
17
+ const NO_SHELL_NAVIGATION_RUNTIME = Object.freeze({
18
+ trail: Object.freeze({ value: Object.freeze([]) }),
19
+ pageTitleSource: Object.freeze({ value: null }),
20
+ visibleParentPanes: Object.freeze({ value: 0 }),
21
+ up: resolvedNothing,
22
+ finish: resolvedNothing,
23
+ pageUnavailable: () => false,
24
+ setPageTitle: () => releaseNothing,
25
+ showParentPane: () => releaseNothing,
26
+ attachShell: () => releaseNothing
27
+ });
28
+
29
+ /**
30
+ * The shell's navigation runtime, or `NO_SHELL_NAVIGATION_RUNTIME` in an application without shell-web's provider.
31
+ * @returns {ReturnType<typeof import("./shellNavigationRuntime.js").createShellNavigationRuntime>}
32
+ */
33
+ function useShellNavigationRuntime() {
34
+ return inject(SHELL_NAVIGATION_RUNTIME_KEY, NO_SHELL_NAVIGATION_RUNTIME);
35
+ }
36
+
37
+ /**
38
+ * The current page's Up navigation and the Save/Cancel exit of new and edit pages.
39
+ * `canGoUp` is true on an inner page (one that declares `meta.jskit.parent`) unless its parent is visible beside it;
40
+ * `up()` is what the shell's arrow does; `finish(target)` leaves a finished form by replacing its entry, to `target`
41
+ * (Save) or, with no target, back to where it was opened from (Cancel); `pageUnavailable()` tells the shell a page Up
42
+ * returned to has lost its record.
43
+ */
44
+ function useShellNavigation() {
45
+ const runtime = useShellNavigationRuntime();
46
+ const withoutShell = runtime === NO_SHELL_NAVIGATION_RUNTIME;
47
+ const router = useRouter();
48
+ const route = useRoute();
49
+ const paths = usePaths();
50
+ const parent = computed(() => resolvePageParent(route.matched));
51
+ const parentTarget = computed(() => {
52
+ if (!parent.value) {
53
+ return "";
54
+ }
55
+ try {
56
+ return paths.page(parent.value.path, { surface: parent.value.surface });
57
+ } catch {
58
+ // A parent whose params the current route lacks falls back to its surface's root.
59
+ return paths.page("/", { surface: parent.value.surface });
60
+ }
61
+ });
62
+ const canGoUp = computed(() => Boolean(parent.value) && runtime.visibleParentPanes.value === 0);
63
+ const upTarget = computed(() => runtime.trail.value.at(-1)?.path || parentTarget.value);
64
+
65
+ function up() {
66
+ if (withoutShell) {
67
+ return parentTarget.value ? router.push(parentTarget.value) : resolvedNothing();
68
+ }
69
+ return runtime.up(parentTarget.value);
70
+ }
71
+
72
+ /** @param {import("vue-router").RouteLocationRaw} [target] */
73
+ function finish(target = "") {
74
+ if (withoutShell) {
75
+ const destination = target || parentTarget.value;
76
+ return destination ? router.replace(destination) : resolvedNothing();
77
+ }
78
+ return runtime.finish(target, parentTarget.value);
79
+ }
80
+
81
+ function pageUnavailable() {
82
+ return runtime.pageUnavailable();
83
+ }
84
+
85
+ return {
86
+ canGoUp,
87
+ upTarget,
88
+ up,
89
+ finish,
90
+ pageUnavailable
91
+ };
92
+ }
93
+
94
+ export { NO_SHELL_NAVIGATION_RUNTIME, useShellNavigation, useShellNavigationRuntime };
@@ -41,6 +41,10 @@ import { createWebPlacementRuntime } from "../placement/runtime.js";
41
41
  import { useShellErrorPresentationStore } from "../stores/useShellErrorPresentationStore.js";
42
42
  import { buildSurfaceConfigContext } from "../placement/surfaceContext.js";
43
43
  import { createShellBootstrapRuntime } from "../runtime/bootstrapRuntime.js";
44
+ import {
45
+ SHELL_NAVIGATION_RUNTIME_KEY,
46
+ createShellNavigationRuntime
47
+ } from "../navigation/shellNavigationRuntime.js";
44
48
  import {
45
49
  SHELL_WEB_REFRESH_RUNTIME_KEY,
46
50
  createShellRefreshRuntime
@@ -316,6 +320,7 @@ const ShellWebClientProvider = defineProvider({
316
320
  errorRuntime,
317
321
  logger
318
322
  });
323
+ const navigationRuntime = createShellNavigationRuntime({ router });
319
324
 
320
325
  return {
321
326
  shell: Object.freeze({
@@ -325,6 +330,7 @@ const ShellWebClientProvider = defineProvider({
325
330
  clientUpdate: clientUpdateRuntime,
326
331
  error: errorRuntime,
327
332
  errorPresentationStore,
333
+ navigation: navigationRuntime,
328
334
  placement: placementRuntime,
329
335
  refresh: refreshRuntime,
330
336
  requestRecovery: requestRecoveryRuntime
@@ -338,11 +344,14 @@ const ShellWebClientProvider = defineProvider({
338
344
  clientUpdate: clientUpdateRuntime,
339
345
  error: errorRuntime,
340
346
  errorPresentationStore,
347
+ navigation: navigationRuntime,
341
348
  placement: placementRuntime,
342
349
  refresh: refreshRuntime,
343
350
  requestRecovery: requestRecoveryRuntime
344
351
  } = outputs.shell;
345
352
  asyncModuleRecoveryRuntime.install();
353
+ // Before the router's first navigation, so the trail starts with the page the tab opened on.
354
+ navigationRuntime.install();
346
355
 
347
356
  const placementTopology = await loadAppPlacementTopology(logger, asyncModuleRecoveryRuntime);
348
357
  placementRuntime.replacePlacementTopology(placementTopology, { source: APP_PLACEMENT_TOPOLOGY_MODULE_SPECIFIER });
@@ -377,11 +386,13 @@ const ShellWebClientProvider = defineProvider({
377
386
  vueApp.provide(SHELL_WEB_ERROR_RUNTIME_KEY, errorRuntime);
378
387
  vueApp.provide(SHELL_ASYNC_MODULE_RECOVERY_RUNTIME_KEY, asyncModuleRecoveryRuntime);
379
388
  vueApp.provide(SHELL_REQUEST_RECOVERY_RUNTIME_KEY, requestRecoveryRuntime);
389
+ vueApp.provide(SHELL_NAVIGATION_RUNTIME_KEY, navigationRuntime);
380
390
 
381
391
  installVueErrorBridge(vueApp, errorRuntime, logger);
382
392
  installRouterErrorBridge(router, errorRuntime, logger);
383
393
  },
384
394
  shutdown(_dependencies, { outputs }) {
395
+ outputs.shell.navigation.dispose();
385
396
  outputs.shell.clientUpdate.dispose();
386
397
  outputs.shell.requestRecovery.dispose();
387
398
  outputs.shell.asyncModuleRecovery.dispose();
@@ -8,13 +8,18 @@ function normalizeDesktopDrawerClosedMode(value = "rail") {
8
8
  return DESKTOP_DRAWER_CLOSED_MODES.includes(normalized) ? normalized : "rail";
9
9
  }
10
10
 
11
+ /**
12
+ * How the shell's navigation drawer presents: a modal drawer over the page (compact and medium windows), or on
13
+ * expanded windows a standard drawer that collapses to a navigation rail (or hides, with `desktopClosedMode: "hidden"`).
14
+ * @param {{ modal?: boolean, open?: boolean, desktopClosedMode?: string }} [options]
15
+ */
11
16
  function resolveShellDrawerPresentation({
12
- compact = false,
17
+ modal = false,
13
18
  open = false,
14
19
  desktopClosedMode = "rail"
15
20
  } = {}) {
16
21
  const closedMode = normalizeDesktopDrawerClosedMode(desktopClosedMode);
17
- if (compact) {
22
+ if (modal) {
18
23
  return Object.freeze({
19
24
  visible: Boolean(open),
20
25
  rail: false,
@@ -46,8 +51,8 @@ function resolveShellDrawerPresentation({
46
51
  });
47
52
  }
48
53
 
49
- function resolveShellDrawerToggleLabel({ compact = false, open = false } = {}) {
50
- if (compact) {
54
+ function resolveShellDrawerToggleLabel({ modal = false, open = false } = {}) {
55
+ if (modal) {
51
56
  return open ? t("jskit.shell.layout.closeNavigationMenu") : t("jskit.shell.layout.openNavigationMenu");
52
57
  }
53
58
  return open ? t("jskit.shell.layout.collapseNavigationDrawer") : t("jskit.shell.layout.expandNavigationDrawer");
@@ -1,4 +1,7 @@
1
1
  const DEFAULT_SHELL_DRAWER_WIDTH = 248;
2
+ // Material 3's navigation drawer is 360dp wide; a modal one leaves at least 56dp of the page showing beside it.
3
+ const MATERIAL_DRAWER_WIDTH = 360;
4
+ const MATERIAL_MODAL_DRAWER_EDGE = 56;
2
5
  const DEFAULT_SHELL_RAIL_WIDTH = 80;
3
6
  const MINIMUM_SHELL_DRAWER_WIDTH = 120;
4
7
  const MAXIMUM_SHELL_DRAWER_WIDTH = 360;
@@ -51,6 +54,18 @@ function normalizeShellNavigationItemSpacing(
51
54
  );
52
55
  }
53
56
 
57
+ /**
58
+ * The Material 3 drawer width: 360dp, narrowed on a small window so a modal drawer leaves 56dp of the page.
59
+ * @param {{ modal?: boolean, viewportWidth?: number }} [options]
60
+ */
61
+ function resolveMaterialDrawerWidth({ modal = false, viewportWidth = Number.POSITIVE_INFINITY } = {}) {
62
+ const available = Number(viewportWidth) - MATERIAL_MODAL_DRAWER_EDGE;
63
+ if (!modal || !Number.isFinite(available)) {
64
+ return MATERIAL_DRAWER_WIDTH;
65
+ }
66
+ return clampNumber(Math.floor(available), MINIMUM_SHELL_DRAWER_WIDTH, MATERIAL_DRAWER_WIDTH);
67
+ }
68
+
54
69
  function resolveContentAwareDrawerWidth(
55
70
  measurements = [],
56
71
  {
@@ -120,11 +135,13 @@ export {
120
135
  DEFAULT_SHELL_DRAWER_WIDTH,
121
136
  DEFAULT_SHELL_NAVIGATION_ITEM_SPACING,
122
137
  DEFAULT_SHELL_RAIL_WIDTH,
138
+ MATERIAL_DRAWER_WIDTH,
123
139
  MAXIMUM_SHELL_DRAWER_WIDTH,
124
140
  MINIMUM_SHELL_DRAWER_WIDTH,
125
141
  measureDrawerContentWidth,
126
142
  normalizeShellDrawerWidth,
127
143
  normalizeShellNavigationItemSpacing,
128
144
  normalizeShellRailWidth,
129
- resolveContentAwareDrawerWidth
145
+ resolveContentAwareDrawerWidth,
146
+ resolveMaterialDrawerWidth
130
147
  };