Show and copy referenced credentials in steps, view, player and print (Refs #24)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-24 12:36:25 -05:00
parent edb3e25e67
commit 6066aac6aa
5 changed files with 70 additions and 1 deletions

View File

@@ -158,6 +158,20 @@
const allRecords = () => state.doc.sections.flatMap((s) => (s.records || []).filter((r) => !isSequence(r)));
const addFrameFrom = (seq) => (name, url) => addFrame(seq, url);
// Copy a credential for the reader, then wipe the clipboard after 30 seconds
// (this overwrites whatever is on the clipboard by then, whether or not it is ours).
let clipTimer = null;
async function copyValue(fld) {
try {
await navigator.clipboard.writeText(fld.value);
clearTimeout(clipTimer);
clipTimer = setTimeout(() => { navigator.clipboard.writeText('').catch(() => {}); }, 30000);
setStatus('Copied ' + fld.label + '. The clipboard is cleared in 30 seconds.');
} catch {
setStatus('Could not copy ' + fld.label + '. Show it and copy it by hand.');
}
}
// Screen capture while editing a visual sequence. The stream lives here, not in
// the DOM, so it survives render(). { stream, video, seqId } or null.
let capture = null;
@@ -338,12 +352,30 @@
onclick: () => openLightbox(label, f.image), onkeydown: (e) => { if (e.key === 'Enter') openLightbox(label, f.image); } })
: h('span', { class: 'muted' }, '(no image)'),
layout !== 'none' ? h('p', { class: 'ftext' }, f.text) : null,
viewUses(f),
f.stop || String(f.ifStuck || '').trim() ? h('div', { class: 'fnotes' },
f.stop ? h('p', { class: 'fstop' }, h('strong', {}, 'Stop here. Do not go further.')) : null,
String(f.ifStuck || '').trim() ? h('p', { class: 'fstuck' }, h('strong', {}, 'If it looks different or fails: '), f.ifStuck) : null) : null,
f.secret ? btn('Hide', toggle, 'link', { 'aria-label': 'Hide ' + label }) : null]);
}
// The credentials a step needs, live from their records: secrets stay masked until shown.
function viewUses(f) {
if (!f.uses || !f.uses.length) return null;
return h('div', { class: 'fuses' }, h('strong', {}, 'You will need:'), f.uses.map((u) => {
const hit = findFieldRef(state.doc, u);
if (!hit) return h('p', { class: 'muted' }, '(a credential this step used has been removed)');
const fld = hit.field;
const shown = !fld.secret || state.revealed.has(fld);
const toggle = () => { state.revealed[shown ? 'delete' : 'add'](fld); render(); };
return h('div', { class: 'row fuse' },
h('span', {}, hit.record.title + ' \u203A ' + fld.label + ': '),
h('span', { class: fld.secret ? 'secret' : '' }, !fld.value ? '(not set)' : shown ? fld.value : '\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022'),
fld.secret ? btn(shown ? 'Hide' : 'Show', toggle, 'link', { 'aria-label': (shown ? 'Hide ' : 'Show ') + fld.label }) : null,
fld.value ? btn('Copy', () => copyValue(fld), 'small', { 'aria-label': 'Copy ' + fld.label }) : null);
}));
}
const capturedNote = (q) => (q.captured ? ' Captured ' + q.captured + '. The site may have changed since.' : '');
// One step at a time, with Back/Next. A secret step stays hidden until shown, as in the list.
@@ -517,6 +549,29 @@
const LAYOUT_LABELS = [['right', 'Text right of image'], ['under', 'Text under image'], ['none', 'No text']];
// Pick the record fields this step needs; the reader sees them beside the step.
function useEditor(q, f, k) {
const recs = allRecords().filter((r) => r.fields.some((x) => x.kind !== 'image'));
const pick = h('select', { 'aria-label': 'Add a credential to step ' + (k + 1), onchange: () => {
if (!pick.value) return;
const [rid, idx] = pick.value.split('|');
const rec = recs.find((r) => r.id === rid);
if (rec && addUse(f, rec, rec.fields[Number(idx)])) { changed(q); render(); }
} },
h('option', { value: '' }, '+ Use a field from a record\u2026'),
recs.map((r) => h('optgroup', { label: r.title }, r.fields.map((x, i) => (x.kind === 'image' ? null
: h('option', { value: r.id + '|' + i }, x.label + (x.secret ? ' (secret)' : '')))))));
return h('div', {},
h('strong', {}, 'Credentials this step needs'),
(f.uses || []).map((u, i) => {
const hit = findFieldRef(state.doc, u);
return h('div', { class: 'row' },
h('span', {}, hit ? hit.record.title + ' \u203A ' + hit.field.label : '(removed)'),
btn('\u2715', () => { removeUse(f, i); changed(q); render(); }, 'icon danger', { 'aria-label': 'Remove credential from step ' + (k + 1) }));
}),
pick);
}
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); } });
@@ -529,6 +584,7 @@
imageZone(f, 'image', q.title + ', step ' + (k + 1), { 'data-frame': String(k) },
(files) => importFiles(q, files, { key: 'image', replace: f, add: addFrameFrom(q) }), () => changed(q)),
f.layout === 'none' ? null : h('label', {}, 'Text', input(f, 'text', { multiline: true, label: 'Text for step ' + (k + 1) }, q)),
useEditor(q, f, k),
h('label', {}, 'If it looks different or fails', input(f, 'ifStuck', { multiline: true, label: 'If step ' + (k + 1) + ' looks different or fails' }, q)),
h('label', { class: 'check' }, stop, ' Stop here: the reader must not go further without help'));
}
@@ -633,6 +689,8 @@
: v.image ? h('img', { class: 'pimg', src: v.image, alt: 'Step ' + (k + 1) })
: 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' },
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);
}

View File

@@ -59,6 +59,7 @@ textarea { width: 100%; display: block; } label { display: block; margin-top: .5
.fnum { font-weight: 700; color: var(--accent); } .ftext { white-space: pre-wrap; margin: 0; }
li.seqitem { display: block; list-style: none; margin-left: -1.4rem; } .frameedit { border-top: 1px dashed var(--line); padding-top: .5rem; }
.fnotes { grid-column: 1 / -1; display: grid; gap: .35rem; } .fnotes p { margin: 0; }
.fuses { grid-column: 1 / -1; } .fuse { align-items: center; margin: .25rem 0; }
.fstop { border: 2px solid var(--danger); color: var(--danger); border-radius: .35rem; padding: .35rem .6rem; }
.fstuck { background: var(--warn-bg); color: var(--warn-fg); border-radius: .35rem; padding: .35rem .6rem; white-space: pre-wrap; }
.walk .fimg { max-height: 28rem; } .walknav { align-items: center; margin-top: .75rem; }

View File

@@ -2,7 +2,7 @@
// YYMMDD is the date, X the iteration that day (A first, B second, ...).
// Bump with `npm run bump` (see bump-version.js). build.js strips `export`.
export const APP_VERSION = '261124C';
export const APP_VERSION = '261124D';
const VERSION_RE = /^(\d{6})([A-Z])$/;
export const isVersion = (v) => typeof v === 'string' && VERSION_RE.test(v);