From d17d17261faccb3eb42e91f88ca035e5b1730c66 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Sun, 31 Jan 2021 04:21:01 +0100 Subject: Bindings to prosemirror --- editor/j/dune | 7 +++++++ editor/j/j.ml | 47 +++++++++++++++++++++++++++++++++++++++++++++++ editor/j/j.mli | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100755 editor/j/dune create mode 100755 editor/j/j.ml create mode 100755 editor/j/j.mli (limited to 'editor/j') diff --git a/editor/j/dune b/editor/j/dune new file mode 100755 index 0000000..56e6691 --- /dev/null +++ b/editor/j/dune @@ -0,0 +1,7 @@ +(library + (name j) + (libraries + brr + js_of_ocaml + ) + ) diff --git a/editor/j/j.ml b/editor/j/j.ml new file mode 100755 index 0000000..96b22e0 --- /dev/null +++ b/editor/j/j.ml @@ -0,0 +1,47 @@ +type ('a, 'b) prop = Jv.prop' + +let prop + : string -> ('a, 'b) prop + = Jstr.of_string + +let get + : 'a -> ('a, 'b) prop -> 'b option + = fun obj prop -> + Jv.get' (Jv.Id.to_jv obj) prop + |> Jv.to_option Jv.Id.of_jv + +let set + : 'a -> ('a, 'b) prop -> 'b -> unit + = fun obj prop value -> + Jv.set' + (Jv.Id.to_jv obj) + prop + (Jv.Id.to_jv value) + +(* Objects *) + +type 'a constr = (Jstr.t * Jv.t) + +let c + : ('a, 'b) prop -> 'b -> 'a constr + = fun prop v -> + (prop, Jv.Id.to_jv v) + +let obj + : 'a constr Array.t -> 'a + = fun props -> + Jv.Id.of_jv @@ Jv.obj' props + +(* Arrays *) + +type 'a array = Jv.t + +let to_array + : 'a array -> 'a Array.t + = fun arr -> + Jv.to_array Jv.Id.of_jv arr + +let of_array + : 'a Array.t -> 'a array + = fun arr -> + Jv.of_array Jv.Id.to_jv arr diff --git a/editor/j/j.mli b/editor/j/j.mli new file mode 100755 index 0000000..796bb9d --- /dev/null +++ b/editor/j/j.mli @@ -0,0 +1,32 @@ +(** The type properties *) +type ('a, 'b) prop + +val prop + : string -> ('a, 'b) prop + +val get + : 'a -> ('a, 'b) prop -> 'b option + +val set + : 'a -> ('a, 'b) prop -> 'b -> unit + + +(* Arrays *) + +type 'a array + +val to_array + : 'a array -> 'a Array.t + +val of_array + : 'a Array.t -> 'a array + +(* Object constructor *) + +type 'a constr + +val c + : ('a, 'b) prop -> 'b -> 'a constr + +val obj + : 'a constr Array.t -> 'a -- cgit v1.2.3