refactoring
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Editor, Command, CommandSpec } from './src/Editor'
|
||||
import { Editor, Command, CommandsSpec } from './src/Editor'
|
||||
|
||||
export default Editor
|
||||
export { Editor, Command, CommandSpec }
|
||||
export { Editor, Command, CommandsSpec }
|
||||
export { default as ComponentRenderer } from './src/ComponentRenderer'
|
||||
export { default as Extension } from './src/Extension'
|
||||
export { default as Node } from './src/Node'
|
||||
|
||||
@@ -31,8 +31,10 @@ export type Command = (props: {
|
||||
dispatch: (args?: any) => any,
|
||||
}) => boolean
|
||||
|
||||
export interface CommandSpec {
|
||||
[key: string]: (...args: any[]) => Command
|
||||
export type CommandSpec = (...args: any[]) => Command
|
||||
|
||||
export interface CommandsSpec {
|
||||
[key: string]: CommandSpec
|
||||
}
|
||||
|
||||
export interface Commands {}
|
||||
@@ -79,7 +81,7 @@ export class Editor extends EventEmitter {
|
||||
private proxy!: Editor
|
||||
private commandManager!: CommandManager
|
||||
private extensionManager!: ExtensionManager
|
||||
private commands: { [key: string]: any } = {}
|
||||
private commands: CommandsSpec = {}
|
||||
private css!: HTMLStyleElement
|
||||
public schema!: Schema
|
||||
public view!: EditorView
|
||||
@@ -166,7 +168,7 @@ export class Editor extends EventEmitter {
|
||||
*
|
||||
* @param commands A list of commands
|
||||
*/
|
||||
public registerCommands(commands: CommandSpec) {
|
||||
public registerCommands(commands: CommandsSpec) {
|
||||
Object
|
||||
.entries(commands)
|
||||
.forEach(([name, command]) => this.registerCommand(name, command))
|
||||
@@ -178,7 +180,7 @@ export class Editor extends EventEmitter {
|
||||
* @param name The name of your command
|
||||
* @param callback The method of your command
|
||||
*/
|
||||
public registerCommand(name: string, callback: (bla?: any) => Command): Editor {
|
||||
public registerCommand(name: string, callback: CommandSpec): Editor {
|
||||
if (this.commands[name]) {
|
||||
throw new Error(`tiptap: command '${name}' is already defined.`)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import cloneDeep from 'clone-deep'
|
||||
import { Plugin } from 'prosemirror-state'
|
||||
import { Editor, CommandSpec } from './Editor'
|
||||
import { Editor, CommandsSpec } from './Editor'
|
||||
|
||||
type AnyObject = {
|
||||
[key: string]: any
|
||||
@@ -26,7 +26,7 @@ export interface ExtensionProps<Options> {
|
||||
export interface ExtensionMethods<Props, Options> {
|
||||
name: string
|
||||
options: Options
|
||||
commands: (params: Props) => CommandSpec
|
||||
commands: (params: Props) => CommandsSpec
|
||||
inputRules: (params: Props) => any[]
|
||||
pasteRules: (params: Props) => any[]
|
||||
keys: (params: Props) => {
|
||||
|
||||
Reference in New Issue
Block a user