@ant-design/agentic-ui 2.16.0 → 2.17.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.
Files changed (56) hide show
  1. package/dist/MarkdownEditor/editor/elements/Code.js +11 -6
  2. package/dist/MarkdownEditor/editor/elements/Image/index.js +17 -5
  3. package/dist/MarkdownEditor/editor/elements/Media.js +61 -9
  4. package/dist/MarkdownEditor/editor/elements/Table/ReadonlyTableComponent.js +15 -3
  5. package/dist/MarkdownEditor/editor/elements/Table/SimpleTable.js +17 -2
  6. package/dist/MarkdownEditor/editor/elements/Table/Table.js +131 -5
  7. package/dist/MarkdownEditor/editor/parser/parserMarkdownToSlateNode.d.ts +100 -1
  8. package/dist/MarkdownEditor/editor/parser/parserMarkdownToSlateNode.js +945 -284
  9. package/dist/MarkdownEditor/editor/style.js +5 -0
  10. package/dist/MarkdownEditor/editor/types/Table.d.ts +1 -0
  11. package/dist/MarkdownEditor/editor/utils/findMatchingClose.d.ts +36 -0
  12. package/dist/MarkdownEditor/editor/utils/findMatchingClose.js +158 -0
  13. package/dist/MarkdownEditor/editor/utils/markdownToHtml.d.ts +41 -2
  14. package/dist/MarkdownEditor/editor/utils/markdownToHtml.js +159 -7
  15. package/dist/Plugins/chart/AreaChart/index.d.ts +12 -0
  16. package/dist/Plugins/chart/AreaChart/index.js +14 -188
  17. package/dist/Plugins/chart/BarChart/index.d.ts +2 -0
  18. package/dist/Plugins/chart/BarChart/index.js +3 -12
  19. package/dist/Plugins/chart/ChartMark/Container.js +5 -2
  20. package/dist/Plugins/chart/ChartRender.d.ts +1 -0
  21. package/dist/Plugins/chart/ChartRender.js +104 -43
  22. package/dist/Plugins/chart/DonutChart/index.js +4 -2
  23. package/dist/Plugins/chart/DonutChart/types.d.ts +2 -0
  24. package/dist/Plugins/chart/FunnelChart/index.d.ts +2 -0
  25. package/dist/Plugins/chart/FunnelChart/index.js +4 -2
  26. package/dist/Plugins/chart/LineChart/index.d.ts +2 -0
  27. package/dist/Plugins/chart/LineChart/index.js +17 -162
  28. package/dist/Plugins/chart/RadarChart/index.d.ts +2 -0
  29. package/dist/Plugins/chart/RadarChart/index.js +8 -4
  30. package/dist/Plugins/chart/ScatterChart/index.d.ts +2 -0
  31. package/dist/Plugins/chart/ScatterChart/index.js +8 -4
  32. package/dist/Plugins/chart/components/ChartContainer/ChartContainer.d.ts +1 -0
  33. package/dist/Plugins/chart/components/ChartFilter/ChartFilter.d.ts +1 -1
  34. package/dist/Plugins/chart/components/ChartFilter/ChartFilter.js +210 -16
  35. package/dist/Plugins/chart/components/ChartToolBar/ChartToolBar.d.ts +2 -0
  36. package/dist/Plugins/chart/components/ChartToolBar/ChartToolBar.js +9 -2
  37. package/dist/Plugins/chart/components/ChartToolBar/style.js +3 -1
  38. package/dist/Plugins/chart/hooks/index.d.ts +10 -0
  39. package/dist/Plugins/chart/hooks/index.js +8 -0
  40. package/dist/Plugins/chart/hooks/useChartDataFilter.d.ts +46 -0
  41. package/dist/Plugins/chart/hooks/useChartDataFilter.js +182 -0
  42. package/dist/Plugins/chart/hooks/useChartStatistics.d.ts +17 -0
  43. package/dist/Plugins/chart/hooks/useChartStatistics.js +25 -0
  44. package/dist/Plugins/chart/hooks/useChartTheme.d.ts +20 -0
  45. package/dist/Plugins/chart/hooks/useChartTheme.js +30 -0
  46. package/dist/Plugins/chart/hooks/useResponsiveSize.d.ts +23 -0
  47. package/dist/Plugins/chart/hooks/useResponsiveSize.js +94 -0
  48. package/dist/Plugins/chart/index.js +92 -8
  49. package/dist/Plugins/chart/utils/registerChart.d.ts +35 -0
  50. package/dist/Plugins/chart/utils/registerChart.js +54 -0
  51. package/dist/Plugins/chart/utils.d.ts +19 -0
  52. package/dist/Plugins/chart/utils.js +27 -0
  53. package/dist/Plugins/code/components/CodeRenderer.js +53 -2
  54. package/dist/Plugins/code/components/CodeToolbar.js +22 -3
  55. package/dist/Plugins/mermaid/Mermaid.js +66 -66
  56. package/package.json +1 -1
@@ -12,6 +12,25 @@ function _array_with_holes(arr) {
12
12
  function _array_without_holes(arr) {
13
13
  if (Array.isArray(arr)) return _array_like_to_array(arr);
14
14
  }
15
+ function _class_call_check(instance, Constructor) {
16
+ if (!(instance instanceof Constructor)) {
17
+ throw new TypeError("Cannot call a class as a function");
18
+ }
19
+ }
20
+ function _defineProperties(target, props) {
21
+ for(var i = 0; i < props.length; i++){
22
+ var descriptor = props[i];
23
+ descriptor.enumerable = descriptor.enumerable || false;
24
+ descriptor.configurable = true;
25
+ if ("value" in descriptor) descriptor.writable = true;
26
+ Object.defineProperty(target, descriptor.key, descriptor);
27
+ }
28
+ }
29
+ function _create_class(Constructor, protoProps, staticProps) {
30
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
31
+ if (staticProps) _defineProperties(Constructor, staticProps);
32
+ return Constructor;
33
+ }
15
34
  function _define_property(obj, key, value) {
16
35
  if (key in obj) {
17
36
  Object.defineProperty(obj, key, {
@@ -124,6 +143,7 @@ import remarkRehype from "remark-rehype";
124
143
  import { fixStrongWithSpecialChars } from "./remarkParse";
125
144
  import { htmlToFragmentList } from "../plugins/insertParsedHtmlNodes";
126
145
  import { EditorUtils } from "../utils";
146
+ import { isCodeBlockLikelyComplete } from "../utils/findMatchingClose";
127
147
  import partialJsonParse from "./json-parse";
128
148
  import mdastParser from "./remarkParse";
129
149
  // 常量定义
@@ -134,6 +154,10 @@ var MIN_TABLE_CELL_LENGTH = 5; // 表格单元格最小长度
134
154
  var INLINE_MATH_SUFFIX_PATTERN = '(?:%|[kKmMbB]|千|万|亿|兆|万亿|百万|亿万)?';
135
155
  var INLINE_MATH_CURRENCY_PATTERN = new RegExp("^[+-]?\\d{1,3}(?:,\\d{3})*(?:\\.\\d+)?".concat(INLINE_MATH_SUFFIX_PATTERN, "$"));
136
156
  var INLINE_MATH_SIMPLE_NUMBER_PATTERN = new RegExp("^[+-]?\\d+(?:\\.\\d+)?".concat(INLINE_MATH_SUFFIX_PATTERN, "$"));
157
+ // HTML 转义和代码块检测相关的常量
158
+ var NOT_SPACE_START = /^\S*/;
159
+ var ENDING_NEWLINE = /\n$/;
160
+ var FENCED_CODE_REGEX = /^(`{3,}|~{3,})/;
137
161
  var shouldTreatInlineMathAsText = function(rawValue) {
138
162
  var trimmedValue = rawValue.trim();
139
163
  if (!trimmedValue) {
@@ -206,6 +230,17 @@ var isNumericValue = function(value) {
206
230
  ;
207
231
  });
208
232
  };
233
+ /**
234
+ * 规范化字段名,统一处理转义字符
235
+ * 将 `index\_value` 转换为 `index_value`,确保字段名一致
236
+ * @param fieldName - 原始字段名
237
+ * @returns 规范化后的字段名
238
+ */ var normalizeFieldName = function(fieldName) {
239
+ if (!fieldName) return fieldName;
240
+ // 移除转义字符:将 `\_` 转换为 `_`,`\\` 转换为 `\`
241
+ return fieldName.replace(/\\_/g, '_').replace(/\\\\/g, '\\').replace(/\\(?=")/g, '') // 移除转义的双引号
242
+ .trim();
243
+ };
209
244
  var getColumnAlignment = function(data, columns) {
210
245
  if (!data.length) return [];
211
246
  // 缓存上一次的对齐结果,避免频繁切换
@@ -478,8 +513,8 @@ var parseText = function(els) {
478
513
  }
479
514
  return leafs;
480
515
  };
481
- var parseTableOrChart = function(table, preNode, plugins) {
482
- var _table_children, _tableHeader_children, _table_children_slice, _table_children1, _table_align, _config_at, _config_at1;
516
+ var parseTableOrChart = function(table, preNode, plugins, parserConfig) {
517
+ var _table_children, _tableHeader_children, _table_children_slice, _table_children1, _table_align, _config_at, _config_at1, _table_otherProps;
483
518
  var keyMap = new Map();
484
519
  // @ts-ignore
485
520
  var config = // @ts-ignore
@@ -496,13 +531,14 @@ var parseTableOrChart = function(table, preNode, plugins) {
496
531
  ]
497
532
  })) === null || _myRemark_stringify === void 0 ? void 0 : _myRemark_stringify.replace(/\n/g, '').trim();
498
533
  }).map(function(title) {
499
- return (title === null || title === void 0 ? void 0 : title.replaceAll('\\', '')) || ' ';
534
+ // 先规范化字段名,统一处理转义字符
535
+ var normalizedTitle = normalizeFieldName(title || ' ');
536
+ return normalizedTitle;
500
537
  }).map(function(title, index) {
501
538
  if (keyMap.has(title)) {
502
- var _title_replace_replace_replace, _title_replace_replace, _title_replace;
503
539
  keyMap.set(title, keyMap.get(title) + '_' + index);
504
540
  return {
505
- title: title === null || title === void 0 ? void 0 : (_title_replace = title.replace(/\n/g, '')) === null || _title_replace === void 0 ? void 0 : (_title_replace_replace = _title_replace.replace(/\\(?=")/g, '')) === null || _title_replace_replace === void 0 ? void 0 : (_title_replace_replace_replace = _title_replace_replace.replace(/\\_/g, '')) === null || _title_replace_replace_replace === void 0 ? void 0 : _title_replace_replace_replace.trim(),
541
+ title: title,
506
542
  dataIndex: title + '_' + index,
507
543
  key: title + '_' + index
508
544
  };
@@ -590,7 +626,7 @@ var parseTableOrChart = function(table, preNode, plugins) {
590
626
  children: ((_c_children = c.children) === null || _c_children === void 0 ? void 0 : _c_children.length) ? [
591
627
  {
592
628
  type: 'paragraph',
593
- children: parseNodes(c.children, plugins, false, c)
629
+ children: parseNodes(c.children, plugins, false, c, parserConfig)
594
630
  }
595
631
  ] : [
596
632
  {
@@ -606,6 +642,9 @@ var parseTableOrChart = function(table, preNode, plugins) {
606
642
  })
607
643
  };
608
644
  });
645
+ // 检查表格是否完成(未闭合)
646
+ // 如果 table 节点有 otherProps.finish,使用它;否则默认为 false(未完成)
647
+ var isFinished = (table === null || table === void 0 ? void 0 : (_table_otherProps = table.otherProps) === null || _table_otherProps === void 0 ? void 0 : _table_otherProps.finish) !== undefined ? table.otherProps.finish : false;
609
648
  var otherProps = _object_spread_props(_object_spread({}, isChart ? {
610
649
  config: config
611
650
  } : config), {
@@ -613,7 +652,8 @@ var parseTableOrChart = function(table, preNode, plugins) {
613
652
  dataSource: dataSource.map(function(item) {
614
653
  item === null || item === void 0 ? true : delete item.chartType;
615
654
  return _object_spread({}, item);
616
- })
655
+ }),
656
+ finish: isFinished
617
657
  });
618
658
  var node = {
619
659
  type: isChart ? 'chart' : 'table',
@@ -626,12 +666,12 @@ var parseTableOrChart = function(table, preNode, plugins) {
626
666
  * 处理标题节点
627
667
  * @param currentElement - 当前处理的标题元素,包含depth和children属性
628
668
  * @returns 返回格式化的标题节点对象
629
- */ var handleHeading = function(currentElement, plugins) {
669
+ */ var handleHeading = function(currentElement, plugins, parserConfig) {
630
670
  var _currentElement_children;
631
671
  return {
632
672
  type: 'head',
633
673
  level: currentElement.depth,
634
- children: ((_currentElement_children = currentElement.children) === null || _currentElement_children === void 0 ? void 0 : _currentElement_children.length) ? parseNodes(currentElement.children, plugins, false, currentElement) : [
674
+ children: ((_currentElement_children = currentElement.children) === null || _currentElement_children === void 0 ? void 0 : _currentElement_children.length) ? parseNodes(currentElement.children, plugins, false, currentElement, parserConfig) : [
635
675
  {
636
676
  text: ''
637
677
  }
@@ -676,66 +716,86 @@ export var decodeURIComponentUrl = function(url) {
676
716
  'listItem',
677
717
  'blockquote'
678
718
  ].includes(parent.type)) {
679
- // 检查是否为 <think> 标签
680
- var thinkElement = findThinkElement(currentElement.value);
681
- if (thinkElement) {
682
- // <think> 标签转换为 think 类型的代码块
683
- el = {
684
- type: 'code',
685
- language: 'think',
686
- value: thinkElement.content,
719
+ // 检查是否为不完整的图片标记
720
+ var incompleteImageMatch = currentElement.value.match(/<incomplete-image\s+data-raw="([^"]+)"\s*\/?>/);
721
+ if (incompleteImageMatch) {
722
+ var rawMarkdown = decodeURIComponent(incompleteImageMatch[1]);
723
+ // 直接创建带有 loading 状态的图片节点(不通过 createMediaNode,因为 URL 为空)
724
+ el = EditorUtils.wrapperCardNode({
725
+ type: 'image',
726
+ url: '',
727
+ mediaType: 'image',
728
+ alt: rawMarkdown,
729
+ loading: true,
730
+ rawMarkdown: rawMarkdown,
687
731
  children: [
688
732
  {
689
- text: thinkElement.content
733
+ text: ''
690
734
  }
691
735
  ]
692
- };
736
+ });
693
737
  } else {
694
- // 检查是否为 <answer> 标签
695
- var answerElement = findAnswerElement(currentElement.value);
696
- if (answerElement) {
697
- // 将 <answer> 标签的内容作为普通文本
738
+ // 检查是否为 <think> 标签
739
+ var thinkElement = findThinkElement(currentElement.value);
740
+ if (thinkElement) {
741
+ // 将 <think> 标签转换为 think 类型的代码块
698
742
  el = {
699
- text: answerElement.content
743
+ type: 'code',
744
+ language: 'think',
745
+ value: thinkElement.content,
746
+ children: [
747
+ {
748
+ text: thinkElement.content
749
+ }
750
+ ]
700
751
  };
701
752
  } else {
702
- var mediaElement = findImageElement(currentElement.value);
703
- if (mediaElement) {
704
- el = createMediaNodeFromElement(mediaElement);
705
- } else if (currentElement.value === '<br/>') {
753
+ // 检查是否为 <answer> 标签
754
+ var answerElement = findAnswerElement(currentElement.value);
755
+ if (answerElement) {
756
+ // <answer> 标签的内容作为普通文本
706
757
  el = {
707
- type: 'paragraph',
708
- children: [
709
- {
710
- text: ''
711
- }
712
- ]
758
+ text: answerElement.content
713
759
  };
714
- } else if (currentElement.value.match(/^<\/(img|video|iframe)>/)) {
715
- // 如果是媒体标签的结束标签,跳过处理
716
- el = null;
717
760
  } else {
718
- // 检查是否为注释(注释需要特殊处理以提取配置)
719
- var isComment = currentElement.value.trim().startsWith('<!--') && currentElement.value.trim().endsWith('-->');
720
- // 检查是否为标准 HTML 元素或注释
721
- if (isComment || isStandardHtmlElement(currentElement.value)) {
722
- // 标准 HTML 元素或注释:按原逻辑处理
723
- el = currentElement.value.match(/<\/?(table|div|ul|li|ol|p|strong)[^\n>]*?>/) ? htmlToFragmentList(currentElement.value, '') : {
724
- type: 'code',
725
- language: 'html',
726
- render: true,
727
- value: currentElement.value,
761
+ var mediaElement = findImageElement(currentElement.value);
762
+ if (mediaElement) {
763
+ el = createMediaNodeFromElement(mediaElement);
764
+ } else if (currentElement.value === '<br/>') {
765
+ el = {
766
+ type: 'paragraph',
728
767
  children: [
729
768
  {
730
- text: currentElement.value
769
+ text: ''
731
770
  }
732
771
  ]
733
772
  };
773
+ } else if (currentElement.value.match(/^<\/(img|video|iframe)>/)) {
774
+ // 如果是媒体标签的结束标签,跳过处理
775
+ el = null;
734
776
  } else {
735
- // 非标准元素(如自定义标签):当作普通文本处理
736
- el = {
737
- text: currentElement.value
738
- };
777
+ // 检查是否为注释(注释需要特殊处理以提取配置)
778
+ var isComment = currentElement.value.trim().startsWith('<!--') && currentElement.value.trim().endsWith('-->');
779
+ // 检查是否为标准 HTML 元素或注释
780
+ if (isComment || isStandardHtmlElement(currentElement.value)) {
781
+ // 标准 HTML 元素或注释:按原逻辑处理
782
+ el = currentElement.value.match(/<\/?(table|div|ul|li|ol|p|strong)[^\n>]*?>/) ? htmlToFragmentList(currentElement.value, '') : {
783
+ type: 'code',
784
+ language: 'html',
785
+ render: true,
786
+ value: currentElement.value,
787
+ children: [
788
+ {
789
+ text: currentElement.value
790
+ }
791
+ ]
792
+ };
793
+ } else {
794
+ // 非标准元素(如自定义标签):当作普通文本处理
795
+ el = {
796
+ text: currentElement.value
797
+ };
798
+ }
739
799
  }
740
800
  }
741
801
  }
@@ -781,6 +841,25 @@ export var decodeURIComponentUrl = function(url) {
781
841
  text: answerElement.content
782
842
  };
783
843
  }
844
+ // 检查是否为不完整的图片标记
845
+ var incompleteImageMatch = currentElement.value.match(/<incomplete-image\s+data-raw="([^"]+)"\s*\/?>/);
846
+ if (incompleteImageMatch) {
847
+ var rawMarkdown = decodeURIComponent(incompleteImageMatch[1]);
848
+ // 直接创建带有 loading 状态的图片节点(不通过 createMediaNode,因为 URL 为空)
849
+ return EditorUtils.wrapperCardNode({
850
+ type: 'image',
851
+ url: '',
852
+ mediaType: 'image',
853
+ alt: rawMarkdown,
854
+ loading: true,
855
+ rawMarkdown: rawMarkdown,
856
+ children: [
857
+ {
858
+ text: ''
859
+ }
860
+ ]
861
+ });
862
+ }
784
863
  // 检查是否为非标准 HTML 元素,如果是则直接当作文本
785
864
  if (!isStandardHtmlElement(currentElement.value)) {
786
865
  return {
@@ -916,13 +995,13 @@ export var decodeURIComponentUrl = function(url) {
916
995
  * 处理列表节点
917
996
  * @param currentElement - 当前处理的列表元素,包含ordered、start等属性
918
997
  * @returns 返回格式化的列表节点对象
919
- */ var handleList = function(currentElement, plugins) {
998
+ */ var handleList = function(currentElement, plugins, parserConfig) {
920
999
  var _el_children;
921
1000
  var el = {
922
1001
  type: 'list',
923
1002
  order: currentElement.ordered,
924
1003
  start: currentElement.start,
925
- children: parseNodes(currentElement.children, plugins, false, currentElement)
1004
+ children: parseNodes(currentElement.children, plugins, false, currentElement, parserConfig)
926
1005
  };
927
1006
  el.task = (_el_children = el.children) === null || _el_children === void 0 ? void 0 : _el_children.some(function(s) {
928
1007
  return typeof s.checked === 'boolean';
@@ -945,9 +1024,9 @@ export var decodeURIComponentUrl = function(url) {
945
1024
  * 处理脚注定义
946
1025
  * @param currentElement - 当前处理的脚注定义元素
947
1026
  * @returns 返回格式化的脚注定义节点对象
948
- */ var handleFootnoteDefinition = function(currentElement, plugins) {
1027
+ */ var handleFootnoteDefinition = function(currentElement, plugins, parserConfig) {
949
1028
  var _parseNodes, _linkNode_children;
950
- var linkNode = (_parseNodes = parseNodes(currentElement.children, plugins, false, currentElement)) === null || _parseNodes === void 0 ? void 0 : _parseNodes.at(0);
1029
+ var linkNode = (_parseNodes = parseNodes(currentElement.children, plugins, false, currentElement, parserConfig)) === null || _parseNodes === void 0 ? void 0 : _parseNodes.at(0);
951
1030
  var cellNode = linkNode === null || linkNode === void 0 ? void 0 : (_linkNode_children = linkNode.children) === null || _linkNode_children === void 0 ? void 0 : _linkNode_children.at(0);
952
1031
  return {
953
1032
  value: cellNode === null || cellNode === void 0 ? void 0 : cellNode.text,
@@ -963,9 +1042,9 @@ export var decodeURIComponentUrl = function(url) {
963
1042
  * 处理列表项节点
964
1043
  * @param currentElement - 当前处理的列表项元素
965
1044
  * @returns 返回格式化的列表项节点对象,包含复选框状态和提及信息
966
- */ var handleListItem = function(currentElement, plugins) {
1045
+ */ var handleListItem = function(currentElement, plugins, parserConfig) {
967
1046
  var _currentElement_children, _currentElement_children__children_, _currentElement_children__children, _currentElement_children_, _currentElement_children1, _currentElement_children__children1, _currentElement_children_1, _currentElement_children2, _children__children_;
968
- var children = ((_currentElement_children = currentElement.children) === null || _currentElement_children === void 0 ? void 0 : _currentElement_children.length) ? parseNodes(currentElement.children, plugins, false, currentElement) : [
1047
+ var children = ((_currentElement_children = currentElement.children) === null || _currentElement_children === void 0 ? void 0 : _currentElement_children.length) ? parseNodes(currentElement.children, plugins, false, currentElement, parserConfig) : [
969
1048
  {
970
1049
  type: 'paragraph',
971
1050
  children: [
@@ -1082,7 +1161,7 @@ export var decodeURIComponentUrl = function(url) {
1082
1161
  };
1083
1162
  /**
1084
1163
  * 处理段落中的子元素
1085
- */ var processParagraphChildren = function(currentElement, plugins) {
1164
+ */ var processParagraphChildren = function(currentElement, plugins, parserConfig) {
1086
1165
  var elements = [];
1087
1166
  var textNodes = [];
1088
1167
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
@@ -1094,7 +1173,7 @@ export var decodeURIComponentUrl = function(url) {
1094
1173
  if (textNodes.length) {
1095
1174
  elements.push({
1096
1175
  type: 'paragraph',
1097
- children: parseNodes(textNodes, plugins, false, currentElement)
1176
+ children: parseNodes(textNodes, plugins, false, currentElement, parserConfig)
1098
1177
  });
1099
1178
  textNodes = [];
1100
1179
  }
@@ -1141,7 +1220,7 @@ export var decodeURIComponentUrl = function(url) {
1141
1220
  if (textNodes.length) {
1142
1221
  elements.push({
1143
1222
  type: 'paragraph',
1144
- children: parseNodes(textNodes, plugins, false, currentElement)
1223
+ children: parseNodes(textNodes, plugins, false, currentElement, undefined)
1145
1224
  });
1146
1225
  }
1147
1226
  return elements;
@@ -1152,7 +1231,7 @@ export var decodeURIComponentUrl = function(url) {
1152
1231
  * @param config - 配置对象,包含样式和行为设置
1153
1232
  * @param plugins - 插件数组
1154
1233
  * @returns 返回格式化的段落节点对象或元素数组
1155
- */ var handleParagraph = function(currentElement, config, plugins) {
1234
+ */ var handleParagraph = function(currentElement, config, plugins, parserConfig) {
1156
1235
  var _currentElement_children, _currentElement_children_at, _currentElement_children1;
1157
1236
  // 检查是否是附件链接
1158
1237
  if (((_currentElement_children = currentElement.children) === null || _currentElement_children === void 0 ? void 0 : _currentElement_children[0].type) === 'html' && currentElement.children[0].value.startsWith('<a')) {
@@ -1164,7 +1243,7 @@ export var decodeURIComponentUrl = function(url) {
1164
1243
  return handleLinkCard(currentElement, config);
1165
1244
  }
1166
1245
  // 处理混合内容段落
1167
- return processParagraphChildren(currentElement, plugins);
1246
+ return processParagraphChildren(currentElement, plugins, parserConfig);
1168
1247
  };
1169
1248
  /**
1170
1249
  * 处理内联代码节点
@@ -1205,7 +1284,34 @@ export var decodeURIComponentUrl = function(url) {
1205
1284
  * @param currentElement - 当前处理的代码块元素,包含语言和内容
1206
1285
  * @returns 返回格式化的代码块节点对象,根据语言类型进行特殊处理
1207
1286
  */ var handleCode = function(currentElement) {
1208
- var _currentElement_value_trim;
1287
+ var _match, _currentElement_otherProps, _currentElement_value_trim;
1288
+ var rawValue = currentElement.value || '';
1289
+ var langString = ((_match = (currentElement.lang || '').match(NOT_SPACE_START)) === null || _match === void 0 ? void 0 : _match[0]) || '';
1290
+ var code = "".concat(rawValue.replace(ENDING_NEWLINE, ''), "\n");
1291
+ // 检查代码块是否完整
1292
+ // 如果是缩进代码块,认为是完整的(因为没有结束标记)
1293
+ var isIndentedCode = currentElement.meta === 'indented';
1294
+ // 使用更智能的方法判断代码块是否完整
1295
+ var streamStatus = 'loading';
1296
+ if (isIndentedCode) {
1297
+ // 缩进代码块没有结束标记,认为是完整的
1298
+ streamStatus = 'done';
1299
+ } else {
1300
+ // 对于围栏代码块,使用多种方法判断
1301
+ var endsWithNewline = code.match(ENDING_NEWLINE);
1302
+ // 如果代码以换行结尾,可能是完整的
1303
+ if (endsWithNewline) {
1304
+ // 进一步检查代码内容是否完整(特别是对于 Mermaid 等需要完整语法的情况)
1305
+ var isLikelyComplete = isCodeBlockLikelyComplete(rawValue, currentElement.lang);
1306
+ streamStatus = isLikelyComplete ? 'done' : 'loading';
1307
+ } else {
1308
+ // 没有换行结尾,肯定不完整
1309
+ streamStatus = 'loading';
1310
+ }
1311
+ }
1312
+ // 如果已经在 parseNodes 中设置了 finish(基于是否是最后一个节点),优先使用它
1313
+ // 否则使用 streamStatus 判断
1314
+ var finishValue = ((_currentElement_otherProps = currentElement.otherProps) === null || _currentElement_otherProps === void 0 ? void 0 : _currentElement_otherProps.finish) !== undefined ? currentElement.otherProps.finish : streamStatus === 'done';
1209
1315
  var baseCodeElement = {
1210
1316
  type: 'code',
1211
1317
  language: currentElement.lang === 'apaasify' ? 'apaasify' : currentElement.lang,
@@ -1216,10 +1322,27 @@ export var decodeURIComponentUrl = function(url) {
1216
1322
  {
1217
1323
  text: currentElement.value
1218
1324
  }
1219
- ]
1325
+ ],
1326
+ // 添加流式状态支持
1327
+ otherProps: _object_spread(_object_spread_props(_object_spread({}, currentElement.otherProps || {}), {
1328
+ 'data-block': 'true',
1329
+ 'data-state': streamStatus,
1330
+ // 优先使用 parseNodes 中设置的 finish,否则使用 streamStatus 判断
1331
+ finish: finishValue
1332
+ }), langString ? {
1333
+ 'data-language': langString
1334
+ } : {})
1220
1335
  };
1221
1336
  var handler = LANGUAGE_HANDLERS[currentElement.lang];
1222
- return handler ? handler(baseCodeElement, currentElement.value) : baseCodeElement;
1337
+ var result = handler ? handler(baseCodeElement, currentElement.value) : baseCodeElement;
1338
+ // 确保 otherProps 被保留
1339
+ var resultWithProps = result;
1340
+ if (baseCodeElement.otherProps && !resultWithProps.otherProps) {
1341
+ resultWithProps.otherProps = baseCodeElement.otherProps;
1342
+ } else if (baseCodeElement.otherProps && resultWithProps.otherProps) {
1343
+ resultWithProps.otherProps = _object_spread({}, resultWithProps.otherProps, baseCodeElement.otherProps);
1344
+ }
1345
+ return resultWithProps;
1223
1346
  };
1224
1347
  /**
1225
1348
  * 处理YAML节点
@@ -1242,11 +1365,11 @@ export var decodeURIComponentUrl = function(url) {
1242
1365
  * 处理引用块节点
1243
1366
  * @param currentElement - 当前处理的引用块元素
1244
1367
  * @returns 返回格式化的引用块节点对象
1245
- */ var handleBlockquote = function(currentElement, plugins) {
1368
+ */ var handleBlockquote = function(currentElement, plugins, parserConfig) {
1246
1369
  var _currentElement_children;
1247
1370
  return {
1248
1371
  type: 'blockquote',
1249
- children: ((_currentElement_children = currentElement.children) === null || _currentElement_children === void 0 ? void 0 : _currentElement_children.length) ? parseNodes(currentElement.children, plugins, false, currentElement) : [
1372
+ children: ((_currentElement_children = currentElement.children) === null || _currentElement_children === void 0 ? void 0 : _currentElement_children.length) ? parseNodes(currentElement.children, plugins, false, currentElement, parserConfig) : [
1250
1373
  {
1251
1374
  type: 'paragraph',
1252
1375
  children: [
@@ -1272,79 +1395,6 @@ export var decodeURIComponentUrl = function(url) {
1272
1395
  ]
1273
1396
  };
1274
1397
  };
1275
- /**
1276
- * 处理文本和内联元素节点
1277
- * @param currentElement - 当前处理的文本或内联元素
1278
- * @param htmlTag - HTML标签栈,用于应用样式
1279
- * @returns 返回格式化的文本或内联元素节点对象
1280
- */ var handleTextAndInlineElements = function(currentElement, htmlTag, plugins) {
1281
- if (currentElement.type === 'text' && htmlTag.length) {
1282
- var el = {
1283
- text: currentElement.value
1284
- };
1285
- if (currentElement.value) {
1286
- applyHtmlTagsToElement(el, htmlTag);
1287
- }
1288
- return el;
1289
- }
1290
- if ([
1291
- 'strong',
1292
- 'link',
1293
- 'text',
1294
- 'emphasis',
1295
- 'delete',
1296
- 'inlineCode'
1297
- ].includes(currentElement.type)) {
1298
- var _currentElement_children;
1299
- if (currentElement.type === 'text') {
1300
- return {
1301
- text: currentElement.value
1302
- };
1303
- }
1304
- var leaf = {};
1305
- applyInlineFormatting(leaf, currentElement);
1306
- applyHtmlTagsToElement(leaf, htmlTag);
1307
- if (currentElement === null || currentElement === void 0 ? void 0 : (_currentElement_children = currentElement.children) === null || _currentElement_children === void 0 ? void 0 : _currentElement_children.some(function(n) {
1308
- return n.type === 'html';
1309
- })) {
1310
- var _parseNodes;
1311
- return _object_spread_props(_object_spread({}, (_parseNodes = parseNodes(currentElement === null || currentElement === void 0 ? void 0 : currentElement.children, plugins, false, currentElement)) === null || _parseNodes === void 0 ? void 0 : _parseNodes.at(0)), {
1312
- url: leaf.url
1313
- });
1314
- } else {
1315
- var _currentElement_children1;
1316
- return parseText(((_currentElement_children1 = currentElement.children) === null || _currentElement_children1 === void 0 ? void 0 : _currentElement_children1.length) ? currentElement.children : [
1317
- {
1318
- value: (leaf === null || leaf === void 0 ? void 0 : leaf.url) || ''
1319
- }
1320
- ], leaf);
1321
- }
1322
- }
1323
- if (currentElement.type === 'break') {
1324
- return {
1325
- text: '\n'
1326
- };
1327
- }
1328
- return {
1329
- text: ''
1330
- };
1331
- };
1332
- /**
1333
- * 应用内联格式到叶子节点
1334
- * @param leaf - 目标叶子节点对象
1335
- * @param currentElement - 当前处理的元素,包含格式信息
1336
- */ var applyInlineFormatting = function(leaf, currentElement) {
1337
- if (currentElement.type === 'strong') leaf.bold = true;
1338
- if (currentElement.type === 'emphasis') leaf.italic = true;
1339
- if (currentElement.type === 'delete') leaf.strikethrough = true;
1340
- if (currentElement.type === 'link') {
1341
- try {
1342
- leaf.url = currentElement === null || currentElement === void 0 ? void 0 : currentElement.url;
1343
- } catch (error) {
1344
- leaf.url = currentElement === null || currentElement === void 0 ? void 0 : currentElement.url;
1345
- }
1346
- }
1347
- };
1348
1398
  /**
1349
1399
  * 应用HTML标签样式到元素
1350
1400
  * @param el - 目标元素对象
@@ -1437,6 +1487,7 @@ export var decodeURIComponentUrl = function(url) {
1437
1487
  };
1438
1488
  /**
1439
1489
  * 元素处理器映射表
1490
+ * 注意:这些处理器需要通过 handleSingleElement 传递 parserConfig
1440
1491
  */ var elementHandlers = {
1441
1492
  heading: {
1442
1493
  handler: function(el, plugins) {
@@ -1526,129 +1577,17 @@ export var decodeURIComponentUrl = function(url) {
1526
1577
  }
1527
1578
  };
1528
1579
  /**
1529
- * 处理单个元素
1530
- */ var handleSingleElement = function(currentElement, config, plugins, parent, htmlTag, preElement) {
1531
- var elementType = currentElement.type;
1532
- var handlerInfo = elementHandlers[elementType];
1533
- // 特殊处理 html 类型
1534
- if (handlerInfo === null || handlerInfo === void 0 ? void 0 : handlerInfo.needsHtmlResult) {
1535
- var htmlResult = handleHtml(currentElement, parent, htmlTag);
1536
- return {
1537
- el: htmlResult.el,
1538
- contextProps: htmlResult.contextProps
1539
- };
1540
- }
1541
- // 使用处理器映射表
1542
- if (handlerInfo) {
1543
- return {
1544
- el: handlerInfo.handler(currentElement, plugins || [], config, parent, htmlTag, preElement)
1545
- };
1546
- }
1547
- // 默认处理
1548
- return {
1549
- el: handleTextAndInlineElements(currentElement, htmlTag, plugins || [])
1550
- };
1551
- };
1552
- /**
1553
- * 解析Markdown节点块为Slate节点数组
1554
- * 这是核心的解析函数,负责将各种类型的Markdown节点转换为对应的Slate编辑器节点
1555
- *
1556
- * @param nodes - 要解析的Markdown节点数组
1557
- * @param top - 是否为顶级解析,影响空行处理逻辑
1558
- * @param parent - 父级节点,用于上下文判断
1559
- * @returns 返回解析后的Slate节点数组
1580
+ * 解析 Markdown AST 节点为 Slate 节点(独立函数版本,用于向后兼容)
1581
+ * 内部使用 MarkdownToSlateParser 类来处理
1560
1582
  *
1561
- * @example
1562
- * ```typescript
1563
- * const markdownNodes = [
1564
- * { type: 'heading', depth: 1, children: [...] },
1565
- * { type: 'paragraph', children: [...] }
1566
- * ];
1567
- * const slateNodes = parseNodes(markdownNodes, true);
1568
- * ```
1569
- */ /**
1570
- * 解析 Markdown AST 节点为 Slate 节点
1571
- * - 当有插件时,优先使用插件处理
1572
- * - 插件未处理时,使用默认处理逻辑
1583
+ * @deprecated 建议直接使用 MarkdownToSlateParser 类
1573
1584
  */ var parseNodes = function(nodes, plugins) {
1574
- var _loop = function(i) {
1575
- var currentElement = nodes[i];
1576
- var el = null;
1577
- var pluginHandled = false;
1578
- var config = (preElement === null || preElement === void 0 ? void 0 : preElement.type) === 'code' && (preElement === null || preElement === void 0 ? void 0 : preElement.language) === 'html' && (preElement === null || preElement === void 0 ? void 0 : preElement.otherProps) ? preElement === null || preElement === void 0 ? void 0 : preElement.otherProps : {};
1579
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1580
- try {
1581
- // 首先尝试使用插件处理
1582
- for(var _iterator = plugins[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1583
- var plugin = _step.value;
1584
- var _plugin_parseMarkdown;
1585
- var rule = (_plugin_parseMarkdown = plugin.parseMarkdown) === null || _plugin_parseMarkdown === void 0 ? void 0 : _plugin_parseMarkdown.find(function(r) {
1586
- return r.match(currentElement);
1587
- });
1588
- if (rule) {
1589
- var converted = rule.convert(currentElement);
1590
- // 检查转换结果是否为 NodeEntry<Text> 格式
1591
- if (Array.isArray(converted) && converted.length === 2) {
1592
- // NodeEntry<Text> 格式: [node, path]
1593
- el = converted[0];
1594
- } else {
1595
- // Elements 格式
1596
- el = converted;
1597
- }
1598
- pluginHandled = true;
1599
- break;
1600
- }
1601
- }
1602
- } catch (err) {
1603
- _didIteratorError = true;
1604
- _iteratorError = err;
1605
- } finally{
1606
- try {
1607
- if (!_iteratorNormalCompletion && _iterator.return != null) {
1608
- _iterator.return();
1609
- }
1610
- } finally{
1611
- if (_didIteratorError) {
1612
- throw _iteratorError;
1613
- }
1614
- }
1615
- }
1616
- // 如果插件没有处理,使用默认处理逻辑
1617
- if (!pluginHandled) {
1618
- // 使用统一的处理函数
1619
- var result = handleSingleElement(currentElement, config, plugins, parent, htmlTag, preElement);
1620
- el = result.el;
1621
- if (result.contextProps) {
1622
- contextProps = _object_spread({}, contextProps, result.contextProps);
1623
- }
1624
- }
1625
- addEmptyLinesIfNeeded(els, preNode, currentElement, top);
1626
- if (el) {
1627
- var _els;
1628
- el = applyContextPropsAndConfig(el, contextProps, config);
1629
- Array.isArray(el) ? (_els = els).push.apply(_els, _to_consumable_array(el)) : els.push(el);
1630
- }
1631
- preNode = currentElement;
1632
- preElement = el;
1633
- };
1634
- var top = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false, parent = arguments.length > 3 ? arguments[3] : void 0;
1635
- if (!(nodes === null || nodes === void 0 ? void 0 : nodes.length)) return [
1636
- {
1637
- type: 'paragraph',
1638
- children: [
1639
- {
1640
- text: ''
1641
- }
1642
- ]
1643
- }
1644
- ];
1645
- var els = [];
1646
- var preNode = null;
1647
- var preElement = null;
1648
- var htmlTag = [];
1649
- var contextProps = {};
1650
- for(var i = 0; i < nodes.length; i++)_loop(i);
1651
- return els;
1585
+ var top = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false, parent = arguments.length > 3 ? arguments[3] : void 0, parserConfig = arguments.length > 4 ? arguments[4] : void 0;
1586
+ // 创建一个临时 parser 实例来处理
1587
+ // 注意:这不是最优的方式,但为了向后兼容保留
1588
+ // 使用类型断言访问私有方法
1589
+ var parser = new MarkdownToSlateParser(parserConfig || {}, plugins || []);
1590
+ return parser.parseNodes(nodes, top, parent);
1652
1591
  };
1653
1592
  var tableRegex = /^\|.*\|\s*\n\|[-:| ]+\|/m;
1654
1593
  /**
@@ -1754,7 +1693,9 @@ var tableRegex = /^\|.*\|\s*\n\|[-:| ]+\|/m;
1754
1693
  'menu',
1755
1694
  'menuitem',
1756
1695
  // 字体
1757
- 'font'
1696
+ 'font',
1697
+ // 自定义标签(用于流式渲染)
1698
+ 'incomplete-image'
1758
1699
  ]);
1759
1700
  /**
1760
1701
  * 检查 HTML 标签是否为标准元素
@@ -1795,6 +1736,78 @@ var tableRegex = /^\|.*\|\s*\n\|[-:| ]+\|/m;
1795
1736
  */ function preprocessThinkTags(markdown) {
1796
1737
  return preprocessSpecialTags(markdown, 'think');
1797
1738
  }
1739
+ /**
1740
+ * 检测不完整的图片标记
1741
+ * 参考 useStreaming 中的逻辑,检测类似 ![ 或 ![text]( 的不完整图片语法
1742
+ * @param markdown - 要检测的 Markdown 字符串
1743
+ * @returns 是否为不完整的图片标记
1744
+ */ function isIncompleteImage(markdown) {
1745
+ // 匹配不完整的图片语法:
1746
+ // 1. ![ 开始但还没有 ]
1747
+ // 2. ![text] 开始但还没有 (
1748
+ // 3. ![text]( 开始但还没有 )
1749
+ var incompleteImagePatterns = [
1750
+ /^!\[[^\]\r\n]{0,1000}$/,
1751
+ /^!\[[^\r\n]{0,1000}\]\(*[^)\r\n]{0,1000}$/
1752
+ ];
1753
+ return incompleteImagePatterns.some(function(pattern) {
1754
+ return pattern.test(markdown);
1755
+ });
1756
+ }
1757
+ /**
1758
+ * 预处理不完整的图片标记,将其转换为特殊的 HTML 标签
1759
+ * @param markdown - 原始 Markdown 字符串
1760
+ * @returns 处理后的 Markdown 字符串
1761
+ */ function preprocessIncompleteImages(markdown) {
1762
+ if (!markdown) return markdown;
1763
+ // 按行处理,避免在代码块中处理
1764
+ var lines = markdown.split('\n');
1765
+ var inCodeBlock = false;
1766
+ var codeBlockFence = '';
1767
+ var codeBlockFenceLen = 0;
1768
+ var processedLines = lines.map(function(line) {
1769
+ // 检测代码块开始/结束
1770
+ var fenceMatch = line.match(FENCED_CODE_REGEX);
1771
+ if (fenceMatch) {
1772
+ var currentFence = fenceMatch[1];
1773
+ var char = currentFence[0];
1774
+ var len = currentFence.length;
1775
+ if (!inCodeBlock) {
1776
+ inCodeBlock = true;
1777
+ codeBlockFence = char;
1778
+ codeBlockFenceLen = len;
1779
+ } else if (char === codeBlockFence && len >= codeBlockFenceLen) {
1780
+ inCodeBlock = false;
1781
+ codeBlockFence = '';
1782
+ codeBlockFenceLen = 0;
1783
+ }
1784
+ return line;
1785
+ }
1786
+ // 如果在代码块中,不处理
1787
+ if (inCodeBlock) {
1788
+ return line;
1789
+ }
1790
+ // 检测不完整的图片标记
1791
+ // 匹配行尾的不完整图片语法(避免匹配完整的图片)
1792
+ var trimmedLine = line.trim();
1793
+ // 如果整行就是一个不完整的图片标记
1794
+ if (isIncompleteImage(trimmedLine)) {
1795
+ var encodedRaw = encodeURIComponent(trimmedLine);
1796
+ return '<incomplete-image data-raw="'.concat(encodedRaw, '" />');
1797
+ }
1798
+ // 检测行内不完整的图片标记(在行尾)
1799
+ // 使用负向前瞻确保不是完整图片的一部分
1800
+ return line.replace(/(!\[[^\]]*\]?\(?[^)]*)$/, function(match) {
1801
+ // 检查是否是不完整的图片
1802
+ if (isIncompleteImage(match.trim())) {
1803
+ var encodedRaw = encodeURIComponent(match.trim());
1804
+ return '<incomplete-image data-raw="'.concat(encodedRaw, '" />');
1805
+ }
1806
+ return match;
1807
+ });
1808
+ });
1809
+ return processedLines.join('\n');
1810
+ }
1798
1811
  /**
1799
1812
  * 预处理所有非标准 HTML 标签,提取其内容(删除标签本身)
1800
1813
  * @param markdown - 原始 Markdown 字符串
@@ -1806,7 +1819,12 @@ var tableRegex = /^\|.*\|\s*\n\|[-:| ]+\|/m;
1806
1819
  while(hasNonStandardTags){
1807
1820
  var before = result;
1808
1821
  // 匹配所有 HTML 标签对:<tagname>content</tagname>
1822
+ // 注意:跳过 incomplete-image 标签(它是自闭合标签,需要特殊处理)
1809
1823
  result = result.replace(/<(\w+)>([\s\S]*?)<\/\1>/g, function(match, tagName, content) {
1824
+ // 保护 incomplete-image 标签(虽然它是自闭合的,但为了安全起见)
1825
+ if (tagName.toLowerCase() === 'incomplete-image') {
1826
+ return match;
1827
+ }
1810
1828
  // 检查是否为标准 HTML 元素
1811
1829
  if (STANDARD_HTML_ELEMENTS.has(tagName.toLowerCase())) {
1812
1830
  // 标准元素保持不变
@@ -1842,34 +1860,677 @@ function preprocessMarkdownTableNewlines(markdown) {
1842
1860
  });
1843
1861
  }).join('\n\n');
1844
1862
  }
1863
+ /**
1864
+ * Markdown 到 Slate 节点解析器类
1865
+ *
1866
+ * 将 Markdown 字符串解析为 Slate 编辑器节点,支持配置选项和插件。
1867
+ * 使用类形式可以避免在函数调用链中传递配置参数和插件。
1868
+ */ export var MarkdownToSlateParser = /*#__PURE__*/ function() {
1869
+ "use strict";
1870
+ function MarkdownToSlateParser() {
1871
+ var config = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, plugins = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
1872
+ _class_call_check(this, MarkdownToSlateParser);
1873
+ _define_property(this, "config", void 0);
1874
+ _define_property(this, "plugins", void 0);
1875
+ this.config = config;
1876
+ this.plugins = plugins;
1877
+ }
1878
+ _create_class(MarkdownToSlateParser, [
1879
+ {
1880
+ /**
1881
+ * 解析 Markdown 字符串并返回解析后的结构和链接信息
1882
+ *
1883
+ * @param md - 要解析的 Markdown 字符串
1884
+ * @returns 一个包含解析后的元素数组和链接信息的对象
1885
+ */ key: "parse",
1886
+ value: function parse(md) {
1887
+ // 先预处理 <think> 标签,再预处理不完整的图片,然后预处理其他非标准 HTML 标签,最后处理表格换行
1888
+ var thinkProcessed = preprocessThinkTags(md || '');
1889
+ var incompleteImageProcessed = preprocessIncompleteImages(thinkProcessed);
1890
+ var nonStandardProcessed = preprocessNonStandardHtmlTags(incompleteImageProcessed);
1891
+ var processedMarkdown = mdastParser.parse(preprocessMarkdownTableNewlines(nonStandardProcessed));
1892
+ var markdownRoot = processedMarkdown.children;
1893
+ // 使用类的配置和插件,通过 this 访问
1894
+ var schema = this.parseNodes(markdownRoot, true, undefined);
1895
+ return {
1896
+ schema: schema === null || schema === void 0 ? void 0 : schema.filter(function(item) {
1897
+ var _item_children;
1898
+ if (item.type === 'paragraph' && ((_item_children = item.children) === null || _item_children === void 0 ? void 0 : _item_children.length) === 1) {
1899
+ if (item.children[0].text === '\n') {
1900
+ return false;
1901
+ }
1902
+ return true;
1903
+ }
1904
+ return true;
1905
+ }),
1906
+ links: []
1907
+ };
1908
+ }
1909
+ },
1910
+ {
1911
+ key: "parseNodes",
1912
+ value: /**
1913
+ * 解析 Markdown AST 节点为 Slate 节点(类方法版本)
1914
+ * - 当有插件时,优先使用插件处理
1915
+ * - 插件未处理时,使用默认处理逻辑
1916
+ */ function parseNodes(nodes) {
1917
+ var _this, _loop = function(i) {
1918
+ var currentElement = nodes[i];
1919
+ var el = null;
1920
+ var pluginHandled = false;
1921
+ var config = (preElement === null || preElement === void 0 ? void 0 : preElement.type) === 'code' && (preElement === null || preElement === void 0 ? void 0 : preElement.language) === 'html' && (preElement === null || preElement === void 0 ? void 0 : preElement.otherProps) ? preElement === null || preElement === void 0 ? void 0 : preElement.otherProps : {};
1922
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1923
+ try {
1924
+ // 首先尝试使用插件处理,使用 this.plugins
1925
+ for(var _iterator = _this.plugins[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1926
+ var plugin = _step.value;
1927
+ var _plugin_parseMarkdown;
1928
+ var rule = (_plugin_parseMarkdown = plugin.parseMarkdown) === null || _plugin_parseMarkdown === void 0 ? void 0 : _plugin_parseMarkdown.find(function(r) {
1929
+ return r.match(currentElement);
1930
+ });
1931
+ if (rule) {
1932
+ var converted = rule.convert(currentElement);
1933
+ // 检查转换结果是否为 NodeEntry<Text> 格式
1934
+ if (Array.isArray(converted) && converted.length === 2) {
1935
+ // NodeEntry<Text> 格式: [node, path]
1936
+ el = converted[0];
1937
+ } else {
1938
+ // Elements 格式
1939
+ el = converted;
1940
+ }
1941
+ pluginHandled = true;
1942
+ break;
1943
+ }
1944
+ }
1945
+ } catch (err) {
1946
+ _didIteratorError = true;
1947
+ _iteratorError = err;
1948
+ } finally{
1949
+ try {
1950
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1951
+ _iterator.return();
1952
+ }
1953
+ } finally{
1954
+ if (_didIteratorError) {
1955
+ throw _iteratorError;
1956
+ }
1957
+ }
1958
+ }
1959
+ // 如果插件没有处理,使用默认处理逻辑
1960
+ if (!pluginHandled) {
1961
+ var isLastNode = i === nodes.length - 1;
1962
+ // 如果是 table 节点,检查是否是最后一个节点,设置 finish 属性
1963
+ if (currentElement.type === 'table') {
1964
+ // 如果 table 不是最后一个节点,finish 设置为 true
1965
+ if (!isLastNode) {
1966
+ if (!currentElement.otherProps) {
1967
+ currentElement.otherProps = {};
1968
+ }
1969
+ currentElement.otherProps.finish = true;
1970
+ } else {
1971
+ // 如果是最后一个节点,且 typing=false,finish 设置为 true
1972
+ if (_this.config.typing === false) {
1973
+ if (!currentElement.otherProps) {
1974
+ currentElement.otherProps = {};
1975
+ }
1976
+ currentElement.otherProps.finish = true;
1977
+ }
1978
+ // 否则保持原逻辑(在 parseTableOrChart 中处理,默认为 false)
1979
+ }
1980
+ }
1981
+ // 如果是 code 节点,检查是否是最后一个节点,设置 finish 属性
1982
+ if (currentElement.type === 'code') {
1983
+ // 如果 code 不是最后一个节点,finish 设置为 true
1984
+ if (!isLastNode) {
1985
+ if (!currentElement.otherProps) {
1986
+ currentElement.otherProps = {};
1987
+ }
1988
+ currentElement.otherProps.finish = true;
1989
+ }
1990
+ // 如果是最后一个节点,保持原逻辑(在 handleCode 中处理)
1991
+ }
1992
+ // 使用统一的处理函数,通过 this 访问配置和插件
1993
+ var result = _this.handleSingleElement(currentElement, config, parent, htmlTag, preElement);
1994
+ el = result.el;
1995
+ if (result.contextProps) {
1996
+ contextProps = _object_spread({}, contextProps, result.contextProps);
1997
+ }
1998
+ }
1999
+ addEmptyLinesIfNeeded(els, preNode, currentElement, top);
2000
+ if (el) {
2001
+ var _els;
2002
+ el = applyContextPropsAndConfig(el, contextProps, config);
2003
+ Array.isArray(el) ? (_els = els).push.apply(_els, _to_consumable_array(el)) : els.push(el);
2004
+ }
2005
+ preNode = currentElement;
2006
+ preElement = el;
2007
+ };
2008
+ var top = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false, parent = arguments.length > 2 ? arguments[2] : void 0;
2009
+ if (!(nodes === null || nodes === void 0 ? void 0 : nodes.length)) return [
2010
+ {
2011
+ type: 'paragraph',
2012
+ children: [
2013
+ {
2014
+ text: ''
2015
+ }
2016
+ ]
2017
+ }
2018
+ ];
2019
+ var els = [];
2020
+ var preNode = null;
2021
+ var preElement = null;
2022
+ var htmlTag = [];
2023
+ var contextProps = {};
2024
+ for(var i = 0; i < nodes.length; i++)_this = this, _loop(i);
2025
+ return els;
2026
+ }
2027
+ },
2028
+ {
2029
+ key: "handleSingleElement",
2030
+ value: /**
2031
+ * 处理单个元素(类方法版本)
2032
+ */ function handleSingleElement(currentElement, config, parent, htmlTag, preElement) {
2033
+ var elementType = currentElement.type;
2034
+ var handlerInfo = elementHandlers[elementType];
2035
+ // 特殊处理 html 类型
2036
+ if (handlerInfo === null || handlerInfo === void 0 ? void 0 : handlerInfo.needsHtmlResult) {
2037
+ var htmlResult = handleHtml(currentElement, parent, htmlTag);
2038
+ return {
2039
+ el: htmlResult.el,
2040
+ contextProps: htmlResult.contextProps
2041
+ };
2042
+ }
2043
+ // 使用处理器映射表
2044
+ // 对于需要 parserConfig 的处理器,直接调用而不是通过 handler
2045
+ if (handlerInfo) {
2046
+ var handlerResult;
2047
+ // 特殊处理需要 parserConfig 的处理器,使用 this.config 和 this.plugins
2048
+ if (elementType === 'heading') {
2049
+ handlerResult = this.handleHeading(currentElement);
2050
+ } else if (elementType === 'list') {
2051
+ handlerResult = this.handleList(currentElement);
2052
+ } else if (elementType === 'listItem') {
2053
+ handlerResult = this.handleListItem(currentElement);
2054
+ } else if (elementType === 'blockquote') {
2055
+ handlerResult = this.handleBlockquote(currentElement);
2056
+ } else if (elementType === 'footnoteDefinition') {
2057
+ handlerResult = this.handleFootnoteDefinition(currentElement);
2058
+ } else if (elementType === 'paragraph') {
2059
+ handlerResult = this.handleParagraph(currentElement, config);
2060
+ } else if (elementType === 'table') {
2061
+ handlerResult = this.parseTableOrChart(currentElement, preElement || parent);
2062
+ } else {
2063
+ // 使用默认的 handler 调用
2064
+ handlerResult = handlerInfo.handler(currentElement, this.plugins, config, parent, htmlTag, preElement);
2065
+ }
2066
+ return {
2067
+ el: handlerResult
2068
+ };
2069
+ }
2070
+ // 默认处理
2071
+ return {
2072
+ el: this.handleTextAndInlineElements(currentElement, htmlTag)
2073
+ };
2074
+ }
2075
+ },
2076
+ {
2077
+ key: "handleHeading",
2078
+ value: /**
2079
+ * 处理标题节点(类方法版本)
2080
+ */ function handleHeading(currentElement) {
2081
+ var _currentElement_children;
2082
+ return {
2083
+ type: 'head',
2084
+ level: currentElement.depth,
2085
+ children: ((_currentElement_children = currentElement.children) === null || _currentElement_children === void 0 ? void 0 : _currentElement_children.length) ? this.parseNodes(currentElement.children, false, currentElement) : [
2086
+ {
2087
+ text: ''
2088
+ }
2089
+ ]
2090
+ };
2091
+ }
2092
+ },
2093
+ {
2094
+ key: "handleList",
2095
+ value: /**
2096
+ * 处理列表节点(类方法版本)
2097
+ */ function handleList(currentElement) {
2098
+ var _el_children;
2099
+ var el = {
2100
+ type: 'list',
2101
+ order: currentElement.ordered,
2102
+ start: currentElement.start,
2103
+ children: this.parseNodes(currentElement.children, false, currentElement)
2104
+ };
2105
+ el.task = (_el_children = el.children) === null || _el_children === void 0 ? void 0 : _el_children.some(function(s) {
2106
+ return typeof s.checked === 'boolean';
2107
+ });
2108
+ return el;
2109
+ }
2110
+ },
2111
+ {
2112
+ key: "handleFootnoteDefinition",
2113
+ value: /**
2114
+ * 处理脚注定义节点(类方法版本)
2115
+ */ function handleFootnoteDefinition(currentElement) {
2116
+ var _this_parseNodes, _linkNode_children;
2117
+ var linkNode = (_this_parseNodes = this.parseNodes(currentElement.children, false, currentElement)) === null || _this_parseNodes === void 0 ? void 0 : _this_parseNodes.at(0);
2118
+ var cellNode = linkNode === null || linkNode === void 0 ? void 0 : (_linkNode_children = linkNode.children) === null || _linkNode_children === void 0 ? void 0 : _linkNode_children.at(0);
2119
+ return {
2120
+ value: cellNode === null || cellNode === void 0 ? void 0 : cellNode.text,
2121
+ url: cellNode === null || cellNode === void 0 ? void 0 : cellNode.url,
2122
+ type: 'footnoteDefinition',
2123
+ identifier: currentElement.identifier,
2124
+ children: [
2125
+ cellNode
2126
+ ]
2127
+ };
2128
+ }
2129
+ },
2130
+ {
2131
+ key: "handleListItem",
2132
+ value: /**
2133
+ * 处理列表项节点(类方法版本)
2134
+ */ function handleListItem(currentElement) {
2135
+ var _currentElement_children, _currentElement_children__children_, _currentElement_children__children, _currentElement_children_, _currentElement_children1, _currentElement_children__children1, _currentElement_children_1, _currentElement_children2;
2136
+ var children = ((_currentElement_children = currentElement.children) === null || _currentElement_children === void 0 ? void 0 : _currentElement_children.length) ? this.parseNodes(currentElement.children, false, currentElement) : [
2137
+ {
2138
+ type: 'paragraph',
2139
+ children: [
2140
+ {
2141
+ text: ''
2142
+ }
2143
+ ]
2144
+ }
2145
+ ];
2146
+ var mentions = undefined;
2147
+ if (((_currentElement_children1 = currentElement.children) === null || _currentElement_children1 === void 0 ? void 0 : (_currentElement_children_ = _currentElement_children1[0]) === null || _currentElement_children_ === void 0 ? void 0 : (_currentElement_children__children = _currentElement_children_.children) === null || _currentElement_children__children === void 0 ? void 0 : (_currentElement_children__children_ = _currentElement_children__children[0]) === null || _currentElement_children__children_ === void 0 ? void 0 : _currentElement_children__children_.type) === 'link' && ((_currentElement_children2 = currentElement.children) === null || _currentElement_children2 === void 0 ? void 0 : (_currentElement_children_1 = _currentElement_children2[0]) === null || _currentElement_children_1 === void 0 ? void 0 : (_currentElement_children__children1 = _currentElement_children_1.children) === null || _currentElement_children__children1 === void 0 ? void 0 : _currentElement_children__children1.length) > 1) {
2148
+ var _children__children, _children_;
2149
+ var item = children === null || children === void 0 ? void 0 : (_children_ = children[0]) === null || _children_ === void 0 ? void 0 : (_children__children = _children_.children) === null || _children__children === void 0 ? void 0 : _children__children[0];
2150
+ var label = item === null || item === void 0 ? void 0 : item.text;
2151
+ if (label) {
2152
+ var _item_url, _children__children1, _children_1;
2153
+ mentions = [
2154
+ {
2155
+ avatar: item === null || item === void 0 ? void 0 : item.url,
2156
+ name: label,
2157
+ id: new URLSearchParams('?' + (item === null || item === void 0 ? void 0 : (_item_url = item.url) === null || _item_url === void 0 ? void 0 : _item_url.split('?')[1])).get('id') || undefined
2158
+ }
2159
+ ];
2160
+ children === null || children === void 0 ? true : (_children_1 = children[0]) === null || _children_1 === void 0 ? true : (_children__children1 = _children_1.children) === null || _children__children1 === void 0 ? true : delete _children__children1[0];
2161
+ }
2162
+ }
2163
+ return {
2164
+ type: 'list-item',
2165
+ checked: currentElement.checked,
2166
+ children: children,
2167
+ mentions: mentions
2168
+ };
2169
+ }
2170
+ },
2171
+ {
2172
+ key: "processParagraphChildren",
2173
+ value: /**
2174
+ * 处理段落子节点(类方法版本)
2175
+ */ function processParagraphChildren(currentElement) {
2176
+ var elements = [];
2177
+ var textNodes = [];
2178
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
2179
+ try {
2180
+ for(var _iterator = (currentElement.children || [])[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2181
+ var currentChild = _step.value;
2182
+ if (currentChild.type === 'image') {
2183
+ // 将累积的文本节点生成段落
2184
+ if (textNodes.length) {
2185
+ elements.push({
2186
+ type: 'paragraph',
2187
+ children: this.parseNodes(textNodes, false, currentElement)
2188
+ });
2189
+ textNodes = [];
2190
+ }
2191
+ // 添加图片节点
2192
+ elements.push(EditorUtils.createMediaNode(decodeURIComponentUrl(currentChild === null || currentChild === void 0 ? void 0 : currentChild.url), 'image', {
2193
+ alt: currentChild.alt
2194
+ }));
2195
+ } else if (currentChild.type === 'html') {
2196
+ // 跳过媒体标签的结束标签
2197
+ if (currentChild.value.match(/^<\/(img|video|iframe)>/)) {
2198
+ continue;
2199
+ }
2200
+ var mediaElement = findImageElement(currentChild.value);
2201
+ if (mediaElement) {
2202
+ var node = createMediaNodeFromElement(mediaElement);
2203
+ if (node) {
2204
+ elements.push(node);
2205
+ }
2206
+ } else {
2207
+ textNodes.push({
2208
+ type: 'html',
2209
+ value: currentChild.value
2210
+ });
2211
+ }
2212
+ } else {
2213
+ textNodes.push(currentChild);
2214
+ }
2215
+ }
2216
+ } catch (err) {
2217
+ _didIteratorError = true;
2218
+ _iteratorError = err;
2219
+ } finally{
2220
+ try {
2221
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
2222
+ _iterator.return();
2223
+ }
2224
+ } finally{
2225
+ if (_didIteratorError) {
2226
+ throw _iteratorError;
2227
+ }
2228
+ }
2229
+ }
2230
+ // 处理剩余的文本节点
2231
+ if (textNodes.length) {
2232
+ elements.push({
2233
+ type: 'paragraph',
2234
+ children: this.parseNodes(textNodes, false, currentElement)
2235
+ });
2236
+ }
2237
+ return elements;
2238
+ }
2239
+ },
2240
+ {
2241
+ key: "handleParagraph",
2242
+ value: /**
2243
+ * 处理段落节点(类方法版本)
2244
+ */ function handleParagraph(currentElement, config) {
2245
+ var _currentElement_children, _currentElement_children_at, _currentElement_children1;
2246
+ // 检查是否是附件链接
2247
+ if (((_currentElement_children = currentElement.children) === null || _currentElement_children === void 0 ? void 0 : _currentElement_children[0].type) === 'html' && currentElement.children[0].value.startsWith('<a')) {
2248
+ var attachNode = handleAttachmentLink(currentElement);
2249
+ if (attachNode) return attachNode;
2250
+ }
2251
+ // 检查是否是链接卡片
2252
+ if ((currentElement === null || currentElement === void 0 ? void 0 : (_currentElement_children1 = currentElement.children) === null || _currentElement_children1 === void 0 ? void 0 : (_currentElement_children_at = _currentElement_children1.at(0)) === null || _currentElement_children_at === void 0 ? void 0 : _currentElement_children_at.type) === 'link' && config.type === 'card') {
2253
+ return handleLinkCard(currentElement, config);
2254
+ }
2255
+ // 处理混合内容段落
2256
+ return this.processParagraphChildren(currentElement);
2257
+ }
2258
+ },
2259
+ {
2260
+ key: "handleBlockquote",
2261
+ value: /**
2262
+ * 处理引用块节点(类方法版本)
2263
+ */ function handleBlockquote(currentElement) {
2264
+ var _currentElement_children;
2265
+ return {
2266
+ type: 'blockquote',
2267
+ children: ((_currentElement_children = currentElement.children) === null || _currentElement_children === void 0 ? void 0 : _currentElement_children.length) ? this.parseNodes(currentElement.children, false, currentElement) : [
2268
+ {
2269
+ type: 'paragraph',
2270
+ children: [
2271
+ {
2272
+ text: ''
2273
+ }
2274
+ ]
2275
+ }
2276
+ ]
2277
+ };
2278
+ }
2279
+ },
2280
+ {
2281
+ key: "handleTextAndInlineElements",
2282
+ value: /**
2283
+ * 处理文本和内联元素节点(类方法版本)
2284
+ */ function handleTextAndInlineElements(currentElement, htmlTag) {
2285
+ if (currentElement.type === 'text' && htmlTag.length) {
2286
+ var el = {
2287
+ text: currentElement.value
2288
+ };
2289
+ if (currentElement.value) {
2290
+ applyHtmlTagsToElement(el, htmlTag);
2291
+ }
2292
+ return el;
2293
+ }
2294
+ if ([
2295
+ 'strong',
2296
+ 'link',
2297
+ 'text',
2298
+ 'emphasis',
2299
+ 'delete',
2300
+ 'inlineCode'
2301
+ ].includes(currentElement.type)) {
2302
+ var _currentElement_children;
2303
+ if (currentElement.type === 'text') {
2304
+ return {
2305
+ text: currentElement.value
2306
+ };
2307
+ }
2308
+ var leaf = {};
2309
+ this.applyInlineFormatting(leaf, currentElement);
2310
+ applyHtmlTagsToElement(leaf, htmlTag);
2311
+ if (currentElement === null || currentElement === void 0 ? void 0 : (_currentElement_children = currentElement.children) === null || _currentElement_children === void 0 ? void 0 : _currentElement_children.some(function(n) {
2312
+ return n.type === 'html';
2313
+ })) {
2314
+ var _this_parseNodes;
2315
+ return _object_spread_props(_object_spread({}, (_this_parseNodes = this.parseNodes(currentElement === null || currentElement === void 0 ? void 0 : currentElement.children, false, currentElement)) === null || _this_parseNodes === void 0 ? void 0 : _this_parseNodes.at(0)), {
2316
+ url: leaf.url
2317
+ });
2318
+ } else {
2319
+ var _currentElement_children1;
2320
+ return parseText(((_currentElement_children1 = currentElement.children) === null || _currentElement_children1 === void 0 ? void 0 : _currentElement_children1.length) ? currentElement.children : [
2321
+ {
2322
+ value: (leaf === null || leaf === void 0 ? void 0 : leaf.url) || ''
2323
+ }
2324
+ ], leaf);
2325
+ }
2326
+ }
2327
+ if (currentElement.type === 'break') {
2328
+ return {
2329
+ text: '\n'
2330
+ };
2331
+ }
2332
+ return {
2333
+ text: ''
2334
+ };
2335
+ }
2336
+ },
2337
+ {
2338
+ key: "applyInlineFormatting",
2339
+ value: /**
2340
+ * 应用内联格式到叶子节点(类方法版本)
2341
+ */ function applyInlineFormatting(leaf, currentElement) {
2342
+ if (currentElement.type === 'strong') leaf.bold = true;
2343
+ if (currentElement.type === 'emphasis') leaf.italic = true;
2344
+ if (currentElement.type === 'delete') leaf.strikethrough = true;
2345
+ if (currentElement.type === 'link') {
2346
+ try {
2347
+ var _this_config;
2348
+ leaf.url = currentElement === null || currentElement === void 0 ? void 0 : currentElement.url;
2349
+ // 如果配置了在新标签页打开链接,添加 target 和 rel 属性
2350
+ if ((_this_config = this.config) === null || _this_config === void 0 ? void 0 : _this_config.openLinksInNewTab) {
2351
+ // 使用 otherProps 存储额外的链接属性
2352
+ if (!leaf.otherProps) {
2353
+ leaf.otherProps = {};
2354
+ }
2355
+ leaf.otherProps.target = '_blank';
2356
+ leaf.otherProps.rel = 'noopener noreferrer';
2357
+ }
2358
+ } catch (error) {
2359
+ leaf.url = currentElement === null || currentElement === void 0 ? void 0 : currentElement.url;
2360
+ }
2361
+ }
2362
+ }
2363
+ },
2364
+ {
2365
+ key: "parseTableOrChart",
2366
+ value: /**
2367
+ * 解析表格或图表(类方法版本)
2368
+ */ function parseTableOrChart(table, preNode) {
2369
+ var _this = this;
2370
+ var _table_children, _tableHeader_children, _table_children_slice, _table_children1, _table_align, _config_at, _config_at1, _table_otherProps;
2371
+ var keyMap = new Map();
2372
+ // @ts-ignore
2373
+ var config = // @ts-ignore
2374
+ (preNode === null || preNode === void 0 ? void 0 : preNode.type) === 'code' && // @ts-ignore
2375
+ (preNode === null || preNode === void 0 ? void 0 : preNode.language) === 'html' && (// @ts-ignore
2376
+ preNode === null || preNode === void 0 ? void 0 : preNode.otherProps) ? preNode === null || preNode === void 0 ? void 0 : preNode.otherProps : {};
2377
+ var tableHeader = table === null || table === void 0 ? void 0 : (_table_children = table.children) === null || _table_children === void 0 ? void 0 : _table_children.at(0);
2378
+ var columns = (tableHeader === null || tableHeader === void 0 ? void 0 : (_tableHeader_children = tableHeader.children) === null || _tableHeader_children === void 0 ? void 0 : _tableHeader_children.map(function(node) {
2379
+ return myRemark.stringify({
2380
+ type: 'root',
2381
+ children: [
2382
+ node
2383
+ ]
2384
+ }).trim();
2385
+ }).map(function(key) {
2386
+ // 规范化字段名,统一处理转义字符
2387
+ var normalizedKey = normalizeFieldName(key);
2388
+ var value = keyMap.get(normalizedKey) || normalizedKey;
2389
+ return value;
2390
+ }).map(function(key) {
2391
+ return {
2392
+ dataIndex: key
2393
+ };
2394
+ })) || [];
2395
+ var dataSource = (table === null || table === void 0 ? void 0 : (_table_children1 = table.children) === null || _table_children1 === void 0 ? void 0 : (_table_children_slice = _table_children1.slice(1)) === null || _table_children_slice === void 0 ? void 0 : _table_children_slice.map(function(row) {
2396
+ var _row_children;
2397
+ return (_row_children = row.children) === null || _row_children === void 0 ? void 0 : _row_children.reduce(function(acc, cell, index) {
2398
+ var column = columns[index];
2399
+ var key = (column === null || column === void 0 ? void 0 : column.dataIndex) || (typeof column === 'string' ? column : undefined);
2400
+ if (key) {
2401
+ acc[key] = myRemark.stringify({
2402
+ type: 'root',
2403
+ children: [
2404
+ cell
2405
+ ]
2406
+ }).trim();
2407
+ }
2408
+ return acc;
2409
+ }, {});
2410
+ })) || [];
2411
+ if ((_table_align = table.align) === null || _table_align === void 0 ? void 0 : _table_align.every(function(item) {
2412
+ return !item;
2413
+ })) {
2414
+ var aligns = getColumnAlignment(dataSource, columns);
2415
+ table.align = aligns;
2416
+ }
2417
+ var aligns1 = table.align;
2418
+ var isChart = (config === null || config === void 0 ? void 0 : config.chartType) || (config === null || config === void 0 ? void 0 : (_config_at1 = config.at) === null || _config_at1 === void 0 ? void 0 : (_config_at = _config_at1.call(config, 0)) === null || _config_at === void 0 ? void 0 : _config_at.chartType);
2419
+ // 计算合并单元格信息
2420
+ var mergeCells = config.mergeCells || [];
2421
+ // 创建合并单元格映射,用于快速查找
2422
+ var mergeMap = new Map();
2423
+ mergeCells === null || mergeCells === void 0 ? void 0 : mergeCells.forEach(function(param) {
2424
+ var row = param.row, col = param.col, rowSpan = param.rowSpan, rowspan = param.rowspan, colSpan = param.colSpan, colspan = param.colspan;
2425
+ var rawRowSpan = rowSpan || rowspan;
2426
+ var rawColSpan = colSpan || colspan;
2427
+ // 主单元格
2428
+ mergeMap.set("".concat(row, "-").concat(col), {
2429
+ rowSpan: rawRowSpan,
2430
+ colSpan: rawColSpan
2431
+ });
2432
+ // 被合并的单元格标记为隐藏
2433
+ for(var r = row; r < row + rawRowSpan; r++){
2434
+ for(var c = col; c < col + rawColSpan; c++){
2435
+ if (r !== row || c !== col) {
2436
+ mergeMap.set("".concat(r, "-").concat(c), {
2437
+ rowSpan: 1,
2438
+ colSpan: 1,
2439
+ hidden: true
2440
+ });
2441
+ }
2442
+ }
2443
+ }
2444
+ });
2445
+ var children = table.children.map(function(r, l) {
2446
+ return {
2447
+ type: 'table-row',
2448
+ align: (aligns1 === null || aligns1 === void 0 ? void 0 : aligns1[l]) || undefined,
2449
+ children: r.children.map(function(c, i) {
2450
+ var _c_children;
2451
+ var mergeInfo = mergeMap.get("".concat(l, "-").concat(i));
2452
+ return _object_spread_props(_object_spread({
2453
+ type: 'table-cell',
2454
+ align: (aligns1 === null || aligns1 === void 0 ? void 0 : aligns1[i]) || undefined,
2455
+ title: l === 0,
2456
+ rows: l,
2457
+ cols: i
2458
+ }, (mergeInfo === null || mergeInfo === void 0 ? void 0 : mergeInfo.rowSpan) && mergeInfo.rowSpan > 1 ? {
2459
+ rowSpan: mergeInfo.rowSpan
2460
+ } : {}, (mergeInfo === null || mergeInfo === void 0 ? void 0 : mergeInfo.colSpan) && mergeInfo.colSpan > 1 ? {
2461
+ colSpan: mergeInfo.colSpan
2462
+ } : {}, (mergeInfo === null || mergeInfo === void 0 ? void 0 : mergeInfo.hidden) ? {
2463
+ hidden: true
2464
+ } : {}), {
2465
+ children: ((_c_children = c.children) === null || _c_children === void 0 ? void 0 : _c_children.length) ? [
2466
+ {
2467
+ type: 'paragraph',
2468
+ children: _this.parseNodes(c.children, false, c)
2469
+ }
2470
+ ] : [
2471
+ {
2472
+ type: 'paragraph',
2473
+ children: [
2474
+ {
2475
+ text: ''
2476
+ }
2477
+ ]
2478
+ }
2479
+ ]
2480
+ });
2481
+ })
2482
+ };
2483
+ });
2484
+ // 检查表格是否完成(未闭合)
2485
+ // 如果 table 节点有 otherProps.finish,使用它;否则默认为 false(未完成)
2486
+ var isFinished = (table === null || table === void 0 ? void 0 : (_table_otherProps = table.otherProps) === null || _table_otherProps === void 0 ? void 0 : _table_otherProps.finish) !== undefined ? table.otherProps.finish : false;
2487
+ var otherProps = _object_spread_props(_object_spread({}, isChart ? {
2488
+ config: config
2489
+ } : config), {
2490
+ columns: columns.map(function(col) {
2491
+ return col.dataIndex;
2492
+ }),
2493
+ dataSource: dataSource.map(function(item) {
2494
+ item === null || item === void 0 ? true : delete item.chartType;
2495
+ return _object_spread({}, item);
2496
+ }),
2497
+ finish: isFinished
2498
+ });
2499
+ var node = {
2500
+ type: isChart ? 'chart' : 'table',
2501
+ children: children,
2502
+ otherProps: otherProps
2503
+ };
2504
+ return EditorUtils.wrapperCardNode(node);
2505
+ }
2506
+ }
2507
+ ]);
2508
+ return MarkdownToSlateParser;
2509
+ }();
1845
2510
  /**
1846
2511
  * 解析Markdown字符串并返回解析后的结构和链接信息。
1847
2512
  *
1848
2513
  * @param md - 要解析的Markdown字符串。
1849
2514
  * @param plugins - 可选的Markdown编辑器插件数组,用于扩展解析功能。
2515
+ * @param config - 可选的解析配置选项。
1850
2516
  * @returns 一个包含解析后的元素数组和链接信息的对象。
1851
2517
  *
1852
2518
  * @property schema - 解析后的元素数组。
1853
2519
  * @property links - 包含路径和目标链接的对象数组。
1854
- */ export var parserMarkdownToSlateNode = function(md, plugins) {
1855
- // 先预处理 <think> 标签,再预处理其他非标准 HTML 标签,最后处理表格换行
1856
- var thinkProcessed = preprocessThinkTags(md || '');
1857
- var nonStandardProcessed = preprocessNonStandardHtmlTags(thinkProcessed);
1858
- var processedMarkdown = mdastParser.parse(preprocessMarkdownTableNewlines(nonStandardProcessed));
1859
- var markdownRoot = processedMarkdown.children;
1860
- var pluginList = plugins || [];
1861
- var schema = parseNodes(markdownRoot, pluginList, true);
1862
- return {
1863
- schema: schema === null || schema === void 0 ? void 0 : schema.filter(function(item) {
1864
- var _item_children;
1865
- if (item.type === 'paragraph' && ((_item_children = item.children) === null || _item_children === void 0 ? void 0 : _item_children.length) === 1) {
1866
- if (item.children[0].text === '\n') {
1867
- return false;
1868
- }
1869
- return true;
1870
- }
1871
- return true;
1872
- }),
1873
- links: []
1874
- };
2520
+ *
2521
+ * @example
2522
+ * ```typescript
2523
+ * // 使用函数形式(向后兼容)
2524
+ * const result = parserMarkdownToSlateNode(markdown, plugins, { openLinksInNewTab: true });
2525
+ *
2526
+ * // 使用类形式(推荐,避免配置传递问题)
2527
+ * const parser = new MarkdownToSlateParser(
2528
+ * { openLinksInNewTab: true },
2529
+ * plugins
2530
+ * );
2531
+ * const result = parser.parse(markdown);
2532
+ * ```
2533
+ */ export var parserMarkdownToSlateNode = function(md, plugins, config) {
2534
+ var parser = new MarkdownToSlateParser(config || {}, plugins || []);
2535
+ return parser.parse(md);
1875
2536
  };