@uiw/react-md-editor 3.23.5 → 3.24.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.
Files changed (109) hide show
  1. package/README.md +56 -38
  2. package/dist/mdeditor.css +2 -0
  3. package/dist/mdeditor.js +289 -287
  4. package/dist/mdeditor.min.css +1 -1
  5. package/dist/mdeditor.min.js +1 -1
  6. package/dist/mdeditor.min.js.LICENSE.txt +1 -1
  7. package/esm/commands/bold.js +9 -13
  8. package/esm/commands/code.d.ts +1 -1
  9. package/esm/commands/code.js +75 -68
  10. package/esm/commands/comment.js +20 -18
  11. package/esm/commands/help.d.ts +2 -0
  12. package/esm/commands/help.js +22 -0
  13. package/esm/commands/hr.js +33 -2
  14. package/esm/commands/image.js +39 -16
  15. package/esm/commands/index.d.ts +3 -1
  16. package/esm/commands/index.js +3 -1
  17. package/esm/commands/issue.d.ts +2 -0
  18. package/esm/commands/issue.js +41 -0
  19. package/esm/commands/italic.js +9 -13
  20. package/esm/commands/link.js +40 -14
  21. package/esm/commands/list.d.ts +3 -10
  22. package/esm/commands/list.js +39 -41
  23. package/esm/commands/quote.js +8 -8
  24. package/esm/commands/strikeThrough.js +9 -13
  25. package/esm/commands/table.d.ts +2 -0
  26. package/esm/commands/table.js +57 -0
  27. package/esm/commands/title.d.ts +7 -1
  28. package/esm/commands/title.js +21 -0
  29. package/esm/commands/title1.js +9 -7
  30. package/esm/commands/title2.js +9 -7
  31. package/esm/commands/title3.js +9 -7
  32. package/esm/commands/title4.js +9 -7
  33. package/esm/commands/title5.js +9 -7
  34. package/esm/commands/title6.js +9 -7
  35. package/esm/components/DragBar/index.js +7 -7
  36. package/esm/components/TextArea/handleKeyDown.js +83 -3
  37. package/esm/utils/InsertTextAtPosition.d.ts +0 -7
  38. package/esm/utils/InsertTextAtPosition.js +6 -24
  39. package/esm/utils/markdownUtils.d.ts +23 -1
  40. package/esm/utils/markdownUtils.js +83 -4
  41. package/lib/Context.js +2 -3
  42. package/lib/Editor.js +1 -2
  43. package/lib/commands/bold.js +10 -15
  44. package/lib/commands/code.d.ts +1 -1
  45. package/lib/commands/code.js +75 -70
  46. package/lib/commands/comment.js +21 -20
  47. package/lib/commands/divider.js +2 -3
  48. package/lib/commands/fullscreen.js +2 -3
  49. package/lib/commands/group.js +2 -3
  50. package/lib/commands/help.d.ts +2 -0
  51. package/lib/commands/help.js +29 -0
  52. package/lib/commands/hr.js +35 -5
  53. package/lib/commands/image.js +40 -18
  54. package/lib/commands/index.d.ts +3 -1
  55. package/lib/commands/index.js +8 -10
  56. package/lib/commands/issue.d.ts +2 -0
  57. package/lib/commands/issue.js +48 -0
  58. package/lib/commands/italic.js +10 -15
  59. package/lib/commands/link.js +41 -16
  60. package/lib/commands/list.d.ts +3 -10
  61. package/lib/commands/list.js +43 -52
  62. package/lib/commands/preview.js +4 -7
  63. package/lib/commands/quote.js +9 -10
  64. package/lib/commands/strikeThrough.js +10 -15
  65. package/lib/commands/table.d.ts +2 -0
  66. package/lib/commands/table.js +64 -0
  67. package/lib/commands/title.d.ts +7 -1
  68. package/lib/commands/title.js +23 -3
  69. package/lib/commands/title1.js +11 -10
  70. package/lib/commands/title2.js +11 -10
  71. package/lib/commands/title3.js +11 -10
  72. package/lib/commands/title4.js +11 -10
  73. package/lib/commands/title5.js +11 -10
  74. package/lib/commands/title6.js +11 -10
  75. package/lib/components/DragBar/index.js +8 -9
  76. package/lib/components/TextArea/handleKeyDown.js +84 -4
  77. package/lib/index.js +1 -2
  78. package/lib/utils/InsertTextAtPosition.d.ts +0 -7
  79. package/lib/utils/InsertTextAtPosition.js +6 -26
  80. package/lib/utils/markdownUtils.d.ts +23 -1
  81. package/lib/utils/markdownUtils.js +84 -4
  82. package/package.json +4 -1
  83. package/src/commands/bold.tsx +13 -12
  84. package/src/commands/code.tsx +72 -71
  85. package/src/commands/comment.tsx +20 -15
  86. package/src/commands/help.tsx +19 -0
  87. package/src/commands/hr.tsx +33 -2
  88. package/src/commands/image.tsx +38 -15
  89. package/src/commands/index.ts +8 -1
  90. package/src/commands/issue.tsx +36 -0
  91. package/src/commands/italic.tsx +13 -12
  92. package/src/commands/link.tsx +39 -12
  93. package/src/commands/list.tsx +35 -53
  94. package/src/commands/quote.tsx +14 -13
  95. package/src/commands/strikeThrough.tsx +13 -12
  96. package/src/commands/table.tsx +52 -0
  97. package/src/commands/title.tsx +18 -1
  98. package/src/commands/title1.tsx +6 -9
  99. package/src/commands/title2.tsx +6 -9
  100. package/src/commands/title3.tsx +6 -9
  101. package/src/commands/title4.tsx +6 -9
  102. package/src/commands/title5.tsx +6 -9
  103. package/src/commands/title6.tsx +6 -9
  104. package/src/components/TextArea/handleKeyDown.tsx +50 -3
  105. package/src/utils/InsertTextAtPosition.ts +7 -28
  106. package/src/utils/markdownUtils.ts +94 -4
  107. package/src/__test__/commands.test.tsx +0 -512
  108. package/src/__test__/editor.test.tsx +0 -88
  109. package/src/__test__/utils/getSurroundingWord.test.tsx +0 -22
package/README.md CHANGED
@@ -16,7 +16,7 @@
16
16
  <img alt="npm bundle size" src="https://img.shields.io/bundlephobia/minzip/@uiw/react-md-editor">
17
17
  </a>
18
18
  <a href="https://uiwjs.github.io/react-md-editor/coverage/lcov-report" target="__blank">
19
- <img alt="Coverage Status" src="https://uiwjs.github.io/react-md-editor/coverage/badges.svg" />
19
+ <img alt="Coverage Status" src="https://uiwjs.github.io/react-md-editor/badges.svg" />
20
20
  </a>
21
21
  <br />
22
22
  <a href="https://github.com/uiwjs/react-md-editor/actions" target="__blank">
@@ -46,6 +46,7 @@ A simple markdown editor with preview, implemented with React.js and TypeScript.
46
46
  - 😻 GitHub flavored markdown support.
47
47
  - 🌒 Support dark-mode/night-mode **@v3.11.0+**.
48
48
  - 💡 Support [next.js](https://github.com/uiwjs/react-md-editor/issues/52#issuecomment-848969341), [Use examples](#support-nextjs) in [next.js](https://nextjs.org/).
49
+ - Line/lines duplication (Ctrl+D) and movement (Alt+UpArrow/DownArrow) **@v3.24.0+**.
49
50
 
50
51
  ### Quick Start
51
52
 
@@ -398,6 +399,27 @@ const codePreview = {
398
399
  icon: <Button />
399
400
  };
400
401
 
402
+ const Disable = () => {
403
+ const { preview, dispatch } = useContext(EditorContext);
404
+ return (
405
+ <button disabled={preview === "preview"}>
406
+ <svg viewBox="0 0 16 16" width="12px" height="12px">
407
+ <path
408
+ d="M8 0C3.6 0 0 3.6 0 8s3.6 8 8 8 8-3.6 8-8-3.6-8-8-8Zm.9 13H7v-1.8h1.9V13Zm-.1-3.6v.5H7.1v-.6c.2-2.1 2-1.9 1.9-3.2.1-.7-.3-1.1-1-1.1-.8 0-1.2.7-1.2 1.6H5c0-1.7 1.2-3 2.9-3 2.3 0 3 1.4 3 2.3.1 2.3-1.9 2-2.1 3.5Z"
409
+ fill="currentColor"
410
+ />
411
+ </svg>
412
+ </button>
413
+ )
414
+ }
415
+
416
+ const customButton = {
417
+ name: "disable",
418
+ keyCommand: "disable",
419
+ value: "disable",
420
+ icon: <Disable />
421
+ }
422
+
401
423
  export default function App() {
402
424
  const [value, setValue] = React.useState("**Hello world!!!**");
403
425
  return (
@@ -406,7 +428,7 @@ export default function App() {
406
428
  <MDEditor
407
429
  value={value}
408
430
  preview="edit"
409
- extraCommands={[codePreview, commands.fullscreen]}
431
+ extraCommands={[codePreview, customButton, commands.fullscreen]}
410
432
  onChange={(val) => setValue(val)}
411
433
  />
412
434
  </div>
@@ -471,7 +493,6 @@ export default function App() {
471
493
 
472
494
  ```jsx mdx:preview
473
495
  import React from "react";
474
- import ReactDOM from "react-dom";
475
496
  import MDEditor from '@uiw/react-md-editor';
476
497
 
477
498
  export default function App() {
@@ -499,7 +520,6 @@ npm install katex
499
520
 
500
521
  ```jsx mdx:preview
501
522
  import React from "react";
502
- import ReactDOM from "react-dom";
503
523
  import MDEditor from '@uiw/react-md-editor';
504
524
  import { getCodeString } from 'rehype-rewrite';
505
525
  import katex from 'katex';
@@ -515,9 +535,11 @@ c = \\pm\\sqrt{a^2 + b^2}
515
535
  `;
516
536
 
517
537
  export default function App() {
538
+ const [value, setValue] = React.useState(mdKaTeX);
518
539
  return (
519
540
  <MDEditor
520
- value={mdKaTeX}
541
+ value={value}
542
+ onChange={(val) => setValue(val)}
521
543
  previewOptions={{
522
544
  components: {
523
545
  code: ({ inline, children = [], className, ...props }) => {
@@ -542,7 +564,7 @@ export default function App() {
542
564
  });
543
565
  return <code style={{ fontSize: '150%' }} dangerouslySetInnerHTML={{ __html: html }} />;
544
566
  }
545
- return <code className={String(className)}>{txt}</code>;
567
+ return <code className={String(className)}>{children}</code>;
546
568
  },
547
569
  },
548
570
  }}
@@ -612,9 +634,9 @@ npm install mermaid
612
634
  ```
613
635
 
614
636
  ```jsx mdx:preview
615
- import React, { useState, useRef, useEffect } from "react";
616
- import ReactDOM from "react-dom";
637
+ import React, { useState, useRef, useEffect, Fragment, useCallback } from "react";
617
638
  import MDEditor from "@uiw/react-md-editor";
639
+ import { getCodeString } from 'rehype-rewrite';
618
640
  import mermaid from "mermaid";
619
641
 
620
642
  const mdMermaid = `The following are some examples of the diagrams, charts and graphs that can be made using Mermaid and the Markdown-inspired text specific to it.
@@ -643,44 +665,37 @@ Bob-->>John: Jolly good!
643
665
  const randomid = () => parseInt(String(Math.random() * 1e15), 10).toString(36);
644
666
  const Code = ({ inline, children = [], className, ...props }) => {
645
667
  const demoid = useRef(`dome${randomid()}`);
646
- const code = getCode(children);
647
- const demo = useRef(null);
668
+ const [container, setContainer] = useState(null);
669
+ const isMermaid = className && /^language-mermaid/.test(className.toLocaleLowerCase());
670
+ const code = props.node && props.node.children ? getCodeString(props.node.children) : children[0] || '';
648
671
  useEffect(() => {
649
- if (demo.current) {
672
+ if (container && isMermaid) {
650
673
  try {
651
- const str = mermaid.render(demoid.current, code, () => null, demo.current);
652
- // @ts-ignore
653
- demo.current.innerHTML = str;
674
+ const str = mermaid.render(demoid.current, code);
675
+ container.innerHTML = str;
654
676
  } catch (error) {
655
- // @ts-ignore
656
- demo.current.innerHTML = error;
677
+ container.innerHTML = error;
657
678
  }
658
679
  }
659
- }, [code, demo]);
680
+ }, [container, isMermaid, code, demoid]);
681
+
682
+ const refElement = useCallback((node) => {
683
+ if (node !== null) {
684
+ setContainer(node);
685
+ }
686
+ }, []);
660
687
 
661
- if (
662
- typeof code === "string" && typeof className === "string" &&
663
- /^language-mermaid/.test(className.toLocaleLowerCase())
664
- ) {
688
+ if (isMermaid) {
665
689
  return (
666
- <code ref={demo}>
690
+ <Fragment>
667
691
  <code id={demoid.current} style={{ display: "none" }} />
668
- </code>
692
+ <code ref={refElement} data-name="mermaid" />
693
+ </Fragment>
669
694
  );
670
695
  }
671
- return <code className={String(className)}>{children}</code>;
696
+ return <code>{children}</code>;
672
697
  };
673
698
 
674
- const getCode = (arr = []) => arr.map((dt) => {
675
- if (typeof dt === "string") {
676
- return dt;
677
- }
678
- if (dt.props && dt.props.children) {
679
- return getCode(dt.props.children);
680
- }
681
- return false;
682
- }).filter(Boolean).join("");
683
-
684
699
  export default function App() {
685
700
  const [value, setValue] = useState(mdMermaid);
686
701
  return (
@@ -828,8 +843,8 @@ As always, thanks to our amazing contributors!
828
843
  <a href="https://github.com/avalero" title="Alberto Valero Gómez">
829
844
  <img src="https://avatars.githubusercontent.com/u/1442682?v=4" width="42;" alt="Alberto Valero Gómez"/>
830
845
  </a>
831
- <a href="https://github.com/alphacoma18" title="Alpha Coma">
832
- <img src="https://avatars.githubusercontent.com/u/108984668?v=4" width="42;" alt="Alpha Coma"/>
846
+ <a href="https://github.com/alphacoma18" title="Alpha Romer Coma">
847
+ <img src="https://avatars.githubusercontent.com/u/108984668?v=4" width="42;" alt="Alpha Romer Coma"/>
833
848
  </a>
834
849
  <a href="https://github.com/Exmirai" title="UniqueUlysees">
835
850
  <img src="https://avatars.githubusercontent.com/u/6436703?v=4" width="42;" alt="UniqueUlysees"/>
@@ -837,8 +852,8 @@ As always, thanks to our amazing contributors!
837
852
  <a href="https://github.com/nuragic" title="Andrea Puddu">
838
853
  <img src="https://avatars.githubusercontent.com/u/1586378?v=4" width="42;" alt="Andrea Puddu"/>
839
854
  </a>
840
- <a href="https://github.com/bramus" title="Bramus!">
841
- <img src="https://avatars.githubusercontent.com/u/213073?v=4" width="42;" alt="Bramus!"/>
855
+ <a href="https://github.com/bramus" title="Bramus">
856
+ <img src="https://avatars.githubusercontent.com/u/213073?v=4" width="42;" alt="Bramus"/>
842
857
  </a>
843
858
  <a href="https://github.com/CarleneCannon-Conner" title="Carlene Cannon-Conner">
844
859
  <img src="https://avatars.githubusercontent.com/u/1942791?v=4" width="42;" alt="Carlene Cannon-Conner"/>
@@ -867,6 +882,9 @@ As always, thanks to our amazing contributors!
867
882
  <a href="https://github.com/phillipb" title="Phillip Burch">
868
883
  <img src="https://avatars.githubusercontent.com/u/1482089?v=4" width="42;" alt="Phillip Burch"/>
869
884
  </a>
885
+ <a href="https://github.com/RARgames" title="RAR">
886
+ <img src="https://avatars.githubusercontent.com/u/13639766?v=4" width="42;" alt="RAR"/>
887
+ </a>
870
888
  <a href="https://github.com/toresbe" title="Tore Sinding Bekkedal">
871
889
  <img src="https://avatars.githubusercontent.com/u/1761606?v=4" width="42;" alt="Tore Sinding Bekkedal"/>
872
890
  </a>
package/dist/mdeditor.css CHANGED
@@ -1288,7 +1288,9 @@ body[data-color-mode*='light'] {
1288
1288
  --md-editor-font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
1289
1289
  --md-editor-background-color: var(--color-canvas-default, #ffffff);
1290
1290
  --md-editor-box-shadow-color: var(--color-border-default, #d0d7de);
1291
+ box-shadow: 0 0 0 1px #d0d7de, 0 0 0 #d0d7de, 0 1px 1px #d0d7de;
1291
1292
  box-shadow: 0 0 0 1px var(--md-editor-box-shadow-color), 0 0 0 var(--md-editor-box-shadow-color), 0 1px 1px var(--md-editor-box-shadow-color);
1293
+ background-color: #ffffff;
1292
1294
  background-color: var(--md-editor-background-color);
1293
1295
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
1294
1296
  display: flex;