Keep Dock exclusive and polish controls chart and overlays
This commit is contained in:
1 parent
84c4b3030a
commit
17011ebd4d
38 files changed
+240
-68
No files matched your search
+86
-24
@@ -19,7 +19,8 @@ try {
|
||||
) || {};
|
||||
} catch {}
|
||||
const params = new URLSearchParams(location.search),
|
||||
concept = concepts.find((c) => c.id === params.get("concept")) || concepts[0];
|
||||
concept = concepts[0];
|
||||
params.delete("concept");
|
||||
let theme =
|
||||
(params.get("theme") || preferences.theme) === "dark" ? "dark" : "light",
|
||||
density = ["compact", "normal", "relaxed"].includes(
|
||||
@@ -220,10 +221,15 @@ function persist() {
|
||||
}
|
||||
let toastTimer;
|
||||
function toast(message) {
|
||||
$("#toast").textContent = message;
|
||||
$("#toast").style.display = "block";
|
||||
const notification = $("#toast");
|
||||
notification.popover = "manual";
|
||||
notification.textContent = message;
|
||||
if (notification.matches(":popover-open")) notification.hidePopover();
|
||||
notification.showPopover();
|
||||
clearTimeout(toastTimer);
|
||||
toastTimer = setTimeout(() => ($("#toast").style.display = "none"), 3500);
|
||||
toastTimer = setTimeout(() => {
|
||||
notification.hidePopover();
|
||||
}, 3500);
|
||||
}
|
||||
function currentIdentity() {
|
||||
return identityAdapter.snapshot().account;
|
||||
@@ -256,14 +262,14 @@ ${currentIdentity()?.roles.some((r) => ["Master Admin", "SSO Admin"].includes(r)
|
||||
}
|
||||
function nav() {
|
||||
const dockBrand = `<button class="dock-toggle dock-brand wordmark" data-action="dock-toggle" aria-expanded="false" aria-controls="dock-navigation" aria-label="${t("Развернуть меню Anidev", "Expand Anidev navigation")}" title="${t("Навигация Anidev", "Anidev navigation")}"><b>a/</b><span>anidev</span></button>`;
|
||||
return `<aside class="navigation" id="dock-navigation">${concept.id === "dock" ? dockBrand : wordmark}<div class="workspace-label">ANIDEV / PRODUCTION</div><nav aria-label="${t("Основная навигация", "Main navigation")}" class="nav-links">${navigationPages()
|
||||
return `<aside class="navigation" id="dock-navigation">${dockBrand}<div class="workspace-label">ANIDEV / PRODUCTION</div><nav aria-label="${t("Основная навигация", "Main navigation")}" class="nav-links">${navigationPages()
|
||||
.map(
|
||||
(p) =>
|
||||
`<button data-page="${p}" ${page === p ? 'aria-current="page"' : ""} title="${pageNames[p]}" aria-label="${pageNames[p]}">${icon(p)}<span>${pageNames[p]}</span></button>`,
|
||||
)
|
||||
.join(
|
||||
"",
|
||||
)}</nav><div class="nav-bottom">eu-central-1<br>Workspace / Pro<br><button data-page="auth" style="font-size:12px;margin-top:15px">${t("Выйти", "Sign out")}</button></div>${concept.id === "dock" ? dockAccount() : ""}</aside>`;
|
||||
)}</nav><div class="nav-bottom">eu-central-1<br>Workspace / Pro<br><button data-page="auth" style="font-size:12px;margin-top:15px">${t("Выйти", "Sign out")}</button></div>${dockAccount()}</aside>`;
|
||||
}
|
||||
function header() {
|
||||
return `<header class="app-header"><button class="mobile-menu" data-action="mobile-menu" aria-label="${t("Открыть навигацию", "Open navigation")}" aria-expanded="false">☰</button><div class="breadcrumb">Anidev <span aria-hidden="true">/</span> ${accountPageIds.includes(page) ? t("Личный кабинет", "My account") : "Production"} <span aria-hidden="true">/</span> ${pageNames[page]}</div><div class="header-actions"><button class="command-trigger" data-action="command">${t("Найти команду", "Find a command")} <kbd>⌘ K</kbd></button><button class="avatar" data-action="profile" aria-label="${escape(accountName())}">${escape(accountInitials())}</button></div></header>`;
|
||||
@@ -273,7 +279,7 @@ const heading = (title, desc, actions = "") =>
|
||||
let dockHoverOpened = false;
|
||||
let dockCloseTimer;
|
||||
function bindDockHover() {
|
||||
if (concept.id !== "dock" || !$(".dock-toggle")) return;
|
||||
if (!$(".dock-toggle")) return;
|
||||
const nav = $(".navigation");
|
||||
nav.addEventListener("pointerenter", (e) => {
|
||||
if (
|
||||
@@ -292,7 +298,7 @@ function bindDockHover() {
|
||||
if (nav.contains(e.relatedTarget)) return;
|
||||
if (dockHoverOpened)
|
||||
dockCloseTimer = setTimeout(() => {
|
||||
if (!$("[popover]:popover-open")) {
|
||||
if (!$("[popover=auto]:popover-open")) {
|
||||
dockHoverOpened = false;
|
||||
setDockOpen(false, false);
|
||||
}
|
||||
@@ -305,7 +311,7 @@ function setDockOpen(open, returnFocus = true) {
|
||||
clearTimeout(dockCloseTimer);
|
||||
}
|
||||
const nav = $(".navigation");
|
||||
if (!nav || concept.id !== "dock") return;
|
||||
if (!nav) return;
|
||||
document.body.classList.toggle("dock-open", open);
|
||||
const toggle = $(".dock-toggle");
|
||||
toggle.setAttribute("aria-expanded", String(open));
|
||||
@@ -338,6 +344,7 @@ function savePreferences() {
|
||||
let initialRender = true;
|
||||
function render() {
|
||||
const route = new URL(location.href);
|
||||
route.searchParams.delete("concept");
|
||||
route.searchParams.set("page", page);
|
||||
route.searchParams.set("theme", theme);
|
||||
route.searchParams.set("locale", locale);
|
||||
@@ -375,10 +382,11 @@ function render() {
|
||||
$("#app").innerHTML =
|
||||
page === "auth"
|
||||
? auth()
|
||||
: `<div class="shell">${nav()}${concept.id === "dock" ? `<button class="dock-scrim" data-action="dock-close" tabindex="-1" aria-label="${t("Закрыть меню", "Close navigation")}" aria-hidden="true"></button>` : ""}<div class="main-column">${header()}<main id="content" tabindex="-1">${content}</main></div></div>`;
|
||||
: `<div class="shell">${nav()}<button class="dock-scrim" data-action="dock-close" tabindex="-1" aria-label="${t("Закрыть меню", "Close navigation")}" aria-hidden="true"></button><div class="main-column">${header()}<main id="content" tabindex="-1">${content}</main></div></div>`;
|
||||
bindForms();
|
||||
accountUI.bind(page);
|
||||
bindDockHover();
|
||||
bindCharts();
|
||||
if (page === "users" && $("#user-search")) bindUsers();
|
||||
}
|
||||
function chart() {
|
||||
@@ -392,7 +400,68 @@ function chart() {
|
||||
const points = values
|
||||
.map((v, i) => `${(i * 500) / (values.length - 1)},${145 - (v - 25) * 5}`)
|
||||
.join(" ");
|
||||
return `<div class="chart" role="img" aria-label="${t("Задержка p95: от 30 до 43 мс. Текущая 34 мс.", "p95 latency: 30 to 43 ms. Current 34 ms.")}"><svg viewBox="0 0 500 150" preserveAspectRatio="none" aria-hidden="true"><path class="chart-grid" d="M0 20H500M0 75H500M0 130H500"/><polygon class="chart-area" points="0,150 ${points} 500,150"/><polyline class="chart-line" points="${points}"/></svg><div class="axis-labels"><span>${chartRange === "24h" ? "00:00" : "21.11"}</span><span>${chartRange === "24h" ? "06:00" : "23.11"}</span><span>${chartRange === "24h" ? "12:00" : "25.11"}</span><span>${chartRange === "24h" ? "18:00" : "27.11"}</span></div></div><p class="chart-legend">${t("p95 · миллисекунды · ниже — лучше · тестовая выборка", "p95 · milliseconds · lower is better · sample dataset")}</p><details class="chart-data"><summary>${t("Числовые данные", "Numerical data")}</summary><div class="chart-data-scroll"><table><thead><tr><th>${t("Время UTC", "Time UTC")}</th><th>p95 / ms</th></tr></thead><tbody>${values.map((v, i) => `<tr><td>${chartRange === "24h" ? String(i).padStart(2, "0") + ":00" : 21 + i + ".11"}</td><td>${v}</td></tr>`).join("")}</tbody></table></div></details>`;
|
||||
return `<div class="chart" role="group" aria-label="${t("Задержка p95: от 30 до 43 мс. Текущая 34 мс.", "p95 latency: 30 to 43 ms. Current 34 ms.")}"><div class="chart-plot" tabindex="0" role="slider" aria-label="${t("Точка графика p95", "p95 chart point")}" aria-valuemin="0" aria-valuemax="${values.length - 1}" aria-valuenow="${values.length - 1}" data-values="${values.join(",")}" data-range="${chartRange}"><svg viewBox="0 0 500 150" preserveAspectRatio="none" aria-hidden="true"><path class="chart-grid" d="M0 20H500M0 75H500M0 130H500"/><polygon class="chart-area" points="0,150 ${points} 500,150"/><polyline class="chart-line" points="${points}"/></svg><span class="chart-guide" hidden></span><span class="chart-dot" hidden></span><div class="chart-tooltip" role="tooltip" hidden></div></div><div class="axis-labels"><span>${chartRange === "24h" ? "00:00" : "21.11"}</span><span>${chartRange === "24h" ? "06:00" : "23.11"}</span><span>${chartRange === "24h" ? "12:00" : "25.11"}</span><span>${chartRange === "24h" ? "18:00" : "27.11"}</span></div></div><p class="chart-legend">${t("p95 · миллисекунды · ниже — лучше · тестовая выборка", "p95 · milliseconds · lower is better · sample dataset")}</p><details class="chart-data"><summary>${t("Числовые данные", "Numerical data")}</summary><div class="chart-data-scroll"><table><thead><tr><th>${t("Время UTC", "Time UTC")}</th><th>p95 / ms</th></tr></thead><tbody>${values.map((v, i) => `<tr><td>${chartRange === "24h" ? String(i).padStart(2, "0") + ":00" : 21 + i + ".11"}</td><td>${v}</td></tr>`).join("")}</tbody></table></div></details>`;
|
||||
}
|
||||
function bindCharts() {
|
||||
document.querySelectorAll(".chart-plot").forEach((plot) => {
|
||||
const values = plot.dataset.values.split(",").map(Number);
|
||||
const tooltip = plot.querySelector(".chart-tooltip");
|
||||
const dot = plot.querySelector(".chart-dot");
|
||||
const guide = plot.querySelector(".chart-guide");
|
||||
let selected = values.length - 1;
|
||||
const label = (index) =>
|
||||
plot.dataset.range === "24h"
|
||||
? `${String(index).padStart(2, "0")}:00 UTC`
|
||||
: `${21 + index}.11`;
|
||||
const text = (index) =>
|
||||
`${label(index)} · ${values[index]} ${t("мс", "ms")}`;
|
||||
plot.setAttribute("aria-valuetext", text(selected));
|
||||
function show(index) {
|
||||
selected = Math.max(0, Math.min(values.length - 1, index));
|
||||
const x = (selected / (values.length - 1)) * plot.clientWidth;
|
||||
tooltip.textContent = text(selected);
|
||||
tooltip.hidden = dot.hidden = guide.hidden = false;
|
||||
tooltip.style.left = `${Math.max(0, Math.min(x - tooltip.offsetWidth / 2, plot.clientWidth - tooltip.offsetWidth))}px`;
|
||||
dot.style.left = guide.style.left = `${x}px`;
|
||||
dot.style.top = `${((145 - (values[selected] - 25) * 5) / 150) * 100}%`;
|
||||
plot.setAttribute("aria-valuenow", String(selected));
|
||||
plot.setAttribute("aria-valuetext", text(selected));
|
||||
}
|
||||
function hide() {
|
||||
tooltip.hidden = dot.hidden = guide.hidden = true;
|
||||
}
|
||||
function point(event) {
|
||||
const rect = plot.getBoundingClientRect();
|
||||
show(
|
||||
Math.round(
|
||||
((event.clientX - rect.left) / rect.width) * (values.length - 1),
|
||||
),
|
||||
);
|
||||
}
|
||||
plot.addEventListener("pointermove", point);
|
||||
plot.addEventListener("pointerdown", point);
|
||||
plot.addEventListener("pointerleave", hide);
|
||||
plot.addEventListener("focus", () => show(selected));
|
||||
plot.addEventListener("blur", hide);
|
||||
plot.addEventListener("keydown", (event) => {
|
||||
const moves = {
|
||||
ArrowLeft: selected - 1,
|
||||
ArrowDown: selected - 1,
|
||||
ArrowRight: selected + 1,
|
||||
ArrowUp: selected + 1,
|
||||
Home: 0,
|
||||
End: values.length - 1,
|
||||
};
|
||||
if (event.key === "Escape") {
|
||||
hide();
|
||||
return;
|
||||
}
|
||||
if (event.key in moves) {
|
||||
event.preventDefault();
|
||||
show(moves[event.key]);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
function dashboard() {
|
||||
return `${heading(t("Обзор инфраструктуры", "Infrastructure overview"), t("Production · 27 ноября 2026", "Production · November 27, 2026"), `<button data-action="activity">${t("Журнал событий", "Activity log")}</button><button class="primary" data-action="invite">${t("Пригласить участника", "Invite member")}</button>`)}
|
||||
@@ -555,7 +624,7 @@ function tokenScreen() {
|
||||
)
|
||||
.join(
|
||||
"",
|
||||
)}</div><pre class="code-block">:root {\n${cssVars(tokens)}\n}</pre><p class="compact-note">${t("Экспорт включает обе темы, JSON и CSS. Акцент применяется к каждой концепции отдельно.", "Export includes both themes, JSON and CSS. Each concept retains its own accent.")}</p></div>`;
|
||||
)}</div><pre class="code-block">:root {\n${cssVars(tokens)}\n}</pre><p class="compact-note">${t("Экспорт включает обе темы, JSON и CSS. Используется утверждённая палитра Dock.", "Export includes both themes, JSON and CSS. Uses the approved Dock palette.")}</p></div>`;
|
||||
}
|
||||
let dialogInitiator = null;
|
||||
function openDialog(title, body, cls = "") {
|
||||
@@ -778,7 +847,7 @@ document.addEventListener("click", async (e) => {
|
||||
if (!e.target.closest(".context-menu")) $(".context-menu")?.remove();
|
||||
if (!action) return;
|
||||
document
|
||||
.querySelectorAll("[popover]:popover-open")
|
||||
.querySelectorAll("[popover=auto]:popover-open")
|
||||
.forEach((el) => el.hidePopover());
|
||||
const actions = {
|
||||
shares: () =>
|
||||
@@ -796,15 +865,8 @@ document.addEventListener("click", async (e) => {
|
||||
setDockOpen(!document.body.classList.contains("dock-open"));
|
||||
},
|
||||
"dock-close": () => setDockOpen(false),
|
||||
"mobile-menu": () => {
|
||||
if (concept.id === "dock") {
|
||||
setDockOpen(!document.body.classList.contains("dock-open"));
|
||||
return;
|
||||
}
|
||||
const nav = $(".navigation");
|
||||
nav.classList.toggle("open");
|
||||
button.setAttribute("aria-expanded", nav.classList.contains("open"));
|
||||
},
|
||||
"mobile-menu": () =>
|
||||
setDockOpen(!document.body.classList.contains("dock-open")),
|
||||
close: () => $("#dialog").close(),
|
||||
invite,
|
||||
command,
|
||||
@@ -985,9 +1047,9 @@ document.addEventListener("click", async (e) => {
|
||||
});
|
||||
});
|
||||
document.addEventListener("keydown", (e) => {
|
||||
if (e.key === "Escape" && $("[popover]:popover-open")) {
|
||||
if (e.key === "Escape" && $("[popover=auto]:popover-open")) {
|
||||
e.preventDefault();
|
||||
$("[popover]:popover-open").hidePopover();
|
||||
$("[popover=auto]:popover-open").hidePopover();
|
||||
$(".dock-account")?.focus();
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user