@mccaskie-labs/workbench-ui 0.3.1 → 0.4.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 +15 -0
- package/dist/cli.d.ts +15 -0
- package/dist/cli.js +121 -0
- package/dist/form-script.d.ts +3 -0
- package/dist/form-script.js +23 -10
- package/dist/index.d.ts +7 -0
- package/dist/index.js +2 -1
- package/dist/style.js +1 -12
- package/dist/styles.d.ts +64 -0
- package/dist/styles.js +156 -0
- package/package.json +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @mccaskie-labs/workbench-ui
|
|
2
2
|
|
|
3
|
+
## 0.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- `npx workbench-ui styles [--check] [dir]` writes a project's `public/styles/workbench.css`: the page look in `@layer workbench.page`, then every installed tool's classes and `--wb-*` variables in `@layer workbench.tools`, each with a comment saying what it is. It also writes `public/styles/project.css` when the project has none; that file is the project's own and is never overwritten. It loads after workbench.css and isn't in a layer, so its rules always win. `--check` fails when workbench.css is out of date with the installed packages, or when project.css names a `wb-` class or variable no tool draws any more (docs/capabilities-manifest.md §10).
|
|
8
|
+
- `shell({ stylesheets })` links stylesheets (such as `STYLESHEETS`: `/styles/workbench.css` then `/styles/project.css`) instead of the inline look.
|
|
9
|
+
- `renderStyles`, `starterProjectCss`, `styleProblems`, `styleNames`, `unknownNames`, `STYLE_FILES`, `STYLED_PACKAGES` and the `ToolStyles` types.
|
|
10
|
+
- Breaking: the form rules leave `CSS` and `STYLE` (they are workbench-forms 0.6.0's `FORM_STYLES` now), and FORM_SCRIPT adds the `wb-form-*` names: `wb-form-error`, `wb-form-live`, `wb-form-summary` with `wb-form-summary-title`, `-list`, `-item` and `-link`, and `wb-form-counter` with `wb-form-counter-over` (was `over`). A page that puts forms on Workbench's inline look adds `renderStyles` output, or uses the generated stylesheet.
|
|
11
|
+
|
|
12
|
+
## 0.3.2
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- renderForm draws a form's labels, controls, hints, messages, summary and config block from its definition in one stacked layout, matching FORM_SCRIPT, so apps no longer write form markup by hand. The generator adds the layout's words (ui.form.optional, ui.form.choose, ui.form.none). workbench-ui: a visible "none of these" box counts only when ticked, and STYLE styles the layout's classes.
|
|
17
|
+
|
|
3
18
|
## 0.3.1
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { type InstalledStyles } from "./styles.ts";
|
|
3
|
+
/** The styles of each Workbench tool the project at `dir` has installed, and the workbench-ui version. */
|
|
4
|
+
export declare function installedStyles(dir: string): Promise<{
|
|
5
|
+
tools: InstalledStyles[];
|
|
6
|
+
uiVersion: string;
|
|
7
|
+
}>;
|
|
8
|
+
export interface StylesPlan {
|
|
9
|
+
/** Files to write, by path relative to the project. */
|
|
10
|
+
files: Record<string, string>;
|
|
11
|
+
/** Why --check fails. */
|
|
12
|
+
problems: string[];
|
|
13
|
+
}
|
|
14
|
+
/** What `styles` writes in `dir`, and what --check would fail on, without touching the disk. */
|
|
15
|
+
export declare function planStyles(dir: string, tools: readonly InstalledStyles[], uiVersion: string): StylesPlan;
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// `npx workbench-ui styles [--check] [dir]`: writes <dir>/public/styles/workbench.css
|
|
3
|
+
// from the styles of every Workbench tool installed in the project
|
|
4
|
+
// (docs/capabilities-manifest.md §10), and public/styles/project.css if the
|
|
5
|
+
// project has none yet (it is the project's own, so never overwritten). With
|
|
6
|
+
// --check it writes nothing and fails when workbench.css differs from what the
|
|
7
|
+
// installed packages draw, or when project.css names a wb- class or variable
|
|
8
|
+
// that no installed tool draws any more (a rename after an update).
|
|
9
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
10
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
11
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
12
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
return path;
|
|
16
|
+
};
|
|
17
|
+
import { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
|
|
18
|
+
import { createRequire } from "node:module";
|
|
19
|
+
import { dirname, join, resolve } from "node:path";
|
|
20
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
21
|
+
import { renderStyles, STYLE_FILES, STYLED_PACKAGES, starterProjectCss, unknownNames } from "./styles.js";
|
|
22
|
+
const USAGE = "usage: workbench-ui styles [--check] [dir]";
|
|
23
|
+
const read = (path) => readFileSync(path, "utf8").replace(/\r\n/g, "\n");
|
|
24
|
+
/** The styles of each Workbench tool the project at `dir` has installed, and the workbench-ui version. */
|
|
25
|
+
export async function installedStyles(dir) {
|
|
26
|
+
const req = createRequire(join(dir, "package.json"));
|
|
27
|
+
const version = (pkg) => {
|
|
28
|
+
try {
|
|
29
|
+
return JSON.parse(read(req.resolve(`${pkg}/package.json`))).version;
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const tools = [];
|
|
36
|
+
for (const p of STYLED_PACKAGES) {
|
|
37
|
+
const v = version(p.package);
|
|
38
|
+
if (v === null)
|
|
39
|
+
continue;
|
|
40
|
+
let path;
|
|
41
|
+
try {
|
|
42
|
+
path = req.resolve(`${p.package}/styles`);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
throw new Error(`${p.package} ${v} has no ./styles export: update it to a version that has one`);
|
|
46
|
+
}
|
|
47
|
+
const mod = (await import(__rewriteRelativeImportExtension(pathToFileURL(path).href)));
|
|
48
|
+
const styles = mod[p.export];
|
|
49
|
+
if (!styles)
|
|
50
|
+
throw new Error(`${p.package}/styles doesn't export ${p.export}`);
|
|
51
|
+
tools.push({ styles, version: v });
|
|
52
|
+
}
|
|
53
|
+
const own = JSON.parse(read(resolve(dirname(fileURLToPath(import.meta.url)), "../package.json")));
|
|
54
|
+
return { tools, uiVersion: version("@mccaskie-labs/workbench-ui") ?? own.version };
|
|
55
|
+
}
|
|
56
|
+
/** What `styles` writes in `dir`, and what --check would fail on, without touching the disk. */
|
|
57
|
+
export function planStyles(dir, tools, uiVersion) {
|
|
58
|
+
const files = {};
|
|
59
|
+
const problems = [];
|
|
60
|
+
const generated = renderStyles(tools, uiVersion);
|
|
61
|
+
const genPath = join(dir, STYLE_FILES.generated);
|
|
62
|
+
if (!existsSync(genPath) || read(genPath) !== generated) {
|
|
63
|
+
files[STYLE_FILES.generated] = generated;
|
|
64
|
+
problems.push(`${STYLE_FILES.generated} is out of date with the installed Workbench packages`);
|
|
65
|
+
}
|
|
66
|
+
const projPath = join(dir, STYLE_FILES.project);
|
|
67
|
+
if (!existsSync(projPath)) {
|
|
68
|
+
files[STYLE_FILES.project] = starterProjectCss(tools);
|
|
69
|
+
problems.push(`${STYLE_FILES.project} is missing`);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
const unknown = unknownNames(read(projPath), tools);
|
|
73
|
+
if (unknown.length)
|
|
74
|
+
problems.push(`${STYLE_FILES.project} names ${unknown.join(", ")}, which no installed Workbench tool draws (renamed or removed: see workbench.css)`);
|
|
75
|
+
}
|
|
76
|
+
return { files, problems };
|
|
77
|
+
}
|
|
78
|
+
async function main(argv) {
|
|
79
|
+
const [command, ...rest] = argv;
|
|
80
|
+
if (command !== "styles") {
|
|
81
|
+
console.error(USAGE);
|
|
82
|
+
return 2;
|
|
83
|
+
}
|
|
84
|
+
const check = rest.includes("--check");
|
|
85
|
+
const dirs = rest.filter((a) => a !== "--check");
|
|
86
|
+
if (dirs.length > 1 || dirs.some((d) => d.startsWith("-"))) {
|
|
87
|
+
console.error(USAGE);
|
|
88
|
+
return 2;
|
|
89
|
+
}
|
|
90
|
+
const dir = resolve(dirs[0] ?? ".");
|
|
91
|
+
const { tools, uiVersion } = await installedStyles(dir);
|
|
92
|
+
const plan = planStyles(dir, tools, uiVersion);
|
|
93
|
+
if (check) {
|
|
94
|
+
if (!plan.problems.length) {
|
|
95
|
+
console.log(`${STYLE_FILES.generated} is current (${tools.map((t) => `${t.styles.package} ${t.version}`).join(", ") || "no styled tools"})`);
|
|
96
|
+
return 0;
|
|
97
|
+
}
|
|
98
|
+
for (const p of plan.problems)
|
|
99
|
+
console.error(p);
|
|
100
|
+
console.error("Run `npx workbench-ui styles` and commit the result; fix project.css by hand.");
|
|
101
|
+
return 1;
|
|
102
|
+
}
|
|
103
|
+
for (const [path, text] of Object.entries(plan.files)) {
|
|
104
|
+
mkdirSync(dirname(join(dir, path)), { recursive: true });
|
|
105
|
+
writeFileSync(join(dir, path), text);
|
|
106
|
+
console.log(`wrote ${path}`);
|
|
107
|
+
}
|
|
108
|
+
const left = plan.problems.filter((p) => p.startsWith(STYLE_FILES.project) && !plan.files[STYLE_FILES.project]);
|
|
109
|
+
for (const p of left)
|
|
110
|
+
console.error(p);
|
|
111
|
+
return left.length ? 1 : 0;
|
|
112
|
+
}
|
|
113
|
+
// Run only when this file is the program, compared by resolved path: a test that imports it must never write files.
|
|
114
|
+
const self = realpathSync(fileURLToPath(import.meta.url));
|
|
115
|
+
const program = process.argv[1] ? realpathSync(resolve(process.argv[1])) : "";
|
|
116
|
+
if (self === program) {
|
|
117
|
+
process.exitCode = await main(process.argv.slice(2)).catch((e) => {
|
|
118
|
+
console.error(e.message);
|
|
119
|
+
return 1;
|
|
120
|
+
});
|
|
121
|
+
}
|
package/dist/form-script.d.ts
CHANGED
|
@@ -21,6 +21,9 @@
|
|
|
21
21
|
* sent, and its message clears. This updates as the person types.
|
|
22
22
|
* - Reset clears every message, the summary and the counters.
|
|
23
23
|
*
|
|
24
|
+
* Every element it adds carries a \`wb-form-*\` class (workbench-forms'
|
|
25
|
+
* FORM_STYLES), the same names renderForm uses.
|
|
26
|
+
*
|
|
24
27
|
* Messages come only from the config (already in the visitor's language) and
|
|
25
28
|
* are written as text, never as HTML. Without WorkbenchForms of the same
|
|
26
29
|
* version on the page it does nothing: the endpoint still checks everything.
|
package/dist/form-script.js
CHANGED
|
@@ -21,6 +21,9 @@
|
|
|
21
21
|
* sent, and its message clears. This updates as the person types.
|
|
22
22
|
* - Reset clears every message, the summary and the counters.
|
|
23
23
|
*
|
|
24
|
+
* Every element it adds carries a \`wb-form-*\` class (workbench-forms'
|
|
25
|
+
* FORM_STYLES), the same names renderForm uses.
|
|
26
|
+
*
|
|
24
27
|
* Messages come only from the config (already in the visitor's language) and
|
|
25
28
|
* are written as text, never as HTML. Without WorkbenchForms of the same
|
|
26
29
|
* version on the page it does nothing: the endpoint still checks everything.
|
|
@@ -59,7 +62,9 @@ export const FORM_SCRIPT = `(() => {
|
|
|
59
62
|
else if (el.checked) picked.push(el.value);
|
|
60
63
|
}
|
|
61
64
|
if (picked.length) return picked;
|
|
62
|
-
|
|
65
|
+
// "None of these" is a ticked box (renderForm) or a hidden input the page always sends.
|
|
66
|
+
const none = form.elements.namedItem(n + "__none");
|
|
67
|
+
return none && (none.type !== "checkbox" || none.checked) ? [] : null;
|
|
63
68
|
}
|
|
64
69
|
const radios = els.filter((el) => el.type === "radio");
|
|
65
70
|
if (radios.length) { const on = radios.find((el) => el.checked); return on ? on.value : undefined; }
|
|
@@ -80,7 +85,7 @@ export const FORM_SCRIPT = `(() => {
|
|
|
80
85
|
if (!els.length) return null;
|
|
81
86
|
p = document.createElement("p");
|
|
82
87
|
p.id = id;
|
|
83
|
-
p.className = "
|
|
88
|
+
p.className = "wb-form-error";
|
|
84
89
|
const last = els[els.length - 1];
|
|
85
90
|
const anchor = last.closest("fieldset") && els.length > 1 ? last.closest("fieldset") : last;
|
|
86
91
|
anchor.insertAdjacentElement("afterend", p);
|
|
@@ -106,26 +111,30 @@ export const FORM_SCRIPT = `(() => {
|
|
|
106
111
|
if (el) el.textContent = "";
|
|
107
112
|
for (const c of controls(n)) c.removeAttribute("aria-invalid");
|
|
108
113
|
};
|
|
114
|
+
// A "none of these" box belongs to its field: its events are the field's.
|
|
115
|
+
const field = (n) => (n && n.endsWith("__none") ? n.slice(0, -6) : n);
|
|
109
116
|
const showing = (n) => controls(n).some((c) => c.getAttribute("aria-invalid") === "true");
|
|
110
117
|
const check = () => {
|
|
111
118
|
const input = {};
|
|
112
119
|
for (const n of names) input[n] = read(n);
|
|
113
120
|
try { return F.validate(cfg.form, input, cfg.context); } catch (e) { console.error("workbench-ui: form " + name + ": " + e.message); return null; }
|
|
114
121
|
};
|
|
115
|
-
let live = form.querySelector(".wb-live");
|
|
116
|
-
if (!live) { live = document.createElement("p"); live.className = "wb-live"; live.setAttribute("role", "status"); live.setAttribute("aria-live", "polite"); form.prepend(live); }
|
|
117
|
-
const summary = form.hasAttribute("data-wb-summary") ? (form.querySelector(".wb-summary") || form.insertBefore(Object.assign(document.createElement("div"), { className: "wb-summary", tabIndex: -1 }), form.firstChild)) : null;
|
|
122
|
+
let live = form.querySelector(".wb-form-live");
|
|
123
|
+
if (!live) { live = document.createElement("p"); live.className = "wb-form-live"; live.setAttribute("role", "status"); live.setAttribute("aria-live", "polite"); form.prepend(live); }
|
|
124
|
+
const summary = form.hasAttribute("data-wb-summary") ? (form.querySelector(".wb-form-summary") || form.insertBefore(Object.assign(document.createElement("div"), { className: "wb-form-summary", tabIndex: -1 }), form.firstChild)) : null;
|
|
125
|
+
// A summary the server drew after a failed submit takes focus, so it is read out once.
|
|
126
|
+
if (summary && !summary.hidden && summary.textContent.trim()) summary.focus();
|
|
118
127
|
const say = (key, count) => { const text = Object.prototype.hasOwnProperty.call(messages, key) ? fill(messages[key], { count }) : ""; live.textContent = ""; setTimeout(() => { live.textContent = text; }, 50); return text; };
|
|
119
128
|
const counters = () => {
|
|
120
129
|
for (const el of form.querySelectorAll("[data-wb-max]")) {
|
|
121
130
|
const id = "wb-count-" + name + "-" + el.name;
|
|
122
131
|
let c = document.getElementById(id);
|
|
123
|
-
if (!c) { c = document.createElement("span"); c.id = id; c.className = "wb-counter"; c.setAttribute("aria-hidden", "true"); el.insertAdjacentElement("afterend", c); }
|
|
132
|
+
if (!c) { c = document.createElement("span"); c.id = id; c.className = "wb-form-counter"; c.setAttribute("aria-hidden", "true"); el.insertAdjacentElement("afterend", c); }
|
|
124
133
|
const def = fields[el.name];
|
|
125
134
|
const tidied = def && def.kind === "long_text" ? F.tidyText(el.value) : F.tidyLine(el.value);
|
|
126
135
|
const n = Array.from(tidied).length;
|
|
127
136
|
c.textContent = n + " / " + el.getAttribute("data-wb-max");
|
|
128
|
-
c.classList.toggle("over", n > Number(el.getAttribute("data-wb-max")));
|
|
137
|
+
c.classList.toggle("wb-form-counter-over", n > Number(el.getAttribute("data-wb-max")));
|
|
129
138
|
}
|
|
130
139
|
};
|
|
131
140
|
const wrapper = (n) => form.querySelector('[data-wb-field="' + n + '"]');
|
|
@@ -160,10 +169,10 @@ export const FORM_SCRIPT = `(() => {
|
|
|
160
169
|
if (isSubmit(b)) { pressing = true; setTimeout(() => { pressing = false; }, 1000); }
|
|
161
170
|
});
|
|
162
171
|
form.addEventListener("focusout", (e) => {
|
|
163
|
-
const n = e.target && e.target.name;
|
|
172
|
+
const n = field(e.target && e.target.name);
|
|
164
173
|
if (!n || !names.includes(n)) return;
|
|
165
174
|
// Leaving one box of a group for another of the same field isn't leaving the field.
|
|
166
|
-
if (e.relatedTarget && e.relatedTarget.name === n) return;
|
|
175
|
+
if (e.relatedTarget && field(e.relatedTarget.name) === n) return;
|
|
167
176
|
if (pressing || isSubmit(e.relatedTarget)) return;
|
|
168
177
|
const r = check();
|
|
169
178
|
if (!r) return;
|
|
@@ -175,7 +184,7 @@ export const FORM_SCRIPT = `(() => {
|
|
|
175
184
|
const edited = (e) => {
|
|
176
185
|
held = false;
|
|
177
186
|
counters();
|
|
178
|
-
const n = e.target && e.target.name;
|
|
187
|
+
const n = field(e.target && e.target.name);
|
|
179
188
|
if (!n || !names.includes(n)) return;
|
|
180
189
|
// A condition may name this field: show or hide the fields that depend on it.
|
|
181
190
|
const r0 = conditional.length ? check() : null;
|
|
@@ -204,11 +213,15 @@ export const FORM_SCRIPT = `(() => {
|
|
|
204
213
|
if (summary) {
|
|
205
214
|
summary.textContent = "";
|
|
206
215
|
const head = document.createElement("p");
|
|
216
|
+
head.className = "wb-form-summary-title";
|
|
207
217
|
head.textContent = text;
|
|
208
218
|
const list = document.createElement("ul");
|
|
219
|
+
list.className = "wb-form-summary-list";
|
|
209
220
|
for (const p of r.problems) {
|
|
210
221
|
const li = document.createElement("li");
|
|
222
|
+
li.className = "wb-form-summary-item";
|
|
211
223
|
const a = document.createElement("a");
|
|
224
|
+
a.className = "wb-form-summary-link";
|
|
212
225
|
a.href = "#" + idFor(p.field);
|
|
213
226
|
a.textContent = words(p);
|
|
214
227
|
li.append(a);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { CSS, STYLE } from "./style.ts";
|
|
2
2
|
export { FORM_SCRIPT } from "./form-script.ts";
|
|
3
|
+
export { renderStyles, STYLE_FILES, STYLED_PACKAGES, styleNames, styleProblems, STYLESHEETS, starterProjectCss, unknownNames, type InstalledStyles, type StyleClass, type StyleState, type StyleVariable, type ToolStyles, } from "./styles.ts";
|
|
3
4
|
/** Plain text made safe to put in HTML, in text or in a quoted attribute. */
|
|
4
5
|
export declare const escape: (value: string) => string;
|
|
5
6
|
/** The outcome colours: a pill's class and, prefixed with o-, a table row's left edge. */
|
|
@@ -111,6 +112,12 @@ export interface ShellOptions {
|
|
|
111
112
|
body: string;
|
|
112
113
|
/** HTML for the end of the head, such as a page's own <style> after the shared one. */
|
|
113
114
|
head?: string;
|
|
115
|
+
/**
|
|
116
|
+
* Stylesheets to link instead of the inline shared look, such as STYLESHEETS in
|
|
117
|
+
* a project: its generated workbench.css (the look and every tool's classes)
|
|
118
|
+
* then its own project.css.
|
|
119
|
+
*/
|
|
120
|
+
stylesheets?: readonly string[];
|
|
114
121
|
/** HTML after the page, such as a <script> with the response's nonce. */
|
|
115
122
|
tail?: string;
|
|
116
123
|
}
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { STYLE } from "./style.js";
|
|
6
6
|
export { CSS, STYLE } from "./style.js";
|
|
7
7
|
export { FORM_SCRIPT } from "./form-script.js";
|
|
8
|
+
export { renderStyles, STYLE_FILES, STYLED_PACKAGES, styleNames, styleProblems, STYLESHEETS, starterProjectCss, unknownNames, } from "./styles.js";
|
|
8
9
|
/** Plain text made safe to put in HTML, in text or in a quoted attribute. */
|
|
9
10
|
export const escape = (value) => value.replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
10
11
|
/** A coloured outcome pill. `text` is plain text. */
|
|
@@ -157,7 +158,7 @@ export function topBar(opts) {
|
|
|
157
158
|
/** A whole page: the shared look, the top bar, the heading, then `body`. */
|
|
158
159
|
export function shell(opts) {
|
|
159
160
|
return `<!doctype html><html lang="en-AU"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="color-scheme" content="dark">
|
|
160
|
-
<title>${escape(opts.title)} · ${escape(opts.site)}</title>${STYLE}${opts.head ?? ""}
|
|
161
|
+
<title>${escape(opts.title)} · ${escape(opts.site)}</title>${opts.stylesheets ? opts.stylesheets.map((href) => `<link rel="stylesheet" href="${escape(href)}">`).join("") : STYLE}${opts.head ?? ""}
|
|
161
162
|
${opts.top}
|
|
162
163
|
<main class="wrap"><h1>${escape(opts.title)}</h1>${opts.body}</main>${opts.tail ?? ""}</html>`;
|
|
163
164
|
}
|
package/dist/style.js
CHANGED
|
@@ -152,21 +152,10 @@ dl.plain dl.plain>dd{margin-bottom:.5rem}dl.plain dl.plain>dd:last-child{margin-
|
|
|
152
152
|
@media (max-width:640px){dl.plain{grid-template-columns:1fr;gap:.1rem}dl.plain dd{margin-bottom:.5rem}}
|
|
153
153
|
@media (prefers-reduced-motion:reduce){*{animation:none!important;transition:none!important}}
|
|
154
154
|
textarea,select{font:inherit;color:var(--text);background:var(--surface);border:1px solid var(--line);border-radius:6px;padding:.45rem .6rem;min-height:2.75rem}
|
|
155
|
-
textarea{width:100%;min-height:6rem;max-height:
|
|
155
|
+
textarea{width:100%;min-height:6rem;max-height:20rem;field-sizing:content;resize:vertical}
|
|
156
156
|
textarea:focus-visible,select:focus-visible{outline:none;box-shadow:0 0 0 3px var(--focus)}
|
|
157
|
-
:root{--wb-w-xs:6ch;--wb-w-s:12ch;--wb-w-m:24ch;--wb-w-l:40ch;--wb-textarea-cap:20rem}
|
|
158
|
-
.wb-w-xs{width:calc(var(--wb-w-xs) + 1.4rem)}.wb-w-s{width:calc(var(--wb-w-s) + 1.4rem)}.wb-w-m{width:calc(var(--wb-w-m) + 1.4rem)}
|
|
159
|
-
.wb-w-l{width:min(100%,calc(var(--wb-w-l) + 1.4rem))}.wb-w-full{width:100%}
|
|
160
157
|
input:not([type=hidden]):not([type=checkbox]):not([type=radio]){min-height:2.75rem}
|
|
161
158
|
[aria-invalid=true]{border-color:var(--fail)}
|
|
162
|
-
.field-error{margin:.3rem 0 0;color:var(--fail);font-size:.875rem}
|
|
163
|
-
.field-error:empty{display:none}
|
|
164
|
-
.wb-counter{display:block;margin-top:.2rem;color:var(--muted);font-size:.78rem;font-variant-numeric:tabular-nums}
|
|
165
|
-
.wb-counter.over{color:var(--fail)}
|
|
166
|
-
.wb-summary{margin:0 0 1rem;padding:.6rem .75rem;border-left:3px solid var(--fail);background:var(--fail-bg);border-radius:6px}
|
|
167
|
-
.wb-summary[hidden],.wb-summary:empty{display:none}
|
|
168
|
-
.wb-summary p{margin:0 0 .3rem;font-weight:600}.wb-summary ul{margin:0;padding-left:1.1rem}
|
|
169
|
-
.wb-live{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
|
|
170
159
|
@media (max-width:640px){nav.links{margin-left:0}th,td{padding:.55rem .7rem}table.kv th{width:auto}}
|
|
171
160
|
`;
|
|
172
161
|
/** The shared rules as a <style> tag. */
|
package/dist/styles.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/** One CSS custom property a tool's rules read, with its default. */
|
|
2
|
+
export interface StyleVariable {
|
|
3
|
+
name: string;
|
|
4
|
+
value: string;
|
|
5
|
+
about: string;
|
|
6
|
+
}
|
|
7
|
+
/** A rule for a class in another state, appended to its selector (`[aria-invalid=true]`, `:hover`). */
|
|
8
|
+
export interface StyleState {
|
|
9
|
+
selector: string;
|
|
10
|
+
about: string;
|
|
11
|
+
css: string;
|
|
12
|
+
}
|
|
13
|
+
/** One class a tool puts on an element, with its default declarations. */
|
|
14
|
+
export interface StyleClass {
|
|
15
|
+
name: string;
|
|
16
|
+
element: string;
|
|
17
|
+
about: string;
|
|
18
|
+
css: string;
|
|
19
|
+
states?: readonly StyleState[];
|
|
20
|
+
}
|
|
21
|
+
/** Every class and variable one tool draws with (workbench-forms' FORM_STYLES, for one). */
|
|
22
|
+
export interface ToolStyles {
|
|
23
|
+
format: 1;
|
|
24
|
+
tool: string;
|
|
25
|
+
package: string;
|
|
26
|
+
title: string;
|
|
27
|
+
prefix: string;
|
|
28
|
+
variables: readonly StyleVariable[];
|
|
29
|
+
classes: readonly StyleClass[];
|
|
30
|
+
}
|
|
31
|
+
/** A tool's styles with the version of the package installed. */
|
|
32
|
+
export interface InstalledStyles {
|
|
33
|
+
styles: ToolStyles;
|
|
34
|
+
version: string;
|
|
35
|
+
}
|
|
36
|
+
/** Where the generated stylesheet and the project's own sit, from the project's root. */
|
|
37
|
+
export declare const STYLE_FILES: {
|
|
38
|
+
readonly generated: "public/styles/workbench.css";
|
|
39
|
+
readonly project: "public/styles/project.css";
|
|
40
|
+
};
|
|
41
|
+
/** The addresses a page links, in order: Workbench's defaults, then the project's own rules. */
|
|
42
|
+
export declare const STYLESHEETS: readonly string[];
|
|
43
|
+
/** The packages whose output can be restyled, each read from its `./styles` export. */
|
|
44
|
+
export declare const STYLED_PACKAGES: readonly {
|
|
45
|
+
package: string;
|
|
46
|
+
export: string;
|
|
47
|
+
}[];
|
|
48
|
+
/** 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. */
|
|
49
|
+
export declare function styleProblems(s: ToolStyles): string[];
|
|
50
|
+
/**
|
|
51
|
+
* The project's generated stylesheet: workbench-ui's page look in
|
|
52
|
+
* `@layer workbench.page`, then each tool's classes in `@layer workbench.tools`,
|
|
53
|
+
* which wins over the page look.
|
|
54
|
+
*/
|
|
55
|
+
export declare function renderStyles(tools: readonly InstalledStyles[], uiVersion: string): string;
|
|
56
|
+
/** The starting project.css: empty rules the project fills, with every variable listed in a comment. */
|
|
57
|
+
export declare function starterProjectCss(tools: readonly InstalledStyles[]): string;
|
|
58
|
+
/** Every wb- class and variable the tools draw with: what a project's own CSS may name. */
|
|
59
|
+
export declare function styleNames(tools: readonly InstalledStyles[]): {
|
|
60
|
+
classes: Set<string>;
|
|
61
|
+
variables: Set<string>;
|
|
62
|
+
};
|
|
63
|
+
/** The wb- classes and variables a project's stylesheet names that no installed tool draws (comments ignored). */
|
|
64
|
+
export declare function unknownNames(projectCss: string, tools: readonly InstalledStyles[]): string[];
|
package/dist/styles.js
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// Restyling what Workbench tools draw in a project (docs/capabilities-manifest.md
|
|
2
|
+
// §10, Robert, 12 November 2026). Every element a tool puts on a project's
|
|
3
|
+
// pages carries a `wb-<tool>-<part>` class with a default rule, and colours and
|
|
4
|
+
// sizes are `--wb-<tool>-*` variables. `npx workbench-ui styles` writes them all,
|
|
5
|
+
// each with a comment saying what it is, into the project's
|
|
6
|
+
// public/styles/workbench.css inside `@layer workbench`, so any rule in the
|
|
7
|
+
// project's own public/styles/project.css wins without !important. This file
|
|
8
|
+
// renders that stylesheet and lists the names a project may use.
|
|
9
|
+
import { CSS } from "./style.js";
|
|
10
|
+
/** Where the generated stylesheet and the project's own sit, from the project's root. */
|
|
11
|
+
export const STYLE_FILES = { generated: "public/styles/workbench.css", project: "public/styles/project.css" };
|
|
12
|
+
/** The addresses a page links, in order: Workbench's defaults, then the project's own rules. */
|
|
13
|
+
export const STYLESHEETS = ["/styles/workbench.css", "/styles/project.css"];
|
|
14
|
+
/** The packages whose output can be restyled, each read from its `./styles` export. */
|
|
15
|
+
export const STYLED_PACKAGES = [{ package: "@mccaskie-labs/workbench-forms", export: "FORM_STYLES" }];
|
|
16
|
+
const NAME = /^[a-z][a-z0-9-]*$/;
|
|
17
|
+
/** 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. */
|
|
18
|
+
export function styleProblems(s) {
|
|
19
|
+
const out = [];
|
|
20
|
+
if (s.format !== 1)
|
|
21
|
+
out.push(`${s.tool}: format must be 1`);
|
|
22
|
+
if (!/^wb-[a-z]+-$/.test(s.prefix))
|
|
23
|
+
out.push(`${s.tool}: prefix must look like wb-<tool>-`);
|
|
24
|
+
const base = s.prefix.slice(0, -1);
|
|
25
|
+
const vars = new Set();
|
|
26
|
+
for (const v of s.variables) {
|
|
27
|
+
if (!v.name.startsWith(`--${s.prefix}`) || !NAME.test(v.name.slice(2)))
|
|
28
|
+
out.push(`${s.tool}: variable ${v.name} must start with --${s.prefix}`);
|
|
29
|
+
if (vars.has(v.name))
|
|
30
|
+
out.push(`${s.tool}: variable ${v.name} is listed twice`);
|
|
31
|
+
if (!v.value.trim() || !v.about.trim())
|
|
32
|
+
out.push(`${s.tool}: variable ${v.name} needs a value and what it is for`);
|
|
33
|
+
vars.add(v.name);
|
|
34
|
+
}
|
|
35
|
+
const classes = new Set();
|
|
36
|
+
for (const c of s.classes) {
|
|
37
|
+
if ((c.name !== base && !c.name.startsWith(s.prefix)) || !NAME.test(c.name))
|
|
38
|
+
out.push(`${s.tool}: class ${c.name} must be ${base} or start with ${s.prefix}`);
|
|
39
|
+
if (classes.has(c.name))
|
|
40
|
+
out.push(`${s.tool}: class ${c.name} is listed twice`);
|
|
41
|
+
classes.add(c.name);
|
|
42
|
+
if (!c.css.trim())
|
|
43
|
+
out.push(`${s.tool}: class ${c.name} has no default rule`);
|
|
44
|
+
if (!c.about.trim() || !c.element.trim())
|
|
45
|
+
out.push(`${s.tool}: class ${c.name} needs its element and what it is for`);
|
|
46
|
+
for (const st of c.states ?? []) {
|
|
47
|
+
if (!st.css.trim() || !st.about.trim())
|
|
48
|
+
out.push(`${s.tool}: ${c.name}${st.selector} needs a rule and what it is for`);
|
|
49
|
+
if (/[{}]/.test(st.selector))
|
|
50
|
+
out.push(`${s.tool}: ${c.name}${st.selector} can't hold braces`);
|
|
51
|
+
}
|
|
52
|
+
for (const css of [c.css, ...(c.states ?? []).map((st) => st.css)]) {
|
|
53
|
+
if (/[{}]/.test(css))
|
|
54
|
+
out.push(`${s.tool}: ${c.name}'s rule can't hold braces`);
|
|
55
|
+
for (const m of css.matchAll(/var\((--[a-z0-9-]+)/g))
|
|
56
|
+
if (!vars.has(m[1]))
|
|
57
|
+
out.push(`${s.tool}: ${c.name} reads ${m[1]}, which isn't listed`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
const comment = (text) => `/* ${text.replace(/\*\//g, "* /")} */`;
|
|
63
|
+
const decls = (css, indent) => css
|
|
64
|
+
.split(";")
|
|
65
|
+
.map((d) => d.trim())
|
|
66
|
+
.filter(Boolean)
|
|
67
|
+
.map((d) => `${indent}${d};`)
|
|
68
|
+
.join("\n");
|
|
69
|
+
/** One tool's block: its variables on :root, then each class and its states, each with a comment. */
|
|
70
|
+
function toolBlock({ styles: s, version }) {
|
|
71
|
+
const out = [` ${comment(`${s.title}: ${s.package} ${version}. Every class starts ${s.prefix} or is ${s.prefix.slice(0, -1)}.`)}`, " :root {"];
|
|
72
|
+
for (const v of s.variables)
|
|
73
|
+
out.push(` ${comment(v.about)}`, ` ${v.name}: ${v.value};`);
|
|
74
|
+
out.push(" }");
|
|
75
|
+
for (const c of s.classes) {
|
|
76
|
+
out.push("", ` ${comment(`<${c.element}> ${c.about}`)}`, ` .${c.name} {`, decls(c.css, " "), " }");
|
|
77
|
+
for (const st of c.states ?? [])
|
|
78
|
+
out.push(` ${comment(st.about)}`, ` .${c.name}${st.selector} {`, decls(st.css, " "), " }");
|
|
79
|
+
}
|
|
80
|
+
return out.join("\n");
|
|
81
|
+
}
|
|
82
|
+
const HEADER = [
|
|
83
|
+
"/*",
|
|
84
|
+
" * Generated by `npx workbench-ui styles`. Don't edit: `npx workbench-ui styles --check` fails when this file differs.",
|
|
85
|
+
" *",
|
|
86
|
+
" * Every element a Workbench tool draws on this project's pages has a class listed below, with its default look,",
|
|
87
|
+
" * and colours and sizes are the --wb-* variables. To restyle one, write a rule for the same class, or set the",
|
|
88
|
+
" * variable, in project.css. It loads after this file and isn't in a layer, so its rules always win.",
|
|
89
|
+
" */",
|
|
90
|
+
];
|
|
91
|
+
/**
|
|
92
|
+
* The project's generated stylesheet: workbench-ui's page look in
|
|
93
|
+
* `@layer workbench.page`, then each tool's classes in `@layer workbench.tools`,
|
|
94
|
+
* which wins over the page look.
|
|
95
|
+
*/
|
|
96
|
+
export function renderStyles(tools, uiVersion) {
|
|
97
|
+
const problems = tools.flatMap((t) => styleProblems(t.styles));
|
|
98
|
+
if (problems.length)
|
|
99
|
+
throw new Error(`workbench-ui styles: ${problems.join("; ")}`);
|
|
100
|
+
const page = CSS.trim().replace(/^/gm, " ");
|
|
101
|
+
return [
|
|
102
|
+
...HEADER,
|
|
103
|
+
"@layer workbench.page, workbench.tools;",
|
|
104
|
+
"",
|
|
105
|
+
comment(`The page look: @mccaskie-labs/workbench-ui ${uiVersion} (shell, topBar, card and the rest). Not yet split into wb- classes.`),
|
|
106
|
+
"@layer workbench.page {",
|
|
107
|
+
page,
|
|
108
|
+
"}",
|
|
109
|
+
"",
|
|
110
|
+
"@layer workbench.tools {",
|
|
111
|
+
tools.map(toolBlock).join("\n\n"),
|
|
112
|
+
"}",
|
|
113
|
+
"",
|
|
114
|
+
].join("\n");
|
|
115
|
+
}
|
|
116
|
+
/** The starting project.css: empty rules the project fills, with every variable listed in a comment. */
|
|
117
|
+
export function starterProjectCss(tools) {
|
|
118
|
+
const vars = tools.flatMap(({ styles: s }) => s.variables.map((v) => ` * ${v.name}: ${v.value}; ${v.about}`));
|
|
119
|
+
return [
|
|
120
|
+
"/*",
|
|
121
|
+
" * This project's own look for what Workbench tools draw. Yours to edit; `npx workbench-ui styles` never",
|
|
122
|
+
" * overwrites it. It loads after workbench.css, which lists every wb- class and variable with its default.",
|
|
123
|
+
" * Rules here always win. Restyle by class (.wb-form-submit { ... }) or map a variable to your own:",
|
|
124
|
+
" *",
|
|
125
|
+
" * :root {",
|
|
126
|
+
...vars,
|
|
127
|
+
" * }",
|
|
128
|
+
" */",
|
|
129
|
+
"",
|
|
130
|
+
].join("\n");
|
|
131
|
+
}
|
|
132
|
+
/** Every wb- class and variable the tools draw with: what a project's own CSS may name. */
|
|
133
|
+
export function styleNames(tools) {
|
|
134
|
+
const classes = new Set();
|
|
135
|
+
const variables = new Set();
|
|
136
|
+
for (const { styles: s } of tools) {
|
|
137
|
+
for (const c of s.classes)
|
|
138
|
+
classes.add(c.name);
|
|
139
|
+
for (const v of s.variables)
|
|
140
|
+
variables.add(v.name);
|
|
141
|
+
}
|
|
142
|
+
return { classes, variables };
|
|
143
|
+
}
|
|
144
|
+
/** The wb- classes and variables a project's stylesheet names that no installed tool draws (comments ignored). */
|
|
145
|
+
export function unknownNames(projectCss, tools) {
|
|
146
|
+
const known = styleNames(tools);
|
|
147
|
+
const css = projectCss.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
148
|
+
const out = new Set();
|
|
149
|
+
for (const m of css.matchAll(/\.(wb-[a-z0-9-]+)/g))
|
|
150
|
+
if (!known.classes.has(m[1]))
|
|
151
|
+
out.add(`.${m[1]}`);
|
|
152
|
+
for (const m of css.matchAll(/(--wb-[a-z0-9-]+)/g))
|
|
153
|
+
if (!known.variables.has(m[1]))
|
|
154
|
+
out.add(m[1]);
|
|
155
|
+
return [...out];
|
|
156
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mccaskie-labs/workbench-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.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",
|
|
@@ -20,6 +20,9 @@
|
|
|
20
20
|
},
|
|
21
21
|
"./package.json": "./package.json"
|
|
22
22
|
},
|
|
23
|
+
"bin": {
|
|
24
|
+
"workbench-ui": "./dist/cli.js"
|
|
25
|
+
},
|
|
23
26
|
"files": [
|
|
24
27
|
"dist",
|
|
25
28
|
"README.md",
|