fix(connection): remove connecting class on mouse leave
This commit is contained in:
@@ -11,6 +11,13 @@ function onMouseDown(evt, { nodeId, setSourceId, setPosition, onConnect, isTarg
|
|||||||
});
|
});
|
||||||
setSourceId(nodeId);
|
setSourceId(nodeId);
|
||||||
|
|
||||||
|
function resetRecentHandle() {
|
||||||
|
if (recentHoveredHandle) {
|
||||||
|
recentHoveredHandle.classList.remove('valid');
|
||||||
|
recentHoveredHandle.classList.remove('connecting');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// checks if element below mouse is a handle and returns connection in form of an object { source: 123, target: 312 }
|
// checks if element below mouse is a handle and returns connection in form of an object { source: 123, target: 312 }
|
||||||
function checkElementBelowIsValid(evt) {
|
function checkElementBelowIsValid(evt) {
|
||||||
const elementBelow = document.elementFromPoint(evt.clientX, evt.clientY);
|
const elementBelow = document.elementFromPoint(evt.clientX, evt.clientY);
|
||||||
@@ -51,11 +58,7 @@ function onMouseDown(evt, { nodeId, setSourceId, setPosition, onConnect, isTarg
|
|||||||
const { connection, elementBelow, isValid, isHoveringHandle } = checkElementBelowIsValid(evt);
|
const { connection, elementBelow, isValid, isHoveringHandle } = checkElementBelowIsValid(evt);
|
||||||
|
|
||||||
if (!isHoveringHandle) {
|
if (!isHoveringHandle) {
|
||||||
if (recentHoveredHandle) {
|
return resetRecentHandle();
|
||||||
recentHoveredHandle.classList.remove('valid');
|
|
||||||
recentHoveredHandle.classList.remove('connecting');
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const isOwnHandle = connection.source === connection.target;
|
const isOwnHandle = connection.source === connection.target;
|
||||||
@@ -74,11 +77,9 @@ function onMouseDown(evt, { nodeId, setSourceId, setPosition, onConnect, isTarg
|
|||||||
onConnect(connection);
|
onConnect(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (recentHoveredHandle) {
|
resetRecentHandle();
|
||||||
recentHoveredHandle.classList.remove('valid');
|
|
||||||
}
|
|
||||||
|
|
||||||
setSourceId(null);
|
setSourceId(null);
|
||||||
|
|
||||||
document.removeEventListener('mousemove', onMouseMove);
|
document.removeEventListener('mousemove', onMouseMove);
|
||||||
document.removeEventListener('mouseup', onMouseUp);
|
document.removeEventListener('mouseup', onMouseUp);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user