Serve Dock directly and add explicit navigation feedback

This commit is contained in:
SantaSpeen committed 2026-11-30 21:12:40 +03:00
1 parent 645afe3ebf
commit 84c4b3030a
77 files changed
+477 -920

No files matched your search

+75 -7
View File
@@ -7,12 +7,27 @@ import {
createAccountUI,
accountPageIds,
} from "../components/account-pages.js";
import { exportSystem } from "../components/export-system.js";
const identityAdapter = createDemoIdentityAdapter();
let preferences = {};
try {
preferences =
JSON.parse(
localStorage.getItem("anidev.preferences") ||
localStorage.getItem("anidev.lab") ||
"{}",
) || {};
} catch {}
const params = new URLSearchParams(location.search),
concept = concepts.find((c) => c.id === params.get("concept")) || concepts[0];
let theme = params.get("theme") === "dark" ? "dark" : "light",
density = params.get("density") || "normal",
locale = params.get("locale") === "en" ? "en" : "ru";
let theme =
(params.get("theme") || preferences.theme) === "dark" ? "dark" : "light",
density = ["compact", "normal", "relaxed"].includes(
params.get("density") || preferences.density,
)
? params.get("density") || preferences.density
: "compact",
locale = (params.get("locale") || preferences.locale) === "en" ? "en" : "ru";
const rawAccent = params.get("accent"),
accent = /^#[0-9a-f]{6}$/i.test(rawAccent)
? rawAccent
@@ -312,7 +327,30 @@ function setDockOpen(open, returnFocus = true) {
if (returnFocus) toggle.focus();
}
}
function savePreferences() {
try {
localStorage.setItem(
"anidev.preferences",
JSON.stringify({ theme, density, locale }),
);
} catch {}
}
let initialRender = true;
function render() {
const route = new URL(location.href);
route.searchParams.set("page", page);
route.searchParams.set("theme", theme);
route.searchParams.set("locale", locale);
if (route.href !== location.href) {
history[
initialRender ||
route.searchParams.get("page") ===
new URL(location.href).searchParams.get("page")
? "replaceState"
: "pushState"
]({}, "", route);
}
initialRender = false;
dockHoverOpened = false;
clearTimeout(dockCloseTimer);
document.body.classList.remove("dock-open");
@@ -508,7 +546,7 @@ function componentScreen() {
<section class="specimen"><h2>Chart</h2>${chart()}</section></div><p class="compact-note">${t("Таблицы, пагинация и фильтры — на экране «Пользователи»; вкладки — в настройках; форма входа — в авторизации.", "Tables, pagination and filters: Users. Tabs: Settings. Sign-in form: Authentication.")}</p></div>`;
}
function tokenScreen() {
return `${heading(t("Дизайн-токены", "Design tokens"), `${concept.name} / ${theme} / ${density}`, `<button data-action="copy-json">${t("Копировать JSON", "Copy JSON")}</button><button class="primary" data-action="copy-css">${t("Копировать CSS", "Copy CSS")}</button>`)}<div class="page-body"><div class="tokens-list">${Object.entries(
return `${heading(t("Дизайн-токены", "Design tokens"), `${concept.name} / ${theme} / ${density}`, `<button data-action="download-system">${t("Экспорт системы", "Export system")}</button><button data-action="copy-json">${t("Копировать JSON", "Copy JSON")}</button><button class="primary" data-action="copy-css">${t("Копировать CSS", "Copy CSS")}</button>`)}<div class="page-body"><div class="tokens-list">${Object.entries(
tokens,
)
.map(
@@ -517,7 +555,7 @@ function tokenScreen() {
)
.join(
"",
)}</div><pre class="code-block">:root {\n${cssVars(tokens)}\n}</pre><p class="compact-note">${t("Экспорт галереи включает обе темы, JSON и CSS. Акцент применяется к каждой концепции отдельно.", "Gallery 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. Акцент применяется к каждой концепции отдельно.", "Export includes both themes, JSON and CSS. Each concept retains its own accent.")}</p></div>`;
}
let dialogInitiator = null;
function openDialog(title, body, cls = "") {
@@ -772,6 +810,24 @@ document.addEventListener("click", async (e) => {
command,
activity: () => $("#activity").scrollIntoView({ behavior: "smooth" }),
profile: () => navigate("profile"),
"download-system": async () => {
button.disabled = true;
try {
await exportSystem(
{ page, theme, density, locale, accent: rawAccent || undefined },
toast,
);
} catch {
toast(
t(
"Экспорт не удался. Повторите попытку.",
"Export failed. Try again.",
),
);
} finally {
button.disabled = false;
}
},
prev: () => {
userPage--;
refreshUsers();
@@ -1074,8 +1130,7 @@ const accountUI = createAccountUI({
document.documentElement.style.cssText = cssVars(tokens);
document.body.dataset.theme = theme;
render();
if (parent !== window)
parent.postMessage({ type: "anidev-theme", theme }, location.origin);
savePreferences();
},
});
if (identityStates.includes(params.get("identityState")))
@@ -1086,4 +1141,17 @@ addEventListener("storage", (e) => {
render();
}
});
addEventListener("popstate", () => {
const route = new URL(location.href);
page = Object.keys(pageNames).includes(route.searchParams.get("page"))
? route.searchParams.get("page")
: "dashboard";
theme = route.searchParams.get("theme") === "dark" ? "dark" : "light";
tokens = tokensFor("dock", theme, rawAccent || undefined, density);
document.documentElement.style.cssText = cssVars(tokens);
document.body.dataset.theme = theme;
initialRender = true;
$("#dialog").close();
render();
});
render();