diff --git a/types/prosemirror-commands/index.d.ts b/types/prosemirror-commands/index.d.ts index 1f6fbee7b3..7f070ebb5d 100644 --- a/types/prosemirror-commands/index.d.ts +++ b/types/prosemirror-commands/index.d.ts @@ -4,13 +4,26 @@ // David Hahn // Tim Baumann // Patrick Simmelbauer +// Mike Morearty // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 3.0 import { MarkType, Node as ProsemirrorNode, NodeType, Schema } from 'prosemirror-model'; import { EditorState, Transaction } from 'prosemirror-state'; import { EditorView } from 'prosemirror-view'; +export interface Command { + ( + state: EditorState, + dispatch: (tr: Transaction) => void, + view: EditorView + ): boolean; +} + +export interface Keymap { + [key: string]: Command; +} + /** * Delete the selection, if there is one. */ @@ -222,17 +235,17 @@ export function chainCommands( * * **Mod-Delete** to `deleteSelection`, `joinForward`, `selectNodeForward` * * **Mod-a** to `selectAll` */ -export let pcBaseKeymap: { [key: string]: any }; +export let pcBaseKeymap: Keymap; /** * A copy of `pcBaseKeymap` that also binds **Ctrl-h** like Backspace, * **Ctrl-d** like Delete, **Alt-Backspace** like Ctrl-Backspace, and * **Ctrl-Alt-Backspace**, **Alt-Delete**, and **Alt-d** like * Ctrl-Delete. */ -export let macBaseKeymap: { [key: string]: any }; +export let macBaseKeymap: Keymap; /** * Depending on the detected platform, this will hold * [`pcBasekeymap`](#commands.pcBaseKeymap) or * [`macBaseKeymap`](#commands.macBaseKeymap). */ -export let baseKeymap: { [key: string]: any }; +export let baseKeymap: Keymap; diff --git a/types/prosemirror-commands/prosemirror-commands-tests.ts b/types/prosemirror-commands/prosemirror-commands-tests.ts index 35980bf990..9db641b03f 100644 --- a/types/prosemirror-commands/prosemirror-commands-tests.ts +++ b/types/prosemirror-commands/prosemirror-commands-tests.ts @@ -9,3 +9,13 @@ commands.deleteSelection(state); commands.baseKeymap["Ctrl-h"]; commands.wrapIn(nodeType, { attr: 'value' }); + +const c1: commands.Command = commands.deleteSelection; +const c2: commands.Command = commands.joinBackward; + +const keymap: commands.Keymap = { + ArrowUp: () => true, // takes no args + ArrowDown: commands.deleteSelection, // takes two args + ArrowLeft: commands.joinBackward, // takes three args + ArrowRight: (state, dispatch, view) => true, // arg types inferred +}; diff --git a/types/prosemirror-keymap/index.d.ts b/types/prosemirror-keymap/index.d.ts index e06f1a4bd9..22e37c8bde 100644 --- a/types/prosemirror-keymap/index.d.ts +++ b/types/prosemirror-keymap/index.d.ts @@ -6,10 +6,11 @@ // Patrick Simmelbauer // Mike Morearty // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.8 +// TypeScript Version: 3.0 +import { Keymap } from 'prosemirror-commands'; import { Schema } from 'prosemirror-model'; -import { EditorState, Plugin, Transaction } from 'prosemirror-state'; +import { Plugin } from 'prosemirror-state'; import { EditorView } from 'prosemirror-view'; /** @@ -43,23 +44,13 @@ import { EditorView } from 'prosemirror-view'; * which they appear determines their precedence (the ones early in * the array get to dispatch first). */ -export function keymap(bindings: { - [key: string]: ( - state: EditorState, - dispatch: (tr: Transaction) => void, - view: EditorView - ) => boolean; -}): Plugin; +export function keymap(bindings: Keymap): Plugin; /** * Given a set of bindings (using the same format as * [`keymap`](#keymap.keymap), return a [keydown * handler](#view.EditorProps.handleKeyDown) handles them. */ -export function keydownHandler(bindings: { - [key: string]: ( - state: EditorState, - dispatch: (tr: Transaction) => void, - view: EditorView - ) => boolean; -}): (view: EditorView, event: KeyboardEvent) => boolean; +export function keydownHandler( + bindings: Keymap, +): (view: EditorView, event: KeyboardEvent) => boolean;