From 8dd664bba064f18c729a239eee11c695a4a3e09e Mon Sep 17 00:00:00 2001 From: Sam Julien Date: Tue, 1 Dec 2026 16:27:25 -0800 Subject: [PATCH 1/2] Artifacts: wider gallery, full-page viewer - PageShell gets a `wide` width (max-w-4xl) for a grid of cards. The Artifacts gallery uses it: 3 cards a row on a desktop window, 2 when the column is narrower, 1 on a phone. The columns follow the column's width (container query), not the window's. - An artifact opened from the gallery shows full page in the main pane, over the list, not in a 560px panel or a sheet. The sidebar stays. The list stays drawn under it, so Back finds it at the same scroll, with focus on the tile that opened it. `?artifact=` and `/artifacts/` both still open it. - Full page, the viewer's controls are one header row: Back, the title, the tabs, then the version, Share, Download and More. The version's author line moves into the version list. The panel beside a conversation keeps its layout. --- .claude/skills/openbot-screen-layout/SKILL.md | 11 +- .../artifacts/artifact-full-page.tsx | 95 ++++ .../components/artifacts/artifacts-page.tsx | 44 +- .../artifacts/viewer/artifact-viewer.tsx | 502 ++++++++++-------- .../artifacts/viewer/version-bar.tsx | 8 +- app/src/components/layout/page-parts.tsx | 12 +- app/src/components/layout/page-shell.tsx | 2 +- app/src/routes/_authed/_app/artifacts.tsx | 135 +++-- .../_authed/_app/artifacts_.$artifactId.tsx | 62 +-- app/tests/artifacts-screens.test.tsx | 180 ++++++- 10 files changed, 707 insertions(+), 344 deletions(-) create mode 100644 app/src/components/artifacts/artifact-full-page.tsx diff --git a/.claude/skills/openbot-screen-layout/SKILL.md b/.claude/skills/openbot-screen-layout/SKILL.md index 2ca169bed6..c05acad653 100644 --- a/.claude/skills/openbot-screen-layout/SKILL.md +++ b/.claude/skills/openbot-screen-layout/SKILL.md @@ -54,8 +54,10 @@ PageShell the page: header (title, description, action, backButton) then `PageShell` takes a `width`: `prose` (`max-w-3xl`, 768px) is the default, and every configuration screen uses it so no screen is wider than another. Sentences inside it are held to `max-w-prose`, so the column has room for a label beside its control without stretching the text. -`wide` (`max-w-5xl`) exists for one screen — `admin/audit.tsx`, because an audit log is a table to be -scanned and prose width would wrap every row. It is not a licence for anything else to be wide. +`wide` (`max-w-4xl`, 896px) is for a grid of cards picked out by how they look: the Artifacts +gallery, three cards a row on a desktop window. `full` (no column) exists for one screen, the audit +log (`manage/audit-page.tsx`), because it is a table to be scanned and prose width would wrap every +row. Neither is a licence for rows or forms to be wide. ## The Rhythm @@ -227,7 +229,8 @@ is actually on screen. The root was once 15px, and every constant taken from the - A width, ratio or scale needs a number in pixels → the Units section. Measure, do not assume. - Choosing a margin or gap between blocks → the Rhythm table. If the frame already gives it, set none. - The screen genuinely does not fit this shape → say so in the response and comment the reason in the - code. There are two accepted precedents: a table (`admin/audit.tsx`, `width="wide"`), and the + code. There are three accepted precedents: a table (the audit log, `width="full"`), the + Artifacts gallery (`width="wide"`, a grid of cards), and the Connections tiles (`connections.index.tsx`), a grid of separate `variant="outline"` cards, 56px tall and 12px apart, because apps are picked out by their mark rather than read down as a list. - The question is which states the screen renders while loading or failing → not this skill; @@ -239,7 +242,7 @@ is actually on screen. The root was once 15px, and every constant taken from the |--------|---------------|------------| | A hand-written `rounded-lg border border-border bg-card` div wrapping rows | `PageRows` re-implemented, and it will drift from the other seven screens | Use `PageRows` | | Rows separated by `gap-*` instead of `` | A stack of cards rather than one card of rows | `` between rows, none after the last | -| `width="wide"` on anything that is not a table | Prose width is the default for a reason; wide was for the audit log | Leave `width` alone | +| `width="wide"` or `"full"` on rows or a form | Prose width is the default for a reason; the others are for a grid of cards and a table | Leave `width` alone | | A `max-w-*`, `p-*` or text size invented for one screen | A fifth container width, which is what this layout exists to stop | Reach for the existing component | | Children on an element passed to `Item`'s `render` | They replace the row's own children; the row draws empty | Pass a childless element | | `bg-card` on a row inside a dialog | `--card` equals `--popover`; the row is invisible | `variant="muted"` | diff --git a/app/src/components/artifacts/artifact-full-page.tsx b/app/src/components/artifacts/artifact-full-page.tsx new file mode 100644 index 0000000000..551d3dd1b6 --- /dev/null +++ b/app/src/components/artifacts/artifact-full-page.tsx @@ -0,0 +1,95 @@ +import { Link } from "@tanstack/react-router"; +import { type Ref, useEffect, useRef } from "react"; +import { IconChevronLeft } from "@/components/icons"; +import { SidebarToggle } from "@/components/layout/sidebar-toggle"; +import { Button } from "@/components/ui/button"; +import { + Tooltip, + TooltipContent, + TooltipTrigger, +} from "@/components/ui/tooltip"; +import { + ArtifactViewer, + type ArtifactViewerProps, +} from "./viewer/artifact-viewer"; + +const BACK_LABEL = "Back to Artifacts"; + +/** + * An artifact, opened full page in the app's main pane, edge to edge: the viewer with one header + * row, which starts with the sidebar's toggle (when the sidebar is hidden) and the way back to the + * Artifacts page. The sidebar stays where it is, so the person can go anywhere else from here too. + * + * Drawn over the Artifacts page when a tile opens it (`?artifact=`), and on its own address + * (`/artifacts/`). + * + * `onBack` is for the Artifacts page, which goes back in the history so the list comes back as it + * was left. Without it, Back is a link to the Artifacts page. + */ +export function ArtifactFullPage({ + onBack, + focusBack = false, + ...viewer +}: Omit & { + onBack?: () => void; + /** Move focus to Back once drawn: the tile that opened it is behind the viewer now. */ + focusBack?: boolean; +}) { + const back = useRef(null); + // The viewer draws its header once the artifact is read, so Back may come a moment later. + useEffect(() => { + if (!focusBack) return; + let frame = 0; + let tries = 0; + const focus = () => { + if (back.current) back.current.focus(); + else if (tries++ < 120) frame = requestAnimationFrame(focus); + }; + focus(); + return () => cancelAnimationFrame(frame); + }, [focusBack]); + + const backButton = ( + + } + size="icon" + variant="ghost" + /> + ) : ( + - ) : null} - - - - } + // Full page, everything sits in one header row; in the panel, whose own header holds the title, + // the version and the actions take a row and the tabs another. + const wide = place === "page"; + + const versionControl = outside ? ( +

+ {wide ? null : `${kindName(artifact.kind)} · `} + Version {shown} +

+ ) : ( + + ); + + const actions = ( + <> + {together ? ( + + ) : null} + {artifact.canShare && !outside ? ( + + ) : null} + + + + } + > + + + + {fullScreen && inApp ? ( + + } + > + + Open full screen + + ) : null} + void doCopy()} > - -
- - {fullScreen && inApp ? ( + + {sourceTabName(artifact.kind) === "Code" + ? "Copy code" + : "Copy contents"} + + {outside ? null : ( + <> + {inApp ? ( + + + Duplicate + + ) : null} + onClick={() => + pin.mutate({ + artifactId: artifact.id, + pinned: !artifact.pinned, + }) } > - - Open full screen + {artifact.pinned ? : } + {artifact.pinned ? "Unpin" : "Pin"} - ) : null} - void doCopy()} - > - - {sourceTabName(artifact.kind) === "Code" - ? "Copy code" - : "Copy contents"} - - {outside ? null : ( - <> - {inApp ? ( + {artifact.kind === "page" ? ( + setPermissionsOpen(true)}> + + Page permissions + + ) : null} + {artifact.source && inApp ? ( + <> + + } > - - Duplicate + + Go to conversation - ) : null} - - pin.mutate({ - artifactId: artifact.id, - pinned: !artifact.pinned, - }) - } - > - {artifact.pinned ? : } - {artifact.pinned ? "Unpin" : "Pin"} - - {artifact.kind === "page" ? ( - setPermissionsOpen(true)}> - - Page permissions + + ) : null} + {canDelete ? ( + <> + + setDeleting(true)} + variant="destructive" + > + + Delete - ) : null} - {artifact.source && inApp ? ( - <> - - - } - > - - Go to conversation - - - ) : null} - {canDelete ? ( - <> - - setDeleting(true)} - variant="destructive" - > - - Delete - - - ) : null} - - )} - -
- - + + ) : null} + + )} + + + ); const preview = content.data ? ( @@ -457,7 +463,6 @@ function Opened({ ); // Full screen has room for the comments beside the artifact; the panel keeps them in a tab. - const wide = place === "page"; const comments = together ? ( ) : null; + // Wide, Comments sits beside the artifact, so its tab is for a window too narrow for that. + const tabsList = ( + + Preview + {sourceTabName(artifact.kind)} + Changes + + Comments + + + ); + const commentOnThis = + selection && tab !== "comments" ? ( + + ) : null; + const older = + shown < latest && !outside ? ( + onVersionChange(undefined)} + onRestore={doRestore} + restoring={restore.isPending} + shown={shown} + /> + ) : null; + + const header = wide ? ( +
+ {/* One row: the title on the left, the tabs, then the version and what can be done with it. + A narrow window wraps it, the tabs first. */} +
+ {leading ? ( +
{leading}
+ ) : null} + + {outside ? null : ( +
+ {tabsList} + {commentOnThis} +
+ )} +
+ {versionControl} + {actions} +
+
+ {older ?
{older}
: null} +
+ ) : ( +
+
+ {versionControl} +
{actions}
+
+ {older} +
+ ); + return (
{said}

-
- {place === "page" ? ( - - ) : null} - {toolbar} - {shown < latest && !outside ? ( - onVersionChange(undefined)} - onRestore={doRestore} - restoring={restore.isPending} - shown={shown} - /> - ) : null} -
{outside ? ( - -
{preview}
-
+ <> + {header} + +
{preview}
+
+ ) : ( -
setTab(value as Tab)} + value={tab} > - setTab(value as Tab)} - value={tab} + {header} +
-
- - Preview - - {sourceTabName(artifact.kind)} - - Changes - + {wide ? null : ( +
+ {tabsList} + {commentOnThis} +
+ )} + + + {/* Where words picked in a document, deck or dashboard become a comment's quote. */} +
+ {preview} +
+
+ - Comments -
-
- {selection && tab !== "comments" ? ( - - ) : null} + + +
- - - {/* Where words picked in a document, deck or dashboard become a comment's quote. */} -
- {preview} -
-
- {comments} - - - - - - - -
- - {wide ? ( - // Full screen and wide, the comments sit beside the artifact rather than behind a tab. - - ) : null} -
+ + ) : null} +
+ )} {together && artifact.kind === "page" ? ( @@ -714,7 +765,10 @@ function OlderVersion({ ); } -/** Full screen, the viewer names the artifact itself: its kind, its title, who can open it. */ +/** + * Full screen, the viewer names the artifact itself, at the start of its header row: its kind, its + * title, and then who can open it and whose it is, which give way first when the row is short. + */ function ViewerTitle({ artifact, outside, @@ -723,21 +777,23 @@ function ViewerTitle({ outside: boolean; }) { const owner = artifact.owner.name; + const about = [ + kindName(artifact.kind), + outside ? null : visibilityName(artifact.visibility), + outside || !owner ? null : owner, + ] + .filter(Boolean) + .join(" · "); return ( -
- - - -
-

- {artifact.title} -

-

- {kindName(artifact.kind)} - {outside ? null : ` · ${visibilityName(artifact.visibility)}`} - {outside || !owner ? null : ` · ${owner}`} -

-
+
+ +

{artifact.title}

+

+ {about} +

); } diff --git a/app/src/components/artifacts/viewer/version-bar.tsx b/app/src/components/artifacts/viewer/version-bar.tsx index 095180936b..1572e0e1c8 100644 --- a/app/src/components/artifacts/viewer/version-bar.tsx +++ b/app/src/components/artifacts/viewer/version-bar.tsx @@ -21,7 +21,8 @@ import { relativeTime } from "@/lib/relative-time"; /** * Which version is on screen, and the way to every other: back and forward a version at a time, or * straight to any of them from the list, each with who made it, when, and what changed. Under it, - * who made the one on screen and their note. + * who made the one on screen and their note, except `compact`, in a header row with no room for a + * second line: there the list says it. */ export function VersionBar({ shown, @@ -29,6 +30,7 @@ export function VersionBar({ versions, me, onShow, + compact = false, }: { shown: number; latest: number; @@ -37,6 +39,8 @@ export function VersionBar({ me: string | undefined; /** Show a version; undefined follows the newest. */ onShow: (version: number | undefined) => void; + /** One line, no "who made it" under the stepper. */ + compact?: boolean; }) { const current = versions?.find((one) => one.number === shown); const go = (version: number) => @@ -117,7 +121,7 @@ export function VersionBar({
- {current ? ( + {current && !compact ? (

{authorName(current.author, me)} diff --git a/app/src/components/layout/page-parts.tsx b/app/src/components/layout/page-parts.tsx index 1e7969c99b..c4adddeebc 100644 --- a/app/src/components/layout/page-parts.tsx +++ b/app/src/components/layout/page-parts.tsx @@ -20,8 +20,13 @@ import { * at the pane's left edge, lined up with the table's first column rather than centred above a table * that is not, and the children fill what is left, so the table can be the one thing that scrolls. * It is not a licence for anything else to be wide. It is no column, so `PageShell` draws it itself. + * + * `wide` is `max-w-4xl`, 896px, for a gallery of cards that a person picks out by how they look + * (Artifacts). In the prose column such a gallery holds two cards a row with empty space beside + * them; this column holds three on a desktop window. It is for a grid of cards, not for rows or + * forms, which keep `prose`. */ -export type ShellWidth = "prose" | "full"; +export type ShellWidth = "prose" | "wide" | "full"; /** * The scroller and the centred `prose` column every configuration screen sits in, without the bar. The @@ -32,10 +37,13 @@ export function PageColumn({ bar, children, className, + width = "prose", }: { bar: boolean; children: React.ReactNode; className?: string; + /** The column's measure. `full` is no column: `PageShell` draws it without this. */ + width?: Exclude; }) { return ( <> @@ -67,7 +75,7 @@ export function PageColumn({ "[&>header+*]:mt-8 [&>header+nav]:mt-6 [&>header+nav+*]:mt-8", // Without a bar above it the heading keeps the full original space. bar ? "pt-8" : "pt-12", - "max-w-3xl", + width === "wide" ? "max-w-4xl" : "max-w-3xl", className, )} > diff --git a/app/src/components/layout/page-shell.tsx b/app/src/components/layout/page-shell.tsx index e51a0be7a0..e2964e5967 100644 --- a/app/src/components/layout/page-shell.tsx +++ b/app/src/components/layout/page-shell.tsx @@ -108,7 +108,7 @@ export function PageShell({ return ( <> {barRow} - + {header} {children} diff --git a/app/src/routes/_authed/_app/artifacts.tsx b/app/src/routes/_authed/_app/artifacts.tsx index 1908ad725d..2eadfd67f3 100644 --- a/app/src/routes/_authed/_app/artifacts.tsx +++ b/app/src/routes/_authed/_app/artifacts.tsx @@ -1,26 +1,22 @@ -import { createFileRoute } from "@tanstack/react-router"; -import { useCallback } from "react"; +import { createFileRoute, useRouter } from "@tanstack/react-router"; +import { useCallback, useEffect, useRef } from "react"; import { z } from "zod"; -import { - ARTIFACT_PANEL_WIDTH, - ArtifactPanelViewer, - artifactPanelSearch, -} from "@/components/artifacts/artifact-panel"; +import { ArtifactFullPage } from "@/components/artifacts/artifact-full-page"; +import { artifactPanelSearch } from "@/components/artifacts/artifact-panel"; import { type ArtifactsFilter, ArtifactsPage, } from "@/components/artifacts/artifacts-page"; -import { ArtifactPanelTitle } from "@/components/artifacts/viewer/artifact-viewer"; -import { DetailPanel } from "@/components/layout/detail-panel"; import type { ArtifactKind } from "@/lib/artifacts/queries"; import { KINDS } from "@/lib/artifacts/words"; import { searchText } from "@/lib/search-text"; +import { cn } from "@/lib/utils"; /** * The Artifacts page, under Conversations: everything Bots made that the person can open. Which list * (`show`), the kind, the search (`q`) and grid or list (`layout`) are in the address, so the page - * comes back as it was left; an artifact opened from it shows in the panel beside the list - * (`?artifact=`). + * comes back as it was left. An artifact opened from it (`?artifact=`) shows full page, over the + * list. The list stays drawn under it, hidden, so Back finds it scrolled where it was. */ const artifactsSearchSchema = z.object({ show: z.enum(["all", "mine", "shared", "pinned"]).optional().catch(undefined), @@ -65,7 +61,12 @@ function ArtifactsRoute() { }), [navigate], ); - const open = (artifactId: string | undefined) => + const router = useRouter(); + // Opened from a tile here, the list is the entry before this one: Back goes back to it. Opened from + // a link or a reload, there is no such entry, and Back goes to the list in its place. + const openedHere = useRef(false); + const open = (artifactId: string) => { + openedHere.current = true; void navigate({ search: (previous) => ({ ...previous, @@ -73,13 +74,90 @@ function ArtifactsRoute() { artifactVersion: undefined, }), }); + }; + const back = () => { + if (openedHere.current) { + openedHere.current = false; + router.history.back(); + return; + } + void navigate({ + replace: true, + search: (previous) => ({ + ...previous, + artifact: undefined, + artifactVersion: undefined, + }), + }); + }; + + // Closed, focus goes back to the tile or row that opened it, under the viewer until now. + const opened = search.artifact; + const last = useRef(undefined); + useEffect(() => { + if (opened) { + last.current = opened; + return; + } + openedHere.current = false; + const id = last.current; + last.current = undefined; + if (!id) return; + const target = document.querySelector( + `[data-artifact-id="${CSS.escape(id)}"]`, + ); + const control = target?.matches("button") + ? target + : target?.querySelector("button"); + (control as HTMLElement | null | undefined)?.focus({ preventScroll: true }); + }, [opened]); return ( - + {/* Hidden, not taken away, while an artifact is open over it: it keeps its scroll. */} +

+ +
+ {opened ? ( +
+ + navigate({ + replace: true, + search: (previous) => ({ + ...previous, + artifact: undefined, + artifactVersion: undefined, + }), + }) + } + // A duplicate takes the original's place, so Back still leads to the list. + onOpenArtifact={(copy) => + void navigate({ + replace: true, + search: (previous) => ({ + ...previous, + artifact: copy, + artifactVersion: undefined, + }), + }) + } onVersionChange={(version) => void navigate({ replace: true, @@ -91,25 +169,8 @@ function ArtifactsRoute() { } version={search.artifactVersion} /> - ) : null - } - detailWidth={ARTIFACT_PANEL_WIDTH} - onClose={() => open(undefined)} - open={search.artifact !== undefined} - title={ - search.artifact ? ( - - ) : undefined - } - > -
- -
- +
+ ) : null} +
); } diff --git a/app/src/routes/_authed/_app/artifacts_.$artifactId.tsx b/app/src/routes/_authed/_app/artifacts_.$artifactId.tsx index a1155e5cee..59c963ce6a 100644 --- a/app/src/routes/_authed/_app/artifacts_.$artifactId.tsx +++ b/app/src/routes/_authed/_app/artifacts_.$artifactId.tsx @@ -1,14 +1,12 @@ -import { IconChevronLeft } from "@/components/icons"; -import { createFileRoute, Link } from "@tanstack/react-router"; +import { createFileRoute } from "@tanstack/react-router"; import { z } from "zod"; +import { ArtifactFullPage } from "@/components/artifacts/artifact-full-page"; import { versionSearch } from "@/components/artifacts/artifact-panel"; -import { ArtifactViewer } from "@/components/artifacts/viewer/artifact-viewer"; -import { SidebarToggle } from "@/components/layout/sidebar-toggle"; -import { Button } from "@/components/ui/button"; /** - * One artifact, full screen in the app: the same viewer as the panel, with the room to read a deck - * or a dashboard. `?version=` opens an older version, as a chat card's Open does. + * One artifact, on its own address: the same full page the Artifacts page opens over its list, with + * the room to read a deck or a dashboard. `?version=` opens an older version, as a chat card's + * Open does. Back is a link to the Artifacts page. */ export const Route = createFileRoute("/_authed/_app/artifacts_/$artifactId")({ validateSearch: z.object({ version: versionSearch }), @@ -20,38 +18,22 @@ function FullScreenArtifact() { const { version } = Route.useSearch(); const navigate = Route.useNavigate(); return ( -
-
- - -
-
- - void navigate({ - params: { artifactId: copy }, - search: {}, - to: "/artifacts/$artifactId", - }) - } - // Deleted: back to the Artifacts page, in place of the page that showed it. - onDeleted={() => navigate({ replace: true, to: "/artifacts" })} - onVersionChange={(next) => - void navigate({ replace: true, search: { version: next } }) - } - place="page" - version={version} - /> -
-
+ + void navigate({ + params: { artifactId: copy }, + search: {}, + to: "/artifacts/$artifactId", + }) + } + // Deleted: back to the Artifacts page, in place of the page that showed it. + onDeleted={() => navigate({ replace: true, to: "/artifacts" })} + onVersionChange={(next) => + void navigate({ replace: true, search: { version: next } }) + } + version={version} + /> ); } diff --git a/app/tests/artifacts-screens.test.tsx b/app/tests/artifacts-screens.test.tsx index 5e9ef2dde7..a34eab26f2 100644 --- a/app/tests/artifacts-screens.test.tsx +++ b/app/tests/artifacts-screens.test.tsx @@ -632,7 +632,7 @@ describe.skipIf(!asked)("artifacts in a conversation", () => { }); describe.skipIf(!asked)("the Artifacts page and full screen", () => { - test("lists, narrows, opens into the panel, pins", async () => { + test("lists, narrows, opens full page, pins", async () => { const { page } = await open({ entry: "app", path: "/artifacts", @@ -683,14 +683,21 @@ describe.skipIf(!asked)("the Artifacts page and full screen", () => { await page.getByRole("button", { name: "List" }).click(); await page.getByRole("button", { name: /Pipeline dashboard/ }).click(); await page.getByRole("tab", { name: "Preview" }).waitFor(); + // The viewer's classes came after the page's stylesheet was made: make it again. + await restyle(page); await inViewer(page).getByText("Deals by stage").first().waitFor(); expect(new URL(page.url()).searchParams.get("artifact")).toBe( DASHBOARD_ID, ); - // Pinned from the viewer's menu: it joins the Pinned list. + // Pinned from the viewer's menu: it joins the Pinned list, back on the page. await page.getByRole("button", { name: "More actions" }).click(); await page.getByRole("menuitem", { name: "Pin" }).click(); + await page.keyboard.press("Escape"); + await page.getByRole("button", { name: "Back to Artifacts" }).click(); + await page.waitForFunction( + () => new URL(location.href).searchParams.get("artifact") === null, + ); await page.getByRole("combobox", { name: "Kind" }).click(); await page.getByRole("option", { name: "Every kind" }).click(); await page.getByRole("button", { name: "Pinned", exact: true }).click(); @@ -806,8 +813,9 @@ describe.skipIf(!asked)("the Artifacts page and full screen", () => { }); try { const tiles = page.locator("[data-slot=artifact-tile]"); - // However many the list holds (the fixtures grow), Delete takes exactly one away. - await tiles.first().waitFor(); + // However many the list holds (the fixtures grow), Delete takes exactly one away. The list is + // there under the open artifact, hidden. + await tiles.first().waitFor({ state: "attached" }); const before = await tiles.count(); await page.getByRole("button", { name: "More actions" }).click(); await page.getByRole("menuitem", { name: "Delete" }).click(); @@ -819,7 +827,7 @@ describe.skipIf(!asked)("the Artifacts page and full screen", () => { expect(await measured(page)).toEqual(HOLDS); await shoot(page, "artifact-delete-confirm-light-1440"); await dialog.getByRole("button", { name: "Delete", exact: true }).click(); - // The panel closes, the list stays, without it. + // The artifact closes, and the list shows, without it. await page.waitForFunction( () => new URL(location.href).searchParams.get("artifact") === null, ); @@ -851,27 +859,165 @@ describe.skipIf(!asked)("the Artifacts page and full screen", () => { } }, 60_000); - test("full screen, from the panel's menu", async () => { + /* + * FROM THE SCREEN-BY-SCREEN AUDIT. The gallery held two cards a row in the prose column, with + * empty space on both sides, and an artifact opened in a 560px panel, as a sheet over a dimmed page + * on a narrower window, under three rows of controls. + */ + test("three cards a row; an artifact opens full page under one header row, and Back finds the list as it was", async () => { const { page } = await open({ entry: "app", - path: `/artifacts?artifact=${PLAN_ID}`, + path: "/artifacts", theme: "light", window: WIDE, ready: (one) => - one.getByRole("button", { name: "More actions" }).waitFor(), + one.getByRole("button", { name: "Pricing calculator" }).waitFor(), }); try { - await page.getByRole("button", { name: "More actions" }).click(); - await page.getByRole("menuitem", { name: "Open full screen" }).click(); - // The viewer's own title, above the document's first heading. + const columns = () => + page.evaluate(() => { + const tops = [ + ...document.querySelectorAll("[data-slot=artifact-tile]"), + ].map((tile) => Math.round(tile.getBoundingClientRect().top)); + return tops.filter((top) => top === tops[0]).length; + }); + expect(await columns()).toBe(3); + await page.setViewportSize(NARROW); + await page.waitForFunction( + () => + document + .querySelectorAll("[data-slot=artifact-tile]")[1] + ?.getBoundingClientRect().top === + document + .querySelectorAll("[data-slot=artifact-tile]")[0] + ?.getBoundingClientRect().top, + ); + expect(await columns()).toBe(2); + await page.setViewportSize(PHONE); + await page.waitForFunction( + () => + (document + .querySelectorAll("[data-slot=artifact-tile]")[1] + ?.getBoundingClientRect().top ?? 0) > + (document + .querySelectorAll("[data-slot=artifact-tile]")[0] + ?.getBoundingClientRect().top ?? 0), + ); + expect(await columns()).toBe(1); + // Short enough that the list scrolls. + await page.setViewportSize({ width: WIDE.width, height: 600 }); + + // Scrolled down the list, a tile in the last row opens: one of the person's own, so Share is there. + const last = page + .locator("[data-slot=artifact-tile]") + .filter({ hasText: "Launch countdown" }); + await last.scrollIntoViewIfNeeded(); + const scroller = () => + page.evaluate(() => { + let element = document.querySelector( + "[data-slot=artifact-tile]", + )?.parentElement; + while (element && getComputedStyle(element).overflowY !== "auto") + element = element.parentElement; + return element?.scrollTop ?? -1; + }); + const scrolled = await scroller(); + expect(scrolled).toBeGreaterThan(0); + const title = "Launch countdown"; + await last.getByRole("button").click(); + await page.getByRole("tab", { name: "Preview" }).waitFor(); + await restyle(page); + + // Full page: the main pane, edge to edge, with the sidebar beside it as it was. + const placed = await page.evaluate(() => { + const full = document + .querySelector("[data-slot=artifact-full-page]") + ?.getBoundingClientRect(); + const pane = document + .querySelector("[data-slot=artifact-full-page]") + ?.parentElement?.getBoundingClientRect(); + const header = document + .querySelector("[data-slot=artifact-viewer-header]") + ?.getBoundingClientRect(); + return { + full: full && pane ? full.width === pane.width : false, + header: header?.height ?? 0, + sidebar: [...document.querySelectorAll("[data-sidebar=sidebar]")] + .length, + }; + }); + expect(placed.full).toBe(true); + expect(placed.header).toBeGreaterThan(0); + expect(placed.header).toBeLessThanOrEqual(48); + expect(placed.sidebar).toBeGreaterThan(0); + // One row: the title, the tabs, the version and Share, each named for a screen reader. + const header = page.locator("[data-slot=artifact-viewer-header]"); + await header.getByRole("heading", { name: title, level: 1 }).waitFor(); + await header.getByRole("tablist").waitFor(); + await header.getByRole("button", { name: /Choose a version/ }).waitFor(); + await header.getByRole("button", { name: "Share" }).waitFor(); + await header.getByRole("button", { name: "More actions" }).waitFor(); + // The tabs work from the keyboard. + await header.getByRole("tab", { name: "Preview" }).focus(); + await page.keyboard.press("ArrowRight"); + await page.keyboard.press("Enter"); await page - .getByRole("heading", { name: "Q3 launch plan", level: 1 }) - .first() + .getByRole("tab", { name: /Source|Code/, selected: true }) .waitFor(); - expect(new URL(page.url()).pathname).toBe(`/artifacts/${PLAN_ID}`); + expect(await measured(page)).toEqual(HOLDS); + + // Back: the list, scrolled where it was, with focus on the tile that opened it. + await page.getByRole("button", { name: "Back to Artifacts" }).click(); + await page.waitForFunction( + () => new URL(location.href).searchParams.get("artifact") === null, + ); + expect(await scroller()).toBe(scrolled); + expect( + await page.evaluate( + () => + document.activeElement + ?.closest("[data-slot=artifact-tile]") + ?.textContent?.includes("Launch countdown") ?? false, + ), + ).toBe(true); + expect(await unanswered(page)).toEqual([]); } finally { await page.close(); } + }, 90_000); + + test("a link to an artifact still opens it, full page; Back leads to the list", async () => { + for (const path of [ + `/artifacts?artifact=${PLAN_ID}`, + `/artifacts/${PLAN_ID}`, + ]) { + const { page } = await open({ + entry: "app", + path, + theme: "light", + window: WIDE, + ready: (one) => + one + .getByRole("heading", { name: "Q3 launch plan", level: 1 }) + .first() + .waitFor(), + }); + try { + await page.getByRole("button", { name: "More actions" }).waitFor(); + await page + .getByRole("link", { name: "Back to Artifacts" }) + .or(page.getByRole("button", { name: "Back to Artifacts" })) + .click(); + await page + .getByRole("button", { name: "Pricing calculator" }) + .waitFor(); + const url = new URL(page.url()); + expect(url.pathname).toBe("/artifacts"); + expect(url.searchParams.get("artifact")).toBeNull(); + } finally { + await page.close(); + } + } }, 60_000); }); @@ -1512,7 +1658,7 @@ const SCREENS: Screen[] = [ ready: (page) => page.getByText("No artifacts yet").waitFor(), }, { - name: "artifacts-with-panel", + name: "artifacts-open", entry: "app", path: `/artifacts?artifact=${DASHBOARD_ID}`, ready: (page) => @@ -1533,7 +1679,7 @@ const SCREENS: Screen[] = [ }, // A person's cream theme on the deck and the dashboard: the content takes it, the viewer doesn't. { - name: "panel-themed-slides", + name: "open-themed-slides", entry: "app", path: `/artifacts?themed=1&artifact=Zx3Ty8Wq1Pk6Lm2Nb7Vc4D`, ready: (page) => inViewer(page).getByText("Board update").first().waitFor(), @@ -1545,7 +1691,7 @@ const SCREENS: Screen[] = [ ready: (page) => inViewer(page).getByText("Board update").first().waitFor(), }, { - name: "panel-themed-dashboard", + name: "open-themed-dashboard", entry: "app", path: `/artifacts?themed=1&artifact=${DASHBOARD_ID}`, ready: (page) => From c73eb5194a06674ad09d2e172a0d4cd9612b75b9 Mon Sep 17 00:00:00 2001 From: Sam Julien Date: Tue, 1 Dec 2026 17:19:59 -0800 Subject: [PATCH 2/2] Artifacts viewer: Escape closes it, Back says where it goes - Escape closes the full-page artifact, as the sheet it replaced did on a narrow window. A menu, a select or a dialog over the viewer closes first, and a field keeps its Escape. - Opened with the panel's Open full screen, the artifact's page says "Back" and goes back to the conversation, not "Back to Artifacts". - The `wide` width is set in PageShell over the column's own class, so PageColumn is unchanged. --- .../artifacts/artifact-full-page.tsx | 47 +++++++++++-- .../artifacts/viewer/artifact-viewer.tsx | 2 + app/src/components/layout/page-parts.tsx | 10 +-- app/src/components/layout/page-shell.tsx | 13 +++- .../_authed/_app/artifacts_.$artifactId.tsx | 15 +++- app/tests/artifacts-app.fixture.tsx | 3 + app/tests/artifacts-screens.test.tsx | 69 +++++++++++++++++++ 7 files changed, 144 insertions(+), 15 deletions(-) diff --git a/app/src/components/artifacts/artifact-full-page.tsx b/app/src/components/artifacts/artifact-full-page.tsx index 551d3dd1b6..29b2a0905b 100644 --- a/app/src/components/artifacts/artifact-full-page.tsx +++ b/app/src/components/artifacts/artifact-full-page.tsx @@ -15,6 +15,30 @@ import { const BACK_LABEL = "Back to Artifacts"; +declare module "@tanstack/react-router" { + interface HistoryState { + /** + * Set by the panel's Open full screen: the artifact's own page was opened from the conversation + * beside it, so its Back goes back there. + */ + artifactFromConversation?: boolean; + } +} + +/** Escape closes the artifact, as the sheet it replaces did, unless something else takes it. */ +function escapeIsOurs(event: KeyboardEvent): boolean { + if (event.key !== "Escape" || event.defaultPrevented || event.isComposing) + return false; + const target = event.target instanceof Element ? event.target : null; + // A field keeps Escape: half a comment is not thrown away with the artifact. + if (target?.closest("input, textarea, select, [contenteditable=true]")) + return false; + // A menu, a select or a dialog over the viewer closes first, on its own Escape. + return !document.querySelector( + "[role=dialog], [role=alertdialog], [role=menu], [role=listbox]", + ); +} + /** * An artifact, opened full page in the app's main pane, edge to edge: the viewer with one header * row, which starts with the sidebar's toggle (when the sidebar is hidden) and the way back to the @@ -23,19 +47,32 @@ const BACK_LABEL = "Back to Artifacts"; * Drawn over the Artifacts page when a tile opens it (`?artifact=`), and on its own address * (`/artifacts/`). * - * `onBack` is for the Artifacts page, which goes back in the history so the list comes back as it - * was left. Without it, Back is a link to the Artifacts page. + * `onBack` is for a page that goes back in the history: the Artifacts page, so the list comes back + * as it was left, or the conversation it was opened from. Without it, Back is a link to the + * Artifacts page. Escape is Back too. */ export function ArtifactFullPage({ onBack, + backLabel = BACK_LABEL, focusBack = false, ...viewer }: Omit & { onBack?: () => void; + /** What Back is called, to the eye and to a screen reader: where it goes. */ + backLabel?: string; /** Move focus to Back once drawn: the tile that opened it is behind the viewer now. */ focusBack?: boolean; }) { const back = useRef(null); + useEffect(() => { + const onKey = (event: KeyboardEvent) => { + if (!escapeIsOurs(event)) return; + event.preventDefault(); + back.current?.click(); + }; + document.addEventListener("keydown", onKey); + return () => document.removeEventListener("keydown", onKey); + }, []); // The viewer draws its header once the artifact is read, so Back may come a moment later. useEffect(() => { if (!focusBack) return; @@ -55,7 +92,7 @@ export function ArtifactFullPage({ render={ onBack ? (