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' ;
@@ -216,26 +216,31 @@ const InternalMDEditor = React.forwardRef<RefMDEditor, MDEditorProps>(
216
216
} ) ;
217
217
}
218
218
} ;
219
+ const contentView = / ( l i v e | p r e v i e w ) / . test ( state . preview || '' ) && (
220
+ < Fragment >
221
+ < TextArea
222
+ className = { `${ prefixCls } -input` }
223
+ prefixCls = { prefixCls }
224
+ autoFocus = { autoFocus }
225
+ { ...textareaProps }
226
+ onChange = { changeHandle }
227
+ renderTextarea = { components ?. textarea || renderTextarea }
228
+ onScroll = { ( e ) => handleScroll ( e , 'text' ) }
229
+ />
230
+ { mdPreview }
231
+ </ Fragment >
232
+ ) ;
219
233
return (
220
234
< EditorContext . Provider value = { { ...state , dispatch } } >
221
235
< div ref = { container } className = { cls } { ...other } onClick = { containerClick } style = { containerStyle } >
222
- { ! hideToolbar && ! toolbarBottom && (
223
- < Toolbar prefixCls = { prefixCls } overflow = { overflow } toolbarBottom = { toolbarBottom } />
224
- ) }
225
- < div className = { `${ prefixCls } -content` } >
226
- { / ( e d i t | l i v e ) / . test ( state . preview || '' ) && (
227
- < TextArea
228
- className = { `${ prefixCls } -input` }
229
- prefixCls = { prefixCls }
230
- autoFocus = { autoFocus }
231
- { ...textareaProps }
232
- onChange = { changeHandle }
233
- renderTextarea = { components ?. textarea || renderTextarea }
234
- onScroll = { ( e ) => handleScroll ( e , 'text' ) }
235
- />
236
- ) }
237
- { / ( l i v e | p r e v i e w ) / . test ( state . preview || '' ) && mdPreview }
238
- </ div >
236
+ < ToolbarVisibility
237
+ hideToolbar = { hideToolbar }
238
+ toolbarBottom = { toolbarBottom }
239
+ prefixCls = { prefixCls }
240
+ overflow = { overflow }
241
+ placement = "top"
242
+ />
243
+ < div className = { `${ prefixCls } -content` } > { contentView } </ div >
239
244
{ visibleDragbar && ! state . fullscreen && (
240
245
< DragBar
241
246
prefixCls = { prefixCls }
@@ -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
) ;
0 commit comments