elm-pages 3.0.0-beta.27 → 3.0.0-beta.29
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 +231 -650
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateDataTest.elmo +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/Runner.elm.js +7 -7
- 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/tests/Pages/Review/DeadCodeEliminateDataTest.elm +7 -7
- 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/RouteBuilder.elm +43 -51
- package/generator/src/compatibility-key.js +2 -2
- package/generator/template/app/Route/Index.elm +3 -3
- package/package.json +2 -2
- package/src/Form.elm +178 -306
- package/src/Head.elm +2 -2
- package/src/Pages/Internal/Platform/CompatibilityKey.elm +1 -1
- package/src/Pages/Internal/Platform.elm +2 -2
- package/src/Pages/PageUrl.elm +11 -8
- package/src/PagesMsg.elm +2 -3
- package/src/Path.elm +16 -19
- package/src/QueryParams.elm +17 -158
- package/src/Scaffold/Route.elm +140 -237
- package/src/Server/Request.elm +0 -3
package/src/Head.elm
CHANGED
|
@@ -61,7 +61,7 @@ are using it to populate article metadata like the article's image, publish date
|
|
|
61
61
|
import Head.Seo
|
|
62
62
|
import Path
|
|
63
63
|
import Route exposing (Route)
|
|
64
|
-
import RouteBuilder exposing (
|
|
64
|
+
import RouteBuilder exposing (App, StatelessRoute)
|
|
65
65
|
|
|
66
66
|
type alias RouteParams =
|
|
67
67
|
{ slug : String }
|
|
@@ -81,7 +81,7 @@ are using it to populate article metadata like the article's image, publish date
|
|
|
81
81
|
|> RouteBuilder.buildNoState { view = view }
|
|
82
82
|
|
|
83
83
|
head :
|
|
84
|
-
|
|
84
|
+
App Data ActionData RouteParams
|
|
85
85
|
-> List Head.Tag
|
|
86
86
|
head static =
|
|
87
87
|
let
|
|
@@ -226,7 +226,7 @@ init config flags url key =
|
|
|
226
226
|
, host = url.host
|
|
227
227
|
, port_ = url.port_
|
|
228
228
|
, path = pagePath
|
|
229
|
-
, query = url.query |> Maybe.map QueryParams.fromString
|
|
229
|
+
, query = url.query |> Maybe.map QueryParams.fromString |> Maybe.withDefault Dict.empty
|
|
230
230
|
, fragment = url.fragment
|
|
231
231
|
}
|
|
232
232
|
}
|
|
@@ -829,7 +829,7 @@ update config appMsg model =
|
|
|
829
829
|
, host = model.url.host
|
|
830
830
|
, port_ = model.url.port_
|
|
831
831
|
, path = pagePath
|
|
832
|
-
, query = model.url.query |> Maybe.map QueryParams.fromString
|
|
832
|
+
, query = model.url.query |> Maybe.map QueryParams.fromString |> Maybe.withDefault Dict.empty
|
|
833
833
|
, fragment = model.url.fragment
|
|
834
834
|
}
|
|
835
835
|
}
|
package/src/Pages/PageUrl.elm
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
module Pages.PageUrl exposing (PageUrl, toUrl)
|
|
2
2
|
|
|
3
|
-
{-| Same as a Url in `elm/url`, but slightly more structured. The path portion of the URL is parsed into a
|
|
4
|
-
the query params
|
|
5
|
-
|
|
6
|
-
Because `elm-pages` takes care of the main routing for pages in your app, the standard Elm URL parser API isn't suited
|
|
7
|
-
to parsing query params individually, which is why the structure of these types is different.
|
|
3
|
+
{-| Same as a Url in `elm/url`, but slightly more structured. The path portion of the URL is parsed into a `List String` representing each segment, and
|
|
4
|
+
the query params are parsed into a `Dict String (List String)`.
|
|
8
5
|
|
|
9
6
|
@docs PageUrl, toUrl
|
|
10
7
|
|
|
11
8
|
-}
|
|
12
9
|
|
|
10
|
+
import Dict exposing (Dict)
|
|
13
11
|
import Path exposing (Path)
|
|
14
|
-
import QueryParams
|
|
12
|
+
import QueryParams
|
|
15
13
|
import Url
|
|
16
14
|
|
|
17
15
|
|
|
@@ -21,7 +19,7 @@ type alias PageUrl =
|
|
|
21
19
|
, host : String
|
|
22
20
|
, port_ : Maybe Int
|
|
23
21
|
, path : Path
|
|
24
|
-
, query :
|
|
22
|
+
, query : Dict String (List String)
|
|
25
23
|
, fragment : Maybe String
|
|
26
24
|
}
|
|
27
25
|
|
|
@@ -33,6 +31,11 @@ toUrl url =
|
|
|
33
31
|
, host = url.host
|
|
34
32
|
, port_ = url.port_
|
|
35
33
|
, path = url.path |> Path.toRelative
|
|
36
|
-
, query =
|
|
34
|
+
, query =
|
|
35
|
+
if url.query |> Dict.isEmpty then
|
|
36
|
+
Nothing
|
|
37
|
+
|
|
38
|
+
else
|
|
39
|
+
url.query |> QueryParams.toString |> Just
|
|
37
40
|
, fragment = url.fragment
|
|
38
41
|
}
|
package/src/PagesMsg.elm
CHANGED
|
@@ -40,7 +40,7 @@ type alias PagesMsg userMsg =
|
|
|
40
40
|
Maybe PageUrl
|
|
41
41
|
-> Shared.Model
|
|
42
42
|
-> Model
|
|
43
|
-
->
|
|
43
|
+
-> App Data ActionData RouteParams
|
|
44
44
|
-> View (PagesMsg Msg)
|
|
45
45
|
view maybeUrl sharedModel model app =
|
|
46
46
|
{ title = "My Page"
|
|
@@ -52,9 +52,8 @@ type alias PagesMsg userMsg =
|
|
|
52
52
|
|
|
53
53
|
-- `Form.renderHtml` gives us `Html (PagesMsg msg)`, so we don't need to wrap its Msg type
|
|
54
54
|
, logoutForm
|
|
55
|
-
|> Form.toDynamicTransition "logout"
|
|
56
55
|
|> Form.withOnSubmit (\_ -> NewItemSubmitted)
|
|
57
|
-
|> Form.renderHtml [] (\_ -> Nothing) app Nothing
|
|
56
|
+
|> Form.renderHtml "logout" [] (\_ -> Nothing) app Nothing
|
|
58
57
|
]
|
|
59
58
|
}
|
|
60
59
|
|
package/src/Path.elm
CHANGED
|
@@ -40,20 +40,25 @@ import Pages.Internal.String exposing (chopEnd, chopStart)
|
|
|
40
40
|
|
|
41
41
|
{-| The path portion of the URL, normalized to ensure that path segments are joined with `/`s in the right places (no doubled up or missing slashes).
|
|
42
42
|
-}
|
|
43
|
-
type Path
|
|
44
|
-
|
|
43
|
+
type alias Path =
|
|
44
|
+
List String
|
|
45
45
|
|
|
46
46
|
|
|
47
|
-
{-|
|
|
48
|
-
multi-part path part, like `blog/post-1`.
|
|
47
|
+
{-| Turn a Path to a relative URL.
|
|
49
48
|
-}
|
|
50
|
-
join :
|
|
49
|
+
join : Path -> Path
|
|
51
50
|
join parts =
|
|
52
51
|
parts
|
|
53
52
|
|> List.filter (\segment -> segment /= "/")
|
|
54
53
|
|> List.map normalize
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
{-| Turn a Path to a relative URL.
|
|
57
|
+
-}
|
|
58
|
+
toRelative : Path -> String
|
|
59
|
+
toRelative parts =
|
|
60
|
+
join parts
|
|
55
61
|
|> String.join "/"
|
|
56
|
-
|> Path
|
|
57
62
|
|
|
58
63
|
|
|
59
64
|
{-| Create a Path from a path String.
|
|
@@ -66,28 +71,20 @@ join parts =
|
|
|
66
71
|
fromString : String -> Path
|
|
67
72
|
fromString path =
|
|
68
73
|
path
|
|
69
|
-
|>
|
|
70
|
-
|> Path
|
|
74
|
+
|> toSegments
|
|
71
75
|
|
|
72
76
|
|
|
73
77
|
{-| -}
|
|
74
|
-
toSegments :
|
|
75
|
-
toSegments
|
|
78
|
+
toSegments : String -> List String
|
|
79
|
+
toSegments path =
|
|
76
80
|
path |> String.split "/" |> List.filter ((/=) "")
|
|
77
81
|
|
|
78
82
|
|
|
79
83
|
{-| Turn a Path to an absolute URL (with no trailing slash).
|
|
80
84
|
-}
|
|
81
85
|
toAbsolute : Path -> String
|
|
82
|
-
toAbsolute
|
|
83
|
-
"/" ++ path
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
{-| Turn a Path to a relative URL.
|
|
87
|
-
-}
|
|
88
|
-
toRelative : Path -> String
|
|
89
|
-
toRelative (Path path) =
|
|
90
|
-
path
|
|
86
|
+
toAbsolute path =
|
|
87
|
+
"/" ++ toRelative path
|
|
91
88
|
|
|
92
89
|
|
|
93
90
|
normalize : String -> String
|
package/src/QueryParams.elm
CHANGED
|
@@ -1,178 +1,37 @@
|
|
|
1
1
|
module QueryParams exposing
|
|
2
2
|
( QueryParams
|
|
3
|
-
,
|
|
4
|
-
,
|
|
5
|
-
, map2, oneOf
|
|
6
|
-
, toDict, toString
|
|
3
|
+
, fromString
|
|
4
|
+
, toString
|
|
7
5
|
)
|
|
8
6
|
|
|
9
|
-
{-| Represents the query portion of a URL. You can use `toDict` or `toString` to turn it into basic types, or you can
|
|
10
|
-
parse it into a custom type using the other functions in this module.
|
|
11
|
-
|
|
12
|
-
@docs QueryParams
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
## Parsing
|
|
16
|
-
|
|
17
|
-
@docs Parser
|
|
18
|
-
|
|
19
|
-
@docs andThen, fail, fromResult, fromString, optionalString, parse, string, strings, succeed
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
## Combining
|
|
23
|
-
|
|
24
|
-
@docs map2, oneOf
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
## Accessing as Built-In Types
|
|
28
|
-
|
|
29
|
-
@docs toDict, toString
|
|
30
|
-
|
|
31
|
-
-}
|
|
32
|
-
|
|
33
7
|
import Dict exposing (Dict)
|
|
34
8
|
import Url
|
|
35
9
|
|
|
36
10
|
|
|
37
11
|
{-| -}
|
|
38
|
-
type QueryParams
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
{-| -}
|
|
43
|
-
type Parser a
|
|
44
|
-
= Parser (Dict String (List String) -> Result String a)
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
{-| -}
|
|
48
|
-
succeed : a -> Parser a
|
|
49
|
-
succeed value =
|
|
50
|
-
Parser (\_ -> Ok value)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
{-| -}
|
|
54
|
-
fail : String -> Parser a
|
|
55
|
-
fail errorMessage =
|
|
56
|
-
Parser (\_ -> Err errorMessage)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
{-| -}
|
|
60
|
-
fromResult : Result String a -> Parser a
|
|
61
|
-
fromResult result =
|
|
62
|
-
Parser (\_ -> result)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
{-| -}
|
|
66
|
-
andThen : (a -> Parser b) -> Parser a -> Parser b
|
|
67
|
-
andThen andThenFn (Parser parser) =
|
|
68
|
-
Parser
|
|
69
|
-
(\dict ->
|
|
70
|
-
case Result.map andThenFn (parser dict) of
|
|
71
|
-
Ok (Parser result) ->
|
|
72
|
-
result dict
|
|
73
|
-
|
|
74
|
-
Err error ->
|
|
75
|
-
Err error
|
|
76
|
-
)
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
{-| -}
|
|
80
|
-
oneOf : List (Parser a) -> Parser a
|
|
81
|
-
oneOf parsers =
|
|
82
|
-
Parser
|
|
83
|
-
(tryParser parsers)
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
{-| -}
|
|
87
|
-
tryParser : List (Parser a) -> Dict String (List String) -> Result String a
|
|
88
|
-
tryParser parsers dict =
|
|
89
|
-
case parsers of
|
|
90
|
-
[] ->
|
|
91
|
-
Err ""
|
|
92
|
-
|
|
93
|
-
(Parser nextParser) :: otherParsers ->
|
|
94
|
-
case nextParser dict of
|
|
95
|
-
Ok okValue ->
|
|
96
|
-
Ok okValue
|
|
97
|
-
|
|
98
|
-
Err _ ->
|
|
99
|
-
tryParser otherParsers dict
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
{-| -}
|
|
103
|
-
map2 : (a -> b -> combined) -> Parser a -> Parser b -> Parser combined
|
|
104
|
-
map2 func (Parser a) (Parser b) =
|
|
105
|
-
Parser <|
|
|
106
|
-
\dict ->
|
|
107
|
-
Result.map2 func (a dict) (b dict)
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
{-| -}
|
|
111
|
-
optionalString : String -> Parser (Maybe String)
|
|
112
|
-
optionalString key =
|
|
113
|
-
custom key
|
|
114
|
-
(\stringList ->
|
|
115
|
-
case stringList of
|
|
116
|
-
str :: _ ->
|
|
117
|
-
Ok (Just str)
|
|
118
|
-
|
|
119
|
-
_ ->
|
|
120
|
-
Ok Nothing
|
|
121
|
-
)
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
{-| -}
|
|
125
|
-
string : String -> Parser String
|
|
126
|
-
string key =
|
|
127
|
-
custom key
|
|
128
|
-
(\stringList ->
|
|
129
|
-
case stringList of
|
|
130
|
-
[ str ] ->
|
|
131
|
-
Ok str
|
|
132
|
-
|
|
133
|
-
_ ->
|
|
134
|
-
Err ("Missing key " ++ key)
|
|
135
|
-
)
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
{-| -}
|
|
139
|
-
custom : String -> (List String -> Result String a) -> Parser a
|
|
140
|
-
custom key customFn =
|
|
141
|
-
Parser <|
|
|
142
|
-
\dict ->
|
|
143
|
-
customFn (Maybe.withDefault [] (Dict.get key dict))
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
{-| -}
|
|
147
|
-
strings : String -> Parser (List String)
|
|
148
|
-
strings key =
|
|
149
|
-
custom key
|
|
150
|
-
(\stringList -> Ok stringList)
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
{-| -}
|
|
154
|
-
fromString : String -> QueryParams
|
|
155
|
-
fromString =
|
|
156
|
-
QueryParams
|
|
12
|
+
type alias QueryParams =
|
|
13
|
+
Dict String (List String)
|
|
157
14
|
|
|
158
15
|
|
|
159
16
|
{-| -}
|
|
160
17
|
toString : QueryParams -> String
|
|
161
|
-
toString
|
|
162
|
-
queryParams
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
{-| -}
|
|
166
|
-
parse : Parser a -> QueryParams -> Result String a
|
|
167
|
-
parse (Parser queryParser) queryParams =
|
|
18
|
+
toString queryParams =
|
|
168
19
|
queryParams
|
|
169
|
-
|>
|
|
170
|
-
|>
|
|
20
|
+
|> Dict.toList
|
|
21
|
+
|> List.concatMap
|
|
22
|
+
(\( key, values ) ->
|
|
23
|
+
values
|
|
24
|
+
|> List.map
|
|
25
|
+
(\value ->
|
|
26
|
+
key ++ "=" ++ value
|
|
27
|
+
)
|
|
28
|
+
)
|
|
29
|
+
|> String.join "&"
|
|
171
30
|
|
|
172
31
|
|
|
173
32
|
{-| -}
|
|
174
|
-
|
|
175
|
-
|
|
33
|
+
fromString : String -> Dict String (List String)
|
|
34
|
+
fromString queryParams =
|
|
176
35
|
prepareQuery (Just queryParams)
|
|
177
36
|
|
|
178
37
|
|