diff --git a/src/components/Editor.vue b/src/components/Editor.vue index 21ef52c8f60..b9847f8ab00 100644 --- a/src/components/Editor.vue +++ b/src/components/Editor.vue @@ -514,6 +514,10 @@ export default { session, onCreate: ({ editor }) => { this.$syncService.startSync() + const proseMirrorMarkdown = this.$syncService.serialize(editor.state.doc) + this.emit('create:content', { + markdown: proseMirrorMarkdown, + }) }, onUpdate: ({ editor }) => { // this.debugContent(editor) diff --git a/src/editor.js b/src/editor.js index 19e06b47619..bf699d2702f 100644 --- a/src/editor.js +++ b/src/editor.js @@ -36,6 +36,13 @@ class TextEditorEmbed { return this.#vm.$children[0] } + onCreate(onCreateCallback = () => {}) { + this.#vm.$on('create:content', (content) => { + onCreateCallback(content) + }) + return this + } + onLoaded(onLoadedCallback = () => {}) { this.#vm.$on('ready', () => { onLoadedCallback() @@ -153,6 +160,7 @@ window.OCA.Text.createEditor = async function({ props: null, }, + onCreate = ({ markdown }) => {}, onLoaded = () => {}, onUpdate = ({ markdown }) => {}, onOutlineToggle = (visible) => {}, @@ -231,6 +239,7 @@ window.OCA.Text.createEditor = async function({ store, }) return new TextEditorEmbed(vm, data) + .onCreate(onCreate) .onLoaded(onLoaded) .onUpdate(onUpdate) .onOutlineToggle(onOutlineToggle)