(null);
@@ -65,12 +74,13 @@ function ResizeHandle({
nodeElementRef.current = document.querySelector(`.react-flow__node[data-id="${nodeId}"]`) as HTMLDivElement;
})
.on('drag', (event: ResizeDragEvent) => {
- const { updateNodePositions, nodeInternals } = store.getState();
+ const { updateNodePositions, nodeInternals, onNodesChange } = store.getState();
const pointerPos = getPointerPosition(event);
const nodeEl = nodeElementRef.current;
const node = nodeInternals.get(nodeId);
if (nodeEl && node) {
+ const changes: NodeChange[] = [];
const distX = enableX ? pointerPos.xSnapped - initialDimensionsRef.current.x : 0;
const distY = enableY ? pointerPos.ySnapped - initialDimensionsRef.current.y : 0;
const width = initialDimensionsRef.current.width + (invertX ? -distX : distX);
@@ -81,7 +91,7 @@ function ResizeHandle({
const y = invertY ? initialDimensionsRef.current.nodeY + distY : initialDimensionsRef.current.nodeY;
if (x !== node.position.x || y !== node.position.y) {
- updateNodePositions(
+ const positionChanges: NodePositionChange[] | null = updateNodePositions(
[
{
id: nodeId,
@@ -89,16 +99,31 @@ function ResizeHandle({
} as Node,
],
true,
+ false,
false
);
+
+ if (positionChanges?.length) {
+ changes.push(positionChanges[0]);
+ }
}
}
- if (width !== node.width) {
- nodeEl.style.width = `${width}px`;
+ if (width !== node.width || height !== node.height) {
+ const dimensionChange: NodeDimensionChange = {
+ id: nodeId,
+ type: 'dimensions',
+ updateStyle: true,
+ dimensions: {
+ width: width !== node.width ? width : node.width,
+ height: height !== node.height ? height : node.height,
+ },
+ };
+ changes.push(dimensionChange);
}
- if (height !== node.height) {
- nodeEl.style.height = `${height}px`;
+
+ if (changes.length) {
+ onNodesChange?.(changes);
}
}
});
@@ -112,7 +137,7 @@ function ResizeHandle({
return (
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
>
);
}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index a8406c2d..4eafb92f 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -230,7 +230,7 @@ importers:
'@types/node': ^18.7.16
'@types/react': ^18.0.19
'@types/react-dom': ^18.0.6
- classcat: ^5.0.3
+ classcat: ^5.0.4
d3-drag: ^3.0.0
d3-selection: ^3.0.0
react: ^18.2.0