@blocklet/editor 2.4.48 → 2.4.49
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.
|
@@ -3,5 +3,5 @@ interface MermaidComponentProps {
|
|
|
3
3
|
theme?: string;
|
|
4
4
|
mode?: string;
|
|
5
5
|
}
|
|
6
|
-
declare function MermaidComponent({ code }: MermaidComponentProps): import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
declare function MermaidComponent({ code }: MermaidComponentProps): import("react/jsx-runtime").JSX.Element | null;
|
|
7
7
|
export default MermaidComponent;
|
|
@@ -1,26 +1,33 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import React, { useEffect } from 'react';
|
|
2
|
+
import React, { useEffect, useState } from 'react';
|
|
3
3
|
import mermaid from 'mermaid';
|
|
4
4
|
import { useTheme } from '@mui/material';
|
|
5
5
|
function MermaidComponent({ code }) {
|
|
6
6
|
const theme = useTheme();
|
|
7
7
|
const ref = React.useRef(null);
|
|
8
|
+
const [error, setError] = useState(false);
|
|
8
9
|
useEffect(() => {
|
|
9
10
|
if (!ref.current)
|
|
10
11
|
return;
|
|
11
12
|
ref.current.innerHTML = '';
|
|
12
13
|
mermaid.initialize({ startOnLoad: false, ...(theme.palette.mode === 'dark' && { theme: 'dark' }) });
|
|
13
14
|
const id = `mermaid-${Math.random().toString(36).substring(2, 9)}`;
|
|
14
|
-
|
|
15
|
+
mermaid
|
|
16
|
+
.parse(code)
|
|
17
|
+
.then(() => {
|
|
15
18
|
mermaid.render(id, code).then(({ svg }) => {
|
|
16
19
|
if (ref.current)
|
|
17
20
|
ref.current.innerHTML = svg;
|
|
18
21
|
});
|
|
19
|
-
}
|
|
20
|
-
|
|
22
|
+
})
|
|
23
|
+
.catch((e) => {
|
|
21
24
|
console.error(e);
|
|
22
|
-
|
|
25
|
+
setError(true);
|
|
26
|
+
});
|
|
23
27
|
}, [code, theme.palette.mode]);
|
|
28
|
+
if (error) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
24
31
|
return _jsx("div", { ref: ref });
|
|
25
32
|
}
|
|
26
33
|
export default MermaidComponent;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/editor",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.49",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"ufo": "^1.5.4",
|
|
70
70
|
"url-join": "^4.0.1",
|
|
71
71
|
"zustand": "^4.5.5",
|
|
72
|
-
"@blocklet/pdf": "2.4.
|
|
72
|
+
"@blocklet/pdf": "2.4.49"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@babel/core": "^7.25.2",
|