Skip to content

Commit 90ec081

Browse files
committed
dynamic extra widgets on fields
1 parent 4844d09 commit 90ec081

File tree

10 files changed

+177
-131
lines changed

10 files changed

+177
-131
lines changed

ghcjs/delivery-calculator/delivery-calculator.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 2.2
22
name: delivery-calculator
3-
version: 0.1.0.6
3+
version: 0.1.0.7
44
synopsis: Delivery Calculator
55
category: Web
66
build-type: Simple

ghcjs/delivery-calculator/src/App/Types.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,10 @@ stUri st = do
406406
uri <- mkURI $ from @Unicode @Prelude.Text baseUri
407407
qxs <-
408408
stQuery
409+
. Syb.everywhere
410+
( Syb.mkT
411+
$ const Blurred
412+
)
409413
. Syb.everywhere
410414
( Syb.mkT $ \x ->
411415
if x ^. #fieldType /= FieldTypeImage

ghcjs/delivery-calculator/src/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ main =
5353
update = updateModel,
5454
Miso.view = viewModel,
5555
subs = mempty,
56-
events = defaultEvents,
56+
events = Map.insert "focus" True defaultEvents,
5757
initialAction = InitUpdate mSt,
5858
mountPoint = Nothing,
5959
logLevel = Off

ghcjs/delivery-calculator/trapeze.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
platforms:
22
android:
33
appName: Delivery Calculator
4-
versionCode: 6
5-
versionName: 0.1.0.6
4+
versionCode: 7
5+
versionName: 0.1.0.7
66
packageName: com.functora.delivery_calculator
77
manifest:
88
- file: AndroidManifest.xml

ghcjs/miso-functora/miso-functora.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ common pkg
8484
, binary
8585
, bytestring
8686
, casing
87+
, containers
8788
, functora-ghcjs
8889
, fuzzy
8990
, jsaddle

ghcjs/miso-functora/src/Functora/Miso/Jsm/Generic.hs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ module Functora.Miso.Jsm.Generic
66
removeAt,
77
openBrowserPage,
88
enterOrEscapeBlur,
9-
blur,
109
insertStorage,
1110
selectStorage,
1211
selectBarcode,
@@ -111,23 +110,12 @@ openBrowserPage uri =
111110
pkg <- getPkg
112111
void $ pkg ^. JS.js1 @Unicode "openBrowserPage" (URI.render uri)
113112

114-
enterOrEscapeBlur :: Uid -> KeyCode -> Update model
113+
enterOrEscapeBlur :: Unicode -> KeyCode -> Update model
115114
enterOrEscapeBlur uid (KeyCode code) =
116115
EffectUpdate $ do
117116
let enterOrEscape = [13, 27] :: [Int]
118117
when (code `elem` enterOrEscape) $ blur uid
119118

120-
blur :: Uid -> JSM ()
121-
blur uid = do
122-
el <-
123-
getElementById
124-
. either impureThrow id
125-
. decodeUtf8Strict
126-
. unTagged
127-
$ htmlUid uid
128-
is <- ghcjsPure $ JS.isTruthy el
129-
when is . void $ el ^. JS.js0 @Unicode "blur"
130-
131119
insertStorage :: (ToJSON a) => Unicode -> a -> JSM ()
132120
insertStorage key raw = do
133121
val <-

ghcjs/miso-functora/src/Functora/Miso/Prelude.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import Miso as X hiding
1919
Text,
2020
URI,
2121
at,
22-
blur,
2322
close,
2423
consoleLog,
2524
for_,

ghcjs/miso-functora/src/Functora/Miso/Types.hs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
)
5761
where
5862

5963
import Data.Foldable (foldMap)
6064
import Data.Functor.Barbie
6165
import qualified Data.Generics as Syb
66+
import qualified Data.Map as Map
6267
import Functora.Cfg
6368
import Functora.Miso.Prelude
6469
import 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+
500513
prependViews :: [View action] -> View action -> View action
501514
prependViews 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+
529548
data 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 ()

ghcjs/miso-functora/src/Functora/Miso/Widgets/Currency.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ selectCurrency
101101
& #optsPlaceholder
102102
.~ ("Search" :: Unicode)
103103
& #optsExtraAttributes
104-
.~ [autofocus_ True]
104+
.~ [ autofocus_ True
105+
]
105106
)
106107
<> [div_ [style_ [("width", "100%")]] mempty]
107108
<> currencyListWidget opts args

0 commit comments

Comments
 (0)