@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/Mark.ts CHANGED
@@ -1,640 +1,159 @@
1
- import {
2
- DOMOutputSpec, Mark as ProseMirrorMark, MarkSpec, MarkType,
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 { MarkConfig } from './index.js'
9
- import { InputRule } from './InputRule.js'
10
- import { Node } from './Node.js'
11
- import { PasteRule } from './PasteRule.js'
12
- import {
13
- AnyConfig,
14
- Attributes,
15
- Extensions,
16
- GlobalAttributes,
17
- KeyboardShortcutCommand,
18
- ParentConfig,
19
- RawCommands,
20
- } from './types.js'
21
- import { callOrReturn } from './utilities/callOrReturn.js'
22
- import { mergeDeep } from './utilities/mergeDeep.js'
23
-
24
- declare module '@tiptap/core' {
25
- export interface MarkConfig<Options = any, Storage = any> {
26
- // @ts-ignore - this is a dynamic key
27
- [key: string]: any
28
-
29
- /**
30
- * The extension name - this must be unique.
31
- * It will be used to identify the extension.
32
- *
33
- * @example 'myExtension'
34
- */
1
+ import type { DOMOutputSpec, Mark as ProseMirrorMark, MarkSpec, MarkType } 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, MarkViewRenderer, ParentConfig } from './types.js'
7
+
8
+ export interface MarkConfig<Options = any, Storage = any>
9
+ extends ExtendableConfig<Options, Storage, MarkConfig<Options, Storage>, MarkType> {
10
+ /**
11
+ * Mark View
12
+ */
13
+ addMarkView?:
14
+ | ((this: {
15
+ name: string
16
+ options: Options
17
+ storage: Storage
18
+ editor: Editor
19
+ type: MarkType
20
+ parent: ParentConfig<MarkConfig<Options, Storage>>['addMarkView']
21
+ }) => MarkViewRenderer)
22
+ | null
23
+
24
+ /**
25
+ * Keep mark after split node
26
+ */
27
+ keepOnSplit?: boolean | (() => boolean)
28
+
29
+ /**
30
+ * Inclusive
31
+ */
32
+ inclusive?:
33
+ | MarkSpec['inclusive']
34
+ | ((this: {
35
+ name: string
36
+ options: Options
37
+ storage: Storage
38
+ parent: ParentConfig<MarkConfig<Options, Storage>>['inclusive']
39
+ editor?: Editor
40
+ }) => MarkSpec['inclusive'])
41
+
42
+ /**
43
+ * Excludes
44
+ */
45
+ excludes?:
46
+ | MarkSpec['excludes']
47
+ | ((this: {
48
+ name: string
49
+ options: Options
50
+ storage: Storage
51
+ parent: ParentConfig<MarkConfig<Options, Storage>>['excludes']
52
+ editor?: Editor
53
+ }) => MarkSpec['excludes'])
54
+
55
+ /**
56
+ * Marks this Mark as exitable
57
+ */
58
+ exitable?: boolean | (() => boolean)
59
+
60
+ /**
61
+ * Group
62
+ */
63
+ group?:
64
+ | MarkSpec['group']
65
+ | ((this: {
66
+ name: string
67
+ options: Options
68
+ storage: Storage
69
+ parent: ParentConfig<MarkConfig<Options, Storage>>['group']
70
+ editor?: Editor
71
+ }) => MarkSpec['group'])
72
+
73
+ /**
74
+ * Spanning
75
+ */
76
+ spanning?:
77
+ | MarkSpec['spanning']
78
+ | ((this: {
79
+ name: string
80
+ options: Options
81
+ storage: Storage
82
+ parent: ParentConfig<MarkConfig<Options, Storage>>['spanning']
83
+ editor?: Editor
84
+ }) => MarkSpec['spanning'])
85
+
86
+ /**
87
+ * Code
88
+ */
89
+ code?:
90
+ | boolean
91
+ | ((this: {
92
+ name: string
93
+ options: Options
94
+ storage: Storage
95
+ parent: ParentConfig<MarkConfig<Options, Storage>>['code']
96
+ editor?: Editor
97
+ }) => boolean)
98
+
99
+ /**
100
+ * Parse HTML
101
+ */
102
+ parseHTML?: (this: {
35
103
  name: string
36
-
37
- /**
38
- * The priority of your extension. The higher, the later it will be called
39
- * and will take precedence over other extensions with a lower priority.
40
- * @default 1000
41
- * @example 1001
42
- */
43
- priority?: number
44
-
45
- /**
46
- * The default options for this extension.
47
- * @example
48
- * defaultOptions: {
49
- * myOption: 'foo',
50
- * myOtherOption: 10,
51
- * }
52
- */
53
- defaultOptions?: Options
54
-
55
- /**
56
- * This method will add options to this extension
57
- * @see https://tiptap.dev/guide/custom-extensions#settings
58
- * @example
59
- * addOptions() {
60
- * return {
61
- * myOption: 'foo',
62
- * myOtherOption: 10,
63
- * }
64
- */
65
- addOptions?: (this: {
66
- name: string
67
- parent: Exclude<ParentConfig<MarkConfig<Options, Storage>>['addOptions'], undefined>
68
- }) => Options
69
-
70
- /**
71
- * The default storage this extension can save data to.
72
- * @see https://tiptap.dev/guide/custom-extensions#storage
73
- * @example
74
- * defaultStorage: {
75
- * prefetchedUsers: [],
76
- * loading: false,
77
- * }
78
- */
79
- addStorage?: (this: {
80
- name: string
81
- options: Options
82
- parent: Exclude<ParentConfig<MarkConfig<Options, Storage>>['addStorage'], undefined>
83
- }) => Storage
84
-
85
- /**
86
- * This function adds globalAttributes to specific nodes.
87
- * @see https://tiptap.dev/guide/custom-extensions#global-attributes
88
- * @example
89
- * addGlobalAttributes() {
90
- * return [
91
- * {
92
- // Extend the following extensions
93
- * types: [
94
- * 'heading',
95
- * 'paragraph',
96
- * ],
97
- * // … with those attributes
98
- * attributes: {
99
- * textAlign: {
100
- * default: 'left',
101
- * renderHTML: attributes => ({
102
- * style: `text-align: ${attributes.textAlign}`,
103
- * }),
104
- * parseHTML: element => element.style.textAlign || 'left',
105
- * },
106
- * },
107
- * },
108
- * ]
109
- * }
110
- */
111
- addGlobalAttributes?: (this: {
112
- name: string
113
- options: Options
114
- storage: Storage
115
- extensions: (Node | Mark)[]
116
- parent: ParentConfig<MarkConfig<Options, Storage>>['addGlobalAttributes']
117
- }) => GlobalAttributes
118
-
119
- /**
120
- * This function adds commands to the editor
121
- * @see https://tiptap.dev/guide/custom-extensions#keyboard-shortcuts
122
- * @example
123
- * addCommands() {
124
- * return {
125
- * myCommand: () => ({ chain }) => chain().setMark('type', 'foo').run(),
126
- * }
127
- * }
128
- */
129
- addCommands?: (this: {
130
- name: string
131
- options: Options
132
- storage: Storage
133
- editor: Editor
134
- type: MarkType
135
- parent: ParentConfig<MarkConfig<Options, Storage>>['addCommands']
136
- }) => Partial<RawCommands>
137
-
138
- /**
139
- * This function registers keyboard shortcuts.
140
- * @see https://tiptap.dev/guide/custom-extensions#keyboard-shortcuts
141
- * @example
142
- * addKeyboardShortcuts() {
143
- * return {
144
- * 'Mod-l': () => this.editor.commands.toggleBulletList(),
145
- * }
146
- * },
147
- */
148
- addKeyboardShortcuts?: (this: {
149
- name: string
150
- options: Options
151
- storage: Storage
152
- editor: Editor
153
- type: MarkType
154
- parent: ParentConfig<MarkConfig<Options, Storage>>['addKeyboardShortcuts']
155
- }) => {
156
- [key: string]: KeyboardShortcutCommand
157
- }
158
-
159
- /**
160
- * This function adds input rules to the editor.
161
- * @see https://tiptap.dev/guide/custom-extensions#input-rules
162
- * @example
163
- * addInputRules() {
164
- * return [
165
- * markInputRule({
166
- * find: inputRegex,
167
- * type: this.type,
168
- * }),
169
- * ]
170
- * },
171
- */
172
- addInputRules?: (this: {
173
- name: string
174
- options: Options
175
- storage: Storage
176
- editor: Editor
177
- type: MarkType
178
- parent: ParentConfig<MarkConfig<Options, Storage>>['addInputRules']
179
- }) => InputRule[]
180
-
181
- /**
182
- * This function adds paste rules to the editor.
183
- * @see https://tiptap.dev/guide/custom-extensions#paste-rules
184
- * @example
185
- * addPasteRules() {
186
- * return [
187
- * markPasteRule({
188
- * find: pasteRegex,
189
- * type: this.type,
190
- * }),
191
- * ]
192
- * },
193
- */
194
- addPasteRules?: (this: {
195
- name: string
196
- options: Options
197
- storage: Storage
198
- editor: Editor
199
- type: MarkType
200
- parent: ParentConfig<MarkConfig<Options, Storage>>['addPasteRules']
201
- }) => PasteRule[]
202
-
203
- /**
204
- * This function adds Prosemirror plugins to the editor
205
- * @see https://tiptap.dev/guide/custom-extensions#prosemirror-plugins
206
- * @example
207
- * addProseMirrorPlugins() {
208
- * return [
209
- * customPlugin(),
210
- * ]
211
- * }
212
- */
213
- addProseMirrorPlugins?: (this: {
214
- name: string
215
- options: Options
216
- storage: Storage
217
- editor: Editor
218
- type: MarkType
219
- parent: ParentConfig<MarkConfig<Options, Storage>>['addProseMirrorPlugins']
220
- }) => Plugin[]
221
-
222
- /**
223
- * This function adds additional extensions to the editor. This is useful for
224
- * building extension kits.
225
- * @example
226
- * addExtensions() {
227
- * return [
228
- * BulletList,
229
- * OrderedList,
230
- * ListItem
231
- * ]
232
- * }
233
- */
234
- addExtensions?: (this: {
235
- name: string
236
- options: Options
237
- storage: Storage
238
- parent: ParentConfig<MarkConfig<Options, Storage>>['addExtensions']
239
- }) => Extensions
240
-
241
- /**
242
- * This function extends the schema of the node.
243
- * @example
244
- * extendNodeSchema() {
245
- * return {
246
- * group: 'inline',
247
- * selectable: false,
248
- * }
249
- * }
250
- */
251
- extendNodeSchema?:
252
- | ((
253
- this: {
254
- name: string
255
- options: Options
256
- storage: Storage
257
- parent: ParentConfig<MarkConfig<Options, Storage>>['extendNodeSchema']
258
- },
259
- extension: Node,
260
- ) => Record<string, any>)
261
- | null
262
-
263
- /**
264
- * This function extends the schema of the mark.
265
- * @example
266
- * extendMarkSchema() {
267
- * return {
268
- * group: 'inline',
269
- * selectable: false,
270
- * }
271
- * }
272
- */
273
- extendMarkSchema?:
274
- | ((
275
- this: {
276
- name: string
277
- options: Options
278
- storage: Storage
279
- parent: ParentConfig<MarkConfig<Options, Storage>>['extendMarkSchema']
280
- },
281
- extension: Mark,
282
- ) => Record<string, any>)
283
- | null
284
-
285
- /**
286
- * The editor is not ready yet.
287
- */
288
- onBeforeCreate?:
289
- | ((this: {
290
- name: string
291
- options: Options
292
- storage: Storage
293
- editor: Editor
294
- type: MarkType
295
- parent: ParentConfig<MarkConfig<Options, Storage>>['onBeforeCreate']
296
- }) => void)
297
- | null
298
-
299
- /**
300
- * The editor is ready.
301
- */
302
- onCreate?:
303
- | ((this: {
304
- name: string
305
- options: Options
306
- storage: Storage
307
- editor: Editor
308
- type: MarkType
309
- parent: ParentConfig<MarkConfig<Options, Storage>>['onCreate']
310
- }) => void)
311
- | null
312
-
313
- /**
314
- * The content has changed.
315
- */
316
- onUpdate?:
317
- | ((this: {
104
+ options: Options
105
+ storage: Storage
106
+ parent: ParentConfig<MarkConfig<Options, Storage>>['parseHTML']
107
+ editor?: Editor
108
+ }) => MarkSpec['parseDOM']
109
+
110
+ /**
111
+ * Render HTML
112
+ */
113
+ renderHTML?:
114
+ | ((
115
+ this: {
318
116
  name: string
319
117
  options: Options
320
118
  storage: Storage
321
- editor: Editor
322
- type: MarkType
323
- parent: ParentConfig<MarkConfig<Options, Storage>>['onUpdate']
324
- }) => void)
325
- | null
326
-
327
- /**
328
- * The selection has changed.
329
- */
330
- onSelectionUpdate?:
331
- | ((this: {
332
- name: string
333
- options: Options
334
- storage: Storage
335
- editor: Editor
336
- type: MarkType
337
- parent: ParentConfig<MarkConfig<Options, Storage>>['onSelectionUpdate']
338
- }) => void)
339
- | null
340
-
341
- /**
342
- * The editor state has changed.
343
- */
344
- onTransaction?:
345
- | ((
346
- this: {
347
- name: string
348
- options: Options
349
- storage: Storage
350
- editor: Editor
351
- type: MarkType
352
- parent: ParentConfig<MarkConfig<Options, Storage>>['onTransaction']
353
- },
354
- props: {
355
- transaction: Transaction
356
- },
357
- ) => void)
358
- | null
359
-
360
- /**
361
- * The editor is focused.
362
- */
363
- onFocus?:
364
- | ((
365
- this: {
366
- name: string
367
- options: Options
368
- storage: Storage
369
- editor: Editor
370
- type: MarkType
371
- parent: ParentConfig<MarkConfig<Options, Storage>>['onFocus']
372
- },
373
- props: {
374
- event: FocusEvent
375
- },
376
- ) => void)
377
- | null
378
-
379
- /**
380
- * The editor isn’t focused anymore.
381
- */
382
- onBlur?:
383
- | ((
384
- this: {
385
- name: string
386
- options: Options
387
- storage: Storage
388
- editor: Editor
389
- type: MarkType
390
- parent: ParentConfig<MarkConfig<Options, Storage>>['onBlur']
391
- },
392
- props: {
393
- event: FocusEvent
394
- },
395
- ) => void)
396
- | null
397
-
398
- /**
399
- * The editor is destroyed.
400
- */
401
- onDestroy?:
402
- | ((this: {
403
- name: string
404
- options: Options
405
- storage: Storage
406
- editor: Editor
407
- type: MarkType
408
- parent: ParentConfig<MarkConfig<Options, Storage>>['onDestroy']
409
- }) => void)
410
- | null
411
-
412
- /**
413
- * Keep mark after split node
414
- */
415
- keepOnSplit?: boolean | (() => boolean)
416
-
417
- /**
418
- * Inclusive
419
- */
420
- inclusive?:
421
- | MarkSpec['inclusive']
422
- | ((this: {
423
- name: string
424
- options: Options
425
- storage: Storage
426
- parent: ParentConfig<MarkConfig<Options, Storage>>['inclusive']
119
+ parent: ParentConfig<MarkConfig<Options, Storage>>['renderHTML']
427
120
  editor?: Editor
428
- }) => MarkSpec['inclusive'])
429
-
430
- /**
431
- * Excludes
432
- */
433
- excludes?:
434
- | MarkSpec['excludes']
435
- | ((this: {
436
- name: string
437
- options: Options
438
- storage: Storage
439
- parent: ParentConfig<MarkConfig<Options, Storage>>['excludes']
440
- editor?: Editor
441
- }) => MarkSpec['excludes'])
442
-
443
- /**
444
- * Marks this Mark as exitable
445
- */
446
- exitable?: boolean | (() => boolean)
447
-
448
- /**
449
- * Group
450
- */
451
- group?:
452
- | MarkSpec['group']
453
- | ((this: {
454
- name: string
455
- options: Options
456
- storage: Storage
457
- parent: ParentConfig<MarkConfig<Options, Storage>>['group']
458
- editor?: Editor
459
- }) => MarkSpec['group'])
460
-
461
- /**
462
- * Spanning
463
- */
464
- spanning?:
465
- | MarkSpec['spanning']
466
- | ((this: {
467
- name: string
468
- options: Options
469
- storage: Storage
470
- parent: ParentConfig<MarkConfig<Options, Storage>>['spanning']
471
- editor?: Editor
472
- }) => MarkSpec['spanning'])
473
-
474
- /**
475
- * Code
476
- */
477
- code?:
478
- | boolean
479
- | ((this: {
480
- name: string
481
- options: Options
482
- storage: Storage
483
- parent: ParentConfig<MarkConfig<Options, Storage>>['code']
484
- editor?: Editor
485
- }) => boolean)
486
-
487
- /**
488
- * Parse HTML
489
- */
490
- parseHTML?: (this: {
491
- name: string
492
- options: Options
493
- storage: Storage
494
- parent: ParentConfig<MarkConfig<Options, Storage>>['parseHTML']
495
- editor?: Editor
496
- }) => MarkSpec['parseDOM']
497
-
498
- /**
499
- * Render HTML
500
- */
501
- renderHTML?:
502
- | ((
503
- this: {
504
- name: string
505
- options: Options
506
- storage: Storage
507
- parent: ParentConfig<MarkConfig<Options, Storage>>['renderHTML']
508
- editor?: Editor
509
- },
510
- props: {
511
- mark: ProseMirrorMark
512
- HTMLAttributes: Record<string, any>
513
- },
514
- ) => DOMOutputSpec)
515
- | null
516
-
517
- /**
518
- * Attributes
519
- */
520
- addAttributes?: (this: {
521
- name: string
522
- options: Options
523
- storage: Storage
524
- parent: ParentConfig<MarkConfig<Options, Storage>>['addAttributes']
525
- editor?: Editor
526
- }) => Attributes | {}
527
- }
121
+ },
122
+ props: {
123
+ mark: ProseMirrorMark
124
+ HTMLAttributes: Record<string, any>
125
+ },
126
+ ) => DOMOutputSpec)
127
+ | null
128
+
129
+ /**
130
+ * Attributes
131
+ */
132
+ addAttributes?: (this: {
133
+ name: string
134
+ options: Options
135
+ storage: Storage
136
+ parent: ParentConfig<MarkConfig<Options, Storage>>['addAttributes']
137
+ editor?: Editor
138
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
139
+ }) => Attributes | {}
528
140
  }
529
141
 
530
142
  /**
531
143
  * The Mark class is used to create custom mark extensions.
532
144
  * @see https://tiptap.dev/api/extensions#create-a-new-extension
533
145
  */
534
- export class Mark<Options = any, Storage = any> {
146
+ export class Mark<Options = any, Storage = any> extends Extendable<Options, Storage, MarkConfig<Options, Storage>> {
535
147
  type = 'mark'
536
148
 
537
- name = 'mark'
538
-
539
- parent: Mark | null = null
540
-
541
- child: Mark | null = null
542
-
543
- options: Options
544
-
545
- storage: Storage
546
-
547
- config: MarkConfig = {
548
- name: this.name,
549
- defaultOptions: {},
550
- }
551
-
552
- constructor(config: Partial<MarkConfig<Options, Storage>> = {}) {
553
- this.config = {
554
- ...this.config,
555
- ...config,
556
- }
557
-
558
- this.name = this.config.name
559
-
560
- if (config.defaultOptions && Object.keys(config.defaultOptions).length > 0) {
561
- console.warn(
562
- `[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`,
563
- )
564
- }
565
-
566
- // TODO: remove `addOptions` fallback
567
- this.options = this.config.defaultOptions
568
-
569
- if (this.config.addOptions) {
570
- this.options = callOrReturn(
571
- getExtensionField<AnyConfig['addOptions']>(this, 'addOptions', {
572
- name: this.name,
573
- }),
574
- )
575
- }
576
-
577
- this.storage = callOrReturn(
578
- getExtensionField<AnyConfig['addStorage']>(this, 'addStorage', {
579
- name: this.name,
580
- options: this.options,
581
- }),
582
- ) || {}
583
- }
584
-
585
- static create<O = any, S = any>(config: Partial<MarkConfig<O, S>> = {}) {
586
- return new Mark<O, S>(config)
587
- }
588
-
589
- configure(options: Partial<Options> = {}) {
590
- // return a new instance so we can use the same extension
591
- // with different calls of `configure`
592
- const extension = this.extend({
593
- ...this.config,
594
- addOptions() {
595
- return mergeDeep(this.parent?.() || {}, options) as Options
596
- },
597
- })
598
-
599
- // Always preserve the current name
600
- extension.name = this.name
601
- // Set the parent to be our parent
602
- extension.parent = this.parent
603
-
604
- return extension
605
- }
606
-
607
- extend<ExtendedOptions = Options, ExtendedStorage = Storage>(
608
- extendedConfig: Partial<MarkConfig<ExtendedOptions, ExtendedStorage>> = {},
609
- ) {
610
- const extension = new Mark<ExtendedOptions, ExtendedStorage>(extendedConfig)
611
-
612
- extension.parent = this
613
-
614
- this.child = extension
615
-
616
- extension.name = extendedConfig.name ? extendedConfig.name : extension.parent.name
617
-
618
- if (extendedConfig.defaultOptions && Object.keys(extendedConfig.defaultOptions).length > 0) {
619
- console.warn(
620
- `[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${extension.name}".`,
621
- )
622
- }
623
-
624
- extension.options = callOrReturn(
625
- getExtensionField<AnyConfig['addOptions']>(extension, 'addOptions', {
626
- name: extension.name,
627
- }),
628
- )
629
-
630
- extension.storage = callOrReturn(
631
- getExtensionField<AnyConfig['addStorage']>(extension, 'addStorage', {
632
- name: extension.name,
633
- options: extension.options,
634
- }),
635
- )
636
-
637
- return extension
149
+ /**
150
+ * Create a new Mark instance
151
+ * @param config - Mark configuration object or a function that returns a configuration object
152
+ */
153
+ static create<O = any, S = any>(config: Partial<MarkConfig<O, S>> | (() => Partial<MarkConfig<O, S>>) = {}) {
154
+ // If the config is a function, execute it to get the configuration object
155
+ const resolvedConfig = typeof config === 'function' ? config() : config
156
+ return new Mark<O, S>(resolvedConfig)
638
157
  }
639
158
 
640
159
  static handleExit({ editor, mark }: { editor: Editor; mark: Mark }) {
@@ -664,4 +183,18 @@ export class Mark<Options = any, Storage = any> {
664
183
 
665
184
  return false
666
185
  }
186
+
187
+ configure(options?: Partial<Options>) {
188
+ return super.configure(options) as Mark<Options, Storage>
189
+ }
190
+
191
+ extend<
192
+ ExtendedOptions = Options,
193
+ ExtendedStorage = Storage,
194
+ ExtendedConfig = MarkConfig<ExtendedOptions, ExtendedStorage>,
195
+ >(extendedConfig?: Partial<ExtendedConfig> | (() => Partial<ExtendedConfig>)) {
196
+ // If the extended config is a function, execute it to get the configuration object
197
+ const resolvedConfig = typeof extendedConfig === 'function' ? extendedConfig() : extendedConfig
198
+ return super.extend(resolvedConfig) as Mark<ExtendedOptions, ExtendedStorage>
199
+ }
667
200
  }