From 898ae8a6f54418c792f7673298d698e356e8cab6 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Mon, 7 Feb 2022 15:39:16 +0100 Subject: Update editor --- editor/editor.html | 156 ----------------------------------------------------- editor/editor.ml | 78 +-------------------------- editor/index.html | 154 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 155 insertions(+), 233 deletions(-) delete mode 100755 editor/editor.html create mode 100755 editor/index.html diff --git a/editor/editor.html b/editor/editor.html deleted file mode 100755 index 9048e02..0000000 --- a/editor/editor.html +++ /dev/null @@ -1,156 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Chimrod – Editor - - - - - -
- - - -
-
- -

Editor

-
-
-
- - - - - - - - - - - - - -
-
-
- -
-

©

-

-

-
- - - - - - - - - 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/index.html b/editor/index.html new file mode 100755 index 0000000..7f3a070 --- /dev/null +++ b/editor/index.html @@ -0,0 +1,154 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Chimrod – Editor + + + + + +
+ + + +
+
+ +

Editor

+
+
+
+ + + + + + + + + + + + + +
+
+
+ +
+

©

+

+

+
+ + + + + + + + + -- cgit v1.2.3