improve command handling

This commit is contained in:
Philipp Kühn
2020-09-22 10:49:38 +02:00
parent 0aa5a4c474
commit 119fdd0dff
31 changed files with 41 additions and 38 deletions

View File

@@ -37,7 +37,13 @@ export interface CommandSpec {
export interface Commands {}
// export type CommandNames = Extract<keyof Commands, string>
export type CommandNames = Extract<keyof Commands, string>
export type SingleCommands = {
[Command in keyof Commands]: Commands[Command] extends (...args: any[]) => any
? (...args: Parameters<Commands[Command]>) => boolean
: never
}
export type ChainedCommands = {
[Command in keyof Commands]: Commands[Command] extends (...args: any[]) => any
@@ -62,6 +68,10 @@ interface EditorOptions {
editable: boolean,
}
declare module './Editor' {
interface Editor extends SingleCommands {}
}
@magicMethods
export class Editor extends EventEmitter {
@@ -85,7 +95,6 @@ export class Editor extends EventEmitter {
editable: true,
}
constructor(options: Partial<EditorOptions> = {}) {
super()
this.options = { ...this.options, ...options }