Skip to content

Commit 88a3124

Browse files
committed
Avoid unintentional react-dnd type collisions
1 parent f57bfb3 commit 88a3124

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/utils/drag-and-drop-utils.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ const externalSource = {
4141
...props.node,
4242
},
4343
path: [],
44-
type: 'NewItem'
45-
}
44+
type: 'rst__NewItem',
45+
};
4646
},
4747

4848
endDrag(props, monitor) {
@@ -68,24 +68,23 @@ function getTargetDepth(dropTargetProps, monitor, component) {
6868
}
6969

7070
let blocksOffset;
71-
if (monitor.getItem().type !== 'NewItem') {
72-
blocksOffset = Math.round(
73-
monitor.getDifferenceFromInitialOffset().x /
74-
dropTargetProps.scaffoldBlockPxWidth
75-
);
76-
} else if (monitor.getItem().type === 'NewItem') {
71+
if (monitor.getItem().type === 'rst__NewItem') {
72+
// Add new node from external source
7773
if (component) {
7874
const relativePosition = findDOMNode(component).getBoundingClientRect(); // eslint-disable-line react/no-find-dom-node
79-
const leftShift = monitor.getSourceClientOffset().x - relativePosition.left;
75+
const leftShift =
76+
monitor.getSourceClientOffset().x - relativePosition.left;
8077
blocksOffset = Math.round(
81-
leftShift /
82-
dropTargetProps.scaffoldBlockPxWidth
78+
leftShift / dropTargetProps.scaffoldBlockPxWidth
8379
);
8480
} else {
8581
blocksOffset = dropTargetProps.path.length;
8682
}
8783
} else {
88-
blocksOffset = 0;
84+
blocksOffset = Math.round(
85+
monitor.getDifferenceFromInitialOffset().x /
86+
dropTargetProps.scaffoldBlockPxWidth
87+
);
8988
}
9089

9190
let targetDepth = Math.min(

0 commit comments

Comments
 (0)