123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778open!Coreopen!Js_of_ocamlmoduleArrow_deprecated=structmoduleEffect=EffectmoduleVdom=Import.VdommoduleStart=Start.Arrow_deprecatedmoduleBonsai=Bonsai.Arrow_deprecatedendmoduleStart=Start.ProcmoduleBonsai=Import.BonsaimoduleIncr=Import.IncrmoduleVdom=Import.VdommoduleTo_incr_dom=To_incr_dommoduleEffect=EffectmodulePersistent_var=Persistent_var(* new *)moduleComputation=Bonsai.ComputationmoduleValue=Bonsai.Value(* [am_running_how] provides information on how the code is currently being run:
- [`Node_test] means that the code is being run using node as part of an expect_test
- [`Node_benchmark] means that the code is being run using node as part of a benchmark
- [`Node] means that the code is being run using node, but not as part of an
expect_test or a benchmark
- [`Browser_benchmark] means that the code is being run in the browser as part of a
benchmark
- [`Browser] means that the code is being run in a browser but not as part of a
benchmark
*)letam_running_how:[`Node_test|`Node_benchmark|`Node|`Browser_benchmark|`Browser]=letis_in_browser=Js.Optdef.test(Obj.magicDom_html.document:_Js.Optdef.t)inletis_benchmark=matchSys.getenv"BENCHMARKS_RUNNER"with|Some"TRUE"->true|_->falseinmatchis_in_browser,is_benchmark,Core.am_running_testwith|true,true,_->`Browser_benchmark|true,false,true->Core.raise_s[%message"cannot run tests in a browser"]|true,false,false->`Browser|false,true,_->`Node_benchmark|false,false,true->`Node_test|false,false,false->`Node;;(* [am_within_disabled_fieldset] traverses up the DOM to see whether an event occurred
within a fieldset element with the disabled attribute. As this function requires DOM
interaction, it will return [false] if the code is not running in the browser.
Note: because this function bubbles up from the target of the event, it's possible
that the event occurs within a disabled fieldset, but the form element which performs
this check is not within a disabled fieldset (or vice versa).
For example, mousemove events will originate from the element under the mouse, so if
the mouse is over a different disabled form, [am_within_disabled_fieldset] will be
[true], even if the component which performs this check is not.
*)letam_within_disabled_fieldset(event:#Dom_html.eventJs.t)=matcham_running_howwith|`Node_test|`Node_benchmark|`Node->false|`Browser|`Browser_benchmark->let(event:<composedPath:'aJs.js_arrayJs.tJs.meth;Dom_html.event>Js.t)=Js.Unsafe.coerceeventinJs.to_arrayevent##composedPath|>Array.exists~f:(funelement->lettag_name=Js.Optdef.to_optionelement##.tagNameinletdisabled=Js.Optdef.to_optionelement##.disabledinmatchOption.bothtag_namedisabledwith|None->false|Some(tag_name,disabled)->String.equal(Js.to_stringtag_name)"FIELDSET"&&Js.to_booldisabled);;