@jskit-ai/shell-web 0.2.4 → 0.2.6
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/package.json +10 -4
- package/src/client/asyncModuleRecovery/index.js +1 -0
- package/src/client/asyncModuleRecovery/inject.js +30 -18
- package/src/client/asyncModuleRecovery/runtime.js +14 -22
- package/src/client/bootstrap/bootstrapPayloadHandlerRegistry.js +13 -6
- package/src/client/browser.js +56 -0
- package/src/client/clientUpdate/runtime.js +28 -18
- package/src/client/components/ShellErrorHost.vue +19 -219
- package/src/client/components/ShellLayout.vue +19 -227
- package/src/client/components/ShellOutlet.vue +16 -53
- package/src/client/components/ShellRouteTransition.vue +2 -291
- package/src/client/composables/shellLayoutDrawerPreference.js +15 -8
- package/src/client/composables/useShellDrawer.js +194 -0
- package/src/client/composables/useShellErrorHost.js +171 -0
- package/src/client/composables/useShellLayoutState.js +10 -20
- package/src/client/composables/useShellNavigationLink.js +6 -6
- package/src/client/composables/useShellPullToRefresh.js +15 -19
- package/src/client/composables/useShellRouteTransition.js +218 -0
- package/src/client/error/index.js +1 -1
- package/src/client/error/inject.js +36 -48
- package/src/client/error/normalize.js +2 -3
- package/src/client/error/policy.js +9 -0
- package/src/client/error/presentation.js +67 -0
- package/src/client/error/presentationDefaults.js +2 -2
- package/src/client/error/presenters.js +44 -19
- package/src/client/error/runtime.js +20 -17
- package/src/client/error/store.js +4 -0
- package/src/client/navigation/linkResolver.js +6 -2
- package/src/client/navigation/usePaths.js +11 -8
- package/src/client/navigation/useSurfaceRouteContext.js +3 -3
- package/src/client/placement/debug.js +2 -2
- package/src/client/placement/index.js +1 -0
- package/src/client/placement/inject.js +49 -46
- package/src/client/placement/pathname.js +3 -9
- package/src/client/placement/runtime.js +4 -16
- package/src/client/placement/surfaceContext.js +14 -33
- package/src/client/placement/validators.js +6 -1
- package/src/client/providers/ShellWebClientProvider.js +14 -32
- package/src/client/providers/appModuleLoadFailure.js +1 -1
- package/src/client/requestRecovery/index.js +1 -0
- package/src/client/requestRecovery/inject.js +29 -17
- package/src/client/requestRecovery/runtime.js +33 -84
- package/src/client/runtime/bootstrapRuntime.js +10 -32
- package/src/client/runtime/refreshRuntime.js +24 -21
- package/src/client/stores/useShellErrorPresentationStore.js +5 -19
- package/src/client/support/drawerWidth.js +39 -0
- package/src/client/support/gestureTargets.js +4 -2
- package/src/client/support/menuLinkTarget.js +1 -1
- package/src/client/support/navigationLinkKeyboard.js +1 -1
- package/src/client/support/primaryNavigation.js +93 -0
- package/src/client/support/routeSwipeGesture.js +13 -3
- package/src/client/support/shellLayoutClass.js +4 -6
- package/src/client/types.js +38 -0
- package/test/asyncModuleRecoveryInject.test.js +13 -18
- package/test/browser.test.js +51 -0
- package/test/clientUpdate.test.js +12 -1
- package/test/drawerWidth.test.js +64 -0
- package/test/errorActions.test.js +7 -2
- package/test/errorPresentation.test.js +51 -0
- package/test/placementInject.test.js +60 -0
- package/test/primaryNavigation.test.js +75 -0
- package/test/provider.test.js +18 -4
- package/test/requestRecovery.test.js +13 -18
- package/test/settingsPlacementContract.test.js +12 -8
- package/test/support/mountComposable.js +90 -0
- package/test/useShellDrawer.test.js +213 -0
- package/test/useShellErrorHost.test.js +149 -0
- package/test/useShellRouteTransition.test.js +129 -0
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { pageViewportWidth } from "../browser.js";
|
|
2
|
+
|
|
1
3
|
const COMPACT_MAX_WIDTH = 600;
|
|
2
4
|
const MEDIUM_MAX_WIDTH = 1280;
|
|
3
5
|
|
|
4
6
|
// Maps the Vuetify display breakpoint name to the shell layout class. Without
|
|
5
7
|
// a known breakpoint the viewport width decides.
|
|
6
|
-
function resolveShellLayoutClass(displayName = "", viewportWidth =
|
|
8
|
+
function resolveShellLayoutClass(displayName = "", viewportWidth = pageViewportWidth()) {
|
|
7
9
|
const name = String(displayName || "").trim().toLowerCase();
|
|
8
10
|
if (name === "xs" || name === "sm") {
|
|
9
11
|
return "compact";
|
|
@@ -25,8 +27,4 @@ function resolveShellLayoutClass(displayName = "", viewportWidth = 0) {
|
|
|
25
27
|
return "expanded";
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
return typeof window === "object" ? Number(window.innerWidth || 0) : 0;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export { readViewportWidth, resolveShellLayoutClass };
|
|
30
|
+
export { resolveShellLayoutClass };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// The values shell-web's client hands out and receives across files, for its own modules and for the packages that use
|
|
2
|
+
// the shell.
|
|
3
|
+
|
|
4
|
+
/** @typedef {ReturnType<typeof import("./error/runtime.js").createErrorRuntime>} ShellErrorRuntime The error runtime. */
|
|
5
|
+
/** @typedef {ReturnType<typeof import("./error/store.js").createErrorPresentationStore>} ShellErrorPresentationStore What the error host shows. */
|
|
6
|
+
/** @typedef {ReturnType<typeof import("./placement/runtime.js").createWebPlacementRuntime>} WebPlacementRuntime The placement runtime. */
|
|
7
|
+
/** @typedef {ReturnType<typeof import("./asyncModuleRecovery/runtime.js").createShellAsyncModuleRecoveryRuntime>} ShellAsyncModuleRecoveryRuntime Offers a reload when an application module fails to load. */
|
|
8
|
+
/** @typedef {ReturnType<typeof import("./requestRecovery/runtime.js").createShellRequestRecoveryRuntime>} ShellRequestRecoveryRuntime Offers a retry or a reload when a request cannot reach the server. */
|
|
9
|
+
/** @typedef {ReturnType<typeof import("./runtime/bootstrapRuntime.js").createShellBootstrapRuntime>} ShellBootstrapRuntime Fetches and applies the bootstrap payload. */
|
|
10
|
+
/** @typedef {ReturnType<typeof import("./runtime/refreshRuntime.js").createShellRefreshRuntime>} ShellRefreshRuntime Refreshes the bootstrap payload and the active queries. */
|
|
11
|
+
/** @typedef {ReturnType<typeof import("./bootstrap/bootstrapPayloadHandlerRegistry.js").createBootstrapPayloadHandlerRegistry>} BootstrapPayloadHandlerRegistry The bootstrap payload handlers. */
|
|
12
|
+
/** @typedef {ReturnType<typeof import("./navigation/useSurfaceRouteContext.js").useSurfaceRouteContext>} SurfaceRouteContext The current route and the surface it is on. */
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The part of the optional `client.realtime` capability the shell reads.
|
|
16
|
+
* @typedef {object} ShellRealtime
|
|
17
|
+
* @property {(listener: (buildId: string) => void) => () => void} onServedClientBuild Calls the listener with each client build a server names; returns the unsubscribe.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* What `useShellLayoutState()` reads from a layout's props.
|
|
22
|
+
* @typedef {object} ShellLayoutStateProps
|
|
23
|
+
* @property {string} [surface] The surface, when the layout names one instead of following the route.
|
|
24
|
+
* @property {string | { key: string, fallback?: string }} [surfaceLabel] A message key, `{ key, fallback }` or plain text.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The props of a surface-aware menu or tab link.
|
|
29
|
+
* @typedef {object} ShellNavigationLinkProps
|
|
30
|
+
* @property {string | { key: string, fallback?: string }} label A message key, `{ key, fallback }` or plain text.
|
|
31
|
+
* @property {string} to
|
|
32
|
+
* @property {string} icon
|
|
33
|
+
* @property {string} surface
|
|
34
|
+
* @property {string} scopedSuffix
|
|
35
|
+
* @property {string} unscopedSuffix
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
export {};
|
|
@@ -2,12 +2,23 @@ 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_ASYNC_MODULE_RECOVERY_RUNTIME,
|
|
5
6
|
SHELL_ASYNC_MODULE_RECOVERY_RUNTIME_KEY,
|
|
6
7
|
useShellAsyncModuleRecoveryRuntime
|
|
7
8
|
} from "../src/client/asyncModuleRecovery/index.js";
|
|
8
9
|
|
|
9
|
-
test("shell async module recovery runtime composable
|
|
10
|
-
|
|
10
|
+
test("shell async module recovery runtime composable resolves NO_SHELL_ASYNC_MODULE_RECOVERY_RUNTIME without the provider", async () => {
|
|
11
|
+
const app = createApp({
|
|
12
|
+
render() {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const runtime = app.runWithContext(() => useShellAsyncModuleRecoveryRuntime());
|
|
18
|
+
|
|
19
|
+
assert.equal(runtime, NO_SHELL_ASYNC_MODULE_RECOVERY_RUNTIME);
|
|
20
|
+
assert.equal(runtime.notify(new Error("failed")), null);
|
|
21
|
+
assert.equal(await runtime.reload(), false);
|
|
11
22
|
});
|
|
12
23
|
|
|
13
24
|
test("shell async module recovery runtime composable resolves the provided public runtime", async () => {
|
|
@@ -31,19 +42,3 @@ test("shell async module recovery runtime composable resolves the provided publi
|
|
|
31
42
|
runtime
|
|
32
43
|
);
|
|
33
44
|
});
|
|
34
|
-
|
|
35
|
-
test("shell async module recovery runtime composable rejects incomplete runtimes", () => {
|
|
36
|
-
const app = createApp({
|
|
37
|
-
render() {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
app.provide(SHELL_ASYNC_MODULE_RECOVERY_RUNTIME_KEY, {
|
|
42
|
-
notify() {}
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
assert.equal(
|
|
46
|
-
app.runWithContext(() => useShellAsyncModuleRecoveryRuntime()),
|
|
47
|
-
null
|
|
48
|
-
);
|
|
49
|
-
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import {
|
|
4
|
+
closestElement,
|
|
5
|
+
pageDocument,
|
|
6
|
+
pageOrigin,
|
|
7
|
+
pagePathname,
|
|
8
|
+
pageStorage,
|
|
9
|
+
pageTitle,
|
|
10
|
+
pageViewportWidth,
|
|
11
|
+
pageWindow
|
|
12
|
+
} from "../src/client/browser.js";
|
|
13
|
+
|
|
14
|
+
test("outside a browser every page read is empty", () => {
|
|
15
|
+
assert.equal(pageWindow(), null);
|
|
16
|
+
assert.equal(pageDocument(), null);
|
|
17
|
+
assert.equal(pagePathname(), "");
|
|
18
|
+
assert.equal(pageOrigin(), "");
|
|
19
|
+
assert.equal(pageTitle(), "");
|
|
20
|
+
assert.equal(pageViewportWidth(), 0);
|
|
21
|
+
assert.equal(pageStorage(), null);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("in a browser the page reads come from the window and the document", (t) => {
|
|
25
|
+
const localStorage = {};
|
|
26
|
+
globalThis.window = {
|
|
27
|
+
innerWidth: 390,
|
|
28
|
+
localStorage,
|
|
29
|
+
location: { pathname: " /home ", origin: "https://app.test" }
|
|
30
|
+
};
|
|
31
|
+
globalThis.document = { title: "App" };
|
|
32
|
+
t.after(() => {
|
|
33
|
+
delete globalThis.window;
|
|
34
|
+
delete globalThis.document;
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
assert.equal(pagePathname(), "/home");
|
|
38
|
+
assert.equal(pageOrigin(), "https://app.test");
|
|
39
|
+
assert.equal(pageTitle(), "App");
|
|
40
|
+
assert.equal(pageViewportWidth(), 390);
|
|
41
|
+
assert.equal(pageStorage(), localStorage);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("an event target that is not an element has no closest element", () => {
|
|
45
|
+
const element = {};
|
|
46
|
+
|
|
47
|
+
assert.equal(closestElement({ closest: () => element }, "a"), element);
|
|
48
|
+
assert.equal(closestElement({ closest: () => null }, "a"), null);
|
|
49
|
+
assert.equal(closestElement({}, "a"), null);
|
|
50
|
+
assert.equal(closestElement(null, "a"), null);
|
|
51
|
+
});
|
|
@@ -92,7 +92,18 @@ async function startClient(t, { inputs = {}, providers = [], probe = { shell: "c
|
|
|
92
92
|
"client.env": {},
|
|
93
93
|
"client.logger": logger,
|
|
94
94
|
"client.pinia": createPinia(),
|
|
95
|
-
"client.query":
|
|
95
|
+
"client.query": {
|
|
96
|
+
getQueryCache() {
|
|
97
|
+
return {
|
|
98
|
+
getAll() {
|
|
99
|
+
return [];
|
|
100
|
+
},
|
|
101
|
+
subscribe() {
|
|
102
|
+
return () => {};
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
},
|
|
96
107
|
"client.router": { currentRoute: { value: { path: "/" } }, onError: () => () => {} },
|
|
97
108
|
"client.surface": createSurfaceRuntime({
|
|
98
109
|
allMode: "all",
|
package/test/drawerWidth.test.js
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
DEFAULT_SHELL_DRAWER_WIDTH,
|
|
5
5
|
DEFAULT_SHELL_NAVIGATION_ITEM_SPACING,
|
|
6
6
|
DEFAULT_SHELL_RAIL_WIDTH,
|
|
7
|
+
measureDrawerContentWidth,
|
|
7
8
|
normalizeShellDrawerWidth,
|
|
8
9
|
normalizeShellNavigationItemSpacing,
|
|
9
10
|
normalizeShellRailWidth,
|
|
@@ -57,3 +58,66 @@ test("content-aware width ignores invalid measurements and uses a bounded fallba
|
|
|
57
58
|
360
|
|
58
59
|
);
|
|
59
60
|
});
|
|
61
|
+
|
|
62
|
+
function installMeasuredPage(t, { drawerStyle, textRects }) {
|
|
63
|
+
globalThis.window = {
|
|
64
|
+
getComputedStyle: (element) => element.style || drawerStyle
|
|
65
|
+
};
|
|
66
|
+
globalThis.document = {
|
|
67
|
+
createRange() {
|
|
68
|
+
let rect = null;
|
|
69
|
+
return {
|
|
70
|
+
selectNodeContents(element) {
|
|
71
|
+
rect = textRects.get(element);
|
|
72
|
+
},
|
|
73
|
+
getBoundingClientRect: () => rect
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
t.after(() => {
|
|
78
|
+
delete globalThis.window;
|
|
79
|
+
delete globalThis.document;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function createLabel(style = {}) {
|
|
84
|
+
return { style: { display: "block", visibility: "visible", ...style } };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
test("the drawer measures the labels people can see, from its inline start", (t) => {
|
|
88
|
+
const wide = createLabel();
|
|
89
|
+
const hidden = createLabel({ visibility: "hidden" });
|
|
90
|
+
const collapsed = createLabel({ display: "none" });
|
|
91
|
+
const empty = createLabel();
|
|
92
|
+
installMeasuredPage(t, {
|
|
93
|
+
drawerStyle: { direction: "ltr", borderRightWidth: "1px", borderLeftWidth: "9px" },
|
|
94
|
+
textRects: new Map([
|
|
95
|
+
[wide, { left: 56, right: 156, width: 100 }],
|
|
96
|
+
[hidden, { left: 56, right: 356, width: 300 }],
|
|
97
|
+
[collapsed, { left: 56, right: 356, width: 300 }],
|
|
98
|
+
[empty, { left: 56, right: 56, width: 0 }]
|
|
99
|
+
])
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const width = measureDrawerContentWidth({
|
|
103
|
+
getBoundingClientRect: () => ({ left: 40, right: 288 }),
|
|
104
|
+
querySelectorAll: () => [wide, hidden, collapsed, empty]
|
|
105
|
+
}, 12);
|
|
106
|
+
|
|
107
|
+
assert.equal(width, 16 + 100 + 12 + 1);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test("a right-to-left drawer measures from its right edge and ends at its left border", (t) => {
|
|
111
|
+
const label = createLabel();
|
|
112
|
+
installMeasuredPage(t, {
|
|
113
|
+
drawerStyle: { direction: "rtl", borderRightWidth: "9px", borderLeftWidth: "1px" },
|
|
114
|
+
textRects: new Map([[label, { left: 148, right: 248, width: 100 }]])
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const width = measureDrawerContentWidth({
|
|
118
|
+
getBoundingClientRect: () => ({ left: 0, right: 264 }),
|
|
119
|
+
querySelectorAll: () => [label]
|
|
120
|
+
}, 12);
|
|
121
|
+
|
|
122
|
+
assert.equal(width, 16 + 100 + 12 + 1);
|
|
123
|
+
});
|
|
@@ -3,7 +3,7 @@ import test from "node:test";
|
|
|
3
3
|
import { readFileSync } from "node:fs";
|
|
4
4
|
import { registerHooks } from "node:module";
|
|
5
5
|
import { compileScript, parse } from "@vue/compiler-sfc";
|
|
6
|
-
import { createRenderer, defineComponent, h, nextTick } from "vue";
|
|
6
|
+
import { createRenderer, defineComponent, h, nextTick, shallowRef } from "vue";
|
|
7
7
|
import { createPinia } from "pinia";
|
|
8
8
|
import { createErrorRuntime } from "../src/client/error/runtime.js";
|
|
9
9
|
import { SHELL_WEB_ERROR_RUNTIME_KEY } from "../src/client/error/inject.js";
|
|
@@ -52,13 +52,18 @@ function fixture(t) {
|
|
|
52
52
|
app.use(pinia);
|
|
53
53
|
useShellErrorPresentationStore(pinia).attachRuntimeStore(store);
|
|
54
54
|
app.provide(SHELL_WEB_ERROR_RUNTIME_KEY, runtime);
|
|
55
|
+
app.provide(Symbol.for("vuetify:layout"), { mainRect: shallowRef({ top: 0, left: 0, right: 0, bottom: 0 }) });
|
|
56
|
+
globalThis.document = { documentElement: { style: { removeProperty() {} } } };
|
|
55
57
|
for (const name of ["VSnackbar", "VDialog", "VCard", "VCardTitle", "VCardText", "VCardActions", "VSpacer", "VAlert", "VBtn"]) {
|
|
56
58
|
app.component(name, defineComponent({ setup: (_props, { slots }) => () =>
|
|
57
59
|
h(name, {}, [slots.default?.(), slots.actions?.()]) }));
|
|
58
60
|
}
|
|
59
61
|
const root = node("root");
|
|
60
62
|
app.mount(root);
|
|
61
|
-
t.after(() =>
|
|
63
|
+
t.after(() => {
|
|
64
|
+
app.unmount();
|
|
65
|
+
delete globalThis.document;
|
|
66
|
+
});
|
|
62
67
|
const all = (item = root) => [item, ...item.children.flatMap((child) => all(child))];
|
|
63
68
|
const button = (label) => all().find((item) => item.type === "VBtn" &&
|
|
64
69
|
all(item).some((child) => child.text.trim() === label));
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { mdiAlertOutline, mdiCheckCircleOutline, mdiInformationOutline } from "@mdi/js";
|
|
4
|
+
import {
|
|
5
|
+
actionsFor,
|
|
6
|
+
resolveBannerPlacement,
|
|
7
|
+
resolveSeverityColor,
|
|
8
|
+
resolveSeverityIcon,
|
|
9
|
+
resolveTimeout
|
|
10
|
+
} from "../src/client/error/presentation.js";
|
|
11
|
+
|
|
12
|
+
test("each severity has its color and icon, and anything else reads as an error", () => {
|
|
13
|
+
assert.equal(resolveSeverityColor(" INFO "), "info");
|
|
14
|
+
assert.equal(resolveSeverityColor("success"), "success");
|
|
15
|
+
assert.equal(resolveSeverityColor("warning"), "warning");
|
|
16
|
+
assert.equal(resolveSeverityColor("critical"), "error");
|
|
17
|
+
assert.equal(resolveSeverityColor(""), "error");
|
|
18
|
+
|
|
19
|
+
assert.equal(resolveSeverityIcon("info"), mdiInformationOutline);
|
|
20
|
+
assert.equal(resolveSeverityIcon("success"), mdiCheckCircleOutline);
|
|
21
|
+
assert.equal(resolveSeverityIcon("warning"), mdiAlertOutline);
|
|
22
|
+
assert.equal(resolveSeverityIcon("error"), mdiAlertOutline);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("a snackbar times out unless it persists or shows nothing", () => {
|
|
26
|
+
assert.equal(resolveTimeout(null), -1);
|
|
27
|
+
assert.equal(resolveTimeout({ persist: true }), -1);
|
|
28
|
+
assert.equal(resolveTimeout({ persist: false }), 5000);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("an entry's actions list its action first and skip an empty one", () => {
|
|
32
|
+
const action = { label: "Retry" };
|
|
33
|
+
const additional = { label: "Details" };
|
|
34
|
+
|
|
35
|
+
assert.deepEqual(actionsFor(null), []);
|
|
36
|
+
assert.deepEqual(actionsFor({ action, additionalActions: [additional] }), [action, additional]);
|
|
37
|
+
assert.deepEqual(actionsFor({ action: null, additionalActions: [additional] }), [additional]);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("banners float below a top app bar and join the page without one", () => {
|
|
41
|
+
assert.deepEqual(resolveBannerPlacement({ top: 0 }), { inline: true, style: undefined });
|
|
42
|
+
assert.deepEqual(resolveBannerPlacement({}), { inline: true, style: undefined });
|
|
43
|
+
assert.deepEqual(resolveBannerPlacement({ top: 64, left: 256, right: 0 }), {
|
|
44
|
+
inline: false,
|
|
45
|
+
style: {
|
|
46
|
+
top: "calc(env(safe-area-inset-top, 0px) + 64px)",
|
|
47
|
+
left: "256px",
|
|
48
|
+
right: "0px"
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import {
|
|
4
|
+
NO_WEB_PLACEMENT_RUNTIME,
|
|
5
|
+
SHELL_WEB_PLACEMENT_RUNTIME_KEY,
|
|
6
|
+
useWebPlacementContext,
|
|
7
|
+
useWebPlacementRevision,
|
|
8
|
+
useWebPlacementRuntime
|
|
9
|
+
} from "../src/client/placement/inject.js";
|
|
10
|
+
import { createWebPlacementRuntime } from "../src/client/placement/runtime.js";
|
|
11
|
+
import { silentLogger } from "@jskit-ai/kernel/shared/support/silentLogger";
|
|
12
|
+
import { mountComposable } from "./support/mountComposable.js";
|
|
13
|
+
|
|
14
|
+
function mountWithRuntime(useComposable) {
|
|
15
|
+
const runtime = createWebPlacementRuntime({ components: new Map(), logger: silentLogger });
|
|
16
|
+
return { runtime, ...mountComposable(useComposable(runtime), { provide: [[SHELL_WEB_PLACEMENT_RUNTIME_KEY, runtime]] }) };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
test("an application without the provider places nothing", () => {
|
|
20
|
+
const { app, result } = mountComposable(() => ({
|
|
21
|
+
runtime: useWebPlacementRuntime(),
|
|
22
|
+
placement: useWebPlacementContext()
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
assert.equal(result.runtime, NO_WEB_PLACEMENT_RUNTIME);
|
|
26
|
+
assert.deepEqual(result.runtime.getPlacements(), []);
|
|
27
|
+
assert.deepEqual(result.placement.context.value, {});
|
|
28
|
+
assert.deepEqual(result.placement.mergeContext({ a: 1 }), {});
|
|
29
|
+
app.unmount();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("the placement context follows the runtime while mounted", () => {
|
|
33
|
+
const { app, result, runtime } = mountWithRuntime(() => useWebPlacementContext);
|
|
34
|
+
|
|
35
|
+
runtime.setContext({ surface: "app" });
|
|
36
|
+
assert.equal(result.context.value.surface, "app");
|
|
37
|
+
|
|
38
|
+
result.mergeContext({ extra: true }, "test");
|
|
39
|
+
assert.deepEqual(runtime.getContext(), { surface: "app", extra: true });
|
|
40
|
+
|
|
41
|
+
result.replaceContext({ only: true }, "test");
|
|
42
|
+
assert.deepEqual(runtime.getContext(), { only: true });
|
|
43
|
+
|
|
44
|
+
app.unmount();
|
|
45
|
+
runtime.setContext({ after: true });
|
|
46
|
+
assert.equal(result.context.value.after, undefined);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("the placement revision follows the runtime while mounted", () => {
|
|
50
|
+
const { app, result, runtime } = mountWithRuntime((target) => () => useWebPlacementRevision(target));
|
|
51
|
+
assert.equal(result.value, 0);
|
|
52
|
+
|
|
53
|
+
runtime.setContext({ surface: "app" });
|
|
54
|
+
assert.equal(result.value, runtime.getRevision());
|
|
55
|
+
|
|
56
|
+
app.unmount();
|
|
57
|
+
const stopped = result.value;
|
|
58
|
+
runtime.setContext({ surface: "admin" });
|
|
59
|
+
assert.equal(result.value, stopped);
|
|
60
|
+
});
|
|
@@ -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
|
+
});
|
package/test/provider.test.js
CHANGED
|
@@ -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 =
|
|
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
|
-
|
|
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
|
|
33
|
-
|
|
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
|
|
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,
|
|
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
|
|
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
|
|
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,7 +277,7 @@ 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
|
|
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
|
});
|