@jskit-ai/shell-web 0.2.13 → 0.2.14

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 (57) hide show
  1. package/CHANGELOG.md +16 -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 +50 -11
  43. package/src/client/navigation/usePaths.js +13 -0
  44. package/src/client/navigation/useShellNavigation.js +2 -0
  45. package/src/client/support/drawerPresentation.js +23 -6
  46. package/src/client/support/navigationPresentation.js +1 -1
  47. package/src/client/support/pageActions.js +126 -0
  48. package/src/test/adaptiveShellSmoke.js +31 -16
  49. package/test/adaptiveShell.browser.test.js +1019 -334
  50. package/test/drawerPresentation.test.js +20 -2
  51. package/test/linkResolver.test.js +4 -0
  52. package/test/materialBaselines.browser.test.js +142 -27
  53. package/test/packageRouteParent.test.js +41 -0
  54. package/test/pageActions.test.js +84 -0
  55. package/test/productionBuild.browser.test.js +98 -0
  56. package/test/settingsPlacementContract.test.js +11 -4
  57. package/test/shellNavigationRuntime.test.js +181 -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 = {
@@ -370,7 +399,9 @@ function createShellNavigationRuntime({ router }) {
370
399
 
371
400
  /**
372
401
  * 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.
402
+ * reopens it: to `target` when given, otherwise back to where it was opened from, or else its declared parent. A
403
+ * target that is the page the form was opened from, given without a query or hash of its own, returns to that entry
404
+ * as it was: its list query (filters, search, sort, page) and scroll.
374
405
  * @param {import("vue-router").RouteLocationRaw} target
375
406
  * @param {string} parentTarget
376
407
  */
@@ -382,8 +413,9 @@ function createShellNavigationRuntime({ router }) {
382
413
  }
383
414
  const resolved = router.resolve(destination);
384
415
  const returning = Boolean(top && router.resolve(top.path).path === resolved.path);
416
+ const bare = Object.keys(resolved.query).length === 0 && !resolved.hash;
385
417
  return navigate({
386
- target: resolved.fullPath,
418
+ target: returning && bare ? top.path : resolved.fullPath,
387
419
  trail: replacedTrail(current.trail, resolved),
388
420
  scroll: returning ? top.scroll : null,
389
421
  focusPath: returning ? router.currentRoute.value.fullPath : "",
@@ -419,16 +451,21 @@ function createShellNavigationRuntime({ router }) {
419
451
  }
420
452
 
421
453
  /**
422
- * Shows a title in the app bar while the caller lives; returns its release.
454
+ * Shows a title in the app bar while the caller lives, over earlier claims; returns its release, which shows the
455
+ * previous claim's title again (the route's title once none is left).
423
456
  * @param {() => string} source
424
457
  */
425
458
  function setPageTitle(source) {
426
- pageTitleSource.value = source;
427
- return () => {
428
- if (pageTitleSource.value === source) {
429
- pageTitleSource.value = null;
430
- }
431
- };
459
+ return titleClaims.claim(source);
460
+ }
461
+
462
+ /**
463
+ * Turns the app bar's Up arrow into a close (X) that runs `close.close`, labelled `close.label()`, while the caller
464
+ * lives, over earlier claims; returns its release, which gives the arrow back once none is left.
465
+ * @param {ShellPageClose} close
466
+ */
467
+ function setPageClose(close) {
468
+ return closeClaims.claim(close);
432
469
  }
433
470
 
434
471
  /** Marks a parent pane as visible beside the page (list-detail), so the page shows no Up arrow; returns its release. */
@@ -458,6 +495,7 @@ function createShellNavigationRuntime({ router }) {
458
495
  return {
459
496
  trail,
460
497
  pageTitleSource,
498
+ pageClose,
461
499
  visibleParentPanes,
462
500
  install,
463
501
  dispose,
@@ -465,6 +503,7 @@ function createShellNavigationRuntime({ router }) {
465
503
  finish,
466
504
  pageUnavailable,
467
505
  setPageTitle,
506
+ setPageClose,
468
507
  showParentPane,
469
508
  attachShell
470
509
  };
@@ -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
  });
@@ -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
+ };
@@ -69,7 +69,16 @@ async function expectElementVisibility(page, expect, testId, visible) {
69
69
  ).toBe(visible);
70
70
  }
71
71
 
72
- async function readShellLayoutClass(drawer) {
72
+ // The layout class comes from the drawer, which carries it; a phone shell whose destinations are all in the
73
+ // navigation bar draws no drawer (or menu control), and its navigation bar says it is compact.
74
+ async function readShellLayoutClass(drawer, bottomNavigation, expect) {
75
+ await expect(
76
+ drawer.or(bottomNavigation).first(),
77
+ "The shell drew neither a drawer nor a navigation bar."
78
+ ).toBeAttached();
79
+ if (await drawer.count() === 0) {
80
+ return "compact";
81
+ }
73
82
  const layoutClass = String(await drawer.getAttribute("data-layout") || "");
74
83
  if (!["compact", "medium", "expanded"].includes(layoutClass)) {
75
84
  throw new Error(`Shell drawer exposed an invalid data-layout value: ${layoutClass || "(empty)"}.`);
@@ -290,8 +299,9 @@ async function runAdaptiveShellSmokeCase({
290
299
  await expect(page.getByRole("main").first()).toBeVisible();
291
300
  await expectNoHorizontalOverflow(page, expect);
292
301
  const drawer = page.getByTestId("jskit-shell-drawer");
302
+ const bottomNavigation = page.getByTestId("jskit-shell-bottom-nav");
293
303
  const toggle = page.getByTestId("jskit-shell-nav-toggle");
294
- const layoutClass = await readShellLayoutClass(drawer);
304
+ const layoutClass = await readShellLayoutClass(drawer, bottomNavigation, expect);
295
305
 
296
306
  if (layoutClass === "compact") {
297
307
  let bootstrapRequests = 0;
@@ -301,21 +311,26 @@ async function runAdaptiveShellSmokeCase({
301
311
  });
302
312
  const bootstrapRequestsBeforePull = bootstrapRequests;
303
313
 
304
- await expect(page.getByTestId("jskit-shell-bottom-nav")).toBeVisible();
305
- await expectElementVisibility(page, expect, "jskit-shell-drawer", false);
306
-
307
- // The modal drawer opens over the app bar, as Material 3 draws it; tapping the scrim beside it closes it.
308
- await openCompactDrawer(page, expect);
309
- await expect(toggle).toHaveAttribute("aria-label", "Close navigation menu");
310
- await page.mouse.click(viewport.width - 8, Math.round(viewport.height / 2));
311
- await expectElementVisibility(page, expect, "jskit-shell-drawer", false);
312
-
313
- await openCompactDrawer(page, expect);
314
- await page.keyboard.press("Escape");
315
- await expectElementVisibility(page, expect, "jskit-shell-drawer", false);
316
- await expect(toggle).toBeFocused();
314
+ await expect(bottomNavigation).toBeVisible();
315
+ if (await drawer.count() === 0) {
316
+ // Every destination is in the navigation bar, so there is no drawer to open and no menu control.
317
+ await expect(toggle).toHaveCount(0);
318
+ } else {
319
+ await expectElementVisibility(page, expect, "jskit-shell-drawer", false);
320
+
321
+ // The modal drawer opens over the app bar, as Material 3 draws it; tapping the scrim beside it closes it.
322
+ await openCompactDrawer(page, expect);
323
+ await expect(toggle).toHaveAttribute("aria-label", "Close navigation menu");
324
+ await page.mouse.click(viewport.width - 8, Math.round(viewport.height / 2));
325
+ await expectElementVisibility(page, expect, "jskit-shell-drawer", false);
326
+
327
+ await openCompactDrawer(page, expect);
328
+ await page.keyboard.press("Escape");
329
+ await expectElementVisibility(page, expect, "jskit-shell-drawer", false);
330
+ await expect(toggle).toBeFocused();
331
+ }
317
332
 
318
- const navButtonHeights = await page.getByTestId("jskit-shell-bottom-nav").locator(".v-btn").evaluateAll((buttons) =>
333
+ const navButtonHeights = await bottomNavigation.locator(".v-btn").evaluateAll((buttons) =>
319
334
  buttons.map((button) => button.getBoundingClientRect().height)
320
335
  );
321
336
  expect(navButtonHeights.length).toBeGreaterThan(0);