Polish toasts and add searchable select and copy input

This commit is contained in:
SantaSpeen committed 2026-12-01 14:01:28 +03:00
1 parent 36f526aa02
commit 8e4e8e6ef0
28 files changed
+671 -17

No files matched your search

+42 -1
View File
@@ -1,3 +1,8 @@
import {
searchSelectMarkup,
mountSearchSelect,
environmentOptions,
} from "../components/search-select.js";
import { createNotifier } from "../components/toast.js";
import { sshScreen, mountSsh } from "../components/ssh-console.js";
import { logsScreen, mountLogs } from "../components/log-reader.js";
@@ -337,6 +342,10 @@ function setDockOpen(open, returnFocus = true) {
: t("Развернуть меню", "Expand navigation"),
);
toggle.title = toggle.getAttribute("aria-label");
if (open)
document
.querySelectorAll("[data-search-popup]:popover-open")
.forEach((popup) => popup.hidePopover());
$(".main-column").inert = open;
syncAdministration();
if (open) {
@@ -357,11 +366,14 @@ function savePreferences() {
);
} catch {}
}
let selectCleanups = [];
let workspaceCleanup = () => {},
workspaceRender = 0;
let initialRender = true;
function render({ preserveDock = false } = {}) {
workspaceCleanup();
selectCleanups.forEach((cleanup) => cleanup());
selectCleanups = [];
workspaceCleanup = () => {};
const workspaceVersion = ++workspaceRender;
const dockWasOpen =
@@ -418,6 +430,13 @@ function render({ preserveDock = false } = {}) {
bindDockHover();
if (dockWasOpen) setDockOpen(true, false);
bindCharts();
document
.querySelectorAll("[data-search-select]")
.forEach((root) =>
selectCleanups.push(
mountSearchSelect(root, { options: environmentOptions, t }),
),
);
if ($("#log-workspace"))
workspaceCleanup = mountLogs($("#log-workspace"), {
t,
@@ -655,7 +674,7 @@ function auth() {
function componentScreen() {
return `${heading(t("Библиотека компонентов", "Component library"), t("Единые компоненты и состояния Dock.", "Shared Dock components and states."), `<button data-action="command">${t("Команды", "Commands")} ${commandShortcut}</button>`)}<div class="page-body"><div class="library">
<section class="specimen"><h2>Buttons</h2><div class="component-row"><button class="primary" data-action="demo-save">${t("Сохранить", "Save")}</button><button data-action="toast">${t("Вторичная", "Secondary")}</button><button class="danger" data-action="delete">${t("Удалить", "Delete")}</button><button disabled>Disabled</button><button aria-busy="true" disabled>${t("Загрузка…", "Loading…")}</button></div><small>Hover · active · focus · disabled · loading</small></section>
<section class="specimen"><h2>Inputs & selects</h2><label class="field">${t("Имя проекта", "Project name")}<input placeholder="Anidev Production"></label><label class="field">Email<input aria-invalid="true" aria-describedby="sample-error" value="invalid-email"><small class="error-text" id="sample-error">${t("Введите корректный email", "Enter a valid email")}</small></label><div class="sample-control-row"><select aria-label="${t("Окружение", "Environment")}"><option>Production</option><option>Staging</option></select><input aria-label="${t("Только для чтения", "Read-only field")}" readonly value="Read only"></div></section>
<section class="specimen"><h2>Inputs & selects</h2><label class="field">${t("Имя проекта", "Project name")}<input placeholder="Anidev Production"></label><label class="field">Email<input aria-invalid="true" aria-describedby="sample-error" value="invalid-email"><small class="error-text" id="sample-error">${t("Введите корректный email", "Enter a valid email")}</small></label><div class="sample-control-row"><select aria-label="${t("Окружение", "Environment")}"><option>Production</option><option>Staging</option></select><input aria-label="${t("Только для чтения", "Read-only field")}" readonly value="Read only"></div><div class="search-select-example">${searchSelectMarkup({ id: "environment-search", name: "searchEnvironment", label: t("Окружение — с поиском", "Environment — searchable"), options: environmentOptions, value: "production", t })}</div><div class="field copy-field-example"><label for="copy-input-example">${t("Строка с копированием", "Field with copy action")}</label><div class="copy-input"><button type="button" class="input-copy-action" data-copy-input aria-label="${t("Скопировать значение", "Copy field value")}" title="${t("Скопировать значение", "Copy field value")}">${iconSvg("copy", { size: 16 })}</button><input id="copy-input-example" name="copyExample" value="anidev-production" autocomplete="off"></div></div></section>
<section class="specimen selection-specimen"><h2>Selection controls</h2><div class="form-row"><label class="choice-pill" for="check-demo"><input id="check-demo" type="checkbox" checked><span>${t("Email-уведомления", "Email notifications")}</span></label></div><fieldset style="border:0;padding:0"><legend>${t("Период хранения", "Retention period")}</legend><div class="component-row"><label class="choice-pill"><input type="radio" name="retention" value="30" checked><span>30 ${t("дней", "days")}</span></label><label class="choice-pill"><input type="radio" name="retention" value="90"><span>90 ${t("дней", "days")}</span></label></div></fieldset><div class="form-row"><label for="switch-demo">${t("Автообновление", "Auto refresh")}</label><input id="switch-demo" class="switch" role="switch" type="checkbox" checked></div></section>
<section class="specimen grouped-choice-specimen"><h2>${t("Группы чекбоксов", "Checkbox groups")}</h2>${[
"horizontal",
@@ -708,6 +727,9 @@ function tokenScreen() {
let dialogInitiator = null;
function openDialog(title, body, cls = "") {
if (document.body.classList.contains("dock-open")) setDockOpen(false, false);
document
.querySelectorAll("[data-search-popup]:popover-open")
.forEach((popup) => popup.hidePopover());
const d = $("#dialog");
if (d.open) d.close();
dialogInitiator = document.activeElement;
@@ -894,6 +916,25 @@ function contextMenu(x, y) {
}
document.addEventListener("click", async (e) => {
if (await accountUI.handleClick(e)) return;
const copyButton = e.target.closest("[data-copy-input]");
if (copyButton) {
const field = copyButton.closest(".copy-input").querySelector("input");
try {
await navigator.clipboard.writeText(field.value);
toast(t("Значение поля скопировано.", "Field value copied."), {
type: "success",
});
} catch {
toast(
t(
"Не удалось скопировать значение.",
"Could not copy the field value.",
),
{ type: "error" },
);
}
return;
}
const pageButton = e.target.closest("[data-page]");
if (pageButton) {
const fromDock = Boolean(pageButton.closest(".navigation"));