refactor(props): remove onConnectStop #2299

This commit is contained in:
moklick
2022-07-25 16:08:52 +02:00
parent 37b311851c
commit efedf04a56
7 changed files with 6 additions and 29 deletions
+4 -4
View File
@@ -38,12 +38,12 @@ const TouchDeviceFlow = () => {
[setEdges] [setEdges]
); );
const onConnectStart = useCallback(() => console.log('connect start'), []); const onConnectStart = useCallback(() => console.log('connect start'), []);
const onConnectStop = useCallback(() => console.log('connect end'), []); const onConnectEnd = useCallback(() => console.log('connect end'), []);
const onClickConnectStart = useCallback( const onClickConnectStart = useCallback(
() => console.log('click connect start'), () => console.log('click connect start'),
[] []
); );
const onClickConnectStop = useCallback( const onClickConnectEnd = useCallback(
() => console.log('click connect end'), () => console.log('click connect end'),
[] []
); );
@@ -56,9 +56,9 @@ const TouchDeviceFlow = () => {
onNodesChange={onNodesChange} onNodesChange={onNodesChange}
onEdgesChange={onEdgesChange} onEdgesChange={onEdgesChange}
onConnectStart={onConnectStart} onConnectStart={onConnectStart}
onConnectStop={onConnectStop} onConnectEnd={onConnectEnd}
onClickConnectStart={onClickConnectStart} onClickConnectStart={onClickConnectStart}
onClickConnectStop={onClickConnectStop} onClickConnectEnd={onClickConnectEnd}
className={styles.flow} className={styles.flow}
/> />
); );
@@ -160,7 +160,6 @@ export function handleMouseDown({
} }
function onMouseUp(event: MouseEvent) { function onMouseUp(event: MouseEvent) {
const { onConnectStop, onConnectEnd } = getState();
const { connection, isValid } = checkElementBelowIsValid( const { connection, isValid } = checkElementBelowIsValid(
event, event,
connectionMode, connectionMode,
@@ -171,13 +170,11 @@ export function handleMouseDown({
doc doc
); );
onConnectStop?.(event);
if (isValid) { if (isValid) {
onConnect?.(connection); onConnect?.(connection);
} }
onConnectEnd?.(event); getState().onConnectEnd?.(event);
if (elementEdgeUpdaterType && onEdgeUpdateEnd) { if (elementEdgeUpdaterType && onEdgeUpdateEnd) {
onEdgeUpdateEnd(event); onEdgeUpdateEnd(event);
@@ -74,7 +74,7 @@ const Handle = forwardRef<HTMLDivElement, HandleComponentProps>(
}; };
const onClick = (event: React.MouseEvent) => { const onClick = (event: React.MouseEvent) => {
const { onClickConnectStart, onClickConnectStop, onClickConnectEnd, connectionMode } = store.getState(); const { onClickConnectStart, onClickConnectEnd, connectionMode } = store.getState();
if (!connectionStartHandle) { if (!connectionStartHandle) {
onClickConnectStart?.(event, { nodeId, handleId, handleType: type }); onClickConnectStart?.(event, { nodeId, handleId, handleType: type });
store.setState({ connectionStartHandle: { nodeId, type, handleId } }); store.setState({ connectionStartHandle: { nodeId, type, handleId } });
@@ -92,8 +92,6 @@ const Handle = forwardRef<HTMLDivElement, HandleComponentProps>(
doc doc
); );
onClickConnectStop?.(event as unknown as MouseEvent);
if (isValid) { if (isValid) {
onConnectExtended(connection); onConnectExtended(connection);
} }
@@ -13,10 +13,8 @@ type StoreUpdaterProps = Pick<
| 'defaultEdges' | 'defaultEdges'
| 'onConnect' | 'onConnect'
| 'onConnectStart' | 'onConnectStart'
| 'onConnectStop'
| 'onConnectEnd' | 'onConnectEnd'
| 'onClickConnectStart' | 'onClickConnectStart'
| 'onClickConnectStop'
| 'onClickConnectEnd' | 'onClickConnectEnd'
| 'nodesDraggable' | 'nodesDraggable'
| 'nodesConnectable' | 'nodesConnectable'
@@ -79,10 +77,8 @@ const StoreUpdater = ({
defaultEdges, defaultEdges,
onConnect, onConnect,
onConnectStart, onConnectStart,
onConnectStop,
onConnectEnd, onConnectEnd,
onClickConnectStart, onClickConnectStart,
onClickConnectStop,
onClickConnectEnd, onClickConnectEnd,
nodesDraggable, nodesDraggable,
nodesConnectable, nodesConnectable,
@@ -133,10 +129,8 @@ const StoreUpdater = ({
useDirectStoreUpdater('connectionMode', connectionMode, store.setState); useDirectStoreUpdater('connectionMode', connectionMode, store.setState);
useDirectStoreUpdater('onConnect', onConnect, store.setState); useDirectStoreUpdater('onConnect', onConnect, store.setState);
useDirectStoreUpdater('onConnectStart', onConnectStart, store.setState); useDirectStoreUpdater('onConnectStart', onConnectStart, store.setState);
useDirectStoreUpdater('onConnectStop', onConnectStop, store.setState);
useDirectStoreUpdater('onConnectEnd', onConnectEnd, store.setState); useDirectStoreUpdater('onConnectEnd', onConnectEnd, store.setState);
useDirectStoreUpdater('onClickConnectStart', onClickConnectStart, store.setState); useDirectStoreUpdater('onClickConnectStart', onClickConnectStart, store.setState);
useDirectStoreUpdater('onClickConnectStop', onClickConnectStop, store.setState);
useDirectStoreUpdater('onClickConnectEnd', onClickConnectEnd, 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);
@@ -65,10 +65,8 @@ const ReactFlow = forwardRef<ReactFlowRefType, ReactFlowProps>(
onMoveEnd, onMoveEnd,
onConnect, onConnect,
onConnectStart, onConnectStart,
onConnectStop,
onConnectEnd, onConnectEnd,
onClickConnectStart, onClickConnectStart,
onClickConnectStop,
onClickConnectEnd, onClickConnectEnd,
onNodeMouseEnter, onNodeMouseEnter,
onNodeMouseMove, onNodeMouseMove,
@@ -216,10 +214,8 @@ const ReactFlow = forwardRef<ReactFlowRefType, ReactFlowProps>(
defaultEdges={defaultEdges} defaultEdges={defaultEdges}
onConnect={onConnect} onConnect={onConnect}
onConnectStart={onConnectStart} onConnectStart={onConnectStart}
onConnectStop={onConnectStop}
onConnectEnd={onConnectEnd} onConnectEnd={onConnectEnd}
onClickConnectStart={onClickConnectStart} onClickConnectStart={onClickConnectStart}
onClickConnectStop={onClickConnectStop}
onClickConnectEnd={onClickConnectEnd} onClickConnectEnd={onClickConnectEnd}
nodesDraggable={nodesDraggable} nodesDraggable={nodesDraggable}
nodesConnectable={nodesConnectable} nodesConnectable={nodesConnectable}
@@ -10,7 +10,6 @@ import {
ConnectionLineType, ConnectionLineType,
ConnectionLineComponent, ConnectionLineComponent,
OnConnectStart, OnConnectStart,
OnConnectStop,
OnConnectEnd, OnConnectEnd,
OnConnect, OnConnect,
CoordinateExtent, CoordinateExtent,
@@ -58,10 +57,8 @@ export interface ReactFlowProps extends HTMLAttributes<HTMLDivElement> {
onEdgesDelete?: OnEdgesDelete; onEdgesDelete?: OnEdgesDelete;
onConnect?: OnConnect; onConnect?: OnConnect;
onConnectStart?: OnConnectStart; onConnectStart?: OnConnectStart;
onConnectStop?: OnConnectStop;
onConnectEnd?: OnConnectEnd; onConnectEnd?: OnConnectEnd;
onClickConnectStart?: OnConnectStart; onClickConnectStart?: OnConnectStart;
onClickConnectStop?: OnConnectStop;
onClickConnectEnd?: OnConnectEnd; onClickConnectEnd?: OnConnectEnd;
onInit?: OnInit; onInit?: OnInit;
onMove?: OnMove; onMove?: OnMove;
-5
View File
@@ -76,9 +76,6 @@ export type OnConnectStartParams = {
}; };
export type OnConnectStart = (event: ReactMouseEvent, params: OnConnectStartParams) => void; export type OnConnectStart = (event: ReactMouseEvent, params: OnConnectStartParams) => void;
export type OnConnectStop = (event: MouseEvent) => void;
export type OnConnectEnd = (event: MouseEvent) => void; export type OnConnectEnd = (event: MouseEvent) => void;
export type Viewport = { export type Viewport = {
@@ -180,11 +177,9 @@ export type ReactFlowStore = {
onConnect?: OnConnect; onConnect?: OnConnect;
onConnectStart?: OnConnectStart; onConnectStart?: OnConnectStart;
onConnectStop?: OnConnectStop;
onConnectEnd?: OnConnectEnd; onConnectEnd?: OnConnectEnd;
onClickConnectStart?: OnConnectStart; onClickConnectStart?: OnConnectStart;
onClickConnectStop?: OnConnectStop;
onClickConnectEnd?: OnConnectEnd; onClickConnectEnd?: OnConnectEnd;
connectOnClick: boolean; connectOnClick: boolean;