@hcaptcha/react-hcaptcha 1.3.0 → 1.4.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/esm/index.js +332 -0
- package/dist/esm/utils.js +14 -0
- package/dist/index.js +34 -25
- package/dist/utils.js +6 -4
- package/package.json +12 -5
- package/src/index.js +19 -18
- package/src/utils.js +1 -3
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
2
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { generateQuery } from "./utils.js"; // Create script to init hCaptcha
|
|
5
|
+
|
|
6
|
+
var onLoadListeners = [];
|
|
7
|
+
var apiScriptRequested = false; // Generate hCaptcha API Script
|
|
8
|
+
|
|
9
|
+
var mountCaptchaScript = function mountCaptchaScript(params) {
|
|
10
|
+
if (params === void 0) {
|
|
11
|
+
params = {};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
apiScriptRequested = true; // Create global onload callback
|
|
15
|
+
|
|
16
|
+
window.hcaptchaOnLoad = function () {
|
|
17
|
+
// Iterate over onload listeners, call each listener
|
|
18
|
+
onLoadListeners = onLoadListeners.filter(function (listener) {
|
|
19
|
+
listener();
|
|
20
|
+
return false;
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
var domain = params.apihost || "https://js.hcaptcha.com";
|
|
25
|
+
delete params.apihost;
|
|
26
|
+
var script = document.createElement("script");
|
|
27
|
+
script.src = domain + "/1/api.js?render=explicit&onload=hcaptchaOnLoad";
|
|
28
|
+
script.async = true;
|
|
29
|
+
var query = generateQuery(params);
|
|
30
|
+
script.src += query !== "" ? "&" + query : "";
|
|
31
|
+
document.head.appendChild(script);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
35
|
+
_inheritsLoose(HCaptcha, _React$Component);
|
|
36
|
+
|
|
37
|
+
function HCaptcha(props) {
|
|
38
|
+
var _this;
|
|
39
|
+
|
|
40
|
+
_this = _React$Component.call(this, props) || this; // API Methods
|
|
41
|
+
|
|
42
|
+
_this.renderCaptcha = _this.renderCaptcha.bind(_assertThisInitialized(_this));
|
|
43
|
+
_this.resetCaptcha = _this.resetCaptcha.bind(_assertThisInitialized(_this));
|
|
44
|
+
_this.removeCaptcha = _this.removeCaptcha.bind(_assertThisInitialized(_this));
|
|
45
|
+
_this.isReady = _this.isReady.bind(_assertThisInitialized(_this)); // Event Handlers
|
|
46
|
+
|
|
47
|
+
_this.handleOnLoad = _this.handleOnLoad.bind(_assertThisInitialized(_this));
|
|
48
|
+
_this.handleSubmit = _this.handleSubmit.bind(_assertThisInitialized(_this));
|
|
49
|
+
_this.handleExpire = _this.handleExpire.bind(_assertThisInitialized(_this));
|
|
50
|
+
_this.handleError = _this.handleError.bind(_assertThisInitialized(_this));
|
|
51
|
+
_this.handleOpen = _this.handleOpen.bind(_assertThisInitialized(_this));
|
|
52
|
+
_this.handleClose = _this.handleClose.bind(_assertThisInitialized(_this));
|
|
53
|
+
_this.handleChallengeExpired = _this.handleChallengeExpired.bind(_assertThisInitialized(_this));
|
|
54
|
+
var isApiReady = typeof hcaptcha !== 'undefined';
|
|
55
|
+
_this.ref = /*#__PURE__*/React.createRef();
|
|
56
|
+
_this.state = {
|
|
57
|
+
isApiReady: isApiReady,
|
|
58
|
+
isRemoved: false,
|
|
59
|
+
elementId: props.id,
|
|
60
|
+
captchaId: ''
|
|
61
|
+
};
|
|
62
|
+
return _this;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
var _proto = HCaptcha.prototype;
|
|
66
|
+
|
|
67
|
+
_proto.componentDidMount = function componentDidMount() {
|
|
68
|
+
//Once captcha is mounted intialize hCaptcha - hCaptcha
|
|
69
|
+
var _this$props = this.props,
|
|
70
|
+
apihost = _this$props.apihost,
|
|
71
|
+
assethost = _this$props.assethost,
|
|
72
|
+
endpoint = _this$props.endpoint,
|
|
73
|
+
host = _this$props.host,
|
|
74
|
+
imghost = _this$props.imghost,
|
|
75
|
+
hl = _this$props.languageOverride,
|
|
76
|
+
reCaptchaCompat = _this$props.reCaptchaCompat,
|
|
77
|
+
reportapi = _this$props.reportapi,
|
|
78
|
+
sentry = _this$props.sentry,
|
|
79
|
+
custom = _this$props.custom;
|
|
80
|
+
var isApiReady = this.state.isApiReady;
|
|
81
|
+
|
|
82
|
+
if (!isApiReady) {
|
|
83
|
+
//Check if hCaptcha has already been loaded, if not create script tag and wait to render captcha
|
|
84
|
+
if (apiScriptRequested) {
|
|
85
|
+
return;
|
|
86
|
+
} // Only create the script tag once, use a global variable to track
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
mountCaptchaScript({
|
|
90
|
+
apihost: apihost,
|
|
91
|
+
assethost: assethost,
|
|
92
|
+
endpoint: endpoint,
|
|
93
|
+
hl: hl,
|
|
94
|
+
host: host,
|
|
95
|
+
imghost: imghost,
|
|
96
|
+
recaptchacompat: reCaptchaCompat === false ? "off" : null,
|
|
97
|
+
reportapi: reportapi,
|
|
98
|
+
sentry: sentry,
|
|
99
|
+
custom: custom
|
|
100
|
+
}); // Add onload callback to global onload listeners
|
|
101
|
+
|
|
102
|
+
onLoadListeners.push(this.handleOnLoad);
|
|
103
|
+
} else {
|
|
104
|
+
this.renderCaptcha();
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
_proto.componentWillUnmount = function componentWillUnmount() {
|
|
109
|
+
var captchaId = this.state.captchaId;
|
|
110
|
+
|
|
111
|
+
if (!this.isReady()) {
|
|
112
|
+
return;
|
|
113
|
+
} // Reset any stored variables / timers when unmounting
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
hcaptcha.reset(captchaId);
|
|
117
|
+
hcaptcha.remove(captchaId);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
_proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) {
|
|
121
|
+
// Prevent component re-rendering when these internal state variables are updated
|
|
122
|
+
if (this.state.isApiReady !== nextState.isApiReady || this.state.isRemoved !== nextState.isRemoved) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return true;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
_proto.componentDidUpdate = function componentDidUpdate(prevProps) {
|
|
130
|
+
var _this2 = this;
|
|
131
|
+
|
|
132
|
+
// Prop Keys that could change
|
|
133
|
+
var keys = ['sitekey', 'size', 'theme', 'tabindex', 'languageOverride', 'endpoint']; // See if any props changed during component update
|
|
134
|
+
|
|
135
|
+
var match = keys.every(function (key) {
|
|
136
|
+
return prevProps[key] === _this2.props[key];
|
|
137
|
+
}); // If they have changed, remove current captcha and render a new one
|
|
138
|
+
|
|
139
|
+
if (!match) {
|
|
140
|
+
this.removeCaptcha(function () {
|
|
141
|
+
_this2.renderCaptcha();
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
_proto.renderCaptcha = function renderCaptcha(onReady) {
|
|
147
|
+
var isApiReady = this.state.isApiReady;
|
|
148
|
+
if (!isApiReady) return;
|
|
149
|
+
var renderParams = Object.assign({
|
|
150
|
+
"open-callback": this.handleOpen,
|
|
151
|
+
"close-callback": this.handleClose,
|
|
152
|
+
"error-callback": this.handleError,
|
|
153
|
+
"chalexpired-callback": this.handleChallengeExpired,
|
|
154
|
+
"expired-callback": this.handleExpire,
|
|
155
|
+
"callback": this.handleSubmit
|
|
156
|
+
}, this.props, {
|
|
157
|
+
hl: this.props.hl || this.props.languageOverride,
|
|
158
|
+
languageOverride: undefined
|
|
159
|
+
}); //Render hCaptcha widget and provide necessary callbacks - hCaptcha
|
|
160
|
+
|
|
161
|
+
var captchaId = hcaptcha.render(this.ref.current, renderParams);
|
|
162
|
+
this.setState({
|
|
163
|
+
isRemoved: false,
|
|
164
|
+
captchaId: captchaId
|
|
165
|
+
}, function () {
|
|
166
|
+
onReady && onReady();
|
|
167
|
+
});
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
_proto.resetCaptcha = function resetCaptcha() {
|
|
171
|
+
var captchaId = this.state.captchaId;
|
|
172
|
+
|
|
173
|
+
if (!this.isReady()) {
|
|
174
|
+
return;
|
|
175
|
+
} // Reset captcha state, removes stored token and unticks checkbox
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
hcaptcha.reset(captchaId);
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
_proto.removeCaptcha = function removeCaptcha(callback) {
|
|
182
|
+
var captchaId = this.state.captchaId;
|
|
183
|
+
|
|
184
|
+
if (!this.isReady()) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
this.setState({
|
|
189
|
+
isRemoved: true
|
|
190
|
+
}, function () {
|
|
191
|
+
hcaptcha.remove(captchaId);
|
|
192
|
+
callback && callback();
|
|
193
|
+
});
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
_proto.handleOnLoad = function handleOnLoad() {
|
|
197
|
+
var _this3 = this;
|
|
198
|
+
|
|
199
|
+
this.setState({
|
|
200
|
+
isApiReady: true
|
|
201
|
+
}, function () {
|
|
202
|
+
// render captcha and wait for captcha id
|
|
203
|
+
_this3.renderCaptcha(function () {
|
|
204
|
+
// trigger onLoad if it exists
|
|
205
|
+
var onLoad = _this3.props.onLoad;
|
|
206
|
+
if (onLoad) onLoad();
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
_proto.handleSubmit = function handleSubmit(event) {
|
|
212
|
+
var onVerify = this.props.onVerify;
|
|
213
|
+
var _this$state = this.state,
|
|
214
|
+
isRemoved = _this$state.isRemoved,
|
|
215
|
+
captchaId = _this$state.captchaId;
|
|
216
|
+
if (typeof hcaptcha === 'undefined' || isRemoved) return;
|
|
217
|
+
var token = hcaptcha.getResponse(captchaId); //Get response token from hCaptcha widget
|
|
218
|
+
|
|
219
|
+
var ekey = hcaptcha.getRespKey(captchaId); //Get current challenge session id from hCaptcha widget
|
|
220
|
+
|
|
221
|
+
onVerify(token, ekey); //Dispatch event to verify user response
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
_proto.handleExpire = function handleExpire() {
|
|
225
|
+
var onExpire = this.props.onExpire;
|
|
226
|
+
var captchaId = this.state.captchaId;
|
|
227
|
+
|
|
228
|
+
if (!this.isReady()) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
hcaptcha.reset(captchaId); // If hCaptcha runs into error, reset captcha - hCaptcha
|
|
233
|
+
|
|
234
|
+
if (onExpire) onExpire();
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
_proto.handleError = function handleError(event) {
|
|
238
|
+
var onError = this.props.onError;
|
|
239
|
+
var captchaId = this.state.captchaId;
|
|
240
|
+
|
|
241
|
+
if (!this.isReady()) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
hcaptcha.reset(captchaId); // If hCaptcha runs into error, reset captcha - hCaptcha
|
|
246
|
+
|
|
247
|
+
if (onError) onError(event);
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
_proto.isReady = function isReady() {
|
|
251
|
+
var _this$state2 = this.state,
|
|
252
|
+
isApiReady = _this$state2.isApiReady,
|
|
253
|
+
isRemoved = _this$state2.isRemoved;
|
|
254
|
+
return isApiReady && !isRemoved;
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
_proto.handleOpen = function handleOpen() {
|
|
258
|
+
if (!this.isReady() || !this.props.onOpen) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
this.props.onOpen();
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
_proto.handleClose = function handleClose() {
|
|
266
|
+
if (!this.isReady() || !this.props.onClose) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
this.props.onClose();
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
_proto.handleChallengeExpired = function handleChallengeExpired() {
|
|
274
|
+
if (!this.isReady() || !this.props.onChalExpired) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
this.props.onChalExpired();
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
_proto.execute = function execute(opts) {
|
|
282
|
+
if (opts === void 0) {
|
|
283
|
+
opts = null;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
var captchaId = this.state.captchaId;
|
|
287
|
+
|
|
288
|
+
if (!this.isReady()) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
if (opts && typeof opts !== "object") {
|
|
293
|
+
opts = null;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return hcaptcha.execute(captchaId, opts);
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
_proto.setData = function setData(data) {
|
|
300
|
+
var captchaId = this.state.captchaId;
|
|
301
|
+
|
|
302
|
+
if (!this.isReady()) {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (data && typeof data !== "object") {
|
|
307
|
+
data = null;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
hcaptcha.setData(captchaId, data);
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
_proto.getResponse = function getResponse() {
|
|
314
|
+
return hcaptcha.getResponse(this.state.captchaId);
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
_proto.getRespKey = function getRespKey() {
|
|
318
|
+
return hcaptcha.getRespKey(this.state.captchaId);
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
_proto.render = function render() {
|
|
322
|
+
var elementId = this.state.elementId;
|
|
323
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
324
|
+
ref: this.ref,
|
|
325
|
+
id: elementId
|
|
326
|
+
});
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
return HCaptcha;
|
|
330
|
+
}(React.Component);
|
|
331
|
+
|
|
332
|
+
export default HCaptcha;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
function generateQuery(params) {
|
|
2
|
+
return Object.entries(params).filter(function (_ref) {
|
|
3
|
+
var key = _ref[0],
|
|
4
|
+
value = _ref[1];
|
|
5
|
+
return value || value === false;
|
|
6
|
+
}).map(function (_ref2) {
|
|
7
|
+
var key = _ref2[0],
|
|
8
|
+
value = _ref2[1];
|
|
9
|
+
return encodeURIComponent(key) + "=" + encodeURIComponent(value);
|
|
10
|
+
}).join("&");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
;
|
|
14
|
+
export { generateQuery };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
|
4
|
+
|
|
3
5
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
6
|
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
exports["default"] = void 0;
|
|
11
|
+
|
|
5
12
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
6
13
|
|
|
7
14
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
@@ -16,16 +23,15 @@ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime
|
|
|
16
23
|
|
|
17
24
|
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
18
25
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
26
|
+
var React = _interopRequireWildcard(require("react"));
|
|
22
27
|
|
|
23
|
-
var
|
|
28
|
+
var _utils = require("./utils.js");
|
|
24
29
|
|
|
25
|
-
var
|
|
26
|
-
generateQuery = _require.generateQuery; // Create script to init hCaptcha
|
|
30
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
|
|
27
31
|
|
|
32
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
28
33
|
|
|
34
|
+
// Create script to init hCaptcha
|
|
29
35
|
var onLoadListeners = [];
|
|
30
36
|
var apiScriptRequested = false; // Generate hCaptcha API Script
|
|
31
37
|
|
|
@@ -46,7 +52,7 @@ var mountCaptchaScript = function mountCaptchaScript() {
|
|
|
46
52
|
var script = document.createElement("script");
|
|
47
53
|
script.src = "".concat(domain, "/1/api.js?render=explicit&onload=hcaptchaOnLoad");
|
|
48
54
|
script.async = true;
|
|
49
|
-
var query = generateQuery(params);
|
|
55
|
+
var query = (0, _utils.generateQuery)(params);
|
|
50
56
|
script.src += query !== "" ? "&".concat(query) : "";
|
|
51
57
|
document.head.appendChild(script);
|
|
52
58
|
};
|
|
@@ -75,7 +81,7 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
75
81
|
_this.handleClose = _this.handleClose.bind((0, _assertThisInitialized2["default"])(_this));
|
|
76
82
|
_this.handleChallengeExpired = _this.handleChallengeExpired.bind((0, _assertThisInitialized2["default"])(_this));
|
|
77
83
|
var isApiReady = typeof hcaptcha !== 'undefined';
|
|
78
|
-
_this.ref = React.createRef();
|
|
84
|
+
_this.ref = /*#__PURE__*/React.createRef();
|
|
79
85
|
_this.state = {
|
|
80
86
|
isApiReady: isApiReady,
|
|
81
87
|
isRemoved: false,
|
|
@@ -104,22 +110,23 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
104
110
|
|
|
105
111
|
if (!isApiReady) {
|
|
106
112
|
//Check if hCaptcha has already been loaded, if not create script tag and wait to render captcha
|
|
107
|
-
if (
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
113
|
+
if (apiScriptRequested) {
|
|
114
|
+
return;
|
|
115
|
+
} // Only create the script tag once, use a global variable to track
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
mountCaptchaScript({
|
|
119
|
+
apihost: apihost,
|
|
120
|
+
assethost: assethost,
|
|
121
|
+
endpoint: endpoint,
|
|
122
|
+
hl: hl,
|
|
123
|
+
host: host,
|
|
124
|
+
imghost: imghost,
|
|
125
|
+
recaptchacompat: reCaptchaCompat === false ? "off" : null,
|
|
126
|
+
reportapi: reportapi,
|
|
127
|
+
sentry: sentry,
|
|
128
|
+
custom: custom
|
|
129
|
+
}); // Add onload callback to global onload listeners
|
|
123
130
|
|
|
124
131
|
onLoadListeners.push(this.handleOnLoad);
|
|
125
132
|
} else {
|
|
@@ -367,4 +374,6 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
367
374
|
return HCaptcha;
|
|
368
375
|
}(React.Component);
|
|
369
376
|
|
|
370
|
-
|
|
377
|
+
var _default = HCaptcha;
|
|
378
|
+
exports["default"] = _default;
|
|
379
|
+
module.exports = exports.default;
|
package/dist/utils.js
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
4
|
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.generateQuery = generateQuery;
|
|
9
|
+
|
|
5
10
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
6
11
|
|
|
7
12
|
function generateQuery(params) {
|
|
@@ -20,7 +25,4 @@ function generateQuery(params) {
|
|
|
20
25
|
}).join("&");
|
|
21
26
|
}
|
|
22
27
|
|
|
23
|
-
;
|
|
24
|
-
module.exports = {
|
|
25
|
-
generateQuery: generateQuery
|
|
26
|
-
};
|
|
28
|
+
;
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hcaptcha/react-hcaptcha",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"types": "types/index.d.ts",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
6
7
|
"files": [
|
|
7
8
|
"src",
|
|
8
9
|
"dist",
|
|
9
|
-
"types
|
|
10
|
+
"types"
|
|
10
11
|
],
|
|
11
12
|
"description": "A React library for hCaptcha",
|
|
12
13
|
"scripts": {
|
|
@@ -14,8 +15,10 @@
|
|
|
14
15
|
"test": "jest",
|
|
15
16
|
"watch": "babel src -d dist --copy-files --watch",
|
|
16
17
|
"transpile": "babel src -d dist --copy-files",
|
|
17
|
-
"
|
|
18
|
-
"
|
|
18
|
+
"prebuild": "rimraf dist",
|
|
19
|
+
"build": "npm run transpile && npm run build:esm",
|
|
20
|
+
"build:esm": "cross-env BABEL_ENV=esm babel src -d dist/esm --copy-files",
|
|
21
|
+
"prepublishOnly": "npm run build"
|
|
19
22
|
},
|
|
20
23
|
"peerDependencies": {
|
|
21
24
|
"react": ">= 16.3.0",
|
|
@@ -36,15 +39,19 @@
|
|
|
36
39
|
"@babel/preset-env": "^7.12.11",
|
|
37
40
|
"@babel/preset-react": "^7.12.10",
|
|
38
41
|
"babel-loader": "^8.2.2",
|
|
42
|
+
"babel-plugin-add-module-exports": "^1.0.4",
|
|
43
|
+
"cross-env": "^7.0.3",
|
|
39
44
|
"html-webpack-plugin": "^3.2.0",
|
|
40
45
|
"jest": "^26.6.3",
|
|
41
46
|
"react": "^16.14.0",
|
|
42
47
|
"react-dom": "^16.14.0",
|
|
48
|
+
"rimraf": "^3.0.2",
|
|
43
49
|
"webpack": "^4.44.2",
|
|
44
50
|
"webpack-cli": "^3.3.12",
|
|
45
51
|
"webpack-dev-server": "^3.11.0"
|
|
46
52
|
},
|
|
47
53
|
"dependencies": {
|
|
48
|
-
"@babel/runtime": "^7.17.9"
|
|
54
|
+
"@babel/runtime": "^7.17.9",
|
|
55
|
+
"@types/react": "^18.0.0"
|
|
49
56
|
}
|
|
50
57
|
}
|
package/src/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { generateQuery } from "./utils.js";
|
|
3
3
|
|
|
4
4
|
// Create script to init hCaptcha
|
|
5
5
|
let onLoadListeners = [];
|
|
@@ -67,23 +67,24 @@ class HCaptcha extends React.Component {
|
|
|
67
67
|
const { isApiReady } = this.state;
|
|
68
68
|
|
|
69
69
|
if (!isApiReady) { //Check if hCaptcha has already been loaded, if not create script tag and wait to render captcha
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
// Only create the script tag once, use a global variable to track
|
|
73
|
-
mountCaptchaScript({
|
|
74
|
-
apihost,
|
|
75
|
-
assethost,
|
|
76
|
-
endpoint,
|
|
77
|
-
hl,
|
|
78
|
-
host,
|
|
79
|
-
imghost,
|
|
80
|
-
recaptchacompat: reCaptchaCompat === false? "off" : null,
|
|
81
|
-
reportapi,
|
|
82
|
-
sentry,
|
|
83
|
-
custom
|
|
84
|
-
});
|
|
70
|
+
if (apiScriptRequested) {
|
|
71
|
+
return;
|
|
85
72
|
}
|
|
86
73
|
|
|
74
|
+
// Only create the script tag once, use a global variable to track
|
|
75
|
+
mountCaptchaScript({
|
|
76
|
+
apihost,
|
|
77
|
+
assethost,
|
|
78
|
+
endpoint,
|
|
79
|
+
hl,
|
|
80
|
+
host,
|
|
81
|
+
imghost,
|
|
82
|
+
recaptchacompat: reCaptchaCompat === false? "off" : null,
|
|
83
|
+
reportapi,
|
|
84
|
+
sentry,
|
|
85
|
+
custom
|
|
86
|
+
});
|
|
87
|
+
|
|
87
88
|
// Add onload callback to global onload listeners
|
|
88
89
|
onLoadListeners.push(this.handleOnLoad);
|
|
89
90
|
} else {
|
|
@@ -293,4 +294,4 @@ class HCaptcha extends React.Component {
|
|
|
293
294
|
}
|
|
294
295
|
}
|
|
295
296
|
|
|
296
|
-
|
|
297
|
+
export default HCaptcha;
|