@@ -89,8 +89,8 @@ const StyledEditorDiv = styled(Box)(({ theme }) => ({
8989 padding : '0.25rem' ,
9090 '& .jsoneditor-div' : {
9191 fontSize : '12px' ,
92- minWidth : '525px ' ,
93- minHeight : '300px ' ,
92+ minWidth : '200px ' ,
93+ minHeight : '200px ' ,
9494 ...theme . mixins . panelBorder . all ,
9595 outline : 0 ,
9696 resize : 'both' ,
@@ -102,7 +102,7 @@ const StyledEditorDiv = styled(Box)(({ theme }) => ({
102102 } ,
103103} ) ) ;
104104
105- const ResizableDiv = ( { columnIndex, children, ...otherProps } ) => {
105+ const ResizableDiv = ( { columnIndex, children, resizeKey , defaultSize , ...otherProps } ) => {
106106
107107 const editorRef = React . useRef ( null ) ;
108108 const { getCellElement} = useContext ( RowInfoContext ) ;
@@ -124,11 +124,24 @@ const ResizableDiv = ({columnIndex, children, ...otherProps}) => {
124124 if ( box . right > innerWidth ) {
125125 editorRef . current . firstChild . style . width = `${ currentWidth - widthDiff - 20 } px` ;
126126 }
127+ // logic to save the height and width of the editor
128+ if ( currentHeight || currentWidth ) {
129+ window . resizeKeys = window . resizeKeys || { } ;
130+ window . resizeKeys [ resizeKey ] = { height : editorRef . current . firstChild . style . height , width : editorRef . current . firstChild . style . width } ;
131+ }
132+
127133 } ;
128134
129135 editorRef . current . addEventListener ( 'mousedown' , ( ) => {
130136 document . addEventListener ( 'mouseup' , resizeEditor , { once : true } ) ;
131137 } ) ;
138+ // Fetch the saved height and width from window object
139+ editorRef . current . firstChild . style . height = window . resizeKeys ?. [ resizeKey ] ?. height || defaultSize . height ;
140+ editorRef . current . firstChild . style . width = window . resizeKeys ?. [ resizeKey ] ?. width || defaultSize . width ;
141+
142+ // set initial position of editor and resize if it goes beyond visible area.
143+ setEditorPosition ( getCellElement ( columnIndex ) , editorRef . current , '.rdg' , 12 ) ;
144+ resizeEditor ( ) ;
132145
133146 return ( ) => document . removeEventListener ( 'mouseup' , resizeEditor ) ;
134147
@@ -137,7 +150,6 @@ const ResizableDiv = ({columnIndex, children, ...otherProps}) => {
137150 return (
138151 < StyledEditorDiv ref = { ( ele ) => {
139152 editorRef . current = ele ;
140- setEditorPosition ( getCellElement ( columnIndex ) , ele , '.rdg' , 12 ) ;
141153 } } { ...otherProps } >
142154 { children }
143155 </ StyledEditorDiv >
@@ -146,7 +158,9 @@ const ResizableDiv = ({columnIndex, children, ...otherProps}) => {
146158ResizableDiv . displayName = 'ResizableDiv' ;
147159ResizableDiv . propTypes = {
148160 children : CustomPropTypes . children ,
149- columnIndex : PropTypes . number
161+ columnIndex : PropTypes . number ,
162+ resizeKey : PropTypes . string ,
163+ defaultSize : PropTypes . object ,
150164} ;
151165
152166function autoFocusAndSelect ( input ) {
@@ -249,7 +263,7 @@ export function TextEditor({row, column, onRowChange, onClose}) {
249263 return (
250264 < Portal container = { document . body } >
251265 < ResizableDiv columnIndex = { column . idx }
252- className = 'Editors-textEditor' data-label = "pg-editor" onKeyDown = { suppressEnterKey } >
266+ className = 'Editors-textEditor' data-label = "pg-editor" resizeKey = { 'text' } defaultSize = { { height : '80px' , width : '250px' } } onKeyDown = { suppressEnterKey } >
253267 < textarea ref = { autoFocusAndSelect } className = 'Editors-textarea' value = { localVal } onChange = { onChange } onKeyDown = { onkeydown } />
254268 < Box display = "flex" justifyContent = "flex-end" >
255269 < DefaultButton startIcon = { < CloseIcon /> } onClick = { ( ) => onClose ( false ) } size = "small" >
@@ -436,7 +450,7 @@ export function JsonTextEditor({row, column, onRowChange, onClose}) {
436450 return (
437451 < Portal container = { document . body } >
438452 < ResizableDiv columnIndex = { column . idx }
439- className = 'Editors-jsonEditor' data-label = "pg-editor" onKeyDown = { suppressEnterKey } >
453+ className = 'Editors-jsonEditor' data-label = "pg-editor" resizeKey = { 'json' } defaultSize = { { height : '500px' , width : '600px' } } onKeyDown = { suppressEnterKey } >
440454 < JsonEditor
441455 setJsonEditorSize = { setJsonEditorSize }
442456 value = { localVal }
0 commit comments