elm-pages 3.0.0-beta.32 → 3.0.0-beta.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/codegen/elm-pages-codegen.cjs +10 -78
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_supervisor.js +1 -1
- package/generator/dead-code-review/elm.json +1 -1
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
- package/generator/review/elm-stuff/tests-0.19.1/js/node_supervisor.js +1 -1
- package/generator/review/elm.json +1 -1
- package/generator/src/RouteBuilder.elm +2 -2
- package/generator/src/compatibility-key.js +2 -2
- package/generator/src/render.js +1 -0
- package/generator/src/request-cache.js +20 -6
- package/generator/static-code/elm-pages.js +10 -0
- package/package.json +3 -3
- package/src/BackendTask/Http.elm +8 -2
- package/src/Internal/Field.elm +19 -0
- package/src/Internal/Input.elm +81 -0
- package/src/Pages/Form.elm +229 -0
- package/src/Pages/Internal/Msg.elm +70 -61
- package/src/Pages/Internal/Platform/Cli.elm +423 -425
- package/src/Pages/Internal/Platform/CompatibilityKey.elm +1 -1
- package/src/Pages/Internal/Platform/GeneratorApplication.elm +1 -5
- package/src/Pages/Internal/Platform.elm +119 -100
- package/src/Pages/ProgramConfig.elm +12 -5
- package/src/Pages/StaticHttpRequest.elm +0 -1
- package/src/Pages/Transition.elm +9 -1
- package/src/PagesMsg.elm +0 -10
- package/src/RequestsAndPending.elm +31 -3
- package/src/Scaffold/Form.elm +9 -9
- package/src/Server/Request.elm +57 -61
- package/src/Form/Field.elm +0 -729
- package/src/Form/FieldStatus.elm +0 -36
- package/src/Form/FieldView.elm +0 -497
- package/src/Form/FormData.elm +0 -22
- package/src/Form/Validation.elm +0 -391
- package/src/Form/Value.elm +0 -118
- package/src/Form.elm +0 -1558
- package/src/FormDecoder.elm +0 -102
- package/src/Pages/FormState.elm +0 -257
- package/src/Pages/Internal/Form.elm +0 -37
|
@@ -291,13 +291,9 @@ initLegacy :
|
|
|
291
291
|
-> ( Model, Effect )
|
|
292
292
|
initLegacy execute =
|
|
293
293
|
let
|
|
294
|
-
staticResponses : BackendTask FatalError ()
|
|
295
|
-
staticResponses =
|
|
296
|
-
StaticResponses.renderApiRequest execute
|
|
297
|
-
|
|
298
294
|
initialModel : Model
|
|
299
295
|
initialModel =
|
|
300
|
-
{ staticResponses =
|
|
296
|
+
{ staticResponses = execute
|
|
301
297
|
, errors = []
|
|
302
298
|
}
|
|
303
299
|
in
|
|
@@ -20,8 +20,7 @@ import BuildError exposing (BuildError)
|
|
|
20
20
|
import Bytes exposing (Bytes)
|
|
21
21
|
import Bytes.Decode
|
|
22
22
|
import Dict exposing (Dict)
|
|
23
|
-
import Form
|
|
24
|
-
import FormDecoder
|
|
23
|
+
import Form
|
|
25
24
|
import Html exposing (Html)
|
|
26
25
|
import Html.Attributes as Attr
|
|
27
26
|
import Http
|
|
@@ -30,7 +29,6 @@ import Json.Encode
|
|
|
30
29
|
import Pages.ContentCache as ContentCache
|
|
31
30
|
import Pages.Fetcher
|
|
32
31
|
import Pages.Flags
|
|
33
|
-
import Pages.FormState
|
|
34
32
|
import Pages.Internal.Msg
|
|
35
33
|
import Pages.Internal.NotFoundReason exposing (NotFoundReason)
|
|
36
34
|
import Pages.Internal.ResponseSketch as ResponseSketch exposing (ResponseSketch)
|
|
@@ -311,7 +309,8 @@ type Msg userMsg pageData actionData sharedData errorPage
|
|
|
311
309
|
| UrlChanged Url
|
|
312
310
|
-- TODO rename to PagesMsg
|
|
313
311
|
| UserMsg (PagesMsg userMsg)
|
|
314
|
-
|
|
312
|
+
--| SetField { formId : String, name : String, value : String }
|
|
313
|
+
| FormMsg (Form.Msg (Msg userMsg pageData actionData sharedData errorPage))
|
|
315
314
|
| UpdateCacheAndUrlNew Bool Url (Maybe userMsg) (Result Http.Error ( Url, ResponseSketch pageData actionData sharedData ))
|
|
316
315
|
| FetcherComplete Bool String Int (Result Http.Error ( Maybe userMsg, ActionDataOrRedirect actionData ))
|
|
317
316
|
| FetcherStarted String Int FormData Time.Posix
|
|
@@ -344,7 +343,7 @@ type alias Model userModel pageData actionData sharedData =
|
|
|
344
343
|
, transition : Maybe ( Int, Pages.Transition.Transition )
|
|
345
344
|
, nextTransitionKey : Int
|
|
346
345
|
, inFlightFetchers : Dict String ( Int, Pages.Transition.FetcherState actionData )
|
|
347
|
-
, pageFormState :
|
|
346
|
+
, pageFormState : Form.Model
|
|
348
347
|
, pendingRedirect : Bool
|
|
349
348
|
, pendingData : Maybe ( pageData, sharedData, Maybe actionData )
|
|
350
349
|
}
|
|
@@ -363,6 +362,7 @@ type Effect userMsg pageData actionData sharedData userEffect errorPage
|
|
|
363
362
|
| Batch (List (Effect userMsg pageData actionData sharedData userEffect errorPage))
|
|
364
363
|
| UserCmd userEffect
|
|
365
364
|
| CancelRequest Int
|
|
365
|
+
| RunCmd (Cmd (Msg userMsg pageData actionData sharedData errorPage))
|
|
366
366
|
|
|
367
367
|
|
|
368
368
|
{-| -}
|
|
@@ -373,6 +373,18 @@ update :
|
|
|
373
373
|
-> ( Model userModel pageData actionData sharedData, Effect userMsg pageData actionData sharedData userEffect errorPage )
|
|
374
374
|
update config appMsg model =
|
|
375
375
|
case appMsg of
|
|
376
|
+
FormMsg formMsg ->
|
|
377
|
+
let
|
|
378
|
+
-- TODO trigger formCmd
|
|
379
|
+
( newModel, formCmd ) =
|
|
380
|
+
Form.update formMsg model.pageFormState
|
|
381
|
+
in
|
|
382
|
+
( { model
|
|
383
|
+
| pageFormState = newModel
|
|
384
|
+
}
|
|
385
|
+
, RunCmd formCmd
|
|
386
|
+
)
|
|
387
|
+
|
|
376
388
|
LinkClicked urlRequest ->
|
|
377
389
|
case urlRequest of
|
|
378
390
|
Browser.Internal url ->
|
|
@@ -398,11 +410,6 @@ update config appMsg model =
|
|
|
398
410
|
, BrowserLoadUrl href
|
|
399
411
|
)
|
|
400
412
|
|
|
401
|
-
SetField info ->
|
|
402
|
-
( { model | pageFormState = Pages.FormState.setField info model.pageFormState }
|
|
403
|
-
, NoEffect
|
|
404
|
-
)
|
|
405
|
-
|
|
406
413
|
UrlChanged url ->
|
|
407
414
|
case model.pendingData of
|
|
408
415
|
Just ( newPageData, newSharedData, newActionData ) ->
|
|
@@ -498,74 +505,60 @@ update config appMsg model =
|
|
|
498
505
|
|> performUserMsg userMsg config
|
|
499
506
|
|
|
500
507
|
Pages.Internal.Msg.Submit fields ->
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
( -- TODO remove hardcoded number
|
|
519
|
-
-1
|
|
520
|
-
, Pages.Transition.Submitting fields
|
|
521
|
-
)
|
|
522
|
-
}
|
|
523
|
-
, Submit fields
|
|
524
|
-
)
|
|
525
|
-
|> (case maybeUserMsg of
|
|
526
|
-
Just justUserMsg ->
|
|
527
|
-
performUserMsg justUserMsg config
|
|
528
|
-
|
|
529
|
-
Nothing ->
|
|
530
|
-
identity
|
|
531
|
-
)
|
|
508
|
+
let
|
|
509
|
+
payload : { fields : List ( String, String ), method : Form.Method, action : String, id : Maybe String }
|
|
510
|
+
payload =
|
|
511
|
+
{ fields = fields.fields
|
|
512
|
+
, method = fields.method
|
|
513
|
+
, action = fields.action
|
|
514
|
+
, id = Just fields.id
|
|
515
|
+
}
|
|
516
|
+
in
|
|
517
|
+
if fields.valid then
|
|
518
|
+
if fields.useFetcher then
|
|
519
|
+
( { model | nextTransitionKey = model.nextTransitionKey + 1 }
|
|
520
|
+
, SubmitFetcher fields.id model.nextTransitionKey payload
|
|
521
|
+
)
|
|
522
|
+
|> (case fields.msg of
|
|
523
|
+
Just justUserMsg ->
|
|
524
|
+
performUserMsg justUserMsg config
|
|
532
525
|
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
model.pageFormState
|
|
537
|
-
|> Pages.FormState.setSubmitAttempted formId
|
|
538
|
-
}
|
|
539
|
-
, NoEffect
|
|
540
|
-
)
|
|
526
|
+
Nothing ->
|
|
527
|
+
identity
|
|
528
|
+
)
|
|
541
529
|
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
530
|
+
else
|
|
531
|
+
( { model
|
|
532
|
+
-- TODO should I setSubmitAttempted here, too?
|
|
533
|
+
| transition =
|
|
534
|
+
Just
|
|
535
|
+
( -- TODO remove hardcoded number
|
|
536
|
+
-1
|
|
537
|
+
, Pages.Transition.Submitting payload
|
|
538
|
+
)
|
|
539
|
+
}
|
|
540
|
+
, Submit payload
|
|
541
|
+
)
|
|
542
|
+
|> (case fields.msg of
|
|
543
|
+
Just justUserMsg ->
|
|
544
|
+
performUserMsg justUserMsg config
|
|
551
545
|
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
546
|
+
Nothing ->
|
|
547
|
+
identity
|
|
548
|
+
)
|
|
555
549
|
|
|
556
550
|
else
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
model.pageFormState
|
|
560
|
-
|> Pages.FormState.setSubmitAttempted fetcherKey
|
|
561
|
-
}
|
|
562
|
-
, NoEffect
|
|
563
|
-
)
|
|
551
|
+
-- TODO should the user msg still be run if the form is invalid?
|
|
552
|
+
( model, NoEffect )
|
|
564
553
|
|
|
565
|
-
Pages.Internal.Msg.
|
|
554
|
+
Pages.Internal.Msg.FormMsg formMsg ->
|
|
566
555
|
-- TODO when init is called for a new page, also need to clear out client-side `pageFormState`
|
|
567
|
-
|
|
568
|
-
|
|
556
|
+
let
|
|
557
|
+
( formModel, formCmd ) =
|
|
558
|
+
Form.update formMsg model.pageFormState
|
|
559
|
+
in
|
|
560
|
+
( { model | pageFormState = formModel }
|
|
561
|
+
, RunCmd (Cmd.map UserMsg formCmd)
|
|
569
562
|
)
|
|
570
563
|
|
|
571
564
|
Pages.Internal.Msg.NoOp ->
|
|
@@ -910,6 +903,9 @@ perform config model effect =
|
|
|
910
903
|
NoEffect ->
|
|
911
904
|
Cmd.none
|
|
912
905
|
|
|
906
|
+
RunCmd cmd ->
|
|
907
|
+
cmd
|
|
908
|
+
|
|
913
909
|
Batch effects ->
|
|
914
910
|
effects
|
|
915
911
|
|> List.map (perform config model)
|
|
@@ -941,7 +937,7 @@ perform config model effect =
|
|
|
941
937
|
fetchRouteData transitionKey toMsg config url maybeRequestInfo
|
|
942
938
|
|
|
943
939
|
Submit fields ->
|
|
944
|
-
if fields.method == Get then
|
|
940
|
+
if fields.method == Form.Get then
|
|
945
941
|
model.key
|
|
946
942
|
|> Maybe.map (\key -> Browser.Navigation.pushUrl key (appendFormQueryParams fields))
|
|
947
943
|
|> Maybe.withDefault Cmd.none
|
|
@@ -991,7 +987,11 @@ perform config model effect =
|
|
|
991
987
|
startFetcher "TODO" -1 options model
|
|
992
988
|
, fromPageMsg = Pages.Internal.Msg.UserMsg >> UserMsg
|
|
993
989
|
, key = key
|
|
994
|
-
, setField =
|
|
990
|
+
, setField =
|
|
991
|
+
\info ->
|
|
992
|
+
--Task.succeed (SetField info) |> Task.perform identity
|
|
993
|
+
-- TODO
|
|
994
|
+
Cmd.none
|
|
995
995
|
}
|
|
996
996
|
|
|
997
997
|
Nothing ->
|
|
@@ -1006,21 +1006,12 @@ startFetcher fetcherKey transitionId options model =
|
|
|
1006
1006
|
let
|
|
1007
1007
|
encodedBody : String
|
|
1008
1008
|
encodedBody =
|
|
1009
|
-
|
|
1010
|
-
{ fields = options.fields
|
|
1011
|
-
|
|
1012
|
-
-- TODO remove hardcoding
|
|
1013
|
-
, action = ""
|
|
1009
|
+
encodeFormData options.fields
|
|
1014
1010
|
|
|
1015
|
-
|
|
1016
|
-
, method = Post
|
|
1017
|
-
, id = Nothing
|
|
1018
|
-
}
|
|
1019
|
-
|
|
1020
|
-
formData : { method : Method, action : String, fields : List ( String, String ), id : Maybe String }
|
|
1011
|
+
formData : { method : Form.Method, action : String, fields : List ( String, String ), id : Maybe String }
|
|
1021
1012
|
formData =
|
|
1022
1013
|
{ -- TODO remove hardcoding
|
|
1023
|
-
method = Get
|
|
1014
|
+
method = Form.Get
|
|
1024
1015
|
|
|
1025
1016
|
-- TODO pass FormData directly
|
|
1026
1017
|
, action = options.url |> Maybe.withDefault model.url.path
|
|
@@ -1078,7 +1069,7 @@ startFetcher2 config fromPageReload fetcherKey transitionId formData model =
|
|
|
1078
1069
|
let
|
|
1079
1070
|
encodedBody : String
|
|
1080
1071
|
encodedBody =
|
|
1081
|
-
|
|
1072
|
+
encodeFormData formData.fields
|
|
1082
1073
|
in
|
|
1083
1074
|
-- TODO make sure that `actionData` isn't updated in Model for fetchers
|
|
1084
1075
|
Cmd.batch
|
|
@@ -1139,7 +1130,7 @@ startFetcher2 config fromPageReload fetcherKey transitionId formData model =
|
|
|
1139
1130
|
|
|
1140
1131
|
-- TODO use formData.method to do either query params or POST body
|
|
1141
1132
|
, url = formData.action |> Url.fromString |> Maybe.map (\{ path } -> Path.join [ path, "content.dat" ] |> Path.toAbsolute) |> Maybe.withDefault "/"
|
|
1142
|
-
, method = formData.method |>
|
|
1133
|
+
, method = formData.method |> methodToString
|
|
1143
1134
|
, timeout = Nothing
|
|
1144
1135
|
}
|
|
1145
1136
|
]
|
|
@@ -1173,10 +1164,10 @@ appendFormQueryParams fields =
|
|
|
1173
1164
|
|> Maybe.withDefault "/"
|
|
1174
1165
|
)
|
|
1175
1166
|
++ (case fields.method of
|
|
1176
|
-
Get ->
|
|
1177
|
-
"?" ++
|
|
1167
|
+
Form.Get ->
|
|
1168
|
+
"?" ++ encodeFormData fields.fields
|
|
1178
1169
|
|
|
1179
|
-
Post ->
|
|
1170
|
+
Form.Post ->
|
|
1180
1171
|
""
|
|
1181
1172
|
)
|
|
1182
1173
|
|
|
@@ -1291,14 +1282,14 @@ fetchRouteData transitionKey toMsg config url details =
|
|
|
1291
1282
|
|
|
1292
1283
|
-}
|
|
1293
1284
|
let
|
|
1294
|
-
formMethod : Method
|
|
1285
|
+
formMethod : Form.Method
|
|
1295
1286
|
formMethod =
|
|
1296
1287
|
details
|
|
1297
1288
|
|> Maybe.map .method
|
|
1298
|
-
|> Maybe.withDefault Get
|
|
1289
|
+
|> Maybe.withDefault Form.Get
|
|
1299
1290
|
in
|
|
1300
1291
|
Http.request
|
|
1301
|
-
{ method = details |> Maybe.map (.method >>
|
|
1292
|
+
{ method = details |> Maybe.map (.method >> methodToString) |> Maybe.withDefault "GET"
|
|
1302
1293
|
, headers = []
|
|
1303
1294
|
, url =
|
|
1304
1295
|
"/"
|
|
@@ -1316,34 +1307,34 @@ fetchRouteData transitionKey toMsg config url details =
|
|
|
1316
1307
|
|> String.join "/"
|
|
1317
1308
|
)
|
|
1318
1309
|
++ (case formMethod of
|
|
1319
|
-
Post ->
|
|
1310
|
+
Form.Post ->
|
|
1320
1311
|
"/"
|
|
1321
1312
|
|
|
1322
|
-
Get ->
|
|
1313
|
+
Form.Get ->
|
|
1323
1314
|
details
|
|
1324
|
-
|> Maybe.map
|
|
1315
|
+
|> Maybe.map (.fields >> encodeFormData)
|
|
1325
1316
|
|> Maybe.map (\encoded -> "?" ++ encoded)
|
|
1326
1317
|
|> Maybe.withDefault ""
|
|
1327
1318
|
)
|
|
1328
1319
|
++ (case formMethod of
|
|
1329
1320
|
-- TODO extract this to something unit testable
|
|
1330
1321
|
-- TODO make states mutually exclusive for submissions and direct URL requests (shouldn't be possible to append two query param strings)
|
|
1331
|
-
Post ->
|
|
1322
|
+
Form.Post ->
|
|
1332
1323
|
""
|
|
1333
1324
|
|
|
1334
|
-
Get ->
|
|
1325
|
+
Form.Get ->
|
|
1335
1326
|
url.query
|
|
1336
1327
|
|> Maybe.map (\encoded -> "?" ++ encoded)
|
|
1337
1328
|
|> Maybe.withDefault ""
|
|
1338
1329
|
)
|
|
1339
1330
|
, body =
|
|
1340
1331
|
case formMethod of
|
|
1341
|
-
Post ->
|
|
1332
|
+
Form.Post ->
|
|
1342
1333
|
let
|
|
1343
1334
|
urlEncodedFields : Maybe String
|
|
1344
1335
|
urlEncodedFields =
|
|
1345
1336
|
details
|
|
1346
|
-
|> Maybe.map
|
|
1337
|
+
|> Maybe.map (.fields >> encodeFormData)
|
|
1347
1338
|
in
|
|
1348
1339
|
urlEncodedFields
|
|
1349
1340
|
|> Maybe.map (\encoded -> Http.stringBody "application/x-www-form-urlencoded" encoded)
|
|
@@ -1597,3 +1588,31 @@ loadDataAndUpdateUrl ( newPageData, newSharedData, newActionData ) maybeUserMsg
|
|
|
1597
1588
|
|> Url.toString
|
|
1598
1589
|
|> BrowserLoadUrl
|
|
1599
1590
|
)
|
|
1591
|
+
|
|
1592
|
+
|
|
1593
|
+
methodToString : Form.Method -> String
|
|
1594
|
+
methodToString method =
|
|
1595
|
+
case method of
|
|
1596
|
+
Form.Get ->
|
|
1597
|
+
"GET"
|
|
1598
|
+
|
|
1599
|
+
Form.Post ->
|
|
1600
|
+
"POST"
|
|
1601
|
+
|
|
1602
|
+
|
|
1603
|
+
encodeFormData : List ( String, String ) -> String
|
|
1604
|
+
encodeFormData fields =
|
|
1605
|
+
fields
|
|
1606
|
+
|> List.map
|
|
1607
|
+
(\( name, value ) ->
|
|
1608
|
+
Url.percentEncode name ++ "=" ++ Url.percentEncode value
|
|
1609
|
+
)
|
|
1610
|
+
|> String.join "&"
|
|
1611
|
+
|
|
1612
|
+
|
|
1613
|
+
type alias FormData =
|
|
1614
|
+
{ fields : List ( String, String )
|
|
1615
|
+
, method : Form.Method
|
|
1616
|
+
, action : String
|
|
1617
|
+
, id : Maybe String
|
|
1618
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
module Pages.ProgramConfig exposing (ProgramConfig)
|
|
1
|
+
module Pages.ProgramConfig exposing (FormData, ProgramConfig)
|
|
2
2
|
|
|
3
3
|
import ApiRoute
|
|
4
4
|
import BackendTask exposing (BackendTask)
|
|
@@ -8,7 +8,7 @@ import Bytes.Decode
|
|
|
8
8
|
import Bytes.Encode
|
|
9
9
|
import Dict exposing (Dict)
|
|
10
10
|
import FatalError exposing (FatalError)
|
|
11
|
-
import Form
|
|
11
|
+
import Form
|
|
12
12
|
import Head
|
|
13
13
|
import Html exposing (Html)
|
|
14
14
|
import Http
|
|
@@ -17,7 +17,6 @@ import Json.Encode
|
|
|
17
17
|
import PageServerResponse exposing (PageServerResponse)
|
|
18
18
|
import Pages.Fetcher
|
|
19
19
|
import Pages.Flags
|
|
20
|
-
import Pages.FormState
|
|
21
20
|
import Pages.Internal.NotFoundReason exposing (NotFoundReason)
|
|
22
21
|
import Pages.Internal.Platform.ToJsPayload
|
|
23
22
|
import Pages.Internal.ResponseSketch exposing (ResponseSketch)
|
|
@@ -47,14 +46,14 @@ type alias ProgramConfig userMsg userModel route pageData actionData sharedData
|
|
|
47
46
|
, pageUrl : Maybe PageUrl
|
|
48
47
|
}
|
|
49
48
|
-> ( userModel, effect )
|
|
50
|
-
, update :
|
|
49
|
+
, update : Form.Model -> Dict String (Pages.Transition.FetcherState actionData) -> Maybe Pages.Transition.Transition -> sharedData -> pageData -> Maybe Browser.Navigation.Key -> userMsg -> userModel -> ( userModel, effect )
|
|
51
50
|
, subscriptions : route -> Path -> userModel -> Sub userMsg
|
|
52
51
|
, sharedData : BackendTask FatalError sharedData
|
|
53
52
|
, data : Decode.Value -> route -> BackendTask FatalError (PageServerResponse pageData errorPage)
|
|
54
53
|
, action : Decode.Value -> route -> BackendTask FatalError (PageServerResponse actionData errorPage)
|
|
55
54
|
, onActionData : actionData -> Maybe userMsg
|
|
56
55
|
, view :
|
|
57
|
-
|
|
56
|
+
Form.Model
|
|
58
57
|
-> Dict String (Pages.Transition.FetcherState actionData)
|
|
59
58
|
-> Maybe Pages.Transition.Transition
|
|
60
59
|
->
|
|
@@ -128,3 +127,11 @@ type alias ProgramConfig userMsg userModel route pageData actionData sharedData
|
|
|
128
127
|
, errorPageToData : errorPage -> pageData
|
|
129
128
|
, notFoundRoute : route
|
|
130
129
|
}
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
type alias FormData =
|
|
133
|
+
{ fields : List ( String, String )
|
|
134
|
+
, method : Form.Method
|
|
135
|
+
, action : String
|
|
136
|
+
, id : Maybe String
|
|
137
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
module Pages.StaticHttpRequest exposing (Error(..), MockResolver, RawRequest(..), Status(..), cacheRequestResolution, mockResolve, toBuildError)
|
|
2
2
|
|
|
3
3
|
import BuildError exposing (BuildError)
|
|
4
|
-
import Dict
|
|
5
4
|
import Json.Encode
|
|
6
5
|
import Pages.StaticHttp.Request
|
|
7
6
|
import RequestsAndPending exposing (RequestsAndPending)
|
package/src/Pages/Transition.elm
CHANGED
|
@@ -14,11 +14,19 @@ module Pages.Transition exposing
|
|
|
14
14
|
|
|
15
15
|
-}
|
|
16
16
|
|
|
17
|
-
import Form
|
|
17
|
+
import Form
|
|
18
18
|
import Path exposing (Path)
|
|
19
19
|
import Time
|
|
20
20
|
|
|
21
21
|
|
|
22
|
+
type alias FormData =
|
|
23
|
+
{ fields : List ( String, String )
|
|
24
|
+
, method : Form.Method
|
|
25
|
+
, action : String
|
|
26
|
+
, id : Maybe String
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
22
30
|
{-| -}
|
|
23
31
|
type Transition
|
|
24
32
|
= Submitting FormData
|
package/src/PagesMsg.elm
CHANGED
|
@@ -2,7 +2,6 @@ module PagesMsg exposing
|
|
|
2
2
|
( PagesMsg
|
|
3
3
|
, fromMsg
|
|
4
4
|
, map, noOp
|
|
5
|
-
, onSubmit
|
|
6
5
|
)
|
|
7
6
|
|
|
8
7
|
{-| In `elm-pages`, Route modules have their own `Msg` type which can be used like a normal TEA (The Elm Architecture) app.
|
|
@@ -16,11 +15,8 @@ You can wrap your Route Module's `Msg` using `fromMsg`.
|
|
|
16
15
|
|
|
17
16
|
@docs map, noOp
|
|
18
17
|
|
|
19
|
-
@docs onSubmit
|
|
20
|
-
|
|
21
18
|
-}
|
|
22
19
|
|
|
23
|
-
import Html exposing (Attribute)
|
|
24
20
|
import Pages.Internal.Msg
|
|
25
21
|
|
|
26
22
|
|
|
@@ -84,9 +80,3 @@ noOp =
|
|
|
84
80
|
map : (a -> b) -> PagesMsg a -> PagesMsg b
|
|
85
81
|
map mapFn msg =
|
|
86
82
|
Pages.Internal.Msg.map mapFn msg
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
{-| -}
|
|
90
|
-
onSubmit : Attribute (PagesMsg userMsg)
|
|
91
|
-
onSubmit =
|
|
92
|
-
Pages.Internal.Msg.onSubmit
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
module RequestsAndPending exposing (RawResponse, RequestsAndPending, Response(..), ResponseBody(..), bodyEncoder, get)
|
|
1
|
+
module RequestsAndPending exposing (HttpError(..), RawResponse, RequestsAndPending, Response(..), ResponseBody(..), bodyEncoder, get)
|
|
2
2
|
|
|
3
3
|
import Base64
|
|
4
4
|
import Bytes exposing (Bytes)
|
|
@@ -101,11 +101,39 @@ responseDecoder =
|
|
|
101
101
|
(Decode.field "url" Decode.string)
|
|
102
102
|
|
|
103
103
|
|
|
104
|
-
get : String -> RequestsAndPending -> Maybe Response
|
|
104
|
+
get : String -> RequestsAndPending -> Maybe (Result HttpError Response)
|
|
105
105
|
get key requestsAndPending =
|
|
106
106
|
Decode.decodeValue
|
|
107
107
|
(Decode.field key
|
|
108
|
-
(Decode.field "response"
|
|
108
|
+
(Decode.field "response"
|
|
109
|
+
(Decode.oneOf
|
|
110
|
+
[ Decode.field "elm-pages-internal-error" errorDecoder |> Decode.map Err
|
|
111
|
+
, decoder |> Decode.map Ok
|
|
112
|
+
]
|
|
113
|
+
)
|
|
114
|
+
)
|
|
109
115
|
)
|
|
110
116
|
requestsAndPending
|
|
111
117
|
|> Result.toMaybe
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
type HttpError
|
|
121
|
+
= NetworkError
|
|
122
|
+
| Timeout
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
errorDecoder : Decoder HttpError
|
|
126
|
+
errorDecoder =
|
|
127
|
+
Decode.string
|
|
128
|
+
|> Decode.andThen
|
|
129
|
+
(\errorCode ->
|
|
130
|
+
case errorCode of
|
|
131
|
+
"NetworkError" ->
|
|
132
|
+
Decode.succeed NetworkError
|
|
133
|
+
|
|
134
|
+
"Timeout" ->
|
|
135
|
+
Decode.succeed Timeout
|
|
136
|
+
|
|
137
|
+
_ ->
|
|
138
|
+
Decode.fail "Unhandled error code."
|
|
139
|
+
)
|
package/src/Scaffold/Form.elm
CHANGED
|
@@ -37,14 +37,14 @@ type Kind
|
|
|
37
37
|
{-| -}
|
|
38
38
|
type alias Context =
|
|
39
39
|
{ errors : Elm.Expression
|
|
40
|
-
,
|
|
40
|
+
, submitting : Elm.Expression
|
|
41
41
|
, submitAttempted : Elm.Expression
|
|
42
42
|
, data : Elm.Expression
|
|
43
43
|
, expression : Elm.Expression
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
|
|
47
|
-
formWithFields : Bool -> List ( String, Kind ) -> ({ formState : { errors : Elm.Expression,
|
|
47
|
+
formWithFields : Bool -> List ( String, Kind ) -> ({ formState : { errors : Elm.Expression, submitting : Elm.Expression, submitAttempted : Elm.Expression, data : Elm.Expression, expression : Elm.Expression }, params : List { name : String, kind : Kind, param : Elm.Expression } } -> Elm.Expression) -> { declaration : Elm.Declaration, call : List Elm.Expression -> Elm.Expression, callFrom : List String -> List Elm.Expression -> Elm.Expression, value : List String -> Elm.Expression }
|
|
48
48
|
formWithFields elmCssView fields viewFn =
|
|
49
49
|
Elm.Declare.function "form"
|
|
50
50
|
[]
|
|
@@ -124,7 +124,7 @@ formWithFields elmCssView fields viewFn =
|
|
|
124
124
|
viewFn
|
|
125
125
|
{ formState =
|
|
126
126
|
{ errors = formState |> Elm.get "errors"
|
|
127
|
-
,
|
|
127
|
+
, submitting = formState |> Elm.get "submitting"
|
|
128
128
|
, submitAttempted = formState |> Elm.get "submitAttempted"
|
|
129
129
|
, data = formState |> Elm.get "data"
|
|
130
130
|
, expression = formState
|
|
@@ -148,7 +148,7 @@ formWithFields elmCssView fields viewFn =
|
|
|
148
148
|
[ Type.string
|
|
149
149
|
, Type.named [] "ParsedForm"
|
|
150
150
|
, Type.var "input"
|
|
151
|
-
, Type.named [] "Msg"
|
|
151
|
+
, Type.namedWith [ "PagesMsg" ] "PagesMsg" [ Type.named [] "Msg" ]
|
|
152
152
|
]
|
|
153
153
|
)
|
|
154
154
|
)
|
|
@@ -237,8 +237,8 @@ provide { fields, view, elmCssView } =
|
|
|
237
237
|
(\_ ->
|
|
238
238
|
initCombined (Elm.val "Action") (form.call [])
|
|
239
239
|
|> Elm.withType
|
|
240
|
-
(Type.namedWith [ "Form" ]
|
|
241
|
-
"
|
|
240
|
+
(Type.namedWith [ "Form", "Handler" ]
|
|
241
|
+
"Handler"
|
|
242
242
|
[ Type.string
|
|
243
243
|
, Type.named [] "Action"
|
|
244
244
|
]
|
|
@@ -444,7 +444,7 @@ formInit : Elm.Expression
|
|
|
444
444
|
formInit =
|
|
445
445
|
Elm.value
|
|
446
446
|
{ importFrom = [ "Form" ]
|
|
447
|
-
, name = "
|
|
447
|
+
, name = "form"
|
|
448
448
|
, annotation = Nothing
|
|
449
449
|
}
|
|
450
450
|
|> Elm.Op.pipe
|
|
@@ -465,8 +465,8 @@ initCombined : Elm.Expression -> Elm.Expression -> Elm.Expression
|
|
|
465
465
|
initCombined initCombinedArg initCombinedArg0 =
|
|
466
466
|
Elm.apply
|
|
467
467
|
(Elm.value
|
|
468
|
-
{ importFrom = [ "Form" ]
|
|
469
|
-
, name = "
|
|
468
|
+
{ importFrom = [ "Form", "Handler" ]
|
|
469
|
+
, name = "init"
|
|
470
470
|
, annotation = Nothing
|
|
471
471
|
}
|
|
472
472
|
)
|