feat(props): add onConnectEnd function #451
This commit is contained in:
@@ -91,6 +91,7 @@ const BasicFlow = () => <ReactFlow elements={elements} />;
|
|||||||
- `onConnect({ source, target })`: called when user connects two nodes
|
- `onConnect({ source, target })`: called when user connects two nodes
|
||||||
- `onConnectStart(event: MouseEvent, { nodeId, handleType })`: called when user starts to drag connection line
|
- `onConnectStart(event: MouseEvent, { nodeId, handleType })`: called when user starts to drag connection line
|
||||||
- `onConnectStop(event: MouseEvent)`: called when user stops to drag connection line
|
- `onConnectStop(event: MouseEvent)`: called when user stops to drag connection line
|
||||||
|
- `onConnectEnd(event: MouseEvent)`: called after user stops or connects nodes
|
||||||
- `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,6 +15,7 @@ const onLoad = (reactFlowInstance) => reactFlowInstance.fitView();
|
|||||||
const isValidConnection = (connection) => connection.target === 'B';
|
const isValidConnection = (connection) => connection.target === 'B';
|
||||||
const onConnectStart = (event, { nodeId, handleType }) => console.log('on connect start', { nodeId, handleType });
|
const onConnectStart = (event, { nodeId, handleType }) => console.log('on connect start', { nodeId, handleType });
|
||||||
const onConnectStop = (event) => console.log('on connect stop', event);
|
const onConnectStop = (event) => console.log('on connect stop', event);
|
||||||
|
const onConnectEnd = (event) => console.log('on connect end', event);
|
||||||
|
|
||||||
const CustomInput = () => (
|
const CustomInput = () => (
|
||||||
<>
|
<>
|
||||||
@@ -53,6 +54,7 @@ const HorizontalFlow = () => {
|
|||||||
nodeTypes={nodeTypes}
|
nodeTypes={nodeTypes}
|
||||||
onConnectStart={onConnectStart}
|
onConnectStart={onConnectStart}
|
||||||
onConnectStop={onConnectStop}
|
onConnectStop={onConnectStop}
|
||||||
|
onConnectEnd={onConnectEnd}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
OnConnectFunc,
|
OnConnectFunc,
|
||||||
OnConnectStartFunc,
|
OnConnectStartFunc,
|
||||||
OnConnectStopFunc,
|
OnConnectStopFunc,
|
||||||
|
OnConnectEndFunc,
|
||||||
Connection,
|
Connection,
|
||||||
SetConnectionId,
|
SetConnectionId,
|
||||||
} from '../../types';
|
} from '../../types';
|
||||||
@@ -22,6 +23,7 @@ interface BaseHandleProps {
|
|||||||
onConnect: OnConnectFunc;
|
onConnect: OnConnectFunc;
|
||||||
onConnectStart?: OnConnectStartFunc;
|
onConnectStart?: OnConnectStartFunc;
|
||||||
onConnectStop?: OnConnectStopFunc;
|
onConnectStop?: OnConnectStopFunc;
|
||||||
|
onConnectEnd?: OnConnectEndFunc;
|
||||||
position: Position;
|
position: Position;
|
||||||
setConnectionNodeId: SetSourceIdFunc;
|
setConnectionNodeId: SetSourceIdFunc;
|
||||||
setPosition: (pos: XYPosition) => void;
|
setPosition: (pos: XYPosition) => void;
|
||||||
@@ -47,7 +49,8 @@ function onMouseDown(
|
|||||||
isTarget: boolean,
|
isTarget: boolean,
|
||||||
isValidConnection: ValidConnectionFunc,
|
isValidConnection: ValidConnectionFunc,
|
||||||
onConnectStart?: OnConnectStartFunc,
|
onConnectStart?: OnConnectStartFunc,
|
||||||
onConnectStop?: OnConnectStopFunc
|
onConnectStop?: OnConnectStopFunc,
|
||||||
|
onConnectEnd?: OnConnectEndFunc
|
||||||
): void {
|
): void {
|
||||||
const reactFlowNode = document.querySelector('.react-flow');
|
const reactFlowNode = document.querySelector('.react-flow');
|
||||||
|
|
||||||
@@ -142,6 +145,10 @@ function onMouseDown(
|
|||||||
onConnect(connection);
|
onConnect(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (onConnectEnd) {
|
||||||
|
onConnectEnd(event);
|
||||||
|
}
|
||||||
|
|
||||||
resetRecentHandle();
|
resetRecentHandle();
|
||||||
setConnectionNodeId({ connectionNodeId: null, connectionHandleType: null });
|
setConnectionNodeId({ connectionNodeId: null, connectionHandleType: null });
|
||||||
|
|
||||||
@@ -159,6 +166,7 @@ const BaseHandle = ({
|
|||||||
onConnect,
|
onConnect,
|
||||||
onConnectStart,
|
onConnectStart,
|
||||||
onConnectStop,
|
onConnectStop,
|
||||||
|
onConnectEnd,
|
||||||
position,
|
position,
|
||||||
setConnectionNodeId,
|
setConnectionNodeId,
|
||||||
setPosition,
|
setPosition,
|
||||||
@@ -196,7 +204,8 @@ const BaseHandle = ({
|
|||||||
isTarget,
|
isTarget,
|
||||||
isValidConnection,
|
isValidConnection,
|
||||||
onConnectStart,
|
onConnectStart,
|
||||||
onConnectStop
|
onConnectStop,
|
||||||
|
onConnectEnd
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
{...rest}
|
{...rest}
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ const Handle = ({
|
|||||||
const onConnectAction = useStoreState((state) => state.onConnect);
|
const onConnectAction = useStoreState((state) => state.onConnect);
|
||||||
const onConnectStart = useStoreState((state) => state.onConnectStart);
|
const onConnectStart = useStoreState((state) => state.onConnectStart);
|
||||||
const onConnectStop = useStoreState((state) => state.onConnectStop);
|
const onConnectStop = useStoreState((state) => state.onConnectStop);
|
||||||
|
const onConnectEnd = useStoreState((state) => state.onConnectEnd);
|
||||||
|
|
||||||
const onConnectExtended = (params: Connection) => {
|
const onConnectExtended = (params: Connection) => {
|
||||||
if (onConnectAction) {
|
if (onConnectAction) {
|
||||||
onConnectAction(params);
|
onConnectAction(params);
|
||||||
@@ -44,6 +46,7 @@ const Handle = ({
|
|||||||
onConnect={onConnectExtended}
|
onConnect={onConnectExtended}
|
||||||
onConnectStart={onConnectStart}
|
onConnectStart={onConnectStart}
|
||||||
onConnectStop={onConnectStop}
|
onConnectStop={onConnectStop}
|
||||||
|
onConnectEnd={onConnectEnd}
|
||||||
type={type}
|
type={type}
|
||||||
position={position}
|
position={position}
|
||||||
isValidConnection={isValidConnection}
|
isValidConnection={isValidConnection}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import {
|
|||||||
FlowTransform,
|
FlowTransform,
|
||||||
OnConnectStartFunc,
|
OnConnectStartFunc,
|
||||||
OnConnectStopFunc,
|
OnConnectStopFunc,
|
||||||
|
OnConnectEndFunc,
|
||||||
} from '../../types';
|
} from '../../types';
|
||||||
|
|
||||||
export interface GraphViewProps {
|
export interface GraphViewProps {
|
||||||
@@ -38,6 +39,7 @@ export interface GraphViewProps {
|
|||||||
onConnect?: (connection: Connection | Edge) => void;
|
onConnect?: (connection: Connection | Edge) => void;
|
||||||
onConnectStart?: OnConnectStartFunc;
|
onConnectStart?: OnConnectStartFunc;
|
||||||
onConnectStop?: OnConnectStopFunc;
|
onConnectStop?: OnConnectStopFunc;
|
||||||
|
onConnectEnd?: OnConnectEndFunc;
|
||||||
onLoad?: OnLoadFunc;
|
onLoad?: OnLoadFunc;
|
||||||
onMove?: (flowTransform?: FlowTransform) => void;
|
onMove?: (flowTransform?: FlowTransform) => void;
|
||||||
onMoveStart?: (flowTransform?: FlowTransform) => void;
|
onMoveStart?: (flowTransform?: FlowTransform) => void;
|
||||||
@@ -91,6 +93,7 @@ const GraphView = ({
|
|||||||
onConnect,
|
onConnect,
|
||||||
onConnectStart,
|
onConnectStart,
|
||||||
onConnectStop,
|
onConnectStop,
|
||||||
|
onConnectEnd,
|
||||||
snapToGrid,
|
snapToGrid,
|
||||||
snapGrid,
|
snapGrid,
|
||||||
onlyRenderVisibleNodes,
|
onlyRenderVisibleNodes,
|
||||||
@@ -119,6 +122,7 @@ const GraphView = ({
|
|||||||
const setOnConnect = useStoreActions((actions) => actions.setOnConnect);
|
const setOnConnect = useStoreActions((actions) => actions.setOnConnect);
|
||||||
const setOnConnectStart = useStoreActions((actions) => actions.setOnConnectStart);
|
const setOnConnectStart = useStoreActions((actions) => actions.setOnConnectStart);
|
||||||
const setOnConnectStop = useStoreActions((actions) => actions.setOnConnectStop);
|
const setOnConnectStop = useStoreActions((actions) => actions.setOnConnectStop);
|
||||||
|
const setOnConnectEnd = useStoreActions((actions) => actions.setOnConnectEnd);
|
||||||
const setSnapGrid = useStoreActions((actions) => actions.setSnapGrid);
|
const setSnapGrid = useStoreActions((actions) => actions.setSnapGrid);
|
||||||
const setNodesDraggable = useStoreActions((actions) => actions.setNodesDraggable);
|
const setNodesDraggable = useStoreActions((actions) => actions.setNodesDraggable);
|
||||||
const setNodesConnectable = useStoreActions((actions) => actions.setNodesConnectable);
|
const setNodesConnectable = useStoreActions((actions) => actions.setNodesConnectable);
|
||||||
@@ -209,6 +213,12 @@ const GraphView = ({
|
|||||||
}
|
}
|
||||||
}, [onConnectStop]);
|
}, [onConnectStop]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (onConnectEnd) {
|
||||||
|
setOnConnectEnd(onConnectEnd);
|
||||||
|
}
|
||||||
|
}, [onConnectEnd]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setSnapGrid({ snapToGrid, snapGrid });
|
setSnapGrid({ snapToGrid, snapGrid });
|
||||||
}, [snapToGrid, snapGrid]);
|
}, [snapToGrid, snapGrid]);
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import {
|
|||||||
FlowTransform,
|
FlowTransform,
|
||||||
OnConnectStartFunc,
|
OnConnectStartFunc,
|
||||||
OnConnectStopFunc,
|
OnConnectStopFunc,
|
||||||
|
OnConnectEndFunc,
|
||||||
} from '../../types';
|
} from '../../types';
|
||||||
|
|
||||||
import '../../style.css';
|
import '../../style.css';
|
||||||
@@ -46,6 +47,7 @@ export interface ReactFlowProps extends Omit<HTMLAttributes<HTMLDivElement>, 'on
|
|||||||
onConnect?: (connection: Edge | Connection) => void;
|
onConnect?: (connection: Edge | Connection) => void;
|
||||||
onConnectStart?: OnConnectStartFunc;
|
onConnectStart?: OnConnectStartFunc;
|
||||||
onConnectStop?: OnConnectStopFunc;
|
onConnectStop?: OnConnectStopFunc;
|
||||||
|
onConnectEnd?: OnConnectEndFunc;
|
||||||
onLoad?: OnLoadFunc;
|
onLoad?: OnLoadFunc;
|
||||||
onMove?: (flowTransform?: FlowTransform) => void;
|
onMove?: (flowTransform?: FlowTransform) => void;
|
||||||
onMoveStart?: (flowTransform?: FlowTransform) => void;
|
onMoveStart?: (flowTransform?: FlowTransform) => void;
|
||||||
@@ -93,6 +95,7 @@ const ReactFlow = ({
|
|||||||
onConnect,
|
onConnect,
|
||||||
onConnectStart,
|
onConnectStart,
|
||||||
onConnectStop,
|
onConnectStop,
|
||||||
|
onConnectEnd,
|
||||||
onNodeMouseEnter,
|
onNodeMouseEnter,
|
||||||
onNodeMouseMove,
|
onNodeMouseMove,
|
||||||
onNodeMouseLeave,
|
onNodeMouseLeave,
|
||||||
@@ -153,6 +156,7 @@ const ReactFlow = ({
|
|||||||
onConnect={onConnect}
|
onConnect={onConnect}
|
||||||
onConnectStart={onConnectStart}
|
onConnectStart={onConnectStart}
|
||||||
onConnectStop={onConnectStop}
|
onConnectStop={onConnectStop}
|
||||||
|
onConnectEnd={onConnectEnd}
|
||||||
snapToGrid={snapToGrid}
|
snapToGrid={snapToGrid}
|
||||||
snapGrid={snapGrid}
|
snapGrid={snapGrid}
|
||||||
onlyRenderVisibleNodes={onlyRenderVisibleNodes}
|
onlyRenderVisibleNodes={onlyRenderVisibleNodes}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import {
|
|||||||
OnConnectFunc,
|
OnConnectFunc,
|
||||||
OnConnectStartFunc,
|
OnConnectStartFunc,
|
||||||
OnConnectStopFunc,
|
OnConnectStopFunc,
|
||||||
|
OnConnectEndFunc,
|
||||||
SelectionRect,
|
SelectionRect,
|
||||||
HandleType,
|
HandleType,
|
||||||
SetConnectionId,
|
SetConnectionId,
|
||||||
@@ -86,10 +87,12 @@ export interface StoreModel {
|
|||||||
onConnect?: OnConnectFunc;
|
onConnect?: OnConnectFunc;
|
||||||
onConnectStart?: OnConnectStartFunc;
|
onConnectStart?: OnConnectStartFunc;
|
||||||
onConnectStop?: OnConnectStopFunc;
|
onConnectStop?: OnConnectStopFunc;
|
||||||
|
onConnectEnd?: OnConnectEndFunc;
|
||||||
|
|
||||||
setOnConnect: Action<StoreModel, OnConnectFunc>;
|
setOnConnect: Action<StoreModel, OnConnectFunc>;
|
||||||
setOnConnectStart: Action<StoreModel, OnConnectStartFunc>;
|
setOnConnectStart: Action<StoreModel, OnConnectStartFunc>;
|
||||||
setOnConnectStop: Action<StoreModel, OnConnectStopFunc>;
|
setOnConnectStop: Action<StoreModel, OnConnectStopFunc>;
|
||||||
|
setOnConnectEnd: Action<StoreModel, OnConnectEndFunc>;
|
||||||
|
|
||||||
setElements: Action<StoreModel, Elements>;
|
setElements: Action<StoreModel, Elements>;
|
||||||
|
|
||||||
@@ -186,6 +189,9 @@ export const storeModel: StoreModel = {
|
|||||||
setOnConnectStop: action((state, onConnectStop) => {
|
setOnConnectStop: action((state, onConnectStop) => {
|
||||||
state.onConnectStop = onConnectStop;
|
state.onConnectStop = onConnectStop;
|
||||||
}),
|
}),
|
||||||
|
setOnConnectEnd: action((state, onConnectEnd) => {
|
||||||
|
state.onConnectEnd = onConnectEnd;
|
||||||
|
}),
|
||||||
|
|
||||||
setElements: action((state, elements) => {
|
setElements: action((state, elements) => {
|
||||||
state.elements = elements;
|
state.elements = elements;
|
||||||
|
|||||||
@@ -211,6 +211,7 @@ export type OnConnectStartParams = {
|
|||||||
};
|
};
|
||||||
export type OnConnectStartFunc = (event: ReactMouseEvent, params: OnConnectStartParams) => void;
|
export type OnConnectStartFunc = (event: ReactMouseEvent, params: OnConnectStartParams) => void;
|
||||||
export type OnConnectStopFunc = (event: MouseEvent) => void;
|
export type OnConnectStopFunc = (event: MouseEvent) => void;
|
||||||
|
export type OnConnectEndFunc = (event: MouseEvent) => void;
|
||||||
|
|
||||||
export type SetConnectionId = {
|
export type SetConnectionId = {
|
||||||
connectionNodeId: ElementId | null;
|
connectionNodeId: ElementId | null;
|
||||||
|
|||||||
Reference in New Issue
Block a user