Merge pull request #5043 from xyflow/refactor/dynamic-expand-parent
Refactor/dynamic expand parent
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'@xyflow/react': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Use current expandParent value on drag to be able to update it while dragging
|
||||||
@@ -152,9 +152,12 @@ const createStore = ({
|
|||||||
updateNodePositions: (nodeDragItems, dragging = false) => {
|
updateNodePositions: (nodeDragItems, dragging = false) => {
|
||||||
const parentExpandChildren: ParentExpandChild[] = [];
|
const parentExpandChildren: ParentExpandChild[] = [];
|
||||||
const changes = [];
|
const changes = [];
|
||||||
|
const { nodeLookup, triggerNodeChanges } = get();
|
||||||
|
|
||||||
for (const [id, dragItem] of nodeDragItems) {
|
for (const [id, dragItem] of nodeDragItems) {
|
||||||
const expandParent = !!(dragItem?.expandParent && dragItem?.parentId && dragItem?.position);
|
// we are using the nodelookup to be sure to use the current expandParent and parentId value
|
||||||
|
const node = nodeLookup.get(id);
|
||||||
|
const expandParent = !!(node?.expandParent && node?.parentId && dragItem?.position);
|
||||||
|
|
||||||
const change: NodeChange = {
|
const change: NodeChange = {
|
||||||
id,
|
id,
|
||||||
@@ -168,10 +171,10 @@ const createStore = ({
|
|||||||
dragging,
|
dragging,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (expandParent) {
|
if (expandParent && node.parentId) {
|
||||||
parentExpandChildren.push({
|
parentExpandChildren.push({
|
||||||
id,
|
id,
|
||||||
parentId: dragItem.parentId!,
|
parentId: node.parentId,
|
||||||
rect: {
|
rect: {
|
||||||
...dragItem.internals.positionAbsolute,
|
...dragItem.internals.positionAbsolute,
|
||||||
width: dragItem.measured.width ?? 0,
|
width: dragItem.measured.width ?? 0,
|
||||||
@@ -184,12 +187,12 @@ const createStore = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (parentExpandChildren.length > 0) {
|
if (parentExpandChildren.length > 0) {
|
||||||
const { nodeLookup, parentLookup, nodeOrigin } = get();
|
const { parentLookup, nodeOrigin } = get();
|
||||||
const parentExpandChanges = handleExpandParent(parentExpandChildren, nodeLookup, parentLookup, nodeOrigin);
|
const parentExpandChanges = handleExpandParent(parentExpandChildren, nodeLookup, parentLookup, nodeOrigin);
|
||||||
changes.push(...parentExpandChanges);
|
changes.push(...parentExpandChanges);
|
||||||
}
|
}
|
||||||
|
|
||||||
get().triggerNodeChanges(changes);
|
triggerNodeChanges(changes);
|
||||||
},
|
},
|
||||||
triggerNodeChanges: (changes) => {
|
triggerNodeChanges: (changes) => {
|
||||||
const { onNodesChange, setNodes, nodes, hasDefaultNodes, debug } = get();
|
const { onNodesChange, setNodes, nodes, hasDefaultNodes, debug } = get();
|
||||||
|
|||||||
Reference in New Issue
Block a user