add basic ChainedCommands type

This commit is contained in:
Philipp Kühn
2020-09-21 21:40:44 +02:00
parent 4c392d5759
commit 778e064979
3 changed files with 21 additions and 8 deletions

View File

@@ -19,6 +19,7 @@ import Mark from './Mark'
import ComponentRenderer from './ComponentRenderer'
import defaultPlugins from './plugins'
import * as commands from './commands'
import { deleteSelection } from 'prosemirror-commands'
// export type Command = (next: Function, editor: Editor) => (...args: any) => any
@@ -35,18 +36,24 @@ export interface CommandSpec {
[key: string]: Command
}
type EditorContent = string | JSON | null
export interface Commands {}
// interface Element {
// editor?: Editor
// }
// export type CommandNames = Extract<keyof Commands, string>
export type ChainedCommands = {
[Command in keyof Commands]: Commands[Command] extends (...args: any[]) => any
? (...args: Parameters<Commands[Command]>) => ChainedCommands
: never
} & {
run: () => boolean
}
type EditorContent = string | JSON | null
interface HTMLElement {
editor?: Editor
}
// Element.prototype.editor = Editor
interface EditorOptions {
element: Element,
content: EditorContent,
@@ -176,7 +183,7 @@ export class Editor extends EventEmitter {
return proxy
}
}
})
}) as ChainedCommands
}
protected chainableEditorState(tr: Transaction, state: EditorState): EditorState {

View File

@@ -9,6 +9,12 @@ declare module '../Editor' {
}
}
// declare module '../Editor' {
// interface Commands {
// deleteSelection: DeleteSelectionCommand,
// }
// }
export const deleteSelection: DeleteSelectionCommand = () => ({ state, dispatch }) => {
return originalDeleteSelection(state, dispatch)
}