import { useState, type CSSProperties } from "react"; import { Spinner } from "@tutti-os/ui-system"; import { ImageIcon, X } from "lucide-react"; import { ZoomableImage } from "../../../app/renderer/components/ZoomableImage"; import { cn } from "../../../app/renderer/lib/utils"; import type { AgentComposerDraftImage } from "../model/agentGuiNodeTypes"; import { DRAFT_IMAGE_PREVIEW_BASE_HEIGHT_PX, DRAFT_IMAGE_PREVIEW_MAX_RATIO, DRAFT_IMAGE_PREVIEW_MAX_WIDTH_PX, DRAFT_IMAGE_PREVIEW_MIN_RATIO, DRAFT_IMAGE_PREVIEW_MIN_WIDTH_PX } from "./AgentComposerChrome"; export function AgentComposerDraftImagePreview({ image, removeLabel, onRemove }: { image: AgentComposerDraftImage; removeLabel: string; onRemove: (id: string) => void; }): React.JSX.Element { const [aspectRatio, setAspectRatio] = useState(1); const previewWidth = Math.round( Math.min( DRAFT_IMAGE_PREVIEW_MAX_WIDTH_PX, Math.max( DRAFT_IMAGE_PREVIEW_MIN_WIDTH_PX, aspectRatio * DRAFT_IMAGE_PREVIEW_BASE_HEIGHT_PX ) ) ); const previewStyle = { aspectRatio: String(aspectRatio), width: `${previewWidth}px` } satisfies CSSProperties; return (
[data-rmiz]]:block [&>[data-rmiz]]:size-full", "[&>[data-rmiz]>[data-rmiz-content]]:block [&>[data-rmiz]>[data-rmiz-content]]:size-full", image.uploadError && "border-[color:color-mix(in_srgb,var(--danger)_55%,var(--line-1))]" )} data-testid="agent-gui-composer-image-draft" data-uploading={image.uploading ? "true" : undefined} data-upload-error={image.uploadError ? "true" : undefined} style={previewStyle} > {image.previewUrl ? ( { const element = event.currentTarget; const width = element.naturalWidth; const height = element.naturalHeight; if (width <= 0 || height <= 0) { return; } const nextRatio = Math.min( DRAFT_IMAGE_PREVIEW_MAX_RATIO, Math.max(DRAFT_IMAGE_PREVIEW_MIN_RATIO, width / height) ); setAspectRatio(nextRatio); }} /> ) : (
)} {image.uploading ? (
) : null}
); } export function SendFilledIcon(): React.JSX.Element { "use memo"; return ( ); }