refactor(split_editor): allow different attachment name

This commit is contained in:
Elian Doran 2025-03-22 02:21:24 +02:00
parent 98e4d563ad
commit acf6d9dc4f
No known key found for this signature in database
3 changed files with 14 additions and 2 deletions

View File

@ -75,6 +75,7 @@ const TPL = `\
* Features: * Features:
* *
* - The two panes are resizeable via a split, on desktop. The split can be optionally customized via {@link buildSplitExtraOptions}. * - The two panes are resizeable via a split, on desktop. The split can be optionally customized via {@link buildSplitExtraOptions}.
* - Can display errors to the user via {@link setError}.
*/ */
export default abstract class AbstractSplitTypeWidget extends TypeWidget { export default abstract class AbstractSplitTypeWidget extends TypeWidget {

View File

@ -9,8 +9,10 @@ import AbstractSplitTypeWidget from "./abstract_split_type_widget.js";
* *
* This adds the following functionality: * This adds the following functionality:
* *
* - Automatic handling of the preview when content or the note changes. * - Automatic handling of the preview when content or the note changes via {@link renderSvg}.
* - Built-in pan and zoom functionality with automatic re-centering. * - Built-in pan and zoom functionality with automatic re-centering.
* - Automatically displays errors to the user if {@link renderSvg} failed.
* - Automatically saves the SVG attachment.
* *
*/ */
export default abstract class AbstractSvgSplitTypeWidget extends AbstractSplitTypeWidget { export default abstract class AbstractSvgSplitTypeWidget extends AbstractSplitTypeWidget {
@ -91,7 +93,7 @@ export default abstract class AbstractSvgSplitTypeWidget extends AbstractSplitTy
#saveSvg() { #saveSvg() {
const payload = { const payload = {
role: "image", role: "image",
title: "mermaid-export.svg", title: `${this.attachmentName}.svg`,
mime: "image/svg+xml", mime: "image/svg+xml",
content: this.svg, content: this.svg,
position: 0 position: 0
@ -115,6 +117,11 @@ export default abstract class AbstractSvgSplitTypeWidget extends AbstractSplitTy
*/ */
abstract renderSvg(content: string): Promise<string>; abstract renderSvg(content: string): Promise<string>;
/**
* Called to obtain the name of the note attachment (without .svg extension) that will be used for storing the preview.
*/
abstract get attachmentName(): string;
/** /**
* @param preservePanZoom `true` to keep the pan/zoom settings of the previous image, or `false` to re-center it. * @param preservePanZoom `true` to keep the pan/zoom settings of the previous image, or `false` to re-center it.
*/ */

View File

@ -11,6 +11,10 @@ export class MermaidTypeWidget extends AbstractSvgSplitTypeWidget {
return "mermaid"; return "mermaid";
} }
get attachmentName(): string {
return "mermaid-export";
}
async renderSvg(content: string) { async renderSvg(content: string) {
const mermaid = (await import("mermaid")).default; const mermaid = (await import("mermaid")).default;
await loadElkIfNeeded(mermaid, content); await loadElkIfNeeded(mermaid, content);