refactor(screenToFlowPosition): add option to configure snapToGrid #3771
This commit is contained in:
@@ -2,6 +2,14 @@
|
||||
|
||||
## 12.0.0-next.6
|
||||
|
||||
## Minor changes
|
||||
|
||||
- pass Node/Edge types to changes thanks @FelipeEmos
|
||||
- use position instead of positionAbsolute for `getNodesBounds`
|
||||
- add second option param to `screenToFlowPosition` for configuring if `snapToGrid` should be used
|
||||
|
||||
## 12.0.0-next.6
|
||||
|
||||
### Minor changes
|
||||
|
||||
- fix `deleteElements`
|
||||
|
||||
@@ -86,8 +86,8 @@ const useViewportHelper = (): ViewportHelperFunctions => {
|
||||
|
||||
panZoom?.setViewport(viewport, { duration: options?.duration });
|
||||
},
|
||||
screenToFlowPosition: (position: XYPosition) => {
|
||||
const { transform, snapToGrid, snapGrid, domNode } = store.getState();
|
||||
screenToFlowPosition: (position: XYPosition, options: { snapToGrid: boolean } = { snapToGrid: true }) => {
|
||||
const { transform, snapGrid, domNode } = store.getState();
|
||||
|
||||
if (!domNode) {
|
||||
return position;
|
||||
@@ -100,7 +100,7 @@ const useViewportHelper = (): ViewportHelperFunctions => {
|
||||
y: position.y - domY,
|
||||
};
|
||||
|
||||
return pointToRendererPoint(correctedPosition, transform, snapToGrid, snapGrid || [1, 1]);
|
||||
return pointToRendererPoint(correctedPosition, transform, options.snapToGrid, snapGrid);
|
||||
},
|
||||
flowToScreenPosition: (position: XYPosition) => {
|
||||
const { transform, domNode } = store.getState();
|
||||
|
||||
@@ -55,7 +55,7 @@ export type ViewportHelperFunctions = {
|
||||
fitView: FitView;
|
||||
setCenter: SetCenter;
|
||||
fitBounds: FitBounds;
|
||||
screenToFlowPosition: (position: XYPosition) => XYPosition;
|
||||
screenToFlowPosition: (position: XYPosition, options?: { snapToGrid: boolean }) => XYPosition;
|
||||
flowToScreenPosition: (position: XYPosition) => XYPosition;
|
||||
viewportInitialized: boolean;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user