refactor(drag-pane): handle middle mouse closes #784, #1767

This commit is contained in:
moklick
2022-08-29 18:00:04 +02:00
parent 588d8fc02e
commit ba9df1035b
4 changed files with 30 additions and 10 deletions
+22 -7
View File
@@ -1,5 +1,5 @@
/* this will be exported as base.css and can be used for a basic styling */ /* this will be exported as base.css and can be used for a basic styling */
/* these are the necessary styles for React Flow */ /* these are the necessary styles for React Flow, they get used by base.css and style.css */
.react-flow__container { .react-flow__container {
position: absolute; position: absolute;
width: 100%; width: 100%;
@@ -101,9 +101,6 @@
background-color: white; background-color: white;
cursor: -webkit-grab; cursor: -webkit-grab;
cursor: grab; cursor: grab;
border-width: 1px;
border-style: solid;
border-color: #bbb;
} }
.react-flow__node.dragging { .react-flow__node.dragging {
cursor: -webkit-grabbing; cursor: -webkit-grabbing;
@@ -129,6 +126,7 @@
} }
.react-flow__handle.connectable { .react-flow__handle.connectable {
pointer-events: all; pointer-events: all;
cursor: crosshair;
} }
.react-flow__handle-bottom { .react-flow__handle-bottom {
top: auto; top: auto;
@@ -196,9 +194,26 @@
stroke-dashoffset: 10; stroke-dashoffset: 10;
} }
} }
.react-flow__node.selected, .react-flow__node-default,
.react-flow__node:focus, .react-flow__node-input,
.react-flow__node:focus-visible { .react-flow__node-output,
.react-flow__node-group {
border-width: 1px;
border-style: solid;
border-color: #bbb;
}
.react-flow__node-default.selected,
.react-flow__node-default:focus,
.react-flow__node-default:focus-visible,
.react-flow__node-input.selected,
.react-flow__node-input:focus,
.react-flow__node-input:focus-visible,
.react-flow__node-output.selected,
.react-flow__node-output:focus,
.react-flow__node-output:focus-visible,
.react-flow__node-group.selected,
.react-flow__node-group:focus,
.react-flow__node-group:focus-visible {
outline: none; outline: none;
border: 1px solid #555; border: 1px solid #555;
} }
+2 -1
View File
@@ -1,5 +1,5 @@
/* this gets exported as style.css and can be used for the default theming */ /* this gets exported as style.css and can be used for the default theming */
/* these are the necessary styles for React Flow */ /* these are the necessary styles for React Flow, they get used by base.css and style.css */
.react-flow__container { .react-flow__container {
position: absolute; position: absolute;
width: 100%; width: 100%;
@@ -130,6 +130,7 @@
} }
.react-flow__handle.connectable { .react-flow__handle.connectable {
pointer-events: all; pointer-events: all;
cursor: crosshair;
} }
.react-flow__handle-bottom { .react-flow__handle-bottom {
top: auto; top: auto;
@@ -213,6 +213,10 @@ const ZoomPane = ({
const zoomScroll = zoomActivationKeyPressed || zoomOnScroll; const zoomScroll = zoomActivationKeyPressed || zoomOnScroll;
const pinchZoom = zoomOnPinch && event.ctrlKey; const pinchZoom = zoomOnPinch && event.ctrlKey;
if (event.button === 1 && event.type === 'mousedown' && event.target.closest(`.react-flow__node`)) {
return true;
}
// if all interactions are disabled, we prevent all zoom events // if all interactions are disabled, we prevent all zoom events
if (!panOnDrag && !zoomScroll && !panOnScroll && !zoomOnDoubleClick && !zoomOnPinch) { if (!panOnDrag && !zoomScroll && !panOnScroll && !zoomOnDoubleClick && !zoomOnPinch) {
return false; return false;
@@ -253,7 +257,7 @@ const ZoomPane = ({
} }
// default filter for d3-zoom // default filter for d3-zoom
return (!event.ctrlKey || event.type === 'wheel') && !event.button; return (!event.ctrlKey || event.type === 'wheel') && event.button <= 1;
}); });
} }
}, [ }, [
+1 -1
View File
@@ -153,7 +153,7 @@ function useDrag({
.filter((event: MouseEvent) => { .filter((event: MouseEvent) => {
const target = event.target as HTMLDivElement; const target = event.target as HTMLDivElement;
const isDraggable = const isDraggable =
!event.button && event.button === 0 &&
(!noDragClassName || !hasSelector(target, `.${noDragClassName}`, nodeRef)) && (!noDragClassName || !hasSelector(target, `.${noDragClassName}`, nodeRef)) &&
(!handleSelector || hasSelector(target, handleSelector, nodeRef)); (!handleSelector || hasSelector(target, handleSelector, nodeRef));