|
@@ -72,7 +72,7 @@ export interface PlaygroundTools {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export function usePlaygroundTools(props?: PlaygroundToolsPropsType): PlaygroundTools {
|
|
export function usePlaygroundTools(props?: PlaygroundToolsPropsType): PlaygroundTools {
|
|
|
- const { maxZoom = 2, minZoom = 0.25, padding = 30 } = props || {};
|
|
|
|
|
|
|
+ const { maxZoom, minZoom, padding = 30 } = props || {};
|
|
|
const playground = usePlayground();
|
|
const playground = usePlayground();
|
|
|
const container = usePlaygroundContainer();
|
|
const container = usePlaygroundContainer();
|
|
|
const historyService = container.isBound(HistoryService)
|
|
const historyService = container.isBound(HistoryService)
|
|
@@ -85,12 +85,6 @@ export function usePlaygroundTools(props?: PlaygroundToolsPropsType): Playground
|
|
|
const [canUndo, setCanUndo] = useState(false);
|
|
const [canUndo, setCanUndo] = useState(false);
|
|
|
const [canRedo, setCanRedo] = useState(false);
|
|
const [canRedo, setCanRedo] = useState(false);
|
|
|
|
|
|
|
|
- const fitViewOptions = {
|
|
|
|
|
- maxZoom,
|
|
|
|
|
- minZoom,
|
|
|
|
|
- padding,
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
const changeLayout = useCallback(
|
|
const changeLayout = useCallback(
|
|
|
(newLayout?: FlowLayoutDefault) => {
|
|
(newLayout?: FlowLayoutDefault) => {
|
|
|
const allNodes = doc.getAllNodes();
|
|
const allNodes = doc.getAllNodes();
|
|
@@ -105,8 +99,10 @@ export function usePlaygroundTools(props?: PlaygroundToolsPropsType): Playground
|
|
|
});
|
|
});
|
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
|
fitView(doc, playground.config, {
|
|
fitView(doc, playground.config, {
|
|
|
- ...fitViewOptions,
|
|
|
|
|
easingDuration: 300,
|
|
easingDuration: 300,
|
|
|
|
|
+ padding,
|
|
|
|
|
+ maxZoom: playground.config.config.maxZoom,
|
|
|
|
|
+ minZoom: playground.config.config.minZoom,
|
|
|
});
|
|
});
|
|
|
}, 10);
|
|
}, 10);
|
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
@@ -118,14 +114,11 @@ export function usePlaygroundTools(props?: PlaygroundToolsPropsType): Playground
|
|
|
doc.setLayout(newLayout);
|
|
doc.setLayout(newLayout);
|
|
|
updateLayout(doc.layout);
|
|
updateLayout(doc.layout);
|
|
|
},
|
|
},
|
|
|
- [doc, playground]
|
|
|
|
|
|
|
+ [doc, playground, padding]
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
const handleZoomOut = useCallback(
|
|
const handleZoomOut = useCallback(
|
|
|
(easing?: boolean) => {
|
|
(easing?: boolean) => {
|
|
|
- if (zoom < minZoom) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
playground?.config.zoomout(easing);
|
|
playground?.config.zoomout(easing);
|
|
|
},
|
|
},
|
|
|
[zoom, playground]
|
|
[zoom, playground]
|
|
@@ -133,9 +126,6 @@ export function usePlaygroundTools(props?: PlaygroundToolsPropsType): Playground
|
|
|
|
|
|
|
|
const handleZoomIn = useCallback(
|
|
const handleZoomIn = useCallback(
|
|
|
(easing?: boolean) => {
|
|
(easing?: boolean) => {
|
|
|
- if (zoom > maxZoom) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
playground?.config.zoomin(easing);
|
|
playground?.config.zoomin(easing);
|
|
|
},
|
|
},
|
|
|
[zoom, playground]
|
|
[zoom, playground]
|
|
@@ -145,12 +135,14 @@ export function usePlaygroundTools(props?: PlaygroundToolsPropsType): Playground
|
|
|
const handleFitView = useCallback(
|
|
const handleFitView = useCallback(
|
|
|
(easing?: boolean, easingDuration?: number) => {
|
|
(easing?: boolean, easingDuration?: number) => {
|
|
|
fitView(doc, playground.config, {
|
|
fitView(doc, playground.config, {
|
|
|
- ...fitViewOptions,
|
|
|
|
|
easing,
|
|
easing,
|
|
|
easingDuration,
|
|
easingDuration,
|
|
|
|
|
+ padding,
|
|
|
|
|
+ maxZoom: playground.config.config.maxZoom,
|
|
|
|
|
+ minZoom: playground.config.config.minZoom,
|
|
|
});
|
|
});
|
|
|
},
|
|
},
|
|
|
- [doc, playground]
|
|
|
|
|
|
|
+ [doc, playground, padding]
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
const handleUpdateZoom = useCallback(
|
|
const handleUpdateZoom = useCallback(
|
|
@@ -179,6 +171,14 @@ export function usePlaygroundTools(props?: PlaygroundToolsPropsType): Playground
|
|
|
return () => dispose.dispose();
|
|
return () => dispose.dispose();
|
|
|
}, [playground, historyService]);
|
|
}, [playground, historyService]);
|
|
|
|
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ const config = playground.config.config;
|
|
|
|
|
+ playground.config.updateConfig({
|
|
|
|
|
+ maxZoom: maxZoom !== undefined ? maxZoom : config.maxZoom,
|
|
|
|
|
+ minZoom: minZoom !== undefined ? minZoom : config.minZoom,
|
|
|
|
|
+ });
|
|
|
|
|
+ }, [playground, maxZoom, minZoom]);
|
|
|
|
|
+
|
|
|
return {
|
|
return {
|
|
|
zoomin: handleZoomIn,
|
|
zoomin: handleZoomIn,
|
|
|
zoomout: handleZoomOut,
|
|
zoomout: handleZoomOut,
|