Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
feat(comments): show every attached image at full size (MUL-7736) (#8870)
Jiayuan Zhang3125bd2ea266
diff --git a/packages/core/attachments/image-sequence.ts b/packages/core/attachments/image-sequence.tsindex 831bc4db59..c6ccf620c7 100644--- a/packages/core/attachments/image-sequence.ts+++ b/packages/core/attachments/image-sequence.ts@@ -152,7 +152,7 @@ export function selectStandaloneAttachments(/*** How a standalone attachment is laid out under its body (MUL-7649): images- * as a row of thumbnails, everything else — HTML included — as file cards.+ * at full size, everything else — HTML included — as file cards.*/export type StandaloneAttachmentGroup = "image" | "file";@@ -164,7 +164,7 @@ export function standaloneAttachmentGroup(/*** The order a surface renders its standalone attachments in (MUL-7649):- * images first (a row of thumbnails), then everything else (a grid of file+ * images first (each at full size), then everything else (a grid of file* cards). Stable within each group. The sequence builder walks standalone* attachments in this same order, so paging through the viewer follows the* screen.diff --git a/packages/views/editor/attachment.tsx b/packages/views/editor/attachment.tsxindex c91fd84256..6c7b321027 100644--- a/packages/views/editor/attachment.tsx+++ b/packages/views/editor/attachment.tsx@@ -101,9 +101,8 @@ export interface AttachmentProps {onDelete?: () => void;/*** "block" (default) renders each kind at full width, as a body renders it.- * "card" is the compact form a list of standalone attachments lays out: an- * image becomes a fixed-height tile, any other file a card. HTML keeps its- * embedded preview in both — the preview is the point of attaching it.+ * "card" is the form a list of standalone attachments lays out: an image+ * keeps its full size up to a height cap, any other file becomes a card.*/layout?: "block" | "card";/** Card layout only — rendered after the file name, e.g. a version badge. */@@ -423,7 +422,7 @@ export function Attachment({onView={openPreview}onDownload={handleDownload}onDelete={onDelete}- className={cn(layout === "card" && "image-tile", className)}+ className={cn(layout === "card" && "image-standalone", className)}/>{preview.modal}</>diff --git a/packages/views/editor/styles/attachment.css b/packages/views/editor/styles/attachment.cssindex 4a2becfee1..6c20bba5b0 100644--- a/packages/views/editor/styles/attachment.css+++ b/packages/views/editor/styles/attachment.css@@ -29,21 +29,18 @@border-radius: var(--radius);}-/* A thumbnail in a row of standalone images (the "card" layout): it fills- the box its row gives it — the row sizes each box from the image's own- aspect ratio — so a set of screenshots reads as one strip instead of a- stack of full-width frames. */-.image-figure.image-tile {- display: block;+/* An image in a list of standalone attachments (the "card" layout): full+ size, so it reads without opening, but capped in height — a phone+ screenshot keeps its shape instead of running the length of the page.+ The list spaces its images itself. */+.image-figure.image-standalone {margin: 0;- width: 100%;- height: 100%;}-.image-figure.image-tile .image-content {- width: 100%;- height: 100%;- object-fit: cover;+.image-figure.image-standalone .image-content {+ width: auto;+ max-width: 100%;+ max-height: 36rem;box-shadow: 0 0 0 1px var(--border);}diff --git a/packages/views/issues/components/comment-card.test.tsx b/packages/views/issues/components/comment-card.test.tsxindex 459a29ae3d..e2f2e1d1a2 100644--- a/packages/views/issues/components/comment-card.test.tsx+++ b/packages/views/issues/components/comment-card.test.tsx@@ -132,21 +132,29 @@ describe("AttachmentList — layout (MUL-7649)", () => {expect(screen.queryByTitle("Preview")).toBeNull();});- it("puts several images in one row of tiles, and keeps a lone image full size", () => {- const { container, unmount } = renderList(+ // MUL-7736: several screenshots used to shrink into one row of thumbnails,+ // so reading any of them took a click. Each keeps its full size instead.+ it("shows every image at full size, one under another", () => {+ const { container } = renderList(<AttachmentList- attachments={[file("a", "a.png", "image/png"), file("b", "b.png", "image/png")]}+ attachments={[+ file("a", "a.png", "image/png"),+ file("b", "b.png", "image/png"),+ file("c", "c.png", "image/png"),+ ]}content=""/>,);- expect(container.querySelectorAll(".image-tile")).toHaveLength(2);- unmount();-- const single = renderList(- <AttachmentList attachments={[file("c", "c.png", "image/png")]} content="" />,- );- expect(single.container.querySelector(".image-figure")).toBeTruthy();- expect(single.container.querySelector(".image-tile")).toBeNull();+ const figures = container.querySelectorAll(".image-figure");+ expect(figures).toHaveLength(3);+ expect([...container.querySelectorAll("img")].map((img) => img.getAttribute("alt"))).toEqual([+ "a.png",+ "b.png",+ "c.png",+ ]);+ // No tile box sized to a shared row height around any of them.+ for (const figure of figures) expect(figure).toHaveClass("image-standalone");+ expect(container.querySelector("[style*='height']")).toBeNull();});it("lays groups out images, then files, whatever the upload order", () => {@@ -160,9 +168,9 @@ describe("AttachmentList — layout (MUL-7649)", () => {content=""/>,);- const tile = container.querySelector(".image-tile")!;+ const image = container.querySelector(".image-figure")!;const card = screen.getByRole("button", { name: "notes.md" });- expect(tile.compareDocumentPosition(card) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();+ expect(image.compareDocumentPosition(card) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();});// Reverses the MUL-2330 pin. An uploaded HTML file is a deliverable, notdiff --git a/packages/views/issues/components/comment-card.tsx b/packages/views/issues/components/comment-card.tsxindex e56695a2d7..969eb7486e 100644--- a/packages/views/issues/components/comment-card.tsx+++ b/packages/views/issues/components/comment-card.tsx@@ -60,7 +60,6 @@ import { descriptionPreview } from "./description-preview";import { useCommentAnnotations } from "./use-comment-annotations";import { useAttachmentVersions } from "./deliverables/attachment-versions";import { VersionBadge } from "./deliverables/version-badge";-import { JustifiedImageRow } from "./justified-image-row";import { useRunCommentMotion } from "./use-run-comment-motion";const commentActionClassName =@@ -232,13 +231,13 @@ export function AttachmentList({const images = standalone.filter((a) => standaloneAttachmentGroup(a) === "image");const files = standalone.filter((a) => standaloneAttachmentGroup(a) === "file");- const render = (a: Attachment, layout: "block" | "card") => {+ const render = (a: Attachment) => {const version = versions?.get(a.id);return (<AttachmentRendererkey={a.id}attachment={{ kind: "record", attachment: a }}- layout={layout}+ layout="card"badge={version ? <VersionBadge version={version} /> : undefined}editable={!!onRemove}onDelete={onRemove ? () => onRemove(a.id) : undefined}@@ -246,20 +245,19 @@ export function AttachmentList({);};- // A lone image keeps its full size; several form justified rows (one- // height per row, edge to edge). Every other file — HTML too: an uploaded- // file is a deliverable to open, not part of the text — is a card in a- // grid, not a full-width row each.+ // Every image shows at its full size, one under another, so it reads+ // without opening (MUL-7736). Every other file — HTML too: an uploaded file+ // is a deliverable to open, not part of the text — is a card in a grid, not+ // a full-width row each.return (<AttachmentDownloadProvider attachments={attachments}><div className={cn("flex flex-col gap-2", className)}>- {images.length === 1 && render(images[0]!, "block")}- {images.length > 1 && (- <JustifiedImageRow items={images} renderTile={(a) => render(a, "card")} />+ {images.length > 0 && (+ <div className="flex flex-col items-start gap-2">{images.map(render)}</div>)}{files.length > 0 && (<div className="grid grid-cols-[repeat(auto-fill,minmax(min(15rem,100%),1fr))] gap-2">- {files.map((a) => render(a, "card"))}+ {files.map(render)}</div>)}</div>diff --git a/packages/views/issues/components/justified-image-row.tsx b/packages/views/issues/components/justified-image-row.tsxdeleted file mode 100644index 29ef654d0d..0000000000--- a/packages/views/issues/components/justified-image-row.tsx+++ /dev/null@@ -1,98 +0,0 @@-"use client";--import { useEffect, useLayoutEffect, useMemo, useRef, useState, type ReactNode } from "react";-import { clampRatio, justifyRows } from "./justified-layout";--const GAP_PX = 8;-const MIN_ROW_HEIGHT = 100;-const MAX_ROW_HEIGHT = 240;-// Until an image has loaded its shape is unknown; most are screenshots.-const DEFAULT_RATIO = 16 / 10;--/**- * Several images under one comment, laid out as justified rows (MUL-7649):- * one shared height per row, each full row edge to edge. Widths come from- * each image's real aspect ratio once it has loaded, so the row settles into- * place instead of cropping.- */-export function JustifiedImageRow<T extends { id: string }>({- items,- renderTile,-}: {- items: ReadonlyArray<T>;- /** Renders one image filling the box it is given. */- renderTile: (item: T) => ReactNode;-}) {- const containerRef = useRef<HTMLDivElement>(null);- const [width, setWidth] = useState(0);- const [ratios, setRatios] = useState<ReadonlyMap<string, number>>(() => new Map());-- useLayoutEffect(() => {- const el = containerRef.current;- if (!el) return;- const measure = () => setWidth(el.clientWidth);- measure();- if (typeof ResizeObserver === "undefined") return;- const observer = new ResizeObserver(measure);- observer.observe(el);- return () => observer.disconnect();- }, []);-- // `load` does not bubble, but it does travel the capture phase — one- // listener here hears every tile's image, including ones that swap URL- // after a re-sign. Images already decoded before this ran are read once.- useEffect(() => {- const el = containerRef.current;- if (!el) return;- const record = (img: HTMLImageElement) => {- const key = img.closest<HTMLElement>("[data-ratio-key]")?.dataset.ratioKey;- if (!key || img.naturalWidth <= 0 || img.naturalHeight <= 0) return;- const ratio = img.naturalWidth / img.naturalHeight;- setRatios((prev) => {- if (Math.abs((prev.get(key) ?? 0) - ratio) < 0.001) return prev;- return new Map(prev).set(key, ratio);- });- };- el.querySelectorAll("img").forEach((img) => {- if (img.complete) record(img);- });- const onLoad = (e: Event) => {- if (e.target instanceof HTMLImageElement) record(e.target);- };- el.addEventListener("load", onLoad, true);- return () => el.removeEventListener("load", onLoad, true);- }, [items]);-- const rows = useMemo(- () =>- justifyRows(- items.map((item) => ratios.get(item.id) ?? DEFAULT_RATIO),- width,- { gap: GAP_PX, minHeight: MIN_ROW_HEIGHT, maxHeight: MAX_ROW_HEIGHT },- ),- [items, ratios, width],- );-- return (- <div ref={containerRef} className="flex flex-col" style={{ gap: GAP_PX }}>- {rows.map((row) => (- <div key={items[row.items[0]!]!.id} className="flex" style={{ gap: GAP_PX }}>- {row.items.map((index) => {- const item = items[index]!;- const ratio = clampRatio(ratios.get(item.id) ?? DEFAULT_RATIO);- return (- <div- key={item.id}- data-ratio-key={item.id}- className="shrink-0"- style={{ width: ratio * row.height, height: row.height }}- >- {renderTile(item)}- </div>- );- })}- </div>- ))}- </div>- );-}diff --git a/packages/views/issues/components/justified-layout.test.ts b/packages/views/issues/components/justified-layout.test.tsdeleted file mode 100644index 582aaef5fd..0000000000--- a/packages/views/issues/components/justified-layout.test.ts+++ /dev/null@@ -1,52 +0,0 @@-// @vitest-environment node-import { describe, expect, it } from "vitest";-import { clampRatio, justifyRows } from "./justified-layout";--const OPTIONS = { gap: 8, minHeight: 100, maxHeight: 240 };--function rowWidth(ratios: number[], row: { items: number[]; height: number }) {- return (- row.items.reduce((sum, i) => sum + clampRatio(ratios[i]!) * row.height, 0) +- OPTIONS.gap * (row.items.length - 1)- );-}--describe("justifyRows", () => {- it("keeps a comment's three screenshots in one full row in a narrow column", () => {- const ratios = [1.6, 1.78, 1.6];- const rows = justifyRows(ratios, 585, OPTIONS);- expect(rows).toHaveLength(1);- expect(rows[0]!.items).toEqual([0, 1, 2]);- expect(rowWidth(ratios, rows[0]!)).toBeCloseTo(584, 0);- });-- it("caps the height, so two images in a wide column stop short of the edge", () => {- const rows = justifyRows([1.6, 1.6], 1200, OPTIONS);- expect(rows).toEqual([{ items: [0, 1], height: 240 }]);- });-- it("wraps before a row would get too short, and the last row keeps the height above", () => {- const ratios = Array.from({ length: 5 }, () => 1.6);- const rows = justifyRows(ratios, 585, OPTIONS);- expect(rows.map((r) => r.items.length)).toEqual([3, 2]);- expect(rowWidth(ratios, rows[0]!)).toBeCloseTo(584, 0);- expect(rows[1]!.height).toBeCloseTo(rows[0]!.height, 5);- });-- it("lays everything out in one row before the width is known", () => {- expect(justifyRows([1.6, 1.6, 1.6], 0, OPTIONS)).toEqual([- { items: [0, 1, 2], height: 240 },- ]);- expect(justifyRows([], 600, OPTIONS)).toEqual([]);- });-});--describe("clampRatio", () => {- it("bounds extreme shapes and falls back on nonsense", () => {- expect(clampRatio(10)).toBe(3);- expect(clampRatio(0.1)).toBe(0.5);- expect(clampRatio(Number.NaN)).toBe(1);- expect(clampRatio(0)).toBe(1);- expect(clampRatio(1.6)).toBe(1.6);- });-});diff --git a/packages/views/issues/components/justified-layout.ts b/packages/views/issues/components/justified-layout.tsdeleted file mode 100644index f228fff690..0000000000--- a/packages/views/issues/components/justified-layout.ts+++ /dev/null@@ -1,71 +0,0 @@-/**- * Justified rows for a set of images (MUL-7649): every image in a row shares- * one height and a full row spans the container exactly — the album layout,- * instead of fixed-height tiles that wrap and leave a ragged edge.- *- * Rows take as many images as fit without dropping below `minHeight`, so a- * comment's handful of screenshots stays one tidy row even in a narrow- * column. No row grows past `maxHeight` (two screenshots in a wide column- * stop short of the edge rather than turning huge), and a final row that- * does not fill keeps the height of the row above it, never larger.- */--export interface JustifiedRow {- /** Indexes into the input, in order. */- items: number[];- height: number;-}--export interface JustifyOptions {- gap: number;- minHeight: number;- maxHeight: number;-}--// Past these, an image would claim an absurd share of the row (a panorama)-// or a sliver of it (a phone-length screenshot); it is cropped to fit instead.-const MIN_RATIO = 0.5;-const MAX_RATIO = 3;--export function clampRatio(ratio: number): number {- if (!Number.isFinite(ratio) || ratio <= 0) return 1;- return Math.min(MAX_RATIO, Math.max(MIN_RATIO, ratio));-}--export function justifyRows(- ratios: ReadonlyArray<number>,- width: number,- { gap, minHeight, maxHeight }: JustifyOptions,-): JustifiedRow[] {- if (ratios.length === 0) return [];- if (width <= 0) {- return [{ items: ratios.map((_, i) => i), height: maxHeight }];- }- // A pixel of slack keeps sub-pixel rounding from wrapping the last image.- const heightFor = (count: number, sum: number) =>- (width - gap * (count - 1) - 1) / sum;-- const rows: JustifiedRow[] = [];- let items: number[] = [];- let ratioSum = 0;- ratios.forEach((raw, index) => {- const ratio = clampRatio(raw);- if (items.length > 0 && heightFor(items.length + 1, ratioSum + ratio) < minHeight) {- rows.push({- items,- height: Math.min(maxHeight, heightFor(items.length, ratioSum)),- });- items = [];- ratioSum = 0;- }- items.push(index);- ratioSum += ratio;- });-- const above = rows.length > 0 ? rows[rows.length - 1]!.height : maxHeight;- rows.push({- items,- height: Math.min(maxHeight, above, heightFor(items.length, ratioSum)),- });- return rows;-}