mharris717 / ember-drag-drop

Drag and Drop Addon for Ember CLI
MIT License
204 stars 141 forks source link

only allow specific object to be dropped #157

Open pc386 opened 5 years ago

pc386 commented 5 years ago

Right now a user can drop anything into draggable-object-target, for example text or an image. Is there a way to check for this? So that only the things I allow can be dropped?

edit: I found an easy solution to my problem. I defined a property which is changed by dragStartHook/dragEndHook. And then I encapsuled my drop target in an if with the property, so only when I start dragging my object it actually enables the drop field

nruth commented 4 years ago

The trouble is with https://github.com/mharris717/ember-drag-drop/blame/a58318b39d9929d1438833fac87d057eb0529216/app/models/obj-hash.js#L24

If you select a few words of text from somewhere on the page on a Mac you're able to drag it into other apps and so on. If you drop it into the dropzone provided by this addon it triggers the above code with the selected text as the key, and throws the no obj for key string (not an Error, which makes debugging harder – #173).

My suggestion here is to change the default behaviour from throw-a-string to halt execution. Maybe just change the thrown string to a custom error object and catch it higher up.

This would be nice, as currently Bugsnag reports a new issue for every unexpected item dragged into the dropzone.

miguelcobain commented 3 years ago

This is an issue for us as well. I was expecting that only <DraggableObject>s could be dragged into <DraggableObjectTarget>s.

Perhaps we could use detect some special data in the DataTransfer to validate the event on the DraggableObjectTarget component.