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.

Results UI: focus, small cards, audio actions, delete-forever confirm, a11y

Claudec352b39ff714
diff --git a/src/components/library-view.tsx b/src/components/library-view.tsx
index d07c72c1..4e61d373 100644
--- a/src/components/library-view.tsx
+++ b/src/components/library-view.tsx
@@ -10,7 +10,8 @@ import { FilterBar, filterFields, hasFilters, NO_FILTERS, type Filters } from "@
import { FolderDialog, FolderHeader, FolderStrip, MoveMenuItems } from "@/components/library/folders";
import { useViewPrefs, ViewOptions, type ViewPrefs } from "@/components/library/view-options";
import { PageShell } from "@/components/page-shell";
-import { downloadUrl } from "@/components/studio/result-actions";
+import { downloadUrl, ForeverConfirmProvider, useConfirmForever } from "@/components/studio/result-actions";
+import { useEdgeFade } from "@/components/studio/use-edge-fade";
import { Viewer } from "@/components/studio/viewer";
import {
AlertDialog,
@@ -25,10 +26,10 @@ import {
import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
import { Kbd } from "@/components/ui/kbd";
import { Skeleton } from "@/components/ui/skeleton";
-import { useCreateGeneration, useFolders, useGenerationActions, useLibrary, useLibraryFacets, useUploads, type Asset, type FeedFilter } from "@/lib/api";
+import { BULK_MAX, useCreateGeneration, useFolders, useGenerationActions, useLibrary, useLibraryFacets, useUploads, type Asset, type FeedFilter } from "@/lib/api";
import type { Generation, MediaKind } from "@/lib/catalog/types";
import { buildEntries, splitByDate, TRASH_DAYS, type LibraryEntry } from "@/lib/library";
-import { isLayered } from "@/lib/output-actions";
+import { isLayered, shownOutputs } from "@/lib/output-actions";
import { cn } from "@/lib/utils";
type TabId = "all" | "images" | "videos" | "audio" | "text" | "3d" | "favorites" | "uploads" | "trash";
@@ -274,7 +275,11 @@ function Inner() {
// --- Viewer --------------------------------------------------------------------------------
const [open, setOpen] = useState<{ id: string; index: number } | null>(null);
const flat = useMemo(
- () => order.flatMap((e) => members(e)).filter((g, i, all) => g.status === "succeeded" && g.outputs.length && all.findIndex((x) => x.id === g.id) === i).flatMap((g) => (isLayered(g) ? [{ g, i: 0 }] : g.outputs.map((_, i) => ({ g, i })))),
+ () =>
+ order
+ .flatMap((e) => members(e))
+ .filter((g, i, all) => g.status === "succeeded" && g.outputs.length && all.findIndex((x) => x.id === g.id) === i)
+ .flatMap((g) => (isLayered(g) ? [{ g, i: 0 }] : shownOutputs(g).map((i) => ({ g, i })))),
[order],
);
const pos = open ? flat.findIndex((f) => f.g.id === open.id && (f.i === open.index || isLayered(f.g))) : -1;
@@ -365,8 +370,23 @@ function Inner() {
};
const [newFolderFor, setNewFolderFor] = useState<string[] | null>(null);
- const [confirmForever, setConfirmForever] = useState<Generation[] | null>(null);
+ const confirmForever = useConfirmForever();
const [confirmEmpty, setConfirmEmpty] = useState(false);
+ // A folder link whose folder is gone (deleted, or a stale link); while folders load, we don't know yet.
+ const foldersLoading = !!folderId && !folders.data;
+ const missingFolder = !!folderId && !!folders.data && !folder && !trash;
+
+ // The tab strip scrolls sideways on phones: fade the hidden edge and keep the active tab in view.
+ const [tabsRef, tabsFade] = useEdgeFade<HTMLDivElement>();
+ const activeTab = useRef<HTMLButtonElement>(null);
+ const focusTab = useRef(false);
+ // Again once the counts load: tabs for kinds you have (Text, 3D) appear and shift the rest.
+ const tabsReady = !!facets.data;
+ useEffect(() => {
+ activeTab.current?.scrollIntoView({ inline: "nearest", block: "nearest" });
+ if (focusTab.current) activeTab.current?.focus();
+ focusTab.current = false;
+ }, [tab.id, tabsReady]);
const loading = uploadsTab ? uploads.isLoading : lib.isLoading;
const refreshing = !uploadsTab && lib.isPlaceholderData;
@@ -420,6 +440,11 @@ function Inner() {
<div className="flex flex-wrap items-end justify-between gap-x-4 gap-y-3 pb-5">
{folder ? (
<FolderHeader folder={folder} onBack={() => go({ folder: undefined })} onMoveOut={(list) => void moveTo(list, null, "Library")} />
+ ) : foldersLoading ? (
+ <div className="flex h-[52px] min-w-0 items-center gap-2" aria-busy="true" aria-label="Loading folder">
+ <Skeleton className="h-8 w-24 rounded-full" />
+ <Skeleton className="h-7 w-48 rounded-lg" />
+ </div>
) : (
<div className="min-w-0">
<h1 className="font-heading text-[34px] leading-tight">Library</h1>
@@ -463,34 +488,58 @@ function Inner() {
</div>
</div>
- {!folder && (
- <div className="scrollbar-none mb-4 flex gap-4 overflow-x-auto border-b">
+ {!folder && !foldersLoading && !missingFolder && (
+ <div
+ ref={tabsRef}
+ style={tabsFade}
+ role="tablist"
+ aria-label="Library sections"
+ className="scrollbar-none mb-4 flex gap-4 overflow-x-auto border-b"
+ onKeyDown={(e) => {
+ // Arrow keys move between tabs (and open them), as in any tab strip.
+ if (e.key !== "ArrowRight" && e.key !== "ArrowLeft") return;
+ const at = visibleTabs.findIndex((t) => t.id === tab.id);
+ const next = visibleTabs[(at + (e.key === "ArrowRight" ? 1 : -1) + visibleTabs.length) % visibleTabs.length];
+ e.preventDefault();
+ focusTab.current = true;
+ go({ tab: next.id === "all" ? undefined : next.id, folder: undefined });
+ }}
+ >
{visibleTabs.map((t) => {
const n = count(t);
+ const on = tab.id === t.id;
return (
<button
key={t.id}
+ ref={on ? activeTab : undefined}
+ role="tab"
+ aria-selected={on}
+ tabIndex={on ? 0 : -1}
onClick={() => go({ tab: t.id === "all" ? undefined : t.id, folder: undefined })}
className={cn(
- "-mb-px inline-flex shrink-0 items-center gap-1.5 border-b-2 border-transparent px-1 pb-2 text-[14px] whitespace-nowrap text-muted-foreground transition-colors hover:text-foreground",
- tab.id === t.id && "border-foreground font-medium text-foreground",
+ "-mb-px inline-flex shrink-0 items-center gap-1.5 border-b-2 border-transparent px-1 pb-2 text-[14px] whitespace-nowrap text-muted-foreground transition-colors outline-none hover:text-foreground focus-visible:text-foreground focus-visible:ring-2 focus-visible:ring-ring",
+ on && "border-foreground font-medium text-foreground",
)}
>
{t.label}
- {n ? <span className="font-mono text-[11px] text-muted-foreground">{n}</span> : null}
+ {n ? (
+ <span className="font-mono text-[11px] text-muted-foreground" aria-label={`${n} items`}>
+ {n}
+ </span>
+ ) : null}
</button>
);
})}
</div>
)}
- {tab.id === "all" && !folder && (folders.data?.length || !loading) ? (
+ {tab.id === "all" && !folderId && (folders.data?.length || !loading) ? (
<div className="mb-4">
<FolderStrip folders={folders.data ?? []} onOpen={(f) => go({ folder: f.id })} onMove={(list, f) => void moveTo(list, f.id, f.name)} />
</div>
) : null}
- {!uploadsTab && (
+ {!uploadsTab && !missingFolder && (
<div className="mb-4 flex flex-wrap items-center justify-between gap-2">
<FilterBar value={filters} onChange={setFilters} facets={facets.data} />
{trash && (
@@ -506,7 +555,14 @@ function Inner() {
</div>
)}
- {loading && !items.length ? (
+ {missingFolder ? (
+ <Empty title="This folder no longer exists">
+ It may have been deleted; what was in it is back in your Library.{" "}
+ <button onClick={() => go({ folder: undefined })} className="text-brand-text hover:underline">
+ Back to Library
+ </button>
+ </Empty>
+ ) : loading && !items.length ? (
<div className="grid grid-cols-[repeat(auto-fill,minmax(min(200px,calc(50vw-22px)),1fr))] gap-2">
{Array.from({ length: 8 }, (_, i) => (
<Skeleton key={i} className="aspect-square rounded-xl" />
@@ -584,7 +640,7 @@ function Inner() {
{trash ? (
<>
<BarButton icon={ArchiveRestore} label="Restore" disabled={!selected.size} onClick={() => void actions.restore(selectedGens).then((n) => (n && toast(`Restored ${n}`), clear()))} />
- <BarButton icon={Trash2} label="Delete forever" destructive disabled={!selected.size} onClick={() => setConfirmForever(selectedGens)} />
+ <BarButton icon={Trash2} label="Delete forever" destructive disabled={!selected.size} onClick={() => confirmForever?.(selectedGens, clear)} />
</>
) : (
<>
@@ -592,7 +648,11 @@ function Inner() {
icon={Download}
label="Download"
disabled={!selectedGens.some((g) => g.status === "succeeded")}
- onClick={() => downloadUrl(`/api/generations/zip?ids=${[...selected].slice(0, 500).join(",")}`)}
+ onClick={() => {
+ const done = selectedGens.filter((g) => g.status === "succeeded").map((g) => g.id);
+ downloadUrl(`/api/generations/zip?ids=${done.slice(0, BULK_MAX).join(",")}`);
+ if (done.length > BULK_MAX) toast(`The zip has the first ${BULK_MAX} of ${done.length}`, { description: "Select the rest and download them as a second zip." });
+ }}
/>
<BarButton icon={Heart} label={allFav ? "Unlike" : "Like"} disabled={!selected.size} onClick={() => void actions.favoriteMany(selectedGens, !allFav)} />
<DropdownMenu modal={false}>
@@ -636,26 +696,6 @@ function Inner() {
/>
)}
- <AlertDialog open={!!confirmForever} onOpenChange={(v) => !v && setConfirmForever(null)}>
- <AlertDialogContent>
- <AlertDialogHeader>
- <AlertDialogTitle>Delete {confirmForever?.length === 1 ? "this for good" : `${confirmForever?.length} items for good`}?</AlertDialogTitle>
- <AlertDialogDescription>They&apos;ll be removed with their files and can&apos;t be recovered.</AlertDialogDescription>
- </AlertDialogHeader>
- <AlertDialogFooter>
- <AlertDialogCancel>Cancel</AlertDialogCancel>
- <AlertDialogAction
- onClick={() => {
- if (confirmForever) void actions.deleteForever(confirmForever).then((n) => n && toast(`Deleted ${n} for good`));
- clear();
- }}
- >
- Delete forever
- </AlertDialogAction>
- </AlertDialogFooter>
- </AlertDialogContent>
- </AlertDialog>
-
<AlertDialog open={confirmEmpty} onOpenChange={setConfirmEmpty}>
<AlertDialogContent>
<AlertDialogHeader>
@@ -665,6 +705,7 @@ function Inner() {
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction
+ variant="destructive"
onClick={() => {
void actions.emptyTrash().then(() => toast("Trash emptied"));
}}
@@ -702,7 +743,9 @@ function BarButton({ icon: Icon, label, onClick, disabled, destructive }: { icon
export function LibraryView() {
return (
<Suspense fallback={null}>
- <Inner />
+ <ForeverConfirmProvider>
+ <Inner />
+ </ForeverConfirmProvider>
</Suspense>
);
}
diff --git a/src/components/library/asset-card.tsx b/src/components/library/asset-card.tsx
index 66a9fb46..525618d9 100644
--- a/src/components/library/asset-card.tsx
+++ b/src/components/library/asset-card.tsx
@@ -8,7 +8,7 @@ import { LayersStack, MediaThumb, SmallThumb } from "@/components/studio/result-
import { OPERATION_LABELS, type Generation } from "@/lib/catalog/types";
import { elapsed, timeAgo } from "@/lib/format";
import { coverOf, trashDaysLeft, userTitle, type LibraryEntry } from "@/lib/library";
-import { isLayered } from "@/lib/output-actions";
+import { isLayered, shownOutputs } from "@/lib/output-actions";
import { cn } from "@/lib/utils";
import { DRAG_TYPE } from "./folders";
import type { Layout } from "./view-options";
@@ -126,20 +126,30 @@ export const AssetCard = memo(function AssetCard({
else if (stack) api.expand(entry.key);
else if (done) api.open(g, 0);
};
- const common = {
- role: "button" as const,
- tabIndex: 0,
- "aria-label": stack ? `${title} — ${stack.label}` : title,
- "aria-pressed": selecting ? selected : undefined,
- "aria-expanded": stack ? !!expanded : undefined,
- onClick: (e: React.MouseEvent) => activate(e.shiftKey),
- onKeyDown: (e: React.KeyboardEvent) => {
- if (e.target !== e.currentTarget) return;
- if (e.key === "Enter" || (e.key === " " && selecting)) {
+ // The card handles mouse clicks; keyboards and screen readers use this button over it, a sibling of
+ // the card's other buttons (none sits inside another). It lets the pointer through to the media.
+ const target = (
+ <button
+ type="button"
+ aria-label={stack ? `${title} — ${stack.label}` : selecting ? `Select “${title}”` : done ? `Open “${title}”` : title}
+ aria-pressed={selecting ? selected : undefined}
+ aria-expanded={stack && !selecting ? !!expanded : undefined}
+ onClick={(e) => {
+ e.stopPropagation();
+ activate(e.shiftKey);
+ }}
+ onKeyDown={(e) => {
+ // Shift+Enter extends a selection like a shift-click.
+ if (e.key !== "Enter") return;
e.preventDefault();
+ e.stopPropagation();
activate(e.shiftKey);
- }
- },
+ }}
+ className="pointer-events-none absolute inset-0 rounded-xl outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset"
+ />
+ );
+ const common = {
+ onClick: (e: React.MouseEvent) => activate(e.shiftKey),
draggable: canHover && !trashed,
onDragStart: (e: React.DragEvent) => {
const dragged = api.dragIds(ids);
@@ -150,13 +160,35 @@ export const AssetCard = memo(function AssetCard({
onPointerEnter: (e: React.PointerEvent) => e.pointerType === "mouse" && !hot && setHot("bar"),
onFocus: () => canHover && !hot && setHot("bar"),
};
- const showActions = !selecting && !stack && done && g.outputs[0].kind !== "audio";
+ const showActions = !selecting && !stack && done;
+ // Audio keeps its player at the bottom of the card: its actions go along the top.
+ const audio = done && !stack && g.outputs[0].kind === "audio";
+ const count = shownOutputs(g).length;
+ // Touch screens: just a ⋯ button that opens every action (at the top for audio, by the badges).
+ const touchMenu =
+ showActions &&
+ !canHover &&
+ (hot === "menu" ? (
+ <TileActions g={g} index={0} opts={api.runner} menuOnly className={audio ? undefined : "absolute right-2 bottom-2"} />
+ ) : (
+ <button
+ aria-label="More actions"
+ onClick={(e) => {
+ e.stopPropagation();
+ setHot("menu");
+ }}
+ className={cn("grid size-8 place-items-center rounded-lg bg-black/45 text-white backdrop-blur", !audio && "absolute right-2 bottom-2")}
+ >
+ <MoreHorizontal className="size-4" />
+ </button>
+ ));
const badges = (
<>
- {g.favorite && !stack && <Heart className="absolute top-2.5 right-2.5 size-4 fill-highlight text-highlight drop-shadow" />}
- {!stack && g.outputs.length > 1 && !isLayered(g) && (
- <span className="absolute top-2 right-8 rounded-full bg-black/55 px-1.5 py-0.5 font-mono text-[11px] text-white backdrop-blur">×{g.outputs.length}</span>
- )}
+ <div className={cn("absolute top-2 right-2 flex items-center gap-1.5", audio && canHover && "group-focus-within/card:opacity-0 group-hover/card:opacity-0")}>
+ {!stack && count > 1 && !isLayered(g) && <span className="rounded-full bg-black/55 px-1.5 py-0.5 font-mono text-[11px] text-white backdrop-blur">×{count}</span>}
+ {g.favorite && !stack && <Heart className="m-0.5 size-4 fill-highlight text-highlight drop-shadow" />}
+ {audio && touchMenu}
+ </div>
{trashed && (
<span className="absolute bottom-2 left-2 rounded-full bg-background/85 px-2 py-0.5 text-[11px] font-medium backdrop-blur">
{trashDaysLeft(g.deletedAt!)} days left
@@ -164,41 +196,30 @@ export const AssetCard = memo(function AssetCard({
)}
</>
);
- const actions =
- showActions &&
- (canHover ? (
+ const actions = canHover
+ ? showActions &&
hot === "bar" && (
<TileActions
g={g}
index={0}
opts={api.runner}
- className="absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/60 to-transparent p-2 pt-8 opacity-0 transition-opacity duration-100 group-focus-within/card:opacity-100 group-hover/card:opacity-100"
+ tone={audio ? "surface" : "media"}
+ className={cn(
+ // Audio: clear of the select dot in the corner.
+ audio ? "absolute inset-x-0 top-0 p-2 pl-10" : "absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/60 to-transparent p-2 pt-8",
+ "opacity-0 transition-opacity duration-100 group-focus-within/card:opacity-100 group-hover/card:opacity-100",
+ )}
/>
)
- ) : hot === "menu" ? (
- <TileActions g={g} index={0} opts={api.runner} menuOnly className="absolute right-2 bottom-2" />
- ) : (
- <button
- aria-label="More actions"
- onClick={(e) => {
- e.stopPropagation();
- setHot("menu");
- }}
- className="absolute right-2 bottom-2 grid size-8 place-items-center rounded-lg bg-black/45 text-white backdrop-blur"
- >
- <MoreHorizontal className="size-4" />
- </button>
- ));
+ : !audio && touchMenu;
if (layout === "list") {
return (
<div
{...common}
- className={cn(
- "group/card relative flex min-h-16 cursor-pointer items-center gap-3 rounded-xl px-2 py-2 outline-none hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring",
- selected && "bg-brand-faint hover:bg-brand-faint-hover",
- )}
+ className={cn("group/card relative flex min-h-16 cursor-pointer items-center gap-3 rounded-xl px-2 py-2 hover:bg-accent", selected && "bg-brand-faint hover:bg-brand-faint-hover")}
>
+ {target}
<div className="relative size-14 shrink-0 overflow-hidden rounded-lg bg-muted">
{stack ? cover ? <SmallThumb output={cover.o} g={cover.g} /> : <StatusCover g={g} /> : done ? <SmallThumb output={g.outputs[0]} g={g} /> : <StatusCover g={g} />}
<SelectDot selected={selected} visible={selecting} onToggle={(s) => api.toggle(entry.key, ids, s)} label={`Select ${title}`} />
@@ -255,7 +276,7 @@ export const AssetCard = memo(function AssetCard({
<div
{...common}
className={cn(
- "relative w-full cursor-pointer overflow-hidden rounded-xl bg-muted outline-none transition-[box-shadow] focus-visible:ring-2 focus-visible:ring-ring",
+ "relative w-full cursor-pointer overflow-hidden rounded-xl bg-muted transition-[box-shadow]",
!selecting && done && !stack && "cursor-zoom-in",
selected && "ring-3 ring-primary",
expanded && "ring-2 ring-border-strong",
@@ -263,6 +284,7 @@ export const AssetCard = memo(function AssetCard({
style={{ aspectRatio: ratio }}
>
{stack ? cover ? <MediaThumb output={cover.o} g={cover.g} fit={fit} /> : <StatusCover g={g} /> : <Cover g={g} fit={fit} />}
+ {target}
{selected && <div className="pointer-events-none absolute inset-0 bg-primary/15" />}
{stack && (
<div className="pointer-events-none absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/70 via-black/30 to-transparent p-3 pt-10 text-white">
diff --git a/src/components/library/filters.tsx b/src/components/library/filters.tsx
index f6fddeb6..fe3a9aea 100644
--- a/src/components/library/filters.tsx
+++ b/src/components/library/filters.tsx
@@ -2,6 +2,7 @@
import { Calendar, Check, ChevronDown, CircleDot, Cpu, X } from "lucide-react";
import { useState } from "react";
+import { useEdgeFade } from "@/components/studio/use-edge-fade";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
import type { LibraryFacets } from "@/lib/api";
import type { GenerationStatus } from "@/lib/catalog/types";
@@ -56,15 +57,18 @@ function Chip({ active, children, ...props }: { active: boolean; children: React
);
}
-function Option({ checked, onClick, children }: { checked: boolean; onClick: () => void; children: React.ReactNode }) {
+/** One choice in a filter popover: a checkbox (models, several at once) or a radio (date, status). */
+function Option({ checked, onClick, children, kind = "checkbox" }: { checked: boolean; onClick: () => void; children: React.ReactNode; kind?: "checkbox" | "radio" }) {
return (
<button
- role="menuitemcheckbox"
+ role={kind}
aria-checked={checked}
onClick={onClick}
className="flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-[13px] transition-colors hover:bg-accent"
>
- <span className={cn("grid size-4 shrink-0 place-items-center rounded border", checked && "border-primary bg-primary text-primary-foreground")}>{checked && <Check className="size-3" />}</span>
+ <span className={cn("grid size-4 shrink-0 place-items-center border", kind === "radio" ? "rounded-full" : "rounded", checked && "border-primary bg-primary text-primary-foreground")}>
+ {checked && <Check className="size-3" />}
+ </span>
<span className="min-w-0 flex-1 truncate">{children}</span>
</button>
);
@@ -91,15 +95,17 @@ export function FilterBar({ value, onChange, facets }: { value: Filters; onChang
const modelLabel = value.models.length === 0 ? "Any model" : value.models.length === 1 ? (models.find((m) => m.id === value.models[0])?.name ?? "1 model") : `${value.models.length} models`;
const d = value.date;
const dateLabel = d.id === "custom" ? [d.from, d.to].filter(Boolean).join(" → ") || "Custom range" : DATES.find((x) => x.id === d.id)!.label;
+ // The chips scroll sideways on phones: fade the edge where more hide.
+ const [rowRef, fade] = useEdgeFade<HTMLDivElement>();
return (
- <div className="scrollbar-none -mx-1 flex items-center gap-1.5 overflow-x-auto px-1 py-0.5">
+ <div ref={rowRef} style={fade} className="scrollbar-none -mx-1 flex items-center gap-1.5 overflow-x-auto px-1 py-0.5">
<Popover>
<PopoverTrigger asChild>
<Chip active={value.models.length > 0}>
<Cpu className="size-3.5" /> {modelLabel} <ChevronDown className="size-3.5 opacity-60" />
</Chip>
</PopoverTrigger>
- <PopoverContent align="start" collisionPadding={12} className="max-h-80 w-[min(92vw,280px)] overflow-y-auto p-1.5">
+ <PopoverContent align="start" collisionPadding={12} className="max-h-80 w-[min(92vw,280px)] overflow-y-auto p-1.5" role="group" aria-label="Models">
{models.length === 0 && <p className="px-2 py-1.5 text-[13px] text-muted-foreground">Nothing made yet</p>}
{models.map((m) => (
<Option
@@ -119,9 +125,9 @@ export function FilterBar({ value, onChange, facets }: { value: Filters; onChang
</Chip>
</PopoverTrigger>
<PopoverContent align="start" collisionPadding={12} className="w-[min(92vw,280px)] space-y-2 p-1.5">
- <div>
+ <div role="radiogroup" aria-label="Date">
{DATES.map((x) => (
- <Option key={x.id} checked={d.id === x.id} onClick={() => onChange({ ...value, date: { id: x.id } })}>
+ <Option key={x.id} kind="radio" checked={d.id === x.id} onClick={() => onChange({ ...value, date: { id: x.id } })}>
{x.label}
</Option>
))}
@@ -156,9 +162,9 @@ export function FilterBar({ value, onChange, facets }: { value: Filters; onChang
<ChevronDown className="size-3.5 opacity-60" />
</Chip>
</PopoverTrigger>
- <PopoverContent align="start" collisionPadding={12} className="w-[min(92vw,220px)] p-1.5">
+ <PopoverContent align="start" collisionPadding={12} className="w-[min(92vw,220px)] p-1.5" role="radiogroup" aria-label="Status">
{STATUSES.map((s) => (
- <Option key={s.id} checked={value.status === s.id} onClick={() => onChange({ ...value, status: s.id })}>
+ <Option key={s.id} kind="radio" checked={value.status === s.id} onClick={() => onChange({ ...value, status: s.id })}>
{s.label}
</Option>
))}
diff --git a/src/components/library/folders.tsx b/src/components/library/folders.tsx
index 8b10473d..e7754964 100644
--- a/src/components/library/folders.tsx
+++ b/src/components/library/folders.tsx
@@ -1,7 +1,7 @@
"use client";
import { Check, ChevronLeft, Folder as FolderIcon, FolderPlus, MoreHorizontal, Pencil, Trash2 } from "lucide-react";
-import { useState } from "react";
+import { useRef, useState } from "react";
import { toast } from "sonner";
import {
AlertDialog,
@@ -61,6 +61,7 @@ export function FolderDialog({ folder, open, onOpenChange, onSaved }: { folder?:
const [name, setName] = useState(folder?.name ?? "");
const [color, setColor] = useState(folder?.color ?? DEFAULT_FOLDER_COLOR);
const [busy, setBusy] = useState(false);
+ const input = useRef<HTMLInputElement>(null);
const save = async () => {
setBusy(true);
try {
@@ -76,7 +77,15 @@ export function FolderDialog({ folder, open, onOpenChange, onSaved }: { folder?:
};
return (
<Dialog open={open} onOpenChange={onOpenChange}>
- <DialogContent className="w-[min(92vw,400px)] gap-4">
+ <DialogContent
+ className="w-[min(92vw,400px)] gap-4"
+ // Straight into the name field, also when opened from a menu that was still handing focus back.
+ onOpenAutoFocus={(e) => {
+ e.preventDefault();
+ input.current?.focus();
+ input.current?.select();
+ }}
+ >
<DialogTitle className="font-heading text-[22px] font-normal">{folder ? "Edit folder" : "New folder"}</DialogTitle>
<DialogDescription className="sr-only">Name and colour</DialogDescription>
<form
@@ -87,7 +96,7 @@ export function FolderDialog({ folder, open, onOpenChange, onSaved }: { folder?:
}}
>
<input
- autoFocus
+ ref={input}
value={name}
onChange={(e) => setName(e.target.value)}
maxLength={60}
@@ -195,11 +204,12 @@ export function FolderHeader({ folder, onBack, onMoveOut }: { folder: Folder; on
</button>
</DropdownMenuTrigger>
<DropdownMenuContent align="start">
- <DropdownMenuItem onSelect={() => setEditing(true)}>
+ {/* Open dialogs once the menu has closed and handed focus back, so the dialog keeps it. */}
+ <DropdownMenuItem onSelect={() => setTimeout(() => setEditing(true), 0)}>
<Pencil /> Rename or recolour
</DropdownMenuItem>
<DropdownMenuSeparator />
- <DropdownMenuItem variant="destructive" onSelect={() => setDeleting(true)}>
+ <DropdownMenuItem variant="destructive" onSelect={() => setTimeout(() => setDeleting(true), 0)}>
<Trash2 /> Delete folder
</DropdownMenuItem>
</DropdownMenuContent>
@@ -244,7 +254,8 @@ export function MoveMenuItems({ folders, current, onMove, onNew }: { folders: Fo
</DropdownMenuItem>
)}
{folders.length > 0 && <DropdownMenuSeparator />}
- <DropdownMenuItem onSelect={onNew}>
+ {/* After the menu has closed and handed focus back, so the dialog keeps it. */}
+ <DropdownMenuItem onSelect={() => setTimeout(onNew, 0)}>
<FolderPlus /> New folder…
</DropdownMenuItem>
</>
diff --git a/src/components/studio/composer.tsx b/src/components/studio/composer.tsx
index f4366817..4a171112 100644
--- a/src/components/studio/composer.tsx
+++ b/src/components/studio/composer.tsx
@@ -207,19 +207,19 @@ export function Composer({ docked }: { docked: boolean }) {
const submit = () => {
if (blocker || create.isPending) {
if (blocker) {
- toast(blocker.message);
+ // One blocker toast at a time (pressing Generate again replaces it), gone once a run starts.
+ toast(blocker.message, { id: "composer-blocker" });
// Point at the tile to fill: the missing slot, or the clip list of a tool that only takes clips.
const target = blocker.slot ?? (config.multiRef && config.hidePrompt && draft.refs.length < 2 ? "refs" : undefined);
if (target) pulseSlot(root.current, target);
}
return;
}
+ toast.dismiss("composer-blocker");
setRecent((r) => pushRecent(r, draft.modelId));
// The server resolves @mentions and drawings itself; only pin the operation when there are none.
+ // No "Queued" toast: the new card (and the "1 generating ↑" pill when it's off-screen) says it.
create.mutate(buildRequest(config.feature, draft, resolvesOnServer ? studioOp : op, config.promptSuffix, config.multiRef?.kind), {
- onSuccess: (items) => {
- toast.success(items.length > 1 ? `${items.length} jobs queued` : "Queued", { duration: 1500 });
- },
onError: (e) => toast.error((e as Error).message),
});
};
diff --git a/src/components/studio/feed.tsx b/src/components/studio/feed.tsx
index e33b0664..12525fb6 100644
--- a/src/components/studio/feed.tsx
+++ b/src/components/studio/feed.tsx
@@ -1,6 +1,6 @@
"use client";
-import { Cloud, Copy, Cpu, FolderDown, Heart, MoreHorizontal, RotateCcw, Sparkles, Trash2, X } from "lucide-react";
+import { Cloud, Copy, Cpu, Download, FolderDown, Heart, MoreHorizontal, RotateCcw, Sparkles, Trash2, X } from "lucide-react";
import { createContext, memo, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
import { toast } from "sonner";
import {
@@ -14,8 +14,8 @@ import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip
import { OPERATION_LABELS, type Generation } from "@/lib/catalog/types";
import { useCreateGeneration, useGenerationActions } from "@/lib/api";
import { elapsed, formatCost, ratioValue, timeAgo } from "@/lib/format";
-import { userTitle } from "@/lib/library";
-import { isLayered } from "@/lib/output-actions";
+import { downloadHref, downloadName, userTitle } from "@/lib/library";
+import { isLayered, shownOutputs } from "@/lib/output-actions";
import { cn } from "@/lib/utils";
import { TileActions, useCanHover, type RunnerOptions } from "./result-actions";
import { LayersStack, MediaThumb } from "./result-media";
@@ -135,40 +135,47 @@ function DraftButton({ g, draftId }: { g: Generation; draftId: string }) {
);
}
-const OutputTile = memo(function OutputTile({ g, index, ratio, layered }: { g: Generation; index: number; ratio: number; layered?: boolean }) {
+const SHOW_ON_HOVER = "opacity-0 transition-opacity duration-100 group-focus-within/tile:opacity-100 group-hover/tile:opacity-100";
+
+const OutputTile = memo(function OutputTile({ g, index, ratio, layered, count }: { g: Generation; index: number; ratio: number; layered?: boolean; count: number }) {
const feed = useFeed();
const canHover = useCanHover();
// Actions mount on first hover / focus / tap: a long feed shouldn't hold thousands of menus and tooltips.
const [hot, setHot] = useState<false | "bar" | "menu">(false);
const o = g.outputs[index];
+ const audio = o.kind === "audio";
const ctx = useMemo(() => ({ reuse: !!feed.reuse }), [feed.reuse]);
return (
+ // The tile opens on click; keyboards and screen readers use the Open button over it (a sibling of
+ // the action buttons, so no button sits inside another).
<div
- role="button"
- tabIndex={0}
- aria-label={`Open ${o.kind === "text" ? "text" : o.kind}${g.outputs.length > 1 && !layered ? ` ${index + 1} of ${g.outputs.length}` : ""}`}
onClick={() => feed.open(g, index)}
- onKeyDown={(e) => {
- if (e.target === e.currentTarget && (e.key === "Enter" || e.key === " ")) {
- e.preventDefault();
- feed.open(g, index);
- }
- }}
onPointerEnter={(e) => e.pointerType === "mouse" && !hot && setHot("bar")}
onFocus={() => canHover && !hot && setHot("bar")}
- className="group/tile relative h-56 max-w-full animate-fade-up cursor-zoom-in overflow-hidden rounded-xl bg-muted outline-none focus-visible:ring-2 focus-visible:ring-ring sm:h-64"
- style={{ aspectRatio: o.kind === "audio" ? 1.6 : layered ? Math.max(ratio, 0.8) : ratio }}
+ className="group/tile relative h-56 max-w-full animate-fade-up cursor-zoom-in overflow-hidden rounded-xl bg-muted sm:h-64"
+ style={{ aspectRatio: audio ? 1.6 : layered ? Math.max(ratio, 0.8) : ratio }}
>
{layered ? <LayersStack g={g} /> : <MediaThumb output={o} g={g} />}
+ <button
+ type="button"
+ aria-label={`Open “${userTitle(g)}”${count > 1 ? ` · ${index + 1} of ${count}` : ""}`}
+ onClick={(e) => {
+ e.stopPropagation();
+ feed.open(g, index);
+ }}
+ className="pointer-events-none absolute inset-0 rounded-xl outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset"
+ />
{o.draftId && <DraftButton g={g} draftId={o.draftId} />}
- {g.favorite && <Heart className="absolute top-2 right-2 size-4 fill-highlight text-highlight drop-shadow" />}
- {o.kind !== "audio" && canHover && hot === "bar" && (
+ {g.favorite && <Heart className={cn("absolute top-2 right-2 size-4 fill-highlight text-highlight drop-shadow", audio && canHover && "group-focus-within/tile:opacity-0 group-hover/tile:opacity-0")} />}
+ {canHover && hot === "bar" && (
<TileActions
g={g}
index={index}
ctx={ctx}
opts={feed.runner}
- className="absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/60 to-transparent p-2 pt-8 opacity-0 transition-opacity duration-100 group-focus-within/tile:opacity-100 group-hover/tile:opacity-100"
+ // Audio keeps its player at the bottom: its actions go along the top.
+ tone={audio ? "surface" : "media"}
+ className={cn(audio ? "absolute inset-x-0 top-0 p-2" : "absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/60 to-transparent p-2 pt-8", SHOW_ON_HOVER)}
/>
)}
{!canHover &&
@@ -198,6 +205,9 @@ export const GenerationGroup = memo(function GenerationGroup({ g }: { g: Generat
const active = g.status === "queued" || g.status === "running";
const placeholders = Math.max(1, g.request.params?.numOutputs ?? 1);
const layered = g.status === "succeeded" && isLayered(g);
+ const shown = shownOutputs(g);
+ const single = g.status === "succeeded" && shown.length === 1 ? g.outputs[shown[0]] : null;
+ const singleName = single ? downloadName(g, single, shown[0]) : "";
const p = g.request.params ?? {};
const meta = [
g.request.step?.label,
@@ -261,6 +271,13 @@ export const GenerationGroup = memo(function GenerationGroup({ g }: { g: Generat
<DropdownMenuItem onSelect={() => void favorite(g)}>
<Heart /> {g.favorite ? "Remove from favorites" : "Add to favorites"}
</DropdownMenuItem>
+ {single && !layered && (
+ <DropdownMenuItem asChild>
+ <a href={downloadHref(single.url, singleName)} download={singleName}>
+ <Download /> Download
+ </a>
+ </DropdownMenuItem>
+ )}
{g.status === "succeeded" && g.outputs.length > 1 && (
<DropdownMenuItem asChild>
<a href={`/api/generations/zip?ids=${g.id}`} download>
@@ -289,7 +306,11 @@ export const GenerationGroup = memo(function GenerationGroup({ g }: { g: Generat
</div>
)}
{g.status === "succeeded" &&
- (layered ? <OutputTile g={g} index={0} ratio={ratio} layered /> : g.outputs.map((o, i) => <OutputTile key={o.url} g={g} index={i} ratio={ratio} />))}
+ (layered ? (
+ <OutputTile g={g} index={0} ratio={ratio} layered count={1} />
+ ) : (
+ shown.map((i) => <OutputTile key={g.outputs[i].url} g={g} index={i} ratio={ratio} count={shown.length} />)
+ ))}
</div>
</section>
);
@@ -325,7 +346,7 @@ export function Feed({
[openAt, hasReuse],
);
if (!items.length) return <>{empty}</>;
- const flat = items.flatMap((g) => (g.status === "succeeded" ? (isLayered(g) ? [{ g, i: 0 }] : g.outputs.map((_, i) => ({ g, i }))) : []));
+ const flat = items.flatMap((g) => (g.status === "succeeded" ? (isLayered(g) ? [{ g, i: 0 }] : shownOutputs(g).map((i) => ({ g, i }))) : []));
const pos = open ? flat.findIndex((f) => f.g.id === open.id && (f.i === open.index || isLayered(f.g))) : -1;
return (
<FeedCtx.Provider value={api}>
diff --git a/src/components/studio/result-actions.tsx b/src/components/studio/result-actions.tsx
index 85d3a5fb..d821cb7c 100644
--- a/src/components/studio/result-actions.tsx
+++ b/src/components/studio/result-actions.tsx
@@ -27,8 +27,18 @@ import {
} from "lucide-react";
import Link from "next/link";
import { useRouter } from "next/navigation";
-import { useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
+import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
import { toast } from "sonner";
+import {
+ AlertDialog,
+ AlertDialogAction,
+ AlertDialogCancel,
+ AlertDialogContent,
+ AlertDialogDescription,
+ AlertDialogFooter,
+ AlertDialogHeader,
+ AlertDialogTitle,
+} from "@/components/ui/alert-dialog";
import {
DropdownMenu,
DropdownMenuContent,
@@ -42,7 +52,8 @@ import { useCreateGeneration, useGenerationActions, useSaveElement } from "@/lib
import { ELEMENT_KINDS, type ElementKind } from "@/lib/catalog/elements";
import type { Generation, OutputFile } from "@/lib/catalog/types";
import { downloadName } from "@/lib/library";
-import { cuesOf, cuesToSrt, outputActions, textOf, type ActionContext, type OutputAction, type OutputActionId } from "@/lib/output-actions";
+import { toSrt, toVtt } from "@/lib/cues";
+import { cuesOf, outputActions, textOf, type ActionContext, type OutputAction, type OutputActionId } from "@/lib/output-actions";
import { cn } from "@/lib/utils";
export const ACTION_ICONS: Record<OutputActionId, LucideIcon> = {
@@ -62,6 +73,7 @@ export const ACTION_ICONS: Record<OutputActionId, LucideIcon> = {
download: Download,
"download-txt": FileDown,
"download-srt": FileDown,
+ "download-vtt": FileDown,
"download-all": FolderDown,
favorite: Heart,
finalize: Sparkles,
@@ -111,10 +123,56 @@ export interface RunnerOptions {
onDeleted?: () => void;
}
+// ---------------------------------------------------------------------------
+// Delete forever always asks first, for one item or many (the Trash's cards, viewer and bulk bar).
+
+type ConfirmForever = (gs: Generation[], after?: () => void) => void;
+const ForeverCtx = createContext<ConfirmForever | null>(null);
+
+/** Asks before anything is deleted for good. Wrap views that show the Trash. */
+export function ForeverConfirmProvider({ children }: { children: React.ReactNode }) {
+ const actions = useGenerationActions();
+ const [pending, setPending] = useState<{ gs: Generation[]; after?: () => void } | null>(null);
+ const ask = useCallback<ConfirmForever>((gs, after) => {
+ if (gs.length) setPending({ gs, after });
+ }, []);
+ const n = pending?.gs.length ?? 0;
+ return (
+ <ForeverCtx.Provider value={ask}>
+ {children}
+ <AlertDialog open={!!pending} onOpenChange={(v) => !v && setPending(null)}>
+ <AlertDialogContent>
+ <AlertDialogHeader>
+ <AlertDialogTitle>Delete {n === 1 ? "this for good" : `${n} items for good`}?</AlertDialogTitle>
+ <AlertDialogDescription>{n === 1 ? "It's" : "They're"} removed with the files and can&apos;t be recovered.</AlertDialogDescription>
+ </AlertDialogHeader>
+ <AlertDialogFooter>
+ <AlertDialogCancel>Cancel</AlertDialogCancel>
+ <AlertDialogAction
+ variant="destructive"
+ onClick={() => {
+ if (!pending) return;
+ void actions.deleteForever(pending.gs).then((done) => done && toast(done === 1 ? "Deleted for good" : `Deleted ${done} for good`));
+ pending.after?.();
+ }}
+ >
+ Delete forever
+ </AlertDialogAction>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
+ </ForeverCtx.Provider>
+ );
+}
+
+/** The Trash's confirm step (null outside a ForeverConfirmProvider). */
+export const useConfirmForever = () => useContext(ForeverCtx);
+
/** Handlers for the actions that aren't plain links. "save-character" is handled by the caller's popover. */
export function useActionRunner(opts: RunnerOptions = {}) {
const actions = useGenerationActions();
const create = useCreateGeneration();
+ const confirmForever = useConfirmForever();
return (a: OutputAction, g: Generation, index: number) => {
const o = g.outputs[index];
switch (a.id) {
@@ -129,7 +187,9 @@ export function useActionRunner(opts: RunnerOptions = {}) {
case "download-txt":
return saveBlob(textOf(o), downloadName(g, o, index, "txt"), "text/plain");
case "download-srt":
- return saveBlob(cuesToSrt(cuesOf(o)), downloadName(g, o, index, "srt"), "application/x-subrip");
+ return saveBlob(toSrt(cuesOf(o)), downloadName(g, o, index, "srt"), "application/x-subrip");
+ case "download-vtt":
+ return saveBlob(toVtt(cuesOf(o)), downloadName(g, o, index, "vtt"), "text/vtt");
case "finalize":
return create.mutate(
{ feature: g.feature, modelId: g.modelId, op: "finalize", prompt: g.request.prompt, params: { draftId: o.draftId, resolution: "1080p", duration: g.request.params?.duration } },
@@ -148,8 +208,9 @@ export function useActionRunner(opts: RunnerOptions = {}) {
void actions.restore([g]);
return void toast("Restored");
case "delete-forever":
- void actions.deleteForever([g]);
- toast("Deleted for good");
+ if (confirmForever) return confirmForever([g], opts.onDeleted);
+ if (!window.confirm("Delete this for good? It's removed with its files and can't be recovered.")) return;
+ void actions.deleteForever([g]).then((done) => done && toast("Deleted for good"));
return opts.onDeleted?.();
}
};
@@ -243,12 +304,18 @@ export function useCanHover(): boolean {
}
const TILE_ICON = "grid size-8 place-items-center rounded-lg text-white/90 transition-colors hover:bg-white/20 hover:text-white focus-visible:bg-white/20 outline-none";
+/** On a light surface (audio tiles): the same buttons in the brand colour. */
+const SURFACE_ICON = "grid size-8 place-items-center rounded-lg text-brand-text transition-colors hover:bg-background/80 focus-visible:bg-background/80 outline-none";
+
+/** Below this strip width (content box) Download and Favorite go into the ⋯ menu, so ⋯ always fits. */
+const NARROW_STRIP = 160;
/**
* The action strip on a result tile: a labelled primary pill, Download and Favorite icons, and a ⋯
* menu with the rest. Tiles mount it lazily (on first hover or focus), so long feeds don't mount
- * thousands of tooltips, menus and mutation observers. `menuOnly` (touch screens): just the ⋯ menu
- * with every action, opened right away.
+ * thousands of tooltips, menus and mutation observers. It fits small cards: under 220 px the pill
+ * loses its label, under 160 px Download and Favorite move into the menu. `menuOnly` (touch
+ * screens): just the ⋯ menu with every action, opened right away.
*/
export function TileActions({
g,
@@ -258,6 +325,7 @@ export function TileActions({
menuOnly,
className,
triggerClassName,
+ tone = "media",
}: {
g: Generation;
index: number;
@@ -267,10 +335,21 @@ export function TileActions({
className?: string;
/** menuOnly: the ⋯ button's look (default: white on a dark chip, for media). */
triggerClassName?: string;
+ /** "media": white on a dark gradient; "surface": on a light card (audio). */
+ tone?: "media" | "surface";
}) {
const run = useActionRunner(opts);
const list = useMemo(() => outputActions(g, index, ctx), [g, index, ctx]);
const [saving, setSaving] = useState(false);
+ const strip = useRef<HTMLDivElement>(null);
+ const [narrow, setNarrow] = useState(false);
+ useEffect(() => {
+ const el = strip.current;
+ if (!el) return;
+ const ro = new ResizeObserver(([e]) => setNarrow(e.contentRect.width < NARROW_STRIP));
+ ro.observe(el);
+ return () => ro.disconnect();
+ }, []);
const popover = saving && (
<Popover open onOpenChange={(v) => !v && setSaving(false)}>
<PopoverAnchor className="absolute right-2 bottom-2" />
@@ -290,35 +369,45 @@ export function TileActions({
}
const primary = list.find((a) => a.placement === "primary");
const bar = list.filter((a) => a.placement === "bar");
- const icon = TILE_ICON;
- const pill = "inline-flex h-8 shrink-0 items-center gap-1.5 rounded-full bg-white/90 px-3 text-[12px] font-medium text-black shadow-soft transition-colors hover:bg-white outline-none focus-visible:ring-2 focus-visible:ring-white";
+ const menu = list.filter((a) => a.placement === "menu");
+ const icon = tone === "surface" ? SURFACE_ICON : TILE_ICON;
+ const pill = cn(
+ "inline-flex h-8 shrink-0 items-center gap-1.5 rounded-full px-2.5 text-[12px] font-medium shadow-soft transition-colors outline-none @min-[220px]:px-3",
+ tone === "surface" ? "bg-background text-foreground hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring" : "bg-white/90 text-black hover:bg-white focus-visible:ring-2 focus-visible:ring-white",
+ );
const PrimaryIcon = primary ? ACTION_ICONS[primary.id] : null;
+ const pillBody = primary && PrimaryIcon && (
+ <>
+ <PrimaryIcon className="size-3.5" /> <span className="hidden @min-[220px]:inline">{primary.label}</span>
+ </>
+ );
return (
- <div className={cn("flex items-center gap-0.5", className)} onClick={stop} onKeyDown={stop}>
+ <div ref={strip} className={cn("@container flex items-center gap-0.5", className)} onClick={stop} onKeyDown={stop}>
{primary &&
- PrimaryIcon &&
+ pillBody &&
(primary.href ? (
- <Link href={primary.href} prefetch={false} className={pill}>
- <PrimaryIcon className="size-3.5" /> {primary.label}
+ <Link href={primary.href} prefetch={false} className={pill} aria-label={primary.label}>
+ {pillBody}
</Link>
) : (
- <button className={pill} onClick={() => run(primary, g, index)}>
- <PrimaryIcon className="size-3.5" /> {primary.label}
+ <button className={pill} aria-label={primary.label} onClick={() => run(primary, g, index)}>
+ {pillBody}
</button>
))}
<span className="flex-1" />
{bar.map((a) => {
const Icon = ACTION_ICONS[a.id];
const body = <Icon className={cn("size-4", a.id === "favorite" && g.favorite && "fill-current")} />;
+ const cls = cn(icon, "hidden @min-[160px]:grid");
return (
<Tooltip key={a.id}>
<TooltipTrigger asChild>
{a.download !== undefined ? (
- <a href={a.href} download={a.download} className={icon} aria-label={a.label}>
+ <a href={a.href} download={a.download} className={cls} aria-label={a.label}>
{body}
</a>
) : (
- <button className={icon} aria-label={a.label} aria-pressed={a.id === "favorite" ? g.favorite : undefined} onClick={() => run(a, g, index)}>
+ <button className={cls} aria-label={a.label} aria-pressed={a.id === "favorite" ? g.favorite : undefined} onClick={() => run(a, g, index)}>
{body}
</button>
)}
@@ -327,7 +416,7 @@ export function TileActions({
</Tooltip>
);
})}
- <ActionMenu g={g} index={index} list={list.filter((a) => a.placement === "menu")} run={run} onSave={() => setSaving(true)} triggerClassName={icon} />
+ <ActionMenu g={g} index={index} list={narrow ? [...bar, ...menu] : menu} run={run} onSave={() => setSaving(true)} triggerClassName={icon} />
{popover}
</div>
);
@@ -355,6 +444,8 @@ export function ActionMenu({
}) {
const destructive = list.filter((a) => a.destructive);
const rest = list.filter((a) => !a.destructive);
+ // Focus goes back to ⋯ when the menu closes, except when it hands over to the Save-as-element popover.
+ const handingOff = useRef(false);
const item = (a: OutputAction) => {
const Icon = ACTION_ICONS[a.id];
if (a.href && a.download !== undefined) {
@@ -376,7 +467,15 @@ export function ActionMenu({
);
}
return (
- <DropdownMenuItem key={a.id} variant={a.destructive ? "destructive" : "default"} onSelect={() => (a.id === "save-character" ? onSave() : run(a, g, index))}>
+ <DropdownMenuItem
+ key={a.id}
+ variant={a.destructive ? "destructive" : "default"}
+ onSelect={() => {
+ if (a.id !== "save-character") return run(a, g, index);
+ handingOff.current = true;
+ onSave();
+ }}
+ >
<Icon className={cn(a.id === "favorite" && g.favorite && "fill-current")} /> {a.id === "save-character" ? "Save as element…" : a.label}
</DropdownMenuItem>
);
@@ -388,7 +487,17 @@ export function ActionMenu({
<MoreHorizontal className="size-4" />
</button>
</DropdownMenuTrigger>
- <DropdownMenuContent align="end" collisionPadding={12} className="min-w-48" onClick={stop} onCloseAutoFocus={(e) => e.preventDefault()}>
+ <DropdownMenuContent
+ align="end"
+ collisionPadding={12}
+ className="min-w-48"
+ onClick={stop}
+ onCloseAutoFocus={(e) => {
+ if (!handingOff.current) return;
+ e.preventDefault();
+ handingOff.current = false;
+ }}
+ >
{rest.map(item)}
{destructive.length > 0 && <DropdownMenuSeparator />}
{destructive.map(item)}
diff --git a/src/components/studio/viewer.tsx b/src/components/studio/viewer.tsx
index 258e2a79..bc0e345e 100644
--- a/src/components/studio/viewer.tsx
+++ b/src/components/studio/viewer.tsx
@@ -9,7 +9,7 @@ import { Dialog, DialogContent, DialogDescription, DialogTitle } from "@/compone
import { Kbd } from "@/components/ui/kbd";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle } from "@/components/ui/sheet";
-import { OPERATION_LABELS, type Generation } from "@/lib/catalog/types";
+import { OPERATION_LABELS, type Generation, type OutputFile } from "@/lib/catalog/types";
import { formatCost, timeAgo } from "@/lib/format";
import { trashDaysLeft, userTitle } from "@/lib/library";
import { isLayered, layerInfo, outputActions, type OutputAction } from "@/lib/output-actions";
@@ -39,6 +39,12 @@ function ignoreKey(e: KeyboardEvent): boolean {
return !!t.closest("video,audio,model-viewer") && (e.key.startsWith("Arrow") || e.key === " ");
}
+/** A text field of an output's meta (a stem's name, a transcript's language), capitalised. */
+function metaText(o: OutputFile | undefined, key: string): string | undefined {
+ const v = o?.meta?.[key];
+ return typeof v === "string" && v ? v[0].toUpperCase() + v.slice(1) : undefined;
+}
+
function Details({ g, index }: { g: Generation; index: number }) {
const p = g.request.params ?? {};
const title = userTitle(g);
@@ -58,7 +64,7 @@ function Details({ g, index }: { g: Generation; index: number }) {
<div className="space-y-4">
<div>
<p className="font-heading text-[20px] leading-snug">{title}</p>
- {g.prompt && g.prompt !== title && <p className="mt-1 text-[12px] leading-relaxed break-words text-muted-foreground">Sent to the model: {g.prompt}</p>}
+ {g.prompt && g.prompt !== title && <p className="mt-1 line-clamp-6 text-[12px] leading-relaxed break-words text-muted-foreground">Sent to the model: {g.prompt}</p>}
{g.prompt && (
<button
onClick={() => {
@@ -78,6 +84,8 @@ function Details({ g, index }: { g: Generation; index: number }) {
<Row label="Preset" value={g.presetName} />
<Row label="Step" value={g.request.step?.label} />
{isLayered(g) && <Row label="Layer" value={`${layerInfo(g.outputs[index], index).name} · ${index + 1} of ${g.outputs.length}`} />}
+ <Row label="Stem" value={metaText(g.outputs[index], "stem")} />
+ <Row label="Language" value={metaText(g.outputs[index], "language") ?? p.targetLanguage} />
<Row label="Aspect ratio" value={p.aspectRatio ?? g.aspectRatio} />
<Row label="Quality" value={p.resolution} />
<Row label="Duration" value={p.duration ? `${p.duration}s` : undefined} />
diff --git a/src/lib/library.ts b/src/lib/library.ts
index f4aec08e..b56c9b04 100644
--- a/src/lib/library.ts
+++ b/src/lib/library.ts
@@ -131,8 +131,13 @@ export function extensionOf(o: Pick<OutputFile, "url" | "kind">): string {
return m ? m[1].toLowerCase() : EXT_BY_KIND[o.kind];
}
-export function downloadName(g: Pick<Generation, "id" | "prompt" | "modelId" | "request">, o: Pick<OutputFile, "url" | "kind">, i: number, ext = extensionOf(o)): string {
- const base = (g.request.prompt || g.prompt || g.modelId).slice(0, 40).replace(/[^\w]+/g, "-").replace(/^-|-$/g, "") || "fuobe";
+export function downloadName(
+ g: Pick<Generation, "id" | "prompt" | "modelId" | "request" | "op" | "presetName" | "modelName">,
+ o: Pick<OutputFile, "url" | "kind">,
+ i: number,
+ ext = extensionOf(o),
+): string {
+ const base = userTitle(g).slice(0, 40).replace(/[^\w]+/g, "-").replace(/^-|-$/g, "") || "fuobe";
return `${base}-${g.id.slice(0, 6)}${i ? `-${i + 1}` : ""}.${ext}`;
}
@@ -192,9 +197,20 @@ export function userTitle(g: Pick<Generation, "request" | "presetName" | "prompt
if (own) return own;
if (g.request.frame) return unwrapScene(g.request.frame.scene);
const words = g.request.prompt?.trim() || g.presetName || g.prompt?.trim();
- if (words && words !== g.op) return words;
+ if (words && words !== g.op && !isData(words)) return words;
const what = OPERATION_LABELS[g.op];
- return what ? `${what}${g.modelName ? ` · ${g.modelName}` : ""}` : (g.modelName ?? "Untitled");
+ const into = g.op === "translate" && g.request.params?.targetLanguage ? ` into ${g.request.params.targetLanguage}` : "";
+ return what ? `${what}${into}${g.modelName ? ` · ${g.modelName}` : ""}` : (g.modelName ?? "Untitled");
+}
+
+/** A chained step's prompt that is data, not words (a translation fed a transcript's cue list). */
+function isData(s: string): boolean {
+ if (!/^[[{]/.test(s)) return false;
+ try {
+ return typeof JSON.parse(s) === "object";
+ } catch {
+ return false;
+ }
}
const order = (g: Generation) => g.request.step?.index ?? g.request.frame?.index ?? 0;
diff --git a/tests/library-pure.test.ts b/tests/library-pure.test.ts
index 80453c83..5c969321 100644
--- a/tests/library-pure.test.ts
+++ b/tests/library-pure.test.ts
@@ -296,6 +296,10 @@ describe("round-3 fixes", () => {
expect(userTitle(gen({ op: "transcribe", modelName: "Whisper", prompt: null, request: { feature: "transcribe", modelId: "w" } }))).toBe("Transcribe · Whisper");
expect(userTitle(gen({ op: "image-to-3d", modelName: "Hunyuan3D", prompt: "image-to-3d", request: { feature: "3d", modelId: "h" } }))).toMatch(/ · Hunyuan3D$/);
expect(userTitle(gen({ request: { feature: "image", modelId: "m", prompt: "a fox", title: "Fox poster" } }))).toBe("Fox poster");
+ // A chained translation got a transcript's cue list as its prompt: that's data, not a title.
+ const cuesIn = gen({ id: "tr0000000001", op: "translate", modelName: "Claude", prompt: '[{"start":0,"end":1,"text":"Hi"}]', request: { feature: "dub", modelId: "text-llm", prompt: '[{"start":0,"end":1,"text":"Hi"}]', params: { targetLanguage: "Spanish" } } });
+ expect(userTitle(cuesIn)).toBe("Translate into Spanish · Claude");
+ expect(downloadName(cuesIn, { url: "/x/a.srt", kind: "text" }, 0)).toBe("Translate-into-Spanish-Claude-tr0000.srt");
});
it("titles an Assist plan's stack with its summary and labels mixed results", () => {