@@ -5,7 +5,6 @@ module Functora.Miso.Widgets.Field
5
5
defOpts ,
6
6
OptsWidget (.. ),
7
7
ModalWidget' (.. ),
8
- ViewerArgs (.. ),
9
8
ViewerOpts (.. ),
10
9
defViewerOpts ,
11
10
field ,
@@ -37,17 +36,17 @@ import qualified Material.Theme as Theme
37
36
import qualified Material.Typography as Typography
38
37
import qualified Miso.String as MS
39
38
40
- data Args model action item = Args
39
+ data Args model action t f = Args
41
40
{ argsModel :: model ,
42
- argsOptic :: ATraversal' model (Field item Unique ),
41
+ argsOptic :: ATraversal' model (Field t f ),
43
42
argsAction :: (model -> JSM model ) -> action
44
43
}
45
44
deriving stock (Generic )
46
45
47
- data Full model action item = Full
48
- { fullArgs :: Args model action item ,
49
- fullParser :: Field item Unique -> Maybe item ,
50
- fullViewer :: item -> MisoString
46
+ data Full model action t f = Full
47
+ { fullArgs :: Args model action t f ,
48
+ fullParser :: Field t f -> Maybe t ,
49
+ fullViewer :: t -> MisoString
51
50
}
52
51
deriving stock (Generic )
53
52
@@ -115,13 +114,6 @@ data ModalWidget' model where
115
114
ATraversal' model (Field a Unique ) ->
116
115
ModalWidget' model
117
116
118
- data ViewerArgs model action t f = ViewerArgs
119
- { viewerArgsModel :: model ,
120
- viewerArgsOptic :: Getter' model (Field t f ),
121
- viewerArgsAction :: (model -> JSM model ) -> action
122
- }
123
- deriving stock (Generic )
124
-
125
117
data ViewerOpts model = ViewerOpts
126
118
{ viewerOptsQrOptic :: Maybe (ATraversal' model OpenedOrClosed ),
127
119
viewerOptsTruncateOptic :: Maybe (ATraversal' model OpenedOrClosed ),
@@ -141,7 +133,7 @@ defTruncateLimit :: Int
141
133
defTruncateLimit = 67
142
134
143
135
field ::
144
- Full model action item ->
136
+ Full model action t Unique ->
145
137
Opts model action ->
146
138
View action
147
139
field Full {fullArgs = args, fullParser = parser, fullViewer = viewer} opts =
@@ -238,7 +230,7 @@ field Full {fullArgs = args, fullParser = parser, fullViewer = viewer} opts =
238
230
%~ maybe id (const . id ) (getOutput next)
239
231
240
232
ratioField ::
241
- Args model action Rational ->
233
+ Args model action Rational Unique ->
242
234
Opts model action ->
243
235
View action
244
236
ratioField args =
@@ -250,7 +242,7 @@ ratioField args =
250
242
}
251
243
252
244
textField ::
253
- Args model action MisoString ->
245
+ Args model action MisoString Unique ->
254
246
Opts model action ->
255
247
View action
256
248
textField args =
@@ -262,7 +254,7 @@ textField args =
262
254
}
263
255
264
256
dynamicField ::
265
- Args model action DynamicField ->
257
+ Args model action DynamicField Unique ->
266
258
Opts model action ->
267
259
View action
268
260
dynamicField args =
@@ -274,7 +266,7 @@ dynamicField args =
274
266
}
275
267
276
268
passwordField ::
277
- Args model action MisoString ->
269
+ Args model action MisoString Unique ->
278
270
Opts model action ->
279
271
View action
280
272
passwordField args opts =
@@ -289,7 +281,7 @@ passwordField args opts =
289
281
290
282
fieldIcon ::
291
283
LeadingOrTrailing ->
292
- Args model action item ->
284
+ Args model action t Unique ->
293
285
Opts model action ->
294
286
OptsWidget model action ->
295
287
TextField. Icon action
@@ -407,7 +399,7 @@ fieldIconSimple lot txt attrs action =
407
399
)
408
400
txt
409
401
410
- fieldModal :: Args model action item -> ModalWidget' model -> [View action ]
402
+ fieldModal :: Args model action t f -> ModalWidget' model -> [View action ]
411
403
fieldModal args@ Args {argsAction = action} (ModalItemWidget opt idx fps lbl ooc) =
412
404
Dialog. dialog
413
405
Dialog. Args
@@ -659,7 +651,7 @@ fieldModal args (ModalMiniWidget opt) =
659
651
}
660
652
661
653
selectTypeWidget ::
662
- Args model action item ->
654
+ Args model action t f ->
663
655
ATraversal' model (Field a Unique ) ->
664
656
View action
665
657
selectTypeWidget args@ Args {argsAction = action} optic =
@@ -772,22 +764,26 @@ cell Opts {optsFullWidth = full} =
772
764
fieldViewer ::
773
765
( Foldable1 f
774
766
) =>
775
- ViewerArgs model action t f ->
767
+ Args model action t f ->
776
768
ViewerOpts model ->
777
769
[View action ]
778
770
fieldViewer args opts =
779
- case value ^. # fieldType of
771
+ case typ of
780
772
FieldTypeNumber -> genericFieldViewer args opts text
781
773
FieldTypePercent -> genericFieldViewer args opts $ text . (<> " %" )
782
774
FieldTypeText -> genericFieldViewer args opts text
783
- FieldTypeTitle -> header input
775
+ FieldTypeTitle -> header val
784
776
FieldTypeHtml ->
785
777
genericFieldViewer args opts {viewerOptsTruncateLimit = Nothing } rawHtml
786
778
FieldTypePassword -> genericFieldViewer args opts $ const " *****"
787
- FieldTypeQrCode -> Qr. qr input <> genericFieldViewer args opts text
779
+ FieldTypeQrCode -> Qr. qr val <> genericFieldViewer args opts text
788
780
where
789
- value = args ^. # viewerArgsModel . viewerArgsOptic args
790
- input = fold1 $ value ^. # fieldInput
781
+ opt =
782
+ # argsModel . argsOptic args
783
+ typ =
784
+ fromMaybe FieldTypeText $ args ^? cloneTraversal opt . # fieldType
785
+ val =
786
+ maybe mempty fold1 $ args ^? cloneTraversal opt . # fieldInput
791
787
792
788
header :: MisoString -> [View action ]
793
789
header txt =
@@ -806,7 +802,7 @@ header txt =
806
802
genericFieldViewer ::
807
803
( Foldable1 f
808
804
) =>
809
- ViewerArgs model action t f ->
805
+ Args model action t f ->
810
806
ViewerOpts model ->
811
807
(MisoString -> View action ) ->
812
808
[View action ]
@@ -854,24 +850,24 @@ genericFieldViewer args opts widget =
854
850
]
855
851
]
856
852
where
857
- st = args ^. # viewerArgsModel
858
- value = st ^. viewerArgsOptic args
859
- input = fold1 $ value ^. # fieldInput
860
- action = args ^. # viewerArgsAction
861
- stateQr = fromMaybe Closed $ do
862
- trav <- opts ^. # viewerOptsQrOptic
863
- st ^? cloneTraversal trav
853
+ opt =
854
+ # argsModel . argsOptic args
855
+ input =
856
+ maybe mempty fold1 $ args ^? cloneTraversal opt . # fieldInput
857
+ action =
858
+ args ^. # argsAction
859
+ fopts =
860
+ fromMaybe defFieldOpts $ args ^? cloneTraversal opt . # fieldOpts
861
+ stateQr =
862
+ fromMaybe Closed $ fopts ^. # fieldOptsQrState
864
863
allowCopy =
865
- value ^. # fieldAllowCopy
864
+ fopts ^. # fieldOptsAllowCopy
866
865
allowTrunc =
867
- maybe False (MS. length input > )
868
- $ opts
869
- ^. # viewerOptsTruncateLimit
866
+ maybe False (MS. length input > ) $ fopts ^. # fieldOptsTruncateLimit
870
867
opticTrunc =
871
868
opts ^. # viewerOptsTruncateOptic
872
- stateTrunc = fromMaybe Closed $ do
873
- trav <- opticTrunc
874
- st ^? cloneTraversal trav
869
+ stateTrunc =
870
+ fromMaybe Closed $ fopts ^. # fieldOptsTruncateState
875
871
extraWidgets =
876
872
( if not allowTrunc
877
873
then mempty
0 commit comments