@asabot/panel-ui 0.0.0-stage → 0.2.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.
- package/LICENSE +21 -0
- package/README.md +41 -2
- package/dist/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
- package/dist/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
- package/dist/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
- package/dist/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
- package/dist/assets/geist-mono-cyrillic-ext-wght-normal-X_5orZeX.woff2 +0 -0
- package/dist/assets/geist-mono-cyrillic-wght-normal-DiZS0aHC.woff2 +0 -0
- package/dist/assets/geist-mono-latin-ext-wght-normal-Bwz-egvJ.woff2 +0 -0
- package/dist/assets/geist-mono-latin-wght-normal-XN7g48iV.woff2 +0 -0
- package/dist/assets/geist-mono-symbols2-wght-normal-CO5SzqOn.woff2 +0 -0
- package/dist/assets/geist-mono-vietnamese-wght-normal-DadHysG0.woff2 +0 -0
- package/dist/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
- package/dist/assets/noto-sans-sc-100-wght-normal-DluiXYzi.woff2 +0 -0
- package/dist/assets/noto-sans-sc-101-wght-normal-CPkZHnw0.woff2 +0 -0
- package/dist/assets/noto-sans-sc-102-wght-normal-gzIulUH6.woff2 +0 -0
- package/dist/assets/noto-sans-sc-103-wght-normal-CJfSBxFo.woff2 +0 -0
- package/dist/assets/noto-sans-sc-104-wght-normal-B3QMglgE.woff2 +0 -0
- package/dist/assets/noto-sans-sc-105-wght-normal-xXh_OMfk.woff2 +0 -0
- package/dist/assets/noto-sans-sc-106-wght-normal-B9n3jMjP.woff2 +0 -0
- package/dist/assets/noto-sans-sc-107-wght-normal-D7fvVprN.woff2 +0 -0
- package/dist/assets/noto-sans-sc-108-wght-normal-J0_LhxVo.woff2 +0 -0
- package/dist/assets/noto-sans-sc-109-wght-normal-Dsp-De_0.woff2 +0 -0
- package/dist/assets/noto-sans-sc-110-wght-normal-DE_6NUrb.woff2 +0 -0
- package/dist/assets/noto-sans-sc-111-wght-normal-C4S-TlTn.woff2 +0 -0
- package/dist/assets/noto-sans-sc-112-wght-normal-BcFuP3w6.woff2 +0 -0
- package/dist/assets/noto-sans-sc-113-wght-normal-Dk932kmj.woff2 +0 -0
- package/dist/assets/noto-sans-sc-114-wght-normal-CO_5Xo-i.woff2 +0 -0
- package/dist/assets/noto-sans-sc-115-wght-normal-BWy07H14.woff2 +0 -0
- package/dist/assets/noto-sans-sc-116-wght-normal-B4HVAfHo.woff2 +0 -0
- package/dist/assets/noto-sans-sc-117-wght-normal-siZzFqgK.woff2 +0 -0
- package/dist/assets/noto-sans-sc-118-wght-normal-xhBB7f6V.woff2 +0 -0
- package/dist/assets/noto-sans-sc-119-wght-normal-Ck_g2FGz.woff2 +0 -0
- package/dist/assets/noto-sans-sc-21-wght-normal-D0x9-yBt.woff2 +0 -0
- package/dist/assets/noto-sans-sc-22-wght-normal-BBUVTShg.woff2 +0 -0
- package/dist/assets/noto-sans-sc-23-wght-normal-Du1oYWkE.woff2 +0 -0
- package/dist/assets/noto-sans-sc-24-wght-normal-CmWjJ0gt.woff2 +0 -0
- package/dist/assets/noto-sans-sc-25-wght-normal-BFHiqilg.woff2 +0 -0
- package/dist/assets/noto-sans-sc-26-wght-normal-C0sF2Z2f.woff2 +0 -0
- package/dist/assets/noto-sans-sc-27-wght-normal-COFdrquJ.woff2 +0 -0
- package/dist/assets/noto-sans-sc-28-wght-normal-DMgdNu1o.woff2 +0 -0
- package/dist/assets/noto-sans-sc-29-wght-normal-Cmq8em30.woff2 +0 -0
- package/dist/assets/noto-sans-sc-30-wght-normal-CZWqZ3yU.woff2 +0 -0
- package/dist/assets/noto-sans-sc-31-wght-normal-Wfi_lutW.woff2 +0 -0
- package/dist/assets/noto-sans-sc-32-wght-normal-BRJQ4PY5.woff2 +0 -0
- package/dist/assets/noto-sans-sc-33-wght-normal-CUVQXNAJ.woff2 +0 -0
- package/dist/assets/noto-sans-sc-34-wght-normal-Bspba0wC.woff2 +0 -0
- package/dist/assets/noto-sans-sc-35-wght-normal-K8fX_YPG.woff2 +0 -0
- package/dist/assets/noto-sans-sc-36-wght-normal-CkITyjoT.woff2 +0 -0
- package/dist/assets/noto-sans-sc-37-wght-normal-WCZ2zfEe.woff2 +0 -0
- package/dist/assets/noto-sans-sc-38-wght-normal-DeM7CUce.woff2 +0 -0
- package/dist/assets/noto-sans-sc-39-wght-normal-BMZNLWQU.woff2 +0 -0
- package/dist/assets/noto-sans-sc-4-wght-normal-AR5bdDjz.woff2 +0 -0
- package/dist/assets/noto-sans-sc-40-wght-normal-BQ5xpS5j.woff2 +0 -0
- package/dist/assets/noto-sans-sc-41-wght-normal-Hthm7FFi.woff2 +0 -0
- package/dist/assets/noto-sans-sc-42-wght-normal-eaS2gKds.woff2 +0 -0
- package/dist/assets/noto-sans-sc-43-wght-normal-o-T53XXV.woff2 +0 -0
- package/dist/assets/noto-sans-sc-44-wght-normal-BJH5J4Ez.woff2 +0 -0
- package/dist/assets/noto-sans-sc-45-wght-normal-BKuxSCOJ.woff2 +0 -0
- package/dist/assets/noto-sans-sc-46-wght-normal-BR_5Mu6e.woff2 +0 -0
- package/dist/assets/noto-sans-sc-47-wght-normal-CyY7gKNX.woff2 +0 -0
- package/dist/assets/noto-sans-sc-48-wght-normal-BNMfTR6k.woff2 +0 -0
- package/dist/assets/noto-sans-sc-49-wght-normal-DX-0y7wg.woff2 +0 -0
- package/dist/assets/noto-sans-sc-5-wght-normal-CfWugllB.woff2 +0 -0
- package/dist/assets/noto-sans-sc-50-wght-normal-DAOGW-Dr.woff2 +0 -0
- package/dist/assets/noto-sans-sc-51-wght-normal-BlFLOjcP.woff2 +0 -0
- package/dist/assets/noto-sans-sc-52-wght-normal-OZjrybnw.woff2 +0 -0
- package/dist/assets/noto-sans-sc-53-wght-normal-CwyWNT6x.woff2 +0 -0
- package/dist/assets/noto-sans-sc-54-wght-normal-DM0nRe18.woff2 +0 -0
- package/dist/assets/noto-sans-sc-55-wght-normal-DBK2wUOR.woff2 +0 -0
- package/dist/assets/noto-sans-sc-56-wght-normal-C-VKK1LS.woff2 +0 -0
- package/dist/assets/noto-sans-sc-57-wght-normal-Cdbfh5kq.woff2 +0 -0
- package/dist/assets/noto-sans-sc-58-wght-normal-CflMKARZ.woff2 +0 -0
- package/dist/assets/noto-sans-sc-59-wght-normal-BS4Kwzxx.woff2 +0 -0
- package/dist/assets/noto-sans-sc-6-wght-normal-ChnZIQfQ.woff2 +0 -0
- package/dist/assets/noto-sans-sc-60-wght-normal-B7QOYsXJ.woff2 +0 -0
- package/dist/assets/noto-sans-sc-61-wght-normal-C8JjQS7w.woff2 +0 -0
- package/dist/assets/noto-sans-sc-62-wght-normal-bS4wq1Gg.woff2 +0 -0
- package/dist/assets/noto-sans-sc-63-wght-normal-BJr8P-OB.woff2 +0 -0
- package/dist/assets/noto-sans-sc-64-wght-normal-DVB11t7j.woff2 +0 -0
- package/dist/assets/noto-sans-sc-65-wght-normal-DMPCXBvK.woff2 +0 -0
- package/dist/assets/noto-sans-sc-66-wght-normal-BobaG10V.woff2 +0 -0
- package/dist/assets/noto-sans-sc-67-wght-normal-Dzk7WhCR.woff2 +0 -0
- package/dist/assets/noto-sans-sc-68-wght-normal-DGbCD9xu.woff2 +0 -0
- package/dist/assets/noto-sans-sc-69-wght-normal-Ctrv1EqA.woff2 +0 -0
- package/dist/assets/noto-sans-sc-70-wght-normal-RgTO941D.woff2 +0 -0
- package/dist/assets/noto-sans-sc-71-wght-normal-D9sG-CWv.woff2 +0 -0
- package/dist/assets/noto-sans-sc-72-wght-normal-C4oWy3ul.woff2 +0 -0
- package/dist/assets/noto-sans-sc-73-wght-normal-B1ZoOTgM.woff2 +0 -0
- package/dist/assets/noto-sans-sc-74-wght-normal-F7dH_rZJ.woff2 +0 -0
- package/dist/assets/noto-sans-sc-75-wght-normal-Cp2wp4si.woff2 +0 -0
- package/dist/assets/noto-sans-sc-76-wght-normal-B494D7xS.woff2 +0 -0
- package/dist/assets/noto-sans-sc-77-wght-normal-B3MVY9Ax.woff2 +0 -0
- package/dist/assets/noto-sans-sc-78-wght-normal-5jX7iNMC.woff2 +0 -0
- package/dist/assets/noto-sans-sc-79-wght-normal-BIoZy8fr.woff2 +0 -0
- package/dist/assets/noto-sans-sc-80-wght-normal-Bje1Fxy1.woff2 +0 -0
- package/dist/assets/noto-sans-sc-81-wght-normal-B2NN7Qi3.woff2 +0 -0
- package/dist/assets/noto-sans-sc-82-wght-normal-CUggNZi4.woff2 +0 -0
- package/dist/assets/noto-sans-sc-83-wght-normal-99rD8YO-.woff2 +0 -0
- package/dist/assets/noto-sans-sc-84-wght-normal-zMBmUocm.woff2 +0 -0
- package/dist/assets/noto-sans-sc-85-wght-normal-CjI3qdxG.woff2 +0 -0
- package/dist/assets/noto-sans-sc-86-wght-normal-BHY8TVEH.woff2 +0 -0
- package/dist/assets/noto-sans-sc-87-wght-normal-DioZSHnU.woff2 +0 -0
- package/dist/assets/noto-sans-sc-88-wght-normal-BXYxwf2t.woff2 +0 -0
- package/dist/assets/noto-sans-sc-89-wght-normal-ClMFrFaL.woff2 +0 -0
- package/dist/assets/noto-sans-sc-90-wght-normal-BnOlPreP.woff2 +0 -0
- package/dist/assets/noto-sans-sc-91-wght-normal-DTr9RQcS.woff2 +0 -0
- package/dist/assets/noto-sans-sc-97-wght-normal-9u6Aiav-.woff2 +0 -0
- package/dist/assets/noto-sans-sc-98-wght-normal-BR-H2C0V.woff2 +0 -0
- package/dist/assets/noto-sans-sc-99-wght-normal-BI6XPoxp.woff2 +0 -0
- package/dist/assets/noto-sans-sc-cyrillic-wght-normal-BGmsQlw-.woff2 +0 -0
- package/dist/assets/noto-sans-sc-latin-ext-wght-normal-DuJTpTg_.woff2 +0 -0
- package/dist/assets/noto-sans-sc-latin-wght-normal-DDW8mKAR.woff2 +0 -0
- package/dist/assets/noto-sans-sc-vietnamese-wght-normal-Bi3ATJ76.woff2 +0 -0
- package/dist/avatar.d.ts +11 -0
- package/dist/avatar.js +25 -0
- package/dist/compatibility-info.d.ts +11 -0
- package/dist/compatibility-info.js +12 -0
- package/dist/delivery-failure.d.ts +4 -0
- package/dist/delivery-failure.js +10 -0
- package/dist/fonts.css +1 -0
- package/dist/format.d.ts +25 -0
- package/dist/format.js +33 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +21 -0
- package/dist/licenses/geist-mono.txt +93 -0
- package/dist/licenses/geist.txt +93 -0
- package/dist/licenses/noto-sans-sc.txt +93 -0
- package/dist/logo.d.ts +3 -0
- package/dist/logo.js +8 -0
- package/dist/markdown.d.ts +4 -0
- package/dist/markdown.js +25 -0
- package/dist/message-chart.d.ts +6 -0
- package/dist/message-chart.js +103 -0
- package/dist/motion.d.ts +45 -0
- package/dist/motion.js +22 -0
- package/dist/plugin-page-layout.d.ts +7 -0
- package/dist/plugin-page-layout.js +6 -0
- package/dist/provider.d.ts +4 -0
- package/dist/provider.js +6 -0
- package/dist/schema-form.d.ts +39 -0
- package/dist/schema-form.js +244 -0
- package/dist/segments.d.ts +10 -0
- package/dist/segments.js +81 -0
- package/dist/styles.css +2 -0
- package/dist/trace-view.d.ts +6 -0
- package/dist/trace-view.js +58 -0
- package/dist/types.d.ts +85 -0
- package/dist/types.js +1 -0
- package/dist/ui/button.d.ts +25 -0
- package/dist/ui/button.js +24 -0
- package/dist/ui/date-picker.d.ts +15 -0
- package/dist/ui/date-picker.js +167 -0
- package/dist/ui/dialog.d.ts +20 -0
- package/dist/ui/dialog.js +17 -0
- package/dist/ui/input.d.ts +14 -0
- package/dist/ui/input.js +15 -0
- package/dist/ui/misc.d.ts +62 -0
- package/dist/ui/misc.js +53 -0
- package/dist/ui/primitives.d.ts +59 -0
- package/dist/ui/primitives.js +51 -0
- package/dist/ui/select.d.ts +17 -0
- package/dist/ui/select.js +12 -0
- package/dist/ui/switch.d.ts +8 -0
- package/dist/ui/switch.js +8 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +15 -0
- package/package.json +68 -3
package/dist/markdown.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ImageOff } from 'lucide-react';
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import ReactMarkdown, {} from 'react-markdown';
|
|
5
|
+
import remarkGfm from 'remark-gfm';
|
|
6
|
+
import { cn } from './utils.js';
|
|
7
|
+
const external = /^(?:https?:|mailto:)/i;
|
|
8
|
+
function MissingImage({ alt }) {
|
|
9
|
+
return (_jsxs("span", { className: "inline-flex items-center gap-1.5 rounded-md bg-surface-2 px-2 py-0.5 text-[12px] text-fg-3", children: [_jsx(ImageOff, { className: "size-3.5" }), alt || '图片'] }));
|
|
10
|
+
}
|
|
11
|
+
function RemoteImage({ src, alt }) {
|
|
12
|
+
const [failed, setFailed] = useState(false);
|
|
13
|
+
if (failed)
|
|
14
|
+
return _jsx(MissingImage, { alt: alt });
|
|
15
|
+
return (_jsx("img", { src: src, alt: alt ?? '', loading: "lazy", referrerPolicy: "no-referrer", onError: () => setFailed(true) }));
|
|
16
|
+
}
|
|
17
|
+
// README content comes from third-party packages: raw HTML is dropped (skipHtml), links leave the panel
|
|
18
|
+
// in a new tab, and only https images are fetched.
|
|
19
|
+
const components = {
|
|
20
|
+
a: ({ node: _node, href, children }) => href && external.test(href) ? (_jsx("a", { href: href, target: "_blank", rel: "noopener noreferrer", children: children })) : (_jsx("span", { children: children })),
|
|
21
|
+
img: ({ node: _node, src, alt }) => typeof src === 'string' && src.startsWith('https://') ? (_jsx(RemoteImage, { src: src, alt: alt })) : (_jsx(MissingImage, { alt: alt })),
|
|
22
|
+
};
|
|
23
|
+
export function Markdown({ children, className }) {
|
|
24
|
+
return (_jsx("div", { className: cn('markdown', className), children: _jsx(ReactMarkdown, { remarkPlugins: [remarkGfm], components: components, skipHtml: true, children: children }) }));
|
|
25
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { AnimatePresence, motion } from 'motion/react';
|
|
3
|
+
import { useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
4
|
+
import { formatClock, formatNumber } from './format.js';
|
|
5
|
+
import { softSpring } from './motion.js';
|
|
6
|
+
import { cn } from './utils.js';
|
|
7
|
+
const height = 232;
|
|
8
|
+
const pad = { top: 14, right: 12, bottom: 26, left: 40 };
|
|
9
|
+
const series = [
|
|
10
|
+
{ key: 'received', label: '收到', color: 'var(--series-in)' },
|
|
11
|
+
{ key: 'sent', label: '发出', color: 'var(--series-out)' },
|
|
12
|
+
];
|
|
13
|
+
/** Monotone cubic interpolation (Fritsch–Carlson): smooth, but never overshoots between data points. */
|
|
14
|
+
function monotonePath(points) {
|
|
15
|
+
const first = points[0];
|
|
16
|
+
if (!first)
|
|
17
|
+
return '';
|
|
18
|
+
const slopes = [];
|
|
19
|
+
const widths = [];
|
|
20
|
+
for (let i = 1; i < points.length; i++) {
|
|
21
|
+
const [x0, y0] = points[i - 1] ?? first;
|
|
22
|
+
const [x1, y1] = points[i] ?? first;
|
|
23
|
+
widths.push(x1 - x0);
|
|
24
|
+
slopes.push((y1 - y0) / (x1 - x0));
|
|
25
|
+
}
|
|
26
|
+
const tangents = points.map((_, i) => {
|
|
27
|
+
const s0 = slopes[i - 1];
|
|
28
|
+
const s1 = slopes[i];
|
|
29
|
+
if (s0 === undefined)
|
|
30
|
+
return s1 ?? 0;
|
|
31
|
+
if (s1 === undefined || s0 * s1 <= 0)
|
|
32
|
+
return s1 === undefined ? s0 : 0;
|
|
33
|
+
const w0 = widths[i - 1] ?? 0;
|
|
34
|
+
const w1 = widths[i] ?? 0;
|
|
35
|
+
return (3 * (w0 + w1)) / ((2 * w1 + w0) / s0 + (w1 + 2 * w0) / s1);
|
|
36
|
+
});
|
|
37
|
+
let d = `M${first[0]},${first[1]}`;
|
|
38
|
+
for (let i = 1; i < points.length; i++) {
|
|
39
|
+
const [x0, y0] = points[i - 1] ?? first;
|
|
40
|
+
const [x1, y1] = points[i] ?? first;
|
|
41
|
+
const h = (x1 - x0) / 3;
|
|
42
|
+
d += `C${x0 + h},${y0 + h * (tangents[i - 1] ?? 0)},${x1 - h},${y1 - h * (tangents[i] ?? 0)},${x1},${y1}`;
|
|
43
|
+
}
|
|
44
|
+
return d;
|
|
45
|
+
}
|
|
46
|
+
/** Rounds the axis so the four gridline steps are whole, readable numbers (1, 2, 5 × 10ⁿ). */
|
|
47
|
+
function niceScale(value) {
|
|
48
|
+
const raw = Math.max(1, value) / 4;
|
|
49
|
+
const magnitude = 10 ** Math.floor(Math.log10(raw));
|
|
50
|
+
const normalized = raw / magnitude;
|
|
51
|
+
const step = Math.max(1, (normalized <= 1 ? 1 : normalized <= 2 ? 2 : normalized <= 5 ? 5 : 10) * magnitude);
|
|
52
|
+
return { max: step * 4, step };
|
|
53
|
+
}
|
|
54
|
+
export function MessageChart({ points, range, dimmed = false, }) {
|
|
55
|
+
const containerRef = useRef(null);
|
|
56
|
+
const [width, setWidth] = useState(0);
|
|
57
|
+
const [hover, setHover] = useState(null);
|
|
58
|
+
useLayoutEffect(() => {
|
|
59
|
+
const element = containerRef.current;
|
|
60
|
+
if (!element)
|
|
61
|
+
return;
|
|
62
|
+
const observer = new ResizeObserver(([entry]) => setWidth(entry?.contentRect.width ?? 0));
|
|
63
|
+
observer.observe(element);
|
|
64
|
+
return () => observer.disconnect();
|
|
65
|
+
}, []);
|
|
66
|
+
const geometry = useMemo(() => {
|
|
67
|
+
if (width === 0 || points.length === 0)
|
|
68
|
+
return null;
|
|
69
|
+
const innerWidth = width - pad.left - pad.right;
|
|
70
|
+
const innerHeight = height - pad.top - pad.bottom;
|
|
71
|
+
const { max, step: tickStep } = niceScale(Math.max(...points.map((point) => Math.max(point.received, point.sent))));
|
|
72
|
+
const step = points.length > 1 ? innerWidth / (points.length - 1) : 0;
|
|
73
|
+
const x = (index) => pad.left + index * step;
|
|
74
|
+
const y = (value) => pad.top + innerHeight - (value / max) * innerHeight;
|
|
75
|
+
const lines = Object.fromEntries(series.map((s) => {
|
|
76
|
+
const coords = points.map((point, index) => [x(index), y(point[s.key])]);
|
|
77
|
+
const line = monotonePath(coords);
|
|
78
|
+
const area = `${line}L${x(points.length - 1)},${y(0)}L${x(0)},${y(0)}Z`;
|
|
79
|
+
return [s.key, { line, area }];
|
|
80
|
+
}));
|
|
81
|
+
const ticks = [0, 1, 2, 3, 4].map((index) => ({ value: index * tickStep, y: y(index * tickStep) }));
|
|
82
|
+
const labelEvery = range === '1h' ? 15 : 24; // every 15 minutes, or every 6 hours (24 × 15 min)
|
|
83
|
+
const xLabels = points
|
|
84
|
+
.map((point, index) => ({ index, t: point.t }))
|
|
85
|
+
.filter(({ t, index }) => range === '1h' ? new Date(t).getMinutes() % 15 === 0 : index % labelEvery === 0);
|
|
86
|
+
return { x, y, lines, ticks, xLabels, innerHeight, step };
|
|
87
|
+
}, [points, range, width]);
|
|
88
|
+
const onPointerMove = (event) => {
|
|
89
|
+
if (!geometry || points.length === 0)
|
|
90
|
+
return;
|
|
91
|
+
const bounds = event.currentTarget.getBoundingClientRect();
|
|
92
|
+
const relative = event.clientX - bounds.left;
|
|
93
|
+
const index = geometry.step === 0 ? 0 : Math.round(relative / geometry.step);
|
|
94
|
+
setHover(Math.max(0, Math.min(points.length - 1, index)));
|
|
95
|
+
};
|
|
96
|
+
const hovered = hover === null ? null : points[hover];
|
|
97
|
+
const totals = {
|
|
98
|
+
received: points.reduce((sum, point) => sum + point.received, 0),
|
|
99
|
+
sent: points.reduce((sum, point) => sum + point.sent, 0),
|
|
100
|
+
};
|
|
101
|
+
const empty = totals.received === 0 && totals.sent === 0;
|
|
102
|
+
return (_jsxs("div", { children: [_jsx("div", { className: "mb-3 flex items-center gap-5 px-5", children: series.map((s) => (_jsxs("div", { className: "flex items-center gap-2 text-[12.5px] text-fg-2", children: [_jsx("span", { className: "h-[2px] w-3.5 rounded-full", style: { background: s.color } }), s.label, _jsx("span", { className: "font-medium text-fg tabular", children: formatNumber(totals[s.key]) })] }, s.key))) }), _jsxs("div", { ref: containerRef, className: cn('relative transition-opacity duration-300', dimmed && 'opacity-50'), style: { height }, children: [geometry && (_jsxs("svg", { width: width, height: height, className: "block overflow-visible", role: "img", "aria-label": "\u6D88\u606F\u8D8B\u52BF\u56FE", children: [_jsx("defs", { children: series.map((s) => (_jsxs("linearGradient", { id: `fill-${s.key}`, x1: "0", x2: "0", y1: "0", y2: "1", children: [_jsx("stop", { offset: "0%", stopColor: s.color, stopOpacity: 0.14 }), _jsx("stop", { offset: "100%", stopColor: s.color, stopOpacity: 0.01 })] }, s.key))) }), geometry.ticks.map((tick) => (_jsxs("g", { children: [_jsx("line", { x1: pad.left, x2: width - pad.right, y1: tick.y, y2: tick.y, stroke: "var(--border)", strokeWidth: 1 }), _jsx("text", { x: pad.left - 10, y: tick.y, dy: "0.32em", textAnchor: "end", className: "fill-fg-3 text-[11px] tabular", children: formatNumber(tick.value) })] }, tick.value))), geometry.xLabels.map(({ index, t }) => (_jsx("text", { x: geometry.x(index), y: height - 6, textAnchor: "middle", className: "fill-fg-3 text-[11px] tabular", children: formatClock(t, false) }, t))), series.map((s) => (_jsx(motion.path, { d: geometry.lines[s.key].area, fill: `url(#fill-${s.key})`, initial: { opacity: 0 }, animate: { opacity: 1, d: geometry.lines[s.key].area }, transition: softSpring }, `${s.key}-area`))), series.map((s) => (_jsx(motion.path, { d: geometry.lines[s.key].line, fill: "none", stroke: s.color, strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", initial: { pathLength: 0 }, animate: { pathLength: 1, d: geometry.lines[s.key].line }, transition: { pathLength: { duration: 1.1, ease: [0.16, 1, 0.3, 1] }, d: softSpring } }, `${s.key}-line`))), hovered && hover !== null && (_jsxs("g", { pointerEvents: "none", children: [_jsx("line", { x1: geometry.x(hover), x2: geometry.x(hover), y1: pad.top, y2: pad.top + geometry.innerHeight, stroke: "var(--border-strong)", strokeWidth: 1 }), series.map((s) => (_jsx(motion.circle, { initial: false, animate: { cx: geometry.x(hover), cy: geometry.y(hovered[s.key]) }, transition: { type: 'spring', stiffness: 700, damping: 40 }, r: 4, fill: s.color, stroke: "var(--surface)", strokeWidth: 2 }, s.key)))] })), _jsx("rect", { x: pad.left, y: pad.top, width: Math.max(0, width - pad.left - pad.right), height: geometry.innerHeight, fill: "transparent", onPointerMove: onPointerMove, onPointerLeave: () => setHover(null) })] })), _jsx(AnimatePresence, { children: hovered && hover !== null && geometry && (_jsxs(motion.div, { initial: { opacity: 0, y: 4 }, animate: { opacity: 1, y: 0, x: Math.min(Math.max(geometry.x(hover) - 70, 0), width - 150) }, exit: { opacity: 0 }, transition: { type: 'spring', stiffness: 600, damping: 40 }, className: "pointer-events-none absolute top-1 left-0 w-[150px] rounded-xl border border-border bg-surface/95 px-3 py-2.5 shadow-pop backdrop-blur", children: [_jsxs("div", { className: "mb-1.5 text-[11.5px] text-fg-3 tabular", children: [formatClock(hovered.t, false), range === '24h' && ` – ${formatClock(hovered.t + 15 * 60_000, false)}`] }), series.map((s) => (_jsxs("div", { className: "flex items-center gap-2 text-[12.5px]", children: [_jsx("span", { className: "h-[2px] w-3 rounded-full", style: { background: s.color } }), _jsx("span", { className: "font-semibold text-fg tabular", children: formatNumber(hovered[s.key]) }), _jsx("span", { className: "text-fg-3", children: s.label })] }, s.key)))] })) }), empty && geometry && (_jsx("div", { className: "pointer-events-none absolute inset-0 flex items-center justify-center pb-6 text-[12.5px] text-fg-3", children: "\u8FD9\u6BB5\u65F6\u95F4\u8FD8\u6CA1\u6709\u6D88\u606F" })), _jsxs("table", { className: "sr-only", children: [_jsx("caption", { children: "\u6BCF\u4E2A\u65F6\u95F4\u6BB5\u6536\u5230\u548C\u53D1\u51FA\u7684\u6D88\u606F\u6570" }), _jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { children: "\u65F6\u95F4" }), _jsx("th", { children: "\u6536\u5230" }), _jsx("th", { children: "\u53D1\u51FA" })] }) }), _jsx("tbody", { children: points.map((point) => (_jsxs("tr", { children: [_jsx("td", { children: formatClock(point.t, false) }), _jsx("td", { children: point.received }), _jsx("td", { children: point.sent })] }, point.t))) })] })] })] }));
|
|
103
|
+
}
|
package/dist/motion.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type Transition } from 'motion/react';
|
|
2
|
+
/** Shared motion presets so every transition in the panel feels like one system. */
|
|
3
|
+
export declare const spring: Transition;
|
|
4
|
+
export declare const softSpring: Transition;
|
|
5
|
+
export declare const snappy: Transition;
|
|
6
|
+
export declare function useFadeUp(): {
|
|
7
|
+
initial: {
|
|
8
|
+
opacity: number;
|
|
9
|
+
y: number;
|
|
10
|
+
};
|
|
11
|
+
animate: {
|
|
12
|
+
opacity: number;
|
|
13
|
+
y: number;
|
|
14
|
+
};
|
|
15
|
+
exit: {
|
|
16
|
+
opacity: number;
|
|
17
|
+
y: number;
|
|
18
|
+
transition: {
|
|
19
|
+
duration: number;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
transition: Transition;
|
|
23
|
+
};
|
|
24
|
+
/** Parent/child variants for staggered list entrances. */
|
|
25
|
+
export declare const stagger: {
|
|
26
|
+
animate: {
|
|
27
|
+
transition: {
|
|
28
|
+
staggerChildren: number;
|
|
29
|
+
delayChildren: number;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export declare const staggerItem: {
|
|
34
|
+
initial: {
|
|
35
|
+
opacity: number;
|
|
36
|
+
y: number;
|
|
37
|
+
scale: number;
|
|
38
|
+
};
|
|
39
|
+
animate: {
|
|
40
|
+
opacity: number;
|
|
41
|
+
y: number;
|
|
42
|
+
scale: number;
|
|
43
|
+
transition: Transition;
|
|
44
|
+
};
|
|
45
|
+
};
|
package/dist/motion.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useReducedMotion } from 'motion/react';
|
|
2
|
+
/** Shared motion presets so every transition in the panel feels like one system. */
|
|
3
|
+
export const spring = { type: 'spring', stiffness: 420, damping: 34, mass: 0.8 };
|
|
4
|
+
export const softSpring = { type: 'spring', stiffness: 260, damping: 30 };
|
|
5
|
+
export const snappy = { type: 'spring', stiffness: 600, damping: 38 };
|
|
6
|
+
export function useFadeUp() {
|
|
7
|
+
const reducedMotion = useReducedMotion();
|
|
8
|
+
return {
|
|
9
|
+
initial: { opacity: 0, y: reducedMotion ? 0 : 8 },
|
|
10
|
+
animate: { opacity: 1, y: 0 },
|
|
11
|
+
exit: { opacity: 0, y: reducedMotion ? 0 : -4, transition: { duration: 0.12 } },
|
|
12
|
+
transition: softSpring,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/** Parent/child variants for staggered list entrances. */
|
|
16
|
+
export const stagger = {
|
|
17
|
+
animate: { transition: { staggerChildren: 0.035, delayChildren: 0.04 } },
|
|
18
|
+
};
|
|
19
|
+
export const staggerItem = {
|
|
20
|
+
initial: { opacity: 0, y: 10, scale: 0.985 },
|
|
21
|
+
animate: { opacity: 1, y: 0, scale: 1, transition: softSpring },
|
|
22
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
/** Use as the outermost layout inside a plugin's iframe. The toolbar stays above the scrolling content. */
|
|
3
|
+
export declare function PluginPageLayout({ toolbar, children, className, }: {
|
|
4
|
+
toolbar?: ReactNode;
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
className?: string;
|
|
7
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cn } from './utils.js';
|
|
3
|
+
/** Use as the outermost layout inside a plugin's iframe. The toolbar stays above the scrolling content. */
|
|
4
|
+
export function PluginPageLayout({ toolbar, children, className, }) {
|
|
5
|
+
return (_jsxs("div", { className: cn('flex h-dvh min-w-0 flex-col overflow-clip', className), children: [toolbar && _jsx("div", { className: "shrink-0", children: toolbar }), _jsx("div", { className: "min-h-0 min-w-0 flex-1 overflow-y-auto overscroll-y-contain", children: children })] }));
|
|
6
|
+
}
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { MotionConfig } from 'motion/react';
|
|
3
|
+
import { TooltipProvider } from './ui/misc.js';
|
|
4
|
+
export function PanelUIProvider({ children }) {
|
|
5
|
+
return (_jsx(MotionConfig, { reducedMotion: "user", children: _jsx(TooltipProvider, { children: children }) }));
|
|
6
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import type { JsonSchema, SchemaOptionSource } from './types.ts';
|
|
3
|
+
import { type SelectOption } from './ui/select.tsx';
|
|
4
|
+
type Value = unknown;
|
|
5
|
+
type Issues = Record<string, string>;
|
|
6
|
+
export type SchemaOptions = {
|
|
7
|
+
state: 'loading';
|
|
8
|
+
} | {
|
|
9
|
+
state: 'error';
|
|
10
|
+
retry: () => void;
|
|
11
|
+
} | {
|
|
12
|
+
state: 'ready';
|
|
13
|
+
options: readonly SelectOption<string>[];
|
|
14
|
+
emptyLabel?: string;
|
|
15
|
+
};
|
|
16
|
+
export type SchemaOptionsResolver = (source: SchemaOptionSource) => SchemaOptions;
|
|
17
|
+
/**
|
|
18
|
+
* Renders a config form from its JSON Schema (generated server-side by z.toJSONSchema). Objects, primitives, enums,
|
|
19
|
+
* primitive unions, primitive arrays and arrays of objects get real controls; anything else falls back to a JSON
|
|
20
|
+
* editor so no config is uneditable.
|
|
21
|
+
*/
|
|
22
|
+
export declare function SchemaForm({ schema, value, issues: rawIssues, saving, onSubmit, resolveOptions, note, submitLabel, submitWhenPristine, }: {
|
|
23
|
+
schema: JsonSchema;
|
|
24
|
+
value: Value;
|
|
25
|
+
issues: Issues;
|
|
26
|
+
saving: boolean;
|
|
27
|
+
onSubmit: (value: Value) => void;
|
|
28
|
+
resolveOptions?: SchemaOptionsResolver;
|
|
29
|
+
note?: ReactNode;
|
|
30
|
+
submitWhenPristine?: boolean;
|
|
31
|
+
submitLabel?: string;
|
|
32
|
+
}): import("react").JSX.Element;
|
|
33
|
+
export declare function ListControl({ id, itemType, value, onChange, }: {
|
|
34
|
+
id: string;
|
|
35
|
+
itemType?: string;
|
|
36
|
+
value: Value[];
|
|
37
|
+
onChange: (value: Value) => void;
|
|
38
|
+
}): import("react").JSX.Element;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Braces, Plus, RotateCcw, Trash2, X } from 'lucide-react';
|
|
3
|
+
import { AnimatePresence, motion } from 'motion/react';
|
|
4
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
5
|
+
import { softSpring } from './motion.js';
|
|
6
|
+
import { Button } from './ui/button.js';
|
|
7
|
+
import { Field, Input, Textarea } from './ui/input.js';
|
|
8
|
+
import { Select } from './ui/select.js';
|
|
9
|
+
import { Switch } from './ui/switch.js';
|
|
10
|
+
import { cn, createUuid } from './utils.js';
|
|
11
|
+
const primitives = new Set(['string', 'number', 'integer', 'boolean']);
|
|
12
|
+
/** Keys whose values the server masks; mirrors the redaction list of the backend. */
|
|
13
|
+
const secretKeys = new Set(['accessToken', 'token', 'password', 'apiToken', 'appSecret']);
|
|
14
|
+
/**
|
|
15
|
+
* The field type, with one addition: `scalar` for an anyOf of primitives (e.g. durations accepted as 30000 or
|
|
16
|
+
* "30s"), edited as text where a purely numeric entry is stored as a number.
|
|
17
|
+
*/
|
|
18
|
+
function typeOf(schema) {
|
|
19
|
+
if (Array.isArray(schema.type))
|
|
20
|
+
return schema.type.find((type) => type !== 'null');
|
|
21
|
+
if (schema.type === undefined && schema.anyOf?.every((option) => primitives.has(typeOf(option) ?? '')))
|
|
22
|
+
return 'scalar';
|
|
23
|
+
return schema.type;
|
|
24
|
+
}
|
|
25
|
+
/** Whether every field of this schema can be rendered as a form control (otherwise fall back to JSON). */
|
|
26
|
+
/** Labelled choices: the standard JSON Schema idiom `oneOf: [{ const, title }]`. */
|
|
27
|
+
function labelledChoices(schema) {
|
|
28
|
+
if (!schema.oneOf?.length || !schema.oneOf.every((option) => option.const !== undefined))
|
|
29
|
+
return undefined;
|
|
30
|
+
return schema.oneOf.map((option) => ({ value: option.const, label: option.title ?? String(option.const) }));
|
|
31
|
+
}
|
|
32
|
+
function isSupported(schema) {
|
|
33
|
+
const type = typeOf(schema);
|
|
34
|
+
if (schema.enum || schema.const !== undefined || labelledChoices(schema))
|
|
35
|
+
return true;
|
|
36
|
+
if (type === 'scalar' || primitives.has(type ?? ''))
|
|
37
|
+
return true;
|
|
38
|
+
if (type === 'array') {
|
|
39
|
+
const item = schema.items ? typeOf(schema.items) : undefined;
|
|
40
|
+
if (item === 'object')
|
|
41
|
+
return isSupported(schema.items);
|
|
42
|
+
return item === 'string' || item === 'number' || item === 'integer';
|
|
43
|
+
}
|
|
44
|
+
if (type === 'object')
|
|
45
|
+
return Object.values(schema.properties ?? {}).every(isSupported);
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
function defaultsOf(schema) {
|
|
49
|
+
if (schema.const !== undefined)
|
|
50
|
+
return schema.const;
|
|
51
|
+
if (schema.default !== undefined)
|
|
52
|
+
return schema.default;
|
|
53
|
+
if (typeOf(schema) === 'object') {
|
|
54
|
+
return Object.fromEntries(Object.entries(schema.properties ?? {}).map(([key, child]) => [key, defaultsOf(child)]));
|
|
55
|
+
}
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
function setAt(value, path, next) {
|
|
59
|
+
if (path.length === 0)
|
|
60
|
+
return next;
|
|
61
|
+
const [head, ...rest] = path;
|
|
62
|
+
if (Array.isArray(value)) {
|
|
63
|
+
const copy = [...value];
|
|
64
|
+
copy[Number(head)] = setAt(copy[Number(head)], rest, next);
|
|
65
|
+
return copy;
|
|
66
|
+
}
|
|
67
|
+
const base = value && typeof value === 'object' ? value : {};
|
|
68
|
+
return { ...base, [head]: setAt(base[head], rest, next) };
|
|
69
|
+
}
|
|
70
|
+
/** Server issue paths look like `a.b[0].c`; the form keys fields by `a.b.0.c`. */
|
|
71
|
+
function normalizeIssueKeys(issues) {
|
|
72
|
+
return Object.fromEntries(Object.entries(issues).map(([path, message]) => [path.replace(/\[(\d+)\]/g, '.$1'), message]));
|
|
73
|
+
}
|
|
74
|
+
function defaultHint(schema) {
|
|
75
|
+
const value = schema.default;
|
|
76
|
+
if (value === undefined || value === '' || typeof value === 'object')
|
|
77
|
+
return undefined;
|
|
78
|
+
return `默认 ${String(value)}`;
|
|
79
|
+
}
|
|
80
|
+
function getAt(value, path) {
|
|
81
|
+
return path.reduce((current, key) => current && typeof current === 'object' ? current[key] : undefined, value);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Renders a config form from its JSON Schema (generated server-side by z.toJSONSchema). Objects, primitives, enums,
|
|
85
|
+
* primitive unions, primitive arrays and arrays of objects get real controls; anything else falls back to a JSON
|
|
86
|
+
* editor so no config is uneditable.
|
|
87
|
+
*/
|
|
88
|
+
export function SchemaForm({ schema, value, issues: rawIssues, saving, onSubmit, resolveOptions, note = '保存后写回配置文件并重载插件', submitLabel = '保存并重载', submitWhenPristine = false, }) {
|
|
89
|
+
const issues = useMemo(() => normalizeIssueKeys(rawIssues), [rawIssues]);
|
|
90
|
+
const initialText = JSON.stringify(value ?? defaultsOf(schema));
|
|
91
|
+
const initial = useMemo(() => (initialText === undefined ? undefined : JSON.parse(initialText)), [initialText]);
|
|
92
|
+
const supported = useMemo(() => isSupported(schema), [schema]);
|
|
93
|
+
const [draft, setDraft] = useState(initial);
|
|
94
|
+
const [jsonMode, setJsonMode] = useState(!supported);
|
|
95
|
+
const [jsonText, setJsonText] = useState(() => JSON.stringify(initial, null, 2));
|
|
96
|
+
const [jsonError, setJsonError] = useState(null);
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
setDraft(initial);
|
|
99
|
+
setJsonText(JSON.stringify(initial, null, 2));
|
|
100
|
+
}, [initial]);
|
|
101
|
+
const dirty = jsonMode
|
|
102
|
+
? jsonText !== JSON.stringify(initial, null, 2)
|
|
103
|
+
: JSON.stringify(draft) !== JSON.stringify(initial);
|
|
104
|
+
const submit = () => {
|
|
105
|
+
if (!jsonMode)
|
|
106
|
+
return onSubmit(draft);
|
|
107
|
+
let value;
|
|
108
|
+
try {
|
|
109
|
+
value = JSON.parse(jsonText);
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
setJsonError('不是合法的 JSON');
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
setJsonError(null);
|
|
116
|
+
onSubmit(value);
|
|
117
|
+
};
|
|
118
|
+
return (_jsxs("div", { children: [_jsxs("div", { className: "mb-4 flex items-center justify-between", children: [_jsx("p", { className: "text-[12.5px] text-fg-3", children: note }), supported && (_jsxs(Button, { variant: "ghost", size: "sm", onClick: () => {
|
|
119
|
+
if (!jsonMode)
|
|
120
|
+
setJsonText(JSON.stringify(draft, null, 2));
|
|
121
|
+
else {
|
|
122
|
+
try {
|
|
123
|
+
setDraft(JSON.parse(jsonText));
|
|
124
|
+
setJsonError(null);
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
setJsonError('JSON 有误,无法切回表单');
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
setJsonMode(!jsonMode);
|
|
132
|
+
}, children: [_jsx(Braces, { className: "size-3.5" }), jsonMode ? '表单' : 'JSON'] }))] }), _jsx(AnimatePresence, { mode: "wait", initial: false, children: jsonMode ? (_jsxs(motion.div, { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, transition: { duration: 0.15 }, children: [_jsx(Textarea, { value: jsonText, onChange: (event) => setJsonText(event.target.value), spellCheck: false, className: "min-h-64 font-mono text-[12.5px]", "aria-invalid": jsonError !== null }), jsonError && _jsx("p", { className: "mt-1.5 text-[12px] text-danger", children: jsonError }), Object.keys(issues).length > 0 && (_jsx("ul", { className: "mt-3 space-y-1 rounded-xl bg-danger-soft px-3 py-2.5 text-[12.5px] text-danger", children: Object.entries(issues).map(([path, message]) => (_jsxs("li", { children: [_jsx("span", { className: "font-mono", children: path || '(根)' }), "\uFF1A", message] }, path))) }))] }, "json")) : (_jsx(motion.div, { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, transition: { duration: 0.15 }, className: "space-y-5", children: _jsx(SchemaFields, { schema: schema, value: draft, path: [], issues: issues, resolveOptions: resolveOptions, onChange: (path, next) => setDraft((current) => setAt(current, path, next)) }) }, "form")) }), _jsx(AnimatePresence, { children: (dirty || submitWhenPristine) && (_jsxs(motion.div, { initial: { opacity: 0, y: 12 }, animate: { opacity: 1, y: 0 }, exit: { opacity: 0, y: 12 }, transition: softSpring, className: "sticky bottom-0 mt-6 -mx-6 flex items-center justify-between gap-3 border-t border-border bg-surface/90 px-6 py-3 backdrop-blur", children: [_jsx("span", { className: "text-[12.5px] text-fg-3", children: dirty ? '有未保存的修改' : '填写完成后保存' }), _jsxs("div", { className: "flex gap-2", children: [_jsxs(Button, { variant: "ghost", size: "sm", onClick: () => {
|
|
133
|
+
setDraft(initial);
|
|
134
|
+
setJsonText(JSON.stringify(initial, null, 2));
|
|
135
|
+
setJsonError(null);
|
|
136
|
+
}, children: [_jsx(RotateCcw, { className: "size-3.5" }), "\u8FD8\u539F"] }), _jsx(Button, { variant: "primary", size: "sm", loading: saving, onClick: submit, children: submitLabel })] })] })) })] }));
|
|
137
|
+
}
|
|
138
|
+
function SchemaFields({ schema, value, path, issues, resolveOptions, onChange, }) {
|
|
139
|
+
const properties = Object.entries(schema.properties ?? {});
|
|
140
|
+
if (properties.length === 0)
|
|
141
|
+
return _jsx("p", { className: "text-[13px] text-fg-3", children: "\u8FD9\u4E2A\u63D2\u4EF6\u6CA1\u6709\u53EF\u914D\u7F6E\u9879\u3002" });
|
|
142
|
+
return (_jsx(_Fragment, { children: properties.map(([key, child]) => {
|
|
143
|
+
const childPath = [...path, key];
|
|
144
|
+
const id = `field-${childPath.join('-')}`;
|
|
145
|
+
const label = child.title ?? key;
|
|
146
|
+
const required = schema.required?.includes(key) && child.default === undefined;
|
|
147
|
+
const error = issues[childPath.join('.')];
|
|
148
|
+
const current = getAt(value, [key]);
|
|
149
|
+
const type = typeOf(child);
|
|
150
|
+
// Constants (e.g. a discriminator like type: 'forward') are filled in by defaultsOf, not edited.
|
|
151
|
+
if (child.const !== undefined)
|
|
152
|
+
return null;
|
|
153
|
+
if (type === 'array' && child.items && typeOf(child.items) === 'object') {
|
|
154
|
+
const itemSchema = child.items;
|
|
155
|
+
return (_jsx(Field, { label: label, hint: child.description, error: error, htmlFor: id, children: _jsx(ObjectListControl, { schema: itemSchema, value: Array.isArray(current) ? current : [], path: childPath, issues: issues, resolveOptions: resolveOptions, onChange: onChange }) }, key));
|
|
156
|
+
}
|
|
157
|
+
if (type === 'object' && !child.enum) {
|
|
158
|
+
return (_jsxs("fieldset", { className: "space-y-4 rounded-xl border border-border p-4", children: [_jsx("legend", { className: "px-1 text-[12.5px] font-medium text-fg-2", children: label }), _jsx(SchemaFields, { schema: child, value: current, path: childPath, issues: issues, resolveOptions: resolveOptions, onChange: onChange })] }, key));
|
|
159
|
+
}
|
|
160
|
+
if (type === 'boolean') {
|
|
161
|
+
return (_jsxs("div", { className: "flex items-start justify-between gap-4 rounded-xl border border-border px-4 py-3", children: [_jsxs("div", { children: [_jsx("label", { htmlFor: id, className: "text-[13px] font-medium text-fg", children: label }), child.description && _jsx("p", { className: "mt-0.5 text-[12px] text-fg-3", children: child.description }), error && _jsx("p", { className: "mt-0.5 text-[12px] text-danger", children: error })] }), _jsx(Switch, { "aria-label": label, checked: current === true, onCheckedChange: (checked) => onChange(childPath, checked) })] }, key));
|
|
162
|
+
}
|
|
163
|
+
const source = type === 'string' ? child['x-asabot-options'] : undefined;
|
|
164
|
+
return (_jsx(Field, { label: label, hint: child.description, error: error, required: required, htmlFor: id, children: source?.source === 'plugins' && resolveOptions ? (_jsx(DynamicSelect, { id: id, value: typeof current === 'string' && current !== '' ? current : undefined, options: resolveOptions(source), clearable: !required, invalid: Boolean(error), onChange: (next) => onChange(childPath, next) })) : (_jsx(PrimitiveControl, { id: id, schema: child, value: current, secret: secretKeys.has(key) || child.writeOnly === true, invalid: Boolean(error), onChange: (next) => onChange(childPath, next) })) }, key));
|
|
165
|
+
}) }));
|
|
166
|
+
}
|
|
167
|
+
function DynamicSelect({ id, value, options, clearable, invalid, onChange, }) {
|
|
168
|
+
const ready = options.state === 'ready';
|
|
169
|
+
const choices = ready ? options.options : [];
|
|
170
|
+
const selected = value !== undefined && !choices.some((item) => item.value === value);
|
|
171
|
+
return (_jsxs(_Fragment, { children: [_jsx(Select, { id: id, className: "w-full", "aria-invalid": invalid, value: value, disabled: !ready || (!choices.length && !(clearable && value !== undefined)), placeholder: options.state === 'loading'
|
|
172
|
+
? '正在加载插件…'
|
|
173
|
+
: options.state === 'error'
|
|
174
|
+
? '无法加载插件'
|
|
175
|
+
: choices.length
|
|
176
|
+
? '选择插件'
|
|
177
|
+
: '没有匹配的插件', options: [
|
|
178
|
+
...(clearable && ready ? [{ value: '', label: options.emptyLabel ?? '不选择' }] : []),
|
|
179
|
+
...(selected ? [{ value, label: ready ? `${value}(不可用)` : value, disabled: true }] : []),
|
|
180
|
+
...choices,
|
|
181
|
+
], onValueChange: (next) => onChange(next === '' ? undefined : next) }), options.state === 'error' && (_jsxs("div", { className: "mt-1 flex items-center gap-2 text-[12px] text-fg-3", role: "status", children: ["\u65E0\u6CD5\u52A0\u8F7D\u63D2\u4EF6\u9009\u9879", _jsx(Button, { size: "sm", variant: "ghost", onClick: options.retry, children: "\u91CD\u8BD5" })] }))] }));
|
|
182
|
+
}
|
|
183
|
+
function PrimitiveControl({ id, schema, value, secret = false, invalid, onChange, }) {
|
|
184
|
+
const type = typeOf(schema);
|
|
185
|
+
if (type === 'scalar') {
|
|
186
|
+
const numeric = schema.anyOf?.some((option) => typeOf(option) === 'number' || typeOf(option) === 'integer');
|
|
187
|
+
return (_jsx(Input, { id: id, value: value === undefined ? '' : String(value), placeholder: defaultHint(schema), "aria-invalid": invalid, onChange: (event) => {
|
|
188
|
+
const text = event.target.value.trim();
|
|
189
|
+
onChange(text === '' ? undefined : numeric && /^-?\d+(?:\.\d+)?$/.test(text) ? Number(text) : text);
|
|
190
|
+
}, className: "font-mono" }));
|
|
191
|
+
}
|
|
192
|
+
const choices = labelledChoices(schema);
|
|
193
|
+
if (choices) {
|
|
194
|
+
return (_jsx(Select, { id: id, "aria-invalid": invalid, className: "w-full", value: value === undefined ? undefined : String(value), onValueChange: (next) => onChange(choices.find((option) => String(option.value) === next)?.value), options: choices.map((option) => ({ value: String(option.value), label: option.label })) }));
|
|
195
|
+
}
|
|
196
|
+
if (schema.enum) {
|
|
197
|
+
return (_jsx(Select, { id: id, "aria-invalid": invalid, className: "w-full", value: value === undefined ? undefined : String(value), onValueChange: (next) => onChange(schema.enum?.find((option) => String(option) === next)), options: schema.enum.map((option) => ({ value: String(option), label: String(option) })) }));
|
|
198
|
+
}
|
|
199
|
+
if (type === 'number' || type === 'integer') {
|
|
200
|
+
return (_jsx(Input, { id: id, type: "number", inputMode: type === 'integer' ? 'numeric' : 'decimal', step: type === 'integer' ? 1 : 'any', min: schema.minimum, max: schema.maximum, value: typeof value === 'number' ? value : '', placeholder: defaultHint(schema), "aria-invalid": invalid, onChange: (event) => onChange(event.target.value === '' ? undefined : Number(event.target.value)), className: "tabular" }));
|
|
201
|
+
}
|
|
202
|
+
if (type === 'array')
|
|
203
|
+
return (_jsx(ListControl, { id: id, itemType: schema.items ? typeOf(schema.items) : 'string', value: Array.isArray(value) ? value : [], onChange: onChange }));
|
|
204
|
+
const text = typeof value === 'string' ? value : '';
|
|
205
|
+
// `${VAR}` references are not secrets themselves; literal secrets come back masked and are replaced wholesale.
|
|
206
|
+
const masked = secret && !text.startsWith('${');
|
|
207
|
+
return (_jsx(Input, { id: id, type: masked ? 'password' : 'text', autoComplete: secret ? 'off' : undefined, value: text, placeholder: defaultHint(schema), "aria-invalid": invalid, onFocus: secret ? (event) => event.target.select() : undefined, onChange: (event) => onChange(event.target.value), className: cn(secret && 'font-mono') }));
|
|
208
|
+
}
|
|
209
|
+
function ObjectListControl({ schema, value, path, issues, resolveOptions, onChange, }) {
|
|
210
|
+
// Items have no identity of their own; a parallel list of keys keeps animations and inputs stable on removal.
|
|
211
|
+
const [keys, setKeys] = useState(() => value.map(createUuid));
|
|
212
|
+
const ids = value.map((_, index) => keys[index] ?? `item-${index}`);
|
|
213
|
+
return (_jsxs("div", { className: "space-y-2.5", children: [_jsx(AnimatePresence, { initial: false, children: value.map((item, index) => (_jsxs(motion.div, { layout: true, initial: { opacity: 0, y: -6 }, animate: { opacity: 1, y: 0 }, exit: { opacity: 0, scale: 0.97 }, transition: softSpring, className: "rounded-xl border border-border bg-surface-2/40 p-4", children: [_jsxs("div", { className: "mb-3 flex items-center justify-between", children: [_jsxs("span", { className: "text-[12px] font-medium text-fg-3 tabular", children: ["#", index + 1] }), _jsx(Button, { variant: "ghost", size: "icon-sm", "aria-label": `删除第 ${index + 1} 项`, onClick: () => {
|
|
214
|
+
setKeys(ids.filter((_, i) => i !== index));
|
|
215
|
+
onChange(path, value.filter((_, i) => i !== index));
|
|
216
|
+
}, children: _jsx(Trash2, { className: "size-3.5" }) })] }), _jsx("div", { className: "space-y-4", children: _jsx(SchemaFields, { schema: schema, value: item, path: [...path, String(index)], issues: issues, resolveOptions: resolveOptions, onChange: onChange }) })] }, ids[index]))) }), _jsxs(Button, { variant: "secondary", size: "sm", onClick: () => {
|
|
217
|
+
setKeys([...ids, createUuid()]);
|
|
218
|
+
onChange(path, [...value, defaultsOf(schema)]);
|
|
219
|
+
}, children: [_jsx(Plus, { className: "size-3.5" }), "\u6DFB\u52A0\u4E00\u9879"] })] }));
|
|
220
|
+
}
|
|
221
|
+
export function ListControl({ id, itemType, value, onChange, }) {
|
|
222
|
+
const [input, setInput] = useState('');
|
|
223
|
+
const numeric = itemType === 'number' || itemType === 'integer';
|
|
224
|
+
const add = () => {
|
|
225
|
+
const text = input.trim();
|
|
226
|
+
if (!text)
|
|
227
|
+
return;
|
|
228
|
+
const item = numeric ? Number(text) : text;
|
|
229
|
+
if (numeric && Number.isNaN(item))
|
|
230
|
+
return;
|
|
231
|
+
// Values are kept unique, so each chip can be keyed by its value.
|
|
232
|
+
if (!value.includes(item))
|
|
233
|
+
onChange([...value, item]);
|
|
234
|
+
setInput('');
|
|
235
|
+
};
|
|
236
|
+
return (_jsx("div", { className: "rounded-[10px] border border-border bg-surface p-1.5 transition-colors focus-within:border-accent focus-within:shadow-[0_0_0_3px_var(--ring)]", children: _jsxs("div", { className: "flex flex-wrap gap-1.5", children: [_jsx(AnimatePresence, { initial: false, children: value.map((item, index) => (_jsxs(motion.span, { layout: true, initial: { opacity: 0, scale: 0.85 }, animate: { opacity: 1, scale: 1 }, exit: { opacity: 0, scale: 0.85 }, transition: softSpring, className: "inline-flex h-7 items-center gap-1 rounded-lg bg-surface-2 pr-1 pl-2.5 font-mono text-[12.5px] text-fg", children: [String(item), _jsx("button", { type: "button", "aria-label": `移除 ${String(item)}`, onClick: () => onChange(value.filter((_, i) => i !== index)), className: "flex size-5 cursor-pointer items-center justify-center rounded-md text-fg-3 hover:bg-surface-3 hover:text-fg", children: _jsx(X, { className: "size-3" }) })] }, String(item)))) }), _jsxs("div", { className: "flex min-w-32 flex-1 items-center", children: [_jsx("input", { id: id, value: input, inputMode: numeric ? 'numeric' : undefined, placeholder: value.length === 0 ? '输入后按回车添加' : '', onChange: (event) => setInput(event.target.value), onKeyDown: (event) => {
|
|
237
|
+
if (event.key === 'Enter') {
|
|
238
|
+
event.preventDefault();
|
|
239
|
+
add();
|
|
240
|
+
}
|
|
241
|
+
else if (event.key === 'Backspace' && !input && value.length > 0)
|
|
242
|
+
onChange(value.slice(0, -1));
|
|
243
|
+
}, className: "h-7 flex-1 bg-transparent px-1.5 text-[13px] outline-none placeholder:text-fg-3" }), _jsx("button", { type: "button", "aria-label": "\u6DFB\u52A0", onClick: add, className: cn('flex size-7 cursor-pointer items-center justify-center rounded-md text-fg-3 hover:bg-surface-2 hover:text-fg', !input && 'invisible'), children: _jsx(Plus, { className: "size-3.5" }) })] })] }) }));
|
|
244
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import type { Segment } from './types.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Renders the neutral message model (DESIGN §5, §24.1). `renderReply` lets a caller show the quoted message;
|
|
5
|
+
* without it a reply segment shows as a small chip.
|
|
6
|
+
*/
|
|
7
|
+
export declare function Segments({ message, renderReply, }: {
|
|
8
|
+
message: Segment[];
|
|
9
|
+
renderReply?: (id: string) => ReactNode;
|
|
10
|
+
}): import("react").JSX.Element;
|
package/dist/segments.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Paperclip, Reply, Share2 } from 'lucide-react';
|
|
3
|
+
import { lazy, Suspense } from 'react';
|
|
4
|
+
import { cn } from './utils.js';
|
|
5
|
+
const Markdown = lazy(() => import('./markdown.js').then((module) => ({ default: module.Markdown })));
|
|
6
|
+
const styleClasses = {
|
|
7
|
+
bold: 'font-semibold',
|
|
8
|
+
italic: 'italic',
|
|
9
|
+
underline: 'underline',
|
|
10
|
+
strike: 'line-through',
|
|
11
|
+
code: 'rounded bg-surface-3/70 px-1 font-mono text-[0.92em]',
|
|
12
|
+
spoiler: 'rounded bg-fg-3/60 text-transparent transition-colors hover:bg-transparent hover:text-inherit',
|
|
13
|
+
};
|
|
14
|
+
function Placeholder({ children, icon }) {
|
|
15
|
+
return (_jsxs("span", { className: "mx-0.5 inline-flex items-center gap-1 rounded-md bg-surface-3/60 px-1.5 text-[0.92em] text-fg-2", children: [icon, children] }));
|
|
16
|
+
}
|
|
17
|
+
/** Image sources the panel may load: remote http(s) and inline base64 (history truncates base64, so those show a placeholder). */
|
|
18
|
+
function imageSource(segment) {
|
|
19
|
+
const source = String(segment.data.url ?? segment.data.file ?? '');
|
|
20
|
+
if (/^https?:\/\//i.test(source))
|
|
21
|
+
return source;
|
|
22
|
+
if (source.startsWith('base64://') && !/\[\d+ bytes\]$/.test(source))
|
|
23
|
+
return `data:image/png;base64,${source.slice('base64://'.length)}`;
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Renders the neutral message model (DESIGN §5, §24.1). `renderReply` lets a caller show the quoted message;
|
|
28
|
+
* without it a reply segment shows as a small chip.
|
|
29
|
+
*/
|
|
30
|
+
export function Segments({ message, renderReply, }) {
|
|
31
|
+
return (_jsx(_Fragment, { children: message.map((segment, index) => {
|
|
32
|
+
const key = `${segment.type}-${index}`;
|
|
33
|
+
const data = segment.data;
|
|
34
|
+
switch (segment.type) {
|
|
35
|
+
case 'text': {
|
|
36
|
+
const style = Array.isArray(data.style) ? data.style : [];
|
|
37
|
+
return (_jsx("span", { className: cn(style.map((item) => styleClasses[item])), children: String(data.text) }, key));
|
|
38
|
+
}
|
|
39
|
+
case 'markdown':
|
|
40
|
+
return (_jsx(Suspense, { fallback: _jsx("span", { className: "whitespace-pre-wrap", children: String(data.content) }), children: _jsx(Markdown, { className: "markdown-compact", children: String(data.content) }) }, key));
|
|
41
|
+
case 'button': {
|
|
42
|
+
const label = String(data.label);
|
|
43
|
+
const value = String(data.value);
|
|
44
|
+
return data.kind === 'link' && /^https?:\/\//i.test(value) ? (_jsx("a", { href: value, target: "_blank", rel: "noopener noreferrer", className: "mx-0.5 my-0.5 inline-flex rounded-lg border border-border bg-surface px-2.5 py-0.5 text-[0.92em] font-medium text-accent hover:border-border-strong", children: label }, key)) : (_jsx("span", { title: value, className: "mx-0.5 my-0.5 inline-flex rounded-lg border border-border bg-surface px-2.5 py-0.5 text-[0.92em] font-medium text-fg", children: label }, key));
|
|
45
|
+
}
|
|
46
|
+
case 'at':
|
|
47
|
+
return (_jsxs("span", { className: "mx-0.5 rounded bg-accent-soft px-1 text-accent-soft-fg", children: ["@", data.id === 'all' ? '全体成员' : String(data.id)] }, key));
|
|
48
|
+
case 'image': {
|
|
49
|
+
const src = imageSource(segment);
|
|
50
|
+
return src ? (_jsx("img", { src: src, alt: String(data.summary ?? '图片'), referrerPolicy: "no-referrer", className: "my-1 block max-h-60 max-w-full rounded-lg" }, key)) : (_jsx(Placeholder, { children: "\u56FE\u7247" }, key));
|
|
51
|
+
}
|
|
52
|
+
case 'face':
|
|
53
|
+
return _jsx(Placeholder, { children: "\u8868\u60C5" }, key);
|
|
54
|
+
case 'audio':
|
|
55
|
+
return _jsx(Placeholder, { children: "\u8BED\u97F3" }, key);
|
|
56
|
+
case 'video':
|
|
57
|
+
return _jsx(Placeholder, { children: "\u89C6\u9891" }, key);
|
|
58
|
+
case 'file':
|
|
59
|
+
return (_jsx(Placeholder, { icon: _jsx(Paperclip, { className: "size-3" }), children: String(data.name ?? '文件') }, key));
|
|
60
|
+
case 'forward':
|
|
61
|
+
return (_jsx(Placeholder, { icon: _jsx(Share2, { className: "size-3" }), children: "\u5408\u5E76\u8F6C\u53D1" }, key));
|
|
62
|
+
case 'reply': {
|
|
63
|
+
const quote = Array.isArray(data.message)
|
|
64
|
+
? data.message
|
|
65
|
+
.map((item) => {
|
|
66
|
+
if (item.type === 'text')
|
|
67
|
+
return String(item.data.text);
|
|
68
|
+
if (item.type === 'file')
|
|
69
|
+
return String(item.data.name ?? '[文件]');
|
|
70
|
+
return { image: '[图片]', audio: '[语音]', video: '[视频]' }[item.type] ?? '';
|
|
71
|
+
})
|
|
72
|
+
.join('')
|
|
73
|
+
: '';
|
|
74
|
+
const preview = quote || (typeof data.title === 'string' ? data.title : '');
|
|
75
|
+
return (_jsx("span", { className: "mb-1 block", children: renderReply ? (renderReply(String(data.id))) : (_jsx(Placeholder, { icon: _jsx(Reply, { className: "size-3 shrink-0" }), children: _jsx("span", { className: "line-clamp-2 break-all", children: preview || '回复' }) })) }, key));
|
|
76
|
+
}
|
|
77
|
+
default:
|
|
78
|
+
return _jsx(Placeholder, { children: segment.type }, key);
|
|
79
|
+
}
|
|
80
|
+
}) }));
|
|
81
|
+
}
|