@uiw/react-md-editor 3.14.1 → 3.14.2
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 +22 -27
- package/dist/mdeditor.css +20 -11
- package/dist/mdeditor.js +774 -913
- package/dist/mdeditor.min.css +1 -1
- package/dist/mdeditor.min.js +1 -1
- package/esm/commands/bold.js +1 -1
- package/esm/commands/bold.js.map +2 -2
- package/esm/components/TextArea/Markdown.js +31 -24
- package/esm/components/TextArea/Markdown.js.map +12 -9
- package/esm/components/TextArea/index.js +3 -8
- package/esm/components/TextArea/index.js.map +2 -4
- package/esm/index.css +4 -0
- package/esm/index.less +6 -0
- package/lib/Context.js +3 -3
- package/lib/Context.js.map +1 -1
- package/lib/Editor.js +19 -19
- package/lib/Editor.js.map +1 -1
- package/lib/commands/bold.js +2 -2
- package/lib/commands/bold.js.map +1 -1
- package/lib/commands/code.js +1 -1
- package/lib/commands/fullscreen.js +1 -1
- package/lib/commands/group.js +4 -4
- package/lib/commands/group.js.map +1 -1
- package/lib/commands/hr.js +1 -1
- package/lib/commands/image.js +1 -1
- package/lib/commands/index.js +8 -8
- package/lib/commands/italic.js +1 -1
- package/lib/commands/link.js +1 -1
- package/lib/commands/list.js +1 -1
- package/lib/commands/preview.js +1 -1
- package/lib/commands/quote.js +1 -1
- package/lib/commands/strikeThrough.js +1 -1
- package/lib/commands/title.js +2 -2
- package/lib/commands/title.js.map +1 -1
- package/lib/commands/title1.js +1 -1
- package/lib/commands/title2.js +1 -1
- package/lib/commands/title3.js +1 -1
- package/lib/commands/title4.js +1 -1
- package/lib/commands/title5.js +1 -1
- package/lib/commands/title6.js +1 -1
- package/lib/components/DragBar/index.js +3 -3
- package/lib/components/TextArea/Markdown.js +39 -33
- package/lib/components/TextArea/Markdown.js.map +12 -9
- package/lib/components/TextArea/Textarea.js +10 -10
- package/lib/components/TextArea/Textarea.js.map +1 -1
- package/lib/components/TextArea/handleKeyDown.js +1 -1
- package/lib/components/TextArea/index.js +14 -19
- package/lib/components/TextArea/index.js.map +2 -4
- package/lib/components/TextArea/shortcuts.js +3 -3
- package/lib/components/TextArea/shortcuts.js.map +1 -1
- package/lib/components/Toolbar/Child.js +4 -4
- package/lib/components/Toolbar/Child.js.map +1 -1
- package/lib/components/Toolbar/index.js +11 -11
- package/lib/components/Toolbar/index.js.map +1 -1
- package/lib/index.js +4 -4
- package/lib/index.js.map +1 -1
- package/lib/index.less +6 -0
- package/lib/utils/InsertTextAtPosition.js +2 -2
- package/lib/utils/InsertTextAtPosition.js.map +1 -1
- package/markdown-editor.css +4 -0
- package/package.json +2 -60
- package/src/commands/bold.tsx +1 -1
- package/src/components/TextArea/Markdown.tsx +31 -24
- package/src/components/TextArea/index.tsx +4 -4
- package/src/index.less +6 -0
- package/LICENSE +0 -21
- package/src/tsconfig.json +0 -8
package/README.md
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
<!--rehype:ignore:start-->
|
|
1
2
|
<p align="center">
|
|
2
3
|
<a href="https://uiwjs.github.io/npm-unpkg/#/pkg/@uiw/react-md-editor/file/README.md">
|
|
3
4
|
<img alt="react-md-editor logo" src="https://user-images.githubusercontent.com/1680273/146292033-0e5e57fc-6f3e-4032-9fa6-0de05f239e36.png">
|
|
@@ -32,7 +33,7 @@
|
|
|
32
33
|
</a>
|
|
33
34
|
</p>
|
|
34
35
|
|
|
35
|
-
<!--
|
|
36
|
+
<!--rehype:ignore:end-->
|
|
36
37
|
|
|
37
38
|
A simple markdown editor with preview, implemented with React.js and TypeScript. This React Component aims to provide a simple Markdown editor with syntax highlighting support. This is based on `textarea` encapsulation, so it does not depend on any modern code editors such as Acs, CodeMirror, Monaco etc.
|
|
38
39
|
|
|
@@ -58,7 +59,7 @@ npm i @uiw/react-md-editor
|
|
|
58
59
|
[](https://uiwjs.github.io/react-md-editor/)
|
|
59
60
|
[](https://uiw.gitee.io/react-md-editor/)
|
|
60
61
|
|
|
61
|
-
```jsx
|
|
62
|
+
```jsx mdx:preview
|
|
62
63
|
import React from "react";
|
|
63
64
|
import MDEditor from '@uiw/react-md-editor';
|
|
64
65
|
|
|
@@ -70,7 +71,7 @@ export default function App() {
|
|
|
70
71
|
value={value}
|
|
71
72
|
onChange={setValue}
|
|
72
73
|
/>
|
|
73
|
-
<MDEditor.Markdown source={value} />
|
|
74
|
+
<MDEditor.Markdown source={value} style={{ whiteSpace: 'pre-wrap' }} />
|
|
74
75
|
</div>
|
|
75
76
|
);
|
|
76
77
|
}
|
|
@@ -81,13 +82,13 @@ export default function App() {
|
|
|
81
82
|
Please note markdown needs to be sanitized if you do not **completely trust** your authors.
|
|
82
83
|
Otherwise, your app is vulnerable to XSS. This can be achieved by adding [rehype-sanitize](https://github.com/rehypejs/rehype-sanitize) as a plugin.
|
|
83
84
|
|
|
84
|
-
```jsx
|
|
85
|
+
```jsx mdx:preview
|
|
85
86
|
import React from "react";
|
|
86
87
|
import MDEditor from '@uiw/react-md-editor';
|
|
87
88
|
import rehypeSanitize from "rehype-sanitize";
|
|
88
89
|
|
|
89
90
|
export default function App() {
|
|
90
|
-
const [value, setValue] = React.useState(
|
|
91
|
+
const [value, setValue] = React.useState(`**Hello world!!!** <IFRAME SRC=\"javascript:javascript:alert(window.origin);\"></IFRAME>`);
|
|
91
92
|
return (
|
|
92
93
|
<div className="container">
|
|
93
94
|
<MDEditor
|
|
@@ -97,10 +98,6 @@ export default function App() {
|
|
|
97
98
|
rehypePlugins: [[rehypeSanitize]],
|
|
98
99
|
}}
|
|
99
100
|
/>
|
|
100
|
-
<MDEditor.Markdown
|
|
101
|
-
source={value}
|
|
102
|
-
rehypePlugins={[[rehypeSanitize]]}
|
|
103
|
-
/>
|
|
104
101
|
</div>
|
|
105
102
|
);
|
|
106
103
|
}
|
|
@@ -110,12 +107,11 @@ export default function App() {
|
|
|
110
107
|
|
|
111
108
|
[](https://codesandbox.io/embed/react-md-editor-custom-toolbars-m2n10?fontsize=14&hidenavigation=1&theme=dark)
|
|
112
109
|
|
|
113
|
-
```
|
|
110
|
+
```jsx mdx:preview
|
|
114
111
|
import React from "react";
|
|
115
|
-
import
|
|
116
|
-
import MDEditor, { commands, ICommand, TextState, TextAreaTextApi } from '@uiw/react-md-editor';
|
|
112
|
+
import MDEditor, { commands } from '@uiw/react-md-editor';
|
|
117
113
|
|
|
118
|
-
const title3
|
|
114
|
+
const title3 = {
|
|
119
115
|
name: 'title3',
|
|
120
116
|
keyCommand: 'title3',
|
|
121
117
|
buttonProps: { 'aria-label': 'Insert title3' },
|
|
@@ -124,7 +120,7 @@ const title3: ICommand = {
|
|
|
124
120
|
<path fill="currentColor" d="M15.7083333,468 C7.03242448,468 0,462.030833 0,454.666667 L0,421.333333 C0,413.969167 7.03242448,408 15.7083333,408 L361.291667,408 C369.967576,408 377,413.969167 377,421.333333 L377,454.666667 C377,462.030833 369.967576,468 361.291667,468 L15.7083333,468 Z M21.6666667,366 C9.69989583,366 0,359.831861 0,352.222222 L0,317.777778 C0,310.168139 9.69989583,304 21.6666667,304 L498.333333,304 C510.300104,304 520,310.168139 520,317.777778 L520,352.222222 C520,359.831861 510.300104,366 498.333333,366 L21.6666667,366 Z M136.835938,64 L136.835937,126 L107.25,126 L107.25,251 L40.75,251 L40.75,126 L-5.68434189e-14,126 L-5.68434189e-14,64 L136.835938,64 Z M212,64 L212,251 L161.648438,251 L161.648438,64 L212,64 Z M378,64 L378,126 L343.25,126 L343.25,251 L281.75,251 L281.75,126 L238,126 L238,64 L378,64 Z M449.047619,189.550781 L520,189.550781 L520,251 L405,251 L405,64 L449.047619,64 L449.047619,189.550781 Z" />
|
|
125
121
|
</svg>
|
|
126
122
|
),
|
|
127
|
-
execute: (state
|
|
123
|
+
execute: (state, api) => {
|
|
128
124
|
let modifyText = `### ${state.selectedText}\n`;
|
|
129
125
|
if (!state.selectedText) {
|
|
130
126
|
modifyText = `### `;
|
|
@@ -134,14 +130,12 @@ const title3: ICommand = {
|
|
|
134
130
|
};
|
|
135
131
|
|
|
136
132
|
export default function App() {
|
|
137
|
-
const [value, setValue] = React.useState("
|
|
133
|
+
const [value, setValue] = React.useState("Hello Markdown! `Tab` key uses default behavior");
|
|
138
134
|
return (
|
|
139
135
|
<div className="container">
|
|
140
136
|
<MDEditor
|
|
141
|
-
value=
|
|
142
|
-
onChange={
|
|
143
|
-
setValue(val!);
|
|
144
|
-
}}
|
|
137
|
+
value={value}
|
|
138
|
+
onChange={setValue}
|
|
145
139
|
commands={[
|
|
146
140
|
// Custom Toolbars
|
|
147
141
|
title3,
|
|
@@ -163,13 +157,13 @@ export default function App() {
|
|
|
163
157
|
return (
|
|
164
158
|
<div style={{ width: 120, padding: 10 }}>
|
|
165
159
|
<div>My Custom Toolbar</div>
|
|
166
|
-
<button type="button" onClick={() => console.log('> execute: >>>>>', getState
|
|
160
|
+
<button type="button" onClick={() => console.log('> execute: >>>>>', getState())}>State</button>
|
|
167
161
|
<button type="button" onClick={() => close()}>Close</button>
|
|
168
162
|
<button type="button" onClick={() => execute()}>Execute</button>
|
|
169
163
|
</div>
|
|
170
164
|
);
|
|
171
165
|
},
|
|
172
|
-
execute: (state
|
|
166
|
+
execute: (state, api) => {
|
|
173
167
|
console.log('>>>>>>update>>>>>', state)
|
|
174
168
|
},
|
|
175
169
|
buttonProps: { 'aria-label': 'Insert title'}
|
|
@@ -185,7 +179,7 @@ export default function App() {
|
|
|
185
179
|
|
|
186
180
|
[](https://codesandbox.io/embed/react-md-editor-preview-markdown-vrucl?fontsize=14&hidenavigation=1&theme=dark)
|
|
187
181
|
|
|
188
|
-
```jsx
|
|
182
|
+
```jsx mdx:preview
|
|
189
183
|
import React from "react";
|
|
190
184
|
import ReactDOM from "react-dom";
|
|
191
185
|
import MDEditor from '@uiw/react-md-editor';
|
|
@@ -213,7 +207,7 @@ The following example is preview in [CodeSandbox](https://codesandbox.io/s/markd
|
|
|
213
207
|
npm install katex
|
|
214
208
|
```
|
|
215
209
|
|
|
216
|
-
```jsx
|
|
210
|
+
```jsx mdx:preview
|
|
217
211
|
import React from "react";
|
|
218
212
|
import ReactDOM from "react-dom";
|
|
219
213
|
import MDEditor from '@uiw/react-md-editor';
|
|
@@ -271,7 +265,7 @@ export default function App() {
|
|
|
271
265
|
|
|
272
266
|
[](https://codesandbox.io/embed/react-md-editor-text-to-images-ijqmx?fontsize=14&hidenavigation=1&theme=dark)
|
|
273
267
|
|
|
274
|
-
```
|
|
268
|
+
```tsx mdx:preview
|
|
275
269
|
import React from "react";
|
|
276
270
|
import MDEditor, { commands, ICommand, TextState, TextAreaTextApi } from "@uiw/react-md-editor";
|
|
277
271
|
import domToImage from "dom-to-image";
|
|
@@ -286,7 +280,7 @@ const textToImage: ICommand = {
|
|
|
286
280
|
</svg>
|
|
287
281
|
),
|
|
288
282
|
execute: (state: TextState, api: TextAreaTextApi) => {
|
|
289
|
-
const dom = document.getElementsByClassName("
|
|
283
|
+
const dom = document.getElementsByClassName("gooooooooo")[0];
|
|
290
284
|
if (dom) {
|
|
291
285
|
domToImage.toJpeg(dom, {}).then((dataUrl) => {
|
|
292
286
|
const link = document.createElement("a");
|
|
@@ -302,6 +296,7 @@ export default function App() {
|
|
|
302
296
|
return (
|
|
303
297
|
<div className="container">
|
|
304
298
|
<MDEditor
|
|
299
|
+
className="gooooooooo"
|
|
305
300
|
value="**Hello world!!!**"
|
|
306
301
|
commands={[
|
|
307
302
|
textToImage,
|
|
@@ -323,7 +318,7 @@ Using [mermaid](https://github.com/mermaid-js/mermaid) to generation of diagram
|
|
|
323
318
|
npm install mermaid
|
|
324
319
|
```
|
|
325
320
|
|
|
326
|
-
```jsx
|
|
321
|
+
```jsx mdx:preview
|
|
327
322
|
import React, { useState, useRef, useEffect } from "react";
|
|
328
323
|
import ReactDOM from "react-dom";
|
|
329
324
|
import MDEditor from "@uiw/react-md-editor";
|
|
@@ -353,7 +348,7 @@ Bob-->>John: Jolly good!
|
|
|
353
348
|
`;
|
|
354
349
|
|
|
355
350
|
const randomid = () => parseInt(String(Math.random() * 1e15), 10).toString(36);
|
|
356
|
-
const Code = ({ inline, children = [], className, ...props }
|
|
351
|
+
const Code = ({ inline, children = [], className, ...props }) => {
|
|
357
352
|
const demoid = useRef(`dome${randomid()}`);
|
|
358
353
|
const code = getCode(children);
|
|
359
354
|
const demo = useRef(null);
|
package/dist/mdeditor.css
CHANGED
|
@@ -96,6 +96,7 @@
|
|
|
96
96
|
}
|
|
97
97
|
[data-color-mode*='dark'] .wmde-markdown,
|
|
98
98
|
[data-color-mode*='dark'] .wmde-markdown-var,
|
|
99
|
+
.wmde-markdown[data-color-mode*='dark'],
|
|
99
100
|
body[data-color-mode*='dark'] {
|
|
100
101
|
color-scheme: dark;
|
|
101
102
|
--color-prettylights-syntax-comment: #8b949e;
|
|
@@ -143,6 +144,7 @@ body[data-color-mode*='dark'] {
|
|
|
143
144
|
}
|
|
144
145
|
[data-color-mode*='light'] .wmde-markdown,
|
|
145
146
|
[data-color-mode*='light'] .wmde-markdown-var,
|
|
147
|
+
.wmde-markdown[data-color-mode*='light'],
|
|
146
148
|
body[data-color-mode*='light'] {
|
|
147
149
|
color-scheme: light;
|
|
148
150
|
--color-prettylights-syntax-comment: #6e7781;
|
|
@@ -868,8 +870,7 @@ body[data-color-mode*='light'] {
|
|
|
868
870
|
.wmde-markdown .task-list-item .handle {
|
|
869
871
|
display: none;
|
|
870
872
|
}
|
|
871
|
-
.wmde-markdown .task-list-item-checkbox
|
|
872
|
-
.wmde-markdown input[type='checkbox'] {
|
|
873
|
+
.wmde-markdown .task-list-item-checkbox {
|
|
873
874
|
margin: 0 0.2em 0.25em -1.6em;
|
|
874
875
|
vertical-align: middle;
|
|
875
876
|
}
|
|
@@ -1017,10 +1018,8 @@ body[data-color-mode*='light'] {
|
|
|
1017
1018
|
margin: 0;
|
|
1018
1019
|
font-size: 14px;
|
|
1019
1020
|
line-height: 18px;
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
-webkit-font-variant-ligatures: common-ligatures;
|
|
1023
|
-
font-variant-ligatures: common-ligatures;
|
|
1021
|
+
font-feature-settings: "liga", "clig";
|
|
1022
|
+
font-variant-ligatures: common-ligatures;
|
|
1024
1023
|
}
|
|
1025
1024
|
.w-md-editor-text-pre,
|
|
1026
1025
|
.w-md-editor-text-input,
|
|
@@ -1033,14 +1032,14 @@ body[data-color-mode*='light'] {
|
|
|
1033
1032
|
font-family: inherit;
|
|
1034
1033
|
font-size: inherit;
|
|
1035
1034
|
font-style: inherit;
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
-webkit-font-variant-ligatures: inherit;
|
|
1039
|
-
font-variant-ligatures: inherit;
|
|
1035
|
+
font-feature-settings: inherit;
|
|
1036
|
+
font-variant-ligatures: inherit;
|
|
1040
1037
|
font-weight: inherit;
|
|
1041
1038
|
letter-spacing: inherit;
|
|
1042
1039
|
line-height: inherit;
|
|
1043
|
-
tab-size: inherit;
|
|
1040
|
+
-moz-tab-size: inherit;
|
|
1041
|
+
-o-tab-size: inherit;
|
|
1042
|
+
tab-size: inherit;
|
|
1044
1043
|
text-indent: inherit;
|
|
1045
1044
|
text-rendering: inherit;
|
|
1046
1045
|
text-transform: inherit;
|
|
@@ -1102,6 +1101,10 @@ body[data-color-mode*='light'] {
|
|
|
1102
1101
|
.w-md-editor-text-input {
|
|
1103
1102
|
color: transparent !important;
|
|
1104
1103
|
}
|
|
1104
|
+
.w-md-editor-text-input::-moz-selection {
|
|
1105
|
+
background-color: #accef7 !important;
|
|
1106
|
+
color: transparent !important;
|
|
1107
|
+
}
|
|
1105
1108
|
.w-md-editor-text-input::selection {
|
|
1106
1109
|
background-color: #accef7 !important;
|
|
1107
1110
|
color: transparent !important;
|
|
@@ -1173,6 +1176,7 @@ body[data-color-mode*='light'] {
|
|
|
1173
1176
|
align-items: center;
|
|
1174
1177
|
border-radius: 3px 3px 0 0;
|
|
1175
1178
|
-webkit-user-select: none;
|
|
1179
|
+
-moz-user-select: none;
|
|
1176
1180
|
-ms-user-select: none;
|
|
1177
1181
|
user-select: none;
|
|
1178
1182
|
}
|
|
@@ -1248,6 +1252,7 @@ body[data-color-mode*='light'] {
|
|
|
1248
1252
|
height: 10px;
|
|
1249
1253
|
border-radius: 0 0 3px 0;
|
|
1250
1254
|
-webkit-user-select: none;
|
|
1255
|
+
-moz-user-select: none;
|
|
1251
1256
|
-ms-user-select: none;
|
|
1252
1257
|
user-select: none;
|
|
1253
1258
|
}
|
|
@@ -1278,6 +1283,10 @@ body[data-color-mode*='light'] {
|
|
|
1278
1283
|
width: 50%;
|
|
1279
1284
|
height: 100%;
|
|
1280
1285
|
}
|
|
1286
|
+
.w-md-editor-text-pre > code {
|
|
1287
|
+
word-break: break-word !important;
|
|
1288
|
+
white-space: pre-wrap !important;
|
|
1289
|
+
}
|
|
1281
1290
|
.w-md-editor-preview {
|
|
1282
1291
|
width: 50%;
|
|
1283
1292
|
box-sizing: border-box;
|