diff --git a/build.js b/build.js index 4cadc8f..262e2f0 100644 --- a/build.js +++ b/build.js @@ -16,10 +16,10 @@ import { assertValid } from './src/model.js'; const root = dirname(fileURLToPath(import.meta.url)); const read = (p) => readFileSync(join(root, 'src', p), 'utf8'); -// Modules are concatenated (ES `export` dropped) ahead of app.js into one scope. +// Modules are concatenated (ES `import` lines and `export` keywords dropped) ahead of app.js into one scope. const MODULES = ['crypto.js', 'model.js', 'ops.js', 'print.js', 'template.js']; export function bundleJs() { - return MODULES.map((f) => read(f).replace(/^export /gm, '')).concat(read('app.js')).join('\n'); + return MODULES.map((f) => read(f).replace(/^import .*$/gm, '').replace(/^export /gm, '')).concat(read('app.js')).join('\n'); } function parseArgs(argv) { diff --git a/src/app.js b/src/app.js index b79e449..be2e834 100644 --- a/src/app.js +++ b/src/app.js @@ -10,6 +10,7 @@ editing: false, dirty: false, revealed: new WeakSet(), // secret field objects currently shown + blob: null, // encrypted payload taken from a file the user chose to open handle: null, // File System Access handle once the user picked a save location status: '', error: '', @@ -56,7 +57,7 @@ } function renderStart() { - const blob = payloadText(); + const blob = state.blob || payloadText(); const msg = h('p', { class: 'error', role: 'alert' }, state.error); if (blob) { const pw = h('input', { type: 'password', autocomplete: 'current-password', autofocus: true, 'aria-label': 'Passphrase' }); @@ -68,6 +69,7 @@ assertValid(doc); state.doc = doc; state.passphrase = pw.value; + state.blob = null; state.current = doc.sections[0] && doc.sections[0].id; } catch (err) { state.error = err instanceof DecryptError ? err.message : 'Could not open the file: ' + err.message; @@ -76,7 +78,8 @@ } }, h('h1', {}, 'Final Wishes'), h('p', {}, 'Enter the passphrase to open this document.'), - pw, msg, btn('Open', null, 'primary', { type: 'submit' })); + pw, msg, btn('Open', null, 'primary', { type: 'submit' }), + state.blob ? btn('Choose a different file', () => { state.blob = null; state.error = ''; render(); }, 'small') : null); return form; } // No encrypted data embedded yet (development / first use). @@ -90,9 +93,16 @@ } catch (err) { state.error = 'Could not open that file: ' + err.message; } render(); } }); + const existing = h('input', { type: 'file', accept: '.html,text/html', 'aria-label': 'Open an existing Final Wishes file', onchange: async () => { + const m = (await existing.files[0].text()).match(/