import { memo } from 'react'; import type { ReactNode, WheelEvent, MouseEvent } from 'react'; import { useStore, useStoreApi } from '../../hooks/useStore'; import useGlobalKeyHandler from '../../hooks/useGlobalKeyHandler'; import useKeyPress from '../../hooks/useKeyPress'; import { GraphViewProps } from '../GraphView'; import ZoomPane from '../ZoomPane'; import UserSelection from '../../components/UserSelection'; import NodesSelection from '../../components/NodesSelection'; import Pane from './Pane'; import type { ReactFlowState } from '../../types'; export type FlowRendererProps = Omit< GraphViewProps, | 'snapToGrid' | 'nodeTypes' | 'edgeTypes' | 'snapGrid' | 'connectionLineType' | 'connectionLineContainerStyle' | 'arrowHeadColor' | 'onlyRenderVisibleElements' | 'selectNodesOnDrag' | 'defaultMarkerColor' | 'rfId' | 'nodeOrigin' > & { children: ReactNode; }; const selector = (s: ReactFlowState) => s.nodesSelectionActive; const FlowRenderer = ({ children, onPaneClick, onPaneMouseEnter, onPaneMouseMove, onPaneMouseLeave, onPaneContextMenu, onPaneScroll, deleteKeyCode, onMove, onMoveStart, onMoveEnd, selectionKeyCode, multiSelectionKeyCode, zoomActivationKeyCode, elementsSelectable, zoomOnScroll, zoomOnPinch, panOnScroll, panOnScrollSpeed, panOnScrollMode, zoomOnDoubleClick, panOnDrag, defaultViewport, translateExtent, minZoom, maxZoom, preventScrolling, onSelectionContextMenu, noWheelClassName, noPanClassName, disableKeyboardA11y, }: FlowRendererProps) => { const store = useStoreApi(); const nodesSelectionActive = useStore(selector); const selectionKeyPressed = useKeyPress(selectionKeyCode); useGlobalKeyHandler({ deleteKeyCode, multiSelectionKeyCode }); const onClick = (event: MouseEvent) => { onPaneClick?.(event); store.getState().resetSelectedElements(); store.setState({ nodesSelectionActive: false }); }; const onContextMenu = onPaneContextMenu ? (event: MouseEvent) => onPaneContextMenu(event) : undefined; const onWheel = onPaneScroll ? (event: WheelEvent) => onPaneScroll(event) : undefined; return ( {children} {nodesSelectionActive && ( )} ); }; FlowRenderer.displayName = 'FlowRenderer'; export default memo(FlowRenderer);