diff options
author | Sébastien Dailly <sebastien@dailly.me> | 2022-02-07 14:58:00 +0100 |
---|---|---|
committer | Sébastien Dailly <sebastien@dailly.me> | 2022-02-07 16:43:33 +0100 |
commit | cee939ada70967b70fe92ca24b3428cc8c8b7c38 (patch) | |
tree | cb8df06a6d93c94c221eb2209dee048d04df4bd5 /editor | |
parent | a6e30a95b5dcd34fb9e65d9a26f0844ec75bb004 (diff) |
Update editor
Diffstat (limited to 'editor')
-rwxr-xr-x | editor/actions/add_page.ml | 9 | ||||
-rwxr-xr-x | editor/actions/editor_actions.ml | 37 | ||||
-rwxr-xr-x | editor/actions/editor_actions.mli | 10 | ||||
-rwxr-xr-x | editor/editor.ml | 12 | ||||
-rwxr-xr-x | editor/forms/add_page.ml | 2 |
5 files changed, 32 insertions, 38 deletions
diff --git a/editor/actions/add_page.ml b/editor/actions/add_page.ml index ec9768b..fcad87f 100755 --- a/editor/actions/add_page.ml +++ b/editor/actions/add_page.ml @@ -21,9 +21,16 @@ let create : unit -> State.event Note.event = fun () -> let title = Jstr.v "Nouvelle page" in + let form = Forms.Add_page.create () in + + let valid_on = Note.S.map + (fun Forms.Add_page.{title} -> not @@ Jstr.equal Jstr.empty title) + (fst form) + in let ev = Elements.Popup.create ~title - ~form:(Forms.Add_page.create ()) + ~form + ~valid_on () in Note.E.map diff --git a/editor/actions/editor_actions.ml b/editor/actions/editor_actions.ml index 5b2a3d3..91d2a24 100755 --- a/editor/actions/editor_actions.ml +++ b/editor/actions/editor_actions.ml @@ -4,7 +4,7 @@ open Brr_note module Js = Js_of_ocaml.Js -(** This is the attribute attached to each link in which containing the node id +(** This is the attribute attached to each link and containing the node id pointed by the link. *) let note_id_attribute = Jstr.v "data-note-id" @@ -47,8 +47,7 @@ let build [] ~at:At.[ class' (Jstr.v "fa") ; class' (Jstr.v "fa-2x") - ; class' (Jstr.v "fa-download") ] - ] + ; class' (Jstr.v "fa-download") ] ] and load_button = El.button ~at:At.[class' (Jstr.v "action-button")] @@ -56,8 +55,7 @@ let build [] ~at:At.[ class' (Jstr.v "fa") ; class' (Jstr.v "fa-2x") - ; class' (Jstr.v "fa-upload") ] - ] + ; class' (Jstr.v "fa-upload") ] ] in (* We are waiting for event inside another event ( form validation inside @@ -139,8 +137,7 @@ let build ; class' (Jstr.v "fa-cog") ] ] ; El.hr () - ; ul - ] in + ; ul ] in let result_event = Note.E.select @@ -148,15 +145,13 @@ let build ; redirect_event ; add_event ; export_event - ; import_event - ] in + ; import_event ] in { ev = result_event ; childs ; ul ; delete_button - ; completed = false - } + ; completed = false } let get_event : t -> State.event Note.event @@ -178,19 +173,19 @@ let get_notes _ = let complete : t -> State.t Note.signal -> El.t list - = fun ({ childs; ul ; completed ; delete_button ; _ } as t) change -> + = fun t change -> + (* As we register some events, we have to prevent many execution of this + function *) let () = - if completed then + if t.completed then raise (Failure "The action panel is already registered") in - - let note_list = - Note.S.map get_notes - change - in t.completed <- true; - Elr.def_children ul note_list; + Elr.def_children + t.ul + (Note.S.map get_notes change); + Elr.def_at (Jstr.v "disabled") (Note.S.map @@ -199,6 +194,6 @@ let complete | None -> Some Jstr.empty | Some _ -> None) change) - delete_button; + t.delete_button; - childs + t.childs diff --git a/editor/actions/editor_actions.mli b/editor/actions/editor_actions.mli index 27b09d7..0e9997b 100755 --- a/editor/actions/editor_actions.mli +++ b/editor/actions/editor_actions.mli @@ -1,17 +1,15 @@ type t -(** Create the elements to be declareds inside the panel *) +(** Create the elements to be declared inside the panel *) val build : unit -> t -(* Get the events triggered by the actions buttons *) +(** Get the events triggered by the actions buttons *) val get_event : t -> State.event Note.event -(* Finalize the creation, register the handler to state update, and return the dom elements. +(** Finalize the creation, register the handler to state update, and return the dom elements. - Raise an error if already completed. - -*) + Raise an error if already completed. *) val complete : t -> State.t Note.signal -> Brr.El.t list diff --git a/editor/editor.ml b/editor/editor.ml index 9eee49e..8dc13e8 100755 --- a/editor/editor.ml +++ b/editor/editor.ml @@ -137,18 +137,12 @@ let app id content = ~eq:State.eq init_state (Note.E.select - [ Brr_note.Evr.on_el Ev.focusout - (fun _ -> + [ Brr_note.Evr.on_els Ev.focusout + (fun _ _ -> State.E ( title , (module Store:State.Event with type t = Store.t))) - editor - ; Brr_note.Evr.on_el Ev.focusout - (fun _ -> - State.E - ( title - , (module Store:State.Event with type t = Store.t))) - title + [ editor ; title ] ; btn_events ]) in diff --git a/editor/forms/add_page.ml b/editor/forms/add_page.ml index 08fb5d7..5ec7f2f 100755 --- a/editor/forms/add_page.ml +++ b/editor/forms/add_page.ml @@ -9,7 +9,7 @@ let create (* The element which contains the information *) let input = El.input () - ~at:At.[type' (Jstr.v "text")] + ~at:At.[type' (Jstr.v "text") ] in let init = |