@captchafox/react 1.0.0 → 1.0.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/index.js +8 -6
- package/dist/index.mjs +9 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -76,7 +76,7 @@ var import_react = require("react");
|
|
|
76
76
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
77
77
|
var CaptchaFox = (0, import_react.forwardRef)(
|
|
78
78
|
({ sitekey, lng, mode, className, onError, onVerify, onLoad, onFail, onClose }, ref) => {
|
|
79
|
-
const containerRef = (0, import_react.
|
|
79
|
+
const [containerRef, setContainerRef] = (0, import_react.useState)();
|
|
80
80
|
const [widgetId, setWidgetId] = (0, import_react.useState)();
|
|
81
81
|
const firstRendered = (0, import_react.useRef)(false);
|
|
82
82
|
(0, import_react.useImperativeHandle)(
|
|
@@ -116,11 +116,11 @@ var CaptchaFox = (0, import_react.forwardRef)(
|
|
|
116
116
|
[widgetId]
|
|
117
117
|
);
|
|
118
118
|
const renderCaptcha = () => __async(void 0, null, function* () {
|
|
119
|
-
var _a, _b, _c
|
|
119
|
+
var _a, _b, _c;
|
|
120
120
|
(_a = window.captchafox) == null ? void 0 : _a.remove(widgetId);
|
|
121
|
-
if (!containerRef
|
|
121
|
+
if (!containerRef || ((_b = containerRef == null ? void 0 : containerRef.children) == null ? void 0 : _b.length) === 1)
|
|
122
122
|
return;
|
|
123
|
-
const newWidgetId = yield (
|
|
123
|
+
const newWidgetId = yield (_c = window.captchafox) == null ? void 0 : _c.render(containerRef, {
|
|
124
124
|
lng,
|
|
125
125
|
sitekey,
|
|
126
126
|
mode,
|
|
@@ -133,6 +133,8 @@ var CaptchaFox = (0, import_react.forwardRef)(
|
|
|
133
133
|
onLoad == null ? void 0 : onLoad();
|
|
134
134
|
});
|
|
135
135
|
(0, import_react.useEffect)(() => {
|
|
136
|
+
if (!containerRef)
|
|
137
|
+
return;
|
|
136
138
|
if (firstRendered.current) {
|
|
137
139
|
if (isApiReady()) {
|
|
138
140
|
renderCaptcha();
|
|
@@ -148,8 +150,8 @@ var CaptchaFox = (0, import_react.forwardRef)(
|
|
|
148
150
|
console.error("[CaptchaFox] Could not load script:", err);
|
|
149
151
|
});
|
|
150
152
|
}
|
|
151
|
-
}, [sitekey, lng, mode]);
|
|
152
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref:
|
|
153
|
+
}, [containerRef, sitekey, lng, mode]);
|
|
154
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref: setContainerRef, id: widgetId, className });
|
|
153
155
|
}
|
|
154
156
|
);
|
|
155
157
|
CaptchaFox.displayName = "CaptchaFox";
|
package/dist/index.mjs
CHANGED
|
@@ -46,11 +46,11 @@ function loadCaptchaScript() {
|
|
|
46
46
|
var isApiReady = () => typeof (window == null ? void 0 : window.captchafox) !== "undefined";
|
|
47
47
|
|
|
48
48
|
// src/CaptchaFox.tsx
|
|
49
|
-
import {
|
|
49
|
+
import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from "react";
|
|
50
50
|
import { jsx } from "react/jsx-runtime";
|
|
51
51
|
var CaptchaFox = forwardRef(
|
|
52
52
|
({ sitekey, lng, mode, className, onError, onVerify, onLoad, onFail, onClose }, ref) => {
|
|
53
|
-
const containerRef =
|
|
53
|
+
const [containerRef, setContainerRef] = useState();
|
|
54
54
|
const [widgetId, setWidgetId] = useState();
|
|
55
55
|
const firstRendered = useRef(false);
|
|
56
56
|
useImperativeHandle(
|
|
@@ -90,11 +90,11 @@ var CaptchaFox = forwardRef(
|
|
|
90
90
|
[widgetId]
|
|
91
91
|
);
|
|
92
92
|
const renderCaptcha = () => __async(void 0, null, function* () {
|
|
93
|
-
var _a, _b, _c
|
|
93
|
+
var _a, _b, _c;
|
|
94
94
|
(_a = window.captchafox) == null ? void 0 : _a.remove(widgetId);
|
|
95
|
-
if (!containerRef
|
|
95
|
+
if (!containerRef || ((_b = containerRef == null ? void 0 : containerRef.children) == null ? void 0 : _b.length) === 1)
|
|
96
96
|
return;
|
|
97
|
-
const newWidgetId = yield (
|
|
97
|
+
const newWidgetId = yield (_c = window.captchafox) == null ? void 0 : _c.render(containerRef, {
|
|
98
98
|
lng,
|
|
99
99
|
sitekey,
|
|
100
100
|
mode,
|
|
@@ -107,6 +107,8 @@ var CaptchaFox = forwardRef(
|
|
|
107
107
|
onLoad == null ? void 0 : onLoad();
|
|
108
108
|
});
|
|
109
109
|
useEffect(() => {
|
|
110
|
+
if (!containerRef)
|
|
111
|
+
return;
|
|
110
112
|
if (firstRendered.current) {
|
|
111
113
|
if (isApiReady()) {
|
|
112
114
|
renderCaptcha();
|
|
@@ -122,8 +124,8 @@ var CaptchaFox = forwardRef(
|
|
|
122
124
|
console.error("[CaptchaFox] Could not load script:", err);
|
|
123
125
|
});
|
|
124
126
|
}
|
|
125
|
-
}, [sitekey, lng, mode]);
|
|
126
|
-
return /* @__PURE__ */ jsx("div", { ref:
|
|
127
|
+
}, [containerRef, sitekey, lng, mode]);
|
|
128
|
+
return /* @__PURE__ */ jsx("div", { ref: setContainerRef, id: widgetId, className });
|
|
127
129
|
}
|
|
128
130
|
);
|
|
129
131
|
CaptchaFox.displayName = "CaptchaFox";
|