@@ -24,8 +24,8 @@ import { changeHistory } from '@mongosh/history';
2424import type { WorkerRuntime } from '@mongosh/node-runtime-worker-thread' ;
2525import { PasswordPrompt } from './password-prompt' ;
2626import { ShellInput } from './shell-input' ;
27- import type { ShellOutputEntry } from './shell-output ' ;
28- import { ShellOutput } from './shell-output' ;
27+ import { ShellContent } from './shell-content ' ;
28+ import type { ShellOutputEntry } from './shell-output-line ' ;
2929
3030const shellContainer = css ( {
3131 fontSize : '13px' ,
@@ -206,7 +206,6 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
206206 const darkMode = useDarkMode ( ) ;
207207
208208 const editorRef = useRef < EditorRef | null > ( null ) ;
209- const shellInputContainerRef = useRef < HTMLDivElement > ( null ) ;
210209 const initialEvaluateRef = useRef ( initialEvaluate ) ;
211210 const outputRef = useRef ( output ) ;
212211 const historyRef = useRef ( history ) ;
@@ -464,42 +463,6 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
464463 }
465464 } , [ onInput , updateShellPrompt ] ) ;
466465
467- const listInnerContainerRef = useRef < HTMLDivElement | null > ( null ) ;
468- const setInnerContainerRef = useCallback ( ( ref : HTMLDivElement ) => {
469- listInnerContainerRef . current = ref ;
470- } , [ ] ) ;
471-
472- const [ virtualListInnerHeight , setVirtualListInnerHeight ] = useState ( 0 ) ;
473- const [ inputEditorHeight , setInputEditorHeight ] = useState ( 0 ) ;
474-
475- useEffect ( ( ) => {
476- if ( ! listInnerContainerRef . current ) {
477- return ;
478- }
479- const observer = new ResizeObserver ( ( [ list ] ) => {
480- requestAnimationFrame ( ( ) => {
481- setVirtualListInnerHeight ( list . contentRect . height ) ;
482- } ) ;
483- } ) ;
484- observer . observe ( listInnerContainerRef . current ) ;
485- return ( ) => {
486- observer . disconnect ( ) ;
487- } ;
488- } , [ listInnerContainerRef . current ] ) ;
489-
490- useEffect ( ( ) => {
491- if ( ! shellInputContainerRef . current ) {
492- return ;
493- }
494- const observer = new ResizeObserver ( ( [ input ] ) => {
495- setInputEditorHeight ( input . contentRect . height ) ;
496- } ) ;
497- observer . observe ( shellInputContainerRef . current ) ;
498- return ( ) => {
499- observer . disconnect ( ) ;
500- } ;
501- } , [ ] ) ;
502-
503466 /* eslint-disable jsx-a11y/no-static-element-interactions */
504467 /* eslint-disable jsx-a11y/click-events-have-key-events */
505468 return (
@@ -512,49 +475,31 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
512475 ) }
513476 onClick = { onShellClicked }
514477 >
515- < div
516- style = { {
517- // By default, we set the initial height to 1px so that the
518- // virtual list can render the items. Once we have content, we
519- // we will get the height of the list:
520- // - If the height of the list is smaller than the height of the
521- // container, we will set it to the height of the list.
522- // - If the height of the list is bigger than the height of the
523- // container, we will set it to the height of the container minus
524- // the height of the input editor.
525- height : `min(calc(100% - ${ inputEditorHeight } px), ${ Math . max (
526- ( output ?? [ ] ) . length > 0 ? virtualListInnerHeight : 1 ,
527- 1
528- ) } px)`,
529- } }
530- >
531- < ShellOutput
532- output = { output ?? [ ] }
533- setInnerContainerRef = { setInnerContainerRef }
534- />
535- </ div >
536- < div ref = { shellInputContainerRef } >
537- { passwordPrompt ? (
538- < PasswordPrompt
539- onFinish = { onFinishPasswordPrompt }
540- onCancel = { onCancelPasswordPrompt }
541- prompt = { passwordPrompt }
542- />
543- ) : (
544- < ShellInput
545- initialText = { initialText }
546- onTextChange = { onInputChanged }
547- prompt = { shellPrompt }
548- autocompleter = { runtime }
549- history = { history }
550- onClearCommand = { listener . onClearCommand }
551- onInput = { onInput }
552- operationInProgress = { isOperationInProgress }
553- editorRef = { setEditorRef }
554- onSigInt = { onSigInt }
555- />
556- ) }
557- </ div >
478+ < ShellContent
479+ output = { output ?? [ ] }
480+ InputPrompt = {
481+ passwordPrompt ? (
482+ < PasswordPrompt
483+ onFinish = { onFinishPasswordPrompt }
484+ onCancel = { onCancelPasswordPrompt }
485+ prompt = { passwordPrompt }
486+ />
487+ ) : (
488+ < ShellInput
489+ initialText = { initialText }
490+ onTextChange = { onInputChanged }
491+ prompt = { shellPrompt }
492+ autocompleter = { runtime }
493+ history = { history }
494+ onClearCommand = { listener . onClearCommand }
495+ onInput = { onInput }
496+ operationInProgress = { isOperationInProgress }
497+ editorRef = { setEditorRef }
498+ onSigInt = { onSigInt }
499+ />
500+ )
501+ }
502+ />
558503 </ div >
559504 ) ;
560505 /* eslint-enable jsx-a11y/no-static-element-interactions */
0 commit comments