remove async commands (WIP)
This commit is contained in:
@@ -46,6 +46,7 @@ export class Editor extends EventEmitter {
|
||||
private commands: { [key: string]: any } = {}
|
||||
private css!: HTMLStyleElement
|
||||
private lastCommand = Promise.resolve()
|
||||
public lastCommandValue: any = undefined
|
||||
public schema!: Schema
|
||||
public view!: EditorView
|
||||
public selection = { from: 0, to: 0 }
|
||||
@@ -59,6 +60,7 @@ export class Editor extends EventEmitter {
|
||||
editable: true,
|
||||
}
|
||||
|
||||
|
||||
constructor(options: Partial<EditorOptions> = {}) {
|
||||
super()
|
||||
this.options = { ...this.options, ...options }
|
||||
@@ -153,12 +155,50 @@ export class Editor extends EventEmitter {
|
||||
}
|
||||
|
||||
this.commands[name] = this.chainCommand((...args: any) => {
|
||||
return new Promise(resolve => callback(resolve, this.proxy)(...args))
|
||||
// console.log('command', this.lastCommandValue)
|
||||
const commandValue = callback(() => {}, this.proxy)(...args)
|
||||
|
||||
// if (commandValue !== undefined) {
|
||||
this.lastCommandValue = commandValue
|
||||
// }
|
||||
|
||||
return this.proxy
|
||||
})
|
||||
|
||||
return this.proxy
|
||||
}
|
||||
|
||||
/**
|
||||
* Call a command.
|
||||
*
|
||||
* @param name The name of the command you want to call.
|
||||
* @param options The options of the command.
|
||||
*/
|
||||
public command(name: string, ...options: any) {
|
||||
return this.commands[name](...options)
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps a command to make it chainable.
|
||||
*
|
||||
* @param method
|
||||
*/
|
||||
private chainCommand = (method: Function) => (...args: any) => {
|
||||
// console.log('chain', this.lastCommandValue)
|
||||
// this.lastCommand = this.lastCommand
|
||||
// .then(() => {
|
||||
|
||||
// const jo = method.apply(this, args)
|
||||
|
||||
// console.log({jo})
|
||||
// })
|
||||
// // .then(method.apply(this, args))
|
||||
// .catch(console.error)
|
||||
method.apply(this, args)
|
||||
|
||||
return this.proxy
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a ProseMirror plugin.
|
||||
*
|
||||
@@ -189,29 +229,6 @@ export class Editor extends EventEmitter {
|
||||
this.view.updateState(state)
|
||||
}
|
||||
|
||||
/**
|
||||
* Call a command.
|
||||
*
|
||||
* @param name The name of the command you want to call.
|
||||
* @param options The options of the command.
|
||||
*/
|
||||
public command(name: string, ...options: any) {
|
||||
return this.commands[name](...options)
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps a command to make it chainable.
|
||||
*
|
||||
* @param method
|
||||
*/
|
||||
private chainCommand = (method: Function) => (...args: any) => {
|
||||
this.lastCommand = this.lastCommand
|
||||
.then(() => method.apply(this, args))
|
||||
.catch(console.error)
|
||||
|
||||
return this.proxy
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an extension manager.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user