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