@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
@@ -114,18 +114,8 @@ function requestRecoveryMessage(error = null, {
114
114
  return t("jskit.shell.recovery.unreachable", { label: requestLabel });
115
115
  }
116
116
 
117
- function resolveQueryMeta(query = null) {
118
- if (isRecord(query?.meta)) {
119
- return query.meta;
120
- }
121
- if (isRecord(query?.options?.meta)) {
122
- return query.options.meta;
123
- }
124
- return {};
125
- }
126
-
127
- function readQueryRecoveryMeta(query = null) {
128
- const meta = resolveQueryMeta(query);
117
+ function readQueryRecoveryMeta(query) {
118
+ const meta = isRecord(query.meta) ? query.meta : {};
129
119
  const jskitMeta = isRecord(meta.jskit) ? meta.jskit : {};
130
120
  const dedupeWindowMs = jskitMeta.requestRecoveryDedupeWindowMs;
131
121
 
@@ -139,18 +129,8 @@ function readQueryRecoveryMeta(query = null) {
139
129
  });
140
130
  }
141
131
 
142
- function isActiveQuery(query = null) {
143
- if (typeof query?.isActive === "function") {
144
- return Boolean(query.isActive());
145
- }
146
- if (typeof query?.getObserversCount === "function") {
147
- return Number(query.getObserversCount()) > 0;
148
- }
149
- return true;
150
- }
151
-
152
- function recoverableQueryError(query = null) {
153
- const state = isRecord(query?.state) ? query.state : {};
132
+ function recoverableQueryError(query) {
133
+ const { state } = query;
154
134
  if (state.status !== "error" || state.fetchStatus !== "idle") {
155
135
  return null;
156
136
  }
@@ -159,12 +139,8 @@ function recoverableQueryError(query = null) {
159
139
  return isRecoverableRequestError(error) ? error : null;
160
140
  }
161
141
 
162
- function createQueryRetry(queryClient, query = null) {
163
- if (!queryClient || typeof queryClient.refetchQueries !== "function") {
164
- return null;
165
- }
166
-
167
- const queryKey = query?.queryKey;
142
+ function createQueryRetry(queryClient, query) {
143
+ const { queryKey } = query;
168
144
  if (!Array.isArray(queryKey)) {
169
145
  return null;
170
146
  }
@@ -182,16 +158,16 @@ function createQueryRetry(queryClient, query = null) {
182
158
  );
183
159
  }
184
160
 
185
- function resolveQueryHash(query = null) {
186
- const explicitHash = normalizeText(query?.queryHash);
161
+ function resolveQueryHash(query) {
162
+ const explicitHash = normalizeText(query.queryHash);
187
163
  if (explicitHash) {
188
164
  return explicitHash;
189
165
  }
190
166
 
191
167
  try {
192
- return normalizeText(JSON.stringify(query?.queryKey || []));
168
+ return normalizeText(JSON.stringify(query.queryKey || []));
193
169
  } catch {
194
- return normalizeText(String(query?.queryKey || ""));
170
+ return normalizeText(String(query.queryKey || ""));
195
171
  }
196
172
  }
197
173
 
@@ -199,17 +175,8 @@ function installRecoverableQueryObserver({
199
175
  queryClient,
200
176
  runtime,
201
177
  logger
202
- } = {}) {
203
- const queryCache =
204
- queryClient && typeof queryClient.getQueryCache === "function"
205
- ? queryClient.getQueryCache()
206
- : null;
207
- if (!queryCache || typeof queryCache.subscribe !== "function") {
208
- return Object.freeze({
209
- dispose() {}
210
- });
211
- }
212
-
178
+ }) {
179
+ const queryCache = queryClient.getQueryCache();
213
180
  const reportedErrorUpdateByQueryHash = new Map();
214
181
 
215
182
  function dismissReportedQueryRecovery(queryHash = "") {
@@ -219,7 +186,7 @@ function installRecoverableQueryObserver({
219
186
  }
220
187
 
221
188
  reportedErrorUpdateByQueryHash.delete(queryHash);
222
- if (reported.presentationId && typeof runtime.dismiss === "function") {
189
+ if (reported.presentationId) {
223
190
  runtime.dismiss(reported.presentationId, {
224
191
  presenterId: reported.presenterId
225
192
  });
@@ -232,14 +199,13 @@ function installRecoverableQueryObserver({
232
199
  }
233
200
  }
234
201
 
235
- function inspectQuery(query = null) {
202
+ function inspectQuery(query) {
236
203
  const queryHash = resolveQueryHash(query);
237
204
  const recoveryMeta = readQueryRecoveryMeta(query);
238
205
  if (
239
- !query ||
240
206
  recoveryMeta.disabled ||
241
207
  !SAFE_REQUEST_RECOVERY_METHODS.has(recoveryMeta.method) ||
242
- !isActiveQuery(query)
208
+ !query.isActive()
243
209
  ) {
244
210
  if (queryHash) {
245
211
  dismissReportedQueryRecovery(queryHash);
@@ -255,7 +221,7 @@ function installRecoverableQueryObserver({
255
221
  return;
256
222
  }
257
223
 
258
- const errorUpdateCount = Number(query?.state?.errorUpdateCount || 0);
224
+ const errorUpdateCount = Number(query.state.errorUpdateCount || 0);
259
225
  const reportKey = `${errorUpdateCount}:${errorMessage(error)}`;
260
226
  const reported = reportedErrorUpdateByQueryHash.get(queryHash);
261
227
  if (reported?.reportKey === reportKey) {
@@ -267,7 +233,7 @@ function installRecoverableQueryObserver({
267
233
  label: recoveryMeta.label,
268
234
  retry: createQueryRetry(queryClient, query),
269
235
  source: recoveryMeta.source,
270
- stale: query?.state?.data !== undefined,
236
+ stale: query.state.data !== undefined,
271
237
  dedupeKey: recoveryMeta.dedupeKey || `shell-web.request-recovery.query.${queryHash}.${errorUpdateCount}`,
272
238
  ...(dedupeWindowMs !== null ? { dedupeWindowMs } : {})
273
239
  });
@@ -285,10 +251,8 @@ function installRecoverableQueryObserver({
285
251
  }
286
252
 
287
253
  try {
288
- if (typeof queryCache.getAll === "function") {
289
- for (const query of queryCache.getAll()) {
290
- inspectQuery(query);
291
- }
254
+ for (const query of queryCache.getAll()) {
255
+ inspectQuery(query);
292
256
  }
293
257
  } catch (error) {
294
258
  logger.warn(
@@ -299,9 +263,9 @@ function installRecoverableQueryObserver({
299
263
  );
300
264
  }
301
265
 
302
- const unsubscribe = queryCache.subscribe((event = {}) => {
266
+ const unsubscribe = queryCache.subscribe((event) => {
303
267
  try {
304
- inspectQuery(event?.query);
268
+ inspectQuery(event.query);
305
269
  } catch (error) {
306
270
  logger.warn(
307
271
  {
@@ -315,22 +279,20 @@ function installRecoverableQueryObserver({
315
279
  return Object.freeze({
316
280
  dispose() {
317
281
  dismissReportedQueryRecoveries();
318
- if (typeof unsubscribe === "function") {
319
- unsubscribe();
320
- }
282
+ unsubscribe();
321
283
  }
322
284
  });
323
285
  }
324
286
 
325
287
  /**
326
288
  * @param {object} options
327
- * @param {any} [options.queryClient]
328
- * @param {any} [options.errorRuntime]
329
- * @param {import("@jskit-ai/kernel/server/types").RuntimeLogger} options.logger
289
+ * @param {import("@jskit-ai/kernel/client/types").ClientQueryClient} options.queryClient
290
+ * @param {import("../types.js").ShellErrorRuntime} options.errorRuntime
291
+ * @param {import("@jskit-ai/kernel/client/types").ClientLogger} options.logger
330
292
  */
331
293
  function createShellRequestRecoveryRuntime({
332
- queryClient = null,
333
- errorRuntime = null,
294
+ queryClient,
295
+ errorRuntime,
334
296
  logger
335
297
  }) {
336
298
  let installedQueryObserver = null;
@@ -389,9 +351,6 @@ function createShellRequestRecoveryRuntime({
389
351
  }
390
352
 
391
353
  function dismiss(presentationId = "", options = {}) {
392
- if (!errorRuntime || typeof errorRuntime.dismiss !== "function") {
393
- return 0;
394
- }
395
354
  return errorRuntime.dismiss(presentationId, options);
396
355
  }
397
356
 
@@ -401,20 +360,8 @@ function createShellRequestRecoveryRuntime({
401
360
  }
402
361
 
403
362
  const source = normalizeText(options.source, { fallback: "shell-web.request-recovery" });
404
- if (!errorRuntime || typeof errorRuntime.report !== "function") {
405
- logger.warn(
406
- {
407
- source,
408
- error: errorMessage(error) || "unknown error"
409
- },
410
- "Shell request recovery could not report because the shell error runtime is unavailable."
411
- );
412
- return null;
413
- }
414
-
415
- const retry = typeof options.retry === "function" ? options.retry : null;
416
- const action = retry
417
- ? retryAction(options, retry)
363
+ const action = options.retry
364
+ ? retryAction(options, options.retry)
418
365
  : options.reload === true
419
366
  ? reloadAction(options)
420
367
  : null;
@@ -458,8 +405,10 @@ function createShellRequestRecoveryRuntime({
458
405
  }
459
406
 
460
407
  function dispose() {
461
- installedQueryObserver?.dispose?.();
462
- installedQueryObserver = null;
408
+ if (installedQueryObserver) {
409
+ installedQueryObserver.dispose();
410
+ installedQueryObserver = null;
411
+ }
463
412
  }
464
413
 
465
414
  const api = Object.freeze({
@@ -1,12 +1,9 @@
1
+ import { normalizeObject } from "@jskit-ai/kernel/shared/support/normalize";
1
2
  import { BOOTSTRAP_PATH } from "@jskit-ai/kernel/shared/surface/paths";
2
3
  import { useJskitText } from "../i18n.js";
3
4
 
4
5
  const { t } = useJskitText();
5
6
 
6
- function normalizeObject(value) {
7
- return value && typeof value === "object" && !Array.isArray(value) ? value : {};
8
- }
9
-
10
7
  function buildBootstrapUrl({ path = BOOTSTRAP_PATH, query = {} } = {}) {
11
8
  const normalizedPath = String(path || BOOTSTRAP_PATH).trim() || BOOTSTRAP_PATH;
12
9
  const params = new URLSearchParams();
@@ -33,30 +30,23 @@ function normalizeBootstrapResponseError(response, url) {
33
30
 
34
31
  /**
35
32
  * @param {object} options
36
- * @param {any} options.handlers
37
- * @param {any} options.placementRuntime
38
- * @param {any} [options.requestRecoveryRuntime]
39
- * @param {any} [options.router]
40
- * @param {import("@jskit-ai/kernel/server/types").RuntimeLogger} options.logger
33
+ * @param {import("../types.js").BootstrapPayloadHandlerRegistry} options.handlers
34
+ * @param {import("../types.js").WebPlacementRuntime} options.placementRuntime
35
+ * @param {import("../types.js").ShellRequestRecoveryRuntime} options.requestRecoveryRuntime
36
+ * @param {import("@jskit-ai/kernel/client/types").ClientRouter} options.router
37
+ * @param {import("@jskit-ai/kernel/client/types").ClientLogger} options.logger
41
38
  * @param {typeof fetch} [options.fetchImplementation]
42
39
  * @param {string} [options.bootstrapPath]
43
40
  */
44
41
  function createShellBootstrapRuntime({
45
42
  handlers,
46
43
  placementRuntime,
47
- requestRecoveryRuntime = null,
48
- router = null,
44
+ requestRecoveryRuntime,
45
+ router,
49
46
  logger,
50
47
  fetchImplementation = globalThis.fetch,
51
48
  bootstrapPath = BOOTSTRAP_PATH
52
- } = {}) {
53
- if (!handlers || typeof handlers.list !== "function") {
54
- throw new Error("createShellBootstrapRuntime requires a bootstrap handler registry.");
55
- }
56
- if (!placementRuntime || typeof placementRuntime.setContext !== "function") {
57
- throw new Error("createShellBootstrapRuntime requires a placement runtime.");
58
- }
59
-
49
+ }) {
60
50
  let initialized = false;
61
51
  let refreshQueue = Promise.resolve();
62
52
 
@@ -69,10 +59,6 @@ function createShellBootstrapRuntime({
69
59
  };
70
60
 
71
61
  for (const handler of payloadHandlers) {
72
- if (typeof handler.resolveBootstrapRequest !== "function") {
73
- continue;
74
- }
75
-
76
62
  const contribution = normalizeObject(
77
63
  await handler.resolveBootstrapRequest({
78
64
  router,
@@ -129,10 +115,6 @@ function createShellBootstrapRuntime({
129
115
  const source = `shell-web.bootstrap.${String(reason || "manual").trim() || "manual"}`;
130
116
 
131
117
  for (const handler of payloadHandlers) {
132
- if (typeof handler.handleBootstrapError !== "function") {
133
- continue;
134
- }
135
-
136
118
  await handler.handleBootstrapError({
137
119
  router,
138
120
  placementRuntime,
@@ -145,10 +127,6 @@ function createShellBootstrapRuntime({
145
127
  }
146
128
 
147
129
  async function performRefresh(reason = "manual") {
148
- if (typeof fetchImplementation !== "function") {
149
- throw new Error("Bootstrap payload fetch requires a fetch implementation.");
150
- }
151
-
152
130
  let request = Object.freeze({ path: bootstrapPath, query: Object.freeze({}), meta: Object.freeze({}) });
153
131
 
154
132
  try {
@@ -170,7 +148,7 @@ function createShellBootstrapRuntime({
170
148
  return await applyBootstrapPayload(payload, reason, request);
171
149
  } catch (error) {
172
150
  await applyBootstrapError(error, reason, request);
173
- requestRecoveryRuntime?.report?.(error, {
151
+ requestRecoveryRuntime.report(error, {
174
152
  label: t("jskit.shell.recovery.appDataLabel"),
175
153
  retry: () => refresh(reason),
176
154
  source: "shell-web.bootstrap",
@@ -5,8 +5,22 @@ const { t } = useJskitText();
5
5
 
6
6
  const SHELL_WEB_REFRESH_RUNTIME_KEY = "jskit.shell-web.runtime.web-refresh.client";
7
7
 
8
- function isPullRefreshQuery(query = null) {
9
- const meta = isRecord(query?.meta) ? query.meta : {};
8
+ /**
9
+ * The refresh of an application without shell-web's provider: nothing refreshes, so pull-to-refresh never starts.
10
+ * @type {any}
11
+ */
12
+ const NO_SHELL_WEB_REFRESH_RUNTIME = Object.freeze({
13
+ async refresh(reason = "manual") {
14
+ return Object.freeze({
15
+ reason,
16
+ bootstrapRefreshed: false,
17
+ queriesRefetched: false
18
+ });
19
+ }
20
+ });
21
+
22
+ function isPullRefreshQuery(query) {
23
+ const meta = isRecord(query.meta) ? query.meta : {};
10
24
  if (meta.jskitRefresh === "pull") {
11
25
  return true;
12
26
  }
@@ -20,33 +34,25 @@ function isPullRefreshQuery(query = null) {
20
34
 
21
35
  /**
22
36
  * @param {object} options
23
- * @param {any} [options.bootstrapRuntime]
24
- * @param {any} [options.queryClient]
25
- * @param {any} [options.errorRuntime]
26
- * @param {import("@jskit-ai/kernel/server/types").RuntimeLogger} options.logger
37
+ * @param {import("../types.js").ShellBootstrapRuntime} options.bootstrapRuntime
38
+ * @param {import("@jskit-ai/kernel/client/types").ClientQueryClient} options.queryClient
39
+ * @param {import("../types.js").ShellErrorRuntime} options.errorRuntime
40
+ * @param {import("@jskit-ai/kernel/client/types").ClientLogger} options.logger
27
41
  */
28
42
  function createShellRefreshRuntime({
29
- bootstrapRuntime = null,
30
- queryClient = null,
31
- errorRuntime = null,
43
+ bootstrapRuntime,
44
+ queryClient,
45
+ errorRuntime,
32
46
  logger
33
47
  }) {
34
48
  let refreshQueue = Promise.resolve(null);
35
49
 
36
50
  async function refreshBootstrap(reason) {
37
- if (!bootstrapRuntime || typeof bootstrapRuntime.refresh !== "function") {
38
- return false;
39
- }
40
-
41
51
  await bootstrapRuntime.refresh(reason);
42
52
  return true;
43
53
  }
44
54
 
45
55
  async function refetchPullQueries() {
46
- if (!queryClient || typeof queryClient.refetchQueries !== "function") {
47
- return false;
48
- }
49
-
50
56
  await queryClient.refetchQueries(
51
57
  {
52
58
  type: "active",
@@ -67,10 +73,6 @@ function createShellRefreshRuntime({
67
73
  "Shell refresh failed."
68
74
  );
69
75
 
70
- if (!errorRuntime || typeof errorRuntime.report !== "function") {
71
- return;
72
- }
73
-
74
76
  errorRuntime.report({
75
77
  source: "shell-web.refresh",
76
78
  message: t("jskit.shell.recovery.refreshFailed"),
@@ -125,6 +127,7 @@ function createShellRefreshRuntime({
125
127
  }
126
128
 
127
129
  export {
130
+ NO_SHELL_WEB_REFRESH_RUNTIME,
128
131
  SHELL_WEB_REFRESH_RUNTIME_KEY,
129
132
  createShellRefreshRuntime
130
133
  };
@@ -1,6 +1,6 @@
1
1
  import { computed, markRaw, shallowRef } from "vue";
2
2
  import { defineStore } from "pinia";
3
- import { EMPTY_PRESENTATION_STATE, EMPTY_PRESENTATION_STORE } from "../error/presentationDefaults.js";
3
+ import { EMPTY_PRESENTATION_STATE, NO_PRESENTATION_STORE } from "../error/presentationDefaults.js";
4
4
 
5
5
  function normalizePresentationState(nextState) {
6
6
  if (!nextState || typeof nextState !== "object") {
@@ -10,19 +10,8 @@ function normalizePresentationState(nextState) {
10
10
  return nextState;
11
11
  }
12
12
 
13
- function isPresentationRuntimeStore(value) {
14
- return Boolean(
15
- value &&
16
- typeof value.getState === "function" &&
17
- typeof value.subscribe === "function" &&
18
- typeof value.present === "function" &&
19
- typeof value.dismiss === "function" &&
20
- typeof value.clear === "function"
21
- );
22
- }
23
-
24
13
  export const useShellErrorPresentationStore = defineStore("jskit.shell-web.error-presentation", () => {
25
- const runtimeStore = shallowRef(markRaw(EMPTY_PRESENTATION_STORE));
14
+ const runtimeStore = shallowRef(markRaw(NO_PRESENTATION_STORE));
26
15
  const presentationState = shallowRef(EMPTY_PRESENTATION_STATE);
27
16
  let unsubscribe = null;
28
17
 
@@ -32,17 +21,14 @@ export const useShellErrorPresentationStore = defineStore("jskit.shell-web.error
32
21
  }
33
22
 
34
23
  function detachRuntimeStore() {
35
- if (typeof unsubscribe === "function") {
24
+ if (unsubscribe) {
36
25
  unsubscribe();
37
26
  unsubscribe = null;
38
27
  }
39
28
  }
40
29
 
41
- function attachRuntimeStore(nextRuntimeStore = EMPTY_PRESENTATION_STORE) {
42
- if (!isPresentationRuntimeStore(nextRuntimeStore)) {
43
- throw new TypeError("useShellErrorPresentationStore.attachRuntimeStore requires an error presentation store.");
44
- }
45
-
30
+ /** @param {import("../types.js").ShellErrorPresentationStore} nextRuntimeStore */
31
+ function attachRuntimeStore(nextRuntimeStore) {
46
32
  if (runtimeStore.value === nextRuntimeStore) {
47
33
  setPresentationState(nextRuntimeStore.getState());
48
34
  return runtimeStore.value;
@@ -78,12 +78,51 @@ function resolveContentAwareDrawerWidth(
78
78
  return clampNumber(Math.ceil(requiredWidth * 4) / 4, minimum, maximum);
79
79
  }
80
80
 
81
+ function measureRenderedText(element) {
82
+ const range = document.createRange();
83
+ range.selectNodeContents(element);
84
+ return range.getBoundingClientRect();
85
+ }
86
+
87
+ // The width the drawer's rendered labels need, from where each one starts on the drawer's inline axis.
88
+ function measureDrawerContentWidth(drawerElement, navigationItemSpacing) {
89
+ const drawerRect = drawerElement.getBoundingClientRect();
90
+ const drawerStyle = window.getComputedStyle(drawerElement);
91
+ const rightToLeft = drawerStyle.direction === "rtl";
92
+ const endBorderWidth = Number.parseFloat(
93
+ rightToLeft ? drawerStyle.borderLeftWidth : drawerStyle.borderRightWidth
94
+ ) || 0;
95
+ const measurements = [];
96
+
97
+ for (const label of drawerElement.querySelectorAll(".v-list-item-title")) {
98
+ const labelStyle = window.getComputedStyle(label);
99
+ if (labelStyle.display === "none" || labelStyle.visibility === "hidden") {
100
+ continue;
101
+ }
102
+ const textRect = measureRenderedText(label);
103
+ if (!textRect || textRect.width <= 0) {
104
+ continue;
105
+ }
106
+ measurements.push({
107
+ logicalStart: rightToLeft
108
+ ? drawerRect.right - textRect.right
109
+ : textRect.left - drawerRect.left,
110
+ textWidth: textRect.width
111
+ });
112
+ }
113
+
114
+ return resolveContentAwareDrawerWidth(measurements, {
115
+ endGap: navigationItemSpacing + endBorderWidth
116
+ });
117
+ }
118
+
81
119
  export {
82
120
  DEFAULT_SHELL_DRAWER_WIDTH,
83
121
  DEFAULT_SHELL_NAVIGATION_ITEM_SPACING,
84
122
  DEFAULT_SHELL_RAIL_WIDTH,
85
123
  MAXIMUM_SHELL_DRAWER_WIDTH,
86
124
  MINIMUM_SHELL_DRAWER_WIDTH,
125
+ measureDrawerContentWidth,
87
126
  normalizeShellDrawerWidth,
88
127
  normalizeShellNavigationItemSpacing,
89
128
  normalizeShellRailWidth,
@@ -1,3 +1,5 @@
1
+ import { closestElement } from "../browser.js";
2
+
1
3
  const SHELL_GESTURE_IGNORED_SELECTORS = Object.freeze([
2
4
  "a",
3
5
  "button",
@@ -14,13 +16,13 @@ const SHELL_GESTURE_IGNORED_SELECTORS = Object.freeze([
14
16
 
15
17
  // Shell gestures follow touch and pen contact, never a mouse drag.
16
18
  function isPrimaryTouchPointer(event) {
17
- return event?.isPrimary !== false && event?.button === 0 && event?.pointerType !== "mouse";
19
+ return event.isPrimary !== false && event.button === 0 && event.pointerType !== "mouse";
18
20
  }
19
21
 
20
22
  // Interactive controls keep their own gestures; the shell does not start one on them.
21
23
  function isShellGestureIgnoredTarget(target, { extraSelectors = [] } = {}) {
22
24
  const selectors = [...SHELL_GESTURE_IGNORED_SELECTORS, ...extraSelectors].join(",");
23
- return Boolean(target?.closest?.(selectors));
25
+ return Boolean(closestElement(target, selectors));
24
26
  }
25
27
 
26
28
  export { isPrimaryTouchPointer, isShellGestureIgnoredTarget };
@@ -44,7 +44,7 @@ function interpolateBracketParams(pathTemplate = "", params = {}) {
44
44
  return "";
45
45
  }
46
46
 
47
- const value = params?.[key];
47
+ const value = params[key];
48
48
  return value == null ? `[${key}]` : encodeURIComponent(String(value));
49
49
  });
50
50
  }
@@ -1,5 +1,5 @@
1
1
  function activateShellNavigationLinkOnSpace(event) {
2
- if (event?.key !== " " || typeof event.currentTarget?.click !== "function") {
2
+ if (event.key !== " ") {
3
3
  return;
4
4
  }
5
5
  event.preventDefault();
@@ -0,0 +1,93 @@
1
+ import { normalizePathname } from "@jskit-ai/kernel/shared";
2
+ import { resolveSurfaceNavigationTargetFromPlacementContext } from "../placement/surfaceContext.js";
3
+ import {
4
+ normalizeMenuLinkPathname,
5
+ resolveMenuLinkTarget
6
+ } from "./menuLinkTarget.js";
7
+
8
+ function normalizeComparablePathname(value = "") {
9
+ const raw = String(value || "").trim();
10
+ if (!raw) {
11
+ return "";
12
+ }
13
+
14
+ try {
15
+ const parsed = new URL(raw, window.location.href);
16
+ if (parsed.origin !== window.location.origin) {
17
+ return "";
18
+ }
19
+ return normalizePathname(parsed.pathname);
20
+ } catch {
21
+ return normalizePathname(normalizeMenuLinkPathname(raw));
22
+ }
23
+ }
24
+
25
+ function pathMatchesNavigationEntry(pathname = "", entry = {}) {
26
+ const target = String(entry.pathname || "").trim();
27
+ if (!target) {
28
+ return false;
29
+ }
30
+ if (entry.exact || target === "/") {
31
+ return pathname === target;
32
+ }
33
+ return pathname === target || pathname.startsWith(`${target}/`);
34
+ }
35
+
36
+ // The primary navigation destinations a swipe can reach: same-origin links, in placement order.
37
+ function resolvePrimaryNavigationEntries(placements, {
38
+ semanticTarget,
39
+ currentSurfaceId,
40
+ placementContext,
41
+ routeParams
42
+ }) {
43
+ return placements
44
+ .filter((entry) => String(entry.semanticTarget || entry.target || "").trim() === semanticTarget)
45
+ .map((entry, index) => {
46
+ const entryProps = entry.props;
47
+ const target = resolveMenuLinkTarget({
48
+ to: entryProps.to,
49
+ surface: entryProps.surface,
50
+ currentSurfaceId,
51
+ placementContext,
52
+ scopedSuffix: entryProps.scopedSuffix,
53
+ unscopedSuffix: entryProps.unscopedSuffix,
54
+ routeParams
55
+ });
56
+ const navigationTarget = resolveSurfaceNavigationTargetFromPlacementContext(placementContext, {
57
+ path: target,
58
+ surfaceId: entryProps.surface || currentSurfaceId
59
+ });
60
+
61
+ return Object.freeze({
62
+ id: entry.id,
63
+ index,
64
+ exact: entryProps.exact === true,
65
+ href: navigationTarget.href,
66
+ pathname: normalizeComparablePathname(navigationTarget.href),
67
+ sameOrigin: navigationTarget.sameOrigin
68
+ });
69
+ })
70
+ .filter((entry) => entry.pathname && entry.sameOrigin);
71
+ }
72
+
73
+ // The destination whose path matches most closely, or -1 away from all of them.
74
+ function resolveActivePrimaryNavigationIndex(pathname, entries) {
75
+ let bestMatch = null;
76
+
77
+ for (const entry of entries) {
78
+ if (!pathMatchesNavigationEntry(pathname, entry)) {
79
+ continue;
80
+ }
81
+ if (!bestMatch || entry.pathname.length > bestMatch.pathname.length) {
82
+ bestMatch = entry;
83
+ }
84
+ }
85
+
86
+ return bestMatch ? bestMatch.index : -1;
87
+ }
88
+
89
+ export {
90
+ normalizeComparablePathname,
91
+ resolveActivePrimaryNavigationIndex,
92
+ resolvePrimaryNavigationEntries
93
+ };
@@ -15,8 +15,12 @@ function isVerticalDrift(absX, absY) {
15
15
  return absY > SWIPE_MAX_VERTICAL_DRIFT || (absY > 28 && absY > absX * 1.3);
16
16
  }
17
17
 
18
- // Tracks one horizontal swipe between primary navigation destinations. A swipe
19
- // that drifts vertically is dropped for good: the gesture became a scroll.
18
+ /**
19
+ * Tracks one horizontal swipe between primary navigation destinations. A swipe
20
+ * that drifts vertically is dropped for good: the gesture became a scroll.
21
+ * @param {object} [options]
22
+ * @param {() => number} [options.now]
23
+ */
20
24
  function createRouteSwipeGesture({ now = () => performance.now() } = {}) {
21
25
  let active = null;
22
26
 
@@ -82,7 +86,13 @@ function createRouteSwipeGesture({ now = () => performance.now() } = {}) {
82
86
  }
83
87
  }
84
88
 
85
- return Object.freeze({ start, reset, move, end, cancel });
89
+ return Object.freeze({
90
+ start,
91
+ reset,
92
+ move,
93
+ end,
94
+ cancel
95
+ });
86
96
  }
87
97
 
88
98
  export { createRouteSwipeGesture };