elm-pages 3.0.0-beta.2 → 3.0.0-beta.20
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 +10 -1
- package/codegen/{elm-pages-codegen.js → elm-pages-codegen.cjs} +2420 -1592
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmi +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmo +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateDataTest.elmo +0 -0
- 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/elm-stuff/0.19.1/i.dat +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm.json +1 -1
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +1326 -121
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Runner.elm.js +15215 -13007
- 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 +8 -6
- package/generator/dead-code-review/src/Pages/Review/DeadCodeEliminateData.elm +189 -17
- package/generator/dead-code-review/tests/Pages/Review/DeadCodeEliminateDataTest.elm +255 -21
- 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/elm-stuff/0.19.1/i.dat +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm.json +1 -1
- package/generator/review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +1326 -121
- package/generator/review/elm-stuff/tests-0.19.1/js/Runner.elm.js +14620 -12636
- 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 +8 -8
- package/generator/src/RouteBuilder.elm +66 -52
- package/generator/src/SharedTemplate.elm +3 -2
- package/generator/src/SiteConfig.elm +3 -2
- package/generator/src/basepath-middleware.js +3 -3
- package/generator/src/build.js +122 -86
- package/generator/src/cli.js +247 -51
- package/generator/src/codegen.js +29 -27
- package/generator/src/compatibility-key.js +1 -0
- package/generator/src/compile-elm.js +20 -22
- package/generator/src/config.js +39 -0
- package/generator/src/copy-dir.js +2 -2
- package/generator/src/dev-server.js +119 -110
- package/generator/src/dir-helpers.js +9 -26
- package/generator/src/elm-codegen.js +5 -4
- package/generator/src/elm-file-constants.js +2 -3
- package/generator/src/error-formatter.js +12 -11
- package/generator/src/file-helpers.js +3 -4
- package/generator/src/generate-template-module-connector.js +14 -21
- package/generator/src/init.js +8 -7
- package/generator/src/pre-render-html.js +41 -28
- package/generator/src/render-test.js +109 -0
- package/generator/src/render-worker.js +26 -28
- package/generator/src/render.js +322 -142
- package/generator/src/request-cache.js +200 -162
- package/generator/src/rewrite-client-elm-json.js +5 -5
- package/generator/src/rewrite-elm-json.js +7 -7
- package/generator/src/route-codegen-helpers.js +16 -31
- package/generator/src/seo-renderer.js +12 -7
- package/generator/src/vite-utils.js +77 -0
- package/generator/static-code/hmr.js +16 -2
- package/generator/template/app/Api.elm +3 -3
- package/generator/template/app/Route/Index.elm +3 -3
- package/generator/template/app/Shared.elm +3 -3
- package/generator/template/app/Site.elm +9 -4
- package/package.json +21 -21
- package/src/ApiRoute.elm +199 -61
- package/src/BackendTask/Custom.elm +214 -0
- package/src/BackendTask/Env.elm +90 -0
- package/src/{DataSource → BackendTask}/File.elm +128 -43
- package/src/{DataSource → BackendTask}/Glob.elm +136 -125
- package/src/BackendTask/Http.elm +673 -0
- package/src/{DataSource → BackendTask}/Internal/Glob.elm +1 -1
- package/src/BackendTask/Internal/Request.elm +28 -0
- package/src/BackendTask/Random.elm +79 -0
- package/src/BackendTask/Time.elm +47 -0
- package/src/BackendTask.elm +537 -0
- package/src/FatalError.elm +89 -0
- package/src/Form/Field.elm +1 -1
- package/src/Form.elm +72 -92
- package/src/Head/Seo.elm +4 -4
- package/src/Head.elm +237 -7
- package/src/HtmlPrinter.elm +7 -3
- package/src/Internal/ApiRoute.elm +7 -5
- package/src/PageServerResponse.elm +6 -1
- package/src/Pages/Generate.elm +775 -132
- package/src/Pages/GeneratorProgramConfig.elm +15 -0
- package/src/Pages/Internal/FatalError.elm +5 -0
- package/src/Pages/Internal/Form.elm +21 -1
- package/src/Pages/Internal/Platform/Cli.elm +479 -747
- package/src/Pages/Internal/Platform/Cli.elm.bak +1276 -0
- package/src/Pages/Internal/Platform/CompatibilityKey.elm +6 -0
- package/src/Pages/Internal/Platform/Effect.elm +1 -2
- package/src/Pages/Internal/Platform/GeneratorApplication.elm +373 -0
- package/src/Pages/Internal/Platform/StaticResponses.elm +73 -270
- package/src/Pages/Internal/Platform/ToJsPayload.elm +4 -7
- package/src/Pages/Internal/Platform.elm +54 -53
- package/src/Pages/Internal/Script.elm +17 -0
- package/src/Pages/Internal/StaticHttpBody.elm +35 -1
- package/src/Pages/Manifest.elm +29 -4
- package/src/Pages/ProgramConfig.elm +12 -8
- package/src/Pages/Script.elm +109 -0
- package/src/Pages/SiteConfig.elm +3 -2
- package/src/Pages/StaticHttp/Request.elm +2 -2
- package/src/Pages/StaticHttpRequest.elm +23 -98
- package/src/RequestsAndPending.elm +8 -19
- package/src/Result/Extra.elm +21 -0
- package/src/Server/Request.elm +43 -34
- package/src/Server/Session.elm +166 -100
- package/src/Server/SetCookie.elm +89 -31
- package/src/DataSource/Env.elm +0 -38
- package/src/DataSource/Http.elm +0 -446
- package/src/DataSource/Internal/Request.elm +0 -20
- package/src/DataSource/Port.elm +0 -90
- package/src/DataSource.elm +0 -538
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
module FatalError exposing (FatalError, fromString, recoverable)
|
|
2
|
+
|
|
3
|
+
{-| The Elm language doesn't have the concept of exceptions or special control flow for errors. It just has
|
|
4
|
+
Custom Types, and by convention types like `Result` and the `Err` variant are used to represent possible failure states
|
|
5
|
+
and combine together different error states.
|
|
6
|
+
|
|
7
|
+
`elm-pages` doesn't change that, Elm still doesn't have special exception control flow at the language level. It does have
|
|
8
|
+
a type, which is just a regular old Elm type, called `FatalError`. Why? Because this plain old Elm type does have one
|
|
9
|
+
special characteristic - the `elm-pages` framework knows how to turn it into an error message. This becomes interesting
|
|
10
|
+
because an `elm-pages` app has several places that accept a value of type `BackendTask FatalError.FatalError value`.
|
|
11
|
+
This design lets the `elm-pages` framework do some of the work for you.
|
|
12
|
+
|
|
13
|
+
For example, if you wanted to handle possible errors to present them to the user
|
|
14
|
+
|
|
15
|
+
type alias Data =
|
|
16
|
+
String
|
|
17
|
+
|
|
18
|
+
data : RouteParams -> BackendTask FatalError Data
|
|
19
|
+
data routeParams =
|
|
20
|
+
BackendTask.Http.getJson "https://api.github.com/repos/dillonkearns/elm-pages"
|
|
21
|
+
(Decode.field "description" Decode.string)
|
|
22
|
+
|> BackendTask.onError
|
|
23
|
+
(\error ->
|
|
24
|
+
case FatalError.unwrap error of
|
|
25
|
+
BackendTask.Http.BadStatus metadata string ->
|
|
26
|
+
if metadata.statusCode == 401 || metadata.statusCode == 403 || metadata.statusCode == 404 then
|
|
27
|
+
BackendTask.succeed "Either this repo doesn't exist or you don't have access to it."
|
|
28
|
+
|
|
29
|
+
else
|
|
30
|
+
-- we're only handling these expected error cases. In the case of an HTTP timeout,
|
|
31
|
+
-- we'll let the error propagate as a FatalError
|
|
32
|
+
BackendTask.fail error |> BackendTask.allowFatal
|
|
33
|
+
|
|
34
|
+
_ ->
|
|
35
|
+
BackendTask.fail error |> BackendTask.allowFatal
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
This can be a lot of work for all possible errors, though. If you don't expect this kind of error (it's an _exceptional_ case),
|
|
39
|
+
you can let the framework handle it if the error ever does unexpectedly occur.
|
|
40
|
+
|
|
41
|
+
data : RouteParams -> BackendTask FatalError Data
|
|
42
|
+
data routeParams =
|
|
43
|
+
BackendTask.Http.getJson "https://api.github.com/repos/dillonkearns/elm-pages"
|
|
44
|
+
(Decode.field "description" Decode.string)
|
|
45
|
+
|> BackendTask.allowFatal
|
|
46
|
+
|
|
47
|
+
This is especially useful for pages generated at build-time (`RouteBuilder.preRender`) where you want the build
|
|
48
|
+
to fail if anything unexpected happens. With pre-rendered routes, you know that these error cases won't
|
|
49
|
+
be seen by users, so it's often a great idea to just let the framework handle these unexpected errors so a developer can
|
|
50
|
+
debug them and see what went wrong. In the example above, maybe we are only pre-rendering pages for a set of known
|
|
51
|
+
GitHub Repositories, so a Not Found or Unauthorized HTTP error would be unexpected and should stop the build so we can fix the
|
|
52
|
+
issue.
|
|
53
|
+
|
|
54
|
+
In the case of server-rendered Routes (`RouteBuilder.serverRender`), `elm-pages` will show your 500 error page
|
|
55
|
+
when these errors occur.
|
|
56
|
+
|
|
57
|
+
@docs FatalError, fromString, recoverable
|
|
58
|
+
|
|
59
|
+
-}
|
|
60
|
+
|
|
61
|
+
import Pages.Internal.FatalError
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
{-| -}
|
|
65
|
+
type alias FatalError =
|
|
66
|
+
Pages.Internal.FatalError.FatalError
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
{-| -}
|
|
70
|
+
build : { title : String, body : String } -> FatalError
|
|
71
|
+
build info =
|
|
72
|
+
Pages.Internal.FatalError.FatalError info
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
{-| -}
|
|
76
|
+
fromString : String -> FatalError
|
|
77
|
+
fromString string =
|
|
78
|
+
build
|
|
79
|
+
{ title = "Custom Error"
|
|
80
|
+
, body = string
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
{-| -}
|
|
85
|
+
recoverable : { title : String, body : String } -> error -> { fatal : FatalError, recoverable : error }
|
|
86
|
+
recoverable info value =
|
|
87
|
+
{ fatal = build info
|
|
88
|
+
, recoverable = value
|
|
89
|
+
}
|
package/src/Form/Field.elm
CHANGED
package/src/Form.elm
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
module Form exposing
|
|
2
2
|
( Form, HtmlForm, StyledHtmlForm, DoneForm
|
|
3
|
-
, Response
|
|
3
|
+
, Response
|
|
4
4
|
, init
|
|
5
5
|
, field, hiddenField, hiddenKind
|
|
6
6
|
, Context
|
|
@@ -23,7 +23,7 @@ module Form exposing
|
|
|
23
23
|
- Showing validation errors on the client-side
|
|
24
24
|
- Receiving a form submission on the server-side
|
|
25
25
|
- Using the exact same client-side validations on the server-side
|
|
26
|
-
- Letting you run server-only Validations with
|
|
26
|
+
- Letting you run server-only Validations with BackendTask's (things like checking for a unique username)
|
|
27
27
|
|
|
28
28
|
Because elm-pages is a framework, it has its own internal Model and Msg's. That means you, the user,
|
|
29
29
|
can offload some of the responsibility to elm-pages and build an interactive form with real-time
|
|
@@ -64,7 +64,7 @@ them into a type and/or errors.
|
|
|
64
64
|
|
|
65
65
|
Totally customizable. Uses [`Form.FieldView`](Form-FieldView) to render all of the fields declared.
|
|
66
66
|
|
|
67
|
-
import
|
|
67
|
+
import BackendTask exposing (BackendTask)
|
|
68
68
|
import ErrorPage exposing (ErrorPage)
|
|
69
69
|
import Form
|
|
70
70
|
import Form.Field as Field
|
|
@@ -184,7 +184,7 @@ Totally customizable. Uses [`Form.FieldView`](Form-FieldView) to render all of t
|
|
|
184
184
|
|
|
185
185
|
### Step 3 - Handle Server-Side Form Submissions
|
|
186
186
|
|
|
187
|
-
action : RouteParams -> Request.Parser (
|
|
187
|
+
action : RouteParams -> Request.Parser (BackendTask (Response ActionData ErrorPage))
|
|
188
188
|
action routeParams =
|
|
189
189
|
Request.formData [ signupForm ]
|
|
190
190
|
|> Request.map
|
|
@@ -192,8 +192,8 @@ Totally customizable. Uses [`Form.FieldView`](Form-FieldView) to render all of t
|
|
|
192
192
|
case signupResult of
|
|
193
193
|
Ok newUser ->
|
|
194
194
|
newUser
|
|
195
|
-
|>
|
|
196
|
-
|>
|
|
195
|
+
|> myCreateUserBackendTask
|
|
196
|
+
|> BackendTask.map
|
|
197
197
|
(\() ->
|
|
198
198
|
-- redirect to the home page
|
|
199
199
|
-- after successful sign-up
|
|
@@ -202,12 +202,12 @@ Totally customizable. Uses [`Form.FieldView`](Form-FieldView) to render all of t
|
|
|
202
202
|
|
|
203
203
|
Err _ ->
|
|
204
204
|
Route.redirectTo Route.Login
|
|
205
|
-
|>
|
|
205
|
+
|> BackendTask.succeed
|
|
206
206
|
)
|
|
207
207
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
208
|
+
myCreateUserBackendTask : BackendTask ()
|
|
209
|
+
myCreateUserBackendTask =
|
|
210
|
+
BackendTask.fail
|
|
211
211
|
"TODO - make a database call to create a new user"
|
|
212
212
|
|
|
213
213
|
|
|
@@ -267,12 +267,13 @@ Totally customizable. Uses [`Form.FieldView`](Form-FieldView) to render all of t
|
|
|
267
267
|
|
|
268
268
|
-}
|
|
269
269
|
|
|
270
|
-
import
|
|
270
|
+
import BackendTask exposing (BackendTask)
|
|
271
271
|
import Dict exposing (Dict)
|
|
272
|
+
import FatalError exposing (FatalError)
|
|
272
273
|
import Form.Field as Field exposing (Field(..))
|
|
273
274
|
import Form.FieldStatus as FieldStatus exposing (FieldStatus)
|
|
274
275
|
import Form.FieldView
|
|
275
|
-
import Form.Validation as Validation exposing (Combined
|
|
276
|
+
import Form.Validation as Validation exposing (Combined)
|
|
276
277
|
import Html exposing (Html)
|
|
277
278
|
import Html.Attributes as Attr
|
|
278
279
|
import Html.Lazy
|
|
@@ -280,7 +281,7 @@ import Html.Styled
|
|
|
280
281
|
import Html.Styled.Attributes as StyledAttr
|
|
281
282
|
import Html.Styled.Lazy
|
|
282
283
|
import Pages.FormState as Form exposing (FormState)
|
|
283
|
-
import Pages.Internal.Form exposing (Validation(..))
|
|
284
|
+
import Pages.Internal.Form exposing (Validation(..), unwrapResponse)
|
|
284
285
|
import Pages.Msg
|
|
285
286
|
import Pages.Transition exposing (Transition(..))
|
|
286
287
|
import Path exposing (Path)
|
|
@@ -332,7 +333,7 @@ dynamic :
|
|
|
332
333
|
->
|
|
333
334
|
Form
|
|
334
335
|
error
|
|
335
|
-
{ combine : Validation error parsed named constraints1
|
|
336
|
+
{ combine : Validation.Validation error parsed named constraints1
|
|
336
337
|
, view : subView
|
|
337
338
|
}
|
|
338
339
|
data
|
|
@@ -341,7 +342,7 @@ dynamic :
|
|
|
341
342
|
Form
|
|
342
343
|
error
|
|
343
344
|
--((decider -> Validation error parsed named) -> combined)
|
|
344
|
-
({ combine : decider -> Validation error parsed named constraints1
|
|
345
|
+
({ combine : decider -> Validation.Validation error parsed named constraints1
|
|
345
346
|
, view : decider -> subView
|
|
346
347
|
}
|
|
347
348
|
-> combineAndView
|
|
@@ -674,14 +675,14 @@ hiddenField name (Field fieldParser _) (Form definitions parseFn toInitialValues
|
|
|
674
675
|
toServerForm :
|
|
675
676
|
Form
|
|
676
677
|
error
|
|
677
|
-
{ combine : Validation error combined kind constraints
|
|
678
|
+
{ combine : Validation.Validation error combined kind constraints
|
|
678
679
|
, view : viewFn
|
|
679
680
|
}
|
|
680
681
|
data
|
|
681
682
|
->
|
|
682
683
|
Form
|
|
683
684
|
error
|
|
684
|
-
{ combine : Validation error (
|
|
685
|
+
{ combine : Validation.Validation error (BackendTask FatalError (Validation.Validation error combined kind constraints)) kind constraints
|
|
685
686
|
, view : viewFn
|
|
686
687
|
}
|
|
687
688
|
data
|
|
@@ -694,7 +695,7 @@ toServerForm (Form a b c) =
|
|
|
694
695
|
{ result : Dict String (List error)
|
|
695
696
|
, isMatchCandidate : Bool
|
|
696
697
|
, combineAndView :
|
|
697
|
-
{ combine : Validation error (
|
|
698
|
+
{ combine : Validation.Validation error (BackendTask FatalError (Validation.Validation error combined kind constraints)) kind constraints
|
|
698
699
|
, view : viewFn
|
|
699
700
|
}
|
|
700
701
|
}
|
|
@@ -705,7 +706,7 @@ toServerForm (Form a b c) =
|
|
|
705
706
|
, combineAndView =
|
|
706
707
|
{ combine =
|
|
707
708
|
thing.combineAndView.combine
|
|
708
|
-
|>
|
|
709
|
+
|> BackendTask.succeed
|
|
709
710
|
|> Validation.succeed2
|
|
710
711
|
, view = thing.combineAndView.view
|
|
711
712
|
}
|
|
@@ -797,13 +798,13 @@ type alias AppContext app actionData =
|
|
|
797
798
|
| --, sharedData : Shared.Data
|
|
798
799
|
--, routeParams : routeParams
|
|
799
800
|
path : Path
|
|
801
|
+
, action : Maybe actionData
|
|
800
802
|
|
|
801
|
-
--, action : Maybe action
|
|
802
803
|
--, submit :
|
|
803
804
|
-- { fields : List ( String, String ), headers : List ( String, String ) }
|
|
804
805
|
-- -> Pages.Fetcher.Fetcher (Result Http.Error action)
|
|
805
806
|
, transition : Maybe Transition
|
|
806
|
-
, fetchers : Dict String (Pages.Transition.FetcherState actionData)
|
|
807
|
+
, fetchers : Dict String (Pages.Transition.FetcherState (Maybe actionData))
|
|
807
808
|
, pageFormState :
|
|
808
809
|
Dict String { fields : Dict String { value : String, status : FieldStatus }, submitAttempted : Bool }
|
|
809
810
|
}
|
|
@@ -844,7 +845,7 @@ parse :
|
|
|
844
845
|
String
|
|
845
846
|
-> AppContext app actionData
|
|
846
847
|
-> data
|
|
847
|
-
-> Form error { info | combine : Validation error parsed named constraints } data
|
|
848
|
+
-> Form error { info | combine : Validation.Validation error parsed named constraints } data
|
|
848
849
|
-> ( Maybe parsed, Dict String (List error) )
|
|
849
850
|
parse formId app data (Form _ parser _) =
|
|
850
851
|
-- TODO Get transition context from `app` so you can check if the current form is being submitted
|
|
@@ -883,7 +884,7 @@ insertIfNonempty key values dict =
|
|
|
883
884
|
{-| -}
|
|
884
885
|
runServerSide :
|
|
885
886
|
List ( String, String )
|
|
886
|
-
-> Form error (Validation error parsed kind constraints) data
|
|
887
|
+
-> Form error (Validation.Validation error parsed kind constraints) data
|
|
887
888
|
-> ( Bool, ( Maybe parsed, Dict String (List error) ) )
|
|
888
889
|
runServerSide rawFormData (Form _ parser _) =
|
|
889
890
|
let
|
|
@@ -979,25 +980,21 @@ runOneOfServerSideHelp rawFormData firstFoundErrors (ServerForms parsers) =
|
|
|
979
980
|
{-| -}
|
|
980
981
|
renderHtml :
|
|
981
982
|
List (Html.Attribute (Pages.Msg.Msg msg))
|
|
982
|
-
->
|
|
983
|
-
Maybe
|
|
984
|
-
{ fields : List ( String, String )
|
|
985
|
-
, errors : Dict String (List error)
|
|
986
|
-
}
|
|
983
|
+
-> (actionData -> Maybe (Response error))
|
|
987
984
|
-> AppContext app actionData
|
|
988
985
|
-> data
|
|
989
986
|
->
|
|
990
987
|
FinalForm
|
|
991
988
|
error
|
|
992
|
-
(Validation error parsed named constraints)
|
|
989
|
+
(Validation.Validation error parsed named constraints)
|
|
993
990
|
data
|
|
994
991
|
(Context error data
|
|
995
992
|
-> List (Html (Pages.Msg.Msg msg))
|
|
996
993
|
)
|
|
997
994
|
msg
|
|
998
995
|
-> Html (Pages.Msg.Msg msg)
|
|
999
|
-
renderHtml attrs
|
|
1000
|
-
Html.Lazy.lazy6 renderHelper attrs
|
|
996
|
+
renderHtml attrs accessResponse app data (FinalForm options a b c) =
|
|
997
|
+
Html.Lazy.lazy6 renderHelper attrs accessResponse options app data (FormInternal a b c)
|
|
1001
998
|
|
|
1002
999
|
|
|
1003
1000
|
{-| -}
|
|
@@ -1025,14 +1022,14 @@ toDynamicFetcher :
|
|
|
1025
1022
|
->
|
|
1026
1023
|
Form
|
|
1027
1024
|
error
|
|
1028
|
-
{ combine : Validation error parsed field constraints
|
|
1025
|
+
{ combine : Validation.Validation error parsed field constraints
|
|
1029
1026
|
, view : Context error data -> view
|
|
1030
1027
|
}
|
|
1031
1028
|
data
|
|
1032
1029
|
->
|
|
1033
1030
|
FinalForm
|
|
1034
1031
|
error
|
|
1035
|
-
(Validation error parsed field constraints)
|
|
1032
|
+
(Validation.Validation error parsed field constraints)
|
|
1036
1033
|
data
|
|
1037
1034
|
(Context error data -> view)
|
|
1038
1035
|
userMsg
|
|
@@ -1098,14 +1095,14 @@ toDynamicTransition :
|
|
|
1098
1095
|
->
|
|
1099
1096
|
Form
|
|
1100
1097
|
error
|
|
1101
|
-
{ combine : Validation error parsed field constraints
|
|
1098
|
+
{ combine : Validation.Validation error parsed field constraints
|
|
1102
1099
|
, view : Context error data -> view
|
|
1103
1100
|
}
|
|
1104
1101
|
data
|
|
1105
1102
|
->
|
|
1106
1103
|
FinalForm
|
|
1107
1104
|
error
|
|
1108
|
-
(Validation error parsed field constraints)
|
|
1105
|
+
(Validation.Validation error parsed field constraints)
|
|
1109
1106
|
data
|
|
1110
1107
|
(Context error data -> view)
|
|
1111
1108
|
userMsg
|
|
@@ -1126,7 +1123,7 @@ toDynamicTransition name (Form a b c) =
|
|
|
1126
1123
|
{ result : Dict String (List error)
|
|
1127
1124
|
, isMatchCandidate : Bool
|
|
1128
1125
|
, combineAndView :
|
|
1129
|
-
{ combine : Validation error parsed field constraints
|
|
1126
|
+
{ combine : Validation.Validation error parsed field constraints
|
|
1130
1127
|
, view : Context error data -> view
|
|
1131
1128
|
}
|
|
1132
1129
|
}
|
|
@@ -1136,7 +1133,7 @@ toDynamicTransition name (Form a b c) =
|
|
|
1136
1133
|
-> FormState
|
|
1137
1134
|
->
|
|
1138
1135
|
{ result :
|
|
1139
|
-
( Validation error parsed field constraints
|
|
1136
|
+
( Validation.Validation error parsed field constraints
|
|
1140
1137
|
, Dict String (List error)
|
|
1141
1138
|
)
|
|
1142
1139
|
, isMatchCandidate : Bool
|
|
@@ -1150,7 +1147,7 @@ toDynamicTransition name (Form a b c) =
|
|
|
1150
1147
|
{ result : Dict String (List error)
|
|
1151
1148
|
, isMatchCandidate : Bool
|
|
1152
1149
|
, combineAndView :
|
|
1153
|
-
{ combine : Validation error parsed field constraints
|
|
1150
|
+
{ combine : Validation.Validation error parsed field constraints
|
|
1154
1151
|
, view : Context error data -> view
|
|
1155
1152
|
}
|
|
1156
1153
|
}
|
|
@@ -1180,53 +1177,42 @@ withOnSubmit onSubmit (FinalForm options a b c) =
|
|
|
1180
1177
|
{-| -}
|
|
1181
1178
|
renderStyledHtml :
|
|
1182
1179
|
List (Html.Styled.Attribute (Pages.Msg.Msg msg))
|
|
1183
|
-
->
|
|
1184
|
-
Maybe
|
|
1185
|
-
{ fields : List ( String, String )
|
|
1186
|
-
, errors : Dict String (List error)
|
|
1187
|
-
}
|
|
1180
|
+
-> (actionData -> Maybe (Response error))
|
|
1188
1181
|
-> AppContext app actionData
|
|
1189
1182
|
-> data
|
|
1190
1183
|
->
|
|
1191
1184
|
FinalForm
|
|
1192
1185
|
error
|
|
1193
|
-
(Validation error parsed named constraints)
|
|
1186
|
+
(Validation.Validation error parsed named constraints)
|
|
1194
1187
|
data
|
|
1195
1188
|
(Context error data
|
|
1196
1189
|
-> List (Html.Styled.Html (Pages.Msg.Msg msg))
|
|
1197
1190
|
)
|
|
1198
1191
|
msg
|
|
1199
1192
|
-> Html.Styled.Html (Pages.Msg.Msg msg)
|
|
1200
|
-
renderStyledHtml attrs
|
|
1201
|
-
Html.Styled.Lazy.lazy6 renderStyledHelper attrs
|
|
1193
|
+
renderStyledHtml attrs accessResponse app data (FinalForm options a b c) =
|
|
1194
|
+
Html.Styled.Lazy.lazy6 renderStyledHelper attrs accessResponse options app data (FormInternal a b c)
|
|
1202
1195
|
|
|
1203
1196
|
|
|
1204
1197
|
{-| -}
|
|
1205
|
-
type Response error
|
|
1206
|
-
|
|
1207
|
-
{ fields : List ( String, String )
|
|
1208
|
-
, errors : Dict String (List error)
|
|
1209
|
-
}
|
|
1198
|
+
type alias Response error =
|
|
1199
|
+
Pages.Internal.Form.Response error
|
|
1210
1200
|
|
|
1211
1201
|
|
|
1212
1202
|
renderHelper :
|
|
1213
1203
|
List (Html.Attribute (Pages.Msg.Msg msg))
|
|
1214
|
-
->
|
|
1215
|
-
Maybe
|
|
1216
|
-
{ fields : List ( String, String )
|
|
1217
|
-
, errors : Dict String (List error)
|
|
1218
|
-
}
|
|
1204
|
+
-> (actionData -> Maybe (Response error))
|
|
1219
1205
|
-> RenderOptions msg
|
|
1220
1206
|
-> AppContext app actionData
|
|
1221
1207
|
-> data
|
|
1222
|
-
-> FormInternal error (Validation error parsed named constraints) data (Context error data -> List (Html (Pages.Msg.Msg msg)))
|
|
1208
|
+
-> FormInternal error (Validation.Validation error parsed named constraints) data (Context error data -> List (Html (Pages.Msg.Msg msg)))
|
|
1223
1209
|
-> Html (Pages.Msg.Msg msg)
|
|
1224
|
-
renderHelper attrs
|
|
1210
|
+
renderHelper attrs accessResponse options formState data form =
|
|
1225
1211
|
-- TODO Get transition context from `app` so you can check if the current form is being submitted
|
|
1226
1212
|
-- TODO either as a transition or a fetcher? Should be easy enough to check for the `id` on either of those?
|
|
1227
1213
|
let
|
|
1228
1214
|
{ formId, hiddenInputs, children, isValid } =
|
|
1229
|
-
helperValues toHiddenInput
|
|
1215
|
+
helperValues toHiddenInput accessResponse options formState data form
|
|
1230
1216
|
|
|
1231
1217
|
toHiddenInput : List (Html.Attribute (Pages.Msg.Msg msg)) -> Html (Pages.Msg.Msg msg)
|
|
1232
1218
|
toHiddenInput hiddenAttrs =
|
|
@@ -1253,22 +1239,18 @@ renderHelper attrs maybe options formState data form =
|
|
|
1253
1239
|
|
|
1254
1240
|
renderStyledHelper :
|
|
1255
1241
|
List (Html.Styled.Attribute (Pages.Msg.Msg msg))
|
|
1256
|
-
->
|
|
1257
|
-
Maybe
|
|
1258
|
-
{ fields : List ( String, String )
|
|
1259
|
-
, errors : Dict String (List error)
|
|
1260
|
-
}
|
|
1242
|
+
-> (actionData -> Maybe (Response error))
|
|
1261
1243
|
-> RenderOptions msg
|
|
1262
1244
|
-> AppContext app actionData
|
|
1263
1245
|
-> data
|
|
1264
|
-
-> FormInternal error (Validation error parsed named constraints) data (Context error data -> List (Html.Styled.Html (Pages.Msg.Msg msg)))
|
|
1246
|
+
-> FormInternal error (Validation.Validation error parsed named constraints) data (Context error data -> List (Html.Styled.Html (Pages.Msg.Msg msg)))
|
|
1265
1247
|
-> Html.Styled.Html (Pages.Msg.Msg msg)
|
|
1266
|
-
renderStyledHelper attrs
|
|
1248
|
+
renderStyledHelper attrs accessResponse options formState data form =
|
|
1267
1249
|
-- TODO Get transition context from `app` so you can check if the current form is being submitted
|
|
1268
1250
|
-- TODO either as a transition or a fetcher? Should be easy enough to check for the `id` on either of those?
|
|
1269
1251
|
let
|
|
1270
1252
|
{ formId, hiddenInputs, children, isValid } =
|
|
1271
|
-
helperValues toHiddenInput
|
|
1253
|
+
helperValues toHiddenInput accessResponse options formState data form
|
|
1272
1254
|
|
|
1273
1255
|
toHiddenInput : List (Html.Attribute (Pages.Msg.Msg msg)) -> Html.Styled.Html (Pages.Msg.Msg msg)
|
|
1274
1256
|
toHiddenInput hiddenAttrs =
|
|
@@ -1295,18 +1277,14 @@ renderStyledHelper attrs maybe options formState data form =
|
|
|
1295
1277
|
|
|
1296
1278
|
helperValues :
|
|
1297
1279
|
(List (Html.Attribute (Pages.Msg.Msg msg)) -> view)
|
|
1298
|
-
->
|
|
1299
|
-
Maybe
|
|
1300
|
-
{ fields : List ( String, String )
|
|
1301
|
-
, errors : Dict String (List error)
|
|
1302
|
-
}
|
|
1280
|
+
-> (actionData -> Maybe (Response error))
|
|
1303
1281
|
-> RenderOptions msg
|
|
1304
1282
|
-> AppContext app actionData
|
|
1305
1283
|
-> data
|
|
1306
1284
|
---> Form error parsed data view
|
|
1307
|
-
-> FormInternal error (Validation error parsed named constraints) data (Context error data -> List view)
|
|
1285
|
+
-> FormInternal error (Validation.Validation error parsed named constraints) data (Context error data -> List view)
|
|
1308
1286
|
-> { formId : String, hiddenInputs : List view, children : List view, isValid : Bool }
|
|
1309
|
-
helperValues toHiddenInput
|
|
1287
|
+
helperValues toHiddenInput accessResponse options formState data (FormInternal fieldDefinitions parser toInitialValues) =
|
|
1310
1288
|
let
|
|
1311
1289
|
formId : String
|
|
1312
1290
|
formId =
|
|
@@ -1323,7 +1301,8 @@ helperValues toHiddenInput maybe options formState data (FormInternal fieldDefin
|
|
|
1323
1301
|
formState.pageFormState
|
|
1324
1302
|
|> Dict.get formId
|
|
1325
1303
|
|> Maybe.withDefault
|
|
1326
|
-
(
|
|
1304
|
+
(formState.action
|
|
1305
|
+
|> Maybe.andThen (accessResponse >> Maybe.map unwrapResponse)
|
|
1327
1306
|
|> Maybe.map
|
|
1328
1307
|
(\{ fields } ->
|
|
1329
1308
|
{ fields =
|
|
@@ -1343,18 +1322,18 @@ helperValues toHiddenInput maybe options formState data (FormInternal fieldDefin
|
|
|
1343
1322
|
|> Dict.union part2
|
|
1344
1323
|
|
|
1345
1324
|
parsed :
|
|
1346
|
-
{ result : ( Validation error parsed named constraints, Dict String (List error) )
|
|
1325
|
+
{ result : ( Validation.Validation error parsed named constraints, Dict String (List error) )
|
|
1347
1326
|
, isMatchCandidate : Bool
|
|
1348
1327
|
, view : Context error data -> List view
|
|
1349
1328
|
}
|
|
1350
1329
|
parsed =
|
|
1351
1330
|
parser (Just data) thisFormState
|
|
1352
1331
|
|
|
1353
|
-
withoutServerErrors : Validation error parsed named constraints
|
|
1332
|
+
withoutServerErrors : Validation.Validation error parsed named constraints
|
|
1354
1333
|
withoutServerErrors =
|
|
1355
1334
|
parsed |> mergeResults
|
|
1356
1335
|
|
|
1357
|
-
withServerErrors : Validation error parsed named constraints
|
|
1336
|
+
withServerErrors : Validation.Validation error parsed named constraints
|
|
1358
1337
|
withServerErrors =
|
|
1359
1338
|
mergeResults
|
|
1360
1339
|
{ parsed
|
|
@@ -1363,8 +1342,8 @@ helperValues toHiddenInput maybe options formState data (FormInternal fieldDefin
|
|
|
1363
1342
|
|> Tuple.mapSecond
|
|
1364
1343
|
(\errors1 ->
|
|
1365
1344
|
mergeErrors errors1
|
|
1366
|
-
(
|
|
1367
|
-
|> Maybe.map .errors
|
|
1345
|
+
(formState.action
|
|
1346
|
+
|> Maybe.andThen (accessResponse >> Maybe.map (unwrapResponse >> .errors))
|
|
1368
1347
|
|> Maybe.withDefault Dict.empty
|
|
1369
1348
|
)
|
|
1370
1349
|
)
|
|
@@ -1375,7 +1354,8 @@ helperValues toHiddenInput maybe options formState data (FormInternal fieldDefin
|
|
|
1375
1354
|
formState.pageFormState
|
|
1376
1355
|
|> Dict.get formId
|
|
1377
1356
|
|> Maybe.withDefault
|
|
1378
|
-
(
|
|
1357
|
+
(formState.action
|
|
1358
|
+
|> Maybe.andThen (accessResponse >> Maybe.map unwrapResponse)
|
|
1379
1359
|
|> Maybe.map
|
|
1380
1360
|
(\{ fields } ->
|
|
1381
1361
|
{ fields =
|
|
@@ -1498,7 +1478,7 @@ initCombined :
|
|
|
1498
1478
|
Form
|
|
1499
1479
|
error
|
|
1500
1480
|
{ combineAndView
|
|
1501
|
-
| combine : Validation error parsed kind constraints
|
|
1481
|
+
| combine : Validation.Validation error parsed kind constraints
|
|
1502
1482
|
}
|
|
1503
1483
|
input
|
|
1504
1484
|
-> ServerForms error combined
|
|
@@ -1511,7 +1491,7 @@ initCombined mapFn (Form _ parseFn _) =
|
|
|
1511
1491
|
foo :
|
|
1512
1492
|
{ result : Dict String (List error)
|
|
1513
1493
|
, isMatchCandidate : Bool
|
|
1514
|
-
, combineAndView : { combineAndView | combine : Validation error parsed kind constraints }
|
|
1494
|
+
, combineAndView : { combineAndView | combine : Validation.Validation error parsed kind constraints }
|
|
1515
1495
|
}
|
|
1516
1496
|
foo =
|
|
1517
1497
|
parseFn Nothing formState
|
|
@@ -1532,7 +1512,7 @@ combine :
|
|
|
1532
1512
|
Form
|
|
1533
1513
|
error
|
|
1534
1514
|
{ combineAndView
|
|
1535
|
-
| combine : Validation error parsed kind constraints
|
|
1515
|
+
| combine : Validation.Validation error parsed kind constraints
|
|
1536
1516
|
}
|
|
1537
1517
|
input
|
|
1538
1518
|
-> ServerForms error combined
|
|
@@ -1546,7 +1526,7 @@ combine mapFn (Form _ parseFn _) (ServerForms serverForms) =
|
|
|
1546
1526
|
foo :
|
|
1547
1527
|
{ result : Dict String (List error)
|
|
1548
1528
|
, isMatchCandidate : Bool
|
|
1549
|
-
, combineAndView : { combineAndView | combine : Validation error parsed kind constraints }
|
|
1529
|
+
, combineAndView : { combineAndView | combine : Validation.Validation error parsed kind constraints }
|
|
1550
1530
|
}
|
|
1551
1531
|
foo =
|
|
1552
1532
|
parseFn Nothing formState
|
|
@@ -1568,12 +1548,12 @@ initCombinedServer :
|
|
|
1568
1548
|
Form
|
|
1569
1549
|
error
|
|
1570
1550
|
{ combineAndView
|
|
1571
|
-
| combine : Combined error (
|
|
1551
|
+
| combine : Combined error (BackendTask backendTaskError (Validation.Validation error parsed kind constraints))
|
|
1572
1552
|
}
|
|
1573
1553
|
input
|
|
1574
|
-
-> ServerForms error (
|
|
1554
|
+
-> ServerForms error (BackendTask backendTaskError (Validation.Validation error combined kind constraints))
|
|
1575
1555
|
initCombinedServer mapFn serverForms =
|
|
1576
|
-
initCombined (
|
|
1556
|
+
initCombined (BackendTask.map (Validation.map mapFn)) serverForms
|
|
1577
1557
|
|
|
1578
1558
|
|
|
1579
1559
|
{-| -}
|
|
@@ -1584,13 +1564,13 @@ combineServer :
|
|
|
1584
1564
|
error
|
|
1585
1565
|
{ combineAndView
|
|
1586
1566
|
| combine :
|
|
1587
|
-
Combined error (
|
|
1567
|
+
Combined error (BackendTask backendTaskError (Validation.Validation error parsed kind constraints))
|
|
1588
1568
|
}
|
|
1589
1569
|
input
|
|
1590
|
-
-> ServerForms error (
|
|
1591
|
-
-> ServerForms error (
|
|
1570
|
+
-> ServerForms error (BackendTask backendTaskError (Validation.Validation error combined kind constraints))
|
|
1571
|
+
-> ServerForms error (BackendTask backendTaskError (Validation.Validation error combined kind constraints))
|
|
1592
1572
|
combineServer mapFn a b =
|
|
1593
|
-
combine (
|
|
1573
|
+
combine (BackendTask.map (Validation.map mapFn)) a b
|
|
1594
1574
|
|
|
1595
1575
|
|
|
1596
1576
|
{-| -}
|
package/src/Head/Seo.elm
CHANGED
|
@@ -455,9 +455,9 @@ tags (Content common details) =
|
|
|
455
455
|
-}
|
|
456
456
|
[ ( "og:type", "article" |> Head.raw |> Just )
|
|
457
457
|
, ( "article:section", articleDetails.section |> Maybe.map Head.raw )
|
|
458
|
-
, ( "article:published_time", articleDetails.publishedTime |> Maybe.map (DateOrDateTime.
|
|
459
|
-
, ( "article:modified_time", articleDetails.modifiedTime |> Maybe.map (DateOrDateTime.
|
|
460
|
-
, ( "article:expiration_time", articleDetails.expirationTime |> Maybe.map (DateOrDateTime.
|
|
458
|
+
, ( "article:published_time", articleDetails.publishedTime |> Maybe.map (DateOrDateTime.toIso8601 >> Head.raw) )
|
|
459
|
+
, ( "article:modified_time", articleDetails.modifiedTime |> Maybe.map (DateOrDateTime.toIso8601 >> Head.raw) )
|
|
460
|
+
, ( "article:expiration_time", articleDetails.expirationTime |> Maybe.map (DateOrDateTime.toIso8601 >> Head.raw) )
|
|
461
461
|
]
|
|
462
462
|
++ List.map
|
|
463
463
|
(\tag -> ( "article:tag", tag |> Head.raw |> Just ))
|
|
@@ -466,7 +466,7 @@ tags (Content common details) =
|
|
|
466
466
|
Book bookDetails ->
|
|
467
467
|
[ ( "og:type", "book" |> Head.raw |> Just )
|
|
468
468
|
, ( "og:isbn", bookDetails.isbn |> Maybe.map Head.raw )
|
|
469
|
-
, ( "og:release_date", bookDetails.releaseDate |> Maybe.map (DateOrDateTime.
|
|
469
|
+
, ( "og:release_date", bookDetails.releaseDate |> Maybe.map (DateOrDateTime.toIso8601 >> Head.raw) )
|
|
470
470
|
]
|
|
471
471
|
++ List.map
|
|
472
472
|
(\tag -> ( "book:tag", tag |> Head.raw |> Just ))
|