diff --git a/src/components/Nodes/wrapNode.tsx b/src/components/Nodes/wrapNode.tsx index 15c0e7c1..20348106 100644 --- a/src/components/Nodes/wrapNode.tsx +++ b/src/components/Nodes/wrapNode.tsx @@ -50,6 +50,8 @@ export default (NodeComponent: ComponentType) => { dragHandle, zIndex, isParent, + noPanClassName, + noDragClassName, }: WrapNodeProps) => { const { addSelectedElements, @@ -217,6 +219,7 @@ export default (NodeComponent: ComponentType) => { const nodeClasses = cc([ 'react-flow__node', `react-flow__node-${type}`, + noPanClassName, className, { selected, @@ -232,7 +235,7 @@ export default (NodeComponent: ComponentType) => { onStop={onDragStop} scale={scale} disabled={!isDraggable} - cancel=".nodrag" + cancel={`.${noDragClassName}`} nodeRef={nodeElement} grid={grid} enableUserSelectHack={false} diff --git a/src/container/FlowRenderer/index.tsx b/src/container/FlowRenderer/index.tsx index 8b8d3088..458e9c59 100644 --- a/src/container/FlowRenderer/index.tsx +++ b/src/container/FlowRenderer/index.tsx @@ -59,8 +59,7 @@ const FlowRenderer = ({ onSelectionDrag, onSelectionDragStop, onSelectionContextMenu, - noDragClassName, - noZoomClassName, + noWheelClassName, noPanClassName, }: FlowRendererProps) => { const { unsetNodesSelection, resetSelectedElements, nodesSelectionActive } = useStore(selector, shallow); @@ -110,8 +109,7 @@ const FlowRenderer = ({ defaultZoom={defaultZoom} zoomActivationKeyCode={zoomActivationKeyCode} preventScrolling={preventScrolling} - noDragClassName={noDragClassName} - noZoomClassName={noZoomClassName} + noWheelClassName={noWheelClassName} noPanClassName={noPanClassName} > {children} diff --git a/src/container/GraphView/index.tsx b/src/container/GraphView/index.tsx index e08dd5ee..5561833d 100644 --- a/src/container/GraphView/index.tsx +++ b/src/container/GraphView/index.tsx @@ -20,6 +20,9 @@ export interface GraphViewProps extends Omit { useOnLoadHandler(onLoad); @@ -110,7 +113,7 @@ const GraphView = ({ onSelectionContextMenu={onSelectionContextMenu} preventScrolling={preventScrolling} noDragClassName={noDragClassName} - noZoomClassName={noZoomClassName} + noWheelClassName={noWheelClassName} noPanClassName={noPanClassName} > @@ -147,6 +150,7 @@ const GraphView = ({ selectNodesOnDrag={selectNodesOnDrag} onlyRenderVisibleElements={onlyRenderVisibleElements} noPanClassName={noPanClassName} + noDragClassName={noDragClassName} /> diff --git a/src/container/NodeRenderer/index.tsx b/src/container/NodeRenderer/index.tsx index c43bb847..a60fdb88 100644 --- a/src/container/NodeRenderer/index.tsx +++ b/src/container/NodeRenderer/index.tsx @@ -1,6 +1,5 @@ import React, { memo, useMemo, ComponentType, MouseEvent } from 'react'; import shallow from 'zustand/shallow'; -import cc from 'classcat'; import { useStore } from '../../store'; import { Node, NodeTypesType, ReactFlowState, WrapNodeProps } from '../../types'; @@ -18,7 +17,8 @@ interface NodeRendererProps { onNodeDrag?: (event: MouseEvent, node: Node) => void; onNodeDragStop?: (event: MouseEvent, node: Node) => void; onlyRenderVisibleElements: boolean; - noPanClassName?: string; + noPanClassName: string; + noDragClassName: string; } const selector = (s: ReactFlowState) => ({ @@ -83,7 +83,7 @@ const NodeRenderer = (props: NodeRendererProps) => { { dragHandle={node.dragHandle} zIndex={internals?.z || 0} isParent={!!internals?.isParent} + noDragClassName={props.noDragClassName} + noPanClassName={props.noPanClassName} /> ); })} diff --git a/src/container/ReactFlow/index.tsx b/src/container/ReactFlow/index.tsx index 66a007f1..87c3bbfb 100644 --- a/src/container/ReactFlow/index.tsx +++ b/src/container/ReactFlow/index.tsx @@ -5,6 +5,7 @@ import React, { MouseEvent as ReactMouseEvent, WheelEvent, forwardRef, + FunctionComponent, } from 'react'; import cc from 'classcat'; @@ -130,7 +131,7 @@ export interface ReactFlowProps extends Omit, 'on onEdgeUpdateEnd?: (event: MouseEvent, edge: Edge) => void; edgeUpdaterRadius?: number; noDragClassName?: string; - noZoomClassName?: string; + noWheelClassName?: string; noPanClassName?: string; } @@ -139,7 +140,7 @@ export type ReactFlowRefType = HTMLDivElement; const initSnapGrid: [number, number] = [15, 15]; const initDefaultPosition: [number, number] = [0, 0]; -const ReactFlow = forwardRef( +const ReactFlow: FunctionComponent = forwardRef( ( { nodes = [], @@ -216,7 +217,7 @@ const ReactFlow = forwardRef( onNodesChange, onEdgesChange, noDragClassName = 'nodrag', - noZoomClassName = 'nowheel', + noWheelClassName = 'nowheel', noPanClassName = 'nopan', ...rest }, @@ -283,7 +284,7 @@ const ReactFlow = forwardRef( edgeUpdaterRadius={edgeUpdaterRadius} defaultMarkerColor={defaultMarkerColor} noDragClassName={noDragClassName} - noZoomClassName={noZoomClassName} + noWheelClassName={noWheelClassName} noPanClassName={noPanClassName} /> @@ -44,7 +43,6 @@ const eventToFlowTransform = (eventTransform: any): FlowTransform => ({ }); const isWrappedWithClass = (event: any, className: string | undefined) => event.target.closest(`.${className}`); -// const hasNoWheelClass = (event: any) => event.target.closest('.nowheel'); const selector = (s: ReactFlowState) => ({ d3Zoom: s.d3Zoom, @@ -73,7 +71,7 @@ const ZoomPane = ({ zoomActivationKeyCode, preventScrolling = true, children, - noZoomClassName, + noWheelClassName, noPanClassName, }: ZoomPaneProps) => { const store = useStoreApi(); @@ -112,7 +110,7 @@ const ZoomPane = ({ if (panOnScroll && !zoomActivationKeyPressed) { d3Selection .on('wheel', (event: any) => { - if (isWrappedWithClass(event, noZoomClassName)) { + if (isWrappedWithClass(event, noWheelClassName)) { return false; } event.preventDefault(); @@ -146,7 +144,7 @@ const ZoomPane = ({ } else if (typeof d3ZoomHandler !== 'undefined') { d3Selection .on('wheel', (event: any) => { - if (!preventScrolling || isWrappedWithClass(event, noZoomClassName)) { + if (!preventScrolling || isWrappedWithClass(event, noWheelClassName)) { return null; } @@ -164,7 +162,7 @@ const ZoomPane = ({ zoomActivationKeyPressed, zoomOnPinch, preventScrolling, - noZoomClassName, + noWheelClassName, ]); useEffect(() => { @@ -238,7 +236,7 @@ const ZoomPane = ({ } // if the target element is inside the nowheel class, we prevent zooming - if (isWrappedWithClass(event, noZoomClassName) && event.type === 'wheel') { + if (isWrappedWithClass(event, noWheelClassName) && event.type === 'wheel') { return false; } diff --git a/src/types/nodes.ts b/src/types/nodes.ts index fe11ef48..ba79bf09 100644 --- a/src/types/nodes.ts +++ b/src/types/nodes.ts @@ -82,6 +82,8 @@ export interface WrapNodeProps { dragHandle?: string; zIndex: number; isParent: boolean; + noPanClassName: string; + noDragClassName: string; } export type NodeHandleBounds = {