mirror of
https://github.com/Orasund/elm-ui-widgets.git
synced 2024-09-11 14:35:37 +03:00
Merge pull request #79 from orus-io/explorer-relative-url-in-flags
Explorer settings & config improvements
This commit is contained in:
commit
ff91ad1f0d
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,3 +2,5 @@
|
||||
elm-stuff
|
||||
# elm-repl generated files
|
||||
repl-temp-*
|
||||
# elm-live && build generated file
|
||||
explorer/main.js
|
||||
|
3
build-doc.sh
Normal file
3
build-doc.sh
Normal file
@ -0,0 +1,3 @@
|
||||
(cd explorer && elm make src/Main.elm --optimize --output main.js) &&
|
||||
cp explorer/main.js docs/ &&
|
||||
cp explorer/main.js docs/3.0.0
|
@ -1,50 +1,25 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Main</title>
|
||||
<script src="main.js"></script>
|
||||
<style>
|
||||
body {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
<meta charset="UTF-8">
|
||||
<title>Main</title>
|
||||
<style>body { padding: 0; margin: 0; }</style>
|
||||
<script src="/3.0.0/main.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="elm"></div>
|
||||
|
||||
<!-- Start Single Page Apps for GitHub Pages -->
|
||||
<script type="text/javascript">
|
||||
// Single Page Apps for GitHub Pages
|
||||
// MIT License
|
||||
// https://github.com/rafgraph/spa-github-pages
|
||||
// This script checks to see if a redirect is present in the query string,
|
||||
// converts it back into the correct url and adds it to the
|
||||
// browser's history using window.history.replaceState(...),
|
||||
// which won't cause the browser to attempt to load the new url.
|
||||
// When the single page app is loaded further down in this file,
|
||||
// the correct url will be waiting in the browser's history for
|
||||
// the single page app to route accordingly.
|
||||
(function (l) {
|
||||
if (l.search[1] === '/') {
|
||||
var decoded = l.search.slice(1).split('&').map(function (s) {
|
||||
return s.replace(/~and~/g, '&')
|
||||
}).join('?');
|
||||
window.history.replaceState(null, null,
|
||||
l.pathname.slice(0, -1) + decoded + l.hash
|
||||
);
|
||||
}
|
||||
}(window.location))
|
||||
</script>
|
||||
<!-- End Single Page Apps for GitHub Pages -->
|
||||
|
||||
<script>
|
||||
var app = Elm.Main.init({
|
||||
node: document.getElementById('elm')
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
(function(){
|
||||
var settings = localStorage.getItem("settings");
|
||||
const app = Elm.Main.init({
|
||||
flags: {
|
||||
settings: settings,
|
||||
config: { relativeUrlPath: ["elm-ui-widgets", "3.0.0"] }
|
||||
}
|
||||
});
|
||||
app.ports.saveSettings.subscribe(function(settings){
|
||||
localStorage.setItem("settings", settings);
|
||||
});
|
||||
}());
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
|
8062
docs/3.0.0/main.js
8062
docs/3.0.0/main.js
File diff suppressed because it is too large
Load Diff
@ -1,50 +1,26 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Main</title>
|
||||
<script src="main.js"></script>
|
||||
<style>
|
||||
body {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
<meta charset="UTF-8">
|
||||
<title>Main</title>
|
||||
<style>body { padding: 0; margin: 0; }</style>
|
||||
<script src="/main.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="elm"></div>
|
||||
|
||||
<!-- Start Single Page Apps for GitHub Pages -->
|
||||
<script type="text/javascript">
|
||||
// Single Page Apps for GitHub Pages
|
||||
// MIT License
|
||||
// https://github.com/rafgraph/spa-github-pages
|
||||
// This script checks to see if a redirect is present in the query string,
|
||||
// converts it back into the correct url and adds it to the
|
||||
// browser's history using window.history.replaceState(...),
|
||||
// which won't cause the browser to attempt to load the new url.
|
||||
// When the single page app is loaded further down in this file,
|
||||
// the correct url will be waiting in the browser's history for
|
||||
// the single page app to route accordingly.
|
||||
(function (l) {
|
||||
if (l.search[1] === '/') {
|
||||
var decoded = l.search.slice(1).split('&').map(function (s) {
|
||||
return s.replace(/~and~/g, '&')
|
||||
}).join('?');
|
||||
window.history.replaceState(null, null,
|
||||
l.pathname.slice(0, -1) + decoded + l.hash
|
||||
);
|
||||
}
|
||||
}(window.location))
|
||||
</script>
|
||||
<!-- End Single Page Apps for GitHub Pages -->
|
||||
|
||||
<script>
|
||||
var app = Elm.Main.init({
|
||||
node: document.getElementById('elm')
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
(function(){
|
||||
var settings = localStorage.getItem("settings");
|
||||
const app = Elm.Main.init({
|
||||
flags: {
|
||||
settings: settings,
|
||||
config: { relativeUrlPath: ["elm-ui-widgets"] }
|
||||
}
|
||||
});
|
||||
app.ports.saveSettings.subscribe(function(settings){
|
||||
localStorage.setItem("settings", settings);
|
||||
});
|
||||
}());
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
|
8062
docs/main.js
8062
docs/main.js
File diff suppressed because it is too large
Load Diff
@ -4,5 +4,5 @@ Explorer
|
||||
To run the explorer :
|
||||
|
||||
```Bash
|
||||
elm-live src/Main.elm
|
||||
elm-live -u -- src/Main.elm --output main.js
|
||||
```
|
||||
|
25
explorer/index.html
Normal file
25
explorer/index.html
Normal file
@ -0,0 +1,25 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Main</title>
|
||||
<style>body { padding: 0; margin: 0; }</style>
|
||||
<script src="/main.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<script>
|
||||
(function(){
|
||||
var settings = localStorage.getItem("settings");
|
||||
const app = Elm.Main.init({
|
||||
flags: {
|
||||
settings: settings
|
||||
}
|
||||
});
|
||||
app.ports.saveSettings.subscribe(function(settings){
|
||||
localStorage.setItem("settings", settings);
|
||||
});
|
||||
}());
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -1,6 +1,7 @@
|
||||
module Main exposing (main)
|
||||
|
||||
import Element
|
||||
import Json.Decode as Decode exposing (Decoder)
|
||||
import Page.AppBar
|
||||
import Page.Button
|
||||
import Page.Dialog
|
||||
@ -37,13 +38,30 @@ pages =
|
||||
|> UIExplorer.nextPage "Dialog" Page.Dialog.page
|
||||
|
||||
|
||||
type alias Flags =
|
||||
{ settings : UIExplorer.Settings
|
||||
, config : UIExplorer.Config
|
||||
}
|
||||
|
||||
|
||||
decodeFlags : Decoder Flags
|
||||
decodeFlags =
|
||||
Decode.map2 Flags
|
||||
UIExplorer.decodeSettings
|
||||
(UIExplorer.decodeConfig
|
||||
{ relativeUrlPath = []
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
config : UIExplorer.ApplicationConfig msg Flags
|
||||
config =
|
||||
{ flagsDecoder = decodeFlags
|
||||
, layoutOptions = []
|
||||
, layoutAttributes = []
|
||||
, sidebarTitle = Element.text "Elm UI Widgets"
|
||||
}
|
||||
|
||||
|
||||
main =
|
||||
let
|
||||
config =
|
||||
UIExplorer.defaultConfig
|
||||
in
|
||||
UIExplorer.application
|
||||
{ config
|
||||
| sidebarTitle = Element.text "Elm UI Widgets"
|
||||
}
|
||||
pages
|
||||
UIExplorer.application config pages
|
||||
|
@ -16,10 +16,10 @@ import Widget.Material.Typography as Typography
|
||||
create :
|
||||
{ title : String
|
||||
, description : String
|
||||
, book : Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) ()
|
||||
, demo : Tile model msg ()
|
||||
, book : Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) flags
|
||||
, demo : Tile model msg flags
|
||||
}
|
||||
-> Page ( ( ( (), () ), model ), ( StorySelectorModel, () ) ) (TileMsg (TileMsg (TileMsg () msg1) msg) (TileMsg StorySelectorMsg ())) ()
|
||||
-> Page ( ( ( (), () ), model ), ( StorySelectorModel, () ) ) (TileMsg (TileMsg (TileMsg () msg1) msg) (TileMsg StorySelectorMsg ())) flags
|
||||
create config =
|
||||
Tile.static []
|
||||
(\_ _ ->
|
||||
|
@ -101,7 +101,7 @@ viewFunctions =
|
||||
{-| Let's you play around with the options.
|
||||
Note that the order of these stories must follow the order of the arguments from the view functions.
|
||||
-}
|
||||
book : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) ()
|
||||
book : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) flags
|
||||
book =
|
||||
Story.book (Just "Options")
|
||||
viewFunctions
|
||||
@ -489,7 +489,7 @@ view { palette } { snackbar, searchText, selected, showDialog, active } =
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
demo : Tile Model Msg ()
|
||||
demo : Tile Model Msg flags
|
||||
demo =
|
||||
{ init = always init
|
||||
, update = update
|
||||
|
@ -81,7 +81,7 @@ viewFunctions =
|
||||
{-| Let's you play around with the options.
|
||||
Note that the order of these stories must follow the order of the arguments from the view functions.
|
||||
-}
|
||||
book : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) ()
|
||||
book : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) flags
|
||||
book =
|
||||
Story.book (Just "Options")
|
||||
viewFunctions
|
||||
@ -273,7 +273,7 @@ view { palette } model =
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
demo : Tile Model Msg ()
|
||||
demo : Tile Model Msg flags
|
||||
demo =
|
||||
{ init = always init
|
||||
, update = update
|
||||
|
@ -59,7 +59,7 @@ viewFunctions =
|
||||
{-| Let's you play around with the options.
|
||||
Note that the order of these stories must follow the order of the arguments from the view functions.
|
||||
-}
|
||||
book : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) ()
|
||||
book : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) flags
|
||||
book =
|
||||
Story.book (Just "Options")
|
||||
viewFunctions
|
||||
@ -190,7 +190,7 @@ view { palette } (IsOpen isOpen) =
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
demo : Tile Model Msg ()
|
||||
demo : Tile Model Msg flags
|
||||
demo =
|
||||
{ init = always init
|
||||
, update = update
|
||||
|
@ -135,7 +135,7 @@ view { palette } () =
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
demo : Tile Model Msg ()
|
||||
demo : Tile Model Msg flags
|
||||
demo =
|
||||
{ init = always init
|
||||
, update = update
|
||||
|
@ -62,7 +62,7 @@ viewDividerFunctions =
|
||||
{-| Let's you play around with the options.
|
||||
Note that the order of these stories must follow the order of the arguments from the view functions.
|
||||
-}
|
||||
dividerBook : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) ()
|
||||
dividerBook : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) flags
|
||||
dividerBook =
|
||||
Story.book (Just "Options")
|
||||
viewDividerFunctions
|
||||
@ -116,7 +116,7 @@ viewHeaderFunctions =
|
||||
{-| Let's you play around with the options.
|
||||
Note that the order of these stories must follow the order of the arguments from the view functions.
|
||||
-}
|
||||
headerBook : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) ()
|
||||
headerBook : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) flags
|
||||
headerBook =
|
||||
Story.book (Just "Options")
|
||||
viewHeaderFunctions
|
||||
@ -170,7 +170,7 @@ viewFullBleedItemFunctions =
|
||||
Story.initStaticTiles
|
||||
|
||||
|
||||
fullBleedItemBook : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) ()
|
||||
fullBleedItemBook : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) flags
|
||||
fullBleedItemBook =
|
||||
Story.book (Just "Options")
|
||||
viewFullBleedItemFunctions
|
||||
@ -239,7 +239,7 @@ viewInsetItemFunctions =
|
||||
Story.initStaticTiles
|
||||
|
||||
|
||||
insetItemBook : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) ()
|
||||
insetItemBook : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) flags
|
||||
insetItemBook =
|
||||
Story.book (Just "Options")
|
||||
viewInsetItemFunctions
|
||||
@ -319,7 +319,7 @@ viewMultiLineItemFunctions =
|
||||
Story.initStaticTiles
|
||||
|
||||
|
||||
multiLineItemBook : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) ()
|
||||
multiLineItemBook : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) flags
|
||||
multiLineItemBook =
|
||||
Story.book (Just "Options")
|
||||
viewMultiLineItemFunctions
|
||||
@ -422,7 +422,7 @@ viewMExpansionItemFunctions =
|
||||
Story.initStaticTiles
|
||||
|
||||
|
||||
expansionItemBook : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) ()
|
||||
expansionItemBook : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) flags
|
||||
expansionItemBook =
|
||||
Story.book (Just "Options")
|
||||
viewMExpansionItemFunctions
|
||||
@ -479,7 +479,7 @@ viewSelectItemFunctions =
|
||||
Story.initStaticTiles
|
||||
|
||||
|
||||
selectItemBook : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) ()
|
||||
selectItemBook : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) flags
|
||||
selectItemBook =
|
||||
Story.book (Just "Options")
|
||||
viewSelectItemFunctions
|
||||
@ -740,7 +740,7 @@ view { palette } model =
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
demo : Tile Model Msg ()
|
||||
demo : Tile Model Msg flags
|
||||
demo =
|
||||
{ init = always init
|
||||
, update = update
|
||||
|
@ -126,7 +126,7 @@ viewFunctions =
|
||||
{-| Let's you play around with the options.
|
||||
Note that the order of these stories must follow the order of the arguments from the view functions.
|
||||
-}
|
||||
book : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) ()
|
||||
book : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) flags
|
||||
book =
|
||||
Story.book (Just "Options")
|
||||
viewFunctions
|
||||
@ -257,7 +257,7 @@ view { palette } (IsEnabled isEnabled) =
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
demo : Tile Model Msg ()
|
||||
demo : Tile Model Msg flags
|
||||
demo =
|
||||
{ init = always init
|
||||
, update = update
|
||||
|
@ -105,7 +105,7 @@ viewFunctions =
|
||||
{-| Let's you play around with the options.
|
||||
Note that the order of these stories must follow the order of the arguments from the view functions.
|
||||
-}
|
||||
book : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) ()
|
||||
book : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) flags
|
||||
book =
|
||||
Story.book (Just "Options")
|
||||
viewFunctions
|
||||
@ -233,7 +233,7 @@ view { palette } (Selected selected) =
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
demo : Tile Model Msg ()
|
||||
demo : Tile Model Msg flags
|
||||
demo =
|
||||
{ init = always init
|
||||
, update = update
|
||||
|
@ -171,7 +171,7 @@ view { palette } model =
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
demo : Tile Model Msg ()
|
||||
demo : Tile Model Msg flags
|
||||
demo =
|
||||
{ init = always init
|
||||
, update = update
|
||||
|
@ -44,7 +44,7 @@ viewFunctions =
|
||||
{-| Let's you play around with the options.
|
||||
Note that the order of these stories must follow the order of the arguments from the view functions.
|
||||
-}
|
||||
book : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) ()
|
||||
book : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) flags
|
||||
book =
|
||||
Story.book (Just "Options")
|
||||
viewFunctions
|
||||
@ -118,7 +118,7 @@ view { palette } (MaybeProgress maybeProgress) =
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
demo : Tile Model Msg ()
|
||||
demo : Tile Model Msg flags
|
||||
demo =
|
||||
{ init = always init
|
||||
, update = update
|
||||
|
@ -92,7 +92,7 @@ viewFunctions =
|
||||
{-| Let's you play around with the options.
|
||||
Note that the order of these stories must follow the order of the arguments from the view functions.
|
||||
-}
|
||||
book : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) ()
|
||||
book : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) flags
|
||||
book =
|
||||
Story.book (Just "Options")
|
||||
viewFunctions
|
||||
|
@ -53,7 +53,7 @@ viewFunctions =
|
||||
{-| Let's you play around with the options.
|
||||
Note that the order of these stories must follow the order of the arguments from the view functions.
|
||||
-}
|
||||
book : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) ()
|
||||
book : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) flags
|
||||
book =
|
||||
Story.book (Just "Options")
|
||||
viewFunctions
|
||||
@ -198,7 +198,7 @@ view { palette } model =
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
demo : Tile Model Msg ()
|
||||
demo : Tile Model Msg flags
|
||||
demo =
|
||||
{ init = always init
|
||||
, update = update
|
||||
|
@ -49,7 +49,7 @@ viewFunctions =
|
||||
{-| Let's you play around with the options.
|
||||
Note that the order of these stories must follow the order of the arguments from the view functions.
|
||||
-}
|
||||
book : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) ()
|
||||
book : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) flags
|
||||
book =
|
||||
Story.book (Just "Options")
|
||||
viewFunctions
|
||||
@ -225,7 +225,7 @@ view { palette } model =
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
demo : Tile Model Msg ()
|
||||
demo : Tile Model Msg flags
|
||||
demo =
|
||||
{ init = always init
|
||||
, update = update
|
||||
|
@ -47,7 +47,7 @@ viewFunctions =
|
||||
{-| Let's you play around with the options.
|
||||
Note that the order of these stories must follow the order of the arguments from the view functions.
|
||||
-}
|
||||
book : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) ()
|
||||
book : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) flags
|
||||
book =
|
||||
Story.book (Just "Options")
|
||||
viewFunctions
|
||||
@ -134,7 +134,7 @@ view { palette } (IsButtonEnabled isButtonEnabled) =
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
demo : Tile Model Msg ()
|
||||
demo : Tile Model Msg flags
|
||||
demo =
|
||||
{ init = always init
|
||||
, update = update
|
||||
|
@ -67,7 +67,7 @@ viewFunctions =
|
||||
{-| Let's you play around with the options.
|
||||
Note that the order of these stories must follow the order of the arguments from the view functions.
|
||||
-}
|
||||
book : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) ()
|
||||
book : Tile.Group ( StorySelectorModel, () ) (TileMsg StorySelectorMsg ()) flags
|
||||
book =
|
||||
Story.book (Just "Options")
|
||||
viewFunctions
|
||||
@ -190,7 +190,7 @@ view { palette } (Selected selected) =
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
demo : Tile Model Msg ()
|
||||
demo : Tile Model Msg flags
|
||||
demo =
|
||||
{ init = always init
|
||||
, update = update
|
||||
|
@ -192,7 +192,7 @@ view { palette } model =
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
demo : Tile Model Msg ()
|
||||
demo : Tile Model Msg flags
|
||||
demo =
|
||||
{ init = always init
|
||||
, update = update
|
||||
|
6
explorer/src/Ports.elm
Normal file
6
explorer/src/Ports.elm
Normal file
@ -0,0 +1,6 @@
|
||||
port module Ports exposing (saveSettings)
|
||||
|
||||
import Json.Encode
|
||||
|
||||
|
||||
port saveSettings : String -> Cmd msg
|
@ -1,6 +1,7 @@
|
||||
module UIExplorer exposing
|
||||
( application, defaultConfig, ApplicationConfig, Model, Msg, PageMsg
|
||||
, firstPage, nextPage, groupPages, static, Page, PageSize, PageBuilder
|
||||
, Config, Settings, decodeConfig, decodeSettings
|
||||
)
|
||||
|
||||
{-|
|
||||
@ -43,7 +44,9 @@ import Element.Region
|
||||
import Html exposing (Html)
|
||||
import Html.Attributes
|
||||
import Json.Decode as Decode
|
||||
import Json.Encode as Encode
|
||||
import Pixels exposing (Pixels)
|
||||
import Ports
|
||||
import Quantity exposing (Quantity)
|
||||
import Set exposing (Set)
|
||||
import Svg
|
||||
@ -58,6 +61,67 @@ import Widget.Material as Material
|
||||
import Widget.Material.Typography as Typography
|
||||
|
||||
|
||||
{-| The Settings. Must be the type of the 'settings' attribute of the flags
|
||||
-}
|
||||
type alias Settings =
|
||||
{ dark : Bool }
|
||||
|
||||
|
||||
decodeSettings : Decode.Decoder Settings
|
||||
decodeSettings =
|
||||
Decode.string
|
||||
|> Decode.andThen
|
||||
(\s ->
|
||||
case
|
||||
Decode.decodeString
|
||||
(Decode.map Settings
|
||||
(Decode.field "dark" Decode.bool)
|
||||
)
|
||||
s
|
||||
of
|
||||
Ok settings ->
|
||||
Decode.succeed settings
|
||||
|
||||
Err _ ->
|
||||
Decode.succeed { dark = False }
|
||||
)
|
||||
|> Decode.field "settings"
|
||||
|
||||
|
||||
saveSettings : Settings -> Cmd msg
|
||||
saveSettings settings =
|
||||
Encode.object
|
||||
[ ( "dark", Encode.bool settings.dark )
|
||||
]
|
||||
|> Encode.encode 0
|
||||
|> Ports.saveSettings
|
||||
|
||||
|
||||
type alias Config =
|
||||
{ relativeUrlPath : List String }
|
||||
|
||||
|
||||
decodeConfig : Config -> Decode.Decoder Config
|
||||
decodeConfig defaults =
|
||||
Decode.oneOf
|
||||
[ Decode.field "config" <|
|
||||
Decode.map Config
|
||||
(Decode.oneOf
|
||||
[ Decode.field "relativeUrlPath" <| Decode.list Decode.string
|
||||
, Decode.succeed defaults.relativeUrlPath
|
||||
]
|
||||
)
|
||||
, Decode.succeed defaults
|
||||
]
|
||||
|
||||
|
||||
type alias Flags flags =
|
||||
{ flags
|
||||
| settings : Settings
|
||||
, config : Config
|
||||
}
|
||||
|
||||
|
||||
{-| The first page in your UI explorer. This is the default page if the user doesn't specify a url path.
|
||||
|
||||
import Element
|
||||
@ -421,20 +485,19 @@ uiUrl path pageId =
|
||||
|
||||
|
||||
init :
|
||||
ApplicationConfig (Msg pageMsg) flags
|
||||
-> PageBuilder pageModel pageMsg flags
|
||||
ApplicationConfig (Msg pageMsg) (Flags flags)
|
||||
-> PageBuilder pageModel pageMsg (Flags flags)
|
||||
-> Decode.Value
|
||||
-> Url
|
||||
-> Browser.Navigation.Key
|
||||
-> ( Model pageModel flags, Cmd (Msg pageMsg) )
|
||||
-> ( Model pageModel (Flags flags), Cmd (Msg pageMsg) )
|
||||
init config (PageBuilder pages) flagsJson url key =
|
||||
let
|
||||
( page, navigationCmd ) =
|
||||
pageFromUrl (PageBuilder pages) config.relativeUrlPath key url
|
||||
in
|
||||
case Decode.decodeValue config.flagsDecoder flagsJson of
|
||||
Ok flags ->
|
||||
let
|
||||
( page, navigationCmd ) =
|
||||
pageFromUrl (PageBuilder pages) flags.config.relativeUrlPath key url
|
||||
|
||||
( pageModels, pageCmds ) =
|
||||
pages.init flags
|
||||
in
|
||||
@ -453,7 +516,7 @@ init config (PageBuilder pages) flagsJson url key =
|
||||
, pageSizeOption = Native
|
||||
, expandColorBlindOptions = False
|
||||
, colorBlindOption = Nothing
|
||||
, darkThemeEnabled = False
|
||||
, darkThemeEnabled = flags.settings.dark
|
||||
}
|
||||
, Cmd.batch
|
||||
[ navigationCmd
|
||||
@ -487,11 +550,11 @@ expandPage page expandedGroups =
|
||||
|
||||
|
||||
update :
|
||||
PageBuilder pageModel pageMsg flags
|
||||
-> ApplicationConfig (Msg pageMsg) flags
|
||||
PageBuilder pageModel pageMsg (Flags flags)
|
||||
-> ApplicationConfig (Msg pageMsg) (Flags flags)
|
||||
-> Msg pageMsg
|
||||
-> Model pageModel flags
|
||||
-> ( Model pageModel flags, Cmd (Msg pageMsg) )
|
||||
-> Model pageModel (Flags flags)
|
||||
-> ( Model pageModel (Flags flags), Cmd (Msg pageMsg) )
|
||||
update pages config msg model =
|
||||
case model of
|
||||
FlagsParsed successModel ->
|
||||
@ -502,17 +565,17 @@ update pages config msg model =
|
||||
|
||||
|
||||
updateSuccess :
|
||||
PageBuilder pageModel pageMsg flags
|
||||
-> ApplicationConfig (Msg pageMsg) flags
|
||||
PageBuilder pageModel pageMsg (Flags flags)
|
||||
-> ApplicationConfig (Msg pageMsg) (Flags flags)
|
||||
-> Msg pageMsg
|
||||
-> SuccessModel pageModel flags
|
||||
-> ( SuccessModel pageModel flags, Cmd (Msg pageMsg) )
|
||||
-> SuccessModel pageModel (Flags flags)
|
||||
-> ( SuccessModel pageModel (Flags flags), Cmd (Msg pageMsg) )
|
||||
updateSuccess (PageBuilder pages) config msg model =
|
||||
case msg of
|
||||
UrlChanged url ->
|
||||
let
|
||||
( page, pageCmd ) =
|
||||
pageFromUrl (PageBuilder pages) config.relativeUrlPath model.key url
|
||||
pageFromUrl (PageBuilder pages) model.flags.config.relativeUrlPath model.key url
|
||||
in
|
||||
( { model | page = page }, pageCmd )
|
||||
|
||||
@ -547,7 +610,7 @@ updateSuccess (PageBuilder pages) config msg model =
|
||||
PressedChangePageHotkey pageId ->
|
||||
( model
|
||||
, Cmd.batch
|
||||
[ Browser.Navigation.pushUrl model.key (uiUrl config.relativeUrlPath pageId)
|
||||
[ Browser.Navigation.pushUrl model.key (uiUrl model.flags.config.relativeUrlPath pageId)
|
||||
, Browser.Dom.focus (pageGroupToString pageId) |> Task.attempt (always NoOp)
|
||||
]
|
||||
)
|
||||
@ -622,16 +685,16 @@ updateSuccess (PageBuilder pages) config msg model =
|
||||
)
|
||||
|
||||
ChangeDarkTheme enabled ->
|
||||
( { model | darkThemeEnabled = enabled }, Cmd.none )
|
||||
( { model | darkThemeEnabled = enabled }, saveSettings { dark = enabled } )
|
||||
|
||||
Load string ->
|
||||
( model, Browser.Navigation.pushUrl model.key string )
|
||||
|
||||
|
||||
view :
|
||||
ApplicationConfig (Msg pageMsg) flags
|
||||
-> PageBuilder pageModel pageMsg flags
|
||||
-> Model pageModel flags
|
||||
ApplicationConfig (Msg pageMsg) (Flags flags)
|
||||
-> PageBuilder pageModel pageMsg (Flags flags)
|
||||
-> Model pageModel (Flags flags)
|
||||
-> { title : String, body : List (Html (Msg pageMsg)) }
|
||||
view config pages model =
|
||||
case model of
|
||||
@ -685,9 +748,9 @@ errorView dark errorMessage =
|
||||
|
||||
|
||||
viewSuccess :
|
||||
ApplicationConfig (Msg pageMsg) flags
|
||||
-> PageBuilder pageModel pageMsg flags
|
||||
-> SuccessModel pageModel flags
|
||||
ApplicationConfig (Msg pageMsg) (Flags flags)
|
||||
-> PageBuilder pageModel pageMsg (Flags flags)
|
||||
-> SuccessModel pageModel (Flags flags)
|
||||
-> Browser.Document (Msg pageMsg)
|
||||
viewSuccess config ((PageBuilder pages) as pages_) model =
|
||||
let
|
||||
@ -794,9 +857,9 @@ sidebarMinimizedWidth =
|
||||
|
||||
|
||||
viewSidebar :
|
||||
PageBuilder pageModel pageMsg flags
|
||||
-> ApplicationConfig (Msg pageMsg) flags
|
||||
-> SuccessModel pageModel flags
|
||||
PageBuilder pageModel pageMsg (Flags flags)
|
||||
-> ApplicationConfig (Msg pageMsg) (Flags flags)
|
||||
-> SuccessModel pageModel (Flags flags)
|
||||
-> Element (Msg pageMsg)
|
||||
viewSidebar pages config model =
|
||||
let
|
||||
@ -860,10 +923,20 @@ viewSidebar pages config model =
|
||||
|> Widget.asItem
|
||||
, Widget.asItem <|
|
||||
if showSearchResults model.searchText then
|
||||
Element.Lazy.lazy5 viewSearchResults model.darkThemeEnabled pages config model.page model.searchText
|
||||
Element.Lazy.lazy5 viewSearchResults
|
||||
model.darkThemeEnabled
|
||||
pages
|
||||
model.flags.config.relativeUrlPath
|
||||
model.page
|
||||
model.searchText
|
||||
|
||||
else
|
||||
Element.Lazy.lazy5 viewSidebarLinks model.darkThemeEnabled pages config model.page model.expandedGroups
|
||||
Element.Lazy.lazy5 viewSidebarLinks
|
||||
model.darkThemeEnabled
|
||||
pages
|
||||
model.flags.config.relativeUrlPath
|
||||
model.page
|
||||
model.expandedGroups
|
||||
]
|
||||
]
|
||||
|> List.concat
|
||||
@ -1137,11 +1210,11 @@ showSearchResults searchText =
|
||||
viewSearchResults :
|
||||
Bool
|
||||
-> PageBuilder pageModel pageMsg flags
|
||||
-> ApplicationConfig (Msg pageMsg) flags
|
||||
-> List String
|
||||
-> List String
|
||||
-> String
|
||||
-> Element (Msg pageMsg)
|
||||
viewSearchResults dark (PageBuilder pages) config currentPage searchText =
|
||||
viewSearchResults dark (PageBuilder pages) relativeUrlPath currentPage searchText =
|
||||
let
|
||||
options : Array { previous : Maybe (List String), current : List String, next : Maybe (List String) }
|
||||
options =
|
||||
@ -1198,7 +1271,7 @@ viewSearchResults dark (PageBuilder pages) config currentPage searchText =
|
||||
|> Array.get int
|
||||
|> Maybe.map .current
|
||||
|> Maybe.withDefault []
|
||||
|> uiUrl config.relativeUrlPath
|
||||
|> uiUrl relativeUrlPath
|
||||
|> Load
|
||||
|> Just
|
||||
}
|
||||
@ -1351,13 +1424,13 @@ buildTree items =
|
||||
|
||||
viewSidebarLinksHelper :
|
||||
Bool
|
||||
-> { a | relativeUrlPath : List String }
|
||||
-> List String
|
||||
-> List String
|
||||
-> Set String
|
||||
-> List String
|
||||
-> List (Tree String)
|
||||
-> List (List String)
|
||||
viewSidebarLinksHelper dark config page expandedGroups path trees =
|
||||
viewSidebarLinksHelper dark relativeUrlPath page expandedGroups path trees =
|
||||
trees
|
||||
|> List.sortBy Tree.label
|
||||
|> List.concatMap
|
||||
@ -1375,7 +1448,7 @@ viewSidebarLinksHelper dark config page expandedGroups path trees =
|
||||
[ newPath ]
|
||||
|
||||
children ->
|
||||
viewSidebarLinksHelper dark config page expandedGroups newPath children
|
||||
viewSidebarLinksHelper dark relativeUrlPath page expandedGroups newPath children
|
||||
)
|
||||
|
||||
|
||||
@ -1411,17 +1484,17 @@ gatherWith testFn list =
|
||||
viewSidebarLinks :
|
||||
Bool
|
||||
-> PageBuilder pageModel pageMsg flags
|
||||
-> ApplicationConfig (Msg pageMsg) flags
|
||||
-> List String
|
||||
-> List String
|
||||
-> Set String
|
||||
-> Element (Msg pageMsg)
|
||||
viewSidebarLinks dark (PageBuilder pages) config page expandedGroups =
|
||||
viewSidebarLinks dark (PageBuilder pages) relativeUrlPath page expandedGroups =
|
||||
let
|
||||
options : Array (List String)
|
||||
options =
|
||||
pages.ids
|
||||
|> buildTree
|
||||
|> viewSidebarLinksHelper dark config page expandedGroups []
|
||||
|> viewSidebarLinksHelper dark relativeUrlPath page expandedGroups []
|
||||
|> Array.fromList
|
||||
|
||||
palette =
|
||||
@ -1456,7 +1529,7 @@ viewSidebarLinks dark (PageBuilder pages) config page expandedGroups =
|
||||
options
|
||||
|> Array.get int
|
||||
|> Maybe.withDefault []
|
||||
|> uiUrl config.relativeUrlPath
|
||||
|> uiUrl relativeUrlPath
|
||||
|> Load
|
||||
|> Just
|
||||
}
|
||||
@ -1502,7 +1575,6 @@ type alias ApplicationConfig msg flags =
|
||||
{ flagsDecoder : Decode.Decoder flags
|
||||
, layoutOptions : List Element.Option
|
||||
, layoutAttributes : List (Element.Attribute msg)
|
||||
, relativeUrlPath : List String
|
||||
, sidebarTitle : Element msg
|
||||
}
|
||||
|
||||
@ -1522,7 +1594,6 @@ defaultConfig =
|
||||
{ flagsDecoder = Decode.succeed ()
|
||||
, layoutOptions = []
|
||||
, layoutAttributes = []
|
||||
, relativeUrlPath = [ "elm-ui-widgets" ]
|
||||
, sidebarTitle = Element.text "UI explorer"
|
||||
}
|
||||
|
||||
@ -1560,9 +1631,9 @@ Instead it's best to just let the compiler infer it automatically.
|
||||
|
||||
-}
|
||||
application :
|
||||
ApplicationConfig (Msg pageMsg) flags
|
||||
-> PageBuilder pageModel pageMsg flags
|
||||
-> Platform.Program Decode.Value (Model pageModel flags) (Msg pageMsg)
|
||||
ApplicationConfig (Msg pageMsg) (Flags flags)
|
||||
-> PageBuilder pageModel pageMsg (Flags flags)
|
||||
-> Platform.Program Decode.Value (Model pageModel (Flags flags)) (Msg pageMsg)
|
||||
application config pages =
|
||||
Browser.application
|
||||
{ init = init config pages
|
||||
|
@ -175,7 +175,7 @@ addTile view tilelist =
|
||||
}
|
||||
|
||||
|
||||
initStaticTiles : Group view () () ()
|
||||
initStaticTiles : Group view () () flags
|
||||
initStaticTiles =
|
||||
{ init = always ( (), Cmd.none )
|
||||
, update = \_ _ -> ( (), Cmd.none )
|
||||
|
@ -371,7 +371,7 @@ page (Builder config) =
|
||||
|
||||
{-| render a markdown text into a simple panel
|
||||
-}
|
||||
markdown : List (Attribute ()) -> String -> Tile () () ()
|
||||
markdown : List (Attribute msg) -> String -> Tile () msg flags
|
||||
markdown attributes text =
|
||||
static attributes
|
||||
(\_ _ ->
|
||||
@ -380,14 +380,14 @@ markdown attributes text =
|
||||
)
|
||||
|
||||
|
||||
static : List (Attribute msg) -> (Context -> flags -> Element msg) -> Tile flags msg flags
|
||||
static : List (Attribute msg) -> (Context -> () -> Element msg) -> Tile () msg flags
|
||||
static attributes tileView =
|
||||
{ init = \flags -> ( flags, Cmd.none )
|
||||
{ init = \flags -> ( (), Cmd.none )
|
||||
, update = \_ m -> ( m, Cmd.none )
|
||||
, view =
|
||||
\pagesize flags ->
|
||||
\pagesize () ->
|
||||
{ title = Nothing
|
||||
, body = tileView pagesize flags
|
||||
, body = tileView pagesize ()
|
||||
, position = FullWidthTile
|
||||
, attributes = attributes
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user