pass extension to component view
This commit is contained in:
@@ -2,6 +2,7 @@ import Vue from 'vue'
|
||||
|
||||
export default class ComponentView {
|
||||
constructor(component, {
|
||||
extension,
|
||||
parent,
|
||||
node,
|
||||
view,
|
||||
@@ -9,6 +10,7 @@ export default class ComponentView {
|
||||
decorations,
|
||||
editable,
|
||||
}) {
|
||||
this.extension = extension
|
||||
this.parent = parent
|
||||
this.component = component
|
||||
this.node = node
|
||||
@@ -63,11 +65,14 @@ export default class ComponentView {
|
||||
return true
|
||||
}
|
||||
|
||||
stopEvent(event) {
|
||||
// TODO: find a way to pass full extensions to ComponentView
|
||||
// so we could check for schema.draggable
|
||||
// for now we're allowing all drag events for node views
|
||||
return !/drag/.test(event.type)
|
||||
stopEvent() {
|
||||
const draggable = !!this.extension.schema.draggable
|
||||
|
||||
if (draggable) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
update(node, decorations) {
|
||||
|
||||
@@ -42,7 +42,6 @@ export default class Editor {
|
||||
this.extensions = this.createExtensions()
|
||||
this.nodes = this.createNodes()
|
||||
this.marks = this.createMarks()
|
||||
this.views = this.createViews()
|
||||
this.schema = this.createSchema()
|
||||
this.plugins = this.createPlugins()
|
||||
this.keymaps = this.createKeymaps()
|
||||
@@ -93,10 +92,6 @@ export default class Editor {
|
||||
return this.extensions.marks
|
||||
}
|
||||
|
||||
createViews() {
|
||||
return this.extensions.views
|
||||
}
|
||||
|
||||
createSchema() {
|
||||
return new Schema({
|
||||
nodes: this.nodes,
|
||||
@@ -146,7 +141,10 @@ export default class Editor {
|
||||
state: this.state,
|
||||
dispatchTransaction: this.dispatchTransaction.bind(this),
|
||||
nodeViews: initNodeViews({
|
||||
nodes: this.views,
|
||||
extensions: [
|
||||
...builtInNodes,
|
||||
...this.options.extensions,
|
||||
],
|
||||
editable: this.options.editable,
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -33,16 +33,6 @@ export default class ExtensionManager {
|
||||
]), [])
|
||||
}
|
||||
|
||||
get views() {
|
||||
return this.extensions
|
||||
.filter(extension => ['node', 'mark'].includes(extension.type))
|
||||
.filter(extension => extension.view)
|
||||
.reduce((views, { name, view }) => ({
|
||||
...views,
|
||||
[name]: view,
|
||||
}), {})
|
||||
}
|
||||
|
||||
keymaps({ schema }) {
|
||||
const extensionKeymaps = this.extensions
|
||||
.filter(extension => ['extension'].includes(extension.type))
|
||||
|
||||
@@ -1,22 +1,27 @@
|
||||
import ComponentView from './ComponentView'
|
||||
|
||||
export default function initNodeViews({ parent, nodes, editable }) {
|
||||
const nodeViews = {}
|
||||
export default function initNodeViews({ parent, extensions, editable }) {
|
||||
return extensions
|
||||
.filter(extension => ['node', 'mark'].includes(extension.type))
|
||||
.filter(extension => extension.view)
|
||||
.reduce((nodeViews, extension) => {
|
||||
const nodeView = (node, view, getPos, decorations) => {
|
||||
const component = extension.view
|
||||
|
||||
Object.keys(nodes).forEach(nodeName => {
|
||||
nodeViews[nodeName] = (node, view, getPos, decorations) => {
|
||||
const component = nodes[nodeName]
|
||||
return new ComponentView(component, {
|
||||
extension,
|
||||
parent,
|
||||
node,
|
||||
view,
|
||||
getPos,
|
||||
decorations,
|
||||
editable,
|
||||
})
|
||||
}
|
||||
|
||||
return new ComponentView(component, {
|
||||
parent,
|
||||
node,
|
||||
view,
|
||||
getPos,
|
||||
decorations,
|
||||
editable,
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
return nodeViews
|
||||
return {
|
||||
...nodeViews,
|
||||
[extension.name]: nodeView,
|
||||
}
|
||||
}, {})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user