refactor(connection): fire onConnect after onConnectStop closes #405
This commit is contained in:
@@ -39,7 +39,7 @@ type Result = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function onMouseDown(
|
function onMouseDown(
|
||||||
evt: ReactMouseEvent,
|
event: ReactMouseEvent,
|
||||||
nodeId: ElementId,
|
nodeId: ElementId,
|
||||||
setConnectionNodeId: SetSourceIdFunc,
|
setConnectionNodeId: SetSourceIdFunc,
|
||||||
setPosition: (pos: XYPosition) => void,
|
setPosition: (pos: XYPosition) => void,
|
||||||
@@ -60,13 +60,13 @@ function onMouseDown(
|
|||||||
let recentHoveredHandle: Element;
|
let recentHoveredHandle: Element;
|
||||||
|
|
||||||
setPosition({
|
setPosition({
|
||||||
x: evt.clientX - containerBounds.left,
|
x: event.clientX - containerBounds.left,
|
||||||
y: evt.clientY - containerBounds.top,
|
y: event.clientY - containerBounds.top,
|
||||||
});
|
});
|
||||||
setConnectionNodeId({ connectionNodeId: nodeId, connectionHandleType: handleType });
|
setConnectionNodeId({ connectionNodeId: nodeId, connectionHandleType: handleType });
|
||||||
|
|
||||||
if (onConnectStart) {
|
if (onConnectStart) {
|
||||||
onConnectStart(evt, { nodeId, handleType });
|
onConnectStart(event, { nodeId, handleType });
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetRecentHandle(): void {
|
function resetRecentHandle(): void {
|
||||||
@@ -79,8 +79,8 @@ function onMouseDown(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 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: MouseEvent) {
|
function checkElementBelowIsValid(event: MouseEvent) {
|
||||||
const elementBelow = document.elementFromPoint(evt.clientX, evt.clientY);
|
const elementBelow = document.elementFromPoint(event.clientX, event.clientY);
|
||||||
|
|
||||||
const result: Result = {
|
const result: Result = {
|
||||||
elementBelow,
|
elementBelow,
|
||||||
@@ -110,13 +110,13 @@ function onMouseDown(
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function onMouseMove(evt: MouseEvent) {
|
function onMouseMove(event: MouseEvent) {
|
||||||
setPosition({
|
setPosition({
|
||||||
x: evt.clientX - containerBounds.left,
|
x: event.clientX - containerBounds.left,
|
||||||
y: evt.clientY - containerBounds.top,
|
y: event.clientY - containerBounds.top,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { connection, elementBelow, isValid, isHoveringHandle } = checkElementBelowIsValid(evt);
|
const { connection, elementBelow, isValid, isHoveringHandle } = checkElementBelowIsValid(event);
|
||||||
|
|
||||||
if (!isHoveringHandle) {
|
if (!isHoveringHandle) {
|
||||||
return resetRecentHandle();
|
return resetRecentHandle();
|
||||||
@@ -131,8 +131,12 @@ function onMouseDown(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onMouseUp(evt: MouseEvent) {
|
function onMouseUp(event: MouseEvent) {
|
||||||
const { connection, isValid } = checkElementBelowIsValid(evt);
|
const { connection, isValid } = checkElementBelowIsValid(event);
|
||||||
|
|
||||||
|
if (onConnectStop) {
|
||||||
|
onConnectStop(event);
|
||||||
|
}
|
||||||
|
|
||||||
if (isValid && onConnect) {
|
if (isValid && onConnect) {
|
||||||
onConnect(connection);
|
onConnect(connection);
|
||||||
@@ -141,10 +145,6 @@ function onMouseDown(
|
|||||||
resetRecentHandle();
|
resetRecentHandle();
|
||||||
setConnectionNodeId({ connectionNodeId: null, connectionHandleType: null });
|
setConnectionNodeId({ connectionNodeId: null, connectionHandleType: null });
|
||||||
|
|
||||||
if (onConnectStop) {
|
|
||||||
onConnectStop(evt);
|
|
||||||
}
|
|
||||||
|
|
||||||
document.removeEventListener('mousemove', onMouseMove);
|
document.removeEventListener('mousemove', onMouseMove);
|
||||||
document.removeEventListener('mouseup', onMouseUp);
|
document.removeEventListener('mouseup', onMouseUp);
|
||||||
}
|
}
|
||||||
@@ -186,9 +186,9 @@ const BaseHandle = ({
|
|||||||
data-nodeid={nodeIdWithHandleId}
|
data-nodeid={nodeIdWithHandleId}
|
||||||
data-handlepos={position}
|
data-handlepos={position}
|
||||||
className={handleClasses}
|
className={handleClasses}
|
||||||
onMouseDown={(evt) =>
|
onMouseDown={(event) =>
|
||||||
onMouseDown(
|
onMouseDown(
|
||||||
evt,
|
event,
|
||||||
nodeIdWithHandleId,
|
nodeIdWithHandleId,
|
||||||
setConnectionNodeId,
|
setConnectionNodeId,
|
||||||
setPosition,
|
setPosition,
|
||||||
|
|||||||
Reference in New Issue
Block a user