12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667openBaseopenJs_of_ocamlincludeUi_effect(* All visibility handlers see all events, so a simple list is enough. *)letvisibility_handlers:(unit->unit)listref=ref[]moduletypeVisibility_handler=sigvalhandle:unit->unitendmoduleDefine_visibility(VH:Visibility_handler)=structlet()=visibility_handlers:=VH.handle::!visibility_handlersendtype_t+=|Viewport_changed|Stop_propagation|Stop_immediate_propagation|Prevent_defaultletsequence_as_siblingleft~unless_stopped=letreccontains_stop=function|Manyes->List.existses~f:contains_stop|Stop_immediate_propagation->true|_->falseinifcontains_stopleftthenleftelseUi_effect.Many[left;unless_stopped()];;(* We need to keep track of the current dom event here so that
movement between [Vdom.Effect.Expert.handle] and
[Ui_concrete.Effect.Expert.handle] keeps the original
dom event around. *)letcurrent_dom_event=refNonelet()=Hashtbl.add_exnExpert.handlers~key:Caml.Obj.Extension_constructor.(id(of_valViewport_changed))~data:(fun_->List.iter!visibility_handlers~f:(funf->f()));;let()=Hashtbl.add_exnExpert.handlers~key:Caml.Obj.Extension_constructor.(id(of_valStop_propagation))~data:(fun_->Option.iter!current_dom_event~f:Dom_html.stopPropagation);;let()=Hashtbl.add_exnExpert.handlers~key:Caml.Obj.Extension_constructor.(id(of_valPrevent_default))~data:(fun_->Option.iter!current_dom_event~f:Dom.preventDefault);;moduleExpert=structlethandle_non_dom_event_exn=Expert.handlelethandledom_eventevent=letold=!current_dom_eventincurrent_dom_event:=Some(dom_event:>Dom_html.elementDom.eventJs.t);Expert.handleevent;current_dom_event:=old;;end