@uiw/react-md-editor 3.9.8 → 3.10.1
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/README.md +46 -21
- package/dist/mdeditor.css +0 -2
- package/dist/mdeditor.js +478 -233
- package/dist/mdeditor.min.css +1 -1
- package/dist/mdeditor.min.js +1 -1
- package/esm/Editor.d.ts +4 -0
- package/esm/Editor.js +4 -2
- package/esm/Editor.js.map +3 -2
- package/esm/components/TextArea/Markdown.js +3 -3
- package/esm/components/TextArea/Markdown.js.map +2 -2
- package/esm/components/Toolbar/index.d.ts +1 -0
- package/esm/components/Toolbar/index.js +6 -3
- package/esm/components/Toolbar/index.js.map +4 -3
- package/lib/Editor.d.ts +4 -0
- package/lib/Editor.js +5 -2
- package/lib/Editor.js.map +3 -2
- package/lib/components/TextArea/Markdown.js +3 -3
- package/lib/components/TextArea/Markdown.js.map +2 -2
- package/lib/components/Toolbar/index.d.ts +1 -0
- package/lib/components/Toolbar/index.js +6 -3
- package/lib/components/Toolbar/index.js.map +4 -3
- package/package.json +5 -4
- package/src/Editor.tsx +6 -1
- package/src/components/TextArea/Markdown.tsx +3 -3
- package/src/components/Toolbar/index.tsx +6 -3
package/README.md
CHANGED
|
@@ -310,14 +310,14 @@ export default function App() {
|
|
|
310
310
|
|
|
311
311
|
Using [mermaid](https://github.com/mermaid-js/mermaid) to generation of diagram and flowchart from text in a similar manner as markdown
|
|
312
312
|
|
|
313
|
-
[](https://codesandbox.io/embed/
|
|
313
|
+
[](https://codesandbox.io/embed/recursing-water-08i59s?fontsize=14&hidenavigation=1&theme=dark)
|
|
314
314
|
|
|
315
315
|
```bash
|
|
316
316
|
npm install mermaid
|
|
317
317
|
```
|
|
318
318
|
|
|
319
319
|
```jsx
|
|
320
|
-
import React from "react";
|
|
320
|
+
import React, { useState, useRef, useEffect } from "react";
|
|
321
321
|
import ReactDOM from "react-dom";
|
|
322
322
|
import MDEditor from "@uiw/react-md-editor";
|
|
323
323
|
import mermaid from "mermaid";
|
|
@@ -345,37 +345,61 @@ Bob-->>John: Jolly good!
|
|
|
345
345
|
\`\`\`
|
|
346
346
|
`;
|
|
347
347
|
|
|
348
|
-
const
|
|
349
|
-
|
|
348
|
+
const randomid = () => parseInt(String(Math.random() * 1e15), 10).toString(36);
|
|
349
|
+
const Code = ({ inline, children = [], className, ...props }: any) => {
|
|
350
|
+
const demoid = useRef(`dome${randomid()}`);
|
|
351
|
+
const code = getCode(children);
|
|
352
|
+
const demo = useRef(null);
|
|
353
|
+
useEffect(() => {
|
|
354
|
+
if (demo.current) {
|
|
355
|
+
try {
|
|
356
|
+
const str = mermaid.render(demoid.current, code, () => null, demo.current);
|
|
357
|
+
// @ts-ignore
|
|
358
|
+
demo.current.innerHTML = str;
|
|
359
|
+
} catch (error) {
|
|
360
|
+
// @ts-ignore
|
|
361
|
+
demo.current.innerHTML = error;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}, [code, demo]);
|
|
365
|
+
|
|
366
|
+
if (
|
|
367
|
+
typeof code === "string" && typeof className === "string" &&
|
|
368
|
+
/^language-mermaid/.test(className.toLocaleLowerCase())
|
|
369
|
+
) {
|
|
370
|
+
return (
|
|
371
|
+
<code ref={demo}>
|
|
372
|
+
<code id={demoid.current} style={{ display: "none" }} />
|
|
373
|
+
</code>
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
return <code className={String(className)}>{children}</code>;
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
const getCode = (arr = []) => arr.map((dt) => {
|
|
380
|
+
if (typeof dt === "string") {
|
|
350
381
|
return dt;
|
|
351
382
|
}
|
|
352
383
|
if (dt.props && dt.props.children) {
|
|
353
384
|
return getCode(dt.props.children);
|
|
354
385
|
}
|
|
355
|
-
|
|
386
|
+
return false;
|
|
387
|
+
}).filter(Boolean).join("");
|
|
356
388
|
|
|
357
389
|
export default function App() {
|
|
390
|
+
const [value, setValue] = useState(mdMermaid);
|
|
358
391
|
return (
|
|
359
392
|
<MDEditor
|
|
393
|
+
onChange={(newValue = "") => setValue(newValue)}
|
|
394
|
+
textareaProps={{
|
|
395
|
+
placeholder: "Please enter Markdown text"
|
|
396
|
+
}}
|
|
360
397
|
height={500}
|
|
361
|
-
value={
|
|
398
|
+
value={value}
|
|
362
399
|
previewOptions={{
|
|
363
400
|
components: {
|
|
364
|
-
code:
|
|
365
|
-
|
|
366
|
-
if (
|
|
367
|
-
typeof code === 'string' &&
|
|
368
|
-
typeof className === 'string' &&
|
|
369
|
-
/^language-mermaid/.test(className.toLocaleLowerCase())
|
|
370
|
-
) {
|
|
371
|
-
const Elm = document.createElement("div");
|
|
372
|
-
Elm.id = "demo";
|
|
373
|
-
const svg = mermaid.render("demo", code);
|
|
374
|
-
return <code dangerouslySetInnerHTML={{ __html: svg }} />
|
|
375
|
-
}
|
|
376
|
-
return <code className={String(className)}>{children}</code>;
|
|
377
|
-
},
|
|
378
|
-
},
|
|
401
|
+
code: Code
|
|
402
|
+
}
|
|
379
403
|
}}
|
|
380
404
|
/>
|
|
381
405
|
);
|
|
@@ -439,6 +463,7 @@ export default HomePage;
|
|
|
439
463
|
- `visiableDragbar?: boolean=true`: Show drag and drop tool. Set the height of the editor.
|
|
440
464
|
- `highlightEnable?: boolean=true`: Disable editing area code highlighting. The value is `false`, which increases the editing speed.
|
|
441
465
|
- `fullscreen?: boolean=false`: Show markdown preview.
|
|
466
|
+
- `overflow?: boolean=true`: Disable `fullscreen` setting body styles
|
|
442
467
|
- `preview?: 'live' | 'edit' | 'preview'`: Default value `live`, Show markdown preview.
|
|
443
468
|
- `maxHeight?: number=1200`: Maximum drag height. The `visiableDragbar=true` value is valid.
|
|
444
469
|
- `minHeights?: number=100`: Minimum drag height. The `visiableDragbar=true` value is valid.
|