diff --git a/example/src/CustomNode/ColorSelectorNode.tsx b/example/src/CustomNode/ColorSelectorNode.tsx index 7ad20340..ac716829 100644 --- a/example/src/CustomNode/ColorSelectorNode.tsx +++ b/example/src/CustomNode/ColorSelectorNode.tsx @@ -16,7 +16,16 @@ const ColorSelectorNode: FC = ({ data, isConnectable }) => { Custom Color Picker Node: {data.color} - + { + console.log('You trigger mousedown event', e); + }} + /> ); diff --git a/src/components/Edges/wrapEdge.tsx b/src/components/Edges/wrapEdge.tsx index c6ef326f..47fb9c85 100644 --- a/src/components/Edges/wrapEdge.tsx +++ b/src/components/Edges/wrapEdge.tsx @@ -4,7 +4,7 @@ import shallow from 'zustand/shallow'; import { useStore, useStoreApi } from '../../store'; import { Edge, EdgeProps, WrapEdgeProps, ReactFlowState, Connection } from '../../types'; -import { onMouseDown } from '../../components/Handle/handler'; +import { handleMouseDown } from '../../components/Handle/handler'; import { EdgeAnchor } from './EdgeAnchor'; import { getMarkerId } from '../../utils/graph'; @@ -160,7 +160,7 @@ export default (EdgeComponent: ComponentType) => { } }; - onMouseDown( + handleMouseDown( event, handleId, nodeId, diff --git a/src/components/Handle/handler.ts b/src/components/Handle/handler.ts index c695c557..54a843fc 100644 --- a/src/components/Handle/handler.ts +++ b/src/components/Handle/handler.ts @@ -82,7 +82,7 @@ function resetRecentHandle(hoveredHandle: Element): void { hoveredHandle?.classList.remove('react-flow__handle-connecting'); } -export function onMouseDown( +export function handleMouseDown( event: ReactMouseEvent, handleId: string | null, nodeId: string, diff --git a/src/components/Handle/index.tsx b/src/components/Handle/index.tsx index 93c9a5a1..873af7c5 100644 --- a/src/components/Handle/index.tsx +++ b/src/components/Handle/index.tsx @@ -5,7 +5,7 @@ import shallow from 'zustand/shallow'; import { useStore, useStoreApi } from '../../store'; import NodeIdContext from '../../contexts/NodeIdContext'; import { HandleProps, Connection, ReactFlowState, Position } from '../../types'; -import { checkElementBelowIsValid, onMouseDown } from './handler'; +import { checkElementBelowIsValid, handleMouseDown } from './handler'; import { getHostForElement } from '../../utils'; import { addEdge } from '../../utils/graph'; @@ -35,6 +35,7 @@ const Handle = forwardRef( onConnect, children, className, + onMouseDown, ...rest }, ref @@ -75,9 +76,9 @@ const Handle = forwardRef( ); const onMouseDownHandler = useCallback( - (event: React.MouseEvent) => { + (event: React.MouseEvent) => { if (event.button === 0) { - onMouseDown( + handleMouseDown( event, handleId, nodeId, @@ -93,6 +94,7 @@ const Handle = forwardRef( onConnectEnd ); } + onMouseDown?.(event); }, [ handleId,