@@ -8,16 +8,13 @@ import Effect (Effect)
8
8
import Effect.Exception as Exception
9
9
import React.Basic.DOM as R
10
10
import React.Basic.DOM.Events as DOM.Events
11
- import React.Basic.Events (SyntheticEvent )
12
11
import React.Basic.Events as Events
13
12
import React.Basic.Hooks (Component , (/\))
14
13
import React.Basic.Hooks as React
15
- import Unsafe.Coerce as Coerce
16
14
import Web.File.File as File
17
15
import Web.File.FileList as FileList
18
16
import Web.HTML as HTML
19
17
import Web.HTML.Event.DataTransfer as DataTransfer
20
- import Web.HTML.Event.DragEvent (DragEvent )
21
18
import Web.HTML.Event.DragEvent as DragEvent
22
19
import Web.HTML.HTMLDocument as HTMLDocument
23
20
import Web.HTML.HTMLElement as HTMLElement
@@ -71,10 +68,10 @@ mkApp = do
71
68
Events .handler DOM.Events .preventDefault \_ -> do
72
69
setHover true
73
70
, onDrop:
74
- Events .handler DOM.Events .preventDefault \e -> do
71
+ Events .handler ( DOM.Events .preventDefault >>> DOM.Events .nativeEvent) \e -> do
75
72
setHover false
76
73
let
77
- maybeFileList = DataTransfer .files ( DragEvent .dataTransfer (toDragEvent e))
74
+ maybeFileList = DataTransfer .files =<< DragEvent .dataTransfer <$> DragEvent .fromEvent e
78
75
Foldable .for_ (FileList .items <$> maybeFileList) (setFiles <<< (<>))
79
76
, children:
80
77
[ R .button
@@ -109,16 +106,3 @@ mkApp = do
109
106
}
110
107
]
111
108
}
112
-
113
- -- | We happen to know that we're dealing with a `DragEvent` where we're using this, but
114
- -- | not every `SyntheticEvent` can be converted to a `DragEvent`, so this is a partial
115
- -- | function. A proper implementation of this would probably be typed
116
- -- |
117
- -- | ```purs
118
- -- | toDragEvent :: SyntheticEvent -> Maybe DragEvent
119
- -- | ```
120
- -- |
121
- -- | and could use `Web.Internal.FFI.unsafeReadProtoTagged` to inspect the constructor
122
- -- | of the event and verify that it is indeed a `DragEvent`.
123
- toDragEvent :: SyntheticEvent -> DragEvent
124
- toDragEvent = Coerce .unsafeCoerce
0 commit comments