@mccaskie-labs/workbench-ui 0.5.0 → 0.6.0
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 +12 -0
- package/README.md +30 -3
- package/dist/cli.d.ts +4 -0
- package/dist/cli.js +45 -11
- package/dist/index.d.ts +54 -2
- package/dist/index.js +84 -2
- package/dist/style.d.ts +8 -0
- package/dist/style.js +24 -3
- package/dist/styles.d.ts +9 -1
- package/dist/styles.js +21 -4
- package/dist/ui-styles.js +134 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @mccaskie-labs/workbench-ui
|
|
2
2
|
|
|
3
|
+
## 0.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- workbench-ui: the page parts, so what a page puts inside its cards is restyleable too. `body`, `note`, `message`, `small`, `button`, `actions`, `input`, `select`, `textarea`, `field`, `check`, `table`, `facts`, `more` and `code` each draw `wb-ui-*` classes listed in `UI_STYLES` with a default look (new variable `--wb-ui-input-width`). Attributes passed to `button`, `input`, `select`, `textarea` and `check` are escaped, and `class` or an `on…` handler is refused. Breaking for a project's generated `workbench.css`: its page layer is now `BASE_CSS` (box sizing, links, code, h2, the spinner's keyframes and reduced motion, each scoped to `html.wb-ui` inside `:where()`), not the older unprefixed conventions (`.body`, `.note`, `.warn`, `.small`, bare `button`, `input` and `table` rules), which stay in `STYLE` and `CSS` for Workbench's own pages; a project page that used them moves to the page parts. `npx workbench-ui styles --check` also fails when the project's own pages (`src/`, `public/`, not tests) put a `wb-` class on an element that no installed tool draws (`unknownMarkupNames`, `markupFiles`). workbench-config: the ui manifest lists the page parts, and its no-own-colours rule names the `--wb-ui-*` variables.
|
|
8
|
+
|
|
9
|
+
## 0.5.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- `npx workbench-ui styles` takes every `ToolStyles` a package exports at `./styles`, one per tool, each with its own prefix (was exactly one), so workbench-availability 0.2.0's calendar (`wb-cal-`) and onboarding cards (`wb-onboard-`) both reach workbench.css.
|
|
14
|
+
|
|
3
15
|
## 0.5.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -7,13 +7,13 @@ npm install @mccaskie-labs/workbench-ui
|
|
|
7
7
|
```
|
|
8
8
|
|
|
9
9
|
```ts
|
|
10
|
-
import { card, pill, shell, shortWhen, topBar } from '@mccaskie-labs/workbench-ui'
|
|
10
|
+
import { body, card, pill, shell, shortWhen, topBar } from '@mccaskie-labs/workbench-ui'
|
|
11
11
|
|
|
12
12
|
const html = shell({
|
|
13
13
|
title: 'Probes',
|
|
14
14
|
site: 'wb-probe',
|
|
15
15
|
top: topBar({ name: 'wb-probe', href: '/', env: 'staging', links: [['History', '/runs'], ['Compare', '/compare']] }),
|
|
16
|
-
body: card('Last run',
|
|
16
|
+
body: card('Last run', body(`${pill('pass', 'Passed')} ${shortWhen(run.started_at)}`), { about: 'The most recent full check.' }),
|
|
17
17
|
})
|
|
18
18
|
```
|
|
19
19
|
|
|
@@ -32,7 +32,34 @@ Everything returns HTML text. Arguments described as plain text are escaped; arg
|
|
|
32
32
|
| `money(usd)`, `duration(ms)` | "US$0.0042", "US$12.50"; "640 ms", "2.35 s", "3 min 5 s". Nothing to show is an en dash |
|
|
33
33
|
| `escape(text)` | Plain text made safe for HTML |
|
|
34
34
|
| `STYLE`, `CSS` | The stylesheet, as a `<style>` tag and as bare rules, for a page that builds its own document |
|
|
35
|
+
| `UI_STYLES`, `BASE_CSS` | Every `wb-ui-*` class and `--wb-ui-*` variable with its default look (also at `./styles`), and the few scoped rules a project's generated `workbench.css` carries besides them |
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
### Page parts
|
|
38
|
+
|
|
39
|
+
What goes inside a card. Each draws a `wb-ui-*` class with a default look, so a page needs no markup or colours of its own, and a project restyles every one in its `public/styles/project.css`.
|
|
40
|
+
|
|
41
|
+
| Export | Draws |
|
|
42
|
+
| --- | --- |
|
|
43
|
+
| `body(html)` | A card's contents, padded (`wb-ui-body`) |
|
|
44
|
+
| `note(html, tone?)` | A boxed note with a coloured edge: `info`, `pass`, `warn` or `fail` (`wb-ui-note`) |
|
|
45
|
+
| `message(tone, text, { id? })` | One line on what just happened, "Saved." or "That code has expired.", as a status or an alert (`wb-ui-message`) |
|
|
46
|
+
| `small(html)` | Small print (`wb-ui-small`) |
|
|
47
|
+
| `button(text, { kind?, type?, attrs? })` | A button: `primary`, `secondary` or `link` (`wb-ui-button`) |
|
|
48
|
+
| `actions(html)` | A row of buttons and their forms (`wb-ui-actions`) |
|
|
49
|
+
| `input(attrs)`, `select(attrs, options, selected?)`, `textarea(attrs, text?)` | A control (`wb-ui-input`). Attributes are escaped; `class` and `on…` are refused |
|
|
50
|
+
| `field(label, id, control, { hint? })` | A label over its control, then a hint with the id `<id>-hint` (`wb-ui-field`) |
|
|
51
|
+
| `check(label, attrs)` | A tick box with its words (`wb-ui-check`) |
|
|
52
|
+
| `table(headings, rows)` | A table that scrolls sideways on a narrow screen; a row can be `{ cells, tone }` (`wb-ui-table`) |
|
|
53
|
+
| `facts([[label, html]])` | Labels and their values (`wb-ui-facts`) |
|
|
54
|
+
| `more(label, html)` | More detail, folded until asked for (`wb-ui-more`) |
|
|
55
|
+
| `code(text)` | Exact text kept as it is (`wb-ui-code`) |
|
|
56
|
+
|
|
57
|
+
For a form whose answers are checked, use workbench-forms' `renderForm` instead of `field` and `input`.
|
|
58
|
+
|
|
59
|
+
Pages are always dark, whatever the computer is set to. A page with its own rules adds them after the shared ones and uses the colour variables (`--wb-ui-surface`, `--wb-ui-line`, `--wb-ui-pass` and so on), never its own colours.
|
|
60
|
+
|
|
61
|
+
### Restyling in a project
|
|
62
|
+
|
|
63
|
+
`npx workbench-ui styles` writes the project's `public/styles/workbench.css` from every installed Workbench tool, and `npx workbench-ui styles --check` (in Checks) fails when it is stale, when `project.css` names a `wb-` class or variable no tool draws, or when the project's own pages (`src/`, `public/`) put such a class on an element. The older page conventions (`.body`, `.note`, `.warn`, bare buttons and tables) are only in `STYLE` and `CSS`, for Workbench's own pages: a project's workbench.css leaves them out, so they never reach a client's own markup.
|
|
37
64
|
|
|
38
65
|
Runs on Node 24 and the Cloudflare Workers runtime. No dependencies.
|
package/dist/cli.d.ts
CHANGED
|
@@ -5,6 +5,10 @@ export declare function installedStyles(dir: string): Promise<{
|
|
|
5
5
|
tools: InstalledStyles[];
|
|
6
6
|
uiVersion: string;
|
|
7
7
|
}>;
|
|
8
|
+
/** Where a project's own pages are written, from its root. */
|
|
9
|
+
export declare const MARKUP_DIRS: readonly string[];
|
|
10
|
+
/** The project's own source files that can hold markup: code and HTML under src/ and public/, not tests, builds or stylesheets. */
|
|
11
|
+
export declare function markupFiles(dir: string): string[];
|
|
8
12
|
export interface StylesPlan {
|
|
9
13
|
/** Files to write, by path relative to the project. */
|
|
10
14
|
files: Record<string, string>;
|
package/dist/cli.js
CHANGED
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
// (docs/capabilities-manifest.md §10), and public/styles/project.css if the
|
|
5
5
|
// project has none yet (it is the project's own, so never overwritten). With
|
|
6
6
|
// --check it writes nothing and fails when workbench.css differs from what the
|
|
7
|
-
// installed packages draw,
|
|
8
|
-
// that no installed tool draws any more (a rename after an update)
|
|
7
|
+
// installed packages draw, when project.css names a wb- class or variable
|
|
8
|
+
// that no installed tool draws any more (a rename after an update), or when the
|
|
9
|
+
// project's own pages (src/ and public/) put such a class on an element.
|
|
9
10
|
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
10
11
|
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
11
12
|
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
@@ -14,12 +15,12 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
|
|
|
14
15
|
}
|
|
15
16
|
return path;
|
|
16
17
|
};
|
|
17
|
-
import { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
|
|
18
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
|
|
18
19
|
import { createRequire } from "node:module";
|
|
19
|
-
import { dirname, join, resolve } from "node:path";
|
|
20
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
20
21
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
21
22
|
import { UI_STYLES } from "./ui-styles.js";
|
|
22
|
-
import { renderStyles, STYLE_FILES, STYLED_SCOPE, starterProjectCss, unknownNames } from "./styles.js";
|
|
23
|
+
import { renderStyles, STYLE_FILES, STYLED_SCOPE, starterProjectCss, unknownMarkupNames, unknownNames } from "./styles.js";
|
|
23
24
|
const USAGE = "usage: workbench-ui styles [--check] [dir]";
|
|
24
25
|
const read = (path) => readFileSync(path, "utf8").replace(/\r\n/g, "\n");
|
|
25
26
|
/** The styles of each Workbench tool the project at `dir` has installed, and the workbench-ui version. */
|
|
@@ -47,18 +48,44 @@ export async function installedStyles(dir) {
|
|
|
47
48
|
continue;
|
|
48
49
|
const mod = (await import(__rewriteRelativeImportExtension(pathToFileURL(req.resolve(`${name}/styles`)).href)));
|
|
49
50
|
const found = Object.values(mod).filter((x) => !!x && typeof x === "object" && x.format === 1 && typeof x.prefix === "string");
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
// One ToolStyles per tool the package draws (workbench-availability has the calendar and onboarding), each with its own prefix.
|
|
52
|
+
if (found.length === 0)
|
|
53
|
+
throw new Error(`${name}/styles must export at least one ToolStyles`);
|
|
54
|
+
if (new Set(found.map((f) => f.prefix)).size !== found.length)
|
|
55
|
+
throw new Error(`${name}/styles exports two ToolStyles with one prefix`);
|
|
56
|
+
for (const f of found.sort((a, b) => (a.prefix < b.prefix ? -1 : 1)))
|
|
57
|
+
tools.push({ styles: f, version: manifest.version });
|
|
53
58
|
}
|
|
54
59
|
const own = JSON.parse(read(resolve(dirname(fileURLToPath(import.meta.url)), "../package.json")));
|
|
55
60
|
const uiVersion = version("@mccaskie-labs/workbench-ui") ?? own.version;
|
|
56
61
|
// The page look's own classes are always there: this command is workbench-ui.
|
|
57
62
|
if (!tools.some((t) => t.styles.package === UI_STYLES.package))
|
|
58
63
|
tools.push({ styles: UI_STYLES, version: uiVersion });
|
|
59
|
-
tools.sort((a, b) => (a.styles.package < b.styles.package ? -1 : 1));
|
|
64
|
+
tools.sort((a, b) => (a.styles.package < b.styles.package ? -1 : a.styles.package > b.styles.package ? 1 : a.styles.prefix < b.styles.prefix ? -1 : 1));
|
|
60
65
|
return { tools, uiVersion };
|
|
61
66
|
}
|
|
67
|
+
/** Where a project's own pages are written, from its root. */
|
|
68
|
+
export const MARKUP_DIRS = ["src", "public"];
|
|
69
|
+
const MARKUP = /\.(?:[cm]?[jt]sx?|html?)$/;
|
|
70
|
+
const NOT_MARKUP = new Set(["node_modules", "dist", ".wrangler", "test", "tests", "__tests__"]);
|
|
71
|
+
/** The project's own source files that can hold markup: code and HTML under src/ and public/, not tests, builds or stylesheets. */
|
|
72
|
+
export function markupFiles(dir) {
|
|
73
|
+
const out = [];
|
|
74
|
+
const walk = (at) => {
|
|
75
|
+
for (const e of readdirSync(at, { withFileTypes: true })) {
|
|
76
|
+
if (e.isDirectory()) {
|
|
77
|
+
if (!NOT_MARKUP.has(e.name) && !e.name.startsWith("."))
|
|
78
|
+
walk(join(at, e.name));
|
|
79
|
+
}
|
|
80
|
+
else if (e.isFile() && MARKUP.test(e.name) && !/\.(?:test|spec)\./.test(e.name) && !e.name.endsWith(".d.ts"))
|
|
81
|
+
out.push(join(at, e.name));
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
for (const d of MARKUP_DIRS)
|
|
85
|
+
if (existsSync(join(dir, d)))
|
|
86
|
+
walk(join(dir, d));
|
|
87
|
+
return out.sort();
|
|
88
|
+
}
|
|
62
89
|
/** What `styles` writes in `dir`, and what --check would fail on, without touching the disk. */
|
|
63
90
|
export function planStyles(dir, tools, uiVersion) {
|
|
64
91
|
const files = {};
|
|
@@ -79,6 +106,12 @@ export function planStyles(dir, tools, uiVersion) {
|
|
|
79
106
|
if (unknown.length)
|
|
80
107
|
problems.push(`${STYLE_FILES.project} names ${unknown.join(", ")}, which no installed Workbench tool draws (renamed or removed: see workbench.css)`);
|
|
81
108
|
}
|
|
109
|
+
for (const file of markupFiles(dir)) {
|
|
110
|
+
const unknown = unknownMarkupNames(read(file), tools);
|
|
111
|
+
const at = relative(dir, file).replace(/\\/g, "/");
|
|
112
|
+
if (unknown.length)
|
|
113
|
+
problems.push(`${at} puts ${unknown.join(", ")} on an element, which no installed Workbench tool draws (renamed or removed: see workbench.css)`);
|
|
114
|
+
}
|
|
82
115
|
return { files, problems };
|
|
83
116
|
}
|
|
84
117
|
async function main(argv) {
|
|
@@ -103,7 +136,7 @@ async function main(argv) {
|
|
|
103
136
|
}
|
|
104
137
|
for (const p of plan.problems)
|
|
105
138
|
console.error(p);
|
|
106
|
-
console.error("Run `npx workbench-ui styles` and commit the result; fix project.css by hand.");
|
|
139
|
+
console.error("Run `npx workbench-ui styles` and commit the result; fix project.css and the pages named by hand.");
|
|
107
140
|
return 1;
|
|
108
141
|
}
|
|
109
142
|
for (const [path, text] of Object.entries(plan.files)) {
|
|
@@ -111,7 +144,8 @@ async function main(argv) {
|
|
|
111
144
|
writeFileSync(join(dir, path), text);
|
|
112
145
|
console.log(`wrote ${path}`);
|
|
113
146
|
}
|
|
114
|
-
|
|
147
|
+
// Writing fixes workbench.css; project.css and the project's own pages are fixed by hand.
|
|
148
|
+
const left = plan.problems.filter((p) => !p.startsWith(STYLE_FILES.generated) && !(p.startsWith(STYLE_FILES.project) && plan.files[STYLE_FILES.project]));
|
|
115
149
|
for (const p of left)
|
|
116
150
|
console.error(p);
|
|
117
151
|
return left.length ? 1 : 0;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { CSS, STYLE, UI_CSS } from "./style.ts";
|
|
1
|
+
export { BASE_CSS, CSS, STYLE, UI_CSS } from "./style.ts";
|
|
2
2
|
export { UI_STYLES } from "./ui-styles.ts";
|
|
3
3
|
export { FORM_SCRIPT } from "./form-script.ts";
|
|
4
|
-
export { renderStyles, STYLE_FILES, STYLED_SCOPE, styleNames, styleProblems, STYLESHEETS, starterProjectCss, unknownNames, type InstalledStyles, type StyleClass, type StyleState, type StyleVariable, type ToolStyles, } from "./styles.ts";
|
|
4
|
+
export { renderStyles, STYLE_FILES, STYLED_SCOPE, styleNames, styleProblems, STYLESHEETS, starterProjectCss, unknownMarkupNames, unknownNames, type InstalledStyles, type StyleClass, type StyleState, type StyleVariable, type ToolStyles, } from "./styles.ts";
|
|
5
5
|
/** Plain text made safe to put in HTML, in text or in a quoted attribute. */
|
|
6
6
|
export declare const escape: (value: string) => string;
|
|
7
7
|
/** The outcome colours: a pill's class and, prefixed with o-, a table row's left edge. */
|
|
@@ -67,6 +67,58 @@ export declare function jumpNav(items: readonly JumpItem[]): string;
|
|
|
67
67
|
* Put it in a <script> with the response's nonce.
|
|
68
68
|
*/
|
|
69
69
|
export declare const SECTIONS_SCRIPT: string;
|
|
70
|
+
/** The tone of a note or a message: info (a note only), pass, warn or fail. */
|
|
71
|
+
export type Says = "info" | "pass" | "warn" | "fail";
|
|
72
|
+
/** A card's contents, padded inside the card. `inner` is HTML. */
|
|
73
|
+
export declare function body(inner: string): string;
|
|
74
|
+
/** A boxed note with a coloured edge: `pass` for good news, `warn` for worth a look, `fail` for a problem. `inner` is HTML. */
|
|
75
|
+
export declare function note(inner: string, tone?: Says): string;
|
|
76
|
+
/** One line saying what just happened, such as "Saved." or "That code has expired." `text` is plain text. */
|
|
77
|
+
export declare function message(tone: Exclude<Says, "info">, text: string, opts?: {
|
|
78
|
+
id?: string;
|
|
79
|
+
}): string;
|
|
80
|
+
/** Small print: a hint, a footnote or a quieter link. `inner` is HTML. */
|
|
81
|
+
export declare function small(inner: string): string;
|
|
82
|
+
/** Attributes for a tag, escaped: `true` writes the bare name, and `false`, null or undefined leaves it out. */
|
|
83
|
+
export type Attrs = Readonly<Record<string, string | number | boolean | null | undefined>>;
|
|
84
|
+
export interface ButtonOptions {
|
|
85
|
+
/** primary (filled, the default), secondary (outlined) or link (looks like a link). */
|
|
86
|
+
kind?: "primary" | "secondary" | "link";
|
|
87
|
+
/** submit (the default) or button. */
|
|
88
|
+
type?: "submit" | "button";
|
|
89
|
+
/** More attributes, such as name, value, id or disabled. */
|
|
90
|
+
attrs?: Attrs;
|
|
91
|
+
}
|
|
92
|
+
/** A button. `text` is plain text. */
|
|
93
|
+
export declare function button(text: string, opts?: ButtonOptions): string;
|
|
94
|
+
/** A row of buttons, and of the small forms around them. `inner` is HTML. */
|
|
95
|
+
export declare function actions(inner: string): string;
|
|
96
|
+
/** A one-line control. `a` holds its attributes (id, name, type, value, required and so on). */
|
|
97
|
+
export declare function input(a: Attrs): string;
|
|
98
|
+
/** A text area holding `text`, which is plain text. */
|
|
99
|
+
export declare function textarea(a: Attrs, text?: string): string;
|
|
100
|
+
/** A drop-down list of [value, label] pairs, with `selected` chosen. Both are plain text. */
|
|
101
|
+
export declare function select(a: Attrs, options: readonly (readonly [value: string, label: string])[], selected?: string): string;
|
|
102
|
+
/** A labelled control: the label over `control` (HTML from input, select or textarea, whose id is `id`), then an optional hint. */
|
|
103
|
+
export declare function field(label: string, id: string, control: string, opts?: {
|
|
104
|
+
hint?: string;
|
|
105
|
+
}): string;
|
|
106
|
+
/** A tick box with its words. `label` is plain text; `a` holds the box's attributes (name, value, checked). */
|
|
107
|
+
export declare function check(label: string, a: Attrs): string;
|
|
108
|
+
export interface TableRow {
|
|
109
|
+
/** The cells, as HTML. */
|
|
110
|
+
cells: readonly string[];
|
|
111
|
+
/** Colours the edge of the row's first cell (and a failed row's background). */
|
|
112
|
+
tone?: Tone;
|
|
113
|
+
}
|
|
114
|
+
/** A table that scrolls sideways on a narrow screen. Headings are plain text; cells are HTML. */
|
|
115
|
+
export declare function table(headings: readonly string[], rows: readonly (TableRow | readonly string[])[]): string;
|
|
116
|
+
/** Pairs of a label (plain text) and its value (HTML). */
|
|
117
|
+
export declare function facts(pairs: readonly (readonly [label: string, value: string])[]): string;
|
|
118
|
+
/** More detail folded away until asked for. `label` is plain text; `inner` is HTML. */
|
|
119
|
+
export declare function more(label: string, inner: string): string;
|
|
120
|
+
/** Exact text kept as it is, such as a reply or a log line. `text` is plain text. */
|
|
121
|
+
export declare function code(text: string): string;
|
|
70
122
|
/** A time in full: Manila first, where Robert is, then UTC. */
|
|
71
123
|
export declare function when(iso: string): string;
|
|
72
124
|
/** A short Manila time for table rows, with the UTC time on hover. */
|
package/dist/index.js
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
// Everything here returns HTML text; every value given as plain text is
|
|
4
4
|
// escaped here, and arguments documented as HTML are trusted as they are.
|
|
5
5
|
import { STYLE } from "./style.js";
|
|
6
|
-
export { CSS, STYLE, UI_CSS } from "./style.js";
|
|
6
|
+
export { BASE_CSS, CSS, STYLE, UI_CSS } from "./style.js";
|
|
7
7
|
export { UI_STYLES } from "./ui-styles.js";
|
|
8
8
|
export { FORM_SCRIPT } from "./form-script.js";
|
|
9
|
-
export { renderStyles, STYLE_FILES, STYLED_SCOPE, styleNames, styleProblems, STYLESHEETS, starterProjectCss, unknownNames, } from "./styles.js";
|
|
9
|
+
export { renderStyles, STYLE_FILES, STYLED_SCOPE, styleNames, styleProblems, STYLESHEETS, starterProjectCss, unknownMarkupNames, unknownNames, } from "./styles.js";
|
|
10
10
|
/** Plain text made safe to put in HTML, in text or in a quoted attribute. */
|
|
11
11
|
export const escape = (value) => value.replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
12
12
|
/** A coloured outcome pill. `text` is plain text. */
|
|
@@ -76,6 +76,88 @@ export const SECTIONS_SCRIPT = `(() => {
|
|
|
76
76
|
addEventListener("hashchange", () => show(named(location.hash), true));
|
|
77
77
|
for (const a of document.querySelectorAll("a.wb-ui-jump-link")) a.addEventListener("click", () => show(named(a.hash), false));
|
|
78
78
|
})();`;
|
|
79
|
+
/** A card's contents, padded inside the card. `inner` is HTML. */
|
|
80
|
+
export function body(inner) {
|
|
81
|
+
return `<div class="wb-ui-body">${inner}</div>`;
|
|
82
|
+
}
|
|
83
|
+
/** A boxed note with a coloured edge: `pass` for good news, `warn` for worth a look, `fail` for a problem. `inner` is HTML. */
|
|
84
|
+
export function note(inner, tone = "info") {
|
|
85
|
+
const role = tone === "fail" ? ' role="alert"' : tone === "info" ? "" : ' role="status"';
|
|
86
|
+
return `<div class="wb-ui-note" data-tone="${tone}"${role}>${inner}</div>`;
|
|
87
|
+
}
|
|
88
|
+
/** One line saying what just happened, such as "Saved." or "That code has expired." `text` is plain text. */
|
|
89
|
+
export function message(tone, text, opts = {}) {
|
|
90
|
+
const id = opts.id ? ` id="${escape(opts.id)}"` : "";
|
|
91
|
+
return `<p class="wb-ui-message" data-tone="${tone}" role="${tone === "fail" ? "alert" : "status"}"${id}>${escape(text)}</p>`;
|
|
92
|
+
}
|
|
93
|
+
/** Small print: a hint, a footnote or a quieter link. `inner` is HTML. */
|
|
94
|
+
export function small(inner) {
|
|
95
|
+
return `<p class="wb-ui-small">${inner}</p>`;
|
|
96
|
+
}
|
|
97
|
+
const NAME = /^[a-zA-Z_:][a-zA-Z0-9_:.-]*$/;
|
|
98
|
+
function attrs(a) {
|
|
99
|
+
let out = "";
|
|
100
|
+
for (const [k, val] of Object.entries(a)) {
|
|
101
|
+
if (!NAME.test(k) || k.toLowerCase() === "class" || /^on/i.test(k))
|
|
102
|
+
throw new Error(`workbench-ui: attribute ${k} can't be set here`);
|
|
103
|
+
if (val === false || val === null || val === undefined)
|
|
104
|
+
continue;
|
|
105
|
+
out += val === true ? ` ${k}` : ` ${k}="${escape(String(val))}"`;
|
|
106
|
+
}
|
|
107
|
+
return out;
|
|
108
|
+
}
|
|
109
|
+
/** A button. `text` is plain text. */
|
|
110
|
+
export function button(text, opts = {}) {
|
|
111
|
+
return `<button class="wb-ui-button" data-kind="${opts.kind ?? "primary"}"${attrs({ type: opts.type ?? "submit", ...opts.attrs })}>${escape(text)}</button>`;
|
|
112
|
+
}
|
|
113
|
+
/** A row of buttons, and of the small forms around them. `inner` is HTML. */
|
|
114
|
+
export function actions(inner) {
|
|
115
|
+
return `<div class="wb-ui-actions">${inner}</div>`;
|
|
116
|
+
}
|
|
117
|
+
/** A one-line control. `a` holds its attributes (id, name, type, value, required and so on). */
|
|
118
|
+
export function input(a) {
|
|
119
|
+
return `<input class="wb-ui-input"${attrs(a)}>`;
|
|
120
|
+
}
|
|
121
|
+
/** A text area holding `text`, which is plain text. */
|
|
122
|
+
export function textarea(a, text = "") {
|
|
123
|
+
return `<textarea class="wb-ui-input"${attrs(a)}>${escape(text)}</textarea>`;
|
|
124
|
+
}
|
|
125
|
+
/** A drop-down list of [value, label] pairs, with `selected` chosen. Both are plain text. */
|
|
126
|
+
export function select(a, options, selected) {
|
|
127
|
+
const opts = options.map(([value, label]) => `<option class="wb-ui-option" value="${escape(value)}"${value === selected ? " selected" : ""}>${escape(label)}</option>`).join("");
|
|
128
|
+
return `<select class="wb-ui-input"${attrs(a)}>${opts}</select>`;
|
|
129
|
+
}
|
|
130
|
+
/** A labelled control: the label over `control` (HTML from input, select or textarea, whose id is `id`), then an optional hint. */
|
|
131
|
+
export function field(label, id, control, opts = {}) {
|
|
132
|
+
const hint = opts.hint ? `<span class="wb-ui-hint" id="${escape(id)}-hint">${escape(opts.hint)}</span>` : "";
|
|
133
|
+
return `<p class="wb-ui-field"><label class="wb-ui-label" for="${escape(id)}">${escape(label)}</label>${control}${hint}</p>`;
|
|
134
|
+
}
|
|
135
|
+
/** A tick box with its words. `label` is plain text; `a` holds the box's attributes (name, value, checked). */
|
|
136
|
+
export function check(label, a) {
|
|
137
|
+
return `<label class="wb-ui-check"><input class="wb-ui-check-box" type="checkbox"${attrs(a)}> <span class="wb-ui-check-text">${escape(label)}</span></label>`;
|
|
138
|
+
}
|
|
139
|
+
/** A table that scrolls sideways on a narrow screen. Headings are plain text; cells are HTML. */
|
|
140
|
+
export function table(headings, rows) {
|
|
141
|
+
const head = `<thead class="wb-ui-table-head"><tr class="wb-ui-table-row">${headings.map((h) => `<th class="wb-ui-table-heading" scope="col">${escape(h)}</th>`).join("")}</tr></thead>`;
|
|
142
|
+
const lines = rows.map((r) => {
|
|
143
|
+
const row = "cells" in r ? r : { cells: r };
|
|
144
|
+
const tone = row.tone ? ` data-tone="${row.tone}"` : "";
|
|
145
|
+
return `<tr class="wb-ui-table-row"${tone}>${row.cells.map((c) => `<td class="wb-ui-table-cell">${c}</td>`).join("")}</tr>`;
|
|
146
|
+
});
|
|
147
|
+
return `<div class="wb-ui-scroll"><table class="wb-ui-table">${head}<tbody class="wb-ui-table-body">${lines.join("")}</tbody></table></div>`;
|
|
148
|
+
}
|
|
149
|
+
/** Pairs of a label (plain text) and its value (HTML). */
|
|
150
|
+
export function facts(pairs) {
|
|
151
|
+
return `<dl class="wb-ui-facts">${pairs.map(([k, val]) => `<dt class="wb-ui-facts-label">${escape(k)}</dt><dd class="wb-ui-facts-value">${val}</dd>`).join("")}</dl>`;
|
|
152
|
+
}
|
|
153
|
+
/** More detail folded away until asked for. `label` is plain text; `inner` is HTML. */
|
|
154
|
+
export function more(label, inner) {
|
|
155
|
+
return `<details class="wb-ui-more"><summary class="wb-ui-more-label">${escape(label)}</summary>${inner}</details>`;
|
|
156
|
+
}
|
|
157
|
+
/** Exact text kept as it is, such as a reply or a log line. `text` is plain text. */
|
|
158
|
+
export function code(text) {
|
|
159
|
+
return `<pre class="wb-ui-code">${escape(text)}</pre>`;
|
|
160
|
+
}
|
|
79
161
|
const utc = (d) => d.toISOString().replace(".000", "");
|
|
80
162
|
const LONG = new Intl.DateTimeFormat("en-AU", { timeZone: "Asia/Manila", dateStyle: "medium", timeStyle: "medium" });
|
|
81
163
|
const SHORT = new Intl.DateTimeFormat("en-AU", { timeZone: "Asia/Manila", day: "numeric", month: "short", hour: "numeric", minute: "2-digit" });
|
package/dist/style.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
/** The page conventions, without a <style> tag (the helpers' classes are UI_STYLES). */
|
|
2
2
|
export declare const CSS: string;
|
|
3
|
+
/**
|
|
4
|
+
* What a project's workbench.css carries besides the classes: the few rules
|
|
5
|
+
* every Workbench page needs that no class can carry (the spinner's keyframes,
|
|
6
|
+
* links and code inside a page, reduced motion). Each is scoped to a page built
|
|
7
|
+
* with shell (`<html class="wb-ui">`) and wrapped in :where(), so it adds no
|
|
8
|
+
* weight and never touches a page of the project's own.
|
|
9
|
+
*/
|
|
10
|
+
export declare const BASE_CSS: string;
|
|
3
11
|
/** UI_STYLES as plain rules: the variables on :root, then each class and its states. */
|
|
4
12
|
export declare const UI_CSS: string;
|
|
5
13
|
/** The whole look as a <style> tag: the page conventions, then the helpers' classes, which win. */
|
package/dist/style.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
// The one stylesheet for every Workbench page. Colours are --wb-ui-* variables,
|
|
2
2
|
// and every page is dark whatever the computer is set to (docs/spec.md §10, 11
|
|
3
3
|
// November 2026). What the helpers draw (shell, topBar, card, pill, chip,
|
|
4
|
-
// jumpNav
|
|
5
|
-
//
|
|
6
|
-
//
|
|
4
|
+
// jumpNav and the page parts: body, note, button, table, facts and the rest)
|
|
5
|
+
// is UI_STYLES (ui-styles.ts). CSS holds the older page conventions for markup
|
|
6
|
+
// a page writes itself (.note, .body, bare tables and buttons), kept for
|
|
7
|
+
// Workbench's own pages (Control, the Gateway, the probe console). A project's
|
|
8
|
+
// generated workbench.css takes BASE_CSS instead, so no unprefixed class or
|
|
9
|
+
// bare element rule reaches a client's own markup. A page adds its own rules
|
|
10
|
+
// after these, never a second copy of them.
|
|
7
11
|
import { UI_STYLES } from "./ui-styles.js";
|
|
8
12
|
/** The page conventions, without a <style> tag (the helpers' classes are UI_STYLES). */
|
|
9
13
|
export const CSS = `*{box-sizing:border-box}
|
|
@@ -104,6 +108,23 @@ input:not([type=hidden]):not([type=checkbox]):not([type=radio]){min-height:2.75r
|
|
|
104
108
|
[aria-invalid=true]{border-color:var(--wb-ui-fail)}
|
|
105
109
|
@media (max-width:640px){th,td{padding:.55rem .7rem}table.kv th{width:auto}}
|
|
106
110
|
`;
|
|
111
|
+
/**
|
|
112
|
+
* What a project's workbench.css carries besides the classes: the few rules
|
|
113
|
+
* every Workbench page needs that no class can carry (the spinner's keyframes,
|
|
114
|
+
* links and code inside a page, reduced motion). Each is scoped to a page built
|
|
115
|
+
* with shell (`<html class="wb-ui">`) and wrapped in :where(), so it adds no
|
|
116
|
+
* weight and never touches a page of the project's own.
|
|
117
|
+
*/
|
|
118
|
+
export const BASE_CSS = `:where(.wb-ui),:where(.wb-ui) *,:where(.wb-ui) ::before,:where(.wb-ui) ::after{box-sizing:border-box}
|
|
119
|
+
:where(.wb-ui) body{margin:0}
|
|
120
|
+
:where(.wb-ui) h2{font-size:1.05rem;margin:2rem 0 .75rem}
|
|
121
|
+
:where(.wb-ui) a{color:var(--wb-ui-accent)}
|
|
122
|
+
:where(.wb-ui) a:hover{color:var(--wb-ui-accent-hover)}
|
|
123
|
+
:where(.wb-ui) a:focus-visible{outline:none;box-shadow:0 0 0 3px var(--wb-ui-focus)}
|
|
124
|
+
:where(.wb-ui) code{font:.85em/1.4 var(--wb-ui-mono)}
|
|
125
|
+
@keyframes wb-ui-spin{to{transform:rotate(360deg)}}
|
|
126
|
+
@media (prefers-reduced-motion:reduce){:where(.wb-ui) *{animation:none!important;transition:none!important}}
|
|
127
|
+
`;
|
|
107
128
|
/** UI_STYLES as plain rules: the variables on :root, then each class and its states. */
|
|
108
129
|
export const UI_CSS = [
|
|
109
130
|
`:root{${UI_STYLES.variables.map((x) => `${x.name}:${x.value}`).join(";")}}`,
|
package/dist/styles.d.ts
CHANGED
|
@@ -49,7 +49,7 @@ export declare const STYLED_SCOPE = "@mccaskie-labs/workbench-";
|
|
|
49
49
|
/** What is wrong with a tool's styles: a name off its prefix, a class with no default rule, a variable used but not listed. */
|
|
50
50
|
export declare function styleProblems(s: ToolStyles): string[];
|
|
51
51
|
/**
|
|
52
|
-
* The project's generated stylesheet: workbench-ui's page
|
|
52
|
+
* The project's generated stylesheet: workbench-ui's page basics (BASE_CSS) in
|
|
53
53
|
* `@layer workbench.page`, then each tool's classes in `@layer workbench.tools`,
|
|
54
54
|
* which wins over the page look.
|
|
55
55
|
*/
|
|
@@ -63,3 +63,11 @@ export declare function styleNames(tools: readonly InstalledStyles[]): {
|
|
|
63
63
|
};
|
|
64
64
|
/** The wb- classes and variables a project's stylesheet names that no installed tool draws (comments ignored). */
|
|
65
65
|
export declare function unknownNames(projectCss: string, tools: readonly InstalledStyles[]): string[];
|
|
66
|
+
/**
|
|
67
|
+
* The wb- classes a project's own markup puts on an element that no installed
|
|
68
|
+
* tool draws: a name renamed or removed by an update (`.body` became
|
|
69
|
+
* `wb-ui-body`), or one mistyped. Reads every class attribute in the text,
|
|
70
|
+
* whether in HTML or in a string in code; a name built from a variable
|
|
71
|
+
* (`wb-ui-${x}`) is left alone. The wb- prefix belongs to Workbench's tools.
|
|
72
|
+
*/
|
|
73
|
+
export declare function unknownMarkupNames(source: string, tools: readonly InstalledStyles[]): string[];
|
package/dist/styles.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// public/styles/workbench.css inside `@layer workbench`, so any rule in the
|
|
7
7
|
// project's own public/styles/project.css wins without !important. This file
|
|
8
8
|
// renders that stylesheet and lists the names a project may use.
|
|
9
|
-
import {
|
|
9
|
+
import { BASE_CSS } from "./style.js";
|
|
10
10
|
/** Where the generated stylesheet and the project's own sit, from the project's root. */
|
|
11
11
|
export const STYLE_FILES = { generated: "public/styles/workbench.css", project: "public/styles/project.css" };
|
|
12
12
|
/** The addresses a page links, in order: Workbench's defaults, then the project's own rules. */
|
|
@@ -93,7 +93,7 @@ const HEADER = [
|
|
|
93
93
|
" */",
|
|
94
94
|
];
|
|
95
95
|
/**
|
|
96
|
-
* The project's generated stylesheet: workbench-ui's page
|
|
96
|
+
* The project's generated stylesheet: workbench-ui's page basics (BASE_CSS) in
|
|
97
97
|
* `@layer workbench.page`, then each tool's classes in `@layer workbench.tools`,
|
|
98
98
|
* which wins over the page look.
|
|
99
99
|
*/
|
|
@@ -101,12 +101,12 @@ export function renderStyles(tools, uiVersion) {
|
|
|
101
101
|
const problems = tools.flatMap((t) => styleProblems(t.styles));
|
|
102
102
|
if (problems.length)
|
|
103
103
|
throw new Error(`workbench-ui styles: ${problems.join("; ")}`);
|
|
104
|
-
const page =
|
|
104
|
+
const page = BASE_CSS.trim().replace(/^/gm, " ");
|
|
105
105
|
return [
|
|
106
106
|
...HEADER,
|
|
107
107
|
"@layer workbench.page, workbench.tools;",
|
|
108
108
|
"",
|
|
109
|
-
comment(`Page
|
|
109
|
+
comment(`Page basics: @mccaskie-labs/workbench-ui ${uiVersion}, only on a page built with shell (html.wb-ui), and of no weight. Everything its helpers draw (cards, notes, buttons, fields, tables) is wb-ui- below.`),
|
|
110
110
|
"@layer workbench.page {",
|
|
111
111
|
page,
|
|
112
112
|
"}",
|
|
@@ -158,3 +158,20 @@ export function unknownNames(projectCss, tools) {
|
|
|
158
158
|
out.add(m[1]);
|
|
159
159
|
return [...out];
|
|
160
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* The wb- classes a project's own markup puts on an element that no installed
|
|
163
|
+
* tool draws: a name renamed or removed by an update (`.body` became
|
|
164
|
+
* `wb-ui-body`), or one mistyped. Reads every class attribute in the text,
|
|
165
|
+
* whether in HTML or in a string in code; a name built from a variable
|
|
166
|
+
* (`wb-ui-${x}`) is left alone. The wb- prefix belongs to Workbench's tools.
|
|
167
|
+
*/
|
|
168
|
+
export function unknownMarkupNames(source, tools) {
|
|
169
|
+
const known = styleNames(tools).classes;
|
|
170
|
+
const out = new Set();
|
|
171
|
+
for (const attr of source.matchAll(/\bclass(?:Name)?\s*=\s*\\?["'`]([^"'`\\]*)/g)) {
|
|
172
|
+
for (const m of attr[1].matchAll(/(?<![\w-])(wb-[a-z0-9-]*[a-z0-9])(?![\w$-])/g))
|
|
173
|
+
if (!known.has(m[1]))
|
|
174
|
+
out.add(`.${m[1]}`);
|
|
175
|
+
}
|
|
176
|
+
return [...out];
|
|
177
|
+
}
|
package/dist/ui-styles.js
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
// The look of what workbench-ui's helpers draw: shell, topBar, card, pill,
|
|
2
|
-
// chip and jumpNav (
|
|
2
|
+
// chip and jumpNav, and the page parts (body, note, message, small, button,
|
|
3
|
+
// actions, field, input, check, table, facts, more and code), so a page needs
|
|
4
|
+
// no markup of its own to look finished (docs/capabilities-manifest.md §10). Every element they put
|
|
3
5
|
// on a page carries one of these classes with a default rule, and the colours
|
|
4
6
|
// and sizes are `--wb-ui-*` variables, so a project restyles a Workbench page
|
|
5
7
|
// in its own public/styles/project.css. The names are public: renaming one is
|
|
6
|
-
// a breaking change. The page conventions for markup a page writes
|
|
7
|
-
// (
|
|
8
|
+
// a breaking change. The older page conventions for markup a page writes
|
|
9
|
+
// itself (.note, .body, bare tables and buttons) stay in CSS (style.ts) for
|
|
10
|
+
// Workbench's own pages; a project's generated workbench.css leaves them out.
|
|
8
11
|
const v = (name) => `var(--wb-ui-${name})`;
|
|
9
12
|
const TONES = ["pass", "refused", "fail", "skip", "running"];
|
|
10
13
|
const RUN = (t) => (t === "running" ? "run" : t);
|
|
14
|
+
/** The tones of a note or message, with the variable each reads for its colour. */
|
|
15
|
+
const SAYS = [
|
|
16
|
+
["pass", "pass"],
|
|
17
|
+
["warn", "warn"],
|
|
18
|
+
["fail", "fail"],
|
|
19
|
+
];
|
|
20
|
+
const FOCUS = `outline:none;box-shadow:0 0 0 3px ${v("focus")}`;
|
|
11
21
|
/** The style hooks of a Workbench page. */
|
|
12
22
|
export const UI_STYLES = {
|
|
13
23
|
format: 1,
|
|
@@ -44,6 +54,7 @@ export const UI_STYLES = {
|
|
|
44
54
|
{ name: "--wb-ui-font", value: 'system-ui,-apple-system,"Segoe UI",sans-serif', about: "The page's font" },
|
|
45
55
|
{ name: "--wb-ui-mono", value: 'ui-monospace,"Cascadia Code",Consolas,monospace', about: "Code's font" },
|
|
46
56
|
{ name: "--wb-ui-width", value: "max(64rem,80vw)", about: "Widest the page's column grows" },
|
|
57
|
+
{ name: "--wb-ui-input-width", value: "24rem", about: "Widest a one-line control grows" },
|
|
47
58
|
],
|
|
48
59
|
classes: [
|
|
49
60
|
{ name: "wb-ui", element: "html", about: "The whole page: dark whatever the computer is set to", css: `color-scheme:dark;background:${v("background")};color:${v("text")};font:15px/1.55 ${v("font")}` },
|
|
@@ -161,5 +172,125 @@ export const UI_STYLES = {
|
|
|
161
172
|
{ selector: "[data-tone=pass]:where(.wb-ui-jump-link>*, .wb-ui-card-head>*)::before", about: "A tick before a passed chip in a jump pill or a folded heading", css: 'content:"\\2713\\00a0"' },
|
|
162
173
|
],
|
|
163
174
|
},
|
|
175
|
+
{
|
|
176
|
+
name: "wb-ui-body",
|
|
177
|
+
element: "div",
|
|
178
|
+
about: "A card's contents, from body(): padded inside the card",
|
|
179
|
+
css: "padding:.85rem 1.1rem",
|
|
180
|
+
states: [
|
|
181
|
+
{ selector: ">:first-child", about: "No gap above the first thing in it", css: "margin-top:0" },
|
|
182
|
+
{ selector: ">:last-child", about: "No gap below the last thing in it", css: "margin-bottom:0" },
|
|
183
|
+
{ selector: "+.wb-ui-body", about: "A second body in the same card, under a line", css: `border-top:1px solid ${v("line")}` },
|
|
184
|
+
],
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
name: "wb-ui-note",
|
|
188
|
+
element: "div",
|
|
189
|
+
about: "A boxed note with a coloured edge, from note(); its data-tone is info, pass, warn or fail",
|
|
190
|
+
css: `padding:.6rem .9rem;margin:.75rem 0;border-left:3px solid ${v("line")};background:${v("surface")};border-radius:0 6px 6px 0`,
|
|
191
|
+
states: [
|
|
192
|
+
...SAYS.map(([t, c]) => ({ selector: `[data-tone=${t}]`, about: `A ${t} note`, css: `border-left-color:${v(c)}` })),
|
|
193
|
+
{ selector: ">:first-child", about: "No gap above the first thing in it", css: "margin-top:0" },
|
|
194
|
+
{ selector: ">:last-child", about: "No gap below the last thing in it", css: "margin-bottom:0" },
|
|
195
|
+
],
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
name: "wb-ui-message",
|
|
199
|
+
element: "p",
|
|
200
|
+
about: "One line saying what just happened, from message(): data-tone pass (it worked) or fail (it didn't)",
|
|
201
|
+
css: "margin:.75rem 0;font-weight:600",
|
|
202
|
+
states: SAYS.map(([t, c]) => ({ selector: `[data-tone=${t}]`, about: `A ${t} message`, css: `color:${v(c)}` })),
|
|
203
|
+
},
|
|
204
|
+
{ name: "wb-ui-small", element: "p", about: "Small print, from small(): a hint, a footnote or a quieter link", css: `font-size:.85rem;color:${v("muted")};margin:.5rem 0` },
|
|
205
|
+
{
|
|
206
|
+
name: "wb-ui-button",
|
|
207
|
+
element: "button",
|
|
208
|
+
about: "A button, from button(); data-kind is primary (filled), secondary (outlined) or link (looks like a link)",
|
|
209
|
+
css: `font:inherit;font-size:.9rem;font-weight:600;line-height:1.2;padding:.5rem 1.1rem;min-height:2.75rem;border:1px solid ${v("accent")};border-radius:6px;background:${v("accent")};color:${v("accent-text")};cursor:pointer;white-space:nowrap`,
|
|
210
|
+
states: [
|
|
211
|
+
{ selector: ":hover", about: "Under the pointer", css: `background:${v("accent-hover")};border-color:${v("accent-hover")}` },
|
|
212
|
+
{ selector: "[data-kind=secondary]", about: "An outlined button, for the less likely choice", css: `background:transparent;color:${v("text")};border-color:${v("line")}` },
|
|
213
|
+
{ selector: "[data-kind=secondary]:hover", about: "An outlined button under the pointer", css: `background:${v("raised")};border-color:${v("muted")}` },
|
|
214
|
+
{ selector: "[data-kind=link]", about: "A button that looks like a link", css: `min-height:0;padding:0;border:0;border-radius:0;background:none;color:${v("accent")};font-weight:inherit;text-decoration:underline` },
|
|
215
|
+
{ selector: "[data-kind=link]:hover", about: "A link button under the pointer", css: `background:none;color:${v("accent-hover")}` },
|
|
216
|
+
{ selector: ":disabled", about: "A button that can't be pressed yet", css: "opacity:.45;cursor:not-allowed" },
|
|
217
|
+
{ selector: ":focus-visible", about: "With the keyboard", css: FOCUS },
|
|
218
|
+
],
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
name: "wb-ui-actions",
|
|
222
|
+
element: "div",
|
|
223
|
+
about: "A row of buttons and the forms around them, from actions()",
|
|
224
|
+
css: "display:flex;flex-wrap:wrap;align-items:center;gap:.6rem;margin:1rem 0",
|
|
225
|
+
states: [{ selector: " form", about: "A form in the row sits inline", css: "display:inline;margin:0" }],
|
|
226
|
+
},
|
|
227
|
+
{ name: "wb-ui-option", element: "option", about: "One choice in a drop-down list", css: `background:${v("surface")};color:${v("text")}` },
|
|
228
|
+
{ name: "wb-ui-field", element: "p", about: "One labelled control, from field(): the label over the control, then any hint", css: "display:flex;flex-direction:column;align-items:flex-start;gap:.3rem;margin:0 0 1rem" },
|
|
229
|
+
{ name: "wb-ui-label", element: "label", about: "A field's label", css: "font-weight:600" },
|
|
230
|
+
{ name: "wb-ui-hint", element: "span", about: "A field's hint under its control", css: `font-size:.85rem;color:${v("muted")}` },
|
|
231
|
+
{
|
|
232
|
+
name: "wb-ui-input",
|
|
233
|
+
element: "input, select or textarea",
|
|
234
|
+
about: "A control, from input(), select() or textarea()",
|
|
235
|
+
css: `font:inherit;color:${v("text")};background:${v("surface")};border:1px solid ${v("line")};border-radius:6px;padding:.45rem .6rem;line-height:1.2;min-height:2.75rem;width:100%;max-width:${v("input-width")}`,
|
|
236
|
+
states: [
|
|
237
|
+
{ selector: ":focus-visible", about: "With the keyboard", css: FOCUS },
|
|
238
|
+
{ selector: "[aria-invalid=true]", about: "A control with a problem", css: `border-color:${v("fail")}` },
|
|
239
|
+
{ selector: ":where(textarea)", about: "A text area grows with what is typed", css: "min-height:6rem;max-height:20rem;field-sizing:content;resize:vertical" },
|
|
240
|
+
{ selector: ":where([type=color])", about: "A colour picker", css: "width:4rem;padding:.2rem" },
|
|
241
|
+
{ selector: ":where([type=number])", about: "A number", css: "width:7.5rem;font-variant-numeric:tabular-nums" },
|
|
242
|
+
],
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
name: "wb-ui-check",
|
|
246
|
+
element: "label",
|
|
247
|
+
about: "A tick box with its words, from check()",
|
|
248
|
+
css: "display:flex;align-items:flex-start;gap:.5rem;margin:0 0 .6rem;cursor:pointer",
|
|
249
|
+
},
|
|
250
|
+
{ name: "wb-ui-check-text", element: "span", about: "A tick box's words", css: "line-height:1.45" },
|
|
251
|
+
{
|
|
252
|
+
name: "wb-ui-check-box",
|
|
253
|
+
element: "input",
|
|
254
|
+
about: "The tick box itself",
|
|
255
|
+
css: `width:1.15rem;height:1.15rem;margin:.15rem 0 0;flex:none;accent-color:${v("accent")}`,
|
|
256
|
+
states: [{ selector: ":focus-visible", about: "With the keyboard", css: FOCUS }],
|
|
257
|
+
},
|
|
258
|
+
{ name: "wb-ui-scroll", element: "div", about: "Around a table, from table(): scrolls sideways on a narrow screen", css: `overflow-x:auto;margin:.75rem 0;border:1px solid ${v("line")};border-radius:8px;background:${v("surface")}`, states: [{ selector: ":where(.wb-ui-card *)", about: "Inside a card, no box of its own", css: "margin:0;border:0;border-radius:0" }] },
|
|
259
|
+
{ name: "wb-ui-table", element: "table", about: "A table, from table()", css: "border-collapse:collapse;width:100%" },
|
|
260
|
+
{ name: "wb-ui-table-head", element: "thead", about: "The row of column headings", css: "vertical-align:bottom" },
|
|
261
|
+
{ name: "wb-ui-table-body", element: "tbody", about: "The rows", css: "vertical-align:top" },
|
|
262
|
+
{ name: "wb-ui-table-row", element: "tr", about: "A table row; its data-tone colours the edge of its first cell", css: `--wb-ui-edge:transparent`,
|
|
263
|
+
states: [
|
|
264
|
+
{ selector: ":where(.wb-ui-table-body>*)+.wb-ui-table-row>*", about: "A line between rows", css: `border-top:1px solid ${v("line")}` },
|
|
265
|
+
{ selector: ":where(.wb-ui-table-body>*):hover>*", about: "A row under the pointer", css: `background:${v("raised")}` },
|
|
266
|
+
{ selector: ":where(.wb-ui-table-body>*)>:first-child", about: "The coloured edge on the first cell", css: `box-shadow:inset 3px 0 0 ${v("edge")}` },
|
|
267
|
+
...TONES.map((t) => ({ selector: `[data-tone=${t}]`, about: `A ${t} row`, css: `--wb-ui-edge:${v(RUN(t))}` })),
|
|
268
|
+
{ selector: "[data-tone=fail]>*", about: "A failed row's cells", css: `background:${v("fail-bg")}` },
|
|
269
|
+
],
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
name: "wb-ui-table-heading",
|
|
273
|
+
element: "th",
|
|
274
|
+
about: "A column's heading",
|
|
275
|
+
css: `text-align:left;vertical-align:bottom;padding:.6rem 1.1rem;font-size:.72rem;font-weight:600;letter-spacing:.04em;text-transform:uppercase;color:${v("muted")};background:${v("raised")};border-bottom:1px solid ${v("line")};white-space:nowrap`,
|
|
276
|
+
},
|
|
277
|
+
{ name: "wb-ui-table-cell", element: "td", about: "A cell", css: "text-align:left;vertical-align:top;padding:.6rem 1.1rem" },
|
|
278
|
+
{ name: "wb-ui-facts", element: "dl", about: "Pairs of a label and its value, from facts()", css: "display:grid;grid-template-columns:minmax(8rem,13rem) 1fr;gap:.45rem 1rem;margin:.6rem 0" },
|
|
279
|
+
{ name: "wb-ui-facts-label", element: "dt", about: "A fact's label", css: `color:${v("muted")};font-size:.875rem;font-weight:600` },
|
|
280
|
+
{ name: "wb-ui-facts-value", element: "dd", about: "A fact's value", css: "margin:0;min-width:0;overflow-wrap:anywhere" },
|
|
281
|
+
{ name: "wb-ui-more", element: "details", about: "More detail, folded away until asked for, from more()", css: "margin:1rem 0" },
|
|
282
|
+
{
|
|
283
|
+
name: "wb-ui-more-label",
|
|
284
|
+
element: "summary",
|
|
285
|
+
about: "The words that open it",
|
|
286
|
+
css: `cursor:pointer;color:${v("accent")};width:max-content;max-width:100%;font-size:.875rem`,
|
|
287
|
+
states: [{ selector: ":focus-visible", about: "With the keyboard", css: FOCUS }],
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
name: "wb-ui-code",
|
|
291
|
+
element: "pre",
|
|
292
|
+
about: "Exact text kept as it is, such as a reply or a log line, from code()",
|
|
293
|
+
css: `font:.85rem/1.5 ${v("mono")};white-space:pre-wrap;overflow-wrap:anywhere;padding:.75rem 1rem;margin:.75rem 0;background:${v("surface")};border:1px solid ${v("line")};border-radius:8px;max-height:28rem;overflow:auto`,
|
|
294
|
+
},
|
|
164
295
|
],
|
|
165
296
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mccaskie-labs/workbench-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Workbench pages: one dark look, a top bar with the environment tag, cards, outcome pills, and one format for times, money and durations.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|