dishui 0.0.84 → 0.0.91
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/Input/index.js +52 -62
- package/dist/components/Input/index.js.map +1 -1
- package/dist/components/LayoutSuite/index.d.ts +10 -0
- package/dist/components/LayoutSuite/index.js +27 -18
- package/dist/components/LayoutSuite/index.js.map +1 -1
- package/dist/components/Markdown/markdownComponents.js +1 -0
- package/dist/components/Markdown/markdownComponents.js.map +1 -1
- package/dist/components/Markdown/useMarkdownSource.js +46 -31
- package/dist/components/Markdown/useMarkdownSource.js.map +1 -1
- package/dist/components/Markdown/useMarkmapRenderer.js +44 -31
- package/dist/components/Markdown/useMarkmapRenderer.js.map +1 -1
- package/dist/components/Markdown/useMermaidRenderer.js +49 -31
- package/dist/components/Markdown/useMermaidRenderer.js.map +1 -1
- package/dist/components/ProtectedRoute/index.d.ts +2 -1
- package/dist/components/ProtectedRoute/index.js +16 -6
- package/dist/components/ProtectedRoute/index.js.map +1 -1
- package/dist/components/Select/index.d.ts +6 -0
- package/dist/components/Select/index.js +166 -136
- package/dist/components/Select/index.js.map +1 -1
- package/dist/components/Table/index.d.ts +23 -2
- package/dist/components/Table/index.js +153 -101
- package/dist/components/Table/index.js.map +1 -1
- package/dist/components/Tabs/index.d.ts +12 -1
- package/dist/components/Tabs/index.js +42 -17
- package/dist/components/Tabs/index.js.map +1 -1
- package/dist/components/pro/ArticleContextMenu/index.js +7 -7
- package/dist/components/pro/CodeEditor/editors/CodeEditor.js +200 -189
- package/dist/components/pro/CodeEditor/editors/CodeEditor.js.map +1 -1
- package/dist/components/pro/CodeEditor/types.d.ts +3 -0
- package/dist/components/pro/DataTable/DataTable.d.ts +1 -1
- package/dist/components/pro/DataTable/DataTable.js +124 -247
- package/dist/components/pro/DataTable/DataTable.js.map +1 -1
- package/dist/components/pro/DataTable/components/TableBody.d.ts +3 -1
- package/dist/components/pro/DataTable/components/TableBody.js +41 -41
- package/dist/components/pro/DataTable/components/TableBody.js.map +1 -1
- package/dist/components/pro/DataTable/components/TablePagination.d.ts +3 -9
- package/dist/components/pro/DataTable/components/TablePagination.js +29 -25
- package/dist/components/pro/DataTable/components/TablePagination.js.map +1 -1
- package/dist/components/pro/DataTable/components/TableToolbar.d.ts +2 -1
- package/dist/components/pro/DataTable/components/TableToolbar.js +25 -19
- package/dist/components/pro/DataTable/components/TableToolbar.js.map +1 -1
- package/dist/components/pro/DataTable/index.d.ts +1 -1
- package/dist/components/pro/DataTable/rowDetailExtension.js +1 -1
- package/dist/components/pro/DataTable/rowDetailExtension.js.map +1 -1
- package/dist/components/pro/DataTable/tanstack-table.d.ts +2 -2
- package/dist/components/pro/DataTable/tanstack-table.js +29 -21
- package/dist/components/pro/DataTable/tanstack-table.js.map +1 -1
- package/dist/components/pro/DataTable/treeDataUtils.d.ts +2 -0
- package/dist/components/pro/DataTable/treeDataUtils.js +18 -19
- package/dist/components/pro/DataTable/treeDataUtils.js.map +1 -1
- package/dist/components/pro/DataTable/types.d.ts +43 -0
- package/dist/components/pro/DataTable/useDataTableModel.d.ts +16 -0
- package/dist/components/pro/DataTable/useDataTableModel.js +148 -0
- package/dist/components/pro/DataTable/useDataTableModel.js.map +1 -0
- package/dist/components/pro/FileExplorer/Breadcrumb.js +12 -12
- package/dist/components/pro/Flow/nodes/DataNodeView.js +87 -82
- package/dist/components/pro/Flow/nodes/DataNodeView.js.map +1 -1
- package/dist/components/pro/Flow/nodes/MediaContent.js +1 -1
- package/dist/components/pro/Flow/nodes/MediaContent.js.map +1 -1
- package/dist/components/pro/Flow/nodes/MediaOverlay.js +1 -1
- package/dist/components/pro/Flow/nodes/MediaOverlay.js.map +1 -1
- package/dist/components/pro/Flow/nodes/Model3DView.js +69 -63
- package/dist/components/pro/Flow/nodes/Model3DView.js.map +1 -1
- package/dist/components/pro/Flow/nodes/chartGeometryBudget.d.ts +14 -0
- package/dist/components/pro/Flow/nodes/chartGeometryBudget.js +76 -0
- package/dist/components/pro/Flow/nodes/chartGeometryBudget.js.map +1 -0
- package/dist/components/pro/Flow/nodes/demandRender.d.ts +11 -0
- package/dist/components/pro/Flow/nodes/demandRender.js +26 -0
- package/dist/components/pro/Flow/nodes/demandRender.js.map +1 -0
- package/dist/components/pro/RichTextEditor/SlashMenu.js +68 -58
- package/dist/components/pro/RichTextEditor/SlashMenu.js.map +1 -1
- package/dist/contexts/AppContext.d.ts +1 -0
- package/dist/contexts/AppContext.js +144 -145
- package/dist/contexts/AppContext.js.map +1 -1
- package/dist/contexts/authentication.d.ts +7 -0
- package/dist/contexts/authentication.js +22 -0
- package/dist/contexts/authentication.js.map +1 -0
- package/dist/data-table.js.map +1 -1
- package/dist/dishui.css +1 -1
- package/dist/hooks/useControllableState.d.ts +6 -14
- package/dist/hooks/useControllableState.js +21 -15
- package/dist/hooks/useControllableState.js.map +1 -1
- package/dist/hooks/useTableColumns.d.ts +3 -3
- package/dist/hooks/useTableColumns.js +2 -2
- package/dist/hooks/useTableColumns.js.map +1 -1
- package/dist/hooks/useTableData.d.ts +11 -4
- package/dist/hooks/useTableData.js +44 -26
- package/dist/hooks/useTableData.js.map +1 -1
- package/dist/index-nostyled.d.ts +2 -2
- package/dist/index.d.ts +4 -4
- package/dist/index.js +97 -97
- package/dist/lite.d.ts +2 -0
- package/dist/lite.js +22 -21
- package/dist/utils/i18n.js +1 -1
- package/dist/utils/i18n.js.map +1 -1
- package/dist/utils/routerBuilder.d.ts +7 -5
- package/dist/utils/routerBuilder.js +11 -15
- package/dist/utils/routerBuilder.js.map +1 -1
- package/dist/utils/safeStorage.d.ts +8 -0
- package/dist/utils/safeStorage.js +45 -0
- package/dist/utils/safeStorage.js.map +1 -0
- package/package.json +22 -5
|
@@ -3,15 +3,16 @@ import t, { createColumn as n } from "../../../../data-table.js";
|
|
|
3
3
|
import r from "../../../Chart/Chart.js";
|
|
4
4
|
import { areaY as i, barX as a, barY as o, defineChart as s, dot as c, lineY as l } from "../../../../chart.js";
|
|
5
5
|
import { DATA_CHART_PALETTE as u, labelFor as d } from "./dataUtils.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
6
|
+
import { showLinePoints as f, withChartGeometryBudget as p } from "./chartGeometryBudget.js";
|
|
7
|
+
import { useLayoutEffect as m, useMemo as h, useRef as g, useState as _ } from "react";
|
|
8
|
+
import { jsx as v } from "react/jsx-runtime";
|
|
9
|
+
import { scaleBand as y } from "@tanstack/charts/scales/band";
|
|
10
|
+
import { scaleLinear as b } from "@tanstack/charts/scales/linear";
|
|
11
|
+
import { scalePoint as x } from "@tanstack/charts/scales/point";
|
|
12
|
+
import { pie as S, polar as C, radialArc as w } from "@tanstack/charts/polar";
|
|
12
13
|
//#region src/components/pro/Flow/nodes/DataNodeView.tsx
|
|
13
|
-
function
|
|
14
|
-
let t =
|
|
14
|
+
function T({ config: e }) {
|
|
15
|
+
let t = h(() => e.columns.map((e) => n(e.key, e.label ?? e.key, { enableSorting: !0 })), [e.columns]), r = h(() => e.columns.map((e) => ({
|
|
15
16
|
field: e.key,
|
|
16
17
|
label: e.label ?? e.key,
|
|
17
18
|
numeric: e.type === "number"
|
|
@@ -21,16 +22,16 @@ function C({ config: e }) {
|
|
|
21
22
|
c: i?.colFields ?? [],
|
|
22
23
|
v: i?.values ?? []
|
|
23
24
|
});
|
|
24
|
-
return /* @__PURE__ */
|
|
25
|
+
return /* @__PURE__ */ v("div", {
|
|
25
26
|
className: "flow-data-table",
|
|
26
|
-
children: /* @__PURE__ */
|
|
27
|
+
children: /* @__PURE__ */ v(E, {
|
|
27
28
|
config: e,
|
|
28
29
|
columns: t,
|
|
29
30
|
pivotFields: r
|
|
30
31
|
}, a)
|
|
31
32
|
});
|
|
32
33
|
}
|
|
33
|
-
function
|
|
34
|
+
function E({ config: n, columns: r, pivotFields: i }) {
|
|
34
35
|
let a = n.pivot, o = e({
|
|
35
36
|
fields: i,
|
|
36
37
|
initialActive: !!a?.enabled,
|
|
@@ -41,7 +42,7 @@ function w({ config: n, columns: r, pivotFields: i }) {
|
|
|
41
42
|
lang: "zh",
|
|
42
43
|
hideModeToggle: !0
|
|
43
44
|
});
|
|
44
|
-
return /* @__PURE__ */
|
|
45
|
+
return /* @__PURE__ */ v(t, {
|
|
45
46
|
data: n.rows,
|
|
46
47
|
columns: r,
|
|
47
48
|
enableSorting: !0,
|
|
@@ -50,83 +51,83 @@ function w({ config: n, columns: r, pivotFields: i }) {
|
|
|
50
51
|
extensions: [o]
|
|
51
52
|
});
|
|
52
53
|
}
|
|
53
|
-
function
|
|
54
|
-
return
|
|
55
|
-
let
|
|
56
|
-
if (!
|
|
57
|
-
let
|
|
58
|
-
if (!
|
|
59
|
-
let
|
|
60
|
-
switch (
|
|
54
|
+
function D(e, t, n) {
|
|
55
|
+
return h(() => {
|
|
56
|
+
let r = e.chart;
|
|
57
|
+
if (!r) return null;
|
|
58
|
+
let d = r.xField, m = (r.yFields ?? []).filter(Boolean);
|
|
59
|
+
if (!d || m.length === 0) return null;
|
|
60
|
+
let h = e.rows, g = r.palette?.length ? r.palette : null, _ = (e, t) => r.seriesColors?.[e] ?? g?.[t % g.length] ?? n ?? u[t % u.length];
|
|
61
|
+
switch (r.type) {
|
|
61
62
|
case "line": return s({
|
|
62
|
-
marks:
|
|
63
|
+
marks: m.map((e, n) => p(l(h, {
|
|
63
64
|
id: e,
|
|
64
|
-
x:
|
|
65
|
+
x: d,
|
|
65
66
|
y: e,
|
|
66
|
-
stroke:
|
|
67
|
-
points:
|
|
68
|
-
})),
|
|
67
|
+
stroke: _(e, n),
|
|
68
|
+
points: f(h.length, m.length, t)
|
|
69
|
+
}))),
|
|
69
70
|
scales: {
|
|
70
|
-
x: { scale: () =>
|
|
71
|
+
x: { scale: () => x().padding(.35) },
|
|
71
72
|
y: {
|
|
72
|
-
scale:
|
|
73
|
+
scale: b,
|
|
73
74
|
nice: !0,
|
|
74
75
|
grid: !0
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
78
|
});
|
|
78
79
|
case "area": return s({
|
|
79
|
-
marks:
|
|
80
|
+
marks: m.map((e, t) => p(i(h, {
|
|
80
81
|
id: e,
|
|
81
|
-
x:
|
|
82
|
+
x: d,
|
|
82
83
|
y: e,
|
|
83
|
-
fill:
|
|
84
|
+
fill: _(e, t),
|
|
84
85
|
fillOpacity: .35,
|
|
85
|
-
stroke:
|
|
86
|
-
})),
|
|
86
|
+
stroke: _(e, t)
|
|
87
|
+
}))),
|
|
87
88
|
scales: {
|
|
88
|
-
x: { scale: () =>
|
|
89
|
+
x: { scale: () => x().padding(.35) },
|
|
89
90
|
y: {
|
|
90
|
-
scale:
|
|
91
|
+
scale: b,
|
|
91
92
|
nice: !0,
|
|
92
93
|
grid: !0
|
|
93
94
|
}
|
|
94
95
|
}
|
|
95
96
|
});
|
|
96
97
|
case "scatter": return s({
|
|
97
|
-
marks: [c(
|
|
98
|
+
marks: [c(h, {
|
|
98
99
|
id: "points",
|
|
99
|
-
x:
|
|
100
|
-
y:
|
|
100
|
+
x: d,
|
|
101
|
+
y: m[0],
|
|
101
102
|
r: 6,
|
|
102
|
-
fill: m
|
|
103
|
+
fill: _(m[0], 0)
|
|
103
104
|
})],
|
|
104
105
|
scales: {
|
|
105
106
|
x: {
|
|
106
|
-
scale:
|
|
107
|
+
scale: b,
|
|
107
108
|
nice: !0,
|
|
108
109
|
grid: !0
|
|
109
110
|
},
|
|
110
111
|
y: {
|
|
111
|
-
scale:
|
|
112
|
+
scale: b,
|
|
112
113
|
nice: !0,
|
|
113
114
|
grid: !0
|
|
114
115
|
}
|
|
115
116
|
}
|
|
116
117
|
});
|
|
117
118
|
case "pie": {
|
|
118
|
-
let e =
|
|
119
|
-
for (let n of
|
|
120
|
-
let
|
|
121
|
-
t.set(
|
|
119
|
+
let e = m[0], t = /* @__PURE__ */ new Map();
|
|
120
|
+
for (let n of h) {
|
|
121
|
+
let r = String(n[d] ?? "");
|
|
122
|
+
t.set(r, (t.get(r) ?? 0) + (Number(n[e]) || 0));
|
|
122
123
|
}
|
|
123
|
-
let
|
|
124
|
+
let n = Array.from(t, ([e, t]) => ({
|
|
124
125
|
cat: e,
|
|
125
126
|
value: t
|
|
126
|
-
})),
|
|
127
|
+
})), i = S(n, { value: "value" }), a = r.palette?.length ? r.palette : u;
|
|
127
128
|
return s({
|
|
128
|
-
marks: [
|
|
129
|
-
marks: [
|
|
129
|
+
marks: [C({
|
|
130
|
+
marks: [w(i, {
|
|
130
131
|
startAngle: "startAngle",
|
|
131
132
|
endAngle: "endAngle",
|
|
132
133
|
padAngle: "padAngle",
|
|
@@ -144,79 +145,83 @@ function T(e, t) {
|
|
|
144
145
|
y: null
|
|
145
146
|
},
|
|
146
147
|
color: {
|
|
147
|
-
domain:
|
|
148
|
-
range:
|
|
148
|
+
domain: n.map((e) => e.cat),
|
|
149
|
+
range: a
|
|
149
150
|
}
|
|
150
151
|
});
|
|
151
152
|
}
|
|
152
153
|
case "barHorizontal": return s({
|
|
153
|
-
marks:
|
|
154
|
+
marks: m.map((e, t) => a(h, {
|
|
154
155
|
id: e,
|
|
155
|
-
y:
|
|
156
|
+
y: d,
|
|
156
157
|
x: e,
|
|
157
|
-
fill:
|
|
158
|
+
fill: _(e, t),
|
|
158
159
|
radius: 4
|
|
159
160
|
})),
|
|
160
161
|
scales: {
|
|
161
|
-
y: { scale: () =>
|
|
162
|
+
y: { scale: () => y().padding(.25) },
|
|
162
163
|
x: {
|
|
163
|
-
scale:
|
|
164
|
+
scale: b,
|
|
164
165
|
nice: !0,
|
|
165
166
|
grid: !0
|
|
166
167
|
}
|
|
167
168
|
}
|
|
168
169
|
});
|
|
169
170
|
default: return s({
|
|
170
|
-
marks:
|
|
171
|
+
marks: m.map((e, t) => o(h, {
|
|
171
172
|
id: e,
|
|
172
|
-
x:
|
|
173
|
+
x: d,
|
|
173
174
|
y: e,
|
|
174
|
-
fill:
|
|
175
|
+
fill: _(e, t),
|
|
175
176
|
radius: 4
|
|
176
177
|
})),
|
|
177
178
|
scales: {
|
|
178
|
-
x: { scale: () =>
|
|
179
|
+
x: { scale: () => y().padding(.25) },
|
|
179
180
|
y: {
|
|
180
|
-
scale:
|
|
181
|
+
scale: b,
|
|
181
182
|
nice: !0,
|
|
182
183
|
grid: !0
|
|
183
184
|
}
|
|
184
185
|
}
|
|
185
186
|
});
|
|
186
187
|
}
|
|
187
|
-
}, [
|
|
188
|
+
}, [
|
|
189
|
+
e,
|
|
190
|
+
t,
|
|
191
|
+
n
|
|
192
|
+
]);
|
|
188
193
|
}
|
|
189
|
-
function
|
|
190
|
-
let a =
|
|
194
|
+
function O({ config: e, surfaceColor: t, textColor: n, primaryColor: i }) {
|
|
195
|
+
let a = e.chart, o = g(null), [s, c] = _({
|
|
191
196
|
w: 0,
|
|
192
197
|
h: 0
|
|
193
|
-
});
|
|
194
|
-
if (
|
|
195
|
-
let e =
|
|
198
|
+
}), l = D(e, s.w, i);
|
|
199
|
+
if (m(() => {
|
|
200
|
+
let e = o.current;
|
|
196
201
|
if (!e) return;
|
|
197
202
|
let t = () => {
|
|
198
|
-
let t = e.getBoundingClientRect(), n = t.width && e.offsetWidth ? t.width / e.offsetWidth : 1;
|
|
199
|
-
|
|
200
|
-
w:
|
|
201
|
-
h:
|
|
203
|
+
let t = e.getBoundingClientRect(), n = t.width && e.offsetWidth ? t.width / e.offsetWidth : 1, r = Math.max(1, Math.round(t.width / (n || 1))), i = Math.max(1, Math.round(t.height / (n || 1)));
|
|
204
|
+
c((e) => e.w === r && e.h === i ? e : {
|
|
205
|
+
w: r,
|
|
206
|
+
h: i
|
|
202
207
|
});
|
|
203
208
|
};
|
|
204
209
|
t();
|
|
205
210
|
let n = new ResizeObserver(t);
|
|
206
211
|
return n.observe(e), () => n.disconnect();
|
|
207
|
-
}, []), !
|
|
212
|
+
}, []), !l) return /* @__PURE__ */ v("div", {
|
|
208
213
|
className: "flow-data-empty",
|
|
209
214
|
children: e.columns.length === 0 ? "尚无数据,请在属性面板上传或填写数据" : "请在属性面板选择 X 轴与至少一个数值字段"
|
|
210
215
|
});
|
|
211
|
-
let u =
|
|
212
|
-
return /* @__PURE__ */
|
|
216
|
+
let u = a && a.xField ? `${d(e.columns, a.xField)} · ${(a.yFields ?? []).map((t) => d(e.columns, t)).join(", ")}` : "Chart";
|
|
217
|
+
return /* @__PURE__ */ v("div", {
|
|
213
218
|
className: "flow-data-chart",
|
|
214
|
-
ref:
|
|
219
|
+
ref: o,
|
|
215
220
|
style: n ? { color: n } : void 0,
|
|
216
|
-
children:
|
|
217
|
-
definition:
|
|
221
|
+
children: s.h > 0 && /* @__PURE__ */ v(r, {
|
|
222
|
+
definition: l,
|
|
218
223
|
"aria-label": u,
|
|
219
|
-
height:
|
|
224
|
+
height: s.h,
|
|
220
225
|
style: {
|
|
221
226
|
background: t ?? "transparent",
|
|
222
227
|
borderColor: "transparent",
|
|
@@ -226,18 +231,18 @@ function E({ config: e, surfaceColor: t, textColor: n, primaryColor: i }) {
|
|
|
226
231
|
})
|
|
227
232
|
});
|
|
228
233
|
}
|
|
229
|
-
function
|
|
230
|
-
return !e || e.columns.length === 0 ? /* @__PURE__ */
|
|
234
|
+
function k({ config: e, surfaceColor: t, textColor: n, primaryColor: r }) {
|
|
235
|
+
return !e || e.columns.length === 0 ? /* @__PURE__ */ v("div", {
|
|
231
236
|
className: "flow-data-empty",
|
|
232
237
|
children: "尚无数据,请在属性面板上传或填写数据"
|
|
233
|
-
}) : e.view === "chart" ? /* @__PURE__ */
|
|
238
|
+
}) : e.view === "chart" ? /* @__PURE__ */ v(O, {
|
|
234
239
|
config: e,
|
|
235
240
|
surfaceColor: t,
|
|
236
241
|
textColor: n,
|
|
237
242
|
primaryColor: r
|
|
238
|
-
}) : /* @__PURE__ */
|
|
243
|
+
}) : /* @__PURE__ */ v(T, { config: e });
|
|
239
244
|
}
|
|
240
245
|
//#endregion
|
|
241
|
-
export {
|
|
246
|
+
export { k as DataNodeView, k as default };
|
|
242
247
|
|
|
243
248
|
//# sourceMappingURL=DataNodeView.js.map
|
|
@@ -1 +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, primaryColor?: string) {\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 // Series color resolution order: an explicit per-series override, then a\n // configured chart palette, then the node's own `color` (the drawing's\n // primary color), then the built-in default palette.\n const paletteRange = chart.palette?.length ? chart.palette : null;\n const seriesColor = (field: string, i: number) =>\n chart.seriesColors?.[field]\n ?? paletteRange?.[i % paletteRange.length]\n ?? primaryColor\n ?? DATA_CHART_PALETTE[i % DATA_CHART_PALETTE.length];\n\n switch (chart.type) {\n case 'line':\n return defineChart({\n marks: yFields.map((yf, i) =>\n lineY(rows, { id: yf, x: xField, y: yf, stroke: seriesColor(yf, i), points: true }),\n ),\n scales: {\n x: { scale: () => scalePoint<string>().padding(0.35) },\n y: { scale: scaleLinear, nice: true, grid: true },\n },\n });\n\n case 'area':\n return defineChart({\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 scales: {\n x: { scale: () => scalePoint<string>().padding(0.35) },\n y: { scale: scaleLinear, nice: true, grid: true },\n },\n });\n\n case 'scatter':\n // Scatter uses the first two numeric fields as x/y.\n return defineChart({\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 scales: {\n x: { scale: scaleLinear, nice: true, grid: true },\n y: { scale: scaleLinear, nice: true, grid: true },\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 scales: { angle: null, radius: null },\n }),\n ],\n scales: { x: null, y: null },\n color: { domain: pieRows.map((d) => d.cat), range },\n });\n }\n\n case 'barHorizontal':\n return defineChart({\n marks: yFields.map((yf, i) =>\n barX(rows, { id: yf, y: xField, x: yf, fill: seriesColor(yf, i), radius: 4 }),\n ),\n scales: {\n y: { scale: () => scaleBand<string>().padding(0.25) },\n x: { scale: scaleLinear, nice: true, grid: true },\n },\n });\n\n case 'bar':\n default:\n return defineChart({\n marks: yFields.map((yf, i) =>\n barY(rows, { id: yf, x: xField, y: yf, fill: seriesColor(yf, i), radius: 4 }),\n ),\n scales: {\n x: { scale: () => scaleBand<string>().padding(0.25) },\n y: { scale: scaleLinear, nice: true, grid: true },\n },\n });\n }\n }, [config, primaryColor]);\n}\n\n/** Renders the chart surface of a Data node. */\nfunction DataChartView({ config, surfaceColor, textColor, primaryColor }: { config: FlowDataConfig; surfaceColor?: string; textColor?: string; primaryColor?: string }) {\n const definition = useChartDefinition(config, primaryColor);\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\n className=\"flow-data-chart\"\n ref={wrapRef}\n style={textColor ? ({ color: textColor } as React.CSSProperties) : undefined}\n >\n {size.h > 0 && (\n <Chart\n definition={definition as any}\n aria-label={label}\n height={size.h}\n // Let the media node's fill show through instead of the Chart's\n // default opaque white card, and let axis/label text inherit the\n // node's text color so the chart matches Archify (or any) theming.\n style={{\n background: surfaceColor ?? 'transparent',\n borderColor: 'transparent',\n color: textColor ?? 'inherit',\n padding: 0,\n }}\n />\n )}\n </div>\n );\n}\n\n/** Dispatches to the table or chart surface based on the node's view. */\nexport function DataNodeView({\n config,\n surfaceColor,\n textColor,\n primaryColor,\n}: {\n config: FlowDataConfig;\n surfaceColor?: string;\n textColor?: string;\n primaryColor?: string;\n}) {\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} surfaceColor={surfaceColor} textColor={textColor} primaryColor={primaryColor} />\n ) : (\n <DataTableView config={config} />\n );\n}\n\nexport default DataNodeView;\n"],"mappings":";;;;;;;;;;;;AAwBA,SAAS,EAAc,EAAE,aAAsC;CAC7D,IAAM,IAAU,QAEZ,EAAO,QAAQ,KAAK,MAClB,EAAsC,EAAI,KAAK,EAAI,SAAS,EAAI,KAAK,EACnE,eAAe,GACjB,CAAC,CACH,GACF,CAAC,EAAO,OAAO,CACjB,GAEM,IAAc,QAEhB,EAAO,QAAQ,KAAK,OAAS;EAC3B,OAAO,EAAI;EACX,OAAO,EAAI,SAAS,EAAI;EACxB,SAAS,EAAI,SAAS;CACxB,EAAE,GACJ,CAAC,EAAO,OAAO,CACjB,GAEM,IAAQ,EAAO,OAIf,IAAW,KAAK,UAAU;EAC9B,GAAG,CAAC,CAAC,GAAO;EACZ,GAAG,GAAO,aAAa,CAAC;EACxB,GAAG,GAAO,aAAa,CAAC;EACxB,GAAG,GAAO,UAAU,CAAC;CACvB,CAAC;CAED,OACE,kBAAC,OAAD;EAAK,WAAU;EACb,UAAA,kBAAC,GAAD;GAEU;GACC;GACI;EACd,GAJM,CAIN;CACE,CAAA;AAET;AAEA,SAAS,EAAe,EACtB,WACA,YACA,kBAKC;CACD,IAAM,IAAQ,EAAO,OACf,IAAiB,EAA2C;EAChE,QAAQ;EACR,eAAe,CAAC,CAAC,GAAO;EACxB,kBAAkB,GAAO,aAAa,CAAC;EACvC,kBAAkB,GAAO,aAAa,CAAC;EACvC,eAAgB,GAAO,UAAuC,CAAC;EAC/D,gBAAgB,GAAO,kBAAkB;EACzC,MAAM;EAEN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D;EAAK,WAAU;EACZ,UAAA,EAAO,QAAQ,WAAW,IACvB,uBACA;CACD,CAAA;CAIT,IAAM,IACJ,KAAS,EAAM,SACX,GAAG,EAAS,EAAO,SAAS,EAAM,MAAM,EAAE,MAAM,EAAM,WAAW,CAAC,EAAA,CAC/D,KAAK,MAAM,EAAS,EAAO,SAAS,CAAC,CAAC,CAAC,CACvC,KAAK,IAAI,MACZ;CAEN,OACE,kBAAC,OAAD;EACE,WAAU;EACV,KAAK;EACL,OAAO,IAAa,EAAE,OAAO,EAAU,IAA4B,KAAA;EAElE,UAAA,EAAK,IAAI,KACR,kBAAC,GAAD;GACc;GACZ,cAAY;GACZ,QAAQ,EAAK;GAIb,OAAO;IACL,YAAY,KAAgB;IAC5B,aAAa;IACb,OAAO,KAAa;IACpB,SAAS;GACX;EACD,CAAA;CAEA,CAAA;AAET;AAGA,SAAgB,EAAa,EAC3B,WACA,iBACA,cACA,mBAMC;CAID,OAHI,CAAC,KAAU,EAAO,QAAQ,WAAW,IAChC,kBAAC,OAAD;EAAK,WAAU;EAAkB,UAAA;CAAuB,CAAA,IAE1D,EAAO,SAAS,UACrB,kBAAC,GAAD;EAAuB;EAAsB;EAAyB;EAAyB;CAAe,CAAA,IAE9G,kBAAC,GAAD,EAAuB,UAAS,CAAA;AAEpC"}
|
|
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';\nimport { showLinePoints, withChartGeometryBudget } from './chartGeometryBudget';\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, width: number, primaryColor?: string) {\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 // Series color resolution order: an explicit per-series override, then a\n // configured chart palette, then the node's own `color` (the drawing's\n // primary color), then the built-in default palette.\n const paletteRange = chart.palette?.length ? chart.palette : null;\n const seriesColor = (field: string, i: number) =>\n chart.seriesColors?.[field]\n ?? paletteRange?.[i % paletteRange.length]\n ?? primaryColor\n ?? DATA_CHART_PALETTE[i % DATA_CHART_PALETTE.length];\n\n switch (chart.type) {\n case 'line':\n return defineChart({\n marks: yFields.map((yf, i) =>\n withChartGeometryBudget(lineY(rows, {\n id: yf, x: xField, y: yf, stroke: seriesColor(yf, i),\n points: showLinePoints(rows.length, yFields.length, width),\n })),\n ),\n scales: {\n x: { scale: () => scalePoint<string>().padding(0.35) },\n y: { scale: scaleLinear, nice: true, grid: true },\n },\n });\n\n case 'area':\n return defineChart({\n marks: yFields.map((yf, i) =>\n withChartGeometryBudget(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 scales: {\n x: { scale: () => scalePoint<string>().padding(0.35) },\n y: { scale: scaleLinear, nice: true, grid: true },\n },\n });\n\n case 'scatter':\n // Scatter uses the first two numeric fields as x/y.\n return defineChart({\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 scales: {\n x: { scale: scaleLinear, nice: true, grid: true },\n y: { scale: scaleLinear, nice: true, grid: true },\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 scales: { angle: null, radius: null },\n }),\n ],\n scales: { x: null, y: null },\n color: { domain: pieRows.map((d) => d.cat), range },\n });\n }\n\n case 'barHorizontal':\n return defineChart({\n marks: yFields.map((yf, i) =>\n barX(rows, { id: yf, y: xField, x: yf, fill: seriesColor(yf, i), radius: 4 }),\n ),\n scales: {\n y: { scale: () => scaleBand<string>().padding(0.25) },\n x: { scale: scaleLinear, nice: true, grid: true },\n },\n });\n\n case 'bar':\n default:\n return defineChart({\n marks: yFields.map((yf, i) =>\n barY(rows, { id: yf, x: xField, y: yf, fill: seriesColor(yf, i), radius: 4 }),\n ),\n scales: {\n x: { scale: () => scaleBand<string>().padding(0.25) },\n y: { scale: scaleLinear, nice: true, grid: true },\n },\n });\n }\n }, [config, width, primaryColor]);\n}\n\n/** Renders the chart surface of a Data node. */\nfunction DataChartView({ config, surfaceColor, textColor, primaryColor }: { config: FlowDataConfig; surfaceColor?: string; textColor?: string; primaryColor?: string }) {\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 const definition = useChartDefinition(config, size.w, primaryColor);\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 const w = Math.max(1, Math.round(rect.width / (scale || 1)));\n const h = Math.max(1, Math.round(rect.height / (scale || 1)));\n setSize(previous => previous.w === w && previous.h === h ? previous : { w, h });\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\n className=\"flow-data-chart\"\n ref={wrapRef}\n style={textColor ? ({ color: textColor } as React.CSSProperties) : undefined}\n >\n {size.h > 0 && (\n <Chart\n definition={definition as any}\n aria-label={label}\n height={size.h}\n // Let the media node's fill show through instead of the Chart's\n // default opaque white card, and let axis/label text inherit the\n // node's text color so the chart matches Archify (or any) theming.\n style={{\n background: surfaceColor ?? 'transparent',\n borderColor: 'transparent',\n color: textColor ?? 'inherit',\n padding: 0,\n }}\n />\n )}\n </div>\n );\n}\n\n/** Dispatches to the table or chart surface based on the node's view. */\nexport function DataNodeView({\n config,\n surfaceColor,\n textColor,\n primaryColor,\n}: {\n config: FlowDataConfig;\n surfaceColor?: string;\n textColor?: string;\n primaryColor?: string;\n}) {\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} surfaceColor={surfaceColor} textColor={textColor} primaryColor={primaryColor} />\n ) : (\n <DataTableView config={config} />\n );\n}\n\nexport default DataNodeView;\n"],"mappings":";;;;;;;;;;;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CAC/D,KAAK,MAAM,EAAS,EAAO,SAAS,CAAC,CAAC,CAAC,CACvC,KAAK,IAAI,MACZ;CAEN,OACE,kBAAC,OAAD;EACE,WAAU;EACV,KAAK;EACL,OAAO,IAAa,EAAE,OAAO,EAAU,IAA4B,KAAA;EAElE,UAAA,EAAK,IAAI,KACR,kBAAC,GAAD;GACc;GACZ,cAAY;GACZ,QAAQ,EAAK;GAIb,OAAO;IACL,YAAY,KAAgB;IAC5B,aAAa;IACb,OAAO,KAAa;IACpB,SAAS;GACX;EACD,CAAA;CAEA,CAAA;AAET;AAGA,SAAgB,EAAa,EAC3B,WACA,iBACA,cACA,mBAMC;CAID,OAHI,CAAC,KAAU,EAAO,QAAQ,WAAW,IAChC,kBAAC,OAAD;EAAK,WAAU;EAAkB,UAAA;CAAuB,CAAA,IAE1D,EAAO,SAAS,UACrB,kBAAC,GAAD;EAAuB;EAAsB;EAAyB;EAAyB;CAAe,CAAA,IAE9G,kBAAC,GAAD,EAAuB,UAAS,CAAA;AAEpC"}
|
|
@@ -84,7 +84,7 @@ function y({ content: e, interactive: t, color: n, fontSize: r }) {
|
|
|
84
84
|
title: "html-media",
|
|
85
85
|
className: "flow-media-iframe",
|
|
86
86
|
style: { pointerEvents: t ? "auto" : "none" },
|
|
87
|
-
sandbox: "allow-scripts
|
|
87
|
+
sandbox: "allow-scripts",
|
|
88
88
|
srcDoc: i
|
|
89
89
|
});
|
|
90
90
|
}
|
|
@@ -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\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,WACzB,OAAO,oBAAiB,CAAC,MAAM,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,CACpE,GAEI,IAAe;AACnB,SAAS,IAAgB;CACnB,AAEJ,OADA,EAAQ,WAAW;EAAE,aAAa;EAAO,OAAO;EAAW,eAAe;EAAS,YAAY;CAAU,CAAC,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;GAAS,OAAO;EAAY,CAAA;EAC3D,KAAK,QACH,OAAO,kBAAC,GAAD;GAAmB;GAAS,OAAO;GAAW,UAAU,EAAK,KAAK;EAAW,CAAA;EACtF,KAAK,SACH,OAAO,kBAAC,GAAD,EAAoB,WAAU,CAAA;EACvC,KAAK,WACH,OACE,kBAAC,GAAD;GACW;GACT,QAAQ,EAAK,KAAK,eAAe;GACpB;EACd,CAAA;EAEL,KAAK,MACH,OAAO,kBAAC,GAAD;GAAc;GAAM,QAAQ,EAAK,KAAK;GAAuB;GAAa,OAAO;EAAY,CAAA;EACtG,KAAK,QACH,OACE,kBAAC,OAAD;GAAK,WAAU;GAAkB,OAAO,EAAE,eAAe,IAAc,SAAS,OAAO;GACrF,UAAA,kBAAC,GAAD;IACE,QAAQ,EAAK,KAAK,cAAc;KAAE,SAAS,CAAC;KAAG,MAAM,CAAC;KAAG,MAAM;IAAQ;IACvE,cAAc,EAAK,KAAK,SAAS,gBAAgB,KAAA,IAAY,EAAqB,EAAK,KAAK,MAAM,EAAE;IACzF;IACX,cAAc,EAAqB,EAAK,KAAK,OAAO,EAAE;GACvD,CAAA;EACE,CAAA;EAET,SACE,OAAO;CACX;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.\n * Content is always untrusted: scripts can drive the preview, but the opaque\n * sandbox origin prevents host DOM/storage access. Do not add allow-same-origin\n * alongside allow-scripts; interactive only controls pointer input. */\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\"\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,WACzB,OAAO,oBAAiB,CAAC,MAAM,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,CACpE,GAEI,IAAe;AACnB,SAAS,IAAgB;CACnB,AAEJ,OADA,EAAQ,WAAW;EAAE,aAAa;EAAO,OAAO;EAAW,eAAe;EAAS,YAAY;CAAU,CAAC,GAC3F;AACjB;AAGA,SAAS,EAAY,EAAE,YAAS,YAA8C;CAC5E,IAAM,CAAC,GAAK,KAAU,EAAS,EAAE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EAAK,KAAK;EAAW,CAAA;EACtF,KAAK,SACH,OAAO,kBAAC,GAAD,EAAoB,WAAU,CAAA;EACvC,KAAK,WACH,OACE,kBAAC,GAAD;GACW;GACT,QAAQ,EAAK,KAAK,eAAe;GACpB;EACd,CAAA;EAEL,KAAK,MACH,OAAO,kBAAC,GAAD;GAAc;GAAM,QAAQ,EAAK,KAAK;GAAuB;GAAa,OAAO;EAAY,CAAA;EACtG,KAAK,QACH,OACE,kBAAC,OAAD;GAAK,WAAU;GAAkB,OAAO,EAAE,eAAe,IAAc,SAAS,OAAO;GACrF,UAAA,kBAAC,GAAD;IACE,QAAQ,EAAK,KAAK,cAAc;KAAE,SAAS,CAAC;KAAG,MAAM,CAAC;KAAG,MAAM;IAAQ;IACvE,cAAc,EAAK,KAAK,SAAS,gBAAgB,KAAA,IAAY,EAAqB,EAAK,KAAK,MAAM,EAAE;IACzF;IACX,cAAc,EAAqB,EAAK,KAAK,OAAO,EAAE;GACvD,CAAA;EACE,CAAA;EAET,SACE,OAAO;CACX;AACF"}
|
|
@@ -4,7 +4,7 @@ import { resolveThemeColorCss as n } from "../utils/themeColor.js";
|
|
|
4
4
|
import r, { Suspense as i, useMemo as a } from "react";
|
|
5
5
|
import { jsx as o } from "react/jsx-runtime";
|
|
6
6
|
//#region src/components/pro/Flow/nodes/MediaOverlay.tsx
|
|
7
|
-
var s = r.lazy(() => import("./MediaContent.js").then((e) => ({ default: e.MediaContent }))), c = class extends r.Component {
|
|
7
|
+
var s = r.memo(r.lazy(() => import("./MediaContent.js").then((e) => ({ default: e.MediaContent })))), c = class extends r.Component {
|
|
8
8
|
constructor(e) {
|
|
9
9
|
super(e), this.state = { error: null };
|
|
10
10
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MediaOverlay.js","names":[],"sources":["../../../../../src/components/pro/Flow/nodes/MediaOverlay.tsx"],"sourcesContent":["import React, { useMemo, Suspense } from 'react';\nimport { useFlowContext } from '../context/FlowContext';\nimport { useFlowUI } from '../context/FlowUIContext';\nimport { resolveThemeColorCss } from '../utils/themeColor';\n\n// Lazy-load the media renderers so the heavy optional deps they pull in\n// (react-markdown, mermaid, katex, markmap, …) are only fetched when a media\n// node actually needs to render. This keeps the base `dishui/flow` bundle\n// lightweight and avoids loading that stack for diagrams without media nodes.\nconst MediaContent = React.lazy(() =>\n import('./MediaContent').then((m) => ({ default: m.MediaContent })),\n);\n\n/** Isolates media render/load failures so one bad node never blanks the editor. */\nclass MediaErrorBoundary extends React.Component<\n { children: React.ReactNode },\n { error: Error | null }\n> {\n constructor(props: { children: React.ReactNode }) {\n super(props);\n this.state = { error: null };\n }\n static getDerivedStateFromError(error: Error) {\n return { error };\n }\n render() {\n if (this.state.error) {\n return <div className=\"flow-media-error\">{this.state.error.message}</div>;\n }\n return this.props.children;\n }\n}\n\n/**\n * DOM overlay for media nodes. PixiJS draws the frame; this layer renders the\n * live content (markdown/html/mermaid/math/AI) on top, synced to the viewport\n * so it pans and zooms with the canvas.\n *\n * Event model: a media surface is `pointer-events: none` by default so the\n * canvas underneath can be clicked to select/drag the node's frame. The\n * surface only becomes interactive while its node is selected (so AI chat can\n * be typed into, HTML can be scrolled). This also stops an always-interactive\n * iframe/AI box from swallowing pointer gestures and leaving the drag stuck.\n */\nexport function MediaOverlay() {\n const { currentCanvas, selection } = useFlowContext();\n const { viewport, isNodeDragging } = useFlowUI();\n\n const mediaNodes = useMemo(\n () => currentCanvas.nodes.filter((n) => n.type === 'mediaNode'),\n [currentCanvas.nodes],\n );\n\n if (mediaNodes.length === 0) return null;\n\n const { x: vx, y: vy, zoom } = viewport;\n\n return (\n <div className=\"flow-media-layer\">\n {mediaNodes.map((node) => {\n // World → screen (CSS px, matching ViewportManager.worldToScreen).\n const left = node.position.x * zoom + vx;\n const top = node.position.y * zoom + vy;\n // Interactive only while selected, so the canvas stays draggable.\n // Suppress entirely during a drag: an interactive iframe would swallow\n // the pointer and the canvas would never receive pointerup (stuck drag).\n const interactive = selection.nodeIds.has(node.id) && !isNodeDragging;\n // Drive the overlay's background / text from the node's own color data.\n // Theme tokens (`theme:*`) resolve to CSS variables so the media content\n // follows theme switches natively; literal colors are used as-is. This\n // keeps html / ai / data (which render opaque content) in sync with the\n // fill/color chosen in the inspector, matching the PixiJS frame drawn\n // underneath. The border is owned by the Pixi frame (also what PNG/PDF\n // export captures), so we don't redraw it here.\n const fillCss = node.data.fill === 'transparent'\n ? 'transparent'\n : resolveThemeColorCss(node.data.fill, 'transparent');\n const textColor = resolveThemeColorCss(node.data.labelColor ?? node.data.color, '#111827');\n return (\n <div\n key={node.id}\n className=\"flow-media-node\"\n data-media-node={node.id}\n style={{\n position: 'absolute',\n left,\n top,\n width: node.width,\n height: node.height,\n // Scale the fixed-size content box to match zoom without\n // reflowing text on every zoom step.\n transform: `scale(${zoom})`,\n transformOrigin: 'top left',\n // Below the frame's selection outline but above the canvas.\n pointerEvents: 'none',\n }}\n >\n <div\n className=\"flow-media-surface\"\n onWheel={(e) => e.stopPropagation()}\n style={{\n background: fillCss,\n color: textColor,\n }}\n >\n <Suspense fallback={<div className=\"flow-media-loading\">…</div>}>\n <MediaErrorBoundary>\n <MediaContent node={node} interactive={interactive} />\n </MediaErrorBoundary>\n </Suspense>\n </div>\n </div>\n );\n })}\n </div>\n );\n}\n"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"MediaOverlay.js","names":[],"sources":["../../../../../src/components/pro/Flow/nodes/MediaOverlay.tsx"],"sourcesContent":["import React, { useMemo, Suspense } from 'react';\nimport { useFlowContext } from '../context/FlowContext';\nimport { useFlowUI } from '../context/FlowUIContext';\nimport { resolveThemeColorCss } from '../utils/themeColor';\n\n// Lazy-load the media renderers so the heavy optional deps they pull in\n// (react-markdown, mermaid, katex, markmap, …) are only fetched when a media\n// node actually needs to render. This keeps the base `dishui/flow` bundle\n// lightweight and avoids loading that stack for diagrams without media nodes.\n// Viewport-only updates move the outer box, not the live media subtree. Keep\n// nodes mounted offscreen so iframe/AI state and model camera state survive.\nconst MediaContent = React.memo(React.lazy(() =>\n import('./MediaContent').then((m) => ({ default: m.MediaContent })),\n));\n\n/** Isolates media render/load failures so one bad node never blanks the editor. */\nclass MediaErrorBoundary extends React.Component<\n { children: React.ReactNode },\n { error: Error | null }\n> {\n constructor(props: { children: React.ReactNode }) {\n super(props);\n this.state = { error: null };\n }\n static getDerivedStateFromError(error: Error) {\n return { error };\n }\n render() {\n if (this.state.error) {\n return <div className=\"flow-media-error\">{this.state.error.message}</div>;\n }\n return this.props.children;\n }\n}\n\n/**\n * DOM overlay for media nodes. PixiJS draws the frame; this layer renders the\n * live content (markdown/html/mermaid/math/AI) on top, synced to the viewport\n * so it pans and zooms with the canvas.\n *\n * Event model: a media surface is `pointer-events: none` by default so the\n * canvas underneath can be clicked to select/drag the node's frame. The\n * surface only becomes interactive while its node is selected (so AI chat can\n * be typed into, HTML can be scrolled). This also stops an always-interactive\n * iframe/AI box from swallowing pointer gestures and leaving the drag stuck.\n */\nexport function MediaOverlay() {\n const { currentCanvas, selection } = useFlowContext();\n const { viewport, isNodeDragging } = useFlowUI();\n\n const mediaNodes = useMemo(\n () => currentCanvas.nodes.filter((n) => n.type === 'mediaNode'),\n [currentCanvas.nodes],\n );\n\n if (mediaNodes.length === 0) return null;\n\n const { x: vx, y: vy, zoom } = viewport;\n\n return (\n <div className=\"flow-media-layer\">\n {mediaNodes.map((node) => {\n // World → screen (CSS px, matching ViewportManager.worldToScreen).\n const left = node.position.x * zoom + vx;\n const top = node.position.y * zoom + vy;\n // Interactive only while selected, so the canvas stays draggable.\n // Suppress entirely during a drag: an interactive iframe would swallow\n // the pointer and the canvas would never receive pointerup (stuck drag).\n const interactive = selection.nodeIds.has(node.id) && !isNodeDragging;\n // Drive the overlay's background / text from the node's own color data.\n // Theme tokens (`theme:*`) resolve to CSS variables so the media content\n // follows theme switches natively; literal colors are used as-is. This\n // keeps html / ai / data (which render opaque content) in sync with the\n // fill/color chosen in the inspector, matching the PixiJS frame drawn\n // underneath. The border is owned by the Pixi frame (also what PNG/PDF\n // export captures), so we don't redraw it here.\n const fillCss = node.data.fill === 'transparent'\n ? 'transparent'\n : resolveThemeColorCss(node.data.fill, 'transparent');\n const textColor = resolveThemeColorCss(node.data.labelColor ?? node.data.color, '#111827');\n return (\n <div\n key={node.id}\n className=\"flow-media-node\"\n data-media-node={node.id}\n style={{\n position: 'absolute',\n left,\n top,\n width: node.width,\n height: node.height,\n // Scale the fixed-size content box to match zoom without\n // reflowing text on every zoom step.\n transform: `scale(${zoom})`,\n transformOrigin: 'top left',\n // Below the frame's selection outline but above the canvas.\n pointerEvents: 'none',\n }}\n >\n <div\n className=\"flow-media-surface\"\n onWheel={(e) => e.stopPropagation()}\n style={{\n background: fillCss,\n color: textColor,\n }}\n >\n <Suspense fallback={<div className=\"flow-media-loading\">…</div>}>\n <MediaErrorBoundary>\n <MediaContent node={node} interactive={interactive} />\n </MediaErrorBoundary>\n </Suspense>\n </div>\n </div>\n );\n })}\n </div>\n );\n}\n"],"mappings":";;;;;;AAWA,IAAM,IAAe,EAAM,KAAK,EAAM,WACpC,OAAO,oBAAiB,CAAC,MAAM,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,CACpE,CAAC,GAGK,IAAN,cAAiC,EAAM,UAGrC;CACA,YAAY,GAAsC;EAEhD,AADA,MAAM,CAAK,GACX,KAAK,QAAQ,EAAE,OAAO,KAAK;CAC7B;CACA,OAAO,yBAAyB,GAAc;EAC5C,OAAO,EAAE,SAAM;CACjB;CACA,SAAS;EAIP,OAHI,KAAK,MAAM,QACN,kBAAC,OAAD;GAAK,WAAU;GAAoB,UAAA,KAAK,MAAM,MAAM;EAAa,CAAA,IAEnE,KAAK,MAAM;CACpB;AACF;AAaA,SAAgB,IAAe;CAC7B,IAAM,EAAE,kBAAe,iBAAc,EAAe,GAC9C,EAAE,aAAU,sBAAmB,EAAU,GAEzC,IAAa,QACX,EAAc,MAAM,QAAQ,MAAM,EAAE,SAAS,WAAW,GAC9D,CAAC,EAAc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