@ctzhian/tiptap 2.7.5 → 2.9.0
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/Editor/demo.js +1 -1
- package/dist/EditorMarkdown/Toolbar.js +15 -15
- package/dist/asset/css/index.css +17 -12
- package/dist/component/CustomBubbleMenu/TooltipInputPopover.d.ts +11 -0
- package/dist/component/CustomBubbleMenu/TooltipInputPopover.js +80 -0
- package/dist/component/CustomBubbleMenu/index.js +39 -36
- package/dist/component/CustomDragHandle/index.js +65 -18
- package/dist/component/Icons/index.d.ts +1 -0
- package/dist/component/Icons/index.js +1 -0
- package/dist/component/Icons/tooltip-line-icon.d.ts +6 -0
- package/dist/component/Icons/tooltip-line-icon.js +13 -0
- package/dist/component/Toolbar/EditorInsert/index.js +1 -1
- package/dist/contants/slash-commands.js +1 -1
- package/dist/extension/component/CodeBlock/index.js +18 -5
- package/dist/extension/component/Flow/FlowDiagram.d.ts +7 -0
- package/dist/extension/component/Flow/FlowDiagram.js +52 -0
- package/dist/extension/component/Flow/Insert.js +1 -1
- package/dist/extension/component/Flow/Readonly.js +6 -2
- package/dist/extension/component/Flow/index.d.ts +1 -0
- package/dist/extension/component/Flow/index.js +133 -68
- package/dist/extension/component/Flow/useMermaidRender.js +2 -2
- package/dist/extension/component/Flow/utils.d.ts +10 -1
- package/dist/extension/component/Flow/utils.js +45 -10
- package/dist/extension/component/Image/index.js +57 -46
- package/dist/extension/component/Tooltip/index.d.ts +4 -0
- package/dist/extension/component/Tooltip/index.js +19 -0
- package/dist/extension/index.d.ts +1 -1
- package/dist/extension/index.js +6 -7
- package/dist/extension/mark/Tooltip.d.ts +24 -0
- package/dist/extension/mark/Tooltip.js +141 -0
- package/dist/extension/node/Flow/index.d.ts +8 -1
- package/dist/extension/node/Flow/index.js +41 -4
- package/dist/index.css +1 -1
- package/dist/themes/index.d.ts +1 -1
- package/dist/type/index.d.ts +2 -0
- package/package.json +2 -2
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
import { SvgIcon } from "@mui/material";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
export var TooltipLineIcon = function TooltipLineIcon(props) {
|
|
5
|
+
return /*#__PURE__*/React.createElement(SvgIcon, _extends({
|
|
6
|
+
viewBox: "0 0 24 24",
|
|
7
|
+
version: "1.1",
|
|
8
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
9
|
+
}, props), /*#__PURE__*/React.createElement("path", {
|
|
10
|
+
d: "M14.45 19L12 22.5L9.55 19H3C2.73478 19 2.48043 18.8946 2.29289 18.7071C2.10536 18.5196 2 18.2652 2 18V4C2 3.73478 2.10536 3.48043 2.29289 3.29289C2.48043 3.10536 2.73478 3 3 3H21C21.2652 3 21.5196 3.10536 21.7071 3.29289C21.8946 3.48043 22 3.73478 22 4V18C22 18.2652 21.8946 18.5196 21.7071 18.7071C21.5196 18.8946 21.2652 19 21 19H14.45ZM13.409 17H20V5H4V17H10.591L12 19.012L13.409 17Z"
|
|
11
|
+
}));
|
|
12
|
+
};
|
|
13
|
+
TooltipLineIcon.displayName = 'icon-tooltip-line';
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
2
|
var _excluded = ["className"];
|
|
3
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
3
8
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
4
9
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
5
10
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
@@ -12,7 +17,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
12
17
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
13
18
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
14
19
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
15
|
-
import { ArrowDownSLineIcon, FileCopyLineIcon } from "../../../component/Icons";
|
|
20
|
+
import { ArrowDownSLineIcon, CheckboxCircleLineIcon, FileCopyLineIcon } from "../../../component/Icons";
|
|
16
21
|
import { languages } from "../../../contants/highlight";
|
|
17
22
|
import { Box, Divider, ListSubheader, MenuItem, Select, Stack, TextField } from '@mui/material';
|
|
18
23
|
import { NodeViewContent, NodeViewWrapper } from '@tiptap/react';
|
|
@@ -144,7 +149,8 @@ var CodeBlockView = function CodeBlockView(props) {
|
|
|
144
149
|
right: 0,
|
|
145
150
|
height: '1.25rem',
|
|
146
151
|
lineHeight: '1.25rem',
|
|
147
|
-
|
|
152
|
+
pl: 2.5,
|
|
153
|
+
pr: 1,
|
|
148
154
|
py: 2,
|
|
149
155
|
zIndex: 1,
|
|
150
156
|
color: 'text.tertiary',
|
|
@@ -330,15 +336,22 @@ var CodeBlockView = function CodeBlockView(props) {
|
|
|
330
336
|
bgcolor: 'inherit',
|
|
331
337
|
color: 'inherit'
|
|
332
338
|
}
|
|
333
|
-
}, /*#__PURE__*/React.createElement(
|
|
339
|
+
}, copyText === '复制成功' ? /*#__PURE__*/React.createElement(CheckboxCircleLineIcon, {
|
|
340
|
+
sx: {
|
|
341
|
+
fontSize: '0.75rem',
|
|
342
|
+
color: 'success.main'
|
|
343
|
+
}
|
|
344
|
+
}) : /*#__PURE__*/React.createElement(FileCopyLineIcon, {
|
|
334
345
|
sx: {
|
|
335
346
|
fontSize: '0.75rem',
|
|
336
347
|
color: 'inherit'
|
|
337
348
|
}
|
|
338
349
|
}), /*#__PURE__*/React.createElement(Box, {
|
|
339
|
-
sx: {
|
|
350
|
+
sx: _objectSpread({
|
|
340
351
|
lineHeight: 1
|
|
341
|
-
}
|
|
352
|
+
}, copyText === '复制成功' ? {
|
|
353
|
+
color: 'success.main'
|
|
354
|
+
} : {})
|
|
342
355
|
}, copyText)))), /*#__PURE__*/React.createElement(Box, {
|
|
343
356
|
component: 'pre',
|
|
344
357
|
sx: {
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Box } from "@mui/material";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { useMermaidRender } from "./useMermaidRender";
|
|
4
|
+
var FlowDiagram = function FlowDiagram(_ref) {
|
|
5
|
+
var code = _ref.code,
|
|
6
|
+
onError = _ref.onError;
|
|
7
|
+
var _useMermaidRender = useMermaidRender({
|
|
8
|
+
code: code,
|
|
9
|
+
onError: onError,
|
|
10
|
+
showLoading: true,
|
|
11
|
+
idPrefix: 'mermaid'
|
|
12
|
+
}),
|
|
13
|
+
svgContent = _useMermaidRender.svgContent,
|
|
14
|
+
error = _useMermaidRender.error,
|
|
15
|
+
loading = _useMermaidRender.loading;
|
|
16
|
+
return /*#__PURE__*/React.createElement(Box, {
|
|
17
|
+
sx: {
|
|
18
|
+
width: '100%',
|
|
19
|
+
minHeight: loading ? '100px' : 'auto',
|
|
20
|
+
display: 'flex',
|
|
21
|
+
alignItems: 'center',
|
|
22
|
+
justifyContent: 'center',
|
|
23
|
+
'& svg': {
|
|
24
|
+
maxWidth: '100%',
|
|
25
|
+
height: 'auto'
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}, loading && !error && /*#__PURE__*/React.createElement(Box, {
|
|
29
|
+
sx: {
|
|
30
|
+
color: 'text.secondary',
|
|
31
|
+
fontSize: '14px'
|
|
32
|
+
}
|
|
33
|
+
}, "\u6B63\u5728\u6E32\u67D3..."), error && /*#__PURE__*/React.createElement(Box, {
|
|
34
|
+
sx: {
|
|
35
|
+
color: 'error.main',
|
|
36
|
+
padding: '20px',
|
|
37
|
+
textAlign: 'center',
|
|
38
|
+
fontSize: '14px'
|
|
39
|
+
}
|
|
40
|
+
}, error), svgContent && !error && /*#__PURE__*/React.createElement(Box, {
|
|
41
|
+
dangerouslySetInnerHTML: {
|
|
42
|
+
__html: svgContent
|
|
43
|
+
},
|
|
44
|
+
sx: {
|
|
45
|
+
width: '100%',
|
|
46
|
+
display: 'flex',
|
|
47
|
+
alignItems: 'center',
|
|
48
|
+
justifyContent: 'center'
|
|
49
|
+
}
|
|
50
|
+
}));
|
|
51
|
+
};
|
|
52
|
+
export default FlowDiagram;
|
|
@@ -73,7 +73,7 @@ var InsertFlow = function InsertFlow(_ref) {
|
|
|
73
73
|
flexGrow: 1,
|
|
74
74
|
textAlign: 'left'
|
|
75
75
|
}
|
|
76
|
-
}, "\u70B9\u51FB\u6B64\u5904\
|
|
76
|
+
}, "\u70B9\u51FB\u6B64\u5904\u8F93\u5165\u6216\u7C98\u8D34 Mermaid \u6D41\u7A0B\u56FE\u4EE3\u7801")), /*#__PURE__*/React.createElement(FloatingPopover, {
|
|
77
77
|
open: Boolean(anchorEl),
|
|
78
78
|
anchorEl: anchorEl,
|
|
79
79
|
onClose: handleClosePopover,
|
|
@@ -18,6 +18,10 @@ var ReadonlyFlow = function ReadonlyFlow(_ref) {
|
|
|
18
18
|
}
|
|
19
19
|
return /*#__PURE__*/React.createElement(NodeViewWrapper, {
|
|
20
20
|
className: "flow-wrapper"
|
|
21
|
+
}, /*#__PURE__*/React.createElement(Box, {
|
|
22
|
+
sx: {
|
|
23
|
+
textAlign: attrs.align || undefined
|
|
24
|
+
}
|
|
21
25
|
}, /*#__PURE__*/React.createElement(Box, {
|
|
22
26
|
sx: {
|
|
23
27
|
position: 'relative',
|
|
@@ -25,7 +29,7 @@ var ReadonlyFlow = function ReadonlyFlow(_ref) {
|
|
|
25
29
|
border: '1px solid',
|
|
26
30
|
borderColor: 'divider',
|
|
27
31
|
borderRadius: 'var(--mui-shape-borderRadius)',
|
|
28
|
-
width: attrs.width || '100%',
|
|
32
|
+
width: typeof attrs.width === 'string' && attrs.width.endsWith('%') ? attrs.width : typeof attrs.width === 'number' ? "".concat(attrs.width, "px") : typeof attrs.width === 'string' && attrs.width && !isNaN(parseFloat(attrs.width)) ? "".concat(attrs.width, "px") : attrs.width || '100%',
|
|
29
33
|
height: 'auto'
|
|
30
34
|
}
|
|
31
35
|
}, /*#__PURE__*/React.createElement(Box, {
|
|
@@ -60,6 +64,6 @@ var ReadonlyFlow = function ReadonlyFlow(_ref) {
|
|
|
60
64
|
height: 'auto'
|
|
61
65
|
}
|
|
62
66
|
}
|
|
63
|
-
}))));
|
|
67
|
+
})))));
|
|
64
68
|
};
|
|
65
69
|
export default ReadonlyFlow;
|
|
@@ -4,16 +4,17 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
4
4
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
5
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
6
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
-
import {
|
|
7
|
+
import { ActionDropdown } from "../../../component";
|
|
8
|
+
import { AlignCenterIcon, AlignLeftIcon, AlignRightIcon, DeleteLineIcon, EditLineIcon } from "../../../component/Icons";
|
|
8
9
|
import { ToolbarItem } from "../../../component/Toolbar";
|
|
9
|
-
import { alpha, Box, Stack, useTheme } from "@mui/material";
|
|
10
|
+
import { alpha, Box, Divider, Stack, useTheme } from "@mui/material";
|
|
10
11
|
import { NodeViewWrapper } from '@tiptap/react';
|
|
11
12
|
import React, { useCallback, useEffect, useRef, useState } from "react";
|
|
12
13
|
import { HoverPopover } from "../../../component/HoverPopover";
|
|
13
14
|
import EditFlow from "./Edit";
|
|
15
|
+
import FlowDiagram from "./FlowDiagram";
|
|
14
16
|
import InsertFlow from "./Insert";
|
|
15
17
|
import ReadonlyFlow from "./Readonly";
|
|
16
|
-
import { useMermaidRender } from "./useMermaidRender";
|
|
17
18
|
var FlowViewWrapper = function FlowViewWrapper(_ref) {
|
|
18
19
|
var editor = _ref.editor,
|
|
19
20
|
node = _ref.node,
|
|
@@ -48,6 +49,23 @@ var FlowViewWrapper = function FlowViewWrapper(_ref) {
|
|
|
48
49
|
var flowWrapperRef = useRef(null);
|
|
49
50
|
var flowContentRef = useRef(null);
|
|
50
51
|
var editButtonRef = useRef(null);
|
|
52
|
+
var isPercentWidth = function isPercentWidth() {
|
|
53
|
+
if (!attrs.width) return true;
|
|
54
|
+
if (typeof attrs.width === 'string' && attrs.width.endsWith('%')) {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
return false;
|
|
58
|
+
};
|
|
59
|
+
var getCurrentWidthPercent = function getCurrentWidthPercent() {
|
|
60
|
+
if (isPercentWidth()) {
|
|
61
|
+
if (!attrs.width) return '100';
|
|
62
|
+
if (typeof attrs.width === 'string' && attrs.width.endsWith('%')) {
|
|
63
|
+
return attrs.width.replace('%', '');
|
|
64
|
+
}
|
|
65
|
+
return '100';
|
|
66
|
+
}
|
|
67
|
+
return 'pixel';
|
|
68
|
+
};
|
|
51
69
|
var getCurrentDisplayWidth = function getCurrentDisplayWidth() {
|
|
52
70
|
if (flowWrapperRef.current) {
|
|
53
71
|
return flowWrapperRef.current.offsetWidth;
|
|
@@ -71,18 +89,6 @@ var FlowViewWrapper = function FlowViewWrapper(_ref) {
|
|
|
71
89
|
}
|
|
72
90
|
return containerSize * (defaultPercent / 100);
|
|
73
91
|
};
|
|
74
|
-
|
|
75
|
-
// 将像素值转换回字符串格式
|
|
76
|
-
var formatValue = function formatValue(pixels, original) {
|
|
77
|
-
if (typeof original === 'string' && original.endsWith('%')) {
|
|
78
|
-
var _flowWrapperRef$curre;
|
|
79
|
-
// 如果原来是百分比,保持百分比格式
|
|
80
|
-
var containerWidth = ((_flowWrapperRef$curre = flowWrapperRef.current) === null || _flowWrapperRef$curre === void 0 || (_flowWrapperRef$curre = _flowWrapperRef$curre.parentElement) === null || _flowWrapperRef$curre === void 0 ? void 0 : _flowWrapperRef$curre.clientWidth) || 800;
|
|
81
|
-
var percent = Math.round(pixels / containerWidth * 100);
|
|
82
|
-
return "".concat(percent, "%");
|
|
83
|
-
}
|
|
84
|
-
return "".concat(Math.round(pixels), "px");
|
|
85
|
-
};
|
|
86
92
|
var handleMouseDown = function handleMouseDown(e, corner) {
|
|
87
93
|
e.preventDefault();
|
|
88
94
|
e.stopPropagation();
|
|
@@ -101,11 +107,13 @@ var FlowViewWrapper = function FlowViewWrapper(_ref) {
|
|
|
101
107
|
newWidth = dragStartWidthRef.current - deltaX;
|
|
102
108
|
}
|
|
103
109
|
newWidth = Math.max(200, Math.min(1920, newWidth));
|
|
110
|
+
// 手动调整宽度时,改为固定宽度(像素值)
|
|
104
111
|
_updateAttributes({
|
|
105
|
-
width:
|
|
106
|
-
code: attrs.code
|
|
112
|
+
width: Math.round(newWidth),
|
|
113
|
+
code: attrs.code,
|
|
114
|
+
align: attrs.align
|
|
107
115
|
});
|
|
108
|
-
}, [isDragging, dragCorner, attrs.
|
|
116
|
+
}, [isDragging, dragCorner, attrs.code, _updateAttributes]);
|
|
109
117
|
var handleMouseUp = useCallback(function () {
|
|
110
118
|
setIsDragging(false);
|
|
111
119
|
setDragCorner(null);
|
|
@@ -144,7 +152,8 @@ var FlowViewWrapper = function FlowViewWrapper(_ref) {
|
|
|
144
152
|
}, /*#__PURE__*/React.createElement(Box, {
|
|
145
153
|
ref: flowContentRef,
|
|
146
154
|
sx: {
|
|
147
|
-
position: 'relative'
|
|
155
|
+
position: 'relative',
|
|
156
|
+
textAlign: attrs.align || undefined
|
|
148
157
|
},
|
|
149
158
|
onMouseEnter: function onMouseEnter() {
|
|
150
159
|
return setIsHovering(true);
|
|
@@ -157,10 +166,11 @@ var FlowViewWrapper = function FlowViewWrapper(_ref) {
|
|
|
157
166
|
sx: {
|
|
158
167
|
position: 'relative',
|
|
159
168
|
border: '2px solid',
|
|
169
|
+
display: 'inline-block',
|
|
160
170
|
borderColor: isHovering || isDragging ? alpha(theme.palette.primary.main, 0.3) : 'transparent',
|
|
161
171
|
borderRadius: 'var(--mui-shape-borderRadius)',
|
|
162
172
|
bgcolor: 'background.paper',
|
|
163
|
-
width: attrs.width || '100%',
|
|
173
|
+
width: typeof attrs.width === 'string' && attrs.width.endsWith('%') ? attrs.width : typeof attrs.width === 'number' ? "".concat(attrs.width, "px") : typeof attrs.width === 'string' && attrs.width && !isNaN(parseFloat(attrs.width)) ? "".concat(attrs.width, "px") : attrs.width || '100%',
|
|
164
174
|
height: 'auto',
|
|
165
175
|
transition: 'border-color 0.2s ease'
|
|
166
176
|
}
|
|
@@ -184,6 +194,109 @@ var FlowViewWrapper = function FlowViewWrapper(_ref) {
|
|
|
184
194
|
}),
|
|
185
195
|
tip: "\u7F16\u8F91\u6D41\u7A0B\u56FE",
|
|
186
196
|
onClick: handleShowPopover
|
|
197
|
+
}), /*#__PURE__*/React.createElement(Divider, {
|
|
198
|
+
orientation: "vertical",
|
|
199
|
+
flexItem: true,
|
|
200
|
+
sx: {
|
|
201
|
+
height: '1rem',
|
|
202
|
+
mx: 0.5,
|
|
203
|
+
alignSelf: 'center',
|
|
204
|
+
borderColor: 'divider'
|
|
205
|
+
}
|
|
206
|
+
}), /*#__PURE__*/React.createElement(ToolbarItem, {
|
|
207
|
+
icon: /*#__PURE__*/React.createElement(AlignLeftIcon, {
|
|
208
|
+
sx: {
|
|
209
|
+
fontSize: '1rem'
|
|
210
|
+
}
|
|
211
|
+
}),
|
|
212
|
+
tip: "\u5DE6\u4FA7\u5BF9\u9F50",
|
|
213
|
+
className: attrs.align === 'left' ? 'tool-active' : '',
|
|
214
|
+
onClick: function onClick() {
|
|
215
|
+
return _updateAttributes({
|
|
216
|
+
align: attrs.align === 'left' ? null : 'left',
|
|
217
|
+
code: attrs.code,
|
|
218
|
+
width: attrs.width
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
}), /*#__PURE__*/React.createElement(ToolbarItem, {
|
|
222
|
+
icon: /*#__PURE__*/React.createElement(AlignCenterIcon, {
|
|
223
|
+
sx: {
|
|
224
|
+
fontSize: '1rem'
|
|
225
|
+
}
|
|
226
|
+
}),
|
|
227
|
+
tip: "\u5C45\u4E2D\u5BF9\u9F50",
|
|
228
|
+
className: attrs.align === 'center' ? 'tool-active' : '',
|
|
229
|
+
onClick: function onClick() {
|
|
230
|
+
return _updateAttributes({
|
|
231
|
+
align: attrs.align === 'center' ? null : 'center',
|
|
232
|
+
code: attrs.code,
|
|
233
|
+
width: attrs.width
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}), /*#__PURE__*/React.createElement(ToolbarItem, {
|
|
237
|
+
icon: /*#__PURE__*/React.createElement(AlignRightIcon, {
|
|
238
|
+
sx: {
|
|
239
|
+
fontSize: '1rem'
|
|
240
|
+
}
|
|
241
|
+
}),
|
|
242
|
+
tip: "\u53F3\u4FA7\u5BF9\u9F50",
|
|
243
|
+
className: attrs.align === 'right' ? 'tool-active' : '',
|
|
244
|
+
onClick: function onClick() {
|
|
245
|
+
return _updateAttributes({
|
|
246
|
+
align: attrs.align === 'right' ? null : 'right',
|
|
247
|
+
code: attrs.code,
|
|
248
|
+
width: attrs.width
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}), /*#__PURE__*/React.createElement(Divider, {
|
|
252
|
+
orientation: "vertical",
|
|
253
|
+
flexItem: true,
|
|
254
|
+
sx: {
|
|
255
|
+
height: '1rem',
|
|
256
|
+
mx: 0.5,
|
|
257
|
+
alignSelf: 'center',
|
|
258
|
+
borderColor: 'divider'
|
|
259
|
+
}
|
|
260
|
+
}), /*#__PURE__*/React.createElement(ActionDropdown, {
|
|
261
|
+
id: "flow-width-dropdown",
|
|
262
|
+
selected: getCurrentWidthPercent(),
|
|
263
|
+
defaultDisplay: !isPercentWidth() ? {
|
|
264
|
+
label: '固定宽度'
|
|
265
|
+
} : undefined,
|
|
266
|
+
list: [{
|
|
267
|
+
key: '50',
|
|
268
|
+
label: '自适应宽度(50%)',
|
|
269
|
+
onClick: function onClick() {
|
|
270
|
+
return _updateAttributes({
|
|
271
|
+
width: '50%'
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}, {
|
|
275
|
+
key: '75',
|
|
276
|
+
label: '自适应宽度(75%)',
|
|
277
|
+
onClick: function onClick() {
|
|
278
|
+
return _updateAttributes({
|
|
279
|
+
width: '75%'
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
}, {
|
|
283
|
+
key: '100',
|
|
284
|
+
label: '自适应宽度(100%)',
|
|
285
|
+
onClick: function onClick() {
|
|
286
|
+
return _updateAttributes({
|
|
287
|
+
width: '100%'
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
}]
|
|
291
|
+
}), /*#__PURE__*/React.createElement(Divider, {
|
|
292
|
+
orientation: "vertical",
|
|
293
|
+
flexItem: true,
|
|
294
|
+
sx: {
|
|
295
|
+
height: '1rem',
|
|
296
|
+
mx: 0.5,
|
|
297
|
+
alignSelf: 'center',
|
|
298
|
+
borderColor: 'divider'
|
|
299
|
+
}
|
|
187
300
|
}), /*#__PURE__*/React.createElement(ToolbarItem, {
|
|
188
301
|
icon: /*#__PURE__*/React.createElement(DeleteLineIcon, {
|
|
189
302
|
sx: {
|
|
@@ -300,52 +413,4 @@ var FlowViewWrapper = function FlowViewWrapper(_ref) {
|
|
|
300
413
|
onCancel: handleEditCancel
|
|
301
414
|
}));
|
|
302
415
|
};
|
|
303
|
-
var FlowDiagram = function FlowDiagram(_ref2) {
|
|
304
|
-
var code = _ref2.code,
|
|
305
|
-
onError = _ref2.onError;
|
|
306
|
-
var _useMermaidRender = useMermaidRender({
|
|
307
|
-
code: code,
|
|
308
|
-
onError: onError,
|
|
309
|
-
showLoading: true,
|
|
310
|
-
idPrefix: 'mermaid'
|
|
311
|
-
}),
|
|
312
|
-
svgContent = _useMermaidRender.svgContent,
|
|
313
|
-
error = _useMermaidRender.error,
|
|
314
|
-
loading = _useMermaidRender.loading;
|
|
315
|
-
return /*#__PURE__*/React.createElement(Box, {
|
|
316
|
-
sx: {
|
|
317
|
-
width: '100%',
|
|
318
|
-
minHeight: loading ? '100px' : 'auto',
|
|
319
|
-
display: 'flex',
|
|
320
|
-
alignItems: 'center',
|
|
321
|
-
justifyContent: 'center',
|
|
322
|
-
'& svg': {
|
|
323
|
-
maxWidth: '100%',
|
|
324
|
-
height: 'auto'
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
}, loading && !error && /*#__PURE__*/React.createElement(Box, {
|
|
328
|
-
sx: {
|
|
329
|
-
color: 'text.secondary',
|
|
330
|
-
fontSize: '14px'
|
|
331
|
-
}
|
|
332
|
-
}, "\u6B63\u5728\u6E32\u67D3..."), error && /*#__PURE__*/React.createElement(Box, {
|
|
333
|
-
sx: {
|
|
334
|
-
color: 'error.main',
|
|
335
|
-
padding: '20px',
|
|
336
|
-
textAlign: 'center',
|
|
337
|
-
fontSize: '14px'
|
|
338
|
-
}
|
|
339
|
-
}, error), svgContent && !error && /*#__PURE__*/React.createElement(Box, {
|
|
340
|
-
dangerouslySetInnerHTML: {
|
|
341
|
-
__html: svgContent
|
|
342
|
-
},
|
|
343
|
-
sx: {
|
|
344
|
-
width: '100%',
|
|
345
|
-
display: 'flex',
|
|
346
|
-
alignItems: 'center',
|
|
347
|
-
justifyContent: 'center'
|
|
348
|
-
}
|
|
349
|
-
}));
|
|
350
|
-
};
|
|
351
416
|
export default FlowViewWrapper;
|
|
@@ -86,7 +86,7 @@ export var useMermaidRender = function useMermaidRender(_ref) {
|
|
|
86
86
|
_context.next = 17;
|
|
87
87
|
break;
|
|
88
88
|
case 16:
|
|
89
|
-
throw new Error('
|
|
89
|
+
throw new Error('Mermaid 流程图渲染结果为空,请检查流程图代码是否正确');
|
|
90
90
|
case 17:
|
|
91
91
|
_context.next = 28;
|
|
92
92
|
break;
|
|
@@ -99,7 +99,7 @@ export var useMermaidRender = function useMermaidRender(_ref) {
|
|
|
99
99
|
}
|
|
100
100
|
return _context.abrupt("return");
|
|
101
101
|
case 23:
|
|
102
|
-
errorMessage = _context.t0.message || '流程图渲染失败';
|
|
102
|
+
errorMessage = _context.t0.message || 'Mermaid 流程图渲染失败';
|
|
103
103
|
setError(errorMessage);
|
|
104
104
|
setLoading(false);
|
|
105
105
|
setSvgContent('');
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import { type MermaidConfig } from 'mermaid';
|
|
2
|
+
/**
|
|
3
|
+
* 初始化 mermaid(只执行一次)
|
|
4
|
+
* @param config 可选的 mermaid 配置,会与默认配置合并
|
|
5
|
+
*/
|
|
6
|
+
export declare const initMermaid: (config?: MermaidConfig) => void;
|
|
7
|
+
/**
|
|
8
|
+
* 获取当前 mermaid 配置
|
|
9
|
+
*/
|
|
10
|
+
export declare const getMermaidConfig: () => MermaidConfig | null;
|
|
2
11
|
/**
|
|
3
12
|
* 生成唯一的 mermaid 渲染 ID
|
|
4
13
|
*/
|
|
@@ -1,27 +1,62 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
1
7
|
import mermaid from 'mermaid';
|
|
8
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 默认 mermaid 配置
|
|
12
|
+
*/
|
|
13
|
+
var defaultMermaidConfig = {
|
|
14
|
+
startOnLoad: false,
|
|
15
|
+
theme: 'default',
|
|
16
|
+
securityLevel: 'loose',
|
|
17
|
+
look: 'handDrawn' // 启用手绘效果
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 全局 mermaid 配置
|
|
22
|
+
*/
|
|
23
|
+
var globalMermaidConfig = null;
|
|
2
24
|
|
|
3
25
|
/**
|
|
4
26
|
* 初始化 mermaid(只执行一次)
|
|
27
|
+
* @param config 可选的 mermaid 配置,会与默认配置合并
|
|
5
28
|
*/
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
29
|
+
export var initMermaid = function initMermaid(config) {
|
|
30
|
+
if (!globalMermaidConfig) {
|
|
31
|
+
var mergedConfig = _objectSpread(_objectSpread(_objectSpread({}, defaultMermaidConfig), config), {}, {
|
|
32
|
+
// 深度合并 flowchart 配置
|
|
33
|
+
flowchart: _objectSpread(_objectSpread({}, defaultMermaidConfig.flowchart), config === null || config === void 0 ? void 0 : config.flowchart)
|
|
34
|
+
});
|
|
35
|
+
mermaid.initialize(mergedConfig);
|
|
36
|
+
globalMermaidConfig = mergedConfig;
|
|
37
|
+
} else if (config) {
|
|
38
|
+
// 如果已经初始化过,但传入了新配置,则更新配置
|
|
39
|
+
var _mergedConfig = _objectSpread(_objectSpread(_objectSpread({}, globalMermaidConfig), config), {}, {
|
|
40
|
+
flowchart: _objectSpread(_objectSpread({}, globalMermaidConfig.flowchart), config === null || config === void 0 ? void 0 : config.flowchart)
|
|
14
41
|
});
|
|
15
|
-
|
|
42
|
+
mermaid.initialize(_mergedConfig);
|
|
43
|
+
globalMermaidConfig = _mergedConfig;
|
|
16
44
|
}
|
|
17
45
|
};
|
|
18
46
|
|
|
47
|
+
/**
|
|
48
|
+
* 获取当前 mermaid 配置
|
|
49
|
+
*/
|
|
50
|
+
export var getMermaidConfig = function getMermaidConfig() {
|
|
51
|
+
return globalMermaidConfig;
|
|
52
|
+
};
|
|
53
|
+
|
|
19
54
|
/**
|
|
20
55
|
* 生成唯一的 mermaid 渲染 ID
|
|
21
56
|
*/
|
|
22
57
|
export var generateMermaidId = function generateMermaidId() {
|
|
23
58
|
var prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'mermaid';
|
|
24
|
-
return "".concat(prefix, "-").concat(
|
|
59
|
+
return "".concat(prefix, "-").concat(uuidv4());
|
|
25
60
|
};
|
|
26
61
|
|
|
27
62
|
/**
|