Skip to content

Commit b447428

Browse files
committed
fix(web): restore zoom, pan and snapshot details to the expanded dialog
Converting this dialog onto the shared Dialog primitive rewrote its render tree and dropped features that had nothing to do with the conversion: the snapshot accessibility panel and its contents toggle went with the rewrite, and upstream's zoomable image and keyboard panning were lost resolving the rebase against it. None of them conflict with the conversion. The two snapshot components are exported again and both are wired back into the converted tree, matching upstream's behaviour rather than approximating it.
1 parent d434be2 commit b447428

3 files changed

Lines changed: 70 additions & 11 deletions

File tree

‎.pnpm-store/v11/index.db‎

8 KB
Binary file not shown.

‎apps/web/src/components/chat/ExpandedImageDialog.tsx‎

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { memo, useCallback, useEffect, useRef, useState, type ReactNode } from "react";
2-
import { ChevronLeftIcon, ChevronRightIcon, XIcon } from "lucide-react";
2+
import { ChevronLeftIcon, ChevronRightIcon, ImageIcon, TextIcon, XIcon } from "lucide-react";
33
import { Button } from "../ui/button";
44
import { Dialog, DialogPopup, DialogTitle } from "../ui/dialog";
55
import type { ExpandedImageItem, ExpandedImagePreview } from "./ExpandedImagePreview";
@@ -9,6 +9,13 @@ import { OpenMediaLink } from "../media/OpenMediaLink";
99
import { MediaActions, type MediaActionSource } from "../media/MediaActions";
1010
import { MediaVideoPlayer } from "../media/MediaVideoPlayer";
1111
import { isContextMenuOpen } from "../../contextMenuFallback";
12+
import {
13+
SnapShotAccessibilityData,
14+
SnapShotContentsButton,
15+
snapShotAccessibilityDetails,
16+
} from "./SnapShotAttachmentDetails";
17+
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
18+
import { ZoomableImage, type ZoomableImageHandle } from "./ZoomableImage";
1219
import { composerFloatingLayerProps } from "./composerEventScope";
1320

1421
interface ExpandedImageDialogProps {
@@ -58,6 +65,8 @@ export const ExpandedImageDialog = memo(function ExpandedImageDialog({
5865
}: ExpandedImageDialogProps) {
5966
const [imageOffset, setImageOffset] = useState(0);
6067
const [failedImageSrc, setFailedImageSrc] = useState<string | null>(null);
68+
const [accessibilityDetailsSrc, setAccessibilityDetailsSrc] = useState<string | null>(null);
69+
const zoomableImageRef = useRef<ZoomableImageHandle>(null);
6170
const [returnFocusTarget] = useState(() =>
6271
document.activeElement instanceof HTMLElement ? document.activeElement : null,
6372
);
@@ -101,6 +110,11 @@ export const ExpandedImageDialog = memo(function ExpandedImageDialog({
101110
useEffect(() => {
102111
const onKeyDown = (event: globalThis.KeyboardEvent) => {
103112
if (event.defaultPrevented || isContextMenuOpen()) return;
113+
if (zoomableImageRef.current?.pan(event.key)) {
114+
event.preventDefault();
115+
event.stopPropagation();
116+
return;
117+
}
104118
if (preview.images.length <= 1) return;
105119
if (event.key === "ArrowLeft") {
106120
event.preventDefault();
@@ -134,6 +148,15 @@ export const ExpandedImageDialog = memo(function ExpandedImageDialog({
134148
item.originalUrl && resolveExternalWebLinkHost(item.originalUrl) !== null ? (
135149
<OpenMediaLink originalUrl={item.originalUrl} />
136150
) : null;
151+
const accessibilityDetails = item.source ? snapShotAccessibilityDetails(item.source) : undefined;
152+
const showingAccessibilityDetails =
153+
Boolean(accessibilityDetails) && accessibilityDetailsSrc === item.src;
154+
const contentsLabel = showingAccessibilityDetails
155+
? "Show screenshot"
156+
: accessibilityDetails?.format === "json"
157+
? "Show accessibility JSON"
158+
: "Show extracted text";
159+
const ContentsIcon = showingAccessibilityDetails ? ImageIcon : TextIcon;
137160

138161
return (
139162
<Dialog
@@ -181,6 +204,13 @@ export const ExpandedImageDialog = memo(function ExpandedImageDialog({
181204
</Button>
182205
{item.type === "video" ? (
183206
<ExpandedVideo key={index} item={item} />
207+
) : showingAccessibilityDetails ? (
208+
accessibilityDetails ? (
209+
<SnapShotAccessibilityData
210+
details={accessibilityDetails}
211+
className="h-[min(86vh,40rem)] w-[min(92vw,42rem)] animate-[snap-shot-contents-enter_140ms_ease-out] rounded-lg border border-border/70 bg-background p-4 text-xs leading-5 shadow-2xl motion-reduce:animate-none"
212+
/>
213+
) : null
184214
) : item.src === null || failedImageSrc === item.src ? (
185215
<ExpandedMediaFailure>
186216
<p>
@@ -191,18 +221,47 @@ export const ExpandedImageDialog = memo(function ExpandedImageDialog({
191221
{openOriginalLink}
192222
</ExpandedMediaFailure>
193223
) : (
194-
<img
224+
<ZoomableImage
225+
ref={zoomableImageRef}
226+
key={`${index}:${item.src}`}
195227
src={item.src}
196-
alt={item.name}
197-
className="max-h-[86vh] max-w-[92vw] select-none rounded-lg border border-border/70 bg-background object-contain shadow-2xl"
198-
draggable={false}
228+
name={item.name}
199229
onError={() => setFailedImageSrc(item.src)}
200230
/>
201231
)}
202-
<p className="mt-2 max-w-[92vw] truncate text-center text-xs text-white/90">
203-
{item.name}
204-
{preview.images.length > 1 ? ` (${index + 1}/${preview.images.length})` : ""}
205-
</p>
232+
<div className="mt-2 flex max-w-[92vw] items-center justify-center gap-1.5 text-xs text-white/80">
233+
<span className="truncate">
234+
{item.name}
235+
{preview.images.length > 1 ? ` (${index + 1}/${preview.images.length})` : ""}
236+
</span>
237+
{accessibilityDetails && item.source ? (
238+
<Tooltip>
239+
<TooltipTrigger
240+
render={
241+
<Button
242+
aria-label={contentsLabel}
243+
aria-pressed={showingAccessibilityDetails}
244+
className="[--control-icon-color:currentColor] hover:bg-white/10 hover:text-white"
245+
onClick={() =>
246+
setAccessibilityDetailsSrc(showingAccessibilityDetails ? null : item.src)
247+
}
248+
size="icon-micro"
249+
variant="ghost-muted"
250+
/>
251+
}
252+
>
253+
<ContentsIcon className="size-3" aria-hidden="true" />
254+
</TooltipTrigger>
255+
<TooltipPopup side="top">{contentsLabel}</TooltipPopup>
256+
</Tooltip>
257+
) : item.source ? (
258+
<SnapShotContentsButton
259+
source={item.source}
260+
side="top"
261+
className="hover:bg-white/10 hover:text-white"
262+
/>
263+
) : null}
264+
</div>
206265
</div>
207266
</MediaActions>
208267
{preview.images.length > 1 && (

‎apps/web/src/components/chat/SnapShotAttachmentDetails.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function HighlightedAccessibilityJson({
7272
});
7373
}
7474

75-
function SnapShotAccessibilityData({
75+
export function SnapShotAccessibilityData({
7676
details,
7777
className,
7878
}: {
@@ -125,7 +125,7 @@ export function snapShotIncludesAccessibility(source: SnapShotSource): boolean {
125125
return Boolean(source.accessibility || source.accessibleText?.trim());
126126
}
127127

128-
function SnapShotContentsButton({
128+
export function SnapShotContentsButton({
129129
source,
130130
className,
131131
side = "top",

0 commit comments

Comments
 (0)