feat: add option for right click movement.
This commit is contained in:
@@ -69,7 +69,7 @@ const FlowRenderer = ({
|
|||||||
const nodesSelectionActive = useStore(selector);
|
const nodesSelectionActive = useStore(selector);
|
||||||
const selectionKeyPressed = useKeyPress(selectionKeyCode);
|
const selectionKeyPressed = useKeyPress(selectionKeyCode);
|
||||||
|
|
||||||
const isSelectionMode = selectionKeyPressed || (selectBoxOnDrag && !panOnDrag);
|
const isSelectionMode = selectionKeyPressed || (selectBoxOnDrag && panOnDrag !== true);
|
||||||
|
|
||||||
useGlobalKeyHandler({ deleteKeyCode, multiSelectionKeyCode });
|
useGlobalKeyHandler({ deleteKeyCode, multiSelectionKeyCode });
|
||||||
|
|
||||||
@@ -79,7 +79,13 @@ const FlowRenderer = ({
|
|||||||
store.setState({ nodesSelectionActive: false });
|
store.setState({ nodesSelectionActive: false });
|
||||||
};
|
};
|
||||||
|
|
||||||
const onContextMenu = onPaneContextMenu ? (event: MouseEvent) => onPaneContextMenu(event) : undefined;
|
const onContextMenu = (event: MouseEvent) => {
|
||||||
|
onPaneContextMenu?.(event);
|
||||||
|
|
||||||
|
if (panOnDrag === 'RightClick') {
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
};
|
||||||
const onWheel = onPaneScroll ? (event: WheelEvent) => onPaneScroll(event) : undefined;
|
const onWheel = onPaneScroll ? (event: WheelEvent) => onPaneScroll(event) : undefined;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -277,8 +277,20 @@ const ZoomPane = ({
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if the pane is only movable using right clicks, prevent all other clicks
|
||||||
|
if (
|
||||||
|
panOnDrag === 'RightClick' &&
|
||||||
|
(event.type === 'mousedown' || event.type === 'touchstart') &&
|
||||||
|
event.button !== 2
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We only allow right clicks if pan on drag is set to right click
|
||||||
|
const buttonAllowed = panOnDrag === 'RightClick' ? 1 !== event.button : !event.button || event.button <= 1;
|
||||||
|
|
||||||
// default filter for d3-zoom
|
// default filter for d3-zoom
|
||||||
return (!event.ctrlKey || event.type === 'wheel') && (!event.button || event.button <= 1);
|
return (!event.ctrlKey || event.type === 'wheel') && buttonAllowed;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [
|
}, [
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ export type ReactFlowProps = HTMLAttributes<HTMLDivElement> & {
|
|||||||
initNodeOrigin?: NodeOrigin;
|
initNodeOrigin?: NodeOrigin;
|
||||||
elementsSelectable?: boolean;
|
elementsSelectable?: boolean;
|
||||||
selectNodesOnDrag?: boolean;
|
selectNodesOnDrag?: boolean;
|
||||||
panOnDrag?: boolean;
|
panOnDrag?: boolean | 'RightClick';
|
||||||
minZoom?: number;
|
minZoom?: number;
|
||||||
maxZoom?: number;
|
maxZoom?: number;
|
||||||
defaultViewport?: Viewport;
|
defaultViewport?: Viewport;
|
||||||
|
|||||||
Reference in New Issue
Block a user