Skip to content

Commit

Permalink
fix: typecheck drag and clipboard events for testing environments
Browse files Browse the repository at this point in the history
  • Loading branch information
bdbch committed Feb 23, 2024
1 parent a863e1c commit bbee9a3
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions packages/core/src/PasteRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export type PasteRuleMatch = {
data?: Record<string, any>
}

export type PasteRuleFinder = RegExp | ((text: string, event?: ClipboardEvent) => PasteRuleMatch[] | null | undefined)
export type PasteRuleFinder = RegExp | ((text: string, event?: ClipboardEvent | null) => PasteRuleMatch[] | null | undefined)

export class PasteRule {
find: PasteRuleFinder
Expand All @@ -33,8 +33,8 @@ export class PasteRule {
commands: SingleCommands
chain: () => ChainedCommands
can: () => CanCommands
pasteEvent: ClipboardEvent
dropEvent: DragEvent
pasteEvent: ClipboardEvent | null
dropEvent: DragEvent | null
}) => void | null

constructor(config: {
Expand All @@ -43,9 +43,9 @@ export class PasteRule {
can: () => CanCommands
chain: () => ChainedCommands
commands: SingleCommands
dropEvent: DragEvent
dropEvent: DragEvent | null
match: ExtendedRegExpMatchArray
pasteEvent: ClipboardEvent
pasteEvent: ClipboardEvent | null
range: Range
state: EditorState
}) => void | null
Expand All @@ -58,7 +58,7 @@ export class PasteRule {
const pasteRuleMatcherHandler = (
text: string,
find: PasteRuleFinder,
event?: ClipboardEvent,
event?: ClipboardEvent | null,
): ExtendedRegExpMatchArray[] => {
if (isRegExp(find)) {
return [...text.matchAll(find)]
Expand Down Expand Up @@ -97,8 +97,8 @@ function run(config: {
from: number
to: number
rule: PasteRule
pasteEvent: ClipboardEvent
dropEvent: DragEvent
pasteEvent: ClipboardEvent | null
dropEvent: DragEvent | null
}): boolean {
const {
editor, state, from, to, rule, pasteEvent, dropEvent,
Expand Down Expand Up @@ -164,8 +164,8 @@ export function pasteRulesPlugin(props: { editor: Editor; rules: PasteRule[] }):
let dragSourceElement: Element | null = null
let isPastedFromProseMirror = false
let isDroppedFromProseMirror = false
let pasteEvent = new ClipboardEvent('paste')
let dropEvent = new DragEvent('drop')
let pasteEvent = typeof ClipboardEvent !== 'undefined' ? new ClipboardEvent('paste') : null
let dropEvent = typeof DragEvent !== 'undefined' ? new DragEvent('drop') : null

const plugins = rules.map(rule => {
return new Plugin({
Expand Down Expand Up @@ -247,8 +247,8 @@ export function pasteRulesPlugin(props: { editor: Editor; rules: PasteRule[] }):
return
}

dropEvent = new DragEvent('drop')
pasteEvent = new ClipboardEvent('paste')
dropEvent = typeof DragEvent !== 'undefined' ? new DragEvent('drop') : null
pasteEvent = typeof ClipboardEvent !== 'undefined' ? new ClipboardEvent('paste') : null

return tr
},
Expand Down

0 comments on commit bbee9a3

Please sign in to comment.