on develop help sign in
Revert "Eliminate GhcjsDomSpace requirements for TextInputs, RangeInputs, and TextAreas"

This reverts commit 75747f8722bfe30c1238a87d3a39a7d407153eb7.

commit4d95d05472269b7dc65e0faa40fa4fd72a3abd92 authorRyan Trinkle <ryan.trinkle@gmail.com> dateMon 15 Aug 2016, 16:22 (10 years ago) parent75747f8
1 file changed+19−17
src/Reflex/Dom/Widget/Input.hs+19−17
src/Reflex/Dom/Widget/Input.hs+19−17
@@ -34,8 +34,10 @@ import GHCJS.DOM.Element (castToElement)
3434import qualified GHCJS.DOM.Element as Element
3535import GHCJS.DOM.EventM (on)
3636import qualified GHCJS.DOM.FileList as FileList
37+import GHCJS.DOM.HTMLInputElement (HTMLInputElement, castToHTMLInputElement)
3738import GHCJS.DOM.HTMLSelectElement (castToHTMLSelectElement)
3839import qualified GHCJS.DOM.HTMLSelectElement as HTMLSelectElement
40+import GHCJS.DOM.HTMLTextAreaElement (HTMLTextAreaElement, castToHTMLTextAreaElement)
3941import GHCJS.DOM.Types (File)
4042import Reflex.Class
4143import Reflex.Dynamic
@@ -50,14 +52,14 @@ import qualified Text.Read as T
5052import qualified GHCJS.DOM.Event as Event
5153import qualified GHCJS.DOM.HTMLInputElement as Input
5254
53−data TextInput d t
55+data TextInput t
5456 = TextInput { _textInput_value :: Dynamic t Text
5557 , _textInput_input :: Event t Text
5658 , _textInput_keypress :: Event t Int
5759 , _textInput_keydown :: Event t Int
5860 , _textInput_keyup :: Event t Int
5961 , _textInput_hasFocus :: Dynamic t Bool
60− , _textInput_element :: RawElement d
62+ , _textInput_element :: HTMLInputElement
6163 }
6264
6365data TextInputConfig t
@@ -77,7 +79,7 @@ instance Reflex t => Default (TextInputConfig t) where
7779
7880-- | Create an input whose value is a string. By default, the "type" attribute is set to "text", but it can be changed using the _textInputConfig_inputType field. Note that only types for which the value is always a string will work - types whose value may be null will not work properly with this widget.
7981{-# INLINABLE textInput #-}
80−textInput :: (DomBuilder t m, PostBuild t m) => TextInputConfig t -> m (TextInput (DomBuilderSpace m) t)
82+textInput :: (DomBuilder t m, PostBuild t m, DomBuilderSpace m ~ GhcjsDomSpace) => TextInputConfig t -> m (TextInput t)
8183textInput (TextInputConfig inputType initial eSetValue dAttrs) = do
8284 modifyAttrs <- dynamicAttributesToModifyAttributes $ fmap (Map.insert "type" inputType) dAttrs
8385 i <- inputElement $ def
@@ -91,11 +93,11 @@ textInput (TextInputConfig inputType initial eSetValue dAttrs) = do
9193 , _textInput_keydown = domEvent Keydown i
9294 , _textInput_keyup = domEvent Keyup i
9395 , _textInput_hasFocus = _inputElement_hasFocus i
94− , _textInput_element = _element_raw $ _inputElement_element i
96+ , _textInput_element = castToHTMLInputElement $ _element_raw $ _inputElement_element i
9597 }
9698
9799{-# INLINABLE textInputGetEnter #-}
98−textInputGetEnter :: Reflex t => TextInput d t -> Event t ()
100+textInputGetEnter :: Reflex t => TextInput t -> Event t ()
99101textInputGetEnter i = fmapMaybe (\n -> if keyCodeLookup n == Enter then Just () else Nothing) $ _textInput_keypress i
100102
101103data RangeInputConfig t
@@ -111,18 +113,18 @@ instance Reflex t => Default (RangeInputConfig t) where
111113 , _rangeInputConfig_attributes = constDyn mempty
112114 }
113115
114−data RangeInput d t
116+data RangeInput t
115117 = RangeInput { _rangeInput_value :: Dynamic t Float
116118 , _rangeInput_input :: Event t Float
117119 , _rangeInput_mouseup :: Event t (Int, Int)
118120 , _rangeInput_hasFocus :: Dynamic t Bool
119− , _rangeInput_element :: RawInputElement d
121+ , _rangeInput_element :: HTMLInputElement
120122 }
121123
122124-- | Create an input whose value is a float.
123125-- https://www.w3.org/wiki/HTML/Elements/input/range
124126{-# INLINABLE rangeInput #-}
125−rangeInput :: (DomBuilder t m, PostBuild t m) => RangeInputConfig t -> m (RangeInput (DomBuilderSpace m) t)
127+rangeInput :: (DomBuilder t m, PostBuild t m, DomBuilderSpace m ~ GhcjsDomSpace) => RangeInputConfig t -> m (RangeInput t)
126128rangeInput (RangeInputConfig initial eSetValue dAttrs) = do
127129 modifyAttrs <- dynamicAttributesToModifyAttributes $ fmap (Map.insert "type" "range") dAttrs
128130 i <- inputElement $ def
@@ -134,7 +136,7 @@ rangeInput (RangeInputConfig initial eSetValue dAttrs) = do
134136 , _rangeInput_input = read . T.unpack <$> _inputElement_input i
135137 , _rangeInput_mouseup = domEvent Mouseup i
136138 , _rangeInput_hasFocus = _inputElement_hasFocus i
137− , _rangeInput_element = _inputElement_raw i
139+ , _rangeInput_element = castToHTMLInputElement $ _element_raw $ _inputElement_element i
138140 }
139141
140142data TextAreaConfig t
@@ -150,16 +152,16 @@ instance Reflex t => Default (TextAreaConfig t) where
150152 , _textAreaConfig_attributes = constDyn mempty
151153 }
152154
153−data TextArea d t
155+data TextArea t
154156 = TextArea { _textArea_value :: Dynamic t Text
155157 , _textArea_input :: Event t Text
156158 , _textArea_hasFocus :: Dynamic t Bool
157159 , _textArea_keypress :: Event t Int
158− , _textArea_element :: RawTextAreaElement d
160+ , _textArea_element :: HTMLTextAreaElement
159161 }
160162
161163{-# INLINABLE textArea #-}
162−textArea :: (DomBuilder t m, PostBuild t m) => TextAreaConfig t -> m (TextArea (DomBuilderSpace m) t)
164+textArea :: (DomBuilder t m, PostBuild t m, DomBuilderSpace m ~ GhcjsDomSpace) => TextAreaConfig t -> m (TextArea t)
163165textArea (TextAreaConfig initial eSet attrs) = do
164166 modifyAttrs <- dynamicAttributesToModifyAttributes attrs
165167 i <- textAreaElement $ def
@@ -171,7 +173,7 @@ textArea (TextAreaConfig initial eSet attrs) = do
171173 , _textArea_input = _textAreaElement_input i
172174 , _textArea_keypress = domEvent Keypress i
173175 , _textArea_hasFocus = _textAreaElement_hasFocus i
174− , _textArea_element = _textAreaElement_raw i
176+ , _textArea_element = castToHTMLTextAreaElement $ _element_raw $ _textAreaElement_element i
175177 }
176178
177179data CheckboxConfig t
@@ -513,12 +515,12 @@ class HasValue a where
513515 type Value a :: *
514516 value :: a -> Value a
515517
516−instance HasValue (TextArea d t) where
517− type Value (TextArea d t) = Dynamic t Text
518+instance HasValue (TextArea t) where
519+ type Value (TextArea t) = Dynamic t Text
518520 value = _textArea_value
519521
520−instance HasValue (TextInput d t) where
521− type Value (TextInput d t) = Dynamic t Text
522+instance HasValue (TextInput t) where
523+ type Value (TextInput t) = Dynamic t Text
522524 value = _textInput_value
523525
524526instance HasValue (FileInput d t) where