reset layout position on json edit

This commit is contained in:
Aykut Saraç 2022-02-09 13:15:27 +03:00
parent 6a94a2c86c
commit 1aa5d8aecd

View File

@ -25,6 +25,7 @@ const StyledEditorWrapper = styled.div`
export const LiveEditor: React.FC = () => {
const canvasRef = React.useRef<CanvasRef | null>(null);
const wrapperRef = React.useRef<ReactZoomPanPinchRef | null>(null);
const [json] = useLocalStorage("json", JSON.stringify(defaultValue));
const [config] = useLocalStorage<StorageConfig>("config", {
layout: "LEFT",
@ -34,6 +35,10 @@ export const LiveEditor: React.FC = () => {
const { nodes, edges } = getEdgeNodes(json);
const onLayoutChange = () => {
wrapperRef.current?.resetTransform();
};
return (
<StyledLiveEditor>
<StyledEditorWrapper>
@ -61,9 +66,7 @@ export const LiveEditor: React.FC = () => {
center={false}
readonly
node={NodeWrapper}
onLayoutChange={() => {
canvasRef.current?.centerCanvas && canvasRef.current?.centerCanvas()
}}
onLayoutChange={onLayoutChange}
/>
</TransformComponent>
</TransformWrapper>