dishui 0.0.46 → 0.0.48
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/chart.js +35 -33
- package/dist/components/Chart/index.d.ts +1 -1
- package/dist/components/pro/CodeEditor/editors/MarkdownEditor.js +1 -2
- package/dist/components/pro/CodeEditor/editors/MarkdownEditor.js.map +1 -1
- package/dist/components/pro/CodeEditor/themes.js +0 -25
- package/dist/components/pro/CodeEditor/themes.js.map +1 -1
- package/dist/components/pro/CodeEditor/types.d.ts +1 -1
- package/dist/components/pro/DataTable/pivotExtension.d.ts +6 -0
- package/dist/components/pro/DataTable/pivotExtension.js +31 -30
- package/dist/components/pro/DataTable/pivotExtension.js.map +1 -1
- package/dist/components/pro/Flow/Flow.js +500 -459
- package/dist/components/pro/Flow/Flow.js.map +1 -1
- package/dist/components/pro/Flow/FlowCanvas.js +526 -524
- package/dist/components/pro/Flow/FlowCanvas.js.map +1 -1
- package/dist/components/pro/Flow/canvas/GridRenderer.d.ts +3 -0
- package/dist/components/pro/Flow/canvas/GridRenderer.js +28 -23
- package/dist/components/pro/Flow/canvas/GridRenderer.js.map +1 -1
- package/dist/components/pro/Flow/canvas/MiniMapRenderer.js +18 -17
- package/dist/components/pro/Flow/canvas/MiniMapRenderer.js.map +1 -1
- package/dist/components/pro/Flow/canvas/PixiApp.d.ts +24 -0
- package/dist/components/pro/Flow/canvas/PixiApp.js +60 -15
- package/dist/components/pro/Flow/canvas/PixiApp.js.map +1 -1
- package/dist/components/pro/Flow/constants.js +7 -7
- package/dist/components/pro/Flow/constants.js.map +1 -1
- package/dist/components/pro/Flow/context/FlowAIContext.d.ts +15 -0
- package/dist/components/pro/Flow/context/FlowAIContext.js +32 -0
- package/dist/components/pro/Flow/context/FlowAIContext.js.map +1 -0
- package/dist/components/pro/Flow/context/FlowUIContext.d.ts +4 -1
- package/dist/components/pro/Flow/context/FlowUIContext.js +58 -55
- package/dist/components/pro/Flow/context/FlowUIContext.js.map +1 -1
- package/dist/components/pro/Flow/edges/EdgeRenderer.js +22 -21
- package/dist/components/pro/Flow/edges/EdgeRenderer.js.map +1 -1
- package/dist/components/pro/Flow/hooks/useFlowImportExport.d.ts +6 -0
- package/dist/components/pro/Flow/hooks/useFlowImportExport.js +146 -89
- package/dist/components/pro/Flow/hooks/useFlowImportExport.js.map +1 -1
- package/dist/components/pro/Flow/hooks/useLayoutActions.d.ts +2 -0
- package/dist/components/pro/Flow/hooks/useLayoutActions.js +94 -65
- package/dist/components/pro/Flow/hooks/useLayoutActions.js.map +1 -1
- package/dist/components/pro/Flow/hooks/usePdfExport.d.ts +10 -0
- package/dist/components/pro/Flow/hooks/usePdfExport.js +60 -0
- package/dist/components/pro/Flow/hooks/usePdfExport.js.map +1 -0
- package/dist/components/pro/Flow/hooks/usePixiApp.d.ts +6 -1
- package/dist/components/pro/Flow/hooks/usePixiApp.js +49 -30
- package/dist/components/pro/Flow/hooks/usePixiApp.js.map +1 -1
- package/dist/components/pro/Flow/index.d.ts +5 -2
- package/dist/components/pro/Flow/lines/FreehandTool.js +21 -20
- package/dist/components/pro/Flow/lines/FreehandTool.js.map +1 -1
- package/dist/components/pro/Flow/lines/GeometricLineTool.js +22 -18
- package/dist/components/pro/Flow/lines/GeometricLineTool.js.map +1 -1
- package/dist/components/pro/Flow/lines/LineRenderer.js +19 -18
- package/dist/components/pro/Flow/lines/LineRenderer.js.map +1 -1
- package/dist/components/pro/Flow/nodes/DataNodeView.d.ts +7 -0
- package/dist/components/pro/Flow/nodes/DataNodeView.js +217 -0
- package/dist/components/pro/Flow/nodes/DataNodeView.js.map +1 -0
- package/dist/components/pro/Flow/nodes/MediaContent.js +149 -120
- package/dist/components/pro/Flow/nodes/MediaContent.js.map +1 -1
- package/dist/components/pro/Flow/nodes/MediaOverlay.js +22 -17
- package/dist/components/pro/Flow/nodes/MediaOverlay.js.map +1 -1
- package/dist/components/pro/Flow/nodes/NodeRenderer.js +77 -76
- package/dist/components/pro/Flow/nodes/NodeRenderer.js.map +1 -1
- package/dist/components/pro/Flow/nodes/aiClient.d.ts +22 -0
- package/dist/components/pro/Flow/nodes/aiClient.js +107 -54
- package/dist/components/pro/Flow/nodes/aiClient.js.map +1 -1
- package/dist/components/pro/Flow/nodes/dataUtils.d.ts +52 -0
- package/dist/components/pro/Flow/nodes/dataUtils.js +270 -0
- package/dist/components/pro/Flow/nodes/dataUtils.js.map +1 -0
- package/dist/components/pro/Flow/nodes/svgIcons.js +59 -27
- package/dist/components/pro/Flow/nodes/svgIcons.js.map +1 -1
- package/dist/components/pro/Flow/panels/AIPanel.d.ts +2 -0
- package/dist/components/pro/Flow/panels/AIPanel.js +498 -0
- package/dist/components/pro/Flow/panels/AIPanel.js.map +1 -0
- package/dist/components/pro/Flow/panels/DataInspectorSection.d.ts +11 -0
- package/dist/components/pro/Flow/panels/DataInspectorSection.js +436 -0
- package/dist/components/pro/Flow/panels/DataInspectorSection.js.map +1 -0
- package/dist/components/pro/Flow/panels/ExpandableTextarea.d.ts +16 -0
- package/dist/components/pro/Flow/panels/ExpandableTextarea.js +65 -0
- package/dist/components/pro/Flow/panels/ExpandableTextarea.js.map +1 -0
- package/dist/components/pro/Flow/panels/FlowPanelGroup.js +51 -39
- package/dist/components/pro/Flow/panels/FlowPanelGroup.js.map +1 -1
- package/dist/components/pro/Flow/panels/FlowToolbar.d.ts +5 -1
- package/dist/components/pro/Flow/panels/FlowToolbar.js +310 -233
- package/dist/components/pro/Flow/panels/FlowToolbar.js.map +1 -1
- package/dist/components/pro/Flow/panels/InspectorPanel.js +358 -363
- package/dist/components/pro/Flow/panels/InspectorPanel.js.map +1 -1
- package/dist/components/pro/Flow/panels/OutlinePanel.js +63 -62
- package/dist/components/pro/Flow/panels/OutlinePanel.js.map +1 -1
- package/dist/components/pro/Flow/panels/ProjectTitle.d.ts +8 -0
- package/dist/components/pro/Flow/panels/ProjectTitle.js +49 -0
- package/dist/components/pro/Flow/panels/ProjectTitle.js.map +1 -0
- package/dist/components/pro/Flow/panels/ShapePalette.js +128 -115
- package/dist/components/pro/Flow/panels/ShapePalette.js.map +1 -1
- package/dist/components/pro/Flow/panels/toolbarIcons.d.ts +13 -0
- package/dist/components/pro/Flow/panels/toolbarIcons.js +241 -87
- package/dist/components/pro/Flow/panels/toolbarIcons.js.map +1 -1
- package/dist/components/pro/Flow/types.d.ts +77 -1
- package/dist/components/pro/Flow/types.js.map +1 -1
- package/dist/components/pro/Flow/utils/pdfExport.d.ts +20 -0
- package/dist/components/pro/Flow/utils/pdfExport.js +95 -0
- package/dist/components/pro/Flow/utils/pdfExport.js.map +1 -0
- package/dist/components/pro/Flow/utils/themeColor.d.ts +86 -0
- package/dist/components/pro/Flow/utils/themeColor.js +190 -0
- package/dist/components/pro/Flow/utils/themeColor.js.map +1 -0
- package/dist/contexts/AppContext.d.ts +1 -1
- package/dist/contexts/AppContext.js +28 -29
- package/dist/contexts/AppContext.js.map +1 -1
- package/dist/dishui.css +1 -1
- package/dist/favicon.svg +10 -0
- package/dist/flow.js +59 -51
- package/dist/index-nostyled.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/styles/themeStyles.js +6 -11
- package/dist/styles/themeStyles.js.map +1 -1
- package/dist/utils/themes.js +3 -23
- package/dist/utils/themes.js.map +1 -1
- package/package.json +17 -18
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { usePivotExtension as y } from "../../DataTable/pivotExtension.js";
|
|
2
|
+
import k, { createColumn as F } from "../../../../data-table.js";
|
|
3
|
+
import A from "../../../Chart/Chart.js";
|
|
4
|
+
import { areaY as C, barX as R, barY as T, defineChart as u, dot as M, lineY as N } from "../../../../chart.js";
|
|
5
|
+
import { DATA_CHART_PALETTE as w, labelFor as v } from "./dataUtils.js";
|
|
6
|
+
import { useLayoutEffect as P, useMemo as b, useRef as S, useState as z } from "react";
|
|
7
|
+
import { jsx as c } from "react/jsx-runtime";
|
|
8
|
+
import { scaleBand as g } from "@tanstack/charts/scales/band";
|
|
9
|
+
import { scaleLinear as m } from "@tanstack/charts/scales/linear";
|
|
10
|
+
import { scalePoint as x } from "@tanstack/charts/scales/point";
|
|
11
|
+
import { pie as D, polar as E, radialArc as V } from "@tanstack/charts/polar";
|
|
12
|
+
function B({ config: e }) {
|
|
13
|
+
const l = b(() => e.columns.map((n) => F(n.key, n.label ?? n.key, { enableSorting: !0 })), [e.columns]), i = b(() => e.columns.map((n) => ({
|
|
14
|
+
field: n.key,
|
|
15
|
+
label: n.label ?? n.key,
|
|
16
|
+
numeric: n.type === "number"
|
|
17
|
+
})), [e.columns]), t = e.pivot, s = JSON.stringify({
|
|
18
|
+
e: !!t?.enabled,
|
|
19
|
+
r: t?.rowFields ?? [],
|
|
20
|
+
c: t?.colFields ?? [],
|
|
21
|
+
v: t?.values ?? []
|
|
22
|
+
});
|
|
23
|
+
return /* @__PURE__ */ c("div", {
|
|
24
|
+
className: "flow-data-table",
|
|
25
|
+
children: /* @__PURE__ */ c(L, {
|
|
26
|
+
config: e,
|
|
27
|
+
columns: l,
|
|
28
|
+
pivotFields: i
|
|
29
|
+
}, s)
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function L({ config: e, columns: l, pivotFields: i }) {
|
|
33
|
+
const t = e.pivot, s = y({
|
|
34
|
+
fields: i,
|
|
35
|
+
initialActive: !!t?.enabled,
|
|
36
|
+
initialRowFields: t?.rowFields ?? [],
|
|
37
|
+
initialColFields: t?.colFields ?? [],
|
|
38
|
+
initialValues: t?.values ?? [],
|
|
39
|
+
panelPlacement: t?.panelPlacement ?? "top",
|
|
40
|
+
lang: "zh",
|
|
41
|
+
hideModeToggle: !0
|
|
42
|
+
});
|
|
43
|
+
return /* @__PURE__ */ c(k, {
|
|
44
|
+
data: e.rows,
|
|
45
|
+
columns: l,
|
|
46
|
+
enableSorting: !0,
|
|
47
|
+
enablePagination: e.rows.length > 50,
|
|
48
|
+
pageSize: 50,
|
|
49
|
+
extensions: [s]
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function O(e) {
|
|
53
|
+
return b(() => {
|
|
54
|
+
const l = e.chart;
|
|
55
|
+
if (!l) return null;
|
|
56
|
+
const i = l.xField, t = (l.yFields ?? []).filter(Boolean);
|
|
57
|
+
if (!i || t.length === 0) return null;
|
|
58
|
+
const s = e.rows, n = (r, a) => l.seriesColors?.[r] ?? w[a % w.length];
|
|
59
|
+
switch (l.type) {
|
|
60
|
+
case "line":
|
|
61
|
+
return u({
|
|
62
|
+
x: { scale: () => x().padding(0.35) },
|
|
63
|
+
y: {
|
|
64
|
+
scale: m,
|
|
65
|
+
nice: !0,
|
|
66
|
+
grid: !0
|
|
67
|
+
},
|
|
68
|
+
marks: t.map((r, a) => N(s, {
|
|
69
|
+
id: r,
|
|
70
|
+
x: i,
|
|
71
|
+
y: r,
|
|
72
|
+
stroke: n(r, a),
|
|
73
|
+
points: !0
|
|
74
|
+
}))
|
|
75
|
+
});
|
|
76
|
+
case "area":
|
|
77
|
+
return u({
|
|
78
|
+
x: { scale: () => x().padding(0.35) },
|
|
79
|
+
y: {
|
|
80
|
+
scale: m,
|
|
81
|
+
nice: !0,
|
|
82
|
+
grid: !0
|
|
83
|
+
},
|
|
84
|
+
marks: t.map((r, a) => C(s, {
|
|
85
|
+
id: r,
|
|
86
|
+
x: i,
|
|
87
|
+
y: r,
|
|
88
|
+
fill: n(r, a),
|
|
89
|
+
fillOpacity: 0.35,
|
|
90
|
+
stroke: n(r, a)
|
|
91
|
+
}))
|
|
92
|
+
});
|
|
93
|
+
case "scatter":
|
|
94
|
+
return u({
|
|
95
|
+
x: {
|
|
96
|
+
scale: m,
|
|
97
|
+
nice: !0,
|
|
98
|
+
grid: !0
|
|
99
|
+
},
|
|
100
|
+
y: {
|
|
101
|
+
scale: m,
|
|
102
|
+
nice: !0,
|
|
103
|
+
grid: !0
|
|
104
|
+
},
|
|
105
|
+
marks: [M(s, {
|
|
106
|
+
id: "points",
|
|
107
|
+
x: i,
|
|
108
|
+
y: t[0],
|
|
109
|
+
r: 6,
|
|
110
|
+
fill: n(t[0], 0)
|
|
111
|
+
})]
|
|
112
|
+
});
|
|
113
|
+
case "pie": {
|
|
114
|
+
const r = t[0], a = /* @__PURE__ */ new Map();
|
|
115
|
+
for (const o of s) {
|
|
116
|
+
const f = String(o[i] ?? "");
|
|
117
|
+
a.set(f, (a.get(f) ?? 0) + (Number(o[r]) || 0));
|
|
118
|
+
}
|
|
119
|
+
const p = Array.from(a, ([o, f]) => ({
|
|
120
|
+
cat: o,
|
|
121
|
+
value: f
|
|
122
|
+
})), h = D(p, { value: "value" }), d = l.palette?.length ? l.palette : w;
|
|
123
|
+
return u({
|
|
124
|
+
marks: [E({ marks: [V(h, {
|
|
125
|
+
startAngle: "startAngle",
|
|
126
|
+
endAngle: "endAngle",
|
|
127
|
+
padAngle: "padAngle",
|
|
128
|
+
innerRadius: 0,
|
|
129
|
+
color: "cat",
|
|
130
|
+
key: "cat"
|
|
131
|
+
})] })],
|
|
132
|
+
color: {
|
|
133
|
+
domain: p.map((o) => o.cat),
|
|
134
|
+
range: d
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
case "barHorizontal":
|
|
139
|
+
return u({
|
|
140
|
+
y: { scale: () => g().padding(0.25) },
|
|
141
|
+
x: {
|
|
142
|
+
scale: m,
|
|
143
|
+
nice: !0,
|
|
144
|
+
grid: !0
|
|
145
|
+
},
|
|
146
|
+
marks: t.map((r, a) => R(s, {
|
|
147
|
+
id: r,
|
|
148
|
+
y: i,
|
|
149
|
+
x: r,
|
|
150
|
+
fill: n(r, a),
|
|
151
|
+
radius: 4
|
|
152
|
+
}))
|
|
153
|
+
});
|
|
154
|
+
default:
|
|
155
|
+
return u({
|
|
156
|
+
x: { scale: () => g().padding(0.25) },
|
|
157
|
+
y: {
|
|
158
|
+
scale: m,
|
|
159
|
+
nice: !0,
|
|
160
|
+
grid: !0
|
|
161
|
+
},
|
|
162
|
+
marks: t.map((r, a) => T(s, {
|
|
163
|
+
id: r,
|
|
164
|
+
x: i,
|
|
165
|
+
y: r,
|
|
166
|
+
fill: n(r, a),
|
|
167
|
+
radius: 4
|
|
168
|
+
}))
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
}, [e]);
|
|
172
|
+
}
|
|
173
|
+
function Y({ config: e }) {
|
|
174
|
+
const l = O(e), i = e.chart, t = S(null), [s, n] = z({
|
|
175
|
+
w: 0,
|
|
176
|
+
h: 0
|
|
177
|
+
});
|
|
178
|
+
if (P(() => {
|
|
179
|
+
const a = t.current;
|
|
180
|
+
if (!a) return;
|
|
181
|
+
const p = () => {
|
|
182
|
+
const d = a.getBoundingClientRect(), o = d.width && a.offsetWidth ? d.width / a.offsetWidth : 1;
|
|
183
|
+
n({
|
|
184
|
+
w: Math.max(1, Math.round(d.width / (o || 1))),
|
|
185
|
+
h: Math.max(1, Math.round(d.height / (o || 1)))
|
|
186
|
+
});
|
|
187
|
+
};
|
|
188
|
+
p();
|
|
189
|
+
const h = new ResizeObserver(p);
|
|
190
|
+
return h.observe(a), () => h.disconnect();
|
|
191
|
+
}, []), !l) return /* @__PURE__ */ c("div", {
|
|
192
|
+
className: "flow-data-empty",
|
|
193
|
+
children: e.columns.length === 0 ? "尚无数据,请在属性面板上传或填写数据" : "请在属性面板选择 X 轴与至少一个数值字段"
|
|
194
|
+
});
|
|
195
|
+
const r = i && i.xField ? `${v(e.columns, i.xField)} · ${(i.yFields ?? []).map((a) => v(e.columns, a)).join(", ")}` : "Chart";
|
|
196
|
+
return /* @__PURE__ */ c("div", {
|
|
197
|
+
className: "flow-data-chart",
|
|
198
|
+
ref: t,
|
|
199
|
+
children: s.h > 0 && /* @__PURE__ */ c(A, {
|
|
200
|
+
definition: l,
|
|
201
|
+
"aria-label": r,
|
|
202
|
+
height: s.h
|
|
203
|
+
})
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
function U({ config: e }) {
|
|
207
|
+
return !e || e.columns.length === 0 ? /* @__PURE__ */ c("div", {
|
|
208
|
+
className: "flow-data-empty",
|
|
209
|
+
children: "尚无数据,请在属性面板上传或填写数据"
|
|
210
|
+
}) : e.view === "chart" ? /* @__PURE__ */ c(Y, { config: e }) : /* @__PURE__ */ c(B, { config: e });
|
|
211
|
+
}
|
|
212
|
+
export {
|
|
213
|
+
U as DataNodeView,
|
|
214
|
+
U as default
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
//# sourceMappingURL=DataNodeView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DataNodeView.js","names":[],"sources":["../../../../../src/components/pro/Flow/nodes/DataNodeView.tsx"],"sourcesContent":["import React, { useMemo, useRef, useState, useLayoutEffect } from 'react';\nimport Chart, {\n areaY,\n barX,\n barY,\n defineChart,\n dot,\n lineY,\n} from '../../../Chart';\nimport { scaleBand } from '@tanstack/charts/scales/band';\nimport { scaleLinear } from '@tanstack/charts/scales/linear';\nimport { scalePoint } from '@tanstack/charts/scales/point';\nimport { polar, pie, radialArc } from '@tanstack/charts/polar';\nimport DataTable, {\n createColumn,\n usePivotExtension,\n type ColumnDef,\n type PivotField,\n type PivotValue,\n} from '../../DataTable';\nimport type { FlowDataConfig } from '../types';\nimport { DATA_CHART_PALETTE, labelFor } from './dataUtils';\n\n/** Renders the table (optionally pivoted) surface of a Data node. */\nfunction DataTableView({ config }: { config: FlowDataConfig }) {\n const columns = useMemo<ColumnDef<Record<string, unknown>>[]>(\n () =>\n config.columns.map((col) =>\n createColumn<Record<string, unknown>>(col.key, col.label ?? col.key, {\n enableSorting: true,\n }),\n ),\n [config.columns],\n );\n\n const pivotFields = useMemo<PivotField[]>(\n () =>\n config.columns.map((col) => ({\n field: col.key,\n label: col.label ?? col.key,\n numeric: col.type === 'number',\n })),\n [config.columns],\n );\n\n const pivot = config.pivot;\n // Remount the pivot extension when the inspector-controlled bits change, so\n // the enabled toggle / initial fields take effect (the extension keeps its\n // own interactive state otherwise). Panel placement stays reactive.\n const pivotKey = JSON.stringify({\n e: !!pivot?.enabled,\n r: pivot?.rowFields ?? [],\n c: pivot?.colFields ?? [],\n v: pivot?.values ?? [],\n });\n\n return (\n <div className=\"flow-data-table\">\n <PivotableTable\n key={pivotKey}\n config={config}\n columns={columns}\n pivotFields={pivotFields}\n />\n </div>\n );\n}\n\nfunction PivotableTable({\n config,\n columns,\n pivotFields,\n}: {\n config: FlowDataConfig;\n columns: ColumnDef<Record<string, unknown>>[];\n pivotFields: PivotField[];\n}) {\n const pivot = config.pivot;\n const pivotExtension = usePivotExtension<Record<string, unknown>>({\n fields: pivotFields,\n initialActive: !!pivot?.enabled,\n initialRowFields: pivot?.rowFields ?? [],\n initialColFields: pivot?.colFields ?? [],\n initialValues: (pivot?.values as PivotValue[] | undefined) ?? [],\n panelPlacement: pivot?.panelPlacement ?? 'top',\n lang: 'zh',\n // 透视开关由 Inspector 统一控制,节点内不再渲染开关,避免占用空间。\n hideModeToggle: true,\n });\n\n return (\n <DataTable<Record<string, unknown>>\n data={config.rows}\n columns={columns}\n enableSorting\n enablePagination={config.rows.length > 50}\n pageSize={50}\n extensions={[pivotExtension]}\n />\n );\n}\n\n/** Builds a TanStack Charts definition from the Data node's chart config. */\nfunction useChartDefinition(config: FlowDataConfig) {\n return useMemo(() => {\n const chart = config.chart;\n if (!chart) return null;\n const xField = chart.xField;\n const yFields = (chart.yFields ?? []).filter(Boolean);\n if (!xField || yFields.length === 0) return null;\n\n const rows = config.rows as any[];\n const seriesColor = (field: string, i: number) =>\n chart.seriesColors?.[field] ?? DATA_CHART_PALETTE[i % DATA_CHART_PALETTE.length];\n\n switch (chart.type) {\n case 'line':\n return defineChart({\n x: { scale: () => scalePoint<string>().padding(0.35) },\n y: { scale: scaleLinear, nice: true, grid: true },\n marks: yFields.map((yf, i) =>\n lineY(rows, { id: yf, x: xField, y: yf, stroke: seriesColor(yf, i), points: true }),\n ),\n });\n\n case 'area':\n return defineChart({\n x: { scale: () => scalePoint<string>().padding(0.35) },\n y: { scale: scaleLinear, nice: true, grid: true },\n marks: yFields.map((yf, i) =>\n areaY(rows, {\n id: yf,\n x: xField,\n y: yf,\n fill: seriesColor(yf, i),\n fillOpacity: 0.35,\n stroke: seriesColor(yf, i),\n }),\n ),\n });\n\n case 'scatter':\n // Scatter uses the first two numeric fields as x/y.\n return defineChart({\n x: { scale: scaleLinear, nice: true, grid: true },\n y: { scale: scaleLinear, nice: true, grid: true },\n marks: [\n dot(rows, {\n id: 'points',\n x: xField,\n y: yFields[0],\n r: 6,\n fill: seriesColor(yFields[0], 0),\n }),\n ],\n });\n\n case 'pie': {\n // Part-to-whole via a polar pie over the first measure. Duplicate\n // categories are aggregated (summed) so slices are unique.\n const yf = yFields[0];\n const totals = new Map<string, number>();\n for (const r of rows) {\n const k = String(r[xField] ?? '');\n totals.set(k, (totals.get(k) ?? 0) + (Number(r[yf]) || 0));\n }\n const pieRows = Array.from(totals, ([cat, value]) => ({ cat, value }));\n const arranged = pie(pieRows, { value: 'value' });\n const range = chart.palette?.length ? chart.palette : DATA_CHART_PALETTE;\n return defineChart({\n marks: [\n polar({\n marks: [\n radialArc(arranged, {\n startAngle: 'startAngle',\n endAngle: 'endAngle',\n padAngle: 'padAngle',\n innerRadius: 0,\n color: 'cat',\n key: 'cat',\n }),\n ],\n }),\n ],\n color: { domain: pieRows.map((d) => d.cat), range },\n });\n }\n\n case 'barHorizontal':\n return defineChart({\n y: { scale: () => scaleBand<string>().padding(0.25) },\n x: { scale: scaleLinear, nice: true, grid: true },\n marks: yFields.map((yf, i) =>\n barX(rows, { id: yf, y: xField, x: yf, fill: seriesColor(yf, i), radius: 4 }),\n ),\n });\n\n case 'bar':\n default:\n return defineChart({\n x: { scale: () => scaleBand<string>().padding(0.25) },\n y: { scale: scaleLinear, nice: true, grid: true },\n marks: yFields.map((yf, i) =>\n barY(rows, { id: yf, x: xField, y: yf, fill: seriesColor(yf, i), radius: 4 }),\n ),\n });\n }\n }, [config]);\n}\n\n/** Renders the chart surface of a Data node. */\nfunction DataChartView({ config }: { config: FlowDataConfig }) {\n const definition = useChartDefinition(config);\n const chart = config.chart;\n\n // TanStack Charts needs a concrete pixel height; inside the media overlay the\n // node box is a fixed size but percentage heights don't always resolve before\n // first paint (esp. in read-only / preview renders), leaving the chart blank.\n // Measure the container and pass an explicit height.\n const wrapRef = useRef<HTMLDivElement>(null);\n const [size, setSize] = useState<{ w: number; h: number }>({ w: 0, h: 0 });\n useLayoutEffect(() => {\n const el = wrapRef.current;\n if (!el) return;\n const measure = () => {\n const rect = el.getBoundingClientRect();\n // getBoundingClientRect includes the overlay's zoom scale; divide it out\n // so the chart is laid out in unscaled (world) pixels.\n const scale = rect.width && el.offsetWidth ? rect.width / el.offsetWidth : 1;\n setSize({\n w: Math.max(1, Math.round(rect.width / (scale || 1))),\n h: Math.max(1, Math.round(rect.height / (scale || 1))),\n });\n };\n measure();\n const ro = new ResizeObserver(measure);\n ro.observe(el);\n return () => ro.disconnect();\n }, []);\n\n if (!definition) {\n return (\n <div className=\"flow-data-empty\">\n {config.columns.length === 0\n ? '尚无数据,请在属性面板上传或填写数据'\n : '请在属性面板选择 X 轴与至少一个数值字段'}\n </div>\n );\n }\n\n const label =\n chart && chart.xField\n ? `${labelFor(config.columns, chart.xField)} · ${(chart.yFields ?? [])\n .map((f) => labelFor(config.columns, f))\n .join(', ')}`\n : 'Chart';\n\n return (\n <div className=\"flow-data-chart\" ref={wrapRef}>\n {size.h > 0 && (\n <Chart\n definition={definition as any}\n aria-label={label}\n height={size.h}\n />\n )}\n </div>\n );\n}\n\n/** Dispatches to the table or chart surface based on the node's view. */\nexport function DataNodeView({ config }: { config: FlowDataConfig }) {\n if (!config || config.columns.length === 0) {\n return <div className=\"flow-data-empty\">尚无数据,请在属性面板上传或填写数据</div>;\n }\n return config.view === 'chart' ? (\n <DataChartView config={config} />\n ) : (\n <DataTableView config={config} />\n );\n}\n\nexport default DataNodeView;\n"],"mappings":";;;;;;;;;;;AAwBA,SAAS,EAAc,EAAE,QAAA,EAAA,GAAsC;AAC7D,QAAM,IAAU,E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
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
1
|
+
import z from "../../../Markdown/Markdown.js";
|
|
2
|
+
import { resolveThemeColor as A, resolveThemeColorCss as D } from "../utils/themeColor.js";
|
|
3
|
+
import { streamAIChat as T } from "./aiClient.js";
|
|
4
|
+
import { Model3DView as $ } from "./Model3DView.js";
|
|
5
|
+
import H, { useEffect as v, useMemo as R, useRef as N, useState as f } from "react";
|
|
6
|
+
import { jsx as t, jsxs as b } from "react/jsx-runtime";
|
|
7
|
+
import V from "mermaid";
|
|
7
8
|
import "katex/dist/katex.min.css";
|
|
8
|
-
import
|
|
9
|
-
var I = !1;
|
|
10
|
-
function
|
|
11
|
-
I || (
|
|
9
|
+
import K from "katex";
|
|
10
|
+
var L = H.lazy(() => import("./DataNodeView.js").then((e) => ({ default: e.DataNodeView }))), I = !1;
|
|
11
|
+
function _() {
|
|
12
|
+
I || (V.initialize({
|
|
12
13
|
startOnLoad: !1,
|
|
13
14
|
theme: "default",
|
|
14
15
|
securityLevel: "loose",
|
|
15
16
|
fontFamily: "inherit"
|
|
16
17
|
}), I = !0);
|
|
17
18
|
}
|
|
18
|
-
function
|
|
19
|
-
const [
|
|
20
|
-
return
|
|
21
|
-
let
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
if (!
|
|
25
|
-
|
|
19
|
+
function P({ content: e, color: r }) {
|
|
20
|
+
const [s, a] = f(""), [o, i] = f(null), u = N(`flow-mermaid-${Math.random().toString(36).slice(2)}`);
|
|
21
|
+
return v(() => {
|
|
22
|
+
let m = !1;
|
|
23
|
+
_();
|
|
24
|
+
const c = e.trim();
|
|
25
|
+
if (!c) {
|
|
26
|
+
a(""), i(null);
|
|
26
27
|
return;
|
|
27
28
|
}
|
|
28
|
-
return
|
|
29
|
-
|
|
29
|
+
return V.render(u.current, c).then(({ svg: d }) => {
|
|
30
|
+
m || (a(d), i(null));
|
|
30
31
|
}).catch((d) => {
|
|
31
|
-
|
|
32
|
+
m || i(d?.message ?? "Mermaid error");
|
|
32
33
|
}), () => {
|
|
33
|
-
|
|
34
|
+
m = !0;
|
|
34
35
|
};
|
|
35
|
-
}, [
|
|
36
|
+
}, [e]), o ? /* @__PURE__ */ t("div", {
|
|
36
37
|
className: "flow-media-error",
|
|
37
|
-
children:
|
|
38
|
-
}) : /* @__PURE__ */
|
|
38
|
+
children: o
|
|
39
|
+
}) : /* @__PURE__ */ t("div", {
|
|
39
40
|
className: "flow-media-mermaid",
|
|
40
41
|
style: { color: r },
|
|
41
|
-
dangerouslySetInnerHTML: { __html:
|
|
42
|
+
dangerouslySetInnerHTML: { __html: s }
|
|
42
43
|
});
|
|
43
44
|
}
|
|
44
|
-
function
|
|
45
|
-
const
|
|
45
|
+
function j({ content: e, color: r, fontSize: s }) {
|
|
46
|
+
const a = R(() => {
|
|
46
47
|
try {
|
|
47
|
-
return
|
|
48
|
+
return K.renderToString(e.trim() || "\\;", {
|
|
48
49
|
displayMode: !0,
|
|
49
50
|
throwOnError: !1
|
|
50
51
|
});
|
|
51
|
-
} catch (
|
|
52
|
-
return `<span class="flow-media-error">${
|
|
52
|
+
} catch (o) {
|
|
53
|
+
return `<span class="flow-media-error">${o?.message ?? "KaTeX error"}</span>`;
|
|
53
54
|
}
|
|
54
|
-
}, [
|
|
55
|
-
return /* @__PURE__ */
|
|
55
|
+
}, [e]);
|
|
56
|
+
return /* @__PURE__ */ t("div", {
|
|
56
57
|
className: "flow-media-math",
|
|
57
58
|
style: {
|
|
58
59
|
color: r,
|
|
59
|
-
fontSize:
|
|
60
|
+
fontSize: s
|
|
60
61
|
},
|
|
61
|
-
dangerouslySetInnerHTML: { __html:
|
|
62
|
+
dangerouslySetInnerHTML: { __html: a }
|
|
62
63
|
});
|
|
63
64
|
}
|
|
64
|
-
function
|
|
65
|
-
|
|
65
|
+
function F({ content: e, interactive: r, color: s, fontSize: a }) {
|
|
66
|
+
const o = R(() => `<!doctype html><html><head><meta charset="utf-8"><style>
|
|
67
|
+
:root { color-scheme: light dark; }
|
|
68
|
+
html, body { margin: 0; background: transparent; }
|
|
69
|
+
body {
|
|
70
|
+
color: ${s ?? "#111827"};
|
|
71
|
+
font-size: ${a ?? 13}px;
|
|
72
|
+
font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
|
|
73
|
+
line-height: 1.5;
|
|
74
|
+
padding: 0;
|
|
75
|
+
}
|
|
76
|
+
a { color: inherit; }
|
|
77
|
+
</style></head><body>${e}</body></html>`, [
|
|
78
|
+
e,
|
|
79
|
+
s,
|
|
80
|
+
a
|
|
81
|
+
]);
|
|
82
|
+
return /* @__PURE__ */ t("iframe", {
|
|
66
83
|
title: "html-media",
|
|
67
84
|
className: "flow-media-iframe",
|
|
68
85
|
style: { pointerEvents: r ? "auto" : "none" },
|
|
69
86
|
sandbox: "allow-scripts allow-same-origin allow-popups allow-forms",
|
|
70
|
-
srcDoc:
|
|
87
|
+
srcDoc: o
|
|
71
88
|
});
|
|
72
89
|
}
|
|
73
|
-
function
|
|
74
|
-
const r =
|
|
75
|
-
return r ? /* @__PURE__ */
|
|
90
|
+
function O({ content: e }) {
|
|
91
|
+
const r = e.trim();
|
|
92
|
+
return r ? /* @__PURE__ */ t("img", {
|
|
76
93
|
className: "flow-media-image",
|
|
77
94
|
src: r,
|
|
78
95
|
alt: "",
|
|
79
96
|
draggable: !1,
|
|
80
97
|
referrerPolicy: "no-referrer"
|
|
81
|
-
}) : /* @__PURE__ */
|
|
98
|
+
}) : /* @__PURE__ */ t("div", {
|
|
82
99
|
className: "flow-media-image-empty",
|
|
83
100
|
children: "输入图片链接,或直接粘贴图片"
|
|
84
101
|
});
|
|
85
102
|
}
|
|
86
|
-
function
|
|
87
|
-
const [
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}, [
|
|
91
|
-
const
|
|
92
|
-
const
|
|
93
|
-
if (!
|
|
94
|
-
|
|
95
|
-
const p = [...
|
|
103
|
+
function q({ node: e, config: r, interactive: s, color: a }) {
|
|
104
|
+
const [o, i] = f([]), [u, m] = f(""), [c, d] = f(!1), [C, M] = f(null), w = N(null), y = N(null);
|
|
105
|
+
v(() => {
|
|
106
|
+
y.current?.scrollTo({ top: y.current.scrollHeight });
|
|
107
|
+
}, [o, c]), v(() => () => w.current?.abort(), []);
|
|
108
|
+
const S = !!r?.gateway && !!r?.model && !c, k = async () => {
|
|
109
|
+
const l = u.trim();
|
|
110
|
+
if (!l || !r?.gateway) return;
|
|
111
|
+
M(null);
|
|
112
|
+
const p = [...o.filter((n) => !(n.role === "assistant" && n.content.trim() === "")), {
|
|
96
113
|
role: "user",
|
|
97
|
-
content:
|
|
114
|
+
content: l
|
|
98
115
|
}];
|
|
99
|
-
|
|
116
|
+
i(p), m(""), d(!0);
|
|
100
117
|
const x = new AbortController();
|
|
101
|
-
|
|
118
|
+
w.current = x;
|
|
102
119
|
let E = "";
|
|
103
|
-
|
|
120
|
+
i((n) => [...n, {
|
|
104
121
|
role: "assistant",
|
|
105
122
|
content: ""
|
|
106
123
|
}]);
|
|
107
124
|
try {
|
|
108
|
-
for await (const
|
|
109
|
-
E +=
|
|
110
|
-
const
|
|
111
|
-
return
|
|
125
|
+
for await (const n of T(r, p, x.signal))
|
|
126
|
+
E += n, i((h) => {
|
|
127
|
+
const g = h.slice();
|
|
128
|
+
return g[g.length - 1] = {
|
|
112
129
|
role: "assistant",
|
|
113
130
|
content: E
|
|
114
|
-
},
|
|
131
|
+
}, g;
|
|
115
132
|
});
|
|
116
|
-
} catch (
|
|
117
|
-
|
|
133
|
+
} catch (n) {
|
|
134
|
+
n?.name !== "AbortError" && M(n?.message ?? "Request failed");
|
|
118
135
|
} finally {
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
return
|
|
122
|
-
}), d(!1),
|
|
136
|
+
i((n) => {
|
|
137
|
+
const h = n[n.length - 1];
|
|
138
|
+
return h && h.role === "assistant" && h.content.trim() === "" ? n.slice(0, -1) : n;
|
|
139
|
+
}), d(!1), w.current = null;
|
|
123
140
|
}
|
|
124
141
|
};
|
|
125
|
-
return /* @__PURE__ */
|
|
142
|
+
return /* @__PURE__ */ b("div", {
|
|
126
143
|
className: "flow-media-ai",
|
|
127
|
-
style: { color:
|
|
144
|
+
style: { color: a },
|
|
128
145
|
children: [
|
|
129
|
-
/* @__PURE__ */
|
|
146
|
+
/* @__PURE__ */ t("div", {
|
|
130
147
|
className: "flow-media-ai-header",
|
|
131
|
-
children: r?.model ? `AI · ${r.model}` :
|
|
148
|
+
children: r?.model ? `AI · ${r.model}` : e.data.label || "AI"
|
|
132
149
|
}),
|
|
133
|
-
/* @__PURE__ */
|
|
150
|
+
/* @__PURE__ */ b("div", {
|
|
134
151
|
className: "flow-media-ai-log",
|
|
135
|
-
ref:
|
|
152
|
+
ref: y,
|
|
136
153
|
children: [
|
|
137
|
-
|
|
154
|
+
o.length === 0 && /* @__PURE__ */ t("div", {
|
|
138
155
|
className: "flow-media-ai-empty",
|
|
139
156
|
children: r?.gateway ? "开始对话…" : "请在属性面板配置 AI 接口"
|
|
140
157
|
}),
|
|
141
|
-
|
|
142
|
-
className: `flow-media-ai-msg flow-media-ai-msg--${
|
|
143
|
-
children:
|
|
144
|
-
content:
|
|
158
|
+
o.map((l, p) => /* @__PURE__ */ t("div", {
|
|
159
|
+
className: `flow-media-ai-msg flow-media-ai-msg--${l.role}`,
|
|
160
|
+
children: l.role === "assistant" ? /* @__PURE__ */ t(z, {
|
|
161
|
+
content: l.content || "…",
|
|
145
162
|
enableMermaid: !1,
|
|
146
163
|
enableMarkmap: !1
|
|
147
|
-
}) : /* @__PURE__ */
|
|
164
|
+
}) : /* @__PURE__ */ t("span", { children: l.content })
|
|
148
165
|
}, p)),
|
|
149
|
-
|
|
166
|
+
C && /* @__PURE__ */ t("div", {
|
|
150
167
|
className: "flow-media-error",
|
|
151
|
-
children:
|
|
168
|
+
children: C
|
|
152
169
|
})
|
|
153
170
|
]
|
|
154
171
|
}),
|
|
155
|
-
/* @__PURE__ */
|
|
172
|
+
/* @__PURE__ */ b("div", {
|
|
156
173
|
className: "flow-media-ai-input",
|
|
157
|
-
style: { pointerEvents:
|
|
158
|
-
children: [/* @__PURE__ */
|
|
159
|
-
value:
|
|
174
|
+
style: { pointerEvents: s ? "auto" : "none" },
|
|
175
|
+
children: [/* @__PURE__ */ t("textarea", {
|
|
176
|
+
value: u,
|
|
160
177
|
placeholder: "输入消息,Enter 发送",
|
|
161
|
-
onChange: (
|
|
162
|
-
onKeyDown: (
|
|
163
|
-
|
|
178
|
+
onChange: (l) => m(l.target.value),
|
|
179
|
+
onKeyDown: (l) => {
|
|
180
|
+
l.key === "Enter" && !l.shiftKey && (l.preventDefault(), S && k());
|
|
164
181
|
},
|
|
165
|
-
onPointerDown: (
|
|
166
|
-
}),
|
|
182
|
+
onPointerDown: (l) => l.stopPropagation()
|
|
183
|
+
}), c ? /* @__PURE__ */ t("button", {
|
|
167
184
|
type: "button",
|
|
168
|
-
onClick: () =>
|
|
185
|
+
onClick: () => w.current?.abort(),
|
|
169
186
|
children: "停止"
|
|
170
|
-
}) : /* @__PURE__ */
|
|
187
|
+
}) : /* @__PURE__ */ t("button", {
|
|
171
188
|
type: "button",
|
|
172
|
-
disabled: !
|
|
173
|
-
onClick:
|
|
189
|
+
disabled: !S || !u.trim(),
|
|
190
|
+
onClick: k,
|
|
174
191
|
children: "发送"
|
|
175
192
|
})]
|
|
176
193
|
})
|
|
177
194
|
]
|
|
178
195
|
});
|
|
179
196
|
}
|
|
180
|
-
function
|
|
181
|
-
const
|
|
182
|
-
switch (
|
|
197
|
+
function ee({ node: e, interactive: r }) {
|
|
198
|
+
const s = e.data.mediaKind ?? "markdown", a = e.data.mediaContent ?? "", o = D(e.data.labelColor ?? e.data.color, "#111827");
|
|
199
|
+
switch (s) {
|
|
183
200
|
case "markdown":
|
|
184
|
-
return /* @__PURE__ */
|
|
201
|
+
return /* @__PURE__ */ t("div", {
|
|
185
202
|
className: "flow-media-markdown",
|
|
186
203
|
style: {
|
|
187
|
-
color:
|
|
188
|
-
fontSize:
|
|
204
|
+
color: o,
|
|
205
|
+
fontSize: e.data.fontSize
|
|
189
206
|
},
|
|
190
|
-
children: /* @__PURE__ */
|
|
207
|
+
children: /* @__PURE__ */ t(z, { content: a })
|
|
191
208
|
});
|
|
192
209
|
case "html":
|
|
193
|
-
return /* @__PURE__ */
|
|
194
|
-
content:
|
|
195
|
-
interactive: r
|
|
210
|
+
return /* @__PURE__ */ t(F, {
|
|
211
|
+
content: a,
|
|
212
|
+
interactive: r,
|
|
213
|
+
color: A(e.data.labelColor ?? e.data.color, "#111827"),
|
|
214
|
+
fontSize: e.data.fontSize
|
|
196
215
|
});
|
|
197
216
|
case "mermaid":
|
|
198
|
-
return /* @__PURE__ */
|
|
199
|
-
content:
|
|
200
|
-
color:
|
|
217
|
+
return /* @__PURE__ */ t(P, {
|
|
218
|
+
content: a,
|
|
219
|
+
color: o
|
|
201
220
|
});
|
|
202
221
|
case "math":
|
|
203
|
-
return /* @__PURE__ */
|
|
204
|
-
content:
|
|
205
|
-
color:
|
|
206
|
-
fontSize:
|
|
222
|
+
return /* @__PURE__ */ t(j, {
|
|
223
|
+
content: a,
|
|
224
|
+
color: o,
|
|
225
|
+
fontSize: e.data.fontSize
|
|
207
226
|
});
|
|
208
227
|
case "image":
|
|
209
|
-
return /* @__PURE__ */
|
|
228
|
+
return /* @__PURE__ */ t(O, { content: a });
|
|
210
229
|
case "model3d":
|
|
211
|
-
return /* @__PURE__ */
|
|
212
|
-
content:
|
|
213
|
-
format:
|
|
230
|
+
return /* @__PURE__ */ t($, {
|
|
231
|
+
content: a,
|
|
232
|
+
format: e.data.modelFormat ?? "stl",
|
|
214
233
|
interactive: r
|
|
215
234
|
});
|
|
216
235
|
case "ai":
|
|
217
|
-
return /* @__PURE__ */
|
|
218
|
-
node:
|
|
219
|
-
config:
|
|
236
|
+
return /* @__PURE__ */ t(q, {
|
|
237
|
+
node: e,
|
|
238
|
+
config: e.data.aiConfig,
|
|
220
239
|
interactive: r,
|
|
221
|
-
color:
|
|
240
|
+
color: o
|
|
241
|
+
});
|
|
242
|
+
case "data":
|
|
243
|
+
return /* @__PURE__ */ t("div", {
|
|
244
|
+
className: "flow-media-data",
|
|
245
|
+
style: { pointerEvents: r ? "auto" : "none" },
|
|
246
|
+
children: /* @__PURE__ */ t(L, { config: e.data.dataConfig ?? {
|
|
247
|
+
columns: [],
|
|
248
|
+
rows: [],
|
|
249
|
+
view: "table"
|
|
250
|
+
} })
|
|
222
251
|
});
|
|
223
252
|
default:
|
|
224
253
|
return null;
|
|
225
254
|
}
|
|
226
255
|
}
|
|
227
256
|
export {
|
|
228
|
-
|
|
257
|
+
ee as MediaContent
|
|
229
258
|
};
|
|
230
259
|
|
|
231
260
|
//# sourceMappingURL=MediaContent.js.map
|