@tiptap/core 3.0.0-next.2 → 3.0.0-next.4

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 (128) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +5 -1
  3. package/dist/index.cjs +2402 -2540
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.cts +1355 -1273
  6. package/dist/index.d.ts +1355 -1273
  7. package/dist/index.js +2408 -2562
  8. package/dist/index.js.map +1 -1
  9. package/package.json +9 -5
  10. package/src/CommandManager.ts +2 -9
  11. package/src/Editor.ts +87 -72
  12. package/src/EventEmitter.ts +7 -10
  13. package/src/Extension.ts +8 -14
  14. package/src/ExtensionManager.ts +26 -125
  15. package/src/InputRule.ts +35 -48
  16. package/src/Mark.ts +9 -9
  17. package/src/Node.ts +9 -9
  18. package/src/NodePos.ts +1 -3
  19. package/src/NodeView.ts +10 -20
  20. package/src/PasteRule.ts +43 -55
  21. package/src/Tracker.ts +7 -9
  22. package/src/commands/blur.ts +14 -12
  23. package/src/commands/clearContent.ts +6 -4
  24. package/src/commands/clearNodes.ts +32 -30
  25. package/src/commands/command.ts +1 -1
  26. package/src/commands/createParagraphNear.ts +5 -3
  27. package/src/commands/cut.ts +12 -10
  28. package/src/commands/deleteCurrentNode.ts +23 -21
  29. package/src/commands/deleteNode.ts +18 -16
  30. package/src/commands/deleteRange.ts +10 -8
  31. package/src/commands/deleteSelection.ts +5 -3
  32. package/src/commands/enter.ts +6 -4
  33. package/src/commands/exitCode.ts +5 -3
  34. package/src/commands/extendMarkRange.ts +14 -12
  35. package/src/commands/first.ts +2 -4
  36. package/src/commands/focus.ts +45 -48
  37. package/src/commands/forEach.ts +2 -2
  38. package/src/commands/insertContent.ts +12 -14
  39. package/src/commands/insertContentAt.ts +101 -98
  40. package/src/commands/join.ts +20 -12
  41. package/src/commands/joinItemBackward.ts +16 -18
  42. package/src/commands/joinItemForward.ts +16 -18
  43. package/src/commands/joinTextblockBackward.ts +5 -3
  44. package/src/commands/joinTextblockForward.ts +5 -3
  45. package/src/commands/keyboardShortcut.ts +29 -34
  46. package/src/commands/lift.ts +10 -8
  47. package/src/commands/liftEmptyBlock.ts +6 -4
  48. package/src/commands/liftListItem.ts +6 -4
  49. package/src/commands/newlineInCode.ts +5 -3
  50. package/src/commands/resetAttributes.ts +36 -41
  51. package/src/commands/scrollIntoView.ts +9 -7
  52. package/src/commands/selectAll.ts +10 -8
  53. package/src/commands/selectNodeBackward.ts +5 -3
  54. package/src/commands/selectNodeForward.ts +5 -3
  55. package/src/commands/selectParentNode.ts +5 -3
  56. package/src/commands/selectTextblockEnd.ts +5 -3
  57. package/src/commands/selectTextblockStart.ts +5 -3
  58. package/src/commands/setContent.ts +25 -25
  59. package/src/commands/setMark.ts +55 -57
  60. package/src/commands/setMeta.ts +7 -5
  61. package/src/commands/setNode.ts +32 -30
  62. package/src/commands/setNodeSelection.ts +11 -9
  63. package/src/commands/setTextSelection.ts +15 -13
  64. package/src/commands/sinkListItem.ts +6 -4
  65. package/src/commands/splitBlock.ts +67 -76
  66. package/src/commands/splitListItem.ts +93 -106
  67. package/src/commands/toggleList.ts +73 -71
  68. package/src/commands/toggleMark.ts +11 -9
  69. package/src/commands/toggleNode.ts +18 -16
  70. package/src/commands/toggleWrap.ts +10 -8
  71. package/src/commands/undoInputRule.ts +31 -29
  72. package/src/commands/unsetAllMarks.ts +16 -14
  73. package/src/commands/unsetMark.ts +27 -25
  74. package/src/commands/updateAttributes.ts +92 -100
  75. package/src/commands/wrapIn.ts +6 -4
  76. package/src/commands/wrapInList.ts +6 -4
  77. package/src/extensions/clipboardTextSerializer.ts +2 -4
  78. package/src/extensions/focusEvents.ts +2 -6
  79. package/src/extensions/keymap.ts +54 -50
  80. package/src/extensions/paste.ts +0 -1
  81. package/src/extensions/tabindex.ts +1 -1
  82. package/src/helpers/combineTransactionSteps.ts +1 -4
  83. package/src/helpers/createChainableState.ts +1 -4
  84. package/src/helpers/createDocument.ts +1 -3
  85. package/src/helpers/createNodeFromContent.ts +4 -10
  86. package/src/helpers/findChildrenInRange.ts +1 -5
  87. package/src/helpers/findParentNode.ts +3 -1
  88. package/src/helpers/flattenExtensions.ts +30 -0
  89. package/src/helpers/getAttributes.ts +1 -4
  90. package/src/helpers/getAttributesFromExtensions.ts +28 -37
  91. package/src/helpers/getChangedRanges.ts +13 -11
  92. package/src/helpers/getExtensionField.ts +1 -4
  93. package/src/helpers/getMarkAttributes.ts +1 -4
  94. package/src/helpers/getMarkRange.ts +5 -15
  95. package/src/helpers/getMarkType.ts +1 -3
  96. package/src/helpers/getNodeAttributes.ts +1 -4
  97. package/src/helpers/getNodeType.ts +1 -3
  98. package/src/helpers/getRenderedAttributes.ts +1 -3
  99. package/src/helpers/getSchema.ts +2 -2
  100. package/src/helpers/getSchemaByResolvedExtensions.ts +45 -77
  101. package/src/helpers/getSplittedAttributes.ts +4 -4
  102. package/src/helpers/getTextContentFromNodes.ts +8 -11
  103. package/src/helpers/index.ts +4 -0
  104. package/src/helpers/injectExtensionAttributesToParseRule.ts +1 -1
  105. package/src/helpers/isActive.ts +1 -5
  106. package/src/helpers/isExtensionRulesEnabled.ts +1 -3
  107. package/src/helpers/isNodeEmpty.ts +2 -2
  108. package/src/helpers/resolveExtensions.ts +25 -0
  109. package/src/helpers/resolveFocusPosition.ts +3 -14
  110. package/src/helpers/rewriteUnknownContent.ts +149 -0
  111. package/src/helpers/sortExtensions.ts +26 -0
  112. package/src/inputRules/markInputRule.ts +1 -5
  113. package/src/inputRules/nodeInputRule.ts +2 -9
  114. package/src/inputRules/textInputRule.ts +1 -4
  115. package/src/inputRules/textblockTypeInputRule.ts +2 -8
  116. package/src/inputRules/wrappingInputRule.ts +13 -19
  117. package/src/pasteRules/markPasteRule.ts +1 -3
  118. package/src/pasteRules/nodePasteRule.ts +2 -8
  119. package/src/pasteRules/textPasteRule.ts +1 -4
  120. package/src/types.ts +212 -172
  121. package/src/utilities/createStyleTag.ts +3 -1
  122. package/src/utilities/deleteProps.ts +7 -11
  123. package/src/utilities/findDuplicates.ts +4 -1
  124. package/src/utilities/isFunction.ts +1 -0
  125. package/src/utilities/isMacOS.ts +1 -3
  126. package/src/utilities/isiOS.ts +5 -10
  127. package/src/utilities/mergeAttributes.ts +16 -6
  128. package/src/utilities/removeDuplicates.ts +1 -3
package/src/InputRule.ts CHANGED
@@ -6,57 +6,48 @@ import { Editor } from './Editor.js'
6
6
  import { createChainableState } from './helpers/createChainableState.js'
7
7
  import { getHTMLFromFragment } from './helpers/getHTMLFromFragment.js'
8
8
  import { getTextContentFromNodes } from './helpers/getTextContentFromNodes.js'
9
- import {
10
- CanCommands,
11
- ChainedCommands,
12
- ExtendedRegExpMatchArray,
13
- Range,
14
- SingleCommands,
15
- } from './types.js'
9
+ import { CanCommands, ChainedCommands, ExtendedRegExpMatchArray, Range, SingleCommands } from './types.js'
16
10
  import { isRegExp } from './utilities/isRegExp.js'
17
11
 
18
12
  export type InputRuleMatch = {
19
- index: number;
20
- text: string;
21
- replaceWith?: string;
22
- match?: RegExpMatchArray;
23
- data?: Record<string, any>;
24
- };
13
+ index: number
14
+ text: string
15
+ replaceWith?: string
16
+ match?: RegExpMatchArray
17
+ data?: Record<string, any>
18
+ }
25
19
 
26
- export type InputRuleFinder = RegExp | ((text: string) => InputRuleMatch | null);
20
+ export type InputRuleFinder = RegExp | ((text: string) => InputRuleMatch | null)
27
21
 
28
22
  export class InputRule {
29
23
  find: InputRuleFinder
30
24
 
31
25
  handler: (props: {
32
- state: EditorState;
33
- range: Range;
34
- match: ExtendedRegExpMatchArray;
35
- commands: SingleCommands;
36
- chain: () => ChainedCommands;
37
- can: () => CanCommands;
26
+ state: EditorState
27
+ range: Range
28
+ match: ExtendedRegExpMatchArray
29
+ commands: SingleCommands
30
+ chain: () => ChainedCommands
31
+ can: () => CanCommands
38
32
  }) => void | null
39
33
 
40
34
  constructor(config: {
41
- find: InputRuleFinder;
35
+ find: InputRuleFinder
42
36
  handler: (props: {
43
- state: EditorState;
44
- range: Range;
45
- match: ExtendedRegExpMatchArray;
46
- commands: SingleCommands;
47
- chain: () => ChainedCommands;
48
- can: () => CanCommands;
49
- }) => void | null;
37
+ state: EditorState
38
+ range: Range
39
+ match: ExtendedRegExpMatchArray
40
+ commands: SingleCommands
41
+ chain: () => ChainedCommands
42
+ can: () => CanCommands
43
+ }) => void | null
50
44
  }) {
51
45
  this.find = config.find
52
46
  this.handler = config.handler
53
47
  }
54
48
  }
55
49
 
56
- const inputRuleMatcherHandler = (
57
- text: string,
58
- find: InputRuleFinder,
59
- ): ExtendedRegExpMatchArray | null => {
50
+ const inputRuleMatcherHandler = (text: string, find: InputRuleFinder): ExtendedRegExpMatchArray | null => {
60
51
  if (isRegExp(find)) {
61
52
  return find.exec(text)
62
53
  }
@@ -75,9 +66,7 @@ const inputRuleMatcherHandler = (
75
66
 
76
67
  if (inputRuleMatch.replaceWith) {
77
68
  if (!inputRuleMatch.text.includes(inputRuleMatch.replaceWith)) {
78
- console.warn(
79
- '[tiptap warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".',
80
- )
69
+ console.warn('[tiptap warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".')
81
70
  }
82
71
 
83
72
  result.push(inputRuleMatch.replaceWith)
@@ -87,16 +76,14 @@ const inputRuleMatcherHandler = (
87
76
  }
88
77
 
89
78
  function run(config: {
90
- editor: Editor;
91
- from: number;
92
- to: number;
93
- text: string;
94
- rules: InputRule[];
95
- plugin: Plugin;
79
+ editor: Editor
80
+ from: number
81
+ to: number
82
+ text: string
83
+ rules: InputRule[]
84
+ plugin: Plugin
96
85
  }): boolean {
97
- const {
98
- editor, from, to, text, rules, plugin,
99
- } = config
86
+ const { editor, from, to, text, rules, plugin } = config
100
87
  const { view } = editor
101
88
 
102
89
  if (view.composing) {
@@ -107,9 +94,9 @@ function run(config: {
107
94
 
108
95
  if (
109
96
  // check for code node
110
- $from.parent.type.spec.code
97
+ $from.parent.type.spec.code ||
111
98
  // check for code mark
112
- || !!($from.nodeBefore || $from.nodeAfter)?.marks.find(mark => mark.type.spec.code)
99
+ !!($from.nodeBefore || $from.nodeAfter)?.marks.find(mark => mark.type.spec.code)
113
100
  ) {
114
101
  return false
115
102
  }
@@ -197,8 +184,8 @@ export function inputRulesPlugin(props: { editor: Editor; rules: InputRule[] }):
197
184
  const simulatedInputMeta = tr.getMeta('applyInputRules') as
198
185
  | undefined
199
186
  | {
200
- from: number;
201
- text: string | ProseMirrorNode | Fragment;
187
+ from: number
188
+ text: string | ProseMirrorNode | Fragment
202
189
  }
203
190
  const isSimulatedInput = !!simulatedInputMeta
204
191
 
package/src/Mark.ts CHANGED
@@ -1,6 +1,4 @@
1
- import {
2
- DOMOutputSpec, Mark as ProseMirrorMark, MarkSpec, MarkType,
3
- } from '@tiptap/pm/model'
1
+ import { DOMOutputSpec, Mark as ProseMirrorMark, MarkSpec, MarkType } from '@tiptap/pm/model'
4
2
  import { Plugin, Transaction } from '@tiptap/pm/state'
5
3
 
6
4
  import { Editor } from './Editor.js'
@@ -524,6 +522,7 @@ declare module '@tiptap/core' {
524
522
  storage: Storage
525
523
  parent: ParentConfig<MarkConfig<Options, Storage>>['addAttributes']
526
524
  editor?: Editor
525
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
527
526
  }) => Attributes | {}
528
527
  }
529
528
  }
@@ -575,12 +574,13 @@ export class Mark<Options = any, Storage = any> {
575
574
  )
576
575
  }
577
576
 
578
- this.storage = callOrReturn(
579
- getExtensionField<AnyConfig['addStorage']>(this, 'addStorage', {
580
- name: this.name,
581
- options: this.options,
582
- }),
583
- ) || {}
577
+ this.storage =
578
+ callOrReturn(
579
+ getExtensionField<AnyConfig['addStorage']>(this, 'addStorage', {
580
+ name: this.name,
581
+ options: this.options,
582
+ }),
583
+ ) || {}
584
584
  }
585
585
 
586
586
  static create<O = any, S = any>(config: Partial<MarkConfig<O, S>> = {}) {
package/src/Node.ts CHANGED
@@ -1,6 +1,4 @@
1
- import {
2
- DOMOutputSpec, Node as ProseMirrorNode, NodeSpec, NodeType,
3
- } from '@tiptap/pm/model'
1
+ import { DOMOutputSpec, Node as ProseMirrorNode, NodeSpec, NodeType } from '@tiptap/pm/model'
4
2
  import { Plugin, Transaction } from '@tiptap/pm/state'
5
3
 
6
4
  import { Editor } from './Editor.js'
@@ -734,6 +732,7 @@ declare module '@tiptap/core' {
734
732
  storage: Storage
735
733
  parent: ParentConfig<NodeConfig<Options, Storage>>['addAttributes']
736
734
  editor?: Editor
735
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
737
736
  }) => Attributes | {}
738
737
  }
739
738
  }
@@ -785,12 +784,13 @@ export class Node<Options = any, Storage = any> {
785
784
  )
786
785
  }
787
786
 
788
- this.storage = callOrReturn(
789
- getExtensionField<AnyConfig['addStorage']>(this, 'addStorage', {
790
- name: this.name,
791
- options: this.options,
792
- }),
793
- ) || {}
787
+ this.storage =
788
+ callOrReturn(
789
+ getExtensionField<AnyConfig['addStorage']>(this, 'addStorage', {
790
+ name: this.name,
791
+ options: this.options,
792
+ }),
793
+ ) || {}
794
794
  }
795
795
 
796
796
  static create<O = any, S = any>(config: Partial<NodeConfig<O, S>> = {}) {
package/src/NodePos.ts CHANGED
@@ -1,6 +1,4 @@
1
- import {
2
- Fragment, Node, ResolvedPos,
3
- } from '@tiptap/pm/model'
1
+ import { Fragment, Node, ResolvedPos } from '@tiptap/pm/model'
4
2
 
5
3
  import { Editor } from './Editor.js'
6
4
  import { Content, Range } from './types.js'
package/src/NodeView.ts CHANGED
@@ -14,7 +14,8 @@ export class NodeView<
14
14
  Component,
15
15
  NodeEditor extends CoreEditor = CoreEditor,
16
16
  Options extends NodeViewRendererOptions = NodeViewRendererOptions,
17
- > implements ProseMirrorNodeView {
17
+ > implements ProseMirrorNodeView
18
+ {
18
19
  component: Component
19
20
 
20
21
  editor: NodeEditor
@@ -74,9 +75,8 @@ export class NodeView<
74
75
 
75
76
  // get the drag handle element
76
77
  // `closest` is not available for text nodes so we may have to use its parent
77
- const dragHandle = target.nodeType === 3
78
- ? target.parentElement?.closest('[data-drag-handle]')
79
- : target.closest('[data-drag-handle]')
78
+ const dragHandle =
79
+ target.nodeType === 3 ? target.parentElement?.closest('[data-drag-handle]') : target.closest('[data-drag-handle]')
80
80
 
81
81
  if (!this.dom || this.contentDOM?.contains(target) || !dragHandle) {
82
82
  return
@@ -195,14 +195,7 @@ export class NodeView<
195
195
  }
196
196
 
197
197
  // these events are handled by prosemirror
198
- if (
199
- isDragging
200
- || isDropEvent
201
- || isCopyEvent
202
- || isPasteEvent
203
- || isCutEvent
204
- || (isClickEvent && isSelectable)
205
- ) {
198
+ if (isDragging || isDropEvent || isCopyEvent || isPasteEvent || isCutEvent || (isClickEvent && isSelectable)) {
206
199
  return false
207
200
  }
208
201
 
@@ -240,15 +233,12 @@ export class NodeView<
240
233
  // see: https://github.com/ueberdosis/tiptap/issues/1214
241
234
  // see: https://github.com/ueberdosis/tiptap/issues/2534
242
235
  if (
243
- this.dom.contains(mutation.target)
244
- && mutation.type === 'childList'
245
- && (isiOS() || isAndroid())
246
- && this.editor.isFocused
236
+ this.dom.contains(mutation.target) &&
237
+ mutation.type === 'childList' &&
238
+ (isiOS() || isAndroid()) &&
239
+ this.editor.isFocused
247
240
  ) {
248
- const changedNodes = [
249
- ...Array.from(mutation.addedNodes),
250
- ...Array.from(mutation.removedNodes),
251
- ] as HTMLElement[]
241
+ const changedNodes = [...Array.from(mutation.addedNodes), ...Array.from(mutation.removedNodes)] as HTMLElement[]
252
242
 
253
243
  // we’ll check if every changed node is contentEditable
254
244
  // to make sure it’s probably mutated by ProseMirror
package/src/PasteRule.ts CHANGED
@@ -5,27 +5,21 @@ import { CommandManager } from './CommandManager.js'
5
5
  import { Editor } from './Editor.js'
6
6
  import { createChainableState } from './helpers/createChainableState.js'
7
7
  import { getHTMLFromFragment } from './helpers/getHTMLFromFragment.js'
8
- import {
9
- CanCommands,
10
- ChainedCommands,
11
- ExtendedRegExpMatchArray,
12
- Range,
13
- SingleCommands,
14
- } from './types.js'
8
+ import { CanCommands, ChainedCommands, ExtendedRegExpMatchArray, Range, SingleCommands } from './types.js'
15
9
  import { isNumber } from './utilities/isNumber.js'
16
10
  import { isRegExp } from './utilities/isRegExp.js'
17
11
 
18
12
  export type PasteRuleMatch = {
19
- index: number;
20
- text: string;
21
- replaceWith?: string;
22
- match?: RegExpMatchArray;
23
- data?: Record<string, any>;
24
- };
13
+ index: number
14
+ text: string
15
+ replaceWith?: string
16
+ match?: RegExpMatchArray
17
+ data?: Record<string, any>
18
+ }
25
19
 
26
20
  export type PasteRuleFinder =
27
21
  | RegExp
28
- | ((text: string, event?: ClipboardEvent | null) => PasteRuleMatch[] | null | undefined);
22
+ | ((text: string, event?: ClipboardEvent | null) => PasteRuleMatch[] | null | undefined)
29
23
 
30
24
  /**
31
25
  * Paste rules are used to react to pasted content.
@@ -35,28 +29,28 @@ export class PasteRule {
35
29
  find: PasteRuleFinder
36
30
 
37
31
  handler: (props: {
38
- state: EditorState;
39
- range: Range;
40
- match: ExtendedRegExpMatchArray;
41
- commands: SingleCommands;
42
- chain: () => ChainedCommands;
43
- can: () => CanCommands;
44
- pasteEvent: ClipboardEvent | null;
45
- dropEvent: DragEvent | null;
32
+ state: EditorState
33
+ range: Range
34
+ match: ExtendedRegExpMatchArray
35
+ commands: SingleCommands
36
+ chain: () => ChainedCommands
37
+ can: () => CanCommands
38
+ pasteEvent: ClipboardEvent | null
39
+ dropEvent: DragEvent | null
46
40
  }) => void | null
47
41
 
48
42
  constructor(config: {
49
- find: PasteRuleFinder;
43
+ find: PasteRuleFinder
50
44
  handler: (props: {
51
- can: () => CanCommands;
52
- chain: () => ChainedCommands;
53
- commands: SingleCommands;
54
- dropEvent: DragEvent | null;
55
- match: ExtendedRegExpMatchArray;
56
- pasteEvent: ClipboardEvent | null;
57
- range: Range;
58
- state: EditorState;
59
- }) => void | null;
45
+ can: () => CanCommands
46
+ chain: () => ChainedCommands
47
+ commands: SingleCommands
48
+ dropEvent: DragEvent | null
49
+ match: ExtendedRegExpMatchArray
50
+ pasteEvent: ClipboardEvent | null
51
+ range: Range
52
+ state: EditorState
53
+ }) => void | null
60
54
  }) {
61
55
  this.find = config.find
62
56
  this.handler = config.handler
@@ -87,9 +81,7 @@ const pasteRuleMatcherHandler = (
87
81
 
88
82
  if (pasteRuleMatch.replaceWith) {
89
83
  if (!pasteRuleMatch.text.includes(pasteRuleMatch.replaceWith)) {
90
- console.warn(
91
- '[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".',
92
- )
84
+ console.warn('[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".')
93
85
  }
94
86
 
95
87
  result.push(pasteRuleMatch.replaceWith)
@@ -100,17 +92,15 @@ const pasteRuleMatcherHandler = (
100
92
  }
101
93
 
102
94
  function run(config: {
103
- editor: Editor;
104
- state: EditorState;
105
- from: number;
106
- to: number;
107
- rule: PasteRule;
108
- pasteEvent: ClipboardEvent | null;
109
- dropEvent: DragEvent | null;
95
+ editor: Editor
96
+ state: EditorState
97
+ from: number
98
+ to: number
99
+ rule: PasteRule
100
+ pasteEvent: ClipboardEvent | null
101
+ dropEvent: DragEvent | null
110
102
  }): boolean {
111
- const {
112
- editor, state, from, to, rule, pasteEvent, dropEvent,
113
- } = config
103
+ const { editor, state, from, to, rule, pasteEvent, dropEvent } = config
114
104
 
115
105
  const { commands, chain, can } = new CommandManager({
116
106
  editor,
@@ -190,7 +180,7 @@ export function pasteRulesPlugin(props: { editor: Editor; rules: PasteRule[] }):
190
180
 
191
181
  try {
192
182
  dropEvent = typeof DragEvent !== 'undefined' ? new DragEvent('drop') : null
193
- } catch (e) {
183
+ } catch {
194
184
  dropEvent = null
195
185
  }
196
186
 
@@ -201,11 +191,11 @@ export function pasteRulesPlugin(props: { editor: Editor; rules: PasteRule[] }):
201
191
  rule,
202
192
  pasteEvt,
203
193
  }: {
204
- state: EditorState;
205
- from: number;
206
- to: { b: number };
207
- rule: PasteRule;
208
- pasteEvt: ClipboardEvent | null;
194
+ state: EditorState
195
+ from: number
196
+ to: { b: number }
197
+ rule: PasteRule
198
+ pasteEvt: ClipboardEvent | null
209
199
  }) => {
210
200
  const tr = state.tr
211
201
  const chainableState = createChainableState({
@@ -229,7 +219,7 @@ export function pasteRulesPlugin(props: { editor: Editor; rules: PasteRule[] }):
229
219
 
230
220
  try {
231
221
  dropEvent = typeof DragEvent !== 'undefined' ? new DragEvent('drop') : null
232
- } catch (e) {
222
+ } catch {
233
223
  dropEvent = null
234
224
  }
235
225
  pasteEvent = typeof ClipboardEvent !== 'undefined' ? new ClipboardEvent('paste') : null
@@ -242,9 +232,7 @@ export function pasteRulesPlugin(props: { editor: Editor; rules: PasteRule[] }):
242
232
  // we register a global drag handler to track the current drag source element
243
233
  view(view) {
244
234
  const handleDragstart = (event: DragEvent) => {
245
- dragSourceElement = view.dom.parentElement?.contains(event.target as Element)
246
- ? view.dom.parentElement
247
- : null
235
+ dragSourceElement = view.dom.parentElement?.contains(event.target as Element) ? view.dom.parentElement : null
248
236
 
249
237
  if (dragSourceElement) {
250
238
  tiptapDragFromOtherEditor = editor
package/src/Tracker.ts CHANGED
@@ -18,17 +18,15 @@ export class Tracker {
18
18
  map(position: number): TrackerResult {
19
19
  let deleted = false
20
20
 
21
- const mappedPosition = this.transaction.steps
22
- .slice(this.currentStep)
23
- .reduce((newPosition, step) => {
24
- const mapResult = step.getMap().mapResult(newPosition)
21
+ const mappedPosition = this.transaction.steps.slice(this.currentStep).reduce((newPosition, step) => {
22
+ const mapResult = step.getMap().mapResult(newPosition)
25
23
 
26
- if (mapResult.deleted) {
27
- deleted = true
28
- }
24
+ if (mapResult.deleted) {
25
+ deleted = true
26
+ }
29
27
 
30
- return mapResult.pos
31
- }, position)
28
+ return mapResult.pos
29
+ }, position)
32
30
 
33
31
  return {
34
32
  position: mappedPosition,
@@ -7,21 +7,23 @@ declare module '@tiptap/core' {
7
7
  * Removes focus from the editor.
8
8
  * @example editor.commands.blur()
9
9
  */
10
- blur: () => ReturnType,
10
+ blur: () => ReturnType
11
11
  }
12
12
  }
13
13
  }
14
14
 
15
- export const blur: RawCommands['blur'] = () => ({ editor, view }) => {
16
- requestAnimationFrame(() => {
17
- if (!editor.isDestroyed) {
18
- (view.dom as HTMLElement).blur()
15
+ export const blur: RawCommands['blur'] =
16
+ () =>
17
+ ({ editor, view }) => {
18
+ requestAnimationFrame(() => {
19
+ if (!editor.isDestroyed) {
20
+ ;(view.dom as HTMLElement).blur()
19
21
 
20
- // Browsers should remove the caret on blur but safari does not.
21
- // See: https://github.com/ueberdosis/tiptap/issues/2405
22
- window?.getSelection()?.removeAllRanges()
23
- }
24
- })
22
+ // Browsers should remove the caret on blur but safari does not.
23
+ // See: https://github.com/ueberdosis/tiptap/issues/2405
24
+ window?.getSelection()?.removeAllRanges()
25
+ }
26
+ })
25
27
 
26
- return true
27
- }
28
+ return true
29
+ }
@@ -8,11 +8,13 @@ declare module '@tiptap/core' {
8
8
  * @param emitUpdate Whether to emit an update event.
9
9
  * @example editor.commands.clearContent()
10
10
  */
11
- clearContent: (emitUpdate?: boolean) => ReturnType,
11
+ clearContent: (emitUpdate?: boolean) => ReturnType
12
12
  }
13
13
  }
14
14
  }
15
15
 
16
- export const clearContent: RawCommands['clearContent'] = (emitUpdate = false) => ({ commands }) => {
17
- return commands.setContent('', emitUpdate)
18
- }
16
+ export const clearContent: RawCommands['clearContent'] =
17
+ (emitUpdate = false) =>
18
+ ({ commands }) => {
19
+ return commands.setContent('', emitUpdate)
20
+ }
@@ -9,47 +9,49 @@ declare module '@tiptap/core' {
9
9
  * Normalize nodes to a simple paragraph.
10
10
  * @example editor.commands.clearNodes()
11
11
  */
12
- clearNodes: () => ReturnType,
12
+ clearNodes: () => ReturnType
13
13
  }
14
14
  }
15
15
  }
16
16
 
17
- export const clearNodes: RawCommands['clearNodes'] = () => ({ state, tr, dispatch }) => {
18
- const { selection } = tr
19
- const { ranges } = selection
17
+ export const clearNodes: RawCommands['clearNodes'] =
18
+ () =>
19
+ ({ state, tr, dispatch }) => {
20
+ const { selection } = tr
21
+ const { ranges } = selection
20
22
 
21
- if (!dispatch) {
22
- return true
23
- }
23
+ if (!dispatch) {
24
+ return true
25
+ }
24
26
 
25
- ranges.forEach(({ $from, $to }) => {
26
- state.doc.nodesBetween($from.pos, $to.pos, (node, pos) => {
27
- if (node.type.isText) {
28
- return
29
- }
27
+ ranges.forEach(({ $from, $to }) => {
28
+ state.doc.nodesBetween($from.pos, $to.pos, (node, pos) => {
29
+ if (node.type.isText) {
30
+ return
31
+ }
30
32
 
31
- const { doc, mapping } = tr
32
- const $mappedFrom = doc.resolve(mapping.map(pos))
33
- const $mappedTo = doc.resolve(mapping.map(pos + node.nodeSize))
34
- const nodeRange = $mappedFrom.blockRange($mappedTo)
33
+ const { doc, mapping } = tr
34
+ const $mappedFrom = doc.resolve(mapping.map(pos))
35
+ const $mappedTo = doc.resolve(mapping.map(pos + node.nodeSize))
36
+ const nodeRange = $mappedFrom.blockRange($mappedTo)
35
37
 
36
- if (!nodeRange) {
37
- return
38
- }
38
+ if (!nodeRange) {
39
+ return
40
+ }
39
41
 
40
- const targetLiftDepth = liftTarget(nodeRange)
42
+ const targetLiftDepth = liftTarget(nodeRange)
41
43
 
42
- if (node.type.isTextblock) {
43
- const { defaultType } = $mappedFrom.parent.contentMatchAt($mappedFrom.index())
44
+ if (node.type.isTextblock) {
45
+ const { defaultType } = $mappedFrom.parent.contentMatchAt($mappedFrom.index())
44
46
 
45
- tr.setNodeMarkup(nodeRange.start, defaultType)
46
- }
47
+ tr.setNodeMarkup(nodeRange.start, defaultType)
48
+ }
47
49
 
48
- if (targetLiftDepth || targetLiftDepth === 0) {
49
- tr.lift(nodeRange, targetLiftDepth)
50
- }
50
+ if (targetLiftDepth || targetLiftDepth === 0) {
51
+ tr.lift(nodeRange, targetLiftDepth)
52
+ }
53
+ })
51
54
  })
52
- })
53
55
 
54
- return true
55
- }
56
+ return true
57
+ }
@@ -12,7 +12,7 @@ declare module '@tiptap/core' {
12
12
  * return true
13
13
  * })
14
14
  */
15
- command: (fn: (props: Parameters<Command>[0]) => boolean) => ReturnType,
15
+ command: (fn: (props: Parameters<Command>[0]) => boolean) => ReturnType
16
16
  }
17
17
  }
18
18
  }
@@ -14,6 +14,8 @@ declare module '@tiptap/core' {
14
14
  }
15
15
  }
16
16
 
17
- export const createParagraphNear: RawCommands['createParagraphNear'] = () => ({ state, dispatch }) => {
18
- return originalCreateParagraphNear(state, dispatch)
19
- }
17
+ export const createParagraphNear: RawCommands['createParagraphNear'] =
18
+ () =>
19
+ ({ state, dispatch }) => {
20
+ return originalCreateParagraphNear(state, dispatch)
21
+ }
@@ -13,22 +13,24 @@ declare module '@tiptap/core' {
13
13
  * @param targetPos The position to insert the content at.
14
14
  * @example editor.commands.cut({ from: 1, to: 3 }, 5)
15
15
  */
16
- cut: ({ from, to }: { from: number, to: number }, targetPos: number) => ReturnType,
16
+ cut: ({ from, to }: { from: number; to: number }, targetPos: number) => ReturnType
17
17
  }
18
18
  }
19
19
  }
20
20
 
21
- export const cut: RawCommands['cut'] = (originRange, targetPos) => ({ editor, tr }) => {
22
- const { state } = editor
21
+ export const cut: RawCommands['cut'] =
22
+ (originRange, targetPos) =>
23
+ ({ editor, tr }) => {
24
+ const { state } = editor
23
25
 
24
- const contentSlice = state.doc.slice(originRange.from, originRange.to)
26
+ const contentSlice = state.doc.slice(originRange.from, originRange.to)
25
27
 
26
- tr.deleteRange(originRange.from, originRange.to)
27
- const newPos = tr.mapping.map(targetPos)
28
+ tr.deleteRange(originRange.from, originRange.to)
29
+ const newPos = tr.mapping.map(targetPos)
28
30
 
29
- tr.insert(newPos, contentSlice.content)
31
+ tr.insert(newPos, contentSlice.content)
30
32
 
31
- tr.setSelection(new TextSelection(tr.doc.resolve(newPos - 1)))
33
+ tr.setSelection(new TextSelection(tr.doc.resolve(newPos - 1)))
32
34
 
33
- return true
34
- }
35
+ return true
36
+ }