refactoring

This commit is contained in:
Philipp Kühn
2021-01-18 13:06:56 +01:00
parent f96dff1f0f
commit 9651958ac4
4 changed files with 76 additions and 23 deletions

View File

@@ -0,0 +1,41 @@
import Vue from 'vue'
import { VueConstructor } from 'vue/types/umd'
export default class VueRenderer {
vm!: Vue
constructor(component: Vue | VueConstructor, props: any) {
const Component = Vue.extend(component)
this.vm = new Component({
// parent,
propsData: props,
}).$mount()
}
get element() {
return this.vm.$el
}
update(data: { [key: string]: any } = {}) {
if (!this.vm.$props) {
return
}
// prevents `Avoid mutating a prop directly` error message
const originalSilent = Vue.config.silent
Vue.config.silent = true
Object
.entries(data)
.forEach(([key, value]) => {
this.vm.$props[key] = value
})
Vue.config.silent = originalSilent
}
destroy() {
this.vm.$destroy()
}
}

View File

@@ -1,3 +1,4 @@
export * from '@tiptap/core'
export { default as VueRenderer } from './VueRenderer'
export { default as VueNodeViewRenderer } from './VueNodeViewRenderer'
export { default as EditorContent } from './components/EditorContent'