commit ebf7150f41c64ac0e18e9f89d1e565b6c3115414 Author: Vasilis Papavasileiou Date: Thu Aug 6 11:52:11 2015 +0200 up-to-date version of @drup's new-style wrapping (ocsigen/tyxml#58) diff --git a/lib/tyxml/tyxml_js.ml b/lib/tyxml/tyxml_js.ml index 0143219..4799600 100644 --- a/lib/tyxml/tyxml_js.ml +++ b/lib/tyxml/tyxml_js.ml @@ -20,8 +20,19 @@ let js_string_of_float f = (Js.number_of_float f)##toString() let js_string_of_int i = (Js.number_of_float (float_of_int i))##toString() + +module type XML = + Xml_sigs.T + with type uri = string + and type event_handler = Dom_html.event Js.t -> bool + and type mouse_event_handler = Dom_html.mouseEvent Js.t -> bool + and type keyboard_event_handler = Dom_html.keyboardEvent Js.t -> bool + and type elt = Dom.node Js.t + + module Xml = struct + module W = Xml_wrap.NoWrap type 'a wrap = 'a type 'a list_wrap = 'a list @@ -162,7 +173,6 @@ module Xml_wrap = struct let append x y = ReactiveData.RList.concat x y end - module Util = struct open ReactiveData open RList @@ -226,9 +236,23 @@ end module R = struct - module Xml_wed = struct - type 'a wrap = 'a Xml_wrap.t - type 'a list_wrap = 'a Xml_wrap.tlist + + let filter_attrib (name,a) on = + match a with + | Xml.Event _ -> + raise (Invalid_argument "filter_attrib not implemented for event handler") + | Xml.Attr a -> + name, + Xml.Attr + (React.S.l2 + (fun on a -> if on then a else None) on a) + + let attach_attribs = Xml.attach_attribs + + module Xml = struct + module W = Xml_wrap + type 'a wrap = 'a W.t + type 'a list_wrap = 'a W.tlist type uri = Xml.uri let string_of_uri = Xml.string_of_uri let uri_of_string = Xml.uri_of_string @@ -239,7 +263,7 @@ module R = struct type attrib = Xml.attrib let attr name f s = - let a = Xml_wrap.fmap f s in + let a = W.fmap f s in name,Xml.Attr a let float_attrib name s = attr name (fun f -> Some (js_string_of_float f)) s @@ -267,7 +291,7 @@ module R = struct let leaf = Xml.leaf let node ?(a=[]) name l = let e = Dom_html.document##createElement(Js.string name) in - Xml.attach_attribs e a; + attach_attribs e a; Util.update_children (e :> Dom.node Js.t) l; (e :> Dom.node Js.t) let cdata = Xml.cdata @@ -275,30 +299,22 @@ module R = struct let cdata_style = Xml.cdata_style end - module Xml_wed_svg = struct - include Xml_wed + module Xml_Svg = struct + include Xml let leaf = Xml_Svg.leaf let node ?(a = []) name l = let e = Dom_html.document##createElementNS(Dom_svg.xmlns,Js.string name) in - Xml.attach_attribs e a; + attach_attribs e a; Util.update_children (e :> Dom.node Js.t) l; (e :> Dom.node Js.t) end - module Svg = Svg_f.MakeWrapped(Xml_wrap)(Xml_wed_svg) - module Html5 = Html5_f.MakeWrapped(Xml_wrap)(Xml_wed)(Svg) - let filter_attrib (name,a) on = - match a with - | Xml.Event _ -> - raise (Invalid_argument "filter_attrib not implemented for event handler") - | Xml.Attr a -> - name, - Xml.Attr - (React.S.l2 - (fun on a -> if on then a else None) on a) + module Svg = Svg_f.Make(Xml_Svg) + module Html5 = Html5_f.Make(Xml)(Svg) + end module To_dom = Tyxml_cast.MakeTo(struct diff --git a/lib/tyxml/tyxml_js.mli b/lib/tyxml/tyxml_js.mli index b3323cc..8cb33c5 100644 --- a/lib/tyxml/tyxml_js.mli +++ b/lib/tyxml/tyxml_js.mli @@ -37,13 +37,16 @@ @see Html5_sigs.T to have a list of available functions to build HTML. *) -module Xml : Xml_sigs.T +module type XML = + Xml_sigs.T with type uri = string and type event_handler = Dom_html.event Js.t -> bool and type mouse_event_handler = Dom_html.mouseEvent Js.t -> bool and type keyboard_event_handler = Dom_html.keyboardEvent Js.t -> bool and type elt = Dom.node Js.t +module Xml : XML with module W = Xml_wrap.NoWrap + module Xml_wrap : Xml_wrap.T with type 'a t = 'a React.signal and type 'a tlist = 'a ReactiveData.RList.t @@ -57,10 +60,13 @@ module Svg : Svg_sigs.Make(Xml).T module Html5 : Html5_sigs.Make(Xml)(Svg).T module R : sig - module Svg : Svg_sigs.MakeWrapped(Xml_wrap)(Xml).T + module Xml : XML with module W = Xml_wrap + + module Svg : Svg_sigs.Make(Xml).T with type +'a elt = 'a Svg.elt and type +'a attrib = 'a Svg.attrib - module Html5 : Html5_sigs.MakeWrapped(Xml_wrap)(Xml)(Svg).T + + module Html5 : Html5_sigs.Make(Xml)(Svg).T with type +'a elt = 'a Html5.elt and type +'a attrib = 'a Html5.attrib val filter_attrib : 'a Html5.attrib -> bool React.signal -> 'a Html5.attrib