mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-10 18:39:22 +08:00
fix(mermaid): saving of attachment
This commit is contained in:
parent
b8a560354f
commit
1fb2b5341d
@ -1,4 +1,5 @@
|
|||||||
import type FNote from "../../entities/fnote.js";
|
import type FNote from "../../entities/fnote.js";
|
||||||
|
import server from "../../services/server.js";
|
||||||
import AbstractSplitTypeWidget from "./abstract_split_type_widget.js";
|
import AbstractSplitTypeWidget from "./abstract_split_type_widget.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -15,6 +16,7 @@ export default abstract class AbstractSvgSplitTypeWidget extends AbstractSplitTy
|
|||||||
private $renderContainer!: JQuery<HTMLElement>;
|
private $renderContainer!: JQuery<HTMLElement>;
|
||||||
private zoomHandler: () => void;
|
private zoomHandler: () => void;
|
||||||
private zoomInstance?: SvgPanZoom.Instance;
|
private zoomInstance?: SvgPanZoom.Instance;
|
||||||
|
private svg?: string;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
@ -41,12 +43,12 @@ export default abstract class AbstractSvgSplitTypeWidget extends AbstractSplitTy
|
|||||||
|
|
||||||
const blob = await note?.getBlob();
|
const blob = await note?.getBlob();
|
||||||
const content = blob?.content || "";
|
const content = blob?.content || "";
|
||||||
this.refreshPreview(content, true);
|
this.onContentChanged(content, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
getData(): { content: string; } {
|
getData(): { content: string; } {
|
||||||
const data = super.getData();
|
const data = super.getData();
|
||||||
this.refreshPreview(data.content, false);
|
this.onContentChanged(data.content, false);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,12 +58,33 @@ export default abstract class AbstractSvgSplitTypeWidget extends AbstractSplitTy
|
|||||||
* @param content the content that will be passed to `renderSvg` for rendering. It is not the SVG content.
|
* @param content the content that will be passed to `renderSvg` for rendering. It is not the SVG content.
|
||||||
* @param recenter `true` to reposition the pan/zoom to fit the image and to center it.
|
* @param recenter `true` to reposition the pan/zoom to fit the image and to center it.
|
||||||
*/
|
*/
|
||||||
async refreshPreview(content: string, recenter: boolean) {
|
async onContentChanged(content: string, recenter: boolean) {
|
||||||
if (this.note) {
|
if (!this.note) {
|
||||||
const svg = await this.renderSvg(content);
|
return;
|
||||||
this.$renderContainer.html(svg);
|
|
||||||
await this.#setupPanZoom(!recenter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const svg = await this.renderSvg(content);
|
||||||
|
if (svg === this.svg) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.svg = svg;
|
||||||
|
|
||||||
|
this.$renderContainer.html(svg);
|
||||||
|
await this.#setupPanZoom(!recenter);
|
||||||
|
this.#saveSvg();
|
||||||
|
}
|
||||||
|
|
||||||
|
#saveSvg() {
|
||||||
|
const payload = {
|
||||||
|
role: "image",
|
||||||
|
title: "mermaid-export.svg",
|
||||||
|
mime: "image/svg+xml",
|
||||||
|
content: this.svg,
|
||||||
|
position: 0
|
||||||
|
};
|
||||||
|
|
||||||
|
server.post(`notes/${this.noteId}/attachments?matchBy=title`, payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup(): void {
|
cleanup(): void {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user