mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
client: Implement SVG export button for mindmap
This commit is contained in:
parent
27a287f8ea
commit
61e0678af4
@ -3,7 +3,7 @@ import NoteContextAwareWidget from "../note_context_aware_widget.js";
|
|||||||
|
|
||||||
const TPL = `
|
const TPL = `
|
||||||
<button type="button"
|
<button type="button"
|
||||||
class="export-mermaid-button"
|
class="export-svg-button"
|
||||||
title="${t('svg_export_button.button_title')}">
|
title="${t('svg_export_button.button_title')}">
|
||||||
<span class="bx bx-export"></span>
|
<span class="bx bx-export"></span>
|
||||||
</button>
|
</button>
|
||||||
@ -12,7 +12,7 @@ const TPL = `
|
|||||||
export default class SvgExportButton extends NoteContextAwareWidget {
|
export default class SvgExportButton extends NoteContextAwareWidget {
|
||||||
isEnabled() {
|
isEnabled() {
|
||||||
return super.isEnabled()
|
return super.isEnabled()
|
||||||
&& this.note?.type === 'mermaid'
|
&& [ "mermaid", "mindMap" ].includes(this.note?.type)
|
||||||
&& this.note.isContentAvailable()
|
&& this.note.isContentAvailable()
|
||||||
&& this.noteContext?.viewScope.viewMode === 'default';
|
&& this.noteContext?.viewScope.viewMode === 'default';
|
||||||
}
|
}
|
||||||
@ -21,7 +21,7 @@ export default class SvgExportButton extends NoteContextAwareWidget {
|
|||||||
super.doRender();
|
super.doRender();
|
||||||
|
|
||||||
this.$widget = $(TPL);
|
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();
|
this.contentSized();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ export default class MermaidWidget extends NoteContextAwareWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async exportMermaidEvent({ntxId}) {
|
async exportSvgEvent({ntxId}) {
|
||||||
if (!this.isNoteContext(ntxId)) {
|
if (!this.isNoteContext(ntxId)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ export default class MindMapWidget extends TypeWidget {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const svgContent = await this.mind.exportSvg().text();
|
const svgContent = await this.renderSvg();
|
||||||
return {
|
return {
|
||||||
content: mind.getDataString(),
|
content: mind.getDataString(),
|
||||||
attachments: [
|
attachments: [
|
||||||
@ -98,9 +98,36 @@ export default class MindMapWidget extends TypeWidget {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async renderSvg() {
|
||||||
|
return await this.mind.exportSvg().text();
|
||||||
|
}
|
||||||
|
|
||||||
async entitiesReloadedEvent({loadResults}) {
|
async entitiesReloadedEvent({loadResults}) {
|
||||||
if (loadResults.isNoteReloaded(this.noteId)) {
|
if (loadResults.isNoteReloaded(this.noteId)) {
|
||||||
this.refresh();
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user