···10 cm : Editor.t;
11 worker : Client.t;
12 merlin_worker : Merlin_ext.Client.worker;
013}
1415let id t = t.id
···69 match prev with
70 | None ->
71 Editor.set_previous_lines t.cm 0;
72- refresh_lines_from ~editor:t;
73- run t
74 | Some p ->
75 assert (p.next = None);
76 p.next <- Some t;
77- refresh_lines_from ~editor:p;
78- run t
7980let set_source_from_html editor this =
81 let doc = Webcomponent.text_content this in
···113 ();
114 ]
115116-let init ~id ?extra_style ?inline_style worker this =
117 let shadow = Webcomponent.attach_shadow this in
118 init_css shadow ~extra_style ~inline_style;
119···134 next = None;
135 worker;
136 merlin_worker;
0137 }
138 in
139 Editor.on_change cm (fun () -> invalidate_after ~editor);
···186let receive_merlin t msg =
187 Merlin_ext.Client.on_message t.merlin_worker
188 (Merlin_ext.fix_answer ~pre:(pre_source t) ~doc:(Editor.source t.cm) msg)
00
···10 cm : Editor.t;
11 worker : Client.t;
12 merlin_worker : Merlin_ext.Client.worker;
13+ run_on : [ `Click | `Load ];
14}
1516let id t = t.id
···70 match prev with
71 | None ->
72 Editor.set_previous_lines t.cm 0;
73+ refresh_lines_from ~editor:t
074 | Some p ->
75 assert (p.next = None);
76 p.next <- Some t;
77+ refresh_lines_from ~editor:p
07879let set_source_from_html editor this =
80 let doc = Webcomponent.text_content this in
···112 ();
113 ]
114115+let init ~id ~run_on ?extra_style ?inline_style worker this =
116 let shadow = Webcomponent.attach_shadow this in
117 init_css shadow ~extra_style ~inline_style;
118···133 next = None;
134 worker;
135 merlin_worker;
136+ run_on;
137 }
138 in
139 Editor.on_change cm (fun () -> invalidate_after ~editor);
···186let receive_merlin t msg =
187 Merlin_ext.Client.on_message t.merlin_worker
188 (Merlin_ext.fix_answer ~pre:(pre_source t) ~doc:(Editor.source t.cm) msg)
189+190+let loadable t = t.run_on = `Load
+3
src/cell.mli
···23val init :
4 id:int ->
05 ?extra_style:Jstr.t ->
6 ?inline_style:Jstr.t ->
7 Client.t ->
···14val completed_run : t -> X_protocol.output list -> unit
15val set_prev : prev:t option -> t -> unit
16val receive_merlin : t -> Protocol.answer -> unit
00
···23val init :
4 id:int ->
5+ run_on:[ `Click | `Load ] ->
6 ?extra_style:Jstr.t ->
7 ?inline_style:Jstr.t ->
8 Client.t ->
···15val completed_run : t -> X_protocol.output list -> unit
16val set_prev : prev:t option -> t -> unit
17val receive_merlin : t -> Protocol.answer -> unit
18+val loadable : t -> bool
19+val run : t -> unit
+6-1
src/webcomponent.ml
···18 Jv.set test "prototype" (Jv.get html_element "prototype");
19 Jv.set Jv.global "__xocaml_exported" (Jv.callback ~arity:1 fn);
20 Jv.set (Jv.get test "prototype") "connectedCallback"
21- (jv_pure_js_expr "(function() { return __xocaml_exported(this) })");
022 let _ : Jv.t = Jv.call custom_elements "define" [| Jv.of_jstr name; test |] in
23 ()
2425let text_content t = Jstr.to_string @@ Jv.to_jstr @@ Jv.get t "textContent"
26let as_target t = Brr.El.of_jv t
00002728let attach_shadow t =
29 Brr.El.of_jv
···18 Jv.set test "prototype" (Jv.get html_element "prototype");
19 Jv.set Jv.global "__xocaml_exported" (Jv.callback ~arity:1 fn);
20 Jv.set (Jv.get test "prototype") "connectedCallback"
21+ (jv_pure_js_expr
22+ "(function() { setTimeout(() => __xocaml_exported(this), 0) })");
23 let _ : Jv.t = Jv.call custom_elements "define" [| Jv.of_jstr name; test |] in
24 ()
2526let text_content t = Jstr.to_string @@ Jv.to_jstr @@ Jv.get t "textContent"
27let as_target t = Brr.El.of_jv t
28+29+let get_attribute t name =
30+ let attr = Jv.call t "getAttribute" [| Jv.of_string name |] in
31+ Jv.to_option Jv.to_string attr
3233let attach_shadow t =
34 Brr.El.of_jv
+1
src/webcomponent.mli
···23val define : Jstr.t -> (t -> unit) -> unit
4val text_content : t -> string
05val as_target : t -> Brr.El.t
6val attach_shadow : t -> Brr.El.t
···23val define : Jstr.t -> (t -> unit) -> unit
4val text_content : t -> string
5+val get_attribute : t -> string -> string option
6val as_target : t -> Brr.El.t
7val attach_shadow : t -> Brr.El.t
+11-1
src/x_ocaml.ml
···3940let extra_style = current_attribute "src-style"
41let inline_style = current_attribute "inline-style"
004243let _ =
44 Webcomponent.define elt_name @@ fun this ->
45 let prev = match !all with [] -> None | e :: _ -> Some e in
000000046 let id = List.length !all in
47- let editor = Cell.init ~id ?extra_style ?inline_style worker this in
48 all := editor :: !all;
49 Cell.set_prev ~prev editor;
050 ()
···3940let extra_style = current_attribute "src-style"
41let inline_style = current_attribute "inline-style"
42+let run_on = current_attribute "run-on" |> Option.map Jstr.to_string
43+let run_on_of_string = function "click" -> `Click | "load" | _ -> `Load
4445let _ =
46 Webcomponent.define elt_name @@ fun this ->
47 let prev = match !all with [] -> None | e :: _ -> Some e in
48+ let run_on =
49+ run_on_of_string
50+ @@
51+ match Webcomponent.get_attribute this "run-on" with
52+ | Some s -> s
53+ | None -> Option.value ~default:"load" run_on
54+ in
55 let id = List.length !all in
56+ let editor = Cell.init ~id ~run_on ?extra_style ?inline_style worker this in
57 all := editor :: !all;
58 Cell.set_prev ~prev editor;
59+ if List.for_all Cell.loadable !all then Cell.run editor;
60 ()