aboutsummaryrefslogtreecommitdiff
path: root/editor/editor.ml
diff options
context:
space:
mode:
Diffstat (limited to 'editor/editor.ml')
-rwxr-xr-xeditor/editor.ml47
1 files changed, 17 insertions, 30 deletions
diff --git a/editor/editor.ml b/editor/editor.ml
index d5ae84b..c32a5ba 100755
--- a/editor/editor.ml
+++ b/editor/editor.ml
@@ -1,12 +1,12 @@
open Js_of_ocaml
open Brr
-let create_new_state pm pm_model pm_state mySchema content =
+let create_new_state pm mySchema content =
let module PM = Prosemirror in
let doc = PM.Model.(
DOMParser.parse
- (DOMParser.from_schema pm_model mySchema)
+ (DOMParser.from_schema pm mySchema)
(Jv.Id.of_jv content)) in
let props = PM.State.creation_prop () in
@@ -14,7 +14,7 @@ let create_new_state pm pm_model pm_state mySchema content =
props##.plugins := Js.some (PM.example_setup pm mySchema);
PM.State.create
- pm_state
+ pm
props
let storage_key = (Jstr.v "editor")
@@ -25,40 +25,27 @@ let prosemirror id content =
let module PM = Prosemirror in
let pm = PM.v () in
- let ( let+ ) o f = Option.iter f o
- and ( and+ ) a b =
- match a, b with
- | Some a, Some b -> Some (a, b)
- | _ -> None
+ let specs = PM.Model.schema_spec
+ (PM.SchemaList.add_list_nodes
+ pm
+ ((PM.SchemaBasic.schema pm)##.spec##.nodes)
+ (Jstr.v "paragraph block*")
+ (Some (Jstr.v "block")))
+ (Some (PM.SchemaBasic.schema pm)##.spec##.marks)
+ None in
- in
-
- let+ pm_state = J.get pm PM.state
- and+ pm_view = J.get pm PM.view
- and+ pm_model = J.get pm PM.model
- and+ schema_basic = J.get pm PM.schema_basic
- and+ schema_list = J.get pm PM.schema_list
-
- in
-
- let _ = schema_basic
- and _ = schema_list in
-
- let mySchema = Js_of_ocaml.Js.Unsafe.eval_string {|new PM.model.Schema({
- nodes: PM.schema_list.addListNodes(PM.schema_basic.schema.spec.nodes, "paragraph block*", "block"),
- marks: PM.schema_basic.schema.spec.marks
- })|} in
+ let mySchema = PM.Model.schema pm specs in
(* Create the initial state *)
let storage = Brr_io.Storage.local G.window in
let opt_data = Brr_io.Storage.get_item storage storage_key in
let state = match opt_data with
- | None -> create_new_state pm pm_model pm_state mySchema content
+ | None -> create_new_state pm mySchema content
| Some contents ->
(* Try to load from the storage *)
begin match Json.decode contents with
- | Error _ -> create_new_state pm pm_model pm_state mySchema content
+ | Error _ -> create_new_state pm mySchema content
| Ok json ->
Console.(log [Jstr.v "Loading json"]);
@@ -68,8 +55,8 @@ let prosemirror id content =
let obj = PM.State.configuration_prop () in
obj##.plugins := Js.some (PM.example_setup pm mySchema);
- obj##.schema := mySchema;
- PM.State.fromJSON pm_state obj json
+ obj##.schema := Js.some mySchema;
+ PM.State.fromJSON pm obj json
end
in
@@ -84,7 +71,7 @@ let prosemirror id content =
let view = PM.View.editor_view
- pm_view
+ pm
(Jv.Id.of_jv id)
props in