From 9f38f36447e4a2b48668f6e5d2e881365e9c8196 Mon Sep 17 00:00:00 2001 From: Chrissi2812 Date: Wed, 24 Apr 2019 16:13:57 +0200 Subject: [PATCH 1/2] add option to disable input/pasterules --- packages/tiptap/src/Editor.js | 4 ++++ packages/tiptap/src/Utils/ExtensionManager.js | 18 ++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/packages/tiptap/src/Editor.js b/packages/tiptap/src/Editor.js index 07dedd03a..ad77b7b5b 100644 --- a/packages/tiptap/src/Editor.js +++ b/packages/tiptap/src/Editor.js @@ -31,6 +31,8 @@ export default class Editor { }], }, useBuiltInExtensions: true, + disabledInputRules: [], + disabledPasteRules: [], dropCursor: {}, parseOptions: {}, onInit: () => {}, @@ -121,12 +123,14 @@ export default class Editor { createInputRules() { return this.extensions.inputRules({ schema: this.schema, + excludedExtensions: this.options.disabledInputRules, }) } createPasteRules() { return this.extensions.pasteRules({ schema: this.schema, + excludedExtensions: this.options.disabledPasteRules, }) } diff --git a/packages/tiptap/src/Utils/ExtensionManager.js b/packages/tiptap/src/Utils/ExtensionManager.js index 20da9068b..40774943b 100644 --- a/packages/tiptap/src/Utils/ExtensionManager.js +++ b/packages/tiptap/src/Utils/ExtensionManager.js @@ -74,13 +74,16 @@ export default class ExtensionManager { ].map(keys => keymap(keys)) } - inputRules({ schema }) { - const extensionInputRules = this.extensions + inputRules({ schema, excludedExtensions }) { + const allowedExtensions = this.extensions + .filter(extension => !excludedExtensions.includes(extension.name)) + + const extensionInputRules = allowedExtensions .filter(extension => ['extension'].includes(extension.type)) .filter(extension => extension.inputRules) .map(extension => extension.inputRules({ schema })) - const nodeMarkInputRules = this.extensions + const nodeMarkInputRules = allowedExtensions .filter(extension => ['node', 'mark'].includes(extension.type)) .filter(extension => extension.inputRules) .map(extension => extension.inputRules({ @@ -97,13 +100,16 @@ export default class ExtensionManager { ]), []) } - pasteRules({ schema }) { - const extensionPasteRules = this.extensions + pasteRules({ schema, excludedExtensions }) { + const allowedExtensions = this.extensions + .filter(extension => !excludedExtensions.includes(extension.name)) + + const extensionPasteRules = allowedExtensions .filter(extension => ['extension'].includes(extension.type)) .filter(extension => extension.pasteRules) .map(extension => extension.pasteRules({ schema })) - const nodeMarkPasteRules = this.extensions + const nodeMarkPasteRules = allowedExtensions .filter(extension => ['node', 'mark'].includes(extension.type)) .filter(extension => extension.pasteRules) .map(extension => extension.pasteRules({ From d5180182f407302658b8b92369d9c742f30d018a Mon Sep 17 00:00:00 2001 From: Chrissi2812 Date: Wed, 8 May 2019 09:35:55 +0200 Subject: [PATCH 2/2] boolean switch for input and paste rules added --- packages/tiptap/src/Editor.js | 8 ++++---- packages/tiptap/src/Utils/ExtensionManager.js | 12 ++++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/tiptap/src/Editor.js b/packages/tiptap/src/Editor.js index ad77b7b5b..1193f2553 100644 --- a/packages/tiptap/src/Editor.js +++ b/packages/tiptap/src/Editor.js @@ -31,8 +31,8 @@ export default class Editor { }], }, useBuiltInExtensions: true, - disabledInputRules: [], - disabledPasteRules: [], + disableInputRules: false, + disablePasteRules: false, dropCursor: {}, parseOptions: {}, onInit: () => {}, @@ -123,14 +123,14 @@ export default class Editor { createInputRules() { return this.extensions.inputRules({ schema: this.schema, - excludedExtensions: this.options.disabledInputRules, + excludedExtensions: this.options.disableInputRules, }) } createPasteRules() { return this.extensions.pasteRules({ schema: this.schema, - excludedExtensions: this.options.disabledPasteRules, + excludedExtensions: this.options.disablePasteRules, }) } diff --git a/packages/tiptap/src/Utils/ExtensionManager.js b/packages/tiptap/src/Utils/ExtensionManager.js index 40774943b..37f50b001 100644 --- a/packages/tiptap/src/Utils/ExtensionManager.js +++ b/packages/tiptap/src/Utils/ExtensionManager.js @@ -75,8 +75,10 @@ export default class ExtensionManager { } inputRules({ schema, excludedExtensions }) { - const allowedExtensions = this.extensions - .filter(extension => !excludedExtensions.includes(extension.name)) + if (!(excludedExtensions instanceof Array) && excludedExtensions) return [] + + const allowedExtensions = (excludedExtensions instanceof Array) ? this.extensions + .filter(extension => !excludedExtensions.includes(extension.name)) : this.extensions const extensionInputRules = allowedExtensions .filter(extension => ['extension'].includes(extension.type)) @@ -101,8 +103,10 @@ export default class ExtensionManager { } pasteRules({ schema, excludedExtensions }) { - const allowedExtensions = this.extensions - .filter(extension => !excludedExtensions.includes(extension.name)) + if (!(excludedExtensions instanceof Array) && excludedExtensions) return [] + + const allowedExtensions = (excludedExtensions instanceof Array) ? this.extensions + .filter(extension => !excludedExtensions.includes(extension.name)) : this.extensions const extensionPasteRules = allowedExtensions .filter(extension => ['extension'].includes(extension.type))