Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Image projects export from an Export tab, not a title-bar button

Bittid8dc64a3745b
diff --git a/src/components/ImageProject.integration.test.tsx b/src/components/ImageProject.integration.test.tsx
index efaa875..8e58e14 100644
--- a/src/components/ImageProject.integration.test.tsx
+++ b/src/components/ImageProject.integration.test.tsx
@@ -17,11 +17,11 @@ vi.mock("@tauri-apps/api/event", () => ({ listen: vi.fn(async () => () => undefi
afterEach(() => { cleanup(); localStorage.clear(); vi.restoreAllMocks(); });
const record = (): ProjectRecord => ({ folderPath: "D:/Images", config: parseProjectConfig(fixture) });
-it("exports the selected image from beside Save and handles cancellation and errors", async () => {
+it("exports the selected image from the Export tab and handles cancellation and errors", async () => {
vi.spyOn(persistence, "isTauri").mockReturnValue(true);
vi.spyOn(persistence, "readMediaFileUrl").mockResolvedValue(null);
const project = record();
- project.config.assets = ["First", "Second"].map((name) => ({ id: name, name, kind: "image", relativePath: `media/generated/${name}.jpg`, mimeType: "image/jpeg", createdAt: project.config.createdAt }));
+ project.config.assets = ["First", "Second"].map((name) => ({ id: name, name, kind: "image", relativePath: `media/generated/${name}.jpg`, mimeType: "image/jpeg", width: 1024, height: 768, createdAt: project.config.createdAt }));
project.config.imageScene!.outputAssetId = "First";
let complete!: (value: boolean) => void;
const exporting = new Promise<boolean>((resolve) => { complete = resolve; });
@@ -30,25 +30,50 @@ it("exports the selected image from beside Save and handles cancellation and err
return undefined as never;
});
render(<ProjectWorkspace project={project} onBack={vi.fn()} onSave={vi.fn()} />);
- const button = screen.getByRole("button", { name: "Export" });
- expect(button.parentElement).toContainElement(screen.getByRole("button", { name: "Save" }));
- expect(screen.queryByRole("button", { name: "Export image" })).not.toBeInTheDocument();
+ // No title-bar Export button any more: only Save sits among the commands.
+ expect(screen.queryByRole("button", { name: /^Export/ })).not.toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "View Second" }));
+ fireEvent.click(within(screen.getByRole("tablist", { name: "Project views" })).getByRole("tab", { name: /Export/ }));
+ const settings = screen.getByRole("region", { name: "Export settings" });
+ expect(within(settings).getByText("JPG or PNG, chosen when saving")).toBeInTheDocument();
+ expect(within(settings).getByText("1024 × 768 px")).toBeInTheDocument();
+ expect(screen.getByRole("region", { name: "Image preview" })).toContainElement(screen.getByRole("img", { name: /Second/ }));
+ const button = within(settings).getByRole("button", { name: "Export…" });
fireEvent.click(button);
await waitFor(() => expect(invoke).toHaveBeenCalledWith("export_generated_image", { folderPath: "D:/Images", relativePath: "media/generated/Second.jpg" }));
- expect(screen.getByRole("button", { name: "Exporting…" })).toBeDisabled();
+ expect(within(settings).getByRole("button", { name: "Exporting…" })).toBeDisabled();
await act(async () => complete(false));
expect(button).toBeEnabled();
+ expect(button).toHaveTextContent("Export…");
expect(screen.queryByText("Couldn’t export image")).not.toBeInTheDocument();
vi.mocked(invoke).mockRejectedValueOnce("Destination is not writable");
fireEvent.click(button);
- expect(await screen.findByText("Destination is not writable")).toBeInTheDocument();
+ expect(await within(settings).findByText("Destination is not writable")).toBeInTheDocument();
+ expect(within(settings).getByText("Couldn’t export image")).toBeInTheDocument();
expect(button).toBeEnabled();
});
-it("disables image export until a generated image is selected", () => {
+it("disables image export until a generated image is selected, and says why", () => {
+ vi.spyOn(persistence, "isTauri").mockReturnValue(true);
render(<ProjectWorkspace project={record()} onBack={vi.fn()} onSave={vi.fn()} />);
- expect(screen.getByRole("button", { name: "Export" })).toBeDisabled();
+ fireEvent.keyDown(document.body, { key: "e", code: "KeyE", ctrlKey: true });
+ expect(within(screen.getByRole("tablist", { name: "Project views" })).getByRole("tab", { name: /Export/ })).toHaveAttribute("aria-selected", "true");
+ const button = screen.getByRole("button", { name: "Export…" });
+ expect(button).toBeDisabled();
+ expect(button).toHaveAttribute("data-tooltip", "Generate an image in the Editor first.");
+ expect(screen.getByText("No image to export yet")).toBeInTheDocument();
+});
+
+it("disables image export outside the desktop app", () => {
+ vi.spyOn(persistence, "isTauri").mockReturnValue(false);
+ vi.spyOn(persistence, "readMediaFileUrl").mockResolvedValue(null);
+ const project = record();
+ project.config.assets = [{ id: "Only", name: "Only", kind: "image", relativePath: "media/generated/Only.jpg", mimeType: "image/jpeg", createdAt: project.config.createdAt }];
+ project.config.imageScene!.outputAssetId = "Only";
+ render(<ProjectWorkspace project={project} initialView="export" onBack={vi.fn()} onSave={vi.fn()} />);
+ expect(screen.getByRole("button", { name: "Export…" })).toBeDisabled();
+ expect(screen.getAllByText("Exporting is available in the Slopus desktop app.").length).toBeGreaterThan(0);
+ expect(screen.queryByText(/ × .* px/)).not.toBeInTheDocument();
});
it("shows the full image prompt at the end of the inspector only when debug is enabled", () => {
@@ -101,7 +126,7 @@ it("opens the three-tab image workspace and saves hierarchy/inspector edits thro
const save = vi.fn(async () => undefined);
render(<ProjectWorkspace project={record()} onBack={vi.fn()} onSave={save} />);
const navigation = within(screen.getByRole("tablist", { name: "Project views" }));
- expect(navigation.getAllByRole("tab").map((tab) => tab.textContent)).toEqual(["Editor", "References"]);
+ expect(navigation.getAllByRole("tab").map((tab) => tab.textContent)).toEqual(["Editor", "References", "Export"]);
fireEvent.contextMenu(screen.getByRole("button", { name: "Image" }));
fireEvent.click(screen.getByRole("menuitem", { name: "New Text" }));
fireEvent.change(screen.getByLabelText("Text to render"), { target: { value: "Hello world" } });
@@ -115,6 +140,9 @@ it("opens the three-tab image workspace and saves hierarchy/inspector edits thro
fireEvent.click(navigation.getByRole("tab", { name: /References/ }));
fireEvent.click(navigation.getByRole("tab", { name: /Editor/ }));
expect(screen.getByRole("tree", { name: "Image nodes" })).toBeInTheDocument();
+ fireEvent.keyDown(document.body, { key: "3", code: "Digit3", ctrlKey: true });
+ expect(navigation.getByRole("tab", { name: /Export/ })).toHaveAttribute("aria-selected", "true");
+ expect(screen.getByRole("region", { name: "Image preview" })).toBeInTheDocument();
});
it("keeps the video tabs and applies image agent commands without changing generated output", async () => {
diff --git a/src/components/ProjectWorkspace.tsx b/src/components/ProjectWorkspace.tsx
index 780aa97..3f25e77 100644
--- a/src/components/ProjectWorkspace.tsx
+++ b/src/components/ProjectWorkspace.tsx
@@ -8,6 +8,7 @@ import { WorkQueue, projectQueueKey } from "../lib/workQueue";
import { useShortcut } from "../lib/commands";
import { AgentDock } from "./workspace/AgentDock";
import { ExportView } from "./workspace/ExportView";
+import { ImageExportView } from "./workspace/ImageExportView";
import { GeneratorView } from "./workspace/GeneratorView";
import { ReferencesView } from "./workspace/ReferencesView";
import { TimelineView, type ConfigUpdate } from "./workspace/TimelineView";
@@ -17,8 +18,6 @@ import { TitleBar } from "./TitleBar";
import { InfoBadge, InfoBar, SelectorBar, Splitter, StatusBar, tooltipProps, usePaneSize } from "./ui";
import { ProjectStatusSlot } from "./workspace/ProjectStatus";
import { outputDimensions, videoDurationMs } from "../lib/export";
-import { invoke } from "@tauri-apps/api/core";
-import { isTauri } from "../lib/persistence";
/** "agent" is not a view any more — the agent is a docked pane — but opening
* a project "on the agent" still means something: the pane opens with it. */
@@ -130,11 +129,8 @@ export function ProjectWorkspace({ project, initialView = "timeline", runtime =
const { config, saving, dirty, saveError, canUndo, canRedo, savedAt } = useSyncExternalStore(session.subscribe, session.getSnapshot);
const items = useSyncExternalStore(queue.subscribe, queue.getSnapshot);
const imageProject = config.generationType === "image";
- const imageOutput = config.assets.find((asset) => asset.kind === "image" && asset.id === config.imageScene?.outputAssetId);
- const [exportingImage, setExportingImage] = useState(false);
- const [imageExportError, setImageExportError] = useState<string | null>(null);
const [view, setView] = useState<ShownView>(() => {
- if (imageProject) return initialView === "references" ? "references" : "editor";
+ if (imageProject) return initialView === "references" || initialView === "export" ? initialView : "editor";
return initialView === "agent" || initialView === "editor" ? "timeline" : initialView;
});
const [agentOpen, setAgentOpenState] = useState(() => initialView === "agent" || readAgentPane());
@@ -167,14 +163,6 @@ export function ProjectWorkspace({ project, initialView = "timeline", runtime =
const changeConfig = (next: ConfigUpdate, key?: string) => session.edit(next, key);
const recordMeasurement = (update: (current: ProjectConfig) => ProjectConfig) => session.update(update, false);
const save = () => session.save().catch(() => undefined);
- const exportImage = async () => {
- if (!imageOutput?.relativePath || exportingImage) return;
- setExportingImage(true); setImageExportError(null);
- try { await invoke("export_generated_image", { folderPath: project.folderPath, relativePath: imageOutput.relativePath }); }
- catch (reason) { setImageExportError(String(reason)); }
- finally { setExportingImage(false); }
- };
- const imageExportDisabled = !imageOutput?.relativePath || Boolean(imageOutput.imageDraft) || !isTauri() || exportingImage;
const leave = async (keepChanges: boolean) => {
setSavingToLeave(true);
try {
@@ -201,7 +189,7 @@ export function ProjectWorkspace({ project, initialView = "timeline", runtime =
const lengthMs = useMemo(() => videoDurationMs(config), [config]);
const sequenceFormat = `${frameWidth}×${frameHeight} · ${config.settings.frameRate} fps · ${formatSequenceLength(lengthMs)}`;
- const views: ShownView[] = imageProject ? ["editor", "references"] : ["timeline", "generator", "references", "export"];
+ const views: ShownView[] = imageProject ? ["editor", "references", "export"] : ["timeline", "generator", "references", "export"];
const running = config.generationJobs.filter(isGenerationOngoing).length;
const toggleAgent = () => {
const open = !agentOpen;
@@ -220,7 +208,7 @@ export function ProjectWorkspace({ project, initialView = "timeline", runtime =
if (!next) return false;
setView(next);
}, { enabled: idle, allowInInput: true });
- useShortcut("Ctrl+E", () => { if (imageProject) { if (!imageExportDisabled) void exportImage(); } else setView("export"); }, { enabled: idle, allowInInput: true });
+ useShortcut("Ctrl+E", () => { setView("export"); }, { enabled: idle, allowInInput: true });
useShortcut("Ctrl+Shift+A", toggleAgent, { enabled: idle, allowInInput: true });
useShortcut("Alt+ArrowLeft", goBack, { enabled: idle });
@@ -256,11 +244,6 @@ export function ProjectWorkspace({ project, initialView = "timeline", runtime =
<button type="button" className="icon-button" disabled={!canRedo} onClick={() => session.redo()} aria-label="Redo" data-tooltip="Redo" data-tooltip-shortcut="Ctrl+Y" aria-keyshortcuts="Control+Y Control+Shift+Z"><Redo16 /></button>
<span className="titlebar-separator" aria-hidden="true" />
<div className="project-commands">
- {imageProject && (
- <button type="button" className="secondary-button" disabled={imageExportDisabled} onClick={() => void exportImage()} data-tooltip="Save the image as JPG or PNG" data-tooltip-shortcut="Ctrl+E">
- <Download16 aria-hidden="true" /> {exportingImage ? "Exporting…" : "Export"}
- </button>
- )}
{/* The standing "All changes saved" pill is gone; the button itself is
the save state. Off means the file on disk already matches what is
on screen. */}
@@ -289,9 +272,8 @@ export function ProjectWorkspace({ project, initialView = "timeline", runtime =
/>
</TitleBar>
- {(saveError || imageExportError) && <div className="project-infobars">
- {saveError && !editingProject && !leaving && <InfoBar severity="error" title="Couldn’t save project" message={saveError} onClose={session.dismissError} />}
- {imageExportError && <InfoBar severity="error" title="Couldn’t export image" message={imageExportError} onClose={() => setImageExportError(null)} />}
+ {saveError && <div className="project-infobars">
+ {!editingProject && !leaving && <InfoBar severity="error" title="Couldn’t save project" message={saveError} onClose={session.dismissError} />}
</div>}
<ProjectStatusSlot.Provider value={statusSlot}>
@@ -301,7 +283,9 @@ export function ProjectWorkspace({ project, initialView = "timeline", runtime =
{view === "timeline" && <TimelineView config={config} openSceneId={selectedGenerationJobId} folderPath={project.folderPath} generationCompletionTimes={generationCompletionTimes} onChange={changeConfig} onMeasured={recordMeasurement} onOpenGenerator={(jobId) => { setSelectedGenerationJobId(jobId); setView(imageProject ? "editor" : "generator"); }} />}
{view === "generator" && <GeneratorView onGenerate={(submissions) => queue.enqueue(session, submissions)} onCancelGeneration={(ids) => queue.cancelScenes(session, ids)} cancellingJobIds={cancellingJobIds} config={config} folderPath={project.folderPath} generationCompletionTimes={generationCompletionTimes} runtime={runtime?.slopfab ?? null} onRuntimeChange={onGeneratorRuntimeChange} onChange={changeConfig} selectedJobId={selectedGenerationJobId} onSelectedJobChange={setSelectedGenerationJobId} onOpenTimeline={() => setView("timeline")} />}
{view === "references" && <ReferencesView config={config} folderPath={project.folderPath} onChange={changeConfig} onRegenerateIcon={(id) => queue.regenerateReferenceIcon(session, id)} onGenerateBuiltinIcons={() => queue.generateBuiltinReferenceIcons(session)} onRegenerateBuiltinIcon={(id) => queue.regenerateBuiltinReferenceIcon(session, id)} pendingBuiltinIconIds={queue.pendingBuiltinIconIds()} pendingIconIds={new Set(config.references.filter((reference) => queue.isReferenceIconPending(session, reference.id)).map((reference) => reference.id))} onOpenGenerator={(jobId) => { setSelectedGenerationJobId(jobId); setView("generator"); }} />}
- {view === "export" && <ExportView config={config} folderPath={project.folderPath} onClose={() => setView("timeline")} />}
+ {view === "export" && (imageProject
+ ? <ImageExportView config={config} folderPath={project.folderPath} />
+ : <ExportView config={config} folderPath={project.folderPath} onClose={() => setView("timeline")} />)}
</div>
{agentOpen && <Splitter {...agentPane.splitterProps} reverse aria-label="Resize agent pane" aria-controls={`${panelId}-agent`} />}
{/* Kept mounted while hidden, so a running turn and the conversation