Commit 957234f06846cf3558d82bf3c637c5f60f658eff

  • avatar
  • Ville Tirronen <ville.tirronen @j…u.fi> (Committer)
  • Mon Apr 29 13:45:13 EEST 2019
  • avatar
  • Ville Tirronen <ville.tirronen @j…u.fi> (Author)
  • Mon Apr 29 13:45:13 EEST 2019
Treewidget -> 0.19
DrawAST/TreeWidget.elm
(66 / 22)
  
1module TreeWidget exposing (..)
1module TreeWidget exposing (Flags, Model, Msg(..), init, main, noPropagateInput, update, view)
22
33import Html exposing (..)
4import Http exposing (encodeUri)
54import Html.Attributes exposing (..)
65import Html.Events exposing (..)
7import Html.Events exposing (..)
86import Json.Decode as Decode
7import Url
8import Url.Builder
99import String
10import Browser
1011
12
1113main =
12 Html.programWithFlags { init = init, update = update, view = view, subscriptions = \x -> Sub.none }
14 Browser.element { init = init, update = update, view = view, subscriptions = \x -> Sub.none }
1315
1416
17
1518-- MODEL
1619
17type alias Model = {expr:String,url:String}
18type alias Flags = {url:String,expr:String}
1920
20init : Flags -> (Model, Cmd Msg)
21init flags = {expr=flags.expr,url=flags.url} ! []
22
21type alias Model =
22 { expr : String, url : String }
2323
2424
25type alias Flags =
26 { url : String, expr : String }
27
28
29init : Flags -> ( Model, Cmd Msg )
30init flags =
31 ( { expr = flags.expr, url = flags.url }
32 , Cmd.none
33 )
34
35
36
2537-- UPDATE
2638
27type Msg = SetExpr String | Nop
2839
29update : Msg -> Model -> (Model,Cmd Msg)
40type Msg
41 = SetExpr String
42 | Nop
43
44
45update : Msg -> Model -> ( Model, Cmd Msg )
3046update msg model =
31 case msg of
32 SetExpr s -> {model|expr=s} ! []
33 Nop -> model ! []
47 case msg of
48 SetExpr s ->
49 ( { model | expr = s }
50 , Cmd.none
51 )
3452
53 Nop ->
54 ( model
55 , Cmd.none
56 )
57
58
59
3560-- VIEW
3661
62
3763view : Model -> Html Msg
3864view model =
39 div [style [("width","400px"),("text-align","center")
40 ,("border","1px solid black"), ("padding","4px")]]
41 [ input [type_ "text", onInput SetExpr, value model.expr, noPropagateInput Nop
42 ,style [("display","block"),("text-align","center"),("border","none"),("border-bottom","1px dashed black")
43 ,("background","#DDD"),("width","100%")] ] [ text "-" ]
44 , img [src (model.url++"?expr="++encodeUri model.expr)] []
45 ]
65 div
66 [ style "width" "400px"
67 , style "text-align" "center"
68 , style "border" "1px solid black"
69 , style "padding" "4px"
70 ]
71 [ input
72 [ type_ "text"
73 , onInput SetExpr
74 , value model.expr
75 , noPropagateInput Nop
76 , style "display" "block"
77 , style "text-align" "center"
78 , style "border" "none"
79 , style "border-bottom" "1px dashed black"
80 , style "background" "#DDD"
81 , style "width" "100%"
82 ]
83 [ text "-" ]
84 , img [ src (Url.Builder.relative [model.url]
85 [Url.Builder.string "expr" model.expr]) ] []
86 ]
4687
47noPropagateInput msg = onWithOptions "keydown" {stopPropagation=True,preventDefault=False} (Decode.succeed msg)
88
89noPropagateInput msg = stopPropagationOn "keydown" (Decode.succeed (msg,True))
90
91
4892
4993--onInput : (String -> msg) -> Attribute msg
5094--onInput tagger =
DrawAST/elm.json
(27 / 0)
  
1{
2 "type": "application",
3 "source-directories": [
4 "."
5 ],
6 "elm-version": "0.19.0",
7 "dependencies": {
8 "direct": {
9 "elm/browser": "1.0.1",
10 "elm/bytes": "1.0.8",
11 "elm/core": "1.0.2",
12 "elm/html": "1.0.0",
13 "elm/http": "2.0.0",
14 "elm/json": "1.1.3"
15 },
16 "indirect": {
17 "elm/file": "1.0.5",
18 "elm/time": "1.0.0",
19 "elm/url": "1.0.0",
20 "elm/virtual-dom": "1.0.2"
21 }
22 },
23 "test-dependencies": {
24 "direct": {},
25 "indirect": {}
26 }
27}