dishui 0.0.49 → 0.0.50
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/dist/components/pro/Flow/Flow.js +419 -407
- package/dist/components/pro/Flow/Flow.js.map +1 -1
- package/dist/components/pro/Flow/archify/build.d.ts +74 -0
- package/dist/components/pro/Flow/archify/build.js +103 -0
- package/dist/components/pro/Flow/archify/build.js.map +1 -0
- package/dist/components/pro/Flow/archify/convert.d.ts +14 -0
- package/dist/components/pro/Flow/archify/convert.js +534 -0
- package/dist/components/pro/Flow/archify/convert.js.map +1 -0
- package/dist/components/pro/Flow/archify/index.d.ts +12 -0
- package/dist/components/pro/Flow/archify/palette.d.ts +64 -0
- package/dist/components/pro/Flow/archify/palette.js +112 -0
- package/dist/components/pro/Flow/archify/palette.js.map +1 -0
- package/dist/components/pro/Flow/archify/presets.d.ts +26 -0
- package/dist/components/pro/Flow/archify/presets.js +43 -0
- package/dist/components/pro/Flow/archify/presets.js.map +1 -0
- package/dist/components/pro/Flow/archify/spec.d.ts +283 -0
- package/dist/components/pro/Flow/archify/spec.js +10 -0
- package/dist/components/pro/Flow/archify/spec.js.map +1 -0
- package/dist/components/pro/Flow/constants.js +14 -0
- package/dist/components/pro/Flow/constants.js.map +1 -1
- package/dist/components/pro/Flow/hooks/useClipboard.d.ts +5 -0
- package/dist/components/pro/Flow/hooks/useClipboard.js +129 -73
- package/dist/components/pro/Flow/hooks/useClipboard.js.map +1 -1
- package/dist/components/pro/Flow/hooks/useFlowImportExport.d.ts +1 -0
- package/dist/components/pro/Flow/hooks/useFlowImportExport.js +108 -93
- package/dist/components/pro/Flow/hooks/useFlowImportExport.js.map +1 -1
- package/dist/components/pro/Flow/hooks/useKeyboardShortcuts.d.ts +1 -0
- package/dist/components/pro/Flow/hooks/useKeyboardShortcuts.js +7 -7
- package/dist/components/pro/Flow/hooks/useKeyboardShortcuts.js.map +1 -1
- package/dist/components/pro/Flow/index.d.ts +2 -0
- package/dist/components/pro/Flow/nodes/DataNodeView.d.ts +4 -1
- package/dist/components/pro/Flow/nodes/DataNodeView.js +127 -115
- package/dist/components/pro/Flow/nodes/DataNodeView.js.map +1 -1
- package/dist/components/pro/Flow/nodes/MediaContent.js +72 -67
- package/dist/components/pro/Flow/nodes/MediaContent.js.map +1 -1
- package/dist/components/pro/Flow/nodes/NodeRenderer.d.ts +5 -0
- package/dist/components/pro/Flow/nodes/NodeRenderer.js +216 -115
- package/dist/components/pro/Flow/nodes/NodeRenderer.js.map +1 -1
- package/dist/components/pro/Flow/panels/FlowToolbar.js +208 -169
- package/dist/components/pro/Flow/panels/FlowToolbar.js.map +1 -1
- package/dist/components/pro/Flow/panels/InspectorPanel.js +602 -369
- package/dist/components/pro/Flow/panels/InspectorPanel.js.map +1 -1
- package/dist/components/pro/Flow/panels/ShapePalette.js +50 -39
- package/dist/components/pro/Flow/panels/ShapePalette.js.map +1 -1
- package/dist/components/pro/Flow/panels/toolbarIcons.d.ts +1 -0
- package/dist/components/pro/Flow/panels/toolbarIcons.js +36 -8
- package/dist/components/pro/Flow/panels/toolbarIcons.js.map +1 -1
- package/dist/components/pro/Flow/types.d.ts +30 -0
- package/dist/components/pro/Flow/types.js.map +1 -1
- package/dist/dishui.css +1 -1
- package/dist/flow.js +73 -56
- package/package.json +18 -17
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { resolveThemeColor as
|
|
1
|
+
import R from "../../../Markdown/Markdown.js";
|
|
2
|
+
import { resolveThemeColor as D, resolveThemeColorCss as v } from "../utils/themeColor.js";
|
|
3
3
|
import { streamAIChat as T } from "./aiClient.js";
|
|
4
4
|
import { Model3DView as $ } from "./Model3DView.js";
|
|
5
|
-
import H, { useEffect as
|
|
5
|
+
import H, { useEffect as C, useMemo as V, useRef as N, useState as f } from "react";
|
|
6
6
|
import { jsx as t, jsxs as b } from "react/jsx-runtime";
|
|
7
|
-
import
|
|
7
|
+
import A from "mermaid";
|
|
8
8
|
import "katex/dist/katex.min.css";
|
|
9
9
|
import K from "katex";
|
|
10
|
-
var L = H.lazy(() => import("./DataNodeView.js").then((e) => ({ default: e.DataNodeView }))),
|
|
10
|
+
var L = H.lazy(() => import("./DataNodeView.js").then((e) => ({ default: e.DataNodeView }))), z = !1;
|
|
11
11
|
function _() {
|
|
12
|
-
|
|
12
|
+
z || (A.initialize({
|
|
13
13
|
startOnLoad: !1,
|
|
14
14
|
theme: "default",
|
|
15
15
|
securityLevel: "loose",
|
|
16
16
|
fontFamily: "inherit"
|
|
17
|
-
}),
|
|
17
|
+
}), z = !0);
|
|
18
18
|
}
|
|
19
19
|
function P({ content: e, color: r }) {
|
|
20
|
-
const [s,
|
|
21
|
-
return
|
|
20
|
+
const [s, o] = f(""), [a, i] = f(null), u = N(`flow-mermaid-${Math.random().toString(36).slice(2)}`);
|
|
21
|
+
return C(() => {
|
|
22
22
|
let m = !1;
|
|
23
23
|
_();
|
|
24
24
|
const c = e.trim();
|
|
25
25
|
if (!c) {
|
|
26
|
-
|
|
26
|
+
o(""), i(null);
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
|
-
return
|
|
30
|
-
m || (
|
|
29
|
+
return A.render(u.current, c).then(({ svg: d }) => {
|
|
30
|
+
m || (o(d), i(null));
|
|
31
31
|
}).catch((d) => {
|
|
32
32
|
m || i(d?.message ?? "Mermaid error");
|
|
33
33
|
}), () => {
|
|
34
34
|
m = !0;
|
|
35
35
|
};
|
|
36
|
-
}, [e]),
|
|
36
|
+
}, [e]), a ? /* @__PURE__ */ t("div", {
|
|
37
37
|
className: "flow-media-error",
|
|
38
|
-
children:
|
|
38
|
+
children: a
|
|
39
39
|
}) : /* @__PURE__ */ t("div", {
|
|
40
40
|
className: "flow-media-mermaid",
|
|
41
41
|
style: { color: r },
|
|
@@ -43,14 +43,14 @@ function P({ content: e, color: r }) {
|
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
function j({ content: e, color: r, fontSize: s }) {
|
|
46
|
-
const
|
|
46
|
+
const o = V(() => {
|
|
47
47
|
try {
|
|
48
48
|
return K.renderToString(e.trim() || "\\;", {
|
|
49
49
|
displayMode: !0,
|
|
50
50
|
throwOnError: !1
|
|
51
51
|
});
|
|
52
|
-
} catch (
|
|
53
|
-
return `<span class="flow-media-error">${
|
|
52
|
+
} catch (a) {
|
|
53
|
+
return `<span class="flow-media-error">${a?.message ?? "KaTeX error"}</span>`;
|
|
54
54
|
}
|
|
55
55
|
}, [e]);
|
|
56
56
|
return /* @__PURE__ */ t("div", {
|
|
@@ -59,16 +59,16 @@ function j({ content: e, color: r, fontSize: s }) {
|
|
|
59
59
|
color: r,
|
|
60
60
|
fontSize: s
|
|
61
61
|
},
|
|
62
|
-
dangerouslySetInnerHTML: { __html:
|
|
62
|
+
dangerouslySetInnerHTML: { __html: o }
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
|
-
function F({ content: e, interactive: r, color: s, fontSize:
|
|
66
|
-
const
|
|
65
|
+
function F({ content: e, interactive: r, color: s, fontSize: o }) {
|
|
66
|
+
const a = V(() => `<!doctype html><html><head><meta charset="utf-8"><style>
|
|
67
67
|
:root { color-scheme: light dark; }
|
|
68
68
|
html, body { margin: 0; background: transparent; }
|
|
69
69
|
body {
|
|
70
70
|
color: ${s ?? "#111827"};
|
|
71
|
-
font-size: ${
|
|
71
|
+
font-size: ${o ?? 13}px;
|
|
72
72
|
font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
|
|
73
73
|
line-height: 1.5;
|
|
74
74
|
padding: 0;
|
|
@@ -77,14 +77,14 @@ function F({ content: e, interactive: r, color: s, fontSize: a }) {
|
|
|
77
77
|
</style></head><body>${e}</body></html>`, [
|
|
78
78
|
e,
|
|
79
79
|
s,
|
|
80
|
-
|
|
80
|
+
o
|
|
81
81
|
]);
|
|
82
82
|
return /* @__PURE__ */ t("iframe", {
|
|
83
83
|
title: "html-media",
|
|
84
84
|
className: "flow-media-iframe",
|
|
85
85
|
style: { pointerEvents: r ? "auto" : "none" },
|
|
86
86
|
sandbox: "allow-scripts allow-same-origin allow-popups allow-forms",
|
|
87
|
-
srcDoc:
|
|
87
|
+
srcDoc: a
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
90
|
function O({ content: e }) {
|
|
@@ -100,48 +100,48 @@ function O({ content: e }) {
|
|
|
100
100
|
children: "输入图片链接,或直接粘贴图片"
|
|
101
101
|
});
|
|
102
102
|
}
|
|
103
|
-
function q({ node: e, config: r, interactive: s, color:
|
|
104
|
-
const [
|
|
105
|
-
|
|
103
|
+
function q({ node: e, config: r, interactive: s, color: o }) {
|
|
104
|
+
const [a, i] = f([]), [u, m] = f(""), [c, d] = f(!1), [M, S] = f(null), p = N(null), y = N(null);
|
|
105
|
+
C(() => {
|
|
106
106
|
y.current?.scrollTo({ top: y.current.scrollHeight });
|
|
107
|
-
}, [
|
|
108
|
-
const
|
|
107
|
+
}, [a, c]), C(() => () => p.current?.abort(), []);
|
|
108
|
+
const k = !!r?.gateway && !!r?.model && !c, x = async () => {
|
|
109
109
|
const l = u.trim();
|
|
110
110
|
if (!l || !r?.gateway) return;
|
|
111
|
-
|
|
112
|
-
const
|
|
111
|
+
S(null);
|
|
112
|
+
const w = [...a.filter((n) => !(n.role === "assistant" && n.content.trim() === "")), {
|
|
113
113
|
role: "user",
|
|
114
114
|
content: l
|
|
115
115
|
}];
|
|
116
|
-
i(
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
let
|
|
116
|
+
i(w), m(""), d(!0);
|
|
117
|
+
const E = new AbortController();
|
|
118
|
+
p.current = E;
|
|
119
|
+
let I = "";
|
|
120
120
|
i((n) => [...n, {
|
|
121
121
|
role: "assistant",
|
|
122
122
|
content: ""
|
|
123
123
|
}]);
|
|
124
124
|
try {
|
|
125
|
-
for await (const n of T(r,
|
|
126
|
-
|
|
125
|
+
for await (const n of T(r, w, E.signal))
|
|
126
|
+
I += n, i((h) => {
|
|
127
127
|
const g = h.slice();
|
|
128
128
|
return g[g.length - 1] = {
|
|
129
129
|
role: "assistant",
|
|
130
|
-
content:
|
|
130
|
+
content: I
|
|
131
131
|
}, g;
|
|
132
132
|
});
|
|
133
133
|
} catch (n) {
|
|
134
|
-
n?.name !== "AbortError" &&
|
|
134
|
+
n?.name !== "AbortError" && S(n?.message ?? "Request failed");
|
|
135
135
|
} finally {
|
|
136
136
|
i((n) => {
|
|
137
137
|
const h = n[n.length - 1];
|
|
138
138
|
return h && h.role === "assistant" && h.content.trim() === "" ? n.slice(0, -1) : n;
|
|
139
|
-
}), d(!1),
|
|
139
|
+
}), d(!1), p.current = null;
|
|
140
140
|
}
|
|
141
141
|
};
|
|
142
142
|
return /* @__PURE__ */ b("div", {
|
|
143
143
|
className: "flow-media-ai",
|
|
144
|
-
style: { color:
|
|
144
|
+
style: { color: o },
|
|
145
145
|
children: [
|
|
146
146
|
/* @__PURE__ */ t("div", {
|
|
147
147
|
className: "flow-media-ai-header",
|
|
@@ -151,21 +151,21 @@ function q({ node: e, config: r, interactive: s, color: a }) {
|
|
|
151
151
|
className: "flow-media-ai-log",
|
|
152
152
|
ref: y,
|
|
153
153
|
children: [
|
|
154
|
-
|
|
154
|
+
a.length === 0 && /* @__PURE__ */ t("div", {
|
|
155
155
|
className: "flow-media-ai-empty",
|
|
156
156
|
children: r?.gateway ? "开始对话…" : "请在属性面板配置 AI 接口"
|
|
157
157
|
}),
|
|
158
|
-
|
|
158
|
+
a.map((l, w) => /* @__PURE__ */ t("div", {
|
|
159
159
|
className: `flow-media-ai-msg flow-media-ai-msg--${l.role}`,
|
|
160
|
-
children: l.role === "assistant" ? /* @__PURE__ */ t(
|
|
160
|
+
children: l.role === "assistant" ? /* @__PURE__ */ t(R, {
|
|
161
161
|
content: l.content || "…",
|
|
162
162
|
enableMermaid: !1,
|
|
163
163
|
enableMarkmap: !1
|
|
164
164
|
}) : /* @__PURE__ */ t("span", { children: l.content })
|
|
165
|
-
},
|
|
166
|
-
|
|
165
|
+
}, w)),
|
|
166
|
+
M && /* @__PURE__ */ t("div", {
|
|
167
167
|
className: "flow-media-error",
|
|
168
|
-
children:
|
|
168
|
+
children: M
|
|
169
169
|
})
|
|
170
170
|
]
|
|
171
171
|
}),
|
|
@@ -177,17 +177,17 @@ function q({ node: e, config: r, interactive: s, color: a }) {
|
|
|
177
177
|
placeholder: "输入消息,Enter 发送",
|
|
178
178
|
onChange: (l) => m(l.target.value),
|
|
179
179
|
onKeyDown: (l) => {
|
|
180
|
-
l.key === "Enter" && !l.shiftKey && (l.preventDefault(),
|
|
180
|
+
l.key === "Enter" && !l.shiftKey && (l.preventDefault(), k && x());
|
|
181
181
|
},
|
|
182
182
|
onPointerDown: (l) => l.stopPropagation()
|
|
183
183
|
}), c ? /* @__PURE__ */ t("button", {
|
|
184
184
|
type: "button",
|
|
185
|
-
onClick: () =>
|
|
185
|
+
onClick: () => p.current?.abort(),
|
|
186
186
|
children: "停止"
|
|
187
187
|
}) : /* @__PURE__ */ t("button", {
|
|
188
188
|
type: "button",
|
|
189
|
-
disabled: !
|
|
190
|
-
onClick:
|
|
189
|
+
disabled: !k || !u.trim(),
|
|
190
|
+
onClick: x,
|
|
191
191
|
children: "发送"
|
|
192
192
|
})]
|
|
193
193
|
})
|
|
@@ -195,40 +195,40 @@ function q({ node: e, config: r, interactive: s, color: a }) {
|
|
|
195
195
|
});
|
|
196
196
|
}
|
|
197
197
|
function ee({ node: e, interactive: r }) {
|
|
198
|
-
const s = e.data.mediaKind ?? "markdown",
|
|
198
|
+
const s = e.data.mediaKind ?? "markdown", o = e.data.mediaContent ?? "", a = v(e.data.labelColor ?? e.data.color, "#111827");
|
|
199
199
|
switch (s) {
|
|
200
200
|
case "markdown":
|
|
201
201
|
return /* @__PURE__ */ t("div", {
|
|
202
202
|
className: "flow-media-markdown",
|
|
203
203
|
style: {
|
|
204
|
-
color:
|
|
204
|
+
color: a,
|
|
205
205
|
fontSize: e.data.fontSize
|
|
206
206
|
},
|
|
207
|
-
children: /* @__PURE__ */ t(
|
|
207
|
+
children: /* @__PURE__ */ t(R, { content: o })
|
|
208
208
|
});
|
|
209
209
|
case "html":
|
|
210
210
|
return /* @__PURE__ */ t(F, {
|
|
211
|
-
content:
|
|
211
|
+
content: o,
|
|
212
212
|
interactive: r,
|
|
213
|
-
color:
|
|
213
|
+
color: D(e.data.labelColor ?? e.data.color, "#111827"),
|
|
214
214
|
fontSize: e.data.fontSize
|
|
215
215
|
});
|
|
216
216
|
case "mermaid":
|
|
217
217
|
return /* @__PURE__ */ t(P, {
|
|
218
|
-
content:
|
|
219
|
-
color:
|
|
218
|
+
content: o,
|
|
219
|
+
color: a
|
|
220
220
|
});
|
|
221
221
|
case "math":
|
|
222
222
|
return /* @__PURE__ */ t(j, {
|
|
223
|
-
content:
|
|
224
|
-
color:
|
|
223
|
+
content: o,
|
|
224
|
+
color: a,
|
|
225
225
|
fontSize: e.data.fontSize
|
|
226
226
|
});
|
|
227
227
|
case "image":
|
|
228
|
-
return /* @__PURE__ */ t(O, { content:
|
|
228
|
+
return /* @__PURE__ */ t(O, { content: o });
|
|
229
229
|
case "model3d":
|
|
230
230
|
return /* @__PURE__ */ t($, {
|
|
231
|
-
content:
|
|
231
|
+
content: o,
|
|
232
232
|
format: e.data.modelFormat ?? "stl",
|
|
233
233
|
interactive: r
|
|
234
234
|
});
|
|
@@ -237,17 +237,22 @@ function ee({ node: e, interactive: r }) {
|
|
|
237
237
|
node: e,
|
|
238
238
|
config: e.data.aiConfig,
|
|
239
239
|
interactive: r,
|
|
240
|
-
color:
|
|
240
|
+
color: a
|
|
241
241
|
});
|
|
242
242
|
case "data":
|
|
243
243
|
return /* @__PURE__ */ t("div", {
|
|
244
244
|
className: "flow-media-data",
|
|
245
245
|
style: { pointerEvents: r ? "auto" : "none" },
|
|
246
|
-
children: /* @__PURE__ */ t(L, {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
246
|
+
children: /* @__PURE__ */ t(L, {
|
|
247
|
+
config: e.data.dataConfig ?? {
|
|
248
|
+
columns: [],
|
|
249
|
+
rows: [],
|
|
250
|
+
view: "table"
|
|
251
|
+
},
|
|
252
|
+
surfaceColor: e.data.fill === "transparent" ? void 0 : v(e.data.fill, ""),
|
|
253
|
+
textColor: a,
|
|
254
|
+
primaryColor: v(e.data.color, "")
|
|
255
|
+
})
|
|
251
256
|
});
|
|
252
257
|
default:
|
|
253
258
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MediaContent.js","names":[],"sources":["../../../../../src/components/pro/Flow/nodes/MediaContent.tsx"],"sourcesContent":["import React, { useEffect, useMemo, useRef, useState } from 'react';\nimport katex from 'katex';\nimport mermaid from 'mermaid';\nimport Markdown from '../../../Markdown';\nimport type { FlowNode, FlowAIConfig } from '../types';\nimport { streamAIChat, type AIChatMessage } from './aiClient';\nimport { resolveThemeColorCss, resolveThemeColor } from '../utils/themeColor';\nimport 'katex/dist/katex.min.css';\nimport { Model3DView } from './Model3DView';\n\n// Data-node view pulls in DataTable + Chart; lazy-load so it only enters the\n// bundle when a data node actually renders.\nconst DataNodeView = React.lazy(() =>\n import('./DataNodeView').then((m) => ({ default: m.DataNodeView })),\n);\n\nlet mermaidReady = false;\nfunction ensureMermaid() {\n if (mermaidReady) return;\n mermaid.initialize({ startOnLoad: false, theme: 'default', securityLevel: 'loose', fontFamily: 'inherit' });\n mermaidReady = true;\n}\n\n/** Renders a Mermaid diagram from source into an inline SVG. */\nfunction MermaidView({ content, color }: { content: string; color?: string }) {\n const [svg, setSvg] = useState('');\n const [error, setError] = useState<string | null>(null);\n const idRef = useRef(`flow-mermaid-${Math.random().toString(36).slice(2)}`);\n\n useEffect(() => {\n let cancelled = false;\n ensureMermaid();\n const src = content.trim();\n if (!src) { setSvg(''); setError(null); return; }\n mermaid\n .render(idRef.current, src)\n .then(({ svg }) => { if (!cancelled) { setSvg(svg); setError(null); } })\n .catch((e) => { if (!cancelled) setError(e?.message ?? 'Mermaid error'); });\n return () => { cancelled = true; };\n }, [content]);\n\n if (error) return <div className=\"flow-media-error\">{error}</div>;\n return <div className=\"flow-media-mermaid\" style={{ color }} dangerouslySetInnerHTML={{ __html: svg }} />;\n}\n\n/** Renders a LaTeX formula (display mode) via KaTeX. */\nfunction MathView({ content, color, fontSize }: { content: string; color?: string; fontSize?: number }) {\n const html = useMemo(() => {\n try {\n return katex.renderToString(content.trim() || '\\\\;', { displayMode: true, throwOnError: false });\n } catch (e: any) {\n return `<span class=\"flow-media-error\">${e?.message ?? 'KaTeX error'}</span>`;\n }\n }, [content]);\n return <div className=\"flow-media-math\" style={{ color, fontSize }} dangerouslySetInnerHTML={{ __html: html }} />;\n}\n\n/** Renders raw HTML in a sandboxed iframe (isolated from the host document).\n * A base stylesheet is injected so the fragment inherits the node's themed\n * text color / font size and a transparent background, keeping it readable on\n * any theme without the author having to set colors. */\nfunction HtmlView({ content, interactive, color, fontSize }: { content: string; interactive: boolean; color?: string; fontSize?: number }) {\n const srcDoc = useMemo(() => {\n const base = `<!doctype html><html><head><meta charset=\"utf-8\"><style>\n :root { color-scheme: light dark; }\n html, body { margin: 0; background: transparent; }\n body {\n color: ${color ?? '#111827'};\n font-size: ${fontSize ?? 13}px;\n font-family: system-ui, -apple-system, \"Segoe UI\", Roboto, sans-serif;\n line-height: 1.5;\n padding: 0;\n }\n a { color: inherit; }\n </style></head><body>${content}</body></html>`;\n return base;\n }, [content, color, fontSize]);\n return (\n <iframe\n title=\"html-media\"\n className=\"flow-media-iframe\"\n style={{ pointerEvents: interactive ? 'auto' : 'none' }}\n sandbox=\"allow-scripts allow-same-origin allow-popups allow-forms\"\n srcDoc={srcDoc}\n />\n );\n}\n\nfunction ImageView({ content }: { content: string }) {\n const src = content.trim();\n if (!src) {\n return <div className=\"flow-media-image-empty\">输入图片链接,或直接粘贴图片</div>;\n }\n return (\n <img\n className=\"flow-media-image\"\n src={src}\n alt=\"\"\n draggable={false}\n referrerPolicy=\"no-referrer\"\n />\n );\n}\n\n/** Interactive AI chat backed by an OpenAI/Anthropic-compatible endpoint. */\nfunction AIView({ node, config, interactive, color }: { node: FlowNode; config?: FlowAIConfig; interactive: boolean; color?: string }) {\n const [messages, setMessages] = useState<AIChatMessage[]>([]);\n const [input, setInput] = useState('');\n const [streaming, setStreaming] = useState(false);\n const [error, setError] = useState<string | null>(null);\n const abortRef = useRef<AbortController | null>(null);\n const scrollRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n scrollRef.current?.scrollTo({ top: scrollRef.current.scrollHeight });\n }, [messages, streaming]);\n\n useEffect(() => () => abortRef.current?.abort(), []);\n\n const canSend = !!config?.gateway && !!config?.model && !streaming;\n\n const send = async () => {\n const text = input.trim();\n if (!text || !config?.gateway) return;\n setError(null);\n // Only keep non-empty assistant messages in history; an aborted/errored\n // request can leave an empty assistant placeholder behind, which the API\n // then rejects (\"assistant message must not be empty\").\n const history = messages.filter(\n (m) => !(m.role === 'assistant' && m.content.trim() === ''),\n );\n const next: AIChatMessage[] = [...history, { role: 'user', content: text }];\n setMessages(next);\n setInput('');\n setStreaming(true);\n const ac = new AbortController();\n abortRef.current = ac;\n let acc = '';\n setMessages((m) => [...m, { role: 'assistant', content: '' }]);\n try {\n for await (const delta of streamAIChat(config, next, ac.signal)) {\n acc += delta;\n setMessages((m) => {\n const copy = m.slice();\n copy[copy.length - 1] = { role: 'assistant', content: acc };\n return copy;\n });\n }\n } catch (e: any) {\n if (e?.name !== 'AbortError') setError(e?.message ?? 'Request failed');\n } finally {\n // Drop the trailing assistant placeholder if nothing streamed in.\n setMessages((m) => {\n const last = m[m.length - 1];\n if (last && last.role === 'assistant' && last.content.trim() === '') {\n return m.slice(0, -1);\n }\n return m;\n });\n setStreaming(false);\n abortRef.current = null;\n }\n };\n\n return (\n <div className=\"flow-media-ai\" style={{ color }}>\n <div className=\"flow-media-ai-header\">\n {config?.model ? `AI · ${config.model}` : (node.data.label || 'AI')}\n </div>\n <div className=\"flow-media-ai-log\" ref={scrollRef}>\n {messages.length === 0 && (\n <div className=\"flow-media-ai-empty\">\n {config?.gateway ? '开始对话…' : '请在属性面板配置 AI 接口'}\n </div>\n )}\n {messages.map((m, i) => (\n <div key={i} className={`flow-media-ai-msg flow-media-ai-msg--${m.role}`}>\n {m.role === 'assistant'\n ? <Markdown content={m.content || '…'} enableMermaid={false} enableMarkmap={false} />\n : <span>{m.content}</span>}\n </div>\n ))}\n {error && <div className=\"flow-media-error\">{error}</div>}\n </div>\n <div className=\"flow-media-ai-input\" style={{ pointerEvents: interactive ? 'auto' : 'none' }}>\n <textarea\n value={input}\n placeholder=\"输入消息,Enter 发送\"\n onChange={(e) => setInput(e.target.value)}\n onKeyDown={(e) => {\n if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); if (canSend) send(); }\n }}\n onPointerDown={(e) => e.stopPropagation()}\n />\n {streaming ? (\n <button type=\"button\" onClick={() => abortRef.current?.abort()}>停止</button>\n ) : (\n <button type=\"button\" disabled={!canSend || !input.trim()} onClick={send}>发送</button>\n )}\n </div>\n </div>\n );\n}\n\n/** Dispatches to the correct renderer for the node's media kind. */\nexport function MediaContent({ node, interactive }: { node: FlowNode; interactive: boolean }) {\n const kind = node.data.mediaKind ?? 'markdown';\n const content = node.data.mediaContent ?? '';\n const textColor = resolveThemeColorCss(node.data.labelColor ?? node.data.color, '#111827');\n\n switch (kind) {\n case 'markdown':\n return (\n <div className=\"flow-media-markdown\" style={{ color: textColor, fontSize: node.data.fontSize }}>\n <Markdown content={content} />\n </div>\n );\n case 'html':\n // The iframe is an isolated document with no access to the parent's CSS\n // variables, so pass a concrete resolved color instead of a var().\n return (\n <HtmlView\n content={content}\n interactive={interactive}\n color={resolveThemeColor(node.data.labelColor ?? node.data.color, '#111827')}\n fontSize={node.data.fontSize}\n />\n );\n case 'mermaid':\n return <MermaidView content={content} color={textColor} />;\n case 'math':\n return <MathView content={content} color={textColor} fontSize={node.data.fontSize} />;\n case 'image':\n return <ImageView content={content} />;\n case 'model3d':\n return (\n <Model3DView\n content={content}\n format={node.data.modelFormat ?? 'stl'}\n interactive={interactive}\n />\n );\n case 'ai':\n return <AIView node={node} config={node.data.aiConfig} interactive={interactive} color={textColor} />;\n case 'data':\n return (\n <div className=\"flow-media-data\" style={{ pointerEvents: interactive ? 'auto' : 'none' }}>\n <DataNodeView config={node.data.dataConfig ?? { columns: [], rows: [], view: 'table' }} />\n </div>\n );\n default:\n return null;\n }\n}\n"],"mappings":";;;;;;;;;AAYA,IAAM,IAAe,EAAM,KAAA,MACzB,OAAO,mBAAA,EAAkB,KAAA,CAAM,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,CACpE,GAEI,IAAe;AACnB,SAAS,IAAgB;AACvB,EAAI,MACJ,EAAQ,WAAW;AAAA,IAAE,aAAa;AAAA,IAAO,OAAO;AAAA,IAAW,eAAe;AAAA,IAAS,YAAY;AAAA,EAAU,CAAC,GAC1G,IAAe;AACjB;AAGA,SAAS,EAAY,EAAE,SAAA,GAAS,OAAA,EAAA,GAA8C;AAC5E,QAAM,CAAC,GAAK,CAAA,IAAU,EAAS,EAAE,GAC3B,CAAC,GAAO,CAAA,IAAY,EAAwB,IAAI,GAChD,IAAQ,EAAO,gBAAgB,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,CAAC,CAAA,EAAG;AAc1E,SAZA,EAAA,MAAgB;AACd,QAAI,IAAY;AAChB,IAAA,EAAc;AACd,UAAM,IAAM,EAAQ,KAAK;AACzB,QAAI,CAAC,GAAK;AAAE,MAAA,EAAO,EAAE,GAAG,EAAS,IAAI;AAAG;AAAA,IAAQ;AAChD,WAAA,EACG,OAAO,EAAM,SAAS,CAAG,EACzB,KAAA,CAAM,EAAE,KAAA,EAAA,MAAU;AAAE,MAAK,MAAa,EAAO,CAAG,GAAG,EAAS,IAAI;AAAA,IAAK,CAAC,EACtE,MAAA,CAAO,MAAM;AAAE,MAAK,KAAW,EAAS,GAAG,WAAW,eAAe;AAAA,IAAG,CAAC,GAC5E,MAAa;AAAE,MAAA,IAAY;AAAA,IAAM;AAAA,EACnC,GAAG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c,QAAQ,EAAK,KAAK,cAAc;AAAA,UAAE,SAAS,CAAC;AAAA,UAAG,MAAM,CAAC;AAAA,UAAG,MAAM;AAAA,QAAQ,EAAI,CAAA;AAAA,MACtF,CAAA;AAAA,IAET;AACE,aAAO;AAAA,EACX;AACF"}
|
|
1
|
+
{"version":3,"file":"MediaContent.js","names":[],"sources":["../../../../../src/components/pro/Flow/nodes/MediaContent.tsx"],"sourcesContent":["import React, { useEffect, useMemo, useRef, useState } from 'react';\nimport katex from 'katex';\nimport mermaid from 'mermaid';\nimport Markdown from '../../../Markdown';\nimport type { FlowNode, FlowAIConfig } from '../types';\nimport { streamAIChat, type AIChatMessage } from './aiClient';\nimport { resolveThemeColorCss, resolveThemeColor } from '../utils/themeColor';\nimport 'katex/dist/katex.min.css';\nimport { Model3DView } from './Model3DView';\n\n// Data-node view pulls in DataTable + Chart; lazy-load so it only enters the\n// bundle when a data node actually renders.\nconst DataNodeView = React.lazy(() =>\n import('./DataNodeView').then((m) => ({ default: m.DataNodeView })),\n);\n\nlet mermaidReady = false;\nfunction ensureMermaid() {\n if (mermaidReady) return;\n mermaid.initialize({ startOnLoad: false, theme: 'default', securityLevel: 'loose', fontFamily: 'inherit' });\n mermaidReady = true;\n}\n\n/** Renders a Mermaid diagram from source into an inline SVG. */\nfunction MermaidView({ content, color }: { content: string; color?: string }) {\n const [svg, setSvg] = useState('');\n const [error, setError] = useState<string | null>(null);\n const idRef = useRef(`flow-mermaid-${Math.random().toString(36).slice(2)}`);\n\n useEffect(() => {\n let cancelled = false;\n ensureMermaid();\n const src = content.trim();\n if (!src) { setSvg(''); setError(null); return; }\n mermaid\n .render(idRef.current, src)\n .then(({ svg }) => { if (!cancelled) { setSvg(svg); setError(null); } })\n .catch((e) => { if (!cancelled) setError(e?.message ?? 'Mermaid error'); });\n return () => { cancelled = true; };\n }, [content]);\n\n if (error) return <div className=\"flow-media-error\">{error}</div>;\n return <div className=\"flow-media-mermaid\" style={{ color }} dangerouslySetInnerHTML={{ __html: svg }} />;\n}\n\n/** Renders a LaTeX formula (display mode) via KaTeX. */\nfunction MathView({ content, color, fontSize }: { content: string; color?: string; fontSize?: number }) {\n const html = useMemo(() => {\n try {\n return katex.renderToString(content.trim() || '\\\\;', { displayMode: true, throwOnError: false });\n } catch (e: any) {\n return `<span class=\"flow-media-error\">${e?.message ?? 'KaTeX error'}</span>`;\n }\n }, [content]);\n return <div className=\"flow-media-math\" style={{ color, fontSize }} dangerouslySetInnerHTML={{ __html: html }} />;\n}\n\n/** Renders raw HTML in a sandboxed iframe (isolated from the host document).\n * A base stylesheet is injected so the fragment inherits the node's themed\n * text color / font size and a transparent background, keeping it readable on\n * any theme without the author having to set colors. */\nfunction HtmlView({ content, interactive, color, fontSize }: { content: string; interactive: boolean; color?: string; fontSize?: number }) {\n const srcDoc = useMemo(() => {\n const base = `<!doctype html><html><head><meta charset=\"utf-8\"><style>\n :root { color-scheme: light dark; }\n html, body { margin: 0; background: transparent; }\n body {\n color: ${color ?? '#111827'};\n font-size: ${fontSize ?? 13}px;\n font-family: system-ui, -apple-system, \"Segoe UI\", Roboto, sans-serif;\n line-height: 1.5;\n padding: 0;\n }\n a { color: inherit; }\n </style></head><body>${content}</body></html>`;\n return base;\n }, [content, color, fontSize]);\n return (\n <iframe\n title=\"html-media\"\n className=\"flow-media-iframe\"\n style={{ pointerEvents: interactive ? 'auto' : 'none' }}\n sandbox=\"allow-scripts allow-same-origin allow-popups allow-forms\"\n srcDoc={srcDoc}\n />\n );\n}\n\nfunction ImageView({ content }: { content: string }) {\n const src = content.trim();\n if (!src) {\n return <div className=\"flow-media-image-empty\">输入图片链接,或直接粘贴图片</div>;\n }\n return (\n <img\n className=\"flow-media-image\"\n src={src}\n alt=\"\"\n draggable={false}\n referrerPolicy=\"no-referrer\"\n />\n );\n}\n\n/** Interactive AI chat backed by an OpenAI/Anthropic-compatible endpoint. */\nfunction AIView({ node, config, interactive, color }: { node: FlowNode; config?: FlowAIConfig; interactive: boolean; color?: string }) {\n const [messages, setMessages] = useState<AIChatMessage[]>([]);\n const [input, setInput] = useState('');\n const [streaming, setStreaming] = useState(false);\n const [error, setError] = useState<string | null>(null);\n const abortRef = useRef<AbortController | null>(null);\n const scrollRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n scrollRef.current?.scrollTo({ top: scrollRef.current.scrollHeight });\n }, [messages, streaming]);\n\n useEffect(() => () => abortRef.current?.abort(), []);\n\n const canSend = !!config?.gateway && !!config?.model && !streaming;\n\n const send = async () => {\n const text = input.trim();\n if (!text || !config?.gateway) return;\n setError(null);\n // Only keep non-empty assistant messages in history; an aborted/errored\n // request can leave an empty assistant placeholder behind, which the API\n // then rejects (\"assistant message must not be empty\").\n const history = messages.filter(\n (m) => !(m.role === 'assistant' && m.content.trim() === ''),\n );\n const next: AIChatMessage[] = [...history, { role: 'user', content: text }];\n setMessages(next);\n setInput('');\n setStreaming(true);\n const ac = new AbortController();\n abortRef.current = ac;\n let acc = '';\n setMessages((m) => [...m, { role: 'assistant', content: '' }]);\n try {\n for await (const delta of streamAIChat(config, next, ac.signal)) {\n acc += delta;\n setMessages((m) => {\n const copy = m.slice();\n copy[copy.length - 1] = { role: 'assistant', content: acc };\n return copy;\n });\n }\n } catch (e: any) {\n if (e?.name !== 'AbortError') setError(e?.message ?? 'Request failed');\n } finally {\n // Drop the trailing assistant placeholder if nothing streamed in.\n setMessages((m) => {\n const last = m[m.length - 1];\n if (last && last.role === 'assistant' && last.content.trim() === '') {\n return m.slice(0, -1);\n }\n return m;\n });\n setStreaming(false);\n abortRef.current = null;\n }\n };\n\n return (\n <div className=\"flow-media-ai\" style={{ color }}>\n <div className=\"flow-media-ai-header\">\n {config?.model ? `AI · ${config.model}` : (node.data.label || 'AI')}\n </div>\n <div className=\"flow-media-ai-log\" ref={scrollRef}>\n {messages.length === 0 && (\n <div className=\"flow-media-ai-empty\">\n {config?.gateway ? '开始对话…' : '请在属性面板配置 AI 接口'}\n </div>\n )}\n {messages.map((m, i) => (\n <div key={i} className={`flow-media-ai-msg flow-media-ai-msg--${m.role}`}>\n {m.role === 'assistant'\n ? <Markdown content={m.content || '…'} enableMermaid={false} enableMarkmap={false} />\n : <span>{m.content}</span>}\n </div>\n ))}\n {error && <div className=\"flow-media-error\">{error}</div>}\n </div>\n <div className=\"flow-media-ai-input\" style={{ pointerEvents: interactive ? 'auto' : 'none' }}>\n <textarea\n value={input}\n placeholder=\"输入消息,Enter 发送\"\n onChange={(e) => setInput(e.target.value)}\n onKeyDown={(e) => {\n if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); if (canSend) send(); }\n }}\n onPointerDown={(e) => e.stopPropagation()}\n />\n {streaming ? (\n <button type=\"button\" onClick={() => abortRef.current?.abort()}>停止</button>\n ) : (\n <button type=\"button\" disabled={!canSend || !input.trim()} onClick={send}>发送</button>\n )}\n </div>\n </div>\n );\n}\n\n/** Dispatches to the correct renderer for the node's media kind. */\nexport function MediaContent({ node, interactive }: { node: FlowNode; interactive: boolean }) {\n const kind = node.data.mediaKind ?? 'markdown';\n const content = node.data.mediaContent ?? '';\n const textColor = resolveThemeColorCss(node.data.labelColor ?? node.data.color, '#111827');\n\n switch (kind) {\n case 'markdown':\n return (\n <div className=\"flow-media-markdown\" style={{ color: textColor, fontSize: node.data.fontSize }}>\n <Markdown content={content} />\n </div>\n );\n case 'html':\n // The iframe is an isolated document with no access to the parent's CSS\n // variables, so pass a concrete resolved color instead of a var().\n return (\n <HtmlView\n content={content}\n interactive={interactive}\n color={resolveThemeColor(node.data.labelColor ?? node.data.color, '#111827')}\n fontSize={node.data.fontSize}\n />\n );\n case 'mermaid':\n return <MermaidView content={content} color={textColor} />;\n case 'math':\n return <MathView content={content} color={textColor} fontSize={node.data.fontSize} />;\n case 'image':\n return <ImageView content={content} />;\n case 'model3d':\n return (\n <Model3DView\n content={content}\n format={node.data.modelFormat ?? 'stl'}\n interactive={interactive}\n />\n );\n case 'ai':\n return <AIView node={node} config={node.data.aiConfig} interactive={interactive} color={textColor} />;\n case 'data':\n return (\n <div className=\"flow-media-data\" style={{ pointerEvents: interactive ? 'auto' : 'none' }}>\n <DataNodeView\n config={node.data.dataConfig ?? { columns: [], rows: [], view: 'table' }}\n surfaceColor={node.data.fill === 'transparent' ? undefined : resolveThemeColorCss(node.data.fill, '')}\n textColor={textColor}\n primaryColor={resolveThemeColorCss(node.data.color, '')}\n />\n </div>\n );\n default:\n return null;\n }\n}\n"],"mappings":";;;;;;;;;AAYA,IAAM,IAAe,EAAM,KAAA,MACzB,OAAO,mBAAA,EAAkB,KAAA,CAAM,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,CACpE,GAEI,IAAe;AACnB,SAAS,IAAgB;AACvB,EAAI,MACJ,EAAQ,WAAW;AAAA,IAAE,aAAa;AAAA,IAAO,OAAO;AAAA,IAAW,eAAe;AAAA,IAAS,YAAY;AAAA,EAAU,CAAC,GAC1G,IAAe;AACjB;AAGA,SAAS,EAAY,EAAE,SAAA,GAAS,OAAA,EAAA,GAA8C;AAC5E,QAAM,CAAC,GAAK,CAAA,IAAU,EAAS,EAAE,GAC3B,CAAC,GAAO,CAAA,IAAY,EAAwB,IAAI,GAChD,IAAQ,EAAO,gBAAgB,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,CAAC,CAAA,EAAG;AAc1E,SAZA,EAAA,MAAgB;AACd,QAAI,IAAY;AAChB,IAAA,EAAc;AACd,UAAM,IAAM,EAAQ,KAAK;AACzB,QAAI,CAAC,GAAK;AAAE,MAAA,EAAO,EAAE,GAAG,EAAS,IAAI;AAAG;AAAA,IAAQ;AAChD,WAAA,EACG,OAAO,EAAM,SAAS,CAAG,EACzB,KAAA,CAAM,EAAE,KAAA,EAAA,MAAU;AAAE,MAAK,MAAa,EAAO,CAAG,GAAG,EAAS,IAAI;AAAA,IAAK,CAAC,EACtE,MAAA,CAAO,MAAM;AAAE,MAAK,KAAW,EAAS,GAAG,WAAW,eAAe;AAAA,IAAG,CAAC,GAC5E,MAAa;AAAE,MAAA,IA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A,kBACrF,gBAAA,EAAC,GAAD;AAAA,UACE,QAAQ,EAAK,KAAK,cAAc;AAAA,YAAE,SAAS,CAAC;AAAA,YAAG,MAAM,CAAC;AAAA,YAAG,MAAM;AAAA,UAAQ;AAAA,UACvE,cAAc,EAAK,KAAK,SAAS,gBAAgB,SAAY,EAAqB,EAAK,KAAK,MAAM,EAAE;AAAA,UACzF,WAAA;AAAA,UACX,cAAc,EAAqB,EAAK,KAAK,OAAO,EAAE;AAAA,QACvD,CAAA;AAAA,MACE,CAAA;AAAA,IAET;AACE,aAAO;AAAA,EACX;AACF"}
|
|
@@ -8,6 +8,11 @@ export interface NodeContainer {
|
|
|
8
8
|
svgTransform: Container;
|
|
9
9
|
icon: Sprite;
|
|
10
10
|
text: Text;
|
|
11
|
+
/** Optional muted second line (Archify card sublabel). */
|
|
12
|
+
subtext: Text;
|
|
13
|
+
/** Optional top-right pill background + label (Archify card tag). */
|
|
14
|
+
tagBg: Graphics;
|
|
15
|
+
tagText: Text;
|
|
11
16
|
/** Sequence badge shown on `animAnchor` nodes. */
|
|
12
17
|
animBadge: Text;
|
|
13
18
|
handles: Graphics;
|