@jskit-ai/shell-web 0.2.4 → 0.2.5
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.
- package/package.json +10 -4
- package/patterns/page-and-placement/example/src/placementTopology.js +1 -0
- package/src/client/asyncModuleRecovery/index.js +1 -0
- package/src/client/asyncModuleRecovery/inject.js +30 -18
- package/src/client/asyncModuleRecovery/runtime.js +14 -22
- package/src/client/bootstrap/bootstrapPayloadHandlerRegistry.js +13 -6
- package/src/client/browser.js +56 -0
- package/src/client/clientUpdate/runtime.js +28 -18
- package/src/client/components/ShellErrorHost.vue +19 -219
- package/src/client/components/ShellLayout.vue +19 -227
- package/src/client/components/ShellOutlet.vue +16 -53
- package/src/client/components/ShellRouteTransition.vue +2 -291
- package/src/client/composables/shellLayoutDrawerPreference.js +15 -8
- package/src/client/composables/useShellDrawer.js +194 -0
- package/src/client/composables/useShellErrorHost.js +171 -0
- package/src/client/composables/useShellLayoutState.js +10 -20
- package/src/client/composables/useShellNavigationLink.js +6 -6
- package/src/client/composables/useShellPullToRefresh.js +15 -19
- package/src/client/composables/useShellRouteTransition.js +218 -0
- package/src/client/error/index.js +1 -1
- package/src/client/error/inject.js +36 -48
- package/src/client/error/normalize.js +2 -3
- package/src/client/error/policy.js +9 -0
- package/src/client/error/presentation.js +67 -0
- package/src/client/error/presentationDefaults.js +2 -2
- package/src/client/error/presenters.js +44 -19
- package/src/client/error/runtime.js +20 -17
- package/src/client/error/store.js +4 -0
- package/src/client/navigation/linkResolver.js +6 -2
- package/src/client/navigation/usePaths.js +11 -8
- package/src/client/navigation/useSurfaceRouteContext.js +3 -3
- package/src/client/placement/debug.js +2 -2
- package/src/client/placement/index.js +1 -0
- package/src/client/placement/inject.js +49 -46
- package/src/client/placement/pathname.js +3 -9
- package/src/client/placement/runtime.js +4 -16
- package/src/client/placement/surfaceContext.js +14 -33
- package/src/client/placement/validators.js +6 -1
- package/src/client/providers/ShellWebClientProvider.js +14 -32
- package/src/client/providers/appModuleLoadFailure.js +1 -1
- package/src/client/requestRecovery/index.js +1 -0
- package/src/client/requestRecovery/inject.js +29 -17
- package/src/client/requestRecovery/runtime.js +33 -84
- package/src/client/runtime/bootstrapRuntime.js +10 -32
- package/src/client/runtime/refreshRuntime.js +24 -21
- package/src/client/stores/useShellErrorPresentationStore.js +5 -19
- package/src/client/support/drawerWidth.js +39 -0
- package/src/client/support/gestureTargets.js +4 -2
- package/src/client/support/menuLinkTarget.js +1 -1
- package/src/client/support/navigationLinkKeyboard.js +1 -1
- package/src/client/support/primaryNavigation.js +93 -0
- package/src/client/support/routeSwipeGesture.js +13 -3
- package/src/client/support/shellLayoutClass.js +4 -6
- package/src/client/types.js +38 -0
- package/test/asyncModuleRecoveryInject.test.js +13 -18
- package/test/browser.test.js +51 -0
- package/test/clientUpdate.test.js +12 -1
- package/test/drawerWidth.test.js +64 -0
- package/test/errorActions.test.js +7 -2
- package/test/errorPresentation.test.js +51 -0
- package/test/placementInject.test.js +60 -0
- package/test/primaryNavigation.test.js +75 -0
- package/test/provider.test.js +18 -4
- package/test/requestRecovery.test.js +13 -18
- package/test/settingsPlacementContract.test.js +12 -8
- package/test/support/mountComposable.js +90 -0
- package/test/useShellDrawer.test.js +213 -0
- package/test/useShellErrorHost.test.js +149 -0
- package/test/useShellRouteTransition.test.js +129 -0
|
@@ -1,31 +1,15 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
-
import {
|
|
3
|
-
computed,
|
|
4
|
-
inject,
|
|
5
|
-
nextTick,
|
|
6
|
-
onBeforeUnmount,
|
|
7
|
-
onMounted,
|
|
8
|
-
ref,
|
|
9
|
-
watch
|
|
10
|
-
} from "vue";
|
|
2
|
+
import { computed, inject, ref } from "vue";
|
|
11
3
|
import { useDisplay } from "vuetify";
|
|
4
|
+
import { useShellDrawer } from "../composables/useShellDrawer.js";
|
|
12
5
|
import { useShellLayoutState } from "../composables/useShellLayoutState.js";
|
|
13
6
|
import { useShellPullToRefresh } from "../composables/useShellPullToRefresh.js";
|
|
14
7
|
import {
|
|
15
|
-
resolveShellDrawerPresentation,
|
|
16
|
-
resolveShellDrawerToggleLabel
|
|
17
|
-
} from "../support/drawerPresentation.js";
|
|
18
|
-
import {
|
|
19
|
-
DEFAULT_SHELL_DRAWER_WIDTH,
|
|
20
8
|
DEFAULT_SHELL_NAVIGATION_ITEM_SPACING,
|
|
21
|
-
DEFAULT_SHELL_RAIL_WIDTH
|
|
22
|
-
normalizeShellDrawerWidth,
|
|
23
|
-
normalizeShellNavigationItemSpacing,
|
|
24
|
-
normalizeShellRailWidth,
|
|
25
|
-
resolveContentAwareDrawerWidth
|
|
9
|
+
DEFAULT_SHELL_RAIL_WIDTH
|
|
26
10
|
} from "../support/drawerWidth.js";
|
|
27
|
-
import {
|
|
28
|
-
import { SHELL_WEB_REFRESH_RUNTIME_KEY } from "../runtime/refreshRuntime.js";
|
|
11
|
+
import { resolveShellLayoutClass } from "../support/shellLayoutClass.js";
|
|
12
|
+
import { NO_SHELL_WEB_REFRESH_RUNTIME, SHELL_WEB_REFRESH_RUNTIME_KEY } from "../runtime/refreshRuntime.js";
|
|
29
13
|
import ShellOutlet from "./ShellOutlet.vue";
|
|
30
14
|
import ShellRouteTransition from "./ShellRouteTransition.vue";
|
|
31
15
|
import { useJskitText } from "../i18n.js";
|
|
@@ -67,10 +51,9 @@ const props = defineProps({
|
|
|
67
51
|
}
|
|
68
52
|
});
|
|
69
53
|
|
|
54
|
+
const layoutState = useShellLayoutState(props);
|
|
70
55
|
const {
|
|
71
|
-
drawerDefaultOpen,
|
|
72
56
|
drawerOpen,
|
|
73
|
-
setDrawerOpen,
|
|
74
57
|
supportingContentOpen,
|
|
75
58
|
supportingContentTitle,
|
|
76
59
|
setSupportingContentOpen,
|
|
@@ -78,18 +61,13 @@ const {
|
|
|
78
61
|
toggleDrawer,
|
|
79
62
|
resolvedSurface,
|
|
80
63
|
resolvedSurfaceLabel
|
|
81
|
-
} =
|
|
64
|
+
} = layoutState;
|
|
82
65
|
const display = useDisplay();
|
|
83
|
-
|
|
84
|
-
const
|
|
66
|
+
/** @type {import("../types.js").ShellRefreshRuntime} */
|
|
67
|
+
const refreshRuntime = inject(SHELL_WEB_REFRESH_RUNTIME_KEY, NO_SHELL_WEB_REFRESH_RUNTIME);
|
|
85
68
|
const navigationToggle = ref(null);
|
|
86
|
-
const navigationDrawer = ref(null);
|
|
87
|
-
const measuredDrawerWidth = ref(DEFAULT_SHELL_DRAWER_WIDTH);
|
|
88
|
-
let drawerContentObserver = null;
|
|
89
|
-
let drawerMeasurementFrame = null;
|
|
90
|
-
let shellMounted = false;
|
|
91
69
|
|
|
92
|
-
const layoutClass = computed(() => resolveShellLayoutClass(display
|
|
70
|
+
const layoutClass = computed(() => resolveShellLayoutClass(display.name.value));
|
|
93
71
|
const isCompactLayout = computed(() => layoutClass.value === "compact");
|
|
94
72
|
const {
|
|
95
73
|
pullRefreshing,
|
|
@@ -98,200 +76,15 @@ const {
|
|
|
98
76
|
pullRefreshLabel,
|
|
99
77
|
pullRefreshStyle
|
|
100
78
|
} = useShellPullToRefresh({ enabled: isCompactLayout, refreshRuntime });
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
})
|
|
110
|
-
const fixedDrawerWidth = computed(() => props.drawerWidth !== null && props.drawerWidth !== undefined);
|
|
111
|
-
const resolvedDrawerWidth = computed(() =>
|
|
112
|
-
normalizeShellDrawerWidth(fixedDrawerWidth.value ? props.drawerWidth : measuredDrawerWidth.value)
|
|
113
|
-
);
|
|
114
|
-
const resolvedRailWidth = computed(() => normalizeShellRailWidth(props.railWidth));
|
|
115
|
-
const resolvedNavigationItemSpacing = computed(() =>
|
|
116
|
-
normalizeShellNavigationItemSpacing(props.navigationItemSpacing)
|
|
117
|
-
);
|
|
118
|
-
watch(
|
|
119
|
-
drawerOpen,
|
|
120
|
-
handleDrawerOpenChange
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
watch(
|
|
124
|
-
isCompactLayout,
|
|
125
|
-
handleLayoutClassChange,
|
|
126
|
-
{ immediate: true }
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
watch(drawerPresentation, scheduleDrawerWidthMeasurement, { flush: "post" });
|
|
130
|
-
watch(resolvedSurface, scheduleDrawerWidthMeasurement, { flush: "post" });
|
|
131
|
-
watch(resolvedNavigationItemSpacing, scheduleDrawerWidthMeasurement, { flush: "post" });
|
|
132
|
-
|
|
133
|
-
onMounted(attachShellListeners);
|
|
134
|
-
onBeforeUnmount(detachShellListeners);
|
|
135
|
-
|
|
136
|
-
function attachShellListeners() {
|
|
137
|
-
shellMounted = true;
|
|
138
|
-
if (typeof window !== "object") {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
window.addEventListener("keydown", handleShellKeydown);
|
|
143
|
-
window.addEventListener("resize", scheduleDrawerWidthMeasurement, { passive: true });
|
|
144
|
-
|
|
145
|
-
if (document?.fonts) {
|
|
146
|
-
void document.fonts.ready.then(scheduleDrawerWidthMeasurement);
|
|
147
|
-
document.fonts.addEventListener?.("loadingdone", scheduleDrawerWidthMeasurement);
|
|
148
|
-
}
|
|
149
|
-
void nextTick().then(initializeDrawerMeasurement);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function detachShellListeners() {
|
|
153
|
-
shellMounted = false;
|
|
154
|
-
if (typeof window !== "object") {
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
window.removeEventListener("keydown", handleShellKeydown);
|
|
159
|
-
window.removeEventListener("resize", scheduleDrawerWidthMeasurement);
|
|
160
|
-
document?.fonts?.removeEventListener?.("loadingdone", scheduleDrawerWidthMeasurement);
|
|
161
|
-
drawerContentObserver?.disconnect();
|
|
162
|
-
drawerContentObserver = null;
|
|
163
|
-
if (drawerMeasurementFrame !== null) {
|
|
164
|
-
window.cancelAnimationFrame(drawerMeasurementFrame);
|
|
165
|
-
drawerMeasurementFrame = null;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function handleDrawerOpenChange(open) {
|
|
170
|
-
if (!isCompactLayout.value) {
|
|
171
|
-
wideDrawerOpen.value = Boolean(open);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
function handleLayoutClassChange(compact) {
|
|
176
|
-
setDrawerOpen(compact ? false : wideDrawerOpen.value);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
function handleShellKeydown(event) {
|
|
180
|
-
if (
|
|
181
|
-
event?.defaultPrevented ||
|
|
182
|
-
event?.key !== "Escape" ||
|
|
183
|
-
!isCompactLayout.value ||
|
|
184
|
-
!drawerOpen.value
|
|
185
|
-
) {
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
event.preventDefault();
|
|
190
|
-
setDrawerOpen(false);
|
|
191
|
-
void nextTick().then(focusNavigationToggle);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
function focusNavigationToggle() {
|
|
195
|
-
const toggleElement = navigationToggle.value?.$el || navigationToggle.value;
|
|
196
|
-
toggleElement?.focus?.({ preventScroll: true });
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
function initializeDrawerMeasurement() {
|
|
200
|
-
const drawerElement = resolveNavigationDrawerElement();
|
|
201
|
-
const drawerContent = drawerElement?.querySelector?.(".v-navigation-drawer__content") || drawerElement;
|
|
202
|
-
if (typeof MutationObserver === "function" && drawerContent) {
|
|
203
|
-
drawerContentObserver?.disconnect();
|
|
204
|
-
drawerContentObserver = new MutationObserver(scheduleDrawerWidthMeasurement);
|
|
205
|
-
drawerContentObserver.observe(drawerContent, {
|
|
206
|
-
childList: true,
|
|
207
|
-
characterData: true,
|
|
208
|
-
subtree: true
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
scheduleDrawerWidthMeasurement();
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
function resolveNavigationDrawerElement() {
|
|
215
|
-
const exposedElement = navigationDrawer.value?.$el || navigationDrawer.value || null;
|
|
216
|
-
if (typeof exposedElement?.getBoundingClientRect === "function") {
|
|
217
|
-
return exposedElement;
|
|
218
|
-
}
|
|
219
|
-
if (typeof document === "object") {
|
|
220
|
-
return document.getElementById("jskit-shell-drawer");
|
|
221
|
-
}
|
|
222
|
-
return null;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
function scheduleDrawerWidthMeasurement() {
|
|
226
|
-
if (
|
|
227
|
-
!shellMounted ||
|
|
228
|
-
fixedDrawerWidth.value ||
|
|
229
|
-
!drawerPresentation.value.visible ||
|
|
230
|
-
drawerPresentation.value.rail ||
|
|
231
|
-
typeof window !== "object"
|
|
232
|
-
) {
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
if (drawerMeasurementFrame !== null) {
|
|
237
|
-
window.cancelAnimationFrame(drawerMeasurementFrame);
|
|
238
|
-
}
|
|
239
|
-
drawerMeasurementFrame = window.requestAnimationFrame(measureDrawerContentWidth);
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
function measureDrawerContentWidth() {
|
|
243
|
-
drawerMeasurementFrame = null;
|
|
244
|
-
const drawerElement = resolveNavigationDrawerElement();
|
|
245
|
-
if (!drawerElement || typeof document !== "object") {
|
|
246
|
-
return;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
const drawerRect = drawerElement.getBoundingClientRect();
|
|
250
|
-
const drawerStyle = window.getComputedStyle(drawerElement);
|
|
251
|
-
const rightToLeft = drawerStyle.direction === "rtl";
|
|
252
|
-
const endBorderWidth = Number.parseFloat(
|
|
253
|
-
rightToLeft ? drawerStyle.borderLeftWidth : drawerStyle.borderRightWidth
|
|
254
|
-
) || 0;
|
|
255
|
-
const measurements = [];
|
|
256
|
-
|
|
257
|
-
for (const label of drawerElement.querySelectorAll(".v-list-item-title")) {
|
|
258
|
-
const labelStyle = window.getComputedStyle(label);
|
|
259
|
-
if (labelStyle.display === "none" || labelStyle.visibility === "hidden") {
|
|
260
|
-
continue;
|
|
261
|
-
}
|
|
262
|
-
const textRect = measureRenderedText(label);
|
|
263
|
-
if (!textRect || textRect.width <= 0) {
|
|
264
|
-
continue;
|
|
265
|
-
}
|
|
266
|
-
measurements.push({
|
|
267
|
-
logicalStart: rightToLeft
|
|
268
|
-
? drawerRect.right - textRect.right
|
|
269
|
-
: textRect.left - drawerRect.left,
|
|
270
|
-
textWidth: textRect.width
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
const nextWidth = resolveContentAwareDrawerWidth(measurements, {
|
|
275
|
-
endGap: resolvedNavigationItemSpacing.value + endBorderWidth
|
|
276
|
-
});
|
|
277
|
-
if (Math.abs(nextWidth - measuredDrawerWidth.value) >= 0.25) {
|
|
278
|
-
measuredDrawerWidth.value = nextWidth;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
function measureRenderedText(element) {
|
|
283
|
-
const range = document.createRange();
|
|
284
|
-
range.selectNodeContents(element);
|
|
285
|
-
const rect = range.getBoundingClientRect();
|
|
286
|
-
range.detach?.();
|
|
287
|
-
return rect;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
function handleDrawerVisibilityChange(open) {
|
|
291
|
-
if (isCompactLayout.value || drawerPresentation.value.closedMode === "hidden" || open === false) {
|
|
292
|
-
setDrawerOpen(open);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
79
|
+
const {
|
|
80
|
+
drawerPresentation,
|
|
81
|
+
drawerToggleLabel,
|
|
82
|
+
fixedDrawerWidth,
|
|
83
|
+
handleDrawerVisibilityChange,
|
|
84
|
+
resolvedDrawerWidth,
|
|
85
|
+
resolvedNavigationItemSpacing,
|
|
86
|
+
resolvedRailWidth
|
|
87
|
+
} = useShellDrawer({ props, isCompactLayout, navigationToggle, layoutState });
|
|
295
88
|
</script>
|
|
296
89
|
|
|
297
90
|
<template>
|
|
@@ -348,7 +141,6 @@ function handleDrawerVisibilityChange(open) {
|
|
|
348
141
|
</div>
|
|
349
142
|
|
|
350
143
|
<v-navigation-drawer
|
|
351
|
-
ref="navigationDrawer"
|
|
352
144
|
id="jskit-shell-drawer"
|
|
353
145
|
:model-value="drawerPresentation.visible"
|
|
354
146
|
class="shell-layout__drawer"
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
-
import {
|
|
3
|
-
computed,
|
|
4
|
-
onBeforeUnmount,
|
|
5
|
-
onMounted,
|
|
6
|
-
ref
|
|
7
|
-
} from "vue";
|
|
2
|
+
import { computed } from "vue";
|
|
8
3
|
import { useRoute } from "vue-router";
|
|
9
4
|
import { useDisplay } from "vuetify";
|
|
10
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
useWebPlacementContext,
|
|
7
|
+
useWebPlacementRevision,
|
|
8
|
+
useWebPlacementRuntime
|
|
9
|
+
} from "../placement/inject.js";
|
|
11
10
|
import { resolveRuntimePathname } from "../placement/pathname.js";
|
|
12
11
|
import {
|
|
13
12
|
readPlacementSurfaceConfig,
|
|
14
13
|
resolveSurfaceIdFromPlacementPathname
|
|
15
14
|
} from "../placement/surfaceContext.js";
|
|
16
|
-
import {
|
|
15
|
+
import { resolveShellLayoutClass } from "../support/shellLayoutClass.js";
|
|
17
16
|
import { useJskitText } from "../i18n.js";
|
|
18
17
|
|
|
19
18
|
const props = defineProps({
|
|
@@ -31,20 +30,8 @@ const props = defineProps({
|
|
|
31
30
|
}
|
|
32
31
|
});
|
|
33
32
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
route = useRoute();
|
|
37
|
-
} catch {
|
|
38
|
-
route = null;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
let display = null;
|
|
42
|
-
try {
|
|
43
|
-
display = useDisplay();
|
|
44
|
-
} catch {
|
|
45
|
-
display = null;
|
|
46
|
-
}
|
|
47
|
-
|
|
33
|
+
const route = useRoute();
|
|
34
|
+
const display = useDisplay();
|
|
48
35
|
const { text } = useJskitText();
|
|
49
36
|
const TRANSLATED_PLACEMENT_PROPS = Object.freeze(["label", "title"]);
|
|
50
37
|
|
|
@@ -55,14 +42,10 @@ function isPlacementText(value) {
|
|
|
55
42
|
// A placement's label and title may be message keys or { key, fallback }; they
|
|
56
43
|
// reach the component in the active language. Plain text passes unchanged.
|
|
57
44
|
function placementProps(entry) {
|
|
58
|
-
const
|
|
59
|
-
if (!source || typeof source !== "object") {
|
|
60
|
-
return source;
|
|
61
|
-
}
|
|
62
|
-
const translated = { ...source };
|
|
45
|
+
const translated = { ...entry.props };
|
|
63
46
|
for (const name of TRANSLATED_PLACEMENT_PROPS) {
|
|
64
|
-
if (isPlacementText(
|
|
65
|
-
translated[name] = text(
|
|
47
|
+
if (isPlacementText(entry.props[name])) {
|
|
48
|
+
translated[name] = text(entry.props[name]);
|
|
66
49
|
}
|
|
67
50
|
}
|
|
68
51
|
return translated;
|
|
@@ -70,31 +53,11 @@ function placementProps(entry) {
|
|
|
70
53
|
|
|
71
54
|
const placementRuntime = useWebPlacementRuntime();
|
|
72
55
|
const { context: placementContext } = useWebPlacementContext();
|
|
73
|
-
const revision =
|
|
74
|
-
typeof placementRuntime.getRevision === "function" ? placementRuntime.getRevision() : 0
|
|
75
|
-
);
|
|
76
|
-
let unsubscribe = null;
|
|
77
|
-
|
|
78
|
-
onMounted(() => {
|
|
79
|
-
if (typeof placementRuntime.subscribe !== "function") {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
unsubscribe = placementRuntime.subscribe((event) => {
|
|
83
|
-
const next = Number(event?.revision);
|
|
84
|
-
revision.value = Number.isInteger(next) ? next : revision.value + 1;
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
onBeforeUnmount(() => {
|
|
89
|
-
if (typeof unsubscribe === "function") {
|
|
90
|
-
unsubscribe();
|
|
91
|
-
unsubscribe = null;
|
|
92
|
-
}
|
|
93
|
-
});
|
|
56
|
+
const revision = useWebPlacementRevision(placementRuntime);
|
|
94
57
|
|
|
95
58
|
const resolvedSurface = computed(() => {
|
|
96
|
-
const contextValue = placementContext
|
|
97
|
-
const pathname = resolveRuntimePathname(route
|
|
59
|
+
const contextValue = placementContext.value;
|
|
60
|
+
const pathname = resolveRuntimePathname(route.path);
|
|
98
61
|
const surfaceFromPathname = resolveSurfaceIdFromPlacementPathname(contextValue, pathname);
|
|
99
62
|
if (surfaceFromPathname) {
|
|
100
63
|
return surfaceFromPathname;
|
|
@@ -111,7 +74,7 @@ const resolvedTargetId = computed(() => {
|
|
|
111
74
|
return String(props.target || "").trim();
|
|
112
75
|
});
|
|
113
76
|
|
|
114
|
-
const resolvedLayoutClass = computed(() => resolveShellLayoutClass(display
|
|
77
|
+
const resolvedLayoutClass = computed(() => resolveShellLayoutClass(display.name.value));
|
|
115
78
|
|
|
116
79
|
const placements = computed(() => {
|
|
117
80
|
void revision.value;
|
|
@@ -1,32 +1,5 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
-
import {
|
|
3
|
-
computed,
|
|
4
|
-
onBeforeUnmount,
|
|
5
|
-
onMounted,
|
|
6
|
-
ref,
|
|
7
|
-
watch
|
|
8
|
-
} from "vue";
|
|
9
|
-
import { useRoute, useRouter } from "vue-router";
|
|
10
|
-
import { useDisplay } from "vuetify";
|
|
11
|
-
import { normalizePathname } from "@jskit-ai/kernel/shared";
|
|
12
|
-
import {
|
|
13
|
-
useWebPlacementContext,
|
|
14
|
-
useWebPlacementRuntime
|
|
15
|
-
} from "../placement/inject.js";
|
|
16
|
-
import { resolveRuntimePathname } from "../placement/pathname.js";
|
|
17
|
-
import {
|
|
18
|
-
readPlacementSurfaceConfig,
|
|
19
|
-
resolveSurfaceNavigationTargetFromPlacementContext,
|
|
20
|
-
resolveSurfaceIdFromPlacementPathname
|
|
21
|
-
} from "../placement/surfaceContext.js";
|
|
22
|
-
import {
|
|
23
|
-
normalizeMenuLinkPathname,
|
|
24
|
-
resolveMenuLinkTarget
|
|
25
|
-
} from "../support/menuLinkTarget.js";
|
|
26
|
-
import { resolveShellRouteTransitionKey } from "../support/routeTransitionKey.js";
|
|
27
|
-
import { createRouteSwipeGesture } from "../support/routeSwipeGesture.js";
|
|
28
|
-
import { isPrimaryTouchPointer, isShellGestureIgnoredTarget } from "../support/gestureTargets.js";
|
|
29
|
-
import { readViewportWidth, resolveShellLayoutClass } from "../support/shellLayoutClass.js";
|
|
2
|
+
import { useShellRouteTransition } from "../composables/useShellRouteTransition.js";
|
|
30
3
|
|
|
31
4
|
const props = defineProps({
|
|
32
5
|
enabled: {
|
|
@@ -47,269 +20,7 @@ const props = defineProps({
|
|
|
47
20
|
}
|
|
48
21
|
});
|
|
49
22
|
|
|
50
|
-
const
|
|
51
|
-
const router = useRouter();
|
|
52
|
-
const display = useDisplay();
|
|
53
|
-
const placementRuntime = useWebPlacementRuntime();
|
|
54
|
-
const { context: placementContext } = useWebPlacementContext();
|
|
55
|
-
const revision = ref(
|
|
56
|
-
typeof placementRuntime.getRevision === "function" ? placementRuntime.getRevision() : 0
|
|
57
|
-
);
|
|
58
|
-
const transitionDirection = ref("none");
|
|
59
|
-
let unsubscribe = null;
|
|
60
|
-
const swipeGesture = createRouteSwipeGesture();
|
|
61
|
-
let stopSwipeClassWatch = null;
|
|
62
|
-
|
|
63
|
-
onMounted(() => {
|
|
64
|
-
if (typeof placementRuntime.subscribe !== "function") {
|
|
65
|
-
unsubscribe = null;
|
|
66
|
-
} else {
|
|
67
|
-
unsubscribe = placementRuntime.subscribe((event) => {
|
|
68
|
-
const next = Number(event?.revision);
|
|
69
|
-
revision.value = Number.isInteger(next) ? next : revision.value + 1;
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (typeof window === "object") {
|
|
74
|
-
window.addEventListener("pointerdown", handlePointerDown, { capture: true, passive: true });
|
|
75
|
-
window.addEventListener("pointermove", handlePointerMove, { capture: true, passive: false });
|
|
76
|
-
window.addEventListener("pointerup", handlePointerEnd, { capture: true, passive: true });
|
|
77
|
-
window.addEventListener("pointercancel", handlePointerCancel, { capture: true, passive: true });
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
stopSwipeClassWatch = watch(
|
|
81
|
-
swipeNavigationEnabled,
|
|
82
|
-
(enabled) => {
|
|
83
|
-
if (typeof document !== "object") {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
document.documentElement.classList.toggle("shell-route-swipe-enabled", enabled);
|
|
87
|
-
},
|
|
88
|
-
{ immediate: true }
|
|
89
|
-
);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
onBeforeUnmount(() => {
|
|
93
|
-
if (typeof unsubscribe === "function") {
|
|
94
|
-
unsubscribe();
|
|
95
|
-
unsubscribe = null;
|
|
96
|
-
}
|
|
97
|
-
if (typeof stopSwipeClassWatch === "function") {
|
|
98
|
-
stopSwipeClassWatch();
|
|
99
|
-
stopSwipeClassWatch = null;
|
|
100
|
-
}
|
|
101
|
-
if (typeof document === "object") {
|
|
102
|
-
document.documentElement.classList.remove("shell-route-swipe-enabled");
|
|
103
|
-
}
|
|
104
|
-
if (typeof window === "object") {
|
|
105
|
-
window.removeEventListener("pointerdown", handlePointerDown, { capture: true });
|
|
106
|
-
window.removeEventListener("pointermove", handlePointerMove, { capture: true });
|
|
107
|
-
window.removeEventListener("pointerup", handlePointerEnd, { capture: true });
|
|
108
|
-
window.removeEventListener("pointercancel", handlePointerCancel, { capture: true });
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
const resolvedLayoutClass = computed(() => resolveShellLayoutClass(display?.name?.value, readViewportWidth()));
|
|
113
|
-
|
|
114
|
-
const currentPathname = computed(() =>
|
|
115
|
-
normalizeComparablePathname(resolveRuntimePathname(route?.path || route?.fullPath || "/"))
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
const currentSurfaceId = computed(() => {
|
|
119
|
-
const contextValue = placementContext?.value || null;
|
|
120
|
-
const surfaceFromPathname = resolveSurfaceIdFromPlacementPathname(contextValue, currentPathname.value);
|
|
121
|
-
if (surfaceFromPathname) {
|
|
122
|
-
return surfaceFromPathname;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const surfaceConfig = readPlacementSurfaceConfig(contextValue);
|
|
126
|
-
return surfaceConfig.defaultSurfaceId || "*";
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
const primaryNavEntries = computed(() => {
|
|
130
|
-
void revision.value;
|
|
131
|
-
const contextValue = placementContext?.value || null;
|
|
132
|
-
const routeParams = route?.params || {};
|
|
133
|
-
|
|
134
|
-
return placementRuntime
|
|
135
|
-
.getPlacements({
|
|
136
|
-
surface: currentSurfaceId.value,
|
|
137
|
-
target: props.target,
|
|
138
|
-
layoutClass: "compact"
|
|
139
|
-
})
|
|
140
|
-
.filter((entry) => String(entry.semanticTarget || entry.target || "").trim() === props.semanticTarget)
|
|
141
|
-
.map((entry, index) => {
|
|
142
|
-
const entryProps = entry?.props && typeof entry.props === "object" ? entry.props : {};
|
|
143
|
-
const target = resolveMenuLinkTarget({
|
|
144
|
-
to: entryProps.to,
|
|
145
|
-
surface: entryProps.surface,
|
|
146
|
-
currentSurfaceId: currentSurfaceId.value,
|
|
147
|
-
placementContext: contextValue,
|
|
148
|
-
scopedSuffix: entryProps.scopedSuffix,
|
|
149
|
-
unscopedSuffix: entryProps.unscopedSuffix,
|
|
150
|
-
routeParams
|
|
151
|
-
});
|
|
152
|
-
const navigationTarget = resolveSurfaceNavigationTargetFromPlacementContext(contextValue, {
|
|
153
|
-
path: target,
|
|
154
|
-
surfaceId: entryProps.surface || currentSurfaceId.value
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
return Object.freeze({
|
|
158
|
-
id: entry.id,
|
|
159
|
-
index,
|
|
160
|
-
exact: entryProps.exact === true,
|
|
161
|
-
href: navigationTarget.href,
|
|
162
|
-
pathname: normalizeComparablePathname(navigationTarget.href),
|
|
163
|
-
sameOrigin: navigationTarget.sameOrigin
|
|
164
|
-
});
|
|
165
|
-
})
|
|
166
|
-
.filter((entry) => entry.pathname && entry.sameOrigin);
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
const activePrimaryNavIndex = computed(() => {
|
|
170
|
-
const pathname = currentPathname.value;
|
|
171
|
-
let bestMatch = null;
|
|
172
|
-
|
|
173
|
-
for (const entry of primaryNavEntries.value) {
|
|
174
|
-
if (!pathMatchesNavigationEntry(pathname, entry)) {
|
|
175
|
-
continue;
|
|
176
|
-
}
|
|
177
|
-
if (!bestMatch || entry.pathname.length > bestMatch.pathname.length) {
|
|
178
|
-
bestMatch = entry;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
return bestMatch ? bestMatch.index : -1;
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
watch(
|
|
186
|
-
activePrimaryNavIndex,
|
|
187
|
-
(nextIndex, previousIndex) => {
|
|
188
|
-
if (
|
|
189
|
-
!Number.isInteger(previousIndex) ||
|
|
190
|
-
previousIndex < 0 ||
|
|
191
|
-
nextIndex < 0 ||
|
|
192
|
-
nextIndex === previousIndex
|
|
193
|
-
) {
|
|
194
|
-
transitionDirection.value = "none";
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
transitionDirection.value = nextIndex > previousIndex ? "forward" : "reverse";
|
|
199
|
-
},
|
|
200
|
-
{ flush: "sync" }
|
|
201
|
-
);
|
|
202
|
-
|
|
203
|
-
const routeTransitionName = computed(() => {
|
|
204
|
-
if (!props.enabled || resolvedLayoutClass.value !== "compact") {
|
|
205
|
-
return "";
|
|
206
|
-
}
|
|
207
|
-
if (transitionDirection.value === "forward") {
|
|
208
|
-
return "shell-route-slide-forward";
|
|
209
|
-
}
|
|
210
|
-
if (transitionDirection.value === "reverse") {
|
|
211
|
-
return "shell-route-slide-reverse";
|
|
212
|
-
}
|
|
213
|
-
return "";
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
// Animation can change with viewport geometry; pane identity changes only with
|
|
217
|
-
// navigation. Resizing must not recreate the routed form or lose focus.
|
|
218
|
-
const routeTransitionKey = ref("");
|
|
219
|
-
watch(
|
|
220
|
-
[() => normalizeComparablePathname(route?.path || route?.fullPath || "/"), currentSurfaceId],
|
|
221
|
-
([routePathKey, surfaceId]) => {
|
|
222
|
-
routeTransitionKey.value = resolveShellRouteTransitionKey({
|
|
223
|
-
routePathKey,
|
|
224
|
-
routeTransitionName: routeTransitionName.value,
|
|
225
|
-
surfaceId
|
|
226
|
-
});
|
|
227
|
-
},
|
|
228
|
-
{ immediate: true, flush: "sync" }
|
|
229
|
-
);
|
|
230
|
-
|
|
231
|
-
const swipeNavigationEnabled = computed(() =>
|
|
232
|
-
Boolean(
|
|
233
|
-
props.enabled &&
|
|
234
|
-
props.swipeEnabled &&
|
|
235
|
-
resolvedLayoutClass.value === "compact" &&
|
|
236
|
-
primaryNavEntries.value.length > 1 &&
|
|
237
|
-
activePrimaryNavIndex.value >= 0
|
|
238
|
-
)
|
|
239
|
-
);
|
|
240
|
-
|
|
241
|
-
function handlePointerDown(event) {
|
|
242
|
-
if (!swipeNavigationEnabled.value || !isPrimaryTouchPointer(event) || isShellGestureIgnoredTarget(event.target)) {
|
|
243
|
-
swipeGesture.reset();
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
swipeGesture.start(event);
|
|
248
|
-
try {
|
|
249
|
-
event.target?.setPointerCapture?.(event.pointerId);
|
|
250
|
-
} catch {
|
|
251
|
-
// Synthetic test events and some embedded webviews may not expose an active pointer.
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
function handlePointerMove(event) {
|
|
256
|
-
const { claim, offset } = swipeGesture.move(event);
|
|
257
|
-
if (claim) {
|
|
258
|
-
event.preventDefault();
|
|
259
|
-
}
|
|
260
|
-
if (offset) {
|
|
261
|
-
navigateBySwipe(offset);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
function handlePointerEnd(event) {
|
|
266
|
-
const offset = swipeGesture.end(event);
|
|
267
|
-
if (offset && swipeNavigationEnabled.value) {
|
|
268
|
-
navigateBySwipe(offset);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
function handlePointerCancel(event) {
|
|
273
|
-
swipeGesture.cancel(event);
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
function navigateBySwipe(offset = 0) {
|
|
277
|
-
const currentIndex = activePrimaryNavIndex.value;
|
|
278
|
-
const nextEntry = primaryNavEntries.value[currentIndex + offset];
|
|
279
|
-
if (!nextEntry?.href || normalizeComparablePathname(nextEntry.href) === currentPathname.value) {
|
|
280
|
-
return;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
void router.push(nextEntry.href).catch(() => {});
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
function normalizeComparablePathname(value = "") {
|
|
287
|
-
const raw = String(value || "").trim();
|
|
288
|
-
if (!raw) {
|
|
289
|
-
return "";
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
try {
|
|
293
|
-
const parsed = new URL(raw, window.location.href);
|
|
294
|
-
if (parsed.origin !== window.location.origin) {
|
|
295
|
-
return "";
|
|
296
|
-
}
|
|
297
|
-
return normalizePathname(parsed.pathname);
|
|
298
|
-
} catch {
|
|
299
|
-
return normalizePathname(normalizeMenuLinkPathname(raw));
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
function pathMatchesNavigationEntry(pathname = "", entry = {}) {
|
|
304
|
-
const target = String(entry.pathname || "").trim();
|
|
305
|
-
if (!target) {
|
|
306
|
-
return false;
|
|
307
|
-
}
|
|
308
|
-
if (entry.exact || target === "/") {
|
|
309
|
-
return pathname === target;
|
|
310
|
-
}
|
|
311
|
-
return pathname === target || pathname.startsWith(`${target}/`);
|
|
312
|
-
}
|
|
23
|
+
const { routeTransitionKey, routeTransitionName } = useShellRouteTransition(props);
|
|
313
24
|
</script>
|
|
314
25
|
|
|
315
26
|
<template>
|