Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Upgrade to Elm 0.19 #4

Merged
merged 9 commits into from Aug 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 0 additions & 17 deletions elm-package.json

This file was deleted.

19 changes: 19 additions & 0 deletions elm.json
@@ -0,0 +1,19 @@
{
"type": "package",
"name": "Microsoft/elm-json-tree-view",
"summary": "Shows JSON data as an expandable HTML tree",
"license": "MIT",
"version": "1.0.1",
"exposed-modules": [
"JsonTree"
],
"elm-version": "0.19.0 <= v < 0.20.0",
"dependencies": {
"elm/core": "1.0.0 <= v < 2.0.0",
"elm/html": "1.0.0 <= v < 2.0.0",
"elm/json": "1.0.0 <= v < 2.0.0"
},
"test-dependencies": {
"elm-explorations/test": "1.0.0 <= v < 2.0.0"
}
}
2 changes: 1 addition & 1 deletion example/README.md
Expand Up @@ -4,6 +4,6 @@

```bash
cd example
elm-make src/Main.elm
elm make src/Main.elm
open index.html
```
16 changes: 0 additions & 16 deletions example/elm-package.json

This file was deleted.

25 changes: 25 additions & 0 deletions example/elm.json
@@ -0,0 +1,25 @@
{
"type": "application",
"source-directories": [
"src",
"../src"
],
"elm-version": "0.19.0",
"dependencies": {
"direct": {
"elm/browser": "1.0.0",
"elm/core": "1.0.0",
"elm/html": "1.0.0",
"elm/json": "1.0.0"
},
"indirect": {
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.0"
}
},
"test-dependencies": {
"direct": {},
"indirect": {}
}
}
92 changes: 40 additions & 52 deletions example/src/Main.elm
Expand Up @@ -4,6 +4,8 @@

module Main exposing (..)

import Browser
import Json.Decode as Decode
import Html exposing (..)
import Html.Attributes exposing (checked, class, style, type_, value)
import Html.Events exposing (onCheck, onClick, onInput)
Expand Down Expand Up @@ -31,23 +33,21 @@ exampleJsonInput =

type alias Model =
{ jsonInput : String
, parseResult : Result String JsonTree.Node
, parseResult : Result Decode.Error JsonTree.Node
, treeState : JsonTree.State
, clickToSelectEnabled : Bool
, selections : List JsonTree.KeyPath
}


init : ( Model, Cmd Msg )
init : Model
init =
( { jsonInput = exampleJsonInput
, parseResult = JsonTree.parseString exampleJsonInput
, treeState = JsonTree.defaultState
, clickToSelectEnabled = False
, selections = []
}
, Cmd.none
)
{ jsonInput = exampleJsonInput
, parseResult = JsonTree.parseString exampleJsonInput
, treeState = JsonTree.defaultState
, clickToSelectEnabled = False
, selections = []
}



Expand All @@ -64,49 +64,37 @@ type Msg
| Selected JsonTree.KeyPath


update : Msg -> Model -> ( Model, Cmd Msg )
update : Msg -> Model -> Model
update msg model =
case msg of
SetJsonInput string ->
( { model | jsonInput = string }
, Cmd.none
)
{ model | jsonInput = string }

Parse ->
( { model | parseResult = JsonTree.parseString model.jsonInput }
, Cmd.none
)
{ model | parseResult = JsonTree.parseString model.jsonInput }

SetTreeViewState state ->
( { model | treeState = state }
, Cmd.none
)
{ model | treeState = state }

ExpandAll ->
( { model | treeState = JsonTree.expandAll model.treeState }
, Cmd.none
)
{ model | treeState = JsonTree.expandAll model.treeState }

CollapseAll ->
case model.parseResult of
Ok rootNode ->
( { model | treeState = JsonTree.collapseToDepth 1 rootNode model.treeState }
, Cmd.none
)
{ model | treeState = JsonTree.collapseToDepth 1 rootNode model.treeState }

Err _ ->
( model, Cmd.none )
model

ToggleSelectionMode ->
( { model
{ model
| clickToSelectEnabled = not model.clickToSelectEnabled
, selections = []
}
, Cmd.none
)

Selected keyPath ->
( { model | selections = model.selections ++ [ keyPath ] }, Cmd.none )
{ model | selections = model.selections ++ [ keyPath ] }



Expand All @@ -115,13 +103,14 @@ update msg model =

view : Model -> Html Msg
view model =
div [ style [ ( "margin", "20px" ) ] ]
div [ style "margin" "20px" ]
[ h1 [] [ text "JSON Tree View Example" ]
, viewInputArea model
, hr [] []
, viewJsonTree model
, if model.clickToSelectEnabled then
viewSelections model

else
text ""
]
Expand All @@ -134,11 +123,9 @@ viewInputArea model =
, textarea
[ value model.jsonInput
, onInput SetJsonInput
, style
[ ( "width", "400px" )
, ( "height", "200px" )
, ( "font-size", "14px" )
]
, style "width" "400px"
, style "height" "200px"
, style "font-size" "14px"
]
[]
, div [] [ button [ onClick Parse ] [ text "Parse" ] ]
Expand Down Expand Up @@ -167,21 +154,22 @@ viewJsonTree model =
{ onSelect =
if allowSelection then
Just Selected

else
Nothing
, toMsg = SetTreeViewState
}
in
div []
[ h3 [] [ text "JSON Tree View" ]
, toolbar
, case model.parseResult of
Ok rootNode ->
JsonTree.view rootNode (config model.clickToSelectEnabled) model.treeState

Err e ->
text ("Invalid JSON: " ++ e)
]
div []
[ h3 [] [ text "JSON Tree View" ]
, toolbar
, case model.parseResult of
Ok rootNode ->
JsonTree.view rootNode (config model.clickToSelectEnabled) model.treeState

Err e ->
pre [] [ text ("Invalid JSON: " ++ Decode.errorToString e)]
]


viewSelections : Model -> Html Msg
Expand All @@ -191,6 +179,7 @@ viewSelections model =
, h3 [] [ text "Recently selected key-paths" ]
, if List.isEmpty model.selections then
text "No selections. Click any scalar value in the JSON tree view above to select it."

else
ul [] (List.map (\x -> li [] [ text x ]) model.selections)
]
Expand All @@ -200,11 +189,10 @@ viewSelections model =
---- PROGRAM ----


main : Program Never Model Msg
main : Program () Model Msg
main =
Html.program
{ view = view
, init = init
Browser.sandbox
{ init = init
, view = view
, update = update
, subscriptions = always Sub.none
}