// CMS application adapter. Shared component implementation belongs to @nodedc packages. import React from "react"; import { renderToStaticMarkup as html } from "react-dom/server"; import { readFile, writeFile } from "node:fs/promises"; import { createHash } from "node:crypto"; import { fileURLToPath } from "node:url"; import { build } from "esbuild"; import { AppHeader, HeaderNavigation, HeaderProfile, HeaderAvatar, ApplicationShell, ApplicationPanel, AdminNavigationPanel, Button, IconButton, Icon, StatusBadge, FieldFrame, TextField, Switch, SettingsCard, GlassSurface, MediaSourceField, DragHandle } from "@nodedc/ui-react"; const h = React.createElement, noop = () => { }, root = fileURLToPath(new URL("../", import.meta.url)); const read = (p) => readFile(new URL(p, import.meta.url), "utf8"); const lock = JSON.parse(await read("design-system.lock.json")); for (const [name, hash] of Object.entries(lock.packages)) { if (createHash("sha256").update(await readFile(new URL(`vendor/${name}`, import.meta.url))).digest("hex") !== hash) throw Error(`Design package mismatch: ${name}`); } const icon = (name) => h(Icon, { name }); const btn = (id, label, variant = "secondary") => h(Button, { id, variant, tone: "neutral" }, label); const ib = (id, label, name) => h(IconButton, { id, label }, icon(name)); const header = h(AppHeader, { brand: h("img", { src: "./nodedc-logo.svg", alt: "NODE.DC" }), brandMonochrome: true, left: ib("toggle-navigation", "\u041F\u043E\u043A\u0430\u0437\u0430\u0442\u044C \u0440\u0430\u0437\u0434\u0435\u043B\u044B", "panel"), center: h(HeaderNavigation, { label: "\u0420\u0430\u0437\u0434\u0435\u043B\u044B CMS", value: "content", onChange: noop, items: [["content", "\u041A\u043E\u043D\u0442\u0435\u043D\u0442"], ["seo", "SEO"], ["knowledge", "\u0411\u0430\u0437\u0430 \u0437\u043D\u0430\u043D\u0438\u0439"]].map(([value, label]) => ({ value, label: h("span", { "data-cms-mode": value }, label) })) }), right: h("span", { id: "cms-profile", className: "cms-ui-island" }) }); const siteContext = h("div", { className: "cms-site-context" }, h("select", { id: "site-selector", "aria-label": "Выбрать сайт" }), h("a", { id: "site-preview", className: "nodedc-icon-button", "aria-label": "Открыть сайт", title: "Открыть сайт", target: "_blank", rel: "noopener" }, icon("external")), ib("project-settings", "Настройки сайта", "settings"), h("span", { id: "workspace-name", hidden: true }, "NODE.DC"), h("span", { id: "workspace-role", hidden: true }, "Администратор сайта"), h("span", { id: "cms-add-block-parking", hidden: true }, ib("add-block", "Добавить блок", "plus")) ); const nav = h(AdminNavigationPanel, { eyebrow: "NODE.DC / CMS", title: h("span", { id: "sidebar-title" }, "\u0410\u0434\u043C\u0438\u043D\u0438\u0441\u0442\u0440\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0435"), headerActions: ib("add-project", "\u0414\u043E\u0431\u0430\u0432\u0438\u0442\u044C \u0441\u0430\u0439\u0442", "plus"), contextSlot: siteContext, items: [], onClose: noop, onItemChange: noop }); const actions = h("div", { className: "cms-editor-actions" }, h(StatusBadge, { id: "dirty-state", "data-dirty": "false" }, "\u0421\u0438\u043D\u0445\u0440\u043E\u043D\u0438\u0437\u0438\u0440\u043E\u0432\u0430\u043D\u043E"), ib("reload", "\u041F\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044C \u0434\u0430\u043D\u043D\u044B\u0435", "refresh"), btn("save", "\u0421\u043E\u0445\u0440\u0430\u043D\u0438\u0442\u044C \u043C\u043E\u0434\u0435\u043B\u044C", "primary"), btn("render", "\u041E\u0431\u043D\u043E\u0432\u0438\u0442\u044C \u0441\u0430\u0439\u0442"), h(Button, { id: "publish", className: "hidden", tone: "neutral" }, "\u041E\u043F\u0443\u0431\u043B\u0438\u043A\u043E\u0432\u0430\u0442\u044C"), h(Button, {id: "download-backup", variant: "secondary", tone: "neutral", className: "hidden"}, "Скачать бэкап")); const content = h(ApplicationPanel, { eyebrow: h("span", { id: "editor-heading" }, "\u041D\u0430\u0441\u0442\u0440\u043E\u0439\u043A\u0438 \u0441\u0430\u0439\u0442\u0430"), title: "\u041A\u043E\u043D\u0442\u0435\u043D\u0442", description: "\u0412\u044B\u0431\u0435\u0440\u0438\u0442\u0435 \u0440\u0430\u0437\u0434\u0435\u043B", headerTools: actions, expanded: true, onClose: noop }, h("div", { className: "cms-editor", dangerouslySetInnerHTML: { __html: await read("editor.html") } })); const shell = html(h(ApplicationShell, { id: "cms-shell", header, stage: h("div", { className: "cms-stage" }, h("p", null, "\u0423\u043F\u0440\u0430\u0432\u043B\u0435\u043D\u0438\u0435 \u0441\u0430\u0439\u0442\u0430\u043C\u0438 NODE.DC"), btn("open-navigation", "\u041E\u0442\u043A\u0440\u044B\u0442\u044C \u0440\u0430\u0437\u0434\u0435\u043B\u044B")), navigation: nav, content, navigationOpen: true, contentOpen: true, contentExpanded: true })); const icons = ["close", "plus", "chevron-up", "chevron-down", "copy", "clipboard", "trash", "eye", "eye-off", "layers", "panel", "file", "settings", "folder", "image", "video", "refresh", "move", "edit"]; const templates = Object.entries({ settingRow: h(SettingsCard, { title: "Настройка", actions: h("span", { "data-slot": "control" }) }), nestedSurface: h(GlassSurface, {tone:"group", padding:"md", materialRim:false}, h("span")), dragHandle: h(DragHandle, {label:"Перетащить блок"}), button: h(Button, null, "\u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0435"), iconButton: h(IconButton, { label: "\u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0435" }, icon("plus")), field: h(FieldFrame, { label: "\u041F\u043E\u043B\u0435" }, h("span", { "data-slot": "control" })), text: h(TextField, { id: "template-field", label: "\u041F\u043E\u043B\u0435" }), card: h(SettingsCard, { eyebrow: "\u0420\u0430\u0437\u0434\u0435\u043B", title: "\u041D\u0430\u0437\u0432\u0430\u043D\u0438\u0435", description: "\u041E\u043F\u0438\u0441\u0430\u043D\u0438\u0435" }, h("div", { "data-slot": "body" })), media: h(MediaSourceField, { label: "\u041C\u0435\u0434\u0438\u0430", source: "file", url: "", onSourceChange: noop, onUrlChange: noop, onFileChange: noop }), ...Object.fromEntries(icons.map((name) => ["icon-" + name, icon(name)])) }).map(([name, node]) => `${html(node)}`).join("\n"); const page = `