@uiw/react-md-editor 3.15.0 → 3.17.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.
Files changed (48) hide show
  1. package/README.md +69 -2
  2. package/dist/mdeditor.css +15 -5
  3. package/dist/mdeditor.js +70 -653
  4. package/dist/mdeditor.min.css +1 -1
  5. package/dist/mdeditor.min.js +1 -1
  6. package/esm/Context.d.ts +15 -0
  7. package/esm/Context.js.map +2 -2
  8. package/esm/Editor.d.ts +19 -1
  9. package/esm/Editor.js +4 -8
  10. package/esm/Editor.js.map +4 -3
  11. package/esm/commands/index.d.ts +2 -0
  12. package/esm/commands/index.js.map +2 -2
  13. package/esm/components/DragBar/index.css +1 -0
  14. package/esm/components/DragBar/index.less +1 -0
  15. package/esm/components/Toolbar/Child.js +0 -1
  16. package/esm/components/Toolbar/Child.js.map +2 -2
  17. package/esm/components/Toolbar/index.css +2 -1
  18. package/esm/components/Toolbar/index.d.ts +0 -2
  19. package/esm/components/Toolbar/index.js +4 -5
  20. package/esm/components/Toolbar/index.js.map +7 -3
  21. package/esm/components/Toolbar/index.less +2 -1
  22. package/esm/index.css +10 -3
  23. package/esm/index.less +9 -3
  24. package/lib/Context.d.ts +15 -0
  25. package/lib/Context.js.map +2 -2
  26. package/lib/Editor.d.ts +19 -1
  27. package/lib/Editor.js +4 -9
  28. package/lib/Editor.js.map +4 -3
  29. package/lib/commands/index.d.ts +2 -0
  30. package/lib/commands/index.js.map +2 -2
  31. package/lib/components/DragBar/index.less +1 -0
  32. package/lib/components/Toolbar/Child.js +0 -1
  33. package/lib/components/Toolbar/Child.js.map +2 -2
  34. package/lib/components/Toolbar/index.d.ts +0 -2
  35. package/lib/components/Toolbar/index.js +4 -6
  36. package/lib/components/Toolbar/index.js.map +8 -4
  37. package/lib/components/Toolbar/index.less +2 -1
  38. package/lib/index.less +9 -3
  39. package/markdown-editor.css +13 -4
  40. package/package.json +2 -2
  41. package/src/Context.tsx +2 -0
  42. package/src/Editor.tsx +25 -11
  43. package/src/commands/index.ts +7 -0
  44. package/src/components/DragBar/index.less +1 -0
  45. package/src/components/Toolbar/Child.tsx +1 -1
  46. package/src/components/Toolbar/index.less +2 -1
  47. package/src/components/Toolbar/index.tsx +11 -6
  48. package/src/index.less +9 -3
package/README.md CHANGED
@@ -162,6 +162,34 @@ const title3 = {
162
162
  },
163
163
  };
164
164
 
165
+ const title2 = {
166
+ name: 'title3',
167
+ keyCommand: 'title3',
168
+ render: (command, disabled, executeCommand) => {
169
+ return (
170
+ <button
171
+ aria-label="Insert title3"
172
+ disabled={disabled}
173
+ onClick={(evn) => {
174
+ evn.stopPropagation();
175
+ executeCommand(command, command.groupName)
176
+ }}
177
+ >
178
+ <svg width="12" height="12" viewBox="0 0 520 520">
179
+ <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" />
180
+ </svg>
181
+ </button>
182
+ )
183
+ },
184
+ execute: (state, api) => {
185
+ let modifyText = `## ${state.selectedText}\n`;
186
+ if (!state.selectedText) {
187
+ modifyText = `## `;
188
+ }
189
+ api.replaceSelection(modifyText);
190
+ },
191
+ }
192
+
165
193
  export default function App() {
166
194
  const [value, setValue] = React.useState("Hello Markdown! `Tab` key uses default behavior");
167
195
  return (
@@ -171,7 +199,7 @@ export default function App() {
171
199
  onChange={setValue}
172
200
  commands={[
173
201
  // Custom Toolbars
174
- title3,
202
+ title3, title2,
175
203
  commands.group([commands.title1, commands.title2, commands.title3, commands.title4, commands.title5, commands.title6], {
176
204
  name: 'title',
177
205
  groupName: 'title',
@@ -263,6 +291,44 @@ export default function App() {
263
291
  }
264
292
  ```
265
293
 
294
+ re-render `toolbar` element.
295
+
296
+ ```jsx mdx:preview
297
+ import React from "react";
298
+ import MDEditor, { commands } from '@uiw/react-md-editor';
299
+
300
+ export default function App() {
301
+ const [value, setValue] = React.useState("Hello Markdown! `Tab` key uses default behavior");
302
+ return (
303
+ <div className="container">
304
+ <MDEditor
305
+ value={value}
306
+ onChange={setValue}
307
+ preview="edit"
308
+ components={{
309
+ toolbar: (command, disabled, executeCommand) => {
310
+ if (command.keyCommand === 'code') {
311
+ return (
312
+ <button
313
+ aria-label="Insert code"
314
+ disabled={disabled}
315
+ onClick={(evn) => {
316
+ evn.stopPropagation();
317
+ executeCommand(command, command.groupName)
318
+ }}
319
+ >
320
+ Code
321
+ </button>
322
+ )
323
+ }
324
+ }
325
+ }}
326
+ />
327
+ </div>
328
+ );
329
+ }
330
+ ```
331
+
266
332
  ### Preview Markdown
267
333
 
268
334
  [![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)
@@ -571,7 +637,8 @@ Inherit custom color variables by adding [`.wmde-markdown-var`](https://github.c
571
637
  - `autoFocus?: true`: Can be used to make `Markdown Editor` focus itself on initialization.
572
638
  - `previewOptions?: ReactMarkdown.ReactMarkdownProps`: This is reset [@uiw/react-markdown-preview](https://github.com/uiwjs/react-markdown-preview/tree/e6e8462d9a5c64a7045e25adcb4928095d74ca37#options-props) settings.
573
639
  - `textareaProps?: TextareaHTMLAttributes`: Set the `textarea` related props.
574
- - `renderTextarea?: (props, opts) => JSX.Element;`: Use div to replace TextArea or re-render TextArea. [#193](https://github.com/uiwjs/react-md-editor/issues/193)
640
+ - ~~`renderTextarea?: (props, opts) => JSX.Element;`~~: `@deprecated` Please use ~~`renderTextarea`~~ -> `components`. Use div to replace TextArea or re-render TextArea. [#193](https://github.com/uiwjs/react-md-editor/issues/193)
641
+ - `components`: re-render textarea/toolbar element. [#419](https://github.com/uiwjs/react-md-editor/issues/419)
575
642
  - `height?: number=200`: The height of the editor. ️⚠️ `Dragbar` is invalid when **`height`** parameter percentage.
576
643
  - `visibleDragbar?: boolean=true`: Show drag and drop tool. Set the height of the editor.
577
644
  - `highlightEnable?: boolean=true`: Disable editing area code highlighting. The value is `false`, which increases the editing speed.
package/dist/mdeditor.css CHANGED
@@ -278,12 +278,12 @@ body[data-color-mode*='light'] {
278
278
  box-sizing: content-box;
279
279
  overflow: hidden;
280
280
  background: transparent;
281
+ border: 0;
281
282
  border-bottom: 1px solid var(--color-border-muted);
282
283
  height: 0.25em;
283
284
  padding: 0;
284
285
  margin: 24px 0;
285
286
  background-color: var(--color-border-default);
286
- border: 0;
287
287
  }
288
288
  .wmde-markdown input {
289
289
  font: inherit;
@@ -1166,7 +1166,7 @@ body[data-color-mode*='light'] {
1166
1166
  .w-md-editor-toolbar {
1167
1167
  border-bottom: 1px solid var(--color-border-default);
1168
1168
  background-color: var(--color-canvas-default);
1169
- padding: 0 5px 0 5px;
1169
+ padding: 5px;
1170
1170
  display: flex;
1171
1171
  justify-content: space-between;
1172
1172
  align-items: center;
@@ -1174,6 +1174,7 @@ body[data-color-mode*='light'] {
1174
1174
  -webkit-user-select: none;
1175
1175
  -moz-user-select: none;
1176
1176
  user-select: none;
1177
+ flex-wrap: wrap;
1177
1178
  }
1178
1179
  .w-md-editor-toolbar.bottom {
1179
1180
  border-bottom: 0px;
@@ -1240,6 +1241,7 @@ body[data-color-mode*='light'] {
1240
1241
  position: absolute;
1241
1242
  cursor: s-resize;
1242
1243
  right: 0;
1244
+ bottom: 0;
1243
1245
  margin-top: -11px;
1244
1246
  margin-right: 0;
1245
1247
  width: 14px;
@@ -1264,14 +1266,22 @@ body[data-color-mode*='light'] {
1264
1266
  box-shadow: 0 0 0 1px var(--color-border-default), 0 0 0 var(--color-border-default), 0 1px 1px var(--color-border-default);
1265
1267
  background-color: var(--color-canvas-default);
1266
1268
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
1269
+ display: flex;
1270
+ flex-direction: column;
1267
1271
  }
1268
- .w-md-editor .copied {
1269
- display: none !important;
1272
+ .w-md-editor-toolbar {
1273
+ height: -webkit-fit-content;
1274
+ height: -moz-fit-content;
1275
+ height: fit-content;
1270
1276
  }
1271
1277
  .w-md-editor-content {
1278
+ height: 100%;
1279
+ overflow: auto;
1272
1280
  position: relative;
1273
1281
  border-radius: 0 0 3px 0;
1274
- height: calc(100% - 39.1px);
1282
+ }
1283
+ .w-md-editor .copied {
1284
+ display: none !important;
1275
1285
  }
1276
1286
  .w-md-editor-input {
1277
1287
  width: 50%;