@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
@@ -72,9 +72,14 @@ const {
72
72
  </div>
73
73
  </div>
74
74
 
75
+ <!-- Material 3 keeps a snackbar clear of the actions it reports on. Vuetify places it inside the layout, above the
76
+ navigation bar and a FAB that takes layout room (`<v-fab app layout>`). On a phone it is centred there; on
77
+ wider windows it starts at the content's start edge and takes at most half its width, clear of end-aligned
78
+ FABs and form actions (Save), so a person can press Save again while it shows. -->
75
79
  <v-snackbar
76
80
  :model-value="snackbarOpen"
77
- location="bottom end"
81
+ class="shell-error-host__snackbar"
82
+ location="bottom start"
78
83
  :timeout="resolveTimeout(displayedSnackbarEntry)"
79
84
  :vertical="actionsFor(displayedSnackbarEntry).length > 1"
80
85
  @update:model-value="onSnackbarModelValue"
@@ -181,6 +186,20 @@ const {
181
186
  font-size: 20px;
182
187
  }
183
188
 
189
+ /* The snackbar is teleported out of this component, so its rules are written for its own classes. Compact windows
190
+ (below 600dp) centre it; wider ones keep it at the start, at most half the content's width. */
191
+ @media (max-width: 599.98px) {
192
+ :global(.shell-error-host__snackbar.v-snackbar--start) {
193
+ justify-content: center;
194
+ }
195
+ }
196
+
197
+ @media (min-width: 600px) {
198
+ :global(.shell-error-host__snackbar .v-snackbar__wrapper) {
199
+ max-width: min(672px, 50%);
200
+ }
201
+ }
202
+
184
203
  @media (max-width: 600px) {
185
204
  .shell-error-host__banners {
186
205
  padding: 8px;
@@ -1,15 +1,20 @@
1
1
  <script setup>
2
- import { computed, inject, onBeforeUnmount, onMounted, ref } from "vue";
2
+ import { computed, inject, onBeforeUnmount, onMounted, ref, useSlots } from "vue";
3
3
  import { useDisplay } from "vuetify";
4
4
  import { useShellAppBar } from "../composables/useShellAppBar.js";
5
5
  import { useShellDrawer } from "../composables/useShellDrawer.js";
6
+ import { useShellOutletPlacements } from "../composables/useShellOutletPlacements.js";
6
7
  import { useShellLayoutState } from "../composables/useShellLayoutState.js";
7
8
  import { useShellPullToRefresh } from "../composables/useShellPullToRefresh.js";
8
9
  import {
9
10
  DEFAULT_SHELL_NAVIGATION_ITEM_SPACING,
10
11
  DEFAULT_SHELL_RAIL_WIDTH
11
12
  } from "../support/drawerWidth.js";
12
- import { normalizeDesktopDrawerClosedMode } from "../support/drawerPresentation.js";
13
+ import {
14
+ normalizeDesktopDrawerClosedMode,
15
+ shellLayoutHasDrawer,
16
+ shellLayoutHasNavigationBar
17
+ } from "../support/drawerPresentation.js";
13
18
  import { resolveShellLayoutClass } from "../support/shellLayoutClass.js";
14
19
  import { resolveWindowSizeClass } from "../support/windowSizeClass.js";
15
20
  import { NO_SHELL_WEB_REFRESH_RUNTIME, SHELL_WEB_REFRESH_RUNTIME_KEY } from "../runtime/refreshRuntime.js";
@@ -85,8 +90,33 @@ const layoutClass = computed(() => resolveShellLayoutClass(display.width.value))
85
90
  const isCompactLayout = computed(() => layoutClass.value === "compact");
86
91
  // Compact and medium windows open the drawer over the page; a medium window keeps a navigation rail beside it.
87
92
  const modalLayout = computed(() => layoutClass.value !== "expanded");
93
+ // A surface draws only the navigation it has: no navigation bar without two bar destinations, and no rail or drawer
94
+ // (nor its menu control) without two menu destinations, as on an account surface whose shell has no navigation or a
95
+ // surface with Home alone. The surface identity (a workspace switcher) keeps the drawer beside other navigation, as on
96
+ // a phone.
97
+ const slots = useSlots();
98
+ const primaryMenu = useShellOutletPlacements("shell-layout:primary-menu");
99
+ const secondaryMenu = useShellOutletPlacements("shell-layout:secondary-menu");
100
+ const identity = useShellOutletPlacements("shell-layout:top-left");
101
+ const bottomNavigation = useShellOutletPlacements("shell-layout:primary-bottom-nav");
102
+ const hasDrawer = computed(() =>
103
+ shellLayoutHasDrawer({
104
+ menuSlot: Boolean(slots.menu),
105
+ menuCount: primaryMenu.value.length + secondaryMenu.value.length,
106
+ identityCount: slots["top-left"] ? 1 : identity.value.length,
107
+ bottomNavigationCount: bottomNavigation.value.length
108
+ })
109
+ );
110
+ const showsBottomNavigation = computed(() =>
111
+ isCompactLayout.value && shellLayoutHasNavigationBar({
112
+ bottomNavigationCount: bottomNavigation.value.length,
113
+ menuCount: primaryMenu.value.length + secondaryMenu.value.length
114
+ })
115
+ );
88
116
  const showsMediumRail = computed(() =>
89
- layoutClass.value === "medium" && normalizeDesktopDrawerClosedMode(props.desktopDrawerClosedMode) === "rail"
117
+ hasDrawer.value &&
118
+ layoutClass.value === "medium" &&
119
+ normalizeDesktopDrawerClosedMode(props.desktopDrawerClosedMode) === "rail"
90
120
  );
91
121
  const {
92
122
  pullRefreshing,
@@ -105,17 +135,27 @@ const {
105
135
  resolvedRailWidth
106
136
  } = useShellDrawer({ props, modalLayout, viewportWidth, navigationToggle, layoutState });
107
137
 
108
- const standardDrawerVisible = computed(() => !modalLayout.value && drawerPresentation.value.visible);
138
+ const standardDrawerVisible = computed(() => hasDrawer.value && !modalLayout.value && drawerPresentation.value.visible);
109
139
  // The menu control sits in the rail or drawer header when one shows, otherwise first in the app bar of a top-level
110
140
  // page; an inner page's leading slot is its Up arrow.
111
- const toggleInAppBar = computed(() => !showsMediumRail.value && !standardDrawerVisible.value);
141
+ const toggleInAppBar = computed(() => hasDrawer.value && !showsMediumRail.value && !standardDrawerVisible.value);
112
142
  const fallbackTitle = computed(() => text(props.title) || resolvedSurfaceLabel.value);
113
143
  const navigationStyle = computed(() => ({
114
144
  "--shell-navigation-item-spacing": `${resolvedNavigationItemSpacing.value}px`,
115
145
  "--shell-navigation-rail-width": `${resolvedRailWidth.value}px`
116
146
  }));
117
147
 
118
- useShellAppBar();
148
+ // A compact bar keeps one trailing item so the title keeps its room: the page's primary action when it has one (a
149
+ // form's Save), otherwise the top-right item nearest the corner (the account menu). The other top-right items follow
150
+ // the page actions in the overflow menu. A layout's own top-right slot stays as it is.
151
+ const { pageActions } = useShellAppBar();
152
+ const topRight = useShellOutletPlacements("shell-layout:top-right");
153
+ const topRightInMenu = computed(() => {
154
+ if (!isCompactLayout.value || slots["top-right"]) {
155
+ return 0;
156
+ }
157
+ return Math.max(topRight.value.length - (pageActions.hasPrimary.value ? 0 : 1), 0);
158
+ });
119
159
 
120
160
  function updateScrolled() {
121
161
  scrolled.value = window.scrollY > 0;
@@ -162,11 +202,15 @@ onBeforeUnmount(() => {
162
202
  <p v-if="props.subtitle" class="shell-layout__page-subtitle">{{ text(props.subtitle) }}</p>
163
203
  </div>
164
204
 
165
- <ShellPageActionsTarget />
205
+ <ShellPageActionsTarget>
206
+ <template v-if="topRightInMenu > 0" #menu>
207
+ <ShellOutlet target="shell-layout:top-right" :end="topRightInMenu" />
208
+ </template>
209
+ </ShellPageActionsTarget>
166
210
 
167
211
  <slot name="top-right" :surface="resolvedSurface">
168
212
  <div class="shell-layout__top-right">
169
- <ShellOutlet target="shell-layout:top-right" />
213
+ <ShellOutlet target="shell-layout:top-right" :start="topRightInMenu" />
170
214
  </div>
171
215
  </slot>
172
216
  </div>
@@ -224,6 +268,7 @@ onBeforeUnmount(() => {
224
268
 
225
269
  <!-- A modal drawer is the outermost layout item, so it opens from the window's edge over the rail and app bar. -->
226
270
  <v-navigation-drawer
271
+ v-if="hasDrawer"
227
272
  id="jskit-shell-drawer"
228
273
  :model-value="drawerPresentation.visible"
229
274
  class="shell-layout__drawer"
@@ -244,11 +289,11 @@ onBeforeUnmount(() => {
244
289
  :rail-width="resolvedRailWidth"
245
290
  @update:model-value="handleDrawerVisibilityChange"
246
291
  >
247
- <div class="shell-layout__drawer-header">
292
+ <!-- The menu control alone, its tooltip its label: no text beside it that would read as its label. -->
293
+ <div v-if="standardDrawerVisible" class="shell-layout__drawer-header">
248
294
  <v-btn
249
- v-if="standardDrawerVisible"
250
295
  ref="navigationToggle"
251
- :icon="drawerPresentation.rail ? '$menu' : '$menuOpen'"
296
+ icon
252
297
  variant="text"
253
298
  color="on-surface-variant"
254
299
  data-testid="jskit-shell-nav-toggle"
@@ -256,8 +301,10 @@ onBeforeUnmount(() => {
256
301
  :aria-expanded="drawerOpen"
257
302
  aria-controls="jskit-shell-drawer"
258
303
  @click="toggleDrawer"
259
- />
260
- <span v-if="!drawerPresentation.rail" class="shell-layout__surface-label">{{ resolvedSurfaceLabel }}</span>
304
+ >
305
+ <v-icon :icon="drawerPresentation.rail ? '$menu' : '$menuOpen'" />
306
+ <v-tooltip activator="parent" location="end" :text="drawerToggleLabel" />
307
+ </v-btn>
261
308
  </div>
262
309
  <div v-if="!drawerPresentation.rail" class="shell-layout__identity">
263
310
  <slot name="top-left" :surface="resolvedSurface">
@@ -291,7 +338,7 @@ onBeforeUnmount(() => {
291
338
  </v-main>
292
339
 
293
340
  <v-bottom-navigation
294
- v-if="isCompactLayout"
341
+ v-if="showsBottomNavigation"
295
342
  class="shell-layout__bottom-nav"
296
343
  data-testid="jskit-shell-bottom-nav"
297
344
  bg-color="surface-container"
@@ -299,7 +346,9 @@ onBeforeUnmount(() => {
299
346
  :height="80"
300
347
  grow
301
348
  >
302
- <ShellOutlet target="shell-layout:primary-bottom-nav" />
349
+ <ShellNavigationScope presentation="bar">
350
+ <ShellOutlet target="shell-layout:primary-bottom-nav" />
351
+ </ShellNavigationScope>
303
352
  </v-bottom-navigation>
304
353
 
305
354
  <v-bottom-sheet
@@ -420,19 +469,6 @@ onBeforeUnmount(() => {
420
469
  padding-inline-start: max(0px, calc(var(--shell-navigation-rail-width) / 2 - 24px));
421
470
  }
422
471
 
423
- .shell-layout__surface-label {
424
- color: rgb(var(--v-theme-on-surface-variant));
425
- font-size: 0.875rem;
426
- font-weight: 500;
427
- letter-spacing: 0.00625rem;
428
- line-height: 1.25rem;
429
- min-width: 0;
430
- overflow: hidden;
431
- padding-inline-start: 4px;
432
- text-overflow: ellipsis;
433
- white-space: nowrap;
434
- }
435
-
436
472
  .shell-layout__identity {
437
473
  min-width: 0;
438
474
  padding-inline: 12px;
@@ -157,16 +157,21 @@ const rail = computed(() => presentation.value === "rail");
157
157
  color: rgb(var(--v-theme-on-secondary-container));
158
158
  }
159
159
 
160
+ /* A rail label is shown in full: one wider than the rail wraps to a second line, as Material 3's rail labels do,
161
+ and only a label that needs a third line ends the second in an ellipsis. */
160
162
  .shell-menu-link-item__rail-label {
163
+ -webkit-box-orient: vertical;
164
+ -webkit-line-clamp: 2;
165
+ display: -webkit-box;
161
166
  font-size: 0.75rem;
162
167
  font-weight: 500;
163
168
  letter-spacing: 0.03125rem;
164
169
  line-height: 1rem;
165
- max-width: 72px;
170
+ max-width: calc(var(--shell-navigation-rail-width, 80px) - 8px);
166
171
  overflow: hidden;
172
+ overflow-wrap: break-word;
167
173
  text-align: center;
168
- text-overflow: ellipsis;
169
- white-space: nowrap;
174
+ white-space: normal;
170
175
  }
171
176
 
172
177
  .shell-menu-link-item--rail.v-list-item--active .shell-menu-link-item__rail-label {
@@ -2,7 +2,7 @@
2
2
  import { provide, toRef } from "vue";
3
3
  import { SHELL_NAVIGATION_PRESENTATION_KEY } from "../support/navigationPresentation.js";
4
4
 
5
- // Tells the navigation items inside it how to present: as a "rail" or a "drawer".
5
+ // Tells the navigation items inside it how to present: as a "rail", a "drawer" or the navigation "bar".
6
6
  const props = defineProps({
7
7
  presentation: {
8
8
  type: String,
@@ -1,18 +1,6 @@
1
1
  <script setup>
2
2
  import { computed } from "vue";
3
- import { useRoute } from "vue-router";
4
- import { useDisplay } from "vuetify";
5
- import {
6
- useWebPlacementContext,
7
- useWebPlacementRevision,
8
- useWebPlacementRuntime
9
- } from "../placement/inject.js";
10
- import { resolveRuntimePathname } from "../placement/pathname.js";
11
- import {
12
- readPlacementSurfaceConfig,
13
- resolveSurfaceIdFromPlacementPathname
14
- } from "../placement/surfaceContext.js";
15
- import { resolveShellLayoutClass } from "../support/shellLayoutClass.js";
3
+ import { useShellOutletPlacements } from "../composables/useShellOutletPlacements.js";
16
4
  import { useJskitText } from "../i18n.js";
17
5
 
18
6
  const props = defineProps({
@@ -27,11 +15,18 @@ const props = defineProps({
27
15
  context: {
28
16
  type: Object,
29
17
  default: () => ({})
18
+ },
19
+ // Renders only the outlet's placements from `start` up to (not including) `end`, as Array.prototype.slice takes them.
20
+ start: {
21
+ type: Number,
22
+ default: 0
23
+ },
24
+ end: {
25
+ type: Number,
26
+ default: undefined
30
27
  }
31
28
  });
32
29
 
33
- const route = useRoute();
34
- const display = useDisplay();
35
30
  const { text } = useJskitText();
36
31
  const TRANSLATED_PLACEMENT_PROPS = Object.freeze(["label", "title"]);
37
32
 
@@ -51,40 +46,8 @@ function placementProps(entry) {
51
46
  return translated;
52
47
  }
53
48
 
54
- const placementRuntime = useWebPlacementRuntime();
55
- const { context: placementContext } = useWebPlacementContext();
56
- const revision = useWebPlacementRevision(placementRuntime);
57
-
58
- const resolvedSurface = computed(() => {
59
- const contextValue = placementContext.value;
60
- const pathname = resolveRuntimePathname(route.path);
61
- const surfaceFromPathname = resolveSurfaceIdFromPlacementPathname(contextValue, pathname);
62
- if (surfaceFromPathname) {
63
- return surfaceFromPathname;
64
- }
65
-
66
- const surfaceConfig = readPlacementSurfaceConfig(contextValue);
67
- if (surfaceConfig.defaultSurfaceId) {
68
- return surfaceConfig.defaultSurfaceId;
69
- }
70
- return "*";
71
- });
72
-
73
- const resolvedTargetId = computed(() => {
74
- return String(props.target || "").trim();
75
- });
76
-
77
- const resolvedLayoutClass = computed(() => resolveShellLayoutClass(display.width.value));
78
-
79
- const placements = computed(() => {
80
- void revision.value;
81
- return placementRuntime.getPlacements({
82
- surface: resolvedSurface.value,
83
- target: resolvedTargetId.value,
84
- layoutClass: resolvedLayoutClass.value,
85
- context: props.context
86
- });
87
- });
49
+ const outletPlacements = useShellOutletPlacements(() => props.target, () => props.context);
50
+ const placements = computed(() => outletPlacements.value.slice(props.start, props.end));
88
51
  </script>
89
52
 
90
53
  <template>
@@ -1,11 +1,17 @@
1
1
  <script setup>
2
- import { computed } from "vue";
2
+ import { computed, inject, mergeProps, onBeforeUnmount, onMounted, ref, useAttrs, useId } from "vue";
3
3
  import { useShellWindowSizeClass } from "../composables/useShellWindowSizeClass.js";
4
4
  import { useJskitText } from "../i18n.js";
5
+ import { NO_SHELL_PAGE_ACTIONS_REGISTRY, SHELL_PAGE_ACTIONS_REGISTRY_KEY } from "../support/pageActions.js";
5
6
 
6
7
  // One page action in the top app bar. On compact windows a secondary action shows as an icon button named by its
7
- // label; the page's primary action (`primary`, at most one) keeps its label as a filled button. Native button
8
- // attributes such as `type="submit"` and `form` pass through, so an app bar Save can submit the page's form.
8
+ // label; the page's primary action (`primary`, at most one) keeps its label as a filled button. In a bar that owns its
9
+ // actions (ShellLayout, or a layout that calls useShellAppBar()), an `overflow` action is an item of the bar's
10
+ // overflow menu, and on compact windows every action but the primary one joins it.
11
+ // Attributes such as `type="submit"` and `form` (so an app bar Save can submit the page's form), `target`,
12
+ // `data-testid` or `aria-*` land on the button, or on the menu item, in every form.
13
+ defineOptions({ inheritAttrs: false });
14
+
9
15
  const props = defineProps({
10
16
  // A message key, { key, fallback } or plain text.
11
17
  label: {
@@ -20,15 +26,35 @@ const props = defineProps({
20
26
  type: [String, Object],
21
27
  default: undefined
22
28
  },
23
- // A link outside the app (another origin); `to` is for the app's own pages.
29
+ // With `to`: replaces the current history entry instead of pushing one.
30
+ replace: {
31
+ type: Boolean,
32
+ default: false
33
+ },
34
+ // A link outside the app (another origin) or to a file; `to` is for the app's own pages.
24
35
  href: {
25
36
  type: String,
26
37
  default: undefined
27
38
  },
39
+ // With `href`: downloads the file instead of opening it, under the given file name when it is a string.
40
+ download: {
41
+ type: [Boolean, String],
42
+ default: undefined
43
+ },
28
44
  primary: {
29
45
  type: Boolean,
30
46
  default: false
31
47
  },
48
+ // A Material 3 colour role, such as "error" for a destructive action.
49
+ color: {
50
+ type: String,
51
+ default: undefined
52
+ },
53
+ // An item of the top app bar's overflow menu, such as a record's secondary actions.
54
+ overflow: {
55
+ type: Boolean,
56
+ default: false
57
+ },
32
58
  disabled: {
33
59
  type: Boolean,
34
60
  default: false
@@ -40,51 +66,104 @@ const props = defineProps({
40
66
  });
41
67
  const emit = defineEmits(["click"]);
42
68
 
69
+ const attrs = useAttrs();
43
70
  const { text } = useJskitText();
44
71
  const { isCompact } = useShellWindowSizeClass();
45
72
  const resolvedLabel = computed(() => text(props.label));
46
73
  const iconOnly = computed(() => Boolean(props.icon) && isCompact.value && !props.primary);
74
+ const color = computed(() => props.color || (props.primary ? "primary" : "on-surface-variant"));
75
+ // A boolean `download` is the attribute without a file name.
76
+ const download = computed(() => (props.download === true ? "" : props.download || undefined));
47
77
 
48
78
  function handleClick(event) {
49
79
  emit("click", event);
50
80
  }
81
+
82
+ const anchor = ref(null);
83
+ /** @type {import("../support/pageActions.js").ShellPageActionsRegistry} */
84
+ const registry = inject(SHELL_PAGE_ACTIONS_REGISTRY_KEY, NO_SHELL_PAGE_ACTIONS_REGISTRY);
85
+ /** @type {import("../support/pageActions.js").ShellPageActionEntry} */
86
+ const entry = {
87
+ id: useId(),
88
+ state: computed(() => ({
89
+ label: resolvedLabel.value,
90
+ icon: props.icon,
91
+ to: props.to,
92
+ href: props.href,
93
+ replace: props.replace,
94
+ download: download.value,
95
+ color: props.color,
96
+ primary: props.primary,
97
+ overflow: props.overflow,
98
+ disabled: props.disabled,
99
+ loading: props.loading
100
+ })),
101
+ attrs,
102
+ activate: handleClick,
103
+ anchor: null
104
+ };
105
+ const registration = registry.register(entry);
106
+ const inMenu = computed(() => registry.inMenu(entry));
107
+
108
+ onMounted(() => {
109
+ entry.anchor = anchor.value;
110
+ registration.placed();
111
+ });
112
+
113
+ onBeforeUnmount(() => {
114
+ registration.release();
115
+ });
51
116
  </script>
52
117
 
53
118
  <template>
54
- <v-tooltip v-if="iconOnly" :text="resolvedLabel" location="bottom">
55
- <template #activator="{ props: tooltipProps }">
119
+ <!-- The action's place in the bar, which orders the overflow menu; it draws nothing itself. -->
120
+ <span ref="anchor" class="shell-page-action-slot">
121
+ <template v-if="!inMenu">
122
+ <v-tooltip v-if="iconOnly" :text="resolvedLabel" location="bottom">
123
+ <template #activator="{ props: tooltipProps }">
124
+ <v-btn
125
+ v-bind="mergeProps(attrs, tooltipProps)"
126
+ class="shell-page-action"
127
+ :icon="props.icon"
128
+ variant="text"
129
+ :color="color"
130
+ :to="props.to"
131
+ :replace="props.replace"
132
+ :href="props.href"
133
+ :download="download"
134
+ :disabled="props.disabled"
135
+ :loading="props.loading"
136
+ :aria-label="resolvedLabel"
137
+ @click="handleClick"
138
+ />
139
+ </template>
140
+ </v-tooltip>
56
141
  <v-btn
57
- v-bind="tooltipProps"
58
- class="shell-page-action"
59
- :icon="props.icon"
60
- variant="text"
61
- color="on-surface-variant"
142
+ v-else
143
+ v-bind="attrs"
144
+ class="shell-page-action shell-page-action--labelled"
145
+ :variant="props.primary ? 'flat' : 'text'"
146
+ :color="color"
147
+ :prepend-icon="props.icon || undefined"
62
148
  :to="props.to"
149
+ :replace="props.replace"
63
150
  :href="props.href"
151
+ :download="download"
64
152
  :disabled="props.disabled"
65
153
  :loading="props.loading"
66
- :aria-label="resolvedLabel"
67
154
  @click="handleClick"
68
- />
155
+ >
156
+ {{ resolvedLabel }}
157
+ </v-btn>
69
158
  </template>
70
- </v-tooltip>
71
- <v-btn
72
- v-else
73
- class="shell-page-action shell-page-action--labelled"
74
- :variant="props.primary ? 'flat' : 'text'"
75
- :color="props.primary ? 'primary' : 'on-surface-variant'"
76
- :prepend-icon="props.icon || undefined"
77
- :to="props.to"
78
- :href="props.href"
79
- :disabled="props.disabled"
80
- :loading="props.loading"
81
- @click="handleClick"
82
- >
83
- {{ resolvedLabel }}
84
- </v-btn>
159
+ </span>
85
160
  </template>
86
161
 
87
162
  <style scoped>
163
+ .shell-page-action-slot {
164
+ display: contents;
165
+ }
166
+
88
167
  .shell-page-action--labelled {
89
168
  margin-inline: 4px;
90
169
  }
@@ -1,12 +1,81 @@
1
1
  <script setup>
2
+ import { computed, inject, mergeProps, useSlots } from "vue";
3
+ import { useJskitText } from "../i18n.js";
2
4
  import { SHELL_PAGE_ACTIONS_ID } from "../support/navigationPresentation.js";
5
+ import { NO_SHELL_PAGE_ACTIONS_REGISTRY, SHELL_PAGE_ACTIONS_REGISTRY_KEY } from "../support/pageActions.js";
3
6
 
4
- // Where the current page's ShellPageActions show: after the page title in the top app bar. ShellLayout's bar has it;
5
- // a layout that draws its own top app bar renders it once there and calls useShellAppBar().
7
+ // Where the current page's ShellPageActions show: after the page title in the top app bar, followed by the bar's
8
+ // overflow menu (Material 3's trailing "More actions" menu) when an action goes there. Its `menu` slot adds the
9
+ // bar's own items that don't fit (on a phone, ShellLayout's top-right items) below the actions. ShellLayout's bar has
10
+ // it; a layout that draws its own top app bar renders it once there and calls useShellAppBar().
11
+ const { t } = useJskitText();
12
+ /** @type {import("../support/pageActions.js").ShellPageActionsRegistry} */
13
+ const registry = inject(SHELL_PAGE_ACTIONS_REGISTRY_KEY, NO_SHELL_PAGE_ACTIONS_REGISTRY);
14
+ const menuEntries = registry.menuEntries;
15
+ const moreLabel = computed(() => t("jskit.shell.actions.more"));
16
+ const slots = useSlots();
17
+
18
+ // A menu item's props: the action's own attributes, then its label, icon, colour, link or download, and state.
19
+ function itemProps(entry) {
20
+ const state = entry.state.value;
21
+ const unavailable = Boolean(state.disabled || state.loading);
22
+ return mergeProps(entry.attrs, {
23
+ title: state.label,
24
+ prependIcon: state.icon || undefined,
25
+ baseColor: state.color,
26
+ to: state.to,
27
+ replace: state.replace,
28
+ href: state.href,
29
+ download: state.download,
30
+ disabled: unavailable,
31
+ "aria-disabled": unavailable ? "true" : undefined
32
+ });
33
+ }
6
34
  </script>
7
35
 
8
36
  <template>
9
37
  <div :id="SHELL_PAGE_ACTIONS_ID" class="shell-page-actions-target" />
38
+ <v-menu v-if="menuEntries.length > 0 || slots.menu" location="bottom end">
39
+ <template #activator="{ props: menuProps }">
40
+ <v-tooltip :text="moreLabel" location="bottom">
41
+ <template #activator="{ props: tooltipProps }">
42
+ <v-btn
43
+ v-bind="mergeProps(menuProps, tooltipProps)"
44
+ class="shell-page-actions-overflow"
45
+ icon="$moreVert"
46
+ variant="text"
47
+ color="on-surface-variant"
48
+ :aria-label="moreLabel"
49
+ data-testid="jskit-shell-page-actions-overflow"
50
+ />
51
+ </template>
52
+ </v-tooltip>
53
+ </template>
54
+ <v-list v-if="!slots.menu" role="menu" min-width="160">
55
+ <v-list-item
56
+ v-for="entry in menuEntries"
57
+ :key="entry.id"
58
+ v-bind="itemProps(entry)"
59
+ role="menuitem"
60
+ @click="entry.activate"
61
+ />
62
+ </v-list>
63
+ <!-- With the bar's own items too, the menu is a panel: the actions' list, then those items. -->
64
+ <v-sheet v-else class="shell-page-actions-target__panel" color="surface-container" elevation="2" rounded="4">
65
+ <v-list v-if="menuEntries.length > 0" role="menu" min-width="160">
66
+ <v-list-item
67
+ v-for="entry in menuEntries"
68
+ :key="entry.id"
69
+ v-bind="itemProps(entry)"
70
+ role="menuitem"
71
+ @click="entry.activate"
72
+ />
73
+ </v-list>
74
+ <div class="shell-page-actions-target__items" data-testid="jskit-shell-page-actions-overflow-items">
75
+ <slot name="menu" />
76
+ </div>
77
+ </v-sheet>
78
+ </v-menu>
10
79
  </template>
11
80
 
12
81
  <style scoped>
@@ -21,4 +90,14 @@ import { SHELL_PAGE_ACTIONS_ID } from "../support/navigationPresentation.js";
21
90
  .shell-page-actions-target:empty {
22
91
  display: none;
23
92
  }
93
+
94
+ .shell-page-actions-target__items {
95
+ align-items: center;
96
+ color: rgb(var(--v-theme-on-surface-variant));
97
+ display: flex;
98
+ flex-wrap: wrap;
99
+ gap: 4px;
100
+ justify-content: flex-end;
101
+ padding: 4px 8px;
102
+ }
24
103
  </style>
@@ -7,7 +7,8 @@ import { useShellNavigationRuntime } from "../navigation/useShellNavigation.js";
7
7
 
8
8
  // The page's one h1, in the top app bar: the title the page sets (useShellPageTitle), else its route's
9
9
  // meta.jskit.title, else `title`. The shell moves focus here after navigation. ShellLayout's bar shows it; a layout
10
- // that draws its own top app bar renders it once in that bar.
10
+ // that draws its own top app bar renders it once in that bar. Its default slot, given `{ title }`, replaces the text
11
+ // inside the h1, such as a menu activator for a title that is also a switcher; the h1, its id and its focus stay.
11
12
  const props = defineProps({
12
13
  // The title of pages that declare none and set none. A message key or plain text.
13
14
  title: {
@@ -28,7 +29,7 @@ const pageTitle = computed(() => {
28
29
 
29
30
  <template>
30
31
  <h1 :id="PAGE_TITLE_ID" class="shell-page-title" tabindex="-1" data-testid="jskit-shell-page-title">
31
- {{ pageTitle }}
32
+ <slot :title="pageTitle">{{ pageTitle }}</slot>
32
33
  </h1>
33
34
  </template>
34
35
 
@@ -42,7 +43,9 @@ const pageTitle = computed(() => {
42
43
  line-height: 1.75rem;
43
44
  margin: 0;
44
45
  outline: none;
45
- overflow: hidden;
46
+ /* Clipped sideways only, so a menu activator in the slot keeps its 48dp touch target above and below. */
47
+ overflow-x: clip;
48
+ overflow-y: visible;
46
49
  text-overflow: ellipsis;
47
50
  white-space: nowrap;
48
51
  }