@siberiacancode/reactuse 0.0.118 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/dist/cjs/hooks/useDidUpdate/useDidUpdate.cjs.map +1 -1
  2. package/dist/cjs/hooks/useDoubleClick/useDoubleClick.cjs +1 -1
  3. package/dist/cjs/hooks/useDoubleClick/useDoubleClick.cjs.map +1 -1
  4. package/dist/cjs/hooks/useDropZone/useDropZone.cjs +2 -0
  5. package/dist/cjs/hooks/useDropZone/useDropZone.cjs.map +1 -0
  6. package/dist/cjs/hooks/useEventSource/useEventSource.cjs +2 -0
  7. package/dist/cjs/hooks/useEventSource/useEventSource.cjs.map +1 -0
  8. package/dist/cjs/hooks/useHover/useHover.cjs +1 -1
  9. package/dist/cjs/hooks/useHover/useHover.cjs.map +1 -1
  10. package/dist/cjs/hooks/useInterval/useInterval.cjs +1 -1
  11. package/dist/cjs/hooks/useInterval/useInterval.cjs.map +1 -1
  12. package/dist/cjs/hooks/useLongPress/useLongPress.cjs +1 -1
  13. package/dist/cjs/hooks/useLongPress/useLongPress.cjs.map +1 -1
  14. package/dist/cjs/hooks/useOnce/useOnce.cjs +1 -1
  15. package/dist/cjs/hooks/useOnce/useOnce.cjs.map +1 -1
  16. package/dist/cjs/hooks/usePerformanceObserver/usePerformanceObserver.cjs +1 -1
  17. package/dist/cjs/hooks/usePerformanceObserver/usePerformanceObserver.cjs.map +1 -1
  18. package/dist/cjs/hooks/usePrevious/usePrevious.cjs +1 -1
  19. package/dist/cjs/hooks/usePrevious/usePrevious.cjs.map +1 -1
  20. package/dist/cjs/hooks/useQuery/useQuery.cjs +1 -1
  21. package/dist/cjs/hooks/useQuery/useQuery.cjs.map +1 -1
  22. package/dist/cjs/hooks/useResizeObserver/useResizeObserver.cjs +1 -1
  23. package/dist/cjs/hooks/useResizeObserver/useResizeObserver.cjs.map +1 -1
  24. package/dist/cjs/hooks/useTimeout/useTimeout.cjs +1 -1
  25. package/dist/cjs/hooks/useTimeout/useTimeout.cjs.map +1 -1
  26. package/dist/cjs/hooks/useTimer/useTimer.cjs +1 -1
  27. package/dist/cjs/hooks/useTimer/useTimer.cjs.map +1 -1
  28. package/dist/cjs/hooks/useVibrate/useVibrate.cjs +1 -1
  29. package/dist/cjs/hooks/useVibrate/useVibrate.cjs.map +1 -1
  30. package/dist/cjs/hooks/useWakeLock/useWakeLock.cjs +1 -1
  31. package/dist/cjs/hooks/useWakeLock/useWakeLock.cjs.map +1 -1
  32. package/dist/cjs/hooks/useWebSocket/useWebSocket.cjs +1 -1
  33. package/dist/cjs/hooks/useWebSocket/useWebSocket.cjs.map +1 -1
  34. package/dist/cjs/index.cjs +1 -1
  35. package/dist/esm/hooks/useDidUpdate/useDidUpdate.mjs.map +1 -1
  36. package/dist/esm/hooks/useDoubleClick/useDoubleClick.mjs +4 -4
  37. package/dist/esm/hooks/useDoubleClick/useDoubleClick.mjs.map +1 -1
  38. package/dist/esm/hooks/useDropZone/useDropZone.mjs +50 -0
  39. package/dist/esm/hooks/useDropZone/useDropZone.mjs.map +1 -0
  40. package/dist/esm/hooks/useEventSource/useEventSource.mjs +52 -0
  41. package/dist/esm/hooks/useEventSource/useEventSource.mjs.map +1 -0
  42. package/dist/esm/hooks/useHover/useHover.mjs +9 -6
  43. package/dist/esm/hooks/useHover/useHover.mjs.map +1 -1
  44. package/dist/esm/hooks/useInterval/useInterval.mjs +6 -6
  45. package/dist/esm/hooks/useInterval/useInterval.mjs.map +1 -1
  46. package/dist/esm/hooks/useLongPress/useLongPress.mjs +1 -1
  47. package/dist/esm/hooks/useLongPress/useLongPress.mjs.map +1 -1
  48. package/dist/esm/hooks/useOnce/useOnce.mjs +3 -3
  49. package/dist/esm/hooks/useOnce/useOnce.mjs.map +1 -1
  50. package/dist/esm/hooks/usePerformanceObserver/usePerformanceObserver.mjs +14 -14
  51. package/dist/esm/hooks/usePerformanceObserver/usePerformanceObserver.mjs.map +1 -1
  52. package/dist/esm/hooks/usePrevious/usePrevious.mjs +3 -3
  53. package/dist/esm/hooks/usePrevious/usePrevious.mjs.map +1 -1
  54. package/dist/esm/hooks/useQuery/useQuery.mjs +27 -29
  55. package/dist/esm/hooks/useQuery/useQuery.mjs.map +1 -1
  56. package/dist/esm/hooks/useResizeObserver/useResizeObserver.mjs +17 -17
  57. package/dist/esm/hooks/useResizeObserver/useResizeObserver.mjs.map +1 -1
  58. package/dist/esm/hooks/useTimeout/useTimeout.mjs +1 -1
  59. package/dist/esm/hooks/useTimeout/useTimeout.mjs.map +1 -1
  60. package/dist/esm/hooks/useTimer/useTimer.mjs +15 -15
  61. package/dist/esm/hooks/useTimer/useTimer.mjs.map +1 -1
  62. package/dist/esm/hooks/useVibrate/useVibrate.mjs +9 -9
  63. package/dist/esm/hooks/useVibrate/useVibrate.mjs.map +1 -1
  64. package/dist/esm/hooks/useWakeLock/useWakeLock.mjs +3 -3
  65. package/dist/esm/hooks/useWakeLock/useWakeLock.mjs.map +1 -1
  66. package/dist/esm/hooks/useWebSocket/useWebSocket.mjs +5 -5
  67. package/dist/esm/hooks/useWebSocket/useWebSocket.mjs.map +1 -1
  68. package/dist/esm/index.mjs +260 -256
  69. package/dist/esm/index.mjs.map +1 -1
  70. package/dist/types/hooks/index.d.ts +2 -0
  71. package/dist/types/hooks/useDropZone/useDropZone.d.ts +80 -0
  72. package/dist/types/hooks/useEventSource/useEventSource.d.ts +47 -0
  73. package/dist/types/hooks/useHover/useHover.d.ts +11 -4
  74. package/dist/types/hooks/usePrevious/usePrevious.d.ts +1 -1
  75. package/dist/types/hooks/useQuery/useQuery.d.ts +0 -1
  76. package/package.json +14 -18
@@ -1,9 +1,9 @@
1
1
  import { useRef as c } from "react";
2
- const s = (r, e) => {
3
- const t = c(r), u = c();
2
+ const i = (r, e) => {
3
+ const t = c(r), u = c(void 0);
4
4
  return ((e == null ? void 0 : e.equality) ?? Object.is)(r, t.current) || (u.current = t.current, t.current = r), u.current;
5
5
  };
6
6
  export {
7
- s as usePrevious
7
+ i as usePrevious
8
8
  };
9
9
  //# sourceMappingURL=usePrevious.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"usePrevious.mjs","sources":["../../../../src/hooks/usePrevious/usePrevious.ts"],"sourcesContent":["import { useRef } from 'react';\n\nexport interface UsePreviousOptions<Value> {\n equality: (a: Value, b: Value) => boolean;\n}\n\n/**\n * @name usePrevious\n * @description - Hook that returns the previous value\n * @category Utilities\n *\n * @template Value The type of the value\n * @param {Value} value The value to get the previous value\n * @param {(a: Value, b: Value) => boolean} [options.equality] The custom equality function to determine if the value has changed\n * @returns {Value} The previous value\n *\n * @example\n * const prevValue = usePrevious(value);\n */\nexport const usePrevious = <Value>(value: Value, options?: UsePreviousOptions<Value>) => {\n const currentRef = useRef<Value>(value);\n const previousRef = useRef<Value>();\n\n const equality = options?.equality ?? Object.is;\n\n if (!equality(value, currentRef.current)) {\n previousRef.current = currentRef.current;\n currentRef.current = value;\n }\n\n return previousRef.current;\n};\n"],"names":["usePrevious","value","options","currentRef","useRef","previousRef"],"mappings":";AAmBa,MAAAA,IAAc,CAAQC,GAAcC,MAAwC;AACjF,QAAAC,IAAaC,EAAcH,CAAK,GAChCI,IAAcD,EAAc;AAIlC,WAFiBF,KAAA,gBAAAA,EAAS,aAAY,OAAO,IAE/BD,GAAOE,EAAW,OAAO,MACrCE,EAAY,UAAUF,EAAW,SACjCA,EAAW,UAAUF,IAGhBI,EAAY;AACrB;"}
1
+ {"version":3,"file":"usePrevious.mjs","sources":["../../../../src/hooks/usePrevious/usePrevious.ts"],"sourcesContent":["import { useRef } from 'react';\n\nexport interface UsePreviousOptions<Value> {\n equality: (a: Value, b: Value) => boolean;\n}\n\n/**\n * @name usePrevious\n * @description - Hook that returns the previous value\n * @category Utilities\n *\n * @template Value The type of the value\n * @param {Value} value The value to get the previous value\n * @param {(a: Value, b: Value) => boolean} [options.equality] The custom equality function to determine if the value has changed\n * @returns {Value | undefined} The previous value\n *\n * @example\n * const prevValue = usePrevious(value);\n */\nexport const usePrevious = <Value>(value: Value, options?: UsePreviousOptions<Value>) => {\n const currentRef = useRef<Value>(value);\n const previousRef = useRef<Value>(undefined);\n\n const equality = options?.equality ?? Object.is;\n\n if (!equality(value, currentRef.current)) {\n previousRef.current = currentRef.current;\n currentRef.current = value;\n }\n\n return previousRef.current;\n};\n"],"names":["usePrevious","value","options","currentRef","useRef","previousRef"],"mappings":";AAmBa,MAAAA,IAAc,CAAQC,GAAcC,MAAwC;AACjF,QAAAC,IAAaC,EAAcH,CAAK,GAChCI,IAAcD,EAAc,MAAS;AAI3C,WAFiBF,KAAA,gBAAAA,EAAS,aAAY,OAAO,IAE/BD,GAAOE,EAAW,OAAO,MACrCE,EAAY,UAAUF,EAAW,SACjCA,EAAW,UAAUF,IAGhBI,EAAY;AACrB;"}
@@ -1,49 +1,47 @@
1
- import { useRef as d, useState as c, useEffect as z } from "react";
2
- import { useDidUpdate as B } from "../useDidUpdate/useDidUpdate.mjs";
3
- import { useMount as G } from "../useMount/useMount.mjs";
1
+ import { useRef as h, useState as f, useEffect as U } from "react";
2
+ import { useDidUpdate as j } from "../useDidUpdate/useDidUpdate.mjs";
3
+ import { useMount as z } from "../useMount/useMount.mjs";
4
4
  import { getRetry as q } from "../../utils/helpers/getRetry.mjs";
5
- const O = (w, e) => {
6
- const y = (e == null ? void 0 : e.enabled) ?? !0, h = d(e != null && e.retry ? q(e.retry) : 0), m = d(!1), [A, t] = c(!1), [F, D] = c(!1), [L, R] = c(!1), [x, I] = c(!1), [M, b] = c(!!(e != null && e.initialData)), [Q, E] = c(void 0), [T, C] = c(e == null ? void 0 : e.initialData), v = d(new AbortController()), S = d(), g = (e == null ? void 0 : e.keys) ?? [], k = () => {
7
- v.current.abort(), v.current = new AbortController();
8
- }, l = (a) => {
9
- k(), t(!0), a === "init" && (m.current = !0, D(!0)), a === "refetch" && I(!0), w({ signal: v.current.signal, keys: g }).then((r) => {
5
+ const N = (w, e) => {
6
+ const t = (e == null ? void 0 : e.enabled) ?? !0, y = h(e != null && e.retry ? q(e.retry) : 0), D = h(!1), [A, d] = f(!1), [F, v] = f(!1), [L, R] = f(!1), [x, I] = f(!1), [M, b] = f(!!(e != null && e.placeholderData)), [Q, E] = f(void 0), [T, C] = f(e == null ? void 0 : e.placeholderData), g = h(new AbortController()), S = h(void 0), m = (e == null ? void 0 : e.keys) ?? [], k = () => {
7
+ g.current.abort(), g.current = new AbortController();
8
+ }, a = (c) => {
9
+ k(), d(!0), c === "init" && (D.current = !0, v(!0)), c === "refetch" && I(!0), w({ signal: g.current.signal, keys: m }).then((r) => {
10
10
  var u;
11
- const f = e != null && e.select ? e == null ? void 0 : e.select(r) : r;
12
- (u = e == null ? void 0 : e.onSuccess) == null || u.call(e, f), C(f), b(!0), E(void 0), R(!1), t(!1), a === "init" && D(!1), a === "refetch" && I(!1);
11
+ const l = e != null && e.select ? e == null ? void 0 : e.select(r) : r;
12
+ (u = e == null ? void 0 : e.onSuccess) == null || u.call(e, l), C(l), b(!0), E(void 0), R(!1), d(!1), c === "init" && v(!1), c === "refetch" && I(!1);
13
13
  }).catch((r) => {
14
- var f;
15
- if (h.current > 0) {
16
- h.current -= 1;
17
- const u = typeof (e == null ? void 0 : e.retryDelay) == "function" ? e == null ? void 0 : e.retryDelay(h.current, r) : e == null ? void 0 : e.retryDelay;
14
+ var l;
15
+ if (y.current > 0) {
16
+ y.current -= 1;
17
+ const u = typeof (e == null ? void 0 : e.retryDelay) == "function" ? e == null ? void 0 : e.retryDelay(y.current, r) : e == null ? void 0 : e.retryDelay;
18
18
  if (u) {
19
- setTimeout(() => l(a), u);
19
+ setTimeout(() => a(c), u);
20
20
  return;
21
21
  }
22
- return l(a);
22
+ return a(c);
23
23
  }
24
- (f = e == null ? void 0 : e.onError) == null || f.call(e, r), C(void 0), b(!1), E(r), R(!0), t(!1), a === "init" && D(!1), a === "refetch" && I(!1), h.current = e != null && e.retry ? q(e.retry) : 0;
24
+ (l = e == null ? void 0 : e.onError) == null || l.call(e, r), C(void 0), b(!1), E(r), R(!0), d(!1), c === "init" && v(!1), c === "refetch" && I(!1), y.current = e != null && e.retry ? q(e.retry) : 0;
25
25
  }).finally(() => {
26
26
  if (e != null && e.refetchInterval) {
27
27
  const r = setInterval(() => {
28
- clearInterval(r), l("refetch");
28
+ clearInterval(r), a("refetch");
29
29
  }, e == null ? void 0 : e.refetchInterval);
30
30
  S.current = r;
31
31
  }
32
32
  });
33
33
  };
34
- G(() => {
35
- y && l("init");
36
- }), B(() => {
37
- y && l(m.current ? "refetch" : "init");
38
- }, [y, ...g]), z(() => () => {
34
+ return z(() => {
35
+ t && a("init");
36
+ }), j(() => {
37
+ t && a(D.current ? "refetch" : "init");
38
+ }, [t, ...m]), U(() => () => {
39
39
  clearInterval(S.current);
40
- }, [y, e == null ? void 0 : e.refetchInterval, e == null ? void 0 : e.retry, ...g]);
41
- const U = () => l("refetch"), j = typeof (e == null ? void 0 : e.placeholderData) == "function" ? (e == null ? void 0 : e.placeholderData).call(e) : e == null ? void 0 : e.placeholderData;
42
- return {
40
+ }, [t, e == null ? void 0 : e.refetchInterval, e == null ? void 0 : e.retry, ...m]), {
43
41
  abort: k,
44
- data: T ?? j,
42
+ data: T,
45
43
  error: Q,
46
- refetch: U,
44
+ refetch: () => a("refetch"),
47
45
  isFetching: A,
48
46
  isLoading: F,
49
47
  isError: L,
@@ -52,6 +50,6 @@ const O = (w, e) => {
52
50
  };
53
51
  };
54
52
  export {
55
- O as useQuery
53
+ N as useQuery
56
54
  };
57
55
  //# sourceMappingURL=useQuery.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useQuery.mjs","sources":["../../../../src/hooks/useQuery/useQuery.ts"],"sourcesContent":["import type { DependencyList } from 'react';\n\nimport { useEffect, useRef, useState } from 'react';\n\nimport { getRetry } from '@/utils/helpers';\n\nimport { useDidUpdate } from '../useDidUpdate/useDidUpdate';\nimport { useMount } from '../useMount/useMount';\n\n/* The use query return type */\nexport interface UseQueryOptions<QueryData, Data> {\n /* The enabled state of the query */\n enabled?: boolean;\n /* The initial data for the hook */\n initialData?: (() => Data) | Data;\n /* The depends for the hook */\n keys?: DependencyList;\n /* The placeholder data for the hook */\n placeholderData?: (() => Data) | Data;\n /* The refetch interval */\n refetchInterval?: number;\n /* The retry count of requests */\n retry?: boolean | number;\n /* The retry delay of requests */\n retryDelay?: ((retry: number, error: Error) => number) | number;\n /* The callback function to be invoked on error */\n onError?: (error: Error) => void;\n /* The callback function to be invoked on success */\n onSuccess?: (data: Data) => void;\n /* The select function to be invoked */\n select?: (data: QueryData) => Data;\n}\n\ninterface UseQueryCallbackParams {\n /* The depends for the hook */\n keys: DependencyList;\n /* The abort signal */\n signal: AbortSignal;\n}\n\n/* The use query return type */\nexport interface UseQueryReturn<Data> {\n /* The abort function */\n abort: AbortController['abort'];\n /* The state of the query */\n data?: Data;\n /* The success state of the query */\n error?: Error;\n /* The error state of the query */\n isError: boolean;\n /* The fetching state of the query */\n isFetching: boolean;\n /* The loading state of the query */\n isLoading: boolean;\n /* The refetching state of the query */\n isRefetching: boolean;\n /* The success state of the query */\n isSuccess: boolean;\n /* The refetch function */\n refetch: () => void;\n}\n\n/**\n * @name useQuery\n * @description - Hook that defines the logic when query data\n * @category Utilities\n *\n * @template Data The type of the data\n * @param {() => Promise<Data>} callback The callback function to be invoked\n * @param {DependencyList} [options.keys] The dependencies for the hook\n * @param {(data: Data) => void} [options.onSuccess] The callback function to be invoked on success\n * @param {(error: Error) => void} [options.onError] The callback function to be invoked on error\n * @param {UseQueryOptionsSelect<Data>} [options.select] The select function to be invoked\n * @param {Data | (() => Data)} [options.initialData] The initial data for the hook\n * @param {Data | (() => Data)} [options.placeholderData] The placeholder data for the hook\n * @param {number} [options.refetchInterval] The refetch interval\n * @param {boolean | number} [options.retry] The retry count of requests\n * @returns {UseQueryReturn<Data>} An object with the state of the query\n *\n * @example\n * const { data, isFetching, isLoading, isError, isSuccess, error, refetch, isRefetching, abort, aborted } = useQuery(() => fetch('url'));\n */\nexport const useQuery = <QueryData, Data = QueryData>(\n callback: (params: UseQueryCallbackParams) => Promise<QueryData>,\n options?: UseQueryOptions<QueryData, Data>\n): UseQueryReturn<Data> => {\n const enabled = options?.enabled ?? true;\n const retryCountRef = useRef(options?.retry ? getRetry(options.retry) : 0);\n const alreadyRequested = useRef(false);\n\n const [isFetching, setIsFetching] = useState(false);\n const [isLoading, setIsLoading] = useState(false);\n const [isError, setIsError] = useState(false);\n const [isRefetching, setIsRefetching] = useState(false);\n const [isSuccess, setIsSuccess] = useState(!!options?.initialData);\n\n const [error, setError] = useState<Error | undefined>(undefined);\n const [data, setData] = useState<Data | undefined>(options?.initialData);\n\n const abortControllerRef = useRef<AbortController>(new AbortController());\n const intervalIdRef = useRef<ReturnType<typeof setInterval>>();\n\n const keys = options?.keys ?? [];\n\n const abort = () => {\n abortControllerRef.current.abort();\n abortControllerRef.current = new AbortController();\n };\n\n const request = (action: 'init' | 'refetch') => {\n abort();\n\n setIsFetching(true);\n if (action === 'init') {\n alreadyRequested.current = true;\n setIsLoading(true);\n }\n if (action === 'refetch') setIsRefetching(true);\n callback({ signal: abortControllerRef.current.signal, keys })\n .then((response) => {\n const data = options?.select ? options?.select(response) : response;\n options?.onSuccess?.(data as Data);\n setData(data as Data);\n setIsSuccess(true);\n setError(undefined);\n setIsError(false);\n setIsFetching(false);\n if (action === 'init') setIsLoading(false);\n if (action === 'refetch') setIsRefetching(false);\n })\n .catch((error: Error) => {\n if (retryCountRef.current > 0) {\n retryCountRef.current -= 1;\n const retryDelay =\n typeof options?.retryDelay === 'function'\n ? options?.retryDelay(retryCountRef.current, error)\n : options?.retryDelay;\n\n if (retryDelay) {\n setTimeout(() => request(action), retryDelay);\n return;\n }\n\n return request(action);\n }\n options?.onError?.(error);\n setData(undefined);\n setIsSuccess(false);\n setError(error);\n setIsError(true);\n setIsFetching(false);\n if (action === 'init') setIsLoading(false);\n if (action === 'refetch') setIsRefetching(false);\n retryCountRef.current = options?.retry ? getRetry(options.retry) : 0;\n })\n .finally(() => {\n if (options?.refetchInterval) {\n const interval = setInterval(() => {\n clearInterval(interval);\n request('refetch');\n }, options?.refetchInterval);\n intervalIdRef.current = interval;\n }\n });\n };\n\n useMount(() => {\n if (!enabled) return;\n request('init');\n });\n\n useDidUpdate(() => {\n if (!enabled) return;\n request(alreadyRequested.current ? 'refetch' : 'init');\n }, [enabled, ...keys]);\n\n useEffect(() => {\n return () => {\n clearInterval(intervalIdRef.current);\n };\n }, [enabled, options?.refetchInterval, options?.retry, ...keys]);\n\n const refetch = () => request('refetch');\n\n const placeholderData =\n typeof options?.placeholderData === 'function'\n ? (options?.placeholderData as () => Data)()\n : options?.placeholderData;\n\n return {\n abort,\n data: data ?? placeholderData,\n error,\n refetch,\n isFetching,\n isLoading,\n isError,\n isSuccess,\n isRefetching\n };\n};\n"],"names":["useQuery","callback","options","enabled","retryCountRef","useRef","getRetry","alreadyRequested","isFetching","setIsFetching","useState","isLoading","setIsLoading","isError","setIsError","isRefetching","setIsRefetching","isSuccess","setIsSuccess","error","setError","data","setData","abortControllerRef","intervalIdRef","keys","abort","request","action","response","_a","retryDelay","interval","useMount","useDidUpdate","useEffect","refetch","placeholderData"],"mappings":";;;;AAkFa,MAAAA,IAAW,CACtBC,GACAC,MACyB;AACnB,QAAAC,KAAUD,KAAA,gBAAAA,EAAS,YAAW,IAC9BE,IAAgBC,EAAOH,KAAA,QAAAA,EAAS,QAAQI,EAASJ,EAAQ,KAAK,IAAI,CAAC,GACnEK,IAAmBF,EAAO,EAAK,GAE/B,CAACG,GAAYC,CAAa,IAAIC,EAAS,EAAK,GAC5C,CAACC,GAAWC,CAAY,IAAIF,EAAS,EAAK,GAC1C,CAACG,GAASC,CAAU,IAAIJ,EAAS,EAAK,GACtC,CAACK,GAAcC,CAAe,IAAIN,EAAS,EAAK,GAChD,CAACO,GAAWC,CAAY,IAAIR,EAAS,CAAC,EAACR,KAAA,QAAAA,EAAS,YAAW,GAE3D,CAACiB,GAAOC,CAAQ,IA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B;AAAA,IACA,WAAAG;AAAA,IACA,SAAAE;AAAA,IACA,WAAAI;AAAA,IACA,cAAAF;AAAA,EACF;AACF;"}
1
+ {"version":3,"file":"useQuery.mjs","sources":["../../../../src/hooks/useQuery/useQuery.ts"],"sourcesContent":["import type { DependencyList } from 'react';\n\nimport { useEffect, useRef, useState } from 'react';\n\nimport { getRetry } from '@/utils/helpers';\n\nimport { useDidUpdate } from '../useDidUpdate/useDidUpdate';\nimport { useMount } from '../useMount/useMount';\n\n/* The use query return type */\nexport interface UseQueryOptions<QueryData, Data> {\n /* The enabled state of the query */\n enabled?: boolean;\n /* The depends for the hook */\n keys?: DependencyList;\n /* The placeholder data for the hook */\n placeholderData?: (() => Data) | Data;\n /* The refetch interval */\n refetchInterval?: number;\n /* The retry count of requests */\n retry?: boolean | number;\n /* The retry delay of requests */\n retryDelay?: ((retry: number, error: Error) => number) | number;\n /* The callback function to be invoked on error */\n onError?: (error: Error) => void;\n /* The callback function to be invoked on success */\n onSuccess?: (data: Data) => void;\n /* The select function to be invoked */\n select?: (data: QueryData) => Data;\n}\n\ninterface UseQueryCallbackParams {\n /* The depends for the hook */\n keys: DependencyList;\n /* The abort signal */\n signal: AbortSignal;\n}\n\n/* The use query return type */\nexport interface UseQueryReturn<Data> {\n /* The abort function */\n abort: AbortController['abort'];\n /* The state of the query */\n data?: Data;\n /* The success state of the query */\n error?: Error;\n /* The error state of the query */\n isError: boolean;\n /* The fetching state of the query */\n isFetching: boolean;\n /* The loading state of the query */\n isLoading: boolean;\n /* The refetching state of the query */\n isRefetching: boolean;\n /* The success state of the query */\n isSuccess: boolean;\n /* The refetch function */\n refetch: () => void;\n}\n\n/**\n * @name useQuery\n * @description - Hook that defines the logic when query data\n * @category Utilities\n *\n * @template Data The type of the data\n * @param {() => Promise<Data>} callback The callback function to be invoked\n * @param {DependencyList} [options.keys] The dependencies for the hook\n * @param {(data: Data) => void} [options.onSuccess] The callback function to be invoked on success\n * @param {(error: Error) => void} [options.onError] The callback function to be invoked on error\n * @param {UseQueryOptionsSelect<Data>} [options.select] The select function to be invoked\n * @param {Data | (() => Data)} [options.initialData] The initial data for the hook\n * @param {Data | (() => Data)} [options.placeholderData] The placeholder data for the hook\n * @param {number} [options.refetchInterval] The refetch interval\n * @param {boolean | number} [options.retry] The retry count of requests\n * @returns {UseQueryReturn<Data>} An object with the state of the query\n *\n * @example\n * const { data, isFetching, isLoading, isError, isSuccess, error, refetch, isRefetching, abort, aborted } = useQuery(() => fetch('url'));\n */\nexport const useQuery = <QueryData, Data = QueryData>(\n callback: (params: UseQueryCallbackParams) => Promise<QueryData>,\n options?: UseQueryOptions<QueryData, Data>\n): UseQueryReturn<Data> => {\n const enabled = options?.enabled ?? true;\n const retryCountRef = useRef(options?.retry ? getRetry(options.retry) : 0);\n const alreadyRequested = useRef(false);\n\n const [isFetching, setIsFetching] = useState(false);\n const [isLoading, setIsLoading] = useState(false);\n const [isError, setIsError] = useState(false);\n const [isRefetching, setIsRefetching] = useState(false);\n const [isSuccess, setIsSuccess] = useState(!!options?.placeholderData);\n\n const [error, setError] = useState<Error | undefined>(undefined);\n const [data, setData] = useState<Data | undefined>(options?.placeholderData);\n\n const abortControllerRef = useRef<AbortController>(new AbortController());\n const intervalIdRef = useRef<ReturnType<typeof setInterval>>(undefined);\n\n const keys = options?.keys ?? [];\n\n const abort = () => {\n abortControllerRef.current.abort();\n abortControllerRef.current = new AbortController();\n };\n\n const request = (action: 'init' | 'refetch') => {\n abort();\n\n setIsFetching(true);\n if (action === 'init') {\n alreadyRequested.current = true;\n setIsLoading(true);\n }\n if (action === 'refetch') setIsRefetching(true);\n callback({ signal: abortControllerRef.current.signal, keys })\n .then((response) => {\n const data = options?.select ? options?.select(response) : response;\n options?.onSuccess?.(data as Data);\n setData(data as Data);\n setIsSuccess(true);\n setError(undefined);\n setIsError(false);\n setIsFetching(false);\n if (action === 'init') setIsLoading(false);\n if (action === 'refetch') setIsRefetching(false);\n })\n .catch((error: Error) => {\n if (retryCountRef.current > 0) {\n retryCountRef.current -= 1;\n const retryDelay =\n typeof options?.retryDelay === 'function'\n ? options?.retryDelay(retryCountRef.current, error)\n : options?.retryDelay;\n\n if (retryDelay) {\n setTimeout(() => request(action), retryDelay);\n return;\n }\n\n return request(action);\n }\n options?.onError?.(error);\n setData(undefined);\n setIsSuccess(false);\n setError(error);\n setIsError(true);\n setIsFetching(false);\n if (action === 'init') setIsLoading(false);\n if (action === 'refetch') setIsRefetching(false);\n retryCountRef.current = options?.retry ? getRetry(options.retry) : 0;\n })\n .finally(() => {\n if (options?.refetchInterval) {\n const interval = setInterval(() => {\n clearInterval(interval);\n request('refetch');\n }, options?.refetchInterval);\n intervalIdRef.current = interval;\n }\n });\n };\n\n useMount(() => {\n if (!enabled) return;\n request('init');\n });\n\n useDidUpdate(() => {\n if (!enabled) return;\n request(alreadyRequested.current ? 'refetch' : 'init');\n }, [enabled, ...keys]);\n\n useEffect(() => {\n return () => {\n clearInterval(intervalIdRef.current);\n };\n }, [enabled, options?.refetchInterval, options?.retry, ...keys]);\n\n const refetch = () => request('refetch');\n\n return {\n abort,\n data,\n error,\n refetch,\n isFetching,\n isLoading,\n isError,\n isSuccess,\n isRefetching\n };\n};\n"],"names":["useQuery","callback","options","enabled","retryCountRef","useRef","getRetry","alreadyRequested","isFetching","setIsFetching","useState","isLoading","setIsLoading","isError","setIsError","isRefetching","setIsRefetching","isSuccess","setIsSuccess","error","setError","data","setData","abortControllerRef","intervalIdRef","keys","abort","request","action","response","_a","retryDelay","interval","useMount","useDidUpdate","useEffect"],"mappings":";;;;AAgFa,MAAAA,IAAW,CACtBC,GACAC,MACyB;AACnB,QAAAC,KAAUD,KAAA,gBAAAA,EAAS,YAAW,IAC9BE,IAAgBC,EAAOH,KAAA,QAAAA,EAAS,QAAQI,EAASJ,EAAQ,KAAK,IAAI,CAAC,GACnEK,IAAmBF,EAAO,EAAK,GAE/B,CAACG,GAAYC,CAAa,IAAIC,EAAS,EAAK,GAC5C,CAACC,GAAWC,CAAY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IACA,OAAAF;AAAA,IACA,SANc,MAAMQ,EAAQ,SAAS;AAAA,IAOrC,YAAAnB;AAAA,IACA,WAAAG;AAAA,IACA,SAAAE;AAAA,IACA,WAAAI;AAAA,IACA,cAAAF;AAAA,EACF;AACF;"}
@@ -1,26 +1,26 @@
1
- import { useState as v, useRef as d, useEffect as l } from "react";
2
- import { useRefState as R } from "../useRefState/useRefState.mjs";
3
- import { isTarget as g } from "../../utils/helpers/isTarget.mjs";
4
- import { getElement as E } from "../../utils/helpers/getElement.mjs";
5
- const w = (...r) => {
6
- const t = g(r[0]) ? r[0] : void 0, e = t ? r[1] : r[0], o = (e == null ? void 0 : e.enabled) ?? !0, [u, m] = v([]), n = R(), s = d();
7
- return s.current = e == null ? void 0 : e.onChange, l(() => {
8
- if (!o && !t && !n.state) return;
9
- const f = t ? E(t) : n.current;
10
- if (!f) return;
11
- const c = new ResizeObserver((i) => {
12
- var b;
13
- m(i), (b = s.current) == null || b.call(s, i, c);
1
+ import { useState as v, useRef as d, useEffect as g } from "react";
2
+ import { useRefState as l } from "../useRefState/useRefState.mjs";
3
+ import { isTarget as R } from "../../utils/helpers/isTarget.mjs";
4
+ import { getElement as a } from "../../utils/helpers/getElement.mjs";
5
+ const h = (...t) => {
6
+ const r = R(t[0]) ? t[0] : void 0, e = r ? t[1] : t[0], u = (e == null ? void 0 : e.enabled) ?? !0, [f, i] = v([]), n = l(), s = d(e == null ? void 0 : e.onChange);
7
+ return s.current = e == null ? void 0 : e.onChange, g(() => {
8
+ if (!u && !r && !n.state) return;
9
+ const o = r ? a(r) : n.current;
10
+ if (!o) return;
11
+ const c = new ResizeObserver((b) => {
12
+ var m;
13
+ i(b), (m = s.current) == null || m.call(s, b, c);
14
14
  });
15
- return c.observe(f, e), () => {
15
+ return c.observe(o, e), () => {
16
16
  c.disconnect();
17
17
  };
18
- }, [t, n.state, e == null ? void 0 : e.box, o]), t ? { entries: u } : {
18
+ }, [r, n.state, e == null ? void 0 : e.box, u]), r ? { entries: f } : {
19
19
  ref: n,
20
- entries: u
20
+ entries: f
21
21
  };
22
22
  };
23
23
  export {
24
- w as useResizeObserver
24
+ h as useResizeObserver
25
25
  };
26
26
  //# sourceMappingURL=useResizeObserver.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useResizeObserver.mjs","sources":["../../../../src/hooks/useResizeObserver/useResizeObserver.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The resize observer options type */\nexport interface UseResizeObserverOptions extends ResizeObserverOptions {\n /** The enabled state */\n enabled?: boolean;\n /** The resize observer callback */\n onChange?: (entries: ResizeObserverEntry[], observer: ResizeObserver) => void;\n}\n\n/** The resize observer return type */\nexport interface UseResizeObserverReturn {\n /** The resize observer entries */\n entries: ResizeObserverEntry[];\n}\n\nexport interface UseResizeObserver {\n (target: HookTarget, options?: UseResizeObserverOptions): UseResizeObserverReturn;\n\n <Target extends Element>(\n options?: UseResizeObserverOptions,\n target?: never\n ): UseResizeObserverReturn & { ref: StateRef<Target> };\n}\n\n/**\n * @name useResizeObserver\n * @description - Hook that gives you resize observer state\n * @category Browser\n *\n * @browserapi ResizeObserver https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver\n *\n * @overload\n * @template Target The target element\n * @param {boolean} [options.enabled=true] The IntersectionObserver options\n * @param {boolean} [options.box] The IntersectionObserver options\n * @param {(entries: ResizeObserverEntry[], observer: ResizeObserver) => void} [options.onChange] The callback to execute when resize is detected\n * @returns {UseResizeObserverReturn & { ref: StateRef<Target> }} An object containing the resize observer state\n *\n * @example\n * const { ref, entries } = useResizeObserver();\n *\n * @overload\n * @template Target The target element\n * @param {HookTarget} target The target element to observe\n * @param {boolean} [options.enabled=true] The IntersectionObserver options\n * @param {boolean} [options.box] The IntersectionObserver options\n * @param {(entries: ResizeObserverEntry[], observer: ResizeObserver) => void} [options.onChange] The callback to execute when resize is detected\n * @returns {UseResizeObserverReturn} An object containing the resize observer state\n *\n * @example\n * const { entries } = useResizeObserver(ref);\n */\nexport const useResizeObserver = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const options = (target ? params[1] : params[0]) as UseResizeObserverOptions | undefined;\n const enabled = options?.enabled ?? true;\n\n const [entries, setEntries] = useState<ResizeObserverEntry[]>([]);\n\n const internalRef = useRefState<Element>();\n const internalOnChangeRef = useRef<UseResizeObserverOptions['onChange']>();\n internalOnChangeRef.current = options?.onChange;\n\n useEffect(() => {\n if (!enabled && !target && !internalRef.state) return;\n\n const element = target ? getElement(target) : internalRef.current;\n if (!element) return;\n\n const observer = new ResizeObserver((entries) => {\n setEntries(entries);\n internalOnChangeRef.current?.(entries, observer);\n });\n observer.observe(element as Element, options);\n\n return () => {\n observer.disconnect();\n };\n }, [target, internalRef.state, options?.box, enabled]);\n\n if (target) return { entries };\n return {\n ref: internalRef,\n entries\n };\n}) as UseResizeObserver;\n"],"names":["useResizeObserver","params","target","isTarget","options","enabled","entries","setEntries","useState","internalRef","useRefState","internalOnChangeRef","useRef","useEffect","element","getElement","observer","_a"],"mappings":";;;;AA6Da,MAAAA,IAAqB,IAAIC,MAAkB;AAChD,QAAAC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,IAAWF,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,GACxCI,KAAUD,KAAA,gBAAAA,EAAS,YAAW,IAE9B,CAACE,GAASC,CAAU,IAAIC,EAAgC,CAAA,CAAE,GAE1DC,IAAcC,EAAqB,GACnCC,IAAsBC,EAA6C;AAoBrE,SAnBJD,EAAoB,UAAUP,KAAA,gBAAAA,EAAS,UAEvCS,EAAU,MAAM;AACd,QAAI,CAACR,KAAW,CAACH,KAAU,CAACO,EAAY,MAAO;AAE/C,UAAMK,IAAUZ,IAASa,EAAWb,CAAM,IAAIO,EAAY;AAC1D,QAAI,CAACK,EAAS;AAEd,UAAME,IAAW,IAAI,eAAe,CAACV,MAAY;;AAC/C,MAAAC,EAAWD,CAAO,IACEW,IAAAN,EAAA,YAAA,QAAAM,EAAA,KAAAN,GAAUL,GAASU;AAAA,IAAQ,CAChD;AACQ,WAAAA,EAAA,QAAQF,GAAoBV,CAAO,GAErC,MAAM;AACX,MAAAY,EAAS,WAAW;AAAA,IACtB;AAAA,EAAA,GACC,CAACd,GAAQO,EAAY,OAAOL,KAAA,gBAAAA,EAAS,KAAKC,CAAO,CAAC,GAEjDH,IAAe,EAAE,SAAAI,EAAQ,IACtB;AAAA,IACL,KAAKG;AAAA,IACL,SAAAH;AAAA,EACF;AACF;"}
1
+ {"version":3,"file":"useResizeObserver.mjs","sources":["../../../../src/hooks/useResizeObserver/useResizeObserver.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The resize observer options type */\nexport interface UseResizeObserverOptions extends ResizeObserverOptions {\n /** The enabled state */\n enabled?: boolean;\n /** The resize observer callback */\n onChange?: (entries: ResizeObserverEntry[], observer: ResizeObserver) => void;\n}\n\n/** The resize observer return type */\nexport interface UseResizeObserverReturn {\n /** The resize observer entries */\n entries: ResizeObserverEntry[];\n}\n\nexport interface UseResizeObserver {\n (target: HookTarget, options?: UseResizeObserverOptions): UseResizeObserverReturn;\n\n <Target extends Element>(\n options?: UseResizeObserverOptions,\n target?: never\n ): UseResizeObserverReturn & { ref: StateRef<Target> };\n}\n\n/**\n * @name useResizeObserver\n * @description - Hook that gives you resize observer state\n * @category Browser\n *\n * @browserapi ResizeObserver https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver\n *\n * @overload\n * @template Target The target element\n * @param {boolean} [options.enabled=true] The IntersectionObserver options\n * @param {boolean} [options.box] The IntersectionObserver options\n * @param {(entries: ResizeObserverEntry[], observer: ResizeObserver) => void} [options.onChange] The callback to execute when resize is detected\n * @returns {UseResizeObserverReturn & { ref: StateRef<Target> }} An object containing the resize observer state\n *\n * @example\n * const { ref, entries } = useResizeObserver();\n *\n * @overload\n * @template Target The target element\n * @param {HookTarget} target The target element to observe\n * @param {boolean} [options.enabled=true] The IntersectionObserver options\n * @param {boolean} [options.box] The IntersectionObserver options\n * @param {(entries: ResizeObserverEntry[], observer: ResizeObserver) => void} [options.onChange] The callback to execute when resize is detected\n * @returns {UseResizeObserverReturn} An object containing the resize observer state\n *\n * @example\n * const { entries } = useResizeObserver(ref);\n */\nexport const useResizeObserver = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const options = (target ? params[1] : params[0]) as UseResizeObserverOptions | undefined;\n const enabled = options?.enabled ?? true;\n\n const [entries, setEntries] = useState<ResizeObserverEntry[]>([]);\n\n const internalRef = useRefState<Element>();\n const internalOnChangeRef = useRef<UseResizeObserverOptions['onChange']>(options?.onChange);\n internalOnChangeRef.current = options?.onChange;\n\n useEffect(() => {\n if (!enabled && !target && !internalRef.state) return;\n\n const element = target ? getElement(target) : internalRef.current;\n if (!element) return;\n\n const observer = new ResizeObserver((entries) => {\n setEntries(entries);\n internalOnChangeRef.current?.(entries, observer);\n });\n observer.observe(element as Element, options);\n\n return () => {\n observer.disconnect();\n };\n }, [target, internalRef.state, options?.box, enabled]);\n\n if (target) return { entries };\n return {\n ref: internalRef,\n entries\n };\n}) as UseResizeObserver;\n"],"names":["useResizeObserver","params","target","isTarget","options","enabled","entries","setEntries","useState","internalRef","useRefState","internalOnChangeRef","useRef","useEffect","element","getElement","observer","_a"],"mappings":";;;;AA6Da,MAAAA,IAAqB,IAAIC,MAAkB;AAChD,QAAAC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,IAAWF,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,GACxCI,KAAUD,KAAA,gBAAAA,EAAS,YAAW,IAE9B,CAACE,GAASC,CAAU,IAAIC,EAAgC,CAAA,CAAE,GAE1DC,IAAcC,EAAqB,GACnCC,IAAsBC,EAA6CR,KAAA,gBAAAA,EAAS,QAAQ;AAoBtF,SAnBJO,EAAoB,UAAUP,KAAA,gBAAAA,EAAS,UAEvCS,EAAU,MAAM;AACd,QAAI,CAACR,KAAW,CAACH,KAAU,CAACO,EAAY,MAAO;AAE/C,UAAMK,IAAUZ,IAASa,EAAWb,CAAM,IAAIO,EAAY;AAC1D,QAAI,CAACK,EAAS;AAEd,UAAME,IAAW,IAAI,eAAe,CAACV,MAAY;;AAC/C,MAAAC,EAAWD,CAAO,IACEW,IAAAN,EAAA,YAAA,QAAAM,EAAA,KAAAN,GAAUL,GAASU;AAAA,IAAQ,CAChD;AACQ,WAAAA,EAAA,QAAQF,GAAoBV,CAAO,GAErC,MAAM;AACX,MAAAY,EAAS,WAAW;AAAA,IACtB;AAAA,EAAA,GACC,CAACd,GAAQO,EAAY,OAAOL,KAAA,gBAAAA,EAAS,KAAKC,CAAO,CAAC,GAEjDH,IAAe,EAAE,SAAAI,EAAQ,IACtB;AAAA,IACL,KAAKG;AAAA,IACL,SAAAH;AAAA,EACF;AACF;"}
@@ -1,7 +1,7 @@
1
1
  import { useState as n, useRef as s, useEffect as a } from "react";
2
2
  import { useEvent as i } from "../useEvent/useEvent.mjs";
3
3
  function T(u, t) {
4
- const [o, r] = n(!1), e = s(), c = i(u);
4
+ const [o, r] = n(!1), e = s(void 0), c = i(u);
5
5
  return a(() => (e.current = setTimeout(() => {
6
6
  c(), r(!0);
7
7
  }, t), () => {
@@ -1 +1 @@
1
- {"version":3,"file":"useTimeout.mjs","sources":["../../../../src/hooks/useTimeout/useTimeout.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport { useEvent } from '../useEvent/useEvent';\n\n/** The use timeout return type */\ninterface UseTimeoutReturn {\n /** Timeout is ready state value */\n ready: boolean;\n /** Function to clear timeout */\n clear: () => void;\n}\n\n/**\n * @name useTimeout\n * @description - Hook that executes a callback function after a specified delay\n * @category Time\n *\n * @param {() => void} callback The function to be executed after the timeout\n * @param {number} delay The delay in milliseconds before the timeout executes the callback function\n * @returns {UseTimeoutReturn} An object with a `ready` boolean state value and a `clear` function to clear timeout\n *\n * @example\n * const { clear, ready } = useTimeout(() => {}, 5000);\n */\nexport function useTimeout(callback: () => void, delay: number): UseTimeoutReturn {\n const [ready, setReady] = useState(false);\n\n const timeoutIdRef = useRef<ReturnType<typeof setTimeout>>();\n const internalCallback = useEvent(callback);\n\n useEffect(() => {\n timeoutIdRef.current = setTimeout(() => {\n internalCallback();\n setReady(true);\n }, delay);\n\n return () => {\n clearTimeout(timeoutIdRef.current);\n };\n }, [delay]);\n\n const clear = () => {\n clearTimeout(timeoutIdRef.current);\n setReady(true);\n };\n\n return { ready, clear };\n}\n"],"names":["useTimeout","callback","delay","ready","setReady","useState","timeoutIdRef","useRef","internalCallback","useEvent","useEffect"],"mappings":";;AAwBgB,SAAAA,EAAWC,GAAsBC,GAAiC;AAChF,QAAM,CAACC,GAAOC,CAAQ,IAAIC,EAAS,EAAK,GAElCC,IAAeC,EAAsC,GACrDC,IAAmBC,EAASR,CAAQ;AAE1C,SAAAS,EAAU,OACKJ,EAAA,UAAU,WAAW,MAAM;AACrB,IAAAE,EAAA,GACjBJ,EAAS,EAAI;AAAA,KACZF,CAAK,GAED,MAAM;AACX,iBAAaI,EAAa,OAAO;AAAA,EACnC,IACC,CAACJ,CAAK,CAAC,GAOH,EAAE,OAAAC,GAAO,OALF,MAAM;AAClB,iBAAaG,EAAa,OAAO,GACjCF,EAAS,EAAI;AAAA,EACf,EAEsB;AACxB;"}
1
+ {"version":3,"file":"useTimeout.mjs","sources":["../../../../src/hooks/useTimeout/useTimeout.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport { useEvent } from '../useEvent/useEvent';\n\n/** The use timeout return type */\ninterface UseTimeoutReturn {\n /** Timeout is ready state value */\n ready: boolean;\n /** Function to clear timeout */\n clear: () => void;\n}\n\n/**\n * @name useTimeout\n * @description - Hook that executes a callback function after a specified delay\n * @category Time\n *\n * @param {() => void} callback The function to be executed after the timeout\n * @param {number} delay The delay in milliseconds before the timeout executes the callback function\n * @returns {UseTimeoutReturn} An object with a `ready` boolean state value and a `clear` function to clear timeout\n *\n * @example\n * const { clear, ready } = useTimeout(() => {}, 5000);\n */\nexport function useTimeout(callback: () => void, delay: number): UseTimeoutReturn {\n const [ready, setReady] = useState(false);\n\n const timeoutIdRef = useRef<ReturnType<typeof setTimeout>>(undefined);\n const internalCallback = useEvent(callback);\n\n useEffect(() => {\n timeoutIdRef.current = setTimeout(() => {\n internalCallback();\n setReady(true);\n }, delay);\n\n return () => {\n clearTimeout(timeoutIdRef.current);\n };\n }, [delay]);\n\n const clear = () => {\n clearTimeout(timeoutIdRef.current);\n setReady(true);\n };\n\n return { ready, clear };\n}\n"],"names":["useTimeout","callback","delay","ready","setReady","useState","timeoutIdRef","useRef","internalCallback","useEvent","useEffect"],"mappings":";;AAwBgB,SAAAA,EAAWC,GAAsBC,GAAiC;AAChF,QAAM,CAACC,GAAOC,CAAQ,IAAIC,EAAS,EAAK,GAElCC,IAAeC,EAAsC,MAAS,GAC9DC,IAAmBC,EAASR,CAAQ;AAE1C,SAAAS,EAAU,OACKJ,EAAA,UAAU,WAAW,MAAM;AACrB,IAAAE,EAAA,GACjBJ,EAAS,EAAI;AAAA,KACZF,CAAK,GAED,MAAM;AACX,iBAAaI,EAAa,OAAO;AAAA,EACnC,IACC,CAACJ,CAAK,CAAC,GAOH,EAAE,OAAAC,GAAO,OALF,MAAM;AAClB,iBAAaG,EAAa,OAAO,GACjCF,EAAS,EAAI;AAAA,EACf,EAEsB;AACxB;"}
@@ -1,16 +1,16 @@
1
- import { useState as v, useRef as M, useEffect as k } from "react";
1
+ import { useState as S, useRef as M, useEffect as k } from "react";
2
2
  import { useDidUpdate as A } from "../useDidUpdate/useDidUpdate.mjs";
3
- const D = (s) => {
4
- const e = Math.ceil(s), c = Math.floor(e / (60 * 60 * 24)), u = Math.floor(e % (60 * 60 * 24) / (60 * 60)), t = Math.floor(e % (60 * 60) / 60);
3
+ const D = (c) => {
4
+ const e = Math.ceil(c), o = Math.floor(e / (60 * 60 * 24)), u = Math.floor(e % (60 * 60 * 24) / (60 * 60)), t = Math.floor(e % (60 * 60) / 60);
5
5
  return {
6
6
  seconds: Math.floor(e % 60),
7
7
  minutes: t,
8
8
  hours: u,
9
- days: c
9
+ days: o
10
10
  };
11
- }, q = (...s) => {
12
- const e = Math.max(s[0] ?? 0, 0), c = typeof s[1] == "object" ? s[1] : { onExpire: s[1] }, [u, t] = v(e > 0 && ((c == null ? void 0 : c.immediately) ?? !0)), [i, n] = v(e), m = M(), f = M();
13
- f.current = c ?? {}, A(() => {
11
+ }, q = (...c) => {
12
+ const e = Math.max(c[0] ?? 0, 0), o = typeof c[1] == "object" ? c[1] : { onExpire: c[1] }, [u, t] = S(e > 0 && ((o == null ? void 0 : o.immediately) ?? !0)), [i, n] = S(e), m = M(void 0), f = M(o);
13
+ f.current = o ?? {}, A(() => {
14
14
  if (e <= 0) {
15
15
  t(!1), n(0);
16
16
  return;
@@ -20,15 +20,15 @@ const D = (s) => {
20
20
  var r, a;
21
21
  if (!u) return;
22
22
  (a = (r = f.current) == null ? void 0 : r.onStart) == null || a.call(r);
23
- const o = () => {
23
+ const s = () => {
24
24
  var d, p;
25
25
  (p = (d = f.current) == null ? void 0 : d.onTick) == null || p.call(d, i), n((j) => {
26
- var l, S;
26
+ var l, v;
27
27
  const h = j - 1;
28
- return h === 0 && (t(!1), (S = (l = f.current) == null ? void 0 : l.onExpire) == null || S.call(l)), h;
28
+ return h === 0 && (t(!1), (v = (l = f.current) == null ? void 0 : l.onExpire) == null || v.call(l)), h;
29
29
  });
30
30
  };
31
- return m.current = setInterval(o, 1e3), () => {
31
+ return m.current = setInterval(s, 1e3), () => {
32
32
  clearInterval(m.current);
33
33
  };
34
34
  }, [u]);
@@ -36,15 +36,15 @@ const D = (s) => {
36
36
  i <= 0 || t(!0);
37
37
  }, T = () => {
38
38
  i <= 0 || t(!u);
39
- }, g = (o, r = !0) => {
40
- n(o), r && t(!0);
39
+ }, g = (s, r = !0) => {
40
+ n(s), r && t(!0);
41
41
  }, y = () => {
42
42
  e <= 0 || (t(!0), n(e));
43
43
  }, E = () => {
44
44
  t(!1), n(0);
45
- }, R = (o) => n((r) => r + o), b = (o) => {
45
+ }, R = (s) => n((r) => r + s), b = (s) => {
46
46
  n((r) => {
47
- const a = r - o;
47
+ const a = r - s;
48
48
  return a <= 0 ? (t(!1), 0) : a;
49
49
  });
50
50
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useTimer.mjs","sources":["../../../../src/hooks/useTimer/useTimer.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport { useDidUpdate } from '../useDidUpdate/useDidUpdate';\n\nexport type PositiveInteger<Value extends number> = `${Value}` extends `-${any}` | `${any}.${any}`\n ? never\n : Value;\n\nexport const getTimeFromSeconds = (timestamp: number) => {\n const roundedTimestamp = Math.ceil(timestamp);\n const days = Math.floor(roundedTimestamp / (60 * 60 * 24));\n const hours = Math.floor((roundedTimestamp % (60 * 60 * 24)) / (60 * 60));\n const minutes = Math.floor((roundedTimestamp % (60 * 60)) / 60);\n const seconds = Math.floor(roundedTimestamp % 60);\n\n return {\n seconds,\n minutes,\n hours,\n days\n };\n};\n\n/** The use timer options type */\nexport interface UseTimerOptions {\n /** Whether the timer should start automatically */\n immediately?: boolean;\n /** The function to be executed when the timer is expired */\n onExpire?: () => void;\n /** The function to be executed when the timer is started */\n onStart?: () => void;\n /** Callback function to be executed on each tick of the timer */\n onTick?: (seconds: number) => void;\n}\n\n/** The use timer return type */\nexport interface UseTimerReturn {\n /** flag to indicate if timer is active or not */\n active: boolean;\n /** The total count of the timer */\n count: number;\n /** The day count of the timer */\n days: number;\n /** The hour count of the timer */\n hours: number;\n /** The minute count of the timer */\n minutes: number;\n /** The second count of the timer */\n seconds: number;\n /** The function to clear the timer */\n clear: () => void;\n /** The function to decrease the timer */\n decrease: (seconds: PositiveInteger<number>) => void;\n /** The function to increase the timer */\n increase: (seconds: PositiveInteger<number>) => void;\n /** The function to pause the timer */\n pause: () => void;\n /** The function to restart the timer */\n restart: (time: PositiveInteger<number>, immediately?: boolean) => void;\n /** The function to resume the timer */\n resume: () => void;\n /** The function to start the timer */\n start: () => void;\n /** The function to toggle the timer */\n toggle: () => void;\n}\n\nexport interface UseTimer {\n (): UseTimerReturn;\n\n (seconds: PositiveInteger<number>, callback: () => void): UseTimerReturn;\n\n (seconds: PositiveInteger<number>, options?: UseTimerOptions): UseTimerReturn;\n}\n\n/**\n * @name useTimer\n * @description - Hook that creates a timer functionality\n * @category Time\n *\n * @overload\n * @returns {UseTimerReturn} An object containing the timer properties and functions\n *\n * @example\n * const { days, hours, minutes, seconds, toggle, pause, start, restart, resume, active, decrease, increase } = useTimer();\n *\n * @overload\n * @param {number} seconds The seconds value that define for how long the timer will be running\n * @param {() => void} callback The function to be executed once countdown timer is expired\n * @returns {UseTimerReturn} An object containing the timer properties and functions\n *\n * @example\n * const { days, hours, minutes, seconds, toggle, pause, start, restart, resume, active, decrease, increase } = useTimer(1000, () => console.log('ready'));\n *\n * @overload\n * @param {number} seconds The seconds value that define for how long the timer will be running\n * @param {boolean} [options.immediately=true] The flag to decide if timer should start automatically\n * @param {() => void} [options.onExpire] The function to be executed when the timer is expired\n * @param {(timestamp: number) => void} [options.onTick] The function to be executed on each tick of the timer\n * @returns {UseTimerReturn} An object containing the timer properties and functions\n *\n * @example\n * const { days, hours, minutes, seconds, toggle, pause, start, restart, resume, active, decrease, increase } = useTimer(1000);\n */\nexport const useTimer = ((...params: any[]) => {\n const initialSeconds = Math.max((params[0] ?? 0) as PositiveInteger<number>, 0);\n const options = (typeof params[1] === 'object' ? params[1] : { onExpire: params[1] }) as\n | UseTimerOptions\n | undefined;\n\n const [active, setActive] = useState(initialSeconds > 0 && (options?.immediately ?? true));\n const [seconds, setSeconds] = useState(initialSeconds);\n\n const intervalIdRef = useRef<ReturnType<typeof setInterval>>();\n const optionsRef = useRef<UseTimerOptions>();\n optionsRef.current = options ?? {};\n\n useDidUpdate(() => {\n if (initialSeconds <= 0) {\n setActive(false);\n setSeconds(0);\n return;\n }\n\n setActive(true);\n setSeconds(initialSeconds);\n }, [initialSeconds]);\n\n useEffect(() => {\n if (!active) return;\n\n optionsRef.current?.onStart?.();\n const onInterval = () => {\n optionsRef.current?.onTick?.(seconds);\n setSeconds((prevSeconds) => {\n const updatedSeconds = prevSeconds - 1;\n if (updatedSeconds === 0) {\n setActive(false);\n optionsRef.current?.onExpire?.();\n }\n return updatedSeconds;\n });\n };\n\n intervalIdRef.current = setInterval(onInterval, 1000);\n return () => {\n clearInterval(intervalIdRef.current);\n };\n }, [active]);\n\n const pause = () => setActive(false);\n const resume = () => {\n if (seconds <= 0) return;\n setActive(true);\n };\n\n const toggle = () => {\n if (seconds <= 0) return;\n setActive(!active);\n };\n\n const restart = (seconds: PositiveInteger<number>, immediately = true) => {\n setSeconds(seconds);\n if (immediately) setActive(true);\n };\n\n const start = () => {\n if (initialSeconds <= 0) return;\n\n setActive(true);\n setSeconds(initialSeconds);\n };\n\n const clear = () => {\n setActive(false);\n setSeconds(0);\n };\n\n const increase = (seconds: PositiveInteger<number>) =>\n setSeconds((prevSeconds) => prevSeconds + seconds);\n const decrease = (seconds: PositiveInteger<number>) => {\n setSeconds((prevSeconds) => {\n const updatedSeconds = prevSeconds - seconds;\n if (updatedSeconds <= 0) {\n setActive(false);\n return 0;\n } else {\n return updatedSeconds;\n }\n });\n };\n\n return {\n ...getTimeFromSeconds(seconds),\n count: seconds,\n pause,\n active,\n resume,\n toggle,\n start,\n restart,\n clear,\n increase,\n decrease\n };\n}) as UseTimer;\n"],"names":["getTimeFromSeconds","timestamp","roundedTimestamp","days","hours","minutes","useTimer","params","initialSeconds","options","active","setActive","useState","seconds","setSeconds","intervalIdRef","useRef","optionsRef","useDidUpdate","useEffect","_b","_a","onInterval","prevSeconds","updatedSeconds","pause","resume","toggle","restart","immediately","start","clear","increase","decrease"],"mappings":";;AAQa,MAAAA,IAAqB,CAACC,MAAsB;AACjD,QAAAC,IAAmB,KAAK,KAAKD,CAAS,GACtCE,IAAO,KAAK,MAAMD,KAAoB,KAAK,KAAK,GAAG,GACnDE,IAAQ,KAAK,MAAOF,KAAoB,KAAK,KAAK,OAAQ,KAAK,GAAG,GAClEG,IAAU,KAAK,MAAOH,KAAoB,KAAK,MAAO,EAAE;AAGvD,SAAA;AAAA,IACL,SAHc,KAAK,MAAMA,IAAmB,EAAE;AAAA,IAI9C,SAAAG;AAAA,IACA,OAAAD;AAAA,IACA,MAAAD;AAAA,EACF;AACF,GAmFaG,IAAY,IAAIC,MAAkB;AAC7C,QAAMC,IAAiB,KAAK,IAAKD,EAAO,CAAC,KAAK,GAA+B,CAAC,GACxEE,IAAW,OAAOF,EAAO,CAAC,KAAM,WAAWA,EAAO,CAAC,IAAI,EAAE,UAAUA,EAAO,CAAC,EAAE,GAI7E,CAACG,GAAQC,CAAS,IAAIC,EAASJ,IAAiB,OAAMC,KAAA,gBAAAA,EAAS,gBAAe,GAAK,GACnF,CAACI,GAASC,CAAU,IAAIF,EAASJ,CAAc,GAE/CO,IAAgBC,EAAuC,GACvDC,IAAaD,EAAwB;AAChC,EAAAC,EAAA,UAAUR,KAAW,CAAC,GAEjCS,EAAa,MAAM;AACjB,QAAIV,KAAkB,GAAG;AACvB,MAAAG,EAAU,EAAK,GACfG,EAAW,CAAC;AACZ;AAAA,IAAA;AAGF,IAAAH,EAAU,EAAI,GACdG,EAAWN,CAAc;AAAA,EAAA,GACxB,CAACA,CAAc,CAAC,GAEnBW,EAAU,MAAM;;AACd,QAAI,CAACT,EAAQ;AAEb,KAAAU,KAAAC,IAAAJ,EAAW,YAAX,gBAAAI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7B,OAAOA;AAAA,IACP,OAAAY;AAAA,IACA,QAAAf;AAAA,IACA,QAAAgB;AAAA,IACA,QAAAC;AAAA,IACA,OAAAG;AAAA,IACA,SAAAF;AAAA,IACA,OAAAG;AAAA,IACA,UAAAC;AAAA,IACA,UAAAC;AAAA,EACF;AACF;"}
1
+ {"version":3,"file":"useTimer.mjs","sources":["../../../../src/hooks/useTimer/useTimer.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport { useDidUpdate } from '../useDidUpdate/useDidUpdate';\n\nexport type PositiveInteger<Value extends number> = `${Value}` extends `-${any}` | `${any}.${any}`\n ? never\n : Value;\n\nexport const getTimeFromSeconds = (timestamp: number) => {\n const roundedTimestamp = Math.ceil(timestamp);\n const days = Math.floor(roundedTimestamp / (60 * 60 * 24));\n const hours = Math.floor((roundedTimestamp % (60 * 60 * 24)) / (60 * 60));\n const minutes = Math.floor((roundedTimestamp % (60 * 60)) / 60);\n const seconds = Math.floor(roundedTimestamp % 60);\n\n return {\n seconds,\n minutes,\n hours,\n days\n };\n};\n\n/** The use timer options type */\nexport interface UseTimerOptions {\n /** Whether the timer should start automatically */\n immediately?: boolean;\n /** The function to be executed when the timer is expired */\n onExpire?: () => void;\n /** The function to be executed when the timer is started */\n onStart?: () => void;\n /** Callback function to be executed on each tick of the timer */\n onTick?: (seconds: number) => void;\n}\n\n/** The use timer return type */\nexport interface UseTimerReturn {\n /** flag to indicate if timer is active or not */\n active: boolean;\n /** The total count of the timer */\n count: number;\n /** The day count of the timer */\n days: number;\n /** The hour count of the timer */\n hours: number;\n /** The minute count of the timer */\n minutes: number;\n /** The second count of the timer */\n seconds: number;\n /** The function to clear the timer */\n clear: () => void;\n /** The function to decrease the timer */\n decrease: (seconds: PositiveInteger<number>) => void;\n /** The function to increase the timer */\n increase: (seconds: PositiveInteger<number>) => void;\n /** The function to pause the timer */\n pause: () => void;\n /** The function to restart the timer */\n restart: (time: PositiveInteger<number>, immediately?: boolean) => void;\n /** The function to resume the timer */\n resume: () => void;\n /** The function to start the timer */\n start: () => void;\n /** The function to toggle the timer */\n toggle: () => void;\n}\n\nexport interface UseTimer {\n (): UseTimerReturn;\n\n (seconds: PositiveInteger<number>, callback: () => void): UseTimerReturn;\n\n (seconds: PositiveInteger<number>, options?: UseTimerOptions): UseTimerReturn;\n}\n\n/**\n * @name useTimer\n * @description - Hook that creates a timer functionality\n * @category Time\n *\n * @overload\n * @returns {UseTimerReturn} An object containing the timer properties and functions\n *\n * @example\n * const { days, hours, minutes, seconds, toggle, pause, start, restart, resume, active, decrease, increase } = useTimer();\n *\n * @overload\n * @param {number} seconds The seconds value that define for how long the timer will be running\n * @param {() => void} callback The function to be executed once countdown timer is expired\n * @returns {UseTimerReturn} An object containing the timer properties and functions\n *\n * @example\n * const { days, hours, minutes, seconds, toggle, pause, start, restart, resume, active, decrease, increase } = useTimer(1000, () => console.log('ready'));\n *\n * @overload\n * @param {number} seconds The seconds value that define for how long the timer will be running\n * @param {boolean} [options.immediately=true] The flag to decide if timer should start automatically\n * @param {() => void} [options.onExpire] The function to be executed when the timer is expired\n * @param {(timestamp: number) => void} [options.onTick] The function to be executed on each tick of the timer\n * @returns {UseTimerReturn} An object containing the timer properties and functions\n *\n * @example\n * const { days, hours, minutes, seconds, toggle, pause, start, restart, resume, active, decrease, increase } = useTimer(1000);\n */\nexport const useTimer = ((...params: any[]) => {\n const initialSeconds = Math.max((params[0] ?? 0) as PositiveInteger<number>, 0);\n const options = (typeof params[1] === 'object' ? params[1] : { onExpire: params[1] }) as\n | UseTimerOptions\n | undefined;\n\n const [active, setActive] = useState(initialSeconds > 0 && (options?.immediately ?? true));\n const [seconds, setSeconds] = useState(initialSeconds);\n\n const intervalIdRef = useRef<ReturnType<typeof setInterval>>(undefined);\n const optionsRef = useRef<UseTimerOptions>(options);\n optionsRef.current = options ?? {};\n\n useDidUpdate(() => {\n if (initialSeconds <= 0) {\n setActive(false);\n setSeconds(0);\n return;\n }\n\n setActive(true);\n setSeconds(initialSeconds);\n }, [initialSeconds]);\n\n useEffect(() => {\n if (!active) return;\n\n optionsRef.current?.onStart?.();\n const onInterval = () => {\n optionsRef.current?.onTick?.(seconds);\n setSeconds((prevSeconds) => {\n const updatedSeconds = prevSeconds - 1;\n if (updatedSeconds === 0) {\n setActive(false);\n optionsRef.current?.onExpire?.();\n }\n return updatedSeconds;\n });\n };\n\n intervalIdRef.current = setInterval(onInterval, 1000);\n return () => {\n clearInterval(intervalIdRef.current);\n };\n }, [active]);\n\n const pause = () => setActive(false);\n const resume = () => {\n if (seconds <= 0) return;\n setActive(true);\n };\n\n const toggle = () => {\n if (seconds <= 0) return;\n setActive(!active);\n };\n\n const restart = (seconds: PositiveInteger<number>, immediately = true) => {\n setSeconds(seconds);\n if (immediately) setActive(true);\n };\n\n const start = () => {\n if (initialSeconds <= 0) return;\n\n setActive(true);\n setSeconds(initialSeconds);\n };\n\n const clear = () => {\n setActive(false);\n setSeconds(0);\n };\n\n const increase = (seconds: PositiveInteger<number>) =>\n setSeconds((prevSeconds) => prevSeconds + seconds);\n const decrease = (seconds: PositiveInteger<number>) => {\n setSeconds((prevSeconds) => {\n const updatedSeconds = prevSeconds - seconds;\n if (updatedSeconds <= 0) {\n setActive(false);\n return 0;\n } else {\n return updatedSeconds;\n }\n });\n };\n\n return {\n ...getTimeFromSeconds(seconds),\n count: seconds,\n pause,\n active,\n resume,\n toggle,\n start,\n restart,\n clear,\n increase,\n decrease\n };\n}) as UseTimer;\n"],"names":["getTimeFromSeconds","timestamp","roundedTimestamp","days","hours","minutes","useTimer","params","initialSeconds","options","active","setActive","useState","seconds","setSeconds","intervalIdRef","useRef","optionsRef","useDidUpdate","useEffect","_b","_a","onInterval","prevSeconds","updatedSeconds","pause","resume","toggle","restart","immediately","start","clear","increase","decrease"],"mappings":";;AAQa,MAAAA,IAAqB,CAACC,MAAsB;AACjD,QAAAC,IAAmB,KAAK,KAAKD,CAAS,GACtCE,IAAO,KAAK,MAAMD,KAAoB,KAAK,KAAK,GA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AAX,gBAAAI,EAAoB,aAApB,QAAAD,EAAA,KAAAC,KAEKG;AAAA,MAAA,CACR;AAAA,IACH;AAEc,WAAAT,EAAA,UAAU,YAAYO,GAAY,GAAI,GAC7C,MAAM;AACX,oBAAcP,EAAc,OAAO;AAAA,IACrC;AAAA,EAAA,GACC,CAACL,CAAM,CAAC;AAEL,QAAAe,IAAQ,MAAMd,EAAU,EAAK,GAC7Be,IAAS,MAAM;AACnB,IAAIb,KAAW,KACfF,EAAU,EAAI;AAAA,EAChB,GAEMgB,IAAS,MAAM;AACnB,IAAId,KAAW,KACfF,EAAU,CAACD,CAAM;AAAA,EACnB,GAEMkB,IAAU,CAACf,GAAkCgB,IAAc,OAAS;AACxE,IAAAf,EAAWD,CAAO,GACdgB,OAAuB,EAAI;AAAA,EACjC,GAEMC,IAAQ,MAAM;AAClB,IAAItB,KAAkB,MAEtBG,EAAU,EAAI,GACdG,EAAWN,CAAc;AAAA,EAC3B,GAEMuB,IAAQ,MAAM;AAClB,IAAApB,EAAU,EAAK,GACfG,EAAW,CAAC;AAAA,EACd,GAEMkB,IAAW,CAACnB,MAChBC,EAAW,CAACS,MAAgBA,IAAcV,CAAO,GAC7CoB,IAAW,CAACpB,MAAqC;AACrD,IAAAC,EAAW,CAACS,MAAgB;AAC1B,YAAMC,IAAiBD,IAAcV;AACrC,aAAIW,KAAkB,KACpBb,EAAU,EAAK,GACR,KAEAa;AAAA,IACT,CACD;AAAA,EACH;AAEO,SAAA;AAAA,IACL,GAAGxB,EAAmBa,CAAO;AAAA,IAC7B,OAAOA;AAAA,IACP,OAAAY;AAAA,IACA,QAAAf;AAAA,IACA,QAAAgB;AAAA,IACA,QAAAC;AAAA,IACA,OAAAG;AAAA,IACA,SAAAF;AAAA,IACA,OAAAG;AAAA,IACA,UAAAC;AAAA,IACA,UAAAC;AAAA,EACF;AACF;"}
@@ -1,22 +1,22 @@
1
1
  import { useRef as v, useState as l, useEffect as g } from "react";
2
- const I = (a, t = 0) => {
3
- const e = typeof navigator < "u" && "vibrate" in navigator, r = v(), [f, n] = l(!1), c = (u = a) => {
2
+ const d = (a, t = 0) => {
3
+ const e = typeof navigator < "u" && "vibrate" in navigator, r = v(void 0), [o, n] = l(!1), c = (u = a) => {
4
4
  e && navigator.vibrate(u);
5
- }, s = () => {
5
+ }, i = () => {
6
6
  e && (navigator.vibrate(0), n(!1), r.current && clearInterval(r.current));
7
- }, o = () => {
7
+ }, f = () => {
8
8
  e && (n(!1), r.current && clearInterval(r.current));
9
- }, i = (u = t) => {
9
+ }, s = (u = t) => {
10
10
  e && (r.current && clearInterval(r.current), n(!0), r.current = setInterval(c, u));
11
11
  };
12
12
  return g(() => {
13
13
  if (!(!e || t <= 0))
14
- return i(t), () => {
15
- s();
14
+ return s(t), () => {
15
+ i();
16
16
  };
17
- }, [t, a]), { supported: e, trigger: c, stop: s, active: f, pause: o, resume: i };
17
+ }, [t, a]), { supported: e, trigger: c, stop: i, active: o, pause: f, resume: s };
18
18
  };
19
19
  export {
20
- I as useVibrate
20
+ d as useVibrate
21
21
  };
22
22
  //# sourceMappingURL=useVibrate.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useVibrate.mjs","sources":["../../../../src/hooks/useVibrate/useVibrate.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\n/** The use vibrate pattern type */\nexport type UseVibratePattern = number | number[];\n\n/** The use vibrate return type */\nexport interface UseVibrateReturn {\n /** The support indicator */\n supported: boolean;\n /** The vibrating indicator */\n vibrating: boolean;\n /** The pause function */\n pause: () => void;\n /** The resume function */\n resume: () => void;\n /** The start function */\n start: (interval: number) => void;\n /** The vibrate function */\n trigger: (pattern?: UseVibratePattern) => void;\n}\n\n/**\n * @name useVibrate\n * @description - Hook that provides vibrate api\n * @category Browser\n *\n * @browserapi navigator.vibrate https://developer.mozilla.org/en-US/docs/Web/API/Navigator/vibrate\n *\n * @overload\n * @param {UseVibratePattern} options.pattern The pattern for vibration\n * @param {number} [options.interval=0] Time in milliseconds between vibrations\n * @returns {UseVibrateReturn} An object containing support indicator, start vibration and stop vibration functions\n *\n * @example\n * const { supported, active, vibrate, stop, pause, resume } = useVibrate(1000);\n */\nexport const useVibrate = (pattern: UseVibratePattern, interval: number = 0) => {\n const supported = typeof navigator !== 'undefined' && 'vibrate' in navigator;\n\n const intervalIdRef = useRef<ReturnType<typeof setInterval>>();\n const [active, setActive] = useState(false);\n\n const trigger = (internalPattern: UseVibratePattern = pattern) => {\n if (!supported) return;\n navigator.vibrate(internalPattern);\n };\n\n const stop = () => {\n if (!supported) return;\n navigator.vibrate(0);\n setActive(false);\n if (intervalIdRef.current) clearInterval(intervalIdRef.current);\n };\n\n const pause = () => {\n if (!supported) return;\n setActive(false);\n if (intervalIdRef.current) clearInterval(intervalIdRef.current);\n };\n\n const resume = (intervalInterval: number = interval) => {\n if (!supported) return;\n if (intervalIdRef.current) clearInterval(intervalIdRef.current);\n setActive(true);\n intervalIdRef.current = setInterval(trigger, intervalInterval);\n };\n\n useEffect(() => {\n if (!supported || interval <= 0) return;\n resume(interval);\n return () => {\n stop();\n };\n }, [interval, pattern]);\n\n return { supported, trigger, stop, active, pause, resume };\n};\n"],"names":["useVibrate","pattern","interval","supported","intervalIdRef","useRef","active","setActive","useState","trigger","internalPattern","stop","pause","resume","intervalInterval","useEffect"],"mappings":";AAoCO,MAAMA,IAAa,CAACC,GAA4BC,IAAmB,MAAM;AAC9E,QAAMC,IAAY,OAAO,YAAc,OAAe,aAAa,WAE7DC,IAAgBC,EAAuC,GACvD,CAACC,GAAQC,CAAS,IAAIC,EAAS,EAAK,GAEpCC,IAAU,CAACC,IAAqCT,MAAY;AAChE,IAAKE,KACL,UAAU,QAAQO,CAAe;AAAA,EACnC,GAEMC,IAAO,MAAM;AACjB,IAAKR,MACL,UAAU,QAAQ,CAAC,GACnBI,EAAU,EAAK,GACXH,EAAc,WAAuB,cAAAA,EAAc,OAAO;AAAA,EAChE,GAEMQ,IAAQ,MAAM;AAClB,IAAKT,MACLI,EAAU,EAAK,GACXH,EAAc,WAAuB,cAAAA,EAAc,OAAO;AAAA,EAChE,GAEMS,IAAS,CAACC,IAA2BZ,MAAa;AACtD,IAAKC,MACDC,EAAc,WAAuB,cAAAA,EAAc,OAAO,GAC9DG,EAAU,EAAI,GACAH,EAAA,UAAU,YAAYK,GAASK,CAAgB;AAAA,EAC/D;AAEA,SAAAC,EAAU,MAAM;AACV,QAAA,GAACZ,KAAaD,KAAY;AAC9B,aAAAW,EAAOX,CAAQ,GACR,MAAM;AACN,QAAAS,EAAA;AAAA,MACP;AAAA,EAAA,GACC,CAACT,GAAUD,CAAO,CAAC,GAEf,EAAE,WAAAE,GAAW,SAAAM,GAAS,MAAAE,GAAM,QAAAL,GAAQ,OAAAM,GAAO,QAAAC,EAAO;AAC3D;"}
1
+ {"version":3,"file":"useVibrate.mjs","sources":["../../../../src/hooks/useVibrate/useVibrate.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\n/** The use vibrate pattern type */\nexport type UseVibratePattern = number | number[];\n\n/** The use vibrate return type */\nexport interface UseVibrateReturn {\n /** The support indicator */\n supported: boolean;\n /** The vibrating indicator */\n vibrating: boolean;\n /** The pause function */\n pause: () => void;\n /** The resume function */\n resume: () => void;\n /** The start function */\n start: (interval: number) => void;\n /** The vibrate function */\n trigger: (pattern?: UseVibratePattern) => void;\n}\n\n/**\n * @name useVibrate\n * @description - Hook that provides vibrate api\n * @category Browser\n *\n * @browserapi navigator.vibrate https://developer.mozilla.org/en-US/docs/Web/API/Navigator/vibrate\n *\n * @overload\n * @param {UseVibratePattern} options.pattern The pattern for vibration\n * @param {number} [options.interval=0] Time in milliseconds between vibrations\n * @returns {UseVibrateReturn} An object containing support indicator, start vibration and stop vibration functions\n *\n * @example\n * const { supported, active, vibrate, stop, pause, resume } = useVibrate(1000);\n */\nexport const useVibrate = (pattern: UseVibratePattern, interval: number = 0) => {\n const supported = typeof navigator !== 'undefined' && 'vibrate' in navigator;\n\n const intervalIdRef = useRef<ReturnType<typeof setInterval>>(undefined);\n const [active, setActive] = useState(false);\n\n const trigger = (internalPattern: UseVibratePattern = pattern) => {\n if (!supported) return;\n navigator.vibrate(internalPattern);\n };\n\n const stop = () => {\n if (!supported) return;\n navigator.vibrate(0);\n setActive(false);\n if (intervalIdRef.current) clearInterval(intervalIdRef.current);\n };\n\n const pause = () => {\n if (!supported) return;\n setActive(false);\n if (intervalIdRef.current) clearInterval(intervalIdRef.current);\n };\n\n const resume = (intervalInterval: number = interval) => {\n if (!supported) return;\n if (intervalIdRef.current) clearInterval(intervalIdRef.current);\n setActive(true);\n intervalIdRef.current = setInterval(trigger, intervalInterval);\n };\n\n useEffect(() => {\n if (!supported || interval <= 0) return;\n resume(interval);\n return () => {\n stop();\n };\n }, [interval, pattern]);\n\n return { supported, trigger, stop, active, pause, resume };\n};\n"],"names":["useVibrate","pattern","interval","supported","intervalIdRef","useRef","active","setActive","useState","trigger","internalPattern","stop","pause","resume","intervalInterval","useEffect"],"mappings":";AAoCO,MAAMA,IAAa,CAACC,GAA4BC,IAAmB,MAAM;AAC9E,QAAMC,IAAY,OAAO,YAAc,OAAe,aAAa,WAE7DC,IAAgBC,EAAuC,MAAS,GAChE,CAACC,GAAQC,CAAS,IAAIC,EAAS,EAAK,GAEpCC,IAAU,CAACC,IAAqCT,MAAY;AAChE,IAAKE,KACL,UAAU,QAAQO,CAAe;AAAA,EACnC,GAEMC,IAAO,MAAM;AACjB,IAAKR,MACL,UAAU,QAAQ,CAAC,GACnBI,EAAU,EAAK,GACXH,EAAc,WAAuB,cAAAA,EAAc,OAAO;AAAA,EAChE,GAEMQ,IAAQ,MAAM;AAClB,IAAKT,MACLI,EAAU,EAAK,GACXH,EAAc,WAAuB,cAAAA,EAAc,OAAO;AAAA,EAChE,GAEMS,IAAS,CAACC,IAA2BZ,MAAa;AACtD,IAAKC,MACDC,EAAc,WAAuB,cAAAA,EAAc,OAAO,GAC9DG,EAAU,EAAI,GACAH,EAAA,UAAU,YAAYK,GAASK,CAAgB;AAAA,EAC/D;AAEA,SAAAC,EAAU,MAAM;AACV,QAAA,GAACZ,KAAaD,KAAY;AAC9B,aAAAW,EAAOX,CAAQ,GACR,MAAM;AACN,QAAAS,EAAA;AAAA,MACP;AAAA,EAAA,GACC,CAACT,GAAUD,CAAO,CAAC,GAEf,EAAE,WAAAE,GAAW,SAAAM,GAAS,MAAAE,GAAM,QAAAL,GAAQ,OAAAM,GAAO,QAAAC,EAAO;AAC3D;"}
@@ -1,6 +1,6 @@
1
- import { useState as v, useRef as d, useEffect as f } from "react";
1
+ import { useState as d, useRef as l, useEffect as f } from "react";
2
2
  const m = (e) => {
3
- const r = typeof navigator < "u" && "wakeLock" in navigator, [u, n] = v(!1), t = d(), l = (e == null ? void 0 : e.immediately) ?? !1, c = (e == null ? void 0 : e.type) ?? "screen", i = async (a) => {
3
+ const r = typeof navigator < "u" && "wakeLock" in navigator, [u, n] = d(!1), t = l(void 0), v = (e == null ? void 0 : e.immediately) ?? !1, c = (e == null ? void 0 : e.type) ?? "screen", i = async (a) => {
4
4
  r && (t.current = await navigator.wakeLock.request(a ?? (e == null ? void 0 : e.type)), t.current.addEventListener("release", () => {
5
5
  n(!1), t.current = void 0;
6
6
  }), n(!0));
@@ -8,7 +8,7 @@ const m = (e) => {
8
8
  !r || !t.current || (await t.current.release(), t.current = void 0, n(!1));
9
9
  };
10
10
  return f(() => {
11
- if (!r || !l || document.visibilityState !== "visible" || c !== "screen")
11
+ if (!r || !v || document.visibilityState !== "visible" || c !== "screen")
12
12
  return;
13
13
  const a = async () => {
14
14
  await s(), await i(c);
@@ -1 +1 @@
1
- {"version":3,"file":"useWakeLock.mjs","sources":["../../../../src/hooks/useWakeLock/useWakeLock.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\n/** The use wake lock options type */\nexport interface UseWakeLockOptions {\n /** Determines if the wake lock should be automatically reacquired when the document becomes visible. */\n immediately?: boolean;\n /** A string specifying the screen wake lock type. */\n type?: WakeLockType;\n}\n\n/** The use wake lock return type */\nexport interface UseWakeLockReturn {\n /** Indicates if the wake lock is currently active. */\n active: boolean;\n /** Indicates if the Wake Lock API is supported in the current environment. */\n supported: boolean;\n /** Function to release the wake lock. */\n release: () => Promise<void>;\n /** Function to request the wake lock. */\n request: () => Promise<void>;\n}\n\n/**\n * @name useWakeLock\n * @description - Hook that provides a wake lock functionality\n * @category Browser\n *\n * @browserapi navigator.wakeLock https://developer.mozilla.org/en-US/docs/Web/API/WakeLock\n *\n * @param {immediately} [options] Configuration options for the hook.\n * @returns {UseWakeLockReturn} An object containing the wake lock state and control methods.\n *\n * @example\n * const { supported, active, request, release } = useWakeLock();\n */\nexport const useWakeLock = (options?: UseWakeLockOptions): UseWakeLockReturn => {\n const supported = typeof navigator !== 'undefined' && 'wakeLock' in navigator;\n\n const [active, setActive] = useState(false);\n const sentinel = useRef<WakeLockSentinel>();\n\n const immediately = options?.immediately ?? false;\n const type = options?.type ?? 'screen';\n\n const request = async (type?: WakeLockType) => {\n if (!supported) return;\n\n sentinel.current = await navigator.wakeLock.request(type ?? options?.type);\n sentinel.current.addEventListener('release', () => {\n setActive(false);\n sentinel.current = undefined;\n });\n\n setActive(true);\n };\n\n const release = async () => {\n if (!supported || !sentinel.current) return;\n\n await sentinel.current.release();\n sentinel.current = undefined;\n setActive(false);\n };\n\n useEffect(() => {\n if (!supported || !immediately || document.visibilityState !== 'visible' || type !== 'screen')\n return;\n\n const onVisibilityChange = async () => {\n await release();\n await request(type);\n };\n\n document.addEventListener('visibilitychange', onVisibilityChange);\n return () => {\n document.removeEventListener('visibilitychange', onVisibilityChange);\n };\n }, [type]);\n\n return { supported, active, request, release };\n};\n"],"names":["useWakeLock","options","supported","active","setActive","useState","sentinel","useRef","immediately","type","request","release","useEffect","onVisibilityChange"],"mappings":";AAmCa,MAAAA,IAAc,CAACC,MAAoD;AAC9E,QAAMC,IAAY,OAAO,YAAc,OAAe,cAAc,WAE9D,CAACC,GAAQC,CAAS,IAAIC,EAAS,EAAK,GACpCC,IAAWC,EAAyB,GAEpCC,KAAcP,KAAA,gBAAAA,EAAS,gBAAe,IACtCQ,KAAOR,KAAA,gBAAAA,EAAS,SAAQ,UAExBS,IAAU,OAAOD,MAAwB;AAC7C,IAAKP,MAELI,EAAS,UAAU,MAAM,UAAU,SAAS,QAAQG,MAAQR,KAAA,gBAAAA,EAAS,KAAI,GAChEK,EAAA,QAAQ,iBAAiB,WAAW,MAAM;AACjD,MAAAF,EAAU,EAAK,GACfE,EAAS,UAAU;AAAA,IAAA,CACpB,GAEDF,EAAU,EAAI;AAAA,EAChB,GAEMO,IAAU,YAAY;AAC1B,IAAI,CAACT,KAAa,CAACI,EAAS,YAEtB,MAAAA,EAAS,QAAQ,QAAQ,GAC/BA,EAAS,UAAU,QACnBF,EAAU,EAAK;AAAA,EACjB;AAEA,SAAAQ,EAAU,MAAM;AACd,QAAI,CAACV,KAAa,CAACM,KAAe,SAAS,oBAAoB,aAAaC,MAAS;AACnF;AAEF,UAAMI,IAAqB,YAAY;AACrC,YAAMF,EAAQ,GACd,MAAMD,EAAQD,CAAI;AAAA,IACpB;AAES,oBAAA,iBAAiB,oBAAoBI,CAAkB,GACzD,MAAM;AACF,eAAA,oBAAoB,oBAAoBA,CAAkB;AAAA,IACrE;AAAA,EAAA,GACC,CAACJ,CAAI,CAAC,GAEF,EAAE,WAAAP,GAAW,QAAAC,GAAQ,SAAAO,GAAS,SAAAC,EAAQ;AAC/C;"}
1
+ {"version":3,"file":"useWakeLock.mjs","sources":["../../../../src/hooks/useWakeLock/useWakeLock.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\n/** The use wake lock options type */\nexport interface UseWakeLockOptions {\n /** Determines if the wake lock should be automatically reacquired when the document becomes visible. */\n immediately?: boolean;\n /** A string specifying the screen wake lock type. */\n type?: WakeLockType;\n}\n\n/** The use wake lock return type */\nexport interface UseWakeLockReturn {\n /** Indicates if the wake lock is currently active. */\n active: boolean;\n /** Indicates if the Wake Lock API is supported in the current environment. */\n supported: boolean;\n /** Function to release the wake lock. */\n release: () => Promise<void>;\n /** Function to request the wake lock. */\n request: () => Promise<void>;\n}\n\n/**\n * @name useWakeLock\n * @description - Hook that provides a wake lock functionality\n * @category Browser\n *\n * @browserapi navigator.wakeLock https://developer.mozilla.org/en-US/docs/Web/API/WakeLock\n *\n * @param {immediately} [options] Configuration options for the hook.\n * @returns {UseWakeLockReturn} An object containing the wake lock state and control methods.\n *\n * @example\n * const { supported, active, request, release } = useWakeLock();\n */\nexport const useWakeLock = (options?: UseWakeLockOptions): UseWakeLockReturn => {\n const supported = typeof navigator !== 'undefined' && 'wakeLock' in navigator;\n\n const [active, setActive] = useState(false);\n const sentinel = useRef<WakeLockSentinel>(undefined);\n\n const immediately = options?.immediately ?? false;\n const type = options?.type ?? 'screen';\n\n const request = async (type?: WakeLockType) => {\n if (!supported) return;\n\n sentinel.current = await navigator.wakeLock.request(type ?? options?.type);\n sentinel.current.addEventListener('release', () => {\n setActive(false);\n sentinel.current = undefined;\n });\n\n setActive(true);\n };\n\n const release = async () => {\n if (!supported || !sentinel.current) return;\n\n await sentinel.current.release();\n sentinel.current = undefined;\n setActive(false);\n };\n\n useEffect(() => {\n if (!supported || !immediately || document.visibilityState !== 'visible' || type !== 'screen')\n return;\n\n const onVisibilityChange = async () => {\n await release();\n await request(type);\n };\n\n document.addEventListener('visibilitychange', onVisibilityChange);\n return () => {\n document.removeEventListener('visibilitychange', onVisibilityChange);\n };\n }, [type]);\n\n return { supported, active, request, release };\n};\n"],"names":["useWakeLock","options","supported","active","setActive","useState","sentinel","useRef","immediately","type","request","release","useEffect","onVisibilityChange"],"mappings":";AAmCa,MAAAA,IAAc,CAACC,MAAoD;AAC9E,QAAMC,IAAY,OAAO,YAAc,OAAe,cAAc,WAE9D,CAACC,GAAQC,CAAS,IAAIC,EAAS,EAAK,GACpCC,IAAWC,EAAyB,MAAS,GAE7CC,KAAcP,KAAA,gBAAAA,EAAS,gBAAe,IACtCQ,KAAOR,KAAA,gBAAAA,EAAS,SAAQ,UAExBS,IAAU,OAAOD,MAAwB;AAC7C,IAAKP,MAELI,EAAS,UAAU,MAAM,UAAU,SAAS,QAAQG,MAAQR,KAAA,gBAAAA,EAAS,KAAI,GAChEK,EAAA,QAAQ,iBAAiB,WAAW,MAAM;AACjD,MAAAF,EAAU,EAAK,GACfE,EAAS,UAAU;AAAA,IAAA,CACpB,GAEDF,EAAU,EAAI;AAAA,EAChB,GAEMO,IAAU,YAAY;AAC1B,IAAI,CAACT,KAAa,CAACI,EAAS,YAEtB,MAAAA,EAAS,QAAQ,QAAQ,GAC/BA,EAAS,UAAU,QACnBF,EAAU,EAAK;AAAA,EACjB;AAEA,SAAAQ,EAAU,MAAM;AACd,QAAI,CAACV,KAAa,CAACM,KAAe,SAAS,oBAAoB,aAAaC,MAAS;AACnF;AAEF,UAAMI,IAAqB,YAAY;AACrC,YAAMF,EAAQ,GACd,MAAMD,EAAQD,CAAI;AAAA,IACpB;AAES,oBAAA,iBAAiB,oBAAoBI,CAAkB,GACzD,MAAM;AACF,eAAA,oBAAoB,oBAAoBA,CAAkB;AAAA,IACrE;AAAA,EAAA,GACC,CAACJ,CAAI,CAAC,GAEF,EAAE,WAAAP,GAAW,QAAAC,GAAQ,SAAAO,GAAS,SAAAC,EAAQ;AAC/C;"}
@@ -1,14 +1,14 @@
1
- import { useRef as y, useState as k, useEffect as w } from "react";
2
- import { useEvent as C } from "../useEvent/useEvent.mjs";
1
+ import { useRef as y, useState as k, useEffect as v } from "react";
2
+ import { useEvent as w } from "../useEvent/useEvent.mjs";
3
3
  import { getRetry as m } from "../../utils/helpers/getRetry.mjs";
4
4
  const W = (t, e) => {
5
- const u = y(), d = y(e != null && e.retry ? m(e.retry) : 0), a = y(!1), [S, n] = k("connecting"), g = (r) => {
5
+ const u = y(void 0), d = y(e != null && e.retry ? m(e.retry) : 0), a = y(!1), [S, n] = k("connecting"), g = (r) => {
6
6
  var c;
7
7
  return (c = u.current) == null ? void 0 : c.send(r);
8
8
  }, R = () => {
9
9
  var r;
10
10
  a.current = !0, (r = u.current) == null || r.close();
11
- }, l = C(() => {
11
+ }, l = w(() => {
12
12
  u.current = new WebSocket(
13
13
  typeof t == "function" ? t() : t,
14
14
  e == null ? void 0 : e.protocols
@@ -32,7 +32,7 @@ const W = (t, e) => {
32
32
  }
33
33
  });
34
34
  });
35
- w(() => (l(), () => {
35
+ v(() => (l(), () => {
36
36
  u.current && (u.current.close(), u.current = void 0);
37
37
  }), [t]);
38
38
  const b = () => {
@@ -1 +1 @@
1
- {"version":3,"file":"useWebSocket.mjs","sources":["../../../../src/hooks/useWebSocket/useWebSocket.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport { getRetry } from '@/utils/helpers';\n\nimport { useEvent } from '../useEvent/useEvent';\n\nexport type UseWebSocketUrl = (() => string) | string;\n\nexport interface UseWebSocketOptions {\n protocols?: Array<'soap' | 'wasm'>;\n retry?: boolean | number;\n onConnected?: (webSocket: WebSocket) => void;\n onDisconnected?: (event: CloseEvent, webSocket: WebSocket) => void;\n onError?: (event: Event, webSocket: WebSocket) => void;\n onMessage?: (event: MessageEvent, webSocket: WebSocket) => void;\n}\n\nexport type UseWebSocketStatus = 'connected' | 'connecting' | 'disconnected' | 'failed';\n\nexport interface UseWebSocketReturn {\n client?: WebSocket;\n close: WebSocket['close'];\n send: WebSocket['send'];\n status: UseWebSocketStatus;\n open: () => void;\n}\n\n/**\n * @name useWebSocket\n * @description - Hook that connects to a WebSocket server and handles incoming and outgoing messages\n * @category Browser\n *\n * @param {UseWebSocketUrl} url The URL of the WebSocket server\n * @param {(webSocket: WebSocket) => void} [options.onConnected] The callback function that is called when the WebSocket connection is established\n * @param {(event: CloseEvent, webSocket: WebSocket) => void} [options.onDisconnected] The callback function that is called when the WebSocket connection is closed\n * @param {(event: Event, webSocket: WebSocket) => void} [options.onError] The callback function that is called when an error occurs\n * @param {(event: MessageEvent, webSocket: WebSocket) => void} [options.onMessage] The callback function that is called when a message is received\n * @param {boolean | number} [options.retry] The number of times to retry the connection\n * @param {Array<'soap' | 'wasm'>} [options.protocols] The list of protocols to use\n * @returns {UseWebSocketReturn} An object with the status, close, send, open, and ws properties\n *\n * @example\n * const { status, close, send, open, client } = useWebSocket('url');\n */\nexport const useWebSocket = (\n url: UseWebSocketUrl,\n options?: UseWebSocketOptions\n): UseWebSocketReturn => {\n const webSocketRef = useRef<WebSocket>();\n const retryCountRef = useRef(options?.retry ? getRetry(options.retry) : 0);\n const explicityCloseRef = useRef(false);\n\n const [status, setStatus] = useState<UseWebSocketStatus>('connecting');\n\n const send = (data: string | ArrayBufferLike | ArrayBufferView | Blob) =>\n webSocketRef.current?.send(data);\n\n const close = () => {\n explicityCloseRef.current = true;\n webSocketRef.current?.close();\n };\n\n const init = useEvent(() => {\n webSocketRef.current = new WebSocket(\n typeof url === 'function' ? url() : url,\n options?.protocols\n );\n setStatus('connecting');\n\n const webSocket = webSocketRef.current;\n if (!webSocket) return;\n\n webSocket.onopen = () => {\n setStatus('connected');\n options?.onConnected?.(webSocket);\n };\n\n webSocket.onerror = (event) => {\n setStatus('failed');\n options?.onError?.(event, webSocket);\n };\n\n webSocket.onmessage = (event) => options?.onMessage?.(event, webSocket);\n\n webSocket.onclose = (event) => {\n setStatus('disconnected');\n options?.onDisconnected?.(event, webSocket);\n if (explicityCloseRef.current) return;\n\n if (retryCountRef.current > 0) {\n retryCountRef.current -= 1;\n return init();\n }\n retryCountRef.current = options?.retry ? getRetry(options.retry) : 0;\n };\n });\n\n useEffect(() => {\n init();\n\n return () => {\n if (!webSocketRef.current) return;\n webSocketRef.current.close();\n webSocketRef.current = undefined;\n };\n }, [url]);\n\n const open = () => {\n explicityCloseRef.current = false;\n init();\n };\n\n return { client: webSocketRef.current, close, open, send, status };\n};\n"],"names":["useWebSocket","url","options","webSocketRef","useRef","retryCountRef","getRetry","explicityCloseRef","status","setStatus","useState","send","data","_a","close","init","useEvent","webSocket","event","useEffect","open"],"mappings":";;;AA4Ca,MAAAA,IAA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AW,GAClBU,EAAK;AAEd,QAAAV,EAAc,UAAUH,KAAA,QAAAA,EAAS,QAAQI,EAASJ,EAAQ,KAAK,IAAI;AAAA;AAAA,IACrE;AAAA,EAAA,CACD;AAED,EAAAiB,EAAU,OACHJ,EAAA,GAEE,MAAM;AACP,IAACZ,EAAa,YAClBA,EAAa,QAAQ,MAAM,GAC3BA,EAAa,UAAU;AAAA,EACzB,IACC,CAACF,CAAG,CAAC;AAER,QAAMmB,IAAO,MAAM;AACjB,IAAAb,EAAkB,UAAU,IACvBQ,EAAA;AAAA,EACP;AAEA,SAAO,EAAE,QAAQZ,EAAa,SAAS,OAAAW,GAAO,MAAAM,GAAM,MAAAT,GAAM,QAAAH,EAAO;AACnE;"}
1
+ {"version":3,"file":"useWebSocket.mjs","sources":["../../../../src/hooks/useWebSocket/useWebSocket.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport { getRetry } from '@/utils/helpers';\n\nimport { useEvent } from '../useEvent/useEvent';\n\nexport type UseWebSocketUrl = (() => string) | string;\n\nexport interface UseWebSocketOptions {\n protocols?: Array<'soap' | 'wasm'>;\n retry?: boolean | number;\n onConnected?: (webSocket: WebSocket) => void;\n onDisconnected?: (event: CloseEvent, webSocket: WebSocket) => void;\n onError?: (event: Event, webSocket: WebSocket) => void;\n onMessage?: (event: MessageEvent, webSocket: WebSocket) => void;\n}\n\nexport type UseWebSocketStatus = 'connected' | 'connecting' | 'disconnected' | 'failed';\n\nexport interface UseWebSocketReturn {\n client?: WebSocket;\n close: WebSocket['close'];\n send: WebSocket['send'];\n status: UseWebSocketStatus;\n open: () => void;\n}\n\n/**\n * @name useWebSocket\n * @description - Hook that connects to a WebSocket server and handles incoming and outgoing messages\n * @category Browser\n *\n * @param {UseWebSocketUrl} url The URL of the WebSocket server\n * @param {(webSocket: WebSocket) => void} [options.onConnected] The callback function that is called when the WebSocket connection is established\n * @param {(event: CloseEvent, webSocket: WebSocket) => void} [options.onDisconnected] The callback function that is called when the WebSocket connection is closed\n * @param {(event: Event, webSocket: WebSocket) => void} [options.onError] The callback function that is called when an error occurs\n * @param {(event: MessageEvent, webSocket: WebSocket) => void} [options.onMessage] The callback function that is called when a message is received\n * @param {boolean | number} [options.retry] The number of times to retry the connection\n * @param {Array<'soap' | 'wasm'>} [options.protocols] The list of protocols to use\n * @returns {UseWebSocketReturn} An object with the status, close, send, open, and ws properties\n *\n * @example\n * const { status, close, send, open, client } = useWebSocket('url');\n */\nexport const useWebSocket = (\n url: UseWebSocketUrl,\n options?: UseWebSocketOptions\n): UseWebSocketReturn => {\n const webSocketRef = useRef<WebSocket>(undefined);\n const retryCountRef = useRef(options?.retry ? getRetry(options.retry) : 0);\n const explicityCloseRef = useRef(false);\n\n const [status, setStatus] = useState<UseWebSocketStatus>('connecting');\n\n const send = (data: string | ArrayBufferLike | ArrayBufferView | Blob) =>\n webSocketRef.current?.send(data);\n\n const close = () => {\n explicityCloseRef.current = true;\n webSocketRef.current?.close();\n };\n\n const init = useEvent(() => {\n webSocketRef.current = new WebSocket(\n typeof url === 'function' ? url() : url,\n options?.protocols\n );\n setStatus('connecting');\n\n const webSocket = webSocketRef.current;\n if (!webSocket) return;\n\n webSocket.onopen = () => {\n setStatus('connected');\n options?.onConnected?.(webSocket);\n };\n\n webSocket.onerror = (event) => {\n setStatus('failed');\n options?.onError?.(event, webSocket);\n };\n\n webSocket.onmessage = (event) => options?.onMessage?.(event, webSocket);\n\n webSocket.onclose = (event) => {\n setStatus('disconnected');\n options?.onDisconnected?.(event, webSocket);\n if (explicityCloseRef.current) return;\n\n if (retryCountRef.current > 0) {\n retryCountRef.current -= 1;\n return init();\n }\n retryCountRef.current = options?.retry ? getRetry(options.retry) : 0;\n };\n });\n\n useEffect(() => {\n init();\n\n return () => {\n if (!webSocketRef.current) return;\n webSocketRef.current.close();\n webSocketRef.current = undefined;\n };\n }, [url]);\n\n const open = () => {\n explicityCloseRef.current = false;\n init();\n };\n\n return { client: webSocketRef.current, close, open, send, status };\n};\n"],"names":["useWebSocket","url","options","webSocketRef","useRef","retryCountRef","getRetry","explicityCloseRef","status","setStatus","useState","send","data","_a","close","init","useEvent","webSocket","event","useEffect","open"],"mappings":";;;AA4Ca,MAAAA,IAAe,CAC1BC,GACAC,MACuB;AACjB,QAAAC,IAAeC,EAAkB,MAAS,GAC1CC,IAAgBD,EAAOF,KAAA,QAAAA,EAAS,QAAQI,EAASJ,EAAQ,KAAK,IAAI,CAAC,GACnEK,IAAoBH,EAAO,EAAK,GAEhC,CAACI,GAAQC,CAAS,IAAIC,EAA6B,YAAY,GAE/DC,IAAO,CAACC,MAAA;;AACZ,YAAAC,IAAAV,EAAa,YAAb,gBAAAU,EAAsB,KAAKD;AAAA,KAEvBE,IAAQ,MAAM;;AAClB,IAAAP,EAAkB,UAAU,KAC5BM,IAAAV,EAAa,YAAb,QAAAU,EAAsB;AAAA,EACxB,GAEME,IAAOC,EAAS,MAAM;AAC1B,IAAAb,EAAa,UAAU,IAAI;AAAA,MACzB,OAAOF,KAAQ,aAAaA,EAAA,IAAQA;AAAA,MACpCC,KAAA,gBAAAA,EAAS;AAAA,IACX,GACAO,EAAU,YAAY;AAEtB,UAAMQ,IAAYd,EAAa;AAC/B,IAAKc,MAELA,EAAU,SAAS,MAAM;;AACvB,MAAAR,EAAU,WAAW,IACrBI,IAAAX,KAAA,gBAAAA,EAAS,gBAAT,QAAAW,EAAA,KAAAX,GAAuBe;AAAA,IACzB,GAEUA,EAAA,UAAU,CAACC,MAAU;;AAC7B,MAAAT,EAAU,QAAQ,IACTI,IAAAX,KAAA,gBAAAA,EAAA,YAAA,QAAAW,EAAA,KAAAX,GAAUgB,GAAOD;AAAA,IAC5B,GAEAA,EAAU,YAAY,CAACC,MAAA;;AAAU,cAAAL,IAAAX,KAAA,gBAAAA,EAAS,cAAT,gBAAAW,EAAA,KAAAX,GAAqBgB,GAAOD;AAAA,OAEnDA,EAAA,UAAU,CAACC,MAAU;;AAG7B,UAFAT,EAAU,cAAc,IACfI,IAAAX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