mirror of
https://github.com/TriliumNext/Trilium.git
synced 2025-12-12 14:11:05 -06: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({
|
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();
|
||||||
|
|||||||
@ -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;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user