@@ -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
|
||||||
|
|||||||
Generated
+1806
-3368
File diff suppressed because it is too large
Load Diff
@@ -5,8 +5,8 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"react-dom": "^16.13.1",
|
"react-dom": "^16.13.1",
|
||||||
"react-flow-renderer": "file:../",
|
"react-flow-renderer": "file:../",
|
||||||
"react-router-dom": "^5.1.2",
|
"react-router-dom": "^5.2.0",
|
||||||
"react-scripts": "3.4.1"
|
"react-scripts": "3.4.3"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "react-scripts start",
|
"start": "react-scripts start",
|
||||||
|
|||||||
@@ -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}
|
||||||
|
|||||||
@@ -186,6 +186,7 @@ export default (NodeComponent: ComponentType<NodeComponentProps>) => {
|
|||||||
sourcePosition,
|
sourcePosition,
|
||||||
targetPosition,
|
targetPosition,
|
||||||
isHidden,
|
isHidden,
|
||||||
|
isInitialized,
|
||||||
}: WrapNodeProps) => {
|
}: WrapNodeProps) => {
|
||||||
const updateNodeDimensions = useStoreActions((actions) => actions.updateNodeDimensions);
|
const updateNodeDimensions = useStoreActions((actions) => actions.updateNodeDimensions);
|
||||||
const setSelectedElements = useStoreActions((actions) => actions.setSelectedElements);
|
const setSelectedElements = useStoreActions((actions) => actions.setSelectedElements);
|
||||||
@@ -282,6 +283,7 @@ export default (NodeComponent: ComponentType<NodeComponentProps>) => {
|
|||||||
zIndex: selected ? 10 : 3,
|
zIndex: selected ? 10 : 3,
|
||||||
transform: `translate(${xPos}px,${yPos}px)`,
|
transform: `translate(${xPos}px,${yPos}px)`,
|
||||||
pointerEvents: isSelectable || isDraggable || onClick ? 'all' : 'none',
|
pointerEvents: isSelectable || isDraggable || onClick ? 'all' : 'none',
|
||||||
|
opacity: isInitialized ? 1 : 0, // prevents jumping of nodes on start
|
||||||
...style,
|
...style,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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]);
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ function renderNode(
|
|||||||
const isDraggable = !!(node.draggable || (nodesDraggable && typeof node.draggable === 'undefined'));
|
const isDraggable = !!(node.draggable || (nodesDraggable && typeof node.draggable === 'undefined'));
|
||||||
const isSelectable = !!(node.selectable || (elementsSelectable && typeof node.selectable === 'undefined'));
|
const isSelectable = !!(node.selectable || (elementsSelectable && typeof node.selectable === 'undefined'));
|
||||||
const isConnectable = !!(node.connectable || (nodesConnectable && typeof node.connectable === 'undefined'));
|
const isConnectable = !!(node.connectable || (nodesConnectable && typeof node.connectable === 'undefined'));
|
||||||
|
const isInitialized = node.__rf.width !== null && node.__rf.height !== null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<NodeComponent
|
<NodeComponent
|
||||||
@@ -64,6 +65,7 @@ function renderNode(
|
|||||||
targetPosition={node.targetPosition}
|
targetPosition={node.targetPosition}
|
||||||
selectNodesOnDrag={props.selectNodesOnDrag}
|
selectNodesOnDrag={props.selectNodesOnDrag}
|
||||||
isHidden={node.isHidden}
|
isHidden={node.isHidden}
|
||||||
|
isInitialized={isInitialized}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
+1
-2
@@ -117,7 +117,6 @@
|
|||||||
.react-flow__node-default.selectable,
|
.react-flow__node-default.selectable,
|
||||||
.react-flow__node-input.selectable,
|
.react-flow__node-input.selectable,
|
||||||
.react-flow__node-output.selectable {
|
.react-flow__node-output.selectable {
|
||||||
|
|
||||||
&.selected,
|
&.selected,
|
||||||
&.selected:hover {
|
&.selected:hover {
|
||||||
box-shadow: 0 0 0 1px #333;
|
box-shadow: 0 0 0 1px #333;
|
||||||
@@ -194,4 +193,4 @@
|
|||||||
right: 0;
|
right: 0;
|
||||||
top: 50%;
|
top: 50%;
|
||||||
transform: translate(0, -50%);
|
transform: translate(0, -50%);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -171,6 +171,7 @@ export interface WrapNodeProps {
|
|||||||
sourcePosition?: Position;
|
sourcePosition?: Position;
|
||||||
targetPosition?: Position;
|
targetPosition?: Position;
|
||||||
isHidden?: boolean;
|
isHidden?: boolean;
|
||||||
|
isInitialized?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type FitViewParams = {
|
export type FitViewParams = {
|
||||||
@@ -210,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