diff --git a/src/public/app/widgets/floating_buttons/svg_export_button.js b/src/public/app/widgets/floating_buttons/svg_export_button.js index f30130a53..6b25ad553 100644 --- a/src/public/app/widgets/floating_buttons/svg_export_button.js +++ b/src/public/app/widgets/floating_buttons/svg_export_button.js @@ -3,7 +3,7 @@ import NoteContextAwareWidget from "../note_context_aware_widget.js"; const TPL = ` @@ -12,7 +12,7 @@ const TPL = ` export default class SvgExportButton extends NoteContextAwareWidget { isEnabled() { return super.isEnabled() - && this.note?.type === 'mermaid' + && [ "mermaid", "mindMap" ].includes(this.note?.type) && this.note.isContentAvailable() && this.noteContext?.viewScope.viewMode === 'default'; } @@ -21,7 +21,7 @@ export default class SvgExportButton extends NoteContextAwareWidget { super.doRender(); this.$widget = $(TPL); - this.$widget.on('click', () => this.triggerEvent('exportMermaid', {ntxId: this.ntxId})); + this.$widget.on('click', () => this.triggerEvent('exportSvg', {ntxId: this.ntxId})); this.contentSized(); } } diff --git a/src/public/app/widgets/mermaid.js b/src/public/app/widgets/mermaid.js index 6411ebbc7..cab971860 100644 --- a/src/public/app/widgets/mermaid.js +++ b/src/public/app/widgets/mermaid.js @@ -132,7 +132,7 @@ export default class MermaidWidget extends NoteContextAwareWidget { } } - async exportMermaidEvent({ntxId}) { + async exportSvgEvent({ntxId}) { if (!this.isNoteContext(ntxId)) { return; } diff --git a/src/public/app/widgets/type_widgets/mind_map.js b/src/public/app/widgets/type_widgets/mind_map.js index 36fd884e8..28a899f66 100644 --- a/src/public/app/widgets/type_widgets/mind_map.js +++ b/src/public/app/widgets/type_widgets/mind_map.js @@ -83,7 +83,7 @@ export default class MindMapWidget extends TypeWidget { return; } - const svgContent = await this.mind.exportSvg().text(); + const svgContent = await this.renderSvg(); return { content: mind.getDataString(), attachments: [ @@ -98,9 +98,36 @@ export default class MindMapWidget extends TypeWidget { }; } + async renderSvg() { + return await this.mind.exportSvg().text(); + } + async entitiesReloadedEvent({loadResults}) { if (loadResults.isNoteReloaded(this.noteId)) { this.refresh(); } } + + async exportSvgEvent({ntxId}) { + if (!this.isNoteContext(ntxId)) { + return; + } + + const svg = await this.renderSvg(); + this.download(`${this.note.title}.svg`, svg); + } + + download(filename, text) { + const element = document.createElement('a'); + element.setAttribute('href', `data:image/svg+xml;charset=utf-8,${encodeURIComponent(text)}`); + element.setAttribute('download', filename); + + element.style.display = 'none'; + document.body.appendChild(element); + + element.click(); + + document.body.removeChild(element); + } + } \ No newline at end of file