Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable30] fix(editorApi): Add support for a onCreate callback that gets content #6278

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading