Public: anyone can read this; the crew can change it.
Component library: skeleton, toast and confirm dialog as ui.ts parts, each in the gallery #5897
mason/forge:mason/5880-component-library-skeleton-toast-and-con → main 6 commits fork
19 files
changed +952
−59
docs/design/areas/dialog.md +4 −3
| @@ -1,10 +1,11 @@ | ||
| 1 | 1 | # Dialog |
| 2 | 2 | |
| 3 | 3 | A §5 `.dialog` is one component in three parts: a head that names it, a body that holds what it asks or shows, and a |
| 4 | foot of buttons aligned to the end. The shell's keyboard-shortcuts dialog (`overlays()` in `src/web/layout.ts`) and the | |
| 5 | limb page's confirm form (`limbPreviewPage()` in `src/web/pages/limb.ts`) both draw it; the rules live in | |
| 4 | foot of buttons aligned to the end. `dialogParts()` in `src/web/ui.ts` draws the three; the wrapper is the caller's — | |
| 5 | the shell's keyboard-shortcuts `<dialog>` (`overlays()` in `src/web/layout.ts`) and the limb page's confirm | |
| 6 | `<form class="dialog">` (`limbPreviewPage()` in `src/web/pages/limb.ts`). The rules live in | |
| 6 | 7 | `src/web/style/components.ts`. |
| 7 | 8 | |
| 8 | 9 | - `.dialog-head` — the dialog's first row: its `h2` title (which `aria-labelledby` names) takes the width, anything beside it sits at the end. |
| 9 | - `.dialog-body` — the dialog's content, padded to the head's inset; add `.stack` when it holds several fields. | |
| 10 | - `.dialog-body` — the dialog's content, padded to the head's inset; `stack: true` adds `.stack` when it holds several fields. | |
| 10 | 11 | - `.dialog-foot` — the dialog's actions on one row, aligned to the end, the primary or danger button last. |
docs/design/areas/gallery.md added +12
| @@ -0,0 +1,12 @@ | ||
| 1 | # Gallery | |
| 2 | ||
| 3 | The living gallery at `/design/components` (#5817): every part `src/web/ui.ts` draws, in each state it has, specimens in | |
| 4 | `src/web/gallery.ts`, page in `src/web/pages/design_components.ts`, rules in `src/web/style/components.ts` under | |
| 5 | `/* ---- gallery (/design/components) ---- */`. A part with no specimen fails `test/design-gallery.test.ts`. | |
| 6 | ||
| 7 | - `.gallery-frame` — the column the specimens sit in; `data-w="390"` or `data-w="1440"` fixes it to a phone's or a desktop's width and scrolls sideways past the page. | |
| 8 | - `.gallery-stage` — one state of one part, inside a dashed hairline so its own edges show; a list inside it scrolls after 480px so 200 items stay one stage. | |
| 9 | ||
| 10 | The search picker (`searchPicker` in `src/web/ui.ts`) adds no class: it is a `.field` holding a search `.input`, a | |
| 11 | `.list` of `label.row`s with a checkbox (or radio) as `.row-lead`, and a `pager`. Its script is "search pickers" in | |
| 12 | `src/web/client.ts`, found by `data-picker`, `data-picker-q`, `data-picker-count` and `data-picker-picked`. |
docs/design/areas/skeleton.md added +10
| @@ -0,0 +1,10 @@ | ||
| 1 | # Skeleton | |
| 2 | ||
| 3 | `skeleton()` in `src/web/ui.ts` (#5880): a placeholder for a part that fills in after the first paint. It is a real | |
| 4 | `.card` holding real `.list` rows (or a real card head and body, `shape: "card"`), so the swap to the loaded part shifts | |
| 5 | nothing; grey bars stand where the words will be, and the card says "Loading…" to a screen reader (`role="status"`, | |
| 6 | `aria-busy`). A page the server renders whole needs none. Rules in `src/web/style/components.ts` under | |
| 7 | `/* ---- skeleton … ---- */`. | |
| 8 | ||
| 9 | - `.skeleton` — on the card: lays a row's title and meta out as two stacked bars. | |
| 10 | - `.skeleton-bar` — one grey bar, a line of text tall; it pulses, and under `prefers-reduced-motion` the kill switch holds it still. |
docs/design/areas/toast.md +3 −1
| @@ -2,4 +2,6 @@ | ||
| 2 | 2 | |
| 3 | 3 | The flash a write leaves after its redirect, and the same one-line banner a page shows for a failure it found itself: one `.toast` per page, toned by `data-tone=success|danger|attn` (§5's toast / flash row), an icon, then the message. |
| 4 | 4 | |
| 5 | - `.toast-body` — the message beside the toast's icon: it takes the rest of the row (`flex: 1; min-width: 0`) so a long message wraps instead of pushing the icon off. Written by `flashToast` in `src/web/layout.ts` (the cookie-driven flash), and by `src/web/pages/repo.ts` (a fetch error), `src/web/pages/browse.ts` (a failed mirror) and `src/web/pages/origins.ts` (origin connected or failed); styled in `src/web/style/components.ts` under `/* ---- toast / flash ---- */`. | |
| 5 | Drawn by one part, `toast()` in `src/web/ui.ts`: the shell's cookie-driven flash (`flashToast` in `src/web/layout.ts`), `src/web/pages/repo.ts` (a fetch error), `src/web/pages/browse.ts` (a failed mirror, `role="alert"`) and `src/web/pages/origins.ts` (origin connected or failed) all call it; nothing writes `.toast` by hand. Styled in `src/web/style/components.ts` under `/* ---- toast / flash ---- */`. | |
| 6 | ||
| 7 | - `.toast-body` — the message beside the toast's icon: it takes the rest of the row (`flex: 1; min-width: 0`) so a long message wraps instead of pushing the icon off. |
docs/design/audit.md +2 −1
| @@ -33,7 +33,7 @@ their own vocabulary instead of composing the named one. | ||
| 33 | 33 | |
| 34 | 34 | ## Finding 2 — the pages, and what each is for |
| 35 | 35 | |
| 36 | There are 62 top-level pages, one entry each: every static `GET` route in `src/http/server.ts` | |
| 36 | There are 63 top-level pages, one entry each: every static `GET` route in `src/http/server.ts` | |
| 37 | 37 | that returns a page (`test/design-audit.test.ts` holds this list to the router, |
| 38 | 38 | both ways). Each entry reads `route` — module · what it is for · what |
| 39 | 39 | duplicates it · what breaks `docs/DESIGN.md`. "Breaks" counts colour literals |
| @@ -55,6 +55,7 @@ Machine routes are not pages and have no entry: `/audit.csv`, | ||
| 55 | 55 | - `/big` — `pages/board.ts` (`bigRedirect`) · a redirect kept for old addresses into the board's wall mode · it is `/board` · none (no page of its own). |
| 56 | 56 | - `/boards` — `pages/boards-view.ts` · saved queries as panels · `/board` · none seen. |
| 57 | 57 | - `/boards/data` — `pages/boards.ts` · the boards' query/data surface · `/board` · none seen. |
| 58 | - `/design/components` — `pages/design_components.ts` · the living gallery: every part of `ui.ts` in each state, theme and width (#5817) · none · none seen. | |
| 58 | 59 | - `/asks` — `studio/asks_page.ts` · what the crew is waiting on me for · `/` "needs me" list · colours 2. |
| 59 | 60 | - `/asked` — `studio/asked_page.ts` · what I answered, as a record · `/asks` · none seen. |
| 60 | 61 | - `/review` — `studio/review_page.ts` · every ask waiting on me, one row each, newest first · `/asks` (same asks, with buttons) · none seen. |
docs/design/sections/5-components.md +3 −3
| @@ -81,10 +81,10 @@ specification. | ||
| 81 | 81 | | **stacked bar chart** `windowSvg()` (`fleet-graph.ts`) | `.plots`, `.plot` (`.plot-name`), `.plot-legend` | bars wear `fg-sN`, the `--series-N` token | server-drawn SVG with `width`/`height` set, so it holds its box before the stylesheet; gridlines `--border`, figures `--muted-fg` in mono, panel names `--faint`; `role="img"` with an `aria-label` totalling it, a `<title>` per bar, and a table of the same numbers beside it | a table of the same numbers | |
| 82 | 82 | | **chart** `chartBox()` (`ui.ts`) | `.chart-box` wrapping `drawChart`'s svg `.chart` (`.big` for the headline figure) | `.is-table` for a table panel | one query or series drawn on the server: the svg carries its own `width`/`height` and the box holds its space, so nothing shifts; `role="img"` with an `aria-label` of its title. Reach for it wherever a page draws a `boards/chart.ts` chart — `/system`'s memory pair and every board panel — and size it from the page (`.bp-*`, `.plots`, `.bgrid`), never inside the frame | the same numbers as a table | |
| 83 | 83 | |
| 84 | Two things are deliberately **not** in the vocabulary: skeleton loaders (the | |
| 85 | server renders whole pages — there is nothing to skeletonise) and a custom | |
| 84 | One thing is deliberately **not** in the vocabulary: a custom | |
| 86 | 85 | switch control (a native checkbox with `accent-color` is themed, keyboard-correct |
| 87 | and honest about what it is). | |
| 86 | and honest about what it is). The server renders whole pages, so a skeleton | |
| 87 | (`docs/design/areas/skeleton.md`) is only for a part that fills in after them. | |
| 88 | 88 | |
| 89 | 89 | Three rules the browser enforces whether or not you meant them: |
| 90 | 90 |
src/core/reserved.ts +1
| @@ -64,6 +64,7 @@ export const SYSTEM_NAMES: readonly string[] = [ | ||
| 64 | 64 | "big", |
| 65 | 65 | "board", |
| 66 | 66 | "boards", |
| 67 | "design", | |
| 67 | 68 | "contribute", |
| 68 | 69 | "events", |
| 69 | 70 | "explore", |
src/http/server.ts +3
| @@ -27,6 +27,7 @@ import { resiliencePage } from "../web/pages/resilience.ts"; | ||
| 27 | 27 | import { limitsPage, limitsSet, quotasSet, signupSet, inviteMint, inviteRevoke } from "../web/pages/admin-limits.ts"; |
| 28 | 28 | import { measureSubmit } from "./measure.ts"; |
| 29 | 29 | import { boardsPage } from "../web/pages/boards.ts"; |
| 30 | import { designComponentsPage } from "../web/pages/design_components.ts"; | |
| 30 | 31 | import { boardNew, boardPin, boardPost, pinPost } from "../web/pages/boards-edit.ts"; |
| 31 | 32 | import { boardLive, boardShow, boardsList } from "../web/pages/boards-view.ts"; |
| 32 | 33 | import { |
| @@ -871,6 +872,8 @@ export function buildRouter(): Router<Handler> { | ||
| 871 | 872 | router.add("POST", "/settings/capacity", capacitySet); |
| 872 | 873 | router.add("GET", "/boards", boardsList); |
| 873 | 874 | router.add("GET", "/boards/data", boardsPage); |
| 875 | // The living gallery of the component library (#5817), for an admin who is a person. | |
| 876 | router.add("GET", "/design/components", designComponentsPage); | |
| 874 | 877 | router.add("POST", "/boards/new", boardNew); |
| 875 | 878 | router.add("POST", "/boards/pin", boardPin); |
| 876 | 879 | for (const op of ["pin-panel", "unpin-panel", "move-pin"]) router.add("POST", `/boards/${op}`, pinPost); |
src/web/client.ts +26
| @@ -1375,6 +1375,32 @@ export const shellJs = /* js */ ` | ||
| 1375 | 1375 | }, fallback); |
| 1376 | 1376 | }); |
| 1377 | 1377 | |
| 1378 | // ---- search pickers: typing narrows this page's rows; Enter asks the server ---- | |
| 1379 | doc.addEventListener('input', function (e) { | |
| 1380 | var q = e.target; | |
| 1381 | if (!q || !q.matches || !q.matches('[data-picker-q]')) return; | |
| 1382 | var picker = q.closest('[data-picker]'); | |
| 1383 | if (!picker) return; | |
| 1384 | var needle = q.value.trim().toLowerCase(); | |
| 1385 | var rows = picker.querySelectorAll('li[data-q]'); | |
| 1386 | var shown = 0; | |
| 1387 | for (var i = 0; i < rows.length; i++) { | |
| 1388 | var hit = needle === '' || rows[i].getAttribute('data-q').indexOf(needle) >= 0; | |
| 1389 | rows[i].hidden = !hit; | |
| 1390 | if (hit) shown++; | |
| 1391 | } | |
| 1392 | var count = picker.querySelector('[data-picker-count]'); | |
| 1393 | if (count) count.textContent = needle === '' ? count.getAttribute('data-picker-count') : String(shown); | |
| 1394 | }); | |
| 1395 | doc.addEventListener('change', function (e) { | |
| 1396 | var box = e.target; | |
| 1397 | if (!box || box.type !== 'checkbox' || !box.closest) return; | |
| 1398 | var picker = box.closest('[data-picker]'); | |
| 1399 | var out = picker ? picker.querySelector('[data-picker-picked]') : null; | |
| 1400 | if (!out) return; | |
| 1401 | out.textContent = String(picker.querySelectorAll('li input:checked, [data-picker-carried]').length); | |
| 1402 | }); | |
| 1403 | ||
| 1378 | 1404 | // ---- code line ranges: shift-click extends #L3 to #L3-L9 ---- |
| 1379 | 1405 | // Delegated, not bound to the table: the code browser swaps the file in |
| 1380 | 1406 | // place, and the new table must behave like the first one did. |
src/web/gallery.ts added +350
| @@ -0,0 +1,350 @@ | ||
| 1 | /** | |
| 2 | * The living gallery's specimens (#5817): every part `ui.ts` draws, in the | |
| 3 | * states a page puts it in — its default, empty, loading, error, long text, | |
| 4 | * and 200 items where a part holds a list. `/design/components` renders them | |
| 5 | * (`pages/design_components.ts`); `test/design-gallery.test.ts` fails when a | |
| 6 | * part `ui.ts` exports has no specimen here, so the gallery cannot fall | |
| 7 | * behind the library it shows. | |
| 8 | * | |
| 9 | * Plain data: a part's name (its export), one line on what it is for, and | |
| 10 | * its states, each a label and a thunk that draws it from fixed fixtures. | |
| 11 | * Nothing here reads a request or the database — a specimen looks the same | |
| 12 | * on every forge. | |
| 13 | */ | |
| 14 | ||
| 15 | import type { EnvStatus } from "../apps/runtime.ts"; | |
| 16 | import { html, type Html } from "./html.ts"; | |
| 17 | import * as ui from "./ui.ts"; | |
| 18 | ||
| 19 | /** The states the gallery shows a part in; a part names only those it has. */ | |
| 20 | export const STATES = ["default", "variants", "empty", "loading", "error", "long text", "200 items"] as const; | |
| 21 | export type State = (typeof STATES)[number]; | |
| 22 | ||
| 23 | export interface Specimen { | |
| 24 | /** The export of `ui.ts` it shows. */ | |
| 25 | readonly part: keyof typeof ui; | |
| 26 | readonly note: string; | |
| 27 | readonly states: readonly { readonly state: State; readonly draw: () => Html }[]; | |
| 28 | } | |
| 29 | ||
| 30 | /** | |
| 31 | * Exports of `ui.ts` that return words or numbers rather than markup, or are | |
| 32 | * re-exported helpers: they are seen inside the parts that use them. | |
| 33 | */ | |
| 34 | export const NOT_DRAWN: ReadonlySet<string> = new Set([ | |
| 35 | "timeAgo", "servedPhrase", "queuedPhrase", "fileSize", "labelCss", "hueOf", "envTone", "envPhrase", "when", | |
| 36 | ]); | |
| 37 | ||
| 38 | const LONG = | |
| 39 | "A title someone typed without ever stopping to think about how wide a phone is, carrying on past every sensible width and then a path: src/web/pages/an-extremely-long-file-name-that-never-breaks-on-its-own.ts"; | |
| 40 | const LONG_NAME = "a-person-whose-login-is-much-longer-than-anyone-planned-for"; | |
| 41 | const AT = "2026-10-25T09:30:00.000Z"; | |
| 42 | const BEFORE = "2026-10-25T09:29:52.000Z"; | |
| 43 | const OID = "3f9c2a1e8b7d6c5f4e3d2c1b0a9f8e7d6c5b4a39"; | |
| 44 | const many = <T>(n: number, f: (i: number) => T): T[] => Array.from({ length: n }, (_, i) => f(i)); | |
| 45 | ||
| 46 | const env = (over: Partial<EnvStatus> = {}): EnvStatus => ({ | |
| 47 | env: "production", | |
| 48 | state: "running", | |
| 49 | commitOid: OID, | |
| 50 | url: "https://notes.forge.example", | |
| 51 | runId: "01run", | |
| 52 | since: AT, | |
| 53 | createdAt: BEFORE, | |
| 54 | deployStartedAt: BEFORE, | |
| 55 | servingAt: AT, | |
| 56 | ...over, | |
| 57 | }); | |
| 58 | const ENVS: Record<string, EnvStatus> = { | |
| 59 | live: env(), | |
| 60 | deploying: env({ state: "deploying", servingAt: undefined }), | |
| 61 | failed: env({ state: "failed", error: "exited with code 1 before /healthz answered" }), | |
| 62 | asleep: env({ env: "pull-12", state: "stopped", dormant: { since: AT, idleSince: BEFORE } }), | |
| 63 | }; | |
| 64 | ||
| 65 | const BASE = "/alice/notes"; | |
| 66 | const label = (name: string, color = "0e8a16") => ({ name, color }); | |
| 67 | const rows = (n: number) => | |
| 68 | many(n, (i) => | |
| 69 | ui.row({ href: `#r${i}`, title: `Row ${i + 1}`, meta: html`${ui.time(AT)}`, trail: ui.pill(i), state: i % 3 === 0 ? "closed" : "open" }), | |
| 70 | ); | |
| 71 | ||
| 72 | /** The GET form every picker specimen's search box belongs to (`pages/design_components.ts` draws it). */ | |
| 73 | export const GALLERY_SEARCH_FORM = "gallery-search"; | |
| 74 | const repos = (n: number, checked: readonly number[]): ui.PickerOption[] => | |
| 75 | many(n, (i) => ({ | |
| 76 | value: `github/alice/repo-${i + 1}`, | |
| 77 | title: html`<span class="mono">alice/repo-${i + 1}</span>`, | |
| 78 | meta: i % 4 === 0 ? html`${ui.badge("private")} notes and drafts` : "a repository", | |
| 79 | search: `alice/repo-${i + 1} ${i % 4 === 0 ? "notes and drafts" : "a repository"}`, | |
| 80 | checked: checked.includes(i), | |
| 81 | })); | |
| 82 | const picker = (o: { id?: string; options: readonly ui.PickerOption[]; q?: string; page?: number; multiple?: boolean }) => | |
| 83 | ui.searchPicker({ | |
| 84 | id: o.id ?? "g-picker", | |
| 85 | label: "Repositories", | |
| 86 | name: "pick", | |
| 87 | options: o.options, | |
| 88 | q: o.q ?? "", | |
| 89 | searchForm: GALLERY_SEARCH_FORM, | |
| 90 | page: o.page ?? 1, | |
| 91 | pageHref: (page) => `#page-${page}`, | |
| 92 | ...(o.multiple === undefined ? {} : { multiple: o.multiple }), | |
| 93 | hint: "Enter searches every page.", | |
| 94 | }); | |
| 95 | ||
| 96 | export const SPECIMENS: readonly Specimen[] = [ | |
| 97 | // ---- text and time ---- | |
| 98 | { | |
| 99 | part: "icon", | |
| 100 | note: "A Lucide drawing from the page's sprite.", | |
| 101 | states: [{ state: "variants", draw: () => html`${(["issue", "pull", "merge", "check", "alert", "copy", "loader", "search"] as const).map((n) => ui.icon(n))}` }], | |
| 102 | }, | |
| 103 | { part: "time", note: "Relative time for the eye, the exact instant for machines.", states: [{ state: "default", draw: () => ui.time(AT) }, { state: "error", draw: () => html`[${ui.time("not a date")}]` }] }, | |
| 104 | { | |
| 105 | part: "tokenCount", | |
| 106 | note: "A token count, only ever beside a size or a cost.", | |
| 107 | states: [{ state: "variants", draw: () => html`${ui.tokenCount(1234, "estimated", "prose")} · ${ui.tokenCount(980_000, "counted")}` }], | |
| 108 | }, | |
| 109 | { part: "sizeWithTokens", note: "A file's bytes, and its tokens when it is text.", states: [{ state: "variants", draw: () => html`${ui.sizeWithTokens(48_213, "README.md")} · ${ui.sizeWithTokens(2_400_000, "logo.png")}` }] }, | |
| 110 | // ---- buttons ---- | |
| 111 | { | |
| 112 | part: "btn", | |
| 113 | note: "A button, or a link that looks like one.", | |
| 114 | states: [ | |
| 115 | { state: "variants", draw: () => html`<div class="bar">${(["primary", "secondary", "outline", "ghost", "danger", "link"] as const).map((v) => ui.btn(v, { variant: v, type: "button" }))}</div>` }, | |
| 116 | { state: "default", draw: () => html`<div class="bar">${ui.btn("Small", { size: "sm", type: "button" })}${ui.btn("Large", { size: "lg", type: "button" })}${ui.btn("With icon", { icon: "plus", type: "button" })}${ui.btn("Disabled", { disabled: true, type: "button" })}</div>` }, | |
| 117 | { state: "loading", draw: () => html`<button type="button" class="btn" aria-busy="true">${ui.icon("loader")}Saving</button>` }, | |
| 118 | { state: "long text", draw: () => ui.btn(LONG, { type: "button" }) }, | |
| 119 | ], | |
| 120 | }, | |
| 121 | { part: "iconBtn", note: "Icon only; the label is its name and tooltip.", states: [{ state: "variants", draw: () => html`<div class="bar">${ui.iconBtn("copy", "Copy", { type: "button" })}${ui.iconBtn("x", "Close", { variant: "ghost", type: "button" })}${ui.iconBtn("trash", "Delete", { variant: "danger", type: "button" })}</div>` }] }, | |
| 122 | { | |
| 123 | part: "copyField", | |
| 124 | note: "A string people copy: a read-only field and a copy button.", | |
| 125 | states: [ | |
| 126 | { state: "default", draw: () => ui.copyField("g-copy-a", "git clone https://forge.example/alice/notes.git", "Clone address", "Copy clone address") }, | |
| 127 | { state: "long text", draw: () => ui.copyField("g-copy-b", `https://forge.example/oauth/callback?state=${"x".repeat(160)}`, "Redirect URI", "Copy redirect URI") }, | |
| 128 | ], | |
| 129 | }, | |
| 130 | // ---- badges, labels, pills, dots ---- | |
| 131 | { | |
| 132 | part: "badge", | |
| 133 | note: "A short word with a tone.", | |
| 134 | states: [ | |
| 135 | { state: "variants", draw: () => html`<div class="bar">${(["default", "success", "danger", "merged", "attn"] as const).map((t) => ui.badge(t, { tone: t }))}${ui.badge("secondary", { variant: "secondary" })}${ui.badge("outline", { variant: "outline" })}</div>` }, | |
| 136 | { state: "long text", draw: () => ui.badge(LONG) }, | |
| 137 | ], | |
| 138 | }, | |
| 139 | { | |
| 140 | part: "stat", | |
| 141 | note: "A number with a label: one tile of a `.stats` grid.", | |
| 142 | states: [ | |
| 143 | { state: "default", draw: () => html`<div class="stats">${ui.stat({ label: "Open pulls", value: 12, note: "3 waiting on review" })}${ui.stat({ label: "Spend", value: "$4.20", tone: "attn", href: "#" })}</div>` }, | |
| 144 | { state: "empty", draw: () => html`<div class="stats">${ui.stat({ label: "Runs today", value: 0 })}</div>` }, | |
| 145 | { state: "long text", draw: () => html`<div class="stats">${ui.stat({ label: LONG, value: "1,234,567,890", note: LONG, noteTitle: LONG })}</div>` }, | |
| 146 | ], | |
| 147 | }, | |
| 148 | { part: "stateBadge", note: "Open, closed, parked or merged — the same on every page.", states: [{ state: "variants", draw: () => html`<div class="bar">${ui.stateBadge("open")}${ui.stateBadge("closed")}${ui.stateBadge("closed", true)}${ui.stateBadge("merged")}</div>` }] }, | |
| 149 | { part: "verdictBadge", note: "What a reviewer said; muted once a push made it stale.", states: [{ state: "variants", draw: () => html`<div class="bar">${ui.verdictBadge("approved")}${ui.verdictBadge("changes_requested")}${ui.verdictBadge("commented")}${ui.verdictBadge("approved", { stale: true })}</div>` }] }, | |
| 150 | { part: "runStateBadge", note: "A run's state, worn by checks, rows and logs.", states: [{ state: "variants", draw: () => html`<div class="bar">${(["queued", "running", "ok", "failed", "cancelled"] as const).map((s) => ui.runStateBadge(s))}${ui.runStateBadge("ok", "agent")}</div>` }] }, | |
| 151 | { part: "envStateBadge", note: "What production or a preview is doing now.", states: [{ state: "variants", draw: () => html`<div class="bar">${(["stopped", "deploying", "running", "asleep", "failed"] as const).map((s) => ui.envStateBadge(s))}${ui.envStateBadge("stopped", true)}</div>` }] }, | |
| 152 | { part: "dormantNote", note: "Why a preview sleeps — never a failure's words.", states: [{ state: "default", draw: () => ui.dormantNote(ENVS.asleep!) ?? html`` }, { state: "empty", draw: () => ui.dormantNote(ENVS.live!) ?? html`<span class="muted small">(nothing: awake)</span>` }] }, | |
| 153 | { | |
| 154 | part: "envLine", | |
| 155 | note: "An environment's facts as row meta.", | |
| 156 | states: [{ state: "variants", draw: () => html`${Object.entries(ENVS).map(([k, e]) => html`<p class="muted small">${k}: ${ui.envLine(BASE, e).map((p, i) => html`${i > 0 ? " · " : ""}${p}`)}</p>`)}` }], | |
| 157 | }, | |
| 158 | { | |
| 159 | part: "envFacts", | |
| 160 | note: "An environment's facts in a card: commit, speed, uptime, notes, errors.", | |
| 161 | states: [ | |
| 162 | { state: "default", draw: () => ui.envFacts(BASE, ENVS.live!, { url: true }) }, | |
| 163 | { state: "loading", draw: () => ui.envFacts(BASE, ENVS.deploying!) }, | |
| 164 | { state: "error", draw: () => ui.envFacts(BASE, ENVS.failed!) }, | |
| 165 | { state: "long text", draw: () => ui.envFacts(BASE, env({ error: LONG, note: LONG, url: `https://${"long-".repeat(20)}app.forge.example` }), { url: true }) }, | |
| 166 | ], | |
| 167 | }, | |
| 168 | { part: "previewDataNote", note: "Whose data a preview holds.", states: [{ state: "default", draw: () => ui.previewDataNote("copy", AT) ?? html`` }, { state: "empty", draw: () => ui.previewDataNote("empty", AT) ?? html`<span class="muted small">(nothing: empty policy)</span>` }] }, | |
| 169 | { | |
| 170 | part: "terminalLine", | |
| 171 | note: "An environment's terminal command, or why it is off.", | |
| 172 | states: [ | |
| 173 | { state: "default", draw: () => ui.terminalLine({ command: "ssh -p 2222 [email protected]" }, "SHA256:3f9c2a1e8b7d6c5f4e3d2c1b0a9f8e7d") }, | |
| 174 | { state: "empty", draw: () => html`${ui.terminalLine({ reason: "no_tty" })}${ui.terminalLine({ reason: "no_listener" })}` }, | |
| 175 | ], | |
| 176 | }, | |
| 177 | { part: "terminalCommand", note: "A command, copyable as one wrapping line.", states: [{ state: "long text", draw: () => ui.terminalCommand(`ssh -p 2222 ${LONG_NAME}@forge.example`, "SHA256:3f9c2a1e8b7d6c5f4e3d2c1b0a9f8e7d", html`<a href="#">How to connect</a>`) }] }, | |
| 178 | { part: "envActions", note: "Redeploy and stop, for a writer; nothing for a reader.", states: [{ state: "default", draw: () => html`<div class="bar">${ui.envActions(BASE, ENVS.live!, true)}</div>` }, { state: "empty", draw: () => ui.envActions(BASE, ENVS.live!, false) }] }, | |
| 179 | { | |
| 180 | part: "labelChip", | |
| 181 | note: "A label, its colour from `labelCss`.", | |
| 182 | states: [ | |
| 183 | { state: "variants", draw: () => html`<div class="bar">${ui.labelChip(label("bug", "d73a4a"))}${ui.labelChip(label("design", "5319e7"), "#")}${ui.labelChip(label("good first issue"))}</div>` }, | |
| 184 | { state: "long text", draw: () => ui.labelChip(label(LONG, "fbca04")) }, | |
| 185 | ], | |
| 186 | }, | |
| 187 | { part: "counts", note: "Icon-and-number facts; zero is never drawn.", states: [{ state: "default", draw: () => ui.counts([{ icon: "comment", value: 4, label: "4 comments" }, { icon: "fork", value: 1200, label: "1200 forks" }]) }, { state: "empty", draw: () => html`[${ui.counts([{ icon: "comment", value: 0, label: "none" }])}]` }] }, | |
| 188 | { part: "repoCounts", note: "Open issues and pulls on a repository row.", states: [{ state: "default", draw: () => ui.repoCounts({ openIssues: 7, openPulls: 2 }) }, { state: "empty", draw: () => html`[${ui.repoCounts({ openIssues: 0, openPulls: null })}]` }] }, | |
| 189 | { part: "pill", note: "A count beside a word.", states: [{ state: "variants", draw: () => html`<div class="bar">${ui.pill(3)}${ui.pill(12, "accent")}${ui.pill("99+", "danger")}</div>` }] }, | |
| 190 | { part: "dot", note: "A list's one-glance state.", states: [{ state: "variants", draw: () => html`<div class="bar">${(["default", "success", "danger", "merged", "attn"] as const).map((t) => ui.dot(t))}</div>` }] }, | |
| 191 | { part: "seriesDot", note: "A chart series' swatch.", states: [{ state: "variants", draw: () => html`<div class="bar">${many(6, (i) => ui.seriesDot(i + 1))}</div>` }] }, | |
| 192 | { part: "meter", note: "A share as a bar; `attn` when it is a limit reached.", states: [{ state: "variants", draw: () => html`<div class="stack">${ui.meter(0, "empty")}${ui.meter(42, "some")}${ui.meter(96, "nearly full", "attn")}${ui.meter(140, "clamped")}</div>` }] }, | |
| 193 | { | |
| 194 | part: "chartBox", | |
| 195 | note: "A drawn chart in the box that holds its space.", | |
| 196 | states: [ | |
| 197 | { state: "default", draw: () => ui.chartBox("bar", many(7, (i) => ({ label: `d${i + 1}`, value: (i * 7) % 11 })), "Runs a day") }, | |
| 198 | { state: "empty", draw: () => ui.chartBox("line", [], "No runs yet") }, | |
| 199 | { state: "200 items", draw: () => ui.chartBox("line", many(200, (i) => ({ label: `t${i}`, value: Math.round(50 + 40 * Math.sin(i / 9)) })), "200 points") }, | |
| 200 | ], | |
| 201 | }, | |
| 202 | { part: "sha", note: "A short object id, always seven characters.", states: [{ state: "variants", draw: () => html`<div class="bar">${ui.sha(OID)}${ui.sha(OID, "#")}</div>` }] }, | |
| 203 | { part: "kbd", note: "A key chord.", states: [{ state: "default", draw: () => ui.kbd(["⌘", "K"]) }] }, | |
| 204 | // ---- identity ---- | |
| 205 | { part: "avatar", note: "Initials on a stable hue.", states: [{ state: "variants", draw: () => html`<div class="bar">${ui.avatar("alice")}${ui.avatar("bob builder", "md")}${ui.avatar("mason", "lg")}</div>` }] }, | |
| 206 | { part: "userTag", note: "An author inside something that is already a link.", states: [{ state: "variants", draw: () => html`<div class="bar">${ui.userTag("alice", { mark: "owner" })}${ui.userTag("mason", { mark: "crew" })}${ui.userTag("bob", { avatar: false })}</div>` }, { state: "long text", draw: () => ui.userTag(LONG_NAME) }] }, | |
| 207 | { part: "originTag", note: "An author who is not an account here.", states: [{ state: "default", draw: () => ui.originTag("octocat", "globe") }] }, | |
| 208 | { part: "nameMark", note: "The owner's or the crew's mark beside a name.", states: [{ state: "variants", draw: () => html`<div class="bar">${ui.nameMark("owner")}${ui.nameMark("crew")}</div>` }] }, | |
| 209 | { part: "userLink", note: "An author as a link to their profile.", states: [{ state: "default", draw: () => ui.userLink("alice", { mark: "owner" }) }, { state: "long text", draw: () => ui.userLink(LONG_NAME, { display: LONG }) }] }, | |
| 210 | // ---- surfaces ---- | |
| 211 | { | |
| 212 | part: "card", | |
| 213 | note: "The one surface: head, body, foot, and a tone.", | |
| 214 | states: [ | |
| 215 | { state: "default", draw: () => ui.card(html`<p>Body text.</p>`, { head: html`<strong>Head</strong>`, foot: ui.btn("Action", { size: "sm", type: "button" }) }) }, | |
| 216 | { state: "variants", draw: () => html`<div class="stack">${(["success", "danger", "attn"] as const).map((t) => ui.card(html`<p>${t}</p>`, { tone: t }))}</div>` }, | |
| 217 | { state: "long text", draw: () => ui.card(html`<p>${LONG}</p>`, { head: html`<strong>${LONG}</strong>` }) }, | |
| 218 | ], | |
| 219 | }, | |
| 220 | { | |
| 221 | part: "listCard", | |
| 222 | note: "A card around a list of rows — the shape every listing takes.", | |
| 223 | states: [ | |
| 224 | { state: "default", draw: () => ui.listCard(rows(3)) }, | |
| 225 | { state: "empty", draw: () => ui.listCard([]) }, | |
| 226 | { state: "200 items", draw: () => ui.listCard(rows(200)) }, | |
| 227 | ], | |
| 228 | }, | |
| 229 | { part: "disclosure", note: "Closed until asked for.", states: [{ state: "default", draw: () => ui.disclosure("Show the details", html`<p>The details.</p>`) }, { state: "variants", draw: () => ui.disclosure("Small, muted", html`<p>Tucked away.</p>`, { small: true }) }, { state: "long text", draw: () => ui.disclosure(LONG, html`<p>${LONG}</p>`) }] }, | |
| 230 | { | |
| 231 | part: "row", | |
| 232 | note: "One list row: a link, its own controls, or a fold.", | |
| 233 | states: [ | |
| 234 | { | |
| 235 | state: "variants", | |
| 236 | draw: () => | |
| 237 | html`<ul class="list">${ui.row({ href: "#", title: "A link row", meta: html`opened ${ui.time(AT)}`, lead: ui.dot("success"), trail: ui.pill(4), state: "open" })}${ui.row({ title: "A row with controls", trail: ui.btn("Act", { size: "sm", type: "button" }) })}${ui.row({ title: "The current row", current: true })}${ui.row({ title: "A folded row", fold: { id: "g-fold", open: false, body: html`<p class="muted small">Folded body.</p>` } })}${ui.row({ title: "A parent", children: [ui.row({ title: "A child" })] })}</ul>`, | |
| 238 | }, | |
| 239 | { state: "long text", draw: () => html`<ul class="list">${ui.row({ href: "#", title: LONG, titleAttr: LONG, meta: html`${LONG}`, trail: ui.badge("trail") })}</ul>` }, | |
| 240 | ], | |
| 241 | }, | |
| 242 | // ---- navigation ---- | |
| 243 | { | |
| 244 | part: "tabs", | |
| 245 | note: "Link tabs: navigation, so `aria-current`.", | |
| 246 | states: [ | |
| 247 | { state: "default", draw: () => ui.tabs([{ label: "Code", href: "#", icon: "code", current: true }, { label: "Issues", href: "#", icon: "issue", count: 7 }, { label: "Pulls", href: "#", icon: "pull", count: 0 }], "Repository") }, | |
| 248 | { state: "200 items", draw: () => ui.tabs(many(200, (i) => ({ label: `Tab ${i + 1}`, href: "#", count: i, current: i === 0 })), "Many tabs") }, | |
| 249 | ], | |
| 250 | }, | |
| 251 | { | |
| 252 | part: "seg", | |
| 253 | note: "A segmented filter built from links.", | |
| 254 | states: [ | |
| 255 | { state: "default", draw: () => ui.seg([{ label: "Open", href: "#", current: true, count: 12 }, { label: "Closed", href: "#", current: false }, { label: "All", href: "#", current: false }]) }, | |
| 256 | { state: "long text", draw: () => ui.seg([{ label: LONG, href: "#", current: true }, { label: "Short", href: "#", current: false }]) }, | |
| 257 | ], | |
| 258 | }, | |
| 259 | { part: "crumbs", note: "Where you are.", states: [{ state: "default", draw: () => ui.crumbs([{ label: "alice", href: "#" }, { label: "notes", href: "#" }, { label: "src" }]) }, { state: "long text", draw: () => ui.crumbs(many(8, (i) => ({ label: `${LONG_NAME}-${i}`, href: "#" })), { mono: true }) }] }, | |
| 260 | { part: "pager", note: "Cursor pagination with an honest end.", states: [{ state: "default", draw: () => ui.pager({ prev: "#", next: "#", note: "21–40" }) }, { state: "variants", draw: () => ui.pager({ next: "#" }) }, { state: "empty", draw: () => html`[${ui.pager({})}]` }] }, | |
| 261 | { | |
| 262 | part: "menu", | |
| 263 | note: "A dropdown on `<details>`, correct with JS off.", | |
| 264 | states: [ | |
| 265 | { state: "default", draw: () => ui.menu({ trigger: html`${ui.icon("chevronDown")}Menu`, title: "Actions", items: [{ label: "Open", href: "#", icon: "external", current: true }, { separator: true, label: "" }, { label: "Delete", post: "#", icon: "trash" }, { label: "Archive", disabled: "Only the owner can archive" }] }) }, | |
| 266 | { state: "200 items", draw: () => ui.menu({ trigger: "200 items", items: many(200, (i) => ({ label: `Item ${i + 1}`, href: "#" })) }) }, | |
| 267 | ], | |
| 268 | }, | |
| 269 | // ---- forms ---- | |
| 270 | { | |
| 271 | part: "field", | |
| 272 | note: "Label, control, hint and error, wired with `aria-describedby`.", | |
| 273 | states: [ | |
| 274 | { state: "default", draw: () => ui.field({ label: "Name", name: "g-name", hint: "Letters, digits and dashes.", placeholder: "my-app" }) }, | |
| 275 | { state: "error", draw: () => ui.field({ label: "Name", name: "g-name-err", value: "My App!", error: "Use letters, digits and dashes only." }) }, | |
| 276 | { state: "variants", draw: () => ui.field({ label: "Description", name: "g-desc", type: "textarea", rows: 3 }) }, | |
| 277 | { state: "long text", draw: () => ui.field({ label: LONG, name: "g-long", value: LONG, hint: LONG, error: LONG }) }, | |
| 278 | ], | |
| 279 | }, | |
| 280 | { | |
| 281 | part: "selectField", | |
| 282 | note: "A select with the field's anatomy.", | |
| 283 | states: [ | |
| 284 | { state: "default", draw: () => ui.selectField({ label: "Visibility", name: "g-vis", options: [{ value: "private", label: "Private", selected: true }, { value: "public", label: "Public" }] }) }, | |
| 285 | { state: "error", draw: () => ui.selectField({ label: "Visibility", name: "g-vis-err", error: "Choose one.", options: [{ value: "", label: "—" }] }) }, | |
| 286 | { state: "200 items", draw: () => ui.selectField({ label: "Repository", name: "g-many", options: many(200, (i) => ({ value: String(i), label: `repository-${i + 1}` })) }) }, | |
| 287 | ], | |
| 288 | }, | |
| 289 | { | |
| 290 | part: "searchPicker", | |
| 291 | note: "A long list to pick from: searchable, paged, multi-select; picks off the page ride along.", | |
| 292 | states: [ | |
| 293 | { state: "default", draw: () => picker({ options: repos(6, [1, 4]) }) }, | |
| 294 | { state: "variants", draw: () => picker({ id: "g-picker-one", options: repos(4, [2]), multiple: false }) }, | |
| 295 | { state: "empty", draw: () => html`<div class="stack">${picker({ id: "g-picker-none", options: [] })}${picker({ id: "g-picker-miss", options: repos(6, []), q: "zzz" })}</div>` }, | |
| 296 | { state: "long text", draw: () => picker({ id: "g-picker-long", options: [{ value: "long", title: LONG, meta: LONG, search: LONG }] }) }, | |
| 297 | { state: "200 items", draw: () => picker({ id: "g-picker-many", options: repos(200, [3, 120]), page: 2 }) }, | |
| 298 | ], | |
| 299 | }, | |
| 300 | { part: "confirmAction", note: "A destructive action, never one careless click away.", states: [{ state: "default", draw: () => ui.confirmAction({ action: "/alice/notes/settings/delete", verb: "Delete repository", size: "sm" }) }] }, | |
| 301 | // ---- states ---- | |
| 302 | { | |
| 303 | part: "empty", | |
| 304 | note: "What a list says when it holds nothing, and the next step.", | |
| 305 | states: [ | |
| 306 | { state: "default", draw: () => ui.empty({ icon: "issue", title: "No open issues", note: "Issues are how people tell the crew what to do.", action: ui.btn("New issue", { href: "#", variant: "primary", size: "sm" }) }) }, | |
| 307 | { state: "long text", draw: () => ui.empty({ title: LONG, note: LONG }) }, | |
| 308 | ], | |
| 309 | }, | |
| 310 | { | |
| 311 | part: "skeleton", | |
| 312 | note: "Holds a list's or a card's space while it loads; the swap shifts nothing, and under less motion it holds still.", | |
| 313 | states: [ | |
| 314 | { state: "loading", draw: () => ui.skeleton() }, | |
| 315 | { state: "variants", draw: () => ui.skeleton({ shape: "card", rows: 2 }) }, | |
| 316 | ], | |
| 317 | }, | |
| 318 | { | |
| 319 | part: "toast", | |
| 320 | note: "The one banner a write leaves after its redirect, or a failure the page found itself.", | |
| 321 | states: [ | |
| 322 | { state: "default", draw: () => ui.toast({ message: "Repository created.", link: { href: "#", label: "Open it" } }) }, | |
| 323 | { state: "variants", draw: () => html`${ui.toast({ tone: "attn", message: "The check is still running." })}${ui.toast({ message: "Token created. It is shown once.", code: "forge_3f9c2a1e8b7d6c5f", codeId: "g-toast-code" })}` }, | |
| 324 | { state: "error", draw: () => ui.toast({ tone: "danger", role: "alert", message: "The mirror failed." }) }, | |
| 325 | { state: "long text", draw: () => ui.toast({ tone: "danger", message: LONG }) }, | |
| 326 | ], | |
| 327 | }, | |
| 328 | { | |
| 329 | part: "dialogParts", | |
| 330 | note: "A dialog's head, body and foot; the wrapper is a <dialog> the shell opens or a form drawn as its own page.", | |
| 331 | states: [ | |
| 332 | { | |
| 333 | state: "default", | |
| 334 | draw: () => html`<div class="dialog">${ui.dialogParts({ | |
| 335 | titleId: "g-dialog-title", | |
| 336 | title: "Close this milestone?", | |
| 337 | stack: true, | |
| 338 | body: ui.field({ label: "Why, in one sentence", name: "g-dialog-reason" }), | |
| 339 | foot: html`${ui.btn("Back", { href: "#", variant: "ghost" })}${ui.btn("Close milestone", { variant: "danger" })}`, | |
| 340 | })}</div>`, | |
| 341 | }, | |
| 342 | { | |
| 343 | state: "long text", | |
| 344 | draw: () => html`<div class="dialog">${ui.dialogParts({ titleId: "g-dialog-long", title: LONG, body: html`<p>${LONG}</p>`, foot: ui.btn("Close") })}</div>`, | |
| 345 | }, | |
| 346 | ], | |
| 347 | }, | |
| 348 | { part: "tlEvent", note: "A low-emphasis timeline row.", states: [{ state: "variants", draw: () => html`<div class="timeline">${ui.tlEvent({ icon: "merge", tone: "merged", body: html`<span>alice merged this ${ui.time(AT)}</span>` })}${ui.tlEvent({ icon: "x", tone: "danger", body: html`<span>the check failed</span>` })}</div>` }] }, | |
| 349 | { part: "tlComment", note: "A comment-weight timeline row.", states: [{ state: "default", draw: () => html`<div class="timeline">${ui.tlComment(ui.card(html`<p>Looks good to me.</p>`, { head: ui.userLink("bob") }))}</div>` }] }, | |
| 350 | ]; |
src/web/layout.ts +12 −24
| @@ -40,7 +40,7 @@ import { html, raw, when, type Html } from "./html.ts"; | ||
| 40 | 40 | import { noRoom } from "../spawn/door.ts"; |
| 41 | 41 | import { quotaFull } from "../spawn/quota.ts"; |
| 42 | 42 | import { icon, iconSprite, inlineIcons, themeGlyph } from "./icons.ts"; |
| 43 | import { btn, copyField, kbd, menu, type MenuItem } from "./ui.ts"; | |
| 43 | import { btn, dialogParts, kbd, menu, toast, type MenuItem } from "./ui.ts"; | |
| 44 | 44 | import { SITE_LINE } from "./site_line.ts"; |
| 45 | 45 | |
| 46 | 46 | /** One row of the command palette: title, href, category. */ |
| @@ -232,6 +232,7 @@ function userMenu( | ||
| 232 | 232 | : [ |
| 233 | 233 | { label: "Boards", href: "/boards", icon: "activity" as const }, |
| 234 | 234 | { label: "System memory", href: "/system", icon: "activity" as const }, |
| 235 | { label: "Components", href: "/design/components", icon: "eye" as const }, | |
| 235 | 236 | ]), |
| 236 | 237 | ] |
| 237 | 238 | : []), |
| @@ -329,6 +330,7 @@ function paletteIndex(ctx: Ctx, extra: PaletteItem[]): Html { | ||
| 329 | 330 | ...(ctx.auth.user?.isAdmin |
| 330 | 331 | ? [ |
| 331 | 332 | { t: "System", h: "/system", c: "Go to" }, |
| 333 | { t: "Components", h: "/design/components", c: "Go to" }, | |
| 332 | 334 | { t: "Forges you sent", h: "/forges", c: "Go to" }, |
| 333 | 335 | { t: "Family of forges", h: "/family", c: "Go to" }, |
| 334 | 336 | ] |
| @@ -384,34 +386,20 @@ function overlays(): Html { | ||
| 384 | 386 | </div> |
| 385 | 387 | </dialog> |
| 386 | 388 | <dialog class="dialog" id="help-dialog" aria-labelledby="help-title"> |
| 387 | <div class="dialog-head"><h2 id="help-title">Keyboard shortcuts</h2></div> | |
| 388 | <div class="dialog-body" data-help-body></div> | |
| 389 | <div class="dialog-foot"> | |
| 390 | <form method="dialog"> | |
| 389 | ${dialogParts({ | |
| 390 | titleId: "help-title", | |
| 391 | title: "Keyboard shortcuts", | |
| 392 | body: html``, | |
| 393 | bodyAttrs: raw("data-help-body"), | |
| 394 | foot: html`<form method="dialog"> | |
| 391 | 395 | <button class="btn" type="submit">Close</button> |
| 392 | </form> | |
| 393 | </div> | |
| 396 | </form>`, | |
| 397 | })} | |
| 394 | 398 | </dialog>`; |
| 395 | 399 | } |
| 396 | 400 | |
| 397 | 401 | function flashToast(flash: Flash): Html { |
| 398 | const tone = flash.tone ?? "success"; | |
| 399 | const glyph = | |
| 400 | tone === "danger" ? "alert" : tone === "attn" ? "alert" : "check"; | |
| 401 | return html`<div class="toast" data-tone="${tone}" role="status"> | |
| 402 | ${icon(glyph)} | |
| 403 | <div class="toast-body"> | |
| 404 | ${flash.message}${when( | |
| 405 | flash.link, | |
| 406 | (link) => html` · <a href="${link.href}">${link.label}</a>`, | |
| 407 | )} | |
| 408 | ${when( | |
| 409 | flash.code, | |
| 410 | (code) => | |
| 411 | copyField("flash-code", code, "Code", "Copy code"), | |
| 412 | )} | |
| 413 | </div> | |
| 414 | </div>`; | |
| 402 | return toast({ ...flash, codeId: "flash-code" }); | |
| 415 | 403 | } |
| 416 | 404 | |
| 417 | 405 | // ---- the chrome ---- |
src/web/pages/browse.ts +2 −4
| @@ -74,6 +74,7 @@ import { | ||
| 74 | 74 | tlComment, |
| 75 | 75 | userTag, |
| 76 | 76 | type IconName, |
| 77 | toast, | |
| 77 | 78 | } from "../ui.ts"; |
| 78 | 79 | import { browseCommit, browseCommits } from "./commits.ts"; |
| 79 | 80 | import { blankDraft, editorPage, runContribute } from "./edit.ts"; |
| @@ -1060,10 +1061,7 @@ export function mirrorJobPage(ctx: Ctx): Response { | ||
| 1060 | 1061 | |
| 1061 | 1062 | const foot = |
| 1062 | 1063 | job.stage === "failed" |
| 1063 | ? html`<div class="toast" data-tone="danger" role="alert"> | |
| 1064 | ${icon("alert")} | |
| 1065 | <div class="toast-body">${job.error ?? "The mirror failed."}</div> | |
| 1066 | </div> | |
| 1064 | ? html`${toast({ tone: "danger", role: "alert", message: job.error ?? "The mirror failed." })} | |
| 1067 | 1065 | <div class="bar mt"> |
| 1068 | 1066 | <form |
| 1069 | 1067 | method="post" |
src/web/pages/design_components.ts added +113
| @@ -0,0 +1,113 @@ | ||
| 1 | /** | |
| 2 | * /design/components, for an admin who is a person (#5817): the living | |
| 3 | * gallery — every part `ui.ts` draws, in every state it has | |
| 4 | * (`web/gallery.ts`), the one place to judge the library. Two links pick | |
| 5 | * what the gallery is seen in: `?theme=` any of the forge's themes, and | |
| 6 | * `?w=390|1440` a phone's or a desktop's column. `?part=` narrows it to one | |
| 7 | * part. Each is checked against what it may be, and anything else is the | |
| 8 | * same as leaving it out. | |
| 9 | * | |
| 10 | * The width is a column, not a viewport: a part's media queries still read | |
| 11 | * the window, so a phone's breakpoints are judged on a phone. It shows how a | |
| 12 | * part wraps, truncates and overflows at that width, which is most of what | |
| 13 | * drifts. | |
| 14 | */ | |
| 15 | import { THEME_NAMES, isThemeName, type ThemeName } from "../../design/themes.ts"; | |
| 16 | import type { Ctx } from "../../http/context.ts"; | |
| 17 | import { notFoundPage } from "../chrome.ts"; | |
| 18 | import { GALLERY_SEARCH_FORM, SPECIMENS, type Specimen } from "../gallery.ts"; | |
| 19 | import { html, type Html } from "../html.ts"; | |
| 20 | import { page } from "../layout.ts"; | |
| 21 | import { card, seg } from "../ui.ts"; | |
| 22 | ||
| 23 | const WIDTHS = ["390", "1440"] as const; | |
| 24 | type Width = (typeof WIDTHS)[number]; | |
| 25 | ||
| 26 | export interface GalleryQuery { | |
| 27 | readonly theme: ThemeName | undefined; | |
| 28 | readonly w: Width | undefined; | |
| 29 | readonly part: string | undefined; | |
| 30 | } | |
| 31 | ||
| 32 | /** The query, each value kept only when it is one the gallery knows. */ | |
| 33 | export function readGalleryQuery(params: URLSearchParams): GalleryQuery { | |
| 34 | const theme = params.get("theme") ?? ""; | |
| 35 | const w = params.get("w") ?? ""; | |
| 36 | const part = params.get("part") ?? ""; | |
| 37 | return { | |
| 38 | theme: isThemeName(theme) ? theme : undefined, | |
| 39 | w: (WIDTHS as readonly string[]).includes(w) ? (w as Width) : undefined, | |
| 40 | part: SPECIMENS.some((s) => s.part === part) ? part : undefined, | |
| 41 | }; | |
| 42 | } | |
| 43 | ||
| 44 | /** This page's address with one value changed, the others kept. */ | |
| 45 | function hrefWith(q: GalleryQuery, change: Partial<Record<keyof GalleryQuery, string | undefined>>): string { | |
| 46 | const next = { ...q, ...change }; | |
| 47 | const params = new URLSearchParams(); | |
| 48 | for (const key of ["theme", "w", "part"] as const) { | |
| 49 | const value = next[key]; | |
| 50 | if (value !== undefined) params.set(key, value); | |
| 51 | } | |
| 52 | const query = params.toString(); | |
| 53 | return `/design/components${query === "" ? "" : `?${query}`}`; | |
| 54 | } | |
| 55 | ||
| 56 | function specimen(s: Specimen, q: GalleryQuery): Html { | |
| 57 | return card( | |
| 58 | html`<div class="stack"> | |
| 59 | ${s.states.map( | |
| 60 | (st) => html`<div class="stack stack-tight" data-state="${st.state}"> | |
| 61 | <span class="muted small">${st.state}</span> | |
| 62 | <div class="gallery-stage">${st.draw()}</div> | |
| 63 | </div>`, | |
| 64 | )} | |
| 65 | </div>`, | |
| 66 | { | |
| 67 | id: `part-${s.part}`, | |
| 68 | head: html`<div class="stack stack-tight"> | |
| 69 | <a class="mono" href="${hrefWith(q, { part: s.part })}"><strong>${s.part}</strong></a> | |
| 70 | <span class="muted small">${s.note}</span> | |
| 71 | </div>`, | |
| 72 | }, | |
| 73 | ); | |
| 74 | } | |
| 75 | ||
| 76 | // GET /design/components | |
| 77 | export function designComponentsPage(ctx: Ctx): Response { | |
| 78 | const user = ctx.auth.user; | |
| 79 | if (user?.isAdmin !== true || user.kind === "agent") return notFoundPage(ctx); | |
| 80 | const q = readGalleryQuery(ctx.url.searchParams); | |
| 81 | const shown = q.part === undefined ? SPECIMENS : SPECIMENS.filter((s) => s.part === q.part); | |
| 82 | const themes = seg([ | |
| 83 | { label: "Mine", href: hrefWith(q, { theme: undefined }), current: q.theme === undefined }, | |
| 84 | ...THEME_NAMES.map((name) => ({ label: name, href: hrefWith(q, { theme: name }), current: q.theme === name })), | |
| 85 | ]); | |
| 86 | const widths = seg([ | |
| 87 | { label: "Fluid", href: hrefWith(q, { w: undefined }), current: q.w === undefined }, | |
| 88 | ...WIDTHS.map((w) => ({ label: `${w} px`, href: hrefWith(q, { w }), current: q.w === w })), | |
| 89 | ]); | |
| 90 | const body = html`<div class="stack"> | |
| 91 | <h1>Components</h1> | |
| 92 | <p class="muted"> | |
| 93 | Every part <span class="mono">src/web/ui.ts</span> draws, in each state it has. | |
| 94 | ${shown.length === SPECIMENS.length | |
| 95 | ? html`${SPECIMENS.length} parts.` | |
| 96 | : html`One part of ${SPECIMENS.length}: <a href="${hrefWith(q, { part: undefined })}">show them all</a>.`} | |
| 97 | </p> | |
| 98 | <div class="bar">${themes}${widths}</div> | |
| 99 | <form id="${GALLERY_SEARCH_FORM}" method="get" action="/design/components"> | |
| 100 | ${(["theme", "w", "part"] as const).map((key) => (q[key] === undefined ? null : html`<input type="hidden" name="${key}" value="${q[key]}" />`))} | |
| 101 | </form> | |
| 102 | <div class="gallery-frame" ${q.w === undefined ? null : html`data-w="${q.w}"`}> | |
| 103 | <div class="stack">${shown.map((s) => specimen(s, q))}</div> | |
| 104 | </div> | |
| 105 | </div>`; | |
| 106 | return page({ | |
| 107 | ctx: q.theme === undefined ? ctx : { ...ctx, theme: q.theme }, | |
| 108 | title: "Components", | |
| 109 | wide: q.w === "1440", | |
| 110 | crumbs: [{ label: "Components", href: "/design/components" }], | |
| 111 | body, | |
| 112 | }); | |
| 113 | } |
src/web/pages/limb.ts +10 −8
| @@ -33,7 +33,7 @@ import { | ||
| 33 | 33 | import { field, readForm } from "../form.ts"; |
| 34 | 34 | import { html, when, type Html } from "../html.ts"; |
| 35 | 35 | import { page, redirect } from "../layout.ts"; |
| 36 | import { badge, btn, card, field as formField, listCard, row, selectField } from "../ui.ts"; | |
| 36 | import { badge, btn, card, dialogParts, field as formField, listCard, row, selectField } from "../ui.ts"; | |
| 37 | 37 | import { replanPreviewPage, replanSubmit } from "./limb_replan.ts"; |
| 38 | 38 | import { folded, issueRow } from "./limb_view.ts"; |
| 39 | 39 | import { milestoneHref } from "./milestones.ts"; |
| @@ -280,10 +280,11 @@ export function limbPreviewPage(ctx: Ctx): Response { | ||
| 280 | 280 | class="dialog" |
| 281 | 281 | aria-labelledby="limb-confirm-title" |
| 282 | 282 | > |
| 283 | <div class="dialog-head"> | |
| 284 | <h2 id="limb-confirm-title">${words.go}?</h2> | |
| 285 | </div> | |
| 286 | <div class="dialog-body stack"> | |
| 283 | ${dialogParts({ | |
| 284 | titleId: "limb-confirm-title", | |
| 285 | title: `${words.go}?`, | |
| 286 | stack: true, | |
| 287 | body: html` | |
| 287 | 288 | <input type="hidden" name="action" value="${action}" /> |
| 288 | 289 | ${when( |
| 289 | 290 | request.under, |
| @@ -316,8 +317,8 @@ export function limbPreviewPage(ctx: Ctx): Response { | ||
| 316 | 317 | ], |
| 317 | 318 | }), |
| 318 | 319 | )} |
| 319 | </div> | |
| 320 | <div class="dialog-foot"> | |
| 320 | `, | |
| 321 | foot: html` | |
| 321 | 322 | ${btn("Back", { |
| 322 | 323 | href: milestoneHref(base, number), |
| 323 | 324 | variant: "ghost", |
| @@ -325,7 +326,8 @@ export function limbPreviewPage(ctx: Ctx): Response { | ||
| 325 | 326 | ${btn(words.go, { |
| 326 | 327 | variant: action === "close" ? "danger" : "primary", |
| 327 | 328 | })} |
| 328 | </div> | |
| 329 | `, | |
| 330 | })} | |
| 329 | 331 | </form> |
| 330 | 332 | </div>` |
| 331 | 333 | : html`<p class="mt"> |
src/web/pages/origins.ts +8 −11
| @@ -76,6 +76,7 @@ import { | ||
| 76 | 76 | field as uiField, |
| 77 | 77 | type IconName, |
| 78 | 78 | copyField, |
| 79 | toast, | |
| 79 | 80 | } from "../ui.ts"; |
| 80 | 81 | |
| 81 | 82 | export type AccountSection = |
| @@ -840,19 +841,15 @@ export function originsPage(ctx: Ctx): Response { | ||
| 840 | 841 | const error = params.get("error"); |
| 841 | 842 | const connected = params.get("connected") === "1"; |
| 842 | 843 | const banner = connected |
| 843 | ? html`<div class="toast" data-tone="success" role="status"> | |
| 844 | ${icon("check")} | |
| 845 | <div class="toast-body">Origin connected.</div> | |
| 846 | </div>` | |
| 844 | ? toast({ tone: "success", message: "Origin connected." }) | |
| 847 | 845 | : error !== null && error !== "" |
| 848 | ? html`<div class="toast" data-tone="danger" role="status"> | |
| 849 | ${icon("alert")} | |
| 850 | <div class="toast-body"> | |
| 851 | ${error === "state" | |
| 846 | ? toast({ | |
| 847 | tone: "danger", | |
| 848 | message: | |
| 849 | error === "state" | |
| 852 | 850 | ? "That authorization could not be matched to a connect you started here. Start again." |
| 853 | : error.slice(0, 200)} | |
| 854 | </div> | |
| 855 | </div>` | |
| 851 | : error.slice(0, 200), | |
| 852 | }) | |
| 856 | 853 | : null; |
| 857 | 854 | |
| 858 | 855 | const timing = { rendering: performance.now() }; |
src/web/pages/repo.ts +2 −4
| @@ -85,6 +85,7 @@ import { | ||
| 85 | 85 | seg, |
| 86 | 86 | time, |
| 87 | 87 | copyField, |
| 88 | toast, | |
| 88 | 89 | } from "../ui.ts"; |
| 89 | 90 | |
| 90 | 91 | const MAX_RENDER_BYTES = 1_000_000; |
| @@ -614,10 +615,7 @@ function aboutCard( | ||
| 614 | 615 | </ul> |
| 615 | 616 | ${when( |
| 616 | 617 | o.fetchError !== "", |
| 617 | () => html`<div class="toast" data-tone="danger" role="status"> | |
| 618 | ${icon("alert")} | |
| 619 | <div class="toast-body">${o.fetchError}</div> | |
| 620 | </div>`, | |
| 618 | () => toast({ tone: "danger", message: o.fetchError }), | |
| 621 | 619 | )} |
| 622 | 620 | ${when( |
| 623 | 621 | admin, |
src/web/style/components.ts +23
| @@ -749,6 +749,19 @@ details[open] > summary.row > .row-lead { transform: rotate(90deg); } | ||
| 749 | 749 | .toast .toast-body { flex: 1; min-width: 0; } |
| 750 | 750 | .toast code { display: block; margin-top: 6px; } |
| 751 | 751 | |
| 752 | /* ---- skeleton (a list's or card's space, held while it loads) ---- */ | |
| 753 | .skeleton .row-main { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; } | |
| 754 | .skeleton-bar { | |
| 755 | display: inline-block; vertical-align: middle; | |
| 756 | width: 60%; height: .75em; border-radius: var(--radius); | |
| 757 | background: var(--muted); | |
| 758 | animation: skeleton-pulse 1.2s var(--ease) infinite alternate; | |
| 759 | } | |
| 760 | .skeleton .row-meta .skeleton-bar, .skeleton .card-body p:last-child .skeleton-bar { width: 35%; } | |
| 761 | .skeleton li:nth-child(3n + 2) .row-title .skeleton-bar { width: 75%; } | |
| 762 | .skeleton .card-head .skeleton-bar { width: 30%; } | |
| 763 | @keyframes skeleton-pulse { to { opacity: .45; } } | |
| 764 | ||
| 752 | 765 | /* ---- tooltip ---- */ |
| 753 | 766 | [data-tip] { position: relative; } |
| 754 | 767 | [data-tip]::after { |
| @@ -886,6 +899,16 @@ details[open] > summary.row > .row-lead { transform: rotate(90deg); } | ||
| 886 | 899 | .palette .palette-input { font-size: 16px; } |
| 887 | 900 | } |
| 888 | 901 | |
| 902 | /* ---- gallery (/design/components) ---- */ | |
| 903 | .gallery-frame { overflow-x: auto; } | |
| 904 | .gallery-frame[data-w="390"] > .stack { width: 390px; } | |
| 905 | .gallery-frame[data-w="1440"] > .stack { width: 1440px; } | |
| 906 | .gallery-stage { | |
| 907 | padding: 12px; border: 1px dashed var(--border); border-radius: var(--radius); | |
| 908 | min-width: 0; overflow-wrap: anywhere; | |
| 909 | } | |
| 910 | .gallery-stage .list { max-height: 480px; overflow-y: auto; } | |
| 911 | ||
| 889 | 912 | /* Forced colours drop box-shadow rings and author colours: the focus ring is |
| 890 | 913 | an outline the system paints. */ |
| 891 | 914 | @media (forced-colors: active) { |
src/web/ui.ts +163
| @@ -1231,6 +1231,96 @@ export function selectField( | ||
| 1231 | 1231 | </div>`; |
| 1232 | 1232 | } |
| 1233 | 1233 | |
| 1234 | /** One choice in a `searchPicker`: what it submits, how it reads, and the words a filter matches. */ | |
| 1235 | export interface PickerOption { | |
| 1236 | readonly value: string; | |
| 1237 | readonly title: Html | string; | |
| 1238 | readonly meta?: Html | string; | |
| 1239 | /** The text the filter looks in; the title and anything else worth finding by. */ | |
| 1240 | readonly search: string; | |
| 1241 | readonly checked?: boolean; | |
| 1242 | } | |
| 1243 | ||
| 1244 | /** Choices a picker draws per page; past it, the pager or the filter narrows. */ | |
| 1245 | export const PICKER_PAGE = 50; | |
| 1246 | ||
| 1247 | /** | |
| 1248 | * A long list a person picks from: a search box, a page of checkbox rows | |
| 1249 | * (radios when `multiple` is false), and a pager. It does the filtering and | |
| 1250 | * paging itself, from `q` and `page`, so a caller hands it every choice and | |
| 1251 | * the words the reader typed. A checked choice off this page or outside the | |
| 1252 | * filter rides along as a hidden input, so paging or narrowing never drops | |
| 1253 | * a pick. | |
| 1254 | * | |
| 1255 | * Forms do not nest, so the search box belongs to the GET form named by | |
| 1256 | * `searchForm` — a `<form id method="get">` the caller puts outside the | |
| 1257 | * form the picks submit in. With script, typing narrows this page's rows at | |
| 1258 | * once and the count follows (`client.ts`, "search pickers"); Enter asks the | |
| 1259 | * server for every page. | |
| 1260 | */ | |
| 1261 | export function searchPicker(o: { | |
| 1262 | /** The picker's id; its parts' ids derive from it. */ | |
| 1263 | id: string; | |
| 1264 | label: string; | |
| 1265 | /** The name each pick submits under, once per chosen value. */ | |
| 1266 | name: string; | |
| 1267 | options: readonly PickerOption[]; | |
| 1268 | q: string; | |
| 1269 | searchForm: string; | |
| 1270 | /** 1-based; out of range reads as the nearest page. */ | |
| 1271 | page: number; | |
| 1272 | pageHref: (page: number) => string; | |
| 1273 | pageSize?: number; | |
| 1274 | multiple?: boolean; | |
| 1275 | hint?: string; | |
| 1276 | }): Html { | |
| 1277 | const size = Math.max(1, Math.floor(o.pageSize ?? PICKER_PAGE)); | |
| 1278 | const needle = o.q.trim().toLowerCase(); | |
| 1279 | const matched = o.options.filter((opt) => needle === "" || opt.search.toLowerCase().includes(needle)); | |
| 1280 | const pages = Math.max(1, Math.ceil(matched.length / size)); | |
| 1281 | const page = Math.min(pages, Math.max(1, Number.isFinite(o.page) ? Math.floor(o.page) : 1)); | |
| 1282 | const shown = matched.slice((page - 1) * size, page * size); | |
| 1283 | const onPage = new Set(shown.map((opt) => opt.value)); | |
| 1284 | const carried = o.options.filter((opt) => opt.checked === true && !onPage.has(opt.value)); | |
| 1285 | const picked = o.options.filter((opt) => opt.checked === true).length; | |
| 1286 | const kind = o.multiple === false ? "radio" : "checkbox"; | |
| 1287 | const hintId = `${o.id}-hint`; | |
| 1288 | return html`<div class="field" id="${o.id}" data-picker> | |
| 1289 | <label for="${o.id}-q">${o.label}</label> | |
| 1290 | <div class="bar"> | |
| 1291 | <input class="input grow" type="search" id="${o.id}-q" name="q" form="${o.searchForm}" value="${o.q}" | |
| 1292 | placeholder="Filter" autocomplete="off" spellcheck="false" aria-controls="${o.id}-list" | |
| 1293 | ${o.hint ? html`aria-describedby="${hintId}"` : null} data-picker-q /> | |
| 1294 | <span class="muted small num" aria-live="polite" | |
| 1295 | ><span data-picker-count="${matched.length}">${matched.length}</span> of ${o.options.length}${kind === "checkbox" | |
| 1296 | ? html` · <span data-picker-picked>${picked}</span> picked` | |
| 1297 | : null}</span | |
| 1298 | > | |
| 1299 | </div> | |
| 1300 | ${shown.length === 0 | |
| 1301 | ? html`<p class="muted small">${o.options.length === 0 ? "Nothing to pick from yet." : html`Nothing matches “${o.q.trim()}”.`}</p>` | |
| 1302 | : html`<ul class="list" id="${o.id}-list" role="group" aria-label="${o.label}"> | |
| 1303 | ${shown.map( | |
| 1304 | (opt) => html`<li data-q="${opt.search.toLowerCase()}"> | |
| 1305 | <label class="row"> | |
| 1306 | <span class="row-lead"><input type="${kind}" name="${o.name}" value="${opt.value}" ${opt.checked ? raw("checked") : null} /></span> | |
| 1307 | <span class="row-main"><span class="row-title">${opt.title}</span>${opt.meta ? html`<span class="row-meta">${opt.meta}</span>` : null}</span> | |
| 1308 | </label> | |
| 1309 | </li>`, | |
| 1310 | )} | |
| 1311 | </ul>`} | |
| 1312 | ${carried.map((opt) => html`<input type="hidden" name="${o.name}" value="${opt.value}" data-picker-carried />`)} | |
| 1313 | ${pages > 1 | |
| 1314 | ? pager({ | |
| 1315 | ...(page > 1 ? { prev: o.pageHref(page - 1) } : {}), | |
| 1316 | ...(page < pages ? { next: o.pageHref(page + 1) } : {}), | |
| 1317 | note: `page ${page} of ${pages}`, | |
| 1318 | }) | |
| 1319 | : null} | |
| 1320 | ${o.hint ? html`<span class="hint" id="${hintId}">${o.hint}</span>` : null} | |
| 1321 | </div>`; | |
| 1322 | } | |
| 1323 | ||
| 1234 | 1324 | /** |
| 1235 | 1325 | * A destructive action. With JS it opens a `<dialog>`; without it the button |
| 1236 | 1326 | * is a plain link to a confirm page, so nothing is ever one careless click |
| @@ -1265,6 +1355,79 @@ export function empty(o: { | ||
| 1265 | 1355 | </div>`; |
| 1266 | 1356 | } |
| 1267 | 1357 | |
| 1358 | export type ToastTone = "success" | "danger" | "attn"; | |
| 1359 | ||
| 1360 | /** | |
| 1361 | * The one-line banner a page shows once: the flash a write leaves after its | |
| 1362 | * redirect, or a failure the page found itself. An icon for its tone, the | |
| 1363 | * message, then an optional link and a copyable one-time code. | |
| 1364 | */ | |
| 1365 | export function toast(o: { | |
| 1366 | tone?: ToastTone; | |
| 1367 | message: string | Html; | |
| 1368 | link?: { href: string; label: string }; | |
| 1369 | /** A one-time value, shown in a copyable monospace block. */ | |
| 1370 | code?: string; | |
| 1371 | /** The code block's id; one toast per page, so the default rarely moves. */ | |
| 1372 | codeId?: string; | |
| 1373 | /** `alert` when the failure is what the page is about; `status` otherwise. */ | |
| 1374 | role?: "status" | "alert"; | |
| 1375 | }): Html { | |
| 1376 | const tone = o.tone ?? "success"; | |
| 1377 | return html`<div class="toast" data-tone="${tone}" role="${o.role ?? "status"}"> | |
| 1378 | ${icon(tone === "success" ? "check" : "alert")} | |
| 1379 | <div class="toast-body"> | |
| 1380 | ${o.message}${when(o.link, (link) => html` · <a href="${link.href}">${link.label}</a>`)} | |
| 1381 | ${when(o.code, (code) => copyField(o.codeId ?? "toast-code", code, "Code", "Copy code"))} | |
| 1382 | </div> | |
| 1383 | </div>`; | |
| 1384 | } | |
| 1385 | ||
| 1386 | /** | |
| 1387 | * A §5 dialog's three parts — the head that names it (`titleId` is what the | |
| 1388 | * wrapper's `aria-labelledby` points at), the body, and the foot of buttons, | |
| 1389 | * the primary or danger one last. The wrapper is the caller's: a `<dialog>` | |
| 1390 | * the shell opens, or a `<form class="dialog">` drawn as a page of its own. | |
| 1391 | */ | |
| 1392 | export function dialogParts(o: { | |
| 1393 | titleId: string; | |
| 1394 | title: string | Html; | |
| 1395 | body: Html; | |
| 1396 | foot: Html; | |
| 1397 | /** The body holds several fields, spaced as a stack. */ | |
| 1398 | stack?: boolean; | |
| 1399 | /** Attributes on the body, for a script that fills it. */ | |
| 1400 | bodyAttrs?: Html; | |
| 1401 | }): Html { | |
| 1402 | return html`<div class="dialog-head"><h2 id="${o.titleId}">${o.title}</h2></div> | |
| 1403 | <div class="dialog-body${o.stack ? " stack" : ""}" ${o.bodyAttrs ?? null}>${o.body}</div> | |
| 1404 | <div class="dialog-foot">${o.foot}</div>`; | |
| 1405 | } | |
| 1406 | ||
| 1407 | /** | |
| 1408 | * A placeholder that holds a list's or a card's space while what goes there | |
| 1409 | * loads: real `.list` rows or a real `.card`, so the swap shifts nothing, with | |
| 1410 | * grey bars where the words will be. The bars pulse; asked for less motion, | |
| 1411 | * they hold still. | |
| 1412 | */ | |
| 1413 | export function skeleton(o: { shape?: "list" | "card"; rows?: number } = {}): Html { | |
| 1414 | const n = Math.min(Math.max(Math.trunc(o.rows ?? 3) || 1, 1), 50); | |
| 1415 | const bar = raw('<span class="skeleton-bar"></span>'); | |
| 1416 | const lines = Array.from({ length: n }, () => bar); | |
| 1417 | const body = | |
| 1418 | o.shape === "card" | |
| 1419 | ? html`<div class="card-head">${bar}</div> | |
| 1420 | <div class="card-body stack">${lines.map((b) => html`<p>${b}</p>`)}</div>` | |
| 1421 | : html`<ul class="list"> | |
| 1422 | ${lines.map( | |
| 1423 | (b) => html`<li><div class="row"><span class="row-main"><span class="row-title">${b}</span><span class="row-meta">${b}</span></span></div></li>`, | |
| 1424 | )} | |
| 1425 | </ul>`; | |
| 1426 | return html`<div class="card skeleton" role="status" aria-busy="true"> | |
| 1427 | <span class="sr-only">Loading…</span>${body} | |
| 1428 | </div>`; | |
| 1429 | } | |
| 1430 | ||
| 1268 | 1431 | export interface TimelineEvent { |
| 1269 | 1432 | icon: IconName; |
| 1270 | 1433 | tone?: Tone; |
test/design-gallery.test.ts added +205
| @@ -0,0 +1,205 @@ | ||
| 1 | /** | |
| 2 | * The living gallery (#5817): every part `ui.ts` draws has a specimen, the | |
| 3 | * states the issue names are all shown, `/design/components` answers an | |
| 4 | * admin with every part and anyone else with the not-found page, and its | |
| 5 | * query takes only the themes and widths it knows. | |
| 6 | */ | |
| 7 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 8 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 9 | import { tmpdir } from "node:os"; | |
| 10 | import { join } from "node:path"; | |
| 11 | import { createApp } from "../src/app.ts"; | |
| 12 | import { createToken } from "../src/core/tokens.ts"; | |
| 13 | import { createUser } from "../src/core/users.ts"; | |
| 14 | import { serve } from "../src/http/server.ts"; | |
| 15 | import { NOT_DRAWN, SPECIMENS, STATES } from "../src/web/gallery.ts"; | |
| 16 | import { readGalleryQuery } from "../src/web/pages/design_components.ts"; | |
| 17 | import { html } from "../src/web/html.ts"; | |
| 18 | import * as ui from "../src/web/ui.ts"; | |
| 19 | ||
| 20 | describe("the specimens", () => { | |
| 21 | test("every function ui.ts exports is drawn in the gallery or named as not drawn", () => { | |
| 22 | const parts = Object.entries(ui) | |
| 23 | .filter(([, value]) => typeof value === "function") | |
| 24 | .map(([name]) => name); | |
| 25 | const drawn = new Set(SPECIMENS.map((s) => s.part)); | |
| 26 | expect(parts.filter((p) => !drawn.has(p as keyof typeof ui) && !NOT_DRAWN.has(p))).toEqual([]); | |
| 27 | expect([...NOT_DRAWN].filter((p) => !parts.includes(p))).toEqual([]); | |
| 28 | }); | |
| 29 | ||
| 30 | test("a part appears once, and every state draws markup", () => { | |
| 31 | expect(new Set(SPECIMENS.map((s) => s.part)).size).toBe(SPECIMENS.length); | |
| 32 | for (const s of SPECIMENS) { | |
| 33 | expect(s.states.length).toBeGreaterThan(0); | |
| 34 | for (const st of s.states) expect(typeof st.draw().text).toBe("string"); | |
| 35 | } | |
| 36 | }); | |
| 37 | ||
| 38 | test("each state the issue names is shown by some part", () => { | |
| 39 | const shown = new Set(SPECIMENS.flatMap((s) => s.states.map((st) => st.state))); | |
| 40 | for (const state of ["empty", "loading", "error", "long text", "200 items"] as const) expect(shown.has(state)).toBe(true); | |
| 41 | expect([...shown].every((s) => (STATES as readonly string[]).includes(s))).toBe(true); | |
| 42 | }); | |
| 43 | ||
| 44 | test("the lists that hold many rows are shown holding 200", () => { | |
| 45 | for (const part of ["listCard", "menu", "selectField", "tabs", "chartBox"]) { | |
| 46 | const s = SPECIMENS.find((x) => x.part === part)!; | |
| 47 | const many = s.states.find((st) => st.state === "200 items"); | |
| 48 | expect(many).toBeDefined(); | |
| 49 | } | |
| 50 | const list = SPECIMENS.find((x) => x.part === "listCard")!.states.find((st) => st.state === "200 items")!.draw().text; | |
| 51 | expect(list.match(/<li/g)?.length).toBe(200); | |
| 52 | }); | |
| 53 | }); | |
| 54 | ||
| 55 | describe("the query", () => { | |
| 56 | test("keeps a known theme, width and part, and drops anything else", () => { | |
| 57 | expect(readGalleryQuery(new URLSearchParams("theme=dark&w=390&part=btn"))).toEqual({ theme: "dark", w: "390", part: "btn" }); | |
| 58 | expect(readGalleryQuery(new URLSearchParams("theme=%22%3E%3Cscript%3E&w=391&part=constructor"))).toEqual({ | |
| 59 | theme: undefined, | |
| 60 | w: undefined, | |
| 61 | part: undefined, | |
| 62 | }); | |
| 63 | }); | |
| 64 | }); | |
| 65 | ||
| 66 | describe("/design/components", () => { | |
| 67 | let dir: string; | |
| 68 | let app: ReturnType<typeof createApp>; | |
| 69 | let servers: Awaited<ReturnType<typeof serve>>; | |
| 70 | const tok: Record<string, string> = {}; | |
| 71 | const get = (path: string, who: string | null) => | |
| 72 | fetch(servers.url + path, { headers: who ? { authorization: `Bearer ${tok[who]}` } : {} }); | |
| 73 | ||
| 74 | beforeAll(async () => { | |
| 75 | dir = await mkdtemp(join(tmpdir(), "forge-design-gallery-")); | |
| 76 | app = createApp({ dataDir: dir, port: 0 }); | |
| 77 | servers = await serve(app); | |
| 78 | const mk = async (username: string, adminIfFirst?: boolean) => { | |
| 79 | const r = await createUser(app.db, { | |
| 80 | origin: "seed", | |
| 81 | trusted: true, | |
| 82 | username, | |
| 83 | email: `${username}@forge.local`, | |
| 84 | password: "a-good-passphrase", | |
| 85 | ...(adminIfFirst ? { adminIfFirst } : {}), | |
| 86 | }); | |
| 87 | if (!r.ok) throw new Error(r.error); | |
| 88 | return r.value; | |
| 89 | }; | |
| 90 | const alice = await mk("alice", true); | |
| 91 | const bob = await mk("bob"); | |
| 92 | tok.admin = createToken(app.db, alice.id, "t", "admin").token; | |
| 93 | tok.bob = createToken(app.db, bob.id, "t", "admin").token; | |
| 94 | }); | |
| 95 | ||
| 96 | afterAll(async () => { | |
| 97 | servers.stop(); | |
| 98 | app.close(); | |
| 99 | await rm(dir, { recursive: true, force: true }); | |
| 100 | }); | |
| 101 | ||
| 102 | test("an admin sees every part, and the page keeps the security floor", async () => { | |
| 103 | const res = await get("/design/components", "admin"); | |
| 104 | expect(res.status).toBe(200); | |
| 105 | expect(res.headers.get("content-security-policy")).toContain("frame-ancestors 'none'"); | |
| 106 | expect(res.headers.get("x-content-type-options")).toBe("nosniff"); | |
| 107 | const body = await res.text(); | |
| 108 | for (const s of SPECIMENS) expect(body).toContain(`id="part-${s.part}"`); | |
| 109 | expect(body).toContain('data-state="200 items"'); | |
| 110 | }); | |
| 111 | ||
| 112 | test("a theme and a width are applied, and a part narrows the page to one", async () => { | |
| 113 | const body = await (await get("/design/components?theme=dark&w=390&part=btn", "admin")).text(); | |
| 114 | expect(body).toMatch(/<html lang="en"\s+data-theme="dark"/); | |
| 115 | expect(body).toContain('class="gallery-frame" data-w="390"'); | |
| 116 | expect(body).toContain('id="part-btn"'); | |
| 117 | expect(body).not.toContain('id="part-row"'); | |
| 118 | }); | |
| 119 | ||
| 120 | test("a value the gallery does not know is ignored, never echoed", async () => { | |
| 121 | const body = await (await get("/design/components?theme=%22%3E%3Cb%3Ex&w=9999", "admin")).text(); | |
| 122 | expect(body).not.toContain("<b>x"); | |
| 123 | expect(body).not.toContain('data-w="9999"'); | |
| 124 | }); | |
| 125 | ||
| 126 | test("anyone but an admin gets the not-found page", async () => { | |
| 127 | expect((await get("/design/components", "bob")).status).toBe(404); | |
| 128 | expect((await get("/design/components", null)).status).toBe(404); | |
| 129 | }); | |
| 130 | ||
| 131 | test("the admin menu links to it", async () => { | |
| 132 | const body = await (await get("/", "admin")).text(); | |
| 133 | expect(body).toContain('href="/design/components"'); | |
| 134 | }); | |
| 135 | }); | |
| 136 | ||
| 137 | describe("searchPicker", () => { | |
| 138 | const opts = (n: number, checked: number[] = []) => | |
| 139 | Array.from({ length: n }, (_, i) => ({ value: `v${i}`, title: `repo-${i}`, search: `repo-${i}${i === 7 ? " needle" : ""}`, checked: checked.includes(i) })); | |
| 140 | const draw = (o: Partial<Parameters<typeof ui.searchPicker>[0]> = {}) => | |
| 141 | ui.searchPicker({ id: "p", label: "Repos", name: "pick", options: opts(120, [0, 110]), q: "", searchForm: "s", page: 1, pageHref: (p) => `/x?page=${p}`, ...o }).text; | |
| 142 | const boxes = (text: string) => [...text.matchAll(/type="checkbox" name="pick" value="(v\d+)"/g)].map((m) => m[1]); | |
| 143 | ||
| 144 | test("draws one page, links the next, and carries a pick from another page", () => { | |
| 145 | const text = draw(); | |
| 146 | expect(boxes(text)).toHaveLength(ui.PICKER_PAGE); | |
| 147 | expect(text).toContain('href="/x?page=2"'); | |
| 148 | expect(text).toContain("page 1 of 3"); | |
| 149 | expect(text).toMatch(/type="hidden" name="pick" value="v110"/); | |
| 150 | expect(text).not.toMatch(/type="hidden" name="pick" value="v0"/); | |
| 151 | }); | |
| 152 | ||
| 153 | test("filters by its search words, and a pick the filter hides still rides along", () => { | |
| 154 | const text = draw({ q: " NEEDLE " }); | |
| 155 | expect(boxes(text)).toEqual(["v7"]); | |
| 156 | expect(text).toMatch(/type="hidden" name="pick" value="v0"/); | |
| 157 | expect(text).not.toContain("page 1 of"); | |
| 158 | }); | |
| 159 | ||
| 160 | test("an out-of-range page reads as the nearest, and nothing matching says so", () => { | |
| 161 | expect(draw({ page: 99 })).toContain("page 3 of 3"); | |
| 162 | expect(draw({ page: Number.NaN })).toContain("page 1 of 3"); | |
| 163 | expect(draw({ q: "<b>zzz" })).toContain("Nothing matches “<b>zzz”."); | |
| 164 | expect(draw({ options: [] })).toContain("Nothing to pick from yet."); | |
| 165 | }); | |
| 166 | ||
| 167 | test("the search box belongs to the GET form, and a single pick is a radio", () => { | |
| 168 | expect(draw()).toMatch(/type="search"[^>]*name="q"[^>]*form="s"/); | |
| 169 | expect(draw({ multiple: false })).toContain('type="radio" name="pick"'); | |
| 170 | expect(draw({ multiple: false })).not.toContain("data-picker-picked"); | |
| 171 | }); | |
| 172 | }); | |
| 173 | ||
| 174 | describe("toast, dialogParts and skeleton (#5880)", () => { | |
| 175 | test("a toast carries its tone's icon, escapes its message, and adds a link and a code only when given", () => { | |
| 176 | const ok = ui.toast({ message: "<b>done</b>" }).text; | |
| 177 | expect(ok).toContain('class="toast" data-tone="success" role="status"'); | |
| 178 | expect(ok).toContain("#i-check"); | |
| 179 | expect(ok).toContain("<b>done</b>"); | |
| 180 | expect(ok).not.toContain("<a "); | |
| 181 | const bad = ui.toast({ tone: "danger", role: "alert", message: "x", link: { href: "/a", label: "See it" }, code: "c0de", codeId: "k" }).text; | |
| 182 | expect(bad).toContain('data-tone="danger" role="alert"'); | |
| 183 | expect(bad).toContain("#i-alert"); | |
| 184 | expect(bad).toContain('<a href="/a">See it</a>'); | |
| 185 | expect(bad).toContain('id="k"'); | |
| 186 | expect(bad).toContain("c0de"); | |
| 187 | }); | |
| 188 | ||
| 189 | test("dialogParts draws head, body and foot, the title named by its id", () => { | |
| 190 | const d = ui.dialogParts({ titleId: "t", title: "Sure?", body: html`<p>b</p>`, foot: html`<button>f</button>`, stack: true }).text; | |
| 191 | expect(d).toMatch(/<div class="dialog-head"><h2 id="t">Sure\?<\/h2><\/div>\s*<div class="dialog-body stack"\s*><p>b<\/p><\/div>\s*<div class="dialog-foot"><button>f<\/button><\/div>/); | |
| 192 | }); | |
| 193 | ||
| 194 | test("a skeleton holds real list rows or a real card, says it is loading, and keeps its row count in bounds", () => { | |
| 195 | const list = ui.skeleton({ rows: 4 }).text; | |
| 196 | expect(list).toContain('class="card skeleton" role="status" aria-busy="true"'); | |
| 197 | expect(list).toContain("Loading…"); | |
| 198 | expect(list.match(/<li><div class="row">/g)?.length).toBe(4); | |
| 199 | expect(ui.skeleton({ rows: 999 }).text.match(/<li>/g)?.length).toBe(50); | |
| 200 | expect(ui.skeleton({ rows: Number.NaN }).text.match(/<li>/g)?.length).toBe(1); | |
| 201 | const card = ui.skeleton({ shape: "card", rows: 2 }).text; | |
| 202 | expect(card).toContain('class="card-head"'); | |
| 203 | expect(card.match(/<p><span class="skeleton-bar">/g)?.length).toBe(2); | |
| 204 | }); | |
| 205 | }); |
new above
offline