Add configurable running print header

The line printed on every page is now a header stored in the document as
header.fields: any number of Text / Last updated fields, each optionally
aligned left or right (at most one of each). Printed order is left,
unaligned, right. Edited from a Print header panel with live preview;
documents without a header use the previous title/last-update default.
The header is a repeating table header so it sits in flow and cannot
overlap body text, replacing the fixed-position footer.

Also add "Open your existing Final Wishes file" to the start screen so
data in an older encrypted file can be carried into a newer build.

Closes #9

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-09 13:23:31 -05:00
parent e4a64eea5d
commit 70c384cdcb
9 changed files with 238 additions and 21 deletions

View File

@@ -1,3 +1,5 @@
import { defaultHeaderFields } from './model.js';
// Pure editing operations on the document model. No DOM; tested in Node.
// build.js strips `export` when bundling.
@@ -73,3 +75,30 @@ export function backupName(date) {
const p = (n) => String(n).padStart(2, '0');
return `final-wishes-${date.getFullYear()}${p(date.getMonth() + 1)}${p(date.getDate())}.html`;
}
// ---- print header ----
// Materialize the default header into the document the first time it is edited.
export function ensureHeader(doc) {
if (!doc.header) doc.header = { fields: defaultHeaderFields(doc) };
return doc.header;
}
export function addHeaderField(doc) {
const f = { kind: 'text', text: 'New text' };
ensureHeader(doc).fields.push(f);
return f;
}
// Alignments ('left' / 'right') already used by fields other than `field`.
export function takenAligns(fields, field) {
return new Set(fields.filter((f) => f !== field && f.align).map((f) => f.align));
}
// Set a field's alignment ('left' | 'right' | '' for none). Refuses a second
// left or right field; returns whether it was applied.
export function setAlign(fields, field, align) {
if (align && takenAligns(fields, field).has(align)) return false;
if (align) field.align = align;
else delete field.align;
return true;
}