@jskit-ai/shell-web 0.2.12 → 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 (63) hide show
  1. package/CHANGELOG.md +20 -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 +7 -3
  5. package/fixtures/adaptive-shell/src/ButtonStatesPage.vue +63 -0
  6. package/fixtures/adaptive-shell/src/ButtonsPage.vue +61 -0
  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/OwnBarLayout.vue +13 -1
  10. package/fixtures/adaptive-shell/src/ReportsPage.vue +29 -0
  11. package/fixtures/adaptive-shell/src/StatusButton.vue +17 -0
  12. package/fixtures/adaptive-shell/src/TitleClaim.vue +17 -0
  13. package/fixtures/adaptive-shell/src/main.js +223 -37
  14. package/fixtures/production-build/index.html +15 -0
  15. package/fixtures/production-build/package.json +5 -0
  16. package/fixtures/production-build/src/App.vue +27 -0
  17. package/fixtures/production-build/src/componentChunk.css +5 -0
  18. package/fixtures/production-build/src/main.js +10 -0
  19. package/fixtures/production-build/vite.config.mjs +12 -0
  20. package/locales/en.json +1 -0
  21. package/package.json +9 -5
  22. package/patterns/application-shell/PATTERN.md +11 -6
  23. package/patterns/application-shell/example/src/components/menus/SectionTabLinkItem.vue +42 -0
  24. package/patterns/application-shell/example/src/pages/home.vue +1 -1
  25. package/patterns/application-shell/example/src/views/NotFound.vue +1 -1
  26. package/patterns/page-and-placement/PATTERN.md +6 -0
  27. package/patterns/page-and-placement/example/src/pages/home/reports.vue +9 -4
  28. package/patterns/page-and-placement/example/src/placementTopology.js +5 -3
  29. package/src/client/components/ShellErrorHost.vue +20 -1
  30. package/src/client/components/ShellLayout.vue +64 -28
  31. package/src/client/components/ShellNavigationItem.vue +8 -3
  32. package/src/client/components/ShellNavigationScope.vue +1 -1
  33. package/src/client/components/ShellOutlet.vue +12 -49
  34. package/src/client/components/ShellPageAction.vue +107 -28
  35. package/src/client/components/ShellPageActionsTarget.vue +81 -2
  36. package/src/client/components/ShellPageTitle.vue +6 -3
  37. package/src/client/components/ShellPrimaryAction.vue +69 -0
  38. package/src/client/components/ShellSectionTabLinkItem.vue +104 -0
  39. package/src/client/components/ShellTabLinkItem.vue +18 -3
  40. package/src/client/components/ShellUpButton.vue +13 -8
  41. package/src/client/composables/useShellAppBar.js +10 -1
  42. package/src/client/composables/useShellOutletPlacements.js +49 -0
  43. package/src/client/composables/useShellPageClose.js +18 -0
  44. package/src/client/index.js +3 -0
  45. package/src/client/navigation/documentNavigation.js +6 -3
  46. package/src/client/navigation/linkResolver.js +22 -11
  47. package/src/client/navigation/shellNavigationRuntime.js +50 -11
  48. package/src/client/navigation/usePaths.js +13 -0
  49. package/src/client/navigation/useShellNavigation.js +2 -0
  50. package/src/client/support/drawerPresentation.js +30 -1
  51. package/src/client/support/navigationPresentation.js +1 -1
  52. package/src/client/support/pageActions.js +126 -0
  53. package/src/test/adaptiveShellSmoke.js +31 -16
  54. package/test/adaptiveShell.browser.test.js +1046 -227
  55. package/test/documentNavigation.test.js +44 -0
  56. package/test/drawerPresentation.test.js +31 -1
  57. package/test/linkResolver.test.js +54 -1
  58. package/test/materialBaselines.browser.test.js +142 -27
  59. package/test/packageRouteParent.test.js +41 -0
  60. package/test/pageActions.test.js +84 -0
  61. package/test/productionBuild.browser.test.js +98 -0
  62. package/test/settingsPlacementContract.test.js +11 -4
  63. package/test/shellNavigationRuntime.test.js +181 -0
@@ -58,9 +58,38 @@ 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
+
66
+ /**
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.
71
+ * @param {{ menuSlot?: boolean, menuCount?: number, identityCount?: number, bottomNavigationCount?: number }} outlets
72
+ */
73
+ function shellLayoutHasDrawer({ menuSlot = false, 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;
86
+ }
87
+
61
88
  export {
62
89
  DESKTOP_DRAWER_CLOSED_MODES,
63
90
  normalizeDesktopDrawerClosedMode,
64
91
  resolveShellDrawerPresentation,
65
- resolveShellDrawerToggleLabel
92
+ resolveShellDrawerToggleLabel,
93
+ shellLayoutHasDrawer,
94
+ shellLayoutHasNavigationBar
66
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);