···11+module State = struct
22+33+ module Config = struct
44+ type t = Jv.t
55+66+ let create ?doc ?selection ?extensions () =
77+ let o = Jv.obj [||] in
88+ Jv.Jstr.set_if_some o "doc" doc;
99+ Jv.set_if_some o "selection" selection;
1010+ Jv.set_if_some o "extensions" (Option.map (Jv.of_array Extension.to_jv) extensions);
1111+ o
1212+ end
1313+1414+ type t = Jv.t
1515+1616+ include (Jv.Id : Jv.CONV with type t := t)
1717+1818+ let create ?(config = Jv.undefined) () =
1919+ let editor_state = Jv.get Jv.global "__CM__state" in
2020+ Jv.call editor_state "create" [| config |]
2121+end
2222+2323+module View = struct
2424+ type t = Jv.t
2525+2626+ include (Jv.Id : Jv.CONV with type t := t)
2727+2828+ type opts = Jv.t
2929+3030+ let opts ?state ?root ?dispatch ?parent () =
3131+ let o = Jv.obj [||] in
3232+ Jv.set_if_some o "state" state;
3333+ Jv.set_if_some o "root" (Option.map Brr.Document.to_jv root);
3434+ Jv.set_if_some o "dispatch" dispatch;
3535+ Jv.set_if_some o "parent" (Option.map Brr.El.to_jv parent);
3636+ o
3737+3838+ let create ?(opts = Jv.undefined) () =
3939+ Jv.new' (Jv.get Jv.global "__CM__view") [| opts |]
4040+4141+ (* TODO *)
4242+ module Update = struct
4343+ type t = Jv.t
4444+ include (Jv.Id : Jv.CONV with type t := t)
4545+ end
4646+end
+35
src/editor.mli
···11+module State : sig
22+ type t
33+44+ include Jv.CONV with type t := t
55+66+ module Config : sig
77+ type t
88+99+ (* TODO: Add selection *)
1010+ val create : ?doc:Jstr.t -> ?selection:Jv.t -> ?extensions:Extension.t array -> unit -> t
1111+ end
1212+1313+ val create : ?config:Config.t -> unit -> t
1414+end
1515+1616+module View : sig
1717+ type t
1818+ (** Editor view *)
1919+2020+ include Jv.CONV with type t := t
2121+2222+ type opts
2323+ (** Configurable options for the editor view *)
2424+2525+ (* TODO: Dispatch function *)
2626+ val opts : ?state:State.t -> ?root:Brr.El.document -> ?dispatch:Jv.t -> ?parent:Brr.El.t -> unit -> opts
2727+2828+ val create : ?opts:opts -> unit -> t
2929+ (** Create a new view *)
3030+3131+ module Update : sig
3232+ type t
3333+ include Jv.CONV with type t := t
3434+ end
3535+end
+3
src/extension.ml
···11+type t = Jv.t
22+33+include (Jv.Id : Jv.CONV with type t := t)
+4
src/extension.mli
···11+type t
22+(** Extensions for the editor *)
33+44+include Jv.CONV with type t := t
+13
src/panel.ml
···11+open Brr
22+type t = Jv.t
33+44+include (Jv.Id : Jv.CONV with type t := t)
55+66+let create ?mount ?update ?top ?pos dom =
77+ let o = Jv.obj [||] in
88+ Jv.set_if_some o "mount" (Option.map Jv.repr mount);
99+ Jv.set_if_some o "update" (Option.map (fun u -> let u' jv = u (Editor.View.Update.of_jv jv) in u') update |> Option.map Jv.repr);
1010+ Jv.Bool.set_if_some o "top" top;
1111+ Jv.Int.set_if_some o "pos" pos;
1212+ Jv.set o "dom" (El.to_jv dom);
1313+ o
+7
src/panel.mli
···11+type t
22+(** Editor panels *)
33+44+include Jv.CONV with type t := t
55+66+77+val create : ?mount:(unit -> unit) -> ?update:(Editor.View.Update.t -> unit) -> ?top:bool -> ?pos:int -> Brr.El.t -> t
+13
src/text.ml
···11+module Line = struct
22+ type t = Jv.t
33+44+ let from t = Jv.Int.get t "from"
55+ let to_ t = Jv.Int.get t "to"
66+77+ let number t = Jv.Int.get t "number"
88+99+ let text t = Jv.Jstr.get t "text"
1010+1111+ let length t = Jv.Int.get t "length"
1212+end
1313+
+20
src/text.mli
···11+module Line : sig
22+ type t
33+ (** A text line *)
44+55+ val from : t -> int
66+ (** Position of the start of the line *)
77+88+ val to_ : t -> int
99+ (** Position at the end of the line before the line break *)
1010+1111+ val number : t -> int
1212+ (** Line's number (1-based) *)
1313+1414+ val text : t -> Jstr.t
1515+ (** Line's text *)
1616+1717+ val length : t -> int
1818+ (** The length of the line *)
1919+ end
2020+