simplify conditions
This commit is contained in:
@@ -123,15 +123,12 @@ export function Pane({
|
|||||||
const onPointerDownCapture = (event: ReactPointerEvent): void => {
|
const onPointerDownCapture = (event: ReactPointerEvent): void => {
|
||||||
const { resetSelectedElements, domNode } = store.getState();
|
const { resetSelectedElements, domNode } = store.getState();
|
||||||
containerBounds.current = domNode?.getBoundingClientRect();
|
containerBounds.current = domNode?.getBoundingClientRect();
|
||||||
|
if (!containerBounds.current) return;
|
||||||
if (!containerBounds.current) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const eventTargetIsContainer = event.target === container.current;
|
const eventTargetIsContainer = event.target === container.current;
|
||||||
// if a child element has the 'nokey' class, we don't want to swallow the event and don't start a selection
|
// if a child element has the 'nokey' class, we don't want to swallow the event and don't start a selection
|
||||||
const isNoKeyEvent = !eventTargetIsContainer && !!(event.target as HTMLElement).closest('.nokey');
|
const isNoKeyEvent = !eventTargetIsContainer && !!(event.target as HTMLElement).closest('.nokey');
|
||||||
const isSelectionActive = (selectionOnDrag && eventTargetIsContainer) || !selectionOnDrag || selectionKeyPressed;
|
const isSelectionActive = (selectionOnDrag && eventTargetIsContainer) || selectionKeyPressed;
|
||||||
|
|
||||||
if (isNoKeyEvent || !isSelecting || !isSelectionActive || event.button !== 0 || !event.isPrimary) {
|
if (isNoKeyEvent || !isSelecting || !isSelectionActive || event.button !== 0 || !event.isPrimary) {
|
||||||
return;
|
return;
|
||||||
@@ -159,7 +156,7 @@ export function Pane({
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!eventTargetIsContainer || paneClickDistance === 0 || !selectionOnDrag) {
|
if (paneClickDistance === 0 || selectionKeyPressed) {
|
||||||
resetSelectedElements();
|
resetSelectedElements();
|
||||||
|
|
||||||
onSelectionStart?.(event);
|
onSelectionStart?.(event);
|
||||||
|
|||||||
@@ -81,6 +81,7 @@
|
|||||||
// We start the selection process when the user clicks down on the pane
|
// We start the selection process when the user clicks down on the pane
|
||||||
function onPointerDownCapture(event: PointerEvent) {
|
function onPointerDownCapture(event: PointerEvent) {
|
||||||
containerBounds = container?.getBoundingClientRect();
|
containerBounds = container?.getBoundingClientRect();
|
||||||
|
if (!containerBounds) return;
|
||||||
|
|
||||||
const eventTargetIsContainer = event.target === container;
|
const eventTargetIsContainer = event.target === container;
|
||||||
|
|
||||||
@@ -88,15 +89,13 @@
|
|||||||
!eventTargetIsContainer && !!(event.target as HTMLElement).closest('.nokey');
|
!eventTargetIsContainer && !!(event.target as HTMLElement).closest('.nokey');
|
||||||
|
|
||||||
const isSelectionActive =
|
const isSelectionActive =
|
||||||
(selectionOnDrag && eventTargetIsContainer) || !selectionOnDrag || store.selectionKeyPressed;
|
(selectionOnDrag && eventTargetIsContainer) || store.selectionKeyPressed;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!store.elementsSelectable ||
|
|
||||||
!isSelecting ||
|
|
||||||
event.button !== 0 ||
|
|
||||||
!containerBounds ||
|
|
||||||
isNoKeyEvent ||
|
isNoKeyEvent ||
|
||||||
|
!isSelecting ||
|
||||||
!isSelectionActive ||
|
!isSelectionActive ||
|
||||||
|
event.button !== 0 ||
|
||||||
!event.isPrimary
|
!event.isPrimary
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
@@ -122,7 +121,7 @@
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (paneClickDistance === 0 || !selectionOnDrag) {
|
if (paneClickDistance === 0 || store.selectionKeyPressed) {
|
||||||
store.unselectNodesAndEdges();
|
store.unselectNodesAndEdges();
|
||||||
|
|
||||||
onselectionstart?.(event);
|
onselectionstart?.(event);
|
||||||
@@ -219,8 +218,8 @@
|
|||||||
|
|
||||||
store.selectionRect = null;
|
store.selectionRect = null;
|
||||||
|
|
||||||
if (selectionInProgress && selectedNodeIds.size > 0) {
|
if (selectionInProgress) {
|
||||||
store.selectionRectMode = 'nodes';
|
store.selectionRectMode = selectedNodeIds.size > 0 ? 'nodes' : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectionInProgress) {
|
if (selectionInProgress) {
|
||||||
|
|||||||
Reference in New Issue
Block a user