11import Editor , { OnChange , loader } from '@monaco-editor/react' ;
22import * as monaco from 'monaco-editor/esm/vs/editor/editor.api' ;
3- import { useEffect , useRef , useState } from 'react' ;
3+ import { useContext , useEffect , useRef , useState } from 'react' ;
44import { ThemeContext } from '../../../../themes/theme-context' ;
5- import { convertPercentToPx } from '../dimensions/dimensions-adjustment ' ;
5+ import { ResizeContext } from '../../../services/context/resize-context/ResizeContext ' ;
66import { formatJsonStringForAllBrowsers } from './util/format-json' ;
77interface IMonaco {
88 body : object | string | undefined ;
@@ -17,6 +17,7 @@ interface IMonaco {
1717export function Monaco ( props : IMonaco ) {
1818 let { body } = props ;
1919 const { onChange, language, readOnly } = props ;
20+ const { parentHeight, dragValue, initiator } = useContext ( ResizeContext ) ;
2021
2122 if ( body && typeof body !== 'string' ) {
2223 body = formatJsonStringForAllBrowsers ( body ) ;
@@ -42,28 +43,14 @@ export function Monaco(props: IMonaco) {
4243
4344 const editorRef = useRef < monaco . editor . IStandaloneCodeEditor | null > ( null ) ;
4445 const [ editorHeight , setEditorHeight ] = useState ( 300 ) ;
45-
4646 useEffect ( ( ) => {
47- const handleResize = ( e : Event ) => {
48- const layout = document . getElementById ( 'layout' ) ;
49- if ( layout ) {
50- const parentHeight = layout . parentElement ?. offsetHeight ?? 0 ;
51- const customEvent = e as CustomEvent ;
52- const { initiator, value } = customEvent . detail as {
53- initiator : string ;
54- value : number ;
55- } ;
56- if ( initiator === 'responseSize' ) {
57- if ( editorRef . current && value > 0 ) {
58- const newHeight = parentHeight - value - 124 ;
59- setEditorHeight ( newHeight ) ;
60- }
61- }
47+ if ( initiator === 'responseSize' ) {
48+ if ( editorRef . current && dragValue > 0 ) {
49+ const newHeight = parentHeight - dragValue - 124 ;
50+ setEditorHeight ( Math . max ( 300 , newHeight ) ) ;
6251 }
63- } ;
64- window . addEventListener ( 'onResizeDragEnd' , handleResize ) ;
65- return ( ) => window . removeEventListener ( 'resize' , handleResize ) ;
66- } , [ ] ) ;
52+ }
53+ } , [ parentHeight , dragValue , initiator ] ) ;
6754
6855 return (
6956 < >
0 commit comments