add selected prop for nodeviews
This commit is contained in:
@@ -406,6 +406,7 @@ export default class IframeNode extends Node {
|
|||||||
// `node` is a Prosemirror Node Object
|
// `node` is a Prosemirror Node Object
|
||||||
// `updateAttrs` is a function to update attributes defined in `schema`
|
// `updateAttrs` is a function to update attributes defined in `schema`
|
||||||
// `editable` is the global editor prop whether the content can be edited
|
// `editable` is the global editor prop whether the content can be edited
|
||||||
|
// `selected`
|
||||||
props: ['node', 'updateAttrs', 'editable'],
|
props: ['node', 'updateAttrs', 'editable'],
|
||||||
computed: {
|
computed: {
|
||||||
src: {
|
src: {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ export default class ComponentView {
|
|||||||
this.getPos = getPos
|
this.getPos = getPos
|
||||||
this.decorations = decorations
|
this.decorations = decorations
|
||||||
this.editable = editable
|
this.editable = editable
|
||||||
|
this.selected = false
|
||||||
|
|
||||||
this.dom = this.createDOM()
|
this.dom = this.createDOM()
|
||||||
this.contentDOM = this.vm.$refs.content
|
this.contentDOM = this.vm.$refs.content
|
||||||
@@ -34,6 +35,7 @@ export default class ComponentView {
|
|||||||
getPos: this.getPos,
|
getPos: this.getPos,
|
||||||
decorations: this.decorations,
|
decorations: this.decorations,
|
||||||
editable: this.editable,
|
editable: this.editable,
|
||||||
|
selected: false,
|
||||||
updateAttrs: attrs => this.updateAttrs(attrs),
|
updateAttrs: attrs => this.updateAttrs(attrs),
|
||||||
updateContent: content => this.updateContent(content),
|
updateContent: content => this.updateContent(content),
|
||||||
},
|
},
|
||||||
@@ -53,16 +55,27 @@ export default class ComponentView {
|
|||||||
this.node = node
|
this.node = node
|
||||||
this.decorations = decorations
|
this.decorations = decorations
|
||||||
|
|
||||||
|
this.updateComponentProps({
|
||||||
|
node,
|
||||||
|
decorations,
|
||||||
|
})
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
updateComponentProps(props) {
|
||||||
// Update props in component
|
// Update props in component
|
||||||
// TODO: Avoid mutating a prop directly.
|
// TODO: Avoid mutating a prop directly.
|
||||||
// Maybe there is a better way to do this?
|
// Maybe there is a better way to do this?
|
||||||
const originalSilent = Vue.config.silent
|
const originalSilent = Vue.config.silent
|
||||||
Vue.config.silent = true
|
Vue.config.silent = true
|
||||||
this.vm._props.node = node
|
|
||||||
this.vm._props.decorations = decorations
|
|
||||||
Vue.config.silent = originalSilent
|
|
||||||
|
|
||||||
return true
|
Object.entries(props).forEach(([key, value]) => {
|
||||||
|
this.vm._props[key] = value
|
||||||
|
})
|
||||||
|
// this.vm._props.node = node
|
||||||
|
// this.vm._props.decorations = decorations
|
||||||
|
Vue.config.silent = originalSilent
|
||||||
}
|
}
|
||||||
|
|
||||||
updateAttrs(attrs) {
|
updateAttrs(attrs) {
|
||||||
@@ -103,6 +116,18 @@ export default class ComponentView {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
selectNode() {
|
||||||
|
this.updateComponentProps({
|
||||||
|
selected: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
deselectNode() {
|
||||||
|
this.updateComponentProps({
|
||||||
|
selected: false,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
this.vm.$destroy()
|
this.vm.$destroy()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user