@@ -316,7 +316,7 @@ export default {
316316 }
317317 subscribe (' text:image-node:add' , this .onAddImageNode )
318318 subscribe (' text:image-node:delete' , this .onDeleteImageNode )
319- this .$parent ? . $ emit (' update:loaded' , true )
319+ this .emit (' update:loaded' , true )
320320 },
321321 created () {
322322 this .$ydoc = new Doc ()
@@ -358,7 +358,7 @@ export default {
358358
359359 initSession () {
360360 if (! this .hasDocumentParameters ) {
361- this .$parent ? . $ emit (' error' , ' No valid file provided' )
361+ this .emit (' error' , ' No valid file provided' )
362362 return
363363 }
364364 const guestName = localStorage .getItem (' nick' ) ? localStorage .getItem (' nick' ) : ' '
@@ -500,7 +500,7 @@ export default {
500500 onUpdate : ({ editor }) => {
501501 // this.debugContent(editor)
502502 const proseMirrorMarkdown = this .$syncService .serialize (editor .state .doc )
503- this .$parent . $ emit (' update:content' , {
503+ this .emit (' update:content' , {
504504 markdown: proseMirrorMarkdown,
505505 })
506506 },
@@ -559,15 +559,15 @@ export default {
559559 onSync ({ steps, document }) {
560560 this .hasConnectionIssue = false
561561 this .$nextTick (() => {
562- this .$ emit (' sync-service:sync' )
562+ this .emit (' sync-service:sync' )
563563 })
564564 this .document = document
565565 },
566566
567567 onError ({ type, data }) {
568568 this .$nextTick (() => {
569569 this .$editor ? .setEditable (false )
570- this .$ emit (' sync-service:error' )
570+ this .emit (' sync-service:error' )
571571 })
572572
573573 if (type === ERROR_TYPE .LOAD_ERROR ) {
@@ -596,8 +596,7 @@ export default {
596596 this .hasConnectionIssue = true
597597 }
598598
599- this .$emit (' ready' )
600- this .$parent ? .$emit (' ready' )
599+ this .emit (' ready' )
601600 },
602601
603602 onStateChange (state ) {
@@ -608,8 +607,7 @@ export default {
608607 this .$editor .commands .focus ()
609608 })
610609 }
611- this .$emit (' ready' )
612- this .$parent ? .$emit (' ready' , true )
610+ this .emit (' ready' )
613611 }
614612 if (Object .prototype .hasOwnProperty .call (state, ' dirty' )) {
615613 // ignore initial loading and other automated changes
@@ -631,30 +629,30 @@ export default {
631629 this .$editor .setOptions ({ editable: ! this .readOnly })
632630
633631 this .$nextTick (() => {
634- this .$ emit (' sync-service:idle' )
632+ this .emit (' sync-service:idle' )
635633 })
636634 },
637635
638636 onSave () {
639637 emit (' files:file:updated' , { fileid: this .fileId })
640638 this .$nextTick (() => {
641- this .$ emit (' sync-service:save' )
639+ this .emit (' sync-service:save' )
642640 })
643641 },
644642
645643 onFocus () {
646- this .$ emit (' focus' )
644+ this .emit (' focus' )
647645 },
648646 onBlur () {
649- this .$ emit (' blur' )
647+ this .emit (' blur' )
650648 },
651649
652650 onAddImageNode () {
653- this .$parent . $ emit (' add-image-node' )
651+ this .emit (' add-image-node' )
654652 },
655653
656654 onDeleteImageNode (imageUrl ) {
657- this .$parent . $ emit (' delete-image-node' , imageUrl)
655+ this .emit (' delete-image-node' , imageUrl)
658656 },
659657
660658 async close () {
@@ -681,6 +679,23 @@ export default {
681679 return true
682680 },
683681
682+ /**
683+ * Wrapper to emit events on our own and the parent component
684+ *
685+ * The parent might be either the root component of src/editor.js or Viewer.vue which collectives currently uses
686+ *
687+ * Ideally this would be done in a generic way in the src/editor.js API abstraction, but it seems
688+ * that there is no proper way to pass any received event along in vue, the only option I've found
689+ * in https://github.com/vuejs/vue/issues/230 feels too hacky to me, so we just emit twice for now
690+ *
691+ * @param {string} event The event name
692+ * @param {any} data The data to pass along
693+ */
694+ emit (event , data ) {
695+ this .$emit (event , data)
696+ this .$parent ? .$emit (event , true )
697+ },
698+
684699 /** @param {Event} event The passed event */
685700 preparePrinting (event ) {
686701 const content = document .getElementById (' content' )
@@ -710,7 +725,7 @@ export default {
710725 },
711726
712727 outlineToggled (visible ) {
713- this .$parent ? . $ emit (' outline-toggled' , visible)
728+ this .emit (' outline-toggled' , visible)
714729 },
715730 },
716731}
0 commit comments