@jskit-ai/shell-web 0.2.4 → 0.2.6

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 (68) hide show
  1. package/package.json +10 -4
  2. package/src/client/asyncModuleRecovery/index.js +1 -0
  3. package/src/client/asyncModuleRecovery/inject.js +30 -18
  4. package/src/client/asyncModuleRecovery/runtime.js +14 -22
  5. package/src/client/bootstrap/bootstrapPayloadHandlerRegistry.js +13 -6
  6. package/src/client/browser.js +56 -0
  7. package/src/client/clientUpdate/runtime.js +28 -18
  8. package/src/client/components/ShellErrorHost.vue +19 -219
  9. package/src/client/components/ShellLayout.vue +19 -227
  10. package/src/client/components/ShellOutlet.vue +16 -53
  11. package/src/client/components/ShellRouteTransition.vue +2 -291
  12. package/src/client/composables/shellLayoutDrawerPreference.js +15 -8
  13. package/src/client/composables/useShellDrawer.js +194 -0
  14. package/src/client/composables/useShellErrorHost.js +171 -0
  15. package/src/client/composables/useShellLayoutState.js +10 -20
  16. package/src/client/composables/useShellNavigationLink.js +6 -6
  17. package/src/client/composables/useShellPullToRefresh.js +15 -19
  18. package/src/client/composables/useShellRouteTransition.js +218 -0
  19. package/src/client/error/index.js +1 -1
  20. package/src/client/error/inject.js +36 -48
  21. package/src/client/error/normalize.js +2 -3
  22. package/src/client/error/policy.js +9 -0
  23. package/src/client/error/presentation.js +67 -0
  24. package/src/client/error/presentationDefaults.js +2 -2
  25. package/src/client/error/presenters.js +44 -19
  26. package/src/client/error/runtime.js +20 -17
  27. package/src/client/error/store.js +4 -0
  28. package/src/client/navigation/linkResolver.js +6 -2
  29. package/src/client/navigation/usePaths.js +11 -8
  30. package/src/client/navigation/useSurfaceRouteContext.js +3 -3
  31. package/src/client/placement/debug.js +2 -2
  32. package/src/client/placement/index.js +1 -0
  33. package/src/client/placement/inject.js +49 -46
  34. package/src/client/placement/pathname.js +3 -9
  35. package/src/client/placement/runtime.js +4 -16
  36. package/src/client/placement/surfaceContext.js +14 -33
  37. package/src/client/placement/validators.js +6 -1
  38. package/src/client/providers/ShellWebClientProvider.js +14 -32
  39. package/src/client/providers/appModuleLoadFailure.js +1 -1
  40. package/src/client/requestRecovery/index.js +1 -0
  41. package/src/client/requestRecovery/inject.js +29 -17
  42. package/src/client/requestRecovery/runtime.js +33 -84
  43. package/src/client/runtime/bootstrapRuntime.js +10 -32
  44. package/src/client/runtime/refreshRuntime.js +24 -21
  45. package/src/client/stores/useShellErrorPresentationStore.js +5 -19
  46. package/src/client/support/drawerWidth.js +39 -0
  47. package/src/client/support/gestureTargets.js +4 -2
  48. package/src/client/support/menuLinkTarget.js +1 -1
  49. package/src/client/support/navigationLinkKeyboard.js +1 -1
  50. package/src/client/support/primaryNavigation.js +93 -0
  51. package/src/client/support/routeSwipeGesture.js +13 -3
  52. package/src/client/support/shellLayoutClass.js +4 -6
  53. package/src/client/types.js +38 -0
  54. package/test/asyncModuleRecoveryInject.test.js +13 -18
  55. package/test/browser.test.js +51 -0
  56. package/test/clientUpdate.test.js +12 -1
  57. package/test/drawerWidth.test.js +64 -0
  58. package/test/errorActions.test.js +7 -2
  59. package/test/errorPresentation.test.js +51 -0
  60. package/test/placementInject.test.js +60 -0
  61. package/test/primaryNavigation.test.js +75 -0
  62. package/test/provider.test.js +18 -4
  63. package/test/requestRecovery.test.js +13 -18
  64. package/test/settingsPlacementContract.test.js +12 -8
  65. package/test/support/mountComposable.js +90 -0
  66. package/test/useShellDrawer.test.js +213 -0
  67. package/test/useShellErrorHost.test.js +149 -0
  68. package/test/useShellRouteTransition.test.js +129 -0
@@ -1,9 +1,13 @@
1
+ import { pageStorage } from "../browser.js";
2
+
1
3
  const SHELL_LAYOUT_DRAWER_DEFAULT_OPEN_STORAGE_KEY = "jskit.shell-web.drawer-default-open";
2
4
 
3
- function readDrawerDefaultOpenPreference({
4
- storage = typeof window === "object" ? window?.localStorage : null
5
- } = {}) {
6
- if (!storage || typeof storage.getItem !== "function") {
5
+ /**
6
+ * @param {object} [options]
7
+ * @param {Pick<Storage, "getItem"> | null} [options.storage] Null outside a browser.
8
+ */
9
+ function readDrawerDefaultOpenPreference({ storage = pageStorage() } = {}) {
10
+ if (!storage) {
7
11
  return true;
8
12
  }
9
13
 
@@ -22,10 +26,13 @@ function readDrawerDefaultOpenPreference({
22
26
  return true;
23
27
  }
24
28
 
25
- function writeDrawerDefaultOpenPreference(open, {
26
- storage = typeof window === "object" ? window?.localStorage : null
27
- } = {}) {
28
- if (!storage || typeof storage.setItem !== "function") {
29
+ /**
30
+ * @param {boolean} open
31
+ * @param {object} [options]
32
+ * @param {Pick<Storage, "setItem"> | null} [options.storage] Null outside a browser.
33
+ */
34
+ function writeDrawerDefaultOpenPreference(open, { storage = pageStorage() } = {}) {
35
+ if (!storage) {
29
36
  return;
30
37
  }
31
38
 
@@ -0,0 +1,194 @@
1
+ import {
2
+ computed,
3
+ nextTick,
4
+ onBeforeUnmount,
5
+ onMounted,
6
+ ref,
7
+ watch
8
+ } from "vue";
9
+ import {
10
+ resolveShellDrawerPresentation,
11
+ resolveShellDrawerToggleLabel
12
+ } from "../support/drawerPresentation.js";
13
+ import {
14
+ DEFAULT_SHELL_DRAWER_WIDTH,
15
+ measureDrawerContentWidth,
16
+ normalizeShellDrawerWidth,
17
+ normalizeShellNavigationItemSpacing,
18
+ normalizeShellRailWidth
19
+ } from "../support/drawerWidth.js";
20
+
21
+ // VNavigationDrawer has no root element of its own to reach through a template ref.
22
+ function navigationDrawerElement() {
23
+ return document.getElementById("jskit-shell-drawer");
24
+ }
25
+
26
+ /**
27
+ * The shell's navigation drawer: what opens it on each layout, how it presents, and the width its labels need.
28
+ * @param {object} options
29
+ * @param {{ desktopDrawerClosedMode: string, drawerWidth: number | null, railWidth: number, navigationItemSpacing: number }} options.props
30
+ * @param {import("vue").Ref<boolean>} options.isCompactLayout
31
+ * @param {import("vue").Ref<{ $el: HTMLElement } | null>} options.navigationToggle
32
+ * @param {ReturnType<typeof import("./useShellLayoutState.js").useShellLayoutState>} options.layoutState
33
+ */
34
+ function useShellDrawer({ props, isCompactLayout, navigationToggle, layoutState }) {
35
+ const {
36
+ drawerDefaultOpen,
37
+ drawerOpen,
38
+ resolvedSurface,
39
+ setDrawerOpen
40
+ } = layoutState;
41
+ const wideDrawerOpen = ref(Boolean(drawerDefaultOpen.value));
42
+ const measuredDrawerWidth = ref(DEFAULT_SHELL_DRAWER_WIDTH);
43
+ let drawerContentObserver = null;
44
+ let drawerMeasurementFrame = null;
45
+ let shellMounted = false;
46
+
47
+ const drawerPresentation = computed(() => resolveShellDrawerPresentation({
48
+ compact: isCompactLayout.value,
49
+ open: drawerOpen.value,
50
+ desktopClosedMode: props.desktopDrawerClosedMode
51
+ }));
52
+ const drawerToggleLabel = computed(() => resolveShellDrawerToggleLabel({
53
+ compact: isCompactLayout.value,
54
+ open: drawerOpen.value
55
+ }));
56
+ const fixedDrawerWidth = computed(() => props.drawerWidth !== null && props.drawerWidth !== undefined);
57
+ const resolvedDrawerWidth = computed(() =>
58
+ normalizeShellDrawerWidth(fixedDrawerWidth.value ? props.drawerWidth : measuredDrawerWidth.value)
59
+ );
60
+ const resolvedRailWidth = computed(() => normalizeShellRailWidth(props.railWidth));
61
+ const resolvedNavigationItemSpacing = computed(() =>
62
+ normalizeShellNavigationItemSpacing(props.navigationItemSpacing)
63
+ );
64
+ watch(
65
+ drawerOpen,
66
+ handleDrawerOpenChange
67
+ );
68
+
69
+ watch(
70
+ isCompactLayout,
71
+ handleLayoutClassChange,
72
+ { immediate: true }
73
+ );
74
+
75
+ watch(drawerPresentation, scheduleDrawerWidthMeasurement, { flush: "post" });
76
+ watch(resolvedSurface, scheduleDrawerWidthMeasurement, { flush: "post" });
77
+ watch(resolvedNavigationItemSpacing, scheduleDrawerWidthMeasurement, { flush: "post" });
78
+
79
+ onMounted(attachShellListeners);
80
+ onBeforeUnmount(detachShellListeners);
81
+
82
+ function attachShellListeners() {
83
+ shellMounted = true;
84
+ window.addEventListener("keydown", handleShellKeydown);
85
+ window.addEventListener("resize", scheduleDrawerWidthMeasurement, { passive: true });
86
+
87
+ void document.fonts.ready.then(scheduleDrawerWidthMeasurement);
88
+ document.fonts.addEventListener("loadingdone", scheduleDrawerWidthMeasurement);
89
+ void nextTick().then(initializeDrawerMeasurement);
90
+ }
91
+
92
+ function detachShellListeners() {
93
+ shellMounted = false;
94
+ window.removeEventListener("keydown", handleShellKeydown);
95
+ window.removeEventListener("resize", scheduleDrawerWidthMeasurement);
96
+ document.fonts.removeEventListener("loadingdone", scheduleDrawerWidthMeasurement);
97
+ drawerContentObserver?.disconnect();
98
+ drawerContentObserver = null;
99
+ if (drawerMeasurementFrame !== null) {
100
+ window.cancelAnimationFrame(drawerMeasurementFrame);
101
+ drawerMeasurementFrame = null;
102
+ }
103
+ }
104
+
105
+ function handleDrawerOpenChange(open) {
106
+ if (!isCompactLayout.value) {
107
+ wideDrawerOpen.value = Boolean(open);
108
+ }
109
+ }
110
+
111
+ function handleLayoutClassChange(compact) {
112
+ setDrawerOpen(compact ? false : wideDrawerOpen.value);
113
+ }
114
+
115
+ function handleShellKeydown(event) {
116
+ if (
117
+ event.defaultPrevented ||
118
+ event.key !== "Escape" ||
119
+ !isCompactLayout.value ||
120
+ !drawerOpen.value
121
+ ) {
122
+ return;
123
+ }
124
+
125
+ event.preventDefault();
126
+ setDrawerOpen(false);
127
+ void nextTick().then(focusNavigationToggle);
128
+ }
129
+
130
+ function focusNavigationToggle() {
131
+ navigationToggle.value.$el.focus({ preventScroll: true });
132
+ }
133
+
134
+ function initializeDrawerMeasurement() {
135
+ const drawerElement = navigationDrawerElement();
136
+ if (drawerElement) {
137
+ drawerContentObserver?.disconnect();
138
+ drawerContentObserver = new MutationObserver(scheduleDrawerWidthMeasurement);
139
+ drawerContentObserver.observe(drawerElement.querySelector(".v-navigation-drawer__content") || drawerElement, {
140
+ childList: true,
141
+ characterData: true,
142
+ subtree: true
143
+ });
144
+ }
145
+ scheduleDrawerWidthMeasurement();
146
+ }
147
+
148
+ function scheduleDrawerWidthMeasurement() {
149
+ if (
150
+ !shellMounted ||
151
+ fixedDrawerWidth.value ||
152
+ !drawerPresentation.value.visible ||
153
+ drawerPresentation.value.rail
154
+ ) {
155
+ return;
156
+ }
157
+
158
+ if (drawerMeasurementFrame !== null) {
159
+ window.cancelAnimationFrame(drawerMeasurementFrame);
160
+ }
161
+ drawerMeasurementFrame = window.requestAnimationFrame(updateMeasuredDrawerWidth);
162
+ }
163
+
164
+ function updateMeasuredDrawerWidth() {
165
+ drawerMeasurementFrame = null;
166
+ const drawerElement = navigationDrawerElement();
167
+ if (!drawerElement) {
168
+ return;
169
+ }
170
+
171
+ const nextWidth = measureDrawerContentWidth(drawerElement, resolvedNavigationItemSpacing.value);
172
+ if (Math.abs(nextWidth - measuredDrawerWidth.value) >= 0.25) {
173
+ measuredDrawerWidth.value = nextWidth;
174
+ }
175
+ }
176
+
177
+ function handleDrawerVisibilityChange(open) {
178
+ if (isCompactLayout.value || drawerPresentation.value.closedMode === "hidden" || open === false) {
179
+ setDrawerOpen(open);
180
+ }
181
+ }
182
+
183
+ return {
184
+ drawerPresentation,
185
+ drawerToggleLabel,
186
+ fixedDrawerWidth,
187
+ handleDrawerVisibilityChange,
188
+ resolvedDrawerWidth,
189
+ resolvedNavigationItemSpacing,
190
+ resolvedRailWidth
191
+ };
192
+ }
193
+
194
+ export { useShellDrawer };
@@ -0,0 +1,171 @@
1
+ import { computed, onBeforeUnmount, ref, watch } from "vue";
2
+ import { useLayout } from "vuetify";
3
+ import { useShellWebErrorRuntime } from "../error/inject.js";
4
+ import { resolveBannerPlacement } from "../error/presentation.js";
5
+ import { useShellErrorPresentationStore } from "../stores/useShellErrorPresentationStore.js";
6
+ import { useJskitText } from "../i18n.js";
7
+
8
+ const BANNER_INLINE_HEIGHT_PROPERTY = "--shell-error-banners-inline-height";
9
+
10
+ function isSameSnackbarEntry(left = null, right = null) {
11
+ return Boolean(left?.id && right?.id && left.id === right.id);
12
+ }
13
+
14
+ function publishInlineBannerHeight(height = 0) {
15
+ const rootStyle = document.documentElement.style;
16
+ if (height > 0) {
17
+ rootStyle.setProperty(BANNER_INLINE_HEIGHT_PROPERTY, `${Math.ceil(height)}px`);
18
+ } else {
19
+ rootStyle.removeProperty(BANNER_INLINE_HEIGHT_PROPERTY);
20
+ }
21
+ }
22
+
23
+ /**
24
+ * What the error host shows and does: the snackbar queue, the dialog, and where the banners sit. Inline banners publish
25
+ * their height so full-viewport surfaces can start below them.
26
+ */
27
+ function useShellErrorHost() {
28
+ const runtime = useShellWebErrorRuntime();
29
+ const { t } = useJskitText();
30
+ const store = useShellErrorPresentationStore();
31
+
32
+ const snackbarEntries = computed(() => store.channels.snackbar || []);
33
+ const bannerEntries = computed(() => store.channels.banner || []);
34
+ const dialogEntry = computed(() => store.channels.dialog[0] || null);
35
+ const displayedSnackbarEntry = ref(null);
36
+ const layoutRect = useLayout().mainRect;
37
+
38
+ const bannersElement = ref(null);
39
+ const bannerPlacement = computed(() => resolveBannerPlacement(layoutRect.value));
40
+ let bannerResizeObserver = null;
41
+
42
+ function stopObservingBanners() {
43
+ bannerResizeObserver?.disconnect();
44
+ bannerResizeObserver = null;
45
+ publishInlineBannerHeight(0);
46
+ }
47
+
48
+ watch(
49
+ [bannersElement, () => bannerPlacement.value.inline],
50
+ ([element, inline]) => {
51
+ stopObservingBanners();
52
+ if (!element || !inline) {
53
+ return;
54
+ }
55
+ bannerResizeObserver = new ResizeObserver(() => {
56
+ publishInlineBannerHeight(element.getBoundingClientRect().height);
57
+ });
58
+ bannerResizeObserver.observe(element);
59
+ publishInlineBannerHeight(element.getBoundingClientRect().height);
60
+ },
61
+ { flush: "post" }
62
+ );
63
+
64
+ onBeforeUnmount(stopObservingBanners);
65
+ const snackbarOpen = ref(false);
66
+
67
+ function hasSnackbarEntry(entry = null) {
68
+ if (!entry?.id) {
69
+ return false;
70
+ }
71
+
72
+ return snackbarEntries.value.some((candidate) => isSameSnackbarEntry(candidate, entry));
73
+ }
74
+
75
+ function openNextSnackbarEntry() {
76
+ const nextEntry = snackbarEntries.value[0] || null;
77
+ if (!nextEntry) {
78
+ displayedSnackbarEntry.value = null;
79
+ snackbarOpen.value = false;
80
+ return;
81
+ }
82
+
83
+ displayedSnackbarEntry.value = nextEntry;
84
+ snackbarOpen.value = true;
85
+ }
86
+
87
+ watch(
88
+ snackbarEntries,
89
+ (entries) => {
90
+ const currentEntry = displayedSnackbarEntry.value;
91
+ if (!currentEntry) {
92
+ openNextSnackbarEntry();
93
+ return;
94
+ }
95
+
96
+ const matchingEntry = entries.find((entry) => isSameSnackbarEntry(entry, currentEntry)) || null;
97
+ if (matchingEntry) {
98
+ displayedSnackbarEntry.value = matchingEntry;
99
+ return;
100
+ }
101
+
102
+ snackbarOpen.value = false;
103
+ },
104
+ {
105
+ immediate: true
106
+ }
107
+ );
108
+
109
+ function dismiss(entry) {
110
+ if (!entry || !entry.channel || !entry.id) {
111
+ return;
112
+ }
113
+
114
+ store.dismiss(entry.channel, entry.id);
115
+ }
116
+
117
+ async function runAction(entry, action) {
118
+ try {
119
+ await action.handler(entry);
120
+ } catch (error) {
121
+ runtime.report({
122
+ source: "shell-web.error-host.action",
123
+ message: t("jskit.shell.error.actionFailed"),
124
+ cause: error,
125
+ intent: "blocking",
126
+ severity: "error"
127
+ });
128
+ }
129
+
130
+ if (action.dismissOnRun !== false) {
131
+ dismiss(entry);
132
+ }
133
+ }
134
+
135
+ function onSnackbarModelValue(nextValue) {
136
+ if (nextValue === false && displayedSnackbarEntry.value) {
137
+ snackbarOpen.value = false;
138
+ dismiss(displayedSnackbarEntry.value);
139
+ }
140
+ }
141
+
142
+ function onDialogModelValue(nextValue) {
143
+ if (nextValue === false && dialogEntry.value && dialogEntry.value.persist !== true) {
144
+ dismiss(dialogEntry.value);
145
+ }
146
+ }
147
+
148
+ function onSnackbarAfterLeave() {
149
+ if (hasSnackbarEntry(displayedSnackbarEntry.value)) {
150
+ return;
151
+ }
152
+
153
+ openNextSnackbarEntry();
154
+ }
155
+
156
+ return {
157
+ bannerEntries,
158
+ bannerPlacement,
159
+ bannersElement,
160
+ dialogEntry,
161
+ dismiss,
162
+ displayedSnackbarEntry,
163
+ onDialogModelValue,
164
+ onSnackbarAfterLeave,
165
+ onSnackbarModelValue,
166
+ runAction,
167
+ snackbarOpen
168
+ };
169
+ }
170
+
171
+ export { useShellErrorHost };
@@ -3,6 +3,7 @@ import { storeToRefs } from "pinia";
3
3
  import { useRoute } from "vue-router";
4
4
  import { normalizeSurfaceId } from "@jskit-ai/kernel/shared/surface";
5
5
  import { useWebPlacementContext } from "../placement/inject.js";
6
+ import { resolveRuntimePathname } from "../placement/pathname.js";
6
7
  import { useShellLayoutStore } from "../stores/useShellLayoutStore.js";
7
8
  import {
8
9
  readPlacementSurfaceConfig,
@@ -26,6 +27,7 @@ function toSurfaceLabel(surfaceId = "") {
26
27
  .join(" ");
27
28
  }
28
29
 
30
+ /** @param {import("../types.js").ShellLayoutStateProps} [props] */
29
31
  function useShellLayoutState(props = {}) {
30
32
  const shellLayoutStore = useShellLayoutStore();
31
33
  const {
@@ -34,13 +36,7 @@ function useShellLayoutState(props = {}) {
34
36
  supportingContentOpen,
35
37
  supportingContentTitle
36
38
  } = storeToRefs(shellLayoutStore);
37
- let route = null;
38
- try {
39
- route = useRoute();
40
- } catch {
41
- route = null;
42
- }
43
-
39
+ const route = useRoute();
44
40
  const { context: placementContext } = useWebPlacementContext();
45
41
 
46
42
  function toggleDrawer() {
@@ -48,16 +44,13 @@ function useShellLayoutState(props = {}) {
48
44
  }
49
45
 
50
46
  const resolvedSurface = computed(() => {
51
- const explicitSurface = normalizeSurfaceId(props?.surface);
47
+ const explicitSurface = normalizeSurfaceId(props.surface);
52
48
  if (explicitSurface) {
53
49
  return explicitSurface;
54
50
  }
55
51
 
56
- const pathname =
57
- String(route?.path || "").trim() ||
58
- (typeof window === "object" && window?.location?.pathname ? String(window.location.pathname).trim() : "/");
59
- const contextValue = placementContext?.value || null;
60
- const resolvedSurfaceFromPath = resolveSurfaceIdFromPlacementPathname(contextValue, pathname);
52
+ const contextValue = placementContext.value;
53
+ const resolvedSurfaceFromPath = resolveSurfaceIdFromPlacementPathname(contextValue, resolveRuntimePathname(route.path));
61
54
  if (resolvedSurfaceFromPath) {
62
55
  return resolvedSurfaceFromPath;
63
56
  }
@@ -72,15 +65,12 @@ function useShellLayoutState(props = {}) {
72
65
 
73
66
  const resolvedSurfaceLabel = computed(() => {
74
67
  // A surface label may be a message key; plain text shows as written.
75
- const explicitLabel = String(text(props?.surfaceLabel) || "").trim();
68
+ const explicitLabel = String(text(props.surfaceLabel) || "").trim();
76
69
  if (explicitLabel) {
77
70
  return explicitLabel;
78
71
  }
79
72
 
80
- const surfaceDefinition = resolveSurfaceDefinitionFromPlacementContext(
81
- placementContext?.value || null,
82
- resolvedSurface.value
83
- );
73
+ const surfaceDefinition = resolveSurfaceDefinitionFromPlacementContext(placementContext.value, resolvedSurface.value);
84
74
  const configuredLabel = String(text(surfaceDefinition?.label) || "").trim();
85
75
  if (configuredLabel) {
86
76
  return configuredLabel;
@@ -89,7 +79,7 @@ function useShellLayoutState(props = {}) {
89
79
  return toSurfaceLabel(resolvedSurface.value);
90
80
  });
91
81
 
92
- return Object.freeze({
82
+ return {
93
83
  drawerDefaultOpen,
94
84
  drawerOpen,
95
85
  supportingContentOpen,
@@ -102,7 +92,7 @@ function useShellLayoutState(props = {}) {
102
92
  toggleDrawer,
103
93
  resolvedSurface,
104
94
  resolvedSurfaceLabel
105
- });
95
+ };
106
96
  }
107
97
 
108
98
  export { useShellLayoutState };
@@ -44,7 +44,10 @@ const shellNavigationLinkProps = Object.freeze({
44
44
  }
45
45
  });
46
46
 
47
- // Surface-aware link resolution shared by the shell menu and tab link items.
47
+ /**
48
+ * Surface-aware link resolution shared by the shell menu and tab link items.
49
+ * @param {import("../types.js").ShellNavigationLinkProps} props
50
+ */
48
51
  function useShellNavigationLink(props) {
49
52
  const route = useRoute();
50
53
  const { context: placementContext } = useWebPlacementContext();
@@ -52,10 +55,7 @@ function useShellNavigationLink(props) {
52
55
  const resolvedLabel = computed(() => text(props.label));
53
56
 
54
57
  const resolvedTo = computed(() => {
55
- const currentSurfaceId = resolveSurfaceIdFromPlacementPathname(
56
- placementContext.value,
57
- String(route?.path || route?.fullPath || "").trim()
58
- );
58
+ const currentSurfaceId = resolveSurfaceIdFromPlacementPathname(placementContext.value, route.path);
59
59
  return resolveMenuLinkTarget({
60
60
  to: props.to,
61
61
  surface: props.surface,
@@ -63,7 +63,7 @@ function useShellNavigationLink(props) {
63
63
  placementContext: placementContext.value,
64
64
  scopedSuffix: props.scopedSuffix,
65
65
  unscopedSuffix: props.unscopedSuffix,
66
- routeParams: route.params || {}
66
+ routeParams: route.params
67
67
  });
68
68
  });
69
69
 
@@ -1,4 +1,5 @@
1
1
  import { computed, onBeforeUnmount, onMounted, ref, unref } from "vue";
2
+ import { NO_SHELL_WEB_REFRESH_RUNTIME } from "../runtime/refreshRuntime.js";
2
3
  import { isPrimaryTouchPointer, isShellGestureIgnoredTarget } from "../support/gestureTargets.js";
3
4
  import { useJskitText } from "../i18n.js";
4
5
 
@@ -7,19 +8,20 @@ const PULL_REFRESH_MAX_DISTANCE = 112;
7
8
  const PULL_REFRESH_IGNORED_SELECTORS = Object.freeze(["[data-shell-pull-refresh-ignore]"]);
8
9
 
9
10
  function isAtPageTop() {
10
- if (typeof window !== "object" || typeof document !== "object") {
11
- return false;
12
- }
13
-
14
- const documentScrollTop = Number(document.documentElement?.scrollTop || 0);
15
- const bodyScrollTop = Number(document.body?.scrollTop || 0);
11
+ const documentScrollTop = Number(document.documentElement.scrollTop || 0);
12
+ const bodyScrollTop = Number(document.body.scrollTop || 0);
16
13
  return Math.max(Number(window.scrollY || 0), documentScrollTop, bodyScrollTop) <= 0;
17
14
  }
18
15
 
19
- // Compact-layout pull-to-refresh. Pointer events start the gesture where the
20
- // browser supports them; touch events carry it on after the browser cancels the
21
- // pointer to scroll, and start it where pointer events are missing.
22
- function useShellPullToRefresh({ enabled, refreshRuntime = null } = {}) {
16
+ /**
17
+ * Compact-layout pull-to-refresh. Pointer events start the gesture where the
18
+ * browser supports them; touch events carry it on after the browser cancels the
19
+ * pointer to scroll, and start it where pointer events are missing.
20
+ * @param {object} options
21
+ * @param {import("vue").MaybeRef<boolean>} options.enabled
22
+ * @param {import("../types.js").ShellRefreshRuntime} options.refreshRuntime
23
+ */
24
+ function useShellPullToRefresh({ enabled, refreshRuntime }) {
23
25
  const { t } = useJskitText();
24
26
  const pullDistance = ref(0);
25
27
  const pullRefreshing = ref(false);
@@ -42,9 +44,6 @@ function useShellPullToRefresh({ enabled, refreshRuntime = null } = {}) {
42
44
  }));
43
45
 
44
46
  onMounted(() => {
45
- if (typeof window !== "object") {
46
- return;
47
- }
48
47
  window.addEventListener("pointerdown", handlePullPointerDown, { capture: true, passive: true });
49
48
  window.addEventListener("pointermove", handlePullPointerMove, { capture: true, passive: false });
50
49
  window.addEventListener("pointerup", handlePullPointerEnd, { capture: true, passive: true });
@@ -56,9 +55,6 @@ function useShellPullToRefresh({ enabled, refreshRuntime = null } = {}) {
56
55
  });
57
56
 
58
57
  onBeforeUnmount(() => {
59
- if (typeof window !== "object") {
60
- return;
61
- }
62
58
  window.removeEventListener("pointerdown", handlePullPointerDown, { capture: true });
63
59
  window.removeEventListener("pointermove", handlePullPointerMove, { capture: true });
64
60
  window.removeEventListener("pointerup", handlePullPointerEnd, { capture: true });
@@ -70,7 +66,7 @@ function useShellPullToRefresh({ enabled, refreshRuntime = null } = {}) {
70
66
  });
71
67
 
72
68
  function canRefresh() {
73
- return Boolean(refreshRuntime && typeof refreshRuntime.refresh === "function");
69
+ return refreshRuntime !== NO_SHELL_WEB_REFRESH_RUNTIME;
74
70
  }
75
71
 
76
72
  function canStartFromTarget(target) {
@@ -124,7 +120,7 @@ function useShellPullToRefresh({ enabled, refreshRuntime = null } = {}) {
124
120
  }
125
121
 
126
122
  function handlePullTouchStart(event) {
127
- if (activePull || event?.touches?.length !== 1 || !canStartFromTarget(event.target)) {
123
+ if (activePull || event.touches.length !== 1 || !canStartFromTarget(event.target)) {
128
124
  return;
129
125
  }
130
126
 
@@ -178,7 +174,7 @@ function useShellPullToRefresh({ enabled, refreshRuntime = null } = {}) {
178
174
  return;
179
175
  }
180
176
 
181
- if (event?.cancelable) {
177
+ if (event.cancelable) {
182
178
  event.preventDefault();
183
179
  }
184
180
  pullDistance.value = Math.min(PULL_REFRESH_MAX_DISTANCE, Math.round(deltaY * 0.55));