From 9a70d8da5515b4e3a03974b19a19902538c5274b Mon Sep 17 00:00:00 2001 From: Vincent Balat Date: Fri, 14 Nov 2025 15:41:07 +0100 Subject: [PATCH] ocamlformat --- .ocamlformat | 2 + src/widgets/ot_calendar.eliom | 135 ++++++++++++++++---------- src/widgets/ot_carousel.eliom | 135 ++++++++++++++++++-------- src/widgets/ot_color_picker.eliom | 7 +- src/widgets/ot_drawer.eliom | 103 ++++++++++++-------- src/widgets/ot_icons.eliom | 6 +- src/widgets/ot_lib.eliom | 9 +- src/widgets/ot_page_transition.eliom | 6 +- src/widgets/ot_picture_uploader.eliom | 42 +++++--- src/widgets/ot_popup.eliom | 21 ++-- src/widgets/ot_pulltorefresh.eliom | 12 ++- src/widgets/ot_size.eliom | 5 +- src/widgets/ot_spinner.eliom | 3 +- src/widgets/ot_sticky.eliom | 9 +- src/widgets/ot_swipe.eliom | 50 ++++++---- src/widgets/ot_time_picker.eliom | 32 +++--- src/widgets/ot_tip.eliom | 25 +++-- src/widgets/ot_toggle.eliom | 8 +- src/widgets/ot_tongue.eliom | 36 +++++-- 19 files changed, 425 insertions(+), 221 deletions(-) diff --git a/.ocamlformat b/.ocamlformat index ee092cc1..78fc5bfb 100644 --- a/.ocamlformat +++ b/.ocamlformat @@ -1,3 +1,5 @@ +version=0.28.1 +parse-docstrings = false break-cases = fit break-collection-expressions = fit-or-vertical break-fun-decl = wrap diff --git a/src/widgets/ot_calendar.eliom b/src/widgets/ot_calendar.eliom index 07bde3af..4f0efde3 100644 --- a/src/widgets/ot_calendar.eliom +++ b/src/widgets/ot_calendar.eliom @@ -185,9 +185,12 @@ let select_action ?(size = 1) selector action = dom_select##.size := size; Lwt.return_unit)) -let rec build_calendar ?prehilight - ~button_labels:{b_prev_year; b_prev_month; b_next_month; b_next_year} ~intl - ~period day +let rec build_calendar + ?prehilight + ~button_labels:{b_prev_year; b_prev_month; b_next_month; b_next_year} + ~intl + ~period + day = let today = CalendarLib.Date.today () in let fst_dow = fst_dow ~intl day @@ -297,43 +300,54 @@ let get_options selector = let update_classes cal zero d = let rows = (To_dom.of_table cal)##.rows in let f i = - rows ## (item (i + 2)) >>! fun r -> + rows##(item (i + 2)) >>! fun r -> let cells = r##.cells in let f j = - cells ## (item j) >>! fun c -> + cells##(item j) >>! fun c -> let d' = CalendarLib.Calendar.Date.(j + (7 * i) |> Period.day |> add zero) in if d = d' - then c ##. classList ## (add (Js.string "ot-c-current")) - else c ##. classList ## (remove (Js.string "ot-c-current")) + then c##.classList##(add (Js.string "ot-c-current")) + else c##.classList##(remove (Js.string "ot-c-current")) in iter_interval 0 6 f in iter_interval 0 5 f -let in_period ?(begin_p = default_period.begin_p) - ?(end_p = default_period.end_p) curr_date +let in_period + ?(begin_p = default_period.begin_p) + ?(end_p = default_period.end_p) + curr_date = curr_date >= begin_p && curr_date <= end_p -let in_period_coerced ?(begin_p = default_period.begin_p) - ?(end_p = default_period.end_p) curr_date +let in_period_coerced + ?(begin_p = default_period.begin_p) + ?(end_p = default_period.end_p) + curr_date = curr_date >= (begin_p :> [`Month | `Year] CalendarLib.Date.date) && curr_date <= (end_p :> [`Month | `Year] CalendarLib.Date.date) -let attach_events ?action ?(click_non_highlighted = false) ?update ~intl ~period - d cal highlight +let attach_events + ?action + ?(click_non_highlighted = false) + ?update + ~intl + ~period + d + cal + highlight = let rows = (To_dom.of_table cal)##.rows in let fst_dow = fst_dow ~intl d and zero = zeroth_displayed_day ~intl d in let mnth = CalendarLib.Date.month fst_dow in iter_interval 0 5 @@ fun i -> - rows ## (item (i + 2)) >>! fun r -> + rows##(item (i + 2)) >>! fun r -> let cells = r##.cells in iter_interval 0 6 @@ fun j -> - cells ## (item j) >>! fun c -> + cells##(item j) >>! fun c -> let d = CalendarLib.Calendar.Date.(j + (7 * i) |> Period.day |> add zero) in if mnth = CalendarLib.Date.month d then @@ -358,14 +372,20 @@ let attach_events ?action ?(click_non_highlighted = false) ?update ~intl ~period in if List.exists (( = ) dom) highlight then ( - c ##. classList ## (add (Js.string "ot-c-highlight")); + c##.classList##(add (Js.string "ot-c-highlight")); set_onclick ()) else if click_non_highlighted then set_onclick () else () -let attach_events_lwt ?action ?click_non_highlighted ~intl ~period d cal - highlight +let attach_events_lwt + ?action + ?click_non_highlighted + ~intl + ~period + d + cal + highlight = let f () = let m = CalendarLib.Date.(month d |> int_of_month) @@ -376,9 +396,13 @@ let attach_events_lwt ?action ?click_non_highlighted ~intl ~period d cal in Lwt.async f -let make_span_handler selector - ((get_sig, set_sig) : int React.signal * (?step:React.step -> int -> unit)) - apply condi fun_handler +let make_span_handler + selector + ((get_sig, set_sig) : + int React.signal * (?step:React.step -> int -> unit)) + apply + condi + fun_handler = Dom_html.handler (fun _ -> if condi () @@ -389,9 +413,13 @@ let make_span_handler selector Js._false) else Js._false) -let set_selected_index selector selector_value options - ((get_sig, set_sig) : int React.signal * (?step:React.step -> int -> unit)) - () +let set_selected_index + selector + selector_value + options + ((get_sig, set_sig) : + int React.signal * (?step:React.step -> int -> unit)) + () = let value = selector_value () in try @@ -404,8 +432,15 @@ let make_selector_handler change_index condi fun_handler = Dom_html.handler (fun _ -> if condi () then (fun_handler (); change_index (); Js._false) else Js._false) -let attach_behavior ?highlight ?click_non_highlighted ?action ~intl ~period d - (cal, prev, next, select_month, select_year, prev_year, next_year) f_d +let attach_behavior + ?highlight + ?click_non_highlighted + ?action + ~intl + ~period + d + (cal, prev, next, select_month, select_year, prev_year, next_year) + f_d = (match highlight with | Some highlight -> @@ -467,18 +502,18 @@ let attach_behavior ?highlight ?click_non_highlighted ?action ~intl ~period d (fun () -> f_d (CalendarLib.Date.next d `Year)) let make : - ?init:int * int * int - -> ?highlight:(int -> int -> int list Lwt.t) - -> ?click_non_highlighted:bool - -> ?update:(int * int * int) React.E.t - -> ?action:(int -> int -> int -> unit Lwt.t) - -> ?period: - CalendarLib.Date.field CalendarLib.Date.date - * CalendarLib.Date.field CalendarLib.Date.date - -> ?button_labels:button_labels - -> ?intl:intl - -> unit - -> [> `Div] elt + ?init:int * int * int + -> ?highlight:(int -> int -> int list Lwt.t) + -> ?click_non_highlighted:bool + -> ?update:(int * int * int) React.E.t + -> ?action:(int -> int -> int -> unit Lwt.t) + -> ?period: + CalendarLib.Date.field CalendarLib.Date.date + * CalendarLib.Date.field CalendarLib.Date.date + -> ?button_labels:button_labels + -> ?intl:intl + -> unit + -> [> `Div] elt = fun ?init ?highlight @@ -525,18 +560,18 @@ let make : elt let%server make : - ?init:int * int * int - -> ?highlight:(int -> int -> int list Lwt.t) Eliom_client_value.t - -> ?click_non_highlighted:bool - -> ?update:(int * int * int) React.E.t Eliom_client_value.t - -> ?action:(int -> int -> int -> unit Lwt.t) Eliom_client_value.t - -> ?period: - CalendarLib.Date.field CalendarLib.Date.date - * CalendarLib.Date.field CalendarLib.Date.date - -> ?button_labels:button_labels - -> ?intl:intl - -> unit - -> [> `Div] elt + ?init:int * int * int + -> ?highlight:(int -> int -> int list Lwt.t) Eliom_client_value.t + -> ?click_non_highlighted:bool + -> ?update:(int * int * int) React.E.t Eliom_client_value.t + -> ?action:(int -> int -> int -> unit Lwt.t) Eliom_client_value.t + -> ?period: + CalendarLib.Date.field CalendarLib.Date.date + * CalendarLib.Date.field CalendarLib.Date.date + -> ?button_labels:button_labels + -> ?intl:intl + -> unit + -> [> `Div] elt = fun ?init ?highlight diff --git a/src/widgets/ot_carousel.eliom b/src/widgets/ot_carousel.eliom index e18eb08b..fd76dc66 100644 --- a/src/widgets/ot_carousel.eliom +++ b/src/widgets/ot_carousel.eliom @@ -54,10 +54,10 @@ let%client remove_transition elt = let%shared default_make_transform ~vertical ?(delta = 0) pos = let p = -pos * 100 in if vertical - (* then Printf.sprintf "translate3d(0, %.3f%%, 0)" d *) - (* else Printf.sprintf "translate3d(%.3f%%, 0, 0)" d *) then Printf.sprintf "translateY(%d%%) translateY(%dpx)" p delta else Printf.sprintf "translateX(%d%%) translateX(%dpx)" p delta +(* then Printf.sprintf "translate3d(0, %.3f%%, 0)" d *) +(* else Printf.sprintf "translate3d(%.3f%%, 0, 0)" d *) (* translate3d possibly more efficient on some devices ... *) (* But causing troubles ... @@ -95,14 +95,22 @@ type%shared 'a t = ; vis_elts : int Eliom_shared.React.S.t ; swipe_pos : float React.S.t Eliom_client_value.t } -let%shared make ?(a = []) ?(vertical = false) ?(position = 0) - ?(transition_duration = 0.6) ?(inertia = 1.0) ?(swipeable = true) - ?(allow_overswipe = false) - ?(update : - [`Goto of int | `Next | `Prev] React.event Eliom_client_value.t option) - ?(disabled = Eliom_shared.React.S.const false) ?(full_height = `No) - ?(make_transform = [%shared default_make_transform]) - ?(make_page_attribute = [%shared fun ~vertical:_ _ -> []]) l +let%shared + make + ?(a = []) + ?(vertical = false) + ?(position = 0) + ?(transition_duration = 0.6) + ?(inertia = 1.0) + ?(swipeable = true) + ?(allow_overswipe = false) + ?(update : + [`Goto of int | `Next | `Prev] React.event Eliom_client_value.t option) + ?(disabled = Eliom_shared.React.S.const false) + ?(full_height = `No) + ?(make_transform = [%shared default_make_transform]) + ?(make_page_attribute = [%shared fun ~vertical:_ _ -> []]) + l = let a = (a :> Html_types.div_attrib attrib list) in let pos_signal, pos_set = Eliom_shared.React.S.create position in @@ -395,12 +403,12 @@ let%shared make ?(a = []) ?(vertical = false) ?(position = 0) if vertical then clY ev -. starty else clX ev -. startx in status := - if abs_float - (if vertical then clX ev -. startx else clY ev -. starty) - >= abs_float move + if + abs_float + (if vertical then clX ev -. startx else clY ev -. starty) + >= abs_float move then - Stopped - (* swiping in wrong direction (vertical/horizontal) *) + Stopped (* swiping in wrong direction (vertical/horizontal) *) else if abs_float move > Ot_swipe.threshold then ( (* We decide to take the event *) @@ -563,7 +571,7 @@ let%shared default_fail_fun e = em ~a:[a_class ["ot-icon-error"]] [] let%shared default_fail_ref : - (exn -> Html_types.div_content Eliom_content.Html.elt) ref + (exn -> Html_types.div_content Eliom_content.Html.elt) ref = ref default_fail_fun @@ -601,9 +609,22 @@ let%server generate_initial_contents ~spinner:_ _ gen = let* contents = generate_content gen in Lwt.return (contents, ref @@ None) -let%shared make_lazy ?a ?vertical ?(position = 0) ?transition_duration ?inertia - ?swipeable ?allow_overswipe ?update ?disabled ?full_height ?make_transform - ?make_page_attribute ?(spinner = spinner) gen_contents +let%shared + make_lazy + ?a + ?vertical + ?(position = 0) + ?transition_duration + ?inertia + ?swipeable + ?allow_overswipe + ?update + ?disabled + ?full_height + ?make_transform + ?make_page_attribute + ?(spinner = spinner) + gen_contents = let gen_contents = (gen_contents @@ -664,9 +685,17 @@ let%shared bullet_class i pos size = fun p size -> if ~%i >= p && ~%i < p + size then ["ot-active"] else []] pos size -let%shared bullets ?(a = []) ?attributes - ~(change : ([> `Goto of int | `Next | `Prev] -> unit) Eliom_client_value.t) - ~pos ~length ?(size = Eliom_shared.React.S.const 1) ?content () +let%shared + bullets + ?(a = []) + ?attributes + ~(change : + ([> `Goto of int | `Next | `Prev] -> unit) Eliom_client_value.t) + ~pos + ~length + ?(size = Eliom_shared.React.S.const 1) + ?content + () = let a = (a :> Html_types.ul_attrib attrib list) in let bullet i c = @@ -696,11 +725,17 @@ let%shared bullets ?(a = []) ?attributes in ul ~a:(a_class ["ot-bullet-nav"] :: a) (List.mapi bullet content) -let%shared ribbon ?(a = []) - ~(change : ([> `Goto of int | `Next | `Prev] -> unit) Eliom_client_value.t) - ~pos ?(size = Eliom_shared.React.S.const 1) ?(initial_gap = 0) - ?(transition_duration = 0.6) - ?(cursor : float React.S.t Eliom_client_value.t option) l +let%shared + ribbon + ?(a = []) + ~(change : + ([> `Goto of int | `Next | `Prev] -> unit) Eliom_client_value.t) + ~pos + ?(size = Eliom_shared.React.S.const 1) + ?(initial_gap = 0) + ?(transition_duration = 0.6) + ?(cursor : float React.S.t Eliom_client_value.t option) + l = let a = (a :> Html_types.div_attrib attrib list) in let item i c = @@ -929,9 +964,13 @@ let%shared ribbon ?(a = []) let%shared blur = function true -> ["ot-blurred"] | false -> [] -let%shared previous ?(a = []) - ~(change : ([> `Prev | `Goto of int] -> unit) Eliom_client_value.t) - ?(offset = Eliom_shared.React.S.const 1) ~pos content +let%shared + previous + ?(a = []) + ~(change : ([> `Prev | `Goto of int] -> unit) Eliom_client_value.t) + ?(offset = Eliom_shared.React.S.const 1) + ~pos + content = Form.button_no_value ~button_type:`Button ~a: @@ -948,9 +987,15 @@ let%shared previous ?(a = []) :: (a :> Html_types.button_attrib Eliom_content.Html.attrib list)) content -let%shared next ?(a = []) - ~(change : ([> `Next | `Goto of int] -> unit) Eliom_client_value.t) - ?(offset = Eliom_shared.React.S.const 1) ~pos ~vis_elts ~length content +let%shared + next + ?(a = []) + ~(change : ([> `Next | `Goto of int] -> unit) Eliom_client_value.t) + ?(offset = Eliom_shared.React.S.const 1) + ~pos + ~vis_elts + ~length + content = Form.button_no_value ~button_type:`Button ~a: @@ -1042,19 +1087,29 @@ let%shared wheel_page_attribute pos z faces ~vertical page_number = fun (pos, swipe_pos) -> let faces = ~%faces in let page_number = ~%page_number in - [ (if float page_number - <= float pos +. swipe_pos -. (float faces /. 2.) - || float page_number - > float pos +. swipe_pos +. (float faces /. 2.) + [ (if + float page_number <= float pos +. swipe_pos -. (float faces /. 2.) + || float page_number + > float pos +. swipe_pos +. (float faces /. 2.) then "ot-hidden-wheel-face" else "") ]] pos in [R.a_class cls; a_style style] -let%shared wheel ?(a = []) ?(vertical = true) ?(position = 0) - ?transition_duration ?inertia ?allow_overswipe ?update ?disabled - ?(faces = 20) ?(face_size = 25) content +let%shared + wheel + ?(a = []) + ?(vertical = true) + ?(position = 0) + ?transition_duration + ?inertia + ?allow_overswipe + ?update + ?disabled + ?(faces = 20) + ?(face_size = 25) + content = let a = a_class ["ot-wheel"] :: a in let z = diff --git a/src/widgets/ot_color_picker.eliom b/src/widgets/ot_color_picker.eliom index 1f8e7e64..a45620a8 100644 --- a/src/widgets/ot_color_picker.eliom +++ b/src/widgets/ot_color_picker.eliom @@ -141,8 +141,11 @@ let display ?a cp_sig = >|= [%shared display_aux ?a:~%a ~setter:~%setter] |> Eliom_content.Html.R.node -let make ?a ?hsv - ?(update = [%client (React.E.never : (int * float * float) React.E.t)]) () +let make + ?a + ?hsv + ?(update = [%client (React.E.never : (int * float * float) React.E.t)]) + () = let ((cp_sig, cp_set) as cp_react) = Eliom_shared.React.S.create (Option.value hsv ~default:(255, 1.0, 0.0)) diff --git a/src/widgets/ot_drawer.eliom b/src/widgets/ot_drawer.eliom index 4a80b235..6703b24e 100644 --- a/src/widgets/ot_drawer.eliom +++ b/src/widgets/ot_drawer.eliom @@ -22,20 +22,23 @@ open Eliom_content.Html] [%%shared open Eliom_content.Html.F] + open%client Js_of_ocaml open%client Lwt.Syntax + [%%client open Js_of_ocaml_lwt] + type%client status = Stopped | Start | Aborted | In_progress let%client clX ev = Js.Optdef.case - ev ##. changedTouches ## (item 0) + ev##.changedTouches##(item 0) (fun () -> 0.) (fun a -> Js.to_float a##.clientX) let%client clY ev = Js.Optdef.case - ev ##. changedTouches ## (item 0) + ev##.changedTouches##(item 0) (fun () -> 0.) (fun a -> Js.to_float a##.clientY) @@ -74,10 +77,17 @@ let%client remove_class elt str = * [ drawer ] DOM element * [ open_drawer ] function to open the drawer * [ close_drawer ] function to close the drawer *) -let%shared drawer ?(a = []) ?(position = `Left) ?(opened = false) - ?(swipe = true) ?(onclose : (unit -> unit) Eliom_client_value.t option) - ?(onopen : (unit -> unit) Eliom_client_value.t option) - ?(wrap_close = fun f -> f) ?(wrap_open = fun f -> f) content +let%shared + drawer + ?(a = []) + ?(position = `Left) + ?(opened = false) + ?(swipe = true) + ?(onclose : (unit -> unit) Eliom_client_value.t option) + ?(onopen : (unit -> unit) Eliom_client_value.t option) + ?(wrap_close = fun f -> f) + ?(wrap_open = fun f -> f) + content = let scroll_pos = ref 0. in let a = (a :> Html_types.div_attrib attrib list) in @@ -103,7 +113,7 @@ let%shared drawer ?(a = []) ?(position = `Left) ?(opened = false) D.div ~a:(a_class ("ot-drawer-bckgrnd" :: bckgrnd_init_class) :: a) [d] in let bind_touch : - ((unit -> unit) Lwt.t * (unit -> unit) Lwt.u) Eliom_client_value.t + ((unit -> unit) Lwt.t * (unit -> unit) Lwt.u) Eliom_client_value.t = [%client Lwt.wait ()] in @@ -247,8 +257,14 @@ let%shared drawer ?(a = []) ?(position = `Left) ?(opened = false) else Lwt.return_unit) in (* let hammer = Hammer.make_hammer bckgrnd in *) - let startx = ref 0. (* position when touch starts *) in - let starty = ref 0. (* position when touch starts *) in + let startx = + ref 0. + (* position when touch starts *) + in + let starty = + ref 0. + (* position when touch starts *) + in let status = ref Stopped in let onpan ev _ = let left = clX ev -. !startx in @@ -256,15 +272,17 @@ let%shared drawer ?(a = []) ?(position = `Left) ?(opened = false) if !status = Start then status := - if (~%position = `Top || ~%position = `Bottom) - && abs_float left > abs_float top - || (~%position = `Left || ~%position = `Right) - && abs_float top > abs_float left + if + (~%position = `Top || ~%position = `Bottom) + && abs_float left > abs_float top + || (~%position = `Left || ~%position = `Right) + && abs_float top > abs_float left then Aborted (* Orthogonal scrolling *) - else if (~%position = `Top || ~%position = `Bottom) - && abs_float top <= Ot_swipe.threshold - || (~%position = `Left || ~%position = `Right) - && abs_float left <= Ot_swipe.threshold + else if + (~%position = `Top || ~%position = `Bottom) + && abs_float top <= Ot_swipe.threshold + || (~%position = `Left || ~%position = `Right) + && abs_float left <= Ot_swipe.threshold then !status else ( (* We decide to take the event *) @@ -277,22 +295,23 @@ let%shared drawer ?(a = []) ?(position = `Left) ?(opened = false) Dom.preventDefault ev; Dom_html.stopPropagation ev; let move = ref 0. in - if ~%position = `Top && top <= 0. - && - (move := top; - true) - || ~%position = `Right && left >= 0. - && - (move := left; - true) - || ~%position = `Bottom && top >= 0. - && - (move := top; - true) - || ~%position = `Left && left <= 0. - && - (move := left; - true) + if + ~%position = `Top && top <= 0. + && + (move := top; + true) + || ~%position = `Right && left >= 0. + && + (move := left; + true) + || ~%position = `Bottom && top >= 0. + && + (move := top; + true) + || ~%position = `Left && left <= 0. + && + (move := left; + true) then perform_animation (`Move !move) else Lwt.return_unit) else Lwt.return_unit @@ -306,15 +325,17 @@ let%shared drawer ?(a = []) ?(position = `Left) ?(opened = false) let width = dr##.offsetWidth in let deltaX = clX ev -. !startx in let deltaY = clY ev -. !starty in - if (~%position = `Top && deltaY < -0.3 *. float width) - || (~%position = `Right && deltaX > 0.3 *. float width) - || (~%position = `Bottom && deltaY > 0.3 *. float width) - || (~%position = `Left && deltaX < -0.3 *. float width) + if + (~%position = `Top && deltaY < -0.3 *. float width) + || (~%position = `Right && deltaX > 0.3 *. float width) + || (~%position = `Bottom && deltaY > 0.3 *. float width) + || (~%position = `Left && deltaX < -0.3 *. float width) then perform_animation `Close - else if (~%position = `Top && deltaY >= 0.) - || (~%position = `Right && deltaX <= 0.) - || (~%position = `Bottom && deltaY <= 0.) - || (~%position = `Left && deltaX >= 0.) + else if + (~%position = `Top && deltaY >= 0.) + || (~%position = `Right && deltaX <= 0.) + || (~%position = `Bottom && deltaY <= 0.) + || (~%position = `Left && deltaX >= 0.) then perform_animation `Abort else perform_animation `Open) else ( diff --git a/src/widgets/ot_icons.eliom b/src/widgets/ot_icons.eliom index 3b2ee926..7772eb0d 100644 --- a/src/widgets/ot_icons.eliom +++ b/src/widgets/ot_icons.eliom @@ -10,8 +10,10 @@ module Make (A : module type of Eliom_content.Html.F) = struct * The optional parameter is at the end to be able to add other CSS classes * with predefined icons. *) - let icon classes - ?(a = ([] : Html_types.i_attrib Eliom_content.Html.attrib list)) () + let icon + classes + ?(a = ([] : Html_types.i_attrib Eliom_content.Html.attrib list)) + () = A.i ~a:(A.a_class ("ot-icon" :: classes) :: a) [] diff --git a/src/widgets/ot_lib.eliom b/src/widgets/ot_lib.eliom index f5788ad2..6b29287d 100644 --- a/src/widgets/ot_lib.eliom +++ b/src/widgets/ot_lib.eliom @@ -52,7 +52,7 @@ let%client window_scrolls ?(ios_html_scroll_hack = false) ?use_capture handler = (List.map (* We listen to several elements because scroll events are not happening on the same element on every platform. *) - (fun element -> Lwt_js_events.scroll ?use_capture element) + (fun element -> Lwt_js_events.scroll ?use_capture element) [ (Dom_html.window :> Dom_html.eventTarget Js.t) ; (Dom_html.document##.documentElement :> Dom_html.eventTarget Js.t) @@ -92,8 +92,11 @@ let%client rec in_ancestors ~elt ~ancestor = (fun () -> false) (fun elt -> in_ancestors ~elt ~ancestor)) -let%client rec click_outside ?use_capture - ?(inside = (Dom_html.document##.body :> Dom_html.element Js.t)) elt +let%client rec + click_outside + ?use_capture + ?(inside = (Dom_html.document##.body :> Dom_html.element Js.t)) + elt = let* ev = Lwt_js_events.click ?use_capture inside in Js.Opt.case ev##.target diff --git a/src/widgets/ot_page_transition.eliom b/src/widgets/ot_page_transition.eliom index f9cd307f..97222cc4 100644 --- a/src/widgets/ot_page_transition.eliom +++ b/src/widgets/ot_page_transition.eliom @@ -126,8 +126,10 @@ module Make (Conf : PAGE_TRANSITION_CONF) = struct (try take_screenshot f with _ -> ba None); Lwt.return_unit - let install_global_handler ?transition_duration ~take_screenshot - ~animation_type + let install_global_handler + ?transition_duration + ~take_screenshot + ~animation_type = let rec hc_handler ev = Eliom_client.onchangepage hc_handler; diff --git a/src/widgets/ot_picture_uploader.eliom b/src/widgets/ot_picture_uploader.eliom index 0fc24266..9d31d45d 100644 --- a/src/widgets/ot_picture_uploader.eliom +++ b/src/widgets/ot_picture_uploader.eliom @@ -44,7 +44,7 @@ type%shared ('a, 'b) service = let%client process_file input callback = Js.Opt.case - input ##. files ## (item 0) + input##.files##(item 0) (fun () -> Lwt.return_unit) (fun x -> callback x) @@ -79,8 +79,11 @@ let%client on_animation_frame f = f x))); last := Some x -let%shared cropper ~(image : Dom_html.element Js.t Eliom_client_value.t) - ?(ratio : float option) () +let%shared + cropper + ~(image : Dom_html.element Js.t Eliom_client_value.t) + ?(ratio : float option) + () = let mk_controller style = D.div ~a:[a_class ["ot-pup-ctrl"; "ot-pup-ctrl-" ^ style]] [] @@ -246,10 +249,11 @@ let%shared cropper ~(image : Dom_html.element Js.t Eliom_client_value.t) | `L -> 0.5, 0., 0.5, 1. | `TL -> 1., 0., 0., 1. in - if React.S.value ~%right >= r *. dx - && React.S.value ~%left >= l *. dx - && React.S.value ~%top >= t *. dy - && React.S.value ~%bottom >= b *. dy + if + React.S.value ~%right >= r *. dx + && React.S.value ~%left >= l *. dx + && React.S.value ~%top >= t *. dy + && React.S.value ~%bottom >= b *. dy then ( update_top (-.t *. dy); update_bottom (b *. dy); @@ -456,8 +460,14 @@ let%client do_submit input ?progress ?cropping ~upload () = let* _ = upload ?progress ?cropping file in Lwt.return_unit -let%client bind_submit (input : Dom_html.inputElement Js.t Eliom_client_value.t) - button ?cropping ~upload ~after_submit () +let%client + bind_submit + (input : Dom_html.inputElement Js.t Eliom_client_value.t) + button + ?cropping + ~upload + ~after_submit + () = Lwt.async (fun () -> Lwt_js_events.clicks button (fun ev _ -> @@ -466,8 +476,8 @@ let%client bind_submit (input : Dom_html.inputElement Js.t Eliom_client_value.t) let* () = do_submit input ?cropping ~upload () in after_submit ())) -let%client bind ?container ~input ~preview ?crop ~submit ~upload ~after_submit - () +let%client + bind ?container ~input ~preview ?crop ~submit ~upload ~after_submit () = let reset, cropping = match crop with Some (x, y) -> Some x, Some y | _ -> None, None @@ -487,9 +497,13 @@ let%server mk_service name arg_deriver = ** file "f" )) () -let%shared mk_form ?(after_submit = fun () -> Lwt.return_unit) ?crop - ?input:(input_a, input_content = [], []) - ?submit:(submit_a, submit_content = [], []) (upload : 'a upload) +let%shared + mk_form + ?(after_submit = fun () -> Lwt.return_unit) + ?crop + ?input:(input_a, input_content = [], []) + ?submit:(submit_a, submit_content = [], []) + (upload : 'a upload) = let preview = preview () in let input, input_label = input ~a:input_a input_content in diff --git a/src/widgets/ot_popup.eliom b/src/widgets/ot_popup.eliom index 4ee75104..f3e44ad0 100644 --- a/src/widgets/ot_popup.eliom +++ b/src/widgets/ot_popup.eliom @@ -22,8 +22,10 @@ open Eliom_content.Html] [%%shared open Eliom_content.Html.F] + open%client Js_of_ocaml open%client Lwt.Syntax + [%%client open Js_of_ocaml_lwt] let%shared hcf ?(a = []) ?(header = []) ?(footer = []) content = @@ -64,10 +66,16 @@ let%client disable_page_scroll, enable_page_scroll = Dom_html.window##scrollTo (Js.float 0.) (Js.float (float pos)); scroll_pos := None ) -let%client popup ?(a = []) ?(enable_scrolling_hack = true) ?close_button - ?confirmation_onclose ?(onclose = fun () -> Lwt.return_unit) - ?(close_on_background_click = false) - ?(close_on_escape = close_button <> None) gen_content +let%client + popup + ?(a = []) + ?(enable_scrolling_hack = true) + ?close_button + ?confirmation_onclose + ?(onclose = fun () -> Lwt.return_unit) + ?(close_on_background_click = false) + ?(close_on_escape = close_button <> None) + gen_content = let a = (a :> Html_types.div_attrib attrib list) in let gen_content = @@ -79,8 +87,9 @@ let%client popup ?(a = []) ?(enable_scrolling_hack = true) ?close_button if enable_scrolling_hack then disable_page_scroll ()); let reset () = if enable_scrolling_hack then enable_page_scroll () in let do_close () = - if (Dom_html.document##getElementsByClassName (Js.string "ot-popup"))##.length - = 1 + if + (Dom_html.document##getElementsByClassName (Js.string "ot-popup"))##.length + = 1 then reset (); let () = Eliom_lib.Option.iter Manip.removeSelf !popup in stop_thread (); onclose () diff --git a/src/widgets/ot_pulltorefresh.eliom b/src/widgets/ot_pulltorefresh.eliom index 5a596126..23aaf803 100644 --- a/src/widgets/ot_pulltorefresh.eliom +++ b/src/widgets/ot_pulltorefresh.eliom @@ -167,9 +167,15 @@ module Make (Conf : CONF) = struct Lwt.async (fun () -> touchcancels js_container touchend_handler) end] -let make ?(a = []) ?(app_only = true) ?(scale = 5.) ?(dragThreshold = 80.) - ?(refresh_timeout = 20.) ?(header = [%shared default_header]) ~content - (afterPull : (unit -> bool Lwt.t) Eliom_client_value.t) +let make + ?(a = []) + ?(app_only = true) + ?(scale = 5.) + ?(dragThreshold = 80.) + ?(refresh_timeout = 20.) + ?(header = [%shared default_header]) + ~content + (afterPull : (unit -> bool Lwt.t) Eliom_client_value.t) = if app_only && not (Eliom_client.is_client_app ()) then div ~a [content] diff --git a/src/widgets/ot_size.eliom b/src/widgets/ot_size.eliom index 767b25cb..93c9fdeb 100644 --- a/src/widgets/ot_size.eliom +++ b/src/widgets/ot_size.eliom @@ -89,7 +89,7 @@ let height_to_bottom offset elt = let page = Dom_html.document##.documentElement in let h = page##.clientHeight in try - let top = Js.to_float (of_opt elt ## getClientRects ## (item 0))##.top in + let top = Js.to_float (of_opt elt##getClientRects##(item 0))##.top in h - int_of_float top - offset with Failure _ -> h - offset @@ -142,7 +142,8 @@ let pageYOffset () = with _ -> get_clientHeight () in max 0 - @@ (* overscroll at the top *) + @@ + (* overscroll at the top *) min (* overscroll at the bottom *) (Dom_html.document##.documentElement##.scrollHeight - get_innerHeight ()) (Js.Unsafe.coerce Dom_html.window)##.pageYOffset diff --git a/src/widgets/ot_spinner.eliom b/src/widgets/ot_spinner.eliom index 1444a6ce..6a13f3fc 100644 --- a/src/widgets/ot_spinner.eliom +++ b/src/widgets/ot_spinner.eliom @@ -20,6 +20,7 @@ *) open%client Js_of_ocaml + [%%shared open Eliom_content.Html] [%%shared open Lwt.Syntax] [%%shared open Eliom_content.Html.F] @@ -38,7 +39,7 @@ let%shared default_fail_fun e = em ~a:[a_class ["ot-icon-error"]] []) ] let%shared default_fail_ref : - (exn -> Html_types.div_content Eliom_content.Html.elt list) ref + (exn -> Html_types.div_content Eliom_content.Html.elt list) ref = ref default_fail_fun diff --git a/src/widgets/ot_sticky.eliom b/src/widgets/ot_sticky.eliom index 22d73efb..64ac065c 100644 --- a/src/widgets/ot_sticky.eliom +++ b/src/widgets/ot_sticky.eliom @@ -118,9 +118,12 @@ let update_state ?force g = else unstick ?force g (* TODO: ensure compatibility with DOM caching *) -let make_sticky ~dir (* TODO: detect based on CSS attribute? *) - ?((*TODO: `Bottom and `Right *) - ios_html_scroll_hack = false) ?(force = false) elt +let make_sticky + ~dir (* TODO: detect based on CSS attribute? *) + ?((*TODO: `Bottom and `Right *) + ios_html_scroll_hack = false) + ?(force = false) + elt = let* () = Ot_nodeready.nodeready (To_dom.of_element elt) in if (not force) && supports_position_sticky elt diff --git a/src/widgets/ot_swipe.eliom b/src/widgets/ot_swipe.eliom index 7077e7b0..d17f739f 100644 --- a/src/widgets/ot_swipe.eliom +++ b/src/widgets/ot_swipe.eliom @@ -2,8 +2,10 @@ [%%shared open Js_of_ocaml] [%%client open Js_of_ocaml_lwt] + open%client Eliom_content.Html open%client Lwt.Syntax + [%%shared open Eliom_content.Html.F] (** sensibility for detecting swipe left/right or up/down *) @@ -13,19 +15,19 @@ let%client px_of_int v = Js.string (string_of_int v ^ "px") let%client identifier ev = Js.Optdef.case - ev ##. changedTouches ## (item 0) + ev##.changedTouches##(item 0) (fun () -> 0) (fun a -> a##.identifier) let%client clX ev = Js.Optdef.case - ev ##. changedTouches ## (item 0) + ev##.changedTouches##(item 0) (fun () -> 0.) (fun a -> Js.to_float a##.clientX) let%client clY ev = Js.Optdef.case - ev ##. changedTouches ## (item 0) + ev##.changedTouches##(item 0) (fun () -> 0.) (fun a -> Js.to_float a##.clientY) @@ -43,8 +45,8 @@ let%client dispatch_event ~ev elt name x y = let event = try (* Better version, but unsupported on iOS and Android: *) - let touchevent = Js.Unsafe.global ##. TouchEvent in - let touch = Js.Unsafe.global ##. Touch in + let touchevent = Js.Unsafe.global##.TouchEvent in + let touch = Js.Unsafe.global##.Touch in let touch = new%js touch (object%js @@ -66,7 +68,7 @@ let%client dispatch_event ~ev elt name x y = Printf.eprintf "%s\n" ("exn: " ^ Printexc.to_string e ^ " - switching to workaround. "); (* HACK *) - let customEvent = Js.Unsafe.global ##. CustomEvent in + let customEvent = Js.Unsafe.global##.CustomEvent in let opt = object%js val bubbles = Js._true @@ -92,25 +94,33 @@ let%client dispatch_event ~ev elt name x y = in (Js.Unsafe.coerce target)##dispatchEvent event) -let%shared bind ?(transition_duration = 0.3) - ?(min : (unit -> int) Eliom_client_value.t option) - ?(max : (unit -> int) Eliom_client_value.t option) - ~(compute_final_pos : - (Dom_html.touchEvent Js.t -> int -> int) Eliom_client_value.t) - ?(onstart : - (Dom_html.touchEvent Js.t -> int -> unit) Eliom_client_value.t option) - ?(onmove : - (Dom_html.touchEvent Js.t -> int -> unit) Eliom_client_value.t option) - ?(onend : - (Dom_html.touchEvent Js.t -> int -> unit) Eliom_client_value.t option) - (elt : _ elt) +let%shared + bind + ?(transition_duration = 0.3) + ?(min : (unit -> int) Eliom_client_value.t option) + ?(max : (unit -> int) Eliom_client_value.t option) + ~(compute_final_pos : + (Dom_html.touchEvent Js.t -> int -> int) Eliom_client_value.t) + ?(onstart : + (Dom_html.touchEvent Js.t -> int -> unit) Eliom_client_value.t option) + ?(onmove : + (Dom_html.touchEvent Js.t -> int -> unit) Eliom_client_value.t option) + ?(onend : + (Dom_html.touchEvent Js.t -> int -> unit) Eliom_client_value.t option) + (elt : _ elt) = ignore [%client (let elt = ~%elt in let elt' = To_dom.of_element elt in - let startx = ref 0. (* position when touch starts *) in - let starty = ref 0. (* position when touch starts *) in + let startx = + ref 0. + (* position when touch starts *) + in + let starty = + ref 0. + (* position when touch starts *) + in let status = ref Stopped in let onpanend ev aa = if !status <> Start diff --git a/src/widgets/ot_time_picker.eliom b/src/widgets/ot_time_picker.eliom index 9057e408..a7f3f25f 100644 --- a/src/widgets/ot_time_picker.eliom +++ b/src/widgets/ot_time_picker.eliom @@ -22,8 +22,8 @@ open Eliom_shared.React.S.Infix open Eliom_content.Html - open%client Js_of_ocaml + [%%client open Js_of_ocaml_lwt] type 'a rf = ?step:React.step -> 'a -> unit @@ -133,8 +133,10 @@ let clock_reactive_hand ?(radius = Eliom_shared.React.S.const 31) e = in Eliom_content.Svg.D.path ~a [] -let clock_reactive_hand_circle ?(radius = 9) - ?(at_radius = Eliom_shared.React.S.const 40) e +let clock_reactive_hand_circle + ?(radius = 9) + ?(at_radius = Eliom_shared.React.S.const 40) + e = let a = let cx = @@ -175,8 +177,12 @@ let make_clock_point ?(zero_is_12 = false) extra_attributes radius de step i = and msg = if i = 0 && zero_is_12 then "12" else string_of_int (step * i) in text ~a [txt msg] -let clock_svg ?zero_is_12 ?(extra_attributes = []) ?(n = 12) ?(step = 1) - (e : int Eliom_shared.React.S.t) +let clock_svg + ?zero_is_12 + ?(extra_attributes = []) + ?(n = 12) + ?(step = 1) + (e : int Eliom_shared.React.S.t) = assert (n >= 0 && 360 mod n = 0); let de = 360 / n in @@ -213,7 +219,7 @@ let%client wrap_touch_aux ev f = and oy' = Js.to_float r##.bottom in assert (ox' >= ox); assert (oy' >= oy); - Js.Optdef.iter ev ##. changedTouches ## (item 0) @@ fun touch0 -> + Js.Optdef.iter ev##.changedTouches##(item 0) @@ fun touch0 -> let x = (Js.to_float touch0##.clientX -. ox) *. 100. /. (ox' -. ox) |> truncate and y = @@ -375,8 +381,10 @@ let display_hours_minutes_seq ?h24 f = Eliom_shared.React.S.l2 [%shared display_hours_minutes_seq ?h24:~%h24 ~%f] let show_minutes_aux - ?(action : (int * int -> unit Lwt.t) Eliom_client_value.t option) e_m hm - f_e_m + ?(action : (int * int -> unit Lwt.t) Eliom_client_value.t option) + e_m + hm + f_e_m = clock_html_wrap ~classes:["ot-tp-clock-min"] (clock_svg ~n:12 ~step:5 e_m) @@ -399,9 +407,11 @@ let get_angle_signal ?round = | _, _ -> e] let make_hours_minutes_seq_24h - ?(action : (int * int -> unit Lwt.t) Eliom_client_value.t option) - ?(init = 0, 0) ?(update : (int * int) React.E.t Eliom_client_value.t option) - ?round_5 () + ?(action : (int * int -> unit Lwt.t) Eliom_client_value.t option) + ?(init = 0, 0) + ?(update : (int * int) React.E.t Eliom_client_value.t option) + ?round_5 + () = let i_h, i_m = init in let i_m = round_5_minutes ?round_5 i_m in diff --git a/src/widgets/ot_tip.eliom b/src/widgets/ot_tip.eliom index 56cc74b4..2db080c5 100644 --- a/src/widgets/ot_tip.eliom +++ b/src/widgets/ot_tip.eliom @@ -24,16 +24,21 @@ open Js_of_ocaml] [%%client open Eliom_content.Html] [%%client open Eliom_content.Html.F] -let%client display ?(container_a = [a_class ["ot-tip-container"]]) - ?(filter_a = [a_class ["ot-tip-filter"]]) - ?(position : - [`Forced_top | `Top | `Ratio of float | `Bottom | `Forced_bottom] = - `Ratio 0.5) ?(side : [`Center | `Left | `Right] = `Center) - ~(origin : Dom_html.element Js.t) ?(onopen = fun _ _ -> ()) - ?(onclose = fun _ _ -> ()) - ~(content : - (unit -> unit) - -> [< Html_types.div_content_fun > `Div] Eliom_content.Html.elt list) () +let%client + display + ?(container_a = [a_class ["ot-tip-container"]]) + ?(filter_a = [a_class ["ot-tip-filter"]]) + ?(position : + [`Forced_top | `Top | `Ratio of float | `Bottom | `Forced_bottom] = + `Ratio 0.5) + ?(side : [`Center | `Left | `Right] = `Center) + ~(origin : Dom_html.element Js.t) + ?(onopen = fun _ _ -> ()) + ?(onclose = fun _ _ -> ()) + ~(content : + (unit -> unit) + -> [< Html_types.div_content_fun > `Div] Eliom_content.Html.elt list) + () = let close = ref @@ fun () -> () in let container = diff --git a/src/widgets/ot_toggle.eliom b/src/widgets/ot_toggle.eliom index 9c665c38..c9e819b7 100644 --- a/src/widgets/ot_toggle.eliom +++ b/src/widgets/ot_toggle.eliom @@ -49,8 +49,12 @@ let display_toggle ?(up_txt = "up") ?(down_txt = "down") f = [txt up_txt] ; div ~a:[a_class ["ot-active"; "ot-down"]] [txt down_txt] ] -let make ?(init_up = false) ?up_txt ?down_txt - ?(update : bool React.E.t Eliom_client_value.t option) () +let make + ?(init_up = false) + ?up_txt + ?down_txt + ?(update : bool React.E.t Eliom_client_value.t option) + () = let e, f = Eliom_shared.React.S.create (if init_up then T_Up else T_Down) in let elt = diff --git a/src/widgets/ot_tongue.eliom b/src/widgets/ot_tongue.eliom index 695fe745..29b9d21a 100644 --- a/src/widgets/ot_tongue.eliom +++ b/src/widgets/ot_tongue.eliom @@ -56,13 +56,13 @@ let%client now () = Js.to_float (new%js Js.date_now)##getTime /. 1000. let%client clX ev = Js.Optdef.case - ev ##. changedTouches ## (item 0) + ev##.changedTouches##(item 0) (fun () -> 0.) (fun a -> Js.to_float a##.clientX) let%client clY ev = Js.Optdef.case - ev ##. changedTouches ## (item 0) + ev##.changedTouches##(item 0) (fun () -> 0.) (fun a -> Js.to_float a##.clientY) @@ -215,8 +215,17 @@ let%client enable_transition ?duration elt = Manip.Class.remove elt "notransition"; Lwt_js_events.request_animation_frame () -let%client bind side stops init handle update set_before_signal set_after_signal - set_swipe_pos elt +let%client + bind + side + stops + init + handle + update + set_before_signal + set_after_signal + set_swipe_pos + elt = let open Lwt_js_events in let elt' = To_dom.of_element elt in @@ -231,7 +240,10 @@ let%client bind side stops init handle update set_before_signal set_after_signal let currentpos = ref 0. in let previouspos = ref 0. in let previoustimestamp = ref 0. in - let startsize = ref 0. (* height or width of visible part in pixel *) in + let startsize = + ref 0. + (* height or width of visible part in pixel *) + in let animation_frame_requested = ref false in let set speed (stop, is_attractor) = let previousstop = !currentstop in @@ -362,10 +374,16 @@ let%client bind side stops init handle update set_before_signal set_after_signal ~keep:(React.E.map (fun stop -> set 0.0 (stop, true)) update) | None -> () -let%shared tongue ?(a = []) ?(side = `Bottom) - ?(stops : stop list = - [`Px 70; `Percent 100; `Interval (`Percent 100, `Full_content)]) - ?(init : simple_stop = `Px 70) ?handle ?update content +let%shared + tongue + ?(a = []) + ?(side = `Bottom) + ?(stops : stop list = + [`Px 70; `Percent 100; `Interval (`Percent 100, `Full_content)]) + ?(init : simple_stop = `Px 70) + ?handle + ?update + content = let a = (a :> Html_types.div_attrib attrib list) in let class_ = class_of_side side in