@ant-design/agentic-ui 2.30.21 → 2.30.22
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/Bubble/MessagesContent/MarkdownPreview.js +6 -5
- package/dist/Bubble/OpenAIMessageBubble/index.d.ts +11 -0
- package/dist/Bubble/OpenAIMessageBubble/index.js +8 -0
- package/dist/Bubble/OpenAIMessageBubble/mapOllamaMessages.d.ts +7 -0
- package/dist/Bubble/OpenAIMessageBubble/mapOllamaMessages.js +136 -0
- package/dist/Bubble/OpenAIMessageBubble/mapOpenAIMessages.d.ts +8 -0
- package/dist/Bubble/OpenAIMessageBubble/mapOpenAIMessages.js +156 -0
- package/dist/Bubble/OpenAIMessageBubble/mapOpenClawMessages.d.ts +8 -0
- package/dist/Bubble/OpenAIMessageBubble/mapOpenClawMessages.js +127 -0
- package/dist/Bubble/OpenAIMessageBubble/normalizeOllamaMessages.d.ts +16 -0
- package/dist/Bubble/OpenAIMessageBubble/normalizeOllamaMessages.js +110 -0
- package/dist/Bubble/OpenAIMessageBubble/normalizeOpenClawMessages.d.ts +10 -0
- package/dist/Bubble/OpenAIMessageBubble/normalizeOpenClawMessages.js +61 -0
- package/dist/Bubble/OpenAIMessageBubble/ollamaTypes.d.ts +48 -0
- package/dist/Bubble/OpenAIMessageBubble/ollamaTypes.js +1 -0
- package/dist/Bubble/OpenAIMessageBubble/openClawTypes.d.ts +27 -0
- package/dist/Bubble/OpenAIMessageBubble/openClawTypes.js +1 -0
- package/dist/Bubble/OpenAIMessageBubble/types.d.ts +71 -0
- package/dist/Bubble/OpenAIMessageBubble/types.js +1 -0
- package/dist/Bubble/OpenAIMessageBubble/useOllamaMessageBubbleData.d.ts +7 -0
- package/dist/Bubble/OpenAIMessageBubble/useOllamaMessageBubbleData.js +23 -0
- package/dist/Bubble/OpenAIMessageBubble/useOpenAIMessageBubbleData.d.ts +6 -0
- package/dist/Bubble/OpenAIMessageBubble/useOpenAIMessageBubbleData.js +20 -0
- package/dist/Bubble/OpenAIMessageBubble/useOpenClawMessageBubbleData.d.ts +7 -0
- package/dist/Bubble/OpenAIMessageBubble/useOpenClawMessageBubbleData.js +22 -0
- package/dist/Bubble/index.d.ts +2 -0
- package/dist/Bubble/index.js +1 -0
- package/dist/MarkdownEditor/editor/Editor.js +24 -12
- package/dist/MarkdownEditor/editor/elements/Table/SimpleTable.js +5 -1
- package/dist/MarkdownEditor/editor/elements/Table/commands/tableCommands.js +24 -8
- package/dist/MarkdownEditor/editor/elements/index.js +18 -14
- package/dist/MarkdownEditor/editor/store.d.ts +12 -0
- package/dist/MarkdownEditor/editor/store.js +30 -5
- package/dist/MarkdownEditor/editor/tools/InsertAutocomplete.js +15 -11
- package/dist/MarkdownInputField/AttachmentButton/AttachmentFileList/AttachmentFileListItem.d.ts +1 -1
- package/dist/MarkdownInputField/AttachmentButton/AttachmentFileList/AttachmentFileListItem.js +4 -5
- package/dist/MarkdownInputField/AttachmentButton/AttachmentFileList/index.d.ts +1 -1
- package/dist/MarkdownInputField/AttachmentButton/index.d.ts +1 -1
- package/dist/MarkdownInputField/MarkdownInputField.js +6 -1
- package/dist/MarkdownInputField/hooks/useMarkdownInputFieldHandlers.js +6 -2
- package/dist/MarkdownInputField/hooks/useMarkdownInputFieldRefs.d.ts +1 -0
- package/dist/MarkdownInputField/hooks/useMarkdownInputFieldRefs.js +36 -5
- package/dist/MarkdownInputField/utils/renderHelpers.js +5 -0
- package/dist/MarkdownRenderer/FncRefForMarkdown.d.ts +24 -0
- package/dist/MarkdownRenderer/FncRefForMarkdown.js +65 -0
- package/dist/MarkdownRenderer/MarkdownRenderer.js +24 -9
- package/dist/MarkdownRenderer/extractFootnoteDefinitions.d.ts +13 -0
- package/dist/MarkdownRenderer/extractFootnoteDefinitions.js +40 -0
- package/dist/MarkdownRenderer/markdownReactShared.d.ts +4 -1
- package/dist/MarkdownRenderer/markdownReactShared.js +20 -10
- package/dist/MarkdownRenderer/renderers/CodeRenderer.d.ts +4 -1
- package/dist/MarkdownRenderer/renderers/CodeRenderer.js +27 -3
- package/dist/MarkdownRenderer/renderers/SchemaRenderer.d.ts +2 -0
- package/dist/MarkdownRenderer/renderers/SchemaRenderer.js +33 -5
- package/dist/MarkdownRenderer/streaming/useStreamingMarkdownReact.js +2 -1
- package/dist/MarkdownRenderer/types.d.ts +5 -9
- package/dist/MarkdownRenderer/useMarkdownToReact.js +1 -1
- package/dist/Plugins/mermaid/MermaidRendererImpl.js +481 -7
- package/dist/Plugins/mermaid/style.js +71 -22
- package/dist/Plugins/mermaid/useMermaidRender.d.ts +2 -1
- package/dist/Plugins/mermaid/useMermaidRender.js +41 -13
- package/dist/Plugins/mermaid/utils.d.ts +16 -0
- package/dist/Plugins/mermaid/utils.js +197 -5
- package/dist/Workspace/Browser/index.js +19 -1
- package/package.json +8 -7
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { useMemo } from "react";
|
|
2
2
|
import partialParse from "../../MarkdownEditor/editor/parser/json-parse";
|
|
3
3
|
import { SchemaRenderer } from "../../Schema";
|
|
4
|
+
import { debugInfo } from "../../Utils/debugUtils";
|
|
4
5
|
var extractTextContent = function extractTextContent1(children) {
|
|
5
6
|
var _children_props;
|
|
6
7
|
if (typeof children === 'string') return children;
|
|
@@ -34,15 +35,38 @@ var extractTextContent = function extractTextContent1(children) {
|
|
|
34
35
|
* - ```apassify → 同 apaasify(兼容旧版)
|
|
35
36
|
* - ```agentar-card → SchemaRenderer
|
|
36
37
|
*/ export var SchemaBlockRenderer = function SchemaBlockRenderer(props) {
|
|
37
|
-
var children = props.children, language = props.language, apaasifyRender = props.apaasifyRender;
|
|
38
|
+
var children = props.children, language = props.language, apaasifyRender = props.apaasifyRender, editorCodeProps = props.editorCodeProps;
|
|
38
39
|
var code = extractTextContent(children);
|
|
39
40
|
var schemaValue = useMemo(function() {
|
|
40
41
|
return parseSchemaValue(code);
|
|
41
42
|
}, [
|
|
42
43
|
code
|
|
43
44
|
]);
|
|
45
|
+
var applyCodeRender = function applyCodeRender(defaultDom, valueForElement) {
|
|
46
|
+
var customRender = editorCodeProps === null || editorCodeProps === void 0 ? void 0 : editorCodeProps.render;
|
|
47
|
+
if (!customRender) return defaultDom;
|
|
48
|
+
var slateLike = {
|
|
49
|
+
attributes: {},
|
|
50
|
+
children: null,
|
|
51
|
+
element: {
|
|
52
|
+
type: language === 'agentar-card' ? 'card' : 'schema',
|
|
53
|
+
value: valueForElement,
|
|
54
|
+
language: language
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
try {
|
|
58
|
+
var rendered = customRender(slateLike, defaultDom, editorCodeProps);
|
|
59
|
+
if (rendered === undefined) return defaultDom;
|
|
60
|
+
return rendered;
|
|
61
|
+
} catch (error) {
|
|
62
|
+
debugInfo('SchemaBlockRenderer - codeProps.render 异常,回退默认', {
|
|
63
|
+
error: (error === null || error === void 0 ? void 0 : error.message) || String(error)
|
|
64
|
+
});
|
|
65
|
+
return defaultDom;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
44
68
|
if (!schemaValue) {
|
|
45
|
-
|
|
69
|
+
var fallbackDom = /*#__PURE__*/ React.createElement("pre", {
|
|
46
70
|
"data-testid": "schema-fallback",
|
|
47
71
|
style: {
|
|
48
72
|
background: 'rgb(242, 241, 241)',
|
|
@@ -59,11 +83,12 @@ var extractTextContent = function extractTextContent1(children) {
|
|
|
59
83
|
wordWrap: 'break-word'
|
|
60
84
|
}
|
|
61
85
|
}, /*#__PURE__*/ React.createElement("code", null, code));
|
|
86
|
+
return applyCodeRender(fallbackDom, code);
|
|
62
87
|
}
|
|
63
88
|
if (apaasifyRender) {
|
|
64
89
|
var rendered = apaasifyRender(schemaValue);
|
|
65
90
|
if (rendered !== undefined) {
|
|
66
|
-
|
|
91
|
+
var apaasifyDom = /*#__PURE__*/ React.createElement("div", {
|
|
67
92
|
"data-testid": "schema-container",
|
|
68
93
|
contentEditable: false,
|
|
69
94
|
style: {
|
|
@@ -82,10 +107,11 @@ var extractTextContent = function extractTextContent1(children) {
|
|
|
82
107
|
overflow: 'hidden'
|
|
83
108
|
}
|
|
84
109
|
}, JSON.stringify(schemaValue, null, 2)));
|
|
110
|
+
return applyCodeRender(apaasifyDom, schemaValue);
|
|
85
111
|
}
|
|
86
112
|
}
|
|
87
113
|
if (language === 'agentar-card') {
|
|
88
|
-
|
|
114
|
+
var cardDom = /*#__PURE__*/ React.createElement("div", {
|
|
89
115
|
"data-testid": "agentar-card-container",
|
|
90
116
|
style: {
|
|
91
117
|
padding: '0.5em'
|
|
@@ -98,8 +124,9 @@ var extractTextContent = function extractTextContent1(children) {
|
|
|
98
124
|
debug: false,
|
|
99
125
|
fallbackContent: null
|
|
100
126
|
}));
|
|
127
|
+
return applyCodeRender(cardDom, schemaValue);
|
|
101
128
|
}
|
|
102
|
-
|
|
129
|
+
var schemaDom = /*#__PURE__*/ React.createElement("div", {
|
|
103
130
|
"data-testid": "schema-renderer",
|
|
104
131
|
style: {
|
|
105
132
|
padding: '0.5em'
|
|
@@ -111,5 +138,6 @@ var extractTextContent = function extractTextContent1(children) {
|
|
|
111
138
|
debug: false,
|
|
112
139
|
fallbackContent: null
|
|
113
140
|
}));
|
|
141
|
+
return applyCodeRender(schemaDom, schemaValue);
|
|
114
142
|
};
|
|
115
143
|
SchemaBlockRenderer.displayName = 'SchemaBlockRenderer';
|
|
@@ -18,12 +18,13 @@ 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, options === null || options === void 0 ? void 0 : options.eleRender);
|
|
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.fncProps, 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.fncProps,
|
|
27
28
|
options === null || options === void 0 ? void 0 : options.streamingParagraphAnimation,
|
|
28
29
|
options === null || options === void 0 ? void 0 : options.eleRender
|
|
29
30
|
]);
|
|
@@ -1,6 +1,7 @@
|
|
|
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
|
+
import type { MarkdownEditorProps } from '../MarkdownEditor/types';
|
|
4
5
|
import type { AttachmentFile } from '../MarkdownInputField/AttachmentButton/types';
|
|
5
6
|
import type { FileMapViewProps } from '../MarkdownInputField/FileMapView';
|
|
6
7
|
/**
|
|
@@ -103,15 +104,10 @@ export interface MarkdownRendererProps {
|
|
|
103
104
|
style?: React.CSSProperties;
|
|
104
105
|
/** 类名前缀 */
|
|
105
106
|
prefixCls?: string;
|
|
106
|
-
/**
|
|
107
|
-
codeProps?:
|
|
108
|
-
/**
|
|
109
|
-
fncProps?:
|
|
110
|
-
render?: (props: Record<string, any> & {
|
|
111
|
-
children: React.ReactNode;
|
|
112
|
-
}, defaultDom: React.ReactNode) => React.ReactNode;
|
|
113
|
-
onFootnoteDefinitionChange?: (data: any[]) => void;
|
|
114
|
-
};
|
|
107
|
+
/** 代码块配置,与 MarkdownEditor `codeProps` 对齐(含 `render` 覆盖) */
|
|
108
|
+
codeProps?: MarkdownEditorProps['codeProps'];
|
|
109
|
+
/** 脚注配置,与 MarkdownEditor `fncProps` 对齐 */
|
|
110
|
+
fncProps?: MarkdownEditorProps['fncProps'];
|
|
115
111
|
/** 链接配置 */
|
|
116
112
|
linkConfig?: {
|
|
117
113
|
/** 是否在新标签页打开链接,默认 true */
|
|
@@ -14,7 +14,7 @@ export var useMarkdownToReact = useStreamingMarkdownReact;
|
|
|
14
14
|
var mdast = processor.parse(preprocessed);
|
|
15
15
|
var hast = processor.runSync(mdast);
|
|
16
16
|
var userComps = components || {};
|
|
17
|
-
var allComponents = buildEditorAlignedComponents('ant-agentic-md-editor', userComps, false, undefined, false);
|
|
17
|
+
var allComponents = buildEditorAlignedComponents('ant-agentic-md-editor', userComps, false, undefined, undefined, false);
|
|
18
18
|
return toJsxRuntime(hast, {
|
|
19
19
|
Fragment: Fragment,
|
|
20
20
|
jsx: jsx,
|
|
@@ -1,25 +1,205 @@
|
|
|
1
|
-
|
|
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 _define_property(obj, key, value) {
|
|
10
|
+
if (key in obj) {
|
|
11
|
+
Object.defineProperty(obj, key, {
|
|
12
|
+
value: value,
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true
|
|
16
|
+
});
|
|
17
|
+
} else {
|
|
18
|
+
obj[key] = value;
|
|
19
|
+
}
|
|
20
|
+
return obj;
|
|
21
|
+
}
|
|
22
|
+
function _iterable_to_array_limit(arr, i) {
|
|
23
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
24
|
+
if (_i == null) return;
|
|
25
|
+
var _arr = [];
|
|
26
|
+
var _n = true;
|
|
27
|
+
var _d = false;
|
|
28
|
+
var _s, _e;
|
|
29
|
+
try {
|
|
30
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
31
|
+
_arr.push(_s.value);
|
|
32
|
+
if (i && _arr.length === i) break;
|
|
33
|
+
}
|
|
34
|
+
} catch (err) {
|
|
35
|
+
_d = true;
|
|
36
|
+
_e = err;
|
|
37
|
+
} finally{
|
|
38
|
+
try {
|
|
39
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
40
|
+
} finally{
|
|
41
|
+
if (_d) throw _e;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return _arr;
|
|
45
|
+
}
|
|
46
|
+
function _non_iterable_rest() {
|
|
47
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
48
|
+
}
|
|
49
|
+
function _object_spread(target) {
|
|
50
|
+
for(var i = 1; i < arguments.length; i++){
|
|
51
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
52
|
+
var ownKeys = Object.keys(source);
|
|
53
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
54
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
55
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
ownKeys.forEach(function(key) {
|
|
59
|
+
_define_property(target, key, source[key]);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return target;
|
|
63
|
+
}
|
|
64
|
+
function ownKeys(object, enumerableOnly) {
|
|
65
|
+
var keys = Object.keys(object);
|
|
66
|
+
if (Object.getOwnPropertySymbols) {
|
|
67
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
68
|
+
if (enumerableOnly) {
|
|
69
|
+
symbols = symbols.filter(function(sym) {
|
|
70
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
keys.push.apply(keys, symbols);
|
|
74
|
+
}
|
|
75
|
+
return keys;
|
|
76
|
+
}
|
|
77
|
+
function _object_spread_props(target, source) {
|
|
78
|
+
source = source != null ? source : {};
|
|
79
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
80
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
81
|
+
} else {
|
|
82
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
83
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return target;
|
|
87
|
+
}
|
|
88
|
+
function _sliced_to_array(arr, i) {
|
|
89
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
90
|
+
}
|
|
91
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
92
|
+
if (!o) return;
|
|
93
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
94
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
95
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
96
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
97
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
98
|
+
}
|
|
99
|
+
import { BorderOutlined, ExpandOutlined, FullscreenExitOutlined, FullscreenOutlined, ZoomInOutlined, ZoomOutOutlined } from "@ant-design/icons";
|
|
100
|
+
import { ConfigProvider, theme } from "antd";
|
|
2
101
|
import classNames from "clsx";
|
|
3
|
-
import React, { useContext, useMemo, useRef } from "react";
|
|
102
|
+
import React, { useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
103
|
+
import { ActionIconBox } from "../../Components/ActionIconBox";
|
|
4
104
|
import { useIntersectionOnce } from "../../Hooks/useIntersectionOnce";
|
|
5
105
|
import { useStyle } from "./style";
|
|
6
106
|
import { useMermaidRender } from "./useMermaidRender";
|
|
107
|
+
import { createMermaidThemeConfig } from "./utils";
|
|
7
108
|
var PRE_STYLE = {
|
|
8
109
|
margin: 0,
|
|
9
110
|
whiteSpace: 'pre-wrap',
|
|
10
111
|
wordBreak: 'break-word'
|
|
11
112
|
};
|
|
113
|
+
var MIN_ZOOM_SCALE = 0.2;
|
|
114
|
+
var MAX_ZOOM_SCALE = 12;
|
|
115
|
+
var ZOOM_STEP_RATIO = 1.2;
|
|
116
|
+
var FIT_PADDING = 24;
|
|
117
|
+
var clamp = function clamp(value, min, max) {
|
|
118
|
+
return Math.max(min, Math.min(max, value));
|
|
119
|
+
};
|
|
120
|
+
var getSvgNaturalSize = function getSvgNaturalSize(svgElement) {
|
|
121
|
+
var _svgElement_viewBox;
|
|
122
|
+
var viewBox = (_svgElement_viewBox = svgElement.viewBox) === null || _svgElement_viewBox === void 0 ? void 0 : _svgElement_viewBox.baseVal;
|
|
123
|
+
if (viewBox && viewBox.width > 0 && viewBox.height > 0) {
|
|
124
|
+
return {
|
|
125
|
+
width: viewBox.width,
|
|
126
|
+
height: viewBox.height
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
var widthAttr = Number.parseFloat(svgElement.getAttribute('width') || '');
|
|
130
|
+
var heightAttr = Number.parseFloat(svgElement.getAttribute('height') || '');
|
|
131
|
+
if (Number.isFinite(widthAttr) && Number.isFinite(heightAttr) && widthAttr > 0 && heightAttr > 0) {
|
|
132
|
+
return {
|
|
133
|
+
width: widthAttr,
|
|
134
|
+
height: heightAttr
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
try {
|
|
138
|
+
var bbox = svgElement.getBBox();
|
|
139
|
+
if (bbox.width > 0 && bbox.height > 0) {
|
|
140
|
+
return {
|
|
141
|
+
width: bbox.width,
|
|
142
|
+
height: bbox.height
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
} catch (e) {
|
|
146
|
+
// Ignore getBBox errors in hidden/unsupported SVG contexts.
|
|
147
|
+
}
|
|
148
|
+
var rect = svgElement.getBoundingClientRect();
|
|
149
|
+
if (rect.width > 0 && rect.height > 0) {
|
|
150
|
+
return {
|
|
151
|
+
width: rect.width,
|
|
152
|
+
height: rect.height
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
return null;
|
|
156
|
+
};
|
|
12
157
|
export var MermaidRendererImpl = function MermaidRendererImpl(props) {
|
|
13
158
|
var context = useContext(ConfigProvider.ConfigContext);
|
|
159
|
+
var token = theme.useToken().token;
|
|
14
160
|
var baseCls = (context === null || context === void 0 ? void 0 : context.getPrefixCls('agentic-plugin-mermaid')) || 'plugin-mermaid';
|
|
15
161
|
var _useStyle = useStyle(baseCls), wrapSSR = _useStyle.wrapSSR, hashId = _useStyle.hashId;
|
|
16
162
|
var containerRef = useRef(null);
|
|
17
163
|
var divRef = useRef(null);
|
|
164
|
+
var panSessionRef = useRef(null);
|
|
18
165
|
var id = useMemo(function() {
|
|
19
166
|
return 'm' + (Date.now() + Math.ceil(Math.random() * 1000));
|
|
20
167
|
}, []);
|
|
168
|
+
var _useState = _sliced_to_array(useState(1), 2), scale = _useState[0], setScale = _useState[1];
|
|
169
|
+
var _useState1 = _sliced_to_array(useState(0), 2), panX = _useState1[0], setPanX = _useState1[1];
|
|
170
|
+
var _useState2 = _sliced_to_array(useState(0), 2), panY = _useState2[0], setPanY = _useState2[1];
|
|
171
|
+
var _useState3 = _sliced_to_array(useState(true), 2), showGrid = _useState3[0], setShowGrid = _useState3[1];
|
|
172
|
+
var _useState4 = _sliced_to_array(useState(false), 2), isPanning = _useState4[0], setIsPanning = _useState4[1];
|
|
173
|
+
var _useState5 = _sliced_to_array(useState(false), 2), isFullscreen = _useState5[0], setIsFullscreen = _useState5[1];
|
|
174
|
+
var mermaidTheme = useMemo(function() {
|
|
175
|
+
return createMermaidThemeConfig({
|
|
176
|
+
colorBgContainer: token.colorBgContainer,
|
|
177
|
+
colorBgElevated: token.colorBgElevated,
|
|
178
|
+
colorText: token.colorText,
|
|
179
|
+
colorTextSecondary: token.colorTextSecondary,
|
|
180
|
+
colorBorder: token.colorBorder,
|
|
181
|
+
colorPrimary: token.colorPrimary,
|
|
182
|
+
fontFamily: token.fontFamily
|
|
183
|
+
});
|
|
184
|
+
}, [
|
|
185
|
+
token.colorBgContainer,
|
|
186
|
+
token.colorBgElevated,
|
|
187
|
+
token.colorText,
|
|
188
|
+
token.colorTextSecondary,
|
|
189
|
+
token.colorBorder,
|
|
190
|
+
token.colorPrimary,
|
|
191
|
+
token.fontFamily
|
|
192
|
+
]);
|
|
21
193
|
var isVisible = useIntersectionOnce(containerRef);
|
|
22
|
-
var _useMermaidRender = useMermaidRender(props.element.value || '', divRef, id, isVisible
|
|
194
|
+
var _useMermaidRender = useMermaidRender(props.element.value || '', divRef, id, isVisible, {
|
|
195
|
+
colorBgContainer: token.colorBgContainer,
|
|
196
|
+
colorBgElevated: token.colorBgElevated,
|
|
197
|
+
colorText: token.colorText,
|
|
198
|
+
colorTextSecondary: token.colorTextSecondary,
|
|
199
|
+
colorBorder: token.colorBorder,
|
|
200
|
+
colorPrimary: token.colorPrimary,
|
|
201
|
+
fontFamily: token.fontFamily
|
|
202
|
+
}), error = _useMermaidRender.error, renderedCode = _useMermaidRender.renderedCode;
|
|
23
203
|
var isError = useMemo(function() {
|
|
24
204
|
return !!error && !!error.trim();
|
|
25
205
|
}, [
|
|
@@ -44,18 +224,312 @@ export var MermaidRendererImpl = function MermaidRendererImpl(props) {
|
|
|
44
224
|
}, [
|
|
45
225
|
isRendered
|
|
46
226
|
]);
|
|
227
|
+
var transformedContainerStyle = useMemo(function() {
|
|
228
|
+
return _object_spread_props(_object_spread({}, containerStyle), {
|
|
229
|
+
'--mermaid-pan-x': "".concat(panX, "px"),
|
|
230
|
+
'--mermaid-pan-y': "".concat(panY, "px"),
|
|
231
|
+
'--mermaid-scale': scale
|
|
232
|
+
});
|
|
233
|
+
}, [
|
|
234
|
+
containerStyle,
|
|
235
|
+
panX,
|
|
236
|
+
panY,
|
|
237
|
+
scale
|
|
238
|
+
]);
|
|
239
|
+
var viewportStyle = useMemo(function() {
|
|
240
|
+
return {
|
|
241
|
+
backgroundImage: showGrid ? mermaidTheme.darkMode ? 'radial-gradient(circle, rgba(255, 255, 255, 0.14) 1.2px, transparent 1.2px)' : 'radial-gradient(circle, rgba(0, 0, 0, 0.08) 1.2px, transparent 1.2px)' : 'none'
|
|
242
|
+
};
|
|
243
|
+
}, [
|
|
244
|
+
mermaidTheme.darkMode,
|
|
245
|
+
showGrid
|
|
246
|
+
]);
|
|
247
|
+
var getDiagramAndViewportSize = useCallback(function() {
|
|
248
|
+
var viewportElement = divRef.current;
|
|
249
|
+
if (!viewportElement) {
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
var svgElement = viewportElement.querySelector('[data-mermaid-svg="true"]');
|
|
253
|
+
if (!svgElement) {
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
var svgSize = getSvgNaturalSize(svgElement);
|
|
257
|
+
if (!svgSize) {
|
|
258
|
+
return null;
|
|
259
|
+
}
|
|
260
|
+
var viewportWidth = viewportElement.clientWidth;
|
|
261
|
+
var viewportHeight = viewportElement.clientHeight;
|
|
262
|
+
if (viewportWidth <= 0 || viewportHeight <= 0) {
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
return {
|
|
266
|
+
viewportWidth: viewportWidth,
|
|
267
|
+
viewportHeight: viewportHeight,
|
|
268
|
+
diagramWidth: svgSize.width,
|
|
269
|
+
diagramHeight: svgSize.height
|
|
270
|
+
};
|
|
271
|
+
}, []);
|
|
272
|
+
var handleFitToScreen = useCallback(function() {
|
|
273
|
+
var size = getDiagramAndViewportSize();
|
|
274
|
+
if (!size) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
var usableWidth = Math.max(size.viewportWidth - FIT_PADDING * 2, 1);
|
|
278
|
+
var usableHeight = Math.max(size.viewportHeight - FIT_PADDING * 2, 1);
|
|
279
|
+
var fittedScale = clamp(Math.min(usableWidth / size.diagramWidth, usableHeight / size.diagramHeight), MIN_ZOOM_SCALE, MAX_ZOOM_SCALE);
|
|
280
|
+
var centeredPanX = (size.viewportWidth - size.diagramWidth * fittedScale) / 2;
|
|
281
|
+
var centeredPanY = (size.viewportHeight - size.diagramHeight * fittedScale) / 2;
|
|
282
|
+
setScale(fittedScale);
|
|
283
|
+
setPanX(centeredPanX);
|
|
284
|
+
setPanY(centeredPanY);
|
|
285
|
+
}, [
|
|
286
|
+
getDiagramAndViewportSize
|
|
287
|
+
]);
|
|
288
|
+
var applyScaleAtPoint = useCallback(function(nextScale, clientX, clientY) {
|
|
289
|
+
var viewportElement = divRef.current;
|
|
290
|
+
if (!viewportElement) {
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
var clampedScale = clamp(nextScale, MIN_ZOOM_SCALE, MAX_ZOOM_SCALE);
|
|
294
|
+
if (clampedScale === scale) {
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
var viewportRect = viewportElement.getBoundingClientRect();
|
|
298
|
+
var targetClientX = clientX !== null && clientX !== void 0 ? clientX : viewportRect.left + viewportRect.width / 2;
|
|
299
|
+
var targetClientY = clientY !== null && clientY !== void 0 ? clientY : viewportRect.top + viewportRect.height / 2;
|
|
300
|
+
var relativeX = targetClientX - viewportRect.left;
|
|
301
|
+
var relativeY = targetClientY - viewportRect.top;
|
|
302
|
+
var nextPanX = relativeX - (relativeX - panX) / scale * clampedScale;
|
|
303
|
+
var nextPanY = relativeY - (relativeY - panY) / scale * clampedScale;
|
|
304
|
+
setScale(clampedScale);
|
|
305
|
+
setPanX(nextPanX);
|
|
306
|
+
setPanY(nextPanY);
|
|
307
|
+
}, [
|
|
308
|
+
panX,
|
|
309
|
+
panY,
|
|
310
|
+
scale
|
|
311
|
+
]);
|
|
312
|
+
var handleZoomIn = useCallback(function() {
|
|
313
|
+
applyScaleAtPoint(scale * ZOOM_STEP_RATIO);
|
|
314
|
+
}, [
|
|
315
|
+
applyScaleAtPoint,
|
|
316
|
+
scale
|
|
317
|
+
]);
|
|
318
|
+
var handleZoomOut = useCallback(function() {
|
|
319
|
+
applyScaleAtPoint(scale / ZOOM_STEP_RATIO);
|
|
320
|
+
}, [
|
|
321
|
+
applyScaleAtPoint,
|
|
322
|
+
scale
|
|
323
|
+
]);
|
|
324
|
+
var handleToggleFullscreen = useCallback(function() {
|
|
325
|
+
var _containerRef_current_requestFullscreen, _containerRef_current;
|
|
326
|
+
if (!containerRef.current) {
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
if (document.fullscreenElement === containerRef.current) {
|
|
330
|
+
var _document_exitFullscreen, _document;
|
|
331
|
+
(_document_exitFullscreen = (_document = document).exitFullscreen) === null || _document_exitFullscreen === void 0 ? void 0 : _document_exitFullscreen.call(_document);
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
(_containerRef_current_requestFullscreen = (_containerRef_current = containerRef.current).requestFullscreen) === null || _containerRef_current_requestFullscreen === void 0 ? void 0 : _containerRef_current_requestFullscreen.call(_containerRef_current);
|
|
335
|
+
}, []);
|
|
336
|
+
var handleWheel = useCallback(function(event) {
|
|
337
|
+
var _target_closest;
|
|
338
|
+
if (!isRendered) {
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
var target = event.target;
|
|
342
|
+
if (target === null || target === void 0 ? void 0 : (_target_closest = target.closest) === null || _target_closest === void 0 ? void 0 : _target_closest.call(target, '[data-mermaid-toolbar]')) {
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
event.preventDefault();
|
|
346
|
+
var scaleMultiplier = event.deltaY < 0 ? ZOOM_STEP_RATIO : 1 / ZOOM_STEP_RATIO;
|
|
347
|
+
applyScaleAtPoint(scale * scaleMultiplier, event.clientX, event.clientY);
|
|
348
|
+
}, [
|
|
349
|
+
applyScaleAtPoint,
|
|
350
|
+
isRendered,
|
|
351
|
+
scale
|
|
352
|
+
]);
|
|
353
|
+
var handlePointerDown = useCallback(function(event) {
|
|
354
|
+
var _target_closest, _event_currentTarget_setPointerCapture, _event_currentTarget;
|
|
355
|
+
if (!isRendered || event.button !== 0) {
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
var target = event.target;
|
|
359
|
+
if (target === null || target === void 0 ? void 0 : (_target_closest = target.closest) === null || _target_closest === void 0 ? void 0 : _target_closest.call(target, '[data-mermaid-toolbar]')) {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
panSessionRef.current = {
|
|
363
|
+
startClientX: event.clientX,
|
|
364
|
+
startClientY: event.clientY,
|
|
365
|
+
startPanX: panX,
|
|
366
|
+
startPanY: panY
|
|
367
|
+
};
|
|
368
|
+
setIsPanning(true);
|
|
369
|
+
(_event_currentTarget_setPointerCapture = (_event_currentTarget = event.currentTarget).setPointerCapture) === null || _event_currentTarget_setPointerCapture === void 0 ? void 0 : _event_currentTarget_setPointerCapture.call(_event_currentTarget, event.pointerId);
|
|
370
|
+
}, [
|
|
371
|
+
isRendered,
|
|
372
|
+
panX,
|
|
373
|
+
panY
|
|
374
|
+
]);
|
|
375
|
+
var handlePointerMove = useCallback(function(event) {
|
|
376
|
+
var panSession = panSessionRef.current;
|
|
377
|
+
if (!panSession) {
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
setPanX(panSession.startPanX + event.clientX - panSession.startClientX);
|
|
381
|
+
setPanY(panSession.startPanY + event.clientY - panSession.startClientY);
|
|
382
|
+
}, []);
|
|
383
|
+
var finishPointerSession = useCallback(function(event) {
|
|
384
|
+
var _event_currentTarget_releasePointerCapture, _event_currentTarget;
|
|
385
|
+
if (!panSessionRef.current) {
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
panSessionRef.current = null;
|
|
389
|
+
setIsPanning(false);
|
|
390
|
+
(_event_currentTarget_releasePointerCapture = (_event_currentTarget = event.currentTarget).releasePointerCapture) === null || _event_currentTarget_releasePointerCapture === void 0 ? void 0 : _event_currentTarget_releasePointerCapture.call(_event_currentTarget, event.pointerId);
|
|
391
|
+
}, []);
|
|
392
|
+
useEffect(function() {
|
|
393
|
+
var syncFullscreenState = function syncFullscreenState() {
|
|
394
|
+
setIsFullscreen(document.fullscreenElement === containerRef.current);
|
|
395
|
+
};
|
|
396
|
+
syncFullscreenState();
|
|
397
|
+
document.addEventListener('fullscreenchange', syncFullscreenState);
|
|
398
|
+
return function() {
|
|
399
|
+
document.removeEventListener('fullscreenchange', syncFullscreenState);
|
|
400
|
+
};
|
|
401
|
+
}, []);
|
|
402
|
+
useEffect(function() {
|
|
403
|
+
if (!isRendered) {
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
var frame = window.requestAnimationFrame(function() {
|
|
407
|
+
handleFitToScreen();
|
|
408
|
+
});
|
|
409
|
+
return function() {
|
|
410
|
+
window.cancelAnimationFrame(frame);
|
|
411
|
+
};
|
|
412
|
+
}, [
|
|
413
|
+
isRendered,
|
|
414
|
+
renderedCode,
|
|
415
|
+
handleFitToScreen
|
|
416
|
+
]);
|
|
417
|
+
useEffect(function() {
|
|
418
|
+
if (!isRendered || !divRef.current) {
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
if (typeof ResizeObserver === 'undefined') {
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
var resizeObserver = new ResizeObserver(function() {
|
|
425
|
+
handleFitToScreen();
|
|
426
|
+
});
|
|
427
|
+
resizeObserver.observe(divRef.current);
|
|
428
|
+
return function() {
|
|
429
|
+
resizeObserver.disconnect();
|
|
430
|
+
};
|
|
431
|
+
}, [
|
|
432
|
+
handleFitToScreen,
|
|
433
|
+
isRendered
|
|
434
|
+
]);
|
|
435
|
+
useEffect(function() {
|
|
436
|
+
if (!isRendered) {
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
handleFitToScreen();
|
|
440
|
+
}, [
|
|
441
|
+
handleFitToScreen,
|
|
442
|
+
isFullscreen,
|
|
443
|
+
isRendered
|
|
444
|
+
]);
|
|
47
445
|
var code = props.element.value || '';
|
|
48
446
|
return wrapSSR(/*#__PURE__*/ React.createElement("div", {
|
|
49
447
|
ref: containerRef,
|
|
50
|
-
className: classNames(baseCls, hashId),
|
|
51
|
-
contentEditable: false
|
|
448
|
+
className: classNames(baseCls, hashId, _define_property({}, "".concat(baseCls, "-fullscreen"), isFullscreen)),
|
|
449
|
+
contentEditable: false,
|
|
450
|
+
"data-mermaid-theme": mermaidTheme.darkMode ? 'dark' : 'light'
|
|
451
|
+
}, /*#__PURE__*/ React.createElement("div", {
|
|
452
|
+
contentEditable: false,
|
|
453
|
+
className: classNames("".concat(baseCls, "-viewport"), hashId),
|
|
454
|
+
onWheel: handleWheel,
|
|
455
|
+
onPointerDown: handlePointerDown,
|
|
456
|
+
onPointerMove: handlePointerMove,
|
|
457
|
+
onPointerUp: finishPointerSession,
|
|
458
|
+
onPointerCancel: finishPointerSession,
|
|
459
|
+
"data-mermaid-grid": showGrid,
|
|
460
|
+
"data-mermaid-panning": isPanning,
|
|
461
|
+
"data-mermaid-viewport": "true",
|
|
462
|
+
style: viewportStyle
|
|
52
463
|
}, /*#__PURE__*/ React.createElement("div", {
|
|
53
464
|
contentEditable: false,
|
|
54
465
|
ref: divRef,
|
|
55
466
|
className: classNames(hashId),
|
|
56
|
-
style:
|
|
467
|
+
style: transformedContainerStyle,
|
|
57
468
|
"data-mermaid-container": "true"
|
|
58
|
-
}),
|
|
469
|
+
}), isRendered && /*#__PURE__*/ React.createElement("div", {
|
|
470
|
+
className: classNames("".concat(baseCls, "-toolbar-float"), hashId),
|
|
471
|
+
role: "toolbar",
|
|
472
|
+
"aria-label": "Mermaid diagram controls",
|
|
473
|
+
"data-mermaid-toolbar": true,
|
|
474
|
+
onPointerDown: function onPointerDown(e) {
|
|
475
|
+
e.stopPropagation();
|
|
476
|
+
}
|
|
477
|
+
}, /*#__PURE__*/ React.createElement("span", {
|
|
478
|
+
"data-mermaid-action": "fit"
|
|
479
|
+
}, /*#__PURE__*/ React.createElement(ActionIconBox, {
|
|
480
|
+
title: "适配画布",
|
|
481
|
+
borderLess: true,
|
|
482
|
+
noPadding: true,
|
|
483
|
+
onClick: handleFitToScreen,
|
|
484
|
+
iconStyle: {
|
|
485
|
+
color: token.colorTextSecondary
|
|
486
|
+
}
|
|
487
|
+
}, /*#__PURE__*/ React.createElement(ExpandOutlined, null))), /*#__PURE__*/ React.createElement("span", {
|
|
488
|
+
"data-mermaid-action": "zoom-out"
|
|
489
|
+
}, /*#__PURE__*/ React.createElement(ActionIconBox, {
|
|
490
|
+
title: "缩小",
|
|
491
|
+
borderLess: true,
|
|
492
|
+
noPadding: true,
|
|
493
|
+
onClick: handleZoomOut,
|
|
494
|
+
iconStyle: {
|
|
495
|
+
color: token.colorTextSecondary
|
|
496
|
+
}
|
|
497
|
+
}, /*#__PURE__*/ React.createElement(ZoomOutOutlined, null))), /*#__PURE__*/ React.createElement("span", {
|
|
498
|
+
"data-mermaid-action": "zoom-in"
|
|
499
|
+
}, /*#__PURE__*/ React.createElement(ActionIconBox, {
|
|
500
|
+
title: "放大",
|
|
501
|
+
borderLess: true,
|
|
502
|
+
noPadding: true,
|
|
503
|
+
onClick: handleZoomIn,
|
|
504
|
+
iconStyle: {
|
|
505
|
+
color: token.colorTextSecondary
|
|
506
|
+
}
|
|
507
|
+
}, /*#__PURE__*/ React.createElement(ZoomInOutlined, null))), /*#__PURE__*/ React.createElement("span", {
|
|
508
|
+
"data-mermaid-action": "grid"
|
|
509
|
+
}, /*#__PURE__*/ React.createElement(ActionIconBox, {
|
|
510
|
+
title: showGrid ? '隐藏背景网格' : '显示背景网格',
|
|
511
|
+
borderLess: true,
|
|
512
|
+
noPadding: true,
|
|
513
|
+
active: showGrid,
|
|
514
|
+
onClick: function onClick() {
|
|
515
|
+
setShowGrid(function(prev) {
|
|
516
|
+
return !prev;
|
|
517
|
+
});
|
|
518
|
+
},
|
|
519
|
+
iconStyle: {
|
|
520
|
+
color: token.colorTextSecondary
|
|
521
|
+
}
|
|
522
|
+
}, /*#__PURE__*/ React.createElement(BorderOutlined, null))), /*#__PURE__*/ React.createElement("span", {
|
|
523
|
+
"data-mermaid-action": "fullscreen"
|
|
524
|
+
}, /*#__PURE__*/ React.createElement(ActionIconBox, {
|
|
525
|
+
title: isFullscreen ? '退出全屏' : '全屏',
|
|
526
|
+
borderLess: true,
|
|
527
|
+
noPadding: true,
|
|
528
|
+
onClick: handleToggleFullscreen,
|
|
529
|
+
iconStyle: {
|
|
530
|
+
color: token.colorTextSecondary
|
|
531
|
+
}
|
|
532
|
+
}, isFullscreen ? /*#__PURE__*/ React.createElement(FullscreenExitOutlined, null) : /*#__PURE__*/ React.createElement(FullscreenOutlined, null))))), error && /*#__PURE__*/ React.createElement("div", {
|
|
59
533
|
className: classNames("".concat(baseCls, "-error"), hashId)
|
|
60
534
|
}, /*#__PURE__*/ React.createElement("pre", {
|
|
61
535
|
style: PRE_STYLE
|