@hcaptcha/react-hcaptcha
Advanced tools
Comparing version 1.10.3 to 1.11.0
@@ -26,2 +26,3 @@ import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized"; | ||
_this.isReady = _this.isReady.bind(_assertThisInitialized(_this)); | ||
_this._onReady = null; | ||
@@ -158,2 +159,3 @@ // Event Handlers | ||
_proto.renderCaptcha = function renderCaptcha(onReady) { | ||
var _this4 = this; | ||
var isApiReady = this.state.isApiReady; | ||
@@ -180,2 +182,3 @@ if (!isApiReady) return; | ||
onReady && onReady(); | ||
_this4._onReady && _this4._onReady(captchaId); | ||
}); | ||
@@ -214,3 +217,3 @@ }; | ||
_proto.handleOnLoad = function handleOnLoad() { | ||
var _this4 = this; | ||
var _this5 = this; | ||
this.setState({ | ||
@@ -220,15 +223,15 @@ isApiReady: true | ||
try { | ||
var element = getMountElement(_this4.props.scriptLocation); | ||
var element = getMountElement(_this5.props.scriptLocation); | ||
var frame = getFrame(element); | ||
_this4._hcaptcha = frame.window.hcaptcha; | ||
_this5._hcaptcha = frame.window.hcaptcha; | ||
// render captcha and wait for captcha id | ||
_this4.renderCaptcha(function () { | ||
_this5.renderCaptcha(function () { | ||
// trigger onLoad if it exists | ||
var onLoad = _this4.props.onLoad; | ||
var onLoad = _this5.props.onLoad; | ||
if (onLoad) onLoad(); | ||
}); | ||
} catch (error) { | ||
_this4.sentryHub.captureException(error); | ||
_this5.sentryHub.captureException(error); | ||
} | ||
@@ -298,5 +301,7 @@ }); | ||
_proto.execute = function execute(opts) { | ||
var _this6 = this; | ||
if (opts === void 0) { | ||
opts = null; | ||
} | ||
opts = typeof opts === 'object' ? opts : null; | ||
try { | ||
@@ -306,10 +311,26 @@ var captchaId = this.state.captchaId; | ||
if (!this.isReady()) { | ||
return; | ||
var _opts; | ||
var onReady = new Promise(function (resolve, reject) { | ||
_this6._onReady = function (id) { | ||
try { | ||
var _hcaptcha = _this6._hcaptcha; | ||
if (opts && opts.async) { | ||
_hcaptcha.execute(id, opts).then(resolve)["catch"](reject); | ||
} else { | ||
resolve(_hcaptcha.execute(id, opts)); | ||
} | ||
} catch (e) { | ||
reject(e); | ||
} | ||
}; | ||
}); | ||
return (_opts = opts) != null && _opts.async ? onReady : null; | ||
} | ||
if (opts && typeof opts !== "object") { | ||
opts = null; | ||
} | ||
return hcaptcha.execute(captchaId, opts); | ||
} catch (error) { | ||
this.sentryHub.captureException(error); | ||
if (opts && opts.async) { | ||
return Promise.reject(error); | ||
} | ||
return null; | ||
} | ||
@@ -316,0 +337,0 @@ }; |
@@ -44,2 +44,3 @@ "use strict"; | ||
_this.isReady = _this.isReady.bind((0, _assertThisInitialized2["default"])(_this)); | ||
_this._onReady = null; | ||
@@ -187,2 +188,3 @@ // Event Handlers | ||
value: function renderCaptcha(onReady) { | ||
var _this4 = this; | ||
var isApiReady = this.state.isApiReady; | ||
@@ -209,2 +211,3 @@ if (!isApiReady) return; | ||
onReady && onReady(); | ||
_this4._onReady && _this4._onReady(captchaId); | ||
}); | ||
@@ -249,3 +252,3 @@ } | ||
value: function handleOnLoad() { | ||
var _this4 = this; | ||
var _this5 = this; | ||
this.setState({ | ||
@@ -255,15 +258,15 @@ isApiReady: true | ||
try { | ||
var element = (0, _utils.getMountElement)(_this4.props.scriptLocation); | ||
var element = (0, _utils.getMountElement)(_this5.props.scriptLocation); | ||
var frame = (0, _utils.getFrame)(element); | ||
_this4._hcaptcha = frame.window.hcaptcha; | ||
_this5._hcaptcha = frame.window.hcaptcha; | ||
// render captcha and wait for captcha id | ||
_this4.renderCaptcha(function () { | ||
_this5.renderCaptcha(function () { | ||
// trigger onLoad if it exists | ||
var onLoad = _this4.props.onLoad; | ||
var onLoad = _this5.props.onLoad; | ||
if (onLoad) onLoad(); | ||
}); | ||
} catch (error) { | ||
_this4.sentryHub.captureException(error); | ||
_this5.sentryHub.captureException(error); | ||
} | ||
@@ -349,3 +352,5 @@ }); | ||
value: function execute() { | ||
var _this6 = this; | ||
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; | ||
opts = (0, _typeof2["default"])(opts) === 'object' ? opts : null; | ||
try { | ||
@@ -355,10 +360,26 @@ var captchaId = this.state.captchaId; | ||
if (!this.isReady()) { | ||
return; | ||
var _opts; | ||
var onReady = new Promise(function (resolve, reject) { | ||
_this6._onReady = function (id) { | ||
try { | ||
var _hcaptcha = _this6._hcaptcha; | ||
if (opts && opts.async) { | ||
_hcaptcha.execute(id, opts).then(resolve)["catch"](reject); | ||
} else { | ||
resolve(_hcaptcha.execute(id, opts)); | ||
} | ||
} catch (e) { | ||
reject(e); | ||
} | ||
}; | ||
}); | ||
return (_opts = opts) !== null && _opts !== void 0 && _opts.async ? onReady : null; | ||
} | ||
if (opts && (0, _typeof2["default"])(opts) !== "object") { | ||
opts = null; | ||
} | ||
return hcaptcha.execute(captchaId, opts); | ||
} catch (error) { | ||
this.sentryHub.captureException(error); | ||
if (opts && opts.async) { | ||
return Promise.reject(error); | ||
} | ||
return null; | ||
} | ||
@@ -365,0 +386,0 @@ } |
{ | ||
"name": "@hcaptcha/react-hcaptcha", | ||
"version": "1.10.3", | ||
"version": "1.11.0", | ||
"types": "types/index.d.ts", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -25,2 +25,3 @@ import * as React from 'react'; | ||
this.isReady = this.isReady.bind(this); | ||
this._onReady = null; | ||
@@ -195,2 +196,3 @@ // Event Handlers | ||
onReady && onReady(); | ||
this._onReady && this._onReady(captchaId); | ||
}); | ||
@@ -235,3 +237,3 @@ } | ||
handleOnLoad () { | ||
handleOnLoad () { | ||
this.setState({ isApiReady: true }, () => { | ||
@@ -333,18 +335,37 @@ try { | ||
execute (opts = null) { | ||
opts = typeof opts === 'object' ? opts : null; | ||
try { | ||
const { captchaId } = this.state; | ||
const hcaptcha = this._hcaptcha; | ||
if (!this.isReady()) { | ||
return; | ||
const onReady = new Promise((resolve, reject) => { | ||
this._onReady = (id) => { | ||
try { | ||
const hcaptcha = this._hcaptcha; | ||
if (opts && opts.async) { | ||
hcaptcha.execute(id, opts).then(resolve).catch(reject); | ||
} else { | ||
resolve(hcaptcha.execute(id, opts)); | ||
} | ||
} catch (e) { | ||
reject(e); | ||
} | ||
}; | ||
}); | ||
return opts?.async ? onReady : null; | ||
} | ||
if (opts && typeof opts !== "object") { | ||
opts = null; | ||
} | ||
return hcaptcha.execute(captchaId, opts); | ||
} catch (error) { | ||
this.sentryHub.captureException(error); | ||
this.sentryHub.captureException(error); | ||
if (opts && opts.async) { | ||
return Promise.reject(error); | ||
} | ||
return null; | ||
} | ||
@@ -351,0 +372,0 @@ } |
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
55110
1206