broken parent expand on resize but almost there

This commit is contained in:
peterkogo
2024-04-11 18:34:17 +02:00
parent 05ac4ef9db
commit 979fe7d565
2 changed files with 53 additions and 26 deletions
@@ -9,11 +9,15 @@ import {
type NodeChange,
type NodeDimensionChange,
type NodePositionChange,
handleParentExpand,
} from '@xyflow/system';
import { useStoreApi } from '../../hooks/useStore';
import { useNodeId } from '../../contexts/NodeIdContext';
import type { ResizeControlProps, ResizeControlLineProps } from './types';
import { InternalNode } from '../../types';
type InternalNodeWithParentExpand = InternalNode & { expandParent: true; parentId: string };
function ResizeControl({
nodeId,
@@ -62,20 +66,44 @@ function ResizeControl({
};
},
onChange: (change: XYResizerChange, childChanges: XYResizerChildChange[]) => {
const { triggerNodeChanges } = store.getState();
const { triggerNodeChanges, nodeLookup } = store.getState();
const changes: NodeChange[] = [];
const newPosition = { x: change.x, y: change.y };
if (change.x !== undefined && change.y !== undefined) {
const positionChange: NodePositionChange = {
id,
type: 'position',
const node = nodeLookup.get(id);
if (node && node.expandParent && node.parentId) {
const nodeWithChange = {
...node,
position: {
x: change.x,
y: change.y,
},
};
width: change.width,
height: change.height,
measured: {
width: change.width ?? node.measured?.width,
height: change.height ?? node.measured?.height,
},
} as InternalNodeWithParentExpand;
const parentExpandChanges = handleParentExpand([nodeWithChange], nodeLookup);
if (parentExpandChanges.length > 0) {
newPosition.x = change.x && change.x < 0 ? 0 : change.x;
newPosition.y = change.y && change.y < 0 ? 0 : change.y;
} else {
console.log('there was no parent expand');
}
changes.push(...parentExpandChanges);
}
if (change.x !== undefined && change.y !== undefined) {
console.log(newPosition);
const positionChange: NodePositionChange = {
id,
type: 'position',
position: { ...newPosition } as { x: number; y: number },
};
changes.push(positionChange);
}