Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Align prompt chips with text and show reference art in picker

Bittia799f2af9737
diff --git a/src/components/workspace/ImageEditor.tsx b/src/components/workspace/ImageEditor.tsx
index 26e02c8..2431e7c 100644
--- a/src/components/workspace/ImageEditor.tsx
+++ b/src/components/workspace/ImageEditor.tsx
@@ -14,6 +14,7 @@ import { isWorkActive, type WorkItem } from "../../lib/workQueue";
import type { ConfigUpdate } from "./TimelineView";
import { ReferenceImage } from "./ReferenceImage";
import { PromptTextField } from "./PromptTextField";
+import { ReferenceIcon } from "./ReferenceIcon";
import { ImageBar } from "./ImageBar";
import { DebugPromptDialog } from "./DebugPromptDialog";
import { TagEditor } from "./TagEditor";
@@ -436,7 +437,7 @@ export function ImageEditor({ config, folderPath, onChange: changeConfig, onGene
const rootField = (field: string) => `${editorId}-${field}`;
const promptLabel = imageRoot ? "Edit prompt" : selected.kind === "root" ? "Prompt (high-level description)" : "Description";
const promptReferences = config.references.filter((reference) => reference.kind === "image" || reference.kind === "text")
- .map((reference) => ({ id: reference.id, name: reference.name, detail: reference.kind === "image" ? "Image" : "Text", icon: reference.kind === "image" ? <Image16 /> : <Text16 /> }));
+ .map((reference) => ({ id: reference.id, name: reference.name, detail: reference.kind === "image" ? "Image" : "Text", icon: <ReferenceIcon reference={reference} folderPath={folderPath} fallback={reference.kind === "image" ? <Image16 /> : <Text16 />} /> }));
/* A reference newly cited in a prompt is one the generation has to be
given, so citing it links it to the edit (or, composing, to the image). */
const changePrompt = (description: string) => {
diff --git a/src/components/workspace/PromptTextField.test.tsx b/src/components/workspace/PromptTextField.test.tsx
index 2cb07cd..03b76f4 100644
--- a/src/components/workspace/PromptTextField.test.tsx
+++ b/src/components/workspace/PromptTextField.test.tsx
@@ -8,7 +8,7 @@ import { canCitePromptReference, promptReferenceNames, splitPromptText } from ".
afterEach(cleanup);
-const references: PromptReference[] = [{ id: "hero", name: "Hero" }, { id: "castle", name: "Castle" }, { id: "odd", name: "Odd [v2]" }];
+const references: PromptReference[] = [{ id: "hero", name: "Hero", icon: <img alt="" src="data:image/png;base64," data-testid="hero-icon" /> }, { id: "castle", name: "Castle" }, { id: "odd", name: "Odd [v2]" }];
function setup(initial: string, onInsertReference = vi.fn()) {
let latest = initial;
@@ -56,6 +56,7 @@ it("inserts the chosen reference at the caret from the toolbar", () => {
fireEvent.click(screen.getByRole("button", { name: "Reference" }));
expect(screen.getByRole("dialog", { name: "Insert a reference" })).toBeInTheDocument();
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(onInsert).toHaveBeenCalledWith(references[0]);
diff --git a/src/components/workspace/ReferenceIcon.tsx b/src/components/workspace/ReferenceIcon.tsx
new file mode 100644
index 0000000..29b109e
--- /dev/null
+++ b/src/components/workspace/ReferenceIcon.tsx
@@ -0,0 +1,20 @@
+import type { ReactNode } from "react";
+import { referenceImages, type ProjectReference } from "../../lib/project";
+import { hasPresetIcon, selectedReferencePreset } from "../../lib/reference-presets";
+import { PresetIcon } from "./PresetIcon";
+import { ReferenceImage } from "./ReferenceImage";
+
+/** The art that stands for a still reference, in the References library's
+ * order: a refmod's generated icon, its first picture, a generated icon,
+ * its preset's icon — or `fallback` (a glyph) when it has none. */
+export function ReferenceIcon({ reference, folderPath, fallback = null }: { reference: ProjectReference; folderPath: string; fallback?: ReactNode }) {
+ const cover = referenceImages(reference)[0];
+ const preset = selectedReferencePreset(reference);
+ const icon = reference.refmods?.length && reference.iconRelativePath
+ ? <ReferenceImage folderPath={folderPath} relativePath={reference.iconRelativePath} alt="" />
+ : cover ? <ReferenceImage folderPath={folderPath} relativePath={cover.relativePath} sourcePath={cover.sourcePath} alt="" />
+ : reference.iconRelativePath ? <ReferenceImage folderPath={folderPath} relativePath={reference.iconRelativePath} alt="" />
+ : hasPresetIcon(preset) ? <PresetIcon preset={preset!} />
+ : null;
+ return icon ?? fallback;
+}
diff --git a/src/styles/prompt-field.css b/src/styles/prompt-field.css
index 558a2b7..faf2e3f 100644
--- a/src/styles/prompt-field.css
+++ b/src/styles/prompt-field.css
@@ -45,24 +45,20 @@
.prompt-field__input:empty::before { content: attr(data-placeholder); color: var(--text-muted); pointer-events: none; }
.prompt-field--disabled .prompt-field__input { color: var(--text-disabled); background: var(--fill-control-disabled); cursor: default; }
-/* Inline with the words: a chip is one line tall, so it never pushes the line
- apart, and wraps as a whole. */
+/* An inline box on the words' own font and line: it shares their baseline
+ and never changes the height of the line it sits in. Its padding and border
+ paint around the name without moving anything. */
.prompt-chip {
- display: inline-block;
- max-width: 100%;
+ display: inline;
margin-inline: 1px;
- padding: 0 var(--space-2);
- overflow: hidden;
+ padding: 1px var(--space-2);
border: 1px solid var(--accent-line);
border-radius: var(--radius-pill);
color: var(--accent-on-soft);
background: var(--accent-soft);
- font-size: var(--text-xs);
+ font: inherit;
font-weight: var(--weight-semibold);
- line-height: calc(1lh - 2px);
- vertical-align: baseline;
white-space: nowrap;
- text-overflow: ellipsis;
cursor: default;
user-select: none;
}
@@ -89,7 +85,10 @@
}
.prompt-reference-picker__option:hover:not(:disabled) { background: var(--fill-subtle-hover); }
.prompt-reference-picker__option:disabled { color: var(--text-disabled); }
-.prompt-reference-picker__icon { display: inline-flex; flex: none; align-items: center; justify-content: center; width: 20px; color: var(--text-secondary); }
+/* Room for the reference's art — its picture or icon — or a glyph. */
+.prompt-reference-picker__icon { display: inline-flex; flex: none; align-items: center; justify-content: center; width: 32px; height: 32px; overflow: hidden; border-radius: var(--radius-sm); color: var(--text-secondary); }
+.prompt-reference-picker__icon img { width: 100%; height: 100%; object-fit: cover; }
+.prompt-reference-picker__icon > span:empty { width: 100%; height: 100%; }
.prompt-reference-picker__text { display: flex; flex-direction: column; min-width: 0; }
.prompt-reference-picker__text > span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.prompt-reference-picker__text small { color: var(--text-muted); font-size: var(--text-xs); }