From b913c84b5898fd6bcd6039643970a581eb7781ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Mon, 22 Oct 2018 21:11:28 +0200 Subject: [PATCH] fix editable --- examples/Components/Routes/Basic/index.vue | 1 - examples/Components/Routes/MenuBubble/index.vue | 1 - packages/tiptap/src/utils/Editor.js | 2 ++ packages/tiptap/src/utils/buildMenuActions.js | 16 +++++++++++----- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/examples/Components/Routes/Basic/index.vue b/examples/Components/Routes/Basic/index.vue index ffe89462..0d29f23b 100644 --- a/examples/Components/Routes/Basic/index.vue +++ b/examples/Components/Routes/Basic/index.vue @@ -145,7 +145,6 @@ export default { data() { return { editor: new Editor({ - editable: true, extensions: [ new BlockquoteNode(), new BulletListNode(), diff --git a/examples/Components/Routes/MenuBubble/index.vue b/examples/Components/Routes/MenuBubble/index.vue index 69a4fb25..1cb0942e 100644 --- a/examples/Components/Routes/MenuBubble/index.vue +++ b/examples/Components/Routes/MenuBubble/index.vue @@ -65,7 +65,6 @@ export default { data() { return { editor: new Editor({ - editable: true, extensions: [ new BlockquoteNode(), new BulletListNode(), diff --git a/packages/tiptap/src/utils/Editor.js b/packages/tiptap/src/utils/Editor.js index 95dd89d5..ecff1a1a 100644 --- a/packages/tiptap/src/utils/Editor.js +++ b/packages/tiptap/src/utils/Editor.js @@ -23,6 +23,7 @@ export default class Editor { constructor(options = {}) { const defaultOptions = { + editable: true, content: '', on: { update: () => {}, @@ -229,6 +230,7 @@ export default class Editor { updateMenuActions() { this.menuActions = buildMenuActions({ + editable: this.options.editable, schema: this.schema, state: this.view.state, commands: this.commands, diff --git a/packages/tiptap/src/utils/buildMenuActions.js b/packages/tiptap/src/utils/buildMenuActions.js index 95ec8298..c8ee4bd0 100644 --- a/packages/tiptap/src/utils/buildMenuActions.js +++ b/packages/tiptap/src/utils/buildMenuActions.js @@ -1,12 +1,17 @@ import { markIsActive, nodeIsActive, getMarkAttrs } from 'tiptap-utils' -export default function ({ schema, state, commands }) { +export default function ({ schema, state, commands, editable }) { const nodes = Object.entries(schema.nodes) .map(([name]) => { const active = (attrs = {}) => nodeIsActive(state, schema.nodes[name], attrs) const command = commands[name] ? commands[name] : () => {} - return { name, active, command } + + return { + name, + active, + command: editable ? command : () => {} + } }) .reduce((actions, { name, active, command }) => ({ ...actions, @@ -21,16 +26,17 @@ export default function ({ schema, state, commands }) { const active = () => markIsActive(state, schema.marks[name]) const attrs = getMarkAttrs(state, schema.marks[name]) const command = commands[name] ? commands[name] : () => {} + return { name, active, attrs, - command, + command: editable ? command : () => {} } }) .reduce((actions, { - name, active, attrs, command, -}) => ({ + name, active, attrs, command, + }) => ({ ...actions, [name]: { active,