@tiptap/core 3.0.0 → 3.0.2

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 (340) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +5 -1
  3. package/dist/index.cjs +5169 -4654
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.cts +3356 -0
  6. package/dist/index.d.ts +3356 -0
  7. package/dist/index.js +5051 -4561
  8. package/dist/index.js.map +1 -1
  9. package/dist/jsx-runtime/jsx-runtime.cjs +56 -0
  10. package/dist/jsx-runtime/jsx-runtime.cjs.map +1 -0
  11. package/dist/jsx-runtime/jsx-runtime.d.cts +22 -0
  12. package/dist/jsx-runtime/jsx-runtime.d.ts +22 -0
  13. package/dist/jsx-runtime/jsx-runtime.js +26 -0
  14. package/dist/jsx-runtime/jsx-runtime.js.map +1 -0
  15. package/jsx-dev-runtime/index.cjs +1 -0
  16. package/jsx-dev-runtime/index.d.cts +1 -0
  17. package/jsx-dev-runtime/index.d.ts +1 -0
  18. package/jsx-dev-runtime/index.js +1 -0
  19. package/jsx-runtime/index.cjs +1 -0
  20. package/jsx-runtime/index.d.cts +1 -0
  21. package/jsx-runtime/index.d.ts +1 -0
  22. package/jsx-runtime/index.js +1 -0
  23. package/package.json +30 -10
  24. package/src/CommandManager.ts +4 -11
  25. package/src/Editor.ts +273 -100
  26. package/src/EventEmitter.ts +16 -10
  27. package/src/Extendable.ts +484 -0
  28. package/src/Extension.ts +29 -493
  29. package/src/ExtensionManager.ts +100 -143
  30. package/src/InputRule.ts +28 -24
  31. package/src/Mark.ts +157 -624
  32. package/src/MarkView.ts +122 -0
  33. package/src/Node.ts +343 -807
  34. package/src/NodePos.ts +18 -9
  35. package/src/NodeView.ts +58 -35
  36. package/src/PasteRule.ts +68 -24
  37. package/src/Tracker.ts +8 -10
  38. package/src/commands/blur.ts +15 -13
  39. package/src/commands/clearContent.ts +13 -6
  40. package/src/commands/clearNodes.ts +33 -31
  41. package/src/commands/command.ts +2 -2
  42. package/src/commands/createParagraphNear.ts +6 -4
  43. package/src/commands/cut.ts +13 -11
  44. package/src/commands/deleteCurrentNode.ts +24 -22
  45. package/src/commands/deleteNode.ts +20 -18
  46. package/src/commands/deleteRange.ts +11 -9
  47. package/src/commands/deleteSelection.ts +6 -4
  48. package/src/commands/enter.ts +7 -5
  49. package/src/commands/exitCode.ts +6 -4
  50. package/src/commands/extendMarkRange.ts +16 -14
  51. package/src/commands/first.ts +3 -5
  52. package/src/commands/focus.ts +51 -53
  53. package/src/commands/forEach.ts +3 -3
  54. package/src/commands/insertContent.ts +8 -10
  55. package/src/commands/insertContentAt.ts +131 -76
  56. package/src/commands/join.ts +21 -13
  57. package/src/commands/joinItemBackward.ts +17 -19
  58. package/src/commands/joinItemForward.ts +17 -19
  59. package/src/commands/joinTextblockBackward.ts +6 -4
  60. package/src/commands/joinTextblockForward.ts +6 -4
  61. package/src/commands/keyboardShortcut.ts +30 -35
  62. package/src/commands/lift.ts +12 -10
  63. package/src/commands/liftEmptyBlock.ts +7 -5
  64. package/src/commands/liftListItem.ts +8 -6
  65. package/src/commands/newlineInCode.ts +6 -4
  66. package/src/commands/resetAttributes.ts +38 -43
  67. package/src/commands/scrollIntoView.ts +10 -8
  68. package/src/commands/selectAll.ts +15 -8
  69. package/src/commands/selectNodeBackward.ts +6 -4
  70. package/src/commands/selectNodeForward.ts +6 -4
  71. package/src/commands/selectParentNode.ts +6 -4
  72. package/src/commands/selectTextblockEnd.ts +6 -4
  73. package/src/commands/selectTextblockStart.ts +6 -4
  74. package/src/commands/setContent.ts +37 -40
  75. package/src/commands/setMark.ts +58 -60
  76. package/src/commands/setMeta.ts +10 -6
  77. package/src/commands/setNode.ts +36 -27
  78. package/src/commands/setNodeSelection.ts +12 -10
  79. package/src/commands/setTextSelection.ts +16 -14
  80. package/src/commands/sinkListItem.ts +8 -6
  81. package/src/commands/splitBlock.ts +60 -68
  82. package/src/commands/splitListItem.ts +99 -101
  83. package/src/commands/toggleList.ts +76 -74
  84. package/src/commands/toggleMark.ts +13 -11
  85. package/src/commands/toggleNode.ts +22 -11
  86. package/src/commands/toggleWrap.ts +12 -10
  87. package/src/commands/undoInputRule.ts +32 -30
  88. package/src/commands/unsetAllMarks.ts +17 -15
  89. package/src/commands/unsetMark.ts +29 -27
  90. package/src/commands/updateAttributes.ts +97 -45
  91. package/src/commands/wrapIn.ts +8 -6
  92. package/src/commands/wrapInList.ts +8 -6
  93. package/src/extensions/clipboardTextSerializer.ts +2 -4
  94. package/src/extensions/delete.ts +89 -0
  95. package/src/extensions/drop.ts +26 -0
  96. package/src/extensions/focusEvents.ts +5 -7
  97. package/src/extensions/index.ts +4 -1
  98. package/src/extensions/keymap.ts +63 -52
  99. package/src/extensions/paste.ts +25 -0
  100. package/src/extensions/tabindex.ts +1 -1
  101. package/src/helpers/combineTransactionSteps.ts +3 -6
  102. package/src/helpers/createChainableState.ts +2 -5
  103. package/src/helpers/createDocument.ts +3 -3
  104. package/src/helpers/createNodeFromContent.ts +37 -25
  105. package/src/helpers/defaultBlockAt.ts +1 -1
  106. package/src/helpers/findChildren.ts +2 -2
  107. package/src/helpers/findChildrenInRange.ts +3 -7
  108. package/src/helpers/findParentNode.ts +5 -3
  109. package/src/helpers/findParentNodeClosestToPos.ts +2 -2
  110. package/src/helpers/flattenExtensions.ts +30 -0
  111. package/src/helpers/generateHTML.ts +1 -1
  112. package/src/helpers/generateJSON.ts +1 -1
  113. package/src/helpers/generateText.ts +1 -1
  114. package/src/helpers/getAttributes.ts +3 -6
  115. package/src/helpers/getAttributesFromExtensions.ts +29 -38
  116. package/src/helpers/getChangedRanges.ts +15 -13
  117. package/src/helpers/getDebugJSON.ts +2 -2
  118. package/src/helpers/getExtensionField.ts +12 -12
  119. package/src/helpers/getHTMLFromFragment.ts +2 -1
  120. package/src/helpers/getMarkAttributes.ts +3 -6
  121. package/src/helpers/getMarkRange.ts +36 -19
  122. package/src/helpers/getMarkType.ts +2 -4
  123. package/src/helpers/getMarksBetween.ts +3 -3
  124. package/src/helpers/getNodeAtPosition.ts +2 -2
  125. package/src/helpers/getNodeAttributes.ts +3 -6
  126. package/src/helpers/getNodeType.ts +2 -4
  127. package/src/helpers/getRenderedAttributes.ts +3 -2
  128. package/src/helpers/getSchema.ts +5 -5
  129. package/src/helpers/getSchemaByResolvedExtensions.ts +49 -79
  130. package/src/helpers/getSchemaTypeByName.ts +1 -1
  131. package/src/helpers/getSchemaTypeNameByName.ts +1 -1
  132. package/src/helpers/getSplittedAttributes.ts +5 -5
  133. package/src/helpers/getText.ts +2 -2
  134. package/src/helpers/getTextBetween.ts +2 -2
  135. package/src/helpers/getTextContentFromNodes.ts +9 -12
  136. package/src/helpers/getTextSerializersFromSchema.ts +2 -2
  137. package/src/helpers/index.ts +4 -0
  138. package/src/helpers/injectExtensionAttributesToParseRule.ts +3 -3
  139. package/src/helpers/isActive.ts +2 -6
  140. package/src/helpers/isAtEndOfNode.ts +1 -1
  141. package/src/helpers/isAtStartOfNode.ts +1 -1
  142. package/src/helpers/isExtensionRulesEnabled.ts +2 -4
  143. package/src/helpers/isList.ts +2 -2
  144. package/src/helpers/isMarkActive.ts +3 -3
  145. package/src/helpers/isNodeActive.ts +3 -3
  146. package/src/helpers/isNodeEmpty.ts +56 -5
  147. package/src/helpers/posToDOMRect.ts +1 -1
  148. package/src/helpers/resolveExtensions.ts +25 -0
  149. package/src/helpers/resolveFocusPosition.ts +5 -16
  150. package/src/helpers/rewriteUnknownContent.ts +149 -0
  151. package/src/helpers/selectionToInsertionEnd.ts +2 -1
  152. package/src/helpers/sortExtensions.ts +26 -0
  153. package/src/helpers/splitExtensions.ts +4 -4
  154. package/src/index.ts +3 -7
  155. package/src/inputRules/markInputRule.ts +6 -9
  156. package/src/inputRules/nodeInputRule.ts +7 -13
  157. package/src/inputRules/textInputRule.ts +4 -6
  158. package/src/inputRules/textblockTypeInputRule.ts +7 -12
  159. package/src/inputRules/wrappingInputRule.ts +19 -24
  160. package/src/jsx-runtime.ts +64 -0
  161. package/src/pasteRules/markPasteRule.ts +6 -7
  162. package/src/pasteRules/nodePasteRule.ts +15 -11
  163. package/src/pasteRules/textPasteRule.ts +4 -6
  164. package/src/style.ts +2 -6
  165. package/src/types.ts +513 -58
  166. package/src/utilities/callOrReturn.ts +1 -1
  167. package/src/utilities/canInsertNode.ts +30 -0
  168. package/src/utilities/createStyleTag.ts +3 -1
  169. package/src/utilities/deleteProps.ts +7 -11
  170. package/src/utilities/elementFromString.ts +3 -0
  171. package/src/utilities/findDuplicates.ts +5 -2
  172. package/src/utilities/index.ts +2 -0
  173. package/src/utilities/isFunction.ts +1 -0
  174. package/src/utilities/isMacOS.ts +1 -3
  175. package/src/utilities/isiOS.ts +5 -10
  176. package/src/utilities/mergeAttributes.ts +32 -5
  177. package/src/utilities/removeDuplicates.ts +1 -3
  178. package/dist/index.umd.js +0 -5098
  179. package/dist/index.umd.js.map +0 -1
  180. package/dist/packages/core/src/CommandManager.d.ts +0 -20
  181. package/dist/packages/core/src/Editor.d.ts +0 -161
  182. package/dist/packages/core/src/EventEmitter.d.ts +0 -11
  183. package/dist/packages/core/src/Extension.d.ts +0 -343
  184. package/dist/packages/core/src/ExtensionManager.d.ts +0 -55
  185. package/dist/packages/core/src/InputRule.d.ts +0 -42
  186. package/dist/packages/core/src/Mark.d.ts +0 -451
  187. package/dist/packages/core/src/Node.d.ts +0 -611
  188. package/dist/packages/core/src/NodePos.d.ts +0 -44
  189. package/dist/packages/core/src/NodeView.d.ts +0 -31
  190. package/dist/packages/core/src/PasteRule.d.ts +0 -50
  191. package/dist/packages/core/src/Tracker.d.ts +0 -11
  192. package/dist/packages/core/src/commands/blur.d.ts +0 -13
  193. package/dist/packages/core/src/commands/clearContent.d.ts +0 -14
  194. package/dist/packages/core/src/commands/clearNodes.d.ts +0 -13
  195. package/dist/packages/core/src/commands/command.d.ts +0 -18
  196. package/dist/packages/core/src/commands/createParagraphNear.d.ts +0 -13
  197. package/dist/packages/core/src/commands/cut.d.ts +0 -20
  198. package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +0 -13
  199. package/dist/packages/core/src/commands/deleteNode.d.ts +0 -15
  200. package/dist/packages/core/src/commands/deleteRange.d.ts +0 -14
  201. package/dist/packages/core/src/commands/deleteSelection.d.ts +0 -13
  202. package/dist/packages/core/src/commands/enter.d.ts +0 -13
  203. package/dist/packages/core/src/commands/exitCode.d.ts +0 -13
  204. package/dist/packages/core/src/commands/extendMarkRange.d.ts +0 -25
  205. package/dist/packages/core/src/commands/first.d.ts +0 -14
  206. package/dist/packages/core/src/commands/focus.d.ts +0 -27
  207. package/dist/packages/core/src/commands/forEach.d.ts +0 -14
  208. package/dist/packages/core/src/commands/index.d.ts +0 -55
  209. package/dist/packages/core/src/commands/insertContent.d.ts +0 -34
  210. package/dist/packages/core/src/commands/insertContentAt.d.ts +0 -47
  211. package/dist/packages/core/src/commands/join.d.ts +0 -41
  212. package/dist/packages/core/src/commands/joinItemBackward.d.ts +0 -13
  213. package/dist/packages/core/src/commands/joinItemForward.d.ts +0 -13
  214. package/dist/packages/core/src/commands/joinTextblockBackward.d.ts +0 -12
  215. package/dist/packages/core/src/commands/joinTextblockForward.d.ts +0 -12
  216. package/dist/packages/core/src/commands/keyboardShortcut.d.ts +0 -14
  217. package/dist/packages/core/src/commands/lift.d.ts +0 -17
  218. package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +0 -13
  219. package/dist/packages/core/src/commands/liftListItem.d.ts +0 -15
  220. package/dist/packages/core/src/commands/newlineInCode.d.ts +0 -13
  221. package/dist/packages/core/src/commands/resetAttributes.d.ts +0 -16
  222. package/dist/packages/core/src/commands/scrollIntoView.d.ts +0 -13
  223. package/dist/packages/core/src/commands/selectAll.d.ts +0 -13
  224. package/dist/packages/core/src/commands/selectNodeBackward.d.ts +0 -13
  225. package/dist/packages/core/src/commands/selectNodeForward.d.ts +0 -13
  226. package/dist/packages/core/src/commands/selectParentNode.d.ts +0 -13
  227. package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +0 -13
  228. package/dist/packages/core/src/commands/selectTextblockStart.d.ts +0 -13
  229. package/dist/packages/core/src/commands/setContent.d.ts +0 -40
  230. package/dist/packages/core/src/commands/setMark.d.ts +0 -15
  231. package/dist/packages/core/src/commands/setMeta.d.ts +0 -15
  232. package/dist/packages/core/src/commands/setNode.d.ts +0 -16
  233. package/dist/packages/core/src/commands/setNodeSelection.d.ts +0 -14
  234. package/dist/packages/core/src/commands/setTextSelection.d.ts +0 -14
  235. package/dist/packages/core/src/commands/sinkListItem.d.ts +0 -15
  236. package/dist/packages/core/src/commands/splitBlock.d.ts +0 -17
  237. package/dist/packages/core/src/commands/splitListItem.d.ts +0 -15
  238. package/dist/packages/core/src/commands/toggleList.d.ts +0 -18
  239. package/dist/packages/core/src/commands/toggleMark.d.ts +0 -30
  240. package/dist/packages/core/src/commands/toggleNode.d.ts +0 -17
  241. package/dist/packages/core/src/commands/toggleWrap.d.ts +0 -16
  242. package/dist/packages/core/src/commands/undoInputRule.d.ts +0 -13
  243. package/dist/packages/core/src/commands/unsetAllMarks.d.ts +0 -13
  244. package/dist/packages/core/src/commands/unsetMark.d.ts +0 -25
  245. package/dist/packages/core/src/commands/updateAttributes.d.ts +0 -24
  246. package/dist/packages/core/src/commands/wrapIn.d.ts +0 -16
  247. package/dist/packages/core/src/commands/wrapInList.d.ts +0 -16
  248. package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +0 -5
  249. package/dist/packages/core/src/extensions/commands.d.ts +0 -3
  250. package/dist/packages/core/src/extensions/editable.d.ts +0 -2
  251. package/dist/packages/core/src/extensions/focusEvents.d.ts +0 -2
  252. package/dist/packages/core/src/extensions/index.d.ts +0 -6
  253. package/dist/packages/core/src/extensions/keymap.d.ts +0 -2
  254. package/dist/packages/core/src/extensions/tabindex.d.ts +0 -2
  255. package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +0 -10
  256. package/dist/packages/core/src/helpers/createChainableState.d.ts +0 -10
  257. package/dist/packages/core/src/helpers/createDocument.d.ts +0 -12
  258. package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +0 -15
  259. package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +0 -7
  260. package/dist/packages/core/src/helpers/findChildren.d.ts +0 -9
  261. package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +0 -10
  262. package/dist/packages/core/src/helpers/findParentNode.d.ts +0 -16
  263. package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +0 -17
  264. package/dist/packages/core/src/helpers/generateHTML.d.ts +0 -8
  265. package/dist/packages/core/src/helpers/generateJSON.d.ts +0 -8
  266. package/dist/packages/core/src/helpers/generateText.d.ts +0 -12
  267. package/dist/packages/core/src/helpers/getAttributes.d.ts +0 -9
  268. package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +0 -6
  269. package/dist/packages/core/src/helpers/getChangedRanges.d.ts +0 -11
  270. package/dist/packages/core/src/helpers/getDebugJSON.d.ts +0 -8
  271. package/dist/packages/core/src/helpers/getExtensionField.d.ts +0 -9
  272. package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +0 -2
  273. package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +0 -3
  274. package/dist/packages/core/src/helpers/getMarkRange.d.ts +0 -3
  275. package/dist/packages/core/src/helpers/getMarkType.d.ts +0 -2
  276. package/dist/packages/core/src/helpers/getMarksBetween.d.ts +0 -3
  277. package/dist/packages/core/src/helpers/getNodeAtPosition.d.ts +0 -11
  278. package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +0 -3
  279. package/dist/packages/core/src/helpers/getNodeType.d.ts +0 -2
  280. package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +0 -3
  281. package/dist/packages/core/src/helpers/getSchema.d.ts +0 -4
  282. package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +0 -10
  283. package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +0 -8
  284. package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +0 -8
  285. package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +0 -9
  286. package/dist/packages/core/src/helpers/getText.d.ts +0 -15
  287. package/dist/packages/core/src/helpers/getTextBetween.d.ts +0 -14
  288. package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +0 -8
  289. package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +0 -8
  290. package/dist/packages/core/src/helpers/index.d.ts +0 -50
  291. package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +0 -9
  292. package/dist/packages/core/src/helpers/isActive.d.ts +0 -2
  293. package/dist/packages/core/src/helpers/isAtEndOfNode.d.ts +0 -2
  294. package/dist/packages/core/src/helpers/isAtStartOfNode.d.ts +0 -2
  295. package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +0 -2
  296. package/dist/packages/core/src/helpers/isList.d.ts +0 -2
  297. package/dist/packages/core/src/helpers/isMarkActive.d.ts +0 -3
  298. package/dist/packages/core/src/helpers/isNodeActive.d.ts +0 -3
  299. package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +0 -2
  300. package/dist/packages/core/src/helpers/isNodeSelection.d.ts +0 -2
  301. package/dist/packages/core/src/helpers/isTextSelection.d.ts +0 -2
  302. package/dist/packages/core/src/helpers/posToDOMRect.d.ts +0 -2
  303. package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +0 -4
  304. package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +0 -2
  305. package/dist/packages/core/src/helpers/splitExtensions.d.ts +0 -9
  306. package/dist/packages/core/src/index.d.ts +0 -24
  307. package/dist/packages/core/src/inputRules/index.d.ts +0 -5
  308. package/dist/packages/core/src/inputRules/markInputRule.d.ts +0 -13
  309. package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -23
  310. package/dist/packages/core/src/inputRules/textInputRule.d.ts +0 -10
  311. package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +0 -15
  312. package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +0 -28
  313. package/dist/packages/core/src/pasteRules/index.d.ts +0 -3
  314. package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +0 -13
  315. package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +0 -13
  316. package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +0 -10
  317. package/dist/packages/core/src/style.d.ts +0 -1
  318. package/dist/packages/core/src/types.d.ts +0 -255
  319. package/dist/packages/core/src/utilities/callOrReturn.d.ts +0 -9
  320. package/dist/packages/core/src/utilities/createStyleTag.d.ts +0 -1
  321. package/dist/packages/core/src/utilities/deleteProps.d.ts +0 -6
  322. package/dist/packages/core/src/utilities/elementFromString.d.ts +0 -1
  323. package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +0 -1
  324. package/dist/packages/core/src/utilities/findDuplicates.d.ts +0 -1
  325. package/dist/packages/core/src/utilities/fromString.d.ts +0 -1
  326. package/dist/packages/core/src/utilities/index.d.ts +0 -20
  327. package/dist/packages/core/src/utilities/isAndroid.d.ts +0 -1
  328. package/dist/packages/core/src/utilities/isEmptyObject.d.ts +0 -1
  329. package/dist/packages/core/src/utilities/isFunction.d.ts +0 -1
  330. package/dist/packages/core/src/utilities/isMacOS.d.ts +0 -1
  331. package/dist/packages/core/src/utilities/isNumber.d.ts +0 -1
  332. package/dist/packages/core/src/utilities/isPlainObject.d.ts +0 -1
  333. package/dist/packages/core/src/utilities/isRegExp.d.ts +0 -1
  334. package/dist/packages/core/src/utilities/isString.d.ts +0 -1
  335. package/dist/packages/core/src/utilities/isiOS.d.ts +0 -1
  336. package/dist/packages/core/src/utilities/mergeAttributes.d.ts +0 -1
  337. package/dist/packages/core/src/utilities/mergeDeep.d.ts +0 -1
  338. package/dist/packages/core/src/utilities/minMax.d.ts +0 -1
  339. package/dist/packages/core/src/utilities/objectIncludes.d.ts +0 -8
  340. package/dist/packages/core/src/utilities/removeDuplicates.d.ts +0 -8
package/src/Node.ts CHANGED
@@ -1,830 +1,366 @@
1
- import {
2
- DOMOutputSpec, Node as ProseMirrorNode, NodeSpec, NodeType,
3
- } from '@tiptap/pm/model'
4
- import { Plugin, Transaction } from '@tiptap/pm/state'
5
-
6
- import { Editor } from './Editor.js'
7
- import { getExtensionField } from './helpers/getExtensionField.js'
8
- import { NodeConfig } from './index.js'
9
- import { InputRule } from './InputRule.js'
10
- import { Mark } from './Mark.js'
11
- import { PasteRule } from './PasteRule.js'
12
- import {
13
- AnyConfig,
14
- Attributes,
15
- Extensions,
16
- GlobalAttributes,
17
- KeyboardShortcutCommand,
18
- NodeViewRenderer,
19
- ParentConfig,
20
- RawCommands,
21
- } from './types.js'
22
- import { callOrReturn } from './utilities/callOrReturn.js'
23
- import { mergeDeep } from './utilities/mergeDeep.js'
24
-
25
- declare module '@tiptap/core' {
26
- interface NodeConfig<Options = any, Storage = any> {
27
- // @ts-ignore - this is a dynamic key
28
- [key: string]: any
29
-
30
- /**
31
- * The extension name - this must be unique.
32
- * It will be used to identify the extension.
33
- *
34
- * @example 'myExtension'
35
- */
1
+ import type { DOMOutputSpec, Node as ProseMirrorNode, NodeSpec, NodeType } from '@tiptap/pm/model'
2
+
3
+ import type { Editor } from './Editor.js'
4
+ import type { ExtendableConfig } from './Extendable.js'
5
+ import { Extendable } from './Extendable.js'
6
+ import type { Attributes, NodeViewRenderer, ParentConfig } from './types.js'
7
+
8
+ export interface NodeConfig<Options = any, Storage = any>
9
+ extends ExtendableConfig<Options, Storage, NodeConfig<Options, Storage>, NodeType> {
10
+ /**
11
+ * Node View
12
+ */
13
+ addNodeView?:
14
+ | ((this: {
15
+ name: string
16
+ options: Options
17
+ storage: Storage
18
+ editor: Editor
19
+ type: NodeType
20
+ parent: ParentConfig<NodeConfig<Options, Storage>>['addNodeView']
21
+ }) => NodeViewRenderer)
22
+ | null
23
+
24
+ /**
25
+ * Defines if this node should be a top level node (doc)
26
+ * @default false
27
+ * @example true
28
+ */
29
+ topNode?: boolean
30
+
31
+ /**
32
+ * The content expression for this node, as described in the [schema
33
+ * guide](/docs/guide/#schema.content_expressions). When not given,
34
+ * the node does not allow any content.
35
+ *
36
+ * You can read more about it on the Prosemirror documentation here
37
+ * @see https://prosemirror.net/docs/guide/#schema.content_expressions
38
+ * @default undefined
39
+ * @example content: 'block+'
40
+ * @example content: 'headline paragraph block*'
41
+ */
42
+ content?:
43
+ | NodeSpec['content']
44
+ | ((this: {
45
+ name: string
46
+ options: Options
47
+ storage: Storage
48
+ parent: ParentConfig<NodeConfig<Options, Storage>>['content']
49
+ editor?: Editor
50
+ }) => NodeSpec['content'])
51
+
52
+ /**
53
+ * The marks that are allowed inside of this node. May be a
54
+ * space-separated string referring to mark names or groups, `"_"`
55
+ * to explicitly allow all marks, or `""` to disallow marks. When
56
+ * not given, nodes with inline content default to allowing all
57
+ * marks, other nodes default to not allowing marks.
58
+ *
59
+ * @example marks: 'strong em'
60
+ */
61
+ marks?:
62
+ | NodeSpec['marks']
63
+ | ((this: {
64
+ name: string
65
+ options: Options
66
+ storage: Storage
67
+ parent: ParentConfig<NodeConfig<Options, Storage>>['marks']
68
+ editor?: Editor
69
+ }) => NodeSpec['marks'])
70
+
71
+ /**
72
+ * The group or space-separated groups to which this node belongs,
73
+ * which can be referred to in the content expressions for the
74
+ * schema.
75
+ *
76
+ * By default Tiptap uses the groups 'block' and 'inline' for nodes. You
77
+ * can also use custom groups if you want to group specific nodes together
78
+ * and handle them in your schema.
79
+ * @example group: 'block'
80
+ * @example group: 'inline'
81
+ * @example group: 'customBlock' // this uses a custom group
82
+ */
83
+ group?:
84
+ | NodeSpec['group']
85
+ | ((this: {
86
+ name: string
87
+ options: Options
88
+ storage: Storage
89
+ parent: ParentConfig<NodeConfig<Options, Storage>>['group']
90
+ editor?: Editor
91
+ }) => NodeSpec['group'])
92
+
93
+ /**
94
+ * Should be set to true for inline nodes. (Implied for text nodes.)
95
+ */
96
+ inline?:
97
+ | NodeSpec['inline']
98
+ | ((this: {
99
+ name: string
100
+ options: Options
101
+ storage: Storage
102
+ parent: ParentConfig<NodeConfig<Options, Storage>>['inline']
103
+ editor?: Editor
104
+ }) => NodeSpec['inline'])
105
+
106
+ /**
107
+ * Can be set to true to indicate that, though this isn't a [leaf
108
+ * node](https://prosemirror.net/docs/ref/#model.NodeType.isLeaf), it doesn't have directly editable
109
+ * content and should be treated as a single unit in the view.
110
+ *
111
+ * @example atom: true
112
+ */
113
+ atom?:
114
+ | NodeSpec['atom']
115
+ | ((this: {
116
+ name: string
117
+ options: Options
118
+ storage: Storage
119
+ parent: ParentConfig<NodeConfig<Options, Storage>>['atom']
120
+ editor?: Editor
121
+ }) => NodeSpec['atom'])
122
+
123
+ /**
124
+ * Controls whether nodes of this type can be selected as a [node
125
+ * selection](https://prosemirror.net/docs/ref/#state.NodeSelection). Defaults to true for non-text
126
+ * nodes.
127
+ *
128
+ * @default true
129
+ * @example selectable: false
130
+ */
131
+ selectable?:
132
+ | NodeSpec['selectable']
133
+ | ((this: {
134
+ name: string
135
+ options: Options
136
+ storage: Storage
137
+ parent: ParentConfig<NodeConfig<Options, Storage>>['selectable']
138
+ editor?: Editor
139
+ }) => NodeSpec['selectable'])
140
+
141
+ /**
142
+ * Determines whether nodes of this type can be dragged without
143
+ * being selected. Defaults to false.
144
+ *
145
+ * @default: false
146
+ * @example: draggable: true
147
+ */
148
+ draggable?:
149
+ | NodeSpec['draggable']
150
+ | ((this: {
151
+ name: string
152
+ options: Options
153
+ storage: Storage
154
+ parent: ParentConfig<NodeConfig<Options, Storage>>['draggable']
155
+ editor?: Editor
156
+ }) => NodeSpec['draggable'])
157
+
158
+ /**
159
+ * Can be used to indicate that this node contains code, which
160
+ * causes some commands to behave differently.
161
+ */
162
+ code?:
163
+ | NodeSpec['code']
164
+ | ((this: {
165
+ name: string
166
+ options: Options
167
+ storage: Storage
168
+ parent: ParentConfig<NodeConfig<Options, Storage>>['code']
169
+ editor?: Editor
170
+ }) => NodeSpec['code'])
171
+
172
+ /**
173
+ * Controls way whitespace in this a node is parsed. The default is
174
+ * `"normal"`, which causes the [DOM parser](https://prosemirror.net/docs/ref/#model.DOMParser) to
175
+ * collapse whitespace in normal mode, and normalize it (replacing
176
+ * newlines and such with spaces) otherwise. `"pre"` causes the
177
+ * parser to preserve spaces inside the node. When this option isn't
178
+ * given, but [`code`](https://prosemirror.net/docs/ref/#model.NodeSpec.code) is true, `whitespace`
179
+ * will default to `"pre"`. Note that this option doesn't influence
180
+ * the way the node is rendered—that should be handled by `toDOM`
181
+ * and/or styling.
182
+ */
183
+ whitespace?:
184
+ | NodeSpec['whitespace']
185
+ | ((this: {
186
+ name: string
187
+ options: Options
188
+ storage: Storage
189
+ parent: ParentConfig<NodeConfig<Options, Storage>>['whitespace']
190
+ editor?: Editor
191
+ }) => NodeSpec['whitespace'])
192
+
193
+ /**
194
+ * Allows a **single** node to be set as linebreak equivalent (e.g. hardBreak).
195
+ * When converting between block types that have whitespace set to "pre"
196
+ * and don't support the linebreak node (e.g. codeBlock) and other block types
197
+ * that do support the linebreak node (e.g. paragraphs) - this node will be used
198
+ * as the linebreak instead of stripping the newline.
199
+ *
200
+ * See [linebreakReplacement](https://prosemirror.net/docs/ref/#model.NodeSpec.linebreakReplacement).
201
+ */
202
+ linebreakReplacement?:
203
+ | NodeSpec['linebreakReplacement']
204
+ | ((this: {
205
+ name: string
206
+ options: Options
207
+ storage: Storage
208
+ parent: ParentConfig<NodeConfig<Options, Storage>>['linebreakReplacement']
209
+ editor?: Editor
210
+ }) => NodeSpec['linebreakReplacement'])
211
+
212
+ /**
213
+ * When enabled, enables both
214
+ * [`definingAsContext`](https://prosemirror.net/docs/ref/#model.NodeSpec.definingAsContext) and
215
+ * [`definingForContent`](https://prosemirror.net/docs/ref/#model.NodeSpec.definingForContent).
216
+ *
217
+ * @default false
218
+ * @example isolating: true
219
+ */
220
+ defining?:
221
+ | NodeSpec['defining']
222
+ | ((this: {
223
+ name: string
224
+ options: Options
225
+ storage: Storage
226
+ parent: ParentConfig<NodeConfig<Options, Storage>>['defining']
227
+ editor?: Editor
228
+ }) => NodeSpec['defining'])
229
+
230
+ /**
231
+ * When enabled (default is false), the sides of nodes of this type
232
+ * count as boundaries that regular editing operations, like
233
+ * backspacing or lifting, won't cross. An example of a node that
234
+ * should probably have this enabled is a table cell.
235
+ */
236
+ isolating?:
237
+ | NodeSpec['isolating']
238
+ | ((this: {
239
+ name: string
240
+ options: Options
241
+ storage: Storage
242
+ parent: ParentConfig<NodeConfig<Options, Storage>>['isolating']
243
+ editor?: Editor
244
+ }) => NodeSpec['isolating'])
245
+
246
+ /**
247
+ * Associates DOM parser information with this node, which can be
248
+ * used by [`DOMParser.fromSchema`](https://prosemirror.net/docs/ref/#model.DOMParser^fromSchema) to
249
+ * automatically derive a parser. The `node` field in the rules is
250
+ * implied (the name of this node will be filled in automatically).
251
+ * If you supply your own parser, you do not need to also specify
252
+ * parsing rules in your schema.
253
+ *
254
+ * @example parseHTML: [{ tag: 'div', attrs: { 'data-id': 'my-block' } }]
255
+ */
256
+ parseHTML?: (this: {
36
257
  name: string
37
-
38
- /**
39
- * The priority of your extension. The higher, the later it will be called
40
- * and will take precedence over other extensions with a lower priority.
41
- * @default 1000
42
- * @example 1001
43
- */
44
- priority?: number
45
-
46
- /**
47
- * The default options for this extension.
48
- * @example
49
- * defaultOptions: {
50
- * myOption: 'foo',
51
- * myOtherOption: 10,
52
- * }
53
- */
54
- defaultOptions?: Options
55
-
56
- /**
57
- * This method will add options to this extension
58
- * @see https://tiptap.dev/guide/custom-extensions#settings
59
- * @example
60
- * addOptions() {
61
- * return {
62
- * myOption: 'foo',
63
- * myOtherOption: 10,
64
- * }
65
- */
66
- addOptions?: (this: {
67
- name: string
68
- parent: Exclude<ParentConfig<NodeConfig<Options, Storage>>['addOptions'], undefined>
69
- }) => Options
70
-
71
- /**
72
- * The default storage this extension can save data to.
73
- * @see https://tiptap.dev/guide/custom-extensions#storage
74
- * @example
75
- * defaultStorage: {
76
- * prefetchedUsers: [],
77
- * loading: false,
78
- * }
79
- */
80
- addStorage?: (this: {
81
- name: string
82
- options: Options
83
- parent: Exclude<ParentConfig<NodeConfig<Options, Storage>>['addStorage'], undefined>
84
- }) => Storage
85
-
86
- /**
87
- * This function adds globalAttributes to specific nodes.
88
- * @see https://tiptap.dev/guide/custom-extensions#global-attributes
89
- * @example
90
- * addGlobalAttributes() {
91
- * return [
92
- * {
93
- // Extend the following extensions
94
- * types: [
95
- * 'heading',
96
- * 'paragraph',
97
- * ],
98
- * // … with those attributes
99
- * attributes: {
100
- * textAlign: {
101
- * default: 'left',
102
- * renderHTML: attributes => ({
103
- * style: `text-align: ${attributes.textAlign}`,
104
- * }),
105
- * parseHTML: element => element.style.textAlign || 'left',
106
- * },
107
- * },
108
- * },
109
- * ]
110
- * }
111
- */
112
- addGlobalAttributes?: (this: {
113
- name: string
114
- options: Options
115
- storage: Storage
116
- extensions: (Node | Mark)[]
117
- parent: ParentConfig<NodeConfig<Options, Storage>>['addGlobalAttributes']
118
- }) => GlobalAttributes
119
-
120
- /**
121
- * This function adds commands to the editor
122
- * @see https://tiptap.dev/guide/custom-extensions#keyboard-shortcuts
123
- * @example
124
- * addCommands() {
125
- * return {
126
- * myCommand: () => ({ chain }) => chain().setMark('type', 'foo').run(),
127
- * }
128
- * }
129
- */
130
- addCommands?: (this: {
131
- name: string
132
- options: Options
133
- storage: Storage
134
- editor: Editor
135
- type: NodeType
136
- parent: ParentConfig<NodeConfig<Options, Storage>>['addCommands']
137
- }) => Partial<RawCommands>
138
-
139
- /**
140
- * This function registers keyboard shortcuts.
141
- * @see https://tiptap.dev/guide/custom-extensions#keyboard-shortcuts
142
- * @example
143
- * addKeyboardShortcuts() {
144
- * return {
145
- * 'Mod-l': () => this.editor.commands.toggleBulletList(),
146
- * }
147
- * },
148
- */
149
- addKeyboardShortcuts?: (this: {
150
- name: string
151
- options: Options
152
- storage: Storage
153
- editor: Editor
154
- type: NodeType
155
- parent: ParentConfig<NodeConfig<Options, Storage>>['addKeyboardShortcuts']
156
- }) => {
157
- [key: string]: KeyboardShortcutCommand
158
- }
159
-
160
- /**
161
- * This function adds input rules to the editor.
162
- * @see https://tiptap.dev/guide/custom-extensions#input-rules
163
- * @example
164
- * addInputRules() {
165
- * return [
166
- * markInputRule({
167
- * find: inputRegex,
168
- * type: this.type,
169
- * }),
170
- * ]
171
- * },
172
- */
173
- addInputRules?: (this: {
174
- name: string
175
- options: Options
176
- storage: Storage
177
- editor: Editor
178
- type: NodeType
179
- parent: ParentConfig<NodeConfig<Options, Storage>>['addInputRules']
180
- }) => InputRule[]
181
-
182
- /**
183
- * This function adds paste rules to the editor.
184
- * @see https://tiptap.dev/guide/custom-extensions#paste-rules
185
- * @example
186
- * addPasteRules() {
187
- * return [
188
- * markPasteRule({
189
- * find: pasteRegex,
190
- * type: this.type,
191
- * }),
192
- * ]
193
- * },
194
- */
195
- addPasteRules?: (this: {
196
- name: string
197
- options: Options
198
- storage: Storage
199
- editor: Editor
200
- type: NodeType
201
- parent: ParentConfig<NodeConfig<Options, Storage>>['addPasteRules']
202
- }) => PasteRule[]
203
-
204
- /**
205
- * This function adds Prosemirror plugins to the editor
206
- * @see https://tiptap.dev/guide/custom-extensions#prosemirror-plugins
207
- * @example
208
- * addProseMirrorPlugins() {
209
- * return [
210
- * customPlugin(),
211
- * ]
212
- * }
213
- */
214
- addProseMirrorPlugins?: (this: {
215
- name: string
216
- options: Options
217
- storage: Storage
218
- editor: Editor
219
- type: NodeType
220
- parent: ParentConfig<NodeConfig<Options, Storage>>['addProseMirrorPlugins']
221
- }) => Plugin[]
222
-
223
- /**
224
- * This function adds additional extensions to the editor. This is useful for
225
- * building extension kits.
226
- * @example
227
- * addExtensions() {
228
- * return [
229
- * BulletList,
230
- * OrderedList,
231
- * ListItem
232
- * ]
233
- * }
234
- */
235
- addExtensions?: (this: {
236
- name: string
237
- options: Options
238
- storage: Storage
239
- parent: ParentConfig<NodeConfig<Options, Storage>>['addExtensions']
240
- }) => Extensions
241
-
242
- /**
243
- * This function extends the schema of the node.
244
- * @example
245
- * extendNodeSchema() {
246
- * return {
247
- * group: 'inline',
248
- * selectable: false,
249
- * }
250
- * }
251
- */
252
- extendNodeSchema?:
253
- | ((
254
- this: {
255
- name: string
256
- options: Options
257
- storage: Storage
258
- parent: ParentConfig<NodeConfig<Options, Storage>>['extendNodeSchema']
259
- },
260
- extension: Node,
261
- ) => Record<string, any>)
262
- | null
263
-
264
- /**
265
- * This function extends the schema of the mark.
266
- * @example
267
- * extendMarkSchema() {
268
- * return {
269
- * group: 'inline',
270
- * selectable: false,
271
- * }
272
- * }
273
- */
274
- extendMarkSchema?:
275
- | ((
276
- this: {
277
- name: string
278
- options: Options
279
- storage: Storage
280
- parent: ParentConfig<NodeConfig<Options, Storage>>['extendMarkSchema']
281
- editor?: Editor
282
- },
283
- extension: Node,
284
- ) => Record<string, any>)
285
- | null
286
-
287
- /**
288
- * The editor is not ready yet.
289
- */
290
- onBeforeCreate?:
291
- | ((this: {
292
- name: string
293
- options: Options
294
- storage: Storage
295
- editor: Editor
296
- type: NodeType
297
- parent: ParentConfig<NodeConfig<Options, Storage>>['onBeforeCreate']
298
- }) => void)
299
- | null
300
-
301
- /**
302
- * The editor is ready.
303
- */
304
- onCreate?:
305
- | ((this: {
306
- name: string
307
- options: Options
308
- storage: Storage
309
- editor: Editor
310
- type: NodeType
311
- parent: ParentConfig<NodeConfig<Options, Storage>>['onCreate']
312
- }) => void)
313
- | null
314
-
315
- /**
316
- * The content has changed.
317
- */
318
- onUpdate?:
319
- | ((this: {
320
- name: string
321
- options: Options
322
- storage: Storage
323
- editor: Editor
324
- type: NodeType
325
- parent: ParentConfig<NodeConfig<Options, Storage>>['onUpdate']
326
- }) => void)
327
- | null
328
-
329
- /**
330
- * The selection has changed.
331
- */
332
- onSelectionUpdate?:
333
- | ((this: {
334
- name: string
335
- options: Options
336
- storage: Storage
337
- editor: Editor
338
- type: NodeType
339
- parent: ParentConfig<NodeConfig<Options, Storage>>['onSelectionUpdate']
340
- }) => void)
341
- | null
342
-
343
- /**
344
- * The editor state has changed.
345
- */
346
- onTransaction?:
347
- | ((
348
- this: {
349
- name: string
350
- options: Options
351
- storage: Storage
352
- editor: Editor
353
- type: NodeType
354
- parent: ParentConfig<NodeConfig<Options, Storage>>['onTransaction']
355
- },
356
- props: {
357
- transaction: Transaction
358
- },
359
- ) => void)
360
- | null
361
-
362
- /**
363
- * The editor is focused.
364
- */
365
- onFocus?:
366
- | ((
367
- this: {
368
- name: string
369
- options: Options
370
- storage: Storage
371
- editor: Editor
372
- type: NodeType
373
- parent: ParentConfig<NodeConfig<Options, Storage>>['onFocus']
374
- },
375
- props: {
376
- event: FocusEvent
377
- },
378
- ) => void)
379
- | null
380
-
381
- /**
382
- * The editor isn’t focused anymore.
383
- */
384
- onBlur?:
385
- | ((
386
- this: {
387
- name: string
388
- options: Options
389
- storage: Storage
390
- editor: Editor
391
- type: NodeType
392
- parent: ParentConfig<NodeConfig<Options, Storage>>['onBlur']
393
- },
394
- props: {
395
- event: FocusEvent
396
- },
397
- ) => void)
398
- | null
399
-
400
- /**
401
- * The editor is destroyed.
402
- */
403
- onDestroy?:
404
- | ((this: {
405
- name: string
406
- options: Options
407
- storage: Storage
408
- editor: Editor
409
- type: NodeType
410
- parent: ParentConfig<NodeConfig<Options, Storage>>['onDestroy']
411
- }) => void)
412
- | null
413
-
414
- /**
415
- * Node View
416
- */
417
- addNodeView?:
418
- | ((this: {
419
- name: string
420
- options: Options
421
- storage: Storage
422
- editor: Editor
423
- type: NodeType
424
- parent: ParentConfig<NodeConfig<Options, Storage>>['addNodeView']
425
- }) => NodeViewRenderer)
426
- | null
427
-
428
- /**
429
- * Defines if this node should be a top level node (doc)
430
- * @default false
431
- * @example true
432
- */
433
- topNode?: boolean
434
-
435
- /**
436
- * The content expression for this node, as described in the [schema
437
- * guide](/docs/guide/#schema.content_expressions). When not given,
438
- * the node does not allow any content.
439
- *
440
- * You can read more about it on the Prosemirror documentation here
441
- * @see https://prosemirror.net/docs/guide/#schema.content_expressions
442
- * @default undefined
443
- * @example content: 'block+'
444
- * @example content: 'headline paragraph block*'
445
- */
446
- content?:
447
- | NodeSpec['content']
448
- | ((this: {
449
- name: string
450
- options: Options
451
- storage: Storage
452
- parent: ParentConfig<NodeConfig<Options, Storage>>['content']
453
- editor?: Editor
454
- }) => NodeSpec['content'])
455
-
456
- /**
457
- * The marks that are allowed inside of this node. May be a
458
- * space-separated string referring to mark names or groups, `"_"`
459
- * to explicitly allow all marks, or `""` to disallow marks. When
460
- * not given, nodes with inline content default to allowing all
461
- * marks, other nodes default to not allowing marks.
462
- *
463
- * @example marks: 'strong em'
464
- */
465
- marks?:
466
- | NodeSpec['marks']
467
- | ((this: {
468
- name: string
469
- options: Options
470
- storage: Storage
471
- parent: ParentConfig<NodeConfig<Options, Storage>>['marks']
472
- editor?: Editor
473
- }) => NodeSpec['marks'])
474
-
475
- /**
476
- * The group or space-separated groups to which this node belongs,
477
- * which can be referred to in the content expressions for the
478
- * schema.
479
- *
480
- * By default Tiptap uses the groups 'block' and 'inline' for nodes. You
481
- * can also use custom groups if you want to group specific nodes together
482
- * and handle them in your schema.
483
- * @example group: 'block'
484
- * @example group: 'inline'
485
- * @example group: 'customBlock' // this uses a custom group
486
- */
487
- group?:
488
- | NodeSpec['group']
489
- | ((this: {
490
- name: string
491
- options: Options
492
- storage: Storage
493
- parent: ParentConfig<NodeConfig<Options, Storage>>['group']
494
- editor?: Editor
495
- }) => NodeSpec['group'])
496
-
497
- /**
498
- * Should be set to true for inline nodes. (Implied for text nodes.)
499
- */
500
- inline?:
501
- | NodeSpec['inline']
502
- | ((this: {
258
+ options: Options
259
+ storage: Storage
260
+ parent: ParentConfig<NodeConfig<Options, Storage>>['parseHTML']
261
+ editor?: Editor
262
+ }) => NodeSpec['parseDOM']
263
+
264
+ /**
265
+ * A description of a DOM structure. Can be either a string, which is
266
+ * interpreted as a text node, a DOM node, which is interpreted as
267
+ * itself, a `{dom, contentDOM}` object, or an array.
268
+ *
269
+ * An array describes a DOM element. The first value in the array
270
+ * should be a string—the name of the DOM element, optionally prefixed
271
+ * by a namespace URL and a space. If the second element is plain
272
+ * object, it is interpreted as a set of attributes for the element.
273
+ * Any elements after that (including the 2nd if it's not an attribute
274
+ * object) are interpreted as children of the DOM elements, and must
275
+ * either be valid `DOMOutputSpec` values, or the number zero.
276
+ *
277
+ * The number zero (pronounced “hole”) is used to indicate the place
278
+ * where a node's child nodes should be inserted. If it occurs in an
279
+ * output spec, it should be the only child element in its parent
280
+ * node.
281
+ *
282
+ * @example toDOM: ['div[data-id="my-block"]', { class: 'my-block' }, 0]
283
+ */
284
+ renderHTML?:
285
+ | ((
286
+ this: {
503
287
  name: string
504
288
  options: Options
505
289
  storage: Storage
506
- parent: ParentConfig<NodeConfig<Options, Storage>>['inline']
290
+ parent: ParentConfig<NodeConfig<Options, Storage>>['renderHTML']
507
291
  editor?: Editor
508
- }) => NodeSpec['inline'])
509
-
510
- /**
511
- * Can be set to true to indicate that, though this isn't a [leaf
512
- * node](https://prosemirror.net/docs/ref/#model.NodeType.isLeaf), it doesn't have directly editable
513
- * content and should be treated as a single unit in the view.
514
- *
515
- * @example atom: true
516
- */
517
- atom?:
518
- | NodeSpec['atom']
519
- | ((this: {
520
- name: string
521
- options: Options
522
- storage: Storage
523
- parent: ParentConfig<NodeConfig<Options, Storage>>['atom']
524
- editor?: Editor
525
- }) => NodeSpec['atom'])
526
-
527
- /**
528
- * Controls whether nodes of this type can be selected as a [node
529
- * selection](https://prosemirror.net/docs/ref/#state.NodeSelection). Defaults to true for non-text
530
- * nodes.
531
- *
532
- * @default true
533
- * @example selectable: false
534
- */
535
- selectable?:
536
- | NodeSpec['selectable']
537
- | ((this: {
538
- name: string
539
- options: Options
540
- storage: Storage
541
- parent: ParentConfig<NodeConfig<Options, Storage>>['selectable']
542
- editor?: Editor
543
- }) => NodeSpec['selectable'])
544
-
545
- /**
546
- * Determines whether nodes of this type can be dragged without
547
- * being selected. Defaults to false.
548
- *
549
- * @default: false
550
- * @example: draggable: true
551
- */
552
- draggable?:
553
- | NodeSpec['draggable']
554
- | ((this: {
555
- name: string
556
- options: Options
557
- storage: Storage
558
- parent: ParentConfig<NodeConfig<Options, Storage>>['draggable']
559
- editor?: Editor
560
- }) => NodeSpec['draggable'])
561
-
562
- /**
563
- * Can be used to indicate that this node contains code, which
564
- * causes some commands to behave differently.
565
- */
566
- code?:
567
- | NodeSpec['code']
568
- | ((this: {
569
- name: string
570
- options: Options
571
- storage: Storage
572
- parent: ParentConfig<NodeConfig<Options, Storage>>['code']
573
- editor?: Editor
574
- }) => NodeSpec['code'])
575
-
576
- /**
577
- * Controls way whitespace in this a node is parsed. The default is
578
- * `"normal"`, which causes the [DOM parser](https://prosemirror.net/docs/ref/#model.DOMParser) to
579
- * collapse whitespace in normal mode, and normalize it (replacing
580
- * newlines and such with spaces) otherwise. `"pre"` causes the
581
- * parser to preserve spaces inside the node. When this option isn't
582
- * given, but [`code`](https://prosemirror.net/docs/ref/#model.NodeSpec.code) is true, `whitespace`
583
- * will default to `"pre"`. Note that this option doesn't influence
584
- * the way the node is rendered—that should be handled by `toDOM`
585
- * and/or styling.
586
- */
587
- whitespace?:
588
- | NodeSpec['whitespace']
589
- | ((this: {
590
- name: string
591
- options: Options
592
- storage: Storage
593
- parent: ParentConfig<NodeConfig<Options, Storage>>['whitespace']
594
- editor?: Editor
595
- }) => NodeSpec['whitespace'])
596
-
597
- /**
598
- * When enabled, enables both
599
- * [`definingAsContext`](https://prosemirror.net/docs/ref/#model.NodeSpec.definingAsContext) and
600
- * [`definingForContent`](https://prosemirror.net/docs/ref/#model.NodeSpec.definingForContent).
601
- *
602
- * @default false
603
- * @example isolating: true
604
- */
605
- defining?:
606
- | NodeSpec['defining']
607
- | ((this: {
608
- name: string
609
- options: Options
610
- storage: Storage
611
- parent: ParentConfig<NodeConfig<Options, Storage>>['defining']
612
- editor?: Editor
613
- }) => NodeSpec['defining'])
614
-
615
- /**
616
- * When enabled (default is false), the sides of nodes of this type
617
- * count as boundaries that regular editing operations, like
618
- * backspacing or lifting, won't cross. An example of a node that
619
- * should probably have this enabled is a table cell.
620
- */
621
- isolating?:
622
- | NodeSpec['isolating']
623
- | ((this: {
292
+ },
293
+ props: {
294
+ node: ProseMirrorNode
295
+ HTMLAttributes: Record<string, any>
296
+ },
297
+ ) => DOMOutputSpec)
298
+ | null
299
+
300
+ /**
301
+ * renders the node as text
302
+ * @example renderText: () => 'foo
303
+ */
304
+ renderText?:
305
+ | ((
306
+ this: {
624
307
  name: string
625
308
  options: Options
626
309
  storage: Storage
627
- parent: ParentConfig<NodeConfig<Options, Storage>>['isolating']
310
+ parent: ParentConfig<NodeConfig<Options, Storage>>['renderText']
628
311
  editor?: Editor
629
- }) => NodeSpec['isolating'])
630
-
631
- /**
632
- * Associates DOM parser information with this node, which can be
633
- * used by [`DOMParser.fromSchema`](https://prosemirror.net/docs/ref/#model.DOMParser^fromSchema) to
634
- * automatically derive a parser. The `node` field in the rules is
635
- * implied (the name of this node will be filled in automatically).
636
- * If you supply your own parser, you do not need to also specify
637
- * parsing rules in your schema.
638
- *
639
- * @example parseHTML: [{ tag: 'div', attrs: { 'data-id': 'my-block' } }]
640
- */
641
- parseHTML?: (this: {
642
- name: string
643
- options: Options
644
- storage: Storage
645
- parent: ParentConfig<NodeConfig<Options, Storage>>['parseHTML']
646
- editor?: Editor
647
- }) => NodeSpec['parseDOM']
648
-
649
- /**
650
- * A description of a DOM structure. Can be either a string, which is
651
- * interpreted as a text node, a DOM node, which is interpreted as
652
- * itself, a `{dom, contentDOM}` object, or an array.
653
- *
654
- * An array describes a DOM element. The first value in the array
655
- * should be a string—the name of the DOM element, optionally prefixed
656
- * by a namespace URL and a space. If the second element is plain
657
- * object, it is interpreted as a set of attributes for the element.
658
- * Any elements after that (including the 2nd if it's not an attribute
659
- * object) are interpreted as children of the DOM elements, and must
660
- * either be valid `DOMOutputSpec` values, or the number zero.
661
- *
662
- * The number zero (pronounced “hole”) is used to indicate the place
663
- * where a node's child nodes should be inserted. If it occurs in an
664
- * output spec, it should be the only child element in its parent
665
- * node.
666
- *
667
- * @example toDOM: ['div[data-id="my-block"]', { class: 'my-block' }, 0]
668
- */
669
- renderHTML?:
670
- | ((
671
- this: {
672
- name: string
673
- options: Options
674
- storage: Storage
675
- parent: ParentConfig<NodeConfig<Options, Storage>>['renderHTML']
676
- editor?: Editor
677
- },
678
- props: {
679
- node: ProseMirrorNode
680
- HTMLAttributes: Record<string, any>
681
- },
682
- ) => DOMOutputSpec)
683
- | null
684
-
685
- /**
686
- * renders the node as text
687
- * @example renderText: () => 'foo
688
- */
689
- renderText?:
690
- | ((
691
- this: {
692
- name: string
693
- options: Options
694
- storage: Storage
695
- parent: ParentConfig<NodeConfig<Options, Storage>>['renderText']
696
- editor?: Editor
697
- },
698
- props: {
699
- node: ProseMirrorNode
700
- pos: number
701
- parent: ProseMirrorNode
702
- index: number
703
- },
704
- ) => string)
705
- | null
706
-
707
- /**
708
- * Add attributes to the node
709
- * @example addAttributes: () => ({ class: 'foo' })
710
- */
711
- addAttributes?: (this: {
712
- name: string
713
- options: Options
714
- storage: Storage
715
- parent: ParentConfig<NodeConfig<Options, Storage>>['addAttributes']
716
- editor?: Editor
717
- }) => Attributes | {}
718
- }
312
+ },
313
+ props: {
314
+ node: ProseMirrorNode
315
+ pos: number
316
+ parent: ProseMirrorNode
317
+ index: number
318
+ },
319
+ ) => string)
320
+ | null
321
+
322
+ /**
323
+ * Add attributes to the node
324
+ * @example addAttributes: () => ({ class: 'foo' })
325
+ */
326
+ addAttributes?: (this: {
327
+ name: string
328
+ options: Options
329
+ storage: Storage
330
+ parent: ParentConfig<NodeConfig<Options, Storage>>['addAttributes']
331
+ editor?: Editor
332
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
333
+ }) => Attributes | {}
719
334
  }
720
335
 
721
336
  /**
722
337
  * The Node class is used to create custom node extensions.
723
338
  * @see https://tiptap.dev/api/extensions#create-a-new-extension
724
339
  */
725
- export class Node<Options = any, Storage = any> {
340
+ export class Node<Options = any, Storage = any> extends Extendable<Options, Storage, NodeConfig<Options, Storage>> {
726
341
  type = 'node'
727
342
 
728
- name = 'node'
729
-
730
- parent: Node | null = null
731
-
732
- child: Node | null = null
733
-
734
- options: Options
735
-
736
- storage: Storage
737
-
738
- config: NodeConfig = {
739
- name: this.name,
740
- defaultOptions: {},
741
- }
742
-
743
- constructor(config: Partial<NodeConfig<Options, Storage>> = {}) {
744
- this.config = {
745
- ...this.config,
746
- ...config,
747
- }
748
-
749
- this.name = this.config.name
750
-
751
- if (config.defaultOptions && Object.keys(config.defaultOptions).length > 0) {
752
- console.warn(
753
- `[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`,
754
- )
755
- }
756
-
757
- // TODO: remove `addOptions` fallback
758
- this.options = this.config.defaultOptions
759
-
760
- if (this.config.addOptions) {
761
- this.options = callOrReturn(
762
- getExtensionField<AnyConfig['addOptions']>(this, 'addOptions', {
763
- name: this.name,
764
- }),
765
- )
766
- }
767
-
768
- this.storage = callOrReturn(
769
- getExtensionField<AnyConfig['addStorage']>(this, 'addStorage', {
770
- name: this.name,
771
- options: this.options,
772
- }),
773
- ) || {}
343
+ /**
344
+ * Create a new Node instance
345
+ * @param config - Node configuration object or a function that returns a configuration object
346
+ */
347
+ static create<O = any, S = any>(config: Partial<NodeConfig<O, S>> | (() => Partial<NodeConfig<O, S>>) = {}) {
348
+ // If the config is a function, execute it to get the configuration object
349
+ const resolvedConfig = typeof config === 'function' ? config() : config
350
+ return new Node<O, S>(resolvedConfig)
774
351
  }
775
352
 
776
- static create<O = any, S = any>(config: Partial<NodeConfig<O, S>> = {}) {
777
- return new Node<O, S>(config)
778
- }
779
-
780
- configure(options: Partial<Options> = {}) {
781
- // return a new instance so we can use the same extension
782
- // with different calls of `configure`
783
- const extension = this.extend({
784
- ...this.config,
785
- addOptions() {
786
- return mergeDeep(this.parent?.() || {}, options) as Options
787
- },
788
- })
789
-
790
- // Always preserve the current name
791
- extension.name = this.name
792
- // Set the parent to be our parent
793
- extension.parent = this.parent
794
-
795
- return extension
353
+ configure(options?: Partial<Options>) {
354
+ return super.configure(options) as Node<Options, Storage>
796
355
  }
797
356
 
798
- extend<ExtendedOptions = Options, ExtendedStorage = Storage>(
799
- extendedConfig: Partial<NodeConfig<ExtendedOptions, ExtendedStorage>> = {},
800
- ) {
801
- const extension = new Node<ExtendedOptions, ExtendedStorage>(extendedConfig)
802
-
803
- extension.parent = this
804
-
805
- this.child = extension
806
-
807
- extension.name = extendedConfig.name ? extendedConfig.name : extension.parent.name
808
-
809
- if (extendedConfig.defaultOptions && Object.keys(extendedConfig.defaultOptions).length > 0) {
810
- console.warn(
811
- `[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${extension.name}".`,
812
- )
813
- }
814
-
815
- extension.options = callOrReturn(
816
- getExtensionField<AnyConfig['addOptions']>(extension, 'addOptions', {
817
- name: extension.name,
818
- }),
819
- )
820
-
821
- extension.storage = callOrReturn(
822
- getExtensionField<AnyConfig['addStorage']>(extension, 'addStorage', {
823
- name: extension.name,
824
- options: extension.options,
825
- }),
826
- )
827
-
828
- return extension
357
+ extend<
358
+ ExtendedOptions = Options,
359
+ ExtendedStorage = Storage,
360
+ ExtendedConfig = NodeConfig<ExtendedOptions, ExtendedStorage>,
361
+ >(extendedConfig?: Partial<ExtendedConfig> | (() => Partial<ExtendedConfig>)) {
362
+ // If the extended config is a function, execute it to get the configuration object
363
+ const resolvedConfig = typeof extendedConfig === 'function' ? extendedConfig() : extendedConfig
364
+ return super.extend(resolvedConfig) as Node<ExtendedOptions, ExtendedStorage>
829
365
  }
830
366
  }