Add DataTransferItem and related API#55
Add DataTransferItem and related API#55thomashoneyman merged 8 commits intopurescript-web:masterfrom
Conversation
| -- | Returns the drag data item kind, which is either "string" or "file". | ||
| foreign import kind :: DataTransferItem -> String |
There was a problem hiding this comment.
An alternative here would be to create a sum type for this return value, since the spec says that it must be one of either "string" or "file". I don't know if that would be preferable.
There was a problem hiding this comment.
I think we should create a sum type if those are the two options.
There was a problem hiding this comment.
Perhaps something like DataTransferItemType = StringItem | FileItem? It's a bit ugly 🤷
There was a problem hiding this comment.
The spec calls them Text and File respectively.


https://html.spec.whatwg.org/#dom-datatransferitem-kind
https://html.spec.whatwg.org/#the-drag-data-item-kind
So my initial thought was
data DataTransferItemKind = Text | Filebut I can understand if those are too generic and we'd prefer to suffix with *Kind or *Type (or if Text is maybe an unexpected name for what has a JS value of "string"). Plenty of decisions here 😄 I'll push what I have but am open to suggestions for the naming.
There was a problem hiding this comment.
Hm, I've got this wrong actually... it can return an empty string "if the DataTransferItem object is in the disabled mode." I'll open this back up for review after I make the changes there.
There was a problem hiding this comment.
I could see suffixing them with *Kind to avoid clashes with other similar types, but I think it's also fine to assume this module will be imported qualified.
|
Sorry for the late review on this, @ptrfrncsmrph -- I have one comment, but otherwise this looks good to me. @garyb, do you have any additional thoughts? |
|
|
||
| -- | Returns a `DataTransferItemList` object which is a list of all of the drag | ||
| -- | data. | ||
| foreign import items :: DataTransfer -> DataTransferItemList |
There was a problem hiding this comment.
Remember to update the explicit exports at the top of the file so this is usable!
|
|
||
| -- | Access an item in the `DataTransferItemList` by index. | ||
| dataTransferItem :: Int -> DataTransferItemList -> Maybe DataTransferItem | ||
| dataTransferItem = map Nullable.toMaybe <$> _dataTransferItem |
There was a problem hiding this comment.
Some of these look like they need to be added to the explicit exports
thomashoneyman
left a comment
There was a problem hiding this comment.
I'd like to see if @garyb has anything he'd like to say, but this looks good from my end!
Prerequisites
purescript-webprojects. Although MDN is a great resource, it is not a suitable reference for this project.Description of the change
Fixes: #54
This would add support
DataTransfer.items(HTML spec reference here, MDN docs here)Checklist: