@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/dist/index.cjs CHANGED
@@ -10,6 +10,11 @@ var transform = require('@tiptap/pm/transform');
10
10
  var commands$1 = require('@tiptap/pm/commands');
11
11
  var schemaList = require('@tiptap/pm/schema-list');
12
12
 
13
+ /**
14
+ * Takes a Transaction & Editor State and turns it into a chainable state object
15
+ * @param config The transaction and state to create the chainable state from
16
+ * @returns A chainable Editor state object
17
+ */
13
18
  function createChainableState(config) {
14
19
  const { state, transaction } = config;
15
20
  let { selection } = transaction;
@@ -176,6 +181,13 @@ class EventEmitter {
176
181
  }
177
182
  }
178
183
 
184
+ /**
185
+ * Returns a field from an extension
186
+ * @param extension The Tiptap extension
187
+ * @param field The field, for example `renderHTML` or `priority`
188
+ * @param context The context object that should be passed as `this` into the function
189
+ * @returns The field value
190
+ */
179
191
  function getExtensionField(extension, field, context) {
180
192
  if (extension.config[field] === undefined && extension.parent) {
181
193
  return getExtensionField(extension.parent, field, context);
@@ -420,6 +432,12 @@ function cleanUpSchemaItem(data) {
420
432
  return value !== null && value !== undefined;
421
433
  }));
422
434
  }
435
+ /**
436
+ * Creates a new Prosemirror schema based on the given extensions.
437
+ * @param extensions An array of Tiptap extensions
438
+ * @param editor The editor instance
439
+ * @returns A Prosemirror schema
440
+ */
423
441
  function getSchemaByResolvedExtensions(extensions, editor) {
424
442
  var _a;
425
443
  const allAttributes = getAttributesFromExtensions(extensions);
@@ -521,6 +539,12 @@ function getSchemaByResolvedExtensions(extensions, editor) {
521
539
  });
522
540
  }
523
541
 
542
+ /**
543
+ * Tries to get a node or mark type by its name.
544
+ * @param name The name of the node or mark type
545
+ * @param schema The Prosemiror schema to search in
546
+ * @returns The node or mark type, or null if it doesn't exist
547
+ */
524
548
  function getSchemaTypeByName(name, schema) {
525
549
  return schema.nodes[name] || schema.marks[name] || null;
526
550
  }
@@ -537,6 +561,12 @@ function isExtensionRulesEnabled(extension, enabled) {
537
561
  return enabled;
538
562
  }
539
563
 
564
+ /**
565
+ * Returns the text content of a resolved prosemirror position
566
+ * @param $from The resolved position to get the text content from
567
+ * @param maxMatch The maximum number of characters to match
568
+ * @returns The text content
569
+ */
540
570
  const getTextContentFromNodes = ($from, maxMatch = 500) => {
541
571
  let textBefore = '';
542
572
  const sliceEndPos = $from.parentOffset;
@@ -744,6 +774,10 @@ function isNumber(value) {
744
774
  return typeof value === 'number';
745
775
  }
746
776
 
777
+ /**
778
+ * Paste rules are used to react to pasted content.
779
+ * @see https://tiptap.dev/guide/custom-extensions/#paste-rules
780
+ */
747
781
  class PasteRule {
748
782
  constructor(config) {
749
783
  this.find = config.find;
@@ -942,57 +976,14 @@ class ExtensionManager {
942
976
  this.editor = editor;
943
977
  this.extensions = ExtensionManager.resolve(extensions);
944
978
  this.schema = getSchemaByResolvedExtensions(this.extensions, editor);
945
- this.extensions.forEach(extension => {
946
- var _a;
947
- // store extension storage in editor
948
- this.editor.extensionStorage[extension.name] = extension.storage;
949
- const context = {
950
- name: extension.name,
951
- options: extension.options,
952
- storage: extension.storage,
953
- editor: this.editor,
954
- type: getSchemaTypeByName(extension.name, this.schema),
955
- };
956
- if (extension.type === 'mark') {
957
- const keepOnSplit = (_a = callOrReturn(getExtensionField(extension, 'keepOnSplit', context))) !== null && _a !== void 0 ? _a : true;
958
- if (keepOnSplit) {
959
- this.splittableMarks.push(extension.name);
960
- }
961
- }
962
- const onBeforeCreate = getExtensionField(extension, 'onBeforeCreate', context);
963
- if (onBeforeCreate) {
964
- this.editor.on('beforeCreate', onBeforeCreate);
965
- }
966
- const onCreate = getExtensionField(extension, 'onCreate', context);
967
- if (onCreate) {
968
- this.editor.on('create', onCreate);
969
- }
970
- const onUpdate = getExtensionField(extension, 'onUpdate', context);
971
- if (onUpdate) {
972
- this.editor.on('update', onUpdate);
973
- }
974
- const onSelectionUpdate = getExtensionField(extension, 'onSelectionUpdate', context);
975
- if (onSelectionUpdate) {
976
- this.editor.on('selectionUpdate', onSelectionUpdate);
977
- }
978
- const onTransaction = getExtensionField(extension, 'onTransaction', context);
979
- if (onTransaction) {
980
- this.editor.on('transaction', onTransaction);
981
- }
982
- const onFocus = getExtensionField(extension, 'onFocus', context);
983
- if (onFocus) {
984
- this.editor.on('focus', onFocus);
985
- }
986
- const onBlur = getExtensionField(extension, 'onBlur', context);
987
- if (onBlur) {
988
- this.editor.on('blur', onBlur);
989
- }
990
- const onDestroy = getExtensionField(extension, 'onDestroy', context);
991
- if (onDestroy) {
992
- this.editor.on('destroy', onDestroy);
993
- }
994
- });
979
+ this.setupExtensions();
995
980
  }
981
+ /**
982
+ * Returns a flattened and sorted extension list while
983
+ * also checking for duplicated extensions and warns the user.
984
+ * @param extensions An array of Tiptap extensions
985
+ * @returns An flattened and sorted array of Tiptap extensions
986
+ */
996
987
  static resolve(extensions) {
997
988
  const resolvedExtensions = ExtensionManager.sort(ExtensionManager.flatten(extensions));
998
989
  const duplicatedNames = findDuplicates(resolvedExtensions.map(extension => extension.name));
@@ -1003,6 +994,11 @@ class ExtensionManager {
1003
994
  }
1004
995
  return resolvedExtensions;
1005
996
  }
997
+ /**
998
+ * Create a flattened array of extensions by traversing the `addExtensions` field.
999
+ * @param extensions An array of Tiptap extensions
1000
+ * @returns A flattened array of Tiptap extensions
1001
+ */
1006
1002
  static flatten(extensions) {
1007
1003
  return (extensions
1008
1004
  .map(extension => {
@@ -1020,6 +1016,11 @@ class ExtensionManager {
1020
1016
  // `Infinity` will break TypeScript so we set a number that is probably high enough
1021
1017
  .flat(10));
1022
1018
  }
1019
+ /**
1020
+ * Sort extensions by priority.
1021
+ * @param extensions An array of Tiptap extensions
1022
+ * @returns A sorted array of Tiptap extensions by priority
1023
+ */
1023
1024
  static sort(extensions) {
1024
1025
  const defaultPriority = 100;
1025
1026
  return extensions.sort((a, b) => {
@@ -1034,6 +1035,10 @@ class ExtensionManager {
1034
1035
  return 0;
1035
1036
  });
1036
1037
  }
1038
+ /**
1039
+ * Get all commands from the extensions.
1040
+ * @returns An object with all commands where the key is the command name and the value is the command function
1041
+ */
1037
1042
  get commands() {
1038
1043
  return this.extensions.reduce((commands, extension) => {
1039
1044
  const context = {
@@ -1053,6 +1058,10 @@ class ExtensionManager {
1053
1058
  };
1054
1059
  }, {});
1055
1060
  }
1061
+ /**
1062
+ * Get all registered Prosemirror plugins from the extensions.
1063
+ * @returns An array of Prosemirror plugins
1064
+ */
1056
1065
  get plugins() {
1057
1066
  const { editor } = this;
1058
1067
  // With ProseMirror, first plugins within an array are executed first.
@@ -1115,9 +1124,17 @@ class ExtensionManager {
1115
1124
  ...allPlugins,
1116
1125
  ];
1117
1126
  }
1127
+ /**
1128
+ * Get all attributes from the extensions.
1129
+ * @returns An array of attributes
1130
+ */
1118
1131
  get attributes() {
1119
1132
  return getAttributesFromExtensions(this.extensions);
1120
1133
  }
1134
+ /**
1135
+ * Get all node views from the extensions.
1136
+ * @returns An object with all node views where the key is the node name and the value is the node view function
1137
+ */
1121
1138
  get nodeViews() {
1122
1139
  const { editor } = this;
1123
1140
  const { nodeExtensions } = splitExtensions(this.extensions);
@@ -1150,6 +1167,62 @@ class ExtensionManager {
1150
1167
  return [extension.name, nodeview];
1151
1168
  }));
1152
1169
  }
1170
+ /**
1171
+ * Go through all extensions, create extension storages & setup marks
1172
+ * & bind editor event listener.
1173
+ */
1174
+ setupExtensions() {
1175
+ this.extensions.forEach(extension => {
1176
+ var _a;
1177
+ // store extension storage in editor
1178
+ this.editor.extensionStorage[extension.name] = extension.storage;
1179
+ const context = {
1180
+ name: extension.name,
1181
+ options: extension.options,
1182
+ storage: extension.storage,
1183
+ editor: this.editor,
1184
+ type: getSchemaTypeByName(extension.name, this.schema),
1185
+ };
1186
+ if (extension.type === 'mark') {
1187
+ const keepOnSplit = (_a = callOrReturn(getExtensionField(extension, 'keepOnSplit', context))) !== null && _a !== void 0 ? _a : true;
1188
+ if (keepOnSplit) {
1189
+ this.splittableMarks.push(extension.name);
1190
+ }
1191
+ }
1192
+ const onBeforeCreate = getExtensionField(extension, 'onBeforeCreate', context);
1193
+ const onCreate = getExtensionField(extension, 'onCreate', context);
1194
+ const onUpdate = getExtensionField(extension, 'onUpdate', context);
1195
+ const onSelectionUpdate = getExtensionField(extension, 'onSelectionUpdate', context);
1196
+ const onTransaction = getExtensionField(extension, 'onTransaction', context);
1197
+ const onFocus = getExtensionField(extension, 'onFocus', context);
1198
+ const onBlur = getExtensionField(extension, 'onBlur', context);
1199
+ const onDestroy = getExtensionField(extension, 'onDestroy', context);
1200
+ if (onBeforeCreate) {
1201
+ this.editor.on('beforeCreate', onBeforeCreate);
1202
+ }
1203
+ if (onCreate) {
1204
+ this.editor.on('create', onCreate);
1205
+ }
1206
+ if (onUpdate) {
1207
+ this.editor.on('update', onUpdate);
1208
+ }
1209
+ if (onSelectionUpdate) {
1210
+ this.editor.on('selectionUpdate', onSelectionUpdate);
1211
+ }
1212
+ if (onTransaction) {
1213
+ this.editor.on('transaction', onTransaction);
1214
+ }
1215
+ if (onFocus) {
1216
+ this.editor.on('focus', onFocus);
1217
+ }
1218
+ if (onBlur) {
1219
+ this.editor.on('blur', onBlur);
1220
+ }
1221
+ if (onDestroy) {
1222
+ this.editor.on('destroy', onDestroy);
1223
+ }
1224
+ });
1225
+ }
1153
1226
  }
1154
1227
 
1155
1228
  // see: https://github.com/mesqueeb/is-what/blob/88d6e4ca92fb2baab6003c54e02eedf4e729e5ab/src/index.ts
@@ -1183,6 +1256,10 @@ function mergeDeep(target, source) {
1183
1256
  return output;
1184
1257
  }
1185
1258
 
1259
+ /**
1260
+ * The Extension class is the base class for all extensions.
1261
+ * @see https://tiptap.dev/api/extensions#create-a-new-extension
1262
+ */
1186
1263
  class Extension {
1187
1264
  constructor(config = {}) {
1188
1265
  this.type = 'extension';
@@ -1220,6 +1297,7 @@ class Extension {
1220
1297
  // return a new instance so we can use the same extension
1221
1298
  // with different calls of `configure`
1222
1299
  const extension = this.extend();
1300
+ extension.parent = this.parent;
1223
1301
  extension.options = mergeDeep(this.options, options);
1224
1302
  extension.storage = callOrReturn(getExtensionField(extension, 'addStorage', {
1225
1303
  name: extension.name,
@@ -1246,19 +1324,25 @@ class Extension {
1246
1324
  }
1247
1325
  }
1248
1326
 
1327
+ /**
1328
+ * Gets the text between two positions in a Prosemirror node
1329
+ * and serializes it using the given text serializers and block separator (see getText)
1330
+ * @param startNode The Prosemirror node to start from
1331
+ * @param range The range of the text to get
1332
+ * @param options Options for the text serializer & block separator
1333
+ * @returns The text between the two positions
1334
+ */
1249
1335
  function getTextBetween(startNode, range, options) {
1250
1336
  const { from, to } = range;
1251
1337
  const { blockSeparator = '\n\n', textSerializers = {} } = options || {};
1252
1338
  let text = '';
1253
- let separated = true;
1254
1339
  startNode.nodesBetween(from, to, (node, pos, parent, index) => {
1255
1340
  var _a;
1341
+ if (node.isBlock && pos > from) {
1342
+ text += blockSeparator;
1343
+ }
1256
1344
  const textSerializer = textSerializers === null || textSerializers === void 0 ? void 0 : textSerializers[node.type.name];
1257
1345
  if (textSerializer) {
1258
- if (node.isBlock && !separated) {
1259
- text += blockSeparator;
1260
- separated = true;
1261
- }
1262
1346
  if (parent) {
1263
1347
  text += textSerializer({
1264
1348
  node,
@@ -1273,16 +1357,16 @@ function getTextBetween(startNode, range, options) {
1273
1357
  }
1274
1358
  if (node.isText) {
1275
1359
  text += (_a = node === null || node === void 0 ? void 0 : node.text) === null || _a === void 0 ? void 0 : _a.slice(Math.max(from, pos) - pos, to - pos); // eslint-disable-line
1276
- separated = false;
1277
- }
1278
- else if (node.isBlock && !separated) {
1279
- text += blockSeparator;
1280
- separated = true;
1281
1360
  }
1282
1361
  });
1283
1362
  return text;
1284
1363
  }
1285
1364
 
1365
+ /**
1366
+ * Find text serializers `toText` in a Prosemirror schema
1367
+ * @param schema The Prosemirror schema to search in
1368
+ * @returns A record of text serializers by node name
1369
+ */
1286
1370
  function getTextSerializersFromSchema(schema) {
1287
1371
  return Object.fromEntries(Object.entries(schema.nodes)
1288
1372
  .filter(([, node]) => node.spec.toText)
@@ -1665,15 +1749,26 @@ function elementFromString(value) {
1665
1749
  return removeWhitespaces(html);
1666
1750
  }
1667
1751
 
1752
+ /**
1753
+ * Takes a JSON or HTML content and creates a Prosemirror node or fragment from it.
1754
+ * @param content The JSON or HTML content to create the node from
1755
+ * @param schema The Prosemirror schema to use for the node
1756
+ * @param options Options for the parser
1757
+ * @returns The created Prosemirror node or fragment
1758
+ */
1668
1759
  function createNodeFromContent(content, schema, options) {
1669
1760
  options = {
1670
1761
  slice: true,
1671
1762
  parseOptions: {},
1672
1763
  ...options,
1673
1764
  };
1674
- if (typeof content === 'object' && content !== null) {
1765
+ const isJSONContent = typeof content === 'object' && content !== null;
1766
+ const isTextContent = typeof content === 'string';
1767
+ if (isJSONContent) {
1675
1768
  try {
1676
- if (Array.isArray(content) && content.length > 0) {
1769
+ const isArrayContent = Array.isArray(content) && content.length > 0;
1770
+ // if the JSON Content is an array of nodes, create a fragment for each node
1771
+ if (isArrayContent) {
1677
1772
  return model.Fragment.fromArray(content.map(item => schema.nodeFromJSON(item)));
1678
1773
  }
1679
1774
  return schema.nodeFromJSON(content);
@@ -1683,7 +1778,7 @@ function createNodeFromContent(content, schema, options) {
1683
1778
  return createNodeFromContent('', schema, options);
1684
1779
  }
1685
1780
  }
1686
- if (typeof content === 'string') {
1781
+ if (isTextContent) {
1687
1782
  const parser = model.DOMParser.fromSchema(schema);
1688
1783
  return options.slice
1689
1784
  ? parser.parseSlice(elementFromString(content), options.parseOptions).content
@@ -1983,6 +2078,12 @@ const newlineInCode = () => ({ state, dispatch }) => {
1983
2078
  return commands$1.newlineInCode(state, dispatch);
1984
2079
  };
1985
2080
 
2081
+ /**
2082
+ * Get the type of a schema item by its name.
2083
+ * @param name The name of the schema item
2084
+ * @param schema The Prosemiror schema to search in
2085
+ * @returns The type of the schema item (`node` or `mark`), or null if it doesn't exist
2086
+ */
1986
2087
  function getSchemaTypeNameByName(name, schema) {
1987
2088
  if (schema.nodes[name]) {
1988
2089
  return 'node';
@@ -2080,6 +2181,13 @@ const selectTextblockStart = () => ({ state, dispatch }) => {
2080
2181
  return commands$1.selectTextblockStart(state, dispatch);
2081
2182
  };
2082
2183
 
2184
+ /**
2185
+ * Create a new Prosemirror document node from content.
2186
+ * @param content The JSON or HTML content to create the document from
2187
+ * @param schema The Prosemirror schema to use for the document
2188
+ * @param parseOptions Options for the parser
2189
+ * @returns The created Prosemirror document node
2190
+ */
2083
2191
  function createDocument(content, schema, parseOptions = {}) {
2084
2192
  return createNodeFromContent(content, schema, { slice: false, parseOptions });
2085
2193
  }
@@ -2117,6 +2225,9 @@ function getMarkAttributes(state, typeOrName) {
2117
2225
 
2118
2226
  /**
2119
2227
  * Returns a new `Transform` based on all steps of the passed transactions.
2228
+ * @param oldDoc The Prosemirror node to start from
2229
+ * @param transactions The transactions to combine
2230
+ * @returns A new `Transform` with all steps of the passed transactions
2120
2231
  */
2121
2232
  function combineTransactionSteps(oldDoc, transactions) {
2122
2233
  const transform$1 = new transform.Transform(oldDoc);
@@ -2128,6 +2239,11 @@ function combineTransactionSteps(oldDoc, transactions) {
2128
2239
  return transform$1;
2129
2240
  }
2130
2241
 
2242
+ /**
2243
+ * Gets the default block type at a given match
2244
+ * @param match The content match to get the default block type from
2245
+ * @returns The default block type or null
2246
+ */
2131
2247
  function defaultBlockAt(match) {
2132
2248
  for (let i = 0; i < match.edgeCount; i += 1) {
2133
2249
  const { type } = match.edge(i);
@@ -2138,6 +2254,12 @@ function defaultBlockAt(match) {
2138
2254
  return null;
2139
2255
  }
2140
2256
 
2257
+ /**
2258
+ * Find children inside a Prosemirror node that match a predicate.
2259
+ * @param node The Prosemirror node to search in
2260
+ * @param predicate The predicate to match
2261
+ * @returns An array of nodes with their positions
2262
+ */
2141
2263
  function findChildren(node, predicate) {
2142
2264
  const nodesWithPos = [];
2143
2265
  node.descendants((child, pos) => {
@@ -2153,6 +2275,10 @@ function findChildren(node, predicate) {
2153
2275
 
2154
2276
  /**
2155
2277
  * Same as `findChildren` but searches only within a `range`.
2278
+ * @param node The Prosemirror node to search in
2279
+ * @param range The range to search in
2280
+ * @param predicate The predicate to match
2281
+ * @returns An array of nodes with their positions
2156
2282
  */
2157
2283
  function findChildrenInRange(node, range, predicate) {
2158
2284
  const nodesWithPos = [];
@@ -2176,6 +2302,15 @@ function findChildrenInRange(node, range, predicate) {
2176
2302
  return nodesWithPos;
2177
2303
  }
2178
2304
 
2305
+ /**
2306
+ * Finds the closest parent node to a resolved position that matches a predicate.
2307
+ * @param $pos The resolved position to search from
2308
+ * @param predicate The predicate to match
2309
+ * @returns The closest parent node to the resolved position that matches the predicate
2310
+ * @example ```js
2311
+ * findParentNodeClosestToPos($from, node => node.type.name === 'paragraph')
2312
+ * ```
2313
+ */
2179
2314
  function findParentNodeClosestToPos($pos, predicate) {
2180
2315
  for (let i = $pos.depth; i > 0; i -= 1) {
2181
2316
  const node = $pos.node(i);
@@ -2190,6 +2325,14 @@ function findParentNodeClosestToPos($pos, predicate) {
2190
2325
  }
2191
2326
  }
2192
2327
 
2328
+ /**
2329
+ * Finds the closest parent node to the current selection that matches a predicate.
2330
+ * @param predicate The predicate to match
2331
+ * @returns A command that finds the closest parent node to the current selection that matches the predicate
2332
+ * @example ```js
2333
+ * findParentNode(node => node.type.name === 'paragraph')
2334
+ * ```
2335
+ */
2193
2336
  function findParentNode(predicate) {
2194
2337
  return (selection) => findParentNodeClosestToPos(selection.$from, predicate);
2195
2338
  }
@@ -2207,18 +2350,39 @@ function getSchema(extensions, editor) {
2207
2350
  return getSchemaByResolvedExtensions(resolvedExtensions, editor);
2208
2351
  }
2209
2352
 
2353
+ /**
2354
+ * Generate HTML from a JSONContent
2355
+ * @param doc The JSONContent to generate HTML from
2356
+ * @param extensions The extensions to use for the schema
2357
+ * @returns The generated HTML
2358
+ */
2210
2359
  function generateHTML(doc, extensions) {
2211
2360
  const schema = getSchema(extensions);
2212
2361
  const contentNode = model.Node.fromJSON(schema, doc);
2213
2362
  return getHTMLFromFragment(contentNode.content, schema);
2214
2363
  }
2215
2364
 
2365
+ /**
2366
+ * Generate JSONContent from HTML
2367
+ * @param html The HTML to generate JSONContent from
2368
+ * @param extensions The extensions to use for the schema
2369
+ * @returns The generated JSONContent
2370
+ */
2216
2371
  function generateJSON(html, extensions) {
2217
2372
  const schema = getSchema(extensions);
2218
2373
  const dom = elementFromString(html);
2219
2374
  return model.DOMParser.fromSchema(schema).parse(dom).toJSON();
2220
2375
  }
2221
2376
 
2377
+ /**
2378
+ * Gets the text of a Prosemirror node
2379
+ * @param node The Prosemirror node
2380
+ * @param options Options for the text serializer & block separator
2381
+ * @returns The text of the node
2382
+ * @example ```js
2383
+ * const text = getText(node, { blockSeparator: '\n' })
2384
+ * ```
2385
+ */
2222
2386
  function getText(node, options) {
2223
2387
  const range = {
2224
2388
  from: 0,
@@ -2227,6 +2391,13 @@ function getText(node, options) {
2227
2391
  return getTextBetween(node, range, options);
2228
2392
  }
2229
2393
 
2394
+ /**
2395
+ * Generate raw text from a JSONContent
2396
+ * @param doc The JSONContent to generate text from
2397
+ * @param extensions The extensions to use for the schema
2398
+ * @param options Options for the text generation f.e. blockSeparator or textSerializers
2399
+ * @returns The generated text
2400
+ */
2230
2401
  function generateText(doc, extensions, options) {
2231
2402
  const { blockSeparator = '\n\n', textSerializers = {} } = options || {};
2232
2403
  const schema = getSchema(extensions);
@@ -2254,6 +2425,12 @@ function getNodeAttributes(state, typeOrName) {
2254
2425
  return { ...node.attrs };
2255
2426
  }
2256
2427
 
2428
+ /**
2429
+ * Get node or mark attributes by type or name on the current editor state
2430
+ * @param state The current editor state
2431
+ * @param typeOrName The node or mark type or name
2432
+ * @returns The attributes of the node or mark or an empty object
2433
+ */
2257
2434
  function getAttributes(state, typeOrName) {
2258
2435
  const schemaType = getSchemaTypeNameByName(typeof typeOrName === 'string' ? typeOrName : typeOrName.name, state.schema);
2259
2436
  if (schemaType === 'node') {
@@ -2438,6 +2615,13 @@ const getNodeAtPosition = (state, typeOrName, pos, maxDepth = 20) => {
2438
2615
  return [node, currentDepth];
2439
2616
  };
2440
2617
 
2618
+ /**
2619
+ * Return attributes of an extension that should be splitted by keepOnSplit flag
2620
+ * @param extensionAttributes Array of extension attributes
2621
+ * @param typeName The type of the extension
2622
+ * @param attributes The attributes of the extension
2623
+ * @returns The splitted attributes
2624
+ */
2441
2625
  function getSplittedAttributes(extensionAttributes, typeName, attributes) {
2442
2626
  return Object.fromEntries(Object
2443
2627
  .entries(attributes)
@@ -3288,7 +3472,12 @@ const Keymap = Extension.create({
3288
3472
  const isAtStart = (parentIsIsolating && $parentPos.parent.childCount === 1)
3289
3473
  ? parentPos === $anchor.pos
3290
3474
  : state.Selection.atStart(doc).from === pos;
3291
- if (!empty || !isAtStart || !parent.type.isTextblock || parent.textContent.length) {
3475
+ if (!empty
3476
+ || !parent.type.isTextblock
3477
+ || parent.textContent.length
3478
+ || !isAtStart
3479
+ || (isAtStart && $anchor.parent.type.name === 'paragraph') // prevent clearNodes when no nodes to clear, otherwise history stack is appended
3480
+ ) {
3292
3481
  return false;
3293
3482
  }
3294
3483
  return commands.clearNodes();
@@ -4060,6 +4249,7 @@ class Editor extends EventEmitter {
4060
4249
  /**
4061
4250
  * Build an input rule that adds a mark when the
4062
4251
  * matched text is typed into it.
4252
+ * @see https://tiptap.dev/guide/custom-extensions/#input-rules
4063
4253
  */
4064
4254
  function markInputRule(config) {
4065
4255
  return new InputRule({
@@ -4103,6 +4293,7 @@ function markInputRule(config) {
4103
4293
  /**
4104
4294
  * Build an input rule that adds a node when the
4105
4295
  * matched text is typed into it.
4296
+ * @see https://tiptap.dev/guide/custom-extensions/#input-rules
4106
4297
  */
4107
4298
  function nodeInputRule(config) {
4108
4299
  return new InputRule({
@@ -4141,6 +4332,7 @@ function nodeInputRule(config) {
4141
4332
  * matched text is typed into it. When using a regular expresion you’ll
4142
4333
  * probably want the regexp to start with `^`, so that the pattern can
4143
4334
  * only occur at the start of a textblock.
4335
+ * @see https://tiptap.dev/guide/custom-extensions/#input-rules
4144
4336
  */
4145
4337
  function textblockTypeInputRule(config) {
4146
4338
  return new InputRule({
@@ -4161,6 +4353,7 @@ function textblockTypeInputRule(config) {
4161
4353
  /**
4162
4354
  * Build an input rule that replaces text when the
4163
4355
  * matched text is typed into it.
4356
+ * @see https://tiptap.dev/guide/custom-extensions/#input-rules
4164
4357
  */
4165
4358
  function textInputRule(config) {
4166
4359
  return new InputRule({
@@ -4197,6 +4390,7 @@ function textInputRule(config) {
4197
4390
  * two nodes. You can pass a join predicate, which takes a regular
4198
4391
  * expression match and the node before the wrapped node, and can
4199
4392
  * return a boolean to indicate whether a join should happen.
4393
+ * @see https://tiptap.dev/guide/custom-extensions/#input-rules
4200
4394
  */
4201
4395
  function wrappingInputRule(config) {
4202
4396
  return new InputRule({
@@ -4236,6 +4430,10 @@ function wrappingInputRule(config) {
4236
4430
  });
4237
4431
  }
4238
4432
 
4433
+ /**
4434
+ * The Mark class is used to create custom mark extensions.
4435
+ * @see https://tiptap.dev/api/extensions#create-a-new-extension
4436
+ */
4239
4437
  class Mark {
4240
4438
  constructor(config = {}) {
4241
4439
  this.type = 'mark';
@@ -4319,6 +4517,10 @@ class Mark {
4319
4517
  }
4320
4518
  }
4321
4519
 
4520
+ /**
4521
+ * The Node class is used to create custom node extensions.
4522
+ * @see https://tiptap.dev/api/extensions#create-a-new-extension
4523
+ */
4322
4524
  class Node {
4323
4525
  constructor(config = {}) {
4324
4526
  this.type = 'node';
@@ -4386,6 +4588,10 @@ function isAndroid() {
4386
4588
  return navigator.platform === 'Android' || /android/i.test(navigator.userAgent);
4387
4589
  }
4388
4590
 
4591
+ /**
4592
+ * Node views are used to customize the rendered DOM structure of a node.
4593
+ * @see https://tiptap.dev/guide/node-views
4594
+ */
4389
4595
  class NodeView {
4390
4596
  constructor(component, props, options) {
4391
4597
  this.isDragging = false;
@@ -4576,6 +4782,7 @@ class NodeView {
4576
4782
  /**
4577
4783
  * Build an paste rule that adds a mark when the
4578
4784
  * matched text is pasted into it.
4785
+ * @see https://tiptap.dev/guide/custom-extensions/#paste-rules
4579
4786
  */
4580
4787
  function markPasteRule(config) {
4581
4788
  return new PasteRule({
@@ -4629,6 +4836,7 @@ function isString(value) {
4629
4836
  /**
4630
4837
  * Build an paste rule that adds a node when the
4631
4838
  * matched text is pasted into it.
4839
+ * @see https://tiptap.dev/guide/custom-extensions/#paste-rules
4632
4840
  */
4633
4841
  function nodePasteRule(config) {
4634
4842
  return new PasteRule({
@@ -4651,6 +4859,7 @@ function nodePasteRule(config) {
4651
4859
  /**
4652
4860
  * Build an paste rule that replaces text when the
4653
4861
  * matched text is pasted into it.
4862
+ * @see https://tiptap.dev/guide/custom-extensions/#paste-rules
4654
4863
  */
4655
4864
  function textPasteRule(config) {
4656
4865
  return new PasteRule({