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,
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,
})
}

View File

@ -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({