feat(edges): add mouse handler closes #987

This commit is contained in:
moklick
2021-03-12 20:46:14 +01:00
parent bf6bce0c58
commit cd1baadf41
6 changed files with 66 additions and 5 deletions
+7 -1
View File
@@ -29,7 +29,10 @@ interface EdgeRendererProps {
markerEndId?: string;
onlyRenderVisibleElements: boolean;
onEdgeUpdate?: OnEdgeUpdateFunc;
onEdgeContextMenu?: (event: React.MouseEvent, element: Edge) => void;
onEdgeContextMenu?: (event: React.MouseEvent, edge: Edge) => void;
onEdgeMouseEnter?: (event: React.MouseEvent, edge: Edge) => void;
onEdgeMouseMove?: (event: React.MouseEvent, edge: Edge) => void;
onEdgeMouseLeave?: (event: React.MouseEvent, edge: Edge) => void;
edgeUpdaterRadius?: number;
}
@@ -166,6 +169,9 @@ const Edge = ({
onConnectEdge={onConnectEdge}
handleEdgeUpdate={typeof props.onEdgeUpdate !== 'undefined'}
onContextMenu={props.onEdgeContextMenu}
onMouseEnter={props.onEdgeMouseEnter}
onMouseMove={props.onEdgeMouseMove}
onMouseLeave={props.onEdgeMouseLeave}
edgeUpdaterRadius={props.edgeUpdaterRadius}
/>
);
+6
View File
@@ -86,6 +86,9 @@ const GraphView = ({
onPaneContextMenu,
onEdgeUpdate,
onEdgeContextMenu,
onEdgeMouseEnter,
onEdgeMouseMove,
onEdgeMouseLeave,
edgeUpdaterRadius,
}: GraphViewProps) => {
const isInitialized = useRef<boolean>(false);
@@ -265,6 +268,9 @@ const GraphView = ({
onEdgeUpdate={onEdgeUpdate}
onlyRenderVisibleElements={onlyRenderVisibleElements}
onEdgeContextMenu={onEdgeContextMenu}
onEdgeMouseEnter={onEdgeMouseEnter}
onEdgeMouseMove={onEdgeMouseMove}
onEdgeMouseLeave={onEdgeMouseLeave}
edgeUpdaterRadius={edgeUpdaterRadius}
/>
</FlowRenderer>
+11 -2
View File
@@ -109,8 +109,11 @@ export interface ReactFlowProps extends Omit<HTMLAttributes<HTMLDivElement>, 'on
panOnScrollMode?: PanOnScrollMode;
zoomOnDoubleClick?: boolean;
onEdgeUpdate?: OnEdgeUpdateFunc;
onEdgeContextMenu?: (event: MouseEvent, nodes: Edge) => void;
edgeUpdaterRadius?: number
onEdgeContextMenu?: (event: MouseEvent, edge: Edge) => void;
onEdgeMouseEnter?: (event: MouseEvent, edge: Edge) => void;
onEdgeMouseMove?: (event: MouseEvent, edge: Edge) => void;
onEdgeMouseLeave?: (event: MouseEvent, edge: Edge) => void;
edgeUpdaterRadius?: number;
}
const ReactFlow = ({
@@ -176,6 +179,9 @@ const ReactFlow = ({
children,
onEdgeUpdate,
onEdgeContextMenu,
onEdgeMouseEnter,
onEdgeMouseMove,
onEdgeMouseLeave,
edgeUpdaterRadius = 10,
...rest
}: ReactFlowProps) => {
@@ -245,6 +251,9 @@ const ReactFlow = ({
onSelectionContextMenu={onSelectionContextMenu}
onEdgeUpdate={onEdgeUpdate}
onEdgeContextMenu={onEdgeContextMenu}
onEdgeMouseEnter={onEdgeMouseEnter}
onEdgeMouseMove={onEdgeMouseMove}
onEdgeMouseLeave={onEdgeMouseLeave}
edgeUpdaterRadius={edgeUpdaterRadius}
/>
<ElementUpdater elements={elements} />