@ant-design/agentic-ui 2.14.1 → 2.16.1

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.
Files changed (103) hide show
  1. package/dist/Bubble/BubbleBeforeNode.js +9 -9
  2. package/dist/Bubble/List/PureBubbleList.js +1 -1
  3. package/dist/Bubble/MessagesContent/EXCEPTION.js +1 -1
  4. package/dist/ChatLayout/style.js +16 -17
  5. package/dist/Constants/mobile.d.ts +3 -0
  6. package/dist/Constants/mobile.js +7 -0
  7. package/dist/Hooks/useLanguage.d.ts +2 -0
  8. package/dist/I18n/locales.d.ts +2 -0
  9. package/dist/I18n/locales.js +4 -0
  10. package/dist/MarkdownEditor/BaseMarkdownEditor.js +1 -1
  11. package/dist/MarkdownEditor/editor/Editor.js +16 -8
  12. package/dist/MarkdownEditor/editor/code.css +2 -2
  13. package/dist/MarkdownEditor/editor/elements/Code.js +11 -6
  14. package/dist/MarkdownEditor/editor/elements/FootnoteDefinition.js +2 -1
  15. package/dist/MarkdownEditor/editor/elements/FootnoteReference.js +2 -1
  16. package/dist/MarkdownEditor/editor/elements/Head.d.ts +1 -0
  17. package/dist/MarkdownEditor/editor/elements/Head.js +1 -1
  18. package/dist/MarkdownEditor/editor/elements/Image/index.js +19 -7
  19. package/dist/MarkdownEditor/editor/elements/LinkCard/index.js +2 -1
  20. package/dist/MarkdownEditor/editor/elements/LinkCard/style.js +1 -1
  21. package/dist/MarkdownEditor/editor/elements/List/ListItem.js +1 -0
  22. package/dist/MarkdownEditor/editor/elements/List/style.js +2 -2
  23. package/dist/MarkdownEditor/editor/elements/Media.js +22 -10
  24. package/dist/MarkdownEditor/editor/elements/Paragraph.js +2 -1
  25. package/dist/MarkdownEditor/editor/elements/Schema.js +1 -1
  26. package/dist/MarkdownEditor/editor/elements/Table/ReadonlyTableComponent.js +16 -4
  27. package/dist/MarkdownEditor/editor/elements/Table/SimpleTable.js +17 -2
  28. package/dist/MarkdownEditor/editor/elements/Table/Table.js +155 -20
  29. package/dist/MarkdownEditor/editor/elements/Table/Td/style.js +5 -2
  30. package/dist/MarkdownEditor/editor/elements/Table/index.js +0 -2
  31. package/dist/MarkdownEditor/editor/elements/Table/style.js +7 -8
  32. package/dist/MarkdownEditor/editor/elements/TagPopup/index.js +5 -3
  33. package/dist/MarkdownEditor/editor/elements/TagPopup/style.js +2 -2
  34. package/dist/MarkdownEditor/editor/parser/parserMarkdownToSlateNode.d.ts +100 -1
  35. package/dist/MarkdownEditor/editor/parser/parserMarkdownToSlateNode.js +781 -240
  36. package/dist/MarkdownEditor/editor/plugins/useKeyboard.js +8 -19
  37. package/dist/MarkdownEditor/editor/store.js +3 -3
  38. package/dist/MarkdownEditor/editor/style.js +41 -6
  39. package/dist/MarkdownEditor/editor/tools/DragHandle.js +3 -3
  40. package/dist/MarkdownEditor/editor/types/Table.d.ts +1 -0
  41. package/dist/MarkdownEditor/editor/utils/findMatchingClose.d.ts +36 -0
  42. package/dist/MarkdownEditor/editor/utils/findMatchingClose.js +158 -0
  43. package/dist/MarkdownEditor/editor/utils/markdownToHtml.d.ts +41 -2
  44. package/dist/MarkdownEditor/editor/utils/markdownToHtml.js +159 -7
  45. package/dist/MarkdownEditor/style.js +8 -2
  46. package/dist/MarkdownEditor/types.d.ts +1 -1
  47. package/dist/MarkdownEditor/utils/exportHtml.js +1 -1
  48. package/dist/MarkdownInputField/MarkdownInputField.d.ts +7 -7
  49. package/dist/MarkdownInputField/MarkdownInputField.js +11 -35
  50. package/dist/MarkdownInputField/SendButton/index.js +17 -3
  51. package/dist/MarkdownInputField/style.js +23 -2
  52. package/dist/Plugins/chart/AreaChart/index.d.ts +12 -0
  53. package/dist/Plugins/chart/AreaChart/index.js +14 -188
  54. package/dist/Plugins/chart/BarChart/index.d.ts +2 -0
  55. package/dist/Plugins/chart/BarChart/index.js +3 -12
  56. package/dist/Plugins/chart/ChartMark/Container.js +5 -2
  57. package/dist/Plugins/chart/ChartRender.d.ts +1 -0
  58. package/dist/Plugins/chart/ChartRender.js +104 -43
  59. package/dist/Plugins/chart/DonutChart/index.js +4 -2
  60. package/dist/Plugins/chart/DonutChart/types.d.ts +2 -0
  61. package/dist/Plugins/chart/FunnelChart/index.d.ts +2 -0
  62. package/dist/Plugins/chart/FunnelChart/index.js +4 -2
  63. package/dist/Plugins/chart/LineChart/index.d.ts +2 -0
  64. package/dist/Plugins/chart/LineChart/index.js +17 -162
  65. package/dist/Plugins/chart/RadarChart/index.d.ts +2 -0
  66. package/dist/Plugins/chart/RadarChart/index.js +8 -4
  67. package/dist/Plugins/chart/ScatterChart/index.d.ts +2 -0
  68. package/dist/Plugins/chart/ScatterChart/index.js +8 -4
  69. package/dist/Plugins/chart/components/ChartContainer/ChartContainer.d.ts +1 -0
  70. package/dist/Plugins/chart/components/ChartContainer/ChartErrorBoundaryExample.js +1 -1
  71. package/dist/Plugins/chart/components/ChartFilter/ChartFilter.d.ts +1 -1
  72. package/dist/Plugins/chart/components/ChartFilter/ChartFilter.js +210 -16
  73. package/dist/Plugins/chart/components/ChartToolBar/ChartToolBar.d.ts +2 -0
  74. package/dist/Plugins/chart/components/ChartToolBar/ChartToolBar.js +9 -2
  75. package/dist/Plugins/chart/components/ChartToolBar/style.js +3 -1
  76. package/dist/Plugins/chart/hooks/index.d.ts +10 -0
  77. package/dist/Plugins/chart/hooks/index.js +8 -0
  78. package/dist/Plugins/chart/hooks/useChartDataFilter.d.ts +46 -0
  79. package/dist/Plugins/chart/hooks/useChartDataFilter.js +182 -0
  80. package/dist/Plugins/chart/hooks/useChartStatistics.d.ts +17 -0
  81. package/dist/Plugins/chart/hooks/useChartStatistics.js +25 -0
  82. package/dist/Plugins/chart/hooks/useChartTheme.d.ts +20 -0
  83. package/dist/Plugins/chart/hooks/useChartTheme.js +30 -0
  84. package/dist/Plugins/chart/hooks/useResponsiveSize.d.ts +23 -0
  85. package/dist/Plugins/chart/hooks/useResponsiveSize.js +94 -0
  86. package/dist/Plugins/chart/index.js +94 -10
  87. package/dist/Plugins/chart/utils/registerChart.d.ts +35 -0
  88. package/dist/Plugins/chart/utils/registerChart.js +54 -0
  89. package/dist/Plugins/chart/utils.d.ts +19 -0
  90. package/dist/Plugins/chart/utils.js +27 -0
  91. package/dist/Plugins/code/components/CodeContainer.js +2 -3
  92. package/dist/Plugins/code/components/CodeRenderer.js +53 -2
  93. package/dist/Plugins/code/components/CodeToolbar.js +22 -3
  94. package/dist/Plugins/katex/InlineKatex.js +1 -1
  95. package/dist/Plugins/katex/Katex.js +1 -1
  96. package/dist/Plugins/mermaid/Mermaid.js +66 -66
  97. package/dist/Plugins/mermaid/index.js +1 -1
  98. package/dist/ThoughtChainList/index.js +21 -2
  99. package/dist/ThoughtChainList/style.js +1 -0
  100. package/dist/Utils/loadCSS.js +6 -6
  101. package/dist/WelcomeMessage/index.js +21 -2
  102. package/dist/Workspace/Task/index.js +1 -1
  103. package/package.json +2 -2
@@ -0,0 +1,23 @@
1
+ /**
2
+ * 响应式尺寸 Hook
3
+ *
4
+ * 用于计算图表的响应式宽度和高度,并监听窗口大小变化。
5
+ * 在移动端(宽度 <= 768px)时自动调整为全宽和自适应高度。
6
+ *
7
+ * @param {number | string} width - 图表宽度,默认600px
8
+ * @param {number | string} height - 图表高度,默认400px
9
+ * @returns {object} 包含响应式尺寸和移动端标识的对象
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const { responsiveWidth, responsiveHeight, isMobile } = useResponsiveSize(800, 400);
14
+ * ```
15
+ *
16
+ * @since 1.0.0
17
+ */
18
+ export declare const useResponsiveSize: (width?: number | string, height?: number | string) => {
19
+ responsiveWidth: string | number;
20
+ responsiveHeight: string | number;
21
+ isMobile: boolean;
22
+ windowWidth: number;
23
+ };
@@ -0,0 +1,94 @@
1
+ function _array_like_to_array(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _array_with_holes(arr) {
7
+ if (Array.isArray(arr)) return arr;
8
+ }
9
+ function _iterable_to_array_limit(arr, i) {
10
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
11
+ if (_i == null) return;
12
+ var _arr = [];
13
+ var _n = true;
14
+ var _d = false;
15
+ var _s, _e;
16
+ try {
17
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
18
+ _arr.push(_s.value);
19
+ if (i && _arr.length === i) break;
20
+ }
21
+ } catch (err) {
22
+ _d = true;
23
+ _e = err;
24
+ } finally{
25
+ try {
26
+ if (!_n && _i["return"] != null) _i["return"]();
27
+ } finally{
28
+ if (_d) throw _e;
29
+ }
30
+ }
31
+ return _arr;
32
+ }
33
+ function _non_iterable_rest() {
34
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
35
+ }
36
+ function _sliced_to_array(arr, i) {
37
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
38
+ }
39
+ function _unsupported_iterable_to_array(o, minLen) {
40
+ if (!o) return;
41
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
42
+ var n = Object.prototype.toString.call(o).slice(8, -1);
43
+ if (n === "Object" && o.constructor) n = o.constructor.name;
44
+ if (n === "Map" || n === "Set") return Array.from(n);
45
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
46
+ }
47
+ import { useEffect, useMemo, useState } from "react";
48
+ /**
49
+ * 响应式尺寸 Hook
50
+ *
51
+ * 用于计算图表的响应式宽度和高度,并监听窗口大小变化。
52
+ * 在移动端(宽度 <= 768px)时自动调整为全宽和自适应高度。
53
+ *
54
+ * @param {number | string} width - 图表宽度,默认600px
55
+ * @param {number | string} height - 图表高度,默认400px
56
+ * @returns {object} 包含响应式尺寸和移动端标识的对象
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * const { responsiveWidth, responsiveHeight, isMobile } = useResponsiveSize(800, 400);
61
+ * ```
62
+ *
63
+ * @since 1.0.0
64
+ */ export var useResponsiveSize = function() {
65
+ var width = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 600, height = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 400;
66
+ var _useState = _sliced_to_array(useState(typeof window !== 'undefined' ? window.innerWidth : 768), 2), windowWidth = _useState[0], setWindowWidth = _useState[1];
67
+ var isMobile = windowWidth <= 768;
68
+ var responsiveWidth = isMobile ? '100%' : width;
69
+ var responsiveHeight = isMobile ? Math.min(windowWidth * 0.8, 400) : height;
70
+ useEffect(function() {
71
+ var handleResize = function() {
72
+ setWindowWidth(window.innerWidth);
73
+ };
74
+ if (typeof window !== 'undefined') {
75
+ window.addEventListener('resize', handleResize);
76
+ return function() {
77
+ return window.removeEventListener('resize', handleResize);
78
+ };
79
+ }
80
+ }, []);
81
+ return useMemo(function() {
82
+ return {
83
+ responsiveWidth: responsiveWidth,
84
+ responsiveHeight: responsiveHeight,
85
+ isMobile: isMobile,
86
+ windowWidth: windowWidth
87
+ };
88
+ }, [
89
+ responsiveWidth,
90
+ responsiveHeight,
91
+ isMobile,
92
+ windowWidth
93
+ ]);
94
+ };
@@ -129,6 +129,7 @@ import { useSlate } from "slate-react";
129
129
  import { ErrorBoundary } from "../../MarkdownEditor/editor/elements/ErrorBoundary";
130
130
  import { useEditorStore } from "../../MarkdownEditor/editor/store";
131
131
  import { DragHandle } from "../../MarkdownEditor/editor/tools/DragHandle";
132
+ import { useMEditor } from "../../MarkdownEditor/hooks/editor";
132
133
  import { ChartRender } from "./ChartRender";
133
134
  import { getDataHash } from "./utils";
134
135
  /**
@@ -270,7 +271,7 @@ export { ChartFilter, ChartToolBar, downloadChart } from "./components";
270
271
  * - 集成编辑器状态管理
271
272
  * - 提供响应式布局
272
273
  */ export var ChartElement = function(props) {
273
- var _node_otherProps, _node_otherProps1, _node_otherProps2, _node_otherProps3, _node_otherProps4, _node_otherProps_columns, _node_otherProps5;
274
+ var _node_otherProps, _node_otherProps1, _node_otherProps2, _node_otherProps3, _node_otherProps4, _node_otherProps5, _node_otherProps_columns, _node_otherProps6;
274
275
  var _useEditorStore = useEditorStore(), store = _useEditorStore.store, readonly = _useEditorStore.readonly, markdownContainerRef = _useEditorStore.markdownContainerRef, rootContainer = _useEditorStore.rootContainer;
275
276
  var editor = useSlate();
276
277
  var node = props.element, attributes = props.attributes, children = props.children;
@@ -282,20 +283,101 @@ export { ChartFilter, ChartToolBar, downloadChart } from "./components";
282
283
  (_node_otherProps = node.otherProps) === null || _node_otherProps === void 0 ? void 0 : _node_otherProps.dataSource
283
284
  ]);
284
285
  var chartData = useMemo(function() {
285
- var _node_otherProps_dataSource, _node_otherProps;
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) {
286
+ var _node_otherProps;
287
+ var dataSource = ((_node_otherProps = node.otherProps) === null || _node_otherProps === void 0 ? void 0 : _node_otherProps.dataSource) || [];
288
+ if (dataSource.length === 0) {
289
+ return [];
290
+ }
291
+ // 获取第一行的 keys 作为参考
292
+ var firstRowKeys = Object.keys(dataSource[0]).sort();
293
+ // 处理数据并过滤掉最后一行(如果它的 keys 和第一行不同)
294
+ var processed = dataSource.map(function(item) {
287
295
  return _object_spread_props(_object_spread({}, item), {
288
296
  column_list: Object.keys(item)
289
297
  });
290
- })) || [];
298
+ });
299
+ // 检查最后一行是否完整
300
+ if (processed.length > 1) {
301
+ var lastRow = processed[processed.length - 1];
302
+ var lastRowKeys = Object.keys(lastRow).filter(function(key) {
303
+ return key !== 'column_list';
304
+ }).sort();
305
+ // 如果最后一行的 keys 和第一行不同,丢弃最后一行
306
+ if (lastRowKeys.length !== firstRowKeys.length || !lastRowKeys.every(function(key, index) {
307
+ return key === firstRowKeys[index];
308
+ })) {
309
+ return processed.slice(0, -1);
310
+ }
311
+ }
312
+ return processed;
291
313
  }, [
292
314
  dataSourceHash,
293
315
  (_node_otherProps1 = node.otherProps) === null || _node_otherProps1 === void 0 ? void 0 : _node_otherProps1.dataSource
294
316
  ]);
295
317
  var columns = ((_node_otherProps2 = node.otherProps) === null || _node_otherProps2 === void 0 ? void 0 : _node_otherProps2.columns) || [];
318
+ // 检查图表是否未闭合
319
+ var isUnclosed = (node === null || node === void 0 ? void 0 : (_node_otherProps3 = node.otherProps) === null || _node_otherProps3 === void 0 ? void 0 : _node_otherProps3.finish) === false;
320
+ // 获取编辑器更新函数
321
+ var _useMEditor = _sliced_to_array(useMEditor(node), 2), update = _useMEditor[1];
322
+ // 判断是否是最后一个节点
323
+ var isLastNode = useMemo(function() {
324
+ try {
325
+ return store.isLatestNode(node);
326
+ } catch (e) {
327
+ return false;
328
+ }
329
+ }, [
330
+ store,
331
+ node
332
+ ]);
333
+ // 如果不是最后一个节点,且未闭合,立即设置为完成
334
+ useEffect(function() {
335
+ if (isUnclosed && !readonly && !isLastNode) {
336
+ var _node_otherProps;
337
+ // 检查 finish 是否仍然是 false(可能已经被其他逻辑更新)
338
+ if ((node === null || node === void 0 ? void 0 : (_node_otherProps = node.otherProps) === null || _node_otherProps === void 0 ? void 0 : _node_otherProps.finish) === false) {
339
+ update({
340
+ otherProps: _object_spread_props(_object_spread({}, node === null || node === void 0 ? void 0 : node.otherProps), {
341
+ finish: true
342
+ })
343
+ }, node);
344
+ }
345
+ }
346
+ }, [
347
+ isUnclosed,
348
+ readonly,
349
+ isLastNode,
350
+ node,
351
+ update
352
+ ]);
353
+ // 5 秒超时机制:如果是最后一个节点且未闭合,5 秒后自动设置为完成
354
+ useEffect(function() {
355
+ if (isUnclosed && !readonly && isLastNode) {
356
+ var timer = setTimeout(function() {
357
+ var _node_otherProps;
358
+ // 检查 finish 是否仍然是 false(可能已经被其他逻辑更新)
359
+ if ((node === null || node === void 0 ? void 0 : (_node_otherProps = node.otherProps) === null || _node_otherProps === void 0 ? void 0 : _node_otherProps.finish) === false) {
360
+ update({
361
+ otherProps: _object_spread_props(_object_spread({}, node === null || node === void 0 ? void 0 : node.otherProps), {
362
+ finish: true
363
+ })
364
+ }, node);
365
+ }
366
+ }, 5000); // 5 秒超时
367
+ return function() {
368
+ clearTimeout(timer);
369
+ };
370
+ }
371
+ }, [
372
+ isUnclosed,
373
+ readonly,
374
+ isLastNode,
375
+ node,
376
+ update
377
+ ]);
296
378
  var _React_useState = _sliced_to_array(React.useState(2), 2), columnLength = _React_useState[0], setColumnLength = _React_useState[1];
297
379
  var config = [
298
- ((_node_otherProps3 = node.otherProps) === null || _node_otherProps3 === void 0 ? void 0 : _node_otherProps3.config) || node.otherProps
380
+ ((_node_otherProps4 = node.otherProps) === null || _node_otherProps4 === void 0 ? void 0 : _node_otherProps4.config) || node.otherProps
299
381
  ].flat(1);
300
382
  var htmlRef = React.useRef(null);
301
383
  var _React_useState1 = _sliced_to_array(React.useState(256), 2), minWidth = _React_useState1[0], setMinWidth = _React_useState1[1];
@@ -316,7 +398,7 @@ export { ChartFilter, ChartToolBar, downloadChart } from "./components";
316
398
  ]);
317
399
  return useMemo(function() {
318
400
  return /*#__PURE__*/ React.createElement("div", _object_spread_props(_object_spread({
319
- className: 'ant-agentic-md-editor-drag-el'
401
+ "data-drag-el": true
320
402
  }, attributes), {
321
403
  "data-be": 'chart',
322
404
  style: {
@@ -332,7 +414,7 @@ export { ChartFilter, ChartToolBar, downloadChart } from "./components";
332
414
  return store.dragStart(e, markdownContainerRef.current);
333
415
  }
334
416
  }), /*#__PURE__*/ React.createElement(DragHandle, null), /*#__PURE__*/ React.createElement("div", {
335
- className: "ant-agentic-md-editor-chart-box",
417
+ "data-chart-box": true,
336
418
  style: {
337
419
  display: 'flex',
338
420
  flexDirection: 'column',
@@ -426,7 +508,8 @@ export { ChartFilter, ChartToolBar, downloadChart } from "./components";
426
508
  dataTime: rest === null || rest === void 0 ? void 0 : rest.dataTime,
427
509
  groupBy: rest === null || rest === void 0 ? void 0 : rest.groupBy,
428
510
  filterBy: rest === null || rest === void 0 ? void 0 : rest.filterBy,
429
- colorLegend: rest === null || rest === void 0 ? void 0 : rest.colorLegend
511
+ colorLegend: rest === null || rest === void 0 ? void 0 : rest.colorLegend,
512
+ loading: isUnclosed
430
513
  });
431
514
  return dom;
432
515
  });
@@ -440,6 +523,7 @@ export { ChartFilter, ChartToolBar, downloadChart } from "./components";
440
523
  title: rest === null || rest === void 0 ? void 0 : rest.title,
441
524
  dataTime: rest === null || rest === void 0 ? void 0 : rest.dataTime,
442
525
  groupBy: rest === null || rest === void 0 ? void 0 : rest.groupBy,
526
+ loading: isUnclosed,
443
527
  filterBy: rest === null || rest === void 0 ? void 0 : rest.filterBy,
444
528
  colorLegend: rest === null || rest === void 0 ? void 0 : rest.colorLegend,
445
529
  config: {
@@ -489,8 +573,8 @@ export { ChartFilter, ChartToolBar, downloadChart } from "./components";
489
573
  attributes,
490
574
  // 使用更高效的依赖项比较
491
575
  dataSourceHash,
492
- (_node_otherProps4 = node.otherProps) === null || _node_otherProps4 === void 0 ? void 0 : _node_otherProps4.config,
493
- (_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,
576
+ (_node_otherProps5 = node.otherProps) === null || _node_otherProps5 === void 0 ? void 0 : _node_otherProps5.config,
577
+ (_node_otherProps6 = node.otherProps) === null || _node_otherProps6 === void 0 ? void 0 : (_node_otherProps_columns = _node_otherProps6.columns) === null || _node_otherProps_columns === void 0 ? void 0 : _node_otherProps_columns.length,
494
578
  editor,
495
579
  columnLength,
496
580
  readonly,
@@ -0,0 +1,35 @@
1
+ /**
2
+ * 注册 Chart.js 基础组件
3
+ *
4
+ * 用于注册图表所需的基础 Chart.js 组件,包括坐标轴、图例、工具提示等。
5
+ * 使用单例模式确保只注册一次。
6
+ *
7
+ * @param {string[]} components - 要注册的组件名称数组
8
+ * @param {Function} registerFn - 注册函数,接收 ChartJS 作为参数
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * registerChartComponents('line-chart', () => {
13
+ * ChartJS.register(
14
+ * CategoryScale,
15
+ * LinearScale,
16
+ * PointElement,
17
+ * LineElement,
18
+ * Filler,
19
+ * Tooltip,
20
+ * Legend,
21
+ * );
22
+ * });
23
+ * ```
24
+ *
25
+ * @since 1.0.0
26
+ */
27
+ export declare const registerChartComponents: (componentName: string, registerFn: () => void) => void;
28
+ /**
29
+ * 注册折线图/面积图所需的组件
30
+ */
31
+ export declare const registerLineChartComponents: () => void;
32
+ /**
33
+ * 注册柱状图所需的组件
34
+ */
35
+ export declare const registerBarChartComponents: () => void;
@@ -0,0 +1,54 @@
1
+ import { BarElement, CategoryScale, Chart as ChartJS, Filler, Legend, LinearScale, LineElement, PointElement, Tooltip } from "chart.js";
2
+ /**
3
+ * Chart.js 组件注册状态映射
4
+ * 用于跟踪哪些 Chart.js 组件已经被注册,避免重复注册
5
+ */ var registeredComponents = new Set();
6
+ /**
7
+ * 注册 Chart.js 基础组件
8
+ *
9
+ * 用于注册图表所需的基础 Chart.js 组件,包括坐标轴、图例、工具提示等。
10
+ * 使用单例模式确保只注册一次。
11
+ *
12
+ * @param {string[]} components - 要注册的组件名称数组
13
+ * @param {Function} registerFn - 注册函数,接收 ChartJS 作为参数
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * registerChartComponents('line-chart', () => {
18
+ * ChartJS.register(
19
+ * CategoryScale,
20
+ * LinearScale,
21
+ * PointElement,
22
+ * LineElement,
23
+ * Filler,
24
+ * Tooltip,
25
+ * Legend,
26
+ * );
27
+ * });
28
+ * ```
29
+ *
30
+ * @since 1.0.0
31
+ */ export var registerChartComponents = function(componentName, registerFn) {
32
+ if (registeredComponents.has(componentName)) {
33
+ return;
34
+ }
35
+ if (typeof window === 'undefined') {
36
+ return;
37
+ }
38
+ registerFn();
39
+ registeredComponents.add(componentName);
40
+ };
41
+ /**
42
+ * 注册折线图/面积图所需的组件
43
+ */ export var registerLineChartComponents = function() {
44
+ registerChartComponents('line-chart', function() {
45
+ ChartJS.register(CategoryScale, LinearScale, PointElement, LineElement, Filler, Tooltip, Legend);
46
+ });
47
+ };
48
+ /**
49
+ * 注册柱状图所需的组件
50
+ */ export var registerBarChartComponents = function() {
51
+ registerChartComponents('bar-chart', function() {
52
+ ChartJS.register(CategoryScale, LinearScale, BarElement, Tooltip, Legend);
53
+ });
54
+ };
@@ -286,3 +286,22 @@ export declare const getDataHash: (data: any[]) => string;
286
286
  * @since 1.0.0
287
287
  */
288
288
  export declare const isConfigEqual: (config1: any, config2: any) => boolean;
289
+ /**
290
+ * 将十六进制颜色转换为带透明度的 RGBA 字符串
291
+ *
292
+ * 支持3位和6位十六进制颜色格式,并添加透明度。
293
+ *
294
+ * @param {string} hex - 十六进制颜色值(如 '#ff0000' 或 '#f00')
295
+ * @param {number} alpha - 透明度值(0-1之间)
296
+ * @returns {string} RGBA 颜色字符串
297
+ *
298
+ * @example
299
+ * ```typescript
300
+ * hexToRgba('#ff0000', 0.5); // 'rgba(255, 0, 0, 0.5)'
301
+ * hexToRgba('#f00', 0.8); // 'rgba(255, 0, 0, 0.8)'
302
+ * ```
303
+ *
304
+ * @since 1.0.0
305
+ */
306
+ export declare const hexToRgba: (hex: string, alpha: number) => string;
307
+ export { registerChartComponents, registerLineChartComponents, registerBarChartComponents, } from './utils/registerChart';
@@ -436,3 +436,30 @@ var intl = new Intl.NumberFormat('en-US', {
436
436
  }
437
437
  return true;
438
438
  };
439
+ /**
440
+ * 将十六进制颜色转换为带透明度的 RGBA 字符串
441
+ *
442
+ * 支持3位和6位十六进制颜色格式,并添加透明度。
443
+ *
444
+ * @param {string} hex - 十六进制颜色值(如 '#ff0000' 或 '#f00')
445
+ * @param {number} alpha - 透明度值(0-1之间)
446
+ * @returns {string} RGBA 颜色字符串
447
+ *
448
+ * @example
449
+ * ```typescript
450
+ * hexToRgba('#ff0000', 0.5); // 'rgba(255, 0, 0, 0.5)'
451
+ * hexToRgba('#f00', 0.8); // 'rgba(255, 0, 0, 0.8)'
452
+ * ```
453
+ *
454
+ * @since 1.0.0
455
+ */ export var hexToRgba = function(hex, alpha) {
456
+ var sanitized = hex.replace('#', '');
457
+ var isShort = sanitized.length === 3;
458
+ var r = parseInt(isShort ? sanitized[0] + sanitized[0] : sanitized.slice(0, 2), 16);
459
+ var g = parseInt(isShort ? sanitized[1] + sanitized[1] : sanitized.slice(2, 4), 16);
460
+ var b = parseInt(isShort ? sanitized[2] + sanitized[2] : sanitized.slice(4, 6), 16);
461
+ var a = Math.max(0, Math.min(1, alpha));
462
+ return "rgba(".concat(r, ", ").concat(g, ", ").concat(b, ", ").concat(a, ")");
463
+ };
464
+ // 导出 Chart.js 注册相关函数
465
+ export { registerChartComponents, registerLineChartComponents, registerBarChartComponents } from "./utils/registerChart";
@@ -41,8 +41,7 @@ export function CodeContainer(param) {
41
41
  height: hide ? 0 : 'auto',
42
42
  opacity: hide ? 0 : 1
43
43
  },
44
- className: classNames('ace-container', 'code-editor-container', 'drag-el', {
45
- frontmatter: safeElement.frontmatter
46
- })
44
+ "data-frontmatter": safeElement.frontmatter ? '' : undefined,
45
+ className: classNames('ace-container', 'code-editor-container', 'drag-el')
47
46
  }, children));
48
47
  }
@@ -64,6 +64,30 @@ function _object_spread(target) {
64
64
  }
65
65
  return target;
66
66
  }
67
+ function ownKeys(object, enumerableOnly) {
68
+ var keys = Object.keys(object);
69
+ if (Object.getOwnPropertySymbols) {
70
+ var symbols = Object.getOwnPropertySymbols(object);
71
+ if (enumerableOnly) {
72
+ symbols = symbols.filter(function(sym) {
73
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
74
+ });
75
+ }
76
+ keys.push.apply(keys, symbols);
77
+ }
78
+ return keys;
79
+ }
80
+ function _object_spread_props(target, source) {
81
+ source = source != null ? source : {};
82
+ if (Object.getOwnPropertyDescriptors) {
83
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
84
+ } else {
85
+ ownKeys(Object(source)).forEach(function(key) {
86
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
87
+ });
88
+ }
89
+ return target;
90
+ }
67
91
  function _sliced_to_array(arr, i) {
68
92
  return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
69
93
  }
@@ -76,7 +100,7 @@ function _unsupported_iterable_to_array(o, minLen) {
76
100
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
77
101
  }
78
102
  import { ConfigProvider, theme as antdTheme } from "antd";
79
- import React, { useMemo, useState } from "react";
103
+ import React, { useEffect, useMemo, useState } from "react";
80
104
  import { MarkdownEditor } from "../../../MarkdownEditor";
81
105
  import { useEditorStore } from "../../../MarkdownEditor/editor/store";
82
106
  import { useCodeEditorState, useRenderConditions, useToolbarConfig } from "../hooks";
@@ -94,7 +118,7 @@ import { AceEditor, AceEditorContainer, CodeContainer, CodeToolbar, HtmlPreview,
94
118
  * - 响应式布局适配
95
119
  * - 支持代码框选中状态管理
96
120
  */ export function CodeRenderer(props) {
97
- var _editorProps_codeProps;
121
+ var _props_element_otherProps, _props_element, _props_element_otherProps1, _props_element1, _editorProps_codeProps;
98
122
  var _useEditorStore = useEditorStore(), editorProps = _useEditorStore.editorProps, readonly = _useEditorStore.readonly;
99
123
  // 使用状态管理Hook
100
124
  var _useCodeEditorState = useCodeEditorState(props.element), state = _useCodeEditorState.state, update = _useCodeEditorState.update, path = _useCodeEditorState.path, handleCloseClick = _useCodeEditorState.handleCloseClick, handleHtmlPreviewClose = _useCodeEditorState.handleHtmlPreviewClose, handleShowBorderChange = _useCodeEditorState.handleShowBorderChange, handleHideChange = _useCodeEditorState.handleHideChange;
@@ -133,6 +157,33 @@ import { AceEditor, AceEditorContainer, CodeContainer, CodeToolbar, HtmlPreview,
133
157
  onViewModeToggle: handleViewModeToggle,
134
158
  viewMode: viewMode
135
159
  }).toolbarProps;
160
+ // 检查代码块是否未闭合
161
+ var isUnclosed = ((_props_element = props.element) === null || _props_element === void 0 ? void 0 : (_props_element_otherProps = _props_element.otherProps) === null || _props_element_otherProps === void 0 ? void 0 : _props_element_otherProps.finish) === false;
162
+ // 5 秒超时机制:如果代码块未闭合,5 秒后自动设置为完成
163
+ useEffect(function() {
164
+ if (isUnclosed && !readonly) {
165
+ var timer = setTimeout(function() {
166
+ var _props_element_otherProps, _props_element;
167
+ // 检查 finish 是否仍然是 false(可能已经被其他逻辑更新)
168
+ if (((_props_element = props.element) === null || _props_element === void 0 ? void 0 : (_props_element_otherProps = _props_element.otherProps) === null || _props_element_otherProps === void 0 ? void 0 : _props_element_otherProps.finish) === false) {
169
+ var _props_element1;
170
+ update({
171
+ otherProps: _object_spread_props(_object_spread({}, (_props_element1 = props.element) === null || _props_element1 === void 0 ? void 0 : _props_element1.otherProps), {
172
+ finish: true
173
+ })
174
+ });
175
+ }
176
+ }, 5000); // 5 秒超时
177
+ return function() {
178
+ clearTimeout(timer);
179
+ };
180
+ }
181
+ }, [
182
+ isUnclosed,
183
+ readonly,
184
+ (_props_element1 = props.element) === null || _props_element1 === void 0 ? void 0 : (_props_element_otherProps1 = _props_element1.otherProps) === null || _props_element_otherProps1 === void 0 ? void 0 : _props_element_otherProps1.finish,
185
+ update
186
+ ]);
136
187
  // 渲染组件
137
188
  return useMemo(function() {
138
189
  // 隐藏配置型 HTML 代码块
@@ -6,8 +6,9 @@
6
6
  import { ChevronsUpDown, Copy, Moon } from "@sofa-design/icons";
7
7
  import { message, Segmented } from "antd";
8
8
  import copy from "copy-to-clipboard";
9
- import React, { useContext } from "react";
9
+ import React, { useContext, useMemo } from "react";
10
10
  import { ActionIconBox } from "../../../Components/ActionIconBox";
11
+ import { Loading } from "../../../Components/Loading";
11
12
  import { I18nContext } from "../../../I18n";
12
13
  import { langIconMap } from "../langIconMap";
13
14
  import { LanguageSelector } from "./LanguageSelector";
@@ -40,10 +41,17 @@ import { LoadImage } from "./LoadImage";
40
41
  * />
41
42
  * ```
42
43
  */ export var CodeToolbar = function(props) {
43
- var _element_language, _element_language1, _i18n_locale, _i18n_locale1;
44
+ var _element_otherProps, _element_language, _element_language1, _i18n_locale, _i18n_locale1;
44
45
  // 获取国际化上下文
45
46
  var i18n = useContext(I18nContext);
46
47
  var element = props.element, readonly = props.readonly, onCloseClick = props.onCloseClick, languageSelectorProps = props.languageSelectorProps, onViewModeToggle = props.onViewModeToggle, theme = props.theme, isExpanded = props.isExpanded, onExpandToggle = props.onExpandToggle, setTheme = props.setTheme, _props_viewMode = props.viewMode, viewMode = _props_viewMode === void 0 ? 'code' : _props_viewMode;
48
+ // 检查代码块是否未闭合 - 使用 useMemo 确保正确响应变化
49
+ var isUnclosed = useMemo(function() {
50
+ var _element_otherProps;
51
+ return (element === null || element === void 0 ? void 0 : (_element_otherProps = element.otherProps) === null || _element_otherProps === void 0 ? void 0 : _element_otherProps.finish) === false;
52
+ }, [
53
+ element === null || element === void 0 ? void 0 : (_element_otherProps = element.otherProps) === null || _element_otherProps === void 0 ? void 0 : _element_otherProps.finish
54
+ ]);
47
55
  return /*#__PURE__*/ React.createElement("div", {
48
56
  "data-testid": "code-toolbar",
49
57
  contentEditable: false,
@@ -72,6 +80,12 @@ import { LoadImage } from "./LoadImage";
72
80
  userSelect: 'none',
73
81
  borderBottom: isExpanded ? theme === 'chaos' ? '1px solid #161616' : '1px solid var(--color-gray-border-light)' : 'none'
74
82
  }
83
+ }, /*#__PURE__*/ React.createElement("div", {
84
+ style: {
85
+ display: 'flex',
86
+ alignItems: 'center',
87
+ gap: 8
88
+ }
75
89
  }, readonly ? // 只读模式:仅显示当前语言信息
76
90
  /*#__PURE__*/ React.createElement("div", {
77
91
  style: {
@@ -98,7 +112,12 @@ import { LoadImage } from "./LoadImage";
98
112
  },
99
113
  src: langIconMap.get(((_element_language1 = element.language) === null || _element_language1 === void 0 ? void 0 : _element_language1.toLowerCase()) || '')
100
114
  })), /*#__PURE__*/ React.createElement("div", null, element.language ? /*#__PURE__*/ React.createElement("span", null, element.katex ? 'Formula' : element.language === 'html' && element.render ? 'Html Renderer' : element.language) : /*#__PURE__*/ React.createElement("span", null, 'plain text'))) : // 非只读模式:显示语言选择器
101
- /*#__PURE__*/ React.createElement(LanguageSelector, languageSelectorProps), /*#__PURE__*/ React.createElement("div", {
115
+ /*#__PURE__*/ React.createElement(LanguageSelector, languageSelectorProps), isUnclosed && /*#__PURE__*/ React.createElement(Loading, {
116
+ style: {
117
+ fontSize: '14px',
118
+ flexShrink: 0
119
+ }
120
+ })), /*#__PURE__*/ React.createElement("div", {
102
121
  style: {
103
122
  display: 'flex',
104
123
  gap: 5,
@@ -221,7 +221,7 @@ function _ts_generator(thisArg, body) {
221
221
  }
222
222
  }
223
223
  import classNames from "classnames";
224
- import React, { useEffect, useRef, useState, startTransition } from "react";
224
+ import React, { startTransition, useEffect, useRef, useState } from "react";
225
225
  import { Editor, Node, Transforms } from "slate";
226
226
  import { useEditorStore } from "../../MarkdownEditor/editor/store";
227
227
  import { useSelStatus } from "../../MarkdownEditor/hooks/editor";
@@ -169,7 +169,7 @@ function _ts_generator(thisArg, body) {
169
169
  }
170
170
  }
171
171
  import classNames from "classnames";
172
- import React, { useEffect, useRef, useState, startTransition } from "react";
172
+ import React, { startTransition, useEffect, useRef, useState } from "react";
173
173
  import { useGetSetState } from "react-use";
174
174
  import { loadKatex } from "./loadKatex";
175
175
  /**