Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

feat(ui): 点开一张图,图下有能真的做事的胶囊条

lmlihenge62db0f0ab48
diff --git a/changelog/unreleased/2026-10-29-image-board-bar.md b/changelog/unreleased/2026-10-29-image-board-bar.md
new file mode 100644
index 00000000..716c2ae2
--- /dev/null
+++ b/changelog/unreleased/2026-10-29-image-board-bar.md
@@ -0,0 +1,48 @@
+# A picture opens with the bar of things you can actually do to it
+
+- **Date:** 2026-10-29
+- **Type:** feature
+- **Scope:** `ui`, `web`
+- **Breaking:** no
+
+[中文](2026-10-29-image-board-bar.zh.md)
+
+Opening a picture in the lightbox used to leave one gesture: close it. The frame now carries,
+under the image, a capsule bar with the actions the page can really perform — **save the file**
+and, when the picture is one of several that arrived together, **step through the batch**. The
+picture's own pixel size sits in the opposite corner of the frame, so a 2364 × 1773 screenshot
+says so instead of looking like whatever the window made of it.
+
+Nothing pretends. Editing, layer split, background removal and the rest of that family are a
+generation service's job, and no endpoint here backs them; the bar holds no button that cannot
+work.
+
+## Details
+
+- `packages/ui/src/components/overlays/lightbox/image-board.ts` (new): the arithmetic, apart from
+ the markup — `stepIndex` (a batch is a carousel: the last picture's "next" is the first);
+ `pixelSizeLabel` (the picture's own size, or nothing while an unloaded image still reports
+ 0 × 0); `downloadName` (the last segment of a URL or path, decoded; the name a route carries in
+ `path=` when its own segment is only an id, as `…/files/content?path=shot.png` is; the media
+ type's name for a `data:` URL; the caller's fallback for a `blob:`).
+- `packages/ui/src/components/overlays/lightbox/lightbox.tsx`: `Lightbox` takes `images` — the
+ batch a picture belongs to — opens on the one that was clicked, shows one thumbnail per picture
+ (marked `aria-current`), a "2 / 3" counter and the two step buttons, and saves whatever is on
+ screen under `downloadName(src)`. `ZoomableImage` forwards a caller's `group` into it. The
+ close glyph and the Escape-layer behaviour are unchanged; a single picture therefore shows only
+ the save action.
+- `packages/ui/src/strings.ts`: three accessibility keys — `download`, `previousImage`,
+ `nextImage` — with the web app mapping them per language (`common.previousImage` /
+ `common.nextImage`, `files.download`).
+- `packages/web/src/features/chat/chat-input.tsx`: the staged attachments are one batch, so
+ opening one of five pictures steps through the other four instead of closing and hunting for the
+ next thumbnail.
+- Tests: `packages/ui/test/image-board.test.ts` (new: wrapping, unknown sizes, every naming
+ source), `packages/ui/test/lightbox.test.ts` (the bar's labels, the download name, a batch
+ opening on the clicked picture, thumbnails, the counter, an empty batch), and the key list in
+ `packages/ui/test/strings.test.ts`.
+
+## Compatibility
+
+- No API, on-disk or protocol change. A lightbox opened without `images` is the picture and its
+ close glyph as before, plus the save action; the markup of a thumbnail is unchanged.
diff --git a/changelog/unreleased/2026-10-29-image-board-bar.zh.md b/changelog/unreleased/2026-10-29-image-board-bar.zh.md
new file mode 100644
index 00000000..3f056122
--- /dev/null
+++ b/changelog/unreleased/2026-10-29-image-board-bar.zh.md
@@ -0,0 +1,39 @@
+# 图片打开后,下面那条胶囊条是真的能用的
+
+- **日期:** 2026-10-29
+- **类型:** feature
+- **范围:** `ui`、`web`
+- **破坏性:** 无
+
+[English](2026-10-29-image-board-bar.md)
+
+图片在 lightbox 里打开以后,过去只有一个动作:关掉。现在图片下方多了一条胶囊工具条,只放页面**真做
+得到**的事 —— **把这个文件存下来**,以及图片是同一批一起到的几张时,**在它们之间前后翻**。图片自己的
+像素尺寸写在框的左上角,于是 2364 × 1773 的截图会这么说自己,而不是看上去只有窗口那么大。
+
+不摆做不了的按钮。编辑、分图层、去背景那一族是图像生成服务的活,这里没有接口撑着它们,于是那条条上
+一个这样的按钮都没有。
+
+## 细节
+
+- `packages/ui/src/components/overlays/lightbox/image-board.ts`(新增):把算式从标记里分出来 ——
+ `stepIndex`(一批图是转盘:最后一张的「下一张」是第一张)、`pixelSizeLabel`(图片自己的尺寸;还没
+ 加载完的 `<img>` 报 0 × 0,那时什么都不说)、`downloadName`(URL 或路径的最后一段并解码;路由自己
+ 那一段只是个 id 时取它在 `path=` 里带着的名字,如 `…/files/content?path=shot.png`;`data:` URL 按
+ 媒体类型给名字;`blob:` 用调用方的兜底名)。
+- `packages/ui/src/components/overlays/lightbox/lightbox.tsx`:`Lightbox` 新增 `images` —— 这张图所属
+ 的那一批 —— 在点的那张上打开,每张一个缩略图(当前那张标 `aria-current`)、一个「2 / 3」计数与两个
+ 翻页按钮,保存的就是屏幕上那一张,文件名走 `downloadName(src)`。`ZoomableImage` 把调用方给的
+ `group` 转进去。关闭按钮与 Escape 层的行为没动;只有一张图时,条上只剩下载。
+- `packages/ui/src/strings.ts`:三个无障碍文案键 —— `download`、`previousImage`、`nextImage` —— 由
+ Web 按语言映射(`common.previousImage` / `common.nextImage`、`files.download`)。
+- `packages/web/src/features/chat/chat-input.tsx`:暂存的附件算一批,于是五张图里点开一张,就在另外
+ 四张之间翻,不用关掉再去找下一个缩略图。
+- 测试:`packages/ui/test/image-board.test.ts`(新增:环绕、尺寸未知、每种名字来源)、
+ `packages/ui/test/lightbox.test.ts`(条上的文案、下载名、一批图开在点的那张、缩略图、计数、空批
+ 次),以及 `packages/ui/test/strings.test.ts` 的键表。
+
+## 兼容
+
+- 接口、磁盘格式、线上协议都没变。不带 `images` 打开的 lightbox 仍是原来那张图加关闭按钮,多出一个
+ 保存动作;缩略图的标记与以前一模一样。
diff --git a/packages/ui/src/components/overlays/lightbox/image-board.ts b/packages/ui/src/components/overlays/lightbox/image-board.ts
new file mode 100644
index 00000000..af659edc
--- /dev/null
+++ b/packages/ui/src/components/overlays/lightbox/image-board.ts
@@ -0,0 +1,79 @@
+/**
+ * The lightbox's arithmetic, apart from its markup so it can be read on its own: which picture of
+ * a batch a step lands on, what a picture's own pixel size reads as, and what name a download
+ * saves under.
+ */
+
+/** One picture of the lightbox's batch: what to fetch, and the words that describe it. */
+export interface LightboxImage {
+ src: string;
+ alt: string;
+}
+
+/**
+ * The index `step` moves to from `at`, wrapping at both ends — the batch is a carousel, so the
+ * last picture's "next" is the first. A batch with nothing in it has only index 0 to be at.
+ */
+export function stepIndex(at: number, step: number, count: number): number {
+ if (count <= 0) return 0;
+ return (((at + step) % count) + count) % count;
+}
+
+/**
+ * The badge's text: the picture's own pixel size, never the size it happens to be drawn at.
+ * `null` while either side is unknown — an `<img>` that has not loaded reports 0 × 0, and a badge
+ * saying "0 × 0" is worse than no badge.
+ */
+export function pixelSizeLabel(width: number, height: number): string | null {
+ if (!Number.isFinite(width) || !Number.isFinite(height) || width < 1 || height < 1) return null;
+ return `${Math.round(width)} × ${Math.round(height)}`;
+}
+
+/** What a `data:` URL's media type says the file is called, when it says anything. */
+function dataTypeName(src: string): string | null {
+ const mime = /^data:([^;,]+)/.exec(src)?.[1]?.trim().toLowerCase() ?? "";
+ if (!mime.startsWith("image/")) return null;
+ const subtype = mime.slice("image/".length);
+ // `svg+xml` is the one subtype that carries a suffix; the rest are single words, and the two
+ // abbreviations below are the ones files are actually saved as.
+ if (subtype === "svg+xml") return "svg";
+ if (subtype === "jpeg") return "jpg";
+ if (subtype === "x-icon" || subtype === "vnd.microsoft.icon") return "ico";
+ return /^[a-z0-9]+$/.test(subtype) ? subtype : null;
+}
+
+/** The last segment of a path, decoded — or `null` when the path ends in a separator. */
+function lastSegment(path: string): string | null {
+ const segment = path.slice(path.lastIndexOf("/") + 1);
+ if (segment === "") return null;
+ try {
+ return decodeURIComponent(segment);
+ } catch {
+ // A stray `%` is not an escape: the raw segment is still a better name than the fallback.
+ return segment;
+ }
+}
+
+/**
+ * The name a download saves under. A URL or a path hands over its last segment, still decoded
+ * (`shot%201.png` is `shot 1.png`); a route that names no file itself but carries one in `path=`
+ * — the app serves a workspace picture at `…/files/content?path=shot.png` — takes that one; a
+ * `data:` URL has no name of its own, so it takes the one its media type implies. Anything else
+ * — a `blob:`, an empty src — takes `fallback`, which keeps the saved file's extension with it
+ * (`image.png`).
+ */
+export function downloadName(src: string, fallback = "image"): string {
+ if (src.startsWith("data:")) {
+ const type = dataTypeName(src);
+ return type === null ? fallback : `${fallback}.${type}`;
+ }
+ // A blob: URL is an opaque id, not a name; there is nothing to save it under but the fallback.
+ if (src.startsWith("blob:")) return fallback;
+ const [pathname = "", ...queryParts] = (src.split("#")[0] ?? "").split("?");
+ const own = lastSegment(pathname);
+ const carried = lastSegment(new URLSearchParams(queryParts.join("?")).get("path") ?? "");
+ // The route's own last segment wins when it looks like a file name; otherwise the name it
+ // carries in `path=` is the file's, and an id-shaped segment (`content`) is not.
+ if (own !== null && own.includes(".")) return own;
+ return carried ?? own ?? fallback;
+}
diff --git a/packages/ui/src/components/overlays/lightbox/lightbox.tsx b/packages/ui/src/components/overlays/lightbox/lightbox.tsx
index 50633fa4..0517f992 100644
--- a/packages/ui/src/components/overlays/lightbox/lightbox.tsx
+++ b/packages/ui/src/components/overlays/lightbox/lightbox.tsx
@@ -1,20 +1,32 @@
/**
- * The lightbox: an image shown large over the page, in a bordered frame with a close glyph in the
- * top-right corner (no title bar), closable via Esc or clicking the overlay. `ZoomableImage` is the
- * thumbnail that opens it: the thumbnail keeps the caller's styling, and a click zooms in.
+ * The lightbox: an image shown large over the page, with a close glyph in the top-right corner
+ * (no title bar) and, below it, the bar of things one can actually do with the picture — download
+ * it, and step through the batch it came in. Closable via Esc or clicking the overlay.
+ * `ZoomableImage` is the thumbnail that opens it: the thumbnail keeps the caller's styling, and a
+ * click zooms in.
*
* The lightbox is rendered via portal to body — the thumbnail may be nested inside a card with a
* transform entrance animation or overflow-hidden, and a `fixed` layer rendered in place would get
* hijacked or clipped by that ancestor (the same reason the Select panel portals). Escape goes
* through the shared Escape-layer stack like every other overlay's, so a lightbox opened from
* inside a dialog closes alone and leaves the dialog up.
+ *
+ * The bar carries only what the page can really do: save the file (a plain `download` link, no
+ * request of its own) and move within the batch. Editing actions a generation service would back
+ * have no endpoint behind them here, and a row of buttons that cannot work is worse than none.
*/
import { useState } from "react";
import type { ComponentPropsWithoutRef } from "react";
import { createPortal } from "react-dom";
import { useUiStrings } from "../../../strings";
-import { CloseIcon } from "../../icons/marks/marks";
+import { ICONS } from "../../icons/icons";
+import { GlyphIcon } from "../../icons/glyph-icon/glyph-icon";
+import { CloseIcon, DownloadIcon } from "../../icons/marks/marks";
import { useEscLayer } from "../esc-layers/esc-layers";
+import { downloadName, pixelSizeLabel, stepIndex } from "./image-board";
+import type { LightboxImage } from "./image-board";
+
+export type { LightboxImage };
export interface LightboxProps {
open: boolean;
@@ -23,19 +35,56 @@ export interface LightboxProps {
onClose: () => void;
/** The close glyph's accessible name; defaults to the interface's word for "close". */
closeLabel?: string;
+ /**
+ * The batch the picture belongs to — the attachments of one message, the results of one
+ * generation — so the lightbox can show them side by side and step between them. `src` picks
+ * the one it opens on. Omitted, the batch is the single picture and the bar is just the
+ * download.
+ */
+ images?: readonly LightboxImage[];
}
-export function Lightbox({ open, src, alt, onClose, closeLabel }: LightboxProps) {
+export function Lightbox({ open, src, alt, onClose, closeLabel, images }: LightboxProps) {
const strings = useUiStrings();
- useEscLayer(open, onClose);
+ // Closing resets the step, so the next opening starts on the caller's own picture rather than on
+ // whichever one the reader last looked at.
+ const close = () => {
+ setStep(null);
+ onClose();
+ };
+ useEscLayer(open, close);
+ // The step the reader took from the caller's picture, or null while they have taken none.
+ const [step, setStep] = useState<number | null>(null);
+ /**
+ * The pixel size of the picture that loaded, tagged with its src: switching pictures leaves the
+ * previous reading behind, and the badge must not show another picture's numbers while the next
+ * one is still arriving.
+ */
+ const [measured, setMeasured] = useState<{ src: string; width: number; height: number } | null>(
+ null,
+ );
if (!open) return null;
+
+ const batch = images !== undefined && images.length > 0 ? images : [{ src, alt }];
+ const opening = Math.max(
+ batch.findIndex((image) => image.src === src),
+ 0,
+ );
+ const at = Math.min(Math.max(step ?? opening, 0), batch.length - 1);
+ const shown = batch[at] ?? { src, alt };
+ const badge =
+ measured !== null && measured.src === shown.src
+ ? pixelSizeLabel(measured.width, measured.height)
+ : null;
+ const multi = batch.length > 1;
+
return createPortal(
<div
- // ui-scrim: the overlay is the dimmed layer, with the image inside it.
- className="ui-scrim anim-fade fixed inset-0 z-50 flex items-center justify-center bg-[var(--ui-overlay-backdrop)] p-10"
+ // ui-scrim: the overlay is the dimmed layer, with the image and its bar inside it.
+ className="ui-scrim anim-fade fixed inset-0 z-50 flex flex-col items-center justify-center gap-3 bg-[var(--ui-overlay-backdrop)] p-10"
onMouseDown={(e) => {
- if (e.target === e.currentTarget) onClose();
+ if (e.target === e.currentTarget) close();
}}
>
<div className="anim-pop relative">
@@ -44,16 +93,85 @@ export function Lightbox({ open, src, alt, onClose, closeLabel }: LightboxProps)
<button
type="button"
aria-label={closeLabel ?? strings.close}
- onClick={onClose}
+ onClick={close}
className="absolute right-2 top-2 flex h-7 w-7 items-center justify-center rounded-full bg-fg/50 text-canvas transition-colors duration-150 hover:bg-fg/70"
>
<CloseIcon />
</button>
<img
- src={src}
- alt={alt}
+ key={shown.src}
+ src={shown.src}
+ alt={shown.alt}
+ onLoad={(e) =>
+ setMeasured({
+ src: shown.src,
+ width: e.currentTarget.naturalWidth,
+ height: e.currentTarget.naturalHeight,
+ })
+ }
className="max-h-[85vh] max-w-[88vw] rounded-lg border border-line bg-surface"
/>
+ {/* The picture's own pixel size, opposite the close glyph: what the file is, not what the
+ window made of it. */}
+ {badge !== null && (
+ <span className="absolute left-2 top-2 rounded-full bg-fg/50 px-2 py-0.5 text-xs tabular-nums text-canvas">
+ {badge}
+ </span>
+ )}
+ </div>
+
+ {multi && (
+ <div className="anim-fade flex max-w-[88vw] items-center gap-2 overflow-x-auto">
+ {batch.map((image, i) => (
+ <button
+ key={`${i}-${image.src}`}
+ type="button"
+ aria-label={image.alt}
+ aria-current={i === at ? "true" : undefined}
+ onClick={() => setStep(i)}
+ className={`h-12 w-12 shrink-0 overflow-hidden rounded-md border transition-colors duration-150 ${
+ i === at ? "border-line-emphasis" : "border-line hover:border-fg-muted"
+ }`}
+ >
+ <img src={image.src} alt="" className="h-full w-full object-cover" />
+ </button>
+ ))}
+ </div>
+ )}
+
+ {/* The capsule bar: step within the batch on the left, save on the right. */}
+ <div className="anim-pop flex items-center gap-1 rounded-full border border-line bg-surface px-1.5 py-1">
+ {multi && (
+ <>
+ <button
+ type="button"
+ aria-label={strings.previousImage}
+ onClick={() => setStep(stepIndex(at, -1, batch.length))}
+ className="flex h-7 w-7 items-center justify-center rounded-full text-fg-muted transition-colors duration-150 hover:bg-surface-muted hover:text-fg"
+ >
+ <GlyphIcon d={ICONS.arrowLeftCentered} size={14} />
+ </button>
+ <button
+ type="button"
+ aria-label={strings.nextImage}
+ onClick={() => setStep(stepIndex(at, 1, batch.length))}
+ className="flex h-7 w-7 items-center justify-center rounded-full text-fg-muted transition-colors duration-150 hover:bg-surface-muted hover:text-fg"
+ >
+ <GlyphIcon d={ICONS.arrowRightCentered} size={14} />
+ </button>
+ <span className="px-1 text-xs tabular-nums text-fg-muted">
+ {at + 1} / {batch.length}
+ </span>
+ </>
+ )}
+ <a
+ href={shown.src}
+ download={downloadName(shown.src)}
+ className="flex h-7 items-center gap-1.5 rounded-full px-2 text-xs text-fg transition-colors duration-150 hover:bg-surface-muted"
+ >
+ <DownloadIcon />
+ <span>{strings.download}</span>
+ </a>
</div>
</div>,
document.body,
@@ -67,6 +185,7 @@ export function ZoomableImage({
className,
closeLabel,
lazy = false,
+ group,
...imgProps
}: {
src: string;
@@ -77,6 +196,8 @@ export function ZoomableImage({
closeLabel?: string;
/** Fetch the thumbnail only as it nears the viewport (a long list of fetched images, e.g. a transcript's). */
lazy?: boolean;
+ /** The batch this picture belongs to, when the caller has one (a message's attachments). */
+ group?: readonly LightboxImage[];
} & Omit<ComponentPropsWithoutRef<"img">, "src" | "alt" | "className" | "loading">) {
const [open, setOpen] = useState(false);
return (
@@ -84,7 +205,7 @@ export function ZoomableImage({
<button type="button" className="block cursor-zoom-in" onClick={() => setOpen(true)}>
{/* Everything else the caller's img already had — a Markdown picture's title, width and
height — belongs to the thumbnail: those are how it fits the text it sits in. The
- lightbox shows the file at its own size and takes only src and alt. */}
+ lightbox shows the file at its own size and takes only src, alt and the batch. */}
<img
{...imgProps}
src={src}
@@ -99,6 +220,7 @@ export function ZoomableImage({
alt={alt}
onClose={() => setOpen(false)}
closeLabel={closeLabel}
+ {...(group !== undefined ? { images: group } : {})}
/>
</>
);
diff --git a/packages/ui/src/strings.ts b/packages/ui/src/strings.ts
index 5c041082..ce172657 100644
--- a/packages/ui/src/strings.ts
+++ b/packages/ui/src/strings.ts
@@ -53,6 +53,11 @@ export interface UiStrings {
next: string;
/** What a pager's "2/5" readout says aloud: the page, then how many there are (`Pager`). */
pagePosition: (page: number, pageCount: number) => string;
+ /** The lightbox's save action, as its label and its name (`Lightbox`). */
+ download: string;
+ /** The lightbox's two steps through a batch of pictures, as their names and tooltips. */
+ previousImage: string;
+ nextImage: string;
}
/** The English fallbacks, used wherever no provider is mounted (a test, a stand-alone page). */
@@ -75,6 +80,9 @@ export const DEFAULT_UI_STRINGS: UiStrings = {
previous: "Previous page",
next: "Next page",
pagePosition: (page, pageCount) => `Page ${page} of ${pageCount}`,
+ download: "Download",
+ previousImage: "Previous image",
+ nextImage: "Next image",
};
const UiStringsContext = createContext<UiStrings>(DEFAULT_UI_STRINGS);
diff --git a/packages/ui/test/image-board.test.ts b/packages/ui/test/image-board.test.ts
new file mode 100644
index 00000000..764e0225
--- /dev/null
+++ b/packages/ui/test/image-board.test.ts
@@ -0,0 +1,89 @@
+/**
+ * The lightbox's arithmetic (src/components/overlays/lightbox/image-board.ts): stepping through a
+ * batch wraps at both ends, the pixel badge speaks only when a picture's own size is known, and a
+ * download takes the file's name from where the picture came from.
+ */
+import { describe, expect, it } from "vitest";
+import {
+ downloadName,
+ pixelSizeLabel,
+ stepIndex,
+} from "../src/components/overlays/lightbox/image-board";
+
+describe("stepIndex", () => {
+ it("steps forward and back inside the batch", () => {
+ expect(stepIndex(0, 1, 3)).toBe(1);
+ expect(stepIndex(2, -1, 3)).toBe(1);
+ });
+
+ it("wraps at both ends, because the batch is a carousel", () => {
+ expect(stepIndex(2, 1, 3)).toBe(0);
+ expect(stepIndex(0, -1, 3)).toBe(2);
+ });
+
+ it("keeps a single picture where it is, and an empty batch at 0", () => {
+ expect(stepIndex(0, 1, 1)).toBe(0);
+ expect(stepIndex(0, -1, 1)).toBe(0);
+ expect(stepIndex(0, 1, 0)).toBe(0);
+ });
+});
+
+describe("pixelSizeLabel", () => {
+ it("reads the picture's own size, with the multiplication sign between them", () => {
+ expect(pixelSizeLabel(2364, 1773)).toBe("2364 × 1773");
+ });
+
+ it("says nothing while the size is unknown — an unloaded image reports 0", () => {
+ expect(pixelSizeLabel(0, 0)).toBeNull();
+ expect(pixelSizeLabel(1280, 0)).toBeNull();
+ expect(pixelSizeLabel(Number.NaN, 720)).toBeNull();
+ expect(pixelSizeLabel(Number.POSITIVE_INFINITY, 720)).toBeNull();
+ });
+
+ it("rounds a fractional size rather than printing it", () => {
+ expect(pixelSizeLabel(1280.4, 719.6)).toBe("1280 × 720");
+ });
+});
+
+describe("downloadName", () => {
+ it("takes the last segment of a URL, without its query or fragment", () => {
+ expect(downloadName("https://example.test/a/quarterly-report.pdf#page=2")).toBe(
+ "quarterly-report.pdf",
+ );
+ expect(downloadName("shot.png")).toBe("shot.png");
+ });
+
+ it("takes the name a route carries in `path=` when its own segment is only an id", () => {
+ // The app serves a workspace picture at …/files/content?path=shot.png.
+ expect(downloadName("/api/sessions/s-1/files/content?path=shot.png")).toBe("shot.png");
+ expect(downloadName("/api/sessions/s-1/files/content?path=docs%2Fshot.png")).toBe("shot.png");
+ // A segment that already names a file wins over the query.
+ expect(downloadName("/files/shot.png?path=other.png")).toBe("shot.png");
+ });
+
+ it("decodes what the URL encoded, so the saved file has the name the user saw", () => {
+ expect(
+ downloadName("https://example.test/reports/%E5%AD%A3%E5%BA%A6%E6%8A%A5%E5%91%8A.pdf"),
+ ).toBe("季度报告.pdf");
+ expect(downloadName("/a/shot%201.png")).toBe("shot 1.png");
+ });
+
+ it("names a data URL after its media type, since it has no name of its own", () => {
+ expect(downloadName("data:image/png;base64,iVBORw0KGgo=")).toBe("image.png");
+ expect(downloadName("data:image/jpeg;base64,/9j/4AAQ")).toBe("image.jpg");
+ expect(downloadName("data:image/svg+xml;utf8,<svg/>")).toBe("image.svg");
+ expect(downloadName("data:image/webp;base64,UklGR")).toBe("image.webp");
+ });
+
+ it("falls back when nothing names the file, keeping the extension with the name", () => {
+ expect(downloadName("blob:https://app.test/6f1c", "image")).toBe("image");
+ expect(downloadName("", "image")).toBe("image");
+ expect(downloadName("data:text/plain,hello", "image")).toBe("image");
+ expect(downloadName("https://example.test/", "image")).toBe("image");
+ expect(downloadName("blob:https://app.test/6f1c", "download")).toBe("download");
+ });
+
+ it("keeps a stray percent sign rather than failing the whole name", () => {
+ expect(downloadName("/a/100%_done.png")).toBe("100%_done.png");
+ });
+});
diff --git a/packages/ui/test/lightbox.test.ts b/packages/ui/test/lightbox.test.ts
index cb44a8c2..6d303047 100644
--- a/packages/ui/test/lightbox.test.ts
+++ b/packages/ui/test/lightbox.test.ts
@@ -2,7 +2,9 @@
* Lightbox and ZoomableImage (src/components/overlays/lightbox/lightbox.tsx): the thumbnail keeps
* the caller's styling and mounts nothing else until clicked; the lightbox names its close glyph in
* the interface's words, dims the page through the scrim hook, and closes on Escape only through
- * the shared layer stack, so a lightbox opened inside a dialog closes alone.
+ * the shared layer stack, so a lightbox opened inside a dialog closes alone. A batch opens on the
+ * picture that was clicked, shows its thumbnails and a step counter, and every picture can be
+ * saved — the bar holds only what the page can really do.
*/
import { readFileSync } from "node:fs";
import { join } from "node:path";
@@ -10,6 +12,7 @@ import { createElement } from "react";
import type { ReactNode } from "react";
import { describe, expect, it, vi } from "vitest";
import { Lightbox, ZoomableImage } from "../src/components/overlays/lightbox/lightbox";
+import type { LightboxImage } from "../src/components/overlays/lightbox/lightbox";
import { DEFAULT_UI_STRINGS, UiStringsProvider } from "../src/strings";
import { classTokens, renderStatic } from "../src/testing";
import { stubDialogGlobals } from "./helpers/dialog-env";
@@ -27,6 +30,9 @@ const lightbox = (closeLabel?: string) =>
createElement(Lightbox, { open: true, src: "/a.png", alt: "Chart", onClose: noop, closeLabel }),
);
+/** The `<img>` tags of a rendered lightbox, in DOM order: the picture first, then its thumbnails. */
+const images = (html: string) => html.match(/<img\b[^>]*>/g) ?? [];
+
describe("ZoomableImage", () => {
it("is a button around the caller's thumbnail, with the lightbox not yet mounted", () => {
const html = renderStatic(
@@ -96,7 +102,125 @@ describe("Lightbox", () => {
it("closes on Escape through the shared layer stack, never a listener of its own", () => {
const text = readFileSync(join(SRC_DIR, "components/overlays/lightbox/lightbox.tsx"), "utf8");
- expect(text).toContain("useEscLayer(open, onClose)");
+ expect(text).toContain("useEscLayer(open, close)");
expect(text).not.toMatch(/"keydown"/);
});
});
+
+const BATCH: readonly LightboxImage[] = [
+ { src: "/a.png", alt: "Chart" },
+ { src: "/b.png", alt: "Table" },
+ { src: "/c.png", alt: "Diagram" },
+];
+
+/** The batch opened on its middle picture, as clicking that thumbnail would. */
+const batchOpened = () =>
+ renderStatic(
+ createElement(Lightbox, {
+ open: true,
+ src: "/b.png",
+ alt: "Table",
+ onClose: noop,
+ images: BATCH,
+ }),
+ );
+
+describe("Lightbox's bar", () => {
+ it("saves the picture shown, under the name its src gives it", () => {
+ expect(lightbox()).toContain('href="/a.png"');
+ expect(lightbox()).toContain('download="a.png"');
+ expect(lightbox()).toContain(">Download</span>");
+ });
+
+ it("takes the name the route carries when its own segment is only an id", () => {
+ const html = renderStatic(
+ createElement(Lightbox, {
+ open: true,
+ src: "/api/sessions/s-1/files/content?path=shot.png",
+ alt: "Shot",
+ onClose: noop,
+ }),
+ );
+ expect(html).toContain('download="shot.png"');
+ });
+
+ it("speaks its labels in the interface's words", () => {
+ const batchHtml = renderStatic(
+ createElement(
+ UiStringsProvider,
+ {
+ strings: {
+ ...DEFAULT_UI_STRINGS,
+ download: "下载",
+ previousImage: "上一张图片",
+ nextImage: "下一张图片",
+ },
+ },
+ createElement(Lightbox, {
+ open: true,
+ src: "/b.png",
+ alt: "Table",
+ onClose: noop,
+ images: BATCH,
+ }),
+ ),
+ );
+ expect(batchHtml).toContain('aria-label="上一张图片"');
+ expect(batchHtml).toContain('aria-label="下一张图片"');
+ expect(batchHtml).toContain(">下载</span>");
+ });
+
+ it("holds no step buttons for a single picture — there is nowhere to step", () => {
+ expect(lightbox()).not.toContain('aria-label="Previous image"');
+ expect(lightbox()).not.toContain('aria-label="Next image"');
+ expect(lightbox()).not.toContain("1 / 1");
+ });
+});
+
+describe("Lightbox with a batch", () => {
+ it("opens on the picture that was clicked, not on the batch's first", () => {
+ const [shown] = images(batchOpened());
+ expect(shown).toContain('src="/b.png"');
+ expect(shown).toContain("max-h-[85vh]");
+ });
+
+ it("shows one thumbnail per picture, marking the one on screen", () => {
+ const thumbnails = images(batchOpened()).slice(1);
+ expect(thumbnails.map((tag) => tag.match(/src="([^"]*)"/)?.[1])).toEqual([
+ "/a.png",
+ "/b.png",
+ "/c.png",
+ ]);
+ // Decorative in the strip: the button's own name describes it, so the <img> says nothing
+ // twice — and the buttons' names are the pictures' alts.
+ expect(thumbnails.every((tag) => tag.includes('alt=""'))).toBe(true);
+ const buttons = batchOpened().match(/aria-current="true"/g) ?? [];
+ expect(buttons).toHaveLength(1);
+ expect(batchOpened().match(/aria-label="Table"/g)?.length).toBeGreaterThanOrEqual(1);
+ });
+
+ it("counts the batch in step form: the picture shown, then how many there are", () => {
+ const text = batchOpened().replace(/<[^>]*>/g, " ");
+ expect(text).toMatch(/2\s*\/\s*3/);
+ });
+
+ it("falls back to the single picture when the batch is empty", () => {
+ const html = renderStatic(
+ createElement(Lightbox, {
+ open: true,
+ src: "/a.png",
+ alt: "Chart",
+ onClose: noop,
+ images: [],
+ }),
+ );
+ expect(images(html)).toHaveLength(1);
+ expect(html).not.toContain("1 / 1");
+ });
+
+ it("paints the bar in tokens, never a palette colour", () => {
+ expect(classTokens(batchOpened())).toEqual(
+ expect.arrayContaining(["rounded-full", "border-line", "bg-surface", "text-fg-muted"]),
+ );
+ });
+});
diff --git a/packages/ui/test/strings.test.ts b/packages/ui/test/strings.test.ts
index 82dc7f6f..39212a98 100644
--- a/packages/ui/test/strings.test.ts
+++ b/packages/ui/test/strings.test.ts
@@ -29,6 +29,7 @@ describe("UiStrings", () => {
"copied",
"copyCode",
"dismiss",
+ "download",
"expand",
"fewer",
"hidePassword",
@@ -37,9 +38,11 @@ describe("UiStrings", () => {
"moreInfo",
"moreInfoAbout",
"next",
+ "nextImage",
"notifications",
"pagePosition",
"previous",
+ "previousImage",
"showPassword",
]);
expect(DEFAULT_UI_STRINGS).toMatchObject({
diff --git a/packages/web/src/features/chat/chat-input.tsx b/packages/web/src/features/chat/chat-input.tsx
index d8321db9..18cfda75 100644
--- a/packages/web/src/features/chat/chat-input.tsx
+++ b/packages/web/src/features/chat/chat-input.tsx
@@ -882,6 +882,14 @@ export function ChatInput({
const textRef = useRef(text);
textRef.current = text;
const [images, setImages] = useState<string[]>([]);
+ /**
+ * The staged images as one batch for the lightbox: opening any of them lets the reader step
+ * through the rest of the strip, instead of closing and hunting for the next thumbnail.
+ */
+ const imageBatch = useMemo(
+ () => images.map((url) => ({ src: url, alt: S.chat.imageAlt })),
+ [images, S.chat.imageAlt],
+ );
// Videos staged from the "+" menu, a drop or a paste: held exactly like images (a base64 data
// URL), but as whole entries rather than bare strings — the picked name is what the clip is
// called when the model that takes none gets it as a scratchpad file, and the chip shows it too.
@@ -2227,6 +2235,7 @@ export function ChatInput({
<ZoomableImage
src={url}
alt={S.chat.imageAlt}
+ group={imageBatch}
className="h-16 w-16 rounded-md border border-gray-200 object-cover dark:border-gray-700"
/>
<button
diff --git a/packages/web/src/lib/strings-en.ts b/packages/web/src/lib/strings-en.ts
index 1135d90f..5fbfcf3a 100644
--- a/packages/web/src/lib/strings-en.ts
+++ b/packages/web/src/lib/strings-en.ts
@@ -1254,6 +1254,9 @@ export const en: Strings = {
/** A pager's two steps, as their names and tooltips (the shared UI package's `Pager`). */
previousPage: "Previous page",
nextPage: "Next page",
+ /** The shared UI package's `Lightbox`: stepping through one batch of pictures. */
+ previousImage: "Previous image",
+ nextImage: "Next image",
name: "Name",
username: "Username",
role: "Role",
diff --git a/packages/web/src/lib/strings.ts b/packages/web/src/lib/strings.ts
index 96292e1e..f369eda0 100644
--- a/packages/web/src/lib/strings.ts
+++ b/packages/web/src/lib/strings.ts
@@ -1302,6 +1302,9 @@ export const zh = {
/** A pager's two steps, as their names and tooltips (the shared UI package's `Pager`). */
previousPage: "上一页",
nextPage: "下一页",
+ /** The shared UI package's `Lightbox`: stepping through one batch of pictures. */
+ previousImage: "上一张图片",
+ nextImage: "下一张图片",
name: "名称",
username: "用户名",
role: "角色",
diff --git a/packages/web/src/lib/ui-strings.ts b/packages/web/src/lib/ui-strings.ts
index 03364f6d..87175d2f 100644
--- a/packages/web/src/lib/ui-strings.ts
+++ b/packages/web/src/lib/ui-strings.ts
@@ -32,6 +32,9 @@ export function uiStringsOf(dict: Strings): UiStrings {
previous: dict.common.previousPage,
next: dict.common.nextPage,
pagePosition: dict.chat.groupPagePosition,
+ download: dict.files.download,
+ previousImage: dict.common.previousImage,
+ nextImage: dict.common.nextImage,
};
}