check for already defined commands
This commit is contained in:
@@ -34,6 +34,7 @@ export class Editor extends EventEmitter {
|
|||||||
injectCSS: true,
|
injectCSS: true,
|
||||||
extensions: [],
|
extensions: [],
|
||||||
}
|
}
|
||||||
|
commands: { [key: string]: any } = {}
|
||||||
|
|
||||||
private lastCommand = Promise.resolve()
|
private lastCommand = Promise.resolve()
|
||||||
|
|
||||||
@@ -54,6 +55,26 @@ export class Editor extends EventEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public registerCommand(name: string, callback: Command): Editor {
|
||||||
|
if (this.commands[name]) {
|
||||||
|
throw new Error(`tiptap: command '${name}' is already defined.`)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.commands[name] = callback
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
this[name] = this.chainCommand((...args: any) => {
|
||||||
|
return new Promise(resolve => callback(resolve, this, ...args))
|
||||||
|
})
|
||||||
|
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
public command(name: string, ...args: any) {
|
||||||
|
// @ts-ignore
|
||||||
|
return this[name](...args)
|
||||||
|
}
|
||||||
|
|
||||||
private createExtensionManager() {
|
private createExtensionManager() {
|
||||||
this.extensionManager = new ExtensionManager(this.options.extensions, this)
|
this.extensionManager = new ExtensionManager(this.options.extensions, this)
|
||||||
}
|
}
|
||||||
@@ -158,20 +179,6 @@ export class Editor extends EventEmitter {
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
public registerCommand(name: string, callback: Command): Editor {
|
|
||||||
// @ts-ignore
|
|
||||||
this[name] = this.chainCommand((...args: any) => {
|
|
||||||
return new Promise(resolve => callback(resolve, this, ...args))
|
|
||||||
})
|
|
||||||
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
public command(name: string, ...args: any) {
|
|
||||||
// @ts-ignore
|
|
||||||
return this[name](...args)
|
|
||||||
}
|
|
||||||
|
|
||||||
// public setParentComponent(component = null) {
|
// public setParentComponent(component = null) {
|
||||||
// if (!component) {
|
// if (!component) {
|
||||||
// return
|
// return
|
||||||
|
|||||||
Reference in New Issue
Block a user