@dfds-ui/hooks 2.2.0-alpha.c2f773c5 → 2.2.0-alpha.c79adffa

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 CHANGED
@@ -12,31 +12,31 @@ var _exportNames = {
12
12
  };
13
13
  Object.defineProperty(exports, "useDimensions", {
14
14
  enumerable: true,
15
- get: function () {
15
+ get: function get() {
16
16
  return _useDimensions.default;
17
17
  }
18
18
  });
19
19
  Object.defineProperty(exports, "useForwardedRef", {
20
20
  enumerable: true,
21
- get: function () {
21
+ get: function get() {
22
22
  return _useForwardedRef.default;
23
23
  }
24
24
  });
25
25
  Object.defineProperty(exports, "useOffline", {
26
26
  enumerable: true,
27
- get: function () {
27
+ get: function get() {
28
28
  return _useOffline.default;
29
29
  }
30
30
  });
31
31
  Object.defineProperty(exports, "useResizeObserver", {
32
32
  enumerable: true,
33
- get: function () {
33
+ get: function get() {
34
34
  return _useResizeObserver.default;
35
35
  }
36
36
  });
37
37
  Object.defineProperty(exports, "useScript", {
38
38
  enumerable: true,
39
- get: function () {
39
+ get: function get() {
40
40
  return _useScript.default;
41
41
  }
42
42
  });
@@ -52,7 +52,7 @@ Object.keys(_useGoogleReCaptchaV).forEach(function (key) {
52
52
  if (key in exports && exports[key] === _useGoogleReCaptchaV[key]) return;
53
53
  Object.defineProperty(exports, key, {
54
54
  enumerable: true,
55
- get: function () {
55
+ get: function get() {
56
56
  return _useGoogleReCaptchaV[key];
57
57
  }
58
58
  });
@@ -8,7 +8,7 @@ export interface DimensionObject {
8
8
  right: number;
9
9
  bottom: number;
10
10
  }
11
- export type UseDimensionsHook = [(node: HTMLElement | null) => void, DimensionObject, HTMLElement | null];
11
+ export declare type UseDimensionsHook = [(node: HTMLElement | null) => void, DimensionObject, HTMLElement | null];
12
12
  export interface UseDimensionsArgs {
13
13
  liveMeasure?: boolean;
14
14
  }
@@ -5,8 +5,12 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _react = require("react");
8
- /* eslint-disable @typescript-eslint/ban-ts-comment */
9
-
8
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
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."); }
10
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
11
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
12
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
13
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } /* eslint-disable @typescript-eslint/ban-ts-comment */
10
14
  const EMPTY_DIMENSION_OBJECT = {
11
15
  width: 0,
12
16
  height: 0,
@@ -19,13 +23,17 @@ const EMPTY_DIMENSION_OBJECT = {
19
23
  };
20
24
  function getDimensionObject(node) {
21
25
  const rect = node.getBoundingClientRect();
26
+ /** @ts-ignore */
27
+ const left = 'x' in rect ? rect.x : rect.left;
28
+ /** @ts-ignore */
29
+ const top = 'y' in rect ? rect.y : rect.top;
22
30
  return {
23
31
  width: rect.width,
24
32
  height: rect.height,
25
- x: rect.x,
26
- y: rect.y,
27
- top: rect.y,
28
- left: rect.x,
33
+ x: left,
34
+ y: top,
35
+ top: top,
36
+ left: left,
29
37
  right: rect.right,
30
38
  bottom: rect.bottom
31
39
  };
@@ -33,8 +41,14 @@ function getDimensionObject(node) {
33
41
  function useDimensions({
34
42
  liveMeasure = true
35
43
  } = {}) {
36
- const [dimensions, setDimensions] = (0, _react.useState)(EMPTY_DIMENSION_OBJECT);
37
- const [node, setNode] = (0, _react.useState)(null);
44
+ const _useState = (0, _react.useState)(EMPTY_DIMENSION_OBJECT),
45
+ _useState2 = _slicedToArray(_useState, 2),
46
+ dimensions = _useState2[0],
47
+ setDimensions = _useState2[1];
48
+ const _useState3 = (0, _react.useState)(null),
49
+ _useState4 = _slicedToArray(_useState3, 2),
50
+ node = _useState4[0],
51
+ setNode = _useState4[1];
38
52
  const ref = (0, _react.useCallback)(node => {
39
53
  setNode(node);
40
54
  }, []);
@@ -3,7 +3,7 @@ declare global {
3
3
  grecaptcha: any;
4
4
  }
5
5
  }
6
- export type GoogleReCaptchaV3Options = {
6
+ export declare type GoogleReCaptchaV3Options = {
7
7
  /**
8
8
  * The `sitekey` to use with reCAPTCHA v3.
9
9
  * https://developers.google.com/recaptcha/docs/v3
@@ -5,14 +5,25 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.useGoogleReCaptchaV3 = useGoogleReCaptchaV3;
7
7
  var _react = require("react");
8
- var _useScript = _interopRequireDefault(require("./useScript"));
8
+ var _useScript3 = _interopRequireDefault(require("./useScript"));
9
9
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
11
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
12
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
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."); }
14
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
15
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
16
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
17
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
10
18
  function useGoogleReCaptchaV3({
11
19
  siteKey,
12
20
  disabled = false
13
21
  }) {
14
22
  // Load ReCaptcha script.
15
- const [loaded, error] = (0, _useScript.default)(`https://www.google.com/recaptcha/api.js?render=${siteKey}`, disabled);
23
+ const _useScript = (0, _useScript3.default)(`https://www.google.com/recaptcha/api.js?render=${siteKey}`, disabled),
24
+ _useScript2 = _slicedToArray(_useScript, 2),
25
+ loaded = _useScript2[0],
26
+ error = _useScript2[1];
16
27
  (0, _react.useEffect)(() => {
17
28
  if (loaded && !disabled) {
18
29
  // eslint-disable-next-line no-console
@@ -20,29 +31,33 @@ function useGoogleReCaptchaV3({
20
31
  }
21
32
  if (error) throw new Error('Google ReCaptcha script failed to load');
22
33
  }, [loaded, error, disabled]);
23
- const executeReCaptcha = (0, _react.useCallback)(async action => {
24
- if (!window) {
25
- throw new Error('ERROR: NOT A WEB BROWSER');
26
- }
27
- if (disabled) {
28
- return Promise.resolve(undefined);
29
- }
30
- const {
31
- grecaptcha
32
- } = window;
33
- if (!grecaptcha) {
34
- throw new Error('ERROR: SCRIPT NOT AVAILABLE');
35
- }
36
- return new Promise(resolve => {
37
- // Invoke the ReCaptcha check.
38
- grecaptcha.ready(() => {
39
- grecaptcha.execute(siteKey, {
40
- action
41
- }).then(token => {
42
- resolve(token);
34
+ const executeReCaptcha = (0, _react.useCallback)(/*#__PURE__*/function () {
35
+ var _ref = _asyncToGenerator(function* (action) {
36
+ if (!window) {
37
+ throw new Error('ERROR: NOT A WEB BROWSER');
38
+ }
39
+ if (disabled) {
40
+ return Promise.resolve(undefined);
41
+ }
42
+ const _window = window,
43
+ grecaptcha = _window.grecaptcha;
44
+ if (!grecaptcha) {
45
+ throw new Error('ERROR: SCRIPT NOT AVAILABLE');
46
+ }
47
+ return new Promise(resolve => {
48
+ // Invoke the ReCaptcha check.
49
+ grecaptcha.ready(() => {
50
+ grecaptcha.execute(siteKey, {
51
+ action
52
+ }).then(token => {
53
+ resolve(token);
54
+ });
43
55
  });
44
56
  });
45
57
  });
46
- }, [siteKey, disabled]);
58
+ return function (_x) {
59
+ return _ref.apply(this, arguments);
60
+ };
61
+ }(), [siteKey, disabled]);
47
62
  return executeReCaptcha;
48
63
  }
package/cjs/useOffline.js CHANGED
@@ -5,9 +5,18 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _react = require("react");
8
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
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."); }
10
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
11
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
12
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
13
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
8
14
  const getOnLineStatus = () => typeof window !== 'undefined' && typeof navigator !== 'undefined' && typeof navigator.onLine === 'boolean' ? navigator.onLine : true;
9
15
  const useOffline = () => {
10
- const [status, setStatus] = (0, _react.useState)(getOnLineStatus());
16
+ const _useState = (0, _react.useState)(getOnLineStatus()),
17
+ _useState2 = _slicedToArray(_useState, 2),
18
+ status = _useState2[0],
19
+ setStatus = _useState2[1];
11
20
  const setOnline = () => setStatus(true);
12
21
  const setOffline = () => setStatus(false);
13
22
  (0, _react.useEffect)(() => {
package/cjs/useScript.js CHANGED
@@ -5,6 +5,13 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _react = require("react");
8
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
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."); }
10
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
11
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
12
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
13
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
14
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
8
15
  class Script {
9
16
  constructor(src) {
10
17
  this.state = 'PENDING';
@@ -33,8 +40,17 @@ class Script {
33
40
  };
34
41
  }
35
42
  emitState() {
36
- for (const cb of this.listeners) {
37
- cb(this.state);
43
+ var _iterator = _createForOfIteratorHelper(this.listeners),
44
+ _step;
45
+ try {
46
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
47
+ const cb = _step.value;
48
+ cb(this.state);
49
+ }
50
+ } catch (err) {
51
+ _iterator.e(err);
52
+ } finally {
53
+ _iterator.f();
38
54
  }
39
55
  }
40
56
  }
@@ -48,10 +64,13 @@ const scripts = new Map();
48
64
  */
49
65
  function useScript(src, doNotLoad = false) {
50
66
  // Keeping track of script loaded and error state
51
- const [state, setState] = (0, _react.useState)({
52
- loaded: false,
53
- error: false
54
- });
67
+ const _useState = (0, _react.useState)({
68
+ loaded: false,
69
+ error: false
70
+ }),
71
+ _useState2 = _slicedToArray(_useState, 2),
72
+ state = _useState2[0],
73
+ setState = _useState2[1];
55
74
  (0, _react.useEffect)(() => {
56
75
  // If doNotLoad we return early so the script will not be loaded
57
76
  if (doNotLoad) {
package/package.json CHANGED
@@ -3,20 +3,20 @@
3
3
  "description": "React hooks",
4
4
  "license": "MIT",
5
5
  "private": false,
6
- "version": "2.2.0-alpha.c2f773c5",
6
+ "version": "2.2.0-alpha.c79adffa",
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": ">= 18.3.1",
14
- "react-dom": ">= 18.3.1"
13
+ "react": ">= 17.0.2",
14
+ "react-dom": ">= 17.0.2"
15
15
  },
16
16
  "dependencies": {
17
- "use-resize-observer": "^9.1.0"
17
+ "use-resize-observer": "^9.0.2"
18
18
  },
19
- "gitHead": "c2f773c5e158ea1a17a9a46fd9e3d41adda1dc5f",
19
+ "gitHead": "c79adffa9d3abdc5a68e179196b451f0d9aec5e9",
20
20
  "publishConfig": {
21
21
  "access": "public"
22
22
  }
@@ -8,7 +8,7 @@ export interface DimensionObject {
8
8
  right: number;
9
9
  bottom: number;
10
10
  }
11
- export type UseDimensionsHook = [(node: HTMLElement | null) => void, DimensionObject, HTMLElement | null];
11
+ export declare type UseDimensionsHook = [(node: HTMLElement | null) => void, DimensionObject, HTMLElement | null];
12
12
  export interface UseDimensionsArgs {
13
13
  liveMeasure?: boolean;
14
14
  }
package/useDimensions.js CHANGED
@@ -18,13 +18,17 @@ var EMPTY_DIMENSION_OBJECT = {
18
18
  };
19
19
  function getDimensionObject(node) {
20
20
  var rect = node.getBoundingClientRect();
21
+ /** @ts-ignore */
22
+ var left = 'x' in rect ? rect.x : rect.left;
23
+ /** @ts-ignore */
24
+ var top = 'y' in rect ? rect.y : rect.top;
21
25
  return {
22
26
  width: rect.width,
23
27
  height: rect.height,
24
- x: rect.x,
25
- y: rect.y,
26
- top: rect.y,
27
- left: rect.x,
28
+ x: left,
29
+ y: top,
30
+ top: top,
31
+ left: left,
28
32
  right: rect.right,
29
33
  bottom: rect.bottom
30
34
  };
@@ -3,7 +3,7 @@ declare global {
3
3
  grecaptcha: any;
4
4
  }
5
5
  }
6
- export type GoogleReCaptchaV3Options = {
6
+ export declare type GoogleReCaptchaV3Options = {
7
7
  /**
8
8
  * The `sitekey` to use with reCAPTCHA v3.
9
9
  * https://developers.google.com/recaptcha/docs/v3