aboutsummaryrefslogtreecommitdiff
path: root/motus
diff options
context:
space:
mode:
Diffstat (limited to 'motus')
-rw-r--r--motus/js/fieldList.ml89
1 files changed, 41 insertions, 48 deletions
diff --git a/motus/js/fieldList.ml b/motus/js/fieldList.ml
index 26b89bb..5af5e92 100644
--- a/motus/js/fieldList.ml
+++ b/motus/js/fieldList.ml
@@ -12,32 +12,26 @@ type elements = Brr.El.t list
*)
let get_validity_from_element : El.t -> Motus_lib.Validity.t =
fun el ->
- if El.class' (Jstr.v "missing") el
- then Missing
- else if El.class' (Jstr.v "misplaced") el
- then Misplaced
+ if El.class' (Jstr.v "missing") el then Missing
+ else if El.class' (Jstr.v "misplaced") el then Misplaced
else Wellplaced
-
let get_rules : elements -> State.proposition =
fun t ->
List.map
~f:(fun input ->
let value = El.prop El.Prop.value input in
- if Jstr.equal Jstr.empty value
- then None
+ if Jstr.equal Jstr.empty value then None
else
let validity = get_validity_from_element input in
- Some (value, validity) )
+ Some (value, validity))
t
-
let get_class : Motus_lib.Validity.t -> Jstr.t = function
| Wellplaced -> Jstr.v "wellplaced"
| Misplaced -> Jstr.v "misplaced"
| _ -> Jstr.v "missing"
-
(** Create the field list modifiied by the user *)
let make : int -> (int * Jstr.t * Motus_lib.Validity.t) E.send -> elements =
fun len change_sender ->
@@ -46,7 +40,8 @@ let make : int -> (int * Jstr.t * Motus_lib.Validity.t) E.send -> elements =
El.input
~at:
At.
- [ type' (Jstr.v "text")
+ [
+ type' (Jstr.v "text")
; v (Jstr.v "maxLength") (Jstr.v "1")
; value Jstr.empty
; class' (Jstr.v "missing")
@@ -55,27 +50,26 @@ let make : int -> (int * Jstr.t * Motus_lib.Validity.t) E.send -> elements =
()
in
- Ev.listen
- Ev.change
- (fun _ ->
- let validity = get_validity_from_element input in
- change_sender (i, El.prop El.Prop.value input, validity) )
- (El.as_target input);
-
- Ev.listen
- Ev.click
- (fun _ ->
- let validity =
- match get_validity_from_element input with
- | Missing -> Motus_lib.Validity.Misplaced
- | Misplaced -> Motus_lib.Validity.Wellplaced
- | Wellplaced -> Motus_lib.Validity.Missing
- in
- change_sender (i, El.prop El.Prop.value input, validity) )
- (El.as_target input);
-
- El.td [ input ] )
+ let _ =
+ Ev.listen Ev.change
+ (fun _ ->
+ let validity = get_validity_from_element input in
+ change_sender (i, El.prop El.Prop.value input, validity))
+ (El.as_target input)
+ and _ =
+ Ev.listen Ev.click
+ (fun _ ->
+ let validity =
+ match get_validity_from_element input with
+ | Missing -> Motus_lib.Validity.Misplaced
+ | Misplaced -> Motus_lib.Validity.Wellplaced
+ | Wellplaced -> Motus_lib.Validity.Missing
+ in
+ change_sender (i, El.prop El.Prop.value input, validity))
+ (El.as_target input)
+ in
+ El.td [ input ])
(** Set the element class depending of the proposition validity for each letter
*)
@@ -115,8 +109,7 @@ let set_with_props :
El.set_class (Jstr.v "missing") false hd;
El.set_at (Jstr.v "readonly") (Some (Jstr.v "false")) hd;
El.set_class (get_class validity) true hd
- | _, [], _ -> () )
-
+ | _, [], _ -> ())
let build : El.t -> int S.t -> State.proposition S.t =
fun container length ->
@@ -128,27 +121,26 @@ let build : El.t -> int S.t -> State.proposition S.t =
El.input
~at:
At.
- [ type' (Jstr.v "text")
+ [
+ type' (Jstr.v "text")
; v (Jstr.v "maxLength") (Jstr.v "1")
; value Jstr.empty
]
()
in
- input )
+ input)
in
let events =
List.mapi
~f:(fun i input ->
- Evr.on_el
- Ev.input
+ Evr.on_el Ev.input
(fun _ ->
let value = El.prop El.Prop.value input in
- if Jstr.equal Jstr.empty value
- then (i, None)
+ if Jstr.equal Jstr.empty value then (i, None)
else
let validity = Motus_lib.Validity.Wellplaced in
- (i, Some (Jstr.uppercased value, validity)) )
- input )
+ (i, Some (Jstr.uppercased value, validity)))
+ input)
elements
(* As the state is in a list, we have no way to be sure that the list
length is the same as the number of elements… except to rely on the
@@ -159,13 +151,14 @@ let build : El.t -> int S.t -> State.proposition S.t =
and init_prop = List.init ~len ~f:(fun _ -> None) in
(* Replace the children in the element *)
- El.set_children
- container
- [ El.table
- [ (* The table has only one row *)
+ El.set_children container
+ [
+ El.table
+ [
+ (* The table has only one row *)
El.tr
(List.map elements ~f:(fun el ->
- El.td [ (* Each cell is the input element *) el ] ) )
+ El.td [ (* Each cell is the input element *) el ]))
]
];
@@ -173,8 +166,8 @@ let build : El.t -> int S.t -> State.proposition S.t =
E.select events
|> E.map (fun (position, value) acc ->
List.mapi acc ~f:(fun i prop ->
- if i <> position then prop else value ) )
+ if i <> position then prop else value))
in
let initial_proposition = S.accum init_prop change in
- initial_proposition )
+ initial_proposition)