// A SONG PIECE's tabs and stepper (plans/umtool-redesign.md, P4a-3). Pure, no // imports, beside lib/pieces/tabs.mjs (the report video's and the article's): // the page, Work's facet and an e2e spec (e2e/urls.ts `songSection`) read the // same table. // // A song walks its own three stages, Spec → Cuts → Done, not the report's four. // The registry declares which stepper a kind walks (lib/projects/kinds.mjs, the // song kind's `piece.flow`), so nothing here branches on a kind id: the flow is // a name the pieces graph copies onto the piece. // // The tab is the URL's `?tab=`, as on every piece page. A song's cut page // (`/projects//`, the CutBench, its loudness and provenance) is a // VIEW of the Cuts tab: the frame draws it with Cuts current. /** The stepper a kind declares to walk Spec → Cuts → Done. */ export const SONG_FLOW = "song"; /** * A song's three stages, each with the Work bucket (lib/work/facets.mjs STAGES) * it stands in for, so Work's stage facet and the song's stepper agree: the * spec is a song's written stage (a report video's article), its cuts its * video, and a full set of cuts its delivery. */ export const SONG_STEPS = [ { id: "spec", label: "Spec", bucket: "article" }, { id: "cuts", label: "Cuts", bucket: "video" }, { id: "done", label: "Done", bucket: "deliver" }, ]; const SKIPPED = { spec: "no spec.json", cuts: "no cut built" }; /** * The song's stepper, by the one stage rule (lib/pieces/tabs.mjs pieceSteps): * the furthest stage reached is current, the ones before it done (or to do with * the reason, when skipped), a piece marked done has done them all. * * Spec reached with a spec.json * Cuts reached with one cut built * Done reached with every cut built (the song's derived `shipped`, which is * also its looks-done suggestion, lib/pieces.ts) * * @param {{ reached: { spec?: boolean, cuts?: boolean, done?: boolean }, lifecycle: string }} p * @returns {{ id: string, label: string, state: "done" | "current" | "todo", title?: string }[]} */ export function songSteps({ reached, lifecycle }) { const has = reached ?? {}; let at = 0; SONG_STEPS.forEach((s, i) => { if (has[s.id]) at = i; }); return SONG_STEPS.map((s, i) => { if (lifecycle === "done") return { id: s.id, label: s.label, state: "done" }; if (i === at) return { id: s.id, label: s.label, state: "current" }; if (i < at && has[s.id]) return { id: s.id, label: s.label, state: "done" }; if (i < at) return { id: s.id, label: s.label, state: "todo", title: SKIPPED[s.id] }; return { id: s.id, label: s.label, state: "todo" }; }); } /** The song stage that is current (lifecycle aside): `spec`, `cuts` or `done`. */ export function songStepOf({ reached }) { return songSteps({ reached, lifecycle: "active" }).find((s) => s.state === "current")?.id ?? "spec"; } /** The Work bucket a song stage stands in for. */ export function bucketOfSongStep(step) { return SONG_STEPS.find((s) => s.id === step)?.bucket ?? "video"; } /** The tabs of a song piece, in order; the key that opens each is its position (`1`–`5`). */ export const SONG_PIECE_TABS = [ { id: "overview", label: "Overview" }, { id: "cuts", label: "Cuts" }, { id: "spec", label: "Spec" }, { id: "cover", label: "Cover" }, { id: "notes", label: "Notes" }, ]; export const SONG_PIECE_TAB_IDS = SONG_PIECE_TABS.map((t) => t.id); /** * Every section the song page drew (components/projects/SongProject.tsx and * CutPage.tsx before P4a-3), by the name a spec says, and the tab it is on. */ export const SONG_SECTION_TAB = { // Overview: the Next card, the song's decisions, the cut set at a glance, // the paste, the README, the song tools. next: "overview", decisions: "overview", slots: "overview", copy: "overview", readme: "overview", tools: "overview", // Cuts: the four cut cards (poster, verdicts, notes, variants), what matches // no cut, and a cut's own page (the bench, loudness, provenance). cuts: "cuts", variants: "cuts", verdicts: "cuts", unattributed: "cuts", bench: "cuts", loudness: "cuts", provenance: "cuts", // Spec: the spec sheet and its operations, the plans. spec: "spec", operations: "spec", plans: "spec", // Cover: the cover-art bench (and its way to the face judger). cover: "cover", thumbs: "cover", faces: "cover", // Notes: the note on the song as a whole, and every other note on it. notes: "notes", }; /** The tab a song section is on; throws on a name nobody declared (a spec's typo should fail loudly). */ export function songTabOfSection(name) { const tab = SONG_SECTION_TAB[name]; if (!tab) throw new Error(`no section "${name}" on a song piece (lib/pieces/song-tabs.mjs SONG_SECTION_TAB)`); return tab; } /** * Where a song note is drawn (lib/notes.ts: a song's notes are keyed by their * TARGET): the song's own on Notes, a cut's, a file's, a mark's, a source's or * a clip's with the cuts, a plan's on Spec, a cover's on Cover. * * @param {string | undefined | null} target */ export function songTabOfNote(target) { const t = String(target ?? ""); if (t === "song") return "notes"; if (/^(cut|file|moment|source|clip):/.test(t)) return "cuts"; if (t.startsWith("plan:")) return "spec"; if (t.startsWith("thumb:")) return "cover"; return "overview"; } /** * The tab a song piece's address opens: `?tab=`; else a `?note=` where * that note is drawn; else the Overview. * * @param {{ tab?: string, note?: string }} search */ export function songTabOf(search) { const t = search?.tab; if (t && SONG_PIECE_TAB_IDS.includes(t)) return t; if (search?.note) return songTabOfNote(search.note); return "overview"; }