commit 992c5b5bd825e4cc2087c4f71158d256136dbb65
parent 6545526f85c8f816a82d50ce0bf8e3bab412a31b
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Mon, 9 Nov 2026 23:07:26 -0500
umtool: a post item's attachment switched off is kept whole (mediaOff), on puts it back as it was (L6 review 1)
Off moved the attachment out of media (its crop, blur, trim, sound lost; on re-measured it fresh). Now
updatePostItem mediaHide/mediaShow move it whole between media and mediaOff, which nothing draws or plays
(only media is read); post-item.mjs validates mediaOff as an attachment list. CLI: set-item
media.<i>.shown=off / media-off.<j>.shown=on. media-on refuses a file the item carries already.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
8 files changed, 129 insertions(+), 26 deletions(-)
diff --git a/umtool/app/api/report/post-item/inspector/route.ts b/umtool/app/api/report/post-item/inspector/route.ts
@@ -18,17 +18,22 @@ export const dynamic = "force-dynamic";
// an attachment off or its sound), the multipart POST /api/report/post-narration (a recording), and here:
//
// GET ?project=<id>&id=<item> the view above, and the token
-// POST { project, token, id, op: "media-on", file: "posts-media/…" } a file of the post put back on the item,
-// measured as `posts set-item media.add=` measures one
+// POST { project, token, id, op: "media-on", file: "posts-media/…" } a file of the post the item never carried put
+// on it, measured as `posts set-item media.add=` measures one (refused
+// when the item carries it, shown or switched off)
+// POST { project, token, id, op: "media-off", i } attachment i switched OFF, kept whole in `mediaOff` (its crop,
+// blur, trim, sound kept; nothing draws it) -- `set-item media.<i>.shown=off`
+// POST { project, token, id, op: "media-show", j } the attachment switched off at j shown again, as it was
+// -- `set-item media-off.<j>.shown=on`
const noStore = { "cache-control": "no-store" };
const MEDIA_RE = /\.(png|jpe?g|webp|gif|mp4|m4v|mov|webm)$/i;
-type Entry = Record<string, unknown> & { id: string; type?: string; post?: string; media?: Array<Record<string, unknown>>; narration?: Record<string, unknown> };
+type Entry = Record<string, unknown> & { id: string; type?: string; post?: string; media?: Array<Record<string, unknown>>; mediaOff?: Array<Record<string, unknown>>; narration?: Record<string, unknown> };
/** The post's own files in the project (posts-media/<channel>/<postId>/), pictures and videos, its screenshots left out. */
async function postFiles(dir: string, e: Entry): Promise<string[]> {
const roots = new Set<string>();
if (typeof e.post === "string" && /^[A-Za-z0-9._-]+\/[A-Za-z0-9._-]+$/.test(e.post)) roots.add(`posts-media/${e.post}`);
- for (const m of e.media ?? []) if (typeof m?.src === "string" && m.src.startsWith("posts-media/")) roots.add(path.posix.dirname(m.src));
+ for (const m of [...(e.media ?? []), ...(e.mediaOff ?? [])]) if (typeof m?.src === "string" && m.src.startsWith("posts-media/")) roots.add(path.posix.dirname(m.src));
const out: string[] = [];
for (const rel of roots) {
if (rel.split("/").includes("..")) continue;
@@ -56,14 +61,15 @@ export async function GET(request: Request) {
i, src: typeof m?.src === "string" ? m.src : null, kind: typeof m?.kind === "string" ? m.kind : null,
mute: m?.mute === true, seconds: typeof m?.seconds === "number" ? m.seconds : null, audio: m?.audio === true,
}));
- const carried = new Set(media.map((m) => m.src));
+ const off = (e.mediaOff ?? []).map((m, j) => ({ j, src: typeof m?.src === "string" ? m.src : null, kind: typeof m?.kind === "string" ? m.kind : null }));
+ const carried = new Set([...media.map((m) => m.src), ...off.map((m) => m.src)]);
const takes = Array.isArray(e.narration?.takes) ? (e.narration.takes as Array<Record<string, unknown>>) : [];
const picked = pickedTake(e) as (Record<string, unknown> & { file: string; index: number }) | null;
return Response.json(
{
id: e.id, post: e.post ?? null, author: e.author ?? null, handle: e.handle ?? null, text,
excerpt: spans, ranges: spans ? excerptRanges(text, spans) : null, excerptErrors: excerptErrors(e),
- media, files: (await postFiles(r.project.dir, e)).filter((f) => !carried.has(f)),
+ media, off, files: (await postFiles(r.project.dir, e)).filter((f) => !carried.has(f)),
narration: {
takes: takes.map((t, i) => ({ i, file: String(t.file ?? ""), engine: typeof t.engine === "string" ? t.engine : null, voice: typeof t.voice === "string" ? t.voice : null, seconds: typeof t.seconds === "number" ? t.seconds : null })),
picked: picked ? picked.index : null,
@@ -88,19 +94,24 @@ export async function POST(request: Request) {
}
const r = await resolveReport(String(body.project ?? ""));
if ("error" in r) return Response.json({ error: r.error }, { status: r.status });
- if (body.op !== "media-on") return Response.json({ error: "op is media-on" }, { status: 400 });
+ if (!["media-on", "media-off", "media-show"].includes(String(body.op))) return Response.json({ error: "op is media-on, media-off or media-show" }, { status: 400 });
const id = String(body.id ?? "");
const tl = ((r.manifest as { timeline?: Entry[] }).timeline ?? []) as Entry[];
const e = tl.find((x) => x?.type === "post" && x.id === id);
if (!e) return Response.json({ error: `no post item ${id}` }, { status: 404 });
- const file = String(body.file ?? "");
- // Only one of the post's own files (the list GET gives): never a path from elsewhere in the project.
- if (!(await postFiles(r.project.dir, e)).includes(file)) return Response.json({ error: `${file} is not one of ${id}'s post files` }, { status: 400 });
+ const token = typeof body.token === "string" ? body.token : null;
try {
- const att = await attachmentOf(r.project.dir, file);
- const { result, editNotes } = await withEditNotes(r.project, () =>
- updatePostItem(r.project.dir, id, { mediaAdd: [att] }, { token: typeof body.token === "string" ? body.token : null }),
- );
+ let patch: Record<string, unknown>;
+ if (body.op === "media-on") {
+ const file = String(body.file ?? "");
+ // Only one of the post's own files (the list GET gives): never a path from elsewhere in the project.
+ if (!(await postFiles(r.project.dir, e)).includes(file)) return Response.json({ error: `${file} is not one of ${id}'s post files` }, { status: 400 });
+ // A file the item carries already -- shown, or switched off with its knobs -- is not added twice.
+ if ([...(e.media ?? []), ...(e.mediaOff ?? [])].some((m) => m?.src === file)) return Response.json({ error: `${id} carries ${file} already (switched off: show it again)` }, { status: 400 });
+ patch = { mediaAdd: [await attachmentOf(r.project.dir, file)] };
+ } else if (body.op === "media-off") patch = { mediaHide: [Number(body.i)] };
+ else patch = { mediaShow: [Number(body.j)] };
+ const { result, editNotes } = await withEditNotes(r.project, () => updatePostItem(r.project.dir, id, patch, { token }));
return Response.json({ ok: true, entry: result.entry, token: result.token, editNotes }, { headers: noStore });
} catch (e2) {
if (e2 instanceof StaleToken) return Response.json({ error: e2.message, stale: true }, { status: 409 });
diff --git a/umtool/components/projects/inspector/PostItemInspector.tsx b/umtool/components/projects/inspector/PostItemInspector.tsx
@@ -12,8 +12,9 @@ import { InspectorFrame, SaidLine, announceManifestChanged, call, refusal, useOn
// spans already picked, settled where the build will find each one (excerptPick.mjs), saved as
// `entry.excerpt` -- verbatim spans in the post's order, read joined with " … ", the card still
// showing the whole post with the rest dimmed (POST /api/report/post-item {op: "set"}).
-// ITS MEDIA each attachment shown or not (off removes it from the item, its file kept; a file of the post the
-// item does not carry can be put back on) and a video's sound on or off.
+// ITS MEDIA each attachment shown or not (off keeps it whole in `mediaOff` -- crop, blur, trim, sound -- and
+// on puts it back as it was; a file of the post the item never carried can be put on) and a video's
+// sound on or off.
// MY RECORDING a sound file of your own read of it, kept as a recorded take and picked (the multipart POST
// /api/report/post-narration: trimmed, levelled; `umtool posts narrate <p> <item> --recording <file>
// --no-clean --no-convert` is the twin).
@@ -23,6 +24,7 @@ type View = {
id: string; post: string | null; author: string | null; handle: string | null; text: string;
excerpt: string[] | null; ranges: Range[] | null; excerptErrors: string[];
media: { i: number; src: string | null; kind: string | null; mute: boolean; seconds: number | null; audio: boolean }[];
+ off: { j: number; src: string | null; kind: string | null }[];
files: string[];
narration: { takes: { i: number; file: string; engine: string | null; voice: string | null; seconds: number | null }[]; picked: number | null; off: boolean };
token: string | null;
@@ -204,11 +206,11 @@ export default function PostItemInspector({ project, block = null }: InspectorPr
<div className="flex min-w-0 flex-col gap-2">
<div className="flex flex-col gap-1" data-post-media-list={view.media.length}>
<span className="micro">media</span>
- {view.media.length === 0 && view.files.length === 0 && <span className="text-muted">no attachment</span>}
+ {view.media.length === 0 && view.off.length === 0 && view.files.length === 0 && <span className="text-muted">no attachment</span>}
{view.media.map((m) => (
<div key={`${m.i}:${m.src}`} data-post-media={m.i} className="flex flex-wrap items-center gap-x-3 gap-y-0.5">
<label className="inline-flex min-w-0 items-center gap-1.5">
- <input type="checkbox" data-post-media-shown="" checked disabled={busy} onChange={() => void write("/api/report/post-item", { op: "set", patch: { media: { [m.i]: null } } }, `${m.src ?? `attachment ${m.i}`}: off the item (its file kept).`)} />
+ <input type="checkbox" data-post-media-shown="" checked disabled={busy} onChange={() => void write("/api/report/post-item/inspector", { op: "media-off", i: m.i }, `${m.src ?? `attachment ${m.i}`}: off (kept as it was set; on puts it back).`)} />
<span className="truncate font-mono text-[11.5px]" title={m.src ?? ""}>{m.src?.split("/").pop() ?? `attachment ${m.i}`}</span>
<span className="text-[11px] text-muted">{m.kind}{m.seconds ? ` ${m.seconds.toFixed(1)} s` : ""}</span>
</label>
@@ -220,6 +222,13 @@ export default function PostItemInspector({ project, block = null }: InspectorPr
)}
</div>
))}
+ {view.off.map((m) => (
+ <label key={`off:${m.j}:${m.src}`} data-post-media-off={m.j} className="inline-flex min-w-0 items-center gap-1.5 text-muted">
+ <input type="checkbox" data-post-media-off-shown="" checked={false} disabled={busy} onChange={() => void write("/api/report/post-item/inspector", { op: "media-show", j: m.j }, `${m.src?.split("/").pop() ?? `attachment ${m.j}`}: on again, as it was.`)} />
+ <span className="truncate font-mono text-[11.5px]" title={m.src ?? ""}>{m.src?.split("/").pop() ?? `attachment ${m.j}`}</span>
+ <span className="text-[11px]">off</span>
+ </label>
+ ))}
{view.files.map((f) => (
<label key={f} data-post-file={f} className="inline-flex min-w-0 items-center gap-1.5 text-muted">
<input type="checkbox" data-post-file-shown="" checked={false} disabled={busy} onChange={() => void write("/api/report/post-item/inspector", { op: "media-on", file: f }, `${f.split("/").pop()}: on the item.`)} />
diff --git a/umtool/docs/knobs.md b/umtool/docs/knobs.md
@@ -2288,6 +2288,6 @@ Every write lands in the **working draft** (`video.manifest.json`, never a take'
| **Provenance** (Cut tab › Project) | `provenance.siteOrigin` (an http(s) origin, no path), `provenance.channelSlug` (a slug; `check` blocks without it), `provenance.channel` (the display name); empty removes one. The **Link policy** per channel under it (its own writer, above) | `umtool provenance <p> [ls] \| set [--site-origin URL] [--channel-slug S] [--channel "…"] [--json]` | `GET/PUT /api/report/provenance` |
| **Insert a teaser or closing card** (Cut tab, beside the intro row; a teaser row's **Edit**) | a `teaser` entry: where (the end, id `close`; the start, `cold`; after an entry), its lines (the first its title; each a `break` — the end of its words, a second tier — and a `hold`, 0–4 s), its `beat` (0.4–2.5 s); the build's teaser rules refuse in their words. A row's Edit changes its lines and beat | `umtool timeline <p> teaser-insert [--at start\|end \| --after <id> \| --before <id>] [--id ID] [--beat S] --line "…" [--break "…"] [--hold S] [--line …] \| --lines-json …` · `umtool timeline <p> teaser <id> <patch>` | `GET/POST /api/report/teaser` (`op: insert \| set`) |
| **Ledger** (Cut tab › Project, a measure ledger) | a row's `date`, `scope` (a track), form, `value` (a number; a regime and its `event` on a regime track), `scopeBasis`, its source (`src`, `channel`, `video`, `cite`), `label`, `quote`, `entryId` and the schema's declared fields — added, changed (a new value redraws its `display`), removed; the ledger CLI's checks word for word | `umtool ledger <p> add\|set\|rm …` | `GET/POST /api/report/ledger` (`op: add \| set \| rm`) |
-| **Post item** (a post row's **Edit**) | its **excerpt**: select words of the post and **Add the selection** — snapped to whole words, merged, a span whose words come earlier too widened to where it was picked (`lib/report/excerptPick.mjs`), saved as `excerpt` (verbatim spans, read joined " … "); its **media** on/off (off removes the attachment from the item, its file kept and offered again) and a video's **sound** (`mute`); **Use my recording**: a sound file of your own read, trimmed and levelled, kept as `take-<n>.recorded-operator.wav` and picked | `umtool posts set-item <p> <item> excerpt='[…]' media.<i>=off media.add=<file> media.<i>.mute=on` · `umtool posts narrate <p> <item> --recording <file> --no-clean --no-convert` | `POST /api/report/post-item` (`op: set`), `GET/POST /api/report/post-item/inspector` (`op: media-on`), multipart `POST /api/report/post-narration` |
-| **Rumble cites** (Cut tab › Project) | each clip naming a Rumble URL-slug FOLDER the archive does not serve, with its embed id (L1's `siteVideoFor`, from the folder's `metadata.info.json`) and what the last link check said; **Use the published embed id** (a row) and **… for all N dead** write `siteVideo` (a citeUrl naming the folder moves with it), one write. No network | `umtool links <p> --embed-ids [--clips a,b] [--dry-run] [--json]` | `GET/POST /api/report/embed-ids` |
+| **Post item** (a post row's **Edit**) | its **excerpt**: select words of the post and **Add the selection** — snapped to whole words, merged, a span whose words come earlier too widened to where it was picked (`lib/report/excerptPick.mjs`), saved as `excerpt` (verbatim spans, read joined " … "); its **media** on/off (off keeps the attachment whole — crop, blur, trim, sound — in the item's `mediaOff`, which nothing draws or plays; on puts it back as it was) and a video's **sound** (`mute`); **Use my recording**: a sound file of your own read, trimmed and levelled, kept as `take-<n>.recorded-operator.wav` and picked | `umtool posts set-item <p> <item> excerpt='[…]' media.<i>.shown=off media-off.<j>.shown=on media.add=<file> media.<i>.mute=on` · `umtool posts narrate <p> <item> --recording <file> --no-clean --no-convert` | `POST /api/report/post-item` (`op: set`), `GET/POST /api/report/post-item/inspector` (`op: media-on \| media-off \| media-show`), multipart `POST /api/report/post-narration` |
+| **Rumble cites** (Cut tab › Project) | each clip naming a Rumble URL-slug FOLDER the archive does not serve, with its embed id (L1's `siteVideoFor`, from the folder's `metadata.info.json`) and what the last link check said; **Use the published embed id** (a row) and **… for all N dead** (every row only when no check has read any; after a check that found none dead it says so) write `siteVideo` (a citeUrl naming the folder moves with it), one write. No network | `umtool links <p> --embed-ids [--clips a,b] [--dry-run] [--json]` | `GET/POST /api/report/embed-ids` |
| **Still** (Play, beside Edit this clip; Cut tab › Project › Shots lists them) | the frame on screen — the clip's fetched window at the playhead's SOURCE second, one `ffmpeg -ss -frames:v 1` (not heavy) — as `shots/still-<clip>-<s>s.png`; nothing fetched, the cut not written | `umtool still <p> <clip> --at <source s> [--take <t>] [--json]` · `umtool still <p> ls` | `GET/POST /api/report/still-frame` |
diff --git a/umtool/e2e/inspector-post-item.spec.ts b/umtool/e2e/inspector-post-item.spec.ts
@@ -94,9 +94,12 @@ test("the excerpt, picked by selecting the post's words: a span whose words come
expect(takeText()).toBe(take);
});
-test("media on/off and a video's sound", async ({ page }) => {
+test("media on/off and a video's sound: off keeps the attachment whole (its crop), on puts it back as it was", async ({ page, request }) => {
await page.setViewportSize({ width: 1366, height: 768 });
const take = takeText();
+ // A crop set on the bench first: the knob off->on must not lose.
+ let r = await request.post("/api/report/post-item", { data: { project: P, op: "set", id: "p-3", patch: { media: { 0: { crop: [0.1, 0.1, 0.8, 0.8] } } } } });
+ expect(r.ok(), await r.text()).toBe(true);
await page.goto(urls.projectHref(P, { tab: "cut" }));
const row = page.locator('[data-entry="p-3"]');
await row.locator("[data-post-edit]").click();
@@ -107,17 +110,32 @@ test("media on/off and a video's sound", async ({ page }) => {
// Each box is the draft's state: a click asks for the change, the box shows it once it is written.
await panel.locator('[data-post-media="0"] [data-post-media-sound]').click();
await expect(panel.locator('[data-post-said="ok"]')).toContainText("Sound off.");
- expect(item("p-3").media?.[0]).toMatchObject({ src: "posts-media/postchan-x/3/3_1.mp4", mute: true });
+ expect(item("p-3").media?.[0]).toMatchObject({ src: "posts-media/postchan-x/3/3_1.mp4", mute: true, crop: [0.1, 0.1, 0.8, 0.8] });
await expect(panel.locator('[data-post-media="0"] [data-post-media-sound]')).not.toBeChecked();
- // The picture of the post it did not carry, put on; then the video taken off (its file kept, offered again).
+ // The picture of the post it never carried, put on.
await panel.locator('[data-post-file="posts-media/postchan-x/3/3_2.png"] [data-post-file-shown]').click();
await expect(panel.locator('[data-post-said="ok"]')).toContainText("3_2.png: on the item.");
expect(item("p-3").media?.map((m) => [m.src, m.kind])).toEqual([["posts-media/postchan-x/3/3_1.mp4", "video"], ["posts-media/postchan-x/3/3_2.png", "image"]]);
+ // A file the item carries already is not added twice.
+ r = await request.post("/api/report/post-item/inspector", { data: { project: P, op: "media-on", id: "p-3", file: "posts-media/postchan-x/3/3_2.png" } });
+ expect(r.status()).toBe(400);
+ expect((await r.json()).error).toContain("carries posts-media/postchan-x/3/3_2.png already");
+
+ // The video OFF: out of what plays, kept whole in mediaOff -- its crop, its sound off.
await panel.locator('[data-post-media="0"] [data-post-media-shown]').click();
- await expect(panel.locator('[data-post-said="ok"]')).toContainText("off the item");
+ await expect(panel.locator('[data-post-said="ok"]')).toContainText("off (kept as it was set");
expect(item("p-3").media?.map((m) => m.src)).toEqual(["posts-media/postchan-x/3/3_2.png"]);
- await expect(panel.locator('[data-post-file="posts-media/postchan-x/3/3_1.mp4"]')).toBeVisible();
+ expect((item("p-3") as Post & { mediaOff?: Record<string, unknown>[] }).mediaOff).toEqual([
+ { src: "posts-media/postchan-x/3/3_1.mp4", kind: "video", seconds: 4, width: 320, height: 180, audio: true, crop: [0.1, 0.1, 0.8, 0.8], mute: true },
+ ]);
+ await expect(panel.locator('[data-post-media-off="0"]')).toContainText("3_1.mp4");
+ await expect(panel.locator('[data-post-file="posts-media/postchan-x/3/3_1.mp4"]')).toHaveCount(0);
+ // ON again: back as it was, crop and all.
+ await panel.locator('[data-post-media-off="0"] [data-post-media-off-shown]').click();
+ await expect(panel.locator('[data-post-said="ok"]')).toContainText("on again, as it was");
+ expect(item("p-3").media?.[1]).toEqual({ src: "posts-media/postchan-x/3/3_1.mp4", kind: "video", seconds: 4, width: 320, height: 180, audio: true, crop: [0.1, 0.1, 0.8, 0.8], mute: true });
+ expect("mediaOff" in item("p-3")).toBe(false);
expect(existsSync(path.join(DIR, "posts-media", "postchan-x", "3", "3_1.mp4"))).toBe(true);
expect(takeText()).toBe(take);
});
diff --git a/umtool/lib/report/inspectorEdits.test.mjs b/umtool/lib/report/inspectorEdits.test.mjs
@@ -253,3 +253,27 @@ test("umtool links --embed-ids: dry run, then the fix; no network", async () =>
r = await run(linksCommand, [p.id, "--embed-ids", "--clips", "c01"]);
assert.equal(r.code, 1);
});
+
+test("an attachment switched off keeps its knobs in mediaOff, and on puts it back as it was", async () => {
+ const { updatePostItem } = await import("./manifest.mjs");
+ const { validatePostItem } = await import("umtool-report-to-video/post-item");
+ const m = MANIFEST();
+ const vid = { src: "posts-media/x/3/3_1.mp4", kind: "video", seconds: 4, width: 320, height: 180, audio: true };
+ const pic = { src: "posts-media/x/3/3_2.png", kind: "image", width: 320, height: 180 };
+ m.timeline.push({ type: "post", id: "p-3", post: "x/3", platform: "x", author: "A", handle: "a", date: "2026-10-30T12:00:00.000Z", text: "words", media: [vid, pic] });
+ const p = await project(m);
+ await updatePostItem(p.dir, "p-3", { media: { 0: { crop: [0.1, 0.1, 0.8, 0.8], mute: true, start: 1 } } });
+ let r = await updatePostItem(p.dir, "p-3", { mediaHide: [0] });
+ assert.deepEqual(r.entry.media, [pic]);
+ assert.deepEqual(r.entry.mediaOff, [{ ...vid, crop: [0.1, 0.1, 0.8, 0.8], mute: true, start: 1 }]);
+ assert.deepEqual(validatePostItem(r.entry), []);
+ r = await updatePostItem(p.dir, "p-3", { mediaShow: [0] });
+ assert.deepEqual(r.entry.media, [pic, { ...vid, crop: [0.1, 0.1, 0.8, 0.8], mute: true, start: 1 }]);
+ assert.equal("mediaOff" in r.entry, false);
+ await assert.rejects(updatePostItem(p.dir, "p-3", { mediaShow: [0] }), /no attachment switched off at 0/);
+ await assert.rejects(updatePostItem(p.dir, "p-3", { mediaHide: [5] }), /shows no attachment 5/);
+ await assert.rejects(updatePostItem(p.dir, "p-3", { mediaHide: [0], hold: 3 }), /go alone/);
+ // The build's check: a bad switched-off attachment is refused as a shown one is.
+ assert.match(validatePostItem({ ...r.entry, mediaOff: [{ src: 7 }] }).join(" "), /mediaOff\[0\]/);
+ assert.match(validatePostItem({ ...r.entry, mediaOff: [] }).join(" "), /mediaOff must be a list/);
+});
diff --git a/umtool/lib/report/manifest.mjs b/umtool/lib/report/manifest.mjs
@@ -2733,8 +2733,12 @@ const POST_REF_FIELDS = Object.freeze(["id", "author", "handle", "badge", "date"
export async function updatePostItem(dir, id, patch, { token = null } = {}) {
if (!isObj(patch)) throw new Error("a post item's patch is an object");
for (const k of Object.keys(patch)) {
- if (!["media", "mediaAdd", "quoted", "parents", "links", "linksAdd"].includes(k) && !POST_ITEM_KNOBS.includes(k)) throw new Error(`${k} is not a post item knob (${[...POST_ITEM_KNOBS, "media", "mediaAdd", "quoted", "parents", "links", "linksAdd"].join(", ")})`);
+ if (!["media", "mediaAdd", "mediaHide", "mediaShow", "quoted", "parents", "links", "linksAdd"].includes(k) && !POST_ITEM_KNOBS.includes(k)) throw new Error(`${k} is not a post item knob (${[...POST_ITEM_KNOBS, "media", "mediaAdd", "mediaHide", "mediaShow", "quoted", "parents", "links", "linksAdd"].join(", ")})`);
}
+ // An attachment SWITCHED OFF and back ON (`mediaHide: [i]` / `mediaShow: [j]`, the inspector's media on/off): it moves
+ // whole between `media` and `mediaOff` (post-item.mjs), its knobs kept -- alone in its write, so no index moves under it.
+ const toggles = ["mediaHide", "mediaShow"].filter((k) => k in patch);
+ if (toggles.length && Object.keys(patch).length !== toggles.length) throw new Error("mediaHide / mediaShow go alone in a write");
return structural(dir, "post-item", token, (m) => {
const i = entryIndex(m.timeline, id);
const e = m.timeline[i];
@@ -2806,6 +2810,24 @@ export async function updatePostItem(dir, id, patch, { token = null } = {}) {
if (!Array.isArray(patch.mediaAdd)) throw new Error("mediaAdd is a list of attachments");
e.media = [...(Array.isArray(e.media) ? e.media : []), ...patch.mediaAdd];
}
+ if (toggles.length) {
+ const idx = (v, k) => {
+ if (!Array.isArray(v) || !v.every((n) => Number.isInteger(n))) throw new Error(`${k} is a list of indices`);
+ return new Set(v);
+ };
+ const on = Array.isArray(e.media) ? e.media : [];
+ const off = Array.isArray(e.mediaOff) ? e.mediaOff : [];
+ const hide = patch.mediaHide !== undefined ? idx(patch.mediaHide, "mediaHide") : new Set();
+ const show = patch.mediaShow !== undefined ? idx(patch.mediaShow, "mediaShow") : new Set();
+ for (const n of hide) if (!isObj(on[n])) throw new Error(`${id} shows no attachment ${n}${on.length ? ` (0–${on.length - 1})` : ""}`);
+ for (const n of show) if (!isObj(off[n])) throw new Error(`${id} has no attachment switched off at ${n}${off.length ? ` (0–${off.length - 1})` : ""}`);
+ const media = [...on.filter((_, n) => !hide.has(n)), ...off.filter((_, n) => show.has(n))];
+ const mediaOff = [...off.filter((_, n) => !show.has(n)), ...on.filter((_, n) => hide.has(n))];
+ if (media.length) e.media = media;
+ else delete e.media;
+ if (mediaOff.length) e.mediaOff = mediaOff;
+ else delete e.mediaOff;
+ }
// A context post's paraphrase (`quoted`, `parents[i]`): its text is never touched. A hand-made ref (`ref`), its
// attachments (`media`) and the words read off its picture (`transcript`) are set here too.
const setContext = (ref, cp, what) => {
diff --git a/umtool/lib/report/postsCli.mjs b/umtool/lib/report/postsCli.mjs
@@ -110,6 +110,7 @@ export const POSTS_USAGE = [
" [media.<i>.start=<s>] [media.<i>.end=<s>] [media.<i>.mute=on|off] [media.<i>.crop=x,y,w,h|off]",
" [media.<i>.push=on|off] [media.<i>.trim=off] [media.<i>.enter=post|item] [quoted.paraphrase=\"…\"|off]",
" [media.<i>.blur=on|off] [media.<i>.blur.strength=1–10] [media.<i>.blur.label=\"…\"|off]",
+ " [media.<i>.shown=off] [media-off.<j>.shown=on] an attachment switched off, kept whole (mediaOff), and on again",
" [media.<i>.blur.boxes=x,y,w,h;…|off] [media.<i>.blur.band=below:<f>|above:<f>|between:<a>,<b>[:left:<f>|:right:<f>]|off]",
" [media.<i>.blur.style=blur|black|pixelate|off] [media.<i>.censor=<edge>:<f>[:<style>][:<strength>]|off]",
" [parent.<i>.paraphrase=\"…\"|off] [narration.rate=0.8–1.5|narration.<mix knob>=…]",
@@ -1018,6 +1019,14 @@ export function postItemPatchOf(pairs) {
}
// AN ATTACHMENT FROM A PROJECT FILE (operator, 4 Nov: "this needs to include the cat video"): measured when it goes in.
else if (k === "media.add") (out.mediaAdd ??= []).push(fileArg(raw, k));
+ // An attachment switched OFF, kept whole (mediaOff: its knobs kept), and back ON (the inspector's media on/off).
+ else if (/^media\.\d+\.shown$/.test(k)) {
+ if (!OFF.has(v)) throw new CliError(`${k}= takes off (on: media-off.<j>.shown=on)`);
+ (out.mediaHide ??= []).push(Number(k.split(".")[1]));
+ } else if (/^media-off\.\d+\.shown$/.test(k)) {
+ if (v !== "on") throw new CliError(`${k}= takes on (the attachment switched off at <j> shown again, as it was)`);
+ (out.mediaShow ??= []).push(Number(k.split(".")[1]));
+ }
else if (/^media\.\d+$/.test(k)) {
if (!OFF.has(v)) throw new CliError(`${k}= takes off (the attachment removed)`);
((out.media ??= {})[k.split(".")[1]] = null);
diff --git a/umtool/report-to-video/post-item.mjs b/umtool/report-to-video/post-item.mjs
@@ -705,6 +705,16 @@ export function validatePostItem(e) {
e.media.forEach((m, i) => errors.push(...mediaErrors(m, `${w}.media[${i}]`)));
}
}
+ // ITS ATTACHMENTS SWITCHED OFF (umtool redesign L6, the inspector's media on/off): each kept whole -- its crop,
+ // blur, trim, sound -- in `mediaOff`, which nothing draws or plays (only `media` is read), so "on" puts it back as
+ // it was. Checked as an attachment is.
+ if (e.mediaOff !== undefined) {
+ if (!Array.isArray(e.mediaOff) || !e.mediaOff.length) errors.push(`${w}.mediaOff must be a list of attachments switched off (absent: none)`);
+ else {
+ if (e.mediaOff.length > POST_MEDIA_MAX) errors.push(`${w}.mediaOff: at most ${POST_MEDIA_MAX} attachments`);
+ e.mediaOff.forEach((m, i) => errors.push(...mediaErrors(m, `${w}.mediaOff[${i}]`)));
+ }
+ }
// Its narration (post-narration.mjs): the script, the takes, the mix's knobs.
errors.push(...validatePostNarration(e));
// Its effects (word-zoom.mjs): a word zoomed on as it is read.