// A PIECE PAGE's tabs (plans/umtool-redesign.md, P4a): which tab a project- // rooted piece opens on, which section lives in which tab, and the key that // switches to each. Pure, no imports: the page, a client component and an e2e // spec (e2e/urls.ts `section`) read the same table. // // The tab is the URL's `?tab=` -- the canvas's address (`…?tab=media`) and the // article page's own key (`/articles/?tab=iterations`), so P4a-2's merged // article piece keeps one spelling. Not a path segment: a project id is a path // resolved longest-prefix, and what is left after it is a VIEW the kind declares // (`clip/`, `takes`, `review` …), so `/projects/a/b/build` could just as well // be a project called `build`. // // An address with no `tab` opens the Overview -- except the two the page always // answered that only make sense on one tab: `?all=1` (the cut's "show every // quote") opens the Cut, and `?note=` opens the tab its anchor is drawn on // (a timeline row's note on the Cut, a timed note on the final video on Build). // // A SONG walks its own stepper and has its own tabs (lib/pieces/song-tabs.mjs, // P4a-3); pieceSteps and stageOfPiece switch to it on the flow the registry // declares, so the one stage rule stays one function. import { SONG_FLOW, bucketOfSongStep, songStepOf, songSteps } from "./song-tabs.mjs"; /** The stepper's four stages, by Work's buckets (lib/work/facets.mjs STAGES). */ export const STAGE_STEPS = [ { id: "research", label: "Research" }, { id: "article", label: "Article" }, { id: "video", label: "Video" }, { id: "deliver", label: "Deliver" }, ]; /** * THE ONE STAGE RULE (P4a-2 follow-up): a piece's stepper, and so its stage -- * the step that is current -- from what the piece has REACHED. The piece page's * stepper and Work's stage facet (lib/work/facets.mjs stageOf, lib/pieces.ts's * article `stage`) both read it, so they can never disagree. * * Research reached with iterations, or a research board that seeded it * Article reached with a report (an article piece's own) * Video reached with a video project it claims (or a video in the * report); a project piece IS its video, always reached * Deliver reached when it looks done (a final video and a share batch, * or published with its video; a song with every cut) * * The current step is the furthest reached (the canvas's: a built video not * yet delivered is at Video); the steps before it are done, or to do with the * reason when they were skipped (an article in the making whose iterations * already made a video has no report yet). A stage that cannot apply is `na` * with its reason: a project no article claims has no Article stage, nor a * Research stage unless a board made it; an article with neither iterations * nor a board (a site's hand-written report) has no Research recorded here. A * piece marked done has done every stage that applies. * * A song (`kind` the flow its kind declares, SONG_FLOW) walks Spec → Cuts → * Done by the same rule (lib/pieces/song-tabs.mjs songSteps). * * @param {{ kind: string, reached: { research?: boolean, article?: boolean, video?: boolean, deliver?: boolean, spec?: boolean, cuts?: boolean, done?: boolean }, lifecycle: string }} p * @returns {{ id: string, label: string, state: "done" | "current" | "todo" | "na", title?: string }[]} */ export function pieceSteps({ kind, reached, lifecycle }) { if (kind === SONG_FLOW) return songSteps({ reached, lifecycle }); const project = kind !== "article"; const has = { ...reached, ...(project ? { video: true, article: false } : {}) }; const na = project ? { ...(has.research ? {} : { research: "no research board" }), article: "no article" } : has.research ? {} : { research: "no iterations or research board" }; const SKIPPED = { research: "no iterations yet", article: "no report yet", video: "no video project yet" }; let at = -1; STAGE_STEPS.forEach((s, i) => { if (!na[s.id] && has[s.id]) at = i; }); if (at < 0) at = STAGE_STEPS.findIndex((s) => !na[s.id]); return STAGE_STEPS.map((s, i) => { if (na[s.id]) return { id: s.id, label: s.label, state: "na", title: na[s.id] }; 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" }; }); } /** * A piece's stage: the step that is current, by the one rule (lifecycle aside -- * a parked or done piece keeps the stage it is at). Always one of Work's four * buckets: a song's stage is the bucket its step stands in for (Spec → article, * Cuts → video, Done → deliver). * * @param {{ kind: string, reached: { research?: boolean, article?: boolean, video?: boolean, deliver?: boolean, spec?: boolean, cuts?: boolean, done?: boolean } }} p */ export function stageOfPiece({ kind, reached }) { if (kind === SONG_FLOW) return bucketOfSongStep(songStepOf({ reached })); return pieceSteps({ kind, reached, lifecycle: "active" }).find((s) => s.state === "current")?.id ?? "video"; } /** * The step a piece's stepper has current, by its own ids (lifecycle aside): one * of the four stages, or a song's `spec` / `cuts` / `done`. The piece page's * `data-piece-stage`. * * @param {{ kind: string, reached: object }} p */ export function stepOfPiece({ kind, reached }) { if (kind === SONG_FLOW) return songStepOf({ reached }); return stageOfPiece({ kind, reached }); } /** * The tabs of a report-video piece, in order; the key that opens each is its position. Since the workspace * (umtool redesign L7b) they are FOUR: the workspace itself (the project's own address: the draft playing, its * blocks, the inspector, the review pass, present), then Sources, Deliver and History. * * What the seven tabs before it held, and where it is now: * Build, Media folded into Deliver (PIECE_FOLDED): the build chain and the final mp4, the drafted fields, * the upload's text and the on-screen panel are what ships -- `?tab=build|media` 307s there (temporary: it moves again) * Overview, Cut addressable VIEWS still (PIECE_VIEWS), out of the tab bar, under the workspace: the piece's * decisions, README and iterations, and the cut as a list with its every tool (fetch windows, * candidates, groups, prep …) have no home in the workspace yet. The workspace's Piece ▾ and * the piece page's ⋯ open them. */ export const PIECE_TABS = [ { id: "workspace", label: "Workspace" }, { id: "sources", label: "Sources" }, { id: "deliver", label: "Deliver" }, { id: "history", label: "History" }, ]; export const PIECE_TAB_IDS = PIECE_TABS.map((t) => t.id); /** The piece page's views out of the tab bar (the workspace's, until it holds them): `?tab=overview`, `?tab=cut`. */ export const PIECE_VIEWS = [ { id: "overview", label: "Overview" }, { id: "cut", label: "The cut as a list" }, ]; export const PIECE_VIEW_IDS = PIECE_VIEWS.map((t) => t.id); /** The tabs that folded into another (L7b): their address 307s to it (temporary), the rest of the query kept. */ export const PIECE_FOLDED = { build: "deliver", media: "deliver" }; /** * Every `?tab=` a report video's address has ever answered (the seven of P4a-1): what a claimed project's address * carries over to its article piece, which keeps all seven (ARTICLE_PIECE_TABS). */ export const PIECE_ADDRESS_TAB_IDS = ["overview", "cut", "media", "build", "deliver", "sources", "history"]; /** * Every section ReportProject draws, by the name a spec says, and the tab it * is on. The names are the sections' own data attributes where they have one. */ export const SECTION_TAB = { // Overview: the Next card, the piece's decisions, the stats, the linked // article and its iterations, and the author's README. next: "overview", decisions: "overview", readme: "overview", stats: "overview", article: "overview", iterations: "overview", // Cut: the timeline, the walk, takes, corrections for the next pass. walk: "cut", timeline: "cut", cut: "cut", takes: "cut", corrections: "cut", // What was Media: every drafted field and each section's Draft with (P4b's one surface), // the review and narration benches' links, the on-screen panel (moved from // Build in P4b) and the upload's text -- on Deliver since L7b. drafts: "deliver", review: "deliver", narration: "deliver", youtube: "deliver", onscreen: "deliver", // What was Build: the build chain and the final mp4 -- on Deliver since L7b. build: "deliver", final: "deliver", // Deliver: the deliver panel and the exports. deliver: "deliver", exports: "deliver", // Sources: the source table, availability, tagging the cited recordings. sources: "sources", tag: "sources", // History: revisions, provenance, notes. revisions: "history", provenance: "history", notes: "history", }; /** The tab a section is on; throws on a name nobody declared (a spec's typo should fail loudly). */ export function tabOfSection(name) { const tab = SECTION_TAB[name]; if (!tab) throw new Error(`no section "${name}" on a piece page (lib/pieces/tabs.mjs SECTION_TAB)`); return tab; } /** Where a note's anchor is drawn: a row's on the Cut, a timed note on the final video on Build. */ export function tabOfNoteAnchor(kind, { piece = "project" } = {}) { // A Play-view note (`cut`) is reached from the Cut tab's Play the cut; its own link opens the Play view. if (kind === "entry" || kind === "edit" || kind === "cut" || kind === "reel") return "cut"; // The final video's timed notes: on Deliver since Build folded into it (L7b); an article piece keeps its Build. if (kind === "moment") return piece === "article" ? "build" : "deliver"; return "overview"; } /** * The tab an address opens. * * @param {{ tab?: string, all?: string, note?: string }} search * @param {{ noteTab?: string | null }} [opts] the tab the `note`'s anchor is on, when the page looked it up */ export function tabOf(search, { noteTab = null } = {}) { const shown = (t) => (PIECE_FOLDED[t] ?? t); const known = (t) => !!t && t !== "workspace" && (PIECE_TAB_IDS.includes(shown(t)) || PIECE_VIEW_IDS.includes(t)); const t = search?.tab; if (known(t)) return shown(t); if (search?.note && known(noteTab)) return shown(noteTab); if (search?.all === "1") return "cut"; return "overview"; } /** The tab a number key opens (`1` … `4`: the workspace, Sources, Deliver, History), or null. */ export function tabOfKey(key) { const n = Number(key); return Number.isInteger(n) && n >= 1 && n <= PIECE_TABS.length ? PIECE_TABS[n - 1].id : null; } // ── the article-rooted piece (P4a-2) ──────────────────────────────────────── // // An article and the video project it claims are ONE piece, at the article's // address (`/articles/`, `/sites//`). Its tabs are the // article's two (the reader, the iterations) set into the video's seven: the // video tabs render the claimed project's P4a-1 tabs. Same `?tab=` ids, so a // project tab maps to the article piece's tab of the same name. /** The tabs of an article piece, in order; the key that opens each is its position (`1`–`9`). */ export const ARTICLE_PIECE_TABS = [ { id: "overview", label: "Overview" }, { id: "article", label: "Article" }, { id: "iterations", label: "Iterations" }, { id: "cut", label: "Cut" }, { id: "media", label: "Media" }, { id: "build", label: "Build" }, { id: "deliver", label: "Deliver" }, { id: "sources", label: "Sources" }, { id: "history", label: "History" }, ]; export const ARTICLE_PIECE_TAB_IDS = ARTICLE_PIECE_TABS.map((t) => t.id); /** The tabs an article piece draws from its video project (every tab a project piece had but its Overview). */ export const VIDEO_TAB_IDS = PIECE_ADDRESS_TAB_IDS.filter((t) => t !== "overview"); /** * The sections an article piece adds to SECTION_TAB, by the name a spec says. * The video's sections keep the tab they have on a project piece, except the * two a project's Overview summarised (the article, its iterations): here they * are tabs of their own. */ export const ARTICLE_SECTION_TAB = { ...SECTION_TAB, // An article piece keeps the video's Media and Build tabs (the project piece folded them into Deliver, L7b). drafts: "media", review: "media", narration: "media", youtube: "media", onscreen: "media", build: "build", final: "build", next: "overview", sections: "overview", article: "article", reader: "article", // The article's workspace files: the Article tab's `source` view (`?tab=source`). source: "article", iterations: "iterations", }; /** The tab a section is on in an article piece; throws on a name nobody declared. */ export function articleTabOfSection(name) { const tab = ARTICLE_SECTION_TAB[name]; if (!tab) throw new Error(`no section "${name}" on an article piece (lib/pieces/tabs.mjs ARTICLE_SECTION_TAB)`); return tab; } /** * The tab an article piece's address opens. `?tab=` first (`source` is the * Article tab's workspace view, the old article page's own key); then a note -- * the article's own notes are drawn on the Article tab, a note on the video * project where its anchor is (the page looks it up and passes `noteTab`); * then the reader's own keys (`rv` the slides/overview switch, `status` the * notes filter, `ws`/`rel` a workspace file) open the Article tab, `?all=1` the * Cut; else the Overview. * * @param {{ tab?: string, note?: string, rv?: string, status?: string, ws?: string, rel?: string, all?: string }} search * @param {{ noteTab?: string | null }} [opts] */ export function articleTabOf(search, { noteTab = null } = {}) { const t = search?.tab; if (t === "source") return "article"; if (t && ARTICLE_PIECE_TAB_IDS.includes(t)) return t; if (search?.note) return noteTab && ARTICLE_PIECE_TAB_IDS.includes(noteTab) ? noteTab : "article"; if (search?.rv || search?.status || search?.ws || search?.rel) return "article"; if (search?.all === "1") return "cut"; return "overview"; }