@zhin.js/console-ui 0.0.0-stage → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/LICENSE +21 -0
  3. package/README.md +195 -2
  4. package/audit/index.mjs +21 -0
  5. package/audit/layout-audit.mjs +492 -0
  6. package/audit/mount-page.jsx +90 -0
  7. package/audit/plugin-pages.mjs +186 -0
  8. package/dist/cn.d.ts +4 -0
  9. package/dist/cn.js +6 -0
  10. package/dist/components/BrandMark.d.ts +16 -0
  11. package/dist/components/BrandMark.js +21 -0
  12. package/dist/components/InfoHint.d.ts +12 -0
  13. package/dist/components/InfoHint.js +13 -0
  14. package/dist/components/PageHeader.d.ts +18 -0
  15. package/dist/components/PageHeader.js +11 -0
  16. package/dist/components/PageShell.d.ts +26 -0
  17. package/dist/components/PageShell.js +10 -0
  18. package/dist/components/RefreshControl.d.ts +28 -0
  19. package/dist/components/RefreshControl.js +68 -0
  20. package/dist/components/StatCard.d.ts +41 -0
  21. package/dist/components/StatCard.js +53 -0
  22. package/dist/components/StatusBadge.d.ts +14 -0
  23. package/dist/components/StatusBadge.js +19 -0
  24. package/dist/components/actions.d.ts +53 -0
  25. package/dist/components/actions.js +50 -0
  26. package/dist/components/code.d.ts +11 -0
  27. package/dist/components/code.js +10 -0
  28. package/dist/components/confirm-dialog-model.d.ts +9 -0
  29. package/dist/components/confirm-dialog-model.js +20 -0
  30. package/dist/components/confirm-dialog.d.ts +32 -0
  31. package/dist/components/confirm-dialog.js +72 -0
  32. package/dist/components/content-blocks.d.ts +141 -0
  33. package/dist/components/content-blocks.js +77 -0
  34. package/dist/components/empty-illustrations.d.ts +15 -0
  35. package/dist/components/empty-illustrations.js +36 -0
  36. package/dist/components/empty-state.d.ts +35 -0
  37. package/dist/components/empty-state.js +43 -0
  38. package/dist/components/error-alert.d.ts +15 -0
  39. package/dist/components/error-alert.js +23 -0
  40. package/dist/components/icon.d.ts +11 -0
  41. package/dist/components/icon.js +8 -0
  42. package/dist/components/layout.d.ts +38 -0
  43. package/dist/components/layout.js +28 -0
  44. package/dist/components/page-chrome.d.ts +53 -0
  45. package/dist/components/page-chrome.js +66 -0
  46. package/dist/components/refresh-control-model.d.ts +9 -0
  47. package/dist/components/refresh-control-model.js +26 -0
  48. package/dist/components/ui/accordion.d.ts +7 -0
  49. package/dist/components/ui/accordion.js +15 -0
  50. package/dist/components/ui/alert.d.ts +8 -0
  51. package/dist/components/ui/alert.js +24 -0
  52. package/dist/components/ui/badge.d.ts +9 -0
  53. package/dist/components/ui/badge.js +30 -0
  54. package/dist/components/ui/button.d.ts +20 -0
  55. package/dist/components/ui/button.js +52 -0
  56. package/dist/components/ui/card.d.ts +17 -0
  57. package/dist/components/ui/card.js +17 -0
  58. package/dist/components/ui/checkbox.d.ts +4 -0
  59. package/dist/components/ui/checkbox.js +10 -0
  60. package/dist/components/ui/control-variant.d.ts +10 -0
  61. package/dist/components/ui/control-variant.js +6 -0
  62. package/dist/components/ui/date-field-model.d.ts +39 -0
  63. package/dist/components/ui/date-field-model.js +105 -0
  64. package/dist/components/ui/date-field.d.ts +33 -0
  65. package/dist/components/ui/date-field.js +161 -0
  66. package/dist/components/ui/dialog.d.ts +24 -0
  67. package/dist/components/ui/dialog.js +27 -0
  68. package/dist/components/ui/dropdown-menu.d.ts +19 -0
  69. package/dist/components/ui/dropdown-menu.js +26 -0
  70. package/dist/components/ui/input.d.ts +8 -0
  71. package/dist/components/ui/input.js +9 -0
  72. package/dist/components/ui/list-item-button.d.ts +10 -0
  73. package/dist/components/ui/list-item-button.js +6 -0
  74. package/dist/components/ui/popover.d.ts +6 -0
  75. package/dist/components/ui/popover.js +9 -0
  76. package/dist/components/ui/radio-group.d.ts +5 -0
  77. package/dist/components/ui/radio-group.js +10 -0
  78. package/dist/components/ui/scroll-area.d.ts +5 -0
  79. package/dist/components/ui/scroll-area.js +13 -0
  80. package/dist/components/ui/searchable-select-model.d.ts +29 -0
  81. package/dist/components/ui/searchable-select-model.js +38 -0
  82. package/dist/components/ui/searchable-select.d.ts +26 -0
  83. package/dist/components/ui/searchable-select.js +85 -0
  84. package/dist/components/ui/select.d.ts +29 -0
  85. package/dist/components/ui/select.js +39 -0
  86. package/dist/components/ui/separator.d.ts +4 -0
  87. package/dist/components/ui/separator.js +11 -0
  88. package/dist/components/ui/sheet.d.ts +27 -0
  89. package/dist/components/ui/sheet.js +27 -0
  90. package/dist/components/ui/skeleton.d.ts +3 -0
  91. package/dist/components/ui/skeleton.js +6 -0
  92. package/dist/components/ui/switch.d.ts +4 -0
  93. package/dist/components/ui/switch.js +8 -0
  94. package/dist/components/ui/table.d.ts +27 -0
  95. package/dist/components/ui/table.js +47 -0
  96. package/dist/components/ui/tabs.d.ts +7 -0
  97. package/dist/components/ui/tabs.js +13 -0
  98. package/dist/components/ui/textarea.d.ts +8 -0
  99. package/dist/components/ui/textarea.js +9 -0
  100. package/dist/components/ui/tooltip.d.ts +7 -0
  101. package/dist/components/ui/tooltip.js +11 -0
  102. package/dist/components/use-container-width.d.ts +13 -0
  103. package/dist/components/use-container-width.js +30 -0
  104. package/dist/custom-media.css +13 -0
  105. package/dist/exports.json +178 -0
  106. package/dist/i18n/index.d.ts +27 -0
  107. package/dist/i18n/index.js +33 -0
  108. package/dist/i18n/messages.d.ts +55 -0
  109. package/dist/i18n/messages.js +110 -0
  110. package/dist/index.d.ts +56 -0
  111. package/dist/index.js +55 -0
  112. package/dist/scale.json +643 -0
  113. package/dist/shared-module.d.ts +28 -0
  114. package/dist/shared-module.js +24 -0
  115. package/dist/styles.css +3399 -0
  116. package/dist/theme.css +469 -0
  117. package/dist/tokens.css +652 -0
  118. package/dist/version.d.ts +6 -0
  119. package/dist/version.js +2 -0
  120. package/lint/eslint-plugin.mjs +128 -0
  121. package/lint/stylelint-config.mjs +43 -0
  122. package/lint/stylelint-plugin.mjs +195 -0
  123. package/lint/tailwind-classes.mjs +121 -0
  124. package/package.json +103 -3
  125. package/tokens/color.mjs +104 -0
  126. package/tokens/colors.css +220 -0
  127. package/tokens/generate.mjs +288 -0
  128. package/tokens/scale.mjs +137 -0
  129. package/tokens/tokens.mjs +362 -0
@@ -0,0 +1,186 @@
1
+ /**
2
+ * Audit of plugin Console pages (`auditPluginPages`, ADR 0063 D20 第 3 条): bundles each page with
3
+ * a mount entry (audit/mount-page.jsx), opens it in Chromium with the published
4
+ * `@zhin.js/console-ui/styles.css`, and runs the layout audit at every width × theme.
5
+ *
6
+ * Node side only. Needs `esbuild` and `@playwright/test` (or `playwright`), resolved from the
7
+ * repository first; both are optional peers of @zhin.js/console-ui, never runtime dependencies of
8
+ * the browser package. A preinstalled Chromium can be selected with PLAYWRIGHT_CHROMIUM_EXECUTABLE.
9
+ *
10
+ * Pages the audit cannot mount on its own (declarative blueprints / adapter pages, rendered by the
11
+ * Console renderers) are returned with `mounted: false` and a `skipped` reason and no violations,
12
+ * unless the request names a `mountModule` (a module exporting `mountPluginPage(context)`, see
13
+ * mount-page.jsx) that renders them.
14
+ */
15
+ import { copyFileSync, existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
16
+ import { createServer } from 'node:http';
17
+ import { createRequire } from 'node:module';
18
+ import { tmpdir } from 'node:os';
19
+ import { dirname, join, resolve } from 'node:path';
20
+ import { fileURLToPath, pathToFileURL } from 'node:url';
21
+ import { AUDIT_THEMES, AUDIT_WIDTHS, auditPage } from './layout-audit.mjs';
22
+
23
+ const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');
24
+
25
+ /** Imports the ESM entry of a package installed under one of `roots` (first match wins). */
26
+ async function importFrom(roots, ids) {
27
+ for (const id of ids) {
28
+ for (const root of roots) {
29
+ let manifestPath;
30
+ try {
31
+ manifestPath = createRequire(join(root, 'package.json')).resolve(`${id}/package.json`);
32
+ } catch {
33
+ continue;
34
+ }
35
+ const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
36
+ const main = manifest.exports?.['.'];
37
+ const entry = (typeof main === 'string' ? main : main?.import?.default ?? main?.import ?? main?.default) ?? manifest.module ?? manifest.main ?? 'index.js';
38
+ const module = await import(pathToFileURL(join(dirname(manifestPath), typeof entry === 'string' ? entry : 'index.js')).href);
39
+ return { ...(module.default && typeof module.default === 'object' ? module.default : {}), ...module };
40
+ }
41
+ }
42
+ throw new Error(`@zhin.js/console-ui/audit needs one of ${ids.join(', ')} (optional peer dependency)`);
43
+ }
44
+
45
+ function resolveDir(id) {
46
+ return dirname(createRequire(join(packageRoot, 'package.json')).resolve(`${id}/package.json`));
47
+ }
48
+
49
+ /**
50
+ * @param {{
51
+ * repoRoot: string,
52
+ * widths?: number[],
53
+ * themes?: ('light'|'dark')[],
54
+ * plugins: { plugin: string, directory: string, packageName: string, pages: { name: string, entry: string }[] }[],
55
+ * mountModule?: string,
56
+ * checks?: string[],
57
+ * }} request
58
+ * @returns {Promise<{ pages: { plugin: string, page: string, mounted: boolean, skipped?: string,
59
+ * violations: { check: string, width: number, theme: 'light'|'dark', message: string, selector?: string }[],
60
+ * exemptions?: { check: string, reason: string, selector?: string }[] }[] }>}
61
+ */
62
+ export async function auditPluginPages(request) {
63
+ const { repoRoot, widths = AUDIT_WIDTHS, themes = AUDIT_THEMES, plugins } = request;
64
+ const styles = join(packageRoot, 'dist/styles.css');
65
+ if (!existsSync(styles)) throw new Error('@zhin.js/console-ui/audit: dist/styles.css is missing; build @zhin.js/console-ui first');
66
+ const roots = [repoRoot, packageRoot];
67
+ const esbuild = await importFrom(roots, ['esbuild']);
68
+ const { chromium } = await importFrom(roots, ['@playwright/test', 'playwright', 'playwright-core']);
69
+ const mountModule = request.mountModule ?? process.env.ZHIN_UI_AUDIT_MOUNT_MODULE;
70
+ const work = mkdtempSync(join(tmpdir(), 'zhin-ui-audit-'));
71
+ copyFileSync(styles, join(work, 'styles.css'));
72
+ // Served over http (not file://): pages may open WebSockets or fetch relative to their origin.
73
+ const server = await serve(work);
74
+ const browser = await chromium.launch({ executablePath: process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE || undefined });
75
+ const results = [];
76
+ try {
77
+ for (const plugin of plugins) {
78
+ for (const pageSpec of plugin.pages) {
79
+ results.push(await auditOne({ esbuild, browser, work, origin: server.origin, plugin, pageSpec, widths, themes, mountModule, repoRoot, checks: request.checks }));
80
+ }
81
+ }
82
+ } finally {
83
+ await browser.close();
84
+ await server.close();
85
+ rmSync(work, { recursive: true, force: true });
86
+ }
87
+ return { pages: results };
88
+ }
89
+
90
+ async function auditOne({ esbuild, browser, work, origin, plugin, pageSpec, widths, themes, mountModule, repoRoot, checks }) {
91
+ const result = { plugin: plugin.plugin, page: pageSpec.name, mounted: false, violations: [], exemptions: [] };
92
+ const id = `${plugin.plugin}/${pageSpec.name}`.replace(/[^a-z0-9]+/giu, '-');
93
+ const entry = join(work, `${id}.entry.tsx`);
94
+ const pagePath = resolve(plugin.directory, pageSpec.entry);
95
+ const mounter = join(packageRoot, 'audit/mount-page.jsx');
96
+ writeFileSync(entry, [
97
+ `import * as pageModule from ${JSON.stringify(pagePath)};`,
98
+ `import { mountAuditPage } from ${JSON.stringify(mounter)};`,
99
+ mountModule ? `import * as custom from ${JSON.stringify(resolve(repoRoot, mountModule))};` : 'const custom = undefined;',
100
+ `void mountAuditPage(pageModule, ${JSON.stringify(pageSpec.name)}, custom);`,
101
+ ].join('\n'));
102
+ try {
103
+ await esbuild.build({
104
+ entryPoints: [entry],
105
+ outfile: join(work, `${id}.js`),
106
+ bundle: true,
107
+ format: 'iife',
108
+ platform: 'browser',
109
+ target: 'es2022',
110
+ jsx: 'automatic',
111
+ loader: { '.css': 'css', '.svg': 'dataurl', '.png': 'dataurl' },
112
+ define: { 'process.env.NODE_ENV': '"production"' },
113
+ nodePaths: [join(plugin.directory, 'node_modules'), join(repoRoot, 'node_modules'), join(packageRoot, 'node_modules')],
114
+ // One React and one @zhin.js/console-ui, as in the Console (shared singletons).
115
+ alias: {
116
+ react: resolveDir('react'),
117
+ 'react-dom': resolveDir('react-dom'),
118
+ },
119
+ // Workspace sources in the repository (the `development` export condition), built output elsewhere.
120
+ conditions: ['development'],
121
+ logLevel: 'silent',
122
+ });
123
+ } catch (error) {
124
+ const message = error?.errors?.[0]?.text ?? String(error?.message ?? error);
125
+ result.violations.push(...themes.flatMap((theme) => widths.map((width) => ({ check: 'mount', width, theme, message: `page does not build: ${message}` }))));
126
+ return result;
127
+ }
128
+ const css = existsSync(join(work, `${id}.css`)) ? `<link rel="stylesheet" href="./${id}.css" />` : '';
129
+ writeFileSync(join(work, `${id}.html`), `<!doctype html><html lang="zh-CN"><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" /><link rel="stylesheet" href="./styles.css" />${css}</head><body><div id="root"></div><script src="./${id}.js"></script></body></html>`);
130
+ const url = `${origin}/${id}.html`;
131
+ const page = await browser.newPage({ locale: 'zh-CN', deviceScaleFactor: 1 });
132
+ const exemptionKeys = new Set();
133
+ try {
134
+ for (const theme of themes) {
135
+ for (const width of widths) {
136
+ await page.setViewportSize({ width, height: 900 });
137
+ await page.goto(`${url}?theme=${theme}`);
138
+ const state = await page.waitForFunction(() => window.__zhinUiAudit, undefined, { timeout: 15_000 }).then((handle) => handle.jsonValue()).catch(() => ({ status: 'error', message: 'the page did not finish mounting within 15s' }));
139
+ if (state.status === 'unsupported') {
140
+ result.skipped = state.message;
141
+ return result;
142
+ }
143
+ if (state.status === 'error') {
144
+ result.violations.push({ check: 'mount', width, theme, message: `page failed to render: ${state.message}` });
145
+ continue;
146
+ }
147
+ result.mounted = true;
148
+ const run = await auditPage(page, { checks });
149
+ for (const violation of run.violations) {
150
+ result.violations.push({ check: violation.check, width, theme, message: violation.message, selector: violation.selector });
151
+ }
152
+ for (const exemption of run.exemptions) {
153
+ const key = `${exemption.check}|${exemption.selector}|${exemption.reason}`;
154
+ if (exemptionKeys.has(key)) continue;
155
+ exemptionKeys.add(key);
156
+ result.exemptions.push({ check: exemption.check, reason: exemption.reason, selector: exemption.selector });
157
+ }
158
+ }
159
+ }
160
+ } finally {
161
+ await page.close();
162
+ }
163
+ return result;
164
+ }
165
+
166
+ const TYPES = { '.html': 'text/html', '.js': 'text/javascript', '.css': 'text/css' };
167
+
168
+ /** Minimal static server for the bundled pages (loopback only). */
169
+ function serve(directory) {
170
+ const server = createServer((request, response) => {
171
+ const name = decodeURIComponent(new URL(request.url ?? '/', 'http://localhost').pathname).replace(/^\/+/u, '');
172
+ const path = join(directory, name);
173
+ if (!name || name.includes('..') || !existsSync(path)) {
174
+ response.writeHead(404).end();
175
+ return;
176
+ }
177
+ const extension = name.slice(name.lastIndexOf('.'));
178
+ response.writeHead(200, { 'content-type': TYPES[extension] ?? 'application/octet-stream' }).end(readFileSync(path));
179
+ });
180
+ return new Promise((resolvePromise) => {
181
+ server.listen(0, '127.0.0.1', () => {
182
+ const { port } = server.address();
183
+ resolvePromise({ origin: `http://127.0.0.1:${port}`, close: () => new Promise((done) => server.close(() => done())) });
184
+ });
185
+ });
186
+ }
package/dist/cn.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { type ClassValue } from 'clsx';
2
+ export type { ClassValue } from 'clsx';
3
+ /** Joins class names and resolves Tailwind conflicts (later classes win). */
4
+ export declare function cn(...inputs: ClassValue[]): string;
package/dist/cn.js ADDED
@@ -0,0 +1,6 @@
1
+ import { clsx } from 'clsx';
2
+ import { twMerge } from 'tailwind-merge';
3
+ /** Joins class names and resolves Tailwind conflicts (later classes win). */
4
+ export function cn(...inputs) {
5
+ return twMerge(clsx(inputs));
6
+ }
@@ -0,0 +1,16 @@
1
+ /** The product name shown next to the mark (zhinjs/console#125: one name everywhere). */
2
+ export declare const CONSOLE_PRODUCT_NAME = "Zhin Console";
3
+ export interface BrandMarkProps {
4
+ /** `sm` 20px, `md` 28px (default), `lg` 40px, or a pixel size. */
5
+ readonly size?: 'sm' | 'md' | 'lg' | number;
6
+ /** Show the product name next to the mark. */
7
+ readonly withText?: boolean;
8
+ /** Product name; defaults to 「Zhin Console」. Also the accessible name of a mark without text. */
9
+ readonly label?: string;
10
+ readonly className?: string;
11
+ }
12
+ /**
13
+ * The Zhin brand mark (SVG), optionally with the product name. Same shape and colors under every
14
+ * palette; only the light / dark brand value differs.
15
+ */
16
+ export declare function BrandMark({ size, withText, label, className }: BrandMarkProps): import("react").JSX.Element;
@@ -0,0 +1,21 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cn } from '../cn.js';
3
+ /** The product name shown next to the mark (zhinjs/console#125: one name everywhere). */
4
+ export const CONSOLE_PRODUCT_NAME = 'Zhin Console';
5
+ /*
6
+ * The Console favicon (zhinjs/console client/favicon.svg): rounded square, Z, dot. Colors are the
7
+ * brand tokens, never the palette (ADR 0063 「色板角色与信号色」): the square is `brand`
8
+ * (#76EEC6 light / #7FFFD4 dark, owner 2026-11-16), the Z `brand-foreground`, the dot
9
+ * `brand-foreground` at half strength. The fallbacks keep the mark right without tokens.css.
10
+ */
11
+ const SQUARE = 'hsl(var(--console-brand, 160 78% 69.8%))';
12
+ const INK = 'hsl(var(--console-brand-foreground, 160 80% 10%))';
13
+ /**
14
+ * The Zhin brand mark (SVG), optionally with the product name. Same shape and colors under every
15
+ * palette; only the light / dark brand value differs.
16
+ */
17
+ export function BrandMark({ size = 'md', withText = false, label = CONSOLE_PRODUCT_NAME, className }) {
18
+ const preset = typeof size === 'number' ? undefined : size;
19
+ const style = typeof size === 'number' ? { width: size, height: size } : undefined;
20
+ return (_jsxs("span", { className: cn('console-brand', className), "data-slot": "brand-mark", "data-size": preset ?? 'custom', children: [_jsxs("svg", { className: "console-brand-mark", style: style, viewBox: "0 0 64 64", fill: "none", xmlns: "http://www.w3.org/2000/svg", focusable: "false", ...(withText ? { 'aria-hidden': true } : { role: 'img', 'aria-label': label }), children: [_jsx("rect", { width: "64", height: "64", rx: "18", fill: SQUARE }), _jsx("path", { d: "M18 18H46L43.4 24.2L28.5 40H45.5V47H17.5L20.1 40.8L35 25H18V18Z", fill: INK }), _jsx("circle", { cx: "49", cy: "15", r: "5", fill: INK, fillOpacity: 0.5 })] }), withText ? _jsx("span", { className: "console-brand-name", children: label }) : null] }));
21
+ }
@@ -0,0 +1,12 @@
1
+ import type { ReactNode } from 'react';
2
+ /**
3
+ * An ⓘ label whose explanation opens on click, Enter or Space: for statements about how a number
4
+ * was counted, which readers need once and not on every visit. `label` stays visible; `children`
5
+ * is the explanation.
6
+ */
7
+ export declare function InfoHint({ label, children, className, tone }: {
8
+ label: ReactNode;
9
+ children: ReactNode;
10
+ className?: string;
11
+ tone?: 'warning';
12
+ }): import("react").JSX.Element;
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Info } from 'lucide-react';
3
+ import { CONSOLE_ICON_STROKE_WIDTH } from './icon.js';
4
+ import { cn } from '../cn.js';
5
+ import { Popover, PopoverContent, PopoverTrigger } from './ui/popover.js';
6
+ /**
7
+ * An ⓘ label whose explanation opens on click, Enter or Space: for statements about how a number
8
+ * was counted, which readers need once and not on every visit. `label` stays visible; `children`
9
+ * is the explanation.
10
+ */
11
+ export function InfoHint({ label, children, className, tone }) {
12
+ return (_jsxs(Popover, { children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs("button", { type: "button", className: cn('console-info-hint console-touch', tone === 'warning' && 'is-warning', className), children: [_jsx("span", { children: label }), _jsx(Info, { strokeWidth: CONSOLE_ICON_STROKE_WIDTH, "aria-hidden": "true" })] }) }), _jsx(PopoverContent, { className: "console-info-hint-panel", align: "start", children: children })] }));
13
+ }
@@ -0,0 +1,18 @@
1
+ import type { ReactNode } from 'react';
2
+ import { type PageAction } from './actions.js';
3
+ export interface PageHeaderProps {
4
+ title: string;
5
+ description?: string;
6
+ /** Always-visible header content (refresh control, custom controls); wraps on narrow headers. */
7
+ actions?: ReactNode;
8
+ /** Labelled actions: buttons on wide headers, folded into 「更多」 below 40rem (D18 第 7 条). */
9
+ menuActions?: readonly PageAction[];
10
+ /** Actions that always live in the 「更多」 menu. */
11
+ moreActions?: readonly PageAction[];
12
+ className?: string;
13
+ }
14
+ /**
15
+ * Page title block (ADR 0063 决策 2): title, one description, and the actions. The header is a size
16
+ * container; its layout follows its own width, so nothing is pushed out of the viewport.
17
+ */
18
+ export declare function PageHeader({ title, description, actions, menuActions, moreActions, className }: PageHeaderProps): import("react").JSX.Element;
@@ -0,0 +1,11 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cn } from '../cn.js';
3
+ import { PageActions } from './actions.js';
4
+ /**
5
+ * Page title block (ADR 0063 决策 2): title, one description, and the actions. The header is a size
6
+ * container; its layout follows its own width, so nothing is pushed out of the viewport.
7
+ */
8
+ export function PageHeader({ title, description, actions, menuActions, moreActions, className }) {
9
+ const hasActions = actions != null || Boolean(menuActions?.length) || Boolean(moreActions?.length);
10
+ return (_jsx("header", { className: cn('console-page-header console-cq', className), "data-slot": "page-header", children: _jsxs("div", { className: "console-page-header-body", children: [_jsxs("div", { className: "console-page-heading", children: [_jsx("h1", { className: "console-page-title", children: title }), description ? _jsx("p", { className: "console-page-description", children: description }) : null] }), hasActions ? _jsx(PageActions, { actions: menuActions, moreActions: moreActions, children: actions }) : null] }) }));
11
+ }
@@ -0,0 +1,26 @@
1
+ import type { ReactNode } from 'react';
2
+ /**
3
+ * Content width of a page (ADR 0063 D16, D18 第 4 条): `reading` 60rem for settings, forms and
4
+ * explanations; `data` 120rem for lists, tables and dashboards (the default); `full` for workspace
5
+ * pages (`definePage({ fullWidth: true })`).
6
+ */
7
+ export type PageContentWidth = 'reading' | 'data' | 'full';
8
+ export interface PageShellProps {
9
+ children: ReactNode;
10
+ /** 默认 vertical stack;grid 用于卡片栅格页(两者都是纵向排列的区块,保留兼容) */
11
+ layout?: 'stack' | 'grid';
12
+ /** Content width the shell resolves into `--console-content-max`. Defaults to `data`. */
13
+ width?: PageContentWidth;
14
+ /**
15
+ * The shell pads the page with `--console-page-padding-inline` / `-block` (default). Pass `false`
16
+ * when the host layout already pads its main area.
17
+ */
18
+ inset?: boolean;
19
+ className?: string;
20
+ }
21
+ /**
22
+ * Page content shell: page padding, section rhythm and the content width
23
+ * `min(100%, var(--console-content-max))` (D18 第 3 条). The frame is a size container, so the
24
+ * components inside follow the page width; it is also its own stacking context (D19 兜底).
25
+ */
26
+ export declare function PageShell({ children, layout, width, inset, className }: PageShellProps): import("react").JSX.Element;
@@ -0,0 +1,10 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { cn } from '../cn.js';
3
+ /**
4
+ * Page content shell: page padding, section rhythm and the content width
5
+ * `min(100%, var(--console-content-max))` (D18 第 3 条). The frame is a size container, so the
6
+ * components inside follow the page width; it is also its own stacking context (D19 兜底).
7
+ */
8
+ export function PageShell({ children, layout = 'stack', width = 'data', inset = true, className }) {
9
+ return (_jsx("div", { className: "console-page-frame console-cq", "data-width": width, "data-inset": inset ? undefined : 'false', "data-slot": "page", children: _jsx("div", { className: cn(layout === 'stack' ? 'console-page' : 'console-page-grid', className), "data-slot": "page-content", "data-width": width, children: children }) }));
10
+ }
@@ -0,0 +1,28 @@
1
+ export interface RefreshControlProps {
2
+ /** Runs on the refresh button and on every auto-refresh tick; a returned promise keeps the control busy until it settles. */
3
+ onRefresh: () => void | Promise<unknown>;
4
+ /**
5
+ * Runs on auto-refresh ticks instead of `onRefresh`, for pages whose explicit refresh does more
6
+ * than re-read (e.g. clears a 「请先刷新」 block) that a timer must not do.
7
+ */
8
+ onAutoRefresh?: () => void | Promise<unknown>;
9
+ /** Time of the last successful load, shown as 「更新于 hh:mm:ss」. */
10
+ updatedAt?: Date | number | string | null;
11
+ /** Auto-refresh interval in ms (0 = manual). Controlled when set. */
12
+ intervalMs?: number;
13
+ /** Initial interval when uncontrolled; defaults to 0 (manual). */
14
+ defaultIntervalMs?: number;
15
+ onIntervalChange?: (intervalMs: number) => void;
16
+ /** Offered intervals in ms; defaults to manual / 5s / 15s / 30s. */
17
+ intervals?: readonly number[];
18
+ /** Busy state owned by the caller (e.g. a data hook); merged with the control's own in-flight state. */
19
+ refreshing?: boolean;
20
+ disabled?: boolean;
21
+ className?: string;
22
+ }
23
+ /**
24
+ * The one refresh control for Console and plugin pages (ADR 0063 D5): 「更新于 hh:mm:ss」, an
25
+ * auto-refresh interval (Radix select: manual / 5s / 15s / 30s) and a refresh button.
26
+ * Auto-refresh skips ticks while the tab is hidden or a refresh is still running.
27
+ */
28
+ export declare function RefreshControl({ onRefresh, onAutoRefresh, updatedAt, intervalMs, defaultIntervalMs, onIntervalChange, intervals, refreshing, disabled, className, }: RefreshControlProps): import("react").JSX.Element;
@@ -0,0 +1,68 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useCallback, useEffect, useRef, useState } from 'react';
3
+ import { RefreshCw } from 'lucide-react';
4
+ import { CONSOLE_ICON_STROKE_WIDTH } from './icon.js';
5
+ import { cn } from '../cn.js';
6
+ import { useConsoleUiI18n } from '../i18n/index.js';
7
+ import { Button } from './ui/button.js';
8
+ import { SelectField } from './ui/select.js';
9
+ import { DEFAULT_REFRESH_INTERVALS, formatRefreshTime, intervalSeconds, refreshIntervalOptions, } from './refresh-control-model.js';
10
+ /**
11
+ * The one refresh control for Console and plugin pages (ADR 0063 D5): 「更新于 hh:mm:ss」, an
12
+ * auto-refresh interval (Radix select: manual / 5s / 15s / 30s) and a refresh button.
13
+ * Auto-refresh skips ticks while the tab is hidden or a refresh is still running.
14
+ */
15
+ export function RefreshControl({ onRefresh, onAutoRefresh, updatedAt, intervalMs, defaultIntervalMs = 0, onIntervalChange, intervals = DEFAULT_REFRESH_INTERVALS, refreshing, disabled, className, }) {
16
+ const i18n = useConsoleUiI18n();
17
+ const [ownInterval, setOwnInterval] = useState(defaultIntervalMs);
18
+ const [inFlight, setInFlight] = useState(false);
19
+ const inFlightRef = useRef(false);
20
+ const onRefreshRef = useRef(onRefresh);
21
+ onRefreshRef.current = onRefresh;
22
+ const onAutoRefreshRef = useRef(onAutoRefresh);
23
+ onAutoRefreshRef.current = onAutoRefresh;
24
+ const interval = intervalMs ?? ownInterval;
25
+ const busy = Boolean(refreshing) || inFlight;
26
+ const run = useCallback((auto = false) => {
27
+ if (inFlightRef.current)
28
+ return;
29
+ let result;
30
+ try {
31
+ result = (auto && onAutoRefreshRef.current ? onAutoRefreshRef.current : onRefreshRef.current)();
32
+ }
33
+ catch {
34
+ return;
35
+ }
36
+ if (result && typeof result.then === 'function') {
37
+ inFlightRef.current = true;
38
+ setInFlight(true);
39
+ void result.catch(() => undefined).finally(() => {
40
+ inFlightRef.current = false;
41
+ setInFlight(false);
42
+ });
43
+ }
44
+ }, []);
45
+ useEffect(() => {
46
+ if (!(interval > 0) || disabled)
47
+ return;
48
+ const timer = setInterval(() => {
49
+ if (typeof document !== 'undefined' && document.visibilityState === 'hidden')
50
+ return;
51
+ if (refreshing)
52
+ return;
53
+ run(true);
54
+ }, interval);
55
+ return () => clearInterval(timer);
56
+ }, [interval, disabled, refreshing, run]);
57
+ const options = refreshIntervalOptions(interval, intervals).map(value => ({
58
+ value: String(value),
59
+ label: value === 0 ? i18n.t('refresh.manual') : i18n.t('refresh.auto', [intervalSeconds(value)]),
60
+ }));
61
+ const time = formatRefreshTime(updatedAt);
62
+ return (_jsxs("div", { className: cn('console-refresh-control flex flex-wrap items-center gap-2', className), children: [_jsx("span", { className: "console-refresh-control-time text-label text-muted-foreground tabular-nums", "aria-live": "polite", children: time ? i18n.t('refresh.updatedAt', [time]) : i18n.t('refresh.notYet') }), _jsx(SelectField, { "aria-label": i18n.t('refresh.interval'), className: "h-control-compact w-auto min-w-32 text-label", options: options, value: String(interval), disabled: disabled, onValueChange: next => {
63
+ const value = Number(next);
64
+ if (intervalMs === undefined)
65
+ setOwnInterval(value);
66
+ onIntervalChange?.(value);
67
+ } }), _jsxs(Button, { variant: "outline", size: "sm", onClick: () => run(), disabled: disabled || busy, "aria-busy": busy || undefined, children: [_jsx(RefreshCw, { strokeWidth: CONSOLE_ICON_STROKE_WIDTH, "aria-hidden": "true", className: cn(busy && 'animate-spin') }), busy ? i18n.t('refresh.refreshing') : i18n.t('refresh.refresh')] })] }));
68
+ }
@@ -0,0 +1,41 @@
1
+ import { type ReactNode } from 'react';
2
+ import type { LucideIcon } from 'lucide-react';
3
+ export interface StatCardProps {
4
+ /** A Lucide icon component, an element, or an image URL (declarative stats, ADR 0063 P2). */
5
+ icon?: LucideIcon | ReactNode;
6
+ label: ReactNode;
7
+ value: ReactNode;
8
+ /** After the value, in label size (e.g. 「ms」). */
9
+ unit?: ReactNode;
10
+ /** On the label row, right-aligned (status badge). */
11
+ badge?: ReactNode;
12
+ /** Under the value (progress meter). */
13
+ footer?: ReactNode;
14
+ sub?: ReactNode;
15
+ /**
16
+ * Signal tone for an abnormal value (zhinjs/console#125): the value in the signal text color,
17
+ * the icon in its fill. Ignored while the value is 0 — a steady state (「失败 0」) is never colored.
18
+ */
19
+ tone?: 'danger' | 'warning';
20
+ /** 数值右侧的附加内容,如环形进度 */
21
+ aside?: ReactNode;
22
+ /** 提供时整张卡片可点击(跳转或筛选) */
23
+ onOpen?: () => void;
24
+ /** 作为筛选器使用时的选中状态 */
25
+ pressed?: boolean;
26
+ }
27
+ /**
28
+ * 指标卡:图标 + 标签、大号数值、说明文字。总览页与列表页共用。
29
+ */
30
+ export declare function StatCard({ icon, label, value, unit, badge, footer, sub, tone, aside, onOpen, pressed }: StatCardProps): import("react").JSX.Element;
31
+ /** `0`, `'0'`, `'0.0'`, `'0%'`: a steady value that never takes a signal tone. */
32
+ export declare function isZeroValue(value: ReactNode): boolean;
33
+ export declare function StatGrid({ children, label, ...data }: {
34
+ children: ReactNode;
35
+ label: string;
36
+ [data: `data-${string}`]: string | undefined;
37
+ }): import("react").JSX.Element;
38
+ export declare function MiniRingGauge({ percent, tone }: {
39
+ percent: number;
40
+ tone?: 'primary' | 'success' | 'warning';
41
+ }): import("react").JSX.Element;
@@ -0,0 +1,53 @@
1
+ import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { createElement, isValidElement } from 'react';
3
+ import { CONSOLE_ICON_STROKE_WIDTH } from './icon.js';
4
+ import { cn } from '../cn.js';
5
+ /**
6
+ * 指标卡:图标 + 标签、大号数值、说明文字。总览页与列表页共用。
7
+ */
8
+ export function StatCard({ icon, label, value, unit, badge, footer, sub, tone, aside, onOpen, pressed }) {
9
+ const signal = tone && !isZeroValue(value) ? tone : undefined;
10
+ const className = cn('console-stat-card', signal && `is-${signal}`, onOpen && 'is-link', pressed && 'is-pressed');
11
+ const labelRow = _jsxs("span", { className: "console-stat-label", children: [statIcon(icon), label] });
12
+ const content = (_jsxs(_Fragment, { children: [badge != null ? _jsxs("span", { className: "console-stat-head", children: [labelRow, badge] }) : labelRow, _jsxs("span", { className: "console-stat-value-row", children: [_jsxs("strong", { className: "console-stat-value", children: [value, unit != null ? _jsx("span", { className: "console-stat-unit", children: unit }) : null] }), aside] }), footer, sub !== undefined && sub !== null ? _jsx("span", { className: "console-stat-sub", children: sub }) : null] }));
13
+ if (!onOpen)
14
+ return _jsx("div", { className: className, "data-slot": "stat-card", children: content });
15
+ return (_jsx("button", { type: "button", className: className, onClick: onOpen, "aria-pressed": pressed, "data-slot": "stat-card", "data-interactive": "", children: content }));
16
+ }
17
+ /** `0`, `'0'`, `'0.0'`, `'0%'`: a steady value that never takes a signal tone. */
18
+ export function isZeroValue(value) {
19
+ if (typeof value === 'number')
20
+ return value === 0;
21
+ if (typeof value !== 'string')
22
+ return false;
23
+ // Trim first: `\s*%?\s*` inside the pattern backtracks polynomially on long whitespace runs.
24
+ const text = value.trim();
25
+ const number = text.endsWith('%') ? text.slice(0, -1).trimEnd() : text;
26
+ return /^0+(?:[.,]0+)?$/u.test(number);
27
+ }
28
+ function statIcon(icon) {
29
+ if (icon == null || icon === '')
30
+ return null;
31
+ if (typeof icon === 'string')
32
+ return _jsx("img", { src: icon, alt: "", className: "console-stat-icon" });
33
+ if (isValidElement(icon))
34
+ return icon;
35
+ if (typeof icon === 'function' || (typeof icon === 'object' && '$$typeof' in icon))
36
+ return createElement(icon, { 'aria-hidden': true, strokeWidth: CONSOLE_ICON_STROKE_WIDTH });
37
+ return icon;
38
+ }
39
+ export function StatGrid({ children, label, ...data }) {
40
+ return (_jsx("section", { className: "console-cq", "aria-label": label, "data-slot": "stat-grid", ...data, children: _jsx("div", { className: "console-stat-grid", children: children }) }));
41
+ }
42
+ export function MiniRingGauge({ percent, tone = 'primary' }) {
43
+ const clamped = Math.max(0, Math.min(100, percent));
44
+ const r = 16;
45
+ const c = 2 * Math.PI * r;
46
+ const offset = c - (clamped / 100) * c;
47
+ const stroke = tone === 'success'
48
+ ? 'hsl(var(--console-signal-success-fill))'
49
+ : tone === 'warning'
50
+ ? 'hsl(var(--console-signal-warning-fill))'
51
+ : 'hsl(var(--primary))';
52
+ return (_jsxs("span", { className: "console-ring-gauge", "aria-hidden": "true", children: [_jsxs("svg", { viewBox: "0 0 40 40", children: [_jsx("circle", { cx: "20", cy: "20", r: r, fill: "none", stroke: "currentColor", strokeOpacity: 0.12, strokeWidth: "3.5" }), _jsx("circle", { cx: "20", cy: "20", r: r, fill: "none", stroke: stroke, strokeWidth: "3.5", strokeLinecap: "round", strokeDasharray: c, strokeDashoffset: offset })] }), _jsxs("span", { className: "console-ring-gauge-label", children: [clamped, "%"] })] }));
53
+ }
@@ -0,0 +1,14 @@
1
+ import type { ReactNode } from 'react';
2
+ /**
3
+ * State of an object as shown in lists (ADR 0063 D15 第 1 条): colored badges only for states that
4
+ * are abnormal or need attention; 「正常」 and neutral states are muted text.
5
+ */
6
+ export type ConsoleStatus = 'ok' | 'neutral' | 'info' | 'pending' | 'warning' | 'error';
7
+ export interface StatusBadgeProps {
8
+ status: ConsoleStatus;
9
+ children: ReactNode;
10
+ className?: string;
11
+ }
12
+ /** Whether a status is rendered as a colored badge (only abnormal / attention states are). */
13
+ export declare function isAttentionStatus(status: ConsoleStatus): boolean;
14
+ export declare function StatusBadge({ status, children, className }: StatusBadgeProps): import("react").JSX.Element;
@@ -0,0 +1,19 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { cn } from '../cn.js';
3
+ const QUIET = new Set(['ok', 'neutral']);
4
+ const BADGE_CLASS = {
5
+ info: 'console-badge-info',
6
+ pending: 'console-badge-info',
7
+ warning: 'console-badge-warning',
8
+ error: 'console-badge-danger',
9
+ };
10
+ /** Whether a status is rendered as a colored badge (only abnormal / attention states are). */
11
+ export function isAttentionStatus(status) {
12
+ return !QUIET.has(status);
13
+ }
14
+ export function StatusBadge({ status, children, className }) {
15
+ if (QUIET.has(status)) {
16
+ return _jsx("span", { className: cn('console-status-quiet', className), "data-slot": "status", "data-status": status, children: children });
17
+ }
18
+ return (_jsx("span", { className: cn('console-badge', BADGE_CLASS[status], className), "data-slot": "badge", "data-status": status, children: children }));
19
+ }
@@ -0,0 +1,53 @@
1
+ import { type ReactNode } from 'react';
2
+ import { type LucideIcon } from 'lucide-react';
3
+ import { type ButtonProps } from './ui/button.js';
4
+ /**
5
+ * One page or row action (ADR 0063 D15 第 4 条): always has a visible label. Rendered as a button
6
+ * where there is room, as an item of the 「更多」 menu where there is not.
7
+ */
8
+ export interface PageAction {
9
+ /** Stable key; defaults to the label. */
10
+ readonly key?: string;
11
+ readonly label: string;
12
+ readonly onSelect: () => void;
13
+ readonly icon?: LucideIcon;
14
+ /**
15
+ * `primary` is the solid brand button — at most one per view (zhinjs/console#125); `destructive`
16
+ * renders the outline button with destructive text (ADR 0063 决策 5).
17
+ */
18
+ readonly tone?: 'default' | 'primary' | 'destructive';
19
+ readonly disabled?: boolean;
20
+ }
21
+ export interface MoreMenuProps {
22
+ readonly actions: readonly PageAction[];
23
+ /** Trigger text; defaults to 「更多」. The trigger always shows its text (D15 第 4 条). */
24
+ readonly label?: string;
25
+ readonly size?: ButtonProps['size'];
26
+ readonly align?: 'start' | 'end';
27
+ readonly className?: string;
28
+ }
29
+ /** The 「更多」 menu: actions that do not get a button of their own. Destructive items come last. */
30
+ export declare function MoreMenu({ actions, label, size, align, className }: MoreMenuProps): import("react").JSX.Element | null;
31
+ export interface PageActionsProps {
32
+ /** Always visible (refresh control, custom controls). Wraps instead of leaving the viewport. */
33
+ readonly children?: ReactNode;
34
+ /** Buttons where the header is at least 40rem wide; collapsed into 「更多」 below that. */
35
+ readonly actions?: readonly PageAction[];
36
+ /** Always in the 「更多」 menu. */
37
+ readonly moreActions?: readonly PageAction[];
38
+ readonly className?: string;
39
+ }
40
+ /**
41
+ * Header actions (ADR 0063 D18 第 7 条): what does not fit goes into the 「更多」 menu, so no
42
+ * control is ever pushed out of the viewport. Measures its own width, i.e. the header's.
43
+ */
44
+ export declare function PageActions({ children, actions, moreActions, className }: PageActionsProps): import("react").JSX.Element | null;
45
+ export interface RowActionsProps {
46
+ /** The main action of the row, shown with its label. */
47
+ readonly primary?: PageAction;
48
+ /** Everything else, in the 「更多」 menu (D15 第 4 条). */
49
+ readonly more?: readonly PageAction[];
50
+ readonly className?: string;
51
+ }
52
+ /** Actions of one table row or list item: one labelled button, the rest in 「更多」. */
53
+ export declare function RowActions({ primary, more, className }: RowActionsProps): import("react").JSX.Element;