mirror of
https://github.com/zadam/trilium.git
synced 2025-11-11 08:58:58 +01:00
chore(type_widgets): save pan & zoom
This commit is contained in:
parent
39bd236799
commit
d2bf972305
@ -43,6 +43,9 @@ export default function RelationMap({ note }: TypeWidgetProps) {
|
||||
const spacedUpdate = useEditorSpacedUpdate({
|
||||
note,
|
||||
getData() {
|
||||
return {
|
||||
content: JSON.stringify(data),
|
||||
};
|
||||
},
|
||||
onContentChange(content) {
|
||||
if (content) {
|
||||
@ -72,11 +75,13 @@ export default function RelationMap({ note }: TypeWidgetProps) {
|
||||
}
|
||||
})
|
||||
|
||||
const onTransform = useCallback(() => {
|
||||
if (!containerRef.current || !apiRef.current) return;
|
||||
const onTransform = useCallback((pzInstance: PanZoom) => {
|
||||
if (!containerRef.current || !apiRef.current || !data) return;
|
||||
const zoom = getZoom(containerRef.current);
|
||||
apiRef.current.setZoom(zoom);
|
||||
}, [ ]);
|
||||
data.transform = JSON.parse(JSON.stringify(pzInstance.getTransform()));
|
||||
spacedUpdate.scheduleUpdate();
|
||||
}, [ data ]);
|
||||
|
||||
usePanZoom({
|
||||
containerRef,
|
||||
@ -122,7 +127,7 @@ function usePanZoom({ containerRef, options, transformData, onTransform }: {
|
||||
containerRef: RefObject<HTMLElement>;
|
||||
options: PanZoomOptions;
|
||||
transformData: MapData["transform"] | undefined;
|
||||
onTransform: () => void
|
||||
onTransform: (pzInstance: PanZoom) => void
|
||||
}) {
|
||||
const apiRef = useRef<PanZoom>(null);
|
||||
|
||||
@ -140,7 +145,7 @@ function usePanZoom({ containerRef, options, transformData, onTransform }: {
|
||||
}
|
||||
|
||||
if (onTransform) {
|
||||
apiRef.current!.on("transform", onTransform);
|
||||
apiRef.current!.on("transform", () => onTransform(pzInstance));
|
||||
}
|
||||
|
||||
return () => pzInstance.dispose();
|
||||
|
||||
@ -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() {
|
||||
if (!this.pzInstance) {
|
||||
return;
|
||||
@ -577,12 +569,6 @@ export default class RelationMapTypeWidget extends TypeWidget {
|
||||
};
|
||||
}
|
||||
|
||||
getData() {
|
||||
return {
|
||||
content: JSON.stringify(this.mapData)
|
||||
};
|
||||
}
|
||||
|
||||
async relationMapCreateChildNoteEvent({ ntxId }: EventData<"relationMapCreateChildNote">) {
|
||||
if (!this.isNoteContext(ntxId)) {
|
||||
return;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user