@jskit-ai/shell-web 0.2.13 → 0.2.14

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 (57) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/fixtures/adaptive-shell/src/ActionsFormPage.vue +22 -0
  3. package/fixtures/adaptive-shell/src/ActionsPage.vue +74 -0
  4. package/fixtures/adaptive-shell/src/App.vue +1 -0
  5. package/fixtures/adaptive-shell/src/ButtonStatesPage.vue +63 -0
  6. package/fixtures/adaptive-shell/src/ButtonsPage.vue +33 -3
  7. package/fixtures/adaptive-shell/src/ComponentsPage.vue +178 -0
  8. package/fixtures/adaptive-shell/src/FeedbackPage.vue +59 -0
  9. package/fixtures/adaptive-shell/src/ReportsPage.vue +29 -0
  10. package/fixtures/adaptive-shell/src/StatusButton.vue +17 -0
  11. package/fixtures/adaptive-shell/src/TitleClaim.vue +17 -0
  12. package/fixtures/adaptive-shell/src/main.js +131 -5
  13. package/fixtures/production-build/index.html +15 -0
  14. package/fixtures/production-build/package.json +5 -0
  15. package/fixtures/production-build/src/App.vue +27 -0
  16. package/fixtures/production-build/src/componentChunk.css +5 -0
  17. package/fixtures/production-build/src/main.js +10 -0
  18. package/fixtures/production-build/vite.config.mjs +12 -0
  19. package/locales/en.json +1 -0
  20. package/package.json +9 -5
  21. package/patterns/application-shell/PATTERN.md +11 -6
  22. package/patterns/application-shell/example/src/components/menus/SectionTabLinkItem.vue +42 -0
  23. package/patterns/application-shell/example/src/pages/home.vue +1 -1
  24. package/patterns/application-shell/example/src/views/NotFound.vue +1 -1
  25. package/patterns/page-and-placement/PATTERN.md +6 -0
  26. package/patterns/page-and-placement/example/src/pages/home/reports.vue +9 -4
  27. package/patterns/page-and-placement/example/src/placementTopology.js +5 -3
  28. package/src/client/components/ShellErrorHost.vue +20 -1
  29. package/src/client/components/ShellLayout.vue +42 -27
  30. package/src/client/components/ShellNavigationItem.vue +8 -3
  31. package/src/client/components/ShellNavigationScope.vue +1 -1
  32. package/src/client/components/ShellOutlet.vue +12 -1
  33. package/src/client/components/ShellPageAction.vue +107 -28
  34. package/src/client/components/ShellPageActionsTarget.vue +81 -2
  35. package/src/client/components/ShellPrimaryAction.vue +69 -0
  36. package/src/client/components/ShellSectionTabLinkItem.vue +104 -0
  37. package/src/client/components/ShellTabLinkItem.vue +18 -3
  38. package/src/client/components/ShellUpButton.vue +13 -8
  39. package/src/client/composables/useShellAppBar.js +10 -1
  40. package/src/client/composables/useShellPageClose.js +18 -0
  41. package/src/client/index.js +3 -0
  42. package/src/client/navigation/shellNavigationRuntime.js +50 -11
  43. package/src/client/navigation/usePaths.js +13 -0
  44. package/src/client/navigation/useShellNavigation.js +2 -0
  45. package/src/client/support/drawerPresentation.js +23 -6
  46. package/src/client/support/navigationPresentation.js +1 -1
  47. package/src/client/support/pageActions.js +126 -0
  48. package/src/test/adaptiveShellSmoke.js +31 -16
  49. package/test/adaptiveShell.browser.test.js +1019 -334
  50. package/test/drawerPresentation.test.js +20 -2
  51. package/test/linkResolver.test.js +4 -0
  52. package/test/materialBaselines.browser.test.js +142 -27
  53. package/test/packageRouteParent.test.js +41 -0
  54. package/test/pageActions.test.js +84 -0
  55. package/test/productionBuild.browser.test.js +98 -0
  56. package/test/settingsPlacementContract.test.js +11 -4
  57. package/test/shellNavigationRuntime.test.js +181 -0
@@ -0,0 +1,181 @@
1
+ import assert from "node:assert/strict";
2
+ import { readFile } from "node:fs/promises";
3
+ import test from "node:test";
4
+ import { createMemoryHistory, createRouter } from "vue-router";
5
+ import { shellScrollBehavior } from "@jskit-ai/kernel/client";
6
+ import { createShellNavigationRuntime } from "../src/client/navigation/shellNavigationRuntime.js";
7
+
8
+ // A window whose history state behaves as the browser's under vue-router: a push starts an entry with fresh state, a
9
+ // replacement keeps the entry's state.
10
+ function browserLikeRouter(routes) {
11
+ let state = null;
12
+ let position = 0;
13
+ let pushing = false;
14
+ globalThis.window = {
15
+ history: {
16
+ get state() {
17
+ return state;
18
+ },
19
+ replaceState(next) {
20
+ state = next;
21
+ }
22
+ },
23
+ scrollX: 0,
24
+ scrollY: 0,
25
+ setTimeout: () => 0,
26
+ clearTimeout() {}
27
+ };
28
+ const router = createRouter({ history: createMemoryHistory(), routes });
29
+ const push = router.push.bind(router);
30
+ const replace = router.replace.bind(router);
31
+ router.push = (to) => {
32
+ pushing = true;
33
+ return push(to);
34
+ };
35
+ router.replace = (to) => {
36
+ pushing = false;
37
+ return replace(to);
38
+ };
39
+ router.afterEach((_to, _from, failure) => {
40
+ if (!failure && pushing) {
41
+ position += 1;
42
+ state = { position };
43
+ }
44
+ });
45
+ return router;
46
+ }
47
+
48
+ const component = { render: () => null };
49
+ const routes = [
50
+ { path: "/home/actions", component, meta: { jskit: { title: "Actions" } } },
51
+ { path: "/home/actions/new", component, meta: { jskit: { parent: "/actions" } } }
52
+ ];
53
+
54
+ test("a page title claim gives the previous claim's title back when it is released", () => {
55
+ const runtime = createShellNavigationRuntime({ router: createRouter({ history: createMemoryHistory(), routes }) });
56
+ const page = () => "Page";
57
+ const panel = () => "Panel";
58
+ assert.equal(runtime.pageTitleSource.value, null);
59
+ const releasePage = runtime.setPageTitle(page);
60
+ const releasePanel = runtime.setPageTitle(panel);
61
+ assert.equal(runtime.pageTitleSource.value, panel);
62
+ releasePanel();
63
+ assert.equal(runtime.pageTitleSource.value, page, "the page's title comes back");
64
+ releasePanel();
65
+ assert.equal(runtime.pageTitleSource.value, page, "a second release changes nothing");
66
+
67
+ // Released out of order: the remaining claim stays on top.
68
+ const releaseOther = runtime.setPageTitle(panel);
69
+ releasePage();
70
+ assert.equal(runtime.pageTitleSource.value, panel);
71
+ releaseOther();
72
+ assert.equal(runtime.pageTitleSource.value, null, "with no claim left, the route's title shows");
73
+ });
74
+
75
+ test("a page close claim turns the Up arrow into the page's close until it is released", async () => {
76
+ const runtime = createShellNavigationRuntime({ router: createRouter({ history: createMemoryHistory(), routes }) });
77
+ const closes = [];
78
+ assert.equal(runtime.pageClose.value, null);
79
+ const form = { label: () => "Cancel", close: () => closes.push("form") };
80
+ const release = runtime.setPageClose(form);
81
+ assert.equal(runtime.pageClose.value, form);
82
+ const dialog = { label: () => "Close", close: () => closes.push("dialog") };
83
+ const releaseDialog = runtime.setPageClose(dialog);
84
+ assert.equal(runtime.pageClose.value, dialog);
85
+ releaseDialog();
86
+ assert.equal(runtime.pageClose.value, form, "the form's close comes back");
87
+ release();
88
+ assert.equal(runtime.pageClose.value, null, "with no claim left, the arrow goes Up again");
89
+
90
+ const source = await readFile(new URL("../src/client/components/ShellUpButton.vue", import.meta.url), "utf8");
91
+ assert.match(source, /pageClose\.value \? pageClose\.value\.close\(\) : up\(\)/u);
92
+ assert.match(source, /:icon="pageClose \? '\$close' : '\$arrowBack'"/u);
93
+ });
94
+
95
+ test("finish(target) returns to the trail's entry with its query when the target is the page the form came from", async () => {
96
+ const router = browserLikeRouter(routes);
97
+ const runtime = createShellNavigationRuntime({ router });
98
+ runtime.install();
99
+ runtime.attachShell();
100
+ try {
101
+ await router.push("/home/actions?view=table&page=2");
102
+ await router.push("/home/actions/new");
103
+ assert.deepEqual(runtime.trail.value.map((step) => step.path), ["/home/actions?view=table&page=2"]);
104
+ await runtime.finish("/home/actions", "/home/actions");
105
+ assert.equal(router.currentRoute.value.fullPath, "/home/actions?view=table&page=2");
106
+ assert.deepEqual(runtime.trail.value, []);
107
+
108
+ // A target with a query of its own keeps it.
109
+ await router.push("/home/actions/new");
110
+ await runtime.finish("/home/actions?view=cards", "/home/actions");
111
+ assert.equal(router.currentRoute.value.fullPath, "/home/actions?view=cards");
112
+
113
+ // Cancel goes back to where the form was opened from, query and all.
114
+ await router.push("/home/actions/new");
115
+ await runtime.finish("", "/home/actions");
116
+ assert.equal(router.currentRoute.value.fullPath, "/home/actions?view=cards");
117
+ } finally {
118
+ runtime.dispose();
119
+ delete globalThis.window;
120
+ }
121
+ });
122
+
123
+ // File routing groups a folder's routes under a record that draws no component, here the whole /w folder. Two pages
124
+ // in it are different pages: the next opens at the top, and Up's saved position is used. A layout that hosts tabs
125
+ // draws a component, so its tabs stay one page.
126
+ test("pages in a route folder are different pages, so a new page opens at the top and Up restores the saved scroll", async () => {
127
+ const folderRoutes = [{
128
+ path: "/w",
129
+ children: [
130
+ { path: "day/overview", component, meta: { jskit: { title: "Daily overview" } } },
131
+ { path: "bookings/:id", component, meta: { jskit: { parent: "/w/day/overview" } } },
132
+ {
133
+ path: "settings",
134
+ component,
135
+ meta: { jskit: { parent: "/w/day/overview" } },
136
+ children: [
137
+ { path: "general", component },
138
+ { path: "profile", component }
139
+ ]
140
+ }
141
+ ]
142
+ }];
143
+ const router = browserLikeRouter(folderRoutes);
144
+ const push = router.push;
145
+ let pushedState = null;
146
+ router.push = (to) => {
147
+ pushedState = typeof to === "object" ? to.state || null : null;
148
+ return push(to);
149
+ };
150
+ const runtime = createShellNavigationRuntime({ router });
151
+ runtime.install();
152
+ runtime.attachShell();
153
+ const scrollFor = (from) => shellScrollBehavior(router.currentRoute.value, from, null);
154
+ try {
155
+ await router.push("/w/day/overview");
156
+ globalThis.window.scrollY = 1313;
157
+ let from = router.currentRoute.value;
158
+ await router.push("/w/bookings/7");
159
+ assert.deepEqual(scrollFor(from), { top: 0 });
160
+ assert.deepEqual(runtime.trail.value, [{ path: "/w/day/overview", scroll: { left: 0, top: 1313 } }]);
161
+
162
+ globalThis.window.scrollY = 56;
163
+ from = router.currentRoute.value;
164
+ await runtime.up("/w/day/overview");
165
+ assert.equal(router.currentRoute.value.fullPath, "/w/day/overview");
166
+ assert.deepEqual(pushedState, { restoreScroll: { left: 0, top: 1313 } });
167
+ globalThis.window.history.replaceState({ ...globalThis.window.history.state, ...pushedState }, "");
168
+ assert.deepEqual(scrollFor(from), { left: 0, top: 1313 });
169
+
170
+ // Tabs of a settings layout stay one page: the scroll stays, and so does the trail.
171
+ await router.push("/w/settings/general");
172
+ const trail = runtime.trail.value;
173
+ from = router.currentRoute.value;
174
+ await router.push("/w/settings/profile");
175
+ assert.equal(scrollFor(from), false);
176
+ assert.deepEqual(runtime.trail.value, trail);
177
+ } finally {
178
+ runtime.dispose();
179
+ delete globalThis.window;
180
+ }
181
+ });