Skip to content

Commit

Permalink
Merge pull request #6278 from nextcloud/backport/6274/stable30
Browse files Browse the repository at this point in the history
[stable30] fix(editorApi): Add support for a onCreate callback that gets content
  • Loading branch information
juliusknorr authored Aug 28, 2024
2 parents 5881869 + 5a041fb commit d1cc458
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -153,6 +160,7 @@ window.OCA.Text.createEditor = async function({
props: null,
},

onCreate = ({ markdown }) => {},
onLoaded = () => {},
onUpdate = ({ markdown }) => {},
onOutlineToggle = (visible) => {},
Expand Down Expand Up @@ -231,6 +239,7 @@ window.OCA.Text.createEditor = async function({
store,
})
return new TextEditorEmbed(vm, data)
.onCreate(onCreate)
.onLoaded(onLoaded)
.onUpdate(onUpdate)
.onOutlineToggle(onOutlineToggle)
Expand Down

0 comments on commit d1cc458

Please sign in to comment.