This commit is contained in:
root
2026-09-20 14:16:41 +02:00
parent 0798933b05
commit b6d1909d7f
56 changed files with 3752 additions and 1989 deletions
+27
View File
@@ -52,6 +52,33 @@ export function confirmDialog({ title, body, confirmText = 'CONFIRM', cancelText
});
}
/**
* A modal dialog around caller-built content (form fields and so on). Returns
* { result, confirm, close }: `result` resolves true on the confirm button and
* false on cancel or Escape; the caller can enable/disable `confirm` as it
* validates, and reads its own fields after `result` resolves.
*/
export function customDialog({ title, content, confirmText = 'OK', cancelText = 'CANCEL', danger = false }) {
const dlg = document.getElementById('dialog');
let resolve;
const result = new Promise((r) => { resolve = r; });
const finish = (v) => {
if (dlg.open) dlg.close();
resolve(v);
};
const confirm = h('button', { class: `btn ${danger ? 'danger' : 'primary'}`, type: 'button', onclick: () => finish(true) }, confirmText);
clear(dlg).append(
h('div', { class: `panel dialog ${danger ? 'danger' : ''}` },
h('div', { class: 'panel-title' }, title),
h('div', { class: 'panel-body stack' }, ...content),
h('div', { class: 'actions' }, h('button', { class: 'btn', type: 'button', onclick: () => finish(false) }, cancelText), confirm),
),
);
dlg.oncancel = () => resolve(false);
dlg.showModal();
return { result, confirm, close: finish };
}
export function download(filename, bytes, type = 'application/octet-stream') {
const url = URL.createObjectURL(new Blob([bytes], { type }));
const a = h('a', { href: url, download: filename });