Replace browser popups with in-page dialogs; focus new-task prompt
This commit is contained in:
Vendored
+23
@@ -42,4 +42,27 @@ export function ago(iso) {
|
||||
export function errorText(err) {
|
||||
return err instanceof Error ? err.message : String(err);
|
||||
}
|
||||
function modal(text, buttons) {
|
||||
const actions = buttons.map((b) => h("button", { type: "submit", value: b.value, class: b.class ?? "" }, b.label));
|
||||
const dialog = h("dialog", { class: "modal" }, h("form", { method: "dialog" }, h("p", { class: "modal-text" }, text), h("div", { class: "modal-actions" }, ...actions)));
|
||||
document.body.append(dialog);
|
||||
return new Promise((resolve) => {
|
||||
dialog.onclose = () => {
|
||||
dialog.remove();
|
||||
resolve(dialog.returnValue);
|
||||
};
|
||||
dialog.showModal();
|
||||
actions.at(-1)?.focus();
|
||||
});
|
||||
}
|
||||
export async function showAlert(text) {
|
||||
await modal(text, [{ label: "OK", value: "ok", class: "primary" }]);
|
||||
}
|
||||
export async function showConfirm(text, action, danger = false) {
|
||||
const value = await modal(text, [
|
||||
{ label: "Cancel", value: "cancel" },
|
||||
{ label: action, value: "ok", class: danger ? "danger-primary" : "primary" },
|
||||
]);
|
||||
return value === "ok";
|
||||
}
|
||||
//# sourceMappingURL=dom.js.map
|
||||
Reference in New Issue
Block a user