@thecb/components 11.3.3-beta.1 → 11.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -24344,29 +24344,47 @@ function useConditionallyAddValidator(condition, validatorFn, addValidator, remo
24344
24344
  var useTurnstileScript = function useTurnstileScript(verifyURL) {
24345
24345
  var _useState = React.useState(false),
24346
24346
  _useState2 = _slicedToArray(_useState, 2),
24347
- isLoaded = _useState2[0],
24348
- setIsLoaded = _useState2[1];
24347
+ scriptLoaded = _useState2[0],
24348
+ setScriptLoaded = _useState2[1];
24349
+ var _useState3 = React.useState(false),
24350
+ _useState4 = _slicedToArray(_useState3, 2),
24351
+ scriptError = _useState4[0],
24352
+ setScriptError = _useState4[1];
24353
+ var handleScriptError = function handleScriptError() {
24354
+ setScriptError(true);
24355
+ setScriptLoaded(false);
24356
+ };
24349
24357
  React.useEffect(function () {
24350
24358
  if (typeof window === "undefined") {
24351
- setIsLoaded(false);
24359
+ setScriptLoaded(false);
24352
24360
  return;
24353
24361
  }
24354
24362
  if (window.turnstile && window.turnstile.render) {
24355
- setIsLoaded(true);
24363
+ setScriptLoaded(true);
24356
24364
  return;
24357
24365
  }
24358
24366
  var script = document.createElement("script");
24359
24367
  script.src = "".concat(verifyURL, "?render=explicit");
24360
24368
  script.onload = function () {
24361
- setIsLoaded(true);
24369
+ setScriptLoaded(true);
24370
+ };
24371
+ script.onerror = function () {
24372
+ handleScriptError();
24373
+ };
24374
+ script.onabort = function () {
24375
+ handleScriptError();
24362
24376
  };
24363
24377
  script.defer = true;
24364
24378
  document.getElementsByTagName("head")[0].appendChild(script);
24365
24379
  return function () {
24366
- setIsLoaded(false);
24380
+ setScriptLoaded(false);
24381
+ setScriptError(false);
24367
24382
  };
24368
24383
  }, [verifyURL]);
24369
- return isLoaded;
24384
+ return {
24385
+ scriptLoaded: scriptLoaded,
24386
+ scriptError: scriptError
24387
+ };
24370
24388
  };
24371
24389
 
24372
24390
 
@@ -49920,89 +49938,142 @@ var HeroImage$1 = withWindowSize(themeComponent(HeroImage, "HeroImage", fallback
49920
49938
  var TurnstileWidgetContainer = styled__default(Box).withConfig({
49921
49939
  displayName: "TurnstileWidget__TurnstileWidgetContainer",
49922
49940
  componentId: "sc-btaugr-0"
49923
- })(["display:flex;padding:", ";justify-content:", ";width:100%;"], function (_ref) {
49941
+ })(["display:flex;flex-direction:column;padding:", ";justify-content:", ";align-items:", ";width:100%;"], function (_ref) {
49924
49942
  var padding = _ref.padding;
49925
49943
  return padding;
49926
49944
  }, function (_ref2) {
49927
49945
  var justify = _ref2.justify;
49928
49946
  return justify;
49947
+ }, function (_ref3) {
49948
+ var align = _ref3.align;
49949
+ return align;
49929
49950
  });
49930
- var TurnstileWidget = /*#__PURE__*/React.forwardRef(function (_ref3, ref) {
49931
- var verifyURL = _ref3.verifyURL,
49932
- siteKey = _ref3.siteKey,
49933
- _ref3$onSuccess = _ref3.onSuccess,
49934
- onSuccess = _ref3$onSuccess === void 0 ? noop$1 : _ref3$onSuccess,
49935
- _ref3$onError = _ref3.onError,
49936
- onError = _ref3$onError === void 0 ? noop$1 : _ref3$onError,
49937
- _ref3$onExpired = _ref3.onExpired,
49938
- onExpired = _ref3$onExpired === void 0 ? noop$1 : _ref3$onExpired,
49939
- _ref3$padding = _ref3.padding,
49940
- padding = _ref3$padding === void 0 ? "1rem" : _ref3$padding,
49941
- _ref3$justify = _ref3.justify,
49942
- justify = _ref3$justify === void 0 ? "flex-end" : _ref3$justify,
49943
- _ref3$size = _ref3.size,
49944
- size = _ref3$size === void 0 ? "normal" : _ref3$size,
49945
- _ref3$tabindex = _ref3.tabindex,
49946
- tabindex = _ref3$tabindex === void 0 ? 0 : _ref3$tabindex,
49947
- _ref3$retry = _ref3.retry,
49948
- retry = _ref3$retry === void 0 ? "auto" : _ref3$retry,
49949
- _ref3$theme = _ref3.theme,
49950
- theme = _ref3$theme === void 0 ? "auto" : _ref3$theme,
49951
- _ref3$extraStyles = _ref3.extraStyles,
49952
- extraStyles = _ref3$extraStyles === void 0 ? "" : _ref3$extraStyles;
49951
+ var FATAL_ERROR_CODES = [
49952
+ // Configuration errors
49953
+ /^100/, /^105/, /^110100$/, /^110110$/, /^110200$/, /^110420$/, /^110430$/, /^400020$/, /^400030$/, /^400040$/,
49954
+ // Browser/environment errors
49955
+ /^110500$/, /^110510$/, /^200010$/, /^200100$/,
49956
+ // Internal errors
49957
+ /^120/];
49958
+ var TurnstileWidget = /*#__PURE__*/React.forwardRef(function (_ref4, ref) {
49959
+ var verifyURL = _ref4.verifyURL,
49960
+ siteKey = _ref4.siteKey,
49961
+ _ref4$onSuccess = _ref4.onSuccess,
49962
+ onSuccess = _ref4$onSuccess === void 0 ? noop$1 : _ref4$onSuccess,
49963
+ _ref4$onError = _ref4.onError,
49964
+ onError = _ref4$onError === void 0 ? noop$1 : _ref4$onError,
49965
+ _ref4$onExpired = _ref4.onExpired,
49966
+ onExpired = _ref4$onExpired === void 0 ? noop$1 : _ref4$onExpired,
49967
+ _ref4$padding = _ref4.padding,
49968
+ padding = _ref4$padding === void 0 ? "1rem" : _ref4$padding,
49969
+ _ref4$justify = _ref4.justify,
49970
+ justify = _ref4$justify === void 0 ? "flex-end" : _ref4$justify,
49971
+ _ref4$align = _ref4.align,
49972
+ align = _ref4$align === void 0 ? "flex-end" : _ref4$align,
49973
+ _ref4$size = _ref4.size,
49974
+ size = _ref4$size === void 0 ? "normal" : _ref4$size,
49975
+ _ref4$tabindex = _ref4.tabindex,
49976
+ tabindex = _ref4$tabindex === void 0 ? 0 : _ref4$tabindex,
49977
+ _ref4$retry = _ref4.retry,
49978
+ retry = _ref4$retry === void 0 ? "never" : _ref4$retry,
49979
+ _ref4$theme = _ref4.theme,
49980
+ theme = _ref4$theme === void 0 ? "light" : _ref4$theme,
49981
+ _ref4$extraStyles = _ref4.extraStyles,
49982
+ extraStyles = _ref4$extraStyles === void 0 ? "" : _ref4$extraStyles;
49953
49983
  if (!verifyURL || !siteKey) return null;
49954
49984
  var widgetRef = React.useRef(null);
49985
+ var widgetIdRef = React.useRef(null);
49955
49986
  var _useState = React.useState(null),
49956
49987
  _useState2 = _slicedToArray(_useState, 2),
49957
- widgetId = _useState2[0],
49958
- setWidgetId = _useState2[1];
49959
- var isTurnstileLoaded = useTurnstileScript(verifyURL);
49988
+ error = _useState2[0],
49989
+ setError = _useState2[1];
49990
+ var _useTurnstileScript = useTurnstileScript(verifyURL),
49991
+ scriptLoaded = _useTurnstileScript.scriptLoaded,
49992
+ scriptError = _useTurnstileScript.scriptError;
49993
+
49994
+ // Clear the error state
49995
+ var clearError = function clearError() {
49996
+ setError(null);
49997
+ };
49998
+
49999
+ // Handle errors based on the retry strategy
50000
+ var handleError = function handleError(errorCode) {
50001
+ if (!errorCode) return;
50002
+ var isFatalError = FATAL_ERROR_CODES.some(function (pattern) {
50003
+ return pattern.test(errorCode);
50004
+ });
50005
+ var errorMessage = getErrorMessage(isFatalError);
50006
+ setError(errorMessage);
50007
+ };
50008
+ var getErrorMessage = function getErrorMessage(isFatalError) {
50009
+ if (isFatalError) {
50010
+ return "Browser or system error. Please refresh the page or try a different browser.";
50011
+ }
50012
+ return "Something went wrong. Please refresh and try again.";
50013
+ };
49960
50014
 
49961
50015
  // Allow the parent component to reset the Turnstile widget
49962
50016
  React.useImperativeHandle(ref, function () {
49963
50017
  return {
49964
50018
  reset: function reset() {
49965
- if (widgetId && window.turnstile) {
49966
- window.turnstile.reset(widgetId);
50019
+ if (widgetIdRef.current && window.turnstile) {
50020
+ window.turnstile.reset(widgetIdRef.current);
50021
+ clearError();
49967
50022
  }
49968
50023
  }
49969
50024
  };
49970
- }, [widgetId]);
50025
+ }, []);
49971
50026
  React.useEffect(function () {
49972
- if (!widgetRef.current || !window.turnstile) return;
49973
- if (!widgetId) {
49974
- var newWidgetId = window.turnstile.render(widgetRef.current, {
50027
+ if (scriptError) {
50028
+ setError("Unable to load security verification. Please refresh the page.");
50029
+ onError === null || onError === void 0 || onError("script_load_failed");
50030
+ return;
50031
+ }
50032
+ if (widgetIdRef.current || !window.turnstile || !scriptLoaded) return;
50033
+ try {
50034
+ widgetIdRef.current = window.turnstile.render(widgetRef.current, {
49975
50035
  sitekey: siteKey,
49976
50036
  size: size,
49977
50037
  retry: retry,
49978
50038
  tabindex: tabindex,
49979
50039
  theme: theme,
49980
50040
  callback: function callback(token) {
49981
- return onSuccess(token);
50041
+ clearError();
50042
+ onSuccess === null || onSuccess === void 0 || onSuccess(token);
49982
50043
  },
49983
- "error-callback": function errorCallback() {
49984
- return onError();
50044
+ "error-callback": function errorCallback(errorCode) {
50045
+ handleError(errorCode);
50046
+ onError === null || onError === void 0 || onError(errorCode);
49985
50047
  },
49986
50048
  "expired-callback": function expiredCallback() {
49987
- return onExpired();
50049
+ clearError();
50050
+ onExpired === null || onExpired === void 0 || onExpired();
49988
50051
  }
49989
50052
  });
49990
- setWidgetId(newWidgetId);
50053
+ } catch (error) {
50054
+ setError("Unable to load security verification. Please refresh the page.");
50055
+ onError === null || onError === void 0 || onError("render_failed");
49991
50056
  }
49992
50057
  return function () {
49993
- if (widgetId && window.turnstile) {
49994
- window.turnstile.remove(widgetId);
49995
- setWidgetId(null);
50058
+ if (widgetIdRef.current && window.turnstile) {
50059
+ window.turnstile.remove(widgetIdRef.current);
50060
+ widgetIdRef.current = null;
50061
+ clearError();
49996
50062
  }
49997
50063
  };
49998
- }, [isTurnstileLoaded, siteKey, widgetId]);
49999
- return /*#__PURE__*/React__default.createElement(TurnstileWidgetContainer, {
50064
+ }, [scriptLoaded, scriptError, siteKey]);
50065
+ return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(TurnstileWidgetContainer, {
50000
50066
  padding: padding,
50001
50067
  justify: justify,
50068
+ align: align,
50002
50069
  extraStyles: extraStyles
50003
50070
  }, /*#__PURE__*/React__default.createElement("div", {
50004
50071
  ref: widgetRef
50005
- }));
50072
+ }), error && /*#__PURE__*/React__default.createElement(Text$1, {
50073
+ color: ERROR_COLOR,
50074
+ variant: "pXS",
50075
+ extraStyles: "\n word-break: break-word;\n text-align: end;\n padding-top: 0.5rem;\n "
50076
+ }, error)));
50006
50077
  });
50007
50078
 
50008
50079
  var pageBackground = "#FBFCFD";