Separate guest and panel navigation and add account flyout
This commit is contained in:
1 parent
60b584b7c1
commit
5852bf1897
42 files changed
+1024
-55
No files matched your search
@@ -2,7 +2,9 @@
|
||||
|
||||
Уточнения Dock: переключатель 44×24px с бегунком 18px и равными отступами; перемещение и смена цвета — 160ms. Выпадающие и контекстные меню имеют скругление control и появление 180ms; reduced motion отключает анимацию. График показывает ближайшее время и p95 при наведении/касании; стрелки, Home/End и Escape доступны с клавиатуры. Числовая таблица сохранена. Тост использует manual popover в верхнем слое браузера и виден поверх модального затемнения.
|
||||
|
||||
Меню аккаунта содержит только Аккаунт, доступную по роли Панель управления, Сменить аккаунт и Выйти из SSO. Настройки и приложения доступны через навигацию личного кабинета.
|
||||
Меню аккаунта содержит Аккаунт, доступную по роли Панель управления, Сменить аккаунт и Выйти из SSO. Строка «Аккаунт» открывает управление при обычном клике; рядом появляется боковое подменю Управление/Безопасность/Устройства и сеансы/Приложения/Настройки. В переиспользуемом starter приложения не добавлены, пока нет отдельного модуля. Личные пункты больше не дублируются в основном Dock. Hover/ArrowRight/кнопка раскрытия открывают боковой список, Left/Escape возвращают к строке. На мобильном остаются две помещающиеся в viewport колонки.
|
||||
|
||||
Dock существует только при подтверждённом входе. Loading/guest/ошибка определения сессии — самостоятельный экран без панели, шапки и подложки. Пользовательский и административный контексты имеют разные основные меню; блокировка сервисов у вошедшего аккаунта сохраняет личные разделы. 401 закрывает overlays, отменяет запросы, очищает private content и скрывает shell.
|
||||
|
||||
Навигация Dock: выбранный пункт сохраняет цвет при наведении. «Администрирование» — disclosure-группа с SSH-консолью и логами. aria-expanded и aria-controls описывают её состояние; закрытые дети inert и aria-hidden. В узком Dock видна только иконка раздела. Переход на дочернюю страницу сохраняет раскрытие Dock и группы, повторный клик не пересоздаёт рабочую область. Enter/Space переключают группу, Right открывает и фокусирует первый пункт, Left закрывает, Up/Down перемещают фокус внутри группы. Escape сначала закрывает подменю, затем Dock; модифицированные стрелки сохраняют браузерное поведение. Переход по меню сохраняет раскрытую панель и режим открытия (hover или закрепление); Escape, подложка и уход мыши из hover-меню закрывают её.
|
||||
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
import { iconSvg } from "../icons/icons.js";
|
||||
import {
|
||||
accountSubmenuMarkup,
|
||||
mountAccountSubmenu,
|
||||
} from "./account-submenu.js";
|
||||
let sequence = 0;
|
||||
/** Fixed account controls live outside the API-driven service navigation. */
|
||||
export function mountAccountMenu(
|
||||
root,
|
||||
{ onNavigate, t = (ru) => ru, name = "", email = "" } = {},
|
||||
{ onNavigate, t = (ru) => ru, name = "", email = "", items } = {},
|
||||
) {
|
||||
if (typeof onNavigate !== "function")
|
||||
throw new TypeError("Account menu needs onNavigate");
|
||||
@@ -12,9 +16,28 @@ export function mountAccountMenu(
|
||||
id = `anidev-account-${++sequence}`;
|
||||
root.classList.add("dock-account-area");
|
||||
root.dataset.fixedAccount = "";
|
||||
root.innerHTML = `<div id="${id}" class="account-menu" popover="auto" role="menu" aria-label="${t("Меню аккаунта", "Account menu")}"><button type="button" role="menuitem" data-account-page="account">${iconSvg("profile", { size: 20 })}<span>${t("Аккаунт", "Account")}</span></button><button type="button" role="menuitem" data-account-page="account-settings">${iconSvg("settings", { size: 20 })}<span>${t("Настройки аккаунта", "Account settings")}</span></button></div><button type="button" class="dock-account" popovertarget="${id}" aria-haspopup="menu" aria-expanded="false" aria-controls="${id}" aria-label="${t("Открыть меню аккаунта", "Open account menu")}"><span class="avatar">${iconSvg("profile", { size: 20 })}</span><span class="account-identity"><b></b><small></small></span><span class="account-more" aria-hidden="true">···</span></button>`;
|
||||
items ||= [
|
||||
{ id: "account", label: t("Управление", "Management"), icon: "profile" },
|
||||
{
|
||||
id: "account-security",
|
||||
label: t("Безопасность", "Security"),
|
||||
icon: "security",
|
||||
},
|
||||
{
|
||||
id: "account-sessions",
|
||||
label: t("Устройства и сеансы", "Devices and sessions"),
|
||||
icon: "sessions",
|
||||
},
|
||||
{
|
||||
id: "account-settings",
|
||||
label: t("Настройки", "Settings"),
|
||||
icon: "settings",
|
||||
},
|
||||
];
|
||||
root.innerHTML = `<div id="${id}" class="account-menu" popover="auto" role="menu" aria-label="${t("Меню аккаунта", "Account menu")}">${accountSubmenuMarkup({ id: id + "-sections", items, t })}</div><button type="button" class="dock-account" popovertarget="${id}" aria-haspopup="menu" aria-expanded="false" aria-controls="${id}" aria-label="${t("Открыть меню аккаунта", "Open account menu")}"><span class="avatar">${iconSvg("profile", { size: 20 })}</span><span class="account-identity"><b></b><small></small></span><span class="account-more" aria-hidden="true">···</span></button>`;
|
||||
const popup = root.querySelector(".account-menu"),
|
||||
trigger = root.querySelector(".dock-account");
|
||||
const sections = mountAccountSubmenu(popup);
|
||||
function update(identity = {}) {
|
||||
root.querySelector(".account-identity b").textContent =
|
||||
identity.name || t("Аккаунт", "Account");
|
||||
@@ -23,6 +46,7 @@ export function mountAccountMenu(
|
||||
}
|
||||
update({ name, email });
|
||||
const close = (restore = false) => {
|
||||
sections.close();
|
||||
if (popup.matches(":popover-open")) popup.hidePopover();
|
||||
if (restore) trigger.focus({ preventScroll: true });
|
||||
};
|
||||
@@ -57,7 +81,9 @@ export function mountAccountMenu(
|
||||
}
|
||||
if (["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key)) {
|
||||
event.preventDefault();
|
||||
const items = [...popup.querySelectorAll("button")],
|
||||
const items = [...popup.querySelectorAll("button")].filter(
|
||||
(button) => !button.closest(".account-submenu"),
|
||||
),
|
||||
current = items.indexOf(document.activeElement);
|
||||
const index =
|
||||
event.key === "Home"
|
||||
@@ -79,7 +105,9 @@ export function mountAccountMenu(
|
||||
if (["ArrowDown", "ArrowUp"].includes(event.key)) {
|
||||
event.preventDefault();
|
||||
popup.showPopover();
|
||||
const buttons = popup.querySelectorAll("button");
|
||||
const buttons = [...popup.querySelectorAll("button")].filter(
|
||||
(button) => !button.closest(".account-submenu"),
|
||||
);
|
||||
buttons[event.key === "ArrowDown" ? 0 : buttons.length - 1].focus();
|
||||
}
|
||||
},
|
||||
@@ -102,13 +130,12 @@ export function mountAccountMenu(
|
||||
button.setAttribute("aria-current", "page");
|
||||
else button.removeAttribute("aria-current");
|
||||
});
|
||||
trigger.dataset.active = String(
|
||||
["account", "account-settings"].includes(id),
|
||||
);
|
||||
trigger.dataset.active = String(items.some((item) => item.id === id));
|
||||
},
|
||||
dispose() {
|
||||
close();
|
||||
abort.abort();
|
||||
sections.dispose();
|
||||
trigger.removeAttribute("popovertarget");
|
||||
},
|
||||
};
|
||||
|
||||
@@ -0,0 +1,233 @@
|
||||
import { iconSvg, iconNames } from "../icons/icons.js";
|
||||
const escape = (value) =>
|
||||
String(value).replace(
|
||||
/[&<>"']/g,
|
||||
(c) =>
|
||||
({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[
|
||||
c
|
||||
],
|
||||
);
|
||||
export function accountSubmenuMarkup({
|
||||
id,
|
||||
items,
|
||||
t = (ru) => ru,
|
||||
pageAttribute = "data-account-page",
|
||||
}) {
|
||||
if (
|
||||
!/^[a-z][\w-]*$/i.test(id) ||
|
||||
!["data-account-page", "data-page"].includes(pageAttribute) ||
|
||||
!Array.isArray(items) ||
|
||||
!items.length
|
||||
)
|
||||
throw new TypeError("Invalid account submenu");
|
||||
for (const item of items)
|
||||
if (!/^[a-z][\w-]*$/i.test(item.id) || !iconNames.includes(item.icon))
|
||||
throw new TypeError("Invalid account section");
|
||||
return `<div class="account-parent" data-account-parent><button type="button" class="account-parent-link" autofocus ${pageAttribute}="${items[0].id}" aria-haspopup="menu" aria-expanded="false" aria-controls="${id}">${iconSvg("profile", { size: 20 })}<span>${t("Аккаунт", "Account")}</span></button><button type="button" class="account-submenu-toggle" aria-label="${t("Разделы аккаунта", "Account sections")}" aria-expanded="false" aria-controls="${id}">${iconSvg("chevron-right", { size: 16 })}</button><div id="${id}" class="account-submenu" popover="auto" role="menu" aria-label="${t("Разделы аккаунта", "Account sections")}">${items.map((item) => `<button type="button" role="menuitem" ${pageAttribute}="${item.id}">${iconSvg(item.icon, { size: 20 })}<span>${escape(item.label)}</span></button>`).join("")}</div></div>`;
|
||||
}
|
||||
export function mountAccountSubmenu(parent) {
|
||||
const wrapper = parent.querySelector("[data-account-parent]"),
|
||||
row = wrapper.querySelector(".account-parent-link"),
|
||||
toggle = wrapper.querySelector(".account-submenu-toggle"),
|
||||
submenu = wrapper.querySelector(".account-submenu");
|
||||
const abort = new AbortController(),
|
||||
{ signal } = abort;
|
||||
const original = { width: parent.style.width, left: parent.style.left };
|
||||
let timer,
|
||||
frame,
|
||||
disposed = false;
|
||||
const open = () => submenu.matches(":popover-open");
|
||||
function fitParent() {
|
||||
const vw =
|
||||
window.visualViewport?.width || document.documentElement.clientWidth,
|
||||
ox = window.visualViewport?.offsetLeft || 0;
|
||||
if (parent.matches(":popover-open") && vw < 508) {
|
||||
parent.style.width = Math.max(100, Math.floor((vw - 36) / 2)) + "px";
|
||||
parent.style.left = ox + 12 + "px";
|
||||
} else {
|
||||
parent.style.width = original.width;
|
||||
parent.style.left = original.left;
|
||||
}
|
||||
}
|
||||
function position() {
|
||||
cancelAnimationFrame(frame);
|
||||
frame = requestAnimationFrame(() => {
|
||||
if (disposed || !open()) return;
|
||||
const viewport = window.visualViewport,
|
||||
vw = viewport?.width || document.documentElement.clientWidth,
|
||||
vh = viewport?.height || innerHeight,
|
||||
ox = viewport?.offsetLeft || 0,
|
||||
oy = viewport?.offsetTop || 0;
|
||||
let rect = parent.getBoundingClientRect(),
|
||||
width = Math.min(236, vw - 24);
|
||||
if (Math.max(ox + vw - rect.right, rect.left - ox) < width + 12) {
|
||||
width = Math.max(100, Math.floor((vw - 36) / 2));
|
||||
parent.style.width = width + "px";
|
||||
parent.style.left = ox + 12 + "px";
|
||||
rect = parent.getBoundingClientRect();
|
||||
}
|
||||
submenu.style.width = width + "px";
|
||||
submenu.style.maxHeight = Math.max(80, vh - 24) + "px";
|
||||
const left =
|
||||
ox + vw - rect.right >= width + 12
|
||||
? rect.right + 6
|
||||
: rect.left - width - 6;
|
||||
submenu.style.left =
|
||||
Math.max(ox + 12, Math.min(left, ox + vw - width - 12)) + "px";
|
||||
const h = submenu.getBoundingClientRect().height;
|
||||
submenu.style.top =
|
||||
Math.max(
|
||||
oy + 12,
|
||||
Math.min(row.getBoundingClientRect().top, oy + vh - h - 12),
|
||||
) + "px";
|
||||
});
|
||||
}
|
||||
function close(restore = false) {
|
||||
clearTimeout(timer);
|
||||
cancelAnimationFrame(frame);
|
||||
if (open()) submenu.hidePopover();
|
||||
fitParent();
|
||||
row.setAttribute("aria-expanded", "false");
|
||||
toggle.setAttribute("aria-expanded", "false");
|
||||
if (restore) row.focus({ preventScroll: true });
|
||||
}
|
||||
function show(focus = false) {
|
||||
if (disposed || !parent.matches(":popover-open")) return;
|
||||
clearTimeout(timer);
|
||||
if (!open()) submenu.showPopover();
|
||||
row.setAttribute("aria-expanded", "true");
|
||||
toggle.setAttribute("aria-expanded", "true");
|
||||
position();
|
||||
if (focus) submenu.querySelector("button").focus({ preventScroll: true });
|
||||
}
|
||||
function scheduleClose() {
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(() => {
|
||||
if (
|
||||
!submenu.contains(document.activeElement) &&
|
||||
!wrapper.matches(":hover")
|
||||
)
|
||||
close();
|
||||
}, 180);
|
||||
}
|
||||
wrapper.addEventListener(
|
||||
"pointerenter",
|
||||
(event) => {
|
||||
if (event.pointerType === "mouse" && matchMedia("(hover:hover)").matches)
|
||||
show();
|
||||
},
|
||||
{ signal },
|
||||
);
|
||||
wrapper.addEventListener(
|
||||
"pointerleave",
|
||||
(event) => {
|
||||
if (
|
||||
!wrapper.contains(event.relatedTarget) &&
|
||||
!submenu.contains(document.activeElement)
|
||||
)
|
||||
scheduleClose();
|
||||
},
|
||||
{ signal },
|
||||
);
|
||||
wrapper.addEventListener(
|
||||
"focusout",
|
||||
(event) => {
|
||||
if (!wrapper.contains(event.relatedTarget)) close();
|
||||
},
|
||||
{ signal },
|
||||
);
|
||||
toggle.addEventListener(
|
||||
"click",
|
||||
(event) => {
|
||||
event.stopPropagation();
|
||||
open() ? close() : show(true);
|
||||
},
|
||||
{ signal },
|
||||
);
|
||||
wrapper.addEventListener(
|
||||
"keydown",
|
||||
(event) => {
|
||||
const inSubmenu = submenu.contains(event.target);
|
||||
if (event.key === "ArrowRight" && !inSubmenu) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
show(true);
|
||||
}
|
||||
if (
|
||||
(inSubmenu || open()) &&
|
||||
["ArrowLeft", "Escape"].includes(event.key)
|
||||
) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
close(true);
|
||||
}
|
||||
if (
|
||||
inSubmenu &&
|
||||
["ArrowUp", "ArrowDown", "Home", "End"].includes(event.key)
|
||||
) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
const items = [...submenu.querySelectorAll("button")],
|
||||
index = items.indexOf(document.activeElement);
|
||||
items[
|
||||
event.key === "Home"
|
||||
? 0
|
||||
: event.key === "End"
|
||||
? items.length - 1
|
||||
: (index + (event.key === "ArrowDown" ? 1 : -1) + items.length) %
|
||||
items.length
|
||||
].focus();
|
||||
}
|
||||
if (inSubmenu && event.key === "Tab") close(true);
|
||||
},
|
||||
{ signal },
|
||||
);
|
||||
parent.addEventListener(
|
||||
"toggle",
|
||||
() => {
|
||||
fitParent();
|
||||
if (!parent.matches(":popover-open")) close();
|
||||
},
|
||||
{ signal },
|
||||
);
|
||||
submenu.addEventListener(
|
||||
"toggle",
|
||||
() => {
|
||||
if (!open()) close();
|
||||
},
|
||||
{ signal },
|
||||
);
|
||||
parent.addEventListener(
|
||||
"pointerleave",
|
||||
(event) => {
|
||||
if (
|
||||
!wrapper.contains(event.relatedTarget) &&
|
||||
!submenu.contains(document.activeElement)
|
||||
)
|
||||
scheduleClose();
|
||||
},
|
||||
{ signal },
|
||||
);
|
||||
window.addEventListener(
|
||||
"resize",
|
||||
() => {
|
||||
fitParent();
|
||||
position();
|
||||
},
|
||||
{ signal },
|
||||
);
|
||||
window.addEventListener("scroll", position, { signal, capture: true });
|
||||
window.visualViewport?.addEventListener("resize", position, { signal });
|
||||
window.visualViewport?.addEventListener("scroll", position, { signal });
|
||||
return {
|
||||
close,
|
||||
show,
|
||||
dispose() {
|
||||
close();
|
||||
parent.style.width = original.width;
|
||||
parent.style.left = original.left;
|
||||
disposed = true;
|
||||
abort.abort();
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -108,6 +108,7 @@ export async function exportSystem(
|
||||
"components/toast.js",
|
||||
"components/copy-field.js",
|
||||
"components/error-page.js",
|
||||
"components/account-submenu.js",
|
||||
"components/search-select.js",
|
||||
"components/workspaces.css",
|
||||
"components/ssh-console.js",
|
||||
|
||||
@@ -3118,6 +3118,110 @@ body[data-concept="dock"] .copy-input .input-copy-action:active {
|
||||
transform: none;
|
||||
}
|
||||
|
||||
.account-menu .account-parent {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) 32px;
|
||||
align-items: stretch;
|
||||
}
|
||||
.account-menu .account-parent > .account-submenu-toggle {
|
||||
padding: 8px;
|
||||
justify-content: center;
|
||||
min-width: 0;
|
||||
}
|
||||
.account-menu .account-parent-link {
|
||||
min-width: 0;
|
||||
width: 100%;
|
||||
}
|
||||
.account-menu .account-parent-link > span {
|
||||
min-width: 0;
|
||||
white-space: normal;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.account-submenu {
|
||||
position: fixed;
|
||||
inset: auto;
|
||||
margin: 0;
|
||||
padding: 6px;
|
||||
background: var(--color-surface);
|
||||
color: var(--color-text);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 12px 32px #07181f35;
|
||||
overflow-y: auto;
|
||||
}
|
||||
.account-submenu:popover-open {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
animation: account-flyout-enter 140ms ease-out;
|
||||
}
|
||||
.account-submenu button {
|
||||
border: 0;
|
||||
background: transparent;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
text-align: left;
|
||||
min-height: 44px;
|
||||
padding: 10px;
|
||||
white-space: normal;
|
||||
}
|
||||
.account-submenu button > svg {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.account-submenu button > span {
|
||||
overflow-wrap: anywhere;
|
||||
min-width: 0;
|
||||
}
|
||||
.account-submenu button:is(:hover, :focus-visible) {
|
||||
background: var(--color-row-hover);
|
||||
}
|
||||
.account-submenu [aria-current="page"] {
|
||||
background: var(--color-row-active);
|
||||
color: var(--color-accent);
|
||||
}
|
||||
@keyframes account-flyout-enter {
|
||||
from {
|
||||
opacity: 0;
|
||||
translate: -4px 0;
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
translate: 0 0;
|
||||
}
|
||||
}
|
||||
.guest-page {
|
||||
min-height: 100dvh;
|
||||
display: grid;
|
||||
place-content: center;
|
||||
padding: 24px;
|
||||
width: 100%;
|
||||
}
|
||||
.guest-page > .identity-gate {
|
||||
max-width: 560px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
body[data-session="loading"] .shell,
|
||||
body[data-session="guest"] .shell,
|
||||
body[data-session="unavailable"] .shell {
|
||||
display: none;
|
||||
}
|
||||
body[data-session="authenticated"] #session-screen {
|
||||
display: none;
|
||||
}
|
||||
#session-screen {
|
||||
min-height: 100dvh;
|
||||
padding: 24px;
|
||||
display: grid;
|
||||
place-content: center;
|
||||
}
|
||||
#session-screen .error-page {
|
||||
margin: 0 auto;
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.account-submenu:popover-open {
|
||||
animation: none;
|
||||
}
|
||||
}
|
||||
/* Fixed identity controls stay outside the API-driven service menu. */
|
||||
[data-fixed-account] {
|
||||
flex-shrink: 0;
|
||||
|
||||
Reference in new issue
Block a user