@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.
- package/dist/ChatLayout/style.js +16 -13
- package/dist/Components/ActionIconBox/index.js +4 -0
- package/dist/Components/Button/IconButton/style.js +1 -1
- package/dist/Components/Button/ToggleButton/style.js +1 -1
- package/dist/Constants/mobile.d.ts +2 -2
- package/dist/Constants/mobile.js +1 -1
- package/dist/History/style.js +2 -2
- package/dist/MarkdownEditor/BaseMarkdownEditor.js +2 -1
- package/dist/MarkdownEditor/editor/Editor.js +22 -6
- package/dist/MarkdownEditor/editor/elements/Paragraph/index.js +27 -5
- package/dist/MarkdownEditor/editor/style.js +7 -3
- package/dist/MarkdownEditor/editor/tools/JinjaTemplatePanel/index.js +2 -2
- package/dist/MarkdownEditor/editor/utils/findMatchingClose.js +38 -18
- package/dist/MarkdownEditor/style.js +13 -2
- package/dist/MarkdownEditor/types.d.ts +11 -1
- package/dist/MarkdownInputField/AttachmentButton/AttachmentFileList/AttachmentFileIcon.js +1 -1
- package/dist/MarkdownInputField/AttachmentButton/AttachmentFileList/style.js +3 -3
- package/dist/MarkdownInputField/FileMapView/style.js +3 -2
- package/dist/MarkdownInputField/SkillModeBar/style.js +1 -1
- package/dist/MarkdownInputField/style.js +1 -1
- package/dist/MarkdownRenderer/MarkdownRenderer.js +3 -2
- package/dist/MarkdownRenderer/index.d.ts +1 -1
- package/dist/MarkdownRenderer/markdownReactShared.d.ts +35 -28
- package/dist/MarkdownRenderer/markdownReactShared.js +181 -60
- package/dist/MarkdownRenderer/renderers/MermaidRenderer.d.ts +2 -2
- package/dist/MarkdownRenderer/renderers/MermaidRenderer.js +162 -5
- package/dist/MarkdownRenderer/streaming/useStreamingMarkdownReact.js +3 -2
- package/dist/MarkdownRenderer/types.d.ts +21 -0
- package/dist/MarkdownRenderer/useStreaming.js +50 -15
- package/dist/Plugins/mermaid/Mermaid.d.ts +2 -28
- package/dist/Plugins/mermaid/Mermaid.js +13 -30
- package/dist/Plugins/mermaid/MermaidFallback.d.ts +5 -2
- package/dist/Plugins/mermaid/MermaidFallback.js +13 -10
- package/dist/Plugins/mermaid/MermaidRendererImpl.d.ts +0 -4
- package/dist/Plugins/mermaid/MermaidRendererImpl.js +15 -22
- package/dist/Plugins/mermaid/style.d.ts +0 -5
- package/dist/Plugins/mermaid/style.js +18 -71
- package/dist/ThoughtChainList/style.js +1 -1
- package/dist/ToolUseBarThink/style.js +1 -1
- package/dist/Workspace/Browser/index.d.ts +6 -0
- package/dist/Workspace/Browser/index.js +22 -13
- package/dist/Workspace/Browser/style.js +14 -15
- package/dist/Workspace/File/FileComponent.js +4 -4
- package/dist/Workspace/File/PreviewComponent.js +4 -4
- package/dist/Workspace/File/style.js +33 -39
- package/dist/Workspace/RealtimeFollow/style.js +78 -85
- package/dist/Workspace/style.js +41 -53
- 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
|
|
5
|
-
*
|
|
4
|
+
* Mermaid 图表渲染器
|
|
5
|
+
* 加载 mermaid 库期间展示源码预览,加载完成后渲染图表。
|
|
6
6
|
*/
|
|
7
7
|
export declare const MermaidBlockRenderer: React.FC<RendererBlockProps>;
|
|
@@ -1,5 +1,157 @@
|
|
|
1
|
-
|
|
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
|
|
15
|
-
*
|
|
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(
|
|
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 +
|
|
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,
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
-
|
|
122
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
7
|
-
*
|
|
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 {
|
|
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
|
-
*
|
|
162
|
-
*
|
|
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(
|
|
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,21 +1,24 @@
|
|
|
1
|
-
import { ConfigProvider
|
|
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
|
-
|
|
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(
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
margin: 0,
|
|
20
|
+
whiteSpace: 'pre-wrap',
|
|
21
|
+
wordBreak: 'break-word'
|
|
19
22
|
}
|
|
20
|
-
})));
|
|
23
|
+
}, props.code))));
|
|
21
24
|
};
|
|
@@ -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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
|
34
|
+
var containerStyle = useMemo(function() {
|
|
33
35
|
return {
|
|
34
|
-
|
|
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
|
|
46
|
-
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
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;
|