From adb2d1a12cfea90b5752cf9b3bae1db3085b7f8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Fri, 6 Mar 2020 11:24:58 +0100 Subject: [PATCH] fix some types --- packages/tiptap-core/src/Editor.ts | 8 +++----- packages/tiptap-history-extension/index.ts | 7 ++++++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/tiptap-core/src/Editor.ts b/packages/tiptap-core/src/Editor.ts index 8fd8675f6..2992c8de6 100644 --- a/packages/tiptap-core/src/Editor.ts +++ b/packages/tiptap-core/src/Editor.ts @@ -13,6 +13,7 @@ import injectCSS from './utils/injectCSS' import ExtensionManager from './ExtensionManager' type EditorContent = string | JSON +type Command = (next: Function, editor: Editor, ...args: any) => any interface Options { element?: Node @@ -155,13 +156,10 @@ export class Editor extends EventEmitter { return this } - public registerCommand(name: string, method: Function): Editor { + public registerCommand(name: string, callback: Command): Editor { // @ts-ignore this[name] = this.chainCommand((...args: any) => { - return new Promise(resolve => { - // return method(resolve, this, ...args) - return method(resolve as Function, this as Editor, ...args as any) - }) + return new Promise(resolve => callback(resolve, this, ...args)) }) return this diff --git a/packages/tiptap-history-extension/index.ts b/packages/tiptap-history-extension/index.ts index 171f62fc0..dcf7a44bf 100644 --- a/packages/tiptap-history-extension/index.ts +++ b/packages/tiptap-history-extension/index.ts @@ -10,6 +10,7 @@ import { declare module '@tiptap/core/src/Editor' { interface Editor { undo(): Editor, + undo(): Editor, } } @@ -18,11 +19,15 @@ export default class History extends Extension { name = 'history' init() { - // @ts-ignore this.editor.registerCommand('undo', (next, { view }) => { undo(view.state, view.dispatch) next() }) + + this.editor.registerCommand('redo', (next, { view }) => { + redo(view.state, view.dispatch) + next() + }) } get plugins() {