The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.
TypeScript ai-videocomfyuicreative-toolsgenerative-aiideogramimage-generationimage-to-3dimage-to-videoltx-videominimax-h3nextjsopen-sourceopen-weightsqwen-imagetext-to-imagevideo-generationwan
Composer: a blocked Generate says why on phones, and filled tiles keep their role
Claude16a46a73a490
diff --git a/src/components/marketing/marketing-studio.tsx b/src/components/marketing/marketing-studio.tsxindex be683475..9da31801 100644--- a/src/components/marketing/marketing-studio.tsx+++ b/src/components/marketing/marketing-studio.tsx@@ -488,7 +488,7 @@ export function MarketingStudio({ models }: { models: Record<string, ModelInfo>onClick={() => void generate()}aria-label={template ? "Recreate template" : "Generate"}aria-disabled={!!blocker || busy}- className={cn("grid size-10 shrink-0 place-items-center rounded-full transition-colors", blocker ? "bg-muted text-subtle-foreground" : "bg-primary text-primary-foreground hover:bg-primary/90")}+ className={cn("grid size-10 shrink-0 place-items-center rounded-full text-primary-foreground transition-colors", blocker ? "bg-primary/55 hover:bg-primary/65" : "bg-primary hover:bg-primary/90")}>{busy ? <Loader2 className="size-4 animate-spin" /> : <ArrowUp className="size-4" />}</button>diff --git a/src/components/studio/composer.tsx b/src/components/studio/composer.tsxindex 0f564423..c54576fd 100644--- a/src/components/studio/composer.tsx+++ b/src/components/studio/composer.tsx@@ -3,6 +3,7 @@import { ArrowUp, AtSign, Loader2, Sparkles, X } from "lucide-react";import dynamic from "next/dynamic";import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";+import { flushSync } from "react-dom";import { toast } from "sonner";import { Button } from "@/components/ui/button";import { Kbd } from "@/components/ui/kbd";@@ -12,7 +13,7 @@ import type { GenerationRequest, MediaKind, ModelDef, Operation, Preset } from "import { enhance, useCreateGeneration, useElements, useEngine, useHydrated, useStatus } from "@/lib/api";import { applyMentions, type StudioElement } from "@/lib/catalog/elements";import { applySketch, stripMotionPaths } from "@/lib/catalog/sketch";-import { blockerFor, costLabel, filterModels, firstMissingSlot, namedImageSlots, needsMask, PLACEHOLDER, promptShown, pushRecent, settingsShape } from "@/lib/composer";+import { blockerFor, blockerLine, costLabel, filterModels, firstMissingSlot, namedImageSlots, needsMask, PLACEHOLDER, promptShown, pushRecent, settingsShape } from "@/lib/composer";import { formatCost } from "@/lib/format";import { cn } from "@/lib/utils";import { AttachMenu } from "./attach-menu";@@ -322,6 +323,19 @@ export function Composer({ docked }: { docked: boolean }) {// Docked and not focused, the tiles fold into one chip on the toolbar (the composer stays one line).const attached = [...slots.map((s) => draft.slots[s.key]), ...draft.refs].filter((v): v is SlotValue => !!v);+ // Phones can't hover Generate for its tooltip, and a folded composer hides the tile it points at:+ // there the blocker is a line under the toolbar (blockerLine), and tapping it opens that tile (the+ // file picker, or the paint tool), as the tap is the click the browser needs for a picker.+ const line = blockerLine(blocker, collapsed);+ const blockerSlot = blocker?.slot ?? (config.multiRef && config.hidePrompt && draft.refs.length < 2 ? "refs" : undefined);+ const openBlocked = (key: string) => {+ flushSync(() => setFocused(true));+ const tile = root.current?.querySelector<HTMLElement>(`[data-slot-key="${key}"]`);+ const control = tile?.matches("button") ? tile : tile?.querySelector<HTMLButtonElement>('button[aria-label$=": upload"]');+ pulseSlot(root.current, key);+ control?.click();+ };+// A blocker toast goes away once it's out of date: the photo attached, the prompt typed (or the next blocker is a different one).const blocking = blocker?.message;useEffect(() => {@@ -427,6 +441,7 @@ export function Composer({ docked }: { docked: boolean }) {label={s.label}kind={s.accept}required={s.required}+ captionvalue={draft.slots[s.key] ?? null}onChange={(v) => attach.setSlotValue(s.key, v)}onFile={(f) => attach.uploadToSlot(s.key, f, s.accept)}@@ -660,7 +675,8 @@ export function Composer({ docked }: { docked: boolean }) {onClick={submit}disabled={create.isPending || signature.lock.isPending}aria-label={blocker ? `Generate — ${blocker.message}` : "Generate"}- className={cn("size-10 shrink-0 rounded-full", blocker && "bg-muted text-subtle-foreground hover:bg-muted")}+ // Blocked, it stays the brand colour (paler): pressing it still says what's missing and points at it.+ className={cn("size-10 shrink-0 rounded-full", blocker && "bg-primary/55 hover:bg-primary/65")}>{create.isPending || signature.lock.isPending ? <Loader2 className="size-4 animate-spin" /> : <ArrowUp className="size-4" />}</Button>@@ -675,6 +691,26 @@ export function Composer({ docked }: { docked: boolean }) {</TooltipContent></Tooltip></div>+ <div aria-live="polite">+ {line && blocker && (+ // Focused from the keyboard, it stays (the composer unfolding must not hide what has the focus).+ <p className={cn("px-2 text-[12px] text-muted-foreground", line === "touch" && "[@media(hover:hover)]:hidden [@media(hover:hover)]:focus-within:block")}>+ {blockerSlot ? (+ <button+ type="button"+ // A mouse press would focus the composer and unfold it under the pointer before the click lands.+ onMouseDown={(e) => e.preventDefault()}+ onClick={() => openBlocked(blockerSlot)}+ className="inline-flex min-h-6 items-center text-left underline decoration-border-strong underline-offset-2 hover:text-foreground hover:decoration-current"+ >+ {blocker.message}+ </button>+ ) : (+ <span className="inline-flex min-h-6 items-center">{blocker.message}</span>+ )}+ </p>+ )}+ </div>{sketched.note && <p className="px-2 pt-1 text-[12px] text-muted-foreground">{sketched.note}</p>}{signed.notes.length > 0 && <p className="px-2 pt-1 text-[12px] text-muted-foreground">{signed.notes.join(" · ")}</p>}{model && op && model.options.endFrame === undefined && draft.slots.endImage?.ref && (diff --git a/src/components/studio/media-slot.tsx b/src/components/studio/media-slot.tsxindex 1c454504..379f4b0f 100644--- a/src/components/studio/media-slot.tsx+++ b/src/components/studio/media-slot.tsx@@ -8,6 +8,7 @@ import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popoverimport { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";import { useAssets, type Asset } from "@/lib/api";import type { MediaKind } from "@/lib/catalog/types";+import { slotCaption } from "@/lib/composer";import { cn } from "@/lib/utils";import type { SketchMode, Stroke } from "./sketch-editor";@@ -223,6 +224,7 @@ export function MediaSlot({size = "md",onFile,slotKey,+ caption,}: {label: string;kind: MediaKind;@@ -234,6 +236,8 @@ export function MediaSlot({onFile?: (f: File) => void;/** Marks the tile so the composer can point at it ("Add a start frame"). */slotKey?: string;+ /** Filled, keep the slot's role on the thumbnail ("Target", "Face"), so two photos can be told apart. */+ caption?: boolean;}) {const handleFile = (f: File) => {// A tile takes its own kind only (a clip dropped on the Image tile would land as a video there).@@ -268,6 +272,11 @@ export function MediaSlot({{value ? (<div className="size-full overflow-hidden rounded-xl border bg-muted"><SlotPreview value={value} />+ {caption && (+ <span aria-hidden className="pointer-events-none absolute inset-x-0 bottom-0 truncate rounded-b-xl bg-black/50 px-1 py-px text-center text-[10px] leading-tight font-medium text-white">+ {slotCaption(label)}+ </span>+ )}{value.uploading && (<div className="absolute inset-0 grid place-items-center rounded-xl bg-background/60" role="status" aria-label="Uploading"><Loader2 className="size-4 animate-spin" />diff --git a/src/lib/composer.ts b/src/lib/composer.tsindex a6433c2f..2e8e9802 100644--- a/src/lib/composer.ts+++ b/src/lib/composer.ts@@ -131,6 +131,19 @@ export function slotMessage(label: string): string {return `Add ${VOWEL.test(word) ? "an" : "a"} ${word}`;}+const GENERIC_NOUN = /^(photo|image|picture|frame|clip|video|file|shot)s?$/i;++/**+ * A filled tile's caption, in the slot's own words without the generic noun the thumbnail already+ * shows: "Target photo" → "Target", "Start frame" → "Start", "Face" → "Face". Labels that would+ * lose their meaning ("Your clip", "Image") stay whole.+ */+export function slotCaption(label: string): string {+ const words = label.trim().split(/\s+/);+ if (words.length > 1 && GENERIC_NOUN.test(words[words.length - 1]) && !DETERMINER.test(words[0])) return words.slice(0, -1).join(" ");+ return words.join(" ");+}+type SlotValues = Partial<Record<InputSlot["key"], { ref: string; uploading?: boolean } | null>>;/** A missing input: one required slot, or (`group`) a set of optional slots of which one is needed ("a portrait or a video"). */@@ -165,6 +178,8 @@ export interface Blocker {message: string;/** The attachment to point at (pulse) when Generate is pressed ("mask": the Paint area tile). */slot?: InputSlot["key"];+ /** Passes by itself or is plain to see (loading, uploading, the empty prompt box): never spelled out under the composer. */+ quiet?: boolean;}/**@@ -198,17 +213,29 @@ export function blockerFor(s: {planError?: string | null;promptMissing: boolean;}): Blocker | null {- if (s.loading) return { message: s.loading };+ if (s.loading) return { message: s.loading, quiet: true };if (!s.model) return { message: "Pick a model" };if (s.engineError) return { message: s.engineError };if (s.missing) return { message: missingMessage(s.missing), slot: s.missing.key };- if (s.uploading) return { message: "Uploading…" };+ if (s.uploading) return { message: "Uploading…", quiet: true };if (s.maskMissing) return { message: "Paint the area to change", slot: "mask" };if (s.planError) return { message: s.planError };- if (s.promptMissing) return { message: "Write a prompt first" };+ if (s.promptMissing) return { message: "Write a prompt first", quiet: true };return null;}+/**+ * Where the composer spells its blocker out in a line under the toolbar ("Add a target photo",+ * which opens that tile when tapped): wherever the tiles it points at are folded away (docked and+ * collapsed: "always"), else only where the Generate button's tooltip can't be seen (no hover:+ * phones and tablets, "touch", which the page decides with a media query so the server's HTML is+ * the same). Never for a quiet blocker.+ */+export function blockerLine(b: Blocker | null, collapsed: boolean): "always" | "touch" | null {+ if (!b || b.quiet) return null;+ return collapsed ? "always" : "touch";+}+/*** Whether the composer shows a prompt box (and the studio its prompt suggestions): not when the* studio or app has none, nor for a model that takes no prompt (try-on, upscalers, 3D, transcription).diff --git a/tests/composer.test.ts b/tests/composer.test.tsindex 86fbca56..30c2d0c5 100644--- a/tests/composer.test.ts+++ b/tests/composer.test.ts@@ -5,6 +5,8 @@ import {acceptedKinds,bestForStudio,blockerFor,+ blockerLine,+ slotCaption,costLabel,filterModels,firstMissingSlot,@@ -143,15 +145,42 @@ describe("blockers", () => {it("orders blockers from most to least actionable", () => {const slot: InputSlot = { key: "image", label: "Target photo", accept: "image", required: true };const base = { model: true, uploading: false, promptMissing: false };- expect(blockerFor({ ...base, loading: "Loading models…", model: false })).toEqual({ message: "Loading models…" });+ expect(blockerFor({ ...base, loading: "Loading models…", model: false })).toEqual({ message: "Loading models…", quiet: true });expect(blockerFor({ ...base, model: false })).toEqual({ message: "Pick a model" });expect(blockerFor({ ...base, missing: slot, uploading: true, planError: "Add an image to edit", promptMissing: true })).toEqual({ message: "Add a target photo", slot: "image" });- expect(blockerFor({ ...base, uploading: true, planError: "Add an image to edit" })).toEqual({ message: "Uploading…" });+ expect(blockerFor({ ...base, uploading: true, planError: "Add an image to edit" })).toEqual({ message: "Uploading…", quiet: true });expect(blockerFor({ ...base, planError: "Pick a language to translate into", promptMissing: true })?.message).toBe("Pick a language to translate into");expect(blockerFor({ ...base, promptMissing: true })?.message).toBe("Write a prompt first");expect(blockerFor({ ...base, engineError: "Face Swap has no cloud version yet", missing: slot })?.message).toMatch(/no cloud version/);expect(blockerFor(base)).toBeNull();});++ it("captions a filled tile with the slot's role", () => {+ expect(slotCaption("Target photo")).toBe("Target");+ expect(slotCaption("Face")).toBe("Face");+ expect(slotCaption("Start frame")).toBe("Start");+ expect(slotCaption("End frame")).toBe("End");+ expect(slotCaption("Reference images")).toBe("Reference");+ expect(slotCaption("Your clip")).toBe("Your clip");+ expect(slotCaption("Image")).toBe("Image");+ expect(slotCaption("Voice sample")).toBe("Voice sample");+ });++ it("spells the blocker out under the composer where its tooltip can't be seen", () => {+ const slot: InputSlot = { key: "image", label: "Target photo", accept: "image", required: true };+ const base = { model: true, uploading: false, promptMissing: false };+ const missing = blockerFor({ ...base, missing: slot });+ // A folded docked composer shows it everywhere; with its tiles open, only screens without hover (the tooltip elsewhere).+ expect(blockerLine(missing, true)).toBe("always");+ expect(blockerLine(missing, false)).toBe("touch");+ expect(blockerLine(blockerFor({ ...base, planError: "Pick a voice" }), false)).toBe("touch");+ expect(blockerLine(blockerFor({ ...base, engineError: "Face Swap has no cloud version yet" }), true)).toBe("always");+ // Never for what passes by itself or is plain to see: loading, uploading, the empty prompt box.+ for (const quiet of [blockerFor({ ...base, loading: "Loading models…" }), blockerFor({ ...base, uploading: true }), blockerFor({ ...base, promptMissing: true })]) {+ expect(blockerLine(quiet, true)).toBeNull();+ }+ expect(blockerLine(null, true)).toBeNull();+ });});describe("attachments", () => {