@@ -33,6 +33,7 @@ import CheckCircleIcon from "@mui/icons-material/CheckCircle";
3333import Grid from "@mui/material/Grid" ;
3434
3535import Moveable from "react-moveable" ;
36+ import { ResizableBox } from "react-resizable" ;
3637import Ansi from "ansi-to-react" ;
3738
3839import { customAlphabet } from "nanoid" ;
@@ -234,23 +235,30 @@ function ResultBlock({ pod, id }) {
234235 < Box overflow = "scroll" maxHeight = "145px" border = "1px" >
235236 { /* <Box bgcolor="lightgray">Error</Box> */ }
236237 { pod . stdout && (
237- < Box whiteSpace = "pre-wrap" sx = { { fontSize : 10 } } >
238+ < Box whiteSpace = "pre-wrap" sx = { { fontSize : 10 } } >
238239 < Ansi > { pod . stdout } </ Ansi >
239240 </ Box >
240241 ) }
241242 { pod ?. result ?. text && pod ?. result ?. count > 0 && (
242- < Box sx = { { display : "flex" , fontSize : 10 , flexDirection : "row" , alignItems : 'center' } } >
243+ < Box
244+ sx = { {
245+ display : "flex" ,
246+ fontSize : 10 ,
247+ flexDirection : "row" ,
248+ alignItems : "center" ,
249+ } }
250+ >
243251 < Box > Result[{ pod . result . count } ]:</ Box >
244252 < Box component = "pre" whiteSpace = "pre-wrap" >
245- { pod . result . text }
253+ { pod . result . text }
246254 </ Box >
247255 </ Box >
248256 ) }
249257 { pod ?. error && < Box color = "red" > { pod ?. error ?. evalue } </ Box > }
250258 { pod ?. error ?. stacktrace && (
251259 < Box >
252260 < Box > StackTrace</ Box >
253- < Box whiteSpace = "pre-wrap" sx = { { fontSize : 10 } } >
261+ < Box whiteSpace = "pre-wrap" sx = { { fontSize : 10 } } >
254262 < Ansi > { pod . error . stacktrace . join ( "\n" ) } </ Ansi >
255263 </ Box >
256264 </ Box >
@@ -289,6 +297,22 @@ const CodeNode = memo<Props>(({ data, id, isConnectable }) => {
289297 state . pods [ id ] ?. stdout ||
290298 state . pods [ id ] ?. stderr
291299 ) ;
300+ const updatePod = useStore ( store , ( state ) => state . updatePod ) ;
301+ const onResize = useCallback ( ( e , data ) => {
302+ const { size } = data ;
303+ const node = nodesMap . get ( id ) ;
304+ if ( node ) {
305+ node . style = { ...node . style , width : size . width } ;
306+ nodesMap . set ( id , node ) ;
307+ updatePod ( {
308+ id,
309+ data : {
310+ width : size . width ,
311+ height : pod . height ,
312+ } ,
313+ } ) ;
314+ }
315+ } , [ ] ) ;
292316 const nodesMap = useStore ( store , ( state ) => state . ydoc . getMap < Node > ( "pods" ) ) ;
293317 const apolloClient = useApolloClient ( ) ;
294318 const deletePod = useStore ( store , ( state ) => state . deletePod ) ;
@@ -315,100 +339,108 @@ const CodeNode = memo<Props>(({ data, id, isConnectable }) => {
315339 } , [ ] ) ;
316340 if ( ! pod ) return null ;
317341 return (
318- < Box
319- sx = { {
320- border : "solid 1px #d6dee6" ,
321- borderRadius : "4px" ,
322- width : "100%" ,
323- height : "100%" ,
324- backgroundColor : "rgb(244, 246, 248)" ,
325- borderColor : isEditorBlur ? "#d6dee6" : "#3182ce" ,
326- } }
327- ref = { ref }
342+ < ResizableBox
343+ onResizeStop = { onResize }
344+ height = { pod . height || 100 }
345+ width = { pod . width }
346+ axis = "x"
347+ minConstraints = { [ 200 , 200 ] }
328348 >
329- < Handle
330- type = "source"
331- position = { Position . Top }
332- id = "top"
333- isConnectable = { isConnectable }
334- />
335- < Handle
336- type = "source"
337- position = { Position . Bottom }
338- id = "bottom"
339- isConnectable = { isConnectable }
340- />
341- < Handle
342- type = "source"
343- position = { Position . Left }
344- id = "left"
345- isConnectable = { isConnectable }
346- />
347- < Handle
348- type = "source"
349- position = { Position . Right }
350- id = "right"
351- isConnectable = { isConnectable }
352- />
353- { /* The header of code pods. */ }
354- < Box className = "custom-drag-handle" >
355- < Box sx = { styles [ "pod-index" ] } > [{ pod . index } ]</ Box >
356- < ToolBox data = { { id } } onRunTask = { runToolBoxTask } > </ ToolBox >
357- </ Box >
358349 < Box
359350 sx = { {
360- height : "90%" ,
361- } }
362- onClick = { ( e ) => {
363- // If the node is selected (for resize), the cursor is not shown. So
364- // we need to deselect it when we re-focus on the editor.
365- setSelected ( null ) ;
366- setNodes ( ( nds ) =>
367- applyNodeChanges (
368- [
369- {
370- id,
371- type : "select" ,
372- selected : false ,
373- } ,
374- ] ,
375- nds
376- )
377- ) ;
351+ border : "solid 1px #d6dee6" ,
352+ borderRadius : "4px" ,
353+ width : "100%" ,
354+ height : "100%" ,
355+ backgroundColor : "rgb(244, 246, 248)" ,
356+ borderColor : isEditorBlur ? "#d6dee6" : "#3182ce" ,
378357 } }
358+ ref = { ref }
379359 >
380- < MyMonaco
381- id = { id }
382- gitvalue = ""
383- onBlur = { ( ) => {
384- setIsEditorBlur ( true ) ;
360+ < Handle
361+ type = "source"
362+ position = { Position . Top }
363+ id = "top"
364+ isConnectable = { isConnectable }
365+ />
366+ < Handle
367+ type = "source"
368+ position = { Position . Bottom }
369+ id = "bottom"
370+ isConnectable = { isConnectable }
371+ />
372+ < Handle
373+ type = "source"
374+ position = { Position . Left }
375+ id = "left"
376+ isConnectable = { isConnectable }
377+ />
378+ < Handle
379+ type = "source"
380+ position = { Position . Right }
381+ id = "right"
382+ isConnectable = { isConnectable }
383+ />
384+ { /* The header of code pods. */ }
385+ < Box className = "custom-drag-handle" >
386+ < Box sx = { styles [ "pod-index" ] } > [{ pod . index } ]</ Box >
387+ < ToolBox data = { { id } } onRunTask = { runToolBoxTask } > </ ToolBox >
388+ </ Box >
389+ < Box
390+ sx = { {
391+ height : "90%" ,
385392 } }
386- onFocus = { ( ) => {
387- setIsEditorBlur ( false ) ;
393+ onClick = { ( e ) => {
394+ // If the node is selected (for resize), the cursor is not shown. So
395+ // we need to deselect it when we re-focus on the editor.
396+ setSelected ( null ) ;
397+ setNodes ( ( nds ) =>
398+ applyNodeChanges (
399+ [
400+ {
401+ id,
402+ type : "select" ,
403+ selected : false ,
404+ } ,
405+ ] ,
406+ nds
407+ )
408+ ) ;
388409 } }
389- />
390- { showResult && (
391- < Box
392- className = "nowheel"
393- sx = { {
394- border : "solid 1px #d6dee6" ,
395- borderRadius : "4px" ,
396- position : "absolute" ,
397- top : isRightLayout ? 0 : "100%" ,
398- left : isRightLayout ? "100%" : 0 ,
399- maxHeight : "158px" ,
400- minWidth : isRightLayout ? "200px" : "100%" ,
401- boxSizing : "border-box" ,
402- backgroundColor : "white" ,
403- zIndex : 100 ,
404- padding : "0 10px" ,
410+ >
411+ < MyMonaco
412+ id = { id }
413+ gitvalue = ""
414+ onBlur = { ( ) => {
415+ setIsEditorBlur ( true ) ;
405416 } }
406- >
407- < ResultBlock pod = { pod } id = { id } />
408- </ Box >
409- ) }
417+ onFocus = { ( ) => {
418+ setIsEditorBlur ( false ) ;
419+ } }
420+ />
421+ { showResult && (
422+ < Box
423+ className = "nowheel"
424+ sx = { {
425+ border : "solid 1px #d6dee6" ,
426+ borderRadius : "4px" ,
427+ position : "absolute" ,
428+ top : isRightLayout ? 0 : "100%" ,
429+ left : isRightLayout ? "100%" : 0 ,
430+ maxHeight : "158px" ,
431+ minWidth : isRightLayout ? "200px" : "100%" ,
432+ boxSizing : "border-box" ,
433+ backgroundColor : "white" ,
434+ zIndex : 100 ,
435+ padding : "0 10px" ,
436+ } }
437+ >
438+ < ResultBlock pod = { pod } id = { id } />
439+ </ Box >
440+ ) }
441+ </ Box >
410442 </ Box >
411- </ Box >
443+ </ ResizableBox >
412444 ) ;
413445} ) ;
414446
0 commit comments