atlassian / pragmatic-drag-and-drop

Fast drag and drop for any experience on any tech stack
https://atlassian.design/components/pragmatic-drag-and-drop
Other
9.73k stars 221 forks source link

{ source } is not ready on canDrop, onDrag in dropTargetForExternal #57

Open kieuminhcanh opened 5 months ago

kieuminhcanh commented 5 months ago

I have no way to get the value of the source to perform a comparison in the canDrop and onDrag functions.

dropTargetForExternal( {
  ...,
  canDrop: ( { source } ) => {
    console.log(source.getStringData('text/plain')) // null
  },
  onDrag( { source } ) {
    console.log(source.getStringData('text/plain')) // null
  },
  onDrop( { source } ) {
    console.log(source.getStringData('text/plain')) // {id:1}
  },
});
IanBellomy commented 5 months ago

Have a similar need dealing with json imports.

85% sure though this is a limitation of the underlying web DnD API and imagine exists, among other reasons, to prevent snoopers from reading files the user is dragging over a browser window en route to another screen destination.

That said, I’d be curious if there’s an idiomatic way for a child target to hand off drop handling after accepting the drop, reading the file content, and concluding it can’t be handled at that level after all.

alexreardon commented 5 months ago

👋 source.items and source.getStringData is will only return populated data in onDrop(). Before then, all you have access to is .types.