From 56bb9e88d05ec7af35d003e1801122c15465555a Mon Sep 17 00:00:00 2001 From: Sylvain Boilard Date: Wed, 6 Nov 2024 07:52:16 +0100 Subject: [PATCH] Lib: Add `detailsElement` and `toggleEvent` objects. (#1728) See: - https://html.spec.whatwg.org/multipage/interactive-elements.html#the-details-element ; - https://html.spec.whatwg.org/multipage/indices.html#event-toggle ; - https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details#attributes ; - https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details#events . --- CHANGES.md | 1 + lib/js_of_ocaml/dom_html.ml | 22 ++++++++++++++++++++++ lib/js_of_ocaml/dom_html.mli | 22 ++++++++++++++++++++++ lib/tyxml/tyxml_cast.ml | 6 ++++-- lib/tyxml/tyxml_cast_sigs.ml | 6 ++++-- lib/tyxml/tyxml_cast_sigs.mli | 6 ++++-- 6 files changed, 57 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 0e39ba7f9e..f4c9358851 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -24,6 +24,7 @@ * Runtime: allow dynlink of precompiled js with separate compilation (#1676) * Runtime: reimplement the runtime of weak and ephemeron (#1707) * Lib: Modify Typed_array API for compatibility with WebAssembly +* Lib: add details element and toggle event (#1728) * Toplevel: no longer set globals for toplevel initialization ## Bug fixes diff --git a/lib/js_of_ocaml/dom_html.ml b/lib/js_of_ocaml/dom_html.ml index a58215b441..ed556ee037 100644 --- a/lib/js_of_ocaml/dom_html.ml +++ b/lib/js_of_ocaml/dom_html.ml @@ -452,6 +452,14 @@ and clipboardEvent = object method clipboardData : dataTransfer t readonly_prop end +and toggleEvent = object + inherit event + + method newState : js_string t readonly_prop + + method oldState : js_string t readonly_prop +end + and dataTransfer = object method dropEffect : js_string t prop @@ -959,6 +967,8 @@ module Event = struct let waiting = Dom.Event.make "waiting" + let toggle = Dom.Event.make "toggle" + let make = Dom.Event.make end @@ -1372,6 +1382,16 @@ class type anchorElement = object method _type : js_string t prop end +class type detailsElement = object ('self) + inherit element + + method open_ : bool t prop + + method name : js_string t prop + + method ontoggle : ('self t, toggleEvent t) event_listener prop +end + class type imageElement = object ('self) inherit element @@ -2736,6 +2756,8 @@ module CoerceTo = struct let del e = unsafeCoerce "del" e + let details e = unsafeCoerce "details" e + let div e = unsafeCoerce "div" e let dl e = unsafeCoerce "dl" e diff --git a/lib/js_of_ocaml/dom_html.mli b/lib/js_of_ocaml/dom_html.mli index 000778d8bf..5e00793cd0 100644 --- a/lib/js_of_ocaml/dom_html.mli +++ b/lib/js_of_ocaml/dom_html.mli @@ -458,6 +458,14 @@ and clipboardEvent = object method clipboardData : dataTransfer t readonly_prop end +and toggleEvent = object + inherit event + + method newState : js_string t readonly_prop + + method oldState : js_string t readonly_prop +end + and dataTransfer = object method dropEffect : js_string t prop @@ -1190,6 +1198,16 @@ class type anchorElement = object method _type : js_string t prop end +class type detailsElement = object ('self) + inherit element + + method open_ : bool t prop + + method name : js_string t prop + + method ontoggle : ('self t, toggleEvent t) event_listener prop +end + class type imageElement = object ('self) inherit element @@ -2503,6 +2521,8 @@ module Event : sig val waiting : mediaEvent t typ + val toggle : toggleEvent t typ + val make : string -> 'a typ end @@ -3048,6 +3068,8 @@ module CoerceTo : sig val del : #element t -> modElement t opt + val details : #element t -> detailsElement t opt + val div : #element t -> divElement t opt val embed : #element t -> embedElement t opt diff --git a/lib/tyxml/tyxml_cast.ml b/lib/tyxml/tyxml_cast.ml index 53c21ffec2..9e3cad874f 100644 --- a/lib/tyxml/tyxml_cast.ml +++ b/lib/tyxml/tyxml_cast.ml @@ -79,6 +79,8 @@ end) : Tyxml_cast_sigs.TO with type 'a elt = 'a C.elt = struct let of_li elt = rebuild_node "of_li" elt + let of_details elt = rebuild_node "of_details" elt + let of_dialog elt = rebuild_node "of_dialog" elt let of_div elt = rebuild_node "of_div" elt @@ -177,8 +179,6 @@ end) : Tyxml_cast_sigs.TO with type 'a elt = 'a C.elt = struct let of_dd elt = rebuild_node "of_dd" elt - let of_details elt = rebuild_node "of_details" elt - let of_dfn elt = rebuild_node "of_dfn" elt let of_dt elt = rebuild_node "of_dt" elt @@ -311,6 +311,8 @@ end) : Tyxml_cast_sigs.OF with type 'a elt = 'a C.elt = struct let of_li elt = rebuild_node "of_li" elt + let of_details elt = rebuild_node "of_details" elt + let of_dialog elt = rebuild_node "of_dialog" elt let of_div elt = rebuild_node "of_div" elt diff --git a/lib/tyxml/tyxml_cast_sigs.ml b/lib/tyxml/tyxml_cast_sigs.ml index 08d8605ce3..a6ea2b76cb 100644 --- a/lib/tyxml/tyxml_cast_sigs.ml +++ b/lib/tyxml/tyxml_cast_sigs.ml @@ -71,6 +71,8 @@ module type OF = sig val of_li : Dom_html.liElement Js.t -> [> Html_types.li ] elt + val of_details : Dom_html.detailsElement Js.t -> [> Html_types.details ] elt + val of_dialog : Dom_html.dialogElement Js.t -> [> Html_types.dialog ] elt val of_div : Dom_html.divElement Js.t -> [> Html_types.div ] elt @@ -182,6 +184,8 @@ module type TO = sig val of_li : [< Html_types.li ] elt -> Dom_html.liElement Js.t + val of_details : [< Html_types.details ] elt -> Dom_html.detailsElement Js.t + val of_dialog : [< Html_types.dialog ] elt -> Dom_html.dialogElement Js.t val of_div : [< Html_types.div ] elt -> Dom_html.divElement Js.t @@ -280,8 +284,6 @@ module type TO = sig val of_dd : [> Html_types.dd ] elt -> Dom_html.element Js.t - val of_details : [> Html_types.details ] elt -> Dom_html.element Js.t - val of_dfn : [> Html_types.dfn ] elt -> Dom_html.element Js.t val of_dt : [> Html_types.dt ] elt -> Dom_html.element Js.t diff --git a/lib/tyxml/tyxml_cast_sigs.mli b/lib/tyxml/tyxml_cast_sigs.mli index 42007a2ec5..a097316749 100644 --- a/lib/tyxml/tyxml_cast_sigs.mli +++ b/lib/tyxml/tyxml_cast_sigs.mli @@ -70,6 +70,8 @@ module type OF = sig val of_li : Dom_html.liElement Js.t -> [> Html_types.li ] elt + val of_details : Dom_html.detailsElement Js.t -> [> Html_types.details ] elt + val of_dialog : Dom_html.dialogElement Js.t -> [> Html_types.dialog ] elt val of_div : Dom_html.divElement Js.t -> [> Html_types.div ] elt @@ -181,6 +183,8 @@ module type TO = sig val of_li : [< Html_types.li ] elt -> Dom_html.liElement Js.t + val of_details : [< Html_types.details ] elt -> Dom_html.detailsElement Js.t + val of_dialog : [< Html_types.dialog ] elt -> Dom_html.dialogElement Js.t val of_div : [< Html_types.div ] elt -> Dom_html.divElement Js.t @@ -279,8 +283,6 @@ module type TO = sig val of_dd : [> Html_types.dd ] elt -> Dom_html.element Js.t - val of_details : [> Html_types.details ] elt -> Dom_html.element Js.t - val of_dfn : [> Html_types.dfn ] elt -> Dom_html.element Js.t val of_dt : [> Html_types.dt ] elt -> Dom_html.element Js.t