Skip to content

Commit

Permalink
Merge pull request #6276 from nextcloud/backport/6274/stable28
Browse files Browse the repository at this point in the history
[stable28] fix(editorApi): Add support for a onCreate callback that gets content
  • Loading branch information
mejo- authored Aug 28, 2024
2 parents 2c9273e + 789b8a4 commit beb2570
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 @@ -52,6 +52,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 @@ -149,6 +156,7 @@ window.OCA.Text.createEditor = async function({
props: null,
},

onCreate = ({ markdown }) => {},
onLoaded = () => {},
onUpdate = ({ markdown }) => {},
onOutlineToggle = (visible) => {},
Expand Down Expand Up @@ -228,6 +236,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 beb2570

Please sign in to comment.