Package Anidev Skill and standalone API panel integration

This commit is contained in:
SantaSpeen committed 2026-12-01 14:42:44 +03:00
1 parent 8e4e8e6ef0
commit 61b05abe44
43 files changed
+1859 -57

No files matched your search

+13
View File
@@ -0,0 +1,13 @@
{
"defaultPage": "overview",
"items": [
{ "id": "overview", "label": "Обзор", "icon": "dashboard" },
{ "id": "projects", "label": "Проекты", "icon": "applications" },
{
"id": "administration",
"label": "Администрирование",
"icon": "server",
"children": [{ "id": "logs", "label": "Логи", "icon": "document" }]
}
]
}
+8
View File
@@ -0,0 +1,8 @@
{
"title": "Логи",
"description": "Последние события из тестового API.",
"rows": [
{ "label": "INFO · Identity", "value": "Сервис запущен" },
{ "label": "WARN · Gateway", "value": "Повтор запроса после таймаута" }
]
}
+9
View File
@@ -0,0 +1,9 @@
{
"title": "Обзор",
"description": "Состояние сервисов проекта. Все значения в этом примере — тестовые.",
"rows": [
{ "label": "Identity", "value": "Работает · 18 мс" },
{ "label": "License API", "value": "Работает · 34 мс" },
{ "label": "Edge Gateway", "value": "Работает · 12 мс" }
]
}
+8
View File
@@ -0,0 +1,8 @@
{
"title": "Проекты",
"description": "Доступные проекты из тестового API.",
"rows": [
{ "label": "Production", "value": "Основное окружение" },
{ "label": "Staging", "value": "Проверка изменений" }
]
}
+56
View File
@@ -0,0 +1,56 @@
.integration-form {
max-width: 440px;
display: grid;
gap: 20px;
margin-top: 32px;
padding-top: 24px;
border-top: 1px solid var(--color-border);
}
.integration-form .field {
margin: 0;
}
.integration-form > button {
justify-self: start;
}
.resource-row {
display: flex;
justify-content: space-between;
gap: 20px;
padding: 14px 12px;
border-bottom: 1px solid var(--color-border);
}
.resource-row:hover {
background: var(--color-row-hover);
}
.resource-row > span {
color: var(--color-muted);
text-align: right;
overflow-wrap: anywhere;
min-width: 0;
}
.resource-list {
max-width: 780px;
}
.nav-empty {
font-size: 13px;
padding: 8px;
opacity: 0;
}
body.dock-open .nav-empty {
opacity: 1;
}
@media (max-width: 600px) {
.app-header {
align-items: flex-start;
}
.header-actions {
flex-wrap: wrap;
justify-content: flex-end;
}
.resource-row {
flex-wrap: wrap;
}
.breadcrumb {
display: none;
}
}
+210
View File
@@ -0,0 +1,210 @@
import {
applyTheme,
iconSvg,
createNotifier,
mountCopyField,
mountDock,
mountNavigation,
searchSelectMarkup,
mountSearchSelect,
} from "./anidev/runtime/index.js";
const $ = (selector) => document.querySelector(selector),
t = (ru) => ru;
let theme = "light",
disposed = false,
menuRequest,
pageRequest;
const notify = createNotifier($("#project-toast"), { t });
const apiBase = new URL("./api/", import.meta.url);
const abort = new AbortController();
const { signal } = abort;
const cleanups = [];
function renderTheme() {
applyTheme({ theme });
$("#theme-toggle").innerHTML = iconSvg(theme === "light" ? "moon" : "sun", {
size: 20,
});
$("#theme-toggle").setAttribute(
"aria-label",
theme === "light" ? "Включить тёмную тему" : "Включить светлую тему",
);
}
renderTheme();
$("#theme-toggle").addEventListener(
"click",
() => {
theme = theme === "light" ? "dark" : "light";
renderTheme();
},
{ signal },
);
async function get(path, signal) {
const response = await fetch(new URL(path, apiBase), {
signal,
credentials: "same-origin",
headers: { Accept: "application/json" },
});
if (!response.ok) throw Error(`API: ${response.status}`);
return response.json();
}
const pageIds = new Set(["overview", "projects", "logs"]);
async function showPage(id) {
pageRequest?.abort();
const request = (pageRequest = new AbortController());
const container = $("#page-data");
container.replaceChildren();
$("#page-title").textContent = id ? "Загрузка…" : "Нет доступных разделов";
$("#page-description").textContent = id
? "Получаем данные раздела."
: "Обратитесь к администратору за доступом.";
if (!id) {
container.setAttribute("aria-busy", "false");
return;
}
container.setAttribute("aria-busy", "true");
try {
if (!pageIds.has(id)) throw Error("Section module is not installed");
const data = await get(`pages/${id}.json`, request.signal);
if (disposed || request !== pageRequest) return;
if (
typeof data.title !== "string" ||
typeof data.description !== "string" ||
!Array.isArray(data.rows)
)
throw Error("Invalid page response");
$("#page-title").textContent = data.title;
$("#page-description").textContent = data.description;
const list = document.createElement("div");
list.className = "resource-list";
for (const row of data.rows.slice(0, 100)) {
if (typeof row.label !== "string" || typeof row.value !== "string")
throw Error("Invalid row response");
const item = document.createElement("div");
item.className = "resource-row";
const label = document.createElement("strong"),
value = document.createElement("span");
label.textContent = row.label;
value.textContent = row.value;
item.append(label, value);
list.append(item);
}
container.append(list);
if (!data.rows.length)
container.textContent = "В этом разделе пока нет данных.";
} catch (error) {
if (error.name === "AbortError" || disposed || request !== pageRequest)
return;
$("#page-title").textContent = "Раздел недоступен";
$("#page-description").textContent =
"Не удалось получить данные. Попробуйте ещё раз.";
const retry = document.createElement("button");
retry.textContent = "Повторить";
retry.addEventListener("click", () => showPage(id), { once: true });
container.append(retry);
} finally {
if (request === pageRequest) container.setAttribute("aria-busy", "false");
}
}
const dock = mountDock({
navigation: $(".navigation"),
main: $(".main-column"),
trigger: $(".dock-brand"),
scrim: $(".dock-scrim"),
t,
});
const navigation = mountNavigation($(".nav-links"), {
t,
onActiveChange: showPage,
onSelect: (id) => {
const url = new URL(location.href);
url.searchParams.set("page", id);
history.pushState({}, "", url);
},
});
async function refreshNavigation() {
menuRequest?.abort();
const request = (menuRequest = new AbortController());
$("#connection-status").textContent = "Обновляем доступные разделы…";
try {
const data = await get("navigation.json", request.signal);
if (disposed || request !== menuRequest) return;
const preferred =
new URL(location.href).searchParams.get("page") ||
navigation.activeId ||
data.defaultPage;
navigation.setItems(data.items, { activeId: preferred });
const url = new URL(location.href);
if (navigation.activeId) url.searchParams.set("page", navigation.activeId);
else url.searchParams.delete("page");
history.replaceState({}, "", url);
$("#connection-status").textContent =
"Пример: данные получены из тестового API.";
} catch (error) {
if (error.name === "AbortError" || disposed || request !== menuRequest)
return;
$("#connection-status").textContent =
"Не удалось обновить разделы. Попробуйте ещё раз; доступное меню сохранено.";
notify("Не удалось загрузить доступные разделы.", { type: "error" });
}
}
$("#refresh-navigation").addEventListener("click", refreshNavigation, {
signal,
});
window.addEventListener(
"popstate",
() => {
try {
navigation.setActive(new URL(location.href).searchParams.get("page"));
} catch {
refreshNavigation();
}
},
{ signal },
);
const options = [
{ value: "production", label: "Production" },
{ value: "staging", label: "Staging" },
{ value: "development", label: "Development" },
{ value: "preview", label: "Preview" },
];
$("#environment-control").innerHTML = searchSelectMarkup({
id: "project-environment",
name: "environment",
label: "Окружение",
options,
value: "production",
t,
});
cleanups.push(mountSearchSelect($("#project-environment"), { options, t }));
$("[data-copy-input]").innerHTML = iconSvg("copy", { size: 16 });
cleanups.push(mountCopyField($(".copy-input"), { notify, t }));
$("#check-settings").addEventListener(
"click",
() =>
notify("Поля заполнены. Пример не отправляет изменения на сервер.", {
type: "info",
}),
{ signal },
);
refreshNavigation();
function dispose() {
if (disposed) return;
disposed = true;
menuRequest?.abort();
pageRequest?.abort();
abort.abort();
cleanups.forEach((cleanup) => cleanup());
navigation.dispose();
dock.dispose();
notify.dispose();
}
window.addEventListener(
"pagehide",
(e) => {
if (!e.persisted) dispose();
},
{ signal },
);
+92
View File
@@ -0,0 +1,92 @@
<!doctype html>
<html lang="ru">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>Anidev — панель проекта</title>
<link rel="stylesheet" href="./anidev/tokens/dock/light.css" />
<link rel="stylesheet" href="./anidev/components/system.css" />
<link rel="stylesheet" href="./app.css" />
</head>
<body data-concept="dock" data-theme="light">
<a class="skip" href="#content">Перейти к содержимому</a>
<div class="shell">
<aside
class="navigation"
id="project-navigation"
aria-label="Разделы проекта"
>
<button
type="button"
class="dock-toggle dock-brand wordmark"
aria-controls="project-navigation"
aria-expanded="false"
aria-label="Развернуть меню"
>
<b>a/</b><span>anidev</span>
</button>
<nav class="nav-links" aria-label="Основная навигация"></nav>
</aside>
<div class="main-column">
<header class="app-header">
<div class="breadcrumb">Anidev / Панель проекта</div>
<div class="header-actions">
<button type="button" id="refresh-navigation">
Обновить разделы</button
><button
type="button"
id="theme-toggle"
aria-label="Включить тёмную тему"
></button>
</div>
</header>
<main id="content" tabindex="-1">
<div class="page-heading">
<div>
<h1 id="page-title">Панель проекта</h1>
<p id="page-description">Загружаем доступные разделы…</p>
</div>
</div>
<p id="connection-status" role="status" class="muted"></p>
<div id="page-data" aria-busy="false"></div>
<section
class="integration-form"
aria-labelledby="project-settings-title"
>
<h2 id="project-settings-title">Настройки проекта</h2>
<div id="environment-control"></div>
<div class="field">
<label for="project-id">Идентификатор проекта</label>
<div class="copy-input">
<button
type="button"
class="input-copy-action"
data-copy-input
aria-label="Скопировать идентификатор"
title="Скопировать идентификатор"
></button
><input id="project-id" value="anidev-production" readonly />
</div>
</div>
<fieldset class="choice-fieldset">
<legend>Уведомления</legend>
<div class="choice-group">
<label class="choice-group-option"
><input type="checkbox" checked /><span>Email</span></label
><label class="choice-group-option"
><input type="checkbox" /><span>Push</span></label
>
</div>
</fieldset>
<button type="button" class="primary" id="check-settings">
Проверить настройки
</button>
</section>
</main>
</div>
</div>
<div class="dock-scrim" aria-hidden="true"></div>
<div id="project-toast"></div>
<script type="module" src="./app.js"></script>
</body>
</html>