Skip to content

Commit f62b947

Browse files
authored
fix: ignore drag & drop from unrelated events #1968 (#2346)
If an event is not from the current blocknote editor, or coming from another blocknote editor on the page, we should not be capturing that event.
1 parent 23eecbb commit f62b947

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

packages/core/src/extensions/SideMenu/SideMenu.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,20 @@ export class SideMenuView<
380380
return;
381381
}
382382

383+
// Relevance gate: Only handle drags that belong to BlockNote
384+
// This prevents interference with external drag-and-drop libraries
385+
// by avoiding calls to closeDropCursor() for non-BlockNote drags
386+
const isBlockNoteDrag =
387+
this.pmView.dragging !== null ||
388+
this.isDragOrigin ||
389+
event.dataTransfer?.types.includes("blocknote/html") ||
390+
(event.target instanceof Node && this.pmView.dom.contains(event.target));
391+
392+
if (!isBlockNoteDrag) {
393+
// Not a BlockNote-related drag, return early without any processing
394+
return;
395+
}
396+
383397
const dragEventContext = this.getDragEventContext(event);
384398

385399
if (!dragEventContext || !dragEventContext.isDropPoint) {
@@ -419,6 +433,23 @@ export class SideMenuView<
419433
* - Whether the drop event is within the bounds of the current editor instance
420434
*/
421435
getDragEventContext = (event: DragEvent) => {
436+
// Relevance gate: Only handle drags that belong to BlockNote
437+
// Check if at least one of the following is true:
438+
// 1. ProseMirror drag started in an editor
439+
// 2. Side menu drag
440+
// 3. BlockNote-specific data type in the drag
441+
// 4. (optional stricter mode) Event target is inside this editor
442+
const isBlockNoteDrag =
443+
this.pmView.dragging !== null ||
444+
this.isDragOrigin ||
445+
event.dataTransfer?.types.includes("blocknote/html") ||
446+
(event.target instanceof Node && this.pmView.dom.contains(event.target));
447+
448+
if (!isBlockNoteDrag) {
449+
// Not a BlockNote-related drag, return early
450+
return undefined;
451+
}
452+
422453
// We need to check if there is text content that is being dragged (select some text & just drag it)
423454
const textContentIsBeingDragged =
424455
!event.dataTransfer?.types.includes("blocknote/html") &&
@@ -477,6 +508,19 @@ export class SideMenuView<
477508
return;
478509
}
479510

511+
// Relevance gate: Only handle drags that belong to BlockNote
512+
// This prevents interference with external drag-and-drop libraries
513+
const isBlockNoteDrag =
514+
this.pmView.dragging !== null ||
515+
this.isDragOrigin ||
516+
event.dataTransfer?.types.includes("blocknote/html") ||
517+
(event.target instanceof Node && this.pmView.dom.contains(event.target));
518+
519+
if (!isBlockNoteDrag) {
520+
// Not a BlockNote-related drag, return early without any processing
521+
return;
522+
}
523+
480524
const context = this.getDragEventContext(event);
481525
if (!context) {
482526
this.closeDropCursor();

0 commit comments

Comments
 (0)