@uiw/react-md-editor 3.16.0 → 3.17.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 +56 -2
- package/dist/mdeditor.css +20 -5
- package/dist/mdeditor.js +70 -653
- package/dist/mdeditor.min.css +1 -1
- package/dist/mdeditor.min.js +1 -1
- package/esm/Context.d.ts +15 -0
- package/esm/Context.js.map +2 -2
- package/esm/Editor.d.ts +19 -1
- package/esm/Editor.js +4 -8
- package/esm/Editor.js.map +4 -3
- package/esm/commands/index.d.ts +1 -1
- package/esm/commands/index.js.map +1 -1
- package/esm/components/DragBar/index.css +1 -0
- package/esm/components/DragBar/index.less +1 -0
- package/esm/components/Toolbar/Child.js +0 -1
- package/esm/components/Toolbar/Child.js.map +2 -2
- package/esm/components/Toolbar/index.css +6 -1
- package/esm/components/Toolbar/index.d.ts +0 -2
- package/esm/components/Toolbar/index.js +4 -5
- package/esm/components/Toolbar/index.js.map +6 -3
- package/esm/components/Toolbar/index.less +6 -1
- package/esm/index.css +10 -3
- package/esm/index.less +9 -3
- package/lib/Context.d.ts +15 -0
- package/lib/Context.js.map +2 -2
- package/lib/Editor.d.ts +19 -1
- package/lib/Editor.js +4 -9
- package/lib/Editor.js.map +4 -3
- package/lib/commands/index.d.ts +1 -1
- package/lib/commands/index.js.map +1 -1
- package/lib/components/DragBar/index.less +1 -0
- package/lib/components/Toolbar/Child.js +0 -1
- package/lib/components/Toolbar/Child.js.map +2 -2
- package/lib/components/Toolbar/index.d.ts +0 -2
- package/lib/components/Toolbar/index.js +4 -6
- package/lib/components/Toolbar/index.js.map +7 -4
- package/lib/components/Toolbar/index.less +6 -1
- package/lib/index.less +9 -3
- package/markdown-editor.css +17 -4
- package/package.json +2 -2
- package/src/Context.tsx +2 -0
- package/src/Editor.tsx +25 -11
- package/src/commands/index.ts +1 -1
- package/src/components/DragBar/index.less +1 -0
- package/src/components/Toolbar/Child.tsx +1 -1
- package/src/components/Toolbar/index.less +6 -1
- package/src/components/Toolbar/index.tsx +10 -7
- package/src/index.less +9 -3
package/markdown-editor.css
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
position: absolute;
|
|
3
3
|
cursor: s-resize;
|
|
4
4
|
right: 0;
|
|
5
|
+
bottom: 0;
|
|
5
6
|
margin-top: -11px;
|
|
6
7
|
margin-right: 0;
|
|
7
8
|
width: 14px;
|
|
@@ -174,13 +175,14 @@
|
|
|
174
175
|
.w-md-editor-toolbar {
|
|
175
176
|
border-bottom: 1px solid var(--color-border-default);
|
|
176
177
|
background-color: var(--color-canvas-default);
|
|
177
|
-
padding:
|
|
178
|
+
padding: 5px 5px;
|
|
178
179
|
display: flex;
|
|
179
180
|
justify-content: space-between;
|
|
180
181
|
align-items: center;
|
|
181
182
|
border-radius: 3px 3px 0 0;
|
|
182
183
|
-webkit-user-select: none;
|
|
183
184
|
user-select: none;
|
|
185
|
+
flex-wrap: wrap;
|
|
184
186
|
}
|
|
185
187
|
.w-md-editor-toolbar.bottom {
|
|
186
188
|
border-bottom: 0px;
|
|
@@ -192,11 +194,15 @@
|
|
|
192
194
|
margin: 0;
|
|
193
195
|
padding: 0;
|
|
194
196
|
list-style: none;
|
|
197
|
+
line-height: initial;
|
|
195
198
|
}
|
|
196
199
|
.w-md-editor-toolbar li {
|
|
197
200
|
display: inline-block;
|
|
198
201
|
font-size: 14px;
|
|
199
202
|
}
|
|
203
|
+
.w-md-editor-toolbar li + li {
|
|
204
|
+
margin: 0;
|
|
205
|
+
}
|
|
200
206
|
.w-md-editor-toolbar li > button {
|
|
201
207
|
border: none;
|
|
202
208
|
height: 20px;
|
|
@@ -251,14 +257,21 @@
|
|
|
251
257
|
box-shadow: 0 0 0 1px var(--color-border-default), 0 0 0 var(--color-border-default), 0 1px 1px var(--color-border-default);
|
|
252
258
|
background-color: var(--color-canvas-default);
|
|
253
259
|
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
|
260
|
+
display: flex;
|
|
261
|
+
flex-direction: column;
|
|
254
262
|
}
|
|
255
|
-
.w-md-editor
|
|
256
|
-
|
|
263
|
+
.w-md-editor-toolbar {
|
|
264
|
+
height: -webkit-fit-content;
|
|
265
|
+
height: fit-content;
|
|
257
266
|
}
|
|
258
267
|
.w-md-editor-content {
|
|
268
|
+
height: 100%;
|
|
269
|
+
overflow: auto;
|
|
259
270
|
position: relative;
|
|
260
271
|
border-radius: 0 0 3px 0;
|
|
261
|
-
|
|
272
|
+
}
|
|
273
|
+
.w-md-editor .copied {
|
|
274
|
+
display: none !important;
|
|
262
275
|
}
|
|
263
276
|
.w-md-editor-input {
|
|
264
277
|
width: 50%;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uiw/react-md-editor",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.17.2",
|
|
4
4
|
"description": "A markdown editor with preview, implemented with React.js and TypeScript.",
|
|
5
5
|
"homepage": "https://uiwjs.github.io/react-md-editor/",
|
|
6
6
|
"author": "kenny wang <wowohoo@qq.com>",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@babel/runtime": "^7.14.6",
|
|
39
|
-
"@uiw/react-markdown-preview": "^4.0.
|
|
39
|
+
"@uiw/react-markdown-preview": "^4.0.24",
|
|
40
40
|
"rehype": "~12.0.1"
|
|
41
41
|
},
|
|
42
42
|
"keywords": [
|
package/src/Context.tsx
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ICommand, TextAreaCommandOrchestrator } from './commands';
|
|
3
|
+
import { MDEditorProps } from './Editor';
|
|
3
4
|
|
|
4
5
|
export type PreviewType = 'live' | 'edit' | 'preview';
|
|
5
6
|
|
|
6
7
|
export type ContextStore = {
|
|
8
|
+
components?: MDEditorProps['components'];
|
|
7
9
|
commands?: ICommand<string>[];
|
|
8
10
|
extraCommands?: ICommand<string>[];
|
|
9
11
|
markdown?: string;
|
package/src/Editor.tsx
CHANGED
|
@@ -39,6 +39,9 @@ export interface MDEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>
|
|
|
39
39
|
/**
|
|
40
40
|
* Custom toolbar heigth
|
|
41
41
|
* @default 29px
|
|
42
|
+
*
|
|
43
|
+
* @deprecated toolbar height adaptive: https://github.com/uiwjs/react-md-editor/issues/427
|
|
44
|
+
*
|
|
42
45
|
*/
|
|
43
46
|
toolbarHeight?: number;
|
|
44
47
|
/**
|
|
@@ -77,8 +80,23 @@ export interface MDEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>
|
|
|
77
80
|
* Set the `textarea` related props.
|
|
78
81
|
*/
|
|
79
82
|
textareaProps?: ITextAreaProps;
|
|
80
|
-
/**
|
|
83
|
+
/**
|
|
84
|
+
* Use div to replace TextArea or re-render TextArea
|
|
85
|
+
* @deprecated Please use ~~`renderTextarea`~~ -> `components`
|
|
86
|
+
*/
|
|
81
87
|
renderTextarea?: ITextAreaProps['renderTextarea'];
|
|
88
|
+
/**
|
|
89
|
+
* re-render element
|
|
90
|
+
*/
|
|
91
|
+
components?: {
|
|
92
|
+
/** Use div to replace TextArea or re-render TextArea */
|
|
93
|
+
textarea?: ITextAreaProps['renderTextarea'];
|
|
94
|
+
/**
|
|
95
|
+
* Override the default command element
|
|
96
|
+
* _`toolbar`_ < _`command[].render`_
|
|
97
|
+
*/
|
|
98
|
+
toolbar?: ICommand['render'];
|
|
99
|
+
};
|
|
82
100
|
/**
|
|
83
101
|
* Disable editing area code highlighting. The value is `false`, which increases the editing speed.
|
|
84
102
|
* @default true
|
|
@@ -135,7 +153,6 @@ const InternalMDEditor = (
|
|
|
135
153
|
commandsFilter,
|
|
136
154
|
extraCommands = getExtraCommands(),
|
|
137
155
|
height = 200,
|
|
138
|
-
toolbarHeight = 29,
|
|
139
156
|
enableScroll = true,
|
|
140
157
|
visibleDragbar = typeof props.visiableDragbar === 'boolean' ? props.visiableDragbar : true,
|
|
141
158
|
highlightEnable = true,
|
|
@@ -153,6 +170,7 @@ const InternalMDEditor = (
|
|
|
153
170
|
onHeightChange,
|
|
154
171
|
hideToolbar,
|
|
155
172
|
toolbarBottom = false,
|
|
173
|
+
components,
|
|
156
174
|
renderTextarea,
|
|
157
175
|
...other
|
|
158
176
|
} = props || {};
|
|
@@ -165,6 +183,7 @@ const InternalMDEditor = (
|
|
|
165
183
|
let [state, dispatch] = useReducer(reducer, {
|
|
166
184
|
markdown: propsValue,
|
|
167
185
|
preview: previewType,
|
|
186
|
+
components,
|
|
168
187
|
height,
|
|
169
188
|
highlightEnable,
|
|
170
189
|
tabSize,
|
|
@@ -303,14 +322,9 @@ const InternalMDEditor = (
|
|
|
303
322
|
}}
|
|
304
323
|
>
|
|
305
324
|
{!hideToolbar && !toolbarBottom && (
|
|
306
|
-
<Toolbar prefixCls={prefixCls}
|
|
325
|
+
<Toolbar prefixCls={prefixCls} overflow={overflow} toolbarBottom={toolbarBottom} />
|
|
307
326
|
)}
|
|
308
|
-
<div
|
|
309
|
-
className={`${prefixCls}-content`}
|
|
310
|
-
style={{
|
|
311
|
-
height: `calc(100% - ${toolbarHeight}px)`,
|
|
312
|
-
}}
|
|
313
|
-
>
|
|
327
|
+
<div className={`${prefixCls}-content`}>
|
|
314
328
|
{/(edit|live)/.test(state.preview || '') && (
|
|
315
329
|
<TextArea
|
|
316
330
|
className={`${prefixCls}-input`}
|
|
@@ -323,7 +337,7 @@ const InternalMDEditor = (
|
|
|
323
337
|
textareaProps.onChange(evn);
|
|
324
338
|
}
|
|
325
339
|
}}
|
|
326
|
-
renderTextarea={renderTextarea}
|
|
340
|
+
renderTextarea={components?.textarea || renderTextarea}
|
|
327
341
|
onScroll={(e) => handleScroll(e, 'text')}
|
|
328
342
|
/>
|
|
329
343
|
)}
|
|
@@ -341,7 +355,7 @@ const InternalMDEditor = (
|
|
|
341
355
|
/>
|
|
342
356
|
)}
|
|
343
357
|
{!hideToolbar && toolbarBottom && (
|
|
344
|
-
<Toolbar prefixCls={prefixCls}
|
|
358
|
+
<Toolbar prefixCls={prefixCls} overflow={overflow} toolbarBottom={toolbarBottom} />
|
|
345
359
|
)}
|
|
346
360
|
</div>
|
|
347
361
|
</EditorContext.Provider>
|
package/src/commands/index.ts
CHANGED
|
@@ -56,7 +56,7 @@ export interface ICommandBase<T> {
|
|
|
56
56
|
disabled: boolean,
|
|
57
57
|
executeCommand: (command: ICommand<T>, name?: string) => void,
|
|
58
58
|
index: number,
|
|
59
|
-
) => React.ReactElement;
|
|
59
|
+
) => void | undefined | null | React.ReactElement;
|
|
60
60
|
execute?: (
|
|
61
61
|
state: TextState,
|
|
62
62
|
api: TextAreaTextApi,
|
|
@@ -17,7 +17,7 @@ export default function Child(props: ChildProps) {
|
|
|
17
17
|
className={`${prefixCls}-toolbar-child ${groupName && barPopup[groupName] ? 'active' : ''}`}
|
|
18
18
|
onClick={(e) => e.stopPropagation()}
|
|
19
19
|
>
|
|
20
|
-
{Array.isArray(commands) ? <Toolbar commands={commands} {...props}
|
|
20
|
+
{Array.isArray(commands) ? <Toolbar commands={commands} {...props} isChild /> : children}
|
|
21
21
|
</div>
|
|
22
22
|
),
|
|
23
23
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -4,12 +4,13 @@
|
|
|
4
4
|
&-toolbar {
|
|
5
5
|
border-bottom: 1px solid var(--color-border-default);
|
|
6
6
|
background-color: var(--color-canvas-default);
|
|
7
|
-
padding:
|
|
7
|
+
padding: 5px 5px;
|
|
8
8
|
display: flex;
|
|
9
9
|
justify-content: space-between;
|
|
10
10
|
align-items: center;
|
|
11
11
|
border-radius: 3px 3px 0 0;
|
|
12
12
|
user-select: none;
|
|
13
|
+
flex-wrap: wrap;
|
|
13
14
|
&.bottom {
|
|
14
15
|
border-bottom: 0px;
|
|
15
16
|
border-top: 1px solid var(--color-border-default);
|
|
@@ -20,10 +21,14 @@
|
|
|
20
21
|
margin: 0;
|
|
21
22
|
padding: 0;
|
|
22
23
|
list-style: none;
|
|
24
|
+
line-height: initial;
|
|
23
25
|
}
|
|
24
26
|
li {
|
|
25
27
|
display: inline-block;
|
|
26
28
|
font-size: 14px;
|
|
29
|
+
& + li {
|
|
30
|
+
margin: 0;
|
|
31
|
+
}
|
|
27
32
|
> button {
|
|
28
33
|
border: none;
|
|
29
34
|
height: 20px;
|
|
@@ -7,7 +7,6 @@ import './index.less';
|
|
|
7
7
|
|
|
8
8
|
export interface IToolbarProps extends IProps {
|
|
9
9
|
overflow?: boolean;
|
|
10
|
-
height?: React.CSSProperties['height'];
|
|
11
10
|
toolbarBottom?: boolean;
|
|
12
11
|
onCommand?: (command: ICommand<string>, groupName?: string) => void;
|
|
13
12
|
commands?: ICommand<string>[];
|
|
@@ -16,7 +15,7 @@ export interface IToolbarProps extends IProps {
|
|
|
16
15
|
|
|
17
16
|
export function ToolbarItems(props: IToolbarProps) {
|
|
18
17
|
const { prefixCls, overflow } = props;
|
|
19
|
-
const { fullscreen, preview, barPopup = {}, commandOrchestrator, dispatch } = useContext(EditorContext);
|
|
18
|
+
const { fullscreen, preview, barPopup = {}, components, commandOrchestrator, dispatch } = useContext(EditorContext);
|
|
20
19
|
const originalOverflow = useRef('');
|
|
21
20
|
|
|
22
21
|
function handleClick(command: ICommand<string>, name?: string) {
|
|
@@ -83,11 +82,15 @@ export function ToolbarItems(props: IToolbarProps) {
|
|
|
83
82
|
})
|
|
84
83
|
: undefined;
|
|
85
84
|
const disabled = barPopup && preview && preview === 'preview' && !/(preview|fullscreen)/.test(item.keyCommand);
|
|
85
|
+
const render = components?.toolbar || item.render;
|
|
86
|
+
const com = (
|
|
87
|
+
render && typeof render === 'function' ? render(item, !!disabled, handleClick, idx) : null
|
|
88
|
+
) as React.ReactElement;
|
|
86
89
|
return (
|
|
87
90
|
<li key={idx} {...item.liProps} className={activeBtn ? `active` : ''}>
|
|
88
|
-
{
|
|
89
|
-
{!
|
|
90
|
-
{!
|
|
91
|
+
{com && React.isValidElement(com) && com}
|
|
92
|
+
{!com && !item.buttonProps && item.icon}
|
|
93
|
+
{!com &&
|
|
91
94
|
item.buttonProps &&
|
|
92
95
|
React.createElement(
|
|
93
96
|
'button',
|
|
@@ -121,11 +124,11 @@ export function ToolbarItems(props: IToolbarProps) {
|
|
|
121
124
|
}
|
|
122
125
|
|
|
123
126
|
export default function Toolbar(props: IToolbarProps = {}) {
|
|
124
|
-
const { prefixCls,
|
|
127
|
+
const { prefixCls, toolbarBottom, isChild } = props;
|
|
125
128
|
const { commands, extraCommands } = useContext(EditorContext);
|
|
126
129
|
const bottomClassName = toolbarBottom ? 'bottom' : '';
|
|
127
130
|
return (
|
|
128
|
-
<div className={`${prefixCls}-toolbar ${bottomClassName}`}
|
|
131
|
+
<div className={`${prefixCls}-toolbar ${bottomClassName}`}>
|
|
129
132
|
<ToolbarItems {...props} commands={props.commands || commands || []} />
|
|
130
133
|
{!isChild && <ToolbarItems {...props} commands={extraCommands || []} />}
|
|
131
134
|
</div>
|
package/src/index.less
CHANGED
|
@@ -10,13 +10,19 @@
|
|
|
10
10
|
0 1px 1px var(--color-border-default);
|
|
11
11
|
background-color: var(--color-canvas-default);
|
|
12
12
|
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
display: flex;
|
|
14
|
+
flex-direction: column;
|
|
15
|
+
&-toolbar {
|
|
16
|
+
height: fit-content;
|
|
15
17
|
}
|
|
16
18
|
&-content {
|
|
19
|
+
height: 100%;
|
|
20
|
+
overflow: auto;
|
|
17
21
|
position: relative;
|
|
18
22
|
border-radius: 0 0 3px 0;
|
|
19
|
-
|
|
23
|
+
}
|
|
24
|
+
.copied {
|
|
25
|
+
display: none !important;
|
|
20
26
|
}
|
|
21
27
|
&-input {
|
|
22
28
|
width: 50%;
|