@ant-design/agentic-ui 2.11.1 → 2.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Bubble/MessagesContent/BubbleExtra.js +7 -1
- package/dist/MarkdownEditor/editor/types/Table.d.ts +1 -0
- package/dist/MarkdownEditor/editor/utils/ace.d.ts +22 -105
- package/dist/MarkdownEditor/editor/utils/ace.js +328 -106
- package/dist/MarkdownEditor/types.d.ts +1 -1
- package/dist/MarkdownInputField/AttachmentButton/AttachmentButtonPopover.d.ts +2 -4
- package/dist/MarkdownInputField/AttachmentButton/AttachmentButtonPopover.js +8 -61
- package/dist/MarkdownInputField/AttachmentButton/index.d.ts +1 -1
- package/dist/MarkdownInputField/AttachmentButton/index.js +7 -19
- package/dist/MarkdownInputField/FileUploadManager/index.d.ts +1 -1
- package/dist/MarkdownInputField/FileUploadManager/index.js +137 -138
- package/dist/MarkdownInputField/MarkdownInputField.d.ts +32 -0
- package/dist/MarkdownInputField/MarkdownInputField.js +26 -8
- package/dist/MarkdownInputField/SendActions/index.d.ts +1 -1
- package/dist/Plugins/chart/ChartRender.js +75 -13
- package/dist/Plugins/chart/LineChart/index.js +10 -4
- package/dist/Plugins/chart/index.js +17 -5
- package/dist/Plugins/chart/utils.d.ts +40 -0
- package/dist/Plugins/chart/utils.js +116 -0
- package/dist/Plugins/code/CodeUI/Katex/Katex.d.ts +0 -1
- package/dist/Plugins/code/CodeUI/Katex/Katex.js +182 -6
- package/dist/Plugins/code/components/AceEditor.d.ts +4 -6
- package/dist/Plugins/code/components/AceEditor.js +362 -40
- package/dist/Plugins/code/loadAceEditor.d.ts +26 -0
- package/dist/Plugins/code/loadAceEditor.js +266 -0
- package/dist/Plugins/katex/InlineKatex.d.ts +0 -1
- package/dist/Plugins/katex/InlineKatex.js +183 -7
- package/dist/Plugins/katex/Katex.d.ts +0 -1
- package/dist/Plugins/katex/Katex.js +184 -6
- package/dist/Plugins/katex/loadKatex.d.ts +18 -0
- package/dist/Plugins/katex/loadKatex.js +181 -0
- package/dist/Plugins/mermaid/Mermaid.js +315 -113
- package/dist/Schema/SchemaEditor/AceEditorWrapper.d.ts +1 -1
- package/dist/Schema/SchemaEditor/AceEditorWrapper.js +342 -53
- package/dist/Utils/loadCSS.d.ts +31 -0
- package/dist/Utils/loadCSS.js +264 -0
- package/package.json +1 -1
|
@@ -229,7 +229,7 @@ import { Loading } from "../../Components/Loading";
|
|
|
229
229
|
import { useIntersectionOnce } from "../../Hooks/useIntersectionOnce";
|
|
230
230
|
import { I18nContext } from "../../I18n";
|
|
231
231
|
import { loadChartRuntime } from "./loadChartRuntime";
|
|
232
|
-
import { isNotEmpty, toNumber } from "./utils";
|
|
232
|
+
import { debounce, getDataHash, isConfigEqual, isNotEmpty, toNumber } from "./utils";
|
|
233
233
|
/**
|
|
234
234
|
* @fileoverview 图表渲染组件文件
|
|
235
235
|
*
|
|
@@ -624,6 +624,8 @@ import { isNotEmpty, toNumber } from "./utils";
|
|
|
624
624
|
* - 提供图表属性工具栏
|
|
625
625
|
* - 使用 React.lazy 和 Suspense 实现代码分割
|
|
626
626
|
*/ export var ChartRender = function(props) {
|
|
627
|
+
var // 对于 rest 对象,使用浅比较
|
|
628
|
+
_config_rest, _config_rest1, _config_rest2;
|
|
627
629
|
var _useState = _sliced_to_array(useState(function() {
|
|
628
630
|
return props.chartType;
|
|
629
631
|
}), 2), chartType = _useState[0], setChartType = _useState[1];
|
|
@@ -635,6 +637,23 @@ import { isNotEmpty, toNumber } from "./utils";
|
|
|
635
637
|
var _useState2 = _sliced_to_array(useState(0), 2), renderKey = _useState2[0], setRenderKey = _useState2[1];
|
|
636
638
|
var containerRef = React.useRef(null);
|
|
637
639
|
var isIntersecting = useIntersectionOnce(containerRef);
|
|
640
|
+
// 用于缓存上一次的数据和配置,避免不必要的重新计算
|
|
641
|
+
var prevDataRef = React.useRef({
|
|
642
|
+
dataHash: '',
|
|
643
|
+
config: null
|
|
644
|
+
});
|
|
645
|
+
// 计算数据哈希值,用于依赖项比较
|
|
646
|
+
var dataHash = React.useMemo(function() {
|
|
647
|
+
return getDataHash(chartData || []);
|
|
648
|
+
}, [
|
|
649
|
+
chartData
|
|
650
|
+
]);
|
|
651
|
+
// 防抖更新 renderKey,避免流式数据频繁更新导致的性能问题
|
|
652
|
+
var debouncedUpdateRenderKeyRef = React.useRef(debounce(function() {
|
|
653
|
+
setRenderKey(function(k) {
|
|
654
|
+
return k + 1;
|
|
655
|
+
});
|
|
656
|
+
}, 300));
|
|
638
657
|
var renderDescriptionsFallback = React.useMemo(function() {
|
|
639
658
|
var _config_columns;
|
|
640
659
|
var columnCount = (config === null || config === void 0 ? void 0 : (_config_columns = config.columns) === null || _config_columns === void 0 ? void 0 : _config_columns.length) || 0;
|
|
@@ -706,8 +725,15 @@ import { isNotEmpty, toNumber } from "./utils";
|
|
|
706
725
|
} : {});
|
|
707
726
|
});
|
|
708
727
|
}, [
|
|
709
|
-
|
|
710
|
-
|
|
728
|
+
// 使用更高效的依赖项比较
|
|
729
|
+
dataHash,
|
|
730
|
+
config === null || config === void 0 ? void 0 : config.x,
|
|
731
|
+
config === null || config === void 0 ? void 0 : config.y,
|
|
732
|
+
config === null || config === void 0 ? void 0 : config.height,
|
|
733
|
+
config === null || config === void 0 ? void 0 : config.index,
|
|
734
|
+
config === null || config === void 0 ? void 0 : (_config_rest = config.rest) === null || _config_rest === void 0 ? void 0 : _config_rest.stacked,
|
|
735
|
+
config === null || config === void 0 ? void 0 : (_config_rest1 = config.rest) === null || _config_rest1 === void 0 ? void 0 : _config_rest1.showLegend,
|
|
736
|
+
config === null || config === void 0 ? void 0 : (_config_rest2 = config.rest) === null || _config_rest2 === void 0 ? void 0 : _config_rest2.showGrid,
|
|
711
737
|
title,
|
|
712
738
|
groupBy,
|
|
713
739
|
colorLegend,
|
|
@@ -730,8 +756,12 @@ import { isNotEmpty, toNumber } from "./utils";
|
|
|
730
756
|
} : {});
|
|
731
757
|
});
|
|
732
758
|
}, [
|
|
733
|
-
|
|
734
|
-
|
|
759
|
+
// 使用更高效的依赖项比较
|
|
760
|
+
dataHash,
|
|
761
|
+
config === null || config === void 0 ? void 0 : config.x,
|
|
762
|
+
config === null || config === void 0 ? void 0 : config.y,
|
|
763
|
+
config === null || config === void 0 ? void 0 : config.height,
|
|
764
|
+
config === null || config === void 0 ? void 0 : config.index,
|
|
735
765
|
title,
|
|
736
766
|
groupBy,
|
|
737
767
|
filterBy
|
|
@@ -741,6 +771,39 @@ import { isNotEmpty, toNumber } from "./utils";
|
|
|
741
771
|
}, [
|
|
742
772
|
props.chartType
|
|
743
773
|
]);
|
|
774
|
+
// 监听数据变化,使用防抖更新渲染键
|
|
775
|
+
React.useEffect(function() {
|
|
776
|
+
var configChanged = !isConfigEqual(prevDataRef.current.config, config);
|
|
777
|
+
var groupByChanged = prevDataRef.current.groupBy !== groupBy;
|
|
778
|
+
var colorLegendChanged = prevDataRef.current.colorLegend !== colorLegend;
|
|
779
|
+
var filterByChanged = prevDataRef.current.filterBy !== filterBy;
|
|
780
|
+
var hasChanged = prevDataRef.current.dataHash !== dataHash || configChanged || groupByChanged || colorLegendChanged || filterByChanged;
|
|
781
|
+
if (hasChanged) {
|
|
782
|
+
// 更新缓存
|
|
783
|
+
prevDataRef.current = {
|
|
784
|
+
dataHash: dataHash,
|
|
785
|
+
config: config,
|
|
786
|
+
groupBy: groupBy,
|
|
787
|
+
colorLegend: colorLegend,
|
|
788
|
+
filterBy: filterBy
|
|
789
|
+
};
|
|
790
|
+
// 对于流式数据,使用防抖更新,避免频繁渲染
|
|
791
|
+
if (prevDataRef.current.dataHash !== dataHash) {
|
|
792
|
+
debouncedUpdateRenderKeyRef.current();
|
|
793
|
+
} else {
|
|
794
|
+
// 配置变化时立即更新
|
|
795
|
+
setRenderKey(function(k) {
|
|
796
|
+
return k + 1;
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
}, [
|
|
801
|
+
dataHash,
|
|
802
|
+
config,
|
|
803
|
+
groupBy,
|
|
804
|
+
colorLegend,
|
|
805
|
+
filterBy
|
|
806
|
+
]);
|
|
744
807
|
/**
|
|
745
808
|
* 图表配置
|
|
746
809
|
*/ var getChartPopover = function() {
|
|
@@ -884,12 +947,7 @@ import { isNotEmpty, toNumber } from "./utils";
|
|
|
884
947
|
})
|
|
885
948
|
})))))
|
|
886
949
|
}, /*#__PURE__*/ React.createElement(ActionIconBox, {
|
|
887
|
-
title: (i18n === null || i18n === void 0 ? void 0 : (_i18n_locale3 = i18n.locale) === null || _i18n_locale3 === void 0 ? void 0 : _i18n_locale3.configChart) || '配置图表'
|
|
888
|
-
onClick: function() {
|
|
889
|
-
return setRenderKey(function(k) {
|
|
890
|
-
return k + 1;
|
|
891
|
-
});
|
|
892
|
-
}
|
|
950
|
+
title: (i18n === null || i18n === void 0 ? void 0 : (_i18n_locale3 = i18n.locale) === null || _i18n_locale3 === void 0 ? void 0 : _i18n_locale3.configChart) || '配置图表'
|
|
893
951
|
}, /*#__PURE__*/ React.createElement(SettingOutlined, {
|
|
894
952
|
style: {
|
|
895
953
|
color: 'rgba(0, 25, 61, 0.3255)'
|
|
@@ -992,8 +1050,12 @@ import { isNotEmpty, toNumber } from "./utils";
|
|
|
992
1050
|
return null;
|
|
993
1051
|
}, [
|
|
994
1052
|
chartType,
|
|
995
|
-
|
|
996
|
-
|
|
1053
|
+
// 使用更高效的依赖项
|
|
1054
|
+
dataHash,
|
|
1055
|
+
config === null || config === void 0 ? void 0 : config.x,
|
|
1056
|
+
config === null || config === void 0 ? void 0 : config.y,
|
|
1057
|
+
config === null || config === void 0 ? void 0 : config.height,
|
|
1058
|
+
config === null || config === void 0 ? void 0 : config.index,
|
|
997
1059
|
renderKey,
|
|
998
1060
|
toolBar,
|
|
999
1061
|
convertDonutData,
|
|
@@ -142,7 +142,7 @@ import React, { useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
|
142
142
|
import { Line } from "react-chartjs-2";
|
|
143
143
|
import { ChartContainer, ChartFilter, ChartStatistic, ChartToolBar, downloadChart } from "../components";
|
|
144
144
|
import { defaultColorList } from "../const";
|
|
145
|
-
import { extractAndSortXValues, findDataPointByXValue } from "../utils";
|
|
145
|
+
import { extractAndSortXValues, findDataPointByXValue, getDataHash } from "../utils";
|
|
146
146
|
import { useStyle } from "./style";
|
|
147
147
|
var lineChartComponentsRegistered = false;
|
|
148
148
|
var LineChart = function(_param) {
|
|
@@ -179,6 +179,12 @@ var LineChart = function(_param) {
|
|
|
179
179
|
return undefined;
|
|
180
180
|
}, []);
|
|
181
181
|
var safeData = Array.isArray(data) ? data : [];
|
|
182
|
+
// 使用数据哈希来优化依赖项比较
|
|
183
|
+
var dataHash = useMemo(function() {
|
|
184
|
+
return getDataHash(safeData);
|
|
185
|
+
}, [
|
|
186
|
+
safeData
|
|
187
|
+
]);
|
|
182
188
|
// 响应式尺寸计算
|
|
183
189
|
var _useState = _sliced_to_array(useState(typeof window !== 'undefined' ? window.innerWidth : 768), 2), windowWidth = _useState[0], setWindowWidth = _useState[1];
|
|
184
190
|
var isMobile = windowWidth <= 768;
|
|
@@ -217,7 +223,7 @@ var LineChart = function(_param) {
|
|
|
217
223
|
}))).filter(Boolean);
|
|
218
224
|
return uniqueCategories;
|
|
219
225
|
}, [
|
|
220
|
-
|
|
226
|
+
dataHash
|
|
221
227
|
]);
|
|
222
228
|
// 从数据中提取 filterLabel,过滤掉 undefined 值
|
|
223
229
|
var validFilterLabels = useMemo(function() {
|
|
@@ -227,7 +233,7 @@ var LineChart = function(_param) {
|
|
|
227
233
|
return filterLabel !== undefined;
|
|
228
234
|
});
|
|
229
235
|
}, [
|
|
230
|
-
|
|
236
|
+
dataHash
|
|
231
237
|
]);
|
|
232
238
|
var filterLabels = useMemo(function() {
|
|
233
239
|
return validFilterLabels.length > 0 ? _to_consumable_array(new Set(validFilterLabels)) : undefined;
|
|
@@ -259,7 +265,7 @@ var LineChart = function(_param) {
|
|
|
259
265
|
return item.x !== null && item.x !== undefined;
|
|
260
266
|
});
|
|
261
267
|
}, [
|
|
262
|
-
|
|
268
|
+
dataHash,
|
|
263
269
|
selectedFilter,
|
|
264
270
|
filterLabels,
|
|
265
271
|
selectedFilterLabel
|
|
@@ -130,6 +130,7 @@ import { ErrorBoundary } from "../../MarkdownEditor/editor/elements/ErrorBoundar
|
|
|
130
130
|
import { useEditorStore } from "../../MarkdownEditor/editor/store";
|
|
131
131
|
import { DragHandle } from "../../MarkdownEditor/editor/tools/DragHandle";
|
|
132
132
|
import { ChartRender } from "./ChartRender";
|
|
133
|
+
import { getDataHash } from "./utils";
|
|
133
134
|
/**
|
|
134
135
|
* @fileoverview 图表插件主入口文件
|
|
135
136
|
*
|
|
@@ -269,10 +270,17 @@ export { ChartFilter, ChartToolBar, downloadChart } from "./components";
|
|
|
269
270
|
* - 集成编辑器状态管理
|
|
270
271
|
* - 提供响应式布局
|
|
271
272
|
*/ export var ChartElement = function(props) {
|
|
272
|
-
var _node_otherProps, _node_otherProps1, _node_otherProps2;
|
|
273
|
+
var _node_otherProps, _node_otherProps1, _node_otherProps2, _node_otherProps3, _node_otherProps4, _node_otherProps_columns, _node_otherProps5;
|
|
273
274
|
var _useEditorStore = useEditorStore(), store = _useEditorStore.store, readonly = _useEditorStore.readonly, markdownContainerRef = _useEditorStore.markdownContainerRef, rootContainer = _useEditorStore.rootContainer;
|
|
274
275
|
var editor = useSlate();
|
|
275
276
|
var node = props.element, attributes = props.attributes, children = props.children;
|
|
277
|
+
// 使用更高效的依赖项比较,避免 JSON.stringify 的性能开销
|
|
278
|
+
var dataSourceHash = useMemo(function() {
|
|
279
|
+
var _node_otherProps;
|
|
280
|
+
return getDataHash(((_node_otherProps = node.otherProps) === null || _node_otherProps === void 0 ? void 0 : _node_otherProps.dataSource) || []);
|
|
281
|
+
}, [
|
|
282
|
+
(_node_otherProps = node.otherProps) === null || _node_otherProps === void 0 ? void 0 : _node_otherProps.dataSource
|
|
283
|
+
]);
|
|
276
284
|
var chartData = useMemo(function() {
|
|
277
285
|
var _node_otherProps_dataSource, _node_otherProps;
|
|
278
286
|
return ((_node_otherProps = node.otherProps) === null || _node_otherProps === void 0 ? void 0 : (_node_otherProps_dataSource = _node_otherProps.dataSource) === null || _node_otherProps_dataSource === void 0 ? void 0 : _node_otherProps_dataSource.map(function(item) {
|
|
@@ -281,12 +289,13 @@ export { ChartFilter, ChartToolBar, downloadChart } from "./components";
|
|
|
281
289
|
});
|
|
282
290
|
})) || [];
|
|
283
291
|
}, [
|
|
284
|
-
|
|
292
|
+
dataSourceHash,
|
|
293
|
+
(_node_otherProps1 = node.otherProps) === null || _node_otherProps1 === void 0 ? void 0 : _node_otherProps1.dataSource
|
|
285
294
|
]);
|
|
286
|
-
var columns = ((
|
|
295
|
+
var columns = ((_node_otherProps2 = node.otherProps) === null || _node_otherProps2 === void 0 ? void 0 : _node_otherProps2.columns) || [];
|
|
287
296
|
var _React_useState = _sliced_to_array(React.useState(2), 2), columnLength = _React_useState[0], setColumnLength = _React_useState[1];
|
|
288
297
|
var config = [
|
|
289
|
-
((
|
|
298
|
+
((_node_otherProps3 = node.otherProps) === null || _node_otherProps3 === void 0 ? void 0 : _node_otherProps3.config) || node.otherProps
|
|
290
299
|
].flat(1);
|
|
291
300
|
var htmlRef = React.useRef(null);
|
|
292
301
|
var _React_useState1 = _sliced_to_array(React.useState(256), 2), minWidth = _React_useState1[0], setMinWidth = _React_useState1[1];
|
|
@@ -463,7 +472,10 @@ export { ChartFilter, ChartToolBar, downloadChart } from "./components";
|
|
|
463
472
|
}))))));
|
|
464
473
|
}, [
|
|
465
474
|
attributes,
|
|
466
|
-
|
|
475
|
+
// 使用更高效的依赖项比较
|
|
476
|
+
dataSourceHash,
|
|
477
|
+
(_node_otherProps4 = node.otherProps) === null || _node_otherProps4 === void 0 ? void 0 : _node_otherProps4.config,
|
|
478
|
+
(_node_otherProps5 = node.otherProps) === null || _node_otherProps5 === void 0 ? void 0 : (_node_otherProps_columns = _node_otherProps5.columns) === null || _node_otherProps_columns === void 0 ? void 0 : _node_otherProps_columns.length,
|
|
467
479
|
editor,
|
|
468
480
|
columnLength,
|
|
469
481
|
readonly,
|
|
@@ -246,3 +246,43 @@ export declare const toNumber: (val: any, fallback: number) => number;
|
|
|
246
246
|
* @since 1.0.0
|
|
247
247
|
*/
|
|
248
248
|
export declare const isNotEmpty: (val: any) => boolean;
|
|
249
|
+
/**
|
|
250
|
+
* 生成数据数组的快速哈希值
|
|
251
|
+
*
|
|
252
|
+
* 用于优化 useMemo 的依赖项比较,避免使用 JSON.stringify 的性能开销。
|
|
253
|
+
* 通过比较数组长度和最后一个元素的引用来快速判断数据是否变化。
|
|
254
|
+
* 适用于流式数据场景,当数据频繁追加时性能更好。
|
|
255
|
+
*
|
|
256
|
+
* @param {any[]} data - 数据数组
|
|
257
|
+
* @returns {string} 哈希值字符串
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* ```typescript
|
|
261
|
+
* const hash1 = getDataHash([{ x: 1, y: 2 }]);
|
|
262
|
+
* const hash2 = getDataHash([{ x: 1, y: 2 }, { x: 3, y: 4 }]);
|
|
263
|
+
* // hash1 !== hash2
|
|
264
|
+
* ```
|
|
265
|
+
*
|
|
266
|
+
* @since 1.0.0
|
|
267
|
+
*/
|
|
268
|
+
export declare const getDataHash: (data: any[]) => string;
|
|
269
|
+
/**
|
|
270
|
+
* 深度比较两个配置对象的关键字段
|
|
271
|
+
*
|
|
272
|
+
* 用于优化 useMemo 的依赖项比较,只比较配置的关键字段,
|
|
273
|
+
* 避免对整个配置对象进行深度比较的性能开销。
|
|
274
|
+
*
|
|
275
|
+
* @param {any} config1 - 第一个配置对象
|
|
276
|
+
* @param {any} config2 - 第二个配置对象
|
|
277
|
+
* @returns {boolean} 是否相等
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* ```typescript
|
|
281
|
+
* const config1 = { x: 'date', y: 'value', height: 400 };
|
|
282
|
+
* const config2 = { x: 'date', y: 'value', height: 400 };
|
|
283
|
+
* isConfigEqual(config1, config2); // true
|
|
284
|
+
* ```
|
|
285
|
+
*
|
|
286
|
+
* @since 1.0.0
|
|
287
|
+
*/
|
|
288
|
+
export declare const isConfigEqual: (config1: any, config2: any) => boolean;
|
|
@@ -320,3 +320,119 @@ var intl = new Intl.NumberFormat('en-US', {
|
|
|
320
320
|
*/ export var isNotEmpty = function(val) {
|
|
321
321
|
return val !== null && val !== undefined;
|
|
322
322
|
};
|
|
323
|
+
/**
|
|
324
|
+
* 生成数据数组的快速哈希值
|
|
325
|
+
*
|
|
326
|
+
* 用于优化 useMemo 的依赖项比较,避免使用 JSON.stringify 的性能开销。
|
|
327
|
+
* 通过比较数组长度和最后一个元素的引用来快速判断数据是否变化。
|
|
328
|
+
* 适用于流式数据场景,当数据频繁追加时性能更好。
|
|
329
|
+
*
|
|
330
|
+
* @param {any[]} data - 数据数组
|
|
331
|
+
* @returns {string} 哈希值字符串
|
|
332
|
+
*
|
|
333
|
+
* @example
|
|
334
|
+
* ```typescript
|
|
335
|
+
* const hash1 = getDataHash([{ x: 1, y: 2 }]);
|
|
336
|
+
* const hash2 = getDataHash([{ x: 1, y: 2 }, { x: 3, y: 4 }]);
|
|
337
|
+
* // hash1 !== hash2
|
|
338
|
+
* ```
|
|
339
|
+
*
|
|
340
|
+
* @since 1.0.0
|
|
341
|
+
*/ export var getDataHash = function(data) {
|
|
342
|
+
if (!Array.isArray(data) || data.length === 0) {
|
|
343
|
+
return "0-".concat((data === null || data === void 0 ? void 0 : data.length) || 0);
|
|
344
|
+
}
|
|
345
|
+
// 使用长度和最后一个元素的引用作为快速哈希
|
|
346
|
+
// 对于流式数据,通常只有新增,所以比较最后一个元素即可
|
|
347
|
+
var lastItem = data[data.length - 1];
|
|
348
|
+
var firstItem = data[0];
|
|
349
|
+
// 使用简单的哈希:长度 + 首尾元素的简单标识
|
|
350
|
+
var firstKey = firstItem ? Object.keys(firstItem).join(',') : '';
|
|
351
|
+
var lastKey = lastItem ? Object.keys(lastItem).join(',') : '';
|
|
352
|
+
return "".concat(data.length, "-").concat(firstKey, "-").concat(lastKey);
|
|
353
|
+
};
|
|
354
|
+
/**
|
|
355
|
+
* 深度比较两个配置对象的关键字段
|
|
356
|
+
*
|
|
357
|
+
* 用于优化 useMemo 的依赖项比较,只比较配置的关键字段,
|
|
358
|
+
* 避免对整个配置对象进行深度比较的性能开销。
|
|
359
|
+
*
|
|
360
|
+
* @param {any} config1 - 第一个配置对象
|
|
361
|
+
* @param {any} config2 - 第二个配置对象
|
|
362
|
+
* @returns {boolean} 是否相等
|
|
363
|
+
*
|
|
364
|
+
* @example
|
|
365
|
+
* ```typescript
|
|
366
|
+
* const config1 = { x: 'date', y: 'value', height: 400 };
|
|
367
|
+
* const config2 = { x: 'date', y: 'value', height: 400 };
|
|
368
|
+
* isConfigEqual(config1, config2); // true
|
|
369
|
+
* ```
|
|
370
|
+
*
|
|
371
|
+
* @since 1.0.0
|
|
372
|
+
*/ export var isConfigEqual = function(config1, config2) {
|
|
373
|
+
if (config1 === config2) return true;
|
|
374
|
+
if (!config1 || !config2) return false;
|
|
375
|
+
var keys1 = Object.keys(config1);
|
|
376
|
+
var keys2 = Object.keys(config2);
|
|
377
|
+
if (keys1.length !== keys2.length) return false;
|
|
378
|
+
// 只比较关键字段
|
|
379
|
+
var keyFields = [
|
|
380
|
+
'x',
|
|
381
|
+
'y',
|
|
382
|
+
'height',
|
|
383
|
+
'index',
|
|
384
|
+
'rest'
|
|
385
|
+
];
|
|
386
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
387
|
+
try {
|
|
388
|
+
for(var _iterator = keyFields[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
389
|
+
var key = _step.value;
|
|
390
|
+
if (config1[key] !== config2[key]) {
|
|
391
|
+
// 对于 rest 对象,进行浅比较
|
|
392
|
+
if (key === 'rest' && config1[key] && config2[key]) {
|
|
393
|
+
var rest1 = config1[key];
|
|
394
|
+
var rest2 = config2[key];
|
|
395
|
+
var restKeys1 = Object.keys(rest1);
|
|
396
|
+
var restKeys2 = Object.keys(rest2);
|
|
397
|
+
if (restKeys1.length !== restKeys2.length) return false;
|
|
398
|
+
var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
399
|
+
try {
|
|
400
|
+
for(var _iterator1 = restKeys1[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
401
|
+
var restKey = _step1.value;
|
|
402
|
+
if (rest1[restKey] !== rest2[restKey]) return false;
|
|
403
|
+
}
|
|
404
|
+
} catch (err) {
|
|
405
|
+
_didIteratorError1 = true;
|
|
406
|
+
_iteratorError1 = err;
|
|
407
|
+
} finally{
|
|
408
|
+
try {
|
|
409
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
410
|
+
_iterator1.return();
|
|
411
|
+
}
|
|
412
|
+
} finally{
|
|
413
|
+
if (_didIteratorError1) {
|
|
414
|
+
throw _iteratorError1;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
} else {
|
|
419
|
+
return false;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
} catch (err) {
|
|
424
|
+
_didIteratorError = true;
|
|
425
|
+
_iteratorError = err;
|
|
426
|
+
} finally{
|
|
427
|
+
try {
|
|
428
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
429
|
+
_iterator.return();
|
|
430
|
+
}
|
|
431
|
+
} finally{
|
|
432
|
+
if (_didIteratorError) {
|
|
433
|
+
throw _iteratorError;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
return true;
|
|
438
|
+
};
|
|
@@ -6,6 +6,35 @@ function _array_like_to_array(arr, len) {
|
|
|
6
6
|
function _array_with_holes(arr) {
|
|
7
7
|
if (Array.isArray(arr)) return arr;
|
|
8
8
|
}
|
|
9
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
10
|
+
try {
|
|
11
|
+
var info = gen[key](arg);
|
|
12
|
+
var value = info.value;
|
|
13
|
+
} catch (error) {
|
|
14
|
+
reject(error);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (info.done) {
|
|
18
|
+
resolve(value);
|
|
19
|
+
} else {
|
|
20
|
+
Promise.resolve(value).then(_next, _throw);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function _async_to_generator(fn) {
|
|
24
|
+
return function() {
|
|
25
|
+
var self = this, args = arguments;
|
|
26
|
+
return new Promise(function(resolve, reject) {
|
|
27
|
+
var gen = fn.apply(self, args);
|
|
28
|
+
function _next(value) {
|
|
29
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
30
|
+
}
|
|
31
|
+
function _throw(err) {
|
|
32
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
33
|
+
}
|
|
34
|
+
_next(undefined);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
}
|
|
9
38
|
function _iterable_to_array_limit(arr, i) {
|
|
10
39
|
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
11
40
|
if (_i == null) return;
|
|
@@ -44,16 +73,112 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
44
73
|
if (n === "Map" || n === "Set") return Array.from(n);
|
|
45
74
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
46
75
|
}
|
|
76
|
+
function _ts_generator(thisArg, body) {
|
|
77
|
+
var f, y, t, g, _ = {
|
|
78
|
+
label: 0,
|
|
79
|
+
sent: function() {
|
|
80
|
+
if (t[0] & 1) throw t[1];
|
|
81
|
+
return t[1];
|
|
82
|
+
},
|
|
83
|
+
trys: [],
|
|
84
|
+
ops: []
|
|
85
|
+
};
|
|
86
|
+
return g = {
|
|
87
|
+
next: verb(0),
|
|
88
|
+
"throw": verb(1),
|
|
89
|
+
"return": verb(2)
|
|
90
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
91
|
+
return this;
|
|
92
|
+
}), g;
|
|
93
|
+
function verb(n) {
|
|
94
|
+
return function(v) {
|
|
95
|
+
return step([
|
|
96
|
+
n,
|
|
97
|
+
v
|
|
98
|
+
]);
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function step(op) {
|
|
102
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
103
|
+
while(_)try {
|
|
104
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
105
|
+
if (y = 0, t) op = [
|
|
106
|
+
op[0] & 2,
|
|
107
|
+
t.value
|
|
108
|
+
];
|
|
109
|
+
switch(op[0]){
|
|
110
|
+
case 0:
|
|
111
|
+
case 1:
|
|
112
|
+
t = op;
|
|
113
|
+
break;
|
|
114
|
+
case 4:
|
|
115
|
+
_.label++;
|
|
116
|
+
return {
|
|
117
|
+
value: op[1],
|
|
118
|
+
done: false
|
|
119
|
+
};
|
|
120
|
+
case 5:
|
|
121
|
+
_.label++;
|
|
122
|
+
y = op[1];
|
|
123
|
+
op = [
|
|
124
|
+
0
|
|
125
|
+
];
|
|
126
|
+
continue;
|
|
127
|
+
case 7:
|
|
128
|
+
op = _.ops.pop();
|
|
129
|
+
_.trys.pop();
|
|
130
|
+
continue;
|
|
131
|
+
default:
|
|
132
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
133
|
+
_ = 0;
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
137
|
+
_.label = op[1];
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
141
|
+
_.label = t[1];
|
|
142
|
+
t = op;
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
if (t && _.label < t[2]) {
|
|
146
|
+
_.label = t[2];
|
|
147
|
+
_.ops.push(op);
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
if (t[2]) _.ops.pop();
|
|
151
|
+
_.trys.pop();
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
op = body.call(thisArg, _);
|
|
155
|
+
} catch (e) {
|
|
156
|
+
op = [
|
|
157
|
+
6,
|
|
158
|
+
e
|
|
159
|
+
];
|
|
160
|
+
y = 0;
|
|
161
|
+
} finally{
|
|
162
|
+
f = t = 0;
|
|
163
|
+
}
|
|
164
|
+
if (op[0] & 5) throw op[1];
|
|
165
|
+
return {
|
|
166
|
+
value: op[0] ? op[1] : void 0,
|
|
167
|
+
done: true
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
}
|
|
47
171
|
import classNames from "classnames";
|
|
48
|
-
import
|
|
49
|
-
import React, { useEffect, useRef } from "react";
|
|
172
|
+
import React, { startTransition, useEffect, useRef, useState } from "react";
|
|
50
173
|
import { useGetSetState } from "react-use";
|
|
51
|
-
import "
|
|
174
|
+
import { loadKatex } from "../../../katex/loadKatex";
|
|
52
175
|
export var Katex = function(props) {
|
|
53
176
|
var _useGetSetState = _sliced_to_array(useGetSetState({
|
|
54
177
|
code: '',
|
|
55
178
|
error: ''
|
|
56
179
|
}), 2), state = _useGetSetState[0], setState = _useGetSetState[1];
|
|
180
|
+
var _useState = _sliced_to_array(useState(false), 2), katexLoaded = _useState[0], setKatexLoaded = _useState[1];
|
|
181
|
+
var katexRef = useRef(null);
|
|
57
182
|
var divRef = useRef(null);
|
|
58
183
|
var timer = useRef(0);
|
|
59
184
|
// 处理未定义的 el
|
|
@@ -62,7 +187,56 @@ export var Katex = function(props) {
|
|
|
62
187
|
type: 'code',
|
|
63
188
|
language: 'katex'
|
|
64
189
|
};
|
|
190
|
+
// 异步加载 Katex 库和 CSS
|
|
191
|
+
useEffect(function() {
|
|
192
|
+
if (process.env.NODE_ENV === 'test') {
|
|
193
|
+
setKatexLoaded(true);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
startTransition(function() {
|
|
197
|
+
// 异步加载在 startTransition 外部执行
|
|
198
|
+
_async_to_generator(function() {
|
|
199
|
+
var katexModule, error;
|
|
200
|
+
return _ts_generator(this, function(_state) {
|
|
201
|
+
switch(_state.label){
|
|
202
|
+
case 0:
|
|
203
|
+
_state.trys.push([
|
|
204
|
+
0,
|
|
205
|
+
2,
|
|
206
|
+
,
|
|
207
|
+
3
|
|
208
|
+
]);
|
|
209
|
+
return [
|
|
210
|
+
4,
|
|
211
|
+
loadKatex()
|
|
212
|
+
];
|
|
213
|
+
case 1:
|
|
214
|
+
katexModule = _state.sent();
|
|
215
|
+
katexRef.current = katexModule.default;
|
|
216
|
+
setKatexLoaded(true);
|
|
217
|
+
return [
|
|
218
|
+
3,
|
|
219
|
+
3
|
|
220
|
+
];
|
|
221
|
+
case 2:
|
|
222
|
+
error = _state.sent();
|
|
223
|
+
console.error('Failed to load Katex:', error);
|
|
224
|
+
setKatexLoaded(true);
|
|
225
|
+
return [
|
|
226
|
+
3,
|
|
227
|
+
3
|
|
228
|
+
];
|
|
229
|
+
case 3:
|
|
230
|
+
return [
|
|
231
|
+
2
|
|
232
|
+
];
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
})();
|
|
236
|
+
});
|
|
237
|
+
}, []);
|
|
65
238
|
useEffect(function() {
|
|
239
|
+
if (!katexLoaded || !katexRef.current) return;
|
|
66
240
|
var code = safeEl.value || '';
|
|
67
241
|
clearTimeout(timer.current);
|
|
68
242
|
timer.current = window.setTimeout(function() {
|
|
@@ -71,8 +245,8 @@ export var Katex = function(props) {
|
|
|
71
245
|
});
|
|
72
246
|
if (state().code) {
|
|
73
247
|
try {
|
|
74
|
-
if (divRef.current) {
|
|
75
|
-
|
|
248
|
+
if (divRef.current && katexRef.current) {
|
|
249
|
+
katexRef.current.render(state().code, divRef.current, {
|
|
76
250
|
strict: false,
|
|
77
251
|
output: 'htmlAndMathml',
|
|
78
252
|
throwOnError: false,
|
|
@@ -93,7 +267,9 @@ export var Katex = function(props) {
|
|
|
93
267
|
return window.clearTimeout(timer.current);
|
|
94
268
|
};
|
|
95
269
|
}, [
|
|
96
|
-
safeEl
|
|
270
|
+
safeEl,
|
|
271
|
+
katexLoaded,
|
|
272
|
+
state
|
|
97
273
|
]);
|
|
98
274
|
return /*#__PURE__*/ React.createElement("div", {
|
|
99
275
|
style: {
|
|
@@ -12,10 +12,8 @@
|
|
|
12
12
|
* @see {@link https://ace.c9.io/} Ace Editor 官方文档
|
|
13
13
|
*/
|
|
14
14
|
/// <reference types="react" />
|
|
15
|
-
/// <reference types="ace-builds/types/ace-
|
|
16
|
-
|
|
17
|
-
import 'ace-builds/src-noconflict/theme-chaos';
|
|
18
|
-
import 'ace-builds/src-noconflict/theme-github';
|
|
15
|
+
/// <reference types="ace-builds/types/ace-modules" />
|
|
16
|
+
/// <reference types="ace-builds" />
|
|
19
17
|
import { Path } from 'slate';
|
|
20
18
|
import { CodeNode } from '../../../MarkdownEditor/el';
|
|
21
19
|
/**
|
|
@@ -68,8 +66,8 @@ interface AceEditorProps {
|
|
|
68
66
|
*/
|
|
69
67
|
export declare function AceEditor({ element, onUpdate, onShowBorderChange, onHideChange, path, isSelected, onSelectionChange, ...props }: AceEditorProps): {
|
|
70
68
|
dom: import("react").RefObject<HTMLDivElement>;
|
|
71
|
-
editorRef: import("react").MutableRefObject<ace.Editor | undefined>;
|
|
72
|
-
setLanguage: (changeLang: string) => void
|
|
69
|
+
editorRef: import("react").MutableRefObject<import("ace-builds").Editor | undefined>;
|
|
70
|
+
setLanguage: (changeLang: string) => Promise<void>;
|
|
73
71
|
focusEditor: () => void | undefined;
|
|
74
72
|
isSelected: boolean;
|
|
75
73
|
onSelectionChange: ((selected: boolean) => void) | undefined;
|