11import { 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" ;
33import { Button } from "../ui/button" ;
44import { Dialog , DialogPopup , DialogTitle } from "../ui/dialog" ;
55import type { ExpandedImageItem , ExpandedImagePreview } from "./ExpandedImagePreview" ;
@@ -9,6 +9,13 @@ import { OpenMediaLink } from "../media/OpenMediaLink";
99import { MediaActions , type MediaActionSource } from "../media/MediaActions" ;
1010import { MediaVideoPlayer } from "../media/MediaVideoPlayer" ;
1111import { 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" ;
1219import { composerFloatingLayerProps } from "./composerEventScope" ;
1320
1421interface 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 && (
0 commit comments