@thecb/components 11.3.1 → 11.3.2-beta.1

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