@jskit-ai/shell-web 0.2.50 → 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,7 @@
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`.
5
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.
6
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.
7
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").
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/shell-web",
3
- "version": "0.2.50",
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
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
@@ -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 };
@@ -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
+ });