|
@@ -2,9 +2,10 @@ import { ReactZoomPanPinchRef } from "react-zoom-pan-pinch";
|
|
import { CanvasDirection } from "reaflow";
|
|
import { CanvasDirection } from "reaflow";
|
|
import { defaultJson } from "src/constants/data";
|
|
import { defaultJson } from "src/constants/data";
|
|
import create from "zustand";
|
|
import create from "zustand";
|
|
-
|
|
|
|
|
|
+import {MutableRefObject} from "react";
|
|
interface ConfigActions {
|
|
interface ConfigActions {
|
|
setJson: (json: string) => void;
|
|
setJson: (json: string) => void;
|
|
|
|
+ setCanvasRef: (canvas: MutableRefObject<HTMLCanvasElement | null> ) => void;
|
|
setConfig: (key: keyof Config, value: unknown) => void;
|
|
setConfig: (key: keyof Config, value: unknown) => void;
|
|
getJson: () => string;
|
|
getJson: () => string;
|
|
zoomIn: () => void;
|
|
zoomIn: () => void;
|
|
@@ -15,6 +16,7 @@ interface ConfigActions {
|
|
const initialStates = {
|
|
const initialStates = {
|
|
json: defaultJson,
|
|
json: defaultJson,
|
|
cursorMode: "move" as "move" | "navigation",
|
|
cursorMode: "move" as "move" | "navigation",
|
|
|
|
+ canvas: undefined as MutableRefObject<HTMLCanvasElement | null> | undefined,
|
|
layout: "RIGHT" as CanvasDirection,
|
|
layout: "RIGHT" as CanvasDirection,
|
|
expand: true,
|
|
expand: true,
|
|
hideEditor: false,
|
|
hideEditor: false,
|
|
@@ -29,6 +31,7 @@ const useConfig = create<Config & ConfigActions>()((set, get) => ({
|
|
...initialStates,
|
|
...initialStates,
|
|
getJson: () => get().json,
|
|
getJson: () => get().json,
|
|
setJson: (json: string) => set({ json }),
|
|
setJson: (json: string) => set({ json }),
|
|
|
|
+ setCanvasRef: (canvas: MutableRefObject<HTMLCanvasElement | null> ) => set({ canvas }),
|
|
zoomIn: () => {
|
|
zoomIn: () => {
|
|
const zoomPanPinch = get().zoomPanPinch;
|
|
const zoomPanPinch = get().zoomPanPinch;
|
|
if (zoomPanPinch) {
|
|
if (zoomPanPinch) {
|
|
@@ -51,7 +54,9 @@ const useConfig = create<Config & ConfigActions>()((set, get) => ({
|
|
},
|
|
},
|
|
centerView: () => {
|
|
centerView: () => {
|
|
const zoomPanPinch = get().zoomPanPinch;
|
|
const zoomPanPinch = get().zoomPanPinch;
|
|
- if (zoomPanPinch) zoomPanPinch.centerView(0.4);
|
|
|
|
|
|
+ const canvas = get().canvas
|
|
|
|
+ if(zoomPanPinch && canvas && canvas.current)
|
|
|
|
+ zoomPanPinch.zoomToElement(canvas.current["containerRef"].current)
|
|
},
|
|
},
|
|
setConfig: (setting: keyof Config, value: unknown) => set({ [setting]: value }),
|
|
setConfig: (setting: keyof Config, value: unknown) => set({ [setting]: value }),
|
|
}));
|
|
}));
|