diff --git a/docs/ui-design-system.md b/docs/ui-design-system.md index cec7366b..70f45506 100644 --- a/docs/ui-design-system.md +++ b/docs/ui-design-system.md @@ -39,3 +39,17 @@ NODE_PATH=/tmp/csai-ui-tools/node_modules node scripts/check-ui-design-system.cj 检查 1440、1024、390、360px 四档屏宽和深浅主题,验证抽屉边界、内部横向溢出、底栏、嵌套层级、展开、键盘关闭、焦点返回,以及主页面横向溢出。 截图与结果默认写入系统临时目录,也可通过 `CSAI_UI_ARTIFACTS` 指定目录。 这覆盖界面布局和公共交互,不等同于真实后端数据、保存操作、所有下拉菜单状态或物理手机软键盘的完整验收。 + +### 真实数据形态回归(Kali 界面验收后补充) + +`check-ui-design-system.cjs` 现在调用 `ui-realistic-scenarios.cjs`,并加载真实 i18next/翻译实现。 +回归数据依据实际页面的数量、文本长度和按钮状态匿名构造,不复制目标地址、凭据或业务证据。 + +- 365 条队列任务,分别渲染暂停、运行、完成状态;验证真实操作按钮不会挤压标题或越界。 +- 626 个工具、614 个已启用工具及长描述;使用真实角色编辑入口检查统计换行和正文滚动。 +- 角色与多文件 Skill 的新增/编辑切换,以及打开编辑后跨越桌面/手机断点;验证翻译刷新不改变编辑标题。 +- 深度测评的原生 dialog 创建和详情入口:公共样式、宽度展开、Escape 关闭、展开状态重置和稳定的可访问名称。 +- 50 条长漏洞记录和三页分页:验证手机整页滚动,标题与分页不会固定占用记录区。 + +所有场景都在四档屏宽与两种主题下运行;夹具请求拒绝非 GET 操作。 +需要定位单个断点时可设置 `CSAI_UI_WIDTHS=390`;提交前省略该变量运行完整矩阵。 diff --git a/scripts/check-ui-design-system.cjs b/scripts/check-ui-design-system.cjs index 1a964e8f..5cfc91fb 100644 --- a/scripts/check-ui-design-system.cjs +++ b/scripts/check-ui-design-system.cjs @@ -17,7 +17,7 @@ const html = fs .replace(/\{\{\.Version\}\}/g, "UI preview") .replace( "", - '', + '', ); const server = http.createServer((req, res) => { const p = req.url.split("?")[0]; @@ -49,18 +49,22 @@ const server = http.createServer((req, res) => { const browser = await chromium.launch({ headless: true }); const findings = []; let count = 0; - for (const width of [1440, 1024, 390, 360]) + for (const width of process.env.CSAI_UI_WIDTHS + ? process.env.CSAI_UI_WIDTHS.split(",").map(Number) + : [1440, 1024, 390, 360]) for (const theme of ["light", "dark"]) { const height = width === 360 ? 640 : width === 390 ? 844 : width === 1024 ? 768 : 900; const page = await browser.newPage({ viewport: { width, height }, colorScheme: theme, + locale: "zh-CN", }); page.on("pageerror", (e) => findings.push({ width, theme, issue: e.message }), ); await page.goto("http://127.0.0.1:" + server.address().port); + await page.evaluate(() => window.i18nReady); await page.evaluate( (catalog) => { window.t = (key, opts = {}) => { @@ -343,6 +347,13 @@ const server = http.createServer((req, res) => { path: out + "/" + id + "-" + width + "-" + theme + ".png", }); } + await require("./ui-realistic-scenarios.cjs")({ + page, + width, + height, + theme, + out, + }); await page.close(); } fs.writeFileSync( diff --git a/scripts/ui-realistic-scenarios.cjs b/scripts/ui-realistic-scenarios.cjs new file mode 100644 index 00000000..88df0c0b --- /dev/null +++ b/scripts/ui-realistic-scenarios.cjs @@ -0,0 +1,328 @@ +// Anonymized reproductions of the real Kali UI states: 365 tasks, 626 tools, +// 614 enabled tools, multi-file skill, 50 long findings. All writes are rejected. +const assert = require("node:assert/strict"); +module.exports = async function ({ page, width, height, theme, out }) { + for (const script of [ + "tasks", + "skills", + "deep-assessments", + "vulnerability", + "vulnerability-workspace", + ]) + await page.addScriptTag({ url: "/static/js/" + script + ".js" }); + await page.evaluate(() => { + const tools = Array.from({ length: 626 }, (_, i) => ({ + name: "review_tool_" + i, + description: "检查授权范围内的接口、权限和配置,保留可复核证据。".repeat( + 4, + ), + enabled: i < 614, + })); + const role = { + name: "界面回归角色", + description: "真实规模的长描述与工具清单", + enabled: true, + tools: [], + user_prompt: "根据已有证据整理报告。".repeat(12), + }; + const assessment = { + id: "assessment-fixture", + name: "授权评估回归任务", + status: "draft", + revision: 1, + steps: [], + objective: "检查已有数据的布局", + scope: "离线界面回归", + updated_at: "2026-11-15T08:00:00Z", + }; + const queue = { + id: "ui-fixture", + title: "多目标授权评估回归队列", + status: "paused", + role: role.name, + agentMode: "single", + scheduleMode: "manual", + concurrency: 2, + totalTasks: 365, + completedTasks: 34, + createdAt: "2026-11-10T13:01:13Z", + tasks: Array.from({ length: 365 }, (_, i) => ({ + id: "task-" + i, + status: i < 34 ? "completed" : "pending", + message: + "https://long-service-name-" + i + ".example.test/verification", + })), + }; + window.fixtureQueue = queue; + window.apiFetch = async (input, opts = {}) => { + if (opts.method && opts.method !== "GET") + throw new Error("UI regression must not write: " + input); + const url = new URL(input, location.origin); + let data = {}; + if (url.pathname === "/api/roles") data = { roles: [role] }; + else if (url.pathname === "/api/config/tools") { + const size = Number(url.searchParams.get("page_size") || 20), + index = Number(url.searchParams.get("page") || 1); + data = { + tools: tools.slice((index - 1) * size, index * size), + total: 626, + total_enabled: 614, + total_pages: Math.ceil(626 / size), + page: index, + page_size: size, + }; + } else if (url.pathname === "/api/batch-tasks/ui-fixture") + data = { queue }; + else if (url.pathname.endsWith("/files")) + data = { + files: [ + { path: "SKILL.md" }, + { path: "references/long-reference-name.md" }, + { path: "assets/README.txt" }, + ], + }; + else if (url.pathname.startsWith("/api/skills/")) + data = { + skill: { + id: "review-skill", + description: "多文件技能包编辑测试", + content: "# 审核步骤\n" + "核对已有证据。\n".repeat(40), + }, + }; + else if (url.pathname === "/api/deep-assessments/options") + data = { + roles: [role.name], + models: ["默认模型"], + projects: [{ id: "ui-project", name: "回归项目" }], + }; + else if (url.pathname === "/api/deep-assessments") + data = { tasks: [assessment], has_more: false }; + else if (url.pathname === "/api/deep-assessments/assessment-fixture") + data = { task: assessment }; + else if (url.pathname.endsWith("/graph")) + data = { nodes: [], edges: [], total: 0, folded: 0, has_more: false }; + return { ok: true, json: async () => data }; + }; + window.showNotification = (message, type) => { + if (type === "error") throw new Error(message); + }; + roles = [role]; + }); + const activate = async (id) => + page.evaluate( + (id) => + document + .querySelectorAll(".page") + .forEach((e) => e.classList.toggle("active", e.id === id)), + id, + ); + const shot = async (name) => + page.screenshot({ + animations: "disabled", + path: `${out}/real-${name}-${width}-${theme}.png`, + }); + await activate("page-tasks"); + for (const state of ["paused", "running", "completed"]) { + await page.evaluate(async (state) => { + fixtureQueue.status = state; + await showBatchQueueDetail("ui-fixture"); + }, state); + await page + .locator("#batch-queue-detail-content .batch-task-item") + .first() + .waitFor(); + const layout = await page + .locator("#batch-queue-detail-modal .modal-header") + .evaluate((e) => { + const title = e.querySelector("h2").getBoundingClientRect(), + header = e.getBoundingClientRect(); + const controls = Array.from(e.querySelectorAll("button")) + .filter((b) => b.getClientRects().length) + .map((b) => b.getBoundingClientRect()); + return { + titleWidth: title.width, + headerHeight: header.height, + allInside: controls.every( + (r) => r.left >= header.left && r.right <= header.right + 1, + ), + titleOverlaps: controls.some( + (r) => + r.left < title.right && + r.right > title.left && + r.top < title.bottom && + r.bottom > title.top, + ), + }; + }); + assert(layout.titleWidth > 200, JSON.stringify(layout)); + assert(layout.headerHeight < 190, JSON.stringify(layout)); + assert(layout.allInside && !layout.titleOverlaps, JSON.stringify(layout)); + if (state === "paused") await shot("queue"); + await page.evaluate(() => closeBatchQueueDetailModal()); + } + await activate("page-roles-management"); + await page.evaluate(() => editRole("界面回归角色")); + await page.locator("#role-tools-list input").first().waitFor(); + await page.evaluate(() => applyTranslations(document)); + assert.equal(await page.locator("#role-modal-title").innerText(), "编辑角色"); + const stats = await page + .locator("#role-tools-stats") + .evaluate((e) => ({ + width: e.clientWidth, + scroll: e.scrollWidth, + text: e.textContent, + })); + assert(stats.text.includes("614") && stats.text.includes("626"), stats.text); + assert(stats.scroll <= stats.width + 2, JSON.stringify(stats)); + await page.locator("#role-tools-stats").scrollIntoViewIfNeeded(); + await shot("role-tools"); + await page.evaluate(() => closeRoleModal()); + await page.evaluate(() => showAddRoleModal()); + await page.evaluate(() => applyTranslations(document)); + assert.equal(await page.locator("#role-modal-title").innerText(), "添加角色"); + await page.evaluate(() => closeRoleModal()); + await activate("page-skills-management"); + await page.evaluate(() => editSkill("review-skill")); + await page.locator("#skill-content").waitFor(); + await page.evaluate(() => applyTranslations(document)); + assert.equal( + await page.locator("#skill-modal-title").innerText(), + "编辑Skill", + ); + await shot("skill"); + await page.evaluate(() => closeSkillModal()); + await page.evaluate(() => showAddSkillModal()); + await page.evaluate(() => applyTranslations(document)); + assert.equal( + await page.locator("#skill-modal-title").innerText(), + "添加Skill", + ); + await page.evaluate(() => closeSkillModal()); + // Real breakpoint transition: mobile boot reapplies the translations. + if (width === 1440) { + await activate("page-roles-management"); + await page.evaluate(() => editRole("界面回归角色")); + await page.setViewportSize({ width: 390, height: 844 }); + await page.waitForTimeout(100); + assert.equal( + await page.locator("#role-modal-title").innerText(), + "编辑角色", + ); + await page.evaluate(() => closeRoleModal()); + await page.setViewportSize({ width, height }); + await activate("page-skills-management"); + await page.evaluate(() => editSkill("review-skill")); + await page.setViewportSize({ width: 390, height: 844 }); + await page.waitForTimeout(100); + assert.equal( + await page.locator("#skill-modal-title").innerText(), + "编辑Skill", + ); + await page.evaluate(() => closeSkillModal()); + await page.setViewportSize({ width, height }); + } + await activate("page-deep-assessments"); + await page.evaluate(() => DeepAssessments.init()); + await page.locator('[data-da-action="create"]').click(); + await page.locator("#da-form-drawer[open]").waitFor(); + await page.waitForTimeout(220); + const native = await page + .locator("#da-form-drawer") + .evaluate((e) => ({ + rect: e.getBoundingClientRect().toJSON(), + bg: getComputedStyle(e).backgroundColor, + expand: !!e.querySelector(".app-drawer-expand"), + })); + assert(native.expand); + assert(Math.abs(native.rect.right - width) < 2, JSON.stringify(native)); + assert(Math.abs(native.rect.height - height) < 2); + assert.equal( + native.bg, + theme === "dark" ? "rgb(17, 24, 39)" : "rgb(255, 255, 255)", + ); + if (width >= 768) { + const before = native.rect.width; + await page.locator("#da-form-drawer .app-drawer-expand").click(); + assert( + (await page.locator("#da-form-drawer").boundingBox()).width > before, + ); + await page.locator("#da-form-drawer .app-drawer-expand").click(); + } + await shot("assessment"); + await page.keyboard.press("Escape"); + assert.equal( + await page.locator("#da-form-drawer").getAttribute("open"), + null, + ); + assert.equal( + await page + .locator("#da-form-drawer .app-drawer-expand") + .getAttribute("aria-pressed"), + "false", + ); + await page.locator('[data-da-action="select"]').click(); + await page.locator("#da-title h3").waitFor(); + await page.locator('[data-da-action="tab"][data-tab="overview"]').click(); + assert.equal( + await page.locator("#da-inspector").getAttribute("aria-labelledby"), + "da-title", + ); + assert.equal( + await page.locator("#da-inspector .app-drawer-expand").count(), + 1, + ); + await shot("assessment-detail"); + await page.keyboard.press("Escape"); + await activate("page-vulnerabilities"); + await page.evaluate(() => { + const rows = Array.from({ length: 50 }, (_, i) => ({ + id: "finding-" + i, + title: "接口响应与权限检查发现:包含较长的组件版本和复现说明 " + i, + description: "已验证的证据摘要。".repeat(10), + severity: i % 3 ? "low" : "high", + status: "open", + target: "https://service-" + i + ".example.test", + target_host: "service-" + i + ".example.test", + target_domain: "example.test", + createdAt: "2026-11-10T12:00:00Z", + })); + vulnerabilityPagination = { + currentPage: 1, + totalPages: 3, + total: 110, + pageSize: 50, + }; + renderVulnerabilities(rows, { view: "host" }); + renderVulnerabilityPagination(); + }); + await page.locator(".vulnerability-record-row").first().waitFor(); + if (width < 768) { + await page + .locator(".vulnerability-record-row") + .first() + .scrollIntoViewIfNeeded(); + await page.locator("#page-vulnerabilities").evaluate((e) => { + e.scrollTop += + e.querySelector(".vulnerability-record-row").getBoundingClientRect() + .top - e.getBoundingClientRect().top; + }); + const scroll = await page + .locator("#page-vulnerabilities") + .evaluate((e) => ({ + height: e.clientHeight, + scrollTop: e.scrollTop, + contentOverflow: getComputedStyle(e.querySelector(".page-content")) + .overflowY, + headerBottom: e.querySelector(".page-header").getBoundingClientRect() + .bottom, + top: e.getBoundingClientRect().top, + })); + assert( + scroll.scrollTop > 0 && scroll.headerBottom <= scroll.top + 1, + JSON.stringify(scroll), + ); + assert(scroll.contentOverflow === "visible", JSON.stringify(scroll)); + assert(scroll.height >= height - 150, JSON.stringify(scroll)); + } + await shot("findings"); +}; diff --git a/web/static/css/design-system.css b/web/static/css/design-system.css index 811eb1c6..7886f562 100644 --- a/web/static/css/design-system.css +++ b/web/static/css/design-system.css @@ -105,7 +105,7 @@ html body [data-ui-surface="drawer"] > :is(.modal-content, .projects-modal-dialo html[dir="rtl"] body [data-ui-surface="drawer"] > :is(.modal-content, .projects-modal-dialog, .c2-modal) { border-radius: 0 var(--ui-radius-card) var(--ui-radius-card) 0 !important; } -html body [data-ui-surface="drawer"] :is(.modal-header, .projects-modal-header, .c2-modal-header, .vulnerability-inspector-header) { +html body [data-ui-surface="drawer"] :is(.modal-header, .projects-modal-header, .c2-modal-header, .vulnerability-inspector-header, .da-drawer-header) { display: flex; align-items: center; flex: 0 0 auto; @@ -119,15 +119,15 @@ html body [data-ui-surface="drawer"] :is(.modal-header, .projects-modal-header, box-shadow: none; } html body [data-ui-surface="drawer"] :is(.modal-header, .projects-modal-header, .c2-modal-header)::after { display: none; } -html body [data-ui-surface="drawer"] :is(.modal-header, .projects-modal-header, .c2-modal-header, .vulnerability-inspector-header) :is(h2, h3) { +html body [data-ui-surface="drawer"] :is(.modal-header, .projects-modal-header, .c2-modal-header, .vulnerability-inspector-header, .da-drawer-header) :is(h2, h3) { font-size: 19px; line-height: 1.5; color: var(--text-primary); margin: 0; overflow-wrap: anywhere; } -html body [data-ui-surface="drawer"] :is(.modal-header, .projects-modal-header, .c2-modal-header, .vulnerability-inspector-header) > :first-child { flex: 1; min-width: 0; } -html body [data-ui-surface="drawer"] :is(.modal-close, .projects-modal-close, .c2-modal-close) { +html body [data-ui-surface="drawer"] :is(.modal-header, .projects-modal-header, .c2-modal-header, .vulnerability-inspector-header, .da-drawer-header) > :first-child { flex: 1; min-width: 0; } +html body [data-ui-surface="drawer"] :is(.modal-close, .projects-modal-close, .c2-modal-close, .da-drawer-close) { position: static; flex: 0 0 36px; width: 36px; @@ -145,7 +145,7 @@ html body [data-ui-surface="drawer"] :is(.modal-body, .projects-modal-body, .c2- color: var(--text-primary); scrollbar-gutter: stable; } -html body [data-ui-surface="drawer"] :is(.modal-footer, .projects-modal-footer, .c2-modal-footer) { +html body [data-ui-surface="drawer"] :is(.modal-footer, .projects-modal-footer, .c2-modal-footer, .da-drawer-footer) { flex: 0 0 auto; display: flex; flex-wrap: wrap; @@ -196,8 +196,8 @@ html body [data-ui-surface="dialog"] > :is(.modal-content, .projects-modal-dialo padding-top: env(safe-area-inset-top, 0px) !important; padding-bottom: env(safe-area-inset-bottom, 0px) !important; } - html body [data-ui-surface="drawer"] :is(.modal-header, .projects-modal-header, .c2-modal-header, .vulnerability-inspector-header) { padding-block: 12px !important; } - html body [data-ui-surface="drawer"] :is(.modal-close, .projects-modal-close, .c2-modal-close) { width: 44px; height: 44px; flex-basis: 44px; } + html body [data-ui-surface="drawer"] :is(.modal-header, .projects-modal-header, .c2-modal-header, .vulnerability-inspector-header, .da-drawer-header) { padding-block: 12px !important; } + html body [data-ui-surface="drawer"] :is(.modal-close, .projects-modal-close, .c2-modal-close, .da-drawer-close) { width: 44px; height: 44px; flex-basis: 44px; } html body .app-drawer-expand { display: none; } html body [data-ui-surface="drawer"] :is(input, textarea, select) { font-size: 16px; } html body [data-ui-surface="drawer"] .modal-header-actions { flex-wrap: wrap; } @@ -229,7 +229,7 @@ html body .page :is(.asset-table, .info-collect-table, .data-table, .chat-files- border-color: var(--ui-border); font-weight: 600; } -html body [data-ui-surface="dialog"] :is(.modal-header, .projects-modal-header, .c2-modal-header, .modal-footer, .projects-modal-footer, .c2-modal-footer) { +html body [data-ui-surface="dialog"] :is(.modal-header, .projects-modal-header, .c2-modal-header, .modal-footer, .projects-modal-footer, .c2-modal-footer, .da-drawer-footer) { background: var(--ui-surface); border-color: var(--ui-border); color: var(--text-primary); @@ -242,3 +242,78 @@ html[dir="rtl"] body [data-ui-surface="drawer"] > :is(.modal-content, .projects- @media (prefers-reduced-motion: reduce) { html[dir="rtl"] body [data-ui-surface="drawer"] > :is(.modal-content, .projects-modal-dialog, .c2-modal) { animation: none !important; } } + +/* Data-heavy queue actions get their own row; never compete with the title. */ +html body #batch-queue-detail-modal .modal-header { + display: grid; + grid-template-columns: minmax(0, 1fr) 36px 36px; + align-items: center; +} +html body #batch-queue-detail-modal .modal-header > h2 { grid-column: 1; grid-row: 1; } +html body #batch-queue-detail-modal .app-drawer-expand { grid-column: 2; grid-row: 1; } +html body #batch-queue-detail-modal .modal-close { grid-column: 3; grid-row: 1; } +html body #batch-queue-detail-modal .modal-header-actions { + grid-column: 1 / -1; + grid-row: 2; + display: flex; + justify-content: flex-start; + flex-wrap: wrap; + min-width: 0; +} +html body #role-modal .role-tools-stats, +html body #role-modal .role-tools-stats-row { min-width: 0; max-width: 100%; } +html body #role-modal .role-tools-stats span { white-space: normal; overflow-wrap: anywhere; min-width: 0; } + +/* Native assessment dialogs share the same surfaces while retaining showModal(). */ +html body dialog.da-drawer[data-ui-surface="drawer"] { + inset: 0 0 0 auto; + margin: 0; + width: min(var(--app-drawer-width), calc(100% - 48px)); + height: 100dvh; + border: 0; + border-inline-start: 1px solid var(--ui-border); + border-radius: var(--ui-radius-card) 0 0 var(--ui-radius-card); + background: var(--ui-surface) !important; + box-shadow: var(--ui-panel-shadow); +} +html body dialog.da-drawer::backdrop { background: var(--ui-overlay); } +html body dialog.da-drawer:not(.da-form-drawer) { --app-drawer-width: 960px; } +html body dialog.da-drawer.app-drawer-expanded { --app-drawer-width: 1440px; } +html body dialog.da-drawer .da-detail-scroll, +html body dialog.da-drawer .da-form-body { padding: var(--ui-space); } +html body dialog.da-drawer .form-control { border-radius: var(--ui-radius-control); background: var(--input-bg); } +html body dialog.da-drawer #da-title h3 { font-size: 19px; } +@media (max-width: 767.98px) { + html body #batch-queue-detail-modal .modal-header { grid-template-columns: minmax(0, 1fr) 44px; gap: 8px; } + html body #batch-queue-detail-modal .modal-close { grid-column: 2; } + html body #batch-queue-detail-modal .modal-header-actions { gap: 8px; } + html body dialog.da-drawer[data-ui-surface="drawer"] { + width: 100%; border-radius: 0; border: 0; + padding-top: env(safe-area-inset-top, 0px) !important; + padding-bottom: env(safe-area-inset-bottom, 0px) !important; + } + html body dialog.da-drawer .da-drawer-footer > button { flex: 1; } + html body dialog.da-drawer .form-control { font-size: 16px; } + /* One page scroll: actions and pagination no longer reserve most of the screen. */ + html body #page-vulnerabilities.active { display: block; overflow-y: auto; overscroll-behavior: contain; } + html body #page-vulnerabilities > .page-header { position: static; } + html body #page-vulnerabilities > .page-content { + height: auto; max-height: none; overflow: visible; flex: none; + } + html body #page-vulnerabilities > .vulnerability-page-footer { position: static; } + html body #vulnerability-pagination { position: static; } + html body #page-vulnerabilities .dashboard-stats { + display: grid; grid-template-columns: repeat(6, minmax(96px, 1fr)); + overflow-x: auto; padding-bottom: 6px; + } + html body #page-vulnerabilities .stat-card { min-height: 84px; padding: 10px; } +} +html body dialog.da-drawer .da-drawer-close { + display: inline-flex; align-items: center; justify-content: center; + border-radius: var(--ui-radius-control); font-size: 0; +} +html body dialog.da-drawer .da-drawer-close::before { + content: ''; width: 18px; height: 18px; background: currentColor; + mask: var(--icon-close-mask) center / contain no-repeat; + -webkit-mask: var(--icon-close-mask) center / contain no-repeat; +} diff --git a/web/static/js/deep-assessments.js b/web/static/js/deep-assessments.js index e7280c9f..159d7c8f 100644 --- a/web/static/js/deep-assessments.js +++ b/web/static/js/deep-assessments.js @@ -24,6 +24,7 @@ } function openDrawer(id) { const drawer = $(id); + window.prepareAppDrawer?.(drawer); if (!drawer.open) { drawer.returnFocus = document.activeElement; drawer.showModal(); @@ -56,6 +57,8 @@ else ++S.drawerEpoch; }); drawer.addEventListener('close', () => { + drawer.classList.remove('app-drawer-expanded'); + drawer.querySelector('.app-drawer-expand')?.setAttribute('aria-pressed', 'false'); syncDrawerLock(); requestAnimationFrame(() => { if (!$('page-deep-assessments')?.classList.contains('active')) return; diff --git a/web/static/js/modal.js b/web/static/js/modal.js index 90c9cfc4..15b9f9e3 100644 --- a/web/static/js/modal.js +++ b/web/static/js/modal.js @@ -40,20 +40,20 @@ function prepareSurface(el) { if (!el || el.id === 'login-overlay') return; - const drawer = DRAWER_IDS.has(el.id) && !el.querySelector('.c2-modal--sleep'); + const drawer = (DRAWER_IDS.has(el.id) || el.matches('dialog.da-drawer')) && !el.querySelector('.c2-modal--sleep'); el.dataset.uiSurface = drawer ? 'drawer' : 'dialog'; el.classList.toggle('app-drawer-wide', drawer && (WIDE_IDS.has(el.id) || !!el.querySelector('.c2-modal--wide'))); if (!drawer) return; el.setAttribute('role', 'dialog'); el.setAttribute('aria-modal', 'true'); - const header = el.querySelector('.modal-header, .projects-modal-header, .c2-modal-header, .vulnerability-inspector-header'); + const header = el.querySelector('.modal-header, .projects-modal-header, .c2-modal-header, .vulnerability-inspector-header, .da-drawer-header'); if (!header) return; // Asynchronously rendered details are prepared again after rendering. const title = header.querySelector('h2, h3'); - if (title) { + if (title && !el.matches('dialog.da-drawer')) { if (!title.id) title.id = el.id + '-heading'; el.setAttribute('aria-labelledby', title.id); } - const close = header.querySelector('.modal-close, .projects-modal-close, .c2-modal-close'); + const close = header.querySelector('.modal-close, .projects-modal-close, .c2-modal-close, .da-drawer-close'); if (close && close.tagName !== 'BUTTON') { close.setAttribute('role', 'button'); close.tabIndex = 0; @@ -142,7 +142,7 @@ opts.focusSelector || 'input.form-input, textarea.form-input, select.form-input, input:not([type="hidden"]):not([disabled]), textarea:not([disabled]), select:not([disabled])'; const focusTarget = opts.focusEl || Array.from(el.querySelectorAll(sel)).find(item => item.getClientRects().length) - || el.querySelector('.modal-close, .projects-modal-close, .c2-modal-close'); + || el.querySelector('.modal-close, .projects-modal-close, .c2-modal-close, .da-drawer-close'); if (focusTarget) { requestAnimationFrame(function () { focusTarget.focus(); @@ -187,7 +187,7 @@ const el = openOrder.filter(isElVisible).at(-1); if (!el || el.dataset.uiSurface !== 'drawer' || event.defaultPrevented) return; if (event.key === 'Escape') { - const close = el.querySelector('.modal-close, .projects-modal-close, .c2-modal-close'); + const close = el.querySelector('.modal-close, .projects-modal-close, .c2-modal-close, .da-drawer-close'); if (close) { event.preventDefault(); event.stopImmediatePropagation(); close.click(); } } else if (event.key === 'Tab') { const items = Array.from(el.querySelectorAll('button, [href], input, select, textarea, [tabindex]')) @@ -203,6 +203,8 @@ }); document.querySelectorAll(OVERLAY_SELECTOR).forEach(prepareSurface); + // Native keeps its own top-layer, focus and cancel lifecycle. + window.prepareAppDrawer = prepareSurface; window.openAppModal = openAppModal; window.closeAppModal = closeAppModal; window.isAppModalOpen = isAppModalOpen; diff --git a/web/static/js/roles.js b/web/static/js/roles.js index ee94f192..3ec24e00 100644 --- a/web/static/js/roles.js +++ b/web/static/js/roles.js @@ -1296,6 +1296,7 @@ async function showAddRoleModal() { const modal = document.getElementById('role-modal'); if (!modal) return; + document.getElementById('role-modal-title').setAttribute('data-i18n', 'roleModal.addRole'); document.getElementById('role-modal-title').textContent = _t('roleModal.addRole'); document.getElementById('role-name').value = ''; document.getElementById('role-name').disabled = false; @@ -1379,6 +1380,7 @@ async function editRole(roleName) { const modal = document.getElementById('role-modal'); if (!modal) return; + document.getElementById('role-modal-title').setAttribute('data-i18n', 'roleModal.editRole'); document.getElementById('role-modal-title').textContent = _t('roleModal.editRole'); document.getElementById('role-name').value = role.name; document.getElementById('role-name').disabled = true; // 编辑时不允许修改名称 diff --git a/web/static/js/skills.js b/web/static/js/skills.js index 3e9507c5..c2f6bba0 100644 --- a/web/static/js/skills.js +++ b/web/static/js/skills.js @@ -498,6 +498,7 @@ function showAddSkillModal() { if (pkg) pkg.style.display = 'none'; if (addEd) addEd.style.display = 'block'; + document.getElementById('skill-modal-title').setAttribute('data-i18n', 'skills.addSkill'); document.getElementById('skill-modal-title').textContent = _t('skills.addSkill'); document.getElementById('skill-name').value = ''; document.getElementById('skill-name').disabled = false; @@ -612,6 +613,7 @@ async function editSkill(skillId) { const addEd = document.getElementById('skill-add-editor'); if (pkg) pkg.style.display = 'block'; if (addEd) addEd.style.display = 'none'; + document.getElementById('skill-modal-title').setAttribute('data-i18n', 'skills.editSkill'); document.getElementById('skill-modal-title').textContent = _t('skills.editSkill'); document.getElementById('skill-name').value = ''; document.getElementById('skill-name').disabled = true; diff --git a/web/templates/index.html b/web/templates/index.html index 394eea7b..b8a721bf 100644 --- a/web/templates/index.html +++ b/web/templates/index.html @@ -51,7 +51,7 @@ - +