@uiw/react-md-editor 3.25.1 → 3.25.3
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 +24 -0
- package/dist/mdeditor.js +5 -5
- package/dist/mdeditor.min.js +1 -1
- package/esm/Editor.js +24 -16
- package/esm/Editor.nohighlight.js +10 -5
- package/esm/components/TextArea/index.css +2 -4
- package/esm/components/TextArea/index.js +4 -0
- package/esm/components/Toolbar/index.d.ts +9 -1
- package/esm/components/Toolbar/index.js +21 -4
- package/lib/Editor.js +25 -17
- package/lib/Editor.nohighlight.js +10 -5
- package/lib/components/TextArea/index.js +4 -0
- package/lib/components/Toolbar/index.d.ts +9 -1
- package/lib/components/Toolbar/index.js +20 -4
- package/markdown-editor.css +2 -4
- package/package.json +2 -1
- package/src/Editor.nohighlight.tsx +16 -7
- package/src/Editor.tsx +32 -22
- package/src/components/TextArea/index.tsx +3 -2
- package/src/components/Toolbar/index.tsx +19 -4
package/esm/Editor.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
|
|
3
3
|
var _excluded = ["prefixCls", "className", "value", "commands", "commandsFilter", "direction", "extraCommands", "height", "enableScroll", "visibleDragbar", "highlightEnable", "preview", "fullscreen", "overflow", "previewOptions", "textareaProps", "maxHeight", "minHeight", "autoFocus", "tabSize", "defaultTabEnable", "onChange", "onStatistics", "onHeightChange", "hideToolbar", "toolbarBottom", "components", "renderTextarea"];
|
|
4
|
-
import React, { useEffect, useReducer, useMemo, useRef, useImperativeHandle } from 'react';
|
|
4
|
+
import React, { useEffect, useReducer, useMemo, useRef, useImperativeHandle, Fragment } from 'react';
|
|
5
5
|
import MarkdownPreview from '@uiw/react-markdown-preview';
|
|
6
6
|
import TextArea from './components/TextArea';
|
|
7
|
-
import
|
|
7
|
+
import { ToolbarVisibility } from './components/Toolbar';
|
|
8
8
|
import DragBar from './components/DragBar';
|
|
9
9
|
import { getCommands, getExtraCommands, TextAreaCommandOrchestrator } from './commands';
|
|
10
10
|
import { reducer, EditorContext } from './Context';
|
|
@@ -59,6 +59,7 @@ var InternalMDEditor = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
59
59
|
preview: previewType,
|
|
60
60
|
components,
|
|
61
61
|
height,
|
|
62
|
+
minHeight,
|
|
62
63
|
highlightEnable,
|
|
63
64
|
tabSize,
|
|
64
65
|
defaultTabEnable,
|
|
@@ -211,6 +212,17 @@ var InternalMDEditor = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
211
212
|
}));
|
|
212
213
|
}
|
|
213
214
|
};
|
|
215
|
+
var contentView = /(live|preview)/.test(state.preview || '') && /*#__PURE__*/_jsxs(Fragment, {
|
|
216
|
+
children: [/*#__PURE__*/_jsx(TextArea, _extends({
|
|
217
|
+
className: prefixCls + "-input",
|
|
218
|
+
prefixCls: prefixCls,
|
|
219
|
+
autoFocus: autoFocus
|
|
220
|
+
}, textareaProps, {
|
|
221
|
+
onChange: changeHandle,
|
|
222
|
+
renderTextarea: (components == null ? void 0 : components.textarea) || renderTextarea,
|
|
223
|
+
onScroll: e => handleScroll(e, 'text')
|
|
224
|
+
})), mdPreview]
|
|
225
|
+
});
|
|
214
226
|
return /*#__PURE__*/_jsx(EditorContext.Provider, {
|
|
215
227
|
value: _extends({}, state, {
|
|
216
228
|
dispatch
|
|
@@ -221,31 +233,27 @@ var InternalMDEditor = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
221
233
|
}, other, {
|
|
222
234
|
onClick: containerClick,
|
|
223
235
|
style: containerStyle,
|
|
224
|
-
children: [
|
|
236
|
+
children: [/*#__PURE__*/_jsx(ToolbarVisibility, {
|
|
237
|
+
hideToolbar: hideToolbar,
|
|
238
|
+
toolbarBottom: toolbarBottom,
|
|
225
239
|
prefixCls: prefixCls,
|
|
226
240
|
overflow: overflow,
|
|
227
|
-
|
|
228
|
-
}), /*#__PURE__*/
|
|
241
|
+
placement: "top"
|
|
242
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
229
243
|
className: prefixCls + "-content",
|
|
230
|
-
children:
|
|
231
|
-
className: prefixCls + "-input",
|
|
232
|
-
prefixCls: prefixCls,
|
|
233
|
-
autoFocus: autoFocus
|
|
234
|
-
}, textareaProps, {
|
|
235
|
-
onChange: changeHandle,
|
|
236
|
-
renderTextarea: (components == null ? void 0 : components.textarea) || renderTextarea,
|
|
237
|
-
onScroll: e => handleScroll(e, 'text')
|
|
238
|
-
})), /(live|preview)/.test(state.preview || '') && mdPreview]
|
|
244
|
+
children: contentView
|
|
239
245
|
}), visibleDragbar && !state.fullscreen && /*#__PURE__*/_jsx(DragBar, {
|
|
240
246
|
prefixCls: prefixCls,
|
|
241
247
|
height: state.height,
|
|
242
248
|
maxHeight: maxHeight,
|
|
243
249
|
minHeight: minHeight,
|
|
244
250
|
onChange: dragBarChange
|
|
245
|
-
}),
|
|
251
|
+
}), /*#__PURE__*/_jsx(ToolbarVisibility, {
|
|
252
|
+
hideToolbar: hideToolbar,
|
|
253
|
+
toolbarBottom: toolbarBottom,
|
|
246
254
|
prefixCls: prefixCls,
|
|
247
255
|
overflow: overflow,
|
|
248
|
-
|
|
256
|
+
placement: "bottom"
|
|
249
257
|
})]
|
|
250
258
|
}))
|
|
251
259
|
});
|
|
@@ -4,7 +4,7 @@ var _excluded = ["prefixCls", "className", "value", "commands", "commandsFilter"
|
|
|
4
4
|
import React, { useEffect, useReducer, useMemo, useRef, useImperativeHandle } from 'react';
|
|
5
5
|
import MarkdownPreview from '@uiw/react-markdown-preview/nohighlight';
|
|
6
6
|
import TextArea from './components/TextArea/index.nohighlight';
|
|
7
|
-
import
|
|
7
|
+
import { ToolbarVisibility } from './components/Toolbar';
|
|
8
8
|
import DragBar from './components/DragBar';
|
|
9
9
|
import { getCommands, getExtraCommands, TextAreaCommandOrchestrator } from './commands';
|
|
10
10
|
import { reducer, EditorContext } from './Context';
|
|
@@ -59,6 +59,7 @@ var InternalMDEditor = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
59
59
|
preview: previewType,
|
|
60
60
|
components,
|
|
61
61
|
height,
|
|
62
|
+
minHeight,
|
|
62
63
|
highlightEnable,
|
|
63
64
|
tabSize,
|
|
64
65
|
defaultTabEnable,
|
|
@@ -221,10 +222,12 @@ var InternalMDEditor = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
221
222
|
}, other, {
|
|
222
223
|
onClick: containerClick,
|
|
223
224
|
style: containerStyle,
|
|
224
|
-
children: [
|
|
225
|
+
children: [/*#__PURE__*/_jsx(ToolbarVisibility, {
|
|
226
|
+
hideToolbar: hideToolbar,
|
|
227
|
+
toolbarBottom: toolbarBottom,
|
|
225
228
|
prefixCls: prefixCls,
|
|
226
229
|
overflow: overflow,
|
|
227
|
-
|
|
230
|
+
placement: "top"
|
|
228
231
|
}), /*#__PURE__*/_jsxs("div", {
|
|
229
232
|
className: prefixCls + "-content",
|
|
230
233
|
children: [/(edit|live)/.test(state.preview || '') && /*#__PURE__*/_jsx(TextArea, _extends({
|
|
@@ -242,10 +245,12 @@ var InternalMDEditor = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
242
245
|
maxHeight: maxHeight,
|
|
243
246
|
minHeight: minHeight,
|
|
244
247
|
onChange: dragBarChange
|
|
245
|
-
}),
|
|
248
|
+
}), /*#__PURE__*/_jsx(ToolbarVisibility, {
|
|
249
|
+
hideToolbar: hideToolbar,
|
|
250
|
+
toolbarBottom: toolbarBottom,
|
|
246
251
|
prefixCls: prefixCls,
|
|
247
252
|
overflow: overflow,
|
|
248
|
-
|
|
253
|
+
placement: "bottom"
|
|
249
254
|
})]
|
|
250
255
|
}))
|
|
251
256
|
});
|
|
@@ -14,8 +14,7 @@
|
|
|
14
14
|
margin: 0;
|
|
15
15
|
font-size: 14px !important;
|
|
16
16
|
line-height: 18px !important;
|
|
17
|
-
|
|
18
|
-
font-variant-ligatures: common-ligatures;
|
|
17
|
+
font-variant-ligatures: common-ligatures;
|
|
19
18
|
}
|
|
20
19
|
.w-md-editor-text-pre,
|
|
21
20
|
.w-md-editor-text-input,
|
|
@@ -29,8 +28,7 @@
|
|
|
29
28
|
font-family: var(--md-editor-font-family) !important;
|
|
30
29
|
font-size: inherit;
|
|
31
30
|
font-style: inherit;
|
|
32
|
-
|
|
33
|
-
font-variant-ligatures: inherit;
|
|
31
|
+
font-variant-ligatures: inherit;
|
|
34
32
|
font-weight: inherit;
|
|
35
33
|
letter-spacing: inherit;
|
|
36
34
|
line-height: inherit;
|
|
@@ -23,6 +23,7 @@ export default function TextArea(props) {
|
|
|
23
23
|
markdown,
|
|
24
24
|
scrollTop,
|
|
25
25
|
commands,
|
|
26
|
+
minHeight,
|
|
26
27
|
highlightEnable,
|
|
27
28
|
extraCommands,
|
|
28
29
|
dispatch
|
|
@@ -62,6 +63,9 @@ export default function TextArea(props) {
|
|
|
62
63
|
onScroll: onScroll,
|
|
63
64
|
children: /*#__PURE__*/_jsx("div", {
|
|
64
65
|
className: prefixCls + "-text",
|
|
66
|
+
style: {
|
|
67
|
+
minHeight
|
|
68
|
+
},
|
|
65
69
|
children: renderTextarea ? /*#__PURE__*/React.cloneElement(renderTextarea(_extends({}, otherProps, {
|
|
66
70
|
value: markdown,
|
|
67
71
|
autoComplete: 'off',
|
|
@@ -3,10 +3,18 @@ import { ICommand } from '../../commands';
|
|
|
3
3
|
import './index.less';
|
|
4
4
|
export interface IToolbarProps extends IProps {
|
|
5
5
|
overflow?: boolean;
|
|
6
|
-
toolbarBottom?: boolean;
|
|
7
6
|
onCommand?: (command: ICommand<string>, groupName?: string) => void;
|
|
8
7
|
commands?: ICommand<string>[];
|
|
9
8
|
isChild?: boolean;
|
|
10
9
|
}
|
|
11
10
|
export declare function ToolbarItems(props: IToolbarProps): import("react/jsx-runtime").JSX.Element;
|
|
12
11
|
export default function Toolbar(props?: IToolbarProps): import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
interface ToolbarVisibilityProps {
|
|
13
|
+
hideToolbar?: boolean;
|
|
14
|
+
toolbarBottom: boolean;
|
|
15
|
+
placement: 'bottom' | 'top';
|
|
16
|
+
overflow: boolean;
|
|
17
|
+
prefixCls: string;
|
|
18
|
+
}
|
|
19
|
+
export declare function ToolbarVisibility(props: ToolbarVisibilityProps): import("react/jsx-runtime").JSX.Element | null;
|
|
20
|
+
export {};
|
|
@@ -113,20 +113,37 @@ export default function Toolbar(props) {
|
|
|
113
113
|
}
|
|
114
114
|
var {
|
|
115
115
|
prefixCls,
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
isChild,
|
|
117
|
+
className
|
|
118
118
|
} = props;
|
|
119
119
|
var {
|
|
120
120
|
commands,
|
|
121
121
|
extraCommands
|
|
122
122
|
} = useContext(EditorContext);
|
|
123
|
-
var bottomClassName = toolbarBottom ? 'bottom' : '';
|
|
124
123
|
return /*#__PURE__*/_jsxs("div", {
|
|
125
|
-
className: prefixCls + "-toolbar " +
|
|
124
|
+
className: prefixCls + "-toolbar " + className,
|
|
126
125
|
children: [/*#__PURE__*/_jsx(ToolbarItems, _extends({}, props, {
|
|
127
126
|
commands: props.commands || commands || []
|
|
128
127
|
})), !isChild && /*#__PURE__*/_jsx(ToolbarItems, _extends({}, props, {
|
|
129
128
|
commands: extraCommands || []
|
|
130
129
|
}))]
|
|
131
130
|
});
|
|
131
|
+
}
|
|
132
|
+
export function ToolbarVisibility(props) {
|
|
133
|
+
var {
|
|
134
|
+
hideToolbar,
|
|
135
|
+
toolbarBottom,
|
|
136
|
+
placement,
|
|
137
|
+
overflow,
|
|
138
|
+
prefixCls
|
|
139
|
+
} = props;
|
|
140
|
+
if (hideToolbar || placement === 'bottom' && !toolbarBottom || placement === 'top' && toolbarBottom) {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
var cls = toolbarBottom ? 'bottom' : '';
|
|
144
|
+
return /*#__PURE__*/_jsx(Toolbar, {
|
|
145
|
+
prefixCls: prefixCls,
|
|
146
|
+
overflow: overflow,
|
|
147
|
+
className: cls
|
|
148
|
+
});
|
|
132
149
|
}
|
package/lib/Editor.js
CHANGED
|
@@ -12,7 +12,7 @@ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/h
|
|
|
12
12
|
var _react = _interopRequireWildcard(require("react"));
|
|
13
13
|
var _reactMarkdownPreview = _interopRequireDefault(require("@uiw/react-markdown-preview"));
|
|
14
14
|
var _TextArea = _interopRequireDefault(require("./components/TextArea"));
|
|
15
|
-
var _Toolbar =
|
|
15
|
+
var _Toolbar = require("./components/Toolbar");
|
|
16
16
|
var _DragBar = _interopRequireDefault(require("./components/DragBar"));
|
|
17
17
|
var _commands = require("./commands");
|
|
18
18
|
var _Context = require("./Context");
|
|
@@ -83,6 +83,7 @@ var InternalMDEditor = /*#__PURE__*/_react["default"].forwardRef(function (props
|
|
|
83
83
|
preview: previewType,
|
|
84
84
|
components: components,
|
|
85
85
|
height: height,
|
|
86
|
+
minHeight: minHeight,
|
|
86
87
|
highlightEnable: highlightEnable,
|
|
87
88
|
tabSize: tabSize,
|
|
88
89
|
defaultTabEnable: defaultTabEnable,
|
|
@@ -270,6 +271,19 @@ var InternalMDEditor = /*#__PURE__*/_react["default"].forwardRef(function (props
|
|
|
270
271
|
}));
|
|
271
272
|
}
|
|
272
273
|
};
|
|
274
|
+
var contentView = /(live|preview)/.test(state.preview || '') && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react.Fragment, {
|
|
275
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_TextArea["default"], (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
|
|
276
|
+
className: "".concat(prefixCls, "-input"),
|
|
277
|
+
prefixCls: prefixCls,
|
|
278
|
+
autoFocus: autoFocus
|
|
279
|
+
}, textareaProps), {}, {
|
|
280
|
+
onChange: changeHandle,
|
|
281
|
+
renderTextarea: (components === null || components === void 0 ? void 0 : components.textarea) || renderTextarea,
|
|
282
|
+
onScroll: function onScroll(e) {
|
|
283
|
+
return handleScroll(e, 'text');
|
|
284
|
+
}
|
|
285
|
+
})), mdPreview]
|
|
286
|
+
});
|
|
273
287
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Context.EditorContext.Provider, {
|
|
274
288
|
value: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, state), {}, {
|
|
275
289
|
dispatch: dispatch
|
|
@@ -280,33 +294,27 @@ var InternalMDEditor = /*#__PURE__*/_react["default"].forwardRef(function (props
|
|
|
280
294
|
}, other), {}, {
|
|
281
295
|
onClick: containerClick,
|
|
282
296
|
style: containerStyle,
|
|
283
|
-
children: [
|
|
297
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Toolbar.ToolbarVisibility, {
|
|
298
|
+
hideToolbar: hideToolbar,
|
|
299
|
+
toolbarBottom: toolbarBottom,
|
|
284
300
|
prefixCls: prefixCls,
|
|
285
301
|
overflow: overflow,
|
|
286
|
-
|
|
287
|
-
}), /*#__PURE__*/(0, _jsxRuntime.
|
|
302
|
+
placement: "top"
|
|
303
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
288
304
|
className: "".concat(prefixCls, "-content"),
|
|
289
|
-
children:
|
|
290
|
-
className: "".concat(prefixCls, "-input"),
|
|
291
|
-
prefixCls: prefixCls,
|
|
292
|
-
autoFocus: autoFocus
|
|
293
|
-
}, textareaProps), {}, {
|
|
294
|
-
onChange: changeHandle,
|
|
295
|
-
renderTextarea: (components === null || components === void 0 ? void 0 : components.textarea) || renderTextarea,
|
|
296
|
-
onScroll: function onScroll(e) {
|
|
297
|
-
return handleScroll(e, 'text');
|
|
298
|
-
}
|
|
299
|
-
})), /(live|preview)/.test(state.preview || '') && mdPreview]
|
|
305
|
+
children: contentView
|
|
300
306
|
}), visibleDragbar && !state.fullscreen && /*#__PURE__*/(0, _jsxRuntime.jsx)(_DragBar["default"], {
|
|
301
307
|
prefixCls: prefixCls,
|
|
302
308
|
height: state.height,
|
|
303
309
|
maxHeight: maxHeight,
|
|
304
310
|
minHeight: minHeight,
|
|
305
311
|
onChange: dragBarChange
|
|
306
|
-
}),
|
|
312
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Toolbar.ToolbarVisibility, {
|
|
313
|
+
hideToolbar: hideToolbar,
|
|
314
|
+
toolbarBottom: toolbarBottom,
|
|
307
315
|
prefixCls: prefixCls,
|
|
308
316
|
overflow: overflow,
|
|
309
|
-
|
|
317
|
+
placement: "bottom"
|
|
310
318
|
})]
|
|
311
319
|
}))
|
|
312
320
|
});
|
|
@@ -12,7 +12,7 @@ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/h
|
|
|
12
12
|
var _react = _interopRequireWildcard(require("react"));
|
|
13
13
|
var _nohighlight = _interopRequireDefault(require("@uiw/react-markdown-preview/nohighlight"));
|
|
14
14
|
var _index = _interopRequireDefault(require("./components/TextArea/index.nohighlight"));
|
|
15
|
-
var _Toolbar =
|
|
15
|
+
var _Toolbar = require("./components/Toolbar");
|
|
16
16
|
var _DragBar = _interopRequireDefault(require("./components/DragBar"));
|
|
17
17
|
var _commands = require("./commands");
|
|
18
18
|
var _Context = require("./Context");
|
|
@@ -83,6 +83,7 @@ var InternalMDEditor = /*#__PURE__*/_react["default"].forwardRef(function (props
|
|
|
83
83
|
preview: previewType,
|
|
84
84
|
components: components,
|
|
85
85
|
height: height,
|
|
86
|
+
minHeight: minHeight,
|
|
86
87
|
highlightEnable: highlightEnable,
|
|
87
88
|
tabSize: tabSize,
|
|
88
89
|
defaultTabEnable: defaultTabEnable,
|
|
@@ -280,10 +281,12 @@ var InternalMDEditor = /*#__PURE__*/_react["default"].forwardRef(function (props
|
|
|
280
281
|
}, other), {}, {
|
|
281
282
|
onClick: containerClick,
|
|
282
283
|
style: containerStyle,
|
|
283
|
-
children: [
|
|
284
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Toolbar.ToolbarVisibility, {
|
|
285
|
+
hideToolbar: hideToolbar,
|
|
286
|
+
toolbarBottom: toolbarBottom,
|
|
284
287
|
prefixCls: prefixCls,
|
|
285
288
|
overflow: overflow,
|
|
286
|
-
|
|
289
|
+
placement: "top"
|
|
287
290
|
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
288
291
|
className: "".concat(prefixCls, "-content"),
|
|
289
292
|
children: [/(edit|live)/.test(state.preview || '') && /*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
|
|
@@ -303,10 +306,12 @@ var InternalMDEditor = /*#__PURE__*/_react["default"].forwardRef(function (props
|
|
|
303
306
|
maxHeight: maxHeight,
|
|
304
307
|
minHeight: minHeight,
|
|
305
308
|
onChange: dragBarChange
|
|
306
|
-
}),
|
|
309
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Toolbar.ToolbarVisibility, {
|
|
310
|
+
hideToolbar: hideToolbar,
|
|
311
|
+
toolbarBottom: toolbarBottom,
|
|
307
312
|
prefixCls: prefixCls,
|
|
308
313
|
overflow: overflow,
|
|
309
|
-
|
|
314
|
+
placement: "bottom"
|
|
310
315
|
})]
|
|
311
316
|
}))
|
|
312
317
|
});
|
|
@@ -27,6 +27,7 @@ function TextArea(props) {
|
|
|
27
27
|
markdown = _useContext.markdown,
|
|
28
28
|
scrollTop = _useContext.scrollTop,
|
|
29
29
|
commands = _useContext.commands,
|
|
30
|
+
minHeight = _useContext.minHeight,
|
|
30
31
|
highlightEnable = _useContext.highlightEnable,
|
|
31
32
|
extraCommands = _useContext.extraCommands,
|
|
32
33
|
dispatch = _useContext.dispatch;
|
|
@@ -65,6 +66,9 @@ function TextArea(props) {
|
|
|
65
66
|
onScroll: onScroll,
|
|
66
67
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
67
68
|
className: "".concat(prefixCls, "-text"),
|
|
69
|
+
style: {
|
|
70
|
+
minHeight: minHeight
|
|
71
|
+
},
|
|
68
72
|
children: renderTextarea ? /*#__PURE__*/_react["default"].cloneElement(renderTextarea((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, otherProps), {}, {
|
|
69
73
|
value: markdown,
|
|
70
74
|
autoComplete: 'off',
|
|
@@ -3,10 +3,18 @@ import { ICommand } from '../../commands';
|
|
|
3
3
|
import './index.less';
|
|
4
4
|
export interface IToolbarProps extends IProps {
|
|
5
5
|
overflow?: boolean;
|
|
6
|
-
toolbarBottom?: boolean;
|
|
7
6
|
onCommand?: (command: ICommand<string>, groupName?: string) => void;
|
|
8
7
|
commands?: ICommand<string>[];
|
|
9
8
|
isChild?: boolean;
|
|
10
9
|
}
|
|
11
10
|
export declare function ToolbarItems(props: IToolbarProps): import("react/jsx-runtime").JSX.Element;
|
|
12
11
|
export default function Toolbar(props?: IToolbarProps): import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
interface ToolbarVisibilityProps {
|
|
13
|
+
hideToolbar?: boolean;
|
|
14
|
+
toolbarBottom: boolean;
|
|
15
|
+
placement: 'bottom' | 'top';
|
|
16
|
+
overflow: boolean;
|
|
17
|
+
prefixCls: string;
|
|
18
|
+
}
|
|
19
|
+
export declare function ToolbarVisibility(props: ToolbarVisibilityProps): import("react/jsx-runtime").JSX.Element | null;
|
|
20
|
+
export {};
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.ToolbarItems = ToolbarItems;
|
|
9
|
+
exports.ToolbarVisibility = ToolbarVisibility;
|
|
9
10
|
exports["default"] = Toolbar;
|
|
10
11
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
12
|
var _react = _interopRequireWildcard(require("react"));
|
|
@@ -121,18 +122,33 @@ function ToolbarItems(props) {
|
|
|
121
122
|
function Toolbar() {
|
|
122
123
|
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
123
124
|
var prefixCls = props.prefixCls,
|
|
124
|
-
|
|
125
|
-
|
|
125
|
+
isChild = props.isChild,
|
|
126
|
+
className = props.className;
|
|
126
127
|
var _useContext2 = (0, _react.useContext)(_Context.EditorContext),
|
|
127
128
|
commands = _useContext2.commands,
|
|
128
129
|
extraCommands = _useContext2.extraCommands;
|
|
129
|
-
var bottomClassName = toolbarBottom ? 'bottom' : '';
|
|
130
130
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
131
|
-
className: "".concat(prefixCls, "-toolbar ").concat(
|
|
131
|
+
className: "".concat(prefixCls, "-toolbar ").concat(className),
|
|
132
132
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(ToolbarItems, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, props), {}, {
|
|
133
133
|
commands: props.commands || commands || []
|
|
134
134
|
})), !isChild && /*#__PURE__*/(0, _jsxRuntime.jsx)(ToolbarItems, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, props), {}, {
|
|
135
135
|
commands: extraCommands || []
|
|
136
136
|
}))]
|
|
137
137
|
});
|
|
138
|
+
}
|
|
139
|
+
function ToolbarVisibility(props) {
|
|
140
|
+
var hideToolbar = props.hideToolbar,
|
|
141
|
+
toolbarBottom = props.toolbarBottom,
|
|
142
|
+
placement = props.placement,
|
|
143
|
+
overflow = props.overflow,
|
|
144
|
+
prefixCls = props.prefixCls;
|
|
145
|
+
if (hideToolbar || placement === 'bottom' && !toolbarBottom || placement === 'top' && toolbarBottom) {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
var cls = toolbarBottom ? 'bottom' : '';
|
|
149
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Toolbar, {
|
|
150
|
+
prefixCls: prefixCls,
|
|
151
|
+
overflow: overflow,
|
|
152
|
+
className: cls
|
|
153
|
+
});
|
|
138
154
|
}
|
package/markdown-editor.css
CHANGED
|
@@ -32,8 +32,7 @@
|
|
|
32
32
|
margin: 0;
|
|
33
33
|
font-size: 14px !important;
|
|
34
34
|
line-height: 18px !important;
|
|
35
|
-
|
|
36
|
-
font-variant-ligatures: common-ligatures;
|
|
35
|
+
font-variant-ligatures: common-ligatures;
|
|
37
36
|
}
|
|
38
37
|
.w-md-editor-text-pre,
|
|
39
38
|
.w-md-editor-text-input,
|
|
@@ -47,8 +46,7 @@
|
|
|
47
46
|
font-family: var(--md-editor-font-family) !important;
|
|
48
47
|
font-size: inherit;
|
|
49
48
|
font-style: inherit;
|
|
50
|
-
|
|
51
|
-
font-variant-ligatures: inherit;
|
|
49
|
+
font-variant-ligatures: inherit;
|
|
52
50
|
font-weight: inherit;
|
|
53
51
|
letter-spacing: inherit;
|
|
54
52
|
line-height: inherit;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uiw/react-md-editor",
|
|
3
|
-
"version": "3.25.
|
|
3
|
+
"version": "3.25.3",
|
|
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>",
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"exports": {
|
|
10
10
|
"./README.md": "./README.md",
|
|
11
11
|
"./package.json": "./package.json",
|
|
12
|
+
"./markdown-editor.css": "./markdown-editor.css",
|
|
12
13
|
".": {
|
|
13
14
|
"import": "./esm/index.js",
|
|
14
15
|
"types": "./lib/index.d.ts",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useEffect, useReducer, useMemo, useRef, useImperativeHandle } from 'react';
|
|
2
2
|
import MarkdownPreview from '@uiw/react-markdown-preview/nohighlight';
|
|
3
3
|
import TextArea from './components/TextArea/index.nohighlight';
|
|
4
|
-
import
|
|
4
|
+
import { ToolbarVisibility } from './components/Toolbar';
|
|
5
5
|
import DragBar from './components/DragBar';
|
|
6
6
|
import { getCommands, getExtraCommands, ICommand, TextState, TextAreaCommandOrchestrator } from './commands';
|
|
7
7
|
import { reducer, EditorContext, ContextStore } from './Context';
|
|
@@ -60,6 +60,7 @@ const InternalMDEditor = React.forwardRef<RefMDEditor, MDEditorProps>(
|
|
|
60
60
|
preview: previewType,
|
|
61
61
|
components,
|
|
62
62
|
height,
|
|
63
|
+
minHeight,
|
|
63
64
|
highlightEnable,
|
|
64
65
|
tabSize,
|
|
65
66
|
defaultTabEnable,
|
|
@@ -219,9 +220,13 @@ const InternalMDEditor = React.forwardRef<RefMDEditor, MDEditorProps>(
|
|
|
219
220
|
return (
|
|
220
221
|
<EditorContext.Provider value={{ ...state, dispatch }}>
|
|
221
222
|
<div ref={container} className={cls} {...other} onClick={containerClick} style={containerStyle}>
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
223
|
+
<ToolbarVisibility
|
|
224
|
+
hideToolbar={hideToolbar}
|
|
225
|
+
toolbarBottom={toolbarBottom}
|
|
226
|
+
prefixCls={prefixCls}
|
|
227
|
+
overflow={overflow}
|
|
228
|
+
placement="top"
|
|
229
|
+
/>
|
|
225
230
|
<div className={`${prefixCls}-content`}>
|
|
226
231
|
{/(edit|live)/.test(state.preview || '') && (
|
|
227
232
|
<TextArea
|
|
@@ -245,9 +250,13 @@ const InternalMDEditor = React.forwardRef<RefMDEditor, MDEditorProps>(
|
|
|
245
250
|
onChange={dragBarChange}
|
|
246
251
|
/>
|
|
247
252
|
)}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
253
|
+
<ToolbarVisibility
|
|
254
|
+
hideToolbar={hideToolbar}
|
|
255
|
+
toolbarBottom={toolbarBottom}
|
|
256
|
+
prefixCls={prefixCls}
|
|
257
|
+
overflow={overflow}
|
|
258
|
+
placement="bottom"
|
|
259
|
+
/>
|
|
251
260
|
</div>
|
|
252
261
|
</EditorContext.Provider>
|
|
253
262
|
);
|
package/src/Editor.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import React, { useEffect, useReducer, useMemo, useRef, useImperativeHandle } from 'react';
|
|
1
|
+
import React, { useEffect, useReducer, useMemo, useRef, useImperativeHandle, Fragment } from 'react';
|
|
2
2
|
import MarkdownPreview from '@uiw/react-markdown-preview';
|
|
3
3
|
import TextArea from './components/TextArea';
|
|
4
|
-
import
|
|
4
|
+
import { ToolbarVisibility } from './components/Toolbar';
|
|
5
5
|
import DragBar from './components/DragBar';
|
|
6
6
|
import { getCommands, getExtraCommands, ICommand, TextState, TextAreaCommandOrchestrator } from './commands';
|
|
7
7
|
import { reducer, EditorContext, ContextStore } from './Context';
|
|
@@ -60,6 +60,7 @@ const InternalMDEditor = React.forwardRef<RefMDEditor, MDEditorProps>(
|
|
|
60
60
|
preview: previewType,
|
|
61
61
|
components,
|
|
62
62
|
height,
|
|
63
|
+
minHeight,
|
|
63
64
|
highlightEnable,
|
|
64
65
|
tabSize,
|
|
65
66
|
defaultTabEnable,
|
|
@@ -216,26 +217,31 @@ const InternalMDEditor = React.forwardRef<RefMDEditor, MDEditorProps>(
|
|
|
216
217
|
});
|
|
217
218
|
}
|
|
218
219
|
};
|
|
220
|
+
const contentView = /(live|preview)/.test(state.preview || '') && (
|
|
221
|
+
<Fragment>
|
|
222
|
+
<TextArea
|
|
223
|
+
className={`${prefixCls}-input`}
|
|
224
|
+
prefixCls={prefixCls}
|
|
225
|
+
autoFocus={autoFocus}
|
|
226
|
+
{...textareaProps}
|
|
227
|
+
onChange={changeHandle}
|
|
228
|
+
renderTextarea={components?.textarea || renderTextarea}
|
|
229
|
+
onScroll={(e) => handleScroll(e, 'text')}
|
|
230
|
+
/>
|
|
231
|
+
{mdPreview}
|
|
232
|
+
</Fragment>
|
|
233
|
+
);
|
|
219
234
|
return (
|
|
220
235
|
<EditorContext.Provider value={{ ...state, dispatch }}>
|
|
221
236
|
<div ref={container} className={cls} {...other} onClick={containerClick} style={containerStyle}>
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
{
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
autoFocus={autoFocus}
|
|
231
|
-
{...textareaProps}
|
|
232
|
-
onChange={changeHandle}
|
|
233
|
-
renderTextarea={components?.textarea || renderTextarea}
|
|
234
|
-
onScroll={(e) => handleScroll(e, 'text')}
|
|
235
|
-
/>
|
|
236
|
-
)}
|
|
237
|
-
{/(live|preview)/.test(state.preview || '') && mdPreview}
|
|
238
|
-
</div>
|
|
237
|
+
<ToolbarVisibility
|
|
238
|
+
hideToolbar={hideToolbar}
|
|
239
|
+
toolbarBottom={toolbarBottom}
|
|
240
|
+
prefixCls={prefixCls}
|
|
241
|
+
overflow={overflow}
|
|
242
|
+
placement="top"
|
|
243
|
+
/>
|
|
244
|
+
<div className={`${prefixCls}-content`}>{contentView}</div>
|
|
239
245
|
{visibleDragbar && !state.fullscreen && (
|
|
240
246
|
<DragBar
|
|
241
247
|
prefixCls={prefixCls}
|
|
@@ -245,9 +251,13 @@ const InternalMDEditor = React.forwardRef<RefMDEditor, MDEditorProps>(
|
|
|
245
251
|
onChange={dragBarChange}
|
|
246
252
|
/>
|
|
247
253
|
)}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
254
|
+
<ToolbarVisibility
|
|
255
|
+
hideToolbar={hideToolbar}
|
|
256
|
+
toolbarBottom={toolbarBottom}
|
|
257
|
+
prefixCls={prefixCls}
|
|
258
|
+
overflow={overflow}
|
|
259
|
+
placement="bottom"
|
|
260
|
+
/>
|
|
251
261
|
</div>
|
|
252
262
|
</EditorContext.Provider>
|
|
253
263
|
);
|
|
@@ -42,7 +42,8 @@ export type TextAreaRef = {
|
|
|
42
42
|
|
|
43
43
|
export default function TextArea(props: ITextAreaProps) {
|
|
44
44
|
const { prefixCls, className, onScroll, renderTextarea, ...otherProps } = props || {};
|
|
45
|
-
const { markdown, scrollTop, commands, highlightEnable, extraCommands, dispatch } =
|
|
45
|
+
const { markdown, scrollTop, commands, minHeight, highlightEnable, extraCommands, dispatch } =
|
|
46
|
+
useContext(EditorContext);
|
|
46
47
|
const textRef = React.useRef<HTMLTextAreaElement>(null);
|
|
47
48
|
const executeRef = React.useRef<TextAreaCommandOrchestrator>();
|
|
48
49
|
const warp = React.createRef<HTMLDivElement>();
|
|
@@ -71,7 +72,7 @@ export default function TextArea(props: ITextAreaProps) {
|
|
|
71
72
|
|
|
72
73
|
return (
|
|
73
74
|
<div ref={warp} className={`${prefixCls}-area ${className || ''}`} onScroll={onScroll}>
|
|
74
|
-
<div className={`${prefixCls}-text`}>
|
|
75
|
+
<div className={`${prefixCls}-text`} style={{ minHeight }}>
|
|
75
76
|
{renderTextarea ? (
|
|
76
77
|
React.cloneElement(
|
|
77
78
|
renderTextarea(
|