added correct expandParent offset of children
This commit is contained in:
@@ -67,7 +67,7 @@ function ResizeControl({
|
||||
};
|
||||
},
|
||||
onChange: (change: XYResizerChange, childChanges: XYResizerChildChange[]) => {
|
||||
const { triggerNodeChanges, nodeLookup } = store.getState();
|
||||
const { triggerNodeChanges, nodeLookup, parentLookup } = store.getState();
|
||||
|
||||
const changes: NodeChange[] = [];
|
||||
const newPosition = { x: change.x, y: change.y };
|
||||
@@ -86,7 +86,7 @@ function ResizeControl({
|
||||
|
||||
const nodeWith = evaluateNodePosition(nodeWithChange, nodeLookup) as InternalNodeWithParentExpand;
|
||||
|
||||
const parentExpandChanges = handleParentExpand([nodeWith], nodeLookup);
|
||||
const parentExpandChanges = handleParentExpand([nodeWith], nodeLookup, parentLookup);
|
||||
changes.push(...parentExpandChanges);
|
||||
newPosition.x = change.x ? Math.max(0, change.x) : undefined;
|
||||
newPosition.y = change.y ? Math.max(0, change.y) : undefined;
|
||||
|
||||
@@ -76,6 +76,7 @@ const createRFStore = ({
|
||||
onNodesChange,
|
||||
fitView,
|
||||
nodeLookup,
|
||||
parentLookup,
|
||||
fitViewOnInit,
|
||||
fitViewDone,
|
||||
fitViewOnInitOptions,
|
||||
@@ -84,7 +85,13 @@ const createRFStore = ({
|
||||
debug,
|
||||
} = get();
|
||||
|
||||
const { changes, updatedInternals } = updateNodeInternalsSystem(updates, nodeLookup, domNode, nodeOrigin);
|
||||
const { changes, updatedInternals } = updateNodeInternalsSystem(
|
||||
updates,
|
||||
nodeLookup,
|
||||
parentLookup,
|
||||
domNode,
|
||||
nodeOrigin
|
||||
);
|
||||
|
||||
if (!updatedInternals) {
|
||||
return;
|
||||
@@ -116,7 +123,7 @@ const createRFStore = ({
|
||||
}
|
||||
},
|
||||
updateNodePositions: (nodeDragItems, dragging = false) => {
|
||||
const { nodeLookup } = get();
|
||||
const { nodeLookup, parentLookup } = get();
|
||||
type ExpandParentInternalNode = InternalNode & { parentId: string; expandParent: true };
|
||||
const expandParentNodes: ExpandParentInternalNode[] = [];
|
||||
|
||||
@@ -148,7 +155,7 @@ const createRFStore = ({
|
||||
});
|
||||
|
||||
if (expandParentNodes.length > 0) {
|
||||
const parentExpandChanges = handleParentExpand(expandParentNodes, nodeLookup);
|
||||
const parentExpandChanges = handleParentExpand(expandParentNodes, nodeLookup, parentLookup);
|
||||
changes.push(...parentExpandChanges);
|
||||
}
|
||||
|
||||
|
||||
@@ -83,6 +83,7 @@ export function createStore({
|
||||
const { changes, updatedInternals } = updateNodeInternalsSystem(
|
||||
updates,
|
||||
nodeLookup,
|
||||
get(store.parentLookup),
|
||||
get(store.domNode),
|
||||
get(store.nodeOrigin)
|
||||
);
|
||||
|
||||
@@ -144,3 +144,4 @@ export type NodeHandle = Optional<HandleElement, 'width' | 'height'>;
|
||||
export type Align = 'center' | 'start' | 'end';
|
||||
|
||||
export type NodeLookup<NodeType extends InternalNodeBase = InternalNodeBase> = Map<string, NodeType>;
|
||||
export type ParentLookup<NodeType extends InternalNodeBase = InternalNodeBase> = Map<string, NodeType[]>;
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
Rect,
|
||||
NodeDimensionChange,
|
||||
NodePositionChange,
|
||||
ParentLookup,
|
||||
} from '../types';
|
||||
import { getDimensions, getHandleBounds } from './dom';
|
||||
import { getBoundsOfRects, getNodeDimensions, isNumeric, nodeToRect } from './general';
|
||||
@@ -160,7 +161,8 @@ type ExpandParentNode<NodeType> = NodeType & { parentId: string; expandParent: t
|
||||
|
||||
export function handleParentExpand(
|
||||
nodes: ExpandParentNode<InternalNodeBase>[],
|
||||
nodeLookup: NodeLookup
|
||||
nodeLookup: NodeLookup,
|
||||
parentLookup: ParentLookup
|
||||
): (NodeDimensionChange | NodePositionChange)[] {
|
||||
const changes: (NodeDimensionChange | NodePositionChange)[] = [];
|
||||
const chilNodeRects = new Map<string, Rect>();
|
||||
@@ -193,6 +195,20 @@ export function handleParentExpand(
|
||||
y: position.y - yChange,
|
||||
},
|
||||
});
|
||||
|
||||
const childNodes = parentLookup.get(id);
|
||||
childNodes?.forEach((childNode) => {
|
||||
if (!nodes.find((n) => n.id === childNode.id)) {
|
||||
changes.push({
|
||||
id: childNode.id,
|
||||
type: 'position',
|
||||
position: {
|
||||
x: childNode.position.x + xChange,
|
||||
y: childNode.position.y + yChange,
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (dimensions.width < rect.width || dimensions.height < rect.height) {
|
||||
@@ -214,7 +230,8 @@ export function handleParentExpand(
|
||||
|
||||
export function updateNodeInternals<NodeType extends InternalNodeBase>(
|
||||
updates: Map<string, InternalNodeUpdate>,
|
||||
nodeLookup: Map<string, NodeType>,
|
||||
nodeLookup: NodeLookup<NodeType>,
|
||||
parentLookup: ParentLookup<NodeType>,
|
||||
domNode: HTMLElement | null,
|
||||
nodeOrigin?: NodeOrigin
|
||||
): { changes: (NodeDimensionChange | NodePositionChange)[]; updatedInternals: boolean } {
|
||||
@@ -284,7 +301,7 @@ export function updateNodeInternals<NodeType extends InternalNodeBase>(
|
||||
});
|
||||
|
||||
if (parentExpandNodes.length > 0) {
|
||||
const parentExpandChanges = handleParentExpand(parentExpandNodes, nodeLookup);
|
||||
const parentExpandChanges = handleParentExpand(parentExpandNodes, nodeLookup, parentLookup);
|
||||
changes.push(...parentExpandChanges);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user