@@ -15,33 +15,45 @@ const useFileTreeResizeOnContentChange = (
1515 const { updateShapeSizeAndPosition } = useCanvasContext ( ) ;
1616
1717 useEffect ( ( ) => {
18- // Only update if the text has changed AND the height is different
1918 const textChanged = previousText . current !== text ;
2019
2120 const finalHeight = Math . max ( calculatedSize . height , minHeight ) ;
2221 const finalSize = { ...calculatedSize , height : finalHeight } ;
2322
24- const heightChanged = finalHeight !== currentSize . height ;
23+ const sizeChanged =
24+ finalHeight !== currentSize . height ||
25+ calculatedSize . width !== currentSize . width ;
2526
26- if ( textChanged && heightChanged ) {
27+ if ( textChanged && sizeChanged ) {
2728 previousText . current = text ;
2829 updateShapeSizeAndPosition ( id , coords , finalSize , false ) ;
30+ } else if ( sizeChanged ) {
31+ // If only the size has changed, also resize
32+ updateShapeSizeAndPosition ( id , coords , finalSize , false ) ;
2933 }
3034 } , [
3135 text ,
3236 calculatedSize . height ,
37+ calculatedSize . width ,
3338 currentSize . height ,
39+ currentSize . width ,
3440 id ,
3541 coords . x ,
3642 coords . y ,
3743 updateShapeSizeAndPosition ,
3844 ] ) ;
3945} ;
4046
47+ // Hook to force width change when ElementSize changes (XS ↔ S)
48+ // This ensures that when dropping a component and changing from S to XS (or vice versa),
49+ // the component doesn't maintain the previous width but forces the correct one:
50+ // - XS: 150px width
51+ // - S: 230px width
52+
4153const useFileTreeResizeOnSizeChange = (
4254 id : string ,
4355 coords : { x : number ; y : number } ,
44- currentWidth : number ,
56+ currentSize : Size ,
4557 size ?: ElementSize
4658) => {
4759 const previousSize = useRef ( size ) ;
@@ -54,16 +66,23 @@ const useFileTreeResizeOnSizeChange = (
5466
5567 const newWidth = size === 'XS' ? 150 : 230 ;
5668
57- if ( currentWidth !== newWidth ) {
69+ if ( currentSize . width !== newWidth ) {
5870 updateShapeSizeAndPosition (
5971 id ,
6072 coords ,
61- { width : newWidth , height : currentWidth } ,
73+ { width : newWidth , height : currentSize . height } ,
6274 false
6375 ) ;
6476 }
6577 }
66- } , [ size , currentWidth , id , coords . x , coords . y , updateShapeSizeAndPosition ] ) ;
78+ } , [
79+ size ,
80+ currentSize . width ,
81+ id ,
82+ coords . x ,
83+ coords . y ,
84+ updateShapeSizeAndPosition ,
85+ ] ) ;
6786} ;
6887
6988export const useFileTreeResize = (
@@ -84,5 +103,5 @@ export const useFileTreeResize = (
84103 minHeight
85104 ) ;
86105
87- useFileTreeResizeOnSizeChange ( id , coords , currentSize . width , size ) ;
106+ useFileTreeResizeOnSizeChange ( id , coords , currentSize , size ) ;
88107} ;
0 commit comments