···1+(** Interactive widget support for the OCaml toplevel.
2+3+ Widgets are rendered in the client as HTML elements built from
4+ {!Js_top_worker_message.Widget_view.node} trees. Event handlers in the view
5+ are symbolic string identifiers — when the user interacts with a widget,
6+ the client sends the handler ID and input value back to the worker,
7+ where the registered callback is invoked.
8+9+ Typical usage with Note FRP:
10+ {[
11+ let e, send = Note.E.create ()
12+ let s = Note.S.hold 50 e
13+14+ let () =
15+ Widget.display ~id:"my-slider"
16+ ~handlers:["x", (fun v ->
17+ send (int_of_string (Option.get v)))]
18+ (Js_top_worker_message.Widget_view.Element { tag = "input";
19+ attrs = [Property ("type", "range")];
20+ children = [] })
21+22+ (* Wire up automatic updates via Note: *)
23+ let _logr = Note.S.log
24+ (Note.S.map (fun v -> ... build view ...) s)
25+ (Widget.update ~id:"my-slider")
26+ ]} *)
27+28+val display :
29+ id:string ->
30+ handlers:(string * (string option -> unit)) list ->
31+ Js_top_worker_message.Widget_view.node ->
32+ unit
33+(** [display ~id ~handlers view] registers a widget with the given [id],
34+ installs [handlers] for routing incoming events, and sends the
35+ initial [view] to the client. If a widget with this [id] already
36+ exists, it is replaced. *)
37+38+val update : id:string -> Js_top_worker_message.Widget_view.node -> unit
39+(** [update ~id view] sends an updated view for an existing widget.
40+ The handler map is not changed. *)
41+42+val clear : id:string -> unit
43+(** [clear ~id] removes the widget and its handlers. Sends a
44+ WidgetClear message to the client. *)
45+46+val handle_event :
47+ widget_id:string -> handler_id:string -> value:string option -> unit
48+(** [handle_event ~widget_id ~handler_id ~value] routes an incoming
49+ event to the registered handler. Called by the worker message loop
50+ when a WidgetEvent is received. *)
51+52+val set_sender : (string -> unit) -> unit
53+(** [set_sender f] installs the function used to send JSON strings to
54+ the client. Called once by the worker at startup. The function [f]
55+ should call [Worker.post_message]. *)