feat(autoPan): add props, handle scale
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import type { MouseEvent as ReactMouseEvent } from 'react';
|
||||
import { StoreApi } from 'zustand';
|
||||
|
||||
import { clamp, getHostForElement, getVelocity } from '../../utils';
|
||||
import { getHostForElement, getVelocity } from '../../utils';
|
||||
import { ConnectionMode } from '../../types';
|
||||
import type { OnConnect, Connection, HandleType, ReactFlowState, XYPosition } from '../../types';
|
||||
|
||||
@@ -100,13 +100,13 @@ export function handleMouseDown({
|
||||
}): void {
|
||||
// when react-flow is used inside a shadow root we can't use document
|
||||
const doc = getHostForElement(event.target as HTMLElement);
|
||||
const { onConnectStart, connectionMode, domNode } = getState();
|
||||
const { onConnectStart, connectionMode, domNode, autoPanOnConnect } = getState();
|
||||
let connectionPosition: XYPosition | null = null;
|
||||
let requestAnimationFrameId = 0;
|
||||
|
||||
// when the user is moving the mouse close to the edge of the canvas while connecting we move the canvas
|
||||
const updateViewport = (): void => {
|
||||
if (!connectionPosition || !containerBounds) {
|
||||
if (!connectionPosition || !containerBounds || !autoPanOnConnect) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -132,6 +132,7 @@ export function handleMouseDown({
|
||||
const handleType = elementEdgeUpdaterType ? elementEdgeUpdaterType : elementBelowIsTarget ? 'target' : 'source';
|
||||
const containerBounds = domNode.getBoundingClientRect();
|
||||
let recentHoveredHandle: Element;
|
||||
|
||||
connectionPosition = {
|
||||
x: event.clientX - containerBounds.left,
|
||||
y: event.clientY - containerBounds.top,
|
||||
|
||||
@@ -45,6 +45,8 @@ type StoreUpdaterProps = Pick<
|
||||
| 'noPanClassName'
|
||||
| 'nodeOrigin'
|
||||
| 'elevateNodesOnSelect'
|
||||
| 'autoPanOnConnect'
|
||||
| 'autoPanOnNodeDrag'
|
||||
> & { rfId: string };
|
||||
|
||||
const selector = (s: ReactFlowState) => ({
|
||||
@@ -119,6 +121,8 @@ const StoreUpdater = ({
|
||||
noPanClassName,
|
||||
nodeOrigin,
|
||||
rfId,
|
||||
autoPanOnConnect,
|
||||
autoPanOnNodeDrag,
|
||||
}: StoreUpdaterProps) => {
|
||||
const {
|
||||
setNodes,
|
||||
@@ -172,6 +176,8 @@ const StoreUpdater = ({
|
||||
useDirectStoreUpdater('noPanClassName', noPanClassName, store.setState);
|
||||
useDirectStoreUpdater('nodeOrigin', nodeOrigin, store.setState);
|
||||
useDirectStoreUpdater('rfId', rfId, store.setState);
|
||||
useDirectStoreUpdater('autoPanOnConnect', autoPanOnConnect, store.setState);
|
||||
useDirectStoreUpdater('autoPanOnNodeDrag', autoPanOnNodeDrag, store.setState);
|
||||
|
||||
useStoreUpdater<Node[]>(nodes, setNodes);
|
||||
useStoreUpdater<Edge[]>(edges, setEdges);
|
||||
|
||||
Reference in New Issue
Block a user