@jskit-ai/shell-web 0.2.11 → 0.2.13
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 +5 -0
- package/fixtures/adaptive-shell/src/App.vue +11 -3
- package/fixtures/adaptive-shell/src/ButtonsPage.vue +31 -0
- package/fixtures/adaptive-shell/src/OwnBarLayout.vue +36 -0
- package/fixtures/adaptive-shell/src/StudioPage.vue +26 -0
- package/fixtures/adaptive-shell/src/main.js +101 -37
- package/package.json +7 -2
- package/src/client/components/ShellLayout.vue +38 -66
- package/src/client/components/ShellOutlet.vue +2 -50
- package/src/client/components/ShellPageActions.vue +2 -2
- package/src/client/components/ShellPageActionsTarget.vue +24 -0
- package/src/client/components/ShellPageTitle.vue +52 -0
- package/src/client/components/ShellUpButton.vue +29 -0
- package/src/client/composables/useShellAppBar.js +27 -0
- package/src/client/composables/useShellOutletPlacements.js +49 -0
- package/src/client/index.js +4 -0
- package/src/client/navigation/documentNavigation.js +6 -3
- package/src/client/navigation/linkResolver.js +22 -11
- package/src/client/support/drawerPresentation.js +13 -1
- package/test/adaptiveShell.browser.test.js +178 -0
- package/test/documentNavigation.test.js +44 -0
- package/test/drawerPresentation.test.js +13 -1
- package/test/linkResolver.test.js +50 -1
- package/test/settingsPlacementContract.test.js +19 -3
|
@@ -1,18 +1,5 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
-
import {
|
|
3
|
-
import { useRoute } from "vue-router";
|
|
4
|
-
import { useDisplay } from "vuetify";
|
|
5
|
-
import {
|
|
6
|
-
useWebPlacementContext,
|
|
7
|
-
useWebPlacementRevision,
|
|
8
|
-
useWebPlacementRuntime
|
|
9
|
-
} from "../placement/inject.js";
|
|
10
|
-
import { resolveRuntimePathname } from "../placement/pathname.js";
|
|
11
|
-
import {
|
|
12
|
-
readPlacementSurfaceConfig,
|
|
13
|
-
resolveSurfaceIdFromPlacementPathname
|
|
14
|
-
} from "../placement/surfaceContext.js";
|
|
15
|
-
import { resolveShellLayoutClass } from "../support/shellLayoutClass.js";
|
|
2
|
+
import { useShellOutletPlacements } from "../composables/useShellOutletPlacements.js";
|
|
16
3
|
import { useJskitText } from "../i18n.js";
|
|
17
4
|
|
|
18
5
|
const props = defineProps({
|
|
@@ -30,8 +17,6 @@ const props = defineProps({
|
|
|
30
17
|
}
|
|
31
18
|
});
|
|
32
19
|
|
|
33
|
-
const route = useRoute();
|
|
34
|
-
const display = useDisplay();
|
|
35
20
|
const { text } = useJskitText();
|
|
36
21
|
const TRANSLATED_PLACEMENT_PROPS = Object.freeze(["label", "title"]);
|
|
37
22
|
|
|
@@ -51,40 +36,7 @@ function placementProps(entry) {
|
|
|
51
36
|
return translated;
|
|
52
37
|
}
|
|
53
38
|
|
|
54
|
-
const
|
|
55
|
-
const { context: placementContext } = useWebPlacementContext();
|
|
56
|
-
const revision = useWebPlacementRevision(placementRuntime);
|
|
57
|
-
|
|
58
|
-
const resolvedSurface = computed(() => {
|
|
59
|
-
const contextValue = placementContext.value;
|
|
60
|
-
const pathname = resolveRuntimePathname(route.path);
|
|
61
|
-
const surfaceFromPathname = resolveSurfaceIdFromPlacementPathname(contextValue, pathname);
|
|
62
|
-
if (surfaceFromPathname) {
|
|
63
|
-
return surfaceFromPathname;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const surfaceConfig = readPlacementSurfaceConfig(contextValue);
|
|
67
|
-
if (surfaceConfig.defaultSurfaceId) {
|
|
68
|
-
return surfaceConfig.defaultSurfaceId;
|
|
69
|
-
}
|
|
70
|
-
return "*";
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
const resolvedTargetId = computed(() => {
|
|
74
|
-
return String(props.target || "").trim();
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
const resolvedLayoutClass = computed(() => resolveShellLayoutClass(display.width.value));
|
|
78
|
-
|
|
79
|
-
const placements = computed(() => {
|
|
80
|
-
void revision.value;
|
|
81
|
-
return placementRuntime.getPlacements({
|
|
82
|
-
surface: resolvedSurface.value,
|
|
83
|
-
target: resolvedTargetId.value,
|
|
84
|
-
layoutClass: resolvedLayoutClass.value,
|
|
85
|
-
context: props.context
|
|
86
|
-
});
|
|
87
|
-
});
|
|
39
|
+
const placements = useShellOutletPlacements(() => props.target, () => props.context);
|
|
88
40
|
</script>
|
|
89
41
|
|
|
90
42
|
<template>
|
|
@@ -7,8 +7,8 @@ import {
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* The app bar's actions target. The current page's actions show in the shell's top app bar after the page title
|
|
10
|
-
* (Material 3 puts a page's actions there); put ShellPageAction buttons inside. Outside a
|
|
11
|
-
* where they are written.
|
|
10
|
+
* (Material 3 puts a page's actions there); put ShellPageAction buttons inside. Outside a layout that owns the top
|
|
11
|
+
* app bar (ShellLayout, or one that calls useShellAppBar()) they render where they are written.
|
|
12
12
|
* @type {string}
|
|
13
13
|
*/
|
|
14
14
|
const target = inject(SHELL_PAGE_ACTIONS_TARGET_KEY, NO_SHELL_PAGE_ACTIONS_TARGET);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { SHELL_PAGE_ACTIONS_ID } from "../support/navigationPresentation.js";
|
|
3
|
+
|
|
4
|
+
// Where the current page's ShellPageActions show: after the page title in the top app bar. ShellLayout's bar has it;
|
|
5
|
+
// a layout that draws its own top app bar renders it once there and calls useShellAppBar().
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
<template>
|
|
9
|
+
<div :id="SHELL_PAGE_ACTIONS_ID" class="shell-page-actions-target" />
|
|
10
|
+
</template>
|
|
11
|
+
|
|
12
|
+
<style scoped>
|
|
13
|
+
.shell-page-actions-target {
|
|
14
|
+
align-items: center;
|
|
15
|
+
color: rgb(var(--v-theme-on-surface-variant));
|
|
16
|
+
display: flex;
|
|
17
|
+
flex: 0 0 auto;
|
|
18
|
+
min-width: 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.shell-page-actions-target:empty {
|
|
22
|
+
display: none;
|
|
23
|
+
}
|
|
24
|
+
</style>
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { computed } from "vue";
|
|
3
|
+
import { useRoute } from "vue-router";
|
|
4
|
+
import { useJskitText } from "../i18n.js";
|
|
5
|
+
import { PAGE_TITLE_ID, resolvePageTitle } from "../navigation/shellNavigationRuntime.js";
|
|
6
|
+
import { useShellNavigationRuntime } from "../navigation/useShellNavigation.js";
|
|
7
|
+
|
|
8
|
+
// The page's one h1, in the top app bar: the title the page sets (useShellPageTitle), else its route's
|
|
9
|
+
// meta.jskit.title, else `title`. The shell moves focus here after navigation. ShellLayout's bar shows it; a layout
|
|
10
|
+
// that draws its own top app bar renders it once in that bar. Its default slot, given `{ title }`, replaces the text
|
|
11
|
+
// inside the h1, such as a menu activator for a title that is also a switcher; the h1, its id and its focus stay.
|
|
12
|
+
const props = defineProps({
|
|
13
|
+
// The title of pages that declare none and set none. A message key or plain text.
|
|
14
|
+
title: {
|
|
15
|
+
type: String,
|
|
16
|
+
default: ""
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const { text } = useJskitText();
|
|
21
|
+
const route = useRoute();
|
|
22
|
+
const navigationRuntime = useShellNavigationRuntime();
|
|
23
|
+
const pageTitle = computed(() => {
|
|
24
|
+
const source = navigationRuntime.pageTitleSource.value;
|
|
25
|
+
const runtimeTitle = typeof source === "function" ? source() : "";
|
|
26
|
+
return text(runtimeTitle) || text(resolvePageTitle(route.matched)) || text(props.title);
|
|
27
|
+
});
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<template>
|
|
31
|
+
<h1 :id="PAGE_TITLE_ID" class="shell-page-title" tabindex="-1" data-testid="jskit-shell-page-title">
|
|
32
|
+
<slot :title="pageTitle">{{ pageTitle }}</slot>
|
|
33
|
+
</h1>
|
|
34
|
+
</template>
|
|
35
|
+
|
|
36
|
+
<style scoped>
|
|
37
|
+
/* Material 3 small top app bar headline: title-large. */
|
|
38
|
+
.shell-page-title {
|
|
39
|
+
color: rgb(var(--v-theme-on-surface));
|
|
40
|
+
font-size: 1.375rem;
|
|
41
|
+
font-weight: 400;
|
|
42
|
+
letter-spacing: 0;
|
|
43
|
+
line-height: 1.75rem;
|
|
44
|
+
margin: 0;
|
|
45
|
+
outline: none;
|
|
46
|
+
/* Clipped sideways only, so a menu activator in the slot keeps its 48dp touch target above and below. */
|
|
47
|
+
overflow-x: clip;
|
|
48
|
+
overflow-y: visible;
|
|
49
|
+
text-overflow: ellipsis;
|
|
50
|
+
white-space: nowrap;
|
|
51
|
+
}
|
|
52
|
+
</style>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { useJskitText } from "../i18n.js";
|
|
3
|
+
import { useShellNavigation } from "../navigation/useShellNavigation.js";
|
|
4
|
+
|
|
5
|
+
// The top app bar's Up arrow. On an inner page (one that declares meta.jskit.parent) it returns to where the person
|
|
6
|
+
// came from or else to that parent, through JSKIT navigation; on a top-level page it renders nothing. ShellLayout's
|
|
7
|
+
// bar shows it; a layout that draws its own top app bar puts it first in that bar and calls useShellAppBar().
|
|
8
|
+
const { t } = useJskitText();
|
|
9
|
+
const { canGoUp, up } = useShellNavigation();
|
|
10
|
+
|
|
11
|
+
function goUp() {
|
|
12
|
+
void up();
|
|
13
|
+
}
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<template>
|
|
17
|
+
<v-btn
|
|
18
|
+
v-if="canGoUp"
|
|
19
|
+
icon
|
|
20
|
+
variant="text"
|
|
21
|
+
color="on-surface"
|
|
22
|
+
data-testid="jskit-shell-back"
|
|
23
|
+
:aria-label="t('jskit.shell.actions.back')"
|
|
24
|
+
@click="goUp"
|
|
25
|
+
>
|
|
26
|
+
<v-icon icon="$arrowBack" />
|
|
27
|
+
<v-tooltip activator="parent" location="bottom" :text="t('jskit.shell.actions.back')" />
|
|
28
|
+
</v-btn>
|
|
29
|
+
</template>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { onBeforeUnmount, onMounted, provide } from "vue";
|
|
2
|
+
import { useShellNavigationRuntime } from "../navigation/useShellNavigation.js";
|
|
3
|
+
import { SHELL_PAGE_ACTIONS_ID, SHELL_PAGE_ACTIONS_TARGET_KEY } from "../support/navigationPresentation.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Makes the calling layout the owner of the shell's top app bar: the pages it renders enter the navigation trail, so
|
|
7
|
+
* Up returns to where a page was opened from, and their ShellPageActions show in its ShellPageActionsTarget.
|
|
8
|
+
* ShellLayout calls it. A layout that draws its own top app bar calls it once and renders ShellUpButton,
|
|
9
|
+
* ShellPageTitle and ShellPageActionsTarget in that bar.
|
|
10
|
+
*/
|
|
11
|
+
function useShellAppBar() {
|
|
12
|
+
const navigationRuntime = useShellNavigationRuntime();
|
|
13
|
+
let release = null;
|
|
14
|
+
|
|
15
|
+
provide(SHELL_PAGE_ACTIONS_TARGET_KEY, `#${SHELL_PAGE_ACTIONS_ID}`);
|
|
16
|
+
|
|
17
|
+
onMounted(() => {
|
|
18
|
+
release = navigationRuntime.attachShell();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
onBeforeUnmount(() => {
|
|
22
|
+
release?.();
|
|
23
|
+
release = null;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { useShellAppBar };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { computed, toValue } from "vue";
|
|
2
|
+
import { useRoute } from "vue-router";
|
|
3
|
+
import { useDisplay } from "vuetify";
|
|
4
|
+
import {
|
|
5
|
+
useWebPlacementContext,
|
|
6
|
+
useWebPlacementRevision,
|
|
7
|
+
useWebPlacementRuntime
|
|
8
|
+
} from "../placement/inject.js";
|
|
9
|
+
import { resolveRuntimePathname } from "../placement/pathname.js";
|
|
10
|
+
import {
|
|
11
|
+
readPlacementSurfaceConfig,
|
|
12
|
+
resolveSurfaceIdFromPlacementPathname
|
|
13
|
+
} from "../placement/surfaceContext.js";
|
|
14
|
+
import { resolveShellLayoutClass } from "../support/shellLayoutClass.js";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The placements an outlet renders on the current surface and window size class: ShellOutlet draws them, and
|
|
18
|
+
* ShellLayout checks which navigation outlets have any.
|
|
19
|
+
* @param {import("vue").MaybeRefOrGetter<string>} target
|
|
20
|
+
* @param {import("vue").MaybeRefOrGetter<Record<string, unknown>>} [context]
|
|
21
|
+
*/
|
|
22
|
+
function useShellOutletPlacements(target, context = {}) {
|
|
23
|
+
const route = useRoute();
|
|
24
|
+
const display = useDisplay();
|
|
25
|
+
const placementRuntime = useWebPlacementRuntime();
|
|
26
|
+
const { context: placementContext } = useWebPlacementContext();
|
|
27
|
+
const revision = useWebPlacementRevision(placementRuntime);
|
|
28
|
+
|
|
29
|
+
const surface = computed(() => {
|
|
30
|
+
const contextValue = placementContext.value;
|
|
31
|
+
const surfaceFromPathname = resolveSurfaceIdFromPlacementPathname(contextValue, resolveRuntimePathname(route.path));
|
|
32
|
+
if (surfaceFromPathname) {
|
|
33
|
+
return surfaceFromPathname;
|
|
34
|
+
}
|
|
35
|
+
return readPlacementSurfaceConfig(contextValue).defaultSurfaceId || "*";
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return computed(() => {
|
|
39
|
+
void revision.value;
|
|
40
|
+
return placementRuntime.getPlacements({
|
|
41
|
+
surface: surface.value,
|
|
42
|
+
target: String(toValue(target) || "").trim(),
|
|
43
|
+
layoutClass: resolveShellLayoutClass(display.width.value),
|
|
44
|
+
context: toValue(context)
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { useShellOutletPlacements };
|
package/src/client/index.js
CHANGED
|
@@ -13,6 +13,10 @@ export { default as ShellTabLinkItem } from "./components/ShellTabLinkItem.vue";
|
|
|
13
13
|
export { default as ShellPageActions } from "./components/ShellPageActions.vue";
|
|
14
14
|
export { default as ShellPageAction } from "./components/ShellPageAction.vue";
|
|
15
15
|
export { default as ShellListDetail } from "./components/ShellListDetail.vue";
|
|
16
|
+
export { default as ShellUpButton } from "./components/ShellUpButton.vue";
|
|
17
|
+
export { default as ShellPageTitle } from "./components/ShellPageTitle.vue";
|
|
18
|
+
export { default as ShellPageActionsTarget } from "./components/ShellPageActionsTarget.vue";
|
|
19
|
+
export { useShellAppBar } from "./composables/useShellAppBar.js";
|
|
16
20
|
export { useShellLayoutState } from "./composables/useShellLayoutState.js";
|
|
17
21
|
export { useShellPageTitle } from "./composables/useShellPageTitle.js";
|
|
18
22
|
export { useShellWindowSizeClass } from "./composables/useShellWindowSizeClass.js";
|
|
@@ -17,10 +17,12 @@ function reloadAppPage(target) {
|
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Leaves the app for another site in the same tab, such as a payment provider's checkout. External pages never enter
|
|
20
|
-
* the trail.
|
|
20
|
+
* the trail. The site is opened with a push, so Back returns to the page that left; a hand-off page that only forwards
|
|
21
|
+
* (to an OAuth provider's consent screen) passes `{ replace: true }`, so Back from the site doesn't rerun the hand-off.
|
|
21
22
|
* @param {string} url An absolute http(s) URL on another origin.
|
|
23
|
+
* @param {{ replace?: boolean }} [options] replace: the site takes the current history entry's place.
|
|
22
24
|
*/
|
|
23
|
-
function leaveApp(url) {
|
|
25
|
+
function leaveApp(url, { replace = false } = {}) {
|
|
24
26
|
const windowRef = pageWindow();
|
|
25
27
|
const target = String(url || "").trim();
|
|
26
28
|
let parsed = null;
|
|
@@ -32,7 +34,8 @@ function leaveApp(url) {
|
|
|
32
34
|
if (!parsed || !/^https?:$/u.test(parsed.protocol) || (windowRef && parsed.origin === windowRef.location.origin)) {
|
|
33
35
|
throw new TypeError(`leaveApp() takes another site's http(s) URL, not "${target}"; navigate in-app pages with the router.`);
|
|
34
36
|
}
|
|
35
|
-
windowRef?.location.
|
|
37
|
+
if (replace) windowRef?.location.replace(parsed.href);
|
|
38
|
+
else windowRef?.location.assign(parsed.href);
|
|
36
39
|
}
|
|
37
40
|
|
|
38
41
|
export { leaveApp, reloadAppPage };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { unref } from "vue";
|
|
2
2
|
import { resolveLinkPath, normalizePathname } from "@jskit-ai/kernel/shared";
|
|
3
|
+
import { isExternalLinkTarget } from "@jskit-ai/kernel/shared/support/linkPath";
|
|
3
4
|
import { normalizeSurfaceId } from "@jskit-ai/kernel/shared/surface/registry";
|
|
4
5
|
import { useWebPlacementContext } from "../placement/inject.js";
|
|
5
6
|
import {
|
|
@@ -8,36 +9,40 @@ import {
|
|
|
8
9
|
} from "../placement/surfaceContext.js";
|
|
9
10
|
import { normalizeRouteParams } from "../support/routeParams.js";
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
// Fills each `:name` segment of a path from params. A param the params lack throws when strict and otherwise stays as
|
|
13
|
+
// written. Only a path segment that starts with ":" is a param; a query and a hash are left alone.
|
|
14
|
+
function fillPathParams(pathTemplate = "/", { params = {}, strictParams = true, label = "route params" } = {}) {
|
|
15
|
+
const template = String(pathTemplate || "/");
|
|
16
|
+
const suffixStart = template.search(/[?#]/u);
|
|
17
|
+
const pathPart = suffixStart < 0 ? template : template.slice(0, suffixStart);
|
|
18
|
+
const suffix = suffixStart < 0 ? "" : template.slice(suffixStart);
|
|
12
19
|
const normalizedParams = normalizeRouteParams(params);
|
|
13
20
|
const missingParams = new Set();
|
|
14
|
-
const outputPath =
|
|
15
|
-
const paramName = String(rawName || "").trim();
|
|
21
|
+
const outputPath = pathPart.replace(/(^|\/):([A-Za-z0-9_]+)/g, (full, start, paramName) => {
|
|
16
22
|
const paramValue = normalizedParams[paramName];
|
|
17
23
|
if (!paramValue) {
|
|
18
24
|
missingParams.add(paramName);
|
|
19
|
-
return
|
|
25
|
+
return full;
|
|
20
26
|
}
|
|
21
|
-
return encodeURIComponent(paramValue)
|
|
27
|
+
return `${start}${encodeURIComponent(paramValue)}`;
|
|
22
28
|
});
|
|
23
29
|
|
|
24
30
|
if (strictParams && missingParams.size > 0) {
|
|
25
|
-
const surfaceLabel = String(surface || "").trim() || "(default)";
|
|
26
31
|
const missing = [...missingParams].sort().join(", ");
|
|
27
|
-
throw new Error(`Missing required
|
|
32
|
+
throw new Error(`Missing required ${label}: ${missing}.`);
|
|
28
33
|
}
|
|
29
34
|
|
|
30
|
-
return outputPath
|
|
35
|
+
return `${outputPath}${suffix}`;
|
|
31
36
|
}
|
|
32
37
|
|
|
33
38
|
function resolveSurfaceBasePath(context = null, surface = "", { params = {}, strictParams = true } = {}) {
|
|
34
39
|
const normalizedSurface = normalizeSurfaceId(surface);
|
|
35
40
|
if (normalizedSurface && resolveSurfaceDefinitionFromPlacementContext(context, normalizedSurface)) {
|
|
36
41
|
const routeBaseTemplate = resolveSurfaceRootPathFromPlacementContext(context, normalizedSurface);
|
|
37
|
-
return
|
|
42
|
+
return fillPathParams(routeBaseTemplate, {
|
|
38
43
|
params,
|
|
39
44
|
strictParams,
|
|
40
|
-
|
|
45
|
+
label: `surface route params for "${normalizedSurface}"`
|
|
41
46
|
});
|
|
42
47
|
}
|
|
43
48
|
|
|
@@ -69,7 +74,13 @@ function resolveShellLinkPath({
|
|
|
69
74
|
strictParams
|
|
70
75
|
});
|
|
71
76
|
|
|
72
|
-
|
|
77
|
+
// A relative path may name params too, like a declared parent "/books/:bookId"; they fill from the same params.
|
|
78
|
+
// An external URL is another site's, so it stays as written.
|
|
79
|
+
const filledRelativePath = isExternalLinkTarget(nextRelativePath)
|
|
80
|
+
? nextRelativePath
|
|
81
|
+
: fillPathParams(nextRelativePath, { params, strictParams, label: `route params for "${nextRelativePath}"` });
|
|
82
|
+
|
|
83
|
+
return resolveLinkPath(nextSurfaceBasePath, filledRelativePath);
|
|
73
84
|
}
|
|
74
85
|
|
|
75
86
|
/**
|
|
@@ -58,9 +58,21 @@ function resolveShellDrawerToggleLabel({ modal = false, open = false } = {}) {
|
|
|
58
58
|
return open ? t("jskit.shell.layout.collapseNavigationDrawer") : t("jskit.shell.layout.expandNavigationDrawer");
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Whether a surface has a drawer (and so a rail and a menu control): it has one when it has menu destinations or its
|
|
63
|
+
* own menu. The surface identity (a workspace switcher) keeps it only beside navigation, as on a phone whose
|
|
64
|
+
* destinations are all in the navigation bar; a surface with no navigation at all, such as an account surface, has
|
|
65
|
+
* none.
|
|
66
|
+
* @param {{ menuSlot?: boolean, menuCount?: number, identityCount?: number, bottomNavigationCount?: number }} outlets
|
|
67
|
+
*/
|
|
68
|
+
function shellLayoutHasDrawer({ menuSlot = false, menuCount = 0, identityCount = 0, bottomNavigationCount = 0 } = {}) {
|
|
69
|
+
return menuSlot || menuCount > 0 || (identityCount > 0 && bottomNavigationCount > 0);
|
|
70
|
+
}
|
|
71
|
+
|
|
61
72
|
export {
|
|
62
73
|
DESKTOP_DRAWER_CLOSED_MODES,
|
|
63
74
|
normalizeDesktopDrawerClosedMode,
|
|
64
75
|
resolveShellDrawerPresentation,
|
|
65
|
-
resolveShellDrawerToggleLabel
|
|
76
|
+
resolveShellDrawerToggleLabel,
|
|
77
|
+
shellLayoutHasDrawer
|
|
66
78
|
};
|
|
@@ -452,6 +452,179 @@ test("shell-web's app bar fills with surface-container once the page scrolls und
|
|
|
452
452
|
}
|
|
453
453
|
});
|
|
454
454
|
|
|
455
|
+
test("shell-web's bar pieces give a layout that draws its own top app bar the shell's Up, title and actions", {
|
|
456
|
+
skip: RUN_BROWSER_TEST ? false : "set JSKIT_SHELL_WEB_BROWSER_INTEGRATION=1",
|
|
457
|
+
timeout: 120_000
|
|
458
|
+
}, async () => {
|
|
459
|
+
const vite = await startViteFixture({ fixtureRoot: FIXTURE_ROOT });
|
|
460
|
+
let browser;
|
|
461
|
+
try {
|
|
462
|
+
browser = await chromium.launch(createChromiumLaunchOptions());
|
|
463
|
+
for (const viewport of DEFAULT_VIEWPORTS) {
|
|
464
|
+
const page = await browser.newPage({
|
|
465
|
+
baseURL: vite.baseURL,
|
|
466
|
+
viewport: { width: viewport.width, height: viewport.height }
|
|
467
|
+
});
|
|
468
|
+
const at = `${viewport.width}px`;
|
|
469
|
+
const ownBar = page.getByTestId("fixture-own-bar");
|
|
470
|
+
|
|
471
|
+
// A top-level page: the title is the page's one h1, in the app's own bar, with no arrow.
|
|
472
|
+
await page.goto("/home/studio");
|
|
473
|
+
await expect(ownBar.getByRole("heading", { level: 1, name: "Studio" }), at).toBeVisible();
|
|
474
|
+
await expect(page.getByRole("heading", { level: 1 }), at).toHaveCount(1);
|
|
475
|
+
await expect(shellBackButton(page), at).toHaveCount(0);
|
|
476
|
+
// A title that is also a switcher: the menu activator is inside the h1, which keeps its id and focus target.
|
|
477
|
+
const title = ownBar.getByRole("heading", { level: 1 });
|
|
478
|
+
await expect(title, at).toHaveAttribute("id", "jskit-shell-page-title");
|
|
479
|
+
await expect(title, at).toHaveAttribute("tabindex", "-1");
|
|
480
|
+
await title.getByRole("button", { name: "Studio" }).click();
|
|
481
|
+
await expect(page.getByText("Other studio", { exact: true }), at).toBeVisible();
|
|
482
|
+
await page.keyboard.press("Escape");
|
|
483
|
+
await expect(page.getByText("Other studio", { exact: true }), at).toBeHidden();
|
|
484
|
+
|
|
485
|
+
// An inner page: Up, its title and its actions, in the app's own bar; Up returns along the trail.
|
|
486
|
+
await page.getByRole("link", { name: "Ada Lovelace", exact: true }).click();
|
|
487
|
+
await expect(page).toHaveURL(/\/home\/studio\/ada$/u);
|
|
488
|
+
await expect(ownBar.getByTestId("jskit-shell-page-title"), at).toHaveText("Ada Lovelace");
|
|
489
|
+
await expect(ownBar.getByTestId("jskit-shell-back"), at).toHaveAccessibleName("Back");
|
|
490
|
+
await expect(ownBar.getByRole("button", { name: "Run" }), at).toBeVisible();
|
|
491
|
+
await pressShellBack(page);
|
|
492
|
+
await expect(page).toHaveURL(/\/home\/studio$/u);
|
|
493
|
+
await expect(shellBackButton(page), at).toHaveCount(0);
|
|
494
|
+
|
|
495
|
+
// A pasted link goes Up to the declared parent.
|
|
496
|
+
await page.goto("/home/studio/ada");
|
|
497
|
+
await pressShellBack(page);
|
|
498
|
+
await expect(page).toHaveURL(/\/home\/studio$/u);
|
|
499
|
+
await page.close();
|
|
500
|
+
}
|
|
501
|
+
} finally {
|
|
502
|
+
await browser?.close();
|
|
503
|
+
await stopProcess(vite);
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
test("a surface with no navigation draws no navigation bar, rail, drawer or menu control", {
|
|
508
|
+
skip: RUN_BROWSER_TEST ? false : "set JSKIT_SHELL_WEB_BROWSER_INTEGRATION=1",
|
|
509
|
+
timeout: 120_000
|
|
510
|
+
}, async () => {
|
|
511
|
+
const vite = await startViteFixture({ fixtureRoot: FIXTURE_ROOT });
|
|
512
|
+
let browser;
|
|
513
|
+
try {
|
|
514
|
+
browser = await chromium.launch(createChromiumLaunchOptions());
|
|
515
|
+
const navigation = { compact: "jskit-shell-bottom-nav", medium: "jskit-shell-rail", expanded: "jskit-shell-drawer" };
|
|
516
|
+
for (const viewport of DEFAULT_VIEWPORTS) {
|
|
517
|
+
const page = await browser.newPage({
|
|
518
|
+
baseURL: vite.baseURL,
|
|
519
|
+
viewport: { width: viewport.width, height: viewport.height }
|
|
520
|
+
});
|
|
521
|
+
const at = `${viewport.width}px`;
|
|
522
|
+
await page.goto("/account");
|
|
523
|
+
await expect(shellPageTitle(page), at).toHaveText("Account");
|
|
524
|
+
for (const id of ["jskit-shell-bottom-nav", "jskit-shell-rail", "jskit-shell-drawer", "jskit-shell-nav-toggle"]) {
|
|
525
|
+
await expect(page.getByTestId(id), `${at} ${id}`).toHaveCount(0);
|
|
526
|
+
}
|
|
527
|
+
assert.equal(Math.round((await page.locator("main").boundingBox()).x), 0, `${at}: the page starts at the window's edge`);
|
|
528
|
+
// Its title and Up stay in the app bar; Up returns to the declared parent on another surface, which has navigation.
|
|
529
|
+
await pressShellBack(page);
|
|
530
|
+
await expect(page).toHaveURL(/\/home$/u);
|
|
531
|
+
await expect(page.getByTestId(navigation[viewport.name]), at).toBeVisible();
|
|
532
|
+
await page.close();
|
|
533
|
+
}
|
|
534
|
+
} finally {
|
|
535
|
+
await browser?.close();
|
|
536
|
+
await stopProcess(vite);
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
test("every button keeps its size, gets a 48dp touch target and ends a long label in an ellipsis; FABs and cards keep theirs", {
|
|
541
|
+
skip: RUN_BROWSER_TEST ? false : "set JSKIT_SHELL_WEB_BROWSER_INTEGRATION=1",
|
|
542
|
+
timeout: 90_000
|
|
543
|
+
}, async () => {
|
|
544
|
+
const vite = await startViteFixture({ fixtureRoot: FIXTURE_ROOT });
|
|
545
|
+
let browser;
|
|
546
|
+
try {
|
|
547
|
+
browser = await chromium.launch(createChromiumLaunchOptions());
|
|
548
|
+
const page = await browser.newPage({ baseURL: vite.baseURL, viewport: { width: 1280, height: 900 } });
|
|
549
|
+
await page.goto("/home/buttons");
|
|
550
|
+
// Vuetify's heights for x-small, small and large, JSKIT's 40dp default; an icon button is 12dp more, JSKIT's 40dp.
|
|
551
|
+
const heights = {
|
|
552
|
+
"x-small": [20, 32],
|
|
553
|
+
small: [28, 40],
|
|
554
|
+
default: [40, 40],
|
|
555
|
+
large: [44, 56]
|
|
556
|
+
};
|
|
557
|
+
for (const [size, [textHeight, iconHeight]] of Object.entries(heights)) {
|
|
558
|
+
for (const [id, height] of [[`fixture-button-${size}`, textHeight], [`fixture-icon-button-${size}`, iconHeight]]) {
|
|
559
|
+
const button = page.getByTestId(id);
|
|
560
|
+
const box = await button.boundingBox();
|
|
561
|
+
assert.equal(Math.round(box.height), height, `${id} keeps its visual height`);
|
|
562
|
+
const target = await button.evaluate((element) => {
|
|
563
|
+
const style = window.getComputedStyle(element, "::before");
|
|
564
|
+
return { width: Number.parseFloat(style.width), height: Number.parseFloat(style.height) };
|
|
565
|
+
});
|
|
566
|
+
assert.equal(Math.round(target.height), Math.max(48, height), `${id} touch target height`);
|
|
567
|
+
assert.ok(target.width >= 48, `${id} touch target width ${target.width}`);
|
|
568
|
+
if (height < 48) {
|
|
569
|
+
// A tap just above the visual, inside the touch target, reaches the button.
|
|
570
|
+
const point = [box.x + box.width / 2, box.y - (48 - height) / 2 + 1];
|
|
571
|
+
const hit = await page.evaluate(([x, y]) => document.elementFromPoint(x, y)?.closest(".v-btn")?.dataset.testid, point);
|
|
572
|
+
assert.equal(hit, id, `${id} answers inside its touch target`);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
const long = page.getByTestId("fixture-long-label");
|
|
577
|
+
const label = await long.evaluate((element) => {
|
|
578
|
+
const content = element.querySelector(".v-btn__content");
|
|
579
|
+
const style = window.getComputedStyle(content);
|
|
580
|
+
return {
|
|
581
|
+
buttonWidth: element.getBoundingClientRect().width,
|
|
582
|
+
buttonRight: element.getBoundingClientRect().right,
|
|
583
|
+
contentRight: content.getBoundingClientRect().right,
|
|
584
|
+
clipped: content.scrollWidth > content.clientWidth,
|
|
585
|
+
textOverflow: style.textOverflow,
|
|
586
|
+
height: element.getBoundingClientRect().height
|
|
587
|
+
};
|
|
588
|
+
});
|
|
589
|
+
assert.ok(label.buttonWidth <= 160.5, `the long button stays in its 160px (${label.buttonWidth})`);
|
|
590
|
+
assert.ok(label.contentRight <= label.buttonRight + 0.5, "the label stays inside its button");
|
|
591
|
+
assert.equal(label.clipped, true);
|
|
592
|
+
assert.equal(label.textOverflow, "ellipsis");
|
|
593
|
+
assert.equal(Math.round(label.height), 40, "the label stays on one line");
|
|
594
|
+
// A touch target reaching past a scroll container's corner adds no scrollbar.
|
|
595
|
+
const corner = await page.getByTestId("fixture-button-corner").evaluate((element) => ({
|
|
596
|
+
extraWidth: element.scrollWidth - element.clientWidth,
|
|
597
|
+
extraHeight: element.scrollHeight - element.clientHeight
|
|
598
|
+
}));
|
|
599
|
+
assert.deepEqual(corner, { extraWidth: 0, extraHeight: 0 });
|
|
600
|
+
// FABs keep Material 3's sizes, not the common button's 40dp.
|
|
601
|
+
for (const [id, width, height] of [
|
|
602
|
+
["fixture-fab", 56, 56],
|
|
603
|
+
["fixture-fab-small", 40, 40],
|
|
604
|
+
["fixture-fab-large", 96, 96],
|
|
605
|
+
["fixture-fab-extended", null, 56]
|
|
606
|
+
]) {
|
|
607
|
+
const box = await page.getByTestId(id).locator(".v-btn").boundingBox();
|
|
608
|
+
assert.equal(Math.round(box.height), height, `${id} height`);
|
|
609
|
+
if (width) assert.equal(Math.round(box.width), width, `${id} width`);
|
|
610
|
+
}
|
|
611
|
+
// An elevated card has its level-1 shadow; flat and tonal cards have none.
|
|
612
|
+
const shadows = {};
|
|
613
|
+
for (const variant of ["elevated", "flat", "tonal"]) {
|
|
614
|
+
shadows[variant] = await page.getByTestId(`fixture-card-${variant}`).evaluate((element) => window.getComputedStyle(element).boxShadow);
|
|
615
|
+
}
|
|
616
|
+
// A shadow of zero offsets, blur and spread (Vuetify's level 0) draws nothing.
|
|
617
|
+
const drawsShadow = (shadow) => shadow !== "none" &&
|
|
618
|
+
shadow.replace(/rgba?\([^)]*\)/gu, "").split(/[\s,]+/u).some((length) => Number.parseFloat(length) > 0);
|
|
619
|
+
assert.equal(drawsShadow(shadows.elevated), true, shadows.elevated);
|
|
620
|
+
assert.deepEqual([drawsShadow(shadows.flat), drawsShadow(shadows.tonal)], [false, false], JSON.stringify(shadows));
|
|
621
|
+
await page.close();
|
|
622
|
+
} finally {
|
|
623
|
+
await browser?.close();
|
|
624
|
+
await stopProcess(vite);
|
|
625
|
+
}
|
|
626
|
+
});
|
|
627
|
+
|
|
455
628
|
async function openMainDestination(page, label) {
|
|
456
629
|
await page.getByRole("link", { name: label, exact: true }).filter({ visible: true }).first().click();
|
|
457
630
|
}
|
|
@@ -549,6 +722,11 @@ test("shell-web Up follows the tab's trail, falls back to the parent and returns
|
|
|
549
722
|
await pressShellBack(pasted);
|
|
550
723
|
await expect(pasted).toHaveURL(/\/home\/suppliers$/u);
|
|
551
724
|
await expect(shellPageTitle(pasted)).toHaveText("Suppliers");
|
|
725
|
+
// A pasted edit link goes Up to its record: the parent "/contacts/:id" takes the id from the route.
|
|
726
|
+
await pasted.goto("/home/contacts/ada/edit");
|
|
727
|
+
await expect(shellPageTitle(pasted)).toHaveText("Edit contact");
|
|
728
|
+
await pressShellBack(pasted);
|
|
729
|
+
await expect(pasted).toHaveURL(/\/home\/contacts\/ada$/u);
|
|
552
730
|
await pasted.close();
|
|
553
731
|
|
|
554
732
|
// List-detail: beside the visible list, General has no arrow; alone, it has one back to the list.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { leaveApp, reloadAppPage } from "../src/client/navigation/documentNavigation.js";
|
|
4
|
+
|
|
5
|
+
// A window whose location records each full load: [method, url].
|
|
6
|
+
function withWindow(run) {
|
|
7
|
+
const loads = [];
|
|
8
|
+
const previous = globalThis.window;
|
|
9
|
+
globalThis.window = {
|
|
10
|
+
location: {
|
|
11
|
+
origin: "https://app.example.com",
|
|
12
|
+
assign: (url) => loads.push(["assign", url]),
|
|
13
|
+
replace: (url) => loads.push(["replace", url])
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
try {
|
|
17
|
+
run(loads);
|
|
18
|
+
} finally {
|
|
19
|
+
if (previous === undefined) delete globalThis.window;
|
|
20
|
+
else globalThis.window = previous;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
test("leaveApp opens another site with a push, or in the current entry's place with { replace: true }", () => {
|
|
25
|
+
withWindow((loads) => {
|
|
26
|
+
leaveApp("https://pay.example.org/checkout?session=1");
|
|
27
|
+
leaveApp("https://auth.example.org/consent", { replace: true });
|
|
28
|
+
assert.deepEqual(loads, [
|
|
29
|
+
["assign", "https://pay.example.org/checkout?session=1"],
|
|
30
|
+
["replace", "https://auth.example.org/consent"]
|
|
31
|
+
]);
|
|
32
|
+
assert.throws(() => leaveApp("https://app.example.com/home", { replace: true }), /another site's http\(s\) URL/u);
|
|
33
|
+
assert.throws(() => leaveApp("/home"), /another site's http\(s\) URL/u);
|
|
34
|
+
assert.equal(loads.length, 2);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("reloadAppPage reloads an in-app path in the current entry's place", () => {
|
|
39
|
+
withWindow((loads) => {
|
|
40
|
+
reloadAppPage("/home/projects");
|
|
41
|
+
assert.deepEqual(loads, [["replace", "/home/projects"]]);
|
|
42
|
+
assert.throws(() => reloadAppPage("https://pay.example.org/"), /use leaveApp\(\)/u);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -3,7 +3,8 @@ import test from "node:test";
|
|
|
3
3
|
import {
|
|
4
4
|
normalizeDesktopDrawerClosedMode,
|
|
5
5
|
resolveShellDrawerPresentation,
|
|
6
|
-
resolveShellDrawerToggleLabel
|
|
6
|
+
resolveShellDrawerToggleLabel,
|
|
7
|
+
shellLayoutHasDrawer
|
|
7
8
|
} from "../src/client/support/drawerPresentation.js";
|
|
8
9
|
|
|
9
10
|
test("wide closed navigation defaults to a visible Material navigation rail", () => {
|
|
@@ -66,3 +67,14 @@ test("open navigation renders as a full drawer and labels its toggle responsivel
|
|
|
66
67
|
"Open navigation menu"
|
|
67
68
|
);
|
|
68
69
|
});
|
|
70
|
+
|
|
71
|
+
test("a surface has a drawer with menu destinations or its own menu, and for its identity only beside navigation", () => {
|
|
72
|
+
assert.equal(shellLayoutHasDrawer({ menuCount: 3 }), true);
|
|
73
|
+
assert.equal(shellLayoutHasDrawer({ menuSlot: true }), true);
|
|
74
|
+
// A phone whose destinations are all in the navigation bar keeps the drawer for its workspace switcher.
|
|
75
|
+
assert.equal(shellLayoutHasDrawer({ identityCount: 1, bottomNavigationCount: 3 }), true);
|
|
76
|
+
// An empty drawer is not drawn, nor is one holding only the identity on a surface without navigation.
|
|
77
|
+
assert.equal(shellLayoutHasDrawer({ bottomNavigationCount: 3 }), false);
|
|
78
|
+
assert.equal(shellLayoutHasDrawer({ identityCount: 1 }), false);
|
|
79
|
+
assert.equal(shellLayoutHasDrawer(), false);
|
|
80
|
+
});
|