Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b8ae1d2486 | ||
|
|
482178b7b6 | ||
|
|
7da500fe0a |
@@ -341,7 +341,6 @@ export const ShapesSwitcher = ({
|
||||
setAppState({
|
||||
activeTool: nextActiveTool,
|
||||
multiElement: null,
|
||||
selectedElementIds: {},
|
||||
});
|
||||
}}
|
||||
icon={mermaidLogoIcon}
|
||||
|
||||
+13
-3
@@ -1192,7 +1192,11 @@ class App extends React.Component<AppProps, AppState> {
|
||||
>
|
||||
{this.props.children}
|
||||
{this.state.activeTool.type === "mermaid" && (
|
||||
<MermaidToExcalidraw />
|
||||
<MermaidToExcalidraw
|
||||
selectedElements={this.scene.getSelectedElements(
|
||||
this.state,
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
</LayerUI>
|
||||
|
||||
@@ -3112,7 +3116,8 @@ class App extends React.Component<AppProps, AppState> {
|
||||
| "eraser"
|
||||
| "hand"
|
||||
| "frame"
|
||||
| "embeddable";
|
||||
| "embeddable"
|
||||
| "mermaid";
|
||||
}
|
||||
| { type: "custom"; customType: string },
|
||||
) => {
|
||||
@@ -3134,7 +3139,12 @@ class App extends React.Component<AppProps, AppState> {
|
||||
if (nextActiveTool.type !== "selection") {
|
||||
this.setState({
|
||||
activeTool: nextActiveTool,
|
||||
selectedElementIds: makeNextSelectedElementIds({}, this.state),
|
||||
selectedElementIds: makeNextSelectedElementIds(
|
||||
nextActiveTool.type === "mermaid"
|
||||
? this.state.selectedElementIds
|
||||
: {},
|
||||
this.state,
|
||||
),
|
||||
selectedGroupIds: {},
|
||||
editingGroupId: null,
|
||||
activeEmbeddable: null,
|
||||
|
||||
@@ -65,7 +65,11 @@ const ErrorComp = ({ error }: { error: string }) => {
|
||||
);
|
||||
};
|
||||
|
||||
const MermaidToExcalidraw = () => {
|
||||
const MermaidToExcalidraw = ({
|
||||
selectedElements,
|
||||
}: {
|
||||
selectedElements: readonly NonDeletedExcalidrawElement[];
|
||||
}) => {
|
||||
const mermaidToExcalidrawLib = useRef<{
|
||||
parseMermaidToExcalidraw: (
|
||||
defination: string,
|
||||
@@ -111,16 +115,25 @@ const MermaidToExcalidraw = () => {
|
||||
|
||||
useEffect(() => {
|
||||
if (!loading) {
|
||||
const data = importMermaidDataFromStorage() || MERMAID_EXAMPLE;
|
||||
const selectedMermaidImage = selectedElements.filter(
|
||||
(el) => el.type === "image" && el.customData?.mermaidText,
|
||||
)[0];
|
||||
const data = selectedMermaidImage
|
||||
? selectedMermaidImage.customData?.mermaidText
|
||||
: importMermaidDataFromStorage() || MERMAID_EXAMPLE;
|
||||
|
||||
setText(data);
|
||||
}
|
||||
}, [loading]);
|
||||
}, [loading, selectedElements]);
|
||||
|
||||
useEffect(() => {
|
||||
const renderExcalidrawPreview = async () => {
|
||||
const canvasNode = canvasRef.current;
|
||||
if (!canvasNode || !mermaidToExcalidrawLib.current) {
|
||||
if (
|
||||
!canvasNode ||
|
||||
!mermaidToExcalidrawLib.current ||
|
||||
deferredText === ""
|
||||
) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
@@ -134,9 +147,17 @@ const MermaidToExcalidraw = () => {
|
||||
setError(null);
|
||||
|
||||
data.current = {
|
||||
elements: convertToExcalidrawElements(elements, {
|
||||
regenerateIds: true,
|
||||
}),
|
||||
elements: convertToExcalidrawElements(
|
||||
elements.map((el) => {
|
||||
if (el.type === "image") {
|
||||
el.customData = { mermaidText: text };
|
||||
}
|
||||
return el;
|
||||
}),
|
||||
{
|
||||
regenerateIds: true,
|
||||
},
|
||||
),
|
||||
files,
|
||||
};
|
||||
const parent = canvasNode.parentElement!;
|
||||
@@ -166,7 +187,7 @@ const MermaidToExcalidraw = () => {
|
||||
}
|
||||
};
|
||||
renderExcalidrawPreview();
|
||||
}, [deferredText]);
|
||||
}, [deferredText, text]);
|
||||
|
||||
const onClose = () => {
|
||||
app.setActiveTool({ type: "selection" });
|
||||
|
||||
Reference in New Issue
Block a user