elm-pages 3.0.0-beta.9 → 3.0.0
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 +2 -2
- package/adapter/netlify.js +207 -0
- package/codegen/{elm-pages-codegen.js → elm-pages-codegen.cjs} +2731 -2939
- 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 +1527 -422
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Runner.elm.js +16840 -13653
- 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 +4 -4
- package/generator/dead-code-review/elm.json +9 -7
- package/generator/dead-code-review/src/Pages/Review/DeadCodeEliminateData.elm +59 -10
- package/generator/dead-code-review/tests/Pages/Review/DeadCodeEliminateDataTest.elm +52 -36
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Internal-RoutePattern.elmi +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Internal-RoutePattern.elmo +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolations.elmi +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolations.elmo +0 -0
- 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 +1527 -422
- package/generator/review/elm-stuff/tests-0.19.1/js/Runner.elm.js +25118 -21832
- 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 +4 -4
- package/generator/review/elm.json +10 -10
- package/generator/src/RouteBuilder.elm +93 -128
- package/generator/src/SharedTemplate.elm +8 -7
- package/generator/src/SiteConfig.elm +3 -2
- package/generator/src/basepath-middleware.js +3 -3
- package/generator/src/build.js +143 -59
- package/generator/src/cli.js +292 -88
- package/generator/src/codegen.js +29 -27
- package/generator/src/compatibility-key.js +3 -0
- package/generator/src/compile-elm.js +43 -26
- package/generator/src/config.js +2 -4
- package/generator/src/copy-dir.js +2 -2
- package/generator/src/dev-server.js +160 -102
- 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 +23 -23
- package/generator/src/init.js +9 -8
- package/generator/src/pre-render-html.js +10 -13
- package/generator/src/render-test.js +109 -0
- package/generator/src/render-worker.js +25 -28
- package/generator/src/render.js +320 -143
- package/generator/src/request-cache.js +265 -162
- package/generator/src/resolve-elm-module.js +64 -0
- package/generator/src/rewrite-client-elm-json.js +6 -5
- package/generator/src/rewrite-elm-json-help.js +56 -0
- package/generator/src/rewrite-elm-json.js +17 -7
- package/generator/src/route-codegen-helpers.js +16 -31
- package/generator/src/seo-renderer.js +1 -3
- package/generator/src/vite-utils.js +1 -2
- package/generator/static-code/elm-pages.js +10 -0
- package/generator/static-code/hmr.js +79 -13
- package/generator/template/app/Api.elm +3 -2
- package/generator/template/app/Effect.elm +155 -0
- package/generator/template/app/ErrorPage.elm +49 -6
- package/generator/template/app/Route/Blog/Slug_.elm +86 -0
- package/generator/template/app/Route/Greet.elm +107 -0
- package/generator/template/app/Route/Hello.elm +119 -0
- package/generator/template/app/Route/Index.elm +26 -25
- package/generator/template/app/Shared.elm +38 -39
- package/generator/template/app/Site.elm +4 -7
- package/generator/template/app/View.elm +9 -8
- package/generator/template/codegen/elm.codegen.json +18 -0
- package/generator/template/custom-backend-task.ts +3 -0
- package/generator/template/elm-pages.config.mjs +13 -0
- package/generator/template/elm-tooling.json +0 -3
- package/generator/template/elm.json +25 -20
- package/generator/template/index.ts +1 -2
- package/generator/template/netlify.toml +4 -1
- package/generator/template/package.json +10 -4
- package/generator/template/script/.elm-pages/compiled-ports/custom-backend-task.mjs +7 -0
- package/generator/template/script/custom-backend-task.ts +3 -0
- package/generator/template/script/elm.json +61 -0
- package/generator/template/script/src/AddRoute.elm +312 -0
- package/generator/template/script/src/Stars.elm +42 -0
- package/package.json +30 -27
- package/src/ApiRoute.elm +249 -82
- package/src/BackendTask/Custom.elm +325 -0
- package/src/BackendTask/Env.elm +90 -0
- package/src/{DataSource → BackendTask}/File.elm +171 -56
- package/src/{DataSource → BackendTask}/Glob.elm +136 -125
- package/src/BackendTask/Http.elm +679 -0
- package/src/{DataSource → BackendTask}/Internal/Glob.elm +1 -1
- package/src/BackendTask/Internal/Request.elm +69 -0
- package/src/BackendTask/Random.elm +79 -0
- package/src/BackendTask/Time.elm +47 -0
- package/src/BackendTask.elm +531 -0
- package/src/FatalError.elm +90 -0
- package/src/FormData.elm +21 -18
- package/src/Head/Seo.elm +4 -4
- package/src/Head.elm +112 -8
- package/src/Internal/ApiRoute.elm +7 -5
- package/src/Internal/Request.elm +84 -4
- package/src/PageServerResponse.elm +6 -1
- package/src/Pages/ConcurrentSubmission.elm +127 -0
- package/src/Pages/Form.elm +340 -0
- package/src/Pages/FormData.elm +19 -0
- package/src/Pages/GeneratorProgramConfig.elm +15 -0
- package/src/Pages/Internal/FatalError.elm +5 -0
- package/src/Pages/Internal/Msg.elm +93 -0
- package/src/Pages/Internal/NotFoundReason.elm +4 -4
- package/src/Pages/Internal/Platform/Cli.elm +586 -768
- package/src/Pages/Internal/Platform/CompatibilityKey.elm +1 -1
- package/src/Pages/Internal/Platform/Effect.elm +1 -2
- package/src/Pages/Internal/Platform/GeneratorApplication.elm +379 -0
- package/src/Pages/Internal/Platform/StaticResponses.elm +65 -276
- package/src/Pages/Internal/Platform/ToJsPayload.elm +6 -9
- package/src/Pages/Internal/Platform.elm +330 -203
- package/src/Pages/Internal/ResponseSketch.elm +2 -2
- package/src/Pages/Internal/Script.elm +17 -0
- package/src/Pages/Internal/StaticHttpBody.elm +35 -1
- package/src/Pages/Manifest.elm +52 -11
- package/src/Pages/Navigation.elm +85 -0
- package/src/Pages/PageUrl.elm +26 -12
- package/src/Pages/ProgramConfig.elm +32 -22
- package/src/Pages/Script.elm +166 -0
- package/src/Pages/SiteConfig.elm +3 -2
- package/src/Pages/StaticHttp/Request.elm +2 -2
- package/src/Pages/StaticHttpRequest.elm +23 -99
- package/src/Pages/Url.elm +3 -3
- package/src/PagesMsg.elm +88 -0
- package/src/QueryParams.elm +21 -172
- package/src/RenderRequest.elm +7 -7
- package/src/RequestsAndPending.elm +37 -20
- package/src/Result/Extra.elm +26 -0
- package/src/Scaffold/Form.elm +569 -0
- package/src/Scaffold/Route.elm +1431 -0
- package/src/Server/Request.elm +476 -1001
- package/src/Server/Response.elm +130 -36
- package/src/Server/Session.elm +181 -111
- package/src/Server/SetCookie.elm +80 -32
- package/src/Stub.elm +53 -0
- package/src/Test/Html/Internal/ElmHtml/ToString.elm +8 -9
- package/src/{Path.elm → UrlPath.elm} +33 -36
- package/generator/template/public/images/icon-png.png +0 -0
- 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 -546
- package/src/Form/Field.elm +0 -717
- package/src/Form/FieldStatus.elm +0 -36
- package/src/Form/FieldView.elm +0 -417
- 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 -1683
- package/src/FormDecoder.elm +0 -102
- package/src/Pages/FormState.elm +0 -256
- package/src/Pages/Generate.elm +0 -1242
- package/src/Pages/Internal/Form.elm +0 -17
- package/src/Pages/Internal/Platform/Cli.elm.bak +0 -1276
- package/src/Pages/Msg.elm +0 -79
- package/src/Pages/Transition.elm +0 -70
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
module Pages.Form exposing
|
|
2
|
+
( renderHtml, renderStyledHtml
|
|
3
|
+
, Options
|
|
4
|
+
, withConcurrent
|
|
5
|
+
, FormWithServerValidations, Handler
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
{-| `elm-pages` has a built-in integration with [`dillonkearns/elm-form`](https://package.elm-lang.org/packages/dillonkearns/elm-form/latest/). See the `dillonkearns/elm-form`
|
|
9
|
+
docs and examples for more information on how to define your [`Form`](https://package.elm-lang.org/packages/dillonkearns/elm-form/latest/Form). This module is the interface for rendering your `Form` in your `elm-pages` app.
|
|
10
|
+
|
|
11
|
+
By rendering your `Form` with this module,
|
|
12
|
+
you get all of the boilerplate managed for you automatically by the `elm-pages` framework. That means you do not need to use `Form.init`, `Form.update`, `Form.Model` since these are all
|
|
13
|
+
abstracted away. In addition to that, in-flight form state is automatically managed for you and exposed through the `app` argument in your Route modules.
|
|
14
|
+
|
|
15
|
+
This means that you can declaratively derive Pending UI or Optimistic UI state from `app.navigation` or `app.concurrentSubmissions` in your Route modules, and even build a
|
|
16
|
+
rich dynamic page that shows pending submissions in the UI without using your Route module's `Model`! This is the power of this abstraction - it's less error-prone to
|
|
17
|
+
declaratively derive state rather than imperatively managing your `Model`.
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
## Rendering Forms
|
|
21
|
+
|
|
22
|
+
@docs renderHtml, renderStyledHtml
|
|
23
|
+
|
|
24
|
+
@docs Options
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
## Form Submission Strategies
|
|
28
|
+
|
|
29
|
+
When you render with [`Pages.Form.renderHtml`](#renderHtml) or [`Pages.Form.renderStyledHtml`](#renderStyledHtml),
|
|
30
|
+
`elm-pages` progressively enhances form submissions to manage the requests through Elm (instead of as a vanilla HTML form submission, which performs a full page reload).
|
|
31
|
+
|
|
32
|
+
By default, `elm-pages` Forms will use the same mental model as the browser's default form submission behavior. That is, the form submission state will be tied to the page's navigation state.
|
|
33
|
+
If you click a link while a form is submitting, the form submission will be cancelled and the page will navigate to the new page. Conceptually, you can think of this as being tied to the navigation state.
|
|
34
|
+
A form submission is part of the page's navigation state, and so is a page navigation. So if you have a page with an edit form, a delete form (no inputs but only a delete button), and a link to a new page,
|
|
35
|
+
you can interact with any of these and it will cancel the previous interactions.
|
|
36
|
+
|
|
37
|
+
You can access this state through `app.navigation` in your `Route` module, which is a value of type [`Pages.Navigation`](Pages-Navigation).
|
|
38
|
+
|
|
39
|
+
This default form submission strategy is a good fit for more linear actions. This is more traditional server submission behavior that you might be familiar with from Rails or other server frameworks without JavaScript enhancement.
|
|
40
|
+
|
|
41
|
+
@docs withConcurrent
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
## Server-Side Validation
|
|
45
|
+
|
|
46
|
+
@docs FormWithServerValidations, Handler
|
|
47
|
+
|
|
48
|
+
-}
|
|
49
|
+
|
|
50
|
+
import BackendTask exposing (BackendTask)
|
|
51
|
+
import Dict exposing (Dict)
|
|
52
|
+
import FatalError exposing (FatalError)
|
|
53
|
+
import Form
|
|
54
|
+
import Form.Handler
|
|
55
|
+
import Form.Validation exposing (Validation)
|
|
56
|
+
import Html
|
|
57
|
+
import Html.Styled
|
|
58
|
+
import Pages.ConcurrentSubmission
|
|
59
|
+
import Pages.Internal.Msg
|
|
60
|
+
import Pages.Navigation
|
|
61
|
+
import PagesMsg exposing (PagesMsg)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
{-| -}
|
|
65
|
+
type alias FormWithServerValidations error combined input view =
|
|
66
|
+
Form.Form
|
|
67
|
+
error
|
|
68
|
+
{ combine :
|
|
69
|
+
Validation
|
|
70
|
+
error
|
|
71
|
+
(BackendTask FatalError (Validation error combined Never Never))
|
|
72
|
+
Never
|
|
73
|
+
Never
|
|
74
|
+
, view : Form.Context error input -> view
|
|
75
|
+
}
|
|
76
|
+
(BackendTask FatalError (Validation error combined Never Never))
|
|
77
|
+
input
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
{-| -}
|
|
81
|
+
type alias Handler error combined =
|
|
82
|
+
Form.Handler.Handler error (BackendTask FatalError (Validation error combined Never Never))
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
{-| A replacement for [`Form.Options`](https://package.elm-lang.org/packages/dillonkearns/elm-form/latest/Form#Options)
|
|
86
|
+
with some extra configuration for the `elm-pages` integration. You can use this type to annotate your form's options.
|
|
87
|
+
-}
|
|
88
|
+
type alias Options error parsed input msg =
|
|
89
|
+
Form.Options error parsed input msg { concurrent : Bool }
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
{-| Instead of using the default submission strategy (tied to the page's navigation state), you can use `withConcurrent`.
|
|
93
|
+
`withConcurrent` allows multiple form submissions to be in flight at the same time. It is useful for more dynamic applications. A good rule of thumb
|
|
94
|
+
is if you could have multiple pending spinners on the page at the same time, you should use `withConcurrent`. For example, if you have a page with a list of items,
|
|
95
|
+
say a Twitter clone. If you click the like button on a Tweet, it won't result in a page navigation. You can click the like button on multiple Tweets at the same time
|
|
96
|
+
and they will all submit independently.
|
|
97
|
+
|
|
98
|
+
In the case of Twitter, there isn't an indication of a loading spinner on the like button because it is expected that it will succeed. This is an example of a User Experience (UX) pattern
|
|
99
|
+
called Optimistic UI. Since it is very likely that liking a Tweet will be successful, the UI will update the UI as if it has immediately succeeded even though the request is still in flight.
|
|
100
|
+
If the request fails, the UI will be updated to reflect the failure with an animation to show that something went wrong.
|
|
101
|
+
|
|
102
|
+
The `withConcurrent` is a good fit for either of these UX patterns (Optimistic UI or Pending UI, i.e. showing a loading spinner). You can derive either of these
|
|
103
|
+
visual states from the `app.concurrentSubmissions` field in your `Route` module.
|
|
104
|
+
|
|
105
|
+
You can call `withConcurrent` on your `Form.Options`. Note that while `withConcurrent` will allow multiple form submissions to be in flight at the same time independently,
|
|
106
|
+
the ID of the Form will still have a unique submission. For example, if you click submit on a form with the ID `"edit-123"` and then submit it again before the first submission has completed,
|
|
107
|
+
the second submission will cancel the first submission. So it is important to use unique IDs for forms that represent unique operations.
|
|
108
|
+
|
|
109
|
+
import Form
|
|
110
|
+
import Pages.Form
|
|
111
|
+
|
|
112
|
+
todoItemView app todo =
|
|
113
|
+
deleteItemForm
|
|
114
|
+
|> Pages.Form.renderHtml []
|
|
115
|
+
(Form.options ("delete-" ++ todo.id)
|
|
116
|
+
|> Form.withInput todo
|
|
117
|
+
|> Pages.Form.withConcurrent
|
|
118
|
+
)
|
|
119
|
+
app
|
|
120
|
+
|
|
121
|
+
-}
|
|
122
|
+
withConcurrent : Options error parsed input msg -> Options error parsed input msg
|
|
123
|
+
withConcurrent options_ =
|
|
124
|
+
{ options_ | extras = Just { concurrent = True } }
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
--init :
|
|
129
|
+
-- (parsed -> combined)
|
|
130
|
+
-- -> FormWithServerValidations error parsed input view
|
|
131
|
+
-- -> Handler error combined
|
|
132
|
+
--init mapFn form =
|
|
133
|
+
-- Form.Handler.init
|
|
134
|
+
-- (\something ->
|
|
135
|
+
-- let
|
|
136
|
+
-- foo : parsed
|
|
137
|
+
-- foo =
|
|
138
|
+
-- something
|
|
139
|
+
--
|
|
140
|
+
-- goal : BackendTask FatalError (Validation error combined Never Never)
|
|
141
|
+
-- goal =
|
|
142
|
+
-- Debug.todo ""
|
|
143
|
+
-- in
|
|
144
|
+
-- --Form.Validation.map (BackendTask.map (mapFn something))
|
|
145
|
+
-- --Debug.todo ""
|
|
146
|
+
-- goal
|
|
147
|
+
-- )
|
|
148
|
+
-- form
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
{-| A replacement for `Form.renderHtml` from `dillonkearns/elm-form` that integrates with `elm-pages`. Use this to render your [`Form`](https://package.elm-lang.org/packages/dillonkearns/elm-form/latest/Form)
|
|
152
|
+
as `elm/html` `Html`.
|
|
153
|
+
-}
|
|
154
|
+
renderHtml :
|
|
155
|
+
List (Html.Attribute (PagesMsg userMsg))
|
|
156
|
+
-> Options error parsed input userMsg
|
|
157
|
+
->
|
|
158
|
+
{ --path : Path
|
|
159
|
+
--, url : Maybe PageUrl
|
|
160
|
+
--, action : Maybe action
|
|
161
|
+
app
|
|
162
|
+
| pageFormState : Form.Model
|
|
163
|
+
, navigation : Maybe Pages.Navigation.Navigation
|
|
164
|
+
, concurrentSubmissions : Dict String (Pages.ConcurrentSubmission.ConcurrentSubmission (Maybe action))
|
|
165
|
+
}
|
|
166
|
+
-> Form.Form error { combine : Validation error parsed named constraints, view : Form.Context error input -> List (Html.Html (PagesMsg userMsg)) } parsed input
|
|
167
|
+
-> Html.Html (PagesMsg userMsg)
|
|
168
|
+
renderHtml attrs options_ app form_ =
|
|
169
|
+
let
|
|
170
|
+
concurrent : Bool
|
|
171
|
+
concurrent =
|
|
172
|
+
options_.extras |> Maybe.map .concurrent |> Maybe.withDefault False
|
|
173
|
+
in
|
|
174
|
+
form_
|
|
175
|
+
|> Form.renderHtml
|
|
176
|
+
{ state = app.pageFormState
|
|
177
|
+
, submitting =
|
|
178
|
+
(case app.concurrentSubmissions |> Dict.get options_.id of
|
|
179
|
+
Just { status } ->
|
|
180
|
+
case status of
|
|
181
|
+
Pages.ConcurrentSubmission.Complete _ ->
|
|
182
|
+
False
|
|
183
|
+
|
|
184
|
+
Pages.ConcurrentSubmission.Submitting ->
|
|
185
|
+
True
|
|
186
|
+
|
|
187
|
+
Pages.ConcurrentSubmission.Reloading _ ->
|
|
188
|
+
True
|
|
189
|
+
|
|
190
|
+
Nothing ->
|
|
191
|
+
False
|
|
192
|
+
)
|
|
193
|
+
|| (case app.navigation of
|
|
194
|
+
Just (Pages.Navigation.Submitting formData) ->
|
|
195
|
+
formData.id == Just options_.id
|
|
196
|
+
|
|
197
|
+
Just (Pages.Navigation.LoadAfterSubmit submitData _ _) ->
|
|
198
|
+
submitData.id == Just options_.id
|
|
199
|
+
|
|
200
|
+
Just (Pages.Navigation.Loading _ _) ->
|
|
201
|
+
False
|
|
202
|
+
|
|
203
|
+
Nothing ->
|
|
204
|
+
False
|
|
205
|
+
)
|
|
206
|
+
, toMsg = Pages.Internal.Msg.FormMsg
|
|
207
|
+
}
|
|
208
|
+
{ id = options_.id
|
|
209
|
+
, method = options_.method
|
|
210
|
+
, input = options_.input
|
|
211
|
+
, serverResponse = options_.serverResponse
|
|
212
|
+
, action = options_.action
|
|
213
|
+
, onSubmit =
|
|
214
|
+
Just
|
|
215
|
+
(\submission ->
|
|
216
|
+
case submission.parsed of
|
|
217
|
+
Form.Valid _ ->
|
|
218
|
+
Pages.Internal.Msg.Submit
|
|
219
|
+
{ useFetcher = concurrent
|
|
220
|
+
, action = submission.action
|
|
221
|
+
, fields = submission.fields
|
|
222
|
+
, method = submission.method
|
|
223
|
+
, msg =
|
|
224
|
+
options_.onSubmit
|
|
225
|
+
|> Maybe.map
|
|
226
|
+
(\onSubmit -> onSubmit submission)
|
|
227
|
+
, id = options_.id
|
|
228
|
+
, valid = True
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
Form.Invalid _ _ ->
|
|
232
|
+
Pages.Internal.Msg.Submit
|
|
233
|
+
{ useFetcher = concurrent
|
|
234
|
+
, action = submission.action
|
|
235
|
+
, method = submission.method
|
|
236
|
+
, fields = submission.fields
|
|
237
|
+
, msg = options_.onSubmit |> Maybe.map (\onSubmit -> onSubmit submission)
|
|
238
|
+
, id = options_.id
|
|
239
|
+
, valid = False
|
|
240
|
+
}
|
|
241
|
+
)
|
|
242
|
+
, extras = Nothing
|
|
243
|
+
}
|
|
244
|
+
attrs
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
{-| A replacement for `Form.renderStyledHtml` from `dillonkearns/elm-form` that integrates with `elm-pages`. Use this to render your [`Form`](https://package.elm-lang.org/packages/dillonkearns/elm-form/latest/Form)
|
|
248
|
+
as `rtfeldman/elm-css` `Html.Styled.Html`.
|
|
249
|
+
-}
|
|
250
|
+
renderStyledHtml :
|
|
251
|
+
List (Html.Styled.Attribute (PagesMsg userMsg))
|
|
252
|
+
-> Options error parsed input userMsg
|
|
253
|
+
->
|
|
254
|
+
{ --path : Path
|
|
255
|
+
--, url : Maybe PageUrl
|
|
256
|
+
--, action : Maybe action
|
|
257
|
+
app
|
|
258
|
+
| pageFormState : Form.Model
|
|
259
|
+
, navigation : Maybe Pages.Navigation.Navigation
|
|
260
|
+
, concurrentSubmissions : Dict String (Pages.ConcurrentSubmission.ConcurrentSubmission (Maybe action))
|
|
261
|
+
}
|
|
262
|
+
-> Form.Form error { combine : Validation error parsed named constraints, view : Form.Context error input -> List (Html.Styled.Html (PagesMsg userMsg)) } parsed input
|
|
263
|
+
-> Html.Styled.Html (PagesMsg userMsg)
|
|
264
|
+
renderStyledHtml attrs options_ app form_ =
|
|
265
|
+
let
|
|
266
|
+
concurrent : Bool
|
|
267
|
+
concurrent =
|
|
268
|
+
options_.extras |> Maybe.map .concurrent |> Maybe.withDefault False
|
|
269
|
+
in
|
|
270
|
+
form_
|
|
271
|
+
|> Form.renderStyledHtml
|
|
272
|
+
{ state = app.pageFormState
|
|
273
|
+
, toMsg = Pages.Internal.Msg.FormMsg
|
|
274
|
+
, submitting =
|
|
275
|
+
(case app.concurrentSubmissions |> Dict.get options_.id of
|
|
276
|
+
Just { status } ->
|
|
277
|
+
case status of
|
|
278
|
+
Pages.ConcurrentSubmission.Complete _ ->
|
|
279
|
+
False
|
|
280
|
+
|
|
281
|
+
Pages.ConcurrentSubmission.Submitting ->
|
|
282
|
+
True
|
|
283
|
+
|
|
284
|
+
Pages.ConcurrentSubmission.Reloading _ ->
|
|
285
|
+
True
|
|
286
|
+
|
|
287
|
+
Nothing ->
|
|
288
|
+
False
|
|
289
|
+
)
|
|
290
|
+
|| (case app.navigation of
|
|
291
|
+
Just (Pages.Navigation.Submitting formData) ->
|
|
292
|
+
formData.id == Just options_.id
|
|
293
|
+
|
|
294
|
+
Just (Pages.Navigation.LoadAfterSubmit submitData _ _) ->
|
|
295
|
+
submitData.id == Just options_.id
|
|
296
|
+
|
|
297
|
+
Just (Pages.Navigation.Loading _ _) ->
|
|
298
|
+
False
|
|
299
|
+
|
|
300
|
+
Nothing ->
|
|
301
|
+
False
|
|
302
|
+
)
|
|
303
|
+
}
|
|
304
|
+
{ id = options_.id
|
|
305
|
+
, method = options_.method
|
|
306
|
+
, input = options_.input
|
|
307
|
+
, serverResponse = options_.serverResponse
|
|
308
|
+
, action = options_.action
|
|
309
|
+
, onSubmit =
|
|
310
|
+
Just
|
|
311
|
+
(\submission ->
|
|
312
|
+
case submission.parsed of
|
|
313
|
+
Form.Valid _ ->
|
|
314
|
+
Pages.Internal.Msg.Submit
|
|
315
|
+
{ useFetcher = concurrent
|
|
316
|
+
, action = submission.action
|
|
317
|
+
, fields = submission.fields
|
|
318
|
+
, method = submission.method
|
|
319
|
+
, msg =
|
|
320
|
+
options_.onSubmit
|
|
321
|
+
|> Maybe.map
|
|
322
|
+
(\onSubmit -> onSubmit submission)
|
|
323
|
+
, id = options_.id
|
|
324
|
+
, valid = True
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
Form.Invalid _ _ ->
|
|
328
|
+
Pages.Internal.Msg.Submit
|
|
329
|
+
{ useFetcher = concurrent
|
|
330
|
+
, action = submission.action
|
|
331
|
+
, fields = submission.fields
|
|
332
|
+
, method = submission.method
|
|
333
|
+
, msg = options_.onSubmit |> Maybe.map (\onSubmit -> onSubmit submission)
|
|
334
|
+
, id = options_.id
|
|
335
|
+
, valid = False
|
|
336
|
+
}
|
|
337
|
+
)
|
|
338
|
+
, extras = Nothing
|
|
339
|
+
}
|
|
340
|
+
attrs
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Pages.FormData exposing (FormData)
|
|
2
|
+
|
|
3
|
+
{-|
|
|
4
|
+
|
|
5
|
+
@docs FormData
|
|
6
|
+
|
|
7
|
+
-}
|
|
8
|
+
|
|
9
|
+
import Form
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
{-| The payload for form submissions.
|
|
13
|
+
-}
|
|
14
|
+
type alias FormData =
|
|
15
|
+
{ fields : List ( String, String )
|
|
16
|
+
, method : Form.Method
|
|
17
|
+
, action : String
|
|
18
|
+
, id : Maybe String
|
|
19
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Pages.GeneratorProgramConfig exposing (GeneratorProgramConfig)
|
|
2
|
+
|
|
3
|
+
import Json.Decode as Decode
|
|
4
|
+
import Json.Encode
|
|
5
|
+
import Pages.Internal.Platform.ToJsPayload
|
|
6
|
+
import Pages.Script exposing (Script)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
type alias GeneratorProgramConfig =
|
|
10
|
+
{ data : Script
|
|
11
|
+
, toJsPort : Json.Encode.Value -> Cmd Never
|
|
12
|
+
, fromJsPort : Sub Decode.Value
|
|
13
|
+
, gotBatchSub : Sub Decode.Value
|
|
14
|
+
, sendPageData : Pages.Internal.Platform.ToJsPayload.NewThingForPort -> Cmd Never
|
|
15
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
module Pages.Internal.Msg exposing
|
|
2
|
+
( Msg(..)
|
|
3
|
+
--, fetcherOnSubmit
|
|
4
|
+
, map
|
|
5
|
+
--, onSubmit
|
|
6
|
+
--, submitIfValid
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
--import Form.FormData exposing (FormData)
|
|
10
|
+
--import FormDecoder
|
|
11
|
+
|
|
12
|
+
import Form exposing (Method)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
{-| -}
|
|
16
|
+
type Msg userMsg
|
|
17
|
+
= UserMsg userMsg
|
|
18
|
+
| Submit { valid : Bool, method : Method, action : String, fields : List ( String, String ), id : String, msg : Maybe userMsg, useFetcher : Bool }
|
|
19
|
+
--| SubmitIfValid String FormData Bool (Maybe userMsg)
|
|
20
|
+
--| SubmitFetcher String FormData Bool (Maybe userMsg)
|
|
21
|
+
| FormMsg (Form.Msg (Msg userMsg))
|
|
22
|
+
| NoOp
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
--{-| -}
|
|
27
|
+
--onSubmit : Attribute (Msg userMsg)
|
|
28
|
+
--onSubmit =
|
|
29
|
+
-- FormDecoder.formDataOnSubmit
|
|
30
|
+
-- |> Attr.map Submit
|
|
31
|
+
--
|
|
32
|
+
--
|
|
33
|
+
--{-| -}
|
|
34
|
+
--submitIfValid : Maybe ({ fields : List ( String, String ) } -> userMsg) -> String -> (List ( String, String ) -> Bool) -> Attribute (Msg userMsg)
|
|
35
|
+
--submitIfValid userMsg formId isValid =
|
|
36
|
+
-- FormDecoder.formDataOnSubmit
|
|
37
|
+
-- |> Attr.map
|
|
38
|
+
-- (\formData ->
|
|
39
|
+
-- SubmitIfValid formId
|
|
40
|
+
-- formData
|
|
41
|
+
-- (isValid formData.fields)
|
|
42
|
+
-- (userMsg
|
|
43
|
+
-- |> Maybe.map
|
|
44
|
+
-- (\toUserMsg ->
|
|
45
|
+
-- toUserMsg { fields = formData.fields }
|
|
46
|
+
-- )
|
|
47
|
+
-- )
|
|
48
|
+
-- )
|
|
49
|
+
--
|
|
50
|
+
--
|
|
51
|
+
--
|
|
52
|
+
--{-| -}
|
|
53
|
+
--fetcherOnSubmit : Maybe ({ fields : List ( String, String ) } -> userMsg) -> String -> (List ( String, String ) -> Bool) -> Attribute (Msg userMsg)
|
|
54
|
+
--fetcherOnSubmit userMsg formId isValid =
|
|
55
|
+
-- FormDecoder.formDataOnSubmit
|
|
56
|
+
-- |> Attr.map
|
|
57
|
+
-- (\formData ->
|
|
58
|
+
-- SubmitFetcher formId
|
|
59
|
+
-- formData
|
|
60
|
+
-- (isValid formData.fields)
|
|
61
|
+
-- (userMsg
|
|
62
|
+
-- |> Maybe.map
|
|
63
|
+
-- (\toUserMsg ->
|
|
64
|
+
-- toUserMsg { fields = formData.fields }
|
|
65
|
+
-- )
|
|
66
|
+
-- )
|
|
67
|
+
-- )
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
{-| -}
|
|
71
|
+
map : (a -> b) -> Msg a -> Msg b
|
|
72
|
+
map mapFn msg =
|
|
73
|
+
-- elm-review: known-unoptimized-recursion
|
|
74
|
+
case msg of
|
|
75
|
+
UserMsg userMsg ->
|
|
76
|
+
UserMsg (mapFn userMsg)
|
|
77
|
+
|
|
78
|
+
Submit info ->
|
|
79
|
+
Submit
|
|
80
|
+
{ valid = info.valid
|
|
81
|
+
, fields = info.fields
|
|
82
|
+
, action = info.action
|
|
83
|
+
, id = info.id
|
|
84
|
+
, msg = Maybe.map mapFn info.msg
|
|
85
|
+
, method = info.method
|
|
86
|
+
, useFetcher = info.useFetcher
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
FormMsg value ->
|
|
90
|
+
FormMsg (Form.mapMsg (map mapFn) value)
|
|
91
|
+
|
|
92
|
+
NoOp ->
|
|
93
|
+
NoOp
|
|
@@ -9,7 +9,7 @@ module Pages.Internal.NotFoundReason exposing (ModuleContext, NotFoundReason(..)
|
|
|
9
9
|
import Html exposing (Html)
|
|
10
10
|
import Html.Attributes as Attr
|
|
11
11
|
import Pages.Internal.RoutePattern exposing (RoutePattern)
|
|
12
|
-
import
|
|
12
|
+
import UrlPath exposing (UrlPath)
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
{-| -}
|
|
@@ -22,7 +22,7 @@ type alias ModuleContext =
|
|
|
22
22
|
|
|
23
23
|
{-| -}
|
|
24
24
|
type alias Payload =
|
|
25
|
-
{ path :
|
|
25
|
+
{ path : UrlPath
|
|
26
26
|
, reason : NotFoundReason
|
|
27
27
|
}
|
|
28
28
|
|
|
@@ -58,7 +58,7 @@ document pathPatterns payload =
|
|
|
58
58
|
, Html.code []
|
|
59
59
|
[ Html.text
|
|
60
60
|
(payload.path
|
|
61
|
-
|>
|
|
61
|
+
|> UrlPath.toAbsolute
|
|
62
62
|
)
|
|
63
63
|
]
|
|
64
64
|
, Html.text " Did you mean to go to one of these routes:"
|
|
@@ -85,7 +85,7 @@ document pathPatterns payload =
|
|
|
85
85
|
, Html.code []
|
|
86
86
|
[ Html.text
|
|
87
87
|
(payload.path
|
|
88
|
-
|>
|
|
88
|
+
|> UrlPath.toAbsolute
|
|
89
89
|
)
|
|
90
90
|
]
|
|
91
91
|
, Html.text " successfully matched the route "
|