@ant-design/agentic-ui 2.16.0 → 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 (53) hide show
  1. package/dist/MarkdownEditor/editor/elements/Code.js +11 -6
  2. package/dist/MarkdownEditor/editor/elements/Table/ReadonlyTableComponent.js +15 -3
  3. package/dist/MarkdownEditor/editor/elements/Table/SimpleTable.js +17 -2
  4. package/dist/MarkdownEditor/editor/elements/Table/Table.js +131 -5
  5. package/dist/MarkdownEditor/editor/parser/parserMarkdownToSlateNode.d.ts +100 -1
  6. package/dist/MarkdownEditor/editor/parser/parserMarkdownToSlateNode.js +781 -240
  7. package/dist/MarkdownEditor/editor/types/Table.d.ts +1 -0
  8. package/dist/MarkdownEditor/editor/utils/findMatchingClose.d.ts +36 -0
  9. package/dist/MarkdownEditor/editor/utils/findMatchingClose.js +158 -0
  10. package/dist/MarkdownEditor/editor/utils/markdownToHtml.d.ts +41 -2
  11. package/dist/MarkdownEditor/editor/utils/markdownToHtml.js +159 -7
  12. package/dist/Plugins/chart/AreaChart/index.d.ts +12 -0
  13. package/dist/Plugins/chart/AreaChart/index.js +14 -188
  14. package/dist/Plugins/chart/BarChart/index.d.ts +2 -0
  15. package/dist/Plugins/chart/BarChart/index.js +3 -12
  16. package/dist/Plugins/chart/ChartMark/Container.js +5 -2
  17. package/dist/Plugins/chart/ChartRender.d.ts +1 -0
  18. package/dist/Plugins/chart/ChartRender.js +104 -43
  19. package/dist/Plugins/chart/DonutChart/index.js +4 -2
  20. package/dist/Plugins/chart/DonutChart/types.d.ts +2 -0
  21. package/dist/Plugins/chart/FunnelChart/index.d.ts +2 -0
  22. package/dist/Plugins/chart/FunnelChart/index.js +4 -2
  23. package/dist/Plugins/chart/LineChart/index.d.ts +2 -0
  24. package/dist/Plugins/chart/LineChart/index.js +17 -162
  25. package/dist/Plugins/chart/RadarChart/index.d.ts +2 -0
  26. package/dist/Plugins/chart/RadarChart/index.js +8 -4
  27. package/dist/Plugins/chart/ScatterChart/index.d.ts +2 -0
  28. package/dist/Plugins/chart/ScatterChart/index.js +8 -4
  29. package/dist/Plugins/chart/components/ChartContainer/ChartContainer.d.ts +1 -0
  30. package/dist/Plugins/chart/components/ChartFilter/ChartFilter.d.ts +1 -1
  31. package/dist/Plugins/chart/components/ChartFilter/ChartFilter.js +210 -16
  32. package/dist/Plugins/chart/components/ChartToolBar/ChartToolBar.d.ts +2 -0
  33. package/dist/Plugins/chart/components/ChartToolBar/ChartToolBar.js +9 -2
  34. package/dist/Plugins/chart/components/ChartToolBar/style.js +3 -1
  35. package/dist/Plugins/chart/hooks/index.d.ts +10 -0
  36. package/dist/Plugins/chart/hooks/index.js +8 -0
  37. package/dist/Plugins/chart/hooks/useChartDataFilter.d.ts +46 -0
  38. package/dist/Plugins/chart/hooks/useChartDataFilter.js +182 -0
  39. package/dist/Plugins/chart/hooks/useChartStatistics.d.ts +17 -0
  40. package/dist/Plugins/chart/hooks/useChartStatistics.js +25 -0
  41. package/dist/Plugins/chart/hooks/useChartTheme.d.ts +20 -0
  42. package/dist/Plugins/chart/hooks/useChartTheme.js +30 -0
  43. package/dist/Plugins/chart/hooks/useResponsiveSize.d.ts +23 -0
  44. package/dist/Plugins/chart/hooks/useResponsiveSize.js +94 -0
  45. package/dist/Plugins/chart/index.js +92 -8
  46. package/dist/Plugins/chart/utils/registerChart.d.ts +35 -0
  47. package/dist/Plugins/chart/utils/registerChart.js +54 -0
  48. package/dist/Plugins/chart/utils.d.ts +19 -0
  49. package/dist/Plugins/chart/utils.js +27 -0
  50. package/dist/Plugins/code/components/CodeRenderer.js +53 -2
  51. package/dist/Plugins/code/components/CodeToolbar.js +22 -3
  52. package/dist/Plugins/mermaid/Mermaid.js +66 -66
  53. 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,9 @@ 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$/;
137
160
  var shouldTreatInlineMathAsText = function(rawValue) {
138
161
  var trimmedValue = rawValue.trim();
139
162
  if (!trimmedValue) {
@@ -206,6 +229,17 @@ var isNumericValue = function(value) {
206
229
  ;
207
230
  });
208
231
  };
232
+ /**
233
+ * 规范化字段名,统一处理转义字符
234
+ * 将 `index\_value` 转换为 `index_value`,确保字段名一致
235
+ * @param fieldName - 原始字段名
236
+ * @returns 规范化后的字段名
237
+ */ var normalizeFieldName = function(fieldName) {
238
+ if (!fieldName) return fieldName;
239
+ // 移除转义字符:将 `\_` 转换为 `_`,`\\` 转换为 `\`
240
+ return fieldName.replace(/\\_/g, '_').replace(/\\\\/g, '\\').replace(/\\(?=")/g, '') // 移除转义的双引号
241
+ .trim();
242
+ };
209
243
  var getColumnAlignment = function(data, columns) {
210
244
  if (!data.length) return [];
211
245
  // 缓存上一次的对齐结果,避免频繁切换
@@ -478,8 +512,8 @@ var parseText = function(els) {
478
512
  }
479
513
  return leafs;
480
514
  };
481
- var parseTableOrChart = function(table, preNode, plugins) {
482
- var _table_children, _tableHeader_children, _table_children_slice, _table_children1, _table_align, _config_at, _config_at1;
515
+ var parseTableOrChart = function(table, preNode, plugins, parserConfig) {
516
+ var _table_children, _tableHeader_children, _table_children_slice, _table_children1, _table_align, _config_at, _config_at1, _table_otherProps;
483
517
  var keyMap = new Map();
484
518
  // @ts-ignore
485
519
  var config = // @ts-ignore
@@ -496,13 +530,14 @@ var parseTableOrChart = function(table, preNode, plugins) {
496
530
  ]
497
531
  })) === null || _myRemark_stringify === void 0 ? void 0 : _myRemark_stringify.replace(/\n/g, '').trim();
498
532
  }).map(function(title) {
499
- return (title === null || title === void 0 ? void 0 : title.replaceAll('\\', '')) || ' ';
533
+ // 先规范化字段名,统一处理转义字符
534
+ var normalizedTitle = normalizeFieldName(title || ' ');
535
+ return normalizedTitle;
500
536
  }).map(function(title, index) {
501
537
  if (keyMap.has(title)) {
502
- var _title_replace_replace_replace, _title_replace_replace, _title_replace;
503
538
  keyMap.set(title, keyMap.get(title) + '_' + index);
504
539
  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(),
540
+ title: title,
506
541
  dataIndex: title + '_' + index,
507
542
  key: title + '_' + index
508
543
  };
@@ -590,7 +625,7 @@ var parseTableOrChart = function(table, preNode, plugins) {
590
625
  children: ((_c_children = c.children) === null || _c_children === void 0 ? void 0 : _c_children.length) ? [
591
626
  {
592
627
  type: 'paragraph',
593
- children: parseNodes(c.children, plugins, false, c)
628
+ children: parseNodes(c.children, plugins, false, c, parserConfig)
594
629
  }
595
630
  ] : [
596
631
  {
@@ -606,6 +641,9 @@ var parseTableOrChart = function(table, preNode, plugins) {
606
641
  })
607
642
  };
608
643
  });
644
+ // 检查表格是否完成(未闭合)
645
+ // 如果 table 节点有 otherProps.finish,使用它;否则默认为 false(未完成)
646
+ 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
647
  var otherProps = _object_spread_props(_object_spread({}, isChart ? {
610
648
  config: config
611
649
  } : config), {
@@ -613,7 +651,8 @@ var parseTableOrChart = function(table, preNode, plugins) {
613
651
  dataSource: dataSource.map(function(item) {
614
652
  item === null || item === void 0 ? true : delete item.chartType;
615
653
  return _object_spread({}, item);
616
- })
654
+ }),
655
+ finish: isFinished
617
656
  });
618
657
  var node = {
619
658
  type: isChart ? 'chart' : 'table',
@@ -626,12 +665,12 @@ var parseTableOrChart = function(table, preNode, plugins) {
626
665
  * 处理标题节点
627
666
  * @param currentElement - 当前处理的标题元素,包含depth和children属性
628
667
  * @returns 返回格式化的标题节点对象
629
- */ var handleHeading = function(currentElement, plugins) {
668
+ */ var handleHeading = function(currentElement, plugins, parserConfig) {
630
669
  var _currentElement_children;
631
670
  return {
632
671
  type: 'head',
633
672
  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) : [
673
+ children: ((_currentElement_children = currentElement.children) === null || _currentElement_children === void 0 ? void 0 : _currentElement_children.length) ? parseNodes(currentElement.children, plugins, false, currentElement, parserConfig) : [
635
674
  {
636
675
  text: ''
637
676
  }
@@ -916,13 +955,13 @@ export var decodeURIComponentUrl = function(url) {
916
955
  * 处理列表节点
917
956
  * @param currentElement - 当前处理的列表元素,包含ordered、start等属性
918
957
  * @returns 返回格式化的列表节点对象
919
- */ var handleList = function(currentElement, plugins) {
958
+ */ var handleList = function(currentElement, plugins, parserConfig) {
920
959
  var _el_children;
921
960
  var el = {
922
961
  type: 'list',
923
962
  order: currentElement.ordered,
924
963
  start: currentElement.start,
925
- children: parseNodes(currentElement.children, plugins, false, currentElement)
964
+ children: parseNodes(currentElement.children, plugins, false, currentElement, parserConfig)
926
965
  };
927
966
  el.task = (_el_children = el.children) === null || _el_children === void 0 ? void 0 : _el_children.some(function(s) {
928
967
  return typeof s.checked === 'boolean';
@@ -945,9 +984,9 @@ export var decodeURIComponentUrl = function(url) {
945
984
  * 处理脚注定义
946
985
  * @param currentElement - 当前处理的脚注定义元素
947
986
  * @returns 返回格式化的脚注定义节点对象
948
- */ var handleFootnoteDefinition = function(currentElement, plugins) {
987
+ */ var handleFootnoteDefinition = function(currentElement, plugins, parserConfig) {
949
988
  var _parseNodes, _linkNode_children;
950
- var linkNode = (_parseNodes = parseNodes(currentElement.children, plugins, false, currentElement)) === null || _parseNodes === void 0 ? void 0 : _parseNodes.at(0);
989
+ var linkNode = (_parseNodes = parseNodes(currentElement.children, plugins, false, currentElement, parserConfig)) === null || _parseNodes === void 0 ? void 0 : _parseNodes.at(0);
951
990
  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
991
  return {
953
992
  value: cellNode === null || cellNode === void 0 ? void 0 : cellNode.text,
@@ -963,9 +1002,9 @@ export var decodeURIComponentUrl = function(url) {
963
1002
  * 处理列表项节点
964
1003
  * @param currentElement - 当前处理的列表项元素
965
1004
  * @returns 返回格式化的列表项节点对象,包含复选框状态和提及信息
966
- */ var handleListItem = function(currentElement, plugins) {
1005
+ */ var handleListItem = function(currentElement, plugins, parserConfig) {
967
1006
  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) : [
1007
+ var children = ((_currentElement_children = currentElement.children) === null || _currentElement_children === void 0 ? void 0 : _currentElement_children.length) ? parseNodes(currentElement.children, plugins, false, currentElement, parserConfig) : [
969
1008
  {
970
1009
  type: 'paragraph',
971
1010
  children: [
@@ -1082,7 +1121,7 @@ export var decodeURIComponentUrl = function(url) {
1082
1121
  };
1083
1122
  /**
1084
1123
  * 处理段落中的子元素
1085
- */ var processParagraphChildren = function(currentElement, plugins) {
1124
+ */ var processParagraphChildren = function(currentElement, plugins, parserConfig) {
1086
1125
  var elements = [];
1087
1126
  var textNodes = [];
1088
1127
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
@@ -1094,7 +1133,7 @@ export var decodeURIComponentUrl = function(url) {
1094
1133
  if (textNodes.length) {
1095
1134
  elements.push({
1096
1135
  type: 'paragraph',
1097
- children: parseNodes(textNodes, plugins, false, currentElement)
1136
+ children: parseNodes(textNodes, plugins, false, currentElement, parserConfig)
1098
1137
  });
1099
1138
  textNodes = [];
1100
1139
  }
@@ -1141,7 +1180,7 @@ export var decodeURIComponentUrl = function(url) {
1141
1180
  if (textNodes.length) {
1142
1181
  elements.push({
1143
1182
  type: 'paragraph',
1144
- children: parseNodes(textNodes, plugins, false, currentElement)
1183
+ children: parseNodes(textNodes, plugins, false, currentElement, undefined)
1145
1184
  });
1146
1185
  }
1147
1186
  return elements;
@@ -1152,7 +1191,7 @@ export var decodeURIComponentUrl = function(url) {
1152
1191
  * @param config - 配置对象,包含样式和行为设置
1153
1192
  * @param plugins - 插件数组
1154
1193
  * @returns 返回格式化的段落节点对象或元素数组
1155
- */ var handleParagraph = function(currentElement, config, plugins) {
1194
+ */ var handleParagraph = function(currentElement, config, plugins, parserConfig) {
1156
1195
  var _currentElement_children, _currentElement_children_at, _currentElement_children1;
1157
1196
  // 检查是否是附件链接
1158
1197
  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 +1203,7 @@ export var decodeURIComponentUrl = function(url) {
1164
1203
  return handleLinkCard(currentElement, config);
1165
1204
  }
1166
1205
  // 处理混合内容段落
1167
- return processParagraphChildren(currentElement, plugins);
1206
+ return processParagraphChildren(currentElement, plugins, parserConfig);
1168
1207
  };
1169
1208
  /**
1170
1209
  * 处理内联代码节点
@@ -1205,7 +1244,34 @@ export var decodeURIComponentUrl = function(url) {
1205
1244
  * @param currentElement - 当前处理的代码块元素,包含语言和内容
1206
1245
  * @returns 返回格式化的代码块节点对象,根据语言类型进行特殊处理
1207
1246
  */ var handleCode = function(currentElement) {
1208
- var _currentElement_value_trim;
1247
+ var _match, _currentElement_otherProps, _currentElement_value_trim;
1248
+ var rawValue = currentElement.value || '';
1249
+ var langString = ((_match = (currentElement.lang || '').match(NOT_SPACE_START)) === null || _match === void 0 ? void 0 : _match[0]) || '';
1250
+ var code = "".concat(rawValue.replace(ENDING_NEWLINE, ''), "\n");
1251
+ // 检查代码块是否完整
1252
+ // 如果是缩进代码块,认为是完整的(因为没有结束标记)
1253
+ var isIndentedCode = currentElement.meta === 'indented';
1254
+ // 使用更智能的方法判断代码块是否完整
1255
+ var streamStatus = 'loading';
1256
+ if (isIndentedCode) {
1257
+ // 缩进代码块没有结束标记,认为是完整的
1258
+ streamStatus = 'done';
1259
+ } else {
1260
+ // 对于围栏代码块,使用多种方法判断
1261
+ var endsWithNewline = code.match(ENDING_NEWLINE);
1262
+ // 如果代码以换行结尾,可能是完整的
1263
+ if (endsWithNewline) {
1264
+ // 进一步检查代码内容是否完整(特别是对于 Mermaid 等需要完整语法的情况)
1265
+ var isLikelyComplete = isCodeBlockLikelyComplete(rawValue, currentElement.lang);
1266
+ streamStatus = isLikelyComplete ? 'done' : 'loading';
1267
+ } else {
1268
+ // 没有换行结尾,肯定不完整
1269
+ streamStatus = 'loading';
1270
+ }
1271
+ }
1272
+ // 如果已经在 parseNodes 中设置了 finish(基于是否是最后一个节点),优先使用它
1273
+ // 否则使用 streamStatus 判断
1274
+ var finishValue = ((_currentElement_otherProps = currentElement.otherProps) === null || _currentElement_otherProps === void 0 ? void 0 : _currentElement_otherProps.finish) !== undefined ? currentElement.otherProps.finish : streamStatus === 'done';
1209
1275
  var baseCodeElement = {
1210
1276
  type: 'code',
1211
1277
  language: currentElement.lang === 'apaasify' ? 'apaasify' : currentElement.lang,
@@ -1216,10 +1282,27 @@ export var decodeURIComponentUrl = function(url) {
1216
1282
  {
1217
1283
  text: currentElement.value
1218
1284
  }
1219
- ]
1285
+ ],
1286
+ // 添加流式状态支持
1287
+ otherProps: _object_spread(_object_spread_props(_object_spread({}, currentElement.otherProps || {}), {
1288
+ 'data-block': 'true',
1289
+ 'data-state': streamStatus,
1290
+ // 优先使用 parseNodes 中设置的 finish,否则使用 streamStatus 判断
1291
+ finish: finishValue
1292
+ }), langString ? {
1293
+ 'data-language': langString
1294
+ } : {})
1220
1295
  };
1221
1296
  var handler = LANGUAGE_HANDLERS[currentElement.lang];
1222
- return handler ? handler(baseCodeElement, currentElement.value) : baseCodeElement;
1297
+ var result = handler ? handler(baseCodeElement, currentElement.value) : baseCodeElement;
1298
+ // 确保 otherProps 被保留
1299
+ var resultWithProps = result;
1300
+ if (baseCodeElement.otherProps && !resultWithProps.otherProps) {
1301
+ resultWithProps.otherProps = baseCodeElement.otherProps;
1302
+ } else if (baseCodeElement.otherProps && resultWithProps.otherProps) {
1303
+ resultWithProps.otherProps = _object_spread({}, resultWithProps.otherProps, baseCodeElement.otherProps);
1304
+ }
1305
+ return resultWithProps;
1223
1306
  };
1224
1307
  /**
1225
1308
  * 处理YAML节点
@@ -1242,11 +1325,11 @@ export var decodeURIComponentUrl = function(url) {
1242
1325
  * 处理引用块节点
1243
1326
  * @param currentElement - 当前处理的引用块元素
1244
1327
  * @returns 返回格式化的引用块节点对象
1245
- */ var handleBlockquote = function(currentElement, plugins) {
1328
+ */ var handleBlockquote = function(currentElement, plugins, parserConfig) {
1246
1329
  var _currentElement_children;
1247
1330
  return {
1248
1331
  type: 'blockquote',
1249
- children: ((_currentElement_children = currentElement.children) === null || _currentElement_children === void 0 ? void 0 : _currentElement_children.length) ? parseNodes(currentElement.children, plugins, false, currentElement) : [
1332
+ children: ((_currentElement_children = currentElement.children) === null || _currentElement_children === void 0 ? void 0 : _currentElement_children.length) ? parseNodes(currentElement.children, plugins, false, currentElement, parserConfig) : [
1250
1333
  {
1251
1334
  type: 'paragraph',
1252
1335
  children: [
@@ -1272,79 +1355,6 @@ export var decodeURIComponentUrl = function(url) {
1272
1355
  ]
1273
1356
  };
1274
1357
  };
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
1358
  /**
1349
1359
  * 应用HTML标签样式到元素
1350
1360
  * @param el - 目标元素对象
@@ -1437,6 +1447,7 @@ export var decodeURIComponentUrl = function(url) {
1437
1447
  };
1438
1448
  /**
1439
1449
  * 元素处理器映射表
1450
+ * 注意:这些处理器需要通过 handleSingleElement 传递 parserConfig
1440
1451
  */ var elementHandlers = {
1441
1452
  heading: {
1442
1453
  handler: function(el, plugins) {
@@ -1526,129 +1537,17 @@ export var decodeURIComponentUrl = function(url) {
1526
1537
  }
1527
1538
  };
1528
1539
  /**
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节点数组
1540
+ * 解析 Markdown AST 节点为 Slate 节点(独立函数版本,用于向后兼容)
1541
+ * 内部使用 MarkdownToSlateParser 类来处理
1560
1542
  *
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
- * - 插件未处理时,使用默认处理逻辑
1543
+ * @deprecated 建议直接使用 MarkdownToSlateParser 类
1573
1544
  */ 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;
1545
+ 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;
1546
+ // 创建一个临时 parser 实例来处理
1547
+ // 注意:这不是最优的方式,但为了向后兼容保留
1548
+ // 使用类型断言访问私有方法
1549
+ var parser = new MarkdownToSlateParser(parserConfig || {}, plugins || []);
1550
+ return parser.parseNodes(nodes, top, parent);
1652
1551
  };
1653
1552
  var tableRegex = /^\|.*\|\s*\n\|[-:| ]+\|/m;
1654
1553
  /**
@@ -1842,34 +1741,676 @@ function preprocessMarkdownTableNewlines(markdown) {
1842
1741
  });
1843
1742
  }).join('\n\n');
1844
1743
  }
1744
+ /**
1745
+ * Markdown 到 Slate 节点解析器类
1746
+ *
1747
+ * 将 Markdown 字符串解析为 Slate 编辑器节点,支持配置选项和插件。
1748
+ * 使用类形式可以避免在函数调用链中传递配置参数和插件。
1749
+ */ export var MarkdownToSlateParser = /*#__PURE__*/ function() {
1750
+ "use strict";
1751
+ function MarkdownToSlateParser() {
1752
+ var config = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, plugins = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
1753
+ _class_call_check(this, MarkdownToSlateParser);
1754
+ _define_property(this, "config", void 0);
1755
+ _define_property(this, "plugins", void 0);
1756
+ this.config = config;
1757
+ this.plugins = plugins;
1758
+ }
1759
+ _create_class(MarkdownToSlateParser, [
1760
+ {
1761
+ /**
1762
+ * 解析 Markdown 字符串并返回解析后的结构和链接信息
1763
+ *
1764
+ * @param md - 要解析的 Markdown 字符串
1765
+ * @returns 一个包含解析后的元素数组和链接信息的对象
1766
+ */ key: "parse",
1767
+ value: function parse(md) {
1768
+ // 先预处理 <think> 标签,再预处理其他非标准 HTML 标签,最后处理表格换行
1769
+ var thinkProcessed = preprocessThinkTags(md || '');
1770
+ var nonStandardProcessed = preprocessNonStandardHtmlTags(thinkProcessed);
1771
+ var processedMarkdown = mdastParser.parse(preprocessMarkdownTableNewlines(nonStandardProcessed));
1772
+ var markdownRoot = processedMarkdown.children;
1773
+ // 使用类的配置和插件,通过 this 访问
1774
+ var schema = this.parseNodes(markdownRoot, true, undefined);
1775
+ return {
1776
+ schema: schema === null || schema === void 0 ? void 0 : schema.filter(function(item) {
1777
+ var _item_children;
1778
+ if (item.type === 'paragraph' && ((_item_children = item.children) === null || _item_children === void 0 ? void 0 : _item_children.length) === 1) {
1779
+ if (item.children[0].text === '\n') {
1780
+ return false;
1781
+ }
1782
+ return true;
1783
+ }
1784
+ return true;
1785
+ }),
1786
+ links: []
1787
+ };
1788
+ }
1789
+ },
1790
+ {
1791
+ key: "parseNodes",
1792
+ value: /**
1793
+ * 解析 Markdown AST 节点为 Slate 节点(类方法版本)
1794
+ * - 当有插件时,优先使用插件处理
1795
+ * - 插件未处理时,使用默认处理逻辑
1796
+ */ function parseNodes(nodes) {
1797
+ var _this, _loop = function(i) {
1798
+ var currentElement = nodes[i];
1799
+ var el = null;
1800
+ var pluginHandled = false;
1801
+ 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 : {};
1802
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1803
+ try {
1804
+ // 首先尝试使用插件处理,使用 this.plugins
1805
+ for(var _iterator = _this.plugins[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1806
+ var plugin = _step.value;
1807
+ var _plugin_parseMarkdown;
1808
+ var rule = (_plugin_parseMarkdown = plugin.parseMarkdown) === null || _plugin_parseMarkdown === void 0 ? void 0 : _plugin_parseMarkdown.find(function(r) {
1809
+ return r.match(currentElement);
1810
+ });
1811
+ if (rule) {
1812
+ var converted = rule.convert(currentElement);
1813
+ // 检查转换结果是否为 NodeEntry<Text> 格式
1814
+ if (Array.isArray(converted) && converted.length === 2) {
1815
+ // NodeEntry<Text> 格式: [node, path]
1816
+ el = converted[0];
1817
+ } else {
1818
+ // Elements 格式
1819
+ el = converted;
1820
+ }
1821
+ pluginHandled = true;
1822
+ break;
1823
+ }
1824
+ }
1825
+ } catch (err) {
1826
+ _didIteratorError = true;
1827
+ _iteratorError = err;
1828
+ } finally{
1829
+ try {
1830
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1831
+ _iterator.return();
1832
+ }
1833
+ } finally{
1834
+ if (_didIteratorError) {
1835
+ throw _iteratorError;
1836
+ }
1837
+ }
1838
+ }
1839
+ // 如果插件没有处理,使用默认处理逻辑
1840
+ if (!pluginHandled) {
1841
+ var isLastNode = i === nodes.length - 1;
1842
+ // 如果是 table 节点,检查是否是最后一个节点,设置 finish 属性
1843
+ if (currentElement.type === 'table') {
1844
+ // 如果 table 不是最后一个节点,finish 设置为 true
1845
+ if (!isLastNode) {
1846
+ if (!currentElement.otherProps) {
1847
+ currentElement.otherProps = {};
1848
+ }
1849
+ currentElement.otherProps.finish = true;
1850
+ } else {
1851
+ // 如果是最后一个节点,且 typing=false,finish 设置为 true
1852
+ if (_this.config.typing === false) {
1853
+ if (!currentElement.otherProps) {
1854
+ currentElement.otherProps = {};
1855
+ }
1856
+ currentElement.otherProps.finish = true;
1857
+ }
1858
+ // 否则保持原逻辑(在 parseTableOrChart 中处理,默认为 false)
1859
+ }
1860
+ }
1861
+ // 如果是 code 节点,检查是否是最后一个节点,设置 finish 属性
1862
+ if (currentElement.type === 'code') {
1863
+ // 如果 code 不是最后一个节点,finish 设置为 true
1864
+ if (!isLastNode) {
1865
+ if (!currentElement.otherProps) {
1866
+ currentElement.otherProps = {};
1867
+ }
1868
+ currentElement.otherProps.finish = true;
1869
+ }
1870
+ // 如果是最后一个节点,保持原逻辑(在 handleCode 中处理)
1871
+ }
1872
+ // 使用统一的处理函数,通过 this 访问配置和插件
1873
+ var result = _this.handleSingleElement(currentElement, config, parent, htmlTag, preElement);
1874
+ el = result.el;
1875
+ if (result.contextProps) {
1876
+ contextProps = _object_spread({}, contextProps, result.contextProps);
1877
+ }
1878
+ }
1879
+ addEmptyLinesIfNeeded(els, preNode, currentElement, top);
1880
+ if (el) {
1881
+ var _els;
1882
+ el = applyContextPropsAndConfig(el, contextProps, config);
1883
+ Array.isArray(el) ? (_els = els).push.apply(_els, _to_consumable_array(el)) : els.push(el);
1884
+ }
1885
+ preNode = currentElement;
1886
+ preElement = el;
1887
+ };
1888
+ var top = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false, parent = arguments.length > 2 ? arguments[2] : void 0;
1889
+ if (!(nodes === null || nodes === void 0 ? void 0 : nodes.length)) return [
1890
+ {
1891
+ type: 'paragraph',
1892
+ children: [
1893
+ {
1894
+ text: ''
1895
+ }
1896
+ ]
1897
+ }
1898
+ ];
1899
+ var els = [];
1900
+ var preNode = null;
1901
+ var preElement = null;
1902
+ var htmlTag = [];
1903
+ var contextProps = {};
1904
+ for(var i = 0; i < nodes.length; i++)_this = this, _loop(i);
1905
+ return els;
1906
+ }
1907
+ },
1908
+ {
1909
+ key: "handleSingleElement",
1910
+ value: /**
1911
+ * 处理单个元素(类方法版本)
1912
+ */ function handleSingleElement(currentElement, config, parent, htmlTag, preElement) {
1913
+ var elementType = currentElement.type;
1914
+ var handlerInfo = elementHandlers[elementType];
1915
+ // 特殊处理 html 类型
1916
+ if (handlerInfo === null || handlerInfo === void 0 ? void 0 : handlerInfo.needsHtmlResult) {
1917
+ var htmlResult = handleHtml(currentElement, parent, htmlTag);
1918
+ return {
1919
+ el: htmlResult.el,
1920
+ contextProps: htmlResult.contextProps
1921
+ };
1922
+ }
1923
+ // 使用处理器映射表
1924
+ // 对于需要 parserConfig 的处理器,直接调用而不是通过 handler
1925
+ if (handlerInfo) {
1926
+ var handlerResult;
1927
+ // 特殊处理需要 parserConfig 的处理器,使用 this.config 和 this.plugins
1928
+ if (elementType === 'heading') {
1929
+ handlerResult = this.handleHeading(currentElement);
1930
+ } else if (elementType === 'list') {
1931
+ handlerResult = this.handleList(currentElement);
1932
+ } else if (elementType === 'listItem') {
1933
+ handlerResult = this.handleListItem(currentElement);
1934
+ } else if (elementType === 'blockquote') {
1935
+ handlerResult = this.handleBlockquote(currentElement);
1936
+ } else if (elementType === 'footnoteDefinition') {
1937
+ handlerResult = this.handleFootnoteDefinition(currentElement);
1938
+ } else if (elementType === 'paragraph') {
1939
+ handlerResult = this.handleParagraph(currentElement, config);
1940
+ } else if (elementType === 'table') {
1941
+ handlerResult = this.parseTableOrChart(currentElement, preElement || parent);
1942
+ } else {
1943
+ // 使用默认的 handler 调用
1944
+ handlerResult = handlerInfo.handler(currentElement, this.plugins, config, parent, htmlTag, preElement);
1945
+ }
1946
+ return {
1947
+ el: handlerResult
1948
+ };
1949
+ }
1950
+ // 默认处理
1951
+ return {
1952
+ el: this.handleTextAndInlineElements(currentElement, htmlTag)
1953
+ };
1954
+ }
1955
+ },
1956
+ {
1957
+ key: "handleHeading",
1958
+ value: /**
1959
+ * 处理标题节点(类方法版本)
1960
+ */ function handleHeading(currentElement) {
1961
+ var _currentElement_children;
1962
+ return {
1963
+ type: 'head',
1964
+ level: currentElement.depth,
1965
+ children: ((_currentElement_children = currentElement.children) === null || _currentElement_children === void 0 ? void 0 : _currentElement_children.length) ? this.parseNodes(currentElement.children, false, currentElement) : [
1966
+ {
1967
+ text: ''
1968
+ }
1969
+ ]
1970
+ };
1971
+ }
1972
+ },
1973
+ {
1974
+ key: "handleList",
1975
+ value: /**
1976
+ * 处理列表节点(类方法版本)
1977
+ */ function handleList(currentElement) {
1978
+ var _el_children;
1979
+ var el = {
1980
+ type: 'list',
1981
+ order: currentElement.ordered,
1982
+ start: currentElement.start,
1983
+ children: this.parseNodes(currentElement.children, false, currentElement)
1984
+ };
1985
+ el.task = (_el_children = el.children) === null || _el_children === void 0 ? void 0 : _el_children.some(function(s) {
1986
+ return typeof s.checked === 'boolean';
1987
+ });
1988
+ return el;
1989
+ }
1990
+ },
1991
+ {
1992
+ key: "handleFootnoteDefinition",
1993
+ value: /**
1994
+ * 处理脚注定义节点(类方法版本)
1995
+ */ function handleFootnoteDefinition(currentElement) {
1996
+ var _this_parseNodes, _linkNode_children;
1997
+ var linkNode = (_this_parseNodes = this.parseNodes(currentElement.children, false, currentElement)) === null || _this_parseNodes === void 0 ? void 0 : _this_parseNodes.at(0);
1998
+ var cellNode = linkNode === null || linkNode === void 0 ? void 0 : (_linkNode_children = linkNode.children) === null || _linkNode_children === void 0 ? void 0 : _linkNode_children.at(0);
1999
+ return {
2000
+ value: cellNode === null || cellNode === void 0 ? void 0 : cellNode.text,
2001
+ url: cellNode === null || cellNode === void 0 ? void 0 : cellNode.url,
2002
+ type: 'footnoteDefinition',
2003
+ identifier: currentElement.identifier,
2004
+ children: [
2005
+ cellNode
2006
+ ]
2007
+ };
2008
+ }
2009
+ },
2010
+ {
2011
+ key: "handleListItem",
2012
+ value: /**
2013
+ * 处理列表项节点(类方法版本)
2014
+ */ function handleListItem(currentElement) {
2015
+ var _currentElement_children, _currentElement_children__children_, _currentElement_children__children, _currentElement_children_, _currentElement_children1, _currentElement_children__children1, _currentElement_children_1, _currentElement_children2;
2016
+ var children = ((_currentElement_children = currentElement.children) === null || _currentElement_children === void 0 ? void 0 : _currentElement_children.length) ? this.parseNodes(currentElement.children, false, currentElement) : [
2017
+ {
2018
+ type: 'paragraph',
2019
+ children: [
2020
+ {
2021
+ text: ''
2022
+ }
2023
+ ]
2024
+ }
2025
+ ];
2026
+ var mentions = undefined;
2027
+ 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) {
2028
+ var _children__children, _children_;
2029
+ 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];
2030
+ var label = item === null || item === void 0 ? void 0 : item.text;
2031
+ if (label) {
2032
+ var _item_url, _children__children1, _children_1;
2033
+ mentions = [
2034
+ {
2035
+ avatar: item === null || item === void 0 ? void 0 : item.url,
2036
+ name: label,
2037
+ 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
2038
+ }
2039
+ ];
2040
+ 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];
2041
+ }
2042
+ }
2043
+ return {
2044
+ type: 'list-item',
2045
+ checked: currentElement.checked,
2046
+ children: children,
2047
+ mentions: mentions
2048
+ };
2049
+ }
2050
+ },
2051
+ {
2052
+ key: "processParagraphChildren",
2053
+ value: /**
2054
+ * 处理段落子节点(类方法版本)
2055
+ */ function processParagraphChildren(currentElement) {
2056
+ var elements = [];
2057
+ var textNodes = [];
2058
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
2059
+ try {
2060
+ for(var _iterator = (currentElement.children || [])[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2061
+ var currentChild = _step.value;
2062
+ if (currentChild.type === 'image') {
2063
+ // 将累积的文本节点生成段落
2064
+ if (textNodes.length) {
2065
+ elements.push({
2066
+ type: 'paragraph',
2067
+ children: this.parseNodes(textNodes, false, currentElement)
2068
+ });
2069
+ textNodes = [];
2070
+ }
2071
+ // 添加图片节点
2072
+ elements.push(EditorUtils.createMediaNode(decodeURIComponentUrl(currentChild === null || currentChild === void 0 ? void 0 : currentChild.url), 'image', {
2073
+ alt: currentChild.alt
2074
+ }));
2075
+ } else if (currentChild.type === 'html') {
2076
+ // 跳过媒体标签的结束标签
2077
+ if (currentChild.value.match(/^<\/(img|video|iframe)>/)) {
2078
+ continue;
2079
+ }
2080
+ var mediaElement = findImageElement(currentChild.value);
2081
+ if (mediaElement) {
2082
+ var node = createMediaNodeFromElement(mediaElement);
2083
+ if (node) {
2084
+ elements.push(node);
2085
+ }
2086
+ } else {
2087
+ textNodes.push({
2088
+ type: 'html',
2089
+ value: currentChild.value
2090
+ });
2091
+ }
2092
+ } else {
2093
+ textNodes.push(currentChild);
2094
+ }
2095
+ }
2096
+ } catch (err) {
2097
+ _didIteratorError = true;
2098
+ _iteratorError = err;
2099
+ } finally{
2100
+ try {
2101
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
2102
+ _iterator.return();
2103
+ }
2104
+ } finally{
2105
+ if (_didIteratorError) {
2106
+ throw _iteratorError;
2107
+ }
2108
+ }
2109
+ }
2110
+ // 处理剩余的文本节点
2111
+ if (textNodes.length) {
2112
+ elements.push({
2113
+ type: 'paragraph',
2114
+ children: this.parseNodes(textNodes, false, currentElement)
2115
+ });
2116
+ }
2117
+ return elements;
2118
+ }
2119
+ },
2120
+ {
2121
+ key: "handleParagraph",
2122
+ value: /**
2123
+ * 处理段落节点(类方法版本)
2124
+ */ function handleParagraph(currentElement, config) {
2125
+ var _currentElement_children, _currentElement_children_at, _currentElement_children1;
2126
+ // 检查是否是附件链接
2127
+ if (((_currentElement_children = currentElement.children) === null || _currentElement_children === void 0 ? void 0 : _currentElement_children[0].type) === 'html' && currentElement.children[0].value.startsWith('<a')) {
2128
+ var attachNode = handleAttachmentLink(currentElement);
2129
+ if (attachNode) return attachNode;
2130
+ }
2131
+ // 检查是否是链接卡片
2132
+ 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') {
2133
+ return handleLinkCard(currentElement, config);
2134
+ }
2135
+ // 处理混合内容段落
2136
+ return this.processParagraphChildren(currentElement);
2137
+ }
2138
+ },
2139
+ {
2140
+ key: "handleBlockquote",
2141
+ value: /**
2142
+ * 处理引用块节点(类方法版本)
2143
+ */ function handleBlockquote(currentElement) {
2144
+ var _currentElement_children;
2145
+ return {
2146
+ type: 'blockquote',
2147
+ children: ((_currentElement_children = currentElement.children) === null || _currentElement_children === void 0 ? void 0 : _currentElement_children.length) ? this.parseNodes(currentElement.children, false, currentElement) : [
2148
+ {
2149
+ type: 'paragraph',
2150
+ children: [
2151
+ {
2152
+ text: ''
2153
+ }
2154
+ ]
2155
+ }
2156
+ ]
2157
+ };
2158
+ }
2159
+ },
2160
+ {
2161
+ key: "handleTextAndInlineElements",
2162
+ value: /**
2163
+ * 处理文本和内联元素节点(类方法版本)
2164
+ */ function handleTextAndInlineElements(currentElement, htmlTag) {
2165
+ if (currentElement.type === 'text' && htmlTag.length) {
2166
+ var el = {
2167
+ text: currentElement.value
2168
+ };
2169
+ if (currentElement.value) {
2170
+ applyHtmlTagsToElement(el, htmlTag);
2171
+ }
2172
+ return el;
2173
+ }
2174
+ if ([
2175
+ 'strong',
2176
+ 'link',
2177
+ 'text',
2178
+ 'emphasis',
2179
+ 'delete',
2180
+ 'inlineCode'
2181
+ ].includes(currentElement.type)) {
2182
+ var _currentElement_children;
2183
+ if (currentElement.type === 'text') {
2184
+ return {
2185
+ text: currentElement.value
2186
+ };
2187
+ }
2188
+ var leaf = {};
2189
+ this.applyInlineFormatting(leaf, currentElement);
2190
+ applyHtmlTagsToElement(leaf, htmlTag);
2191
+ if (currentElement === null || currentElement === void 0 ? void 0 : (_currentElement_children = currentElement.children) === null || _currentElement_children === void 0 ? void 0 : _currentElement_children.some(function(n) {
2192
+ return n.type === 'html';
2193
+ })) {
2194
+ var _this_parseNodes;
2195
+ 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)), {
2196
+ url: leaf.url
2197
+ });
2198
+ } else {
2199
+ var _currentElement_children1;
2200
+ return parseText(((_currentElement_children1 = currentElement.children) === null || _currentElement_children1 === void 0 ? void 0 : _currentElement_children1.length) ? currentElement.children : [
2201
+ {
2202
+ value: (leaf === null || leaf === void 0 ? void 0 : leaf.url) || ''
2203
+ }
2204
+ ], leaf);
2205
+ }
2206
+ }
2207
+ if (currentElement.type === 'break') {
2208
+ return {
2209
+ text: '\n'
2210
+ };
2211
+ }
2212
+ return {
2213
+ text: ''
2214
+ };
2215
+ }
2216
+ },
2217
+ {
2218
+ key: "applyInlineFormatting",
2219
+ value: /**
2220
+ * 应用内联格式到叶子节点(类方法版本)
2221
+ */ function applyInlineFormatting(leaf, currentElement) {
2222
+ if (currentElement.type === 'strong') leaf.bold = true;
2223
+ if (currentElement.type === 'emphasis') leaf.italic = true;
2224
+ if (currentElement.type === 'delete') leaf.strikethrough = true;
2225
+ if (currentElement.type === 'link') {
2226
+ try {
2227
+ var _this_config;
2228
+ leaf.url = currentElement === null || currentElement === void 0 ? void 0 : currentElement.url;
2229
+ // 如果配置了在新标签页打开链接,添加 target 和 rel 属性
2230
+ if ((_this_config = this.config) === null || _this_config === void 0 ? void 0 : _this_config.openLinksInNewTab) {
2231
+ // 使用 otherProps 存储额外的链接属性
2232
+ if (!leaf.otherProps) {
2233
+ leaf.otherProps = {};
2234
+ }
2235
+ leaf.otherProps.target = '_blank';
2236
+ leaf.otherProps.rel = 'noopener noreferrer';
2237
+ }
2238
+ } catch (error) {
2239
+ leaf.url = currentElement === null || currentElement === void 0 ? void 0 : currentElement.url;
2240
+ }
2241
+ }
2242
+ }
2243
+ },
2244
+ {
2245
+ key: "parseTableOrChart",
2246
+ value: /**
2247
+ * 解析表格或图表(类方法版本)
2248
+ */ function parseTableOrChart(table, preNode) {
2249
+ var _this = this;
2250
+ var _table_children, _tableHeader_children, _table_children_slice, _table_children1, _table_align, _config_at, _config_at1, _table_otherProps;
2251
+ var keyMap = new Map();
2252
+ // @ts-ignore
2253
+ var config = // @ts-ignore
2254
+ (preNode === null || preNode === void 0 ? void 0 : preNode.type) === 'code' && // @ts-ignore
2255
+ (preNode === null || preNode === void 0 ? void 0 : preNode.language) === 'html' && (// @ts-ignore
2256
+ preNode === null || preNode === void 0 ? void 0 : preNode.otherProps) ? preNode === null || preNode === void 0 ? void 0 : preNode.otherProps : {};
2257
+ var tableHeader = table === null || table === void 0 ? void 0 : (_table_children = table.children) === null || _table_children === void 0 ? void 0 : _table_children.at(0);
2258
+ 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) {
2259
+ return myRemark.stringify({
2260
+ type: 'root',
2261
+ children: [
2262
+ node
2263
+ ]
2264
+ }).trim();
2265
+ }).map(function(key) {
2266
+ // 规范化字段名,统一处理转义字符
2267
+ var normalizedKey = normalizeFieldName(key);
2268
+ var value = keyMap.get(normalizedKey) || normalizedKey;
2269
+ return value;
2270
+ }).map(function(key) {
2271
+ return {
2272
+ dataIndex: key
2273
+ };
2274
+ })) || [];
2275
+ 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) {
2276
+ var _row_children;
2277
+ return (_row_children = row.children) === null || _row_children === void 0 ? void 0 : _row_children.reduce(function(acc, cell, index) {
2278
+ var column = columns[index];
2279
+ var key = (column === null || column === void 0 ? void 0 : column.dataIndex) || (typeof column === 'string' ? column : undefined);
2280
+ if (key) {
2281
+ acc[key] = myRemark.stringify({
2282
+ type: 'root',
2283
+ children: [
2284
+ cell
2285
+ ]
2286
+ }).trim();
2287
+ }
2288
+ return acc;
2289
+ }, {});
2290
+ })) || [];
2291
+ if ((_table_align = table.align) === null || _table_align === void 0 ? void 0 : _table_align.every(function(item) {
2292
+ return !item;
2293
+ })) {
2294
+ var aligns = getColumnAlignment(dataSource, columns);
2295
+ table.align = aligns;
2296
+ }
2297
+ var aligns1 = table.align;
2298
+ 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);
2299
+ // 计算合并单元格信息
2300
+ var mergeCells = config.mergeCells || [];
2301
+ // 创建合并单元格映射,用于快速查找
2302
+ var mergeMap = new Map();
2303
+ mergeCells === null || mergeCells === void 0 ? void 0 : mergeCells.forEach(function(param) {
2304
+ var row = param.row, col = param.col, rowSpan = param.rowSpan, rowspan = param.rowspan, colSpan = param.colSpan, colspan = param.colspan;
2305
+ var rawRowSpan = rowSpan || rowspan;
2306
+ var rawColSpan = colSpan || colspan;
2307
+ // 主单元格
2308
+ mergeMap.set("".concat(row, "-").concat(col), {
2309
+ rowSpan: rawRowSpan,
2310
+ colSpan: rawColSpan
2311
+ });
2312
+ // 被合并的单元格标记为隐藏
2313
+ for(var r = row; r < row + rawRowSpan; r++){
2314
+ for(var c = col; c < col + rawColSpan; c++){
2315
+ if (r !== row || c !== col) {
2316
+ mergeMap.set("".concat(r, "-").concat(c), {
2317
+ rowSpan: 1,
2318
+ colSpan: 1,
2319
+ hidden: true
2320
+ });
2321
+ }
2322
+ }
2323
+ }
2324
+ });
2325
+ var children = table.children.map(function(r, l) {
2326
+ return {
2327
+ type: 'table-row',
2328
+ align: (aligns1 === null || aligns1 === void 0 ? void 0 : aligns1[l]) || undefined,
2329
+ children: r.children.map(function(c, i) {
2330
+ var _c_children;
2331
+ var mergeInfo = mergeMap.get("".concat(l, "-").concat(i));
2332
+ return _object_spread_props(_object_spread({
2333
+ type: 'table-cell',
2334
+ align: (aligns1 === null || aligns1 === void 0 ? void 0 : aligns1[i]) || undefined,
2335
+ title: l === 0,
2336
+ rows: l,
2337
+ cols: i
2338
+ }, (mergeInfo === null || mergeInfo === void 0 ? void 0 : mergeInfo.rowSpan) && mergeInfo.rowSpan > 1 ? {
2339
+ rowSpan: mergeInfo.rowSpan
2340
+ } : {}, (mergeInfo === null || mergeInfo === void 0 ? void 0 : mergeInfo.colSpan) && mergeInfo.colSpan > 1 ? {
2341
+ colSpan: mergeInfo.colSpan
2342
+ } : {}, (mergeInfo === null || mergeInfo === void 0 ? void 0 : mergeInfo.hidden) ? {
2343
+ hidden: true
2344
+ } : {}), {
2345
+ children: ((_c_children = c.children) === null || _c_children === void 0 ? void 0 : _c_children.length) ? [
2346
+ {
2347
+ type: 'paragraph',
2348
+ children: _this.parseNodes(c.children, false, c)
2349
+ }
2350
+ ] : [
2351
+ {
2352
+ type: 'paragraph',
2353
+ children: [
2354
+ {
2355
+ text: ''
2356
+ }
2357
+ ]
2358
+ }
2359
+ ]
2360
+ });
2361
+ })
2362
+ };
2363
+ });
2364
+ // 检查表格是否完成(未闭合)
2365
+ // 如果 table 节点有 otherProps.finish,使用它;否则默认为 false(未完成)
2366
+ 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;
2367
+ var otherProps = _object_spread_props(_object_spread({}, isChart ? {
2368
+ config: config
2369
+ } : config), {
2370
+ columns: columns.map(function(col) {
2371
+ return col.dataIndex;
2372
+ }),
2373
+ dataSource: dataSource.map(function(item) {
2374
+ item === null || item === void 0 ? true : delete item.chartType;
2375
+ return _object_spread({}, item);
2376
+ }),
2377
+ finish: isFinished
2378
+ });
2379
+ var node = {
2380
+ type: isChart ? 'chart' : 'table',
2381
+ children: children,
2382
+ otherProps: otherProps
2383
+ };
2384
+ return EditorUtils.wrapperCardNode(node);
2385
+ }
2386
+ }
2387
+ ]);
2388
+ return MarkdownToSlateParser;
2389
+ }();
1845
2390
  /**
1846
2391
  * 解析Markdown字符串并返回解析后的结构和链接信息。
1847
2392
  *
1848
2393
  * @param md - 要解析的Markdown字符串。
1849
2394
  * @param plugins - 可选的Markdown编辑器插件数组,用于扩展解析功能。
2395
+ * @param config - 可选的解析配置选项。
1850
2396
  * @returns 一个包含解析后的元素数组和链接信息的对象。
1851
2397
  *
1852
2398
  * @property schema - 解析后的元素数组。
1853
2399
  * @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
- };
2400
+ *
2401
+ * @example
2402
+ * ```typescript
2403
+ * // 使用函数形式(向后兼容)
2404
+ * const result = parserMarkdownToSlateNode(markdown, plugins, { openLinksInNewTab: true });
2405
+ *
2406
+ * // 使用类形式(推荐,避免配置传递问题)
2407
+ * const parser = new MarkdownToSlateParser(
2408
+ * { openLinksInNewTab: true },
2409
+ * plugins
2410
+ * );
2411
+ * const result = parser.parse(markdown);
2412
+ * ```
2413
+ */ export var parserMarkdownToSlateNode = function(md, plugins, config) {
2414
+ var parser = new MarkdownToSlateParser(config || {}, plugins || []);
2415
+ return parser.parse(md);
1875
2416
  };