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:
37
src/model.js
37
src/model.js
@@ -4,6 +4,7 @@
|
||||
// Document:
|
||||
// { schemaVersion: 1,
|
||||
// meta: { owner, title, lastUpdated: 'YYYY-MM-DD' },
|
||||
// header?: { fields: [HeaderField] }, // running print header; absent = defaults
|
||||
// sections: [ Section ] }
|
||||
//
|
||||
// Section (ordered). `kind` decides which body it has:
|
||||
@@ -17,6 +18,11 @@
|
||||
// fields: [{ label, value, secret?: boolean }], notes?: string }
|
||||
// Item: { id, text, status: 'open'|'done'|'tbd', detail?: string }
|
||||
//
|
||||
// HeaderField: { kind: 'text'|'lastUpdated', text, align?: 'left'|'right' }
|
||||
// kind 'text' prints `text`; 'lastUpdated' prints `text` (a label) + meta.lastUpdated.
|
||||
// At most one field is 'left' and one 'right'. Printed order: the left field,
|
||||
// then unaligned fields in list order, then the right field.
|
||||
//
|
||||
// Ids are unique across the whole document. `secret` fields are masked
|
||||
// in the UI and optionally in print output.
|
||||
|
||||
@@ -24,6 +30,16 @@ export const SCHEMA_VERSION = 1;
|
||||
export const SECTION_KINDS = ['text', 'records', 'steps', 'checklist'];
|
||||
export const RECORD_STATUSES = ['ok', 'tbd'];
|
||||
export const ITEM_STATUSES = ['open', 'done', 'tbd'];
|
||||
export const HEADER_KINDS = ['text', 'lastUpdated'];
|
||||
export const HEADER_ALIGNS = ['left', 'right'];
|
||||
|
||||
// What the header is when the document doesn't define one.
|
||||
export function defaultHeaderFields(doc) {
|
||||
return [
|
||||
{ kind: 'text', text: (doc.meta && doc.meta.title) || 'Final Wishes', align: 'left' },
|
||||
{ kind: 'lastUpdated', text: 'Last update: ', align: 'right' },
|
||||
];
|
||||
}
|
||||
|
||||
const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
|
||||
const isStr = (v) => typeof v === 'string';
|
||||
@@ -57,6 +73,27 @@ export function validate(doc) {
|
||||
if (!DATE_RE.test(doc.meta.lastUpdated ?? '')) errs.push('meta.lastUpdated must be YYYY-MM-DD');
|
||||
}
|
||||
|
||||
if (doc.header !== undefined) {
|
||||
if (!isObj(doc.header) || !Array.isArray(doc.header.fields)) errs.push('header.fields must be an array');
|
||||
else {
|
||||
let left = 0;
|
||||
let right = 0;
|
||||
doc.header.fields.forEach((f, i) => {
|
||||
const w = `header.fields[${i}]`;
|
||||
if (!isObj(f)) return errs.push(`${w}: must be an object`);
|
||||
if (!HEADER_KINDS.includes(f.kind)) errs.push(`${w}: unknown kind "${f.kind}"`);
|
||||
if (!isStr(f.text)) errs.push(`${w}: text must be a string`);
|
||||
if (f.align !== undefined) {
|
||||
if (!HEADER_ALIGNS.includes(f.align)) errs.push(`${w}: bad align "${f.align}"`);
|
||||
else if (f.align === 'left') left++;
|
||||
else right++;
|
||||
}
|
||||
});
|
||||
if (left > 1) errs.push('header: only one field can be left aligned');
|
||||
if (right > 1) errs.push('header: only one field can be right aligned');
|
||||
}
|
||||
}
|
||||
|
||||
if (!Array.isArray(doc.sections)) return [...errs, 'sections must be an array'];
|
||||
|
||||
doc.sections.forEach((s, i) => {
|
||||
|
||||
Reference in New Issue
Block a user