Skip to content

Commit

Permalink
Add missing fns that are needed for universal-components (#16)
Browse files Browse the repository at this point in the history
* Re-export CssJs

* Re-export CssJs.style

* Remove crap from js

* Remove crap from mli

* Maintain interface

* Create type rule

* Bring all melange.ppx features

* Support ReactDOM.createDOMElementVariadic

* Move domProps into its own file

* Add suppressHydrationWarning

* Implement React.Children.*

* Fix fontFamily

* Fix Children interface

* Remove pinning (#17)
  • Loading branch information
davesnx authored May 31, 2023
1 parent 64c9f9f commit 3dc58eb
Show file tree
Hide file tree
Showing 20 changed files with 1,918 additions and 923 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ setup-githooks: ## Setup githooks

.PHONY: pin
pin: ## Pin dependencies
@opam pin add melange-compiler-libs.dev "https://github.com/melange-re/melange-compiler-libs.git#575ac4c24b296ea897821f9aaee1146ff258c704" -y
@opam pin add melange.dev "https://github.com/melange-re/melange.git#ebc038332c16e331ee4ab9017426e63461157cdd" -y
@opam pin add melange "https://github.com/melange-re/melange.git#47c95b328039161142c6313843100ffb989282f5" -y

.PHONY: create-switch
create-switch: ## Create opam switch
Expand Down
13 changes: 13 additions & 0 deletions lib/css/css.ml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,19 @@ let render_style_tag () =
Printf.sprintf "%s %s" accumulator rules)
cache.contents ""

(* Re-export CssJs to have compatibility with bs-css *)
type rule = Rule.t

module CssJs = struct
include Properties
include Colors
include Rule

type rule = Rule.t

let style arr = style (Array.to_list arr)
end

(* let keyframes name rules =
let rules =
rules
Expand Down
49 changes: 23 additions & 26 deletions lib/css/properties.re
Original file line number Diff line number Diff line change
Expand Up @@ -1806,21 +1806,14 @@ let backgroundSize = x =>
);

let fontFace =
(
~fontFamily as _,
~src,
~fontStyle as _=?,
~fontWeight=?,
~fontDisplay=?,
(),
) => {
let _fontStyle = "font-style: " ++ "normal" ++ ";";
/* let fontStyle =
fontStyle
|> Option.map(FontStyle.toString)
|> Option.get("", s => "font-style: " ++ s ++ ";"); */

let _src =
(~fontFamily, ~src, ~fontStyle=?, ~fontWeight=?, ~fontDisplay=?, ()) => {
let fontStyle =
switch (fontStyle) {
| Some(style) => "font-style: " ++ style ++ ";"
| None => ""
};

let src =
src
|> concatArr(
fun
Expand All @@ -1829,8 +1822,10 @@ let fontFace =
", ",
);

let _fontWeight =
Option.get(fontWeight, "", w =>
let fontWeight =
switch (fontWeight) {
| None => ""
| Some(w) =>
"font-weight: "
++ (
switch (w) {
Expand All @@ -1840,19 +1835,21 @@ let fontFace =
}
)
++ ";"
);
let _fontDisplay =
};

let fontDisplay =
Option.get(fontDisplay, "", f =>
"font-display: " ++ FontDisplay.toString(f) ++ ";"
);

{j|@font-face {
font-family: $fontFamily;
src: $src;
$(fontStyle)
$(fontWeight)
$(fontDisplay)
}|j};
Printf.sprintf(
"@font-face { font-family: %s;\nsrc: %s;\n%s\n%s\n%s }",
fontFamily,
src,
fontStyle,
fontWeight,
fontDisplay,
);
};

let textDecoration = x =>
Expand Down
85 changes: 28 additions & 57 deletions lib/js/js.ml
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
type 'a t = < .. > as 'a

module Fn = struct
type 'a arity0 = { i0 : unit -> 'a [@internal] }
type 'a arity1 = { i1 : 'a [@internal] }
type 'a arity2 = { i2 : 'a [@internal] }
type 'a arity3 = { i3 : 'a [@internal] }
type 'a arity4 = { i4 : 'a [@internal] }
type 'a arity5 = { i5 : 'a [@internal] }
type 'a arity6 = { i6 : 'a [@internal] }
type 'a arity7 = { i7 : 'a [@internal] }
type 'a arity8 = { i8 : 'a [@internal] }
type 'a arity9 = { i9 : 'a [@internal] }
type 'a arity10 = { i10 : 'a [@internal] }
type 'a arity11 = { i11 : 'a [@internal] }
type 'a arity12 = { i12 : 'a [@internal] }
type 'a arity13 = { i13 : 'a [@internal] }
type 'a arity14 = { i14 : 'a [@internal] }
type 'a arity15 = { i15 : 'a [@internal] }
type 'a arity16 = { i16 : 'a [@internal] }
type 'a arity17 = { i17 : 'a [@internal] }
type 'a arity18 = { i18 : 'a [@internal] }
type 'a arity19 = { i19 : 'a [@internal] }
type 'a arity20 = { i20 : 'a [@internal] }
type 'a arity21 = { i21 : 'a [@internal] }
type 'a arity22 = { i22 : 'a [@internal] }
end
(* module Fn = struct
type 'a arity0 = { i0 : unit -> 'a [@internal] }
type 'a arity1 = { i1 : 'a [@internal] }
type 'a arity2 = { i2 : 'a [@internal] }
type 'a arity3 = { i3 : 'a [@internal] }
type 'a arity4 = { i4 : 'a [@internal] }
type 'a arity5 = { i5 : 'a [@internal] }
type 'a arity6 = { i6 : 'a [@internal] }
type 'a arity7 = { i7 : 'a [@internal] }
type 'a arity8 = { i8 : 'a [@internal] }
type 'a arity9 = { i9 : 'a [@internal] }
type 'a arity10 = { i10 : 'a [@internal] }
type 'a arity11 = { i11 : 'a [@internal] }
type 'a arity12 = { i12 : 'a [@internal] }
type 'a arity13 = { i13 : 'a [@internal] }
type 'a arity14 = { i14 : 'a [@internal] }
type 'a arity15 = { i15 : 'a [@internal] }
type 'a arity16 = { i16 : 'a [@internal] }
type 'a arity17 = { i17 : 'a [@internal] }
type 'a arity18 = { i18 : 'a [@internal] }
type 'a arity19 = { i19 : 'a [@internal] }
type 'a arity20 = { i20 : 'a [@internal] }
type 'a arity21 = { i21 : 'a [@internal] }
type 'a arity22 = { i22 : 'a [@internal] }
end *)

(**/**)

Expand Down Expand Up @@ -154,9 +154,9 @@ module Nullable = struct
let bind x f =
match to_opt x with
| None -> (Stdlib.Obj.magic (x : 'a t) : 'b t)
| Some x -> return (f x [@bs])
| Some x -> return (f x)

let iter x f = match to_opt x with None -> () | Some x -> f x [@bs]
let iter x f = match to_opt x with None -> () | Some x -> f x
let fromOption x = match x with None -> undefined | Some x -> return x
let from_opt = fromOption
end
Expand Down Expand Up @@ -742,41 +742,12 @@ module Re = struct
fun regexp str ->
try
let rex = regexp.regex in
print_endline (Printf.sprintf "before lastIndex: %d" regexp.lastIndex);
let substrings = Pcre.exec ~rex ~pos:regexp.lastIndex str in
let _, lastIndex = Pcre.get_substring_ofs substrings 0 in
print_endline (Printf.sprintf "after lastIndex: %d" lastIndex);
regexp.lastIndex <- lastIndex;
let sbs =
Pcre.get_opt_substrings substrings
|> Stdlib.Array.to_list
|> Stdlib.List.filter_map (fun x -> x)
in
print_endline (Printf.sprintf "substrings: %s" (String.concat ", " sbs));
Some { substrings }
with Not_found -> None

let regexp = fromStringWithFlags ~flags:"g" ".ats"
let str = "cats and bats and mats"

let wat () =
try
let rex = regexp.regex in
let substrings = Pcre.exec ~rex ~pos:regexp.lastIndex str in
print_endline (Printf.sprintf "lastIndex: %d" regexp.lastIndex);
let _, lastIndex = Pcre.get_substring_ofs substrings 0 in
regexp.lastIndex <- lastIndex;
let sbs =
Pcre.get_opt_substrings substrings
|> Stdlib.Array.to_list
|> Stdlib.List.filter_map (fun x -> x)
in
print_endline (Printf.sprintf "substrings: %s" (String.concat ", " sbs));
()
with Not_found ->
regexp.lastIndex <- 0;
print_endline "Not found"

let exec : string -> t -> result option = fun str rex -> exec_ rex str

let test_ : t -> string -> bool =
Expand Down Expand Up @@ -1180,7 +1151,7 @@ let () = Js.log replaced (* prints "bEAUtifUl vOwEls" *)
@see <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_function_as_a_parameter> MDN
*)
let unsafeReplaceBy0 _ _ = failwith "TODO" = "replace" [@@bs.send.pipe: t]
let unsafeReplaceBy0 _ _ = failwith "TODO" = "replace"

(* external unsafeReplaceBy1 :
Re.t -> ((t -> t -> int -> t -> t)[@bs.uncurry]) -> t = "replace" [@@bs.send.pipe: t] *)
Expand Down
Loading

0 comments on commit 3dc58eb

Please sign in to comment.