chore(react/type_widget): save mindmap attachment

This commit is contained in:
Elian Doran 2025-09-21 09:26:44 +03:00
parent 3417e37f16
commit 7d99a92bd9
No known key found for this signature in database
2 changed files with 15 additions and 22 deletions

View File

@ -25,7 +25,21 @@ export default function MindMap({ note }: TypeWidgetProps) {
const apiRef = useRef<MindElixirInstance>(null); const apiRef = useRef<MindElixirInstance>(null);
const spacedUpdate = useEditorSpacedUpdate({ const spacedUpdate = useEditorSpacedUpdate({
note, note,
getData: () => ({ content: apiRef.current?.getDataString() }), getData: () => {
if (!apiRef.current) return;
return {
content: apiRef.current.getDataString(),
attachments: [
{
role: "image",
title: "mindmap-export.svg",
mime: "image/svg+xml",
content: apiRef.current.exportSvg().text(),
position: 0
}
]
}
},
onContentChange: (content) => { onContentChange: (content) => {
let newContent: MindElixirData; let newContent: MindElixirData;
if (content) { if (content) {

View File

@ -48,27 +48,6 @@ export default class MindMapWidget extends TypeWidget {
this.mind = mind; this.mind = mind;
} }
async getData() {
const mind = this.mind;
if (!mind) {
return;
}
const svgContent = await this.renderSvg();
return {
content: mind.getDataString(),
attachments: [
{
role: "image",
title: "mindmap-export.svg",
mime: "image/svg+xml",
content: svgContent,
position: 0
}
]
};
}
async renderSvg() { async renderSvg() {
return await this.mind!.exportSvg().text(); return await this.mind!.exportSvg().text();
} }