@mccaskie-labs/workbench-ui 0.8.0 → 0.10.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 CHANGED
@@ -1,5 +1,18 @@
1
1
  # @mccaskie-labs/workbench-ui
2
2
 
3
+ ## 0.10.0
4
+
5
+ ### Minor Changes
6
+
7
+ - The look library as data (docs/look-studio.md step 1, Robert, 24 November 2026). The seven looks are now split into small checked files in `library/`: seven palettes, seven font pairings, three site layouts (`standard`, `centred`, `showcase`, from `SITE_LAYOUT_CHOICES`) and seven looks that each name one of each plus a corner shape. Every item has a state (`testing`, `released`, `withdrawn`), a `source` and a `since`; `LIBRARY` holds them, `LOOKS` is the released looks with their parts filled in (each now also carries `status`, `palette`, `pairing` and `layout`), and `LookId` is any look's id. Every project's generated theme is byte for byte what it was (tested). New: `resolveTheme`, `resolveAdminTheme`, `lookById`, `lookFor` and `themeInput` take an optional library; `ThemeInput` gains `palette`, `pairing` and `layout` (by id, over the look's own); `resolveSiteLayout` gives a project's site layout; `libraryProblems` checks a library's rules (every palette reads in light, dark and as an admin page; no two palettes nearer than `MIN_PALETTE_DISTANCE` by `paletteDistance`; a released look names only released parts) and `itemProblems` one file's shape, refusing any field it doesn't know. A project may add its own items in `workbench/looks/*.json`: `npx workbench-ui styles` reads them beside the package's, so brand.json can name them, and `--check` names a bad, clashing or unreadable one. A released library file never changes: `library/released.json` keeps each one's fingerprint and `npm run library` refuses to run when one has changed. (brand.json can carry `palette`, `pairing` and `layout` once workbench-config's schema allows them.)
8
+
9
+ ## 0.9.0
10
+
11
+ ### Minor Changes
12
+
13
+ - A page part for "Are you sure?": `confirm({ endpoint, fields, ask, question, consequence?, yes, no, reason?, type?, extra?, open? })` draws a button (`ask`, with the `wb-ui-button` look) that only opens a question naming the thing, what happens next and whether it can be undone; its "Yes, …" button posts `fields` with `confirm=yes`. It is a `<details>`, so it works with no script. A page's handler checks `confirmed(body)` (or `confirmed(body, word)` where a word must be typed) and refuses, changing nothing, when it is false. `renderConfirm`, `confirmed` and `ConfirmOptions` (the shared block every Workbench tool asks with) and `ConfirmPartOptions` are exported.
14
+ - New classes `wb-ui-confirm`, `-confirm-open`, `-confirm-ask`, `-confirm-keep`, `-confirm-form`, `-confirm-question`, `-confirm-consequence`, `-confirm-field`, `-confirm-label`, `-confirm-input` and `-confirm-yes`, in `UI_STYLES` and so in a project's generated `workbench.css`. They read the existing variables (the box is `--wb-ui-background`, the yes button `--wb-ui-bad` with `--wb-ui-accent-text`) and one new one, `--wb-ui-corner` (6px). `wb-ui-button` on a `<summary>` sits inline, and `wb-ui-actions` no longer makes the question's own form inline (its rule is now ` form:not(.wb-ui-confirm-form)`).
15
+
3
16
  ## 0.8.0
4
17
 
5
18
  ### Minor Changes
package/README.md CHANGED
@@ -46,6 +46,7 @@ What goes inside a card. Each draws a `wb-ui-*` class with a default look, so a
46
46
  | `small(html)` | Small print (`wb-ui-small`) |
47
47
  | `button(text, { kind?, type?, attrs? })` | A button: `primary`, `secondary` or `link` (`wb-ui-button`) |
48
48
  | `actions(html)` | A row of buttons and their forms (`wb-ui-actions`) |
49
+ | `confirm({ endpoint, fields, ask, question, consequence?, yes, no, reason?, type?, extra?, open? })` | "Are you sure?" before something that removes, cancels or can't be undone: the `ask` button only opens the question, and its `yes` button posts `fields` with `confirm=yes` (`wb-ui-confirm`). The page's handler refuses a post where `confirmed(body)` is false, changing nothing. `reason: { label }` adds a reason box; `type: { label, word }` makes the person type a word first (check it with `confirmed(body, word)`) |
49
50
  | `input(attrs)`, `select(attrs, options, selected?)`, `textarea(attrs, text?)` | A control (`wb-ui-input`). Attributes are escaped; `class` and `on…` are refused |
50
51
  | `field(label, id, control, { hint? })` | A label over its control, then a hint with the id `<id>-hint` (`wb-ui-field`) |
51
52
  | `check(label, attrs)` | A tick box with its words (`wb-ui-check`) |
@@ -54,6 +55,23 @@ What goes inside a card. Each draws a `wb-ui-*` class with a default look, so a
54
55
  | `more(label, html)` | More detail, folded until asked for (`wb-ui-more`) |
55
56
  | `code(text)` | Exact text kept as it is (`wb-ui-code`) |
56
57
 
58
+ ```ts
59
+ import { confirm, confirmed } from '@mccaskie-labs/workbench-ui'
60
+
61
+ confirm({
62
+ endpoint: '/admin/admins',
63
+ fields: { action: 'remove_admin', email: admin.email },
64
+ ask: 'Remove',
65
+ question: `Remove ${admin.email} as an admin?`,
66
+ consequence: 'They can no longer open the admin page. You can add them again later.',
67
+ yes: 'Yes, remove this admin',
68
+ no: 'No, keep them',
69
+ })
70
+ // In the handler: if (!confirmed(body)) refuse with "Please confirm first. Nothing has changed."
71
+ ```
72
+
73
+ `renderConfirm`, `confirmed` and `ConfirmOptions` are the shared block every Workbench tool asks with; `confirm` is it with workbench-ui's own classes.
74
+
57
75
  For a form whose answers are checked, use workbench-forms' `renderForm` instead of `field` and `input`.
58
76
 
59
77
  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.
@@ -63,3 +81,16 @@ Pages are always dark, whatever the computer is set to. A page with its own rule
63
81
  `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.
64
82
 
65
83
  Runs on Node 24 and the Cloudflare Workers runtime. No dependencies.
84
+
85
+ ## The look library
86
+
87
+ A project's look comes from the library (`docs/look-studio.md` §4): palettes, font pairings, site layouts and looks as small checked JSON files in `library/<kind>s/<id>.json`, compiled into `src/library.generated.ts` by `npm run library`. Each has a state: `testing`, `released` (never changes again; a change is a new id, kept by `library/released.json`) or `withdrawn` (no longer offered, still works where named).
88
+
89
+ | Export | What it does |
90
+ | --- | --- |
91
+ | `LIBRARY`, `LOOKS` | Every packaged item by kind; the released looks with their palette, fonts and shape filled in |
92
+ | `resolveTheme(input, library?)`, `resolveAdminTheme`, `resolveSiteLayout` | The tokens, the admin tokens and the site layout from brand.json's `look`, `palette`, `pairing`, `layout`, `scheme`, `shape`, `colours` and `fonts` |
93
+ | `itemProblems(file)`, `libraryProblems(library)` | One file's shape (unknown fields refused); the library's rules: contrast in light, dark and admin, no near copies (`paletteDistance`, `MIN_PALETTE_DISTANCE`), looks naming released parts |
94
+ | `withProjectItems(items)` | The packaged library plus a project's own items |
95
+
96
+ A project adds its own items in `workbench/looks/*.json`, the same shape with `"since": "project"`. `npx workbench-ui styles` reads them, so brand.json can name them, and `--check` names any that is bad, clashes with a packaged id or doesn't read.
package/dist/cli.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ import { type Library } from "./library.ts";
2
3
  import { type InstalledStyles } from "./styles.ts";
3
4
  /** The styles of each Workbench tool the project at `dir` has installed, and the workbench-ui version. */
4
5
  export declare function installedStyles(dir: string): Promise<{
@@ -11,6 +12,17 @@ export declare const MARKUP_DIRS: readonly string[];
11
12
  export declare function markupFiles(dir: string): string[];
12
13
  /** Where a project's brand file sits, from its root (workbench-config's BRAND_FILE). */
13
14
  export declare const BRAND_FILE = "brand.json";
15
+ /** Where a project keeps its own look library items (docs/look-studio.md §4), from its root. */
16
+ export declare const PROJECT_LOOKS_DIR = "workbench/looks";
17
+ /**
18
+ * The library a project sees: the package's, plus the project's own items in
19
+ * workbench/looks/*.json (from the look studio, or written by its Claude), and
20
+ * what is wrong with those files. A bad file is left out, never guessed at.
21
+ */
22
+ export declare function projectLibrary(dir: string): {
23
+ library: Library;
24
+ problems: string[];
25
+ };
14
26
  /**
15
27
  * The theme block for the project at `dir`, from its brand.json (Clean, light,
16
28
  * when it has none), and what is wrong with it: a field of the wrong kind, or
package/dist/cli.js CHANGED
@@ -23,7 +23,8 @@ import { createRequire } from "node:module";
23
23
  import { dirname, join, relative, resolve } from "node:path";
24
24
  import { fileURLToPath, pathToFileURL } from "node:url";
25
25
  import { UI_STYLES } from "./ui-styles.js";
26
- import { renderTheme, resolveAdminTheme, resolveTheme, themeInput, themeProblems } from "./theme.js";
26
+ import { libraryProblems, renderTheme, resolveAdminTheme, resolveTheme, themeInput, themeProblems } from "./theme.js";
27
+ import { findItem, itemProblems, LIBRARY, withProjectItems } from "./library.js";
27
28
  import { DEFAULT_THEME_CSS, renderStyles, STYLE_FILES, STYLED_SCOPE, starterProjectCss, unknownMarkupNames, unknownNames } from "./styles.js";
28
29
  const USAGE = "usage: workbench-ui styles [--check] [dir]";
29
30
  const read = (path) => readFileSync(path, "utf8").replace(/\r\n/g, "\n");
@@ -92,6 +93,49 @@ export function markupFiles(dir) {
92
93
  }
93
94
  /** Where a project's brand file sits, from its root (workbench-config's BRAND_FILE). */
94
95
  export const BRAND_FILE = "brand.json";
96
+ /** Where a project keeps its own look library items (docs/look-studio.md §4), from its root. */
97
+ export const PROJECT_LOOKS_DIR = "workbench/looks";
98
+ /**
99
+ * The library a project sees: the package's, plus the project's own items in
100
+ * workbench/looks/*.json (from the look studio, or written by its Claude), and
101
+ * what is wrong with those files. A bad file is left out, never guessed at.
102
+ */
103
+ export function projectLibrary(dir) {
104
+ const at = join(dir, PROJECT_LOOKS_DIR);
105
+ if (!existsSync(at))
106
+ return { library: LIBRARY, problems: [] };
107
+ const items = [];
108
+ const problems = [];
109
+ for (const name of readdirSync(at).filter((n) => n.endsWith(".json")).sort()) {
110
+ const file = `${PROJECT_LOOKS_DIR}/${name}`;
111
+ let raw;
112
+ try {
113
+ raw = JSON.parse(read(join(at, name)));
114
+ }
115
+ catch {
116
+ problems.push(`${file} isn't valid JSON`);
117
+ continue;
118
+ }
119
+ const bad = itemProblems(raw);
120
+ if (bad.length) {
121
+ problems.push(...bad.map((b) => `${file}: ${b}`));
122
+ continue;
123
+ }
124
+ const item = raw;
125
+ if (findItem(LIBRARY, item.kind, item.id))
126
+ problems.push(`${file}: workbench-ui already has a ${item.kind} called ${item.id}: give yours its own id`);
127
+ else if (items.some((i) => i.kind === item.kind && i.id === item.id))
128
+ problems.push(`${file}: two of the project's files make a ${item.kind} called ${item.id}`);
129
+ else
130
+ items.push(item);
131
+ }
132
+ if (!items.length)
133
+ return { library: LIBRARY, problems };
134
+ const library = withProjectItems(items);
135
+ // The package's own items always keep the rules (tested), so anything left is the project's.
136
+ problems.push(...libraryProblems(library).map((p) => `${PROJECT_LOOKS_DIR}: ${p}`));
137
+ return { library, problems };
138
+ }
95
139
  /**
96
140
  * The theme block for the project at `dir`, from its brand.json (Clean, light,
97
141
  * when it has none), and what is wrong with it: a field of the wrong kind, or
@@ -100,7 +144,7 @@ export const BRAND_FILE = "brand.json";
100
144
  export function projectTheme(dir) {
101
145
  const at = join(dir, BRAND_FILE);
102
146
  if (!existsSync(at))
103
- return { css: DEFAULT_THEME_CSS, problems: [] };
147
+ return { css: DEFAULT_THEME_CSS, problems: projectLibrary(dir).problems };
104
148
  let brand;
105
149
  try {
106
150
  brand = JSON.parse(read(at));
@@ -108,11 +152,13 @@ export function projectTheme(dir) {
108
152
  catch {
109
153
  return { css: DEFAULT_THEME_CSS, problems: [`${BRAND_FILE} isn't valid JSON`] };
110
154
  }
111
- const { input, problems } = themeInput(brand);
112
- const site = resolveTheme(input);
113
- const look = `${input.look ?? "clean"}, ${input.scheme ?? "light"}${input.colours?.primary || input.fonts || input.shape ? ", with brand.json's own choices" : ""}`;
155
+ const own = projectLibrary(dir);
156
+ const { input, problems } = themeInput(brand, own.library);
157
+ problems.unshift(...own.problems);
158
+ const site = resolveTheme(input, own.library);
159
+ const look = `${input.look ?? "clean"}, ${input.scheme ?? "light"}${input.colours?.primary || input.fonts || input.shape || input.palette || input.pairing ? ", with brand.json's own choices" : ""}`;
114
160
  problems.push(...themeProblems(site).map((p) => `${BRAND_FILE}: ${p}`));
115
- return { css: renderTheme(site, resolveAdminTheme(input), `${look} (from ${BRAND_FILE})`), problems };
161
+ return { css: renderTheme(site, resolveAdminTheme(input, own.library), `${look} (from ${BRAND_FILE})`), problems };
116
162
  }
117
163
  /** What `styles` writes in `dir`, and what --check would fail on, without touching the disk. */
118
164
  export function planStyles(dir, tools, uiVersion) {
@@ -0,0 +1,60 @@
1
+ export interface ConfirmOptions {
2
+ /** The tool's class prefix, without the trailing dash: "wb-booking". */
3
+ prefix: string;
4
+ /** Where the form posts. */
5
+ endpoint: string;
6
+ /** The hidden fields that say what to do: action, the thing's id or token. */
7
+ fields: Readonly<Record<string, string>>;
8
+ /** The first button's words: "Cancel". */
9
+ ask: string;
10
+ /** The first button's class, so it keeps the look it has in the tool's styles. */
11
+ askClass: string;
12
+ /** The question, naming the thing: "Cancel Sam's booking for Yoga on Monday 7 December at 6:00 pm?" */
13
+ question: string;
14
+ /** What happens next and who is told: "We'll email Sam to say it's cancelled." */
15
+ consequence?: string;
16
+ /** The button that does it, in its own words: "Yes, cancel this booking". */
17
+ yes: string;
18
+ /** The words that close the question again: "No, keep it". */
19
+ no: string;
20
+ /** A reason to send with it, when the action takes one. */
21
+ reason?: {
22
+ label: string;
23
+ name?: string;
24
+ maxlength?: number;
25
+ required?: boolean;
26
+ };
27
+ /** For deleting a lot at once: a word the person must type before the button works. */
28
+ type?: {
29
+ label: string;
30
+ word: string;
31
+ };
32
+ /** More fields for the question's form, as HTML the tool has already escaped (a second box, a choice). Drawn above the button. */
33
+ extra?: string;
34
+ /** Draw the question already showing: the page was drawn again to ask it. */
35
+ open?: boolean;
36
+ }
37
+ /** The button and its question. */
38
+ export declare function renderConfirm(o: ConfirmOptions): string;
39
+ /** Whether a post answered the question: confirm=yes and, where a word had to be typed, that word. */
40
+ export declare function confirmed(body: Readonly<Record<string, unknown>>, word?: string): boolean;
41
+ interface ConfirmStyle {
42
+ name: string;
43
+ element: string;
44
+ about: string;
45
+ css: string;
46
+ states?: readonly {
47
+ selector: string;
48
+ about: string;
49
+ css: string;
50
+ }[];
51
+ }
52
+ /**
53
+ * The question's classes with their default rules, for the tool's styles.
54
+ * `v` reads one of the tool's own variables (text, muted, line, sunk, surface,
55
+ * radius, danger, on-danger, focus).
56
+ */
57
+ export declare function confirmStyles(prefix: string, v: (name: string) => string, o?: {
58
+ reason?: boolean;
59
+ }): ConfirmStyle[];
60
+ export {};
@@ -0,0 +1,85 @@
1
+ // "Are you sure?" for the actions that cancel, decline or delete
2
+ // (docs/critical-actions-audit.md, "The standard"). The button a person presses first only opens
3
+ // the question: what is about to happen, named in full, and who will be told.
4
+ // The second button does it. It is a <details>, so it works with no script,
5
+ // and the post carries confirm=yes, which the action helpers insist on: a page
6
+ // that draws its own one-click button is refused with `confirm_needed`.
7
+ //
8
+ // This file is the same in every tool that asks (only the prefix differs), so
9
+ // a project restyles each tool's question by that tool's own class names.
10
+ const esc = (s) => s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
11
+ const pattern = (word) => word.replace(/[.*+?^${}()|[\]\\\/-]/g, "\\$&");
12
+ /** The button and its question. */
13
+ export function renderConfirm(o) {
14
+ const p = o.prefix;
15
+ const hidden = Object.entries({ ...o.fields, confirm: "yes" })
16
+ .map(([k, v]) => `<input type="hidden" name="${esc(k)}" value="${esc(v)}">`)
17
+ .join("");
18
+ const reason = o.reason
19
+ ? `<label class="${p}-confirm-field"><span class="${p}-confirm-label">${esc(o.reason.label)}</span><input class="${p}-confirm-input" type="text" name="${esc(o.reason.name ?? "reason")}" maxlength="${o.reason.maxlength ?? 200}"${o.reason.required ? " required" : ""}></label>`
20
+ : "";
21
+ const type = o.type
22
+ ? `<label class="${p}-confirm-field"><span class="${p}-confirm-label">${esc(o.type.label)}</span><input class="${p}-confirm-input" type="text" name="confirm_word" required pattern="${esc(pattern(o.type.word))}" autocomplete="off" autocapitalize="off" spellcheck="false"></label>`
23
+ : "";
24
+ return `<details class="${p}-confirm"${o.open ? " open" : ""}><summary class="${p}-confirm-open ${esc(o.askClass)}"><span class="${p}-confirm-ask">${esc(o.ask)}</span><span class="${p}-confirm-keep">${esc(o.no)}</span></summary><form class="${p}-confirm-form" method="post" action="${esc(o.endpoint)}">${hidden}<p class="${p}-confirm-question">${esc(o.question)}</p>${o.consequence ? `<p class="${p}-confirm-consequence">${esc(o.consequence)}</p>` : ""}${reason}${o.extra ?? ""}${type}<button class="${p}-confirm-yes" type="submit">${esc(o.yes)}</button></form></details>`;
25
+ }
26
+ /** Whether a post answered the question: confirm=yes and, where a word had to be typed, that word. */
27
+ export function confirmed(body, word) {
28
+ if (body.confirm !== "yes" && body.confirm !== true)
29
+ return false;
30
+ return word === undefined || (typeof body.confirm_word === "string" && body.confirm_word.trim() === word);
31
+ }
32
+ /**
33
+ * The question's classes with their default rules, for the tool's styles.
34
+ * `v` reads one of the tool's own variables (text, muted, line, sunk, surface,
35
+ * radius, danger, on-danger, focus).
36
+ */
37
+ export function confirmStyles(prefix, v, o = {}) {
38
+ const focus = { selector: ":focus-visible", about: "Has focus", css: `outline:none;box-shadow:0 0 0 3px ${v("focus")}` };
39
+ return [
40
+ {
41
+ name: `${prefix}-confirm`,
42
+ element: "details",
43
+ about: "A button that asks \"Are you sure?\" before it cancels, declines or deletes",
44
+ css: "display:block",
45
+ states: [
46
+ { selector: `[open]`, about: "The question is showing", css: `display:flex;flex-direction:column;align-items:flex-start;gap:.75rem;box-sizing:border-box;width:100%;padding:1rem;background:${v("sunk")};border:1px solid ${v("line")};border-radius:${v("radius")}` },
47
+ { selector: `[open] > summary`, about: "\"No, keep it\" sits under the button that does it", css: "order:2" },
48
+ { selector: `[open] .${prefix}-confirm-ask`, about: "The first button's words, hidden while the question shows", css: "display:none" },
49
+ { selector: `[open] .${prefix}-confirm-keep`, about: "\"No, keep it\", shown while the question shows", css: "display:inline" },
50
+ ],
51
+ },
52
+ {
53
+ name: `${prefix}-confirm-open`,
54
+ element: "summary",
55
+ about: "The first button: it only opens the question",
56
+ css: "list-style:none",
57
+ states: [{ selector: "::-webkit-details-marker", about: "No arrow beside the button", css: "display:none" }],
58
+ },
59
+ { name: `${prefix}-confirm-ask`, element: "span", about: "The first button's words", css: "display:inline" },
60
+ { name: `${prefix}-confirm-keep`, element: "span", about: "\"No, keep it\": closes the question", css: `display:none;color:${v("text")}` },
61
+ { name: `${prefix}-confirm-form`, element: "form", about: "The question and the button that does it", css: "display:grid;gap:.75rem;justify-items:start;width:100%" },
62
+ { name: `${prefix}-confirm-question`, element: "p", about: "What is about to happen, naming the thing", css: `margin:0;font-weight:600;color:${v("text")}` },
63
+ { name: `${prefix}-confirm-consequence`, element: "p", about: "What happens next and who is told", css: `margin:0;color:${v("muted")}` },
64
+ ...(o.reason
65
+ ? [
66
+ { name: `${prefix}-confirm-field`, element: "label", about: "The reason, or the word to type", css: "display:grid;gap:.25rem;width:100%" },
67
+ { name: `${prefix}-confirm-label`, element: "span", about: "What to type there", css: `color:${v("muted")}` },
68
+ {
69
+ name: `${prefix}-confirm-input`,
70
+ element: "input",
71
+ about: "Where it is typed",
72
+ css: `box-sizing:border-box;width:100%;min-height:2.75rem;padding:.5rem .75rem;font:inherit;color:${v("text")};background:${v("surface")};border:1px solid ${v("line")};border-radius:${v("radius")}`,
73
+ states: [focus],
74
+ },
75
+ ]
76
+ : []),
77
+ {
78
+ name: `${prefix}-confirm-yes`,
79
+ element: "button",
80
+ about: "The button that does it",
81
+ css: `display:inline-flex;align-items:center;justify-content:center;min-height:2.75rem;padding:0 1rem;font:inherit;font-weight:600;border-radius:${v("radius")};cursor:pointer;color:${v("on-danger")};background:${v("danger")};border:1px solid ${v("danger")}`,
82
+ states: [focus],
83
+ },
84
+ ];
85
+ }
package/dist/index.d.ts CHANGED
@@ -1,8 +1,11 @@
1
+ import { type ConfirmOptions } from "./confirm.ts";
2
+ export { confirmed, renderConfirm, type ConfirmOptions } from "./confirm.ts";
1
3
  export { BASE_CSS, CSS, STYLE, UI_CSS } from "./style.ts";
2
4
  export { UI_STYLES } from "./ui-styles.ts";
3
5
  export { FORM_SCRIPT } from "./form-script.ts";
4
6
  export { DEFAULT_THEME_CSS, 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
- export { contrast, DEFAULT_LOOK, LOOKS, lookById, lookFor, mix, renderTheme, resolveAdminTheme, resolveTheme, THEME_TOKENS, themeInput, themeProblems, type Look, type LookId, type Palette, type Scheme, type Shape, type Theme, type ThemeInput, type ThemeToken, type TokenName, } from "./theme.ts";
7
+ export { contrast, DEFAULT_LOOK, LOOKS, libraryProblems, lookById, lookFor, lookOf, looksIn, MIN_PALETTE_DISTANCE, mix, paletteDistance, renderTheme, resolveAdminTheme, resolveSiteLayout, resolveTheme, THEME_TOKENS, themeInput, themeProblems, type Look, type LookId, type Palette, type Scheme, type Shape, type Theme, type ThemeInput, type ThemeToken, type TokenName, } from "./theme.ts";
8
+ export { findItem, itemProblems, LIBRARY, LIBRARY_KINDS, libraryOf, SITE_LAYOUT_CHOICES, usable, withProjectItems, type FontFallback, type ItemStatus, type LayoutItem, type Library, type LibraryItem, type LibraryKind, type LookItem, type PairingFont, type PairingItem, type PaletteItem, type SiteLayoutChoice, } from "./library.ts";
6
9
  /** Plain text made safe to put in HTML, in text or in a quoted attribute. */
7
10
  export declare const escape: (value: string) => string;
8
11
  /** The outcome colours: a pill's class and, prefixed with o-, a table row's left edge. */
@@ -94,6 +97,16 @@ export interface ButtonOptions {
94
97
  export declare function button(text: string, opts?: ButtonOptions): string;
95
98
  /** A row of buttons, and of the small forms around them. `inner` is HTML. */
96
99
  export declare function actions(inner: string): string;
100
+ /** What `confirm` takes: renderConfirm's options without the prefix and the first button's class, which are workbench-ui's own. */
101
+ export type ConfirmPartOptions = Omit<ConfirmOptions, "prefix" | "askClass">;
102
+ /**
103
+ * "Are you sure?" before something that removes, cancels or can't be undone.
104
+ * The first button (`ask`, drawn like `button`) only opens the question; the
105
+ * second (`yes`) posts `fields` with confirm=yes to `endpoint`, so the page's
106
+ * handler checks `confirmed(body)` before it acts. A `<details>`, so it works
107
+ * with no script. Every text option is plain text; `extra` is HTML.
108
+ */
109
+ export declare function confirm(opts: ConfirmPartOptions): string;
97
110
  /** A one-line control. `a` holds its attributes (id, name, type, value, required and so on). */
98
111
  export declare function input(a: Attrs): string;
99
112
  /** A text area holding `text`, which is plain text. */
package/dist/index.js CHANGED
@@ -2,12 +2,15 @@
2
2
  // (Control, the Gateway, the probe console and each project's starter page).
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
+ import { renderConfirm } from "./confirm.js";
5
6
  import { STYLE } from "./style.js";
7
+ export { confirmed, renderConfirm } from "./confirm.js";
6
8
  export { BASE_CSS, CSS, STYLE, UI_CSS } from "./style.js";
7
9
  export { UI_STYLES } from "./ui-styles.js";
8
10
  export { FORM_SCRIPT } from "./form-script.js";
9
11
  export { DEFAULT_THEME_CSS, renderStyles, STYLE_FILES, STYLED_SCOPE, styleNames, styleProblems, STYLESHEETS, starterProjectCss, unknownMarkupNames, unknownNames, } from "./styles.js";
10
- export { contrast, DEFAULT_LOOK, LOOKS, lookById, lookFor, mix, renderTheme, resolveAdminTheme, resolveTheme, THEME_TOKENS, themeInput, themeProblems, } from "./theme.js";
12
+ export { contrast, DEFAULT_LOOK, LOOKS, libraryProblems, lookById, lookFor, lookOf, looksIn, MIN_PALETTE_DISTANCE, mix, paletteDistance, renderTheme, resolveAdminTheme, resolveSiteLayout, resolveTheme, THEME_TOKENS, themeInput, themeProblems, } from "./theme.js";
13
+ export { findItem, itemProblems, LIBRARY, LIBRARY_KINDS, libraryOf, SITE_LAYOUT_CHOICES, usable, withProjectItems, } from "./library.js";
11
14
  /** Plain text made safe to put in HTML, in text or in a quoted attribute. */
12
15
  export const escape = (value) => value.replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
13
16
  /** A coloured outcome pill. `text` is plain text. */
@@ -115,6 +118,16 @@ export function button(text, opts = {}) {
115
118
  export function actions(inner) {
116
119
  return `<div class="wb-ui-actions">${inner}</div>`;
117
120
  }
121
+ /**
122
+ * "Are you sure?" before something that removes, cancels or can't be undone.
123
+ * The first button (`ask`, drawn like `button`) only opens the question; the
124
+ * second (`yes`) posts `fields` with confirm=yes to `endpoint`, so the page's
125
+ * handler checks `confirmed(body)` before it acts. A `<details>`, so it works
126
+ * with no script. Every text option is plain text; `extra` is HTML.
127
+ */
128
+ export function confirm(opts) {
129
+ return renderConfirm({ ...opts, prefix: "wb-ui", askClass: "wb-ui-button" });
130
+ }
118
131
  /** A one-line control. `a` holds its attributes (id, name, type, value, required and so on). */
119
132
  export function input(a) {
120
133
  return `<input class="wb-ui-input"${attrs(a)}>`;
@@ -0,0 +1,100 @@
1
+ export type Scheme = "light" | "dark";
2
+ /** How round the corners are. */
3
+ export type Shape = "square" | "soft" | "round";
4
+ export type ItemStatus = "testing" | "released" | "withdrawn";
5
+ /** The colours a palette sets for one scheme. */
6
+ export interface Palette {
7
+ background: string;
8
+ text: string;
9
+ muted: string;
10
+ accent: string;
11
+ danger: string;
12
+ success: string;
13
+ warning: string;
14
+ }
15
+ interface ItemBase {
16
+ id: string;
17
+ title: string;
18
+ status: ItemStatus;
19
+ /** Who or what made it, and when. */
20
+ source: string;
21
+ /** The workbench-ui version it arrived in, or "project" for a project's own file. */
22
+ since: string;
23
+ }
24
+ export interface PaletteItem extends ItemBase {
25
+ kind: "palette";
26
+ /** A colour group, such as "green", for finding near neighbours. */
27
+ group: string;
28
+ /** One line an owner reads. */
29
+ about: string;
30
+ light: Palette;
31
+ dark: Palette;
32
+ }
33
+ export type FontFallback = "sans" | "serif";
34
+ export interface PairingFont {
35
+ family: string;
36
+ fallback: FontFallback;
37
+ }
38
+ export interface PairingItem extends ItemBase {
39
+ kind: "pairing";
40
+ about: string;
41
+ heading: PairingFont;
42
+ body: PairingFont;
43
+ }
44
+ /** The choices a site layout makes (docs/look-studio.md §6), each list's first is the default. */
45
+ export declare const SITE_LAYOUT_CHOICES: {
46
+ readonly header: readonly ["menu-right", "centred", "menu-centre"];
47
+ readonly footer: readonly ["line", "columns", "centred"];
48
+ readonly width: readonly ["standard", "narrow", "wide"];
49
+ readonly spacing: readonly ["standard", "compact", "airy"];
50
+ readonly hero: readonly ["plain", "over-picture", "beside-picture"];
51
+ };
52
+ export type SiteLayoutChoice = keyof typeof SITE_LAYOUT_CHOICES;
53
+ export interface LayoutItem extends ItemBase {
54
+ kind: "layout";
55
+ /** One line an owner reads: what kind of site it suits. */
56
+ bestFor: string;
57
+ header: (typeof SITE_LAYOUT_CHOICES.header)[number];
58
+ footer: (typeof SITE_LAYOUT_CHOICES.footer)[number];
59
+ width: (typeof SITE_LAYOUT_CHOICES.width)[number];
60
+ spacing: (typeof SITE_LAYOUT_CHOICES.spacing)[number];
61
+ hero: (typeof SITE_LAYOUT_CHOICES.hero)[number];
62
+ }
63
+ export interface LookItem extends ItemBase {
64
+ kind: "look";
65
+ feel: string;
66
+ /** The New project gallery's starter groups this look is suggested for. */
67
+ suggestedFor: string[];
68
+ palette: string;
69
+ pairing: string;
70
+ layout: string;
71
+ shape: Shape;
72
+ }
73
+ export type LibraryItem = PaletteItem | PairingItem | LayoutItem | LookItem;
74
+ export type LibraryKind = LibraryItem["kind"];
75
+ export declare const LIBRARY_KINDS: readonly LibraryKind[];
76
+ /** A library: every item by kind. */
77
+ export interface Library {
78
+ palettes: readonly PaletteItem[];
79
+ pairings: readonly PairingItem[];
80
+ layouts: readonly LayoutItem[];
81
+ looks: readonly LookItem[];
82
+ }
83
+ /** Sorts items into a library, by kind then in the order given. */
84
+ export declare function libraryOf(items: readonly LibraryItem[]): Library;
85
+ /** The library that ships in this version of workbench-ui. */
86
+ export declare const LIBRARY: Library;
87
+ /** The package's library with a project's own items added after it. */
88
+ export declare function withProjectItems(items: readonly LibraryItem[], base?: Library): Library;
89
+ export declare function findItem<K extends LibraryKind>(lib: Library, kind: K, id: string): Extract<LibraryItem, {
90
+ kind: K;
91
+ }> | undefined;
92
+ /** Items a project or the New project form may choose: not withdrawn. Released ones first. */
93
+ export declare function usable<T extends LibraryItem>(items: readonly T[]): T[];
94
+ /**
95
+ * What is wrong with one library file's contents, in plain words (empty when
96
+ * it is a good item). Checks shape only; whether its colours read and whether
97
+ * it names real parts are `libraryProblems`'.
98
+ */
99
+ export declare function itemProblems(raw: unknown): string[];
100
+ export {};