@thecb/components 11.3.1 → 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 +139 -62
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +15 -6
- package/dist/index.esm.js +139 -62
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/molecules/turnstile-widget/TurnstileWidget.js +137 -33
- package/src/hooks/use-turnstile-script/index.js +15 -6
- package/src/.DS_Store +0 -0
- package/src/components/.DS_Store +0 -0
- package/src/components/atoms/.DS_Store +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -513,32 +513,41 @@ 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 [
|
|
516
|
+
const [scriptLoaded, setScriptLoaded] = useState(false);
|
|
517
|
+
const [scriptError, setScriptError] = useState(null);
|
|
517
518
|
|
|
518
519
|
useEffect(() => {
|
|
519
520
|
if (typeof window === "undefined") {
|
|
520
|
-
|
|
521
|
+
setScriptLoaded(false);
|
|
521
522
|
return;
|
|
522
523
|
}
|
|
523
524
|
if (window.turnstile && window.turnstile.render) {
|
|
524
|
-
|
|
525
|
+
setScriptLoaded(true);
|
|
525
526
|
return;
|
|
526
527
|
}
|
|
527
528
|
|
|
528
529
|
const script = document.createElement("script");
|
|
529
530
|
script.src = `${verifyURL}?render=explicit`;
|
|
530
531
|
script.onload = () => {
|
|
531
|
-
|
|
532
|
+
setScriptLoaded(true);
|
|
533
|
+
};
|
|
534
|
+
script.onerror = () => {
|
|
535
|
+
setScriptError(true);
|
|
536
|
+
setScriptLoaded(false);
|
|
537
|
+
};
|
|
538
|
+
script.onabort = () => {
|
|
539
|
+
setScriptError(true);
|
|
540
|
+
setScriptLoaded(false);
|
|
532
541
|
};
|
|
533
542
|
script.defer = true;
|
|
534
543
|
document.getElementsByTagName("head")[0].appendChild(script);
|
|
535
544
|
|
|
536
545
|
return () => {
|
|
537
|
-
|
|
546
|
+
setScriptLoaded(false);
|
|
538
547
|
};
|
|
539
548
|
}, [verifyURL]);
|
|
540
549
|
|
|
541
|
-
return
|
|
550
|
+
return { scriptLoaded, scriptError };
|
|
542
551
|
};
|
|
543
552
|
|
|
544
553
|
|
package/dist/index.esm.js
CHANGED
|
@@ -24404,29 +24404,44 @@ function useConditionallyAddValidator(condition, validatorFn, addValidator, remo
|
|
|
24404
24404
|
var useTurnstileScript = function useTurnstileScript(verifyURL) {
|
|
24405
24405
|
var _useState = useState(false),
|
|
24406
24406
|
_useState2 = _slicedToArray(_useState, 2),
|
|
24407
|
-
|
|
24408
|
-
|
|
24407
|
+
scriptLoaded = _useState2[0],
|
|
24408
|
+
setScriptLoaded = _useState2[1];
|
|
24409
|
+
var _useState3 = useState(null),
|
|
24410
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
24411
|
+
scriptError = _useState4[0],
|
|
24412
|
+
setScriptError = _useState4[1];
|
|
24409
24413
|
useEffect$1(function () {
|
|
24410
24414
|
if (typeof window === "undefined") {
|
|
24411
|
-
|
|
24415
|
+
setScriptLoaded(false);
|
|
24412
24416
|
return;
|
|
24413
24417
|
}
|
|
24414
24418
|
if (window.turnstile && window.turnstile.render) {
|
|
24415
|
-
|
|
24419
|
+
setScriptLoaded(true);
|
|
24416
24420
|
return;
|
|
24417
24421
|
}
|
|
24418
24422
|
var script = document.createElement("script");
|
|
24419
24423
|
script.src = "".concat(verifyURL, "?render=explicit");
|
|
24420
24424
|
script.onload = function () {
|
|
24421
|
-
|
|
24425
|
+
setScriptLoaded(true);
|
|
24426
|
+
};
|
|
24427
|
+
script.onerror = function () {
|
|
24428
|
+
setScriptError(true);
|
|
24429
|
+
setScriptLoaded(false);
|
|
24430
|
+
};
|
|
24431
|
+
script.onabort = function () {
|
|
24432
|
+
setScriptError(true);
|
|
24433
|
+
setScriptLoaded(false);
|
|
24422
24434
|
};
|
|
24423
24435
|
script.defer = true;
|
|
24424
24436
|
document.getElementsByTagName("head")[0].appendChild(script);
|
|
24425
24437
|
return function () {
|
|
24426
|
-
|
|
24438
|
+
setScriptLoaded(false);
|
|
24427
24439
|
};
|
|
24428
24440
|
}, [verifyURL]);
|
|
24429
|
-
return
|
|
24441
|
+
return {
|
|
24442
|
+
scriptLoaded: scriptLoaded,
|
|
24443
|
+
scriptError: scriptError
|
|
24444
|
+
};
|
|
24430
24445
|
};
|
|
24431
24446
|
|
|
24432
24447
|
|
|
@@ -49980,89 +49995,151 @@ var HeroImage$1 = withWindowSize(themeComponent(HeroImage, "HeroImage", fallback
|
|
|
49980
49995
|
var TurnstileWidgetContainer = styled(Box).withConfig({
|
|
49981
49996
|
displayName: "TurnstileWidget__TurnstileWidgetContainer",
|
|
49982
49997
|
componentId: "sc-btaugr-0"
|
|
49983
|
-
})(["display:flex;padding:", ";justify-content:", ";width:100%;"], function (_ref) {
|
|
49998
|
+
})(["display:flex;flex-direction:column;align-items:flex-end;padding:", ";justify-content:", ";align-items:", ";width:100%;"], function (_ref) {
|
|
49984
49999
|
var padding = _ref.padding;
|
|
49985
50000
|
return padding;
|
|
49986
50001
|
}, function (_ref2) {
|
|
49987
50002
|
var justify = _ref2.justify;
|
|
49988
50003
|
return justify;
|
|
50004
|
+
}, function (_ref3) {
|
|
50005
|
+
var justify = _ref3.justify;
|
|
50006
|
+
return justify;
|
|
49989
50007
|
});
|
|
49990
|
-
var
|
|
49991
|
-
|
|
49992
|
-
|
|
49993
|
-
|
|
49994
|
-
|
|
49995
|
-
|
|
49996
|
-
|
|
49997
|
-
|
|
49998
|
-
|
|
49999
|
-
|
|
50000
|
-
|
|
50001
|
-
|
|
50002
|
-
|
|
50003
|
-
|
|
50004
|
-
|
|
50005
|
-
|
|
50006
|
-
|
|
50007
|
-
|
|
50008
|
-
|
|
50009
|
-
|
|
50010
|
-
|
|
50011
|
-
|
|
50012
|
-
|
|
50008
|
+
var FATAL_ERROR_CODES = [
|
|
50009
|
+
// Configuration errors
|
|
50010
|
+
/^100/, /^105/, /^110100$/, /^110110$/, /^110200$/, /^110420$/, /^110430$/, /^400020$/, /^400030$/, /^400040$/,
|
|
50011
|
+
// Browser/environment errors
|
|
50012
|
+
/^110500$/, /^110510$/, /^200010$/, /^200100$/,
|
|
50013
|
+
// Internal errors
|
|
50014
|
+
/^120/];
|
|
50015
|
+
var TurnstileWidget = /*#__PURE__*/forwardRef(function (_ref4, ref) {
|
|
50016
|
+
var verifyURL = _ref4.verifyURL,
|
|
50017
|
+
siteKey = _ref4.siteKey,
|
|
50018
|
+
_ref4$onSuccess = _ref4.onSuccess,
|
|
50019
|
+
onSuccess = _ref4$onSuccess === void 0 ? noop$1 : _ref4$onSuccess,
|
|
50020
|
+
_ref4$onError = _ref4.onError,
|
|
50021
|
+
onError = _ref4$onError === void 0 ? noop$1 : _ref4$onError,
|
|
50022
|
+
_ref4$onExpired = _ref4.onExpired,
|
|
50023
|
+
onExpired = _ref4$onExpired === void 0 ? noop$1 : _ref4$onExpired,
|
|
50024
|
+
_ref4$padding = _ref4.padding,
|
|
50025
|
+
padding = _ref4$padding === void 0 ? "1rem" : _ref4$padding,
|
|
50026
|
+
_ref4$justify = _ref4.justify,
|
|
50027
|
+
justify = _ref4$justify === void 0 ? "flex-end" : _ref4$justify,
|
|
50028
|
+
_ref4$size = _ref4.size,
|
|
50029
|
+
size = _ref4$size === void 0 ? "normal" : _ref4$size,
|
|
50030
|
+
_ref4$tabindex = _ref4.tabindex,
|
|
50031
|
+
tabindex = _ref4$tabindex === void 0 ? 0 : _ref4$tabindex,
|
|
50032
|
+
_ref4$retry = _ref4.retry,
|
|
50033
|
+
retry = _ref4$retry === void 0 ? "never" : _ref4$retry,
|
|
50034
|
+
_ref4$theme = _ref4.theme,
|
|
50035
|
+
theme = _ref4$theme === void 0 ? "light" : _ref4$theme,
|
|
50036
|
+
_ref4$extraStyles = _ref4.extraStyles,
|
|
50037
|
+
extraStyles = _ref4$extraStyles === void 0 ? "" : _ref4$extraStyles,
|
|
50038
|
+
_ref4$maxErrorRetries = _ref4.maxErrorRetries,
|
|
50039
|
+
maxErrorRetries = _ref4$maxErrorRetries === void 0 ? 3 : _ref4$maxErrorRetries;
|
|
50013
50040
|
if (!verifyURL || !siteKey) return null;
|
|
50014
50041
|
var widgetRef = useRef(null);
|
|
50042
|
+
var widgetIdRef = useRef(null);
|
|
50043
|
+
var retryCountRef = useRef(0);
|
|
50015
50044
|
var _useState = useState(null),
|
|
50016
50045
|
_useState2 = _slicedToArray(_useState, 2),
|
|
50017
|
-
|
|
50018
|
-
|
|
50019
|
-
var
|
|
50046
|
+
error = _useState2[0],
|
|
50047
|
+
setError = _useState2[1];
|
|
50048
|
+
var _useTurnstileScript = useTurnstileScript(verifyURL),
|
|
50049
|
+
scriptLoaded = _useTurnstileScript.scriptLoaded,
|
|
50050
|
+
scriptError = _useTurnstileScript.scriptError;
|
|
50051
|
+
|
|
50052
|
+
// Clear the error state and reset retry count
|
|
50053
|
+
var clearError = function clearError() {
|
|
50054
|
+
setError(null);
|
|
50055
|
+
retryCountRef.current = 0;
|
|
50056
|
+
};
|
|
50057
|
+
|
|
50058
|
+
// Handle errors based on the retry strategy
|
|
50059
|
+
var handleError = function handleError(errorCode) {
|
|
50060
|
+
retryCountRef.current += 1;
|
|
50061
|
+
var currentRetryCount = retryCountRef.current;
|
|
50062
|
+
|
|
50063
|
+
// If we haven't exceeded max retries, reset and try again
|
|
50064
|
+
if (currentRetryCount <= maxErrorRetries) {
|
|
50065
|
+
window.turnstile.reset(widgetIdRef.current);
|
|
50066
|
+
setError(null);
|
|
50067
|
+
return;
|
|
50068
|
+
}
|
|
50069
|
+
|
|
50070
|
+
// Max retries exceeded - show appropriate error message
|
|
50071
|
+
if (errorCode) {
|
|
50072
|
+
var errorMessage = getErrorMessage(errorCode);
|
|
50073
|
+
setError(errorMessage);
|
|
50074
|
+
}
|
|
50075
|
+
};
|
|
50076
|
+
var getErrorMessage = function getErrorMessage(errorCode) {
|
|
50077
|
+
var isFatalError = FATAL_ERROR_CODES.some(function (pattern) {
|
|
50078
|
+
return pattern.test(errorCode);
|
|
50079
|
+
});
|
|
50080
|
+
if (isFatalError) {
|
|
50081
|
+
return "Browser or system error. Please refresh the page or update your browser.";
|
|
50082
|
+
}
|
|
50083
|
+
return "Something went wrong. Please refresh and try again.";
|
|
50084
|
+
};
|
|
50020
50085
|
|
|
50021
50086
|
// Allow the parent component to reset the Turnstile widget
|
|
50022
50087
|
useImperativeHandle(ref, function () {
|
|
50023
50088
|
return {
|
|
50024
50089
|
reset: function reset() {
|
|
50025
|
-
if (
|
|
50026
|
-
window.turnstile.reset(
|
|
50090
|
+
if (widgetIdRef.current && window.turnstile) {
|
|
50091
|
+
window.turnstile.reset(widgetIdRef.current);
|
|
50092
|
+
clearError();
|
|
50027
50093
|
}
|
|
50028
50094
|
}
|
|
50029
50095
|
};
|
|
50030
|
-
}, [
|
|
50096
|
+
}, []);
|
|
50031
50097
|
useEffect$1(function () {
|
|
50032
|
-
if (
|
|
50033
|
-
|
|
50034
|
-
|
|
50035
|
-
|
|
50036
|
-
|
|
50037
|
-
|
|
50038
|
-
|
|
50039
|
-
|
|
50040
|
-
|
|
50041
|
-
|
|
50042
|
-
|
|
50043
|
-
|
|
50044
|
-
|
|
50045
|
-
|
|
50046
|
-
"expired-callback": function expiredCallback() {
|
|
50047
|
-
return onExpired();
|
|
50098
|
+
if (widgetIdRef.current || !window.turnstile || !scriptLoaded) return;
|
|
50099
|
+
widgetIdRef.current = window.turnstile.render(widgetRef.current, {
|
|
50100
|
+
sitekey: siteKey,
|
|
50101
|
+
size: size,
|
|
50102
|
+
retry: retry,
|
|
50103
|
+
tabindex: tabindex,
|
|
50104
|
+
theme: theme,
|
|
50105
|
+
callback: function callback(token) {
|
|
50106
|
+
clearError();
|
|
50107
|
+
onSuccess(token);
|
|
50108
|
+
},
|
|
50109
|
+
"error-callback": function errorCallback(errorCode) {
|
|
50110
|
+
if (retry === "never") {
|
|
50111
|
+
handleError(errorCode);
|
|
50048
50112
|
}
|
|
50049
|
-
|
|
50050
|
-
|
|
50051
|
-
|
|
50113
|
+
onError === null || onError === void 0 || onError(errorCode);
|
|
50114
|
+
},
|
|
50115
|
+
"expired-callback": function expiredCallback() {
|
|
50116
|
+
clearError();
|
|
50117
|
+
onExpired === null || onExpired === void 0 || onExpired();
|
|
50118
|
+
}
|
|
50119
|
+
});
|
|
50052
50120
|
return function () {
|
|
50053
|
-
if (
|
|
50054
|
-
window.turnstile.remove(
|
|
50055
|
-
|
|
50121
|
+
if (widgetIdRef.current && window.turnstile) {
|
|
50122
|
+
window.turnstile.remove(widgetIdRef.current);
|
|
50123
|
+
widgetIdRef.current = null;
|
|
50124
|
+
clearError();
|
|
50056
50125
|
}
|
|
50057
50126
|
};
|
|
50058
|
-
}, [
|
|
50059
|
-
return /*#__PURE__*/React__default.createElement(TurnstileWidgetContainer, {
|
|
50127
|
+
}, [scriptLoaded, siteKey]);
|
|
50128
|
+
return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(TurnstileWidgetContainer, {
|
|
50060
50129
|
padding: padding,
|
|
50061
50130
|
justify: justify,
|
|
50062
50131
|
extraStyles: extraStyles
|
|
50063
50132
|
}, /*#__PURE__*/React__default.createElement("div", {
|
|
50064
50133
|
ref: widgetRef
|
|
50065
|
-
})
|
|
50134
|
+
}), error && /*#__PURE__*/React__default.createElement(Text$1, {
|
|
50135
|
+
color: ERROR_COLOR,
|
|
50136
|
+
variant: "pXS",
|
|
50137
|
+
extraStyles: "\n word-break: break-word;\n text-align: end;\n "
|
|
50138
|
+
}, error), scriptError && /*#__PURE__*/React__default.createElement(Text$1, {
|
|
50139
|
+
color: ERROR_COLOR,
|
|
50140
|
+
variant: "pXS",
|
|
50141
|
+
extraStyles: "\n word-break: break-word;\n text-align: end;\n "
|
|
50142
|
+
}, "Unable to load security verification. Please refresh the page.")));
|
|
50066
50143
|
});
|
|
50067
50144
|
|
|
50068
50145
|
var pageBackground = "#FBFCFD";
|