Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Rework references

Bittida91c21306c3
diff --git a/src/components/ProjectWorkspace.test.ts b/src/components/ProjectWorkspace.test.ts
index 3f8719c..c4cf799 100644
--- a/src/components/ProjectWorkspace.test.ts
+++ b/src/components/ProjectWorkspace.test.ts
@@ -22,7 +22,7 @@ afterEach(cleanup);
/** Runs `body` with the app believing it is inside the desktop shell, so the
* REAL Tauri import path executes instead of the browser fallback. */
-async function asDesktopApp(importedImage: { name: string; relativePath: string }, body: () => void | Promise<void>) {
+async function asDesktopApp(importedImage: { name: string; relativePath: string } | Array<{ name: string; relativePath: string }>, body: () => void | Promise<void>) {
const { invoke } = await import("@tauri-apps/api/core");
(window as unknown as Record<string, unknown>).__TAURI_INTERNALS__ = {};
vi.mocked(invoke).mockResolvedValue(importedImage);
@@ -1053,14 +1053,19 @@ describe("project workspace timecode", () => {
// which is exactly why this shipped.
const config = createProjectConfig({ name: "Ceramic lamp", prompt: "A quiet product film", aspectRatio: "16:9", resolution: "1080p", targetDurationSeconds: 30 });
const onChange = vi.fn();
- await asDesktopApp({ name: "IMG_4821", relativePath: "references/IMG_4821.jpg" }, async () => {
+ await asDesktopApp([{ name: "IMG_4821", relativePath: "references/IMG_4821.jpg" }], async () => {
render(createElement(ReferencesView, { config, folderPath: "C:\\Ceramic Lamp", onChange }));
- fireEvent.click(screen.getByRole("button", { name: "Add image" }));
+ fireEvent.click(screen.getByRole("button", { name: /Add a reference/ }));
+ const dialog = screen.getByRole("dialog", { name: "Add a reference" });
+ fireEvent.click(within(dialog).getByRole("button", { name: "Image" }));
+ fireEvent.click(within(dialog).getByRole("button", { name: "Choose images" }));
await waitFor(() => expect(onChange).toHaveBeenCalled());
});
const imported = onChange.mock.calls[0][0].references[0];
- expect(imported.relativePath).toBe("references/IMG_4821.jpg");
+ expect(imported.kind).toBe("text");
+ expect(imported.relativePath).toBeUndefined();
+ expect(imported.images[0].relativePath).toBe("references/IMG_4821.jpg");
// The import writes no prose: description is what the compiler hands the
// model as the user's own account of the picture.
expect(imported.description).toBe("");
@@ -1083,7 +1088,7 @@ describe("project workspace timecode", () => {
// file is sent.
cleanup();
const withImport = onChange.mock.calls[0][0];
- expect(withImport.references[0].relativePath).toBeTruthy();
+ expect(withImport.references[0].images).toHaveLength(1);
const { container } = render(createElement(ReferencesView, { config: withImport, folderPath: "C:\\Ceramic Lamp", onChange: () => undefined }));
const screenText = container.textContent ?? "";
for (const staleRule of ["you’ve described", "described references", "skipped", "is skipped until you write"]) {
@@ -1097,8 +1102,8 @@ describe("project workspace timecode", () => {
const { container } = render(createElement(ReferencesView, { config, folderPath: "C:\\Ceramic Lamp", onChange: () => undefined }));
const view = container.querySelector(".references-view")!;
expect(Array.from(view.children).slice(0, 2).map((element) => element.className)).toEqual(["references-main", "reference-inspector"]);
- expect(container.querySelector(".references-heading__actions")!.textContent).toContain("New definition");
- expect(container.querySelector(".references-heading__actions")!.textContent).toContain("Add image");
+ expect(container.querySelector(".references-heading__actions")).toBeNull();
+ expect(screen.getByRole("button", { name: /Add a reference/ })).not.toBeNull();
expect(container.querySelector(".reference-inspector__scroll")).not.toBeNull();
expect(container.querySelector(".reference-layout")).toBeNull();
expect(container.querySelector(".reference-library__toolbar")).toBeNull();
diff --git a/src/components/workspace/GeneratorView.tsx b/src/components/workspace/GeneratorView.tsx
index 9359276..c58cde7 100644
--- a/src/components/workspace/GeneratorView.tsx
+++ b/src/components/workspace/GeneratorView.tsx
@@ -1,7 +1,7 @@
import { Plus, Sparkles, Square, Trash2, WandSparkles } from "lucide-react";
import { invoke } from "@tauri-apps/api/core";
import { useEffect, useMemo, useRef, useState } from "react";
-import { actionReferenceIds, compileGenerationJobPrompt, compileGenerationJobSegments, createDraftGenerationJob, danglingReferenceTokens, GENERATION_FRAME_RATE, sceneDurationSeconds, sceneGenerationReferences, sceneGenerationSeed, sceneGenerationSnapshot, sceneGenerationSteps, sceneShots, SCENE_MAX_SECONDS, SCENE_MIN_SECONDS, projectItemPath, usableImageReferences, type GenerationJob, type ProjectConfig, type ProjectReference, type PromptSegment, type SceneShot } from "../../lib/project";
+import { actionReferenceIds, compileGenerationJobPrompt, compileGenerationJobSegments, createDraftGenerationJob, danglingReferenceTokens, GENERATION_FRAME_RATE, sceneDurationSeconds, sceneGenerationReferences, sceneGenerationSeed, sceneGenerationSnapshot, sceneGenerationSteps, sceneShots, SCENE_MAX_SECONDS, SCENE_MIN_SECONDS, projectItemPath, usableReferenceImages, type GenerationJob, type ProjectConfig, type ProjectReference, type PromptSegment, type SceneShot } from "../../lib/project";
import { generationDimensions } from "../../lib/export";
import { isTauri } from "../../lib/persistence";
import { cancelVidfabGeneration, enqueueVidfabGeneration, resolveVidfabPlan, type VidfabGenerationRequest, type VidfabStatus } from "../../lib/runtime";
@@ -109,10 +109,10 @@ export function GeneratorView({ config, folderPath, runtime = null, generationCo
const id = `ref-${Date.now()}`;
const reference: ProjectReference = {
id,
- kind: "image",
+ kind: "text",
name: imported.name,
description: "",
- relativePath: imported.relativePath,
+ images: [{ id: `${id}-image`, name: imported.name, relativePath: imported.relativePath }],
intendedUse: [],
createdAt: new Date().toISOString(),
};
@@ -246,8 +246,8 @@ export function GeneratorView({ config, folderPath, runtime = null, generationCo
seed: sceneGenerationSeed(job),
canvasWidth: canvas.width,
canvasHeight: canvas.height,
- referencePaths: usableImageReferences(bound)
- .map((reference) => projectItemPath(folderPath, reference) ?? "")
+ referencePaths: usableReferenceImages(bound)
+ .map((image) => projectItemPath(folderPath, image) ?? "")
.filter((path) => path.length > 0),
};
};
diff --git a/src/components/workspace/ReferencesView.test.tsx b/src/components/workspace/ReferencesView.test.tsx
index 7293425..51c6fc7 100644
--- a/src/components/workspace/ReferencesView.test.tsx
+++ b/src/components/workspace/ReferencesView.test.tsx
@@ -1,13 +1,20 @@
// @vitest-environment jsdom
import "@testing-library/jest-dom/vitest";
-import { cleanup, fireEvent, render, screen, within } from "@testing-library/react";
+import { cleanup, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
+import { invoke } from "@tauri-apps/api/core";
import { useState } from "react";
-import { afterEach, describe, expect, it } from "vitest";
+import { afterEach, describe, expect, it, vi } from "vitest";
import { createProjectConfig, parseProjectConfig, type ProjectConfig } from "../../lib/project";
import { ReferencesView } from "./ReferencesView";
-afterEach(cleanup);
+vi.mock("@tauri-apps/api/core", () => ({ invoke: vi.fn() }));
+
+afterEach(() => {
+ cleanup();
+ delete (window as unknown as Record<string, unknown>).__TAURI_INTERNALS__;
+ vi.mocked(invoke).mockReset();
+});
const project = (): ProjectConfig => {
const base = createProjectConfig({
@@ -57,20 +64,24 @@ describe("Reference type presets", () => {
expect(screen.getByRole("button", { name: /Lead traveler/ })).toBeInTheDocument();
});
- it("opens the type picker immediately for a new definition", () => {
+ it("opens the new-reference picker from the add card", () => {
const state = setup();
- fireEvent.click(screen.getByRole("button", { name: "New definition" }));
+ expect(screen.queryByRole("button", { name: "New definition" })).not.toBeInTheDocument();
+ expect(screen.queryByRole("button", { name: "Add image" })).not.toBeInTheDocument();
+ fireEvent.click(screen.getByRole("button", { name: /Add a reference/ }));
- const dialog = screen.getByRole("dialog", { name: "Choose a reference type" });
+ const dialog = screen.getByRole("dialog", { name: "Add a reference" });
expect(dialog).toBeInTheDocument();
+ expect(state.latest().references).toHaveLength(1);
+ expect(within(dialog).getByRole("button", { name: "Text" })).toHaveAttribute("aria-pressed", "true");
+ fireEvent.click(within(dialog).getByRole("button", { name: "Use Text" }));
expect(state.latest().references[0]).toMatchObject({ name: "New definition", intendedUse: [] });
- expect(within(dialog).getByRole("button", { name: "Custom" })).toHaveAttribute("aria-pressed", "true");
});
it("shows one Type control without the old explanatory copy", () => {
setup();
expect(screen.getByRole("heading", { name: "Type" })).toBeInTheDocument();
- expect(screen.getByRole("button", { name: "Custom" })).toBeInTheDocument();
+ expect(screen.getByRole("button", { name: "Text" })).toBeInTheDocument();
expect(screen.queryByText("Intended use")).not.toBeInTheDocument();
expect(screen.queryByText(/Select any that apply/)).not.toBeInTheDocument();
expect(screen.getByRole("textbox", { name: "Prompt" })).toHaveValue("A traveler with a weathered red coat.");
@@ -78,7 +89,7 @@ describe("Reference type presets", () => {
it("chooses one prepared character from the scalable popup", () => {
const state = setup();
- fireEvent.click(screen.getByRole("button", { name: "Custom" }));
+ fireEvent.click(screen.getByRole("button", { name: "Text" }));
const dialog = screen.getByRole("dialog", { name: "Choose a reference type" });
fireEvent.click(within(dialog).getByRole("button", { name: "Character" }));
const groups = within(dialog).getByRole("group", { name: "Character subcategories" });
@@ -98,7 +109,7 @@ describe("Reference type presets", () => {
it("searches location templates and can return to a custom prompt", () => {
const state = setup();
- fireEvent.click(screen.getByRole("button", { name: "Custom" }));
+ fireEvent.click(screen.getByRole("button", { name: "Text" }));
const dialog = screen.getByRole("dialog", { name: "Choose a reference type" });
fireEvent.click(within(dialog).getByRole("button", { name: "Location" }));
const groups = within(dialog).getByRole("group", { name: "Location subcategories" });
@@ -119,10 +130,37 @@ describe("Reference type presets", () => {
fireEvent.click(screen.getByRole("button", { name: "Location" }));
const reopened = screen.getByRole("dialog", { name: "Choose a reference type" });
- fireEvent.click(within(reopened).getByRole("button", { name: "Custom" }));
- fireEvent.click(within(reopened).getByRole("button", { name: "Use Custom" }));
+ fireEvent.click(within(reopened).getByRole("button", { name: "Text" }));
+ fireEvent.click(within(reopened).getByRole("button", { name: "Use Text" }));
expect(state.latest().references[0].intendedUse).toEqual([]);
expect(screen.getByRole("textbox", { name: "Prompt" })).toHaveValue("Lunar base, at night, in winter.");
});
+
+ it("creates one image-only reference with every selected picture attached", async () => {
+ (window as unknown as Record<string, unknown>).__TAURI_INTERNALS__ = {};
+ vi.mocked(invoke).mockResolvedValue([
+ { name: "front", relativePath: "references/front.png" },
+ { name: "side", relativePath: "references/side.png" },
+ ]);
+ const state = setup();
+
+ fireEvent.click(screen.getByRole("button", { name: /Add a reference/ }));
+ const dialog = screen.getByRole("dialog", { name: "Add a reference" });
+ fireEvent.click(within(dialog).getByRole("button", { name: "Image" }));
+ fireEvent.click(within(dialog).getByRole("button", { name: "Choose images" }));
+
+ await waitFor(() => expect(state.latest().references).toHaveLength(2));
+ expect(invoke).toHaveBeenCalledWith("choose_reference_images", { folderPath: "C:\\\\project" });
+ expect(state.latest().references[0]).toMatchObject({
+ kind: "text",
+ name: "front",
+ description: "",
+ images: [
+ { name: "front", relativePath: "references/front.png" },
+ { name: "side", relativePath: "references/side.png" },
+ ],
+ });
+ expect(state.latest().references[0]).not.toHaveProperty("relativePath");
+ });
});
diff --git a/src/components/workspace/ReferencesView.tsx b/src/components/workspace/ReferencesView.tsx
index 3696be4..94abd02 100644
--- a/src/components/workspace/ReferencesView.tsx
+++ b/src/components/workspace/ReferencesView.tsx
@@ -1,7 +1,7 @@
-import { BookOpen, ChevronRight, FileText, Image, Link2, Plus, Search, Trash2, Upload, Users, X } from "lucide-react";
+import { BookOpen, ChevronRight, FileText, ImagePlus, Link2, Plus, Search, Trash2, Upload, Users, X } from "lucide-react";
import { invoke } from "@tauri-apps/api/core";
import { useMemo, useState } from "react";
-import { isReferenceDescribed, type ProjectConfig, type ProjectReference } from "../../lib/project";
+import { isReferenceDescribed, referenceImages, type ProjectConfig, type ProjectReference, type ProjectReferenceImage } from "../../lib/project";
import {
composeLocationPrompt,
locationSelectionFromPrompt,
@@ -21,58 +21,70 @@ import { ReferenceImage } from "./ReferenceImage";
/** What a reference IS, in a word. This replaced the file path in both places
* it used to be printed: a path is a fact about the disk, not about the
* reference, and neither the card nor the inspector does anything with it. */
-const referenceKindLabel = (kind: ProjectReference["kind"]) =>
- kind === "text" ? "Text definition" : kind === "image" ? "Image" : kind === "video" ? "Video clip" : "Sound";
+const referenceKindLabel = (reference: ProjectReference) => {
+ const count = referenceImages(reference).length;
+ if (count === 0) return reference.kind === "video" ? "Video clip" : reference.kind === "audio" ? "Sound" : "Text definition";
+ return `${count} image${count === 1 ? "" : "s"}${isReferenceDescribed(reference) ? " + text" : ""}`;
+};
export function ReferencesView({ config, folderPath, onChange }: { config: ProjectConfig; folderPath: string; onChange: (next: ProjectConfig) => void }) {
const [selectedId, setSelectedId] = useState<string | undefined>(config.references[0]?.id);
- const [definitionDialog, setDefinitionDialog] = useState(false);
- const [definitionName, setDefinitionName] = useState("Visual style reference");
- const [definitionDescription, setDefinitionDescription] = useState("");
const [importError, setImportError] = useState<string | null>(null);
const [presetDialog, setPresetDialog] = useState(false);
+ const [creatingReference, setCreatingReference] = useState(false);
+ const [pickerSection, setPickerSection] = useState<ReferenceType | "image">("custom");
const [pickerType, setPickerType] = useState<ReferenceType>("custom");
const [pickerSubcategory, setPickerSubcategory] = useState("all");
const [presetSearch, setPresetSearch] = useState("");
const [locationPresetId, setLocationPresetId] = useState<string | null>(null);
const [locationSettings, setLocationSettings] = useState<LocationSettings>({});
const selected = config.references.find((ref) => ref.id === selectedId);
+ const selectedImages = selected ? referenceImages(selected) : [];
const jobs = useMemo(() => config.generationJobs.filter((job) => job.referenceIds.includes(selectedId ?? "")), [config.generationJobs, selectedId]);
const update = (id: string, patch: Partial<ProjectReference>) => onChange({ ...config, references: config.references.map((ref) => ref.id === id ? { ...ref, ...patch } : ref) });
// 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.
- const addTextReference = (name = "New definition", description = "") => {
+ const addTextReference = (name = "New definition", description = "", intendedUse: ProjectReference["intendedUse"] = []) => {
const id = `ref-${Date.now()}`;
- const reference: ProjectReference = { id, kind: "text", name, description, content: description || null, intendedUse: [], createdAt: new Date().toISOString() };
+ const reference: ProjectReference = { id, kind: "text", name, description, content: description || null, intendedUse, createdAt: new Date().toISOString() };
onChange({ ...config, references: [reference, ...config.references] });
setSelectedId(id);
+ return id;
};
- const addDefinition = () => {
- addTextReference();
+ const openNewReference = () => {
+ setCreatingReference(true);
+ setPickerSection("custom");
setPickerType("custom");
setPickerSubcategory("all");
setPresetSearch("");
setPresetDialog(true);
};
- const addImage = async () => {
+ const addImages = async () => {
setImportError(null);
if (!isTauri()) {
- setDefinitionDialog(true);
+ setImportError("Image import is available in the desktop app.");
return;
}
try {
- const imported = await invoke<{ name: string; relativePath: string } | null>("choose_reference_image", { folderPath });
- if (!imported) return;
- const id = `ref-${Date.now()}`;
- // Empty on purpose, exactly like addTextReference. This field is compiled
- // into the prompt as the user's own account of the picture, so a filing
- // note here ("Visual reference copied into this portable project.") was
- // shipped to the model as if they had written it. The card says the
- // definition is missing instead of faking one.
- const reference: ProjectReference = { id, kind: "image", name: imported.name, description: "", relativePath: imported.relativePath, intendedUse: [], createdAt: new Date().toISOString() };
- onChange({ ...config, references: [reference, ...config.references] });
- setSelectedId(id);
+ const imported = await invoke<Array<{ name: string; relativePath: string }>>("choose_reference_images", { folderPath });
+ if (imported.length === 0) return;
+ const stamp = Date.now();
+ const images: ProjectReferenceImage[] = imported.map((image, index) => ({
+ id: `ref-image-${stamp}-${index + 1}`,
+ name: image.name,
+ relativePath: image.relativePath,
+ }));
+ if (creatingReference) {
+ const id = `ref-${stamp}`;
+ const reference: ProjectReference = { id, kind: "text", name: imported[0].name, description: "", content: null, images, intendedUse: [], createdAt: new Date().toISOString() };
+ onChange({ ...config, references: [reference, ...config.references] });
+ setSelectedId(id);
+ setPresetDialog(false);
+ setCreatingReference(false);
+ } else if (selected) {
+ update(selected.id, { images: [...(selected.images ?? []), ...images] });
+ }
} catch (reason) {
setImportError(reason instanceof Error ? reason.message : String(reason));
}
@@ -88,6 +100,8 @@ export function ReferencesView({ config, folderPath, onChange }: { config: Proje
};
const openPresetPicker = () => {
if (!selected) return;
+ setCreatingReference(false);
+ setPickerSection(referenceType(selected));
setPickerType(referenceType(selected));
setPickerSubcategory("all");
setPresetSearch("");
@@ -97,27 +111,33 @@ export function ReferencesView({ config, folderPath, onChange }: { config: Proje
setPresetDialog(true);
};
const chooseCustom = () => {
- if (!selected) return;
- update(selected.id, { intendedUse: [] });
+ if (creatingReference) addTextReference();
+ else if (selected) update(selected.id, { intendedUse: [] });
+ else return;
setPresetDialog(false);
+ setCreatingReference(false);
};
const choosePreset = (preset: ReferencePreset) => {
- if (!selected) return;
if (preset.type === "location") {
setLocationPresetId(preset.id);
setLocationSettings({});
return;
}
- update(selected.id, { intendedUse: [preset.type], description: preset.prompt, content: preset.prompt });
+ if (creatingReference) addTextReference(preset.name, preset.prompt, [preset.type]);
+ else if (selected) update(selected.id, { intendedUse: [preset.type], description: preset.prompt, content: preset.prompt });
+ else return;
setPresetDialog(false);
+ setCreatingReference(false);
};
const chooseLocation = () => {
- if (!selected) return;
const preset = REFERENCE_PRESETS.find((candidate) => candidate.type === "location" && candidate.id === locationPresetId);
if (!preset) return;
const prompt = composeLocationPrompt(preset, locationSettings);
- update(selected.id, { intendedUse: ["location"], description: prompt, content: prompt });
+ if (creatingReference) addTextReference(preset.name, prompt, ["location"]);
+ else if (selected) update(selected.id, { intendedUse: ["location"], description: prompt, content: prompt });
+ else return;
setPresetDialog(false);
+ setCreatingReference(false);
};
const visiblePresets = REFERENCE_PRESETS.filter((preset) => {
if (preset.type !== pickerType) return false;
@@ -137,28 +157,26 @@ export function ReferencesView({ config, folderPath, onChange }: { config: Proje
<h1>References</h1>
<p>{config.references.length === 1 ? "1 reference" : `${config.references.length} references`}</p>
</div>
- <div className="references-heading__actions">
- <button className="secondary-button" onClick={addDefinition}><FileText size={16} /> New definition</button>
- <button className="primary-button" onClick={() => void addImage()}><Upload size={16} /> Add image</button>
- </div>
</header>
<section className="reference-library" aria-labelledby="reference-library-heading">
{/* Both regions used to start at h3, so the outline jumped h1 → h3. */}
<h2 className="sr-only" id="reference-library-heading">Reference library</h2>
<div className="reference-grid">
- {config.references.map((ref) => <button key={ref.id} className={selectedId === ref.id ? "selected" : ""} onClick={() => setSelectedId(ref.id)}>
- {ref.kind === "image" && (ref.relativePath || ref.sourcePath)
- ? <span className="reference-art reference-art--photo"><ReferenceImage folderPath={folderPath} relativePath={ref.relativePath} sourcePath={ref.sourcePath} alt={ref.name} /></span>
- : ref.kind === "image"
- ? <span className="reference-art"><Image size={26} /><em>Image file</em></span>
- : <span className="reference-copy-art"><FileText size={26} /><em>Text definition</em></span>}
- <span className="reference-card__body"><span><b>{ref.name}</b><small>{referenceKindLabel(ref.kind)}</small></span>{isReferenceDescribed(ref)
+ {config.references.map((ref) => {
+ const images = referenceImages(ref);
+ const cover = images[0];
+ return <button key={ref.id} className={selectedId === ref.id ? "selected" : ""} onClick={() => setSelectedId(ref.id)}>
+ {cover
+ ? <span className="reference-art reference-art--photo"><ReferenceImage folderPath={folderPath} relativePath={cover.relativePath} sourcePath={cover.sourcePath} alt={cover.name} /></span>
+ : <span className="reference-copy-art"><FileText size={26} /><em>Text definition</em></span>}
+ <span className="reference-card__body"><span><b>{ref.name}</b><small>{referenceKindLabel(ref)}</small></span>{isReferenceDescribed(ref)
? <p>{ref.description}</p>
- : <p className="reference-card__incomplete">{ref.kind === "image"
+ : <p className="reference-card__incomplete">{images.length > 0
? "Not described yet — the picture is sent, but nothing tells the engine what to keep."
: "Not described yet — it won’t be used until you add a definition."}</p>}<span className="use-tags"><i>{referenceTypeLabel(referenceType(ref))}</i></span></span>
- </button>)}
- <button className="reference-add-card" onClick={() => void addImage()}><span><Plus size={22} /></span><b>Add a reference</b><small>Import an image or write a definition</small></button>
+ </button>;
+ })}
+ <button className="reference-add-card" onClick={openNewReference}><span><Plus size={22} /></span><b>Add a reference</b><small>Import images or write a definition</small></button>
</div>
</section>
</main>
@@ -176,14 +194,14 @@ export function ReferencesView({ config, folderPath, onChange }: { config: Proje
</> : <h2>Reference details</h2>}</header>
<div className="reference-inspector__scroll">
{selected ? <>
- <div className={`reference-detail-art reference-detail-art--${selected.kind}${selected.kind === "image" && (selected.relativePath || selected.sourcePath) ? " reference-detail-art--photo" : ""}`}>
- {selected.kind === "image" && (selected.relativePath || selected.sourcePath)
- ? <ReferenceImage folderPath={folderPath} relativePath={selected.relativePath} sourcePath={selected.sourcePath} alt={selected.name} />
- : <span>{selected.kind === "image" ? <Image size={30} /> : <Users size={30} />}</span>}
+ <div className={`reference-detail-art${selectedImages.length > 0 ? " reference-detail-art--photo" : " reference-detail-art--text"}`}>
+ {selectedImages.length > 0
+ ? <div className="reference-detail-images">{selectedImages.map((image) => <ReferenceImage key={image.id} folderPath={folderPath} relativePath={image.relativePath} sourcePath={image.sourcePath} alt={image.name} />)}</div>
+ : <span><Users size={30} /></span>}
{/* A caption only where there is no picture to look at. It used
to print the file's path over the thumbnail, which is neither
what the reference IS nor anything the user acts on. */}
- {selected.kind !== "image" && <em>{referenceKindLabel(selected.kind)}</em>}
+ {selectedImages.length === 0 && <em>{referenceKindLabel(selected)}</em>}
</div>
<div className="reference-fields">
{referenceType(selected) === "custom" ? <label><span>Prompt</span><textarea value={selected.description} placeholder="Describe what should stay consistent — the traits, materials, colours, or wardrobe PolStudio should preserve across shots." onChange={(event) => update(selected.id, { description: event.target.value, content: event.target.value || null })} /></label> : <div className="reference-preset-summary">
@@ -207,31 +225,28 @@ export function ReferencesView({ config, folderPath, onChange }: { config: Proje
</> : <div className="reference-empty"><BookOpen size={26} /><b>Select a reference</b><p>Pick one from the library, or add a new one, to edit its definition and see which generations use it.</p></div>}
</div>
</aside>
- {definitionDialog && <div className="reference-dialog-backdrop"><div className="reference-dialog" role="dialog" aria-modal="true" aria-labelledby="reference-dialog-title">
- <h2 id="reference-dialog-title">Define a visual reference</h2>
- <p>Image import is available in the desktop app. This browser preview will save an honest text definition without inventing a file path.</p>
- <label><span>Name</span><input value={definitionName} onChange={(event) => setDefinitionName(event.target.value)} /></label>
- <label><span>Definition</span><textarea value={definitionDescription} onChange={(event) => setDefinitionDescription(event.target.value)} placeholder="Describe the composition, materials, colors, or character traits to preserve." /></label>
- <div>
- <button className="secondary-button" onClick={() => setDefinitionDialog(false)}>Cancel</button>
- <button className="primary-button" disabled={!definitionName.trim() || !definitionDescription.trim()} onClick={() => { addTextReference(definitionName.trim(), definitionDescription.trim()); setDefinitionDialog(false); setDefinitionDescription(""); }}>Save text definition</button>
- </div>
- </div></div>}
- {presetDialog && selected && <div className="reference-dialog-backdrop"><div className="reference-preset-dialog" role="dialog" aria-modal="true" aria-labelledby="reference-preset-title">
+ {presetDialog && (creatingReference || selected) && <div className="reference-dialog-backdrop"><div className="reference-preset-dialog" role="dialog" aria-modal="true" aria-labelledby="reference-preset-title">
<header>
- <div><h2 id="reference-preset-title">Choose a reference type</h2><p>Pick one type and one prepared option, or keep a custom prompt.</p></div>
- <button onClick={() => setPresetDialog(false)} aria-label="Close type picker"><X size={18} /></button>
+ <div><h2 id="reference-preset-title">{creatingReference ? "Add a reference" : "Choose a reference type"}</h2><p>Use text, a prepared definition, images, or any combination of text and images.</p></div>
+ <button onClick={() => { setPresetDialog(false); setCreatingReference(false); }} aria-label="Close type picker"><X size={18} /></button>
</header>
<div className="reference-preset-dialog__body">
<nav aria-label="Reference types">
- {REFERENCE_TYPES.map((type) => <button key={type.id} className={pickerType === type.id ? "active" : ""} aria-pressed={pickerType === type.id} onClick={() => { setPickerType(type.id); setPickerSubcategory("all"); setPresetSearch(""); setLocationPresetId(null); setLocationSettings({}); }}>{type.label}<ChevronRight size={16} /></button>)}
+ {REFERENCE_TYPES.map((type) => <button key={type.id} className={pickerSection === type.id ? "active" : ""} aria-pressed={pickerSection === type.id} onClick={() => { setPickerSection(type.id); setPickerType(type.id); setPickerSubcategory("all"); setPresetSearch(""); setLocationPresetId(null); setLocationSettings({}); }}>{type.label}<ChevronRight size={16} /></button>)}
+ <button className={pickerSection === "image" ? "active" : ""} aria-pressed={pickerSection === "image"} onClick={() => setPickerSection("image")}>Image<ChevronRight size={16} /></button>
</nav>
<section>
- {pickerType === "custom" ? <div className="reference-custom-option">
+ {pickerSection === "image" ? <div className="reference-custom-option reference-image-option">
+ <ImagePlus size={28} />
+ <h3>Reference images</h3>
+ <p>{creatingReference ? "Choose one or more pictures. The new reference starts with an empty text prompt that you can describe later." : `Add one or more pictures to this reference. Its ${isReferenceDescribed(selected!) ? "text prompt is kept" : "text prompt can remain empty"}.`}</p>
+ {!creatingReference && selectedImages.length > 0 && <small>{selectedImages.length} image{selectedImages.length === 1 ? "" : "s"} currently attached</small>}
+ <button className="primary-button" onClick={() => void addImages()}><Upload size={16} /> {creatingReference ? "Choose images" : "Add images"}</button>
+ </div> : pickerType === "custom" ? <div className="reference-custom-option">
<FileText size={26} />
- <h3>Custom prompt</h3>
- <p>Keep the current prompt and edit it directly in Reference details.</p>
- <button className="primary-button" onClick={chooseCustom}>Use Custom</button>
+ <h3>Text prompt</h3>
+ <p>{creatingReference ? "Create an empty text definition and write the prompt in Reference details." : "Keep the current prompt and edit it directly in Reference details."}</p>
+ <button className="primary-button" onClick={chooseCustom}>Use Text</button>
</div> : <>
<label className="reference-preset-search"><Search size={17} /><input value={presetSearch} onChange={(event) => setPresetSearch(event.target.value)} placeholder={`Search ${referenceTypeLabel(pickerType).toLocaleLowerCase()} options`} aria-label="Search reference options" /></label>
<div className="reference-subcategories" role="group" aria-label={`${referenceTypeLabel(pickerType)} subcategories`}>
diff --git a/src/components/workspace/SceneEditor.tsx b/src/components/workspace/SceneEditor.tsx
index e644ca7..10c1ca2 100644
--- a/src/components/workspace/SceneEditor.tsx
+++ b/src/components/workspace/SceneEditor.tsx
@@ -5,6 +5,7 @@ import {
danglingReferenceTokens,
isReferenceUsable,
isVisualReference,
+ referenceImages,
normalizeSceneShots,
referenceToken,
sceneBriefText,
@@ -281,7 +282,7 @@ export function SceneInspector({ job, shots, references, disabled, importAvailab
// is written. One place, never a second field that could disagree with it.
const chosen = shots.map((shot) => shot.settings?.[look.id]?.[0]).find(Boolean) ?? "";
const imageReferences = useMemo(
- () => references.filter((reference) => reference.kind === "image" && isReferenceUsable(reference)),
+ () => references.filter((reference) => referenceImages(reference).length > 0 && isReferenceUsable(reference)),
[references],
);
diff --git a/src/lib/reference-presets.ts b/src/lib/reference-presets.ts
index 43c67c3..77d9b94 100644
--- a/src/lib/reference-presets.ts
+++ b/src/lib/reference-presets.ts
@@ -15,7 +15,7 @@ export interface ReferencePreset {
}
export const REFERENCE_TYPES: ReadonlyArray<{ id: ReferenceType; label: string }> = [
- { id: "custom", label: "Custom" },
+ { id: "custom", label: "Text" },
{ id: "character", label: "Character" },
{ id: "product", label: "Product" },
{ id: "location", label: "Location" },
@@ -156,7 +156,7 @@ export function referenceType(reference: ProjectReference): ReferenceType {
}
export const referenceTypeLabel = (type: ReferenceType): string =>
- REFERENCE_TYPES.find((candidate) => candidate.id === type)?.label ?? "Custom";
+ REFERENCE_TYPES.find((candidate) => candidate.id === type)?.label ?? "Text";
export const selectedReferencePreset = (reference: ProjectReference): ReferencePreset | undefined => {
const preset = presetForReference(reference);
diff --git a/src/styles/references.css b/src/styles/references.css
index 65f9205..f7150f7 100644
--- a/src/styles/references.css
+++ b/src/styles/references.css
@@ -203,6 +203,27 @@
padding: var(--space-2) var(--space-2) var(--space-7);
}
+.reference-detail-images {
+ width: 100%;
+ height: 100%;
+ display: flex;
+ align-items: stretch;
+ gap: var(--space-2);
+ overflow-x: auto;
+ padding: var(--space-2);
+}
+
+.reference-detail-art--photo .reference-detail-images img {
+ width: min(220px, 72%);
+ height: 100%;
+ flex: 0 0 auto;
+ padding: 0;
+ border: 1px solid var(--line);
+ border-radius: var(--radius-sm);
+ background: var(--panel-3);
+ object-fit: contain;
+}
+
/* Loading, or the file is not where the project says it is. Two states, said
plainly, rather than one placeholder that could mean either. */
.reference-image-fallback {
@@ -982,6 +1003,16 @@
line-height: var(--leading-normal);
}
+.reference-image-option > small {
+ margin: calc(var(--space-3) * -1) 0 var(--space-4);
+ color: var(--text-secondary);
+ font-size: var(--text-sm);
+}
+
+.reference-image-option .primary-button {
+ gap: var(--space-2);
+}
+
/* --- Responsive ------------------------------------------------------------ */
@media (max-width: 1180px) {