Skip to content

armgit / fuobe

Public Imported from GitHub
0

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.

Studios: fixes from the review of the example row

Adarsh0e70facbc796
diff --git a/src/components/home/showcase-tile.tsx b/src/components/home/showcase-tile.tsx
index 0c4132db..dfea6fd1 100644
--- a/src/components/home/showcase-tile.tsx
+++ b/src/components/home/showcase-tile.tsx
@@ -27,6 +27,7 @@ export function ShowcaseTile({
index,
sizes = SIZES,
small = false,
+ onNavigate,
}: {
card: PresetCardData;
kind: string;
@@ -35,8 +36,13 @@ export function ShowcaseTile({
index: number;
/** How wide the tile shows, where it isn't on Home's wall (a studio's row of four, under its composer). */
sizes?: string;
- /** A tile that is small at every width (a studio's row): it gets the taller, darker shade of a phone's tile. */
+ /**
+ * A tile that is small at every width (a studio's row): it gets the taller, darker shade of a phone's tile, and it is
+ * never the page's largest picture, so even the first isn't fetched ahead of the rest.
+ */
small?: boolean;
+ /** Called as the link navigates in the app; preventDefault() keeps the page (a studio picks the tile's move itself). */
+ onNavigate?: React.ComponentProps<typeof IntentLink>["onNavigate"];
}) {
const { ref, playing, asked, handlers } = usePreviewPlayback<HTMLAnchorElement>(card.id, card.preview);
const still = card.preview.rest?.src ?? card.preview.poster;
@@ -45,6 +51,7 @@ export function ShowcaseTile({
<IntentLink
ref={ref}
href={href}
+ onNavigate={onNavigate}
{...handlers}
// In the order it shows: the kind (from xl), the name, the line.
aria-label={`${kind}: ${card.name}, ${caption}. Try it`}
@@ -62,7 +69,7 @@ export function ShowcaseTile({
place={staggered(index)}
sizes={sizes}
loading={index < 4 ? "eager" : "lazy"}
- fetchPriority={index === 0 ? "high" : undefined}
+ fetchPriority={index === 0 && !small ? "high" : undefined}
/>
</div>
{/* A small tile (a phone's, or four across a tablet) is short: a taller, darker shade keeps its white words readable over a bright picture. */}
diff --git a/src/components/studio/attachments.ts b/src/components/studio/attachments.ts
index aeb67f69..f665a785 100644
--- a/src/components/studio/attachments.ts
+++ b/src/components/studio/attachments.ts
@@ -175,10 +175,12 @@ export function useAttach(slots: InputSlot[], refMax: number) {
/**
* The page's drop zone hands files to the composer, which knows the current slots (they change
- * with the model and preset). The composer registers its `attachFiles` here.
+ * with the model and preset). The composer registers its `attachFiles` here, and its camera
+ * motion and effect picker as `pick` (the studio's example tiles pick through it).
*/
export interface ComposerBridge {
current: ((files: File[]) => void) | null;
+ pick?: ((id: string) => void) | null;
}
export const ComposerBridgeCtx = createContext<ComposerBridge | null>(null);
diff --git a/src/components/studio/composer.tsx b/src/components/studio/composer.tsx
index 769a45e1..f27369b5 100644
--- a/src/components/studio/composer.tsx
+++ b/src/components/studio/composer.tsx
@@ -400,6 +400,14 @@ export function Composer({ docked }: { docked: boolean }) {
const route = presetParams(picked, engine);
setDraft((d) => ({ presetId: id, modelId: m.id, params: { ...m.defaults, ...route, numOutputs: d.params.numOutputs, enhancePrompt: d.params.enhancePrompt, seed: d.params.seed }, ...lookCleared(model, m) }));
};
+ // The empty studio's example tiles pick a camera motion or effect here, as the chip does, so what is attached stays.
+ useEffect(() => {
+ if (!bridgeRef) return;
+ bridgeRef.pick = pickPreset;
+ return () => {
+ if (bridgeRef.pick === pickPreset) bridgeRef.pick = null;
+ };
+ });
// A motion handed over in the link (?preset= from the Motions gallery) is known once the presets load: it moves the
// studio's untouched default model to its Original, once per preset.
const adoptedPreset = useRef<string | undefined>(undefined);
diff --git a/src/components/studio/studio-page.tsx b/src/components/studio/studio-page.tsx
index 1d25717e..05c41a9c 100644
--- a/src/components/studio/studio-page.tsx
+++ b/src/components/studio/studio-page.tsx
@@ -4,7 +4,7 @@ import { ArrowRight, ArrowUp, Loader2, Upload } from "lucide-react";
import Link from "next/link";
import dynamic from "next/dynamic";
import { useSearchParams } from "next/navigation";
-import { memo, Suspense, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
+import { memo, Suspense, useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
import { nanoid } from "nanoid";
import { toast } from "sonner";
import { SidebarTrigger } from "@/components/ui/sidebar";
@@ -20,7 +20,7 @@ import { currentModelId, migrateRequest } from "@/lib/catalog/replaced";
import { matchSpokenLanguage } from "@/lib/speech-languages";
import { SoulPresetCards } from "@/components/moodboards/soul-preset-cards";
import type { StudioCatalog } from "@/lib/studio-catalog";
-import type { StudioExample } from "@/lib/studio-examples";
+import type { StudioExample, StudioExampleRow } from "@/lib/studio-examples";
import { cn } from "@/lib/utils";
import { ComposerBridgeCtx, useComposerBridge, type ComposerBridge } from "./attachments";
import { CatalogProvider, useCatalog } from "./catalog";
@@ -250,30 +250,60 @@ function PromptSuggestions({ suggestions }: { suggestions: string[] }) {
const EXAMPLE_SIZES = "(min-width: 640px) 240px, 50vw";
/** The row's tiles. Memoized: the row reads the draft (below), and typing shouldn't re-render four playing covers. */
-const ExampleTiles = memo(function ExampleTiles({ examples }: { examples: StudioExample[] }) {
+const ExampleTiles = memo(function ExampleTiles({ tiles }: { tiles: StudioExample[] }) {
+ const bridge = useComposerBridge();
+ const grid = useRef<HTMLDivElement>(null);
+ // A tile that picks a camera motion or effect in this same studio (/video?preset=…) picks it the way the composer's
+ // own picker does: a photo already attached, the model and its settings stay, where opening the link anew would
+ // start a fresh draft. Its link still opens in a new tab, and is the way in when the composer isn't there.
+ const pickHere = (href: string) => (e: { preventDefault: () => void }) => {
+ const url = new URL(href, window.location.href);
+ const id = url.searchParams.get("preset");
+ if (!id || url.pathname !== window.location.pathname || !bridge?.pick) return;
+ e.preventDefault();
+ // The row goes once a move is picked, and the tile with it: a tile picked from the keyboard hands its focus to this
+ // studio's composer, so the next key types the prompt instead of starting again from the top of the page.
+ const keyboard = !!grid.current?.querySelector(":focus-visible");
+ const composer = grid.current?.closest("[data-studio]")?.querySelector<HTMLElement>("[data-composer]");
+ bridge.pick(id);
+ // The move's card shows above the composer: back up to it, as the link's navigation would have.
+ window.scrollTo({ top: 0, behavior: window.matchMedia("(prefers-reduced-motion: reduce)").matches ? "auto" : "smooth" });
+ if (keyboard) requestAnimationFrame(() => composer?.querySelector<HTMLElement>("textarea, button")?.focus({ preventScroll: true }));
+ };
return (
- <div className="grid grid-cols-2 gap-3 sm:grid-cols-4">
- {examples.map((e, i) => (
- <ShowcaseTile key={e.card.id} card={e.card} kind={e.kind} caption={e.caption} href={e.href} index={i} sizes={EXAMPLE_SIZES} small />
+ <div ref={grid} className="grid grid-cols-2 gap-3 sm:grid-cols-4">
+ {tiles.map((e, i) => (
+ <ShowcaseTile
+ key={e.card.id}
+ card={e.card}
+ kind={e.kind}
+ caption={e.caption}
+ href={e.href}
+ index={i}
+ sizes={EXAMPLE_SIZES}
+ small
+ onNavigate={pickHere(e.href)}
+ />
))}
</div>
);
});
/**
- * "See what it makes": real covers from the studio's own presets (src/lib/studio-examples.ts) under the empty
- * composer, each opening its app or picking its motion or effect. Hidden while a preset is picked: its own card is
- * above the composer then.
+ * Real covers from the studio's own presets (src/lib/studio-examples.ts) under the empty composer, each opening its
+ * app or picking its motion or effect. Hidden while a preset is picked: its own card is above the composer then.
*/
-function StudioExamples({ examples }: { examples: StudioExample[] }) {
+function StudioExamples({ row }: { row: StudioExampleRow }) {
const { draft } = useStudio();
+ // Its own id: a studio left earlier stays in the page, hidden, with a row of its own.
+ const heading = useId();
if (draft.presetId) return null;
return (
- <section aria-labelledby="studio-examples" className="mx-auto w-full max-w-[1000px] px-3 pb-10 sm:px-6">
- <h2 id="studio-examples" className="mb-2 text-center text-[12.5px] font-medium text-muted-foreground">
- See what it makes
+ <section aria-labelledby={heading} className="mx-auto w-full max-w-[1000px] px-3 pb-10 sm:px-6">
+ <h2 id={heading} className="mb-2 text-center text-[12.5px] font-medium text-muted-foreground">
+ {row.heading}
</h2>
- <ExampleTiles examples={examples} />
+ <ExampleTiles tiles={row.tiles} />
</section>
);
}
@@ -316,7 +346,7 @@ function StudioHeader({ title, header, tabs }: { title: string; header?: React.R
);
}
-function StudioBody({ header, tabs, examples }: { header?: React.ReactNode; tabs?: React.ReactNode; examples?: StudioExample[] }) {
+function StudioBody({ header, tabs, examples }: { header?: React.ReactNode; tabs?: React.ReactNode; examples?: StudioExampleRow }) {
// Config and actions only: the draft lives in the composer, so typing doesn't re-render the page or the feed.
const { config, setDraft } = useStudioActions();
const [engine, setEngine] = useEngine();
@@ -345,6 +375,7 @@ function StudioBody({ header, tabs, examples }: { header?: React.ReactNode; tabs
return (
<div
+ data-studio
className="relative flex min-h-svh min-w-0 flex-col"
onDragEnter={(e) => {
if (![...e.dataTransfer.types].includes("Files")) return;
@@ -415,7 +446,8 @@ function StudioBody({ header, tabs, examples }: { header?: React.ReactNode; tabs
{!hasItems && config.suggestions && <PromptSuggestions suggestions={config.suggestions} />}
{!hasItems && config.signature && <SoulPresetCards />}
- {!hasItems && !!examples?.length && <StudioExamples examples={examples} />}
+ {/* Only once the feed is known to be empty: a studio with results would show the row, fetch its covers, then drop it. */}
+ {feed.isSuccess && !hasItems && !!examples?.tiles.length && <StudioExamples row={examples} />}
{dragging && (
<div className="pointer-events-none absolute inset-0 z-40 grid place-items-center bg-overlay p-8">
@@ -445,7 +477,7 @@ interface StudioPageProps {
/** Prompt to start with when the URL doesn't carry one (e.g. "@Maya "). */
initialPrompt?: string;
/** Real covers of what the studio makes, under the empty composer (`studioExamples()` in a server component). */
- examples?: StudioExample[];
+ examples?: StudioExampleRow;
}
type DraftProps = Omit<StudioPageProps, "catalog">;
@@ -543,7 +575,7 @@ function StudioSession({
}: {
header?: React.ReactNode;
tabs?: React.ReactNode;
- examples?: StudioExample[];
+ examples?: StudioExampleRow;
sync: Omit<React.ComponentProps<typeof HandoffSync>, "onStart">;
}) {
const [startRequest, setStartRequest] = useState(0);
diff --git a/src/lib/studio-examples.ts b/src/lib/studio-examples.ts
index c35f39e6..6a30e1dc 100644
--- a/src/lib/studio-examples.ts
+++ b/src/lib/studio-examples.ts
@@ -12,23 +12,33 @@ import type { PresetCardData } from "@/lib/preset-cards";
export type ExampleStudio = "image" | "video" | "edit";
/**
- * Each studio's four, in the order they show. A line of its own where Home has none for that preset, else Home's
- * (HOME_CAPTION_MAX.card holds either whole on a phone's tile).
+ * Each studio's row: the line above it, and its four in the order they show. A line of its own where Home has none
+ * for that preset, else Home's (HOME_CAPTION_MAX.card holds either whole on a phone's tile). Video's tiles pick their
+ * move in the studio itself; Image's and Edit's are apps, each on a page of its own, and their heading says so.
*/
-export const STUDIO_EXAMPLES: Record<ExampleStudio, { id: string; caption?: string }[]> = {
- image: [
- { id: "app-sketch-to-real", caption: "A rough sketch, made a real photo" },
- { id: "app-style-transfer", caption: "Any photo, redrawn as anime" },
- { id: "app-virtual-try-on" },
- { id: "app-product-shot" },
- ],
- video: [{ id: "motion-fpv-drone" }, { id: "effect-flame-on" }, { id: "motion-bullet-time" }, { id: "effect-angel-wings" }],
- edit: [
- { id: "app-relight" },
- { id: "app-colorize", caption: "Black & white photos, in full color" },
- { id: "app-outfit-swap" },
- { id: "app-hairstyle-try-on" },
- ],
+export const STUDIO_EXAMPLES: Record<ExampleStudio, { heading: string; tiles: { id: string; caption?: string }[] }> = {
+ image: {
+ heading: "Or start from an app",
+ tiles: [
+ { id: "app-sketch-to-real", caption: "A rough sketch, made a real photo" },
+ { id: "app-style-transfer", caption: "Any photo, redrawn as anime" },
+ { id: "app-virtual-try-on" },
+ { id: "app-product-shot" },
+ ],
+ },
+ video: {
+ heading: "See what it makes",
+ tiles: [{ id: "motion-fpv-drone" }, { id: "effect-flame-on" }, { id: "motion-bullet-time" }, { id: "effect-angel-wings" }],
+ },
+ edit: {
+ heading: "Or start from an app",
+ tiles: [
+ { id: "app-relight" },
+ { id: "app-colorize", caption: "Black & white photos, in full color" },
+ { id: "app-outfit-swap" },
+ { id: "app-hairstyle-try-on" },
+ ],
+ },
};
/** A tile of the studio's row: its cover, what kind of preset it is, its line, and where it opens. */
@@ -39,18 +49,28 @@ export interface StudioExample {
href: string;
}
+/** A studio's row: the line above it and its tiles. */
+export interface StudioExampleRow {
+ heading: string;
+ tiles: StudioExample[];
+}
+
const homeCaptions = new Map<string, string>([...HOME_WALL, ...HOME_EFFECTS, ...HOME_MOTIONS, ...HOME_REVEALS].map((t) => [t.id, t.caption]));
/** The kind a tile names (from xl, as Home's wall does): the apps here all wipe from a before to an after. */
const KIND: Record<PresetType, string> = { app: "App · before → after", motion: "Camera motion", effect: "Effect" };
/** The studio's row, as cards (each resting on its peak frame, as on Home). */
-export function studioExamples(studio: ExampleStudio): StudioExample[] {
- return STUDIO_EXAMPLES[studio].map(({ id, caption }) => {
- // homeCard throws for an id the catalog doesn't have, so the build fails rather than the page.
- const card = homeCard(id);
- const line = caption ?? homeCaptions.get(id);
- if (!line) throw new Error(`The ${studio} studio's example ${id} has no line`);
- return { card, kind: KIND[getPreset(id)!.type], caption: line, href: presetHref(id) };
- });
+export function studioExamples(studio: ExampleStudio): StudioExampleRow {
+ const { heading, tiles } = STUDIO_EXAMPLES[studio];
+ return {
+ heading,
+ tiles: tiles.map(({ id, caption }) => {
+ // homeCard throws for an id the catalog doesn't have, so the build fails rather than the page.
+ const card = homeCard(id);
+ const line = caption ?? homeCaptions.get(id);
+ if (!line) throw new Error(`The ${studio} studio's example ${id} has no line`);
+ return { card, kind: KIND[getPreset(id)!.type], caption: line, href: presetHref(id) };
+ }),
+ };
}
diff --git a/tests/studio-examples.test.ts b/tests/studio-examples.test.ts
index 6bc88c8b..0d2921ed 100644
--- a/tests/studio-examples.test.ts
+++ b/tests/studio-examples.test.ts
@@ -24,15 +24,21 @@ describe("the studios' examples", () => {
it("shows four for each of Image, Video and Edit, none twice", () => {
expect(studios.sort()).toEqual(["edit", "image", "video"]);
for (const s of studios) {
- const ids = STUDIO_EXAMPLES[s].map((e) => e.id);
+ const ids = STUDIO_EXAMPLES[s].tiles.map((e) => e.id);
expect(ids, s).toHaveLength(4);
expect(new Set(ids).size, s).toBe(4);
}
});
+ it("says over Image's and Edit's apps that they are apps, and over Video's moves what the studio makes", () => {
+ expect(studioExamples("image").heading).toBe("Or start from an app");
+ expect(studioExamples("edit").heading).toBe("Or start from an app");
+ expect(studioExamples("video").heading).toBe("See what it makes");
+ });
+
it("names real presets, each with its cover, its clip and their small copies", () => {
for (const s of studios) {
- for (const { card } of studioExamples(s)) {
+ for (const { card } of studioExamples(s).tiles) {
expect(getPreset(card.id), card.id).toBeDefined();
const cover = PRESET_PREVIEWS[card.id];
expect(cover, `${card.id} has a real cover`).toBeDefined();
@@ -54,7 +60,7 @@ describe("the studios' examples", () => {
it("gives each a line that fits a phone's tile whole, and says what kind it is", () => {
for (const s of studios) {
- for (const e of studioExamples(s)) {
+ for (const e of studioExamples(s).tiles) {
expect(e.caption.length, e.card.id).toBeGreaterThan(0);
expect(e.caption.length, e.card.id).toBeLessThanOrEqual(HOME_CAPTION_MAX.card);
expect(e.kind, e.card.id).toBe({ app: "App · before → after", motion: "Camera motion", effect: "Effect" }[getPreset(e.card.id)!.type]);
@@ -63,11 +69,11 @@ describe("the studios' examples", () => {
});
it("opens an app on its own page, and picks a motion or effect in the Video studio", () => {
- const [image, video] = [studioExamples("image"), studioExamples("video")];
+ const [image, video] = [studioExamples("image").tiles, studioExamples("video").tiles];
expect(image[0].href).toBe(`/apps/${image[0].card.id}`);
for (const e of video) expect(e.href, e.card.id).toBe(`/video?preset=${e.card.id}`);
// Edit and Image show apps, Video shows what its studio picks.
- for (const s of ["image", "edit"] as const) for (const e of studioExamples(s)) expect(getPreset(e.card.id)!.type, e.card.id).toBe("app");
+ for (const s of ["image", "edit"] as const) for (const e of studioExamples(s).tiles) expect(getPreset(e.card.id)!.type, e.card.id).toBe("app");
for (const e of video) expect(["motion", "effect"], e.card.id).toContain(getPreset(e.card.id)!.type);
});
@@ -75,9 +81,21 @@ describe("the studios' examples", () => {
const read = (...p: string[]) => fs.readFileSync(path.join(root, "src", ...p), "utf8");
expect(read("lib", "studio-examples.ts")).toMatch(/^import "server-only";$/m);
const page = read("components", "studio", "studio-page.tsx");
- expect(page).toMatch(/^import type \{ StudioExample \} from "@\/lib\/studio-examples";$/m);
+ expect(page).toMatch(/^import type \{ StudioExample, StudioExampleRow \} from "@\/lib\/studio-examples";$/m);
expect(page).toMatch(/dynamic\(\(\) => import\("@\/components\/home\/showcase-tile"\)/);
expect(page).not.toMatch(/^import [^;]*from "@\/components\/home\/showcase-tile";$/m);
for (const s of studios) expect(read("app", "(studio)", s, "page.tsx"), s).toContain(`examples={studioExamples("${s}")}`);
});
+
+ it("shows only once the feed is known to be empty, and a Video tile picks its move through the composer", () => {
+ const read = (...p: string[]) => fs.readFileSync(path.join(root, "src", ...p), "utf8");
+ const page = read("components", "studio", "studio-page.tsx");
+ expect(page).toMatch(/\{feed\.isSuccess && !hasItems && !!examples\?\.tiles\.length && <StudioExamples /);
+ expect(page).toMatch(/onNavigate=\{pickHere\(e\.href\)\}/);
+ expect(read("components", "studio", "composer.tsx")).toMatch(/bridgeRef\.pick = pickPreset;/);
+ // A tile picked from the keyboard hands its focus to its own studio's composer, not to a hidden studio's.
+ expect(page).toMatch(/closest\("\[data-studio\]"\)\?\.querySelector<HTMLElement>\("\[data-composer\]"\)/);
+ expect(page).toMatch(/if \(keyboard\) requestAnimationFrame\(\(\) => composer\?\.querySelector<HTMLElement>\("textarea, button"\)\?\.focus\(\{ preventScroll: true \}\)\)/);
+ expect(page).toMatch(/^\s+data-studio$/m);
+ });
});