This commit is contained in:
Mateusz Gruszczyński committed 2026-11-08 23:23:21 +01:00
1 parent 1ac94213e0
commit 0119b11005
28 files changed
+698 -153

No files matched your search

+12 -4
View File
@@ -61,15 +61,23 @@ function translate() {
syncSettingsDirtyIndicators();
window.rustProxyIcons?.refresh?.();
}
function hideToast() { const node = $("toast"); if (typeof node.hidePopover === "function" && node.matches(":popover-open")) node.hidePopover(); node.hidden = true; }
function toastNode() {
let node = document.getElementById("toast");
if (!node) { // the node lived inside a dialog that was rebuilt; recreate it instead of failing every later toast
node = document.createElement("div"); node.id = "toast"; node.className = "toast"; node.hidden = true;
node.setAttribute("role", "status"); node.setAttribute("aria-live", "polite"); node.setAttribute("popover", "manual"); document.body.append(node);
}
return node;
}
function hideToast() { const node = toastNode(); if (typeof node.hidePopover === "function" && node.matches(":popover-open")) node.hidePopover(); node.hidden = true; }
function raiseToast() {
const node = $("toast"); if (node.hidden) return;
const node = toastNode(); if (node.hidden) return;
const modal = [...document.querySelectorAll("dialog[open]")].at(-1), parent = modal || document.body;
if (typeof node.hidePopover === "function" && node.matches(":popover-open")) node.hidePopover();
if (node.parentElement !== parent) parent.append(node);
if (typeof node.showPopover === "function") node.showPopover();
}
function toast(message, error = false) { clearTimeout(toastTimer); const node = $("toast"); node.textContent = message; node.classList.toggle("error", error); node.hidden = false; raiseToast(); toastTimer = setTimeout(hideToast, error ? 10000 : 4000); }
function toast(message, error = false) { clearTimeout(toastTimer); const node = toastNode(); node.textContent = message; node.classList.toggle("error", error); node.hidden = false; raiseToast(); toastTimer = setTimeout(hideToast, error ? 10000 : 4000); }
function authMessage(message = "") { const node = $("auth-message"); if (!node) return; node.textContent = message; node.classList.toggle("error", Boolean(message)); }
function fieldError(target, message) { const error = new Error(message); error.fieldTarget = target; return error; }
function clearFieldError(target) {
@@ -134,7 +142,7 @@ function apiErrorMessage(path, response, value) {
const area = apiArea(path);
return area ? t("errorContext").replace("{area}", t(area)).replace("{message}", detail) : detail;
}
new MutationObserver(records => { if (!records.some(r => r.target.tagName === "DIALOG")) return; const node = $("toast"); if (!node.hidden) raiseToast(); }).observe(document.body, { subtree: true, attributes: true, attributeFilter: ["open"] });
new MutationObserver(records => { if (!records.some(r => r.target.tagName === "DIALOG")) return; const node = toastNode(); if (!node.hidden) raiseToast(); }).observe(document.body, { subtree: true, attributes: true, attributeFilter: ["open"] });
async function api(path, options = {}) {
const started = performance.now(), trackLatency = path.startsWith("/api/");
try {