From d529e39a5ced6c33061ba1f6182b229de2a967a7 Mon Sep 17 00:00:00 2001 From: Jonas Date: Thu, 14 Mar 2024 18:49:01 +0100 Subject: [PATCH] fix(MarkdownContentEditor): Respect `onLoaded` callback passed via API Emit `ready` once the editor is ready (Tiptap `create` event), which causes the `onLoaded` callback passed via editor API to be called Signed-off-by: Jonas --- .../Editor/MarkdownContentEditor.vue | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/components/Editor/MarkdownContentEditor.vue b/src/components/Editor/MarkdownContentEditor.vue index cfeb7982248..de2db6d4969 100644 --- a/src/components/Editor/MarkdownContentEditor.vue +++ b/src/components/Editor/MarkdownContentEditor.vue @@ -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') + } }) }, @@ -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) }, }, }