Skip to content

Commit

Permalink
fix(editorApi): Add support for a onCreate callback that gets content
Browse files Browse the repository at this point in the history
Required for Collectives to update the reader content with editor
content on initial load (i.e. before first editor update happens).

Signed-off-by: Jonas <[email protected]>
  • Loading branch information
mejo- committed Aug 28, 2024
1 parent f5e75fa commit 0d3166c
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 0d3166c

Please sign in to comment.