0 | ||| A `Source` is a monadic streaming function that produces
  1 | ||| values independently of the input value.
  2 | module Rhone.JS.Source
  3 |
  4 | import Data.MSF
  5 | import JS
  6 | import Rhone.JS.ElemRef
  7 | import Text.Html
  8 | import Web.Dom
  9 | import Web.Html
 10 |
 11 | %default total
 12 |
 13 | --------------------------------------------------------------------------------
 14 | --          Value
 15 | --------------------------------------------------------------------------------
 16 |
 17 | public export
 18 | interface SafeCast t => HasValue t where
 19 |   getValue : t -> JSIO String
 20 |
 21 | public export
 22 | HasValue HTMLButtonElement where
 23 |   getValue = to value
 24 |
 25 | public export
 26 | HasValue HTMLDataElement where
 27 |   getValue = to value
 28 |
 29 | public export
 30 | HasValue HTMLInputElement where
 31 |   getValue = to value
 32 |
 33 | public export
 34 | HasValue HTMLOptionElement where
 35 |   getValue = to value
 36 |
 37 | public export
 38 | HasValue HTMLOutputElement where
 39 |   getValue = to value
 40 |
 41 | public export
 42 | HasValue HTMLParamElement where
 43 |   getValue = to value
 44 |
 45 | public export
 46 | HasValue HTMLSelectElement where
 47 |   getValue = to value
 48 |
 49 | public export
 50 | HasValue HTMLTextAreaElement where
 51 |   getValue = to value
 52 |
 53 | public export
 54 | HasValue RadioNodeList where
 55 |   getValue = to value
 56 |
 57 | export
 58 | value : HasValue t => MSF JSIO (ElemRef t) String
 59 | value = arrM $ \r => getElementByRef r >>= getValue
 60 |
 61 | export %inline
 62 | valueOf : HasValue t => ElemRef t -> MSF JSIO i String
 63 | valueOf r = const r >>> value
 64 |
 65 | export
 66 | meterValue : MSF JSIO (ElemRef HTMLMeterElement) Double
 67 | meterValue = arrM $ \r => getElementByRef r >>= to value
 68 |
 69 | export %inline
 70 | meterValueOf : ElemRef HTMLMeterElement -> MSF JSIO i Double
 71 | meterValueOf r = const r >>> meterValue
 72 |
 73 | export
 74 | progressValue : MSF JSIO (ElemRef HTMLProgressElement) Double
 75 | progressValue = arrM $ \r => getElementByRef r >>= to value
 76 |
 77 | export %inline
 78 | progressValueOf : ElemRef HTMLProgressElement -> MSF JSIO i Double
 79 | progressValueOf r = const r >>> progressValue
 80 |
 81 | --------------------------------------------------------------------------------
 82 | --          Checked
 83 | --------------------------------------------------------------------------------
 84 |
 85 | export
 86 | getChecked : HTMLInputElement -> JSIO Bool
 87 | getChecked el = get el checked
 88 |
 89 | export
 90 | checked : MSF JSIO (ElemRef HTMLInputElement) Bool
 91 | checked = arrM getElementByRef >>! getChecked
 92 |
 93 | export %inline
 94 | checkedAt : ElemRef HTMLInputElement -> MSF JSIO i Bool
 95 | checkedAt r = const r >>> checked
 96 |
 97 | --------------------------------------------------------------------------------
 98 | --          Routing
 99 | --------------------------------------------------------------------------------
100 |
101 | export
102 | windowLocation : MSF JSIO i Location
103 | windowLocation = constM $ window >>= location
104 |
105 | export
106 | windowHash : MSF JSIO i String
107 | windowHash = windowLocation >>! to Location.hash
108 |