@dfds-ui/hooks 1.1.15 → 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/cjs/index.js +10 -18
- package/cjs/useDimensions.js +6 -24
- package/cjs/useForwardedRef.js +0 -7
- package/cjs/useGoogleReCaptchaV3.d.ts +1 -1
- package/cjs/useGoogleReCaptchaV3.js +4 -23
- package/cjs/useOffline.js +3 -16
- package/cjs/useResizeObserver.js +0 -3
- package/cjs/useScript.js +11 -32
- package/package.json +5 -5
- package/useDimensions.js +8 -25
- package/useForwardedRef.js +0 -3
- package/useGoogleReCaptchaV3.d.ts +1 -1
- package/useGoogleReCaptchaV3.js +9 -28
- package/useOffline.js +3 -15
- package/useScript.js +11 -39
package/cjs/index.js
CHANGED
|
@@ -10,16 +10,10 @@ var _exportNames = {
|
|
|
10
10
|
useOffline: true,
|
|
11
11
|
useDimensions: true
|
|
12
12
|
};
|
|
13
|
-
Object.defineProperty(exports, "
|
|
14
|
-
enumerable: true,
|
|
15
|
-
get: function get() {
|
|
16
|
-
return _useScript.default;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
Object.defineProperty(exports, "useResizeObserver", {
|
|
13
|
+
Object.defineProperty(exports, "useDimensions", {
|
|
20
14
|
enumerable: true,
|
|
21
15
|
get: function get() {
|
|
22
|
-
return
|
|
16
|
+
return _useDimensions.default;
|
|
23
17
|
}
|
|
24
18
|
});
|
|
25
19
|
Object.defineProperty(exports, "useForwardedRef", {
|
|
@@ -34,25 +28,24 @@ Object.defineProperty(exports, "useOffline", {
|
|
|
34
28
|
return _useOffline.default;
|
|
35
29
|
}
|
|
36
30
|
});
|
|
37
|
-
Object.defineProperty(exports, "
|
|
31
|
+
Object.defineProperty(exports, "useResizeObserver", {
|
|
38
32
|
enumerable: true,
|
|
39
33
|
get: function get() {
|
|
40
|
-
return
|
|
34
|
+
return _useResizeObserver.default;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(exports, "useScript", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get: function get() {
|
|
40
|
+
return _useScript.default;
|
|
41
41
|
}
|
|
42
42
|
});
|
|
43
|
-
|
|
44
43
|
var _useScript = _interopRequireDefault(require("./useScript"));
|
|
45
|
-
|
|
46
44
|
var _useResizeObserver = _interopRequireDefault(require("./useResizeObserver"));
|
|
47
|
-
|
|
48
45
|
var _useForwardedRef = _interopRequireDefault(require("./useForwardedRef"));
|
|
49
|
-
|
|
50
46
|
var _useOffline = _interopRequireDefault(require("./useOffline"));
|
|
51
|
-
|
|
52
47
|
var _useDimensions = _interopRequireDefault(require("./useDimensions"));
|
|
53
|
-
|
|
54
48
|
var _useGoogleReCaptchaV = require("./useGoogleReCaptchaV3");
|
|
55
|
-
|
|
56
49
|
Object.keys(_useGoogleReCaptchaV).forEach(function (key) {
|
|
57
50
|
if (key === "default" || key === "__esModule") return;
|
|
58
51
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -64,5 +57,4 @@ Object.keys(_useGoogleReCaptchaV).forEach(function (key) {
|
|
|
64
57
|
}
|
|
65
58
|
});
|
|
66
59
|
});
|
|
67
|
-
|
|
68
60
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
package/cjs/useDimensions.js
CHANGED
|
@@ -4,21 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = require("react");
|
|
9
|
-
|
|
10
8
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
11
|
-
|
|
12
9
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
13
|
-
|
|
14
10
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
15
|
-
|
|
16
11
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
17
|
-
|
|
18
12
|
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
19
|
-
|
|
20
13
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
21
|
-
|
|
22
14
|
const EMPTY_DIMENSION_OBJECT = {
|
|
23
15
|
width: 0,
|
|
24
16
|
height: 0,
|
|
@@ -29,14 +21,11 @@ const EMPTY_DIMENSION_OBJECT = {
|
|
|
29
21
|
right: 0,
|
|
30
22
|
bottom: 0
|
|
31
23
|
};
|
|
32
|
-
|
|
33
24
|
function getDimensionObject(node) {
|
|
34
25
|
const rect = node.getBoundingClientRect();
|
|
35
26
|
/** @ts-ignore */
|
|
36
|
-
|
|
37
27
|
const left = 'x' in rect ? rect.x : rect.left;
|
|
38
28
|
/** @ts-ignore */
|
|
39
|
-
|
|
40
29
|
const top = 'y' in rect ? rect.y : rect.top;
|
|
41
30
|
return {
|
|
42
31
|
width: rect.width,
|
|
@@ -49,20 +38,17 @@ function getDimensionObject(node) {
|
|
|
49
38
|
bottom: rect.bottom
|
|
50
39
|
};
|
|
51
40
|
}
|
|
52
|
-
|
|
53
41
|
function useDimensions({
|
|
54
42
|
liveMeasure = true
|
|
55
43
|
} = {}) {
|
|
56
44
|
const _useState = (0, _react.useState)(EMPTY_DIMENSION_OBJECT),
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
45
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
46
|
+
dimensions = _useState2[0],
|
|
47
|
+
setDimensions = _useState2[1];
|
|
61
48
|
const _useState3 = (0, _react.useState)(null),
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
49
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
50
|
+
node = _useState4[0],
|
|
51
|
+
setNode = _useState4[1];
|
|
66
52
|
const ref = (0, _react.useCallback)(node => {
|
|
67
53
|
setNode(node);
|
|
68
54
|
}, []);
|
|
@@ -70,9 +56,7 @@ function useDimensions({
|
|
|
70
56
|
useIsomorphicLayoutEffect(() => {
|
|
71
57
|
if (node) {
|
|
72
58
|
const measure = () => window.requestAnimationFrame(() => setDimensions(getDimensionObject(node)));
|
|
73
|
-
|
|
74
59
|
measure();
|
|
75
|
-
|
|
76
60
|
if (liveMeasure) {
|
|
77
61
|
window.addEventListener('resize', measure);
|
|
78
62
|
window.addEventListener('scroll', measure);
|
|
@@ -82,13 +66,11 @@ function useDimensions({
|
|
|
82
66
|
};
|
|
83
67
|
}
|
|
84
68
|
}
|
|
85
|
-
|
|
86
69
|
return () => {
|
|
87
70
|
/* no-op */
|
|
88
71
|
};
|
|
89
72
|
}, [liveMeasure, node]);
|
|
90
73
|
return [ref, dimensions, node];
|
|
91
74
|
}
|
|
92
|
-
|
|
93
75
|
var _default = useDimensions;
|
|
94
76
|
exports.default = _default;
|
package/cjs/useForwardedRef.js
CHANGED
|
@@ -4,28 +4,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
|
|
10
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
9
|
function useForwardedRef(forwardedRef) {
|
|
13
10
|
const innerRef = _react.default.useRef(null);
|
|
14
|
-
|
|
15
11
|
_react.default.useEffect(() => {
|
|
16
12
|
if (!forwardedRef) {
|
|
17
13
|
return;
|
|
18
14
|
}
|
|
19
|
-
|
|
20
15
|
if (typeof forwardedRef === 'function') {
|
|
21
16
|
forwardedRef(innerRef.current);
|
|
22
17
|
} else {
|
|
23
18
|
forwardedRef.current = innerRef.current;
|
|
24
19
|
}
|
|
25
20
|
}, [forwardedRef]);
|
|
26
|
-
|
|
27
21
|
return innerRef;
|
|
28
22
|
}
|
|
29
|
-
|
|
30
23
|
var _default = useForwardedRef;
|
|
31
24
|
exports.default = _default;
|
|
@@ -15,4 +15,4 @@ export declare type GoogleReCaptchaV3Options = {
|
|
|
15
15
|
*/
|
|
16
16
|
disabled?: boolean;
|
|
17
17
|
};
|
|
18
|
-
export declare function useGoogleReCaptchaV3({ siteKey, disabled }: GoogleReCaptchaV3Options): (action?: string
|
|
18
|
+
export declare function useGoogleReCaptchaV3({ siteKey, disabled }: GoogleReCaptchaV3Options): (action?: string) => Promise<string | undefined>;
|
|
@@ -4,45 +4,31 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.useGoogleReCaptchaV3 = useGoogleReCaptchaV3;
|
|
7
|
-
|
|
8
7
|
var _react = require("react");
|
|
9
|
-
|
|
10
8
|
var _useScript3 = _interopRequireDefault(require("./useScript"));
|
|
11
|
-
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
10
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
15
|
-
|
|
16
11
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
17
|
-
|
|
18
12
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
19
|
-
|
|
20
13
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
21
|
-
|
|
22
14
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
23
|
-
|
|
24
15
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
25
|
-
|
|
26
16
|
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
27
|
-
|
|
28
17
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
29
|
-
|
|
30
18
|
function useGoogleReCaptchaV3({
|
|
31
19
|
siteKey,
|
|
32
20
|
disabled = false
|
|
33
21
|
}) {
|
|
34
22
|
// Load ReCaptcha script.
|
|
35
23
|
const _useScript = (0, _useScript3.default)(`https://www.google.com/recaptcha/api.js?render=${siteKey}`, disabled),
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
24
|
+
_useScript2 = _slicedToArray(_useScript, 2),
|
|
25
|
+
loaded = _useScript2[0],
|
|
26
|
+
error = _useScript2[1];
|
|
40
27
|
(0, _react.useEffect)(() => {
|
|
41
28
|
if (loaded && !disabled) {
|
|
42
29
|
// eslint-disable-next-line no-console
|
|
43
30
|
console.log('Google ReCaptcha script loaded!');
|
|
44
31
|
}
|
|
45
|
-
|
|
46
32
|
if (error) throw new Error('Google ReCaptcha script failed to load');
|
|
47
33
|
}, [loaded, error, disabled]);
|
|
48
34
|
const executeReCaptcha = (0, _react.useCallback)( /*#__PURE__*/function () {
|
|
@@ -50,18 +36,14 @@ function useGoogleReCaptchaV3({
|
|
|
50
36
|
if (!window) {
|
|
51
37
|
throw new Error('ERROR: NOT A WEB BROWSER');
|
|
52
38
|
}
|
|
53
|
-
|
|
54
39
|
if (disabled) {
|
|
55
40
|
return Promise.resolve(undefined);
|
|
56
41
|
}
|
|
57
|
-
|
|
58
42
|
const _window = window,
|
|
59
|
-
|
|
60
|
-
|
|
43
|
+
grecaptcha = _window.grecaptcha;
|
|
61
44
|
if (!grecaptcha) {
|
|
62
45
|
throw new Error('ERROR: SCRIPT NOT AVAILABLE');
|
|
63
46
|
}
|
|
64
|
-
|
|
65
47
|
return new Promise(resolve => {
|
|
66
48
|
// Invoke the ReCaptcha check.
|
|
67
49
|
grecaptcha.ready(() => {
|
|
@@ -73,7 +55,6 @@ function useGoogleReCaptchaV3({
|
|
|
73
55
|
});
|
|
74
56
|
});
|
|
75
57
|
});
|
|
76
|
-
|
|
77
58
|
return function (_x) {
|
|
78
59
|
return _ref.apply(this, arguments);
|
|
79
60
|
};
|
package/cjs/useOffline.js
CHANGED
|
@@ -4,33 +4,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = require("react");
|
|
9
|
-
|
|
10
8
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
11
|
-
|
|
12
9
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
13
|
-
|
|
14
10
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
15
|
-
|
|
16
11
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
17
|
-
|
|
18
12
|
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
19
|
-
|
|
20
13
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
21
|
-
|
|
22
14
|
const getOnLineStatus = () => typeof window !== 'undefined' && typeof navigator !== 'undefined' && typeof navigator.onLine === 'boolean' ? navigator.onLine : true;
|
|
23
|
-
|
|
24
15
|
const useOffline = () => {
|
|
25
16
|
const _useState = (0, _react.useState)(getOnLineStatus()),
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
17
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
18
|
+
status = _useState2[0],
|
|
19
|
+
setStatus = _useState2[1];
|
|
30
20
|
const setOnline = () => setStatus(true);
|
|
31
|
-
|
|
32
21
|
const setOffline = () => setStatus(false);
|
|
33
|
-
|
|
34
22
|
(0, _react.useEffect)(() => {
|
|
35
23
|
window.addEventListener('online', setOnline);
|
|
36
24
|
window.addEventListener('offline', setOffline);
|
|
@@ -44,6 +32,5 @@ const useOffline = () => {
|
|
|
44
32
|
isOffline: !status
|
|
45
33
|
};
|
|
46
34
|
};
|
|
47
|
-
|
|
48
35
|
var _default = useOffline;
|
|
49
36
|
exports.default = _default;
|
package/cjs/useResizeObserver.js
CHANGED
|
@@ -4,10 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _polyfilled = _interopRequireDefault(require("use-resize-observer/polyfilled"));
|
|
9
|
-
|
|
10
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
9
|
var _default = _polyfilled.default;
|
|
13
10
|
exports.default = _default;
|
package/cjs/useScript.js
CHANGED
|
@@ -4,23 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = require("react");
|
|
9
|
-
|
|
10
8
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
11
|
-
|
|
12
9
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
13
|
-
|
|
14
10
|
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
15
|
-
|
|
16
11
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
17
|
-
|
|
18
12
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
19
|
-
|
|
20
13
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
21
|
-
|
|
22
14
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
23
|
-
|
|
24
15
|
class Script {
|
|
25
16
|
constructor(src) {
|
|
26
17
|
this.state = 'PENDING';
|
|
@@ -28,35 +19,29 @@ class Script {
|
|
|
28
19
|
const script = document.createElement('script');
|
|
29
20
|
script.src = src;
|
|
30
21
|
script.async = true;
|
|
31
|
-
|
|
32
22
|
const load = () => {
|
|
33
23
|
this.state = 'LOADED';
|
|
34
24
|
script.removeEventListener('load', load);
|
|
35
25
|
this.emitState();
|
|
36
26
|
};
|
|
37
|
-
|
|
38
27
|
const error = () => {
|
|
39
28
|
this.state = 'ERROR';
|
|
40
29
|
script.removeEventListener('error', error);
|
|
41
30
|
this.emitState();
|
|
42
31
|
};
|
|
43
|
-
|
|
44
32
|
script.addEventListener('load', load);
|
|
45
33
|
script.addEventListener('error', error);
|
|
46
34
|
document.body.appendChild(script);
|
|
47
35
|
}
|
|
48
|
-
|
|
49
36
|
onStateChange(cb) {
|
|
50
37
|
this.listeners.push(cb);
|
|
51
38
|
return () => {
|
|
52
39
|
this.listeners = this.listeners.filter(fn => fn !== cb);
|
|
53
40
|
};
|
|
54
41
|
}
|
|
55
|
-
|
|
56
42
|
emitState() {
|
|
57
43
|
var _iterator = _createForOfIteratorHelper(this.listeners),
|
|
58
|
-
|
|
59
|
-
|
|
44
|
+
_step;
|
|
60
45
|
try {
|
|
61
46
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
62
47
|
const cb = _step.value;
|
|
@@ -68,27 +53,24 @@ class Script {
|
|
|
68
53
|
_iterator.f();
|
|
69
54
|
}
|
|
70
55
|
}
|
|
71
|
-
|
|
72
56
|
}
|
|
73
|
-
|
|
74
57
|
const scripts = new Map();
|
|
58
|
+
|
|
75
59
|
/**
|
|
76
60
|
* Hook for loading external script
|
|
77
61
|
* @param {string} src - The URL of the script
|
|
78
62
|
* @param {boolean} [doNotLoad=false] - If set to true the script will not be loaded
|
|
79
63
|
* This can be handy because hooks can not be called conditionally by the consumer
|
|
80
64
|
*/
|
|
81
|
-
|
|
82
65
|
function useScript(src, doNotLoad = false) {
|
|
83
66
|
// Keeping track of script loaded and error state
|
|
84
67
|
const _useState = (0, _react.useState)({
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
68
|
+
loaded: false,
|
|
69
|
+
error: false
|
|
70
|
+
}),
|
|
71
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
72
|
+
state = _useState2[0],
|
|
73
|
+
setState = _useState2[1];
|
|
92
74
|
(0, _react.useEffect)(() => {
|
|
93
75
|
// If doNotLoad we return early so the script will not be loaded
|
|
94
76
|
if (doNotLoad) {
|
|
@@ -97,12 +79,11 @@ function useScript(src, doNotLoad = false) {
|
|
|
97
79
|
error: false
|
|
98
80
|
});
|
|
99
81
|
return;
|
|
100
|
-
}
|
|
101
|
-
// loaded by another instance of the hook, so no need to load again
|
|
102
|
-
|
|
82
|
+
}
|
|
103
83
|
|
|
84
|
+
// If scripts already includes src it means that the script was already
|
|
85
|
+
// loaded by another instance of the hook, so no need to load again
|
|
104
86
|
const script = scripts.get(src) || scripts.set(src, new Script(src)).get(src);
|
|
105
|
-
|
|
106
87
|
if (script.state === 'LOADED') {
|
|
107
88
|
setState({
|
|
108
89
|
loaded: true,
|
|
@@ -110,7 +91,6 @@ function useScript(src, doNotLoad = false) {
|
|
|
110
91
|
});
|
|
111
92
|
return;
|
|
112
93
|
}
|
|
113
|
-
|
|
114
94
|
return script.onStateChange(state => {
|
|
115
95
|
if (state === 'ERROR') {
|
|
116
96
|
scripts.delete(src);
|
|
@@ -128,6 +108,5 @@ function useScript(src, doNotLoad = false) {
|
|
|
128
108
|
}, [src, doNotLoad]);
|
|
129
109
|
return [state.loaded, state.error];
|
|
130
110
|
}
|
|
131
|
-
|
|
132
111
|
var _default = useScript;
|
|
133
112
|
exports.default = _default;
|
package/package.json
CHANGED
|
@@ -3,20 +3,20 @@
|
|
|
3
3
|
"description": "React hooks",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"private": false,
|
|
6
|
-
"version": "
|
|
6
|
+
"version": "2.0.0",
|
|
7
7
|
"sideEffects": false,
|
|
8
8
|
"main": "./cjs/index.js",
|
|
9
9
|
"module": "./index.js",
|
|
10
10
|
"esnext": "./index.js",
|
|
11
11
|
"typings": "./index.d.ts",
|
|
12
12
|
"peerDependencies": {
|
|
13
|
-
"react": ">=
|
|
14
|
-
"react-dom": ">=
|
|
13
|
+
"react": ">= 17.0.2",
|
|
14
|
+
"react-dom": ">= 17.0.2"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"use-resize-observer": "^
|
|
17
|
+
"use-resize-observer": "^9.0.2"
|
|
18
18
|
},
|
|
19
|
-
"gitHead": "
|
|
19
|
+
"gitHead": "98f0815776d1be1eef0e7a3012c384d7933ede8c",
|
|
20
20
|
"publishConfig": {
|
|
21
21
|
"access": "public"
|
|
22
22
|
}
|
package/useDimensions.js
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
-
|
|
3
2
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
-
|
|
5
3
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
6
|
-
|
|
7
4
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
8
|
-
|
|
9
5
|
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
10
|
-
|
|
11
6
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
|
-
|
|
13
7
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
14
8
|
import { useState, useCallback, useLayoutEffect, useEffect } from 'react';
|
|
15
9
|
var EMPTY_DIMENSION_OBJECT = {
|
|
@@ -22,14 +16,11 @@ var EMPTY_DIMENSION_OBJECT = {
|
|
|
22
16
|
right: 0,
|
|
23
17
|
bottom: 0
|
|
24
18
|
};
|
|
25
|
-
|
|
26
19
|
function getDimensionObject(node) {
|
|
27
20
|
var rect = node.getBoundingClientRect();
|
|
28
21
|
/** @ts-ignore */
|
|
29
|
-
|
|
30
22
|
var left = 'x' in rect ? rect.x : rect.left;
|
|
31
23
|
/** @ts-ignore */
|
|
32
|
-
|
|
33
24
|
var top = 'y' in rect ? rect.y : rect.top;
|
|
34
25
|
return {
|
|
35
26
|
width: rect.width,
|
|
@@ -42,22 +33,18 @@ function getDimensionObject(node) {
|
|
|
42
33
|
bottom: rect.bottom
|
|
43
34
|
};
|
|
44
35
|
}
|
|
45
|
-
|
|
46
36
|
function useDimensions() {
|
|
47
37
|
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
38
|
+
_ref$liveMeasure = _ref.liveMeasure,
|
|
39
|
+
liveMeasure = _ref$liveMeasure === void 0 ? true : _ref$liveMeasure;
|
|
51
40
|
var _useState = useState(EMPTY_DIMENSION_OBJECT),
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
41
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
42
|
+
dimensions = _useState2[0],
|
|
43
|
+
setDimensions = _useState2[1];
|
|
56
44
|
var _useState3 = useState(null),
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
45
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
46
|
+
node = _useState4[0],
|
|
47
|
+
setNode = _useState4[1];
|
|
61
48
|
var ref = useCallback(function (node) {
|
|
62
49
|
setNode(node);
|
|
63
50
|
}, []);
|
|
@@ -69,9 +56,7 @@ function useDimensions() {
|
|
|
69
56
|
return setDimensions(getDimensionObject(node));
|
|
70
57
|
});
|
|
71
58
|
};
|
|
72
|
-
|
|
73
59
|
measure();
|
|
74
|
-
|
|
75
60
|
if (liveMeasure) {
|
|
76
61
|
window.addEventListener('resize', measure);
|
|
77
62
|
window.addEventListener('scroll', measure);
|
|
@@ -81,12 +66,10 @@ function useDimensions() {
|
|
|
81
66
|
};
|
|
82
67
|
}
|
|
83
68
|
}
|
|
84
|
-
|
|
85
69
|
return function () {
|
|
86
70
|
/* no-op */
|
|
87
71
|
};
|
|
88
72
|
}, [liveMeasure, node]);
|
|
89
73
|
return [ref, dimensions, node];
|
|
90
74
|
}
|
|
91
|
-
|
|
92
75
|
export default useDimensions;
|
package/useForwardedRef.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
3
2
|
function useForwardedRef(forwardedRef) {
|
|
4
3
|
var innerRef = React.useRef(null);
|
|
5
4
|
React.useEffect(function () {
|
|
6
5
|
if (!forwardedRef) {
|
|
7
6
|
return;
|
|
8
7
|
}
|
|
9
|
-
|
|
10
8
|
if (typeof forwardedRef === 'function') {
|
|
11
9
|
forwardedRef(innerRef.current);
|
|
12
10
|
} else {
|
|
@@ -15,5 +13,4 @@ function useForwardedRef(forwardedRef) {
|
|
|
15
13
|
}, [forwardedRef]);
|
|
16
14
|
return innerRef;
|
|
17
15
|
}
|
|
18
|
-
|
|
19
16
|
export default useForwardedRef;
|
|
@@ -15,4 +15,4 @@ export declare type GoogleReCaptchaV3Options = {
|
|
|
15
15
|
*/
|
|
16
16
|
disabled?: boolean;
|
|
17
17
|
};
|
|
18
|
-
export declare function useGoogleReCaptchaV3({ siteKey, disabled }: GoogleReCaptchaV3Options): (action?: string
|
|
18
|
+
export declare function useGoogleReCaptchaV3({ siteKey, disabled }: GoogleReCaptchaV3Options): (action?: string) => Promise<string | undefined>;
|
package/useGoogleReCaptchaV3.js
CHANGED
|
@@ -1,45 +1,35 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
1
3
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
2
|
-
|
|
3
4
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
4
|
-
|
|
5
5
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
6
|
-
|
|
7
6
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
8
|
-
|
|
9
7
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
10
|
-
|
|
11
8
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
12
|
-
|
|
13
9
|
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
14
|
-
|
|
15
10
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
16
|
-
|
|
17
11
|
import { useCallback, useEffect } from 'react';
|
|
18
12
|
import useScript from './useScript';
|
|
19
13
|
export function useGoogleReCaptchaV3(_ref) {
|
|
20
14
|
var siteKey = _ref.siteKey,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
_ref$disabled = _ref.disabled,
|
|
16
|
+
disabled = _ref$disabled === void 0 ? false : _ref$disabled;
|
|
24
17
|
// Load ReCaptcha script.
|
|
25
18
|
var _useScript = useScript("https://www.google.com/recaptcha/api.js?render=".concat(siteKey), disabled),
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
19
|
+
_useScript2 = _slicedToArray(_useScript, 2),
|
|
20
|
+
loaded = _useScript2[0],
|
|
21
|
+
error = _useScript2[1];
|
|
30
22
|
useEffect(function () {
|
|
31
23
|
if (loaded && !disabled) {
|
|
32
24
|
// eslint-disable-next-line no-console
|
|
33
25
|
console.log('Google ReCaptcha script loaded!');
|
|
34
26
|
}
|
|
35
|
-
|
|
36
27
|
if (error) throw new Error('Google ReCaptcha script failed to load');
|
|
37
28
|
}, [loaded, error, disabled]);
|
|
38
29
|
var executeReCaptcha = useCallback( /*#__PURE__*/function () {
|
|
39
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/
|
|
30
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(action) {
|
|
40
31
|
var _window, grecaptcha;
|
|
41
|
-
|
|
42
|
-
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
32
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
43
33
|
while (1) {
|
|
44
34
|
switch (_context.prev = _context.next) {
|
|
45
35
|
case 0:
|
|
@@ -47,27 +37,20 @@ export function useGoogleReCaptchaV3(_ref) {
|
|
|
47
37
|
_context.next = 2;
|
|
48
38
|
break;
|
|
49
39
|
}
|
|
50
|
-
|
|
51
40
|
throw new Error('ERROR: NOT A WEB BROWSER');
|
|
52
|
-
|
|
53
41
|
case 2:
|
|
54
42
|
if (!disabled) {
|
|
55
43
|
_context.next = 4;
|
|
56
44
|
break;
|
|
57
45
|
}
|
|
58
|
-
|
|
59
46
|
return _context.abrupt("return", Promise.resolve(undefined));
|
|
60
|
-
|
|
61
47
|
case 4:
|
|
62
48
|
_window = window, grecaptcha = _window.grecaptcha;
|
|
63
|
-
|
|
64
49
|
if (grecaptcha) {
|
|
65
50
|
_context.next = 7;
|
|
66
51
|
break;
|
|
67
52
|
}
|
|
68
|
-
|
|
69
53
|
throw new Error('ERROR: SCRIPT NOT AVAILABLE');
|
|
70
|
-
|
|
71
54
|
case 7:
|
|
72
55
|
return _context.abrupt("return", new Promise(function (resolve) {
|
|
73
56
|
// Invoke the ReCaptcha check.
|
|
@@ -79,7 +62,6 @@ export function useGoogleReCaptchaV3(_ref) {
|
|
|
79
62
|
});
|
|
80
63
|
});
|
|
81
64
|
}));
|
|
82
|
-
|
|
83
65
|
case 8:
|
|
84
66
|
case "end":
|
|
85
67
|
return _context.stop();
|
|
@@ -87,7 +69,6 @@ export function useGoogleReCaptchaV3(_ref) {
|
|
|
87
69
|
}
|
|
88
70
|
}, _callee);
|
|
89
71
|
}));
|
|
90
|
-
|
|
91
72
|
return function (_x) {
|
|
92
73
|
return _ref2.apply(this, arguments);
|
|
93
74
|
};
|
package/useOffline.js
CHANGED
|
@@ -1,35 +1,24 @@
|
|
|
1
1
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
-
|
|
3
2
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
-
|
|
5
3
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
6
|
-
|
|
7
4
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
8
|
-
|
|
9
5
|
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
10
|
-
|
|
11
6
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
|
-
|
|
13
7
|
import { useEffect, useState } from 'react';
|
|
14
|
-
|
|
15
8
|
var getOnLineStatus = function getOnLineStatus() {
|
|
16
9
|
return typeof window !== 'undefined' && typeof navigator !== 'undefined' && typeof navigator.onLine === 'boolean' ? navigator.onLine : true;
|
|
17
10
|
};
|
|
18
|
-
|
|
19
11
|
var useOffline = function useOffline() {
|
|
20
12
|
var _useState = useState(getOnLineStatus()),
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
13
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
14
|
+
status = _useState2[0],
|
|
15
|
+
setStatus = _useState2[1];
|
|
25
16
|
var setOnline = function setOnline() {
|
|
26
17
|
return setStatus(true);
|
|
27
18
|
};
|
|
28
|
-
|
|
29
19
|
var setOffline = function setOffline() {
|
|
30
20
|
return setStatus(false);
|
|
31
21
|
};
|
|
32
|
-
|
|
33
22
|
useEffect(function () {
|
|
34
23
|
window.addEventListener('online', setOnline);
|
|
35
24
|
window.addEventListener('offline', setOffline);
|
|
@@ -43,5 +32,4 @@ var useOffline = function useOffline() {
|
|
|
43
32
|
isOffline: !status
|
|
44
33
|
};
|
|
45
34
|
};
|
|
46
|
-
|
|
47
35
|
export default useOffline;
|
package/useScript.js
CHANGED
|
@@ -1,61 +1,41 @@
|
|
|
1
1
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
-
|
|
3
2
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
-
|
|
5
3
|
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
6
|
-
|
|
7
4
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
8
|
-
|
|
9
5
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
10
|
-
|
|
11
6
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
12
|
-
|
|
13
7
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
14
|
-
|
|
15
8
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
16
|
-
|
|
17
9
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
18
|
-
|
|
19
10
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
20
|
-
|
|
21
11
|
import { useState, useEffect } from 'react';
|
|
22
|
-
|
|
23
12
|
var Script = /*#__PURE__*/function () {
|
|
24
13
|
function Script(src) {
|
|
25
14
|
var _this = this;
|
|
26
|
-
|
|
27
15
|
_classCallCheck(this, Script);
|
|
28
|
-
|
|
29
16
|
this.state = 'PENDING';
|
|
30
17
|
this.listeners = [];
|
|
31
18
|
var script = document.createElement('script');
|
|
32
19
|
script.src = src;
|
|
33
20
|
script.async = true;
|
|
34
|
-
|
|
35
21
|
var load = function load() {
|
|
36
22
|
_this.state = 'LOADED';
|
|
37
23
|
script.removeEventListener('load', load);
|
|
38
|
-
|
|
39
24
|
_this.emitState();
|
|
40
25
|
};
|
|
41
|
-
|
|
42
26
|
var error = function error() {
|
|
43
27
|
_this.state = 'ERROR';
|
|
44
28
|
script.removeEventListener('error', error);
|
|
45
|
-
|
|
46
29
|
_this.emitState();
|
|
47
30
|
};
|
|
48
|
-
|
|
49
31
|
script.addEventListener('load', load);
|
|
50
32
|
script.addEventListener('error', error);
|
|
51
33
|
document.body.appendChild(script);
|
|
52
34
|
}
|
|
53
|
-
|
|
54
35
|
_createClass(Script, [{
|
|
55
36
|
key: "onStateChange",
|
|
56
37
|
value: function onStateChange(cb) {
|
|
57
38
|
var _this2 = this;
|
|
58
|
-
|
|
59
39
|
this.listeners.push(cb);
|
|
60
40
|
return function () {
|
|
61
41
|
_this2.listeners = _this2.listeners.filter(function (fn) {
|
|
@@ -67,8 +47,7 @@ var Script = /*#__PURE__*/function () {
|
|
|
67
47
|
key: "emitState",
|
|
68
48
|
value: function emitState() {
|
|
69
49
|
var _iterator = _createForOfIteratorHelper(this.listeners),
|
|
70
|
-
|
|
71
|
-
|
|
50
|
+
_step;
|
|
72
51
|
try {
|
|
73
52
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
74
53
|
var cb = _step.value;
|
|
@@ -81,30 +60,26 @@ var Script = /*#__PURE__*/function () {
|
|
|
81
60
|
}
|
|
82
61
|
}
|
|
83
62
|
}]);
|
|
84
|
-
|
|
85
63
|
return Script;
|
|
86
64
|
}();
|
|
87
|
-
|
|
88
65
|
var scripts = new Map();
|
|
66
|
+
|
|
89
67
|
/**
|
|
90
68
|
* Hook for loading external script
|
|
91
69
|
* @param {string} src - The URL of the script
|
|
92
70
|
* @param {boolean} [doNotLoad=false] - If set to true the script will not be loaded
|
|
93
71
|
* This can be handy because hooks can not be called conditionally by the consumer
|
|
94
72
|
*/
|
|
95
|
-
|
|
96
73
|
function useScript(src) {
|
|
97
74
|
var doNotLoad = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
98
|
-
|
|
99
75
|
// Keeping track of script loaded and error state
|
|
100
76
|
var _useState = useState({
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
77
|
+
loaded: false,
|
|
78
|
+
error: false
|
|
79
|
+
}),
|
|
80
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
81
|
+
state = _useState2[0],
|
|
82
|
+
setState = _useState2[1];
|
|
108
83
|
useEffect(function () {
|
|
109
84
|
// If doNotLoad we return early so the script will not be loaded
|
|
110
85
|
if (doNotLoad) {
|
|
@@ -113,12 +88,11 @@ function useScript(src) {
|
|
|
113
88
|
error: false
|
|
114
89
|
});
|
|
115
90
|
return;
|
|
116
|
-
}
|
|
117
|
-
// loaded by another instance of the hook, so no need to load again
|
|
118
|
-
|
|
91
|
+
}
|
|
119
92
|
|
|
93
|
+
// If scripts already includes src it means that the script was already
|
|
94
|
+
// loaded by another instance of the hook, so no need to load again
|
|
120
95
|
var script = scripts.get(src) || scripts.set(src, new Script(src)).get(src);
|
|
121
|
-
|
|
122
96
|
if (script.state === 'LOADED') {
|
|
123
97
|
setState({
|
|
124
98
|
loaded: true,
|
|
@@ -126,7 +100,6 @@ function useScript(src) {
|
|
|
126
100
|
});
|
|
127
101
|
return;
|
|
128
102
|
}
|
|
129
|
-
|
|
130
103
|
return script.onStateChange(function (state) {
|
|
131
104
|
if (state === 'ERROR') {
|
|
132
105
|
scripts["delete"](src);
|
|
@@ -144,5 +117,4 @@ function useScript(src) {
|
|
|
144
117
|
}, [src, doNotLoad]);
|
|
145
118
|
return [state.loaded, state.error];
|
|
146
119
|
}
|
|
147
|
-
|
|
148
120
|
export default useScript;
|