diff options
-rw-r--r-- | lib/js/urweb.js | 1 | ||||
-rw-r--r-- | src/monoize.sml | 45 | ||||
-rw-r--r-- | tests/ctextbox.ur | 7 | ||||
-rw-r--r-- | tests/ctextbox.urp | 3 |
4 files changed, 46 insertions, 10 deletions
diff --git a/lib/js/urweb.js b/lib/js/urweb.js index 7bb6849e..c46263b8 100644 --- a/lib/js/urweb.js +++ b/lib/js/urweb.js @@ -87,6 +87,7 @@ function inp(t, s) { addNode(x); s.h = cons(function() { x.value = s.v }, s.h); x.onkeyup = function() { sv(s, x.value) }; + return x; } function eh(x) { diff --git a/src/monoize.sml b/src/monoize.sml index 8d5ed36c..80661d03 100644 --- a/src/monoize.sml +++ b/src/monoize.sml @@ -1777,12 +1777,12 @@ fun monoExp (env, st, fm) (all as (e, loc)) = L'.ERecord xes => xes | _ => raise Fail "Non-record attributes!" + fun lowercaseFirst "" = "" + | lowercaseFirst s = String.str (Char.toLower (String.sub (s, 0))) + ^ String.extract (s, 1, NONE) + fun tagStart tag = let - fun lowercaseFirst "" = "" - | lowercaseFirst s = String.str (Char.toLower (String.sub (s, 0))) - ^ String.extract (s, 1, NONE) - val s = (L'.EPrim (Prim.String (String.concat ["<", tag])), loc) in foldl (fn (("Action", _, _), acc) => acc @@ -1897,6 +1897,26 @@ fun monoExp (env, st, fm) (all as (e, loc)) = normal () | _ => normal () end + + fun setAttrs jexp = + let + val s = (L'.EPrim (Prim.String (String.concat ["<", tag])), loc) + + val assgns = List.mapPartial + (fn ("Source", _, _) => NONE + | (x, e, _) => + SOME (strcat [str ("d." ^ lowercaseFirst x ^ "="), + (L'.EJavaScript (L'.Script, e, NONE), loc), + str ";"])) + attrs + in + case assgns of + [] => jexp + | _ => strcat (str "var d=" + :: jexp + :: str ";" + :: assgns) + end in case tag of "body" => normal ("body", NONE, @@ -2002,12 +2022,17 @@ fun monoExp (env, st, fm) (all as (e, loc)) = loc), fm) end | SOME (_, src, _) => - (strcat [str "<script type=\"text/javascript\">inp(\"input\",", - (L'.EJavaScript (L'.Script, src, NONE), loc), - str ")</script>"], - fm)) - - | "option" => normal ("option", NONE, NONE) + let + val sc = strcat [str "inp(\"input\",", + (L'.EJavaScript (L'.Script, src, NONE), loc), + str ")"] + val sc = setAttrs sc + in + (strcat [str "<script type=\"text/javascript\">", + sc, + str "</script>"], + fm) + end) | "tabl" => normal ("table", NONE, NONE) | _ => normal (tag, NONE, NONE) diff --git a/tests/ctextbox.ur b/tests/ctextbox.ur new file mode 100644 index 00000000..c2a322e3 --- /dev/null +++ b/tests/ctextbox.ur @@ -0,0 +1,7 @@ +fun main () : transaction page = + s <- source "Initial"; + return <xml><body> + <ctextbox source={s} size=5/> + + <dyn signal={s <- signal s; return (cdata s)}/> + </body></xml> diff --git a/tests/ctextbox.urp b/tests/ctextbox.urp new file mode 100644 index 00000000..93c828ac --- /dev/null +++ b/tests/ctextbox.urp @@ -0,0 +1,3 @@ +debug + +ctextbox |