UNPKG

2.51 kBTypeScriptView Raw
1// Type definitions for prosemirror-keymap 1.0
2// Project: https://github.com/ProseMirror/prosemirror-keymap
3// Definitions by: Bradley Ayers <https://github.com/bradleyayers>
4// David Hahn <https://github.com/davidka>
5// Tim Baumann <https://github.com/timjb>
6// Patrick Simmelbauer <https://github.com/patsimm>
7// Mike Morearty <https://github.com/mmorearty>
8// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
9// TypeScript Version: 3.0
10
11import { Keymap } from 'prosemirror-commands';
12import { Schema } from 'prosemirror-model';
13import { Plugin } from 'prosemirror-state';
14import { EditorView } from 'prosemirror-view';
15
16/**
17 * Create a keymap plugin for the given set of bindings.
18 *
19 * Bindings should map key names to [command](#commands)-style
20 * functions, which will be called with `(EditorState, dispatch,
21 * EditorView)` arguments, and should return true when they've handled
22 * the key. Note that the view argument isn't part of the command
23 * protocol, but can be used as an escape hatch if a binding needs to
24 * directly interact with the UI.
25 *
26 * Key names may be strings like `"Shift-Ctrl-Enter"`—a key
27 * identifier prefixed with zero or more modifiers. Key identifiers
28 * are based on the strings that can appear in
29 * [`KeyEvent.key`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key).
30 * Use lowercase letters to refer to letter keys (or uppercase letters
31 * if you want shift to be held). You may use `"Space"` as an alias
32 * for the `" "` name.
33 *
34 * Modifiers can be given in any order. `Shift-` (or `s-`), `Alt-` (or
35 * `a-`), `Ctrl-` (or `c-` or `Control-`) and `Cmd-` (or `m-` or
36 * `Meta-`) are recognized. For characters that are created by holding
37 * shift, the `Shift-` prefix is implied, and should not be added
38 * explicitly.
39 *
40 * You can use `Mod-` as a shorthand for `Cmd-` on Mac and `Ctrl-` on
41 * other platforms.
42 *
43 * You can add multiple keymap plugins to an editor. The order in
44 * which they appear determines their precedence (the ones early in
45 * the array get to dispatch first).
46 */
47export function keymap<S extends Schema = any>(bindings: Keymap<S>): Plugin;
48
49/**
50 * Given a set of bindings (using the same format as
51 * [`keymap`](#keymap.keymap), return a [keydown
52 * handler](#view.EditorProps.handleKeyDown) handles them.
53 */
54export function keydownHandler<S extends Schema = any>(
55 bindings: Keymap<S>,
56): (view: EditorView, event: KeyboardEvent) => boolean;