ProseMirror / prosemirror

The ProseMirror WYSIWYM editor
http://prosemirror.net/
MIT License
7.53k stars 334 forks source link

`clearData` cause `event.dataTransfer.files` empty when dragging a image element #1472

Closed fantasticit closed 1 month ago

fantasticit commented 1 month ago

https://github.com/ProseMirror/prosemirror-view/blob/e8bcd75d305b42052c4bd17653374d670b6f17d3/src/input.ts#L680

event.dataTransfer.files will be empty when dragging a image element in old chrome (version <= 120), because of the invoke of event.dataTransfer.clearData().

The event.dataTransfer.clearData is changed at chrome 125 and then event.dataTransfer.files will not be empty.

To fix this issues in old chrome version, maybe we need change event.dataTransfer.clearData() to !event.dataTransfer.files.length && event.dataTransfer.clearData().

marijnh commented 1 month ago

If you are dragging from editor content, how would there be files in the event's data transfer?

fantasticit commented 1 month ago

drag a image node like <img src="http://" draggable="true" /> in non-editbale pm editor, then drop at another webpage. event.dataTransfer.files has files in chrome 125.

fantasticit commented 1 month ago
  1. upload image at https://prosemirror.net/examples/upload/
  2. drag and drop the image at https://evercoder.github.io/clipboard-inspector/
marijnh commented 1 month ago

Oh cool, I didn't know it did that. But isn't Chrome 120 old enough that, given that browser's automatic upgrade behavior, it's not really a problem anymore?

fantasticit commented 1 month ago

Due to various reasons (such as political reasons), in some countries or regions, the browser kernels of users on various platforms may not be updated in a timely manner (often for a long time), which may lead to problems for these users dragging content to other web pages. In addition, many browser products are shell Google kernels and are rarely updated in a timely manner.

marijnh commented 1 month ago

Fair enough. Attached patch suppresses that call on old Chrome versions.