child nodes get repositioned correctly when resizing top or left

This commit is contained in:
peterkogo
2024-01-23 12:35:24 +01:00
parent 8a9f8127b5
commit abc6fea20b
5 changed files with 111 additions and 7 deletions
@@ -1,6 +1,12 @@
import { useRef, useEffect, memo } from 'react';
import cc from 'classcat';
import { XYResizer, ResizeControlVariant, type XYResizerInstance, type XYResizerChange } from '@xyflow/system';
import {
XYResizer,
ResizeControlVariant,
type XYResizerInstance,
type XYResizerChange,
XYResizerChildChange,
} from '@xyflow/system';
import { useStoreApi } from '../../hooks/useStore';
import { useNodeId } from '../../contexts/NodeIdContext';
@@ -52,7 +58,7 @@ function ResizeControl({
snapToGrid,
};
},
onChange: (change: XYResizerChange) => {
onChange: (change: XYResizerChange, childChanges: XYResizerChildChange[]) => {
const { triggerNodeChanges } = store.getState();
const changes: NodeChange[] = [];
@@ -83,6 +89,17 @@ function ResizeControl({
changes.push(dimensionChange);
}
childChanges.forEach((childChange) => {
const positionChange: NodePositionChange = {
id: childChange.id,
type: 'position',
position: childChange.position,
};
changes.push(positionChange);
});
triggerNodeChanges(changes);
},
onEnd: () => {