diff options
Diffstat (limited to 'editor')
-rwxr-xr-x | editor/editor.ml | 78 | ||||
-rwxr-xr-x | editor/index.html (renamed from editor/editor.html) | 2 |
2 files changed, 1 insertions, 79 deletions
diff --git a/editor/editor.ml b/editor/editor.ml index be15718..d5ae84b 100755 --- a/editor/editor.ml +++ b/editor/editor.ml @@ -1,76 +1,5 @@ open Js_of_ocaml open Brr -open Note - - - -let storage_key = (Jstr.v "content") -(** Save the text into the local storage *) -let save_contents - : Quill.t -> unit - = fun editor -> - let storage = Brr_io.Storage.local G.window in - let contents = Quill.get_contents editor in - Brr_io.Storage.set_item - storage - storage_key - (Json.encode @@ Quill.delta_to_json @@ contents) - |> Console.log_if_error ~use:() - - - -(** Load the content from the cache storage *) -let load_contents - : Quill.t -> unit - = fun editor -> - let storage = Brr_io.Storage.local G.window in - Brr_io.Storage.get_item - storage - storage_key - |> Option.iter (fun contents -> - Json.decode contents - |> Result.map (fun json -> - Quill.delta_of_json json - |> Quill.set_contents editor - ) - |> Console.log_if_error ~use:() - ) - -let quill id = - begin match (Jv.is_none id) with - | true -> Console.(error [str "No element with id '%s' found"; id]) - | false -> - let options = Quill.options () in - J.set options Quill.placeholder (Jstr.v "Nouvelle note…"); - J.set options Quill.theme (Jstr.v "snow"); - - (* Create the editor with the configuration *) - Quill.quill ~options (Jv.Id.of_jv id) - |> Result.iter (fun editor -> - - load_contents editor; - - - let () = Quill.on_text_change editor (fun delta old source -> - let _ = delta - and _ = old - and _ = source - in - () - ) - in - - (* Attach an event on focus out *) - let out_event = Brr_note.Evr.on_el - (Ev.focusout) - (fun _ -> save_contents editor) - (Jv.Id.of_jv id) in - - (* Prevent the event to be garbage collected *) - E.log out_event (fun _ -> ()) - |> Option.iter Logr.hold - ) - end let create_new_state pm pm_model pm_state mySchema content = let module PM = Prosemirror in @@ -183,18 +112,13 @@ let prosemirror id content = | _, _-> Console.(error [str "No element with id '%s' '%s' found"; id ; content]) - - end - - let () = let open Jv in let editor = obj - [| "attach_quill", (repr quill) - ; "attach_prosemirror", (repr prosemirror) + [| "attach_prosemirror", (repr prosemirror) |] in set global "editor" editor diff --git a/editor/editor.html b/editor/index.html index 9048e02..7f3a070 100755 --- a/editor/editor.html +++ b/editor/index.html @@ -117,8 +117,6 @@ <script> var script = document.getElementById('script'); script.addEventListener('load', function() { - var quill = document.getElementById('text-container'); - editor.attach_quill(quill); var prose = document.getElementById('text_editor'); var content = document.getElementById('content'); editor.attach_prosemirror(prose, content); |