({
imageUri,
imagePath,
alt = "Generated image",
showControls = true,
className = "",
}: ImageViewerProps)
| 21 | } |
| 22 | |
| 23 | export function ImageViewer({ |
| 24 | imageUri, |
| 25 | imagePath, |
| 26 | alt = "Generated image", |
| 27 | showControls = true, |
| 28 | className = "", |
| 29 | }: ImageViewerProps) { |
| 30 | const [showModal, setShowModal] = useState(false) |
| 31 | const [zoomLevel, setZoomLevel] = useState(1) |
| 32 | const [copyFeedback, setCopyFeedback] = useState(false) |
| 33 | const [isHovering, setIsHovering] = useState(false) |
| 34 | const [isDragging, setIsDragging] = useState(false) |
| 35 | const [dragPosition, setDragPosition] = useState({ x: 0, y: 0 }) |
| 36 | const [imageError, setImageError] = useState<string | null>(null) |
| 37 | const { copyWithFeedback } = useCopyToClipboard() |
| 38 | const { t } = useAppTranslation() |
| 39 | |
| 40 | /** |
| 41 | * Opens a modal with the image for zooming |
| 42 | */ |
| 43 | const handleZoom = async (e: React.MouseEvent) => { |
| 44 | e.stopPropagation() |
| 45 | setShowModal(true) |
| 46 | setZoomLevel(1) |
| 47 | setDragPosition({ x: 0, y: 0 }) |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Copies the image path to clipboard |
| 52 | */ |
| 53 | const handleCopy = async (e: React.MouseEvent) => { |
| 54 | e.stopPropagation() |
| 55 | |
| 56 | try { |
| 57 | // Copy the file path if available |
| 58 | if (imagePath) { |
| 59 | await copyWithFeedback(imagePath, e) |
| 60 | // Show feedback |
| 61 | setCopyFeedback(true) |
| 62 | setTimeout(() => setCopyFeedback(false), 2000) |
| 63 | } |
| 64 | } catch (err) { |
| 65 | console.error("Error copying:", err instanceof Error ? err.message : String(err)) |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Saves the image as a file |
| 71 | */ |
| 72 | const handleSave = async (e: React.MouseEvent) => { |
| 73 | e.stopPropagation() |
| 74 | |
| 75 | try { |
| 76 | // Request VSCode to save the image |
| 77 | vscode.postMessage({ |
| 78 | type: "saveImage", |
| 79 | dataUri: imageUri, |
| 80 | }) |
nothing calls this directly
no test coverage detected