From 4637ccfaf389cef30d3fb121e8d74c4cd6104cf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Wed, 14 Nov 2018 12:14:19 +0100 Subject: [PATCH] refactoring --- packages/tiptap/src/utils/ComponentView.js | 75 +++++++++++----------- 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/packages/tiptap/src/utils/ComponentView.js b/packages/tiptap/src/utils/ComponentView.js index 09e56056..8f7db9f5 100644 --- a/packages/tiptap/src/utils/ComponentView.js +++ b/packages/tiptap/src/utils/ComponentView.js @@ -11,9 +11,9 @@ export default class ComponentView { decorations, editable, }) { + this.component = component this.extension = extension this.parent = parent - this.component = component this.node = node this.view = view this.getPos = getPos @@ -41,41 +41,6 @@ export default class ComponentView { return this.vm.$el } - updateAttrs(attrs) { - if (!this.editable) { - return - } - - const transaction = this.view.state.tr.setNodeMarkup(this.getPos(), null, { - ...this.node.attrs, - ...attrs, - }) - this.view.dispatch(transaction) - } - - updateContent(content) { - if (!this.editable) { - return - } - - const transaction = this.view.state.tr.setNodeMarkup(this.getPos(), this.node.type, { content }) - this.view.dispatch(transaction) - } - - ignoreMutation() { - return true - } - - stopEvent() { - const draggable = !!this.extension.schema.draggable - - if (draggable) { - return false - } - - return true - } - update(node, decorations) { if (node.type !== this.node.type) { return false @@ -100,6 +65,44 @@ export default class ComponentView { return true } + updateAttrs(attrs) { + if (!this.editable) { + return + } + + const transaction = this.view.state.tr.setNodeMarkup(this.getPos(), null, { + ...this.node.attrs, + ...attrs, + }) + this.view.dispatch(transaction) + } + + updateContent(content) { + if (!this.editable) { + return + } + + const transaction = this.view.state.tr.setNodeMarkup(this.getPos(), this.node.type, { content }) + this.view.dispatch(transaction) + } + + // prevent a full re-render of the vue component on update + // we'll handle prop updates in `update()` + ignoreMutation() { + return true + } + + // disable (almost) all prosemirror event listener for node views + stopEvent() { + const draggable = !!this.extension.schema.draggable + + if (draggable) { + return false + } + + return true + } + destroy() { this.vm.$destroy() }