index.d.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { Command, Plugin } from 'prosemirror-state';
  2. import { EditorView } from 'prosemirror-view';
  3. /**
  4. Create a keymap plugin for the given set of bindings.
  5. Bindings should map key names to [command](https://prosemirror.net/docs/ref/#commands)-style
  6. functions, which will be called with `(EditorState, dispatch,
  7. EditorView)` arguments, and should return true when they've handled
  8. the key. Note that the view argument isn't part of the command
  9. protocol, but can be used as an escape hatch if a binding needs to
  10. directly interact with the UI.
  11. Key names may be strings like `"Shift-Ctrl-Enter"`—a key
  12. identifier prefixed with zero or more modifiers. Key identifiers
  13. are based on the strings that can appear in
  14. [`KeyEvent.key`](https:developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key).
  15. Use lowercase letters to refer to letter keys (or uppercase letters
  16. if you want shift to be held). You may use `"Space"` as an alias
  17. for the `" "` name.
  18. Modifiers can be given in any order. `Shift-` (or `s-`), `Alt-` (or
  19. `a-`), `Ctrl-` (or `c-` or `Control-`) and `Cmd-` (or `m-` or
  20. `Meta-`) are recognized. For characters that are created by holding
  21. shift, the `Shift-` prefix is implied, and should not be added
  22. explicitly.
  23. You can use `Mod-` as a shorthand for `Cmd-` on Mac and `Ctrl-` on
  24. other platforms.
  25. You can add multiple keymap plugins to an editor. The order in
  26. which they appear determines their precedence (the ones early in
  27. the array get to dispatch first).
  28. */
  29. declare function keymap(bindings: {
  30. [key: string]: Command;
  31. }): Plugin;
  32. /**
  33. Given a set of bindings (using the same format as
  34. [`keymap`](https://prosemirror.net/docs/ref/#keymap.keymap)), return a [keydown
  35. handler](https://prosemirror.net/docs/ref/#view.EditorProps.handleKeyDown) that handles them.
  36. */
  37. declare function keydownHandler(bindings: {
  38. [key: string]: Command;
  39. }): (view: EditorView, event: KeyboardEvent) => boolean;
  40. export { keydownHandler, keymap };