elm-pages 3.0.0-beta.18 → 3.0.0-beta.19
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/codegen/{elm-pages-codegen.js → elm-pages-codegen.cjs} +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/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/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/src/basepath-middleware.js +3 -3
- package/generator/src/build.js +36 -30
- package/generator/src/cli.js +30 -23
- package/generator/src/codegen.js +19 -18
- package/generator/src/compatibility-key.js +1 -1
- package/generator/src/compile-elm.js +20 -22
- package/generator/src/config.js +2 -4
- package/generator/src/dev-server.js +47 -30
- package/generator/src/dir-helpers.js +9 -25
- package/generator/src/elm-codegen.js +2 -4
- package/generator/src/elm-file-constants.js +2 -3
- package/generator/src/error-formatter.js +5 -5
- package/generator/src/file-helpers.js +3 -4
- package/generator/src/generate-template-module-connector.js +14 -15
- package/generator/src/init.js +8 -7
- package/generator/src/pre-render-html.js +11 -12
- package/generator/src/render-worker.js +21 -26
- package/generator/src/render.js +29 -40
- package/generator/src/request-cache.js +13 -8
- package/generator/src/rewrite-client-elm-json.js +5 -5
- package/generator/src/rewrite-elm-json.js +5 -5
- 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/package.json +9 -8
- package/src/BackendTask/File.elm +1 -1
- package/src/Form.elm +26 -47
- package/src/Pages/Generate.elm +42 -13
- package/src/Pages/Internal/Form.elm +14 -1
- package/src/Server/Request.elm +21 -13
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @param {string[]} name
|
|
3
3
|
*/
|
|
4
|
-
function routeParams(name) {
|
|
4
|
+
export function routeParams(name) {
|
|
5
5
|
return name
|
|
6
6
|
.map((section) => {
|
|
7
7
|
const routeParamMatch = section.match(/([A-Z][A-Za-z0-9]*)__?$/);
|
|
@@ -17,7 +17,7 @@ function routeParams(name) {
|
|
|
17
17
|
* @param {string[]} name
|
|
18
18
|
* @returns {Segment[]}
|
|
19
19
|
*/
|
|
20
|
-
function parseRouteParams(name) {
|
|
20
|
+
export function parseRouteParams(name) {
|
|
21
21
|
return name.flatMap((section) => {
|
|
22
22
|
const routeParamMatch = section.match(/([A-Z][A-Za-z0-9]*)(_?_?)$/);
|
|
23
23
|
const maybeParam = (routeParamMatch && routeParamMatch[1]) || "TODO";
|
|
@@ -68,7 +68,7 @@ function parseRouteParams(name) {
|
|
|
68
68
|
* @param {string[]} name
|
|
69
69
|
* @returns {( Segment | {kind: 'static'; name: string})[]}
|
|
70
70
|
*/
|
|
71
|
-
function parseRouteParamsWithStatic(name) {
|
|
71
|
+
export function parseRouteParamsWithStatic(name) {
|
|
72
72
|
return name.flatMap((section) => {
|
|
73
73
|
const routeParamMatch = section.match(/([A-Z][A-Za-z0-9]*)(_?_?)$/);
|
|
74
74
|
const maybeParam = (routeParamMatch && routeParamMatch[1]) || "TODO";
|
|
@@ -123,7 +123,7 @@ function parseRouteParamsWithStatic(name) {
|
|
|
123
123
|
* @param {string[]} name
|
|
124
124
|
* @returns {string}
|
|
125
125
|
*/
|
|
126
|
-
function routeVariantDefinition(name) {
|
|
126
|
+
export function routeVariantDefinition(name) {
|
|
127
127
|
const newLocal = parseRouteParams(name);
|
|
128
128
|
if (newLocal.length == 0) {
|
|
129
129
|
return routeVariant(name);
|
|
@@ -151,7 +151,7 @@ function routeVariantDefinition(name) {
|
|
|
151
151
|
* @param {string[]} name
|
|
152
152
|
* @returns {string}
|
|
153
153
|
*/
|
|
154
|
-
function toPathPattern(name) {
|
|
154
|
+
export function toPathPattern(name) {
|
|
155
155
|
return (
|
|
156
156
|
"/" +
|
|
157
157
|
parseRouteParamsWithStatic(name)
|
|
@@ -181,7 +181,7 @@ function toPathPattern(name) {
|
|
|
181
181
|
* @param {string[]} name
|
|
182
182
|
* @returns {string[]}
|
|
183
183
|
*/
|
|
184
|
-
function toPathPatterns(name) {
|
|
184
|
+
export function toPathPatterns(name) {
|
|
185
185
|
const segments = parseRouteParamsWithStatic(name);
|
|
186
186
|
|
|
187
187
|
const lastSegment = segments[segments.length - 1];
|
|
@@ -199,7 +199,7 @@ function toPathPatterns(name) {
|
|
|
199
199
|
/**
|
|
200
200
|
* @param {string[]} segments
|
|
201
201
|
*/
|
|
202
|
-
function joinPath(segments) {
|
|
202
|
+
export function joinPath(segments) {
|
|
203
203
|
const joined = segments.join("/");
|
|
204
204
|
if (joined.startsWith("/")) {
|
|
205
205
|
return joined;
|
|
@@ -211,7 +211,7 @@ function joinPath(segments) {
|
|
|
211
211
|
/**
|
|
212
212
|
* @return {string[]}
|
|
213
213
|
*/
|
|
214
|
-
function newHelper(segments) {
|
|
214
|
+
export function newHelper(segments) {
|
|
215
215
|
return segments.map((param) => {
|
|
216
216
|
switch (param.kind) {
|
|
217
217
|
case "static": {
|
|
@@ -238,7 +238,7 @@ function newHelper(segments) {
|
|
|
238
238
|
* @param {string[]} name
|
|
239
239
|
* @returns {string}
|
|
240
240
|
*/
|
|
241
|
-
function toElmPathPattern(name) {
|
|
241
|
+
export function toElmPathPattern(name) {
|
|
242
242
|
const parsedSegments = parseRouteParamsWithStatic(name);
|
|
243
243
|
|
|
244
244
|
const foundEndings = parsedSegments.flatMap((segment) => {
|
|
@@ -297,14 +297,14 @@ function toElmPathPattern(name) {
|
|
|
297
297
|
* @param {string} input
|
|
298
298
|
* @returns {string}
|
|
299
299
|
*/
|
|
300
|
-
function camelToKebab(input) {
|
|
300
|
+
export function camelToKebab(input) {
|
|
301
301
|
return input.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
302
302
|
}
|
|
303
303
|
|
|
304
304
|
/**
|
|
305
305
|
* @param {string[]} name
|
|
306
306
|
*/
|
|
307
|
-
function paramsRecord(name) {
|
|
307
|
+
export function paramsRecord(name) {
|
|
308
308
|
return `{ ${parseRouteParams(name).map((param) => {
|
|
309
309
|
switch (param.kind) {
|
|
310
310
|
case "dynamic": {
|
|
@@ -326,7 +326,7 @@ function paramsRecord(name) {
|
|
|
326
326
|
/**
|
|
327
327
|
* @param {string[]} name
|
|
328
328
|
*/
|
|
329
|
-
function routeVariant(name) {
|
|
329
|
+
export function routeVariant(name) {
|
|
330
330
|
return `${name.join("__")}`;
|
|
331
331
|
}
|
|
332
332
|
|
|
@@ -334,44 +334,29 @@ function routeVariant(name) {
|
|
|
334
334
|
* @param {string[]} name
|
|
335
335
|
* @param {string} paramsName
|
|
336
336
|
*/
|
|
337
|
-
function destructureRoute(name, paramsName) {
|
|
337
|
+
export function destructureRoute(name, paramsName) {
|
|
338
338
|
return emptyRouteParams(name)
|
|
339
339
|
? `Route.${routeVariant(name)}`
|
|
340
340
|
: `(Route.${routeVariant(name)} ${paramsName})`;
|
|
341
341
|
}
|
|
342
342
|
|
|
343
|
-
function referenceRouteParams(name, paramsName) {
|
|
343
|
+
export function referenceRouteParams(name, paramsName) {
|
|
344
344
|
return emptyRouteParams(name) ? `{}` : paramsName;
|
|
345
345
|
}
|
|
346
346
|
/**
|
|
347
347
|
* @param {string[]} name
|
|
348
348
|
*/
|
|
349
|
-
function emptyRouteParams(name) {
|
|
349
|
+
export function emptyRouteParams(name) {
|
|
350
350
|
return parseRouteParams(name).length === 0;
|
|
351
351
|
}
|
|
352
352
|
|
|
353
353
|
/**
|
|
354
354
|
* @param {string} name
|
|
355
355
|
*/
|
|
356
|
-
function toFieldName(name) {
|
|
356
|
+
export function toFieldName(name) {
|
|
357
357
|
if (name === "SPLAT") {
|
|
358
358
|
return "splat";
|
|
359
359
|
} else {
|
|
360
360
|
return name.charAt(0).toLowerCase() + name.slice(1);
|
|
361
361
|
}
|
|
362
362
|
}
|
|
363
|
-
|
|
364
|
-
module.exports = {
|
|
365
|
-
routeParams,
|
|
366
|
-
routeVariantDefinition,
|
|
367
|
-
routeVariant,
|
|
368
|
-
toFieldName,
|
|
369
|
-
paramsRecord,
|
|
370
|
-
toPathPattern,
|
|
371
|
-
toPathPatterns,
|
|
372
|
-
parseRouteParams,
|
|
373
|
-
parseRouteParamsWithStatic,
|
|
374
|
-
toElmPathPattern,
|
|
375
|
-
destructureRoute,
|
|
376
|
-
referenceRouteParams,
|
|
377
|
-
};
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
module.exports = { gather };
|
|
2
|
-
|
|
3
1
|
/** @typedef { { type: 'root'; keyValuePair: [string, string] } } RootTagModifier */
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
4
|
* @param {( SeoTag | RootTagModifier )[]} tags
|
|
7
5
|
*/
|
|
8
|
-
function gather(tags) {
|
|
6
|
+
export function gather(tags) {
|
|
9
7
|
const withoutRootModifiers = tags.flatMap((value) => {
|
|
10
8
|
if (value.type === "root") {
|
|
11
9
|
return [];
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @param {...import('vite').UserConfig} configs
|
|
5
5
|
* @returns {import('vite').UserConfig}
|
|
6
6
|
*/
|
|
7
|
-
function merge_vite_configs(...configs) {
|
|
7
|
+
export function merge_vite_configs(...configs) {
|
|
8
8
|
return deep_merge(
|
|
9
9
|
...configs.map((config) => ({
|
|
10
10
|
...config,
|
|
@@ -75,4 +75,3 @@ function merge_into(a, b) {
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
-
module.exports = { merge_vite_configs };
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "elm-pages",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "3.0.0-beta.19",
|
|
4
5
|
"homepage": "https://elm-pages.com",
|
|
5
6
|
"moduleResolution": "node",
|
|
6
7
|
"description": "Type-safe static sites, written in pure elm with your own custom elm-markup syntax.",
|
|
@@ -10,7 +11,7 @@
|
|
|
10
11
|
"test": "./test.sh",
|
|
11
12
|
"test:snapshot": "(cd examples/escaping && npm install && npm test) && (cd examples/base-path && npm install && npm test)",
|
|
12
13
|
"cypress": "npm start & cypress run",
|
|
13
|
-
"build:generator": "elm-codegen install && (cd codegen && lamdera make Generate.elm --output elm-pages-codegen.js)",
|
|
14
|
+
"build:generator": "elm-codegen install && (cd codegen && lamdera make Generate.elm --output elm-pages-codegen.js && mv elm-pages-codegen.js elm-pages-codegen.cjs)",
|
|
14
15
|
"review": "elm-review"
|
|
15
16
|
},
|
|
16
17
|
"repository": "https://github.com/dillonkearns/elm-pages",
|
|
@@ -26,7 +27,7 @@
|
|
|
26
27
|
"dependencies": {
|
|
27
28
|
"busboy": "^1.0.0",
|
|
28
29
|
"chokidar": "^3.5.3",
|
|
29
|
-
"commander": "^
|
|
30
|
+
"commander": "^10.0.0",
|
|
30
31
|
"connect": "^3.7.0",
|
|
31
32
|
"cookie-signature": "^1.1.0",
|
|
32
33
|
"cross-spawn": "7.0.3",
|
|
@@ -34,8 +35,8 @@
|
|
|
34
35
|
"elm-doc-preview": "^5.0.5",
|
|
35
36
|
"elm-hot": "^1.1.6",
|
|
36
37
|
"esbuild": "^0.16.15",
|
|
37
|
-
"fs-extra": "^
|
|
38
|
-
"globby": "
|
|
38
|
+
"fs-extra": "^11.1.0",
|
|
39
|
+
"globby": "^13.1.3",
|
|
39
40
|
"gray-matter": "^4.0.3",
|
|
40
41
|
"jsesc": "^3.0.2",
|
|
41
42
|
"kleur": "^4.1.5",
|
|
@@ -45,7 +46,7 @@
|
|
|
45
46
|
"serve-static": "^1.15.0",
|
|
46
47
|
"terser": "^5.16.1",
|
|
47
48
|
"vite": "^4.0.4",
|
|
48
|
-
"which": "^
|
|
49
|
+
"which": "^3.0.0"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
52
|
"@types/cross-spawn": "^6.0.2",
|
|
@@ -54,7 +55,7 @@
|
|
|
54
55
|
"@types/micromatch": "^4.0.2",
|
|
55
56
|
"@types/node": "^18.11.9",
|
|
56
57
|
"@types/serve-static": "^1.15.0",
|
|
57
|
-
"cypress": "^12.
|
|
58
|
+
"cypress": "^12.4.0",
|
|
58
59
|
"elm-codegen": "^0.2.0",
|
|
59
60
|
"elm-optimize-level-2": "^0.3.5",
|
|
60
61
|
"elm-review": "^2.8.2",
|
|
@@ -70,7 +71,7 @@
|
|
|
70
71
|
"generator/review/",
|
|
71
72
|
"generator/dead-code-review/",
|
|
72
73
|
"src/",
|
|
73
|
-
"codegen/elm-pages-codegen.
|
|
74
|
+
"codegen/elm-pages-codegen.cjs",
|
|
74
75
|
"generator/template/",
|
|
75
76
|
"generator/static-code/"
|
|
76
77
|
],
|
package/src/BackendTask/File.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
|
|
@@ -281,7 +281,7 @@ import Html.Styled
|
|
|
281
281
|
import Html.Styled.Attributes as StyledAttr
|
|
282
282
|
import Html.Styled.Lazy
|
|
283
283
|
import Pages.FormState as Form exposing (FormState)
|
|
284
|
-
import Pages.Internal.Form exposing (Validation(..))
|
|
284
|
+
import Pages.Internal.Form exposing (Validation(..), unwrapResponse)
|
|
285
285
|
import Pages.Msg
|
|
286
286
|
import Pages.Transition exposing (Transition(..))
|
|
287
287
|
import Path exposing (Path)
|
|
@@ -798,13 +798,13 @@ type alias AppContext app actionData =
|
|
|
798
798
|
| --, sharedData : Shared.Data
|
|
799
799
|
--, routeParams : routeParams
|
|
800
800
|
path : Path
|
|
801
|
+
, action : Maybe actionData
|
|
801
802
|
|
|
802
|
-
--, action : Maybe action
|
|
803
803
|
--, submit :
|
|
804
804
|
-- { fields : List ( String, String ), headers : List ( String, String ) }
|
|
805
805
|
-- -> Pages.Fetcher.Fetcher (Result Http.Error action)
|
|
806
806
|
, transition : Maybe Transition
|
|
807
|
-
, fetchers : Dict String (Pages.Transition.FetcherState actionData)
|
|
807
|
+
, fetchers : Dict String (Pages.Transition.FetcherState (Maybe actionData))
|
|
808
808
|
, pageFormState :
|
|
809
809
|
Dict String { fields : Dict String { value : String, status : FieldStatus }, submitAttempted : Bool }
|
|
810
810
|
}
|
|
@@ -980,11 +980,7 @@ runOneOfServerSideHelp rawFormData firstFoundErrors (ServerForms parsers) =
|
|
|
980
980
|
{-| -}
|
|
981
981
|
renderHtml :
|
|
982
982
|
List (Html.Attribute (Pages.Msg.Msg msg))
|
|
983
|
-
->
|
|
984
|
-
Maybe
|
|
985
|
-
{ fields : List ( String, String )
|
|
986
|
-
, errors : Dict String (List error)
|
|
987
|
-
}
|
|
983
|
+
-> (actionData -> Maybe (Response error))
|
|
988
984
|
-> AppContext app actionData
|
|
989
985
|
-> data
|
|
990
986
|
->
|
|
@@ -997,8 +993,8 @@ renderHtml :
|
|
|
997
993
|
)
|
|
998
994
|
msg
|
|
999
995
|
-> Html (Pages.Msg.Msg msg)
|
|
1000
|
-
renderHtml attrs
|
|
1001
|
-
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)
|
|
1002
998
|
|
|
1003
999
|
|
|
1004
1000
|
{-| -}
|
|
@@ -1181,11 +1177,7 @@ withOnSubmit onSubmit (FinalForm options a b c) =
|
|
|
1181
1177
|
{-| -}
|
|
1182
1178
|
renderStyledHtml :
|
|
1183
1179
|
List (Html.Styled.Attribute (Pages.Msg.Msg msg))
|
|
1184
|
-
->
|
|
1185
|
-
Maybe
|
|
1186
|
-
{ fields : List ( String, String )
|
|
1187
|
-
, errors : Dict String (List error)
|
|
1188
|
-
}
|
|
1180
|
+
-> (actionData -> Maybe (Response error))
|
|
1189
1181
|
-> AppContext app actionData
|
|
1190
1182
|
-> data
|
|
1191
1183
|
->
|
|
@@ -1198,36 +1190,29 @@ renderStyledHtml :
|
|
|
1198
1190
|
)
|
|
1199
1191
|
msg
|
|
1200
1192
|
-> Html.Styled.Html (Pages.Msg.Msg msg)
|
|
1201
|
-
renderStyledHtml attrs
|
|
1202
|
-
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)
|
|
1203
1195
|
|
|
1204
1196
|
|
|
1205
1197
|
{-| -}
|
|
1206
|
-
type Response error
|
|
1207
|
-
|
|
1208
|
-
{ fields : List ( String, String )
|
|
1209
|
-
, errors : Dict String (List error)
|
|
1210
|
-
}
|
|
1198
|
+
type alias Response error =
|
|
1199
|
+
Pages.Internal.Form.Response error
|
|
1211
1200
|
|
|
1212
1201
|
|
|
1213
1202
|
renderHelper :
|
|
1214
1203
|
List (Html.Attribute (Pages.Msg.Msg msg))
|
|
1215
|
-
->
|
|
1216
|
-
Maybe
|
|
1217
|
-
{ fields : List ( String, String )
|
|
1218
|
-
, errors : Dict String (List error)
|
|
1219
|
-
}
|
|
1204
|
+
-> (actionData -> Maybe (Response error))
|
|
1220
1205
|
-> RenderOptions msg
|
|
1221
1206
|
-> AppContext app actionData
|
|
1222
1207
|
-> data
|
|
1223
1208
|
-> FormInternal error (Validation.Validation error parsed named constraints) data (Context error data -> List (Html (Pages.Msg.Msg msg)))
|
|
1224
1209
|
-> Html (Pages.Msg.Msg msg)
|
|
1225
|
-
renderHelper attrs
|
|
1210
|
+
renderHelper attrs accessResponse options formState data form =
|
|
1226
1211
|
-- TODO Get transition context from `app` so you can check if the current form is being submitted
|
|
1227
1212
|
-- TODO either as a transition or a fetcher? Should be easy enough to check for the `id` on either of those?
|
|
1228
1213
|
let
|
|
1229
1214
|
{ formId, hiddenInputs, children, isValid } =
|
|
1230
|
-
helperValues toHiddenInput
|
|
1215
|
+
helperValues toHiddenInput accessResponse options formState data form
|
|
1231
1216
|
|
|
1232
1217
|
toHiddenInput : List (Html.Attribute (Pages.Msg.Msg msg)) -> Html (Pages.Msg.Msg msg)
|
|
1233
1218
|
toHiddenInput hiddenAttrs =
|
|
@@ -1254,22 +1239,18 @@ renderHelper attrs maybe options formState data form =
|
|
|
1254
1239
|
|
|
1255
1240
|
renderStyledHelper :
|
|
1256
1241
|
List (Html.Styled.Attribute (Pages.Msg.Msg msg))
|
|
1257
|
-
->
|
|
1258
|
-
Maybe
|
|
1259
|
-
{ fields : List ( String, String )
|
|
1260
|
-
, errors : Dict String (List error)
|
|
1261
|
-
}
|
|
1242
|
+
-> (actionData -> Maybe (Response error))
|
|
1262
1243
|
-> RenderOptions msg
|
|
1263
1244
|
-> AppContext app actionData
|
|
1264
1245
|
-> data
|
|
1265
1246
|
-> FormInternal error (Validation.Validation error parsed named constraints) data (Context error data -> List (Html.Styled.Html (Pages.Msg.Msg msg)))
|
|
1266
1247
|
-> Html.Styled.Html (Pages.Msg.Msg msg)
|
|
1267
|
-
renderStyledHelper attrs
|
|
1248
|
+
renderStyledHelper attrs accessResponse options formState data form =
|
|
1268
1249
|
-- TODO Get transition context from `app` so you can check if the current form is being submitted
|
|
1269
1250
|
-- TODO either as a transition or a fetcher? Should be easy enough to check for the `id` on either of those?
|
|
1270
1251
|
let
|
|
1271
1252
|
{ formId, hiddenInputs, children, isValid } =
|
|
1272
|
-
helperValues toHiddenInput
|
|
1253
|
+
helperValues toHiddenInput accessResponse options formState data form
|
|
1273
1254
|
|
|
1274
1255
|
toHiddenInput : List (Html.Attribute (Pages.Msg.Msg msg)) -> Html.Styled.Html (Pages.Msg.Msg msg)
|
|
1275
1256
|
toHiddenInput hiddenAttrs =
|
|
@@ -1296,18 +1277,14 @@ renderStyledHelper attrs maybe options formState data form =
|
|
|
1296
1277
|
|
|
1297
1278
|
helperValues :
|
|
1298
1279
|
(List (Html.Attribute (Pages.Msg.Msg msg)) -> view)
|
|
1299
|
-
->
|
|
1300
|
-
Maybe
|
|
1301
|
-
{ fields : List ( String, String )
|
|
1302
|
-
, errors : Dict String (List error)
|
|
1303
|
-
}
|
|
1280
|
+
-> (actionData -> Maybe (Response error))
|
|
1304
1281
|
-> RenderOptions msg
|
|
1305
1282
|
-> AppContext app actionData
|
|
1306
1283
|
-> data
|
|
1307
1284
|
---> Form error parsed data view
|
|
1308
1285
|
-> FormInternal error (Validation.Validation error parsed named constraints) data (Context error data -> List view)
|
|
1309
1286
|
-> { formId : String, hiddenInputs : List view, children : List view, isValid : Bool }
|
|
1310
|
-
helperValues toHiddenInput
|
|
1287
|
+
helperValues toHiddenInput accessResponse options formState data (FormInternal fieldDefinitions parser toInitialValues) =
|
|
1311
1288
|
let
|
|
1312
1289
|
formId : String
|
|
1313
1290
|
formId =
|
|
@@ -1324,7 +1301,8 @@ helperValues toHiddenInput maybe options formState data (FormInternal fieldDefin
|
|
|
1324
1301
|
formState.pageFormState
|
|
1325
1302
|
|> Dict.get formId
|
|
1326
1303
|
|> Maybe.withDefault
|
|
1327
|
-
(
|
|
1304
|
+
(formState.action
|
|
1305
|
+
|> Maybe.andThen (accessResponse >> Maybe.map unwrapResponse)
|
|
1328
1306
|
|> Maybe.map
|
|
1329
1307
|
(\{ fields } ->
|
|
1330
1308
|
{ fields =
|
|
@@ -1364,8 +1342,8 @@ helperValues toHiddenInput maybe options formState data (FormInternal fieldDefin
|
|
|
1364
1342
|
|> Tuple.mapSecond
|
|
1365
1343
|
(\errors1 ->
|
|
1366
1344
|
mergeErrors errors1
|
|
1367
|
-
(
|
|
1368
|
-
|> Maybe.map .errors
|
|
1345
|
+
(formState.action
|
|
1346
|
+
|> Maybe.andThen (accessResponse >> Maybe.map (unwrapResponse >> .errors))
|
|
1369
1347
|
|> Maybe.withDefault Dict.empty
|
|
1370
1348
|
)
|
|
1371
1349
|
)
|
|
@@ -1376,7 +1354,8 @@ helperValues toHiddenInput maybe options formState data (FormInternal fieldDefin
|
|
|
1376
1354
|
formState.pageFormState
|
|
1377
1355
|
|> Dict.get formId
|
|
1378
1356
|
|> Maybe.withDefault
|
|
1379
|
-
(
|
|
1357
|
+
(formState.action
|
|
1358
|
+
|> Maybe.andThen (accessResponse >> Maybe.map unwrapResponse)
|
|
1380
1359
|
|> Maybe.map
|
|
1381
1360
|
(\{ fields } ->
|
|
1382
1361
|
{ fields =
|
package/src/Pages/Generate.elm
CHANGED
|
@@ -3,6 +3,7 @@ module Pages.Generate exposing
|
|
|
3
3
|
, Type(..)
|
|
4
4
|
, serverRender
|
|
5
5
|
, preRender, single
|
|
6
|
+
, addDeclarations
|
|
6
7
|
)
|
|
7
8
|
|
|
8
9
|
{-| This module provides some functions for scaffolding code for a new Route Module. It uses [`elm-codegen`'s API](https://package.elm-lang.org/packages/mdgriffith/elm-codegen/latest/) for generating code.
|
|
@@ -27,6 +28,11 @@ Learn more about [the `elm-pages run` CLI command in its docs page](https://elm-
|
|
|
27
28
|
|
|
28
29
|
@docs preRender, single
|
|
29
30
|
|
|
31
|
+
|
|
32
|
+
## Including Additional elm-codegen Declarations
|
|
33
|
+
|
|
34
|
+
@docs addDeclarations
|
|
35
|
+
|
|
30
36
|
-}
|
|
31
37
|
|
|
32
38
|
import Elm
|
|
@@ -54,12 +60,14 @@ typeToDeclaration name type_ =
|
|
|
54
60
|
{-| -}
|
|
55
61
|
type Builder
|
|
56
62
|
= ServerRender
|
|
63
|
+
(List Elm.Declaration)
|
|
57
64
|
{ data : ( Type, Elm.Expression -> Elm.Expression )
|
|
58
65
|
, action : ( Type, Elm.Expression -> Elm.Expression )
|
|
59
66
|
, head : Elm.Expression -> Elm.Expression
|
|
60
67
|
, moduleName : List String
|
|
61
68
|
}
|
|
62
69
|
| PreRender
|
|
70
|
+
(List Elm.Declaration)
|
|
63
71
|
{ data : ( Type, Elm.Expression -> Elm.Expression )
|
|
64
72
|
, pages : Maybe Elm.Expression
|
|
65
73
|
, head : Elm.Expression -> Elm.Expression
|
|
@@ -76,7 +84,7 @@ serverRender :
|
|
|
76
84
|
}
|
|
77
85
|
-> Builder
|
|
78
86
|
serverRender =
|
|
79
|
-
ServerRender
|
|
87
|
+
ServerRender []
|
|
80
88
|
|
|
81
89
|
|
|
82
90
|
{-| -}
|
|
@@ -96,7 +104,7 @@ preRender input =
|
|
|
96
104
|
-- |> Maybe.map RoutePattern.hasRouteParams
|
|
97
105
|
-- |> Maybe.withDefault False
|
|
98
106
|
--in
|
|
99
|
-
PreRender
|
|
107
|
+
PreRender []
|
|
100
108
|
{ data = input.data
|
|
101
109
|
, pages =
|
|
102
110
|
input.pages
|
|
@@ -118,7 +126,7 @@ single :
|
|
|
118
126
|
}
|
|
119
127
|
-> Builder
|
|
120
128
|
single input =
|
|
121
|
-
PreRender
|
|
129
|
+
PreRender []
|
|
122
130
|
{ data = ( Tuple.first input.data, \_ -> Tuple.second input.data )
|
|
123
131
|
, pages = Nothing
|
|
124
132
|
, head = input.head
|
|
@@ -134,7 +142,7 @@ buildNoState :
|
|
|
134
142
|
-> Elm.File
|
|
135
143
|
buildNoState definitions builder_ =
|
|
136
144
|
case builder_ of
|
|
137
|
-
ServerRender builder ->
|
|
145
|
+
ServerRender declarations builder ->
|
|
138
146
|
userFunction builder.moduleName
|
|
139
147
|
{ view =
|
|
140
148
|
\maybeUrl sharedModel _ app ->
|
|
@@ -153,9 +161,10 @@ buildNoState definitions builder_ =
|
|
|
153
161
|
, data = builder.data |> Tuple.first
|
|
154
162
|
, actionData = builder.action |> Tuple.first
|
|
155
163
|
}
|
|
164
|
+
, declarations = declarations
|
|
156
165
|
}
|
|
157
166
|
|
|
158
|
-
PreRender builder ->
|
|
167
|
+
PreRender declarations builder ->
|
|
159
168
|
userFunction builder.moduleName
|
|
160
169
|
{ view =
|
|
161
170
|
\maybeUrl sharedModel _ app ->
|
|
@@ -177,9 +186,21 @@ buildNoState definitions builder_ =
|
|
|
177
186
|
(Elm.Annotation.list (Elm.Annotation.named [] "RouteParams"))
|
|
178
187
|
|> Alias
|
|
179
188
|
}
|
|
189
|
+
, declarations = declarations
|
|
180
190
|
}
|
|
181
191
|
|
|
182
192
|
|
|
193
|
+
{-| -}
|
|
194
|
+
addDeclarations : List Elm.Declaration -> Builder -> Builder
|
|
195
|
+
addDeclarations declarations builder =
|
|
196
|
+
case builder of
|
|
197
|
+
ServerRender existingDeclarations record ->
|
|
198
|
+
ServerRender (existingDeclarations ++ declarations) record
|
|
199
|
+
|
|
200
|
+
PreRender existingDeclarations record ->
|
|
201
|
+
PreRender (existingDeclarations ++ declarations) record
|
|
202
|
+
|
|
203
|
+
|
|
183
204
|
{-| -}
|
|
184
205
|
buildWithLocalState :
|
|
185
206
|
{ view :
|
|
@@ -213,7 +234,7 @@ buildWithLocalState :
|
|
|
213
234
|
-> Elm.File
|
|
214
235
|
buildWithLocalState definitions builder_ =
|
|
215
236
|
case builder_ of
|
|
216
|
-
ServerRender builder ->
|
|
237
|
+
ServerRender declarations builder ->
|
|
217
238
|
userFunction builder.moduleName
|
|
218
239
|
{ view =
|
|
219
240
|
\maybeUrl sharedModel model app ->
|
|
@@ -261,9 +282,10 @@ buildWithLocalState definitions builder_ =
|
|
|
261
282
|
, data = builder.data |> Tuple.first
|
|
262
283
|
, actionData = builder.action |> Tuple.first
|
|
263
284
|
}
|
|
285
|
+
, declarations = declarations
|
|
264
286
|
}
|
|
265
287
|
|
|
266
|
-
PreRender builder ->
|
|
288
|
+
PreRender declarations builder ->
|
|
267
289
|
userFunction builder.moduleName
|
|
268
290
|
{ view =
|
|
269
291
|
\maybeUrl sharedModel model app ->
|
|
@@ -314,6 +336,7 @@ buildWithLocalState definitions builder_ =
|
|
|
314
336
|
(Elm.Annotation.list (Elm.Annotation.named [] "RouteParams"))
|
|
315
337
|
|> Alias
|
|
316
338
|
}
|
|
339
|
+
, declarations = declarations
|
|
317
340
|
}
|
|
318
341
|
|
|
319
342
|
|
|
@@ -350,7 +373,7 @@ buildWithSharedState :
|
|
|
350
373
|
-> Elm.File
|
|
351
374
|
buildWithSharedState definitions builder_ =
|
|
352
375
|
case builder_ of
|
|
353
|
-
ServerRender builder ->
|
|
376
|
+
ServerRender declarations builder ->
|
|
354
377
|
userFunction builder.moduleName
|
|
355
378
|
{ view =
|
|
356
379
|
\maybeUrl sharedModel model app ->
|
|
@@ -398,9 +421,10 @@ buildWithSharedState definitions builder_ =
|
|
|
398
421
|
, data = builder.data |> Tuple.first
|
|
399
422
|
, actionData = builder.action |> Tuple.first
|
|
400
423
|
}
|
|
424
|
+
, declarations = declarations
|
|
401
425
|
}
|
|
402
426
|
|
|
403
|
-
PreRender builder ->
|
|
427
|
+
PreRender declarations builder ->
|
|
404
428
|
userFunction builder.moduleName
|
|
405
429
|
{ view =
|
|
406
430
|
\maybeUrl sharedModel model app ->
|
|
@@ -451,6 +475,7 @@ buildWithSharedState definitions builder_ =
|
|
|
451
475
|
(Elm.Annotation.list (Elm.Annotation.named [] "RouteParams"))
|
|
452
476
|
|> Alias
|
|
453
477
|
}
|
|
478
|
+
, declarations = declarations
|
|
454
479
|
}
|
|
455
480
|
|
|
456
481
|
|
|
@@ -480,6 +505,7 @@ userFunction :
|
|
|
480
505
|
, action : ActionOrPages
|
|
481
506
|
, head : Elm.Expression -> Elm.Expression
|
|
482
507
|
, types : { model : Type, msg : Type, data : Type, actionData : Type }
|
|
508
|
+
, declarations : List Elm.Declaration
|
|
483
509
|
}
|
|
484
510
|
-> Elm.File
|
|
485
511
|
userFunction moduleName definitions =
|
|
@@ -694,8 +720,8 @@ userFunction moduleName definitions =
|
|
|
694
720
|
)
|
|
695
721
|
in
|
|
696
722
|
Elm.file ("Route" :: moduleName)
|
|
697
|
-
([ definitions.types.model |> typeToDeclaration "Model"
|
|
698
|
-
, definitions.types.msg |> typeToDeclaration "Msg"
|
|
723
|
+
([ definitions.types.model |> typeToDeclaration "Model" |> Elm.expose
|
|
724
|
+
, definitions.types.msg |> typeToDeclaration "Msg" |> Elm.expose
|
|
699
725
|
, Elm.alias "RouteParams"
|
|
700
726
|
(Elm.Annotation.record
|
|
701
727
|
(RoutePattern.fromModuleName moduleName
|
|
@@ -704,6 +730,7 @@ userFunction moduleName definitions =
|
|
|
704
730
|
|> Maybe.withDefault []
|
|
705
731
|
)
|
|
706
732
|
)
|
|
733
|
+
|> Elm.expose
|
|
707
734
|
, Elm.declaration "route"
|
|
708
735
|
((case definitions.action of
|
|
709
736
|
Action _ ->
|
|
@@ -782,6 +809,7 @@ userFunction moduleName definitions =
|
|
|
782
809
|
)
|
|
783
810
|
)
|
|
784
811
|
)
|
|
812
|
+
|> Elm.expose
|
|
785
813
|
]
|
|
786
814
|
++ (case localDefinitions of
|
|
787
815
|
Just local ->
|
|
@@ -793,8 +821,8 @@ userFunction moduleName definitions =
|
|
|
793
821
|
Nothing ->
|
|
794
822
|
[]
|
|
795
823
|
)
|
|
796
|
-
++ [ definitions.types.data |> typeToDeclaration "Data"
|
|
797
|
-
, definitions.types.actionData |> typeToDeclaration "ActionData"
|
|
824
|
+
++ [ definitions.types.data |> typeToDeclaration "Data" |> Elm.expose
|
|
825
|
+
, definitions.types.actionData |> typeToDeclaration "ActionData" |> Elm.expose
|
|
798
826
|
, dataFn.declaration
|
|
799
827
|
, headFn.declaration
|
|
800
828
|
, viewFn.declaration
|
|
@@ -803,6 +831,7 @@ userFunction moduleName definitions =
|
|
|
803
831
|
]
|
|
804
832
|
|> List.filterMap identity
|
|
805
833
|
)
|
|
834
|
+
++ definitions.declarations
|
|
806
835
|
)
|
|
807
836
|
|
|
808
837
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
module Pages.Internal.Form exposing (Validation(..), ViewField)
|
|
1
|
+
module Pages.Internal.Form exposing (Response(..), Validation(..), ViewField, unwrapResponse)
|
|
2
2
|
|
|
3
3
|
import Dict exposing (Dict)
|
|
4
4
|
import Form.FieldStatus exposing (FieldStatus)
|
|
@@ -15,3 +15,16 @@ type alias ViewField kind =
|
|
|
15
15
|
, status : FieldStatus
|
|
16
16
|
, kind : ( kind, List ( String, Encode.Value ) )
|
|
17
17
|
}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
{-| -}
|
|
21
|
+
type Response error
|
|
22
|
+
= Response
|
|
23
|
+
{ fields : List ( String, String )
|
|
24
|
+
, errors : Dict String (List error)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
unwrapResponse : Response error -> { fields : List ( String, String ), errors : Dict String (List error) }
|
|
29
|
+
unwrapResponse (Response response) =
|
|
30
|
+
response
|