2021-02-28 06:56:08 +08:00
|
|
|
import Vue from 'vue'
|
2021-03-15 16:00:44 +08:00
|
|
|
import { AnyObject } from '@tiptap/core'
|
2021-02-28 06:56:08 +08:00
|
|
|
import { VueConstructor } from 'vue/types/umd'
|
|
|
|
|
2021-03-01 06:24:26 +08:00
|
|
|
export class VueRenderer {
|
2021-03-15 16:00:44 +08:00
|
|
|
ref!: Vue
|
2021-02-28 06:56:08 +08:00
|
|
|
|
|
|
|
constructor(component: Vue | VueConstructor, props: any) {
|
|
|
|
const Component = Vue.extend(component)
|
|
|
|
|
2021-03-15 16:00:44 +08:00
|
|
|
this.ref = new Component(props).$mount()
|
2021-02-28 06:56:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
get element() {
|
2021-03-15 16:00:44 +08:00
|
|
|
return this.ref.$el
|
2021-02-28 06:56:08 +08:00
|
|
|
}
|
|
|
|
|
2021-03-15 16:00:44 +08:00
|
|
|
updateProps(props: AnyObject = {}) {
|
|
|
|
if (!this.ref.$props) {
|
2021-02-28 06:56:08 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// prevents `Avoid mutating a prop directly` error message
|
|
|
|
const originalSilent = Vue.config.silent
|
|
|
|
Vue.config.silent = true
|
|
|
|
|
|
|
|
Object
|
|
|
|
.entries(props)
|
|
|
|
.forEach(([key, value]) => {
|
2021-03-15 16:00:44 +08:00
|
|
|
this.ref.$props[key] = value
|
2021-02-28 06:56:08 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
Vue.config.silent = originalSilent
|
|
|
|
}
|
|
|
|
|
|
|
|
destroy() {
|
2021-03-15 16:00:44 +08:00
|
|
|
this.ref.$destroy()
|
2021-02-28 06:56:08 +08:00
|
|
|
}
|
|
|
|
}
|