Capture walkthroughs online in a separate tool, merge them in offline (Fixes #28)

build.js now also writes capture.html: no document, no payload, no storage.
It captures walkthroughs and exports an encrypted .fwcapture bundle (magic
FC, own passphrase). The main app's Import captures... opens a bundle and
places each walkthrough in a chosen section or sub-tab; nothing is written
until Save and the bundle is never modified.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-27 15:41:19 -05:00
parent 273c714fc4
commit 673560a249
12 changed files with 443 additions and 9 deletions

View File

@@ -915,6 +915,65 @@
});
}
// ---------- import captured walkthroughs (issue #28) ----------
// Open a bundle made by capture.html, then choose where each walkthrough goes. All or
// nothing per bundle: a wrong passphrase or damaged file imports nothing. The bundle file is
// never changed, so walkthroughs you skip can be imported from it later.
function importCaptures() {
const dests = destinations(state.doc);
const file = h('input', { type: 'file', accept: '.fwcapture,text/plain', 'aria-label': 'Capture bundle file' });
const pw = h('input', { type: 'password', autocomplete: 'off', placeholder: 'Bundle passphrase', 'aria-label': 'Bundle passphrase' });
const msg = h('p', { class: 'error', role: 'alert' });
const list = h('div', {});
const go = btn('Import selected', null, 'primary', { type: 'button', hidden: true });
let rows = [];
const close = () => { dlg.close(); dlg.remove(); };
const open = async () => {
msg.textContent = '';
try {
if (!file.files[0]) throw new Error('Choose the bundle file first.');
const bundle = await openBundle(await file.files[0].text(), pw.value);
if (!bundle.walkthroughs.length) throw new Error('That bundle has no walkthroughs.');
rows = bundle.walkthroughs.map((w) => {
const use = h('input', { type: 'checkbox', checked: true, 'aria-label': 'Import this walkthrough' });
const title = h('input', { value: w.title, 'aria-label': 'Walkthrough name' });
const where = h('select', { 'aria-label': 'Where to put it' }, dests.map((d) => h('option', { value: d.key }, d.label)));
const cur = state.doc.sections.find((x) => x.id === state.current);
if (cur) where.value = cur.id + '|';
return { w, use, title, where, el: h('div', { class: 'importrow' },
h('label', { class: 'check' }, use, ' ' + w.frames.length + ' step' + (w.frames.length === 1 ? '' : 's') + ', captured ' + w.captured),
h('div', { class: 'row' }, title, where)) };
});
list.replaceChildren(...rows.map((r) => r.el));
go.hidden = false;
if (!dests.length) msg.textContent = 'The document has no sections to put them in. Add one first.';
} catch (err) {
msg.textContent = err instanceof DecryptError ? err.message : err.message || 'Could not open that file.';
}
};
go.onclick = () => {
const picked = rows.filter((r) => r.use.checked);
if (!picked.length) { msg.textContent = 'Tick at least one walkthrough, or Cancel.'; return; }
for (const r of picked) {
const d = dests.find((x) => x.key === r.where.value);
const sec = state.doc.sections.find((x) => x.id === d.sid);
importWalkthrough(state.doc, sec, Object.assign({}, r.w, { title: r.title.value }), d.tab);
}
close();
markDirty();
state.status = 'Imported ' + picked.length + ' walkthrough' + (picked.length === 1 ? '' : 's') + '. Save to keep them, then delete the bundle file.';
render();
};
const dlg = h('dialog', { class: 'card', 'aria-label': 'Import captured walkthroughs' },
h('h3', {}, 'Import captured walkthroughs'),
h('p', {}, 'Choose the bundle file made by the capture tool and enter its passphrase. Nothing is saved until you Save.'),
file, pw, btn('Open bundle', open, 'small'), msg, list,
h('div', { class: 'row' }, btn('Cancel', close), go));
dlg.addEventListener('cancel', () => dlg.remove());
document.body.append(dlg);
dlg.showModal();
}
// backup=true downloads final-wishes-YYYYMMDD.html; otherwise writes the main file.
async function save({ backup = false } = {}) {
try {
@@ -1039,6 +1098,7 @@
btn('Backup copy', () => save({ backup: true })),
btn('Change passphrase', changePassphrase),
btn('Print…', openPrintDialog),
state.editing ? null : btn('Import captures…', importCaptures, '', { title: 'Merge walkthroughs captured with the separate capture tool' }),
state.editing ? null : btn('Search', openSearch, '', { id: 'searchopen', title: 'Find a word in the document' }),
btn(state.editing ? 'Done editing' : 'Edit', () => { state.editing = !state.editing; render(); }, state.editing ? 'primary' : '')])),
...(resetRequested() && !state.resetOffered ? [resetBanner()] : []), // never pass null: append() would print "null"