-
Notifications
You must be signed in to change notification settings - Fork 24
Add DataTransferItem and related API #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
661e7fe
8e71271
8f56ac6
25a14aa
c52f03f
76291c7
4870dd4
879e724
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
"use strict"; | ||
|
||
exports.kind = function (dataTransferItem) { | ||
return dataTransferItem.kind; | ||
}; | ||
|
||
exports.type_ = function (dataTransferItem) { | ||
return dataTransferItem.type; | ||
}; | ||
|
||
exports._dataTransferItem = function (index) { | ||
return function (dataTransferItemList) { | ||
return dataTransferItemList[index]; | ||
}; | ||
}; | ||
|
||
exports._length = function (dataTransferItemList) { | ||
return dataTransferItemList.length; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Web.HTML.Event.DataTransfer.DataTransferItem | ||
( DataTransferItem | ||
, DataTransferItemList | ||
) where | ||
|
||
import Prelude | ||
import Data.Maybe (Maybe) | ||
import Data.Nullable (Nullable) | ||
import Data.Nullable as Nullable | ||
|
||
-- | Returns the drag data item kind, which is either "string" or "file". | ||
foreign import kind :: DataTransferItem -> String | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should create a sum type if those are the two options. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The spec calls them Text and File respectively. https://html.spec.whatwg.org/#dom-datatransferitem-kind So my initial thought was data DataTransferItemKind = Text | File but I can understand if those are too generic and we'd prefer to suffix with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, I've got this wrong actually... it can return an empty string "if the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated here 879e724 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could see suffixing them with |
||
|
||
-- | A Unicode string giving the type or format of the data, generally given by | ||
-- | a MIME type. Some values that are not MIME types are special-cased for | ||
-- | legacy reasons. The API does not enforce the use of MIME types; other | ||
-- | values can be used as well. In all cases, however, the values are all | ||
-- | converted to ASCII lowercase by the API. | ||
-- | There is a limit of one text item per item type string. | ||
foreign import type_ :: DataTransferItem -> String | ||
|
||
-- | 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some of these look like they need to be added to the explicit exports |
||
|
||
foreign import _dataTransferItem :: Int -> DataTransferItemList -> Nullable DataTransferItem | ||
|
||
length :: DataTransferItemList -> Int | ||
length = _length | ||
|
||
foreign import _length :: DataTransferItemList -> Int | ||
|
||
foreign import data DataTransferItem :: Type | ||
|
||
foreign import data DataTransferItemList :: Type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember to update the explicit exports at the top of the file so this is usable!