diff --git a/src/ReactDOM.re b/src/ReactDOM.re index bedb622f2..7544cadcc 100644 --- a/src/ReactDOM.re +++ b/src/ReactDOM.re @@ -477,6 +477,91 @@ external unmountComponentAtNode: Dom.element => unit = [@mel.module "react-dom"] external flushSync: (unit => unit) => unit = "flushSync"; +module Experimental = { + type preloadOptions; + + [@mel.obj] + external preloadOptions: + ( + ~_as: [ + | `audio + | `document + | `embed + | `fetch + | `font + | `image + | [@mel.as "object"] `object_ + | `script + | `style + | `track + | `video + | `worker + ], + ~fetchPriority: [ | `auto | `high | `low]=?, + ~referrerPolicy: [ + | [@mel.as "no-referrer"] `noReferrer + | [@mel.as "no-referrer-when-downgrade"] + `noReferrerWhenDowngrade + | [@mel.as "origin"] `origin + | [@mel.as "origin-when-cross-origin"] + `originWhenCrossOrigin + | [@mel.as "unsafe-url"] `unsafeUrl + ] + =?, + ~imageSrcSet: string=?, + ~imageSizes: string=?, + ~crossOrigin: string=?, + ~integrity: string=?, + ~nonce: string=?, + unit + ) => + preloadOptions; + + [@deriving jsProperties] + type preinitOptions = { + [@mel.as "as"] + _as: [ | `script | `style], + [@mel.optional] + fetchPriority: option([ | `auto | `high | `low]), + [@mel.optional] + precedence: option([ | `reset | `low | `medium | `high]), + [@mel.optional] + crossOrigin: option(string), + [@mel.optional] + integrity: option(string), + [@mel.optional] + nonce: option(string), + }; + + [@deriving jsProperties] + type preOptions = { + [@mel.as "as"] + _as: [ | `script], + [@mel.optional] + crossOrigin: option(string), + [@mel.optional] + integrity: option(string), + [@mel.optional] + nonce: option(string), + }; + + [@mel.module "react-dom"] external preconnect: string => unit = "preconnect"; + [@mel.module "react-dom"] + external prefetchDNS: string => unit = "prefetchDNS"; + [@mel.module "react-dom"] + external preinit: (string, ~options: preinitOptions=?, unit) => unit = + "preinit"; + [@mel.module "react-dom"] + external preinitModule: (string, ~options: preOptions=?, unit) => unit = + "preinitModule"; + [@mel.module "react-dom"] + external preload: (string, ~options: preloadOptions=?, unit) => unit = + "preload"; + [@mel.module "react-dom"] + external preloadModule: (string, ~options: preOptions=?, unit) => unit = + "preloadModule"; +}; + external domElementToObj: Dom.element => Js.t({..}) = "%identity"; type style = Style.t; diff --git a/src/ReactDOM.rei b/src/ReactDOM.rei index 2310ca3e2..1433e0859 100644 --- a/src/ReactDOM.rei +++ b/src/ReactDOM.rei @@ -478,6 +478,169 @@ external unmountComponentAtNode: Dom.element => unit = [@mel.module "react-dom"] external flushSync: (unit => unit) => unit = "flushSync"; +module Experimental: { + /* This module is used to bind to APIs for future versions of ReactDOM. There is no guarantee of backwards compatibility or stability. */ + /* + preload options. + https://react.dev/reference/react-dom/preload#parameters + */ + type preloadOptions; + + [@mel.obj] + external preloadOptions: + /* Its possible values are audio, document, embed, fetch, font, image, object, script, style, track, video, worker. */ + ( + ~_as: [ + | `audio + | `document + | `embed + | `fetch + | `font + | `image + | [@mel.as "object"] `object_ + | `script + | `style + | `track + | `video + | `worker + ], + /* + Suggests a relative priority for fetching the resource. + The possible values are auto (the default), high, and low. + */ + ~fetchPriority: [ | `auto | `high | `low]=?, + /* + The Referrer header to send when fetching. + Its possible values are no-referrer-when-downgrade (the default), no-referrer, origin, origin-when-cross-origin, and unsafe-url. + */ + ~referrerPolicy: [ + | [@mel.as "no-referrer"] `noReferrer + | [@mel.as "no-referrer-when-downgrade"] + `noReferrerWhenDowngrade + | [@mel.as "origin"] `origin + | [@mel.as "origin-when-cross-origin"] + `originWhenCrossOrigin + | [@mel.as "unsafe-url"] `unsafeUrl + ] + =?, + /* + For use only with as: "image". Specifies the source set of the image. + https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images + */ + ~imageSrcSet: string=?, + /* + For use only with as: "image". Specifies the source sizes of the image. + https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images + */ + ~imageSizes: string=?, + /* + a required string. It must be "anonymous", "use-credentials", and "". + https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin + */ + ~crossOrigin: string=?, + /* + A cryptographic hash of the module, to verify its authenticity. + https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity + */ + ~integrity: string=?, + /* + A cryptographic nonce to allow the module when using a strict Content Security Policy. + https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/nonce + */ + ~nonce: string=?, + unit + ) => + preloadOptions; + + /* + preinit options. + https://react.dev/reference/react-dom/preinit#parameters + */ + [@deriving jsProperties] + type preinitOptions = { + /* possible values: "script" or "style" */ + [@mel.as "as"] + _as: [ | `script | `style], + /* + Suggests a relative priority for fetching the resource. + The possible values are auto (the default), high, and low. + */ + [@mel.optional] + fetchPriority: option([ | `auto | `high | `low]), + /* + Required with Stylesheets (`style). Says where to insert the stylesheet relative to others. + Stylesheets with higher precedence can override those with lower precedence. + The possible values are reset, low, medium, high. + */ + [@mel.optional] + precedence: option([ | `reset | `low | `medium | `high]), + /* + a required string. It must be "anonymous", "use-credentials", and "". + https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin + */ + [@mel.optional] + crossOrigin: option(string), + /* + A cryptographic hash of the module, to verify its authenticity. + https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity + */ + [@mel.optional] + integrity: option(string), + /* + A cryptographic nonce to allow the module when using a strict Content Security Policy. + https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/nonce + */ + [@mel.optional] + nonce: option(string), + }; + + /* + preinitModule and preloadModule options. + https://react.dev/reference/react-dom/preinitModule#parameters + https://react.dev/reference/react-dom/preloadModule#parameters + */ + [@deriving jsProperties] + type preOptions = { + /* It must be 'script'. */ + [@mel.as "as"] + _as: [ | `script], + /* + a required string. It must be "anonymous", "use-credentials", and "". + https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin + */ + [@mel.optional] + crossOrigin: option(string), + /* + A cryptographic hash of the module, to verify its authenticity. + https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity + */ + [@mel.optional] + integrity: option(string), + /* + A cryptographic nonce to allow the module when using a strict Content Security Policy. + https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/nonce + */ + [@mel.optional] + nonce: option(string), + }; + + [@mel.module "react-dom"] external preconnect: string => unit = "preconnect"; + [@mel.module "react-dom"] + external prefetchDNS: string => unit = "prefetchDNS"; + [@mel.module "react-dom"] + external preinit: (string, ~options: preinitOptions=?, unit) => unit = + "preinit"; + [@mel.module "react-dom"] + external preinitModule: (string, ~options: preOptions=?, unit) => unit = + "preinitModule"; + [@mel.module "react-dom"] + external preload: (string, ~options: preloadOptions=?, unit) => unit = + "preload"; + [@mel.module "react-dom"] + external preloadModule: (string, ~options: preOptions=?, unit) => unit = + "preloadModule"; +}; + external domElementToObj: Dom.element => Js.t({..}) = "%identity"; type style = Style.t;