@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/src/NodeView.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { Node as ProseMirrorNode } from 'prosemirror-model'
2
- import { NodeSelection } from 'prosemirror-state'
3
- import { Decoration, NodeView as ProseMirrorNodeView } from 'prosemirror-view'
1
+ import { Node as ProseMirrorNode } from '@tiptap/pm/model'
2
+ import { NodeSelection } from '@tiptap/pm/state'
3
+ import { Decoration, NodeView as ProseMirrorNodeView } from '@tiptap/pm/view'
4
4
 
5
5
  import { Editor as CoreEditor } from './Editor'
6
6
  import { Node } from './Node'
@@ -12,7 +12,6 @@ export class NodeView<
12
12
  Editor extends CoreEditor = CoreEditor,
13
13
  Options extends NodeViewRendererOptions = NodeViewRendererOptions,
14
14
  > implements ProseMirrorNodeView {
15
-
16
15
  component: Component
17
16
 
18
17
  editor: Editor
@@ -59,7 +58,7 @@ export class NodeView<
59
58
 
60
59
  onDragStart(event: DragEvent) {
61
60
  const { view } = this.editor
62
- const target = (event.target as HTMLElement)
61
+ const target = event.target as HTMLElement
63
62
 
64
63
  // get the drag handle element
65
64
  // `closest` is not available for text nodes so we may have to use its parent
@@ -67,11 +66,7 @@ export class NodeView<
67
66
  ? target.parentElement?.closest('[data-drag-handle]')
68
67
  : target.closest('[data-drag-handle]')
69
68
 
70
- if (
71
- !this.dom
72
- || this.contentDOM?.contains(target)
73
- || !dragHandle
74
- ) {
69
+ if (!this.dom || this.contentDOM?.contains(target) || !dragHandle) {
75
70
  return
76
71
  }
77
72
 
@@ -110,7 +105,7 @@ export class NodeView<
110
105
  return this.options.stopEvent({ event })
111
106
  }
112
107
 
113
- const target = (event.target as HTMLElement)
108
+ const target = event.target as HTMLElement
114
109
  const isInElement = this.dom.contains(target) && !this.contentDOM?.contains(target)
115
110
 
116
111
  // any event from child nodes should be handled by ProseMirror
@@ -119,8 +114,7 @@ export class NodeView<
119
114
  }
120
115
 
121
116
  const isDropEvent = event.type === 'drop'
122
- const isInput = ['INPUT', 'BUTTON', 'SELECT', 'TEXTAREA'].includes(target.tagName)
123
- || target.isContentEditable
117
+ const isInput = ['INPUT', 'BUTTON', 'SELECT', 'TEXTAREA'].includes(target.tagName) || target.isContentEditable
124
118
 
125
119
  // any input event within node views should be ignored by ProseMirror
126
120
  if (isInput && !isDropEvent) {
@@ -152,19 +146,26 @@ export class NodeView<
152
146
  // we have to store that dragging started
153
147
  if (isDraggable && isEditable && !isDragging && isClickEvent) {
154
148
  const dragHandle = target.closest('[data-drag-handle]')
155
- const isValidDragHandle = dragHandle
156
- && (this.dom === dragHandle || (this.dom.contains(dragHandle)))
149
+ const isValidDragHandle = dragHandle && (this.dom === dragHandle || this.dom.contains(dragHandle))
157
150
 
158
151
  if (isValidDragHandle) {
159
152
  this.isDragging = true
160
153
 
161
- document.addEventListener('dragend', () => {
162
- this.isDragging = false
163
- }, { once: true })
164
-
165
- document.addEventListener('mouseup', () => {
166
- this.isDragging = false
167
- }, { once: true })
154
+ document.addEventListener(
155
+ 'dragend',
156
+ () => {
157
+ this.isDragging = false
158
+ },
159
+ { once: true },
160
+ )
161
+
162
+ document.addEventListener(
163
+ 'mouseup',
164
+ () => {
165
+ this.isDragging = false
166
+ },
167
+ { once: true },
168
+ )
168
169
  }
169
170
  }
170
171
 
@@ -183,7 +184,7 @@ export class NodeView<
183
184
  return true
184
185
  }
185
186
 
186
- ignoreMutation(mutation: MutationRecord | { type: 'selection', target: Element }) {
187
+ ignoreMutation(mutation: MutationRecord | { type: 'selection'; target: Element }) {
187
188
  if (!this.dom || !this.contentDOM) {
188
189
  return true
189
190
  }
package/src/PasteRule.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { EditorState, Plugin } from 'prosemirror-state'
1
+ import { EditorState, Plugin } from '@tiptap/pm/state'
2
2
 
3
3
  import { CommandManager } from './CommandManager'
4
4
  import { Editor } from './Editor'
@@ -14,46 +14,47 @@ import { isNumber } from './utilities/isNumber'
14
14
  import { isRegExp } from './utilities/isRegExp'
15
15
 
16
16
  export type PasteRuleMatch = {
17
- index: number,
18
- text: string,
19
- replaceWith?: string,
20
- match?: RegExpMatchArray,
21
- data?: Record<string, any>,
17
+ index: number
18
+ text: string
19
+ replaceWith?: string
20
+ match?: RegExpMatchArray
21
+ data?: Record<string, any>
22
22
  }
23
23
 
24
- export type PasteRuleFinder =
25
- | RegExp
26
- | ((text: string) => PasteRuleMatch[] | null | undefined)
24
+ export type PasteRuleFinder = RegExp | ((text: string) => PasteRuleMatch[] | null | undefined)
27
25
 
28
26
  export class PasteRule {
29
27
  find: PasteRuleFinder
30
28
 
31
29
  handler: (props: {
32
- state: EditorState,
33
- range: Range,
34
- match: ExtendedRegExpMatchArray,
35
- commands: SingleCommands,
36
- chain: () => ChainedCommands,
37
- can: () => CanCommands,
30
+ state: EditorState
31
+ range: Range
32
+ match: ExtendedRegExpMatchArray
33
+ commands: SingleCommands
34
+ chain: () => ChainedCommands
35
+ can: () => CanCommands
38
36
  }) => void | null
39
37
 
40
38
  constructor(config: {
41
- find: PasteRuleFinder,
39
+ find: PasteRuleFinder
42
40
  handler: (props: {
43
- state: EditorState,
44
- range: Range,
45
- match: ExtendedRegExpMatchArray,
46
- commands: SingleCommands,
47
- chain: () => ChainedCommands,
48
- can: () => CanCommands,
49
- }) => void | null,
41
+ state: EditorState
42
+ range: Range
43
+ match: ExtendedRegExpMatchArray
44
+ commands: SingleCommands
45
+ chain: () => ChainedCommands
46
+ can: () => CanCommands
47
+ }) => void | null
50
48
  }) {
51
49
  this.find = config.find
52
50
  this.handler = config.handler
53
51
  }
54
52
  }
55
53
 
56
- const pasteRuleMatcherHandler = (text: string, find: PasteRuleFinder): ExtendedRegExpMatchArray[] => {
54
+ const pasteRuleMatcherHandler = (
55
+ text: string,
56
+ find: PasteRuleFinder,
57
+ ): ExtendedRegExpMatchArray[] => {
57
58
  if (isRegExp(find)) {
58
59
  return [...text.matchAll(find)]
59
60
  }
@@ -65,16 +66,17 @@ const pasteRuleMatcherHandler = (text: string, find: PasteRuleFinder): ExtendedR
65
66
  }
66
67
 
67
68
  return matches.map(pasteRuleMatch => {
68
- const result: ExtendedRegExpMatchArray = []
69
+ const result: ExtendedRegExpMatchArray = [pasteRuleMatch.text]
69
70
 
70
- result.push(pasteRuleMatch.text)
71
71
  result.index = pasteRuleMatch.index
72
72
  result.input = text
73
73
  result.data = pasteRuleMatch.data
74
74
 
75
75
  if (pasteRuleMatch.replaceWith) {
76
76
  if (!pasteRuleMatch.text.includes(pasteRuleMatch.replaceWith)) {
77
- console.warn('[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".')
77
+ console.warn(
78
+ '[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".',
79
+ )
78
80
  }
79
81
 
80
82
  result.push(pasteRuleMatch.replaceWith)
@@ -85,18 +87,14 @@ const pasteRuleMatcherHandler = (text: string, find: PasteRuleFinder): ExtendedR
85
87
  }
86
88
 
87
89
  function run(config: {
88
- editor: Editor,
89
- state: EditorState,
90
- from: number,
91
- to: number,
92
- rule: PasteRule,
90
+ editor: Editor
91
+ state: EditorState
92
+ from: number
93
+ to: number
94
+ rule: PasteRule
93
95
  }): boolean {
94
96
  const {
95
- editor,
96
- state,
97
- from,
98
- to,
99
- rule,
97
+ editor, state, from, to, rule,
100
98
  } = config
101
99
 
102
100
  const { commands, chain, can } = new CommandManager({
@@ -113,12 +111,7 @@ function run(config: {
113
111
 
114
112
  const resolvedFrom = Math.max(from, pos)
115
113
  const resolvedTo = Math.min(to, pos + node.content.size)
116
- const textToMatch = node.textBetween(
117
- resolvedFrom - pos,
118
- resolvedTo - pos,
119
- undefined,
120
- '\ufffc',
121
- )
114
+ const textToMatch = node.textBetween(resolvedFrom - pos, resolvedTo - pos, undefined, '\ufffc')
122
115
 
123
116
  const matches = pasteRuleMatcherHandler(textToMatch, rule.find)
124
117
 
@@ -157,7 +150,7 @@ function run(config: {
157
150
  * text that matches any of the given rules to trigger the rule’s
158
151
  * action.
159
152
  */
160
- export function pasteRulesPlugin(props: { editor: Editor, rules: PasteRule[] }): Plugin[] {
153
+ export function pasteRulesPlugin(props: { editor: Editor; rules: PasteRule[] }): Plugin[] {
161
154
  const { editor, rules } = props
162
155
  let dragSourceElement: Element | null = null
163
156
  let isPastedFromProseMirror = false
package/src/Tracker.ts CHANGED
@@ -1,12 +1,11 @@
1
- import { Transaction } from 'prosemirror-state'
1
+ import { Transaction } from '@tiptap/pm/state'
2
2
 
3
3
  export interface TrackerResult {
4
- position: number,
5
- deleted: boolean,
4
+ position: number
5
+ deleted: boolean
6
6
  }
7
7
 
8
8
  export class Tracker {
9
-
10
9
  transaction: Transaction
11
10
 
12
11
  currentStep: number
@@ -22,9 +21,7 @@ export class Tracker {
22
21
  const mappedPosition = this.transaction.steps
23
22
  .slice(this.currentStep)
24
23
  .reduce((newPosition, step) => {
25
- const mapResult = step
26
- .getMap()
27
- .mapResult(newPosition)
24
+ const mapResult = step.getMap().mapResult(newPosition)
28
25
 
29
26
  if (mapResult.deleted) {
30
27
  deleted = true
@@ -38,5 +35,4 @@ export class Tracker {
38
35
  deleted,
39
36
  }
40
37
  }
41
-
42
38
  }
@@ -1,4 +1,4 @@
1
- import { liftTarget } from 'prosemirror-transform'
1
+ import { liftTarget } from '@tiptap/pm/transform'
2
2
 
3
3
  import { RawCommands } from '../types'
4
4
 
@@ -1,4 +1,4 @@
1
- import { createParagraphNear as originalCreateParagraphNear } from 'prosemirror-commands'
1
+ import { createParagraphNear as originalCreateParagraphNear } from '@tiptap/pm/commands'
2
2
 
3
3
  import { RawCommands } from '../types'
4
4
 
@@ -8,7 +8,7 @@ declare module '@tiptap/core' {
8
8
  /**
9
9
  * Create a paragraph nearby.
10
10
  */
11
- createParagraphNear: () => ReturnType,
11
+ createParagraphNear: () => ReturnType
12
12
  }
13
13
  }
14
14
  }
@@ -1,4 +1,4 @@
1
- import { NodeType } from 'prosemirror-model'
1
+ import { NodeType } from '@tiptap/pm/model'
2
2
 
3
3
  import { getNodeType } from '../helpers/getNodeType'
4
4
  import { RawCommands } from '../types'
@@ -1,4 +1,4 @@
1
- import { deleteSelection as originalDeleteSelection } from 'prosemirror-commands'
1
+ import { deleteSelection as originalDeleteSelection } from '@tiptap/pm/commands'
2
2
 
3
3
  import { RawCommands } from '../types'
4
4
 
@@ -8,7 +8,7 @@ declare module '@tiptap/core' {
8
8
  /**
9
9
  * Delete the selection, if there is one.
10
10
  */
11
- deleteSelection: () => ReturnType,
11
+ deleteSelection: () => ReturnType
12
12
  }
13
13
  }
14
14
  }
@@ -1,4 +1,4 @@
1
- import { exitCode as originalExitCode } from 'prosemirror-commands'
1
+ import { exitCode as originalExitCode } from '@tiptap/pm/commands'
2
2
 
3
3
  import { RawCommands } from '../types'
4
4
 
@@ -8,7 +8,7 @@ declare module '@tiptap/core' {
8
8
  /**
9
9
  * Exit from a code block.
10
10
  */
11
- exitCode: () => ReturnType,
11
+ exitCode: () => ReturnType
12
12
  }
13
13
  }
14
14
  }
@@ -1,5 +1,5 @@
1
- import { MarkType } from 'prosemirror-model'
2
- import { TextSelection } from 'prosemirror-state'
1
+ import { MarkType } from '@tiptap/pm/model'
2
+ import { TextSelection } from '@tiptap/pm/state'
3
3
 
4
4
  import { getMarkRange } from '../helpers/getMarkRange'
5
5
  import { getMarkType } from '../helpers/getMarkType'
@@ -11,7 +11,10 @@ declare module '@tiptap/core' {
11
11
  /**
12
12
  * Extends the text selection to the current mark.
13
13
  */
14
- extendMarkRange: (typeOrName: string | MarkType, attributes?: Record<string, any>) => ReturnType,
14
+ extendMarkRange: (
15
+ typeOrName: string | MarkType,
16
+ attributes?: Record<string, any>,
17
+ ) => ReturnType
15
18
  }
16
19
  }
17
20
  }
@@ -1,4 +1,4 @@
1
- import { ParseOptions } from 'prosemirror-model'
1
+ import { ParseOptions } from '@tiptap/pm/model'
2
2
 
3
3
  import { Content, RawCommands } from '../types'
4
4
 
@@ -11,14 +11,18 @@ declare module '@tiptap/core' {
11
11
  insertContent: (
12
12
  value: Content,
13
13
  options?: {
14
- parseOptions?: ParseOptions,
15
- updateSelection?: boolean,
14
+ parseOptions?: ParseOptions
15
+ updateSelection?: boolean
16
16
  },
17
- ) => ReturnType,
17
+ ) => ReturnType
18
18
  }
19
19
  }
20
20
  }
21
21
 
22
22
  export const insertContent: RawCommands['insertContent'] = (value, options) => ({ tr, commands }) => {
23
- return commands.insertContentAt({ from: tr.selection.from, to: tr.selection.to }, value, options)
23
+ return commands.insertContentAt(
24
+ { from: tr.selection.from, to: tr.selection.to },
25
+ value,
26
+ options,
27
+ )
24
28
  }
@@ -1,12 +1,8 @@
1
- import { Fragment, Node as ProseMirrorNode, ParseOptions } from 'prosemirror-model'
1
+ import { Fragment, Node as ProseMirrorNode, ParseOptions } from '@tiptap/pm/model'
2
2
 
3
3
  import { createNodeFromContent } from '../helpers/createNodeFromContent'
4
4
  import { selectionToInsertionEnd } from '../helpers/selectionToInsertionEnd'
5
- import {
6
- Content,
7
- Range,
8
- RawCommands,
9
- } from '../types'
5
+ import { Content, Range, RawCommands } from '../types'
10
6
 
11
7
  declare module '@tiptap/core' {
12
8
  interface Commands<ReturnType> {
@@ -18,10 +14,10 @@ declare module '@tiptap/core' {
18
14
  position: number | Range,
19
15
  value: Content,
20
16
  options?: {
21
- parseOptions?: ParseOptions,
22
- updateSelection?: boolean,
17
+ parseOptions?: ParseOptions
18
+ updateSelection?: boolean
23
19
  },
24
- ) => ReturnType,
20
+ ) => ReturnType
25
21
  }
26
22
  }
27
23
  }
@@ -50,27 +46,19 @@ export const insertContentAt: RawCommands['insertContentAt'] = (position, value,
50
46
  return true
51
47
  }
52
48
 
53
- let { from, to } = typeof position === 'number'
54
- ? { from: position, to: position }
55
- : position
49
+ let { from, to } = typeof position === 'number' ? { from: position, to: position } : position
56
50
 
57
51
  let isOnlyTextContent = true
58
52
  let isOnlyBlockContent = true
59
- const nodes = isFragment(content)
60
- ? content
61
- : [content]
53
+ const nodes = isFragment(content) ? content : [content]
62
54
 
63
55
  nodes.forEach(node => {
64
56
  // check if added node is valid
65
57
  node.check()
66
58
 
67
- isOnlyTextContent = isOnlyTextContent
68
- ? node.isText && node.marks.length === 0
69
- : false
59
+ isOnlyTextContent = isOnlyTextContent ? node.isText && node.marks.length === 0 : false
70
60
 
71
- isOnlyBlockContent = isOnlyBlockContent
72
- ? node.isBlock
73
- : false
61
+ isOnlyBlockContent = isOnlyBlockContent ? node.isBlock : false
74
62
  })
75
63
 
76
64
  // check if we can replace the wrapping node by
@@ -80,9 +68,7 @@ export const insertContentAt: RawCommands['insertContentAt'] = (position, value,
80
68
  // instead of inserting the image below the paragraph
81
69
  if (from === to && isOnlyBlockContent) {
82
70
  const { parent } = tr.doc.resolve(from)
83
- const isEmptyTextBlock = parent.isTextblock
84
- && !parent.type.spec.code
85
- && !parent.childCount
71
+ const isEmptyTextBlock = parent.isTextblock && !parent.type.spec.code && !parent.childCount
86
72
 
87
73
  if (isEmptyTextBlock) {
88
74
  from -= 1
@@ -1,6 +1,9 @@
1
1
  import {
2
- joinBackward as originalJoinBackward, joinDown as originalJoinDown, joinForward as originalJoinForward, joinUp as originalJoinUp,
3
- } from 'prosemirror-commands'
2
+ joinBackward as originalJoinBackward,
3
+ joinDown as originalJoinDown,
4
+ joinForward as originalJoinForward,
5
+ joinUp as originalJoinUp,
6
+ } from '@tiptap/pm/commands'
4
7
 
5
8
  import { RawCommands } from '../types'
6
9
 
@@ -10,25 +13,25 @@ declare module '@tiptap/core' {
10
13
  /**
11
14
  * Join two nodes Up.
12
15
  */
13
- joinUp: () => ReturnType,
16
+ joinUp: () => ReturnType
14
17
  }
15
18
  joinDown: {
16
19
  /**
17
20
  * Join two nodes Down.
18
21
  */
19
- joinDown: () => ReturnType,
22
+ joinDown: () => ReturnType
20
23
  }
21
24
  joinBackward: {
22
25
  /**
23
26
  * Join two nodes Backwards.
24
27
  */
25
- joinBackward: () => ReturnType,
28
+ joinBackward: () => ReturnType
26
29
  }
27
30
  joinForward: {
28
31
  /**
29
32
  * Join two nodes Forwards.
30
33
  */
31
- joinForward: () => ReturnType,
34
+ joinForward: () => ReturnType
32
35
  }
33
36
  }
34
37
  }
@@ -1,5 +1,5 @@
1
- import { lift as originalLift } from 'prosemirror-commands'
2
- import { NodeType } from 'prosemirror-model'
1
+ import { lift as originalLift } from '@tiptap/pm/commands'
2
+ import { NodeType } from '@tiptap/pm/model'
3
3
 
4
4
  import { getNodeType } from '../helpers/getNodeType'
5
5
  import { isNodeActive } from '../helpers/isNodeActive'
@@ -11,7 +11,7 @@ declare module '@tiptap/core' {
11
11
  /**
12
12
  * Removes an existing wrap.
13
13
  */
14
- lift: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType,
14
+ lift: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType
15
15
  }
16
16
  }
17
17
  }
@@ -1,4 +1,4 @@
1
- import { liftEmptyBlock as originalLiftEmptyBlock } from 'prosemirror-commands'
1
+ import { liftEmptyBlock as originalLiftEmptyBlock } from '@tiptap/pm/commands'
2
2
 
3
3
  import { RawCommands } from '../types'
4
4
 
@@ -1,5 +1,5 @@
1
- import { NodeType } from 'prosemirror-model'
2
- import { liftListItem as originalLiftListItem } from 'prosemirror-schema-list'
1
+ import { NodeType } from '@tiptap/pm/model'
2
+ import { liftListItem as originalLiftListItem } from '@tiptap/pm/schema-list'
3
3
 
4
4
  import { getNodeType } from '../helpers/getNodeType'
5
5
  import { RawCommands } from '../types'
@@ -10,7 +10,7 @@ declare module '@tiptap/core' {
10
10
  /**
11
11
  * Lift the list item into a wrapping list.
12
12
  */
13
- liftListItem: (typeOrName: string | NodeType) => ReturnType,
13
+ liftListItem: (typeOrName: string | NodeType) => ReturnType
14
14
  }
15
15
  }
16
16
  }
@@ -1,4 +1,4 @@
1
- import { newlineInCode as originalNewlineInCode } from 'prosemirror-commands'
1
+ import { newlineInCode as originalNewlineInCode } from '@tiptap/pm/commands'
2
2
 
3
3
  import { RawCommands } from '../types'
4
4
 
@@ -8,7 +8,7 @@ declare module '@tiptap/core' {
8
8
  /**
9
9
  * Add a newline character in code.
10
10
  */
11
- newlineInCode: () => ReturnType,
11
+ newlineInCode: () => ReturnType
12
12
  }
13
13
  }
14
14
  }
@@ -1,4 +1,4 @@
1
- import { MarkType, NodeType } from 'prosemirror-model'
1
+ import { MarkType, NodeType } from '@tiptap/pm/model'
2
2
 
3
3
  import { getMarkType } from '../helpers/getMarkType'
4
4
  import { getNodeType } from '../helpers/getNodeType'
@@ -12,7 +12,10 @@ declare module '@tiptap/core' {
12
12
  /**
13
13
  * Resets some node attributes to the default value.
14
14
  */
15
- resetAttributes: (typeOrName: string | NodeType | MarkType, attributes: string | string[]) => ReturnType,
15
+ resetAttributes: (
16
+ typeOrName: string | NodeType | MarkType,
17
+ attributes: string | string[],
18
+ ) => ReturnType
16
19
  }
17
20
  }
18
21
  }
@@ -22,9 +25,7 @@ export const resetAttributes: RawCommands['resetAttributes'] = (typeOrName, attr
22
25
  let markType: MarkType | null = null
23
26
 
24
27
  const schemaType = getSchemaTypeNameByName(
25
- typeof typeOrName === 'string'
26
- ? typeOrName
27
- : typeOrName.name,
28
+ typeof typeOrName === 'string' ? typeOrName : typeOrName.name,
28
29
  state.schema,
29
30
  )
30
31
 
@@ -50,7 +51,11 @@ export const resetAttributes: RawCommands['resetAttributes'] = (typeOrName, attr
50
51
  if (markType && node.marks.length) {
51
52
  node.marks.forEach(mark => {
52
53
  if (markType === mark.type) {
53
- tr.addMark(pos, pos + node.nodeSize, markType.create(deleteProps(mark.attrs, attributes)))
54
+ tr.addMark(
55
+ pos,
56
+ pos + node.nodeSize,
57
+ markType.create(deleteProps(mark.attrs, attributes)),
58
+ )
54
59
  }
55
60
  })
56
61
  }
@@ -1,4 +1,4 @@
1
- import { selectNodeBackward as originalSelectNodeBackward } from 'prosemirror-commands'
1
+ import { selectNodeBackward as originalSelectNodeBackward } from '@tiptap/pm/commands'
2
2
 
3
3
  import { RawCommands } from '../types'
4
4
 
@@ -8,7 +8,7 @@ declare module '@tiptap/core' {
8
8
  /**
9
9
  * Select a node backward.
10
10
  */
11
- selectNodeBackward: () => ReturnType,
11
+ selectNodeBackward: () => ReturnType
12
12
  }
13
13
  }
14
14
  }
@@ -1,4 +1,4 @@
1
- import { selectNodeForward as originalSelectNodeForward } from 'prosemirror-commands'
1
+ import { selectNodeForward as originalSelectNodeForward } from '@tiptap/pm/commands'
2
2
 
3
3
  import { RawCommands } from '../types'
4
4
 
@@ -8,7 +8,7 @@ declare module '@tiptap/core' {
8
8
  /**
9
9
  * Select a node forward.
10
10
  */
11
- selectNodeForward: () => ReturnType,
11
+ selectNodeForward: () => ReturnType
12
12
  }
13
13
  }
14
14
  }
@@ -1,4 +1,4 @@
1
- import { selectParentNode as originalSelectParentNode } from 'prosemirror-commands'
1
+ import { selectParentNode as originalSelectParentNode } from '@tiptap/pm/commands'
2
2
 
3
3
  import { RawCommands } from '../types'
4
4
 
@@ -8,7 +8,7 @@ declare module '@tiptap/core' {
8
8
  /**
9
9
  * Select the parent node.
10
10
  */
11
- selectParentNode: () => ReturnType,
11
+ selectParentNode: () => ReturnType
12
12
  }
13
13
  }
14
14
  }
@@ -1,6 +1,6 @@
1
1
  // @ts-ignore
2
2
  // TODO: add types to @types/prosemirror-commands
3
- import { selectTextblockEnd as originalSelectTextblockEnd } from 'prosemirror-commands'
3
+ import { selectTextblockEnd as originalSelectTextblockEnd } from '@tiptap/pm/commands'
4
4
 
5
5
  import { RawCommands } from '../types'
6
6
 
@@ -10,7 +10,7 @@ declare module '@tiptap/core' {
10
10
  /**
11
11
  * Moves the cursor to the end of current text block.
12
12
  */
13
- selectTextblockEnd: () => ReturnType,
13
+ selectTextblockEnd: () => ReturnType
14
14
  }
15
15
  }
16
16
  }