remove editable prop, fix #223

This commit is contained in:
Philipp Kühn 2019-05-21 21:22:15 +02:00
parent de624c1d5f
commit 5c81cddff9
5 changed files with 28 additions and 31 deletions

View File

@ -417,10 +417,10 @@ export default class IframeNode extends Node {
// there are some props available // there are some props available
// `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 // `view` is the ProseMirror view instance
// `options` is an array of your extension options // `options` is an array of your extension options
// `selected` // `selected`
props: ['node', 'updateAttrs', 'editable'], props: ['node', 'updateAttrs', 'view'],
computed: { computed: {
src: { src: {
get() { get() {
@ -437,7 +437,7 @@ export default class IframeNode extends Node {
template: ` template: `
<div class="iframe"> <div class="iframe">
<iframe class="iframe__embed" :src="src"></iframe> <iframe class="iframe__embed" :src="src"></iframe>
<input class="iframe__input" type="text" v-model="src" v-if="editable" /> <input class="iframe__input" type="text" v-model="src" v-if="view.editable" />
</div> </div>
`, `,
} }

View File

@ -15,7 +15,7 @@ export default class TodoItem extends Node {
get view() { get view() {
return { return {
props: ['node', 'updateAttrs', 'editable'], props: ['node', 'updateAttrs', 'view'],
methods: { methods: {
onChange() { onChange() {
this.updateAttrs({ this.updateAttrs({
@ -26,7 +26,7 @@ export default class TodoItem extends Node {
template: ` template: `
<li :data-type="node.type.name" :data-done="node.attrs.done.toString()"> <li :data-type="node.type.name" :data-done="node.attrs.done.toString()">
<span class="todo-checkbox" contenteditable="false" @click="onChange"></span> <span class="todo-checkbox" contenteditable="false" @click="onChange"></span>
<div class="todo-content" ref="content" :contenteditable="editable.toString()"></div> <div class="todo-content" ref="content" :contenteditable="view.editable.toString()"></div>
</li> </li>
`, `,
} }

View File

@ -156,7 +156,6 @@ export default class Editor extends Emitter {
return this.extensions.commands({ return this.extensions.commands({
schema: this.schema, schema: this.schema,
view: this.view, view: this.view,
editable: this.options.editable,
}) })
} }
@ -277,12 +276,11 @@ export default class Editor extends Emitter {
...this.builtInExtensions, ...this.builtInExtensions,
...this.options.extensions, ...this.options.extensions,
], ],
editable: this.options.editable,
}), }),
}) })
} }
initNodeViews({ parent, extensions, editable }) { initNodeViews({ parent, extensions }) {
return extensions return extensions
.filter(extension => ['node', 'mark'].includes(extension.type)) .filter(extension => ['node', 'mark'].includes(extension.type))
.filter(extension => extension.view) .filter(extension => extension.view)
@ -291,13 +289,13 @@ export default class Editor extends Emitter {
const component = extension.view const component = extension.view
return new ComponentView(component, { return new ComponentView(component, {
editor: this,
extension, extension,
parent, parent,
node, node,
view, view,
getPos, getPos,
decorations, decorations,
editable,
}) })
} }

View File

@ -5,48 +5,46 @@ import { getMarkRange } from 'tiptap-utils'
export default class ComponentView { export default class ComponentView {
constructor(component, { constructor(component, {
editor,
extension, extension,
parent, parent,
node, node,
view, view,
getPos,
decorations, decorations,
editable, getPos,
}) { }) {
this.component = component this.component = component
this.editor = editor
this.extension = extension this.extension = extension
this.parent = parent this.parent = parent
this.node = node this.node = node
this.view = view this.view = view
this.getPos = getPos
this.decorations = decorations this.decorations = decorations
this.editable = editable
this.selected = false
this.isNode = !!this.node.marks this.isNode = !!this.node.marks
this.isMark = !this.isNode this.isMark = !this.isNode
this.getPos = this.isMark ? this.getMarkPos : getPos
this.dom = this.createDOM() this.dom = this.createDOM()
this.contentDOM = this.vm.$refs.content this.contentDOM = this.vm.$refs.content
if (this.isMark) {
this.getPos = this.getMarkPos
}
} }
createDOM() { createDOM() {
const Component = Vue.extend(this.component) const Component = Vue.extend(this.component)
const props = {
editor: this.editor,
node: this.node,
view: this.view,
getPos: () => this.getPos(),
decorations: this.decorations,
selected: false,
options: this.extension.options,
updateAttrs: attrs => this.updateAttrs(attrs),
}
this.vm = new Component({ this.vm = new Component({
parent: this.parent, parent: this.parent,
propsData: { propsData: props,
node: this.node,
view: this.view,
getPos: () => this.getPos(),
decorations: this.decorations,
editable: this.editable,
selected: false,
options: this.extension.options,
updateAttrs: attrs => this.updateAttrs(attrs),
},
}).$mount() }).$mount()
return this.vm.$el return this.vm.$el
} }
@ -90,7 +88,7 @@ export default class ComponentView {
} }
updateAttrs(attrs) { updateAttrs(attrs) {
if (!this.editable) { if (!this.view.editable) {
return return
} }

View File

@ -134,7 +134,8 @@ export default class ExtensionManager {
]), []) ]), [])
} }
commands({ schema, view, editable }) { commands({ schema, view }) {
return this.extensions return this.extensions
.filter(extension => extension.commands) .filter(extension => extension.commands)
.reduce((allCommands, extension) => { .reduce((allCommands, extension) => {
@ -148,7 +149,7 @@ export default class ExtensionManager {
}) })
const apply = (cb, attrs) => { const apply = (cb, attrs) => {
if (!editable) { if (!view.editable) {
return false return false
} }
view.focus() view.focus()