@haklex/rich-renderer-mermaid 0.1.0 → 0.2.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/MermaidRenderer-uLPYgYDI.js +586 -0
- package/dist/index.mjs +368 -287
- package/dist/rich-renderer-mermaid.css +2 -1
- package/dist/static.mjs +2 -4
- package/dist/svg-post-process.d.ts.map +1 -1
- package/package.json +11 -11
- package/dist/MermaidRenderer-CZN-HzPn.js +0 -606
package/dist/index.mjs
CHANGED
|
@@ -1,294 +1,375 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as editorViewToggle, D as editorTplBtn, E as editorTitle, I as mermaidError, L as mermaidLoading, M as footerBtnCancel, N as footerBtnSave, O as editorViewItem, P as mermaidContainer, R as zoomBtn, S as editorPreviewErrorWrap, T as editorSep, _ as editorPopup, a as codeGutter, b as editorPreviewErrorMsg, c as editorFooter, d as editorHeaderRight, f as editorIconBtn, i as codeEditor, j as footerActions, k as editorViewItemActive, l as editorHeader, n as useMermaidRender, o as codeGutterLine, r as codeArea, s as editorBody, t as MermaidRenderer, u as editorHeaderLeft, v as editorPreviewEmpty, w as editorPreviewWrap, x as editorPreviewErrorTitle, y as editorPreviewErrorIcon, z as zoomControls } from "./MermaidRenderer-uLPYgYDI.js";
|
|
2
2
|
import { useColorScheme } from "@haklex/rich-editor";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { useCallback,
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
3
|
+
import { presentDialog, usePortalTheme } from "@haklex/rich-editor-ui";
|
|
4
|
+
import { CircleAlert, Code2, Columns2, Copy, Download, Eye, FishSymbol, Maximize2, RotateCcw, X, ZoomIn, ZoomOut } from "lucide-react";
|
|
5
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
6
|
+
import { TransformComponent, TransformWrapper, useControls } from "react-zoom-pan-pinch";
|
|
7
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
//#region src/MermaidEditRenderer.tsx
|
|
9
|
+
var TEMPLATES = [
|
|
10
|
+
{
|
|
11
|
+
label: "Flowchart",
|
|
12
|
+
code: "graph TD\n A[Start] --> B{Decision}\n B -->|Yes| C[Action 1]\n B -->|No| D[Action 2]\n C --> E[End]\n D --> E"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
label: "Sequence",
|
|
16
|
+
code: "sequenceDiagram\n participant A as Client\n participant B as Server\n A->>B: Request\n B-->>A: Response"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
label: "Class",
|
|
20
|
+
code: "classDiagram\n class Animal {\n +String name\n +makeSound()\n }\n class Dog {\n +bark()\n }\n Animal <|-- Dog"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
label: "State",
|
|
24
|
+
code: "stateDiagram-v2\n [*] --> Idle\n Idle --> Processing: Submit\n Processing --> Success: Complete\n Processing --> Error: Fail\n Error --> Idle: Retry\n Success --> [*]"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
label: "Git",
|
|
28
|
+
code: "gitGraph\n commit\n branch develop\n checkout develop\n commit\n checkout main\n merge develop\n commit"
|
|
29
|
+
}
|
|
30
30
|
];
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
31
|
+
var MermaidLivePreview = ({ code, svgRef, colorScheme }) => {
|
|
32
|
+
const [debounced, setDebounced] = useState(code);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
const t = setTimeout(() => setDebounced(code), 300);
|
|
35
|
+
return () => clearTimeout(t);
|
|
36
|
+
}, [code]);
|
|
37
|
+
const { loading, error, imgSrc, svg, width, height } = useMermaidRender(debounced, colorScheme);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
svgRef.current = svg;
|
|
40
|
+
}, [svg, svgRef]);
|
|
41
|
+
if (!debounced.trim()) return /* @__PURE__ */ jsx("div", {
|
|
42
|
+
className: editorPreviewWrap,
|
|
43
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
44
|
+
className: editorPreviewEmpty,
|
|
45
|
+
children: "Enter Mermaid code to see the preview"
|
|
46
|
+
})
|
|
47
|
+
});
|
|
48
|
+
if (loading && !imgSrc) return /* @__PURE__ */ jsx("div", {
|
|
49
|
+
className: editorPreviewWrap,
|
|
50
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
51
|
+
className: mermaidLoading,
|
|
52
|
+
children: "Rendering"
|
|
53
|
+
})
|
|
54
|
+
});
|
|
55
|
+
if (error && !imgSrc) return /* @__PURE__ */ jsx("div", {
|
|
56
|
+
className: editorPreviewWrap,
|
|
57
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
58
|
+
className: editorPreviewErrorWrap,
|
|
59
|
+
children: [
|
|
60
|
+
/* @__PURE__ */ jsx("span", {
|
|
61
|
+
className: editorPreviewErrorIcon,
|
|
62
|
+
children: /* @__PURE__ */ jsx(CircleAlert, { size: 16 })
|
|
63
|
+
}),
|
|
64
|
+
/* @__PURE__ */ jsx("p", {
|
|
65
|
+
className: editorPreviewErrorTitle,
|
|
66
|
+
children: "Syntax Error"
|
|
67
|
+
}),
|
|
68
|
+
/* @__PURE__ */ jsx("p", {
|
|
69
|
+
className: editorPreviewErrorMsg,
|
|
70
|
+
children: error
|
|
71
|
+
})
|
|
72
|
+
]
|
|
73
|
+
})
|
|
74
|
+
});
|
|
75
|
+
return /* @__PURE__ */ jsx("div", {
|
|
76
|
+
className: editorPreviewWrap,
|
|
77
|
+
children: /* @__PURE__ */ jsxs(TransformWrapper, {
|
|
78
|
+
initialScale: 1,
|
|
79
|
+
maxScale: 5,
|
|
80
|
+
minScale: .3,
|
|
81
|
+
children: [/* @__PURE__ */ jsx(ZoomControls, {}), /* @__PURE__ */ jsx(TransformComponent, {
|
|
82
|
+
wrapperStyle: {
|
|
83
|
+
width: "100%",
|
|
84
|
+
height: "100%"
|
|
85
|
+
},
|
|
86
|
+
contentStyle: {
|
|
87
|
+
width: "100%",
|
|
88
|
+
display: "flex",
|
|
89
|
+
justifyContent: "center"
|
|
90
|
+
},
|
|
91
|
+
children: /* @__PURE__ */ jsx("img", {
|
|
92
|
+
alt: "Mermaid diagram",
|
|
93
|
+
height,
|
|
94
|
+
src: imgSrc,
|
|
95
|
+
width
|
|
96
|
+
})
|
|
97
|
+
})]
|
|
98
|
+
})
|
|
99
|
+
});
|
|
69
100
|
};
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
101
|
+
var CodeEditor = ({ value, onChange }) => {
|
|
102
|
+
const textareaRef = useRef(null);
|
|
103
|
+
const gutterRef = useRef(null);
|
|
104
|
+
const lineCount = value.split("\n").length;
|
|
105
|
+
const syncScroll = useCallback(() => {
|
|
106
|
+
if (textareaRef.current && gutterRef.current) gutterRef.current.scrollTop = textareaRef.current.scrollTop;
|
|
107
|
+
}, []);
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
const el = textareaRef.current;
|
|
110
|
+
if (!el) return;
|
|
111
|
+
el.addEventListener("scroll", syncScroll);
|
|
112
|
+
return () => el.removeEventListener("scroll", syncScroll);
|
|
113
|
+
}, [syncScroll]);
|
|
114
|
+
const handleKeyDown = useCallback((e) => {
|
|
115
|
+
if (e.key === "Tab") {
|
|
116
|
+
e.preventDefault();
|
|
117
|
+
const ta = e.currentTarget;
|
|
118
|
+
const start = ta.selectionStart;
|
|
119
|
+
const end = ta.selectionEnd;
|
|
120
|
+
onChange(`${value.slice(0, Math.max(0, start))} ${value.slice(Math.max(0, end))}`);
|
|
121
|
+
requestAnimationFrame(() => {
|
|
122
|
+
ta.selectionStart = ta.selectionEnd = start + 2;
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}, [value, onChange]);
|
|
126
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
127
|
+
className: codeEditor,
|
|
128
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
129
|
+
"aria-hidden": "true",
|
|
130
|
+
className: codeGutter,
|
|
131
|
+
ref: gutterRef,
|
|
132
|
+
children: Array.from({ length: lineCount }, (_, i) => /* @__PURE__ */ jsx("div", {
|
|
133
|
+
className: codeGutterLine,
|
|
134
|
+
children: i + 1
|
|
135
|
+
}, i))
|
|
136
|
+
}), /* @__PURE__ */ jsx("textarea", {
|
|
137
|
+
className: codeArea,
|
|
138
|
+
placeholder: "Enter Mermaid code...",
|
|
139
|
+
ref: textareaRef,
|
|
140
|
+
spellCheck: false,
|
|
141
|
+
value,
|
|
142
|
+
onChange: (e) => onChange(e.target.value),
|
|
143
|
+
onKeyDown: handleKeyDown
|
|
144
|
+
})]
|
|
145
|
+
});
|
|
115
146
|
};
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
147
|
+
var MermaidEditorContent = ({ initialContent, onSave, dismiss, colorScheme }) => {
|
|
148
|
+
const [code, setCode] = useState(initialContent);
|
|
149
|
+
const [activeView, setActiveView] = useState("split");
|
|
150
|
+
const [copied, setCopied] = useState(false);
|
|
151
|
+
const svgRef = useRef("");
|
|
152
|
+
const handleCopy = useCallback(async () => {
|
|
153
|
+
await navigator.clipboard.writeText(code);
|
|
154
|
+
setCopied(true);
|
|
155
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
156
|
+
}, [code]);
|
|
157
|
+
const handleDownload = useCallback(() => {
|
|
158
|
+
const raw = svgRef.current;
|
|
159
|
+
if (!raw) return;
|
|
160
|
+
const blob = new Blob([raw], { type: "image/svg+xml" });
|
|
161
|
+
const url = URL.createObjectURL(blob);
|
|
162
|
+
const a = document.createElement("a");
|
|
163
|
+
a.href = url;
|
|
164
|
+
a.download = "mermaid-diagram.svg";
|
|
165
|
+
a.click();
|
|
166
|
+
URL.revokeObjectURL(url);
|
|
167
|
+
}, []);
|
|
168
|
+
const handleReset = useCallback(() => setCode(initialContent), [initialContent]);
|
|
169
|
+
const handleSave = useCallback(() => {
|
|
170
|
+
onSave(code);
|
|
171
|
+
dismiss();
|
|
172
|
+
}, [
|
|
173
|
+
code,
|
|
174
|
+
onSave,
|
|
175
|
+
dismiss
|
|
176
|
+
]);
|
|
177
|
+
const viewBtn = (mode, Icon) => /* @__PURE__ */ jsx("button", {
|
|
178
|
+
className: `${editorViewItem}${activeView === mode ? ` ${editorViewItemActive}` : ""}`,
|
|
179
|
+
type: "button",
|
|
180
|
+
onClick: () => setActiveView(mode),
|
|
181
|
+
children: /* @__PURE__ */ jsx(Icon, { size: 14 })
|
|
182
|
+
});
|
|
183
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
184
|
+
/* @__PURE__ */ jsxs("div", {
|
|
185
|
+
className: editorHeader,
|
|
186
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
187
|
+
className: editorHeaderLeft,
|
|
188
|
+
children: [
|
|
189
|
+
/* @__PURE__ */ jsxs("div", {
|
|
190
|
+
className: editorTitle,
|
|
191
|
+
children: [/* @__PURE__ */ jsx(FishSymbol, { size: 18 }), /* @__PURE__ */ jsx("span", { children: "Mermaid Editor" })]
|
|
192
|
+
}),
|
|
193
|
+
/* @__PURE__ */ jsx("div", { className: editorSep }),
|
|
194
|
+
TEMPLATES.map((tpl) => /* @__PURE__ */ jsx("button", {
|
|
195
|
+
className: editorTplBtn,
|
|
196
|
+
type: "button",
|
|
197
|
+
onClick: () => setCode(tpl.code),
|
|
198
|
+
children: tpl.label
|
|
199
|
+
}, tpl.label))
|
|
200
|
+
]
|
|
201
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
202
|
+
className: editorHeaderRight,
|
|
203
|
+
children: [
|
|
204
|
+
/* @__PURE__ */ jsxs("div", {
|
|
205
|
+
className: editorViewToggle,
|
|
206
|
+
children: [
|
|
207
|
+
viewBtn("code", Code2),
|
|
208
|
+
viewBtn("split", Columns2),
|
|
209
|
+
viewBtn("preview", Eye)
|
|
210
|
+
]
|
|
211
|
+
}),
|
|
212
|
+
/* @__PURE__ */ jsx("div", { className: editorSep }),
|
|
213
|
+
/* @__PURE__ */ jsx("button", {
|
|
214
|
+
className: editorIconBtn,
|
|
215
|
+
title: copied ? "Copied!" : "Copy code",
|
|
216
|
+
type: "button",
|
|
217
|
+
onClick: handleCopy,
|
|
218
|
+
children: /* @__PURE__ */ jsx(Copy, { size: 14 })
|
|
219
|
+
}),
|
|
220
|
+
/* @__PURE__ */ jsx("button", {
|
|
221
|
+
className: editorIconBtn,
|
|
222
|
+
title: "Download SVG",
|
|
223
|
+
type: "button",
|
|
224
|
+
onClick: handleDownload,
|
|
225
|
+
children: /* @__PURE__ */ jsx(Download, { size: 14 })
|
|
226
|
+
}),
|
|
227
|
+
/* @__PURE__ */ jsx("button", {
|
|
228
|
+
className: editorIconBtn,
|
|
229
|
+
title: "Reset",
|
|
230
|
+
type: "button",
|
|
231
|
+
onClick: handleReset,
|
|
232
|
+
children: /* @__PURE__ */ jsx(RotateCcw, { size: 14 })
|
|
233
|
+
}),
|
|
234
|
+
/* @__PURE__ */ jsx("div", { className: editorSep }),
|
|
235
|
+
/* @__PURE__ */ jsx("button", {
|
|
236
|
+
className: editorIconBtn,
|
|
237
|
+
title: "Close",
|
|
238
|
+
type: "button",
|
|
239
|
+
onClick: dismiss,
|
|
240
|
+
children: /* @__PURE__ */ jsx(X, { size: 14 })
|
|
241
|
+
})
|
|
242
|
+
]
|
|
243
|
+
})]
|
|
244
|
+
}),
|
|
245
|
+
/* @__PURE__ */ jsxs("div", {
|
|
246
|
+
className: editorBody,
|
|
247
|
+
children: [activeView !== "preview" && /* @__PURE__ */ jsxs("div", {
|
|
248
|
+
className: `_36yqiej ${activeView === "code" ? "_36yqiel" : "_36yqiek"}`,
|
|
249
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
250
|
+
className: "_36yqiem",
|
|
251
|
+
children: "Editor"
|
|
252
|
+
}), /* @__PURE__ */ jsx(CodeEditor, {
|
|
253
|
+
value: code,
|
|
254
|
+
onChange: setCode
|
|
255
|
+
})]
|
|
256
|
+
}), activeView !== "code" && /* @__PURE__ */ jsxs("div", {
|
|
257
|
+
className: "_36yqien",
|
|
258
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
259
|
+
className: "_36yqiem",
|
|
260
|
+
children: "Preview"
|
|
261
|
+
}), /* @__PURE__ */ jsx(MermaidLivePreview, {
|
|
262
|
+
code,
|
|
263
|
+
colorScheme,
|
|
264
|
+
svgRef
|
|
265
|
+
})]
|
|
266
|
+
})]
|
|
267
|
+
}),
|
|
268
|
+
/* @__PURE__ */ jsx("div", {
|
|
269
|
+
className: editorFooter,
|
|
270
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
271
|
+
className: footerActions,
|
|
272
|
+
children: [/* @__PURE__ */ jsx("button", {
|
|
273
|
+
className: footerBtnCancel,
|
|
274
|
+
type: "button",
|
|
275
|
+
onClick: dismiss,
|
|
276
|
+
children: "Cancel"
|
|
277
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
278
|
+
className: footerBtnSave,
|
|
279
|
+
type: "button",
|
|
280
|
+
onClick: handleSave,
|
|
281
|
+
children: "Save"
|
|
282
|
+
})]
|
|
283
|
+
})
|
|
284
|
+
})
|
|
285
|
+
] });
|
|
223
286
|
};
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
287
|
+
var ZoomControls = () => {
|
|
288
|
+
const { zoomIn, zoomOut, resetTransform } = useControls();
|
|
289
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
290
|
+
className: zoomControls,
|
|
291
|
+
children: [
|
|
292
|
+
/* @__PURE__ */ jsx("button", {
|
|
293
|
+
className: zoomBtn,
|
|
294
|
+
type: "button",
|
|
295
|
+
onClick: () => zoomIn(),
|
|
296
|
+
children: /* @__PURE__ */ jsx(ZoomIn, { size: 14 })
|
|
297
|
+
}),
|
|
298
|
+
/* @__PURE__ */ jsx("button", {
|
|
299
|
+
className: zoomBtn,
|
|
300
|
+
type: "button",
|
|
301
|
+
onClick: () => zoomOut(),
|
|
302
|
+
children: /* @__PURE__ */ jsx(ZoomOut, { size: 14 })
|
|
303
|
+
}),
|
|
304
|
+
/* @__PURE__ */ jsx("button", {
|
|
305
|
+
className: zoomBtn,
|
|
306
|
+
type: "button",
|
|
307
|
+
onClick: () => resetTransform(),
|
|
308
|
+
children: /* @__PURE__ */ jsx(Maximize2, { size: 14 })
|
|
309
|
+
})
|
|
310
|
+
]
|
|
311
|
+
});
|
|
231
312
|
};
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
MermaidEditRenderer,
|
|
293
|
-
M as MermaidRenderer
|
|
313
|
+
var MermaidEditRenderer = ({ content, onContentChange }) => {
|
|
314
|
+
const colorScheme = useColorScheme();
|
|
315
|
+
const { loading, error, imgSrc, width, height } = useMermaidRender(content);
|
|
316
|
+
const { className: portalClassName } = usePortalTheme();
|
|
317
|
+
const handleClick = useCallback(() => {
|
|
318
|
+
if (!onContentChange) return;
|
|
319
|
+
presentDialog({
|
|
320
|
+
content: ({ dismiss }) => /* @__PURE__ */ jsx(MermaidEditorContent, {
|
|
321
|
+
colorScheme,
|
|
322
|
+
dismiss,
|
|
323
|
+
initialContent: content,
|
|
324
|
+
onSave: onContentChange
|
|
325
|
+
}),
|
|
326
|
+
className: editorPopup,
|
|
327
|
+
portalClassName,
|
|
328
|
+
theme: colorScheme,
|
|
329
|
+
showCloseButton: false,
|
|
330
|
+
clickOutsideToDismiss: false
|
|
331
|
+
});
|
|
332
|
+
}, [
|
|
333
|
+
onContentChange,
|
|
334
|
+
content,
|
|
335
|
+
portalClassName,
|
|
336
|
+
colorScheme
|
|
337
|
+
]);
|
|
338
|
+
if (loading) return /* @__PURE__ */ jsx("div", {
|
|
339
|
+
className: mermaidLoading,
|
|
340
|
+
children: "Mermaid Loading"
|
|
341
|
+
});
|
|
342
|
+
if (!imgSrc) return /* @__PURE__ */ jsx("div", {
|
|
343
|
+
className: mermaidError,
|
|
344
|
+
children: error || "Render failed"
|
|
345
|
+
});
|
|
346
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
347
|
+
className: mermaidContainer,
|
|
348
|
+
children: [onContentChange && /* @__PURE__ */ jsx("span", {
|
|
349
|
+
className: "_36yqie1",
|
|
350
|
+
onClick: handleClick,
|
|
351
|
+
children: "Edit"
|
|
352
|
+
}), /* @__PURE__ */ jsxs(TransformWrapper, {
|
|
353
|
+
initialScale: 1,
|
|
354
|
+
maxScale: 4,
|
|
355
|
+
minScale: .5,
|
|
356
|
+
wheel: { disabled: true },
|
|
357
|
+
children: [/* @__PURE__ */ jsx(ZoomControls, {}), /* @__PURE__ */ jsx(TransformComponent, {
|
|
358
|
+
wrapperStyle: { width: "100%" },
|
|
359
|
+
contentStyle: {
|
|
360
|
+
width: "100%",
|
|
361
|
+
display: "flex",
|
|
362
|
+
justifyContent: "center"
|
|
363
|
+
},
|
|
364
|
+
children: /* @__PURE__ */ jsx("img", {
|
|
365
|
+
alt: "Mermaid diagram",
|
|
366
|
+
height,
|
|
367
|
+
src: imgSrc,
|
|
368
|
+
width
|
|
369
|
+
})
|
|
370
|
+
})]
|
|
371
|
+
})]
|
|
372
|
+
});
|
|
294
373
|
};
|
|
374
|
+
//#endregion
|
|
375
|
+
export { MermaidEditRenderer, MermaidRenderer };
|