Fix Copy on plain-http hubs, toasts under modal backdrops, shorter install dialog

- copyText (house ui.js): over plain http (a LAN IP or .local name) there is
  no navigator.clipboard, and the fallback copied an empty string. el() set
  the textarea's value as an attribute, which textareas ignore. The textarea
  also sat outside the open modal, where it can't be selected. The fallback
  now sets .value, works inside the dialog, and reports a failure instead of
  always toasting success.
- toast (house ui.js): goes inside an open modal dialog, above its backdrop,
  which dimmed it to gray on gray in both themes.
- Install dialog: one sentence that holds on any machine, plus the hub address
  and a link to the install notes; the command is select-all on click.

The same ui.js fix is in the web-frontend skill's house assets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
neil 2026-11-04 19:42:00 -08:00
parent 35459b6309
commit 30ce39d5f0
3 changed files with 30 additions and 11 deletions

View file

@ -23,12 +23,15 @@ export function el(spec, props = {}, ...children) {
return node;
}
/** A short confirmation in the corner: toast('Copied'), toast('Upload failed: too large', 'error'). */
/** A short confirmation in the corner: toast('Copied'), toast('Upload failed: too large', 'error').
* While a modal dialog is open the toast goes inside it: everything outside a modal sits under
* its backdrop, which would dim the toast. */
export function toast(message, kind = 'info') {
let box = document.getElementById('toasts');
const host = document.querySelector('dialog[open]') || document.body;
let box = [...host.children].find((c) => c.classList.contains('toasts'));
if (!box) {
box = el('div.toasts', { id: 'toasts', 'aria-live': 'polite' });
document.body.append(box);
box = el('div.toasts', { 'aria-live': 'polite' });
host.append(box);
}
const t = el(`div.toast.${kind}`, { role: kind === 'error' ? 'alert' : 'status' }, message);
box.append(t);
@ -36,17 +39,29 @@ export function toast(message, kind = 'info') {
setTimeout(() => t.remove(), kind === 'error' ? 5400 : 2600);
}
/** Copies text and toasts `what`; resolves false (and says so) when the browser refuses.
* navigator.clipboard only exists in secure contexts (https, localhost). On plain http, e.g.
* http://192.168.1.10 or http://host.local, it falls back to a hidden textarea + execCommand. */
export async function copyText(text, what = 'Copied') {
let ok = false;
try {
await navigator.clipboard.writeText(text);
ok = true;
} catch {
const ta = el('textarea', { value: text, style: 'position:fixed;opacity:0' });
document.body.append(ta);
// Inside an open modal, anything outside the dialog is inert and can't be selected.
const host = document.querySelector('dialog[open]') || document.body;
const before = document.activeElement;
const ta = el('textarea', { readonly: true, 'aria-hidden': 'true', style: 'position:fixed;top:0;left:0;width:1px;height:1px;opacity:0' });
ta.value = text; // a textarea's value attribute is ignored: set the property
host.append(ta);
ta.focus();
ta.select();
document.execCommand('copy');
try { ok = document.execCommand('copy'); } catch { ok = false; }
ta.remove();
before?.focus?.();
}
toast(what);
toast(ok ? what : 'Couldn’t copy here: select the text and press Ctrl+C (⌘C on a Mac)', ok ? 'info' : 'error');
return ok;
}
/** Copies HTML as rich text (with a plain-text alternative) for pasting into docs and chat apps. */