@@ -43,22 +43,27 @@ module Functora.Miso.Types
4343 uniqueToIdentity ,
4444 identityToUnique ,
4545 keyed ,
46+ appendAttrs ,
4647 prependViews ,
4748 TopOrBottom (.. ),
4849 OnlineOrOffline (.. ),
4950 StaticOrDynamic (.. ),
5051 LeadingOrTrailing (.. ),
52+ FocusedOrBlurred (.. ),
5153 OpenedOrClosed (.. ),
5254 Update (.. ),
5355 unUpdate ,
5456 themeCssFile ,
57+ noopAll ,
58+ noop ,
5559 module X ,
5660 )
5761where
5862
5963import Data.Foldable (foldMap )
6064import Data.Functor.Barbie
6165import qualified Data.Generics as Syb
66+ import qualified Data.Map as Map
6267import Functora.Cfg
6368import Functora.Miso.Prelude
6469import Functora.Miso.Theme as X (Theme )
@@ -122,6 +127,7 @@ data Field a f = Field
122127 fieldInput :: f Unicode ,
123128 fieldOutput :: a ,
124129 fieldModalState :: OpenedOrClosed ,
130+ fieldFocusState :: FocusedOrBlurred ,
125131 fieldRequired :: Bool ,
126132 fieldOpts :: FieldOpts
127133 }
@@ -176,6 +182,7 @@ newField typ output newInput = do
176182 fieldInput = input,
177183 fieldOutput = output,
178184 fieldModalState = Closed ,
185+ fieldFocusState = Blurred ,
179186 fieldRequired = False ,
180187 fieldOpts = defFieldOpts
181188 }
@@ -187,6 +194,7 @@ newFieldId typ viewer output =
187194 fieldInput = Identity $ viewer output,
188195 fieldOutput = output,
189196 fieldModalState = Closed ,
197+ fieldFocusState = Blurred ,
190198 fieldRequired = False ,
191199 fieldOpts = defFieldOpts
192200 }
@@ -497,6 +505,11 @@ keyed key = \case
497505 Node x0 x1 Nothing x2 x3 -> Node x0 x1 (Just $ Miso. Key key) x2 x3
498506 x -> x
499507
508+ appendAttrs :: [Attribute action ] -> View action -> View action
509+ appendAttrs attrs = \ case
510+ Node x0 x1 x2 x3 x4 -> Node x0 x1 x2 (x3 <> attrs) x4
511+ x -> x
512+
500513prependViews :: [View action ] -> View action -> View action
501514prependViews xs = \ case
502515 Node a b c d e -> Node a b c d $ xs <> e
@@ -526,6 +539,12 @@ data LeadingOrTrailing
526539 deriving stock (Eq , Ord , Show , Read , Enum , Bounded , Data , Generic )
527540 deriving (Binary ) via GenericType LeadingOrTrailing
528541
542+ data FocusedOrBlurred
543+ = Focused
544+ | Blurred
545+ deriving stock (Eq , Ord , Show , Read , Enum , Bounded , Data , Generic )
546+ deriving (Binary ) via GenericType FocusedOrBlurred
547+
529548data OpenedOrClosed
530549 = Opened
531550 | Closed
@@ -554,3 +573,22 @@ themeCssFile =
554573 . from @ String @ Unicode
555574 . Casing. kebab
556575 . inspect @ String
576+
577+ noopAll :: (Update model -> action ) -> [Attribute action ]
578+ noopAll action =
579+ fmap (noop action)
580+ $ Map. keys defaultEvents
581+
582+ noop :: (Update model -> action ) -> Unicode -> Attribute action
583+ noop action event =
584+ onWithOptions
585+ defaultOptions
586+ { preventDefault = True ,
587+ stopPropagation = True
588+ }
589+ event
590+ emptyDecoder
591+ . const
592+ . action
593+ . EffectUpdate
594+ $ pure ()
0 commit comments