refactor(expandParent): use current value on drag #5039
This commit is contained in:
@@ -51,7 +51,7 @@ const createStore = ({
|
|||||||
* setNodes() is called exclusively in response to user actions:
|
* setNodes() is called exclusively in response to user actions:
|
||||||
* - either when the `<ReactFlow nodes>` prop is updated in the controlled ReactFlow setup,
|
* - either when the `<ReactFlow nodes>` prop is updated in the controlled ReactFlow setup,
|
||||||
* - or when the user calls something like `reactFlowInstance.setNodes()` in an uncontrolled ReactFlow setup.
|
* - or when the user calls something like `reactFlowInstance.setNodes()` in an uncontrolled ReactFlow setup.
|
||||||
*
|
*
|
||||||
* When this happens, we take the note objects passed by the user and extend them with fields
|
* When this happens, we take the note objects passed by the user and extend them with fields
|
||||||
* relevant for internal React Flow operations.
|
* relevant for internal React Flow operations.
|
||||||
*/
|
*/
|
||||||
@@ -154,16 +154,18 @@ const createStore = ({
|
|||||||
const changes = [];
|
const changes = [];
|
||||||
|
|
||||||
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 = get().nodeLookup.get(id);
|
||||||
|
const expandParent = !!(node?.expandParent && node?.parentId && dragItem?.position);
|
||||||
|
|
||||||
const change: NodeChange = {
|
const change: NodeChange = {
|
||||||
id,
|
id,
|
||||||
type: 'position',
|
type: 'position',
|
||||||
position: expandParent
|
position: expandParent
|
||||||
? {
|
? {
|
||||||
x: Math.max(0, dragItem.position.x),
|
x: Math.max(0, dragItem.position.x),
|
||||||
y: Math.max(0, dragItem.position.y),
|
y: Math.max(0, dragItem.position.y),
|
||||||
}
|
}
|
||||||
: dragItem.position,
|
: dragItem.position,
|
||||||
dragging,
|
dragging,
|
||||||
};
|
};
|
||||||
@@ -171,7 +173,7 @@ const createStore = ({
|
|||||||
if (expandParent) {
|
if (expandParent) {
|
||||||
parentExpandChildren.push({
|
parentExpandChildren.push({
|
||||||
id,
|
id,
|
||||||
parentId: dragItem.parentId!,
|
parentId: node.parentId!,
|
||||||
rect: {
|
rect: {
|
||||||
...dragItem.internals.positionAbsolute,
|
...dragItem.internals.positionAbsolute,
|
||||||
width: dragItem.measured.width!,
|
width: dragItem.measured.width!,
|
||||||
|
|||||||
Reference in New Issue
Block a user