Pass drag event to disableDropCursor #15

Merged
tslocke merged 1 commit from master into master 2022-08-07 09:47:39 +02:00
tslocke commented 2022-08-06 13:37:13 +02:00 (Migrated from github.com)

It's useful to be able to disable the drop cursor conditionally, depending on what kind of thing is being dragged. In my case I wanted to only show the block level (horizontal) drop cursor when an image file is dragged over the editor.

Passing the DragEvent makes this more symmetrical with EditorView.handleDrop.

It may be this wasn't provided in the past because browsers only provided kind/type information on drop, not during the drag, but it seems like that has changed: https://caniuse.com/mdn-api_datatransfer_items

Here's how I'm using it (on all my nodes that have text content):

disableDropCursor(editor: EditorView, pos: number, event: DragEvent) {
  const items = [...event.dataTransfer?.items ?? []]
  return items.length == 0 || !items[0].type.match(/^text\//)
}
It's useful to be able to disable the drop cursor conditionally, depending on what kind of thing is being dragged. In my case I wanted to only show the block level (horizontal) drop cursor when an image file is dragged over the editor. Passing the DragEvent makes this more symmetrical with EditorView.handleDrop. It may be this wasn't provided in the past because browsers only provided kind/type information on drop, not during the drag, but it seems like that has changed: https://caniuse.com/mdn-api_datatransfer_items Here's how I'm using it (on all my nodes that have text content): ``` disableDropCursor(editor: EditorView, pos: number, event: DragEvent) { const items = [...event.dataTransfer?.items ?? []] return items.length == 0 || !items[0].type.match(/^text\//) } ```
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
prosemirror/prosemirror-dropcursor!15
No description provided.