From f4a59ed2811d4dca2daad58d083078c01488dd11 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Mon, 7 Feb 2022 15:54:32 +0100 Subject: Added prosemirror deps --- editor/prosemirror/prosemirror.ml | 119 +++++++++++++++++++------------------- 1 file changed, 58 insertions(+), 61 deletions(-) (limited to 'editor/prosemirror/prosemirror.ml') 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 -- cgit v1.2.3