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

fix(viewer): share Vue constructor from Viewer #5402

Merged
merged 1 commit into from
Feb 21, 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
16 changes: 16 additions & 0 deletions src/ViewerVue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @type {import('Vue').VueConstructor|null}
*/
let ViewerVue = null

/**
* @param {import('Vue').VueConstructor} VueConstructor - Vue constructor from Viewer
*/
export const setViewerVue = (VueConstructor) => {
ViewerVue = VueConstructor
}

/**
* @return {import('Vue').VueConstructor|null}
*/
export const getViewerVue = () => ViewerVue
10 changes: 10 additions & 0 deletions src/components/ViewerComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ import RichTextReader from './RichTextReader.vue'
import { getSharingToken } from '../helpers/token.js'
import getEditorInstance from './Editor.singleton.js'

import { setViewerVue } from '../ViewerVue.js'

export default {
name: 'ViewerComponent',
components: {
Expand Down Expand Up @@ -113,6 +115,14 @@ export default {
},
},

beforeCreate() {
// This component is rendered in the Viewer app
// Get Vue constructor from the Viewer app
// To reuse later as Vue constructor and not mix Text's Vue constructor and Viewer's Vue constructor in a single Virtual DOM
// Which is not fully supported by Vue
setViewerVue(this.$options._base)
},

mounted() {
this.loadFileContent()
},
Expand Down
8 changes: 7 additions & 1 deletion src/extensions/LinkBubblePluginView.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import tippy from 'tippy.js'
import { domHref } from '../helpers/links.js'
import LinkBubbleView from '../components/Link/LinkBubbleView.vue'

import { getViewerVue } from '../ViewerVue.js'

const updateDelay = 250

class LinkBubblePluginView {
Expand All @@ -16,7 +18,11 @@ class LinkBubblePluginView {
this.editor = editor
this.view = view

this.#component = new VueRenderer(LinkBubbleView, {
// When editor is used in Viewer component, it should render comopnent using Viewer's Vue constructor,
// Otherwise there are VNodes with different Vue constructors in a single Virtual DOM which is not fully supported by Vue
const ViewerVue = getViewerVue()
const LinkBubbleViewConstructor = ViewerVue ? ViewerVue.extend(LinkBubbleView) : LinkBubbleView
this.#component = new VueRenderer(LinkBubbleViewConstructor, {
parent: this.editor.contentComponent,
propsData: {
editor: this.editor,
Expand Down
Loading