@jskit-ai/shell-web 0.2.16 → 0.2.17
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 +1 -0
- package/fixtures/adaptive-shell/src/App.vue +5 -0
- package/fixtures/adaptive-shell/src/RecordListPage.vue +10 -2
- package/package.json +3 -3
- package/src/client/support/drawerWidth.js +26 -2
- package/test/adaptiveShell.browser.test.js +80 -0
- package/test/drawerWidth.test.js +58 -0
- package/test/shellNavigationRuntime.test.js +5 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
- A content-sized drawer (`drawer-width="content"`) fits the identity at its top (`ShellLayout`'s `top-left` slot or the `shell-layout:top-left` outlet, such as a workspace switcher) as well as its labels. It measured only the labels, so a name longer than they were was cut to the drawer's width; the identity is now read at the width its content wants, its 12dp padding included, and the drawer takes the wider of that and the labels, up to 360dp as before.
|
|
5
6
|
- The shell's client provider starts loading the app's `src/placementTopology.js`, `src/placement.js` and `src/error.js` together instead of each after the one before; it still reads, checks and applies them in the same order, and each is still optional. Measured on the accounts starter with 60 ms of latency per request: the three arrived by 851 ms instead of 935 ms (721-790, 799-865 and 869-935 ms before, 718-851 ms together after), and the bootstrap request that follows them started 82 ms sooner.
|
|
6
7
|
- After Up or the browser's Back, the shell's attempts to focus the element that opened the page left (every 100 ms for up to 1.5 s, until the page draws it) stop at the next navigation and when focus has moved since they started. Before, they outlived both: a Back then a Forward within 1.5 s could focus a matching link or tab on the next page and take the caret from a field someone was typing in. Focus that only fell back to the page body, as when the left page's element goes away, still gets the opener.
|
|
7
8
|
- `ShellErrorHost`'s snackbar no longer covers the actions it reports on: it showed at the bottom end for 5 seconds over Save and the FAB, so a second Save waited it out. It is centred at the bottom on compact windows and starts at the content's start edge on wider ones, at most half the content's width, clear of end-aligned FABs and form actions; Vuetify keeps it above the navigation bar and a FAB that takes layout room (`<v-fab app layout>`). On a phone a form's Save is the app bar's primary action (`ShellPageAction primary`), which it never covers.
|
|
@@ -20,6 +20,8 @@ const themeMode = computed(() => route.query.theme === "dark" ? "dark" : "light"
|
|
|
20
20
|
const railWidth = computed(() => Number(route.query.railWidth) || undefined);
|
|
21
21
|
const navigationItemSpacing = computed(() => Number(route.query.navigationItemSpacing) || undefined);
|
|
22
22
|
const drawerWidth = computed(() => (route.query.drawerWidth === "content" ? "content" : undefined));
|
|
23
|
+
// ?identity=<name> puts an identity at the top of the drawer, as a workspace switcher does.
|
|
24
|
+
const identity = computed(() => String(route.query.identity || ""));
|
|
23
25
|
|
|
24
26
|
watchEffect(function applyFixtureTheme() {
|
|
25
27
|
const themeName = `${surface.value === "admin" ? "admin" : "home"}-${themeMode.value}`;
|
|
@@ -43,6 +45,9 @@ watchEffect(function applyFixtureTheme() {
|
|
|
43
45
|
:navigation-item-spacing="navigationItemSpacing"
|
|
44
46
|
:drawer-width="drawerWidth"
|
|
45
47
|
>
|
|
48
|
+
<template v-if="identity" #top-left>
|
|
49
|
+
<v-btn variant="text" class="fixture-identity text-none" prepend-icon="$work">{{ identity }}</v-btn>
|
|
50
|
+
</template>
|
|
46
51
|
<RouterView />
|
|
47
52
|
</ShellLayout>
|
|
48
53
|
<ShellErrorHost />
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
-
import { computed } from "vue";
|
|
2
|
+
import { computed, ref } from "vue";
|
|
3
3
|
import { useRoute } from "vue-router";
|
|
4
4
|
import { usePaths } from "../../../src/client/navigation/usePaths.js";
|
|
5
5
|
import { records } from "./records.js";
|
|
@@ -7,7 +7,15 @@ import { records } from "./records.js";
|
|
|
7
7
|
const route = useRoute();
|
|
8
8
|
const paths = usePaths();
|
|
9
9
|
const kind = computed(() => String(route.meta.kind));
|
|
10
|
-
|
|
10
|
+
// A list that loads its rows draws them after the page opens: window.__fixtureRecordsDelayMs holds them back that long.
|
|
11
|
+
const delay = Number(window.__fixtureRecordsDelayMs) || 0;
|
|
12
|
+
const loaded = ref(delay <= 0);
|
|
13
|
+
if (!loaded.value) {
|
|
14
|
+
window.setTimeout(() => {
|
|
15
|
+
loaded.value = true;
|
|
16
|
+
}, delay);
|
|
17
|
+
}
|
|
18
|
+
const items = computed(() => (loaded.value ? records[kind.value] || [] : []));
|
|
11
19
|
</script>
|
|
12
20
|
|
|
13
21
|
<template>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/shell-web",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.17",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jskit test"
|
|
@@ -46,14 +46,14 @@
|
|
|
46
46
|
"./locales/en.json": "./locales/en.json"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@jskit-ai/architecture-inspector": "0.1.
|
|
49
|
+
"@jskit-ai/architecture-inspector": "0.1.12"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@jskit-ai/material-web": "0.1.3",
|
|
53
53
|
"@vue/compiler-sfc": "3.5.44"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@jskit-ai/kernel": "0.2.
|
|
56
|
+
"@jskit-ai/kernel": "0.2.14",
|
|
57
57
|
"pinia": "^4.0.3",
|
|
58
58
|
"vue": "^3.5.44",
|
|
59
59
|
"vue-router": "^5.3.1",
|
|
@@ -82,7 +82,9 @@ function resolveContentAwareDrawerWidth(
|
|
|
82
82
|
if (!Number.isFinite(logicalStart) || logicalStart < 0 || !Number.isFinite(textWidth) || textWidth <= 0) {
|
|
83
83
|
continue;
|
|
84
84
|
}
|
|
85
|
-
|
|
85
|
+
// A measurement that brings its own end space (the identity's padding) says so; a label gets the drawer's.
|
|
86
|
+
const measurementEndGap = Number.isFinite(measurement?.endGap) ? measurement.endGap : Number(endGap || 0);
|
|
87
|
+
requiredWidth = Math.max(requiredWidth, logicalStart + textWidth + measurementEndGap);
|
|
86
88
|
}
|
|
87
89
|
|
|
88
90
|
if (requiredWidth <= 0) {
|
|
@@ -99,7 +101,25 @@ function measureRenderedText(element) {
|
|
|
99
101
|
return range.getBoundingClientRect();
|
|
100
102
|
}
|
|
101
103
|
|
|
102
|
-
// The
|
|
104
|
+
// The identity at the top of the drawer (ShellLayout's top-left slot or outlet, such as a workspace switcher) at the
|
|
105
|
+
// width its content wants: a name wider than the drawer is cut to the drawer's width, so its box is measured with the
|
|
106
|
+
// width left to its content (max-content) for that one reading, its padding included, and set back before anything
|
|
107
|
+
// paints. Hidden (empty), it measures nothing.
|
|
108
|
+
function measureDrawerIdentity(identityElement, drawerRect, rightToLeft, endBorderWidth) {
|
|
109
|
+
const { width, maxWidth } = identityElement.style;
|
|
110
|
+
identityElement.style.width = "max-content";
|
|
111
|
+
identityElement.style.maxWidth = "none";
|
|
112
|
+
const rect = identityElement.getBoundingClientRect();
|
|
113
|
+
identityElement.style.width = width;
|
|
114
|
+
identityElement.style.maxWidth = maxWidth;
|
|
115
|
+
return {
|
|
116
|
+
logicalStart: rightToLeft ? drawerRect.right - rect.right : rect.left - drawerRect.left,
|
|
117
|
+
textWidth: rect.width,
|
|
118
|
+
endGap: endBorderWidth
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// The width the drawer's identity and rendered labels need, from where each one starts on the drawer's inline axis.
|
|
103
123
|
function measureDrawerContentWidth(drawerElement, navigationItemSpacing) {
|
|
104
124
|
const drawerRect = drawerElement.getBoundingClientRect();
|
|
105
125
|
const drawerStyle = window.getComputedStyle(drawerElement);
|
|
@@ -108,6 +128,10 @@ function measureDrawerContentWidth(drawerElement, navigationItemSpacing) {
|
|
|
108
128
|
rightToLeft ? drawerStyle.borderLeftWidth : drawerStyle.borderRightWidth
|
|
109
129
|
) || 0;
|
|
110
130
|
const measurements = [];
|
|
131
|
+
const identity = drawerElement.querySelector(".shell-layout__identity");
|
|
132
|
+
if (identity) {
|
|
133
|
+
measurements.push(measureDrawerIdentity(identity, drawerRect, rightToLeft, endBorderWidth));
|
|
134
|
+
}
|
|
111
135
|
|
|
112
136
|
for (const label of drawerElement.querySelectorAll(".v-list-item-title")) {
|
|
113
137
|
const labelStyle = window.getComputedStyle(label);
|
|
@@ -502,6 +502,86 @@ test("a snackbar never covers the FAB, the navigation bar or a form's Save, so S
|
|
|
502
502
|
}
|
|
503
503
|
});
|
|
504
504
|
|
|
505
|
+
// A content-sized drawer fits a long name in its identity (a workspace switcher, say) as well as its labels.
|
|
506
|
+
test("a content-sized drawer is wide enough for its identity's name", {
|
|
507
|
+
skip: RUN_BROWSER_TEST ? false : "set JSKIT_SHELL_WEB_BROWSER_INTEGRATION=1",
|
|
508
|
+
timeout: 90_000
|
|
509
|
+
}, async (t) => {
|
|
510
|
+
const { vite, browser } = await startFixture(t);
|
|
511
|
+
const page = await browser.newPage({ baseURL: vite.baseURL, viewport: { width: 1280, height: 900 } });
|
|
512
|
+
const name = "Northwind Regional Distribution";
|
|
513
|
+
await page.goto(`/home?drawerWidth=content&identity=${encodeURIComponent(name)}`);
|
|
514
|
+
const drawer = page.getByTestId("jskit-shell-drawer");
|
|
515
|
+
await expect(drawer).toHaveAttribute("data-presentation", "drawer");
|
|
516
|
+
await expect(drawer.getByRole("button", { name })).toBeVisible();
|
|
517
|
+
// The name's text lies inside the button and the button inside the drawer, its 12dp padding beside it.
|
|
518
|
+
const fit = () => drawer.evaluate((element) => {
|
|
519
|
+
const drawerRect = element.getBoundingClientRect();
|
|
520
|
+
const button = element.querySelector(".fixture-identity");
|
|
521
|
+
const buttonRect = button.getBoundingClientRect();
|
|
522
|
+
const range = document.createRange();
|
|
523
|
+
range.selectNodeContents(button.querySelector(".v-btn__content"));
|
|
524
|
+
const text = range.getBoundingClientRect();
|
|
525
|
+
return {
|
|
526
|
+
textInside: text.left >= buttonRect.left && text.right <= buttonRect.right,
|
|
527
|
+
buttonInside: buttonRect.left >= drawerRect.left && buttonRect.right <= drawerRect.right - 12 + 0.5,
|
|
528
|
+
width: Math.round(drawerRect.width)
|
|
529
|
+
};
|
|
530
|
+
});
|
|
531
|
+
// The drawer measures again once the page's fonts load and animates its width, so each reading waits for both.
|
|
532
|
+
const settle = () => drawer.evaluate(async (element) => {
|
|
533
|
+
await document.fonts.ready;
|
|
534
|
+
await new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve)));
|
|
535
|
+
await Promise.all(element.getAnimations({ subtree: true }).map((animation) => animation.finished.catch(() => undefined)));
|
|
536
|
+
});
|
|
537
|
+
await expect.poll(async () => {
|
|
538
|
+
await settle();
|
|
539
|
+
const { textInside, buttonInside } = await fit();
|
|
540
|
+
return textInside && buttonInside;
|
|
541
|
+
}).toBe(true);
|
|
542
|
+
// It stays at that width: no jump once settled.
|
|
543
|
+
const settled = (await fit()).width;
|
|
544
|
+
assert.ok(settled <= 360, `the drawer is ${settled}px wide`);
|
|
545
|
+
await page.waitForTimeout(300);
|
|
546
|
+
await settle();
|
|
547
|
+
assert.equal((await fit()).width, settled);
|
|
548
|
+
// Without the long name the drawer fits its labels again.
|
|
549
|
+
await page.goto("/home?drawerWidth=content");
|
|
550
|
+
await expect.poll(async () => Math.round((await drawer.boundingBox())?.width || 0)).toBeLessThan(settled);
|
|
551
|
+
await page.close();
|
|
552
|
+
});
|
|
553
|
+
|
|
554
|
+
// A list that fetches its rows is short when the router scrolls; Up and Back still return to where it was scrolled.
|
|
555
|
+
test("Up and Back return to a list's position once the list has drawn its rows", {
|
|
556
|
+
skip: RUN_BROWSER_TEST ? false : "set JSKIT_SHELL_WEB_BROWSER_INTEGRATION=1",
|
|
557
|
+
timeout: 90_000
|
|
558
|
+
}, async (t) => {
|
|
559
|
+
const { vite, browser } = await startFixture(t);
|
|
560
|
+
const page = await browser.newPage({ baseURL: vite.baseURL, viewport: { width: 390, height: 844 } });
|
|
561
|
+
const scrollY = () => page.evaluate(() => window.scrollY);
|
|
562
|
+
await page.goto("/home/contacts");
|
|
563
|
+
for (const back of [pressShellBack, (target) => target.goBack()]) {
|
|
564
|
+
const opener = page.getByRole("link", { name: "Contact 35", exact: true });
|
|
565
|
+
await opener.scrollIntoViewIfNeeded();
|
|
566
|
+
const scrolled = await scrollY();
|
|
567
|
+
assert.ok(scrolled > 400, "the contacts list did not scroll");
|
|
568
|
+
await opener.click();
|
|
569
|
+
await expect(page).toHaveURL(/\/home\/contacts\/contact-35$/u);
|
|
570
|
+
await page.evaluate(() => {
|
|
571
|
+
window.__fixtureRecordsDelayMs = 300;
|
|
572
|
+
});
|
|
573
|
+
await back(page);
|
|
574
|
+
await expect(page).toHaveURL(/\/home\/contacts$/u);
|
|
575
|
+
await expect(page.getByRole("link", { name: "Contact 35", exact: true })).toBeVisible();
|
|
576
|
+
await expect.poll(scrollY).toBeGreaterThan(scrolled - 3);
|
|
577
|
+
assert.ok(Math.abs(await scrollY() - scrolled) <= 2, `scrolled to ${await scrollY()}, not ${scrolled}`);
|
|
578
|
+
await page.evaluate(() => {
|
|
579
|
+
window.__fixtureRecordsDelayMs = 0;
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
await page.close();
|
|
583
|
+
});
|
|
584
|
+
|
|
505
585
|
test("shell-web's app bar fills with surface-container once the page scrolls under it", {
|
|
506
586
|
skip: RUN_BROWSER_TEST ? false : "set JSKIT_SHELL_WEB_BROWSER_INTEGRATION=1",
|
|
507
587
|
timeout: 90_000
|
package/test/drawerWidth.test.js
CHANGED
|
@@ -101,6 +101,7 @@ test("the drawer measures the labels people can see, from its inline start", (t)
|
|
|
101
101
|
|
|
102
102
|
const width = measureDrawerContentWidth({
|
|
103
103
|
getBoundingClientRect: () => ({ left: 40, right: 288 }),
|
|
104
|
+
querySelector: () => null,
|
|
104
105
|
querySelectorAll: () => [wide, hidden, collapsed, empty]
|
|
105
106
|
}, 12);
|
|
106
107
|
|
|
@@ -116,8 +117,65 @@ test("a right-to-left drawer measures from its right edge and ends at its left b
|
|
|
116
117
|
|
|
117
118
|
const width = measureDrawerContentWidth({
|
|
118
119
|
getBoundingClientRect: () => ({ left: 0, right: 264 }),
|
|
120
|
+
querySelector: () => null,
|
|
119
121
|
querySelectorAll: () => [label]
|
|
120
122
|
}, 12);
|
|
121
123
|
|
|
122
124
|
assert.equal(width, 16 + 100 + 12 + 1);
|
|
123
125
|
});
|
|
126
|
+
|
|
127
|
+
// The drawer's identity (a workspace switcher, say) is cut to the drawer's width when its name is longer, so the drawer
|
|
128
|
+
// reads it at the width its content wants.
|
|
129
|
+
function createIdentity({ natural, cut, start = 40, rightToLeft = false }) {
|
|
130
|
+
const identity = {
|
|
131
|
+
style: { width: "", maxWidth: "" },
|
|
132
|
+
readings: [],
|
|
133
|
+
getBoundingClientRect() {
|
|
134
|
+
const width = identity.style.width === "max-content" && identity.style.maxWidth === "none" ? natural : cut;
|
|
135
|
+
identity.readings.push(width);
|
|
136
|
+
return rightToLeft ? { left: start - width, right: start, width } : { left: start, right: start + width, width };
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
return identity;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
test("a content-sized drawer fits its identity's natural width, padding included", (t) => {
|
|
143
|
+
const label = createLabel();
|
|
144
|
+
installMeasuredPage(t, {
|
|
145
|
+
drawerStyle: { direction: "ltr", borderRightWidth: "1px", borderLeftWidth: "0px" },
|
|
146
|
+
textRects: new Map([[label, { left: 112, right: 212, width: 100 }]])
|
|
147
|
+
});
|
|
148
|
+
const identity = createIdentity({ natural: 300, cut: 180 });
|
|
149
|
+
const drawer = (shown) => ({
|
|
150
|
+
getBoundingClientRect: () => ({ left: 40, right: 220 }),
|
|
151
|
+
querySelector: (selector) => (selector === ".shell-layout__identity" && shown ? identity : null),
|
|
152
|
+
querySelectorAll: () => [label]
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
// The identity's padding is its end space, so only the drawer's border follows it.
|
|
156
|
+
assert.equal(measureDrawerContentWidth(drawer(true), 12), 300 + 1);
|
|
157
|
+
assert.deepEqual(identity.readings, [300]);
|
|
158
|
+
assert.deepEqual(identity.style, { width: "", maxWidth: "" }, "the identity's own width is set back");
|
|
159
|
+
// A name shorter than the labels leaves the labels' width, and a drawer without an identity measures its labels.
|
|
160
|
+
assert.equal(measureDrawerContentWidth({ ...drawer(true), querySelector: () => createIdentity({ natural: 90, cut: 90 }) }, 12),
|
|
161
|
+
72 + 100 + 12 + 1);
|
|
162
|
+
assert.equal(measureDrawerContentWidth(drawer(false), 12), 72 + 100 + 12 + 1);
|
|
163
|
+
// An empty identity is hidden and has no width.
|
|
164
|
+
assert.equal(measureDrawerContentWidth({ ...drawer(true), querySelector: () => createIdentity({ natural: 0, cut: 0 }) }, 12),
|
|
165
|
+
72 + 100 + 12 + 1);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test("a right-to-left drawer measures its identity from its right edge", (t) => {
|
|
169
|
+
installMeasuredPage(t, {
|
|
170
|
+
drawerStyle: { direction: "rtl", borderRightWidth: "0px", borderLeftWidth: "1px" },
|
|
171
|
+
textRects: new Map()
|
|
172
|
+
});
|
|
173
|
+
const identity = createIdentity({ natural: 280, cut: 200, start: 264, rightToLeft: true });
|
|
174
|
+
const width = measureDrawerContentWidth({
|
|
175
|
+
getBoundingClientRect: () => ({ left: 64, right: 264 }),
|
|
176
|
+
querySelector: () => identity,
|
|
177
|
+
querySelectorAll: () => []
|
|
178
|
+
}, 12);
|
|
179
|
+
|
|
180
|
+
assert.equal(width, 280 + 1);
|
|
181
|
+
});
|
|
@@ -6,7 +6,8 @@ import { shellScrollBehavior } from "@jskit-ai/kernel/client";
|
|
|
6
6
|
import { createShellNavigationRuntime } from "../src/client/navigation/shellNavigationRuntime.js";
|
|
7
7
|
|
|
8
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.
|
|
9
|
+
// replacement keeps the entry's state. Its page is drawn (10,000px tall in an 800px window), so the kernel's scroll
|
|
10
|
+
// behaviour reaches a restored position at once.
|
|
10
11
|
function browserLikeRouter(routes) {
|
|
11
12
|
let state = null;
|
|
12
13
|
let position = 0;
|
|
@@ -20,6 +21,9 @@ function browserLikeRouter(routes) {
|
|
|
20
21
|
state = next;
|
|
21
22
|
}
|
|
22
23
|
},
|
|
24
|
+
document: { documentElement: { scrollHeight: 10_000, scrollWidth: 390 } },
|
|
25
|
+
innerHeight: 800,
|
|
26
|
+
innerWidth: 390,
|
|
23
27
|
scrollX: 0,
|
|
24
28
|
scrollY: 0,
|
|
25
29
|
setTimeout: () => 0,
|