@uiw/react-md-editor 3.25.2 → 3.25.4

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/esm/Editor.js CHANGED
@@ -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';
6
6
  import TextArea from './components/TextArea';
7
- import Toolbar from './components/Toolbar';
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: [!hideToolbar && !toolbarBottom && /*#__PURE__*/_jsx(Toolbar, {
225
+ children: [/*#__PURE__*/_jsx(ToolbarVisibility, {
226
+ hideToolbar: hideToolbar,
227
+ toolbarBottom: toolbarBottom,
225
228
  prefixCls: prefixCls,
226
229
  overflow: overflow,
227
- toolbarBottom: toolbarBottom
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
- }), !hideToolbar && toolbarBottom && /*#__PURE__*/_jsx(Toolbar, {
248
+ }), /*#__PURE__*/_jsx(ToolbarVisibility, {
249
+ hideToolbar: hideToolbar,
250
+ toolbarBottom: toolbarBottom,
246
251
  prefixCls: prefixCls,
247
252
  overflow: overflow,
248
- toolbarBottom: toolbarBottom
253
+ placement: "bottom"
249
254
  })]
250
255
  }))
251
256
  });
@@ -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 Toolbar from './components/Toolbar';
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: [!hideToolbar && !toolbarBottom && /*#__PURE__*/_jsx(Toolbar, {
225
+ children: [/*#__PURE__*/_jsx(ToolbarVisibility, {
226
+ hideToolbar: hideToolbar,
227
+ toolbarBottom: toolbarBottom,
225
228
  prefixCls: prefixCls,
226
229
  overflow: overflow,
227
- toolbarBottom: toolbarBottom
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
- }), !hideToolbar && toolbarBottom && /*#__PURE__*/_jsx(Toolbar, {
248
+ }), /*#__PURE__*/_jsx(ToolbarVisibility, {
249
+ hideToolbar: hideToolbar,
250
+ toolbarBottom: toolbarBottom,
246
251
  prefixCls: prefixCls,
247
252
  overflow: overflow,
248
- toolbarBottom: toolbarBottom
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
- -webkit-font-variant-ligatures: common-ligatures;
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
- -webkit-font-variant-ligatures: inherit;
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
- toolbarBottom,
117
- isChild
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 " + bottomClassName,
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 = _interopRequireDefault(require("./components/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: [!hideToolbar && !toolbarBottom && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Toolbar["default"], {
284
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Toolbar.ToolbarVisibility, {
285
+ hideToolbar: hideToolbar,
286
+ toolbarBottom: toolbarBottom,
284
287
  prefixCls: prefixCls,
285
288
  overflow: overflow,
286
- toolbarBottom: toolbarBottom
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)(_TextArea["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
- }), !hideToolbar && toolbarBottom && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Toolbar["default"], {
309
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Toolbar.ToolbarVisibility, {
310
+ hideToolbar: hideToolbar,
311
+ toolbarBottom: toolbarBottom,
307
312
  prefixCls: prefixCls,
308
313
  overflow: overflow,
309
- toolbarBottom: toolbarBottom
314
+ placement: "bottom"
310
315
  })]
311
316
  }))
312
317
  });
@@ -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 = _interopRequireDefault(require("./components/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: [!hideToolbar && !toolbarBottom && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Toolbar["default"], {
284
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Toolbar.ToolbarVisibility, {
285
+ hideToolbar: hideToolbar,
286
+ toolbarBottom: toolbarBottom,
284
287
  prefixCls: prefixCls,
285
288
  overflow: overflow,
286
- toolbarBottom: toolbarBottom
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
- }), !hideToolbar && toolbarBottom && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Toolbar["default"], {
309
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Toolbar.ToolbarVisibility, {
310
+ hideToolbar: hideToolbar,
311
+ toolbarBottom: toolbarBottom,
307
312
  prefixCls: prefixCls,
308
313
  overflow: overflow,
309
- toolbarBottom: toolbarBottom
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
- toolbarBottom = props.toolbarBottom,
125
- isChild = props.isChild;
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(bottomClassName),
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
  }
@@ -32,8 +32,7 @@
32
32
  margin: 0;
33
33
  font-size: 14px !important;
34
34
  line-height: 18px !important;
35
- -webkit-font-variant-ligatures: common-ligatures;
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
- -webkit-font-variant-ligatures: inherit;
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.2",
3
+ "version": "3.25.4",
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>",
@@ -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 Toolbar from './components/Toolbar';
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
- {!hideToolbar && !toolbarBottom && (
223
- <Toolbar prefixCls={prefixCls} overflow={overflow} toolbarBottom={toolbarBottom} />
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
- {!hideToolbar && toolbarBottom && (
249
- <Toolbar prefixCls={prefixCls} overflow={overflow} toolbarBottom={toolbarBottom} />
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 Toolbar from './components/Toolbar';
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
- {!hideToolbar && !toolbarBottom && (
223
- <Toolbar prefixCls={prefixCls} overflow={overflow} toolbarBottom={toolbarBottom} />
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
- {!hideToolbar && toolbarBottom && (
249
- <Toolbar prefixCls={prefixCls} overflow={overflow} toolbarBottom={toolbarBottom} />
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
  );
@@ -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 } = useContext(EditorContext);
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(
@@ -7,7 +7,6 @@ import './index.less';
7
7
 
8
8
  export interface IToolbarProps extends IProps {
9
9
  overflow?: boolean;
10
- toolbarBottom?: boolean;
11
10
  onCommand?: (command: ICommand<string>, groupName?: string) => void;
12
11
  commands?: ICommand<string>[];
13
12
  isChild?: boolean;
@@ -125,13 +124,29 @@ export function ToolbarItems(props: IToolbarProps) {
125
124
  }
126
125
 
127
126
  export default function Toolbar(props: IToolbarProps = {}) {
128
- const { prefixCls, toolbarBottom, isChild } = props;
127
+ const { prefixCls, isChild, className } = props;
129
128
  const { commands, extraCommands } = useContext(EditorContext);
130
- const bottomClassName = toolbarBottom ? 'bottom' : '';
131
129
  return (
132
- <div className={`${prefixCls}-toolbar ${bottomClassName}`}>
130
+ <div className={`${prefixCls}-toolbar ${className}`}>
133
131
  <ToolbarItems {...props} commands={props.commands || commands || []} />
134
132
  {!isChild && <ToolbarItems {...props} commands={extraCommands || []} />}
135
133
  </div>
136
134
  );
137
135
  }
136
+
137
+ interface ToolbarVisibilityProps {
138
+ hideToolbar?: boolean;
139
+ toolbarBottom: boolean;
140
+ placement: 'bottom' | 'top';
141
+ overflow: boolean;
142
+ prefixCls: string;
143
+ }
144
+
145
+ export function ToolbarVisibility(props: ToolbarVisibilityProps) {
146
+ const { hideToolbar, toolbarBottom, placement, overflow, prefixCls } = props;
147
+ if (hideToolbar || (placement === 'bottom' && !toolbarBottom) || (placement === 'top' && toolbarBottom)) {
148
+ return null;
149
+ }
150
+ const cls = toolbarBottom ? 'bottom' : '';
151
+ return <Toolbar prefixCls={prefixCls} overflow={overflow} className={cls} />;
152
+ }