@uiw/react-md-editor 3.14.4 → 3.16.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 +119 -3
- package/dist/mdeditor.css +1 -6
- package/dist/mdeditor.js +818 -350
- package/dist/mdeditor.min.css +1 -1
- package/dist/mdeditor.min.js +1 -1
- package/esm/Context.d.ts +2 -2
- package/esm/Context.js.map +1 -1
- package/esm/Editor.d.ts +4 -3
- package/esm/Editor.js +2 -2
- package/esm/Editor.js.map +2 -3
- package/esm/commands/group.d.ts +1 -1
- package/esm/commands/index.d.ts +2 -0
- package/esm/commands/index.js.map +2 -2
- package/esm/components/Toolbar/index.js +1 -1
- package/esm/components/Toolbar/index.js.map +3 -2
- package/esm/index.css +1 -0
- package/esm/index.less +1 -0
- package/lib/Context.d.ts +2 -2
- package/lib/Context.js.map +1 -1
- package/lib/Editor.d.ts +4 -3
- package/lib/Editor.js +2 -2
- package/lib/Editor.js.map +2 -3
- package/lib/commands/group.d.ts +1 -1
- package/lib/commands/index.d.ts +2 -0
- package/lib/commands/index.js.map +2 -2
- package/lib/components/Toolbar/index.js +1 -1
- package/lib/components/Toolbar/index.js.map +3 -2
- package/lib/index.less +1 -0
- package/markdown-editor.css +1 -0
- package/package.json +2 -2
- package/src/Context.tsx +1 -1
- package/src/Editor.tsx +6 -6
- package/src/commands/index.ts +7 -0
- package/src/components/Toolbar/index.tsx +4 -2
- package/src/index.less +1 -0
package/README.md
CHANGED
|
@@ -77,6 +77,39 @@ export default function App() {
|
|
|
77
77
|
}
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
+
### Special Markdown syntax
|
|
81
|
+
|
|
82
|
+
**Supports for CSS Style**
|
|
83
|
+
|
|
84
|
+
Use HTML comments `<!--rehype:xxx-->`<!--rehype:style=color: red; font-weight: bold;--> to let Markdown support style customization.
|
|
85
|
+
|
|
86
|
+
```markdown
|
|
87
|
+
## Title
|
|
88
|
+
<!--rehype:style=display: flex; height: 230px; align-items: center; justify-content: center; font-size: 38px;-->
|
|
89
|
+
|
|
90
|
+
Markdown Supports **Style**<!--rehype:style=color: red;-->
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
**Ignore content display via HTML comments**
|
|
94
|
+
|
|
95
|
+
Shown in GitHub readme, excluded in HTML.
|
|
96
|
+
|
|
97
|
+
```markdown
|
|
98
|
+
# Hello World
|
|
99
|
+
|
|
100
|
+
<!--rehype:ignore:start-->Hello World<!--rehype:ignore:end-->
|
|
101
|
+
|
|
102
|
+
Good!
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Output:
|
|
106
|
+
|
|
107
|
+
```html
|
|
108
|
+
<h1>Hello World</h1>
|
|
109
|
+
|
|
110
|
+
<p>Good!</p>
|
|
111
|
+
```
|
|
112
|
+
|
|
80
113
|
### Security
|
|
81
114
|
|
|
82
115
|
Please note markdown needs to be sanitized if you do not **completely trust** your authors.
|
|
@@ -129,6 +162,34 @@ const title3 = {
|
|
|
129
162
|
},
|
|
130
163
|
};
|
|
131
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
|
+
|
|
132
193
|
export default function App() {
|
|
133
194
|
const [value, setValue] = React.useState("Hello Markdown! `Tab` key uses default behavior");
|
|
134
195
|
return (
|
|
@@ -138,7 +199,61 @@ export default function App() {
|
|
|
138
199
|
onChange={setValue}
|
|
139
200
|
commands={[
|
|
140
201
|
// Custom Toolbars
|
|
141
|
-
title3,
|
|
202
|
+
title3, title2,
|
|
203
|
+
commands.group([commands.title1, commands.title2, commands.title3, commands.title4, commands.title5, commands.title6], {
|
|
204
|
+
name: 'title',
|
|
205
|
+
groupName: 'title',
|
|
206
|
+
buttonProps: { 'aria-label': 'Insert title'}
|
|
207
|
+
}),
|
|
208
|
+
commands.divider,
|
|
209
|
+
commands.group([], {
|
|
210
|
+
name: 'update',
|
|
211
|
+
groupName: 'update',
|
|
212
|
+
icon: (
|
|
213
|
+
<svg viewBox="0 0 1024 1024" width="12" height="12">
|
|
214
|
+
<path fill="currentColor" d="M716.8 921.6a51.2 51.2 0 1 1 0 102.4H307.2a51.2 51.2 0 1 1 0-102.4h409.6zM475.8016 382.1568a51.2 51.2 0 0 1 72.3968 0l144.8448 144.8448a51.2 51.2 0 0 1-72.448 72.3968L563.2 541.952V768a51.2 51.2 0 0 1-45.2096 50.8416L512 819.2a51.2 51.2 0 0 1-51.2-51.2v-226.048l-57.3952 57.4464a51.2 51.2 0 0 1-67.584 4.2496l-4.864-4.2496a51.2 51.2 0 0 1 0-72.3968zM512 0c138.6496 0 253.4912 102.144 277.1456 236.288l10.752 0.3072C924.928 242.688 1024 348.0576 1024 476.5696 1024 608.9728 918.8352 716.8 788.48 716.8a51.2 51.2 0 1 1 0-102.4l8.3968-0.256C866.2016 609.6384 921.6 550.0416 921.6 476.5696c0-76.4416-59.904-137.8816-133.12-137.8816h-97.28v-51.2C691.2 184.9856 610.6624 102.4 512 102.4S332.8 184.9856 332.8 287.488v51.2H235.52c-73.216 0-133.12 61.44-133.12 137.8816C102.4 552.96 162.304 614.4 235.52 614.4l5.9904 0.3584A51.2 51.2 0 0 1 235.52 716.8C105.1648 716.8 0 608.9728 0 476.5696c0-132.1984 104.8064-239.872 234.8544-240.2816C258.5088 102.144 373.3504 0 512 0z" />
|
|
215
|
+
</svg>
|
|
216
|
+
),
|
|
217
|
+
children: ({ close, execute, getState, textApi }) => {
|
|
218
|
+
return (
|
|
219
|
+
<div style={{ width: 120, padding: 10 }}>
|
|
220
|
+
<div>My Custom Toolbar</div>
|
|
221
|
+
<button type="button" onClick={() => console.log('> execute: >>>>>', getState())}>State</button>
|
|
222
|
+
<button type="button" onClick={() => close()}>Close</button>
|
|
223
|
+
<button type="button" onClick={() => execute()}>Execute</button>
|
|
224
|
+
</div>
|
|
225
|
+
);
|
|
226
|
+
},
|
|
227
|
+
execute: (state, api) => {
|
|
228
|
+
console.log('>>>>>>update>>>>>', state)
|
|
229
|
+
},
|
|
230
|
+
buttonProps: { 'aria-label': 'Insert title'}
|
|
231
|
+
}),
|
|
232
|
+
]}
|
|
233
|
+
/>
|
|
234
|
+
</div>
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Customize the toolbar with `commands` and `extraCommands` props.
|
|
240
|
+
|
|
241
|
+
```jsx mdx:preview
|
|
242
|
+
import React from "react";
|
|
243
|
+
import MDEditor, { commands } from '@uiw/react-md-editor';
|
|
244
|
+
|
|
245
|
+
export default function App() {
|
|
246
|
+
const [value, setValue] = React.useState("Hello Markdown! `Tab` key uses default behavior");
|
|
247
|
+
return (
|
|
248
|
+
<div className="container">
|
|
249
|
+
<MDEditor
|
|
250
|
+
value={value}
|
|
251
|
+
onChange={setValue}
|
|
252
|
+
preview="edit"
|
|
253
|
+
commands={[
|
|
254
|
+
commands.codeEdit, commands.codePreview
|
|
255
|
+
]}
|
|
256
|
+
extraCommands={[
|
|
142
257
|
commands.group([commands.title1, commands.title2, commands.title3, commands.title4, commands.title5, commands.title6], {
|
|
143
258
|
name: 'title',
|
|
144
259
|
groupName: 'title',
|
|
@@ -168,6 +283,7 @@ export default function App() {
|
|
|
168
283
|
},
|
|
169
284
|
buttonProps: { 'aria-label': 'Insert title'}
|
|
170
285
|
}),
|
|
286
|
+
commands.divider, commands.fullscreen
|
|
171
287
|
]}
|
|
172
288
|
/>
|
|
173
289
|
</div>
|
|
@@ -476,7 +592,7 @@ Inherit custom color variables by adding [`.wmde-markdown-var`](https://github.c
|
|
|
476
592
|
|
|
477
593
|
- `value: string`: The Markdown value.
|
|
478
594
|
- `onChange?: (value?: string, event?: React.ChangeEvent<HTMLTextAreaElement>, state?: ContextStore)`: Event handler for the `onChange` event.
|
|
479
|
-
- `onHeightChange?: (value?:
|
|
595
|
+
- `onHeightChange?: ((value?: CSSProperties['height'], oldValue?: CSSProperties['height'], state?: ContextStore)`: editor height change listener.
|
|
480
596
|
- `commands?: ICommand[]`: An array of [`ICommand`](https://github.com/uiwjs/react-md-editor/blob/d02543050c9abd8f7c72ae02b6421ac2e6ae421a/src/commands/index.ts#L39-L57), which, each one, contain a [`commands`](https://github.com/uiwjs/react-md-editor/blob/d02543050c9abd8f7c72ae02b6421ac2e6ae421a/src/commands/index.ts#L155-L180) property. If no commands are specified, the default will be used. Commands are explained in more details below.
|
|
481
597
|
- `commandsFilter?: (command: ICommand, isExtra: boolean) => false | ICommand`: Filter or modify your commands.
|
|
482
598
|
- `extraCommands?: ICommand[]`: Displayed on the right side of the toolbar.
|
|
@@ -484,7 +600,7 @@ Inherit custom color variables by adding [`.wmde-markdown-var`](https://github.c
|
|
|
484
600
|
- `previewOptions?: ReactMarkdown.ReactMarkdownProps`: This is reset [@uiw/react-markdown-preview](https://github.com/uiwjs/react-markdown-preview/tree/e6e8462d9a5c64a7045e25adcb4928095d74ca37#options-props) settings.
|
|
485
601
|
- `textareaProps?: TextareaHTMLAttributes`: Set the `textarea` related props.
|
|
486
602
|
- `renderTextarea?: (props, opts) => JSX.Element;`: Use div to replace TextArea or re-render TextArea. [#193](https://github.com/uiwjs/react-md-editor/issues/193)
|
|
487
|
-
- `height?: number=200`: The height of the editor.
|
|
603
|
+
- `height?: number=200`: The height of the editor. ️⚠️ `Dragbar` is invalid when **`height`** parameter percentage.
|
|
488
604
|
- `visibleDragbar?: boolean=true`: Show drag and drop tool. Set the height of the editor.
|
|
489
605
|
- `highlightEnable?: boolean=true`: Disable editing area code highlighting. The value is `false`, which increases the editing speed.
|
|
490
606
|
- `fullscreen?: boolean=false`: Show markdown preview.
|
package/dist/mdeditor.css
CHANGED
|
@@ -496,10 +496,6 @@ body[data-color-mode*='light'] {
|
|
|
496
496
|
color: var(--color-fg-subtle);
|
|
497
497
|
opacity: 1;
|
|
498
498
|
}
|
|
499
|
-
.wmde-markdown :-ms-input-placeholder {
|
|
500
|
-
color: var(--color-fg-subtle);
|
|
501
|
-
opacity: 1;
|
|
502
|
-
}
|
|
503
499
|
.wmde-markdown ::placeholder {
|
|
504
500
|
color: var(--color-fg-subtle);
|
|
505
501
|
opacity: 1;
|
|
@@ -1177,7 +1173,6 @@ body[data-color-mode*='light'] {
|
|
|
1177
1173
|
border-radius: 3px 3px 0 0;
|
|
1178
1174
|
-webkit-user-select: none;
|
|
1179
1175
|
-moz-user-select: none;
|
|
1180
|
-
-ms-user-select: none;
|
|
1181
1176
|
user-select: none;
|
|
1182
1177
|
}
|
|
1183
1178
|
.w-md-editor-toolbar.bottom {
|
|
@@ -1253,7 +1248,6 @@ body[data-color-mode*='light'] {
|
|
|
1253
1248
|
border-radius: 0 0 3px 0;
|
|
1254
1249
|
-webkit-user-select: none;
|
|
1255
1250
|
-moz-user-select: none;
|
|
1256
|
-
-ms-user-select: none;
|
|
1257
1251
|
user-select: none;
|
|
1258
1252
|
}
|
|
1259
1253
|
.w-md-editor-bar svg {
|
|
@@ -1331,6 +1325,7 @@ body[data-color-mode*='light'] {
|
|
|
1331
1325
|
left: 0;
|
|
1332
1326
|
right: 0;
|
|
1333
1327
|
bottom: 0;
|
|
1328
|
+
height: 100% !important;
|
|
1334
1329
|
}
|
|
1335
1330
|
.w-md-editor-fullscreen .w-md-editor-content {
|
|
1336
1331
|
height: 100%;
|