mirror of
https://github.com/zadam/trilium.git
synced 2025-11-11 17:08:58 +01:00
chore(react/type_widget): reposition on split resize
This commit is contained in:
parent
145ff1a2a5
commit
b376842e2d
@ -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%;
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user