fix(mermaid): bring back auto resize on drag

This commit is contained in:
Elian Doran 2025-03-21 23:04:46 +02:00
parent cbc6efdad2
commit ae18b4b634
No known key found for this signature in database
2 changed files with 31 additions and 9 deletions

View File

@ -43,7 +43,7 @@ const TPL = `\
* *
* Features: * Features:
* *
* - The two panes are resizeable via a split, on desktop. * - The two panes are resizeable via a split, on desktop. The split can be optionally customized via {@link buildSplitExtraOptions}.
*/ */
export default abstract class AbstractSplitTypeWidget extends TypeWidget { export default abstract class AbstractSplitTypeWidget extends TypeWidget {
@ -95,10 +95,19 @@ export default abstract class AbstractSplitTypeWidget extends TypeWidget {
sizes: [ 50, 50 ], sizes: [ 50, 50 ],
direction: "horizontal", direction: "horizontal",
gutterSize: DEFAULT_GUTTER_SIZE, gutterSize: DEFAULT_GUTTER_SIZE,
// onDragEnd: () => this.zoomHandler?.() ...this.buildSplitExtraOptions()
}); });
} }
/**
* Called upon when the split between the preview and content pane is initialized. Can be used to add additional listeners if needed.
*
* @returns the additional split options.
*/
buildSplitExtraOptions(): Split.Options {
return {};
}
getData() { getData() {
return this.editorTypeWidget.getData(); return this.editorTypeWidget.getData();
} }

View File

@ -12,15 +12,27 @@ import AbstractSplitTypeWidget from "./abstract_split_type_widget.js";
export default abstract class AbstractSvgSplitTypeWidget extends AbstractSplitTypeWidget { export default abstract class AbstractSvgSplitTypeWidget extends AbstractSplitTypeWidget {
private $renderContainer!: JQuery<HTMLElement>; private $renderContainer!: JQuery<HTMLElement>;
private zoomHandler?: () => void; private zoomHandler: () => void;
private zoomInstance?: SvgPanZoom.Instance; private zoomInstance?: SvgPanZoom.Instance;
constructor() {
super();
this.zoomHandler = () => {
if (this.zoomInstance) {
this.zoomInstance.resize();
this.zoomInstance.fit();
this.zoomInstance.center();
}
}
}
doRender(): void { doRender(): void {
super.doRender(); super.doRender();
this.$renderContainer = $(`<div>`) this.$renderContainer = $(`<div>`)
.addClass("render-container") .addClass("render-container")
.css("height", "100%"); .css("height", "100%");
this.$preview.append(this.$renderContainer); this.$preview.append(this.$renderContainer);
$(window).on("resize", this.zoomHandler);
} }
async doRefresh(note: FNote | null | undefined) { async doRefresh(note: FNote | null | undefined) {
@ -52,6 +64,7 @@ export default abstract class AbstractSvgSplitTypeWidget extends AbstractSplitTy
cleanup(): void { cleanup(): void {
this.#cleanUpZoom(); this.#cleanUpZoom();
$(window).off("resize", this.zoomHandler);
super.cleanup(); super.cleanup();
} }
@ -102,13 +115,13 @@ export default abstract class AbstractSvgSplitTypeWidget extends AbstractSplitTy
zoomInstance.fit(); zoomInstance.fit();
} }
this.zoomHandler = () => {
zoomInstance.resize();
zoomInstance.fit();
zoomInstance.center();
};
this.zoomInstance = zoomInstance; this.zoomInstance = zoomInstance;
$(window).on("resize", this.zoomHandler); }
buildSplitExtraOptions(): Split.Options {
return {
onDragEnd: () => this.zoomHandler?.()
}
} }
#cleanUpZoom() { #cleanUpZoom() {