elm-pages 3.0.0-beta.32 → 3.0.0-beta.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/codegen/elm-pages-codegen.cjs +10 -78
- 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/dead-code-review/elm.json +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/review/elm.json +1 -1
- package/generator/src/RouteBuilder.elm +2 -2
- package/generator/src/compatibility-key.js +2 -2
- package/generator/src/render.js +1 -0
- package/generator/src/request-cache.js +20 -6
- package/generator/static-code/elm-pages.js +10 -0
- package/package.json +3 -3
- package/src/BackendTask/Http.elm +8 -2
- package/src/Internal/Field.elm +19 -0
- package/src/Internal/Input.elm +81 -0
- package/src/Pages/Form.elm +229 -0
- package/src/Pages/Internal/Msg.elm +70 -61
- package/src/Pages/Internal/Platform/Cli.elm +423 -425
- package/src/Pages/Internal/Platform/CompatibilityKey.elm +1 -1
- package/src/Pages/Internal/Platform/GeneratorApplication.elm +1 -5
- package/src/Pages/Internal/Platform.elm +119 -100
- package/src/Pages/ProgramConfig.elm +12 -5
- package/src/Pages/StaticHttpRequest.elm +0 -1
- package/src/Pages/Transition.elm +9 -1
- package/src/PagesMsg.elm +0 -10
- package/src/RequestsAndPending.elm +31 -3
- package/src/Scaffold/Form.elm +9 -9
- package/src/Server/Request.elm +57 -61
- package/src/Form/Field.elm +0 -729
- package/src/Form/FieldStatus.elm +0 -36
- package/src/Form/FieldView.elm +0 -497
- package/src/Form/FormData.elm +0 -22
- package/src/Form/Validation.elm +0 -391
- package/src/Form/Value.elm +0 -118
- package/src/Form.elm +0 -1558
- package/src/FormDecoder.elm +0 -102
- package/src/Pages/FormState.elm +0 -257
- package/src/Pages/Internal/Form.elm +0 -37
package/src/FormDecoder.elm
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
module FormDecoder exposing (encodeFormData, formDataOnSubmit, methodToString)
|
|
2
|
-
|
|
3
|
-
import Form.FormData as FormData exposing (FormData)
|
|
4
|
-
import Html
|
|
5
|
-
import Html.Events
|
|
6
|
-
import Json.Decode as Decode
|
|
7
|
-
import Json.Encode
|
|
8
|
-
import Url
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
formDataOnSubmit : Html.Attribute FormData
|
|
12
|
-
formDataOnSubmit =
|
|
13
|
-
Html.Events.preventDefaultOn "submit"
|
|
14
|
-
(Decode.map4 FormData
|
|
15
|
-
(Decode.value
|
|
16
|
-
|> Decode.andThen
|
|
17
|
-
(\decodeValue ->
|
|
18
|
-
case Decode.decodeValue tuplesDecoder (decoder decodeValue) of
|
|
19
|
-
Ok decoded ->
|
|
20
|
-
Decode.succeed decoded
|
|
21
|
-
|
|
22
|
-
Err error ->
|
|
23
|
-
Decode.succeed
|
|
24
|
-
[ ( "error"
|
|
25
|
-
, Decode.errorToString error
|
|
26
|
-
)
|
|
27
|
-
]
|
|
28
|
-
)
|
|
29
|
-
)
|
|
30
|
-
(currentForm "method" methodDecoder)
|
|
31
|
-
(currentForm "action" Decode.string)
|
|
32
|
-
(currentForm "id" (Decode.nullable Decode.string))
|
|
33
|
-
|> Decode.map alwaysPreventDefault
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
currentForm : String -> Decode.Decoder a -> Decode.Decoder a
|
|
38
|
-
currentForm field decoder_ =
|
|
39
|
-
Decode.oneOf
|
|
40
|
-
[ Decode.at [ "submitter", "form" ] decoder_
|
|
41
|
-
, Decode.at [ "currentTarget", field ] decoder_
|
|
42
|
-
]
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
methodDecoder : Decode.Decoder FormData.Method
|
|
46
|
-
methodDecoder =
|
|
47
|
-
Decode.string
|
|
48
|
-
|> Decode.map
|
|
49
|
-
(\methodString ->
|
|
50
|
-
case methodString |> String.toUpper of
|
|
51
|
-
"GET" ->
|
|
52
|
-
FormData.Get
|
|
53
|
-
|
|
54
|
-
"POST" ->
|
|
55
|
-
FormData.Post
|
|
56
|
-
|
|
57
|
-
_ ->
|
|
58
|
-
-- TODO what about "dialog" method? Is it okay for that to be interpreted as GET,
|
|
59
|
-
-- or should there be a variant for that?
|
|
60
|
-
FormData.Get
|
|
61
|
-
)
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
decoder : Decode.Value -> Decode.Value
|
|
65
|
-
decoder event =
|
|
66
|
-
Json.Encode.string "REPLACE_ME_WITH_FORM_TO_STRING"
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
alwaysPreventDefault : msg -> ( msg, Bool )
|
|
70
|
-
alwaysPreventDefault msg =
|
|
71
|
-
( msg, True )
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
tuplesDecoder : Decode.Decoder (List ( String, String ))
|
|
75
|
-
tuplesDecoder =
|
|
76
|
-
Decode.list
|
|
77
|
-
(Decode.map2 Tuple.pair
|
|
78
|
-
(Decode.index 0 Decode.string)
|
|
79
|
-
(Decode.index 1 Decode.string)
|
|
80
|
-
)
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
methodToString : FormData.Method -> String
|
|
84
|
-
methodToString method =
|
|
85
|
-
case method of
|
|
86
|
-
FormData.Get ->
|
|
87
|
-
"GET"
|
|
88
|
-
|
|
89
|
-
FormData.Post ->
|
|
90
|
-
"POST"
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
encodeFormData :
|
|
94
|
-
FormData
|
|
95
|
-
-> String
|
|
96
|
-
encodeFormData data =
|
|
97
|
-
data.fields
|
|
98
|
-
|> List.map
|
|
99
|
-
(\( name, value ) ->
|
|
100
|
-
Url.percentEncode name ++ "=" ++ Url.percentEncode value
|
|
101
|
-
)
|
|
102
|
-
|> String.join "&"
|
package/src/Pages/FormState.elm
DELETED
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
module Pages.FormState exposing (Event(..), FieldEvent, FieldState, FormState, PageFormState, init, listeners, setField, setSubmitAttempted, update)
|
|
2
|
-
|
|
3
|
-
{-|
|
|
4
|
-
|
|
5
|
-
@docs Event, FieldEvent, FieldState, FormState, PageFormState, init, listeners, setField, setSubmitAttempted, update
|
|
6
|
-
|
|
7
|
-
-}
|
|
8
|
-
|
|
9
|
-
import Dict exposing (Dict)
|
|
10
|
-
import Form.FieldStatus as FieldStatus exposing (FieldStatus)
|
|
11
|
-
import Html exposing (Attribute)
|
|
12
|
-
import Html.Attributes as Attr
|
|
13
|
-
import Html.Events
|
|
14
|
-
import Json.Decode as Decode exposing (Decoder)
|
|
15
|
-
import Pages.Internal.Msg
|
|
16
|
-
import PagesMsg exposing (PagesMsg)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
{-| -}
|
|
20
|
-
listeners : String -> List (Attribute (PagesMsg userMsg))
|
|
21
|
-
listeners formId =
|
|
22
|
-
[ Html.Events.on "focusin" (Decode.value |> Decode.map Pages.Internal.Msg.FormFieldEvent)
|
|
23
|
-
, Html.Events.on "focusout" (Decode.value |> Decode.map Pages.Internal.Msg.FormFieldEvent)
|
|
24
|
-
, Html.Events.on "input" (Decode.value |> Decode.map Pages.Internal.Msg.FormFieldEvent)
|
|
25
|
-
, Attr.id formId
|
|
26
|
-
]
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
{-| -}
|
|
30
|
-
type Event
|
|
31
|
-
= InputEvent String
|
|
32
|
-
| FocusEvent
|
|
33
|
-
--| ChangeEvent
|
|
34
|
-
| BlurEvent
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
{-| -}
|
|
38
|
-
type alias FieldEvent =
|
|
39
|
-
{ value : String
|
|
40
|
-
, formId : String
|
|
41
|
-
, name : String
|
|
42
|
-
, event : Event
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
{-| -}
|
|
47
|
-
fieldEventDecoder : Decoder FieldEvent
|
|
48
|
-
fieldEventDecoder =
|
|
49
|
-
Decode.map4 FieldEvent
|
|
50
|
-
inputValueDecoder
|
|
51
|
-
(Decode.at [ "currentTarget", "id" ] Decode.string)
|
|
52
|
-
(Decode.at [ "target", "name" ] Decode.string)
|
|
53
|
-
fieldDecoder
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
{-| -}
|
|
57
|
-
inputValueDecoder : Decoder String
|
|
58
|
-
inputValueDecoder =
|
|
59
|
-
Decode.at [ "target", "type" ] Decode.string
|
|
60
|
-
|> Decode.andThen
|
|
61
|
-
(\targetType ->
|
|
62
|
-
case targetType of
|
|
63
|
-
"checkbox" ->
|
|
64
|
-
Decode.map2
|
|
65
|
-
(\valueWhenChecked isChecked ->
|
|
66
|
-
if isChecked then
|
|
67
|
-
valueWhenChecked
|
|
68
|
-
|
|
69
|
-
else
|
|
70
|
-
""
|
|
71
|
-
)
|
|
72
|
-
(Decode.at [ "target", "value" ] Decode.string)
|
|
73
|
-
(Decode.at [ "target", "checked" ] Decode.bool)
|
|
74
|
-
|
|
75
|
-
_ ->
|
|
76
|
-
Decode.at [ "target", "value" ] Decode.string
|
|
77
|
-
)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
{-| -}
|
|
81
|
-
fieldDecoder : Decoder Event
|
|
82
|
-
fieldDecoder =
|
|
83
|
-
Decode.field "type" Decode.string
|
|
84
|
-
|> Decode.andThen
|
|
85
|
-
(\type_ ->
|
|
86
|
-
case type_ of
|
|
87
|
-
"input" ->
|
|
88
|
-
inputValueDecoder |> Decode.map InputEvent
|
|
89
|
-
|
|
90
|
-
"focusin" ->
|
|
91
|
-
FocusEvent
|
|
92
|
-
|> Decode.succeed
|
|
93
|
-
|
|
94
|
-
"focusout" ->
|
|
95
|
-
BlurEvent
|
|
96
|
-
|> Decode.succeed
|
|
97
|
-
|
|
98
|
-
_ ->
|
|
99
|
-
Decode.fail "Unexpected event.type"
|
|
100
|
-
)
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
{-| -}
|
|
104
|
-
update : Decode.Value -> PageFormState -> PageFormState
|
|
105
|
-
update eventObject pageFormState =
|
|
106
|
-
--if Dict.isEmpty pageFormState then
|
|
107
|
-
-- -- TODO get all initial field values
|
|
108
|
-
-- pageFormState
|
|
109
|
-
--
|
|
110
|
-
--else
|
|
111
|
-
case eventObject |> Decode.decodeValue fieldEventDecoder of
|
|
112
|
-
Ok fieldEvent ->
|
|
113
|
-
pageFormState
|
|
114
|
-
|> Dict.update fieldEvent.formId
|
|
115
|
-
(\previousValue_ ->
|
|
116
|
-
let
|
|
117
|
-
previousValue : FormState
|
|
118
|
-
previousValue =
|
|
119
|
-
previousValue_
|
|
120
|
-
|> Maybe.withDefault init
|
|
121
|
-
in
|
|
122
|
-
previousValue
|
|
123
|
-
|> updateForm fieldEvent
|
|
124
|
-
|> Just
|
|
125
|
-
)
|
|
126
|
-
|
|
127
|
-
Err _ ->
|
|
128
|
-
pageFormState
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
{-| -}
|
|
132
|
-
setField : { formId : String, name : String, value : String } -> PageFormState -> PageFormState
|
|
133
|
-
setField info pageFormState =
|
|
134
|
-
pageFormState
|
|
135
|
-
|> Dict.update info.formId
|
|
136
|
-
(\previousValue_ ->
|
|
137
|
-
let
|
|
138
|
-
previousValue : FormState
|
|
139
|
-
previousValue =
|
|
140
|
-
previousValue_
|
|
141
|
-
|> Maybe.withDefault init
|
|
142
|
-
in
|
|
143
|
-
{ previousValue
|
|
144
|
-
| fields =
|
|
145
|
-
previousValue.fields
|
|
146
|
-
|> Dict.update info.name
|
|
147
|
-
(\previousFieldValue_ ->
|
|
148
|
-
let
|
|
149
|
-
previousFieldValue : FieldState
|
|
150
|
-
previousFieldValue =
|
|
151
|
-
previousFieldValue_
|
|
152
|
-
|> Maybe.withDefault { value = "", status = FieldStatus.NotVisited }
|
|
153
|
-
in
|
|
154
|
-
{ previousFieldValue | value = info.value }
|
|
155
|
-
|> Just
|
|
156
|
-
)
|
|
157
|
-
}
|
|
158
|
-
|> Just
|
|
159
|
-
)
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
{-| -}
|
|
163
|
-
updateForm : FieldEvent -> FormState -> FormState
|
|
164
|
-
updateForm fieldEvent formState =
|
|
165
|
-
{ formState
|
|
166
|
-
| fields =
|
|
167
|
-
formState.fields
|
|
168
|
-
|> Dict.update fieldEvent.name
|
|
169
|
-
(\previousValue_ ->
|
|
170
|
-
let
|
|
171
|
-
previousValue : FieldState
|
|
172
|
-
previousValue =
|
|
173
|
-
previousValue_
|
|
174
|
-
|> Maybe.withDefault { value = fieldEvent.value, status = FieldStatus.NotVisited }
|
|
175
|
-
in
|
|
176
|
-
(case fieldEvent.event of
|
|
177
|
-
InputEvent newValue ->
|
|
178
|
-
{ previousValue | value = newValue }
|
|
179
|
-
|
|
180
|
-
FocusEvent ->
|
|
181
|
-
{ previousValue | status = previousValue.status |> increaseStatusTo FieldStatus.Focused }
|
|
182
|
-
|
|
183
|
-
BlurEvent ->
|
|
184
|
-
{ previousValue | status = previousValue.status |> increaseStatusTo FieldStatus.Blurred }
|
|
185
|
-
)
|
|
186
|
-
|> Just
|
|
187
|
-
)
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
{-| -}
|
|
192
|
-
setSubmitAttempted : String -> PageFormState -> PageFormState
|
|
193
|
-
setSubmitAttempted fieldId pageFormState =
|
|
194
|
-
pageFormState
|
|
195
|
-
|> Dict.update fieldId
|
|
196
|
-
(\maybeForm ->
|
|
197
|
-
case maybeForm of
|
|
198
|
-
Just formState ->
|
|
199
|
-
Just { formState | submitAttempted = True }
|
|
200
|
-
|
|
201
|
-
Nothing ->
|
|
202
|
-
Just { init | submitAttempted = True }
|
|
203
|
-
)
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
{-| -}
|
|
207
|
-
init : FormState
|
|
208
|
-
init =
|
|
209
|
-
{ fields = Dict.empty
|
|
210
|
-
, submitAttempted = False
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
{-| -}
|
|
215
|
-
type alias PageFormState =
|
|
216
|
-
Dict String FormState
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
{-| -}
|
|
220
|
-
type alias FormState =
|
|
221
|
-
{ fields : Dict String FieldState
|
|
222
|
-
, submitAttempted : Bool
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
{-| -}
|
|
227
|
-
type alias FieldState =
|
|
228
|
-
{ value : String
|
|
229
|
-
, status : FieldStatus
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
{-| -}
|
|
234
|
-
increaseStatusTo : FieldStatus -> FieldStatus -> FieldStatus
|
|
235
|
-
increaseStatusTo increaseTo currentStatus =
|
|
236
|
-
if statusRank increaseTo > statusRank currentStatus then
|
|
237
|
-
increaseTo
|
|
238
|
-
|
|
239
|
-
else
|
|
240
|
-
currentStatus
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
{-| -}
|
|
244
|
-
statusRank : FieldStatus -> Int
|
|
245
|
-
statusRank status =
|
|
246
|
-
case status of
|
|
247
|
-
FieldStatus.NotVisited ->
|
|
248
|
-
0
|
|
249
|
-
|
|
250
|
-
FieldStatus.Focused ->
|
|
251
|
-
1
|
|
252
|
-
|
|
253
|
-
FieldStatus.Changed ->
|
|
254
|
-
2
|
|
255
|
-
|
|
256
|
-
FieldStatus.Blurred ->
|
|
257
|
-
3
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
module Pages.Internal.Form exposing (Response(..), Validation(..), ViewField, unwrapResponse)
|
|
2
|
-
|
|
3
|
-
import Dict exposing (Dict)
|
|
4
|
-
import Form.FieldStatus exposing (FieldStatus)
|
|
5
|
-
import Json.Encode as Encode
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
type Validation error parsed kind field
|
|
9
|
-
= Validation (Maybe (ViewField kind)) (Maybe String) ( Maybe parsed, Dict String (List error) )
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
{-| -}
|
|
13
|
-
type alias ViewField kind =
|
|
14
|
-
{ value : Maybe String
|
|
15
|
-
, status : FieldStatus
|
|
16
|
-
, kind : ( kind, List ( String, Encode.Value ) )
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
{-| -}
|
|
21
|
-
type Response error
|
|
22
|
-
= Response
|
|
23
|
-
{ fields : List ( String, String )
|
|
24
|
-
, errors : Dict String (List error)
|
|
25
|
-
, clientErrors : Dict String (List error)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
unwrapResponse :
|
|
30
|
-
Response error
|
|
31
|
-
->
|
|
32
|
-
{ fields : List ( String, String )
|
|
33
|
-
, errors : Dict String (List error)
|
|
34
|
-
, clientErrors : Dict String (List error)
|
|
35
|
-
}
|
|
36
|
-
unwrapResponse (Response response) =
|
|
37
|
-
response
|