@ant-design/agentic-ui 2.30.9 → 2.30.11

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 (48) hide show
  1. package/dist/ChatLayout/style.js +16 -13
  2. package/dist/Components/ActionIconBox/index.js +4 -0
  3. package/dist/Components/Button/IconButton/style.js +1 -1
  4. package/dist/Components/Button/ToggleButton/style.js +1 -1
  5. package/dist/Constants/mobile.d.ts +2 -2
  6. package/dist/Constants/mobile.js +1 -1
  7. package/dist/History/style.js +2 -2
  8. package/dist/MarkdownEditor/BaseMarkdownEditor.js +2 -1
  9. package/dist/MarkdownEditor/editor/Editor.js +22 -6
  10. package/dist/MarkdownEditor/editor/elements/Paragraph/index.js +27 -5
  11. package/dist/MarkdownEditor/editor/style.js +7 -3
  12. package/dist/MarkdownEditor/editor/tools/JinjaTemplatePanel/index.js +2 -2
  13. package/dist/MarkdownEditor/editor/utils/findMatchingClose.js +38 -18
  14. package/dist/MarkdownEditor/style.js +13 -2
  15. package/dist/MarkdownEditor/types.d.ts +11 -1
  16. package/dist/MarkdownInputField/AttachmentButton/AttachmentFileList/AttachmentFileIcon.js +1 -1
  17. package/dist/MarkdownInputField/AttachmentButton/AttachmentFileList/style.js +3 -3
  18. package/dist/MarkdownInputField/FileMapView/style.js +3 -2
  19. package/dist/MarkdownInputField/SkillModeBar/style.js +1 -1
  20. package/dist/MarkdownInputField/style.js +1 -1
  21. package/dist/MarkdownRenderer/MarkdownRenderer.js +3 -2
  22. package/dist/MarkdownRenderer/index.d.ts +1 -1
  23. package/dist/MarkdownRenderer/markdownReactShared.d.ts +35 -28
  24. package/dist/MarkdownRenderer/markdownReactShared.js +181 -60
  25. package/dist/MarkdownRenderer/renderers/MermaidRenderer.d.ts +2 -2
  26. package/dist/MarkdownRenderer/renderers/MermaidRenderer.js +162 -5
  27. package/dist/MarkdownRenderer/streaming/useStreamingMarkdownReact.js +3 -2
  28. package/dist/MarkdownRenderer/types.d.ts +21 -0
  29. package/dist/MarkdownRenderer/useStreaming.js +50 -15
  30. package/dist/Plugins/mermaid/Mermaid.d.ts +2 -28
  31. package/dist/Plugins/mermaid/Mermaid.js +13 -30
  32. package/dist/Plugins/mermaid/MermaidFallback.d.ts +5 -2
  33. package/dist/Plugins/mermaid/MermaidFallback.js +13 -10
  34. package/dist/Plugins/mermaid/MermaidRendererImpl.d.ts +0 -4
  35. package/dist/Plugins/mermaid/MermaidRendererImpl.js +15 -22
  36. package/dist/Plugins/mermaid/style.d.ts +0 -5
  37. package/dist/Plugins/mermaid/style.js +18 -71
  38. package/dist/ThoughtChainList/style.js +1 -1
  39. package/dist/ToolUseBarThink/style.js +1 -1
  40. package/dist/Workspace/Browser/index.d.ts +6 -0
  41. package/dist/Workspace/Browser/index.js +22 -13
  42. package/dist/Workspace/Browser/style.js +14 -15
  43. package/dist/Workspace/File/FileComponent.js +4 -4
  44. package/dist/Workspace/File/PreviewComponent.js +4 -4
  45. package/dist/Workspace/File/style.js +33 -39
  46. package/dist/Workspace/RealtimeFollow/style.js +78 -85
  47. package/dist/Workspace/style.js +41 -53
  48. package/package.json +3 -3
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import type { RendererBlockProps } from '../types';
3
3
  /**
4
- * Mermaid 图表渲染器——复用 MarkdownEditor 的 MermaidRendererImpl。
5
- * 将代码块文本包装为 CodeNode 格式后直接传递给已有的 Mermaid 渲染组件。
4
+ * Mermaid 图表渲染器
5
+ * 加载 mermaid 库期间展示源码预览,加载完成后渲染图表。
6
6
  */
7
7
  export declare const MermaidBlockRenderer: React.FC<RendererBlockProps>;
@@ -1,5 +1,157 @@
1
- import React, { useMemo } from "react";
1
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
+ try {
3
+ var info = gen[key](arg);
4
+ var value = info.value;
5
+ } catch (error) {
6
+ reject(error);
7
+ return;
8
+ }
9
+ if (info.done) {
10
+ resolve(value);
11
+ } else {
12
+ Promise.resolve(value).then(_next, _throw);
13
+ }
14
+ }
15
+ function _async_to_generator(fn) {
16
+ return function() {
17
+ var self = this, args = arguments;
18
+ return new Promise(function(resolve, reject) {
19
+ var gen = fn.apply(self, args);
20
+ function _next(value) {
21
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
+ }
23
+ function _throw(err) {
24
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
+ }
26
+ _next(undefined);
27
+ });
28
+ };
29
+ }
30
+ function _ts_generator(thisArg, body) {
31
+ var f, y, t, _ = {
32
+ label: 0,
33
+ sent: function() {
34
+ if (t[0] & 1) throw t[1];
35
+ return t[1];
36
+ },
37
+ trys: [],
38
+ ops: []
39
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
40
+ return d(g, "next", {
41
+ value: verb(0)
42
+ }), d(g, "throw", {
43
+ value: verb(1)
44
+ }), d(g, "return", {
45
+ value: verb(2)
46
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
47
+ value: function() {
48
+ return this;
49
+ }
50
+ }), g;
51
+ function verb(n) {
52
+ return function(v) {
53
+ return step([
54
+ n,
55
+ v
56
+ ]);
57
+ };
58
+ }
59
+ function step(op) {
60
+ if (f) throw new TypeError("Generator is already executing.");
61
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
62
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
63
+ if (y = 0, t) op = [
64
+ op[0] & 2,
65
+ t.value
66
+ ];
67
+ switch(op[0]){
68
+ case 0:
69
+ case 1:
70
+ t = op;
71
+ break;
72
+ case 4:
73
+ _.label++;
74
+ return {
75
+ value: op[1],
76
+ done: false
77
+ };
78
+ case 5:
79
+ _.label++;
80
+ y = op[1];
81
+ op = [
82
+ 0
83
+ ];
84
+ continue;
85
+ case 7:
86
+ op = _.ops.pop();
87
+ _.trys.pop();
88
+ continue;
89
+ default:
90
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
91
+ _ = 0;
92
+ continue;
93
+ }
94
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
95
+ _.label = op[1];
96
+ break;
97
+ }
98
+ if (op[0] === 6 && _.label < t[1]) {
99
+ _.label = t[1];
100
+ t = op;
101
+ break;
102
+ }
103
+ if (t && _.label < t[2]) {
104
+ _.label = t[2];
105
+ _.ops.push(op);
106
+ break;
107
+ }
108
+ if (t[2]) _.ops.pop();
109
+ _.trys.pop();
110
+ continue;
111
+ }
112
+ op = body.call(thisArg, _);
113
+ } catch (e) {
114
+ op = [
115
+ 6,
116
+ e
117
+ ];
118
+ y = 0;
119
+ } finally{
120
+ f = t = 0;
121
+ }
122
+ if (op[0] & 5) throw op[1];
123
+ return {
124
+ value: op[0] ? op[1] : void 0,
125
+ done: true
126
+ };
127
+ }
128
+ }
129
+ import React, { lazy, Suspense, useMemo } from "react";
130
+ import { isBrowser } from "../../Plugins/mermaid/env";
131
+ import { MermaidCodePreview } from "../../Plugins/mermaid/MermaidFallback";
2
132
  import { MermaidRendererImpl } from "../../Plugins/mermaid/MermaidRendererImpl";
133
+ import { loadMermaid } from "../../Plugins/mermaid/utils";
134
+ var LazyMermaidRenderer = /*#__PURE__*/ lazy(function() {
135
+ return _async_to_generator(function() {
136
+ return _ts_generator(this, function(_state) {
137
+ switch(_state.label){
138
+ case 0:
139
+ return [
140
+ 4,
141
+ loadMermaid()
142
+ ];
143
+ case 1:
144
+ _state.sent();
145
+ return [
146
+ 2,
147
+ {
148
+ default: MermaidRendererImpl
149
+ }
150
+ ];
151
+ }
152
+ });
153
+ })();
154
+ });
3
155
  var extractTextContent = function extractTextContent1(children) {
4
156
  var _children_props;
5
157
  if (typeof children === 'string') return children;
@@ -11,8 +163,8 @@ var extractTextContent = function extractTextContent1(children) {
11
163
  return '';
12
164
  };
13
165
  /**
14
- * Mermaid 图表渲染器——复用 MarkdownEditor 的 MermaidRendererImpl。
15
- * 将代码块文本包装为 CodeNode 格式后直接传递给已有的 Mermaid 渲染组件。
166
+ * Mermaid 图表渲染器
167
+ * 加载 mermaid 库期间展示源码预览,加载完成后渲染图表。
16
168
  */ export var MermaidBlockRenderer = function MermaidBlockRenderer(props) {
17
169
  var children = props.children;
18
170
  var code = extractTextContent(children);
@@ -31,13 +183,18 @@ var extractTextContent = function extractTextContent1(children) {
31
183
  code
32
184
  ]);
33
185
  if (!code.trim()) return null;
186
+ if (!isBrowser()) return null;
34
187
  return /*#__PURE__*/ React.createElement("div", {
35
188
  "data-be": "mermaid",
36
189
  style: {
37
190
  margin: '1em 0'
38
191
  }
39
- }, /*#__PURE__*/ React.createElement(MermaidRendererImpl, {
192
+ }, /*#__PURE__*/ React.createElement(Suspense, {
193
+ fallback: /*#__PURE__*/ React.createElement(MermaidCodePreview, {
194
+ code: code
195
+ })
196
+ }, /*#__PURE__*/ React.createElement(LazyMermaidRenderer, {
40
197
  element: fakeElement
41
- }));
198
+ })));
42
199
  };
43
200
  MermaidBlockRenderer.displayName = 'MermaidBlockRenderer';
@@ -18,13 +18,14 @@ import { shouldResetRevisionProgress } from "./revisionPolicy";
18
18
  ]);
19
19
  var prefixCls = (options === null || options === void 0 ? void 0 : options.prefixCls) || 'ant-agentic-md-editor';
20
20
  var components = useMemo(function() {
21
- return buildEditorAlignedComponents(prefixCls, (options === null || options === void 0 ? void 0 : options.components) || {}, options === null || options === void 0 ? void 0 : options.streaming, options === null || options === void 0 ? void 0 : options.linkConfig, options === null || options === void 0 ? void 0 : options.streamingParagraphAnimation);
21
+ return buildEditorAlignedComponents(prefixCls, (options === null || options === void 0 ? void 0 : options.components) || {}, options === null || options === void 0 ? void 0 : options.streaming, options === null || options === void 0 ? void 0 : options.linkConfig, options === null || options === void 0 ? void 0 : options.streamingParagraphAnimation, options === null || options === void 0 ? void 0 : options.eleRender);
22
22
  }, [
23
23
  prefixCls,
24
24
  options === null || options === void 0 ? void 0 : options.components,
25
25
  options === null || options === void 0 ? void 0 : options.streaming,
26
26
  options === null || options === void 0 ? void 0 : options.linkConfig,
27
- options === null || options === void 0 ? void 0 : options.streamingParagraphAnimation
27
+ options === null || options === void 0 ? void 0 : options.streamingParagraphAnimation,
28
+ options === null || options === void 0 ? void 0 : options.eleRender
28
29
  ]);
29
30
  return useMemo(function() {
30
31
  if (!content) {
@@ -1,6 +1,19 @@
1
1
  import type React from 'react';
2
2
  import type { MarkdownRemarkPlugin, MarkdownToHtmlConfig } from '../MarkdownEditor/editor/utils/markdownToHtml';
3
3
  import type { MarkdownEditorPlugin } from '../MarkdownEditor/plugin';
4
+ /**
5
+ * markdown 渲染模式下传给 eleRender 的元素属性,
6
+ * 包含 HTML 标签名、hast 节点及所有原生 HTML 属性。
7
+ */
8
+ export interface MarkdownRendererEleProps {
9
+ /** HTML tag name, e.g. 'p', 'h1', 'blockquote', 'pre' */
10
+ tagName: string;
11
+ /** The original hast node */
12
+ node?: any;
13
+ /** Rendered children */
14
+ children?: React.ReactNode;
15
+ [key: string]: any;
16
+ }
4
17
  export interface CharacterQueueOptions {
5
18
  /** 每帧输出的最大字符数,默认 3 */
6
19
  charsPerFrame?: number;
@@ -79,6 +92,14 @@ export interface MarkdownRendererProps {
79
92
  /** 自定义渲染函数,接收解析后的 JSON value,返回 React 节点 */
80
93
  render?: (value: any) => React.ReactNode;
81
94
  };
95
+ /**
96
+ * 自定义元素渲染函数(markdown 渲染模式)
97
+ * 与 Slate 模式的 eleItemRender 对应,允许拦截并替换任意块级/行内元素的渲染结果。
98
+ * @param props - 元素属性(tagName、node、children 等)
99
+ * @param defaultDom - 默认渲染结果
100
+ * @returns 自定义渲染节点,或 undefined 时回退到 defaultDom
101
+ */
102
+ eleRender?: (props: MarkdownRendererEleProps, defaultDom: React.ReactNode) => React.ReactNode;
82
103
  }
83
104
  export interface MarkdownRendererRef {
84
105
  /** 获取渲染容器的 DOM 元素 */
@@ -97,30 +97,58 @@ var STREAM_INCOMPLETE_REGEX = {
97
97
  /^[-+*]\s{1,3}(\*{1,3}|_{1,3})(?!\s)(?!.*\1$)[^\r\n]{0,1000}$/
98
98
  ],
99
99
  'inline-code': [
100
- /^`[^`\r\n]{0,300}$/
100
+ /^`[^`\r\n]{0,300}$/,
101
+ /^`{2,}$/
101
102
  ]
102
103
  };
103
104
  var STREAMING_LOADING_PLACEHOLDER = '...';
105
+ var parsePipeRowCells = function parsePipeRowCells(line) {
106
+ var trimmedLine = line.trim();
107
+ if (!trimmedLine.startsWith('|') || !trimmedLine.endsWith('|')) {
108
+ return null;
109
+ }
110
+ var cells = trimmedLine.split('|').slice(1, -1).map(function(cell) {
111
+ return cell.trim();
112
+ });
113
+ if (!cells.length) return null;
114
+ return cells;
115
+ };
116
+ var isTableSeparatorCell = function isTableSeparatorCell(cell) {
117
+ return /^:?-{3,}:?$/.test(cell);
118
+ };
104
119
  /**
105
120
  * 判断表格是否仍不完整。
106
- * 等待 header + separator + 至少一行数据(3 行)后提交。
121
+ * 等待 header + separator + 第一行数据完整闭合后提交。
107
122
  */ var isTableIncomplete = function isTableIncomplete(markdown) {
123
+ var _firstDataRowTrimmed_match;
108
124
  if (markdown.includes('\n\n')) return false;
109
- var lines = markdown.split('\n');
125
+ var lines = markdown.replace(/\r\n/g, '\n').split('\n');
110
126
  // 需要至少 3 行:header | separator | 第一行数据
111
127
  if (lines.length < 3) return true;
112
- var _lines = _sliced_to_array(lines, 2), header = _lines[0], separator = _lines[1];
113
- if (!/^\|.*\|$/.test(header.trim())) return false;
114
- var columns = separator.trim().split('|').map(function(c) {
115
- return c.trim();
116
- }).filter(Boolean);
117
- var isSeparatorValid = columns.every(function(col, i) {
118
- return i === columns.length - 1 ? col === ':' || /^:?-+:?$/.test(col) : /^:?-+:?$/.test(col);
119
- });
128
+ var _lines = _sliced_to_array(lines, 3), header = _lines[0], separator = _lines[1], firstDataRow = _lines[2];
129
+ var headerCells = parsePipeRowCells(header);
130
+ if (!headerCells) return false;
131
+ var separatorCells = parsePipeRowCells(separator);
132
+ if (!separatorCells || separatorCells.length !== headerCells.length) {
133
+ return false;
134
+ }
135
+ var isSeparatorValid = separatorCells.every(isTableSeparatorCell);
120
136
  if (!isSeparatorValid) return false;
121
- // separator 完整但还没有数据行
122
- if (lines.length <= 2) return true;
123
- // 有数据行了,不再缓存
137
+ var firstDataRowTrimmed = (firstDataRow === null || firstDataRow === void 0 ? void 0 : firstDataRow.trim()) || '';
138
+ // 第三行仍为空,说明首行数据尚未到达,继续缓存避免提前渲染 table header
139
+ if (!firstDataRowTrimmed) return true;
140
+ // 第三行不是表格行,视为当前表格 token 已完成(例如 header-only 表格后接普通文本)
141
+ if (!firstDataRowTrimmed.startsWith('|')) return false;
142
+ var minPipeDelimiterCount = headerCells.length + 1;
143
+ var currentPipeDelimiterCount = ((_firstDataRowTrimmed_match = firstDataRowTrimmed.match(/\|/g)) === null || _firstDataRowTrimmed_match === void 0 ? void 0 : _firstDataRowTrimmed_match.length) || 0;
144
+ // 管道分隔符数量不足,说明第一行数据还未输入完整
145
+ if (currentPipeDelimiterCount < minPipeDelimiterCount) return true;
146
+ // 第一行数据必须是闭合的管道行(以 | 结尾),否则继续缓存
147
+ if (!firstDataRowTrimmed.endsWith('|')) return true;
148
+ var firstDataRowCells = parsePipeRowCells(firstDataRow);
149
+ if (!firstDataRowCells || firstDataRowCells.length !== headerCells.length) {
150
+ return true;
151
+ }
124
152
  return false;
125
153
  };
126
154
  var _obj;
@@ -301,12 +329,19 @@ var isInCodeBlock = function isInCodeBlock(text) {
301
329
  var chunk = text.slice(cache.processedLength);
302
330
  if (!chunk) return;
303
331
  cache.processedLength += chunk.length;
332
+ var wasInCodeBlock = isInCodeBlock(cache.completeMarkdown + cache.pending);
304
333
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
305
334
  try {
306
335
  for(var _iterator = chunk[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
307
336
  var char = _step.value;
308
337
  cache.pending += char;
309
- if (isInCodeBlock(cache.completeMarkdown + cache.pending)) {
338
+ var inCodeBlock = isInCodeBlock(cache.completeMarkdown + cache.pending);
339
+ if (inCodeBlock) {
340
+ wasInCodeBlock = true;
341
+ continue;
342
+ }
343
+ if (wasInCodeBlock) {
344
+ wasInCodeBlock = false;
310
345
  commitCache(cache);
311
346
  continue;
312
347
  }
@@ -3,38 +3,12 @@ import { CodeNode } from '../../MarkdownEditor/el';
3
3
  /**
4
4
  * Mermaid 组件 - Mermaid图表渲染组件
5
5
  *
6
- * 该组件使用Mermaid库渲染图表,支持流程图、时序图、甘特图等。
7
- * 使用 React.lazy 和 Suspense 实现代码分割和延迟加载,优化性能。
6
+ * 仅在代码块闭合(otherProps.finished !== false)时才渲染图表,
7
+ * 否则展示原始代码。加载过程中同样展示源码预览而非骨架屏。
8
8
  *
9
9
  * @component
10
- * @description Mermaid图表渲染组件,支持各种Mermaid图表类型
11
10
  * @param {Object} props - 组件属性
12
11
  * @param {CodeNode} props.element - 代码节点,包含Mermaid图表代码
13
- * @param {string} [props.element.value] - Mermaid图表代码字符串
14
- *
15
- * @example
16
- * ```tsx
17
- * <Mermaid
18
- * element={{
19
- * type: 'code',
20
- * value: 'graph TD\nA[开始] --> B[处理] --> C[结束]'
21
- * }}
22
- * />
23
- * ```
24
- *
25
- * @returns {React.ReactElement} 渲染的Mermaid图表组件
26
- *
27
- * @remarks
28
- * - 基于Mermaid库实现图表渲染
29
- * - 支持多种图表类型(流程图、时序图、甘特图等)
30
- * - 使用 React.lazy 和 Suspense 实现代码分割
31
- * - 提供延迟渲染优化性能
32
- * - 包含错误处理机制
33
- * - 支持空状态显示
34
- * - 提供美观的样式设计
35
- * - 禁用文本选择
36
- * - 居中显示图表
37
- * - 自动生成唯一ID
38
12
  */
39
13
  export declare const Mermaid: (props: {
40
14
  element: CodeNode;
@@ -128,7 +128,7 @@ function _ts_generator(thisArg, body) {
128
128
  }
129
129
  import React, { lazy, Suspense } from "react";
130
130
  import { isBrowser } from "./env";
131
- import { MermaidFallback } from "./MermaidFallback";
131
+ import { MermaidCodePreview } from "./MermaidFallback";
132
132
  import { MermaidRendererImpl } from "./MermaidRendererImpl";
133
133
  import { loadMermaid } from "./utils";
134
134
  /**
@@ -158,44 +158,27 @@ import { loadMermaid } from "./utils";
158
158
  /**
159
159
  * Mermaid 组件 - Mermaid图表渲染组件
160
160
  *
161
- * 该组件使用Mermaid库渲染图表,支持流程图、时序图、甘特图等。
162
- * 使用 React.lazy 和 Suspense 实现代码分割和延迟加载,优化性能。
161
+ * 仅在代码块闭合(otherProps.finished !== false)时才渲染图表,
162
+ * 否则展示原始代码。加载过程中同样展示源码预览而非骨架屏。
163
163
  *
164
164
  * @component
165
- * @description Mermaid图表渲染组件,支持各种Mermaid图表类型
166
165
  * @param {Object} props - 组件属性
167
166
  * @param {CodeNode} props.element - 代码节点,包含Mermaid图表代码
168
- * @param {string} [props.element.value] - Mermaid图表代码字符串
169
- *
170
- * @example
171
- * ```tsx
172
- * <Mermaid
173
- * element={{
174
- * type: 'code',
175
- * value: 'graph TD\nA[开始] --> B[处理] --> C[结束]'
176
- * }}
177
- * />
178
- * ```
179
- *
180
- * @returns {React.ReactElement} 渲染的Mermaid图表组件
181
- *
182
- * @remarks
183
- * - 基于Mermaid库实现图表渲染
184
- * - 支持多种图表类型(流程图、时序图、甘特图等)
185
- * - 使用 React.lazy 和 Suspense 实现代码分割
186
- * - 提供延迟渲染优化性能
187
- * - 包含错误处理机制
188
- * - 支持空状态显示
189
- * - 提供美观的样式设计
190
- * - 禁用文本选择
191
- * - 居中显示图表
192
- * - 自动生成唯一ID
193
167
  */ export var Mermaid = function Mermaid(props) {
168
+ var _props_element_otherProps;
194
169
  if (!isBrowser()) {
195
170
  return null;
196
171
  }
172
+ var isUnfinished = ((_props_element_otherProps = props.element.otherProps) === null || _props_element_otherProps === void 0 ? void 0 : _props_element_otherProps.finished) === false;
173
+ if (isUnfinished) {
174
+ return /*#__PURE__*/ React.createElement(MermaidCodePreview, {
175
+ code: props.element.value || ''
176
+ });
177
+ }
197
178
  return /*#__PURE__*/ React.createElement(Suspense, {
198
- fallback: /*#__PURE__*/ React.createElement(MermaidFallback, null)
179
+ fallback: /*#__PURE__*/ React.createElement(MermaidCodePreview, {
180
+ code: props.element.value || ''
181
+ })
199
182
  }, /*#__PURE__*/ React.createElement(MermaidRenderer, {
200
183
  element: props.element
201
184
  }));
@@ -1,4 +1,7 @@
1
1
  /**
2
- * 加载中的占位组件
2
+ * Mermaid 源码预览组件
3
+ * 在加载 / 未闭合 / 等待渲染等阶段展示原始 Mermaid 代码
3
4
  */
4
- export declare const MermaidFallback: () => any;
5
+ export declare const MermaidCodePreview: (props: {
6
+ code: string;
7
+ }) => any;
@@ -1,21 +1,24 @@
1
- import { ConfigProvider, Skeleton } from "antd";
1
+ import { ConfigProvider } from "antd";
2
2
  import classNames from "clsx";
3
3
  import React, { useContext } from "react";
4
4
  import { useStyle } from "./style";
5
5
  /**
6
- * 加载中的占位组件
7
- */ export var MermaidFallback = function MermaidFallback() {
6
+ * Mermaid 源码预览组件
7
+ * 在加载 / 未闭合 / 等待渲染等阶段展示原始 Mermaid 代码
8
+ */ export var MermaidCodePreview = function MermaidCodePreview(props) {
8
9
  var context = useContext(ConfigProvider.ConfigContext);
9
10
  var baseCls = (context === null || context === void 0 ? void 0 : context.getPrefixCls('agentic-plugin-mermaid')) || 'agentic-plugin-mermaid';
10
11
  var _useStyle = useStyle(baseCls), wrapSSR = _useStyle.wrapSSR, hashId = _useStyle.hashId;
11
12
  return wrapSSR(/*#__PURE__*/ React.createElement("div", {
12
- className: classNames("".concat(baseCls, "-fallback"), hashId)
13
- }, /*#__PURE__*/ React.createElement(Skeleton.Image, {
14
- active: true,
13
+ className: classNames(baseCls, hashId),
14
+ contentEditable: false
15
+ }, /*#__PURE__*/ React.createElement("div", {
16
+ className: classNames("".concat(baseCls, "-empty"), hashId)
17
+ }, /*#__PURE__*/ React.createElement("pre", {
15
18
  style: {
16
- width: '100%',
17
- minHeight: '200px',
18
- maxWidth: '800px'
19
+ margin: 0,
20
+ whiteSpace: 'pre-wrap',
21
+ wordBreak: 'break-word'
19
22
  }
20
- })));
23
+ }, props.code))));
21
24
  };
@@ -1,8 +1,4 @@
1
1
  import { CodeNode } from '../../MarkdownEditor/el';
2
- /**
3
- * Mermaid 渲染器组件实现
4
- * 负责实际的图表渲染逻辑
5
- */
6
2
  export declare const MermaidRendererImpl: (props: {
7
3
  element: CodeNode;
8
4
  }) => any;
@@ -4,10 +4,12 @@ import React, { useContext, useMemo, useRef } from "react";
4
4
  import { useIntersectionOnce } from "../../Hooks/useIntersectionOnce";
5
5
  import { useStyle } from "./style";
6
6
  import { useMermaidRender } from "./useMermaidRender";
7
- /**
8
- * Mermaid 渲染器组件实现
9
- * 负责实际的图表渲染逻辑
10
- */ export var MermaidRendererImpl = function MermaidRendererImpl(props) {
7
+ var PRE_STYLE = {
8
+ margin: 0,
9
+ whiteSpace: 'pre-wrap',
10
+ wordBreak: 'break-word'
11
+ };
12
+ export var MermaidRendererImpl = function MermaidRendererImpl(props) {
11
13
  var context = useContext(ConfigProvider.ConfigContext);
12
14
  var baseCls = (context === null || context === void 0 ? void 0 : context.getPrefixCls('agentic-plugin-mermaid')) || 'plugin-mermaid';
13
15
  var _useStyle = useStyle(baseCls), wrapSSR = _useStyle.wrapSSR, hashId = _useStyle.hashId;
@@ -29,9 +31,9 @@ import { useMermaidRender } from "./useMermaidRender";
29
31
  renderedCode,
30
32
  isError
31
33
  ]);
32
- var style = useMemo(function() {
34
+ var containerStyle = useMemo(function() {
33
35
  return {
34
- visibility: isRendered ? 'visible' : 'hidden',
36
+ opacity: isRendered ? 1 : 0,
35
37
  pointerEvents: isRendered ? 'auto' : 'none',
36
38
  width: '100%',
37
39
  height: isRendered ? '100%' : '0',
@@ -42,8 +44,8 @@ import { useMermaidRender } from "./useMermaidRender";
42
44
  }, [
43
45
  isRendered
44
46
  ]);
45
- var renderCode = props.element.value || '';
46
- var dom = /*#__PURE__*/ React.createElement("div", {
47
+ var code = props.element.value || '';
48
+ return wrapSSR(/*#__PURE__*/ React.createElement("div", {
47
49
  ref: containerRef,
48
50
  className: classNames(baseCls, hashId),
49
51
  contentEditable: false
@@ -51,24 +53,15 @@ import { useMermaidRender } from "./useMermaidRender";
51
53
  contentEditable: false,
52
54
  ref: divRef,
53
55
  className: classNames(hashId),
54
- style: style,
56
+ style: containerStyle,
55
57
  "data-mermaid-container": "true"
56
58
  }), error && /*#__PURE__*/ React.createElement("div", {
57
59
  className: classNames("".concat(baseCls, "-error"), hashId)
58
60
  }, /*#__PURE__*/ React.createElement("pre", {
59
- style: {
60
- margin: 0,
61
- whiteSpace: 'pre-wrap',
62
- wordBreak: 'break-word'
63
- }
64
- }, renderCode)), !renderedCode && !error && /*#__PURE__*/ React.createElement("div", {
61
+ style: PRE_STYLE
62
+ }, code)), !renderedCode && !error && /*#__PURE__*/ React.createElement("div", {
65
63
  className: classNames("".concat(baseCls, "-empty"), hashId)
66
64
  }, /*#__PURE__*/ React.createElement("pre", {
67
- style: {
68
- margin: 0,
69
- whiteSpace: 'pre-wrap',
70
- wordBreak: 'break-word'
71
- }
72
- }, renderCode)));
73
- return wrapSSR(dom);
65
+ style: PRE_STYLE
66
+ }, code))));
74
67
  };
@@ -1,9 +1,4 @@
1
1
  /// <reference types="react" />
2
- /**
3
- * Mermaid 插件样式 Hook
4
- * @param prefixCls - 样式类名前缀
5
- * @returns 样式相关的 wrapSSR 和 hashId
6
- */
7
2
  export declare function useStyle(prefixCls?: string): {
8
3
  hashId: string;
9
4
  wrapSSR: (node: import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>) => import("react").JSX.Element;