@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.
- package/README.md +56 -38
- package/dist/mdeditor.css +2 -0
- package/dist/mdeditor.js +289 -287
- package/dist/mdeditor.min.css +1 -1
- package/dist/mdeditor.min.js +1 -1
- package/dist/mdeditor.min.js.LICENSE.txt +1 -1
- package/esm/commands/bold.js +9 -13
- package/esm/commands/code.d.ts +1 -1
- package/esm/commands/code.js +75 -68
- package/esm/commands/comment.js +20 -18
- package/esm/commands/help.d.ts +2 -0
- package/esm/commands/help.js +22 -0
- package/esm/commands/hr.js +33 -2
- package/esm/commands/image.js +39 -16
- package/esm/commands/index.d.ts +3 -1
- package/esm/commands/index.js +3 -1
- package/esm/commands/issue.d.ts +2 -0
- package/esm/commands/issue.js +41 -0
- package/esm/commands/italic.js +9 -13
- package/esm/commands/link.js +40 -14
- package/esm/commands/list.d.ts +3 -10
- package/esm/commands/list.js +39 -41
- package/esm/commands/quote.js +8 -8
- package/esm/commands/strikeThrough.js +9 -13
- package/esm/commands/table.d.ts +2 -0
- package/esm/commands/table.js +57 -0
- package/esm/commands/title.d.ts +7 -1
- package/esm/commands/title.js +21 -0
- package/esm/commands/title1.js +9 -7
- package/esm/commands/title2.js +9 -7
- package/esm/commands/title3.js +9 -7
- package/esm/commands/title4.js +9 -7
- package/esm/commands/title5.js +9 -7
- package/esm/commands/title6.js +9 -7
- package/esm/components/DragBar/index.js +7 -7
- package/esm/components/TextArea/handleKeyDown.js +83 -3
- package/esm/utils/InsertTextAtPosition.d.ts +0 -7
- package/esm/utils/InsertTextAtPosition.js +6 -24
- package/esm/utils/markdownUtils.d.ts +23 -1
- package/esm/utils/markdownUtils.js +83 -4
- package/lib/Context.js +2 -3
- package/lib/Editor.js +1 -2
- package/lib/commands/bold.js +10 -15
- package/lib/commands/code.d.ts +1 -1
- package/lib/commands/code.js +75 -70
- package/lib/commands/comment.js +21 -20
- package/lib/commands/divider.js +2 -3
- package/lib/commands/fullscreen.js +2 -3
- package/lib/commands/group.js +2 -3
- package/lib/commands/help.d.ts +2 -0
- package/lib/commands/help.js +29 -0
- package/lib/commands/hr.js +35 -5
- package/lib/commands/image.js +40 -18
- package/lib/commands/index.d.ts +3 -1
- package/lib/commands/index.js +8 -10
- package/lib/commands/issue.d.ts +2 -0
- package/lib/commands/issue.js +48 -0
- package/lib/commands/italic.js +10 -15
- package/lib/commands/link.js +41 -16
- package/lib/commands/list.d.ts +3 -10
- package/lib/commands/list.js +43 -52
- package/lib/commands/preview.js +4 -7
- package/lib/commands/quote.js +9 -10
- package/lib/commands/strikeThrough.js +10 -15
- package/lib/commands/table.d.ts +2 -0
- package/lib/commands/table.js +64 -0
- package/lib/commands/title.d.ts +7 -1
- package/lib/commands/title.js +23 -3
- package/lib/commands/title1.js +11 -10
- package/lib/commands/title2.js +11 -10
- package/lib/commands/title3.js +11 -10
- package/lib/commands/title4.js +11 -10
- package/lib/commands/title5.js +11 -10
- package/lib/commands/title6.js +11 -10
- package/lib/components/DragBar/index.js +8 -9
- package/lib/components/TextArea/handleKeyDown.js +84 -4
- package/lib/index.js +1 -2
- package/lib/utils/InsertTextAtPosition.d.ts +0 -7
- package/lib/utils/InsertTextAtPosition.js +6 -26
- package/lib/utils/markdownUtils.d.ts +23 -1
- package/lib/utils/markdownUtils.js +84 -4
- package/package.json +4 -1
- package/src/commands/bold.tsx +13 -12
- package/src/commands/code.tsx +72 -71
- package/src/commands/comment.tsx +20 -15
- package/src/commands/help.tsx +19 -0
- package/src/commands/hr.tsx +33 -2
- package/src/commands/image.tsx +38 -15
- package/src/commands/index.ts +8 -1
- package/src/commands/issue.tsx +36 -0
- package/src/commands/italic.tsx +13 -12
- package/src/commands/link.tsx +39 -12
- package/src/commands/list.tsx +35 -53
- package/src/commands/quote.tsx +14 -13
- package/src/commands/strikeThrough.tsx +13 -12
- package/src/commands/table.tsx +52 -0
- package/src/commands/title.tsx +18 -1
- package/src/commands/title1.tsx +6 -9
- package/src/commands/title2.tsx +6 -9
- package/src/commands/title3.tsx +6 -9
- package/src/commands/title4.tsx +6 -9
- package/src/commands/title5.tsx +6 -9
- package/src/commands/title6.tsx +6 -9
- package/src/components/TextArea/handleKeyDown.tsx +50 -3
- package/src/utils/InsertTextAtPosition.ts +7 -28
- package/src/utils/markdownUtils.ts +94 -4
- package/src/__test__/commands.test.tsx +0 -512
- package/src/__test__/editor.test.tsx +0 -88
- 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/
|
|
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={
|
|
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)}>{
|
|
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
|
|
647
|
-
const
|
|
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 (
|
|
672
|
+
if (container && isMermaid) {
|
|
650
673
|
try {
|
|
651
|
-
const str = mermaid.render(demoid.current, code
|
|
652
|
-
|
|
653
|
-
demo.current.innerHTML = str;
|
|
674
|
+
const str = mermaid.render(demoid.current, code);
|
|
675
|
+
container.innerHTML = str;
|
|
654
676
|
} catch (error) {
|
|
655
|
-
|
|
656
|
-
demo.current.innerHTML = error;
|
|
677
|
+
container.innerHTML = error;
|
|
657
678
|
}
|
|
658
679
|
}
|
|
659
|
-
}, [code,
|
|
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
|
-
<
|
|
690
|
+
<Fragment>
|
|
667
691
|
<code id={demoid.current} style={{ display: "none" }} />
|
|
668
|
-
|
|
692
|
+
<code ref={refElement} data-name="mermaid" />
|
|
693
|
+
</Fragment>
|
|
669
694
|
);
|
|
670
695
|
}
|
|
671
|
-
return <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;
|