diff --git a/.ocamlformat b/.ocamlformat index a7668bf8f9..a84459a472 100644 --- a/.ocamlformat +++ b/.ocamlformat @@ -1,5 +1,6 @@ -version=0.27.0 +version=0.28.1 parse-docstrings = false +wrap-comments = false break-cases = fit break-collection-expressions = fit-or-vertical break-fun-decl = wrap diff --git a/.ocp-indent b/.ocp-indent index e98972dec4..e42012c136 100644 --- a/.ocp-indent +++ b/.ocp-indent @@ -1,4 +1,4 @@ normal with=0 -syntax=lwt mll +syntax=mll max_indent=2 diff --git a/dune-project b/dune-project index 91fcfcfdca..7799eb20ad 100644 --- a/dune-project +++ b/dune-project @@ -1,7 +1,7 @@ (lang dune 3.19) (name eliom) -(version 11.1.1) +(version 12.0.0~dev) (maintainers dev@ocsigen.org) (authors dev@ocsigen.org) (license "LGPL-2.1-only WITH OCaml-LGPL-linking-exception") @@ -28,7 +28,6 @@ The client-side code is compiled to JS using Ocsigen Js_of_ocaml or to Wasm usin (ppxlib (>= 0.15)) (js_of_ocaml-compiler (>= 6.0)) (js_of_ocaml (>= 6.0)) - (js_of_ocaml-lwt (>= 6.0)) (js_of_ocaml-ocamlbuild :build) (js_of_ocaml-ppx (>= 6.0)) (js_of_ocaml-ppx_deriving_json (>= 6.0)) @@ -41,4 +40,5 @@ The client-side code is compiled to JS using Ocsigen Js_of_ocaml or to Wasm usin base-bytes (ocsipersist (and (>= 2.0) (< 3.0))) ppx_optcomp - (xml-light (>= "2.5")))) + (xml-light (>= "2.5")) + js_of_ocaml-eio)) diff --git a/eliom.opam b/eliom.opam index 0a5a479070..d39dbb5840 100644 --- a/eliom.opam +++ b/eliom.opam @@ -1,6 +1,6 @@ # This file is generated by dune, edit dune-project instead opam-version: "2.0" -version: "11.1.1" +version: "12.0.0~dev" synopsis: "Advanced client/server Web and mobile framework" description: """ Eliom is a framework for implementing Web sites and client/server Web and mobile applications. @@ -24,7 +24,6 @@ depends: [ "ppxlib" {>= "0.15"} "js_of_ocaml-compiler" {>= "6.0"} "js_of_ocaml" {>= "6.0"} - "js_of_ocaml-lwt" {>= "6.0"} "js_of_ocaml-ocamlbuild" {build} "js_of_ocaml-ppx" {>= "6.0"} "js_of_ocaml-ppx_deriving_json" {>= "6.0"} @@ -38,6 +37,7 @@ depends: [ "ocsipersist" {>= "2.0" & < "3.0"} "ppx_optcomp" "xml-light" {>= "2.5"} + "js_of_ocaml-eio" "odoc" {with-doc} ] build: [ diff --git a/pkg/distillery/templates/app.exe/PROJECT_NAME.eliom b/pkg/distillery/templates/app.exe/PROJECT_NAME.eliom index 2f69b13869..fc32e2f7fd 100644 --- a/pkg/distillery/templates/app.exe/PROJECT_NAME.eliom +++ b/pkg/distillery/templates/app.exe/PROJECT_NAME.eliom @@ -1,11 +1,12 @@ -(* This file was generated by Eliom-distillery. - Feel free to use it, modify it, and redistribute it as you wish. *) +(* This file was generated by Eliom-distillery. Feel free to use it, modify it, + and redistribute it as you wish. *) let%server application_name = "%%%PROJECT_NAME%%%" let%client application_name = Eliom_client.get_application_name () let%server () = - Ocsipersist_settings.set_db_file "local/var/data/%%%PROJECT_NAME%%%/%%%PROJECT_NAME%%%_db"; + Ocsipersist_settings.set_db_file + "local/var/data/%%%PROJECT_NAME%%%/%%%PROJECT_NAME%%%_db" (* Create a module for the application. See https://ocsigen.org/eliom/manual/clientserver-applications for more @@ -15,9 +16,9 @@ module%shared App = Eliom_registration.App (struct let global_data_path = Some ["__global_data__"] end) -(* As the headers (stylesheets, etc) won't change, we ask Eliom not to - update the
of the page when changing page. (This also avoids - blinking when changing page in iOS). *) +(* As the headers (stylesheets, etc) won't change, we ask Eliom not to update + the of the page when changing page. (This also avoids blinking when + changing page in iOS). *) let%client _ = Eliom_client.persist_document_head () let%server main_service = @@ -28,15 +29,14 @@ let%client main_service = ~%main_service let%shared () = App.register ~service:main_service (fun () () -> - Lwt.return - Eliom_content.Html.F.( - html - (head - (title (txt "%%%PROJECT_NAME%%%")) - [ css_link - ~uri: - (make_uri - ~service:(Eliom_service.static_dir ()) - ["css"; "%%%PROJECT_NAME%%%.css"]) - () ]) - (body [h1 [txt "Welcome to Eliom!"]]))) + Eliom_content.Html.F.( + html + (head + (title (txt "%%%PROJECT_NAME%%%")) + [ css_link + ~uri: + (make_uri + ~service:(Eliom_service.static_dir ()) + ["css"; "%%%PROJECT_NAME%%%.css"]) + () ]) + (body [h1 [txt "Welcome to Eliom!"]]))) diff --git a/pkg/distillery/templates/app.exe/dune b/pkg/distillery/templates/app.exe/dune index 79f6fd711e..48669291a3 100644 --- a/pkg/distillery/templates/app.exe/dune +++ b/pkg/distillery/templates/app.exe/dune @@ -100,10 +100,12 @@ ; %%%MODULE_NAME%%%_i18n )) (js_of_ocaml - (build_runtime_flags :standard --enable use-js-string) + (build_runtime_flags :standard --enable use-js-string --enable effects) (flags :standard --enable + effects + --enable with-js-error --enable use-js-string diff --git a/pkg/distillery/templates/app.lib/PROJECT_NAME.eliom b/pkg/distillery/templates/app.lib/PROJECT_NAME.eliom index 6fe38deee0..a40f41f941 100644 --- a/pkg/distillery/templates/app.lib/PROJECT_NAME.eliom +++ b/pkg/distillery/templates/app.lib/PROJECT_NAME.eliom @@ -1,5 +1,5 @@ -(* This file was generated by Eliom-distillery. - Feel free to use it, modify it, and redistribute it as you wish. *) +(* This file was generated by Eliom-distillery. Feel free to use it, modify it, + and redistribute it as you wish. *) let%server application_name = "%%%PROJECT_NAME%%%" let%client application_name = Eliom_client.get_application_name () @@ -12,9 +12,9 @@ module%shared App = Eliom_registration.App (struct let global_data_path = Some ["__global_data__"] end) -(* As the headers (stylesheets, etc) won't change, we ask Eliom not to - update the of the page when changing page. (This also avoids - blinking when changing page in iOS). *) +(* As the headers (stylesheets, etc) won't change, we ask Eliom not to update + the of the page when changing page. (This also avoids blinking when + changing page in iOS). *) let%client _ = Eliom_client.persist_document_head () let%server main_service = @@ -25,15 +25,14 @@ let%client main_service = ~%main_service let%shared () = App.register ~service:main_service (fun () () -> - Lwt.return - Eliom_content.Html.F.( - html - (head - (title (txt "%%%PROJECT_NAME%%%")) - [ css_link - ~uri: - (make_uri - ~service:(Eliom_service.static_dir ()) - ["css"; "%%%PROJECT_NAME%%%.css"]) - () ]) - (body [h1 [txt "Welcome to Eliom!"]]))) + Eliom_content.Html.F.( + html + (head + (title (txt "%%%PROJECT_NAME%%%")) + [ css_link + ~uri: + (make_uri + ~service:(Eliom_service.static_dir ()) + ["css"; "%%%PROJECT_NAME%%%.css"]) + () ]) + (body [h1 [txt "Welcome to Eliom!"]]))) diff --git a/pkg/distillery/templates/app.lib/dune b/pkg/distillery/templates/app.lib/dune index 3e04eda1d4..85ab8caf0a 100644 --- a/pkg/distillery/templates/app.lib/dune +++ b/pkg/distillery/templates/app.lib/dune @@ -71,10 +71,12 @@ ; %%%MODULE_NAME%%%_i18n )) (js_of_ocaml - (build_runtime_flags :standard --enable use-js-string) + (build_runtime_flags :standard --enable use-js-string --enable effects) (flags :standard --enable + effects + --enable with-js-error --enable use-js-string diff --git a/pkg/distillery/templates/basic.ppx/PROJECT_NAME.eliom b/pkg/distillery/templates/basic.ppx/PROJECT_NAME.eliom index c04a600377..dd5a1b5629 100644 --- a/pkg/distillery/templates/basic.ppx/PROJECT_NAME.eliom +++ b/pkg/distillery/templates/basic.ppx/PROJECT_NAME.eliom @@ -21,10 +21,9 @@ let () = %%%MODULE_NAME%%%_app.register ~service:main_service (fun () () -> - Lwt.return - (Eliom_tools.F.html - ~title:"%%%PROJECT_NAME%%%" - ~css:[["css";"%%%PROJECT_NAME%%%.css"]] - Html.F.(body [ - h1 [txt "Welcome from Eliom's distillery!"]; - ]))) + (Eliom_tools.F.html + ~title:"%%%PROJECT_NAME%%%" + ~css:[["css";"%%%PROJECT_NAME%%%.css"]] + Html.F.(body [ + h1 [txt "Welcome from Eliom's distillery!"]; + ]))) diff --git a/src/lib/client/dune b/src/lib/client/dune index dace844303..4ff37218e2 100644 --- a/src/lib/client/dune +++ b/src/lib/client/dune @@ -21,14 +21,14 @@ ocsigenserver.polytables js_of_ocaml js_of_ocaml-tyxml - js_of_ocaml-lwt - lwt_react + react ocsigenserver.baselib.base logs logs.browser cohttp tyxml - reactiveData) + reactiveData + js_of_ocaml-eio) (foreign_stubs (language c) (names eliom_stubs)) diff --git a/src/lib/client/dune.client b/src/lib/client/dune.client index 68f8ab59b5..375a16e59f 100644 --- a/src/lib/client/dune.client +++ b/src/lib/client/dune.client @@ -1,3 +1,5 @@ +(rule (copy# ../eio_react.shared.ml eio_react.ml)) +(rule (copy# ../eio_react.shared.mli eio_react.mli)) (rule (copy# ../eliom_bus.client.ml eliom_bus.ml)) (rule (copy# ../eliom_bus.client.mli eliom_bus.mli)) (rule (copy# ../eliom_client.client.ml eliom_client.ml)) @@ -90,6 +92,8 @@ (with-stdout-to %{target} (chdir .. (run ppx_eliom_client --as-pp --intf %{deps}))))) (rule (copy# ../eliom_shared_sigs.shared.mli eliom_shared_sigs.mli)) +(rule (copy# ../eliom_stream.shared.ml eliom_stream.ml)) +(rule (copy# ../eliom_stream.shared.mli eliom_stream.mli)) (rule (target eliom_tools.ml) (deps ../eliom_tools.eliom) (action (with-stdout-to %{target} diff --git a/src/lib/client/eliommod_dom.ml b/src/lib/client/eliommod_dom.ml index 54028c8fb9..72df496ef9 100644 --- a/src/lib/client/eliommod_dom.ml +++ b/src/lib/client/eliommod_dom.ml @@ -1,4 +1,4 @@ -open Lwt.Syntax +open Eio.Std (* Ocsigen * http://www.ocsigen.org @@ -479,7 +479,7 @@ let fetch_linked_css e = let css = Eliom_request.http_get href [] Eliom_request.string_result in - acc @ [e, (e##.media, href, css >|= snd)] + acc @ [e, (e##.media, href, snd css)] | Dom.Element e -> let c = e##.childNodes in let acc = ref acc in @@ -578,26 +578,25 @@ let rewrite_css_url ~prefix css pos = let import_re = Regexp.regexp "@import\\s*" let rec rewrite_css ~max (media, href, css) = - Lwt.catch - (fun () -> - css >>= function - | None -> Lwt.return_nil - | Some css -> - if !Eliom_config.debug_timings - then Console.console##(time (Js.string ("rewrite_CSS: " ^ href))); - let* imports, css = - rewrite_css_import ~max ~prefix:(basedir href) ~media css 0 - in - if !Eliom_config.debug_timings - then Console.console##(timeEnd (Js.string ("rewrite_CSS: " ^ href))); - Lwt.return (imports @ [media, css])) - (fun _ -> Lwt.return [media, Printf.sprintf "@import url(%s);" href]) + try + match css with + | None -> [] + | Some css -> + if !Eliom_config.debug_timings + then Console.console##(time (Js.string ("rewrite_CSS: " ^ href))); + let imports, css = + rewrite_css_import ~max ~prefix:(basedir href) ~media css 0 + in + if !Eliom_config.debug_timings + then Console.console##(timeEnd (Js.string ("rewrite_CSS: " ^ href))); + imports @ [media, css] + with _ -> [media, Printf.sprintf "@import url(%s);" href] and rewrite_css_import ?(charset = "") ~max ~prefix ~media css pos = match Regexp.search import_re css pos with | None -> (* No @import anymore, rewrite url. *) - Lwt.return ([], rewrite_css_url ~prefix css pos) + [], rewrite_css_url ~prefix css pos | Some (i, res) -> ( (* Found @import rule, try to preload. *) let init = String.sub css pos (i - pos) in @@ -606,45 +605,45 @@ and rewrite_css_import ?(charset = "") ~max ~prefix ~media css pos = let i = i + String.length (Regexp.matched_string res) in let i, href = parse_url ~prefix css i in let i, media' = parse_media css i in - let* import = - if max = 0 - then - (* Maximum imbrication of @import reached, rewrite url. *) - Lwt.return - [media, Printf.sprintf "@import url('%s') %s;\n" href media'] - else if media##.length > 0 && String.length media' > 0 - then - (* TODO combine media if possible... + let (imports, css), import = + Fiber.pair + (fun () -> rewrite_css_import ~charset ~max ~prefix ~media css i) + (fun () -> + if + max = 0 + then + (* Maximum imbrication of @import reached, rewrite url. *) + [media, Printf.sprintf "@import url('%s') %s;\n" href media'] + else if media##.length > 0 && String.length media' > 0 + then + (* TODO combine media if possible... in the mean time keep explicit import. *) - Lwt.return - [media, Printf.sprintf "@import url('%s') %s;\n" href media'] - else - let media = - if media##.length > 0 then media else Js.string media' - in - let css = - Eliom_request.http_get href [] Eliom_request.string_result - in - rewrite_css ~max:(max - 1) (media, href, css >|= snd) - and* imports, css = - rewrite_css_import ~charset ~max ~prefix ~media css i + [media, Printf.sprintf "@import url('%s') %s;\n" href media'] + else + let media = + if media##.length > 0 then media else Js.string media' + in + let css = + Eliom_request.http_get href [] Eliom_request.string_result + in + rewrite_css ~max:(max - 1) (media, href, snd css)) in - Lwt.return (import @ imports, css) + import @ imports, css with - | Incorrect_url -> Lwt.return ([], rewrite_css_url ~prefix css pos) + | Incorrect_url -> [], rewrite_css_url ~prefix css pos | exn -> Logs.info ~src:section (fun fmt -> fmt ("Error while importing css" ^^ "@\n%s") (Printexc.to_string exn)); - Lwt.return ([], rewrite_css_url ~prefix css pos)) + [], rewrite_css_url ~prefix css pos) let max_preload_depth = ref 4 let build_style (e, css) = - let* css = rewrite_css ~max:!max_preload_depth css in - (* lwt css = *) - Lwt_list.map_p + let css = rewrite_css ~max:!max_preload_depth css in + Fiber.List.map + (* lwt css = *) (fun (media, css) -> let style = Dom_html.createStyle Dom_html.document in style##._type := Js.string "text/css"; @@ -655,7 +654,7 @@ let build_style (e, css) = if Js.Optdef.test styleSheet then Js.Unsafe.(set styleSheet (Js.string "cssText") (Js.string css)) else style##.innerHTML := Js.string css; - Lwt.return (e, (style :> Dom.node Js.t))) + e, (style :> Dom.node Js.t)) css (* IE8 doesn't allow appendChild on noscript-elements *) @@ -669,7 +668,7 @@ let build_style (e, css) = let preload_css (doc : Dom_html.element Js.t) = if !Eliom_config.debug_timings then Console.console##(time (Js.string "preload_css (fetch+rewrite)")); - let* css = Lwt_list.map_p build_style (fetch_linked_css (get_head doc)) in + let css = Fiber.List.map build_style (fetch_linked_css (get_head doc)) in let css = List.concat css in List.iter (fun (e, css) -> @@ -682,8 +681,7 @@ let preload_css (doc : Dom_html.element Js.t) = section (fun fmt -> fmt "Unique CSS skipped...")) css; if !Eliom_config.debug_timings - then Console.console##(timeEnd (Js.string "preload_css (fetch+rewrite)")); - Lwt.return_unit + then Console.console##(timeEnd (Js.string "preload_css (fetch+rewrite)")) (** Window scrolling *) diff --git a/src/lib/client/eliommod_dom.mli b/src/lib/client/eliommod_dom.mli index 5286bd8e50..70267dcd90 100644 --- a/src/lib/client/eliommod_dom.mli +++ b/src/lib/client/eliommod_dom.mli @@ -71,7 +71,7 @@ val html_document : (** Assuming [d] has a body and head element, [html_document d] will return the same document as html *) -val preload_css : Dom_html.element Js.t -> unit Lwt.t +val preload_css : Dom_html.element Js.t -> unit (** [preload_css e] downloads every css included in every link elements that is a descendant of [e] and replace it and its linked css by inline [