remove proxy from createChain
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
|||||||
ChainedCommands,
|
ChainedCommands,
|
||||||
CanCommands,
|
CanCommands,
|
||||||
Commands,
|
Commands,
|
||||||
|
Command,
|
||||||
CommandSpec,
|
CommandSpec,
|
||||||
CommandProps,
|
CommandProps,
|
||||||
} from './types'
|
} from './types'
|
||||||
@@ -54,9 +55,7 @@ export default class CommandManager {
|
|||||||
const hasStartTransaction = !!startTr
|
const hasStartTransaction = !!startTr
|
||||||
const tr = startTr || state.tr
|
const tr = startTr || state.tr
|
||||||
|
|
||||||
return new Proxy({}, {
|
const run = () => {
|
||||||
get: (_, name: keyof ChainedCommands, proxy) => {
|
|
||||||
if (name === 'run') {
|
|
||||||
if (!hasStartTransaction && shouldDispatch && !tr.getMeta('preventDispatch')) {
|
if (!hasStartTransaction && shouldDispatch && !tr.getMeta('preventDispatch')) {
|
||||||
view.dispatch(tr)
|
view.dispatch(tr)
|
||||||
}
|
}
|
||||||
@@ -64,22 +63,23 @@ export default class CommandManager {
|
|||||||
return () => callbacks.every(callback => callback === true)
|
return () => callbacks.every(callback => callback === true)
|
||||||
}
|
}
|
||||||
|
|
||||||
const command = commands[name] as CommandSpec
|
const chain = {
|
||||||
|
...Object.fromEntries(Object.entries(commands).map(([name, command]) => {
|
||||||
if (!command) {
|
const chainedCommand = (...args: any[]) => {
|
||||||
throw new Error(`tiptap: command '${name}' not found.`)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (...args: any[]) => {
|
|
||||||
const props = this.buildProps(tr, shouldDispatch)
|
const props = this.buildProps(tr, shouldDispatch)
|
||||||
const callback = command(...args)(props)
|
const callback = command(...args)(props)
|
||||||
|
|
||||||
callbacks.push(callback)
|
callbacks.push(callback)
|
||||||
|
|
||||||
return proxy
|
return chain
|
||||||
}
|
}
|
||||||
},
|
|
||||||
}) as ChainedCommands
|
return [name, chainedCommand]
|
||||||
|
})),
|
||||||
|
run,
|
||||||
|
} as unknown as ChainedCommands
|
||||||
|
|
||||||
|
return chain
|
||||||
}
|
}
|
||||||
|
|
||||||
public createCan(startTr?: Transaction): CanCommands {
|
public createCan(startTr?: Transaction): CanCommands {
|
||||||
|
|||||||
Reference in New Issue
Block a user