@@ -43,22 +43,27 @@ module Functora.Miso.Types
43
43
uniqueToIdentity ,
44
44
identityToUnique ,
45
45
keyed ,
46
+ appendAttrs ,
46
47
prependViews ,
47
48
TopOrBottom (.. ),
48
49
OnlineOrOffline (.. ),
49
50
StaticOrDynamic (.. ),
50
51
LeadingOrTrailing (.. ),
52
+ FocusedOrBlurred (.. ),
51
53
OpenedOrClosed (.. ),
52
54
Update (.. ),
53
55
unUpdate ,
54
56
themeCssFile ,
57
+ noopAll ,
58
+ noop ,
55
59
module X ,
56
60
)
57
61
where
58
62
59
63
import Data.Foldable (foldMap )
60
64
import Data.Functor.Barbie
61
65
import qualified Data.Generics as Syb
66
+ import qualified Data.Map as Map
62
67
import Functora.Cfg
63
68
import Functora.Miso.Prelude
64
69
import Functora.Miso.Theme as X (Theme )
@@ -122,6 +127,7 @@ data Field a f = Field
122
127
fieldInput :: f Unicode ,
123
128
fieldOutput :: a ,
124
129
fieldModalState :: OpenedOrClosed ,
130
+ fieldFocusState :: FocusedOrBlurred ,
125
131
fieldRequired :: Bool ,
126
132
fieldOpts :: FieldOpts
127
133
}
@@ -176,6 +182,7 @@ newField typ output newInput = do
176
182
fieldInput = input,
177
183
fieldOutput = output,
178
184
fieldModalState = Closed ,
185
+ fieldFocusState = Blurred ,
179
186
fieldRequired = False ,
180
187
fieldOpts = defFieldOpts
181
188
}
@@ -187,6 +194,7 @@ newFieldId typ viewer output =
187
194
fieldInput = Identity $ viewer output,
188
195
fieldOutput = output,
189
196
fieldModalState = Closed ,
197
+ fieldFocusState = Blurred ,
190
198
fieldRequired = False ,
191
199
fieldOpts = defFieldOpts
192
200
}
@@ -497,6 +505,11 @@ keyed key = \case
497
505
Node x0 x1 Nothing x2 x3 -> Node x0 x1 (Just $ Miso. Key key) x2 x3
498
506
x -> x
499
507
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
+
500
513
prependViews :: [View action ] -> View action -> View action
501
514
prependViews xs = \ case
502
515
Node a b c d e -> Node a b c d $ xs <> e
@@ -526,6 +539,12 @@ data LeadingOrTrailing
526
539
deriving stock (Eq , Ord , Show , Read , Enum , Bounded , Data , Generic )
527
540
deriving (Binary ) via GenericType LeadingOrTrailing
528
541
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
+
529
548
data OpenedOrClosed
530
549
= Opened
531
550
| Closed
@@ -554,3 +573,22 @@ themeCssFile =
554
573
. from @ String @ Unicode
555
574
. Casing. kebab
556
575
. 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