@ant-design/agentic-ui 2.30.9 → 2.30.10
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/Constants/mobile.d.ts +2 -2
- package/dist/Constants/mobile.js +1 -1
- package/dist/MarkdownEditor/editor/utils/findMatchingClose.js +38 -18
- package/dist/MarkdownEditor/style.js +13 -2
- package/dist/MarkdownEditor/types.d.ts +1 -1
- package/dist/MarkdownRenderer/markdownReactShared.js +2 -2
- package/dist/MarkdownRenderer/renderers/MermaidRenderer.d.ts +2 -2
- package/dist/MarkdownRenderer/renderers/MermaidRenderer.js +162 -5
- package/dist/MarkdownRenderer/useStreaming.js +10 -2
- 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/package.json +3 -3
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
export declare const TABLE_COL_WIDTH_MIN_COLUMNS = 5;
|
|
7
7
|
/** 编辑模式表格:列数 >= 此值时才计算并渲染 data col 元素,否则仅渲染行号列 */
|
|
8
8
|
export declare const TABLE_EDIT_COL_WIDTH_MIN_COLUMNS = 3;
|
|
9
|
-
/** 表格默认列宽 (px),与 style.ts 中 --agentic-ui-table-cell-min-width (
|
|
10
|
-
export declare const TABLE_DEFAULT_COL_WIDTH =
|
|
9
|
+
/** 表格默认列宽 (px),与 style.ts 中 --agentic-ui-table-cell-min-width (40px) 保持一致 */
|
|
10
|
+
export declare const TABLE_DEFAULT_COL_WIDTH = 40;
|
|
11
11
|
/** 表格最后一列最小宽度 (px),弹性列用于吸收剩余空间 */
|
|
12
12
|
export declare const TABLE_LAST_COL_MIN_WIDTH = 80;
|
|
13
13
|
export declare const MOBILE_PADDING = "clamp(4px, 2vw, 12px)";
|
package/dist/Constants/mobile.js
CHANGED
|
@@ -8,7 +8,7 @@ var MOBILE_TABLE_MIN_CELL_WIDTH = 96;
|
|
|
8
8
|
* - 列数 >= 5:使用 TABLE_DEFAULT_COL_WIDTH 固定宽度
|
|
9
9
|
*/ export var TABLE_COL_WIDTH_MIN_COLUMNS = 5;
|
|
10
10
|
/** 编辑模式表格:列数 >= 此值时才计算并渲染 data col 元素,否则仅渲染行号列 */ export var TABLE_EDIT_COL_WIDTH_MIN_COLUMNS = 3;
|
|
11
|
-
/** 表格默认列宽 (px),与 style.ts 中 --agentic-ui-table-cell-min-width (
|
|
11
|
+
/** 表格默认列宽 (px),与 style.ts 中 --agentic-ui-table-cell-min-width (40px) 保持一致 */ export var TABLE_DEFAULT_COL_WIDTH = 40;
|
|
12
12
|
/** 表格最后一列最小宽度 (px),弹性列用于吸收剩余空间 */ export var TABLE_LAST_COL_MIN_WIDTH = 80;
|
|
13
13
|
export var MOBILE_PADDING = "clamp(".concat(MOBILE_PADDING_MIN, ", ").concat(MOBILE_PADDING_SCALE, ", ").concat(MOBILE_PADDING_MAX, ")");
|
|
14
14
|
export var MOBILE_BREAKPOINT = '768px';
|
|
@@ -101,26 +101,46 @@
|
|
|
101
101
|
}
|
|
102
102
|
return false;
|
|
103
103
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
104
|
+
var MERMAID_DIAGRAM_KEYWORDS = [
|
|
105
|
+
'graph',
|
|
106
|
+
'flowchart',
|
|
107
|
+
'sequenceDiagram',
|
|
108
|
+
'gantt',
|
|
109
|
+
'pie',
|
|
110
|
+
'classDiagram',
|
|
111
|
+
'stateDiagram',
|
|
112
|
+
'erDiagram',
|
|
113
|
+
'journey',
|
|
114
|
+
'gitgraph',
|
|
115
|
+
'xychart-beta',
|
|
116
|
+
'mindmap',
|
|
117
|
+
'timeline',
|
|
118
|
+
'quadrantChart',
|
|
119
|
+
'sankey-beta',
|
|
120
|
+
'block-beta',
|
|
121
|
+
'packet-beta',
|
|
122
|
+
'kanban',
|
|
123
|
+
'architecture-beta',
|
|
124
|
+
'requirementDiagram',
|
|
125
|
+
'zenuml',
|
|
126
|
+
'C4Context',
|
|
127
|
+
'C4Container',
|
|
128
|
+
'C4Component',
|
|
129
|
+
'C4Deployment'
|
|
130
|
+
];
|
|
131
|
+
var MERMAID_INCOMPLETE_TAIL = [
|
|
132
|
+
/graph\s*$/i,
|
|
133
|
+
/-->?\s*$/
|
|
134
|
+
];
|
|
135
|
+
function isMermaidCodeComplete(code) {
|
|
136
|
+
if (!MERMAID_DIAGRAM_KEYWORDS.some(function(kw) {
|
|
137
|
+
return code.includes(kw);
|
|
138
|
+
})) return false;
|
|
111
139
|
if (code.length < 10) return false;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
// 检查是否以常见的不完整模式结尾
|
|
116
|
-
var incompletePatterns = [
|
|
117
|
-
/graph\s*$/i,
|
|
118
|
-
/-->?\s*$/
|
|
119
|
-
];
|
|
120
|
-
var endsWithIncomplete = incompletePatterns.some(function(pattern) {
|
|
121
|
-
return pattern.test(code);
|
|
140
|
+
if (checkUnclosedBrackets(code)) return false;
|
|
141
|
+
return !MERMAID_INCOMPLETE_TAIL.some(function(re) {
|
|
142
|
+
return re.test(code);
|
|
122
143
|
});
|
|
123
|
-
return !endsWithIncomplete;
|
|
124
144
|
}
|
|
125
145
|
/**
|
|
126
146
|
* 检查代码块是否完整(基于代码内容)
|
|
@@ -64,8 +64,8 @@ var TABLE_CELL = {
|
|
|
64
64
|
textAlign: 'left',
|
|
65
65
|
lineHeight: '24px',
|
|
66
66
|
fontSize: '1em',
|
|
67
|
-
minWidth: 'var(--agentic-ui-table-cell-min-width,
|
|
68
|
-
width: 'var(--agentic-ui-table-cell-min-width,
|
|
67
|
+
minWidth: 'var(--agentic-ui-table-cell-min-width, 40px)',
|
|
68
|
+
width: 'var(--agentic-ui-table-cell-min-width, 40px)',
|
|
69
69
|
whiteSpace: 'nowrap',
|
|
70
70
|
overflow: 'hidden',
|
|
71
71
|
textOverflow: 'ellipsis',
|
|
@@ -155,6 +155,8 @@ var genTableStyle = function genTableStyle(token, mobileBreakpoint, mobilePaddin
|
|
|
155
155
|
borderBottom: 'none'
|
|
156
156
|
}), _define_property(_obj, 'tr td:first-child:not(.config-td)', {
|
|
157
157
|
fontWeight: 600
|
|
158
|
+
}), _define_property(_obj, 'tbody tr:not(.config-tr)', {
|
|
159
|
+
animation: 'agenticTableRowFadeIn 0.3s ease both'
|
|
158
160
|
}), _define_property(_obj, 'tbody tr:not(.config-tr):hover', {
|
|
159
161
|
background: 'linear-gradient(var(--agentic-ui-table-hover-bg, rgba(0, 0, 0, 0.04)), var(--agentic-ui-table-hover-bg, rgba(0, 0, 0, 0.04))), linear-gradient(var(--agentic-ui-table-cell-bg, #ffffff), var(--agentic-ui-table-cell-bg, #ffffff))'
|
|
160
162
|
}), _define_property(_obj, "@media (max-width: ".concat(mobileBreakpoint, ")"), {
|
|
@@ -295,6 +297,15 @@ var genTableStyle = function genTableStyle(token, mobileBreakpoint, mobilePaddin
|
|
|
295
297
|
'&:hover': {
|
|
296
298
|
color: '#52c41a'
|
|
297
299
|
}
|
|
300
|
+
}), _define_property(_obj1, '@keyframes agenticTableRowFadeIn', {
|
|
301
|
+
from: {
|
|
302
|
+
opacity: 0,
|
|
303
|
+
transform: 'translateY(4px)'
|
|
304
|
+
},
|
|
305
|
+
to: {
|
|
306
|
+
opacity: 1,
|
|
307
|
+
transform: 'translateY(0)'
|
|
308
|
+
}
|
|
298
309
|
}), _obj1;
|
|
299
310
|
};
|
|
300
311
|
var genStyle = function genStyle(token) {
|
|
@@ -344,7 +344,7 @@ export type MarkdownEditorProps = {
|
|
|
344
344
|
* - `--agentic-ui-table-header-bg` 表头背景色,默认 #f7f7f9
|
|
345
345
|
* - `--agentic-ui-table-hover-bg` 行悬停背景色,默认 rgba(0,0,0,0.04)
|
|
346
346
|
* - `--agentic-ui-table-cell-bg` 单元格背景色,默认 #ffffff
|
|
347
|
-
* - `--agentic-ui-table-cell-min-width` 单元格最小宽度,默认
|
|
347
|
+
* - `--agentic-ui-table-cell-min-width` 单元格最小宽度,默认 40px
|
|
348
348
|
* - `--agentic-ui-table-cell-padding` 单元格内边距,默认 16px 12px
|
|
349
349
|
* @example style={{ ['--agentic-ui-table-border-color']: '#ddd', ['--agentic-ui-table-header-bg']: '#f0f0f0' } as React.CSSProperties}
|
|
350
350
|
*/
|
|
@@ -684,7 +684,7 @@ var extractLanguageFromClassName = function extractLanguageFromClassName(classNa
|
|
|
684
684
|
whiteSpace: 'normal',
|
|
685
685
|
maxWidth: '20%'
|
|
686
686
|
},
|
|
687
|
-
children: children
|
|
687
|
+
children: wrapAnimation(children)
|
|
688
688
|
}));
|
|
689
689
|
},
|
|
690
690
|
td: function td(props) {
|
|
@@ -698,7 +698,7 @@ var extractLanguageFromClassName = function extractLanguageFromClassName(classNa
|
|
|
698
698
|
whiteSpace: 'normal',
|
|
699
699
|
maxWidth: '20%'
|
|
700
700
|
},
|
|
701
|
-
children: children
|
|
701
|
+
children: wrapAnimation(children)
|
|
702
702
|
}));
|
|
703
703
|
},
|
|
704
704
|
// input[type=checkbox]:task list 的 checkbox(兜底,主逻辑在 li 中)
|
|
@@ -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';
|
|
@@ -97,7 +97,8 @@ 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 = '...';
|
|
@@ -301,12 +302,19 @@ var isInCodeBlock = function isInCodeBlock(text) {
|
|
|
301
302
|
var chunk = text.slice(cache.processedLength);
|
|
302
303
|
if (!chunk) return;
|
|
303
304
|
cache.processedLength += chunk.length;
|
|
305
|
+
var wasInCodeBlock = isInCodeBlock(cache.completeMarkdown + cache.pending);
|
|
304
306
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
305
307
|
try {
|
|
306
308
|
for(var _iterator = chunk[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
307
309
|
var char = _step.value;
|
|
308
310
|
cache.pending += char;
|
|
309
|
-
|
|
311
|
+
var inCodeBlock = isInCodeBlock(cache.completeMarkdown + cache.pending);
|
|
312
|
+
if (inCodeBlock) {
|
|
313
|
+
wasInCodeBlock = true;
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
if (wasInCodeBlock) {
|
|
317
|
+
wasInCodeBlock = false;
|
|
310
318
|
commitCache(cache);
|
|
311
319
|
continue;
|
|
312
320
|
}
|
|
@@ -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;
|
|
@@ -53,7 +53,6 @@ function _object_spread_props(target, source) {
|
|
|
53
53
|
import { useEditorStyleRegister } from "../../Hooks/useStyle";
|
|
54
54
|
var genStyle = function genStyle(token) {
|
|
55
55
|
return _define_property({}, token.componentCls, {
|
|
56
|
-
// 主容器样式
|
|
57
56
|
marginBottom: '0.75em',
|
|
58
57
|
cursor: 'default',
|
|
59
58
|
userSelect: 'none',
|
|
@@ -68,23 +67,21 @@ var genStyle = function genStyle(token) {
|
|
|
68
67
|
justifyContent: 'center',
|
|
69
68
|
alignItems: 'center',
|
|
70
69
|
flexDirection: 'column',
|
|
71
|
-
// 增加隔离:防止内容溢出影响其他元素
|
|
72
70
|
position: 'relative',
|
|
73
71
|
isolation: 'isolate',
|
|
74
72
|
contain: 'layout style paint',
|
|
75
73
|
overflow: 'hidden',
|
|
76
|
-
|
|
74
|
+
transition: 'height 0.3s ease, min-height 0.3s ease',
|
|
77
75
|
'& [data-mermaid-container="true"]': {
|
|
78
76
|
width: '100%',
|
|
79
77
|
display: 'flex',
|
|
80
78
|
justifyContent: 'center',
|
|
81
|
-
// 增加隔离样式
|
|
82
79
|
position: 'relative',
|
|
83
80
|
isolation: 'isolate',
|
|
84
81
|
contain: 'layout style paint',
|
|
85
|
-
overflow: 'hidden'
|
|
82
|
+
overflow: 'hidden',
|
|
83
|
+
transition: 'opacity 0.3s ease, height 0.3s ease, min-height 0.3s ease, max-height 0.3s ease'
|
|
86
84
|
},
|
|
87
|
-
// SVG 包装器样式(用于动态创建的 wrapper)
|
|
88
85
|
'& [data-mermaid-wrapper]': {
|
|
89
86
|
position: 'relative',
|
|
90
87
|
width: '100%',
|
|
@@ -97,87 +94,47 @@ var genStyle = function genStyle(token) {
|
|
|
97
94
|
alignItems: 'center',
|
|
98
95
|
minHeight: '200px'
|
|
99
96
|
},
|
|
100
|
-
// SVG 元素样式
|
|
101
97
|
'& [data-mermaid-svg="true"]': {
|
|
102
98
|
maxWidth: '100%',
|
|
103
99
|
height: 'auto',
|
|
104
100
|
overflow: 'hidden'
|
|
105
101
|
},
|
|
106
|
-
// SVG 内部元素样式
|
|
107
|
-
'& [data-mermaid-internal="true"]': {
|
|
108
|
-
},
|
|
109
|
-
// 加载状态样式
|
|
110
|
-
'&-loading': {
|
|
111
|
-
textAlign: 'center',
|
|
112
|
-
color: '#6B7280',
|
|
113
|
-
padding: '0.5rem',
|
|
114
|
-
position: 'relative',
|
|
115
|
-
zIndex: 1,
|
|
116
|
-
width: '100%',
|
|
117
|
-
display: 'flex',
|
|
118
|
-
justifyContent: 'center',
|
|
119
|
-
alignItems: 'center',
|
|
120
|
-
minHeight: '200px',
|
|
121
|
-
// Skeleton 样式优化
|
|
122
|
-
'& .ant-skeleton': {
|
|
123
|
-
width: '100%',
|
|
124
|
-
maxWidth: '800px'
|
|
125
|
-
},
|
|
126
|
-
'& .ant-skeleton-image': {
|
|
127
|
-
width: '100%',
|
|
128
|
-
minHeight: '200px',
|
|
129
|
-
borderRadius: '12px'
|
|
130
|
-
}
|
|
131
|
-
},
|
|
132
|
-
// 错误状态样式
|
|
133
102
|
'&-error': {
|
|
134
103
|
textAlign: 'center',
|
|
135
104
|
color: 'rgba(239, 68, 68, 0.8)',
|
|
136
105
|
padding: '0.5rem',
|
|
137
106
|
flex: 1,
|
|
138
|
-
// 错误信息也增加隔离
|
|
139
107
|
position: 'relative',
|
|
140
108
|
zIndex: 1,
|
|
141
109
|
wordBreak: 'break-word',
|
|
142
110
|
maxWidth: '100%',
|
|
143
111
|
height: '100%',
|
|
144
|
-
width: '100%'
|
|
112
|
+
width: '100%',
|
|
113
|
+
animation: 'agenticMermaidFadeIn 0.3s ease'
|
|
145
114
|
},
|
|
146
|
-
// 空状态样式
|
|
147
115
|
'&-empty': {
|
|
148
|
-
textAlign: '
|
|
116
|
+
textAlign: 'left',
|
|
149
117
|
color: '#6B7280',
|
|
150
|
-
padding: '0.5rem',
|
|
118
|
+
padding: '0.75rem 1.5rem',
|
|
151
119
|
position: 'relative',
|
|
152
120
|
zIndex: 1,
|
|
153
121
|
flex: 1,
|
|
154
122
|
height: '100%',
|
|
155
|
-
width: '100%'
|
|
156
|
-
},
|
|
157
|
-
// Fallback 组件样式
|
|
158
|
-
'&-fallback': {
|
|
159
|
-
marginBottom: '0.75em',
|
|
160
|
-
padding: '0.75rem 0',
|
|
161
|
-
display: 'flex',
|
|
162
|
-
justifyContent: 'center',
|
|
163
|
-
alignItems: 'center',
|
|
164
|
-
color: '#6B7280',
|
|
165
123
|
width: '100%',
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
124
|
+
fontFamily: "ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace",
|
|
125
|
+
fontSize: '0.875em',
|
|
126
|
+
lineHeight: 1.7,
|
|
127
|
+
animation: 'agenticMermaidFadeIn 0.3s ease'
|
|
128
|
+
},
|
|
129
|
+
'@keyframes agenticMermaidFadeIn': {
|
|
130
|
+
from: {
|
|
131
|
+
opacity: 0
|
|
171
132
|
},
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
minHeight: '200px',
|
|
175
|
-
borderRadius: '12px'
|
|
133
|
+
to: {
|
|
134
|
+
opacity: 1
|
|
176
135
|
}
|
|
177
136
|
},
|
|
178
|
-
// SVG 渲染优化样式
|
|
179
137
|
'& svg': {
|
|
180
|
-
// 节点样式
|
|
181
138
|
'& .node': {
|
|
182
139
|
'& rect, & circle, & ellipse, & polygon': {
|
|
183
140
|
stroke: '#333',
|
|
@@ -185,37 +142,27 @@ var genStyle = function genStyle(token) {
|
|
|
185
142
|
fill: '#fff'
|
|
186
143
|
}
|
|
187
144
|
},
|
|
188
|
-
// 强制设置所有文字样式
|
|
189
145
|
'& text': {
|
|
190
|
-
// 确保文字不会被裁剪
|
|
191
146
|
dominantBaseline: 'middle',
|
|
192
147
|
textAnchor: 'middle'
|
|
193
148
|
},
|
|
194
|
-
// 节点标签 - 更大的字体
|
|
195
149
|
'& .nodeLabel': {
|
|
196
150
|
fontWeight: 500,
|
|
197
151
|
fill: '#333 !important'
|
|
198
152
|
},
|
|
199
|
-
// 边标签 - 稍小一些但仍然清晰
|
|
200
153
|
'& .edgeLabel': {
|
|
201
154
|
fill: '#666 !important'
|
|
202
155
|
},
|
|
203
|
-
// 专门针对流程图的文字
|
|
204
156
|
'& .flowchart-label': {
|
|
205
157
|
fill: '#333 !important'
|
|
206
158
|
},
|
|
207
|
-
// 针对不同类型的标签
|
|
208
159
|
'& .label': {
|
|
209
160
|
fill: '#333 !important'
|
|
210
161
|
}
|
|
211
162
|
}
|
|
212
163
|
});
|
|
213
164
|
};
|
|
214
|
-
|
|
215
|
-
* Mermaid 插件样式 Hook
|
|
216
|
-
* @param prefixCls - 样式类名前缀
|
|
217
|
-
* @returns 样式相关的 wrapSSR 和 hashId
|
|
218
|
-
*/ export function useStyle(prefixCls) {
|
|
165
|
+
export function useStyle(prefixCls) {
|
|
219
166
|
return useEditorStyleRegister('agentic-plugin-mermaid', function(token) {
|
|
220
167
|
var editorToken = _object_spread_props(_object_spread({}, token), {
|
|
221
168
|
componentCls: ".".concat(prefixCls)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ant-design/agentic-ui",
|
|
3
|
-
"version": "2.30.
|
|
3
|
+
"version": "2.30.10",
|
|
4
4
|
"description": "面向智能体的 UI 组件库,提供多步推理可视化、工具调用展示、任务执行协同等 Agentic UI 能力",
|
|
5
5
|
"repository": "git@github.com:ant-design/agentic-ui.git",
|
|
6
6
|
"license": "MIT",
|
|
@@ -91,10 +91,10 @@
|
|
|
91
91
|
"lodash-es": "^4.17.23",
|
|
92
92
|
"lottie-react": "^2.4.1",
|
|
93
93
|
"markdown-it": "^14.1.1",
|
|
94
|
-
"mdast-util-directive": "^3.1.0",
|
|
95
|
-
"micromark-extension-directive": "^4.0.0",
|
|
96
94
|
"markdown-it-container": "^4.0.0",
|
|
95
|
+
"mdast-util-directive": "^3.1.0",
|
|
97
96
|
"mermaid": "^11.12.2",
|
|
97
|
+
"micromark-extension-directive": "^4.0.0",
|
|
98
98
|
"mustache": "^4.2.0",
|
|
99
99
|
"nanoid": "^5.1.6",
|
|
100
100
|
"partial-json": "^0.1.7",
|