AI media harness for planning, generating, and editing locally
TypeScript
Use the prompt text field for video shot descriptions
Bitti2896ea233a84
diff --git a/src/components/ImageProject.integration.test.tsx b/src/components/ImageProject.integration.test.tsxindex 354d761..05742f5 100644--- a/src/components/ImageProject.integration.test.tsx+++ b/src/components/ImageProject.integration.test.tsx@@ -1,6 +1,7 @@// @vitest-environment jsdomimport "@testing-library/jest-dom/vitest";import { act, cleanup, fireEvent, render, screen, waitFor, within } from "@testing-library/react";+import { typePrompt } from "./workspace/promptTestUtils";import { afterEach, expect, it, vi } from "vitest";import { ProjectWorkspace } from "./ProjectWorkspace";import { PromptComposer } from "./PromptComposer";@@ -16,8 +17,6 @@ import fixture from "../../fixtures/project-v1-image.json";import { invoke } from "@tauri-apps/api/core";import * as persistence from "../lib/persistence";-/* The prompt is a contenteditable: typing is its text and an input event. */-const typePrompt = (field: HTMLElement, text: string) => { field.textContent = text; fireEvent.input(field); };vi.mock("@tauri-apps/api/core", () => ({ invoke: vi.fn() }));vi.mock("@tauri-apps/api/event", () => ({ listen: vi.fn(async () => () => undefined) }));afterEach(() => { cleanup(); localStorage.clear(); vi.restoreAllMocks(); });diff --git a/src/components/ProjectWorkspace.test.ts b/src/components/ProjectWorkspace.test.tsindex 5b4ee19..0f3c07f 100644--- a/src/components/ProjectWorkspace.test.ts+++ b/src/components/ProjectWorkspace.test.ts@@ -2,7 +2,7 @@ import { WorkQueue } from "../lib/workQueue";// @vitest-environment jsdomimport "@testing-library/jest-dom/vitest";-import { act, cleanup, createEvent, fireEvent, render, screen, waitFor, within } from "@testing-library/react";+import { act, cleanup, fireEvent, render, screen, waitFor, within } from "@testing-library/react";import { listen } from "@tauri-apps/api/event";import { createElement } from "react";import { afterEach, describe, expect, it, vi } from "vitest";@@ -12,13 +12,14 @@ import { saveGeneratedScene } from "../lib/generatedVideo";import { formatDurationTimecode, formatSavedAt, formatSequenceLength, isGenerationOngoing } from "./ProjectWorkspace";import { ProjectWorkspace } from "./ProjectWorkspace";import { GeneratorView } from "./workspace/GeneratorView";-import { REFERENCE_DRAG_TYPE } from "./workspace/SceneEditor";+import { changePromptChip, insertPromptReference, placePromptCaret, promptChips, promptValue, typePrompt } from "./workspace/promptTestUtils";import { ReferencesView } from "./workspace/ReferencesView";import { saveDebugOptionsEnabled } from "../lib/settings";import { SHOT_TAG_GROUPS } from "../lib/shot-tags";import { chooseOption, optionNames } from "./workspace/comboTestUtils";vi.mock("@tauri-apps/api/core", () => ({ invoke: vi.fn() }));+const storedLine = (field: HTMLElement) => promptValue(field, (id) => `@[ref:${id}]`);vi.mock("@tauri-apps/api/event", () => ({ listen: vi.fn(async () => () => undefined) }));vi.mock("../lib/generatedVideo", () => ({ saveGeneratedScene: vi.fn(), releaseRendered: vi.fn(async () => true) }));@@ -510,9 +511,9 @@ describe("project workspace timecode", () => {project: { folderPath: "C:\\Ceramic Lamp", config }, initialView: "generator",onBack: () => undefined, onSave: async () => undefined,}));- const line = () => screen.getByRole("textbox", { name: "Describe shot 1" }) as HTMLTextAreaElement;+ const line = () => screen.getByRole("textbox", { name: "Describe shot 1" });openShot(1);- fireEvent.change(line(), { target: { value: "a slow push across the launch pad" } });+ typePrompt(line(), "a slow push across the launch pad");fireEvent.click(screen.getByRole("tab", { name: "Timeline" }));await screen.findByRole("heading", { name: "Timeline", level: 2 });fireEvent.click(screen.getByRole("tab", { name: "Generator" }));@@ -526,7 +527,7 @@ describe("project workspace timecode", () => {a composer the parent has to hold on its behalf — every keystroke lands onthe scene itself, so the project carries them across the trip. Losing theuser's own half-written words is the one thing this app must never do. */- expect(line().value).toBe("a slow push across the launch pad");+ expect(storedLine(line())).toBe("a slow push across the launch pad");});it("does not bind an audio-tagged reference a new shot's prompt would drop", () => {@@ -789,7 +790,7 @@ describe("project workspace timecode", () => {fireEvent.change(screen.getByRole("spinbutton", { name: `Shot ${shotNumber} starts at, in seconds` }), { target: { value: String(startSeconds) } });next = onChange.mock.calls.at(-1)![0];rerender(createElement(GeneratorView, { config: parseProjectConfig(next), folderPath: "C:\\Ceramic Lamp", onChange, onOpenTimeline: () => undefined, selectedJobId: config.generationJobs[0].id }));- fireEvent.change(screen.getByRole("textbox", { name: `Describe shot ${shotNumber}` }), { target: { value: line } });+ typePrompt(screen.getByRole("textbox", { name: `Describe shot ${shotNumber}` }), line);next = onChange.mock.calls.at(-1)![0];rerender(createElement(GeneratorView, { config: parseProjectConfig(next), folderPath: "C:\\Ceramic Lamp", onChange, onOpenTimeline: () => undefined, selectedJobId: config.generationJobs[0].id }));}@@ -887,7 +888,7 @@ describe("project workspace timecode", () => {// One shot, holding the words and the tags the file already had.openShot(1);- expect((screen.getByRole("textbox", { name: "Describe shot 1" }) as HTMLTextAreaElement).value).toBe("A quiet product film");+ expect(storedLine(screen.getByRole("textbox", { name: "Describe shot 1" }))).toBe("A quiet product film");// The legacy per-job tag now reads as a setting ON the shot.expect(screen.getByRole("button", { name: "Remove Lens: Macro from shot 1" })).not.toBeNull();expect(screen.queryByRole("textbox", { name: "Describe shot 2" })).toBeNull();@@ -918,12 +919,12 @@ describe("project workspace timecode", () => {expect((screen.getByRole("slider", { name: "First scene length in seconds" }) as HTMLInputElement).disabled).toBe(false);expect((screen.getByRole("button", { name: "Add a shot to First scene" }) as HTMLButtonElement).disabled).toBe(false);openShot(1);- expect((screen.getByRole("textbox", { name: "Describe shot 1" }) as HTMLTextAreaElement).disabled).toBe(false);+ expect(screen.getByRole("textbox", { name: "Describe shot 1" })).toHaveAttribute("contenteditable", "true");expect((screen.getByRole("combobox", { name: "Add a setting to shot 1" }) as HTMLSelectElement).disabled).toBe(false);expect(screen.queryByText(/It can be changed once it finishes/)).toBeNull();});- it("drops a reference into a line, cites it as a subject, and changes its smart chip", () => {+ it("inserts a reference into a line, cites it as a subject, and changes its smart chip", () => {const fresh = lampProject();const createdAt = fresh.createdAt;const references = [@@ -934,34 +935,33 @@ describe("project workspace timecode", () => {const onChange = vi.fn();const render1 = render(createElement(GeneratorView, { config, folderPath: "C:\\Ceramic Lamp", onChange, onOpenTimeline: () => undefined, selectedJobId: config.generationJobs[0].id }));const show = (next: ProjectConfig) => render1.rerender(createElement(GeneratorView, { config: parseProjectConfig(next), folderPath: "C:\\Ceramic Lamp", onChange, onOpenTimeline: () => undefined, selectedJobId: config.generationJobs[0].id }));+ const line = () => screen.getByRole("textbox", { name: "Describe shot 1" });openShot(1);- // Dragged out of the palette and dropped onto the line.- const drop = (referenceId: string) => {- const field = screen.getByRole("textbox", { name: "Describe shot 1" });- const event = createEvent.drop(field);- Object.defineProperty(event, "dataTransfer", { value: { getData: (type: string) => type === REFERENCE_DRAG_TYPE ? referenceId : "", types: [REFERENCE_DRAG_TYPE] } });- fireEvent(field, event);- };- drop("ref-woman");+ // The picker says which references the scene already numbers.+ fireEvent.click(screen.getByRole("button", { name: "Reference" }));+ expect(within(screen.getByRole("dialog", { name: "Insert a reference" })).getAllByRole("button").map((button) => button.textContent))+ .toEqual(["Red-haired womanNot in this scene yet", "City streetNot in this scene yet"]);+ fireEvent.click(screen.getByRole("button", { name: "Reference" }));+ insertPromptReference("Red-haired woman");let next = onChange.mock.calls.at(-1)![0];// Writing it into the line is what binds it to the scene, which is what// gives it a subject number and a place in reference_paths.expect(next.generationJobs[0].referenceIds).toEqual(["ref-woman"]);show(next);- fireEvent.change(screen.getByRole("textbox", { name: "Describe shot 1" }), { target: { value: "[Reference 1] walks towards the camera on " } });+ typePrompt(line(), "@[ref:ref-woman] walks towards the camera on ");next = onChange.mock.calls.at(-1)![0];show(next);- drop("ref-street");+ placePromptCaret(line());+ insertPromptReference("City street");next = onChange.mock.calls.at(-1)![0];expect(next.generationJobs[0].referenceIds).toEqual(["ref-woman", "ref-street"]);show(next);- // What the user reads in the field is "Reference N"; what is stored is the- // reference's id, so a rename or a reorder cannot re-point the sentence.- expect((screen.getByRole("textbox", { name: "Describe shot 1" }) as HTMLTextAreaElement).value)- .toBe("[Reference 1] walks towards the camera on [Reference 2]");+ // What the user reads in the field is each reference's name, on a chip;+ // what is stored is its id, so a rename or a reorder cannot re-point it.+ expect(promptChips(line())).toEqual(["Red-haired woman", "City street"]);expect(next.generationJobs[0].shots[0].action).toBe("@[ref:ref-woman] walks towards the camera on @[ref:ref-street]");openScene();openDebugPrompt();@@ -974,21 +974,25 @@ describe("project workspace timecode", () => {// Clicking the first reference in the line offers every other one.openShot(1);- const token = screen.getByRole("combobox", { name: "Reference 1 · Red-haired woman — choose another reference" });- expect(token.closest(".shot-action-editor")).not.toBeNull();- expect(screen.queryByText("Every reference in the line can be swapped for another:")).toBeNull();- expect(optionNames(token)).toEqual([- "Reference 1 · Red-haired woman", "Reference 2 · City street", "Remove from the line",- ]);- chooseOption(token, "Reference 2 · City street");+ fireEvent.click(line().querySelectorAll(".prompt-chip")[0]);+ const picker = screen.getByRole("dialog", { name: "Change reference Red-haired woman" });+ expect(within(picker).getAllByRole("button").map((button) => button.textContent))+ .toEqual(["Red-haired womanReference 1", "City streetReference 2", "Remove from the prompt"]);+ fireEvent.click(within(picker).getByRole("button", { name: /^City street/ }));next = onChange.mock.calls.at(-1)![0];show(next);expect(next.generationJobs[0].shots[0].action).toBe("@[ref:ref-street] walks towards the camera on @[ref:ref-street]");openScene();expect(compiled()).toContain("<Subject 2> walks towards the camera on <Subject 2>");++ // A reference that can no longer be cited stays on its chip, marked.+ openShot(1);+ show({ ...next, references: next.references.filter((reference: { id: string }) => reference.id !== "ref-street") });+ expect(line().querySelector(".prompt-chip--missing")).toHaveTextContent("Deleted reference");+ expect(screen.getByText("A reference can’t be used")).toBeInTheDocument();});- it("keeps a word off the citation wherever in the line it is dropped", () => {+ it("keeps a word off the citation wherever in the line it is inserted", () => {/* The caret has two sides and the insert used to look at one of them. Atthe START of a line there is nothing in front of the token, so nothingforced a space after it and the sentence compiled to@@ -1003,30 +1007,27 @@ describe("project workspace timecode", () => {];const start = parseProjectConfig({ ...fresh, references, generationJobs: [{ ...fresh.generationJobs[0], shots: [{ id: "shot-a", startSeconds: 0, action: "walks towards the camera and stops." }], referenceIds: [] }] });- /* Each case drops the same reference at a different caret offset into the+ /* Each case inserts the same reference at a different caret offset into thesame untouched line, so the only variable is where it landed. */- const dropAt = (caret: number): string => {+ const insertAt = (caret: number): string => {let config = start;const onChange = vi.fn((next: ProjectConfig) => { config = parseProjectConfig(next); });const view = () => createElement(GeneratorView, { config, folderPath: "C:\\Ceramic Lamp", onChange, onOpenTimeline: () => undefined, selectedJobId: start.generationJobs[0].id });const app = render(view());openShot(1);- const field = screen.getByRole("textbox", { name: "Describe shot 1" }) as HTMLTextAreaElement;- field.setSelectionRange(caret, caret);- const event = createEvent.drop(field);- Object.defineProperty(event, "dataTransfer", { value: { getData: (type: string) => type === REFERENCE_DRAG_TYPE ? "ref-woman" : "", types: [REFERENCE_DRAG_TYPE] } });- fireEvent(field, event);+ placePromptCaret(screen.getByRole("textbox", { name: "Describe shot 1" }), caret);+ insertPromptReference("Red-haired woman");app.unmount();return config.generationJobs[0].shots![0].action;};const line = "walks towards the camera and stops.";- expect(dropAt(0)).toBe(`@[ref:ref-woman] ${line}`);- expect(dropAt(line.length)).toBe(`${line} @[ref:ref-woman]`);+ expect(insertAt(0)).toBe(`@[ref:ref-woman] ${line}`);+ expect(insertAt(line.length)).toBe(`${line} @[ref:ref-woman]`);/* Between two words, from either side of the space that separates them:one space each side, never two and never none. */- expect(dropAt("walks towards ".length)).toBe("walks towards @[ref:ref-woman] the camera and stops.");- expect(dropAt("walks towards".length)).toBe("walks towards @[ref:ref-woman] the camera and stops.");+ expect(insertAt("walks towards ".length)).toBe("walks towards @[ref:ref-woman] the camera and stops.");+ expect(insertAt("walks towards".length)).toBe("walks towards @[ref:ref-woman] the camera and stops.");});@@ -1051,6 +1052,7 @@ describe("project workspace timecode", () => {const show = () => app.rerender(view());const set = (role: string, name: string, value: string) => {if (role === "combobox") chooseTag(name, value);+ else if (name.startsWith("Describe shot")) typePrompt(screen.getByRole(role, { name }), value);else fireEvent.change(screen.getByRole(role, { name }), { target: { value } });show();};@@ -1060,11 +1062,9 @@ describe("project workspace timecode", () => {exactly as the user would. */const shot = (shotNumber: number) => { openShot(shotNumber, "First scene"); show(); };const scene = () => { openScene("First scene"); show(); };- const dropReference = (referenceId: string, shotNumber: number) => {- const field = screen.getByRole("textbox", { name: `Describe shot ${shotNumber}` });- const event = createEvent.drop(field);- Object.defineProperty(event, "dataTransfer", { value: { getData: (type: string) => type === REFERENCE_DRAG_TYPE ? referenceId : "", types: [REFERENCE_DRAG_TYPE] } });- fireEvent(field, event);+ const insertReference = (name: string, shotNumber: number) => {+ placePromptCaret(screen.getByRole("textbox", { name: `Describe shot ${shotNumber}` }));+ insertPromptReference(name);show();};@@ -1072,19 +1072,19 @@ describe("project workspace timecode", () => {press("Add a shot to First scene");press("Add a shot to First scene");- // The street is dropped FIRST and the woman second, but the numbering+ // The street is inserted FIRST and the woman second, but the numbering// follows the project's reference order once both are bound — which is the// order reference_paths is built in, so <Subject 1> is <Picture 1>.shot(1);- dropReference("ref-street", 1);- dropReference("ref-woman", 1);- set("textbox", "Describe shot 1", "[Reference 1] walks towards the camera on [Reference 2]");+ insertReference("City street", 1);+ insertReference("Red-haired woman", 1);+ set("textbox", "Describe shot 1", "@[ref:ref-woman] walks towards the camera on @[ref:ref-street]");shot(2);set("spinbutton", "Shot 2 starts at, in seconds", "4.5");set("textbox", "Describe shot 2", "she stops at a doorway and looks up");shot(3);set("spinbutton", "Shot 3 starts at, in seconds", "9");- set("textbox", "Describe shot 3", "the door opens and light spills across [Reference 2]");+ set("textbox", "Describe shot 3", "the door opens and light spills across @[ref:ref-street]");shot(1);set("combobox", "Add a setting to shot 1", "cameraMovement");@@ -1099,11 +1099,10 @@ describe("project workspace timecode", () => {set("textbox", "The sound of this scene", "Rain on cobbles, distant traffic, her boots on stone.");set("textbox", "The music of this scene", "Low sustained cello, slow tempo, swelling in the last two seconds.");- // What the field shows is "Reference N"; what is stored is the id, so a- // rename or a reorder cannot re-point the sentence.+ // What the field shows is each name on a chip; what is stored is the id,+ // so a rename or a reorder cannot re-point the sentence.shot(1);- expect((screen.getByRole("textbox", { name: "Describe shot 1" }) as HTMLTextAreaElement).value)- .toBe("[Reference 1] walks towards the camera on [Reference 2]");+ expect(promptChips(screen.getByRole("textbox", { name: "Describe shot 1" }))).toEqual(["Red-haired woman", "City street"]);expect(config.generationJobs[0].shots![0].action).toBe("@[ref:ref-woman] walks towards the camera on @[ref:ref-street]");expect(config.generationJobs[0].durationSeconds).toBe(12);expect(config.generationJobs[0].shots!.map((item) => item.startSeconds)).toEqual([0, 4.5, 9]);@@ -1158,10 +1157,7 @@ describe("project workspace timecode", () => {// And the swap: the same sentence, pointed at the other reference.shot(1);- const token = document.querySelector(".reference-smart-chip") as HTMLElement;- expect(optionNames(token))- .toEqual(["Reference 1 · Red-haired woman", "Reference 2 · City street", "Remove from the line"]);- chooseOption(token, "Reference 2 · City street");+ changePromptChip(screen.getByRole("textbox", { name: "Describe shot 1" }), 0, "City street");show();scene();expect(document.querySelector(".compiled-prompt__text")!.textContent)diff --git a/src/components/workspace/GeneratorView.test.tsx b/src/components/workspace/GeneratorView.test.tsxindex 1a33f1a..e4afb64 100644--- a/src/components/workspace/GeneratorView.test.tsx+++ b/src/components/workspace/GeneratorView.test.tsx@@ -9,6 +9,7 @@ import { cancelSlopfabGeneration, getEngineStatus, type SlopfabStatus } from "..import { askNative } from "../../lib/nativeShell";import { GeneratorView, templateSceneBlocker } from "./GeneratorView";import { choose, chooseOption, comboValue, optionNames } from "./comboTestUtils";+import { insertPromptReference, placePromptCaret, typePrompt } from "./promptTestUtils";import { minimaxOriginalTemplate, viggleAnimateTemplate, saveDebugOptionsEnabled } from "../../lib/settings";vi.mock("../../lib/nativeShell", async (importOriginal) => ({@@ -164,7 +165,7 @@ it("submits Pose from the scene panel with its video and optional prompt referenexpect(generate).toBeDisabled();choose("Pose video reference for this scene", "Motion");expect(generate).toBeDisabled();- fireEvent.change(screen.getByLabelText("Describe shot 1"), { target: { value: "A dancer on a rainy street." } });+ typePrompt(screen.getByLabelText("Describe shot 1"), "A dancer on a rainy street.");expect(generate).toBeEnabled();fireEvent.click(generate);expect(submitted.mock.calls[0][0][0].request).toMatchObject({@@ -172,7 +173,8 @@ it("submits Pose from the scene panel with its video and optional prompt referenreferencePaths: [],referenceVideos: [{ name: "Motion", sourcePath: "C:/motion.mp4", startSeconds: 1, durationSeconds: 3, includeAudio: false }],});- fireEvent.click(screen.getByRole("button", { name: /Not in this scene yet Hero/ }));+ placePromptCaret(screen.getByLabelText("Describe shot 1"));+ insertPromptReference("Hero");expect(latest.generationJobs[0].shots![0].action).toContain("@[ref:hero]");fireEvent.click(generate);expect(submitted.mock.calls.at(-1)![0][0].request.referencePaths).toEqual(["C:/project/references/hero.png"]);@@ -238,7 +240,7 @@ it.each(["extend", "bridge"] as const)("submits %s with ordered video anchors anexpect(request.prompt).toContain("The dancer turns toward the door.");expect(parseProjectConfig(JSON.parse(JSON.stringify(latest))).generationJobs[0].startVideoReferenceId).toBe("start");fireEvent.click(screen.getByRole("button", { name: "Shot 1 of Transition" }));- fireEvent.change(screen.getByLabelText("Describe shot 1"), { target: { value: "" } });+ typePrompt(screen.getByLabelText("Describe shot 1"), "");expect(generate).toBeDisabled();});diff --git a/src/components/workspace/GeneratorView.tsx b/src/components/workspace/GeneratorView.tsxindex e24a6bb..c5291f6 100644--- a/src/components/workspace/GeneratorView.tsx+++ b/src/components/workspace/GeneratorView.tsx@@ -638,6 +638,7 @@ export function GeneratorView({ config, folderPath, runtime = null, generationCoendsAt={shotEndsAt}duration={sceneDurationSeconds(selected)}references={isVideoTransition(selected) ? sceneGenerationReferences(selected, config.references) : config.references}+ folderPath={folderPath}disabled={false}onChange={(updates) => patchShot(selected, openShot.id, updates)}/>@@ -679,6 +680,7 @@ export function GeneratorView({ config, folderPath, runtime = null, generationCodefaultLook={config.settings.defaultLook}disabled={false}references={config.references}+ folderPath={folderPath}importAvailable={isTauri()}importError={startFrameError}previousScene={jobs[jobs.findIndex((job) => job.id === selected.id) - 1]}diff --git a/src/components/workspace/ImageEditor.test.tsx b/src/components/workspace/ImageEditor.test.tsxindex d5e03bf..e41285b 100644--- a/src/components/workspace/ImageEditor.test.tsx+++ b/src/components/workspace/ImageEditor.test.tsx@@ -2,6 +2,7 @@import "@testing-library/jest-dom/vitest";import { useState } from "react";import { cleanup, createEvent, fireEvent, render, screen, waitFor, within } from "@testing-library/react";+import { promptValue, typePrompt } from "./promptTestUtils";import { afterEach, expect, it, vi } from "vitest";import { ImageEditor } from "./ImageEditor";import { choose, comboValue } from "./comboTestUtils";@@ -15,11 +16,6 @@ import * as persistence from "../../lib/persistence";import fixture from "../../../fixtures/project-v1-image.json";import snapshotFixture from "../../../fixtures/image-generation-snapshot.json";-/* The prompt is a contenteditable: typing is its text and an input event. */-const typePrompt = (field: HTMLElement, text: string) => { field.textContent = text; fireEvent.input(field); };-/* Reads a chip back as the [Name] it stands for, as the value stores it. */-const promptValue = (field: HTMLElement) => [...field.childNodes].map((node) => node instanceof HTMLElement && node.dataset.promptReference !== undefined- ? `[${node.dataset.promptReference}]` : node.textContent ?? "").join("").replaceAll("", "");vi.mock("@tauri-apps/api/core", () => ({ invoke: vi.fn() }));afterEach(() => { cleanup(); localStorage.clear(); vi.restoreAllMocks(); });function setup(initial = parseProjectConfig(fixture)) {diff --git a/src/components/workspace/PromptTextField.test.tsx b/src/components/workspace/PromptTextField.test.tsxindex 03b76f4..bcef944 100644--- a/src/components/workspace/PromptTextField.test.tsx+++ b/src/components/workspace/PromptTextField.test.tsx@@ -58,7 +58,7 @@ it("inserts the chosen reference at the caret from the toolbar", () => {expect(screen.getByRole("button", { name: "Odd [v2]" })).toBeDisabled();expect(screen.getByRole("button", { name: "Hero" })).toContainElement(screen.getByTestId("hero-icon"));fireEvent.click(screen.getByRole("button", { name: "Hero" }));- expect(value()).toBe("A [Hero]knight rides");+ expect(value()).toBe("A [Hero] knight rides");expect(onInsert).toHaveBeenCalledWith(references[0]);expect(field.querySelector(".prompt-chip")).toHaveTextContent("Hero");expect(screen.queryByRole("dialog")).toBeNull();diff --git a/src/components/workspace/PromptTextField.tsx b/src/components/workspace/PromptTextField.tsxindex 3ea1969..179f893 100644--- a/src/components/workspace/PromptTextField.tsx+++ b/src/components/workspace/PromptTextField.tsx@@ -1,5 +1,5 @@import { useEffect, useLayoutEffect, useRef, useState, type CSSProperties, type KeyboardEvent as ReactKeyboardEvent, type ReactNode } from "react";-import { canCitePromptReference, promptReferenceToken, splitPromptText } from "../../lib/promptReferences";+import { canCitePromptReference, promptReferenceToken, splitPromptText, type PromptPart } from "../../lib/promptReferences";import { Add14, Delete14 } from "../ui/icons";import { Flyout, TextField } from "../ui";import "../../styles/prompt-field.css";@@ -13,18 +13,37 @@ export interface PromptReference {detail?: string;}+/** How references are written into the value. Each chip stands for one token+ * and carries its key: what `split` reads out of the token and `token` writes+ * back. */+export interface PromptTokenFormat {+ split: (text: string) => PromptPart[];+ token: (key: string) => string;+ key: (reference: PromptReference) => string;+ /** Why a reference cannot be written as a token, or null when it can. */+ uncitable?: (reference: PromptReference) => string | null;+}++/** `[Name]` — readable in the saved text, and what a person may type by hand. */+export const NAME_TOKENS: PromptTokenFormat = {+ split: splitPromptText,+ token: promptReferenceToken,+ key: (reference) => reference.name,+ uncitable: (reference) => canCitePromptReference(reference.name) ? null : "Rename it without brackets to cite it in a prompt",+};+/* A multi-line prompt whose references are smart chips inside the text.- The value is plain text; a reference is written into it as `[Name]` (see- lib/promptReferences) and the field shows every such token as a chip. The- Reference button on the toolbar above opens a picker and drops the chosen- reference at the caret; clicking a chip opens the same picker to change it- to another reference or take it out.+ The value is plain text with each reference written into it as a token —+ `[Name]` by default (see lib/promptReferences), or any other `format` — and+ the field shows every token as a chip. The Reference button on the toolbar+ above opens a picker and drops the chosen reference at the caret; clicking a+ chip opens the same picker to change it to another reference or take it out.The editable surface is a contenteditable the component writes itself,not React children, so React never reconciles against what the browsertyped. It is rebuilt from the value only when the two disagree — a change- from outside, a chip picked, or `[Name]` typed out by hand — and the caret+ from outside, a chip picked, or a token typed out by hand — and the caretis put back by its offset in the text. */const CHIP = "data-prompt-reference";@@ -38,14 +57,25 @@ interface Picking {anchor: HTMLElement;start: number;end: number;- /** The chip being changed; none when inserting. */+ /** The key of the chip being changed; none when inserting. */current: string | null;}-export function PromptTextField({ value, onChange, references, onInsertReference, disabled = false, placeholder, rows = 4, id, className, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy }: {+interface Chips {+ format: PromptTokenFormat;+ byKey: ReadonlyMap<string, PromptReference>;+ /** What a chip whose key no reference in the list has is called. */+ missingLabel: (key: string) => string;+}++export function PromptTextField({ value, onChange, references, format = NAME_TOKENS, missingLabel = (key) => key, missingTooltip = "No reference has this name — click to choose one", onInsertReference, disabled = false, placeholder, rows = 4, id, className, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy }: {value: string;onChange: (value: string) => void;+ /** The references the picker offers; a chip for any other key is missing. */references: readonly PromptReference[];+ format?: PromptTokenFormat;+ missingLabel?: (key: string) => string;+ missingTooltip?: string;/** Called with the reference a chip was made from, inserted or changed to. */onInsertReference?: (reference: PromptReference) => void;disabled?: boolean;@@ -62,41 +92,43 @@ export function PromptTextField({ value, onChange, references, onInsertReferenceconst selection = useRef<{ start: number; end: number } | null>(null);const pendingCaret = useRef<number | null>(null);const [picking, setPicking] = useState<Picking | null>(null);- const known = new Set(references.map((reference) => reference.name));- const knownKey = [...known].join("\n");+ const chips: Chips = { format, byKey: new Map(references.map((reference) => [format.key(reference), reference])), missingLabel };+ const label = (key: string) => chips.byKey.get(key)?.name ?? missingLabel(key);+ // What a chip shows: a rename or a reference coming and going redraws them.+ const chipsKey = references.map((reference) => `${format.key(reference)}\u0000${reference.name}`).join("\n");/* Rebuilt when the value no longer matches what is on screen, or when a- reference is added, removed or renamed and a chip's broken state flips. */- const renderedKnown = useRef<string | null>(null);+ reference is added, removed or renamed and a chip's label or state flips. */+ const renderedChips = useRef<string | null>(null);useLayoutEffect(() => {const root = field.current;if (!root) return;- const caret = pendingCaret.current ?? (document.activeElement === root ? caretRange(root)?.end ?? null : null);- if (serialize(root) !== value || renderedKnown.current !== knownKey || needsRender(root)) {- render(root, value, known);- renderedKnown.current = knownKey;- if (caret !== null && document.activeElement === root) placeCaret(root, caret);+ const caret = pendingCaret.current ?? (document.activeElement === root ? caretRange(root, format)?.end ?? null : null);+ if (serialize(root, format) !== value || renderedChips.current !== chipsKey || needsRender(root, format)) {+ render(root, value, chips, missingTooltip);+ renderedChips.current = chipsKey;+ if (caret !== null && document.activeElement === root) placeCaret(root, caret, format);}if (pendingCaret.current !== null) {root.focus();- placeCaret(root, pendingCaret.current);+ placeCaret(root, pendingCaret.current, format);selection.current = { start: pendingCaret.current, end: pendingCaret.current };pendingCaret.current = null;}// eslint-disable-next-line react-hooks/exhaustive-deps- }, [value, knownKey]);+ }, [value, chipsKey]);/* The toolbar button takes the focus, so where the caret was is kept as itmoves; a reference goes there, or at the end of a field never focused. */useEffect(() => {const remember = () => {const root = field.current;- const range = root && caretRange(root);+ const range = root && caretRange(root, format);if (range) selection.current = range;};document.addEventListener("selectionchange", remember);return () => document.removeEventListener("selectionchange", remember);- }, []);+ }, [format]);const replace = (start: number, end: number, text: string) => {pendingCaret.current = start + text.length;@@ -105,20 +137,20 @@ export function PromptTextField({ value, onChange, references, onInsertReference// Nothing to re-render, but the caret still has to come back.const root = field.current!;root.focus();- placeCaret(root, pendingCaret.current);+ placeCaret(root, pendingCaret.current, format);pendingCaret.current = null;} else onChange(next);};const input = (native: Event) => {const root = field.current!;- const next = serialize(root);- // Chrome writes a chip out of `[Name]` typed by hand only once the- // composition (an IME, a dead key) is over.- if (!(native as InputEvent).isComposing && needsRender(root)) {- const caret = caretRange(root)?.end ?? next.length;- render(root, next, known);- placeCaret(root, caret);+ const next = serialize(root, format);+ // A token typed by hand becomes a chip only once the composition (an+ // IME, a dead key) is over.+ if (!(native as InputEvent).isComposing && needsRender(root, format)) {+ const caret = caretRange(root, format)?.end ?? next.length;+ render(root, next, chips, missingTooltip);+ placeCaret(root, caret, format);}if (next !== value) onChange(next);};@@ -127,7 +159,7 @@ export function PromptTextField({ value, onChange, references, onInsertReferenceif (event.key !== "Enter" || event.nativeEvent.isComposing) return;// A line break is a character of the value, not a <div> the browser adds.event.preventDefault();- const range = caretRange(field.current!) ?? { start: value.length, end: value.length };+ const range = caretRange(field.current!, format) ?? { start: value.length, end: value.length };replace(range.start, range.end, "\n");};@@ -138,9 +170,14 @@ export function PromptTextField({ value, onChange, references, onInsertReferenceconst choose = (reference: PromptReference) => {if (!picking) return;- const { start, end } = picking;+ const { start, end, current } = picking;setPicking(null);- replace(start, end, promptReferenceToken(reference.name));+ // A new chip never touches a word: a citation fused to one reads as a+ // malformed token ("<Subject 1>walks") once the prompt is compiled. A+ // changed chip keeps the spacing it had.+ const lead = current === null && start > 0 && !/\s/.test(value[start - 1]) ? " " : "";+ const trail = current === null && end < value.length && !/\s/.test(value[end]) ? " " : "";+ replace(start, end, `${lead}${format.token(format.key(reference))}${trail}`);onInsertReference?.(reference);};@@ -184,7 +221,7 @@ export function PromptTextField({ value, onChange, references, onInsertReference// elements the value has no way to say.event.preventDefault();const text = event.clipboardData.getData("text/plain").replace(/\r\n?/g, "\n");- const range = caretRange(field.current!) ?? { start: value.length, end: value.length };+ const range = caretRange(field.current!, format) ?? { start: value.length, end: value.length };replace(range.start, range.end, text);}}onDrop={(event) => event.preventDefault()}@@ -192,14 +229,16 @@ export function PromptTextField({ value, onChange, references, onInsertReferenceconst chip = (event.target as HTMLElement).closest<HTMLElement>(`[${CHIP}]`);if (!chip || !field.current) return;event.preventDefault();- const start = offsetBefore(field.current, chip);- const name = chip.getAttribute(CHIP)!;- openPicker(chip, start, start + promptReferenceToken(name).length, name);+ const start = offsetBefore(field.current, chip, format);+ const key = chip.getAttribute(CHIP)!;+ openPicker(chip, start, start + format.token(key).length, key);}}/><ReferencePickerpicking={picking}references={references}+ format={format}+ label={label}onChoose={choose}onRemove={() => {if (!picking) return;@@ -211,9 +250,11 @@ export function PromptTextField({ value, onChange, references, onInsertReference</div>;}-function ReferencePicker({ picking, references, onChoose, onRemove, onClose }: {+function ReferencePicker({ picking, references, format, label, onChoose, onRemove, onClose }: {picking: Picking | null;references: readonly PromptReference[];+ format: PromptTokenFormat;+ label: (key: string) => string;onChoose: (reference: PromptReference) => void;onRemove: () => void;onClose: () => void;@@ -224,7 +265,8 @@ function ReferencePicker({ picking, references, onChoose, onRemove, onClose }: {useEffect(() => { if (picking) setFilter(""); }, [picking]);const query = filter.trim().toLowerCase();const shown = references.filter((reference) => !query || reference.name.toLowerCase().includes(query));- const missing = picking?.current != null && !references.some((reference) => reference.name === picking.current);+ const current = picking?.current ?? null;+ const missing = current !== null && !references.some((reference) => format.key(reference) === current);const move = (event: ReactKeyboardEvent, step: number) => {const options = [...(list.current?.querySelectorAll<HTMLButtonElement>("button:not(:disabled)") ?? [])];@@ -238,13 +280,13 @@ function ReferencePicker({ picking, references, onChoose, onRemove, onClose }: {open={Boolean(picking)}anchor={picking?.anchor ?? null}onClose={onClose}- aria-label={picking?.current != null ? `Change reference ${picking.current}` : "Insert a reference"}+ aria-label={current !== null ? `Change reference ${label(current)}` : "Insert a reference"}className="prompt-reference-picker"initialFocus={filterInput}width={280}>- {picking?.current != null && <p className="prompt-reference-picker__current">- {missing ? <>No reference is named <b>{picking.current}</b>. Choose one to cite instead.</> : <>Cites <b>{picking.current}</b></>}+ {current !== null && <p className="prompt-reference-picker__current">+ {missing ? <><b>{label(current)}</b> can’t be used. Choose a reference to cite instead.</> : <>Cites <b>{label(current)}</b></>}</p>}{references.length > 6 && <TextFieldinputRef={filterInput}@@ -254,7 +296,7 @@ function ReferencePicker({ picking, references, onChoose, onRemove, onClose }: {aria-label="Find a reference"onKeyDown={(event) => {if (event.key === "ArrowDown") move(event, 1);- if (event.key === "Enter" && shown.length) { event.preventDefault(); if (canCitePromptReference(shown[0].name)) onChoose(shown[0]); }+ if (event.key === "Enter" && shown.length) { event.preventDefault(); if (!format.uncitable?.(shown[0])) onChoose(shown[0]); }}}/>}<div ref={list} className="prompt-reference-picker__list" role="group" aria-label="References" onKeyDown={(event) => {@@ -262,14 +304,14 @@ function ReferencePicker({ picking, references, onChoose, onRemove, onClose }: {if (event.key === "ArrowUp") move(event, -1);}}>{shown.map((reference) => {- const citable = canCitePromptReference(reference.name);+ const why = format.uncitable?.(reference) ?? null;return <buttonkey={reference.id}type="button"className="prompt-reference-picker__option ui-selectable"- aria-pressed={reference.name === picking?.current}- disabled={!citable}- data-tooltip={citable ? undefined : "Rename it without brackets to cite it in a prompt"}+ aria-pressed={format.key(reference) === current}+ disabled={why !== null}+ data-tooltip={why ?? undefined}onClick={() => onChoose(reference)}>{reference.icon && <span className="prompt-reference-picker__icon" aria-hidden="true">{reference.icon}</span>}@@ -279,7 +321,7 @@ function ReferencePicker({ picking, references, onChoose, onRemove, onClose }: {{!references.length && <p className="prompt-reference-picker__empty">No references yet — add them under References.</p>}{references.length > 0 && !shown.length && <p className="prompt-reference-picker__empty">No reference matches “{filter.trim()}”.</p>}</div>- {picking?.current != null && <button type="button" className="prompt-reference-picker__option prompt-reference-picker__remove" onClick={onRemove}>+ {current !== null && <button type="button" className="prompt-reference-picker__option prompt-reference-picker__remove" onClick={onRemove}><span className="prompt-reference-picker__icon" aria-hidden="true"><Delete14 /></span>Remove from the prompt</button>}</Flyout>;@@ -287,21 +329,23 @@ function ReferencePicker({ picking, references, onChoose, onRemove, onClose }: {/* --- The editable surface ------------------------------------------------ */-function chipElement(name: string, known: ReadonlySet<string>): HTMLElement {+function chipElement(key: string, chips: Chips, missingTooltip: string): HTMLElement {+ const reference = chips.byKey.get(key);+ const name = reference?.name ?? chips.missingLabel(key);const chip = document.createElement("span");- chip.setAttribute(CHIP, name);+ chip.setAttribute(CHIP, key);chip.setAttribute("contenteditable", "false");- chip.className = known.has(name) ? "prompt-chip" : "prompt-chip prompt-chip--missing";+ chip.className = reference ? "prompt-chip" : "prompt-chip prompt-chip--missing";chip.setAttribute("role", "button");- chip.setAttribute("aria-label", known.has(name) ? `Reference ${name}` : `Missing reference ${name}`);- chip.dataset.tooltip = known.has(name) ? "Change or remove this reference" : "No reference has this name — click to choose one";+ chip.setAttribute("aria-label", reference ? `Reference ${name}` : `Missing reference ${name}`);+ chip.dataset.tooltip = reference ? "Change or remove this reference" : missingTooltip;chip.textContent = name;return chip;}-function render(root: HTMLElement, value: string, known: ReadonlySet<string>) {- const parts = splitPromptText(value);- root.replaceChildren(...parts.map((part) => part.kind === "text" ? document.createTextNode(part.value) : chipElement(part.value, known)));+function render(root: HTMLElement, value: string, chips: Chips, missingTooltip: string) {+ const parts = chips.format.split(value);+ root.replaceChildren(...parts.map((part) => part.kind === "text" ? document.createTextNode(part.value) : chipElement(part.value, chips, missingTooltip)));if (parts.at(-1)?.kind === "reference") root.append(document.createTextNode(CARET_ROOM));// A closing line break draws no line of its own without something after it.if (value.endsWith("\n")) {@@ -313,17 +357,17 @@ function render(root: HTMLElement, value: string, known: ReadonlySet<string>) {/** The value a subtree stands for. Takes a fragment too, so the text before* the caret is measured by the same rule as the whole. */-function serialize(node: Node): string {+function serialize(node: Node, format: PromptTokenFormat): string {let out = "";node.childNodes.forEach((child) => {if (child.nodeType === Node.TEXT_NODE) out += (child.textContent ?? "").replaceAll(CARET_ROOM, "");else if (child instanceof HTMLElement) {- if (child.hasAttribute(CHIP)) out += promptReferenceToken(child.getAttribute(CHIP)!);+ if (child.hasAttribute(CHIP)) out += format.token(child.getAttribute(CHIP)!);else if (child.tagName === "BR") out += child.hasAttribute(END) ? "" : "\n";else {// A block the browser wrapped a line in starts a new line.if ((child.tagName === "DIV" || child.tagName === "P") && out && !out.endsWith("\n")) out += "\n";- out += serialize(child);+ out += serialize(child, format);}}});@@ -331,26 +375,26 @@ function serialize(node: Node): string {}/** Whether the surface holds anything `render` would not have written: a- * `[Name]` still as text, a stray element, or typing beside a caret room. */-function needsRender(root: HTMLElement): boolean {+ * token still as text, a stray element, or typing beside a caret room. */+function needsRender(root: HTMLElement, format: PromptTokenFormat): boolean {return [...root.childNodes].some((child) => {if (child.nodeType === Node.TEXT_NODE) {const text = child.textContent ?? "";- return splitPromptText(text.replaceAll(CARET_ROOM, "")).some((part) => part.kind === "reference") || (text.includes(CARET_ROOM) && text !== CARET_ROOM);+ return format.split(text.replaceAll(CARET_ROOM, "")).some((part) => part.kind === "reference") || (text.includes(CARET_ROOM) && text !== CARET_ROOM);}return !(child instanceof HTMLElement && (child.hasAttribute(CHIP) || child.hasAttribute(END)));}) || (root.lastChild?.nodeType === Node.ELEMENT_NODE && (root.lastChild as HTMLElement).hasAttribute(CHIP));}-function offsetBefore(root: HTMLElement, node: Node): number {+function offsetBefore(root: HTMLElement, node: Node, format: PromptTokenFormat): number {const range = document.createRange();range.selectNodeContents(root);range.setEndBefore(node);- return serialize(range.cloneContents()).length;+ return serialize(range.cloneContents(), format).length;}/** The selection as offsets into the value, or null when it is not in the field. */-function caretRange(root: HTMLElement): { start: number; end: number } | null {+function caretRange(root: HTMLElement, format: PromptTokenFormat): { start: number; end: number } | null {const selection = document.getSelection();if (!selection?.rangeCount) return null;const range = selection.getRangeAt(0);@@ -359,17 +403,17 @@ function caretRange(root: HTMLElement): { start: number; end: number } | null {const before = document.createRange();before.selectNodeContents(root);before.setEnd(container, offset);- return serialize(before.cloneContents()).length;+ return serialize(before.cloneContents(), format).length;};return { start: measure(range.startContainer, range.startOffset), end: measure(range.endContainer, range.endOffset) };}-function placeCaret(root: HTMLElement, offset: number) {+function placeCaret(root: HTMLElement, offset: number, format: PromptTokenFormat) {const range = document.createRange();let remaining = offset;let placed = false;for (const child of [...root.childNodes]) {- const length = serialize(wrap(child)).length;+ const length = serialize(wrap(child), format).length;if (child.nodeType === Node.TEXT_NODE && remaining <= length) {// The caret room is invisible: offset 0 inside it is right after the chip.range.setStart(child, child.textContent === CARET_ROOM ? 0 : remaining);diff --git a/src/components/workspace/SceneEditor.tsx b/src/components/workspace/SceneEditor.tsxindex 8b4a5b3..296e609 100644--- a/src/components/workspace/SceneEditor.tsx+++ b/src/components/workspace/SceneEditor.tsx@@ -1,8 +1,9 @@-import { Dismiss12, ImageAdd16 } from "../ui/icons";-import { useId, useMemo, useRef, useState, type ReactNode } from "react";+import { Dismiss12, Image16, ImageAdd16, Text16, Video16 } from "../ui/icons";+import { useId, useMemo, useState, type ReactNode } from "react";import { ComboBox, InfoBar, PropRow, PropSection } from "../ui";import {actionReferenceIds,+ canTokenizeReference,danglingReferenceTokens,isReferenceUsable,isVisualReference,@@ -36,11 +37,17 @@ import {type ShotTagSelection,} from "../../lib/shot-tags";import { CommittedNumberInput } from "./CommittedNumberInput";+import { PromptTextField, type PromptTokenFormat } from "./PromptTextField";+import { ReferenceIcon } from "./ReferenceIcon";-/** What a reference chip carries when it is dragged into a shot's line. A- * private type, so a file dragged in from the desktop is never mistaken for- * one — the drop handler checks for it before it touches the text. */-export const REFERENCE_DRAG_TYPE = "application/x-slopus-reference";+/** A line cites a reference by id — `@[ref:<id>]` — which survives a rename+ * and a reorder; the chip shows its name. */+const ACTION_TOKENS: PromptTokenFormat = {+ split: splitActionText,+ token: referenceToken,+ key: (reference) => reference.id,+ uncitable: (reference) => canTokenizeReference(reference.id) ? null : "This reference can’t be written into a line",+};/** The step the length slider and the cut handles move in. Half a second is the* finest cut the timestamp format prints exactly (`formatSceneSeconds`), so@@ -99,8 +106,10 @@ export function writeShots(job: GenerationJob, next: readonly SceneShot[], extra/** Everything about ONE shot: when it starts, the line the user wrote for it,* the references that line cites, and the settings hung off it. This is what* clicking a card on the board opens. */-export function ShotInspector({ job, shots, shot, index, endsAt, duration, references, disabled, onChange, promptOnly = false }: {+export function ShotInspector({ job, shots, shot, index, endsAt, duration, references, folderPath = "", disabled, onChange, promptOnly = false }: {promptOnly?: boolean;+ /** The project folder, for each reference's art in the picker. */+ folderPath?: string;job: GenerationJob;/** Every shot of the scene, so the panel can number the references the same* way the compiler does and warn about the ones no line can still cite. */@@ -118,11 +127,20 @@ export function ShotInspector({ job, shots, shot, index, endsAt, duration, referdisabled: boolean;onChange: (updates: Partial<SceneShot>) => void;}) {- const fieldRef = useRef<HTMLTextAreaElement | null>(null);const citable = useMemo(() => citableReferences(references), [references]);const tokenOrder = useMemo(() => referenceOrder(job, shots, references), [job, shots, references]);const numbered = useMemo(() => citable.filter((reference) => tokenOrder.includes(reference.id)), [citable, tokenOrder]);const referenceById = useMemo(() => new Map(references.map((reference) => [reference.id, reference])), [references]);+ /* The picker names each reference by the number the line gives it, which+ is the <Subject N> it becomes; one the scene does not cite yet is bound+ to it, and numbered, by being written into a line. */+ const pickable = useMemo(() => citable.map((reference) => {+ const number = numbered.findIndex((item) => item.id === reference.id) + 1;+ return {+ id: reference.id, name: reference.name, detail: number > 0 ? `Reference ${number}` : "Not in this scene yet",+ icon: <ReferenceIcon reference={reference} folderPath={folderPath} fallback={reference.kind === "video" ? <Video16 /> : referenceImages(reference).length ? <Image16 /> : <Text16 />} />,+ };+ }), [citable, numbered, folderPath]);const dangling = useMemo(() => danglingReferenceTokens(shots, references), [shots, references]);const settings = shot.settings ?? {};const shotNumber = index + 1;@@ -131,42 +149,6 @@ export function ShotInspector({ job, shots, shot, index, endsAt, duration, refer? SPEECH_LANGUAGES: [...SPEECH_LANGUAGES, speechLanguage];- /* The line, written the way the user reads and types it. What is STORED is- `@[ref:<id>]`, which survives a rename and a reorder; what is SHOWN is- "[Reference N]", which is what they were promised and what they may type by- hand. The two are one mapping, applied in both directions here and nowhere- else, so the field can never show a citation the storage does not hold. */- const display = useMemo(() => splitActionText(shot.action).map((part) => {- if (part.kind === "text") return part.value;- const number = tokenOrder.indexOf(part.value) + 1;- return number > 0 ? `[Reference ${number}]` : part.value;- }).join(""), [shot.action, tokenOrder]);-- const store = (typed: string): string => typed.replace(/\[Reference (\d+)\]/g, (whole, digits: string) => {- const id = tokenOrder[Number(digits) - 1];- // A number nobody has a reference for stays exactly as typed. It is the- // user's own text, and turning it into a citation would invent a subject.- return id ? referenceToken(id) : whole;- });-- const insertAtCaret = (referenceId: string) => {- const number = tokenOrder.indexOf(referenceId) + 1;- const field = fieldRef.current;- const at = field ? field.selectionStart : display.length;- const before = display.slice(0, at);- const after = display.slice(at);- // Both sides, not just the one in front of the caret. A drop at the START- // of a line has nothing before it, so `lead` is empty and the token used to- // fuse to the first word: "<Subject 1>walks towards the camera" — a- // malformed citation, sent to the model exactly as written.- const lead = before && !/\s$/.test(before) ? " " : "";- const trail = after && !/^\s/.test(after) ? " " : "";- // A reference this scene does not cite yet has no number, so the token is- // written by id and the number appears once the scene binds it.- const token = number > 0 ? `[Reference ${number}]` : referenceToken(referenceId);- onChange({ action: store(`${before}${lead}${token}${trail}${after}`) });- };-/* Open on its own, a shot is three sections: the shot itself, thereferences its line can cite, and its settings. Inside the Pose scene'ssection (promptOnly) it is just the fields, with no headers of its own. */@@ -196,41 +178,21 @@ export function ShotInspector({ job, shots, shot, index, endsAt, duration, refer{job.sceneType === "character-replace" ? <CharacterReplaceInputs shot={shot} references={references} disabled={disabled} onChange={onChange} /> : <><div className="shot-card__action">- <label className="shot-card__sublabel" htmlFor={`shot-action-${shot.id}`}>{job.sceneType === "pose" ? "Where the pose is used" : "Description"}</label>- <div className="shot-action-editor">- <textarea- id={`shot-action-${shot.id}`}- ref={fieldRef}- value={display}- disabled={disabled}- aria-label={`Describe shot ${shotNumber}`}- placeholder={job.sceneType === "pose" ? "Example: a dancer in a red coat performs this movement on a rainy city street." : "Example: she walks towards the camera and stops under the awning."}- onChange={(event) => onChange({ action: store(event.target.value) })}- onDragOver={(event) => { if (event.dataTransfer.types.includes(REFERENCE_DRAG_TYPE)) event.preventDefault(); }}- onDrop={(event) => {- const referenceId = event.dataTransfer.getData(REFERENCE_DRAG_TYPE);- if (!referenceId) return;- event.preventDefault();- insertAtCaret(referenceId);- }}- />- <ReferenceSmartChips- action={shot.action}- tokenOrder={tokenOrder}- referenceById={referenceById}- citable={citable}- numbered={numbered}- disabled={disabled}- onChange={(partIndex, to) => {- const action = splitActionText(shot.action).map((part, currentIndex) => {- if (part.kind === "text") return part.value;- if (currentIndex === partIndex) return to ? referenceToken(to) : "";- return referenceToken(part.value);- }).join("");- onChange({ action });- }}- />- </div>+ <span className="shot-card__sublabel" aria-hidden="true">{job.sceneType === "pose" ? "Where the pose is used" : "Description"}</span>+ <PromptTextField+ id={`shot-action-${shot.id}`}+ aria-label={`Describe shot ${shotNumber}`}+ rows={6}+ value={shot.action}+ format={ACTION_TOKENS}+ references={pickable}+ missingLabel={(referenceId) => referenceById.get(referenceId)?.name ?? "Deleted reference"}+ missingTooltip="Left out of the prompt — click to swap it for another reference or remove it"+ disabled={disabled}+ placeholder={job.sceneType === "pose" ? "Example: a dancer in a red coat performs this movement on a rainy city street." : "Example: she walks towards the camera and stops under the awning."}+ onChange={(action) => onChange({ action })}+ />+ <DanglingReferences dangling={dangling} referenceById={referenceById} /></div>{!promptOnly && <div className="shot-speech">@@ -259,16 +221,6 @@ export function ShotInspector({ job, shots, shot, index, endsAt, duration, refer</>}</>)}- {job.sceneType !== "character-replace" && group("References", "references", citable.length || undefined, <ReferencePalette- labelled={promptOnly}- citable={citable}- numbered={numbered}- dangling={dangling}- referenceById={referenceById}- disabled={disabled}- onInsert={insertAtCaret}- />)}-{job.sceneType !== "character-replace" && !promptOnly && group("Settings", "settings", chosenSettings || undefined, <ShotSettingssettings={settings}disabled={disabled}@@ -328,12 +280,13 @@ const SCENE_TYPES: { value: SceneType; label: string }[] = [* §4.1), and the two sound fields defined per prompt (§4.6, §4.7). Length* lives in the scene header where it stays visible. Simple label + control* pairs are inspector rows; the free-text fields stay full width. */-export function SceneInspector({ job, shots, references, previousScene, defaultSteps, defaultLook, disabled, importAvailable, importError, onAddStartFrame, onAddEndFrame, onChange, onShots, sceneType = job.sceneType ?? "first-last-frame" }: {+export function SceneInspector({ job, shots, references, folderPath = "", previousScene, defaultSteps, defaultLook, disabled, importAvailable, importError, onAddStartFrame, onAddEndFrame, onChange, onShots, sceneType = job.sceneType ?? "first-last-frame" }: {sceneType?: SceneType;defaultLook?: string | null;job: GenerationJob;shots: SceneShot[];references: ProjectReference[];+ folderPath?: string;previousScene?: GenerationJob;defaultSteps: number;disabled: boolean;@@ -384,7 +337,7 @@ export function SceneInspector({ job, shots, references, previousScene, defaultS<p className="prop-caption">Uses the saved clip range for pose and motion. Describe the subject and setting below.</p>{shots.map((shot, index) => <ShotInspector key={shot.id} job={job} shots={shots} shot={shot} index={index}endsAt={shots[index + 1]?.startSeconds ?? sceneDurationSeconds(job)} duration={sceneDurationSeconds(job)}- references={references} disabled={disabled} promptOnly+ references={references} folderPath={folderPath} disabled={disabled} promptOnlyonChange={(updates) => onShots(shots.map((item) => item.id === shot.id ? { ...item, ...updates } : item))} />)}</>}{characterReplace && <p className="prop-caption">Open a shot to choose its source video and new character.</p>}@@ -532,50 +485,6 @@ export function SceneInspector({ job, shots, references, previousScene, defaultS</section>;}-/** Selectable smart chips live inside the description editor. Each one owns a- * single token occurrence, so changing it leaves identical citations later- * in the same sentence alone. */-function ReferenceSmartChips({ action, tokenOrder, referenceById, citable, numbered, disabled, onChange }: {- action: string;- tokenOrder: string[];- referenceById: Map<string, ProjectReference>;- citable: ProjectReference[];- numbered: ProjectReference[];- disabled: boolean;- onChange: (partIndex: number, to: string | null) => void;-}) {- const parts = splitActionText(action);- if (!parts.some((part) => part.kind === "reference")) return null;- const label = (id: string): string => {- const number = tokenOrder.indexOf(id) + 1;- const name = referenceById.get(id)?.name;- return `Reference ${number > 0 ? number : "?"}${name ? ` · ${name}` : ""}`;- };- return <div className="shot-action-editor__chips">- {parts.map((part, index) => part.kind === "reference" && <ComboBox- key={index}- className={`reference-smart-chip ${citable.some((reference) => reference.id === part.value) ? "" : "reference-smart-chip--broken"}`}- value={part.value}- disabled={disabled}- aria-label={`${label(part.value)} — choose another reference`}- options={[- // A reference that can no longer be cited still has to be listed,- // or the control could not show what the line currently says.- ...(!citable.some((reference) => reference.id === part.value) ? [{ value: part.value, label: `${label(part.value)} — can’t be used` }] : []),- ...citable.map((reference) => {- const number = numbered.findIndex((item) => item.id === reference.id) + 1;- return { value: reference.id, label: number > 0 ? `Reference ${number} · ${reference.name}` : `${reference.name} — not in this scene yet` };- }),- { value: "", label: "Remove from the line" },- ]}- onChange={(value) => {- if (value === "") onChange(index, null);- else if (value !== part.value) onChange(index, value);- }}- />)}- </div>;-}-/* --- Settings ------------------------------------------------------------- *//** Settings are ADDED one at a time and given a value, rather than laid out as@@ -646,47 +555,14 @@ function ShotSettings({ settings, disabled, shotNumber, onChange }: {/* --- The references this scene can use ------------------------------------ */-function ReferencePalette({ labelled, citable, numbered, dangling, referenceById, disabled, onInsert }: {- /** Name the palette itself, where no section header does it. */- labelled: boolean;- citable: ProjectReference[];- numbered: ProjectReference[];- dangling: string[];- referenceById: Map<string, ProjectReference>;- disabled: boolean;- onInsert: (referenceId: string) => void;-}) {- return <div className="reference-palette">- {labelled && <span className="shot-card__sublabel">References</span>}- {citable.length === 0 && <span className="reference-palette__lead">None yet — add one under References.</span>}- <ul>- {citable.map((reference) => {- const number = numbered.findIndex((item) => item.id === reference.id) + 1;- return <li key={reference.id}>- <button- type="button"- className="reference-chip"- draggable={!disabled}- disabled={disabled}- data-tooltip={number > 0- ? `Writes “Reference ${number}” into the line, and <Subject ${number}> into the prompt. Drag it, or click to insert at the caret.`- : "Dropping it into a line adds it to this scene with the next Reference number"}- onDragStart={(event) => {- event.dataTransfer.setData(REFERENCE_DRAG_TYPE, reference.id);- event.dataTransfer.effectAllowed = "copy";- }}- onClick={() => onInsert(reference.id)}- >- <em>{number > 0 ? `Reference ${number}` : "Not in this scene yet"}</em>- <b>{reference.name}</b>- </button>- </li>;- })}- </ul>- {dangling.length > 0 && <InfoBar- severity="error"- title={dangling.length === 1 ? "A reference can’t be used" : `${dangling.length} references can’t be used`}- message={`${dangling.map((id) => referenceById.get(id)?.name ?? "A deleted reference").join(", ")} ${dangling.length === 1 ? "is" : "are"} left out of the prompt. Swap ${dangling.length === 1 ? "it" : "each one"} for another reference or remove ${dangling.length === 1 ? "it" : "them"} from the line before generating.`}- />}- </div>;+/** A line can still name a reference the prompt can no longer use — one+ * deleted, or switched to sound only. Its chip shows it; this says what+ * happens to it. */+function DanglingReferences({ dangling, referenceById }: { dangling: string[]; referenceById: Map<string, ProjectReference> }) {+ if (!dangling.length) return null;+ return <InfoBar+ severity="error"+ title={dangling.length === 1 ? "A reference can’t be used" : `${dangling.length} references can’t be used`}+ message={`${dangling.map((id) => referenceById.get(id)?.name ?? "A deleted reference").join(", ")} ${dangling.length === 1 ? "is" : "are"} left out of the prompt. Swap ${dangling.length === 1 ? "it" : "each one"} for another reference or remove ${dangling.length === 1 ? "it" : "them"} from the line before generating.`}+ />;}diff --git a/src/components/workspace/promptTestUtils.ts b/src/components/workspace/promptTestUtils.tsnew file mode 100644index 0000000..de811fc--- /dev/null+++ b/src/components/workspace/promptTestUtils.ts@@ -0,0 +1,42 @@+import { fireEvent, screen } from "@testing-library/react";++/* PromptTextField is a contenteditable: typing into it is its text and an+ input event, and its value reads each chip back as the token it stands for. */++export const typePrompt = (field: HTMLElement, text: string) => {+ field.textContent = text;+ fireEvent.input(field);+};++/** The value on screen; `token` writes a chip's key back (default `[Name]`). */+export const promptValue = (field: HTMLElement, token = (key: string) => `[${key}]`): string =>+ [...field.childNodes].map((node) => node instanceof HTMLElement && node.dataset.promptReference !== undefined+ ? token(node.dataset.promptReference) : node.textContent ?? "").join("").replaceAll("", "");++/** The names on a field's chips, in order. */+export const promptChips = (field: HTMLElement): string[] =>+ [...field.querySelectorAll(".prompt-chip")].map((chip) => chip.textContent ?? "");++/** Puts the caret `offset` characters into the field's first text, or at its end. */+export const placePromptCaret = (field: HTMLElement, offset?: number) => {+ const range = document.createRange();+ if (offset === undefined) { range.selectNodeContents(field); range.collapse(false); }+ else { range.setStart(field.firstChild!, offset); range.collapse(true); }+ document.getSelection()!.removeAllRanges();+ document.getSelection()!.addRange(range);+ fireEvent(document, new Event("selectionchange"));+};++const option = (name: string) => screen.getByRole("button", { name: new RegExp(`^${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\b`) });++/** Inserts a reference with the field's Reference button, at the caret. */+export const insertPromptReference = (name: string) => {+ fireEvent.click(screen.getByRole("button", { name: "Reference" }));+ fireEvent.click(option(name));+};++/** Opens the picker from a field's `index`th chip and picks `name` (or Remove). */+export const changePromptChip = (field: HTMLElement, index: number, name: string | null) => {+ fireEvent.click(field.querySelectorAll(".prompt-chip")[index]);+ fireEvent.click(name === null ? screen.getByRole("button", { name: "Remove from the prompt" }) : option(name));+};diff --git a/src/styles/generator.css b/src/styles/generator.cssindex 84a192b..4e5be40 100644--- a/src/styles/generator.css+++ b/src/styles/generator.css@@ -798,69 +798,6 @@margin-bottom: 0;}-/* The line itself: a composite text field (the textarea plus the chips that- stand for the references it cites) with the TextBox underline on focus. */-.shot-action-editor {- overflow: hidden;- border: 1px solid var(--stroke-control);- border-bottom-color: var(--stroke-control-bottom);- border-radius: var(--radius-sm);- background: var(--fill-control);-}--.shot-action-editor:has(textarea:focus-visible) {- border-bottom-color: var(--field-focus-line);- background: var(--fill-input-focus);- box-shadow: inset 0 -1px 0 var(--field-focus-line);-}--.shot-card__action textarea {- width: 100%;- min-height: 144px;- padding: var(--space-2);- border: 0;- border-radius: 0;- outline: 0;- box-shadow: none; /* .shot-action-editor draws the underline */- color: var(--text-primary);- background: transparent;- font-family: var(--font-sans);- font-size: var(--text-base);- line-height: var(--leading-normal);- resize: vertical;-}--.shot-card__action textarea:disabled {- color: var(--text-muted);-}--/* One ComboBox per cited reference, as a 24px chip. */-.shot-action-editor__chips {- display: flex;- flex-wrap: wrap;- align-items: center;- gap: var(--space-1);- padding: var(--space-1) var(--space-2) var(--space-2);- border-top: 1px solid var(--line);-}--.ui-combo.reference-smart-chip {- min-width: 0;- max-width: 100%;- height: var(--control-sm);- min-height: var(--control-sm);- padding-inline: var(--space-2);- border-color: var(--accent-line);- color: var(--text-primary);- background: var(--accent-soft);- font-size: var(--text-xs);-}--.ui-combo.reference-smart-chip--broken {- border-color: var(--danger-line);- background: var(--danger-soft);-}-/* --- Settings on a shot ------------------------------------------------------Its own section in the shot's pane; the header names it and counts what isset. */@@ -933,70 +870,6 @@line-height: var(--leading-snug);}-/* --- References that can be dropped into a line ------------------------------- A section of the shot's pane, or (inside the Pose scene) a labelled block. */--.reference-palette__lead {- display: block;- color: var(--text-muted);- font-size: var(--text-xs);- line-height: var(--leading-normal);-}--.reference-palette ul {- display: flex;- flex-wrap: wrap;- gap: var(--space-1);- margin: 0 0 var(--space-2);- padding: 0;- list-style: none;-}--.reference-palette ul:empty {- margin: 0;-}--/* Draggable reference tokens: 24px chips with 4px corners. */-.reference-chip {- max-width: 26ch;- height: var(--control-sm);- display: inline-flex;- align-items: center;- gap: var(--space-1);- padding: 0 var(--space-2);- border: 1px solid var(--stroke-control);- border-radius: var(--radius-sm);- color: var(--text-primary);- background: var(--fill-control);- font-size: var(--text-xs);- text-align: left;- cursor: grab;- transition: var(--transition-control);-}--.reference-chip:hover:not(:disabled) {- background: var(--fill-control-hover);-}--.reference-chip:disabled {- color: var(--text-disabled);- cursor: default;-}--.reference-chip em {- flex: 0 0 auto;- color: var(--text-muted);- font-style: normal;-}--.reference-chip b {- min-width: 0;- overflow: hidden;- font-weight: var(--weight-semibold);- text-overflow: ellipsis;- white-space: nowrap;-}-/* --- The compiled prompt (Debug prompt dialog) ----------------------------- */.debug-prompt {