@tiptap/core 2.0.0-beta.99 → 2.0.0-rc.1

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 (297) hide show
  1. package/README.md +3 -3
  2. package/dist/index.cjs +4360 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/{tiptap-core.esm.js → index.js} +2349 -1447
  5. package/dist/index.js.map +1 -0
  6. package/dist/index.umd.js +4358 -0
  7. package/dist/index.umd.js.map +1 -0
  8. package/dist/packages/core/src/CommandManager.d.ts +14 -7
  9. package/dist/packages/core/src/Editor.d.ts +25 -11
  10. package/dist/packages/core/src/EventEmitter.d.ts +8 -4
  11. package/dist/packages/core/src/Extension.d.ts +63 -29
  12. package/dist/packages/core/src/ExtensionManager.d.ts +3 -4
  13. package/dist/packages/core/src/InputRule.d.ts +42 -0
  14. package/dist/packages/core/src/Mark.d.ts +94 -36
  15. package/dist/packages/core/src/Node.d.ts +104 -45
  16. package/dist/packages/core/src/NodeView.d.ts +8 -8
  17. package/dist/packages/core/src/PasteRule.d.ts +42 -0
  18. package/dist/packages/core/src/Tracker.d.ts +1 -1
  19. package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +12 -0
  20. package/dist/packages/core/src/commands/deleteNode.d.ts +1 -1
  21. package/dist/packages/core/src/commands/deleteRange.d.ts +1 -1
  22. package/dist/packages/core/src/commands/extendMarkRange.d.ts +1 -1
  23. package/dist/packages/core/src/commands/focus.d.ts +4 -2
  24. package/dist/packages/core/src/commands/index.d.ts +50 -0
  25. package/dist/packages/core/src/commands/insertContent.d.ts +6 -3
  26. package/dist/packages/core/src/commands/insertContentAt.d.ts +6 -3
  27. package/dist/packages/core/src/commands/join.d.ts +33 -0
  28. package/dist/packages/core/src/commands/lift.d.ts +1 -1
  29. package/dist/packages/core/src/commands/liftListItem.d.ts +1 -1
  30. package/dist/packages/core/src/commands/resetAttributes.d.ts +1 -1
  31. package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +12 -0
  32. package/dist/packages/core/src/commands/selectTextblockStart.d.ts +12 -0
  33. package/dist/packages/core/src/commands/setContent.d.ts +2 -2
  34. package/dist/packages/core/src/commands/setMark.d.ts +1 -1
  35. package/dist/packages/core/src/commands/setNode.d.ts +1 -1
  36. package/dist/packages/core/src/commands/setTextSelection.d.ts +1 -1
  37. package/dist/packages/core/src/commands/sinkListItem.d.ts +1 -1
  38. package/dist/packages/core/src/commands/splitListItem.d.ts +1 -1
  39. package/dist/packages/core/src/commands/toggleList.d.ts +2 -2
  40. package/dist/packages/core/src/commands/toggleMark.d.ts +7 -2
  41. package/dist/packages/core/src/commands/toggleNode.d.ts +1 -1
  42. package/dist/packages/core/src/commands/toggleWrap.d.ts +1 -1
  43. package/dist/packages/core/src/commands/unsetMark.d.ts +7 -2
  44. package/dist/packages/core/src/commands/updateAttributes.d.ts +1 -1
  45. package/dist/packages/core/src/commands/wrapIn.d.ts +1 -1
  46. package/dist/packages/core/src/commands/wrapInList.d.ts +1 -1
  47. package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +1 -1
  48. package/dist/packages/core/src/extensions/commands.d.ts +2 -97
  49. package/dist/packages/core/src/extensions/editable.d.ts +1 -1
  50. package/dist/packages/core/src/extensions/focusEvents.d.ts +1 -1
  51. package/dist/packages/core/src/extensions/index.d.ts +1 -0
  52. package/dist/packages/core/src/extensions/keymap.d.ts +1 -1
  53. package/dist/packages/core/src/extensions/tabindex.d.ts +2 -0
  54. package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +7 -0
  55. package/dist/packages/core/src/helpers/createChainableState.d.ts +5 -0
  56. package/dist/packages/core/src/helpers/createDocument.d.ts +2 -2
  57. package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +2 -2
  58. package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +2 -0
  59. package/dist/packages/core/src/helpers/findChildren.d.ts +3 -3
  60. package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +3 -3
  61. package/dist/packages/core/src/helpers/findParentNode.d.ts +3 -4
  62. package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +3 -3
  63. package/dist/packages/core/src/helpers/generateHTML.d.ts +1 -1
  64. package/dist/packages/core/src/helpers/generateJSON.d.ts +1 -1
  65. package/dist/packages/core/src/helpers/generateText.d.ts +5 -0
  66. package/dist/packages/core/src/helpers/getAttributes.d.ts +3 -3
  67. package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +2 -2
  68. package/dist/packages/core/src/helpers/getChangedRanges.d.ts +11 -0
  69. package/dist/packages/core/src/helpers/getDebugJSON.d.ts +2 -5
  70. package/dist/packages/core/src/helpers/getExtensionField.d.ts +2 -2
  71. package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +2 -2
  72. package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +3 -3
  73. package/dist/packages/core/src/helpers/getMarkRange.d.ts +2 -2
  74. package/dist/packages/core/src/helpers/getMarkType.d.ts +2 -2
  75. package/dist/packages/core/src/helpers/getMarksBetween.d.ts +2 -2
  76. package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +3 -3
  77. package/dist/packages/core/src/helpers/getNodeType.d.ts +2 -2
  78. package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +2 -2
  79. package/dist/packages/core/src/helpers/getSchema.d.ts +2 -2
  80. package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +2 -2
  81. package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +2 -2
  82. package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +2 -2
  83. package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +1 -1
  84. package/dist/packages/core/src/helpers/getText.d.ts +6 -0
  85. package/dist/packages/core/src/helpers/getTextBetween.d.ts +6 -0
  86. package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +2 -0
  87. package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +3 -0
  88. package/dist/packages/core/src/helpers/index.d.ts +47 -0
  89. package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +2 -2
  90. package/dist/packages/core/src/helpers/isActive.d.ts +2 -2
  91. package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +2 -0
  92. package/dist/packages/core/src/helpers/isList.d.ts +1 -1
  93. package/dist/packages/core/src/helpers/isMarkActive.d.ts +3 -3
  94. package/dist/packages/core/src/helpers/isNodeActive.d.ts +3 -3
  95. package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +2 -2
  96. package/dist/packages/core/src/helpers/isNodeSelection.d.ts +2 -2
  97. package/dist/packages/core/src/helpers/isTextSelection.d.ts +2 -2
  98. package/dist/packages/core/src/helpers/posToDOMRect.d.ts +2 -2
  99. package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +4 -0
  100. package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +2 -2
  101. package/dist/packages/core/src/helpers/splitExtensions.d.ts +6 -6
  102. package/dist/packages/core/src/index.d.ts +12 -34
  103. package/dist/packages/core/src/inputRules/index.d.ts +5 -0
  104. package/dist/packages/core/src/inputRules/markInputRule.d.ts +12 -3
  105. package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +12 -3
  106. package/dist/packages/core/src/inputRules/textInputRule.d.ts +9 -0
  107. package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +14 -0
  108. package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +27 -0
  109. package/dist/packages/core/src/pasteRules/index.d.ts +3 -0
  110. package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +12 -3
  111. package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +12 -0
  112. package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +9 -0
  113. package/dist/packages/core/src/style.d.ts +1 -2
  114. package/dist/packages/core/src/types.d.ts +70 -40
  115. package/dist/packages/core/src/utilities/callOrReturn.d.ts +1 -1
  116. package/dist/packages/core/src/utilities/createStyleTag.d.ts +1 -1
  117. package/dist/packages/core/src/utilities/deleteProps.d.ts +1 -1
  118. package/dist/packages/core/src/utilities/elementFromString.d.ts +1 -1
  119. package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +1 -0
  120. package/dist/packages/core/src/utilities/findDuplicates.d.ts +1 -0
  121. package/dist/packages/core/src/utilities/fromString.d.ts +1 -1
  122. package/dist/packages/core/src/utilities/index.d.ts +20 -0
  123. package/dist/packages/core/src/utilities/isEmptyObject.d.ts +1 -1
  124. package/dist/packages/core/src/utilities/isFunction.d.ts +1 -0
  125. package/dist/packages/core/src/utilities/isMacOS.d.ts +1 -0
  126. package/dist/packages/core/src/utilities/isNumber.d.ts +1 -0
  127. package/dist/packages/core/src/utilities/isPlainObject.d.ts +1 -1
  128. package/dist/packages/core/src/utilities/isRegExp.d.ts +1 -0
  129. package/dist/packages/core/src/utilities/isString.d.ts +1 -0
  130. package/dist/packages/core/src/utilities/isiOS.d.ts +1 -1
  131. package/dist/packages/core/src/utilities/mergeAttributes.d.ts +1 -1
  132. package/dist/packages/core/src/utilities/mergeDeep.d.ts +1 -1
  133. package/dist/packages/core/src/utilities/minMax.d.ts +1 -1
  134. package/dist/packages/core/src/utilities/objectIncludes.d.ts +3 -1
  135. package/dist/packages/core/src/utilities/removeDuplicates.d.ts +8 -0
  136. package/package.json +25 -24
  137. package/src/CommandManager.ts +73 -83
  138. package/src/Editor.ts +101 -53
  139. package/src/EventEmitter.ts +14 -4
  140. package/src/Extension.ts +244 -138
  141. package/src/ExtensionManager.ts +153 -152
  142. package/src/InputRule.ts +260 -0
  143. package/src/Mark.ts +365 -204
  144. package/src/Node.ts +406 -253
  145. package/src/NodeView.ts +59 -38
  146. package/src/PasteRule.ts +240 -0
  147. package/src/Tracker.ts +4 -8
  148. package/src/commands/blur.ts +4 -0
  149. package/src/commands/clearNodes.ts +15 -9
  150. package/src/commands/createParagraphNear.ts +3 -2
  151. package/src/commands/deleteCurrentNode.ts +41 -0
  152. package/src/commands/deleteNode.ts +3 -2
  153. package/src/commands/deleteRange.ts +1 -1
  154. package/src/commands/deleteSelection.ts +3 -2
  155. package/src/commands/exitCode.ts +3 -2
  156. package/src/commands/extendMarkRange.ts +9 -5
  157. package/src/commands/focus.ts +31 -42
  158. package/src/commands/index.ts +50 -0
  159. package/src/commands/insertContent.ts +15 -4
  160. package/src/commands/insertContentAt.ts +71 -14
  161. package/src/commands/join.ts +53 -0
  162. package/src/commands/keyboardShortcut.ts +3 -3
  163. package/src/commands/lift.ts +6 -5
  164. package/src/commands/liftEmptyBlock.ts +2 -1
  165. package/src/commands/liftListItem.ts +5 -4
  166. package/src/commands/newlineInCode.ts +3 -2
  167. package/src/commands/resetAttributes.ts +16 -10
  168. package/src/commands/selectAll.ts +5 -3
  169. package/src/commands/selectNodeBackward.ts +3 -2
  170. package/src/commands/selectNodeForward.ts +3 -2
  171. package/src/commands/selectParentNode.ts +3 -2
  172. package/src/commands/selectTextblockEnd.ts +20 -0
  173. package/src/commands/selectTextblockStart.ts +20 -0
  174. package/src/commands/setContent.ts +6 -9
  175. package/src/commands/setMark.ts +66 -13
  176. package/src/commands/setNode.ts +30 -6
  177. package/src/commands/setNodeSelection.ts +6 -7
  178. package/src/commands/setTextSelection.ts +8 -9
  179. package/src/commands/sinkListItem.ts +5 -4
  180. package/src/commands/splitBlock.ts +23 -38
  181. package/src/commands/splitListItem.ts +30 -27
  182. package/src/commands/toggleList.ts +108 -19
  183. package/src/commands/toggleMark.ts +17 -6
  184. package/src/commands/toggleNode.ts +9 -4
  185. package/src/commands/toggleWrap.ts +8 -8
  186. package/src/commands/undoInputRule.ts +31 -2
  187. package/src/commands/unsetAllMarks.ts +4 -8
  188. package/src/commands/unsetMark.ts +34 -21
  189. package/src/commands/updateAttributes.ts +18 -12
  190. package/src/commands/wrapIn.ts +5 -10
  191. package/src/commands/wrapInList.ts +5 -4
  192. package/src/extensions/clipboardTextSerializer.ts +15 -36
  193. package/src/extensions/commands.ts +3 -144
  194. package/src/extensions/editable.ts +2 -1
  195. package/src/extensions/focusEvents.ts +4 -6
  196. package/src/extensions/index.ts +1 -0
  197. package/src/extensions/keymap.ts +111 -13
  198. package/src/extensions/tabindex.ts +18 -0
  199. package/src/helpers/combineTransactionSteps.ts +21 -0
  200. package/src/helpers/createChainableState.ts +38 -0
  201. package/src/helpers/createDocument.ts +4 -3
  202. package/src/helpers/createNodeFromContent.ts +10 -15
  203. package/src/helpers/defaultBlockAt.ts +13 -0
  204. package/src/helpers/findChildren.ts +4 -3
  205. package/src/helpers/findChildrenInRange.ts +8 -3
  206. package/src/helpers/findParentNode.ts +4 -3
  207. package/src/helpers/findParentNodeClosestToPos.ts +13 -7
  208. package/src/helpers/generateHTML.ts +6 -5
  209. package/src/helpers/generateJSON.ts +6 -7
  210. package/src/helpers/generateText.ts +27 -0
  211. package/src/helpers/getAttributes.ts +8 -9
  212. package/src/helpers/getAttributesFromExtensions.ts +25 -12
  213. package/src/helpers/getChangedRanges.ts +83 -0
  214. package/src/helpers/getDebugJSON.ts +42 -38
  215. package/src/helpers/getExtensionField.ts +3 -3
  216. package/src/helpers/getHTMLFromFragment.ts +5 -6
  217. package/src/helpers/getMarkAttributes.ts +18 -10
  218. package/src/helpers/getMarkRange.ts +13 -8
  219. package/src/helpers/getMarkType.ts +5 -3
  220. package/src/helpers/getMarksBetween.ts +34 -10
  221. package/src/helpers/getNodeAttributes.ts +14 -12
  222. package/src/helpers/getNodeType.ts +5 -3
  223. package/src/helpers/getRenderedAttributes.ts +8 -6
  224. package/src/helpers/getSchema.ts +5 -4
  225. package/src/helpers/getSchemaByResolvedExtensions.ts +165 -111
  226. package/src/helpers/getSchemaTypeByName.ts +3 -11
  227. package/src/helpers/getSchemaTypeNameByName.ts +2 -2
  228. package/src/helpers/getSplittedAttributes.ts +1 -1
  229. package/src/helpers/getText.ts +19 -0
  230. package/src/helpers/getTextBetween.ts +46 -0
  231. package/src/helpers/getTextContentFromNodes.ts +26 -0
  232. package/src/helpers/getTextSerializersFromSchema.ts +11 -0
  233. package/src/helpers/index.ts +47 -0
  234. package/src/helpers/injectExtensionAttributesToParseRule.ts +22 -23
  235. package/src/helpers/isActive.ts +10 -5
  236. package/src/helpers/isExtensionRulesEnabled.ts +15 -0
  237. package/src/helpers/isList.ts +6 -5
  238. package/src/helpers/isMarkActive.ts +32 -35
  239. package/src/helpers/isNodeActive.ts +27 -37
  240. package/src/helpers/isNodeEmpty.ts +2 -2
  241. package/src/helpers/isNodeSelection.ts +3 -4
  242. package/src/helpers/isTextSelection.ts +3 -4
  243. package/src/helpers/posToDOMRect.ts +10 -4
  244. package/src/helpers/resolveFocusPosition.ts +42 -0
  245. package/src/helpers/selectionToInsertionEnd.ts +3 -3
  246. package/src/helpers/splitExtensions.ts +3 -3
  247. package/src/index.ts +12 -37
  248. package/src/inputRules/index.ts +5 -0
  249. package/src/inputRules/markInputRule.ts +59 -40
  250. package/src/inputRules/nodeInputRule.ts +45 -12
  251. package/src/inputRules/textInputRule.ts +35 -0
  252. package/src/inputRules/textblockTypeInputRule.ts +37 -0
  253. package/src/inputRules/wrappingInputRule.ts +84 -0
  254. package/src/pasteRules/index.ts +3 -0
  255. package/src/pasteRules/markPasteRule.ts +49 -56
  256. package/src/pasteRules/nodePasteRule.ts +37 -0
  257. package/src/pasteRules/textPasteRule.ts +35 -0
  258. package/src/style.ts +12 -3
  259. package/src/types.ts +140 -106
  260. package/src/utilities/callOrReturn.ts +3 -2
  261. package/src/utilities/createStyleTag.ts +8 -4
  262. package/src/utilities/deleteProps.ts +1 -1
  263. package/src/utilities/elementFromString.ts +1 -1
  264. package/src/utilities/escapeForRegEx.ts +4 -0
  265. package/src/utilities/findDuplicates.ts +5 -0
  266. package/src/utilities/fromString.ts +2 -2
  267. package/src/utilities/index.ts +20 -0
  268. package/src/utilities/isEmptyObject.ts +2 -2
  269. package/src/utilities/isFunction.ts +3 -0
  270. package/src/utilities/isMacOS.ts +5 -0
  271. package/src/utilities/isNumber.ts +3 -0
  272. package/src/utilities/isPlainObject.ts +8 -5
  273. package/src/utilities/isRegExp.ts +3 -0
  274. package/src/utilities/isString.ts +3 -0
  275. package/src/utilities/isiOS.ts +1 -1
  276. package/src/utilities/mergeAttributes.ts +2 -1
  277. package/src/utilities/mergeDeep.ts +2 -2
  278. package/src/utilities/minMax.ts +1 -1
  279. package/src/utilities/objectIncludes.ts +18 -4
  280. package/src/utilities/removeDuplicates.ts +15 -0
  281. package/CHANGELOG.md +0 -1190
  282. package/LICENSE.md +0 -21
  283. package/dist/packages/core/src/commands/joinBackward.d.ts +0 -12
  284. package/dist/packages/core/src/commands/joinForward.d.ts +0 -12
  285. package/dist/packages/core/src/utilities/isClass.d.ts +0 -1
  286. package/dist/packages/core/src/utilities/isObject.d.ts +0 -1
  287. package/dist/packages/core/src/utilities/removeElement.d.ts +0 -1
  288. package/dist/tiptap-core.cjs.js +0 -3408
  289. package/dist/tiptap-core.cjs.js.map +0 -1
  290. package/dist/tiptap-core.esm.js.map +0 -1
  291. package/dist/tiptap-core.umd.js +0 -3405
  292. package/dist/tiptap-core.umd.js.map +0 -1
  293. package/src/commands/joinBackward.ts +0 -17
  294. package/src/commands/joinForward.ts +0 -17
  295. package/src/utilities/isClass.ts +0 -7
  296. package/src/utilities/isObject.ts +0 -10
  297. package/src/utilities/removeElement.ts +0 -5
@@ -1 +1 @@
1
- export default function mergeAttributes(...objects: Record<string, any>[]): Record<string, any>;
1
+ export declare function mergeAttributes(...objects: Record<string, any>[]): Record<string, any>;
@@ -1 +1 @@
1
- export default function mergeDeep(target: Record<string, any>, source: Record<string, any>): Record<string, any>;
1
+ export declare function mergeDeep(target: Record<string, any>, source: Record<string, any>): Record<string, any>;
@@ -1 +1 @@
1
- export default function minMax(value?: number, min?: number, max?: number): number;
1
+ export declare function minMax(value?: number, min?: number, max?: number): number;
@@ -3,4 +3,6 @@
3
3
  * @param object1 Object
4
4
  * @param object2 Object
5
5
  */
6
- export default function objectIncludes(object1: Record<string, any>, object2: Record<string, any>): boolean;
6
+ export declare function objectIncludes(object1: Record<string, any>, object2: Record<string, any>, options?: {
7
+ strict: boolean;
8
+ }): boolean;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Removes duplicated values within an array.
3
+ * Supports numbers, strings and objects.
4
+ */
5
+ export declare function removeDuplicates<T>(array: T[], by?: {
6
+ (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string;
7
+ (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string;
8
+ }): T[];
package/package.json CHANGED
@@ -1,49 +1,50 @@
1
1
  {
2
2
  "name": "@tiptap/core",
3
3
  "description": "headless rich text editor",
4
- "version": "2.0.0-beta.99",
4
+ "version": "2.0.0-rc.1",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
8
8
  "headless",
9
9
  "wysiwyg",
10
- "text editor"
10
+ "text editor",
11
+ "prosemirror"
11
12
  ],
12
13
  "license": "MIT",
13
14
  "funding": {
14
15
  "type": "github",
15
16
  "url": "https://github.com/sponsors/ueberdosis"
16
17
  },
17
- "main": "dist/tiptap-core.cjs.js",
18
- "umd": "dist/tiptap-core.umd.js",
19
- "module": "dist/tiptap-core.esm.js",
18
+ "type": "module",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/packages/core/src/index.d.ts",
22
+ "import": "./dist/index.js",
23
+ "require": "./dist/index.cjs"
24
+ }
25
+ },
26
+ "main": "dist/index.cjs",
27
+ "module": "dist/index.js",
28
+ "umd": "dist/index.umd.js",
20
29
  "types": "dist/packages/core/src/index.d.ts",
21
30
  "files": [
22
31
  "src",
23
32
  "dist"
24
33
  ],
25
- "dependencies": {
26
- "@types/prosemirror-commands": "^1.0.4",
27
- "@types/prosemirror-inputrules": "^1.0.4",
28
- "@types/prosemirror-keymap": "^1.0.4",
29
- "@types/prosemirror-model": "^1.13.1",
30
- "@types/prosemirror-schema-list": "^1.0.3",
31
- "@types/prosemirror-state": "^1.2.7",
32
- "@types/prosemirror-transform": "^1.1.4",
33
- "@types/prosemirror-view": "^1.17.2",
34
- "prosemirror-commands": "^1.1.10",
35
- "prosemirror-inputrules": "^1.1.3",
36
- "prosemirror-keymap": "^1.1.3",
37
- "prosemirror-model": "^1.14.3",
38
- "prosemirror-schema-list": "^1.1.5",
39
- "prosemirror-state": "^1.3.4",
40
- "prosemirror-transform": "^1.3.2",
41
- "prosemirror-view": "^1.19.0"
34
+ "peerDependencies": {
35
+ "@tiptap/pm": "2.0.0-rc.1"
36
+ },
37
+ "devDependencies": {
38
+ "@tiptap/pm": "2.0.0-rc.1"
42
39
  },
43
40
  "repository": {
44
41
  "type": "git",
45
42
  "url": "https://github.com/ueberdosis/tiptap",
46
43
  "directory": "packages/core"
47
44
  },
48
- "gitHead": "903220b86bc7f20df420410e5c9a70c79b1171fc"
49
- }
45
+ "sideEffects": false,
46
+ "scripts": {
47
+ "clean": "rm -rf dist",
48
+ "build": "npm run clean && rollup -c"
49
+ }
50
+ }
@@ -1,37 +1,44 @@
1
- import { EditorState, Transaction } from 'prosemirror-state'
1
+ import { EditorState, Transaction } from '@tiptap/pm/state'
2
+
2
3
  import { Editor } from './Editor'
4
+ import { createChainableState } from './helpers/createChainableState'
3
5
  import {
4
- SingleCommands,
5
- ChainedCommands,
6
- CanCommands,
7
- AnyCommands,
8
- CommandProps,
6
+ AnyCommands, CanCommands, ChainedCommands, CommandProps, SingleCommands,
9
7
  } from './types'
10
8
 
11
- export default class CommandManager {
12
-
9
+ export class CommandManager {
13
10
  editor: Editor
14
11
 
15
- commands: AnyCommands
12
+ rawCommands: AnyCommands
13
+
14
+ customState?: EditorState
15
+
16
+ constructor(props: { editor: Editor; state?: EditorState }) {
17
+ this.editor = props.editor
18
+ this.rawCommands = this.editor.extensionManager.commands
19
+ this.customState = props.state
20
+ }
21
+
22
+ get hasCustomState(): boolean {
23
+ return !!this.customState
24
+ }
16
25
 
17
- constructor(editor: Editor, commands: AnyCommands) {
18
- this.editor = editor
19
- this.commands = commands
26
+ get state(): EditorState {
27
+ return this.customState || this.editor.state
20
28
  }
21
29
 
22
- public createCommands(): SingleCommands {
23
- const { commands, editor } = this
24
- const { state, view } = editor
30
+ get commands(): SingleCommands {
31
+ const { rawCommands, editor, state } = this
32
+ const { view } = editor
25
33
  const { tr } = state
26
34
  const props = this.buildProps(tr)
27
35
 
28
- return Object.fromEntries(Object
29
- .entries(commands)
30
- .map(([name, command]) => {
36
+ return Object.fromEntries(
37
+ Object.entries(rawCommands).map(([name, command]) => {
31
38
  const method = (...args: any[]) => {
32
39
  const callback = command(...args)(props)
33
40
 
34
- if (!tr.getMeta('preventDispatch')) {
41
+ if (!tr.getMeta('preventDispatch') && !this.hasCustomState) {
35
42
  view.dispatch(tr)
36
43
  }
37
44
 
@@ -39,18 +46,32 @@ export default class CommandManager {
39
46
  }
40
47
 
41
48
  return [name, method]
42
- })) as unknown as SingleCommands
49
+ }),
50
+ ) as unknown as SingleCommands
51
+ }
52
+
53
+ get chain(): () => ChainedCommands {
54
+ return () => this.createChain()
55
+ }
56
+
57
+ get can(): () => CanCommands {
58
+ return () => this.createCan()
43
59
  }
44
60
 
45
61
  public createChain(startTr?: Transaction, shouldDispatch = true): ChainedCommands {
46
- const { commands, editor } = this
47
- const { state, view } = editor
62
+ const { rawCommands, editor, state } = this
63
+ const { view } = editor
48
64
  const callbacks: boolean[] = []
49
65
  const hasStartTransaction = !!startTr
50
66
  const tr = startTr || state.tr
51
67
 
52
68
  const run = () => {
53
- if (!hasStartTransaction && shouldDispatch && !tr.getMeta('preventDispatch')) {
69
+ if (
70
+ !hasStartTransaction
71
+ && shouldDispatch
72
+ && !tr.getMeta('preventDispatch')
73
+ && !this.hasCustomState
74
+ ) {
54
75
  view.dispatch(tr)
55
76
  }
56
77
 
@@ -58,18 +79,20 @@ export default class CommandManager {
58
79
  }
59
80
 
60
81
  const chain = {
61
- ...Object.fromEntries(Object.entries(commands).map(([name, command]) => {
62
- const chainedCommand = (...args: never[]) => {
63
- const props = this.buildProps(tr, shouldDispatch)
64
- const callback = command(...args)(props)
82
+ ...Object.fromEntries(
83
+ Object.entries(rawCommands).map(([name, command]) => {
84
+ const chainedCommand = (...args: never[]) => {
85
+ const props = this.buildProps(tr, shouldDispatch)
86
+ const callback = command(...args)(props)
65
87
 
66
- callbacks.push(callback)
88
+ callbacks.push(callback)
67
89
 
68
- return chain
69
- }
90
+ return chain
91
+ }
70
92
 
71
- return [name, chainedCommand]
72
- })),
93
+ return [name, chainedCommand]
94
+ }),
95
+ ),
73
96
  run,
74
97
  } as unknown as ChainedCommands
75
98
 
@@ -77,16 +100,15 @@ export default class CommandManager {
77
100
  }
78
101
 
79
102
  public createCan(startTr?: Transaction): CanCommands {
80
- const { commands, editor } = this
81
- const { state } = editor
82
- const dispatch = undefined
103
+ const { rawCommands, state } = this
104
+ const dispatch = false
83
105
  const tr = startTr || state.tr
84
106
  const props = this.buildProps(tr, dispatch)
85
- const formattedCommands = Object.fromEntries(Object
86
- .entries(commands)
87
- .map(([name, command]) => {
88
- return [name, (...args: never[]) => command(...args)({ ...props, dispatch })]
89
- })) as unknown as SingleCommands
107
+ const formattedCommands = Object.fromEntries(
108
+ Object.entries(rawCommands).map(([name, command]) => {
109
+ return [name, (...args: never[]) => command(...args)({ ...props, dispatch: undefined })]
110
+ }),
111
+ ) as unknown as SingleCommands
90
112
 
91
113
  return {
92
114
  ...formattedCommands,
@@ -95,8 +117,8 @@ export default class CommandManager {
95
117
  }
96
118
 
97
119
  public buildProps(tr: Transaction, shouldDispatch = true): CommandProps {
98
- const { editor, commands } = this
99
- const { state, view } = editor
120
+ const { rawCommands, editor, state } = this
121
+ const { view } = editor
100
122
 
101
123
  if (state.storedMarks) {
102
124
  tr.setStoredMarks(state.storedMarks)
@@ -106,54 +128,22 @@ export default class CommandManager {
106
128
  tr,
107
129
  editor,
108
130
  view,
109
- state: this.chainableState(tr, state),
110
- dispatch: shouldDispatch
111
- ? () => undefined
112
- : undefined,
131
+ state: createChainableState({
132
+ state,
133
+ transaction: tr,
134
+ }),
135
+ dispatch: shouldDispatch ? () => undefined : undefined,
113
136
  chain: () => this.createChain(tr),
114
137
  can: () => this.createCan(tr),
115
138
  get commands() {
116
- return Object.fromEntries(Object
117
- .entries(commands)
118
- .map(([name, command]) => {
139
+ return Object.fromEntries(
140
+ Object.entries(rawCommands).map(([name, command]) => {
119
141
  return [name, (...args: never[]) => command(...args)(props)]
120
- })) as unknown as SingleCommands
142
+ }),
143
+ ) as unknown as SingleCommands
121
144
  },
122
145
  }
123
146
 
124
147
  return props
125
148
  }
126
-
127
- public chainableState(tr: Transaction, state: EditorState): EditorState {
128
- let { selection } = tr
129
- let { doc } = tr
130
- let { storedMarks } = tr
131
-
132
- return {
133
- ...state,
134
- schema: state.schema,
135
- plugins: state.plugins,
136
- apply: state.apply.bind(state),
137
- applyTransaction: state.applyTransaction.bind(state),
138
- reconfigure: state.reconfigure.bind(state),
139
- toJSON: state.toJSON.bind(state),
140
- get storedMarks() {
141
- return storedMarks
142
- },
143
- get selection() {
144
- return selection
145
- },
146
- get doc() {
147
- return doc
148
- },
149
- get tr() {
150
- selection = tr.selection
151
- doc = tr.doc
152
- storedMarks = tr.storedMarks
153
-
154
- return tr
155
- },
156
- }
157
- }
158
-
159
149
  }
package/src/Editor.ts CHANGED
@@ -1,29 +1,33 @@
1
+ import { MarkType, NodeType, Schema } from '@tiptap/pm/model'
1
2
  import {
2
- EditorState,
3
- Plugin,
4
- PluginKey,
5
- Transaction,
6
- } from 'prosemirror-state'
7
- import { EditorView } from 'prosemirror-view'
8
- import { Schema, MarkType, NodeType } from 'prosemirror-model'
9
- import getAttributes from './helpers/getAttributes'
10
- import isActive from './helpers/isActive'
11
- import removeElement from './utilities/removeElement'
12
- import createDocument from './helpers/createDocument'
13
- import getHTMLFromFragment from './helpers/getHTMLFromFragment'
14
- import isNodeEmpty from './helpers/isNodeEmpty'
15
- import createStyleTag from './utilities/createStyleTag'
16
- import CommandManager from './CommandManager'
17
- import ExtensionManager from './ExtensionManager'
18
- import EventEmitter from './EventEmitter'
3
+ EditorState, Plugin, PluginKey, Transaction,
4
+ } from '@tiptap/pm/state'
5
+ import { EditorView } from '@tiptap/pm/view'
6
+
7
+ import { CommandManager } from './CommandManager'
8
+ import { EventEmitter } from './EventEmitter'
9
+ import { ExtensionManager } from './ExtensionManager'
10
+ import * as extensions from './extensions'
11
+ import { createDocument } from './helpers/createDocument'
12
+ import { getAttributes } from './helpers/getAttributes'
13
+ import { getHTMLFromFragment } from './helpers/getHTMLFromFragment'
14
+ import { getText } from './helpers/getText'
15
+ import { getTextSerializersFromSchema } from './helpers/getTextSerializersFromSchema'
16
+ import { isActive } from './helpers/isActive'
17
+ import { isNodeEmpty } from './helpers/isNodeEmpty'
18
+ import { resolveFocusPosition } from './helpers/resolveFocusPosition'
19
+ import { style } from './style'
19
20
  import {
20
- EditorOptions,
21
21
  CanCommands,
22
22
  ChainedCommands,
23
+ EditorEvents,
24
+ EditorOptions,
25
+ JSONContent,
23
26
  SingleCommands,
27
+ TextSerializer,
24
28
  } from './types'
25
- import * as extensions from './extensions'
26
- import style from './style'
29
+ import { createStyleTag } from './utilities/createStyleTag'
30
+ import { isFunction } from './utilities/isFunction'
27
31
 
28
32
  export { extensions }
29
33
 
@@ -31,8 +35,7 @@ export interface HTMLElement {
31
35
  editor?: Editor
32
36
  }
33
37
 
34
- export class Editor extends EventEmitter {
35
-
38
+ export class Editor extends EventEmitter<EditorEvents> {
36
39
  private commandManager!: CommandManager
37
40
 
38
41
  public extensionManager!: ExtensionManager
@@ -45,10 +48,13 @@ export class Editor extends EventEmitter {
45
48
 
46
49
  public isFocused = false
47
50
 
51
+ public extensionStorage: Record<string, any> = {}
52
+
48
53
  public options: EditorOptions = {
49
54
  element: document.createElement('div'),
50
55
  content: '',
51
56
  injectCSS: true,
57
+ injectNonce: undefined,
52
58
  extensions: [],
53
59
  autofocus: false,
54
60
  editable: true,
@@ -56,6 +62,7 @@ export class Editor extends EventEmitter {
56
62
  parseOptions: {},
57
63
  enableInputRules: true,
58
64
  enablePasteRules: true,
65
+ enableCoreExtensions: true,
59
66
  onBeforeCreate: () => null,
60
67
  onCreate: () => null,
61
68
  onUpdate: () => null,
@@ -94,25 +101,32 @@ export class Editor extends EventEmitter {
94
101
  }, 0)
95
102
  }
96
103
 
104
+ /**
105
+ * Returns the editor storage.
106
+ */
107
+ public get storage(): Record<string, any> {
108
+ return this.extensionStorage
109
+ }
110
+
97
111
  /**
98
112
  * An object of all registered commands.
99
113
  */
100
114
  public get commands(): SingleCommands {
101
- return this.commandManager.createCommands()
115
+ return this.commandManager.commands
102
116
  }
103
117
 
104
118
  /**
105
119
  * Create a command chain to call multiple commands at once.
106
120
  */
107
121
  public chain(): ChainedCommands {
108
- return this.commandManager.createChain()
122
+ return this.commandManager.chain()
109
123
  }
110
124
 
111
125
  /**
112
126
  * Check if a command or a command chain can be executed. Without executing it.
113
127
  */
114
128
  public can(): CanCommands {
115
- return this.commandManager.createCan()
129
+ return this.commandManager.can()
116
130
  }
117
131
 
118
132
  /**
@@ -120,7 +134,7 @@ export class Editor extends EventEmitter {
120
134
  */
121
135
  private injectCSS(): void {
122
136
  if (this.options.injectCSS && document) {
123
- this.css = createStyleTag(style)
137
+ this.css = createStyleTag(style, this.options.injectNonce)
124
138
  }
125
139
  }
126
140
 
@@ -149,8 +163,12 @@ export class Editor extends EventEmitter {
149
163
  /**
150
164
  * Update editable state of the editor.
151
165
  */
152
- public setEditable(editable: boolean): void {
166
+ public setEditable(editable: boolean, emitUpdate = true): void {
153
167
  this.setOptions({ editable })
168
+
169
+ if (emitUpdate) {
170
+ this.emit('update', { editor: this, transaction: this.state.tr })
171
+ }
154
172
  }
155
173
 
156
174
  /**
@@ -160,9 +178,7 @@ export class Editor extends EventEmitter {
160
178
  // since plugins are applied after creating the view
161
179
  // `editable` is always `true` for one tick.
162
180
  // that’s why we also have to check for `options.editable`
163
- return this.options.editable
164
- && this.view
165
- && this.view.editable
181
+ return this.options.editable && this.view && this.view.editable
166
182
  }
167
183
 
168
184
  /**
@@ -178,9 +194,12 @@ export class Editor extends EventEmitter {
178
194
  * @param plugin A ProseMirror plugin
179
195
  * @param handlePlugins Control how to merge the plugin into the existing plugins.
180
196
  */
181
- public registerPlugin(plugin: Plugin, handlePlugins?: (newPlugin: Plugin, plugins: Plugin[]) => Plugin[]): void {
182
- const plugins = typeof handlePlugins === 'function'
183
- ? handlePlugins(plugin, this.state.plugins)
197
+ public registerPlugin(
198
+ plugin: Plugin,
199
+ handlePlugins?: (newPlugin: Plugin, plugins: Plugin[]) => Plugin[],
200
+ ): void {
201
+ const plugins = isFunction(handlePlugins)
202
+ ? handlePlugins(plugin, [...this.state.plugins])
184
203
  : [...this.state.plugins, plugin]
185
204
 
186
205
  const state = this.state.reconfigure({ plugins })
@@ -191,17 +210,15 @@ export class Editor extends EventEmitter {
191
210
  /**
192
211
  * Unregister a ProseMirror plugin.
193
212
  *
194
- * @param name The plugins name
213
+ * @param nameOrPluginKey The plugins name
195
214
  */
196
215
  public unregisterPlugin(nameOrPluginKey: string | PluginKey): void {
197
216
  if (this.isDestroyed) {
198
217
  return
199
218
  }
200
219
 
201
- const name = typeof nameOrPluginKey === 'string'
202
- ? `${nameOrPluginKey}$`
203
- // @ts-ignore
204
- : nameOrPluginKey.key
220
+ // @ts-ignore
221
+ const name = typeof nameOrPluginKey === 'string' ? `${nameOrPluginKey}$` : nameOrPluginKey.key
205
222
 
206
223
  const state = this.state.reconfigure({
207
224
  // @ts-ignore
@@ -215,7 +232,7 @@ export class Editor extends EventEmitter {
215
232
  * Creates an extension manager.
216
233
  */
217
234
  private createExtensionManager(): void {
218
- const coreExtensions = Object.entries(extensions).map(([, extension]) => extension)
235
+ const coreExtensions = this.options.enableCoreExtensions ? Object.values(extensions) : []
219
236
  const allExtensions = [...coreExtensions, ...this.options.extensions].filter(extension => {
220
237
  return ['extension', 'node', 'mark'].includes(extension?.type)
221
238
  })
@@ -227,7 +244,9 @@ export class Editor extends EventEmitter {
227
244
  * Creates an command manager.
228
245
  */
229
246
  private createCommandManager(): void {
230
- this.commandManager = new CommandManager(this, this.extensionManager.commands)
247
+ this.commandManager = new CommandManager({
248
+ editor: this,
249
+ })
231
250
  }
232
251
 
233
252
  /**
@@ -241,11 +260,15 @@ export class Editor extends EventEmitter {
241
260
  * Creates a ProseMirror view.
242
261
  */
243
262
  private createView(): void {
263
+ const doc = createDocument(this.options.content, this.schema, this.options.parseOptions)
264
+ const selection = resolveFocusPosition(doc, this.options.autofocus)
265
+
244
266
  this.view = new EditorView(this.options.element, {
245
267
  ...this.options.editorProps,
246
268
  dispatchTransaction: this.dispatchTransaction.bind(this),
247
269
  state: EditorState.create({
248
- doc: createDocument(this.options.content, this.schema, this.options.parseOptions),
270
+ doc,
271
+ selection: selection || undefined,
249
272
  }),
250
273
  })
251
274
 
@@ -262,6 +285,7 @@ export class Editor extends EventEmitter {
262
285
  // Let’s store the editor instance in the DOM element.
263
286
  // So we’ll have access to it for tests.
264
287
  const dom = this.view.dom as HTMLElement
288
+
265
289
  dom.editor = this
266
290
  }
267
291
 
@@ -296,6 +320,12 @@ export class Editor extends EventEmitter {
296
320
  * @param transaction An editor state transaction
297
321
  */
298
322
  private dispatchTransaction(transaction: Transaction): void {
323
+ // if the editor / the view of the editor was destroyed
324
+ // the transaction should not be dispatched as there is no view anymore.
325
+ if (this.view.isDestroyed) {
326
+ return
327
+ }
328
+
299
329
  if (this.isCapturingTransaction) {
300
330
  if (!this.capturedTransaction) {
301
331
  this.capturedTransaction = transaction
@@ -366,16 +396,12 @@ export class Editor extends EventEmitter {
366
396
  * @param name Name of the node or mark
367
397
  * @param attributes Attributes of the node or mark
368
398
  */
369
- public isActive(name: string, attributes?: {}): boolean;
370
- public isActive(attributes: {}): boolean;
399
+ public isActive(name: string, attributes?: {}): boolean
400
+ public isActive(attributes: {}): boolean
371
401
  public isActive(nameOrAttributes: string, attributesOrUndefined?: {}): boolean {
372
- const name = typeof nameOrAttributes === 'string'
373
- ? nameOrAttributes
374
- : null
402
+ const name = typeof nameOrAttributes === 'string' ? nameOrAttributes : null
375
403
 
376
- const attributes = typeof nameOrAttributes === 'string'
377
- ? attributesOrUndefined
378
- : nameOrAttributes
404
+ const attributes = typeof nameOrAttributes === 'string' ? attributesOrUndefined : nameOrAttributes
379
405
 
380
406
  return isActive(this.state, name, attributes)
381
407
  }
@@ -383,7 +409,7 @@ export class Editor extends EventEmitter {
383
409
  /**
384
410
  * Get the document as JSON.
385
411
  */
386
- public getJSON(): Record<string, any> {
412
+ public getJSON(): JSONContent {
387
413
  return this.state.doc.toJSON()
388
414
  }
389
415
 
@@ -391,7 +417,25 @@ export class Editor extends EventEmitter {
391
417
  * Get the document as HTML.
392
418
  */
393
419
  public getHTML(): string {
394
- return getHTMLFromFragment(this.state.doc, this.schema)
420
+ return getHTMLFromFragment(this.state.doc.content, this.schema)
421
+ }
422
+
423
+ /**
424
+ * Get the document as text.
425
+ */
426
+ public getText(options?: {
427
+ blockSeparator?: string
428
+ textSerializers?: Record<string, TextSerializer>
429
+ }): string {
430
+ const { blockSeparator = '\n\n', textSerializers = {} } = options || {}
431
+
432
+ return getText(this.state.doc, {
433
+ blockSeparator,
434
+ textSerializers: {
435
+ ...getTextSerializersFromSchema(this.schema),
436
+ ...textSerializers,
437
+ },
438
+ })
395
439
  }
396
440
 
397
441
  /**
@@ -403,8 +447,14 @@ export class Editor extends EventEmitter {
403
447
 
404
448
  /**
405
449
  * Get the number of characters for the current document.
450
+ *
451
+ * @deprecated
406
452
  */
407
453
  public getCharacterCount(): number {
454
+ console.warn(
455
+ '[tiptap warn]: "editor.getCharacterCount()" is deprecated. Please use "editor.storage.characterCount.characters()" instead.',
456
+ )
457
+
408
458
  return this.state.doc.content.size - 2
409
459
  }
410
460
 
@@ -419,7 +469,6 @@ export class Editor extends EventEmitter {
419
469
  }
420
470
 
421
471
  this.removeAllListeners()
422
- removeElement(this.css)
423
472
  }
424
473
 
425
474
  /**
@@ -429,5 +478,4 @@ export class Editor extends EventEmitter {
429
478
  // @ts-ignore
430
479
  return !this.view?.docView
431
480
  }
432
-
433
481
  }