open Brr type t = Jv.t type options let bounds : (options, El.t) J.prop = J.prop "bounds" let debug : (options, Jstr.t) J.prop = J.prop "debug" let placeholder : (options, Jstr.t) J.prop = J.prop "placeholder" let readonly : (options, Jstr.t) J.prop = J.prop "readonly" let theme : (options, Jstr.t) J.prop = J.prop "theme" let scrollingContainer : (options, El.t) J.prop = J.prop "scrollingContainer" let options : unit -> options = Jv.Id.of_jv @@ Jv.obj' [||] (** Constructor. [quill element] will create the editor inside the given element *) let quill : ?options:options -> El.t -> (t, Jv.Error.t) Result.t = fun ?options element -> let quill = Jv.get Jv.global "Quill" in let options = Jv.of_option ~none:Jv.undefined Jv.Id.to_jv options in match Jv.new' quill Jv.Id.[| to_jv element; options |] with | exception Jv.Error e -> Error e | v -> Ok v type delta = Jv.t let delta_to_json : delta -> Brr.Json.t = Jv.Id.to_jv let delta_of_json : Brr.Json.t -> delta = Jv.Id.of_jv (* Operations is an array *) type operations = Jv.t let ops : (delta, operations) J.prop = J.prop "ops" (** Return the editor content *) let get_contents : t -> delta = fun t -> Jv.call t "getContents" [||] let set_contents : t -> delta -> unit = fun t contents -> ignore @@ Jv.call t "setContents" [|contents|] (** [extract_content t index length] return the content starting from index, with length elements *) let extract_contents : t -> int -> int -> delta = fun t index length -> Jv.call t "getContents" [|Jv.of_int index; Jv.of_int length|] let on_text_change : t -> (string -> string -> string -> unit) -> unit = fun t callback -> ignore @@ Jv.call t "on" [|Jv.Id.to_jv @@ Jstr.v "text-change" ; Jv.repr callback|] (* [update_contents t delta] replace the content with the commands given by delta. *) let update_contents : t -> delta -> delta = fun t delta -> Jv.call t "updateContents" [|delta|]