-
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
Merged
thomashoneyman
merged 8 commits into
purescript-web:master
from
pete-murphy:pm/add-data-transfer-api
Oct 8, 2021
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
661e7fe
Add DataTransferItem and related API
pete-murphy 8e71271
Add to CHANGELOG
pete-murphy 8f56ac6
Merge branch 'master' into pm/add-data-transfer-api
thomashoneyman 25a14aa
Merge branch 'purescript-web:master' into master
pete-murphy c52f03f
Make kind a sum type, add to exports
pete-murphy 76291c7
Merge branch 'master' into pm/add-data-transfer-api
pete-murphy 4870dd4
Order foreign imports first
pete-murphy 879e724
Update `kind` to return `Maybe`
pete-murphy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"use strict"; | ||
|
||
exports._kind = function (nothing, just, text, file, dataTransferItem) { | ||
if (dataTransferItem.kind === "string") { | ||
return just(text); | ||
} else if (dataTransferItem.kind === "file") { | ||
return just(file); | ||
} else { | ||
return nothing; | ||
} | ||
}; | ||
|
||
exports.type_ = function (dataTransferItem) { | ||
return dataTransferItem.type; | ||
}; | ||
|
||
exports._dataTransferItem = function (index) { | ||
return function (dataTransferItemList) { | ||
return dataTransferItemList[index]; | ||
}; | ||
}; | ||
|
||
exports._length = function (dataTransferItemList) { | ||
return dataTransferItemList.length; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
module Web.HTML.Event.DataTransfer.DataTransferItem | ||
( DataTransferItem | ||
, DataTransferItemKind(..) | ||
, DataTransferItemList | ||
, dataTransferItem | ||
, kind | ||
, length | ||
, type_ | ||
) where | ||
|
||
import Prelude | ||
|
||
import Data.Function.Uncurried (Fn5) | ||
import Data.Function.Uncurried as Uncurried | ||
import Data.Maybe (Maybe(..)) | ||
import Data.Nullable (Nullable) | ||
import Data.Nullable as Nullable | ||
|
||
data DataTransferItemKind = Text | File | ||
|
||
derive instance Eq DataTransferItemKind | ||
derive instance Ord DataTransferItemKind | ||
|
||
instance Show DataTransferItemKind where | ||
show = case _ of | ||
Text -> "Text" | ||
File -> "File" | ||
|
||
foreign import _kind | ||
:: Fn5 (forall x. Maybe x) | ||
(forall x. x -> Maybe x) | ||
DataTransferItemKind | ||
DataTransferItemKind | ||
DataTransferItem | ||
(Maybe DataTransferItemKind) | ||
|
||
-- | Returns the drag data item kind of the `DataTransferItem`. In the case | ||
-- | where the `DataTransferItem` object is in _disabled mode_, `Nothing` is | ||
-- | returned. | ||
kind :: DataTransferItem -> Maybe DataTransferItemKind | ||
kind = Uncurried.runFn5 _kind Nothing Just Text File | ||
|
||
-- | 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 | ||
|
||
foreign import _dataTransferItem :: Int -> DataTransferItemList -> Nullable DataTransferItem | ||
|
||
-- | 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 _length :: DataTransferItemList -> Int | ||
|
||
length :: DataTransferItemList -> Int | ||
length = _length | ||
|
||
foreign import data DataTransferItem :: Type | ||
|
||
foreign import data DataTransferItemList :: Type |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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!