add command scope

This commit is contained in:
Philipp Kühn
2021-02-16 11:27:58 +01:00
parent 87beee25b0
commit ca8d1a4245
74 changed files with 614 additions and 460 deletions

View File

@@ -35,7 +35,8 @@ export default class CommandManager {
.entries(commands)
.map(([name, command]) => {
const method = (...args: any) => {
const callback = command(...args)(props)
// TODO: fix any
const callback = command(...args as any)(props)
if (!tr.getMeta('preventDispatch')) {
view.dispatch(tr)
@@ -85,7 +86,7 @@ export default class CommandManager {
public createCan(startTr?: Transaction): CanCommands {
const { commands, editor } = this
const { state } = editor
const dispatch = false
const dispatch = undefined
const tr = startTr || state.tr
const props = this.buildProps(tr, dispatch)
const formattedCommands = Object.fromEntries(Object
@@ -118,10 +119,14 @@ export default class CommandManager {
: undefined,
chain: () => this.createChain(tr),
can: () => this.createCan(tr),
// TODO: fix
// @ts-ignore
get commands() {
return Object.fromEntries(Object
.entries(commands)
.map(([name, command]) => {
// TODO: fix
// @ts-ignore
return [name, (...args: any[]) => command(...args)(props)]
})) as SingleCommands
},