remove registerCommands

This commit is contained in:
Philipp Kühn
2021-02-10 14:52:08 +01:00
parent 290ff76e37
commit 2340840621
4 changed files with 25 additions and 61 deletions

View File

@@ -4,7 +4,7 @@ import { inputRules as inputRulesPlugin } from 'prosemirror-inputrules'
import { EditorView, Decoration } from 'prosemirror-view'
import { Plugin } from 'prosemirror-state'
import { Editor } from './Editor'
import { Extensions, NodeViewRenderer } from './types'
import { Extensions, NodeViewRenderer, Commands } from './types'
import getSchema from './helpers/getSchema'
import getSchemaTypeByName from './helpers/getSchemaTypeByName'
import getNodeType from './helpers/getNodeType'
@@ -32,11 +32,6 @@ export default class ExtensionManager {
type: getSchemaTypeByName(extension.config.name, this.schema),
}
const commands = extension.config.addCommands.bind(context)()
// @ts-ignore
editor.registerCommands(commands)
if (typeof extension.config.onCreate === 'function') {
this.editor.on('create', extension.config.onCreate.bind(context))
}
@@ -67,6 +62,21 @@ export default class ExtensionManager {
})
}
get commands(): Commands {
return this.extensions.reduce((extensions, extension) => {
const context = {
options: extension.options,
editor: this.editor,
type: getSchemaTypeByName(extension.config.name, this.schema),
}
return {
...extensions,
...extension.config.addCommands.bind(context)(),
}
}, {} as Commands)
}
get plugins(): Plugin[] {
return [...this.extensions]
.reverse()