@hcaptcha/react-hcaptcha 1.4.2 → 1.4.3

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 CHANGED
@@ -54,6 +54,7 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
54
54
  _this.removeCaptcha = _this.removeCaptcha.bind(_assertThisInitialized(_this));
55
55
  _this.isReady = _this.isReady.bind(_assertThisInitialized(_this)); // Event Handlers
56
56
 
57
+ _this.loadCaptcha = _this.loadCaptcha.bind(_assertThisInitialized(_this));
57
58
  _this.handleOnLoad = _this.handleOnLoad.bind(_assertThisInitialized(_this));
58
59
  _this.handleSubmit = _this.handleSubmit.bind(_assertThisInitialized(_this));
59
60
  _this.handleExpire = _this.handleExpire.bind(_assertThisInitialized(_this));
@@ -63,6 +64,7 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
63
64
  _this.handleChallengeExpired = _this.handleChallengeExpired.bind(_assertThisInitialized(_this));
64
65
  var isApiReady = typeof hcaptcha !== 'undefined';
65
66
  _this.ref = /*#__PURE__*/React.createRef();
67
+ _this.apiScriptRequested = false;
66
68
  _this.state = {
67
69
  isApiReady: isApiReady,
68
70
  isRemoved: false,
@@ -76,38 +78,19 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
76
78
 
77
79
  _proto.componentDidMount = function componentDidMount() {
78
80
  // Once captcha is mounted intialize hCaptcha - hCaptcha
79
- var _this$props = this.props,
80
- apihost = _this$props.apihost,
81
- assethost = _this$props.assethost,
82
- endpoint = _this$props.endpoint,
83
- host = _this$props.host,
84
- imghost = _this$props.imghost,
85
- hl = _this$props.languageOverride,
86
- reCaptchaCompat = _this$props.reCaptchaCompat,
87
- reportapi = _this$props.reportapi,
88
- sentry = _this$props.sentry,
89
- custom = _this$props.custom;
90
81
  var isApiReady = this.state.isApiReady;
82
+ /*
83
+ * Check if hCaptcha has already been loaded,
84
+ * If Yes, render the captcha
85
+ * If No, create script tag and wait to render the captcha
86
+ */
91
87
 
92
- if (!isApiReady) {
93
- // Check if hCaptcha has already been loaded, if not create script tag and wait to render captcha
94
- var mountParams = {
95
- apihost: apihost,
96
- assethost: assethost,
97
- endpoint: endpoint,
98
- hl: hl,
99
- host: host,
100
- imghost: imghost,
101
- recaptchacompat: reCaptchaCompat === false ? "off" : null,
102
- reportapi: reportapi,
103
- sentry: sentry,
104
- custom: custom
105
- }; // Only create the script tag once, use a global promise to track
106
-
107
- mountCaptchaScript(mountParams).then(this.handleOnLoad)["catch"](this.handleError);
108
- } else {
88
+ if (isApiReady) {
109
89
  this.renderCaptcha();
90
+ return;
110
91
  }
92
+
93
+ this.loadCaptcha();
111
94
  };
112
95
 
113
96
  _proto.componentWillUnmount = function componentWillUnmount() {
@@ -148,6 +131,38 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
148
131
  }
149
132
  };
150
133
 
134
+ _proto.loadCaptcha = function loadCaptcha() {
135
+ if (this.apiScriptRequested) {
136
+ return;
137
+ }
138
+
139
+ var _this$props = this.props,
140
+ apihost = _this$props.apihost,
141
+ assethost = _this$props.assethost,
142
+ endpoint = _this$props.endpoint,
143
+ host = _this$props.host,
144
+ imghost = _this$props.imghost,
145
+ hl = _this$props.languageOverride,
146
+ reCaptchaCompat = _this$props.reCaptchaCompat,
147
+ reportapi = _this$props.reportapi,
148
+ sentry = _this$props.sentry,
149
+ custom = _this$props.custom;
150
+ var mountParams = {
151
+ apihost: apihost,
152
+ assethost: assethost,
153
+ endpoint: endpoint,
154
+ hl: hl,
155
+ host: host,
156
+ imghost: imghost,
157
+ recaptchacompat: reCaptchaCompat === false ? "off" : null,
158
+ reportapi: reportapi,
159
+ sentry: sentry,
160
+ custom: custom
161
+ };
162
+ mountCaptchaScript(mountParams).then(this.handleOnLoad)["catch"](this.handleError);
163
+ this.apiScriptRequested = true;
164
+ };
165
+
151
166
  _proto.renderCaptcha = function renderCaptcha(onReady) {
152
167
  var isApiReady = this.state.isApiReady;
153
168
  if (!isApiReady) return;
package/dist/index.js CHANGED
@@ -84,6 +84,7 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
84
84
  _this.removeCaptcha = _this.removeCaptcha.bind((0, _assertThisInitialized2["default"])(_this));
85
85
  _this.isReady = _this.isReady.bind((0, _assertThisInitialized2["default"])(_this)); // Event Handlers
86
86
 
87
+ _this.loadCaptcha = _this.loadCaptcha.bind((0, _assertThisInitialized2["default"])(_this));
87
88
  _this.handleOnLoad = _this.handleOnLoad.bind((0, _assertThisInitialized2["default"])(_this));
88
89
  _this.handleSubmit = _this.handleSubmit.bind((0, _assertThisInitialized2["default"])(_this));
89
90
  _this.handleExpire = _this.handleExpire.bind((0, _assertThisInitialized2["default"])(_this));
@@ -93,6 +94,7 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
93
94
  _this.handleChallengeExpired = _this.handleChallengeExpired.bind((0, _assertThisInitialized2["default"])(_this));
94
95
  var isApiReady = typeof hcaptcha !== 'undefined';
95
96
  _this.ref = /*#__PURE__*/React.createRef();
97
+ _this.apiScriptRequested = false;
96
98
  _this.state = {
97
99
  isApiReady: isApiReady,
98
100
  isRemoved: false,
@@ -106,38 +108,19 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
106
108
  key: "componentDidMount",
107
109
  value: function componentDidMount() {
108
110
  // Once captcha is mounted intialize hCaptcha - hCaptcha
109
- var _this$props = this.props,
110
- apihost = _this$props.apihost,
111
- assethost = _this$props.assethost,
112
- endpoint = _this$props.endpoint,
113
- host = _this$props.host,
114
- imghost = _this$props.imghost,
115
- hl = _this$props.languageOverride,
116
- reCaptchaCompat = _this$props.reCaptchaCompat,
117
- reportapi = _this$props.reportapi,
118
- sentry = _this$props.sentry,
119
- custom = _this$props.custom;
120
111
  var isApiReady = this.state.isApiReady;
112
+ /*
113
+ * Check if hCaptcha has already been loaded,
114
+ * If Yes, render the captcha
115
+ * If No, create script tag and wait to render the captcha
116
+ */
121
117
 
122
- if (!isApiReady) {
123
- // Check if hCaptcha has already been loaded, if not create script tag and wait to render captcha
124
- var mountParams = {
125
- apihost: apihost,
126
- assethost: assethost,
127
- endpoint: endpoint,
128
- hl: hl,
129
- host: host,
130
- imghost: imghost,
131
- recaptchacompat: reCaptchaCompat === false ? "off" : null,
132
- reportapi: reportapi,
133
- sentry: sentry,
134
- custom: custom
135
- }; // Only create the script tag once, use a global promise to track
136
-
137
- mountCaptchaScript(mountParams).then(this.handleOnLoad)["catch"](this.handleError);
138
- } else {
118
+ if (isApiReady) {
139
119
  this.renderCaptcha();
120
+ return;
140
121
  }
122
+
123
+ this.loadCaptcha();
141
124
  }
142
125
  }, {
143
126
  key: "componentWillUnmount",
@@ -180,6 +163,39 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
180
163
  });
181
164
  }
182
165
  }
166
+ }, {
167
+ key: "loadCaptcha",
168
+ value: function loadCaptcha() {
169
+ if (this.apiScriptRequested) {
170
+ return;
171
+ }
172
+
173
+ var _this$props = this.props,
174
+ apihost = _this$props.apihost,
175
+ assethost = _this$props.assethost,
176
+ endpoint = _this$props.endpoint,
177
+ host = _this$props.host,
178
+ imghost = _this$props.imghost,
179
+ hl = _this$props.languageOverride,
180
+ reCaptchaCompat = _this$props.reCaptchaCompat,
181
+ reportapi = _this$props.reportapi,
182
+ sentry = _this$props.sentry,
183
+ custom = _this$props.custom;
184
+ var mountParams = {
185
+ apihost: apihost,
186
+ assethost: assethost,
187
+ endpoint: endpoint,
188
+ hl: hl,
189
+ host: host,
190
+ imghost: imghost,
191
+ recaptchacompat: reCaptchaCompat === false ? "off" : null,
192
+ reportapi: reportapi,
193
+ sentry: sentry,
194
+ custom: custom
195
+ };
196
+ mountCaptchaScript(mountParams).then(this.handleOnLoad)["catch"](this.handleError);
197
+ this.apiScriptRequested = true;
198
+ }
183
199
  }, {
184
200
  key: "renderCaptcha",
185
201
  value: function renderCaptcha(onReady) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hcaptcha/react-hcaptcha",
3
- "version": "1.4.2",
3
+ "version": "1.4.3",
4
4
  "types": "types/index.d.ts",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/esm/index.js",
package/src/index.js CHANGED
@@ -50,6 +50,7 @@ class HCaptcha extends React.Component {
50
50
  this.isReady = this.isReady.bind(this);
51
51
 
52
52
  // Event Handlers
53
+ this.loadCaptcha = this.loadCaptcha.bind(this);
53
54
  this.handleOnLoad = this.handleOnLoad.bind(this);
54
55
  this.handleSubmit = this.handleSubmit.bind(this);
55
56
  this.handleExpire = this.handleExpire.bind(this);
@@ -61,6 +62,7 @@ class HCaptcha extends React.Component {
61
62
  const isApiReady = typeof hcaptcha !== 'undefined';
62
63
 
63
64
  this.ref = React.createRef();
65
+ this.apiScriptRequested = false;
64
66
 
65
67
  this.state = {
66
68
  isApiReady,
@@ -71,42 +73,32 @@ class HCaptcha extends React.Component {
71
73
  }
72
74
 
73
75
  componentDidMount () { // Once captcha is mounted intialize hCaptcha - hCaptcha
74
- const { apihost, assethost, endpoint, host, imghost, languageOverride:hl, reCaptchaCompat, reportapi, sentry, custom } = this.props;
75
76
  const { isApiReady } = this.state;
76
77
 
77
- if (!isApiReady) { // Check if hCaptcha has already been loaded, if not create script tag and wait to render captcha
78
- const mountParams = {
79
- apihost,
80
- assethost,
81
- endpoint,
82
- hl,
83
- host,
84
- imghost,
85
- recaptchacompat: reCaptchaCompat === false? "off" : null,
86
- reportapi,
87
- sentry,
88
- custom
89
- };
90
-
91
- // Only create the script tag once, use a global promise to track
92
- mountCaptchaScript(mountParams)
93
- .then(this.handleOnLoad)
94
- .catch(this.handleError);
95
- } else {
78
+ /*
79
+ * Check if hCaptcha has already been loaded,
80
+ * If Yes, render the captcha
81
+ * If No, create script tag and wait to render the captcha
82
+ */
83
+ if (isApiReady) {
96
84
  this.renderCaptcha();
85
+
86
+ return;
97
87
  }
88
+
89
+ this.loadCaptcha();
98
90
  }
99
91
 
100
92
  componentWillUnmount() {
101
- const { captchaId } = this.state;
93
+ const { captchaId } = this.state;
102
94
 
103
- if (!this.isReady()) {
104
- return;
105
- }
95
+ if (!this.isReady()) {
96
+ return;
97
+ }
106
98
 
107
- // Reset any stored variables / timers when unmounting
108
- hcaptcha.reset(captchaId);
109
- hcaptcha.remove(captchaId);
99
+ // Reset any stored variables / timers when unmounting
100
+ hcaptcha.reset(captchaId);
101
+ hcaptcha.remove(captchaId);
110
102
  }
111
103
 
112
104
  shouldComponentUpdate(nextProps, nextState) {
@@ -132,6 +124,42 @@ class HCaptcha extends React.Component {
132
124
  }
133
125
  }
134
126
 
127
+ loadCaptcha() {
128
+ if (this.apiScriptRequested) {
129
+ return;
130
+ }
131
+
132
+ const {
133
+ apihost,
134
+ assethost,
135
+ endpoint,
136
+ host,
137
+ imghost,
138
+ languageOverride: hl,
139
+ reCaptchaCompat,
140
+ reportapi,
141
+ sentry,
142
+ custom
143
+ } = this.props;
144
+ const mountParams = {
145
+ apihost,
146
+ assethost,
147
+ endpoint,
148
+ hl,
149
+ host,
150
+ imghost,
151
+ recaptchacompat: reCaptchaCompat === false? "off" : null,
152
+ reportapi,
153
+ sentry,
154
+ custom
155
+ };
156
+
157
+ mountCaptchaScript(mountParams)
158
+ .then(this.handleOnLoad)
159
+ .catch(this.handleError);
160
+ this.apiScriptRequested = true;
161
+ }
162
+
135
163
  renderCaptcha(onReady) {
136
164
  const { isApiReady } = this.state;
137
165
  if (!isApiReady) return;