@tiptap/core 2.3.2 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (184) hide show
  1. package/dist/index.cjs +273 -64
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +273 -64
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.umd.js +273 -64
  6. package/dist/index.umd.js.map +1 -1
  7. package/dist/packages/core/src/Extension.d.ts +129 -14
  8. package/dist/packages/core/src/ExtensionManager.d.ts +37 -0
  9. package/dist/packages/core/src/Mark.d.ts +129 -14
  10. package/dist/packages/core/src/Node.d.ts +226 -30
  11. package/dist/packages/core/src/NodeView.d.ts +4 -0
  12. package/dist/packages/core/src/PasteRule.d.ts +4 -0
  13. package/dist/packages/core/src/commands/blur.d.ts +1 -0
  14. package/dist/packages/core/src/commands/clearContent.d.ts +2 -0
  15. package/dist/packages/core/src/commands/clearNodes.d.ts +1 -0
  16. package/dist/packages/core/src/commands/command.d.ts +6 -0
  17. package/dist/packages/core/src/commands/createParagraphNear.d.ts +1 -0
  18. package/dist/packages/core/src/commands/cut.d.ts +5 -0
  19. package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +1 -0
  20. package/dist/packages/core/src/commands/deleteNode.d.ts +3 -1
  21. package/dist/packages/core/src/commands/deleteRange.d.ts +2 -0
  22. package/dist/packages/core/src/commands/deleteSelection.d.ts +1 -0
  23. package/dist/packages/core/src/commands/enter.d.ts +1 -0
  24. package/dist/packages/core/src/commands/exitCode.d.ts +1 -0
  25. package/dist/packages/core/src/commands/extendMarkRange.d.ts +14 -2
  26. package/dist/packages/core/src/commands/first.d.ts +2 -0
  27. package/dist/packages/core/src/commands/focus.d.ts +14 -1
  28. package/dist/packages/core/src/commands/insertContent.d.ts +17 -1
  29. package/dist/packages/core/src/commands/insertContentAt.d.ts +20 -1
  30. package/dist/packages/core/src/commands/join.d.ts +12 -4
  31. package/dist/packages/core/src/commands/joinItemBackward.d.ts +2 -1
  32. package/dist/packages/core/src/commands/joinItemForward.d.ts +2 -1
  33. package/dist/packages/core/src/commands/keyboardShortcut.d.ts +2 -0
  34. package/dist/packages/core/src/commands/lift.d.ts +5 -1
  35. package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +2 -1
  36. package/dist/packages/core/src/commands/liftListItem.d.ts +3 -1
  37. package/dist/packages/core/src/commands/newlineInCode.d.ts +1 -0
  38. package/dist/packages/core/src/commands/resetAttributes.d.ts +3 -0
  39. package/dist/packages/core/src/commands/scrollIntoView.d.ts +1 -0
  40. package/dist/packages/core/src/commands/selectAll.d.ts +1 -0
  41. package/dist/packages/core/src/commands/selectNodeBackward.d.ts +1 -0
  42. package/dist/packages/core/src/commands/selectNodeForward.d.ts +1 -0
  43. package/dist/packages/core/src/commands/selectParentNode.d.ts +1 -0
  44. package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +1 -0
  45. package/dist/packages/core/src/commands/selectTextblockStart.d.ts +1 -0
  46. package/dist/packages/core/src/commands/setContent.d.ts +19 -1
  47. package/dist/packages/core/src/commands/setMark.d.ts +2 -0
  48. package/dist/packages/core/src/commands/setMeta.d.ts +3 -0
  49. package/dist/packages/core/src/commands/setNode.d.ts +3 -0
  50. package/dist/packages/core/src/commands/setNodeSelection.d.ts +2 -0
  51. package/dist/packages/core/src/commands/setTextSelection.d.ts +2 -0
  52. package/dist/packages/core/src/commands/sinkListItem.d.ts +2 -0
  53. package/dist/packages/core/src/commands/splitBlock.d.ts +3 -0
  54. package/dist/packages/core/src/commands/splitListItem.d.ts +2 -0
  55. package/dist/packages/core/src/commands/toggleList.d.ts +5 -0
  56. package/dist/packages/core/src/commands/toggleMark.d.ts +13 -1
  57. package/dist/packages/core/src/commands/toggleNode.d.ts +4 -0
  58. package/dist/packages/core/src/commands/toggleWrap.d.ts +3 -0
  59. package/dist/packages/core/src/commands/undoInputRule.d.ts +1 -0
  60. package/dist/packages/core/src/commands/unsetAllMarks.d.ts +1 -0
  61. package/dist/packages/core/src/commands/unsetMark.d.ts +8 -1
  62. package/dist/packages/core/src/commands/updateAttributes.d.ts +12 -1
  63. package/dist/packages/core/src/commands/wrapIn.d.ts +3 -0
  64. package/dist/packages/core/src/commands/wrapInList.d.ts +3 -0
  65. package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +3 -0
  66. package/dist/packages/core/src/helpers/createChainableState.d.ts +5 -0
  67. package/dist/packages/core/src/helpers/createDocument.d.ts +7 -0
  68. package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +7 -0
  69. package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +5 -0
  70. package/dist/packages/core/src/helpers/findChildren.d.ts +6 -0
  71. package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +4 -0
  72. package/dist/packages/core/src/helpers/findParentNode.d.ts +8 -0
  73. package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +9 -0
  74. package/dist/packages/core/src/helpers/generateHTML.d.ts +6 -0
  75. package/dist/packages/core/src/helpers/generateJSON.d.ts +6 -0
  76. package/dist/packages/core/src/helpers/generateText.d.ts +7 -0
  77. package/dist/packages/core/src/helpers/getAttributes.d.ts +6 -0
  78. package/dist/packages/core/src/helpers/getExtensionField.d.ts +7 -0
  79. package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +6 -0
  80. package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +6 -0
  81. package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +6 -0
  82. package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +7 -0
  83. package/dist/packages/core/src/helpers/getText.d.ts +9 -0
  84. package/dist/packages/core/src/helpers/getTextBetween.d.ts +8 -0
  85. package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +6 -0
  86. package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +5 -0
  87. package/dist/packages/core/src/inputRules/markInputRule.d.ts +1 -0
  88. package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +1 -0
  89. package/dist/packages/core/src/inputRules/textInputRule.d.ts +1 -0
  90. package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +1 -0
  91. package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +1 -0
  92. package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +1 -0
  93. package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +1 -0
  94. package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +1 -0
  95. package/package.json +2 -2
  96. package/src/Extension.ts +130 -14
  97. package/src/ExtensionManager.ts +117 -85
  98. package/src/Mark.ts +129 -14
  99. package/src/Node.ts +226 -30
  100. package/src/NodeView.ts +4 -0
  101. package/src/PasteRule.ts +4 -0
  102. package/src/commands/blur.ts +1 -0
  103. package/src/commands/clearContent.ts +2 -0
  104. package/src/commands/clearNodes.ts +1 -0
  105. package/src/commands/command.ts +6 -0
  106. package/src/commands/createParagraphNear.ts +1 -0
  107. package/src/commands/cut.ts +5 -0
  108. package/src/commands/deleteCurrentNode.ts +1 -0
  109. package/src/commands/deleteNode.ts +3 -1
  110. package/src/commands/deleteRange.ts +2 -0
  111. package/src/commands/deleteSelection.ts +1 -0
  112. package/src/commands/enter.ts +1 -0
  113. package/src/commands/exitCode.ts +1 -0
  114. package/src/commands/extendMarkRange.ts +12 -1
  115. package/src/commands/first.ts +2 -0
  116. package/src/commands/focus.ts +12 -0
  117. package/src/commands/insertContent.ts +16 -0
  118. package/src/commands/insertContentAt.ts +19 -0
  119. package/src/commands/join.ts +12 -4
  120. package/src/commands/joinItemBackward.ts +2 -1
  121. package/src/commands/joinItemForward.ts +2 -1
  122. package/src/commands/keyboardShortcut.ts +2 -0
  123. package/src/commands/lift.ts +5 -1
  124. package/src/commands/liftEmptyBlock.ts +2 -1
  125. package/src/commands/liftListItem.ts +3 -1
  126. package/src/commands/newlineInCode.ts +1 -0
  127. package/src/commands/resetAttributes.ts +3 -0
  128. package/src/commands/scrollIntoView.ts +1 -0
  129. package/src/commands/selectAll.ts +1 -0
  130. package/src/commands/selectNodeBackward.ts +1 -0
  131. package/src/commands/selectNodeForward.ts +1 -0
  132. package/src/commands/selectParentNode.ts +1 -0
  133. package/src/commands/selectTextblockEnd.ts +1 -0
  134. package/src/commands/selectTextblockStart.ts +1 -0
  135. package/src/commands/setContent.ts +17 -0
  136. package/src/commands/setMark.ts +2 -0
  137. package/src/commands/setMeta.ts +3 -0
  138. package/src/commands/setNode.ts +3 -0
  139. package/src/commands/setNodeSelection.ts +2 -0
  140. package/src/commands/setTextSelection.ts +2 -0
  141. package/src/commands/sinkListItem.ts +2 -0
  142. package/src/commands/splitBlock.ts +3 -0
  143. package/src/commands/splitListItem.ts +2 -0
  144. package/src/commands/toggleList.ts +5 -0
  145. package/src/commands/toggleMark.ts +12 -0
  146. package/src/commands/toggleNode.ts +4 -0
  147. package/src/commands/toggleWrap.ts +3 -0
  148. package/src/commands/undoInputRule.ts +1 -0
  149. package/src/commands/unsetAllMarks.ts +1 -0
  150. package/src/commands/unsetMark.ts +7 -0
  151. package/src/commands/updateAttributes.ts +10 -0
  152. package/src/commands/wrapIn.ts +3 -0
  153. package/src/commands/wrapInList.ts +3 -0
  154. package/src/extensions/keymap.ts +7 -1
  155. package/src/helpers/combineTransactionSteps.ts +3 -0
  156. package/src/helpers/createChainableState.ts +5 -0
  157. package/src/helpers/createDocument.ts +7 -0
  158. package/src/helpers/createNodeFromContent.ts +16 -3
  159. package/src/helpers/defaultBlockAt.ts +5 -0
  160. package/src/helpers/findChildren.ts +6 -0
  161. package/src/helpers/findChildrenInRange.ts +4 -0
  162. package/src/helpers/findParentNode.ts +8 -0
  163. package/src/helpers/findParentNodeClosestToPos.ts +9 -0
  164. package/src/helpers/generateHTML.ts +6 -0
  165. package/src/helpers/generateJSON.ts +6 -0
  166. package/src/helpers/generateText.ts +7 -0
  167. package/src/helpers/getAttributes.ts +6 -0
  168. package/src/helpers/getExtensionField.ts +7 -0
  169. package/src/helpers/getSchemaByResolvedExtensions.ts +6 -0
  170. package/src/helpers/getSchemaTypeByName.ts +6 -0
  171. package/src/helpers/getSchemaTypeNameByName.ts +6 -0
  172. package/src/helpers/getSplittedAttributes.ts +7 -0
  173. package/src/helpers/getText.ts +9 -0
  174. package/src/helpers/getTextBetween.ts +12 -10
  175. package/src/helpers/getTextContentFromNodes.ts +6 -0
  176. package/src/helpers/getTextSerializersFromSchema.ts +5 -0
  177. package/src/inputRules/markInputRule.ts +1 -0
  178. package/src/inputRules/nodeInputRule.ts +1 -0
  179. package/src/inputRules/textInputRule.ts +1 -0
  180. package/src/inputRules/textblockTypeInputRule.ts +1 -0
  181. package/src/inputRules/wrappingInputRule.ts +1 -0
  182. package/src/pasteRules/markPasteRule.ts +1 -0
  183. package/src/pasteRules/nodePasteRule.ts +1 -0
  184. package/src/pasteRules/textPasteRule.ts +1 -0
@@ -9,12 +9,31 @@ declare module '@tiptap/core' {
9
9
  insertContentAt: {
10
10
  /**
11
11
  * Insert a node or string of HTML at a specific position.
12
+ * @example editor.commands.insertContentAt(0, '<h1>Example</h1>')
12
13
  */
13
14
  insertContentAt: (
15
+ /**
16
+ * The position to insert the content at.
17
+ */
14
18
  position: number | Range,
19
+
20
+ /**
21
+ * The ProseMirror content to insert.
22
+ */
15
23
  value: Content,
24
+
25
+ /**
26
+ * Optional options
27
+ */
16
28
  options?: {
29
+ /**
30
+ * Options for parsing the content.
31
+ */
17
32
  parseOptions?: ParseOptions
33
+
34
+ /**
35
+ * Whether to update the selection after inserting the content.
36
+ */
18
37
  updateSelection?: boolean
19
38
  applyInputRules?: boolean
20
39
  applyPasteRules?: boolean
@@ -11,25 +11,33 @@ declare module '@tiptap/core' {
11
11
  interface Commands<ReturnType> {
12
12
  joinUp: {
13
13
  /**
14
- * Join two nodes Up.
14
+ * Join the selected block or, if there is a text selection, the closest ancestor block of the selection that can be joined, with the sibling above it.
15
+ * @example editor.commands.joinUp()
15
16
  */
16
17
  joinUp: () => ReturnType
17
18
  }
18
19
  joinDown: {
19
20
  /**
20
- * Join two nodes Down.
21
+ * Join the selected block, or the closest ancestor of the selection that can be joined, with the sibling after it.
22
+ * @example editor.commands.joinDown()
21
23
  */
22
24
  joinDown: () => ReturnType
23
25
  }
24
26
  joinBackward: {
25
27
  /**
26
- * Join two nodes Backwards.
28
+ * If the selection is empty and at the start of a textblock, try to reduce the distance between that block and the one before it—if there's a block directly before it that can be joined, join them.
29
+ * If not, try to move the selected block closer to the next one in the document structure by lifting it out of its
30
+ * parent or moving it into a parent of the previous block. Will use the view for accurate (bidi-aware) start-of-textblock detection if given.
31
+ * @example editor.commands.joinBackward()
27
32
  */
28
33
  joinBackward: () => ReturnType
29
34
  }
30
35
  joinForward: {
31
36
  /**
32
- * Join two nodes Forwards.
37
+ * If the selection is empty and the cursor is at the end of a textblock, try to reduce or remove the boundary between that block and the one after it,
38
+ * either by joining them or by moving the other block closer to this one in the tree structure.
39
+ * Will use the view for accurate start-of-textblock detection if given.
40
+ * @example editor.commands.joinForward()
33
41
  */
34
42
  joinForward: () => ReturnType
35
43
  }
@@ -6,7 +6,8 @@ declare module '@tiptap/core' {
6
6
  interface Commands<ReturnType> {
7
7
  joinItemBackward: {
8
8
  /**
9
- * Join two nodes Forwards.
9
+ * Join two items backward.
10
+ * @example editor.commands.joinItemBackward()
10
11
  */
11
12
  joinItemBackward: () => ReturnType
12
13
  }
@@ -6,7 +6,8 @@ declare module '@tiptap/core' {
6
6
  interface Commands<ReturnType> {
7
7
  joinItemForward: {
8
8
  /**
9
- * Join two nodes Forwards.
9
+ * Join two items Forwards.
10
+ * @example editor.commands.joinItemForward()
10
11
  */
11
12
  joinItemForward: () => ReturnType
12
13
  }
@@ -61,6 +61,8 @@ declare module '@tiptap/core' {
61
61
  keyboardShortcut: {
62
62
  /**
63
63
  * Trigger a keyboard shortcut.
64
+ * @param name The name of the keyboard shortcut.
65
+ * @example editor.commands.keyboardShortcut('Mod-b')
64
66
  */
65
67
  keyboardShortcut: (name: string) => ReturnType,
66
68
  }
@@ -9,7 +9,11 @@ declare module '@tiptap/core' {
9
9
  interface Commands<ReturnType> {
10
10
  lift: {
11
11
  /**
12
- * Removes an existing wrap.
12
+ * Removes an existing wrap if possible lifting the node out of it
13
+ * @param typeOrName The type or name of the node.
14
+ * @param attributes The attributes of the node.
15
+ * @example editor.commands.lift('paragraph')
16
+ * @example editor.commands.lift('heading', { level: 1 })
13
17
  */
14
18
  lift: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType
15
19
  }
@@ -6,7 +6,8 @@ declare module '@tiptap/core' {
6
6
  interface Commands<ReturnType> {
7
7
  liftEmptyBlock: {
8
8
  /**
9
- * Lift block if empty.
9
+ * If the cursor is in an empty textblock that can be lifted, lift the block.
10
+ * @example editor.commands.liftEmptyBlock()
10
11
  */
11
12
  liftEmptyBlock: () => ReturnType,
12
13
  }
@@ -8,7 +8,9 @@ declare module '@tiptap/core' {
8
8
  interface Commands<ReturnType> {
9
9
  liftListItem: {
10
10
  /**
11
- * Lift the list item into a wrapping list.
11
+ * Create a command to lift the list item around the selection up into a wrapping list.
12
+ * @param typeOrName The type or name of the node.
13
+ * @example editor.commands.liftListItem('listItem')
12
14
  */
13
15
  liftListItem: (typeOrName: string | NodeType) => ReturnType
14
16
  }
@@ -7,6 +7,7 @@ declare module '@tiptap/core' {
7
7
  newlineInCode: {
8
8
  /**
9
9
  * Add a newline character in code.
10
+ * @example editor.commands.newlineInCode()
10
11
  */
11
12
  newlineInCode: () => ReturnType
12
13
  }
@@ -11,6 +11,9 @@ declare module '@tiptap/core' {
11
11
  resetAttributes: {
12
12
  /**
13
13
  * Resets some node attributes to the default value.
14
+ * @param typeOrName The type or name of the node.
15
+ * @param attributes The attributes of the node to reset.
16
+ * @example editor.commands.resetAttributes('heading', 'level')
14
17
  */
15
18
  resetAttributes: (
16
19
  typeOrName: string | NodeType | MarkType,
@@ -5,6 +5,7 @@ declare module '@tiptap/core' {
5
5
  scrollIntoView: {
6
6
  /**
7
7
  * Scroll the selection into view.
8
+ * @example editor.commands.scrollIntoView()
8
9
  */
9
10
  scrollIntoView: () => ReturnType,
10
11
  }
@@ -5,6 +5,7 @@ declare module '@tiptap/core' {
5
5
  selectAll: {
6
6
  /**
7
7
  * Select the whole document.
8
+ * @example editor.commands.selectAll()
8
9
  */
9
10
  selectAll: () => ReturnType,
10
11
  }
@@ -7,6 +7,7 @@ declare module '@tiptap/core' {
7
7
  selectNodeBackward: {
8
8
  /**
9
9
  * Select a node backward.
10
+ * @example editor.commands.selectNodeBackward()
10
11
  */
11
12
  selectNodeBackward: () => ReturnType
12
13
  }
@@ -7,6 +7,7 @@ declare module '@tiptap/core' {
7
7
  selectNodeForward: {
8
8
  /**
9
9
  * Select a node forward.
10
+ * @example editor.commands.selectNodeForward()
10
11
  */
11
12
  selectNodeForward: () => ReturnType
12
13
  }
@@ -7,6 +7,7 @@ declare module '@tiptap/core' {
7
7
  selectParentNode: {
8
8
  /**
9
9
  * Select the parent node.
10
+ * @example editor.commands.selectParentNode()
10
11
  */
11
12
  selectParentNode: () => ReturnType
12
13
  }
@@ -9,6 +9,7 @@ declare module '@tiptap/core' {
9
9
  selectTextblockEnd: {
10
10
  /**
11
11
  * Moves the cursor to the end of current text block.
12
+ * @example editor.commands.selectTextblockEnd()
12
13
  */
13
14
  selectTextblockEnd: () => ReturnType
14
15
  }
@@ -9,6 +9,7 @@ declare module '@tiptap/core' {
9
9
  selectTextblockStart: {
10
10
  /**
11
11
  * Moves the cursor to the start of current text block.
12
+ * @example editor.commands.selectTextblockStart()
12
13
  */
13
14
  selectTextblockStart: () => ReturnType
14
15
  }
@@ -8,10 +8,27 @@ declare module '@tiptap/core' {
8
8
  setContent: {
9
9
  /**
10
10
  * Replace the whole document with new content.
11
+ * @param content The new content.
12
+ * @param emitUpdate Whether to emit an update event.
13
+ * @param parseOptions Options for parsing the content.
14
+ * @example editor.commands.setContent('<p>Example text</p>')
11
15
  */
12
16
  setContent: (
17
+ /**
18
+ * The new content.
19
+ */
13
20
  content: Content,
21
+
22
+ /**
23
+ * Whether to emit an update event.
24
+ * @default false
25
+ */
14
26
  emitUpdate?: boolean,
27
+
28
+ /**
29
+ * Options for parsing the content.
30
+ * @default {}
31
+ */
15
32
  parseOptions?: ParseOptions,
16
33
  ) => ReturnType
17
34
  }
@@ -11,6 +11,8 @@ declare module '@tiptap/core' {
11
11
  setMark: {
12
12
  /**
13
13
  * Add a mark with new attributes.
14
+ * @param typeOrName The mark type or name.
15
+ * @example editor.commands.setMark('bold', { level: 1 })
14
16
  */
15
17
  setMark: (typeOrName: string | MarkType, attributes?: Record<string, any>) => ReturnType
16
18
  }
@@ -5,6 +5,9 @@ declare module '@tiptap/core' {
5
5
  setMeta: {
6
6
  /**
7
7
  * Store a metadata property in the current transaction.
8
+ * @param key The key of the metadata property.
9
+ * @param value The value to store.
10
+ * @example editor.commands.setMeta('foo', 'bar')
8
11
  */
9
12
  setMeta: (key: string, value: any) => ReturnType,
10
13
  }
@@ -9,6 +9,9 @@ declare module '@tiptap/core' {
9
9
  setNode: {
10
10
  /**
11
11
  * Replace a given range with a node.
12
+ * @param typeOrName The type or name of the node
13
+ * @param attributes The attributes of the node
14
+ * @example editor.commands.setNode('paragraph')
12
15
  */
13
16
  setNode: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType
14
17
  }
@@ -8,6 +8,8 @@ declare module '@tiptap/core' {
8
8
  setNodeSelection: {
9
9
  /**
10
10
  * Creates a NodeSelection.
11
+ * @param position - Position of the node.
12
+ * @example editor.commands.setNodeSelection(10)
11
13
  */
12
14
  setNodeSelection: (position: number) => ReturnType
13
15
  }
@@ -8,6 +8,8 @@ declare module '@tiptap/core' {
8
8
  setTextSelection: {
9
9
  /**
10
10
  * Creates a TextSelection.
11
+ * @param position The position of the selection.
12
+ * @example editor.commands.setTextSelection(10)
11
13
  */
12
14
  setTextSelection: (position: number | Range) => ReturnType
13
15
  }
@@ -9,6 +9,8 @@ declare module '@tiptap/core' {
9
9
  sinkListItem: {
10
10
  /**
11
11
  * Sink the list item down into an inner list.
12
+ * @param typeOrName The type or name of the node.
13
+ * @example editor.commands.sinkListItem('listItem')
12
14
  */
13
15
  sinkListItem: (typeOrName: string | NodeType) => ReturnType
14
16
  }
@@ -20,6 +20,9 @@ declare module '@tiptap/core' {
20
20
  splitBlock: {
21
21
  /**
22
22
  * Forks a new node from an existing node.
23
+ * @param options.keepMarks Keep marks from the previous node.
24
+ * @example editor.commands.splitBlock()
25
+ * @example editor.commands.splitBlock({ keepMarks: true })
23
26
  */
24
27
  splitBlock: (options?: { keepMarks?: boolean }) => ReturnType
25
28
  }
@@ -13,6 +13,8 @@ declare module '@tiptap/core' {
13
13
  splitListItem: {
14
14
  /**
15
15
  * Splits one list item into two list items.
16
+ * @param typeOrName The type or name of the node.
17
+ * @example editor.commands.splitListItem('listItem')
16
18
  */
17
19
  splitListItem: (typeOrName: string | NodeType) => ReturnType
18
20
  }
@@ -62,6 +62,11 @@ declare module '@tiptap/core' {
62
62
  toggleList: {
63
63
  /**
64
64
  * Toggle between different list types.
65
+ * @param listTypeOrName The type or name of the list.
66
+ * @param itemTypeOrName The type or name of the list item.
67
+ * @param keepMarks Keep marks when toggling.
68
+ * @param attributes Attributes for the new list.
69
+ * @example editor.commands.toggleList('bulletList', 'listItem')
65
70
  */
66
71
  toggleList: (listTypeOrName: string | NodeType, itemTypeOrName: string | NodeType, keepMarks?: boolean, attributes?: Record<string, any>) => ReturnType;
67
72
  }
@@ -9,10 +9,22 @@ declare module '@tiptap/core' {
9
9
  toggleMark: {
10
10
  /**
11
11
  * Toggle a mark on and off.
12
+ * @param typeOrName The mark type or name.
13
+ * @param attributes The attributes of the mark.
14
+ * @param options.extendEmptyMarkRange Removes the mark even across the current selection. Defaults to `false`.
15
+ * @example editor.commands.toggleMark('bold')
12
16
  */
13
17
  toggleMark: (
18
+ /**
19
+ * The mark type or name.
20
+ */
14
21
  typeOrName: string | MarkType,
22
+
23
+ /**
24
+ * The attributes of the mark.
25
+ */
15
26
  attributes?: Record<string, any>,
27
+
16
28
  options?: {
17
29
  /**
18
30
  * Removes the mark even across the current selection. Defaults to `false`.
@@ -9,6 +9,10 @@ declare module '@tiptap/core' {
9
9
  toggleNode: {
10
10
  /**
11
11
  * Toggle a node with another node.
12
+ * @param typeOrName The type or name of the node.
13
+ * @param toggleTypeOrName The type or name of the node to toggle.
14
+ * @param attributes The attributes of the node.
15
+ * @example editor.commands.toggleNode('heading', 'paragraph')
12
16
  */
13
17
  toggleNode: (
14
18
  typeOrName: string | NodeType,
@@ -9,6 +9,9 @@ declare module '@tiptap/core' {
9
9
  toggleWrap: {
10
10
  /**
11
11
  * Wraps nodes in another node, or removes an existing wrap.
12
+ * @param typeOrName The type or name of the node.
13
+ * @param attributes The attributes of the node.
14
+ * @example editor.commands.toggleWrap('blockquote')
12
15
  */
13
16
  toggleWrap: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType
14
17
  }
@@ -5,6 +5,7 @@ declare module '@tiptap/core' {
5
5
  undoInputRule: {
6
6
  /**
7
7
  * Undo an input rule.
8
+ * @example editor.commands.undoInputRule()
8
9
  */
9
10
  undoInputRule: () => ReturnType,
10
11
  }
@@ -5,6 +5,7 @@ declare module '@tiptap/core' {
5
5
  unsetAllMarks: {
6
6
  /**
7
7
  * Remove all marks in the current selection.
8
+ * @example editor.commands.unsetAllMarks()
8
9
  */
9
10
  unsetAllMarks: () => ReturnType,
10
11
  }
@@ -9,9 +9,16 @@ declare module '@tiptap/core' {
9
9
  unsetMark: {
10
10
  /**
11
11
  * Remove all marks in the current selection.
12
+ * @param typeOrName The mark type or name.
13
+ * @param options.extendEmptyMarkRange Removes the mark even across the current selection. Defaults to `false`.
14
+ * @example editor.commands.unsetMark('bold')
12
15
  */
13
16
  unsetMark: (
17
+ /**
18
+ * The mark type or name.
19
+ */
14
20
  typeOrName: string | MarkType,
21
+
15
22
  options?: {
16
23
  /**
17
24
  * Removes the mark even across the current selection. Defaults to `false`.
@@ -10,9 +10,19 @@ declare module '@tiptap/core' {
10
10
  updateAttributes: {
11
11
  /**
12
12
  * Update attributes of a node or mark.
13
+ * @param typeOrName The type or name of the node or mark.
14
+ * @param attributes The attributes of the node or mark.
15
+ * @example editor.commands.updateAttributes('mention', { userId: "2" })
13
16
  */
14
17
  updateAttributes: (
18
+ /**
19
+ * The type or name of the node or mark.
20
+ */
15
21
  typeOrName: string | NodeType | MarkType,
22
+
23
+ /**
24
+ * The attributes of the node or mark.
25
+ */
16
26
  attributes: Record<string, any>,
17
27
  ) => ReturnType
18
28
  }
@@ -9,6 +9,9 @@ declare module '@tiptap/core' {
9
9
  wrapIn: {
10
10
  /**
11
11
  * Wraps nodes in another node.
12
+ * @param typeOrName The type or name of the node.
13
+ * @param attributes The attributes of the node.
14
+ * @example editor.commands.wrapIn('blockquote')
12
15
  */
13
16
  wrapIn: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType
14
17
  }
@@ -9,6 +9,9 @@ declare module '@tiptap/core' {
9
9
  wrapInList: {
10
10
  /**
11
11
  * Wrap a node in a list.
12
+ * @param typeOrName The type or name of the node.
13
+ * @param attributes The attributes of the node.
14
+ * @example editor.commands.wrapInList('bulletList')
12
15
  */
13
16
  wrapInList: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType
14
17
  }
@@ -27,7 +27,13 @@ export const Keymap = Extension.create({
27
27
  ? parentPos === $anchor.pos
28
28
  : Selection.atStart(doc).from === pos
29
29
 
30
- if (!empty || !isAtStart || !parent.type.isTextblock || parent.textContent.length) {
30
+ if (
31
+ !empty
32
+ || !parent.type.isTextblock
33
+ || parent.textContent.length
34
+ || !isAtStart
35
+ || (isAtStart && $anchor.parent.type.name === 'paragraph') // prevent clearNodes when no nodes to clear, otherwise history stack is appended
36
+ ) {
31
37
  return false
32
38
  }
33
39
 
@@ -4,6 +4,9 @@ import { Transform } from '@tiptap/pm/transform'
4
4
 
5
5
  /**
6
6
  * Returns a new `Transform` based on all steps of the passed transactions.
7
+ * @param oldDoc The Prosemirror node to start from
8
+ * @param transactions The transactions to combine
9
+ * @returns A new `Transform` with all steps of the passed transactions
7
10
  */
8
11
  export function combineTransactionSteps(
9
12
  oldDoc: ProseMirrorNode,
@@ -1,5 +1,10 @@
1
1
  import { EditorState, Transaction } from '@tiptap/pm/state'
2
2
 
3
+ /**
4
+ * Takes a Transaction & Editor State and turns it into a chainable state object
5
+ * @param config The transaction and state to create the chainable state from
6
+ * @returns A chainable Editor state object
7
+ */
3
8
  export function createChainableState(config: {
4
9
  transaction: Transaction
5
10
  state: EditorState
@@ -3,6 +3,13 @@ import { Node as ProseMirrorNode, ParseOptions, Schema } from '@tiptap/pm/model'
3
3
  import { Content } from '../types.js'
4
4
  import { createNodeFromContent } from './createNodeFromContent.js'
5
5
 
6
+ /**
7
+ * Create a new Prosemirror document node from content.
8
+ * @param content The JSON or HTML content to create the document from
9
+ * @param schema The Prosemirror schema to use for the document
10
+ * @param parseOptions Options for the parser
11
+ * @returns The created Prosemirror document node
12
+ */
6
13
  export function createDocument(
7
14
  content: Content,
8
15
  schema: Schema,
@@ -14,6 +14,13 @@ export type CreateNodeFromContentOptions = {
14
14
  parseOptions?: ParseOptions
15
15
  }
16
16
 
17
+ /**
18
+ * Takes a JSON or HTML content and creates a Prosemirror node or fragment from it.
19
+ * @param content The JSON or HTML content to create the node from
20
+ * @param schema The Prosemirror schema to use for the node
21
+ * @param options Options for the parser
22
+ * @returns The created Prosemirror node or fragment
23
+ */
17
24
  export function createNodeFromContent(
18
25
  content: Content,
19
26
  schema: Schema,
@@ -25,9 +32,15 @@ export function createNodeFromContent(
25
32
  ...options,
26
33
  }
27
34
 
28
- if (typeof content === 'object' && content !== null) {
35
+ const isJSONContent = typeof content === 'object' && content !== null
36
+ const isTextContent = typeof content === 'string'
37
+
38
+ if (isJSONContent) {
29
39
  try {
30
- if (Array.isArray(content) && content.length > 0) {
40
+ const isArrayContent = Array.isArray(content) && content.length > 0
41
+
42
+ // if the JSON Content is an array of nodes, create a fragment for each node
43
+ if (isArrayContent) {
31
44
  return Fragment.fromArray(content.map(item => schema.nodeFromJSON(item)))
32
45
  }
33
46
 
@@ -39,7 +52,7 @@ export function createNodeFromContent(
39
52
  }
40
53
  }
41
54
 
42
- if (typeof content === 'string') {
55
+ if (isTextContent) {
43
56
  const parser = DOMParser.fromSchema(schema)
44
57
 
45
58
  return options.slice
@@ -1,5 +1,10 @@
1
1
  import { ContentMatch, NodeType } from '@tiptap/pm/model'
2
2
 
3
+ /**
4
+ * Gets the default block type at a given match
5
+ * @param match The content match to get the default block type from
6
+ * @returns The default block type or null
7
+ */
3
8
  export function defaultBlockAt(match: ContentMatch): NodeType | null {
4
9
  for (let i = 0; i < match.edgeCount; i += 1) {
5
10
  const { type } = match.edge(i)
@@ -2,6 +2,12 @@ import { Node as ProseMirrorNode } from '@tiptap/pm/model'
2
2
 
3
3
  import { NodeWithPos, Predicate } from '../types.js'
4
4
 
5
+ /**
6
+ * Find children inside a Prosemirror node that match a predicate.
7
+ * @param node The Prosemirror node to search in
8
+ * @param predicate The predicate to match
9
+ * @returns An array of nodes with their positions
10
+ */
5
11
  export function findChildren(node: ProseMirrorNode, predicate: Predicate): NodeWithPos[] {
6
12
  const nodesWithPos: NodeWithPos[] = []
7
13
 
@@ -4,6 +4,10 @@ import { NodeWithPos, Predicate, Range } from '../types.js'
4
4
 
5
5
  /**
6
6
  * Same as `findChildren` but searches only within a `range`.
7
+ * @param node The Prosemirror node to search in
8
+ * @param range The range to search in
9
+ * @param predicate The predicate to match
10
+ * @returns An array of nodes with their positions
7
11
  */
8
12
  export function findChildrenInRange(
9
13
  node: ProseMirrorNode,
@@ -3,6 +3,14 @@ import { Selection } from '@tiptap/pm/state'
3
3
  import { Predicate } from '../types.js'
4
4
  import { findParentNodeClosestToPos } from './findParentNodeClosestToPos.js'
5
5
 
6
+ /**
7
+ * Finds the closest parent node to the current selection that matches a predicate.
8
+ * @param predicate The predicate to match
9
+ * @returns A command that finds the closest parent node to the current selection that matches the predicate
10
+ * @example ```js
11
+ * findParentNode(node => node.type.name === 'paragraph')
12
+ * ```
13
+ */
6
14
  export function findParentNode(predicate: Predicate) {
7
15
  return (selection: Selection) => findParentNodeClosestToPos(selection.$from, predicate)
8
16
  }
@@ -2,6 +2,15 @@ import { Node as ProseMirrorNode, ResolvedPos } from '@tiptap/pm/model'
2
2
 
3
3
  import { Predicate } from '../types.js'
4
4
 
5
+ /**
6
+ * Finds the closest parent node to a resolved position that matches a predicate.
7
+ * @param $pos The resolved position to search from
8
+ * @param predicate The predicate to match
9
+ * @returns The closest parent node to the resolved position that matches the predicate
10
+ * @example ```js
11
+ * findParentNodeClosestToPos($from, node => node.type.name === 'paragraph')
12
+ * ```
13
+ */
5
14
  export function findParentNodeClosestToPos(
6
15
  $pos: ResolvedPos,
7
16
  predicate: Predicate,