···1+module State = struct
2+3+ module Config = struct
4+ type t = Jv.t
5+6+ let create ?doc ?selection ?extensions () =
7+ let o = Jv.obj [||] in
8+ Jv.Jstr.set_if_some o "doc" doc;
9+ Jv.set_if_some o "selection" selection;
10+ Jv.set_if_some o "extensions" (Option.map (Jv.of_array Extension.to_jv) extensions);
11+ o
12+ end
13+14+ type t = Jv.t
15+16+ include (Jv.Id : Jv.CONV with type t := t)
17+18+ let create ?(config = Jv.undefined) () =
19+ let editor_state = Jv.get Jv.global "__CM__state" in
20+ Jv.call editor_state "create" [| config |]
21+end
22+23+module View = struct
24+ type t = Jv.t
25+26+ include (Jv.Id : Jv.CONV with type t := t)
27+28+ type opts = Jv.t
29+30+ let opts ?state ?root ?dispatch ?parent () =
31+ let o = Jv.obj [||] in
32+ Jv.set_if_some o "state" state;
33+ Jv.set_if_some o "root" (Option.map Brr.Document.to_jv root);
34+ Jv.set_if_some o "dispatch" dispatch;
35+ Jv.set_if_some o "parent" (Option.map Brr.El.to_jv parent);
36+ o
37+38+ let create ?(opts = Jv.undefined) () =
39+ Jv.new' (Jv.get Jv.global "__CM__view") [| opts |]
40+41+ (* TODO *)
42+ module Update = struct
43+ type t = Jv.t
44+ include (Jv.Id : Jv.CONV with type t := t)
45+ end
46+end
+35
src/editor.mli
···00000000000000000000000000000000000
···1+module State : sig
2+ type t
3+4+ include Jv.CONV with type t := t
5+6+ module Config : sig
7+ type t
8+9+ (* TODO: Add selection *)
10+ val create : ?doc:Jstr.t -> ?selection:Jv.t -> ?extensions:Extension.t array -> unit -> t
11+ end
12+13+ val create : ?config:Config.t -> unit -> t
14+end
15+16+module View : sig
17+ type t
18+ (** Editor view *)
19+20+ include Jv.CONV with type t := t
21+22+ type opts
23+ (** Configurable options for the editor view *)
24+25+ (* TODO: Dispatch function *)
26+ val opts : ?state:State.t -> ?root:Brr.El.document -> ?dispatch:Jv.t -> ?parent:Brr.El.t -> unit -> opts
27+28+ val create : ?opts:opts -> unit -> t
29+ (** Create a new view *)
30+31+ module Update : sig
32+ type t
33+ include Jv.CONV with type t := t
34+ end
35+end
+3
src/extension.ml
···000
···1+type t = Jv.t
2+3+include (Jv.Id : Jv.CONV with type t := t)
+4
src/extension.mli
···0000
···1+type t
2+(** Extensions for the editor *)
3+4+include Jv.CONV with type t := t
+13
src/panel.ml
···0000000000000
···1+open Brr
2+type t = Jv.t
3+4+include (Jv.Id : Jv.CONV with type t := t)
5+6+let create ?mount ?update ?top ?pos dom =
7+ let o = Jv.obj [||] in
8+ Jv.set_if_some o "mount" (Option.map Jv.repr mount);
9+ 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);
10+ Jv.Bool.set_if_some o "top" top;
11+ Jv.Int.set_if_some o "pos" pos;
12+ Jv.set o "dom" (El.to_jv dom);
13+ o
+7
src/panel.mli
···0000000
···1+type t
2+(** Editor panels *)
3+4+include Jv.CONV with type t := t
5+6+7+val create : ?mount:(unit -> unit) -> ?update:(Editor.View.Update.t -> unit) -> ?top:bool -> ?pos:int -> Brr.El.t -> t
+13
src/text.ml
···0000000000000
···1+module Line = struct
2+ type t = Jv.t
3+4+ let from t = Jv.Int.get t "from"
5+ let to_ t = Jv.Int.get t "to"
6+7+ let number t = Jv.Int.get t "number"
8+9+ let text t = Jv.Jstr.get t "text"
10+11+ let length t = Jv.Int.get t "length"
12+end
13+
+20
src/text.mli
···00000000000000000000
···1+module Line : sig
2+ type t
3+ (** A text line *)
4+5+ val from : t -> int
6+ (** Position of the start of the line *)
7+8+ val to_ : t -> int
9+ (** Position at the end of the line before the line break *)
10+11+ val number : t -> int
12+ (** Line's number (1-based) *)
13+14+ val text : t -> Jstr.t
15+ (** Line's text *)
16+17+ val length : t -> int
18+ (** The length of the line *)
19+ end
20+