refactor(edge-updater): pass handle type #1212

This commit is contained in:
moklick
2021-05-28 14:26:03 +02:00
parent 64510998c0
commit 3124d46732
4 changed files with 12 additions and 6 deletions
+2 -1
View File
@@ -150,7 +150,8 @@ export default (EdgeComponent: ComponentType<EdgeProps>) => {
onConnectEdge,
isTarget,
isValidConnection,
connectionMode
connectionMode,
isSourceHandle ? 'target' : 'source'
);
},
[id, source, target, type, sourceHandleId, targetHandleId, setConnectionNodeId, setPosition, edgeElement]
+4 -3
View File
@@ -12,6 +12,7 @@ import {
ConnectionMode,
SetConnectionId,
Connection,
HandleType,
} from '../../types';
type ValidConnectionFunc = (connection: Connection) => boolean;
@@ -96,6 +97,7 @@ export function onMouseDown(
isTarget: boolean,
isValidConnection: ValidConnectionFunc,
connectionMode: ConnectionMode,
elementEdgeUpdaterType?: HandleType | null,
onConnectStart?: OnConnectStartFunc,
onConnectStop?: OnConnectStopFunc,
onConnectEnd?: OnConnectEndFunc
@@ -111,13 +113,12 @@ export function onMouseDown(
const elementBelow = doc.elementFromPoint(event.clientX, event.clientY);
const elementBelowIsTarget = elementBelow?.classList.contains('target');
const elementBelowIsSource = elementBelow?.classList.contains('source');
const elementBelowIsUpdater = elementBelow?.classList.contains('react-flow__edgeupdater');
if (!reactFlowNode || (!elementBelowIsTarget && !elementBelowIsSource && !elementBelowIsUpdater)) {
if (!reactFlowNode || (!elementBelowIsTarget && !elementBelowIsSource && !elementEdgeUpdaterType)) {
return;
}
const handleType = elementBelowIsTarget ? 'target' : 'source';
const handleType = elementEdgeUpdaterType ? elementEdgeUpdaterType : elementBelowIsTarget ? 'target' : 'source';
const containerBounds = reactFlowNode.getBoundingClientRect();
let recentHoveredHandle: Element;
+3 -2
View File
@@ -45,12 +45,13 @@ const Handle: FC<HandleProps & Omit<HTMLAttributes<HTMLDivElement>, 'id'>> = ({
event,
handleId,
nodeId,
(setConnectionNodeId as unknown) as SetSourceIdFunc,
(setPosition as unknown) as SetPosition,
setConnectionNodeId as unknown as SetSourceIdFunc,
setPosition as unknown as SetPosition,
onConnectExtended,
isTarget,
isValidConnection,
connectionMode,
null,
onConnectStart,
onConnectStop,
onConnectEnd