refactor(connect-events): add onClickConnect events
This commit is contained in:
Generated
+3
-1
@@ -27,7 +27,7 @@
|
|||||||
},
|
},
|
||||||
"..": {
|
"..": {
|
||||||
"name": "react-flow-renderer",
|
"name": "react-flow-renderer",
|
||||||
"version": "10.2.3-next.1",
|
"version": "10.2.3",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.17.9",
|
"@babel/runtime": "^7.17.9",
|
||||||
@@ -53,6 +53,7 @@
|
|||||||
"@types/resize-observer-browser": "^0.1.7",
|
"@types/resize-observer-browser": "^0.1.7",
|
||||||
"autoprefixer": "^10.4.7",
|
"autoprefixer": "^10.4.7",
|
||||||
"babel-preset-react-app": "^10.0.1",
|
"babel-preset-react-app": "^10.0.1",
|
||||||
|
"cross-env": "^7.0.3",
|
||||||
"cypress": "^9.6.1",
|
"cypress": "^9.6.1",
|
||||||
"postcss": "^8.4.13",
|
"postcss": "^8.4.13",
|
||||||
"postcss-cli": "^9.1.0",
|
"postcss-cli": "^9.1.0",
|
||||||
@@ -31536,6 +31537,7 @@
|
|||||||
"autoprefixer": "^10.4.7",
|
"autoprefixer": "^10.4.7",
|
||||||
"babel-preset-react-app": "^10.0.1",
|
"babel-preset-react-app": "^10.0.1",
|
||||||
"classcat": "^5.0.3",
|
"classcat": "^5.0.3",
|
||||||
|
"cross-env": "^7.0.3",
|
||||||
"cypress": "^9.6.1",
|
"cypress": "^9.6.1",
|
||||||
"d3-drag": "^3.0.0",
|
"d3-drag": "^3.0.0",
|
||||||
"d3-selection": "^3.0.0",
|
"d3-selection": "^3.0.0",
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { MouseEvent as ReactMouseEvent, CSSProperties } from 'react';
|
import { MouseEvent as ReactMouseEvent, CSSProperties, useCallback } from 'react';
|
||||||
import ReactFlow, {
|
import ReactFlow, {
|
||||||
addEdge,
|
addEdge,
|
||||||
MiniMap,
|
MiniMap,
|
||||||
@@ -162,7 +162,7 @@ const nodeColor = (n: Node): string => {
|
|||||||
const OverviewFlow = () => {
|
const OverviewFlow = () => {
|
||||||
const [nodes, , onNodesChange] = useNodesState(initialNodes);
|
const [nodes, , onNodesChange] = useNodesState(initialNodes);
|
||||||
const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges);
|
const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges);
|
||||||
const onConnect = (params: Connection | Edge) => setEdges((eds) => addEdge(params, eds));
|
const onConnect = useCallback((params: Connection | Edge) => setEdges((eds) => addEdge(params, eds)), [setEdges]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ReactFlow
|
<ReactFlow
|
||||||
|
|||||||
@@ -33,7 +33,11 @@ const initialEdges: Edge[] = [];
|
|||||||
const TouchDeviceFlow = () => {
|
const TouchDeviceFlow = () => {
|
||||||
const [nodes, , onNodesChange] = useNodesState(initialNodes);
|
const [nodes, , onNodesChange] = useNodesState(initialNodes);
|
||||||
const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges);
|
const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges);
|
||||||
const onConnect = useCallback((connection: Connection) => setEdges((eds) => addEdge(connection, eds)), []);
|
const onConnect = useCallback((connection: Connection) => setEdges((eds) => addEdge(connection, eds)), [setEdges]);
|
||||||
|
const onConnectStart = useCallback(() => console.log('connect start'), []);
|
||||||
|
const onConnectStop = useCallback(() => console.log('connect end'), []);
|
||||||
|
const onClickConnectStart = useCallback(() => console.log('click connect start'), []);
|
||||||
|
const onClickConnectStop = useCallback(() => console.log('click connect end'), []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ReactFlow
|
<ReactFlow
|
||||||
@@ -42,6 +46,10 @@ const TouchDeviceFlow = () => {
|
|||||||
onConnect={onConnect}
|
onConnect={onConnect}
|
||||||
onNodesChange={onNodesChange}
|
onNodesChange={onNodesChange}
|
||||||
onEdgesChange={onEdgesChange}
|
onEdgesChange={onEdgesChange}
|
||||||
|
onConnectStart={onConnectStart}
|
||||||
|
onConnectStop={onConnectStop}
|
||||||
|
onClickConnectStart={onClickConnectStart}
|
||||||
|
onClickConnectStop={onClickConnectStop}
|
||||||
className="touchdevice-flow"
|
className="touchdevice-flow"
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ const selector = (s: ReactFlowState) => ({
|
|||||||
onConnectStart: s.onConnectStart,
|
onConnectStart: s.onConnectStart,
|
||||||
onConnectStop: s.onConnectStop,
|
onConnectStop: s.onConnectStop,
|
||||||
onConnectEnd: s.onConnectEnd,
|
onConnectEnd: s.onConnectEnd,
|
||||||
|
onClickConnectStart: s.onClickConnectStart,
|
||||||
|
onClickConnectStop: s.onClickConnectStop,
|
||||||
|
onClickConnectEnd: s.onClickConnectEnd,
|
||||||
connectionMode: s.connectionMode,
|
connectionMode: s.connectionMode,
|
||||||
connectionStartHandle: s.connectionStartHandle,
|
connectionStartHandle: s.connectionStartHandle,
|
||||||
connectOnClick: s.connectOnClick,
|
connectOnClick: s.connectOnClick,
|
||||||
@@ -47,6 +50,9 @@ const Handle = forwardRef<HTMLDivElement, HandleComponentProps>(
|
|||||||
onConnectStart,
|
onConnectStart,
|
||||||
onConnectStop,
|
onConnectStop,
|
||||||
onConnectEnd,
|
onConnectEnd,
|
||||||
|
onClickConnectStart,
|
||||||
|
onClickConnectStop,
|
||||||
|
onClickConnectEnd,
|
||||||
connectionMode,
|
connectionMode,
|
||||||
connectionStartHandle,
|
connectionStartHandle,
|
||||||
connectOnClick,
|
connectOnClick,
|
||||||
@@ -95,7 +101,7 @@ const Handle = forwardRef<HTMLDivElement, HandleComponentProps>(
|
|||||||
|
|
||||||
const onClick = (event: React.MouseEvent) => {
|
const onClick = (event: React.MouseEvent) => {
|
||||||
if (!connectionStartHandle) {
|
if (!connectionStartHandle) {
|
||||||
onConnectStart?.(event, { nodeId, handleId, handleType: type });
|
onClickConnectStart?.(event, { nodeId, handleId, handleType: type });
|
||||||
store.setState({ connectionStartHandle: { nodeId, type, handleId } });
|
store.setState({ connectionStartHandle: { nodeId, type, handleId } });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -111,13 +117,13 @@ const Handle = forwardRef<HTMLDivElement, HandleComponentProps>(
|
|||||||
doc
|
doc
|
||||||
);
|
);
|
||||||
|
|
||||||
onConnectStop?.(event as unknown as MouseEvent);
|
onClickConnectStop?.(event as unknown as MouseEvent);
|
||||||
|
|
||||||
if (isValid) {
|
if (isValid) {
|
||||||
onConnectExtended(connection);
|
onConnectExtended(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
onConnectEnd?.(event as unknown as MouseEvent);
|
onClickConnectEnd?.(event as unknown as MouseEvent);
|
||||||
|
|
||||||
store.setState({ connectionStartHandle: null });
|
store.setState({ connectionStartHandle: null });
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import {
|
|||||||
DefaultEdgeOptions,
|
DefaultEdgeOptions,
|
||||||
FitViewOptions,
|
FitViewOptions,
|
||||||
OnNodesDelete,
|
OnNodesDelete,
|
||||||
OnEdgesDelete
|
OnEdgesDelete,
|
||||||
} from '../../types';
|
} from '../../types';
|
||||||
|
|
||||||
interface StoreUpdaterProps {
|
interface StoreUpdaterProps {
|
||||||
@@ -31,6 +31,9 @@ interface StoreUpdaterProps {
|
|||||||
onConnectStart?: OnConnectStart;
|
onConnectStart?: OnConnectStart;
|
||||||
onConnectStop?: OnConnectStop;
|
onConnectStop?: OnConnectStop;
|
||||||
onConnectEnd?: OnConnectEnd;
|
onConnectEnd?: OnConnectEnd;
|
||||||
|
onClickConnectStart?: OnConnectStart;
|
||||||
|
onClickConnectStop?: OnConnectStop;
|
||||||
|
onClickConnectEnd?: OnConnectEnd;
|
||||||
nodesDraggable?: boolean;
|
nodesDraggable?: boolean;
|
||||||
nodesConnectable?: boolean;
|
nodesConnectable?: boolean;
|
||||||
minZoom?: number;
|
minZoom?: number;
|
||||||
@@ -88,6 +91,9 @@ const StoreUpdater = ({
|
|||||||
onConnectStart,
|
onConnectStart,
|
||||||
onConnectStop,
|
onConnectStop,
|
||||||
onConnectEnd,
|
onConnectEnd,
|
||||||
|
onClickConnectStart,
|
||||||
|
onClickConnectStop,
|
||||||
|
onClickConnectEnd,
|
||||||
nodesDraggable,
|
nodesDraggable,
|
||||||
nodesConnectable,
|
nodesConnectable,
|
||||||
minZoom,
|
minZoom,
|
||||||
@@ -133,6 +139,9 @@ const StoreUpdater = ({
|
|||||||
useDirectStoreUpdater('onConnectStart', onConnectStart, store.setState);
|
useDirectStoreUpdater('onConnectStart', onConnectStart, store.setState);
|
||||||
useDirectStoreUpdater('onConnectStop', onConnectStop, store.setState);
|
useDirectStoreUpdater('onConnectStop', onConnectStop, store.setState);
|
||||||
useDirectStoreUpdater('onConnectEnd', onConnectEnd, store.setState);
|
useDirectStoreUpdater('onConnectEnd', onConnectEnd, store.setState);
|
||||||
|
useDirectStoreUpdater('onClickConnectStart', onClickConnectStart, store.setState);
|
||||||
|
useDirectStoreUpdater('onClickConnectStop', onClickConnectStop, store.setState);
|
||||||
|
useDirectStoreUpdater('onClickConnectEnd', onClickConnectEnd, store.setState);
|
||||||
useDirectStoreUpdater('nodesDraggable', nodesDraggable, store.setState);
|
useDirectStoreUpdater('nodesDraggable', nodesDraggable, store.setState);
|
||||||
useDirectStoreUpdater('nodesConnectable', nodesConnectable, store.setState);
|
useDirectStoreUpdater('nodesConnectable', nodesConnectable, store.setState);
|
||||||
useDirectStoreUpdater('elementsSelectable', elementsSelectable, store.setState);
|
useDirectStoreUpdater('elementsSelectable', elementsSelectable, store.setState);
|
||||||
|
|||||||
@@ -68,6 +68,9 @@ const ReactFlow = forwardRef<ReactFlowRefType, ReactFlowProps>(
|
|||||||
onConnectStart,
|
onConnectStart,
|
||||||
onConnectStop,
|
onConnectStop,
|
||||||
onConnectEnd,
|
onConnectEnd,
|
||||||
|
onClickConnectStart,
|
||||||
|
onClickConnectStop,
|
||||||
|
onClickConnectEnd,
|
||||||
onNodeMouseEnter,
|
onNodeMouseEnter,
|
||||||
onNodeMouseMove,
|
onNodeMouseMove,
|
||||||
onNodeMouseLeave,
|
onNodeMouseLeave,
|
||||||
@@ -216,6 +219,9 @@ const ReactFlow = forwardRef<ReactFlowRefType, ReactFlowProps>(
|
|||||||
onConnectStart={onConnectStart}
|
onConnectStart={onConnectStart}
|
||||||
onConnectStop={onConnectStop}
|
onConnectStop={onConnectStop}
|
||||||
onConnectEnd={onConnectEnd}
|
onConnectEnd={onConnectEnd}
|
||||||
|
onClickConnectStart={onClickConnectStart}
|
||||||
|
onClickConnectStop={onClickConnectStop}
|
||||||
|
onClickConnectEnd={onClickConnectEnd}
|
||||||
nodesDraggable={nodesDraggable}
|
nodesDraggable={nodesDraggable}
|
||||||
nodesConnectable={nodesConnectable}
|
nodesConnectable={nodesConnectable}
|
||||||
elementsSelectable={elementsSelectable}
|
elementsSelectable={elementsSelectable}
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ function useDrag({
|
|||||||
.filter((event: MouseEvent) => {
|
.filter((event: MouseEvent) => {
|
||||||
const target = event.target as HTMLDivElement;
|
const target = event.target as HTMLDivElement;
|
||||||
const filter =
|
const filter =
|
||||||
!event.ctrlKey && !event.button && (!noDragClassName || !target.className?.includes?.(noDragClassName));
|
!event.ctrlKey && !event.button && (!noDragClassName || !target.classList?.contains?.(noDragClassName));
|
||||||
return handleSelector
|
return handleSelector
|
||||||
? selectorExistsTargetToNode(target as HTMLDivElement, handleSelector, nodeRef) && filter
|
? selectorExistsTargetToNode(target as HTMLDivElement, handleSelector, nodeRef) && filter
|
||||||
: filter;
|
: filter;
|
||||||
|
|||||||
@@ -65,6 +65,9 @@ export interface ReactFlowProps extends HTMLAttributes<HTMLDivElement> {
|
|||||||
onConnectStart?: OnConnectStart;
|
onConnectStart?: OnConnectStart;
|
||||||
onConnectStop?: OnConnectStop;
|
onConnectStop?: OnConnectStop;
|
||||||
onConnectEnd?: OnConnectEnd;
|
onConnectEnd?: OnConnectEnd;
|
||||||
|
onClickConnectStart?: OnConnectStart;
|
||||||
|
onClickConnectStop?: OnConnectStop;
|
||||||
|
onClickConnectEnd?: OnConnectEnd;
|
||||||
onInit?: OnInit;
|
onInit?: OnInit;
|
||||||
onMove?: OnMove;
|
onMove?: OnMove;
|
||||||
onMoveStart?: OnMoveStart;
|
onMoveStart?: OnMoveStart;
|
||||||
|
|||||||
@@ -165,6 +165,10 @@ export type ReactFlowStore = {
|
|||||||
onConnectStop?: OnConnectStop;
|
onConnectStop?: OnConnectStop;
|
||||||
onConnectEnd?: OnConnectEnd;
|
onConnectEnd?: OnConnectEnd;
|
||||||
|
|
||||||
|
onClickConnectStart?: OnConnectStart;
|
||||||
|
onClickConnectStop?: OnConnectStop;
|
||||||
|
onClickConnectEnd?: OnConnectEnd;
|
||||||
|
|
||||||
connectOnClick: boolean;
|
connectOnClick: boolean;
|
||||||
defaultEdgeOptions?: DefaultEdgeOptions;
|
defaultEdgeOptions?: DefaultEdgeOptions;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user