@tiptap/core 2.2.3 → 2.2.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.
@@ -8,7 +8,7 @@ export declare type PasteRuleMatch = {
8
8
  match?: RegExpMatchArray;
9
9
  data?: Record<string, any>;
10
10
  };
11
- export declare type PasteRuleFinder = RegExp | ((text: string, event?: ClipboardEvent) => PasteRuleMatch[] | null | undefined);
11
+ export declare type PasteRuleFinder = RegExp | ((text: string, event?: ClipboardEvent | null) => PasteRuleMatch[] | null | undefined);
12
12
  export declare class PasteRule {
13
13
  find: PasteRuleFinder;
14
14
  handler: (props: {
@@ -18,8 +18,8 @@ export declare class PasteRule {
18
18
  commands: SingleCommands;
19
19
  chain: () => ChainedCommands;
20
20
  can: () => CanCommands;
21
- pasteEvent: ClipboardEvent;
22
- dropEvent: DragEvent;
21
+ pasteEvent: ClipboardEvent | null;
22
+ dropEvent: DragEvent | null;
23
23
  }) => void | null;
24
24
  constructor(config: {
25
25
  find: PasteRuleFinder;
@@ -27,9 +27,9 @@ export declare class PasteRule {
27
27
  can: () => CanCommands;
28
28
  chain: () => ChainedCommands;
29
29
  commands: SingleCommands;
30
- dropEvent: DragEvent;
30
+ dropEvent: DragEvent | null;
31
31
  match: ExtendedRegExpMatchArray;
32
- pasteEvent: ClipboardEvent;
32
+ pasteEvent: ClipboardEvent | null;
33
33
  range: Range;
34
34
  state: EditorState;
35
35
  }) => void | null;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tiptap/core",
3
3
  "description": "headless rich text editor",
4
- "version": "2.2.3",
4
+ "version": "2.2.4",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -32,7 +32,7 @@
32
32
  "dist"
33
33
  ],
34
34
  "devDependencies": {
35
- "@tiptap/pm": "^2.2.3"
35
+ "@tiptap/pm": "^2.2.4"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "@tiptap/pm": "^2.0.0"
package/src/PasteRule.ts CHANGED
@@ -21,7 +21,7 @@ export type PasteRuleMatch = {
21
21
  data?: Record<string, any>
22
22
  }
23
23
 
24
- export type PasteRuleFinder = RegExp | ((text: string, event?: ClipboardEvent) => PasteRuleMatch[] | null | undefined)
24
+ export type PasteRuleFinder = RegExp | ((text: string, event?: ClipboardEvent | null) => PasteRuleMatch[] | null | undefined)
25
25
 
26
26
  export class PasteRule {
27
27
  find: PasteRuleFinder
@@ -33,8 +33,8 @@ export class PasteRule {
33
33
  commands: SingleCommands
34
34
  chain: () => ChainedCommands
35
35
  can: () => CanCommands
36
- pasteEvent: ClipboardEvent
37
- dropEvent: DragEvent
36
+ pasteEvent: ClipboardEvent | null
37
+ dropEvent: DragEvent | null
38
38
  }) => void | null
39
39
 
40
40
  constructor(config: {
@@ -43,9 +43,9 @@ export class PasteRule {
43
43
  can: () => CanCommands
44
44
  chain: () => ChainedCommands
45
45
  commands: SingleCommands
46
- dropEvent: DragEvent
46
+ dropEvent: DragEvent | null
47
47
  match: ExtendedRegExpMatchArray
48
- pasteEvent: ClipboardEvent
48
+ pasteEvent: ClipboardEvent | null
49
49
  range: Range
50
50
  state: EditorState
51
51
  }) => void | null
@@ -58,7 +58,7 @@ export class PasteRule {
58
58
  const pasteRuleMatcherHandler = (
59
59
  text: string,
60
60
  find: PasteRuleFinder,
61
- event?: ClipboardEvent,
61
+ event?: ClipboardEvent | null,
62
62
  ): ExtendedRegExpMatchArray[] => {
63
63
  if (isRegExp(find)) {
64
64
  return [...text.matchAll(find)]
@@ -97,8 +97,8 @@ function run(config: {
97
97
  from: number
98
98
  to: number
99
99
  rule: PasteRule
100
- pasteEvent: ClipboardEvent
101
- dropEvent: DragEvent
100
+ pasteEvent: ClipboardEvent | null
101
+ dropEvent: DragEvent | null
102
102
  }): boolean {
103
103
  const {
104
104
  editor, state, from, to, rule, pasteEvent, dropEvent,
@@ -164,8 +164,8 @@ export function pasteRulesPlugin(props: { editor: Editor; rules: PasteRule[] }):
164
164
  let dragSourceElement: Element | null = null
165
165
  let isPastedFromProseMirror = false
166
166
  let isDroppedFromProseMirror = false
167
- let pasteEvent = new ClipboardEvent('paste')
168
- let dropEvent = new DragEvent('drop')
167
+ let pasteEvent = typeof ClipboardEvent !== 'undefined' ? new ClipboardEvent('paste') : null
168
+ let dropEvent = typeof DragEvent !== 'undefined' ? new DragEvent('drop') : null
169
169
 
170
170
  const plugins = rules.map(rule => {
171
171
  return new Plugin({
@@ -247,8 +247,8 @@ export function pasteRulesPlugin(props: { editor: Editor; rules: PasteRule[] }):
247
247
  return
248
248
  }
249
249
 
250
- dropEvent = new DragEvent('drop')
251
- pasteEvent = new ClipboardEvent('paste')
250
+ dropEvent = typeof DragEvent !== 'undefined' ? new DragEvent('drop') : null
251
+ pasteEvent = typeof ClipboardEvent !== 'undefined' ? new ClipboardEvent('paste') : null
252
252
 
253
253
  return tr
254
254
  },