diff --git a/OVERVIEW.md b/OVERVIEW.md index 3092aaa..d0e49d2 100644 --- a/OVERVIEW.md +++ b/OVERVIEW.md @@ -80,7 +80,7 @@ A **visual sequence** (`kind: 'sequence'`, numbered `frames` of image + text wit **Upgrading app code, keeping data.** A file runs the code it was saved with. On the start screen, "Open your existing Final Wishes file" extracts the `#payload` from an older `.html`, unlocks it with the passphrase, and Save then writes it out with the newer code. -**Print.** Built only when Print is chosen and cleared on `afterprint`, so secrets don't linger in the DOM. It is a `` whose `` holds the running header, which the browser repeats at the top of every page. Each section starts a new page (a section with sub-tabs gets a sub-heading per non-empty tab), records and sequence steps avoid page breaks inside them, and checklist items have tick boxes. The print dialog offers three views (issue #29): "withhold secrets" (default, mode `masked`), "lawyer's view" (`lawyer`: shows secrets flagged `lawyer: true`, still withholds plain secrets) and "include secrets" (`complete`). `isHidden()`, `displayValue()`, `frameView()` and `usesView()` in `print.js` take the mode (a boolean still works: true is complete); `levelOf()`/`setLevel()` in `ops.js` keep the flags canonical and the edit UI uses a Normal/Lawyer/Secret select. Older builds read a lawyer-level item as a plain secret, which fails closed. `countByLevel()` feeds the dialog counts; `?reset=1` still erases lawyer-level values. Images are decoded before `window.print()`. +**Print.** Built only when Print is chosen and cleared on `afterprint`, so secrets don't linger in the DOM. It is a `
` whose `` holds the running header, which the browser repeats at the top of every page. Each section starts a new page (a section with sub-tabs gets a sub-heading per non-empty tab), records and sequence steps avoid page breaks inside them, and checklist items have tick boxes. The print dialog offers three views (issue #29): "withhold secrets" (default, mode `masked`), "lawyer's view" (`lawyer`: shows secrets flagged `lawyer: true`, still withholds plain secrets) "lawyer's summary" (`summary`, issue #30: `summaryGroups()` in `print.js` lists only records with lawyer-level text fields, each with just those fields, built by `printSummary()` in `app.js`) and "include secrets" (`complete`). `isHidden()`, `displayValue()`, `frameView()` and `usesView()` in `print.js` take the mode (a boolean still works: true is complete); `levelOf()`/`setLevel()` in `ops.js` keep the flags canonical and the edit UI uses a Normal/Lawyer/Secret select. Older builds read a lawyer-level item as a plain secret, which fails closed. `countByLevel()` feeds the dialog counts; `?reset=1` still erases lawyer-level values. Images are decoded before `window.print()`. ## Integrations diff --git a/README.md b/README.md index 0d6499b..79677c1 100644 --- a/README.md +++ b/README.md @@ -295,13 +295,18 @@ Documents made by older versions keep working: anything a newer version added LastPass master password. ## Printing -**Print...** offers "Withhold secrets" (safe overview), "Lawyer's view" and -"Include secrets" (full copy). Every field and step has a level in Edit mode: +**Print...** offers "Withhold secrets" (safe overview), "Lawyer's view", +"Lawyer's summary" and "Include secrets" (full copy). Every field and step has a level in Edit mode: **Normal** (always printed), **Lawyer** or **Secret**. Lawyer and Secret values are both hidden on screen until **Show**. For a bank account, say, the name is Normal, the account number Lawyer and the balance Secret: the overview prints only the name, the lawyer's view adds the account number, and the full copy -prints all three. A lawyer's-view copy is still sensitive, so store it too. Print on Letter paper with the browser's own +prints all three. The **lawyer's summary** is a short list instead of a full copy: only the +records that have at least one Lawyer-level field, each with just its Lawyer +fields (so the account and its number, nothing else), in clear text. Text +sections, steps, walkthroughs, notes and Normal or Secret fields are left out. +Lawyer-level image fields are not listed. Both lawyer copies are still +sensitive, so store them too. Print on Letter paper with the browser's own "Headers and footers" turned off (that is separate from the document header below). A full copy is as sensitive as the passwords on it: store it in the fire safe and shred superseded copies. Page layout was checked by rendering diff --git a/docs/thumbdrive/README.txt b/docs/thumbdrive/README.txt index 54e9c62..59fa42b 100644 --- a/docs/thumbdrive/README.txt +++ b/docs/thumbdrive/README.txt @@ -24,6 +24,8 @@ TO PRINT IT - "Withhold secrets": a safe overview with no passwords or PINs. - "Lawyer's view": adds the details a lawyer needs (such as account numbers) but still withholds the most private secrets. + - "Lawyer's summary": a short list of accounts and account numbers only, + with everything else left out. - "Include secrets": the full copy. Keep it locked away and shred it when you are finished. In the browser's print window, set Paper size to Letter and turn OFF diff --git a/src/app.js b/src/app.js index 97f1cf2..f18af70 100644 --- a/src/app.js +++ b/src/app.js @@ -828,6 +828,26 @@ r.notes ? h('p', { class: 'pnotes' }, r.notes) : null); } + // The lawyer's summary: just the records with lawyer-level fields, as one compact list. + function printSummary(doc) { + const groups = summaryGroups(doc); + const list = groups.length ? groups.map((s) => h('section', { class: 'psumsec' }, + h('h2', {}, s.section), + s.groups.map((g) => [g.title == null ? null : h('h3', { class: 'psubhead' }, g.title), + g.records.map((r) => h('div', { class: 'prec' }, h('h3', {}, r.title), + h('table', {}, h('tbody', {}, r.fields.map((f) => h('tr', {}, h('th', {}, f.label), h('td', { class: 'psecret' }, f.value || '(not set)')))))))]))) + : h('p', {}, 'Nothing to list: no record has a lawyer-level field.'); + printRoot.replaceChildren(h('table', { class: 'ptable' }, + h('thead', {}, h('tr', {}, h('td', {}, headerEl(doc)))), + h('tbody', {}, h('tr', {}, h('td', {}, + h('section', { class: 'pcover psumcover' }, + h('h1', {}, (doc.meta.title || 'Final Wishes') + ": lawyer's summary"), + doc.meta.owner ? h('p', { class: 'powner' }, 'Prepared by ' + doc.meta.owner) : null, + h('p', {}, 'Last update: ' + doc.meta.lastUpdated), + h('p', { class: 'pnote warn' }, "This is the LAWYER'S SUMMARY. It lists only the accounts and details a lawyer needs, in clear text. Keep it locked away.")), + list))))); + } + function printItem(it, numbered) { return h('li', { class: 'pitem ' + it.status }, box(it.status), h('strong', {}, it.text), it.status === 'tbd' ? h('span', { class: 'ptag' }, 'TBD') : null, @@ -836,6 +856,7 @@ function buildPrintDoc(rawMode) { const mode = normalizeMode(rawMode); + if (mode === 'summary') return printSummary(state.doc); const doc = state.doc; 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." @@ -867,12 +888,14 @@ function openPrintDialog() { const n = countByLevel(state.doc); + const sum = summaryCounts(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('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('summary', false, "Lawyer's summary (a short list of " + sum.records + ' record' + (sum.records === 1 ? '' : 's') + ' with lawyer-level values, ' + sum.values + ' value' + (sum.values === 1 ? '' : 's') + ')'), radio('complete', false, 'Include secrets (full copy: store it securely)'), h('div', { class: 'row' }, btn('Cancel', () => { dlg.close(); dlg.remove(); }), diff --git a/src/print.js b/src/print.js index 1fa2b95..4f73cdc 100644 --- a/src/print.js +++ b/src/print.js @@ -1,12 +1,14 @@ import { defaultHeaderFields, isSequence } from './model.js'; +import { printGroups } from './ops.js'; // Pure helpers for the printed document. No DOM; tested in Node. // build.js strips `export` when bundling. // Print views: 'masked' (no secrets), 'lawyer' (lawyer-level secrets shown, the // rest withheld) and 'complete' (everything). A boolean is accepted for older -// callers: true is 'complete', false is 'masked'. -export const PRINT_MODES = ['masked', 'lawyer', 'complete']; +// callers: true is 'complete', false is 'masked'. 'summary' is the lawyer's summary: +// it shows lawyer-level values like 'lawyer' does, but lists only those records (see summaryGroups). +export const PRINT_MODES = ['masked', 'lawyer', 'complete', 'summary']; export function normalizeMode(mode) { if (mode === true) return 'complete'; return PRINT_MODES.includes(mode) ? mode : 'masked'; @@ -18,7 +20,7 @@ export function normalizeMode(mode) { export function isHidden(item, mode) { if (!item.secret) return false; const m = normalizeMode(mode); - return m === 'complete' ? false : m === 'lawyer' ? !item.lawyer : true; + return m === 'complete' ? false : m === 'masked' ? true : !item.lawyer; } // What to print for a field. Secrets are either shown or withheld; an empty @@ -90,6 +92,30 @@ export function usesView(doc, frame, mode) { // How many filled-in secret values the document holds: { lawyer, secret } where // `lawyer` counts lawyer-level ones and `secret` the plain ones. Empty ones don't count. +// What the lawyer's summary lists: [{ section, groups: [{ title, records: [{ title, fields }] }] }]. +// A record qualifies if it has a lawyer-level text field (secret + lawyer); only those fields are +// listed. Image fields, plain secrets and normal fields never are. Sections and sub-tabs with +// no qualifying record are left out; order is the document's. +export function summaryGroups(doc) { + const lawyerFields = (r) => r.fields.filter((f) => f.secret && f.lawyer && f.kind !== 'image'); + const out = []; + for (const s of doc.sections) { + if (s.kind !== 'records') continue; + const groups = printGroups(s) + .map((g) => ({ title: g.title, records: g.entries.filter((r) => !isSequence(r)).map((r) => ({ title: r.title, fields: lawyerFields(r) })).filter((r) => r.fields.length) })) + .filter((g) => g.records.length); + if (groups.length) out.push({ section: s.title, groups }); + } + return out; +} + +// { records, values } the lawyer's summary would list, for the print dialog. +export function summaryCounts(doc) { + let records = 0, values = 0; + for (const s of summaryGroups(doc)) for (const g of s.groups) for (const r of g.records) { records++; values += r.fields.length; } + return { records, values }; +} + export function countByLevel(doc) { const n = { lawyer: 0, secret: 0 }; const add = (x) => { n[x.lawyer ? 'lawyer' : 'secret']++; }; diff --git a/src/style.css b/src/style.css index ea0c7ca..0fb28d3 100644 --- a/src/style.css +++ b/src/style.css @@ -100,6 +100,9 @@ dialog.lightbox { max-width: 92vw; max-height: 92vh; overflow: auto; } .bigimg { .pnote { border: 1.5pt solid #000; padding: 8pt 10pt; font: 600 10.5pt system-ui, sans-serif; } .pnote.warn { border-width: 3pt; } .ptoc { columns: 2; padding-left: 1.2em; } + .pcover.psumcover { break-after: auto; } + .pcover.psumcover h1 { font-size: 20pt; margin: 0 0 .1in; } + .psumsec h2 { break-after: avoid; } .psec { break-before: page; } .psec:first-of-type { break-before: auto; } h2 { font-size: 17pt; border-bottom: 1pt solid #000; padding-bottom: 3pt; margin: 0 0 10pt; break-after: avoid; } diff --git a/test/print.test.js b/test/print.test.js index 46aa553..335b48d 100644 --- a/test/print.test.js +++ b/test/print.test.js @@ -109,3 +109,52 @@ test('countByLevel splits lawyer-level from plain secrets, and countSecrets tota assert.deepEqual(countByLevel(doc), { lawyer: 2, secret: 2 }); assert.equal(countSecrets(doc), 4); }); + +import { summaryGroups, summaryCounts } from '../src/print.js'; + +const rec = (title, fields) => ({ id: title, title, status: 'ok', updated: '2022-04-14', fields }); +const lw = (label, value) => ({ label, value, secret: true, lawyer: true }); +const summaryDoc = () => ({ sections: [ + { id: 'a', title: 'Intro', kind: 'text', body: 'hello' }, + { id: 'b', title: 'Bank', kind: 'records', records: [ + rec('Chase', [{ label: 'Name', value: 'Chase' }, lw('Account', '123'), { label: 'Balance', value: '$9', secret: true }]), + rec('Only secret', [{ label: 'PIN', value: '1', secret: true }]), + rec('Only normal', [{ label: 'Phone', value: '555' }]), + rec('Empty acct', [lw('Account', '')]), + rec('Card scan', [{ label: 'Card', kind: 'image', value: '', secret: true, lawyer: true }]), + { id: 'q', kind: 'sequence', title: 'Walk', updated: '2022-04-14', frames: [{ image: '', text: 'x', layout: 'none', secret: true, lawyer: true }] }, + ] }, + { id: 'c', title: 'Nothing here', kind: 'records', records: [rec('Plain', [{ label: 'x', value: 'y' }])] }, + { id: 'd', title: 'Steps', kind: 'steps', items: [] }, +] }); + +test('summaryGroups keeps only records with lawyer-level text fields, and only those fields', () => { + const out = summaryGroups(summaryDoc()); + assert.equal(out.length, 1); + assert.equal(out[0].section, 'Bank'); + assert.deepEqual(out[0].groups[0].records.map((r) => r.title), ['Chase', 'Empty acct']); + assert.deepEqual(out[0].groups[0].records[0].fields.map((f) => f.label), ['Account']); // no Name, no Balance + assert.equal(out[0].groups[0].title, null); +}); + +test('summaryGroups follows sub-tabs and drops tabs with no match', () => { + const doc = summaryDoc(); + const s = doc.sections[1]; + s.subsections = [{ id: 't1', title: 'Savings' }, { id: 't2', title: 'Unused' }]; + s.records[0].subsection = 't1'; + const out = summaryGroups(doc); + assert.deepEqual(out[0].groups.map((g) => g.title), ['General', 'Savings']); + assert.deepEqual(out[0].groups[1].records.map((r) => r.title), ['Chase']); +}); + +test('summaryCounts counts records and values; an empty document lists nothing', () => { + assert.deepEqual(summaryCounts(summaryDoc()), { records: 2, values: 2 }); + assert.deepEqual(summaryGroups({ sections: [] }), []); + assert.deepEqual(summaryCounts({ sections: [] }), { records: 0, values: 0 }); +}); + +test("the summary mode shows lawyer values like the lawyer's view and keeps plain secrets hidden", () => { + assert.equal(normalizeMode('summary'), 'summary'); + assert.equal(isHidden(acct.num, 'summary'), false); + assert.equal(isHidden(acct.amt, 'summary'), true); +});