feat(connecting): move pane when mouse is close to edge of canvas #2753

This commit is contained in:
moklick
2023-01-16 16:39:48 +01:00
parent 893ee87838
commit e413bceb19
4 changed files with 69 additions and 16 deletions
+19
View File
@@ -1,4 +1,5 @@
import { createStore } from 'zustand';
import { zoomIdentity } from 'd3-zoom';
import { clampPosition, getDimensions, internalsSymbol } from '../utils';
import { applyNodeChanges, createSelectionChange, getSelectionChanges } from '../utils/changes';
@@ -19,6 +20,7 @@ import type {
UnselectNodesAndEdgesParams,
NodeChange,
} from '../types';
import { XYPosition } from 'react-flow-renderer';
const createRFStore = () =>
createStore<ReactFlowState>((set, get) => ({
@@ -250,6 +252,23 @@ const createRFStore = () =>
nodeInternals: new Map(nodeInternals),
});
},
movePane: (delta: XYPosition) => {
const { transform, width, height, d3Zoom, d3Selection, translateExtent } = get();
if (!d3Zoom || !d3Selection || (!delta.x && !delta.y)) {
return;
}
const nextTransform = zoomIdentity.translate(transform[0] + delta.x, transform[1] + delta.y).scale(transform[2]);
const extent: CoordinateExtent = [
[0, 0],
[width, height],
];
const constrainedTransform = d3Zoom?.constrain()(nextTransform, extent, translateExtent);
d3Zoom.transform(d3Selection, constrainedTransform);
},
cancelConnection: () =>
set({
connectionNodeId: initialState.connectionNodeId,