···1111 o
1212 end
13131414+ module type Facet = sig
1515+ type t
1616+ include Jv.CONV with type t := t
1717+ type input
1818+ type output
1919+2020+ val of_ : t -> input -> Extension.t
2121+ end
2222+2323+ module FacetMaker (I : sig type t val to_jv : t -> Jv.t end) : (Facet with type input = I.t and type output = Jv.t) = struct
2424+ type t = Jv.t
2525+2626+ include (Jv.Id : Jv.CONV with type t := t)
2727+2828+ type input = I.t
2929+ type output = Jv.t
3030+3131+ let of_ t i =
3232+ Jv.call t "of" [| I.to_jv i |] |> Extension.of_jv
3333+ end
3434+3535+ type ('i, 'o) facet = Facet : (module Facet with type input = 'i and type output = 'o and type t = 'a) * 'a -> ('i, 'o) facet
3636+1437 type t = Jv.t
15381639 include (Jv.Id : Jv.CONV with type t := t)
···2245 let doc t = Jv.get t "doc" |> Text.of_jv
2346end
24474848+(* Helper for function *)
4949+module Func (I : sig type t include Jv.CONV with type t := t end) = struct
5050+ type t = I.t -> unit
5151+ let to_jv f = Jv.repr f
5252+end
5353+2554module View = struct
2655 type t = Jv.t
2756···3766 Jv.set_if_some o "parent" (Option.map Brr.El.to_jv parent);
3867 o
39686969+ let g = Jv.get Jv.global "__CM__view"
7070+4071 let create ?(opts = Jv.undefined) () =
4141- Jv.new' (Jv.get Jv.global "__CM__view") [| opts |]
7272+ Jv.new' g [| opts |]
42734374 let state t = Jv.get t "state" |> State.of_jv
44754576 let set_state t v = Jv.call t "setState" [| State.to_jv v |] |> ignore
4646-4747- (* TODO *)
4877 module Update = struct
4978 type t = Jv.t
50798080+ let state t = State.of_jv @@ Jv.get t "state"
8181+5182 include (Jv.Id : Jv.CONV with type t := t)
5283 end
8484+8585+ let update_listener _ : (Update.t -> unit, Jv.t) State.facet =
8686+ let module F = State.FacetMaker (Func(Update)) in
8787+ let jv = Jv.get g "updateListener" in
8888+ Facet ((module F), F.of_jv jv)
8989+9090+ let line_wrapping () = Jv.get g "lineWrapping" |> Extension.of_jv
5391end
+19
src/editor.mli
···1515 t
1616 end
17171818+ module type Facet = sig
1919+ type t
2020+ include Jv.CONV with type t := t
2121+ type input
2222+ type output
2323+2424+ val of_ : t -> input -> Extension.t
2525+ end
2626+2727+ module FacetMaker : functor (I : sig type t include Jv.CONV with type t := t end) -> Facet with type input = I.t
2828+2929+ type ('i, 'o) facet = Facet : (module Facet with type input = 'i and type output = 'o and type t = 'a) * 'a -> ('i, 'o) facet
3030+1831 val create : ?config:Config.t -> unit -> t
19322033 val doc : t -> Text.t
···4962 module Update : sig
5063 type t
51646565+ val state : t -> State.t
6666+5267 include Jv.CONV with type t := t
5368 end
6969+7070+ val update_listener : unit -> (Update.t -> unit, Jv.t) State.facet
7171+7272+ val line_wrapping : unit -> Extension.t
5473end