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