mirror of
https://github.com/zadam/trilium.git
synced 2025-10-21 15:49:00 +02:00
feat(mermaid): react to layout change immediately
This commit is contained in:
parent
cf874b5ee8
commit
4860594758
@ -6,6 +6,7 @@ import Split from "split.js";
|
|||||||
import { DEFAULT_GUTTER_SIZE } from "../../services/resizer.js";
|
import { DEFAULT_GUTTER_SIZE } from "../../services/resizer.js";
|
||||||
import options from "../../services/options.js";
|
import options from "../../services/options.js";
|
||||||
import type SwitchSplitOrientationButton from "../floating_buttons/switch_layout_button.js";
|
import type SwitchSplitOrientationButton from "../floating_buttons/switch_layout_button.js";
|
||||||
|
import type { EventData } from "../../components/app_context.js";
|
||||||
|
|
||||||
const TPL = `\
|
const TPL = `\
|
||||||
<div class="note-detail-split note-detail-printable">
|
<div class="note-detail-split note-detail-printable">
|
||||||
@ -106,7 +107,7 @@ export default abstract class AbstractSplitTypeWidget extends TypeWidget {
|
|||||||
private $editor!: JQuery<HTMLElement>;
|
private $editor!: JQuery<HTMLElement>;
|
||||||
private $errorContainer!: JQuery<HTMLElement>;
|
private $errorContainer!: JQuery<HTMLElement>;
|
||||||
private editorTypeWidget: EditableCodeTypeWidget;
|
private editorTypeWidget: EditableCodeTypeWidget;
|
||||||
private layoutOrientation!: "horizontal" | "vertical";
|
private layoutOrientation?: "horizontal" | "vertical";
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
@ -118,17 +119,13 @@ export default abstract class AbstractSplitTypeWidget extends TypeWidget {
|
|||||||
doRender(): void {
|
doRender(): void {
|
||||||
this.$widget = $(TPL);
|
this.$widget = $(TPL);
|
||||||
|
|
||||||
const layoutOrientation = options.get("splitEditorOrientation") ?? "horizontal";
|
|
||||||
this.$widget.addClass(`split-${layoutOrientation}`);
|
|
||||||
this.layoutOrientation = layoutOrientation as ("horizontal" | "vertical");
|
|
||||||
|
|
||||||
this.$firstCol = this.$widget.find(".note-detail-split-first-col");
|
this.$firstCol = this.$widget.find(".note-detail-split-first-col");
|
||||||
this.$secondCol = this.$widget.find(".note-detail-split-second-col");
|
this.$secondCol = this.$widget.find(".note-detail-split-second-col");
|
||||||
this.$preview = this.$widget.find(".note-detail-split-preview");
|
this.$preview = this.$widget.find(".note-detail-split-preview");
|
||||||
this.$editor = this.$widget.find(".note-detail-split-editor");
|
this.$editor = this.$widget.find(".note-detail-split-editor");
|
||||||
this.$editor.append(this.editorTypeWidget.render());
|
this.$editor.append(this.editorTypeWidget.render());
|
||||||
this.$errorContainer = this.$widget.find(".note-detail-error-container");
|
this.$errorContainer = this.$widget.find(".note-detail-error-container");
|
||||||
this.#setupResizer();
|
this.#adjustLayoutOrientation();
|
||||||
|
|
||||||
super.doRender();
|
super.doRender();
|
||||||
}
|
}
|
||||||
@ -139,6 +136,8 @@ export default abstract class AbstractSplitTypeWidget extends TypeWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async doRefresh(note: FNote | null | undefined) {
|
async doRefresh(note: FNote | null | undefined) {
|
||||||
|
this.#adjustLayoutOrientation();
|
||||||
|
|
||||||
await this.editorTypeWidget.initialized;
|
await this.editorTypeWidget.initialized;
|
||||||
|
|
||||||
if (note) {
|
if (note) {
|
||||||
@ -148,6 +147,18 @@ export default abstract class AbstractSplitTypeWidget extends TypeWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#adjustLayoutOrientation() {
|
||||||
|
const layoutOrientation = options.get("splitEditorOrientation") ?? "horizontal";
|
||||||
|
if (this.layoutOrientation === layoutOrientation) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.$widget.toggleClass("split-horizontal", layoutOrientation === "horizontal");
|
||||||
|
this.$widget.toggleClass("split-vertical", layoutOrientation === "vertical");
|
||||||
|
this.layoutOrientation = layoutOrientation as ("horizontal" | "vertical");
|
||||||
|
this.#setupResizer();
|
||||||
|
}
|
||||||
|
|
||||||
#setupResizer() {
|
#setupResizer() {
|
||||||
if (!utils.isDesktop()) {
|
if (!utils.isDesktop()) {
|
||||||
return;
|
return;
|
||||||
@ -188,4 +199,10 @@ export default abstract class AbstractSplitTypeWidget extends TypeWidget {
|
|||||||
return this.editorTypeWidget.getData();
|
return this.editorTypeWidget.getData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {
|
||||||
|
if (loadResults.isOptionReloaded("splitEditorOrientation")) {
|
||||||
|
this.refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user