@thecb/components 11.3.1-beta.0 → 11.3.2-beta.0

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
@@ -24412,29 +24412,44 @@ function useConditionallyAddValidator(condition, validatorFn, addValidator, remo
24412
24412
  var useTurnstileScript = function useTurnstileScript(verifyURL) {
24413
24413
  var _useState = React.useState(false),
24414
24414
  _useState2 = _slicedToArray(_useState, 2),
24415
- isLoaded = _useState2[0],
24416
- setIsLoaded = _useState2[1];
24415
+ scriptLoaded = _useState2[0],
24416
+ setScriptLoaded = _useState2[1];
24417
+ var _useState3 = React.useState(null),
24418
+ _useState4 = _slicedToArray(_useState3, 2),
24419
+ scriptError = _useState4[0],
24420
+ setScriptError = _useState4[1];
24417
24421
  React.useEffect(function () {
24418
24422
  if (typeof window === "undefined") {
24419
- setIsLoaded(false);
24423
+ setScriptLoaded(false);
24420
24424
  return;
24421
24425
  }
24422
24426
  if (window.turnstile && window.turnstile.render) {
24423
- setIsLoaded(true);
24427
+ setScriptLoaded(true);
24424
24428
  return;
24425
24429
  }
24426
24430
  var script = document.createElement("script");
24427
24431
  script.src = "".concat(verifyURL, "?render=explicit");
24428
24432
  script.onload = function () {
24429
- setIsLoaded(true);
24433
+ setScriptLoaded(true);
24434
+ };
24435
+ script.onerror = function () {
24436
+ setScriptError(true);
24437
+ setScriptLoaded(false);
24438
+ };
24439
+ script.onabort = function () {
24440
+ setScriptError(true);
24441
+ setScriptLoaded(false);
24430
24442
  };
24431
24443
  script.defer = true;
24432
24444
  document.getElementsByTagName("head")[0].appendChild(script);
24433
24445
  return function () {
24434
- setIsLoaded(false);
24446
+ setScriptLoaded(false);
24435
24447
  };
24436
24448
  }, [verifyURL]);
24437
- return isLoaded;
24449
+ return {
24450
+ scriptLoaded: scriptLoaded,
24451
+ scriptError: scriptError
24452
+ };
24438
24453
  };
24439
24454
 
24440
24455
 
@@ -49988,89 +50003,151 @@ var HeroImage$1 = withWindowSize(themeComponent(HeroImage, "HeroImage", fallback
49988
50003
  var TurnstileWidgetContainer = styled__default(Box).withConfig({
49989
50004
  displayName: "TurnstileWidget__TurnstileWidgetContainer",
49990
50005
  componentId: "sc-btaugr-0"
49991
- })(["display:flex;padding:", ";justify-content:", ";width:100%;"], function (_ref) {
50006
+ })(["display:flex;flex-direction:column;align-items:flex-end;padding:", ";justify-content:", ";align-items:", ";width:100%;"], function (_ref) {
49992
50007
  var padding = _ref.padding;
49993
50008
  return padding;
49994
50009
  }, function (_ref2) {
49995
50010
  var justify = _ref2.justify;
49996
50011
  return justify;
50012
+ }, function (_ref3) {
50013
+ var justify = _ref3.justify;
50014
+ return justify;
49997
50015
  });
49998
- var TurnstileWidget = /*#__PURE__*/React.forwardRef(function (_ref3, ref) {
49999
- var verifyURL = _ref3.verifyURL,
50000
- siteKey = _ref3.siteKey,
50001
- _ref3$onSuccess = _ref3.onSuccess,
50002
- onSuccess = _ref3$onSuccess === void 0 ? noop$1 : _ref3$onSuccess,
50003
- _ref3$onError = _ref3.onError,
50004
- onError = _ref3$onError === void 0 ? noop$1 : _ref3$onError,
50005
- _ref3$onExpired = _ref3.onExpired,
50006
- onExpired = _ref3$onExpired === void 0 ? noop$1 : _ref3$onExpired,
50007
- _ref3$padding = _ref3.padding,
50008
- padding = _ref3$padding === void 0 ? "1rem" : _ref3$padding,
50009
- _ref3$justify = _ref3.justify,
50010
- justify = _ref3$justify === void 0 ? "flex-end" : _ref3$justify,
50011
- _ref3$size = _ref3.size,
50012
- size = _ref3$size === void 0 ? "normal" : _ref3$size,
50013
- _ref3$tabindex = _ref3.tabindex,
50014
- tabindex = _ref3$tabindex === void 0 ? 0 : _ref3$tabindex,
50015
- _ref3$retry = _ref3.retry,
50016
- retry = _ref3$retry === void 0 ? "auto" : _ref3$retry,
50017
- _ref3$theme = _ref3.theme,
50018
- theme = _ref3$theme === void 0 ? "auto" : _ref3$theme,
50019
- _ref3$extraStyles = _ref3.extraStyles,
50020
- extraStyles = _ref3$extraStyles === void 0 ? "" : _ref3$extraStyles;
50016
+ var FATAL_ERROR_CODES = [
50017
+ // Configuration errors
50018
+ /^100/, /^105/, /^110100$/, /^110110$/, /^110200$/, /^110420$/, /^110430$/, /^400020$/, /^400030$/, /^400040$/,
50019
+ // Browser/environment errors
50020
+ /^110500$/, /^110510$/, /^200010$/, /^200100$/,
50021
+ // Internal errors
50022
+ /^120/];
50023
+ var TurnstileWidget = /*#__PURE__*/React.forwardRef(function (_ref4, ref) {
50024
+ var verifyURL = _ref4.verifyURL,
50025
+ siteKey = _ref4.siteKey,
50026
+ _ref4$onSuccess = _ref4.onSuccess,
50027
+ onSuccess = _ref4$onSuccess === void 0 ? noop$1 : _ref4$onSuccess,
50028
+ _ref4$onError = _ref4.onError,
50029
+ onError = _ref4$onError === void 0 ? noop$1 : _ref4$onError,
50030
+ _ref4$onExpired = _ref4.onExpired,
50031
+ onExpired = _ref4$onExpired === void 0 ? noop$1 : _ref4$onExpired,
50032
+ _ref4$padding = _ref4.padding,
50033
+ padding = _ref4$padding === void 0 ? "1rem" : _ref4$padding,
50034
+ _ref4$justify = _ref4.justify,
50035
+ justify = _ref4$justify === void 0 ? "flex-end" : _ref4$justify,
50036
+ _ref4$size = _ref4.size,
50037
+ size = _ref4$size === void 0 ? "normal" : _ref4$size,
50038
+ _ref4$tabindex = _ref4.tabindex,
50039
+ tabindex = _ref4$tabindex === void 0 ? 0 : _ref4$tabindex,
50040
+ _ref4$retry = _ref4.retry,
50041
+ retry = _ref4$retry === void 0 ? "never" : _ref4$retry,
50042
+ _ref4$theme = _ref4.theme,
50043
+ theme = _ref4$theme === void 0 ? "light" : _ref4$theme,
50044
+ _ref4$extraStyles = _ref4.extraStyles,
50045
+ extraStyles = _ref4$extraStyles === void 0 ? "" : _ref4$extraStyles,
50046
+ _ref4$maxErrorRetries = _ref4.maxErrorRetries,
50047
+ maxErrorRetries = _ref4$maxErrorRetries === void 0 ? 3 : _ref4$maxErrorRetries;
50021
50048
  if (!verifyURL || !siteKey) return null;
50022
50049
  var widgetRef = React.useRef(null);
50050
+ var widgetIdRef = React.useRef(null);
50051
+ var retryCountRef = React.useRef(0);
50023
50052
  var _useState = React.useState(null),
50024
50053
  _useState2 = _slicedToArray(_useState, 2),
50025
- widgetId = _useState2[0],
50026
- setWidgetId = _useState2[1];
50027
- var isTurnstileLoaded = useTurnstileScript(verifyURL);
50054
+ error = _useState2[0],
50055
+ setError = _useState2[1];
50056
+ var _useTurnstileScript = useTurnstileScript(verifyURL),
50057
+ scriptLoaded = _useTurnstileScript.scriptLoaded,
50058
+ scriptError = _useTurnstileScript.scriptError;
50059
+
50060
+ // Clear the error state and reset retry count
50061
+ var clearError = function clearError() {
50062
+ setError(null);
50063
+ retryCountRef.current = 0;
50064
+ };
50065
+
50066
+ // Handle errors based on the retry strategy
50067
+ var handleError = function handleError(errorCode) {
50068
+ retryCountRef.current += 1;
50069
+ var currentRetryCount = retryCountRef.current;
50070
+
50071
+ // If we haven't exceeded max retries, reset and try again
50072
+ if (currentRetryCount <= maxErrorRetries) {
50073
+ window.turnstile.reset(widgetIdRef.current);
50074
+ setError(null);
50075
+ return;
50076
+ }
50077
+
50078
+ // Max retries exceeded - show appropriate error message
50079
+ if (errorCode) {
50080
+ var errorMessage = getErrorMessage(errorCode);
50081
+ setError(errorMessage);
50082
+ }
50083
+ };
50084
+ var getErrorMessage = function getErrorMessage(errorCode) {
50085
+ var isFatalError = FATAL_ERROR_CODES.some(function (pattern) {
50086
+ return pattern.test(errorCode);
50087
+ });
50088
+ if (isFatalError) {
50089
+ return "Browser or system error. Please refresh the page or update your browser.";
50090
+ }
50091
+ return "Something went wrong. Please refresh and try again.";
50092
+ };
50028
50093
 
50029
50094
  // Allow the parent component to reset the Turnstile widget
50030
50095
  React.useImperativeHandle(ref, function () {
50031
50096
  return {
50032
50097
  reset: function reset() {
50033
- if (widgetId && window.turnstile) {
50034
- window.turnstile.reset(widgetId);
50098
+ if (widgetIdRef.current && window.turnstile) {
50099
+ window.turnstile.reset(widgetIdRef.current);
50100
+ clearError();
50035
50101
  }
50036
50102
  }
50037
50103
  };
50038
- }, [widgetId]);
50104
+ }, []);
50039
50105
  React.useEffect(function () {
50040
- if (!widgetRef.current || !window.turnstile) return;
50041
- if (!widgetId) {
50042
- var newWidgetId = window.turnstile.render(widgetRef.current, {
50043
- sitekey: siteKey,
50044
- size: size,
50045
- retry: retry,
50046
- tabindex: tabindex,
50047
- theme: theme,
50048
- callback: function callback(token) {
50049
- return onSuccess(token);
50050
- },
50051
- "error-callback": function errorCallback() {
50052
- return onError();
50053
- },
50054
- "expired-callback": function expiredCallback() {
50055
- return onExpired();
50106
+ if (widgetIdRef.current || !window.turnstile || !scriptLoaded) return;
50107
+ widgetIdRef.current = window.turnstile.render(widgetRef.current, {
50108
+ sitekey: siteKey,
50109
+ size: size,
50110
+ retry: retry,
50111
+ tabindex: tabindex,
50112
+ theme: theme,
50113
+ callback: function callback(token) {
50114
+ clearError();
50115
+ onSuccess(token);
50116
+ },
50117
+ "error-callback": function errorCallback(errorCode) {
50118
+ if (retry === "never") {
50119
+ handleError(errorCode);
50056
50120
  }
50057
- });
50058
- setWidgetId(newWidgetId);
50059
- }
50121
+ onError === null || onError === void 0 || onError(errorCode);
50122
+ },
50123
+ "expired-callback": function expiredCallback() {
50124
+ clearError();
50125
+ onExpired === null || onExpired === void 0 || onExpired();
50126
+ }
50127
+ });
50060
50128
  return function () {
50061
- if (widgetId && window.turnstile) {
50062
- window.turnstile.remove(widgetId);
50063
- setWidgetId(null);
50129
+ if (widgetIdRef.current && window.turnstile) {
50130
+ window.turnstile.remove(widgetIdRef.current);
50131
+ widgetIdRef.current = null;
50132
+ clearError();
50064
50133
  }
50065
50134
  };
50066
- }, [isTurnstileLoaded, siteKey, widgetId]);
50067
- return /*#__PURE__*/React__default.createElement(TurnstileWidgetContainer, {
50135
+ }, [scriptLoaded, siteKey]);
50136
+ return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(TurnstileWidgetContainer, {
50068
50137
  padding: padding,
50069
50138
  justify: justify,
50070
50139
  extraStyles: extraStyles
50071
50140
  }, /*#__PURE__*/React__default.createElement("div", {
50072
50141
  ref: widgetRef
50073
- }));
50142
+ }), error && /*#__PURE__*/React__default.createElement(Text$1, {
50143
+ color: ERROR_COLOR,
50144
+ variant: "pXS",
50145
+ extraStyles: "\n word-break: break-word;\n text-align: end;\n "
50146
+ }, error), scriptError && /*#__PURE__*/React__default.createElement(Text$1, {
50147
+ color: ERROR_COLOR,
50148
+ variant: "pXS",
50149
+ extraStyles: "\n word-break: break-word;\n text-align: end;\n "
50150
+ }, "Unable to load security verification. Please refresh the page.")));
50074
50151
  });
50075
50152
 
50076
50153
  var pageBackground = "#FBFCFD";