feat(connections): support touch

This commit is contained in:
moklick
2023-01-23 17:58:15 +01:00
parent 24e8b8adc0
commit 0a2c96fe3e
10 changed files with 82 additions and 67 deletions
+4 -10
View File
@@ -11,8 +11,9 @@ import { containerStyle } from '../../styles';
import { useStore, useStoreApi } from '../../hooks/useStore';
import { getSelectionChanges } from '../../utils/changes';
import { getConnectedEdges, getNodesInside } from '../../utils/graph';
import { getEventPosition } from '../../utils';
import { SelectionMode } from '../../types';
import type { ReactFlowProps, XYPosition, ReactFlowState, NodeChange, EdgeChange } from '../../types';
import type { ReactFlowProps, ReactFlowState, NodeChange, EdgeChange } from '../../types';
type PaneProps = {
isSelecting: boolean;
@@ -33,13 +34,6 @@ type PaneProps = {
>
>;
function getMousePosition(event: ReactMouseEvent, containerBounds: DOMRect): XYPosition {
return {
x: event.clientX - containerBounds.left,
y: event.clientY - containerBounds.top,
};
}
const wrapHandler = (
handler: React.MouseEventHandler | undefined,
containerRef: React.MutableRefObject<HTMLDivElement | null>
@@ -118,7 +112,7 @@ const Pane = memo(
return;
}
const { x, y } = getMousePosition(event, containerBounds.current);
const { x, y } = getEventPosition(event, containerBounds.current);
resetSelectedElements();
@@ -145,7 +139,7 @@ const Pane = memo(
store.setState({ userSelectionActive: true, nodesSelectionActive: false });
const mousePos = getMousePosition(event, containerBounds.current);
const mousePos = getEventPosition(event, containerBounds.current);
const startX = userSelectionRect.startX ?? 0;
const startY = userSelectionRect.startY ?? 0;