Skip to content

Commit d1cc458

Browse files
authored
Merge pull request #6278 from nextcloud/backport/6274/stable30
[stable30] fix(editorApi): Add support for a onCreate callback that gets content
2 parents 5881869 + 5a041fb commit d1cc458

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/components/Editor.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,10 @@ export default {
514514
session,
515515
onCreate: ({ editor }) => {
516516
this.$syncService.startSync()
517+
const proseMirrorMarkdown = this.$syncService.serialize(editor.state.doc)
518+
this.emit('create:content', {
519+
markdown: proseMirrorMarkdown,
520+
})
517521
},
518522
onUpdate: ({ editor }) => {
519523
// this.debugContent(editor)

src/editor.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ class TextEditorEmbed {
3636
return this.#vm.$children[0]
3737
}
3838

39+
onCreate(onCreateCallback = () => {}) {
40+
this.#vm.$on('create:content', (content) => {
41+
onCreateCallback(content)
42+
})
43+
return this
44+
}
45+
3946
onLoaded(onLoadedCallback = () => {}) {
4047
this.#vm.$on('ready', () => {
4148
onLoadedCallback()
@@ -153,6 +160,7 @@ window.OCA.Text.createEditor = async function({
153160
props: null,
154161
},
155162

163+
onCreate = ({ markdown }) => {},
156164
onLoaded = () => {},
157165
onUpdate = ({ markdown }) => {},
158166
onOutlineToggle = (visible) => {},
@@ -231,6 +239,7 @@ window.OCA.Text.createEditor = async function({
231239
store,
232240
})
233241
return new TextEditorEmbed(vm, data)
242+
.onCreate(onCreate)
234243
.onLoaded(onLoaded)
235244
.onUpdate(onUpdate)
236245
.onOutlineToggle(onOutlineToggle)

0 commit comments

Comments
 (0)