@jskit-ai/shell-web 0.2.13 → 0.2.15

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 (58) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/fixtures/adaptive-shell/src/ActionsFormPage.vue +22 -0
  3. package/fixtures/adaptive-shell/src/ActionsPage.vue +74 -0
  4. package/fixtures/adaptive-shell/src/App.vue +1 -0
  5. package/fixtures/adaptive-shell/src/ButtonStatesPage.vue +63 -0
  6. package/fixtures/adaptive-shell/src/ButtonsPage.vue +33 -3
  7. package/fixtures/adaptive-shell/src/ComponentsPage.vue +178 -0
  8. package/fixtures/adaptive-shell/src/FeedbackPage.vue +59 -0
  9. package/fixtures/adaptive-shell/src/ReportsPage.vue +29 -0
  10. package/fixtures/adaptive-shell/src/StatusButton.vue +17 -0
  11. package/fixtures/adaptive-shell/src/TitleClaim.vue +17 -0
  12. package/fixtures/adaptive-shell/src/main.js +131 -5
  13. package/fixtures/production-build/index.html +15 -0
  14. package/fixtures/production-build/package.json +5 -0
  15. package/fixtures/production-build/src/App.vue +27 -0
  16. package/fixtures/production-build/src/componentChunk.css +5 -0
  17. package/fixtures/production-build/src/main.js +10 -0
  18. package/fixtures/production-build/vite.config.mjs +12 -0
  19. package/locales/en.json +1 -0
  20. package/package.json +9 -5
  21. package/patterns/application-shell/PATTERN.md +11 -6
  22. package/patterns/application-shell/example/src/components/menus/SectionTabLinkItem.vue +42 -0
  23. package/patterns/application-shell/example/src/pages/home.vue +1 -1
  24. package/patterns/application-shell/example/src/views/NotFound.vue +1 -1
  25. package/patterns/page-and-placement/PATTERN.md +6 -0
  26. package/patterns/page-and-placement/example/src/pages/home/reports.vue +9 -4
  27. package/patterns/page-and-placement/example/src/placementTopology.js +5 -3
  28. package/src/client/components/ShellErrorHost.vue +20 -1
  29. package/src/client/components/ShellLayout.vue +42 -27
  30. package/src/client/components/ShellNavigationItem.vue +8 -3
  31. package/src/client/components/ShellNavigationScope.vue +1 -1
  32. package/src/client/components/ShellOutlet.vue +12 -1
  33. package/src/client/components/ShellPageAction.vue +107 -28
  34. package/src/client/components/ShellPageActionsTarget.vue +81 -2
  35. package/src/client/components/ShellPrimaryAction.vue +69 -0
  36. package/src/client/components/ShellSectionTabLinkItem.vue +104 -0
  37. package/src/client/components/ShellTabLinkItem.vue +18 -3
  38. package/src/client/components/ShellUpButton.vue +13 -8
  39. package/src/client/composables/useShellAppBar.js +10 -1
  40. package/src/client/composables/useShellPageClose.js +18 -0
  41. package/src/client/index.js +3 -0
  42. package/src/client/navigation/shellNavigationRuntime.js +59 -12
  43. package/src/client/navigation/usePaths.js +13 -0
  44. package/src/client/navigation/useShellNavigation.js +2 -0
  45. package/src/client/providers/ShellWebClientProvider.js +25 -9
  46. package/src/client/support/drawerPresentation.js +23 -6
  47. package/src/client/support/navigationPresentation.js +1 -1
  48. package/src/client/support/pageActions.js +126 -0
  49. package/src/test/adaptiveShellSmoke.js +31 -16
  50. package/test/adaptiveShell.browser.test.js +1019 -334
  51. package/test/drawerPresentation.test.js +20 -2
  52. package/test/linkResolver.test.js +4 -0
  53. package/test/materialBaselines.browser.test.js +142 -27
  54. package/test/packageRouteParent.test.js +41 -0
  55. package/test/pageActions.test.js +84 -0
  56. package/test/productionBuild.browser.test.js +98 -0
  57. package/test/settingsPlacementContract.test.js +11 -4
  58. package/test/shellNavigationRuntime.test.js +272 -0
@@ -5,12 +5,24 @@ import {
5
5
  shellNavigationLinkProps,
6
6
  useShellNavigationLink
7
7
  } from "../composables/useShellNavigationLink.js";
8
- import { NO_VUETIFY_ICONS, VUETIFY_ICONS_KEY, filledIconAlias } from "../support/navigationPresentation.js";
8
+ import {
9
+ NO_SHELL_NAVIGATION_PRESENTATION,
10
+ NO_VUETIFY_ICONS,
11
+ SHELL_NAVIGATION_PRESENTATION_KEY,
12
+ VUETIFY_ICONS_KEY,
13
+ filledIconAlias
14
+ } from "../support/navigationPresentation.js";
9
15
  import { useJskitText } from "../i18n.js";
16
+ import ShellSectionTabLinkItem from "./ShellSectionTabLinkItem.vue";
10
17
 
11
18
  // A Material 3 navigation bar destination: the icon in a 64x32 indicator with its label below; the active one's
12
- // indicator is filled and so is its icon.
19
+ // indicator is filled and so is its icon. It is one only in ShellLayout's navigation bar; placed anywhere else (a
20
+ // page's section tabs), it is a section tab, ShellSectionTabLinkItem, which a page.section-nav names itself.
21
+ // In the bar it is a text button in on-surface-variant of its own, so no app's filled-button defaults fill it.
13
22
  const props = defineProps(shellNavigationLinkProps);
23
+ /** @type {{ value: string }} */
24
+ const presentation = inject(SHELL_NAVIGATION_PRESENTATION_KEY, NO_SHELL_NAVIGATION_PRESENTATION);
25
+ const inNavigationBar = computed(() => presentation.value === "bar");
14
26
  const { t } = useJskitText();
15
27
  const { resolvedLabel, resolvedTarget, resolvedIcon } = useShellNavigationLink(props);
16
28
  /** @type {{ aliases?: Record<string, unknown> }} */
@@ -25,8 +37,9 @@ const displayIcon = computed(() =>
25
37
  </script>
26
38
 
27
39
  <template>
40
+ <ShellSectionTabLinkItem v-if="!inNavigationBar" v-bind="props" />
28
41
  <v-btn
29
- v-if="resolvedTarget.href"
42
+ v-else-if="resolvedTarget.href"
30
43
  class="tab-link-item text-none"
31
44
  :class="{ 'tab-link-item--active': active }"
32
45
  :to="resolvedTarget.sameOrigin ? resolvedTarget.href : undefined"
@@ -35,6 +48,8 @@ const displayIcon = computed(() =>
35
48
  :disabled="props.disabled"
36
49
  :exact="props.exact"
37
50
  :ripple="false"
51
+ variant="text"
52
+ color="on-surface-variant"
38
53
  min-width="0"
39
54
  stacked
40
55
  >
@@ -1,15 +1,19 @@
1
1
  <script setup>
2
+ import { computed } from "vue";
2
3
  import { useJskitText } from "../i18n.js";
3
- import { useShellNavigation } from "../navigation/useShellNavigation.js";
4
+ import { useShellNavigation, useShellNavigationRuntime } from "../navigation/useShellNavigation.js";
4
5
 
5
6
  // The top app bar's Up arrow. On an inner page (one that declares meta.jskit.parent) it returns to where the person
6
- // came from or else to that parent, through JSKIT navigation; on a top-level page it renders nothing. ShellLayout's
7
- // bar shows it; a layout that draws its own top app bar puts it first in that bar and calls useShellAppBar().
8
- const { t } = useJskitText();
7
+ // came from or else to that parent, through JSKIT navigation; on a top-level page it renders nothing. On a page that
8
+ // closes (useShellPageClose(), such as a new or edit form) it is that page's close (X) instead. ShellLayout's bar
9
+ // shows it; a layout that draws its own top app bar puts it first in that bar and calls useShellAppBar().
10
+ const { t, text } = useJskitText();
9
11
  const { canGoUp, up } = useShellNavigation();
12
+ const pageClose = useShellNavigationRuntime().pageClose;
13
+ const label = computed(() => (pageClose.value ? text(pageClose.value.label()) : t("jskit.shell.actions.back")));
10
14
 
11
15
  function goUp() {
12
- void up();
16
+ void (pageClose.value ? pageClose.value.close() : up());
13
17
  }
14
18
  </script>
15
19
 
@@ -20,10 +24,11 @@ function goUp() {
20
24
  variant="text"
21
25
  color="on-surface"
22
26
  data-testid="jskit-shell-back"
23
- :aria-label="t('jskit.shell.actions.back')"
27
+ :aria-label="label"
28
+ :data-action="pageClose ? 'close' : 'up'"
24
29
  @click="goUp"
25
30
  >
26
- <v-icon icon="$arrowBack" />
27
- <v-tooltip activator="parent" location="bottom" :text="t('jskit.shell.actions.back')" />
31
+ <v-icon :icon="pageClose ? '$close' : '$arrowBack'" />
32
+ <v-tooltip activator="parent" location="bottom" :text="label" />
28
33
  </v-btn>
29
34
  </template>
@@ -1,18 +1,25 @@
1
1
  import { onBeforeUnmount, onMounted, provide } from "vue";
2
2
  import { useShellNavigationRuntime } from "../navigation/useShellNavigation.js";
3
3
  import { SHELL_PAGE_ACTIONS_ID, SHELL_PAGE_ACTIONS_TARGET_KEY } from "../support/navigationPresentation.js";
4
+ import { SHELL_PAGE_ACTIONS_REGISTRY_KEY, createShellPageActionsRegistry } from "../support/pageActions.js";
5
+ import { useShellWindowSizeClass } from "./useShellWindowSizeClass.js";
4
6
 
5
7
  /**
6
8
  * Makes the calling layout the owner of the shell's top app bar: the pages it renders enter the navigation trail, so
7
- * Up returns to where a page was opened from, and their ShellPageActions show in its ShellPageActionsTarget.
9
+ * Up returns to where a page was opened from, and their ShellPageActions show in its ShellPageActionsTarget, with
10
+ * the bar's overflow menu for the actions that go there.
8
11
  * ShellLayout calls it. A layout that draws its own top app bar calls it once and renders ShellUpButton,
9
12
  * ShellPageTitle and ShellPageActionsTarget in that bar.
13
+ * @returns {{ pageActions: import("../support/pageActions.js").ShellPageActionsRegistry }} The bar's page actions,
14
+ * whose `hasPrimary` tells a compact bar whether its one trailing place is taken.
10
15
  */
11
16
  function useShellAppBar() {
12
17
  const navigationRuntime = useShellNavigationRuntime();
18
+ const pageActions = createShellPageActionsRegistry({ isCompact: useShellWindowSizeClass().isCompact });
13
19
  let release = null;
14
20
 
15
21
  provide(SHELL_PAGE_ACTIONS_TARGET_KEY, `#${SHELL_PAGE_ACTIONS_ID}`);
22
+ provide(SHELL_PAGE_ACTIONS_REGISTRY_KEY, pageActions);
16
23
 
17
24
  onMounted(() => {
18
25
  release = navigationRuntime.attachShell();
@@ -22,6 +29,8 @@ function useShellAppBar() {
22
29
  release?.();
23
30
  release = null;
24
31
  });
32
+
33
+ return { pageActions };
25
34
  }
26
35
 
27
36
  export { useShellAppBar };
@@ -0,0 +1,18 @@
1
+ import { onScopeDispose, toValue } from "vue";
2
+ import { useShellNavigationRuntime } from "../navigation/useShellNavigation.js";
3
+
4
+ /**
5
+ * Makes the calling page a task that closes, as Material 3 draws a full-screen form: while the calling component
6
+ * lives, the top app bar's Up arrow is a close (X) labelled `label` that runs `close`, such as the form's Cancel, so
7
+ * the bar shows no Up arrow beside an X. A page without an Up arrow is unchanged and shows its own Cancel.
8
+ * @param {object} options
9
+ * @param {import("vue").MaybeRefOrGetter<string>} options.label A message key or plain text.
10
+ * @param {() => unknown} options.close
11
+ */
12
+ function useShellPageClose({ label, close }) {
13
+ const runtime = useShellNavigationRuntime();
14
+ const release = runtime.setPageClose({ label: () => String(toValue(label) || ""), close });
15
+ onScopeDispose(release);
16
+ }
17
+
18
+ export { useShellPageClose };
@@ -10,8 +10,10 @@ export { default as ShellErrorHost } from "./components/ShellErrorHost.vue";
10
10
  export { default as ShellMenuLinkItem } from "./components/ShellMenuLinkItem.vue";
11
11
  export { default as ShellSurfaceAwareMenuLinkItem } from "./components/ShellSurfaceAwareMenuLinkItem.vue";
12
12
  export { default as ShellTabLinkItem } from "./components/ShellTabLinkItem.vue";
13
+ export { default as ShellSectionTabLinkItem } from "./components/ShellSectionTabLinkItem.vue";
13
14
  export { default as ShellPageActions } from "./components/ShellPageActions.vue";
14
15
  export { default as ShellPageAction } from "./components/ShellPageAction.vue";
16
+ export { default as ShellPrimaryAction } from "./components/ShellPrimaryAction.vue";
15
17
  export { default as ShellListDetail } from "./components/ShellListDetail.vue";
16
18
  export { default as ShellUpButton } from "./components/ShellUpButton.vue";
17
19
  export { default as ShellPageTitle } from "./components/ShellPageTitle.vue";
@@ -19,6 +21,7 @@ export { default as ShellPageActionsTarget } from "./components/ShellPageActions
19
21
  export { useShellAppBar } from "./composables/useShellAppBar.js";
20
22
  export { useShellLayoutState } from "./composables/useShellLayoutState.js";
21
23
  export { useShellPageTitle } from "./composables/useShellPageTitle.js";
24
+ export { useShellPageClose } from "./composables/useShellPageClose.js";
22
25
  export { useShellWindowSizeClass } from "./composables/useShellWindowSizeClass.js";
23
26
  export { useShellNavigation } from "./navigation/useShellNavigation.js";
24
27
  export { leaveApp, reloadAppPage } from "./navigation/documentNavigation.js";
@@ -1,4 +1,4 @@
1
- import { shallowRef } from "vue";
1
+ import { computed, shallowRef } from "vue";
2
2
  import { NavigationFailureType, isNavigationFailure } from "vue-router";
3
3
  import { staysOnSamePage } from "@jskit-ai/kernel/client";
4
4
  import { isRecord } from "@jskit-ai/kernel/shared/support/normalize";
@@ -78,6 +78,32 @@ function cssAttributeValue(value) {
78
78
  return String(value).replace(/["\\]/gu, "\\$&");
79
79
  }
80
80
 
81
+ /**
82
+ * @typedef {object} ShellPageClose
83
+ * @property {() => string} label The close's label, a message key or plain text.
84
+ * @property {() => unknown} close What choosing it does, such as a form's Cancel.
85
+ */
86
+
87
+ /**
88
+ * Claims of one kind, the latest on top: `top` is the latest claim's value, and releasing a claim shows the one below
89
+ * it again.
90
+ * @template T
91
+ * @returns {{ top: import("vue").ComputedRef<T | null>, claim: (value: T) => () => void }}
92
+ */
93
+ function createClaimStack() {
94
+ const claims = shallowRef([]);
95
+ return {
96
+ top: computed(() => claims.value.at(-1)?.value ?? null),
97
+ claim(value) {
98
+ const entry = { value };
99
+ claims.value = [...claims.value, entry];
100
+ return () => {
101
+ claims.value = claims.value.filter((candidate) => candidate !== entry);
102
+ };
103
+ }
104
+ };
105
+ }
106
+
81
107
  /**
82
108
  * The shell's Up navigation (Material's Up and Back model): one trail per browser tab, kept in history state.
83
109
  * In-app navigation to another inner page pushes the page left; same-page changes, replacements and top-level
@@ -89,7 +115,10 @@ function cssAttributeValue(value) {
89
115
  */
90
116
  function createShellNavigationRuntime({ router }) {
91
117
  const trail = shallowRef([]);
92
- const pageTitleSource = shallowRef(null);
118
+ const titleClaims = createClaimStack();
119
+ const pageTitleSource = titleClaims.top;
120
+ const closeClaims = createClaimStack();
121
+ const pageClose = closeClaims.top;
93
122
  const visibleParentPanes = shallowRef(0);
94
123
  const removeHooks = [];
95
124
  let current = {
@@ -180,13 +209,16 @@ function createShellNavigationRuntime({ router }) {
180
209
  return null;
181
210
  }
182
211
 
183
- // After Up or Back, focus the element that opened the page left, or else the page title.
212
+ // After Up or Back, focus the element that opened the page left, or else the page title. The next navigation
213
+ // cancels it (handleBeforeEach), and so does focus moved since it was scheduled: a person already typing in a field
214
+ // keeps the caret there.
184
215
  function scheduleFocus(leftPath) {
185
216
  clearFocusTimer();
186
217
  const windowRef = pageWindow();
187
218
  if (!windowRef) {
188
219
  return;
189
220
  }
221
+ const focusedWhenScheduled = pageDocument()?.activeElement || null;
190
222
  let attempts = 0;
191
223
  const tryFocus = () => {
192
224
  focusTimer = null;
@@ -194,6 +226,10 @@ function createShellNavigationRuntime({ router }) {
194
226
  if (!documentRef) {
195
227
  return;
196
228
  }
229
+ const focused = documentRef.activeElement;
230
+ if (focused && focused !== documentRef.body && focused !== focusedWhenScheduled) {
231
+ return;
232
+ }
197
233
  const opener = findOpener(documentRef, leftPath);
198
234
  if (opener) {
199
235
  opener.focus({ preventScroll: true });
@@ -210,6 +246,7 @@ function createShellNavigationRuntime({ router }) {
210
246
  }
211
247
 
212
248
  function handleBeforeEach(to, from) {
249
+ clearFocusTimer();
213
250
  if (pending && !pending.redirected && pending.fallback && to.redirectedFrom && sameLocation(to.redirectedFrom.fullPath, pending.target)) {
214
251
  // The trail's page now redirects (no access, workspace left): go to the declared parent instead.
215
252
  pending = {
@@ -370,7 +407,9 @@ function createShellNavigationRuntime({ router }) {
370
407
 
371
408
  /**
372
409
  * 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.
410
+ * reopens it: to `target` when given, otherwise back to where it was opened from, or else its declared parent. A
411
+ * target that is the page the form was opened from, given without a query or hash of its own, returns to that entry
412
+ * as it was: its list query (filters, search, sort, page) and scroll.
374
413
  * @param {import("vue-router").RouteLocationRaw} target
375
414
  * @param {string} parentTarget
376
415
  */
@@ -382,8 +421,9 @@ function createShellNavigationRuntime({ router }) {
382
421
  }
383
422
  const resolved = router.resolve(destination);
384
423
  const returning = Boolean(top && router.resolve(top.path).path === resolved.path);
424
+ const bare = Object.keys(resolved.query).length === 0 && !resolved.hash;
385
425
  return navigate({
386
- target: resolved.fullPath,
426
+ target: returning && bare ? top.path : resolved.fullPath,
387
427
  trail: replacedTrail(current.trail, resolved),
388
428
  scroll: returning ? top.scroll : null,
389
429
  focusPath: returning ? router.currentRoute.value.fullPath : "",
@@ -419,16 +459,21 @@ function createShellNavigationRuntime({ router }) {
419
459
  }
420
460
 
421
461
  /**
422
- * Shows a title in the app bar while the caller lives; returns its release.
462
+ * Shows a title in the app bar while the caller lives, over earlier claims; returns its release, which shows the
463
+ * previous claim's title again (the route's title once none is left).
423
464
  * @param {() => string} source
424
465
  */
425
466
  function setPageTitle(source) {
426
- pageTitleSource.value = source;
427
- return () => {
428
- if (pageTitleSource.value === source) {
429
- pageTitleSource.value = null;
430
- }
431
- };
467
+ return titleClaims.claim(source);
468
+ }
469
+
470
+ /**
471
+ * Turns the app bar's Up arrow into a close (X) that runs `close.close`, labelled `close.label()`, while the caller
472
+ * lives, over earlier claims; returns its release, which gives the arrow back once none is left.
473
+ * @param {ShellPageClose} close
474
+ */
475
+ function setPageClose(close) {
476
+ return closeClaims.claim(close);
432
477
  }
433
478
 
434
479
  /** Marks a parent pane as visible beside the page (list-detail), so the page shows no Up arrow; returns its release. */
@@ -458,6 +503,7 @@ function createShellNavigationRuntime({ router }) {
458
503
  return {
459
504
  trail,
460
505
  pageTitleSource,
506
+ pageClose,
461
507
  visibleParentPanes,
462
508
  install,
463
509
  dispose,
@@ -465,6 +511,7 @@ function createShellNavigationRuntime({ router }) {
465
511
  finish,
466
512
  pageUnavailable,
467
513
  setPageTitle,
514
+ setPageClose,
468
515
  showParentPane,
469
516
  attachShell
470
517
  };
@@ -48,8 +48,21 @@ function usePaths({ routeContext = useSurfaceRouteContext() } = {}) {
48
48
  const shellLinkResolver = useShellLinkResolver();
49
49
  const routeParams = computed(() => normalizeRouteParams(routeContext.route.params));
50
50
 
51
+ /**
52
+ * A page's path: on the current surface (or `options.surface`), its params filled from the route and
53
+ * `options.params`. A global route (a route with `scope: "global"`, such as /auth/login) belongs to no surface:
54
+ * `{ scope: "global" }` gives its app path, params filled the same way. `explicitTo` passes a finished target
55
+ * through unchanged, for a target that arrives as data.
56
+ */
51
57
  function page(relativePath = "/", options = {}) {
52
58
  const source = normalizeObject(options);
59
+ if (source.scope === "global") {
60
+ return shellLinkResolver.resolve(relativePath, {
61
+ surface: "",
62
+ params: resolveRouteParams(routeParams.value, source.params),
63
+ strictParams: source.strictParams !== false
64
+ });
65
+ }
53
66
  const surface =
54
67
  resolveSurfaceId(source.surface, routeContext.currentSurfaceId.value) ||
55
68
  resolveDefaultSurfaceIdFromPlacementContext(routeContext.placementContext.value);
@@ -17,11 +17,13 @@ function releaseNothing() {}
17
17
  const NO_SHELL_NAVIGATION_RUNTIME = Object.freeze({
18
18
  trail: Object.freeze({ value: Object.freeze([]) }),
19
19
  pageTitleSource: Object.freeze({ value: null }),
20
+ pageClose: Object.freeze({ value: null }),
20
21
  visibleParentPanes: Object.freeze({ value: 0 }),
21
22
  up: resolvedNothing,
22
23
  finish: resolvedNothing,
23
24
  pageUnavailable: () => false,
24
25
  setPageTitle: () => releaseNothing,
26
+ setPageClose: () => releaseNothing,
25
27
  showParentPane: () => releaseNothing,
26
28
  attachShell: () => releaseNothing
27
29
  });
@@ -106,9 +106,24 @@ async function loadAppModule({
106
106
  return fallback;
107
107
  }
108
108
 
109
- function loadAppPlacementDefinitions(logger, asyncModuleRecoveryRuntime) {
109
+ // Starts the app's optional modules downloading together, so boot waits for the slowest one instead of each in
110
+ // turn; each is still read, checked and applied in order. A missing module is expected, so each import gets a
111
+ // handler at once and its failure is read where it is awaited.
112
+ function importAppModules() {
113
+ const imports = {
114
+ placements: import("/src/placement.js"),
115
+ placementTopology: import("/src/placementTopology.js"),
116
+ errorConfig: import("/src/error.js")
117
+ };
118
+ for (const pending of Object.values(imports)) {
119
+ pending.catch(() => {});
120
+ }
121
+ return imports;
122
+ }
123
+
124
+ function loadAppPlacementDefinitions(logger, asyncModuleRecoveryRuntime, pendingImport) {
110
125
  return loadAppModule({
111
- importModule: () => import("/src/placement.js"),
126
+ importModule: () => pendingImport,
112
127
  specifier: APP_PLACEMENT_MODULE_SPECIFIER,
113
128
  label: t("jskit.shell.recovery.placementConfigLabel"),
114
129
  resolve(exported) {
@@ -123,9 +138,9 @@ function loadAppPlacementDefinitions(logger, asyncModuleRecoveryRuntime) {
123
138
  });
124
139
  }
125
140
 
126
- function loadAppPlacementTopology(logger, asyncModuleRecoveryRuntime) {
141
+ function loadAppPlacementTopology(logger, asyncModuleRecoveryRuntime, pendingImport) {
127
142
  return loadAppModule({
128
- importModule: () => import("/src/placementTopology.js"),
143
+ importModule: () => pendingImport,
129
144
  specifier: APP_PLACEMENT_TOPOLOGY_MODULE_SPECIFIER,
130
145
  label: t("jskit.shell.recovery.placementTopologyLabel"),
131
146
  resolve: (exported) => resolveAppPlacementTopologyExport(exported, logger),
@@ -168,9 +183,9 @@ function createErrorConfigToolkit(errorRuntime) {
168
183
  });
169
184
  }
170
185
 
171
- function loadAppErrorConfig(logger, errorRuntime, asyncModuleRecoveryRuntime) {
186
+ function loadAppErrorConfig(logger, errorRuntime, asyncModuleRecoveryRuntime, pendingImport) {
172
187
  return loadAppModule({
173
- importModule: () => import("/src/error.js"),
188
+ importModule: () => pendingImport,
174
189
  specifier: APP_ERROR_MODULE_SPECIFIER,
175
190
  label: t("jskit.shell.recovery.errorConfigLabel"),
176
191
  async resolve(exported) {
@@ -353,9 +368,10 @@ const ShellWebClientProvider = defineProvider({
353
368
  // Before the router's first navigation, so the trail starts with the page the tab opened on.
354
369
  navigationRuntime.install();
355
370
 
356
- const placementTopology = await loadAppPlacementTopology(logger, asyncModuleRecoveryRuntime);
371
+ const appModules = importAppModules();
372
+ const placementTopology = await loadAppPlacementTopology(logger, asyncModuleRecoveryRuntime, appModules.placementTopology);
357
373
  placementRuntime.replacePlacementTopology(placementTopology, { source: APP_PLACEMENT_TOPOLOGY_MODULE_SPECIFIER });
358
- const placements = await loadAppPlacementDefinitions(logger, asyncModuleRecoveryRuntime);
374
+ const placements = await loadAppPlacementDefinitions(logger, asyncModuleRecoveryRuntime, appModules.placements);
359
375
  placementRuntime.replacePlacements(placements, { source: APP_PLACEMENT_MODULE_SPECIFIER });
360
376
  const appConfig = getClientAppConfig();
361
377
  const surfaceConfig = buildSurfaceConfigContext(surfaceRuntime, {
@@ -371,7 +387,7 @@ const ShellWebClientProvider = defineProvider({
371
387
  }
372
388
  );
373
389
 
374
- const errorConfig = await loadAppErrorConfig(logger, errorRuntime, asyncModuleRecoveryRuntime);
390
+ const errorConfig = await loadAppErrorConfig(logger, errorRuntime, asyncModuleRecoveryRuntime, appModules.errorConfig);
375
391
  errorRuntime.configure(errorConfig);
376
392
  requestRecoveryRuntime.install();
377
393
  // After the app's error configuration, so the offer follows its policy.
@@ -58,15 +58,31 @@ function resolveShellDrawerToggleLabel({ modal = false, open = false } = {}) {
58
58
  return open ? t("jskit.shell.layout.collapseNavigationDrawer") : t("jskit.shell.layout.expandNavigationDrawer");
59
59
  }
60
60
 
61
+ // Material 3 navigation (a bar, a rail, a drawer) moves between destinations: with one in all, such as Home alone,
62
+ // there is nowhere to go, and the shell draws none. Each destination is in one outlet at a time (on a phone the bar's
63
+ // are not in the drawer), so the outlets' counts add up to the surface's destinations.
64
+ const MIN_NAVIGATION_DESTINATIONS = 2;
65
+
61
66
  /**
62
- * Whether a surface has a drawer (and so a rail and a menu control): it has one when it has menu destinations or its
63
- * own menu. The surface identity (a workspace switcher) keeps it only beside navigation, as on a phone whose
64
- * destinations are all in the navigation bar; a surface with no navigation at all, such as an account surface, has
65
- * none.
67
+ * Whether a surface has a drawer (and so a rail and a menu control): it has one when it holds a menu destination of a
68
+ * surface with two or more in all, or its own menu. The surface identity (a workspace switcher) keeps it beside any
69
+ * navigation, as on a phone whose destinations are all in the navigation bar; a surface with no navigation at all,
70
+ * such as an account surface, or with Home alone, has none.
66
71
  * @param {{ menuSlot?: boolean, menuCount?: number, identityCount?: number, bottomNavigationCount?: number }} outlets
67
72
  */
68
73
  function shellLayoutHasDrawer({ menuSlot = false, menuCount = 0, identityCount = 0, bottomNavigationCount = 0 } = {}) {
69
- return menuSlot || menuCount > 0 || (identityCount > 0 && bottomNavigationCount > 0);
74
+ const destinations = menuCount + bottomNavigationCount;
75
+ return menuSlot ||
76
+ (menuCount > 0 && destinations >= MIN_NAVIGATION_DESTINATIONS) ||
77
+ (identityCount > 0 && destinations > 0);
78
+ }
79
+
80
+ /**
81
+ * Whether a compact window shows the navigation bar: it holds a destination of a surface with two or more in all.
82
+ * @param {{ bottomNavigationCount?: number, menuCount?: number }} outlets
83
+ */
84
+ function shellLayoutHasNavigationBar({ bottomNavigationCount = 0, menuCount = 0 } = {}) {
85
+ return bottomNavigationCount > 0 && bottomNavigationCount + menuCount >= MIN_NAVIGATION_DESTINATIONS;
70
86
  }
71
87
 
72
88
  export {
@@ -74,5 +90,6 @@ export {
74
90
  normalizeDesktopDrawerClosedMode,
75
91
  resolveShellDrawerPresentation,
76
92
  resolveShellDrawerToggleLabel,
77
- shellLayoutHasDrawer
93
+ shellLayoutHasDrawer,
94
+ shellLayoutHasNavigationBar
78
95
  };
@@ -1,4 +1,4 @@
1
- /** How navigation items inside it present: "rail", "drawer" or, outside the shell's navigation, "list". */
1
+ /** How navigation items inside it present: "rail", "drawer", the navigation "bar" or, outside the shell's navigation, "list". */
2
2
  const SHELL_NAVIGATION_PRESENTATION_KEY = "jskit.shell-web.navigation.presentation";
3
3
  /** Navigation items outside the shell's drawer and rail, such as a settings section's own menu, present as a list. */
4
4
  const NO_SHELL_NAVIGATION_PRESENTATION = Object.freeze({ value: "list" });
@@ -0,0 +1,126 @@
1
+ import { computed, shallowRef } from "vue";
2
+
3
+ /**
4
+ * The page actions of the top app bar that owns them (useShellAppBar()), for its overflow menu. A compact bar keeps
5
+ * one trailing item so the title has the room: the page's primary action (a form's Save), or else the bar's own item
6
+ * nearest the corner (the account avatar); every other action and item is in the overflow menu.
7
+ */
8
+ const SHELL_PAGE_ACTIONS_REGISTRY_KEY = "jskit.shell-web.layout.page-actions-registry";
9
+ // Node.DOCUMENT_POSITION_PRECEDING and DOCUMENT_POSITION_FOLLOWING, without the browser's Node.
10
+ const PRECEDING = 2;
11
+ const FOLLOWING = 4;
12
+
13
+ /**
14
+ * @typedef {object} ShellPageActionState
15
+ * @property {string} label The resolved label, also the menu item's title.
16
+ * @property {string} icon
17
+ * @property {unknown} to
18
+ * @property {string | undefined} href
19
+ * @property {boolean} replace
20
+ * @property {string | undefined} download
21
+ * @property {string | undefined} color
22
+ * @property {boolean} primary
23
+ * @property {boolean} overflow
24
+ * @property {boolean} disabled
25
+ * @property {boolean} loading
26
+ */
27
+
28
+ /**
29
+ * @typedef {object} ShellPageActionEntry
30
+ * @property {string} id
31
+ * @property {import("vue").ComputedRef<ShellPageActionState>} state
32
+ * @property {Record<string, unknown>} attrs The action's own attributes (data-testid, target, ...).
33
+ * @property {(event: Event) => void} activate What choosing the action does.
34
+ * @property {Element | Comment | null} anchor Where the action sits in the bar, for its order.
35
+ */
36
+
37
+ /**
38
+ * @typedef {object} ShellPageActionsRegistry
39
+ * @property {import("vue").ComputedRef<ShellPageActionEntry[]>} menuEntries The overflow menu's actions, in bar order.
40
+ * @property {import("vue").ComputedRef<boolean>} hasPrimary Whether the bar shows a primary action.
41
+ * @property {(entry: ShellPageActionEntry) => { placed: () => void, release: () => void }} register
42
+ * @property {(entry: ShellPageActionEntry) => boolean} inMenu
43
+ */
44
+
45
+ /**
46
+ * Actions outside a bar that owns them (no ShellLayout, no useShellAppBar()) render where they are written, with no
47
+ * overflow menu.
48
+ * @type {ShellPageActionsRegistry}
49
+ */
50
+ const NO_SHELL_PAGE_ACTIONS_REGISTRY = {
51
+ menuEntries: computed(() => []),
52
+ hasPrimary: computed(() => false),
53
+ register: () => ({ placed() {}, release() {} }),
54
+ inMenu: () => false
55
+ };
56
+
57
+ function documentOrder(left, right) {
58
+ if (!left.anchor || !right.anchor || left.anchor === right.anchor) {
59
+ return 0;
60
+ }
61
+ const position = left.anchor.compareDocumentPosition(right.anchor);
62
+ if (position & FOLLOWING) {
63
+ return -1;
64
+ }
65
+ return position & PRECEDING ? 1 : 0;
66
+ }
67
+
68
+ /**
69
+ * The actions in the overflow menu, in bar order: those marked `overflow`, and on compact windows every action but
70
+ * the primary one.
71
+ * @param {readonly ShellPageActionEntry[]} entries In bar order.
72
+ * @param {boolean} compact
73
+ */
74
+ function overflowEntries(entries, compact) {
75
+ return entries.filter((entry) => entry.state.value.overflow || (compact && !entry.state.value.primary));
76
+ }
77
+
78
+ /**
79
+ * The top app bar's page actions: each ShellPageAction registers while it lives, and the bar's overflow menu shows
80
+ * the ones that go there.
81
+ * @param {{ isCompact: import("vue").Ref<boolean> }} options
82
+ * @returns {ShellPageActionsRegistry}
83
+ */
84
+ function createShellPageActionsRegistry({ isCompact }) {
85
+ const entries = shallowRef(/** @type {ShellPageActionEntry[]} */ ([]));
86
+ const ordered = computed(() => [...entries.value].sort(documentOrder));
87
+ const menuEntries = computed(() => overflowEntries(ordered.value, isCompact.value));
88
+ const hasPrimary = computed(() =>
89
+ ordered.value.some((entry) => entry.state.value.primary && !entry.state.value.overflow)
90
+ );
91
+
92
+ /**
93
+ * @param {ShellPageActionEntry} entry
94
+ * @returns {{ placed: () => void, release: () => void }} `placed()` once its anchor is in the bar; `release()`.
95
+ */
96
+ function register(entry) {
97
+ entries.value = [...entries.value, entry];
98
+ return {
99
+ placed() {
100
+ entries.value = [...entries.value];
101
+ },
102
+ release() {
103
+ entries.value = entries.value.filter((candidate) => candidate !== entry);
104
+ }
105
+ };
106
+ }
107
+
108
+ /** @param {ShellPageActionEntry} entry */
109
+ function inMenu(entry) {
110
+ return menuEntries.value.includes(entry);
111
+ }
112
+
113
+ return {
114
+ menuEntries,
115
+ hasPrimary,
116
+ register,
117
+ inMenu
118
+ };
119
+ }
120
+
121
+ export {
122
+ NO_SHELL_PAGE_ACTIONS_REGISTRY,
123
+ SHELL_PAGE_ACTIONS_REGISTRY_KEY,
124
+ createShellPageActionsRegistry,
125
+ overflowEntries
126
+ };