@tiptap/core 2.0.0-beta.209 → 2.0.0-beta.210

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 (259) hide show
  1. package/dist/index.cjs +4311 -0
  2. package/dist/index.d.ts +2330 -0
  3. package/dist/index.js +4311 -0
  4. package/package.json +24 -23
  5. package/src/CommandManager.ts +27 -36
  6. package/src/Editor.ts +27 -37
  7. package/src/Extension.ts +193 -179
  8. package/src/ExtensionManager.ts +82 -98
  9. package/src/InputRule.ts +38 -43
  10. package/src/Mark.ts +277 -264
  11. package/src/Node.ts +349 -314
  12. package/src/NodeView.ts +24 -23
  13. package/src/PasteRule.ts +37 -44
  14. package/src/Tracker.ts +4 -8
  15. package/src/commands/clearNodes.ts +1 -1
  16. package/src/commands/createParagraphNear.ts +2 -2
  17. package/src/commands/deleteNode.ts +1 -1
  18. package/src/commands/deleteSelection.ts +2 -2
  19. package/src/commands/exitCode.ts +2 -2
  20. package/src/commands/extendMarkRange.ts +6 -3
  21. package/src/commands/insertContent.ts +9 -5
  22. package/src/commands/insertContentAt.ts +10 -24
  23. package/src/commands/join.ts +9 -6
  24. package/src/commands/lift.ts +3 -3
  25. package/src/commands/liftEmptyBlock.ts +1 -1
  26. package/src/commands/liftListItem.ts +3 -3
  27. package/src/commands/newlineInCode.ts +2 -2
  28. package/src/commands/resetAttributes.ts +11 -6
  29. package/src/commands/selectNodeBackward.ts +2 -2
  30. package/src/commands/selectNodeForward.ts +2 -2
  31. package/src/commands/selectParentNode.ts +2 -2
  32. package/src/commands/selectTextblockEnd.ts +2 -2
  33. package/src/commands/selectTextblockStart.ts +2 -2
  34. package/src/commands/setContent.ts +3 -4
  35. package/src/commands/setMark.ts +26 -16
  36. package/src/commands/setNode.ts +19 -17
  37. package/src/commands/setNodeSelection.ts +2 -2
  38. package/src/commands/setTextSelection.ts +3 -5
  39. package/src/commands/sinkListItem.ts +3 -3
  40. package/src/commands/splitBlock.ts +20 -25
  41. package/src/commands/splitListItem.ts +15 -25
  42. package/src/commands/toggleList.ts +27 -24
  43. package/src/commands/toggleMark.ts +3 -3
  44. package/src/commands/toggleNode.ts +6 -2
  45. package/src/commands/toggleWrap.ts +2 -2
  46. package/src/commands/unsetMark.ts +3 -3
  47. package/src/commands/updateAttributes.ts +14 -9
  48. package/src/commands/wrapIn.ts +3 -3
  49. package/src/commands/wrapInList.ts +3 -3
  50. package/src/extensions/clipboardTextSerializer.ts +1 -1
  51. package/src/extensions/editable.ts +1 -1
  52. package/src/extensions/focusEvents.ts +1 -1
  53. package/src/extensions/keymap.ts +2 -7
  54. package/src/extensions/tabindex.ts +1 -1
  55. package/src/helpers/combineTransactionSteps.ts +7 -4
  56. package/src/helpers/createChainableState.ts +3 -3
  57. package/src/helpers/createDocument.ts +1 -1
  58. package/src/helpers/createNodeFromContent.ts +4 -10
  59. package/src/helpers/defaultBlockAt.ts +1 -1
  60. package/src/helpers/findChildren.ts +1 -1
  61. package/src/helpers/findChildrenInRange.ts +6 -2
  62. package/src/helpers/findParentNode.ts +1 -1
  63. package/src/helpers/findParentNodeClosestToPos.ts +12 -7
  64. package/src/helpers/generateHTML.ts +1 -1
  65. package/src/helpers/generateJSON.ts +2 -4
  66. package/src/helpers/generateText.ts +4 -7
  67. package/src/helpers/getAttributes.ts +3 -5
  68. package/src/helpers/getChangedRanges.ts +1 -1
  69. package/src/helpers/getDebugJSON.ts +4 -4
  70. package/src/helpers/getHTMLFromFragment.ts +2 -4
  71. package/src/helpers/getMarkAttributes.ts +6 -3
  72. package/src/helpers/getMarkRange.ts +1 -1
  73. package/src/helpers/getMarkType.ts +4 -2
  74. package/src/helpers/getMarksBetween.ts +8 -6
  75. package/src/helpers/getNodeAttributes.ts +7 -6
  76. package/src/helpers/getNodeType.ts +4 -2
  77. package/src/helpers/getRenderedAttributes.ts +5 -2
  78. package/src/helpers/getSchema.ts +1 -1
  79. package/src/helpers/getSchemaByResolvedExtensions.ts +151 -107
  80. package/src/helpers/getSchemaTypeByName.ts +1 -1
  81. package/src/helpers/getSchemaTypeNameByName.ts +1 -1
  82. package/src/helpers/getText.ts +3 -3
  83. package/src/helpers/getTextBetween.ts +4 -7
  84. package/src/helpers/getTextContentFromNodes.ts +8 -3
  85. package/src/helpers/getTextSerializersFromSchema.ts +6 -5
  86. package/src/helpers/injectExtensionAttributesToParseRule.ts +6 -5
  87. package/src/helpers/isActive.ts +6 -2
  88. package/src/helpers/isMarkActive.ts +12 -15
  89. package/src/helpers/isNodeActive.ts +4 -7
  90. package/src/helpers/isNodeEmpty.ts +1 -1
  91. package/src/helpers/isNodeSelection.ts +1 -1
  92. package/src/helpers/isTextSelection.ts +1 -1
  93. package/src/helpers/posToDOMRect.ts +1 -1
  94. package/src/helpers/resolveFocusPosition.ts +2 -3
  95. package/src/helpers/selectionToInsertionEnd.ts +2 -2
  96. package/src/inputRules/markInputRule.ts +3 -4
  97. package/src/inputRules/nodeInputRule.ts +3 -4
  98. package/src/inputRules/textblockTypeInputRule.ts +3 -4
  99. package/src/inputRules/wrappingInputRule.ts +5 -6
  100. package/src/pasteRules/markPasteRule.ts +3 -4
  101. package/src/pasteRules/nodePasteRule.ts +8 -10
  102. package/src/types.ts +109 -125
  103. package/dist/packages/core/src/CommandManager.d.ts +0 -20
  104. package/dist/packages/core/src/Editor.d.ts +0 -147
  105. package/dist/packages/core/src/EventEmitter.d.ts +0 -11
  106. package/dist/packages/core/src/Extension.d.ts +0 -227
  107. package/dist/packages/core/src/ExtensionManager.d.ts +0 -18
  108. package/dist/packages/core/src/InputRule.d.ts +0 -42
  109. package/dist/packages/core/src/Mark.d.ts +0 -327
  110. package/dist/packages/core/src/Node.d.ts +0 -397
  111. package/dist/packages/core/src/NodeView.d.ts +0 -27
  112. package/dist/packages/core/src/PasteRule.d.ts +0 -42
  113. package/dist/packages/core/src/Tracker.d.ts +0 -11
  114. package/dist/packages/core/src/commands/blur.d.ts +0 -12
  115. package/dist/packages/core/src/commands/clearContent.d.ts +0 -12
  116. package/dist/packages/core/src/commands/clearNodes.d.ts +0 -12
  117. package/dist/packages/core/src/commands/command.d.ts +0 -12
  118. package/dist/packages/core/src/commands/createParagraphNear.d.ts +0 -12
  119. package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +0 -12
  120. package/dist/packages/core/src/commands/deleteNode.d.ts +0 -13
  121. package/dist/packages/core/src/commands/deleteRange.d.ts +0 -12
  122. package/dist/packages/core/src/commands/deleteSelection.d.ts +0 -12
  123. package/dist/packages/core/src/commands/enter.d.ts +0 -12
  124. package/dist/packages/core/src/commands/exitCode.d.ts +0 -12
  125. package/dist/packages/core/src/commands/extendMarkRange.d.ts +0 -13
  126. package/dist/packages/core/src/commands/first.d.ts +0 -12
  127. package/dist/packages/core/src/commands/focus.d.ts +0 -14
  128. package/dist/packages/core/src/commands/forEach.d.ts +0 -14
  129. package/dist/packages/core/src/commands/index.d.ts +0 -50
  130. package/dist/packages/core/src/commands/insertContent.d.ts +0 -16
  131. package/dist/packages/core/src/commands/insertContentAt.d.ts +0 -16
  132. package/dist/packages/core/src/commands/join.d.ts +0 -33
  133. package/dist/packages/core/src/commands/keyboardShortcut.d.ts +0 -12
  134. package/dist/packages/core/src/commands/lift.d.ts +0 -13
  135. package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +0 -12
  136. package/dist/packages/core/src/commands/liftListItem.d.ts +0 -13
  137. package/dist/packages/core/src/commands/newlineInCode.d.ts +0 -12
  138. package/dist/packages/core/src/commands/resetAttributes.d.ts +0 -13
  139. package/dist/packages/core/src/commands/scrollIntoView.d.ts +0 -12
  140. package/dist/packages/core/src/commands/selectAll.d.ts +0 -12
  141. package/dist/packages/core/src/commands/selectNodeBackward.d.ts +0 -12
  142. package/dist/packages/core/src/commands/selectNodeForward.d.ts +0 -12
  143. package/dist/packages/core/src/commands/selectParentNode.d.ts +0 -12
  144. package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +0 -12
  145. package/dist/packages/core/src/commands/selectTextblockStart.d.ts +0 -12
  146. package/dist/packages/core/src/commands/setContent.d.ts +0 -13
  147. package/dist/packages/core/src/commands/setMark.d.ts +0 -13
  148. package/dist/packages/core/src/commands/setMeta.d.ts +0 -12
  149. package/dist/packages/core/src/commands/setNode.d.ts +0 -13
  150. package/dist/packages/core/src/commands/setNodeSelection.d.ts +0 -12
  151. package/dist/packages/core/src/commands/setTextSelection.d.ts +0 -12
  152. package/dist/packages/core/src/commands/sinkListItem.d.ts +0 -13
  153. package/dist/packages/core/src/commands/splitBlock.d.ts +0 -14
  154. package/dist/packages/core/src/commands/splitListItem.d.ts +0 -13
  155. package/dist/packages/core/src/commands/toggleList.d.ts +0 -13
  156. package/dist/packages/core/src/commands/toggleMark.d.ts +0 -18
  157. package/dist/packages/core/src/commands/toggleNode.d.ts +0 -13
  158. package/dist/packages/core/src/commands/toggleWrap.d.ts +0 -13
  159. package/dist/packages/core/src/commands/undoInputRule.d.ts +0 -12
  160. package/dist/packages/core/src/commands/unsetAllMarks.d.ts +0 -12
  161. package/dist/packages/core/src/commands/unsetMark.d.ts +0 -18
  162. package/dist/packages/core/src/commands/updateAttributes.d.ts +0 -13
  163. package/dist/packages/core/src/commands/wrapIn.d.ts +0 -13
  164. package/dist/packages/core/src/commands/wrapInList.d.ts +0 -13
  165. package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +0 -2
  166. package/dist/packages/core/src/extensions/commands.d.ts +0 -3
  167. package/dist/packages/core/src/extensions/editable.d.ts +0 -2
  168. package/dist/packages/core/src/extensions/focusEvents.d.ts +0 -2
  169. package/dist/packages/core/src/extensions/index.d.ts +0 -6
  170. package/dist/packages/core/src/extensions/keymap.d.ts +0 -2
  171. package/dist/packages/core/src/extensions/tabindex.d.ts +0 -2
  172. package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +0 -7
  173. package/dist/packages/core/src/helpers/createChainableState.d.ts +0 -5
  174. package/dist/packages/core/src/helpers/createDocument.d.ts +0 -3
  175. package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +0 -7
  176. package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +0 -2
  177. package/dist/packages/core/src/helpers/findChildren.d.ts +0 -3
  178. package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +0 -6
  179. package/dist/packages/core/src/helpers/findParentNode.d.ts +0 -8
  180. package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +0 -8
  181. package/dist/packages/core/src/helpers/generateHTML.d.ts +0 -2
  182. package/dist/packages/core/src/helpers/generateJSON.d.ts +0 -2
  183. package/dist/packages/core/src/helpers/generateText.d.ts +0 -5
  184. package/dist/packages/core/src/helpers/getAttributes.d.ts +0 -3
  185. package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +0 -6
  186. package/dist/packages/core/src/helpers/getChangedRanges.d.ts +0 -11
  187. package/dist/packages/core/src/helpers/getDebugJSON.d.ts +0 -8
  188. package/dist/packages/core/src/helpers/getExtensionField.d.ts +0 -2
  189. package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +0 -2
  190. package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +0 -3
  191. package/dist/packages/core/src/helpers/getMarkRange.d.ts +0 -3
  192. package/dist/packages/core/src/helpers/getMarkType.d.ts +0 -2
  193. package/dist/packages/core/src/helpers/getMarksBetween.d.ts +0 -3
  194. package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +0 -3
  195. package/dist/packages/core/src/helpers/getNodeType.d.ts +0 -2
  196. package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +0 -3
  197. package/dist/packages/core/src/helpers/getSchema.d.ts +0 -3
  198. package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +0 -3
  199. package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +0 -2
  200. package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +0 -2
  201. package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +0 -2
  202. package/dist/packages/core/src/helpers/getText.d.ts +0 -6
  203. package/dist/packages/core/src/helpers/getTextBetween.d.ts +0 -6
  204. package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +0 -2
  205. package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +0 -3
  206. package/dist/packages/core/src/helpers/index.d.ts +0 -33
  207. package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +0 -9
  208. package/dist/packages/core/src/helpers/isActive.d.ts +0 -2
  209. package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +0 -2
  210. package/dist/packages/core/src/helpers/isList.d.ts +0 -2
  211. package/dist/packages/core/src/helpers/isMarkActive.d.ts +0 -3
  212. package/dist/packages/core/src/helpers/isNodeActive.d.ts +0 -3
  213. package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +0 -2
  214. package/dist/packages/core/src/helpers/isNodeSelection.d.ts +0 -2
  215. package/dist/packages/core/src/helpers/isTextSelection.d.ts +0 -2
  216. package/dist/packages/core/src/helpers/posToDOMRect.d.ts +0 -2
  217. package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +0 -4
  218. package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +0 -2
  219. package/dist/packages/core/src/helpers/splitExtensions.d.ts +0 -9
  220. package/dist/packages/core/src/index.d.ts +0 -23
  221. package/dist/packages/core/src/inputRules/index.d.ts +0 -5
  222. package/dist/packages/core/src/inputRules/markInputRule.d.ts +0 -12
  223. package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -12
  224. package/dist/packages/core/src/inputRules/textInputRule.d.ts +0 -9
  225. package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +0 -14
  226. package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +0 -23
  227. package/dist/packages/core/src/pasteRules/index.d.ts +0 -3
  228. package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +0 -12
  229. package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +0 -12
  230. package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +0 -9
  231. package/dist/packages/core/src/style.d.ts +0 -1
  232. package/dist/packages/core/src/types.d.ts +0 -214
  233. package/dist/packages/core/src/utilities/callOrReturn.d.ts +0 -9
  234. package/dist/packages/core/src/utilities/createStyleTag.d.ts +0 -1
  235. package/dist/packages/core/src/utilities/deleteProps.d.ts +0 -6
  236. package/dist/packages/core/src/utilities/elementFromString.d.ts +0 -1
  237. package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +0 -1
  238. package/dist/packages/core/src/utilities/findDuplicates.d.ts +0 -1
  239. package/dist/packages/core/src/utilities/fromString.d.ts +0 -1
  240. package/dist/packages/core/src/utilities/index.d.ts +0 -20
  241. package/dist/packages/core/src/utilities/isEmptyObject.d.ts +0 -1
  242. package/dist/packages/core/src/utilities/isFunction.d.ts +0 -1
  243. package/dist/packages/core/src/utilities/isMacOS.d.ts +0 -1
  244. package/dist/packages/core/src/utilities/isNumber.d.ts +0 -1
  245. package/dist/packages/core/src/utilities/isPlainObject.d.ts +0 -1
  246. package/dist/packages/core/src/utilities/isRegExp.d.ts +0 -1
  247. package/dist/packages/core/src/utilities/isString.d.ts +0 -1
  248. package/dist/packages/core/src/utilities/isiOS.d.ts +0 -1
  249. package/dist/packages/core/src/utilities/mergeAttributes.d.ts +0 -1
  250. package/dist/packages/core/src/utilities/mergeDeep.d.ts +0 -1
  251. package/dist/packages/core/src/utilities/minMax.d.ts +0 -1
  252. package/dist/packages/core/src/utilities/objectIncludes.d.ts +0 -8
  253. package/dist/packages/core/src/utilities/removeDuplicates.d.ts +0 -8
  254. package/dist/tiptap-core.cjs +0 -4360
  255. package/dist/tiptap-core.cjs.map +0 -1
  256. package/dist/tiptap-core.esm.js +0 -4284
  257. package/dist/tiptap-core.esm.js.map +0 -1
  258. package/dist/tiptap-core.umd.js +0 -4358
  259. package/dist/tiptap-core.umd.js.map +0 -1
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tiptap/core",
3
3
  "description": "headless rich text editor",
4
- "version": "2.0.0-beta.209",
4
+ "version": "2.0.0-beta.210",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -18,41 +18,42 @@
18
18
  "type": "module",
19
19
  "exports": {
20
20
  ".": {
21
- "types": "./dist/packages/core/src/index.d.ts",
22
- "import": "./dist/tiptap-core.esm.js",
23
- "require": "./dist/tiptap-core.cjs"
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.js",
23
+ "require": "./dist/index.cjs"
24
24
  }
25
25
  },
26
- "main": "dist/tiptap-core.cjs",
27
- "umd": "dist/tiptap-core.umd.js",
28
- "module": "dist/tiptap-core.esm.js",
29
- "types": "dist/packages/core/src/index.d.ts",
26
+ "main": "dist/index.cjs",
27
+ "module": "dist/index.js",
28
+ "types": "dist/index.d.ts",
30
29
  "files": [
31
30
  "src",
32
31
  "dist"
33
32
  ],
34
33
  "peerDependencies": {
35
- "prosemirror-commands": "^1.3.1",
36
- "prosemirror-keymap": "^1.2.0",
37
- "prosemirror-model": "^1.18.1",
38
- "prosemirror-schema-list": "^1.2.2",
39
- "prosemirror-state": "^1.4.1",
40
- "prosemirror-transform": "^1.7.0",
41
- "prosemirror-view": "^1.28.2"
34
+ "@tiptap/pm": "^2.0.0-beta.209"
42
35
  },
43
36
  "devDependencies": {
44
- "prosemirror-commands": "^1.3.1",
45
- "prosemirror-keymap": "^1.2.0",
46
- "prosemirror-model": "^1.18.1",
47
- "prosemirror-schema-list": "^1.2.2",
48
- "prosemirror-state": "^1.4.1",
49
- "prosemirror-transform": "^1.7.0",
50
- "prosemirror-view": "^1.28.2"
37
+ "@tiptap/pm": "^2.0.0-beta.210"
51
38
  },
52
39
  "repository": {
53
40
  "type": "git",
54
41
  "url": "https://github.com/ueberdosis/tiptap",
55
42
  "directory": "packages/core"
56
43
  },
57
- "sideEffects": false
44
+ "sideEffects": false,
45
+ "scripts": {
46
+ "build": "tsup"
47
+ },
48
+ "tsup": {
49
+ "entry": [
50
+ "src/index.ts"
51
+ ],
52
+ "dts": true,
53
+ "splitting": true,
54
+ "format": [
55
+ "esm",
56
+ "cjs"
57
+ ]
58
+ }
58
59
  }
@@ -1,27 +1,19 @@
1
- import { EditorState, Transaction } from 'prosemirror-state'
1
+ import { EditorState, Transaction } from '@tiptap/pm/state'
2
2
 
3
3
  import { Editor } from './Editor'
4
4
  import { createChainableState } from './helpers/createChainableState'
5
5
  import {
6
- AnyCommands,
7
- CanCommands,
8
- ChainedCommands,
9
- CommandProps,
10
- SingleCommands,
6
+ AnyCommands, CanCommands, ChainedCommands, CommandProps, SingleCommands,
11
7
  } from './types'
12
8
 
13
9
  export class CommandManager {
14
-
15
10
  editor: Editor
16
11
 
17
12
  rawCommands: AnyCommands
18
13
 
19
14
  customState?: EditorState
20
15
 
21
- constructor(props: {
22
- editor: Editor,
23
- state?: EditorState,
24
- }) {
16
+ constructor(props: { editor: Editor; state?: EditorState }) {
25
17
  this.editor = props.editor
26
18
  this.rawCommands = this.editor.extensionManager.commands
27
19
  this.customState = props.state
@@ -41,9 +33,8 @@ export class CommandManager {
41
33
  const { tr } = state
42
34
  const props = this.buildProps(tr)
43
35
 
44
- return Object.fromEntries(Object
45
- .entries(rawCommands)
46
- .map(([name, command]) => {
36
+ return Object.fromEntries(
37
+ Object.entries(rawCommands).map(([name, command]) => {
47
38
  const method = (...args: any[]) => {
48
39
  const callback = command(...args)(props)
49
40
 
@@ -55,7 +46,8 @@ export class CommandManager {
55
46
  }
56
47
 
57
48
  return [name, method]
58
- })) as unknown as SingleCommands
49
+ }),
50
+ ) as unknown as SingleCommands
59
51
  }
60
52
 
61
53
  get chain(): () => ChainedCommands {
@@ -87,18 +79,20 @@ export class CommandManager {
87
79
  }
88
80
 
89
81
  const chain = {
90
- ...Object.fromEntries(Object.entries(rawCommands).map(([name, command]) => {
91
- const chainedCommand = (...args: never[]) => {
92
- const props = this.buildProps(tr, shouldDispatch)
93
- 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)
94
87
 
95
- callbacks.push(callback)
88
+ callbacks.push(callback)
96
89
 
97
- return chain
98
- }
90
+ return chain
91
+ }
99
92
 
100
- return [name, chainedCommand]
101
- })),
93
+ return [name, chainedCommand]
94
+ }),
95
+ ),
102
96
  run,
103
97
  } as unknown as ChainedCommands
104
98
 
@@ -110,11 +104,11 @@ export class CommandManager {
110
104
  const dispatch = false
111
105
  const tr = startTr || state.tr
112
106
  const props = this.buildProps(tr, dispatch)
113
- const formattedCommands = Object.fromEntries(Object
114
- .entries(rawCommands)
115
- .map(([name, command]) => {
107
+ const formattedCommands = Object.fromEntries(
108
+ Object.entries(rawCommands).map(([name, command]) => {
116
109
  return [name, (...args: never[]) => command(...args)({ ...props, dispatch: undefined })]
117
- })) as unknown as SingleCommands
110
+ }),
111
+ ) as unknown as SingleCommands
118
112
 
119
113
  return {
120
114
  ...formattedCommands,
@@ -138,21 +132,18 @@ export class CommandManager {
138
132
  state,
139
133
  transaction: tr,
140
134
  }),
141
- dispatch: shouldDispatch
142
- ? () => undefined
143
- : undefined,
135
+ dispatch: shouldDispatch ? () => undefined : undefined,
144
136
  chain: () => this.createChain(tr),
145
137
  can: () => this.createCan(tr),
146
138
  get commands() {
147
- return Object.fromEntries(Object
148
- .entries(rawCommands)
149
- .map(([name, command]) => {
139
+ return Object.fromEntries(
140
+ Object.entries(rawCommands).map(([name, command]) => {
150
141
  return [name, (...args: never[]) => command(...args)(props)]
151
- })) as unknown as SingleCommands
142
+ }),
143
+ ) as unknown as SingleCommands
152
144
  },
153
145
  }
154
146
 
155
147
  return props
156
148
  }
157
-
158
149
  }
package/src/Editor.ts CHANGED
@@ -1,11 +1,8 @@
1
- import { MarkType, NodeType, Schema } from 'prosemirror-model'
1
+ import { MarkType, NodeType, Schema } from '@tiptap/pm/model'
2
2
  import {
3
- EditorState,
4
- Plugin,
5
- PluginKey,
6
- Transaction,
7
- } from 'prosemirror-state'
8
- import { EditorView } from 'prosemirror-view'
3
+ EditorState, Plugin, PluginKey, Transaction,
4
+ } from '@tiptap/pm/state'
5
+ import { EditorView } from '@tiptap/pm/view'
9
6
 
10
7
  import { CommandManager } from './CommandManager'
11
8
  import { EventEmitter } from './EventEmitter'
@@ -39,7 +36,6 @@ export interface HTMLElement {
39
36
  }
40
37
 
41
38
  export class Editor extends EventEmitter<EditorEvents> {
42
-
43
39
  private commandManager!: CommandManager
44
40
 
45
41
  public extensionManager!: ExtensionManager
@@ -167,9 +163,12 @@ export class Editor extends EventEmitter<EditorEvents> {
167
163
  /**
168
164
  * Update editable state of the editor.
169
165
  */
170
- public setEditable(editable: boolean): void {
166
+ public setEditable(editable: boolean, emitUpdate = true): void {
171
167
  this.setOptions({ editable })
172
- this.emit('update', { editor: this, transaction: this.state.tr })
168
+
169
+ if (emitUpdate) {
170
+ this.emit('update', { editor: this, transaction: this.state.tr })
171
+ }
173
172
  }
174
173
 
175
174
  /**
@@ -179,9 +178,7 @@ export class Editor extends EventEmitter<EditorEvents> {
179
178
  // since plugins are applied after creating the view
180
179
  // `editable` is always `true` for one tick.
181
180
  // that’s why we also have to check for `options.editable`
182
- return this.options.editable
183
- && this.view
184
- && this.view.editable
181
+ return this.options.editable && this.view && this.view.editable
185
182
  }
186
183
 
187
184
  /**
@@ -197,7 +194,10 @@ export class Editor extends EventEmitter<EditorEvents> {
197
194
  * @param plugin A ProseMirror plugin
198
195
  * @param handlePlugins Control how to merge the plugin into the existing plugins.
199
196
  */
200
- public registerPlugin(plugin: Plugin, handlePlugins?: (newPlugin: Plugin, plugins: Plugin[]) => Plugin[]): void {
197
+ public registerPlugin(
198
+ plugin: Plugin,
199
+ handlePlugins?: (newPlugin: Plugin, plugins: Plugin[]) => Plugin[],
200
+ ): void {
201
201
  const plugins = isFunction(handlePlugins)
202
202
  ? handlePlugins(plugin, [...this.state.plugins])
203
203
  : [...this.state.plugins, plugin]
@@ -217,10 +217,8 @@ export class Editor extends EventEmitter<EditorEvents> {
217
217
  return
218
218
  }
219
219
 
220
- const name = typeof nameOrPluginKey === 'string'
221
- ? `${nameOrPluginKey}$`
222
- // @ts-ignore
223
- : nameOrPluginKey.key
220
+ // @ts-ignore
221
+ const name = typeof nameOrPluginKey === 'string' ? `${nameOrPluginKey}$` : nameOrPluginKey.key
224
222
 
225
223
  const state = this.state.reconfigure({
226
224
  // @ts-ignore
@@ -234,9 +232,7 @@ export class Editor extends EventEmitter<EditorEvents> {
234
232
  * Creates an extension manager.
235
233
  */
236
234
  private createExtensionManager(): void {
237
- const coreExtensions = this.options.enableCoreExtensions
238
- ? Object.values(extensions)
239
- : []
235
+ const coreExtensions = this.options.enableCoreExtensions ? Object.values(extensions) : []
240
236
  const allExtensions = [...coreExtensions, ...this.options.extensions].filter(extension => {
241
237
  return ['extension', 'node', 'mark'].includes(extension?.type)
242
238
  })
@@ -394,16 +390,12 @@ export class Editor extends EventEmitter<EditorEvents> {
394
390
  * @param name Name of the node or mark
395
391
  * @param attributes Attributes of the node or mark
396
392
  */
397
- public isActive(name: string, attributes?: {}): boolean;
398
- public isActive(attributes: {}): boolean;
393
+ public isActive(name: string, attributes?: {}): boolean
394
+ public isActive(attributes: {}): boolean
399
395
  public isActive(nameOrAttributes: string, attributesOrUndefined?: {}): boolean {
400
- const name = typeof nameOrAttributes === 'string'
401
- ? nameOrAttributes
402
- : null
396
+ const name = typeof nameOrAttributes === 'string' ? nameOrAttributes : null
403
397
 
404
- const attributes = typeof nameOrAttributes === 'string'
405
- ? attributesOrUndefined
406
- : nameOrAttributes
398
+ const attributes = typeof nameOrAttributes === 'string' ? attributesOrUndefined : nameOrAttributes
407
399
 
408
400
  return isActive(this.state, name, attributes)
409
401
  }
@@ -426,13 +418,10 @@ export class Editor extends EventEmitter<EditorEvents> {
426
418
  * Get the document as text.
427
419
  */
428
420
  public getText(options?: {
429
- blockSeparator?: string,
430
- textSerializers?: Record<string, TextSerializer>,
421
+ blockSeparator?: string
422
+ textSerializers?: Record<string, TextSerializer>
431
423
  }): string {
432
- const {
433
- blockSeparator = '\n\n',
434
- textSerializers = {},
435
- } = options || {}
424
+ const { blockSeparator = '\n\n', textSerializers = {} } = options || {}
436
425
 
437
426
  return getText(this.state.doc, {
438
427
  blockSeparator,
@@ -456,7 +445,9 @@ export class Editor extends EventEmitter<EditorEvents> {
456
445
  * @deprecated
457
446
  */
458
447
  public getCharacterCount(): number {
459
- console.warn('[tiptap warn]: "editor.getCharacterCount()" is deprecated. Please use "editor.storage.characterCount.characters()" instead.')
448
+ console.warn(
449
+ '[tiptap warn]: "editor.getCharacterCount()" is deprecated. Please use "editor.storage.characterCount.characters()" instead.',
450
+ )
460
451
 
461
452
  return this.state.doc.content.size - 2
462
453
  }
@@ -481,5 +472,4 @@ export class Editor extends EventEmitter<EditorEvents> {
481
472
  // @ts-ignore
482
473
  return !this.view?.docView
483
474
  }
484
-
485
475
  }