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> </node-view-wrapper>
</template> </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> <style lang="scss" scoped>
.draggable-item { .draggable-item {
display: flex; display: flex;

View File

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