Add sub-tabs to records sections (Refs #18)

Records sections can be split into user-named sub-tabs with a General
catch-all. Records and visual sequences move between tabs via a Sub-tab
drop-down; up/down, collapse all and print work per tab.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-21 19:32:05 -05:00
parent 37bdb62baf
commit d7dc098e79
9 changed files with 411 additions and 24 deletions

View File

@@ -54,7 +54,7 @@ Git-ignored on purpose: `*.pdf`, `data/` (plaintext working copies with real sec
**Document model** (`src/model.js`, `schemaVersion 1`): `meta {owner, title, lastUpdated}`; optional `header {fields}` for the running print header; `sections`. Section kinds:
- `text` (a `body`, plus optional `sequences`)
- `records` (records with labeled `fields`; a field is text or an image)
- `records` (records with labeled `fields`; a field is text or an image). It can optionally have sub-tabs: `subsections: [{id, title}]`, a `generalTitle` for the catch-all first tab (default "General"), and a `subsection` id on each record or sequence. No `subsection`, or one that matches no tab, means General.
- `steps` and `checklist` (ordered `items`)
A **visual sequence** (`kind: 'sequence'`, numbered `frames` of image + text with a layout of right / under / none) is an entry in the same ordered list as a section's records or items, or in a text section's `sequences` array. It is not a record or an item: no step number and no tick box. Ids are unique across the whole document. `secret` flags exist on fields and frames. Validation is `validate()` / `assertValid()`; the save path refuses an invalid document.
@@ -62,6 +62,7 @@ A **visual sequence** (`kind: 'sequence'`, numbered `frames` of image + text wit
**UI** (`src/app.js`, a single IIFE): state lives in one `state` object (including `collapsed`, the folded record ids). Edits mutate `state.doc` in place and then call `markDirty()` or `changed(record)` (which also stamps `updated` and `meta.lastUpdated`). `render()` rebuilds the page. `changed` clears `state.status`, so set the status afterwards.
- **Editing and Cancel:** edit mode is global. **Cancel** reverts the section (or the print header) on screen to a deep-copy baseline taken at open and at each save, then leaves edit mode.
- **Collapsing records:** in view mode each record card has a Collapse/Expand button, and records sections have "Collapse all" / "Expand all". Folded ids live in `state.collapsed` (a `Set`, view-only, never saved, cleared on reload). A collapsed card shows only its title and gets ↑/↓ buttons that reorder it via `move()` and `changed()`, so moving stamps `updated` and marks the document dirty.
- **Sub-tabs:** `ops.js` holds the pure logic (`tabsOf`, `entriesInTab`, `moveToTab`, `moveWithin`, `removeSubsection`, `printGroups`). The records stay in one array, and the tab bar filters them. The shown tab is in `state.tabs` (not saved). Up/down moves a record past its nearest neighbour in the same tab. Deleting a tab sends its records to General. Print writes one sub-heading per non-empty tab.
- **Images:** drag and drop, clipboard paste and file picker all feed `importFiles()`. Files are sniffed by their first bytes, downscaled to at most 1600 px and re-encoded, which strips metadata, and stored as data URLs with a limit of about 3 MB each.
**Save.** Uses the File System Access API (`showSaveFilePicker`, handle reused) where available, otherwise a Blob download. `assemble()` rebuilds the full HTML from the page's own CSS and JS plus a fresh encrypted payload. "Backup copy" downloads `final-wishes-YYYYMMDD.html`.
@@ -100,7 +101,7 @@ No database. The document is a JSON object, encrypted and embedded in the HTML f
- **Bundle scope:** all modules share one scope after the build. Don't add a top-level name that already exists elsewhere, and don't use `import`/`export` forms other than line-start `import ` and `export `, because the stripper is regex-based.
- **`h()` children:** it flattens with `flat(Infinity)`, but `replaceChildren` needs an explicit `.flat()`. Use `textContent`, never `innerHTML`.
- **Dirty and status:** `markDirty()` clears the status text, so set `state.status` after calling `changed()`.
- **Older builds:** files saved with images or visual sequences can't be opened by builds that predate them. The upgrade path only goes forward.
- **Older builds:** files saved with images, visual sequences or sub-tabs can't be opened by builds that predate them. The upgrade path only goes forward.
- **Blob size:** images are embedded in the encrypted payload and make the file bigger and saves slower.
- **Skipped test:** one test in `test/model.test.js` is skipped unless the gitignored `data/seed.json` exists.
- **Browser coverage:** features were verified in headless Chromium only; Firefox and Safari drop and paste are untested.