improve node views

This commit is contained in:
Philipp Kühn
2020-11-25 22:11:17 +01:00
parent c8fa3cc29d
commit b5ba3fd3eb
2 changed files with 29 additions and 27 deletions

View File

@@ -10,27 +10,6 @@
</node-view-wrapper>
</template>
<script>
export default {
props: {
editor: {
type: Object,
required: true,
},
node: {
type: Object,
required: true,
},
updateAttributes: {
type: Function,
required: true,
},
},
}
</script>
<style lang="scss" scoped>
.draggable-item {
display: flex;

View File

@@ -132,11 +132,15 @@ class VueNodeView implements NodeView {
})
const props = {
editor: this.editor,
NodeViewWrapper,
NodeViewContent,
editor: this.editor,
node: this.node,
updateAttributes: (attrs: {}) => this.updateAttributes(attrs),
decorations: this.decorations,
selected: false,
extension: this.extension,
getPos: () => this.getPos(),
updateAttributes: (attributes = {}) => this.updateAttributes(attributes),
}
this.vm = new Component({
@@ -242,14 +246,21 @@ class VueNodeView implements NodeView {
this.node = node
this.decorations = decorations
this.updateComponentProps()
this.updateComponentProps({ node, decorations })
return true
}
updateComponentProps() {
this.vm.$props.node = this.node
this.vm.$props.decorations = this.decorations
updateComponentProps(data: { [key: string]: any } = {}) {
if (!this.vm.$props) {
return
}
Object
.entries(data)
.forEach(([key, value]) => {
this.vm.$props[key] = value
})
}
updateAttributes(attributes: {}) {
@@ -267,6 +278,18 @@ class VueNodeView implements NodeView {
this.editor.view.dispatch(transaction)
}
selectNode() {
this.updateComponentProps({
selected: true,
})
}
deselectNode() {
this.updateComponentProps({
selected: false,
})
}
}
export default function VueRenderer(component: Vue | VueConstructor, options?: Partial<VueRendererOptions>) {