diff --git a/src/export.ts b/src/export.ts index 02dfe5a..ad0693c 100644 --- a/src/export.ts +++ b/src/export.ts @@ -37,11 +37,30 @@ export default class Export extends Plugin { // } ); // Insert a text into the editor after clicking the button. - this.listenTo( view, 'execute', async () => { - asBlob(this.editor.getData()).then((data: any) => { - saveAs(data, 'file.docx') // save as docx file - }) // asBlob() return Promise + // this.listenTo( view, 'execute', async () => { + // asBlob(this.editor.getData()).then((data: any) => { + // saveAs(data, 'file.docx') // save as docx file + // }) // asBlob() return Promise + // editor.editing.view.focus(); + // } ); + + // POST fetch docx and download + this.listenTo( view, 'execute', async () => { + fetch('http://localhost:3000/docx', { + method: 'POST', + body: JSON.stringify({ htmlData: this.editor.getData() }), + headers: { + 'Content-Type': 'application/json' + } + }) + .then(response => response.blob()) + .then(blob => { + saveAs(blob, 'stou.docx') // save as docx file + }) + .catch(error => { + console.error('Error:', error); + }); editor.editing.view.focus(); } );