0 | module Web.Html
 1 |
 2 | import JS
 3 | import public Web.Internal.Types
 4 | import public Web.Raw.Html
 5 |
 6 | %default total
 7 |
 8 | --------------------------------------------------------------------------------
 9 | --          Callbacks
10 | --------------------------------------------------------------------------------
11 |
12 | export
13 | Callback BlobCallback (Maybe Blob -> JSIO ()) where
14 |   callback f = toBlobCallback $ runJS . f . nullableToMaybe
15 |
16 | export
17 | Callback CustomElementConstructor (IO HTMLElement) where
18 |   callback = toCustomElementConstructor . const
19 |
20 | export
21 | Callback EventHandlerNonNull (Event -> JSIO ()) where
22 |   callback f = toEventHandlerNonNull (map (toFFI . MkAny) . runJS . f)
23 |
24 | export
25 | Callback FunctionStringCallback (String -> JSIO ()) where
26 |   callback f = toFunctionStringCallback (runJS . f)
27 |
28 | export
29 | Callback OnBeforeUnloadEventHandlerNonNull (Event -> JSIO (Maybe String)) where
30 |   callback f = toOnBeforeUnloadEventHandlerNonNull $ map maybeToNullable
31 |                                                    . runJSWithDefault Nothing
32 |                                                    . f
33 | export
34 | Callback OnErrorEventHandlerNonNull (  HSum [Event, String]
35 |                                     -> Optional String
36 |                                     -> Optional Bits32
37 |                                     -> Optional Bits32
38 |                                     -> Optional Any
39 |                                     -> JSIO Any
40 |                                     ) where
41 |   callback f = toOnErrorEventHandlerNonNull $ \u,b,c,d,e =>
42 |     map toFFI $ runJSWithDefault (MkAny ()) $ do
43 |       ns <- tryFromFFI "JS.Html.ErrorEventHandlerNonNull.callback" u
44 |       f
45 |         ns
46 |         (undeforToOptional b)
47 |         (undeforToOptional c)
48 |         (undeforToOptional d)
49 |         (MkAny <$> undeforToOptional e)
50 |
51 | export
52 | Callback FocusEventHandler (FocusEvent -> JSIO ()) where
53 |   callback f = toFocusEventHandler (runJS . f)
54 |
55 | export
56 | Callback InputEventHandler (InputEvent -> JSIO ()) where
57 |   callback f = toInputEventHandler (runJS . f)
58 |
59 | export
60 | Callback KeyboardEventHandler (KeyboardEvent -> JSIO ()) where
61 |   callback f = toKeyboardEventHandler (runJS . f)
62 |
63 | export
64 | Callback MouseEventHandler (MouseEvent -> JSIO ()) where
65 |   callback f = toMouseEventHandler (runJS . f)
66 |
67 | export
68 | Callback UIEventHandler (UIEvent -> JSIO ()) where
69 |   callback f = toUIEventHandler (runJS . f)
70 |
71 | export
72 | Callback WheelEventHandler (WheelEvent -> JSIO ()) where
73 |   callback f = toWheelEventHandler (runJS . f)
74 |