@tiptap/core 3.0.0-next.0 → 3.0.0-next.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 (184) hide show
  1. package/dist/index.cjs +4675 -4581
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +3452 -0
  4. package/dist/index.d.ts +3452 -0
  5. package/dist/index.js +4574 -4483
  6. package/dist/index.js.map +1 -1
  7. package/package.json +6 -8
  8. package/src/Editor.ts +6 -0
  9. package/src/Extension.ts +4 -3
  10. package/src/ExtensionManager.ts +2 -1
  11. package/src/Mark.ts +4 -3
  12. package/src/Node.ts +4 -3
  13. package/src/commands/setMeta.ts +3 -1
  14. package/src/commands/splitListItem.ts +27 -17
  15. package/src/helpers/getAttributesFromExtensions.ts +1 -1
  16. package/src/helpers/getMarksBetween.ts +1 -1
  17. package/src/helpers/getSchemaByResolvedExtensions.ts +1 -1
  18. package/src/helpers/isList.ts +1 -1
  19. package/src/helpers/isNodeEmpty.ts +33 -12
  20. package/src/pasteRules/nodePasteRule.ts +14 -5
  21. package/src/style.ts +2 -2
  22. package/dist/index.umd.js +0 -5130
  23. package/dist/index.umd.js.map +0 -1
  24. package/dist/packages/core/src/CommandManager.d.ts +0 -20
  25. package/dist/packages/core/src/Editor.d.ts +0 -159
  26. package/dist/packages/core/src/EventEmitter.d.ts +0 -11
  27. package/dist/packages/core/src/Extension.d.ts +0 -343
  28. package/dist/packages/core/src/ExtensionManager.d.ts +0 -55
  29. package/dist/packages/core/src/InputRule.d.ts +0 -42
  30. package/dist/packages/core/src/Mark.d.ts +0 -451
  31. package/dist/packages/core/src/Node.d.ts +0 -611
  32. package/dist/packages/core/src/NodePos.d.ts +0 -44
  33. package/dist/packages/core/src/NodeView.d.ts +0 -31
  34. package/dist/packages/core/src/PasteRule.d.ts +0 -50
  35. package/dist/packages/core/src/Tracker.d.ts +0 -11
  36. package/dist/packages/core/src/commands/blur.d.ts +0 -13
  37. package/dist/packages/core/src/commands/clearContent.d.ts +0 -14
  38. package/dist/packages/core/src/commands/clearNodes.d.ts +0 -13
  39. package/dist/packages/core/src/commands/command.d.ts +0 -18
  40. package/dist/packages/core/src/commands/createParagraphNear.d.ts +0 -13
  41. package/dist/packages/core/src/commands/cut.d.ts +0 -20
  42. package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +0 -13
  43. package/dist/packages/core/src/commands/deleteNode.d.ts +0 -15
  44. package/dist/packages/core/src/commands/deleteRange.d.ts +0 -14
  45. package/dist/packages/core/src/commands/deleteSelection.d.ts +0 -13
  46. package/dist/packages/core/src/commands/enter.d.ts +0 -13
  47. package/dist/packages/core/src/commands/exitCode.d.ts +0 -13
  48. package/dist/packages/core/src/commands/extendMarkRange.d.ts +0 -25
  49. package/dist/packages/core/src/commands/first.d.ts +0 -14
  50. package/dist/packages/core/src/commands/focus.d.ts +0 -27
  51. package/dist/packages/core/src/commands/forEach.d.ts +0 -14
  52. package/dist/packages/core/src/commands/index.d.ts +0 -55
  53. package/dist/packages/core/src/commands/insertContent.d.ts +0 -34
  54. package/dist/packages/core/src/commands/insertContentAt.d.ts +0 -47
  55. package/dist/packages/core/src/commands/join.d.ts +0 -41
  56. package/dist/packages/core/src/commands/joinItemBackward.d.ts +0 -13
  57. package/dist/packages/core/src/commands/joinItemForward.d.ts +0 -13
  58. package/dist/packages/core/src/commands/joinTextblockBackward.d.ts +0 -12
  59. package/dist/packages/core/src/commands/joinTextblockForward.d.ts +0 -12
  60. package/dist/packages/core/src/commands/keyboardShortcut.d.ts +0 -14
  61. package/dist/packages/core/src/commands/lift.d.ts +0 -17
  62. package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +0 -13
  63. package/dist/packages/core/src/commands/liftListItem.d.ts +0 -15
  64. package/dist/packages/core/src/commands/newlineInCode.d.ts +0 -13
  65. package/dist/packages/core/src/commands/resetAttributes.d.ts +0 -16
  66. package/dist/packages/core/src/commands/scrollIntoView.d.ts +0 -13
  67. package/dist/packages/core/src/commands/selectAll.d.ts +0 -13
  68. package/dist/packages/core/src/commands/selectNodeBackward.d.ts +0 -13
  69. package/dist/packages/core/src/commands/selectNodeForward.d.ts +0 -13
  70. package/dist/packages/core/src/commands/selectParentNode.d.ts +0 -13
  71. package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +0 -13
  72. package/dist/packages/core/src/commands/selectTextblockStart.d.ts +0 -13
  73. package/dist/packages/core/src/commands/setContent.d.ts +0 -40
  74. package/dist/packages/core/src/commands/setMark.d.ts +0 -15
  75. package/dist/packages/core/src/commands/setMeta.d.ts +0 -15
  76. package/dist/packages/core/src/commands/setNode.d.ts +0 -16
  77. package/dist/packages/core/src/commands/setNodeSelection.d.ts +0 -14
  78. package/dist/packages/core/src/commands/setTextSelection.d.ts +0 -14
  79. package/dist/packages/core/src/commands/sinkListItem.d.ts +0 -15
  80. package/dist/packages/core/src/commands/splitBlock.d.ts +0 -17
  81. package/dist/packages/core/src/commands/splitListItem.d.ts +0 -15
  82. package/dist/packages/core/src/commands/toggleList.d.ts +0 -18
  83. package/dist/packages/core/src/commands/toggleMark.d.ts +0 -30
  84. package/dist/packages/core/src/commands/toggleNode.d.ts +0 -17
  85. package/dist/packages/core/src/commands/toggleWrap.d.ts +0 -16
  86. package/dist/packages/core/src/commands/undoInputRule.d.ts +0 -13
  87. package/dist/packages/core/src/commands/unsetAllMarks.d.ts +0 -13
  88. package/dist/packages/core/src/commands/unsetMark.d.ts +0 -25
  89. package/dist/packages/core/src/commands/updateAttributes.d.ts +0 -24
  90. package/dist/packages/core/src/commands/wrapIn.d.ts +0 -16
  91. package/dist/packages/core/src/commands/wrapInList.d.ts +0 -16
  92. package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +0 -5
  93. package/dist/packages/core/src/extensions/commands.d.ts +0 -3
  94. package/dist/packages/core/src/extensions/editable.d.ts +0 -2
  95. package/dist/packages/core/src/extensions/focusEvents.d.ts +0 -2
  96. package/dist/packages/core/src/extensions/index.d.ts +0 -6
  97. package/dist/packages/core/src/extensions/keymap.d.ts +0 -2
  98. package/dist/packages/core/src/extensions/tabindex.d.ts +0 -2
  99. package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +0 -10
  100. package/dist/packages/core/src/helpers/createChainableState.d.ts +0 -10
  101. package/dist/packages/core/src/helpers/createDocument.d.ts +0 -12
  102. package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +0 -15
  103. package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +0 -7
  104. package/dist/packages/core/src/helpers/findChildren.d.ts +0 -9
  105. package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +0 -10
  106. package/dist/packages/core/src/helpers/findParentNode.d.ts +0 -16
  107. package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +0 -17
  108. package/dist/packages/core/src/helpers/generateHTML.d.ts +0 -8
  109. package/dist/packages/core/src/helpers/generateJSON.d.ts +0 -8
  110. package/dist/packages/core/src/helpers/generateText.d.ts +0 -12
  111. package/dist/packages/core/src/helpers/getAttributes.d.ts +0 -9
  112. package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +0 -6
  113. package/dist/packages/core/src/helpers/getChangedRanges.d.ts +0 -11
  114. package/dist/packages/core/src/helpers/getDebugJSON.d.ts +0 -8
  115. package/dist/packages/core/src/helpers/getExtensionField.d.ts +0 -9
  116. package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +0 -2
  117. package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +0 -3
  118. package/dist/packages/core/src/helpers/getMarkRange.d.ts +0 -3
  119. package/dist/packages/core/src/helpers/getMarkType.d.ts +0 -2
  120. package/dist/packages/core/src/helpers/getMarksBetween.d.ts +0 -3
  121. package/dist/packages/core/src/helpers/getNodeAtPosition.d.ts +0 -11
  122. package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +0 -3
  123. package/dist/packages/core/src/helpers/getNodeType.d.ts +0 -2
  124. package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +0 -3
  125. package/dist/packages/core/src/helpers/getSchema.d.ts +0 -4
  126. package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +0 -10
  127. package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +0 -8
  128. package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +0 -8
  129. package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +0 -9
  130. package/dist/packages/core/src/helpers/getText.d.ts +0 -15
  131. package/dist/packages/core/src/helpers/getTextBetween.d.ts +0 -14
  132. package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +0 -8
  133. package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +0 -8
  134. package/dist/packages/core/src/helpers/index.d.ts +0 -50
  135. package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +0 -9
  136. package/dist/packages/core/src/helpers/isActive.d.ts +0 -2
  137. package/dist/packages/core/src/helpers/isAtEndOfNode.d.ts +0 -2
  138. package/dist/packages/core/src/helpers/isAtStartOfNode.d.ts +0 -2
  139. package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +0 -2
  140. package/dist/packages/core/src/helpers/isList.d.ts +0 -2
  141. package/dist/packages/core/src/helpers/isMarkActive.d.ts +0 -3
  142. package/dist/packages/core/src/helpers/isNodeActive.d.ts +0 -3
  143. package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +0 -8
  144. package/dist/packages/core/src/helpers/isNodeSelection.d.ts +0 -2
  145. package/dist/packages/core/src/helpers/isTextSelection.d.ts +0 -2
  146. package/dist/packages/core/src/helpers/posToDOMRect.d.ts +0 -2
  147. package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +0 -4
  148. package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +0 -2
  149. package/dist/packages/core/src/helpers/splitExtensions.d.ts +0 -9
  150. package/dist/packages/core/src/index.d.ts +0 -24
  151. package/dist/packages/core/src/inputRules/index.d.ts +0 -5
  152. package/dist/packages/core/src/inputRules/markInputRule.d.ts +0 -13
  153. package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -23
  154. package/dist/packages/core/src/inputRules/textInputRule.d.ts +0 -10
  155. package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +0 -15
  156. package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +0 -28
  157. package/dist/packages/core/src/pasteRules/index.d.ts +0 -3
  158. package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +0 -13
  159. package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +0 -13
  160. package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +0 -10
  161. package/dist/packages/core/src/style.d.ts +0 -1
  162. package/dist/packages/core/src/types.d.ts +0 -253
  163. package/dist/packages/core/src/utilities/callOrReturn.d.ts +0 -9
  164. package/dist/packages/core/src/utilities/createStyleTag.d.ts +0 -1
  165. package/dist/packages/core/src/utilities/deleteProps.d.ts +0 -6
  166. package/dist/packages/core/src/utilities/elementFromString.d.ts +0 -1
  167. package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +0 -1
  168. package/dist/packages/core/src/utilities/findDuplicates.d.ts +0 -1
  169. package/dist/packages/core/src/utilities/fromString.d.ts +0 -1
  170. package/dist/packages/core/src/utilities/index.d.ts +0 -20
  171. package/dist/packages/core/src/utilities/isAndroid.d.ts +0 -1
  172. package/dist/packages/core/src/utilities/isEmptyObject.d.ts +0 -1
  173. package/dist/packages/core/src/utilities/isFunction.d.ts +0 -1
  174. package/dist/packages/core/src/utilities/isMacOS.d.ts +0 -1
  175. package/dist/packages/core/src/utilities/isNumber.d.ts +0 -1
  176. package/dist/packages/core/src/utilities/isPlainObject.d.ts +0 -1
  177. package/dist/packages/core/src/utilities/isRegExp.d.ts +0 -1
  178. package/dist/packages/core/src/utilities/isString.d.ts +0 -1
  179. package/dist/packages/core/src/utilities/isiOS.d.ts +0 -1
  180. package/dist/packages/core/src/utilities/mergeAttributes.d.ts +0 -1
  181. package/dist/packages/core/src/utilities/mergeDeep.d.ts +0 -1
  182. package/dist/packages/core/src/utilities/minMax.d.ts +0 -1
  183. package/dist/packages/core/src/utilities/objectIncludes.d.ts +0 -8
  184. package/dist/packages/core/src/utilities/removeDuplicates.d.ts +0 -8
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tiptap/core",
3
3
  "description": "headless rich text editor",
4
- "version": "3.0.0-next.0",
4
+ "version": "3.0.0-next.1",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -18,24 +18,23 @@
18
18
  "type": "module",
19
19
  "exports": {
20
20
  ".": {
21
- "types": "./dist/packages/core/src/index.d.ts",
21
+ "types": "./dist/index.d.ts",
22
22
  "import": "./dist/index.js",
23
23
  "require": "./dist/index.cjs"
24
24
  }
25
25
  },
26
26
  "main": "dist/index.cjs",
27
27
  "module": "dist/index.js",
28
- "umd": "dist/index.umd.js",
29
- "types": "dist/packages/core/src/index.d.ts",
28
+ "types": "dist/index.d.ts",
30
29
  "files": [
31
30
  "src",
32
31
  "dist"
33
32
  ],
34
33
  "devDependencies": {
35
- "@tiptap/pm": "^3.0.0-next.0"
34
+ "@tiptap/pm": "^3.0.0-next.1"
36
35
  },
37
36
  "peerDependencies": {
38
- "@tiptap/pm": "^3.0.0-next.0"
37
+ "@tiptap/pm": "^3.0.0-next.1"
39
38
  },
40
39
  "repository": {
41
40
  "type": "git",
@@ -44,7 +43,6 @@
44
43
  },
45
44
  "sideEffects": false,
46
45
  "scripts": {
47
- "clean": "rm -rf dist",
48
- "build": "npm run clean && rollup -c"
46
+ "build": "tsup"
49
47
  }
50
48
  }
package/src/Editor.ts CHANGED
@@ -57,6 +57,11 @@ export class Editor extends EventEmitter<EditorEvents> {
57
57
 
58
58
  public isFocused = false
59
59
 
60
+ /**
61
+ * The editor is considered initialized after the `create` event has been emitted.
62
+ */
63
+ public isInitialized = false
64
+
60
65
  public extensionStorage: Record<string, any> = {}
61
66
 
62
67
  public options: EditorOptions = {
@@ -111,6 +116,7 @@ export class Editor extends EventEmitter<EditorEvents> {
111
116
 
112
117
  this.commands.focus(this.options.autofocus)
113
118
  this.emit('create', { editor: this })
119
+ this.isInitialized = true
114
120
  }, 0)
115
121
  }
116
122
 
package/src/Extension.ts CHANGED
@@ -32,10 +32,10 @@ declare module '@tiptap/core' {
32
32
  name: string
33
33
 
34
34
  /**
35
- * The priority of your extension. The higher, the later it will be called
35
+ * The priority of your extension. The higher, the earlier it will be called
36
36
  * and will take precedence over other extensions with a lower priority.
37
- * @default 1000
38
- * @example 1001
37
+ * @default 100
38
+ * @example 101
39
39
  */
40
40
  priority?: number
41
41
 
@@ -339,6 +339,7 @@ declare module '@tiptap/core' {
339
339
  parent: ParentConfig<ExtensionConfig<Options, Storage>>['onTransaction']
340
340
  },
341
341
  props: {
342
+ editor: Editor
342
343
  transaction: Transaction
343
344
  },
344
345
  ) => void)
@@ -12,8 +12,9 @@ import { getSchemaByResolvedExtensions } from './helpers/getSchemaByResolvedExte
12
12
  import { getSchemaTypeByName } from './helpers/getSchemaTypeByName.js'
13
13
  import { isExtensionRulesEnabled } from './helpers/isExtensionRulesEnabled.js'
14
14
  import { splitExtensions } from './helpers/splitExtensions.js'
15
- import { Mark, NodeConfig } from './index.js'
15
+ import type { NodeConfig } from './index.js'
16
16
  import { InputRule, inputRulesPlugin } from './InputRule.js'
17
+ import { Mark } from './Mark.js'
17
18
  import { PasteRule, pasteRulesPlugin } from './PasteRule.js'
18
19
  import { AnyConfig, Extensions, RawCommands } from './types.js'
19
20
  import { callOrReturn } from './utilities/callOrReturn.js'
package/src/Mark.ts CHANGED
@@ -35,10 +35,10 @@ declare module '@tiptap/core' {
35
35
  name: string
36
36
 
37
37
  /**
38
- * The priority of your extension. The higher, the later it will be called
38
+ * The priority of your extension. The higher, the earlier it will be called
39
39
  * and will take precedence over other extensions with a lower priority.
40
- * @default 1000
41
- * @example 1001
40
+ * @default 100
41
+ * @example 101
42
42
  */
43
43
  priority?: number
44
44
 
@@ -352,6 +352,7 @@ declare module '@tiptap/core' {
352
352
  parent: ParentConfig<MarkConfig<Options, Storage>>['onTransaction']
353
353
  },
354
354
  props: {
355
+ editor: Editor
355
356
  transaction: Transaction
356
357
  },
357
358
  ) => void)
package/src/Node.ts CHANGED
@@ -36,10 +36,10 @@ declare module '@tiptap/core' {
36
36
  name: string
37
37
 
38
38
  /**
39
- * The priority of your extension. The higher, the later it will be called
39
+ * The priority of your extension. The higher, the earlier it will be called
40
40
  * and will take precedence over other extensions with a lower priority.
41
- * @default 1000
42
- * @example 1001
41
+ * @default 100
42
+ * @example 101
43
43
  */
44
44
  priority?: number
45
45
 
@@ -354,6 +354,7 @@ declare module '@tiptap/core' {
354
354
  parent: ParentConfig<NodeConfig<Options, Storage>>['onTransaction']
355
355
  },
356
356
  props: {
357
+ editor: Editor
357
358
  transaction: Transaction
358
359
  },
359
360
  ) => void)
@@ -1,3 +1,5 @@
1
+ import type { Plugin, PluginKey } from '@tiptap/pm/state'
2
+
1
3
  import { RawCommands } from '../types.js'
2
4
 
3
5
  declare module '@tiptap/core' {
@@ -9,7 +11,7 @@ declare module '@tiptap/core' {
9
11
  * @param value The value to store.
10
12
  * @example editor.commands.setMeta('foo', 'bar')
11
13
  */
12
- setMeta: (key: string, value: any) => ReturnType,
14
+ setMeta: (key: string | Plugin | PluginKey, value: any) => ReturnType,
13
15
  }
14
16
  }
15
17
  }
@@ -14,14 +14,15 @@ declare module '@tiptap/core' {
14
14
  /**
15
15
  * Splits one list item into two list items.
16
16
  * @param typeOrName The type or name of the node.
17
+ * @param overrideAttrs The attributes to ensure on the new node.
17
18
  * @example editor.commands.splitListItem('listItem')
18
19
  */
19
- splitListItem: (typeOrName: string | NodeType) => ReturnType
20
+ splitListItem: (typeOrName: string | NodeType, overrideAttrs?: Record<string, any>) => ReturnType
20
21
  }
21
22
  }
22
23
  }
23
24
 
24
- export const splitListItem: RawCommands['splitListItem'] = typeOrName => ({
25
+ export const splitListItem: RawCommands['splitListItem'] = (typeOrName, overrideAttrs = {}) => ({
25
26
  tr, state, dispatch, editor,
26
27
  }) => {
27
28
  const type = getNodeType(typeOrName, state.schema)
@@ -70,11 +71,14 @@ export const splitListItem: RawCommands['splitListItem'] = typeOrName => ({
70
71
  const depthAfter = $from.indexAfter(-1) < $from.node(-2).childCount ? 1 : $from.indexAfter(-2) < $from.node(-3).childCount ? 2 : 3
71
72
 
72
73
  // Add a second list item with an empty default start node
73
- const newNextTypeAttributes = getSplittedAttributes(
74
- extensionAttributes,
75
- $from.node().type.name,
76
- $from.node().attrs,
77
- )
74
+ const newNextTypeAttributes = {
75
+ ...getSplittedAttributes(
76
+ extensionAttributes,
77
+ $from.node().type.name,
78
+ $from.node().attrs,
79
+ ),
80
+ ...overrideAttrs,
81
+ }
78
82
  const nextType = type.contentMatch.defaultType?.createAndFill(newNextTypeAttributes) || undefined
79
83
 
80
84
  wrap = wrap.append(Fragment.from(type.createAndFill(null, nextType) || undefined))
@@ -107,16 +111,22 @@ export const splitListItem: RawCommands['splitListItem'] = typeOrName => ({
107
111
 
108
112
  const nextType = $to.pos === $from.end() ? grandParent.contentMatchAt(0).defaultType : null
109
113
 
110
- const newTypeAttributes = getSplittedAttributes(
111
- extensionAttributes,
112
- grandParent.type.name,
113
- grandParent.attrs,
114
- )
115
- const newNextTypeAttributes = getSplittedAttributes(
116
- extensionAttributes,
117
- $from.node().type.name,
118
- $from.node().attrs,
119
- )
114
+ const newTypeAttributes = {
115
+ ...getSplittedAttributes(
116
+ extensionAttributes,
117
+ grandParent.type.name,
118
+ grandParent.attrs,
119
+ ),
120
+ ...overrideAttrs,
121
+ }
122
+ const newNextTypeAttributes = {
123
+ ...getSplittedAttributes(
124
+ extensionAttributes,
125
+ $from.node().type.name,
126
+ $from.node().attrs,
127
+ ),
128
+ ...overrideAttrs,
129
+ }
120
130
 
121
131
  tr.delete($from.pos, $to.pos)
122
132
 
@@ -1,4 +1,4 @@
1
- import { MarkConfig, NodeConfig } from '../index.js'
1
+ import type { MarkConfig, NodeConfig } from '../index.js'
2
2
  import {
3
3
  AnyConfig,
4
4
  Attribute,
@@ -12,7 +12,7 @@ export function getMarksBetween(from: number, to: number, doc: ProseMirrorNode):
12
12
  .resolve(from)
13
13
  .marks()
14
14
  .forEach(mark => {
15
- const $pos = doc.resolve(from - 1)
15
+ const $pos = doc.resolve(from)
16
16
  const range = getMarkRange($pos, mark.type)
17
17
 
18
18
  if (!range) {
@@ -2,7 +2,7 @@ import {
2
2
  MarkSpec, NodeSpec, Schema, TagParseRule,
3
3
  } from '@tiptap/pm/model'
4
4
 
5
- import { Editor, MarkConfig, NodeConfig } from '../index.js'
5
+ import type { Editor, MarkConfig, NodeConfig } from '../index.js'
6
6
  import { AnyConfig, Extensions } from '../types.js'
7
7
  import { callOrReturn } from '../utilities/callOrReturn.js'
8
8
  import { isEmptyObject } from '../utilities/isEmptyObject.js'
@@ -1,5 +1,5 @@
1
1
  import { getExtensionField } from '../helpers/getExtensionField.js'
2
- import { NodeConfig } from '../index.js'
2
+ import type { NodeConfig } from '../index.js'
3
3
  import { Extensions } from '../types.js'
4
4
  import { callOrReturn } from '../utilities/callOrReturn.js'
5
5
  import { splitExtensions } from './splitExtensions.js'
@@ -1,40 +1,61 @@
1
1
  import { Node as ProseMirrorNode } from '@tiptap/pm/model'
2
2
 
3
3
  /**
4
- * Returns true if the given node is empty.
5
- * When `checkChildren` is true (default), it will also check if all children are empty.
4
+ * Returns true if the given prosemirror node is empty.
6
5
  */
7
6
  export function isNodeEmpty(
8
7
  node: ProseMirrorNode,
9
- { checkChildren }: { checkChildren: boolean } = { checkChildren: true },
8
+ {
9
+ checkChildren = true,
10
+ ignoreWhitespace = false,
11
+ }: {
12
+ /**
13
+ * When true (default), it will also check if all children are empty.
14
+ */
15
+ checkChildren?: boolean;
16
+ /**
17
+ * When true, it will ignore whitespace when checking for emptiness.
18
+ */
19
+ ignoreWhitespace?: boolean;
20
+ } = {},
10
21
  ): boolean {
22
+ if (ignoreWhitespace) {
23
+ if (node.type.name === 'hardBreak') {
24
+ // Hard breaks are considered empty
25
+ return true
26
+ }
27
+ if (node.isText) {
28
+ return /^\s*$/m.test(node.text ?? '')
29
+ }
30
+ }
31
+
11
32
  if (node.isText) {
12
33
  return !node.text
13
34
  }
14
35
 
15
- if (node.content.childCount === 0) {
16
- return true
36
+ if (node.isAtom || node.isLeaf) {
37
+ return false
17
38
  }
18
39
 
19
- if (node.isLeaf) {
20
- return false
40
+ if (node.content.childCount === 0) {
41
+ return true
21
42
  }
22
43
 
23
44
  if (checkChildren) {
24
- let hasSameContent = true
45
+ let isContentEmpty = true
25
46
 
26
47
  node.content.forEach(childNode => {
27
- if (hasSameContent === false) {
48
+ if (isContentEmpty === false) {
28
49
  // Exit early for perf
29
50
  return
30
51
  }
31
52
 
32
- if (!isNodeEmpty(childNode)) {
33
- hasSameContent = false
53
+ if (!isNodeEmpty(childNode, { ignoreWhitespace, checkChildren })) {
54
+ isContentEmpty = false
34
55
  }
35
56
  })
36
57
 
37
- return hasSameContent
58
+ return isContentEmpty
38
59
  }
39
60
 
40
61
  return false
@@ -1,7 +1,7 @@
1
1
  import { NodeType } from '@tiptap/pm/model'
2
2
 
3
3
  import { PasteRule, PasteRuleFinder } from '../PasteRule.js'
4
- import { ExtendedRegExpMatchArray } from '../types.js'
4
+ import { ExtendedRegExpMatchArray, JSONContent } from '../types.js'
5
5
  import { callOrReturn } from '../utilities/index.js'
6
6
 
7
7
  /**
@@ -17,6 +17,11 @@ export function nodePasteRule(config: {
17
17
  | ((match: ExtendedRegExpMatchArray, event: ClipboardEvent) => Record<string, any>)
18
18
  | false
19
19
  | null
20
+ getContent?:
21
+ | JSONContent[]
22
+ | ((attrs: Record<string, any>) => JSONContent[])
23
+ | false
24
+ | null
20
25
  }) {
21
26
  return new PasteRule({
22
27
  find: config.find,
@@ -24,16 +29,20 @@ export function nodePasteRule(config: {
24
29
  match, chain, range, pasteEvent,
25
30
  }) {
26
31
  const attributes = callOrReturn(config.getAttributes, undefined, match, pasteEvent)
32
+ const content = callOrReturn(config.getContent, undefined, attributes)
27
33
 
28
34
  if (attributes === false || attributes === null) {
29
35
  return null
30
36
  }
31
37
 
38
+ const node = { type: config.type.name, attrs: attributes } as JSONContent
39
+
40
+ if (content) {
41
+ node.content = content
42
+ }
43
+
32
44
  if (match.input) {
33
- chain().deleteRange(range).insertContentAt(range.from, {
34
- type: config.type.name,
35
- attrs: attributes,
36
- })
45
+ chain().deleteRange(range).insertContentAt(range.from, node)
37
46
  }
38
47
  },
39
48
  })
package/src/style.ts CHANGED
@@ -27,8 +27,8 @@ img.ProseMirror-separator {
27
27
  display: inline !important;
28
28
  border: none !important;
29
29
  margin: 0 !important;
30
- width: 1px !important;
31
- height: 1px !important;
30
+ width: 0 !important;
31
+ height: 0 !important;
32
32
  }
33
33
 
34
34
  .ProseMirror-gapcursor {