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

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