on master help sign in
Merge branch 'master' into dev
9943120Evan Czaplicki
Elm.cabal+1−1
@@ -20,7 +20,7 @@ Category: Compiler, Language
20
20
21Build-type: Custom
21Build-type: Custom
22
22
23−Extra-source-files: changelog.txt
23+Extra-source-files: changelog.md
24Data-dir: data
24Data-dir: data
25Data-files: elm-runtime.js interfaces.data docs.json
25Data-files: elm-runtime.js interfaces.data docs.json
26Cabal-version: >=1.9
26Cabal-version: >=1.9
libraries/Char.elm+2−2
@@ -52,8 +52,8 @@ toLocaleLower = Native.Char.toLocaleLower
52
52
53type KeyCode = Int
53type KeyCode = Int
54
54
55−{-| Convert to unicode. Used with the [`Keyboard`](/docs/Keyboard.elm)
55+{-| Convert to unicode. Used with the `Keyboard` library, which expects the
56−library, which expects the input to be uppercase. -}
56+input to be uppercase. -}
57toCode : Char -> KeyCode
57toCode : Char -> KeyCode
58toCode = Native.Char.toCode
58toCode = Native.Char.toCode
59
59
libraries/Debug.elm+2
@@ -1,6 +1,8 @@
1module Debug where
1module Debug where
2{-| This library is for investigating bugs or performance problems. It should
2{-| This library is for investigating bugs or performance problems. It should
3*not* be used in production code.
3*not* be used in production code.
4+
5+@docs log
4-}
6-}
5
7
6import Native.Debug
8import Native.Debug
libraries/Http.elm+2−4
@@ -1,8 +1,6 @@
1module Http where
1module Http where
2−
3−{-| A library for asynchronous HTTP requests. See the
2+{-| A library for asynchronous HTTP requests. See the `WebSocket`
4−[WebSocket](http://elm-lang.org/docs/WebSocket.elm) library if
5−you have very strict latency requirements.
3+library if you have very strict latency requirements.
6
4
7# Sending Requests
5# Sending Requests
8@docs send, sendGet
6@docs send, sendGet
libraries/Keyboard.elm+2−4
@@ -1,5 +1,4 @@
1module Keyboard where
1module Keyboard where
2−
3{-| Library for working with keyboard input.
2{-| Library for working with keyboard input.
4
3
5# Representing Keys
4# Representing Keys
@@ -20,9 +19,8 @@ import Signal (Signal)
20import Native.Keyboard
19import Native.Keyboard
21
20
22{-| Type alias to make it clearer what integers are supposed to represent
21{-| Type alias to make it clearer what integers are supposed to represent
23−in this library. Use [`Char.toCode`](docs/Char.elm#toCode) and
22+in this library. Use `Char.toCode` and `Char.fromCode` to convert key codes
24−[`Char.fromCode`](/docs/Char.elm#fromCode) to convert key codes to characters.
25−Use the uppercase character with `toCode`.
23+to characters. Use the uppercase character with `toCode`.
26-}
24-}
27type KeyCode = Int
25type KeyCode = Int
28
26
libraries/Signal.elm+1−1
@@ -10,7 +10,7 @@ past-dependence.
10
10
11Some useful functions for working with time (e.g. setting FPS) and combining
11Some useful functions for working with time (e.g. setting FPS) and combining
12signals and time (e.g. delaying updates, getting timestamps) can be found in
12signals and time (e.g. delaying updates, getting timestamps) can be found in
13−the [`Time`](/docs/Signal/Time.elm) library.
13+the `Time` library.
14
14
15# Combine
15# Combine
16@docs constant, lift, lift2, merge, merges, combine
16@docs constant, lift, lift2, merge, merges, combine
libraries/String.elm+6−6
@@ -174,18 +174,18 @@ pad = Native.String.pad
174
174
175{-| Pad a string on the left until it has a given length.
175{-| Pad a string on the left until it has a given length.
176
176
177− pad 5 '.' "1" == "....1"
177+ padLeft 5 '.' "1" == "....1"
178− pad 5 '.' "11" == "...11"
178+ padLeft 5 '.' "11" == "...11"
179− pad 5 '.' "121" == "..121"
179+ padLeft 5 '.' "121" == "..121"
180-}
180-}
181padLeft : Int -> Char -> String -> String
181padLeft : Int -> Char -> String -> String
182padLeft = Native.String.padLeft
182padLeft = Native.String.padLeft
183
183
184{-| Pad a string on the right until it has a given length.
184{-| Pad a string on the right until it has a given length.
185
185
186− pad 5 '.' "1" == "1...."
186+ padRight 5 '.' "1" == "1...."
187− pad 5 '.' "11" == "11..."
187+ padRight 5 '.' "11" == "11..."
188− pad 5 '.' "121" == "121.."
188+ padRight 5 '.' "121" == "121.."
189-}
189-}
190padRight : Int -> Char -> String -> String
190padRight : Int -> Char -> String -> String
191padRight = Native.String.padRight
191padRight = Native.String.padRight
runtime/Render/Element.js+57−29
@@ -34,35 +34,59 @@ function setProps(elem, e) {
34 e.appendChild(a);
34 e.appendChild(a);
35 }
35 }
36 if (props.hover.ctor !== '_Tuple0') {
36 if (props.hover.ctor !== '_Tuple0') {
37− e.style.pointerEvents = 'auto';
38− e.elm_hover_handler = props.hover;
37+ addHover(e, props.hover);
39− e.elm_hover_count = 0;
40− e.addEventListener('mouseover', function() {
41− if (e.elm_hover_count++ > 0) return;
42− var handler = e.elm_hover_handler;
43− if (handler !== null) {
44− handler(true);
45− }
46− });
47− e.addEventListener('mouseout', function(evt) {
48− if (e.contains(evt.toElement || evt.relatedTarget)) return;
49− e.elm_hover_count = 0;
50− var handler = e.elm_hover_handler;
51− if (handler !== null) {
52− handler(false);
53− }
54− });
55 }
38 }
56 if (props.click.ctor !== '_Tuple0') {
39 if (props.click.ctor !== '_Tuple0') {
57− e.style.pointerEvents = 'auto';
58− e.elm_click_handler = props.click;
40+ addClick(e, props.click);
59− e.addEventListener('click', function() {
60− e.elm_click_handler(Tuple0);
61− });
62 }
41 }
63 return e;
42 return e;
64}
43}
65
44
45+function addClick(e, handler) {
46+ e.style.pointerEvents = 'auto';
47+ e.elm_click_handler = handler;
48+ function trigger() {
49+ e.elm_click_handler(Utils.Tuple0);
50+ }
51+ e.elm_click_trigger = trigger;
52+ e.addEventListener('click', trigger);
53+}
54+
55+function removeClick(e, handler) {
56+ if (e.elm_click_trigger) {
57+ e.removeEventListener('click', e.elm_click_trigger);
58+ }
59+}
60+
61+function addHover(e, handler) {
62+ e.style.pointerEvents = 'auto';
63+ e.elm_hover_handler = handler;
64+ e.elm_hover_count = 0;
65+
66+ function over() {
67+ if (e.elm_hover_count++ > 0) return;
68+ e.elm_hover_handler(true);
69+ }
70+ function out(evt) {
71+ if (e.contains(evt.toElement || evt.relatedTarget)) return;
72+ e.elm_hover_count = 0;
73+ e.elm_hover_handler(false);
74+ }
75+ e.elm_hover_over = over;
76+ e.elm_hover_out = out;
77+ e.addEventListener('mouseover', over);
78+ e.addEventListener('mouseout', out);
79+}
80+
81+function removeHover(e) {
82+ if (e.elm_hover_over) {
83+ e.removeEventListener('mouseover', e.elm_hover_over);
84+ }
85+ if (e.elm_hover_out) {
86+ e.removeEventListener('mouseout', e.elm_hover_out);
87+ }
88+}
89+
66function image(props, img) {
90function image(props, img) {
67 switch (img._0.ctor) {
91 switch (img._0.ctor) {
68 case 'Plain': return plainImage(img._3);
92 case 'Plain': return plainImage(img._3);
@@ -358,17 +382,21 @@ function updateProps(node, curr, next) {
358 }
382 }
359
383
360 // update hover handlers
384 // update hover handlers
361− if (props.hover.ctor !== '_Tuple0') {
385+ if (props.hover.ctor === '_Tuple0') {
362− e.elm_hover_handler = props.hover;
386+ removeHover(e);
363 } else if (e.elm_hover_handler) {
387 } else if (e.elm_hover_handler) {
364− e.elm_hover_handler = null;
388+ e.elm_hover_handler = props.hover;
389+ } else {
390+ addHover(e, props.hover);
365 }
391 }
366
392
367 // update click handlers
393 // update click handlers
368− if (props.click.ctor !== '_Tuple0') {
394+ if (props.click.ctor === '_Tuple0') {
369− e.elm_click_handler = props.click;
395+ removeClick(e);
370 } else if (e.elm_click_handler) {
396 } else if (e.elm_click_handler) {
371− e.elm_click_handler = null;
397+ e.elm_click_handler = props.click;
398+ } else {
399+ addClick(e, props.click);
372 }
400 }
373}
401}
374
402
server/Server.hs+11−8
@@ -24,11 +24,14 @@ import Snap.Util.FileServe
24
24
25data Flags = Flags
25data Flags = Flags
26 { port :: Int
26 { port :: Int
27+ , runtime :: Maybe FilePath
27 } deriving (Data,Typeable,Show,Eq)
28 } deriving (Data,Typeable,Show,Eq)
28
29
29flags :: Flags
30flags :: Flags
30flags = Flags
31flags = Flags
31 { port = 8000 &= help "set the port of the server"
32 { port = 8000 &= help "set the port of the server"
33+ , runtime = Nothing &= typFile
34+ &= help "Specify a custom location for Elm's runtime system."
32 } &= help "Quickly reload Elm projects in your browser. Just refresh to recompile.\n\
35 } &= help "Quickly reload Elm projects in your browser. Just refresh to recompile.\n\
33 \It serves static files and freshly recompiled Elm files."
36 \It serves static files and freshly recompiled Elm files."
34 &= helpArg [explicit, name "help", name "h"]
37 &= helpArg [explicit, name "help", name "h"]
@@ -49,7 +52,7 @@ main = do
49 putStrLn $ "Elm Server " ++ Version.showVersion version ++
52 putStrLn $ "Elm Server " ++ Version.showVersion version ++
50 ": Just refresh a page to recompile it!"
53 ": Just refresh a page to recompile it!"
51 httpServe (setPort (port cargs) config) $
54 httpServe (setPort (port cargs) config) $
52− serveRuntime
55+ serveRuntime (maybe Elm.runtime id (runtime cargs))
53 <|> serveElm
56 <|> serveElm
54 <|> serveDirectoryWith directoryConfig "."
57 <|> serveDirectoryWith directoryConfig "."
55
58
@@ -74,14 +77,14 @@ indexStyle =
74 \th { background:rgb(90,99,120); color:white; text-align:left;\
77 \th { background:rgb(90,99,120); color:white; text-align:left;\
75 \ padding:10px; font-weight:normal; }"
78 \ padding:10px; font-weight:normal; }"
76
79
77−runtime :: String
80+runtimeName :: String
78−runtime = "elm-runtime.js"
81+runtimeName = "elm-runtime.js"
79
82
80−serveRuntime :: Snap ()
83+serveRuntime :: FilePath -> Snap ()
81−serveRuntime =
84+serveRuntime runtimePath =
82 do file <- BSC.unpack . rqPathInfo <$> getRequest
85 do file <- BSC.unpack . rqPathInfo <$> getRequest
83− guard (file == runtime)
86+ guard (file == runtimeName)
84− serveFileAs "application/javascript" Elm.runtime
87+ serveFileAs "application/javascript" runtimePath
85
88
86serveElm :: Snap ()
89serveElm :: Snap ()
87serveElm =
90serveElm =
@@ -91,7 +94,7 @@ serveElm =
91 onSuccess (compile file) (serve file)
94 onSuccess (compile file) (serve file)
92 where
95 where
93 compile file =
96 compile file =
94− let elmArgs = [ "--make", "--runtime=" ++ runtime, file ]
97+ let elmArgs = [ "--make", "--runtime=" ++ runtimeName, file ]
95 in createProcess $ (proc "elm" elmArgs) { std_out = CreatePipe }
98 in createProcess $ (proc "elm" elmArgs) { std_out = CreatePipe }
96
99
97 serve file =
100 serve file =