refactor(onLoad): add new zoom pan helpers
This commit is contained in:
@@ -8,7 +8,8 @@ import { OnLoad, XYPosition, Node, Edge, FlowExportObject } from '../types';
|
||||
function useOnLoadHandler(onLoad: OnLoad<any> | undefined) {
|
||||
const isInitialized = useRef<boolean>(false);
|
||||
const store = useStoreApi();
|
||||
const { zoomIn, zoomOut, zoomTo, transform: setTransform, fitView, initialized } = useZoomPanHelper();
|
||||
const { zoomIn, zoomOut, zoomTo, getZoom, setTransform, getTransform, setCenter, fitView, initialized } =
|
||||
useZoomPanHelper();
|
||||
|
||||
useEffect(() => {
|
||||
if (!isInitialized.current && initialized) {
|
||||
@@ -47,7 +48,10 @@ function useOnLoadHandler(onLoad: OnLoad<any> | undefined) {
|
||||
zoomIn,
|
||||
zoomOut,
|
||||
zoomTo,
|
||||
getZoom,
|
||||
setTransform,
|
||||
getTransform,
|
||||
setCenter,
|
||||
project,
|
||||
getNodes,
|
||||
getEdges,
|
||||
|
||||
+17
-9
@@ -24,15 +24,23 @@ export type OnNodesChange = (nodes: NodeChange[]) => void;
|
||||
|
||||
export type OnEdgesChange = (nodes: EdgeChange[]) => void;
|
||||
|
||||
export type ZoomInOut = (options?: ZoomPanHelperFunctionOptions) => void;
|
||||
export type ZoomTo = (zoomLevel: number, options?: ZoomPanHelperFunctionOptions) => void;
|
||||
export type SetTransform = (transform: FlowTransform, options?: ZoomPanHelperFunctionOptions) => void;
|
||||
export type SetCenter = (x: number, y: number, options?: SetCenterOptions) => void;
|
||||
|
||||
export type OnLoadParams<T = any> = {
|
||||
zoomIn: () => void;
|
||||
zoomOut: () => void;
|
||||
zoomTo: (zoomLevel: number) => void;
|
||||
zoomIn: ZoomInOut;
|
||||
zoomOut: ZoomInOut;
|
||||
zoomTo: ZoomTo;
|
||||
getZoom: () => number;
|
||||
setCenter: SetCenter;
|
||||
fitView: FitView;
|
||||
project: Project;
|
||||
getNodes: () => Node<T>[];
|
||||
getEdges: () => Edge<T>[];
|
||||
setTransform: (transform: FlowTransform) => void;
|
||||
setTransform: SetTransform;
|
||||
getTransform: () => FlowTransform;
|
||||
toObject: ToObject<T>;
|
||||
};
|
||||
|
||||
@@ -118,14 +126,14 @@ export type FitBoundsOptions = ZoomPanHelperFunctionOptions & {
|
||||
padding?: number;
|
||||
};
|
||||
export interface ZoomPanHelperFunctions {
|
||||
zoomIn: (options?: ZoomPanHelperFunctionOptions) => void;
|
||||
zoomOut: (options?: ZoomPanHelperFunctionOptions) => void;
|
||||
zoomTo: (zoomLevel: number, options?: ZoomPanHelperFunctionOptions) => void;
|
||||
zoomIn: ZoomInOut;
|
||||
zoomOut: ZoomInOut;
|
||||
zoomTo: ZoomTo;
|
||||
getZoom: () => number;
|
||||
setTransform: (transform: FlowTransform, options?: ZoomPanHelperFunctionOptions) => void;
|
||||
setTransform: SetTransform;
|
||||
getTransform: () => FlowTransform;
|
||||
fitView: FitView;
|
||||
setCenter: (x: number, y: number, options?: SetCenterOptions) => void;
|
||||
setCenter: SetCenter;
|
||||
fitBounds: (bounds: Rect, options?: FitBoundsOptions) => void;
|
||||
project: (position: XYPosition) => XYPosition;
|
||||
initialized: boolean;
|
||||
|
||||
Reference in New Issue
Block a user