Files
final-wishes/src/print.js
Eric Bell 70c384cdcb 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>
2026-11-09 13:23:31 -05:00

44 lines
1.5 KiB
JavaScript

import { defaultHeaderFields } from './model.js';
// Pure helpers for the printed document. No DOM; tested in Node.
// build.js strips `export` when bundling.
// What to print for a field. Secrets are either shown or withheld; an empty
// secret is always "(not set)" so a blank is never mistaken for a hidden value.
export function displayValue(field, includeSecrets) {
if (field.secret) {
if (!field.value) return '(not set)';
return includeSecrets ? field.value : '[withheld]';
}
return field.value || '(blank)';
}
export function headerFields(doc) {
return doc.header ? doc.header.fields : defaultHeaderFields(doc);
}
export function headerText(field, doc) {
return field.kind === 'lastUpdated' ? (field.text || '') + doc.meta.lastUpdated : field.text;
}
// { left, middle: [..], right } in printed order: the left-aligned field, then
// unaligned fields in list order, then the right-aligned field. Empty text is dropped.
export function headerLayout(doc) {
const fields = headerFields(doc);
const left = fields.find((f) => f.align === 'left');
const right = fields.find((f) => f.align === 'right');
return {
left: left ? headerText(left, doc) : '',
middle: fields.filter((f) => f.align !== 'left' && f.align !== 'right').map((f) => headerText(f, doc)).filter(Boolean),
right: right ? headerText(right, doc) : '',
};
}
export function countSecrets(doc) {
let n = 0;
for (const s of doc.sections) {
for (const r of s.records || []) for (const f of r.fields) if (f.secret && f.value) n++;
}
return n;
}