Add lawyer's view: a third field level and print mode (Fixes #29)

Fields and steps are Normal, Lawyer or Secret. Lawyer is stored as
secret: true plus lawyer: true, so older builds treat it as a plain secret.
Print offers masked, lawyer and complete views.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-30 20:15:47 -05:00
parent edb85d4f64
commit eeba5d00db
10 changed files with 218 additions and 51 deletions

View File

@@ -583,22 +583,28 @@
return zone;
}
// Normal / Lawyer / Secret chooser for a field or step (replaces the old "secret" checkbox).
const LEVELS = [['normal', 'Normal'], ['lawyer', 'Lawyer'], ['secret', 'Secret']];
function levelSelect(x, label, onChange) {
const sel = h('select', { 'aria-label': label, onchange: () => { setLevel(x, sel.value); onChange(); } },
LEVELS.map(([v, t]) => h('option', { value: v, selected: levelOf(x) === v }, t)));
return h('label', { class: 'check' }, sel);
}
function editImageField(r, f, i) {
const secret = h('input', { type: 'checkbox', checked: !!f.secret, 'aria-label': 'Secret',
onchange: () => { f.secret = secret.checked || undefined; if (!f.secret) delete f.secret; changed(r); } });
const secret = levelSelect(f, 'Visibility of ' + (f.label || 'image field'), () => changed(r));
const zone = imageZone(f, 'value', f.label, { 'data-field': String(i) }, (files) => importFiles(r, files, { replace: f }), () => changed(r));
return h('div', { class: 'field imagefield' },
h('div', { class: 'row' }, input(f, 'label', { label: 'Field label' }, r), h('label', { class: 'check' }, secret, ' secret'), rowTools(r.fields, i, 'image field', r)),
h('div', { class: 'row' }, input(f, 'label', { label: 'Field label' }, r), secret, rowTools(r.fields, i, 'image field', r)),
zone);
}
function editField(r, f, i) {
if (f.kind === 'image') return editImageField(r, f, i);
const secret = h('input', { type: 'checkbox', checked: !!f.secret, 'aria-label': 'Secret',
onchange: () => { f.secret = secret.checked || undefined; if (!f.secret) delete f.secret; changed(r); } });
const secret = levelSelect(f, 'Visibility of ' + (f.label || 'field'), () => changed(r));
return h('div', { class: 'row field' },
input(f, 'label', { label: 'Field label' }, r), input(f, 'value', { label: 'Field value' }, r),
h('label', { class: 'check' }, secret, ' secret'), rowTools(r.fields, i, 'field', r));
secret, rowTools(r.fields, i, 'field', r));
}
// "Sub-tab: [select]" for a record or sequence; changing it moves the entry to that tab.
@@ -684,14 +690,13 @@
}
function editFrame(q, f, k) {
const secret = h('input', { type: 'checkbox', checked: !!f.secret, 'aria-label': 'Secret step',
onchange: () => { f.secret = secret.checked || undefined; if (!f.secret) delete f.secret; changed(q); } });
const secret = levelSelect(f, 'Visibility of step ' + (k + 1), () => changed(q));
const stop = h('input', { type: 'checkbox', checked: !!f.stop, 'aria-label': 'Stop here, step ' + (k + 1),
onchange: () => { f.stop = stop.checked || undefined; if (!f.stop) delete f.stop; changed(q); } });
const layout = h('select', { 'aria-label': 'Text position for step ' + (k + 1), onchange: () => { f.layout = layout.value; changed(q); render(); } },
LAYOUT_LABELS.map(([v, t]) => h('option', { value: v, selected: f.layout === v }, t)));
return h('div', { class: 'field imagefield frameedit' },
h('div', { class: 'row' }, h('strong', {}, 'Step ' + (k + 1)), layout, h('label', { class: 'check' }, secret, ' secret'), rowTools(q.frames, k, 'step', q)),
h('div', { class: 'row' }, h('strong', {}, 'Step ' + (k + 1)), layout, secret, rowTools(q.frames, k, 'step', q)),
imageZone(f, 'image', q.title + ', step ' + (k + 1), { 'data-frame': String(k) },
(files) => importFiles(q, files, { key: 'image', replace: f, add: addFrameFrom(q) }), () => { if (!f.image) delete f.marks; changed(q); }),
f.image ? h('div', { class: 'row' }, btn('Mark up picture\u2026', () => openAnnotator(q, f), 'small', { 'aria-label': 'Mark up the picture for step ' + (k + 1) }),
@@ -789,37 +794,37 @@
const box = (status) => h('span', { class: 'cb ' + status, 'aria-hidden': 'true' }, status === 'done' ? '✓' : '');
// Text, or the picture itself for a visible image field.
function printCell(f, includeSecrets) {
if (f.kind === 'image' && f.value && (!f.secret || includeSecrets)) return h('img', { class: 'pimg', src: f.value, alt: f.label });
return displayValue(f, includeSecrets);
function printCell(f, mode) {
if (f.kind === 'image' && f.value && !isHidden(f, mode)) return h('img', { class: 'pimg', src: f.value, alt: f.label });
return displayValue(f, mode);
}
function printFrame(f, k, includeSecrets) {
const v = frameView(f, includeSecrets);
function printFrame(f, k, mode) {
const v = frameView(f, mode);
return h('div', { class: 'pframe ' + v.layout },
h('div', { class: 'pfnum' }, 'Step ' + (k + 1)),
v.withheld ? h('p', { class: 'psecret' }, '[withheld]')
: v.image ? markedImage(h('img', { class: 'pimg', src: v.image, alt: 'Step ' + (k + 1) }), f.marks)
: h('p', {}, '(no image)'),
v.layout !== 'none' ? h('p', { class: 'pftext' }, v.text) : null,
v.withheld ? null : usesView(state.doc, f, includeSecrets).map((u) => h('p', { class: 'pftext' },
v.withheld ? null : usesView(state.doc, f, mode).map((u) => h('p', { class: 'pftext' },
u.missing ? '(a credential this step used has been removed)' : 'You will need: ' + u.record + ' \u203A ' + u.label + ': ' + u.value)),
v.stop ? h('p', { class: 'pstop' }, h('strong', {}, 'STOP HERE. Do not go further.')) : null,
v.ifStuck ? h('p', { class: 'pftext' }, h('strong', {}, 'If it looks different or fails: '), v.ifStuck) : null);
}
function printSequence(q, includeSecrets) {
function printSequence(q, mode) {
return h('div', { class: 'pseq' },
h('h3', {}, q.title),
q.captured ? h('p', { class: 'pftext' }, 'Captured ' + q.captured + '. The site may have changed since.') : null,
q.frames.map((f, k) => printFrame(f, k, includeSecrets)));
q.frames.map((f, k) => printFrame(f, k, mode)));
}
function printRecord(r, includeSecrets) {
function printRecord(r, mode) {
return h('div', { class: 'prec' + (r.status === 'tbd' ? ' tbd' : '') },
h('h3', {}, r.title, r.status === 'tbd' ? h('span', { class: 'ptag' }, 'TBD') : null),
r.fields.length ? h('table', {}, h('tbody', {}, r.fields.map((f) => h('tr', {},
h('th', {}, f.label), h('td', { class: f.secret ? 'psecret' : '' }, printCell(f, includeSecrets)))))) : null,
h('th', {}, f.label), h('td', { class: f.secret ? 'psecret' : '' }, printCell(f, mode)))))) : null,
r.notes ? h('p', { class: 'pnotes' }, r.notes) : null);
}
@@ -829,27 +834,29 @@
it.detail ? h('p', { class: 'pnotes' }, it.detail) : null);
}
function buildPrintDoc(includeSecrets) {
function buildPrintDoc(rawMode) {
const mode = normalizeMode(rawMode);
const doc = state.doc;
const kept = includeSecrets ? 'This copy INCLUDES passwords, PINs and other secrets. Keep it locked away (fire safe or sealed envelope).'
const kept = mode === 'complete' ? 'This copy INCLUDES passwords, PINs and other secrets. Keep it locked away (fire safe or sealed envelope).'
: mode === 'lawyer' ? "This is the LAWYER'S VIEW. It includes account numbers and other details a lawyer needs, but the most private secrets (passwords, PINs, balances) are WITHHELD. Keep it locked away."
: 'Secrets (passwords, PINs, security answers) are WITHHELD from this copy. They are stored in the encrypted file.';
const content = [
h('section', { class: 'pcover' },
h('h1', {}, doc.meta.title || 'Final Wishes'),
doc.meta.owner ? h('p', { class: 'powner' }, 'Prepared by ' + doc.meta.owner) : null,
h('p', {}, 'Last update: ' + doc.meta.lastUpdated),
h('p', { class: 'pnote' + (includeSecrets ? ' warn' : '') }, kept),
h('p', { class: 'pnote' + (mode !== 'masked' ? ' warn' : '') }, kept),
h('p', {}, 'Items marked TBD are not yet filled in. A box beside an instruction is for ticking it off as it is done.'),
h('h2', {}, 'Contents'),
h('ol', { class: 'ptoc' }, doc.sections.map((s) => h('li', {}, s.title)))),
doc.sections.map((s) => h('section', { class: 'psec' },
h('h2', {}, s.title),
s.intro ? h('p', { class: 'pintro' }, s.intro) : null,
s.kind === 'text' ? [h('p', { class: 'pbody' }, s.body), (s.sequences || []).map((q) => printSequence(q, includeSecrets))] : null,
s.kind === 'text' ? [h('p', { class: 'pbody' }, s.body), (s.sequences || []).map((q) => printSequence(q, mode))] : null,
s.kind === 'records' ? printGroups(s).map((g) => [g.title == null ? null : h('h3', { class: 'psubhead' }, g.title),
g.entries.map((r) => (isSequence(r) ? printSequence(r, includeSecrets) : printRecord(r, includeSecrets)))]) : null,
s.kind === 'steps' ? h('ol', { class: 'pitems' }, s.items.map((i) => (isSequence(i) ? h('li', { class: 'pseqitem' }, printSequence(i, includeSecrets)) : printItem(i)))) : null,
s.kind === 'checklist' ? h('ul', { class: 'pitems' }, s.items.map((i) => (isSequence(i) ? h('li', { class: 'pseqitem' }, printSequence(i, includeSecrets)) : printItem(i)))) : null)),
g.entries.map((r) => (isSequence(r) ? printSequence(r, mode) : printRecord(r, mode)))]) : null,
s.kind === 'steps' ? h('ol', { class: 'pitems' }, s.items.map((i) => (isSequence(i) ? h('li', { class: 'pseqitem' }, printSequence(i, mode)) : printItem(i)))) : null,
s.kind === 'checklist' ? h('ul', { class: 'pitems' }, s.items.map((i) => (isSequence(i) ? h('li', { class: 'pseqitem' }, printSequence(i, mode)) : printItem(i)))) : null)),
].flat();
// The header sits in <thead> so the browser repeats it, in flow, at the top of every page.
printRoot.replaceChildren(h('table', { class: 'ptable' },
@@ -859,18 +866,20 @@
window.addEventListener('afterprint', () => printRoot.replaceChildren()); // don't leave secrets lingering in the DOM
function openPrintDialog() {
const n = countSecrets(state.doc);
const n = countByLevel(state.doc);
const plural = (c) => c + ' secret value' + (c === 1 ? '' : 's');
const radio = (value, checked, text) => h('label', { class: 'radio' }, h('input', { type: 'radio', name: 'mode', value, checked }), ' ' + text);
const dlg = h('dialog', { class: 'card', 'aria-label': 'Print options' },
h('h3', {}, 'Print'),
radio('mask', true, 'Withhold secrets (safe overview; ' + n + ' secret value' + (n === 1 ? '' : 's') + ' hidden)'),
radio('include', false, 'Include secrets (full copy: store it securely)'),
radio('masked', true, 'Withhold secrets (safe overview; ' + plural(n.lawyer + n.secret) + ' hidden)'),
radio('lawyer', false, "Lawyer's view (shows " + n.lawyer + ' lawyer-level value' + (n.lawyer === 1 ? '' : 's') + '; ' + plural(n.secret) + ' hidden)'),
radio('complete', false, 'Include secrets (full copy: store it securely)'),
h('div', { class: 'row' },
btn('Cancel', () => { dlg.close(); dlg.remove(); }),
btn('Print', async () => {
const include = dlg.querySelector('input[name=mode]:checked').value === 'include';
const chosen = dlg.querySelector('input[name=mode]:checked').value;
dlg.close(); dlg.remove();
buildPrintDoc(include);
buildPrintDoc(chosen);
// Pictures must be decoded before the browser lays out the pages.
await Promise.all([...printRoot.querySelectorAll('img')].map((img) => img.decode().catch(() => {})));
window.print();