@@ -6,6 +6,9 @@ module Functora.Miso.Widgets.Field
6
6
OptsWidget (.. ),
7
7
OptsWidgetPair (.. ),
8
8
ModalWidget' (.. ),
9
+ truncateUnicode ,
10
+ truncateDynamicField ,
11
+ expandDynamicField ,
9
12
field ,
10
13
ratioField ,
11
14
textField ,
@@ -198,7 +201,7 @@ field full@Full {fullArgs = args, fullParser = parser, fullViewer = viewer} opts
198
201
. # uniqueUid
199
202
getInput st' =
200
203
st' ^? cloneTraversal optic . # fieldInput . # uniqueValue
201
- getOutput st' = do
204
+ getOutput st' =
202
205
(st' ^? cloneTraversal optic >>= parser)
203
206
<|> (st' ^? cloneTraversal optic . # fieldOutput)
204
207
getInputReplacement st' = do
@@ -872,7 +875,7 @@ genericFieldViewer args widget =
872
875
[ Css. fullWidth
873
876
]
874
877
$ [ widget
875
- $ truncateFieldInput
878
+ $ truncateFieldViewer
876
879
allowTrunc
877
880
stateTrunc
878
881
(opts ^. # fieldOptsTruncateLimit)
@@ -966,20 +969,51 @@ fieldViewerIcon icon action =
966
969
)
967
970
icon
968
971
969
- truncateFieldInput ::
972
+ truncateFieldViewer ::
970
973
Bool ->
971
974
OpenedOrClosed ->
972
975
Maybe Int ->
973
976
Unicode ->
974
977
Unicode
975
- truncateFieldInput True Closed limit full =
976
- let half = fromMaybe defTruncateLimit limit `div` 2
977
- in take half full
978
- <> " ..."
979
- <> MS. takeEnd half full
980
- truncateFieldInput _ _ _ full =
978
+ truncateFieldViewer True Closed limit full =
979
+ truncateUnicode limit full
980
+ truncateFieldViewer _ _ _ full =
981
981
full
982
982
983
+ truncateDynamicField ::
984
+ Maybe Int ->
985
+ Field DynamicField Identity ->
986
+ Field DynamicField Identity
987
+ truncateDynamicField limit =
988
+ (# fieldInput . # runIdentity %~ truncateUnicode limit)
989
+ . ( # fieldOutput %~ \ case
990
+ DynamicFieldNumber {} -> DynamicFieldNumber 0
991
+ DynamicFieldText {} -> DynamicFieldText mempty
992
+ )
993
+
994
+ truncateUnicode :: Maybe Int -> Unicode -> Unicode
995
+ truncateUnicode limit input =
996
+ if length input <= full
997
+ then input
998
+ else
999
+ take half input
1000
+ <> " ..."
1001
+ <> MS. takeEnd half input
1002
+ where
1003
+ full = fromMaybe defTruncateLimit limit
1004
+ half = full `div` 2
1005
+
1006
+ expandDynamicField ::
1007
+ Field DynamicField Identity ->
1008
+ Field DynamicField Identity
1009
+ expandDynamicField x =
1010
+ if null inp
1011
+ then x & # fieldInput . # runIdentity .~ inspectDynamicField out
1012
+ else x & # fieldOutput .~ fromMaybe out (parseDynamicFieldId x)
1013
+ where
1014
+ inp = x ^. # fieldInput . # runIdentity
1015
+ out = x ^. # fieldOutput
1016
+
983
1017
insertAction ::
984
1018
Full model action t Unique ->
985
1019
((Maybe Unicode -> JSM () ) -> JSM () ) ->
0 commit comments