@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
@@ -0,0 +1,149 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { markRaw, nextTick, shallowRef } from "vue";
4
+ import { createPinia } from "pinia";
5
+ import { useShellErrorHost } from "../src/client/composables/useShellErrorHost.js";
6
+ import { SHELL_WEB_ERROR_RUNTIME_KEY } from "../src/client/error/inject.js";
7
+ import { createErrorPresentationStore } from "../src/client/error/store.js";
8
+ import { useShellErrorPresentationStore } from "../src/client/stores/useShellErrorPresentationStore.js";
9
+ import { mountComposable } from "./support/mountComposable.js";
10
+
11
+ function mountHost(t, { top = 0 } = {}) {
12
+ const heights = new Map();
13
+ globalThis.document = {
14
+ documentElement: {
15
+ style: {
16
+ setProperty: (name, value) => heights.set(name, value),
17
+ removeProperty: (name) => heights.delete(name)
18
+ }
19
+ }
20
+ };
21
+ const observers = [];
22
+ globalThis.ResizeObserver = class {
23
+ constructor(callback) {
24
+ this.callback = callback;
25
+ observers.push(this);
26
+ }
27
+
28
+ observe(element) {
29
+ this.element = element;
30
+ }
31
+
32
+ disconnect() {
33
+ this.element = null;
34
+ }
35
+ };
36
+ t.after(() => {
37
+ delete globalThis.document;
38
+ delete globalThis.ResizeObserver;
39
+ });
40
+
41
+ const pinia = createPinia();
42
+ const store = createErrorPresentationStore();
43
+ useShellErrorPresentationStore(pinia).attachRuntimeStore(store);
44
+ const reports = [];
45
+ const layoutRect = shallowRef({ top, left: 0, right: 0, bottom: 0 });
46
+ const { app, result } = mountComposable(useShellErrorHost, {
47
+ plugins: [pinia],
48
+ provide: [
49
+ [SHELL_WEB_ERROR_RUNTIME_KEY, { report: (event) => reports.push(event) }],
50
+ [Symbol.for("vuetify:layout"), { mainRect: layoutRect }]
51
+ ]
52
+ });
53
+ return { app, heights, host: result, layoutRect, observers, reports, store };
54
+ }
55
+
56
+ test("snackbars show one at a time and the next opens after the last one leaves", async (t) => {
57
+ const { app, host, store } = mountHost(t);
58
+ const first = store.present("snackbar", { message: "First" });
59
+ store.present("snackbar", { message: "Second" });
60
+ await nextTick();
61
+
62
+ assert.equal(host.displayedSnackbarEntry.value.id, first);
63
+ assert.equal(host.snackbarOpen.value, true);
64
+
65
+ host.onSnackbarModelValue(false);
66
+ await nextTick();
67
+ assert.equal(host.snackbarOpen.value, false);
68
+ assert.equal(host.displayedSnackbarEntry.value.id, first);
69
+
70
+ host.onSnackbarAfterLeave();
71
+ assert.equal(host.displayedSnackbarEntry.value.message, "Second");
72
+ assert.equal(host.snackbarOpen.value, true);
73
+
74
+ host.onSnackbarModelValue(false);
75
+ await nextTick();
76
+ host.onSnackbarAfterLeave();
77
+ assert.equal(host.displayedSnackbarEntry.value, null);
78
+ assert.equal(host.snackbarOpen.value, false);
79
+ app.unmount();
80
+ });
81
+
82
+ test("a dialog closes on request unless it persists", async (t) => {
83
+ const { app, host, store } = mountHost(t);
84
+ store.present("dialog", { message: "Closable" });
85
+ await nextTick();
86
+ host.onDialogModelValue(false);
87
+ await nextTick();
88
+ assert.equal(host.dialogEntry.value, null);
89
+
90
+ store.present("dialog", { message: "Stays", persist: true });
91
+ await nextTick();
92
+ host.onDialogModelValue(false);
93
+ await nextTick();
94
+ assert.equal(host.dialogEntry.value.message, "Stays");
95
+ app.unmount();
96
+ });
97
+
98
+ test("a failed action reports through the shell and still dismisses its entry", async (t) => {
99
+ const { app, host, reports, store } = mountHost(t);
100
+ store.present("snackbar", { message: "Saved" });
101
+ await nextTick();
102
+ const failure = new Error("Undo failed");
103
+
104
+ await host.runAction(host.displayedSnackbarEntry.value, {
105
+ async handler() {
106
+ throw failure;
107
+ }
108
+ });
109
+
110
+ assert.equal(reports[0].cause, failure);
111
+ assert.equal(reports[0].intent, "blocking");
112
+ assert.equal(store.getState().channels.snackbar.length, 0);
113
+ app.unmount();
114
+ });
115
+
116
+ test("an action can keep its entry open", async (t) => {
117
+ const { app, host, store } = mountHost(t);
118
+ store.present("snackbar", { message: "Saved" });
119
+ await nextTick();
120
+
121
+ await host.runAction(host.displayedSnackbarEntry.value, { handler() {}, dismissOnRun: false });
122
+
123
+ assert.equal(store.getState().channels.snackbar.length, 1);
124
+ app.unmount();
125
+ });
126
+
127
+ test("inline banners publish their height and withdraw it when they float or go", async (t) => {
128
+ const { app, heights, host, layoutRect, observers } = mountHost(t);
129
+ const element = markRaw({ getBoundingClientRect: () => ({ height: 40.2 }) });
130
+ assert.equal(host.bannerPlacement.value.inline, true);
131
+
132
+ host.bannersElement.value = element;
133
+ await nextTick();
134
+ assert.equal(heights.get("--shell-error-banners-inline-height"), "41px");
135
+ assert.equal(observers[0].element, element);
136
+
137
+ layoutRect.value = { top: 64, left: 0, right: 0, bottom: 0 };
138
+ await nextTick();
139
+ assert.equal(host.bannerPlacement.value.inline, false);
140
+ assert.equal(heights.size, 0);
141
+ assert.equal(observers[0].element, null);
142
+
143
+ layoutRect.value = { top: 0, left: 0, right: 0, bottom: 0 };
144
+ await nextTick();
145
+ assert.equal(heights.size, 1);
146
+
147
+ app.unmount();
148
+ assert.equal(heights.size, 0);
149
+ });
@@ -0,0 +1,129 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { reactive, ref } from "vue";
4
+ import { routeLocationKey, routerKey } from "vue-router";
5
+ import { useShellRouteTransition } from "../src/client/composables/useShellRouteTransition.js";
6
+ import { SHELL_WEB_PLACEMENT_RUNTIME_KEY } from "../src/client/placement/inject.js";
7
+ import { installPage, mountComposable } from "./support/mountComposable.js";
8
+
9
+ const SURFACE_CONFIG = Object.freeze({
10
+ defaultSurfaceId: "home",
11
+ enabledSurfaceIds: ["home"],
12
+ surfacesById: {
13
+ home: { id: "home", pagesRoot: "home", routeBase: "/home", enabled: true }
14
+ }
15
+ });
16
+
17
+ function createPlacementRuntime() {
18
+ const placements = [
19
+ { id: "home", target: "shell.primary-nav", props: { to: "/home", exact: true } },
20
+ { id: "contacts", target: "shell.primary-nav", props: { to: "/home/contacts" } },
21
+ { id: "bookings", target: "shell.primary-nav", props: { to: "/home/bookings" } }
22
+ ];
23
+ return {
24
+ getContext: () => ({ surfaceConfig: SURFACE_CONFIG }),
25
+ getPlacements: () => placements,
26
+ getRevision: () => 1,
27
+ subscribe: () => () => {}
28
+ };
29
+ }
30
+
31
+ function mountTransition(t, { path = "/home/contacts", displayName = "xs", props = {} } = {}) {
32
+ const page = installPage(t);
33
+ const route = reactive({ path, params: {} });
34
+ const pushes = [];
35
+ const router = {
36
+ async push(href) {
37
+ pushes.push(href);
38
+ route.path = href;
39
+ }
40
+ };
41
+ const { app, result } = mountComposable(
42
+ () => useShellRouteTransition({
43
+ enabled: true,
44
+ target: "shell-layout:primary-bottom-nav",
45
+ semanticTarget: "shell.primary-nav",
46
+ swipeEnabled: true,
47
+ ...props
48
+ }),
49
+ {
50
+ provide: [
51
+ [routerKey, router],
52
+ [routeLocationKey, route],
53
+ [Symbol.for("vuetify:display"), { name: ref(displayName), mobile: ref(false) }],
54
+ [SHELL_WEB_PLACEMENT_RUNTIME_KEY, createPlacementRuntime()]
55
+ ]
56
+ }
57
+ );
58
+ return { app, page, pushes, result, route };
59
+ }
60
+
61
+ const touch = { isPrimary: true, button: 0, pointerType: "touch", pointerId: 3 };
62
+
63
+ test("a swipe moves between destinations and names the direction of the motion", (t) => {
64
+ const { app, page, pushes, result } = mountTransition(t);
65
+ assert.equal(page.classes.has("shell-route-swipe-enabled"), true);
66
+ assert.equal(result.routeTransitionName.value, "");
67
+
68
+ page.dispatch("pointerdown", { ...touch, clientX: 300, clientY: 100 });
69
+ page.dispatch("pointermove", { ...touch, clientX: 200, clientY: 102 });
70
+
71
+ assert.deepEqual(pushes, ["/home/bookings"]);
72
+ assert.equal(result.routeTransitionName.value, "shell-route-slide-forward");
73
+ assert.equal(result.routeTransitionKey.value, "/home/bookings");
74
+
75
+ page.dispatch("pointerdown", { ...touch, clientX: 100, clientY: 100 });
76
+ page.dispatch("pointermove", { ...touch, clientX: 200, clientY: 102 });
77
+
78
+ assert.deepEqual(pushes, ["/home/bookings", "/home/contacts"]);
79
+ assert.equal(result.routeTransitionName.value, "shell-route-slide-reverse");
80
+ app.unmount();
81
+ });
82
+
83
+ test("a route change away from every destination has no motion", (t) => {
84
+ const { app, result, route } = mountTransition(t);
85
+
86
+ route.path = "/home/bookings";
87
+ assert.equal(result.routeTransitionName.value, "shell-route-slide-forward");
88
+
89
+ route.path = "/away";
90
+ assert.equal(result.routeTransitionName.value, "");
91
+ assert.equal(result.routeTransitionKey.value, "surface:home");
92
+ app.unmount();
93
+ });
94
+
95
+ test("wide layouts keep the pane still and never start a swipe", (t) => {
96
+ const { app, page, pushes, result, route } = mountTransition(t, { displayName: "lg" });
97
+ assert.equal(page.classes.has("shell-route-swipe-enabled"), false);
98
+
99
+ page.dispatch("pointerdown", { ...touch, clientX: 300, clientY: 100 });
100
+ page.dispatch("pointermove", { ...touch, clientX: 200, clientY: 102 });
101
+ assert.deepEqual(pushes, []);
102
+
103
+ route.path = "/home/bookings";
104
+ assert.equal(result.routeTransitionName.value, "");
105
+ assert.equal(result.routeTransitionKey.value, "surface:home");
106
+ app.unmount();
107
+ });
108
+
109
+ test("a swipe from an interactive control or with swipes off does nothing", (t) => {
110
+ const off = mountTransition(t, { props: { swipeEnabled: false } });
111
+ assert.equal(off.page.classes.has("shell-route-swipe-enabled"), false);
112
+ off.app.unmount();
113
+
114
+ const { app, page, pushes } = mountTransition(t);
115
+ page.dispatch("pointerdown", { ...touch, clientX: 300, clientY: 100, target: { closest: () => ({}) } });
116
+ page.dispatch("pointermove", { ...touch, clientX: 200, clientY: 102 });
117
+ assert.deepEqual(pushes, []);
118
+ app.unmount();
119
+ });
120
+
121
+ test("unmounting removes the swipe listeners and the page class", (t) => {
122
+ const { app, page } = mountTransition(t);
123
+ assert.equal(page.listeners.size, 4);
124
+
125
+ app.unmount();
126
+
127
+ assert.equal(page.listeners.size, 0);
128
+ assert.equal(page.classes.has("shell-route-swipe-enabled"), false);
129
+ });