index.d.cts 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. import { Node, NodeType, Attrs, MarkType } from 'prosemirror-model';
  2. import { Command } from 'prosemirror-state';
  3. /**
  4. Delete the selection, if there is one.
  5. */
  6. declare const deleteSelection: Command;
  7. /**
  8. If the selection is empty and at the start of a textblock, try to
  9. reduce the distance between that block and the one before it—if
  10. there's a block directly before it that can be joined, join them.
  11. If not, try to move the selected block closer to the next one in
  12. the document structure by lifting it out of its parent or moving it
  13. into a parent of the previous block. Will use the view for accurate
  14. (bidi-aware) start-of-textblock detection if given.
  15. */
  16. declare const joinBackward: Command;
  17. /**
  18. A more limited form of [`joinBackward`]($commands.joinBackward)
  19. that only tries to join the current textblock to the one before
  20. it, if the cursor is at the start of a textblock.
  21. */
  22. declare const joinTextblockBackward: Command;
  23. /**
  24. A more limited form of [`joinForward`]($commands.joinForward)
  25. that only tries to join the current textblock to the one after
  26. it, if the cursor is at the end of a textblock.
  27. */
  28. declare const joinTextblockForward: Command;
  29. /**
  30. When the selection is empty and at the start of a textblock, select
  31. the node before that textblock, if possible. This is intended to be
  32. bound to keys like backspace, after
  33. [`joinBackward`](https://prosemirror.net/docs/ref/#commands.joinBackward) or other deleting
  34. commands, as a fall-back behavior when the schema doesn't allow
  35. deletion at the selected point.
  36. */
  37. declare const selectNodeBackward: Command;
  38. /**
  39. If the selection is empty and the cursor is at the end of a
  40. textblock, try to reduce or remove the boundary between that block
  41. and the one after it, either by joining them or by moving the other
  42. block closer to this one in the tree structure. Will use the view
  43. for accurate start-of-textblock detection if given.
  44. */
  45. declare const joinForward: Command;
  46. /**
  47. When the selection is empty and at the end of a textblock, select
  48. the node coming after that textblock, if possible. This is intended
  49. to be bound to keys like delete, after
  50. [`joinForward`](https://prosemirror.net/docs/ref/#commands.joinForward) and similar deleting
  51. commands, to provide a fall-back behavior when the schema doesn't
  52. allow deletion at the selected point.
  53. */
  54. declare const selectNodeForward: Command;
  55. /**
  56. Join the selected block or, if there is a text selection, the
  57. closest ancestor block of the selection that can be joined, with
  58. the sibling above it.
  59. */
  60. declare const joinUp: Command;
  61. /**
  62. Join the selected block, or the closest ancestor of the selection
  63. that can be joined, with the sibling after it.
  64. */
  65. declare const joinDown: Command;
  66. /**
  67. Lift the selected block, or the closest ancestor block of the
  68. selection that can be lifted, out of its parent node.
  69. */
  70. declare const lift: Command;
  71. /**
  72. If the selection is in a node whose type has a truthy
  73. [`code`](https://prosemirror.net/docs/ref/#model.NodeSpec.code) property in its spec, replace the
  74. selection with a newline character.
  75. */
  76. declare const newlineInCode: Command;
  77. /**
  78. When the selection is in a node with a truthy
  79. [`code`](https://prosemirror.net/docs/ref/#model.NodeSpec.code) property in its spec, create a
  80. default block after the code block, and move the cursor there.
  81. */
  82. declare const exitCode: Command;
  83. /**
  84. If a block node is selected, create an empty paragraph before (if
  85. it is its parent's first child) or after it.
  86. */
  87. declare const createParagraphNear: Command;
  88. /**
  89. If the cursor is in an empty textblock that can be lifted, lift the
  90. block.
  91. */
  92. declare const liftEmptyBlock: Command;
  93. /**
  94. Create a variant of [`splitBlock`](https://prosemirror.net/docs/ref/#commands.splitBlock) that uses
  95. a custom function to determine the type of the newly split off block.
  96. */
  97. declare function splitBlockAs(splitNode?: (node: Node, atEnd: boolean) => {
  98. type: NodeType;
  99. attrs?: Attrs;
  100. } | null): Command;
  101. /**
  102. Split the parent block of the selection. If the selection is a text
  103. selection, also delete its content.
  104. */
  105. declare const splitBlock: Command;
  106. /**
  107. Acts like [`splitBlock`](https://prosemirror.net/docs/ref/#commands.splitBlock), but without
  108. resetting the set of active marks at the cursor.
  109. */
  110. declare const splitBlockKeepMarks: Command;
  111. /**
  112. Move the selection to the node wrapping the current selection, if
  113. any. (Will not select the document node.)
  114. */
  115. declare const selectParentNode: Command;
  116. /**
  117. Select the whole document.
  118. */
  119. declare const selectAll: Command;
  120. /**
  121. Moves the cursor to the start of current text block.
  122. */
  123. declare const selectTextblockStart: Command;
  124. /**
  125. Moves the cursor to the end of current text block.
  126. */
  127. declare const selectTextblockEnd: Command;
  128. /**
  129. Wrap the selection in a node of the given type with the given
  130. attributes.
  131. */
  132. declare function wrapIn(nodeType: NodeType, attrs?: Attrs | null): Command;
  133. /**
  134. Returns a command that tries to set the selected textblocks to the
  135. given node type with the given attributes.
  136. */
  137. declare function setBlockType(nodeType: NodeType, attrs?: Attrs | null): Command;
  138. /**
  139. Create a command function that toggles the given mark with the
  140. given attributes. Will return `false` when the current selection
  141. doesn't support that mark. This will remove the mark if any marks
  142. of that type exist in the selection, or add it otherwise. If the
  143. selection is empty, this applies to the [stored
  144. marks](https://prosemirror.net/docs/ref/#state.EditorState.storedMarks) instead of a range of the
  145. document.
  146. */
  147. declare function toggleMark(markType: MarkType, attrs?: Attrs | null): Command;
  148. /**
  149. Wrap a command so that, when it produces a transform that causes
  150. two joinable nodes to end up next to each other, those are joined.
  151. Nodes are considered joinable when they are of the same type and
  152. when the `isJoinable` predicate returns true for them or, if an
  153. array of strings was passed, if their node type name is in that
  154. array.
  155. */
  156. declare function autoJoin(command: Command, isJoinable: ((before: Node, after: Node) => boolean) | readonly string[]): Command;
  157. /**
  158. Combine a number of command functions into a single function (which
  159. calls them one by one until one returns true).
  160. */
  161. declare function chainCommands(...commands: readonly Command[]): Command;
  162. /**
  163. A basic keymap containing bindings not specific to any schema.
  164. Binds the following keys (when multiple commands are listed, they
  165. are chained with [`chainCommands`](https://prosemirror.net/docs/ref/#commands.chainCommands)):
  166. * **Enter** to `newlineInCode`, `createParagraphNear`, `liftEmptyBlock`, `splitBlock`
  167. * **Mod-Enter** to `exitCode`
  168. * **Backspace** and **Mod-Backspace** to `deleteSelection`, `joinBackward`, `selectNodeBackward`
  169. * **Delete** and **Mod-Delete** to `deleteSelection`, `joinForward`, `selectNodeForward`
  170. * **Mod-Delete** to `deleteSelection`, `joinForward`, `selectNodeForward`
  171. * **Mod-a** to `selectAll`
  172. */
  173. declare const pcBaseKeymap: {
  174. [key: string]: Command;
  175. };
  176. /**
  177. A copy of `pcBaseKeymap` that also binds **Ctrl-h** like Backspace,
  178. **Ctrl-d** like Delete, **Alt-Backspace** like Ctrl-Backspace, and
  179. **Ctrl-Alt-Backspace**, **Alt-Delete**, and **Alt-d** like
  180. Ctrl-Delete.
  181. */
  182. declare const macBaseKeymap: {
  183. [key: string]: Command;
  184. };
  185. /**
  186. Depending on the detected platform, this will hold
  187. [`pcBasekeymap`](https://prosemirror.net/docs/ref/#commands.pcBaseKeymap) or
  188. [`macBaseKeymap`](https://prosemirror.net/docs/ref/#commands.macBaseKeymap).
  189. */
  190. declare const baseKeymap: {
  191. [key: string]: Command;
  192. };
  193. export { autoJoin, baseKeymap, chainCommands, createParagraphNear, deleteSelection, exitCode, joinBackward, joinDown, joinForward, joinTextblockBackward, joinTextblockForward, joinUp, lift, liftEmptyBlock, macBaseKeymap, newlineInCode, pcBaseKeymap, selectAll, selectNodeBackward, selectNodeForward, selectParentNode, selectTextblockEnd, selectTextblockStart, setBlockType, splitBlock, splitBlockAs, splitBlockKeepMarks, toggleMark, wrapIn };