elm-pages 3.0.0-beta.3 → 3.0.0-beta.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/README.md +10 -1
  2. package/codegen/{elm-pages-codegen.js → elm-pages-codegen.cjs} +2864 -2589
  3. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmi +0 -0
  4. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmo +0 -0
  5. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateDataTest.elmo +0 -0
  6. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
  7. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/i.dat +0 -0
  8. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
  9. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm.json +1 -1
  10. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +1447 -342
  11. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Runner.elm.js +16458 -13724
  12. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
  13. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_supervisor.js +4 -4
  14. package/generator/dead-code-review/elm.json +9 -7
  15. package/generator/dead-code-review/src/Pages/Review/DeadCodeEliminateData.elm +59 -10
  16. package/generator/dead-code-review/tests/Pages/Review/DeadCodeEliminateDataTest.elm +52 -36
  17. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Internal-RoutePattern.elmi +0 -0
  18. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Internal-RoutePattern.elmo +0 -0
  19. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolations.elmi +0 -0
  20. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolations.elmo +0 -0
  21. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
  22. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/i.dat +0 -0
  23. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
  24. package/generator/review/elm-stuff/tests-0.19.1/elm.json +1 -1
  25. package/generator/review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +1447 -342
  26. package/generator/review/elm-stuff/tests-0.19.1/js/Runner.elm.js +24542 -21748
  27. package/generator/review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
  28. package/generator/review/elm-stuff/tests-0.19.1/js/node_supervisor.js +4 -4
  29. package/generator/review/elm.json +10 -10
  30. package/generator/src/RouteBuilder.elm +113 -107
  31. package/generator/src/SharedTemplate.elm +3 -2
  32. package/generator/src/SiteConfig.elm +3 -2
  33. package/generator/src/basepath-middleware.js +3 -3
  34. package/generator/src/build.js +125 -88
  35. package/generator/src/cli.js +273 -88
  36. package/generator/src/codegen.js +29 -27
  37. package/generator/src/compatibility-key.js +3 -0
  38. package/generator/src/compile-elm.js +43 -26
  39. package/generator/src/config.js +39 -0
  40. package/generator/src/copy-dir.js +2 -2
  41. package/generator/src/dev-server.js +150 -133
  42. package/generator/src/dir-helpers.js +9 -26
  43. package/generator/src/elm-codegen.js +5 -4
  44. package/generator/src/elm-file-constants.js +2 -3
  45. package/generator/src/error-formatter.js +12 -11
  46. package/generator/src/file-helpers.js +3 -4
  47. package/generator/src/generate-template-module-connector.js +23 -22
  48. package/generator/src/init.js +9 -8
  49. package/generator/src/pre-render-html.js +39 -28
  50. package/generator/src/render-test.js +109 -0
  51. package/generator/src/render-worker.js +25 -28
  52. package/generator/src/render.js +320 -142
  53. package/generator/src/request-cache.js +252 -163
  54. package/generator/src/resolve-elm-module.js +63 -0
  55. package/generator/src/rewrite-client-elm-json.js +6 -5
  56. package/generator/src/rewrite-elm-json-help.js +56 -0
  57. package/generator/src/rewrite-elm-json.js +17 -7
  58. package/generator/src/route-codegen-helpers.js +16 -31
  59. package/generator/src/seo-renderer.js +12 -7
  60. package/generator/src/vite-utils.js +77 -0
  61. package/generator/static-code/hmr.js +79 -13
  62. package/generator/template/app/Api.elm +6 -5
  63. package/generator/template/app/Effect.elm +123 -0
  64. package/generator/template/app/ErrorPage.elm +37 -6
  65. package/generator/template/app/Route/Index.elm +17 -10
  66. package/generator/template/app/Shared.elm +24 -47
  67. package/generator/template/app/Site.elm +19 -6
  68. package/generator/template/app/View.elm +1 -8
  69. package/generator/template/elm-tooling.json +0 -3
  70. package/generator/template/elm.json +32 -24
  71. package/generator/template/package.json +10 -4
  72. package/package.json +29 -27
  73. package/src/ApiRoute.elm +199 -61
  74. package/src/BackendTask/Custom.elm +325 -0
  75. package/src/BackendTask/Env.elm +90 -0
  76. package/src/{DataSource → BackendTask}/File.elm +128 -43
  77. package/src/{DataSource → BackendTask}/Glob.elm +136 -125
  78. package/src/BackendTask/Http.elm +673 -0
  79. package/src/{DataSource → BackendTask}/Internal/Glob.elm +1 -1
  80. package/src/BackendTask/Internal/Request.elm +28 -0
  81. package/src/BackendTask/Random.elm +79 -0
  82. package/src/BackendTask/Time.elm +47 -0
  83. package/src/BackendTask.elm +537 -0
  84. package/src/FatalError.elm +89 -0
  85. package/src/Form/Field.elm +21 -9
  86. package/src/Form/FieldView.elm +94 -14
  87. package/src/Form.elm +275 -400
  88. package/src/Head.elm +237 -7
  89. package/src/HtmlPrinter.elm +7 -3
  90. package/src/Internal/ApiRoute.elm +7 -5
  91. package/src/PageServerResponse.elm +6 -1
  92. package/src/Pages/FormState.elm +6 -5
  93. package/src/Pages/GeneratorProgramConfig.elm +15 -0
  94. package/src/Pages/Internal/FatalError.elm +5 -0
  95. package/src/Pages/Internal/Form.elm +21 -1
  96. package/src/Pages/{Msg.elm → Internal/Msg.elm} +26 -16
  97. package/src/Pages/Internal/Platform/Cli.elm +598 -763
  98. package/src/Pages/Internal/Platform/CompatibilityKey.elm +6 -0
  99. package/src/Pages/Internal/Platform/Effect.elm +1 -2
  100. package/src/Pages/Internal/Platform/GeneratorApplication.elm +373 -0
  101. package/src/Pages/Internal/Platform/StaticResponses.elm +73 -270
  102. package/src/Pages/Internal/Platform/ToJsPayload.elm +4 -7
  103. package/src/Pages/Internal/Platform.elm +216 -102
  104. package/src/Pages/Internal/Script.elm +17 -0
  105. package/src/Pages/Internal/StaticHttpBody.elm +35 -1
  106. package/src/Pages/Manifest.elm +29 -4
  107. package/src/Pages/PageUrl.elm +23 -9
  108. package/src/Pages/ProgramConfig.elm +14 -10
  109. package/src/Pages/Script.elm +109 -0
  110. package/src/Pages/SiteConfig.elm +3 -2
  111. package/src/Pages/StaticHttp/Request.elm +2 -2
  112. package/src/Pages/StaticHttpRequest.elm +23 -98
  113. package/src/PagesMsg.elm +92 -0
  114. package/src/Path.elm +16 -19
  115. package/src/QueryParams.elm +21 -172
  116. package/src/RequestsAndPending.elm +8 -19
  117. package/src/Result/Extra.elm +26 -0
  118. package/src/Scaffold/Form.elm +560 -0
  119. package/src/Scaffold/Route.elm +1388 -0
  120. package/src/Server/Request.elm +43 -37
  121. package/src/Server/Session.elm +62 -42
  122. package/src/Server/SetCookie.elm +12 -4
  123. package/src/Test/Html/Internal/ElmHtml/ToString.elm +8 -9
  124. package/src/DataSource/Env.elm +0 -38
  125. package/src/DataSource/Http.elm +0 -446
  126. package/src/DataSource/Internal/Request.elm +0 -20
  127. package/src/DataSource/Port.elm +0 -90
  128. package/src/DataSource.elm +0 -538
  129. package/src/Pages/Generate.elm +0 -800
@@ -0,0 +1,560 @@
1
+ module Scaffold.Form exposing
2
+ ( Kind(..), provide, restArgsParser
3
+ , Context
4
+ , fieldEncoder, recordEncoder
5
+ )
6
+
7
+ {-|
8
+
9
+ @docs Kind, provide, restArgsParser
10
+
11
+ @docs Context
12
+
13
+ @docs fieldEncoder, recordEncoder
14
+
15
+ -}
16
+
17
+ import Cli.Option
18
+ import Elm
19
+ import Elm.Annotation as Type
20
+ import Elm.Declare
21
+ import Elm.Op
22
+ import List.Extra
23
+ import Result.Extra
24
+
25
+
26
+ {-| -}
27
+ type Kind
28
+ = FieldInt
29
+ | FieldText
30
+ | FieldTextarea
31
+ | FieldFloat
32
+ | FieldTime
33
+ | FieldDate
34
+ | FieldCheckbox
35
+
36
+
37
+ {-| -}
38
+ type alias Context =
39
+ { errors : Elm.Expression
40
+ , isTransitioning : Elm.Expression
41
+ , submitAttempted : Elm.Expression
42
+ , data : Elm.Expression
43
+ , expression : Elm.Expression
44
+ }
45
+
46
+
47
+ {-| -}
48
+ formWithFields :
49
+ Bool
50
+ -> List ( String, Kind )
51
+ ->
52
+ ({ formState : Context
53
+ , params : List { name : String, kind : Kind, param : Elm.Expression }
54
+ }
55
+ -> Elm.Expression
56
+ )
57
+ -> { declaration : Elm.Declaration, call : List Elm.Expression -> Elm.Expression, callFrom : List String -> List Elm.Expression -> Elm.Expression }
58
+ formWithFields elmCssView fields viewFn =
59
+ Elm.Declare.function "form"
60
+ []
61
+ (\_ ->
62
+ fields
63
+ |> List.foldl
64
+ (\( fieldName, kind ) chain ->
65
+ chain
66
+ |> Elm.Op.pipe
67
+ (formField fieldName
68
+ (case kind of
69
+ FieldText ->
70
+ formFieldText
71
+ |> Elm.Op.pipe (formFieldRequired (Elm.string "Required"))
72
+
73
+ FieldInt ->
74
+ formFieldInt { invalid = \_ -> Elm.string "" }
75
+ |> Elm.Op.pipe (formFieldRequired (Elm.string "Required"))
76
+
77
+ FieldTextarea ->
78
+ formFieldText
79
+ |> Elm.Op.pipe (formFieldRequired (Elm.string "Required"))
80
+ |> Elm.Op.pipe
81
+ (formFieldTextarea
82
+ { rows = Elm.nothing
83
+ , cols = Elm.nothing
84
+ }
85
+ )
86
+
87
+ FieldFloat ->
88
+ formFieldFloat { invalid = \_ -> Elm.string "" }
89
+ |> Elm.Op.pipe (formFieldRequired (Elm.string "Required"))
90
+
91
+ FieldTime ->
92
+ formFieldTime { invalid = \_ -> Elm.string "" }
93
+ |> Elm.Op.pipe (formFieldRequired (Elm.string "Required"))
94
+
95
+ FieldDate ->
96
+ formFieldDate { invalid = \_ -> Elm.string "" }
97
+ |> Elm.Op.pipe (formFieldRequired (Elm.string "Required"))
98
+
99
+ FieldCheckbox ->
100
+ formFieldCheckbox
101
+ )
102
+ )
103
+ )
104
+ (Elm.function (List.map fieldToParam fields)
105
+ (\params ->
106
+ Elm.record
107
+ [ ( "combine"
108
+ , params
109
+ |> List.foldl
110
+ (\fieldExpression chain ->
111
+ chain
112
+ |> Elm.Op.pipe (validationAndMap fieldExpression)
113
+ )
114
+ (Elm.val "ParsedForm"
115
+ |> Elm.Op.pipe validationSucceed
116
+ )
117
+ )
118
+ , ( "view"
119
+ , Elm.fn ( "formState", Nothing )
120
+ (\formState ->
121
+ let
122
+ mappedParams : List { name : String, kind : Kind, param : Elm.Expression }
123
+ mappedParams =
124
+ params
125
+ |> List.Extra.zip fields
126
+ |> List.map
127
+ (\( ( name, kind ), param ) ->
128
+ { name = name
129
+ , kind = kind
130
+ , param = param
131
+ }
132
+ )
133
+ in
134
+ viewFn
135
+ { formState =
136
+ { errors = formState |> Elm.get "errors"
137
+ , isTransitioning = formState |> Elm.get "isTransitioning"
138
+ , submitAttempted = formState |> Elm.get "submitAttempted"
139
+ , data = formState |> Elm.get "data"
140
+ , expression = formState
141
+ }
142
+ , params = mappedParams
143
+ }
144
+ )
145
+ )
146
+ ]
147
+ )
148
+ |> Elm.Op.pipe formInit
149
+ )
150
+ |> Elm.withType
151
+ (Type.namedWith [ "Form" ]
152
+ (if elmCssView then
153
+ "StyledHtmlForm"
154
+
155
+ else
156
+ "HtmlForm"
157
+ )
158
+ [ Type.string
159
+ , Type.named [] "ParsedForm"
160
+ , Type.var "input"
161
+ , Type.named [] "Msg"
162
+ ]
163
+ )
164
+ )
165
+
166
+
167
+ fieldToParam : ( String, Kind ) -> ( String, Maybe Type.Annotation )
168
+ fieldToParam ( name, _ ) =
169
+ ( name, Nothing )
170
+
171
+
172
+ {-| -}
173
+ restArgsParser : Cli.Option.Option (List String) (List ( String, Kind )) Cli.Option.RestArgsOption
174
+ restArgsParser =
175
+ Cli.Option.restArgs "formFields"
176
+ |> Cli.Option.validateMap
177
+ (\items ->
178
+ items
179
+ |> List.map parseField
180
+ |> Result.Extra.combine
181
+ )
182
+
183
+
184
+ parseField : String -> Result String ( String, Kind )
185
+ parseField rawField =
186
+ case String.split ":" rawField of
187
+ [ fieldName ] ->
188
+ Ok ( fieldName, FieldText )
189
+
190
+ [ fieldName, fieldKind ] ->
191
+ (case fieldKind of
192
+ "text" ->
193
+ Ok FieldText
194
+
195
+ "textarea" ->
196
+ Ok FieldTextarea
197
+
198
+ "checkbox" ->
199
+ Ok FieldCheckbox
200
+
201
+ "time" ->
202
+ Ok FieldTime
203
+
204
+ "date" ->
205
+ Ok FieldDate
206
+
207
+ invalidFieldKind ->
208
+ Err ("I wasn't able to interpret the type of the field `" ++ fieldName ++ "` because it has an unexpected field type `" ++ invalidFieldKind ++ "`.")
209
+ )
210
+ |> Result.map (Tuple.pair fieldName)
211
+
212
+ _ ->
213
+ Err ("Unexpected form field format: `" ++ rawField ++ "`. Must be in format `first` or `checkin:date`.")
214
+
215
+
216
+ {-| -}
217
+ provide :
218
+ { fields : List ( String, Kind )
219
+ , elmCssView : Bool
220
+ , view :
221
+ { formState : Context
222
+ , params : List { name : String, kind : Kind, param : Elm.Expression }
223
+ }
224
+ -> Elm.Expression
225
+ }
226
+ ->
227
+ Maybe
228
+ { formHandlers : Elm.Expression
229
+ , form : Elm.Expression
230
+ , declarations : List Elm.Declaration
231
+ }
232
+ provide { fields, view, elmCssView } =
233
+ if List.isEmpty fields then
234
+ Nothing
235
+
236
+ else
237
+ let
238
+ form : { declaration : Elm.Declaration, call : List Elm.Expression -> Elm.Expression, callFrom : List String -> List Elm.Expression -> Elm.Expression }
239
+ form =
240
+ formWithFields elmCssView fields view
241
+
242
+ formHandlersDeclaration :
243
+ { declaration : Elm.Declaration
244
+ , call : List Elm.Expression -> Elm.Expression
245
+ , callFrom : List String -> List Elm.Expression -> Elm.Expression
246
+ }
247
+ formHandlersDeclaration =
248
+ -- TODO customizable formHandlers name?
249
+ Elm.Declare.function "formHandlers"
250
+ []
251
+ (\_ ->
252
+ initCombined (Elm.val "Action") (form.call [])
253
+ |> Elm.withType
254
+ (Type.namedWith [ "Form" ]
255
+ "ServerForms"
256
+ [ Type.string
257
+ , Type.named [] "Action"
258
+ ]
259
+ )
260
+ )
261
+ in
262
+ Just
263
+ { formHandlers = formHandlersDeclaration.call []
264
+ , form = form.call []
265
+ , declarations =
266
+ [ formWithFields elmCssView fields view |> .declaration
267
+ , Elm.customType "Action"
268
+ [ Elm.variantWith "Action" [ Type.named [] "ParsedForm" ]
269
+ ]
270
+ , formHandlersDeclaration.declaration
271
+
272
+ -- TODO customize ParsedForm name?
273
+ , Elm.alias "ParsedForm"
274
+ (fields
275
+ |> List.map
276
+ (\( fieldName, kind ) ->
277
+ ( fieldName
278
+ , case kind of
279
+ FieldText ->
280
+ Type.string
281
+
282
+ FieldInt ->
283
+ Type.int
284
+
285
+ FieldTextarea ->
286
+ Type.string
287
+
288
+ FieldFloat ->
289
+ Type.float
290
+
291
+ FieldTime ->
292
+ Type.named [ "Form", "Field" ] "TimeOfDay"
293
+
294
+ FieldDate ->
295
+ Type.named [ "Date" ] "Date"
296
+
297
+ FieldCheckbox ->
298
+ Type.bool
299
+ )
300
+ )
301
+ |> Type.record
302
+ )
303
+ ]
304
+ }
305
+
306
+
307
+ validationAndMap : Elm.Expression -> Elm.Expression
308
+ validationAndMap andMapArg =
309
+ Elm.apply
310
+ (Elm.value
311
+ { importFrom = [ "Form", "Validation" ]
312
+ , name = "andMap"
313
+ , annotation = Nothing
314
+ }
315
+ )
316
+ [ andMapArg ]
317
+
318
+
319
+ validationSucceed : Elm.Expression
320
+ validationSucceed =
321
+ Elm.value
322
+ { importFrom = [ "Form", "Validation" ]
323
+ , name = "succeed"
324
+ , annotation = Nothing
325
+ }
326
+
327
+
328
+ formFieldText : Elm.Expression
329
+ formFieldText =
330
+ Elm.value
331
+ { importFrom = [ "Form", "Field" ]
332
+ , name = "text"
333
+ , annotation = Nothing
334
+ }
335
+
336
+
337
+ formFieldRequired : Elm.Expression -> Elm.Expression
338
+ formFieldRequired requiredArg =
339
+ Elm.apply
340
+ (Elm.value
341
+ { importFrom = [ "Form", "Field" ]
342
+ , name = "required"
343
+ , annotation = Nothing
344
+ }
345
+ )
346
+ [ requiredArg ]
347
+
348
+
349
+ formFieldInt : { invalid : Elm.Expression -> Elm.Expression } -> Elm.Expression
350
+ formFieldInt intArg =
351
+ Elm.apply
352
+ (Elm.value
353
+ { importFrom = [ "Form", "Field" ]
354
+ , name = "int"
355
+ , annotation =
356
+ Nothing
357
+ }
358
+ )
359
+ [ Elm.record
360
+ [ Tuple.pair
361
+ "invalid"
362
+ (Elm.functionReduced "intUnpack" intArg.invalid)
363
+ ]
364
+ ]
365
+
366
+
367
+ formFieldTextarea :
368
+ { rows : Elm.Expression, cols : Elm.Expression }
369
+ -> Elm.Expression
370
+ formFieldTextarea textareaArg =
371
+ Elm.apply
372
+ (Elm.value
373
+ { importFrom = [ "Form", "Field" ]
374
+ , name = "textarea"
375
+ , annotation = Nothing
376
+ }
377
+ )
378
+ [ Elm.record
379
+ [ Tuple.pair "rows" textareaArg.rows
380
+ , Tuple.pair "cols" textareaArg.cols
381
+ ]
382
+ ]
383
+
384
+
385
+ formFieldTime : { invalid : Elm.Expression -> Elm.Expression } -> Elm.Expression
386
+ formFieldTime timeArg =
387
+ Elm.apply
388
+ (Elm.value
389
+ { importFrom = [ "Form", "Field" ]
390
+ , name = "time"
391
+ , annotation = Nothing
392
+ }
393
+ )
394
+ [ Elm.record
395
+ [ Tuple.pair
396
+ "invalid"
397
+ (Elm.functionReduced "timeUnpack" timeArg.invalid)
398
+ ]
399
+ ]
400
+
401
+
402
+ formFieldDate : { invalid : Elm.Expression -> Elm.Expression } -> Elm.Expression
403
+ formFieldDate dateArg =
404
+ Elm.apply
405
+ (Elm.value
406
+ { importFrom = [ "Form", "Field" ]
407
+ , name = "date"
408
+ , annotation = Nothing
409
+ }
410
+ )
411
+ [ Elm.record
412
+ [ Tuple.pair
413
+ "invalid"
414
+ (Elm.functionReduced "dateUnpack" dateArg.invalid)
415
+ ]
416
+ ]
417
+
418
+
419
+ formFieldCheckbox : Elm.Expression
420
+ formFieldCheckbox =
421
+ Elm.value
422
+ { importFrom = [ "Form", "Field" ]
423
+ , name = "checkbox"
424
+ , annotation = Nothing
425
+ }
426
+
427
+
428
+ formFieldFloat : { invalid : Elm.Expression -> Elm.Expression } -> Elm.Expression
429
+ formFieldFloat floatArg =
430
+ Elm.apply
431
+ (Elm.value
432
+ { importFrom = [ "Form", "Field" ]
433
+ , name = "float"
434
+ , annotation = Nothing
435
+ }
436
+ )
437
+ [ Elm.record
438
+ [ Tuple.pair
439
+ "invalid"
440
+ (Elm.functionReduced "floatUnpack" floatArg.invalid)
441
+ ]
442
+ ]
443
+
444
+
445
+ formField : String -> Elm.Expression -> Elm.Expression
446
+ formField fieldArg fieldArg0 =
447
+ Elm.apply
448
+ (Elm.value
449
+ { importFrom = [ "Form" ]
450
+ , name = "field"
451
+ , annotation = Nothing
452
+ }
453
+ )
454
+ [ Elm.string fieldArg, fieldArg0 ]
455
+
456
+
457
+ formInit : Elm.Expression
458
+ formInit =
459
+ Elm.value
460
+ { importFrom = [ "Form" ]
461
+ , name = "init"
462
+ , annotation = Nothing
463
+ }
464
+ |> Elm.Op.pipe
465
+ (Elm.apply
466
+ (Elm.value
467
+ { importFrom = [ "Form" ]
468
+ , name = "hiddenKind"
469
+ , annotation = Nothing
470
+ }
471
+ )
472
+ [ Elm.tuple (Elm.string "kind") (Elm.string "regular")
473
+ , Elm.string "Expected kind."
474
+ ]
475
+ )
476
+
477
+
478
+ initCombined : Elm.Expression -> Elm.Expression -> Elm.Expression
479
+ initCombined initCombinedArg initCombinedArg0 =
480
+ Elm.apply
481
+ (Elm.value
482
+ { importFrom = [ "Form" ]
483
+ , name = "initCombined"
484
+ , annotation = Nothing
485
+ }
486
+ )
487
+ [ initCombinedArg, initCombinedArg0 ]
488
+
489
+
490
+ {-| Generate a JSON Encoder for the form fields. This can be helpful for sending the validated form data through a
491
+ BackendTask.Custom or to an external API from your scaffolded Route Module code.
492
+ -}
493
+ recordEncoder : Elm.Expression -> List ( String, Kind ) -> Elm.Expression
494
+ recordEncoder record fields =
495
+ fields
496
+ |> List.map
497
+ (\( field, kind ) ->
498
+ Elm.tuple
499
+ (Elm.string field)
500
+ (fieldEncoder record field kind)
501
+ )
502
+ |> Elm.list
503
+ |> List.singleton
504
+ |> Elm.apply
505
+ (Elm.value
506
+ { importFrom = [ "Json", "Encode" ]
507
+ , name = "object"
508
+ , annotation =
509
+ Just
510
+ (Type.function
511
+ [ Type.list
512
+ (Type.tuple
513
+ Type.string
514
+ (Type.namedWith [ "Json", "Encode" ] "Value" [])
515
+ )
516
+ ]
517
+ (Type.namedWith [ "Json", "Encode" ] "Value" [])
518
+ )
519
+ }
520
+ )
521
+
522
+
523
+ {-| -}
524
+ fieldEncoder : Elm.Expression -> String -> Kind -> Elm.Expression
525
+ fieldEncoder record name kind =
526
+ Elm.apply
527
+ (case kind of
528
+ FieldInt ->
529
+ encoder "int"
530
+
531
+ FieldText ->
532
+ encoder "string"
533
+
534
+ FieldTextarea ->
535
+ encoder "string"
536
+
537
+ FieldFloat ->
538
+ encoder "float"
539
+
540
+ FieldTime ->
541
+ -- TODO fix time encoder
542
+ encoder "int"
543
+
544
+ FieldDate ->
545
+ -- TODO fix date encoder
546
+ encoder "int"
547
+
548
+ FieldCheckbox ->
549
+ encoder "bool"
550
+ )
551
+ [ Elm.get name record ]
552
+
553
+
554
+ encoder : String -> Elm.Expression
555
+ encoder name =
556
+ Elm.value
557
+ { importFrom = [ "Json", "Encode" ]
558
+ , name = name
559
+ , annotation = Nothing
560
+ }