AI media harness for planning, generating, and editing locally
TypeScript
Image export: pick the image from the image bar under the stage
Bitti45e4841dc7c2
diff --git a/src/components/ImageProject.integration.test.tsx b/src/components/ImageProject.integration.test.tsxindex 393206b..dcf461b 100644--- a/src/components/ImageProject.integration.test.tsx+++ b/src/components/ImageProject.integration.test.tsx@@ -37,7 +37,9 @@ it("exports the selected image from the Export tab and handles cancellation andconst settings = screen.getByRole("region", { name: "Export settings" });expect(within(settings).getByRole("combobox", { name: "Format" })).toHaveTextContent("JPG");expect(within(settings).getByRole("combobox", { name: "Resolution" })).toHaveTextContent("1024 × 768 (original)");- expect(screen.getByRole("region", { name: "Image preview" })).toContainElement(screen.getByRole("img", { name: /Second/ }));+ const preview = screen.getByRole("region", { name: "Image preview" });+ expect(within(preview.querySelector(".export-screen") as HTMLElement).getByRole("img", { name: /Second/ })).toBeInTheDocument();+ expect(within(screen.getByLabelText("Generated images")).getByRole("button", { name: "View Second" })).toHaveAttribute("aria-pressed", "true");const button = within(settings).getByRole("button", { name: "Export…" });fireEvent.click(button);await waitFor(() => expect(invoke).toHaveBeenCalledWith("export_generated_image", {diff --git a/src/components/workspace/ImageBar.tsx b/src/components/workspace/ImageBar.tsxnew file mode 100644index 0000000..e91bfee--- /dev/null+++ b/src/components/workspace/ImageBar.tsx@@ -0,0 +1,65 @@+import { forwardRef, useEffect, useImperativeHandle, useLayoutEffect, useRef, type KeyboardEvent } from "react";+import type { ProjectAsset } from "../../lib/project";+import { Edit11, Image24 } from "../ui/icons";+import { ReferenceImage } from "./ReferenceImage";+import "../../styles/image-editor.css";++/* The strip of an image project's images along the foot of the Editor and the+ Export tab: one thumbnail per image, the selected one ringed in accent, a+ draft badged. The mouse wheel scrolls it sideways, and a new image scrolls+ into view at the end. `onMenu` opens a context menu for an image (id) or+ for the bar (null) at a point; without it the bar has no menu. */+export const ImageBar = forwardRef<HTMLDivElement | null, {+ images: ProjectAsset[];+ selectedId: string | null | undefined;+ folderPath: string;+ onSelect: (id: string) => void;+ onMenu?: (id: string | null, x: number, y: number) => void;+}>(function ImageBar({ images, selectedId, folderPath, onSelect, onMenu }, ref) {+ const bar = useRef<HTMLDivElement>(null);+ useImperativeHandle(ref, () => bar.current as HTMLDivElement);++ const previousCount = useRef(images.length);+ useLayoutEffect(() => {+ const element = bar.current;+ if (element && images.length > previousCount.current) element.scrollLeft = element.scrollWidth;+ previousCount.current = images.length;+ }, [images.length]);+ useEffect(() => {+ const element = bar.current;+ if (!element) return;+ const wheel = (event: WheelEvent) => {+ if (event.ctrlKey || element.scrollWidth <= element.clientWidth) return;+ event.preventDefault();+ const delta = Math.abs(event.deltaX) > Math.abs(event.deltaY) ? event.deltaX : event.deltaY;+ const unit = event.deltaMode === 1 ? 16 : event.deltaMode === 2 ? element.clientWidth : 1;+ element.scrollLeft += delta * unit;+ };+ element.addEventListener("wheel", wheel, { passive: false });+ return () => element.removeEventListener("wheel", wheel);+ }, [images.length]);++ const menuKey = (event: KeyboardEvent) => event.key === "ContextMenu" || (event.shiftKey && event.key === "F10");++ return <div ref={bar} tabIndex={0} className="image-results" aria-label="Generated images"+ onContextMenu={onMenu && ((event) => { event.preventDefault(); onMenu(null, event.clientX, event.clientY); })}+ onKeyDown={onMenu && ((event) => {+ if (event.target !== event.currentTarget || !menuKey(event)) return;+ event.preventDefault();+ const bounds = event.currentTarget.getBoundingClientRect();+ onMenu(null, bounds.left, bounds.top);+ })}>+ {images.map((asset) => <button key={asset.id} type="button" data-image-asset={asset.id} data-tooltip={asset.name} aria-label={`View ${asset.name}`} aria-pressed={asset.id === selectedId}+ onContextMenu={onMenu && ((event) => { event.preventDefault(); event.stopPropagation(); onMenu(asset.id, event.clientX, event.clientY); })}+ onKeyDown={onMenu && ((event) => {+ if (!menuKey(event)) return;+ event.preventDefault();+ const bounds = event.currentTarget.getBoundingClientRect();+ onMenu(asset.id, bounds.left, bounds.bottom);+ })}+ onClick={() => onSelect(asset.id)}>+ {asset.relativePath || asset.sourcePath ? <ReferenceImage folderPath={folderPath} relativePath={asset.relativePath} sourcePath={asset.sourcePath} alt={asset.name} /> : <Image24 aria-hidden="true" />}+ {asset.imageDraft && <span className="image-draft-badge"><Edit11 aria-hidden="true" />{asset.imageGeneration?.scene.rootType === "image" ? "Editing" : "Draft"}</span>}+ </button>)}+ </div>;+});diff --git a/src/components/workspace/ImageEditor.tsx b/src/components/workspace/ImageEditor.tsxindex 48f5f57..10ea9fa 100644--- a/src/components/workspace/ImageEditor.tsx+++ b/src/components/workspace/ImageEditor.tsx@@ -1,5 +1,5 @@-import { useEffect, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore, type CSSProperties, type DragEvent, type KeyboardEvent as ReactKeyboardEvent, type PointerEvent } from "react";-import { Add14, Add16, Boxes16, Boxes16Filled, ChevronDown14, ChevronRight14, Copy16, Cube16, Cube16Filled, Cursor16, Cursor16Filled, Delete14, Delete16, Edit11, Edit16, FolderAdd16, FolderOpen16, Group16, Group16Filled, Image16, Image24, Image32, Paste16, Rename16, Sparkle16, Stop14, Text16, Text16Filled } from "../ui/icons";+import { useEffect, useId, useMemo, useRef, useState, useSyncExternalStore, type CSSProperties, type DragEvent, type KeyboardEvent as ReactKeyboardEvent, type PointerEvent } from "react";+import { Add14, Add16, Boxes16, Boxes16Filled, ChevronDown14, ChevronRight14, Copy16, Cube16, Cube16Filled, Cursor16, Cursor16Filled, Delete14, Delete16, Edit16, FolderAdd16, FolderOpen16, Group16, Group16Filled, Image16, Image32, Paste16, Rename16, Sparkle16, Stop14, Text16, Text16Filled } from "../ui/icons";import { invoke } from "@tauri-apps/api/core";import { addImageNode, createImageEditScene, createImageScene, duplicateImageNode, imageDescendants, imageScenePrompt, removeImageNode, resizeImageNode, type ImageBox, type ImageNode, type ImageScene, type ImageSource } from "../../lib/imageScene";import { compileImageEdits, editGeneratedImage, imageEditDebugPrompt } from "../../lib/imageEditing";@@ -12,6 +12,7 @@ import { defaultGeneratorTemplate, loadDebugOptionsEnabled, loadGeneratorTemplatimport { isWorkActive, type WorkItem } from "../../lib/workQueue";import type { ConfigUpdate } from "./TimelineView";import { ReferenceImage } from "./ReferenceImage";+import { ImageBar } from "./ImageBar";import { DebugPromptDialog } from "./DebugPromptDialog";import { TagEditor } from "./TagEditor";import styleSuggestions from "../../lib/imageStyleSuggestions.json";@@ -118,25 +119,6 @@ export function ImageEditor({ config, folderPath, onChange: changeConfig, onGeneconst active = work && isWorkActive(work);const output = config.assets.find((asset) => asset.id === scene.outputAssetId);const images = config.assets.filter((asset) => asset.kind === "image");- const previousImageCount = useRef(images.length);- useLayoutEffect(() => {- const bar = imageResults.current;- if (bar && images.length > previousImageCount.current) bar.scrollLeft = bar.scrollWidth;- previousImageCount.current = images.length;- }, [images.length]);- useEffect(() => {- const element = imageResults.current;- if (!element) return;- const wheel = (event: WheelEvent) => {- if (event.ctrlKey || element.scrollWidth <= element.clientWidth) return;- event.preventDefault();- const delta = Math.abs(event.deltaX) > Math.abs(event.deltaY) ? event.deltaX : event.deltaY;- const unit = event.deltaMode === 1 ? 16 : event.deltaMode === 2 ? element.clientWidth : 1;- element.scrollLeft += delta * unit;- };- element.addEventListener("wheel", wheel, { passive: false });- return () => element.removeEventListener("wheel", wheel);- }, [images.length]);// Generated assets retain the dimensions returned by the native encoder.// Project settings size only the empty canvas and future generation requests.const { width, height } = imageRoot && scene.sourceImage ? scene.sourceImage : output?.width && output?.height@@ -553,20 +535,8 @@ export function ImageEditor({ config, folderPath, onChange: changeConfig, onGene</div></div>{(error || work?.error) && <InfoBar className="image-error" severity="error" title="Couldn’t update the image" message={error ?? work?.error ?? ""} onClose={error ? () => setError(null) : undefined} />}<div className="image-status" role="status">{active && <ProgressBar value={work.progress * 100} aria-label="Image generation progress" />}<span>{active ? work.detail : imageRoot ? editPlan?.error ?? `${width} × ${height} · ${editPlan?.edits.length} edits in hierarchy order` : !isTauri() ? "Image generation is available in the desktop app." : `${width} × ${height} · Placement boxes guide the prompt`}</span></div>- <div ref={imageResults} tabIndex={0} className="image-results" aria-label="Generated images" onContextMenu={(event) => { event.preventDefault(); setContextMenu(null); setImageMenu({ id: null, x: event.clientX, y: event.clientY }); }} onKeyDown={(event) => {- if (event.target === event.currentTarget && (event.key === "ContextMenu" || event.shiftKey && event.key === "F10")) {- event.preventDefault(); const bounds = event.currentTarget.getBoundingClientRect(); setContextMenu(null); setImageMenu({ id: null, x: bounds.left, y: bounds.top });- }- }}>{images.map((asset) => <button key={asset.id} data-image-asset={asset.id} data-tooltip={asset.name} aria-label={`View ${asset.name}`} aria-pressed={asset.id === scene.outputAssetId}- onContextMenu={(event) => { event.preventDefault(); event.stopPropagation(); setContextMenu(null); setImageMenu({ id: asset.id, x: event.clientX, y: event.clientY }); }}- onKeyDown={(event) => {- if (event.key === "ContextMenu" || (event.shiftKey && event.key === "F10")) {- event.preventDefault();- const bounds = event.currentTarget.getBoundingClientRect();- setContextMenu(null); setImageMenu({ id: asset.id, x: bounds.left, y: bounds.bottom });- }- }}- onClick={() => selectImage(asset.id)}>{asset.relativePath || asset.sourcePath ? <ReferenceImage folderPath={folderPath} relativePath={asset.relativePath} sourcePath={asset.sourcePath} alt={asset.name} /> : <Image24 aria-hidden="true" />}{asset.imageDraft && <span className="image-draft-badge"><Edit11 aria-hidden="true" />{asset.imageGeneration?.scene.rootType === "image" ? "Editing" : "Draft"}</span>}</button>)}</div>+ <ImageBar ref={imageResults} images={images} selectedId={scene.outputAssetId} folderPath={folderPath} onSelect={selectImage}+ onMenu={(id, x, y) => { setContextMenu(null); setImageMenu({ id, x, y }); }} /></section><Splitter {...inspectorPane.splitterProps} reverse aria-label="Resize inspector" /><aside className="image-inspector" aria-label="Image node inspector">diff --git a/src/components/workspace/ImageExportView.test.tsx b/src/components/workspace/ImageExportView.test.tsxindex 4017b12..f803800 100644--- a/src/components/workspace/ImageExportView.test.tsx+++ b/src/components/workspace/ImageExportView.test.tsx@@ -58,3 +58,20 @@ it("sends the chosen size, format and JPG quality, and hides quality for PNG", afireEvent.click(screen.getByRole("option", { name: /PNG/ }));expect(screen.queryByRole("slider", { name: "JPG quality" })).toBeNull();});++it("shows the image bar and exports the image picked in it, leaving the Editor's image alone", async () => {+ vi.spyOn(persistence, "isTauri").mockReturnValue(true);+ vi.spyOn(persistence, "readMediaFileUrl").mockResolvedValue(null);+ vi.mocked(invoke).mockResolvedValue(true);+ const config = withOutput({ width: 2048, height: 1152 });+ config.assets.push({ id: "second", name: "Second", kind: "image", relativePath: "media/generated/second.jpg", mimeType: "image/jpeg", width: 1024, height: 576, createdAt: config.createdAt } as ProjectConfig["assets"][number]);+ render(<ImageExportView config={config} folderPath="D:/Images" />);+ const bar = screen.getByLabelText("Generated images");+ expect(within(bar).getByRole("button", { name: "View Out" })).toHaveAttribute("aria-pressed", "true");+ fireEvent.click(within(bar).getByRole("button", { name: "View Second" }));+ expect(within(bar).getByRole("button", { name: "View Second" })).toHaveAttribute("aria-pressed", "true");+ expect(screen.getByRole("combobox", { name: "Resolution" })).toHaveTextContent("1024 × 576 (original)");+ fireEvent.click(screen.getByRole("button", { name: "Export…" }));+ await waitFor(() => expect(invoke).toHaveBeenCalledWith("export_generated_image", expect.objectContaining({ relativePath: "media/generated/second.jpg" })));+ expect(config.imageScene!.outputAssetId).toBe("out");+});diff --git a/src/components/workspace/ImageExportView.tsx b/src/components/workspace/ImageExportView.tsxindex 065afcc..78d9008 100644--- a/src/components/workspace/ImageExportView.tsx+++ b/src/components/workspace/ImageExportView.tsx@@ -5,6 +5,7 @@ import { PROJECT_RESOLUTIONS, type ProjectConfig } from "../../lib/project";import { isTauri } from "../../lib/persistence";import { ComboBox, EmptyState, InfoBar, PropRow, PropSection, Slider, Splitter, tooltipProps, usePaneSize } from "../ui";import { Image32 } from "../ui/icons";+import { ImageBar } from "./ImageBar";import { ReferenceImage } from "./ReferenceImage";/* The image project's Export tab: the same page as the video export (see@@ -12,7 +13,7 @@ import { ReferenceImage } from "./ReferenceImage";pane on the right opening straight on its first section, with Export… pinnedat its foot. Output sets the size (the image's own, or a rung of the projectladder at its aspect), the format and, for JPG, the quality; Export… then- asks where to save. Format and quality are remembered across projects. */+ asks where to save. The image bar under the stage picks which image. Format and quality are remembered across projects. */type ImageFormat = "jpg" | "png";const STORAGE_KEY = "slopus.image-export.v1";@@ -31,7 +32,11 @@ export function ImageExportView({ config, folderPath }: { config: ProjectConfig;const settingsPane = usePaneSize("export.settings", 340, { min: 280, max: 560 });const [exporting, setExporting] = useState(false);const [error, setError] = useState<string | null>(null);- const output = config.assets.find((asset) => asset.kind === "image" && asset.id === config.imageScene?.outputAssetId);+ /* Which image to export is this page's own choice: it starts on the one open+ in the Editor, and picking another here leaves the Editor where it was. */+ const images = config.assets.filter((asset) => asset.kind === "image");+ const [chosenId, setChosenId] = useState<string | null>(null);+ const output = images.find((asset) => asset.id === chosenId) ?? images.find((asset) => asset.id === config.imageScene?.outputAssetId);const draft = Boolean(output?.imageDraft);const desktop = isTauri();@@ -86,6 +91,7 @@ export function ImageExportView({ config, folderPath }: { config: ProjectConfig;: <EmptyState className="export-empty" icon={<Image32 />} title={draft ? "The image is a draft" : "No image to export yet"} description={blocker ?? undefined} />}</div></div>+ {images.length > 0 && <ImageBar images={images} selectedId={output?.id} folderPath={folderPath} onSelect={(id) => { setChosenId(id); setError(null); }} />}</section><Splitter {...settingsPane.splitterProps} reverse aria-label="Resize export settings" aria-controls="image-export-settings" />diff --git a/src/styles/export.css b/src/styles/export.cssindex f7b3fbf..b0de931 100644--- a/src/styles/export.css+++ b/src/styles/export.css@@ -46,6 +46,13 @@background: var(--surface-stage);}+/* An image project's image bar runs under the stage, on chrome, where the+ video export has its transport bar. */+.export-preview > .image-results {+ flex: none;+ background: var(--surface-chrome);+}+/* The stage is the screen plus its transport bar. It is also the element thatgoes fullscreen, so the bar comes along. */.export-stage {