feat(props): add mouse event to onConnectStart and onConnectStop
This commit is contained in:
@@ -88,8 +88,8 @@ const BasicFlow = () => <ReactFlow elements={elements} />;
|
|||||||
- `onNodeMouseLeave(evt: MouseEvent, node: Node)`: node mouse leave
|
- `onNodeMouseLeave(evt: MouseEvent, node: Node)`: node mouse leave
|
||||||
- `onNodeContextMenu(evt: MouseEvent, node: Node)`: node context menu
|
- `onNodeContextMenu(evt: MouseEvent, node: Node)`: node context menu
|
||||||
- `onConnect({ source, target })`: called when user connects two nodes
|
- `onConnect({ source, target })`: called when user connects two nodes
|
||||||
- `onConnectStart({ nodeId, handleType })`: called when user starts to drag connection line
|
- `onConnectStart(evt: MouseEvent, { nodeId, handleType })`: called when user starts to drag connection line
|
||||||
- `onConnectStop()`: called when user stops to drag connection line
|
- `onConnectStop(evt: MouseEvent)`: called when user stops to drag connection line
|
||||||
- `onLoad(reactFlowInstance)`: called after flow is initialized
|
- `onLoad(reactFlowInstance)`: called after flow is initialized
|
||||||
- `onMove()`: called when user is panning or zooming
|
- `onMove()`: called when user is panning or zooming
|
||||||
- `onMoveStart()`: called when user starts panning or zooming
|
- `onMoveStart()`: called when user starts panning or zooming
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ const isValidConnection = (connection) => connection.target === 'B';
|
|||||||
|
|
||||||
const onLoad = (reactFlowInstance) => reactFlowInstance.fitView();
|
const onLoad = (reactFlowInstance) => reactFlowInstance.fitView();
|
||||||
|
|
||||||
const onConnectStart = ({ nodeId, handleType }) => console.log('on connect start', { nodeId, handleType });
|
const onConnectStart = (evt, { nodeId, handleType }) => console.log('on connect start', { nodeId, handleType });
|
||||||
|
|
||||||
const onConnectStop = () => console.log('on connect stop');
|
const onConnectStop = (evt) => console.log('on connect stop', evt);
|
||||||
|
|
||||||
const CustomInput = () => (
|
const CustomInput = () => (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ function onMouseDown(
|
|||||||
setConnectionNodeId({ connectionNodeId: nodeId, connectionHandleType: handleType });
|
setConnectionNodeId({ connectionNodeId: nodeId, connectionHandleType: handleType });
|
||||||
|
|
||||||
if (onConnectStart) {
|
if (onConnectStart) {
|
||||||
onConnectStart({ nodeId, handleType });
|
onConnectStart(evt, { nodeId, handleType });
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetRecentHandle(): void {
|
function resetRecentHandle(): void {
|
||||||
@@ -142,7 +142,7 @@ function onMouseDown(
|
|||||||
setConnectionNodeId({ connectionNodeId: null, connectionHandleType: null });
|
setConnectionNodeId({ connectionNodeId: null, connectionHandleType: null });
|
||||||
|
|
||||||
if (onConnectStop) {
|
if (onConnectStop) {
|
||||||
onConnectStop();
|
onConnectStop(evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
document.removeEventListener('mousemove', onMouseMove);
|
document.removeEventListener('mousemove', onMouseMove);
|
||||||
|
|||||||
+11
-11
@@ -1,4 +1,4 @@
|
|||||||
import { CSSProperties, MouseEvent } from 'react';
|
import { CSSProperties, MouseEvent as ReactMouseEvent } from 'react';
|
||||||
|
|
||||||
export type ElementId = string;
|
export type ElementId = string;
|
||||||
|
|
||||||
@@ -154,13 +154,13 @@ export interface WrapNodeProps {
|
|||||||
isDraggable: boolean;
|
isDraggable: boolean;
|
||||||
isConnectable: boolean;
|
isConnectable: boolean;
|
||||||
selectNodesOnDrag: boolean;
|
selectNodesOnDrag: boolean;
|
||||||
onClick?: (evt: MouseEvent, node: Node) => void;
|
onClick?: (evt: ReactMouseEvent, node: Node) => void;
|
||||||
onMouseEnter?: (evt: MouseEvent, node: Node) => void;
|
onMouseEnter?: (evt: ReactMouseEvent, node: Node) => void;
|
||||||
onMouseMove?: (evt: MouseEvent, node: Node) => void;
|
onMouseMove?: (evt: ReactMouseEvent, node: Node) => void;
|
||||||
onMouseLeave?: (evt: MouseEvent, node: Node) => void;
|
onMouseLeave?: (evt: ReactMouseEvent, node: Node) => void;
|
||||||
onContextMenu?: (evt: MouseEvent, node: Node) => void;
|
onContextMenu?: (evt: ReactMouseEvent, node: Node) => void;
|
||||||
onNodeDragStart?: (evt: MouseEvent, node: Node) => void;
|
onNodeDragStart?: (evt: ReactMouseEvent, node: Node) => void;
|
||||||
onNodeDragStop?: (evt: MouseEvent, node: Node) => void;
|
onNodeDragStop?: (evt: ReactMouseEvent, node: Node) => void;
|
||||||
style?: CSSProperties;
|
style?: CSSProperties;
|
||||||
className?: string;
|
className?: string;
|
||||||
sourcePosition?: Position;
|
sourcePosition?: Position;
|
||||||
@@ -202,8 +202,8 @@ export type OnConnectStartParams = {
|
|||||||
nodeId: ElementId | null;
|
nodeId: ElementId | null;
|
||||||
handleType: HandleType | null;
|
handleType: HandleType | null;
|
||||||
};
|
};
|
||||||
export type OnConnectStartFunc = (params: OnConnectStartParams) => void;
|
export type OnConnectStartFunc = (evt: ReactMouseEvent, params: OnConnectStartParams) => void;
|
||||||
export type OnConnectStopFunc = () => void;
|
export type OnConnectStopFunc = (evt: MouseEvent) => void;
|
||||||
|
|
||||||
export type SetConnectionId = {
|
export type SetConnectionId = {
|
||||||
connectionNodeId: ElementId | null;
|
connectionNodeId: ElementId | null;
|
||||||
@@ -235,7 +235,7 @@ export interface EdgeCompProps {
|
|||||||
labelStyle?: CSSProperties;
|
labelStyle?: CSSProperties;
|
||||||
labelShowBg?: boolean;
|
labelShowBg?: boolean;
|
||||||
labelBgStyle?: CSSProperties;
|
labelBgStyle?: CSSProperties;
|
||||||
onClick?: (evt: MouseEvent, edge: Edge) => void;
|
onClick?: (evt: ReactMouseEvent, edge: Edge) => void;
|
||||||
animated?: boolean;
|
animated?: boolean;
|
||||||
selected?: boolean;
|
selected?: boolean;
|
||||||
data?: any;
|
data?: any;
|
||||||
|
|||||||
Reference in New Issue
Block a user