@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
@@ -0,0 +1,69 @@
1
+ <script setup>
2
+ import { useShellWindowSizeClass } from "../composables/useShellWindowSizeClass.js";
3
+ import { useJskitText } from "../i18n.js";
4
+ import ShellPageAction from "./ShellPageAction.vue";
5
+ import ShellPageActions from "./ShellPageActions.vue";
6
+
7
+ // A screen's primary action, such as a list's "New", as Material 3 places it: an extended FAB above the navigation
8
+ // bar or beside the rail on compact and medium windows, the app bar's filled primary action on expanded and large
9
+ // ones. It goes to `to`, or runs its click handler (a "New" that opens a dialog). Its layout order puts the FAB inside
10
+ // the shell's navigation bar, so it sits above the bar instead of over it, and it takes layout room (`layout`), so the
11
+ // shell's snackbar shows above it and the screen's last card scrolls clear of it. Attributes and the click handler land on
12
+ // the FAB, or on the bar's button.
13
+ defineOptions({ inheritAttrs: false });
14
+
15
+ const props = defineProps({
16
+ // A message key, { key, fallback } or plain text.
17
+ label: {
18
+ type: [String, Object],
19
+ required: true
20
+ },
21
+ icon: {
22
+ type: String,
23
+ default: "$add"
24
+ },
25
+ to: {
26
+ type: [String, Object],
27
+ default: undefined
28
+ },
29
+ disabled: {
30
+ type: Boolean,
31
+ default: false
32
+ },
33
+ loading: {
34
+ type: Boolean,
35
+ default: false
36
+ }
37
+ });
38
+ const { text } = useJskitText();
39
+ const { isCompact, isMedium } = useShellWindowSizeClass();
40
+ </script>
41
+
42
+ <template>
43
+ <v-fab
44
+ v-if="isCompact || isMedium"
45
+ v-bind="$attrs"
46
+ class="shell-primary-action"
47
+ app
48
+ layout
49
+ extended
50
+ location="bottom end"
51
+ order="1"
52
+ :prepend-icon="props.icon"
53
+ :text="text(props.label)"
54
+ :to="props.to"
55
+ :disabled="props.disabled"
56
+ :loading="props.loading"
57
+ />
58
+ <ShellPageActions v-else>
59
+ <ShellPageAction
60
+ v-bind="$attrs"
61
+ primary
62
+ :icon="props.icon"
63
+ :label="props.label"
64
+ :to="props.to"
65
+ :disabled="props.disabled"
66
+ :loading="props.loading"
67
+ />
68
+ </ShellPageActions>
69
+ </template>
@@ -0,0 +1,104 @@
1
+ <script setup>
2
+ import { computed } from "vue";
3
+ import { useLink } from "vue-router";
4
+ import {
5
+ shellNavigationLinkProps,
6
+ useShellNavigationLink
7
+ } from "../composables/useShellNavigationLink.js";
8
+ import { useJskitText } from "../i18n.js";
9
+
10
+ // A Material 3 primary tab that links to a section of a page (page.section-nav): its label in title-small, with the
11
+ // placement's icon above it when it names one, and under the active one's content a 3dp primary indicator with
12
+ // rounded top corners. The tabs sit in the page's own row, which draws the 1dp outline-variant divider under them
13
+ // and scrolls sideways when they don't fit; this is not the navigation bar's destination (ShellTabLinkItem).
14
+ const props = defineProps(shellNavigationLinkProps);
15
+ const { t } = useJskitText();
16
+ const { resolvedLabel, resolvedTarget, resolvedIcon } = useShellNavigationLink(props);
17
+ const link = useLink({ to: computed(() => (resolvedTarget.value.sameOrigin && resolvedTarget.value.href) || "/") });
18
+ const active = computed(() =>
19
+ resolvedTarget.value.sameOrigin && Boolean(props.exact ? link.isExactActive.value : link.isActive.value)
20
+ );
21
+ // Only an icon the placement names: a section tab guesses none from its label.
22
+ const icon = computed(() => (props.icon ? resolvedIcon.value : ""));
23
+ </script>
24
+
25
+ <template>
26
+ <v-btn
27
+ v-if="resolvedTarget.href"
28
+ class="section-tab-link-item text-none"
29
+ :class="{ 'section-tab-link-item--active': active, 'section-tab-link-item--icon': Boolean(icon) }"
30
+ :to="resolvedTarget.sameOrigin ? resolvedTarget.href : undefined"
31
+ :href="resolvedTarget.sameOrigin ? undefined : resolvedTarget.href"
32
+ :active="active"
33
+ :aria-current="active ? 'page' : undefined"
34
+ :disabled="props.disabled"
35
+ :exact="props.exact"
36
+ variant="text"
37
+ rounded="0"
38
+ min-width="0"
39
+ >
40
+ <v-icon v-if="icon" :icon="icon" class="section-tab-link-item__icon" />
41
+ <span class="section-tab-link-item__label">{{ resolvedLabel || t("jskit.shell.layout.tab") }}</span>
42
+ <span class="section-tab-link-item__indicator" aria-hidden="true" />
43
+ </v-btn>
44
+ </template>
45
+
46
+ <style scoped>
47
+ .section-tab-link-item {
48
+ color: rgb(var(--v-theme-on-surface-variant));
49
+ flex: 0 0 auto;
50
+ height: 48px;
51
+ padding-inline: 16px;
52
+ }
53
+
54
+ .section-tab-link-item--icon {
55
+ height: 64px;
56
+ }
57
+
58
+ .section-tab-link-item--active {
59
+ color: rgb(var(--v-theme-primary));
60
+ }
61
+
62
+ .section-tab-link-item :deep(.v-btn__content) {
63
+ align-self: stretch;
64
+ flex-direction: column;
65
+ gap: 2px;
66
+ justify-content: center;
67
+ position: relative;
68
+ }
69
+
70
+ /* The indicator marks the selection; the state layer stays for hover, focus and press. */
71
+ .section-tab-link-item.v-btn--active > :deep(.v-btn__overlay) {
72
+ opacity: 0;
73
+ }
74
+
75
+ .section-tab-link-item.v-btn--active:hover > :deep(.v-btn__overlay) {
76
+ opacity: var(--v-hover-opacity);
77
+ }
78
+
79
+ .section-tab-link-item.v-btn--active:focus-visible > :deep(.v-btn__overlay) {
80
+ opacity: var(--v-focus-opacity);
81
+ }
82
+
83
+ .section-tab-link-item__label {
84
+ font-size: 0.875rem;
85
+ font-weight: 500;
86
+ letter-spacing: 0.00625rem;
87
+ line-height: 1.25rem;
88
+ white-space: nowrap;
89
+ }
90
+
91
+ .section-tab-link-item__indicator {
92
+ background: rgb(var(--v-theme-primary));
93
+ border-radius: 3px 3px 0 0;
94
+ bottom: 0;
95
+ height: 3px;
96
+ inset-inline: 0;
97
+ opacity: 0;
98
+ position: absolute;
99
+ }
100
+
101
+ .section-tab-link-item--active .section-tab-link-item__indicator {
102
+ opacity: 1;
103
+ }
104
+ </style>
@@ -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,49 @@
1
+ import { computed, toValue } from "vue";
2
+ import { useRoute } from "vue-router";
3
+ import { useDisplay } from "vuetify";
4
+ import {
5
+ useWebPlacementContext,
6
+ useWebPlacementRevision,
7
+ useWebPlacementRuntime
8
+ } from "../placement/inject.js";
9
+ import { resolveRuntimePathname } from "../placement/pathname.js";
10
+ import {
11
+ readPlacementSurfaceConfig,
12
+ resolveSurfaceIdFromPlacementPathname
13
+ } from "../placement/surfaceContext.js";
14
+ import { resolveShellLayoutClass } from "../support/shellLayoutClass.js";
15
+
16
+ /**
17
+ * The placements an outlet renders on the current surface and window size class: ShellOutlet draws them, and
18
+ * ShellLayout checks which navigation outlets have any.
19
+ * @param {import("vue").MaybeRefOrGetter<string>} target
20
+ * @param {import("vue").MaybeRefOrGetter<Record<string, unknown>>} [context]
21
+ */
22
+ function useShellOutletPlacements(target, context = {}) {
23
+ const route = useRoute();
24
+ const display = useDisplay();
25
+ const placementRuntime = useWebPlacementRuntime();
26
+ const { context: placementContext } = useWebPlacementContext();
27
+ const revision = useWebPlacementRevision(placementRuntime);
28
+
29
+ const surface = computed(() => {
30
+ const contextValue = placementContext.value;
31
+ const surfaceFromPathname = resolveSurfaceIdFromPlacementPathname(contextValue, resolveRuntimePathname(route.path));
32
+ if (surfaceFromPathname) {
33
+ return surfaceFromPathname;
34
+ }
35
+ return readPlacementSurfaceConfig(contextValue).defaultSurfaceId || "*";
36
+ });
37
+
38
+ return computed(() => {
39
+ void revision.value;
40
+ return placementRuntime.getPlacements({
41
+ surface: surface.value,
42
+ target: String(toValue(target) || "").trim(),
43
+ layoutClass: resolveShellLayoutClass(display.width.value),
44
+ context: toValue(context)
45
+ });
46
+ });
47
+ }
48
+
49
+ export { useShellOutletPlacements };
@@ -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";
@@ -17,10 +17,12 @@ function reloadAppPage(target) {
17
17
 
18
18
  /**
19
19
  * Leaves the app for another site in the same tab, such as a payment provider's checkout. External pages never enter
20
- * the trail.
20
+ * the trail. The site is opened with a push, so Back returns to the page that left; a hand-off page that only forwards
21
+ * (to an OAuth provider's consent screen) passes `{ replace: true }`, so Back from the site doesn't rerun the hand-off.
21
22
  * @param {string} url An absolute http(s) URL on another origin.
23
+ * @param {{ replace?: boolean }} [options] replace: the site takes the current history entry's place.
22
24
  */
23
- function leaveApp(url) {
25
+ function leaveApp(url, { replace = false } = {}) {
24
26
  const windowRef = pageWindow();
25
27
  const target = String(url || "").trim();
26
28
  let parsed = null;
@@ -32,7 +34,8 @@ function leaveApp(url) {
32
34
  if (!parsed || !/^https?:$/u.test(parsed.protocol) || (windowRef && parsed.origin === windowRef.location.origin)) {
33
35
  throw new TypeError(`leaveApp() takes another site's http(s) URL, not "${target}"; navigate in-app pages with the router.`);
34
36
  }
35
- windowRef?.location.assign(parsed.href);
37
+ if (replace) windowRef?.location.replace(parsed.href);
38
+ else windowRef?.location.assign(parsed.href);
36
39
  }
37
40
 
38
41
  export { leaveApp, reloadAppPage };
@@ -1,5 +1,6 @@
1
1
  import { unref } from "vue";
2
2
  import { resolveLinkPath, normalizePathname } from "@jskit-ai/kernel/shared";
3
+ import { isExternalLinkTarget } from "@jskit-ai/kernel/shared/support/linkPath";
3
4
  import { normalizeSurfaceId } from "@jskit-ai/kernel/shared/surface/registry";
4
5
  import { useWebPlacementContext } from "../placement/inject.js";
5
6
  import {
@@ -8,36 +9,40 @@ import {
8
9
  } from "../placement/surfaceContext.js";
9
10
  import { normalizeRouteParams } from "../support/routeParams.js";
10
11
 
11
- function materializeSurfaceRouteBase(routeBaseTemplate = "/", { params = {}, strictParams = true, surface = "" } = {}) {
12
+ // Fills each `:name` segment of a path from params. A param the params lack throws when strict and otherwise stays as
13
+ // written. Only a path segment that starts with ":" is a param; a query and a hash are left alone.
14
+ function fillPathParams(pathTemplate = "/", { params = {}, strictParams = true, label = "route params" } = {}) {
15
+ const template = String(pathTemplate || "/");
16
+ const suffixStart = template.search(/[?#]/u);
17
+ const pathPart = suffixStart < 0 ? template : template.slice(0, suffixStart);
18
+ const suffix = suffixStart < 0 ? "" : template.slice(suffixStart);
12
19
  const normalizedParams = normalizeRouteParams(params);
13
20
  const missingParams = new Set();
14
- const outputPath = String(routeBaseTemplate || "/").replace(/:([A-Za-z0-9_]+)/g, (_full, rawName) => {
15
- const paramName = String(rawName || "").trim();
21
+ const outputPath = pathPart.replace(/(^|\/):([A-Za-z0-9_]+)/g, (full, start, paramName) => {
16
22
  const paramValue = normalizedParams[paramName];
17
23
  if (!paramValue) {
18
24
  missingParams.add(paramName);
19
- return `:${paramName}`;
25
+ return full;
20
26
  }
21
- return encodeURIComponent(paramValue);
27
+ return `${start}${encodeURIComponent(paramValue)}`;
22
28
  });
23
29
 
24
30
  if (strictParams && missingParams.size > 0) {
25
- const surfaceLabel = String(surface || "").trim() || "(default)";
26
31
  const missing = [...missingParams].sort().join(", ");
27
- throw new Error(`Missing required surface route params for "${surfaceLabel}": ${missing}.`);
32
+ throw new Error(`Missing required ${label}: ${missing}.`);
28
33
  }
29
34
 
30
- return outputPath;
35
+ return `${outputPath}${suffix}`;
31
36
  }
32
37
 
33
38
  function resolveSurfaceBasePath(context = null, surface = "", { params = {}, strictParams = true } = {}) {
34
39
  const normalizedSurface = normalizeSurfaceId(surface);
35
40
  if (normalizedSurface && resolveSurfaceDefinitionFromPlacementContext(context, normalizedSurface)) {
36
41
  const routeBaseTemplate = resolveSurfaceRootPathFromPlacementContext(context, normalizedSurface);
37
- return materializeSurfaceRouteBase(routeBaseTemplate, {
42
+ return fillPathParams(routeBaseTemplate, {
38
43
  params,
39
44
  strictParams,
40
- surface: normalizedSurface
45
+ label: `surface route params for "${normalizedSurface}"`
41
46
  });
42
47
  }
43
48
 
@@ -69,7 +74,13 @@ function resolveShellLinkPath({
69
74
  strictParams
70
75
  });
71
76
 
72
- return resolveLinkPath(nextSurfaceBasePath, nextRelativePath);
77
+ // A relative path may name params too, like a declared parent "/books/:bookId"; they fill from the same params.
78
+ // An external URL is another site's, so it stays as written.
79
+ const filledRelativePath = isExternalLinkTarget(nextRelativePath)
80
+ ? nextRelativePath
81
+ : fillPathParams(nextRelativePath, { params, strictParams, label: `route params for "${nextRelativePath}"` });
82
+
83
+ return resolveLinkPath(nextSurfaceBasePath, filledRelativePath);
73
84
  }
74
85
 
75
86
  /**
@@ -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
  });