@uiw/react-md-editor 3.13.0 → 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.
Files changed (72) hide show
  1. package/README.md +31 -34
  2. package/dist/mdeditor.css +20 -21
  3. package/dist/mdeditor.js +1076 -986
  4. package/dist/mdeditor.min.css +1 -1
  5. package/dist/mdeditor.min.js +1 -1
  6. package/esm/Editor.d.ts +6 -2
  7. package/esm/Editor.js +3 -3
  8. package/esm/Editor.js.map +3 -2
  9. package/esm/commands/bold.js +1 -1
  10. package/esm/commands/bold.js.map +2 -2
  11. package/esm/components/TextArea/Markdown.js +31 -24
  12. package/esm/components/TextArea/Markdown.js.map +12 -9
  13. package/esm/components/TextArea/index.js +3 -8
  14. package/esm/components/TextArea/index.js.map +2 -4
  15. package/esm/index.css +4 -0
  16. package/esm/index.less +6 -0
  17. package/lib/Context.js +3 -3
  18. package/lib/Context.js.map +1 -1
  19. package/lib/Editor.d.ts +6 -2
  20. package/lib/Editor.js +22 -22
  21. package/lib/Editor.js.map +3 -2
  22. package/lib/commands/bold.js +2 -2
  23. package/lib/commands/bold.js.map +1 -1
  24. package/lib/commands/code.js +1 -1
  25. package/lib/commands/fullscreen.js +1 -1
  26. package/lib/commands/group.js +4 -4
  27. package/lib/commands/group.js.map +1 -1
  28. package/lib/commands/hr.js +1 -1
  29. package/lib/commands/image.js +1 -1
  30. package/lib/commands/index.js +8 -8
  31. package/lib/commands/italic.js +1 -1
  32. package/lib/commands/link.js +1 -1
  33. package/lib/commands/list.js +1 -1
  34. package/lib/commands/preview.js +1 -1
  35. package/lib/commands/quote.js +1 -1
  36. package/lib/commands/strikeThrough.js +1 -1
  37. package/lib/commands/title.js +2 -2
  38. package/lib/commands/title.js.map +1 -1
  39. package/lib/commands/title1.js +1 -1
  40. package/lib/commands/title2.js +1 -1
  41. package/lib/commands/title3.js +1 -1
  42. package/lib/commands/title4.js +1 -1
  43. package/lib/commands/title5.js +1 -1
  44. package/lib/commands/title6.js +1 -1
  45. package/lib/components/DragBar/index.js +3 -3
  46. package/lib/components/TextArea/Markdown.js +39 -33
  47. package/lib/components/TextArea/Markdown.js.map +12 -9
  48. package/lib/components/TextArea/Textarea.js +10 -10
  49. package/lib/components/TextArea/Textarea.js.map +1 -1
  50. package/lib/components/TextArea/handleKeyDown.js +1 -1
  51. package/lib/components/TextArea/index.js +14 -19
  52. package/lib/components/TextArea/index.js.map +2 -4
  53. package/lib/components/TextArea/shortcuts.js +3 -3
  54. package/lib/components/TextArea/shortcuts.js.map +1 -1
  55. package/lib/components/Toolbar/Child.js +4 -4
  56. package/lib/components/Toolbar/Child.js.map +1 -1
  57. package/lib/components/Toolbar/index.js +11 -11
  58. package/lib/components/Toolbar/index.js.map +1 -1
  59. package/lib/index.js +4 -4
  60. package/lib/index.js.map +1 -1
  61. package/lib/index.less +6 -0
  62. package/lib/utils/InsertTextAtPosition.js +2 -2
  63. package/lib/utils/InsertTextAtPosition.js.map +1 -1
  64. package/markdown-editor.css +4 -0
  65. package/package.json +3 -61
  66. package/src/Editor.tsx +8 -4
  67. package/src/commands/bold.tsx +1 -1
  68. package/src/components/TextArea/Markdown.tsx +31 -24
  69. package/src/components/TextArea/index.tsx +4 -4
  70. package/src/index.less +6 -0
  71. package/LICENSE +0 -21
  72. 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
- <!--dividing-->
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
  [![Open in Github gh-pages](https://img.shields.io/badge/Open%20In-Github%20gh--pages-blue?logo=github)](https://uiwjs.github.io/react-md-editor/)
59
60
  [![Open in Gitee gh-pages](https://img.shields.io/badge/Open%20In-Gitee%20gh--pages-blue?logo=web)](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("**Hello world!!!** <IFRAME SRC="javascript:javascript:alert(window.origin);"></IFRAME>");
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
  [![Open in CodeSandbox](https://img.shields.io/badge/Open%20in-CodeSandbox-blue?logo=codesandbox)](https://codesandbox.io/embed/react-md-editor-custom-toolbars-m2n10?fontsize=14&hidenavigation=1&theme=dark)
112
109
 
113
- ```tsx
110
+ ```jsx mdx:preview
114
111
  import React from "react";
115
- import ReactDOM from "react-dom";
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: ICommand = {
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: TextState, api: TextAreaTextApi) => {
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("**Hello world!!!**");
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="Hello Markdown!"
142
- onChange={(val) => {
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!())}>State</button>
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: TextState, api: TextAreaTextApi) => {
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
  [![Open in CodeSandbox](https://img.shields.io/badge/Open%20in-CodeSandbox-blue?logo=codesandbox)](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';
@@ -207,16 +201,17 @@ The following example is preview in [CodeSandbox](https://codesandbox.io/s/markd
207
201
 
208
202
  [![Open in CodeSandbox](https://img.shields.io/badge/Open%20in-CodeSandbox-blue?logo=codesandbox)](https://codesandbox.io/embed/headless-frog-em8yg?fontsize=14&hidenavigation=1&theme=dark)
209
203
 
210
- > ⚠️ Upgrade v2 to v3 [d025430](https://github.com/uiwjs/react-md-editor/blob/d02543050c9abd8f7c72ae02b6421ac2e6ae421a/website/ExmapleKaTeX.tsx#L1-L59)
204
+ > ⚠️ Upgrade v2 to v3 [d025430](https://github.com/uiwjs/react-md-editor/blob/7b9f11ab689a7ea288df3e82c26f4f0e9a53d271/website/ExmapleKaTeX.tsx#L1-L63)
211
205
 
212
206
  ```bash
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';
214
+ import { getCodeString } from 'rehype-rewrite';
220
215
  import katex from 'katex';
221
216
  import 'katex/dist/katex.css';
222
217
 
@@ -246,15 +241,16 @@ export default function App() {
246
241
  }
247
242
  return <code>{txt}</code>;
248
243
  }
244
+ const code = props.node && props.node.children ? getCodeString(props.node.children) : txt;
249
245
  if (
250
- typeof txt === 'string' &&
246
+ typeof code === 'string' &&
251
247
  typeof className === 'string' &&
252
248
  /^language-katex/.test(className.toLocaleLowerCase())
253
249
  ) {
254
- const html = katex.renderToString(txt, {
250
+ const html = katex.renderToString(code, {
255
251
  throwOnError: false,
256
252
  });
257
- return <code dangerouslySetInnerHTML={{ __html: html }} />;
253
+ return <code style={{ fontSize: '150%' }} dangerouslySetInnerHTML={{ __html: html }} />;
258
254
  }
259
255
  return <code className={String(className)}>{txt}</code>;
260
256
  },
@@ -269,7 +265,7 @@ export default function App() {
269
265
 
270
266
  [![Open in CodeSandbox](https://img.shields.io/badge/Open%20in-CodeSandbox-blue?logo=codesandbox)](https://codesandbox.io/embed/react-md-editor-text-to-images-ijqmx?fontsize=14&hidenavigation=1&theme=dark)
271
267
 
272
- ```jsx
268
+ ```tsx mdx:preview
273
269
  import React from "react";
274
270
  import MDEditor, { commands, ICommand, TextState, TextAreaTextApi } from "@uiw/react-md-editor";
275
271
  import domToImage from "dom-to-image";
@@ -284,7 +280,7 @@ const textToImage: ICommand = {
284
280
  </svg>
285
281
  ),
286
282
  execute: (state: TextState, api: TextAreaTextApi) => {
287
- const dom = document.getElementsByClassName("w-md-editor")[0];
283
+ const dom = document.getElementsByClassName("gooooooooo")[0];
288
284
  if (dom) {
289
285
  domToImage.toJpeg(dom, {}).then((dataUrl) => {
290
286
  const link = document.createElement("a");
@@ -300,6 +296,7 @@ export default function App() {
300
296
  return (
301
297
  <div className="container">
302
298
  <MDEditor
299
+ className="gooooooooo"
303
300
  value="**Hello world!!!**"
304
301
  commands={[
305
302
  textToImage,
@@ -321,7 +318,7 @@ Using [mermaid](https://github.com/mermaid-js/mermaid) to generation of diagram
321
318
  npm install mermaid
322
319
  ```
323
320
 
324
- ```jsx
321
+ ```jsx mdx:preview
325
322
  import React, { useState, useRef, useEffect } from "react";
326
323
  import ReactDOM from "react-dom";
327
324
  import MDEditor from "@uiw/react-md-editor";
@@ -351,7 +348,7 @@ Bob-->>John: Jolly good!
351
348
  `;
352
349
 
353
350
  const randomid = () => parseInt(String(Math.random() * 1e15), 10).toString(36);
354
- const Code = ({ inline, children = [], className, ...props }: any) => {
351
+ const Code = ({ inline, children = [], className, ...props }) => {
355
352
  const demoid = useRef(`dome${randomid()}`);
356
353
  const code = getCode(children);
357
354
  const demo = useRef(null);
@@ -488,13 +485,13 @@ Inherit custom color variables by adding [`.wmde-markdown-var`](https://github.c
488
485
  - `textareaProps?: TextareaHTMLAttributes`: Set the `textarea` related props.
489
486
  - `renderTextarea?: (props, opts) => JSX.Element;`: Use div to replace TextArea or re-render TextArea. [#193](https://github.com/uiwjs/react-md-editor/issues/193)
490
487
  - `height?: number=200`: The height of the editor.
491
- - `visiableDragbar?: boolean=true`: Show drag and drop tool. Set the height of the editor.
488
+ - `visibleDragbar?: boolean=true`: Show drag and drop tool. Set the height of the editor.
492
489
  - `highlightEnable?: boolean=true`: Disable editing area code highlighting. The value is `false`, which increases the editing speed.
493
490
  - `fullscreen?: boolean=false`: Show markdown preview.
494
491
  - `overflow?: boolean=true`: Disable `fullscreen` setting body styles
495
492
  - `preview?: 'live' | 'edit' | 'preview'`: Default value `live`, Show markdown preview.
496
- - `maxHeight?: number=1200`: Maximum drag height. The `visiableDragbar=true` value is valid.
497
- - `minHeights?: number=100`: Minimum drag height. The `visiableDragbar=true` value is valid.
493
+ - `maxHeight?: number=1200`: Maximum drag height. The `visibleDragbar=true` value is valid.
494
+ - `minHeights?: number=100`: Minimum drag height. The `visibleDragbar=true` value is valid.
498
495
  - `tabSize?: number=2`: The number of characters to insert when pressing tab key. Default `2` spaces.
499
496
  - `defaultTabEnable?: boolean=false`: If `false`, the `tab` key inserts a tab character into the textarea. If `true`, the `tab` key executes default behavior e.g. focus shifts to next element.
500
497
  - `hideToolbar?: boolean=false`: Option to hide the tool bar.
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;
@@ -351,7 +353,6 @@ body[data-color-mode*='light'] {
351
353
  width: -webkit-max-content;
352
354
  width: max-content;
353
355
  max-width: 100%;
354
- overflow: auto;
355
356
  }
356
357
  .wmde-markdown td,
357
358
  .wmde-markdown th {
@@ -387,15 +388,6 @@ body[data-color-mode*='light'] {
387
388
  font-weight: 600;
388
389
  line-height: 1.25;
389
390
  }
390
- .wmde-markdown table {
391
- border-spacing: 0;
392
- border-collapse: collapse;
393
- display: block;
394
- width: -webkit-max-content;
395
- width: max-content;
396
- max-width: 100%;
397
- overflow: auto;
398
- }
399
391
  .wmde-markdown td,
400
392
  .wmde-markdown th {
401
393
  padding: 0;
@@ -878,8 +870,7 @@ body[data-color-mode*='light'] {
878
870
  .wmde-markdown .task-list-item .handle {
879
871
  display: none;
880
872
  }
881
- .wmde-markdown .task-list-item-checkbox,
882
- .wmde-markdown input[type='checkbox'] {
873
+ .wmde-markdown .task-list-item-checkbox {
883
874
  margin: 0 0.2em 0.25em -1.6em;
884
875
  vertical-align: middle;
885
876
  }
@@ -1027,10 +1018,8 @@ body[data-color-mode*='light'] {
1027
1018
  margin: 0;
1028
1019
  font-size: 14px;
1029
1020
  line-height: 18px;
1030
- -webkit-font-feature-settings: "liga", "clig";
1031
- font-feature-settings: "liga", "clig";
1032
- -webkit-font-variant-ligatures: common-ligatures;
1033
- font-variant-ligatures: common-ligatures;
1021
+ font-feature-settings: "liga", "clig";
1022
+ font-variant-ligatures: common-ligatures;
1034
1023
  }
1035
1024
  .w-md-editor-text-pre,
1036
1025
  .w-md-editor-text-input,
@@ -1043,14 +1032,14 @@ body[data-color-mode*='light'] {
1043
1032
  font-family: inherit;
1044
1033
  font-size: inherit;
1045
1034
  font-style: inherit;
1046
- -webkit-font-feature-settings: inherit;
1047
- font-feature-settings: inherit;
1048
- -webkit-font-variant-ligatures: inherit;
1049
- font-variant-ligatures: inherit;
1035
+ font-feature-settings: inherit;
1036
+ font-variant-ligatures: inherit;
1050
1037
  font-weight: inherit;
1051
1038
  letter-spacing: inherit;
1052
1039
  line-height: inherit;
1053
- tab-size: inherit;
1040
+ -moz-tab-size: inherit;
1041
+ -o-tab-size: inherit;
1042
+ tab-size: inherit;
1054
1043
  text-indent: inherit;
1055
1044
  text-rendering: inherit;
1056
1045
  text-transform: inherit;
@@ -1112,6 +1101,10 @@ body[data-color-mode*='light'] {
1112
1101
  .w-md-editor-text-input {
1113
1102
  color: transparent !important;
1114
1103
  }
1104
+ .w-md-editor-text-input::-moz-selection {
1105
+ background-color: #accef7 !important;
1106
+ color: transparent !important;
1107
+ }
1115
1108
  .w-md-editor-text-input::selection {
1116
1109
  background-color: #accef7 !important;
1117
1110
  color: transparent !important;
@@ -1183,6 +1176,7 @@ body[data-color-mode*='light'] {
1183
1176
  align-items: center;
1184
1177
  border-radius: 3px 3px 0 0;
1185
1178
  -webkit-user-select: none;
1179
+ -moz-user-select: none;
1186
1180
  -ms-user-select: none;
1187
1181
  user-select: none;
1188
1182
  }
@@ -1258,6 +1252,7 @@ body[data-color-mode*='light'] {
1258
1252
  height: 10px;
1259
1253
  border-radius: 0 0 3px 0;
1260
1254
  -webkit-user-select: none;
1255
+ -moz-user-select: none;
1261
1256
  -ms-user-select: none;
1262
1257
  user-select: none;
1263
1258
  }
@@ -1288,6 +1283,10 @@ body[data-color-mode*='light'] {
1288
1283
  width: 50%;
1289
1284
  height: 100%;
1290
1285
  }
1286
+ .w-md-editor-text-pre > code {
1287
+ word-break: break-word !important;
1288
+ white-space: pre-wrap !important;
1289
+ }
1291
1290
  .w-md-editor-preview {
1292
1291
  width: 50%;
1293
1292
  box-sizing: border-box;