fix adding decoration classes to node views in vue
This commit is contained in:
@@ -8,11 +8,13 @@ export const NodeViewWrapper = Vue.extend({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
inject: ['onDragStart'],
|
inject: ['onDragStart', 'decorationClasses'],
|
||||||
|
|
||||||
render(createElement) {
|
render(createElement) {
|
||||||
return createElement(
|
return createElement(
|
||||||
this.as, {
|
this.as, {
|
||||||
|
// @ts-ignore
|
||||||
|
class: this.decorationClasses.value,
|
||||||
style: {
|
style: {
|
||||||
whiteSpace: 'normal',
|
whiteSpace: 'normal',
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -51,6 +51,10 @@ class VueNodeView extends NodeView<(Vue | VueConstructor), Editor> {
|
|||||||
|
|
||||||
renderer!: VueRenderer
|
renderer!: VueRenderer
|
||||||
|
|
||||||
|
decorationClasses!: {
|
||||||
|
value: string
|
||||||
|
}
|
||||||
|
|
||||||
mount() {
|
mount() {
|
||||||
const props: NodeViewProps = {
|
const props: NodeViewProps = {
|
||||||
editor: this.editor,
|
editor: this.editor,
|
||||||
@@ -71,14 +75,19 @@ class VueNodeView extends NodeView<(Vue | VueConstructor), Editor> {
|
|||||||
isEditable.value = this.editor.isEditable
|
isEditable.value = this.editor.isEditable
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.decorationClasses = Vue.observable({
|
||||||
|
value: this.getDecorationClasses(),
|
||||||
|
})
|
||||||
|
|
||||||
const Component = Vue
|
const Component = Vue
|
||||||
.extend(this.component)
|
.extend(this.component)
|
||||||
.extend({
|
.extend({
|
||||||
props: Object.keys(props),
|
props: Object.keys(props),
|
||||||
provide() {
|
provide: () => {
|
||||||
return {
|
return {
|
||||||
onDragStart,
|
onDragStart,
|
||||||
isEditable,
|
isEditable,
|
||||||
|
decorationClasses: this.decorationClasses,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -122,6 +131,7 @@ class VueNodeView extends NodeView<(Vue | VueConstructor), Editor> {
|
|||||||
|
|
||||||
this.node = node
|
this.node = node
|
||||||
this.decorations = decorations
|
this.decorations = decorations
|
||||||
|
this.decorationClasses.value = this.getDecorationClasses()
|
||||||
this.renderer.updateProps({ node, decorations })
|
this.renderer.updateProps({ node, decorations })
|
||||||
|
|
||||||
return true
|
return true
|
||||||
@@ -139,6 +149,14 @@ class VueNodeView extends NodeView<(Vue | VueConstructor), Editor> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getDecorationClasses() {
|
||||||
|
return this.decorations
|
||||||
|
// @ts-ignore
|
||||||
|
.map(item => item.type.attrs.class)
|
||||||
|
.flat()
|
||||||
|
.join(' ')
|
||||||
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
this.renderer.destroy()
|
this.renderer.destroy()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,11 +8,13 @@ export const NodeViewWrapper = defineComponent({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
inject: ['onDragStart'],
|
inject: ['onDragStart', 'decorationClasses'],
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return h(
|
return h(
|
||||||
this.as, {
|
this.as, {
|
||||||
|
// @ts-ignore
|
||||||
|
class: this.decorationClasses.value,
|
||||||
style: {
|
style: {
|
||||||
whiteSpace: 'normal',
|
whiteSpace: 'normal',
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
} from '@tiptap/core'
|
} from '@tiptap/core'
|
||||||
import {
|
import {
|
||||||
ref,
|
ref,
|
||||||
|
Ref,
|
||||||
provide,
|
provide,
|
||||||
PropType,
|
PropType,
|
||||||
Component,
|
Component,
|
||||||
@@ -56,6 +57,8 @@ class VueNodeView extends NodeView<Component, Editor> {
|
|||||||
|
|
||||||
renderer!: VueRenderer
|
renderer!: VueRenderer
|
||||||
|
|
||||||
|
decorationClasses!: Ref<string>
|
||||||
|
|
||||||
mount() {
|
mount() {
|
||||||
const props: NodeViewProps = {
|
const props: NodeViewProps = {
|
||||||
editor: this.editor,
|
editor: this.editor,
|
||||||
@@ -74,12 +77,15 @@ class VueNodeView extends NodeView<Component, Editor> {
|
|||||||
isEditable.value = this.editor.isEditable
|
isEditable.value = this.editor.isEditable
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.decorationClasses = ref(this.getDecorationClasses())
|
||||||
|
|
||||||
const extendedComponent = defineComponent({
|
const extendedComponent = defineComponent({
|
||||||
extends: { ...this.component },
|
extends: { ...this.component },
|
||||||
props: Object.keys(props),
|
props: Object.keys(props),
|
||||||
setup: () => {
|
setup: () => {
|
||||||
provide('onDragStart', onDragStart)
|
provide('onDragStart', onDragStart)
|
||||||
provide('isEditable', isEditable)
|
provide('isEditable', isEditable)
|
||||||
|
provide('decorationClasses', this.decorationClasses)
|
||||||
|
|
||||||
return (this.component as any).setup?.(props)
|
return (this.component as any).setup?.(props)
|
||||||
},
|
},
|
||||||
@@ -124,6 +130,7 @@ class VueNodeView extends NodeView<Component, Editor> {
|
|||||||
|
|
||||||
this.node = node
|
this.node = node
|
||||||
this.decorations = decorations
|
this.decorations = decorations
|
||||||
|
this.decorationClasses.value = this.getDecorationClasses()
|
||||||
this.renderer.updateProps({ node, decorations })
|
this.renderer.updateProps({ node, decorations })
|
||||||
|
|
||||||
return true
|
return true
|
||||||
@@ -141,6 +148,14 @@ class VueNodeView extends NodeView<Component, Editor> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getDecorationClasses() {
|
||||||
|
return this.decorations
|
||||||
|
// @ts-ignore
|
||||||
|
.map(item => item.type.attrs.class)
|
||||||
|
.flat()
|
||||||
|
.join(' ')
|
||||||
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
this.renderer.destroy()
|
this.renderer.destroy()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user