@tiptap/core 2.0.0-beta.16 → 2.0.0-beta.163

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 (312) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +2 -2
  3. package/dist/packages/core/src/CommandManager.d.ts +13 -6
  4. package/dist/packages/core/src/Editor.d.ts +23 -18
  5. package/dist/packages/core/src/EventEmitter.d.ts +8 -4
  6. package/dist/packages/core/src/Extension.d.ts +102 -26
  7. package/dist/packages/core/src/ExtensionManager.d.ts +7 -12
  8. package/dist/packages/core/src/InputRule.d.ts +42 -0
  9. package/dist/packages/core/src/Mark.d.ts +134 -30
  10. package/dist/packages/core/src/Node.d.ts +160 -32
  11. package/dist/packages/core/src/NodeView.d.ts +5 -9
  12. package/dist/packages/core/src/PasteRule.d.ts +42 -0
  13. package/dist/packages/core/src/Tracker.d.ts +11 -0
  14. package/dist/packages/core/src/commands/blur.d.ts +3 -3
  15. package/dist/packages/core/src/commands/clearContent.d.ts +3 -3
  16. package/dist/packages/core/src/commands/clearNodes.d.ts +3 -3
  17. package/dist/packages/core/src/commands/command.d.ts +2 -2
  18. package/dist/packages/core/src/commands/createParagraphNear.d.ts +3 -3
  19. package/dist/packages/core/src/commands/deleteNode.d.ts +13 -0
  20. package/dist/packages/core/src/commands/deleteRange.d.ts +3 -3
  21. package/dist/packages/core/src/commands/deleteSelection.d.ts +3 -3
  22. package/dist/packages/core/src/commands/enter.d.ts +3 -3
  23. package/dist/packages/core/src/commands/exitCode.d.ts +3 -3
  24. package/dist/packages/core/src/commands/extendMarkRange.d.ts +3 -3
  25. package/dist/packages/core/src/commands/first.d.ts +3 -3
  26. package/dist/packages/core/src/commands/focus.d.ts +5 -3
  27. package/dist/packages/core/src/commands/forEach.d.ts +14 -0
  28. package/dist/packages/core/src/commands/insertContent.d.ts +7 -3
  29. package/dist/packages/core/src/commands/insertContentAt.d.ts +16 -0
  30. package/dist/packages/core/src/commands/joinBackward.d.ts +3 -3
  31. package/dist/packages/core/src/commands/joinForward.d.ts +3 -3
  32. package/dist/packages/core/src/commands/keyboardShortcut.d.ts +3 -3
  33. package/dist/packages/core/src/commands/lift.d.ts +3 -3
  34. package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +3 -3
  35. package/dist/packages/core/src/commands/liftListItem.d.ts +3 -3
  36. package/dist/packages/core/src/commands/newlineInCode.d.ts +3 -3
  37. package/dist/packages/core/src/commands/resetAttributes.d.ts +13 -0
  38. package/dist/packages/core/src/commands/scrollIntoView.d.ts +3 -3
  39. package/dist/packages/core/src/commands/selectAll.d.ts +3 -3
  40. package/dist/packages/core/src/commands/selectNodeBackward.d.ts +3 -3
  41. package/dist/packages/core/src/commands/selectNodeForward.d.ts +3 -3
  42. package/dist/packages/core/src/commands/selectParentNode.d.ts +3 -3
  43. package/dist/packages/core/src/commands/setContent.d.ts +4 -3
  44. package/dist/packages/core/src/commands/setMark.d.ts +3 -3
  45. package/dist/packages/core/src/commands/setMeta.d.ts +12 -0
  46. package/dist/packages/core/src/commands/setNode.d.ts +3 -3
  47. package/dist/packages/core/src/commands/setNodeSelection.d.ts +12 -0
  48. package/dist/packages/core/src/commands/setTextSelection.d.ts +12 -0
  49. package/dist/packages/core/src/commands/sinkListItem.d.ts +3 -3
  50. package/dist/packages/core/src/commands/splitBlock.d.ts +3 -3
  51. package/dist/packages/core/src/commands/splitListItem.d.ts +3 -3
  52. package/dist/packages/core/src/commands/toggleList.d.ts +3 -3
  53. package/dist/packages/core/src/commands/toggleMark.d.ts +8 -3
  54. package/dist/packages/core/src/commands/toggleNode.d.ts +3 -3
  55. package/dist/packages/core/src/commands/toggleWrap.d.ts +3 -3
  56. package/dist/packages/core/src/commands/undoInputRule.d.ts +3 -3
  57. package/dist/packages/core/src/commands/unsetAllMarks.d.ts +3 -3
  58. package/dist/packages/core/src/commands/unsetMark.d.ts +8 -3
  59. package/dist/packages/core/src/commands/updateAttributes.d.ts +13 -0
  60. package/dist/packages/core/src/commands/wrapIn.d.ts +3 -3
  61. package/dist/packages/core/src/commands/wrapInList.d.ts +3 -3
  62. package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +1 -1
  63. package/dist/packages/core/src/extensions/commands.d.ts +17 -15
  64. package/dist/packages/core/src/extensions/editable.d.ts +1 -1
  65. package/dist/packages/core/src/extensions/focusEvents.d.ts +1 -1
  66. package/dist/packages/core/src/extensions/index.d.ts +1 -0
  67. package/dist/packages/core/src/extensions/keymap.d.ts +1 -1
  68. package/dist/packages/core/src/extensions/tabindex.d.ts +2 -0
  69. package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +7 -0
  70. package/dist/packages/core/src/helpers/createChainableState.d.ts +5 -0
  71. package/dist/packages/core/src/helpers/createDocument.d.ts +3 -4
  72. package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +4 -5
  73. package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +2 -0
  74. package/dist/packages/core/src/helpers/findChildren.d.ts +3 -0
  75. package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +6 -0
  76. package/dist/packages/core/src/helpers/findParentNode.d.ts +1 -1
  77. package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +1 -1
  78. package/dist/packages/core/src/helpers/generateHTML.d.ts +2 -2
  79. package/dist/packages/core/src/helpers/generateJSON.d.ts +2 -0
  80. package/dist/packages/core/src/helpers/generateText.d.ts +5 -0
  81. package/dist/packages/core/src/helpers/getAttributes.d.ts +3 -0
  82. package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +1 -1
  83. package/dist/packages/core/src/helpers/getChangedRanges.d.ts +11 -0
  84. package/dist/packages/core/src/helpers/getDebugJSON.d.ts +8 -0
  85. package/dist/packages/core/src/helpers/getExtensionField.d.ts +2 -0
  86. package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +2 -2
  87. package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +1 -2
  88. package/dist/packages/core/src/helpers/getMarkRange.d.ts +1 -1
  89. package/dist/packages/core/src/helpers/getMarkType.d.ts +1 -1
  90. package/dist/packages/core/src/helpers/getMarksBetween.d.ts +2 -2
  91. package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +1 -2
  92. package/dist/packages/core/src/helpers/getNodeType.d.ts +1 -1
  93. package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +2 -2
  94. package/dist/packages/core/src/helpers/getSchema.d.ts +1 -1
  95. package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +3 -0
  96. package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +1 -1
  97. package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +1 -1
  98. package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +2 -2
  99. package/dist/packages/core/src/helpers/getText.d.ts +6 -0
  100. package/dist/packages/core/src/helpers/getTextBetween.d.ts +6 -0
  101. package/dist/packages/core/src/helpers/getTextSeralizersFromSchema.d.ts +3 -0
  102. package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +1 -1
  103. package/dist/packages/core/src/helpers/isActive.d.ts +1 -2
  104. package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +2 -0
  105. package/dist/packages/core/src/helpers/isList.d.ts +1 -1
  106. package/dist/packages/core/src/helpers/isMarkActive.d.ts +1 -2
  107. package/dist/packages/core/src/helpers/isNodeActive.d.ts +1 -2
  108. package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +1 -1
  109. package/dist/packages/core/src/helpers/isNodeSelection.d.ts +1 -1
  110. package/dist/packages/core/src/helpers/isTextSelection.d.ts +1 -1
  111. package/dist/packages/core/src/helpers/posToDOMRect.d.ts +2 -0
  112. package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +4 -0
  113. package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +1 -1
  114. package/dist/packages/core/src/helpers/splitExtensions.d.ts +4 -4
  115. package/dist/packages/core/src/index.d.ts +51 -20
  116. package/dist/packages/core/src/inputRules/markInputRule.d.ts +11 -2
  117. package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +11 -2
  118. package/dist/packages/core/src/inputRules/textInputRule.d.ts +9 -0
  119. package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +14 -0
  120. package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +23 -0
  121. package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +11 -2
  122. package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +9 -0
  123. package/dist/packages/core/src/style.d.ts +1 -2
  124. package/dist/packages/core/src/types.d.ts +105 -52
  125. package/dist/packages/core/src/utilities/callOrReturn.d.ts +2 -1
  126. package/dist/packages/core/src/utilities/createStyleTag.d.ts +1 -1
  127. package/dist/packages/core/src/utilities/deleteProps.d.ts +1 -2
  128. package/dist/packages/core/src/utilities/elementFromString.d.ts +1 -1
  129. package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +1 -0
  130. package/dist/packages/core/src/utilities/findDuplicates.d.ts +1 -0
  131. package/dist/packages/core/src/utilities/fromString.d.ts +1 -1
  132. package/dist/packages/core/src/utilities/isClass.d.ts +1 -1
  133. package/dist/packages/core/src/utilities/isEmptyObject.d.ts +1 -1
  134. package/dist/packages/core/src/utilities/isFunction.d.ts +1 -0
  135. package/dist/packages/core/src/utilities/isNumber.d.ts +1 -0
  136. package/dist/packages/core/src/utilities/isObject.d.ts +1 -1
  137. package/dist/packages/core/src/utilities/isPlainObject.d.ts +1 -1
  138. package/dist/packages/core/src/utilities/isRegExp.d.ts +1 -0
  139. package/dist/packages/core/src/utilities/isiOS.d.ts +1 -0
  140. package/dist/packages/core/src/utilities/mergeAttributes.d.ts +1 -2
  141. package/dist/packages/core/src/utilities/mergeDeep.d.ts +1 -2
  142. package/dist/packages/core/src/utilities/minMax.d.ts +1 -1
  143. package/dist/packages/core/src/utilities/objectIncludes.d.ts +3 -2
  144. package/dist/packages/core/src/utilities/removeDuplicates.d.ts +8 -0
  145. package/dist/tiptap-core.cjs.js +3495 -2047
  146. package/dist/tiptap-core.cjs.js.map +1 -1
  147. package/dist/tiptap-core.esm.js +3466 -2049
  148. package/dist/tiptap-core.esm.js.map +1 -1
  149. package/dist/tiptap-core.umd.js +3499 -2050
  150. package/dist/tiptap-core.umd.js.map +1 -1
  151. package/package.json +20 -16
  152. package/src/CommandManager.ts +60 -62
  153. package/src/Editor.ts +108 -75
  154. package/src/EventEmitter.ts +14 -4
  155. package/src/Extension.ts +196 -41
  156. package/src/ExtensionManager.ts +242 -78
  157. package/src/InputRule.ts +268 -0
  158. package/src/Mark.ts +242 -47
  159. package/src/Node.ts +279 -52
  160. package/src/NodeView.ts +105 -42
  161. package/src/PasteRule.ts +217 -0
  162. package/src/Tracker.ts +42 -0
  163. package/src/commands/blur.ts +9 -7
  164. package/src/commands/clearContent.ts +3 -3
  165. package/src/commands/clearNodes.ts +29 -18
  166. package/src/commands/command.ts +2 -2
  167. package/src/commands/createParagraphNear.ts +3 -3
  168. package/src/commands/deleteNode.ts +36 -0
  169. package/src/commands/deleteRange.ts +3 -3
  170. package/src/commands/deleteSelection.ts +3 -3
  171. package/src/commands/enter.ts +3 -3
  172. package/src/commands/exitCode.ts +3 -3
  173. package/src/commands/extendMarkRange.ts +10 -10
  174. package/src/commands/first.ts +3 -3
  175. package/src/commands/focus.ts +45 -44
  176. package/src/commands/forEach.ts +24 -0
  177. package/src/commands/insertContent.ts +12 -24
  178. package/src/commands/insertContentAt.ts +96 -0
  179. package/src/commands/joinBackward.ts +3 -3
  180. package/src/commands/joinForward.ts +3 -3
  181. package/src/commands/keyboardShortcut.ts +3 -3
  182. package/src/commands/lift.ts +5 -5
  183. package/src/commands/liftEmptyBlock.ts +3 -3
  184. package/src/commands/liftListItem.ts +4 -4
  185. package/src/commands/newlineInCode.ts +3 -3
  186. package/src/commands/resetAttributes.ts +61 -0
  187. package/src/commands/scrollIntoView.ts +3 -3
  188. package/src/commands/selectAll.ts +8 -6
  189. package/src/commands/selectNodeBackward.ts +3 -3
  190. package/src/commands/selectNodeForward.ts +3 -3
  191. package/src/commands/selectParentNode.ts +3 -3
  192. package/src/commands/setContent.ts +7 -11
  193. package/src/commands/setMark.ts +35 -12
  194. package/src/commands/setMeta.ts +18 -0
  195. package/src/commands/setNode.ts +27 -6
  196. package/src/commands/setNodeSelection.ts +28 -0
  197. package/src/commands/setTextSelection.ts +32 -0
  198. package/src/commands/sinkListItem.ts +4 -4
  199. package/src/commands/splitBlock.ts +14 -9
  200. package/src/commands/splitListItem.ts +41 -15
  201. package/src/commands/toggleList.ts +82 -18
  202. package/src/commands/toggleMark.ts +17 -7
  203. package/src/commands/toggleNode.ts +5 -5
  204. package/src/commands/toggleWrap.ts +8 -9
  205. package/src/commands/undoInputRule.ts +34 -5
  206. package/src/commands/unsetAllMarks.ts +7 -11
  207. package/src/commands/unsetMark.ts +34 -22
  208. package/src/commands/updateAttributes.ts +72 -0
  209. package/src/commands/wrapIn.ts +4 -10
  210. package/src/commands/wrapInList.ts +4 -4
  211. package/src/extensions/clipboardTextSerializer.ts +13 -35
  212. package/src/extensions/commands.ts +24 -21
  213. package/src/extensions/focusEvents.ts +0 -3
  214. package/src/extensions/index.ts +1 -0
  215. package/src/extensions/keymap.ts +76 -6
  216. package/src/extensions/tabindex.ts +19 -0
  217. package/src/helpers/combineTransactionSteps.ts +18 -0
  218. package/src/helpers/createChainableState.ts +37 -0
  219. package/src/helpers/createDocument.ts +5 -7
  220. package/src/helpers/createNodeFromContent.ts +15 -18
  221. package/src/helpers/defaultBlockAt.ts +13 -0
  222. package/src/helpers/findChildren.ts +17 -0
  223. package/src/helpers/findChildrenInRange.ts +31 -0
  224. package/src/helpers/findParentNode.ts +2 -2
  225. package/src/helpers/findParentNodeClosestToPos.ts +1 -1
  226. package/src/helpers/generateHTML.ts +5 -5
  227. package/src/helpers/generateJSON.ts +13 -0
  228. package/src/helpers/generateText.ts +29 -0
  229. package/src/helpers/getAttributes.ts +27 -0
  230. package/src/helpers/getAttributesFromExtensions.ts +28 -7
  231. package/src/helpers/getChangedRanges.ts +82 -0
  232. package/src/helpers/getDebugJSON.ts +53 -0
  233. package/src/helpers/getExtensionField.ts +25 -0
  234. package/src/helpers/getHTMLFromFragment.ts +6 -5
  235. package/src/helpers/getMarkAttributes.ts +12 -9
  236. package/src/helpers/getMarkRange.ts +34 -6
  237. package/src/helpers/getMarkType.ts +5 -1
  238. package/src/helpers/getMarksBetween.ts +31 -10
  239. package/src/helpers/getNodeAttributes.ts +7 -8
  240. package/src/helpers/getNodeType.ts +5 -1
  241. package/src/helpers/getRenderedAttributes.ts +4 -6
  242. package/src/helpers/getSchema.ts +6 -133
  243. package/src/helpers/getSchemaByResolvedExtensions.ts +147 -0
  244. package/src/helpers/getSchemaTypeByName.ts +2 -10
  245. package/src/helpers/getSchemaTypeNameByName.ts +1 -1
  246. package/src/helpers/getSplittedAttributes.ts +4 -4
  247. package/src/helpers/getText.ts +18 -0
  248. package/src/helpers/getTextBetween.ts +45 -0
  249. package/src/helpers/getTextSeralizersFromSchema.ts +9 -0
  250. package/src/helpers/injectExtensionAttributesToParseRule.ts +14 -10
  251. package/src/helpers/isActive.ts +4 -5
  252. package/src/helpers/isExtensionRulesEnabled.ts +15 -0
  253. package/src/helpers/isList.ts +14 -7
  254. package/src/helpers/isMarkActive.ts +43 -19
  255. package/src/helpers/isNodeActive.ts +26 -34
  256. package/src/helpers/isNodeEmpty.ts +1 -1
  257. package/src/helpers/isNodeSelection.ts +2 -2
  258. package/src/helpers/isTextSelection.ts +2 -2
  259. package/src/helpers/posToDOMRect.ts +34 -0
  260. package/src/helpers/resolveFocusPosition.ts +34 -0
  261. package/src/helpers/selectionToInsertionEnd.ts +1 -1
  262. package/src/helpers/splitExtensions.ts +1 -1
  263. package/src/index.ts +53 -20
  264. package/src/inputRules/markInputRule.ts +58 -39
  265. package/src/inputRules/nodeInputRule.ts +44 -11
  266. package/src/inputRules/textInputRule.ts +35 -0
  267. package/src/inputRules/textblockTypeInputRule.ts +37 -0
  268. package/src/inputRules/wrappingInputRule.ts +59 -0
  269. package/src/pasteRules/markPasteRule.ts +61 -53
  270. package/src/pasteRules/textPasteRule.ts +35 -0
  271. package/src/style.ts +16 -3
  272. package/src/types.ts +119 -37
  273. package/src/utilities/callOrReturn.ts +6 -3
  274. package/src/utilities/createStyleTag.ts +8 -1
  275. package/src/utilities/deleteProps.ts +2 -4
  276. package/src/utilities/elementFromString.ts +4 -5
  277. package/src/utilities/escapeForRegEx.ts +4 -0
  278. package/src/utilities/findDuplicates.ts +5 -0
  279. package/src/utilities/fromString.ts +2 -2
  280. package/src/utilities/isClass.ts +2 -2
  281. package/src/utilities/isEmptyObject.ts +2 -2
  282. package/src/utilities/isFunction.ts +3 -0
  283. package/src/utilities/isNumber.ts +3 -0
  284. package/src/utilities/isObject.ts +6 -6
  285. package/src/utilities/isPlainObject.ts +8 -5
  286. package/src/utilities/isRegExp.ts +3 -0
  287. package/src/utilities/isString.ts +3 -0
  288. package/src/utilities/isiOS.ts +12 -0
  289. package/src/utilities/mergeAttributes.ts +2 -3
  290. package/src/utilities/mergeDeep.ts +2 -3
  291. package/src/utilities/minMax.ts +1 -1
  292. package/src/utilities/objectIncludes.ts +17 -5
  293. package/src/utilities/removeDuplicates.ts +15 -0
  294. package/CHANGELOG.md +0 -313
  295. package/dist/packages/core/src/commands/insertHTML.d.ts +0 -12
  296. package/dist/packages/core/src/commands/insertNode.d.ts +0 -13
  297. package/dist/packages/core/src/commands/insertText.d.ts +0 -12
  298. package/dist/packages/core/src/commands/replace.d.ts +0 -13
  299. package/dist/packages/core/src/commands/replaceRange.d.ts +0 -13
  300. package/dist/packages/core/src/commands/resetNodeAttributes.d.ts +0 -13
  301. package/dist/packages/core/src/commands/updateNodeAttributes.d.ts +0 -13
  302. package/dist/packages/core/src/utilities/removeElement.d.ts +0 -1
  303. package/dist/tiptap-core.bundle.umd.min.js +0 -17
  304. package/dist/tiptap-core.bundle.umd.min.js.map +0 -1
  305. package/src/commands/insertHTML.ts +0 -30
  306. package/src/commands/insertNode.ts +0 -33
  307. package/src/commands/insertText.ts +0 -22
  308. package/src/commands/replace.ts +0 -20
  309. package/src/commands/replaceRange.ts +0 -36
  310. package/src/commands/resetNodeAttributes.ts +0 -31
  311. package/src/commands/updateNodeAttributes.ts +0 -33
  312. package/src/utilities/removeElement.ts +0 -5
@@ -1,17 +1,46 @@
1
- import { undoInputRule as originalUndoInputRule } from 'prosemirror-inputrules'
2
- import { Command, RawCommands } from '../types'
1
+ import { RawCommands } from '../types'
3
2
 
4
3
  declare module '@tiptap/core' {
5
- interface Commands {
4
+ interface Commands<ReturnType> {
6
5
  undoInputRule: {
7
6
  /**
8
7
  * Undo an input rule.
9
8
  */
10
- undoInputRule: () => Command,
9
+ undoInputRule: () => ReturnType,
11
10
  }
12
11
  }
13
12
  }
14
13
 
15
14
  export const undoInputRule: RawCommands['undoInputRule'] = () => ({ state, dispatch }) => {
16
- return originalUndoInputRule(state, dispatch)
15
+ const plugins = state.plugins
16
+
17
+ for (let i = 0; i < plugins.length; i += 1) {
18
+ const plugin = plugins[i]
19
+ let undoable
20
+
21
+ // @ts-ignore
22
+ // eslint-disable-next-line
23
+ if (plugin.spec.isInputRules && (undoable = plugin.getState(state))) {
24
+ if (dispatch) {
25
+ const tr = state.tr
26
+ const toUndo = undoable.transform
27
+
28
+ for (let j = toUndo.steps.length - 1; j >= 0; j -= 1) {
29
+ tr.step(toUndo.steps[j].invert(toUndo.docs[j]))
30
+ }
31
+
32
+ if (undoable.text) {
33
+ const marks = tr.doc.resolve(undoable.from).marks()
34
+
35
+ tr.replaceWith(undoable.from, undoable.to, state.schema.text(undoable.text, marks))
36
+ } else {
37
+ tr.delete(undoable.from, undoable.to)
38
+ }
39
+ }
40
+
41
+ return true
42
+ }
43
+ }
44
+
45
+ return false
17
46
  }
@@ -1,17 +1,17 @@
1
- import { Command, RawCommands } from '../types'
1
+ import { RawCommands } from '../types'
2
2
 
3
3
  declare module '@tiptap/core' {
4
- interface Commands {
4
+ interface Commands<ReturnType> {
5
5
  unsetAllMarks: {
6
6
  /**
7
7
  * Remove all marks in the current selection.
8
8
  */
9
- unsetAllMarks: () => Command,
9
+ unsetAllMarks: () => ReturnType,
10
10
  }
11
11
  }
12
12
  }
13
13
 
14
- export const unsetAllMarks: RawCommands['unsetAllMarks'] = () => ({ tr, state, dispatch }) => {
14
+ export const unsetAllMarks: RawCommands['unsetAllMarks'] = () => ({ tr, dispatch }) => {
15
15
  const { selection } = tr
16
16
  const { empty, ranges } = selection
17
17
 
@@ -20,13 +20,9 @@ export const unsetAllMarks: RawCommands['unsetAllMarks'] = () => ({ tr, state, d
20
20
  }
21
21
 
22
22
  if (dispatch) {
23
- Object
24
- .entries(state.schema.marks)
25
- .forEach(([, mark]) => {
26
- ranges.forEach(range => {
27
- tr.removeMark(range.$from.pos, range.$to.pos, mark as any)
28
- })
29
- })
23
+ ranges.forEach(range => {
24
+ tr.removeMark(range.$from.pos, range.$to.pos)
25
+ })
30
26
  }
31
27
 
32
28
  return true
@@ -1,43 +1,55 @@
1
1
  import { MarkType } from 'prosemirror-model'
2
- import { Command, RawCommands } from '../types'
3
- import getMarkType from '../helpers/getMarkType'
4
- import getMarkRange from '../helpers/getMarkRange'
2
+ import { RawCommands } from '../types'
3
+ import { getMarkType } from '../helpers/getMarkType'
4
+ import { getMarkRange } from '../helpers/getMarkRange'
5
5
 
6
6
  declare module '@tiptap/core' {
7
- interface Commands {
7
+ interface Commands<ReturnType> {
8
8
  unsetMark: {
9
9
  /**
10
10
  * Remove all marks in the current selection.
11
11
  */
12
- unsetMark: (typeOrName: string | MarkType) => Command,
12
+ unsetMark: (
13
+ typeOrName: string | MarkType,
14
+ options?: {
15
+ /**
16
+ * Removes the mark even across the current selection. Defaults to `false`.
17
+ */
18
+ extendEmptyMarkRange?: boolean,
19
+ },
20
+ ) => ReturnType,
13
21
  }
14
22
  }
15
23
  }
16
24
 
17
- export const unsetMark: RawCommands['unsetMark'] = typeOrName => ({ tr, state, dispatch }) => {
25
+ export const unsetMark: RawCommands['unsetMark'] = (typeOrName, options = {}) => ({ tr, state, dispatch }) => {
26
+ const { extendEmptyMarkRange = false } = options
18
27
  const { selection } = tr
19
28
  const type = getMarkType(typeOrName, state.schema)
20
29
  const { $from, empty, ranges } = selection
21
30
 
22
- if (dispatch) {
23
- if (empty) {
24
- let { from, to } = selection
25
- const range = getMarkRange($from, type)
26
-
27
- if (range) {
28
- from = range.from
29
- to = range.to
30
- }
31
-
32
- tr.removeMark(from, to, type)
33
- } else {
34
- ranges.forEach(range => {
35
- tr.removeMark(range.$from.pos, range.$to.pos, type)
36
- })
31
+ if (!dispatch) {
32
+ return true
33
+ }
34
+
35
+ if (empty && extendEmptyMarkRange) {
36
+ let { from, to } = selection
37
+ const attrs = $from.marks().find(mark => mark.type === type)?.attrs
38
+ const range = getMarkRange($from, type, attrs)
39
+
40
+ if (range) {
41
+ from = range.from
42
+ to = range.to
37
43
  }
38
44
 
39
- tr.removeStoredMark(type)
45
+ tr.removeMark(from, to, type)
46
+ } else {
47
+ ranges.forEach(range => {
48
+ tr.removeMark(range.$from.pos, range.$to.pos, type)
49
+ })
40
50
  }
41
51
 
52
+ tr.removeStoredMark(type)
53
+
42
54
  return true
43
55
  }
@@ -0,0 +1,72 @@
1
+ import { NodeType, MarkType } from 'prosemirror-model'
2
+ import { getNodeType } from '../helpers/getNodeType'
3
+ import { getMarkType } from '../helpers/getMarkType'
4
+ import { getSchemaTypeNameByName } from '../helpers/getSchemaTypeNameByName'
5
+ import { RawCommands } from '../types'
6
+
7
+ declare module '@tiptap/core' {
8
+ interface Commands<ReturnType> {
9
+ updateAttributes: {
10
+ /**
11
+ * Update attributes of a node or mark.
12
+ */
13
+ updateAttributes: (typeOrName: string | NodeType | MarkType, attributes: Record<string, any>) => ReturnType,
14
+ }
15
+ }
16
+ }
17
+
18
+ export const updateAttributes: RawCommands['updateAttributes'] = (typeOrName, attributes = {}) => ({ tr, state, dispatch }) => {
19
+ let nodeType: NodeType | null = null
20
+ let markType: MarkType | null = null
21
+
22
+ const schemaType = getSchemaTypeNameByName(
23
+ typeof typeOrName === 'string'
24
+ ? typeOrName
25
+ : typeOrName.name,
26
+ state.schema,
27
+ )
28
+
29
+ if (!schemaType) {
30
+ return false
31
+ }
32
+
33
+ if (schemaType === 'node') {
34
+ nodeType = getNodeType(typeOrName as NodeType, state.schema)
35
+ }
36
+
37
+ if (schemaType === 'mark') {
38
+ markType = getMarkType(typeOrName as MarkType, state.schema)
39
+ }
40
+
41
+ if (dispatch) {
42
+ tr.selection.ranges.forEach(range => {
43
+ const from = range.$from.pos
44
+ const to = range.$to.pos
45
+
46
+ state.doc.nodesBetween(from, to, (node, pos) => {
47
+ if (nodeType && nodeType === node.type) {
48
+ tr.setNodeMarkup(pos, undefined, {
49
+ ...node.attrs,
50
+ ...attributes,
51
+ })
52
+ }
53
+
54
+ if (markType && node.marks.length) {
55
+ node.marks.forEach(mark => {
56
+ if (markType === mark.type) {
57
+ const trimmedFrom = Math.max(pos, from)
58
+ const trimmedTo = Math.min(pos + node.nodeSize, to)
59
+
60
+ tr.addMark(trimmedFrom, trimmedTo, markType.create({
61
+ ...mark.attrs,
62
+ ...attributes,
63
+ }))
64
+ }
65
+ })
66
+ }
67
+ })
68
+ })
69
+ }
70
+
71
+ return true
72
+ }
@@ -1,27 +1,21 @@
1
1
  import { wrapIn as originalWrapIn } from 'prosemirror-commands'
2
2
  import { NodeType } from 'prosemirror-model'
3
- import { AnyObject, Command, RawCommands } from '../types'
4
- import isNodeActive from '../helpers/isNodeActive'
5
- import getNodeType from '../helpers/getNodeType'
3
+ import { RawCommands } from '../types'
4
+ import { getNodeType } from '../helpers/getNodeType'
6
5
 
7
6
  declare module '@tiptap/core' {
8
- interface Commands {
7
+ interface Commands<ReturnType> {
9
8
  wrapIn: {
10
9
  /**
11
10
  * Wraps nodes in another node.
12
11
  */
13
- wrapIn: (typeOrName: string | NodeType, attributes?: AnyObject) => Command,
12
+ wrapIn: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType,
14
13
  }
15
14
  }
16
15
  }
17
16
 
18
17
  export const wrapIn: RawCommands['wrapIn'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
19
18
  const type = getNodeType(typeOrName, state.schema)
20
- const isActive = isNodeActive(state, type, attributes)
21
-
22
- if (isActive) {
23
- return false
24
- }
25
19
 
26
20
  return originalWrapIn(type, attributes)(state, dispatch)
27
21
  }
@@ -1,15 +1,15 @@
1
1
  import { wrapInList as originalWrapInList } from 'prosemirror-schema-list'
2
2
  import { NodeType } from 'prosemirror-model'
3
- import { AnyObject, Command, RawCommands } from '../types'
4
- import getNodeType from '../helpers/getNodeType'
3
+ import { RawCommands } from '../types'
4
+ import { getNodeType } from '../helpers/getNodeType'
5
5
 
6
6
  declare module '@tiptap/core' {
7
- interface Commands {
7
+ interface Commands<ReturnType> {
8
8
  wrapInList: {
9
9
  /**
10
10
  * Wrap a node in a list.
11
11
  */
12
- wrapInList: (typeOrName: string | NodeType, attributes?: AnyObject) => Command,
12
+ wrapInList: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType,
13
13
  }
14
14
  }
15
15
  }
@@ -1,40 +1,10 @@
1
- import { Editor } from '@tiptap/core'
2
1
  import { Plugin, PluginKey } from 'prosemirror-state'
3
2
  import { Extension } from '../Extension'
4
-
5
- const textBetween = (
6
- editor: Editor,
7
- from: number,
8
- to: number,
9
- blockSeparator?: string,
10
- leafText?: string,
11
- ): string => {
12
- let text = ''
13
- let separated = true
14
-
15
- editor.state.doc.nodesBetween(from, to, (node, pos) => {
16
- const textSerializer = editor.extensionManager.textSerializers[node.type.name]
17
-
18
- if (textSerializer) {
19
- text += textSerializer({ node })
20
- separated = !blockSeparator
21
- } else if (node.isText) {
22
- text += node?.text?.slice(Math.max(from, pos) - pos, to - pos)
23
- separated = !blockSeparator
24
- } else if (node.isLeaf && leafText) {
25
- text += leafText
26
- separated = !blockSeparator
27
- } else if (!separated && node.isBlock) {
28
- text += blockSeparator
29
- separated = true
30
- }
31
- }, 0)
32
-
33
- return text
34
- }
3
+ import { getTextBetween } from '../helpers/getTextBetween'
4
+ import { getTextSeralizersFromSchema } from '../helpers/getTextSeralizersFromSchema'
35
5
 
36
6
  export const ClipboardTextSerializer = Extension.create({
37
- name: 'editable',
7
+ name: 'clipboardTextSerializer',
38
8
 
39
9
  addProseMirrorPlugins() {
40
10
  return [
@@ -43,9 +13,17 @@ export const ClipboardTextSerializer = Extension.create({
43
13
  props: {
44
14
  clipboardTextSerializer: () => {
45
15
  const { editor } = this
46
- const { from, to } = editor.state.selection
16
+ const { state, schema } = editor
17
+ const { doc, selection } = state
18
+ const { ranges } = selection
19
+ const from = Math.min(...ranges.map(range => range.$from.pos))
20
+ const to = Math.max(...ranges.map(range => range.$to.pos))
21
+ const textSerializers = getTextSeralizersFromSchema(schema)
22
+ const range = { from, to }
47
23
 
48
- return textBetween(editor, from, to, '\n')
24
+ return getTextBetween(doc, range, {
25
+ textSerializers,
26
+ })
49
27
  },
50
28
  },
51
29
  }),
@@ -4,6 +4,7 @@ import * as clearContent from '../commands/clearContent'
4
4
  import * as clearNodes from '../commands/clearNodes'
5
5
  import * as command from '../commands/command'
6
6
  import * as createParagraphNear from '../commands/createParagraphNear'
7
+ import * as deleteNode from '../commands/deleteNode'
7
8
  import * as deleteRange from '../commands/deleteRange'
8
9
  import * as deleteSelection from '../commands/deleteSelection'
9
10
  import * as enter from '../commands/enter'
@@ -11,10 +12,9 @@ import * as exitCode from '../commands/exitCode'
11
12
  import * as extendMarkRange from '../commands/extendMarkRange'
12
13
  import * as first from '../commands/first'
13
14
  import * as focus from '../commands/focus'
15
+ import * as forEach from '../commands/forEach'
14
16
  import * as insertContent from '../commands/insertContent'
15
- import * as insertHTML from '../commands/insertHTML'
16
- import * as insertNode from '../commands/insertNode'
17
- import * as insertText from '../commands/insertText'
17
+ import * as insertContentAt from '../commands/insertContentAt'
18
18
  import * as joinBackward from '../commands/joinBackward'
19
19
  import * as joinForward from '../commands/joinForward'
20
20
  import * as keyboardShortcut from '../commands/keyboardShortcut'
@@ -22,9 +22,7 @@ import * as lift from '../commands/lift'
22
22
  import * as liftEmptyBlock from '../commands/liftEmptyBlock'
23
23
  import * as liftListItem from '../commands/liftListItem'
24
24
  import * as newlineInCode from '../commands/newlineInCode'
25
- import * as replace from '../commands/replace'
26
- import * as replaceRange from '../commands/replaceRange'
27
- import * as resetNodeAttributes from '../commands/resetNodeAttributes'
25
+ import * as resetAttributes from '../commands/resetAttributes'
28
26
  import * as scrollIntoView from '../commands/scrollIntoView'
29
27
  import * as selectAll from '../commands/selectAll'
30
28
  import * as selectNodeBackward from '../commands/selectNodeBackward'
@@ -32,7 +30,10 @@ import * as selectNodeForward from '../commands/selectNodeForward'
32
30
  import * as selectParentNode from '../commands/selectParentNode'
33
31
  import * as setContent from '../commands/setContent'
34
32
  import * as setMark from '../commands/setMark'
33
+ import * as setMeta from '../commands/setMeta'
35
34
  import * as setNode from '../commands/setNode'
35
+ import * as setNodeSelection from '../commands/setNodeSelection'
36
+ import * as setTextSelection from '../commands/setTextSelection'
36
37
  import * as sinkListItem from '../commands/sinkListItem'
37
38
  import * as splitBlock from '../commands/splitBlock'
38
39
  import * as splitListItem from '../commands/splitListItem'
@@ -43,7 +44,7 @@ import * as toggleWrap from '../commands/toggleWrap'
43
44
  import * as undoInputRule from '../commands/undoInputRule'
44
45
  import * as unsetAllMarks from '../commands/unsetAllMarks'
45
46
  import * as unsetMark from '../commands/unsetMark'
46
- import * as updateNodeAttributes from '../commands/updateNodeAttributes'
47
+ import * as updateAttributes from '../commands/updateAttributes'
47
48
  import * as wrapIn from '../commands/wrapIn'
48
49
  import * as wrapInList from '../commands/wrapInList'
49
50
 
@@ -52,6 +53,7 @@ export { clearContent }
52
53
  export { clearNodes }
53
54
  export { command }
54
55
  export { createParagraphNear }
56
+ export { deleteNode }
55
57
  export { deleteRange }
56
58
  export { deleteSelection }
57
59
  export { enter }
@@ -59,10 +61,9 @@ export { exitCode }
59
61
  export { extendMarkRange }
60
62
  export { first }
61
63
  export { focus }
64
+ export { forEach }
62
65
  export { insertContent }
63
- export { insertHTML }
64
- export { insertNode }
65
- export { insertText }
66
+ export { insertContentAt }
66
67
  export { joinBackward }
67
68
  export { joinForward }
68
69
  export { keyboardShortcut }
@@ -70,9 +71,7 @@ export { lift }
70
71
  export { liftEmptyBlock }
71
72
  export { liftListItem }
72
73
  export { newlineInCode }
73
- export { replace }
74
- export { replaceRange }
75
- export { resetNodeAttributes }
74
+ export { resetAttributes }
76
75
  export { scrollIntoView }
77
76
  export { selectAll }
78
77
  export { selectNodeBackward }
@@ -80,7 +79,10 @@ export { selectNodeForward }
80
79
  export { selectParentNode }
81
80
  export { setContent }
82
81
  export { setMark }
82
+ export { setMeta }
83
83
  export { setNode }
84
+ export { setNodeSelection }
85
+ export { setTextSelection }
84
86
  export { sinkListItem }
85
87
  export { splitBlock }
86
88
  export { splitListItem }
@@ -91,7 +93,7 @@ export { toggleWrap }
91
93
  export { undoInputRule }
92
94
  export { unsetAllMarks }
93
95
  export { unsetMark }
94
- export { updateNodeAttributes }
96
+ export { updateAttributes }
95
97
  export { wrapIn }
96
98
  export { wrapInList }
97
99
 
@@ -105,6 +107,7 @@ export const Commands = Extension.create({
105
107
  ...clearNodes,
106
108
  ...command,
107
109
  ...createParagraphNear,
110
+ ...deleteNode,
108
111
  ...deleteRange,
109
112
  ...deleteSelection,
110
113
  ...enter,
@@ -112,10 +115,9 @@ export const Commands = Extension.create({
112
115
  ...extendMarkRange,
113
116
  ...first,
114
117
  ...focus,
118
+ ...forEach,
115
119
  ...insertContent,
116
- ...insertHTML,
117
- ...insertNode,
118
- ...insertText,
120
+ ...insertContentAt,
119
121
  ...joinBackward,
120
122
  ...joinForward,
121
123
  ...keyboardShortcut,
@@ -123,9 +125,7 @@ export const Commands = Extension.create({
123
125
  ...liftEmptyBlock,
124
126
  ...liftListItem,
125
127
  ...newlineInCode,
126
- ...replace,
127
- ...replaceRange,
128
- ...resetNodeAttributes,
128
+ ...resetAttributes,
129
129
  ...scrollIntoView,
130
130
  ...selectAll,
131
131
  ...selectNodeBackward,
@@ -133,7 +133,10 @@ export const Commands = Extension.create({
133
133
  ...selectParentNode,
134
134
  ...setContent,
135
135
  ...setMark,
136
+ ...setMeta,
136
137
  ...setNode,
138
+ ...setNodeSelection,
139
+ ...setTextSelection,
137
140
  ...sinkListItem,
138
141
  ...splitBlock,
139
142
  ...splitListItem,
@@ -144,7 +147,7 @@ export const Commands = Extension.create({
144
147
  ...undoInputRule,
145
148
  ...unsetAllMarks,
146
149
  ...unsetMark,
147
- ...updateNodeAttributes,
150
+ ...updateAttributes,
148
151
  ...wrapIn,
149
152
  ...wrapInList,
150
153
  }
@@ -11,9 +11,6 @@ export const FocusEvents = Extension.create({
11
11
  new Plugin({
12
12
  key: new PluginKey('focusEvents'),
13
13
  props: {
14
- attributes: {
15
- tabindex: '0',
16
- },
17
14
  handleDOMEvents: {
18
15
  focus: (view, event) => {
19
16
  editor.isFocused = true
@@ -3,3 +3,4 @@ export { Commands } from './commands'
3
3
  export { Editable } from './editable'
4
4
  export { FocusEvents } from './focusEvents'
5
5
  export { Keymap } from './keymap'
6
+ export { Tabindex } from './tabindex'
@@ -1,3 +1,6 @@
1
+ import { Plugin, PluginKey, Selection } from 'prosemirror-state'
2
+ import { createChainableState } from '../helpers/createChainableState'
3
+ import { CommandManager } from '../CommandManager'
1
4
  import { Extension } from '../Extension'
2
5
 
3
6
  export const Keymap = Extension.create({
@@ -6,6 +9,24 @@ export const Keymap = Extension.create({
6
9
  addKeyboardShortcuts() {
7
10
  const handleBackspace = () => this.editor.commands.first(({ commands }) => [
8
11
  () => commands.undoInputRule(),
12
+ // maybe convert first text block node to default node
13
+ () => commands.command(({ tr }) => {
14
+ const { selection, doc } = tr
15
+ const { empty, $anchor } = selection
16
+ const { pos, parent } = $anchor
17
+ const isAtStart = Selection.atStart(doc).from === pos
18
+
19
+ if (
20
+ !empty
21
+ || !isAtStart
22
+ || !parent.type.isTextblock
23
+ || parent.textContent.length
24
+ ) {
25
+ return false
26
+ }
27
+
28
+ return commands.clearNodes()
29
+ }),
9
30
  () => commands.deleteSelection(),
10
31
  () => commands.joinBackward(),
11
32
  () => commands.selectNodeBackward(),
@@ -25,12 +46,61 @@ export const Keymap = Extension.create({
25
46
  () => commands.splitBlock(),
26
47
  ]),
27
48
  'Mod-Enter': () => this.editor.commands.exitCode(),
28
- Backspace: () => handleBackspace(),
29
- 'Mod-Backspace': () => handleBackspace(),
30
- Delete: () => handleDelete(),
31
- 'Mod-Delete': () => handleDelete(),
32
- // we don’t need a custom `selectAll` for now
33
- // 'Mod-a': () => this.editor.commands.selectAll(),
49
+ Backspace: handleBackspace,
50
+ 'Mod-Backspace': handleBackspace,
51
+ 'Shift-Backspace': handleBackspace,
52
+ Delete: handleDelete,
53
+ 'Mod-Delete': handleDelete,
54
+ 'Mod-a': () => this.editor.commands.selectAll(),
34
55
  }
35
56
  },
57
+
58
+ addProseMirrorPlugins() {
59
+ return [
60
+ // With this plugin we check if the whole document was selected and deleted.
61
+ // In this case we will additionally call `clearNodes()` to convert e.g. a heading
62
+ // to a paragraph if necessary.
63
+ // This is an alternative to ProseMirror's `AllSelection`, which doesn’t work well
64
+ // with many other commands.
65
+ new Plugin({
66
+ key: new PluginKey('clearDocument'),
67
+ appendTransaction: (transactions, oldState, newState) => {
68
+ const docChanges = transactions.some(transaction => transaction.docChanged)
69
+ && !oldState.doc.eq(newState.doc)
70
+
71
+ if (!docChanges) {
72
+ return
73
+ }
74
+
75
+ const { empty, from, to } = oldState.selection
76
+ const allFrom = Selection.atStart(oldState.doc).from
77
+ const allEnd = Selection.atEnd(oldState.doc).to
78
+ const allWasSelected = from === allFrom && to === allEnd
79
+ const isEmpty = newState.doc.textBetween(0, newState.doc.content.size, ' ', ' ').length === 0
80
+
81
+ if (empty || !allWasSelected || !isEmpty) {
82
+ return
83
+ }
84
+
85
+ const tr = newState.tr
86
+ const state = createChainableState({
87
+ state: newState,
88
+ transaction: tr,
89
+ })
90
+ const { commands } = new CommandManager({
91
+ editor: this.editor,
92
+ state,
93
+ })
94
+
95
+ commands.clearNodes()
96
+
97
+ if (!tr.steps.length) {
98
+ return
99
+ }
100
+
101
+ return tr
102
+ },
103
+ }),
104
+ ]
105
+ },
36
106
  })
@@ -0,0 +1,19 @@
1
+ import { Plugin, PluginKey } from 'prosemirror-state'
2
+ import { Extension } from '../Extension'
3
+
4
+ export const Tabindex = Extension.create({
5
+ name: 'tabindex',
6
+
7
+ addProseMirrorPlugins() {
8
+ return [
9
+ new Plugin({
10
+ key: new PluginKey('tabindex'),
11
+ props: {
12
+ attributes: {
13
+ tabindex: '0',
14
+ },
15
+ },
16
+ }),
17
+ ]
18
+ },
19
+ })
@@ -0,0 +1,18 @@
1
+ import { Node as ProseMirrorNode } from 'prosemirror-model'
2
+ import { Transaction } from 'prosemirror-state'
3
+ import { Transform } from 'prosemirror-transform'
4
+
5
+ /**
6
+ * Returns a new `Transform` based on all steps of the passed transactions.
7
+ */
8
+ export function combineTransactionSteps(oldDoc: ProseMirrorNode, transactions: Transaction[]): Transform {
9
+ const transform = new Transform(oldDoc)
10
+
11
+ transactions.forEach(transaction => {
12
+ transaction.steps.forEach(step => {
13
+ transform.step(step)
14
+ })
15
+ })
16
+
17
+ return transform
18
+ }