@jskit-ai/shell-web 0.2.12 → 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 +4 -0
- package/fixtures/adaptive-shell/src/App.vue +6 -3
- package/fixtures/adaptive-shell/src/ButtonsPage.vue +31 -0
- package/fixtures/adaptive-shell/src/OwnBarLayout.vue +13 -1
- package/fixtures/adaptive-shell/src/main.js +97 -37
- package/package.json +2 -2
- package/src/client/components/ShellLayout.vue +27 -6
- package/src/client/components/ShellOutlet.vue +2 -50
- package/src/client/components/ShellPageTitle.vue +6 -3
- package/src/client/composables/useShellOutletPlacements.js +49 -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 +134 -0
- package/test/documentNavigation.test.js +44 -0
- package/test/drawerPresentation.test.js +13 -1
- package/test/linkResolver.test.js +50 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
- The application-shell pattern's not-found view renders in the shell, so the top app bar carries its title and the navigation leads back into the app; the shell foundation has it too.
|
|
8
8
|
- `ShellListDetail` lays out list-detail pages such as settings: the list beside the open detail on expanded windows (with the landing child as the empty detail), one pane at a time on narrower ones. The foundation and shell patterns' settings pages use it instead of redirecting their landing page to the first section.
|
|
9
9
|
- The drawer is 360dp wide by default; `drawerWidth="content"` fits it to its labels. A modal drawer (compact and medium windows) opens over the app bar and closes from its scrim or Escape. The drawer's divider shows only between primary and secondary destinations. The `--shell-chrome-*` custom properties, the rail and drawer item tooltips and `@mdi/js` are gone.
|
|
10
|
+
- A surface draws only the navigation it has: no navigation bar without bar destinations, and no rail, drawer or menu control without menu destinations, as on an account surface whose shell exists for the app bar's title, Up and actions. The surface identity (a workspace switcher) keeps the drawer only beside other navigation, as on a phone whose destinations are all in the navigation bar; a phone surface with neither identity nor secondary destinations loses its empty drawer and menu control.
|
|
11
|
+
- `usePaths().page()`, and every shell link, fills a path's `:name` segments from the current route's params (or the `params` given), so a declared parent such as `/books/:bookId` takes the id on a direct visit to `/books/7/edit` and Up goes to `/books/7`; a missing param throws as a missing surface param does, and Up then goes to the surface's root.
|
|
12
|
+
- `leaveApp(url, { replace: true })` leaves in place of the current history entry, for a hand-off page that only forwards (to an OAuth provider's consent screen), so Back from the site doesn't rerun it; `leaveApp(url)` still pushes.
|
|
13
|
+
- `ShellPageTitle`'s default slot, given `{ title }`, replaces the text inside the h1, so a title that is also a switcher (a project menu) can be the menu's activator and stay the page's one h1, with its id and focus.
|
|
10
14
|
- A layout that draws its own top app bar builds it from the pieces of `ShellLayout`'s bar: `ShellUpButton` (the Up arrow, shown only on inner pages), `ShellPageTitle` (the page's one `h1`) and `ShellPageActionsTarget`, with `useShellAppBar()` once in the layout so its pages enter the trail and their `ShellPageActions` show in its bar. `ShellLayout` is built from the same pieces and looks and behaves as before.
|
|
11
15
|
- Upgrading: see the guide's [Move an app to the Material 3 defaults](https://mobily-enterprises.github.io/jskit-ai/guide/app-setup/material-3-migration).
|
|
12
16
|
|
|
@@ -10,15 +10,18 @@ const route = useRoute();
|
|
|
10
10
|
const theme = useTheme();
|
|
11
11
|
const bare = computed(() => route.meta.bare === true);
|
|
12
12
|
const ownBar = computed(() => route.meta.ownBar === true);
|
|
13
|
-
const surface = computed(() =>
|
|
14
|
-
|
|
13
|
+
const surface = computed(() => {
|
|
14
|
+
if (route.path.startsWith("/w/")) return "admin";
|
|
15
|
+
return route.path.startsWith("/account") ? "account" : "home";
|
|
16
|
+
});
|
|
17
|
+
const surfaceLabel = computed(() => ({ admin: "Admin", account: "Account" })[surface.value] || "Home");
|
|
15
18
|
const themeMode = computed(() => route.query.theme === "dark" ? "dark" : "light");
|
|
16
19
|
const railWidth = computed(() => Number(route.query.railWidth) || undefined);
|
|
17
20
|
const navigationItemSpacing = computed(() => Number(route.query.navigationItemSpacing) || undefined);
|
|
18
21
|
const drawerWidth = computed(() => (route.query.drawerWidth === "content" ? "content" : undefined));
|
|
19
22
|
|
|
20
23
|
watchEffect(function applyFixtureTheme() {
|
|
21
|
-
const themeName = `${surface.value}-${themeMode.value}`;
|
|
24
|
+
const themeName = `${surface.value === "admin" ? "admin" : "home"}-${themeMode.value}`;
|
|
22
25
|
theme.change(themeName);
|
|
23
26
|
document.body.dataset.surface = surface.value;
|
|
24
27
|
document.body.dataset.theme = themeMode.value;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
// Every button size with its 48dp touch target, a label longer than its button, a small button in the corner of a
|
|
3
|
+
// scroll container, the FAB sizes and cards by variant.
|
|
4
|
+
const sizes = ["x-small", "small", "default", "large"];
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<template>
|
|
8
|
+
<section class="d-flex flex-column align-start ga-8 pa-6">
|
|
9
|
+
<template v-for="size in sizes" :key="size">
|
|
10
|
+
<v-btn :size="size" variant="tonal" :data-testid="`fixture-button-${size}`">Size {{ size }}</v-btn>
|
|
11
|
+
<v-btn :size="size" icon="$close" :aria-label="`Close ${size}`" :data-testid="`fixture-icon-button-${size}`" />
|
|
12
|
+
</template>
|
|
13
|
+
<div :style="{ width: '160px' }">
|
|
14
|
+
<v-btn variant="tonal" data-testid="fixture-long-label">A label far longer than the room it has</v-btn>
|
|
15
|
+
</div>
|
|
16
|
+
<div class="d-flex align-end justify-end" :style="{ width: '160px', height: '32px', overflow: 'auto' }" data-testid="fixture-button-corner">
|
|
17
|
+
<v-btn size="x-small" icon="$close" aria-label="Close corner" />
|
|
18
|
+
</div>
|
|
19
|
+
<div class="d-flex align-center ga-4">
|
|
20
|
+
<v-fab icon="$add" aria-label="Add" data-testid="fixture-fab" />
|
|
21
|
+
<v-fab icon="$add" size="small" aria-label="Add small" data-testid="fixture-fab-small" />
|
|
22
|
+
<v-fab icon="$add" size="large" aria-label="Add large" data-testid="fixture-fab-large" />
|
|
23
|
+
<v-fab extended prepend-icon="$add" text="New" data-testid="fixture-fab-extended" />
|
|
24
|
+
</div>
|
|
25
|
+
<div class="d-flex ga-4">
|
|
26
|
+
<v-card v-for="variant in ['elevated', 'flat', 'tonal']" :key="variant" :variant="variant" :data-testid="`fixture-card-${variant}`">
|
|
27
|
+
<v-card-text>{{ variant }}</v-card-text>
|
|
28
|
+
</v-card>
|
|
29
|
+
</div>
|
|
30
|
+
</section>
|
|
31
|
+
</template>
|
|
@@ -13,7 +13,19 @@ useShellAppBar();
|
|
|
13
13
|
<v-app-bar color="surface" flat :height="64" data-testid="fixture-own-bar">
|
|
14
14
|
<ShellUpButton />
|
|
15
15
|
<div class="flex-grow-1 px-3 text-truncate">
|
|
16
|
-
<ShellPageTitle title="Studio"
|
|
16
|
+
<ShellPageTitle title="Studio">
|
|
17
|
+
<template #default="{ title }">
|
|
18
|
+
<!-- A title that is also a switcher: the menu activator sits inside the one h1. -->
|
|
19
|
+
<v-menu>
|
|
20
|
+
<template #activator="{ props: menu }">
|
|
21
|
+
<v-btn variant="text" append-icon="$dropdown" class="text-title-large" v-bind="menu">{{ title }}</v-btn>
|
|
22
|
+
</template>
|
|
23
|
+
<v-list>
|
|
24
|
+
<v-list-item title="Other studio" />
|
|
25
|
+
</v-list>
|
|
26
|
+
</v-menu>
|
|
27
|
+
</template>
|
|
28
|
+
</ShellPageTitle>
|
|
17
29
|
</div>
|
|
18
30
|
<ShellPageActionsTarget />
|
|
19
31
|
<v-btn variant="text" data-testid="fixture-workspace-control">Workspace</v-btn>
|
|
@@ -9,6 +9,7 @@ import "@jskit-ai/material-web/client/material.css";
|
|
|
9
9
|
import { materialThemes, createMaterialVuetifyOptions } from "@jskit-ai/material-web/client";
|
|
10
10
|
import { shellScrollBehavior } from "@jskit-ai/kernel/client";
|
|
11
11
|
import App from "./App.vue";
|
|
12
|
+
import ButtonsPage from "./ButtonsPage.vue";
|
|
12
13
|
import { adminTheme, theme } from "./theme/index.js";
|
|
13
14
|
import RecordListPage from "./RecordListPage.vue";
|
|
14
15
|
import RecordPage from "./RecordPage.vue";
|
|
@@ -39,48 +40,94 @@ const COMPONENTS = new Map([
|
|
|
39
40
|
["fixture.tab-link", ShellTabLinkItem]
|
|
40
41
|
]);
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
// Main navigation as literal data, one placement per destination, as jskit check reads it.
|
|
44
|
+
const placements = [
|
|
45
|
+
{
|
|
46
|
+
id: "fixture.home.home",
|
|
45
47
|
target: "shell.primary-nav",
|
|
46
48
|
kind: "link",
|
|
47
|
-
surfaces: [
|
|
48
|
-
order,
|
|
49
|
-
props: {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
49
|
+
surfaces: ["home"],
|
|
50
|
+
order: 10,
|
|
51
|
+
props: { label: "Home", surface: "home", scopedSuffix: "/", unscopedSuffix: "/", exact: true }
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
id: "fixture.home.settings",
|
|
55
|
+
target: "shell.primary-nav",
|
|
56
|
+
kind: "link",
|
|
57
|
+
surfaces: ["home"],
|
|
58
|
+
order: 20,
|
|
59
|
+
props: { label: "Settings", surface: "home", scopedSuffix: "/settings", unscopedSuffix: "/settings" }
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
id: "fixture.home.contacts",
|
|
63
|
+
target: "shell.primary-nav",
|
|
64
|
+
kind: "link",
|
|
65
|
+
surfaces: ["home"],
|
|
66
|
+
order: 30,
|
|
67
|
+
props: { label: "Contacts", surface: "home", scopedSuffix: "/contacts", unscopedSuffix: "/contacts" }
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
id: "fixture.home.suppliers",
|
|
71
|
+
target: "shell.primary-nav",
|
|
72
|
+
kind: "link",
|
|
73
|
+
surfaces: ["home"],
|
|
74
|
+
order: 40,
|
|
75
|
+
props: { label: "Suppliers", surface: "home", scopedSuffix: "/suppliers", unscopedSuffix: "/suppliers" }
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
id: "fixture.home.bookings",
|
|
79
|
+
target: "shell.primary-nav",
|
|
80
|
+
kind: "link",
|
|
81
|
+
surfaces: ["home"],
|
|
82
|
+
order: 50,
|
|
83
|
+
props: { label: "Bookings", surface: "home", scopedSuffix: "/bookings", unscopedSuffix: "/bookings" }
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
id: "fixture.admin.home",
|
|
87
|
+
target: "shell.primary-nav",
|
|
88
|
+
kind: "link",
|
|
89
|
+
surfaces: ["admin"],
|
|
90
|
+
order: 10,
|
|
91
|
+
props: { label: "Home", surface: "admin", scopedSuffix: "/", unscopedSuffix: "/", exact: true }
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
id: "fixture.admin.assistant",
|
|
95
|
+
target: "shell.primary-nav",
|
|
96
|
+
kind: "link",
|
|
97
|
+
surfaces: ["admin"],
|
|
98
|
+
order: 20,
|
|
99
|
+
props: { label: "Assistant", surface: "admin", scopedSuffix: "/assistant", unscopedSuffix: "/assistant" }
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
id: "fixture.admin.contacts",
|
|
103
|
+
target: "shell.primary-nav",
|
|
104
|
+
kind: "link",
|
|
105
|
+
surfaces: ["admin"],
|
|
106
|
+
order: 30,
|
|
107
|
+
props: { label: "Contacts", surface: "admin", scopedSuffix: "/contacts", unscopedSuffix: "/contacts" }
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
id: "fixture.admin.bookings",
|
|
111
|
+
target: "shell.primary-nav",
|
|
112
|
+
kind: "link",
|
|
113
|
+
surfaces: ["admin"],
|
|
114
|
+
order: 40,
|
|
115
|
+
props: { label: "Bookings", surface: "admin", scopedSuffix: "/bookings", unscopedSuffix: "/bookings" }
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
id: "fixture.admin.rostering",
|
|
119
|
+
target: "shell.primary-nav",
|
|
120
|
+
kind: "link",
|
|
121
|
+
surfaces: ["admin"],
|
|
122
|
+
order: 50,
|
|
123
|
+
props: { label: "Rostering", surface: "admin", scopedSuffix: "/rostering", unscopedSuffix: "/rostering" }
|
|
124
|
+
},
|
|
78
125
|
{
|
|
79
126
|
id: "fixture.help",
|
|
80
127
|
target: "shell.secondary-nav",
|
|
81
128
|
kind: "link",
|
|
82
129
|
componentToken: "fixture.menu-link",
|
|
83
|
-
surfaces: ["
|
|
130
|
+
surfaces: ["home", "admin"],
|
|
84
131
|
order: 100,
|
|
85
132
|
props: {
|
|
86
133
|
label: "Help and support",
|
|
@@ -120,10 +167,12 @@ placementRuntime.setContext({
|
|
|
120
167
|
surfaceConfig: {
|
|
121
168
|
tenancyMode: "path",
|
|
122
169
|
defaultSurfaceId: "home",
|
|
123
|
-
enabledSurfaceIds: ["home", "admin"],
|
|
170
|
+
enabledSurfaceIds: ["home", "admin", "account"],
|
|
124
171
|
surfacesById: {
|
|
125
172
|
home: { id: "home", routeBase: "/home", enabled: true },
|
|
126
|
-
admin: { id: "admin", routeBase: "/w/:workspaceSlug/admin", enabled: true }
|
|
173
|
+
admin: { id: "admin", routeBase: "/w/:workspaceSlug/admin", enabled: true },
|
|
174
|
+
// A surface whose shell has no navigation, as an account page's.
|
|
175
|
+
account: { id: "account", routeBase: "/account", enabled: true }
|
|
127
176
|
}
|
|
128
177
|
}
|
|
129
178
|
});
|
|
@@ -155,6 +204,11 @@ const routes = [
|
|
|
155
204
|
beforeEnter: refuseBlockedRecord,
|
|
156
205
|
meta: { kind: "contacts", jskit: { parent: "/contacts" } }
|
|
157
206
|
},
|
|
207
|
+
{
|
|
208
|
+
path: "/home/contacts/:id/edit",
|
|
209
|
+
component: ScreenPage,
|
|
210
|
+
meta: { title: "Edit contact", jskit: { title: "Edit contact", parent: "/contacts/:id" } }
|
|
211
|
+
},
|
|
158
212
|
{ path: "/home/suppliers", component: RecordListPage, meta: { kind: "suppliers", jskit: { title: "Suppliers" } } },
|
|
159
213
|
{
|
|
160
214
|
path: "/home/suppliers/:id",
|
|
@@ -162,12 +216,18 @@ const routes = [
|
|
|
162
216
|
beforeEnter: refuseBlockedRecord,
|
|
163
217
|
meta: { kind: "suppliers", jskit: { parent: "/suppliers" } }
|
|
164
218
|
},
|
|
219
|
+
{ path: "/home/buttons", component: ButtonsPage, meta: { jskit: { title: "Buttons" } } },
|
|
165
220
|
// A layout that draws its own top app bar from the shell's pieces.
|
|
166
221
|
{ path: "/home/studio", component: StudioPage, meta: { ownBar: true, jskit: { title: "Studio" } } },
|
|
167
222
|
{ path: "/home/studio/:id", component: StudioPage, meta: { ownBar: true, jskit: { parent: "/studio" } } },
|
|
168
223
|
{ path: "/home/:section?", component: ScreenPage, meta: { title: "Home surface" } },
|
|
169
224
|
{ path: "/w/:workspaceSlug/admin/:section?", component: ScreenPage, meta: { title: "Admin surface" } },
|
|
170
225
|
{ path: "/help", component: ScreenPage, meta: { title: "Help and support" } },
|
|
226
|
+
{
|
|
227
|
+
path: "/account",
|
|
228
|
+
component: ScreenPage,
|
|
229
|
+
meta: { title: "Account", jskit: { title: "Account", parent: { surface: "home", path: "/" } } }
|
|
230
|
+
},
|
|
171
231
|
{ path: "/sign-in", component: ScreenPage, meta: { title: "Sign in", bare: true } }
|
|
172
232
|
];
|
|
173
233
|
const router = createRouter({ history: createWebHistory(), routes, scrollBehavior: shellScrollBehavior });
|
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.13",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "node --test --test-concurrency=1"
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@jskit-ai/architecture-inspector": "0.1.8"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@jskit-ai/material-web": "0.1.
|
|
49
|
+
"@jskit-ai/material-web": "0.1.2",
|
|
50
50
|
"@vue/compiler-sfc": "3.5.44"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
-
import { computed, inject, onBeforeUnmount, onMounted, ref } from "vue";
|
|
2
|
+
import { computed, inject, onBeforeUnmount, onMounted, ref, useSlots } from "vue";
|
|
3
3
|
import { useDisplay } from "vuetify";
|
|
4
4
|
import { useShellAppBar } from "../composables/useShellAppBar.js";
|
|
5
5
|
import { useShellDrawer } from "../composables/useShellDrawer.js";
|
|
6
|
+
import { useShellOutletPlacements } from "../composables/useShellOutletPlacements.js";
|
|
6
7
|
import { useShellLayoutState } from "../composables/useShellLayoutState.js";
|
|
7
8
|
import { useShellPullToRefresh } from "../composables/useShellPullToRefresh.js";
|
|
8
9
|
import {
|
|
9
10
|
DEFAULT_SHELL_NAVIGATION_ITEM_SPACING,
|
|
10
11
|
DEFAULT_SHELL_RAIL_WIDTH
|
|
11
12
|
} from "../support/drawerWidth.js";
|
|
12
|
-
import { normalizeDesktopDrawerClosedMode } from "../support/drawerPresentation.js";
|
|
13
|
+
import { normalizeDesktopDrawerClosedMode, shellLayoutHasDrawer } from "../support/drawerPresentation.js";
|
|
13
14
|
import { resolveShellLayoutClass } from "../support/shellLayoutClass.js";
|
|
14
15
|
import { resolveWindowSizeClass } from "../support/windowSizeClass.js";
|
|
15
16
|
import { NO_SHELL_WEB_REFRESH_RUNTIME, SHELL_WEB_REFRESH_RUNTIME_KEY } from "../runtime/refreshRuntime.js";
|
|
@@ -85,8 +86,27 @@ const layoutClass = computed(() => resolveShellLayoutClass(display.width.value))
|
|
|
85
86
|
const isCompactLayout = computed(() => layoutClass.value === "compact");
|
|
86
87
|
// Compact and medium windows open the drawer over the page; a medium window keeps a navigation rail beside it.
|
|
87
88
|
const modalLayout = computed(() => layoutClass.value !== "expanded");
|
|
89
|
+
// A surface draws only the navigation it has: no navigation bar without bar destinations, and no rail or drawer (nor
|
|
90
|
+
// its menu control) without menu destinations, as on an account surface whose shell has no navigation. The surface
|
|
91
|
+
// identity (a workspace switcher) keeps the drawer beside other navigation, as on a phone.
|
|
92
|
+
const slots = useSlots();
|
|
93
|
+
const primaryMenu = useShellOutletPlacements("shell-layout:primary-menu");
|
|
94
|
+
const secondaryMenu = useShellOutletPlacements("shell-layout:secondary-menu");
|
|
95
|
+
const identity = useShellOutletPlacements("shell-layout:top-left");
|
|
96
|
+
const bottomNavigation = useShellOutletPlacements("shell-layout:primary-bottom-nav");
|
|
97
|
+
const hasDrawer = computed(() =>
|
|
98
|
+
shellLayoutHasDrawer({
|
|
99
|
+
menuSlot: Boolean(slots.menu),
|
|
100
|
+
menuCount: primaryMenu.value.length + secondaryMenu.value.length,
|
|
101
|
+
identityCount: slots["top-left"] ? 1 : identity.value.length,
|
|
102
|
+
bottomNavigationCount: bottomNavigation.value.length
|
|
103
|
+
})
|
|
104
|
+
);
|
|
105
|
+
const showsBottomNavigation = computed(() => isCompactLayout.value && bottomNavigation.value.length > 0);
|
|
88
106
|
const showsMediumRail = computed(() =>
|
|
89
|
-
|
|
107
|
+
hasDrawer.value &&
|
|
108
|
+
layoutClass.value === "medium" &&
|
|
109
|
+
normalizeDesktopDrawerClosedMode(props.desktopDrawerClosedMode) === "rail"
|
|
90
110
|
);
|
|
91
111
|
const {
|
|
92
112
|
pullRefreshing,
|
|
@@ -105,10 +125,10 @@ const {
|
|
|
105
125
|
resolvedRailWidth
|
|
106
126
|
} = useShellDrawer({ props, modalLayout, viewportWidth, navigationToggle, layoutState });
|
|
107
127
|
|
|
108
|
-
const standardDrawerVisible = computed(() => !modalLayout.value && drawerPresentation.value.visible);
|
|
128
|
+
const standardDrawerVisible = computed(() => hasDrawer.value && !modalLayout.value && drawerPresentation.value.visible);
|
|
109
129
|
// The menu control sits in the rail or drawer header when one shows, otherwise first in the app bar of a top-level
|
|
110
130
|
// page; an inner page's leading slot is its Up arrow.
|
|
111
|
-
const toggleInAppBar = computed(() => !showsMediumRail.value && !standardDrawerVisible.value);
|
|
131
|
+
const toggleInAppBar = computed(() => hasDrawer.value && !showsMediumRail.value && !standardDrawerVisible.value);
|
|
112
132
|
const fallbackTitle = computed(() => text(props.title) || resolvedSurfaceLabel.value);
|
|
113
133
|
const navigationStyle = computed(() => ({
|
|
114
134
|
"--shell-navigation-item-spacing": `${resolvedNavigationItemSpacing.value}px`,
|
|
@@ -224,6 +244,7 @@ onBeforeUnmount(() => {
|
|
|
224
244
|
|
|
225
245
|
<!-- A modal drawer is the outermost layout item, so it opens from the window's edge over the rail and app bar. -->
|
|
226
246
|
<v-navigation-drawer
|
|
247
|
+
v-if="hasDrawer"
|
|
227
248
|
id="jskit-shell-drawer"
|
|
228
249
|
:model-value="drawerPresentation.visible"
|
|
229
250
|
class="shell-layout__drawer"
|
|
@@ -291,7 +312,7 @@ onBeforeUnmount(() => {
|
|
|
291
312
|
</v-main>
|
|
292
313
|
|
|
293
314
|
<v-bottom-navigation
|
|
294
|
-
v-if="
|
|
315
|
+
v-if="showsBottomNavigation"
|
|
295
316
|
class="shell-layout__bottom-nav"
|
|
296
317
|
data-testid="jskit-shell-bottom-nav"
|
|
297
318
|
bg-color="surface-container"
|
|
@@ -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,7 +7,8 @@ import { useShellNavigationRuntime } from "../navigation/useShellNavigation.js";
|
|
|
7
7
|
|
|
8
8
|
// The page's one h1, in the top app bar: the title the page sets (useShellPageTitle), else its route's
|
|
9
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.
|
|
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.
|
|
11
12
|
const props = defineProps({
|
|
12
13
|
// The title of pages that declare none and set none. A message key or plain text.
|
|
13
14
|
title: {
|
|
@@ -28,7 +29,7 @@ const pageTitle = computed(() => {
|
|
|
28
29
|
|
|
29
30
|
<template>
|
|
30
31
|
<h1 :id="PAGE_TITLE_ID" class="shell-page-title" tabindex="-1" data-testid="jskit-shell-page-title">
|
|
31
|
-
{{ pageTitle }}
|
|
32
|
+
<slot :title="pageTitle">{{ pageTitle }}</slot>
|
|
32
33
|
</h1>
|
|
33
34
|
</template>
|
|
34
35
|
|
|
@@ -42,7 +43,9 @@ const pageTitle = computed(() => {
|
|
|
42
43
|
line-height: 1.75rem;
|
|
43
44
|
margin: 0;
|
|
44
45
|
outline: none;
|
|
45
|
-
|
|
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;
|
|
46
49
|
text-overflow: ellipsis;
|
|
47
50
|
white-space: nowrap;
|
|
48
51
|
}
|
|
@@ -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 };
|
|
@@ -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
|
};
|
|
@@ -473,6 +473,14 @@ test("shell-web's bar pieces give a layout that draws its own top app bar the sh
|
|
|
473
473
|
await expect(ownBar.getByRole("heading", { level: 1, name: "Studio" }), at).toBeVisible();
|
|
474
474
|
await expect(page.getByRole("heading", { level: 1 }), at).toHaveCount(1);
|
|
475
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();
|
|
476
484
|
|
|
477
485
|
// An inner page: Up, its title and its actions, in the app's own bar; Up returns along the trail.
|
|
478
486
|
await page.getByRole("link", { name: "Ada Lovelace", exact: true }).click();
|
|
@@ -496,6 +504,127 @@ test("shell-web's bar pieces give a layout that draws its own top app bar the sh
|
|
|
496
504
|
}
|
|
497
505
|
});
|
|
498
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
|
+
|
|
499
628
|
async function openMainDestination(page, label) {
|
|
500
629
|
await page.getByRole("link", { name: label, exact: true }).filter({ visible: true }).first().click();
|
|
501
630
|
}
|
|
@@ -593,6 +722,11 @@ test("shell-web Up follows the tab's trail, falls back to the parent and returns
|
|
|
593
722
|
await pressShellBack(pasted);
|
|
594
723
|
await expect(pasted).toHaveURL(/\/home\/suppliers$/u);
|
|
595
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);
|
|
596
730
|
await pasted.close();
|
|
597
731
|
|
|
598
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
|
+
});
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import test from "node:test";
|
|
3
|
-
import { createApp } from "vue";
|
|
3
|
+
import { createApp, ref } from "vue";
|
|
4
4
|
import { resolveShellLinkPath, useShellLinkResolver } from "../src/client/navigation/linkResolver.js";
|
|
5
|
+
import { usePaths } from "../src/client/navigation/usePaths.js";
|
|
6
|
+
import { SHELL_WEB_PLACEMENT_RUNTIME_KEY } from "../src/client/placement/inject.js";
|
|
5
7
|
|
|
6
8
|
function createPlacementContext() {
|
|
7
9
|
return {
|
|
@@ -132,3 +134,50 @@ test("useShellLinkResolver exposes only surface-relative resolve", () => {
|
|
|
132
134
|
assert.deepEqual(Object.keys(resolver), ["resolve"]);
|
|
133
135
|
assert.equal(resolver.resolve("/reports"), "/console/reports");
|
|
134
136
|
});
|
|
137
|
+
|
|
138
|
+
test("resolveShellLinkPath fills the relative path's :name segments from params", () => {
|
|
139
|
+
const to = resolveShellLinkPath({
|
|
140
|
+
context: createPlacementContext(),
|
|
141
|
+
surface: "app",
|
|
142
|
+
params: { workspaceSlug: "acme", proposalId: "7 b" },
|
|
143
|
+
relativePath: "/program/proposal/:proposalId/edit"
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
assert.equal(to, "/w/acme/program/proposal/7%20b/edit");
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test("resolveShellLinkPath throws for a relative path's missing param unless params are not strict", () => {
|
|
150
|
+
const link = { context: createPlacementContext(), surface: "console", relativePath: "/books/:bookId" };
|
|
151
|
+
assert.throws(() => resolveShellLinkPath(link), /Missing required route params for "\/books\/:bookId": bookId\./u);
|
|
152
|
+
assert.equal(resolveShellLinkPath({ ...link, strictParams: false }), "/console/books/:bookId");
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test("resolveShellLinkPath leaves an external URL, a query and a hash alone", () => {
|
|
156
|
+
const context = createPlacementContext();
|
|
157
|
+
assert.equal(
|
|
158
|
+
resolveShellLinkPath({ context, surface: "console", relativePath: "https://example.com:8080/:x" }),
|
|
159
|
+
"https://example.com:8080/:x"
|
|
160
|
+
);
|
|
161
|
+
assert.equal(
|
|
162
|
+
resolveShellLinkPath({ context, surface: "console", relativePath: "/search?at=:time#:part", params: { time: "now" } }),
|
|
163
|
+
"/console/search?at=:time#:part"
|
|
164
|
+
);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test("usePaths().page() fills a declared parent's params from the current route", () => {
|
|
168
|
+
const context = createPlacementContext();
|
|
169
|
+
const app = createApp({ render: () => null });
|
|
170
|
+
app.provide(SHELL_WEB_PLACEMENT_RUNTIME_KEY, { getContext: () => context, subscribe: () => () => {} });
|
|
171
|
+
const paths = app.runWithContext(() => usePaths({
|
|
172
|
+
routeContext: {
|
|
173
|
+
route: { params: { bookId: "7" } },
|
|
174
|
+
placementContext: ref(context),
|
|
175
|
+
currentSurfaceId: ref("console")
|
|
176
|
+
}
|
|
177
|
+
}));
|
|
178
|
+
|
|
179
|
+
// What the Up arrow of a direct visit to /console/books/7/edit resolves its parent "/books/:bookId" to.
|
|
180
|
+
assert.equal(paths.page("/books/:bookId"), "/console/books/7");
|
|
181
|
+
assert.equal(paths.page("/books/:bookId", { params: { bookId: "8" } }), "/console/books/8");
|
|
182
|
+
assert.throws(() => paths.page("/authors/:authorId"), /Missing required route params/u);
|
|
183
|
+
});
|