@ant-design/agentic-ui 2.30.5 → 2.30.7

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.
@@ -1,1270 +1,9 @@
1
- function _array_like_to_array(arr, len) {
2
- if (len == null || len > arr.length) len = arr.length;
3
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
- return arr2;
5
- }
6
- function _array_with_holes(arr) {
7
- if (Array.isArray(arr)) return arr;
8
- }
9
- function _array_without_holes(arr) {
10
- if (Array.isArray(arr)) return _array_like_to_array(arr);
11
- }
12
- function _define_property(obj, key, value) {
13
- if (key in obj) {
14
- Object.defineProperty(obj, key, {
15
- value: value,
16
- enumerable: true,
17
- configurable: true,
18
- writable: true
19
- });
20
- } else {
21
- obj[key] = value;
22
- }
23
- return obj;
24
- }
25
- function _iterable_to_array(iter) {
26
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
27
- }
28
- function _non_iterable_rest() {
29
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
30
- }
31
- function _non_iterable_spread() {
32
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
33
- }
34
- function _object_spread(target) {
35
- for(var i = 1; i < arguments.length; i++){
36
- var source = arguments[i] != null ? arguments[i] : {};
37
- var ownKeys = Object.keys(source);
38
- if (typeof Object.getOwnPropertySymbols === "function") {
39
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
40
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
41
- }));
42
- }
43
- ownKeys.forEach(function(key) {
44
- _define_property(target, key, source[key]);
45
- });
46
- }
47
- return target;
48
- }
49
- function ownKeys(object, enumerableOnly) {
50
- var keys = Object.keys(object);
51
- if (Object.getOwnPropertySymbols) {
52
- var symbols = Object.getOwnPropertySymbols(object);
53
- if (enumerableOnly) {
54
- symbols = symbols.filter(function(sym) {
55
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
56
- });
57
- }
58
- keys.push.apply(keys, symbols);
59
- }
60
- return keys;
61
- }
62
- function _object_spread_props(target, source) {
63
- source = source != null ? source : {};
64
- if (Object.getOwnPropertyDescriptors) {
65
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
66
- } else {
67
- ownKeys(Object(source)).forEach(function(key) {
68
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
69
- });
70
- }
71
- return target;
72
- }
73
- function _object_without_properties(source, excluded) {
74
- if (source == null) return {};
75
- var target = {}, sourceKeys, key, i;
76
- if (typeof Reflect !== "undefined" && Reflect.ownKeys) {
77
- sourceKeys = Reflect.ownKeys(source);
78
- for(i = 0; i < sourceKeys.length; i++){
79
- key = sourceKeys[i];
80
- if (excluded.indexOf(key) >= 0) continue;
81
- if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
82
- target[key] = source[key];
83
- }
84
- return target;
85
- }
86
- target = _object_without_properties_loose(source, excluded);
87
- if (Object.getOwnPropertySymbols) {
88
- sourceKeys = Object.getOwnPropertySymbols(source);
89
- for(i = 0; i < sourceKeys.length; i++){
90
- key = sourceKeys[i];
91
- if (excluded.indexOf(key) >= 0) continue;
92
- if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
93
- target[key] = source[key];
94
- }
95
- }
96
- return target;
97
- }
98
- function _object_without_properties_loose(source, excluded) {
99
- if (source == null) return {};
100
- var target = {}, sourceKeys = Object.getOwnPropertyNames(source), key, i;
101
- for(i = 0; i < sourceKeys.length; i++){
102
- key = sourceKeys[i];
103
- if (excluded.indexOf(key) >= 0) continue;
104
- if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
105
- target[key] = source[key];
106
- }
107
- return target;
108
- }
109
- function _to_array(arr) {
110
- return _array_with_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_rest();
111
- }
112
- function _to_consumable_array(arr) {
113
- return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
114
- }
115
- function _unsupported_iterable_to_array(o, minLen) {
116
- if (!o) return;
117
- if (typeof o === "string") return _array_like_to_array(o, minLen);
118
- var n = Object.prototype.toString.call(o).slice(8, -1);
119
- if (n === "Object" && o.constructor) n = o.constructor.name;
120
- if (n === "Map" || n === "Set") return Array.from(n);
121
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
122
- }
123
- import { Checkbox, Image } from "antd";
124
1
  import { toJsxRuntime } from "hast-util-to-jsx-runtime";
125
- import React, { useMemo, useRef } from "react";
126
2
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
127
- import rehypeKatex from "rehype-katex";
128
- import rehypeRaw from "rehype-raw";
129
- import remarkDirective from "remark-directive";
130
- import remarkFrontmatter from "remark-frontmatter";
131
- import remarkGfm from "remark-gfm";
132
- import remarkMath from "remark-math";
133
- import remarkParse from "remark-parse";
134
- import remarkRehype from "remark-rehype";
135
- import { unified } from "unified";
136
- import { visit } from "unist-util-visit";
137
3
  import { JINJA_DOLLAR_PLACEHOLDER } from "../MarkdownEditor/editor/parser/constants";
138
- import { remarkDirectiveContainer } from "../MarkdownEditor/editor/parser/remarkDirectiveContainer";
139
- import { convertParagraphToImage, fixStrongWithSpecialChars, protectJinjaDollarInText } from "../MarkdownEditor/editor/parser/remarkParse";
140
- import { REMARK_REHYPE_DIRECTIVE_HANDLERS } from "../MarkdownEditor/editor/utils/markdownToHtml";
141
- import { parseChineseCurrencyToNumber } from "../Plugins/chart/utils";
142
- import { ToolUseBarThink } from "../ToolUseBarThink";
143
- import AnimationText from "./AnimationText";
144
- var INLINE_MATH_WITH_SINGLE_DOLLAR = {
145
- singleDollarTextMath: true
146
- };
147
- var FRONTMATTER_LANGUAGES = [
148
- 'yaml'
149
- ];
150
- var REMARK_DIRECTIVE_CONTAINER_OPTIONS = {
151
- className: 'markdown-container',
152
- titleElement: {
153
- className: [
154
- 'markdown-container__title'
155
- ]
156
- }
157
- };
158
- var remarkRehypePlugin = remarkRehype;
159
- var FOOTNOTE_REF_PATTERN = /\[\^([^\]]+)\]/g;
160
- var CHART_COMMENT_PATTERN = /^<!--\s*(\[[\s\S]*\]|\{[\s\S]*\})\s*-->$/;
161
- var extractCellText = function extractCellText1(cell) {
162
- if (!(cell === null || cell === void 0 ? void 0 : cell.children)) return '';
163
- return cell.children.map(function(child) {
164
- if (child.type === 'text') return child.value || '';
165
- if (child.children) return extractCellText(child);
166
- return '';
167
- }).join('').trim();
168
- };
169
- /**
170
- * 从 mdast table 节点提取列名和数据
171
- */ var extractTableData = function extractTableData(tableNode) {
172
- var _loop = function(i) {
173
- var row = tableNode.children[i];
174
- if (!(row === null || row === void 0 ? void 0 : row.children)) return "continue";
175
- var record = {
176
- key: "row-".concat(i)
177
- };
178
- row.children.forEach(function(cell, j) {
179
- if (j < columns.length) {
180
- var val = extractCellText(cell);
181
- if (val === '') {
182
- record[columns[j].dataIndex] = val;
183
- } else {
184
- var num = Number(val);
185
- if (Number.isFinite(num)) {
186
- record[columns[j].dataIndex] = num;
187
- } else {
188
- var cn = parseChineseCurrencyToNumber(val);
189
- record[columns[j].dataIndex] = cn !== null ? cn : val;
190
- }
191
- }
192
- }
193
- });
194
- dataSource.push(record);
195
- };
196
- var _tableNode_children, _headerRow_children;
197
- if (!((_tableNode_children = tableNode.children) === null || _tableNode_children === void 0 ? void 0 : _tableNode_children.length)) return null;
198
- var headerRow = tableNode.children[0];
199
- if (!(headerRow === null || headerRow === void 0 ? void 0 : (_headerRow_children = headerRow.children) === null || _headerRow_children === void 0 ? void 0 : _headerRow_children.length)) return null;
200
- var columns = headerRow.children.map(function(cell) {
201
- var text = extractCellText(cell);
202
- return {
203
- title: text,
204
- dataIndex: text,
205
- key: text
206
- };
207
- });
208
- var dataSource = [];
209
- for(var i = 1; i < tableNode.children.length; i++)_loop(i);
210
- return {
211
- columns: columns,
212
- dataSource: dataSource
213
- };
214
- };
215
- /**
216
- * remark 插件:将 "HTML 注释(图表配置)+ 表格" 组合转为 chart 代码块。
217
- *
218
- * 在 MarkdownEditor 中,parseTableOrChart 负责此逻辑。
219
- * 在 MarkdownRenderer 中,此插件在 mdast 层面完成等价转换。
220
- *
221
- * 匹配模式:
222
- * ```
223
- * <!-- [{"chartType":"line","x":"month","y":"value",...}] -->
224
- * | month | value |
225
- * |-------|-------|
226
- * | 2024 | 100 |
227
- * ```
228
- */ var remarkChartFromComment = function remarkChartFromComment() {
229
- return function(tree) {
230
- var children = tree.children;
231
- if (!children || !Array.isArray(children)) return;
232
- var toRemove = [];
233
- for(var i = 0; i < children.length - 1; i++){
234
- var _node_value;
235
- var node = children[i];
236
- var next = children[i + 1];
237
- if (node.type !== 'html' || next.type !== 'table') continue;
238
- var match = (_node_value = node.value) === null || _node_value === void 0 ? void 0 : _node_value.match(CHART_COMMENT_PATTERN);
239
- if (!match) continue;
240
- var chartConfig = void 0;
241
- try {
242
- chartConfig = JSON.parse(match[1]);
243
- } catch (unused) {
244
- continue;
245
- }
246
- if (!Array.isArray(chartConfig)) chartConfig = [
247
- chartConfig
248
- ];
249
- var hasChartType = chartConfig.some(function(c) {
250
- return c.chartType && c.chartType !== 'table';
251
- });
252
- if (!hasChartType) continue;
253
- var tableData = extractTableData(next);
254
- if (!tableData) continue;
255
- var chartJson = JSON.stringify({
256
- config: chartConfig,
257
- columns: tableData.columns,
258
- dataSource: tableData.dataSource
259
- });
260
- children[i] = {
261
- type: 'code',
262
- lang: 'chart',
263
- value: chartJson
264
- };
265
- toRemove.push(i + 1);
266
- i++;
267
- }
268
- for(var j = toRemove.length - 1; j >= 0; j--){
269
- children.splice(toRemove[j], 1);
270
- }
271
- };
272
- };
273
- /**
274
- * rehype 插件:将文本中残留的 [^N] 模式转为 fnc 标记元素。
275
- *
276
- * remark-gfm 只在有对应 footnoteDefinition 时才会转换 footnoteReference,
277
- * 但 AI 对话场景中 [^1] 常用作内联引用(无底部定义)。
278
- * 此插件在 hast 层面补充处理这些"裸引用"。
279
- */ var rehypeFootnoteRef = function rehypeFootnoteRef() {
280
- return function(tree) {
281
- visit(tree, 'text', function(node, index, parent) {
282
- if (!parent || index === undefined) return;
283
- var value = node.value;
284
- if (!FOOTNOTE_REF_PATTERN.test(value)) return;
285
- FOOTNOTE_REF_PATTERN.lastIndex = 0;
286
- var children = [];
287
- var lastIndex = 0;
288
- var match;
289
- while((match = FOOTNOTE_REF_PATTERN.exec(value)) !== null){
290
- if (match.index > lastIndex) {
291
- children.push({
292
- type: 'text',
293
- value: value.slice(lastIndex, match.index)
294
- });
295
- }
296
- children.push({
297
- type: 'element',
298
- tagName: 'span',
299
- properties: {
300
- 'data-fnc': 'fnc',
301
- 'data-fnc-name': match[1]
302
- },
303
- children: [
304
- {
305
- type: 'text',
306
- value: match[1]
307
- }
308
- ]
309
- });
310
- lastIndex = match.index + match[0].length;
311
- }
312
- if (lastIndex < value.length) {
313
- children.push({
314
- type: 'text',
315
- value: value.slice(lastIndex)
316
- });
317
- }
318
- if (children.length > 0) {
319
- var _parent_children;
320
- (_parent_children = parent.children).splice.apply(_parent_children, [
321
- index,
322
- 1
323
- ].concat(_to_consumable_array(children)));
324
- return index + children.length;
325
- }
326
- });
327
- };
328
- };
329
- var createHastProcessor = function createHastProcessor(extraRemarkPlugins, config) {
330
- var processor = unified();
331
- processor.use(remarkParse).use(remarkGfm, {
332
- singleTilde: false
333
- }).use(fixStrongWithSpecialChars).use(convertParagraphToImage).use(protectJinjaDollarInText).use(remarkMath, INLINE_MATH_WITH_SINGLE_DOLLAR).use(remarkFrontmatter, FRONTMATTER_LANGUAGES).use(remarkDirective).use(remarkDirectiveContainer, REMARK_DIRECTIVE_CONTAINER_OPTIONS).use(remarkChartFromComment).use(remarkRehypePlugin, {
334
- allowDangerousHtml: true,
335
- handlers: REMARK_REHYPE_DIRECTIVE_HANDLERS
336
- }).use(rehypeRaw).use(rehypeKatex, {
337
- strict: 'ignore'
338
- }).use(rehypeFootnoteRef);
339
- if (extraRemarkPlugins) {
340
- extraRemarkPlugins.forEach(function(entry) {
341
- if (Array.isArray(entry)) {
342
- var _processor;
343
- var _entry = _to_array(entry), plugin = _entry[0], pluginOptions = _entry.slice(1);
344
- (_processor = processor).use.apply(_processor, [
345
- plugin
346
- ].concat(_to_consumable_array(pluginOptions)));
347
- } else {
348
- processor.use(entry);
349
- }
350
- });
351
- }
352
- if (config === null || config === void 0 ? void 0 : config.markedConfig) {
353
- config.markedConfig.forEach(function(entry) {
354
- if (Array.isArray(entry)) {
355
- var _processor;
356
- var _entry = _to_array(entry), plugin = _entry[0], pluginOptions = _entry.slice(1);
357
- (_processor = processor).use.apply(_processor, [
358
- plugin
359
- ].concat(_to_consumable_array(pluginOptions)));
360
- } else {
361
- processor.use(entry);
362
- }
363
- });
364
- }
365
- return processor;
366
- };
367
- var extractLanguageFromClassName = function extractLanguageFromClassName(className) {
368
- if (!className) return undefined;
369
- var flat = typeof className === 'string' ? className : className.map(String).join(' ');
370
- var classes = flat.split(/\s+/).filter(Boolean);
371
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
372
- try {
373
- for(var _iterator = classes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
374
- var cls = _step.value;
375
- var match = cls.match(/^language-(.+)$/);
376
- if (match) return match[1];
377
- }
378
- } catch (err) {
379
- _didIteratorError = true;
380
- _iteratorError = err;
381
- } finally{
382
- try {
383
- if (!_iteratorNormalCompletion && _iterator.return != null) {
384
- _iterator.return();
385
- }
386
- } finally{
387
- if (_didIteratorError) {
388
- throw _iteratorError;
389
- }
390
- }
391
- }
392
- return undefined;
393
- };
394
- /**
395
- * 提取 React children 的文本内容
396
- */ var extractChildrenText = function extractChildrenText1(children) {
397
- var _children_props;
398
- if (typeof children === 'string') return children;
399
- if (typeof children === 'number') return String(children);
400
- if (Array.isArray(children)) return children.map(extractChildrenText).join('');
401
- if (React.isValidElement(children) && ((_children_props = children.props) === null || _children_props === void 0 ? void 0 : _children_props.children)) {
402
- return extractChildrenText(children.props.children);
403
- }
404
- return '';
405
- };
406
- /**
407
- * <think> 标签渲染组件——使用 ToolUseBarThink 替代原生 DOM。
408
- * 在 MarkdownEditor 中,<think> 被预处理为 ```think 代码块,
409
- * 然后由 ThinkBlock 组件(依赖 Slate 上下文)渲染为 ToolUseBarThink。
410
- * 在 MarkdownRenderer 中,<think> 通过 rehypeRaw 保留为 hast 元素,
411
- * 这里直接渲染为 ToolUseBarThink,无需 Slate 上下文。
412
- */ var ThinkBlockRendererComponent = function ThinkBlockRendererComponent(props) {
413
- var children = props.children;
414
- var content = extractChildrenText(children);
415
- var isLoading = content.endsWith('...');
416
- return React.createElement(ToolUseBarThink, {
417
- testId: 'think-block-renderer',
418
- styles: {
419
- root: {
420
- boxSizing: 'border-box',
421
- maxWidth: '680px',
422
- marginTop: 8
423
- }
424
- },
425
- toolName: isLoading ? '深度思考...' : '深度思考',
426
- thinkContent: content,
427
- status: isLoading ? 'loading' : 'success'
428
- });
429
- };
430
- /**
431
- * 构建与 MarkdownEditor Readonly 组件对齐的 hast→React 组件映射。
432
- *
433
- * MarkdownEditor 的 Slate 元素使用 data-be 属性和 prefixCls 类名,
434
- * 这里为原生 HTML 标签添加相同的属性,使共用的 CSS 能正确命中。
435
- */ var buildEditorAlignedComponents = function buildEditorAlignedComponents(prefixCls, userComponents, streaming, linkConfig) {
436
- var listCls = "".concat(prefixCls, "-list");
437
- var tableCls = "".concat(prefixCls, "-content-table");
438
- var contentCls = prefixCls; // e.g. ant-agentic-md-editor-content
439
- var wrapAnimation = function wrapAnimation(children) {
440
- return streaming ? jsx(AnimationText, {
441
- children: children
442
- }) : children;
443
- };
444
- return _object_spread({
445
- // ================================================================
446
- // Block 级别元素
447
- // ================================================================
448
- p: function p(props) {
449
- var _node = props.node, children = props.children, rest = _object_without_properties(props, [
450
- "node",
451
- "children"
452
- ]);
453
- return jsx('div', _object_spread_props(_object_spread({}, rest), {
454
- 'data-be': 'paragraph',
455
- 'data-testid': 'markdown-paragraph',
456
- children: wrapAnimation(children)
457
- }));
458
- },
459
- h1: function h1(props) {
460
- var _node = props.node, children = props.children, rest = _object_without_properties(props, [
461
- "node",
462
- "children"
463
- ]);
464
- return jsx('h1', _object_spread_props(_object_spread({}, rest), {
465
- 'data-be': 'head',
466
- 'data-testid': 'markdown-heading-1',
467
- children: wrapAnimation(children)
468
- }));
469
- },
470
- h2: function h2(props) {
471
- var _node = props.node, children = props.children, rest = _object_without_properties(props, [
472
- "node",
473
- "children"
474
- ]);
475
- return jsx('h2', _object_spread_props(_object_spread({}, rest), {
476
- 'data-be': 'head',
477
- 'data-testid': 'markdown-heading-2',
478
- children: wrapAnimation(children)
479
- }));
480
- },
481
- h3: function h3(props) {
482
- var _node = props.node, children = props.children, rest = _object_without_properties(props, [
483
- "node",
484
- "children"
485
- ]);
486
- return jsx('h3', _object_spread_props(_object_spread({}, rest), {
487
- 'data-be': 'head',
488
- 'data-testid': 'markdown-heading-3',
489
- children: wrapAnimation(children)
490
- }));
491
- },
492
- h4: function h4(props) {
493
- var _node = props.node, children = props.children, rest = _object_without_properties(props, [
494
- "node",
495
- "children"
496
- ]);
497
- return jsx('h4', _object_spread_props(_object_spread({}, rest), {
498
- 'data-be': 'head',
499
- 'data-testid': 'markdown-heading-4',
500
- children: wrapAnimation(children)
501
- }));
502
- },
503
- h5: function h5(props) {
504
- var _node = props.node, children = props.children, rest = _object_without_properties(props, [
505
- "node",
506
- "children"
507
- ]);
508
- return jsx('h5', _object_spread_props(_object_spread({}, rest), {
509
- 'data-be': 'head',
510
- 'data-testid': 'markdown-heading-5',
511
- children: wrapAnimation(children)
512
- }));
513
- },
514
- h6: function h6(props) {
515
- var _node = props.node, children = props.children, rest = _object_without_properties(props, [
516
- "node",
517
- "children"
518
- ]);
519
- return jsx('h6', _object_spread_props(_object_spread({}, rest), {
520
- 'data-be': 'head',
521
- 'data-testid': 'markdown-heading-6',
522
- children: wrapAnimation(children)
523
- }));
524
- },
525
- blockquote: function blockquote(props) {
526
- var _node = props.node, children = props.children, rest = _object_without_properties(props, [
527
- "node",
528
- "children"
529
- ]);
530
- return jsx('blockquote', _object_spread_props(_object_spread({}, rest), {
531
- 'data-be': 'blockquote',
532
- 'data-testid': 'markdown-blockquote',
533
- children: children
534
- }));
535
- },
536
- ul: function ul(props) {
537
- var _node = props.node, children = props.children, rest = _object_without_properties(props, [
538
- "node",
539
- "children"
540
- ]);
541
- return jsx('div', {
542
- className: "".concat(listCls, "-container"),
543
- 'data-be': 'list',
544
- 'data-testid': 'markdown-unordered-list',
545
- children: jsx('ul', _object_spread_props(_object_spread({}, rest), {
546
- className: "".concat(listCls, " ul"),
547
- children: children
548
- }))
549
- });
550
- },
551
- ol: function ol(props) {
552
- var _node = props.node, children = props.children, start = props.start, rest = _object_without_properties(props, [
553
- "node",
554
- "children",
555
- "start"
556
- ]);
557
- return jsx('div', {
558
- className: "".concat(listCls, "-container"),
559
- 'data-be': 'list',
560
- 'data-testid': 'markdown-ordered-list',
561
- children: jsx('ol', _object_spread_props(_object_spread({}, rest), {
562
- className: "".concat(listCls, " ol"),
563
- start: start,
564
- children: children
565
- }))
566
- });
567
- },
568
- li: function li(props) {
569
- var _node = props.node, children = props.children, className = props.className, rest = _object_without_properties(props, [
570
- "node",
571
- "children",
572
- "className"
573
- ]);
574
- var isTask = className === 'task-list-item' || Array.isArray(className) && className.includes('task-list-item');
575
- if (isTask) {
576
- var childArray = Array.isArray(children) ? children : [
577
- children
578
- ];
579
- var checked = false;
580
- var filteredChildren = childArray.filter(function(child) {
581
- var _child_props;
582
- if (React.isValidElement(child) && ((_child_props = child.props) === null || _child_props === void 0 ? void 0 : _child_props.type) === 'checkbox') {
583
- var _child_props1;
584
- checked = !!((_child_props1 = child.props) === null || _child_props1 === void 0 ? void 0 : _child_props1.checked);
585
- return false;
586
- }
587
- return true;
588
- });
589
- return jsxs('li', _object_spread_props(_object_spread({}, rest), {
590
- className: "".concat(listCls, "-item ").concat(listCls, "-task"),
591
- 'data-be': 'list-item',
592
- 'data-testid': 'markdown-task-item',
593
- children: [
594
- jsx('span', {
595
- className: "".concat(listCls, "-check-item"),
596
- contentEditable: false,
597
- 'data-check-item': true,
598
- children: jsx(Checkbox, {
599
- checked: checked,
600
- disabled: true
601
- })
602
- })
603
- ].concat(_to_consumable_array(filteredChildren))
604
- }));
605
- }
606
- return jsx('li', _object_spread_props(_object_spread({}, rest), {
607
- className: "".concat(listCls, "-item"),
608
- 'data-be': 'list-item',
609
- 'data-testid': 'markdown-list-item',
610
- children: wrapAnimation(children)
611
- }));
612
- },
613
- table: function table(props) {
614
- var _node = props.node, children = props.children, rest = _object_without_properties(props, [
615
- "node",
616
- "children"
617
- ]);
618
- return jsx('div', {
619
- className: tableCls,
620
- 'data-testid': 'markdown-table',
621
- children: jsx('div', {
622
- className: "".concat(tableCls, "-container"),
623
- children: jsx('table', _object_spread_props(_object_spread({}, rest), {
624
- className: "".concat(tableCls, "-readonly-table"),
625
- style: {
626
- tableLayout: 'auto',
627
- width: '100%'
628
- },
629
- children: children
630
- }))
631
- })
632
- });
633
- },
634
- thead: function thead(props) {
635
- var _node = props.node, children = props.children, rest = _object_without_properties(props, [
636
- "node",
637
- "children"
638
- ]);
639
- return jsx('thead', _object_spread_props(_object_spread({}, rest), {
640
- 'data-testid': 'markdown-thead',
641
- children: children
642
- }));
643
- },
644
- tbody: function tbody(props) {
645
- var _node = props.node, children = props.children, rest = _object_without_properties(props, [
646
- "node",
647
- "children"
648
- ]);
649
- return jsx('tbody', _object_spread_props(_object_spread({}, rest), {
650
- 'data-testid': 'markdown-tbody',
651
- children: children
652
- }));
653
- },
654
- tr: function tr(props) {
655
- var _node = props.node, children = props.children, rest = _object_without_properties(props, [
656
- "node",
657
- "children"
658
- ]);
659
- return jsx('tr', _object_spread_props(_object_spread({}, rest), {
660
- 'data-testid': 'markdown-tr',
661
- children: children
662
- }));
663
- },
664
- th: function th(props) {
665
- var _node = props.node, children = props.children, rest = _object_without_properties(props, [
666
- "node",
667
- "children"
668
- ]);
669
- return jsx('th', _object_spread_props(_object_spread({}, rest), {
670
- 'data-testid': 'markdown-th',
671
- style: {
672
- whiteSpace: 'normal',
673
- maxWidth: '20%'
674
- },
675
- children: children
676
- }));
677
- },
678
- td: function td(props) {
679
- var _node = props.node, children = props.children, rest = _object_without_properties(props, [
680
- "node",
681
- "children"
682
- ]);
683
- return jsx('td', _object_spread_props(_object_spread({}, rest), {
684
- 'data-testid': 'markdown-td',
685
- style: {
686
- whiteSpace: 'normal',
687
- maxWidth: '20%'
688
- },
689
- children: wrapAnimation(children)
690
- }));
691
- },
692
- // input[type=checkbox]:task list 的 checkbox(兜底,主逻辑在 li 中)
693
- input: function input(props) {
694
- var _node = props.node, type = props.type, checked = props.checked, disabled = props.disabled, rest = _object_without_properties(props, [
695
- "node",
696
- "type",
697
- "checked",
698
- "disabled"
699
- ]);
700
- if (type === 'checkbox') {
701
- return jsx(Checkbox, {
702
- checked: !!checked,
703
- disabled: true,
704
- 'data-testid': 'markdown-checkbox'
705
- });
706
- }
707
- return jsx('input', _object_spread_props(_object_spread({}, rest), {
708
- type: type,
709
- checked: checked,
710
- disabled: disabled
711
- }));
712
- },
713
- // ================================================================
714
- // Leaf 级别(行内元素)
715
- // ================================================================
716
- a: function a(props) {
717
- var _node = props.node, href = props.href, _origOnClick = props.onClick, rest = _object_without_properties(props, [
718
- "node",
719
- "href",
720
- "onClick"
721
- ]);
722
- var openInNewTab = (linkConfig === null || linkConfig === void 0 ? void 0 : linkConfig.openInNewTab) !== false;
723
- return jsx('a', _object_spread_props(_object_spread({}, rest), {
724
- href: href,
725
- 'data-be': 'text',
726
- 'data-url': 'url',
727
- 'data-testid': 'markdown-link',
728
- target: openInNewTab ? '_blank' : undefined,
729
- rel: openInNewTab ? 'noopener noreferrer' : undefined,
730
- onClick: function onClick(e) {
731
- if (linkConfig === null || linkConfig === void 0 ? void 0 : linkConfig.onClick) {
732
- var res = linkConfig.onClick(href);
733
- if (res === false) {
734
- e.preventDefault();
735
- return;
736
- }
737
- }
738
- }
739
- }));
740
- },
741
- strong: function strong(props) {
742
- var _node = props.node, children = props.children, rest = _object_without_properties(props, [
743
- "node",
744
- "children"
745
- ]);
746
- return jsx('strong', _object_spread_props(_object_spread({}, rest), {
747
- 'data-testid': 'markdown-bold',
748
- style: {
749
- fontWeight: 'bold'
750
- },
751
- children: children
752
- }));
753
- },
754
- em: function em(props) {
755
- var _node = props.node, children = props.children, rest = _object_without_properties(props, [
756
- "node",
757
- "children"
758
- ]);
759
- return jsx('em', _object_spread_props(_object_spread({}, rest), {
760
- 'data-testid': 'markdown-italic',
761
- style: {
762
- fontStyle: 'italic'
763
- },
764
- children: children
765
- }));
766
- },
767
- del: function del(props) {
768
- var _node = props.node, children = props.children, rest = _object_without_properties(props, [
769
- "node",
770
- "children"
771
- ]);
772
- return jsx('del', _object_spread_props(_object_spread({}, rest), {
773
- 'data-testid': 'markdown-strikethrough',
774
- children: children
775
- }));
776
- },
777
- code: function code(props) {
778
- var _node = props.node, children = props.children, className = props.className, rest = _object_without_properties(props, [
779
- "node",
780
- "children",
781
- "className"
782
- ]);
783
- var fenceLang = extractLanguageFromClassName(className);
784
- return jsx('code', _object_spread_props(_object_spread({}, rest), {
785
- 'data-testid': fenceLang ? 'markdown-fenced-code' : 'markdown-inline-code',
786
- className: fenceLang ? className : "".concat(contentCls, "-inline-code"),
787
- children: children
788
- }));
789
- },
790
- mark: function mark(props) {
791
- var _node = props.node, children = props.children, rest = _object_without_properties(props, [
792
- "node",
793
- "children"
794
- ]);
795
- return jsx('mark', _object_spread_props(_object_spread({}, rest), {
796
- 'data-testid': 'markdown-mark',
797
- style: {
798
- background: '#f59e0b',
799
- padding: '0.1em 0.2em',
800
- borderRadius: 2
801
- },
802
- children: children
803
- }));
804
- },
805
- kbd: function kbd(props) {
806
- var _node = props.node, children = props.children, rest = _object_without_properties(props, [
807
- "node",
808
- "children"
809
- ]);
810
- return jsx('kbd', _object_spread_props(_object_spread({}, rest), {
811
- 'data-testid': 'markdown-kbd',
812
- style: {
813
- padding: '0.1em 0.4em',
814
- fontSize: '0.85em',
815
- border: '1px solid var(--color-gray-border-light, #d9d9d9)',
816
- borderRadius: 3,
817
- boxShadow: '0 1px 0 var(--color-gray-border-light, #d9d9d9)',
818
- fontFamily: 'Consolas, Monaco, "Courier New", monospace'
819
- },
820
- children: children
821
- }));
822
- },
823
- sub: function sub(props) {
824
- var _node = props.node, children = props.children, rest = _object_without_properties(props, [
825
- "node",
826
- "children"
827
- ]);
828
- return jsx('sub', _object_spread_props(_object_spread({}, rest), {
829
- 'data-testid': 'markdown-sub',
830
- children: children
831
- }));
832
- },
833
- // ================================================================
834
- // 代码块 pre > code → 路由到自定义渲染器
835
- pre: function pre(props) {
836
- var _hastPreNode_children_, _hastPreNode_children, _hastPreNode_children__properties;
837
- var hastPreNode = props.node, children = props.children, rest = _object_without_properties(props, [
838
- "node",
839
- "children"
840
- ]);
841
- var codeChild = Array.isArray(children) ? children[0] : children;
842
- var codeProps = (codeChild === null || codeChild === void 0 ? void 0 : codeChild.props) || {};
843
- var codeHastClass = (hastPreNode === null || hastPreNode === void 0 ? void 0 : (_hastPreNode_children = hastPreNode.children) === null || _hastPreNode_children === void 0 ? void 0 : (_hastPreNode_children_ = _hastPreNode_children[0]) === null || _hastPreNode_children_ === void 0 ? void 0 : _hastPreNode_children_.type) === 'element' && hastPreNode.children[0].tagName === 'code' ? (_hastPreNode_children__properties = hastPreNode.children[0].properties) === null || _hastPreNode_children__properties === void 0 ? void 0 : _hastPreNode_children__properties.className : undefined;
844
- var language = extractLanguageFromClassName(codeProps.className);
845
- if (!language) {
846
- language = extractLanguageFromClassName(codeHastClass);
847
- }
848
- var CodeBlockComponent = userComponents.__codeBlock || userComponents.code;
849
- if (CodeBlockComponent) {
850
- return jsx(CodeBlockComponent, _object_spread_props(_object_spread({}, rest), {
851
- language: language,
852
- children: codeProps.children,
853
- node: hastPreNode
854
- }));
855
- }
856
- return jsxs('pre', _object_spread_props(_object_spread({}, rest), {
857
- children: [
858
- children
859
- ]
860
- }));
861
- },
862
- img: function img(props) {
863
- var _node = props.node, src = props.src, alt = props.alt, width = props.width, height = props.height, _rest = _object_without_properties(props, [
864
- "node",
865
- "src",
866
- "alt",
867
- "width",
868
- "height"
869
- ]);
870
- var imgWidth = width ? Number(width) || width : 400;
871
- return jsx('div', {
872
- 'data-be': 'image',
873
- 'data-testid': 'markdown-image',
874
- style: {
875
- position: 'relative',
876
- userSelect: 'none',
877
- width: '100%',
878
- maxWidth: '100%',
879
- boxSizing: 'border-box'
880
- },
881
- children: jsx('div', {
882
- style: {
883
- padding: 4,
884
- userSelect: 'none',
885
- display: 'flex',
886
- flexDirection: 'column',
887
- width: '100%',
888
- maxWidth: '100%',
889
- boxSizing: 'border-box'
890
- },
891
- 'data-testid': 'image-container',
892
- 'data-be': 'image-container',
893
- children: jsx(Image, {
894
- src: src,
895
- alt: alt || 'image',
896
- width: imgWidth,
897
- height: height,
898
- preview: {
899
- getContainer: function getContainer() {
900
- return document.body;
901
- }
902
- },
903
- referrerPolicy: 'no-referrer',
904
- draggable: false,
905
- style: {
906
- maxWidth: '100%',
907
- height: 'auto',
908
- display: 'block'
909
- }
910
- })
911
- })
912
- });
913
- },
914
- // 视频:对齐 ReadonlyMedia 的 video 处理
915
- video: function video(props) {
916
- var _node = props.node, children = props.children, rest = _object_without_properties(props, [
917
- "node",
918
- "children"
919
- ]);
920
- return jsx('div', {
921
- 'data-be': 'media',
922
- 'data-testid': 'markdown-video',
923
- style: {
924
- position: 'relative',
925
- width: '100%',
926
- maxWidth: '100%',
927
- margin: '0.5em 0'
928
- },
929
- children: jsx('video', _object_spread_props(_object_spread({}, rest), {
930
- controls: true,
931
- style: {
932
- maxWidth: '100%',
933
- borderRadius: 8
934
- },
935
- children: children
936
- }))
937
- });
938
- },
939
- // 音频:对齐 ReadonlyMedia 的 audio 处理
940
- audio: function audio(props) {
941
- var _node = props.node, children = props.children, rest = _object_without_properties(props, [
942
- "node",
943
- "children"
944
- ]);
945
- return jsx('div', {
946
- 'data-be': 'media',
947
- 'data-testid': 'markdown-audio',
948
- style: {
949
- position: 'relative',
950
- width: '100%',
951
- margin: '0.5em 0'
952
- },
953
- children: jsx('audio', _object_spread_props(_object_spread({}, rest), {
954
- controls: true,
955
- style: {
956
- width: '100%'
957
- },
958
- children: children
959
- }))
960
- });
961
- },
962
- // iframe
963
- iframe: function iframe(props) {
964
- var _node = props.node, rest = _object_without_properties(props, [
965
- "node"
966
- ]);
967
- return jsx('div', {
968
- 'data-testid': 'markdown-iframe',
969
- style: {
970
- position: 'relative',
971
- width: '100%',
972
- margin: '0.5em 0'
973
- },
974
- children: jsx('iframe', _object_spread_props(_object_spread({}, rest), {
975
- style: {
976
- width: '100%',
977
- minHeight: 300,
978
- border: '1px solid var(--color-gray-border-light, #e8e8e8)',
979
- borderRadius: 8
980
- }
981
- }))
982
- });
983
- },
984
- hr: function hr(props) {
985
- var _node = props.node, rest = _object_without_properties(props, [
986
- "node"
987
- ]);
988
- return jsx('hr', _object_spread_props(_object_spread({}, rest), {
989
- 'data-be': 'hr',
990
- 'data-testid': 'markdown-hr'
991
- }));
992
- },
993
- // 脚注引用 sup > a(remark-gfm 有定义时生成)
994
- sup: function sup(props) {
995
- var _node = props.node, children = props.children, rest = _object_without_properties(props, [
996
- "node",
997
- "children"
998
- ]);
999
- return jsx('span', _object_spread_props(_object_spread({}, rest), {
1000
- 'data-fnc': 'fnc',
1001
- 'data-testid': 'markdown-footnote-ref',
1002
- className: "".concat(contentCls, "-fnc"),
1003
- style: {
1004
- fontSize: 12,
1005
- cursor: 'pointer'
1006
- },
1007
- children: children
1008
- }));
1009
- },
1010
- span: function span(props) {
1011
- var _node = props.node, children = props.children, rest = _object_without_properties(props, [
1012
- "node",
1013
- "children"
1014
- ]);
1015
- if (rest['data-fnc'] === 'fnc') {
1016
- return jsx('span', _object_spread_props(_object_spread({}, rest), {
1017
- 'data-testid': 'markdown-footnote-ref',
1018
- className: "".concat(contentCls, "-fnc"),
1019
- style: {
1020
- fontSize: 12,
1021
- cursor: 'pointer'
1022
- },
1023
- children: children
1024
- }));
1025
- }
1026
- return jsx('span', _object_spread_props(_object_spread({}, rest), {
1027
- children: children
1028
- }));
1029
- },
1030
- section: function section(props) {
1031
- var _node = props.node, children = props.children, className = props.className, rest = _object_without_properties(props, [
1032
- "node",
1033
- "children",
1034
- "className"
1035
- ]);
1036
- var isFootnotes = className === 'footnotes' || typeof (rest === null || rest === void 0 ? void 0 : rest['data-footnotes']) !== 'undefined';
1037
- if (isFootnotes) {
1038
- return jsx('div', _object_spread_props(_object_spread({}, rest), {
1039
- 'data-be': 'footnoteDefinition',
1040
- 'data-testid': 'markdown-footnote-section',
1041
- style: {
1042
- fontSize: 12,
1043
- borderTop: '1px solid var(--color-gray-border-light, #e8e8e8)',
1044
- marginTop: 16,
1045
- paddingTop: 8
1046
- },
1047
- children: children
1048
- }));
1049
- }
1050
- return jsx('section', _object_spread_props(_object_spread({}, rest), {
1051
- className: className,
1052
- children: children
1053
- }));
1054
- },
1055
- think: ThinkBlockRendererComponent,
1056
- answer: function answer(props) {
1057
- var _node = props.node, children = props.children;
1058
- return jsx(Fragment, {
1059
- children: children
1060
- });
1061
- }
1062
- }, userComponents);
1063
- };
1064
- /**
1065
- * 将单个 markdown 片段转为 React 元素(内部函数)
1066
- */ var renderMarkdownBlock = function renderMarkdownBlock(blockContent, processor, components) {
1067
- if (!blockContent.trim()) return null;
1068
- try {
1069
- var mdast = processor.parse(blockContent);
1070
- var hast = processor.runSync(mdast);
1071
- return toJsxRuntime(hast, {
1072
- Fragment: Fragment,
1073
- jsx: jsx,
1074
- jsxs: jsxs,
1075
- components: components,
1076
- passNode: true
1077
- });
1078
- } catch (unused) {
1079
- return null;
1080
- }
1081
- };
1082
- /** 流式未闭合围栏内,空行后的下一行是否仍像围栏内代码(JSON 等)延续 */ var lineLooksLikeFenceCodeContinuation = function lineLooksLikeFenceCodeContinuation(rawLine) {
1083
- var t = rawLine.trimStart();
1084
- if (!t) {
1085
- return true;
1086
- }
1087
- if (t.startsWith('```') || t.startsWith('~~~')) {
1088
- return true;
1089
- }
1090
- var c = t[0];
1091
- return c === '{' || c === '}' || c === '[' || c === ']' || c === '"' || c === "'" || c === '`' || c === '-' || c === ',' || c >= '0' && c <= '9';
1092
- };
1093
- /**
1094
- * 将 markdown 按块(双换行)拆分,尊重代码围栏边界。
1095
- * 返回的每个块是一个独立的 markdown 片段,可单独解析。
1096
- *
1097
- * 流式且围栏未闭合时,inFence 会一直为 true,段间 `\n\n` 在按行拆分时只出现一个空行,
1098
- * 无法用「连续两个空行」检测。此时在空行处前瞻下一行:若不像围栏内代码延续则虚拟闭合围栏,
1099
- * 使末块能变为非末块且缓存键与先前一致。
1100
- */ var splitMarkdownBlocks = function splitMarkdownBlocks(content, streaming) {
1101
- var lines = content.split('\n');
1102
- var blocks = [];
1103
- var current = [];
1104
- var inFence = false;
1105
- for(var i = 0; i < lines.length; i += 1){
1106
- var line = lines[i];
1107
- var trimmed = line.trimStart();
1108
- if (trimmed.startsWith('```') || trimmed.startsWith('~~~')) {
1109
- inFence = !inFence;
1110
- }
1111
- if (streaming && inFence && line === '' && current.length > 0) {
1112
- var prev = current[current.length - 1];
1113
- var nextLine = lines[i + 1];
1114
- var doubleBlankInsideFence = prev === '';
1115
- var blankThenNonCodeLine = prev !== '' && nextLine !== undefined && nextLine.trim() !== '' && !lineLooksLikeFenceCodeContinuation(nextLine);
1116
- if (doubleBlankInsideFence || blankThenNonCodeLine) {
1117
- var body = current;
1118
- while(body.length > 0 && body[body.length - 1] === ''){
1119
- body = body.slice(0, -1);
1120
- }
1121
- if (body.length > 0) {
1122
- blocks.push(body.join('\n'));
1123
- }
1124
- current = [];
1125
- inFence = false;
1126
- continue;
1127
- }
1128
- }
1129
- if (!inFence && line === '' && current.length > 0) {
1130
- var prev1 = current[current.length - 1];
1131
- if (prev1 === '') {
1132
- blocks.push(current.join('\n'));
1133
- current = [];
1134
- continue;
1135
- }
1136
- }
1137
- current.push(line);
1138
- }
1139
- if (current.length > 0) {
1140
- blocks.push(current.join('\n'));
1141
- }
1142
- return blocks;
1143
- };
1144
- var _BLOCK_CACHE_KEY = Symbol('blockCache');
1145
- /**
1146
- * 将 markdown 字符串转换为 React 元素树的 hook。
1147
- *
1148
- * 性能优化:分块缓存
1149
- * - markdown 按双换行拆分为独立块
1150
- * - 已完成的块(非最后一个)通过内容哈希缓存 React 输出
1151
- * - 每次更新只重新解析变化的块(通常仅最后一个)
1152
- * - 稳定块的 React 元素直接复用,跳过 parse → hast → jsx 全链路
1153
- */ /**
1154
- * 流式场景下,最后一个块每个字符都变化,但大部分变化只是尾部追加。
1155
- * 对最后一个块做节流:只在新增了换行、块级标记、或超过一定字符数时才重新解析。
1156
- */ var LAST_BLOCK_THROTTLE_CHARS = 20;
1157
- var BLOCK_BOUNDARY_TRIGGERS = /[\n`|#>*\-!$[\]]/;
1158
- var shouldReparseLastBlock = function shouldReparseLastBlock(prevSource, newSource, streaming) {
1159
- if (!streaming) return true;
1160
- if (!prevSource) return true;
1161
- if (newSource.length < prevSource.length) return true;
1162
- if (!newSource.startsWith(prevSource)) return true;
1163
- var added = newSource.slice(prevSource.length);
1164
- if (added.length >= LAST_BLOCK_THROTTLE_CHARS) return true;
1165
- if (BLOCK_BOUNDARY_TRIGGERS.test(added)) return true;
1166
- return false;
1167
- };
1168
- export var useMarkdownToReact = function useMarkdownToReact(content, options) {
1169
- var processorRef = useRef(null);
1170
- var blockCacheRef = useRef(new Map());
1171
- var lastBlockRef = useRef(null);
1172
- var prevContentRef = useRef('');
1173
- var processor = useMemo(function() {
1174
- var p = createHastProcessor(options === null || options === void 0 ? void 0 : options.remarkPlugins, options === null || options === void 0 ? void 0 : options.htmlConfig);
1175
- processorRef.current = p;
1176
- return p;
1177
- }, [
1178
- options === null || options === void 0 ? void 0 : options.remarkPlugins,
1179
- options === null || options === void 0 ? void 0 : options.htmlConfig
1180
- ]);
1181
- var prefixCls = (options === null || options === void 0 ? void 0 : options.prefixCls) || 'ant-agentic-md-editor';
1182
- var components = useMemo(function() {
1183
- var userComponents = (options === null || options === void 0 ? void 0 : options.components) || {};
1184
- return buildEditorAlignedComponents(prefixCls, userComponents, options === null || options === void 0 ? void 0 : options.streaming, options === null || options === void 0 ? void 0 : options.linkConfig);
1185
- }, [
1186
- prefixCls,
1187
- options === null || options === void 0 ? void 0 : options.components,
1188
- options === null || options === void 0 ? void 0 : options.streaming,
1189
- options === null || options === void 0 ? void 0 : options.linkConfig
1190
- ]);
1191
- return useMemo(function() {
1192
- if (!content) {
1193
- prevContentRef.current = '';
1194
- return null;
1195
- }
1196
- var prevContent = prevContentRef.current;
1197
- if (prevContent && content !== prevContent && !content.startsWith(prevContent)) {
1198
- blockCacheRef.current = new Map();
1199
- lastBlockRef.current = null;
1200
- }
1201
- prevContentRef.current = content;
1202
- try {
1203
- var preprocessed = content.replace(new RegExp(JINJA_DOLLAR_PLACEHOLDER, 'g'), '$');
1204
- var blocks = splitMarkdownBlocks(preprocessed, options === null || options === void 0 ? void 0 : options.streaming);
1205
- if (blocks.length === 0) return null;
1206
- var cache = blockCacheRef.current;
1207
- var newCache = new Map();
1208
- var elements = [];
1209
- var KEY_PREFIX_LEN = 64;
1210
- for(var i = 0; i < blocks.length; i++){
1211
- var block = blocks[i];
1212
- var isLast = i === blocks.length - 1;
1213
- // 用 index + 内容前 64 字符作 key,保持稳定性:
1214
- // - 末块在流式中节流时,用 lastBlockRef.source 的切片作 key,避免每次追加字符导致 key 变化
1215
- // - 末块变为非末块时,必须与先前 key 一致,否则 ChartBlockRenderer 等会 unmount/remount 闪烁
1216
- // - 因此统一用「实际展示内容」的 slice 作 key,节流时用 lastBlockRef.source
1217
- var contentForKey = isLast && (options === null || options === void 0 ? void 0 : options.streaming) && lastBlockRef.current && !shouldReparseLastBlock(lastBlockRef.current.source, block, options === null || options === void 0 ? void 0 : options.streaming) ? lastBlockRef.current.source.slice(0, KEY_PREFIX_LEN) : block.slice(0, KEY_PREFIX_LEN);
1218
- var stableKey = "b".concat(i, "-").concat(contentForKey);
1219
- if (!isLast) {
1220
- var cached = cache.get(block);
1221
- if (cached && cached.source === block) {
1222
- newCache.set(block, cached);
1223
- elements.push(jsx(Fragment, {
1224
- children: cached.element
1225
- }, stableKey));
1226
- continue;
1227
- }
1228
- }
1229
- // 最后一个块:节流——仅在有意义的变化时重新解析
1230
- if (isLast && lastBlockRef.current) {
1231
- if (!shouldReparseLastBlock(lastBlockRef.current.source, block, options === null || options === void 0 ? void 0 : options.streaming)) {
1232
- newCache.set(block, {
1233
- source: lastBlockRef.current.source,
1234
- element: lastBlockRef.current.element
1235
- });
1236
- elements.push(jsx(Fragment, {
1237
- children: lastBlockRef.current.element
1238
- }, stableKey));
1239
- continue;
1240
- }
1241
- }
1242
- var element = renderMarkdownBlock(block, processor, components);
1243
- var entry = {
1244
- source: block,
1245
- element: element
1246
- };
1247
- newCache.set(block, entry);
1248
- if (isLast) lastBlockRef.current = entry;
1249
- elements.push(jsx(Fragment, {
1250
- children: element
1251
- }, stableKey));
1252
- }
1253
- blockCacheRef.current = newCache;
1254
- return jsxs(Fragment, {
1255
- children: elements
1256
- });
1257
- } catch (error) {
1258
- console.error('Failed to render markdown:', error);
1259
- return null;
1260
- }
1261
- }, [
1262
- content,
1263
- processor,
1264
- components,
1265
- options === null || options === void 0 ? void 0 : options.streaming
1266
- ]);
1267
- };
4
+ import { buildEditorAlignedComponents, createHastProcessor } from "./markdownReactShared";
5
+ import { useStreamingMarkdownReact } from "./streaming/useStreamingMarkdownReact";
6
+ export var useMarkdownToReact = useStreamingMarkdownReact;
1268
7
  /**
1269
8
  * 同步将 markdown 转为 React 元素(非 hook 版本,用于测试或一次性转换)
1270
9
  */ export var markdownToReactSync = function markdownToReactSync(content, components, remarkPlugins, htmlConfig) {
@@ -1275,7 +14,7 @@ export var useMarkdownToReact = function useMarkdownToReact(content, options) {
1275
14
  var mdast = processor.parse(preprocessed);
1276
15
  var hast = processor.runSync(mdast);
1277
16
  var userComps = components || {};
1278
- var allComponents = buildEditorAlignedComponents('ant-agentic-md-editor', userComps, false);
17
+ var allComponents = buildEditorAlignedComponents('ant-agentic-md-editor', userComps, false, undefined, false);
1279
18
  return toJsxRuntime(hast, {
1280
19
  Fragment: Fragment,
1281
20
  jsx: jsx,