mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-16 06:19:21 +00:00
fix(studio): sidebar/panels UX — asset delete confirm, rename, search trap, undo (#1966)
Left-sidebar and slideshow-panel fixes from the studio UX review. Four criticals: an unconfirmed permanent asset delete, a Rename menu item that did nothing, a search box that unmounted itself while its filter stayed applied, and slideshow edits whose persist failures were swallowed. Asset context menu: Delete shows an inline DeleteConfirm before calling the API; the dead Rename item is a working inline rename (validates `/`, `\`, `..`, preserves directory + extension); role="menu"/"menuitem", Escape, arrow-key nav, focus-into-menu, viewport clamping. Assets tab: header controls gate on the UNFILTERED asset count, so a no-match query shows "No assets match" + Clear search instead of unmounting its own input; cards and font rows are keyboard-operable; a copy chip surfaces clipboard failure; the import button owns its pending state; a broken thumbnail names the file type. Slideshow panel: persist failures raise a "Changes not saved — Retry" banner (role="alert") with a working retry; in-panel undo stack (50 snapshots, scoped ⌘Z); branch delete confirms inline; reorder buttons disable at boundaries; HotspotTool explains its prerequisites. Blocks / compositions tabs: "Added!"/"Copied!" are promise-truthful; hover-only overlays reveal on focus; PromptPreviewModal gets the dialog contract + dirty-draft guard; lint dot → labeled count badge; the render button explains "A render is already in progress"; sidebar tabs are a real APG tablist; AudioRow coordinates a single preview at a time. Restacked onto main now that PRs 1962/1963/1964 have squash-merged, so this carries only its own changes. Reconciled against six weeks of main: main's newer interaction model wins (rows drag to the timeline, click reveals the clip or opens the preview, copy is a context-menu action), and this PR's a11y and error surfacing is ported on top of it. The card components main extracted to AssetCard.tsx receive the keyboard activation, focus cues and copy-outcome chip; the "Add at playhead" item main added joins the rewritten menu's arrow-key order; the Catalog tab is unconditional since the blocks-panel flag was removed. The row copy chip is feedback-only — an idle "Copy path" label would describe something the row no longer does. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
5fd84c395b
commit
44791c3f7d
@@ -183,6 +183,13 @@ export function SlideshowPanel({ scenes, onPersist, onPersistNotes }: SlideshowP
|
||||
const [expandedSections, setExpandedSections] = useState<Set<SectionKey>>(
|
||||
() => new Set<SectionKey>(["slides", "inspector"]),
|
||||
);
|
||||
// Persist failure surfacing: edits keep working in memory, but the user must
|
||||
// know the file write failed (and be able to retry) — never silent data loss.
|
||||
const [persistError, setPersistError] = useState(false);
|
||||
const [retrying, setRetrying] = useState(false);
|
||||
// In-panel undo history of manifest snapshots (discrete edits only).
|
||||
const undoStackRef = useRef<SlideshowManifest[]>([]);
|
||||
const [undoDepth, setUndoDepth] = useState(0);
|
||||
|
||||
const currentTime = usePlayerStore((s) => s.currentTime);
|
||||
const { domEditSelection } = useDomEditSelectionContext();
|
||||
@@ -209,26 +216,56 @@ export function SlideshowPanel({ scenes, onPersist, onPersistNotes }: SlideshowP
|
||||
setManifest(parsed);
|
||||
manifestRef.current = parsed;
|
||||
setSelectedSequenceId(null);
|
||||
// History belongs to one composition — a switch starts fresh.
|
||||
undoStackRef.current = [];
|
||||
setUndoDepth(0);
|
||||
setPersistError(false);
|
||||
}, [compHtml]);
|
||||
|
||||
/** Discrete actions (toggle, reorder, add/delete, hotspot): persist immediately. */
|
||||
const applyManifest = useCallback(
|
||||
async (next: SlideshowManifest) => {
|
||||
async (next: SlideshowManifest, opts?: { skipUndo?: boolean }) => {
|
||||
// Fold any in-flight typed notes into the discrete manifest so they are
|
||||
// not silently dropped when the debounce timer would have fired later.
|
||||
const merged = notesCtrlRef.current.mergeIntoDiscrete(next);
|
||||
if (!opts?.skipUndo) {
|
||||
undoStackRef.current.push(manifestRef.current);
|
||||
if (undoStackRef.current.length > 50) undoStackRef.current.shift();
|
||||
setUndoDepth(undoStackRef.current.length);
|
||||
}
|
||||
setManifest(merged);
|
||||
manifestRef.current = merged;
|
||||
// Surface persist failures instead of swallowing them at each call site.
|
||||
try {
|
||||
await onPersist(merged);
|
||||
setPersistError(false);
|
||||
} catch (err) {
|
||||
console.error("[slideshow] failed to persist manifest edit:", err);
|
||||
setPersistError(true);
|
||||
}
|
||||
},
|
||||
[onPersist],
|
||||
);
|
||||
|
||||
const handleUndo = useCallback(() => {
|
||||
const prev = undoStackRef.current.pop();
|
||||
if (!prev) return;
|
||||
setUndoDepth(undoStackRef.current.length);
|
||||
applyManifest(prev, { skipUndo: true }).catch(() => {});
|
||||
}, [applyManifest]);
|
||||
|
||||
const handleRetryPersist = useCallback(async () => {
|
||||
setRetrying(true);
|
||||
try {
|
||||
await onPersist(manifestRef.current);
|
||||
setPersistError(false);
|
||||
} catch (err) {
|
||||
console.error("[slideshow] retry persist failed:", err);
|
||||
} finally {
|
||||
setRetrying(false);
|
||||
}
|
||||
}, [onPersist]);
|
||||
|
||||
/**
|
||||
* Notes path: update in-memory state immediately for a responsive UI, but
|
||||
* debounce the disk persist to ~450 ms after the last keystroke. The pending
|
||||
@@ -338,18 +375,10 @@ export function SlideshowPanel({ scenes, onPersist, onPersistNotes }: SlideshowP
|
||||
[applyManifest],
|
||||
);
|
||||
|
||||
// Confirmation is inline in BranchItem (consistent with the FileTree/assets
|
||||
// delete pattern); by the time this fires the user has already confirmed.
|
||||
const handleDeleteSequence = useCallback(
|
||||
(id: string) => {
|
||||
// Deleting a branch removes its slides and orphans any hotspot targeting it —
|
||||
// confirm first to prevent accidental data loss.
|
||||
const seq = (manifestRef.current.slideSequences ?? []).find((s) => s.id === id);
|
||||
const count = seq?.slides.length ?? 0;
|
||||
const label = seq?.label ?? id;
|
||||
const ok = window.confirm(
|
||||
`Delete branch "${label}"${count ? ` and its ${count} slide${count === 1 ? "" : "s"}` : ""}? ` +
|
||||
`Hotspots pointing to it will no longer resolve.`,
|
||||
);
|
||||
if (!ok) return;
|
||||
applyManifest(deleteSequence(manifestRef.current, id)).catch(() => {});
|
||||
},
|
||||
[applyManifest],
|
||||
@@ -383,7 +412,47 @@ export function SlideshowPanel({ scenes, onPersist, onPersistNotes }: SlideshowP
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col h-full overflow-y-auto text-white">
|
||||
<div
|
||||
className="flex flex-col h-full overflow-y-auto text-white"
|
||||
onKeyDown={(e) => {
|
||||
// In-panel undo — scoped so it never fights the app-level file undo.
|
||||
if ((e.metaKey || e.ctrlKey) && !e.shiftKey && e.key.toLowerCase() === "z") {
|
||||
const target = e.target instanceof HTMLElement ? e.target.tagName : "";
|
||||
if (target === "TEXTAREA" || target === "INPUT") return;
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
handleUndo();
|
||||
}
|
||||
}}
|
||||
>
|
||||
{persistError && (
|
||||
<div
|
||||
role="alert"
|
||||
className="flex items-center justify-between gap-2 px-3 py-2 bg-red-950/40 border-b border-red-500/40"
|
||||
>
|
||||
<span className="text-[11px] text-red-300">Changes not saved</span>
|
||||
<button
|
||||
type="button"
|
||||
disabled={retrying}
|
||||
onClick={handleRetryPersist}
|
||||
className="px-2 py-0.5 text-[10px] rounded bg-red-600 text-white enabled:hover:bg-red-500 enabled:active:scale-[0.97] disabled:opacity-50 transition-colors"
|
||||
>
|
||||
{retrying ? "Retrying…" : "Retry"}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
{undoDepth > 0 && (
|
||||
<div className="flex items-center justify-end px-3 py-1 border-b border-neutral-800/60">
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleUndo}
|
||||
title="Undo last slideshow edit (⌘Z)"
|
||||
className="px-2 py-0.5 text-[10px] rounded text-neutral-400 hover:text-neutral-200 hover:bg-neutral-800 active:scale-[0.97] transition-colors"
|
||||
>
|
||||
Undo ({undoDepth})
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
<SectionHeader
|
||||
expanded={expandedSections.has("slides")}
|
||||
onToggle={() => toggleSection("slides")}
|
||||
|
||||
@@ -23,7 +23,7 @@ export function SectionHeader({
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className="flex w-full items-center justify-between px-3 py-2 text-[11px] font-medium text-neutral-400 hover:text-neutral-200 border-b border-neutral-800 transition-colors"
|
||||
className="flex w-full items-center justify-between px-3 py-2 text-[11px] font-medium text-neutral-400 hover:text-neutral-200 active:bg-neutral-800/60 border-b border-neutral-800 transition-colors"
|
||||
onClick={onToggle}
|
||||
aria-expanded={expanded}
|
||||
>
|
||||
@@ -64,6 +64,7 @@ export function SlideList({
|
||||
{rows.map((scene) => {
|
||||
const isSlide = slideIds.has(scene.id);
|
||||
const isSelected = selectedSceneId === scene.id;
|
||||
const slideIndex = slides.findIndex((s) => s.sceneId === scene.id);
|
||||
return (
|
||||
<div
|
||||
key={scene.id}
|
||||
@@ -98,7 +99,8 @@ export function SlideList({
|
||||
type="button"
|
||||
aria-label="Move slide up"
|
||||
title="Move up"
|
||||
className="px-1 py-0.5 text-[10px] text-neutral-400 hover:text-white disabled:opacity-30"
|
||||
disabled={slideIndex <= 0}
|
||||
className="px-1 py-0.5 text-[10px] text-neutral-400 enabled:hover:text-white enabled:active:scale-[0.95] disabled:opacity-30 disabled:cursor-not-allowed"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onReorder(scene.id, "up");
|
||||
@@ -110,7 +112,8 @@ export function SlideList({
|
||||
type="button"
|
||||
aria-label="Move slide down"
|
||||
title="Move down"
|
||||
className="px-1 py-0.5 text-[10px] text-neutral-400 hover:text-white disabled:opacity-30"
|
||||
disabled={slideIndex === slides.length - 1}
|
||||
className="px-1 py-0.5 text-[10px] text-neutral-400 enabled:hover:text-white enabled:active:scale-[0.95] disabled:opacity-30 disabled:cursor-not-allowed"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onReorder(scene.id, "down");
|
||||
@@ -310,6 +313,7 @@ function BranchItem({
|
||||
}: BranchItemProps) {
|
||||
const [editing, setEditing] = useState(false);
|
||||
const [draft, setDraft] = useState(seq.label);
|
||||
const [confirmingDelete, setConfirmingDelete] = useState(false);
|
||||
|
||||
const commitRename = useCallback(() => {
|
||||
const label = draft.trim();
|
||||
@@ -341,7 +345,10 @@ function BranchItem({
|
||||
title="Click to rename"
|
||||
onClick={() => setEditing(true)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter" || e.key === " ") setEditing(true);
|
||||
if (e.key === "Enter" || e.key === " ") {
|
||||
e.preventDefault();
|
||||
setEditing(true);
|
||||
}
|
||||
}}
|
||||
>
|
||||
{seq.label}
|
||||
@@ -350,12 +357,42 @@ function BranchItem({
|
||||
<button
|
||||
type="button"
|
||||
aria-label={`Delete branch ${seq.label}`}
|
||||
className="text-[10px] text-neutral-500 hover:text-red-400 transition-colors px-1"
|
||||
onClick={() => onDelete(seq.id)}
|
||||
className="text-[10px] text-neutral-500 hover:text-red-400 active:scale-[0.95] transition-colors px-1"
|
||||
onClick={() => setConfirmingDelete(true)}
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
</div>
|
||||
{confirmingDelete && (
|
||||
<div className="px-2 py-1.5 bg-red-950/30 border-l-2 border-red-500 flex flex-col gap-1 rounded-sm">
|
||||
<span className="text-[10px] text-red-400">
|
||||
Delete branch “{seq.label}”
|
||||
{seq.slides.length > 0
|
||||
? ` and its ${seq.slides.length} slide${seq.slides.length === 1 ? "" : "s"}`
|
||||
: ""}
|
||||
? Hotspots pointing to it will no longer resolve.
|
||||
</span>
|
||||
<div className="flex items-center justify-end gap-1">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setConfirmingDelete(false);
|
||||
onDelete(seq.id);
|
||||
}}
|
||||
className="px-2 py-0.5 text-[10px] rounded bg-red-600 text-white hover:bg-red-500 active:bg-red-700 transition-colors"
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setConfirmingDelete(false)}
|
||||
className="px-2 py-0.5 text-[10px] rounded text-neutral-400 hover:text-neutral-200 transition-colors"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div className="flex flex-col gap-px pl-2">
|
||||
{scenes.map((scene) => {
|
||||
const assigned = seq.slides.some((s) => s.sceneId === scene.id);
|
||||
@@ -447,6 +484,16 @@ export function HotspotTool({
|
||||
Selected element:{" "}
|
||||
<span className="text-neutral-200 font-mono">{elementKey ?? "none"}</span>
|
||||
</p>
|
||||
{!elementKey && (
|
||||
<p className="text-[10px] text-neutral-500 italic">
|
||||
Click an element on the canvas to choose the hotspot target.
|
||||
</p>
|
||||
)}
|
||||
{sequences.length === 0 && (
|
||||
<p className="text-[10px] text-neutral-500 italic">
|
||||
Create a branch in the Branches section first — hotspots jump to a branch.
|
||||
</p>
|
||||
)}
|
||||
<label className="text-[11px] text-neutral-400">Hotspot label</label>
|
||||
<input
|
||||
type="text"
|
||||
@@ -473,7 +520,14 @@ export function HotspotTool({
|
||||
<button
|
||||
type="button"
|
||||
disabled={!elementKey || !targetSequenceId}
|
||||
className="px-3 py-1.5 rounded bg-studio-accent/80 hover:bg-studio-accent text-white text-[11px] font-medium transition-colors disabled:opacity-40 disabled:cursor-not-allowed"
|
||||
title={
|
||||
!elementKey
|
||||
? "Select an element on the canvas first"
|
||||
: !targetSequenceId
|
||||
? "Choose a target branch first"
|
||||
: undefined
|
||||
}
|
||||
className="px-3 py-1.5 rounded bg-studio-accent/80 enabled:hover:bg-studio-accent enabled:active:scale-[0.98] text-white text-[11px] font-medium transition-colors disabled:opacity-40 disabled:cursor-not-allowed"
|
||||
onClick={handleMakeHotspot}
|
||||
>
|
||||
Make hotspot
|
||||
|
||||
@@ -52,7 +52,7 @@ describe("AssetCard click behavior", () => {
|
||||
const cardProps = {
|
||||
projectId: "p1",
|
||||
onCopy: vi.fn(),
|
||||
isCopied: false,
|
||||
copyFeedback: null,
|
||||
};
|
||||
|
||||
it("clears an open preview overlay when clicking an already-added asset (reveal branch)", () => {
|
||||
@@ -81,7 +81,7 @@ describe("AudioRow click behavior", () => {
|
||||
const rowProps = {
|
||||
projectId: "p1",
|
||||
onCopy: vi.fn(),
|
||||
isCopied: false,
|
||||
copyFeedback: null,
|
||||
};
|
||||
|
||||
it("clears an open preview overlay when clicking an already-added audio asset (reveal branch)", () => {
|
||||
|
||||
@@ -11,7 +11,7 @@ import { usePlayerStore } from "../../player/store/playerStore";
|
||||
import { timelineClipFocusId } from "../../player/components/timelineNavigationIdentity";
|
||||
import { useAssetPreviewStore } from "../../utils/assetPreviewStore";
|
||||
import { findClipForAsset, isPointerClick } from "../../utils/assetClickBehavior";
|
||||
import { basename, ext, truncateMiddle, formatDuration } from "./assetHelpers";
|
||||
import { basename, ext, truncateMiddle, formatDuration, type CopyFeedback } from "./assetHelpers";
|
||||
import { resolveMediaPreviewUrl } from "../../player/components/thumbnailUtils";
|
||||
|
||||
/** Drag payload writer shared by the asset tile and the font row: copy effect
|
||||
@@ -22,6 +22,23 @@ function writeAssetDragData(e: React.DragEvent, asset: string): void {
|
||||
e.dataTransfer.setData("text/plain", asset);
|
||||
}
|
||||
|
||||
/** Copy-path outcome chip. Copying is a context-menu action, so this is pure
|
||||
* feedback — it renders only once a copy has succeeded or failed, and never
|
||||
* as an idle affordance for something the tile itself does not do. */
|
||||
function CopyChip({ feedback, asset }: { feedback: CopyFeedback; asset: string }) {
|
||||
if (feedback?.path !== asset) return null;
|
||||
return (
|
||||
<span
|
||||
role="status"
|
||||
className={`flex-shrink-0 text-[9px] font-medium px-1.5 py-px rounded ${
|
||||
feedback.ok ? "text-panel-accent bg-panel-accent/10" : "text-red-400 bg-red-500/10"
|
||||
}`}
|
||||
>
|
||||
{feedback.ok ? "Copied" : "Copy failed"}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
/** Open the row/tile context menu at the pointer, shared by asset tile + font row. */
|
||||
function openAssetContextMenu(
|
||||
e: React.MouseEvent,
|
||||
@@ -90,7 +107,7 @@ export interface AssetCardProps {
|
||||
used: boolean;
|
||||
duration?: number;
|
||||
onCopy: (path: string) => void;
|
||||
isCopied: boolean;
|
||||
copyFeedback: CopyFeedback;
|
||||
onDelete?: (path: string) => void;
|
||||
onRename?: (oldPath: string, newPath: string) => void;
|
||||
onAddAssetToTimeline?: (path: string) => void;
|
||||
@@ -112,13 +129,15 @@ export function AssetCard({
|
||||
used,
|
||||
duration,
|
||||
onCopy,
|
||||
isCopied,
|
||||
copyFeedback,
|
||||
onDelete,
|
||||
onRename,
|
||||
onAddAssetToTimeline,
|
||||
}: AssetCardProps) {
|
||||
const [contextMenu, setContextMenu] = useState<{ x: number; y: number } | null>(null);
|
||||
const [hovered, setHovered] = useState(false);
|
||||
const [imgError, setImgError] = useState(false);
|
||||
const isCopied = copyFeedback?.path === asset && copyFeedback.ok;
|
||||
const fullName = asset.split("/").pop() ?? asset;
|
||||
const name = basename(asset);
|
||||
const extension = ext(asset);
|
||||
@@ -143,66 +162,80 @@ export function AssetCard({
|
||||
pointerDownRef.current = { x: e.clientX, y: e.clientY };
|
||||
}, []);
|
||||
|
||||
// Reveal the clip when the asset is already on the timeline, otherwise open
|
||||
// the preview overlay. Shared by pointer-up and keyboard activation so the
|
||||
// tile does the same thing however it is operated.
|
||||
const activateCard = useCallback(() => {
|
||||
if (used) {
|
||||
const clip = findClipForAsset(elements, asset);
|
||||
if (clip) {
|
||||
// Dismiss any open preview overlay (from another asset) — the reveal
|
||||
// must not leave a stale preview card floating over the canvas.
|
||||
clearPreviewAsset();
|
||||
const clipKey = clip.key ?? clip.id;
|
||||
setSelectedElementId(clipKey);
|
||||
// Scroll the timeline so the selected clip is actually visible.
|
||||
requestTimelineFocus(timelineClipFocusId(clipKey));
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Not added (or no matching clip found) → preview overlay
|
||||
setPreviewAsset(asset, projectId);
|
||||
}, [
|
||||
used,
|
||||
elements,
|
||||
asset,
|
||||
projectId,
|
||||
setSelectedElementId,
|
||||
requestTimelineFocus,
|
||||
setPreviewAsset,
|
||||
clearPreviewAsset,
|
||||
]);
|
||||
|
||||
const handlePointerUp = useCallback(
|
||||
(e: React.PointerEvent) => {
|
||||
const origin = pointerDownRef.current;
|
||||
pointerDownRef.current = null;
|
||||
if (!origin) return;
|
||||
if (!isPointerClick(e.clientX - origin.x, e.clientY - origin.y)) return;
|
||||
// Treat as click
|
||||
if (used) {
|
||||
const clip = findClipForAsset(elements, asset);
|
||||
if (clip) {
|
||||
// Dismiss any open preview overlay (from another asset) — the reveal
|
||||
// must not leave a stale preview card floating over the canvas.
|
||||
clearPreviewAsset();
|
||||
const clipKey = clip.key ?? clip.id;
|
||||
setSelectedElementId(clipKey);
|
||||
// Scroll the timeline so the selected clip is actually visible.
|
||||
requestTimelineFocus(timelineClipFocusId(clipKey));
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Not added (or no matching clip found) → preview overlay
|
||||
setPreviewAsset(asset, projectId);
|
||||
activateCard();
|
||||
},
|
||||
[
|
||||
used,
|
||||
elements,
|
||||
asset,
|
||||
projectId,
|
||||
setSelectedElementId,
|
||||
requestTimelineFocus,
|
||||
setPreviewAsset,
|
||||
clearPreviewAsset,
|
||||
],
|
||||
[activateCard],
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
draggable
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
aria-label={`${name} — open, drag to timeline, right-click for actions`}
|
||||
onPointerDown={handlePointerDown}
|
||||
onPointerUp={handlePointerUp}
|
||||
onKeyDown={(e) => {
|
||||
if (e.target !== e.currentTarget) return;
|
||||
if (e.key === "Enter" || e.key === " ") {
|
||||
e.preventDefault();
|
||||
activateCard();
|
||||
}
|
||||
}}
|
||||
onDragStart={(e) => writeAssetDragData(e, asset)}
|
||||
onContextMenu={(e) => openAssetContextMenu(e, setContextMenu)}
|
||||
onPointerEnter={() => setHovered(true)}
|
||||
onPointerLeave={() => setHovered(false)}
|
||||
className={`flex flex-col gap-1 cursor-pointer rounded-md p-1 transition-colors ${
|
||||
className={`flex flex-col gap-1 cursor-pointer rounded-md p-1 transition-colors outline-none focus-visible:bg-neutral-800/60 ${
|
||||
isCopied ? "bg-studio-accent/10" : "hover:bg-neutral-800/40"
|
||||
}`}
|
||||
>
|
||||
{/* Thumbnail */}
|
||||
<div className="w-full aspect-video rounded overflow-hidden bg-neutral-900 relative">
|
||||
{isImage && (
|
||||
{isImage && !imgError && (
|
||||
<img
|
||||
src={serveUrl}
|
||||
alt={name}
|
||||
loading="lazy"
|
||||
className="w-full h-full object-cover"
|
||||
onError={(e) => {
|
||||
(e.target as HTMLImageElement).style.display = "none";
|
||||
}}
|
||||
onError={() => setImgError(true)}
|
||||
/>
|
||||
)}
|
||||
{isVideo && (
|
||||
@@ -220,7 +253,7 @@ export function AssetCard({
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
{!isImage && !isVideo && (
|
||||
{((!isImage && !isVideo) || (isImage && imgError)) && (
|
||||
<div className="w-full h-full flex items-center justify-center">
|
||||
<span className="text-[10px] font-medium text-neutral-600">{extension}</span>
|
||||
</div>
|
||||
@@ -242,14 +275,17 @@ export function AssetCard({
|
||||
</div>
|
||||
|
||||
{/* Filename caption */}
|
||||
<span
|
||||
className={`text-[10px] leading-tight text-center block w-full ${
|
||||
used ? "text-panel-text-2" : "text-panel-text-4"
|
||||
}`}
|
||||
title={fullName}
|
||||
>
|
||||
{truncateMiddle(fullName, 22)}
|
||||
</span>
|
||||
<div className="flex items-center justify-center gap-1">
|
||||
<span
|
||||
className={`text-[10px] leading-tight text-center ${
|
||||
used ? "text-panel-text-2" : "text-panel-text-4"
|
||||
}`}
|
||||
title={fullName}
|
||||
>
|
||||
{truncateMiddle(fullName, 22)}
|
||||
</span>
|
||||
<CopyChip feedback={copyFeedback} asset={asset} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{contextMenu && (
|
||||
@@ -272,7 +308,7 @@ export interface FontRowProps {
|
||||
asset: string;
|
||||
used: boolean;
|
||||
onCopy: (path: string) => void;
|
||||
isCopied: boolean;
|
||||
copyFeedback: CopyFeedback;
|
||||
onDelete?: (path: string) => void;
|
||||
onRename?: (oldPath: string, newPath: string) => void;
|
||||
onAddAssetToTimeline?: (path: string) => void;
|
||||
@@ -285,7 +321,7 @@ export function FontRow({
|
||||
asset,
|
||||
used,
|
||||
onCopy,
|
||||
isCopied,
|
||||
copyFeedback,
|
||||
onDelete,
|
||||
onRename,
|
||||
onAddAssetToTimeline,
|
||||
@@ -293,15 +329,26 @@ export function FontRow({
|
||||
const [contextMenu, setContextMenu] = useState<{ x: number; y: number } | null>(null);
|
||||
const name = basename(asset);
|
||||
const extension = ext(asset);
|
||||
const isCopied = copyFeedback?.path === asset && copyFeedback.ok;
|
||||
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
draggable
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
aria-label={`${name} — copy path, drag to timeline, right-click for actions`}
|
||||
onClick={() => onCopy(asset)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.target !== e.currentTarget) return;
|
||||
if (e.key === "Enter" || e.key === " ") {
|
||||
e.preventDefault();
|
||||
onCopy(asset);
|
||||
}
|
||||
}}
|
||||
onDragStart={(e) => writeAssetDragData(e, asset)}
|
||||
onContextMenu={(e) => openAssetContextMenu(e, setContextMenu)}
|
||||
className={`px-2.5 py-1.5 flex items-center gap-2.5 cursor-pointer transition-colors ${
|
||||
className={`px-2.5 py-1.5 flex items-center gap-2.5 cursor-pointer transition-colors outline-none focus-visible:bg-neutral-800/60 ${
|
||||
isCopied
|
||||
? "bg-studio-accent/10 border-l-2 border-studio-accent"
|
||||
: "border-l-2 border-transparent hover:bg-neutral-800/50"
|
||||
@@ -323,6 +370,7 @@ export function FontRow({
|
||||
in use
|
||||
</span>
|
||||
)}
|
||||
<CopyChip feedback={copyFeedback} asset={asset} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
|
||||
import { filename } from "./assetHelpers";
|
||||
|
||||
/** Reject names that would escape the asset directory or break paths. */
|
||||
function isValidAssetName(name: string): boolean {
|
||||
return name.length > 0 && !/[/\\]/.test(name) && !name.includes("..");
|
||||
}
|
||||
|
||||
// fallow-ignore-next-line complexity
|
||||
export function ContextMenu({
|
||||
x,
|
||||
y,
|
||||
@@ -17,6 +26,77 @@ export function ContextMenu({
|
||||
onRename?: (oldPath: string, newPath: string) => void;
|
||||
onAddAtPlayhead?: (path: string) => void;
|
||||
}) {
|
||||
const menuRef = useRef<HTMLDivElement>(null);
|
||||
const [pos, setPos] = useState({ x, y });
|
||||
const [mode, setMode] = useState<"menu" | "confirm-delete" | "rename">("menu");
|
||||
const [renameDraft, setRenameDraft] = useState(() => filename(asset));
|
||||
const [renameError, setRenameError] = useState<string | null>(null);
|
||||
|
||||
// Clamp the menu inside the viewport once it has a size.
|
||||
useLayoutEffect(() => {
|
||||
const el = menuRef.current;
|
||||
if (!el) return;
|
||||
const rect = el.getBoundingClientRect();
|
||||
const margin = 8;
|
||||
setPos({
|
||||
x: Math.min(x, window.innerWidth - rect.width - margin),
|
||||
y: Math.min(y, window.innerHeight - rect.height - margin),
|
||||
});
|
||||
}, [x, y, mode]);
|
||||
|
||||
// Keyboard contract: Escape backs out one level (rename/delete-confirm →
|
||||
// menu → closed), arrows move between menu items.
|
||||
useEffect(() => {
|
||||
const onKeyDown = (e: KeyboardEvent) => {
|
||||
if (e.key === "Escape") {
|
||||
e.stopPropagation();
|
||||
if (mode !== "menu") {
|
||||
setMode("menu");
|
||||
} else {
|
||||
onClose();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (mode !== "menu" || (e.key !== "ArrowDown" && e.key !== "ArrowUp")) return;
|
||||
const items = Array.from(
|
||||
menuRef.current?.querySelectorAll<HTMLButtonElement>('[role="menuitem"]') ?? [],
|
||||
);
|
||||
if (items.length === 0) return;
|
||||
e.preventDefault();
|
||||
const idx = items.findIndex((el) => el === document.activeElement);
|
||||
const delta = e.key === "ArrowDown" ? 1 : -1;
|
||||
const next = items[(idx + delta + items.length) % items.length];
|
||||
next.focus();
|
||||
};
|
||||
document.addEventListener("keydown", onKeyDown, true);
|
||||
return () => document.removeEventListener("keydown", onKeyDown, true);
|
||||
}, [mode, onClose]);
|
||||
|
||||
// Move focus into the menu on open so arrow keys work immediately.
|
||||
useEffect(() => {
|
||||
if (mode === "menu") {
|
||||
menuRef.current?.querySelector<HTMLButtonElement>('[role="menuitem"]')?.focus();
|
||||
}
|
||||
}, [mode]);
|
||||
|
||||
const commitRename = useCallback(() => {
|
||||
const trimmed = renameDraft.trim();
|
||||
if (trimmed === filename(asset)) {
|
||||
onClose();
|
||||
return;
|
||||
}
|
||||
if (!isValidAssetName(trimmed)) {
|
||||
setRenameError("Name can't contain / or ..");
|
||||
return;
|
||||
}
|
||||
const dir = asset.includes("/") ? asset.slice(0, asset.lastIndexOf("/") + 1) : "";
|
||||
onRename?.(asset, `${dir}${trimmed}`);
|
||||
onClose();
|
||||
}, [renameDraft, asset, onRename, onClose]);
|
||||
|
||||
const itemCls =
|
||||
"w-full text-left px-3 py-1.5 text-neutral-300 hover:bg-neutral-800 focus-visible:bg-neutral-800 outline-none active:bg-neutral-700/70 transition-colors";
|
||||
|
||||
return (
|
||||
<div
|
||||
className="fixed inset-0 z-[200]"
|
||||
@@ -27,56 +107,130 @@ export function ContextMenu({
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className="absolute bg-neutral-900 border border-neutral-700 rounded-lg shadow-xl py-1 min-w-[140px] text-xs"
|
||||
style={{ left: x, top: y }}
|
||||
ref={menuRef}
|
||||
role="menu"
|
||||
aria-label={`Actions for ${filename(asset)}`}
|
||||
className="absolute bg-neutral-900 border border-neutral-700 rounded-lg shadow-xl py-1 min-w-[160px] text-xs"
|
||||
style={{ left: pos.x, top: pos.y }}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{onAddAtPlayhead && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onAddAtPlayhead(asset);
|
||||
onClose();
|
||||
}}
|
||||
className="w-full text-left px-3 py-1.5 text-neutral-300 hover:bg-neutral-800 transition-colors"
|
||||
>
|
||||
Add at playhead
|
||||
</button>
|
||||
{mode === "menu" && (
|
||||
<>
|
||||
{onAddAtPlayhead && (
|
||||
<button
|
||||
role="menuitem"
|
||||
onClick={() => {
|
||||
onAddAtPlayhead(asset);
|
||||
onClose();
|
||||
}}
|
||||
className={itemCls}
|
||||
>
|
||||
Add at playhead
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
role="menuitem"
|
||||
onClick={() => {
|
||||
onCopy(asset);
|
||||
onClose();
|
||||
}}
|
||||
className={itemCls}
|
||||
>
|
||||
Copy path
|
||||
</button>
|
||||
{onRename && (
|
||||
<button role="menuitem" onClick={() => setMode("rename")} className={itemCls}>
|
||||
Rename
|
||||
</button>
|
||||
)}
|
||||
{onDelete && (
|
||||
<button
|
||||
role="menuitem"
|
||||
onClick={() => setMode("confirm-delete")}
|
||||
className={`${itemCls} text-red-400`}
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onCopy(asset);
|
||||
onClose();
|
||||
}}
|
||||
className="w-full text-left px-3 py-1.5 text-neutral-300 hover:bg-neutral-800 transition-colors"
|
||||
>
|
||||
Copy path
|
||||
</button>
|
||||
{onRename && (
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
{mode === "confirm-delete" && (
|
||||
<DeleteConfirm
|
||||
name={filename(asset)}
|
||||
onConfirm={() => {
|
||||
onDelete?.(asset);
|
||||
onClose();
|
||||
}}
|
||||
className="w-full text-left px-3 py-1.5 text-neutral-300 hover:bg-neutral-800 transition-colors"
|
||||
>
|
||||
Rename
|
||||
</button>
|
||||
onCancel={() => setMode("menu")}
|
||||
/>
|
||||
)}
|
||||
{onDelete && (
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onDelete(asset);
|
||||
onClose();
|
||||
}}
|
||||
className="w-full text-left px-3 py-1.5 text-red-400 hover:bg-neutral-800 transition-colors"
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
{mode === "rename" && (
|
||||
<div className="px-2 py-1.5 flex flex-col gap-1">
|
||||
<input
|
||||
autoFocus
|
||||
value={renameDraft}
|
||||
onChange={(e) => {
|
||||
setRenameDraft(e.target.value);
|
||||
setRenameError(null);
|
||||
}}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter") commitRename();
|
||||
if (e.key === "Escape") {
|
||||
e.stopPropagation();
|
||||
setMode("menu");
|
||||
}
|
||||
}}
|
||||
aria-label={`Rename ${filename(asset)}`}
|
||||
className="w-full bg-neutral-800 border border-neutral-600 rounded px-1.5 py-1 text-[11px] text-white focus:border-studio-accent/60 focus:outline-none"
|
||||
/>
|
||||
{renameError && <span className="text-[10px] text-red-400">{renameError}</span>}
|
||||
<div className="flex items-center justify-end gap-1">
|
||||
<button
|
||||
onClick={() => setMode("menu")}
|
||||
className="px-2 py-0.5 text-[10px] rounded text-neutral-400 hover:text-neutral-200 transition-colors"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
onClick={commitRename}
|
||||
className="px-2 py-0.5 text-[10px] rounded bg-studio-accent/80 hover:bg-studio-accent text-white transition-colors"
|
||||
>
|
||||
Rename
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function DeleteConfirm({
|
||||
name,
|
||||
onConfirm,
|
||||
onCancel,
|
||||
}: {
|
||||
name: string;
|
||||
onConfirm: () => void;
|
||||
onCancel: () => void;
|
||||
}) {
|
||||
return (
|
||||
<div className="px-2 py-1.5 bg-red-950/30 border-l-2 border-red-500 flex items-center justify-between gap-2">
|
||||
<span className="text-[10px] text-red-400 truncate">Delete {name}?</span>
|
||||
<div className="flex items-center gap-1 flex-shrink-0">
|
||||
<button
|
||||
onClick={onConfirm}
|
||||
className="px-2 py-0.5 text-[10px] rounded bg-red-600 text-white hover:bg-red-500 active:bg-red-700 transition-colors"
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
<button
|
||||
onClick={onCancel}
|
||||
className="px-2 py-0.5 text-[10px] rounded text-neutral-400 hover:text-neutral-200 transition-colors"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
// fallow-ignore-file code-duplication
|
||||
import { memo, useState, useCallback, useRef, useMemo, useEffect } from "react";
|
||||
import { SearchInput } from "../ui/SearchInput";
|
||||
import { MEDIA_EXT, FONT_EXT } from "../../utils/mediaTypes";
|
||||
import { copyTextToClipboard } from "../../utils/clipboard";
|
||||
import { usePlayerStore } from "../../player/store/playerStore";
|
||||
import { type MediaCategory, getCategory, CATEGORY_LABELS, FILTER_ORDER } from "./assetHelpers";
|
||||
import {
|
||||
type MediaCategory,
|
||||
type CopyFeedback,
|
||||
getCategory,
|
||||
basename,
|
||||
CATEGORY_LABELS,
|
||||
FILTER_ORDER,
|
||||
} from "./assetHelpers";
|
||||
import { AudioRow } from "./AudioRow";
|
||||
import { GlobalAssetsView } from "./GlobalAssetsView";
|
||||
import { AssetCard, FontRow } from "./AssetCard";
|
||||
@@ -11,7 +19,7 @@ import { AssetCard, FontRow } from "./AssetCard";
|
||||
interface AssetsTabProps {
|
||||
projectId: string;
|
||||
assets: string[];
|
||||
onImport?: (files: FileList) => void;
|
||||
onImport?: (files: FileList) => void | Promise<void>;
|
||||
onDelete?: (path: string) => void;
|
||||
onRename?: (oldPath: string, newPath: string) => void;
|
||||
onAddAssetToTimeline?: (path: string) => void;
|
||||
@@ -90,6 +98,99 @@ export function deriveUsedPaths(elements: Array<{ src?: string }>): Set<string>
|
||||
return paths;
|
||||
}
|
||||
|
||||
/** Import trigger. An import is an await, so the button owns the pending state
|
||||
* instead of leaving the author clicking a control that looks idle. */
|
||||
function ImportButton({ importing, onClick }: { importing: boolean; onClick: () => void }) {
|
||||
return (
|
||||
<button
|
||||
onClick={onClick}
|
||||
disabled={importing}
|
||||
aria-busy={importing}
|
||||
className="w-full flex items-center justify-center gap-1.5 rounded-md bg-panel-input px-3 py-[7px] text-[11px] font-medium text-panel-text-3 enabled:hover:text-panel-text-1 enabled:active:scale-[0.98] disabled:opacity-60 transition-colors mb-2.5"
|
||||
>
|
||||
{importing ? (
|
||||
<svg className="animate-spin" width="11" height="11" viewBox="0 0 24 24" fill="none">
|
||||
<circle
|
||||
className="opacity-25"
|
||||
cx="12"
|
||||
cy="12"
|
||||
r="10"
|
||||
stroke="currentColor"
|
||||
strokeWidth="4"
|
||||
/>
|
||||
<path
|
||||
className="opacity-75"
|
||||
fill="currentColor"
|
||||
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"
|
||||
/>
|
||||
</svg>
|
||||
) : (
|
||||
<svg
|
||||
width="11"
|
||||
height="11"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2.5"
|
||||
strokeLinecap="round"
|
||||
>
|
||||
<path d="M12 5v14M5 12h14" />
|
||||
</svg>
|
||||
)}
|
||||
{importing ? "Importing…" : "Import media"}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
/** Empty list body. A query that matched nothing says so and offers a way out;
|
||||
* a genuinely empty project gets the drop hint. */
|
||||
function EmptyState({
|
||||
searchQuery,
|
||||
onClearSearch,
|
||||
}: {
|
||||
searchQuery: string;
|
||||
onClearSearch: () => void;
|
||||
}) {
|
||||
if (searchQuery) {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center h-full px-4 gap-2">
|
||||
<p className="text-[11px] text-neutral-500 text-center">
|
||||
No assets match “{searchQuery}”
|
||||
</p>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClearSearch}
|
||||
className="px-2.5 py-1 text-[11px] font-medium rounded-md bg-panel-input text-panel-text-3 hover:text-panel-text-1 active:scale-[0.98] transition-colors"
|
||||
>
|
||||
Clear search
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center h-full px-4 gap-2">
|
||||
<svg
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
className="text-neutral-700"
|
||||
>
|
||||
<path
|
||||
d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
/>
|
||||
<polyline points="17 8 12 3 7 8" strokeLinecap="round" strokeLinejoin="round" />
|
||||
<line x1="12" y1="3" x2="12" y2="15" strokeLinecap="round" />
|
||||
</svg>
|
||||
<p className="text-[10px] text-neutral-600 text-center">Drop media files here</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export const AssetsTab = memo(function AssetsTab({
|
||||
projectId,
|
||||
assets,
|
||||
@@ -100,7 +201,8 @@ export const AssetsTab = memo(function AssetsTab({
|
||||
}: AssetsTabProps) {
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
const [dragOver, setDragOver] = useState(false);
|
||||
const [copiedPath, setCopiedPath] = useState<string | null>(null);
|
||||
const [copyFeedback, setCopyFeedback] = useState<CopyFeedback>(null);
|
||||
const [importing, setImporting] = useState(false);
|
||||
const [activeFilter, setActiveFilter] = useState<MediaCategory | "all">("all");
|
||||
const [usageFilter, setUsageFilter] = useState<"all" | "used" | "unused">("all");
|
||||
const [searchQuery, setSearchQuery] = useState("");
|
||||
@@ -144,42 +246,55 @@ export const AssetsTab = memo(function AssetsTab({
|
||||
cancelled = true;
|
||||
};
|
||||
}, [projectId, assetsKey]);
|
||||
|
||||
const handleImport = useCallback(
|
||||
async (files: FileList) => {
|
||||
if (!onImport) return;
|
||||
setImporting(true);
|
||||
try {
|
||||
await onImport(files);
|
||||
} finally {
|
||||
setImporting(false);
|
||||
}
|
||||
},
|
||||
[onImport],
|
||||
);
|
||||
|
||||
const handleDrop = useCallback(
|
||||
(e: React.DragEvent) => {
|
||||
e.preventDefault();
|
||||
setDragOver(false);
|
||||
if (e.dataTransfer.files.length) onImport?.(e.dataTransfer.files);
|
||||
if (e.dataTransfer.files.length) void handleImport(e.dataTransfer.files);
|
||||
},
|
||||
[onImport],
|
||||
[handleImport],
|
||||
);
|
||||
|
||||
const handleCopyPath = useCallback(async (path: string) => {
|
||||
const copied = await copyTextToClipboard(path);
|
||||
if (copied) {
|
||||
setCopiedPath(path);
|
||||
setTimeout(() => setCopiedPath(null), 1500);
|
||||
}
|
||||
setCopyFeedback({ path, ok: copied });
|
||||
setTimeout(() => setCopyFeedback(null), copied ? 1500 : 3000);
|
||||
}, []);
|
||||
const elements = usePlayerStore((s) => s.elements);
|
||||
const usedPaths = useMemo(() => deriveUsedPaths(elements), [elements]);
|
||||
|
||||
// Unfiltered pool — header controls (search, chips) are gated on THIS, not
|
||||
// the search-filtered list, so a no-match query can't unmount its own input.
|
||||
const allMediaAssets = useMemo(
|
||||
() => assets.filter((a) => MEDIA_EXT.test(a) || FONT_EXT.test(a)),
|
||||
[assets],
|
||||
);
|
||||
|
||||
const mediaAssets = useMemo(() => {
|
||||
const media = assets.filter((a) => MEDIA_EXT.test(a) || FONT_EXT.test(a));
|
||||
const all = filterByUsage(media, usedPaths, usageFilter);
|
||||
const all = filterByUsage(allMediaAssets, usedPaths, usageFilter);
|
||||
if (!searchQuery) return all;
|
||||
const q = searchQuery.toLowerCase();
|
||||
return all.filter((a) => {
|
||||
if (
|
||||
a
|
||||
.split("/")
|
||||
.pop()
|
||||
?.replace(/\.[^.]*$/, "")
|
||||
.toLowerCase()
|
||||
.includes(q)
|
||||
)
|
||||
return true;
|
||||
if (basename(a).toLowerCase().includes(q)) return true;
|
||||
const rec = manifest.get(a);
|
||||
return rec?.description?.toLowerCase().includes(q);
|
||||
});
|
||||
}, [assets, searchQuery, manifest, usageFilter, usedPaths]);
|
||||
}, [allMediaAssets, searchQuery, manifest, usageFilter, usedPaths]);
|
||||
|
||||
const categorized = useMemo(() => {
|
||||
const groups: Record<MediaCategory, string[]> = { audio: [], images: [], video: [], fonts: [] };
|
||||
for (const a of mediaAssets) {
|
||||
@@ -244,23 +359,7 @@ export const AssetsTab = memo(function AssetsTab({
|
||||
{/* Import */}
|
||||
{onImport && (
|
||||
<>
|
||||
<button
|
||||
onClick={() => fileInputRef.current?.click()}
|
||||
className="w-full flex items-center justify-center gap-1.5 rounded-md bg-panel-input px-3 py-[7px] text-[11px] font-medium text-panel-text-3 hover:text-panel-text-1 transition-colors mb-2.5"
|
||||
>
|
||||
<svg
|
||||
width="11"
|
||||
height="11"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2.5"
|
||||
strokeLinecap="round"
|
||||
>
|
||||
<path d="M12 5v14M5 12h14" />
|
||||
</svg>
|
||||
Import media
|
||||
</button>
|
||||
<ImportButton importing={importing} onClick={() => fileInputRef.current?.click()} />
|
||||
<input
|
||||
ref={fileInputRef}
|
||||
type="file"
|
||||
@@ -269,7 +368,7 @@ export const AssetsTab = memo(function AssetsTab({
|
||||
className="hidden"
|
||||
onChange={(e) => {
|
||||
if (e.target.files?.length) {
|
||||
onImport(e.target.files);
|
||||
void handleImport(e.target.files);
|
||||
e.target.value = "";
|
||||
}
|
||||
}}
|
||||
@@ -277,45 +376,24 @@ export const AssetsTab = memo(function AssetsTab({
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* Search */}
|
||||
{mediaAssets.length > 0 && (
|
||||
<div className="flex items-center gap-1.5 rounded-md bg-panel-input px-2.5 py-[5px] mb-2">
|
||||
<svg width="12" height="12" viewBox="0 0 256 256" fill="none" className="flex-shrink-0">
|
||||
<circle
|
||||
cx="116"
|
||||
cy="116"
|
||||
r="76"
|
||||
stroke="currentColor"
|
||||
strokeWidth="22"
|
||||
className="text-panel-text-5"
|
||||
/>
|
||||
<line
|
||||
x1="170"
|
||||
y1="170"
|
||||
x2="232"
|
||||
y2="232"
|
||||
stroke="currentColor"
|
||||
strokeWidth="22"
|
||||
strokeLinecap="round"
|
||||
className="text-panel-text-5"
|
||||
/>
|
||||
</svg>
|
||||
<input
|
||||
type="text"
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
placeholder="Search assets..."
|
||||
className="min-w-0 w-full bg-transparent text-[11px] text-panel-text-1 outline-none placeholder:text-panel-text-5"
|
||||
/>
|
||||
</div>
|
||||
{/* Search — gated on the UNFILTERED pool so it never unmounts itself */}
|
||||
{allMediaAssets.length > 0 && (
|
||||
<SearchInput
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
placeholder="Search assets..."
|
||||
aria-label="Search assets"
|
||||
className="mb-2"
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Filter chips */}
|
||||
{viewMode === "local" && mediaAssets.length > 0 && (
|
||||
{viewMode === "local" && allMediaAssets.length > 0 && (
|
||||
<div className="flex gap-1.5 flex-wrap">
|
||||
<button
|
||||
onClick={() => setActiveFilter("all")}
|
||||
className={`px-2.5 py-1 text-[11px] font-medium rounded-md transition-colors ${
|
||||
aria-pressed={activeFilter === "all"}
|
||||
className={`px-2.5 py-1 text-[11px] font-medium rounded-md transition-colors active:scale-[0.98] ${
|
||||
activeFilter === "all"
|
||||
? "bg-panel-accent/15 text-panel-accent"
|
||||
: "bg-panel-input text-panel-text-3 hover:text-panel-text-1"
|
||||
@@ -328,7 +406,8 @@ export const AssetsTab = memo(function AssetsTab({
|
||||
<button
|
||||
key={cat}
|
||||
onClick={() => setActiveFilter(activeFilter === cat ? "all" : cat)}
|
||||
className={`px-2.5 py-1 text-[11px] font-medium rounded-md transition-colors ${
|
||||
aria-pressed={activeFilter === cat}
|
||||
className={`px-2.5 py-1 text-[11px] font-medium rounded-md transition-colors active:scale-[0.98] ${
|
||||
activeFilter === cat
|
||||
? "bg-panel-accent/15 text-panel-accent"
|
||||
: "bg-panel-input text-panel-text-3 hover:text-panel-text-1"
|
||||
@@ -371,26 +450,7 @@ export const AssetsTab = memo(function AssetsTab({
|
||||
{viewMode === "global" ? (
|
||||
<GlobalAssetsView searchQuery={searchQuery} />
|
||||
) : mediaAssets.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center h-full px-4 gap-2">
|
||||
<svg
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
className="text-neutral-700"
|
||||
>
|
||||
<path
|
||||
d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
/>
|
||||
<polyline points="17 8 12 3 7 8" strokeLinecap="round" strokeLinejoin="round" />
|
||||
<line x1="12" y1="3" x2="12" y2="15" strokeLinecap="round" />
|
||||
</svg>
|
||||
<p className="text-[10px] text-neutral-600 text-center">Drop media files here</p>
|
||||
</div>
|
||||
<EmptyState searchQuery={searchQuery} onClearSearch={() => setSearchQuery("")} />
|
||||
) : (
|
||||
visibleCategories.map((cat) => (
|
||||
<div key={cat} className="mb-1">
|
||||
@@ -411,7 +471,7 @@ export const AssetsTab = memo(function AssetsTab({
|
||||
used={usedPaths.has(a)}
|
||||
meta={manifest.get(a)}
|
||||
onCopy={handleCopyPath}
|
||||
isCopied={copiedPath === a}
|
||||
copyFeedback={copyFeedback}
|
||||
onDelete={onDelete}
|
||||
onRename={onRename}
|
||||
onAddAssetToTimeline={onAddAssetToTimeline}
|
||||
@@ -427,7 +487,7 @@ export const AssetsTab = memo(function AssetsTab({
|
||||
used={usedPaths.has(a)}
|
||||
duration={manifest.get(a)?.duration}
|
||||
onCopy={handleCopyPath}
|
||||
isCopied={copiedPath === a}
|
||||
copyFeedback={copyFeedback}
|
||||
onDelete={onDelete}
|
||||
onRename={onRename}
|
||||
onAddAssetToTimeline={onAddAssetToTimeline}
|
||||
@@ -442,7 +502,7 @@ export const AssetsTab = memo(function AssetsTab({
|
||||
asset={a}
|
||||
used={usedPaths.has(a)}
|
||||
onCopy={handleCopyPath}
|
||||
isCopied={copiedPath === a}
|
||||
copyFeedback={copyFeedback}
|
||||
onDelete={onDelete}
|
||||
onRename={onRename}
|
||||
onAddAssetToTimeline={onAddAssetToTimeline}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useState, useRef, useEffect, useCallback } from "react";
|
||||
import { ContextMenu } from "./AssetContextMenu";
|
||||
import { basename, getAudioSubtype } from "./assetHelpers";
|
||||
import { basename, getAudioSubtype, type CopyFeedback } from "./assetHelpers";
|
||||
import { TIMELINE_ASSET_MIME } from "../../utils/timelineAssetDrop";
|
||||
import { usePlayerStore } from "../../player/store/playerStore";
|
||||
import { useAssetPreviewStore } from "../../utils/assetPreviewStore";
|
||||
@@ -8,13 +8,16 @@ import { findClipForAsset, isPointerClick } from "../../utils/assetClickBehavior
|
||||
import { resolveMediaPreviewUrl } from "../../player/components/thumbnailUtils";
|
||||
import { timelineClipFocusId } from "../../player/components/timelineNavigationIdentity";
|
||||
|
||||
// Only one preview should play at a time; starting a row stops the previous one.
|
||||
let stopCurrentPreview: (() => void) | null = null;
|
||||
|
||||
export function AudioRow({
|
||||
projectId,
|
||||
asset,
|
||||
used,
|
||||
meta,
|
||||
onCopy,
|
||||
isCopied,
|
||||
copyFeedback,
|
||||
onDelete,
|
||||
onRename,
|
||||
onAddAssetToTimeline,
|
||||
@@ -24,7 +27,7 @@ export function AudioRow({
|
||||
used: boolean;
|
||||
meta?: { description?: string; duration?: number };
|
||||
onCopy: (path: string) => void;
|
||||
isCopied: boolean;
|
||||
copyFeedback: CopyFeedback;
|
||||
onDelete?: (path: string) => void;
|
||||
onRename?: (oldPath: string, newPath: string) => void;
|
||||
onAddAssetToTimeline?: (path: string) => void;
|
||||
@@ -40,6 +43,14 @@ export function AudioRow({
|
||||
const name = basename(asset);
|
||||
const subtype = getAudioSubtype(asset);
|
||||
const serveUrl = resolveMediaPreviewUrl(asset, projectId);
|
||||
const isCopied = copyFeedback?.path === asset && copyFeedback.ok;
|
||||
const copyFailed = copyFeedback?.path === asset && !copyFeedback.ok;
|
||||
|
||||
const stopPlayback = useCallback(() => {
|
||||
audioRef.current?.pause();
|
||||
setPlaying(false);
|
||||
cancelAnimationFrame(animRef.current);
|
||||
}, []);
|
||||
|
||||
// CapCut-style click behavior: drag-threshold gate.
|
||||
const pointerDownRef = useRef<{ x: number; y: number } | null>(null);
|
||||
@@ -49,6 +60,36 @@ export function AudioRow({
|
||||
const setPreviewAsset = useAssetPreviewStore((s) => s.setPreviewAsset);
|
||||
const clearPreviewAsset = useAssetPreviewStore((s) => s.clearPreviewAsset);
|
||||
|
||||
// Reveal the clip when the asset is already on the timeline, otherwise open
|
||||
// the preview overlay. Shared by pointer-up and keyboard activation so the
|
||||
// row does the same thing however it is operated.
|
||||
const activateRow = useCallback(() => {
|
||||
if (used) {
|
||||
const clip = findClipForAsset(elements, asset);
|
||||
if (clip) {
|
||||
// Dismiss any open preview overlay (from another asset) — the reveal
|
||||
// must not leave a stale preview card floating over the canvas.
|
||||
clearPreviewAsset();
|
||||
const clipKey = clip.key ?? clip.id;
|
||||
setSelectedElementId(clipKey);
|
||||
// Scroll the timeline so the selected clip is actually visible.
|
||||
requestTimelineFocus(timelineClipFocusId(clipKey));
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Not added → preview overlay (audio player)
|
||||
setPreviewAsset(asset, projectId);
|
||||
}, [
|
||||
used,
|
||||
elements,
|
||||
asset,
|
||||
projectId,
|
||||
setSelectedElementId,
|
||||
requestTimelineFocus,
|
||||
setPreviewAsset,
|
||||
clearPreviewAsset,
|
||||
]);
|
||||
|
||||
const handlePointerDown = useCallback((e: React.PointerEvent) => {
|
||||
pointerDownRef.current = { x: e.clientX, y: e.clientY };
|
||||
}, []);
|
||||
@@ -59,32 +100,9 @@ export function AudioRow({
|
||||
pointerDownRef.current = null;
|
||||
if (!origin) return;
|
||||
if (!isPointerClick(e.clientX - origin.x, e.clientY - origin.y)) return;
|
||||
if (used) {
|
||||
const clip = findClipForAsset(elements, asset);
|
||||
if (clip) {
|
||||
// Dismiss any open preview overlay (from another asset) — the reveal
|
||||
// must not leave a stale preview card floating over the canvas.
|
||||
clearPreviewAsset();
|
||||
const clipKey = clip.key ?? clip.id;
|
||||
setSelectedElementId(clipKey);
|
||||
// Scroll the timeline so the selected clip is actually visible.
|
||||
requestTimelineFocus(timelineClipFocusId(clipKey));
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Not added → preview overlay (audio player)
|
||||
setPreviewAsset(asset, projectId);
|
||||
activateRow();
|
||||
},
|
||||
[
|
||||
used,
|
||||
elements,
|
||||
asset,
|
||||
projectId,
|
||||
setSelectedElementId,
|
||||
requestTimelineFocus,
|
||||
setPreviewAsset,
|
||||
clearPreviewAsset,
|
||||
],
|
||||
[activateRow],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -92,8 +110,9 @@ export function AudioRow({
|
||||
cancelAnimationFrame(animRef.current);
|
||||
audioRef.current?.pause();
|
||||
actxRef.current?.close();
|
||||
if (stopCurrentPreview === stopPlayback) stopCurrentPreview = null;
|
||||
};
|
||||
}, []);
|
||||
}, [stopPlayback]);
|
||||
|
||||
useEffect(() => {
|
||||
if (playing) {
|
||||
@@ -126,12 +145,15 @@ export function AudioRow({
|
||||
|
||||
const togglePlay = useCallback(async () => {
|
||||
if (playing) {
|
||||
audioRef.current?.pause();
|
||||
setPlaying(false);
|
||||
cancelAnimationFrame(animRef.current);
|
||||
stopPlayback();
|
||||
if (stopCurrentPreview === stopPlayback) stopCurrentPreview = null;
|
||||
return;
|
||||
}
|
||||
|
||||
// Stop whichever other row is currently previewing.
|
||||
if (stopCurrentPreview && stopCurrentPreview !== stopPlayback) stopCurrentPreview();
|
||||
stopCurrentPreview = stopPlayback;
|
||||
|
||||
if (!actxRef.current) {
|
||||
actxRef.current = new AudioContext();
|
||||
analyserRef.current = actxRef.current.createAnalyser();
|
||||
@@ -146,17 +168,26 @@ export function AudioRow({
|
||||
cancelAnimationFrame(animRef.current);
|
||||
};
|
||||
audioRef.current = el;
|
||||
sourceRef.current = actxRef.current.createMediaElementSource(el);
|
||||
sourceRef.current.connect(analyserRef.current!);
|
||||
analyserRef.current!.connect(actxRef.current.destination);
|
||||
const analyser = analyserRef.current;
|
||||
if (analyser) {
|
||||
sourceRef.current = actxRef.current.createMediaElementSource(el);
|
||||
sourceRef.current.connect(analyser);
|
||||
analyser.connect(actxRef.current.destination);
|
||||
}
|
||||
el.src = serveUrl;
|
||||
}
|
||||
|
||||
if (actxRef.current.state === "suspended") await actxRef.current.resume();
|
||||
audioRef.current.currentTime = 0;
|
||||
await audioRef.current.play();
|
||||
setPlaying(true);
|
||||
}, [serveUrl, playing]);
|
||||
try {
|
||||
await audioRef.current.play();
|
||||
setPlaying(true);
|
||||
} catch {
|
||||
// Playback refused (e.g. decode failure) — reset instead of a stuck state.
|
||||
setPlaying(false);
|
||||
if (stopCurrentPreview === stopPlayback) stopCurrentPreview = null;
|
||||
}
|
||||
}, [serveUrl, playing, stopPlayback]);
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -164,6 +195,18 @@ export function AudioRow({
|
||||
draggable
|
||||
onPointerDown={handlePointerDown}
|
||||
onPointerUp={handlePointerUp}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
aria-label={`${name} — open, drag to timeline, right-click for actions`}
|
||||
onKeyDown={(e) => {
|
||||
// Only when the row itself is focused — keydowns bubbling from the
|
||||
// inner controls (play button) must keep their native activation.
|
||||
if (e.target !== e.currentTarget) return;
|
||||
if (e.key === "Enter" || e.key === " ") {
|
||||
e.preventDefault();
|
||||
activateRow();
|
||||
}
|
||||
}}
|
||||
onDragStart={(e) => {
|
||||
e.dataTransfer.effectAllowed = "copy";
|
||||
e.dataTransfer.setData(TIMELINE_ASSET_MIME, JSON.stringify({ path: asset }));
|
||||
@@ -173,7 +216,7 @@ export function AudioRow({
|
||||
e.preventDefault();
|
||||
setContextMenu({ x: e.clientX, y: e.clientY });
|
||||
}}
|
||||
className={`group w-full text-left px-4 py-1.5 flex items-center gap-2.5 transition-all cursor-pointer ${
|
||||
className={`group w-full text-left px-4 py-1.5 flex items-center gap-2.5 transition-colors cursor-pointer outline-none focus-visible:bg-neutral-800/60 ${
|
||||
playing
|
||||
? "bg-panel-accent/[0.06]"
|
||||
: isCopied
|
||||
@@ -182,7 +225,9 @@ export function AudioRow({
|
||||
}`}
|
||||
>
|
||||
<button
|
||||
className={`w-7 h-7 rounded-md flex-shrink-0 flex items-center justify-center transition-all ${
|
||||
aria-label={playing ? `Pause preview of ${name}` : `Play preview of ${name}`}
|
||||
aria-pressed={playing}
|
||||
className={`w-7 h-7 rounded-md flex-shrink-0 flex items-center justify-center transition-colors active:scale-[0.95] ${
|
||||
playing
|
||||
? "bg-panel-accent/15 text-panel-accent"
|
||||
: "text-panel-text-5 group-hover:text-panel-text-3"
|
||||
@@ -221,6 +266,16 @@ export function AudioRow({
|
||||
in use
|
||||
</span>
|
||||
)}
|
||||
{(isCopied || copyFailed) && (
|
||||
<span
|
||||
role="status"
|
||||
className={`flex-shrink-0 text-[9px] font-medium px-1.5 py-px rounded ${
|
||||
copyFailed ? "text-red-400 bg-red-500/10" : "text-panel-accent bg-panel-accent/10"
|
||||
}`}
|
||||
>
|
||||
{copyFailed ? "Copy failed" : "Copied"}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{bars.length > 0 && (
|
||||
<div className="flex items-end gap-[2px] h-[14px] mt-0.5">
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// fallow-ignore-file code-duplication
|
||||
import { memo, useState, useCallback, useRef, useEffect } from "react";
|
||||
import { createPortal } from "react-dom";
|
||||
import { SearchInput } from "../ui/SearchInput";
|
||||
import { PromptPreviewModal } from "./PromptPreviewModal";
|
||||
import { useBlockCatalog } from "../../hooks/useBlockCatalog";
|
||||
import {
|
||||
BLOCK_CATEGORIES,
|
||||
@@ -18,7 +20,7 @@ export interface BlockPreviewInfo {
|
||||
}
|
||||
|
||||
interface BlocksTabProps {
|
||||
onAddBlock?: (blockName: string) => void;
|
||||
onAddBlock?: (blockName: string) => void | Promise<void>;
|
||||
onPreviewBlock?: (preview: BlockPreviewInfo | null) => void;
|
||||
}
|
||||
|
||||
@@ -48,29 +50,12 @@ export const BlocksTab = memo(function BlocksTab({ onAddBlock, onPreviewBlock }:
|
||||
<div className="flex flex-col flex-1 min-h-0">
|
||||
{/* Search */}
|
||||
<div className="px-3 pt-2 pb-1 flex-shrink-0">
|
||||
<div className="relative">
|
||||
<svg
|
||||
className="absolute left-2 top-1/2 -translate-y-1/2 text-neutral-500"
|
||||
width="12"
|
||||
height="12"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<circle cx="11" cy="11" r="8" />
|
||||
<path d="m21 21-4.35-4.35" />
|
||||
</svg>
|
||||
<input
|
||||
type="text"
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
placeholder="Search by name, category, or tag…"
|
||||
className="w-full bg-neutral-900 border border-neutral-800 rounded-md pl-7 pr-2 py-1.5 text-[11px] text-neutral-200 placeholder:text-neutral-600 focus:outline-none focus:border-neutral-700 transition-colors"
|
||||
/>
|
||||
</div>
|
||||
<SearchInput
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
placeholder="Search by name, category, or tag…"
|
||||
aria-label="Search blocks"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Category pills */}
|
||||
@@ -165,7 +150,8 @@ function CategoryPill({
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClick}
|
||||
className={`flex-shrink-0 px-2 py-1 rounded-full text-[10px] font-medium transition-colors ${
|
||||
aria-pressed={active}
|
||||
className={`flex-shrink-0 px-2 py-1 rounded-full text-[10px] font-medium transition-colors active:scale-[0.98] ${
|
||||
active
|
||||
? colors
|
||||
? `${colors.bg} ${colors.text}`
|
||||
@@ -304,12 +290,12 @@ function BlockCard({
|
||||
tags?: string[];
|
||||
posterUrl?: string;
|
||||
videoUrl?: string;
|
||||
onAdd?: () => void;
|
||||
onAdd?: () => void | Promise<void>;
|
||||
onShowPrompt?: (info: { title: string; prompt: string }) => void;
|
||||
onPreview?: (preview: BlockPreviewInfo | null) => void;
|
||||
}) {
|
||||
const [hovered, setHovered] = useState(false);
|
||||
const [adding, setAdding] = useState(false);
|
||||
const [addState, setAddState] = useState<"idle" | "adding" | "added" | "failed">("idle");
|
||||
const hoverTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
const colors = getCategoryColors(category);
|
||||
const needsWebGL = tags?.includes("html-in-canvas") || tags?.includes("webgl");
|
||||
@@ -337,14 +323,20 @@ function BlockCard({
|
||||
}, []);
|
||||
|
||||
const handleAdd = useCallback(
|
||||
(e: React.MouseEvent) => {
|
||||
async (e: React.MouseEvent) => {
|
||||
e.stopPropagation();
|
||||
if (adding || !onAdd) return;
|
||||
setAdding(true);
|
||||
onAdd();
|
||||
setTimeout(() => setAdding(false), 1000);
|
||||
if (addState !== "idle" || !onAdd) return;
|
||||
setAddState("adding");
|
||||
try {
|
||||
// Confirm only what actually happened — no optimistic "Added!".
|
||||
await onAdd();
|
||||
setAddState("added");
|
||||
} catch {
|
||||
setAddState("failed");
|
||||
}
|
||||
setTimeout(() => setAddState("idle"), 1500);
|
||||
},
|
||||
[onAdd, adding],
|
||||
[onAdd, addState],
|
||||
);
|
||||
|
||||
const { activeCompPath, compositionDimensions } = useStudioShellContext();
|
||||
@@ -422,14 +414,18 @@ function BlockCard({
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Action overlay */}
|
||||
<div className="absolute inset-0 flex flex-col items-center justify-center gap-1.5 bg-black/60 opacity-0 group-hover/card:opacity-100 transition-opacity">
|
||||
{/* Action overlay — also revealed when a button inside receives focus */}
|
||||
<div className="absolute inset-0 flex flex-col items-center justify-center gap-1.5 bg-black/60 opacity-0 group-hover/card:opacity-100 group-focus-within/card:opacity-100 transition-opacity">
|
||||
{onAdd && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleAdd}
|
||||
title="Add to composition at current time"
|
||||
className="flex items-center gap-1 px-3 py-1.5 rounded-md bg-white text-black text-[10px] font-semibold hover:bg-neutral-200 transition-colors"
|
||||
className={`flex items-center gap-1 px-3 py-1.5 rounded-md text-[10px] font-semibold transition-colors active:scale-[0.97] ${
|
||||
addState === "failed"
|
||||
? "bg-red-500 text-white"
|
||||
: "bg-white text-black hover:bg-neutral-200"
|
||||
}`}
|
||||
>
|
||||
<svg
|
||||
width="10"
|
||||
@@ -441,14 +437,20 @@ function BlockCard({
|
||||
>
|
||||
<path d="M12 5v14M5 12h14" />
|
||||
</svg>
|
||||
{adding ? "Added!" : "Add"}
|
||||
{addState === "adding"
|
||||
? "Adding…"
|
||||
: addState === "added"
|
||||
? "Added!"
|
||||
: addState === "failed"
|
||||
? "Failed"
|
||||
: "Add"}
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleShowPrompt}
|
||||
title="Generate a prompt to paste into your AI agent"
|
||||
className={`flex items-center gap-1.5 px-3 ${onAdd ? "py-1" : "py-1.5"} rounded-md transition-colors ${
|
||||
className={`flex items-center gap-1.5 px-3 ${onAdd ? "py-1" : "py-1.5"} rounded-md transition-colors active:scale-[0.97] ${
|
||||
onAdd
|
||||
? "bg-white/15 text-white/90 hover:bg-white/25 text-[9px]"
|
||||
: "bg-white text-black hover:bg-neutral-200 text-[10px] font-semibold"
|
||||
@@ -499,93 +501,3 @@ function BlockCard({
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function PromptPreviewModal({
|
||||
title,
|
||||
prompt,
|
||||
onClose,
|
||||
}: {
|
||||
title: string;
|
||||
prompt: string;
|
||||
onClose: () => void;
|
||||
}) {
|
||||
const [value, setValue] = useState(prompt);
|
||||
const [copied, setCopied] = useState(false);
|
||||
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
requestAnimationFrame(() => textareaRef.current?.focus());
|
||||
}, []);
|
||||
|
||||
const handleCopy = useCallback(() => {
|
||||
navigator.clipboard.writeText(value);
|
||||
setCopied(true);
|
||||
setTimeout(() => setCopied(false), 1500);
|
||||
}, [value]);
|
||||
|
||||
return (
|
||||
<div
|
||||
className="fixed inset-0 z-[100] flex items-center justify-center bg-black/60 backdrop-blur-sm"
|
||||
onClick={onClose}
|
||||
>
|
||||
<div
|
||||
className="w-[560px] max-h-[80vh] flex flex-col rounded-2xl border border-neutral-800 bg-neutral-950 shadow-2xl"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<div className="flex items-center justify-between px-5 py-4 border-b border-neutral-800/60">
|
||||
<div>
|
||||
<h3 className="text-sm font-medium text-neutral-200">Ask agent</h3>
|
||||
<p className="text-xs text-neutral-500 mt-0.5">{title}</p>
|
||||
</div>
|
||||
<button
|
||||
className="p-1 rounded-md text-neutral-500 hover:text-neutral-300 hover:bg-neutral-800/50"
|
||||
onClick={onClose}
|
||||
>
|
||||
<svg
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
>
|
||||
<line x1="18" y1="6" x2="6" y2="18" />
|
||||
<line x1="6" y1="6" x2="18" y2="18" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
<div className="flex-1 overflow-y-auto px-5 py-4">
|
||||
<p className="text-[11px] text-neutral-500 mb-2">
|
||||
Edit the prompt below, then copy and paste into your AI agent
|
||||
</p>
|
||||
<textarea
|
||||
ref={textareaRef}
|
||||
value={value}
|
||||
onChange={(e) => setValue(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) handleCopy();
|
||||
if (e.key === "Escape") onClose();
|
||||
}}
|
||||
className="w-full min-h-[240px] text-[11px] text-neutral-200 leading-relaxed font-mono bg-neutral-900/60 rounded-lg p-3 border border-neutral-800 resize-y focus:outline-none focus:border-studio-accent/60 focus:ring-1 focus:ring-studio-accent/30"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-center justify-between px-5 py-3 border-t border-neutral-800/60">
|
||||
<span className="text-[11px] text-neutral-600">
|
||||
{navigator.platform.includes("Mac") ? "⌘" : "Ctrl"}+Enter to copy
|
||||
</span>
|
||||
<button
|
||||
className={`px-4 py-1.5 rounded-lg text-xs font-medium transition-colors ${
|
||||
copied
|
||||
? "bg-emerald-500 text-white"
|
||||
: "bg-studio-accent/90 text-neutral-950 hover:bg-studio-accent"
|
||||
}`}
|
||||
onClick={handleCopy}
|
||||
>
|
||||
{copied ? "Copied!" : "Copy prompt"}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { memo, useCallback, useEffect, useRef, useState } from "react";
|
||||
import { setPreviewMediaMuted } from "../../player/lib/timelineIframeHelpers";
|
||||
import { buildCompositionThumbnailUrl } from "../../player/components/CompositionThumbnail";
|
||||
import { TIMELINE_COMPOSITION_MIME } from "../../utils/timelineCompositionDrop";
|
||||
import { Tooltip } from "../ui/Tooltip";
|
||||
|
||||
interface CompositionsTabProps {
|
||||
projectId: string;
|
||||
@@ -201,6 +202,8 @@ function CompCard({
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
draggable
|
||||
aria-label={`Open composition ${name}`}
|
||||
aria-pressed={isActive}
|
||||
onDragStart={(event) => {
|
||||
draggedRef.current = true;
|
||||
event.dataTransfer.effectAllowed = "copy";
|
||||
@@ -215,6 +218,8 @@ function CompCard({
|
||||
if (!draggedRef.current) onSelect();
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
// Only when the row itself is focused — keydowns bubbling from the
|
||||
// inner controls (play button) must keep their native activation.
|
||||
if (event.target !== event.currentTarget) return;
|
||||
if (event.key === "Enter" || event.key === " ") {
|
||||
event.preventDefault();
|
||||
@@ -223,7 +228,7 @@ function CompCard({
|
||||
}}
|
||||
onPointerEnter={handleEnter}
|
||||
onPointerLeave={handleLeave}
|
||||
className={`group/card w-full select-none text-left px-2 py-1.5 flex items-center gap-2.5 transition-colors cursor-grab active:cursor-grabbing ${
|
||||
className={`group/card w-full select-none text-left px-2 py-1.5 flex items-center gap-2.5 transition-colors cursor-grab active:cursor-grabbing outline-none focus-visible:bg-neutral-800/60 ${
|
||||
isActive
|
||||
? "bg-studio-accent/10 border-l-2 border-studio-accent"
|
||||
: "border-l-2 border-transparent hover:bg-neutral-800/50"
|
||||
@@ -288,7 +293,12 @@ function CompCard({
|
||||
<div className="flex items-center gap-1">
|
||||
<span className="text-[11px] font-medium text-neutral-300 truncate">{name}</span>
|
||||
{lintInfo && lintInfo.count > 0 && (
|
||||
<span className="flex-shrink-0 w-2 h-2 rounded-full bg-amber-400" />
|
||||
<span
|
||||
aria-label={`${lintInfo.count} lint finding${lintInfo.count === 1 ? "" : "s"}`}
|
||||
className="flex-shrink-0 min-w-[16px] text-center rounded-full bg-amber-500/20 px-1 text-[8px] font-bold text-amber-400"
|
||||
>
|
||||
{lintInfo.count}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<span className="text-[9px] text-neutral-600 truncate block">{comp}</span>
|
||||
@@ -308,39 +318,41 @@ function CompCard({
|
||||
</button>
|
||||
)}
|
||||
{onRender && (
|
||||
<button
|
||||
type="button"
|
||||
title={isRendering ? "Rendering..." : `Render ${name}`}
|
||||
aria-label={isRendering ? "Rendering..." : `Render ${name}`}
|
||||
disabled={isRendering}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onRender();
|
||||
}}
|
||||
// h-6 w-6 = the 24x24 WCAG 2.2 (2.5.8) minimum target; the 14px glyph
|
||||
// is unchanged, only the box grows. The sibling "+" button is h-8 w-8,
|
||||
// so the card row already has the room.
|
||||
className={`flex h-6 w-6 flex-shrink-0 items-center justify-center rounded transition-colors ${
|
||||
isRendering
|
||||
? "text-neutral-600 cursor-not-allowed"
|
||||
: "text-neutral-600 hover:text-studio-accent hover:bg-neutral-800"
|
||||
}`}
|
||||
>
|
||||
<svg
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
<Tooltip label={isRendering ? "A render is already in progress" : `Render ${name}`}>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={isRendering ? "A render is already in progress" : `Render ${name}`}
|
||||
disabled={isRendering}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onRender();
|
||||
}}
|
||||
// h-6 w-6 = the 24x24 WCAG 2.2 (2.5.8) minimum target; the 14px glyph
|
||||
// is unchanged, only the box grows. The sibling "+" button is h-8 w-8,
|
||||
// so the card row already has the room.
|
||||
className={`flex h-6 w-6 flex-shrink-0 items-center justify-center rounded transition-colors ${
|
||||
isRendering
|
||||
? "text-neutral-600 cursor-not-allowed"
|
||||
: "text-neutral-600 hover:text-studio-accent hover:bg-neutral-800"
|
||||
}`}
|
||||
>
|
||||
<path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4" />
|
||||
<polyline points="7 10 12 15 17 10" />
|
||||
<line x1="12" y1="15" x2="12" y2="3" />
|
||||
</svg>
|
||||
</button>
|
||||
<svg
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4" />
|
||||
<polyline points="7 10 12 15 17 10" />
|
||||
<line x1="12" y1="15" x2="12" y2="3" />
|
||||
</svg>
|
||||
</button>
|
||||
</Tooltip>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -24,6 +24,13 @@ export interface LeftSidebarHandle {
|
||||
|
||||
const STORAGE_KEY = "hf-studio-sidebar-tab";
|
||||
|
||||
const SIDEBAR_TABS: Array<{ id: SidebarTab; label: string; tooltip: string }> = [
|
||||
{ id: "code", label: "Code", tooltip: "Source code editor" },
|
||||
{ id: "compositions", label: "Comps", tooltip: "Compositions and sub-compositions" },
|
||||
{ id: "assets", label: "Assets", tooltip: "Videos, images, audio, fonts" },
|
||||
{ id: "blocks", label: "Catalog", tooltip: "Browse blocks and components" },
|
||||
];
|
||||
|
||||
// Both the `localStorage` reference and `getItem` itself can throw when the
|
||||
// browsing context is partitioned or site data is blocked — the same case
|
||||
// telemetry/config.ts documents. This runs as a `useState` initializer, so an
|
||||
@@ -49,7 +56,7 @@ interface LeftSidebarProps {
|
||||
assets: string[];
|
||||
activeComposition: string | null;
|
||||
onSelectComposition: (comp: string) => void;
|
||||
onImportFiles?: (files: FileList, dir?: string) => void;
|
||||
onImportFiles?: (files: FileList, dir?: string) => void | Promise<void>;
|
||||
fileTree?: string[];
|
||||
editingFile?: { path: string; content: string | null } | null;
|
||||
onSelectFile?: (path: string) => void;
|
||||
@@ -67,7 +74,7 @@ interface LeftSidebarProps {
|
||||
lintFindingCount?: number;
|
||||
lintFindingsByFile?: Map<string, { count: number; messages: string[] }>;
|
||||
onToggleCollapse?: () => void;
|
||||
onAddBlock?: (blockName: string) => void;
|
||||
onAddBlock?: (blockName: string) => void | Promise<void>;
|
||||
onPreviewBlock?: (preview: BlockPreviewInfo | null) => void;
|
||||
takeoverContent?: ReactNode;
|
||||
onAddAssetToTimeline?: (path: string) => void;
|
||||
@@ -112,6 +119,7 @@ export const LeftSidebar = memo(
|
||||
const [tab, setTab] = useState<SidebarTab>(getPersistedTab);
|
||||
const tabRef = useRef(tab);
|
||||
tabRef.current = tab;
|
||||
const tablistRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const selectTab = useCallback((t: SidebarTab) => {
|
||||
setTab(t);
|
||||
@@ -127,6 +135,20 @@ export const LeftSidebar = memo(
|
||||
|
||||
useImperativeHandle(ref, () => ({ selectTab, getTab }), [selectTab, getTab]);
|
||||
|
||||
// APG tabs pattern: Left/Right move focus AND selection between tabs.
|
||||
const handleTablistKeyDown = useCallback(
|
||||
(e: React.KeyboardEvent) => {
|
||||
if (e.key !== "ArrowLeft" && e.key !== "ArrowRight") return;
|
||||
e.preventDefault();
|
||||
const ids = SIDEBAR_TABS.map((t) => t.id);
|
||||
const idx = ids.indexOf(tabRef.current);
|
||||
const next = ids[(idx + (e.key === "ArrowRight" ? 1 : -1) + ids.length) % ids.length];
|
||||
selectTab(next);
|
||||
tablistRef.current?.querySelector<HTMLButtonElement>(`[data-tab-id="${next}"]`)?.focus();
|
||||
},
|
||||
[selectTab],
|
||||
);
|
||||
|
||||
return (
|
||||
<div
|
||||
className="flex flex-col h-full overflow-hidden rounded-lg border border-neutral-800/50 bg-neutral-950"
|
||||
@@ -140,61 +162,33 @@ export const LeftSidebar = memo(
|
||||
<div className="border-b border-neutral-800/50 px-3 py-3 flex-shrink-0">
|
||||
<div className="flex items-center gap-2">
|
||||
<div
|
||||
ref={tablistRef}
|
||||
role="tablist"
|
||||
aria-label="Sidebar panels"
|
||||
onKeyDown={handleTablistKeyDown}
|
||||
className="grid min-w-0 flex-1 gap-0.5 rounded-[18px] bg-neutral-900 p-1 shadow-[inset_0_1px_0_rgba(255,255,255,0.03)]"
|
||||
style={{ gridTemplateColumns: "1fr 1fr 1fr 1fr" }}
|
||||
>
|
||||
<Tooltip label="Source code editor" side="bottom">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => selectTab("code")}
|
||||
className={`rounded-[14px] px-1.5 py-2 text-[10px] font-semibold truncate transition-all ${
|
||||
tab === "code"
|
||||
? "bg-neutral-800 text-white"
|
||||
: "text-neutral-500 hover:text-neutral-200"
|
||||
}`}
|
||||
>
|
||||
Code
|
||||
</button>
|
||||
</Tooltip>
|
||||
<Tooltip label="Compositions and sub-compositions" side="bottom">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => selectTab("compositions")}
|
||||
className={`rounded-[14px] px-1.5 py-2 text-[10px] font-semibold truncate transition-all ${
|
||||
tab === "compositions"
|
||||
? "bg-neutral-800 text-white"
|
||||
: "text-neutral-500 hover:text-neutral-200"
|
||||
}`}
|
||||
>
|
||||
Comps
|
||||
</button>
|
||||
</Tooltip>
|
||||
<Tooltip label="Videos, images, audio, fonts" side="bottom">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => selectTab("assets")}
|
||||
className={`rounded-[14px] px-1.5 py-2 text-[10px] font-semibold truncate transition-all ${
|
||||
tab === "assets"
|
||||
? "bg-neutral-800 text-white"
|
||||
: "text-neutral-500 hover:text-neutral-200"
|
||||
}`}
|
||||
>
|
||||
Assets
|
||||
</button>
|
||||
</Tooltip>
|
||||
<Tooltip label="Browse blocks and components" side="bottom">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => selectTab("blocks")}
|
||||
className={`rounded-[14px] px-1.5 py-2 text-[10px] font-semibold truncate transition-all ${
|
||||
tab === "blocks"
|
||||
? "bg-neutral-800 text-white"
|
||||
: "text-neutral-500 hover:text-neutral-200"
|
||||
}`}
|
||||
>
|
||||
Catalog
|
||||
</button>
|
||||
</Tooltip>
|
||||
{SIDEBAR_TABS.map((t) => (
|
||||
<Tooltip key={t.id} label={t.tooltip} side="bottom">
|
||||
<button
|
||||
type="button"
|
||||
role="tab"
|
||||
data-tab-id={t.id}
|
||||
aria-selected={tab === t.id}
|
||||
aria-controls={`sidebar-panel-${t.id}`}
|
||||
tabIndex={tab === t.id ? 0 : -1}
|
||||
onClick={() => selectTab(t.id)}
|
||||
className={`rounded-[14px] px-1.5 py-2 text-[10px] font-semibold truncate transition-all active:scale-[0.97] ${
|
||||
tab === t.id
|
||||
? "bg-neutral-800 text-white"
|
||||
: "text-neutral-500 hover:text-neutral-200"
|
||||
}`}
|
||||
>
|
||||
{t.label}
|
||||
</button>
|
||||
</Tooltip>
|
||||
))}
|
||||
</div>
|
||||
{onToggleCollapse && (
|
||||
<button
|
||||
@@ -225,29 +219,41 @@ export const LeftSidebar = memo(
|
||||
|
||||
{/* Tab content */}
|
||||
{tab === "compositions" && (
|
||||
<CompositionsTab
|
||||
projectId={projectId}
|
||||
compositions={compositions}
|
||||
activeComposition={activeComposition}
|
||||
onSelect={onSelectComposition}
|
||||
onAddToTimeline={onAddCompositionToTimeline}
|
||||
onRenderComposition={onRenderComposition}
|
||||
isRendering={isRendering}
|
||||
lintFindingsByFile={lintFindingsByFile}
|
||||
/>
|
||||
<div
|
||||
id="sidebar-panel-compositions"
|
||||
role="tabpanel"
|
||||
className="flex flex-col flex-1 min-h-0"
|
||||
>
|
||||
<CompositionsTab
|
||||
projectId={projectId}
|
||||
compositions={compositions}
|
||||
activeComposition={activeComposition}
|
||||
onSelect={onSelectComposition}
|
||||
onAddToTimeline={onAddCompositionToTimeline}
|
||||
onRenderComposition={onRenderComposition}
|
||||
isRendering={isRendering}
|
||||
lintFindingsByFile={lintFindingsByFile}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{tab === "assets" && (
|
||||
<AssetsTab
|
||||
projectId={projectId}
|
||||
assets={assets}
|
||||
onImport={onImportFiles}
|
||||
onDelete={onDeleteFile}
|
||||
onRename={onRenameFile}
|
||||
onAddAssetToTimeline={onAddAssetToTimeline}
|
||||
/>
|
||||
<div
|
||||
id="sidebar-panel-assets"
|
||||
role="tabpanel"
|
||||
className="flex flex-col flex-1 min-h-0"
|
||||
>
|
||||
<AssetsTab
|
||||
projectId={projectId}
|
||||
assets={assets}
|
||||
onImport={onImportFiles}
|
||||
onDelete={onDeleteFile}
|
||||
onRename={onRenameFile}
|
||||
onAddAssetToTimeline={onAddAssetToTimeline}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{tab === "code" && (
|
||||
<div className="flex flex-1 min-h-0">
|
||||
<div id="sidebar-panel-code" role="tabpanel" className="flex flex-1 min-h-0">
|
||||
{(fileProp?.length ?? 0) > 0 && (
|
||||
<div className="w-[160px] flex-shrink-0 border-r border-neutral-800 overflow-y-auto">
|
||||
<FileTree
|
||||
@@ -276,7 +282,13 @@ export const LeftSidebar = memo(
|
||||
)}
|
||||
|
||||
{tab === "blocks" && (
|
||||
<BlocksTab onAddBlock={onAddBlock} onPreviewBlock={onPreviewBlock} />
|
||||
<div
|
||||
id="sidebar-panel-blocks"
|
||||
role="tabpanel"
|
||||
className="flex flex-col flex-1 min-h-0"
|
||||
>
|
||||
<BlocksTab onAddBlock={onAddBlock} onPreviewBlock={onPreviewBlock} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Lint button pinned at the bottom */}
|
||||
@@ -285,7 +297,7 @@ export const LeftSidebar = memo(
|
||||
<button
|
||||
onClick={onLint}
|
||||
disabled={linting}
|
||||
className="w-full flex items-center justify-center gap-1.5 px-2 py-1.5 rounded-md text-[11px] font-medium text-neutral-500 hover:text-amber-300 hover:bg-neutral-800 transition-colors disabled:opacity-40"
|
||||
className="w-full flex items-center justify-center gap-1.5 px-2 py-1.5 rounded-md text-[11px] font-medium text-neutral-500 enabled:hover:text-amber-300 enabled:hover:bg-neutral-800 enabled:active:scale-[0.98] transition-colors disabled:opacity-40"
|
||||
>
|
||||
<svg
|
||||
width="12"
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
import { useState, useCallback, useEffect, useRef } from "react";
|
||||
import { useDialogBehavior } from "../ui/useDialogBehavior";
|
||||
|
||||
export function PromptPreviewModal({
|
||||
title,
|
||||
prompt,
|
||||
onClose,
|
||||
}: {
|
||||
title: string;
|
||||
prompt: string;
|
||||
onClose: () => void;
|
||||
}) {
|
||||
const [value, setValue] = useState(prompt);
|
||||
const [copyState, setCopyState] = useState<"idle" | "copied" | "failed">("idle");
|
||||
const [entered, setEntered] = useState(false);
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
||||
const valueRef = useRef(value);
|
||||
valueRef.current = value;
|
||||
|
||||
// Escape / focus trap / focus restore. A dirty draft vetoes Escape and
|
||||
// backdrop close so a stray click can't discard edits (the X still closes).
|
||||
const { requestClose } = useDialogBehavior({
|
||||
open: true,
|
||||
onClose,
|
||||
containerRef,
|
||||
canClose: () => valueRef.current === prompt,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
requestAnimationFrame(() => {
|
||||
setEntered(true);
|
||||
textareaRef.current?.focus();
|
||||
});
|
||||
}, []);
|
||||
|
||||
const handleCopy = useCallback(async () => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(valueRef.current);
|
||||
setCopyState("copied");
|
||||
} catch {
|
||||
setCopyState("failed");
|
||||
}
|
||||
setTimeout(() => setCopyState("idle"), 1500);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`fixed inset-0 z-[100] flex items-center justify-center bg-black/60 backdrop-blur-sm transition-opacity duration-150 ease-out ${
|
||||
entered ? "opacity-100" : "opacity-0"
|
||||
}`}
|
||||
onClick={requestClose}
|
||||
>
|
||||
<div
|
||||
ref={containerRef}
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-label={`Ask agent — ${title}`}
|
||||
tabIndex={-1}
|
||||
className="w-[560px] max-h-[80vh] flex flex-col rounded-2xl border border-neutral-800 bg-neutral-950 shadow-2xl outline-none"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<div className="flex items-center justify-between px-5 py-4 border-b border-neutral-800/60">
|
||||
<div>
|
||||
<h3 className="text-sm font-medium text-neutral-200">Ask agent</h3>
|
||||
<p className="text-xs text-neutral-500 mt-0.5">{title}</p>
|
||||
</div>
|
||||
<button
|
||||
aria-label="Close"
|
||||
className="p-1 rounded-md text-neutral-500 hover:text-neutral-300 hover:bg-neutral-800/50 active:scale-[0.95]"
|
||||
onClick={onClose}
|
||||
>
|
||||
<svg
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<line x1="18" y1="6" x2="6" y2="18" />
|
||||
<line x1="6" y1="6" x2="18" y2="18" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
<div className="flex-1 overflow-y-auto px-5 py-4">
|
||||
<p className="text-[11px] text-neutral-500 mb-2">
|
||||
Edit the prompt below, then copy and paste into your AI agent
|
||||
</p>
|
||||
<textarea
|
||||
ref={textareaRef}
|
||||
value={value}
|
||||
onChange={(e) => setValue(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) void handleCopy();
|
||||
}}
|
||||
className="w-full min-h-[240px] text-[11px] text-neutral-200 leading-relaxed font-mono bg-neutral-900/60 rounded-lg p-3 border border-neutral-800 resize-y focus:outline-none focus:border-studio-accent/60 focus:ring-1 focus:ring-studio-accent/30"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-center justify-between px-5 py-3 border-t border-neutral-800/60">
|
||||
<span className="text-[11px] text-neutral-600">
|
||||
{navigator.platform.includes("Mac") ? "⌘" : "Ctrl"}+Enter to copy
|
||||
</span>
|
||||
<button
|
||||
className={`px-4 py-1.5 rounded-lg text-xs font-medium transition-colors active:scale-[0.97] ${
|
||||
copyState === "copied"
|
||||
? "bg-emerald-500 text-white"
|
||||
: copyState === "failed"
|
||||
? "bg-red-500 text-white"
|
||||
: "bg-studio-accent/90 text-neutral-950 hover:bg-studio-accent"
|
||||
}`}
|
||||
onClick={handleCopy}
|
||||
>
|
||||
{copyState === "copied"
|
||||
? "Copied!"
|
||||
: copyState === "failed"
|
||||
? "Copy failed"
|
||||
: "Copy prompt"}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -24,6 +24,14 @@ export function basename(path: string): string {
|
||||
return dot > 0 ? name.slice(0, dot) : name;
|
||||
}
|
||||
|
||||
/** Last path segment WITH its extension (basename() strips it). */
|
||||
export function filename(path: string): string {
|
||||
return path.split("/").pop() ?? path;
|
||||
}
|
||||
|
||||
/** Feedback shown on an asset row/card after a copy-path attempt. */
|
||||
export type CopyFeedback = { path: string; ok: boolean } | null;
|
||||
|
||||
export function ext(path: string): string {
|
||||
const name = path.split("/").pop() ?? path;
|
||||
const dot = name.lastIndexOf(".");
|
||||
|
||||
Reference in New Issue
Block a user