chore(react/type_widget): reposition on split resize

This commit is contained in:
Elian Doran 2025-09-20 21:12:29 +03:00
parent 145ff1a2a5
commit b376842e2d
No known key found for this signature in database
3 changed files with 14 additions and 15 deletions

View File

@ -84,7 +84,10 @@
}
/* #region SVG */
.note-detail-split.svg-editor .render-container,
.note-detail-split.svg-editor .render-container {
height: 100%;
}
.note-detail-split.svg-editor .render-container svg {
width: 100%;
height: 100%;

View File

@ -3,7 +3,7 @@ import { t } from "../../../services/i18n";
import SplitEditor, { PreviewButton, SplitEditorProps } from "./SplitEditor";
import { RawHtmlBlock } from "../../react/RawHtml";
import server from "../../../services/server";
import svgPanZoom from "svg-pan-zoom";
import svgPanZoom, { zoomIn } from "svg-pan-zoom";
interface SvgSplitEditorProps extends Omit<SplitEditorProps, "previewContent"> {
/**
@ -55,6 +55,7 @@ export default function SvgSplitEditor({ note, attachmentName, renderSvg, ...pro
// Pan & zoom.
const lastPanZoom = useRef<{ pan: SvgPanZoom.Point, zoom: number }>();
const lastNoteId = useRef<string>();
const zoomRef = useRef<SvgPanZoom.Instance>();
useEffect(() => {
const shouldPreservePanZoom = (lastNoteId.current === note.noteId);
const svgEl = containerRef.current?.querySelector("svg");
@ -73,6 +74,8 @@ export default function SvgSplitEditor({ note, attachmentName, renderSvg, ...pro
}
lastNoteId.current = note.noteId;
zoomRef.current = zoomInstance;
return () => {
lastPanZoom.current = {
pan: zoomInstance.getPan(),
@ -89,6 +92,12 @@ export default function SvgSplitEditor({ note, attachmentName, renderSvg, ...pro
error={error}
onContentChanged={onContentChanged}
dataSaved={onSave}
splitOptions={{
onDrag: () => {
if (!zoomRef.current) return;
zoomRef.current.resize().fit().center();
}
}}
previewContent={(
<RawHtmlBlock
className="render-container"

View File

@ -25,22 +25,9 @@ export default abstract class AbstractSvgSplitTypeWidget extends AbstractSplitTy
private zoomInstance?: SvgPanZoom.Instance;
private svg?: string;
constructor() {
super();
this.zoomHandler = () => {
if (this.zoomInstance) {
this.zoomInstance.resize();
this.zoomInstance.fit();
this.zoomInstance.center();
}
}
}
doRender(): void {
super.doRender();
this.$renderContainer = $(`<div>`)
.addClass("render-container")
.css("height", "100%");
this.$preview.append(this.$renderContainer);
$(window).on("resize", this.zoomHandler);
}