From 1eeaf137bd30aff1bef34d05eeec686f6da8959d Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Sun, 23 May 2021 22:09:50 +0200 Subject: Update editor --- editor/state/state.ml | 26 ++++++++++++++++++++++---- editor/state/state.mli | 6 +++++- editor/state/storage.ml | 3 ++- 3 files changed, 29 insertions(+), 6 deletions(-) (limited to 'editor/state') diff --git a/editor/state/state.ml b/editor/state/state.ml index 48b4d58..569f26c 100755 --- a/editor/state/state.ml +++ b/editor/state/state.ml @@ -17,9 +17,7 @@ type t = (** Compare two states together. - The prosemirror elemens are ignored - -*) + The prosemirror elemens are ignored *) let eq s1 s2 = Stdlib.(==) ( s1.editable @@ -66,5 +64,25 @@ let load_page let editor_state = state_of_storage state.pm json state.view##.state##.schema in let () = state.view##updateState editor_state and () = set_title json in - { state with page_id } + + let last_backup = + Js.Opt.case json##.date + (fun () -> state.last_backup ) + (fun v -> v) in + + { state with page_id + ; last_backup } + + +let init + : PM.t -> PM.View.editor_view Js.t -> float -> Jstr.t option -> t + = fun pm view last_backup page_id -> + { editable = true + ; view + ; last_backup + ; page_id + + ; window = [] + ; pm + } diff --git a/editor/state/state.mli b/editor/state/state.mli index e370015..6984067 100755 --- a/editor/state/state.mli +++ b/editor/state/state.mli @@ -1,5 +1,4 @@ module Js = Js_of_ocaml.Js - module Storage = Storage type t = @@ -14,6 +13,7 @@ type t = val eq: t -> t -> bool +(** Update the title element according to the page. *) val set_title : Storage.content Js.t -> unit @@ -22,3 +22,7 @@ val state_of_storage val load_page : Jstr.t option -> t -> Storage.content Js.t -> t + +(** Initialise a new state *) +val init + : Prosemirror.t -> Prosemirror.View.editor_view Js.t -> float -> Jstr.t option -> t diff --git a/editor/state/storage.ml b/editor/state/storage.ml index f893c2d..b0c00de 100755 --- a/editor/state/storage.ml +++ b/editor/state/storage.ml @@ -62,7 +62,8 @@ let save' (* First load the content from the storage *) match check (load' key) with - | false -> Ok false + | false -> + Ok false | true -> let storage = Brr_io.Storage.local G.window in let operation = Brr_io.Storage.set_item -- cgit v1.2.3