on develop help sign in
Merge branch 'develop' into textAreaElementHasSetValue
commitb5e2c31423f63d7d3100c1001a24838d95d2f202 authorAli Abrar <aliabrar@gmail.com> dateFri 6 Nov 2020, 10:05 (6 years ago) parentb9d7914ddf8977
33 files changed+574−326
LICENSE+12 README.md+9−9 cabal.project+1 chrome-test-utils/LICENSE+1−1 chrome-test-utils/chrome-test-utils.cabal+1−1 chrome-test-utils/src/Test/Util/UnshareNetwork.hs+2−2 dep/reflex-platform/github.json+3−3 reflex-dom-core/ChangeLog.md+46−15 reflex-dom-core/LICENSE+1−1 reflex-dom-core/reflex-dom-core.cabal+33−21 reflex-dom-core/src/Reflex/Dom/Builder/Class.hs+1−1 reflex-dom-core/src/Reflex/Dom/Builder/Class/Events.hs+13−2 reflex-dom-core/src/Reflex/Dom/Builder/Hydratable.hs+4−4 reflex-dom-core/src/Reflex/Dom/Builder/Immediate.hs+91−43 reflex-dom-core/src/Reflex/Dom/Builder/Static.hs+12−9 reflex-dom-core/src/Reflex/Dom/Class.hs+4−7 reflex-dom-core/src/Reflex/Dom/Prerender.hs+5−3 reflex-dom-core/src/Reflex/Dom/Widget/Basic.hs−7 reflex-dom-core/src/Reflex/Dom/Widget/Input.hs+4−1 reflex-dom-core/src/Reflex/Dom/Widget/Resize.hs+4−4 reflex-dom-core/src/Reflex/Dom/Xhr.hs+8−6 reflex-dom-core/src/Reflex/Dom/Xhr/Foreign.hs+2−2 reflex-dom-core/test/gc.hs+1−1 reflex-dom-core/test/hydration.hs+128−29 reflex-dom/ChangeLog.md+13 reflex-dom/LICENSE+1−1 reflex-dom/benchmark.hs+2−1 reflex-dom/reflex-dom.cabal+72−21 reflex-dom/src/Reflex/Dom/Internal.hs+5 release.nix+13−4 test/default.nix+10 test/prebuild.hs−127 test/reflex-dom-reexports.hs+72
LICENSEnew file+12
@@ -0,0 +1,12 @@
1+Copyright (c) 2020, Obsidian Systems LLC
2+All rights reserved.
3+
4+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5+
6+1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7+
8+2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9+
10+3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11+
12+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
README.md+9−9
@@ -1,21 +1,21 @@
11## [Reflex-DOM](https://reflex-frp.org)
22
3−[![Hackage](https://img.shields.io/hackage/v/reflex-dom.svg)](http://hackage.haskell.org/package/reflex-dom)
3+[![Haskell](https://img.shields.io/badge/language-Haskell-orange.svg)](https://haskell.org) [![Hackage](https://img.shields.io/hackage/v/reflex-dom.svg)](https://hackage.haskell.org/package/reflex-dom) [![Hackage CI](https://matrix.hackage.haskell.org/api/v2/packages/reflex-dom/badge)](https://matrix.hackage.haskell.org/#/package/reflex-dom) [![BSD3 License](https://img.shields.io/badge/license-BSD3-blue.svg)](https://github.com/reflex-frp/reflex-dom/blob/master/LICENSE)
44
5−### A Framework for Functional Reactive Web Apps in Haskell
5+Web applications without callbacks or side-effects. Reflex-DOM brings the power of [Functional Reactive Programming (FRP)](https://wiki.haskell.org/Functional_Reactive_Programming) to the web. Build [HTML](https://developer.mozilla.org/en-US/docs/Web/HTML) and other [Document Object Model (DOM)](https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model) data with a pure functional interface.
66
7−Reflex-DOM is a framework for building web applications in Haskell, based on the [Functional Reactive Programming](https://wiki.haskell.org/Functional_Reactive_Programming) library [Reflex](https://github.com/reflex-frp/reflex).
8−
9−A summary of Reflex-DOM functions is available in the [quick reference](Quickref.md).
7+Reflex-DOM is a framework for building web applications in [Haskell](https://www.haskell.org/), based on the [Functional Reactive Programming](https://wiki.haskell.org/Functional_Reactive_Programming) library [Reflex](https://github.com/reflex-frp/reflex).
108
119**Visit https://reflex-frp.org/ for more information, tutorials, documentation and [examples](https://examples.reflex-frp.org/).**
1210
1311### Additional resources
14−[Get started with Reflex](https://github.com/reflex-frp/reflex-platform)
15−
16−[/r/reflexfrp](https://www.reddit.com/r/reflexfrp)
1712
18−[irc.freenode.net #reflex-frp](http://webchat.freenode.net?channels=%23reflex-frp&uio=d4)
13+* [Official Website](https://reflex-frp.org/)
14+* [Quick Reference](Quickref.md)
15+* [Obelisk](https://github.com/obsidiansystems/obelisk#obelisk): A framework built on Reflex and Reflex-DOM for functional reactive web and mobile applications, with batteries included.
16+* [Get started with Reflex](https://github.com/reflex-frp/reflex-platform)
17+* [/r/reflexfrp](https://www.reddit.com/r/reflexfrp)
18+* [irc.freenode.net #reflex-frp](http://webchat.freenode.net?channels=%23reflex-frp&uio=d4)
1919
2020### Hacking
2121
cabal.projectnew file+1
@@ -0,0 +1 @@
1+packages: reflex-dom-core, reflex-dom
chrome-test-utils/LICENSE+1−1
@@ -1,4 +1,4 @@
1−Copyright (c) 2019, Obsidian Systems LLC
1+Copyright (c) 2020, Obsidian Systems LLC
22All rights reserved.
33
44Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
chrome-test-utils/chrome-test-utils.cabal+1−1
@@ -1,5 +1,5 @@
11Name: chrome-test-utils
2−Version: 0.4
2+Version: 0.5
33Synopsis: Utilities to write headless Chromium tests
44License: BSD3
55License-file: LICENSE
chrome-test-utils/src/Test/Util/UnshareNetwork.hs+2−2
@@ -4,8 +4,8 @@ import System.Linux.Namespaces
44import System.Posix
55import System.Process
66
7−unshareNetork :: IO ()
8−unshareNetork = do
7+unshareNetwork :: IO ()
8+unshareNetwork = do
99 uid <- getEffectiveUserID
1010 unshare [User, Network]
1111 writeUserMappings Nothing [UserMapping 0 uid 1]
dep/reflex-platform/github.json+3−3
@@ -1,7 +1,7 @@
11{
22 "owner": "reflex-frp",
33 "repo": "reflex-platform",
4− "branch": "develop",
5− "rev": "e7b76dd552a10916c7d8702c11292dac4f4299ea",
6− "sha256": "0s1183arrwldcs50qhzgnv94v24n9bgq6dfq64wp0a3q2nzyvgwh"
4+ "branch": "master",
5+ "rev": "510b990d0b11f0626afbec5fe8575b5b2395391b",
6+ "sha256": "09cmahsbxr0963wq171c7j139iyzz49hramr4v9nsf684wcwkngv"
77}
reflex-dom-core/ChangeLog.md+46−15
@@ -1,44 +1,75 @@
11# Revision history for reflex-dom-core
22
3+## 0.6.0.0
4+
5+* ([#375](https://github.com/reflex-frp/reflex-dom/pull/375)) **(Breaking change)** Expose resized dimensions from `resizeDetector`, `resizeDetectorWithStyle`, and `resizeDetectorWithAttrs` from `Reflex.Dom.Widget.Resize`.
6+* ([#374](https://github.com/reflex-frp/reflex-dom/pull/374)) **(Breaking change)** Provide text clipboard data as value of `Paste` event.
7+* ([#348](https://github.com/reflex-frp/reflex-dom/pull/348)) **(Breaking change)** Make XHR response headers case insensitive by changing `_xhrResponse_headers :: Map Text Text` to `_xhrResponse_headers :: Map (CI Text) Text`.
8+* ([#225](https://github.com/reflex-frp/reflex-dom/pull/225)) **(Breaking change)** Add a functional dependency to `HasDomEvent`.
9+* ([#342](https://github.com/reflex-frp/reflex-dom/issues/342)) **(Breaking change)** The mouse wheel event is now a `WheelEventResult` rather than `()`. This provides information about the wheel's motion beyond the fact that it merely moved.
10+* ([#353](https://github.com/reflex-frp/reflex-dom/pull/353)) Support GHC 8.8.
11+* ([#358](https://github.com/reflex-frp/reflex-dom/pull/358)) Fix attribute support for explicitly namespaced elements.
12+* ([#363](https://github.com/reflex-frp/reflex-dom/pull/363)) Remove deprecation warnings for the following widgets in
13+ `Reflex.Dom.Widget.Basic`:
14+ * `Link`
15+ * `button`
16+ * `dtdd`
17+ * `linkClass`
18+ * `link`
19+ * `tabDisplay`
20+ * `tableDynAttr`
21+* ([#361](https://github.com/reflex-frp/reflex-dom/pull/361)) Fix bug in hydration causing the JavaScript to crash when dealing with unexpected HTML.
22+* ([#310](https://github.com/reflex-frp/reflex-dom/issues/310)) Fix the static rendering of which dropdown value is selected.
23+* ([#364](https://github.com/reflex-frp/reflex-dom/pull/364)) Export attributes used for controlling hydration at the element level:
24+ * "data-ssr" is now available as `Reflex.Dom.Builder.Immediate.hydratableAttribute`.
25+ * "data-hydration-skip" is now available as `Reflex.Dom.Builder.Immediate.skipHydrationAttribute`.
26+* ([#366](https://github.com/reflex-frp/reflex-dom/pull/366)) Bump bounds for `reflex` to include 0.7.
27+
328## 0.5.3
429
530* Deprecate a number of old inflexible widget helpers in `Reflex.Dom.Widget.Basic`:
6−
7− * `Link`
8− * `button`
9− * `dtdd`
10− * `linkClass`
11− * `link`
12− * `tabDisplay`
13− * `tableDynAttr`
31+ * `Link`
32+ * `button`
33+ * `dtdd`
34+ * `linkClass`
35+ * `link`
36+ * `tabDisplay`
37+ * `tableDynAttr`
1438
1539 And in `Reflex.Dom.Widget.Input`:
16−
17− * `TextInput`
18− * `TextAreaConfig`
19− * `CheckboxConfig`
20− * `FileInput`
21−
22− * Add `< 0.7` upper bound for reflex
40+ * `TextInput`
41+ * `TextAreaConfig`
42+ * `CheckboxConfig`
43+ * `FileInput`
44+* Add `< 0.7` upper bound for `reflex`.
2345
2446## 0.5.2
2547
2648* Update to use new dependent-sum/map packages and drop dependency on `*Tag` classes (e.g., `ShowTag`).
49+
2750* Update version bounds of base, containers, and stm
51+
2852* Update to use the newly split `these`/`semialign` packages. To use the pre-split `these` package, set the `split-these` flag to false.
53+
2954* Reintroduce "data-ssr": elements without this attribute are skipped during
3055 hydration.
56+
3157* Fix an issue in the hydration tests that prevented the test from finding the chromium executable
58+
3259* Relax constraints on `dyn` and `widgetHold` to match the ones in `networkView` and `networkHold` respectively
60+
3361* Fix prerender for RequesterT so that it doesn't accidentally discard a request that is made at the same moment as getPostBuild's Event fires
3462
3563## 0.5.1
3664
3765* Added support for marking elements with a "data-skip-hydration" attribute, which will cause hydration to ignore and skip over them.
66+
3867* Removed "data-ssr" attributes from statically rendered output.
3968
4069## 0.5
4170
4271* Add HydrationDomBuilderT to support hydration of statically rendered DOM nodes. See the note at the top of Reflex.Dom.Builder.Immediate.
72+
4373* As a result of the hydration changes, the Prerender class has changed, the type of `prerender` has changed and it is now a class method.
74+
4475* Add the Reflex.Dom.Xhr.FormData module to make posting formdata over xhr more convenient.
reflex-dom-core/LICENSE+1−1
@@ -1,4 +1,4 @@
1−Copyright (c) 2015, Obsidian Systems LLC
1+Copyright (c) 2020, Obsidian Systems LLC
22All rights reserved.
33
44Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
reflex-dom-core/reflex-dom-core.cabal+33−21
@@ -1,7 +1,18 @@
1+cabal-version: 1.24
12Name: reflex-dom-core
2−Version: 0.5.3
3+Version: 0.6.0.0
34Synopsis: Functional Reactive Web Apps with Reflex
4−Description: Reflex-DOM is a Functional Reactive web framework based on the Reflex FRP engine
5+Description:
6+ Web applications without callbacks or side-effects.
7+ Reflex-DOM brings the power of functional reactive programming (FRP) to the web.
8+ Build HTML and other Document Object Model (DOM) data with a pure functional interface.
9+ .
10+ Reflex-DOM is a Functional Reactive web framework based on the Reflex FRP engine: <https://reflex-frp.org/>.
11+ .
12+ The @reflex-dom@ package is a small wrapper around the @reflex-dom-core@ package. It pulls in the
13+ correct set of dependencies for each target platform (GHCJS, WebKitGTK, WASM, mobile, etc.).
14+ Libraries should depend on @reflex-dom-core@ and executables will usually depend on @reflex-dom@.
15+ All of @reflex-dom-core@'s modules are re-exported by @reflex-dom@.
516License: BSD3
617License-file: LICENSE
718Author: Ryan Trinkle
@@ -9,7 +20,6 @@ Maintainer: ryan.trinkle@gmail.com
920Stability: Experimental
1021Category: FRP, Web, GUI, HTML, Javascript, Reactive, Reactivity, User Interfaces, User-interface
1122Build-type: Simple
12−Cabal-version: >=1.9.2
1323-- Deal with https://github.com/haskell/cabal/issues/2544 / https://github.com/haskell/cabal/issues/367
1424extra-source-files: src-ghc/Foreign/JavaScript/Internal/Utils.hs
1525 src-ghcjs/Foreign/JavaScript/Internal/Utils.hs
@@ -48,17 +58,18 @@ library
4858 hs-source-dirs: src
4959 build-depends:
5060 aeson >= 0.8 && < 1.5,
51− base >= 4.7 && < 4.13,
61+ base >= 4.7 && < 4.14,
5262 bifunctors >= 4.2 && < 6,
53− bimap >= 0.3 && < 0.4,
54− blaze-builder,
63+ bimap >= 0.3 && < 0.5,
64+ blaze-builder >= 0.4.1 && < 0.5,
5565 bytestring == 0.10.*,
66+ case-insensitive < 1.3,
5667 containers >= 0.6 && < 0.7,
57− constraints >= 0.9 && < 0.12,
68+ constraints >= 0.9 && < 0.13,
5869 contravariant >= 1.4 && < 1.6,
5970 data-default >= 0.5 && < 0.8,
60− dependent-map >= 0.3 && < 0.4,
61− dependent-sum >= 0.6 && < 0.7,
71+ dependent-map >= 0.3 && < 0.5,
72+ dependent-sum >= 0.6 && < 0.8,
6273 dependent-sum-template >= 0.1 && < 0.2,
6374 directory >= 1.2 && < 1.4,
6475 exception-transformers == 0.4.*,
@@ -69,11 +80,11 @@ library
6980 lens >= 4.7 && < 5,
7081 monad-control >= 1.0.1 && < 1.1,
7182 mtl >= 2.1 && < 2.3,
72− primitive >= 0.5 && < 0.7,
73− random,
83+ primitive >= 0.5 && < 0.8,
84+ random >= 1.1 && < 1.2,
7485 ref-tf == 0.4.*,
75− reflex >= 0.6.2 && < 0.7,
76− semigroups >= 0.16 && < 0.19,
86+ reflex >= 0.6.2 && < 0.8,
87+ semigroups >= 0.16 && < 0.20,
7788 stm >= 2.4 && < 2.6,
7889 text == 1.2.*,
7990 transformers >= 0.3 && < 0.6,
@@ -84,7 +95,7 @@ library
8495 hs-source-dirs: src-ghcjs
8596 build-depends:
8697 ghcjs-base,
87− hashable == 1.2.*
98+ hashable >= 1.2 && < 1.4
8899 else
89100 hs-source-dirs: src-ghc
90101 if !os(windows)
@@ -92,8 +103,8 @@ library
92103
93104 if flag(split-these)
94105 build-depends:
95− semialign >= 1 && < 1.1,
96− these >= 1 && < 1.1
106+ semialign >= 1 && < 1.2,
107+ these >= 1 && < 1.2
97108 else
98109 build-depends:
99110 these >= 0.4 && < 0.9
@@ -132,6 +143,7 @@ library
132143 Reflex.Dom.Xhr.ResponseType
133144 Reflex.Dom.Xhr.Exception
134145
146+ default-language: Haskell98
135147 ghc-options: -Wall -fwarn-tabs -funbox-strict-fields -O2 -ferror-spans -fspecialise-aggressively
136148 ghc-prof-options: -fprof-auto
137149
@@ -146,26 +158,24 @@ library
146158
147159 if flag(use-template-haskell)
148160 build-depends:
149− dependent-sum >= 0.6,
150161 dependent-sum-template >= 0.1 && < 0.2,
151− template-haskell
162+ template-haskell >= 2.12.0 && < 2.16
152163 other-extensions: TemplateHaskell
153164 cpp-options: -DUSE_TEMPLATE_HASKELL
154165 other-modules:
155166 Reflex.Dom.Builder.Class.TH
156− else
157− build-depends:
158− dependent-sum == 0.6.*
159167
160168test-suite hlint
161169 build-depends: base, hlint
162170 hs-source-dirs: test
163171 main-is: hlint.hs
164172 type: exitcode-stdio-1.0
173+ default-language: Haskell98
165174
166175test-suite hydration
167176 build-depends: base
168177 , aeson
178+ , async
169179 , bytestring
170180 , chrome-test-utils
171181 , constraints
@@ -207,6 +217,7 @@ test-suite hydration
207217 ghc-prof-options: -fprof-auto -optP-DPROFILING
208218 main-is: hydration.hs
209219 type: exitcode-stdio-1.0
220+ default-language: Haskell98
210221 if !os(linux) || !arch(x86_64) || flag(profile-reflex)
211222 buildable: False
212223
@@ -226,6 +237,7 @@ test-suite gc
226237 ghc-prof-options: -fprof-auto -optP-DPROFILING
227238 main-is: gc.hs
228239 type: exitcode-stdio-1.0
240+ default-language: Haskell98
229241 if !os(linux) || !arch(x86_64)
230242 buildable: False
231243
reflex-dom-core/src/Reflex/Dom/Builder/Class.hs+1−1
@@ -638,7 +638,7 @@ instance (DomBuilder t m, MonadFix m, MonadHold t m, Group q, Query q, Additive
638638
639639-- * Convenience functions
640640
641−class HasDomEvent t target eventName where
641+class HasDomEvent t target eventName | target -> t where
642642 type DomEventType target eventName :: *
643643 domEvent :: EventName eventName -> target -> Event t (DomEventType target eventName)
644644
reflex-dom-core/src/Reflex/Dom/Builder/Class/Events.hs+13−2
@@ -14,6 +14,7 @@ import Data.GADT.Compare.TH
1414import Data.GADT.Compare
1515 (GOrdering(..), (:~:)(..), GEq(..), GCompare(..))
1616#endif
17+import Data.Text (Text)
1718
1819data EventTag
1920 = AbortTag
@@ -151,7 +152,7 @@ type family EventResultType (en :: EventTag) :: * where
151152 EventResultType 'BeforecopyTag = ()
152153 EventResultType 'CopyTag = ()
153154 EventResultType 'BeforepasteTag = ()
154− EventResultType 'PasteTag = ()
155+ EventResultType 'PasteTag = Maybe Text
155156 EventResultType 'ResetTag = ()
156157 EventResultType 'SearchTag = ()
157158 EventResultType 'SelectstartTag = ()
@@ -159,7 +160,17 @@ type family EventResultType (en :: EventTag) :: * where
159160 EventResultType 'TouchmoveTag = TouchEventResult
160161 EventResultType 'TouchendTag = TouchEventResult
161162 EventResultType 'TouchcancelTag = TouchEventResult
162− EventResultType 'WheelTag = ()
163+ EventResultType 'WheelTag = WheelEventResult
164+
165+data DeltaMode = DeltaPixel | DeltaLine | DeltaPage
166+ deriving (Show, Read, Eq, Ord, Bounded, Enum)
167+
168+data WheelEventResult = WheelEventResult
169+ { _wheelEventResult_deltaX :: Double
170+ , _wheelEventResult_deltaY :: Double
171+ , _wheelEventResult_deltaZ :: Double
172+ , _wheelEventResult_deltaMode :: DeltaMode
173+ } deriving (Show, Read, Eq, Ord)
163174
164175data TouchEventResult = TouchEventResult
165176 { _touchEventResult_altKey :: Bool
reflex-dom-core/src/Reflex/Dom/Builder/Hydratable.hs+4−4
@@ -21,10 +21,10 @@ import GHCJS.DOM.Types (MonadJSM (..))
2121#endif
2222import Reflex
2323import Reflex.Dom.Builder.Class
24−import Reflex.Dom.Builder.Immediate (HasDocument (..))
24+import Reflex.Dom.Builder.Immediate (HasDocument (..), hydratableAttribute)
2525import Reflex.Host.Class
2626
27−-- | A DomBuilder transformer that adds "data-ssr" to all elements such that the
27+-- | A DomBuilder transformer that adds an attribute to all elements such that the
2828-- hydration builder knows which bits of DOM were added by us, and which were
2929-- added by external scripts.
3030newtype HydratableT m a = HydratableT { runHydratableT :: m a } deriving (Functor, Applicative, Monad, MonadAtomicRef, MonadFix, MonadIO)
@@ -62,8 +62,8 @@ instance PrimMonad m => PrimMonad (HydratableT m) where
6262
6363makeHydratable :: Reflex t => ElementConfig er t m -> ElementConfig er t m
6464makeHydratable cfg = cfg
65− { _elementConfig_initialAttributes = Map.insert "data-ssr" "" $ _elementConfig_initialAttributes cfg
66− , _elementConfig_modifyAttributes = fmap (Map.delete "data-ssr") <$> _elementConfig_modifyAttributes cfg
65+ { _elementConfig_initialAttributes = Map.insert hydratableAttribute "" $ _elementConfig_initialAttributes cfg
66+ , _elementConfig_modifyAttributes = fmap (Map.delete hydratableAttribute) <$> _elementConfig_modifyAttributes cfg
6767 }
6868
6969instance PostBuild t m => PostBuild t (HydratableT m) where
reflex-dom-core/src/Reflex/Dom/Builder/Immediate.hs+91−43
@@ -107,6 +107,9 @@ module Reflex.Dom.Builder.Immediate
107107 , WindowConfig (..)
108108 , Window (..)
109109 , wrapWindow
110+ -- * Attributes for controlling hydration
111+ , hydratableAttribute
112+ , skipHydrationAttribute
110113 -- * Internal
111114 , traverseDMapWithKeyWithAdjust'
112115 , hoistTraverseWithKeyWithAdjust
@@ -137,11 +140,14 @@ import Data.IntMap.Strict (IntMap)
137140import Data.Maybe
138141import Data.Monoid ((<>))
139142import Data.Some (Some(..))
143+import Data.GADT.Compare (GCompare)
144+import Data.String (IsString)
140145import Data.Text (Text)
141146import Foreign.JavaScript.Internal.Utils
142147import Foreign.JavaScript.TH
148+import GHCJS.DOM.ClipboardEvent as ClipboardEvent
143149import GHCJS.DOM.Document (Document, createDocumentFragment, createElement, createElementNS, createTextNode, createComment)
144−import GHCJS.DOM.Element (getScrollTop, removeAttribute, removeAttributeNS, setAttribute, setAttributeNS, hasAttribute, hasAttributeNS)
150+import GHCJS.DOM.Element (getScrollTop, removeAttribute, removeAttributeNS, setAttribute, setAttributeNS, hasAttribute)
145151import GHCJS.DOM.EventM (EventM, event, on)
146152import GHCJS.DOM.KeyboardEvent as KeyboardEvent
147153import GHCJS.DOM.MouseEvent
@@ -175,6 +181,7 @@ import qualified Data.IntMap.Strict as IntMap
175181import qualified Data.Map as Map
176182import qualified Data.Text as T
177183import qualified GHCJS.DOM as DOM
184+import qualified GHCJS.DOM.DataTransfer as DataTransfer
178185import qualified GHCJS.DOM.DocumentAndElementEventHandlers as Events
179186import qualified GHCJS.DOM.DocumentOrShadowRoot as Document
180187import qualified GHCJS.DOM.Element as Element
@@ -192,6 +199,7 @@ import qualified GHCJS.DOM.TouchEvent as TouchEvent
192199import qualified GHCJS.DOM.TouchList as TouchList
193200import qualified GHCJS.DOM.Types as DOM
194201import qualified GHCJS.DOM.Window as Window
202+import qualified GHCJS.DOM.WheelEvent as WheelEvent
195203import qualified Reflex.Patch.DMap as PatchDMap
196204import qualified Reflex.Patch.DMapWithMove as PatchDMapWithMove
197205import qualified Reflex.Patch.MapWithMove as PatchMapWithMove
@@ -318,8 +326,7 @@ addHydrationStepWithSetup :: (Adjustable t m, MonadIO m) => m a -> (a -> Hydrati
318326addHydrationStepWithSetup setup f = getHydrationMode >>= \case
319327 HydrationMode_Immediate -> pure ()
320328 HydrationMode_Hydrating -> do
321− switchover <- HydrationDomBuilderT $ asks _hydrationDomBuilderEnv_switchover
322− (s, _) <- lift $ runWithReplace setup $ return () <$ switchover
329+ s <- lift setup
323330 addHydrationStep (f s)
324331
325332-- | Add a hydration step
@@ -743,6 +750,14 @@ elementInternal elementTag cfg child = getHydrationMode >>= \case
743750 -> HydrationDomBuilderT HydrationDomSpace DomTimeline HydrationM (Element er HydrationDomSpace DomTimeline, a)
744751 #-}
745752
753+-- | An attribute which causes hydration to skip over an element completely.
754+skipHydrationAttribute :: IsString s => s
755+skipHydrationAttribute = "data-hydration-skip"
756+
757+-- | An attribute which signals that an element should be hydrated.
758+hydratableAttribute :: IsString s => s
759+hydratableAttribute = "data-ssr"
760+
746761{-# INLINE hydrateElement #-}
747762hydrateElement
748763 :: forall er t m a. (MonadJSM m, Reflex t, MonadReflexCreateTrigger t m, MonadFix m)
@@ -764,18 +779,15 @@ hydrateElement elementTag cfg child = do
764779 }
765780 result <- HydrationDomBuilderT $ lift $ runReaderT (unHydrationDomBuilderT child) env'
766781 wrapResult <- liftIO newEmptyMVar
767− let skipAttr = "data-hydration-skip" :: DOM.JSString
768− ssrAttr = "data-ssr" :: DOM.JSString
782+ let -- Determine if we should skip an element. We currently skip elements for
783+ -- two reasons:
784+ -- 1) it was not produced by a static builder which supports hydration
785+ -- 2) it is explicitly marked to be skipped
769786 shouldSkip :: DOM.Element -> HydrationRunnerT t m Bool
770− shouldSkip e = case cfg ^. namespace of
771− Nothing -> do
772− skip <- hasAttribute e skipAttr
773− ssr <- hasAttribute e ssrAttr
774− pure $ skip || not ssr
775− Just ns -> do
776− skip <- hasAttributeNS e (Just ns) skipAttr
777− ssr <- hasAttributeNS e (Just ns) ssrAttr
778− pure $ skip || not ssr
787+ shouldSkip e = do
788+ skip <- hasAttribute e (skipHydrationAttribute :: DOM.JSString)
789+ hydratable <- hasAttribute e (hydratableAttribute :: DOM.JSString)
790+ pure $ skip || not hydratable
779791 childDom <- liftIO $ readIORef childDelayedRef
780792 let rawCfg = extractRawElementConfig cfg
781793 doc <- askDocument
@@ -791,7 +803,7 @@ hydrateElement elementTag cfg child = do
791803 Just node -> DOM.castTo DOM.Element node >>= \case
792804 Nothing -> go (Just node) -- this node is not an element, skip
793805 Just e -> shouldSkip e >>= \case
794− True -> go (Just node) -- this element is explicitly marked for being skipped by hydration
806+ True -> go (Just node) -- this element should be skipped by hydration
795807 False -> do
796808 t <- Element.getTagName e
797809 -- TODO: check attributes?
@@ -1277,8 +1289,8 @@ hydrateComment doc t mSetContents = do
12771289skipToAndReplaceComment
12781290 :: (MonadJSM m, Reflex t, MonadFix m, Adjustable t m, MonadHold t m, RawDocument (DomBuilderSpace (HydrationDomBuilderT s t m)) ~ Document)
12791291 => Text
1280− -> IORef Text
1281− -> HydrationDomBuilderT s t m (HydrationRunnerT t m (), IORef DOM.Text, IORef Text)
1292+ -> IORef (Maybe Text)
1293+ -> HydrationDomBuilderT s t m (HydrationRunnerT t m (), IORef DOM.Text, IORef (Maybe Text))
12821294skipToAndReplaceComment prefix key0Ref = getHydrationMode >>= \case
12831295 HydrationMode_Immediate -> do
12841296 -- If we're in immediate mode, we don't try to replace an existing comment,
@@ -1286,43 +1298,50 @@ skipToAndReplaceComment prefix key0Ref = getHydrationMode >>= \case
12861298 t <- textNodeImmediate $ TextNodeConfig ("" :: Text) Nothing
12871299 append $ toNode t
12881300 textNodeRef <- liftIO $ newIORef t
1289− keyRef <- liftIO $ newIORef ""
1301+ keyRef <- liftIO $ newIORef Nothing
12901302 pure (pure (), textNodeRef, keyRef)
12911303 HydrationMode_Hydrating -> do
12921304 doc <- askDocument
12931305 textNodeRef <- liftIO $ newIORef $ error "textNodeRef not yet initialized"
12941306 keyRef <- liftIO $ newIORef $ error "keyRef not yet initialized"
1295− let go key0 mLastNode = do
1296− parent <- askParent
1297− node <- maybe (Node.getFirstChildUnchecked parent) Node.getNextSiblingUnchecked mLastNode
1298− DOM.castTo DOM.Comment node >>= \case
1307+ let
1308+ go Nothing _ = do
1309+ tn <- createTextNode doc ("" :: Text)
1310+ insertAfterPreviousNode tn
1311+ HydrationRunnerT $ modify' $ \s -> s { _hydrationState_failed = True }
1312+ pure (tn, Nothing)
1313+ go (Just key0) mLastNode = do
1314+ parent <- askParent
1315+ maybe (Node.getFirstChild parent) Node.getNextSibling mLastNode >>= \case
1316+ Nothing -> go Nothing Nothing
1317+ Just node -> DOM.castTo DOM.Comment node >>= \case
12991318 Just comment -> do
1300− commentText <- Node.getTextContentUnchecked comment
1301− case T.stripPrefix (prefix <> key0) commentText of
1319+ commentText <- fromMaybe (error "Cannot get text content of comment node") <$> Node.getTextContent comment
1320+ case T.stripPrefix (prefix <> key0) commentText of -- 'key0' may be @""@ in which case we're just finding the actual key; TODO: Don't be clever.
13021321 Just key -> do
13031322 -- Replace the comment with an (invisible) text node
13041323 tn <- createTextNode doc ("" :: Text)
13051324 Node.replaceChild_ parent tn comment
1306− pure (tn, key)
1325+ pure (tn, Just key)
13071326 Nothing -> do
1308− go key0 (Just node)
1327+ go (Just key0) (Just node)
13091328 Nothing -> do
1310− go key0 (Just node)
1311− switchComment = do
1312− key0 <- liftIO $ readIORef key0Ref
1313− (tn, key) <- go key0 =<< getPreviousNode
1314− setPreviousNode $ Just $ toNode tn
1315− liftIO $ do
1316− writeIORef textNodeRef tn
1317− writeIORef keyRef key
1329+ go (Just key0) (Just node)
1330+ switchComment = do
1331+ key0 <- liftIO $ readIORef key0Ref
1332+ (tn, key) <- go key0 =<< getPreviousNode
1333+ setPreviousNode $ Just $ toNode tn
1334+ liftIO $ do
1335+ writeIORef textNodeRef tn
1336+ writeIORef keyRef key
13181337 pure (switchComment, textNodeRef, keyRef)
13191338
13201339{-# INLINABLE skipToReplaceStart #-}
1321−skipToReplaceStart :: (MonadJSM m, Reflex t, MonadFix m, Adjustable t m, MonadHold t m, RawDocument (DomBuilderSpace (HydrationDomBuilderT s t m)) ~ Document) => HydrationDomBuilderT s t m (HydrationRunnerT t m (), IORef DOM.Text, IORef Text)
1322−skipToReplaceStart = skipToAndReplaceComment "replace-start" =<< liftIO (newIORef "")
1340+skipToReplaceStart :: (MonadJSM m, Reflex t, MonadFix m, Adjustable t m, MonadHold t m, RawDocument (DomBuilderSpace (HydrationDomBuilderT s t m)) ~ Document) => HydrationDomBuilderT s t m (HydrationRunnerT t m (), IORef DOM.Text, IORef (Maybe Text))
1341+skipToReplaceStart = skipToAndReplaceComment "replace-start" =<< liftIO (newIORef $ Just "") -- TODO: Don't rely on clever usage @""@ to make this work.
13231342
13241343{-# INLINABLE skipToReplaceEnd #-}
1325−skipToReplaceEnd :: (MonadJSM m, Reflex t, MonadFix m, Adjustable t m, MonadHold t m, RawDocument (DomBuilderSpace (HydrationDomBuilderT s t m)) ~ Document) => IORef Text -> HydrationDomBuilderT s t m (HydrationRunnerT t m (), IORef DOM.Text)
1344+skipToReplaceEnd :: (MonadJSM m, Reflex t, MonadFix m, Adjustable t m, MonadHold t m, RawDocument (DomBuilderSpace (HydrationDomBuilderT s t m)) ~ Document) => IORef (Maybe Text) -> HydrationDomBuilderT s t m (HydrationRunnerT t m (), IORef DOM.Text)
13261345skipToReplaceEnd key = fmap (\(m,e,_) -> (m,e)) $ skipToAndReplaceComment "replace-end" key
13271346
13281347instance SupportsHydrationDomBuilder t m => NotReady t (HydrationDomBuilderT s t m) where
@@ -1614,7 +1633,7 @@ instance (Adjustable t m, MonadJSM m, MonadHold t m, MonadFix m, PrimMonad m, Ra
16141633
16151634{-# INLINABLE traverseDMapWithKeyWithAdjust' #-}
16161635traverseDMapWithKeyWithAdjust'
1617− :: forall s t m (k :: * -> *) v v'. (Adjustable t m, MonadHold t m, MonadFix m, MonadJSM m, PrimMonad m, DMap.GCompare k, RawDocument (DomBuilderSpace (HydrationDomBuilderT s t m)) ~ Document)
1636+ :: forall s t m (k :: * -> *) v v'. (Adjustable t m, MonadHold t m, MonadFix m, MonadJSM m, PrimMonad m, GCompare k, RawDocument (DomBuilderSpace (HydrationDomBuilderT s t m)) ~ Document)
16181637 => (forall a. k a -> v a -> HydrationDomBuilderT s t m (v' a))
16191638 -> DMap k v
16201639 -> Event t (PatchDMap k v)
@@ -1734,7 +1753,7 @@ hoistTraverseWithKeyWithAdjust
17341753 ::
17351754 ( Adjustable t m
17361755 , MonadHold t m
1737− , DMap.GCompare k
1756+ , GCompare k
17381757 , MonadIO m
17391758 , MonadJSM m
17401759 , PrimMonad m
@@ -2239,7 +2258,7 @@ defaultDomEventHandler e evt = fmap (Just . EventResult) $ case evt of
22392258 Beforecopy -> return ()
22402259 Copy -> return ()
22412260 Beforepaste -> return ()
2242− Paste -> return ()
2261+ Paste -> getPasteData
22432262 Reset -> return ()
22442263 Search -> return ()
22452264 Selectstart -> return ()
@@ -2248,7 +2267,7 @@ defaultDomEventHandler e evt = fmap (Just . EventResult) $ case evt of
22482267 Touchend -> getTouchEvent
22492268 Touchcancel -> getTouchEvent
22502269 Mousewheel -> return ()
2251− Wheel -> return ()
2270+ Wheel -> getWheelEvent
22522271
22532272{-# INLINABLE defaultDomWindowEventHandler #-}
22542273defaultDomWindowEventHandler :: DOM.Window -> EventName en -> EventM DOM.Window (EventType en) (Maybe (EventResult en))
@@ -2289,7 +2308,7 @@ defaultDomWindowEventHandler w evt = fmap (Just . EventResult) $ case evt of
22892308 Beforecopy -> return ()
22902309 Copy -> return ()
22912310 Beforepaste -> return ()
2292− Paste -> return ()
2311+ Paste -> getPasteData
22932312 Reset -> return ()
22942313 Search -> return ()
22952314 Selectstart -> return ()
@@ -2298,7 +2317,7 @@ defaultDomWindowEventHandler w evt = fmap (Just . EventResult) $ case evt of
22982317 Touchend -> getTouchEvent
22992318 Touchcancel -> getTouchEvent
23002319 Mousewheel -> return ()
2301− Wheel -> return ()
2320+ Wheel -> getWheelEvent
23022321
23032322{-# INLINABLE withIsEvent #-}
23042323withIsEvent :: EventName en -> (IsEvent (EventType en) => r) -> r
@@ -2566,6 +2585,15 @@ getMouseEventCoords = do
25662585 e <- event
25672586 bisequence (getClientX e, getClientY e)
25682587
2588+{-# INLINABLE getPasteData #-}
2589+getPasteData :: EventM e ClipboardEvent (Maybe Text)
2590+getPasteData = do
2591+ e <- event
2592+ mdt <- ClipboardEvent.getClipboardData e
2593+ case mdt of
2594+ Nothing -> return Nothing
2595+ Just dt -> Just <$> DataTransfer.getData dt ("text" :: Text)
2596+
25692597{-# INLINABLE getTouchEvent #-}
25702598getTouchEvent :: EventM e TouchEvent TouchEventResult
25712599getTouchEvent = do
@@ -2607,6 +2635,26 @@ getTouchEvent = do
26072635 , _touchEventResult_touches = touches
26082636 }
26092637
2638+{-# INLINABLE getWheelEvent #-}
2639+getWheelEvent :: EventM e WheelEvent WheelEventResult
2640+getWheelEvent = do
2641+ e <- event
2642+ dx :: Double <- WheelEvent.getDeltaX e
2643+ dy :: Double <- WheelEvent.getDeltaY e
2644+ dz :: Double <- WheelEvent.getDeltaZ e
2645+ deltaMode :: Word <- WheelEvent.getDeltaMode e
2646+ return $ WheelEventResult
2647+ { _wheelEventResult_deltaX = dx
2648+ , _wheelEventResult_deltaY = dy
2649+ , _wheelEventResult_deltaZ = dz
2650+ , _wheelEventResult_deltaMode = case deltaMode of
2651+ 0 -> DeltaPixel
2652+ 1 -> DeltaLine
2653+ 2 -> DeltaPage
2654+ -- See https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/deltaMode
2655+ _ -> error "getWheelEvent: impossible encoding"
2656+ }
2657+
26102658instance MonadSample t m => MonadSample t (HydrationDomBuilderT s t m) where
26112659 {-# INLINABLE sample #-}
26122660 sample = lift . sample
reflex-dom-core/src/Reflex/Dom/Builder/Static.hs+12−9
@@ -55,7 +55,6 @@ import Reflex.PerformEvent.Class
5555import Reflex.PostBuild.Base
5656import Reflex.PostBuild.Class
5757import Reflex.TriggerEvent.Class
58−import System.Random (randomRIO)
5958
6059data StaticDomBuilderEnv t = StaticDomBuilderEnv
6160 { _staticDomBuilderEnv_shouldEscape :: Bool
@@ -64,6 +63,7 @@ data StaticDomBuilderEnv t = StaticDomBuilderEnv
6463 -- We use this to add a "selected" attribute to the appropriate "option" child element.
6564 -- This is not yet a perfect simulation of what the browser does, but it is much closer than doing nothing.
6665 -- TODO: Handle edge cases, e.g. setting to a value for which there is no option, then adding that option dynamically afterwards.
66+ , _staticDomBuilderEnv_nextRunWithReplaceKey :: IORef Int
6767 }
6868
6969newtype StaticDomBuilderT t m a = StaticDomBuilderT
@@ -164,7 +164,7 @@ instance (SupportsStaticDomBuilder t m, Monad m) => HasDocument (StaticDomBuilde
164164instance (Reflex t, Adjustable t m, MonadHold t m, SupportsStaticDomBuilder t m) => Adjustable t (StaticDomBuilderT t m) where
165165 runWithReplace a0 a' = do
166166 e <- StaticDomBuilderT ask
167− key <- replaceStart
167+ key <- replaceStart e
168168 (result0, result') <- lift $ runWithReplace (runStaticDomBuilderT a0 e) (flip runStaticDomBuilderT e <$> a')
169169 o <- hold (snd result0) $ fmapCheap snd result'
170170 StaticDomBuilderT $ modify $ (:) $ join o
@@ -174,10 +174,9 @@ instance (Reflex t, Adjustable t m, MonadHold t m, SupportsStaticDomBuilder t m)
174174 traverseDMapWithKeyWithAdjust = hoistDMapWithKeyWithAdjust traverseDMapWithKeyWithAdjust mapPatchDMap
175175 traverseDMapWithKeyWithAdjustWithMove = hoistDMapWithKeyWithAdjust traverseDMapWithKeyWithAdjustWithMove mapPatchDMapWithMove
176176
177−-- TODO remove this?
178−replaceStart :: (DomBuilder t m, MonadIO m) => m Text
179−replaceStart = do
180− str <- liftIO $ replicateM 8 $ randomRIO ('a', 'z')
177+replaceStart :: (DomBuilder t m, MonadIO m) => StaticDomBuilderEnv t -> m Text
178+replaceStart env = do
179+ str <- show <$> liftIO (atomicModifyRef (_staticDomBuilderEnv_nextRunWithReplaceKey env) $ \k -> (succ k, k))
181180 let key = "-" <> T.pack str
182181 _ <- commentNode $ def { _commentNodeConfig_initialContents = "replace-start" <> key }
183182 pure key
@@ -287,7 +286,8 @@ instance SupportsStaticDomBuilder t m => DomBuilder t (StaticDomBuilderT t m) wh
287286 es <- newFanEventWithTrigger $ \_ _ -> return (return ())
288287 StaticDomBuilderT $ do
289288 let shouldEscape = elementTag `Set.notMember` noEscapeElements
290− (result, innerHtml) <- lift $ lift $ runStaticDomBuilderT child $ StaticDomBuilderEnv shouldEscape Nothing
289+ nextRunWithReplaceKey <- asks _staticDomBuilderEnv_nextRunWithReplaceKey
290+ (result, innerHtml) <- lift $ lift $ runStaticDomBuilderT child $ StaticDomBuilderEnv shouldEscape Nothing nextRunWithReplaceKey
291291 attrs0 <- foldDyn applyMap (cfg ^. initialAttributes) (cfg ^. modifyAttributes)
292292 selectValue <- asks _staticDomBuilderEnv_selectValue
293293 let addSelectedAttr attrs sel = case Map.lookup "value" attrs of
@@ -341,7 +341,9 @@ instance SupportsStaticDomBuilder t m => DomBuilder t (StaticDomBuilderT t m) wh
341341 selectElement cfg child = do
342342 v <- holdDyn (cfg ^. selectElementConfig_initialValue) (cfg ^. selectElementConfig_setValue)
343343 (e, result) <- element "select" (_selectElementConfig_elementConfig cfg) $ do
344− (a, innerHtml) <- StaticDomBuilderT $ lift $ lift $ runStaticDomBuilderT child $ StaticDomBuilderEnv False $ Just (current v)
344+ (a, innerHtml) <- StaticDomBuilderT $ do
345+ nextRunWithReplaceKey <- asks _staticDomBuilderEnv_nextRunWithReplaceKey
346+ lift $ lift $ runStaticDomBuilderT child $ StaticDomBuilderEnv False (Just $ current v) nextRunWithReplaceKey
345347 StaticDomBuilderT $ lift $ modify $ (:) innerHtml
346348 return a
347349 let wrapped = SelectElement
@@ -363,7 +365,8 @@ renderStatic :: StaticWidget x a -> IO (a, ByteString)
363365renderStatic w = do
364366 runDomHost $ do
365367 (postBuild, postBuildTriggerRef) <- newEventWithTriggerRef
366− let env0 = StaticDomBuilderEnv True Nothing
368+ nextRunWithReplaceKey <- newRef 0
369+ let env0 = StaticDomBuilderEnv True Nothing nextRunWithReplaceKey
367370 ((res, bs), FireCommand fire) <- hostPerformEventT $ runStaticDomBuilderT (runPostBuildT w postBuild) env0
368371 mPostBuildTrigger <- readRef postBuildTriggerRef
369372 forM_ mPostBuildTrigger $ \postBuildTrigger -> fire [postBuildTrigger :=> Identity ()] $ return ()
reflex-dom-core/src/Reflex/Dom/Class.hs+4−7
@@ -4,8 +4,7 @@ module Reflex.Dom.Class ( module Reflex.Dom.Class
44 , module Web.KeyCode
55 ) where
66
7−import Data.Map (Map)
8−import qualified Data.Map as Map
7+import Control.Lens
98import Reflex.Class
109import Web.KeyCode
1110
@@ -13,11 +12,9 @@ import Foreign.JavaScript.TH
1312import Reflex.PerformEvent.Class
1413import Reflex.PostBuild.Class
1514
16−import Prelude hiding (concat, mapM, mapM_, sequence)
17−
18−-- | Alias for Data.Map.singleton
19−(=:) :: k -> a -> Map k a
20−(=:) = Map.singleton
15+-- | Previously an alias for 'Data.Map.singleton', but now generalised to 'At'
16+(=:) :: (At m, Monoid m) => Index m -> IxValue m -> m
17+k =: a = at k ?~ a $ mempty
2118infixr 7 =: -- Ought to bind tighter than <>, which is infixr 6
2219
2320{-# DEPRECATED keycodeEnter "Instead of `x == keycodeEnter`, use `keyCodeLookup x == Enter`" #-}
reflex-dom-core/src/Reflex/Dom/Prerender.hs+5−3
@@ -24,7 +24,7 @@ module Reflex.Dom.Prerender
2424
2525import Control.Monad.Primitive (PrimMonad(..))
2626import Control.Monad.Reader
27−import Control.Monad.Ref (MonadRef(..))
27+import Control.Monad.Ref (MonadRef(..), MonadAtomicRef(..))
2828import Data.IORef (IORef, newIORef)
2929import Data.Semigroup (Semigroup)
3030import Data.Text (Text)
@@ -165,6 +165,8 @@ instance Monad m => MonadRef (UnrunnableT js t m) where
165165 newRef _ = unrunnable
166166 readRef _ = unrunnable
167167 writeRef _ _ = unrunnable
168+instance Monad m => MonadAtomicRef (UnrunnableT js t m) where
169+ atomicModifyRef _ _ = unrunnable
168170instance Monad m => HasDocument (UnrunnableT js t m) where
169171 askDocument = unrunnable
170172instance Monad m => HasJSContext (UnrunnableT js t m) where
@@ -203,7 +205,7 @@ instance Monad m => MonadReflexCreateTrigger t (UnrunnableT js t m) where
203205 newFanEventWithTrigger _ = unrunnable
204206instance Monad m => MonadFix (UnrunnableT js t m) where
205207 mfix _ = unrunnable
206−instance Monad m => MonadHold t (UnrunnableT js t m) where
208+instance (Monad m, MonadHold t m) => MonadHold t (UnrunnableT js t m) where
207209 hold _ _ = unrunnable
208210 holdDyn _ _ = unrunnable
209211 holdIncremental _ _ = unrunnable
@@ -226,7 +228,7 @@ instance (Reflex t, Monad m) => DomRenderHook t (UnrunnableT js t m) where
226228 withRenderHook _ _ = unrunnable
227229 requestDomAction _ = unrunnable
228230 requestDomAction_ _ = unrunnable
229−instance (Reflex t, Monad m) => Prerender JS' t (UnrunnableT js t m) where
231+instance (Reflex t, Monad m, MonadHold t m) => Prerender JS' t (UnrunnableT js t m) where
230232 type Client (UnrunnableT js t m) = UnrunnableT js t m
231233 prerender _ _ = unrunnable
232234
reflex-dom-core/src/Reflex/Dom/Widget/Basic.hs−7
@@ -138,7 +138,6 @@ dynComment t = do
138138display :: (PostBuild t m, DomBuilder t m, Show a) => Dynamic t a -> m ()
139139display = dynText . fmap (T.pack . show)
140140
141−{-# DEPRECATED button "Use 'elAttr'' in combination with 'domEvent' instead" #-}
142141button :: DomBuilder t m => Text -> m (Event t ())
143142button t = do
144143 (e, _) <- element "button" def $ text t
@@ -272,25 +271,21 @@ dynamicAttributesToModifyAttributesWithInitial attrs0 d = do
272271 return $ if Map.null p then Nothing else Just p
273272 return modificationsNeeded
274273
275−{-# DEPRECATED Link "Will be removed when 'linkClass' and 'link' are removed. Follow those functions' deprecation instructions." #-}
276274newtype Link t
277275 = Link { _link_clicked :: Event t ()
278276 }
279277
280−{-# DEPRECATED linkClass "Use 'elAttr'' in combination with 'domEvent' for just clicks. Use 'routeLink' for Obelisk navigation" #-}
281278linkClass :: DomBuilder t m => Text -> Text -> m (Link t)
282279linkClass s c = do
283280 (l,_) <- elAttr' "a" ("class" =: c) $ text s
284281 return $ Link $ domEvent Click l
285282
286−{-# DEPRECATED link "Use 'elAttr'' in combination with 'domEvent' for just clicks. Use 'routeLink' for Obelisk navigation" #-}
287283link :: DomBuilder t m => Text -> m (Link t)
288284link s = linkClass s ""
289285
290286divClass :: forall t m a. DomBuilder t m => Text -> m a -> m a
291287divClass = elClass "div"
292288
293−{-# DEPRECATED dtdd "Use an application specific widget generating function" #-}
294289dtdd :: forall t m a. DomBuilder t m => Text -> m a -> m a
295290dtdd h w = do
296291 el "dt" $ text h
@@ -301,7 +296,6 @@ blank = return ()
301296
302297-- TODO: Move to an example project.
303298-- | A widget to display a table with static columns and dynamic rows.
304−{-# DEPRECATED tableDynAttr "Use an application specific widget generating function" #-}
305299tableDynAttr :: forall t m r k v. (Ord k, DomBuilder t m, MonadHold t m, PostBuild t m, MonadFix m)
306300 => Text -- ^ Class applied to <table> element
307301 -> [(Text, k -> Dynamic t r -> m v)] -- ^ Columns of (header, row key -> row value -> child widget)
@@ -321,7 +315,6 @@ tableDynAttr klass cols dRows rowAttrs = elAttr "div" (Map.singleton "style" "zo
321315-- | A widget to construct a tabbed view that shows only one of its child widgets at a time.
322316-- Creates a header bar containing a <ul> with one <li> per child; clicking a <li> displays
323317-- the corresponding child and hides all others.
324−{-# DEPRECATED tabDisplay "Use an application specific widget generating function" #-}
325318tabDisplay :: forall t m k. (MonadFix m, DomBuilder t m, MonadHold t m, PostBuild t m, Ord k)
326319 => Text -- ^ Class applied to <ul> element
327320 -> Text -- ^ Class applied to currently active <li> element
reflex-dom-core/src/Reflex/Dom/Widget/Input.hs+4−1
@@ -437,9 +437,12 @@ dropdown k0 options (DropdownConfig setK attrs) = do
437437 let xs = fmap (\(ix, (k, v)) -> ((ix, k), ((ix, k), v))) $ zip [0::Int ..] $ Map.toList os
438438 in (Map.fromList $ map snd xs, Bimap.fromList $ map fst xs)
439439 modifyAttrs <- dynamicAttributesToModifyAttributes attrs
440+ postBuild <- getPostBuild
441+ let setSelection = attachPromptlyDynWithMaybe (flip Bimap.lookupR) ixKeys $
442+ leftmost [setK, k0 <$ postBuild]
440443 let cfg = def
441444 & selectElementConfig_elementConfig . elementConfig_modifyAttributes .~ fmap mapKeysToAttributeName modifyAttrs
442− & selectElementConfig_setValue .~ fmap (T.pack . show) (attachPromptlyDynWithMaybe (flip Bimap.lookupR) ixKeys setK)
445+ & selectElementConfig_setValue .~ fmap (T.pack . show) setSelection
443446 (eRaw, _) <- selectElement cfg $ listWithKey indexedOptions $ \(ix, k) v -> do
444447 let optionAttrs = fmap (\dk -> "value" =: T.pack (show ix) <> if dk == k then "selected" =: "selected" else mempty) defaultKey
445448 elDynAttr "option" optionAttrs $ dynText v
reflex-dom-core/src/Reflex/Dom/Widget/Resize.hs+4−4
@@ -37,19 +37,19 @@ import qualified GHCJS.DOM.Types as DOM
3737-- This function can cause strange scrollbars to appear in some circumstances.
3838-- These can be hidden with pseudo selectors, for example, in webkit browsers:
3939-- .wrapper *::-webkit-scrollbar { width: 0px; background: transparent; }
40−resizeDetector :: (MonadJSM m, DomBuilder t m, PostBuild t m, TriggerEvent t m, PerformEvent t m, MonadHold t m, DomBuilderSpace m ~ GhcjsDomSpace, MonadJSM (Performable m), MonadFix m) => m a -> m (Event t (), a)
40+resizeDetector :: (MonadJSM m, DomBuilder t m, PostBuild t m, TriggerEvent t m, PerformEvent t m, MonadHold t m, DomBuilderSpace m ~ GhcjsDomSpace, MonadJSM (Performable m), MonadFix m) => m a -> m (Event t (Maybe Double, Maybe Double), a)
4141resizeDetector = resizeDetectorWithStyle ""
4242
4343resizeDetectorWithStyle :: (MonadJSM m, DomBuilder t m, PostBuild t m, TriggerEvent t m, PerformEvent t m, MonadHold t m, DomBuilderSpace m ~ GhcjsDomSpace, MonadJSM (Performable m), MonadFix m)
4444 => Text -- ^ A css style string. Warning: It should not contain the "position" style attribute.
4545 -> m a -- ^ The embedded widget
46− -> m (Event t (), a) -- ^ An 'Event' that fires on resize, and the result of the embedded widget
46+ -> m (Event t (Maybe Double, Maybe Double), a) -- ^ An 'Event' that fires on resize, and the result of the embedded widget
4747resizeDetectorWithStyle styleString = resizeDetectorWithAttrs ("style" =: styleString)
4848
4949resizeDetectorWithAttrs :: (MonadJSM m, DomBuilder t m, PostBuild t m, TriggerEvent t m, PerformEvent t m, MonadHold t m, DomBuilderSpace m ~ GhcjsDomSpace, MonadJSM (Performable m), MonadFix m)
5050 => Map Text Text -- ^ A map of attributes. Warning: It should not modify the "position" style attribute.
5151 -> m a -- ^ The embedded widget
52− -> m (Event t (), a) -- ^ An 'Event' that fires on resize, and the result of the embedded widget
52+ -> m (Event t (Maybe Double, Maybe Double), a) -- ^ An 'Event' that fires on resize, and the result of the embedded widget
5353resizeDetectorWithAttrs attrs w = do
5454 let childStyle = "position: absolute; left: 0; top: 0;"
5555 containerAttrs = "style" =: "position: absolute; left: 0; top: 0; right: 0; bottom: 0; overflow: scroll; z-index: -1; visibility: hidden;"
@@ -91,4 +91,4 @@ resizeDetectorWithAttrs attrs w = do
9191 size0 <- performEvent $ fmap (const $ liftJSM reset) pb
9292 rec resize <- performEventAsync $ fmap (\d cb -> (liftIO . cb) =<< liftJSM (resetIfChanged d)) $ tag (current dimensions) $ leftmost [expandScroll, shrinkScroll]
9393 dimensions <- holdDyn (Nothing, Nothing) $ leftmost [ size0, fmapMaybe id resize ]
94− return (fmapMaybe void resize, w')
94+ return (updated dimensions, w')
reflex-dom-core/src/Reflex/Dom/Xhr.hs+8−6
@@ -159,6 +159,8 @@ import Data.Aeson.Text
159159import Data.Aeson.Encode
160160#endif
161161import qualified Data.ByteString.Lazy as BL
162+import Data.CaseInsensitive (CI)
163+import qualified Data.CaseInsensitive as CI
162164import Data.Default
163165import qualified Data.List as L
164166import Data.Map (Map)
@@ -198,12 +200,12 @@ data XhrResponse
198200 , _xhrResponse_statusText :: Text
199201 , _xhrResponse_response :: Maybe XhrResponseBody
200202 , _xhrResponse_responseText :: Maybe Text
201− , _xhrResponse_headers :: Map Text Text
203+ , _xhrResponse_headers :: Map (CI Text) Text
202204 }
203205 deriving (Typeable)
204206
205207data XhrResponseHeaders =
206− OnlyHeaders (Set.Set Text) -- ^ Parse a subset of headers from the XHR Response
208+ OnlyHeaders (Set.Set (CI Text)) -- ^ Parse a subset of headers from the XHR Response
207209 | AllHeaders -- ^ Parse all headers from the XHR Response
208210 deriving (Show, Read, Eq, Ord, Typeable)
209211
@@ -275,7 +277,7 @@ newXMLHttpRequestWithError req cb = do
275277 AllHeaders -> parseAllHeadersString <$>
276278 xmlHttpRequestGetAllResponseHeaders xhr
277279 OnlyHeaders xs -> traverse (xmlHttpRequestGetResponseHeader xhr)
278− (Map.fromSet id xs)
280+ (Map.fromSet CI.original xs)
279281 _ <- liftJSM $ cb $ Right
280282 XhrResponse { _xhrResponse_status = status
281283 , _xhrResponse_statusText = statusText
@@ -288,10 +290,10 @@ newXMLHttpRequestWithError req cb = do
288290 return ()
289291 return xhr
290292
291−parseAllHeadersString :: Text -> Map Text Text
293+parseAllHeadersString :: Text -> Map (CI Text) Text
292294parseAllHeadersString s = Map.fromList $ fmap (stripBoth . T.span (/=':')) $
293295 L.dropWhileEnd T.null $ T.splitOn (T.pack "\r\n") s
294− where stripBoth (txt1, txt2) = (T.strip txt1, T.strip $ T.drop 1 txt2)
296+ where stripBoth (txt1, txt2) = (CI.mk $ T.strip txt1, T.strip $ T.drop 1 txt2)
295297
296298newXMLHttpRequest :: (HasJSContext m, MonadJSM m, IsXhrPayload a) => XhrRequest a -> (XhrResponse -> JSM ()) -> m XMLHttpRequest
297299newXMLHttpRequest req cb = newXMLHttpRequestWithError req $ mapM_ cb
@@ -444,7 +446,7 @@ xhrResponse_responseText :: Lens' XhrResponse (Maybe Text)
444446xhrResponse_responseText f (XhrResponse x1 x2 x3 x4 x5) = (\y -> XhrResponse x1 x2 x3 y x5) <$> f x4
445447{-# INLINE xhrResponse_responseText #-}
446448
447−xhrResponse_headers :: Lens' XhrResponse (Map Text Text)
449+xhrResponse_headers :: Lens' XhrResponse (Map (CI Text) Text)
448450xhrResponse_headers f (XhrResponse x1 x2 x3 x4 x5) = (\y -> XhrResponse x1 x2 x3 x4 y) <$> f x5
449451{-# INLINE xhrResponse_headers #-}
450452
reflex-dom-core/src/Reflex/Dom/Xhr/Foreign.hs+2−2
@@ -15,7 +15,7 @@ import Data.Text (Text)
1515import Data.ByteString (ByteString)
1616import Foreign.JavaScript.Utils (bsFromMutableArrayBuffer, bsToArrayBuffer)
1717import GHCJS.DOM.Enums
18−import GHCJS.DOM.EventM (EventM, on)
18+import GHCJS.DOM.EventM (EventM, on, onSync)
1919import GHCJS.DOM.EventTarget (dispatchEvent)
2020import GHCJS.DOM.Types (MonadJSM, ToJSString, FormData, Document, Blob (..), ArrayBuffer (..), JSVal, JSM, IsEvent, XMLHttpRequestProgressEvent, ProgressEvent, Event, XMLHttpRequestUpload, FromJSString, ArrayBufferView (..), liftJSM, castTo)
2121import GHCJS.DOM.XMLHttpRequest
@@ -114,7 +114,7 @@ xmlHttpRequestOntimeout :: XMLHttpRequest -> EventM XMLHttpRequest ProgressEvent
114114xmlHttpRequestOntimeout = (`on` timeout)
115115
116116xmlHttpRequestOnreadystatechange :: XMLHttpRequest -> EventM XMLHttpRequest Event () -> JSM (JSM ())
117−xmlHttpRequestOnreadystatechange = (`on` readyStateChange)
117+xmlHttpRequestOnreadystatechange = (`onSync` readyStateChange)
118118
119119xmlHttpRequestSetTimeout :: MonadJSM m => XMLHttpRequest -> Word -> m ()
120120xmlHttpRequestSetTimeout = setTimeout
reflex-dom-core/test/gc.hs+1−1
@@ -47,7 +47,7 @@ failureLimit = 0
4747
4848main :: IO ()
4949main = do
50− handle (\(_ :: IOError) -> return ()) $ unshareNetork -- If we run into an exception with sandboxing, just don't bother
50+ handle (\(_ :: IOError) -> return ()) $ unshareNetwork -- If we run into an exception with sandboxing, just don't bother
5151 withSandboxedChromeFlags True $ \chromeFlags -> do
5252 mainThread <- myThreadId
5353 browserProcess <- spawnCommand $ mconcat
reflex-dom-core/test/hydration.hs+128−29
@@ -1,13 +1,9 @@
1−{-# OPTIONS_GHC -fno-warn-orphans #-}
21{-# LANGUAGE BangPatterns #-}
3−{-# LANGUAGE StandaloneDeriving #-}
4−{-# LANGUAGE GeneralizedNewtypeDeriving #-}
5−{-# LANGUAGE UndecidableInstances #-}
62{-# LANGUAGE ConstraintKinds #-}
7−{-# LANGUAGE CPP #-}
83{-# LANGUAGE FlexibleContexts #-}
94{-# LANGUAGE FlexibleInstances #-}
105{-# LANGUAGE GADTs #-}
6+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
117{-# LANGUAGE LambdaCase #-}
128{-# LANGUAGE MultiParamTypeClasses #-}
139{-# LANGUAGE OverloadedStrings #-}
@@ -15,13 +11,19 @@
1511{-# LANGUAGE RankNTypes #-}
1612{-# LANGUAGE RecursiveDo #-}
1713{-# LANGUAGE ScopedTypeVariables #-}
14+{-# LANGUAGE StandaloneDeriving #-}
1815{-# LANGUAGE TemplateHaskell #-}
1916{-# LANGUAGE TupleSections #-}
2017{-# LANGUAGE TypeApplications #-}
2118{-# LANGUAGE TypeFamilies #-}
19+{-# LANGUAGE UndecidableInstances #-}
20+
21+{-# OPTIONS_GHC -fno-warn-orphans #-}
2222
2323import Prelude hiding (fail)
2424import Control.Concurrent
25+import qualified Control.Concurrent.Async as Async
26+import Control.Lens.Operators
2527import Control.Monad hiding (fail)
2628import Control.Monad.Catch
2729import Control.Monad.Fail
@@ -31,12 +33,13 @@ import Control.Monad.Ref
3133import Data.Constraint.Extras
3234import Data.Constraint.Extras.TH
3335import Data.Dependent.Map (DMap)
34−import Data.Dependent.Sum (DSum(..), (==>), EqTag(..), ShowTag(..))
36+import Data.Dependent.Sum (DSum(..), (==>))
3537import Data.Functor.Identity
3638import Data.Functor.Misc
3739import Data.GADT.Compare.TH
3840import Data.GADT.Show.TH
3941import Data.IORef (IORef)
42+import Data.List (sort)
4043import Data.Maybe
4144import Data.Proxy
4245import Data.Text (Text)
@@ -47,6 +50,7 @@ import Network.Socket
4750import Network.Wai
4851import Network.WebSockets
4952import Reflex.Dom.Core
53+import Reflex.Dom.Widget.Input (dropdown)
5054import Reflex.Patch.DMapWithMove
5155import System.Directory
5256import System.Environment
@@ -55,14 +59,13 @@ import System.IO.Silently
5559import System.IO.Temp
5660import System.Process
5761import System.Which (staticWhich)
58−import qualified Test.HUnit as HUnit (assertEqual, assertFailure)
62+import qualified Test.HUnit as HUnit
5963import qualified Test.Hspec as H
6064import qualified Test.Hspec.Core.Spec as H
6165import Test.Hspec (xit)
6266import Test.Hspec.WebDriver hiding (runWD, click, uploadFile, WD)
6367import qualified Test.Hspec.WebDriver as WD
6468import Test.WebDriver (WD(..))
65−import Test.WebDriver.Exceptions (ServerError(..))
6669
6770import qualified Data.ByteString.Lazy as LBS
6871import qualified Data.Dependent.Map as DMap
@@ -78,6 +81,9 @@ import qualified Test.WebDriver.Capabilities as WD
7881import Test.Util.ChromeFlags
7982import Test.Util.UnshareNetwork
8083
84+-- ORPHAN: https://github.com/kallisti-dev/hs-webdriver/pull/167
85+deriving instance MonadMask WD
86+
8187chromium :: FilePath
8288chromium = $(staticWhich "chromium")
8389
@@ -93,11 +99,14 @@ instance MonadRef WD where
9399 writeRef r = WD . writeRef r
94100
95101assertEqual :: (MonadIO m, Eq a, Show a) => String -> a -> a -> m ()
96−assertEqual a b = liftIO . HUnit.assertEqual a b
102+assertEqual msg a b = liftIO $ HUnit.assertEqual msg a b
97103
98104assertFailure :: MonadIO m => String -> m ()
99105assertFailure = liftIO . HUnit.assertFailure
100106
107+assertBool :: (MonadIO m) => String -> Bool -> m ()
108+assertBool msg bool = liftIO $ HUnit.assertBool msg bool
109+
101110chromeConfig :: Text -> [Text] -> WD.WDConfig
102111chromeConfig fp flags = WD.useBrowser (WD.chrome { WD.chromeBinary = Just $ T.unpack fp, WD.chromeOptions = T.unpack <$> flags }) WD.defaultConfig
103112
@@ -128,7 +137,7 @@ deriving instance MonadFail WD
128137
129138main :: IO ()
130139main = do
131− unshareNetork
140+ unshareNetwork
132141 isHeadless <- (== Nothing) <$> lookupEnv "NO_HEADLESS"
133142 withSandboxedChromeFlags isHeadless $ \chromeFlags -> do
134143 withSeleniumServer $ \selenium -> do
@@ -770,6 +779,15 @@ tests withDebugging wdConfig caps _selenium = do
770779 prerender_ (pure ()) (liftIO $ trigger "Client")
771780 textNode $ TextNodeConfig "Initial" $ Just e
772781
782+ describe "namespaces" $ session' $ do
783+ it "dyn can be nested in namespaced widget" $ runWD $ do
784+ testWidget (pure ()) (checkTextInTag "svg" "one") $ do
785+ let svgRootCfg = def
786+ & (elementConfig_namespace ?~ "http://www.w3.org/2000/svg")
787+ & (elementConfig_initialAttributes .~ ("width" =: "100%" <> "height" =: "100%" <> "viewBox" =: "0 0 1536 2048"))
788+ void $ element "svg" svgRootCfg $ do
789+ dyn_ $ text "one" <$ pure ()
790+
773791 describe "runWithReplace" $ session' $ do
774792 it "works" $ runWD $ do
775793 replaceChan :: Chan Text <- liftIO newChan
@@ -914,6 +932,58 @@ tests withDebugging wdConfig caps _selenium = do
914932 , el "span" . text <$> replace
915933 ]
916934
935+ let checkInnerHtml t x = findElemWithRetry (WD.ByTag t) >>= (`attr` "innerHTML") >>= (`shouldBe` Just x)
936+ it "removes bracketing comments" $ runWD $ do
937+ replaceChan :: Chan () <- liftIO newChan
938+ let
939+ preSwitchover = checkInnerHtml "div" "before|<!--replace-start-0-->inner1<!--replace-end-0-->|after"
940+ check () = do
941+ liftIO $ writeChan replaceChan () -- trigger creation of p tag
942+ _ <- findElemWithRetry $ WD.ByTag "p" -- wait till p tag is created
943+ checkInnerHtml "div" "before|<p>inner2</p>|after"
944+ testWidget' preSwitchover check $ do
945+ replace <- triggerEventWithChan replaceChan
946+ el "div" $ do
947+ text "before|"
948+ _ <- runWithReplace (text "inner1") $ el "p" (text "inner2") <$ replace
949+ text "|after"
950+ it "ignores extra ending bracketing comment" $ runWD $ do
951+ replaceChan :: Chan () <- liftIO newChan
952+ let
953+ preSwitchover = checkInnerHtml "div" "before|<!--replace-start-0-->inner1<!--replace-end-0--><!--replace-end-0-->|after"
954+ check () = do
955+ liftIO $ writeChan replaceChan () -- trigger creation of p tag
956+ _ <- findElemWithRetry $ WD.ByTag "p" -- wait till p tag is created
957+ checkInnerHtml "div" "before|inner2|after"
958+ testWidget' preSwitchover check $ do
959+ replace <- triggerEventWithChan replaceChan
960+ el "div" $ do
961+ text "before|"
962+ _ <- runWithReplace (text "inner1" *> comment "replace-end-0") $ text "inner2" <$ replace
963+ text "|after"
964+ void $ runWithReplace blank $ el "p" blank <$ replace -- Signal tag for end of test
965+ it "ignores missing ending bracketing comments" $ runWD $ do
966+ replaceChan :: Chan () <- liftIO newChan
967+ let
968+ preSwitchover = do
969+ checkInnerHtml "div" "before|<!--replace-start-0-->inner1<!--replace-end-0-->|after"
970+ divEl <- findElemWithRetry (WD.ByTag "div")
971+ let wrongHtml = "<!--replace-start-0-->inner1"
972+ actualHtml :: String <- WD.executeJS
973+ [WD.JSArg divEl, WD.JSArg wrongHtml]
974+ "arguments[0].innerHTML = arguments[1]; return arguments[0].innerHTML"
975+ actualHtml `shouldBe` wrongHtml
976+ check () = do
977+ liftIO $ writeChan replaceChan () -- trigger creation of p tag
978+ _ <- findElemWithRetry $ WD.ByTag "p" -- wait till p tag is created
979+ checkInnerHtml "div" "before|<p>inner2</p>|after"
980+ testWidget' preSwitchover check $ do
981+ replace <- triggerEventWithChan replaceChan
982+ el "div" $ do
983+ text "before|"
984+ _ <- runWithReplace (text "inner1") $ el "p" (text "inner2") <$ replace
985+ text "|after"
986+
917987 describe "traverseDMapWithKeyWithAdjust" $ session' $ do
918988 let widget :: DomBuilder t m => DKey a -> Identity a -> m (Identity a)
919989 widget k (Identity v) = elAttr "li" ("id" =: textKey k) $ do
@@ -1230,6 +1300,29 @@ tests withDebugging wdConfig caps _selenium = do
12301300 el "ol" $ text "inner"
12311301 text "after"
12321302
1303+ -- TODO: This test presupposes the exact set of labels that "dropdown" places in the "value" fields to distinguish options.
1304+ -- This dependence on internal implementation details is undesirable in a test case, but seems fairly tricky to avoid.
1305+ -- It seems expedient for the time being to expect this test case to be updated, should those implementation details ever change.
1306+ describe "dropdown" $ session' $ do
1307+ let doTest expectedOpts (initialValue :: Text) = do
1308+ let doCheck = do
1309+ es <- findElemsWithRetry $ WD.ByTag "option"
1310+ opts <- mapM fetchElement es
1311+ assertEqual "missing/extra/incorrect option element(s)" expectedOpts (sort opts)
1312+ testWidget doCheck doCheck $ do
1313+ void $ dropdown initialValue (constDyn (("aa" :: Text) =: "aaa" <> "bb" =: "bbb")) def
1314+ fetchElement e = do
1315+ val <- WD.attr e "value"
1316+ sel <- WD.attr e "selected"
1317+ return (fromMaybe "" val, isJust sel)
1318+ -- The "aa" test case is important, but a good test implementation probably needs to avoid selenium, because HTML parsers will insert a "selected" attribute on the first "option" tag if no selected attributes are present; thus as written, this erroneously succeeds on the old implementation (but properly implemented, should fail)
1319+ -- Thus, it would appear that we do actually need a HTML5 or maybe XML parser for this test suite.
1320+ xit "statically renders initial values (on aa)" $ runWD $ do
1321+ doTest [("0",True),("1",False)] "aa"
1322+ -- These tests are currently marked "pending" (by using "xit" instead of "it") because this test has a high chance of non-deterministically failing, which is a problem elsewhere in this test suite as well
1323+ xit "statically renders initial values (on bb)" $ runWD $ do
1324+ doTest [("0",False),("1",True)] "bb"
1325+
12331326data Selenium = Selenium
12341327 { _selenium_portNumber :: PortNumber
12351328 , _selenium_stopServer :: IO ()
@@ -1297,6 +1390,9 @@ checkTextInId i expected = do
12971390findElemWithRetry :: Selector -> WD WD.Element
12981391findElemWithRetry = withRetry . WD.findElem
12991392
1393+findElemsWithRetry :: Selector -> WD [WD.Element]
1394+findElemsWithRetry = withRetry . WD.findElems
1395+
13001396getBody :: WD WD.Element
13011397getBody = WD.findElem $ WD.ByTag "body"
13021398
@@ -1305,8 +1401,8 @@ withRetry a = wait 300
13051401 where wait :: Int -> WD a
13061402 wait 0 = a
13071403 wait n = try a >>= \case
1308− Left (_ :: SomeException) -> do
1309− liftIO $ threadDelay 100000
1404+ Left (e :: SomeException) -> do
1405+ liftIO $ putStrLn ("(retrying due to " <> show e <> ")") *> threadDelay 100000
13101406 wait $ n - 1
13111407 Right v -> return v
13121408
@@ -1388,23 +1484,26 @@ testWidgetDebug' withDebugging beforeJS afterSwitchover bodyWidget = do
13881484 ]
13891485 -- hSilence to get rid of ConnectionClosed logs
13901486 silenceIfDebug = if withDebugging then id else hSilence [stderr]
1391− jsaddleWarp = forkIO $ silenceIfDebug $ Warp.runSettings settings application
1392− jsaddleTid <- liftIO jsaddleWarp
1393− putStrLnDebug "taking waitJSaddle"
1394− liftIO $ takeMVar waitJSaddle
1395− putStrLnDebug "opening page"
1396− WD.openPage $ "http://localhost:" <> show jsaddlePort
1397− putStrLnDebug "running beforeJS"
1398− a <- beforeJS
1399− putStrLnDebug "putting waitBeforeJS"
1400− liftIO $ putMVar waitBeforeJS ()
1401− putStrLnDebug "taking waitUntilSwitchover"
1402− liftIO $ takeMVar waitUntilSwitchover
1403− putStrLnDebug "running afterSwitchover"
1404− b <- afterSwitchover a
1405− putStrLnDebug "killing jsaddle thread"
1406− liftIO $ killThread jsaddleTid
1407− return b
1487+ jsaddleWarp = silenceIfDebug $ Warp.runSettings settings application
1488+ withAsync' jsaddleWarp $ do
1489+ putStrLnDebug "taking waitJSaddle"
1490+ liftIO $ takeMVar waitJSaddle
1491+ putStrLnDebug "opening page"
1492+ WD.openPage $ "http://localhost:" <> show jsaddlePort
1493+ putStrLnDebug "running beforeJS"
1494+ a <- beforeJS
1495+ putStrLnDebug "putting waitBeforeJS"
1496+ liftIO $ putMVar waitBeforeJS ()
1497+ putStrLnDebug "taking waitUntilSwitchover"
1498+ liftIO $ takeMVar waitUntilSwitchover
1499+ putStrLnDebug "running afterSwitchover"
1500+ afterSwitchover a
1501+
1502+withAsync' :: (MonadIO m, MonadMask m) => IO a -> m b -> m b
1503+withAsync' f g = bracket
1504+ (liftIO $ Async.async f)
1505+ (liftIO . Async.uninterruptibleCancel)
1506+ (const g)
14081507
14091508data Key2 a where
14101509 Key2_Int :: Int -> Key2 Int
reflex-dom/ChangeLog.md+13
@@ -1,5 +1,17 @@
11# Revision history for reflex-dom
22
3+## 0.6.0.0
4+
5+* ([#379](https://github.com/reflex-frp/reflex-dom/pull/379)) Re-export all modules from `reflex-dom-core`. The newly re-exported modules are:
6+ * `Foreign.JavaScript.Utils`
7+ * `Reflex.Dom.Builder.Hydratable`
8+ * `Reflex.Dom.Modals.Class`
9+ * `Reflex.Dom.Prerender`
10+ * `Reflex.Dom.Time`
11+ * `Reflex.Dom.WebSocket.Query`
12+ * `Reflex.Dom.Xhr.FormData`
13+* ([#366](https://github.com/reflex-frp/reflex-dom/pull/366)) Bump bounds for `reflex` to include 0.7.
14+
315## 0.5.3
416
517* On Android, enable prompting the user for geolocation
@@ -18,4 +30,5 @@
1830## 0.5
1931
2032* Re-export new hydration widget "mainWidget" functions.
33+
2134* The use-warp flag now properly takes precedence on macOS.
reflex-dom/LICENSE+1−1
@@ -1,4 +1,4 @@
1−Copyright (c) 2015, Obsidian Systems LLC
1+Copyright (c) 2020, Obsidian Systems LLC
22All rights reserved.
33
44Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
reflex-dom/benchmark.hs+2−1
@@ -15,8 +15,9 @@ import qualified Data.Text as T
1515import Reflex.Dom
1616import System.Random
1717import qualified Data.Map as Map
18−import Data.Dependent.Map (DMap (..), DSum (..))
18+import Data.Dependent.Map (DMap (..))
1919import qualified Data.Dependent.Map as DMap
20+import Data.Dependent.Sum (DSum (..))
2021import Data.Functor.Misc
2122import Data.Functor.Identity
2223import Data.Functor.Compose
reflex-dom/reflex-dom.cabal+72−21
@@ -1,10 +1,20 @@
1+cabal-version: 1.24
12Name: reflex-dom
2−Version: 0.5.3
3+Version: 0.6.0.0
34Synopsis: Functional Reactive Web Apps with Reflex
45Description:
5− Reflex-DOM is a Functional Reactive web framework based on the Reflex FRP engine.
6+ Web applications without callbacks or side-effects.
7+ Reflex-DOM brings the power of functional reactive programming (FRP) to the web.
8+ Build HTML and other Document Object Model (DOM) data with a pure functional interface.
69 .
7− For hackage documentation, please see: <https://hackage.haskell.org/package/reflex-dom-core>.
10+ Reflex-DOM is a Functional Reactive web framework based on the Reflex FRP engine: <https://reflex-frp.org/>.
11+ .
12+ The @reflex-dom@ package is a small wrapper around the @reflex-dom-core@ package. It pulls in the
13+ correct set of dependencies for each target platform (GHCJS, WebKitGTK, WASM, mobile, etc.).
14+ Libraries should depend on @reflex-dom-core@ and executables will usually depend on @reflex-dom@.
15+ All of @reflex-dom-core@'s modules are re-exported by @reflex-dom@.
16+ .
17+ For Hackage documentation, please see: <https://hackage.haskell.org/package/reflex-dom-core>.
818License: BSD3
919License-file: LICENSE
1020Author: Ryan Trinkle
@@ -12,7 +22,6 @@ Maintainer: ryan.trinkle@gmail.com
1222Stability: Experimental
1323Category: FRP, Web, GUI, HTML, Javascript, Reactive, Reactivity, User Interfaces, User-interface
1424Build-type: Simple
15−cabal-version: >=1.24
1625extra-source-files:
1726 java/org/reflexfrp/reflexdom/MainWidget.java
1827 ChangeLog.md
@@ -41,55 +50,67 @@ flag build-examples
4150 default: False
4251 manual: True
4352
53+flag wasm32
54+ description: Build for wasm32 architecture
55+ default: False
56+ manual: True
57+
4458library
4559 hs-source-dirs: src
4660 if os(android)
4761 hs-source-dirs: src-android
4862 other-modules: Reflex.Dom.Android.MainWidget
4963 build-depends:
50− aeson,
64+ aeson >= 1.4 && < 1.5,
5165 android-activity == 0.1.*,
5266 data-default == 0.7.*,
53− jsaddle
67+ jsaddle >= 0.9.6 && < 0.10
5468 c-sources: cbits/MainWidget.c
5569 include-dirs: cbits/include
5670 install-includes: MainWidget.h
5771 cpp-options: -DANDROID
5872 build-tools: hsc2hs
5973 build-depends:
60− base >= 4.7 && < 4.13,
74+ base >= 4.7 && < 4.14,
6175 bytestring == 0.10.*,
62− reflex >= 0.6.2 && < 0.7,
63− reflex-dom-core >=0.5.2 && < 0.6,
76+ reflex >= 0.6.2 && < 0.8,
77+ reflex-dom-core == 0.6.0.0,
6478 text == 1.2.*
6579 if !impl(ghcjs)
6680 if flag(use-warp) && (os(linux) || os(osx))
6781 build-depends:
68− jsaddle,
69− jsaddle-warp
82+ jsaddle >= 0.9.6 && < 0.10,
83+ jsaddle-warp >= 0.9.6 && < 0.10
7084 else
7185 if os(osx) || os(ios)
7286 build-depends:
7387 data-default == 0.7.*,
74− jsaddle,
75− jsaddle-wkwebview
88+ jsaddle >= 0.9.6 && < 0.10,
89+ jsaddle-wkwebview >= 0.9.6 && < 0.10
7690 else
77− if flag(webkit2gtk)
91+ if flag(wasm32)
7892 build-depends:
79− jsaddle-webkit2gtk
93+ jsaddle >= 0.9.6 && < 0.10,
94+ jsaddle-wasm >= 0.1 && < 0.2
8095 else
81− if !os(android)
96+ if flag(webkit2gtk)
8297 build-depends:
83− jsaddle-webkit2gtk
98+ jsaddle-webkit2gtk >= 0.9.6 && < 0.10
99+ else
100+ if !os(android)
101+ build-depends:
102+ jsaddle-webkit2gtk >= 0.9.6 && < 0.10
84103
85104 exposed-modules:
86105 Reflex.Dom
87106 Reflex.Dom.Internal
88107 reexported-modules:
89− Foreign.JavaScript.TH
90− , Foreign.JavaScript.Orphans
108+ Foreign.JavaScript.Orphans
109+ , Foreign.JavaScript.TH
110+ , Foreign.JavaScript.Utils
91111 , Reflex.Dom.Builder.Class
92112 , Reflex.Dom.Builder.Class.Events
113+ , Reflex.Dom.Builder.Hydratable
93114 , Reflex.Dom.Builder.Immediate
94115 , Reflex.Dom.Builder.InputDisabled
95116 , Reflex.Dom.Builder.Static
@@ -97,14 +118,19 @@ library
97118 , Reflex.Dom.Core
98119 , Reflex.Dom.Location
99120 , Reflex.Dom.Main
121+ , Reflex.Dom.Modals.Class
100122 , Reflex.Dom.Old
123+ , Reflex.Dom.Prerender
124+ , Reflex.Dom.Time
101125 , Reflex.Dom.WebSocket
126+ , Reflex.Dom.WebSocket.Query
102127 , Reflex.Dom.Widget
103128 , Reflex.Dom.Widget.Basic
104129 , Reflex.Dom.Widget.Input
105130 , Reflex.Dom.Widget.Lazy
106131 , Reflex.Dom.Widget.Resize
107132 , Reflex.Dom.Xhr
133+ , Reflex.Dom.Xhr.FormData
108134 ghc-options: -Wall -fwarn-tabs -funbox-strict-fields -O2 -ferror-spans
109135 if flag(expose-all-unfoldings)
110136 ghc-options: -fexpose-all-unfoldings
@@ -136,7 +162,19 @@ executable sortableList
136162 default-language: Haskell2010
137163
138164executable benchmark
139− build-depends: base, reflex, reflex-dom, text, prim-uniq, dependent-map, containers, transformers, mtl, ghcjs-dom, ghc-prim, random, dependent-sum
165+ build-depends: base
166+ , containers
167+ , dependent-map
168+ , dependent-sum
169+ , ghc-prim
170+ , ghcjs-dom
171+ , mtl
172+ , prim-uniq
173+ , random
174+ , reflex
175+ , reflex-dom
176+ , text
177+ , transformers
140178 hs-source-dirs: .
141179 main-is: benchmark.hs
142180 ghc-options: -O2 -fspecialise-aggressively
@@ -145,7 +183,20 @@ executable benchmark
145183 default-language: Haskell2010
146184
147185executable krausest
148− build-depends: base, reflex, reflex-dom, text, prim-uniq, dependent-map, containers, transformers, mtl, ghcjs-dom, ghc-prim, random, dependent-sum, vector
186+ build-depends: base
187+ , containers
188+ , dependent-map
189+ , dependent-sum
190+ , ghc-prim
191+ , ghcjs-dom
192+ , mtl
193+ , prim-uniq
194+ , random
195+ , reflex
196+ , reflex-dom
197+ , text
198+ , transformers
199+ , vector
149200 hs-source-dirs: benchmarks
150201 main-is: krausest.hs
151202 ghc-options: -O2 -fspecialise-aggressively
reflex-dom/src/Reflex/Dom/Internal.hs+5
@@ -80,6 +80,11 @@ run jsm = do
8080 startMainWidget a startPage jsm
8181 }
8282 forever $ threadDelay 1000000000
83+#elif defined(wasm32_HOST_ARCH)
84+import qualified Language.Javascript.JSaddle.Wasm as Wasm (run)
85+import Language.Javascript.JSaddle (JSM)
86+run :: JSM () -> IO ()
87+run = Wasm.run 0
8388#else
8489import Language.Javascript.JSaddle.WebKitGTK (run)
8590#endif
release.nix+13−4
@@ -1,12 +1,14 @@
11{ reflex-platform-fun ? import ./dep/reflex-platform
2+, supportedSystems ? ["x86_64-linux" "x86_64-darwin"]
23}:
34
45let
56 native-reflex-platform = reflex-platform-fun {};
67 inherit (native-reflex-platform.nixpkgs) lib;
7− systems = ["x86_64-linux" "x86_64-darwin"];
88
9− perPlatform = lib.genAttrs systems (system: let
9+ tests = system: import ./test { pkgs = (reflex-platform-fun { inherit system; }).nixpkgs; };
10+
11+ perPlatform = lib.genAttrs supportedSystems (system: let
1012 reflex-platform = reflex-platform-fun { inherit system; };
1113 compilers = [
1214 "ghc"
@@ -25,15 +27,22 @@ let
2527 (self: super: {
2628 _dep = super._dep // {
2729 reflex-dom = builtins.filterSource (path: type: !(builtins.elem (baseNameOf path) [
28− "release.nix"
2930 ".git"
3031 "dist"
32+ "dist-newstyle"
33+ ]) && !(builtins.elem path [
34+ ./CONTRIBUTING.md
35+ ./FAQ.md
36+ ./Quickref.md
37+ ./README.md
38+ ./release.nix
39+ ./test
3140 ])) ./.;
3241 };
3342 })
3443 ];
3544 };
36− all = {
45+ all = tests system // {
3746 inherit (reflex-platform.${ghc})
3847 reflex-dom-core
3948 reflex-dom
test/default.nixnew file+10
@@ -0,0 +1,10 @@
1+{ pkgs ? (import ../dep/reflex-platform {}).nixpkgs }:
2+{
3+ test-reflex-dom-reexports = pkgs.runCommand "test-reflex-dom-reexports" {} (
4+ let
5+ ghc = pkgs.haskellPackages.ghcWithPackages (p: [p.Cabal]);
6+ in ''
7+ ${ghc}/bin/runhaskell ${./reflex-dom-reexports.hs} ${../reflex-dom/reflex-dom.cabal} ${../reflex-dom-core/reflex-dom-core.cabal}
8+ touch "$out"
9+ '');
10+}
test/prebuild.hsdeleted−127
@@ -1,127 +0,0 @@
1−{-# LANGUAGE CPP #-}
2−{-# LANGUAGE OverloadedStrings #-}
3−{-# LANGUAGE ScopedTypeVariables #-}
4−{-# LANGUAGE TypeFamilies #-}
5−{-# LANGUAGE LambdaCase #-}
6−{-# LANGUAGE FlexibleInstances #-}
7−{-# LANGUAGE MultiParamTypeClasses #-}
8−import Control.Monad
9−import Control.Monad.Identity
10−import Control.Monad.Trans
11−import Reflex.Dom
12−import qualified Data.Text as T
13−import Control.Concurrent
14−
15−import Control.Monad.State.Strict
16−import Data.Functor.Misc
17−import Data.Monoid
18−import Data.Word
19−import qualified Data.Map as Map
20−import qualified Data.Dependent.Map as DMap
21−import Data.Dependent.Sum
22−import qualified Reflex.Patch.DMapWithMove as PatchDMapWithMove
23−
24−main :: IO ()
25−main = mainWidget w
26−
27−w :: forall t m. (MonadWidget t m, DomRenderHook t m, MountableDomBuilder t m) => m ()
28−w = do
29− let slow :: forall m'. (MonadWidget t m', DomRenderHook t m') => m' ()
30− {-
31− performEventChain = do
32− postBuild <- delay 0 =<< getPostBuild
33− rec let maxN = 10000
34− n = leftmost [0 <$ postBuild, ffilter (<=maxN) $ succ <$> n']
35− n' <- performEvent $ return <$> n
36− pausedUntil $ ffilter (==maxN) n'
37− _ <- widgetHold (text "Starting") $ text . T.pack . show <$> n
38− return ()
39− -}
40−-- {- Many dyns
41− slow = elAttr "div" ("style" =: "position:relative;width:256px;height:256px") $ go maxDepth
42− where maxDepth = 6 :: Int
43− go 0 = blank
44− go n = void $ dyn $ pure $ do
45− let bgcolor = "rgba(0,0,0," <> T.pack (show (1 - (fromIntegral n / fromIntegral maxDepth) :: Double)) <> ")"
46− s pos = pos <> ";position:absolute;border:1px solid white;background-color:" <> bgcolor
47− elAttr "div" ("style" =: s "left:0;right:50%;top:0;bottom:50%") $ go $ pred n
48− elAttr "div" ("style" =: s "left:50%;right:0;top:0;bottom:50%") $ go $ pred n
49− elAttr "div" ("style" =: s "left:50%;right:0;top:50%;bottom:0") $ go $ pred n
50− elAttr "div" ("style" =: s "left:0;right:50%;top:50%;bottom:0") $ go $ pred n
51−-- -}
52− {- Many elDynAttrs
53− slow = do
54− let size = 64
55− replicateM_ size $ elAttr "div" ("style" =: ("height:4px;width:" <> T.pack (show (size*4)) <> "px;line-height:0;background-color:gray")) $ do
56− replicateM_ size $ elDynAttr "div" (pure $ "style" =: "display:inline-block;width:4px;height:4px;background-color:black") blank
57− -}
58− {- Many dynTexts
59− slow = el "table" $ do
60− let size = 64
61− replicateM_ size $ el "tr" $ do
62− replicateM_ size $ el "td" $ do
63− dynText $ pure "."
64− -}
65− {- Many simultaneous performEvents
66− slow = do
67− postBuild <- getPostBuild
68− replicateM_ ((2 :: Int) ^ (14 :: Int)) $ performEvent_ $ return () <$ postBuild
69− done <- performEvent $ return () <$ postBuild
70− _ <- widgetHold (text "Doing performEvent") $ text "Done" <$ done
71− return ()
72− -}
73− {-
74− slow = do
75− postBuild <- getPostBuild
76− postBuild' <- performEvent . (return () <$) =<< performEvent . (return () <$) =<< getPostBuild
77− let f x = Map.fromList [(n, x) | n <- [1 :: Int .. 4096]]
78− listHoldWithKey (f False) (f (Just True) <$ postBuild') $ \k -> \case
79− False -> do
80− text "X "
81− notReadyUntil =<< getPostBuild
82− True -> do
83− text ". "
84− return ()
85− -}
86− {-
87− slow = do
88− let f :: forall a. EitherTag () () a -> Const2 () () a -> m' (Const2 () () a)
89− f _ (Const2 ()) = do
90− notReadyUntil =<< delay 0.5 =<< getPostBuild
91− text "Done"
92− return $ Const2 ()
93− postBuild <- getPostBuild
94− traverseDMapWithKeyWithAdjustWithMove f (DMap.singleton LeftTag $ Const2 ()) $ (PatchDMapWithMove.moveDMapKey LeftTag RightTag) <$ postBuild
95− return ()
96− -}
97− {-
98− slow = do
99− let h x = do
100− liftIO $ putStrLn "render hook"
101− result <- x
102− liftIO $ putStrLn "render hook done"
103− return result
104− f :: forall a. Const2 () () a -> Identity a -> m' (Identity a)
105− f (Const2 ()) (Identity ()) = do
106− liftIO $ putStrLn "f"
107− widgetHold notReady . (blank <$) =<< delay 0.1 =<< getPostBuild
108− liftIO $ putStrLn "f done"
109− return $ Identity ()
110− withRenderHook h $ do
111− postBuild <- getPostBuild
112− _ <- traverseDMapWithKeyWithAdjust f mempty $ PatchDMap (DMap.singleton (Const2 () :: Const2 () () ()) (ComposeMaybe $ Just $ Identity ())) <$ postBuild
113− return ()
114− -}
115− el "div" $ do
116− draw <- button "Draw"
117− widgetHold blank $ ffor draw $ \_ -> do
118− _ <- untilReady (text "Loading...") slow
119− return ()
120− return ()
121−
122−#ifdef EXPERIMENTAL_DEPENDENT_SUM_INSTANCES
123−instance {-# INCOHERENT #-} (Show (f a), Show (f b)) => ShowTag (EitherTag a b) f where
124− showTagToShow e _ = case e of
125− LeftTag -> id
126− RightTag -> id
127−#endif
test/reflex-dom-reexports.hsnew file+72
@@ -0,0 +1,72 @@
1+-- This tests that reflex-dom re-exports all of reflex-dom-core's modules.
2+-- Without this test they easily drift.
3+module Main where
4+
5+import Control.Monad (when)
6+import Data.List (intercalate)
7+import Data.Maybe (fromMaybe, isNothing, mapMaybe)
8+import qualified Data.Set as Set
9+import Distribution.Types.PackageName (mkPackageName)
10+import Distribution.Compiler (CompilerFlavor (GHC))
11+import Distribution.ModuleName (ModuleName, components)
12+import Distribution.PackageDescription.Parsec (parseGenericPackageDescription)
13+import qualified Distribution.Parsec.Common as Dist
14+import Distribution.Parsec.ParseResult (runParseResult)
15+import qualified Distribution.System as Dist
16+import Distribution.Types.BuildInfo (buildable, defaultExtensions, defaultLanguage, hsSourceDirs, options)
17+import Distribution.Types.CondTree (simplifyCondTree)
18+import Distribution.Types.GenericPackageDescription (ConfVar (Arch, Impl, OS), condLibrary)
19+import Distribution.Types.Library (exposedModules, libBuildInfo, reexportedModules)
20+import Distribution.Types.ModuleReexport (ModuleReexport, moduleReexportOriginalName, moduleReexportOriginalPackage)
21+import Distribution.Utils.Generic (toUTF8BS, readUTF8File)
22+import System.Environment (getArgs)
23+import qualified System.Info
24+
25+main :: IO ()
26+main = do
27+ [reflexDomFile, reflexDomCoreFile] <- getArgs
28+ (_, reflexDomReexports) <- parseCabalExports reflexDomFile
29+ (reflexDomCoreExports', _) <- parseCabalExports reflexDomCoreFile
30+
31+ let
32+ reflexDomCoreExports = Set.fromList reflexDomCoreExports'
33+ reflexDomCorePackageName = mkPackageName "reflex-dom-core"
34+ reflexDomReexportsFromCore
35+ = Set.fromList
36+ $ mapMaybe (\x -> if let origPackage = moduleReexportOriginalPackage x
37+ in isNothing origPackage || origPackage == Just reflexDomCorePackageName
38+ then Just $ moduleReexportOriginalName x
39+ else Nothing
40+ )
41+ reflexDomReexports
42+
43+ when (reflexDomCoreExports /= reflexDomReexportsFromCore) $ do
44+ error $ intercalate "\n\t"
45+ $ "reflex-dom does not re-export the following modules from reflex-dom-core:"
46+ : map
47+ (intercalate "." . components)
48+ (Set.toAscList $ reflexDomCoreExports `Set.difference` reflexDomReexportsFromCore)
49+
50+ putStrLn "Test passed."
51+
52+parseCabalExports :: FilePath -> IO ([ModuleName], [ModuleReexport])
53+parseCabalExports file = do
54+ contents <- readUTF8File file
55+ let
56+ (warnings, result) = runParseResult $ parseGenericPackageDescription $ toUTF8BS contents
57+ osConfVar = case System.Info.os of
58+ "linux" -> Just Dist.Linux
59+ "darwin" -> Just Dist.OSX
60+ _ -> error "Unrecognized System.Info.os"
61+ archConfVar = Just Dist.X86_64
62+ evalConfVar v = Right $ case v of
63+ OS osVar -> Just osVar == osConfVar
64+ Arch archVar -> Just archVar == archConfVar
65+ Impl GHC _ -> True
66+ _ -> False
67+ pure $ case condLibrary <$> result of
68+ Right (Just condLib) ->
69+ let (_, lib) = simplifyCondTree evalConfVar condLib
70+ in (exposedModules lib, reexportedModules lib)
71+ Right Nothing -> error $ "Haskell package has no library component: " <> file
72+ Left (_, errors) -> error $ "Failed to parse " <> file <> ":\n" <> unlines (map show errors)