chore(type_widgets): save pan & zoom

This commit is contained in:
Elian Doran 2025-09-29 19:41:08 +03:00
parent 39bd236799
commit d2bf972305
No known key found for this signature in database
2 changed files with 10 additions and 19 deletions

View File

@ -43,6 +43,9 @@ export default function RelationMap({ note }: TypeWidgetProps) {
const spacedUpdate = useEditorSpacedUpdate({ const spacedUpdate = useEditorSpacedUpdate({
note, note,
getData() { getData() {
return {
content: JSON.stringify(data),
};
}, },
onContentChange(content) { onContentChange(content) {
if (content) { if (content) {
@ -72,11 +75,13 @@ export default function RelationMap({ note }: TypeWidgetProps) {
} }
}) })
const onTransform = useCallback(() => { const onTransform = useCallback((pzInstance: PanZoom) => {
if (!containerRef.current || !apiRef.current) return; if (!containerRef.current || !apiRef.current || !data) return;
const zoom = getZoom(containerRef.current); const zoom = getZoom(containerRef.current);
apiRef.current.setZoom(zoom); apiRef.current.setZoom(zoom);
}, [ ]); data.transform = JSON.parse(JSON.stringify(pzInstance.getTransform()));
spacedUpdate.scheduleUpdate();
}, [ data ]);
usePanZoom({ usePanZoom({
containerRef, containerRef,
@ -122,7 +127,7 @@ function usePanZoom({ containerRef, options, transformData, onTransform }: {
containerRef: RefObject<HTMLElement>; containerRef: RefObject<HTMLElement>;
options: PanZoomOptions; options: PanZoomOptions;
transformData: MapData["transform"] | undefined; transformData: MapData["transform"] | undefined;
onTransform: () => void onTransform: (pzInstance: PanZoom) => void
}) { }) {
const apiRef = useRef<PanZoom>(null); const apiRef = useRef<PanZoom>(null);
@ -140,7 +145,7 @@ function usePanZoom({ containerRef, options, transformData, onTransform }: {
} }
if (onTransform) { if (onTransform) {
apiRef.current!.on("transform", onTransform); apiRef.current!.on("transform", () => onTransform(pzInstance));
} }
return () => pzInstance.dispose(); return () => pzInstance.dispose();

View File

@ -338,14 +338,6 @@ export default class RelationMapTypeWidget extends TypeWidget {
}); });
} }
async initPanZoom() {
const panzoom = (await import("panzoom")).default;
this.pzInstance.on("transform", () => {
this.saveCurrentTransform();
});
}
saveCurrentTransform() { saveCurrentTransform() {
if (!this.pzInstance) { if (!this.pzInstance) {
return; return;
@ -577,12 +569,6 @@ export default class RelationMapTypeWidget extends TypeWidget {
}; };
} }
getData() {
return {
content: JSON.stringify(this.mapData)
};
}
async relationMapCreateChildNoteEvent({ ntxId }: EventData<"relationMapCreateChildNote">) { async relationMapCreateChildNoteEvent({ ntxId }: EventData<"relationMapCreateChildNote">) {
if (!this.isNoteContext(ntxId)) { if (!this.isNoteContext(ntxId)) {
return; return;