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