// EDIT on the audition deck (release 32 R1): a drafted field rewritten by the // person as plain text, and turned back into the field's value. One line per // part, so the same textarea serves every field the card can edit: // // onscreen line 1 the title, the rest the subtitle // narration the text // lines one teaser line per line // publish.youtube line 1 the title (the description stays) // // Any other field (flips, threads, the cut's order, a social post) is edited // where it always was: the deck links its section. The value goes through the // manifest's own writer (writeDraftedField), so it is the operator's after. export const EDITABLE_FIELDS = Object.freeze(["onscreen", "narration", "lines", "publish.youtube"]); /** Whether the card can edit this field in place. */ export const isEditableField = (field) => EDITABLE_FIELDS.includes(field); /** The textarea's text for a field, from the words the review shows (judgedText). */ export function editTextOf(field, judged) { const s = typeof judged === "string" ? judged : ""; if (field === "onscreen") return s.replace(" — ", "\n"); if (field === "lines") return s.split(" / ").join("\n"); return s; } const linesOf = (text) => String(text ?? "") .split(/\r?\n/) .map((l) => l.trim()) .filter(Boolean); /** * The field's new value from the edited text, keeping what the text does not * say (a narration's voice, a teaser line's own keys, the description). * Throws in words when the text cannot be the field. */ export function valueFromEdit(field, current, text) { const lines = linesOf(text); const obj = (v) => (v && typeof v === "object" && !Array.isArray(v) ? v : {}); if (field === "onscreen") { if (!lines.length) throw new Error("an on-screen text needs a title"); const { title: _t, subtitle: _s, ...rest } = obj(current); const subtitle = lines.slice(1).join(" "); return { ...rest, title: lines[0], ...(subtitle ? { subtitle } : {}) }; } if (field === "narration") { const t = String(text ?? "").trim(); if (!t) throw new Error("a narration needs its words"); return { ...obj(current), text: t }; } if (field === "lines") { if (!lines.length) throw new Error("a teaser needs at least one line"); const was = Array.isArray(current) ? current : []; return lines.map((l, i) => (was[i] && typeof was[i] === "object" ? { ...was[i], text: l } : l)); } if (field === "publish.youtube") { if (!lines.length) throw new Error("a YouTube title cannot be empty"); return { ...obj(current), title: lines[0] }; } throw new Error(`${field} is edited in its own section, not on the card`); } /** The current value of a review row's field in a manifest. */ export function currentFieldValue(manifest, { entry, field }) { if (entry) return (manifest?.timeline ?? []).find((e) => e?.id === entry)?.[field]; if (field === "publish.youtube") return manifest?.publish?.youtube; return undefined; }