@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
package/src/Node.ts CHANGED
@@ -26,22 +26,40 @@ declare module '@tiptap/core' {
26
26
  [key: string]: any
27
27
 
28
28
  /**
29
- * Name
29
+ * The extension name - this must be unique.
30
+ * It will be used to identify the extension.
31
+ *
32
+ * @example 'myExtension'
30
33
  */
31
34
  name: string
32
35
 
33
36
  /**
34
- * Priority
37
+ * The priority of your extension. The higher, the later it will be called
38
+ * and will take precedence over other extensions with a lower priority.
39
+ * @default 1000
40
+ * @example 1001
35
41
  */
36
42
  priority?: number
37
43
 
38
44
  /**
39
- * Default options
45
+ * The default options for this extension.
46
+ * @example
47
+ * defaultOptions: {
48
+ * myOption: 'foo',
49
+ * myOtherOption: 10,
50
+ * }
40
51
  */
41
52
  defaultOptions?: Options
42
53
 
43
54
  /**
44
- * Default Options
55
+ * This method will add options to this extension
56
+ * @see https://tiptap.dev/guide/custom-extensions#settings
57
+ * @example
58
+ * addOptions() {
59
+ * return {
60
+ * myOption: 'foo',
61
+ * myOtherOption: 10,
62
+ * }
45
63
  */
46
64
  addOptions?: (this: {
47
65
  name: string
@@ -49,7 +67,13 @@ declare module '@tiptap/core' {
49
67
  }) => Options
50
68
 
51
69
  /**
52
- * Default Storage
70
+ * The default storage this extension can save data to.
71
+ * @see https://tiptap.dev/guide/custom-extensions#storage
72
+ * @example
73
+ * defaultStorage: {
74
+ * prefetchedUsers: [],
75
+ * loading: false,
76
+ * }
53
77
  */
54
78
  addStorage?: (this: {
55
79
  name: string
@@ -58,7 +82,30 @@ declare module '@tiptap/core' {
58
82
  }) => Storage
59
83
 
60
84
  /**
61
- * Global attributes
85
+ * This function adds globalAttributes to specific nodes.
86
+ * @see https://tiptap.dev/guide/custom-extensions#global-attributes
87
+ * @example
88
+ * addGlobalAttributes() {
89
+ * return [
90
+ * {
91
+ // Extend the following extensions
92
+ * types: [
93
+ * 'heading',
94
+ * 'paragraph',
95
+ * ],
96
+ * // … with those attributes
97
+ * attributes: {
98
+ * textAlign: {
99
+ * default: 'left',
100
+ * renderHTML: attributes => ({
101
+ * style: `text-align: ${attributes.textAlign}`,
102
+ * }),
103
+ * parseHTML: element => element.style.textAlign || 'left',
104
+ * },
105
+ * },
106
+ * },
107
+ * ]
108
+ * }
62
109
  */
63
110
  addGlobalAttributes?: (this: {
64
111
  name: string
@@ -68,7 +115,14 @@ declare module '@tiptap/core' {
68
115
  }) => GlobalAttributes | {}
69
116
 
70
117
  /**
71
- * Raw
118
+ * This function adds commands to the editor
119
+ * @see https://tiptap.dev/guide/custom-extensions#keyboard-shortcuts
120
+ * @example
121
+ * addCommands() {
122
+ * return {
123
+ * myCommand: () => ({ chain }) => chain().setMark('type', 'foo').run(),
124
+ * }
125
+ * }
72
126
  */
73
127
  addCommands?: (this: {
74
128
  name: string
@@ -80,7 +134,14 @@ declare module '@tiptap/core' {
80
134
  }) => Partial<RawCommands>
81
135
 
82
136
  /**
83
- * Keyboard shortcuts
137
+ * This function registers keyboard shortcuts.
138
+ * @see https://tiptap.dev/guide/custom-extensions#keyboard-shortcuts
139
+ * @example
140
+ * addKeyboardShortcuts() {
141
+ * return {
142
+ * 'Mod-l': () => this.editor.commands.toggleBulletList(),
143
+ * }
144
+ * },
84
145
  */
85
146
  addKeyboardShortcuts?: (this: {
86
147
  name: string
@@ -94,7 +155,17 @@ declare module '@tiptap/core' {
94
155
  }
95
156
 
96
157
  /**
97
- * Input rules
158
+ * This function adds input rules to the editor.
159
+ * @see https://tiptap.dev/guide/custom-extensions#input-rules
160
+ * @example
161
+ * addInputRules() {
162
+ * return [
163
+ * markInputRule({
164
+ * find: inputRegex,
165
+ * type: this.type,
166
+ * }),
167
+ * ]
168
+ * },
98
169
  */
99
170
  addInputRules?: (this: {
100
171
  name: string
@@ -106,7 +177,17 @@ declare module '@tiptap/core' {
106
177
  }) => InputRule[]
107
178
 
108
179
  /**
109
- * Paste rules
180
+ * This function adds paste rules to the editor.
181
+ * @see https://tiptap.dev/guide/custom-extensions#paste-rules
182
+ * @example
183
+ * addPasteRules() {
184
+ * return [
185
+ * markPasteRule({
186
+ * find: pasteRegex,
187
+ * type: this.type,
188
+ * }),
189
+ * ]
190
+ * },
110
191
  */
111
192
  addPasteRules?: (this: {
112
193
  name: string
@@ -118,7 +199,14 @@ declare module '@tiptap/core' {
118
199
  }) => PasteRule[]
119
200
 
120
201
  /**
121
- * ProseMirror plugins
202
+ * This function adds Prosemirror plugins to the editor
203
+ * @see https://tiptap.dev/guide/custom-extensions#prosemirror-plugins
204
+ * @example
205
+ * addProseMirrorPlugins() {
206
+ * return [
207
+ * customPlugin(),
208
+ * ]
209
+ * }
122
210
  */
123
211
  addProseMirrorPlugins?: (this: {
124
212
  name: string
@@ -130,7 +218,16 @@ declare module '@tiptap/core' {
130
218
  }) => Plugin[]
131
219
 
132
220
  /**
133
- * Extensions
221
+ * This function adds additional extensions to the editor. This is useful for
222
+ * building extension kits.
223
+ * @example
224
+ * addExtensions() {
225
+ * return [
226
+ * BulletList,
227
+ * OrderedList,
228
+ * ListItem
229
+ * ]
230
+ * }
134
231
  */
135
232
  addExtensions?: (this: {
136
233
  name: string
@@ -140,7 +237,14 @@ declare module '@tiptap/core' {
140
237
  }) => Extensions
141
238
 
142
239
  /**
143
- * Extend Node Schema
240
+ * This function extends the schema of the node.
241
+ * @example
242
+ * extendNodeSchema() {
243
+ * return {
244
+ * group: 'inline',
245
+ * selectable: false,
246
+ * }
247
+ * }
144
248
  */
145
249
  extendNodeSchema?:
146
250
  | ((
@@ -155,7 +259,14 @@ declare module '@tiptap/core' {
155
259
  | null
156
260
 
157
261
  /**
158
- * Extend Mark Schema
262
+ * This function extends the schema of the mark.
263
+ * @example
264
+ * extendMarkSchema() {
265
+ * return {
266
+ * group: 'inline',
267
+ * selectable: false,
268
+ * }
269
+ * }
159
270
  */
160
271
  extendMarkSchema?:
161
272
  | ((
@@ -312,12 +423,22 @@ declare module '@tiptap/core' {
312
423
  | null
313
424
 
314
425
  /**
315
- * TopNode
426
+ * Defines if this node should be a top level node (doc)
427
+ * @default false
428
+ * @example true
316
429
  */
317
430
  topNode?: boolean
318
431
 
319
432
  /**
320
- * Content
433
+ * The content expression for this node, as described in the [schema
434
+ * guide](/docs/guide/#schema.content_expressions). When not given,
435
+ * the node does not allow any content.
436
+ *
437
+ * You can read more about it on the Prosemirror documentation here
438
+ * @see https://prosemirror.net/docs/guide/#schema.content_expressions
439
+ * @default undefined
440
+ * @example content: 'block+'
441
+ * @example content: 'headline paragraph block*'
321
442
  */
322
443
  content?:
323
444
  | NodeSpec['content']
@@ -330,7 +451,13 @@ declare module '@tiptap/core' {
330
451
  }) => NodeSpec['content'])
331
452
 
332
453
  /**
333
- * Marks
454
+ * The marks that are allowed inside of this node. May be a
455
+ * space-separated string referring to mark names or groups, `"_"`
456
+ * to explicitly allow all marks, or `""` to disallow marks. When
457
+ * not given, nodes with inline content default to allowing all
458
+ * marks, other nodes default to not allowing marks.
459
+ *
460
+ * @example marks: 'strong em'
334
461
  */
335
462
  marks?:
336
463
  | NodeSpec['marks']
@@ -343,7 +470,16 @@ declare module '@tiptap/core' {
343
470
  }) => NodeSpec['marks'])
344
471
 
345
472
  /**
346
- * Group
473
+ * The group or space-separated groups to which this node belongs,
474
+ * which can be referred to in the content expressions for the
475
+ * schema.
476
+ *
477
+ * By default Tiptap uses the groups 'block' and 'inline' for nodes. You
478
+ * can also use custom groups if you want to group specific nodes together
479
+ * and handle them in your schema.
480
+ * @example group: 'block'
481
+ * @example group: 'inline'
482
+ * @example group: 'customBlock' // this uses a custom group
347
483
  */
348
484
  group?:
349
485
  | NodeSpec['group']
@@ -356,7 +492,7 @@ declare module '@tiptap/core' {
356
492
  }) => NodeSpec['group'])
357
493
 
358
494
  /**
359
- * Inline
495
+ * Should be set to true for inline nodes. (Implied for text nodes.)
360
496
  */
361
497
  inline?:
362
498
  | NodeSpec['inline']
@@ -369,7 +505,11 @@ declare module '@tiptap/core' {
369
505
  }) => NodeSpec['inline'])
370
506
 
371
507
  /**
372
- * Atom
508
+ * Can be set to true to indicate that, though this isn't a [leaf
509
+ * node](https://prosemirror.net/docs/ref/#model.NodeType.isLeaf), it doesn't have directly editable
510
+ * content and should be treated as a single unit in the view.
511
+ *
512
+ * @example atom: true
373
513
  */
374
514
  atom?:
375
515
  | NodeSpec['atom']
@@ -382,7 +522,12 @@ declare module '@tiptap/core' {
382
522
  }) => NodeSpec['atom'])
383
523
 
384
524
  /**
385
- * Selectable
525
+ * Controls whether nodes of this type can be selected as a [node
526
+ * selection](https://prosemirror.net/docs/ref/#state.NodeSelection). Defaults to true for non-text
527
+ * nodes.
528
+ *
529
+ * @default true
530
+ * @example selectable: false
386
531
  */
387
532
  selectable?:
388
533
  | NodeSpec['selectable']
@@ -395,7 +540,11 @@ declare module '@tiptap/core' {
395
540
  }) => NodeSpec['selectable'])
396
541
 
397
542
  /**
398
- * Draggable
543
+ * Determines whether nodes of this type can be dragged without
544
+ * being selected. Defaults to false.
545
+ *
546
+ * @default: false
547
+ * @example: draggable: true
399
548
  */
400
549
  draggable?:
401
550
  | NodeSpec['draggable']
@@ -408,7 +557,8 @@ declare module '@tiptap/core' {
408
557
  }) => NodeSpec['draggable'])
409
558
 
410
559
  /**
411
- * Code
560
+ * Can be used to indicate that this node contains code, which
561
+ * causes some commands to behave differently.
412
562
  */
413
563
  code?:
414
564
  | NodeSpec['code']
@@ -421,7 +571,15 @@ declare module '@tiptap/core' {
421
571
  }) => NodeSpec['code'])
422
572
 
423
573
  /**
424
- * Whitespace
574
+ * Controls way whitespace in this a node is parsed. The default is
575
+ * `"normal"`, which causes the [DOM parser](https://prosemirror.net/docs/ref/#model.DOMParser) to
576
+ * collapse whitespace in normal mode, and normalize it (replacing
577
+ * newlines and such with spaces) otherwise. `"pre"` causes the
578
+ * parser to preserve spaces inside the node. When this option isn't
579
+ * given, but [`code`](https://prosemirror.net/docs/ref/#model.NodeSpec.code) is true, `whitespace`
580
+ * will default to `"pre"`. Note that this option doesn't influence
581
+ * the way the node is rendered—that should be handled by `toDOM`
582
+ * and/or styling.
425
583
  */
426
584
  whitespace?:
427
585
  | NodeSpec['whitespace']
@@ -434,7 +592,12 @@ declare module '@tiptap/core' {
434
592
  }) => NodeSpec['whitespace'])
435
593
 
436
594
  /**
437
- * Defining
595
+ * When enabled, enables both
596
+ * [`definingAsContext`](https://prosemirror.net/docs/ref/#model.NodeSpec.definingAsContext) and
597
+ * [`definingForContent`](https://prosemirror.net/docs/ref/#model.NodeSpec.definingForContent).
598
+ *
599
+ * @default false
600
+ * @example isolating: true
438
601
  */
439
602
  defining?:
440
603
  | NodeSpec['defining']
@@ -447,7 +610,10 @@ declare module '@tiptap/core' {
447
610
  }) => NodeSpec['defining'])
448
611
 
449
612
  /**
450
- * Isolating
613
+ * When enabled (default is false), the sides of nodes of this type
614
+ * count as boundaries that regular editing operations, like
615
+ * backspacing or lifting, won't cross. An example of a node that
616
+ * should probably have this enabled is a table cell.
451
617
  */
452
618
  isolating?:
453
619
  | NodeSpec['isolating']
@@ -460,7 +626,14 @@ declare module '@tiptap/core' {
460
626
  }) => NodeSpec['isolating'])
461
627
 
462
628
  /**
463
- * Parse HTML
629
+ * Associates DOM parser information with this node, which can be
630
+ * used by [`DOMParser.fromSchema`](https://prosemirror.net/docs/ref/#model.DOMParser^fromSchema) to
631
+ * automatically derive a parser. The `node` field in the rules is
632
+ * implied (the name of this node will be filled in automatically).
633
+ * If you supply your own parser, you do not need to also specify
634
+ * parsing rules in your schema.
635
+ *
636
+ * @example parseHTML: [{ tag: 'div', attrs: { 'data-id': 'my-block' } }]
464
637
  */
465
638
  parseHTML?: (this: {
466
639
  name: string
@@ -471,7 +644,24 @@ declare module '@tiptap/core' {
471
644
  }) => NodeSpec['parseDOM']
472
645
 
473
646
  /**
474
- * Render HTML
647
+ * A description of a DOM structure. Can be either a string, which is
648
+ * interpreted as a text node, a DOM node, which is interpreted as
649
+ * itself, a `{dom, contentDOM}` object, or an array.
650
+ *
651
+ * An array describes a DOM element. The first value in the array
652
+ * should be a string—the name of the DOM element, optionally prefixed
653
+ * by a namespace URL and a space. If the second element is plain
654
+ * object, it is interpreted as a set of attributes for the element.
655
+ * Any elements after that (including the 2nd if it's not an attribute
656
+ * object) are interpreted as children of the DOM elements, and must
657
+ * either be valid `DOMOutputSpec` values, or the number zero.
658
+ *
659
+ * The number zero (pronounced “hole”) is used to indicate the place
660
+ * where a node's child nodes should be inserted. If it occurs in an
661
+ * output spec, it should be the only child element in its parent
662
+ * node.
663
+ *
664
+ * @example toDOM: ['div[data-id="my-block"]', { class: 'my-block' }, 0]
475
665
  */
476
666
  renderHTML?:
477
667
  | ((
@@ -490,7 +680,8 @@ declare module '@tiptap/core' {
490
680
  | null
491
681
 
492
682
  /**
493
- * Render Text
683
+ * renders the node as text
684
+ * @example renderText: () => 'foo
494
685
  */
495
686
  renderText?:
496
687
  | ((
@@ -511,7 +702,8 @@ declare module '@tiptap/core' {
511
702
  | null
512
703
 
513
704
  /**
514
- * Add Attributes
705
+ * Add attributes to the node
706
+ * @example addAttributes: () => ({ class: 'foo' })
515
707
  */
516
708
  addAttributes?: (this: {
517
709
  name: string
@@ -523,6 +715,10 @@ declare module '@tiptap/core' {
523
715
  }
524
716
  }
525
717
 
718
+ /**
719
+ * The Node class is used to create custom node extensions.
720
+ * @see https://tiptap.dev/api/extensions#create-a-new-extension
721
+ */
526
722
  export class Node<Options = any, Storage = any> {
527
723
  type = 'node'
528
724
 
package/src/NodeView.ts CHANGED
@@ -8,6 +8,10 @@ import { DecorationWithType, NodeViewRendererOptions, NodeViewRendererProps } fr
8
8
  import { isAndroid } from './utilities/isAndroid.js'
9
9
  import { isiOS } from './utilities/isiOS.js'
10
10
 
11
+ /**
12
+ * Node views are used to customize the rendered DOM structure of a node.
13
+ * @see https://tiptap.dev/guide/node-views
14
+ */
11
15
  export class NodeView<
12
16
  Component,
13
17
  NodeEditor extends CoreEditor = CoreEditor,
package/src/PasteRule.ts CHANGED
@@ -23,6 +23,10 @@ export type PasteRuleMatch = {
23
23
 
24
24
  export type PasteRuleFinder = RegExp | ((text: string, event?: ClipboardEvent | null) => PasteRuleMatch[] | null | undefined)
25
25
 
26
+ /**
27
+ * Paste rules are used to react to pasted content.
28
+ * @see https://tiptap.dev/guide/custom-extensions/#paste-rules
29
+ */
26
30
  export class PasteRule {
27
31
  find: PasteRuleFinder
28
32
 
@@ -5,6 +5,7 @@ declare module '@tiptap/core' {
5
5
  blur: {
6
6
  /**
7
7
  * Removes focus from the editor.
8
+ * @example editor.commands.blur()
8
9
  */
9
10
  blur: () => ReturnType,
10
11
  }
@@ -5,6 +5,8 @@ declare module '@tiptap/core' {
5
5
  clearContent: {
6
6
  /**
7
7
  * Clear the whole document.
8
+ * @param emitUpdate Whether to emit an update event.
9
+ * @example editor.commands.clearContent()
8
10
  */
9
11
  clearContent: (emitUpdate?: boolean) => ReturnType,
10
12
  }
@@ -7,6 +7,7 @@ declare module '@tiptap/core' {
7
7
  clearNodes: {
8
8
  /**
9
9
  * Normalize nodes to a simple paragraph.
10
+ * @example editor.commands.clearNodes()
10
11
  */
11
12
  clearNodes: () => ReturnType,
12
13
  }
@@ -5,6 +5,12 @@ declare module '@tiptap/core' {
5
5
  command: {
6
6
  /**
7
7
  * Define a command inline.
8
+ * @param fn The command function.
9
+ * @example
10
+ * editor.commands.command(({ tr, state }) => {
11
+ * ...
12
+ * return true
13
+ * })
8
14
  */
9
15
  command: (fn: (props: Parameters<Command>[0]) => boolean) => ReturnType,
10
16
  }
@@ -7,6 +7,7 @@ declare module '@tiptap/core' {
7
7
  createParagraphNear: {
8
8
  /**
9
9
  * Create a paragraph nearby.
10
+ * @example editor.commands.createParagraphNear()
10
11
  */
11
12
  createParagraphNear: () => ReturnType
12
13
  }
@@ -7,6 +7,11 @@ declare module '@tiptap/core' {
7
7
  cut: {
8
8
  /**
9
9
  * Cuts content from a range and inserts it at a given position.
10
+ * @param range The range to cut.
11
+ * @param range.from The start position of the range.
12
+ * @param range.to The end position of the range.
13
+ * @param targetPos The position to insert the content at.
14
+ * @example editor.commands.cut({ from: 1, to: 3 }, 5)
10
15
  */
11
16
  cut: ({ from, to }: { from: number, to: number }, targetPos: number) => ReturnType,
12
17
  }
@@ -5,6 +5,7 @@ declare module '@tiptap/core' {
5
5
  deleteCurrentNode: {
6
6
  /**
7
7
  * Delete the node that currently has the selection anchor.
8
+ * @example editor.commands.deleteCurrentNode()
8
9
  */
9
10
  deleteCurrentNode: () => ReturnType,
10
11
  }
@@ -7,7 +7,9 @@ declare module '@tiptap/core' {
7
7
  interface Commands<ReturnType> {
8
8
  deleteNode: {
9
9
  /**
10
- * Delete a node.
10
+ * Delete a node with a given type or name.
11
+ * @param typeOrName The type or name of the node.
12
+ * @example editor.commands.deleteNode('paragraph')
11
13
  */
12
14
  deleteNode: (typeOrName: string | NodeType) => ReturnType,
13
15
  }
@@ -5,6 +5,8 @@ declare module '@tiptap/core' {
5
5
  deleteRange: {
6
6
  /**
7
7
  * Delete a given range.
8
+ * @param range The range to delete.
9
+ * @example editor.commands.deleteRange({ from: 1, to: 3 })
8
10
  */
9
11
  deleteRange: (range: Range) => ReturnType,
10
12
  }
@@ -7,6 +7,7 @@ declare module '@tiptap/core' {
7
7
  deleteSelection: {
8
8
  /**
9
9
  * Delete the selection, if there is one.
10
+ * @example editor.commands.deleteSelection()
10
11
  */
11
12
  deleteSelection: () => ReturnType
12
13
  }
@@ -5,6 +5,7 @@ declare module '@tiptap/core' {
5
5
  enter: {
6
6
  /**
7
7
  * Trigger enter.
8
+ * @example editor.commands.enter()
8
9
  */
9
10
  enter: () => ReturnType,
10
11
  }
@@ -7,6 +7,7 @@ declare module '@tiptap/core' {
7
7
  exitCode: {
8
8
  /**
9
9
  * Exit from a code block.
10
+ * @example editor.commands.exitCode()
10
11
  */
11
12
  exitCode: () => ReturnType
12
13
  }
@@ -9,10 +9,21 @@ declare module '@tiptap/core' {
9
9
  interface Commands<ReturnType> {
10
10
  extendMarkRange: {
11
11
  /**
12
- * Extends the text selection to the current mark.
12
+ * Extends the text selection to the current mark by type or name.
13
+ * @param typeOrName The type or name of the mark.
14
+ * @param attributes The attributes of the mark.
15
+ * @example editor.commands.extendMarkRange('bold')
16
+ * @example editor.commands.extendMarkRange('mention', { userId: "1" })
13
17
  */
14
18
  extendMarkRange: (
19
+ /**
20
+ * The type or name of the mark.
21
+ */
15
22
  typeOrName: string | MarkType,
23
+
24
+ /**
25
+ * The attributes of the mark.
26
+ */
16
27
  attributes?: Record<string, any>,
17
28
  ) => ReturnType
18
29
  }
@@ -5,6 +5,8 @@ declare module '@tiptap/core' {
5
5
  first: {
6
6
  /**
7
7
  * Runs one command after the other and stops at the first which returns true.
8
+ * @param commands The commands to run.
9
+ * @example editor.commands.first([command1, command2])
8
10
  */
9
11
  first: (commands: Command[] | ((props: CommandProps) => Command[])) => ReturnType,
10
12
  }
@@ -8,9 +8,21 @@ declare module '@tiptap/core' {
8
8
  focus: {
9
9
  /**
10
10
  * Focus the editor at the given position.
11
+ * @param position The position to focus at.
12
+ * @param options.scrollIntoView Scroll the focused position into view after focusing
13
+ * @example editor.commands.focus()
14
+ * @example editor.commands.focus(32, { scrollIntoView: false })
11
15
  */
12
16
  focus: (
17
+ /**
18
+ * The position to focus at.
19
+ */
13
20
  position?: FocusPosition,
21
+
22
+ /**
23
+ * Optional options
24
+ * @default { scrollIntoView: true }
25
+ */
14
26
  options?: {
15
27
  scrollIntoView?: boolean,
16
28
  },
@@ -7,11 +7,27 @@ declare module '@tiptap/core' {
7
7
  insertContent: {
8
8
  /**
9
9
  * Insert a node or string of HTML at the current position.
10
+ * @example editor.commands.insertContent('<h1>Example</h1>')
11
+ * @example editor.commands.insertContent('<h1>Example</h1>', { updateSelection: false })
10
12
  */
11
13
  insertContent: (
14
+ /**
15
+ * The ProseMirror content to insert.
16
+ */
12
17
  value: Content,
18
+
19
+ /**
20
+ * Optional options
21
+ */
13
22
  options?: {
23
+ /**
24
+ * Options for parsing the content.
25
+ */
14
26
  parseOptions?: ParseOptions
27
+
28
+ /**
29
+ * Whether to update the selection after inserting the content.
30
+ */
15
31
  updateSelection?: boolean
16
32
  applyInputRules?: boolean
17
33
  applyPasteRules?: boolean