@hcaptcha/react-hcaptcha 1.17.4 → 2.0.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/README.md +8 -4
- package/lib/dist/cjs/hooks/index.js +4 -0
- package/lib/dist/cjs/index.js +4 -0
- package/lib/dist/esm/hooks/index.js +4 -0
- package/lib/dist/esm/index.js +4 -0
- package/package.json +41 -61
- package/types/hooks/index.d.ts +2 -3
- package/types/index.d.ts +18 -19
- package/dist/esm/hooks/Context.js +0 -2
- package/dist/esm/hooks/Provider.js +0 -120
- package/dist/esm/hooks/index.js +0 -2
- package/dist/esm/hooks/useHCaptcha.tsx +0 -4
- package/dist/esm/index.js +0 -421
- package/dist/esm/package.json +0 -1
- package/dist/esm/utils.js +0 -12
- package/dist/hooks/Context.js +0 -8
- package/dist/hooks/Provider.js +0 -137
- package/dist/hooks/index.js +0 -19
- package/dist/hooks/useHCaptcha.tsx +0 -4
- package/dist/index.js +0 -484
- package/dist/utils.js +0 -18
- package/src/hooks/Context.jsx +0 -3
- package/src/hooks/Provider.jsx +0 -98
- package/src/hooks/index.jsx +0 -2
- package/src/hooks/useHCaptcha.tsx +0 -4
- package/src/index.js +0 -471
- package/src/utils.js +0 -15
package/dist/esm/index.js
DELETED
|
@@ -1,421 +0,0 @@
|
|
|
1
|
-
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
2
|
-
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
3
|
-
import * as React from 'react';
|
|
4
|
-
import { hCaptchaLoader } from '@hcaptcha/loader';
|
|
5
|
-
import { getFrame, getMountElement } from './utils.js';
|
|
6
|
-
var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
7
|
-
_inheritsLoose(HCaptcha, _React$Component);
|
|
8
|
-
function HCaptcha(props) {
|
|
9
|
-
var _this;
|
|
10
|
-
_this = _React$Component.call(this, props) || this;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Internal reference to track hCaptcha API
|
|
14
|
-
*
|
|
15
|
-
* Required as window is relative to initialization in application
|
|
16
|
-
* not where the script and iFrames have been loaded.
|
|
17
|
-
*/
|
|
18
|
-
_this._hcaptcha = undefined;
|
|
19
|
-
|
|
20
|
-
// API Methods
|
|
21
|
-
_this.renderCaptcha = _this.renderCaptcha.bind(_assertThisInitialized(_this));
|
|
22
|
-
_this.resetCaptcha = _this.resetCaptcha.bind(_assertThisInitialized(_this));
|
|
23
|
-
_this.removeCaptcha = _this.removeCaptcha.bind(_assertThisInitialized(_this));
|
|
24
|
-
_this.isReady = _this.isReady.bind(_assertThisInitialized(_this));
|
|
25
|
-
_this._onReady = null;
|
|
26
|
-
|
|
27
|
-
// Event Handlers
|
|
28
|
-
_this.loadCaptcha = _this.loadCaptcha.bind(_assertThisInitialized(_this));
|
|
29
|
-
_this.handleOnLoad = _this.handleOnLoad.bind(_assertThisInitialized(_this));
|
|
30
|
-
_this.handleSubmit = _this.handleSubmit.bind(_assertThisInitialized(_this));
|
|
31
|
-
_this.handleExpire = _this.handleExpire.bind(_assertThisInitialized(_this));
|
|
32
|
-
_this.handleError = _this.handleError.bind(_assertThisInitialized(_this));
|
|
33
|
-
_this.handleOpen = _this.handleOpen.bind(_assertThisInitialized(_this));
|
|
34
|
-
_this.handleClose = _this.handleClose.bind(_assertThisInitialized(_this));
|
|
35
|
-
_this.handleChallengeExpired = _this.handleChallengeExpired.bind(_assertThisInitialized(_this));
|
|
36
|
-
_this.ref = /*#__PURE__*/React.createRef();
|
|
37
|
-
_this.apiScriptRequested = false;
|
|
38
|
-
_this.sentryHub = null;
|
|
39
|
-
_this.captchaId = '';
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Tracks the currently pending async execute() promise.
|
|
43
|
-
* Stores { resolve, reject } so we can cancel on unmount/errors/etc.
|
|
44
|
-
*/
|
|
45
|
-
_this._pendingExecute = null;
|
|
46
|
-
_this.state = {
|
|
47
|
-
isApiReady: false,
|
|
48
|
-
isRemoved: false,
|
|
49
|
-
elementId: props.id
|
|
50
|
-
};
|
|
51
|
-
return _this;
|
|
52
|
-
}
|
|
53
|
-
var _proto = HCaptcha.prototype;
|
|
54
|
-
_proto.componentDidMount = function componentDidMount() {
|
|
55
|
-
var _this2 = this;
|
|
56
|
-
// Once captcha is mounted intialize hCaptcha - hCaptcha
|
|
57
|
-
var element = getMountElement(this.props.scriptLocation);
|
|
58
|
-
var frame = getFrame(element);
|
|
59
|
-
this._hcaptcha = frame.window.hcaptcha || undefined;
|
|
60
|
-
var isApiReady = typeof this._hcaptcha !== 'undefined';
|
|
61
|
-
|
|
62
|
-
/*
|
|
63
|
-
* Check if hCaptcha has already been loaded,
|
|
64
|
-
* If Yes, render the captcha
|
|
65
|
-
* If No, create script tag and wait to render the captcha
|
|
66
|
-
*/
|
|
67
|
-
if (isApiReady) {
|
|
68
|
-
this.setState({
|
|
69
|
-
isApiReady: true
|
|
70
|
-
}, function () {
|
|
71
|
-
_this2.renderCaptcha();
|
|
72
|
-
});
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
this.loadCaptcha();
|
|
76
|
-
};
|
|
77
|
-
_proto.componentWillUnmount = function componentWillUnmount() {
|
|
78
|
-
var hcaptcha = this._hcaptcha;
|
|
79
|
-
var captchaId = this.captchaId;
|
|
80
|
-
this._cancelPendingExecute('react-component-unmounted');
|
|
81
|
-
if (!this.isReady()) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// Reset any stored variables / timers when unmounting
|
|
86
|
-
hcaptcha.reset(captchaId);
|
|
87
|
-
hcaptcha.remove(captchaId);
|
|
88
|
-
};
|
|
89
|
-
_proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) {
|
|
90
|
-
// Prevent component re-rendering when these internal state variables are updated
|
|
91
|
-
if (this.state.isApiReady !== nextState.isApiReady || this.state.isRemoved !== nextState.isRemoved) {
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
return true;
|
|
95
|
-
};
|
|
96
|
-
_proto.componentDidUpdate = function componentDidUpdate(prevProps) {
|
|
97
|
-
var _this3 = this;
|
|
98
|
-
// Prop Keys that could change
|
|
99
|
-
var keys = ['sitekey', 'size', 'theme', 'tabindex', 'languageOverride', 'endpoint'];
|
|
100
|
-
// See if any props changed during component update
|
|
101
|
-
var match = keys.every(function (key) {
|
|
102
|
-
return prevProps[key] === _this3.props[key];
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
// If they have changed, remove current captcha and render a new one
|
|
106
|
-
if (!match) {
|
|
107
|
-
this.removeCaptcha(function () {
|
|
108
|
-
_this3.renderCaptcha();
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
_proto.loadCaptcha = function loadCaptcha() {
|
|
113
|
-
if (this.apiScriptRequested) {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
var _this$props = this.props,
|
|
117
|
-
apihost = _this$props.apihost,
|
|
118
|
-
assethost = _this$props.assethost,
|
|
119
|
-
endpoint = _this$props.endpoint,
|
|
120
|
-
host = _this$props.host,
|
|
121
|
-
imghost = _this$props.imghost,
|
|
122
|
-
hl = _this$props.languageOverride,
|
|
123
|
-
reCaptchaCompat = _this$props.reCaptchaCompat,
|
|
124
|
-
reportapi = _this$props.reportapi,
|
|
125
|
-
sentry = _this$props.sentry,
|
|
126
|
-
custom = _this$props.custom,
|
|
127
|
-
loadAsync = _this$props.loadAsync,
|
|
128
|
-
scriptLocation = _this$props.scriptLocation,
|
|
129
|
-
scriptSource = _this$props.scriptSource,
|
|
130
|
-
secureApi = _this$props.secureApi,
|
|
131
|
-
_this$props$cleanup = _this$props.cleanup,
|
|
132
|
-
cleanup = _this$props$cleanup === void 0 ? true : _this$props$cleanup,
|
|
133
|
-
userJourneys = _this$props.userJourneys;
|
|
134
|
-
var mountParams = {
|
|
135
|
-
render: 'explicit',
|
|
136
|
-
apihost: apihost,
|
|
137
|
-
assethost: assethost,
|
|
138
|
-
endpoint: endpoint,
|
|
139
|
-
hl: hl,
|
|
140
|
-
host: host,
|
|
141
|
-
imghost: imghost,
|
|
142
|
-
recaptchacompat: reCaptchaCompat === false ? 'off' : null,
|
|
143
|
-
reportapi: reportapi,
|
|
144
|
-
sentry: sentry,
|
|
145
|
-
custom: custom,
|
|
146
|
-
loadAsync: loadAsync,
|
|
147
|
-
scriptLocation: scriptLocation,
|
|
148
|
-
scriptSource: scriptSource,
|
|
149
|
-
secureApi: secureApi,
|
|
150
|
-
cleanup: cleanup,
|
|
151
|
-
uj: userJourneys !== undefined ? userJourneys : false
|
|
152
|
-
};
|
|
153
|
-
hCaptchaLoader(mountParams).then(this.handleOnLoad, this.handleError)["catch"](this.handleError);
|
|
154
|
-
this.apiScriptRequested = true;
|
|
155
|
-
};
|
|
156
|
-
_proto.renderCaptcha = function renderCaptcha(onRender) {
|
|
157
|
-
var _this4 = this;
|
|
158
|
-
var onReady = this.props.onReady;
|
|
159
|
-
var isApiReady = this.state.isApiReady;
|
|
160
|
-
var captchaId = this.captchaId;
|
|
161
|
-
|
|
162
|
-
// Prevent calling hCaptcha render on two conditions:
|
|
163
|
-
// • API is not ready
|
|
164
|
-
// • Component has already been mounted
|
|
165
|
-
if (!isApiReady || captchaId) return;
|
|
166
|
-
var renderParams = Object.assign({
|
|
167
|
-
"open-callback": this.handleOpen,
|
|
168
|
-
"close-callback": this.handleClose,
|
|
169
|
-
"error-callback": this.handleError,
|
|
170
|
-
"chalexpired-callback": this.handleChallengeExpired,
|
|
171
|
-
"expired-callback": this.handleExpire,
|
|
172
|
-
"callback": this.handleSubmit
|
|
173
|
-
}, this.props, {
|
|
174
|
-
hl: this.props.hl || this.props.languageOverride,
|
|
175
|
-
languageOverride: undefined
|
|
176
|
-
});
|
|
177
|
-
var hcaptcha = this._hcaptcha;
|
|
178
|
-
//Render hCaptcha widget and provide necessary callbacks - hCaptcha
|
|
179
|
-
var id = hcaptcha.render(this.ref.current, renderParams);
|
|
180
|
-
this.captchaId = id;
|
|
181
|
-
this.setState({
|
|
182
|
-
isRemoved: false
|
|
183
|
-
}, function () {
|
|
184
|
-
onRender && onRender();
|
|
185
|
-
onReady && onReady();
|
|
186
|
-
_this4._onReady && _this4._onReady(id);
|
|
187
|
-
});
|
|
188
|
-
};
|
|
189
|
-
_proto.resetCaptcha = function resetCaptcha() {
|
|
190
|
-
var hcaptcha = this._hcaptcha;
|
|
191
|
-
var captchaId = this.captchaId;
|
|
192
|
-
if (!this.isReady()) {
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// Reset captcha state, removes stored token and unticks checkbox
|
|
197
|
-
hcaptcha.reset(captchaId);
|
|
198
|
-
this._cancelPendingExecute('hcaptcha-reset');
|
|
199
|
-
};
|
|
200
|
-
_proto.removeCaptcha = function removeCaptcha(callback) {
|
|
201
|
-
var _this5 = this;
|
|
202
|
-
var hcaptcha = this._hcaptcha;
|
|
203
|
-
var captchaId = this.captchaId;
|
|
204
|
-
this._cancelPendingExecute('hcaptcha-removed');
|
|
205
|
-
if (!this.isReady()) {
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
this.setState({
|
|
209
|
-
isRemoved: true
|
|
210
|
-
}, function () {
|
|
211
|
-
_this5.captchaId = '';
|
|
212
|
-
hcaptcha.remove(captchaId);
|
|
213
|
-
callback && callback();
|
|
214
|
-
});
|
|
215
|
-
};
|
|
216
|
-
_proto.handleOnLoad = function handleOnLoad() {
|
|
217
|
-
var _this6 = this;
|
|
218
|
-
this.setState({
|
|
219
|
-
isApiReady: true
|
|
220
|
-
}, function () {
|
|
221
|
-
var element = getMountElement(_this6.props.scriptLocation);
|
|
222
|
-
var frame = getFrame(element);
|
|
223
|
-
_this6._hcaptcha = frame.window.hcaptcha;
|
|
224
|
-
|
|
225
|
-
// render captcha and wait for captcha id
|
|
226
|
-
_this6.renderCaptcha(function () {
|
|
227
|
-
// trigger onLoad if it exists
|
|
228
|
-
|
|
229
|
-
var onLoad = _this6.props.onLoad;
|
|
230
|
-
if (onLoad) onLoad();
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
};
|
|
234
|
-
_proto.handleSubmit = function handleSubmit(event) {
|
|
235
|
-
var onVerify = this.props.onVerify;
|
|
236
|
-
var isRemoved = this.state.isRemoved;
|
|
237
|
-
var hcaptcha = this._hcaptcha;
|
|
238
|
-
var captchaId = this.captchaId;
|
|
239
|
-
if (typeof hcaptcha === 'undefined' || isRemoved) return;
|
|
240
|
-
var token = hcaptcha.getResponse(captchaId); //Get response token from hCaptcha widget
|
|
241
|
-
var ekey = hcaptcha.getRespKey(captchaId); //Get current challenge session id from hCaptcha widget
|
|
242
|
-
if (onVerify) onVerify(token, ekey); //Dispatch event to verify user response
|
|
243
|
-
};
|
|
244
|
-
_proto.handleExpire = function handleExpire() {
|
|
245
|
-
var onExpire = this.props.onExpire;
|
|
246
|
-
var hcaptcha = this._hcaptcha;
|
|
247
|
-
var captchaId = this.captchaId;
|
|
248
|
-
if (!this.isReady()) {
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
hcaptcha.reset(captchaId); // If hCaptcha runs into error, reset captcha - hCaptcha
|
|
252
|
-
|
|
253
|
-
if (onExpire) onExpire();
|
|
254
|
-
};
|
|
255
|
-
_proto.handleError = function handleError(event) {
|
|
256
|
-
var onError = this.props.onError;
|
|
257
|
-
var hcaptcha = this._hcaptcha;
|
|
258
|
-
var captchaId = this.captchaId;
|
|
259
|
-
if (this.isReady()) {
|
|
260
|
-
// If hCaptcha runs into error, reset captcha - hCaptcha
|
|
261
|
-
hcaptcha.reset(captchaId);
|
|
262
|
-
}
|
|
263
|
-
if (onError) onError(event);
|
|
264
|
-
};
|
|
265
|
-
_proto.isReady = function isReady() {
|
|
266
|
-
var _this$state = this.state,
|
|
267
|
-
isApiReady = _this$state.isApiReady,
|
|
268
|
-
isRemoved = _this$state.isRemoved;
|
|
269
|
-
return isApiReady && !isRemoved;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* Cancel any pending async execute() promise
|
|
274
|
-
* Called when the component unmounts, errors occur, resets, etc.
|
|
275
|
-
*/;
|
|
276
|
-
_proto._cancelPendingExecute = function _cancelPendingExecute(reason) {
|
|
277
|
-
if (!this._pendingExecute) {
|
|
278
|
-
return;
|
|
279
|
-
}
|
|
280
|
-
var pending = this._pendingExecute;
|
|
281
|
-
this._pendingExecute = null;
|
|
282
|
-
var error = new Error(reason);
|
|
283
|
-
pending.reject(error);
|
|
284
|
-
};
|
|
285
|
-
_proto.handleOpen = function handleOpen() {
|
|
286
|
-
if (!this.isReady() || !this.props.onOpen) {
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
|
-
this.props.onOpen();
|
|
290
|
-
};
|
|
291
|
-
_proto.handleClose = function handleClose() {
|
|
292
|
-
if (!this.isReady() || !this.props.onClose) {
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
|
-
this.props.onClose();
|
|
296
|
-
};
|
|
297
|
-
_proto.handleChallengeExpired = function handleChallengeExpired() {
|
|
298
|
-
if (!this.isReady() || !this.props.onChalExpired) {
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
this.props.onChalExpired();
|
|
302
|
-
};
|
|
303
|
-
_proto.execute = function execute(opts) {
|
|
304
|
-
var _this7 = this;
|
|
305
|
-
if (opts === void 0) {
|
|
306
|
-
opts = null;
|
|
307
|
-
}
|
|
308
|
-
opts = typeof opts === 'object' ? opts : null;
|
|
309
|
-
try {
|
|
310
|
-
var hcaptcha = this._hcaptcha;
|
|
311
|
-
var captchaId = this.captchaId;
|
|
312
|
-
|
|
313
|
-
// Is an async execute and there's already 1 pending, cancel the old one.
|
|
314
|
-
if (opts && opts.async && this._pendingExecute) {
|
|
315
|
-
this._cancelPendingExecute('hcaptcha-execute-replaced');
|
|
316
|
-
}
|
|
317
|
-
if (!this.isReady()) {
|
|
318
|
-
if (opts && opts.async) {
|
|
319
|
-
return new Promise(function (resolve, reject) {
|
|
320
|
-
_this7._pendingExecute = {
|
|
321
|
-
resolve: resolve,
|
|
322
|
-
reject: reject
|
|
323
|
-
};
|
|
324
|
-
_this7._onReady = function (id) {
|
|
325
|
-
if (!_this7._pendingExecute) {
|
|
326
|
-
return;
|
|
327
|
-
}
|
|
328
|
-
try {
|
|
329
|
-
var _result = hcaptcha.execute(id, opts);
|
|
330
|
-
if (_result && typeof _result.then === 'function') {
|
|
331
|
-
_result.then(function (val) {
|
|
332
|
-
_this7._pendingExecute = null;
|
|
333
|
-
resolve(val);
|
|
334
|
-
})["catch"](function (err) {
|
|
335
|
-
_this7._pendingExecute = null;
|
|
336
|
-
reject(err);
|
|
337
|
-
});
|
|
338
|
-
} else {
|
|
339
|
-
_this7._pendingExecute = null;
|
|
340
|
-
reject(new Error('hcaptcha-execute-no-promise'));
|
|
341
|
-
}
|
|
342
|
-
} catch (e) {
|
|
343
|
-
_this7._pendingExecute = null;
|
|
344
|
-
reject(e);
|
|
345
|
-
}
|
|
346
|
-
};
|
|
347
|
-
});
|
|
348
|
-
} else {
|
|
349
|
-
// Non-async: don't return a promise.
|
|
350
|
-
this._onReady = function (id) {
|
|
351
|
-
hcaptcha.execute(id, opts);
|
|
352
|
-
};
|
|
353
|
-
return null;
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
// hCaptcha is ready, execute directly.
|
|
358
|
-
var result = hcaptcha.execute(captchaId, opts);
|
|
359
|
-
|
|
360
|
-
// If it's async execute, track it.
|
|
361
|
-
if (opts && opts.async && result && typeof result.then === 'function') {
|
|
362
|
-
return new Promise(function (resolve, reject) {
|
|
363
|
-
_this7._pendingExecute = {
|
|
364
|
-
resolve: resolve,
|
|
365
|
-
reject: reject
|
|
366
|
-
};
|
|
367
|
-
result.then(function (val) {
|
|
368
|
-
_this7._pendingExecute = null;
|
|
369
|
-
resolve(val);
|
|
370
|
-
})["catch"](function (err) {
|
|
371
|
-
_this7._pendingExecute = null;
|
|
372
|
-
reject(err);
|
|
373
|
-
});
|
|
374
|
-
});
|
|
375
|
-
}
|
|
376
|
-
return result;
|
|
377
|
-
} catch (error) {
|
|
378
|
-
if (opts && opts.async) {
|
|
379
|
-
return Promise.reject(error);
|
|
380
|
-
}
|
|
381
|
-
return null;
|
|
382
|
-
}
|
|
383
|
-
};
|
|
384
|
-
_proto.close = function close() {
|
|
385
|
-
var hcaptcha = this._hcaptcha;
|
|
386
|
-
var captchaId = this.captchaId;
|
|
387
|
-
this._cancelPendingExecute('hcaptcha-closed');
|
|
388
|
-
if (!this.isReady()) {
|
|
389
|
-
return;
|
|
390
|
-
}
|
|
391
|
-
return hcaptcha.close(captchaId);
|
|
392
|
-
};
|
|
393
|
-
_proto.setData = function setData(data) {
|
|
394
|
-
var hcaptcha = this._hcaptcha;
|
|
395
|
-
var captchaId = this.captchaId;
|
|
396
|
-
if (!this.isReady()) {
|
|
397
|
-
return;
|
|
398
|
-
}
|
|
399
|
-
if (data && typeof data !== "object") {
|
|
400
|
-
data = null;
|
|
401
|
-
}
|
|
402
|
-
hcaptcha.setData(captchaId, data);
|
|
403
|
-
};
|
|
404
|
-
_proto.getResponse = function getResponse() {
|
|
405
|
-
var hcaptcha = this._hcaptcha;
|
|
406
|
-
return hcaptcha.getResponse(this.captchaId);
|
|
407
|
-
};
|
|
408
|
-
_proto.getRespKey = function getRespKey() {
|
|
409
|
-
var hcaptcha = this._hcaptcha;
|
|
410
|
-
return hcaptcha.getRespKey(this.captchaId);
|
|
411
|
-
};
|
|
412
|
-
_proto.render = function render() {
|
|
413
|
-
var elementId = this.state.elementId;
|
|
414
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
415
|
-
ref: this.ref,
|
|
416
|
-
id: elementId
|
|
417
|
-
});
|
|
418
|
-
};
|
|
419
|
-
return HCaptcha;
|
|
420
|
-
}(React.Component);
|
|
421
|
-
export default HCaptcha;
|
package/dist/esm/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|
package/dist/esm/utils.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
function getFrame(element) {
|
|
2
|
-
var doc = element && element.ownerDocument || document;
|
|
3
|
-
var win = doc.defaultView || doc.parentWindow || window;
|
|
4
|
-
return {
|
|
5
|
-
document: doc,
|
|
6
|
-
window: win
|
|
7
|
-
};
|
|
8
|
-
}
|
|
9
|
-
function getMountElement(element) {
|
|
10
|
-
return element || document.head;
|
|
11
|
-
}
|
|
12
|
-
export { getFrame, getMountElement };
|
package/dist/hooks/Context.js
DELETED
package/dist/hooks/Provider.js
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.HCaptchaProvider = void 0;
|
|
9
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
12
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
13
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
14
|
-
var _index = _interopRequireDefault(require("../index"));
|
|
15
|
-
var _Context = require("./Context");
|
|
16
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
17
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
|
18
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
19
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
20
|
-
var HCaptchaProvider = exports.HCaptchaProvider = function HCaptchaProvider(_ref) {
|
|
21
|
-
var _ref$sitekey = _ref.sitekey,
|
|
22
|
-
sitekey = _ref$sitekey === void 0 ? null : _ref$sitekey,
|
|
23
|
-
_ref$size = _ref.size,
|
|
24
|
-
size = _ref$size === void 0 ? "normal" : _ref$size,
|
|
25
|
-
_ref$theme = _ref.theme,
|
|
26
|
-
theme = _ref$theme === void 0 ? "light" : _ref$theme,
|
|
27
|
-
_ref$rqdata = _ref.rqdata,
|
|
28
|
-
rqdata = _ref$rqdata === void 0 ? null : _ref$rqdata,
|
|
29
|
-
_ref$languageOverride = _ref.languageOverride,
|
|
30
|
-
languageOverride = _ref$languageOverride === void 0 ? null : _ref$languageOverride,
|
|
31
|
-
onVerify = _ref.onVerify,
|
|
32
|
-
onError = _ref.onError,
|
|
33
|
-
children = _ref.children;
|
|
34
|
-
var hcaptchaRef = (0, _react.useRef)(null);
|
|
35
|
-
var _useState = (0, _react.useState)(false),
|
|
36
|
-
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
37
|
-
ready = _useState2[0],
|
|
38
|
-
setReady = _useState2[1];
|
|
39
|
-
var _useState3 = (0, _react.useState)(null),
|
|
40
|
-
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
|
41
|
-
token = _useState4[0],
|
|
42
|
-
setToken = _useState4[1];
|
|
43
|
-
var _useState5 = (0, _react.useState)(null),
|
|
44
|
-
_useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
|
|
45
|
-
error = _useState6[0],
|
|
46
|
-
setError = _useState6[1];
|
|
47
|
-
var handleReady = function handleReady() {
|
|
48
|
-
setReady(true);
|
|
49
|
-
};
|
|
50
|
-
var handleError = function handleError(error) {
|
|
51
|
-
setError(error);
|
|
52
|
-
onError && onError(error);
|
|
53
|
-
};
|
|
54
|
-
var handleExpire = function handleExpire() {
|
|
55
|
-
setToken(null);
|
|
56
|
-
};
|
|
57
|
-
var handleVerify = function handleVerify(token) {
|
|
58
|
-
setToken(token);
|
|
59
|
-
onVerify && onVerify(token);
|
|
60
|
-
};
|
|
61
|
-
var executeInstance = /*#__PURE__*/function () {
|
|
62
|
-
var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
|
|
63
|
-
var config,
|
|
64
|
-
_yield$hcaptchaRef$cu,
|
|
65
|
-
response,
|
|
66
|
-
_args = arguments;
|
|
67
|
-
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
68
|
-
while (1) switch (_context.prev = _context.next) {
|
|
69
|
-
case 0:
|
|
70
|
-
config = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
|
|
71
|
-
_context.prev = 1;
|
|
72
|
-
if (ready) {
|
|
73
|
-
_context.next = 4;
|
|
74
|
-
break;
|
|
75
|
-
}
|
|
76
|
-
throw new Error("hCaptcha not ready");
|
|
77
|
-
case 4:
|
|
78
|
-
if (token) {
|
|
79
|
-
resetInstance();
|
|
80
|
-
}
|
|
81
|
-
_context.next = 7;
|
|
82
|
-
return hcaptchaRef.current.execute(_objectSpread({
|
|
83
|
-
async: true
|
|
84
|
-
}, config.rqdata ? {
|
|
85
|
-
rqdata: config.rqdata
|
|
86
|
-
} : {}));
|
|
87
|
-
case 7:
|
|
88
|
-
_yield$hcaptchaRef$cu = _context.sent;
|
|
89
|
-
response = _yield$hcaptchaRef$cu.response;
|
|
90
|
-
setToken(response);
|
|
91
|
-
return _context.abrupt("return", response);
|
|
92
|
-
case 13:
|
|
93
|
-
_context.prev = 13;
|
|
94
|
-
_context.t0 = _context["catch"](1);
|
|
95
|
-
setError(_context.t0);
|
|
96
|
-
onError && onError(_context.t0);
|
|
97
|
-
case 17:
|
|
98
|
-
case "end":
|
|
99
|
-
return _context.stop();
|
|
100
|
-
}
|
|
101
|
-
}, _callee, null, [[1, 13]]);
|
|
102
|
-
}));
|
|
103
|
-
return function executeInstance() {
|
|
104
|
-
return _ref2.apply(this, arguments);
|
|
105
|
-
};
|
|
106
|
-
}();
|
|
107
|
-
var resetInstance = function resetInstance() {
|
|
108
|
-
var _hcaptchaRef$current;
|
|
109
|
-
hcaptchaRef === null || hcaptchaRef === void 0 || (_hcaptchaRef$current = hcaptchaRef.current) === null || _hcaptchaRef$current === void 0 || _hcaptchaRef$current.resetCaptcha();
|
|
110
|
-
};
|
|
111
|
-
(0, _react.useEffect)(function () {
|
|
112
|
-
if (rqdata) {
|
|
113
|
-
var _hcaptchaRef$current2;
|
|
114
|
-
hcaptchaRef === null || hcaptchaRef === void 0 || (_hcaptchaRef$current2 = hcaptchaRef.current) === null || _hcaptchaRef$current2 === void 0 || _hcaptchaRef$current2.setData(rqdata);
|
|
115
|
-
}
|
|
116
|
-
}, [rqdata]);
|
|
117
|
-
return /*#__PURE__*/_react["default"].createElement(_Context.HCaptchaContext.Provider, {
|
|
118
|
-
value: {
|
|
119
|
-
sitekey: sitekey,
|
|
120
|
-
error: error,
|
|
121
|
-
token: token,
|
|
122
|
-
ready: ready,
|
|
123
|
-
executeInstance: executeInstance,
|
|
124
|
-
resetInstance: resetInstance
|
|
125
|
-
}
|
|
126
|
-
}, children, /*#__PURE__*/_react["default"].createElement(_index["default"], {
|
|
127
|
-
sitekey: sitekey,
|
|
128
|
-
size: size,
|
|
129
|
-
theme: theme,
|
|
130
|
-
languageOverride: languageOverride,
|
|
131
|
-
onReady: handleReady,
|
|
132
|
-
onVerify: handleVerify,
|
|
133
|
-
onExpire: handleExpire,
|
|
134
|
-
onError: handleError,
|
|
135
|
-
ref: hcaptchaRef
|
|
136
|
-
}));
|
|
137
|
-
};
|
package/dist/hooks/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "HCaptchaProvider", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function get() {
|
|
9
|
-
return _Provider.HCaptchaProvider;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "useHCaptcha", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function get() {
|
|
15
|
-
return _useHCaptcha.useHCaptcha;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
var _useHCaptcha = require("./useHCaptcha");
|
|
19
|
-
var _Provider = require("./Provider");
|