@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 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
- [![Open in CodeSandbox](https://img.shields.io/badge/Open%20in-CodeSandbox-blue?logo=codesandbox)](https://codesandbox.io/embed/markdown-editor-mermaid-for-react-uvtsx?fontsize=14&hidenavigation=1&theme=dark)
313
+ [![Open in CodeSandbox](https://img.shields.io/badge/Open%20in-CodeSandbox-blue?logo=codesandbox)](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 getCode = (arr = []) => arr.map(dt => {
349
- if (typeof dt === 'string') {
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
- }).filter(Boolean).join('');
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={mdMermaid || ""}
398
+ value={value}
362
399
  previewOptions={{
363
400
  components: {
364
- code: ({ inline, children = [], className, ...props }) => {
365
- const code = getCode(children);
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.
package/dist/mdeditor.css CHANGED
@@ -187,8 +187,6 @@
187
187
  .wmde-markdown ul {
188
188
  margin-bottom: 16px;
189
189
  margin-top: 0;
190
- list-style: disc outside none;
191
- list-style: initial;
192
190
  }
193
191
  .wmde-markdown li {
194
192
  display: list-item;