|
| 1 | +module Web.HTML.Event.DataTransfer.DataTransferItem |
| 2 | + ( DataTransferItem |
| 3 | + , DataTransferItemKind(..) |
| 4 | + , DataTransferItemList |
| 5 | + , dataTransferItem |
| 6 | + , kind |
| 7 | + , length |
| 8 | + , type_ |
| 9 | + ) where |
| 10 | + |
| 11 | +import Prelude |
| 12 | + |
| 13 | +import Data.Function.Uncurried (Fn5) |
| 14 | +import Data.Function.Uncurried as Uncurried |
| 15 | +import Data.Maybe (Maybe(..)) |
| 16 | +import Data.Nullable (Nullable) |
| 17 | +import Data.Nullable as Nullable |
| 18 | + |
| 19 | +data DataTransferItemKind = Text | File |
| 20 | + |
| 21 | +derive instance Eq DataTransferItemKind |
| 22 | +derive instance Ord DataTransferItemKind |
| 23 | + |
| 24 | +instance Show DataTransferItemKind where |
| 25 | + show = case _ of |
| 26 | + Text -> "Text" |
| 27 | + File -> "File" |
| 28 | + |
| 29 | +foreign import _kind |
| 30 | + :: Fn5 (forall x. Maybe x) |
| 31 | + (forall x. x -> Maybe x) |
| 32 | + DataTransferItemKind |
| 33 | + DataTransferItemKind |
| 34 | + DataTransferItem |
| 35 | + (Maybe DataTransferItemKind) |
| 36 | + |
| 37 | +-- | Returns the drag data item kind of the `DataTransferItem`. In the case |
| 38 | +-- | where the `DataTransferItem` object is in _disabled mode_, `Nothing` is |
| 39 | +-- | returned. |
| 40 | +kind :: DataTransferItem -> Maybe DataTransferItemKind |
| 41 | +kind = Uncurried.runFn5 _kind Nothing Just Text File |
| 42 | + |
| 43 | +-- | A Unicode string giving the type or format of the data, generally given by |
| 44 | +-- | a MIME type. Some values that are not MIME types are special-cased for |
| 45 | +-- | legacy reasons. The API does not enforce the use of MIME types; other |
| 46 | +-- | values can be used as well. In all cases, however, the values are all |
| 47 | +-- | converted to ASCII lowercase by the API. |
| 48 | +-- | There is a limit of one text item per item type string. |
| 49 | +foreign import type_ :: DataTransferItem -> String |
| 50 | + |
| 51 | +foreign import _dataTransferItem :: Int -> DataTransferItemList -> Nullable DataTransferItem |
| 52 | + |
| 53 | +-- | Access an item in the `DataTransferItemList` by index. |
| 54 | +dataTransferItem :: Int -> DataTransferItemList -> Maybe DataTransferItem |
| 55 | +dataTransferItem = map Nullable.toMaybe <$> _dataTransferItem |
| 56 | + |
| 57 | +foreign import _length :: DataTransferItemList -> Int |
| 58 | + |
| 59 | +length :: DataTransferItemList -> Int |
| 60 | +length = _length |
| 61 | + |
| 62 | +foreign import data DataTransferItem :: Type |
| 63 | + |
| 64 | +foreign import data DataTransferItemList :: Type |
0 commit comments