@capsitech/react-utilities 0.1.10 → 0.1.11

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.
Files changed (102) hide show
  1. package/lib/Components/SuspenseRoute.js +29 -0
  2. package/lib/Components/index.js +1 -0
  3. package/lib/Hooks/index.d.ts +2 -2
  4. package/lib/Hooks/index.js +98 -0
  5. package/lib/Hooks/useInfiniteScroll.d.ts +1 -1
  6. package/lib/Hooks/useInfiniteScroll.js +22 -0
  7. package/lib/Hooks/useNetworkState.js +41 -0
  8. package/lib/Hooks/useShortcuts.js +91 -0
  9. package/lib/Utilities/ApiUtility.axios.js +326 -0
  10. package/lib/Utilities/BrowserInfo.js +153 -0
  11. package/lib/Utilities/Countries.js +290 -0
  12. package/lib/Utilities/CustomEventEmitter.js +30 -0
  13. package/lib/Utilities/FastCompare.js +128 -0
  14. package/lib/Utilities/HideablePromise.js +10 -0
  15. package/lib/Utilities/LoadScripts.js +51 -0
  16. package/lib/Utilities/MTDFraudPrevention.js +157 -0
  17. package/lib/Utilities/Nationalities.js +245 -0
  18. package/lib/Utilities/RouteUtils.d.ts +1 -1
  19. package/lib/Utilities/RouteUtils.js +223 -0
  20. package/lib/Utilities/TimeZones.js +1069 -0
  21. package/lib/Utilities/Types.js +1 -0
  22. package/lib/Utilities/Utils.d.ts +1 -1
  23. package/lib/Utilities/Utils.js +331 -0
  24. package/lib/Utilities/dayjs.d.ts +11 -10
  25. package/lib/Utilities/dayjs.js +57 -0
  26. package/lib/Utilities/index.js +14 -0
  27. package/lib/index.js +3 -72
  28. package/package.json +10 -57
  29. package/lib/Components.d.ts +0 -2
  30. package/lib/Components.js +0 -5
  31. package/lib/Components.js.map +0 -1
  32. package/lib/Hooks.d.ts +0 -2
  33. package/lib/Hooks.js +0 -72
  34. package/lib/Hooks.js.map +0 -1
  35. package/lib/Utilities.d.ts +0 -2
  36. package/lib/Utilities.js +0 -54
  37. package/lib/Utilities.js.map +0 -1
  38. package/lib/index.js.map +0 -1
  39. package/lib/logo.png +0 -0
  40. package/lib/src/Components/SuspenseRoute.d.ts +0 -2
  41. package/lib/src/Components/SuspenseRoute.js +0 -22
  42. package/lib/src/Components/SuspenseRoute.js.map +0 -1
  43. package/lib/src/Components/index.d.ts +0 -2
  44. package/lib/src/Components/index.js +0 -5
  45. package/lib/src/Components/index.js.map +0 -1
  46. package/lib/src/Hooks/index.d.ts +0 -2
  47. package/lib/src/Hooks/index.js +0 -20
  48. package/lib/src/Hooks/index.js.map +0 -1
  49. package/lib/src/Hooks/useInfiniteScroll.d.ts +0 -2
  50. package/lib/src/Hooks/useInfiniteScroll.js +0 -20
  51. package/lib/src/Hooks/useInfiniteScroll.js.map +0 -1
  52. package/lib/src/Hooks/useNetworkState.d.ts +0 -2
  53. package/lib/src/Hooks/useNetworkState.js +0 -33
  54. package/lib/src/Hooks/useNetworkState.js.map +0 -1
  55. package/lib/src/Hooks/useShortcuts.d.ts +0 -2
  56. package/lib/src/Hooks/useShortcuts.js +0 -43
  57. package/lib/src/Hooks/useShortcuts.js.map +0 -1
  58. package/lib/src/Utilities/ApiUtility.axios.d.ts +0 -2
  59. package/lib/src/Utilities/ApiUtility.axios.js +0 -228
  60. package/lib/src/Utilities/ApiUtility.axios.js.map +0 -1
  61. package/lib/src/Utilities/BrowserInfo.d.ts +0 -2
  62. package/lib/src/Utilities/BrowserInfo.js +0 -51
  63. package/lib/src/Utilities/BrowserInfo.js.map +0 -1
  64. package/lib/src/Utilities/Countries.d.ts +0 -2
  65. package/lib/src/Utilities/Countries.js +0 -518
  66. package/lib/src/Utilities/Countries.js.map +0 -1
  67. package/lib/src/Utilities/CustomEventEmitter.d.ts +0 -2
  68. package/lib/src/Utilities/CustomEventEmitter.js +0 -27
  69. package/lib/src/Utilities/CustomEventEmitter.js.map +0 -1
  70. package/lib/src/Utilities/FastCompare.d.ts +0 -2
  71. package/lib/src/Utilities/FastCompare.js +0 -56
  72. package/lib/src/Utilities/FastCompare.js.map +0 -1
  73. package/lib/src/Utilities/HideablePromise.d.ts +0 -2
  74. package/lib/src/Utilities/HideablePromise.js +0 -18
  75. package/lib/src/Utilities/HideablePromise.js.map +0 -1
  76. package/lib/src/Utilities/LoadScripts.d.ts +0 -2
  77. package/lib/src/Utilities/LoadScripts.js +0 -26
  78. package/lib/src/Utilities/LoadScripts.js.map +0 -1
  79. package/lib/src/Utilities/MTDFraudPrevention.d.ts +0 -2
  80. package/lib/src/Utilities/MTDFraudPrevention.js +0 -60
  81. package/lib/src/Utilities/MTDFraudPrevention.js.map +0 -1
  82. package/lib/src/Utilities/Nationalities.d.ts +0 -2
  83. package/lib/src/Utilities/Nationalities.js +0 -250
  84. package/lib/src/Utilities/Nationalities.js.map +0 -1
  85. package/lib/src/Utilities/RouteUtils.d.ts +0 -2
  86. package/lib/src/Utilities/RouteUtils.js +0 -200
  87. package/lib/src/Utilities/RouteUtils.js.map +0 -1
  88. package/lib/src/Utilities/TimeZones.d.ts +0 -2
  89. package/lib/src/Utilities/TimeZones.js +0 -1074
  90. package/lib/src/Utilities/TimeZones.js.map +0 -1
  91. package/lib/src/Utilities/Types.d.ts +0 -1
  92. package/lib/src/Utilities/Types.js +0 -2
  93. package/lib/src/Utilities/Types.js.map +0 -1
  94. package/lib/src/Utilities/Utils.d.ts +0 -2
  95. package/lib/src/Utilities/Utils.js +0 -274
  96. package/lib/src/Utilities/Utils.js.map +0 -1
  97. package/lib/src/Utilities/dayjs.d.ts +0 -2
  98. package/lib/src/Utilities/dayjs.js +0 -42
  99. package/lib/src/Utilities/dayjs.js.map +0 -1
  100. package/lib/src/Utilities/index.d.ts +0 -2
  101. package/lib/src/Utilities/index.js +0 -54
  102. package/lib/src/Utilities/index.js.map +0 -1
package/lib/Hooks.js DELETED
@@ -1,72 +0,0 @@
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
- if (e.current)
9
- return r();
10
- e.current = !0;
11
- }, t), e.current;
12
- };
13
- function c(r) {
14
- const t = s(r);
15
- return o(() => {
16
- t.current = r;
17
- }, [r]), t;
18
- }
19
- const p = (r) => {
20
- const t = s(r);
21
- return o(() => {
22
- t.current = r;
23
- }), i(
24
- ((...e) => {
25
- var u;
26
- return (u = t.current) == null ? void 0 : u.call(t, ...e);
27
- }),
28
- []
29
- );
30
- }, I = () => {
31
- const r = s(!0);
32
- return r.current ? (r.current = !1, !0) : r.current;
33
- };
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);
40
- };
41
- if (t !== null) {
42
- const n = setInterval(u, t);
43
- return () => clearInterval(n);
44
- }
45
- }, [t, e]);
46
- }
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]);
57
- }
58
- export {
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,
66
- c as useLatestRef,
67
- g as useNetworkState,
68
- F as useShortcuts,
69
- l as useTimeout,
70
- m as useUpdateEffect
71
- };
72
- //# sourceMappingURL=Hooks.js.map
package/lib/Hooks.js.map DELETED
@@ -1 +0,0 @@
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;"}
@@ -1,2 +0,0 @@
1
- export * from './Utilities/index'
2
- export {}
package/lib/Utilities.js DELETED
@@ -1,54 +0,0 @@
1
- import { ApiUtility as o, FileDownloadStatus as r, HttpMethods as i } from "./src/Utilities/ApiUtility.axios.js";
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
- import { AllCountries as w, getCountries as y, getCountryByPhoneNumber as A, getCountryOptions as C } from "./src/Utilities/Countries.js";
4
- import { CustomEventEmitter as H } from "./src/Utilities/CustomEventEmitter.js";
5
- import { dayjs as T } from "./src/Utilities/dayjs.js";
6
- import { fastCompare as I } from "./src/Utilities/FastCompare.js";
7
- import { HideablePromise as U } from "./src/Utilities/HideablePromise.js";
8
- import { LoadScript as B } from "./src/Utilities/LoadScripts.js";
9
- import { fraudPreventionHeadersEnum as M, getFraudPreventionHeaders as O, getScreenDetails as b, windowDetails as L } from "./src/Utilities/MTDFraudPrevention.js";
10
- import { AllNationalities as Z, getNationalityOptions as j } from "./src/Utilities/Nationalities.js";
11
- import { FeatureStatus as z, RouteUtils as K } from "./src/Utilities/RouteUtils.js";
12
- import { AllTimeZones as G, getTimeZoneOptions as J } from "./src/Utilities/TimeZones.js";
13
- import { StorageMessageKey as V, Utils as X, useIsMountedRef as Y } from "./src/Utilities/Utils.js";
14
- export {
15
- w as AllCountries,
16
- Z as AllNationalities,
17
- G as AllTimeZones,
18
- o as ApiUtility,
19
- H as CustomEventEmitter,
20
- z as FeatureStatus,
21
- r as FileDownloadStatus,
22
- U as HideablePromise,
23
- i as HttpMethods,
24
- B as LoadScript,
25
- K as RouteUtils,
26
- V as StorageMessageKey,
27
- X as Utils,
28
- T as dayjs,
29
- I as fastCompare,
30
- M as fraudPreventionHeadersEnum,
31
- s as getBrowserDoNotTrackStatus,
32
- g as getBrowserPluginsAsString,
33
- y as getCountries,
34
- A as getCountryByPhoneNumber,
35
- C as getCountryOptions,
36
- a as getDeviceLocalIPAsString,
37
- O as getFraudPreventionHeaders,
38
- j as getNationalityOptions,
39
- m as getScreenColourDepth,
40
- b as getScreenDetails,
41
- p as getScreenHeight,
42
- l as getScreenScalingFactor,
43
- u as getScreenWidth,
44
- J as getTimeZoneOptions,
45
- f as getTimezone,
46
- d as getUserAgent,
47
- S as getWindowHeight,
48
- c as getWindowWidth,
49
- x as resetDeviceIpString,
50
- D as resetDeviceIpTimeStamp,
51
- Y as useIsMountedRef,
52
- L as windowDetails
53
- };
54
- //# sourceMappingURL=Utilities.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Utilities.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;"}
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;"}
package/lib/logo.png DELETED
Binary file
@@ -1,2 +0,0 @@
1
- export * from '../../Components/SuspenseRoute'
2
- export {}
@@ -1,22 +0,0 @@
1
- import { jsx as t } from "react/jsx-runtime";
2
- import i from "react";
3
- const n = (e) => typeof e == "object" && e && e.hasOwnProperty("$$typeof") && e.hasOwnProperty("_payload") && e.hasOwnProperty("_init"), f = ({
4
- children: e,
5
- label: s = "Loading components...",
6
- fallback: r
7
- }) => n(e) ? (r || (r = o), /* @__PURE__ */ t(i.Suspense, { fallback: /* @__PURE__ */ t(r, { label: s }), children: /* @__PURE__ */ t(e, {}) })) : /* @__PURE__ */ t(e, {}), o = ({ label: e = "Loading components..." }) => /* @__PURE__ */ t("div", { style: {
8
- position: "fixed",
9
- top: 0,
10
- left: 0,
11
- width: "100%",
12
- height: "100%",
13
- backgroundColor: "rgba(0, 0, 0, 0.3)",
14
- zIndex: 9999,
15
- display: "flex",
16
- justifyContent: "center",
17
- alignItems: "center"
18
- }, children: e });
19
- export {
20
- f as SuspenseRoute
21
- };
22
- //# sourceMappingURL=SuspenseRoute.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SuspenseRoute.js","sources":["../../../src/Components/SuspenseRoute.tsx"],"sourcesContent":["import React from \"react\";\r\n\r\ninterface ISuspenseRouteProps {\r\n label?: string;\r\n children?: any;\r\n fallback?: any;\r\n}\r\n\r\nconst isSuspenseComponent = (component: any) =>\r\n typeof component === \"object\" &&\r\n component &&\r\n component.hasOwnProperty(\"$$typeof\") &&\r\n component.hasOwnProperty(\"_payload\") &&\r\n component.hasOwnProperty(\"_init\");\r\n\r\nexport const SuspenseRoute = ({\r\n children: Component,\r\n label = \"Loading components...\",\r\n fallback: FallbackComponent,\r\n}: ISuspenseRouteProps) => {\r\n if (isSuspenseComponent(Component)) {\r\n if (!FallbackComponent)\r\n FallbackComponent = SuspenseRouteFallback;\r\n\r\n return <React.Suspense fallback={<FallbackComponent label={label} />}>\r\n <Component />\r\n </React.Suspense>\r\n }\r\n return (\r\n <Component />\r\n );\r\n};\r\n\r\nconst SuspenseRouteFallback = ({ label = \"Loading components...\" }: { label?: string }) => {\r\n return <div style={{\r\n position: 'fixed',\r\n top: 0,\r\n left: 0,\r\n width: '100%',\r\n height: '100%',\r\n backgroundColor: 'rgba(0, 0, 0, 0.3)',\r\n zIndex: 9999,\r\n display: 'flex',\r\n justifyContent: 'center',\r\n alignItems: 'center'\r\n }}>{label}</div>;\r\n}"],"names":["isSuspenseComponent","component","SuspenseRoute","Component","label","FallbackComponent","SuspenseRouteFallback","jsx","React"],"mappings":";;AAQA,MAAMA,IAAsB,CAACC,MAC3B,OAAOA,KAAc,YACrBA,KACAA,EAAU,eAAe,UAAU,KACnCA,EAAU,eAAe,UAAU,KACnCA,EAAU,eAAe,OAAO,GAErBC,IAAgB,CAAC;AAAA,EAC5B,UAAUC;AAAA,EACV,OAAAC,IAAQ;AAAA,EACR,UAAUC;AACZ,MACML,EAAoBG,CAAS,KAC1BE,MACHA,IAAoBC,IAEf,gBAAAC,EAACC,EAAM,UAAN,EAAe,UAAU,gBAAAD,EAACF,GAAA,EAAkB,OAAAD,EAAA,CAAc,GAChE,UAAA,gBAAAG,EAACJ,GAAA,CAAA,CAAU,EAAA,CACb,uBAGCA,GAAA,EAAU,GAITG,IAAwB,CAAC,EAAE,OAAAF,IAAQ,8BAChC,gBAAAG,EAAC,SAAI,OAAO;AAAA,EACjB,UAAU;AAAA,EACV,KAAK;AAAA,EACL,MAAM;AAAA,EACN,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,iBAAiB;AAAA,EACjB,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,gBAAgB;AAAA,EAChB,YAAY;AAAA,GACV,UAAAH,GAAM;"}
@@ -1,2 +0,0 @@
1
- export * from '../../Components/index'
2
- export {}
@@ -1,5 +0,0 @@
1
- import { SuspenseRoute as p } from "./SuspenseRoute.js";
2
- export {
3
- p as SuspenseRoute
4
- };
5
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -1,2 +0,0 @@
1
- export * from '../../Hooks/index'
2
- export {}
@@ -1,20 +0,0 @@
1
- import "react";
2
- import { useInfiniteScroll as o } from "./useInfiniteScroll.js";
3
- import { isBrowser as a, isNavigator as u, useNetworkState as i } from "./useNetworkState.js";
4
- import { disabledEventPropagation as p, useShortcuts as l } from "./useShortcuts.js";
5
- import { useCallbackRef as n, useFirstRenderState as c, useInterval as d, useLatestRef as x, useTimeout as S, useUpdateEffect as v } from "../../Hooks.js";
6
- export {
7
- p as disabledEventPropagation,
8
- a as isBrowser,
9
- u as isNavigator,
10
- n as useCallbackRef,
11
- c as useFirstRenderState,
12
- o as useInfiniteScroll,
13
- d as useInterval,
14
- x as useLatestRef,
15
- i as useNetworkState,
16
- l as useShortcuts,
17
- S as useTimeout,
18
- v as useUpdateEffect
19
- };
20
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
@@ -1,2 +0,0 @@
1
- export * from '../../Hooks/useInfiniteScroll'
2
- export {}
@@ -1,20 +0,0 @@
1
- import n from "react";
2
- const a = (e, r) => {
3
- const t = n.useCallback(
4
- (o) => {
5
- new IntersectionObserver((c) => {
6
- c.forEach((i) => {
7
- i.intersectionRatio > 0 && r({ type: "next-page" });
8
- });
9
- }).observe(o);
10
- },
11
- [r]
12
- );
13
- n.useEffect(() => {
14
- e.current && t(e.current);
15
- }, [t, e]);
16
- };
17
- export {
18
- a as useInfiniteScroll
19
- };
20
- //# sourceMappingURL=useInfiniteScroll.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useInfiniteScroll.js","sources":["../../../src/Hooks/useInfiniteScroll.ts"],"sourcesContent":["import React from 'react';\r\n\r\n/**\r\n * Infinite scrolling with intersection observer\r\n * @param scrollRef Reference object for observe bottom boundary\r\n * @param dispatch Trigger an action that updates the page number\r\n */\r\nexport const useInfiniteScroll = (scrollRef: React.MutableRefObject<any>, dispatch: any) => {\r\n const scrollObserver = React.useCallback(\r\n (node: any) => {\r\n new IntersectionObserver((entries) => {\r\n entries.forEach((en) => {\r\n if (en.intersectionRatio > 0) {\r\n dispatch({ type: 'next-page' });\r\n }\r\n });\r\n }).observe(node);\r\n },\r\n [dispatch]\r\n );\r\n\r\n React.useEffect(() => {\r\n if (scrollRef.current) {\r\n scrollObserver(scrollRef.current);\r\n }\r\n }, [scrollObserver, scrollRef]);\r\n};\r\n"],"names":["useInfiniteScroll","scrollRef","dispatch","scrollObserver","React","node","entries","en"],"mappings":";AAOO,MAAMA,IAAoB,CAACC,GAAwCC,MAAkB;AAC1F,QAAMC,IAAiBC,EAAM;AAAA,IAC3B,CAACC,MAAc;AACb,UAAI,qBAAqB,CAACC,MAAY;AACpC,QAAAA,EAAQ,QAAQ,CAACC,MAAO;AACtB,UAAIA,EAAG,oBAAoB,KACzBL,EAAS,EAAE,MAAM,aAAa;AAAA,QAElC,CAAC;AAAA,MACH,CAAC,EAAE,QAAQG,CAAI;AAAA,IACjB;AAAA,IACA,CAACH,CAAQ;AAAA,EAAA;AAGX,EAAAE,EAAM,UAAU,MAAM;AACpB,IAAIH,EAAU,WACZE,EAAeF,EAAU,OAAO;AAAA,EAEpC,GAAG,CAACE,GAAgBF,CAAS,CAAC;AAChC;"}
@@ -1,2 +0,0 @@
1
- export * from '../../Hooks/useNetworkState'
2
- export {}
@@ -1,33 +0,0 @@
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
- return {
6
- online: i,
7
- previous: s,
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
- };
16
- }
17
- function c(n) {
18
- const [i, s] = d.useState(n != null ? n : r);
19
- return d.useEffect(() => {
20
- const o = () => {
21
- s(r);
22
- };
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
- };
26
- }, []), i;
27
- }
28
- export {
29
- a as isBrowser,
30
- w as isNavigator,
31
- c as useNetworkState
32
- };
33
- //# sourceMappingURL=useNetworkState.js.map
@@ -1 +0,0 @@
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;"}
@@ -1,2 +0,0 @@
1
- export * from '../../Hooks/useShortcuts'
2
- export {}
@@ -1,43 +0,0 @@
1
- import a from "react";
2
- const y = ["INPUT", "TEXTAREA", "SELECT"], l = (t, n) => {
3
- switch (n.type) {
4
- case "set-key-down":
5
- return { ...t, [n.key]: !0 };
6
- case "set-key-up":
7
- return { ...t, [n.key]: !1 };
8
- case "reset-keys":
9
- return { ...n.data };
10
- default:
11
- return t;
12
- }
13
- }, h = (t, n, d) => {
14
- if (!Array.isArray(t)) throw new Error("The first parameter to `useShortcuts` must be an ordered array of `KeyboardEvent.key` strings.");
15
- if (!t.length) throw new Error("The first parameter to `useShortcuts` must contain atleast one `KeyboardEvent.key` string.");
16
- if (!n || typeof n != "function") throw new Error("The second parameter to `useShortcuts` must be a function that will be envoked when the keys are pressed.");
17
- const { overrideSystem: i } = d || {}, f = t.reduce((e, r) => (e[r.toLowerCase()] = !1, e), {}), [s, u] = a.useReducer(l, f), w = a.useCallback(
18
- (e) => (r) => {
19
- const o = e.toLowerCase();
20
- if (!r.repeat && !y.includes(r.target.tagName) && o === r.key.toLowerCase() && s[o] !== void 0)
21
- return i && (r.preventDefault(), p(r)), u({ type: "set-key-down", key: o }), !1;
22
- },
23
- [s, i]
24
- ), c = a.useCallback(
25
- (e) => (r) => {
26
- const o = e.toLowerCase();
27
- if (!y.includes(r.target.tagName) && r.key.toLowerCase() === o && s[o] !== void 0)
28
- return i && (r.preventDefault(), p(r)), u({ type: "set-key-up", key: o }), !1;
29
- },
30
- [s, i]
31
- );
32
- a.useEffect(() => {
33
- Object.values(s).filter((e) => !e).length ? u({ type: "" }) : (n(s), u({ type: "reset-keys", data: f }));
34
- }, [n, s]), a.useEffect(() => (t.forEach((e) => window.addEventListener("keydown", w(e))), () => t.forEach((e) => window.removeEventListener("keydown", w(e)))), []), a.useEffect(() => (t.forEach((e) => window.addEventListener("keyup", c(e))), () => t.forEach((e) => window.removeEventListener("keyup", c(e)))), []);
35
- };
36
- function p(t) {
37
- t && (t.stopPropagation ? t.stopPropagation() : window.event && (window.event.cancelBubble = !0));
38
- }
39
- export {
40
- p as disabledEventPropagation,
41
- h as useShortcuts
42
- };
43
- //# sourceMappingURL=useShortcuts.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useShortcuts.js","sources":["../../../src/Hooks/useShortcuts.ts"],"sourcesContent":["import React from 'react';\r\n\r\nconst blacklistedTargets = ['INPUT', 'TEXTAREA', 'SELECT'];\r\n\r\ntype KeysActions = { type: 'set-key-down' | 'set-key-up'; key: string } | { type: 'reset-keys'; data: any } | { type: '' };\r\ninterface IKeysState {\r\n [key: string]: any;\r\n}\r\n\r\nconst keysReducer = (state: IKeysState, action: KeysActions) => {\r\n switch (action.type) {\r\n case 'set-key-down':\r\n const keydownState = { ...state, [action.key]: true };\r\n return keydownState;\r\n case 'set-key-up':\r\n const keyUpState = { ...state, [action.key]: false };\r\n return keyUpState;\r\n case 'reset-keys':\r\n const resetState = { ...action.data };\r\n return resetState;\r\n default:\r\n return state;\r\n }\r\n};\r\n\r\nexport const useShortcuts = (shortcutKeys: string[] | string, callback: (keys: string) => void, options?: { overrideSystem: boolean }) => {\r\n if (!Array.isArray(shortcutKeys)) throw new Error('The first parameter to `useShortcuts` must be an ordered array of `KeyboardEvent.key` strings.');\r\n\r\n if (!shortcutKeys.length) throw new Error('The first parameter to `useShortcuts` must contain atleast one `KeyboardEvent.key` string.');\r\n\r\n if (!callback || typeof callback !== 'function') throw new Error('The second parameter to `useShortcuts` must be a function that will be envoked when the keys are pressed.');\r\n\r\n const { overrideSystem } = options || {};\r\n const initalKeyMapping = shortcutKeys.reduce((currentKeys: any, key) => {\r\n currentKeys[key.toLowerCase()] = false;\r\n return currentKeys;\r\n }, {});\r\n\r\n const [keys, setKeys] = React.useReducer(keysReducer, initalKeyMapping);\r\n\r\n const keydownListener = React.useCallback(\r\n (assignedKey: string) => (keydownEvent: KeyboardEvent) => {\r\n const loweredKey = assignedKey.toLowerCase();\r\n\r\n if (keydownEvent.repeat) return;\r\n if (blacklistedTargets.includes((keydownEvent.target as any).tagName)) return;\r\n if (loweredKey !== keydownEvent.key.toLowerCase()) return;\r\n if (keys[loweredKey] === undefined) return;\r\n\r\n if (overrideSystem) {\r\n keydownEvent.preventDefault();\r\n disabledEventPropagation(keydownEvent);\r\n }\r\n\r\n setKeys({ type: 'set-key-down', key: loweredKey });\r\n return false;\r\n },\r\n [keys, overrideSystem]\r\n );\r\n\r\n const keyupListener = React.useCallback(\r\n (assignedKey: string) => (keyupEvent: KeyboardEvent) => {\r\n const raisedKey = assignedKey.toLowerCase();\r\n\r\n if (blacklistedTargets.includes((keyupEvent.target as any).tagName)) return;\r\n if (keyupEvent.key.toLowerCase() !== raisedKey) return;\r\n if (keys[raisedKey] === undefined) return;\r\n\r\n if (overrideSystem) {\r\n keyupEvent.preventDefault();\r\n disabledEventPropagation(keyupEvent);\r\n }\r\n\r\n setKeys({ type: 'set-key-up', key: raisedKey });\r\n return false;\r\n },\r\n [keys, overrideSystem]\r\n );\r\n\r\n React.useEffect(() => {\r\n //console.log('keys', keys);\r\n if (!Object.values(keys).filter((value) => !value).length) {\r\n callback(keys);\r\n setKeys({ type: 'reset-keys', data: initalKeyMapping });\r\n } else {\r\n setKeys({ type: '' });\r\n }\r\n }, [callback, keys]);\r\n\r\n React.useEffect(() => {\r\n shortcutKeys.forEach((k) => window.addEventListener('keydown', keydownListener(k)));\r\n return () => shortcutKeys.forEach((k) => window.removeEventListener('keydown', keydownListener(k)));\r\n }, []);\r\n\r\n React.useEffect(() => {\r\n shortcutKeys.forEach((k) => window.addEventListener('keyup', keyupListener(k)));\r\n return () => shortcutKeys.forEach((k) => window.removeEventListener('keyup', keyupListener(k)));\r\n }, []);\r\n};\r\n\r\nexport function disabledEventPropagation(e: KeyboardEvent) {\r\n if (e) {\r\n if (e.stopPropagation) {\r\n e.stopPropagation();\r\n } else if (window.event) {\r\n window.event.cancelBubble = true;\r\n }\r\n }\r\n}\r\n"],"names":["blacklistedTargets","keysReducer","state","action","useShortcuts","shortcutKeys","callback","options","overrideSystem","initalKeyMapping","currentKeys","key","keys","setKeys","React","keydownListener","assignedKey","keydownEvent","loweredKey","disabledEventPropagation","keyupListener","keyupEvent","raisedKey","value","k","e"],"mappings":"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"}
@@ -1,2 +0,0 @@
1
- export * from '../../Utilities/ApiUtility.axios'
2
- export {}
@@ -1,228 +0,0 @@
1
- var u = Object.defineProperty;
2
- var g = (i, e, t) => e in i ? u(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
- var n = (i, e, t) => g(i, typeof e != "symbol" ? e + "" : e, t);
4
- import l from "axios";
5
- import { saveAs as y } from "file-saver";
6
- import { stringify as f } from "qs";
7
- var m = /* @__PURE__ */ ((i) => (i.get = "get", i.post = "post", i))(m || {}), A = /* @__PURE__ */ ((i) => (i.downloading = "downloading", i.done = "done", i.error = "error", i))(A || {});
8
- class E {
9
- constructor() {
10
- n(this, "config", {});
11
- // private getParams = (params?: any) => {
12
- // if (params) {
13
- // for (const key in params) {
14
- // if (params[key] == null || params[key] === undefined || params[key] === '')
15
- // delete params[key];
16
- // }
17
- // }
18
- // return params;
19
- // };
20
- n(this, "getResponse", async (e, t, o) => await l.get(e, {
21
- params: t,
22
- paramsSerializer: {
23
- serialize: (s, r) => f(t, {
24
- arrayFormat: "indices",
25
- allowDots: !0,
26
- skipNulls: !0
27
- })
28
- },
29
- ...this._axiosOptions(o || {})
30
- }));
31
- n(this, "get", async (e, t, o, s) => {
32
- const r = await this.getResponse(e, t, s);
33
- return this.handleResponse(r, o);
34
- });
35
- n(this, "getResult", async (e, t, o, s) => {
36
- try {
37
- const r = await this.get(e, t, void 0, s);
38
- if (r.status)
39
- return r.result;
40
- this.handleErrorResponse(r.message, r.errors);
41
- } catch (r) {
42
- r.isAxiosError ? this.handleAxiosError(r, o) : this.handleResponse(r, o);
43
- }
44
- return null;
45
- });
46
- n(this, "post", async (e, t, o, s) => {
47
- try {
48
- const r = await l.post(e, t, this._axiosOptions({ contentType: o, ...s || {} }));
49
- return this.handleResponse(r);
50
- } catch (r) {
51
- if (r != null && r.isAxiosError)
52
- return this.handleAxiosError(r);
53
- }
54
- return {};
55
- });
56
- n(this, "put", async (e, t, o, s) => {
57
- try {
58
- const r = await l.put(e, t, this._axiosOptions({ contentType: o, ...s || {} }));
59
- return this.handleResponse(r);
60
- } catch (r) {
61
- if (r != null && r.isAxiosError)
62
- return this.handleAxiosError(r);
63
- }
64
- return {};
65
- });
66
- n(this, "appendFormDataValues", (e, t, o) => {
67
- if ((!o || o.length <= 0) && (o = ""), typeof t != "function" && typeof t != "object" && typeof t != "symbol" || t instanceof File) {
68
- t && o && e.append(o, t);
69
- return;
70
- }
71
- for (const s in t) {
72
- const r = `${o}${o && !o.endsWith(".") ? "." : ""}${s}`;
73
- if (t[s] instanceof FileList) {
74
- const a = t[s];
75
- for (let h = 0; h < a.length; h++)
76
- e.append(`${r}[${h}]`, a[h]);
77
- } else
78
- Array.isArray(t[s]) ? t[s].forEach((a, h) => {
79
- this.appendFormDataValues(e, a, `${r}[${h}]`);
80
- }) : typeof t[s] == "object" ? this.appendFormDataValues(e, t[s], r) : t[s] && e.append(r, t[s]);
81
- }
82
- });
83
- n(this, "postForm", async (e, t, o) => {
84
- let s = new FormData();
85
- t instanceof FormData ? s = t : this.appendFormDataValues(s, t);
86
- try {
87
- const r = await l.post(e, s, this._axiosOptions({ contentType: "multipart/form-data", ...o || {} }));
88
- return this.handleResponse(r);
89
- } catch (r) {
90
- if (r != null && r.isAxiosError)
91
- return this.handleAxiosError(r);
92
- }
93
- return {};
94
- });
95
- n(this, "putForm", async (e, t, o) => {
96
- let s = new FormData();
97
- t instanceof FormData ? s = t : this.appendFormDataValues(s, t);
98
- try {
99
- const r = await l.putForm(e, s, this._axiosOptions({ contentType: "multipart/form-data", ...o || {} }));
100
- return this.handleResponse(r);
101
- } catch (r) {
102
- if (r != null && r.isAxiosError)
103
- return this.handleAxiosError(r);
104
- }
105
- return {};
106
- });
107
- n(this, "delete", async (e, t, o) => {
108
- const s = await l.delete(e, this._axiosOptions({ contentType: t, ...o || {} }));
109
- return this.handleResponse(s);
110
- });
111
- n(this, "getFileName", (e) => {
112
- var t = void 0;
113
- if (e && e.indexOf("attachment") !== -1) {
114
- var o = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/, s = o.exec(e);
115
- s != null && s[1] && (t = s[1].replace(/['"]/g, ""));
116
- }
117
- return t;
118
- });
119
- n(this, "downloadFile", async (e, t, o, s) => {
120
- let r;
121
- const a = {}, h = this.accessToken;
122
- h && (a.Authorization = `Bearer ${h}`);
123
- const d = { headers: a, ...s || {} };
124
- o === "post" ? r = l.post(e, t, {
125
- ...this._axiosOptions(d),
126
- responseType: "blob"
127
- }) : r = l.get(e, {
128
- params: t,
129
- paramsSerializer: {
130
- serialize: (c, p) => f(t, {
131
- arrayFormat: "indices",
132
- allowDots: !0,
133
- skipNulls: !0
134
- })
135
- },
136
- ...this._axiosOptions(d),
137
- responseType: "blob"
138
- });
139
- try {
140
- const c = await r, p = this.getFileName(c.headers.get("Content-Disposition"));
141
- return y(c.data, p), {
142
- status: "done"
143
- /* done */
144
- };
145
- } catch (c) {
146
- return c.isAxiosError ? this.handleResponse(c.response) : this.handleResponse(c), c.response ? {
147
- status: "error",
148
- error: c.response.status
149
- } : { status: "error", error: c.message };
150
- }
151
- });
152
- n(this, "getAuthHeader", (e) => {
153
- const t = {
154
- "Content-Type": e || "application/json",
155
- Accept: "application/json"
156
- }, o = this.accessToken;
157
- return o && (t.Authorization = `Bearer ${o}`), t;
158
- });
159
- n(this, "handleResponse", (e, t) => {
160
- if (!e)
161
- this.handleError && this.handleError("No response from the server, please try after some time.");
162
- else if ([401, 403].indexOf(e.status) !== -1) {
163
- if (t)
164
- throw e;
165
- console.error("401 Unauthorized or 403 Forbidden response returned from api");
166
- }
167
- return e == null ? void 0 : e.data;
168
- });
169
- n(this, "handleAxiosError", (e, t) => {
170
- var o, s;
171
- if (t && ((o = e.response) == null ? void 0 : o.status) === 401) throw e;
172
- if (((s = e.response) == null ? void 0 : s.status) === 400) {
173
- const r = e.response.data;
174
- if (r && r.errors) {
175
- const a = [];
176
- for (const h in r.errors)
177
- r.errors[h] && r.errors[h].length > 0 && a.push(r.errors[h][0]);
178
- return {
179
- result: null,
180
- status: !1,
181
- message: a.length > 0 ? a[0] : "",
182
- errors: a
183
- };
184
- }
185
- }
186
- return {};
187
- });
188
- n(this, "handleErrorResponse", (e, t) => {
189
- this.handleError && this.handleError(e, t);
190
- });
191
- n(this, "_axiosOptions", (e) => {
192
- const { contentType: t, headers: o, ...s } = e || {};
193
- return {
194
- headers: o || this.getAuthHeader(t),
195
- baseURL: this.getBaseUrl(),
196
- ...s
197
- };
198
- });
199
- n(this, "getBaseUrl", () => this.config.baseURL || process.env.REACT_APP_API_URL || typeof window != "undefined" && window.__API_BASE_URL__);
200
- }
201
- get accessToken() {
202
- return this.config.accessToken;
203
- }
204
- set accessToken(e) {
205
- this.config.accessToken = e;
206
- }
207
- get handleError() {
208
- return this.config.handleError || ((e, t) => {
209
- });
210
- }
211
- set handleError(e) {
212
- this.config.handleError = e;
213
- }
214
- /**
215
- * Configure the API utility with base URL and other options
216
- * @param config Configuration object
217
- */
218
- configure(e) {
219
- this.config = { ...this.config, ...e };
220
- }
221
- }
222
- const T = new E();
223
- export {
224
- T as ApiUtility,
225
- A as FileDownloadStatus,
226
- m as HttpMethods
227
- };
228
- //# sourceMappingURL=ApiUtility.axios.js.map