@jskit-ai/shell-web 0.2.13 → 0.2.15
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/CHANGELOG.md +18 -0
- package/fixtures/adaptive-shell/src/ActionsFormPage.vue +22 -0
- package/fixtures/adaptive-shell/src/ActionsPage.vue +74 -0
- package/fixtures/adaptive-shell/src/App.vue +1 -0
- package/fixtures/adaptive-shell/src/ButtonStatesPage.vue +63 -0
- package/fixtures/adaptive-shell/src/ButtonsPage.vue +33 -3
- package/fixtures/adaptive-shell/src/ComponentsPage.vue +178 -0
- package/fixtures/adaptive-shell/src/FeedbackPage.vue +59 -0
- package/fixtures/adaptive-shell/src/ReportsPage.vue +29 -0
- package/fixtures/adaptive-shell/src/StatusButton.vue +17 -0
- package/fixtures/adaptive-shell/src/TitleClaim.vue +17 -0
- package/fixtures/adaptive-shell/src/main.js +131 -5
- package/fixtures/production-build/index.html +15 -0
- package/fixtures/production-build/package.json +5 -0
- package/fixtures/production-build/src/App.vue +27 -0
- package/fixtures/production-build/src/componentChunk.css +5 -0
- package/fixtures/production-build/src/main.js +10 -0
- package/fixtures/production-build/vite.config.mjs +12 -0
- package/locales/en.json +1 -0
- package/package.json +9 -5
- package/patterns/application-shell/PATTERN.md +11 -6
- package/patterns/application-shell/example/src/components/menus/SectionTabLinkItem.vue +42 -0
- package/patterns/application-shell/example/src/pages/home.vue +1 -1
- package/patterns/application-shell/example/src/views/NotFound.vue +1 -1
- package/patterns/page-and-placement/PATTERN.md +6 -0
- package/patterns/page-and-placement/example/src/pages/home/reports.vue +9 -4
- package/patterns/page-and-placement/example/src/placementTopology.js +5 -3
- package/src/client/components/ShellErrorHost.vue +20 -1
- package/src/client/components/ShellLayout.vue +42 -27
- package/src/client/components/ShellNavigationItem.vue +8 -3
- package/src/client/components/ShellNavigationScope.vue +1 -1
- package/src/client/components/ShellOutlet.vue +12 -1
- package/src/client/components/ShellPageAction.vue +107 -28
- package/src/client/components/ShellPageActionsTarget.vue +81 -2
- package/src/client/components/ShellPrimaryAction.vue +69 -0
- package/src/client/components/ShellSectionTabLinkItem.vue +104 -0
- package/src/client/components/ShellTabLinkItem.vue +18 -3
- package/src/client/components/ShellUpButton.vue +13 -8
- package/src/client/composables/useShellAppBar.js +10 -1
- package/src/client/composables/useShellPageClose.js +18 -0
- package/src/client/index.js +3 -0
- package/src/client/navigation/shellNavigationRuntime.js +59 -12
- package/src/client/navigation/usePaths.js +13 -0
- package/src/client/navigation/useShellNavigation.js +2 -0
- package/src/client/providers/ShellWebClientProvider.js +25 -9
- package/src/client/support/drawerPresentation.js +23 -6
- package/src/client/support/navigationPresentation.js +1 -1
- package/src/client/support/pageActions.js +126 -0
- package/src/test/adaptiveShellSmoke.js +31 -16
- package/test/adaptiveShell.browser.test.js +1019 -334
- package/test/drawerPresentation.test.js +20 -2
- package/test/linkResolver.test.js +4 -0
- package/test/materialBaselines.browser.test.js +142 -27
- package/test/packageRouteParent.test.js +41 -0
- package/test/pageActions.test.js +84 -0
- package/test/productionBuild.browser.test.js +98 -0
- package/test/settingsPlacementContract.test.js +11 -4
- package/test/shellNavigationRuntime.test.js +272 -0
|
@@ -0,0 +1,272 @@
|
|
|
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
|
+
});
|
|
182
|
+
|
|
183
|
+
// After Up, the runtime retries focusing the opener of the page left until the page draws it. Those retries end at the
|
|
184
|
+
// next navigation and when focus has moved since they were scheduled, so they never take the caret from a field
|
|
185
|
+
// someone is typing in (a Back then Forward within the retry window used to focus a matching tab on the next page).
|
|
186
|
+
test("Up's opener focus retries stop at the next navigation and when focus has moved", async () => {
|
|
187
|
+
const router = browserLikeRouter(routes);
|
|
188
|
+
const timers = new Map();
|
|
189
|
+
let nextTimer = 1;
|
|
190
|
+
globalThis.window.setTimeout = (callback) => {
|
|
191
|
+
timers.set(nextTimer, callback);
|
|
192
|
+
return nextTimer++;
|
|
193
|
+
};
|
|
194
|
+
globalThis.window.clearTimeout = (id) => {
|
|
195
|
+
timers.delete(id);
|
|
196
|
+
};
|
|
197
|
+
// One round runs the timers due now (one focus attempt); every round runs until none is left.
|
|
198
|
+
const runRound = () => {
|
|
199
|
+
const due = [...timers];
|
|
200
|
+
timers.clear();
|
|
201
|
+
for (const [, callback] of due) {
|
|
202
|
+
callback();
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
const runEveryRound = () => {
|
|
206
|
+
for (let round = 0; round < 20 && timers.size > 0; round += 1) {
|
|
207
|
+
runRound();
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
const focused = [];
|
|
211
|
+
const element = (name) => ({ name, focus: () => focused.push(name) });
|
|
212
|
+
const body = element("body");
|
|
213
|
+
const upButton = element("up");
|
|
214
|
+
const searchBox = element("search");
|
|
215
|
+
let openerDrawn = false;
|
|
216
|
+
const opener = { ...element("opener"), getClientRects: () => (openerDrawn ? [{}] : []) };
|
|
217
|
+
globalThis.document = {
|
|
218
|
+
body,
|
|
219
|
+
activeElement: body,
|
|
220
|
+
querySelectorAll: () => [opener],
|
|
221
|
+
getElementById: () => element("title")
|
|
222
|
+
};
|
|
223
|
+
const runtime = createShellNavigationRuntime({ router });
|
|
224
|
+
runtime.install();
|
|
225
|
+
runtime.attachShell();
|
|
226
|
+
const openFormAndGoUp = async () => {
|
|
227
|
+
await router.push("/home/actions");
|
|
228
|
+
await router.push("/home/actions/new");
|
|
229
|
+
focused.length = 0;
|
|
230
|
+
openerDrawn = false;
|
|
231
|
+
globalThis.document.activeElement = upButton;
|
|
232
|
+
await runtime.up("/home/actions");
|
|
233
|
+
assert.equal(router.currentRoute.value.fullPath, "/home/actions");
|
|
234
|
+
};
|
|
235
|
+
try {
|
|
236
|
+
// Unchanged: focus still on Up, the page draws its opener on a later attempt, and the opener gets focus.
|
|
237
|
+
await openFormAndGoUp();
|
|
238
|
+
runRound();
|
|
239
|
+
assert.deepEqual(focused, [], "no opener drawn yet");
|
|
240
|
+
openerDrawn = true;
|
|
241
|
+
runRound();
|
|
242
|
+
assert.deepEqual(focused, ["opener"]);
|
|
243
|
+
|
|
244
|
+
// A navigation before the opener is drawn cancels the retries.
|
|
245
|
+
await openFormAndGoUp();
|
|
246
|
+
runRound();
|
|
247
|
+
assert.equal(timers.size, 1, "a retry is waiting");
|
|
248
|
+
await router.push("/home/actions/new");
|
|
249
|
+
openerDrawn = true;
|
|
250
|
+
runEveryRound();
|
|
251
|
+
assert.deepEqual(focused, [], "the next page's matching element is not focused");
|
|
252
|
+
|
|
253
|
+
// Focus moved to a field since Up: the retries give up instead of taking it.
|
|
254
|
+
await openFormAndGoUp();
|
|
255
|
+
runRound();
|
|
256
|
+
globalThis.document.activeElement = searchBox;
|
|
257
|
+
openerDrawn = true;
|
|
258
|
+
runEveryRound();
|
|
259
|
+
assert.deepEqual(focused, [], "the field keeps focus");
|
|
260
|
+
|
|
261
|
+
// Focus that only fell back to the body (the left page's element went away) does not stop it.
|
|
262
|
+
await openFormAndGoUp();
|
|
263
|
+
globalThis.document.activeElement = body;
|
|
264
|
+
openerDrawn = true;
|
|
265
|
+
runRound();
|
|
266
|
+
assert.deepEqual(focused, ["opener"]);
|
|
267
|
+
} finally {
|
|
268
|
+
runtime.dispose();
|
|
269
|
+
delete globalThis.window;
|
|
270
|
+
delete globalThis.document;
|
|
271
|
+
}
|
|
272
|
+
});
|