aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@dailly.me>2022-02-07 15:39:16 +0100
committerSébastien Dailly <sebastien@dailly.me>2022-02-07 16:43:33 +0100
commit898ae8a6f54418c792f7673298d698e356e8cab6 (patch)
treeb4328d1baaf15507b7500af2f63a606659d83466
parentd17d17261faccb3eb42e91f88ca035e5b1730c66 (diff)
Update editor
-rwxr-xr-xeditor/editor.ml78
-rwxr-xr-xeditor/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);