feat: make sure 'panOnDrag' overrides 'selectBoxOnDrag'.
This commit is contained in:
@@ -16,7 +16,7 @@ type SelectionRect = Rect & {
|
|||||||
};
|
};
|
||||||
|
|
||||||
type UserSelectionProps = {
|
type UserSelectionProps = {
|
||||||
selectionKeyPressed: boolean;
|
isSelectionMode: boolean;
|
||||||
onClick?: (e: React.MouseEvent) => void;
|
onClick?: (e: React.MouseEvent) => void;
|
||||||
onContextMenu?: (e: React.MouseEvent) => void;
|
onContextMenu?: (e: React.MouseEvent) => void;
|
||||||
onWheel?: (e: React.WheelEvent) => void;
|
onWheel?: (e: React.WheelEvent) => void;
|
||||||
@@ -35,7 +35,7 @@ const selector = (s: ReactFlowState) => ({
|
|||||||
elementsSelectable: s.elementsSelectable,
|
elementsSelectable: s.elementsSelectable,
|
||||||
});
|
});
|
||||||
|
|
||||||
const UserSelection = memo(({ selectionKeyPressed, onClick, onContextMenu, onWheel, children }: UserSelectionProps) => {
|
const UserSelection = memo(({ isSelectionMode, onClick, onContextMenu, onWheel, children }: UserSelectionProps) => {
|
||||||
const store = useStoreApi();
|
const store = useStoreApi();
|
||||||
const prevSelectedNodesCount = useRef<number>(0);
|
const prevSelectedNodesCount = useRef<number>(0);
|
||||||
const prevSelectedEdgesCount = useRef<number>(0);
|
const prevSelectedEdgesCount = useRef<number>(0);
|
||||||
@@ -53,7 +53,7 @@ const UserSelection = memo(({ selectionKeyPressed, onClick, onContextMenu, onWhe
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onMouseDown = (event: React.MouseEvent): void => {
|
const onMouseDown = (event: React.MouseEvent): void => {
|
||||||
if (!elementsSelectable || !selectionKeyPressed || event.button !== 0) {
|
if (!elementsSelectable || !isSelectionMode || event.button !== 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ const UserSelection = memo(({ selectionKeyPressed, onClick, onContextMenu, onWhe
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onMouseMove = (event: React.MouseEvent): void => {
|
const onMouseMove = (event: React.MouseEvent): void => {
|
||||||
if (!selectionKeyPressed || !containerBounds.current || !userSelectionRect) {
|
if (!isSelectionMode || !containerBounds.current || !userSelectionRect) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,7 +129,7 @@ const UserSelection = memo(({ selectionKeyPressed, onClick, onContextMenu, onWhe
|
|||||||
};
|
};
|
||||||
|
|
||||||
const eventHandlers =
|
const eventHandlers =
|
||||||
elementsSelectable && (selectionKeyPressed || userSelectionActive)
|
elementsSelectable && (isSelectionMode || userSelectionActive)
|
||||||
? {
|
? {
|
||||||
onClick,
|
onClick,
|
||||||
onContextMenu,
|
onContextMenu,
|
||||||
|
|||||||
@@ -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;
|
const isSelectionMode = selectionKeyPressed || (selectBoxOnDrag && !panOnDrag);
|
||||||
|
|
||||||
useGlobalKeyHandler({ deleteKeyCode, multiSelectionKeyCode });
|
useGlobalKeyHandler({ deleteKeyCode, multiSelectionKeyCode });
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ const FlowRenderer = ({
|
|||||||
panOnScrollSpeed={panOnScrollSpeed}
|
panOnScrollSpeed={panOnScrollSpeed}
|
||||||
panOnScrollMode={panOnScrollMode}
|
panOnScrollMode={panOnScrollMode}
|
||||||
zoomOnDoubleClick={zoomOnDoubleClick}
|
zoomOnDoubleClick={zoomOnDoubleClick}
|
||||||
panOnDrag={panOnDrag && !isSelectionMode}
|
panOnDrag={panOnDrag}
|
||||||
defaultViewport={defaultViewport}
|
defaultViewport={defaultViewport}
|
||||||
translateExtent={translateExtent}
|
translateExtent={translateExtent}
|
||||||
minZoom={minZoom}
|
minZoom={minZoom}
|
||||||
@@ -111,7 +111,7 @@ const FlowRenderer = ({
|
|||||||
onMouseLeave={onPaneMouseLeave}
|
onMouseLeave={onPaneMouseLeave}
|
||||||
onContextMenu={onContextMenu}
|
onContextMenu={onContextMenu}
|
||||||
onWheel={onWheel}
|
onWheel={onWheel}
|
||||||
selectionKeyPressed={isSelectionMode}
|
isSelectionMode={isSelectionMode}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
{nodesSelectionActive && (
|
{nodesSelectionActive && (
|
||||||
|
|||||||
Reference in New Issue
Block a user