aboutsummaryrefslogtreecommitdiff
path: root/editor/editor.ml
diff options
context:
space:
mode:
Diffstat (limited to 'editor/editor.ml')
-rwxr-xr-xeditor/editor.ml58
1 files changed, 3 insertions, 55 deletions
diff --git a/editor/editor.ml b/editor/editor.ml
index 19480e2..1c2b8a5 100755
--- a/editor/editor.ml
+++ b/editor/editor.ml
@@ -2,55 +2,6 @@ open Js_of_ocaml
open Brr
module PM = Prosemirror
-let create_new_state pm mySchema content =
- let module PM = Prosemirror in
-
- let doc = PM.Model.(
- DOMParser.parse
- (DOMParser.from_schema pm mySchema)
- (Jv.Id.of_jv content)) in
-
- let props = PM.State.creation_prop () in
- props##.doc := Js.some doc;
- props##.plugins := Plugins.default pm mySchema;
-
- PM.State.create
- pm
- props
-
-let storage_key = (Jstr.v "editor")
-
-let storage = Brr_io.Storage.local G.window
-
-(** Read the state from the local storage, or load the content from the given
- element *)
-let load_storage
- : PM.t -> PM.Model.schema Js.t -> Jv.t -> PM.State.editor_state Js.t
- = fun pm schema content ->
- let opt_data = Brr_io.Storage.get_item storage storage_key in
- match opt_data with
- | None -> create_new_state pm schema content
- | Some contents ->
- (* Try to load from the storage *)
- match Json.decode contents with
- | Error _ -> create_new_state pm schema content
- | Ok json ->
- let obj = PM.State.configuration_prop () in
- obj##.plugins := Plugins.default pm schema;
- obj##.schema := Js.some schema;
- PM.State.fromJSON pm obj json
-
-let save_storage
- : PM.View.editor_view Js.t -> unit
- = fun view ->
- let contents = view##.state##toJSON () in
- let storage = Brr_io.Storage.local G.window in
- Brr_io.Storage.set_item
- storage
- storage_key
- (Json.encode @@ contents)
- |> Console.log_if_error ~use:()
-
let prosemirror id content =
begin match (Jv.is_none id), (Jv.is_none content) with
| false, false ->
@@ -61,8 +12,6 @@ let prosemirror id content =
let schema = (PM.SchemaBasic.schema pm) in
let schema = Footnotes.footnote_schema pm schema in
- Console.(log [ schema ]);
-
let specs = PM.Model.schema_spec
(PM.SchemaList.add_list_nodes
pm
@@ -74,7 +23,7 @@ let prosemirror id content =
let mySchema = PM.Model.schema pm specs in
(* Create the initial state *)
- let state = load_storage pm mySchema content in
+ let state = Storage.load pm mySchema content in
let props = PM.View.direct_editor_props () in
props##.state := state;
@@ -90,16 +39,15 @@ let prosemirror id content =
let nodes = PM.O.init
[| ("footnote", view') |] in
props##.nodeViews := nodes;
-
let view = PM.View.editor_view
pm
(Jv.Id.of_jv id)
props in
- Console.(log [Jstr.v "main view"; view]);
+
(* Attach an event on focus out *)
let _ = Brr_note.Evr.on_el
(Ev.focusout)
- (fun _ -> save_storage view)
+ (fun _ -> Storage.save view)
(Jv.Id.of_jv id) in
()