@thecb/components 11.3.3-beta.1 → 11.3.4

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.d.ts CHANGED
@@ -513,32 +513,45 @@ declare function useConditionallyAddValidator(
513
513
  * @param {string} verifyURL - The URL of the Turnstile verification script.
514
514
  */
515
515
  declare const useTurnstileScript = verifyURL => {
516
- const [isLoaded, setIsLoaded] = useState(false);
516
+ const [scriptLoaded, setScriptLoaded] = useState(false);
517
+ const [scriptError, setScriptError] = useState(false);
518
+
519
+ const handleScriptError = () => {
520
+ setScriptError(true);
521
+ setScriptLoaded(false);
522
+ };
517
523
 
518
524
  useEffect(() => {
519
525
  if (typeof window === "undefined") {
520
- setIsLoaded(false);
526
+ setScriptLoaded(false);
521
527
  return;
522
528
  }
523
529
  if (window.turnstile && window.turnstile.render) {
524
- setIsLoaded(true);
530
+ setScriptLoaded(true);
525
531
  return;
526
532
  }
527
533
 
528
534
  const script = document.createElement("script");
529
535
  script.src = `${verifyURL}?render=explicit`;
530
536
  script.onload = () => {
531
- setIsLoaded(true);
537
+ setScriptLoaded(true);
538
+ };
539
+ script.onerror = () => {
540
+ handleScriptError();
541
+ };
542
+ script.onabort = () => {
543
+ handleScriptError();
532
544
  };
533
545
  script.defer = true;
534
546
  document.getElementsByTagName("head")[0].appendChild(script);
535
547
 
536
548
  return () => {
537
- setIsLoaded(false);
549
+ setScriptLoaded(false);
550
+ setScriptError(false);
538
551
  };
539
552
  }, [verifyURL]);
540
553
 
541
- return isLoaded;
554
+ return { scriptLoaded, scriptError };
542
555
  };
543
556
 
544
557
 
@@ -674,7 +687,7 @@ interface FormInputProps {
674
687
  showErrors?: boolean;
675
688
  type?: string;
676
689
  formatter?: string | null;
677
- decorator?: boolean;
690
+ decorator?: string;
678
691
  themeValues?: object;
679
692
  background?: string;
680
693
  customHeight?: string;
package/dist/index.esm.js CHANGED
@@ -24336,29 +24336,47 @@ function useConditionallyAddValidator(condition, validatorFn, addValidator, remo
24336
24336
  var useTurnstileScript = function useTurnstileScript(verifyURL) {
24337
24337
  var _useState = useState(false),
24338
24338
  _useState2 = _slicedToArray(_useState, 2),
24339
- isLoaded = _useState2[0],
24340
- setIsLoaded = _useState2[1];
24339
+ scriptLoaded = _useState2[0],
24340
+ setScriptLoaded = _useState2[1];
24341
+ var _useState3 = useState(false),
24342
+ _useState4 = _slicedToArray(_useState3, 2),
24343
+ scriptError = _useState4[0],
24344
+ setScriptError = _useState4[1];
24345
+ var handleScriptError = function handleScriptError() {
24346
+ setScriptError(true);
24347
+ setScriptLoaded(false);
24348
+ };
24341
24349
  useEffect$1(function () {
24342
24350
  if (typeof window === "undefined") {
24343
- setIsLoaded(false);
24351
+ setScriptLoaded(false);
24344
24352
  return;
24345
24353
  }
24346
24354
  if (window.turnstile && window.turnstile.render) {
24347
- setIsLoaded(true);
24355
+ setScriptLoaded(true);
24348
24356
  return;
24349
24357
  }
24350
24358
  var script = document.createElement("script");
24351
24359
  script.src = "".concat(verifyURL, "?render=explicit");
24352
24360
  script.onload = function () {
24353
- setIsLoaded(true);
24361
+ setScriptLoaded(true);
24362
+ };
24363
+ script.onerror = function () {
24364
+ handleScriptError();
24365
+ };
24366
+ script.onabort = function () {
24367
+ handleScriptError();
24354
24368
  };
24355
24369
  script.defer = true;
24356
24370
  document.getElementsByTagName("head")[0].appendChild(script);
24357
24371
  return function () {
24358
- setIsLoaded(false);
24372
+ setScriptLoaded(false);
24373
+ setScriptError(false);
24359
24374
  };
24360
24375
  }, [verifyURL]);
24361
- return isLoaded;
24376
+ return {
24377
+ scriptLoaded: scriptLoaded,
24378
+ scriptError: scriptError
24379
+ };
24362
24380
  };
24363
24381
 
24364
24382
 
@@ -49912,89 +49930,142 @@ var HeroImage$1 = withWindowSize(themeComponent(HeroImage, "HeroImage", fallback
49912
49930
  var TurnstileWidgetContainer = styled(Box).withConfig({
49913
49931
  displayName: "TurnstileWidget__TurnstileWidgetContainer",
49914
49932
  componentId: "sc-btaugr-0"
49915
- })(["display:flex;padding:", ";justify-content:", ";width:100%;"], function (_ref) {
49933
+ })(["display:flex;flex-direction:column;padding:", ";justify-content:", ";align-items:", ";width:100%;"], function (_ref) {
49916
49934
  var padding = _ref.padding;
49917
49935
  return padding;
49918
49936
  }, function (_ref2) {
49919
49937
  var justify = _ref2.justify;
49920
49938
  return justify;
49939
+ }, function (_ref3) {
49940
+ var align = _ref3.align;
49941
+ return align;
49921
49942
  });
49922
- var TurnstileWidget = /*#__PURE__*/forwardRef(function (_ref3, ref) {
49923
- var verifyURL = _ref3.verifyURL,
49924
- siteKey = _ref3.siteKey,
49925
- _ref3$onSuccess = _ref3.onSuccess,
49926
- onSuccess = _ref3$onSuccess === void 0 ? noop$1 : _ref3$onSuccess,
49927
- _ref3$onError = _ref3.onError,
49928
- onError = _ref3$onError === void 0 ? noop$1 : _ref3$onError,
49929
- _ref3$onExpired = _ref3.onExpired,
49930
- onExpired = _ref3$onExpired === void 0 ? noop$1 : _ref3$onExpired,
49931
- _ref3$padding = _ref3.padding,
49932
- padding = _ref3$padding === void 0 ? "1rem" : _ref3$padding,
49933
- _ref3$justify = _ref3.justify,
49934
- justify = _ref3$justify === void 0 ? "flex-end" : _ref3$justify,
49935
- _ref3$size = _ref3.size,
49936
- size = _ref3$size === void 0 ? "normal" : _ref3$size,
49937
- _ref3$tabindex = _ref3.tabindex,
49938
- tabindex = _ref3$tabindex === void 0 ? 0 : _ref3$tabindex,
49939
- _ref3$retry = _ref3.retry,
49940
- retry = _ref3$retry === void 0 ? "auto" : _ref3$retry,
49941
- _ref3$theme = _ref3.theme,
49942
- theme = _ref3$theme === void 0 ? "auto" : _ref3$theme,
49943
- _ref3$extraStyles = _ref3.extraStyles,
49944
- extraStyles = _ref3$extraStyles === void 0 ? "" : _ref3$extraStyles;
49943
+ var FATAL_ERROR_CODES = [
49944
+ // Configuration errors
49945
+ /^100/, /^105/, /^110100$/, /^110110$/, /^110200$/, /^110420$/, /^110430$/, /^400020$/, /^400030$/, /^400040$/,
49946
+ // Browser/environment errors
49947
+ /^110500$/, /^110510$/, /^200010$/, /^200100$/,
49948
+ // Internal errors
49949
+ /^120/];
49950
+ var TurnstileWidget = /*#__PURE__*/forwardRef(function (_ref4, ref) {
49951
+ var verifyURL = _ref4.verifyURL,
49952
+ siteKey = _ref4.siteKey,
49953
+ _ref4$onSuccess = _ref4.onSuccess,
49954
+ onSuccess = _ref4$onSuccess === void 0 ? noop$1 : _ref4$onSuccess,
49955
+ _ref4$onError = _ref4.onError,
49956
+ onError = _ref4$onError === void 0 ? noop$1 : _ref4$onError,
49957
+ _ref4$onExpired = _ref4.onExpired,
49958
+ onExpired = _ref4$onExpired === void 0 ? noop$1 : _ref4$onExpired,
49959
+ _ref4$padding = _ref4.padding,
49960
+ padding = _ref4$padding === void 0 ? "1rem" : _ref4$padding,
49961
+ _ref4$justify = _ref4.justify,
49962
+ justify = _ref4$justify === void 0 ? "flex-end" : _ref4$justify,
49963
+ _ref4$align = _ref4.align,
49964
+ align = _ref4$align === void 0 ? "flex-end" : _ref4$align,
49965
+ _ref4$size = _ref4.size,
49966
+ size = _ref4$size === void 0 ? "normal" : _ref4$size,
49967
+ _ref4$tabindex = _ref4.tabindex,
49968
+ tabindex = _ref4$tabindex === void 0 ? 0 : _ref4$tabindex,
49969
+ _ref4$retry = _ref4.retry,
49970
+ retry = _ref4$retry === void 0 ? "never" : _ref4$retry,
49971
+ _ref4$theme = _ref4.theme,
49972
+ theme = _ref4$theme === void 0 ? "light" : _ref4$theme,
49973
+ _ref4$extraStyles = _ref4.extraStyles,
49974
+ extraStyles = _ref4$extraStyles === void 0 ? "" : _ref4$extraStyles;
49945
49975
  if (!verifyURL || !siteKey) return null;
49946
49976
  var widgetRef = useRef(null);
49977
+ var widgetIdRef = useRef(null);
49947
49978
  var _useState = useState(null),
49948
49979
  _useState2 = _slicedToArray(_useState, 2),
49949
- widgetId = _useState2[0],
49950
- setWidgetId = _useState2[1];
49951
- var isTurnstileLoaded = useTurnstileScript(verifyURL);
49980
+ error = _useState2[0],
49981
+ setError = _useState2[1];
49982
+ var _useTurnstileScript = useTurnstileScript(verifyURL),
49983
+ scriptLoaded = _useTurnstileScript.scriptLoaded,
49984
+ scriptError = _useTurnstileScript.scriptError;
49985
+
49986
+ // Clear the error state
49987
+ var clearError = function clearError() {
49988
+ setError(null);
49989
+ };
49990
+
49991
+ // Handle errors based on the retry strategy
49992
+ var handleError = function handleError(errorCode) {
49993
+ if (!errorCode) return;
49994
+ var isFatalError = FATAL_ERROR_CODES.some(function (pattern) {
49995
+ return pattern.test(errorCode);
49996
+ });
49997
+ var errorMessage = getErrorMessage(isFatalError);
49998
+ setError(errorMessage);
49999
+ };
50000
+ var getErrorMessage = function getErrorMessage(isFatalError) {
50001
+ if (isFatalError) {
50002
+ return "Browser or system error. Please refresh the page or try a different browser.";
50003
+ }
50004
+ return "Something went wrong. Please refresh and try again.";
50005
+ };
49952
50006
 
49953
50007
  // Allow the parent component to reset the Turnstile widget
49954
50008
  useImperativeHandle(ref, function () {
49955
50009
  return {
49956
50010
  reset: function reset() {
49957
- if (widgetId && window.turnstile) {
49958
- window.turnstile.reset(widgetId);
50011
+ if (widgetIdRef.current && window.turnstile) {
50012
+ window.turnstile.reset(widgetIdRef.current);
50013
+ clearError();
49959
50014
  }
49960
50015
  }
49961
50016
  };
49962
- }, [widgetId]);
50017
+ }, []);
49963
50018
  useEffect$1(function () {
49964
- if (!widgetRef.current || !window.turnstile) return;
49965
- if (!widgetId) {
49966
- var newWidgetId = window.turnstile.render(widgetRef.current, {
50019
+ if (scriptError) {
50020
+ setError("Unable to load security verification. Please refresh the page.");
50021
+ onError === null || onError === void 0 || onError("script_load_failed");
50022
+ return;
50023
+ }
50024
+ if (widgetIdRef.current || !window.turnstile || !scriptLoaded) return;
50025
+ try {
50026
+ widgetIdRef.current = window.turnstile.render(widgetRef.current, {
49967
50027
  sitekey: siteKey,
49968
50028
  size: size,
49969
50029
  retry: retry,
49970
50030
  tabindex: tabindex,
49971
50031
  theme: theme,
49972
50032
  callback: function callback(token) {
49973
- return onSuccess(token);
50033
+ clearError();
50034
+ onSuccess === null || onSuccess === void 0 || onSuccess(token);
49974
50035
  },
49975
- "error-callback": function errorCallback() {
49976
- return onError();
50036
+ "error-callback": function errorCallback(errorCode) {
50037
+ handleError(errorCode);
50038
+ onError === null || onError === void 0 || onError(errorCode);
49977
50039
  },
49978
50040
  "expired-callback": function expiredCallback() {
49979
- return onExpired();
50041
+ clearError();
50042
+ onExpired === null || onExpired === void 0 || onExpired();
49980
50043
  }
49981
50044
  });
49982
- setWidgetId(newWidgetId);
50045
+ } catch (error) {
50046
+ setError("Unable to load security verification. Please refresh the page.");
50047
+ onError === null || onError === void 0 || onError("render_failed");
49983
50048
  }
49984
50049
  return function () {
49985
- if (widgetId && window.turnstile) {
49986
- window.turnstile.remove(widgetId);
49987
- setWidgetId(null);
50050
+ if (widgetIdRef.current && window.turnstile) {
50051
+ window.turnstile.remove(widgetIdRef.current);
50052
+ widgetIdRef.current = null;
50053
+ clearError();
49988
50054
  }
49989
50055
  };
49990
- }, [isTurnstileLoaded, siteKey, widgetId]);
49991
- return /*#__PURE__*/React__default.createElement(TurnstileWidgetContainer, {
50056
+ }, [scriptLoaded, scriptError, siteKey]);
50057
+ return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(TurnstileWidgetContainer, {
49992
50058
  padding: padding,
49993
50059
  justify: justify,
50060
+ align: align,
49994
50061
  extraStyles: extraStyles
49995
50062
  }, /*#__PURE__*/React__default.createElement("div", {
49996
50063
  ref: widgetRef
49997
- }));
50064
+ }), error && /*#__PURE__*/React__default.createElement(Text$1, {
50065
+ color: ERROR_COLOR,
50066
+ variant: "pXS",
50067
+ extraStyles: "\n word-break: break-word;\n text-align: end;\n padding-top: 0.5rem;\n "
50068
+ }, error)));
49998
50069
  });
49999
50070
 
50000
50071
  var pageBackground = "#FBFCFD";