/** * HTML shell for the browser plan review (pure string building). * * The page is intentionally inert: it carries no plan text in its markup and * no inline script. Everything the review needs travels in one JSON data * island (`` cannot * close the tag. * * It shares the Bytefly shell, components, and syntax colours with * `file-browse` through `lib/web`; the server sets the CSP header, and the * page loads only same-origin scripts. */ import { appHead, baseAttribute, collapsedShell, docHead, type KeyHint, keysSheet, liveChip, pageFooter, pageSheet, reloadChip, SIDEBAR_COLLAPSE_MAX, tabTitle, } from "../../lib/web/index.ts"; import { keyRows, type KeySurface } from "./web-keys.ts"; import type { ReviewRole } from "./types.ts"; import type { ReviewPageData } from "./web-payload.ts"; // The island's two types live with the code that builds it (`web-payload.ts`); they are // re-exported here because a page's data and the page's markup are read from the same // imports in every caller, and two declarations of one island is how its halves drift. export type { ReviewOutlineItem, ReviewPageData } from "./web-payload.ts"; /** * Viewport width, at and below which the review's outline collapses above the review. * * The review keeps the shell's collapse at its own width: its outline is long and its document * needs the height, so the band arrives earlier than the shell's sidebar does on browse. */ const PLAN_COLLAPSE_MAX = 1180; /** Page styles: the kit's four layers, then the review's own rules. */ export const REVIEW_CSS = pageSheet( `.review-share__list{list-style:none;margin:0 0 var(--space-3);padding:0;display:flex;flex-direction:column;gap:var(--space-2)} .review-share__row{display:flex;align-items:center;gap:var(--space-2);padding:var(--space-2) var(--space-3);border:1px solid var(--border);border-radius:var(--radius-md)} .review-share__url{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font:var(--fs-sm) var(--font-mono);color:var(--text)} .review-share__who{flex:0 0 auto;font:var(--fs-xs) var(--font-ui);color:var(--muted)} .review-share__who--bound{color:var(--accent)} .review-share__actions{display:flex;flex:0 0 auto;gap:4px} .review-share__qr{display:flex;justify-content:center;margin:0 0 var(--space-3)} .review-share__qr svg{width:168px;height:168px;background:#fff;border-radius:var(--radius-md);padding:var(--space-1)} .bf-review{--review-measure:1012px;--review-rail:26px;--review-gutter:34px;flex:1 1 auto;padding:var(--space-5) var(--space-6) 120px} /* The document is the kit's Markdown body: one prose vocabulary for every page that renders a file. Only its box is this page's — the measure comes from the blocks, which keep the comment rail in their gutter, and the scroll box stays the shell's main pane. */ .bf-review.bf-md{max-width:none;overflow-x:hidden;overflow-y:auto} /* Sticky header: the kit's toolbar says who the page is of and how it is doing, and the control row under it holds the page's own actions (the kit's shape; see lib/web/README.md). */ /* The subject is the plan's title, so it is read from its head — the kit cuts a path's head because a path ends in the folder being read, and a title ends in nothing. */ .review-bar .bf-context--subject{direction:ltr;text-align:left} /* The review's state sentence is longer than a stream's, so the pill may shrink inside the toolbar instead of overflowing it. */ .review-bar .bf-live{max-width:100%} /* A status sentence shares the facts zone with the chips: it holds one line, keeps the head, and disappears when there is nothing to say. paintStatus replaces the class, so the page styles it through the toolbar rather than wearing a class of its own. */ .review-bar .bf-status{max-width:42ch;overflow:hidden;text-overflow:ellipsis;white-space:nowrap} .review-bar .bf-status:empty{display:none} /* The page's own actions: the bar is the kit's, and the group sits under the header's chrome. */ .review-actions{display:flex;align-items:center;gap:var(--space-2);flex-wrap:wrap;justify-content:flex-end;min-width:0} /* The finish block: what this page's own decisions do, in the reader's role. One or two button names in the text colour, and the sentence around them quiet. */ .review-finish{margin:0;padding:var(--space-2) var(--space-3);border:1px solid var(--border);border-radius:var(--radius-md);background:var(--surface);color:var(--muted);font-size:var(--fs-xs);line-height:var(--lh-snug)} .review-finish strong{color:var(--text);font-weight:var(--fw-semibold)} /* A reviewer's identity is a fact about them, not one of the page's actions: the name control wears the quiet chrome the toolbar gives a control that is not the page's own. */ .review-identity{display:flex;align-items:center;gap:var(--space-2)} .review-identity .bf-btn--ghost{font-size:var(--fs-xs);color:var(--muted)} .review-identity .bf-btn--ghost:disabled{opacity:1;color:var(--text)} /* Review panel: the reader's finish block, the facts that role is owed, the view switch, the section outline, then the keys. */ .bf-app__body--single{grid-template-columns:minmax(0,1fr)} .review-panel{display:flex;flex-direction:column;gap:var(--space-3);padding:var(--space-4) var(--space-4) var(--space-2)} .review-facts{display:flex;flex-direction:column;gap:var(--space-2);padding-bottom:var(--space-3);border-bottom:1px solid var(--border)} .review-fact{display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:var(--space-3);font-size:var(--fs-sm);color:var(--muted)} /* The label is one word or two, never a column: squeezed by the value beside it, it broke "Plan steps" over two lines. It holds its line, and the value wraps below instead. */ .review-fact>span:first-child{white-space:nowrap} .review-steps{display:inline-flex;align-items:center;gap:var(--space-2);color:var(--text)} .review-steps__track{display:inline-block;width:96px;height:6px;border-radius:var(--radius-badge);background:var(--accent-soft);overflow:hidden} .review-steps__fill{display:block;height:100%;width:0;background:var(--accent);transition:width var(--motion-fast) linear} .review-fact__value{color:var(--text);font-family:var(--font-ui);font-variant-numeric:tabular-nums} .review-view{display:flex} .review-view .bf-tabs__item{flex:1 1 auto;justify-content:center} /* The page's switch fills its segment when pressed. The kit's tabs say it in colour and weight alone, which is the right quiet for three links; this control redraws the whole document, so the segment the reader pressed has to be findable at a glance. */ .review-view .bf-tabs__item[aria-pressed="true"]{background:var(--accent-soft);color:var(--accent)} /* The count of what the view hid, beside the switch that hid it: a filtered plan that reads as a short one is the defect, and this is the fact that undoes it. */ .review-note{margin:0;color:var(--muted);font-size:var(--fs-xs);line-height:var(--lh-relaxed)} .review-note:empty{display:none} .review-nav{min-width:0} .review-nav__title{margin:0;font:var(--fw-semibold) var(--fs-sm) var(--font-ui);color:var(--muted)} .review-nav ul{list-style:none;margin:0;padding:0} .review-nav a{display:flex;align-items:baseline;gap:var(--space-2);padding:4px 8px;border-radius:var(--radius-sm);color:var(--muted);font-size:var(--fs-sm);line-height:var(--lh-snug)} .review-nav a:hover{background:var(--accent-soft);color:var(--accent);text-decoration:none} .review-nav a[aria-current="true"]{background:var(--accent-soft);color:var(--text);font-weight:var(--fw-semibold)} .review-nav__link{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap} .review-nav__count{flex:0 0 auto;min-width:18px;padding:0 5px;border-radius:var(--radius-badge);background:var(--accent-soft);color:var(--accent);font:var(--fs-xs)/18px var(--font-ui);text-align:center} /* A section that shrank since the last review: how many blocks it no longer holds. Same badge as the comment count, quieter, because it is a fact about the document rather than something to read. */ .review-nav__removed{flex:0 0 auto;min-width:18px;padding:0 5px;border-radius:var(--radius-badge);background:var(--accent-soft);color:var(--muted);font:var(--fs-xs)/18px var(--font-ui);text-align:center} .review-changed{flex:0 0 auto;width:6px;height:6px;border-radius:50%;background:var(--accent)} .review-nav .lvl-2 a{padding-left:18px} .review-nav .lvl-3 a{padding-left:30px} .review-nav .lvl-4 a,.review-nav .lvl-5 a,.review-nav .lvl-6 a{padding-left:42px} .review-hints{margin:auto 0 0;padding-top:var(--space-3);color:var(--muted);font-size:var(--fs-xs);line-height:var(--lh-relaxed)} .review-hints .bf-kbd{margin:0 1px} /* The document: one measure, centred, with a comment rail in its left margin. */ .bf-review>.bf-block{position:relative;width:100%;max-width:var(--review-measure);margin:0 auto;padding:3px 8px 3px var(--review-gutter);border-radius:var(--radius-md);overflow-wrap:break-word} /* The kit gaps one list from the next, which would put a blank line between every two steps: a run is drawn item by block, so its items sit flush and the gap belongs to the item that ends the run. */ .bf-review>.bf-block[data-kind="list"]>ul,.bf-review>.bf-block[data-kind="list"]>ol{margin:0} .bf-review>.bf-block[data-run-end]>ul,.bf-review>.bf-block[data-run-end]>ol{margin:0 0 1em} .bf-block[id]{scroll-margin-top:88px} .bf-block__rail{position:absolute;left:0;top:6px;display:flex;flex-direction:column;align-items:center;gap:6px;width:var(--review-rail)} .bf-block__add{appearance:none;width:22px;height:22px;min-width:22px;padding:0;border:1px solid var(--border);border-radius:var(--radius-badge);background:var(--surface);color:var(--muted);font:var(--fs-md)/1 var(--font-ui);cursor:pointer;opacity:0;transition:opacity var(--motion-fast) var(--motion-ease)} .bf-block__add:hover{border-color:var(--accent);color:var(--accent)} .bf-block:hover .bf-block__add,.bf-block:focus-within .bf-block__add,.bf-block--active .bf-block__add,.bf-block--commented .bf-block__add{opacity:1} .bf-block__count{display:inline-flex;align-items:center;justify-content:center;min-width:20px;height:20px;padding:0 5px;border-radius:var(--radius-badge);background:var(--accent-soft);color:var(--accent);font:var(--fw-semibold) var(--fs-xs)/1 var(--font-ui)} /* A block the last review did not hold: the one mark that says "read this line again". The rule sits at the text edge, inside the gutter the rail already reserves, so it cannot reflow the measure or collide with a comment badge. */ .bf-block[data-changed]{box-shadow:inset 2px 0 0 var(--accent)} .bf-block:hover,.bf-block--active{background:var(--surface)} .bf-block--active{box-shadow:inset 0 0 0 1px var(--border)} /* Comment threads sit in the document flow, aligned with the block's text. */ .bf-comments{display:flex;flex-direction:column;gap:8px;width:100%;max-width:var(--review-measure);margin:0 auto 14px;padding-left:var(--review-gutter)} .bf-comments:empty{display:none} .bf-comments--orphans{margin-top:26px;padding:var(--space-3) 0 0 var(--review-gutter);border-top:1px dashed var(--border)} .bf-comments--orphans>p{margin:0 0 8px;color:var(--muted);font-size:var(--fs-sm)} /* The comment is the kit's record: its body, rail, label and quote are the kit's, and this page adds only what its own card carries — the head row its controls sit in, the badge a moved note wears, and the quiet plane a settled one takes. */ .bf-comment__head{display:flex;align-items:center;gap:var(--space-2);margin-bottom:6px} /* A reviewer's name is a name, not a label: keep its own capitalisation. */ /* A note a refinement carried off its own block: muted, because the complaint is the guess, not the text. */ .bf-comment__moved{font:var(--fw-medium) var(--fs-xs) var(--font-ui);color:var(--muted);border:1px solid var(--border);border-radius:var(--radius-sm);padding:0 6px} .bf-comment__spacer{flex:1 1 auto} /* A settled note keeps its quote and loses its body: the record stays, the eye moves on. */ .bf-comment--resolved{opacity:.72} .bf-comment__resolved{font:var(--fw-medium) var(--fs-xs) var(--font-ui);color:var(--success)} .bf-comment__actions{display:flex;gap:4px} /* A quote is read at the record's own line height, not the document's: it is one line of context. */ .bf-comment__body{line-height:var(--lh-snug)} .bf-composer{margin:0} .bf-block--composing .bf-block__add{opacity:0} ${collapsedShell( PLAN_COLLAPSE_MAX, `.review-panel{padding:var(--space-2) var(--space-4) var(--space-3)} .review-facts{flex-direction:row;flex-wrap:wrap;gap:var(--space-3) var(--space-5);border-bottom:0;padding-bottom:0} /* The disclosure names the outline now, so the panel's own title would be the same word twice. */ .review-nav__title{display:none} .review-nav ul{display:flex;flex-wrap:wrap;gap:2px} .review-nav .lvl-2 a,.review-nav .lvl-3 a,.review-nav .lvl-4 a,.review-nav .lvl-5 a,.review-nav .lvl-6 a{padding-left:8px} .review-hints{display:none}`, )} @media (max-width:${SIDEBAR_COLLAPSE_MAX}px){ .bf-review{padding:var(--space-4) 18px 80px} } /* The toolbar keeps the kit's row at every width: the subject takes a row of its own when the line cannot hold it, and the page's actions stay in their own bar. */ @media (prefers-reduced-motion:no-preference){.bf-block{transition:background var(--motion-fast) var(--motion-ease)}} @media (hover:none){.bf-block__add{opacity:1}} /* On paper the document is the whole page: no comment rail to hover, no composer, no reading progress, and the comments stay with the blocks they belong to. */ @media print{ .bf-review{padding:0} .bf-review>.bf-block{max-width:none;padding:0 0 6px} .bf-block__rail,.bf-composer,.bf-block__add,.review-view,.review-note{display:none} /* A printed review is the whole plan, never the view the reader had on screen: the base layer's hidden rule is !important, so the un-hide has to be too, and a thread the filter hid on screen goes back under its block. */ .bf-block[hidden]{display:block!important} .bf-comments[hidden]{display:flex!important} .bf-block:hover,.bf-block--active{background:none;box-shadow:none} .bf-comments{padding-left:0} .bf-comment{break-inside:avoid} }`.trim(), ); /** * The sidebar's one-line keyboard reminder. It names the keys a reviewer reaches * for first and defers to the shortcut sheet (`?`) for the rest, so the line does * not have to grow every time a binding is added. */ function reviewHints(role: ReviewRole, canApprove: boolean): string { const surface: KeySurface = { role, canApprove, hasCommentWalk: true, hasViewCycle: true }; const parts = keyRows(surface) .filter((row) => row.hint !== undefined) .map( (row) => `${row.keys.map((key) => `${key}`).join("/")} ${row.hint?.(surface) ?? ""}`, ); return `
Press ${parts.join(", ")}.
`; } /** The shortcut sheet's rows: the same table the handler dispatches through. */ function reviewKeys(role: ReviewRole, canApprove: boolean): KeyHint[] { const surface: KeySurface = { role, canApprove, hasCommentWalk: true, hasViewCycle: true }; return keyRows(surface).map((row) => ({ keys: [...row.keys], label: row.label(surface) })); } /** * The approval confirmation. Approving leaves plan mode and runs the plan, which * cannot be undone from the page, so it is one deliberate dialog rather than the * header button's single click. The shared `bf-dialog` styles and the shared * dialog runtime supply the backdrop, the Tab trap, and `Esc`. */ function approveDialog(): string { return `Pi leaves plan mode and starts the work. The comments you added are saved with the plan.
Choose Approve & run to go ahead, or Cancel to keep reviewing.
Your comments are signed with this name, and this link keeps it after your first post.
View only — reading the plan in the browser. Open it again to keep up as the plan changes.
`; if (role === "reviewer") return `Post comments signs them with your name and returns them to the plan.
`; if (canApprove) return `Approve & run runs the plan and returns these comments; Save feedback keeps planning.
`; return `Save feedback returns these comments to the plan and keeps planning.
`; } /** * Render the review page for `data`. The markup is a fixed shell; the client * fills every dynamic field, so this function is the only place that needs the * JSON-island escaping. */ export function renderReviewPage(data: ReviewPageData): string { const island = JSON.stringify(data).replace(/ 0; const bodyClass = hasOutline ? "bf-app__body" : "bf-app__body bf-app__body--single"; // The panel is the reader's own. A reviewer is named there, sees what their comments are // signed with, and the comment count; the plan's step progress is the owner's and a // viewer's, because approval seeds it and a reader is reading the same steps. The switch // and the outline are the plan's, so every role gets them. A reviewer's name is a fact // about them, not one of the page's actions, so it lives here rather than in the control // bar. const identity = data.role === "reviewer" ? ` ` : ""; const outlinePanel = hasOutline ? ` ` : ""; // Approve is the decisive action, so it takes the primary button and the // owner's Save is demoted; a comment-only review has no approve button and // keeps Save primary. A reviewer's one write action is Post, and nothing on // their page closes the review or mints another link. const isOwner = data.role === "owner"; const isViewer = data.role === "viewer"; const approveButton = data.canApprove ? ` ` : ""; // A viewer's page writes nothing, so it gets no save control of either kind — and the bar // itself is left out below when every control in it is absent. const saveControl = isOwner ? `` : isViewer ? "" : ``; const closeControl = isOwner ? `` : ""; // Sharing belongs to the owner; a reviewer's identity is a row in the panel. const shareControl = isOwner ? `` : ""; const controls = `${shareControl}${approveButton}${saveControl}${closeControl}`; // One name for the page, read from the role: a view is not a review, and the tab, the // toolbar lockup, and the section of the docs that explains it must not disagree. const pageName = isViewer ? "plan view" : "plan review"; return ` ${docHead({ title: tabTitle(pageName, data.title), css: REVIEW_CSS, base: data.base })} Skip to the plan ${appHead({ product: pageName, subject: { id: "plan-title", label: data.title, title: data.path }, facts: `${liveChip({ id: "review-state", label: "connecting\u2026" })} ${reloadChip({ title: isViewer ? "Reload to read the plan again" : "Reload to review the plan again" })} `, controls: controls === "" ? undefined : controls, identityClass: "review-bar", controlsClass: "review-actions", })}