@hcaptcha/react-hcaptcha 1.2.0 → 1.4.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.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
- 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); }; }
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 React = require('react');
28
+ var _utils = require("./utils.js");
24
29
 
25
- var _require = require("./utils.js"),
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 (!apiScriptRequested) {
108
- // Only create the script tag once, use a global variable to track
109
- mountCaptchaScript({
110
- apihost: apihost,
111
- assethost: assethost,
112
- endpoint: endpoint,
113
- hl: hl,
114
- host: host,
115
- imghost: imghost,
116
- recaptchacompat: reCaptchaCompat === false ? "off" : null,
117
- reportapi: reportapi,
118
- sentry: sentry,
119
- custom: custom
120
- });
121
- } // Add onload callback to global onload listeners
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
- module.exports = HCaptcha;
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.2.0",
3
+ "version": "1.4.0",
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/index.d.ts"
10
+ "types"
10
11
  ],
11
12
  "description": "A React library for hCaptcha",
12
13
  "scripts": {
@@ -14,7 +15,9 @@
14
15
  "test": "jest",
15
16
  "watch": "babel src -d dist --copy-files --watch",
16
17
  "transpile": "babel src -d dist --copy-files",
17
- "build": "npm run transpile",
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",
18
21
  "prepublishOnly": "npm run transpile"
19
22
  },
20
23
  "peerDependencies": {
@@ -36,12 +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"
52
+ },
53
+ "dependencies": {
54
+ "@babel/runtime": "^7.17.9",
55
+ "@types/react": "^18.0.0"
46
56
  }
47
57
  }
package/src/index.js CHANGED
@@ -1,5 +1,5 @@
1
- const React = require('react');
2
- const { generateQuery } = require("./utils.js");
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
- if (!apiScriptRequested) {
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
- module.exports = HCaptcha;
297
+ export default HCaptcha;
package/src/utils.js CHANGED
@@ -6,6 +6,4 @@ function generateQuery(params) {
6
6
  }).join("&");
7
7
  };
8
8
 
9
- module.exports = {
10
- generateQuery
11
- };
9
+ export { generateQuery };