Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Expand still image toolbar

Bittia14187c40588
diff --git a/src/components/ImageProject.integration.test.tsx b/src/components/ImageProject.integration.test.tsx
index c6550bc..6d52741 100644
--- a/src/components/ImageProject.integration.test.tsx
+++ b/src/components/ImageProject.integration.test.tsx
@@ -62,28 +62,29 @@ it.each([false, true])("scopes generation controls to each image and queues othe
const queue = new WorkQueue(vi.fn(async (record) => record));
render(<ProjectWorkspace project={project} workQueue={queue} onBack={vi.fn()} onSave={vi.fn()} />);
const panel = within(screen.getByRole("region", { name: "Image panel" }));
- fireEvent.click(panel.getByRole("button", { name: "Generate" }));
+ const toolbar = within(screen.getByRole("toolbar", { name: "Image tools" }));
+ fireEvent.click(toolbar.getByRole("button", { name: "Generate" }));
await waitFor(() => expect(enqueue).toHaveBeenCalledOnce());
- expect(panel.getByRole("button", { name: "Cancel" })).toBeEnabled();
+ expect(toolbar.getByRole("button", { name: "Cancel" })).toBeEnabled();
fireEvent.click(screen.getByRole("button", { name: "View Second" }));
- expect(panel.queryByRole("button", { name: "Cancel" })).not.toBeInTheDocument();
- expect(panel.getByRole("combobox", { name: "Generator" })).toBeEnabled();
- fireEvent.click(panel.getByRole("button", { name: "Generate" }));
+ expect(toolbar.queryByRole("button", { name: "Cancel" })).not.toBeInTheDocument();
+ expect(toolbar.getByRole("combobox", { name: "Generator" })).toBeEnabled();
+ fireEvent.click(toolbar.getByRole("button", { name: "Generate" }));
expect(queue.getSnapshot().map((item) => [item.imageAssetId, item.status])).toEqual([["First", "generating"], ["Second", "queued"]]);
expect(enqueue).toHaveBeenCalledOnce();
fireEvent.click(screen.getByRole("button", { name: "View Third" }));
- expect(panel.getByRole("button", { name: "Generate" })).toBeEnabled();
+ expect(toolbar.getByRole("button", { name: "Generate" })).toBeEnabled();
expect(panel.queryByRole("progressbar")).not.toBeInTheDocument();
fireEvent.contextMenu(screen.getByRole("button", { name: "View First" }));
expect(screen.getByRole("menuitem", { name: "Remove" })).toBeDisabled();
fireEvent.keyDown(screen.getByRole("menu", { name: "Generated image actions" }), { key: "Escape" });
fireEvent.click(screen.getByRole("button", { name: "View First" }));
- fireEvent.click(panel.getByRole("button", { name: "Cancel" }));
+ fireEvent.click(toolbar.getByRole("button", { name: "Cancel" }));
await waitFor(() => expect(cancel).toHaveBeenCalledWith(queue.getSnapshot()[0].id));
fireEvent.click(screen.getByRole("button", { name: "View Second" }));
- fireEvent.click(panel.getByRole("button", { name: "Cancel" }));
+ fireEvent.click(toolbar.getByRole("button", { name: "Cancel" }));
expect(queue.getSnapshot()[1].status).toBe("cancelled");
- expect(panel.getByRole("button", { name: "Generate" })).toBeEnabled();
+ expect(toolbar.getByRole("button", { name: "Generate" })).toBeEnabled();
});
it("exports the selected image from the Export tab and handles cancellation and errors", async () => {
diff --git a/src/components/workspace/ImageEditor.tsx b/src/components/workspace/ImageEditor.tsx
index 6e54e25..b71d6ce 100644
--- a/src/components/workspace/ImageEditor.tsx
+++ b/src/components/workspace/ImageEditor.tsx
@@ -486,6 +486,59 @@ export function ImageEditor({ config, folderPath, onChange: changeConfig, onGene
const missingReference = (id: string) => config.references.find((reference) => reference.id === id)?.name ?? "Deleted reference";
return <div ref={editorRoot} className="image-editor" style={{ ...treePane.style, ...inspectorPane.style }}>
+ <div className="image-canvas-tools" role="toolbar" aria-label="Image tools">
+ {/* Three columns: Generate and the generator lead, the canvas tools
+ sit in the middle, the view controls at the trailing edge. */}
+ <div className="image-tools__start">
+ <button className="primary-button image-generate-button" data-tooltip={editPlan?.error ?? undefined} disabled={active ? work.cancelling || work.status === "encoding" : !isTauri() || !template || !templateUsable(template) || (imageRoot ? Boolean(editPlan?.error) : !imageScenePrompt(scene))} onClick={() => attempt(() => active ? onCancel(work.id) : onGenerate(template!))}>{active ? <Stop14 aria-hidden="true" /> : <Sparkle16 aria-hidden="true" />}{active ? work.cancelling ? "Cancelling…" : "Cancel" : "Generate"}</button>
+ <ComboBox
+ className="image-generator"
+ aria-label="Generator"
+ data-tooltip="Generator"
+ value={template?.id ?? ""}
+ disabled={Boolean(active) || !imageTemplates.length}
+ placeholder="No MiniMax H3 templates"
+ options={imageTemplates.map((item) => ({ value: item.id, label: item.name, disabled: !templateUsable(item), description: !templateUsable(item) ? "Download in Settings" : undefined }))}
+ onChange={(id) => { setTemplateId(id); localStorage.setItem("slopus.image-generator-template.v1", id); const next = imageTemplates.find((candidate) => candidate.id === id); if (next) commit({ ...scene, steps: next.defaultSteps }); }}
+ />
+ </div>
+ <div className="image-tools__group" role="radiogroup" aria-label="Canvas tool" onKeyDown={(event) => {
+ if (event.key !== "ArrowLeft" && event.key !== "ArrowRight") return;
+ event.preventDefault();
+ const at = TOOLS.findIndex((tool) => tool.id === drawKind);
+ const next = TOOLS[(at + (event.key === "ArrowRight" ? 1 : -1) + TOOLS.length) % TOOLS.length];
+ chooseTool(next.id);
+ requestAnimationFrame(() => event.currentTarget.querySelector<HTMLButtonElement>('[aria-checked="true"]')?.focus());
+ }}>
+ {TOOLS.map((tool) => <button
+ key={tool.label}
+ type="button"
+ role="radio"
+ aria-checked={drawKind === tool.id}
+ aria-label={tool.label}
+ aria-keyshortcuts={tool.key}
+ tabIndex={drawKind === tool.id ? 0 : -1}
+ className={`image-tool${drawKind === tool.id ? " image-tool--on" : ""}`}
+ {...tooltipProps(tool.label, tool.key)}
+ onClick={() => chooseTool(tool.id)}
+ ><span aria-hidden="true">{drawKind === tool.id ? tool.onIcon : tool.icon}</span></button>)}
+ </div>
+ <div className="image-tools__end">
+ <button className={`image-tool${boxes ? " image-tool--on" : ""}`} aria-label="Show placement boxes" aria-pressed={boxes} data-tooltip="Show placement boxes" onClick={() => { setBoxes(!boxes); setDrawKind(null); }}>{boxes ? <Boxes16Filled aria-hidden="true" /> : <Boxes16 aria-hidden="true" />}</button>
+ <span className="image-tools__separator" role="separator" aria-orientation="vertical" />
+ <ComboBox
+ editable
+ className="image-zoom"
+ aria-label="Image zoom"
+ data-tooltip="Zoom (Ctrl+0 fit, Ctrl+1 100%, Ctrl+= in, Ctrl+- out)"
+ value={zoomValue}
+ displayText={zoomText}
+ parseText={parseZoom}
+ options={zoomOptions}
+ onChange={(value) => { if (value === "fit") fit(); else zoomTo(Number(value)); }}
+ />
+ </div>
+ </div>
<aside ref={hierarchy} className="image-tree" aria-label="Image hierarchy" onContextMenu={(event) => { if ((event.target as HTMLElement).closest("input, textarea, [contenteditable=true]")) return; event.preventDefault(); setSelection(root.id); setContextMenu({ x: event.clientX, y: event.clientY }); }} onKeyDown={treeKeys}>
{/* Undo and Redo live in the title bar; Ctrl+Z / Ctrl+Y still step the image edits here. */}
<PaneHeader title="Scene" />
@@ -527,59 +580,6 @@ export function ImageEditor({ config, folderPath, onChange: changeConfig, onGene
] : []),
]} />}
<section className="image-center" aria-label="Image panel">
- <div className="image-canvas-tools" role="toolbar" aria-label="Image tools">
- {/* Three columns: Generate and the generator lead, the canvas tools
- sit in the middle, the view controls at the trailing edge. */}
- <div className="image-tools__start">
- <button className="primary-button image-generate-button" data-tooltip={editPlan?.error ?? undefined} disabled={active ? work.cancelling || work.status === "encoding" : !isTauri() || !template || !templateUsable(template) || (imageRoot ? Boolean(editPlan?.error) : !imageScenePrompt(scene))} onClick={() => attempt(() => active ? onCancel(work.id) : onGenerate(template!))}>{active ? <Stop14 aria-hidden="true" /> : <Sparkle16 aria-hidden="true" />}{active ? work.cancelling ? "Cancelling…" : "Cancel" : "Generate"}</button>
- <ComboBox
- className="image-generator"
- aria-label="Generator"
- data-tooltip="Generator"
- value={template?.id ?? ""}
- disabled={Boolean(active) || !imageTemplates.length}
- placeholder="No MiniMax H3 templates"
- options={imageTemplates.map((item) => ({ value: item.id, label: item.name, disabled: !templateUsable(item), description: !templateUsable(item) ? "Download in Settings" : undefined }))}
- onChange={(id) => { setTemplateId(id); localStorage.setItem("slopus.image-generator-template.v1", id); const next = imageTemplates.find((candidate) => candidate.id === id); if (next) commit({ ...scene, steps: next.defaultSteps }); }}
- />
- </div>
- <div className="image-tools__group" role="radiogroup" aria-label="Canvas tool" onKeyDown={(event) => {
- if (event.key !== "ArrowLeft" && event.key !== "ArrowRight") return;
- event.preventDefault();
- const at = TOOLS.findIndex((tool) => tool.id === drawKind);
- const next = TOOLS[(at + (event.key === "ArrowRight" ? 1 : -1) + TOOLS.length) % TOOLS.length];
- chooseTool(next.id);
- requestAnimationFrame(() => event.currentTarget.querySelector<HTMLButtonElement>('[aria-checked="true"]')?.focus());
- }}>
- {TOOLS.map((tool) => <button
- key={tool.label}
- type="button"
- role="radio"
- aria-checked={drawKind === tool.id}
- aria-label={tool.label}
- aria-keyshortcuts={tool.key}
- tabIndex={drawKind === tool.id ? 0 : -1}
- className={`image-tool${drawKind === tool.id ? " image-tool--on" : ""}`}
- {...tooltipProps(tool.label, tool.key)}
- onClick={() => chooseTool(tool.id)}
- ><span aria-hidden="true">{drawKind === tool.id ? tool.onIcon : tool.icon}</span></button>)}
- </div>
- <div className="image-tools__end">
- <button className={`image-tool${boxes ? " image-tool--on" : ""}`} aria-label="Show placement boxes" aria-pressed={boxes} data-tooltip="Show placement boxes" onClick={() => { setBoxes(!boxes); setDrawKind(null); }}>{boxes ? <Boxes16Filled aria-hidden="true" /> : <Boxes16 aria-hidden="true" />}</button>
- <span className="image-tools__separator" role="separator" aria-orientation="vertical" />
- <ComboBox
- editable
- className="image-zoom"
- aria-label="Image zoom"
- data-tooltip="Zoom (Ctrl+0 fit, Ctrl+1 100%, Ctrl+= in, Ctrl+- out)"
- value={zoomValue}
- displayText={zoomText}
- parseText={parseZoom}
- options={zoomOptions}
- onChange={(value) => { if (value === "fit") fit(); else zoomTo(Number(value)); }}
- />
- </div>
- </div>
<div ref={viewport} tabIndex={-1} className={`image-viewport${panning ? " panning" : ""}`} data-tooltip="Scroll to zoom · drag with the middle button to pan"
onPointerDownCapture={(event) => {
if (event.button !== 1 || pointer.current || pan.current) return;
diff --git a/src/styles/image-editor.css b/src/styles/image-editor.css
index ae411f4..af95d3b 100644
--- a/src/styles/image-editor.css
+++ b/src/styles/image-editor.css
@@ -6,7 +6,7 @@
========================================================================== */
.project-content--editor { padding: 0; overflow: hidden; }
-.image-editor { --pane-image-tree: 240px; --pane-image-inspector: 300px; display: grid; grid-template-columns: minmax(140px, var(--pane-image-tree)) auto minmax(160px, 1fr) auto minmax(220px, var(--pane-image-inspector)); height: 100%; min-height: 0; background: var(--layer); }
+.image-editor { --pane-image-tree: 240px; --pane-image-inspector: 300px; display: grid; grid-template-columns: minmax(140px, var(--pane-image-tree)) auto minmax(160px, 1fr) auto minmax(220px, var(--pane-image-inspector)); grid-template-rows: auto minmax(0, 1fr); height: 100%; min-height: 0; background: var(--layer); }
.image-tree, .image-inspector { min-width: 0; min-height: 0; overflow: auto; background: var(--panel); }
.image-tree { display: flex; flex-direction: column; }
.image-tree > .ui-pane-header, .image-inspector > .ui-item-header { flex-shrink: 0; }
@@ -39,7 +39,7 @@
/* --- Canvas and its tool strip ------------------------------------------------ */
.image-center { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--layer); }
-.image-canvas-tools { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: var(--space-2); min-height: var(--space-7); padding: var(--space-1) var(--space-2); border-bottom: 1px solid var(--line); }
+.image-canvas-tools { grid-column: 1 / -1; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: var(--space-2); min-height: var(--space-7); padding: var(--space-1) var(--space-2); border-bottom: 1px solid var(--line); }
.image-generate-button { flex-shrink: 0; white-space: nowrap; }
.image-tools__start, .image-tools__end { min-width: 0; display: flex; align-items: center; gap: var(--space-1); }
.image-tools__end { justify-content: flex-end; }