"use client"; import { useEffect, useRef, useState } from "react"; import { Button } from "@/components/ui/button"; import { cn } from "@/lib/utils"; import { MANIFEST_CHANGED, announceManifestChanged } from "../timelineApi"; export { announceManifestChanged }; // --------------------------------------------------------------------------- // THE INSPECTOR PANELS' COMMON PARTS (umtool redesign L6). Every panel in this directory is self-contained: it // takes `{ project, block? }` (the project id; the block -- a timeline entry's id -- it inspects, when it is about // one), reads its own state from its API route and writes through it, so L7 can mount it in the workspace's // inspector unchanged. Today they are mounted in the Cut tab (and Play's Still button). Every write lands in the // working draft (video.manifest.json) with its own undo point; none touches a take's patch. No AI anywhere. // --------------------------------------------------------------------------- export type InspectorProps = { project: string; block?: string | null }; /** What a write said: a sentence, good or bad. */ export type Said = { ok: boolean; text: string } | null; /** A JSON request; the parsed body (or {}) and whether it was 2xx. A stale token says so. */ export async function call>(url: string, init?: RequestInit): Promise<{ ok: boolean; status: number; j: T & { error?: string; errors?: string[]; stale?: boolean } }> { const r = await fetch(url, { cache: "no-store", ...init, headers: init?.body && typeof init.body === "string" ? { "content-type": "application/json", ...(init.headers ?? {}) } : init?.headers }); const j = (await r.json().catch(() => ({}))) as T & { error?: string; errors?: string[]; stale?: boolean }; return { ok: r.ok, status: r.status, j }; } /** The sentence for a refused write. */ export const refusal = (j: { error?: string; errors?: string[]; stale?: boolean }, status: number) => j.stale ? "The draft changed since this panel read it — it has been read again; check and save once more." : (j.errors?.length ? j.errors.join("; ") : j.error) ?? `HTTP ${status}`; /** A panel's frame: a heading, the body. */ export function InspectorFrame({ kind, title, aside, className, children }: { kind: string; title: React.ReactNode; aside?: React.ReactNode; className?: string; children: React.ReactNode }) { return (

{title}

{aside ? {aside} : null}
{children}
); } /** The line under a panel's buttons. */ export function SaidLine({ said, testid }: { said: Said; testid: string }) { if (!said) return null; return ( {said.text} ); } /** * A row's "Edit" that opens a panel under it (the Cut tab's per-row inspector, until L7's workspace has one * inspector for the selected block). */ export function InspectorToggle({ label = "Edit", testid, children, className }: { label?: string; testid: string; children: React.ReactNode; className?: string }) { const [open, setOpen] = useState(false); return ( <> {open ?
{children}
: null} ); } /** * Read again whenever the draft changed under the panel (the page's MANIFEST_CHANGED: another panel's write, the * timeline's Undo), so its token is never the stale one. `reread` keeps a form being typed in (it refreshes the * view, not the fields). */ export function useOnManifestChanged(project: string, reread: () => unknown) { const fn = useRef(reread); fn.current = reread; useEffect(() => { const on = (e: Event) => { if ((e as CustomEvent).detail?.project === project) void fn.current(); }; window.addEventListener(MANIFEST_CHANGED, on); return () => window.removeEventListener(MANIFEST_CHANGED, on); }, [project]); } /** * Its children only once the `
` it sits in has been opened (an Options panel): the panels inside read * nothing until somebody looks. Outside a `
`, at once. */ export function WhenOpen({ children }: { children: React.ReactNode }) { const ref = useRef(null); const [open, setOpen] = useState(false); useEffect(() => { const d = ref.current?.closest("details"); if (!d) { setOpen(true); return; } const on = () => { if (d.open) setOpen(true); }; on(); d.addEventListener("toggle", on); return () => d.removeEventListener("toggle", on); }, []); return ( <>