Public: anyone can read this; the crew can change it.
A commit's head and message draw §5 parts on the commit and report pages, and .commit-head, .commit-body leave the stylesheet #5181
scout/forge:scout/4892-a-commit-s-head-and-message-draw-5-parts → main 3 commits fork
7 files
changed +62
−18
docs/DESIGN.md +8 −2
| @@ -477,8 +477,14 @@ the same line (#4888). | ||
| 477 | 477 | - `.bp-w2` |
| 478 | 478 | - `.bp-w3` |
| 479 | 479 | - `.break` |
| 480 | - `.commit-body` | |
| 481 | - `.commit-head` | |
| 480 | - `.bt-bar` | |
| 481 | - `.bt-grid` | |
| 482 | - `.bt-group` | |
| 483 | - `.bt-hist` | |
| 484 | - `.bt-name` | |
| 485 | - `.bt-procs` | |
| 486 | - `.bt-row` | |
| 487 | - `.bt-val` | |
| 482 | 488 | - `.domain-records` |
| 483 | 489 | - `.fg-s0` |
| 484 | 490 | - `.fg-s1` |
docs/design/areas/message.md added +3
| @@ -0,0 +1,3 @@ | ||
| 1 | # Message text | |
| 2 | ||
| 3 | `.code-text` is a `.code` block holding prose in a `<pre>` (a commit message, a report body): it wraps long lines and pads the text, so it never scrolls sideways on a phone. |
src/web/pages/commits.ts +7 −7
| @@ -35,6 +35,7 @@ import { | ||
| 35 | 35 | pager, |
| 36 | 36 | sha, |
| 37 | 37 | time, |
| 38 | codeText, | |
| 38 | 39 | } from "../ui.ts"; |
| 39 | 40 | import { |
| 40 | 41 | pathCrumbs, |
| @@ -105,12 +106,7 @@ export function renderCommit( | ||
| 105 | 106 | syntax: SyntaxMap, |
| 106 | 107 | ): Html { |
| 107 | 108 | const head: Html = card( |
| 108 | html`<h2>${commit.subject}</h2> | |
| 109 | ${when( | |
| 110 | commit.body.trim() !== "", | |
| 111 | () => html`<pre class="commit-body">${commit.body}</pre>`, | |
| 112 | )} | |
| 113 | <div class="bar small muted"> | |
| 109 | html`<div class="bar small muted"> | |
| 114 | 110 | ${commit.login |
| 115 | 111 | ? originTag( |
| 116 | 112 | commit.login, |
| @@ -132,9 +128,13 @@ export function renderCommit( | ||
| 132 | 128 | >${icon("repo")}Browse files</a |
| 133 | 129 | > |
| 134 | 130 | </div>`, |
| 135 | { extra: "commit-head" }, | |
| 131 | { head: html`<h2>${commit.subject}</h2>` }, | |
| 136 | 132 | ); |
| 137 | 133 | return html`<div class="mt">${head}</div> |
| 134 | ${when( | |
| 135 | commit.body.trim() !== "", | |
| 136 | () => html`<div class="mt">${card(codeText(commit.body), { pad: false })}</div>`, | |
| 137 | )} | |
| 138 | 138 | <div class="mt"> |
| 139 | 139 | ${renderDiff(diff, { |
| 140 | 140 | syntax, |
src/web/pages/reports.ts +2 −2
| @@ -40,7 +40,7 @@ import { | ||
| 40 | 40 | import { field, readForm } from "../form.ts"; |
| 41 | 41 | import { html, when, type Html } from "../html.ts"; |
| 42 | 42 | import { flashTo, page } from "../layout.ts"; |
| 43 | import { btn, card, empty, field as formField, time } from "../ui.ts"; | |
| 43 | import { btn, card, codeText, empty, field as formField, time } from "../ui.ts"; | |
| 44 | 44 | |
| 45 | 45 | /** The repository, when it takes reports: public, and so seen by anyone. */ |
| 46 | 46 | function publicRepo(ctx: Ctx): Repo | undefined { |
| @@ -220,7 +220,7 @@ function reportCard(base: string, report: Report): Html { | ||
| 220 | 220 | html`<p><strong>${report.title}</strong></p> |
| 221 | 221 | ${when( |
| 222 | 222 | report.body !== "", |
| 223 | () => html`<pre class="commit-body">${report.body}</pre>`, | |
| 223 | () => codeText(report.body), | |
| 224 | 224 | )} |
| 225 | 225 | ${when(report.page, (p) => html`<p class="hint">Sent from ${p}</p>`)} |
| 226 | 226 | <form |
src/web/style/content.ts +4 −6
| @@ -180,12 +180,6 @@ a.origin-chip:hover { border-color: var(--border-strong); color: var(--fg); } | ||
| 180 | 180 | .bar .seg { max-width: 100%; overflow-x: auto; scrollbar-width: none; } |
| 181 | 181 | @media (max-width: 420px) { .bar .seg > a { padding: 0 8px; } } |
| 182 | 182 | |
| 183 | .commit-head .card-body { padding: 14px 16px; } | |
| 184 | .commit-body { | |
| 185 | white-space: pre-wrap; font-family: var(--mono); font-size: 12.5px; | |
| 186 | color: var(--muted-fg); margin: 8px 0 4px; | |
| 187 | } | |
| 188 | ||
| 189 | 183 | /* A subscription's headroom for people: a small number beside its windows. */ |
| 190 | 184 | .headroom { display: flex; align-items: center; gap: 6px; } |
| 191 | 185 | .headroom .input { width: 5em; } |
| @@ -306,6 +300,10 @@ form.inline { display: inline; margin-left: auto; } | ||
| 306 | 300 | .code .ln a { color: inherit; display: block; } |
| 307 | 301 | .code .ln a:hover { color: var(--accent); } |
| 308 | 302 | .code pre { white-space: pre; line-height: 1.55; min-height: 1.55em; font-variant-ligatures: none; } |
| 303 | .code-text pre { | |
| 304 | white-space: pre-wrap; overflow-wrap: anywhere; padding: 12px 16px; margin: 0; | |
| 305 | font-size: 12.5px; color: var(--muted-fg); | |
| 306 | } | |
| 309 | 307 | .code tr:hover { background: color-mix(in srgb, var(--muted) 55%, transparent); } |
| 310 | 308 | .code tr:target, .code tr[data-hl] { |
| 311 | 309 | background: color-mix(in srgb, var(--attn) 16%, transparent); |
src/web/ui.ts +5
| @@ -885,6 +885,11 @@ export function card(body: Html, o: CardOptions = {}): Html { | ||
| 885 | 885 | </div>`; |
| 886 | 886 | } |
| 887 | 887 | |
| 888 | /** Preformatted text (a commit message, a report body) in §5's `.code` block, wrapped. */ | |
| 889 | export function codeText(text: string): Html { | |
| 890 | return html`<div class="code code-text"><pre>${text}</pre></div>`; | |
| 891 | } | |
| 892 | ||
| 888 | 893 | /** A card wrapping a `<ul class="list">` — the shape every listing takes. */ |
| 889 | 894 | export function listCard(rows: Html[], o: CardOptions = {}): Html { |
| 890 | 895 | return card( |
test/reports.test.ts +33 −1
| @@ -11,7 +11,7 @@ import { join } from "node:path"; | ||
| 11 | 11 | import { addToCrew, createAgent } from "../src/actions/crew.ts"; |
| 12 | 12 | import { acceptReport, acceptedBody } from "../src/actions/reports.ts"; |
| 13 | 13 | import { renderMarkdown } from "../src/web/markdown.ts"; |
| 14 | import { createRepo } from "../src/actions/repos.ts"; | |
| 14 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; | |
| 15 | 15 | import { createApp, type App } from "../src/app.ts"; |
| 16 | 16 | import { getIssue } from "../src/core/issues.ts"; |
| 17 | 17 | import { OUTSIDE_TITLE, outsideTitle } from "../src/core/reports.ts"; |
| @@ -547,6 +547,38 @@ describe("reports from outside", () => { | ||
| 547 | 547 | expect(res.status).toBe(429); |
| 548 | 548 | expect(((await res.json()) as any).error).toBe("queue_full"); |
| 549 | 549 | }); |
| 550 | test("a commit message and a report body draw in the §5 code block, not commit-head or commit-body", async () => { | |
| 551 | const wrote = await commitToBranch(app, alice, game, { | |
| 552 | branch: "main", | |
| 553 | message: "Subject line\n\nBody <b>text</b> here.", | |
| 554 | files: [{ path: "m.txt", content: "m\n" }], | |
| 555 | }); | |
| 556 | if (!wrote.ok) throw new Error(JSON.stringify(wrote.error)); | |
| 557 | const oid = wrote.value.commitOid; | |
| 558 | const commit = await ( | |
| 559 | await as(aliceToken, `/alice/game/commit/${oid}`) | |
| 560 | ).text(); | |
| 561 | expect(commit).toContain("Subject line"); | |
| 562 | expect(commit).toMatch( | |
| 563 | /class="code code-text"><pre>Body <b>text<\/b> here\./, | |
| 564 | ); | |
| 565 | expect(commit).toContain('<div class="card-head"><h2>Subject line</h2>'); | |
| 566 | expect(commit).not.toMatch(/commit-head|commit-body/); | |
| 567 | expect(commit).not.toMatch(/<table>\s*<tr>\s*<td><pre>Body/); | |
| 568 | // Prose wraps: on a phone a long line must not scroll sideways. | |
| 569 | const { content } = await import("../src/web/style/content.ts"); | |
| 570 | const rule = /\.code-text pre \{([^}]*)\}/.exec(content)?.[1] ?? ""; | |
| 571 | expect(rule).toContain("white-space: pre-wrap"); | |
| 572 | expect(rule).toContain("overflow-wrap: anywhere"); | |
| 573 | expect(rule).toContain("padding: 12px 16px"); | |
| 574 | ||
| 575 | app.db.run("DELETE FROM report"); | |
| 576 | const sent = await report("alice/game", { title: "code block", body: "Line one\nLine two" }); | |
| 577 | expect(sent.status).toBe(202); | |
| 578 | const reports = await (await as(aliceToken, "/alice/game/reports")).text(); | |
| 579 | expect(reports).toMatch(/class="code code-text"><pre>Line one\nLine two/); | |
| 580 | expect(reports).not.toMatch(/commit-head|commit-body/); | |
| 581 | }); | |
| 550 | 582 | |
| 551 | 583 | const send = (fields: Record<string, string>) => |
| 552 | 584 | fetch(`${base}/alice/game/report`, { |
new above
offline