diff --git a/.agents-docs/AGENTS-architecture-console-page.md b/.agents-docs/AGENTS-architecture-console-page.md index 794655f..e591c23 100644 --- a/.agents-docs/AGENTS-architecture-console-page.md +++ b/.agents-docs/AGENTS-architecture-console-page.md @@ -21,6 +21,7 @@ One row per file under `src/web-console/public/` (the games and their sound are | `public/skills.js` | the skill list: every per-skill fact the console uses (card, order, start pose, launch scoring, subagent opt-in, which spec states light its card), data only, imported by the page and by Node; the older tables (`SKILL_CATALOG`, `START_POSES`, `CONSOLE_WORKFLOWS` and the rest, in `answers.js`) are lookups on it. Each entry also carries `weight` (what its launch and `run` score on the meter, or null), `started` and `ran` (the meter's labels for them, or null), `resume` (`"overview"`, `"folder"` or null: what the resume command takes after the skill's command) and an optional `card.help` (Help's line for the card when it differs from `blurb`). `WORKFLOWS` (every entry's workflow, in order) and `isWorkflow()` are what the CLI checks a `--workflow` against. The meter's `WEIGHTS`, `LAUNCH_LABELS` and `RUN_LABELS`, `resumeCommand()`, Help's card list and `cmd-help`'s workflow list are all derived from it, so a new skill is one entry here, not an edit to each of those | | `public/sound.js` | the sound cues: which plays, one at a time, held until the first click; seven cues (not Planny snoring or waking) play the file picked in Preferences, saved flat as `soundFile` (`soundFileQuestion`) out of the 19 files `sound-01` to `sound-19` in `public/sounds/` | | `public/spec-states.js` | the spec states (`diagnosed`, `fixed`, `exploring`, `mapped`, `planned`, `documented`, `building`, `built`, `unrecognized`): each one's picker label, the card it is the natural next step for and its recommendation, data only; which cards a state lights lives in `skills.js`, how a folder maps to a state in `classifySpec()` in `scan.mjs` | +| `public/card-rows.js` | how many cards a dashboard group draws per row (`steadyColumns(count, width)`): one card width per group, what fits or one column more or fewer to leave no card alone on a row (one empty corner is fine from three across), a last row still short centered; `screens/dashboard.js` applies it as `--dash-cols` and `is-centered` on draw and on resize; tested in `scripts/test-web-console-card-rows.mjs` | | `public/state.js` | the page's shared state (`page.S` the server's truth, `page.local` what is staged) and the `redraw()` / save hooks every screen calls; defines only | | `public/uploads.js` | pictures and documents attached to a note: chips, trays, re-encoding, upload, retry, and the page's shared full-screen picture preview (`openPicview`, the `#picview` dialog every thumbnail opens) | | `public/screens/ask.js` | the Ask chat, the Subagents tab, and attaching files to notes | diff --git a/package.json b/package.json index 25ed305..ce7d963 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "play": "node scripts/play.mjs", "pretest": "node scripts/fix-line-endings.mjs", "test:fast": "node scripts/test-fast.mjs", - "test": "node scripts/check-test-lanes.mjs && node scripts/validate-char-count.js && node install.js --build-skills && node scripts/check-versions.mjs && node scripts/check-doc-size.mjs && node scripts/parse-check.mjs && node scripts/check-skill-table.mjs && node scripts/check-prompt-wording.mjs && node scripts/check-console-openings.mjs && node scripts/node-test.mjs scripts/test-line-endings.mjs scripts/test-us-english.mjs scripts/test-script-git.mjs scripts/test-git-repo.mjs scripts/test-skill-scripts.mjs scripts/test-script-test-map.mjs scripts/test-script-test-match.mjs scripts/test-script-test-commands.mjs scripts/test-script-run-check.mjs scripts/test-script-pr-prep.mjs scripts/test-script-dead-code.mjs scripts/test-script-ui-prototype.mjs scripts/test-script-coverage.mjs scripts/test-script-changelog.mjs scripts/test-web-console-git.mjs scripts/test-web-console-git-board.mjs scripts/test-web-console-chat.mjs scripts/test-web-console-subagents.mjs scripts/test-web-console-pointers.mjs scripts/test-console-wire-budgets.mjs scripts/test-web-console-speed.mjs scripts/test-web-console-qa.mjs scripts/test-web-console-concurrency.mjs scripts/test-web-console-workspace.mjs scripts/test-web-console-lifecycle.mjs scripts/test-web-console-chat-stress.mjs scripts/test-web-console-server.mjs scripts/test-web-console-session.mjs scripts/test-web-console-logic.mjs scripts/test-web-console-agents-doc.mjs scripts/test-web-console-prototypes.mjs scripts/test-web-console-activities.mjs scripts/test-web-console-activities-rapids.mjs scripts/test-web-console-activities-flock.mjs scripts/test-web-console-activities-bounce.mjs scripts/test-web-console-activities-bounce-game.mjs scripts/test-web-console-activities-ghoul.mjs scripts/test-web-console-activities-ghoul-graveyard.mjs scripts/test-web-console-activities-ghoul-grounds.mjs scripts/test-web-console-activities-ghoul-chapel.mjs scripts/test-web-console-activities-ghoul-sanatorium.mjs scripts/test-web-console-activities-ghoul-village.mjs scripts/test-web-console-activities-ghoul-mine.mjs scripts/test-web-console-activities-ghoul-carnival.mjs scripts/test-web-console-activities-ghoul-frozen.mjs scripts/test-web-console-activities-ghoul-bog.mjs scripts/test-web-console-activities-ghoul-lantern.mjs scripts/test-web-console-activities-ghoul-marrow.mjs scripts/test-web-console-activities-ghoul-mat.mjs scripts/test-web-console-activities-ghoul-eye.mjs scripts/test-web-console-activities-ghoul-bonestair.mjs scripts/test-web-console-activities-ghoul-heart.mjs scripts/test-web-console-activities-ghoul-ending.mjs scripts/test-web-console-activities-ghoul-ride.mjs scripts/test-web-console-activities-ghoul-cart.mjs scripts/test-web-console-activities-ghoul-sled.mjs scripts/test-web-console-activities-ghoul-banister.mjs scripts/test-web-console-activities-ghoul-gurney.mjs scripts/test-web-console-activities-ghoul-hearse.mjs scripts/test-web-console-activities-ghoul-wagon.mjs scripts/test-web-console-activities-ghoul-pew.mjs scripts/test-web-console-activities-ghoul-mower.mjs scripts/test-web-console-activities-ghoul-tray.mjs scripts/test-web-console-activities-ghoul-arms.mjs scripts/test-web-console-activities-ghoul-dice.mjs scripts/test-web-console-activities-ghoul-gameover.mjs scripts/test-web-console-activities-ghoul-intro.mjs scripts/test-web-console-activities-ghoul-bossintro.mjs scripts/test-web-console-activities-ghoul-story.mjs scripts/test-web-console-activities-ghoul-bones.mjs scripts/test-web-console-activities-ghoul-retry.mjs scripts/test-web-console-activities-bounce-cars.mjs scripts/test-web-console-tones.mjs scripts/test-web-console-skills.mjs scripts/test-web-console-spec-states.mjs scripts/test-spec-carry.mjs scripts/test-spec-carry-page.mjs scripts/test-web-console-state.mjs scripts/test-web-console-send-state.mjs scripts/test-web-console-strengths.mjs scripts/test-web-console-shape.mjs scripts/test-script-pathfinder.mjs scripts/test-skill-test-runs.mjs scripts/test-launcher.mjs scripts/test-agents-file.mjs scripts/test-agent-lookup.mjs scripts/test-web-console-source.mjs scripts/test-web-console-hardening.mjs scripts/test-web-console-embed.mjs scripts/test-web-console-in-app.mjs scripts/test-web-console-loop.mjs scripts/test-web-console-handoffs.mjs scripts/test-web-console-notepad.mjs scripts/test-script-xray.mjs scripts/test-script-finalize.mjs scripts/test-getting-started.mjs scripts/test-install-update.mjs scripts/test-browser-helper.mjs scripts/test-web-console-page-cards.mjs scripts/test-web-console-page-dashboard.mjs scripts/test-web-console-page-session.mjs scripts/test-web-console-page-ask.mjs scripts/test-web-console-page-workspace.mjs scripts/test-web-console-page-help.mjs scripts/test-web-console-page-prefs.mjs scripts/test-web-console-page-git.mjs scripts/test-web-console-page-notepad.mjs scripts/test-web-console-page-send.mjs scripts/test-web-console-page-loop.mjs scripts/test-web-console-page-activities.mjs scripts/test-web-console-page-setup.mjs scripts/test-ui-prototype-page.mjs scripts/test-standalone-check.mjs scripts/test-check-versions.mjs scripts/test-app-meter.mjs scripts/test-check-test-lanes.mjs scripts/test-check-doc-size.mjs scripts/test-set-version.mjs scripts/test-console-stub.mjs scripts/test-check-prompt-wording.mjs scripts/test-check-console-openings.mjs" + "test": "node scripts/check-test-lanes.mjs && node scripts/validate-char-count.js && node install.js --build-skills && node scripts/check-versions.mjs && node scripts/check-doc-size.mjs && node scripts/parse-check.mjs && node scripts/check-skill-table.mjs && node scripts/check-prompt-wording.mjs && node scripts/check-console-openings.mjs && node scripts/node-test.mjs scripts/test-line-endings.mjs scripts/test-us-english.mjs scripts/test-script-git.mjs scripts/test-git-repo.mjs scripts/test-skill-scripts.mjs scripts/test-script-test-map.mjs scripts/test-script-test-match.mjs scripts/test-script-test-commands.mjs scripts/test-script-run-check.mjs scripts/test-script-pr-prep.mjs scripts/test-script-dead-code.mjs scripts/test-script-ui-prototype.mjs scripts/test-script-coverage.mjs scripts/test-script-changelog.mjs scripts/test-web-console-git.mjs scripts/test-web-console-git-board.mjs scripts/test-web-console-chat.mjs scripts/test-web-console-subagents.mjs scripts/test-web-console-pointers.mjs scripts/test-console-wire-budgets.mjs scripts/test-web-console-speed.mjs scripts/test-web-console-qa.mjs scripts/test-web-console-concurrency.mjs scripts/test-web-console-workspace.mjs scripts/test-web-console-lifecycle.mjs scripts/test-web-console-chat-stress.mjs scripts/test-web-console-server.mjs scripts/test-web-console-session.mjs scripts/test-web-console-logic.mjs scripts/test-web-console-agents-doc.mjs scripts/test-web-console-prototypes.mjs scripts/test-web-console-activities.mjs scripts/test-web-console-activities-rapids.mjs scripts/test-web-console-activities-flock.mjs scripts/test-web-console-activities-bounce.mjs scripts/test-web-console-activities-bounce-game.mjs scripts/test-web-console-activities-ghoul.mjs scripts/test-web-console-activities-ghoul-graveyard.mjs scripts/test-web-console-activities-ghoul-grounds.mjs scripts/test-web-console-activities-ghoul-chapel.mjs scripts/test-web-console-activities-ghoul-sanatorium.mjs scripts/test-web-console-activities-ghoul-village.mjs scripts/test-web-console-activities-ghoul-mine.mjs scripts/test-web-console-activities-ghoul-carnival.mjs scripts/test-web-console-activities-ghoul-frozen.mjs scripts/test-web-console-activities-ghoul-bog.mjs scripts/test-web-console-activities-ghoul-lantern.mjs scripts/test-web-console-activities-ghoul-marrow.mjs scripts/test-web-console-activities-ghoul-mat.mjs scripts/test-web-console-activities-ghoul-eye.mjs scripts/test-web-console-activities-ghoul-bonestair.mjs scripts/test-web-console-activities-ghoul-heart.mjs scripts/test-web-console-activities-ghoul-ending.mjs scripts/test-web-console-activities-ghoul-ride.mjs scripts/test-web-console-activities-ghoul-cart.mjs scripts/test-web-console-activities-ghoul-sled.mjs scripts/test-web-console-activities-ghoul-banister.mjs scripts/test-web-console-activities-ghoul-gurney.mjs scripts/test-web-console-activities-ghoul-hearse.mjs scripts/test-web-console-activities-ghoul-wagon.mjs scripts/test-web-console-activities-ghoul-pew.mjs scripts/test-web-console-activities-ghoul-mower.mjs scripts/test-web-console-activities-ghoul-tray.mjs scripts/test-web-console-activities-ghoul-arms.mjs scripts/test-web-console-activities-ghoul-dice.mjs scripts/test-web-console-activities-ghoul-gameover.mjs scripts/test-web-console-activities-ghoul-intro.mjs scripts/test-web-console-activities-ghoul-bossintro.mjs scripts/test-web-console-activities-ghoul-story.mjs scripts/test-web-console-activities-ghoul-bones.mjs scripts/test-web-console-activities-ghoul-retry.mjs scripts/test-web-console-activities-bounce-cars.mjs scripts/test-web-console-tones.mjs scripts/test-web-console-skills.mjs scripts/test-web-console-spec-states.mjs scripts/test-web-console-card-rows.mjs scripts/test-spec-carry.mjs scripts/test-spec-carry-page.mjs scripts/test-web-console-state.mjs scripts/test-web-console-send-state.mjs scripts/test-web-console-strengths.mjs scripts/test-web-console-shape.mjs scripts/test-script-pathfinder.mjs scripts/test-skill-test-runs.mjs scripts/test-launcher.mjs scripts/test-agents-file.mjs scripts/test-agent-lookup.mjs scripts/test-web-console-source.mjs scripts/test-web-console-hardening.mjs scripts/test-web-console-embed.mjs scripts/test-web-console-in-app.mjs scripts/test-web-console-loop.mjs scripts/test-web-console-handoffs.mjs scripts/test-web-console-notepad.mjs scripts/test-script-xray.mjs scripts/test-script-finalize.mjs scripts/test-getting-started.mjs scripts/test-install-update.mjs scripts/test-browser-helper.mjs scripts/test-web-console-page-cards.mjs scripts/test-web-console-page-dashboard.mjs scripts/test-web-console-page-session.mjs scripts/test-web-console-page-ask.mjs scripts/test-web-console-page-workspace.mjs scripts/test-web-console-page-help.mjs scripts/test-web-console-page-prefs.mjs scripts/test-web-console-page-git.mjs scripts/test-web-console-page-notepad.mjs scripts/test-web-console-page-send.mjs scripts/test-web-console-page-loop.mjs scripts/test-web-console-page-activities.mjs scripts/test-web-console-page-setup.mjs scripts/test-ui-prototype-page.mjs scripts/test-standalone-check.mjs scripts/test-check-versions.mjs scripts/test-app-meter.mjs scripts/test-check-test-lanes.mjs scripts/test-check-doc-size.mjs scripts/test-set-version.mjs scripts/test-console-stub.mjs scripts/test-check-prompt-wording.mjs scripts/test-check-console-openings.mjs" }, "devDependencies": { "gpt-tokenizer": "2.9.0", diff --git a/scripts/test-lanes.json b/scripts/test-lanes.json index d2569c1..e65a830 100644 --- a/scripts/test-lanes.json +++ b/scripts/test-lanes.json @@ -33,6 +33,7 @@ "test-spec-carry.mjs", "test-us-english.mjs", "test-web-console-agents-doc.mjs", + "test-web-console-card-rows.mjs", "test-web-console-git-board.mjs", "test-web-console-prototypes.mjs", "test-web-console-send-state.mjs", diff --git a/scripts/test-web-console-card-rows.mjs b/scripts/test-web-console-card-rows.mjs new file mode 100644 index 0000000..f480889 --- /dev/null +++ b/scripts/test-web-console-card-rows.mjs @@ -0,0 +1,65 @@ +// Web console tests, the dashboard's card rows: public/card-rows.js picks how +// many cards a dashboard group draws per row, so no card sits alone on a row. +// Every card in a group keeps one width; the count moves by one from what fits +// when that leaves fewer gaps; one empty corner is fine; a short last row is +// centered (at two across an empty corner is a lone card, so it counts as a +// gap there). Run with: node --test scripts/test-web-console-card-rows.mjs + +import test from "node:test"; +import assert from "node:assert/strict"; +import { steadyColumns } from "../src/web-console/public/card-rows.js"; + +// Widths are the grid's own, in px: 720, 880, 1080 and 1440 are the Card width +// presets, 358 a phone. At 240px cards and 12px gaps they fit 2, 3, 4, 5 and 1. +const CASES = [ + // count, width, cols, center, why + [11, 880, 3, false, "3 + 3 + 3 + 2: one empty corner is fine"], + [11, 1080, 4, false, "4 + 4 + 3: one empty corner is fine"], + [11, 1440, 6, false, "five leave four gaps; six fit at 200px and leave one"], + [10, 1080, 5, false, "four leave two gaps; five fit and leave none"], + [10, 880, 2, false, "three and four both leave two gaps; two leave none"], + [9, 1080, 5, false, "four leave three gaps; five leave one"], + [8, 1080, 4, false, "two full rows"], + [7, 880, 4, false, "three leave two gaps; four leave one"], + [7, 720, 2, true, "at two across an empty corner is a lone card, so the last row is centered"], + [6, 1440, 6, false, "five leave four gaps; six fill one row"], + [5, 880, 3, false, "3 + 2"], + [13, 1080, 5, true, "every count leaves two gaps or more: one more column, and the last row centered"], + [2, 1440, 5, false, "a single short row stays as it is, never centered"], + [2, 880, 3, false, "the Set up pair keeps today's width"], + [5, 358, 1, false, "a phone stacks the cards"], + [1, 880, 3, false, "one card stays one card wide"], +]; + +for (const [count, width, cols, center, why] of CASES) { + test(`${count} cards at ${width}px: ${cols} across${center ? ", last row centered" : ""} (${why})`, () => { + assert.deepEqual(steadyColumns(count, width), { cols, center }); + }); +} + +test("never fewer than two columns from a narrowing, and never wider than the cards allow", () => { + // Three fit at 880; two is allowed (it fills), one never is. + for (let count = 1; count <= 16; count++) { + for (const width of [480, 720, 880, 1080, 1440]) { + const { cols } = steadyColumns(count, width); + const fit = Math.max(1, Math.floor((width + 12) / 252)); + assert.ok(cols >= Math.min(fit, 2), `${count} at ${width}: ${cols} is too few`); + assert.ok((width + 12) / cols - 12 >= 200 || cols === 1, `${count} at ${width}: ${cols} makes cards under 200px`); + } + } +}); + +test("no layout leaves a lone card on a row unless the cards are stacked or centered", () => { + for (let count = 2; count <= 16; count++) { + for (const width of [720, 880, 1080, 1440]) { + const { cols, center } = steadyColumns(count, width); + if (count <= cols || cols === 1 || center) continue; + assert.notEqual(count % cols, 1, `${count} at ${width}: ${cols} across leaves one card alone`); + } + } +}); + +test("a zero or missing width still answers one column", () => { + assert.deepEqual(steadyColumns(4, 0), { cols: 1, center: false }); + assert.deepEqual(steadyColumns(0, 880), { cols: 3, center: false }); +}); diff --git a/scripts/test-web-console-page-dashboard.mjs b/scripts/test-web-console-page-dashboard.mjs index 241938e..844ce38 100644 --- a/scripts/test-web-console-page-dashboard.mjs +++ b/scripts/test-web-console-page-dashboard.mjs @@ -658,6 +658,8 @@ test("the Notebook switch shows on Start fresh for Pathfinder, Plan and Quick Ta assert.equal(await offersNote(main, "Start from scratch", "/plan2code-xray"), false, "a utility never"); assert.equal(await offersNote(main, "Start from scratch", "/plan2code-diagnose"), true, "Diagnose on Start fresh"); assert.equal(await offersNote(main, "ready", "/plan2code-diagnose"), true, "Diagnose on a picked spec"); + assert.equal(await offersNote(main, "Start from scratch", "/plan2code-ui-prototype"), true, "UI Prototype on Start fresh"); + assert.equal(await offersNote(main, "ready", "/plan2code-ui-prototype"), false, "UI Prototype on a picked spec"); }); test("the switch lists the Notebook's tabs beside a preview: an empty tab grayed, five ticks at most, a Long tab note, and + note: on the command", async (t) => { @@ -754,3 +756,40 @@ test("the switch reads the Notebook again when it closes, and starts off again a assert.equal(await main.locator(".confirm-cmd-note").isHidden(), true); assert.equal(await tabs.count(), 0); }); + +// The cards of a group as rows: each card's left edge and width, grouped by +// the top edge it sits at. +async function cardRows(grid) { + const rows = new Map(); + for (const card of await grid.locator(":scope > .dash-card").all()) { + const box = await card.boundingBox(); + const top = Math.round(box.y); + if (!rows.has(top)) rows.set(top, []); + rows.get(top).push({ x: Math.round(box.x), w: Math.round(box.width) }); + } + return [...rows.keys()].sort((a, b) => a - b).map((k) => rows.get(k)); +} + +test("every group keeps one card width and leaves no card alone on a row, at each Card width setting", async (t) => { + const s = await openSession(await suite.browser(), { t, workflow: "dashboard", payload: MENU, project: tempProject(DRAFT_PROJECT) }); + await s.page.setViewportSize({ width: 2400, height: 1000 }); + const main = await toTheMenu(s); + await hideUnavailable(main, false); + const utilities = main + .locator("section.dash-group") + .filter({ has: s.page.locator("h3", { hasText: /^Useful any time$/ }) }) + .locator(".dash-grid"); + await utilities.waitFor(); + const count = await utilities.locator(":scope > .dash-card").count(); + assert.ok(count >= 9, `the utilities hold enough cards to wrap: ${count}`); + + for (const width of ["narrow", "comfortable", "wide", "ultrawide"]) { + await s.page.evaluate((w) => (document.documentElement.dataset.width = w), width); + let rows; + const settled = await until(async () => { + rows = await cardRows(utilities); + return rows.length > 1 && rows.every((r) => r.length >= 2) && new Set(rows.flat().map((c) => c.w)).size === 1 && (width !== "ultrawide" || rows[0].length === 6); + }); + assert.ok(settled, `at ${width}, every row holds two cards or more, all one width: ${JSON.stringify(rows)}`); + } +}); diff --git a/src/web-console/public/card-rows.js b/src/web-console/public/card-rows.js new file mode 100644 index 0000000..0844faa --- /dev/null +++ b/src/web-console/public/card-rows.js @@ -0,0 +1,35 @@ +/* card-rows.js: How many cards a dashboard group draws per row, so no card sits + alone on a row. Pure: the dashboard measures, this decides. */ + +// The card sizes the grid used before: as many 240px cards as fit, 12px apart. +// One more column is allowed while the cards stay at least 200px wide. +const CARD = 240; +const TIGHT = 200; +const GAP = 12; + +// The empty spots the last row leaves at `cols` across. +const gapsAt = (count, cols) => (cols - (count % cols)) % cols; + +// How bad a column count is: 0 is fine. One empty corner is fine from three +// across; at two across it is a lone card, so it counts. +function badness(count, cols) { + const gaps = gapsAt(count, cols); + if (gaps === 0 || (gaps === 1 && cols >= 3)) return 0; + return gaps; +} + +// `{ cols, center }` for `count` cards in a grid `width` px wide. Every card +// keeps one width. The count is what fits, one more (while cards stay 200px +// wide) or one fewer (never below two), whichever leaves the fewest gaps; a +// tie keeps what fits, then takes one more. A last row still short is +// centered, but a group that fits in one row is drawn as it is. +export function steadyColumns(count, width) { + const fit = Math.max(1, Math.floor((Number(width) + GAP) / (CARD + GAP)) || 1); + if (count <= fit) return { cols: fit, center: false }; + const candidates = [fit]; + if ((width + GAP) / (fit + 1) - GAP >= TIGHT) candidates.push(fit + 1); + if (fit - 1 >= 2) candidates.push(fit - 1); + let cols = fit; + for (const c of candidates) if (badness(count, c) < badness(count, cols)) cols = c; + return { cols, center: badness(count, cols) > 0 }; +} diff --git a/src/web-console/public/screens/dashboard.js b/src/web-console/public/screens/dashboard.js index 45e5937..409c291 100644 --- a/src/web-console/public/screens/dashboard.js +++ b/src/web-console/public/screens/dashboard.js @@ -16,6 +16,7 @@ import { el, approvalTip, mdInto, releasesLink, copyButton, lightDismiss, SVG_NS import { needsRoleNudge, ROLE_NOT_SET } from "../starters.js"; import { looks, saveLooks } from "../looks.js"; import { RED_BANNER, RED_BANNER_IN_APP } from "../meter.js"; +import { steadyColumns } from "../card-rows.js"; import { dashNoteKind, defaultSpec, @@ -285,10 +286,33 @@ export function renderDashboard(main) { if (note) revealNote(note, page.wake.typed); } main.appendChild(wrap); + fitCardRows(wrap); + watchCardRows(wrap); // Deferred: this runs inside render(), and the dialog is not part of it. queueMicrotask(hooks.maybeWelcome); } +// Each group's cards share one width, in as many columns as leave no card +// alone on a row (card-rows.js). Measured from the grid's own width, so the +// Card width setting and the window both count; only a change is written. +function fitCardRows(root) { + for (const grid of root.querySelectorAll(".dash-grid")) { + const { cols, center } = steadyColumns(grid.children.length, grid.clientWidth); + if (grid.style.getPropertyValue("--dash-cols") !== String(cols)) grid.style.setProperty("--dash-cols", String(cols)); + grid.classList.toggle("is-centered", center); + } +} + +// One watcher, on the menu drawn last: a resize refits its groups. Fitting +// changes only the menu's height, which refits to the same columns, so the +// watcher never feeds itself. +const rowsObserver = typeof ResizeObserver === "function" ? new ResizeObserver((entries) => entries.forEach((e) => fitCardRows(e.target))) : null; +function watchCardRows(wrap) { + if (!rowsObserver) return; + rowsObserver.disconnect(); + rowsObserver.observe(wrap); +} + const WAKE_TYPE_DELAY_MS = 350; const WAKE_TYPE_EVERY_MS = 14; diff --git a/src/web-console/public/styles/dashboard.css b/src/web-console/public/styles/dashboard.css index 8fb2669..20e4295 100644 --- a/src/web-console/public/styles/dashboard.css +++ b/src/web-console/public/styles/dashboard.css @@ -173,7 +173,17 @@ padding-bottom: 8px; } -.dash-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; } +/* Every card in a group has one width, `--dash-cols` to a row: the dashboard + picks the count (card-rows.js) so no card sits alone on a row, and centers a + last row still short. The 3 is only the first paint's guess. */ +.dash-grid { + --dash-cols: 3; + display: flex; + flex-wrap: wrap; + gap: 12px; +} +.dash-grid > .dash-card { flex: 0 0 calc((100% - (var(--dash-cols) - 1) * 12px) / var(--dash-cols)); min-width: 0; } +.dash-grid.is-centered { justify-content: center; } /* A card IS a button, so it carries the reset the page's other big clickable surfaces do; the look is the panel look with a lift on hover, and the diff --git a/src/web-console/public/styles/shell.css b/src/web-console/public/styles/shell.css index 22dd0be..0a9248b 100644 --- a/src/web-console/public/styles/shell.css +++ b/src/web-console/public/styles/shell.css @@ -440,7 +440,9 @@ h1 { .attach-row { display: flex; align-items: center; margin: -4px 0 6px -13px; } .attach-row.is-under { margin: 6px 0 4px -13px; } -.attach-row .suggest-chip { margin: 0 0 0 auto; } +/* .btn on the chip's rule: pieces.css loads later, and .btn.tiny's bottom + margin would otherwise lift the chip off the row's center line. */ +.attach-row .btn.suggest-chip { margin: 0 0 0 auto; } .attach-row .suggest-nudge { margin-left: auto; } .attach-row .suggest-nudge + .suggest-chip { margin-left: 9px; } .msg .suggest-tag { diff --git a/src/web-console/static.mjs b/src/web-console/static.mjs index 28bd26a..a0a7135 100644 --- a/src/web-console/static.mjs +++ b/src/web-console/static.mjs @@ -25,6 +25,7 @@ export const SERVABLE = new Set([ "skills.js", "hops.js", "spec-states.js", + "card-rows.js", "state.js", "doc-files.js", "send-state.js",