fix(connectionLine): add container bounds

This commit is contained in:
moklick
2019-07-31 11:48:16 +02:00
parent 2d5e2d9241
commit 191bc11253
5 changed files with 15 additions and 31 deletions
+4 -3
View File
@@ -6,11 +6,12 @@ import { GraphContext } from '../../GraphContext';
import { setConnecting, setConnectionPos } from '../../state/actions';
function onMouseDown(evt, nodeId, dispatch, onConnect) {
const connectionPosition = { x: evt.clientX, y: evt.clientY };
const containerBounds = document.querySelector('.react-graph').getBoundingClientRect();
const connectionPosition = { x: evt.clientX - containerBounds.x, y: evt.clientY - containerBounds.y };
dispatch(setConnecting({ connectionPosition, connectionSourceId: nodeId }))
function onMouseMove(evt) {
dispatch(setConnectionPos({ x: evt.clientX, y: evt.clientY }));
dispatch(setConnectionPos({ x: evt.clientX - containerBounds.x, y: evt.clientY - containerBounds.y }));
}
function onMouseUp(evt) {
@@ -46,7 +47,7 @@ export default memo(({ source, target, className = null, ...rest }) => {
className={handleClasses}
{...rest}
/>
)
);
}
return (
-7
View File
@@ -29,12 +29,6 @@ const getHandleBounds = (sel, nodeElement, parentBounds, k) => {
};
};
const onDragOver = evt => {
evt.preventDefault();
evt.dataTransfer.dropEffect = 'move';
}
export default NodeComponent => memo((props) => {
const nodeElement = useRef(null);
const { state, dispatch } = useContext(GraphContext);
@@ -113,7 +107,6 @@ export default NodeComponent => memo((props) => {
scale={k}
>
<div
onDragOver={onDragOver}
className={nodeClasses}
ref={nodeElement}
style={{ zIndex: selected ? 10 : 3, transform: `translate(${position.x}px,${position.y}px)` }}