elm-pages 3.0.0-beta.4 → 3.0.0-beta.40

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 (140) hide show
  1. package/README.md +10 -1
  2. package/adapter/netlify.js +207 -0
  3. package/codegen/{elm-pages-codegen.js → elm-pages-codegen.cjs} +2678 -2725
  4. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmi +0 -0
  5. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmo +0 -0
  6. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateDataTest.elmo +0 -0
  7. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
  8. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/i.dat +0 -0
  9. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
  10. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm.json +1 -1
  11. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +1447 -342
  12. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Runner.elm.js +17004 -13817
  13. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
  14. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_supervisor.js +4 -4
  15. package/generator/dead-code-review/elm.json +9 -7
  16. package/generator/dead-code-review/src/Pages/Review/DeadCodeEliminateData.elm +59 -10
  17. package/generator/dead-code-review/tests/Pages/Review/DeadCodeEliminateDataTest.elm +52 -36
  18. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Internal-RoutePattern.elmi +0 -0
  19. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Internal-RoutePattern.elmo +0 -0
  20. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolations.elmi +0 -0
  21. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolations.elmo +0 -0
  22. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
  23. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/i.dat +0 -0
  24. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
  25. package/generator/review/elm-stuff/tests-0.19.1/elm.json +1 -1
  26. package/generator/review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +1447 -342
  27. package/generator/review/elm-stuff/tests-0.19.1/js/Runner.elm.js +25025 -21739
  28. package/generator/review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
  29. package/generator/review/elm-stuff/tests-0.19.1/js/node_supervisor.js +4 -4
  30. package/generator/review/elm.json +10 -10
  31. package/generator/src/RouteBuilder.elm +115 -109
  32. package/generator/src/SharedTemplate.elm +3 -2
  33. package/generator/src/SiteConfig.elm +3 -2
  34. package/generator/src/basepath-middleware.js +3 -3
  35. package/generator/src/build.js +209 -92
  36. package/generator/src/cli.js +292 -88
  37. package/generator/src/codegen.js +29 -27
  38. package/generator/src/compatibility-key.js +3 -0
  39. package/generator/src/compile-elm.js +43 -26
  40. package/generator/src/config.js +39 -0
  41. package/generator/src/copy-dir.js +2 -2
  42. package/generator/src/dev-server.js +176 -138
  43. package/generator/src/dir-helpers.js +9 -26
  44. package/generator/src/elm-codegen.js +5 -4
  45. package/generator/src/elm-file-constants.js +2 -3
  46. package/generator/src/error-formatter.js +12 -11
  47. package/generator/src/file-helpers.js +3 -4
  48. package/generator/src/generate-template-module-connector.js +23 -23
  49. package/generator/src/init.js +9 -8
  50. package/generator/src/pre-render-html.js +39 -28
  51. package/generator/src/render-test.js +109 -0
  52. package/generator/src/render-worker.js +25 -28
  53. package/generator/src/render.js +321 -142
  54. package/generator/src/request-cache.js +265 -162
  55. package/generator/src/resolve-elm-module.js +64 -0
  56. package/generator/src/rewrite-client-elm-json.js +6 -5
  57. package/generator/src/rewrite-elm-json-help.js +56 -0
  58. package/generator/src/rewrite-elm-json.js +17 -7
  59. package/generator/src/route-codegen-helpers.js +16 -31
  60. package/generator/src/seo-renderer.js +12 -7
  61. package/generator/src/vite-utils.js +77 -0
  62. package/generator/static-code/elm-pages.js +10 -0
  63. package/generator/static-code/hmr.js +79 -13
  64. package/generator/template/app/Api.elm +6 -5
  65. package/generator/template/app/Effect.elm +123 -0
  66. package/generator/template/app/ErrorPage.elm +37 -6
  67. package/generator/template/app/Route/Index.elm +17 -10
  68. package/generator/template/app/Shared.elm +24 -47
  69. package/generator/template/app/Site.elm +19 -6
  70. package/generator/template/app/View.elm +1 -8
  71. package/generator/template/elm-tooling.json +0 -3
  72. package/generator/template/elm.json +32 -24
  73. package/generator/template/package.json +10 -4
  74. package/package.json +30 -27
  75. package/src/ApiRoute.elm +199 -61
  76. package/src/BackendTask/Custom.elm +325 -0
  77. package/src/BackendTask/Env.elm +90 -0
  78. package/src/{DataSource → BackendTask}/File.elm +171 -56
  79. package/src/{DataSource → BackendTask}/Glob.elm +136 -125
  80. package/src/BackendTask/Http.elm +679 -0
  81. package/src/{DataSource → BackendTask}/Internal/Glob.elm +1 -1
  82. package/src/BackendTask/Internal/Request.elm +69 -0
  83. package/src/BackendTask/Random.elm +79 -0
  84. package/src/BackendTask/Time.elm +47 -0
  85. package/src/BackendTask.elm +537 -0
  86. package/src/FatalError.elm +90 -0
  87. package/src/Head.elm +237 -7
  88. package/src/HtmlPrinter.elm +7 -3
  89. package/src/Internal/ApiRoute.elm +7 -5
  90. package/src/PageServerResponse.elm +6 -1
  91. package/src/Pages/Form.elm +229 -0
  92. package/src/Pages/GeneratorProgramConfig.elm +15 -0
  93. package/src/Pages/Internal/FatalError.elm +5 -0
  94. package/src/Pages/Internal/Msg.elm +93 -0
  95. package/src/Pages/Internal/Platform/Cli.elm +612 -763
  96. package/src/Pages/Internal/Platform/CompatibilityKey.elm +6 -0
  97. package/src/Pages/Internal/Platform/Effect.elm +1 -2
  98. package/src/Pages/Internal/Platform/GeneratorApplication.elm +379 -0
  99. package/src/Pages/Internal/Platform/StaticResponses.elm +65 -276
  100. package/src/Pages/Internal/Platform/ToJsPayload.elm +6 -9
  101. package/src/Pages/Internal/Platform.elm +327 -194
  102. package/src/Pages/Internal/Script.elm +17 -0
  103. package/src/Pages/Internal/StaticHttpBody.elm +35 -1
  104. package/src/Pages/Manifest.elm +29 -4
  105. package/src/Pages/PageUrl.elm +23 -9
  106. package/src/Pages/ProgramConfig.elm +26 -15
  107. package/src/Pages/Script.elm +109 -0
  108. package/src/Pages/SiteConfig.elm +3 -2
  109. package/src/Pages/StaticHttp/Request.elm +2 -2
  110. package/src/Pages/StaticHttpRequest.elm +23 -99
  111. package/src/Pages/Transition.elm +12 -3
  112. package/src/PagesMsg.elm +82 -0
  113. package/src/Path.elm +16 -19
  114. package/src/QueryParams.elm +21 -172
  115. package/src/RequestsAndPending.elm +37 -20
  116. package/src/Result/Extra.elm +26 -0
  117. package/src/Scaffold/Form.elm +546 -0
  118. package/src/Scaffold/Route.elm +1402 -0
  119. package/src/Server/Request.elm +73 -72
  120. package/src/Server/Session.elm +62 -42
  121. package/src/Server/SetCookie.elm +12 -4
  122. package/src/Stub.elm +53 -0
  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/Form/Field.elm +0 -717
  130. package/src/Form/FieldStatus.elm +0 -36
  131. package/src/Form/FieldView.elm +0 -417
  132. package/src/Form/FormData.elm +0 -22
  133. package/src/Form/Validation.elm +0 -391
  134. package/src/Form/Value.elm +0 -118
  135. package/src/Form.elm +0 -1683
  136. package/src/FormDecoder.elm +0 -102
  137. package/src/Pages/FormState.elm +0 -256
  138. package/src/Pages/Generate.elm +0 -800
  139. package/src/Pages/Internal/Form.elm +0 -17
  140. package/src/Pages/Msg.elm +0 -79
@@ -1,717 +0,0 @@
1
- module Form.Field exposing
2
- ( text, checkbox, int, float
3
- , select, range, OutsideRange(..)
4
- , date, time, TimeOfDay
5
- , Field(..), FieldInfo, exactValue
6
- , required, withClientValidation, withInitialValue, map
7
- , email, password, search, telephone, url, textarea
8
- , withMax, withMin, withStep, withMinLength, withMaxLength
9
- , No, Yes
10
- )
11
-
12
- {-|
13
-
14
-
15
- ## Base Fields
16
-
17
- @docs text, checkbox, int, float
18
-
19
-
20
- ## Multiple Choice Fields
21
-
22
- @docs select, range, OutsideRange
23
-
24
-
25
- ## Date/Time Fields
26
-
27
- @docs date, time, TimeOfDay
28
-
29
-
30
- ## Other
31
-
32
- @docs Field, FieldInfo, exactValue
33
-
34
-
35
- ## Field Configuration
36
-
37
- @docs required, withClientValidation, withInitialValue, map
38
-
39
-
40
- ## Text Field Display Options
41
-
42
- @docs email, password, search, telephone, url, textarea
43
-
44
-
45
- ## Numeric Field Options
46
-
47
- @docs withMax, withMin, withStep, withMinLength, withMaxLength
48
-
49
-
50
- ## Phantom Options
51
-
52
- @docs No, Yes
53
-
54
- -}
55
-
56
- import Date exposing (Date)
57
- import Dict exposing (Dict)
58
- import Form.FieldView as FieldView exposing (Input, Options(..))
59
- import Form.Value
60
- import Json.Encode as Encode
61
-
62
-
63
- {-| -}
64
- type Field error parsed data kind constraints
65
- = Field (FieldInfo error parsed data) kind
66
-
67
-
68
- {-| -}
69
- type alias FieldInfo error parsed data =
70
- { initialValue : Maybe (data -> String)
71
- , decode : Maybe String -> ( Maybe parsed, List error )
72
- , properties : List ( String, Encode.Value )
73
- }
74
-
75
-
76
- {-| -}
77
- type Yes
78
- = Yes Never
79
-
80
-
81
- {-| -}
82
- type No
83
- = No Never
84
-
85
-
86
- {-| -}
87
- required :
88
- error
89
- ->
90
- Field
91
- error
92
- (Maybe parsed)
93
- data
94
- kind
95
- { constraints
96
- | required : ()
97
- , wasMapped : No
98
- }
99
- -> Field error parsed data kind { constraints | wasMapped : No }
100
- required missingError (Field field kind) =
101
- Field
102
- { initialValue = field.initialValue
103
- , decode =
104
- \rawValue ->
105
- let
106
- ( parsed, allErrors ) =
107
- field.decode rawValue
108
-
109
- isEmpty : Bool
110
- isEmpty =
111
- rawValue == Just "" || rawValue == Nothing
112
- in
113
- ( parsed |> Maybe.andThen identity
114
- , if isEmpty then
115
- missingError :: allErrors
116
-
117
- else
118
- allErrors
119
- )
120
- , properties = field.properties
121
- }
122
- kind
123
-
124
-
125
- {-| -}
126
- text :
127
- Field
128
- error
129
- (Maybe String)
130
- data
131
- Input
132
- { required : ()
133
- , plainText : ()
134
- , wasMapped : No
135
- , initial : String
136
- , minlength : ()
137
- , maxlength : ()
138
- }
139
- text =
140
- Field
141
- { initialValue = Nothing
142
- , decode =
143
- \rawValue ->
144
- ( if rawValue == Just "" then
145
- Just Nothing
146
-
147
- else
148
- Just rawValue
149
- , []
150
- )
151
- , properties = []
152
- }
153
- (FieldView.Input FieldView.Text)
154
-
155
-
156
- {-| -}
157
- date :
158
- { invalid : String -> error }
159
- ->
160
- Field
161
- error
162
- (Maybe Date)
163
- data
164
- Input
165
- { min : Date
166
- , max : Date
167
- , required : ()
168
- , wasMapped : No
169
- , initial : Date
170
- }
171
- date toError =
172
- Field
173
- { initialValue = Nothing
174
- , decode =
175
- \rawString ->
176
- if (rawString |> Maybe.withDefault "") == "" then
177
- ( Just Nothing, [] )
178
-
179
- else
180
- case
181
- rawString
182
- |> Maybe.withDefault ""
183
- |> Date.fromIsoString
184
- |> Result.mapError (\_ -> toError.invalid (rawString |> Maybe.withDefault ""))
185
- of
186
- Ok parsedDate ->
187
- ( Just (Just parsedDate), [] )
188
-
189
- Err error ->
190
- ( Nothing, [ error ] )
191
- , properties = []
192
- }
193
- (FieldView.Input FieldView.Date)
194
-
195
-
196
- {-| -}
197
- type alias TimeOfDay =
198
- { hours : Int
199
- , minutes : Int
200
- }
201
-
202
-
203
- {-| <https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/time>
204
- -}
205
- time :
206
- { invalid : String -> error }
207
- ->
208
- Field
209
- error
210
- (Maybe TimeOfDay)
211
- data
212
- Input
213
- { -- TODO support min/max
214
- --min : ???,
215
- --, max : ???,
216
- required : ()
217
- , wasMapped : No
218
- }
219
- time toError =
220
- Field
221
- { initialValue = Nothing
222
- , decode =
223
- \rawString ->
224
- if (rawString |> Maybe.withDefault "") == "" then
225
- ( Just Nothing, [] )
226
-
227
- else
228
- case
229
- rawString
230
- |> Maybe.withDefault ""
231
- |> parseTimeOfDay
232
- |> Result.mapError (\_ -> toError.invalid (rawString |> Maybe.withDefault ""))
233
- of
234
- Ok parsedDate ->
235
- ( Just (Just parsedDate), [] )
236
-
237
- Err error ->
238
- ( Nothing, [ error ] )
239
- , properties = []
240
- }
241
- (FieldView.Input FieldView.Time)
242
-
243
-
244
- parseTimeOfDay : String -> Result () { hours : Int, minutes : Int }
245
- parseTimeOfDay rawTimeOfDay =
246
- case rawTimeOfDay |> String.split ":" |> List.map String.toInt of
247
- [ Just hours, Just minutes ] ->
248
- Ok
249
- { hours = hours
250
- , minutes = minutes
251
- }
252
-
253
- _ ->
254
- Err ()
255
-
256
-
257
- {-| -}
258
- select :
259
- List ( String, option )
260
- -> (String -> error)
261
- ->
262
- Field
263
- error
264
- (Maybe option)
265
- data
266
- (Options option)
267
- { required : ()
268
- , wasMapped : No
269
- }
270
- select optionsMapping invalidError =
271
- let
272
- dict : Dict String option
273
- dict =
274
- Dict.fromList optionsMapping
275
-
276
- fromString : String -> Maybe option
277
- fromString string =
278
- Dict.get string dict
279
- in
280
- Field
281
- { initialValue = Nothing
282
- , decode =
283
- \rawValue ->
284
- case rawValue of
285
- Nothing ->
286
- ( Just Nothing, [] )
287
-
288
- Just "" ->
289
- ( Just Nothing, [] )
290
-
291
- Just justValue ->
292
- let
293
- parsed : Maybe option
294
- parsed =
295
- fromString justValue
296
- in
297
- case parsed of
298
- Just okParsed ->
299
- ( Just (Just okParsed)
300
- , []
301
- )
302
-
303
- Nothing ->
304
- ( Just Nothing
305
- , [ invalidError justValue
306
- ]
307
- )
308
- , properties = []
309
- }
310
- (Options fromString (optionsMapping |> List.map Tuple.first))
311
-
312
-
313
- {-| -}
314
- exactValue :
315
- String
316
- -> error
317
- ->
318
- Field
319
- error
320
- String
321
- data
322
- Input
323
- { required : ()
324
- , plainText : ()
325
- , wasMapped : No
326
- , initial : String
327
- }
328
- exactValue initialValue error =
329
- Field
330
- { initialValue = Just (\_ -> initialValue)
331
- , decode =
332
- \rawValue ->
333
- if rawValue == Just initialValue then
334
- ( rawValue, [] )
335
-
336
- else
337
- ( rawValue, [ error ] )
338
- , properties = []
339
- }
340
- (FieldView.Input FieldView.Text)
341
-
342
-
343
- {-| -}
344
- checkbox :
345
- Field
346
- error
347
- Bool
348
- data
349
- Input
350
- { required : ()
351
- , initial : Bool
352
- }
353
- checkbox =
354
- Field
355
- { initialValue = Nothing
356
- , decode =
357
- \rawString ->
358
- ( (rawString == Just "on")
359
- |> Just
360
- , []
361
- )
362
- , properties = []
363
- }
364
- (FieldView.Input FieldView.Checkbox)
365
-
366
-
367
- {-| -}
368
- int :
369
- { invalid : String -> error }
370
- ->
371
- Field
372
- error
373
- (Maybe Int)
374
- data
375
- Input
376
- { min : Int
377
- , max : Int
378
- , required : ()
379
- , wasMapped : No
380
- , step : Int
381
- , initial : Int
382
- }
383
- int toError =
384
- Field
385
- { initialValue = Nothing
386
- , decode =
387
- \rawString ->
388
- case rawString of
389
- Nothing ->
390
- ( Just Nothing, [] )
391
-
392
- Just "" ->
393
- ( Just Nothing, [] )
394
-
395
- Just string ->
396
- case string |> String.toInt of
397
- Just parsedInt ->
398
- ( Just (Just parsedInt), [] )
399
-
400
- Nothing ->
401
- ( Nothing, [ toError.invalid string ] )
402
- , properties = []
403
- }
404
- (FieldView.Input FieldView.Number)
405
-
406
-
407
- {-| -}
408
- float :
409
- { invalid : String -> error }
410
- ->
411
- Field
412
- error
413
- (Maybe Float)
414
- data
415
- Input
416
- { min : Float
417
- , max : Float
418
- , required : ()
419
- , wasMapped : No
420
- , initial : Float
421
- }
422
- float toError =
423
- Field
424
- { initialValue = Nothing
425
- , decode =
426
- \rawString ->
427
- case rawString of
428
- Nothing ->
429
- ( Just Nothing, [] )
430
-
431
- Just "" ->
432
- ( Just Nothing, [] )
433
-
434
- Just string ->
435
- case string |> String.toFloat of
436
- Just parsedFloat ->
437
- ( Just (Just parsedFloat), [] )
438
-
439
- Nothing ->
440
- ( Nothing, [ toError.invalid string ] )
441
- , properties = []
442
- }
443
- (FieldView.Input FieldView.Number)
444
-
445
-
446
- {-| -}
447
- telephone :
448
- Field error parsed data Input { constraints | plainText : () }
449
- -> Field error parsed data Input constraints
450
- telephone (Field field _) =
451
- Field field
452
- (FieldView.Input FieldView.Tel)
453
-
454
-
455
- {-| -}
456
- search :
457
- Field error parsed data Input { constraints | plainText : () }
458
- -> Field error parsed data Input constraints
459
- search (Field field _) =
460
- Field field
461
- (FieldView.Input FieldView.Search)
462
-
463
-
464
- {-| -}
465
- password :
466
- Field error parsed data Input { constraints | plainText : () }
467
- -> Field error parsed data Input constraints
468
- password (Field field _) =
469
- Field field
470
- (FieldView.Input FieldView.Password)
471
-
472
-
473
- {-| -}
474
- email :
475
- Field error parsed data Input { constraints | plainText : () }
476
- -> Field error parsed data Input constraints
477
- email (Field field _) =
478
- Field field
479
- (FieldView.Input FieldView.Email)
480
-
481
-
482
- {-| -}
483
- url :
484
- Field error parsed data Input { constraints | plainText : () }
485
- -> Field error parsed data Input constraints
486
- url (Field field _) =
487
- Field field
488
- (FieldView.Input FieldView.Url)
489
-
490
-
491
- {-| -}
492
- textarea :
493
- Field error parsed data Input { constraints | plainText : () }
494
- -> Field error parsed data Input constraints
495
- textarea (Field field _) =
496
- Field field (FieldView.Input FieldView.Textarea)
497
-
498
-
499
- {-| -}
500
- type OutsideRange
501
- = AboveRange
502
- | BelowRange
503
-
504
-
505
- {-| -}
506
- range :
507
- { min : Form.Value.Value valueType
508
- , max : Form.Value.Value valueType
509
- , initial : data -> Form.Value.Value valueType
510
- , missing : error
511
- , invalid : OutsideRange -> error
512
- }
513
- ->
514
- Field
515
- error
516
- (Maybe valueType)
517
- data
518
- kind
519
- { constraints
520
- | required : ()
521
- , initial : valueType
522
- , min : valueType
523
- , max : valueType
524
- , wasMapped : No
525
- }
526
- ->
527
- Field
528
- error
529
- valueType
530
- data
531
- Input
532
- { constraints | wasMapped : No }
533
- range info field =
534
- field
535
- |> required info.missing
536
- |> withMin info.min (info.invalid BelowRange)
537
- |> withMax info.max (info.invalid AboveRange)
538
- |> (\(Field innerField _) -> Field { innerField | initialValue = Just (info.initial >> Form.Value.toString) } (FieldView.Input FieldView.Range))
539
-
540
-
541
- {-| -}
542
- map : (parsed -> mapped) -> Field error parsed data kind constraints -> Field error mapped data kind { constraints | wasMapped : Yes }
543
- map mapFn field_ =
544
- withClientValidation
545
- (\value -> ( Just (mapFn value), [] ))
546
- field_
547
-
548
-
549
- {-| -}
550
- withClientValidation : (parsed -> ( Maybe mapped, List error )) -> Field error parsed data kind constraints -> Field error mapped data kind { constraints | wasMapped : Yes }
551
- withClientValidation mapFn (Field field kind) =
552
- Field
553
- { initialValue = field.initialValue
554
- , decode =
555
- \value ->
556
- value
557
- |> field.decode
558
- |> (\( maybeValue, errors ) ->
559
- case maybeValue of
560
- Nothing ->
561
- ( Nothing, errors )
562
-
563
- Just okValue ->
564
- okValue
565
- |> mapFn
566
- |> Tuple.mapSecond ((++) errors)
567
- )
568
- , properties = field.properties
569
- }
570
- kind
571
-
572
-
573
- {-| -}
574
- withInitialValue : (data -> Form.Value.Value valueType) -> Field error value data kind { constraints | initial : valueType } -> Field error value data kind constraints
575
- withInitialValue toInitialValue (Field field kind) =
576
- Field
577
- { field
578
- | initialValue =
579
- Just (toInitialValue >> Form.Value.toString)
580
- }
581
- kind
582
-
583
-
584
-
585
- -- Input Properties
586
-
587
-
588
- {-| -}
589
- withMin : Form.Value.Value valueType -> error -> Field error parsed data kind { constraints | min : valueType } -> Field error parsed data kind constraints
590
- withMin min error (Field field kind) =
591
- Field
592
- { initialValue = field.initialValue
593
- , decode =
594
- \value ->
595
- value
596
- |> field.decode
597
- |> (\( maybeValue, errors ) ->
598
- case maybeValue of
599
- Nothing ->
600
- ( Nothing, errors )
601
-
602
- Just okValue ->
603
- if isEmptyValue value then
604
- ( Just okValue, errors )
605
-
606
- else
607
- case Form.Value.compare (value |> Maybe.withDefault "") min of
608
- LT ->
609
- ( Just okValue, error :: errors )
610
-
611
- _ ->
612
- ( Just okValue, errors )
613
- )
614
- , properties = ( "min", Encode.string (Form.Value.toString min) ) :: field.properties
615
- }
616
- kind
617
-
618
-
619
- {-| -}
620
- withMinLength : Int -> error -> Field error parsed data kind { constraints | minlength : () } -> Field error parsed data kind constraints
621
- withMinLength minLength error (Field field kind) =
622
- Field
623
- { initialValue = field.initialValue
624
- , decode =
625
- \value ->
626
- value
627
- |> field.decode
628
- |> (\( maybeValue, errors ) ->
629
- case maybeValue of
630
- Nothing ->
631
- ( Nothing, errors )
632
-
633
- Just okValue ->
634
- if (value |> Maybe.withDefault "" |> String.length) >= minLength then
635
- ( Just okValue, errors )
636
-
637
- else
638
- ( Just okValue, error :: errors )
639
- )
640
- , properties = ( "minlength", Encode.string (String.fromInt minLength) ) :: field.properties
641
- }
642
- kind
643
-
644
-
645
- {-| -}
646
- withMaxLength : Int -> error -> Field error parsed data kind { constraints | maxlength : () } -> Field error parsed data kind constraints
647
- withMaxLength maxLength error (Field field kind) =
648
- Field
649
- { initialValue = field.initialValue
650
- , decode =
651
- \value ->
652
- value
653
- |> field.decode
654
- |> (\( maybeValue, errors ) ->
655
- case maybeValue of
656
- Nothing ->
657
- ( Nothing, errors )
658
-
659
- Just okValue ->
660
- if (value |> Maybe.withDefault "" |> String.length) <= maxLength then
661
- ( Just okValue, errors )
662
-
663
- else
664
- ( Just okValue, error :: errors )
665
- )
666
- , properties = ( "maxlength", Encode.string (String.fromInt maxLength) ) :: field.properties
667
- }
668
- kind
669
-
670
-
671
- isEmptyValue : Maybe String -> Bool
672
- isEmptyValue value =
673
- (value |> Maybe.withDefault "") == ""
674
-
675
-
676
- {-| -}
677
- withMax : Form.Value.Value valueType -> error -> Field error parsed data kind { constraints | max : valueType } -> Field error parsed data kind constraints
678
- withMax max error (Field field kind) =
679
- Field
680
- { initialValue = field.initialValue
681
- , decode =
682
- \value ->
683
- value
684
- |> field.decode
685
- |> (\( maybeValue, errors ) ->
686
- case maybeValue of
687
- Nothing ->
688
- ( Nothing, errors )
689
-
690
- Just okValue ->
691
- if isEmptyValue value then
692
- ( Just okValue, errors )
693
-
694
- else
695
- case Form.Value.compare (value |> Maybe.withDefault "") max of
696
- GT ->
697
- ( Just okValue, error :: errors )
698
-
699
- _ ->
700
- ( Just okValue, errors )
701
- )
702
- , properties = ( "max", Encode.string (Form.Value.toString max) ) :: field.properties
703
- }
704
- kind
705
-
706
-
707
- {-| -}
708
- withStep : Form.Value.Value valueType -> Field msg error value view { constraints | step : valueType } -> Field msg error value view constraints
709
- withStep max field =
710
- withStringProperty ( "step", Form.Value.toString max ) field
711
-
712
-
713
- withStringProperty : ( String, String ) -> Field error parsed data kind constraints1 -> Field error parsed data kind constraints2
714
- withStringProperty ( key, value ) (Field field kind) =
715
- Field
716
- { field | properties = ( key, Encode.string value ) :: field.properties }
717
- kind