@jskit-ai/shell-web 0.2.49 → 0.2.51

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 CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ - A UI kit, `@jskit-ai/shell-web/client/ui`, through which an application gives JSKIT's views its own design system's button, dialog frame and text classes: `provideShellUi(vueApp, { Button, Dialog, text })`, once before it mounts, and `useShellUi()` in a view, which returns them. `Button` takes `emphasis` (`high`, `medium`, `subtle`, `low`), `tone` (`accent`, `neutral`, `danger`), `size` (`default`, `large`), `type`, `disabled`, `pending`, `block`, `href` and `icon`, with its label in the default slot; `Dialog` takes `open` and `title`, emits `close`, and has a default slot for its body and an `actions` slot; `text` maps the text roles `title`, `heading`, `subheading`, `strong`, `lead`, `body` and `caption` to class names. A kit is partial: the roles and text roles it leaves out are Material 3's, `ShellUiButton` (a Vuetify button: flat, tonal, outlined and text, in primary, secondary and error) and `ShellUiDialog` (a 440 px `v-dialog` named by its title), and Material's type scale (`MATERIAL_TEXT`); an unknown role or text role, a role that is not a component and a class that is not a string throw. It exports Vue components, so shell-web's `optimizeDeps.exclude` names `@jskit-ai/shell-web/client/ui` and a dependency scan leaves it source, as it leaves `@jskit-ai/shell-web/client`.
6
+ - `ShellErrorHost`'s banners no longer cover the page below a top app bar. They floated there over the top of the content, fixed and up to 1,120 px wide, and reserved no room, so on every page with an app bar a request recovery banner hid the content's first lines and took their clicks (Playwright: `.shell-error-host__banner` intercepts pointer events). They are now a top Vuetify layout item (`v-layout-item`) of their own measured height, placed after the app bar and the navigation, so `v-main` starts the content below them as it starts it below the app bar, and gives the room back when they close; content scrolled under them passes under them as under the app bar. On a surface without an app bar (sign-in) they still join the page flow above the content and publish `--shell-error-banners-inline-height`, as before. They keep their z-index (2600) and their look. An app that draws its own layout around `v-main` gets the same room, since Vuetify's layout reserves it.
5
7
  - The environment banner of a staging page that real people use (its server has `STAGING_REACHES_REAL_PEOPLE=true`, so the page carries the kernel's `jskit-staging-reaches-real-people` tag) reads "Staging · real people", described as "Staging that real people use: email and text messages reach the people they are for, other messages are logged and payments use the sandbox.", in place of the test-copy wording; `installAppEnvironmentBanner` takes `reachesRealPeople`, read from the page when omitted. New message keys: `jskit.shell.appEnvironment.stagingRealPeople` and `stagingRealPeopleDescription`. Every other page's banner is unchanged.
6
8
  - A navigation rail label never breaks inside a word. A label wider than the rail wraps between its words to a second line, as Material 3's rail labels do, and only a label that needs a third line ends its second in an ellipsis, as before; a single word wider than the rail now ends in an ellipsis too, where it was split across two lines ("Administrati" over "on").
7
9
  - Closing a dialog no longer makes a closed modal navigation drawer or side sheet reachable. The page behind a dialog made every part `ShellLayout` marks `data-shell-page` live when the dialog closed, and when the layout mounted, the closed drawer and side sheet included, which Vuetify keeps `inert` while they are closed, so their off-screen destinations and content took keyboard focus and assistive technology read them. Now only the parts the dialog made inert are made live again; a part already inert stays so, and a drawer that closes behind the dialog (a window that narrows, a link in the dialog) is inert once the dialog closes.
package/README.md CHANGED
@@ -24,6 +24,17 @@ elsewhere on the page stay. Medium and wider bars show them all.
24
24
  `ShellErrorHost` centres its snackbar above the navigation bar on compact
25
25
  windows and starts it at the content's start edge, at most half the content's
26
26
  width, on wider ones, so it never covers the FAB or the actions it reports on.
27
+ Its banners never cover the content either: below a top app bar they are a top
28
+ layout item of their own height, so `v-main` starts the content below them,
29
+ and on a surface without an app bar they join the page flow above it.
30
+
31
+ Request recovery reports a network failure of a `GET` or `HEAD` query as a
32
+ banner with Retry, for reads whose screen does not show the failure itself.
33
+ `useList()`, `useView()` and `useAddEdit()` from `@jskit-ai/http-web` show
34
+ theirs where the read failed (`loadError`, with Retry), so their queries are
35
+ left out unless the caller passes `requestRecovery`. A hand-written query
36
+ whose component shows its own load error with Retry sets
37
+ `meta: { jskit: { requestRecovery: false } }`, so the failure shows once.
27
38
 
28
39
  ## The page behind a dialog
29
40
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/shell-web",
3
- "version": "0.2.49",
3
+ "version": "0.2.51",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "jskit test"
@@ -39,6 +39,7 @@
39
39
  "./client/composables/useShellPageClose": "./src/client/composables/useShellPageClose.js",
40
40
  "./client/composables/useShellWindowSizeClass": "./src/client/composables/useShellWindowSizeClass.js",
41
41
  "./client/directives/vPending": "./src/client/directives/vPending.js",
42
+ "./client/ui": "./src/client/ui/index.js",
42
43
  "./client/providers/ShellWebClientProvider": "./src/client/providers/ShellWebClientProvider.js",
43
44
  "./client/types": "./src/client/types.js",
44
45
  "./test/adaptiveShellSmoke": "./src/test/adaptiveShellSmoke.js",
@@ -47,14 +48,14 @@
47
48
  "./locales/en.json": "./locales/en.json"
48
49
  },
49
50
  "dependencies": {
50
- "@jskit-ai/architecture-inspector": "0.1.32"
51
+ "@jskit-ai/architecture-inspector": "0.1.33"
51
52
  },
52
53
  "devDependencies": {
53
- "@jskit-ai/material-web": "0.1.9",
54
+ "@jskit-ai/material-web": "0.1.10",
54
55
  "@vue/compiler-sfc": "3.5.44"
55
56
  },
56
57
  "peerDependencies": {
57
- "@jskit-ai/kernel": "0.2.33",
58
+ "@jskit-ai/kernel": "0.2.34",
58
59
  "pinia": "^4.0.3",
59
60
  "vue": "^3.5.44",
60
61
  "vue-router": "^5.3.1",
@@ -105,7 +106,8 @@
105
106
  "@jskit-ai/shell-web/client/types"
106
107
  ],
107
108
  "exclude": [
108
- "@jskit-ai/shell-web/client"
109
+ "@jskit-ai/shell-web/client",
110
+ "@jskit-ai/shell-web/client/ui"
109
111
  ]
110
112
  },
111
113
  "singleton": true
@@ -38,9 +38,11 @@ placement registry, topology, and adaptive smoke helper exported by
38
38
  - Cached route/resource state hydrates writable UI state synchronously or with
39
39
  immediate watchers.
40
40
  - Loading uses stable skeletons, not spinners or shifting status banners.
41
- - `ShellErrorHost` stays directly inside `v-app`. Its banners float below a top
42
- app bar; on a surface without one (such as sign-in) they join the page flow
43
- above the content so they never cover it. A full-viewport fixed screen on
41
+ - `ShellErrorHost` stays directly inside `v-app`. Below a top app bar its
42
+ banners are a top Vuetify layout item of their own height, so `v-main`
43
+ starts the content below them as it starts it below the app bar; on a
44
+ surface without one (such as sign-in) they join the page flow above the
45
+ content. Either way they never cover it. A full-viewport fixed screen on
44
46
  such a surface starts at `var(--shell-error-banners-inline-height, 0px)`, as
45
47
  `@jskit-ai/auth-web`'s login and reset views do.
46
48
  - Restyle shell chrome through its custom properties, not by overriding
@@ -1,4 +1,5 @@
1
1
  <script setup>
2
+ import { VLayoutItem } from "vuetify/components/VLayout";
2
3
  import { useShellErrorHost } from "../composables/useShellErrorHost.js";
3
4
  import {
4
5
  actionsFor,
@@ -13,6 +14,7 @@ import { useJskitText } from "../i18n.js";
13
14
  const { t, text, serverMessage } = useJskitText();
14
15
  const {
15
16
  bannerEntries,
17
+ bannerLayoutItemProps,
16
18
  bannerPlacement,
17
19
  bannersElement,
18
20
  dialogEntry,
@@ -33,45 +35,52 @@ const {
33
35
  :class="{ 'shell-error-host--inline-banners': bannerPlacement.inline }"
34
36
  aria-live="polite"
35
37
  >
36
- <div
38
+ <!-- Below a top app bar the banners are a top layout item of their own height, so the layout starts the page's
39
+ content below them as it starts it below the app bar; without one they are a block in the page flow. -->
40
+ <component
41
+ :is="bannerPlacement.inline ? 'div' : VLayoutItem"
37
42
  v-if="bannerEntries.length > 0"
38
- ref="bannersElement"
39
- class="shell-error-host__banners"
40
- :class="{ 'shell-error-host__banners--inline': bannerPlacement.inline }"
41
- :style="bannerPlacement.style"
42
- data-testid="shell-error-host-banners"
43
+ v-bind="bannerPlacement.inline ? {} : bannerLayoutItemProps"
44
+ class="shell-error-host__banners-place"
43
45
  >
44
- <div class="shell-error-host__banner-stack">
45
- <v-alert
46
- v-for="entry in bannerEntries"
47
- :key="entry.id"
48
- :color="`${resolveSeverityColor(entry.severity)}-container`"
49
- :icon="resolveSeverityIcon(entry.severity)"
50
- variant="flat"
51
- density="comfortable"
52
- :rounded="12"
53
- class="shell-error-host__banner"
54
- closable
55
- :close-label="t('jskit.shell.actions.close')"
56
- @click:close="dismiss(entry)"
57
- >
58
- <div class="d-flex align-center ga-3 flex-wrap">
59
- <span>{{ serverMessage(entry) }}</span>
60
- <v-spacer />
61
- <v-btn
62
- v-for="(action, index) in actionsFor(entry)"
63
- :key="index"
64
- variant="text"
65
- size="small"
66
- class="text-none"
67
- @click="runAction(entry, action)"
68
- >
69
- {{ text(action.label) }}
70
- </v-btn>
71
- </div>
72
- </v-alert>
46
+ <div
47
+ ref="bannersElement"
48
+ class="shell-error-host__banners"
49
+ :class="{ 'shell-error-host__banners--inline': bannerPlacement.inline }"
50
+ data-testid="shell-error-host-banners"
51
+ >
52
+ <div class="shell-error-host__banner-stack">
53
+ <v-alert
54
+ v-for="entry in bannerEntries"
55
+ :key="entry.id"
56
+ :color="`${resolveSeverityColor(entry.severity)}-container`"
57
+ :icon="resolveSeverityIcon(entry.severity)"
58
+ variant="flat"
59
+ density="comfortable"
60
+ :rounded="12"
61
+ class="shell-error-host__banner"
62
+ closable
63
+ :close-label="t('jskit.shell.actions.close')"
64
+ @click:close="dismiss(entry)"
65
+ >
66
+ <div class="d-flex align-center ga-3 flex-wrap">
67
+ <span>{{ serverMessage(entry) }}</span>
68
+ <v-spacer />
69
+ <v-btn
70
+ v-for="(action, index) in actionsFor(entry)"
71
+ :key="index"
72
+ variant="text"
73
+ size="small"
74
+ class="text-none"
75
+ @click="runAction(entry, action)"
76
+ >
77
+ {{ text(action.label) }}
78
+ </v-btn>
79
+ </div>
80
+ </v-alert>
81
+ </div>
73
82
  </div>
74
- </div>
83
+ </component>
75
84
 
76
85
  <!-- Material 3 keeps a snackbar clear of the actions it reports on. Vuetify places it inside the layout, above the
77
86
  navigation bar and a FAB that takes layout room (`<v-fab app layout>`). On a phone it is centred there; on
@@ -154,16 +163,18 @@ const {
154
163
  order: -1;
155
164
  }
156
165
 
166
+ /* The floating banners' layout item spans the content's width under the app bar and takes no clicks itself. */
167
+ .shell-error-host__banners-place {
168
+ pointer-events: none;
169
+ }
170
+
157
171
  .shell-error-host__banners {
158
- position: fixed;
159
- z-index: 2600;
160
172
  pointer-events: none;
161
173
  padding: 10px 12px;
162
174
  }
163
175
 
164
176
  .shell-error-host__banners--inline {
165
177
  position: relative;
166
- z-index: auto;
167
178
  padding-top: calc(env(safe-area-inset-top, 0px) + 10px);
168
179
  }
169
180
 
@@ -7,6 +7,13 @@ import { useJskitText } from "../i18n.js";
7
7
  import { useShellWindowSizeClass } from "./useShellWindowSizeClass.js";
8
8
 
9
9
  const BANNER_INLINE_HEIGHT_PROPERTY = "--shell-error-banners-inline-height";
10
+ // The name of the top layout item floating banners take below the app bar, and its order: after every default-order
11
+ // item (the app bar, the navigation rail or drawer), so the banners sit under the app bar and beside the navigation,
12
+ // over the content's own width, whatever order the app mounts them in.
13
+ const BANNER_LAYOUT_ITEM_NAME = "shell-error-host-banners";
14
+ const BANNER_LAYOUT_ITEM_ORDER = 1;
15
+ // Above Vuetify's overlays (2400), as the banners always were.
16
+ const BANNER_Z_INDEX = 2600;
10
17
  // The modal surfaces that keep their actions at their bottom edge on a compact window, where the snackbar shows: an
11
18
  // open dialog (a bottom sheet is one) and an open temporary navigation drawer.
12
19
  const MODAL_SURFACE_SELECTOR = [
@@ -32,8 +39,9 @@ function publishInlineBannerHeight(height = 0) {
32
39
  }
33
40
 
34
41
  /**
35
- * What the error host shows and does: the snackbar queue, the dialog, and where the banners sit. Inline banners publish
36
- * their height so full-viewport surfaces can start below them.
42
+ * What the error host shows and does: the snackbar queue, the dialog, and where the banners sit. Below a top app bar the
43
+ * banners take a top layout item of their own measured height, so the page's content starts below them; without one
44
+ * they join the page flow and publish their height so full-viewport surfaces can start below them.
37
45
  */
38
46
  function useShellErrorHost() {
39
47
  const runtime = useShellWebErrorRuntime();
@@ -44,30 +52,54 @@ function useShellErrorHost() {
44
52
  const bannerEntries = computed(() => store.channels.banner || []);
45
53
  const dialogEntry = computed(() => store.channels.dialog[0] || null);
46
54
  const displayedSnackbarEntry = ref(null);
47
- const layoutRect = useLayout().mainRect;
55
+ const layout = useLayout();
48
56
 
49
57
  const bannersElement = ref(null);
50
- const bannerPlacement = computed(() => resolveBannerPlacement(layoutRect.value));
58
+ // The floating banners' measured height: the room their layout item takes below the app bar.
59
+ const bannerHeight = ref(0);
60
+ // Where the banners start: under the top app bar, which mainRect's top is. Once they float, the layout counts their
61
+ // own room in mainRect too, so their layout item says where they start.
62
+ const bannerTop = computed(() => {
63
+ const item = layout.getLayoutItem(BANNER_LAYOUT_ITEM_NAME);
64
+ return item ? item.top : layout.mainRect.value.top;
65
+ });
66
+ const bannerPlacement = computed(() => resolveBannerPlacement(bannerTop.value));
67
+ // The floating banners' VLayoutItem.
68
+ const bannerLayoutItemProps = computed(() => ({
69
+ name: BANNER_LAYOUT_ITEM_NAME,
70
+ order: BANNER_LAYOUT_ITEM_ORDER,
71
+ position: "top",
72
+ size: bannerHeight.value,
73
+ modelValue: true,
74
+ style: { zIndex: BANNER_Z_INDEX }
75
+ }));
51
76
  let bannerResizeObserver = null;
52
77
 
53
78
  function stopObservingBanners() {
54
79
  bannerResizeObserver?.disconnect();
55
80
  bannerResizeObserver = null;
56
81
  publishInlineBannerHeight(0);
82
+ bannerHeight.value = 0;
57
83
  }
58
84
 
59
85
  watch(
60
86
  [bannersElement, () => bannerPlacement.value.inline],
61
87
  ([element, inline]) => {
62
88
  stopObservingBanners();
63
- if (!element || !inline) {
89
+ if (!element) {
64
90
  return;
65
91
  }
66
- bannerResizeObserver = new ResizeObserver(() => {
67
- publishInlineBannerHeight(element.getBoundingClientRect().height);
68
- });
92
+ const measure = () => {
93
+ const height = element.getBoundingClientRect().height;
94
+ if (inline) {
95
+ publishInlineBannerHeight(height);
96
+ } else {
97
+ bannerHeight.value = Math.ceil(height);
98
+ }
99
+ };
100
+ bannerResizeObserver = new ResizeObserver(measure);
69
101
  bannerResizeObserver.observe(element);
70
- publishInlineBannerHeight(element.getBoundingClientRect().height);
102
+ measure();
71
103
  },
72
104
  { flush: "post" }
73
105
  );
@@ -175,6 +207,7 @@ function useShellErrorHost() {
175
207
 
176
208
  return {
177
209
  bannerEntries,
210
+ bannerLayoutItemProps,
178
211
  bannerPlacement,
179
212
  bannersElement,
180
213
  dialogEntry,
@@ -37,23 +37,12 @@ function actionsFor(entry) {
37
37
  return entry ? [entry.action, ...entry.additionalActions].filter(Boolean) : [];
38
38
  }
39
39
 
40
- // Banners float just below a top app bar. A surface without one (sign-in pages)
41
- // has nothing to float under, so the banners join the page flow above the
42
- // content instead of covering it.
43
- function resolveBannerPlacement(rect) {
44
- const top = Number(rect.top) || 0;
45
- if (top <= 0) {
46
- return { inline: true, style: undefined };
47
- }
48
-
49
- return {
50
- inline: false,
51
- style: {
52
- top: `calc(env(safe-area-inset-top, 0px) + ${top}px)`,
53
- left: `${Number(rect.left) || 0}px`,
54
- right: `${Number(rect.right) || 0}px`
55
- }
56
- };
40
+ // Banners sit just below a top app bar, in a top layout item of their own height, so the page's content starts below
41
+ // them as it starts below the app bar. A surface without one (sign-in pages) has no app bar to sit under, so the
42
+ // banners join the page flow above the content instead. Neither covers the content. `top` is where the banners start:
43
+ // the height of the top app bar, 0 without one.
44
+ function resolveBannerPlacement(top = 0) {
45
+ return Object.freeze({ inline: !(Number(top) > 0) });
57
46
  }
58
47
 
59
48
  export {
@@ -35,4 +35,13 @@
35
35
  * @property {string} unscopedSuffix
36
36
  */
37
37
 
38
+ /**
39
+ * The application's design system for JSKIT's views (`@jskit-ai/shell-web/client/ui`): the components a view draws its
40
+ * buttons and dialogs with, and the classes of its text by role. Material 3's unless the application provides its own.
41
+ * @typedef {object} ShellUi
42
+ * @property {import("vue").Component} Button A button: props `emphasis`, `tone`, `size`, `type`, `disabled`, `pending`, `block`, `href`, `icon`; the label in its default slot.
43
+ * @property {import("vue").Component} Dialog A modal dialog: props `open` and `title`, the event `close`; the body in its default slot and the actions in `actions`.
44
+ * @property {Readonly<Record<"title" | "heading" | "subheading" | "strong" | "lead" | "body" | "caption", string>>} text The class names of each text role.
45
+ */
46
+
38
47
  export {};
@@ -0,0 +1,41 @@
1
+ <script setup>
2
+ // The kit's Material button (shell-web's Button role), a Vuetify button: each emphasis is a Material 3 button type and
3
+ // each tone a colour role. A view's other attributes (class, data-testid, form, aria-*) and listeners reach the button.
4
+ // `type` applies to a button, `href` makes it a link.
5
+ const props = defineProps({
6
+ // high: the screen's main action. medium: a secondary action with a fill. subtle: a secondary action drawn with an
7
+ // outline, such as one of several equal choices. low: an action drawn as text alone.
8
+ emphasis: { type: String, default: "medium", validator: (value) => ["high", "medium", "subtle", "low"].includes(value) },
9
+ tone: { type: String, default: "accent", validator: (value) => ["accent", "neutral", "danger"].includes(value) },
10
+ // large: a form's main action, drawn bigger.
11
+ size: { type: String, default: "default", validator: (value) => ["default", "large"].includes(value) },
12
+ type: { type: String, default: "button" },
13
+ disabled: { type: Boolean, default: false },
14
+ // The action is running.
15
+ pending: { type: Boolean, default: false },
16
+ // The button takes the whole width of its container.
17
+ block: { type: Boolean, default: false },
18
+ href: { type: String, default: undefined },
19
+ // A leading icon, as an icon alias ("$google").
20
+ icon: { type: String, default: undefined }
21
+ });
22
+
23
+ const VARIANTS = Object.freeze({ high: "flat", medium: "tonal", subtle: "outlined", low: "text" });
24
+ const COLORS = Object.freeze({ accent: "primary", neutral: "secondary", danger: "error" });
25
+ </script>
26
+
27
+ <template>
28
+ <v-btn
29
+ :variant="VARIANTS[props.emphasis]"
30
+ :color="COLORS[props.tone]"
31
+ :size="props.size"
32
+ :type="props.href ? undefined : props.type"
33
+ :href="props.href"
34
+ :disabled="props.disabled"
35
+ :loading="props.pending"
36
+ :block="props.block"
37
+ :prepend-icon="props.icon"
38
+ >
39
+ <slot />
40
+ </v-btn>
41
+ </template>
@@ -0,0 +1,46 @@
1
+ <script setup>
2
+ import { useShellUiText } from "./shellUi.js";
3
+
4
+ // The kit's Material dialog (shell-web's Dialog role): a Vuetify dialog whose card holds the title, the body and the
5
+ // actions, the main one last. Escape and a click outside ask the view to close it (`close`); the view decides, and
6
+ // gives focus back where it was.
7
+ defineProps({
8
+ open: { type: Boolean, required: true },
9
+ // Names the dialog and heads it.
10
+ title: { type: String, required: true }
11
+ });
12
+ const emit = defineEmits(["close"]);
13
+ const text = useShellUiText();
14
+ </script>
15
+
16
+ <template>
17
+ <v-dialog
18
+ :model-value="open"
19
+ max-width="440"
20
+ :aria-label="title"
21
+ @update:model-value="(shown) => shown || emit('close')"
22
+ >
23
+ <v-card>
24
+ <v-card-text class="shell-ui-dialog">
25
+ <h2 :class="[text.heading, 'mb-2']">{{ title }}</h2>
26
+ <slot />
27
+ <div v-if="$slots.actions" class="shell-ui-dialog__actions">
28
+ <slot name="actions" />
29
+ </div>
30
+ </v-card-text>
31
+ </v-card>
32
+ </v-dialog>
33
+ </template>
34
+
35
+ <style scoped>
36
+ .shell-ui-dialog {
37
+ padding: 24px;
38
+ }
39
+
40
+ .shell-ui-dialog__actions {
41
+ display: flex;
42
+ flex-wrap: wrap;
43
+ justify-content: flex-end;
44
+ gap: 8px;
45
+ }
46
+ </style>
@@ -0,0 +1,9 @@
1
+ import ShellUiButton from "./ShellUiButton.vue";
2
+ import ShellUiDialog from "./ShellUiDialog.vue";
3
+ import { MATERIAL_TEXT, SHELL_UI_KEY, SHELL_UI_ROLES, SHELL_UI_TEXT_ROLES, defineShellUi } from "./shellUi.js";
4
+
5
+ // The application's design system for JSKIT's views: a view draws its buttons with the kit's Button, its dialogs with
6
+ // its Dialog and its text with its text classes. Without a kit, or for a role the kit leaves out, they are Material 3's.
7
+ const { provideShellUi, useShellUi } = defineShellUi({ Button: ShellUiButton, Dialog: ShellUiDialog, text: MATERIAL_TEXT });
8
+
9
+ export { MATERIAL_TEXT, SHELL_UI_KEY, SHELL_UI_ROLES, SHELL_UI_TEXT_ROLES, ShellUiButton, ShellUiDialog, provideShellUi, useShellUi };
@@ -0,0 +1,107 @@
1
+ import { inject } from "vue";
2
+
3
+ const SHELL_UI_KEY = "jskit.shell-web.ui.client";
4
+ // The kit's roles: the button and the dialog a JSKIT view draws, and the classes of its text.
5
+ const SHELL_UI_ROLES = Object.freeze(["Button", "Dialog", "text"]);
6
+ // A view's text by what it is: a page's title (its h1), a heading and a subheading inside a page or a dialog, a short
7
+ // emphasized line, lead text, body text and a caption.
8
+ const SHELL_UI_TEXT_ROLES = Object.freeze(["title", "heading", "subheading", "strong", "lead", "body", "caption"]);
9
+ // Material 3's type scale for each text role, as Vuetify's classes: what a JSKIT view drew before the kit.
10
+ const MATERIAL_TEXT = Object.freeze({
11
+ title: "text-headline-medium",
12
+ heading: "text-title-large",
13
+ subheading: "text-title-medium",
14
+ strong: "text-title-small",
15
+ lead: "text-body-large",
16
+ body: "text-body-medium",
17
+ caption: "text-body-small"
18
+ });
19
+
20
+ function isRecord(value) {
21
+ return value !== null && typeof value === "object" && !Array.isArray(value);
22
+ }
23
+
24
+ function shown(value) {
25
+ return typeof value === "string" ? `"${value}"` : String(value);
26
+ }
27
+
28
+ function component(role, value) {
29
+ if (typeof value !== "function" && !isRecord(value)) {
30
+ throw new TypeError(`Shell UI role "${role}" needs a Vue component, not ${shown(value)}.`);
31
+ }
32
+ return value;
33
+ }
34
+
35
+ function textClasses(text) {
36
+ if (!isRecord(text)) {
37
+ throw new TypeError('Shell UI role "text" needs an object of class names by text role.');
38
+ }
39
+ for (const [role, value] of Object.entries(text)) {
40
+ if (!SHELL_UI_TEXT_ROLES.includes(role)) {
41
+ throw new TypeError(`Shell UI text role "${role}" is not one of ${SHELL_UI_TEXT_ROLES.join(", ")}.`);
42
+ }
43
+ if (typeof value !== "string") {
44
+ throw new TypeError(`Shell UI text role "${role}" needs a class name, not ${shown(value)}.`);
45
+ }
46
+ }
47
+ return text;
48
+ }
49
+
50
+ /**
51
+ * The kit a view reads: the application's roles where it gave them, the defaults for the rest, each checked.
52
+ * @param {unknown} kit
53
+ * @param {import("../types.js").ShellUi} defaults
54
+ * @returns {import("../types.js").ShellUi}
55
+ */
56
+ function resolveShellUi(kit, defaults) {
57
+ if (kit === undefined) {
58
+ return defaults;
59
+ }
60
+ if (!isRecord(kit)) {
61
+ throw new TypeError("provideShellUi needs a kit object: { Button, Dialog, text }, each optional.");
62
+ }
63
+ for (const role of Object.keys(kit)) {
64
+ if (!SHELL_UI_ROLES.includes(role)) {
65
+ throw new TypeError(`Shell UI role "${role}" is not one of ${SHELL_UI_ROLES.join(", ")}.`);
66
+ }
67
+ }
68
+ return Object.freeze({
69
+ Button: Object.hasOwn(kit, "Button") ? component("Button", kit.Button) : defaults.Button,
70
+ Dialog: Object.hasOwn(kit, "Dialog") ? component("Dialog", kit.Dialog) : defaults.Dialog,
71
+ text: Object.freeze({ ...defaults.text, ...(Object.hasOwn(kit, "text") ? textClasses(kit.text) : {}) })
72
+ });
73
+ }
74
+
75
+ /**
76
+ * The kit's two functions over its defaults: `provideShellUi(vueApp, kit)`, which an application calls once, before it
77
+ * mounts, with the roles it draws in its own design system, and `useShellUi()`, which a view calls in its setup.
78
+ * @param {import("../types.js").ShellUi} defaults
79
+ */
80
+ function defineShellUi(defaults) {
81
+ return Object.freeze({
82
+ /**
83
+ * @param {{ provide: (key: string, value: unknown) => unknown }} vueApp
84
+ * @param {Partial<import("../types.js").ShellUi>} [kit]
85
+ */
86
+ provideShellUi(vueApp, kit) {
87
+ vueApp.provide(SHELL_UI_KEY, resolveShellUi(kit, defaults));
88
+ },
89
+ /** @returns {import("../types.js").ShellUi} */
90
+ useShellUi() {
91
+ return inject(SHELL_UI_KEY, defaults);
92
+ }
93
+ });
94
+ }
95
+
96
+ // What the kit's own Material components read where the application provided no kit: Material's text classes.
97
+ const MATERIAL_TEXT_ONLY = Object.freeze({ text: MATERIAL_TEXT });
98
+
99
+ /**
100
+ * The text classes the application provided, or Material's, for the kit's own Material components.
101
+ * @returns {Readonly<Record<string, string>>}
102
+ */
103
+ function useShellUiText() {
104
+ return inject(SHELL_UI_KEY, MATERIAL_TEXT_ONLY).text;
105
+ }
106
+
107
+ export { MATERIAL_TEXT, SHELL_UI_KEY, SHELL_UI_ROLES, SHELL_UI_TEXT_ROLES, defineShellUi, resolveShellUi, useShellUiText };
@@ -533,7 +533,11 @@ async function reportBannerAndMeasure(page) {
533
533
  const banner = page.locator(".shell-error-host__banner").first();
534
534
  await expect(banner).toBeVisible();
535
535
  await page.evaluate(() => new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve))));
536
- return banner.evaluate((element) => {
536
+ return measureBanner(page);
537
+ }
538
+
539
+ function measureBanner(page) {
540
+ return page.locator(".shell-error-host__banner").first().evaluate((element) => {
537
541
  const box = (node) => {
538
542
  const rect = node.getBoundingClientRect();
539
543
  return { top: rect.top, bottom: rect.bottom, left: rect.left, right: rect.right };
@@ -551,7 +555,9 @@ async function reportBannerAndMeasure(page) {
551
555
  closeColor,
552
556
  closeColorWithThemedDefault,
553
557
  appBar: appBar ? box(appBar) : null,
554
- content: Array.from(document.querySelectorAll("main h1, main input, main button"))
558
+ // The page's content: inside main, or on a surface without a layout (sign-in) everything outside the host.
559
+ content: Array.from((document.querySelector("main") || document.body).querySelectorAll("h1, p, input, button"))
560
+ .filter((node) => !node.closest(".shell-error-host"))
555
561
  .map((node) => ({ name: node.textContent.trim() || node.name, rect: box(node) }))
556
562
  };
557
563
  });
@@ -584,11 +590,26 @@ test("shell-web error banners never cover content and keep a readable close butt
584
590
 
585
591
  await page.goto(`/home?theme=${theme}`);
586
592
  await expect(page.getByTestId("jskit-shell-app-bar")).toBeVisible();
593
+ const answer = page.getByRole("textbox", { name: "Unsaved answer" });
594
+ const contentTop = await answer.evaluate((element) => element.getBoundingClientRect().top);
587
595
  const shell = await reportBannerAndMeasure(page);
588
596
  assert.ok(
589
597
  shell.banner.top >= shell.appBar.bottom - 1,
590
598
  `${viewport.width}px ${theme}: the banner overlaps the top app bar.`
591
599
  );
600
+ // Under an app bar the banner takes its own room: the content starts below it, so it covers none of it and the
601
+ // content's controls take their own clicks. The layout eases the content down, so the check waits for it.
602
+ await expect.poll(async () => {
603
+ const { banner, content } = await measureBanner(page);
604
+ return content.filter((item) => overlaps(banner, item.rect)).map((item) => item.name);
605
+ }, { message: `${viewport.width}px ${theme}: the banner covers content below the app bar.` }).toEqual([]);
606
+ await answer.click({ trial: true, timeout: 2_000 });
607
+ // Closed, it gives its room back and the content starts where it did.
608
+ await page.locator(".shell-error-host__banner .v-alert__close .v-btn").first().click();
609
+ await expect(page.locator(".shell-error-host__banner")).toHaveCount(0);
610
+ await expect.poll(() => answer.evaluate((element) => element.getBoundingClientRect().top), {
611
+ message: `${viewport.width}px ${theme}: the content does not move back up once the banner closes.`
612
+ }).toBeCloseTo(contentTop, 0);
592
613
  await page.close();
593
614
  }
594
615
  }
@@ -13,7 +13,16 @@ import { useShellErrorPresentationStore } from "../src/client/stores/useShellErr
13
13
  import { silentLogger } from "@jskit-ai/kernel/shared/support/silentLogger";
14
14
 
15
15
  const componentUrl = new URL("../src/client/components/ShellErrorHost.vue", import.meta.url).href;
16
+ // The host imports VLayoutItem from Vuetify's own entry, whose CSS Node cannot load; like the other Vuetify
17
+ // components here, it is a stub.
18
+ const layoutStubUrl = `data:text/javascript,${encodeURIComponent(
19
+ "export const VLayoutItem = { name: \"VLayoutItem\", setup: (_props, { slots }) => () => slots.default?.() };"
20
+ )}`;
16
21
  const hooks = registerHooks({
22
+ resolve(specifier, context, nextResolve) {
23
+ if (specifier !== "vuetify/components/VLayout") return nextResolve(specifier, context);
24
+ return { url: layoutStubUrl, shortCircuit: true };
25
+ },
17
26
  load(url, context, nextLoad) {
18
27
  if (url !== componentUrl) return nextLoad(url, context);
19
28
  const { descriptor } = parse(readFileSync(new URL(url), "utf8"));
@@ -52,7 +61,10 @@ function fixture(t) {
52
61
  app.use(pinia);
53
62
  useShellErrorPresentationStore(pinia).attachRuntimeStore(store);
54
63
  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 }) });
64
+ app.provide(Symbol.for("vuetify:layout"), {
65
+ mainRect: shallowRef({ top: 0, left: 0, right: 0, bottom: 0 }),
66
+ getLayoutItem: () => undefined
67
+ });
56
68
  app.provide(Symbol.for("vuetify:display"), { width: shallowRef(1280), mobile: shallowRef(false) });
57
69
  globalThis.document = { documentElement: { style: { removeProperty() {} } }, querySelector: () => null };
58
70
  for (const name of ["VSnackbar", "VDialog", "VCard", "VCardTitle", "VCardText", "VCardActions", "VSpacer", "VAlert", "VBtn"]) {
@@ -37,14 +37,8 @@ test("an entry's actions list its action first and skip an empty one", () => {
37
37
  });
38
38
 
39
39
  test("banners float below a top app bar and join the page without one", () => {
40
- assert.deepEqual(resolveBannerPlacement({ top: 0 }), { inline: true, style: undefined });
41
- assert.deepEqual(resolveBannerPlacement({}), { inline: true, style: undefined });
42
- assert.deepEqual(resolveBannerPlacement({ top: 64, left: 256, right: 0 }), {
43
- inline: false,
44
- style: {
45
- top: "calc(env(safe-area-inset-top, 0px) + 64px)",
46
- left: "256px",
47
- right: "0px"
48
- }
49
- });
40
+ assert.deepEqual(resolveBannerPlacement(0), { inline: true });
41
+ assert.deepEqual(resolveBannerPlacement(), { inline: true });
42
+ assert.deepEqual(resolveBannerPlacement(Number.NaN), { inline: true });
43
+ assert.deepEqual(resolveBannerPlacement(64), { inline: false });
50
44
  });
@@ -457,13 +457,21 @@ test("shell-web packageMetadata pre-optimizes package subpaths reached through d
457
457
  ]);
458
458
 
459
459
  assert.deepEqual(packageMetadata?.metadata?.client?.optimizeDeps?.exclude, [
460
- "@jskit-ai/shell-web/client"
460
+ "@jskit-ai/shell-web/client",
461
+ "@jskit-ai/shell-web/client/ui"
461
462
  ]);
462
463
  });
463
464
 
464
465
  test("all public shell JavaScript helpers are ready in a cold dependency scan", async () => {
465
- // The provider loads application-owned /src modules. It and Vue components stay source.
466
- const sourceEntries = new Set(["./client", "./client/providers/ShellWebClientProvider"]);
466
+ // The client entry and the UI kit export Vue components, which a dependency scan cannot prebundle, so each stays
467
+ // source by its own name in the exclude, never through another entry's prefix. The provider loads application-owned
468
+ // /src modules; the client bootstrap keeps it source by its own subpath, as the client entry is.
469
+ const vueEntries = ["./client", "./client/ui"];
470
+ const sourceEntries = new Set([...vueEntries, "./client/providers/ShellWebClientProvider"]);
471
+ for (const entry of vueEntries) {
472
+ assert.ok(packageMetadata.metadata.client.optimizeDeps.exclude.includes(`${packageJson.name}${entry.slice(1)}`),
473
+ `${packageJson.name}${entry.slice(1)} exports Vue components, so it stays source by its own name in the exclude.`);
474
+ }
467
475
  const helpers = Object.entries(packageJson.exports)
468
476
  .filter(([entry, target]) => entry.startsWith("./client/") && target.endsWith(".js") && !sourceEntries.has(entry))
469
477
  .map(([entry]) => `${packageJson.name}${entry.slice(1)}`)
@@ -0,0 +1,99 @@
1
+ import assert from "node:assert/strict";
2
+ import { readFileSync } from "node:fs";
3
+ import test from "node:test";
4
+ import { fileURLToPath } from "node:url";
5
+ import { defineComponent } from "vue";
6
+ import {
7
+ MATERIAL_TEXT,
8
+ SHELL_UI_KEY,
9
+ SHELL_UI_ROLES,
10
+ SHELL_UI_TEXT_ROLES,
11
+ defineShellUi
12
+ } from "../src/client/ui/shellUi.js";
13
+ import { mountComposable } from "./support/mountComposable.js";
14
+
15
+ // Stand-ins for the Material button and dialog, which are Vue files a unit test cannot import.
16
+ const MaterialButton = defineComponent({ name: "MaterialButton", render: () => null });
17
+ const MaterialDialog = defineComponent({ name: "MaterialDialog", render: () => null });
18
+ const { provideShellUi, useShellUi } = defineShellUi({ Button: MaterialButton, Dialog: MaterialDialog, text: MATERIAL_TEXT });
19
+
20
+ function withKit(kit) {
21
+ return mountComposable(useShellUi, { plugins: [{ install: (app) => provideShellUi(app, kit) }] });
22
+ }
23
+
24
+ test("the kit's roles are a button, a dialog and seven text roles, whose Material classes are Material 3's type scale", () => {
25
+ assert.deepEqual(SHELL_UI_ROLES, ["Button", "Dialog", "text"]);
26
+ assert.deepEqual(SHELL_UI_TEXT_ROLES, ["title", "heading", "subheading", "strong", "lead", "body", "caption"]);
27
+ assert.deepEqual(MATERIAL_TEXT, {
28
+ title: "text-headline-medium",
29
+ heading: "text-title-large",
30
+ subheading: "text-title-medium",
31
+ strong: "text-title-small",
32
+ lead: "text-body-large",
33
+ body: "text-body-medium",
34
+ caption: "text-body-small"
35
+ });
36
+ assert.equal(SHELL_UI_KEY, "jskit.shell-web.ui.client");
37
+ });
38
+
39
+ test("an application that provides no kit gets the Material button, dialog and type classes", () => {
40
+ const { app, result } = mountComposable(useShellUi);
41
+ assert.equal(result.Button, MaterialButton);
42
+ assert.equal(result.Dialog, MaterialDialog);
43
+ assert.deepEqual(result.text, MATERIAL_TEXT);
44
+ app.unmount();
45
+ });
46
+
47
+ test("a partial kit replaces only the roles it names, and a partial text map only its own text roles", () => {
48
+ const AppButton = defineComponent({ name: "AppButton", render: () => null });
49
+ const { app, result } = withKit({ Button: AppButton, text: { title: "app-title", body: "app-body" } });
50
+ assert.equal(result.Button, AppButton);
51
+ assert.equal(result.Dialog, MaterialDialog);
52
+ assert.deepEqual(result.text, { ...MATERIAL_TEXT, title: "app-title", body: "app-body" });
53
+ assert.equal(Object.isFrozen(result), true);
54
+ assert.equal(Object.isFrozen(result.text), true);
55
+ app.unmount();
56
+ });
57
+
58
+ test("a functional component is a component, and an empty text class draws the role with no class", () => {
59
+ const AppDialog = () => null;
60
+ const { app, result } = withKit({ Dialog: AppDialog, text: { caption: "" } });
61
+ assert.equal(result.Dialog, AppDialog);
62
+ assert.equal(result.text.caption, "");
63
+ app.unmount();
64
+ });
65
+
66
+ test("a kit with an unknown role, an unknown text role, a role that is not a component or a class that is not a string is refused", () => {
67
+ const app = { provide: () => assert.fail("a refused kit is never provided") };
68
+ assert.throws(() => provideShellUi(app, { Buton: MaterialButton }), /Shell UI role "Buton" is not one of Button, Dialog, text\./u);
69
+ assert.throws(
70
+ () => provideShellUi(app, { text: { headline: "x" } }),
71
+ /Shell UI text role "headline" is not one of title, heading, subheading, strong, lead, body, caption\./u
72
+ );
73
+ assert.throws(() => provideShellUi(app, { Button: "AppButton" }), /Shell UI role "Button" needs a Vue component, not "AppButton"\./u);
74
+ assert.throws(() => provideShellUi(app, { Dialog: null }), /Shell UI role "Dialog" needs a Vue component, not null\./u);
75
+ assert.throws(() => provideShellUi(app, { text: { body: 14 } }), /Shell UI text role "body" needs a class name, not 14\./u);
76
+ assert.throws(() => provideShellUi(app, { text: ["app-title"] }), /Shell UI role "text" needs an object of class names by text role\./u);
77
+ assert.throws(() => provideShellUi(app, "kit"), /provideShellUi needs a kit object/u);
78
+ });
79
+
80
+ test("shell-web exports the kit at ./client/ui, with the Material button and dialog as its defaults", () => {
81
+ const packageJson = JSON.parse(readFileSync(fileURLToPath(new URL("../package.json", import.meta.url)), "utf8"));
82
+ assert.equal(packageJson.exports["./client/ui"], "./src/client/ui/index.js");
83
+ const index = readFileSync(fileURLToPath(new URL("../src/client/ui/index.js", import.meta.url)), "utf8");
84
+ assert.match(index, /import ShellUiButton from "\.\/ShellUiButton\.vue";/u);
85
+ assert.match(index, /import ShellUiDialog from "\.\/ShellUiDialog\.vue";/u);
86
+ assert.match(index, /defineShellUi\(\{ Button: ShellUiButton, Dialog: ShellUiDialog, text: MATERIAL_TEXT \}\)/u);
87
+ assert.match(index, /export \{[^}]*\bprovideShellUi\b[^}]*\buseShellUi\b[^}]*\}/u);
88
+ });
89
+
90
+ test("the Material button draws each emphasis and tone as the Vuetify button the auth screens drew before the kit", () => {
91
+ const button = readFileSync(fileURLToPath(new URL("../src/client/ui/ShellUiButton.vue", import.meta.url)), "utf8");
92
+ assert.match(button, /high: "flat"/u);
93
+ assert.match(button, /medium: "tonal"/u);
94
+ assert.match(button, /subtle: "outlined"/u);
95
+ assert.match(button, /low: "text"/u);
96
+ assert.match(button, /accent: "primary"/u);
97
+ assert.match(button, /neutral: "secondary"/u);
98
+ assert.match(button, /danger: "error"/u);
99
+ });
@@ -1,6 +1,6 @@
1
1
  import assert from "node:assert/strict";
2
2
  import test from "node:test";
3
- import { markRaw, nextTick, ref, shallowRef } from "vue";
3
+ import { markRaw, nextTick, reactive, ref, shallowRef } from "vue";
4
4
  import { createPinia } from "pinia";
5
5
  import { useShellErrorHost } from "../src/client/composables/useShellErrorHost.js";
6
6
  import { SHELL_WEB_ERROR_RUNTIME_KEY } from "../src/client/error/inject.js";
@@ -46,16 +46,18 @@ function mountHost(t, { top = 0, width = 1280 } = {}) {
46
46
  useShellErrorPresentationStore(pinia).attachRuntimeStore(store);
47
47
  const reports = [];
48
48
  const layoutRect = shallowRef({ top, left: 0, right: 0, bottom: 0 });
49
+ // The layout items Vuetify has placed, by name, each with the rect it starts at.
50
+ const layoutItems = reactive(new Map());
49
51
  const windowWidth = ref(width);
50
52
  const { app, result } = mountComposable(useShellErrorHost, {
51
53
  plugins: [pinia],
52
54
  provide: [
53
55
  [SHELL_WEB_ERROR_RUNTIME_KEY, { report: (event) => reports.push(event) }],
54
- [Symbol.for("vuetify:layout"), { mainRect: layoutRect }],
56
+ [Symbol.for("vuetify:layout"), { mainRect: layoutRect, getLayoutItem: (name) => layoutItems.get(name) }],
55
57
  [Symbol.for("vuetify:display"), { width: windowWidth, mobile: ref(false) }]
56
58
  ]
57
59
  });
58
- return { app, heights, host: result, layoutRect, observers, openSurfaces, reports, store, windowWidth };
60
+ return { app, heights, host: result, layoutItems, layoutRect, observers, openSurfaces, reports, store, windowWidth };
59
61
  }
60
62
 
61
63
  test("snackbars show one at a time and the next opens after the last one leaves", async (t) => {
@@ -181,3 +183,45 @@ test("inline banners publish their height and withdraw it when they float or go"
181
183
  app.unmount();
182
184
  assert.equal(heights.size, 0);
183
185
  });
186
+
187
+ test("below an app bar the banners take a top layout item of their own height, so the content starts below them", async (t) => {
188
+ const { app, heights, host, layoutItems, layoutRect } = mountHost(t, { top: 64 });
189
+ const element = markRaw({ getBoundingClientRect: () => ({ height: 40.2 }) });
190
+ assert.equal(host.bannerPlacement.value.inline, false);
191
+
192
+ host.bannersElement.value = element;
193
+ await nextTick();
194
+ assert.deepEqual(host.bannerLayoutItemProps.value, {
195
+ name: "shell-error-host-banners",
196
+ order: 1,
197
+ position: "top",
198
+ size: 41,
199
+ modelValue: true,
200
+ style: { zIndex: 2600 }
201
+ });
202
+ assert.equal(heights.size, 0, "Only inline banners publish their height.");
203
+
204
+ // Vuetify places the item under the app bar and starts the content below both: the banners still float.
205
+ layoutItems.set("shell-error-host-banners", { top: 64, left: 0, right: 0, bottom: 0, size: 41, position: "top" });
206
+ layoutRect.value = { top: 105, left: 0, right: 0, bottom: 0 };
207
+ await nextTick();
208
+ assert.equal(host.bannerPlacement.value.inline, false);
209
+ assert.equal(host.bannerLayoutItemProps.value.size, 41);
210
+
211
+ // Without the app bar they start at the top: they join the page flow and give the layout their room back.
212
+ layoutItems.set("shell-error-host-banners", { top: 0, left: 0, right: 0, bottom: 0, size: 41, position: "top" });
213
+ await nextTick();
214
+ assert.equal(host.bannerPlacement.value.inline, true);
215
+ assert.equal(host.bannerLayoutItemProps.value.size, 0);
216
+ assert.equal(heights.get("--shell-error-banners-inline-height"), "41px");
217
+
218
+ layoutItems.delete("shell-error-host-banners");
219
+ layoutRect.value = { top: 64, left: 0, right: 0, bottom: 0 };
220
+ await nextTick();
221
+ assert.equal(host.bannerLayoutItemProps.value.size, 41);
222
+ host.bannersElement.value = null;
223
+ await nextTick();
224
+ assert.equal(host.bannerLayoutItemProps.value.size, 0, "Banners that go give their room back.");
225
+ assert.equal(heights.size, 0);
226
+ app.unmount();
227
+ });