Merge pull request #272 from Chrissi2812/disabled-paste-input-rules

add option to disable input/pasterules
This commit is contained in:
Philipp Kühn 2019-05-09 10:35:25 +02:00 committed by GitHub
commit 2225dc3f72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 6 deletions

View File

@ -35,6 +35,8 @@ export default class Editor extends Emitter {
}], }],
}, },
useBuiltInExtensions: true, useBuiltInExtensions: true,
disableInputRules: false,
disablePasteRules: false,
dropCursor: {}, dropCursor: {},
parseOptions: {}, parseOptions: {},
onInit: () => {}, onInit: () => {},
@ -141,12 +143,14 @@ export default class Editor extends Emitter {
createInputRules() { createInputRules() {
return this.extensions.inputRules({ return this.extensions.inputRules({
schema: this.schema, schema: this.schema,
excludedExtensions: this.options.disableInputRules,
}) })
} }
createPasteRules() { createPasteRules() {
return this.extensions.pasteRules({ return this.extensions.pasteRules({
schema: this.schema, schema: this.schema,
excludedExtensions: this.options.disablePasteRules,
}) })
} }

View File

@ -78,13 +78,18 @@ export default class ExtensionManager {
].map(keys => keymap(keys)) ].map(keys => keymap(keys))
} }
inputRules({ schema }) { inputRules({ schema, excludedExtensions }) {
const extensionInputRules = this.extensions 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'].includes(extension.type))
.filter(extension => extension.inputRules) .filter(extension => extension.inputRules)
.map(extension => extension.inputRules({ schema })) .map(extension => extension.inputRules({ schema }))
const nodeMarkInputRules = this.extensions const nodeMarkInputRules = allowedExtensions
.filter(extension => ['node', 'mark'].includes(extension.type)) .filter(extension => ['node', 'mark'].includes(extension.type))
.filter(extension => extension.inputRules) .filter(extension => extension.inputRules)
.map(extension => extension.inputRules({ .map(extension => extension.inputRules({
@ -101,13 +106,18 @@ export default class ExtensionManager {
]), []) ]), [])
} }
pasteRules({ schema }) { pasteRules({ schema, excludedExtensions }) {
const extensionPasteRules = this.extensions 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'].includes(extension.type))
.filter(extension => extension.pasteRules) .filter(extension => extension.pasteRules)
.map(extension => extension.pasteRules({ schema })) .map(extension => extension.pasteRules({ schema }))
const nodeMarkPasteRules = this.extensions const nodeMarkPasteRules = allowedExtensions
.filter(extension => ['node', 'mark'].includes(extension.type)) .filter(extension => ['node', 'mark'].includes(extension.type))
.filter(extension => extension.pasteRules) .filter(extension => extension.pasteRules)
.map(extension => extension.pasteRules({ .map(extension => extension.pasteRules({