AI media harness for planning, generating, and editing locally
TypeScript
Add reference image paging and removal
Bittie77e21abc668
diff --git a/src/components/workspace/ReferencesView.test.tsx b/src/components/workspace/ReferencesView.test.tsxindex 3627fb8..93c572b 100644--- a/src/components/workspace/ReferencesView.test.tsx+++ b/src/components/workspace/ReferencesView.test.tsx@@ -5,7 +5,7 @@ import { act, cleanup, fireEvent, render, screen, waitFor, within } from "@testiimport { invoke } from "@tauri-apps/api/core";import { useState } from "react";import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";-import { createProjectConfig, parseProjectConfig, type ProjectConfig } from "../../lib/project";+import { createProjectConfig, parseProjectConfig, referenceImages, type ProjectConfig } from "../../lib/project";import { ReferencesView } from "./ReferencesView";import { referenceIconPrompt } from "../../lib/referenceIcons";import { saveDebugOptionsEnabled } from "../../lib/settings";@@ -59,6 +59,59 @@ function setup(initial = project(), onRegenerateIcon = vi.fn(), pendingIconIds =}describe("Reference type presets", () => {+ it("pages through one image at a time, resets on reference changes, and removes images through the last page", () => {+ const initial = project();+ initial.references[0].images = ["front", "side", "back"].map((name) => ({ id: name, name, relativePath: `references/${name}.png` }));+ initial.references.push({ ...initial.references[0], id: "ref-other", name: "Other" });+ const state = setup(initial);+ const inspector = within(screen.getByRole("complementary"));+ const previous = () => inspector.getByRole("button", { name: "Previous reference image" });+ const next = () => inspector.getByRole("button", { name: "Next reference image" });+ const remove = () => fireEvent.click(inspector.getByRole("button", { name: "Remove reference image" }));+ expect(inspector.getAllByRole("img")).toHaveLength(1);+ expect(inspector.getByRole("img", { name: /^front/ })).toBeInTheDocument();+ expect(previous()).toBeDisabled();+ fireEvent.click(next());+ expect(inspector.getByRole("img", { name: /^side/ })).toBeInTheDocument();+ expect(inspector.queryByRole("img", { name: /^front/ })).not.toBeInTheDocument();+ fireEvent.click(previous());+ expect(inspector.getByText("Image 1 of 3")).toBeInTheDocument();+ fireEvent.click(next());+ fireEvent.click(screen.getByRole("button", { name: /Other 3 images/ }));+ expect(inspector.getByText("Image 1 of 3")).toBeInTheDocument();+ fireEvent.click(screen.getByRole("button", { name: /Hero 3 images/ }));+ fireEvent.click(next());+ remove();+ expect(inspector.getByText("Image 2 of 2")).toBeInTheDocument();+ expect(inspector.getByRole("img", { name: /^back/ })).toBeInTheDocument();+ expect(next()).toBeDisabled();+ remove();+ expect(inspector.getByText("Image 1 of 1")).toBeInTheDocument();+ expect(previous()).toBeDisabled();+ expect(next()).toBeDisabled();+ remove();+ expect(inspector.queryByRole("group", { name: "Reference images" })).not.toBeInTheDocument();+ const saved = parseProjectConfig(JSON.parse(JSON.stringify(state.latest())));+ expect(saved.references[0]).toMatchObject({ ...initial.references[0], images: [] });+ expect(saved.references[1].images).toHaveLength(3);+ expect(saved.generationJobs).toEqual(initial.generationJobs);+ });++ it.each(["legacy", "attachment"])("removes the %s image from an older reference without restoring it on reload", (target) => {+ const initial = project();+ Object.assign(initial.references[0], { kind: "image", relativePath: "references/legacy.png", sourcePath: null, images: [{ id: "extra", name: "Extra", relativePath: "references/extra.png" }] });+ const state = setup(initial);+ if (target === "attachment") fireEvent.click(screen.getByRole("button", { name: "Next reference image" }));+ fireEvent.click(screen.getByRole("button", { name: "Remove reference image" }));+ const saved = parseProjectConfig(JSON.parse(JSON.stringify(state.latest())));+ expect(saved.references[0]).toMatchObject({ kind: "text", relativePath: null, sourcePath: null, description: initial.references[0].description });+ expect(referenceImages(saved.references[0]).map((image) => image.relativePath)).toEqual([target === "legacy" ? "references/extra.png" : "references/legacy.png"]);+ cleanup();+ const restored = setup(saved);+ fireEvent.click(screen.getByRole("button", { name: "Remove reference image" }));+ expect(referenceImages(parseProjectConfig(restored.latest()).references[0])).toEqual([]);+ });+it("shows the exact icon regeneration prompt in a debug-only footer dialog", () => {const regenerate = vi.fn();const state = setup(project(), regenerate);diff --git a/src/components/workspace/ReferencesView.tsx b/src/components/workspace/ReferencesView.tsxindex 01bd147..4b8eeb5 100644--- a/src/components/workspace/ReferencesView.tsx+++ b/src/components/workspace/ReferencesView.tsx@@ -1,4 +1,4 @@-import { BookOpen, ChevronRight, FileText, ImagePlus, Plus, RefreshCw, Search, Trash2, Users, X } from "lucide-react";+import { BookOpen, ChevronLeft, ChevronRight, FileText, ImagePlus, Plus, RefreshCw, Search, Trash2, Users, X } from "lucide-react";import { invoke } from "@tauri-apps/api/core";import { useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";import { isReferenceDescribed, referenceImages, type ProjectConfig, type ProjectReference, type ProjectReferenceImage } from "../../lib/project";@@ -58,6 +58,8 @@ export function ReferencesView({ config, folderPath, onChange, onRegenerateIcon,onOpenGenerator?: (jobId: string) => void;}) {const [selectedId, setSelectedId] = useState<string | undefined>(config.references[0]?.id);+ const [imagePage, setImagePage] = useState(0);+ useEffect(() => setImagePage(0), [selectedId]);const configRef = useRef(config);configRef.current = config;const debugEnabled = useSyncExternalStore(subscribeDebugOptions, loadDebugOptionsEnabled);@@ -79,6 +81,8 @@ export function ReferencesView({ config, folderPath, onChange, onRegenerateIcon,const [presetSearch, setPresetSearch] = useState("");const selected = config.references.find((ref) => ref.id === selectedId);const selectedImages = selected ? referenceImages(selected) : [];+ const currentImagePage = Math.min(imagePage, Math.max(0, selectedImages.length - 1));+ const selectedImage = selectedImages[currentImagePage];const hasRefmods = Boolean(selected?.refmods?.length);const showImages = selectedImages.length > 0 && !hasRefmods;const canGenerateIcon = Boolean(selected && (hasRefmods ? activeReferenceRefmods(selected).length : selected.description.trim()));@@ -94,6 +98,18 @@ export function ReferencesView({ config, folderPath, onChange, onRegenerateIcon,const current = configRef.current;onChange({ ...current, references: current.references.map((ref) => ref.id === id ? { ...ref, ...patch } : ref) });};+ const removeImage = () => {+ if (!selected || !selectedImage) return;+ const current = configRef.current.references.find((ref) => ref.id === selected.id);+ if (!current) return;+ const images = referenceImages(current).filter((image) => image.id !== selectedImage.id);+ update(current.id, {+ images,+ // Move any remaining legacy image into attachments before clearing its path.+ ...(current.kind === "image" ? { kind: "text", relativePath: null, sourcePath: null } : {}),+ });+ setImagePage(Math.min(currentImagePage, Math.max(0, images.length - 1)));+ };// Starts empty on purpose. Seeding it with the instruction text meant an// unedited definition shipped "Describe the traits…" to the model as if the// user had written it. The guidance lives in the field's placeholder instead.@@ -242,7 +258,7 @@ export function ReferencesView({ config, folderPath, onChange, onRegenerateIcon,</section>}{(selected.kind !== "video" || showImages || hasRefmods) && <div className={`reference-detail-art${showImages || selected.iconRelativePath || (!hasRefmods && selectedPresetIcon) ? " reference-detail-art--photo" : " reference-detail-art--text"}${(!hasRefmods && selectedPresetIcon) || selected.iconRelativePath ? " reference-detail-art--preset" : ""}`}>{showImages- ? <div className="reference-detail-images">{selectedImages.map((image) => <ReferenceImage key={image.id} folderPath={folderPath} relativePath={image.relativePath} sourcePath={image.sourcePath} alt={image.name} />)}</div>+ ? <div className="reference-detail-images"><ReferenceImage key={selectedImage.id} folderPath={folderPath} relativePath={selectedImage.relativePath} sourcePath={selectedImage.sourcePath} alt={selectedImage.name} /></div>: selected.iconRelativePath? <ReferenceImage className="reference-detail-preset-icon" folderPath={folderPath} relativePath={selected.iconRelativePath} alt={`${selected.name} reference icon`} />: !hasRefmods && selectedPresetIcon@@ -265,6 +281,12 @@ export function ReferencesView({ config, folderPath, onChange, onRegenerateIcon,}}><RefreshCw size={14} aria-hidden="true" /></button>}</div>}+ {showImages && <div className="reference-image-controls" role="group" aria-label="Reference images">+ <button type="button" className="secondary-button" aria-label="Previous reference image" title="Previous image" disabled={currentImagePage === 0} onClick={() => setImagePage(currentImagePage - 1)}><ChevronLeft size={16} aria-hidden="true" /></button>+ <span aria-live="polite">Image {currentImagePage + 1} of {selectedImages.length}</span>+ <button type="button" className="secondary-button" aria-label="Next reference image" title="Next image" disabled={currentImagePage === selectedImages.length - 1} onClick={() => setImagePage(currentImagePage + 1)}><ChevronRight size={16} aria-hidden="true" /></button>+ <button type="button" className="inspector-remove-button" aria-label="Remove reference image" title={`Remove ${selectedImage.name}`} onClick={removeImage}><Trash2 size={16} aria-hidden="true" /></button>+ </div>}<div className="reference-fields"><label><span>Prompt</span><textarea disabled={hasRefmods} value={selected.description} placeholder="Describe what should stay consistent — the traits, materials, colours, or wardrobe Slopus should preserve across shots." onChange={(event) => update(selected.id, { description: event.target.value, content: event.target.value || null, subcategory: selectedSubcategory })} /></label><div className="reference-fields__actions">diff --git a/src/components/workspace/ReferencesView.video.test.tsx b/src/components/workspace/ReferencesView.video.test.tsxindex d696b59..784d5a9 100644--- a/src/components/workspace/ReferencesView.video.test.tsx+++ b/src/components/workspace/ReferencesView.video.test.tsx@@ -66,6 +66,11 @@ it("attaches mixed files through Add file and renders an icon with an enabled reexpect(latest.references[0].kind).toBe("video");expect(screen.getByLabelText("Prompt")).toBeEnabled();expect(screen.getByRole("button", { name: "Add file" })).toBeEnabled();+ fireEvent.click(screen.getByRole("button", { name: "Remove reference image" }));+ expect(parseProjectConfig(latest).references[0]).toMatchObject({+ kind: "video", sourcePath: "D:/motion.mp4", images: [],+ video: { startSeconds: 0, durationSeconds: 4, includeAudio: false },+ });});it("shows an existing refmod icon only in the normal inspector slot and clears it on removal", () => {diff --git a/src/styles/references.css b/src/styles/references.cssindex 7dd1e30..08473b7 100644--- a/src/styles/references.css+++ b/src/styles/references.css@@ -284,17 +284,13 @@.reference-detail-images {width: 100%;height: 100%;- display: flex;- align-items: stretch;- gap: var(--space-2);- overflow-x: auto;+ min-height: 0;padding: var(--space-2);}.reference-detail-art--photo .reference-detail-images img {- width: min(220px, 72%);+ width: 100%;height: 100%;- flex: 0 0 auto;padding: 0;border: 1px solid var(--line);border-radius: var(--radius-sm);@@ -302,6 +298,25 @@object-fit: contain;}+.reference-image-controls {+ display: flex;+ align-items: center;+ justify-content: center;+ gap: var(--space-2);+ padding: var(--space-2) var(--space-3);+ border-bottom: 1px solid var(--line);+}++.reference-image-controls > span {+ color: var(--text-secondary);+ font-size: var(--text-sm);+ font-variant-numeric: tabular-nums;+}++.reference-image-controls > .inspector-remove-button { margin-left: auto; }++.reference-image-controls > button:disabled { opacity: 0.5; cursor: default; }+/* Loading, or the file is not where the project says it is. Two states, saidplainly, rather than one placeholder that could mean either. */.reference-image-fallback {