AI media harness for planning, generating, and editing locally
TypeScript
Move location settings to inspector
Bitticf438f5ec903
diff --git a/src/components/workspace/ReferencesView.test.tsx b/src/components/workspace/ReferencesView.test.tsxindex fcf5221..ca59665 100644--- a/src/components/workspace/ReferencesView.test.tsx+++ b/src/components/workspace/ReferencesView.test.tsx@@ -38,8 +38,8 @@ const project = (): ProjectConfig => {});};-function setup() {- let latest = project();+function setup(initial = project()) {+ let latest = initial;function Harness() {const [config, setConfig] = useState(latest);latest = config;@@ -135,15 +135,18 @@ describe("Reference type presets", () => {fireEvent.change(within(dialog).getByRole("textbox", { name: "Search reference options" }), { target: { value: "lunar" } });expect(within(dialog).getByRole("button", { name: /Lunar base/ })).toBeInTheDocument();expect(within(dialog).queryByRole("button", { name: /Victorian manor/ })).not.toBeInTheDocument();+ expect(within(dialog).queryByRole("combobox", { name: "Time of day" })).not.toBeInTheDocument();fireEvent.click(within(dialog).getByRole("button", { name: /Lunar base/ }));- fireEvent.click(within(within(dialog).getByRole("group", { name: "Time of day" })).getByRole("button", { name: "Night" }));- fireEvent.click(within(within(dialog).getByRole("group", { name: "Season" })).getByRole("button", { name: "Winter" }));- expect(within(dialog).getByText("Lunar base, at night, in winter.")).toBeInTheDocument();- fireEvent.click(within(dialog).getByRole("button", { name: "Use location" }));+ expect(screen.queryByRole("dialog")).not.toBeInTheDocument();+ const settings = screen.getByRole("region", { name: "Location settings" });+ expect(settings.closest("aside")).not.toBeNull();+ fireEvent.change(within(settings).getByRole("combobox", { name: "Time of day" }), { target: { value: "night" } });+ fireEvent.change(within(settings).getByRole("combobox", { name: "Season" }), { target: { value: "winter" } });expect(state.latest().references[0]).toMatchObject({intendedUse: ["location"],description: "Lunar base, at night, in winter.",+ content: "Lunar base, at night, in winter.",});fireEvent.click(screen.getByRole("button", { name: "Location" }));@@ -152,9 +155,49 @@ describe("Reference type presets", () => {fireEvent.click(within(reopened).getByRole("button", { name: "Use Text" }));expect(state.latest().references[0].intendedUse).toEqual([]);+ expect(screen.queryByRole("region", { name: "Location settings" })).not.toBeInTheDocument();expect(screen.getByRole("textbox", { name: "Prompt" })).toHaveValue("Lunar base, at night, in winter.");});+ it("creates locations directly and restores, updates, and clears their saved settings in the inspector", () => {+ 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: "Location" }));+ expect(within(dialog).queryByText("Time of day")).not.toBeInTheDocument();+ expect(within(dialog).queryByText("Weather")).not.toBeInTheDocument();+ fireEvent.click(within(dialog).getByRole("button", { name: /Coastal village/ }));+ expect(screen.queryByRole("dialog")).not.toBeInTheDocument();+ expect(state.latest().references).toHaveLength(2);+ expect(screen.getByRole("combobox", { name: "Weather" })).toHaveValue("");+ fireEvent.change(screen.getByRole("combobox", { name: "Time of day" }), { target: { value: "night" } });+ fireEvent.change(screen.getByRole("combobox", { name: "Weather" }), { target: { value: "rain" } });+ fireEvent.change(screen.getByRole("combobox", { name: "Season" }), { target: { value: "winter" } });+ const saved = parseProjectConfig(state.latest());+ expect(saved.references[0].description).toBe("Coastal village, at night, in rain, in winter.");+ cleanup();+ const restored = setup(saved);+ expect(screen.getByRole("combobox", { name: "Time of day" })).toHaveValue("night");+ expect(screen.getByRole("combobox", { name: "Weather" })).toHaveValue("rain");+ expect(screen.getByRole("combobox", { name: "Season" })).toHaveValue("winter");+ fireEvent.change(screen.getByRole("combobox", { name: "Weather" }), { target: { value: "" } });+ expect(restored.latest().references[0]).toMatchObject({+ description: "Coastal village, at night, in winter.",+ content: "Coastal village, at night, in winter.",+ });+ fireEvent.click(screen.getByRole("button", { name: "Location" }));+ const picker = screen.getByRole("dialog", { name: "Choose a reference type" });+ fireEvent.change(within(picker).getByRole("textbox", { name: "Search reference options" }), { target: { value: "lunar" } });+ fireEvent.click(within(picker).getByRole("button", { name: /Lunar base/ }));+ expect(restored.latest().references[0].description).toBe("Lunar base, at night, in winter.");+ fireEvent.click(screen.getByRole("button", { name: /Add a reference/ }));+ const newPicker = screen.getByRole("dialog", { name: "Add a reference" });+ fireEvent.click(within(newPicker).getByRole("button", { name: "Location" }));+ fireEvent.click(within(newPicker).getByRole("button", { name: /Coastal village/ }));+ expect(restored.latest().references[0].description).toBe("Coastal village.");+ expect(screen.getByRole("combobox", { name: "Time of day" })).toHaveValue("");+ });+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([diff --git a/src/components/workspace/ReferencesView.tsx b/src/components/workspace/ReferencesView.tsxindex f095136..242d381 100644--- a/src/components/workspace/ReferencesView.tsx+++ b/src/components/workspace/ReferencesView.tsx@@ -10,7 +10,6 @@ import {referenceType,referenceTypeLabel,selectedReferencePreset,- type LocationSettings,type ReferencePreset,type ReferenceType,} from "../../lib/reference-presets";@@ -36,11 +35,12 @@ export function ReferencesView({ config, folderPath, onChange }: { config: Projeconst [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 selectedPreset = selected ? selectedReferencePreset(selected) : undefined;+ const selectedLocation = useMemo(() => selected && referenceType(selected) === "location"+ ? locationSelectionFromPrompt(selected.description)+ : undefined, [selected]);const selectedPresetIcon = selectedImages.length === 0 ? selectedPreset?.icon : undefined;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) });@@ -107,9 +107,6 @@ export function ReferencesView({ config, folderPath, onChange }: { config: ProjesetPickerType(referenceType(selected));setPickerSubcategory("all");setPresetSearch("");- const location = locationSelectionFromPrompt(selected.description);- setLocationPresetId(location?.preset.id ?? null);- setLocationSettings(location?.settings ?? {});setPresetDialog(true);};const chooseCustom = () => {@@ -120,23 +117,11 @@ export function ReferencesView({ config, folderPath, onChange }: { config: ProjesetCreatingReference(false);};const choosePreset = (preset: ReferencePreset) => {- if (preset.type === "location") {- setLocationPresetId(preset.id);- setLocationSettings({});- return;- }- 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 = () => {- const preset = REFERENCE_PRESETS.find((candidate) => candidate.type === "location" && candidate.id === locationPresetId);- if (!preset) return;- const prompt = composeLocationPrompt(preset, locationSettings);- if (creatingReference) addTextReference(preset.name, prompt, ["location"]);- else if (selected) update(selected.id, { intendedUse: ["location"], description: prompt, content: prompt });+ const prompt = preset.type === "location"+ ? composeLocationPrompt(preset, creatingReference ? {} : selectedLocation?.settings ?? {})+ : preset.prompt;+ if (creatingReference) addTextReference(preset.name, prompt, [preset.type]);+ else if (selected) update(selected.id, { intendedUse: [preset.type], description: prompt, content: prompt });else return;setPresetDialog(false);setCreatingReference(false);@@ -148,9 +133,6 @@ export function ReferencesView({ config, folderPath, onChange }: { config: Projereturn !query || `${preset.name} ${preset.prompt} ${preset.subcategory} ${preset.searchTerms ?? ""}`.toLocaleLowerCase().includes(query);});const subcategories = [...new Set(REFERENCE_PRESETS.filter((preset) => preset.type === pickerType).map((preset) => preset.subcategory))];- const chosenLocationPreset = pickerType === "location"- ? REFERENCE_PRESETS.find((preset) => preset.type === "location" && preset.id === locationPresetId)- : undefined;return <div className="references-view"><main className="references-main">@@ -219,6 +201,18 @@ export function ReferencesView({ config, folderPath, onChange }: { config: Proje</button></div>}</div>+ {selectedLocation && <section className="reference-location-settings" aria-label="Location settings">+ {LOCATION_SETTING_GROUPS.map((group) => <label key={group.id} className="reference-location-settings__group">+ <span>{group.label}</span>+ <select value={selectedLocation.settings[group.id] ?? ""} onChange={(event) => {+ const prompt = composeLocationPrompt(selectedLocation.preset, { ...selectedLocation.settings, [group.id]: event.target.value || undefined });+ update(selected.id, { description: prompt, content: prompt });+ }}>+ <option value="">None</option>+ {group.options.map((option) => <option key={option.id} value={option.id}>{option.label}</option>)}+ </select>+ </label>)}+ </section>}<section className="reference-type"><h3>Type</h3><button className="reference-type__trigger" onClick={openPresetPicker} aria-haspopup="dialog">@@ -239,7 +233,7 @@ export function ReferencesView({ config, folderPath, onChange }: { config: Proje</header><div className="reference-preset-dialog__body"><nav aria-label="Reference types">- {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>)}+ {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(""); }}>{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>@@ -260,22 +254,8 @@ export function ReferencesView({ config, folderPath, onChange }: { config: Proje<button className={pickerSubcategory === "all" ? "active" : ""} aria-pressed={pickerSubcategory === "all"} onClick={() => setPickerSubcategory("all")}>All</button>{subcategories.map((subcategory) => <button key={subcategory} className={pickerSubcategory === subcategory ? "active" : ""} aria-pressed={pickerSubcategory === subcategory} onClick={() => setPickerSubcategory(subcategory)}>{subcategory}</button>)}</div>- {chosenLocationPreset && <div className="reference-location-settings">- <header><span><small>Location</small><b>{chosenLocationPreset.name}</b></span><button className="primary-button" onClick={chooseLocation}>Use location</button></header>- <p>Add any combination. Each row is optional.</p>- {LOCATION_SETTING_GROUPS.map((group) => <div key={group.id} className="reference-location-settings__group">- <b>{group.label}</b>- <span role="group" aria-label={group.label}>{group.options.map((option) => <button- key={option.id}- className={locationSettings[group.id] === option.id ? "active" : ""}- aria-pressed={locationSettings[group.id] === option.id}- onClick={() => setLocationSettings((current) => ({ ...current, [group.id]: current[group.id] === option.id ? undefined : option.id }))}- >{option.label}</button>)}</span>- </div>)}- <small className="reference-location-settings__preview">{composeLocationPrompt(chosenLocationPreset, locationSettings)}</small>- </div>}<div className="reference-preset-grid">- {visiblePresets.map((preset) => <button key={preset.id} className={`${preset.id === locationPresetId ? "active" : ""}${preset.icon ? " reference-preset-card--with-icon" : ""}`.trim()} aria-pressed={preset.type === "location" ? preset.id === locationPresetId : undefined} onClick={() => choosePreset(preset)}>+ {visiblePresets.map((preset) => <button key={preset.id} className={preset.icon ? "reference-preset-card--with-icon" : undefined} onClick={() => choosePreset(preset)}>{preset.icon && <img className="reference-preset-icon" src={preset.icon} alt="" loading="lazy" />}<small>{preset.subcategory}</small><b>{preset.name}</b><span>{preset.prompt}</span></button>)}diff --git a/src/styles/references.css b/src/styles/references.cssindex 764a64e..56178e1 100644--- a/src/styles/references.css+++ b/src/styles/references.css@@ -964,69 +964,34 @@.reference-location-settings {display: flex;flex-direction: column;- gap: var(--space-3);- margin-bottom: var(--space-4);- padding: var(--space-4);- border: 1px solid var(--accent);- border-radius: var(--radius-md);- background: var(--accent-soft);+ gap: var(--space-2);+ padding: var(--space-3);+ border-bottom: 1px solid var(--line);}-.reference-location-settings > header {- display: flex;+.reference-location-settings__group {+ display: grid;+ grid-template-columns: 96px minmax(0, 1fr);align-items: center;- justify-content: space-between;gap: var(--space-3);}-.reference-location-settings > header span,-.reference-location-settings > header small,-.reference-location-settings > header b {- display: block;-}--.reference-location-settings > header small {- color: var(--text-muted);- font-size: var(--text-2xs);- text-transform: uppercase;-}--.reference-location-settings > p,-.reference-location-settings__preview {- color: var(--text-muted);- font-size: var(--text-sm);-}--.reference-location-settings__group {- display: flex;- flex-direction: column;- gap: var(--space-2);-}--.reference-location-settings__group > b {- color: var(--text-secondary);- font-size: var(--text-xs);-}-.reference-location-settings__group > span {- display: flex;- flex-wrap: wrap;- gap: var(--space-2);-}--.reference-location-settings__group button {- min-height: var(--control-sm);- padding: 0 var(--space-3);- border: 1px solid var(--line);- border-radius: var(--radius-pill);color: var(--text-secondary);- background: var(--panel-3);+ font-size: var(--text-sm);+ font-weight: var(--weight-medium);}-.reference-location-settings__group button:hover,-.reference-location-settings__group button.active {- border-color: var(--accent-bright);- color: var(--accent-bright);+.reference-location-settings__group select {+ min-width: 0;+ width: 100%;+ height: var(--control-sm);+ padding: 0 var(--space-2);+ border: 1px solid var(--line-strong);+ border-radius: var(--radius-sm);+ color: var(--text-primary);+ background: var(--field-bg);+ font-size: var(--text-sm);}.reference-preset-grid b,