fix all eslint errors
This commit is contained in:
@@ -8,8 +8,11 @@ export default class CommandManager {
|
||||
|
||||
commands: { [key: string]: any } = {}
|
||||
|
||||
methodNames: string[] = []
|
||||
|
||||
constructor(editor: Editor) {
|
||||
this.editor = editor
|
||||
this.methodNames = getAllMethodNames(this.editor)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -23,7 +26,7 @@ export default class CommandManager {
|
||||
throw new Error(`tiptap: command '${name}' is already defined.`)
|
||||
}
|
||||
|
||||
if (getAllMethodNames(this.editor).includes(name)) {
|
||||
if (this.methodNames.includes(name)) {
|
||||
throw new Error(`tiptap: '${name}' is a protected name.`)
|
||||
}
|
||||
|
||||
|
||||
@@ -40,14 +40,14 @@ export interface Commands {}
|
||||
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
|
||||
[Item in keyof Commands]: Commands[Item] extends (...args: any[]) => any
|
||||
? (...args: Parameters<Commands[Item]>) => boolean
|
||||
: never
|
||||
}
|
||||
|
||||
export type ChainedCommands = {
|
||||
[Command in keyof Commands]: Commands[Command] extends (...args: any[]) => any
|
||||
? (...args: Parameters<Commands[Command]>) => ChainedCommands
|
||||
[Item in keyof Commands]: Commands[Item] extends (...args: any[]) => any
|
||||
? (...args: Parameters<Commands[Item]>) => ChainedCommands
|
||||
: never
|
||||
} & {
|
||||
run: () => boolean
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
export default function getAllMethodNames(obj: Object) {
|
||||
const methods = new Set()
|
||||
|
||||
while (obj = Reflect.getPrototypeOf(obj)) {
|
||||
const keys = Reflect.ownKeys(obj)
|
||||
keys.forEach(k => methods.add(k))
|
||||
}
|
||||
|
||||
return Array.from(methods)
|
||||
export default function getAllMethodNames(obj: Object): string[] {
|
||||
return Reflect.ownKeys(Reflect.getPrototypeOf(obj))
|
||||
.map(name => name.toString())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user