dishui 0.0.83 → 0.0.89
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/Demo/index.js +2 -2
- package/dist/components/Demo/index.js.map +1 -1
- 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/Page/index.d.ts +18 -4
- package/dist/components/Page/index.js +47 -35
- package/dist/components/Page/index.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/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/Text/index.d.ts +1 -1
- package/dist/components/Text/index.js +2 -2
- package/dist/components/Text/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 +98 -240
- package/dist/components/pro/DataTable/DataTable.js.map +1 -1
- package/dist/components/pro/DataTable/components/TableBody.js +14 -16
- 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/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 +24 -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/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 +2 -2
- package/dist/index.js +97 -97
- package/dist/layouts/Sidebar.d.ts +3 -1
- package/dist/layouts/Sidebar.js +131 -122
- package/dist/layouts/Sidebar.js.map +1 -1
- 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
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { builtInSortFns as e, useReactTable as t } from "./tanstack-table.js";
|
|
2
|
+
import { createTreeSortingFns as n, findAllChildRowIds as r, prepareTreeData as i } from "./treeDataUtils.js";
|
|
3
|
+
import { deepEqual as a, useControllableState as o } from "../../../hooks/useControllableState.js";
|
|
4
|
+
import { useCallback as s, useEffect as c, useLayoutEffect as l, useMemo as u, useRef as d } from "react";
|
|
5
|
+
//#region src/components/pro/DataTable/useDataTableModel.ts
|
|
6
|
+
function f(e, t, n = 0) {
|
|
7
|
+
if (!Number.isSafeInteger(t) || t < n) throw RangeError(`DataTable: ${e} must be an integer >= ${n}.`);
|
|
8
|
+
}
|
|
9
|
+
function p(p) {
|
|
10
|
+
let { data: m, columns: h, getRowId: g, subDataKey: _ = "subs", enableExpanding: v = !1, enableTreeSort: y = !0, enablePagination: b = !0, manualPagination: x = !1, enableSorting: S = !0, enableFiltering: C = !0, enableSelection: w = !0, manualSorting: T = !1, manualFiltering: E = !1, rowCount: D, pageCount: O } = p, [k, A] = o(p.sortingState, p.onSortingChange, a, p.defaultSortingState ?? []), [j, M] = o(p.selectedRows, p.onRowSelectionChange, a, p.defaultSelectedRows ?? {}), [N, P] = o(p.columnFilters, p.onColumnFiltersChange, a, p.defaultColumnFilters ?? []), [F, I] = o(p.columnVisibility, p.onColumnVisibilityChange, a, p.defaultColumnVisibility ?? {}), [L, R] = o(p.columnOrder, p.onColumnOrderChange, a, p.defaultColumnOrder ?? []), [z, B] = o(p.expandedRows, p.onExpandedRowsChange, a, p.defaultExpandedRows ?? {}), [V, H] = o(p.pageIndex, p.onPageChange, Object.is, p.defaultPageIndex ?? 0), [U, W] = o(p.pageSize, p.onPageSizeChange, Object.is, p.defaultPageSize ?? 10);
|
|
11
|
+
if (f("pageIndex", V), f("pageSize", U, 1), x && (D !== void 0 && f("rowCount", D), O !== void 0 && f("pageCount", O), b && D === void 0 && O === void 0)) throw Error("DataTable: manualPagination requires rowCount or pageCount.");
|
|
12
|
+
let G = u(() => v ? i(m, z, _, g) : m, [
|
|
13
|
+
m,
|
|
14
|
+
v,
|
|
15
|
+
z,
|
|
16
|
+
_,
|
|
17
|
+
g
|
|
18
|
+
]), K = u(() => {
|
|
19
|
+
if (!v || !y) return h;
|
|
20
|
+
let t = n().treeSortAsc, r = (n) => n.map((n) => {
|
|
21
|
+
if ("columns" in n) return {
|
|
22
|
+
...n,
|
|
23
|
+
columns: r(n.columns ?? [])
|
|
24
|
+
};
|
|
25
|
+
if (n.enableSorting === !1) return n;
|
|
26
|
+
let i = n.sortFn, a = typeof i == "function" ? i : i && i !== "auto" ? e[i] : t;
|
|
27
|
+
return {
|
|
28
|
+
...n,
|
|
29
|
+
sortUndefined: !1,
|
|
30
|
+
sortFn: (e, n, r) => e.depth > 0 || n.depth > 0 ? 0 : (a ?? t)(e, n, r)
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
return r(h);
|
|
34
|
+
}, [
|
|
35
|
+
h,
|
|
36
|
+
v,
|
|
37
|
+
y
|
|
38
|
+
]), q = {
|
|
39
|
+
pageIndex: V,
|
|
40
|
+
pageSize: U
|
|
41
|
+
}, J = d(q);
|
|
42
|
+
l(() => {
|
|
43
|
+
J.current = q;
|
|
44
|
+
});
|
|
45
|
+
let Y = s((e) => {
|
|
46
|
+
let t = J.current, n = typeof e == "function" ? e(t) : e;
|
|
47
|
+
f("pageIndex", n.pageIndex), f("pageSize", n.pageSize, 1), J.current = {
|
|
48
|
+
pageIndex: p.pageIndex === void 0 ? n.pageIndex : t.pageIndex,
|
|
49
|
+
pageSize: p.pageSize === void 0 ? n.pageSize : t.pageSize
|
|
50
|
+
}, W(n.pageSize), H(n.pageIndex);
|
|
51
|
+
}, [
|
|
52
|
+
p.pageIndex,
|
|
53
|
+
p.pageSize,
|
|
54
|
+
H,
|
|
55
|
+
W
|
|
56
|
+
]), X = t({
|
|
57
|
+
data: G,
|
|
58
|
+
columns: K,
|
|
59
|
+
getRowId: (e, t) => v ? String(e.__id) : g?.(e, t) ?? String(t),
|
|
60
|
+
getSubRows: v ? (e) => e[_] : void 0,
|
|
61
|
+
manualPagination: x || !b,
|
|
62
|
+
manualSorting: x || T || !S,
|
|
63
|
+
manualFiltering: x || E || !C,
|
|
64
|
+
pageCount: x ? O : void 0,
|
|
65
|
+
rowCount: x ? D : void 0,
|
|
66
|
+
paginateExpandedRows: !1,
|
|
67
|
+
maxLeafRowFilterDepth: v ? 0 : void 0,
|
|
68
|
+
enableSorting: S,
|
|
69
|
+
enableFilters: C,
|
|
70
|
+
enableRowSelection: w,
|
|
71
|
+
enableSubRowSelection: !1,
|
|
72
|
+
autoResetPageIndex: !1,
|
|
73
|
+
autoResetExpanded: !1,
|
|
74
|
+
state: {
|
|
75
|
+
sorting: k,
|
|
76
|
+
rowSelection: j,
|
|
77
|
+
columnFilters: N,
|
|
78
|
+
columnVisibility: F,
|
|
79
|
+
columnOrder: L,
|
|
80
|
+
expanded: z,
|
|
81
|
+
pagination: {
|
|
82
|
+
pageIndex: V,
|
|
83
|
+
pageSize: U
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
onSortingChange: A,
|
|
87
|
+
onRowSelectionChange: M,
|
|
88
|
+
onColumnFiltersChange: P,
|
|
89
|
+
onColumnVisibilityChange: I,
|
|
90
|
+
onColumnOrderChange: R,
|
|
91
|
+
onExpandedChange: (e) => B((t) => {
|
|
92
|
+
let n = typeof e == "function" ? e(t) : e;
|
|
93
|
+
return n === !0 ? Object.fromEntries(X.getCoreRowModel().flatRows.map((e) => [e.id, !0])) : n;
|
|
94
|
+
}),
|
|
95
|
+
onPaginationChange: Y
|
|
96
|
+
}), Z = X.getPageCount(), Q = d({
|
|
97
|
+
sorting: k,
|
|
98
|
+
columnFilters: N,
|
|
99
|
+
size: U
|
|
100
|
+
});
|
|
101
|
+
c(() => {
|
|
102
|
+
let e = Q.current;
|
|
103
|
+
Q.current = {
|
|
104
|
+
sorting: k,
|
|
105
|
+
columnFilters: N,
|
|
106
|
+
size: U
|
|
107
|
+
}, b && !x && p.pageIndex === void 0 && (!a(e.sorting, k) || !a(e.columnFilters, N) || e.size !== U ? H(0) : V >= Z && H(Math.max(0, Z - 1)));
|
|
108
|
+
}, [
|
|
109
|
+
k,
|
|
110
|
+
N,
|
|
111
|
+
U,
|
|
112
|
+
V,
|
|
113
|
+
Z,
|
|
114
|
+
b,
|
|
115
|
+
x,
|
|
116
|
+
p.pageIndex,
|
|
117
|
+
H
|
|
118
|
+
]);
|
|
119
|
+
let $ = (e, t) => {
|
|
120
|
+
let n = !z[e];
|
|
121
|
+
B((i) => {
|
|
122
|
+
let a = {
|
|
123
|
+
...i,
|
|
124
|
+
[e]: n
|
|
125
|
+
};
|
|
126
|
+
return n || r(t, e, _, g).forEach((e) => {
|
|
127
|
+
a[e] = !1;
|
|
128
|
+
}), a;
|
|
129
|
+
}), p.onRowExpand?.(t, n);
|
|
130
|
+
}, ee = new Map(X.getCoreRowModel().flatRows.map((e) => [e.original, e.id]));
|
|
131
|
+
return {
|
|
132
|
+
table: X,
|
|
133
|
+
rowSelection: j,
|
|
134
|
+
visibilityState: F,
|
|
135
|
+
columnOrderState: X.getAllLeafColumns().map((e) => e.id),
|
|
136
|
+
setColumnOrderState: R,
|
|
137
|
+
expandedRowsState: z,
|
|
138
|
+
handleRowExpand: $,
|
|
139
|
+
resolveRowId: (e, t) => ee.get(e) ?? g?.(e, t) ?? String(t),
|
|
140
|
+
internalPageIndex: V,
|
|
141
|
+
internalPageSize: U,
|
|
142
|
+
handlePaginationChange: Y
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
//#endregion
|
|
146
|
+
export { p as useDataTableModel };
|
|
147
|
+
|
|
148
|
+
//# sourceMappingURL=useDataTableModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDataTableModel.js","names":[],"sources":["../../../../src/components/pro/DataTable/useDataTableModel.ts"],"sourcesContent":["import { useCallback, useEffect, useLayoutEffect, useMemo, useRef } from 'react';\nimport { useControllableState, deepEqual } from '../../../hooks/useControllableState';\nimport {\n useReactTable, builtInSortFns,\n type ColumnDef, type SortingFn, type PaginationState, type Updater,\n} from './tanstack-table';\nimport type { DataTableProps } from './types';\nimport { createTreeSortingFns, findAllChildRowIds, prepareTreeData } from './treeDataUtils';\n\nfunction assertInteger(name: string, value: number, minimum = 0) {\n if (!Number.isSafeInteger(value) || value < minimum) {\n throw new RangeError(`DataTable: ${name} must be an integer >= ${minimum}.`);\n }\n}\n\n/** Shared by the view and executable row-model regression tests. */\nexport function useDataTableModel<T extends object>(props: DataTableProps<T>) {\n const {\n data, columns, getRowId, subDataKey = 'subs', enableExpanding = false,\n enableTreeSort = true, enablePagination = true, manualPagination = false,\n enableSorting = true, enableFiltering = true, enableSelection = true,\n manualSorting = false, manualFiltering = false, rowCount, pageCount,\n } = props;\n const [sorting, setSorting] = useControllableState(\n props.sortingState, props.onSortingChange, deepEqual, props.defaultSortingState ?? [],\n );\n const [rowSelection, setRowSelection] = useControllableState(\n props.selectedRows, props.onRowSelectionChange, deepEqual, props.defaultSelectedRows ?? {},\n );\n const [columnFilters, setColumnFilters] = useControllableState(\n props.columnFilters, props.onColumnFiltersChange, deepEqual, props.defaultColumnFilters ?? [],\n );\n const [visibilityState, setVisibilityState] = useControllableState(\n props.columnVisibility, props.onColumnVisibilityChange, deepEqual, props.defaultColumnVisibility ?? {},\n );\n const [columnOrder, setColumnOrderState] = useControllableState(\n props.columnOrder, props.onColumnOrderChange, deepEqual, props.defaultColumnOrder ?? [],\n );\n const [expandedRowsState, setExpandedRowsState] = useControllableState(\n props.expandedRows, props.onExpandedRowsChange, deepEqual, props.defaultExpandedRows ?? {},\n );\n const [internalPageIndex, setInternalPageIndex] = useControllableState(\n props.pageIndex, props.onPageChange, Object.is, props.defaultPageIndex ?? 0,\n );\n const [internalPageSize, setInternalPageSize] = useControllableState(\n props.pageSize, props.onPageSizeChange, Object.is, props.defaultPageSize ?? 10,\n );\n assertInteger('pageIndex', internalPageIndex);\n assertInteger('pageSize', internalPageSize, 1);\n if (manualPagination) {\n if (rowCount !== undefined) assertInteger('rowCount', rowCount);\n if (pageCount !== undefined) assertInteger('pageCount', pageCount);\n if (enablePagination && rowCount === undefined && pageCount === undefined) {\n throw new Error('DataTable: manualPagination requires rowCount or pageCount.');\n }\n }\n\n const tableData = useMemo(() => enableExpanding\n ? prepareTreeData(data, expandedRowsState, subDataKey, getRowId)\n : data, [data, enableExpanding, expandedRowsState, subDataKey, getRowId]);\n\n const processedColumns = useMemo(() => {\n if (!enableExpanding || !enableTreeSort) return columns;\n const defaultSort = createTreeSortingFns<T>().treeSortAsc;\n const wrap = (defs: readonly ColumnDef<T, any>[]): ColumnDef<T, any>[] => defs.map(column => {\n if ('columns' in column) return { ...column, columns: wrap(column.columns ?? []) };\n if (column.enableSorting === false) return column;\n const originalSort = column.sortFn;\n const sort = typeof originalSort === 'function' ? originalSort\n : originalSort && originalSort !== 'auto'\n ? builtInSortFns[originalSort as keyof typeof builtInSortFns] as SortingFn<T>\n : defaultSort;\n return {\n ...column,\n // TanStack handles undefined before invoking sortFn. Disable that shortcut\n // so an undefined child value cannot reorder an otherwise unsorted subtree.\n sortUndefined: false,\n sortFn: (a, b, id) => a.depth > 0 || b.depth > 0 ? 0 : (sort ?? defaultSort)(a, b, id),\n };\n });\n return wrap(columns);\n }, [columns, enableExpanding, enableTreeSort]);\n\n const pagination = { pageIndex: internalPageIndex, pageSize: internalPageSize };\n const paginationRef = useRef(pagination);\n useLayoutEffect(() => { paginationRef.current = pagination; });\n const handlePaginationChange = useCallback((updater: Updater<PaginationState>) => {\n const current = paginationRef.current;\n const next = typeof updater === 'function' ? updater(current) : updater;\n assertInteger('pageIndex', next.pageIndex);\n assertInteger('pageSize', next.pageSize, 1);\n // Preserve pending uncontrolled slices across batched TanStack updaters,\n // while controlled slices continue to use the parent's committed values.\n paginationRef.current = {\n pageIndex: props.pageIndex === undefined ? next.pageIndex : current.pageIndex,\n pageSize: props.pageSize === undefined ? next.pageSize : current.pageSize,\n };\n setInternalPageSize(next.pageSize);\n setInternalPageIndex(next.pageIndex);\n }, [props.pageIndex, props.pageSize, setInternalPageIndex, setInternalPageSize]);\n\n const table = useReactTable<T>({\n data: tableData,\n columns: processedColumns,\n getRowId: (row, index) => enableExpanding\n ? String((row as Record<string, unknown>).__id)\n : getRowId?.(row, index) ?? String(index),\n getSubRows: enableExpanding\n ? row => (row as Record<string, unknown>)[subDataKey] as T[]\n : undefined,\n // Local pipeline sees the full hierarchy. Only server mode bypasses all\n // processing; hiding pagination alone still permits local sort/filter.\n manualPagination: manualPagination || !enablePagination,\n manualSorting: manualPagination || manualSorting || !enableSorting,\n manualFiltering: manualPagination || manualFiltering || !enableFiltering,\n pageCount: manualPagination ? pageCount : undefined,\n rowCount: manualPagination ? rowCount : undefined,\n paginateExpandedRows: false,\n maxLeafRowFilterDepth: enableExpanding ? 0 : undefined,\n enableSorting,\n enableFilters: enableFiltering,\n enableRowSelection: enableSelection,\n enableSubRowSelection: false,\n autoResetPageIndex: false,\n autoResetExpanded: false,\n state: {\n sorting, rowSelection, columnFilters, columnVisibility: visibilityState,\n columnOrder, expanded: expandedRowsState,\n pagination: { pageIndex: internalPageIndex, pageSize: internalPageSize },\n },\n onSortingChange: setSorting,\n onRowSelectionChange: setRowSelection,\n onColumnFiltersChange: setColumnFilters,\n onColumnVisibilityChange: setVisibilityState,\n onColumnOrderChange: setColumnOrderState,\n onExpandedChange: updater => setExpandedRowsState(previous => {\n const next = typeof updater === 'function' ? updater(previous) : updater;\n return next === true\n ? Object.fromEntries(table.getCoreRowModel().flatRows.map(row => [row.id, true]))\n : next;\n }),\n onPaginationChange: handlePaginationChange,\n });\n\n const localPageCount = table.getPageCount();\n const previousQuery = useRef({ sorting, columnFilters, size: internalPageSize });\n useEffect(() => {\n const previous = previousQuery.current;\n previousQuery.current = { sorting, columnFilters, size: internalPageSize };\n // Never rewrite a controlled page or a server request. Their owner must\n // reset/clamp the page along with the query and remote total.\n if (!enablePagination || manualPagination || props.pageIndex !== undefined) return;\n if (!deepEqual(previous.sorting, sorting) || !deepEqual(previous.columnFilters, columnFilters)\n || previous.size !== internalPageSize) {\n setInternalPageIndex(0);\n } else if (internalPageIndex >= localPageCount) {\n setInternalPageIndex(Math.max(0, localPageCount - 1));\n }\n }, [sorting, columnFilters, internalPageSize, internalPageIndex, localPageCount,\n enablePagination, manualPagination, props.pageIndex, setInternalPageIndex]);\n\n const handleRowExpand = (rowId: string, row: T) => {\n const expanded = !expandedRowsState[rowId];\n setExpandedRowsState(previous => {\n const next = { ...previous, [rowId]: expanded };\n if (!expanded) {\n findAllChildRowIds(row, rowId, subDataKey, getRowId).forEach(id => { next[id] = false; });\n }\n return next;\n });\n props.onRowExpand?.(row, expanded);\n };\n\n // TanStack owns mutable row models; snapshot IDs per render rather than\n // caching by flatRows identity, which does not guarantee unchanged contents.\n const rowIds = new Map(table.getCoreRowModel().flatRows.map(row => [row.original, row.id]));\n const resolveRowId = (row: T, index: number) =>\n rowIds.get(row) ?? getRowId?.(row, index) ?? String(index);\n\n // Derive the default order instead of notifying the parent on mount.\n const columnOrderState = table.getAllLeafColumns().map(column => column.id);\n return {\n table, rowSelection, visibilityState, columnOrderState, setColumnOrderState,\n expandedRowsState, handleRowExpand, resolveRowId,\n internalPageIndex, internalPageSize, handlePaginationChange,\n };\n}\n"],"mappings":";;;;;AASA,SAAS,EAAc,GAAc,GAAe,IAAU,GAAG;CAC/D,IAAI,CAAC,OAAO,cAAc,CAAK,KAAK,IAAQ,GAC1C,MAAU,WAAW,cAAc,EAAK,yBAAyB,EAAQ,EAAE;AAE/E;AAGA,SAAgB,EAAoC,GAA0B;CAC5E,IAAM,EACJ,SAAM,YAAS,aAAU,gBAAa,QAAQ,qBAAkB,IAChE,oBAAiB,IAAM,sBAAmB,IAAM,sBAAmB,IACnE,mBAAgB,IAAM,qBAAkB,IAAM,qBAAkB,IAChE,mBAAgB,IAAO,qBAAkB,IAAO,aAAU,iBACxD,GACE,CAAC,GAAS,KAAc,EAC5B,EAAM,cAAc,EAAM,iBAAiB,GAAW,EAAM,uBAAuB,CAAC,CACtF,GACM,CAAC,GAAc,KAAmB,EACtC,EAAM,cAAc,EAAM,sBAAsB,GAAW,EAAM,uBAAuB,CAAC,CAC3F,GACM,CAAC,GAAe,KAAoB,EACxC,EAAM,eAAe,EAAM,uBAAuB,GAAW,EAAM,wBAAwB,CAAC,CAC9F,GACM,CAAC,GAAiB,K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I,EAAE,CAAC,CAAC;CAM1F,OAAO;EACL;EAAO;EAAc;EAAiB,kBAFf,EAAM,kBAAkB,CAAC,CAAC,KAAI,MAAU,EAAO,EAEhC;EAAkB;EACxD;EAAmB;EAAiB,eAPhB,GAAQ,MAC5B,GAAO,IAAI,CAAG,KAAK,IAAW,GAAK,CAAK,KAAK,OAAO,CAAK;EAOzD;EAAmB;EAAkB;CACvC;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import t from "
|
|
1
|
+
import e from "../../Tree/Tree.js";
|
|
2
|
+
import { useClickOutside as t } from "../../../hooks/useClickOutside.js";
|
|
3
3
|
import n, { useCallback as r, useEffect as i, useRef as a, useState as o } from "react";
|
|
4
4
|
import { jsx as s, jsxs as c } from "react/jsx-runtime";
|
|
5
5
|
//#region src/components/pro/FileExplorer/Breadcrumb.tsx
|
|
@@ -43,7 +43,7 @@ var l = { root: "Root" }, u = () => /* @__PURE__ */ s("svg", {
|
|
|
43
43
|
d: "M4 4a2 2 0 012-2h4.586A2 2 0 0112 2.586L15.414 6A2 2 0 0116 7.414V16a2 2 0 01-2 2H6a2 2 0 01-2-2V4zm2 6a1 1 0 011-1h6a1 1 0 110 2H7a1 1 0 01-1-1zm1 3a1 1 0 100 2h6a1 1 0 100-2H7z",
|
|
44
44
|
clipRule: "evenodd"
|
|
45
45
|
})
|
|
46
|
-
}), m = ({ path:
|
|
46
|
+
}), m = ({ path: t, adapter: n, onNavigate: a }) => {
|
|
47
47
|
let [c, l] = o([]), [u, d] = o(!1), m = r(async (e) => {
|
|
48
48
|
try {
|
|
49
49
|
return (await n.list(e)).sort((e, t) => e.type === t.type ? String(e.name).localeCompare(String(t.name)) : e.type === "folder" ? -1 : 1).map((e) => ({
|
|
@@ -61,13 +61,13 @@ var l = { root: "Root" }, u = () => /* @__PURE__ */ s("svg", {
|
|
|
61
61
|
}
|
|
62
62
|
}, [n]);
|
|
63
63
|
i(() => {
|
|
64
|
-
let
|
|
65
|
-
return d(!0), m(
|
|
66
|
-
|
|
64
|
+
let e = !0;
|
|
65
|
+
return d(!0), m(t).then((t) => {
|
|
66
|
+
e && (l(t), d(!1));
|
|
67
67
|
}), () => {
|
|
68
|
-
|
|
68
|
+
e = !1;
|
|
69
69
|
};
|
|
70
|
-
}, [
|
|
70
|
+
}, [t, m]);
|
|
71
71
|
let h = r(async (e, t) => {
|
|
72
72
|
if (!t) return;
|
|
73
73
|
let n = String(e), r = (e, t) => {
|
|
@@ -104,7 +104,7 @@ var l = { root: "Root" }, u = () => /* @__PURE__ */ s("svg", {
|
|
|
104
104
|
children: "Empty Folder"
|
|
105
105
|
}) : /* @__PURE__ */ s("div", {
|
|
106
106
|
className: "p-1 w-64 max-h-[300px] overflow-y-auto sm:min-w-[200px] max-w-[80vw]",
|
|
107
|
-
children: /* @__PURE__ */ s(
|
|
107
|
+
children: /* @__PURE__ */ s(e, {
|
|
108
108
|
data: c,
|
|
109
109
|
onNodeClick: g,
|
|
110
110
|
onNodeToggle: h,
|
|
@@ -117,9 +117,9 @@ var l = { root: "Root" }, u = () => /* @__PURE__ */ s("svg", {
|
|
|
117
117
|
indent: 12
|
|
118
118
|
})
|
|
119
119
|
});
|
|
120
|
-
}, h = ({ path:
|
|
120
|
+
}, h = ({ path: e, adapter: n, onNavigate: r }) => {
|
|
121
121
|
let [i, l] = o(!1), u = a(null);
|
|
122
|
-
return
|
|
122
|
+
return t(u, () => l(!1), i), /* @__PURE__ */ c("div", {
|
|
123
123
|
className: "relative flex items-center",
|
|
124
124
|
ref: u,
|
|
125
125
|
children: [n ? /* @__PURE__ */ s("button", {
|
|
@@ -135,7 +135,7 @@ var l = { root: "Root" }, u = () => /* @__PURE__ */ s("svg", {
|
|
|
135
135
|
className: "absolute top-full left-1/2 -translate-x-1/2 mt-1 bg-base-100 shadow-2xl border border-base-200 rounded-xl z-[9999]",
|
|
136
136
|
onClick: (e) => e.stopPropagation(),
|
|
137
137
|
children: /* @__PURE__ */ s(m, {
|
|
138
|
-
path:
|
|
138
|
+
path: e,
|
|
139
139
|
adapter: n,
|
|
140
140
|
onNavigate: (e) => {
|
|
141
141
|
r(e), l(!1);
|
|
@@ -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;AA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AM,EAAK,SAAS,KAAS,EAAE,CAAC;IACpD,GAAG,KAAK,IAAI,GAAG,KAAK,MAAM,EAAK,UAAU,KAAS,EAAE,CAAC;GACvD,CAAC;EACH;EACA,EAAQ;EACR,IAAM,IAAK,IAAI,eAAe,CAAO;EAErC,OADA,EAAG,QAAQ,CAAE,SACA,EAAG,WAAW;CAC7B,GAAG,CAAC,CAAC,GAED,CAAC,GACH,OACE,kBAAC,OAAD;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":";;;;;;;;;;;;;AAyBA,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,gBAAgB;CAClB,CAAC;CAED,OACE,kBAAC,GAAD;EACE,MAAM,EA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OADA,EAAG,QAAQ,CAAE,SACA,EAAG,WAAW;CAC7B,GAAG,CAAC,CAAC,GAED,CAAC,GACH,OACE,kBAAC,OAAD;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"}
|
|
@@ -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
|
}
|