elm-pages 3.0.0-beta.33 → 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.
Files changed (38) hide show
  1. package/README.md +1 -1
  2. package/codegen/elm-pages-codegen.cjs +10 -78
  3. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
  4. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
  5. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_supervisor.js +1 -1
  6. package/generator/dead-code-review/elm.json +1 -1
  7. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
  8. package/generator/review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
  9. package/generator/review/elm-stuff/tests-0.19.1/js/node_supervisor.js +1 -1
  10. package/generator/review/elm.json +1 -1
  11. package/generator/src/RouteBuilder.elm +2 -2
  12. package/generator/src/compatibility-key.js +2 -2
  13. package/generator/static-code/elm-pages.js +10 -0
  14. package/package.json +3 -3
  15. package/src/Internal/Field.elm +19 -0
  16. package/src/Internal/Input.elm +81 -0
  17. package/src/Pages/Form.elm +229 -0
  18. package/src/Pages/Internal/Msg.elm +70 -61
  19. package/src/Pages/Internal/Platform/Cli.elm +423 -425
  20. package/src/Pages/Internal/Platform/CompatibilityKey.elm +1 -1
  21. package/src/Pages/Internal/Platform/GeneratorApplication.elm +1 -5
  22. package/src/Pages/Internal/Platform.elm +119 -100
  23. package/src/Pages/ProgramConfig.elm +12 -5
  24. package/src/Pages/StaticHttpRequest.elm +0 -1
  25. package/src/Pages/Transition.elm +9 -1
  26. package/src/PagesMsg.elm +0 -10
  27. package/src/Scaffold/Form.elm +9 -9
  28. package/src/Server/Request.elm +57 -61
  29. package/src/Form/Field.elm +0 -729
  30. package/src/Form/FieldStatus.elm +0 -36
  31. package/src/Form/FieldView.elm +0 -497
  32. package/src/Form/FormData.elm +0 -22
  33. package/src/Form/Validation.elm +0 -391
  34. package/src/Form/Value.elm +0 -118
  35. package/src/Form.elm +0 -1558
  36. package/src/FormDecoder.elm +0 -102
  37. package/src/Pages/FormState.elm +0 -257
  38. package/src/Pages/Internal/Form.elm +0 -37
@@ -91,13 +91,14 @@ import CookieParser
91
91
  import Dict exposing (Dict)
92
92
  import FatalError exposing (FatalError)
93
93
  import Form
94
+ import Form.Handler
94
95
  import Form.Validation as Validation
95
96
  import FormData
96
97
  import Internal.Request
97
98
  import Json.Decode
98
99
  import Json.Encode
99
100
  import List.NonEmpty
100
- import Pages.Internal.Form exposing (Validation(..))
101
+ import Pages.Form
101
102
  import QueryParams
102
103
  import Time
103
104
  import Url
@@ -877,60 +878,63 @@ fileField_ name =
877
878
  |> Internal.Request.Parser
878
879
 
879
880
 
881
+ runForm : Validation.Validation error parsed kind constraints -> Form.Validated error parsed
882
+ runForm validation =
883
+ Form.Handler.run []
884
+ (Form.Handler.init identity
885
+ (Form.form
886
+ { combine = validation
887
+ , view = []
888
+ }
889
+ )
890
+ )
891
+
892
+
880
893
  {-| -}
881
894
  formDataWithServerValidation :
882
- Form.ServerForms error (BackendTask FatalError (Validation.Validation error combined kind constraints))
883
- -> Parser (BackendTask FatalError (Result (Form.Response error) ( Form.Response error, combined )))
895
+ Form.Handler.Handler error (BackendTask FatalError (Validation.Validation error combined kind constraints))
896
+ -> Parser (BackendTask FatalError (Result (Form.ServerResponse error) ( Form.ServerResponse error, combined )))
884
897
  formDataWithServerValidation formParsers =
885
898
  rawFormData
886
899
  |> andThen
887
900
  (\rawFormData_ ->
888
- let
889
- ( maybeDecoded, errors ) =
890
- Form.runOneOfServerSide
891
- rawFormData_
892
- formParsers
893
- in
894
- case ( maybeDecoded, errors |> Dict.toList |> List.filter (\( _, value ) -> value |> List.isEmpty |> not) |> List.NonEmpty.fromList ) of
895
- ( Just decoded, Nothing ) ->
901
+ case Form.Handler.run rawFormData_ formParsers of
902
+ Form.Valid decoded ->
896
903
  succeed
897
904
  (decoded
898
905
  |> BackendTask.map
899
- (\(Validation _ _ ( maybeParsed, errors2 )) ->
900
- case ( maybeParsed, errors2 |> Dict.toList |> List.filter (\( _, value ) -> value |> List.isEmpty |> not) |> List.NonEmpty.fromList ) of
901
- ( Just decodedFinal, Nothing ) ->
906
+ (\clientValidated ->
907
+ case runForm clientValidated of
908
+ Form.Valid decodedFinal ->
902
909
  Ok
903
- ( Pages.Internal.Form.Response
904
- { fields = rawFormData_
905
- , errors = Dict.empty
906
- , clientErrors = Dict.empty
907
- }
910
+ ( { persisted =
911
+ { fields = Just rawFormData_
912
+ , clientSideErrors = Nothing
913
+ }
914
+ , serverSideErrors = Dict.empty
915
+ }
908
916
  , decodedFinal
909
917
  )
910
918
 
911
- _ ->
919
+ Form.Invalid _ errors2 ->
912
920
  Err
913
- (Pages.Internal.Form.Response
914
- { fields = rawFormData_
915
- , errors = errors2
916
- , clientErrors = errors
921
+ { persisted =
922
+ { fields = Just rawFormData_
923
+ , clientSideErrors = Just errors2
917
924
  }
918
- )
925
+ , serverSideErrors = Dict.empty
926
+ }
919
927
  )
920
928
  )
921
929
 
922
- ( _, maybeErrors ) ->
930
+ Form.Invalid _ errors ->
923
931
  Err
924
- (Pages.Internal.Form.Response
925
- { fields = rawFormData_
926
- , errors =
927
- maybeErrors
928
- |> Maybe.map List.NonEmpty.toList
929
- |> Maybe.withDefault []
930
- |> Dict.fromList
931
- , clientErrors = Dict.empty
932
+ { persisted =
933
+ { fields = Just rawFormData_
934
+ , clientSideErrors = Just errors
932
935
  }
933
- )
936
+ , serverSideErrors = Dict.empty
937
+ }
934
938
  |> BackendTask.succeed
935
939
  |> succeed
936
940
  )
@@ -938,40 +942,32 @@ formDataWithServerValidation formParsers =
938
942
 
939
943
  {-| -}
940
944
  formData :
941
- Form.ServerForms error combined
942
- -> Parser ( Form.Response error, Result { fields : List ( String, String ), errors : Dict String (List error), clientErrors : Dict String (List error) } combined )
945
+ Form.Handler.Handler error combined
946
+ -> Parser ( Form.ServerResponse error, Form.Validated error combined )
943
947
  formData formParsers =
944
948
  rawFormData
945
949
  |> andThen
946
950
  (\rawFormData_ ->
947
- let
948
- ( maybeDecoded, errors ) =
949
- Form.runOneOfServerSide
950
- rawFormData_
951
- formParsers
952
- in
953
- case ( maybeDecoded, errors |> Dict.toList |> List.filter (\( _, value ) -> value |> List.isEmpty |> not) |> List.NonEmpty.fromList ) of
954
- ( Just decoded, Nothing ) ->
955
- ( Pages.Internal.Form.Response { fields = [], errors = Dict.empty, clientErrors = Dict.empty }
956
- , Ok decoded
951
+ case Form.Handler.run rawFormData_ formParsers of
952
+ (Form.Valid decoded) as validated ->
953
+ ( { persisted =
954
+ { fields = Just rawFormData_
955
+ , clientSideErrors = Just Dict.empty
956
+ }
957
+ , serverSideErrors = Dict.empty
958
+ }
959
+ , validated
957
960
  )
958
961
  |> succeed
959
962
 
960
- ( _, maybeErrors ) ->
961
- let
962
- record : { fields : List ( String, String ), errors : Dict String (List error), clientErrors : Dict String (List error) }
963
- record =
964
- { fields = rawFormData_
965
- , errors = Dict.empty
966
- , clientErrors =
967
- maybeErrors
968
- |> Maybe.map List.NonEmpty.toList
969
- |> Maybe.withDefault []
970
- |> Dict.fromList
963
+ (Form.Invalid maybeDecoded maybeErrors) as validated ->
964
+ ( { persisted =
965
+ { fields = Just rawFormData_
966
+ , clientSideErrors = Just maybeErrors
971
967
  }
972
- in
973
- ( Pages.Internal.Form.Response record
974
- , Err record
968
+ , serverSideErrors = Dict.empty
969
+ }
970
+ , validated
975
971
  )
976
972
  |> succeed
977
973
  )