@hcaptcha/react-hcaptcha
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -67,3 +67,4 @@ "use strict"; | ||
_this.resetCaptcha = _this.resetCaptcha.bind((0, _assertThisInitialized2["default"])(_this)); | ||
_this.removeCaptcha = _this.removeCaptcha.bind((0, _assertThisInitialized2["default"])(_this)); // Event Handlers | ||
_this.removeCaptcha = _this.removeCaptcha.bind((0, _assertThisInitialized2["default"])(_this)); | ||
_this.isReady = _this.isReady.bind((0, _assertThisInitialized2["default"])(_this)); // Event Handlers | ||
@@ -74,2 +75,5 @@ _this.handleOnLoad = _this.handleOnLoad.bind((0, _assertThisInitialized2["default"])(_this)); | ||
_this.handleError = _this.handleError.bind((0, _assertThisInitialized2["default"])(_this)); | ||
_this.handleOpen = _this.handleOpen.bind((0, _assertThisInitialized2["default"])(_this)); | ||
_this.handleClose = _this.handleClose.bind((0, _assertThisInitialized2["default"])(_this)); | ||
_this.handleChallengeExpired = _this.handleChallengeExpired.bind((0, _assertThisInitialized2["default"])(_this)); | ||
var isApiReady = typeof hcaptcha !== 'undefined'; | ||
@@ -130,8 +134,9 @@ _this.ref = React.createRef(); | ||
value: function componentWillUnmount() { | ||
var _this$state = this.state, | ||
isApiReady = _this$state.isApiReady, | ||
isRemoved = _this$state.isRemoved, | ||
captchaId = _this$state.captchaId; | ||
if (!isApiReady || isRemoved) return; // Reset any stored variables / timers when unmounting | ||
var captchaId = this.state.captchaId; | ||
if (!this.isReady()) { | ||
return; | ||
} // Reset any stored variables / timers when unmounting | ||
hcaptcha.reset(captchaId); | ||
@@ -174,3 +179,6 @@ hcaptcha.remove(captchaId); | ||
var renderParams = Object.assign({ | ||
"open-callback": this.handleOpen, | ||
"close-callback": this.handleClose, | ||
"error-callback": this.handleError, | ||
"chalexpired-callback": this.handleChallengeExpired, | ||
"expired-callback": this.handleExpire, | ||
@@ -194,8 +202,9 @@ "callback": this.handleSubmit | ||
value: function resetCaptcha() { | ||
var _this$state2 = this.state, | ||
isApiReady = _this$state2.isApiReady, | ||
isRemoved = _this$state2.isRemoved, | ||
captchaId = _this$state2.captchaId; | ||
if (!isApiReady || isRemoved) return; // Reset captcha state, removes stored token and unticks checkbox | ||
var captchaId = this.state.captchaId; | ||
if (!this.isReady()) { | ||
return; | ||
} // Reset captcha state, removes stored token and unticks checkbox | ||
hcaptcha.reset(captchaId); | ||
@@ -206,7 +215,8 @@ } | ||
value: function removeCaptcha(callback) { | ||
var _this$state3 = this.state, | ||
isApiReady = _this$state3.isApiReady, | ||
isRemoved = _this$state3.isRemoved, | ||
captchaId = _this$state3.captchaId; | ||
if (!isApiReady || isRemoved) return; | ||
var captchaId = this.state.captchaId; | ||
if (!this.isReady()) { | ||
return; | ||
} | ||
this.setState({ | ||
@@ -239,5 +249,5 @@ isRemoved: true | ||
var onVerify = this.props.onVerify; | ||
var _this$state4 = this.state, | ||
isRemoved = _this$state4.isRemoved, | ||
captchaId = _this$state4.captchaId; | ||
var _this$state = this.state, | ||
isRemoved = _this$state.isRemoved, | ||
captchaId = _this$state.captchaId; | ||
if (typeof hcaptcha === 'undefined' || isRemoved) return; | ||
@@ -254,7 +264,8 @@ var token = hcaptcha.getResponse(captchaId); //Get response token from hCaptcha widget | ||
var onExpire = this.props.onExpire; | ||
var _this$state5 = this.state, | ||
isApiReady = _this$state5.isApiReady, | ||
isRemoved = _this$state5.isRemoved, | ||
captchaId = _this$state5.captchaId; | ||
if (!isApiReady || isRemoved) return; | ||
var captchaId = this.state.captchaId; | ||
if (!this.isReady()) { | ||
return; | ||
} | ||
hcaptcha.reset(captchaId); // If hCaptcha runs into error, reset captcha - hCaptcha | ||
@@ -268,7 +279,8 @@ | ||
var onError = this.props.onError; | ||
var _this$state6 = this.state, | ||
isApiReady = _this$state6.isApiReady, | ||
isRemoved = _this$state6.isRemoved, | ||
captchaId = _this$state6.captchaId; | ||
if (!isApiReady || isRemoved) return; | ||
var captchaId = this.state.captchaId; | ||
if (!this.isReady()) { | ||
return; | ||
} | ||
hcaptcha.reset(captchaId); // If hCaptcha runs into error, reset captcha - hCaptcha | ||
@@ -279,11 +291,46 @@ | ||
}, { | ||
key: "isReady", | ||
value: function isReady() { | ||
var _this$state2 = this.state, | ||
isApiReady = _this$state2.isApiReady, | ||
isRemoved = _this$state2.isRemoved; | ||
return isApiReady && !isRemoved; | ||
} | ||
}, { | ||
key: "handleOpen", | ||
value: function handleOpen() { | ||
if (!this.isReady() || !this.props.onOpen) { | ||
return; | ||
} | ||
this.props.onOpen(); | ||
} | ||
}, { | ||
key: "handleClose", | ||
value: function handleClose() { | ||
if (!this.isReady() || !this.props.onClose) { | ||
return; | ||
} | ||
this.props.onClose(); | ||
} | ||
}, { | ||
key: "handleChallengeExpired", | ||
value: function handleChallengeExpired() { | ||
if (!this.isReady() || !this.props.onChalExpired) { | ||
return; | ||
} | ||
this.props.onChalExpired(); | ||
} | ||
}, { | ||
key: "execute", | ||
value: function execute() { | ||
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; | ||
var _this$state7 = this.state, | ||
isApiReady = _this$state7.isApiReady, | ||
isRemoved = _this$state7.isRemoved, | ||
captchaId = _this$state7.captchaId; | ||
if (!isApiReady || isRemoved) return; | ||
var captchaId = this.state.captchaId; | ||
if (!this.isReady()) { | ||
return; | ||
} | ||
if (opts && (0, _typeof2["default"])(opts) !== "object") { | ||
@@ -290,0 +337,0 @@ opts = null; |
{ | ||
"name": "@hcaptcha/react-hcaptcha", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"types": "types/index.d.ts", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -143,2 +143,5 @@ # React hCaptcha Component Library | ||
|`onLoad`|-|When the hCaptcha API loads.| | ||
|`onOpen`|-|When the user display of a challenge starts.| | ||
|`onClose`|-|When the user dismisses a challenge.| | ||
|`onChalExpired`|-|When the user display of a challenge times out with no answer.| | ||
@@ -145,0 +148,0 @@ ### Methods |
@@ -42,2 +42,3 @@ const React = require('react'); | ||
this.removeCaptcha = this.removeCaptcha.bind(this); | ||
this.isReady = this.isReady.bind(this); | ||
@@ -49,2 +50,5 @@ // Event Handlers | ||
this.handleError = this.handleError.bind(this); | ||
this.handleOpen = this.handleOpen.bind(this); | ||
this.handleClose = this.handleClose.bind(this); | ||
this.handleChallengeExpired = this.handleChallengeExpired.bind(this); | ||
@@ -93,5 +97,8 @@ const isApiReady = typeof hcaptcha !== 'undefined'; | ||
componentWillUnmount() { | ||
const { isApiReady, isRemoved, captchaId } = this.state; | ||
if(!isApiReady || isRemoved) return | ||
const { captchaId } = this.state; | ||
if (!this.isReady()) { | ||
return; | ||
} | ||
// Reset any stored variables / timers when unmounting | ||
@@ -130,3 +137,6 @@ hcaptcha.reset(captchaId); | ||
const renderParams = Object.assign({ | ||
"open-callback" : this.handleOpen, | ||
"close-callback" : this.handleClose, | ||
"error-callback" : this.handleError, | ||
"chalexpired-callback": this.handleChallengeExpired, | ||
"expired-callback" : this.handleExpire, | ||
@@ -148,5 +158,7 @@ "callback" : this.handleSubmit, | ||
resetCaptcha() { | ||
const { isApiReady, isRemoved, captchaId } = this.state; | ||
const { captchaId } = this.state; | ||
if (!isApiReady || isRemoved) return | ||
if (!this.isReady()) { | ||
return; | ||
} | ||
// Reset captcha state, removes stored token and unticks checkbox | ||
@@ -157,5 +169,7 @@ hcaptcha.reset(captchaId) | ||
removeCaptcha(callback) { | ||
const { isApiReady, isRemoved, captchaId } = this.state; | ||
const { captchaId } = this.state; | ||
if (!isApiReady || isRemoved) return | ||
if (!this.isReady()) { | ||
return; | ||
} | ||
@@ -193,5 +207,8 @@ this.setState({ isRemoved: true }, () => { | ||
const { onExpire } = this.props; | ||
const { isApiReady, isRemoved, captchaId } = this.state; | ||
const { captchaId } = this.state; | ||
if (!isApiReady || isRemoved) return | ||
if (!this.isReady()) { | ||
return; | ||
} | ||
hcaptcha.reset(captchaId) // If hCaptcha runs into error, reset captcha - hCaptcha | ||
@@ -204,5 +221,7 @@ | ||
const { onError } = this.props; | ||
const { isApiReady, isRemoved, captchaId } = this.state; | ||
const { captchaId } = this.state; | ||
if (!isApiReady || isRemoved) return | ||
if (!this.isReady()) { | ||
return; | ||
} | ||
@@ -213,6 +232,38 @@ hcaptcha.reset(captchaId) // If hCaptcha runs into error, reset captcha - hCaptcha | ||
isReady () { | ||
const { isApiReady, isRemoved } = this.state; | ||
return isApiReady && !isRemoved; | ||
} | ||
handleOpen () { | ||
if (!this.isReady() || !this.props.onOpen) { | ||
return; | ||
} | ||
this.props.onOpen(); | ||
} | ||
handleClose () { | ||
if (!this.isReady() || !this.props.onClose) { | ||
return; | ||
} | ||
this.props.onClose(); | ||
} | ||
handleChallengeExpired () { | ||
if (!this.isReady() || !this.props.onChalExpired) { | ||
return; | ||
} | ||
this.props.onChalExpired(); | ||
} | ||
execute (opts = null) { | ||
const { isApiReady, isRemoved, captchaId } = this.state; | ||
const { captchaId } = this.state; | ||
if (!isApiReady || isRemoved) return; | ||
if (!this.isReady()) { | ||
return; | ||
} | ||
@@ -219,0 +270,0 @@ if (opts && typeof opts !== "object") { |
@@ -18,2 +18,5 @@ // Type definitions for @hcaptcha/react-hcaptcha 0.1 | ||
onExpire?: () => any; | ||
onOpen?: () => any; | ||
onClose?: () => any; | ||
onChalExpired?: () => any; | ||
onError?: (event: string) => any; | ||
@@ -20,0 +23,0 @@ onVerify?: (token: string) => any; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32010
574
193