aboutsummaryrefslogtreecommitdiff
path: root/editor/prosemirror
diff options
context:
space:
mode:
Diffstat (limited to 'editor/prosemirror')
-rwxr-xr-xeditor/prosemirror/bindings.ml98
-rwxr-xr-xeditor/prosemirror/dune1
-rwxr-xr-xeditor/prosemirror/prosemirror.ml119
-rwxr-xr-xeditor/prosemirror/prosemirror.mli67
4 files changed, 178 insertions, 107 deletions
diff --git a/editor/prosemirror/bindings.ml b/editor/prosemirror/bindings.ml
index d2ef2e6..08db819 100755
--- a/editor/prosemirror/bindings.ml
+++ b/editor/prosemirror/bindings.ml
@@ -1,14 +1,53 @@
open Js_of_ocaml.Js
+class type ['a] ordered_map = object ('this)
+
+ method get:
+ Jstr.t -> 'a t opt meth
+
+ method update:
+ Jstr.t -> 'a t -> Jstr.t opt -> 'this meth
+
+ method remove:
+ Jstr.t -> 'this meth
+
+ method addToStart:
+ Jstr.t -> 'a t -> 'this meth
+
+ method addToEnd:
+ Jstr.t -> 'a t -> 'this meth
+
+end
+
module Model = struct
type mark
- type schema
+ type node_spec
+
+ type mark_spec
- type content_match
+ class type schema_spec = object ('this)
- type node_spec
+ method nodes:
+ node_spec ordered_map t readonly_prop
+
+ method marks:
+ mark_spec ordered_map t readonly_prop
+
+ method topNode:
+ Jstr.t opt readonly_prop
+
+ end
+
+ class type schema = object ('this)
+
+ method spec:
+ schema_spec t prop
+
+ end
+
+ type content_match
type slice
@@ -43,7 +82,7 @@ module Model = struct
inherit _node_props
method name:
- string readonly_prop
+ Jstr.t readonly_prop
method schema:
schema t readonly_prop
@@ -363,6 +402,57 @@ module View = struct
end
+module SchemaBasic = struct
+
+ class type nodes = object ('this)
+
+ method doc:
+ Model.node_spec t prop
+
+ method paragraph:
+ Model.node_spec t prop
+
+ method blockquote:
+ Model.node_spec t prop
+
+ method horizontal_rule:
+ Model.node_spec t prop
+
+ method heading:
+ Model.node_spec t prop
+
+ method code_block:
+ Model.node_spec t prop
+
+ method text:
+ Model.node_spec t prop
+
+ method image:
+ Model.node_spec t prop
+
+ method hard_break:
+ Model.node_spec t prop
+
+ end
+
+ class type marks = object ('this)
+
+ method link:
+ Model.mark_spec t prop
+
+ method em:
+ Model.mark_spec t prop
+
+ method strong:
+ Model.mark_spec t prop
+
+ method code:
+ Model.mark_spec t prop
+
+ end
+
+end
+
module History = struct
class type history_prop = object ('this)
diff --git a/editor/prosemirror/dune b/editor/prosemirror/dune
index 4fff7b2..730af26 100755
--- a/editor/prosemirror/dune
+++ b/editor/prosemirror/dune
@@ -3,7 +3,6 @@
(libraries
brr
js_of_ocaml
- j
)
(preprocess (pps js_of_ocaml-ppx))
)
diff --git a/editor/prosemirror/prosemirror.ml b/editor/prosemirror/prosemirror.ml
index bf72227..c19abe0 100755
--- a/editor/prosemirror/prosemirror.ml
+++ b/editor/prosemirror/prosemirror.ml
@@ -8,57 +8,53 @@ let v
= fun () ->
Jv.get Jv.global "PM"
-type pm_schema
-
-type pm_state = Jv.t
-
-type pm_view = Jv.t
-
-
-let state
- : (t, pm_state) J.prop
- = J.prop "state"
-
-let view
- : (t, pm_view) J.prop
- = J.prop "view"
-
-type schema
-
-let schema_basic
- : (t, Jv.t) J.prop
- = J.prop "schema_basic"
-
-(* Model *)
-
-type pm_model = Jv.t
-
-let model
- : (t, pm_model) J.prop
- = J.prop "model"
-
module Model = struct
include Bindings.Model
module DOMParser = struct
- type t = Jv.t
+ type parser = Jv.t
let from_schema
- : pm_model -> schema Js.t -> t
- = fun model schema ->
+ : t -> schema Js.t -> parser
+ = fun t schema ->
+ let model = Jv.get t "model" in
let parser = Jv.get model "DOMParser" in
Jv.call (Jv.Id.to_jv parser) "fromSchema" [|Jv.Id.to_jv schema|]
let parse
- : t -> El.t -> node Js.t
+ : parser -> El.t -> node Js.t
= fun dom_parser el ->
Jv.call dom_parser "parse" [|Jv.Id.to_jv el|]
|> Jv.Id.of_jv
end
+ let schema_spec:
+ node_spec Bindings.ordered_map Js.t
+ -> mark_spec Bindings.ordered_map Js.t option
+ -> string option
+ -> schema_spec Js.t
+ = fun nodes marks_opt topNode_opt ->
+ let marks = Jv.of_option ~none:Jv.null Jv.Id.to_jv marks_opt
+ and topNode = Jv.of_option ~none:Jv.null Jv.of_string topNode_opt in
+ Jv.obj
+ [| "nodes", (Jv.Id.to_jv nodes)
+ ; "marks", marks
+ ; "topNode", topNode
+ |]
+ |> Jv.Id.of_jv
+
+
+ let schema
+ : t -> schema_spec Js.t -> schema Js.t
+ = fun t spec ->
+ let model = Jv.get t "model" in
+ Jv.new' (Jv.get model "Schema") [| Jv.Id.to_jv spec |]
+ |> Jv.Id.of_jv
+
+
let empty_fragment
: t -> fragment Js.t
= fun t ->
@@ -69,13 +65,6 @@ module Model = struct
end
-type pm_transform = Jv.t
-
-let transform
- : (t, pm_transform) J.prop
- = J.prop "prosemirror-transform"
-
-
module State = struct
include Bindings.State
@@ -89,15 +78,17 @@ module State = struct
= fun () -> Js_of_ocaml.Js.Unsafe.obj [||]
let create
- : pm_state -> creation_prop Js.t -> editor_state Js.t
- = fun state props ->
+ : t -> creation_prop Js.t -> editor_state Js.t
+ = fun t props ->
+ let state = Jv.get t "state" in
let editor_state = Jv.get state "EditorState" in
Jv.call editor_state "create" [|Jv.Id.to_jv props|]
|> Jv.Id.of_jv
let fromJSON
- : pm_state -> configuration_prop Js_of_ocaml.Js.t -> Brr.Json.t -> editor_state Js.t
- = fun state config json ->
+ : t -> configuration_prop Js_of_ocaml.Js.t -> Brr.Json.t -> editor_state Js.t
+ = fun t config json ->
+ let state = Jv.get t "state" in
let editor_state = Jv.get state "EditorState" in
Jv.call editor_state "fromJSON" [|Jv.Id.to_jv config ; json |]
|> Jv.Id.of_jv
@@ -117,33 +108,39 @@ module View = struct
= fun () -> Js_of_ocaml.Js.Unsafe.obj [||]
let editor_view
- : pm_view -> El.t -> direct_editor_props Js.t -> editor_view Js.t
- = fun view node props ->
+ : t -> El.t -> direct_editor_props Js.t -> editor_view Js.t
+ = fun t node props ->
+ let view = Jv.get t "view" in
Jv.new' (Jv.get view "EditorView") [|Jv.Id.to_jv node ; Jv.Id.to_jv props|]
|> Jv.Id.of_jv
end
-(* Schema list *)
+module SchemaList = struct
+
+ let add_list_nodes
+ : t -> Model.node_spec Bindings.ordered_map Js.t -> Jstr.t -> Jstr.t option -> Model.node_spec Bindings.ordered_map Js.t
+ = fun t nodes item_content list_group_opt ->
+ let schema_list = Jv.get t "schema_list" in
-type schema_list = Jv.t
+ let list_group = Jv.of_option ~none:Jv.null Jv.of_jstr list_group_opt in
-let schema_list
- : (t, schema_list) J.prop
- = J.prop "schema_list"
+ Jv.call schema_list "addListNodes"
+ [|Jv.Id.to_jv nodes
+ ; Jv.of_jstr item_content
+ ; list_group |]
+ |> Jv.Id.of_jv
-module SchemaList = struct
+end
- let js f = Jv.of_jstr @@ Jstr.v f
+module SchemaBasic = struct
- let js_opt = Jv.of_option
- ~none:Jv.null
- js
+ include Bindings.SchemaBasic
- let add_list_nodes
- : schema_list -> ?listGroup:string -> node:Model.node Js.t -> itemContent:string -> unit
- = fun s ?listGroup ~node ~itemContent ->
- Jv.call (Jv.Id.to_jv s) "addListNodes" [|Jv.Id.to_jv node; js itemContent ; js_opt listGroup|]
- |> ignore
+ let schema
+ : t -> Model.schema Js.t
+ = fun t ->
+ Jv.get (Jv.get t "schema_basic") "schema"
+ |> Jv.Id.of_jv
end
diff --git a/editor/prosemirror/prosemirror.mli b/editor/prosemirror/prosemirror.mli
index 1e0e889..aa27bf4 100755
--- a/editor/prosemirror/prosemirror.mli
+++ b/editor/prosemirror/prosemirror.mli
@@ -6,65 +6,41 @@ type t
val v
: unit -> t
-type schema_list
-
-type pm_schema
-
-type pm_state
-
-type pm_view
-
-type pm_model
-
-type pm_transform
-
-val state
- : (t, pm_state) J.prop
-
-val view
- : (t, pm_view) J.prop
-
-val model
- : (t, pm_model) J.prop
-
-type schema
-
-val schema_basic
- : (t, Jv.t) J.prop
-
-val schema_list
- : (t, schema_list) J.prop
-
-
-val transform
- : (t, pm_transform) J.prop
-
-
module rec Model : sig
include module type of Bindings.Model
+ val schema_spec:
+ node_spec Bindings.ordered_map Js.t
+ -> mark_spec Bindings.ordered_map Js.t option
+ -> string option
+ -> schema_spec Js.t
+
+ val schema
+ : t -> schema_spec Js.t -> schema Js.t
module DOMParser : sig
- type t
+
+ type parser
val from_schema
- : pm_model -> schema Js.t -> t
+ : t -> schema Js.t -> parser
val parse
- : t -> El.t -> node Js.t
+ : parser -> El.t -> node Js.t
end
val empty_fragment
: t -> fragment Js.t
+
end
and SchemaList : sig
val add_list_nodes
- : schema_list -> ?listGroup:string -> node:Model.node Js.t -> itemContent:string -> unit
+ : t -> Model.node_spec Bindings.ordered_map Js.t -> Jstr.t -> Jstr.t option -> Model.node_spec Bindings.ordered_map Js.t
end
@@ -81,10 +57,10 @@ and State : sig
: unit -> creation_prop Js.t
val create
- : pm_state -> creation_prop Js.t -> editor_state Js.t
+ : t -> creation_prop Js.t -> editor_state Js.t
val fromJSON
- : pm_state -> configuration_prop Js.t -> Brr.Json.t -> editor_state Js.t
+ : t -> configuration_prop Js.t -> Brr.Json.t -> editor_state Js.t
end
@@ -104,7 +80,16 @@ and View : sig
: unit -> direct_editor_props Js.t
val editor_view
- : pm_view -> El.t -> direct_editor_props Js.t -> editor_view Js.t
+ : t -> El.t -> direct_editor_props Js.t -> editor_view Js.t
+
+end
+
+module SchemaBasic : sig
+
+ include module type of Bindings.SchemaBasic
+
+ val schema
+ : t -> Model.schema Js.t
end