@capsitech/react-utilities 0.1.8 → 0.1.10
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/lib/Hooks.js +56 -51
- package/lib/Hooks.js.map +1 -1
- package/lib/Utilities.js +6 -6
- package/lib/index.js +6 -6
- package/lib/src/Hooks/useNetworkState.js +20 -20
- package/lib/src/Hooks/useNetworkState.js.map +1 -1
- package/lib/src/Utilities/ApiUtility.axios.js +211 -205
- package/lib/src/Utilities/ApiUtility.axios.js.map +1 -1
- package/lib/src/Utilities/Countries.js +120 -114
- package/lib/src/Utilities/Countries.js.map +1 -1
- package/lib/src/Utilities/CustomEventEmitter.js +20 -17
- package/lib/src/Utilities/CustomEventEmitter.js.map +1 -1
- package/lib/src/Utilities/FastCompare.js +1 -1
- package/lib/src/Utilities/FastCompare.js.map +1 -1
- package/lib/src/Utilities/HideablePromise.js +10 -4
- package/lib/src/Utilities/HideablePromise.js.map +1 -1
- package/lib/src/Utilities/RouteUtils.js +178 -170
- package/lib/src/Utilities/RouteUtils.js.map +1 -1
- package/lib/src/Utilities/Utils.js +239 -236
- package/lib/src/Utilities/Utils.js.map +1 -1
- package/lib/src/Utilities/dayjs.js +39 -3
- package/lib/src/Utilities/dayjs.js.map +1 -1
- package/lib/src/Utilities/index.js +6 -6
- package/package.json +13 -1
- package/lib/dayjs-aKjfjjRl.mjs +0 -605
- package/lib/dayjs-aKjfjjRl.mjs.map +0 -1
package/lib/Hooks.js
CHANGED
|
@@ -1,67 +1,72 @@
|
|
|
1
|
-
import { useRef as
|
|
2
|
-
import { useInfiniteScroll as
|
|
3
|
-
import { isBrowser as
|
|
4
|
-
import { disabledEventPropagation as
|
|
5
|
-
const
|
|
6
|
-
const e =
|
|
7
|
-
return
|
|
1
|
+
import { useRef as s, useEffect as o, useCallback as i } from "react";
|
|
2
|
+
import { useInfiniteScroll as E } from "./src/Hooks/useInfiniteScroll.js";
|
|
3
|
+
import { isBrowser as T, isNavigator as d, useNetworkState as g } from "./src/Hooks/useNetworkState.js";
|
|
4
|
+
import { disabledEventPropagation as w, useShortcuts as F } from "./src/Hooks/useShortcuts.js";
|
|
5
|
+
const m = (r, t) => {
|
|
6
|
+
const e = s(!1);
|
|
7
|
+
return o(() => {
|
|
8
8
|
if (e.current)
|
|
9
|
-
return
|
|
9
|
+
return r();
|
|
10
10
|
e.current = !0;
|
|
11
|
-
},
|
|
11
|
+
}, t), e.current;
|
|
12
12
|
};
|
|
13
|
-
function c(
|
|
14
|
-
const
|
|
15
|
-
return
|
|
16
|
-
|
|
17
|
-
}, [
|
|
13
|
+
function c(r) {
|
|
14
|
+
const t = s(r);
|
|
15
|
+
return o(() => {
|
|
16
|
+
t.current = r;
|
|
17
|
+
}, [r]), t;
|
|
18
18
|
}
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
return
|
|
22
|
-
|
|
19
|
+
const p = (r) => {
|
|
20
|
+
const t = s(r);
|
|
21
|
+
return o(() => {
|
|
22
|
+
t.current = r;
|
|
23
23
|
}), i(
|
|
24
|
-
((...e) =>
|
|
24
|
+
((...e) => {
|
|
25
|
+
var u;
|
|
26
|
+
return (u = t.current) == null ? void 0 : u.call(t, ...e);
|
|
27
|
+
}),
|
|
25
28
|
[]
|
|
26
29
|
);
|
|
27
|
-
},
|
|
28
|
-
const
|
|
29
|
-
return
|
|
30
|
+
}, I = () => {
|
|
31
|
+
const r = s(!0);
|
|
32
|
+
return r.current ? (r.current = !1, !0) : r.current;
|
|
30
33
|
};
|
|
31
|
-
function
|
|
32
|
-
const e = c(
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
34
|
+
function a(r, t) {
|
|
35
|
+
const e = c(r);
|
|
36
|
+
o(() => {
|
|
37
|
+
const u = () => {
|
|
38
|
+
var n;
|
|
39
|
+
(n = e.current) == null || n.call(e);
|
|
36
40
|
};
|
|
37
|
-
if (
|
|
38
|
-
const
|
|
39
|
-
return () => clearInterval(
|
|
41
|
+
if (t !== null) {
|
|
42
|
+
const n = setInterval(u, t);
|
|
43
|
+
return () => clearInterval(n);
|
|
40
44
|
}
|
|
41
|
-
}, [
|
|
45
|
+
}, [t, e]);
|
|
42
46
|
}
|
|
43
|
-
function
|
|
44
|
-
const e = c(
|
|
45
|
-
|
|
46
|
-
if (
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
function l(r, t) {
|
|
48
|
+
const e = c(r);
|
|
49
|
+
o(() => {
|
|
50
|
+
if (t == null) return;
|
|
51
|
+
const u = setTimeout(() => {
|
|
52
|
+
var n;
|
|
53
|
+
(n = e.current) == null || n.call(e);
|
|
54
|
+
}, t);
|
|
55
|
+
return () => clearTimeout(u);
|
|
56
|
+
}, [t, e]);
|
|
52
57
|
}
|
|
53
58
|
export {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
w as disabledEventPropagation,
|
|
60
|
+
T as isBrowser,
|
|
61
|
+
d as isNavigator,
|
|
62
|
+
p as useCallbackRef,
|
|
63
|
+
I as useFirstRenderState,
|
|
64
|
+
E as useInfiniteScroll,
|
|
65
|
+
a as useInterval,
|
|
61
66
|
c as useLatestRef,
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
67
|
+
g as useNetworkState,
|
|
68
|
+
F as useShortcuts,
|
|
69
|
+
l as useTimeout,
|
|
70
|
+
m as useUpdateEffect
|
|
66
71
|
};
|
|
67
72
|
//# sourceMappingURL=Hooks.js.map
|
package/lib/Hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Hooks.js","sources":["../src/Hooks/index.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from 'react';\r\n\r\nexport * from './useInfiniteScroll';\r\nexport * from './useNetworkState';\r\nexport * from './useShortcuts';\r\n\r\n/**\r\n * React effect hook that invokes only on update.\r\n * It doesn't invoke on mount\r\n */\r\nexport const useUpdateEffect: typeof useEffect = (effect, deps) => {\r\n const mounted = useRef(false);\r\n\r\n useEffect(() => {\r\n if (mounted.current) {\r\n return effect();\r\n }\r\n mounted.current = true;\r\n return undefined;\r\n // eslint-disable-next-line react-hooks/exhaustive-deps\r\n }, deps);\r\n\r\n return mounted.current;\r\n};\r\n\r\n/**\r\n * React hook to persist any value between renders,\r\n * but keeps it up-to-date if it changes.\r\n *\r\n * @param value the value or function to persist\r\n */\r\nexport function useLatestRef<T>(value: T) {\r\n const ref = useRef(value);\r\n\r\n useEffect(() => {\r\n ref.current = value;\r\n }, [value]);\r\n\r\n return ref;\r\n}\r\n\r\n/**\r\n * useCallbackRef hook\r\n *\r\n * A custom hook that converts a callback to a ref to avoid triggering re-renders\r\n * ..when passed as a prop or avoid re-executing effects when passed as a dependency\r\n *\r\n * @param callback The callback to write to a ref object\r\n */\r\nexport const useCallbackRef = <T extends (...args: any[]) => any>(callback: T | undefined): T => {\r\n const callbackRef = useRef(callback);\r\n\r\n useEffect(() => {\r\n callbackRef.current = callback;\r\n });\r\n\r\n return useCallback(\r\n ((...args) => {\r\n return callbackRef.current?.(...args);\r\n }) as T,\r\n []\r\n );\r\n};\r\n\r\n/**\r\n * useFirstRenderState hook\r\n *\r\n * Returns \"true\" if component is just mounted (first render), else \"false\".\r\n */\r\nexport const useFirstRenderState = (): boolean => {\r\n const isFirst = useRef(true);\r\n\r\n if (isFirst.current) {\r\n isFirst.current = false;\r\n return true;\r\n }\r\n\r\n return isFirst.current;\r\n};\r\n\r\n/**\r\n * React Hook that provides a declarative `setInterval`\r\n *\r\n * @param callback the callback to execute at interval\r\n * @param delay the `setInterval` delay (in ms)\r\n */\r\nexport function useInterval(callback: () => void, delay: number | null) {\r\n const savedCallback = useLatestRef(callback);\r\n\r\n useEffect(() => {\r\n const tick = () => {\r\n savedCallback.current?.();\r\n };\r\n if (delay !== null) {\r\n const id = setInterval(tick, delay);\r\n return () => clearInterval(id);\r\n }\r\n }, [delay, savedCallback]);\r\n}\r\n\r\n/**\r\n * React hook that provides a declarative `setTimeout`\r\n *\r\n * @param callback the callback to run after specified delay\r\n * @param delay the delay (in ms)\r\n */\r\nexport function useTimeout(callback: Function, delay: number | null) {\r\n const savedCallback = useLatestRef(callback);\r\n\r\n useEffect(() => {\r\n if (delay == null) return;\r\n\r\n const timeoutId = setTimeout(() => {\r\n savedCallback.current?.();\r\n }, delay);\r\n\r\n return () => clearTimeout(timeoutId);\r\n }, [delay, savedCallback]);\r\n}\r\n"],"names":["useUpdateEffect","effect","deps","mounted","useRef","useEffect","useLatestRef","value","ref","useCallbackRef","callback","callbackRef","useCallback","args","useFirstRenderState","isFirst","useInterval","delay","savedCallback","tick","id","useTimeout","timeoutId"],"mappings":";;;;AAUO,MAAMA,IAAoC,CAACC,GAAQC,MAAS;AACjE,QAAMC,IAAUC,EAAO,EAAK;AAE5B,SAAAC,EAAU,MAAM;AACd,QAAIF,EAAQ;AACV,aAAOF,EAAA;AAET,IAAAE,EAAQ,UAAU;AAAA,EAGpB,GAAGD,CAAI,GAEAC,EAAQ;AACjB;AAQO,SAASG,EAAgBC,GAAU;AACxC,QAAMC,IAAMJ,EAAOG,CAAK;AAExB,SAAAF,EAAU,MAAM;AACd,IAAAG,EAAI,UAAUD;AAAA,EAChB,GAAG,CAACA,CAAK,CAAC,GAEHC;AACT;AAUO,MAAMC,IAAiB,CAAoCC,MAA+B;AAC/F,QAAMC,IAAcP,EAAOM,CAAQ;AAEnC,SAAAL,EAAU,MAAM;AACd,IAAAM,EAAY,UAAUD;AAAA,EACxB,CAAC,GAEME;AAAA,KACJ,IAAIC,
|
|
1
|
+
{"version":3,"file":"Hooks.js","sources":["../src/Hooks/index.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from 'react';\r\n\r\nexport * from './useInfiniteScroll';\r\nexport * from './useNetworkState';\r\nexport * from './useShortcuts';\r\n\r\n/**\r\n * React effect hook that invokes only on update.\r\n * It doesn't invoke on mount\r\n */\r\nexport const useUpdateEffect: typeof useEffect = (effect, deps) => {\r\n const mounted = useRef(false);\r\n\r\n useEffect(() => {\r\n if (mounted.current) {\r\n return effect();\r\n }\r\n mounted.current = true;\r\n return undefined;\r\n // eslint-disable-next-line react-hooks/exhaustive-deps\r\n }, deps);\r\n\r\n return mounted.current;\r\n};\r\n\r\n/**\r\n * React hook to persist any value between renders,\r\n * but keeps it up-to-date if it changes.\r\n *\r\n * @param value the value or function to persist\r\n */\r\nexport function useLatestRef<T>(value: T) {\r\n const ref = useRef(value);\r\n\r\n useEffect(() => {\r\n ref.current = value;\r\n }, [value]);\r\n\r\n return ref;\r\n}\r\n\r\n/**\r\n * useCallbackRef hook\r\n *\r\n * A custom hook that converts a callback to a ref to avoid triggering re-renders\r\n * ..when passed as a prop or avoid re-executing effects when passed as a dependency\r\n *\r\n * @param callback The callback to write to a ref object\r\n */\r\nexport const useCallbackRef = <T extends (...args: any[]) => any>(callback: T | undefined): T => {\r\n const callbackRef = useRef(callback);\r\n\r\n useEffect(() => {\r\n callbackRef.current = callback;\r\n });\r\n\r\n return useCallback(\r\n ((...args) => {\r\n return callbackRef.current?.(...args);\r\n }) as T,\r\n []\r\n );\r\n};\r\n\r\n/**\r\n * useFirstRenderState hook\r\n *\r\n * Returns \"true\" if component is just mounted (first render), else \"false\".\r\n */\r\nexport const useFirstRenderState = (): boolean => {\r\n const isFirst = useRef(true);\r\n\r\n if (isFirst.current) {\r\n isFirst.current = false;\r\n return true;\r\n }\r\n\r\n return isFirst.current;\r\n};\r\n\r\n/**\r\n * React Hook that provides a declarative `setInterval`\r\n *\r\n * @param callback the callback to execute at interval\r\n * @param delay the `setInterval` delay (in ms)\r\n */\r\nexport function useInterval(callback: () => void, delay: number | null) {\r\n const savedCallback = useLatestRef(callback);\r\n\r\n useEffect(() => {\r\n const tick = () => {\r\n savedCallback.current?.();\r\n };\r\n if (delay !== null) {\r\n const id = setInterval(tick, delay);\r\n return () => clearInterval(id);\r\n }\r\n }, [delay, savedCallback]);\r\n}\r\n\r\n/**\r\n * React hook that provides a declarative `setTimeout`\r\n *\r\n * @param callback the callback to run after specified delay\r\n * @param delay the delay (in ms)\r\n */\r\nexport function useTimeout(callback: Function, delay: number | null) {\r\n const savedCallback = useLatestRef(callback);\r\n\r\n useEffect(() => {\r\n if (delay == null) return;\r\n\r\n const timeoutId = setTimeout(() => {\r\n savedCallback.current?.();\r\n }, delay);\r\n\r\n return () => clearTimeout(timeoutId);\r\n }, [delay, savedCallback]);\r\n}\r\n"],"names":["useUpdateEffect","effect","deps","mounted","useRef","useEffect","useLatestRef","value","ref","useCallbackRef","callback","callbackRef","useCallback","args","_a","useFirstRenderState","isFirst","useInterval","delay","savedCallback","tick","id","useTimeout","timeoutId"],"mappings":";;;;AAUO,MAAMA,IAAoC,CAACC,GAAQC,MAAS;AACjE,QAAMC,IAAUC,EAAO,EAAK;AAE5B,SAAAC,EAAU,MAAM;AACd,QAAIF,EAAQ;AACV,aAAOF,EAAA;AAET,IAAAE,EAAQ,UAAU;AAAA,EAGpB,GAAGD,CAAI,GAEAC,EAAQ;AACjB;AAQO,SAASG,EAAgBC,GAAU;AACxC,QAAMC,IAAMJ,EAAOG,CAAK;AAExB,SAAAF,EAAU,MAAM;AACd,IAAAG,EAAI,UAAUD;AAAA,EAChB,GAAG,CAACA,CAAK,CAAC,GAEHC;AACT;AAUO,MAAMC,IAAiB,CAAoCC,MAA+B;AAC/F,QAAMC,IAAcP,EAAOM,CAAQ;AAEnC,SAAAL,EAAU,MAAM;AACd,IAAAM,EAAY,UAAUD;AAAA,EACxB,CAAC,GAEME;AAAA,KACJ,IAAIC,MAAS;;AACZ,cAAOC,IAAAH,EAAY,YAAZ,gBAAAG,EAAA,KAAAH,GAAsB,GAAGE;AAAA,IAClC;AAAA,IACA,CAAA;AAAA,EAAC;AAEL,GAOaE,IAAsB,MAAe;AAChD,QAAMC,IAAUZ,EAAO,EAAI;AAE3B,SAAIY,EAAQ,WACVA,EAAQ,UAAU,IACX,MAGFA,EAAQ;AACjB;AAQO,SAASC,EAAYP,GAAsBQ,GAAsB;AACtE,QAAMC,IAAgBb,EAAaI,CAAQ;AAE3C,EAAAL,EAAU,MAAM;AACd,UAAMe,IAAO,MAAM;;AACjB,OAAAN,IAAAK,EAAc,YAAd,QAAAL,EAAA,KAAAK;AAAA,IACF;AACA,QAAID,MAAU,MAAM;AAClB,YAAMG,IAAK,YAAYD,GAAMF,CAAK;AAClC,aAAO,MAAM,cAAcG,CAAE;AAAA,IAC/B;AAAA,EACF,GAAG,CAACH,GAAOC,CAAa,CAAC;AAC3B;AAQO,SAASG,EAAWZ,GAAoBQ,GAAsB;AACnE,QAAMC,IAAgBb,EAAaI,CAAQ;AAE3C,EAAAL,EAAU,MAAM;AACd,QAAIa,KAAS,KAAM;AAEnB,UAAMK,IAAY,WAAW,MAAM;;AACjC,OAAAT,IAAAK,EAAc,YAAd,QAAAL,EAAA,KAAAK;AAAA,IACF,GAAGD,CAAK;AAER,WAAO,MAAM,aAAaK,CAAS;AAAA,EACrC,GAAG,CAACL,GAAOC,CAAa,CAAC;AAC3B;"}
|
package/lib/Utilities.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ApiUtility as o, FileDownloadStatus as r, HttpMethods as i } from "./src/Utilities/ApiUtility.axios.js";
|
|
2
|
-
import { getBrowserDoNotTrackStatus as s, getBrowserPluginsAsString as
|
|
2
|
+
import { getBrowserDoNotTrackStatus as s, getBrowserPluginsAsString as g, getDeviceLocalIPAsString as a, getScreenColourDepth as m, getScreenHeight as p, getScreenScalingFactor as l, getScreenWidth as u, getTimezone as f, getUserAgent as d, getWindowHeight as S, getWindowWidth as c, resetDeviceIpString as x, resetDeviceIpTimeStamp as D } from "./src/Utilities/BrowserInfo.js";
|
|
3
3
|
import { AllCountries as w, getCountries as y, getCountryByPhoneNumber as A, getCountryOptions as C } from "./src/Utilities/Countries.js";
|
|
4
4
|
import { CustomEventEmitter as H } from "./src/Utilities/CustomEventEmitter.js";
|
|
5
|
-
import {
|
|
5
|
+
import { dayjs as T } from "./src/Utilities/dayjs.js";
|
|
6
6
|
import { fastCompare as I } from "./src/Utilities/FastCompare.js";
|
|
7
7
|
import { HideablePromise as U } from "./src/Utilities/HideablePromise.js";
|
|
8
8
|
import { LoadScript as B } from "./src/Utilities/LoadScripts.js";
|
|
@@ -29,11 +29,11 @@ export {
|
|
|
29
29
|
I as fastCompare,
|
|
30
30
|
M as fraudPreventionHeadersEnum,
|
|
31
31
|
s as getBrowserDoNotTrackStatus,
|
|
32
|
-
|
|
32
|
+
g as getBrowserPluginsAsString,
|
|
33
33
|
y as getCountries,
|
|
34
34
|
A as getCountryByPhoneNumber,
|
|
35
35
|
C as getCountryOptions,
|
|
36
|
-
|
|
36
|
+
a as getDeviceLocalIPAsString,
|
|
37
37
|
O as getFraudPreventionHeaders,
|
|
38
38
|
j as getNationalityOptions,
|
|
39
39
|
m as getScreenColourDepth,
|
|
@@ -42,8 +42,8 @@ export {
|
|
|
42
42
|
l as getScreenScalingFactor,
|
|
43
43
|
u as getScreenWidth,
|
|
44
44
|
J as getTimeZoneOptions,
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
f as getTimezone,
|
|
46
|
+
d as getUserAgent,
|
|
47
47
|
S as getWindowHeight,
|
|
48
48
|
c as getWindowWidth,
|
|
49
49
|
x as resetDeviceIpString,
|
package/lib/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { SuspenseRoute as o } from "./src/Components/SuspenseRoute.js";
|
|
2
2
|
import { useCallbackRef as i, useFirstRenderState as s, useInterval as n, useLatestRef as a, useTimeout as p, useUpdateEffect as u } from "./Hooks.js";
|
|
3
3
|
import { ApiUtility as m, FileDownloadStatus as f, HttpMethods as l } from "./src/Utilities/ApiUtility.axios.js";
|
|
4
|
-
import { getBrowserDoNotTrackStatus as
|
|
4
|
+
import { getBrowserDoNotTrackStatus as d, getBrowserPluginsAsString as x, getDeviceLocalIPAsString as c, getScreenColourDepth as v, getScreenHeight as w, getScreenScalingFactor as h, getScreenWidth as C, getTimezone as D, getUserAgent as y, getWindowHeight as A, getWindowWidth as P, resetDeviceIpString as H, resetDeviceIpTimeStamp as I } from "./src/Utilities/BrowserInfo.js";
|
|
5
5
|
import { AllCountries as R, getCountries as T, getCountryByPhoneNumber as E, getCountryOptions as F } from "./src/Utilities/Countries.js";
|
|
6
6
|
import { CustomEventEmitter as b } from "./src/Utilities/CustomEventEmitter.js";
|
|
7
|
-
import {
|
|
7
|
+
import { dayjs as W } from "./src/Utilities/dayjs.js";
|
|
8
8
|
import { fastCompare as L } from "./src/Utilities/FastCompare.js";
|
|
9
9
|
import { HideablePromise as O } from "./src/Utilities/HideablePromise.js";
|
|
10
10
|
import { LoadScript as j } from "./src/Utilities/LoadScripts.js";
|
|
@@ -15,7 +15,7 @@ import { AllTimeZones as te, getTimeZoneOptions as oe } from "./src/Utilities/Ti
|
|
|
15
15
|
import { StorageMessageKey as ie, Utils as se, useIsMountedRef as ne } from "./src/Utilities/Utils.js";
|
|
16
16
|
import { useInfiniteScroll as pe } from "./src/Hooks/useInfiniteScroll.js";
|
|
17
17
|
import { isBrowser as ge, isNavigator as me, useNetworkState as fe } from "./src/Hooks/useNetworkState.js";
|
|
18
|
-
import { disabledEventPropagation as
|
|
18
|
+
import { disabledEventPropagation as Se, useShortcuts as de } from "./src/Hooks/useShortcuts.js";
|
|
19
19
|
export {
|
|
20
20
|
R as AllCountries,
|
|
21
21
|
V as AllNationalities,
|
|
@@ -32,10 +32,10 @@ export {
|
|
|
32
32
|
o as SuspenseRoute,
|
|
33
33
|
se as Utils,
|
|
34
34
|
W as dayjs,
|
|
35
|
-
|
|
35
|
+
Se as disabledEventPropagation,
|
|
36
36
|
L as fastCompare,
|
|
37
37
|
K as fraudPreventionHeadersEnum,
|
|
38
|
-
|
|
38
|
+
d as getBrowserDoNotTrackStatus,
|
|
39
39
|
x as getBrowserPluginsAsString,
|
|
40
40
|
T as getCountries,
|
|
41
41
|
E as getCountryByPhoneNumber,
|
|
@@ -64,7 +64,7 @@ export {
|
|
|
64
64
|
ne as useIsMountedRef,
|
|
65
65
|
a as useLatestRef,
|
|
66
66
|
fe as useNetworkState,
|
|
67
|
-
|
|
67
|
+
de as useShortcuts,
|
|
68
68
|
p as useTimeout,
|
|
69
69
|
u as useUpdateEffect,
|
|
70
70
|
J as windowDetails
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import
|
|
2
|
-
const
|
|
3
|
-
function r(
|
|
4
|
-
const i = t
|
|
1
|
+
import d from "react";
|
|
2
|
+
const a = typeof window != "undefined", w = typeof navigator != "undefined", t = w ? navigator : void 0, e = t && (t.connection || t.mozConnection || t.webkitConnection);
|
|
3
|
+
function r(n) {
|
|
4
|
+
const i = t == null ? void 0 : t.onLine, s = n == null ? void 0 : n.online;
|
|
5
5
|
return {
|
|
6
6
|
online: i,
|
|
7
7
|
previous: s,
|
|
8
|
-
since: i !== s ? /* @__PURE__ */ new Date() :
|
|
9
|
-
downlink: e
|
|
10
|
-
downlinkMax: e
|
|
11
|
-
effectiveType: e
|
|
12
|
-
rtt: e
|
|
13
|
-
saveData: e
|
|
14
|
-
type: e
|
|
8
|
+
since: i !== s ? /* @__PURE__ */ new Date() : n == null ? void 0 : n.since,
|
|
9
|
+
downlink: e == null ? void 0 : e.downlink,
|
|
10
|
+
downlinkMax: e == null ? void 0 : e.downlinkMax,
|
|
11
|
+
effectiveType: e == null ? void 0 : e.effectiveType,
|
|
12
|
+
rtt: e == null ? void 0 : e.rtt,
|
|
13
|
+
saveData: e == null ? void 0 : e.saveData,
|
|
14
|
+
type: e == null ? void 0 : e.type
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
-
function
|
|
18
|
-
const [i, s] =
|
|
19
|
-
return
|
|
20
|
-
const
|
|
17
|
+
function c(n) {
|
|
18
|
+
const [i, s] = d.useState(n != null ? n : r);
|
|
19
|
+
return d.useEffect(() => {
|
|
20
|
+
const o = () => {
|
|
21
21
|
s(r);
|
|
22
22
|
};
|
|
23
|
-
return window.addEventListener("online",
|
|
24
|
-
window.removeEventListener("online",
|
|
23
|
+
return window.addEventListener("online", o, { passive: !0 }), window.addEventListener("offline", o, { passive: !0 }), e && window.addEventListener("change", o, { passive: !0 }), () => {
|
|
24
|
+
window.removeEventListener("online", o), window.removeEventListener("offline", o), e && window.removeEventListener("change", o);
|
|
25
25
|
};
|
|
26
26
|
}, []), i;
|
|
27
27
|
}
|
|
28
28
|
export {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
a as isBrowser,
|
|
30
|
+
w as isNavigator,
|
|
31
|
+
c as useNetworkState
|
|
32
32
|
};
|
|
33
33
|
//# sourceMappingURL=useNetworkState.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNetworkState.js","sources":["../../../src/Hooks/useNetworkState.ts"],"sourcesContent":["import React from 'react';\r\n\r\nexport interface INetworkInformation extends EventTarget {\r\n readonly downlink: number;\r\n readonly downlinkMax: number;\r\n readonly effectiveType: 'slow-2g' | '2g' | '3g' | '4g';\r\n readonly rtt: number;\r\n readonly saveData: boolean;\r\n readonly type: 'bluetooth' | 'cellular' | 'ethernet' | 'none' | 'wifi' | 'wimax' | 'other' | 'unknown';\r\n\r\n onChange: (event: Event) => void;\r\n}\r\n\r\nexport interface IUseNetworkState {\r\n /**\r\n * @desc Whether browser connected to the network or not.\r\n */\r\n online: boolean | undefined;\r\n /**\r\n * @desc Previous value of `online` property. Helps to identify if browser\r\n * just connected or lost connection.\r\n */\r\n previous: boolean | undefined;\r\n /**\r\n * @desc The {Date} object pointing to the moment when state change occurred.\r\n */\r\n since: Date | undefined;\r\n /**\r\n * @desc Effective bandwidth estimate in megabits per second, rounded to the\r\n * nearest multiple of 25 kilobits per seconds.\r\n */\r\n downlink: INetworkInformation['downlink'] | undefined;\r\n /**\r\n * @desc Maximum downlink speed, in megabits per second (Mbps), for the\r\n * underlying connection technology\r\n */\r\n downlinkMax: INetworkInformation['downlinkMax'] | undefined;\r\n /**\r\n * @desc Effective type of the connection meaning one of 'slow-2g', '2g', '3g', or '4g'.\r\n * This value is determined using a combination of recently observed round-trip time\r\n * and downlink values.\r\n */\r\n effectiveType: INetworkInformation['effectiveType'] | undefined;\r\n /**\r\n * @desc Estimated effective round-trip time of the current connection, rounded\r\n * to the nearest multiple of 25 milliseconds\r\n */\r\n rtt: INetworkInformation['rtt'] | undefined;\r\n /**\r\n * @desc {true} if the user has set a reduced data usage option on the user agent.\r\n */\r\n saveData: INetworkInformation['saveData'] | undefined;\r\n /**\r\n * @desc The type of connection a device is using to communicate with the network.\r\n * It will be one of the following values:\r\n * - bluetooth\r\n * - cellular\r\n * - ethernet\r\n * - none\r\n * - wifi\r\n * - wimax\r\n * - other\r\n * - unknown\r\n */\r\n type: INetworkInformation['type'] | undefined;\r\n}\r\nexport const isBrowser = typeof window !== 'undefined';\r\nexport const isNavigator = typeof navigator !== 'undefined';\r\n\r\nconst nav: (Navigator & Partial<Record<'connection' | 'mozConnection' | 'webkitConnection', INetworkInformation>>) | undefined = isNavigator ? navigator : undefined;\r\nconst conn: INetworkInformation | undefined = nav && (nav.connection || nav.mozConnection || nav.webkitConnection);\r\n\r\nfunction getConnectionState(previousState?: IUseNetworkState): IUseNetworkState {\r\n const online = nav?.onLine;\r\n const previousOnline = previousState?.online;\r\n\r\n return {\r\n online,\r\n previous: previousOnline,\r\n since: online !== previousOnline ? new Date() : previousState?.since,\r\n downlink: conn?.downlink,\r\n downlinkMax: conn?.downlinkMax,\r\n effectiveType: conn?.effectiveType,\r\n rtt: conn?.rtt,\r\n saveData: conn?.saveData,\r\n type: conn?.type,\r\n };\r\n}\r\n\r\nexport type IHookStateInitialSetter<S> = () => S;\r\nexport type IHookStateInitAction<S> = S | IHookStateInitialSetter<S>;\r\n\r\nexport function useNetworkState(initialState?: IHookStateInitAction<IUseNetworkState>): IUseNetworkState {\r\n const [state, setState] = React.useState(initialState ?? getConnectionState);\r\n\r\n React.useEffect(() => {\r\n const handleStateChange = () => {\r\n setState(getConnectionState);\r\n };\r\n\r\n window.addEventListener('online', handleStateChange, { passive: true });\r\n window.addEventListener('offline', handleStateChange, { passive: true });\r\n\r\n if (conn) {\r\n window.addEventListener('change', handleStateChange, { passive: true });\r\n }\r\n\r\n return () => {\r\n window.removeEventListener('online', handleStateChange);\r\n window.removeEventListener('offline', handleStateChange);\r\n\r\n if (conn) {\r\n window.removeEventListener('change', handleStateChange);\r\n }\r\n };\r\n }, []);\r\n\r\n return state;\r\n}\r\n"],"names":["isBrowser","isNavigator","nav","conn","getConnectionState","previousState","online","previousOnline","useNetworkState","initialState","state","setState","React","handleStateChange"],"mappings":";AAkEO,MAAMA,IAAY,OAAO,
|
|
1
|
+
{"version":3,"file":"useNetworkState.js","sources":["../../../src/Hooks/useNetworkState.ts"],"sourcesContent":["import React from 'react';\r\n\r\nexport interface INetworkInformation extends EventTarget {\r\n readonly downlink: number;\r\n readonly downlinkMax: number;\r\n readonly effectiveType: 'slow-2g' | '2g' | '3g' | '4g';\r\n readonly rtt: number;\r\n readonly saveData: boolean;\r\n readonly type: 'bluetooth' | 'cellular' | 'ethernet' | 'none' | 'wifi' | 'wimax' | 'other' | 'unknown';\r\n\r\n onChange: (event: Event) => void;\r\n}\r\n\r\nexport interface IUseNetworkState {\r\n /**\r\n * @desc Whether browser connected to the network or not.\r\n */\r\n online: boolean | undefined;\r\n /**\r\n * @desc Previous value of `online` property. Helps to identify if browser\r\n * just connected or lost connection.\r\n */\r\n previous: boolean | undefined;\r\n /**\r\n * @desc The {Date} object pointing to the moment when state change occurred.\r\n */\r\n since: Date | undefined;\r\n /**\r\n * @desc Effective bandwidth estimate in megabits per second, rounded to the\r\n * nearest multiple of 25 kilobits per seconds.\r\n */\r\n downlink: INetworkInformation['downlink'] | undefined;\r\n /**\r\n * @desc Maximum downlink speed, in megabits per second (Mbps), for the\r\n * underlying connection technology\r\n */\r\n downlinkMax: INetworkInformation['downlinkMax'] | undefined;\r\n /**\r\n * @desc Effective type of the connection meaning one of 'slow-2g', '2g', '3g', or '4g'.\r\n * This value is determined using a combination of recently observed round-trip time\r\n * and downlink values.\r\n */\r\n effectiveType: INetworkInformation['effectiveType'] | undefined;\r\n /**\r\n * @desc Estimated effective round-trip time of the current connection, rounded\r\n * to the nearest multiple of 25 milliseconds\r\n */\r\n rtt: INetworkInformation['rtt'] | undefined;\r\n /**\r\n * @desc {true} if the user has set a reduced data usage option on the user agent.\r\n */\r\n saveData: INetworkInformation['saveData'] | undefined;\r\n /**\r\n * @desc The type of connection a device is using to communicate with the network.\r\n * It will be one of the following values:\r\n * - bluetooth\r\n * - cellular\r\n * - ethernet\r\n * - none\r\n * - wifi\r\n * - wimax\r\n * - other\r\n * - unknown\r\n */\r\n type: INetworkInformation['type'] | undefined;\r\n}\r\nexport const isBrowser = typeof window !== 'undefined';\r\nexport const isNavigator = typeof navigator !== 'undefined';\r\n\r\nconst nav: (Navigator & Partial<Record<'connection' | 'mozConnection' | 'webkitConnection', INetworkInformation>>) | undefined = isNavigator ? navigator : undefined;\r\nconst conn: INetworkInformation | undefined = nav && (nav.connection || nav.mozConnection || nav.webkitConnection);\r\n\r\nfunction getConnectionState(previousState?: IUseNetworkState): IUseNetworkState {\r\n const online = nav?.onLine;\r\n const previousOnline = previousState?.online;\r\n\r\n return {\r\n online,\r\n previous: previousOnline,\r\n since: online !== previousOnline ? new Date() : previousState?.since,\r\n downlink: conn?.downlink,\r\n downlinkMax: conn?.downlinkMax,\r\n effectiveType: conn?.effectiveType,\r\n rtt: conn?.rtt,\r\n saveData: conn?.saveData,\r\n type: conn?.type,\r\n };\r\n}\r\n\r\nexport type IHookStateInitialSetter<S> = () => S;\r\nexport type IHookStateInitAction<S> = S | IHookStateInitialSetter<S>;\r\n\r\nexport function useNetworkState(initialState?: IHookStateInitAction<IUseNetworkState>): IUseNetworkState {\r\n const [state, setState] = React.useState(initialState ?? getConnectionState);\r\n\r\n React.useEffect(() => {\r\n const handleStateChange = () => {\r\n setState(getConnectionState);\r\n };\r\n\r\n window.addEventListener('online', handleStateChange, { passive: true });\r\n window.addEventListener('offline', handleStateChange, { passive: true });\r\n\r\n if (conn) {\r\n window.addEventListener('change', handleStateChange, { passive: true });\r\n }\r\n\r\n return () => {\r\n window.removeEventListener('online', handleStateChange);\r\n window.removeEventListener('offline', handleStateChange);\r\n\r\n if (conn) {\r\n window.removeEventListener('change', handleStateChange);\r\n }\r\n };\r\n }, []);\r\n\r\n return state;\r\n}\r\n"],"names":["isBrowser","isNavigator","nav","conn","getConnectionState","previousState","online","previousOnline","useNetworkState","initialState","state","setState","React","handleStateChange"],"mappings":";AAkEO,MAAMA,IAAY,OAAO,UAAW,aAC9BC,IAAc,OAAO,aAAc,aAE1CC,IAA2HD,IAAc,YAAY,QACrJE,IAAwCD,MAAQA,EAAI,cAAcA,EAAI,iBAAiBA,EAAI;AAEjG,SAASE,EAAmBC,GAAoD;AAC9E,QAAMC,IAASJ,KAAA,gBAAAA,EAAK,QACdK,IAAiBF,KAAA,gBAAAA,EAAe;AAEtC,SAAO;AAAA,IACL,QAAAC;AAAA,IACA,UAAUC;AAAA,IACV,OAAOD,MAAWC,IAAiB,oBAAI,KAAA,IAASF,KAAA,gBAAAA,EAAe;AAAA,IAC/D,UAAUF,KAAA,gBAAAA,EAAM;AAAA,IAChB,aAAaA,KAAA,gBAAAA,EAAM;AAAA,IACnB,eAAeA,KAAA,gBAAAA,EAAM;AAAA,IACrB,KAAKA,KAAA,gBAAAA,EAAM;AAAA,IACX,UAAUA,KAAA,gBAAAA,EAAM;AAAA,IAChB,MAAMA,KAAA,gBAAAA,EAAM;AAAA,EAAA;AAEhB;AAKO,SAASK,EAAgBC,GAAyE;AACvG,QAAM,CAACC,GAAOC,CAAQ,IAAIC,EAAM,SAASH,KAAA,OAAAA,IAAgBL,CAAkB;AAE3E,SAAAQ,EAAM,UAAU,MAAM;AACpB,UAAMC,IAAoB,MAAM;AAC9B,MAAAF,EAASP,CAAkB;AAAA,IAC7B;AAEA,kBAAO,iBAAiB,UAAUS,GAAmB,EAAE,SAAS,IAAM,GACtE,OAAO,iBAAiB,WAAWA,GAAmB,EAAE,SAAS,IAAM,GAEnEV,KACF,OAAO,iBAAiB,UAAUU,GAAmB,EAAE,SAAS,IAAM,GAGjE,MAAM;AACX,aAAO,oBAAoB,UAAUA,CAAiB,GACtD,OAAO,oBAAoB,WAAWA,CAAiB,GAEnDV,KACF,OAAO,oBAAoB,UAAUU,CAAiB;AAAA,IAE1D;AAAA,EACF,GAAG,CAAA,CAAE,GAEEH;AACT;"}
|