Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

MUL-8422 feat(attachments): page the viewer from a pager under the stage (#9745)

Jiayuan Zhang893c6b9a1623
diff --git a/packages/views/editor/attachment-preview-modal.tsx b/packages/views/editor/attachment-preview-modal.tsx
index 0ac3dee65d..1475061cb4 100644
--- a/packages/views/editor/attachment-preview-modal.tsx
+++ b/packages/views/editor/attachment-preview-modal.tsx
@@ -836,10 +836,8 @@ function PreviewPanel({
return (
<>
- {/* Three columns so the counter stays centered on the window while a
- long filename truncates before reaching it. */}
<header
- className="dark @container grid h-14 shrink-0 grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)] items-center gap-4 pl-3 pr-2 text-foreground"
+ className="dark @container grid h-14 shrink-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-4 pl-3 pr-2 text-foreground"
style={surface === "viewer" ? DRAG : undefined}
>
<div className="flex min-w-0 items-center gap-2.5">
@@ -867,17 +865,6 @@ function PreviewPanel({
)}
</div>
</div>
- <span
- className="select-none text-label tabular-nums text-muted-foreground"
- aria-live="polite"
- >
- {sequence
- ? t(($) => $.attachment.sequence_position, {
- index: sequence.index + 1,
- total: sequence.total,
- })
- : null}
- </span>
<div
className="flex items-center justify-self-end gap-0.5"
style={NO_DRAG}
@@ -1013,58 +1000,41 @@ function PreviewPanel({
</div>
</header>
<div className="flex min-h-0 flex-1">
- {/* The stage. In a sequence its sides are 64px gutters holding the
- prev / next buttons, so a fitted image or a page never runs under
- them. */}
- <motion.div
- className={cn(
- "relative min-h-0 min-w-0 flex-1",
- sequence ? "px-16" : "px-4",
- )}
- onClick={closeOnBackdrop}
- initial={{ transform: reduceMotion ? "scale(1)" : "scale(0.97)" }}
- animate={{
- transform: "scale(1)",
- transition: {
- duration: UI_MOTION_DURATION.standard,
- ease: UI_EASE_OUT,
- },
- }}
- >
- {kind === "image" ? (
- <ImagePreview
- state={state}
- mediaUrl={mediaUrl}
- canvas={canvas}
- natural={natural}
- onNaturalSize={handleNaturalSize}
- onError={imageLoadError}
- />
- ) : (
- <PreviewContent
- kind={kind}
- source={source}
- state={state}
- view={view}
- onDownload={onDownload}
- onBackdropClick={closeOnBackdrop}
- />
- )}
- {sequence && (
- <>
- <SequenceButton
- side="prev"
- label={t(($) => $.attachment.previous)}
- onClick={sequence.onPrev}
+ <div className="flex min-h-0 min-w-0 flex-1 flex-col">
+ <motion.div
+ className="min-h-0 flex-1 px-4"
+ onClick={closeOnBackdrop}
+ initial={{ transform: reduceMotion ? "scale(1)" : "scale(0.97)" }}
+ animate={{
+ transform: "scale(1)",
+ transition: {
+ duration: UI_MOTION_DURATION.standard,
+ ease: UI_EASE_OUT,
+ },
+ }}
+ >
+ {kind === "image" ? (
+ <ImagePreview
+ state={state}
+ mediaUrl={mediaUrl}
+ canvas={canvas}
+ natural={natural}
+ onNaturalSize={handleNaturalSize}
+ onError={imageLoadError}
/>
- <SequenceButton
- side="next"
- label={t(($) => $.attachment.next)}
- onClick={sequence.onNext}
+ ) : (
+ <PreviewContent
+ kind={kind}
+ source={source}
+ state={state}
+ view={view}
+ onDownload={onDownload}
+ onBackdropClick={closeOnBackdrop}
/>
- </>
- )}
- </motion.div>
+ )}
+ </motion.div>
+ {sequence && <SequencePager sequence={sequence} />}
+ </div>
{info?.open && (
// A column beside the stage rather than a layer over it: the file
// re-fits into what is left instead of hiding under the panel.
@@ -1179,11 +1149,44 @@ function ChromeDivider() {
return <span className="mx-1.5 h-4 w-px bg-input" aria-hidden />;
}
-// Prev / next in the stage gutters, vertically centered — next to the
-// content, never on it. `onClick` undefined means "boundary reached": the
-// button stays mounted but disabled, so the reader can see they are at one
-// end instead of the control vanishing. `enabled:hover` so the disabled state
-// gets no hover feedback.
+// Prev / next with the position between them, centered under the stage. The
+// strip is not backdrop: a click that misses a button must not close the
+// viewer. The counter's min width keeps the buttons still as digits change.
+function SequencePager({ sequence }: { sequence: PreviewSequence }) {
+ const { t } = useT("editor");
+ return (
+ <div className="dark flex h-12 shrink-0 items-center justify-center gap-1 text-foreground">
+ <SequenceButton
+ side="prev"
+ label={t(($) => $.attachment.previous)}
+ onClick={sequence.onPrev}
+ />
+ <span
+ className="min-w-16 select-none text-center text-label tabular-nums text-muted-foreground"
+ aria-live="polite"
+ >
+ {t(($) => $.attachment.sequence_position, {
+ index: sequence.index + 1,
+ total: sequence.total,
+ })}
+ </span>
+ <SequenceButton
+ side="next"
+ label={t(($) => $.attachment.next)}
+ onClick={sequence.onNext}
+ />
+ </div>
+ );
+}
+
+const SEQUENCE_KEYS = {
+ prev: { chord: createShortcutChord("Left"), aria: "ArrowLeft", Icon: ChevronLeft },
+ next: { chord: createShortcutChord("Right"), aria: "ArrowRight", Icon: ChevronRight },
+} as const;
+
+// `onClick` undefined means "boundary reached": the button stays mounted but
+// disabled, so the reader can see they are at one end instead of the control
+// vanishing. `enabled:hover` so the disabled state gets no hover feedback.
function SequenceButton({
side,
label,
@@ -1193,20 +1196,21 @@ function SequenceButton({
label: string;
onClick?: () => void;
}) {
- const Icon = side === "prev" ? ChevronLeft : ChevronRight;
+ const { chord, aria, Icon } = SEQUENCE_KEYS[side];
return (
- <TooltipHint label={label}>
+ <TooltipHint
+ label={label}
+ shortcut={<ShortcutKeycaps shortcut={chord} decorative className="ml-1.5" />}
+ >
<button
type="button"
- className={cn(
- "dark absolute top-1/2 flex size-10 -translate-y-1/2 items-center justify-center rounded-full bg-secondary/80 text-foreground transition-colors enabled:hover:bg-secondary disabled:opacity-30",
- side === "prev" ? "left-3" : "right-3",
- )}
+ className="flex size-8 items-center justify-center rounded-md text-muted-foreground transition-colors enabled:hover:bg-secondary enabled:hover:text-foreground disabled:opacity-40"
aria-label={label}
+ aria-keyshortcuts={aria}
disabled={!onClick}
onClick={onClick}
>
- <Icon className="size-5" />
+ <Icon className="size-4" />
</button>
</TooltipHint>
);
diff --git a/packages/views/editor/preview-sequence-context.test.tsx b/packages/views/editor/preview-sequence-context.test.tsx
index adbd638993..455b9d7022 100644
--- a/packages/views/editor/preview-sequence-context.test.tsx
+++ b/packages/views/editor/preview-sequence-context.test.tsx
@@ -227,6 +227,33 @@ describe("PreviewSequenceProvider", () => {
expectCounter("2 / 3");
});
+ it("keeps the counter between its buttons, on a strip that is not backdrop", () => {
+ render(
+ <PreviewSequenceProvider items={sequenceOf(THREE)}>
+ <Opener openKey={THREE[0]!.id} />
+ </PreviewSequenceProvider>,
+ );
+ act(() => {
+ fireEvent.click(screen.getByText("open"));
+ });
+
+ const pager = screen.getByText("1 / 3").parentElement!;
+ expect(pager).toContainElement(prevButton());
+ expect(pager).toContainElement(nextButton());
+ expect(prevButton()).toHaveAttribute("aria-keyshortcuts", "ArrowLeft");
+ expect(nextButton()).toHaveAttribute("aria-keyshortcuts", "ArrowRight");
+
+ // A click that misses both buttons must leave the viewer open: a closing
+ // viewer drops its key handler, so the arrow would no longer page.
+ act(() => {
+ fireEvent.click(pager);
+ });
+ act(() => {
+ fireEvent.keyDown(document, { key: "ArrowRight" });
+ });
+ expectCounter("2 / 3");
+ });
+
it("moves with the left / right arrow keys", () => {
render(
<PreviewSequenceProvider items={sequenceOf(THREE)}>