diff --git a/packages/tiptap/src/Editor.js b/packages/tiptap/src/Editor.js index d6f7afbaf..18f8516e9 100644 --- a/packages/tiptap/src/Editor.js +++ b/packages/tiptap/src/Editor.js @@ -35,6 +35,8 @@ export default class Editor extends Emitter { }], }, useBuiltInExtensions: true, + disableInputRules: false, + disablePasteRules: false, dropCursor: {}, parseOptions: {}, onInit: () => {}, @@ -141,12 +143,14 @@ export default class Editor extends Emitter { createInputRules() { return this.extensions.inputRules({ schema: this.schema, + excludedExtensions: this.options.disableInputRules, }) } createPasteRules() { return this.extensions.pasteRules({ schema: this.schema, + excludedExtensions: this.options.disablePasteRules, }) } diff --git a/packages/tiptap/src/Utils/ExtensionManager.js b/packages/tiptap/src/Utils/ExtensionManager.js index fd343e850..0f348189c 100644 --- a/packages/tiptap/src/Utils/ExtensionManager.js +++ b/packages/tiptap/src/Utils/ExtensionManager.js @@ -78,13 +78,18 @@ export default class ExtensionManager { ].map(keys => keymap(keys)) } - inputRules({ schema }) { - const extensionInputRules = this.extensions + inputRules({ schema, excludedExtensions }) { + 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)) .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({ @@ -101,13 +106,18 @@ export default class ExtensionManager { ]), []) } - pasteRules({ schema }) { - const extensionPasteRules = this.extensions + pasteRules({ schema, excludedExtensions }) { + 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)) .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({