diff options
author | Sébastien Dailly <sebastien@chimrod.com> | 2021-01-31 04:21:01 +0100 |
---|---|---|
committer | Sébastien Dailly <sebastien@dailly.me> | 2022-02-07 16:43:33 +0100 |
commit | d17d17261faccb3eb42e91f88ca035e5b1730c66 (patch) | |
tree | 28424d286bda347aee77528ece79907026b2e35b /editor/quill.ml | |
parent | 1961a9779b482cf9cbdb3365137c2e74423067c6 (diff) |
Bindings to prosemirror
Diffstat (limited to 'editor/quill.ml')
-rwxr-xr-x | editor/quill.ml | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/editor/quill.ml b/editor/quill.ml new file mode 100755 index 0000000..8069d90 --- /dev/null +++ b/editor/quill.ml @@ -0,0 +1,101 @@ +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|] + + |