aboutsummaryrefslogtreecommitdiff
path: root/editor/j/j.ml
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@chimrod.com>2021-01-31 04:21:01 +0100
committerSébastien Dailly <sebastien@dailly.me>2022-02-07 16:43:33 +0100
commitd17d17261faccb3eb42e91f88ca035e5b1730c66 (patch)
tree28424d286bda347aee77528ece79907026b2e35b /editor/j/j.ml
parent1961a9779b482cf9cbdb3365137c2e74423067c6 (diff)
Bindings to prosemirror
Diffstat (limited to 'editor/j/j.ml')
-rwxr-xr-xeditor/j/j.ml47
1 files changed, 47 insertions, 0 deletions
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