elm-pages 3.0.0-beta.26 → 3.0.0-beta.27

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/src/Form.elm CHANGED
@@ -282,8 +282,9 @@ import Html.Styled.Attributes as StyledAttr
282
282
  import Html.Styled.Lazy
283
283
  import Pages.FormState as Form exposing (FormState)
284
284
  import Pages.Internal.Form exposing (Validation(..), unwrapResponse)
285
- import Pages.Msg
285
+ import Pages.Internal.Msg
286
286
  import Pages.Transition exposing (Transition(..))
287
+ import PagesMsg exposing (PagesMsg)
287
288
  import Path exposing (Path)
288
289
 
289
290
 
@@ -980,7 +981,7 @@ runOneOfServerSideHelp rawFormData firstFoundErrors (ServerForms parsers) =
980
981
 
981
982
  {-| -}
982
983
  renderHtml :
983
- List (Html.Attribute (Pages.Msg.Msg msg))
984
+ List (Html.Attribute (PagesMsg msg))
984
985
  -> (actionData -> Maybe (Response error))
985
986
  -> AppContext app actionData
986
987
  -> data
@@ -990,10 +991,10 @@ renderHtml :
990
991
  (Form.Validation.Validation error parsed named constraints)
991
992
  data
992
993
  (Context error data
993
- -> List (Html (Pages.Msg.Msg msg))
994
+ -> List (Html (PagesMsg msg))
994
995
  )
995
996
  msg
996
- -> Html (Pages.Msg.Msg msg)
997
+ -> Html (PagesMsg msg)
997
998
  renderHtml attrs accessResponse app data (FinalForm options a b c) =
998
999
  Html.Lazy.lazy6 renderHelper attrs accessResponse options app data (FormInternal a b c)
999
1000
 
@@ -1177,7 +1178,7 @@ withOnSubmit onSubmit (FinalForm options a b c) =
1177
1178
 
1178
1179
  {-| -}
1179
1180
  renderStyledHtml :
1180
- List (Html.Styled.Attribute (Pages.Msg.Msg msg))
1181
+ List (Html.Styled.Attribute (PagesMsg msg))
1181
1182
  -> (actionData -> Maybe (Response error))
1182
1183
  -> AppContext app actionData
1183
1184
  -> data
@@ -1187,10 +1188,10 @@ renderStyledHtml :
1187
1188
  (Form.Validation.Validation error parsed named constraints)
1188
1189
  data
1189
1190
  (Context error data
1190
- -> List (Html.Styled.Html (Pages.Msg.Msg msg))
1191
+ -> List (Html.Styled.Html (PagesMsg msg))
1191
1192
  )
1192
1193
  msg
1193
- -> Html.Styled.Html (Pages.Msg.Msg msg)
1194
+ -> Html.Styled.Html (PagesMsg msg)
1194
1195
  renderStyledHtml attrs accessResponse app data (FinalForm options a b c) =
1195
1196
  Html.Styled.Lazy.lazy6 renderStyledHelper attrs accessResponse options app data (FormInternal a b c)
1196
1197
 
@@ -1201,13 +1202,13 @@ type alias Response error =
1201
1202
 
1202
1203
 
1203
1204
  renderHelper :
1204
- List (Html.Attribute (Pages.Msg.Msg msg))
1205
+ List (Html.Attribute (PagesMsg msg))
1205
1206
  -> (actionData -> Maybe (Response error))
1206
1207
  -> RenderOptions msg
1207
1208
  -> AppContext app actionData
1208
1209
  -> data
1209
- -> FormInternal error (Form.Validation.Validation error parsed named constraints) data (Context error data -> List (Html (Pages.Msg.Msg msg)))
1210
- -> Html (Pages.Msg.Msg msg)
1210
+ -> FormInternal error (Form.Validation.Validation error parsed named constraints) data (Context error data -> List (Html (PagesMsg msg)))
1211
+ -> Html (PagesMsg msg)
1211
1212
  renderHelper attrs accessResponse options formState data form =
1212
1213
  -- TODO Get transition context from `app` so you can check if the current form is being submitted
1213
1214
  -- TODO either as a transition or a fetcher? Should be easy enough to check for the `id` on either of those?
@@ -1215,7 +1216,7 @@ renderHelper attrs accessResponse options formState data form =
1215
1216
  { formId, hiddenInputs, children, isValid } =
1216
1217
  helperValues toHiddenInput accessResponse options formState data form
1217
1218
 
1218
- toHiddenInput : List (Html.Attribute (Pages.Msg.Msg msg)) -> Html (Pages.Msg.Msg msg)
1219
+ toHiddenInput : List (Html.Attribute (PagesMsg msg)) -> Html (PagesMsg msg)
1219
1220
  toHiddenInput hiddenAttrs =
1220
1221
  Html.input hiddenAttrs []
1221
1222
  in
@@ -1228,10 +1229,10 @@ renderHelper attrs accessResponse options formState data form =
1228
1229
  , Attr.action (Path.toAbsolute formState.path)
1229
1230
  , case options.submitStrategy of
1230
1231
  FetcherStrategy ->
1231
- Pages.Msg.fetcherOnSubmit options.onSubmit formId (\_ -> isValid)
1232
+ Pages.Internal.Msg.fetcherOnSubmit options.onSubmit formId (\_ -> isValid)
1232
1233
 
1233
1234
  TransitionStrategy ->
1234
- Pages.Msg.submitIfValid formId (\_ -> isValid)
1235
+ Pages.Internal.Msg.submitIfValid options.onSubmit formId (\_ -> isValid)
1235
1236
  ]
1236
1237
  ++ attrs
1237
1238
  )
@@ -1239,13 +1240,13 @@ renderHelper attrs accessResponse options formState data form =
1239
1240
 
1240
1241
 
1241
1242
  renderStyledHelper :
1242
- List (Html.Styled.Attribute (Pages.Msg.Msg msg))
1243
+ List (Html.Styled.Attribute (PagesMsg msg))
1243
1244
  -> (actionData -> Maybe (Response error))
1244
1245
  -> RenderOptions msg
1245
1246
  -> AppContext app actionData
1246
1247
  -> data
1247
- -> FormInternal error (Form.Validation.Validation error parsed named constraints) data (Context error data -> List (Html.Styled.Html (Pages.Msg.Msg msg)))
1248
- -> Html.Styled.Html (Pages.Msg.Msg msg)
1248
+ -> FormInternal error (Form.Validation.Validation error parsed named constraints) data (Context error data -> List (Html.Styled.Html (PagesMsg msg)))
1249
+ -> Html.Styled.Html (PagesMsg msg)
1249
1250
  renderStyledHelper attrs accessResponse options formState data form =
1250
1251
  -- TODO Get transition context from `app` so you can check if the current form is being submitted
1251
1252
  -- TODO either as a transition or a fetcher? Should be easy enough to check for the `id` on either of those?
@@ -1253,7 +1254,7 @@ renderStyledHelper attrs accessResponse options formState data form =
1253
1254
  { formId, hiddenInputs, children, isValid } =
1254
1255
  helperValues toHiddenInput accessResponse options formState data form
1255
1256
 
1256
- toHiddenInput : List (Html.Attribute (Pages.Msg.Msg msg)) -> Html.Styled.Html (Pages.Msg.Msg msg)
1257
+ toHiddenInput : List (Html.Attribute (PagesMsg msg)) -> Html.Styled.Html (PagesMsg msg)
1257
1258
  toHiddenInput hiddenAttrs =
1258
1259
  Html.Styled.input (hiddenAttrs |> List.map StyledAttr.fromUnstyled) []
1259
1260
  in
@@ -1265,11 +1266,11 @@ renderStyledHelper attrs accessResponse options formState data form =
1265
1266
  , case options.submitStrategy of
1266
1267
  FetcherStrategy ->
1267
1268
  StyledAttr.fromUnstyled <|
1268
- Pages.Msg.fetcherOnSubmit options.onSubmit formId (\_ -> isValid)
1269
+ Pages.Internal.Msg.fetcherOnSubmit options.onSubmit formId (\_ -> isValid)
1269
1270
 
1270
1271
  TransitionStrategy ->
1271
1272
  StyledAttr.fromUnstyled <|
1272
- Pages.Msg.submitIfValid formId (\_ -> isValid)
1273
+ Pages.Internal.Msg.submitIfValid options.onSubmit formId (\_ -> isValid)
1273
1274
  ]
1274
1275
  ++ attrs
1275
1276
  )
@@ -1277,7 +1278,7 @@ renderStyledHelper attrs accessResponse options formState data form =
1277
1278
 
1278
1279
 
1279
1280
  helperValues :
1280
- (List (Html.Attribute (Pages.Msg.Msg msg)) -> view)
1281
+ (List (Html.Attribute (PagesMsg msg)) -> view)
1281
1282
  -> (actionData -> Maybe (Response error))
1282
1283
  -> RenderOptions msg
1283
1284
  -> AppContext app actionData
@@ -1476,7 +1477,7 @@ type alias HtmlForm error parsed input msg =
1476
1477
  Form
1477
1478
  error
1478
1479
  { combine : Combined error parsed
1479
- , view : Context error input -> List (Html (Pages.Msg.Msg msg))
1480
+ , view : Context error input -> List (Html (PagesMsg msg))
1480
1481
  }
1481
1482
  input
1482
1483
 
@@ -1600,7 +1601,7 @@ type alias StyledHtmlForm error parsed data msg =
1600
1601
  Form
1601
1602
  error
1602
1603
  { combine : Combined error parsed
1603
- , view : Context error data -> List (Html.Styled.Html (Pages.Msg.Msg msg))
1604
+ , view : Context error data -> List (Html.Styled.Html (PagesMsg msg))
1604
1605
  }
1605
1606
  data
1606
1607
 
@@ -12,15 +12,16 @@ import Html exposing (Attribute)
12
12
  import Html.Attributes as Attr
13
13
  import Html.Events
14
14
  import Json.Decode as Decode exposing (Decoder)
15
- import Pages.Msg
15
+ import Pages.Internal.Msg
16
+ import PagesMsg exposing (PagesMsg)
16
17
 
17
18
 
18
19
  {-| -}
19
- listeners : String -> List (Attribute (Pages.Msg.Msg userMsg))
20
+ listeners : String -> List (Attribute (PagesMsg userMsg))
20
21
  listeners formId =
21
- [ Html.Events.on "focusin" (Decode.value |> Decode.map Pages.Msg.FormFieldEvent)
22
- , Html.Events.on "focusout" (Decode.value |> Decode.map Pages.Msg.FormFieldEvent)
23
- , Html.Events.on "input" (Decode.value |> Decode.map Pages.Msg.FormFieldEvent)
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)
24
25
  , Attr.id formId
25
26
  ]
26
27
 
@@ -1,16 +1,11 @@
1
- module Pages.Msg exposing
1
+ module Pages.Internal.Msg exposing
2
2
  ( Msg(..)
3
- , map, onSubmit, fetcherOnSubmit, submitIfValid
3
+ , fetcherOnSubmit
4
+ , map
5
+ , onSubmit
6
+ , submitIfValid
4
7
  )
5
8
 
6
- {-|
7
-
8
- @docs Msg
9
-
10
- @docs map, onSubmit, fetcherOnSubmit, submitIfValid
11
-
12
- -}
13
-
14
9
  import Form.FormData exposing (FormData)
15
10
  import FormDecoder
16
11
  import Html exposing (Attribute)
@@ -22,9 +17,10 @@ import Json.Decode
22
17
  type Msg userMsg
23
18
  = UserMsg userMsg
24
19
  | Submit FormData
25
- | SubmitIfValid String FormData Bool
20
+ | SubmitIfValid String FormData Bool (Maybe userMsg)
26
21
  | SubmitFetcher String FormData Bool (Maybe userMsg)
27
22
  | FormFieldEvent Json.Decode.Value
23
+ | NoOp
28
24
 
29
25
 
30
26
  {-| -}
@@ -35,10 +31,21 @@ onSubmit =
35
31
 
36
32
 
37
33
  {-| -}
38
- submitIfValid : String -> (List ( String, String ) -> Bool) -> Attribute (Msg userMsg)
39
- submitIfValid formId isValid =
34
+ submitIfValid : Maybe ({ fields : List ( String, String ) } -> userMsg) -> String -> (List ( String, String ) -> Bool) -> Attribute (Msg userMsg)
35
+ submitIfValid userMsg formId isValid =
40
36
  FormDecoder.formDataOnSubmit
41
- |> Attr.map (\formData -> SubmitIfValid formId formData (isValid formData.fields))
37
+ |> Attr.map
38
+ (\formData ->
39
+ SubmitIfValid formId
40
+ formData
41
+ (isValid formData.fields)
42
+ (userMsg
43
+ |> Maybe.map
44
+ (\toUserMsg ->
45
+ toUserMsg { fields = formData.fields }
46
+ )
47
+ )
48
+ )
42
49
 
43
50
 
44
51
  {-| -}
@@ -69,11 +76,14 @@ map mapFn msg =
69
76
  Submit info ->
70
77
  Submit info
71
78
 
72
- SubmitIfValid formId info isValid ->
73
- SubmitIfValid formId info isValid
79
+ SubmitIfValid formId info isValid toUserMsg ->
80
+ SubmitIfValid formId info isValid (Maybe.map mapFn toUserMsg)
74
81
 
75
82
  SubmitFetcher formId info isValid toUserMsg ->
76
83
  SubmitFetcher formId info isValid (Maybe.map mapFn toUserMsg)
77
84
 
78
85
  FormFieldEvent value ->
79
86
  FormFieldEvent value
87
+
88
+ NoOp ->
89
+ NoOp
@@ -27,10 +27,10 @@ import Pages.Internal.Platform.Effect as Effect exposing (Effect)
27
27
  import Pages.Internal.Platform.StaticResponses as StaticResponses
28
28
  import Pages.Internal.Platform.ToJsPayload as ToJsPayload
29
29
  import Pages.Internal.ResponseSketch as ResponseSketch
30
- import Pages.Msg
31
30
  import Pages.ProgramConfig exposing (ProgramConfig)
32
31
  import Pages.SiteConfig exposing (SiteConfig)
33
32
  import Pages.StaticHttp.Request
33
+ import PagesMsg exposing (PagesMsg)
34
34
  import Path exposing (Path)
35
35
  import RenderRequest exposing (RenderRequest)
36
36
  import RequestsAndPending exposing (RequestsAndPending)
@@ -503,7 +503,7 @@ initLegacy site ((RenderRequest.SinglePage includeHtml singleRequest _) as rende
503
503
  )
504
504
  |> Tuple.first
505
505
 
506
- viewValue : { title : String, body : List (Html (Pages.Msg.Msg userMsg)) }
506
+ viewValue : { title : String, body : List (Html (PagesMsg userMsg)) }
507
507
  viewValue =
508
508
  (config.view Dict.empty Dict.empty Nothing currentPage Nothing sharedData pageData_ maybeActionData |> .view) pageModel
509
509
 
@@ -550,7 +550,7 @@ initLegacy site ((RenderRequest.SinglePage includeHtml singleRequest _) as rende
550
550
  )
551
551
  |> (\( actionHeaders, byteEncodedPageData ) ->
552
552
  let
553
- rendered : { view : userModel -> { title : String, body : List (Html (Pages.Msg.Msg userMsg)) }, head : List Tag }
553
+ rendered : { view : userModel -> { title : String, body : List (Html (PagesMsg userMsg)) }, head : List Tag }
554
554
  rendered =
555
555
  config.view Dict.empty Dict.empty Nothing currentPage Nothing sharedData pageData_ maybeActionData
556
556
  in
@@ -641,7 +641,7 @@ initLegacy site ((RenderRequest.SinglePage includeHtml singleRequest _) as rende
641
641
  pageData2 =
642
642
  config.errorPageToData error
643
643
 
644
- viewValue : { title : String, body : List (Html (Pages.Msg.Msg userMsg)) }
644
+ viewValue : { title : String, body : List (Html (PagesMsg userMsg)) }
645
645
  viewValue =
646
646
  (config.view Dict.empty Dict.empty Nothing currentPage Nothing sharedData pageData2 Nothing |> .view) pageModel
647
647
  in
@@ -854,7 +854,7 @@ render404Page config sharedData isDevServer path notFoundReason =
854
854
  pathAndRoute =
855
855
  { path = path, route = config.notFoundRoute }
856
856
 
857
- viewValue : { title : String, body : List (Html (Pages.Msg.Msg userMsg)) }
857
+ viewValue : { title : String, body : List (Html (PagesMsg userMsg)) }
858
858
  viewValue =
859
859
  (config.view Dict.empty
860
860
  Dict.empty
@@ -3,4 +3,4 @@ module Pages.Internal.Platform.CompatibilityKey exposing (currentCompatibilityKe
3
3
 
4
4
  currentCompatibilityKey : Int
5
5
  currentCompatibilityKey =
6
- 10
6
+ 11
@@ -31,13 +31,14 @@ import Pages.ContentCache as ContentCache
31
31
  import Pages.Fetcher
32
32
  import Pages.Flags
33
33
  import Pages.FormState
34
+ import Pages.Internal.Msg
34
35
  import Pages.Internal.NotFoundReason exposing (NotFoundReason)
35
36
  import Pages.Internal.ResponseSketch as ResponseSketch exposing (ResponseSketch)
36
37
  import Pages.Internal.String as String
37
- import Pages.Msg
38
38
  import Pages.ProgramConfig exposing (ProgramConfig)
39
39
  import Pages.StaticHttpRequest as StaticHttpRequest
40
40
  import Pages.Transition
41
+ import PagesMsg exposing (PagesMsg)
41
42
  import Path exposing (Path)
42
43
  import QueryParams
43
44
  import Task
@@ -53,7 +54,7 @@ type alias Program userModel userMsg pageData actionData sharedData errorPage =
53
54
  mainView :
54
55
  ProgramConfig userMsg userModel route pageData actionData sharedData effect (Msg userMsg pageData actionData sharedData errorPage) errorPage
55
56
  -> Model userModel pageData actionData sharedData
56
- -> { title : String, body : List (Html (Pages.Msg.Msg userMsg)) }
57
+ -> { title : String, body : List (Html (PagesMsg userMsg)) }
57
58
  mainView config model =
58
59
  case model.notFound of
59
60
  Just info ->
@@ -308,7 +309,7 @@ init config flags url key =
308
309
  type Msg userMsg pageData actionData sharedData errorPage
309
310
  = LinkClicked Browser.UrlRequest
310
311
  | UrlChanged Url
311
- | UserMsg (Pages.Msg.Msg userMsg)
312
+ | UserMsg (PagesMsg userMsg)
312
313
  | SetField { formId : String, name : String, value : String }
313
314
  | UpdateCacheAndUrlNew Bool Url (Maybe userMsg) (Result Http.Error ( Url, ResponseSketch pageData actionData sharedData ))
314
315
  | FetcherComplete Bool String Int (Result Http.Error ( Maybe userMsg, ActionDataOrRedirect actionData ))
@@ -491,11 +492,11 @@ update config appMsg model =
491
492
 
492
493
  UserMsg userMsg_ ->
493
494
  case userMsg_ of
494
- Pages.Msg.UserMsg userMsg ->
495
+ Pages.Internal.Msg.UserMsg userMsg ->
495
496
  ( model, NoEffect )
496
497
  |> performUserMsg userMsg config
497
498
 
498
- Pages.Msg.Submit fields ->
499
+ Pages.Internal.Msg.Submit fields ->
499
500
  ( { model
500
501
  | transition =
501
502
  Just
@@ -507,7 +508,7 @@ update config appMsg model =
507
508
  , Submit fields
508
509
  )
509
510
 
510
- Pages.Msg.SubmitIfValid formId fields isValid ->
511
+ Pages.Internal.Msg.SubmitIfValid formId fields isValid maybeUserMsg ->
511
512
  if isValid then
512
513
  ( { model
513
514
  -- TODO should I setSubmitAttempted here, too?
@@ -520,6 +521,13 @@ update config appMsg model =
520
521
  }
521
522
  , Submit fields
522
523
  )
524
+ |> (case maybeUserMsg of
525
+ Just justUserMsg ->
526
+ performUserMsg justUserMsg config
527
+
528
+ Nothing ->
529
+ identity
530
+ )
523
531
 
524
532
  else
525
533
  ( { model
@@ -530,7 +538,7 @@ update config appMsg model =
530
538
  , NoEffect
531
539
  )
532
540
 
533
- Pages.Msg.SubmitFetcher fetcherKey fields isValid maybeUserMsg ->
541
+ Pages.Internal.Msg.SubmitFetcher fetcherKey fields isValid maybeUserMsg ->
534
542
  if isValid then
535
543
  -- TODO should I setSubmitAttempted here, too?
536
544
  ( { model | nextTransitionKey = model.nextTransitionKey + 1 }
@@ -553,12 +561,15 @@ update config appMsg model =
553
561
  , NoEffect
554
562
  )
555
563
 
556
- Pages.Msg.FormFieldEvent value ->
564
+ Pages.Internal.Msg.FormFieldEvent value ->
557
565
  -- TODO when init is called for a new page, also need to clear out client-side `pageFormState`
558
566
  ( { model | pageFormState = Pages.FormState.update value model.pageFormState }
559
567
  , NoEffect
560
568
  )
561
569
 
570
+ Pages.Internal.Msg.NoOp ->
571
+ ( model, NoEffect )
572
+
562
573
  UpdateCacheAndUrlNew scrollToTopWhenDone urlWithoutRedirectResolution maybeUserMsg updateResult ->
563
574
  -- TODO remove all fetchers that are in the state `FetcherReloading` here -- I think that's the right logic?
564
575
  case
@@ -977,7 +988,7 @@ perform config model effect =
977
988
  -- TODO need to get the fetcherId here
978
989
  -- TODO need to increment and pass in the transitionId
979
990
  startFetcher "TODO" -1 options model
980
- , fromPageMsg = Pages.Msg.UserMsg >> UserMsg
991
+ , fromPageMsg = Pages.Internal.Msg.UserMsg >> UserMsg
981
992
  , key = key
982
993
  , setField = \info -> Task.succeed (SetField info) |> Task.perform identity
983
994
  }
@@ -1088,6 +1099,7 @@ startFetcher2 config fromPageReload fetcherKey transitionId formData model =
1088
1099
  decodedAction : ActionDataOrRedirect actionData
1089
1100
  decodedAction =
1090
1101
  case Bytes.Decode.decode config.decodeResponse bytesBody of
1102
+ -- @@@
1091
1103
  Just (ResponseSketch.Redirect redirectTo) ->
1092
1104
  RedirectResponse redirectTo
1093
1105
 
@@ -1205,7 +1217,7 @@ application config =
1205
1217
  [ config.subscriptions (model.url |> config.urlToRoute)
1206
1218
  (urls.currentUrl |> config.urlToRoute |> config.routeToPath |> Path.join)
1207
1219
  pageData.userModel
1208
- |> Sub.map (Pages.Msg.UserMsg >> UserMsg)
1220
+ |> Sub.map (Pages.Internal.Msg.UserMsg >> UserMsg)
1209
1221
  , config.hotReloadData
1210
1222
  |> Sub.map HotReloadCompleteNew
1211
1223
  ]
@@ -22,10 +22,10 @@ import Pages.Internal.NotFoundReason exposing (NotFoundReason)
22
22
  import Pages.Internal.Platform.ToJsPayload
23
23
  import Pages.Internal.ResponseSketch exposing (ResponseSketch)
24
24
  import Pages.Internal.RoutePattern exposing (RoutePattern)
25
- import Pages.Msg
26
25
  import Pages.PageUrl exposing (PageUrl)
27
26
  import Pages.SiteConfig exposing (SiteConfig)
28
27
  import Pages.Transition
28
+ import PagesMsg exposing (PagesMsg)
29
29
  import Path exposing (Path)
30
30
  import Url exposing (Url)
31
31
 
@@ -66,7 +66,7 @@ type alias ProgramConfig userMsg userModel route pageData actionData sharedData
66
66
  -> pageData
67
67
  -> Maybe actionData
68
68
  ->
69
- { view : userModel -> { title : String, body : List (Html (Pages.Msg.Msg userMsg)) }
69
+ { view : userModel -> { title : String, body : List (Html (PagesMsg userMsg)) }
70
70
  , head : List Head.Tag
71
71
  }
72
72
  , handleRoute : route -> BackendTask FatalError (Maybe NotFoundReason)
@@ -0,0 +1,93 @@
1
+ module PagesMsg exposing
2
+ ( PagesMsg
3
+ , fromMsg
4
+ , map, noOp
5
+ , onSubmit
6
+ )
7
+
8
+ {-| In `elm-pages`, Route modules have their own `Msg` type which can be used like a normal TEA (The Elm Architecture) app.
9
+ But the `Msg` defined in a `Route` module is wrapped in the `PagesMsg` type.
10
+
11
+ @docs PagesMsg
12
+
13
+ You can wrap your Route Module's `Msg` using `fromMsg`.
14
+
15
+ @docs fromMsg
16
+
17
+ @docs map, noOp
18
+
19
+ @docs onSubmit
20
+
21
+ -}
22
+
23
+ import Html exposing (Attribute)
24
+ import Pages.Internal.Msg
25
+
26
+
27
+ {-| -}
28
+ type alias PagesMsg userMsg =
29
+ Pages.Internal.Msg.Msg userMsg
30
+
31
+
32
+ {-|
33
+
34
+ import PagesMsg exposing (PagesMsg)
35
+
36
+ type Msg
37
+ = ToggleMenu
38
+
39
+ view :
40
+ Maybe PageUrl
41
+ -> Shared.Model
42
+ -> Model
43
+ -> StaticPayload Data ActionData RouteParams
44
+ -> View (PagesMsg Msg)
45
+ view maybeUrl sharedModel model app =
46
+ { title = "My Page"
47
+ , view =
48
+ [ button
49
+ -- we need to wrap our Route module's `Msg` here so we have a `PagesMsg Msg`
50
+ [ onClick (PagesMsg.fromMsg ToggleMenu) ]
51
+ []
52
+
53
+ -- `Form.renderHtml` gives us `Html (PagesMsg msg)`, so we don't need to wrap its Msg type
54
+ , logoutForm
55
+ |> Form.toDynamicTransition "logout"
56
+ |> Form.withOnSubmit (\_ -> NewItemSubmitted)
57
+ |> Form.renderHtml [] (\_ -> Nothing) app Nothing
58
+ ]
59
+ }
60
+
61
+ -}
62
+ fromMsg : userMsg -> PagesMsg userMsg
63
+ fromMsg userMsg =
64
+ Pages.Internal.Msg.UserMsg userMsg
65
+
66
+
67
+ {-| A Msg that is handled by the elm-pages framework and does nothing. Helpful for when you don't want to register a callback.
68
+
69
+ import Browser.Dom as Dom
70
+ import PagesMsg exposing (PagesMsg)
71
+ import Task
72
+
73
+ resetViewport : Cmd (PagesMsg msg)
74
+ resetViewport =
75
+ Dom.setViewport 0 0
76
+ |> Task.perform (\() -> PagesMsg.noOp)
77
+
78
+ -}
79
+ noOp : PagesMsg userMsg
80
+ noOp =
81
+ Pages.Internal.Msg.NoOp
82
+
83
+
84
+ {-| -}
85
+ map : (a -> b) -> PagesMsg a -> PagesMsg b
86
+ map mapFn msg =
87
+ Pages.Internal.Msg.map mapFn msg
88
+
89
+
90
+ {-| -}
91
+ onSubmit : Attribute (PagesMsg userMsg)
92
+ onSubmit =
93
+ Pages.Internal.Msg.onSubmit