Claude commited on
Commit
93e4afe
·
1 Parent(s): 0c2c651

editor: bulk include toggles that drive every section at once

Browse files

Adds a "Apply to all sections" bar between the toolbar and the
document header. One checkbox per include key — Whole section,
Scene description, Alt-text, On-screen text, Transcript, Audio.
Three behaviours:

* Standard tri-state. The bar reflects the union of per-section
state on page load: all-checked, all-unchecked, or indeterminate
when sections disagree.

* Bulk → per-section. Toggling a bulk box sets every matching
per-section checkbox to the bulk's new state and dispatches a
synthesised 'change' event on each, so the existing per-section
sync (data-include, data-included, data-include-alt-text) fires
for free. No duplicated wiring.

* Per-section → bulk. Any individual checkbox change re-runs the
union calculation so the bulk indicator stays accurate. Applies
after Load JSON too (applyState calls syncBulkToggles when it
finishes mutating per-section state).

A bulk box for a key with zero matching per-section checkboxes
(e.g. Audio when no segment carries an audio asset) renders
disabled rather than misleadingly empty.

The bar lives inside [data-editor] so buildFinalHTML strips it
from the published guide along with the rest of the editor chrome.

https://claude.ai/code/session_01EM8jiYxdVFy1w3LeJ9GBJg

Files changed (2) hide show
  1. app/templates/review.html +107 -0
  2. tests/test_html_gen.py +15 -0
app/templates/review.html CHANGED
@@ -244,6 +244,27 @@
244
  margin-top: -0.25rem;
245
  margin-bottom: var(--space-md);
246
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
247
  </style>
248
  </head>
249
  <body>
@@ -264,6 +285,20 @@
264
  <span class="vgm-status" role="status" aria-live="polite"></span>
265
  </div>
266
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
267
  <header class="doc-header" role="banner">
268
  <p class="doc-header__eyebrow" contenteditable="true" data-bind="eyebrow" spellcheck="true">{{ module or eyebrow }}</p>
269
  <h1 contenteditable="true" data-bind="title" spellcheck="true">{{ title }}</h1>
@@ -718,6 +753,9 @@
718
  if (box) box.checked = include;
719
  }
720
  });
 
 
 
721
  }
722
 
723
  function cssEscape(s) {
@@ -1150,7 +1188,76 @@
1150
  section.querySelectorAll('[data-list="math_equations"] [data-list-row]').forEach(bindMathRow);
1151
  });
1152
  syncTitle();
 
1153
  })();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1154
  </script>
1155
  </body>
1156
  </html>
 
244
  margin-top: -0.25rem;
245
  margin-bottom: var(--space-md);
246
  }
247
+ .vgm-bulk {
248
+ background: var(--color-accent-light);
249
+ border-bottom: 1px solid var(--color-border);
250
+ padding: 0.55rem 1rem;
251
+ display: flex;
252
+ flex-wrap: wrap;
253
+ gap: 0.4rem 1.1rem;
254
+ align-items: center;
255
+ font-family: var(--font-body);
256
+ font-size: 0.9rem;
257
+ color: var(--color-accent-dark);
258
+ }
259
+ .vgm-bulk__label { margin-right: 0.3rem; font-weight: 700; }
260
+ .vgm-bulk label {
261
+ display: inline-flex;
262
+ align-items: center;
263
+ gap: 0.3rem;
264
+ cursor: pointer;
265
+ font-weight: 500;
266
+ }
267
+ .vgm-bulk input[type="checkbox"] { width: 1rem; height: 1rem; }
268
  </style>
269
  </head>
270
  <body>
 
285
  <span class="vgm-status" role="status" aria-live="polite"></span>
286
  </div>
287
 
288
+ {# Bulk toggles — flip every per-section include checkbox of a given
289
+ key in one click. Defaults: the boxes reflect whatever the
290
+ per-section defaults are after page load; mixed sections show the
291
+ box as indeterminate. Editor-only chrome, stripped from output. #}
292
+ <div class="vgm-bulk" data-editor role="group" aria-label="Apply to every section">
293
+ <strong class="vgm-bulk__label">Apply to all sections:</strong>
294
+ <label><input type="checkbox" data-bulk-toggle="include"> <span>Whole section</span></label>
295
+ <label><input type="checkbox" data-bulk-toggle="description"> <span>Scene description</span></label>
296
+ <label><input type="checkbox" data-bulk-toggle="alt_text"> <span>Alt-text</span></label>
297
+ <label><input type="checkbox" data-bulk-toggle="on_screen_text"> <span>On-screen text</span></label>
298
+ <label><input type="checkbox" data-bulk-toggle="transcript"> <span>Transcript</span></label>
299
+ <label><input type="checkbox" data-bulk-toggle="audio"> <span>Audio</span></label>
300
+ </div>
301
+
302
  <header class="doc-header" role="banner">
303
  <p class="doc-header__eyebrow" contenteditable="true" data-bind="eyebrow" spellcheck="true">{{ module or eyebrow }}</p>
304
  <h1 contenteditable="true" data-bind="title" spellcheck="true">{{ title }}</h1>
 
753
  if (box) box.checked = include;
754
  }
755
  });
756
+ // Per-section state just changed under our feet — refresh the
757
+ // bulk-toggle indicators so they reflect the loaded JSON.
758
+ if (typeof syncBulkToggles === 'function') syncBulkToggles();
759
  }
760
 
761
  function cssEscape(s) {
 
1188
  section.querySelectorAll('[data-list="math_equations"] [data-list-row]').forEach(bindMathRow);
1189
  });
1190
  syncTitle();
1191
+ bindBulkToggles();
1192
  })();
1193
+
1194
+ // Bulk-toggle helpers live outside the IIFE so syncBulkToggles can be
1195
+ // re-invoked from applyState after a Load-JSON round-trip without
1196
+ // re-running the whole init.
1197
+ function getPerSectionBoxesFor(key) {
1198
+ // The "Whole section" box uses data-bind="include"; everything else
1199
+ // is a data-element-toggle. One helper unifies both for the bulk
1200
+ // sync so the same checkbox-event plumbing works for both.
1201
+ if (key === 'include') {
1202
+ return Array.from(document.querySelectorAll('section.section input[data-bind="include"]'));
1203
+ }
1204
+ return Array.from(document.querySelectorAll(
1205
+ `section.section input[data-element-toggle="${key}"]`,
1206
+ ));
1207
+ }
1208
+
1209
+ function syncBulkToggles() {
1210
+ document.querySelectorAll('[data-bulk-toggle]').forEach(bulk => {
1211
+ const key = bulk.getAttribute('data-bulk-toggle');
1212
+ const boxes = getPerSectionBoxesFor(key);
1213
+ if (!boxes.length) {
1214
+ bulk.disabled = true;
1215
+ bulk.indeterminate = false;
1216
+ bulk.checked = false;
1217
+ return;
1218
+ }
1219
+ bulk.disabled = false;
1220
+ const onCount = boxes.filter(b => b.checked).length;
1221
+ if (onCount === 0) {
1222
+ bulk.indeterminate = false;
1223
+ bulk.checked = false;
1224
+ } else if (onCount === boxes.length) {
1225
+ bulk.indeterminate = false;
1226
+ bulk.checked = true;
1227
+ } else {
1228
+ bulk.indeterminate = true;
1229
+ bulk.checked = false;
1230
+ }
1231
+ });
1232
+ }
1233
+
1234
+ function bindBulkToggles() {
1235
+ // Bulk → per-section: set every matching box to the bulk's new
1236
+ // state, dispatching 'change' so the existing per-section sync
1237
+ // logic (data-include attribute, data-included on the section,
1238
+ // data-include-alt-text on the section, etc.) fires for free.
1239
+ document.querySelectorAll('[data-bulk-toggle]').forEach(bulk => {
1240
+ bulk.addEventListener('change', () => {
1241
+ const key = bulk.getAttribute('data-bulk-toggle');
1242
+ const desired = bulk.checked;
1243
+ getPerSectionBoxesFor(key).forEach(box => {
1244
+ if (box.checked !== desired) {
1245
+ box.checked = desired;
1246
+ box.dispatchEvent(new Event('change', { bubbles: true }));
1247
+ }
1248
+ });
1249
+ });
1250
+ });
1251
+ // Per-section → bulk: any individual change updates the bulk
1252
+ // checkbox state (checked / unchecked / indeterminate).
1253
+ const keys = ['include', 'description', 'alt_text', 'on_screen_text', 'transcript', 'audio'];
1254
+ keys.forEach(key => {
1255
+ getPerSectionBoxesFor(key).forEach(box => {
1256
+ box.addEventListener('change', syncBulkToggles);
1257
+ });
1258
+ });
1259
+ syncBulkToggles();
1260
+ }
1261
  </script>
1262
  </body>
1263
  </html>
tests/test_html_gen.py CHANGED
@@ -347,6 +347,21 @@ def test_render_guide_falls_back_to_alt_when_no_description(tmp_path):
347
  assert "Alt-text needs author review." in html
348
 
349
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
350
  def test_render_review_transcript_uses_details_summary(tmp_path):
351
  """Per UX feedback: narration sections are now collapsible (rendered
352
  as a <details> with summary 'Transcript'), default closed, and
 
347
  assert "Alt-text needs author review." in html
348
 
349
 
350
+ def test_render_review_emits_bulk_toggle_bar(tmp_path):
351
+ """Per UX feedback: a 'Apply to all sections' bar exposes a bulk
352
+ checkbox per element type so the editor can hide/show alt-text,
353
+ transcript, etc. across the whole document in one click instead
354
+ of toggling N per-segment checkboxes."""
355
+ img = tmp_path / "scene_0000.jpg"
356
+ _make_image(img)
357
+ segments = build_segments([SceneFrame(0, 0.0, 5.0, img)], [""], [""], inline_images=True)
358
+ html = render_review("Review Me", segments, lang="en")
359
+ assert 'class="vgm-bulk"' in html
360
+ # One bulk toggle per element-include checkbox plus the whole-section one.
361
+ for key in ("include", "description", "alt_text", "on_screen_text", "transcript", "audio"):
362
+ assert f'data-bulk-toggle="{key}"' in html, f"missing bulk toggle for {key}"
363
+
364
+
365
  def test_render_review_transcript_uses_details_summary(tmp_path):
366
  """Per UX feedback: narration sections are now collapsible (rendered
367
  as a <details> with summary 'Transcript'), default closed, and