@jskit-ai/shell-web 0.2.3 → 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.
Files changed (74) hide show
  1. package/fixtures/adaptive-shell/src/main.js +4 -2
  2. package/package.json +10 -4
  3. package/patterns/page-and-placement/example/src/placementTopology.js +1 -0
  4. package/src/client/asyncModuleRecovery/index.js +1 -0
  5. package/src/client/asyncModuleRecovery/inject.js +30 -18
  6. package/src/client/asyncModuleRecovery/runtime.js +20 -24
  7. package/src/client/bootstrap/bootstrapPayloadHandlerRegistry.js +13 -6
  8. package/src/client/browser.js +56 -0
  9. package/src/client/clientUpdate/runtime.js +28 -18
  10. package/src/client/components/ShellErrorHost.vue +19 -219
  11. package/src/client/components/ShellLayout.vue +19 -227
  12. package/src/client/components/ShellOutlet.vue +16 -53
  13. package/src/client/components/ShellRouteTransition.vue +2 -291
  14. package/src/client/composables/shellLayoutDrawerPreference.js +15 -8
  15. package/src/client/composables/useShellDrawer.js +194 -0
  16. package/src/client/composables/useShellErrorHost.js +171 -0
  17. package/src/client/composables/useShellLayoutState.js +10 -20
  18. package/src/client/composables/useShellNavigationLink.js +6 -6
  19. package/src/client/composables/useShellPullToRefresh.js +15 -19
  20. package/src/client/composables/useShellRouteTransition.js +218 -0
  21. package/src/client/error/index.js +1 -1
  22. package/src/client/error/inject.js +36 -48
  23. package/src/client/error/normalize.js +2 -3
  24. package/src/client/error/policy.js +9 -0
  25. package/src/client/error/presentation.js +67 -0
  26. package/src/client/error/presentationDefaults.js +2 -2
  27. package/src/client/error/presenters.js +44 -19
  28. package/src/client/error/runtime.js +30 -28
  29. package/src/client/error/store.js +4 -0
  30. package/src/client/navigation/linkResolver.js +6 -2
  31. package/src/client/navigation/usePaths.js +11 -8
  32. package/src/client/navigation/useSurfaceRouteContext.js +3 -3
  33. package/src/client/placement/debug.js +2 -2
  34. package/src/client/placement/index.js +1 -0
  35. package/src/client/placement/inject.js +49 -46
  36. package/src/client/placement/pathname.js +3 -9
  37. package/src/client/placement/runtime.js +13 -39
  38. package/src/client/placement/surfaceContext.js +14 -33
  39. package/src/client/placement/validators.js +6 -1
  40. package/src/client/providers/ShellWebClientProvider.js +17 -38
  41. package/src/client/providers/appModuleLoadFailure.js +1 -1
  42. package/src/client/requestRecovery/index.js +1 -0
  43. package/src/client/requestRecovery/inject.js +29 -17
  44. package/src/client/requestRecovery/runtime.js +40 -87
  45. package/src/client/runtime/bootstrapRuntime.js +20 -35
  46. package/src/client/runtime/refreshRuntime.js +30 -22
  47. package/src/client/stores/useShellErrorPresentationStore.js +5 -19
  48. package/src/client/support/drawerWidth.js +39 -0
  49. package/src/client/support/gestureTargets.js +4 -2
  50. package/src/client/support/menuLinkTarget.js +1 -1
  51. package/src/client/support/navigationLinkKeyboard.js +1 -1
  52. package/src/client/support/primaryNavigation.js +93 -0
  53. package/src/client/support/routeSwipeGesture.js +13 -3
  54. package/src/client/support/shellLayoutClass.js +4 -6
  55. package/src/client/types.js +38 -0
  56. package/test/asyncModuleRecoveryInject.test.js +13 -18
  57. package/test/bootstrapRuntime.test.js +3 -1
  58. package/test/browser.test.js +51 -0
  59. package/test/clientUpdate.test.js +12 -1
  60. package/test/drawerWidth.test.js +64 -0
  61. package/test/errorActions.test.js +10 -3
  62. package/test/errorPresentation.test.js +51 -0
  63. package/test/errorRuntime.test.js +21 -10
  64. package/test/placementInject.test.js +60 -0
  65. package/test/placementRuntime.test.js +12 -9
  66. package/test/primaryNavigation.test.js +75 -0
  67. package/test/provider.test.js +18 -4
  68. package/test/requestRecovery.test.js +13 -18
  69. package/test/settingsPlacementContract.test.js +15 -11
  70. package/test/support/mountComposable.js +90 -0
  71. package/test/translation.test.js +4 -2
  72. package/test/useShellDrawer.test.js +213 -0
  73. package/test/useShellErrorHost.test.js +149 -0
  74. package/test/useShellRouteTransition.test.js +129 -0
@@ -2,6 +2,7 @@ import assert from "node:assert/strict";
2
2
  import test from "node:test";
3
3
  import { definePlacement } from "../src/client/placement/validators.js";
4
4
  import { createWebPlacementRuntime } from "../src/client/placement/runtime.js";
5
+ import { silentLogger } from "@jskit-ai/kernel/shared/support/silentLogger";
5
6
 
6
7
  function createComponentsStub({ tokens = {} } = {}) {
7
8
  return {
@@ -61,7 +62,7 @@ test("web placement runtime resolves semantic targets through topology variants"
61
62
  }
62
63
  });
63
64
 
64
- const runtime = createWebPlacementRuntime({ components });
65
+ const runtime = createWebPlacementRuntime({ components, logger: silentLogger });
65
66
  runtime.replacePlacementTopology([
66
67
  semanticTopologyEntry({
67
68
  id: "shell.primary-nav",
@@ -109,7 +110,7 @@ test("web placement runtime accepts append-only topology objects", () => {
109
110
  }
110
111
  });
111
112
 
112
- const runtime = createWebPlacementRuntime({ components });
113
+ const runtime = createWebPlacementRuntime({ components, logger: silentLogger });
113
114
  runtime.replacePlacementTopology({
114
115
  placements: [
115
116
  semanticTopologyEntry({
@@ -148,7 +149,7 @@ test("web placement runtime filters by surface/host/position, resolves component
148
149
  }
149
150
  });
150
151
 
151
- const runtime = createWebPlacementRuntime({ components });
152
+ const runtime = createWebPlacementRuntime({ components, logger: silentLogger });
152
153
  runtime.replacePlacements([
153
154
  definePlacement({
154
155
  id: "test.menu",
@@ -196,7 +197,7 @@ test("web placement runtime preserves source order when placements share the sam
196
197
  }
197
198
  });
198
199
 
199
- const runtime = createWebPlacementRuntime({ components });
200
+ const runtime = createWebPlacementRuntime({ components, logger: silentLogger });
200
201
  runtime.replacePlacements([
201
202
  definePlacement({
202
203
  id: "test.beta",
@@ -233,7 +234,8 @@ test("web placement runtime applies context contributors and placement when() pr
233
234
  components,
234
235
  contextContributors: [
235
236
  () => ({ auth: { authenticated: true } })
236
- ]
237
+ ],
238
+ logger: silentLogger
237
239
  });
238
240
  runtime.replacePlacements([
239
241
  definePlacement({
@@ -269,7 +271,8 @@ test("web placement runtime uses runtime context and local context overrides con
269
271
  components,
270
272
  contextContributors: [
271
273
  () => ({ auth: { authenticated: false } })
272
- ]
274
+ ],
275
+ logger: silentLogger
273
276
  });
274
277
  runtime.replacePlacements([
275
278
  definePlacement({
@@ -304,7 +307,7 @@ test("web placement runtime uses runtime context and local context overrides con
304
307
 
305
308
  test("web placement runtime notifies subscribers on placement and context updates", () => {
306
309
  const components = createComponentsStub();
307
- const runtime = createWebPlacementRuntime({ components });
310
+ const runtime = createWebPlacementRuntime({ components, logger: silentLogger });
308
311
  const events = [];
309
312
  const unsubscribe = runtime.subscribe((event) => {
310
313
  events.push(event.type);
@@ -329,7 +332,7 @@ test("web placement runtime notifies subscribers on placement and context update
329
332
 
330
333
  test("web placement runtime rejects duplicate placement ids", () => {
331
334
  const components = createComponentsStub();
332
- const runtime = createWebPlacementRuntime({ components });
335
+ const runtime = createWebPlacementRuntime({ components, logger: silentLogger });
333
336
 
334
337
  assert.throws(() => {
335
338
  runtime.replacePlacements([
@@ -468,7 +471,7 @@ test("web placement runtime follows explicit surface targeting without role indi
468
471
  "component.admin": () => null
469
472
  }
470
473
  });
471
- const runtime = createWebPlacementRuntime({ components });
474
+ const runtime = createWebPlacementRuntime({ components, logger: silentLogger });
472
475
  runtime.replacePlacements([
473
476
  definePlacement({
474
477
  id: "global.banner",
@@ -0,0 +1,75 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import {
4
+ normalizeComparablePathname,
5
+ resolveActivePrimaryNavigationIndex,
6
+ resolvePrimaryNavigationEntries
7
+ } from "../src/client/support/primaryNavigation.js";
8
+
9
+ const PLACEMENT_CONTEXT = Object.freeze({
10
+ surfaceConfig: {
11
+ defaultSurfaceId: "home",
12
+ enabledSurfaceIds: ["home"],
13
+ surfacesById: {
14
+ home: { id: "home", pagesRoot: "home", routeBase: "/home", enabled: true }
15
+ }
16
+ }
17
+ });
18
+
19
+ function placement(id, props, semanticTarget = "shell.primary-nav") {
20
+ return { id, semanticTarget, props };
21
+ }
22
+
23
+ function resolveEntries(placements) {
24
+ return resolvePrimaryNavigationEntries(placements, {
25
+ semanticTarget: "shell.primary-nav",
26
+ currentSurfaceId: "home",
27
+ placementContext: PLACEMENT_CONTEXT,
28
+ routeParams: {}
29
+ });
30
+ }
31
+
32
+ test("comparable pathnames drop the query and hash outside a browser", () => {
33
+ assert.equal(normalizeComparablePathname(""), "");
34
+ assert.equal(normalizeComparablePathname("/home/settings/?tab=1#top"), "/home/settings");
35
+ });
36
+
37
+ test("comparable pathnames in a browser resolve against the page and refuse other origins", (t) => {
38
+ globalThis.window = { location: { href: "https://app.test/home/", origin: "https://app.test" } };
39
+ t.after(() => {
40
+ delete globalThis.window;
41
+ });
42
+
43
+ assert.equal(normalizeComparablePathname("contacts/"), "/home/contacts");
44
+ assert.equal(normalizeComparablePathname("https://app.test/home/?x=1"), "/home");
45
+ assert.equal(normalizeComparablePathname("https://other.test/home"), "");
46
+ });
47
+
48
+ test("primary navigation keeps the target's same-origin destinations in placement order", () => {
49
+ const entries = resolveEntries([
50
+ placement("home", { to: "/home", exact: true }),
51
+ placement("elsewhere", { to: "/home/other" }, "shell.secondary-nav"),
52
+ placement("external", { to: "https://other.test/home" }),
53
+ placement("contacts", { surface: "home", unscopedSuffix: "/contacts", scopedSuffix: "/contacts" })
54
+ ]);
55
+
56
+ assert.deepEqual(entries.map((entry) => [entry.id, entry.index, entry.exact, entry.href, entry.pathname]), [
57
+ ["home", 0, true, "/home", "/home"],
58
+ ["contacts", 2, false, "/home/contacts", "/home/contacts"]
59
+ ]);
60
+ });
61
+
62
+ test("the active destination is the closest path match", () => {
63
+ const entries = [
64
+ { index: 0, pathname: "/home", exact: false },
65
+ { index: 1, pathname: "/home/settings", exact: false },
66
+ { index: 2, pathname: "/home/exact", exact: true },
67
+ { index: 3, pathname: "/", exact: false }
68
+ ];
69
+
70
+ assert.equal(resolveActivePrimaryNavigationIndex("/home/settings/general", entries), 1);
71
+ assert.equal(resolveActivePrimaryNavigationIndex("/home/other", entries), 0);
72
+ assert.equal(resolveActivePrimaryNavigationIndex("/home/exact/child", entries), 0);
73
+ assert.equal(resolveActivePrimaryNavigationIndex("/", entries), 3);
74
+ assert.equal(resolveActivePrimaryNavigationIndex("/away", entries), -1);
75
+ });
@@ -61,6 +61,22 @@ function createRouter() {
61
61
  };
62
62
  }
63
63
 
64
+ function createQueryClient() {
65
+ return {
66
+ getQueryCache() {
67
+ return {
68
+ getAll() {
69
+ return [];
70
+ },
71
+ subscribe() {
72
+ return () => {};
73
+ }
74
+ };
75
+ },
76
+ async refetchQueries() {}
77
+ };
78
+ }
79
+
64
80
  function createSurfaceRuntimeFixture() {
65
81
  return createSurfaceRuntime({
66
82
  allMode: "all",
@@ -74,7 +90,7 @@ function createSurfaceRuntimeFixture() {
74
90
  async function startShell({
75
91
  bootstrapPayload = {},
76
92
  bootstrapResponse = null,
77
- queryClient = null
93
+ queryClient = createQueryClient()
78
94
  } = {}) {
79
95
  let shell = null;
80
96
  const Probe = defineProvider({
@@ -154,9 +170,7 @@ test("shell refresh updates bootstrap state and active pull queries", async () =
154
170
  let refetchCount = 0;
155
171
  const fixture = await startShell({
156
172
  queryClient: {
157
- getQueryCache() {
158
- return null;
159
- },
173
+ ...createQueryClient(),
160
174
  async refetchQueries() {
161
175
  refetchCount += 1;
162
176
  }
@@ -2,6 +2,7 @@ import assert from "node:assert/strict";
2
2
  import test from "node:test";
3
3
  import { createApp } from "vue";
4
4
  import {
5
+ NO_SHELL_REQUEST_RECOVERY_RUNTIME,
5
6
  SHELL_REQUEST_RECOVERY_RUNTIME_KEY,
6
7
  isRecoverableRequestError,
7
8
  requestRecoveryMessage,
@@ -29,8 +30,18 @@ test("shell request recovery message uses app-facing labels", () => {
29
30
  );
30
31
  });
31
32
 
32
- test("shell request recovery runtime composable returns null outside Vue injection context", () => {
33
- assert.equal(useShellRequestRecoveryRuntime(), null);
33
+ test("shell request recovery runtime composable resolves NO_SHELL_REQUEST_RECOVERY_RUNTIME without the provider", async () => {
34
+ const app = createApp({
35
+ render() {
36
+ return null;
37
+ }
38
+ });
39
+
40
+ const runtime = app.runWithContext(() => useShellRequestRecoveryRuntime());
41
+
42
+ assert.equal(runtime, NO_SHELL_REQUEST_RECOVERY_RUNTIME);
43
+ assert.equal(runtime.report(new TypeError("Failed to fetch")), null);
44
+ assert.equal(await runtime.reload(), false);
34
45
  });
35
46
 
36
47
  test("shell request recovery runtime composable resolves the provided public runtime", () => {
@@ -54,19 +65,3 @@ test("shell request recovery runtime composable resolves the provided public run
54
65
  runtime
55
66
  );
56
67
  });
57
-
58
- test("shell request recovery runtime composable rejects incomplete runtimes", () => {
59
- const app = createApp({
60
- render() {
61
- return null;
62
- }
63
- });
64
- app.provide(SHELL_REQUEST_RECOVERY_RUNTIME_KEY, {
65
- report() {}
66
- });
67
-
68
- assert.equal(
69
- app.runWithContext(() => useShellRequestRecoveryRuntime()),
70
- null
71
- );
72
- });
@@ -13,6 +13,13 @@ import { resolveShellRouteTransitionKey } from "../src/client/support/routeTrans
13
13
  const TEST_DIRECTORY = path.dirname(fileURLToPath(import.meta.url));
14
14
  const PACKAGE_DIR = path.resolve(TEST_DIRECTORY, "..");
15
15
 
16
+ async function readClientSources(...relativePaths) {
17
+ const sources = await Promise.all(
18
+ relativePaths.map((relativePath) => readFile(path.join(PACKAGE_DIR, "src", "client", relativePath), "utf8"))
19
+ );
20
+ return sources.join("\n");
21
+ }
22
+
16
23
  function readOutlets(target = "") {
17
24
  const outlets = packageMetadata?.metadata?.ui?.placements?.outlets;
18
25
  const normalizedTarget = String(target || "").trim();
@@ -63,7 +70,7 @@ test("shell-web application pattern exposes surface-derived settings outlets", a
63
70
  });
64
71
 
65
72
  test("shell-web shell layout registers navigation at the app layout level", async () => {
66
- const source = await readFile(path.join(PACKAGE_DIR, "src", "client", "components", "ShellLayout.vue"), "utf8");
73
+ const source = await readClientSources("composables/useShellDrawer.js", "components/ShellLayout.vue");
67
74
 
68
75
  assert.doesNotMatch(source, /<v-layout\b/);
69
76
  assert.doesNotMatch(source, /overflow-hidden/);
@@ -83,7 +90,7 @@ test("shell-web shell layout registers navigation at the app layout level", asyn
83
90
  assert.match(source, /target="shell-layout:supporting-side-panel"/);
84
91
  assert.match(source, /data-testid="jskit-shell-supporting-bottom-sheet"/);
85
92
  assert.match(source, /data-testid="jskit-shell-supporting-side-panel"/);
86
- assert.match(source, /inject\(SHELL_WEB_REFRESH_RUNTIME_KEY, null\)/);
93
+ assert.match(source, /inject\(SHELL_WEB_REFRESH_RUNTIME_KEY, NO_SHELL_WEB_REFRESH_RUNTIME\)/);
87
94
  const refreshRuntimeSource = await readFile(path.join(PACKAGE_DIR, "src", "client", "runtime", "refreshRuntime.js"), "utf8");
88
95
  assert.match(refreshRuntimeSource, /SHELL_WEB_REFRESH_RUNTIME_KEY = "jskit\.shell-web\.runtime\.web-refresh\.client"/);
89
96
  assert.match(source, /useShellPullToRefresh\(\{ enabled: isCompactLayout, refreshRuntime \}\)/);
@@ -146,7 +153,7 @@ test("shell navigation tooltips ignore incidental pointer traversal", async () =
146
153
  });
147
154
 
148
155
  test("shell-web error host uses one explicit close affordance for banner errors", async () => {
149
- const source = await readFile(path.join(PACKAGE_DIR, "src", "client", "components", "ShellErrorHost.vue"), "utf8");
156
+ const source = await readClientSources("components/ShellErrorHost.vue", "error/presentation.js");
150
157
 
151
158
  assert.match(source, /function resolveSeverityIcon/);
152
159
  assert.match(source, /mdiAlertOutline/);
@@ -250,10 +257,7 @@ test("shell-web exports request recovery runtime access as a public client API",
250
257
  });
251
258
 
252
259
  test("shell-web route transition keeps mobile route motion placement-driven", async () => {
253
- const source = await readFile(
254
- path.join(PACKAGE_DIR, "src", "client", "components", "ShellRouteTransition.vue"),
255
- "utf8"
256
- );
260
+ const source = await readClientSources("components/ShellRouteTransition.vue", "composables/useShellRouteTransition.js");
257
261
 
258
262
  assert.match(source, /target:\s*\{[\s\S]*default:\s*"shell-layout:primary-bottom-nav"/);
259
263
  assert.match(source, /semanticTarget:\s*\{[\s\S]*default:\s*"shell\.primary-nav"/);
@@ -273,18 +277,18 @@ test("shell-web route transition keeps mobile route motion placement-driven", as
273
277
  assert.match(source, /\.shell-route-transition__pane\s*\{[\s\S]*min-height:\s*0/);
274
278
  assert.match(source, /transitionDirection\.value = nextIndex > previousIndex \? "forward" : "reverse"/);
275
279
  assert.match(source, /const routeTransitionKey = ref\(""\)/);
276
- assert.match(source, /\[\(\) => normalizeComparablePathname\(route\?\.path \|\| route\?\.fullPath \|\| "\/"\), currentSurfaceId\]/);
280
+ assert.match(source, /\[\(\) => normalizeComparablePathname\(route\.path\), currentSurfaceId\]/);
277
281
  assert.match(source, /routeTransitionKey\.value = resolveShellRouteTransitionKey/);
278
282
  assert.match(source, /prefers-reduced-motion:\s*reduce/);
279
283
  });
280
284
 
281
285
  test("shell-web route transition key preserves no-motion surfaces and animated path transitions", () => {
282
- const previewSurfaceKey = "surface:vibe64-preview";
286
+ const previewSurfaceKey = "surface:editor-preview";
283
287
  assert.equal(
284
288
  resolveShellRouteTransitionKey({
285
289
  routeTransitionName: "",
286
290
  routePathKey: "/preview",
287
- surfaceId: "vibe64-preview"
291
+ surfaceId: "editor-preview"
288
292
  }),
289
293
  previewSurfaceKey
290
294
  );
@@ -292,7 +296,7 @@ test("shell-web route transition key preserves no-motion surfaces and animated p
292
296
  resolveShellRouteTransitionKey({
293
297
  routeTransitionName: "",
294
298
  routePathKey: "/preview/dashboard",
295
- surfaceId: "vibe64-preview"
299
+ surfaceId: "editor-preview"
296
300
  }),
297
301
  previewSurfaceKey
298
302
  );
@@ -0,0 +1,90 @@
1
+ import { createRenderer, defineComponent } from "vue";
2
+
3
+ function node(type) {
4
+ return { type, props: {}, children: [], parent: null, text: "" };
5
+ }
6
+
7
+ const renderer = createRenderer({
8
+ createElement: node,
9
+ createText: () => node("text"),
10
+ createComment: () => node("comment"),
11
+ setText() {},
12
+ setElementText() {},
13
+ patchProp() {},
14
+ parentNode: (item) => item.parent,
15
+ nextSibling: () => null,
16
+ insert(item, parent) {
17
+ item.parent = parent;
18
+ parent.children.push(item);
19
+ },
20
+ remove(item) {
21
+ item.parent?.children.splice(item.parent.children.indexOf(item), 1);
22
+ }
23
+ });
24
+
25
+ // Runs a composable inside a mounted component, with what the application provides.
26
+ function mountComposable(useComposable, { provide = [], plugins = [] } = {}) {
27
+ let result = null;
28
+ const app = renderer.createApp(defineComponent({
29
+ setup() {
30
+ result = useComposable();
31
+ return () => null;
32
+ }
33
+ }));
34
+ for (const plugin of plugins) {
35
+ app.use(plugin);
36
+ }
37
+ for (const [key, value] of provide) {
38
+ app.provide(key, value);
39
+ }
40
+ app.mount(node("root"));
41
+ return { app, result };
42
+ }
43
+
44
+ // A window whose listeners a test can dispatch to, and a document with what the shell's composables read.
45
+ function installPage(t, { window: windowMembers = {}, document: documentMembers = {} } = {}) {
46
+ const listeners = new Map();
47
+ const classes = new Set();
48
+ globalThis.window = {
49
+ location: { href: "https://app.test/", origin: "https://app.test" },
50
+ addEventListener(type, handler) {
51
+ listeners.set(type, handler);
52
+ },
53
+ removeEventListener(type, handler) {
54
+ if (listeners.get(type) === handler) {
55
+ listeners.delete(type);
56
+ }
57
+ },
58
+ ...windowMembers
59
+ };
60
+ globalThis.document = {
61
+ documentElement: {
62
+ classList: {
63
+ toggle(name, enabled) {
64
+ if (enabled) {
65
+ classes.add(name);
66
+ } else {
67
+ classes.delete(name);
68
+ }
69
+ },
70
+ remove(name) {
71
+ classes.delete(name);
72
+ }
73
+ }
74
+ },
75
+ ...documentMembers
76
+ };
77
+ t.after(() => {
78
+ delete globalThis.window;
79
+ delete globalThis.document;
80
+ });
81
+ return {
82
+ classes,
83
+ listeners,
84
+ dispatch(type, event) {
85
+ listeners.get(type)({ preventDefault() {}, target: { closest: () => null, setPointerCapture() {} }, ...event });
86
+ }
87
+ };
88
+ }
89
+
90
+ export { installPage, mountComposable };
@@ -9,6 +9,7 @@ import { createErrorPresentationStore } from "../src/client/error/store.js";
9
9
  import { createDefaultMaterialErrorPresenters } from "../src/client/error/presenters.js";
10
10
  import { requestRecoveryMessage } from "../src/client/requestRecovery/runtime.js";
11
11
  import { resolveShellDrawerToggleLabel } from "../src/client/support/drawerPresentation.js";
12
+ import { silentLogger } from "@jskit-ai/kernel/shared/support/silentLogger";
12
13
 
13
14
  // A test language with every shell key translated, plus the kernel code used below.
14
15
  function testLanguageMessages() {
@@ -40,7 +41,8 @@ function createStoreRuntime() {
40
41
  const store = createErrorPresentationStore();
41
42
  const runtime = createErrorRuntime({
42
43
  presenters: createDefaultMaterialErrorPresenters({ store }),
43
- moduleDefaultPresenterId: "material.snackbar"
44
+ moduleDefaultPresenterId: "material.snackbar",
45
+ logger: silentLogger
44
46
  });
45
47
  return { store, runtime };
46
48
  }
@@ -102,7 +104,7 @@ test("presented client errors keep their messageCode from the cause", () => {
102
104
  test("a module that fails to load is reported with the kernel's sentence code", async () => {
103
105
  const { createShellAsyncModuleRecoveryRuntime } = await import("../src/client/asyncModuleRecovery/runtime.js");
104
106
  const reports = [];
105
- const runtime = createShellAsyncModuleRecoveryRuntime({ errorRuntime: { report: (entry) => reports.push(entry) } });
107
+ const runtime = createShellAsyncModuleRecoveryRuntime({ errorRuntime: { report: (entry) => reports.push(entry) }, logger: silentLogger });
106
108
  runtime.notify(new TypeError("Failed to fetch dynamically imported module: /src/x.js"));
107
109
  assert.equal(reports.length, 1);
108
110
  assert.equal(reports[0].message, "App module did not download. The app may have been updated, or the network request failed.");
@@ -0,0 +1,213 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { computed, nextTick, ref } from "vue";
4
+ import { useShellDrawer } from "../src/client/composables/useShellDrawer.js";
5
+ import { installPage, mountComposable } from "./support/mountComposable.js";
6
+
7
+ const LABEL_TEXT_WIDTH = 150;
8
+
9
+ function createDrawerElement() {
10
+ const label = { style: { display: "block", visibility: "visible" } };
11
+ return {
12
+ label,
13
+ getBoundingClientRect: () => ({ left: 0, right: 248 }),
14
+ querySelector: () => null,
15
+ querySelectorAll: () => [label]
16
+ };
17
+ }
18
+
19
+ function mountDrawer(t, { compact = false, props = {} } = {}) {
20
+ const frames = [];
21
+ const drawerElement = createDrawerElement();
22
+ const fontListeners = new Set();
23
+ const page = installPage(t, {
24
+ window: {
25
+ requestAnimationFrame(callback) {
26
+ frames.push(callback);
27
+ return frames.length;
28
+ },
29
+ cancelAnimationFrame(id) {
30
+ frames[id - 1] = null;
31
+ },
32
+ getComputedStyle: (element) => element.style || { direction: "ltr", borderRightWidth: "1px" }
33
+ },
34
+ document: {
35
+ fonts: {
36
+ ready: Promise.resolve(),
37
+ addEventListener: (_type, listener) => fontListeners.add(listener),
38
+ removeEventListener: (_type, listener) => fontListeners.delete(listener)
39
+ },
40
+ getElementById: () => drawerElement,
41
+ createRange: () => ({
42
+ selectNodeContents() {},
43
+ getBoundingClientRect: () => ({ left: 16, right: 16 + LABEL_TEXT_WIDTH, width: LABEL_TEXT_WIDTH })
44
+ })
45
+ }
46
+ });
47
+ const observers = [];
48
+ globalThis.MutationObserver = class {
49
+ constructor(callback) {
50
+ this.callback = callback;
51
+ this.connected = false;
52
+ observers.push(this);
53
+ }
54
+
55
+ observe() {
56
+ this.connected = true;
57
+ }
58
+
59
+ disconnect() {
60
+ this.connected = false;
61
+ }
62
+ };
63
+ t.after(() => {
64
+ delete globalThis.MutationObserver;
65
+ });
66
+
67
+ const isCompactLayout = ref(compact);
68
+ const drawerOpen = ref(true);
69
+ const focused = [];
70
+ const navigationToggle = ref({ $el: { focus: (options) => focused.push(options) } });
71
+ const { app, result } = mountComposable(() => useShellDrawer({
72
+ props: {
73
+ desktopDrawerClosedMode: "rail",
74
+ drawerWidth: null,
75
+ railWidth: 80,
76
+ navigationItemSpacing: 12,
77
+ ...props
78
+ },
79
+ isCompactLayout,
80
+ navigationToggle,
81
+ layoutState: {
82
+ drawerDefaultOpen: ref(true),
83
+ drawerOpen,
84
+ resolvedSurface: computed(() => "home"),
85
+ setDrawerOpen(open) {
86
+ drawerOpen.value = open;
87
+ }
88
+ }
89
+ }));
90
+ return { app, drawerOpen, focused, fontListeners, frames, isCompactLayout, observers, page, result };
91
+ }
92
+
93
+ async function runFrames(frames) {
94
+ await nextTick();
95
+ await nextTick();
96
+ for (const frame of frames.splice(0)) {
97
+ frame?.();
98
+ }
99
+ }
100
+
101
+ test("a compact layout closes the drawer and a wide one restores how it was left there", async (t) => {
102
+ const { app, drawerOpen, isCompactLayout, result } = mountDrawer(t);
103
+ assert.equal(drawerOpen.value, true);
104
+ assert.equal(result.drawerPresentation.value.kind, "drawer");
105
+
106
+ drawerOpen.value = false;
107
+ await nextTick();
108
+ assert.equal(result.drawerPresentation.value.kind, "rail");
109
+
110
+ isCompactLayout.value = true;
111
+ await nextTick();
112
+ assert.equal(drawerOpen.value, false);
113
+ assert.equal(result.drawerPresentation.value.kind, "modal");
114
+
115
+ drawerOpen.value = true;
116
+ await nextTick();
117
+ isCompactLayout.value = false;
118
+ await nextTick();
119
+ assert.equal(drawerOpen.value, false);
120
+ app.unmount();
121
+ });
122
+
123
+ test("a wide layout reopens a drawer left open there", async (t) => {
124
+ const { app, drawerOpen, isCompactLayout } = mountDrawer(t);
125
+
126
+ isCompactLayout.value = true;
127
+ await nextTick();
128
+ assert.equal(drawerOpen.value, false);
129
+
130
+ isCompactLayout.value = false;
131
+ await nextTick();
132
+ assert.equal(drawerOpen.value, true);
133
+ app.unmount();
134
+ });
135
+
136
+ test("a compact layout starts closed", (t) => {
137
+ const { app, drawerOpen, result } = mountDrawer(t, { compact: true });
138
+ assert.equal(drawerOpen.value, false);
139
+ assert.equal(result.drawerPresentation.value.visible, false);
140
+ app.unmount();
141
+ });
142
+
143
+ test("Escape closes the compact drawer and returns focus to its toggle", async (t) => {
144
+ const { app, drawerOpen, focused, page } = mountDrawer(t, { compact: true });
145
+
146
+ page.dispatch("keydown", { key: "Escape" });
147
+ assert.deepEqual(focused, []);
148
+
149
+ drawerOpen.value = true;
150
+ await nextTick();
151
+ page.dispatch("keydown", { key: "Enter" });
152
+ assert.equal(drawerOpen.value, true);
153
+ page.dispatch("keydown", { key: "Escape", defaultPrevented: true });
154
+ assert.equal(drawerOpen.value, true);
155
+
156
+ page.dispatch("keydown", { key: "Escape" });
157
+ assert.equal(drawerOpen.value, false);
158
+ await nextTick();
159
+ await nextTick();
160
+ assert.deepEqual(focused, [{ preventScroll: true }]);
161
+ app.unmount();
162
+ });
163
+
164
+ test("the drawer's width follows its measured labels", async (t) => {
165
+ const { app, frames, observers, result } = mountDrawer(t);
166
+ assert.equal(result.resolvedDrawerWidth.value, 248);
167
+
168
+ await runFrames(frames);
169
+
170
+ assert.equal(result.resolvedDrawerWidth.value, 16 + LABEL_TEXT_WIDTH + 12 + 1);
171
+ assert.equal(observers.length, 1);
172
+ assert.equal(observers[0].connected, true);
173
+ app.unmount();
174
+ });
175
+
176
+ test("a fixed drawer width is never measured", async (t) => {
177
+ const { app, frames, result } = mountDrawer(t, { props: { drawerWidth: 300 } });
178
+
179
+ await runFrames(frames);
180
+
181
+ assert.equal(result.fixedDrawerWidth.value, true);
182
+ assert.equal(result.resolvedDrawerWidth.value, 300);
183
+ assert.equal(frames.length, 0);
184
+ app.unmount();
185
+ });
186
+
187
+ test("a closed wide drawer only ignores a request to open it", (t) => {
188
+ const { app, drawerOpen, result } = mountDrawer(t);
189
+
190
+ drawerOpen.value = false;
191
+ result.handleDrawerVisibilityChange(true);
192
+ assert.equal(drawerOpen.value, false);
193
+
194
+ drawerOpen.value = true;
195
+ result.handleDrawerVisibilityChange(false);
196
+ assert.equal(drawerOpen.value, false);
197
+ app.unmount();
198
+ });
199
+
200
+ test("unmounting detaches every listener and pending measurement", async (t) => {
201
+ const { app, fontListeners, frames, observers, page } = mountDrawer(t);
202
+ await nextTick();
203
+ await nextTick();
204
+ assert.equal(page.listeners.size, 2);
205
+ assert.equal(fontListeners.size, 1);
206
+
207
+ app.unmount();
208
+
209
+ assert.equal(page.listeners.size, 0);
210
+ assert.equal(fontListeners.size, 0);
211
+ assert.equal(observers[0].connected, false);
212
+ assert.deepEqual(frames.filter(Boolean), []);
213
+ });