AI media harness for planning, generating, and editing locally
TypeScript
Move image hierarchy actions into context menu
Bitti3a16d3f5bb09
diff --git a/src/components/ImageProject.integration.test.tsx b/src/components/ImageProject.integration.test.tsxindex 3b4da8f..9f92e1f 100644--- a/src/components/ImageProject.integration.test.tsx+++ b/src/components/ImageProject.integration.test.tsx@@ -28,7 +28,8 @@ it("shows the full image prompt at the end of the inspector only when debug is eexpect(screen.queryByRole("button", { name: "Debug Prompt" })).not.toBeInTheDocument();act(() => saveDebugOptionsEnabled(true));// The complete scene prompt is available even with a child selected.- fireEvent.click(screen.getByRole("button", { name: "Text" }));+ fireEvent.contextMenu(screen.getByRole("button", { name: "Image" }));+ fireEvent.click(screen.getByRole("menuitem", { name: "New Text" }));fireEvent.change(screen.getByLabelText("Text to render"), { target: { value: "TO THE MOON" } });const inspector = screen.getByRole("complementary", { name: "Image node inspector" });const button = within(inspector).getByRole("button", { name: "Debug Prompt" });@@ -64,7 +65,8 @@ it("opens the three-tab image workspace and saves hierarchy/inspector edits throrender(<ProjectWorkspace project={record()} onBack={vi.fn()} onSave={save} />);const navigation = within(screen.getByRole("navigation", { name: "Project views" }));expect(navigation.getAllByRole("button").map((button) => button.textContent)).toEqual([" Agent", " Editor", " References"]);- fireEvent.click(screen.getByRole("button", { name: "Text" }));+ 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" } });fireEvent.change(screen.getByLabelText("Description"), { target: { value: "Large blue letters" } });fireEvent.click(screen.getByRole("button", { name: "Save" }));diff --git a/src/components/workspace/HierarchyContextMenu.tsx b/src/components/workspace/HierarchyContextMenu.tsxnew file mode 100644index 0000000..0eabc7c--- /dev/null+++ b/src/components/workspace/HierarchyContextMenu.tsx@@ -0,0 +1,43 @@+import { useEffect, useLayoutEffect, useRef, useState, type ReactNode } from "react";+import { createPortal } from "react-dom";++export interface HierarchyMenuItem {+ label: string; icon: ReactNode; shortcut?: string; disabled?: boolean; danger?: boolean; separator?: boolean; action: () => void;+}+export function HierarchyContextMenu({ x, y, items, onClose }: { x: number; y: number; items: HierarchyMenuItem[]; onClose: () => void }) {+ const menu = useRef<HTMLDivElement>(null);+ const [position, setPosition] = useState({ left: x, top: y });+ useLayoutEffect(() => {+ const bounds = menu.current!.getBoundingClientRect();+ setPosition({ left: Math.max(8, Math.min(x, window.innerWidth - bounds.width - 8)), top: Math.max(8, Math.min(y, window.innerHeight - bounds.height - 8)) });+ menu.current?.querySelector<HTMLButtonElement>("button:not(:disabled)")?.focus();+ }, [x, y]);+ useEffect(() => {+ const outside = (event: PointerEvent) => { if (event.target instanceof Node && !menu.current?.contains(event.target)) onClose(); };+ const escape = (event: KeyboardEvent) => {+ if (event.key === "Escape") { event.preventDefault(); event.stopPropagation(); onClose(); }+ };+ document.addEventListener("pointerdown", outside);+ window.addEventListener("keydown", escape, true);+ window.addEventListener("resize", onClose);+ return () => { document.removeEventListener("pointerdown", outside); window.removeEventListener("keydown", escape, true); window.removeEventListener("resize", onClose); };+ }, [onClose]);+ return createPortal(<div ref={menu} className="image-hierarchy-menu" role="menu" aria-label="Image hierarchy actions" style={position} onContextMenu={(event) => event.preventDefault()} onKeyDown={(event) => {+ event.stopPropagation();+ const shortcut = (event.ctrlKey || event.metaKey) ? `Ctrl+${event.key.toUpperCase()}` : event.key;+ const command = items.find((item) => item.shortcut === shortcut && !item.disabled);+ if (command) { event.preventDefault(); onClose(); command.action(); return; }+ const buttons = [...menu.current!.querySelectorAll<HTMLButtonElement>("button:not(:disabled)")];+ const index = buttons.indexOf(document.activeElement as HTMLButtonElement);+ if (["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key)) {+ event.preventDefault();+ const next = event.key === "Home" ? 0 : event.key === "End" ? buttons.length - 1 : (index + (event.key === "ArrowDown" ? 1 : -1) + buttons.length) % buttons.length;+ buttons[next]?.focus();+ } else if (event.key === "Tab") { event.preventDefault(); onClose(); }+ }}>+ {items.map((item) => <div key={item.label} role="none">+ {item.separator && <div role="separator" />}+ <button type="button" role="menuitem" disabled={item.disabled} className={item.danger ? "danger" : ""} onClick={() => { onClose(); item.action(); }}>{item.icon}<span>{item.label}</span>{item.shortcut && <kbd>{item.shortcut}</kbd>}</button>+ </div>)}+ </div>, document.body);+}diff --git a/src/components/workspace/ImageEditor.test.tsx b/src/components/workspace/ImageEditor.test.tsxindex 5e0da2e..cbd1921 100644--- a/src/components/workspace/ImageEditor.test.tsx+++ b/src/components/workspace/ImageEditor.test.tsx@@ -79,7 +79,7 @@ it("drags whole hierarchy branches to nest or reorder, preserves placement, andexpect(current().imageScene!.nodes.find((node) => node.id === "group-rocket")?.parentId).toBe("cloud");expect(current().imageScene!.nodes.find((node) => node.id === "title")).toEqual(scene.nodes[2]);expect(screen.getByRole("button", { name: "Collapse Cloud" })).toBeInTheDocument();- expect(screen.getByLabelText("Parent")).toHaveValue("cloud");+ expect(screen.queryByLabelText("Parent")).not.toBeInTheDocument();const nested = current().imageScene;drop("Cloud", "Title");expect(current().imageScene).toBe(nested);@@ -95,3 +95,74 @@ it("drags whole hierarchy branches to nest or reorder, preserves placement, andexpect(current().imageScene!.nodes.find((node) => node.id === "group-rocket")?.box).toEqual(scene.nodes[1].box);expect(parseProjectConfig(JSON.parse(JSON.stringify(current()))).imageScene).toEqual(current().imageScene);});++it("uses the context menu for creation, inline rename, and independent subtree copy/paste", () => {+ const current = setup();+ const open = (name: string) => fireEvent.contextMenu(screen.getByRole("button", { name }));+ const action = (name: string) => fireEvent.click(screen.getByRole("menuitem", { name: new RegExp(`^${name}(?:$| )`) }));+ const panel = within(screen.getByRole("complementary", { name: "Image hierarchy" }));+ expect(panel.queryByRole("button", { name: "Object" })).not.toBeInTheDocument();+ expect(panel.queryByRole("button", { name: "Duplicate" })).not.toBeInTheDocument();+ open("Image");+ expect(screen.getByRole("menuitem", { name: /^Copy/ })).toBeDisabled();+ expect(screen.getByRole("menuitem", { name: /^Delete/ })).toBeDisabled();+ expect(screen.getByRole("menuitem", { name: /^Paste/ })).toBeDisabled();+ fireEvent.keyDown(window, { key: "Escape" });+ open("Rocket");+ expect(screen.getByLabelText("Name")).toHaveValue("Rocket");+ action("Copy");+ actionAfterOpen("Rocket", "Rename");+ const rename = screen.getByRole("textbox", { name: "Rename image node" });+ expect(rename).toHaveFocus();+ fireEvent.change(rename, { target: { value: "Launch vehicle" } });+ fireEvent.keyDown(rename, { key: "Enter" });+ expect(current().imageScene!.nodes.find((node) => node.id === "group-rocket")?.name).toBe("Launch vehicle");+ actionAfterOpen("Image", "Paste");+ const pasted = current().imageScene!.nodes.find((node) => node.name === "Rocket")!;+ expect(pasted.id).not.toBe("group-rocket");+ expect(pasted.parentId).toBe("image-root");+ const child = current().imageScene!.nodes.find((node) => node.parentId === pasted.id)!;+ expect(child.id).not.toBe("title");+ expect(child.text).toBe("LIFT OFF");+ expect(child.box).toEqual(fixture.imageScene.nodes[2].box);+ actionAfterOpen("Rocket", "Delete");+ expect(current().imageScene!.nodes.some((node) => node.id === child.id)).toBe(false);+ fireEvent.click(screen.getByRole("button", { name: "Undo image edit" }));+ expect(current().imageScene!.nodes.some((node) => node.id === child.id)).toBe(true);+ actionAfterOpen("Launch vehicle", "New Text");+ const text = current().imageScene!.nodes.at(-1)!;+ expect(text.parentId).toBe("group-rocket");+ actionAfterOpen("Text", "New Object");+ expect(current().imageScene!.nodes.at(-1)?.parentId).toBe("group-rocket");+ expect(parseProjectConfig(JSON.parse(JSON.stringify(current()))).imageScene).toEqual(current().imageScene);+ function actionAfterOpen(node: string, name: string) { open(node); action(name); }+});++it("supports menu keyboard navigation and tree shortcuts without intercepting name editing", () => {+ const current = setup();+ const rocket = screen.getByRole("button", { name: "Rocket" });+ fireEvent.click(rocket);+ fireEvent.keyDown(rocket, { key: "F10", shiftKey: true });+ const first = screen.getByRole("menuitem", { name: "New Object" });+ expect(first).toHaveFocus();+ fireEvent.keyDown(first, { key: "End" });+ expect(screen.getByRole("menuitem", { name: /^Delete/ })).toHaveFocus();+ fireEvent.keyDown(window, { key: "Escape" });+ expect(rocket).toHaveFocus();+ fireEvent.keyDown(rocket, { key: "c", ctrlKey: true });+ fireEvent.keyDown(rocket, { key: "F2" });+ const rename = screen.getByRole("textbox", { name: "Rename image node" });+ fireEvent.change(rename, { target: { value: "Discard this" } });+ fireEvent.keyDown(rename, { key: "Delete" });+ expect(current().imageScene!.nodes).toHaveLength(3);+ fireEvent.keyDown(rename, { key: "Escape" });+ expect(current().imageScene!.nodes[1].name).toBe("Rocket");+ fireEvent.click(screen.getByRole("button", { name: "Title" }));+ fireEvent.keyDown(screen.getByRole("button", { name: "Title" }), { key: "v", ctrlKey: true });+ const pasted = current().imageScene!.nodes.at(-2)!;+ expect(pasted.parentId).toBe("group-rocket");+ expect(current().imageScene!.nodes).toHaveLength(5);+ fireEvent.contextMenu(screen.getByRole("tree", { name: "Image nodes" }));+ fireEvent.click(screen.getByRole("menuitem", { name: "New Group" }));+ expect(current().imageScene!.nodes.at(-1)).toMatchObject({ kind: "group", parentId: "image-root" });+});diff --git a/src/components/workspace/ImageEditor.tsx b/src/components/workspace/ImageEditor.tsxindex 8845361..95849f5 100644--- a/src/components/workspace/ImageEditor.tsx+++ b/src/components/workspace/ImageEditor.tsx@@ -1,5 +1,5 @@import { useEffect, useMemo, useRef, useState, useSyncExternalStore, type CSSProperties, type DragEvent, type PointerEvent } from "react";-import { Box, ChevronDown, ChevronRight, Copy, Download, Image, Plus, Redo2, Sparkles, Square, Trash2, Undo2 } from "lucide-react";+import { Box, ChevronDown, ChevronRight, ClipboardPaste, Copy, Download, FolderPlus, Image, Pencil, Plus, Redo2, Sparkles, Square, Trash2, Type, Undo2 } from "lucide-react";import { invoke } from "@tauri-apps/api/core";import { addImageNode, createImageScene, duplicateImageNode, imageDescendants, imageScenePrompt, removeImageNode, resizeImageNode, type ImageBox, type ImageNode, type ImageScene } from "../../lib/imageScene";import { outputDimensions } from "../../lib/export";@@ -14,6 +14,8 @@ import { DebugPromptDialog } from "./DebugPromptDialog";import { TagEditor } from "./TagEditor";import styleSuggestions from "../../lib/imageStyleSuggestions.json";import { applyImageCommand } from "../../lib/imageCommands";+import { copyImageNode, getImageNodeClipboard, pasteImageNode, subscribeImageNodeClipboard } from "../../lib/imageNodeClipboard";+import { HierarchyContextMenu } from "./HierarchyContextMenu";import "../../styles/image-editor.css";export function ImageEditor({ config, folderPath, onChange, onGenerate, onCancel, work }: {@@ -27,6 +29,11 @@ export function ImageEditor({ config, folderPath, onChange, onGenerate, onCancelconst [collapsed, setCollapsed] = useState(new Set<string>());const [draggedNode, setDraggedNode] = useState<string | null>(null);const [treeDrop, setTreeDrop] = useState<{ id: string; placement: "before" | "inside" | "after" } | null>(null);+ const [contextMenu, setContextMenu] = useState<{ x: number; y: number } | null>(null);+ const [renaming, setRenaming] = useState<{ id: string; value: string } | null>(null);+ const renameEnding = useRef(false);+ const hierarchy = useRef<HTMLElement>(null);+ const clipboard = useSyncExternalStore(subscribeImageNodeClipboard, getImageNodeClipboard);const [templates, setTemplates] = useState(loadGeneratorTemplateSettings);const [templateId, setTemplateId] = useState(() => localStorage.getItem("slopus.image-generator-template.v1") ?? defaultGeneratorTemplate().id);const imageTemplates = templates.templates.filter((template) => template.mode !== "animate");@@ -63,15 +70,48 @@ export function ImageEditor({ config, folderPath, onChange, onGenerate, onCancelhistoryChanged((value) => value + 1);};const patchNode = (patch: Partial<ImageNode>) => commit({ ...scene, nodes: scene.nodes.map((node) => node.id === selected.id ? { ...node, ...patch } : node) });+ const insertParent = selected.kind === "object" || selected.kind === "text" ? selected.parentId ?? root.id : selected.id;const add = (kind: Exclude<ImageNode["kind"], "root">, box?: ImageBox) => {- const next = addImageNode(scene, selected.id, kind, box); commit(next); setSelection(next.nodes.at(-1)!.id);- setCollapsed((current) => { const next = new Set(current); next.delete(selected.id); return next; });+ const next = addImageNode(scene, insertParent, kind, box); commit(next); setSelection(next.nodes.at(-1)!.id);+ setCollapsed((current) => { const next = new Set(current); next.delete(insertParent); return next; });};const attempt = (action: () => void | Promise<unknown>) => {setError(null);try { void Promise.resolve(action()).catch((reason) => setError(String(reason))); }catch (reason) { setError(reason instanceof Error ? reason.message : String(reason)); }};+ const focusNode = (id: string) => [...(hierarchy.current?.querySelectorAll<HTMLElement>("[data-image-node]") ?? [])].find((row) => row.dataset.imageNode === id)?.querySelector<HTMLButtonElement>(".image-tree__select")?.focus();+ const closeContextMenu = () => { setContextMenu(null); focusNode(selected.id); };+ const startRename = () => { renameEnding.current = false; setRenaming({ id: selected.id, value: selected.name }); };+ const finishRename = (save: boolean, restoreFocus = true) => {+ if (!renaming || renameEnding.current) return;+ renameEnding.current = true;+ if (save && renaming.value.trim()) commit({ ...scene, nodes: scene.nodes.map((node) => node.id === renaming.id ? { ...node, name: renaming.value.trim() } : node) });+ const id = renaming.id;+ setRenaming(null);+ if (restoreFocus) requestAnimationFrame(() => focusNode(id));+ };+ const removeSelected = () => {+ if (selected.kind === "root") return;+ const parent = selected.parentId ?? root.id;+ commit(removeImageNode(scene, selected.id)); setSelection(parent);+ requestAnimationFrame(() => focusNode(parent));+ };+ const paste = () => {+ const result = pasteImageNode(scene, insertParent);+ if (!result) return;+ commit(result.scene); setSelection(result.id);+ setCollapsed((current) => { const next = new Set(current); next.delete(insertParent); return next; });+ requestAnimationFrame(() => focusNode(result.id));+ };+ const duplicate = () => {+ if (selected.kind === "root") return;+ const next = duplicateImageNode(scene, selected.id);+ const oldIds = new Set(scene.nodes.map((node) => node.id));+ const copy = next.nodes.find((node) => !oldIds.has(node.id) && node.parentId === selected.parentId)!;+ commit(next); setSelection(copy.id);+ requestAnimationFrame(() => focusNode(copy.id));+ };const point = (event: PointerEvent<SVGSVGElement>) => {const bounds = event.currentTarget.getBoundingClientRect();return { x: Math.round(Math.max(0, Math.min(1000, (event.clientX - bounds.left) / bounds.width * 1000))), y: Math.round(Math.max(0, Math.min(1000, (event.clientY - bounds.top) / bounds.height * 1000))) };@@ -102,7 +142,6 @@ export function ImageEditor({ config, folderPath, onChange, onGenerate, onCancel}pointer.current = null; setDraftBox(null);};- const descendants = imageDescendants(scene, selected.id);const dropDestination = (event: DragEvent<HTMLDivElement>, target: ImageNode) => {const source = scene.nodes.find((node) => node.id === draggedNode);if (!source || source.kind === "root" || imageDescendants(scene, source.id).has(target.id)) return null;@@ -119,7 +158,9 @@ export function ImageEditor({ config, folderPath, onChange, onGenerate, onCancelconst open = !collapsed.has(node.id);return <div key={node.id} role="treeitem" aria-selected={selected.id === node.id} aria-expanded={children.length ? open : undefined}><div className={`image-tree__row ${selected.id === node.id ? "selected" : ""}${draggedNode === node.id ? " dragging" : ""}${treeDrop?.id === node.id ? ` image-tree__drop--${treeDrop.placement}` : ""}`} style={{ paddingLeft: `calc(var(--space-2) + ${depth} * var(--space-4))` }}- draggable={node.kind !== "root"}+ data-image-node={node.id}+ onContextMenu={(event) => { if ((event.target as HTMLElement).closest("input, textarea, [contenteditable=true]")) return; event.preventDefault(); event.stopPropagation(); setSelection(node.id); setContextMenu({ x: event.clientX, y: event.clientY }); }}+ draggable={node.kind !== "root" && renaming?.id !== node.id}onDragStart={(event) => {if (node.kind === "root") { event.preventDefault(); return; }event.stopPropagation();@@ -145,19 +186,45 @@ export function ImageEditor({ config, folderPath, onChange, onGenerate, onCancelsetDraggedNode(null); setTreeDrop(null);}}>{children.length ? <button className="icon-button" aria-label={`${open ? "Collapse" : "Expand"} ${node.name}`} onClick={() => setCollapsed((current) => { const next = new Set(current); if (open) next.add(node.id); else next.delete(node.id); return next; })}>{open ? <ChevronDown size={14} /> : <ChevronRight size={14} />}</button> : <span className="image-tree__spacer" />}- <button className="image-tree__select" onClick={() => setSelection(node.id)}><span aria-hidden="true">{node.kind === "text" ? "T" : node.kind === "root" ? <Image size={16} /> : <Box size={16} />}</span><span>{node.name}</span></button>+ {renaming?.id === node.id ? <input className="image-tree__rename" aria-label="Rename image node" maxLength={120} ref={(element) => { if (element && document.activeElement !== element) { element.focus(); element.select(); } }} value={renaming.value} onChange={(event) => setRenaming({ ...renaming, value: event.target.value })} onBlur={() => finishRename(true, false)} onKeyDown={(event) => {+ event.stopPropagation();+ if (event.key === "Enter" && !event.nativeEvent.isComposing) { event.preventDefault(); finishRename(true); }+ if (event.key === "Escape") { event.preventDefault(); finishRename(false); }+ }} /> : <button className="image-tree__select" onFocus={() => setSelection(node.id)} onClick={() => setSelection(node.id)}><span aria-hidden="true">{node.kind === "text" ? "T" : node.kind === "root" ? <Image size={16} /> : <Box size={16} />}</span><span>{node.name}</span></button>}</div>{open && children.length > 0 && <div role="group">{children.map((child) => tree(child, depth + 1))}</div>}</div>;};return <div className="image-editor">- <aside className="image-tree" aria-label="Image hierarchy">+ <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={(event) => {+ if ((event.target as HTMLElement).closest("input, textarea, select, [contenteditable=true]") || contextMenu) return;+ const key = event.key.toLowerCase();+ if ((event.ctrlKey || event.metaKey) && (key === "c" || key === "v")) {+ event.preventDefault(); event.stopPropagation();+ attempt(() => key === "c" ? copyImageNode(scene, selected.id) : paste());+ } else if (key === "delete") { event.preventDefault(); event.stopPropagation(); removeSelected(); }+ else if (key === "f2") { event.preventDefault(); event.stopPropagation(); startRename(); }+ else if (event.key === "ContextMenu" || (event.shiftKey && event.key === "F10")) {+ event.preventDefault(); event.stopPropagation();+ const bounds = (event.target as HTMLElement).getBoundingClientRect();+ setContextMenu({ x: bounds.left, y: bounds.bottom });+ }+ }}><header><strong>Scene</strong><div className="image-editor__actions"><button className="icon-button" title="Undo" aria-label="Undo image edit" disabled={!undo.current.length} onClick={() => history(true)}><Undo2 size={16} /></button><button className="icon-button" title="Redo" aria-label="Redo image edit" disabled={!redo.current.length} onClick={() => history(false)}><Redo2 size={16} /></button></div></header>- <div className="image-tree__add">{(["object", "text", "group", "background"] as const).map((kind) => <button className="secondary-button" key={kind} onClick={() => add(kind)}><Plus size={14} />{kind[0].toUpperCase() + kind.slice(1)}</button>)}</div><div role="tree" aria-label="Image nodes">{tree(root, 0)}</div>- <p className="image-tree__hint">Drag onto a node to nest, or between nodes to reorder.</p>- <div className="image-tree__footer"><button className="secondary-button" disabled={selected.kind === "root"} onClick={() => { const next = duplicateImageNode(scene, selected.id); commit(next); setSelection(next.nodes[scene.nodes.length].id); }}><Copy size={15} /> Duplicate</button><button className="icon-button" aria-label="Delete selected node and children" disabled={selected.kind === "root"} onClick={() => { commit(removeImageNode(scene, selected.id)); setSelection(selected.parentId ?? root.id); }}><Trash2 size={16} /></button></div>+ <p className="image-tree__hint">Right-click to add or edit nodes. Drag onto a node to nest, or between nodes to reorder.</p></aside>+ {contextMenu && <HierarchyContextMenu {...contextMenu} onClose={closeContextMenu} items={[+ { label: "New Object", icon: <Box size={15} />, action: () => attempt(() => add("object")) },+ { label: "New Text", icon: <Type size={15} />, action: () => attempt(() => add("text")) },+ { label: "New Group", icon: <FolderPlus size={15} />, action: () => attempt(() => add("group")) },+ { label: "New Background", icon: <Image size={15} />, action: () => attempt(() => add("background")) },+ { label: "Rename", icon: <Pencil size={15} />, shortcut: "F2", separator: true, action: startRename },+ { label: "Copy", icon: <Copy size={15} />, shortcut: "Ctrl+C", separator: true, disabled: selected.kind === "root", action: () => copyImageNode(scene, selected.id) },+ { label: "Paste", icon: <ClipboardPaste size={15} />, shortcut: "Ctrl+V", disabled: !clipboard, action: () => attempt(paste) },+ { label: "Duplicate", icon: <Copy size={15} />, disabled: selected.kind === "root", action: () => attempt(duplicate) },+ { label: "Delete", icon: <Trash2 size={15} />, shortcut: "Delete", separator: true, danger: true, disabled: selected.kind === "root", action: removeSelected },+ ]} />}<section className="image-center" aria-label="Image panel"><header className="image-toolbar"><button className="primary-button" disabled={active ? work.cancelling || work.status === "encoding" : !isTauri() || !template || templateNeedsDownload(template) || !imageScenePrompt(scene)} onClick={() => attempt(() => active ? onCancel(work.id) : onGenerate(template!))}><Sparkles size={16} />{active ? work.cancelling ? "Cancelling…" : "Cancel" : "Generate"}</button><label>Generator template<select aria-label="Image generator template" value={template?.id ?? ""} disabled={Boolean(active)} onChange={(event) => { setTemplateId(event.target.value); localStorage.setItem("slopus.image-generator-template.v1", event.target.value); const next = imageTemplates.find((candidate) => candidate.id === event.target.value); if (next) commit({ ...scene, steps: next.defaultSteps }); }}>@@ -188,7 +255,6 @@ export function ImageEditor({ config, folderPath, onChange, onGenerate, onCancel<label>Name<input value={selected.name} maxLength={120} onChange={(event) => { if (event.target.value.trim()) patchNode({ name: event.target.value }); }} /></label><label>{selected.kind === "root" ? "Prompt (high-level description)" : "Description"}<textarea rows={4} value={selected.description} onChange={(event) => patchNode({ description: event.target.value })} /></label>{selected.kind === "text" && <label>Text to render<input value={selected.text} onChange={(event) => patchNode({ text: event.target.value })} /></label>}- {selected.kind !== "root" && <label>Parent<select value={selected.parentId ?? root.id} onChange={(event) => patchNode({ parentId: event.target.value })}>{scene.nodes.filter((node) => !descendants.has(node.id)).map((node) => <option key={node.id} value={node.id}>{node.name}</option>)}</select></label>}{selected.kind === "root" && <><label>Background (environment)<textarea rows={3} value={scene.background} onChange={(event) => commit({ ...scene, background: event.target.value })} /></label><h3>Image generation</h3><label>Steps<input type="number" min="2" max="1000" value={scene.steps} onChange={(event) => { const value = Number(event.target.value); if (Number.isInteger(value) && value >= 2 && value <= 1000) commit({ ...scene, steps: value }); }} /></label>diff --git a/src/lib/imageNodeClipboard.ts b/src/lib/imageNodeClipboard.tsnew file mode 100644index 0000000..a35c2aa--- /dev/null+++ b/src/lib/imageNodeClipboard.ts@@ -0,0 +1,23 @@+import { imageDescendants, imageSceneSchema, type ImageNode, type ImageScene } from "./imageScene";++// Like ImgFab, node copying uses an in-app clipboard, separate from text copying.+let clipboard: ImageNode[] | null = null;+const listeners = new Set<() => void>();+export const getImageNodeClipboard = () => clipboard;+export function subscribeImageNodeClipboard(listener: () => void) {+ listeners.add(listener);+ return () => { listeners.delete(listener); };+}+export function copyImageNode(scene: ImageScene, id: string) {+ const node = scene.nodes.find((item) => item.id === id);+ if (!node || node.kind === "root") return;+ const descendants = imageDescendants(scene, id);+ clipboard = structuredClone([node, ...scene.nodes.filter((item) => item.id !== id && descendants.has(item.id))]);+ listeners.forEach((listener) => listener());+}+export function pasteImageNode(scene: ImageScene, parentId: string) {+ if (!clipboard) return null;+ const ids = new Map(clipboard.map((node) => [node.id, crypto.randomUUID()]));+ const nodes = structuredClone(clipboard).map((node, index) => ({ ...node, id: ids.get(node.id)!, parentId: index === 0 ? parentId : ids.get(node.parentId!)! }));+ return { scene: imageSceneSchema.parse({ ...scene, nodes: [...scene.nodes, ...nodes] }), id: nodes[0].id };+}diff --git a/src/styles/image-editor.css b/src/styles/image-editor.cssindex a36459b..b51c74b 100644--- a/src/styles/image-editor.css+++ b/src/styles/image-editor.css@@ -8,9 +8,7 @@.image-inspector { display: flex; flex-direction: column; border-left: 1px solid var(--line-solid); }.image-inspector > header { flex-shrink: 0; }.image-inspector > .debug-prompt { margin-top: auto; }-.image-editor__actions, .image-tree__footer { display: flex; align-items: center; gap: var(--space-1); }-.image-tree__add { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-1); padding: var(--space-2); }-.image-tree__add button { padding-inline: var(--space-2); font-size: var(--text-xs); }+.image-editor__actions { display: flex; align-items: center; gap: var(--space-1); }.image-tree__row { position: relative; display: flex; align-items: center; min-height: var(--control-md); }.image-tree__row[draggable="true"] .image-tree__select { cursor: grab; }.image-tree__row.dragging { opacity: 0.45; }@@ -23,7 +21,14 @@.image-tree__select { display: flex; gap: var(--space-2); align-items: center; flex: 1; min-width: 0; padding: var(--space-2); text-align: left; border: 0; background: transparent; color: inherit; }.image-tree__select span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }.image-tree__spacer { width: var(--control-sm); flex-shrink: 0; }-.image-tree__footer { padding: var(--space-2); border-top: 1px solid var(--line-solid); }+.image-editor .image-tree__rename { flex: 1; min-width: 0; width: 100%; margin: var(--space-1); padding: var(--space-1); min-height: var(--control-sm); }+.image-hierarchy-menu { position: fixed; z-index: 115; width: 220px; max-width: calc(100vw - 16px); max-height: calc(100dvh - 16px); overflow: auto; padding: var(--space-1); border: 1px solid var(--line-strong); border-radius: var(--radius-md); background: var(--panel); box-shadow: var(--shadow); }+.image-hierarchy-menu button { display: flex; align-items: center; gap: var(--space-2); width: 100%; padding: var(--space-2); border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text-primary); text-align: left; font-size: var(--text-sm); }+.image-hierarchy-menu button:hover:not(:disabled), .image-hierarchy-menu button:focus-visible { background: var(--panel-3); }+.image-hierarchy-menu button:disabled { opacity: 0.4; }+.image-hierarchy-menu button.danger { color: var(--danger); }+.image-hierarchy-menu kbd { margin-left: auto; color: var(--text-muted); font: inherit; font-size: var(--text-xs); }+.image-hierarchy-menu [role="separator"] { height: 1px; margin: var(--space-1); background: var(--line-solid); }.image-center { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--bg); }.image-editor .image-toolbar { justify-content: flex-start; flex-wrap: wrap; background: var(--panel); }.image-toolbar label { display: flex; flex-direction: column; gap: var(--space-1); flex: 1; min-width: 120px; font-size: var(--text-xs); }@@ -63,4 +68,4 @@.image-palette { display: flex; flex-wrap: wrap; gap: var(--space-2); }.image-palette > div { display: flex; align-items: center; }.image-palette input[type="color"] { width: var(--control-sm); height: var(--control-sm); padding: var(--space-1); }-@media (max-width: 1100px) { .image-editor { grid-template-columns: 180px minmax(0, 1fr) 240px; } .image-tree__add { grid-template-columns: 1fr; } .image-model { display: none; } }+@media (max-width: 1100px) { .image-editor { grid-template-columns: 180px minmax(0, 1fr) 240px; } .image-model { display: none; } }