Skip to content

Commit

Permalink
Merge pull request #5489 from nextcloud/fix/content_editor_onloaded
Browse files Browse the repository at this point in the history
fix(MarkdownContentEditor): Respect `onLoaded` callback passed via API
  • Loading branch information
mejo- authored Mar 19, 2024
2 parents 08ccd25 + d529e39 commit 1da385d
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/components/Editor/MarkdownContentEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,15 @@ export default {
extensions: this.extensions(),
onUpdate: ({ editor }) => {
const markdown = (createMarkdownSerializer(this.$editor.schema)).serialize(editor.state.doc)
this.$root.$emit('update:content', {
this.emit('update:content', {
json: editor.state.doc,
markdown,
})
},
onCreate: ({ editor }) => {
this.$emit('ready')
this.$parent.$emit('ready')
}
})
},

Expand All @@ -160,8 +164,24 @@ export default {
},

outlineToggled(visible) {
this.$emit('outline-toggled', visible)
this.$parent.$emit('outline-toggled', visible)
this.emit('outline-toggled', visible)
},

/**
* Wrapper to emit events on our own and the parent component
*
* The parent might be either the root component of src/editor.js or Viewer.vue which collectives currently uses
*
* Ideally this would be done in a generic way in the src/editor.js API abstraction, but it seems
* that there is no proper way to pass any received event along in vue, the only option I've found
* in https://github.com/vuejs/vue/issues/230 feels too hacky to me, so we just emit twice for now
*
* @param {string} event The event name
* @param {any} data The data to pass along
*/
emit(event, data) {
this.$emit(event, data)
this.$parent?.$emit(event, data)
},
},
}
Expand Down

0 comments on commit 1da385d

Please sign in to comment.