feat: Integrate input rules and paste rules into the core (#1997)
* refactoring * improve link regex * WIP: add new markPasteRule und linkify to image mark * move copy of inputrule to core * trigger codeblock inputrule on enter * refactoring * add regex match to markpasterulematch * refactoring * improve link regex * WIP: add new markPasteRule und linkify to image mark * move copy of inputrule to core * trigger codeblock inputrule on enter * refactoring * add regex match to markpasterulematch * update linkify * wip * wip * log * wip * remove debug code * wip * wip * wip * wip * wip * wip * wip * wip * rename matcher * add data to ExtendedRegExpMatchArray * remove logging * add code option to marks, prevent inputrules in code mark * remove link regex * fix codeblock inputrule on enter * refactoring * refactoring * refactoring * refactoring * fix position bug * add test * export InputRule and PasteRule * clean up link demo * fix types
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { keymap } from 'prosemirror-keymap'
|
||||
import { Schema, Node as ProsemirrorNode } from 'prosemirror-model'
|
||||
import { inputRules as inputRulesPlugin } from 'prosemirror-inputrules'
|
||||
import { inputRulesPlugin } from './InputRule'
|
||||
import { pasteRulesPlugin } from './PasteRule'
|
||||
import { EditorView, Decoration } from 'prosemirror-view'
|
||||
import { Plugin } from 'prosemirror-state'
|
||||
import { Editor } from './Editor'
|
||||
@@ -210,7 +211,12 @@ export default class ExtensionManager {
|
||||
// so it feels more natural to run plugins at the end of an array first.
|
||||
// That’s why we have to reverse the `extensions` array and sort again
|
||||
// based on the `priority` option.
|
||||
return ExtensionManager.sort([...this.extensions].reverse())
|
||||
const extensions = ExtensionManager.sort([...this.extensions].reverse())
|
||||
|
||||
const inputRules: any[] = []
|
||||
const pasteRules: any[] = []
|
||||
|
||||
const allPlugins = extensions
|
||||
.map(extension => {
|
||||
const context = {
|
||||
name: extension.name,
|
||||
@@ -248,12 +254,7 @@ export default class ExtensionManager {
|
||||
)
|
||||
|
||||
if (this.editor.options.enableInputRules && addInputRules) {
|
||||
const inputRules = addInputRules()
|
||||
const inputRulePlugins = inputRules.length
|
||||
? [inputRulesPlugin({ rules: inputRules })]
|
||||
: []
|
||||
|
||||
plugins.push(...inputRulePlugins)
|
||||
inputRules.push(...addInputRules())
|
||||
}
|
||||
|
||||
const addPasteRules = getExtensionField<AnyConfig['addPasteRules']>(
|
||||
@@ -263,9 +264,7 @@ export default class ExtensionManager {
|
||||
)
|
||||
|
||||
if (this.editor.options.enablePasteRules && addPasteRules) {
|
||||
const pasteRulePlugins = addPasteRules()
|
||||
|
||||
plugins.push(...pasteRulePlugins)
|
||||
pasteRules.push(...addPasteRules())
|
||||
}
|
||||
|
||||
const addProseMirrorPlugins = getExtensionField<AnyConfig['addProseMirrorPlugins']>(
|
||||
@@ -283,6 +282,12 @@ export default class ExtensionManager {
|
||||
return plugins
|
||||
})
|
||||
.flat()
|
||||
|
||||
return [
|
||||
inputRulesPlugin(inputRules),
|
||||
pasteRulesPlugin(pasteRules),
|
||||
...allPlugins,
|
||||
]
|
||||
}
|
||||
|
||||
get attributes() {
|
||||
|
||||
Reference in New Issue
Block a user