@oneplatformdev/hooks 0.0.1-beta.7 → 0.1.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.
- package/README.md +2 -2
- package/package.json +29 -30
- package/index.d.ts +0 -35
- package/index.mjs +0 -72
- package/useBoolean/index.d.ts +0 -1
- package/useBoolean/index.mjs +0 -4
- package/useBoolean/package.json +0 -7
- package/useBoolean/useBoolean.d.ts +0 -29
- package/useBoolean/useBoolean.mjs +0 -16
- package/useClickAnyWhere/index.d.ts +0 -1
- package/useClickAnyWhere/index.mjs +0 -4
- package/useClickAnyWhere/package.json +0 -7
- package/useClickAnyWhere/useClickAnyWhere.d.ts +0 -16
- package/useClickAnyWhere/useClickAnyWhere.mjs +0 -9
- package/useCopyToClipboard/index.d.ts +0 -1
- package/useCopyToClipboard/index.mjs +0 -4
- package/useCopyToClipboard/package.json +0 -7
- package/useCopyToClipboard/useCopyToClipboard.d.ts +0 -33
- package/useCopyToClipboard/useCopyToClipboard.mjs +0 -16
- package/useCountdown/index.d.ts +0 -1
- package/useCountdown/index.mjs +0 -4
- package/useCountdown/package.json +0 -7
- package/useCountdown/useCountdown.d.ts +0 -46
- package/useCountdown/useCountdown.mjs +0 -33
- package/useCounter/index.d.ts +0 -1
- package/useCounter/index.mjs +0 -4
- package/useCounter/package.json +0 -7
- package/useCounter/useCounter.d.ts +0 -28
- package/useCounter/useCounter.mjs +0 -20
- package/useDarkMode/index.d.ts +0 -1
- package/useDarkMode/index.mjs +0 -4
- package/useDarkMode/package.json +0 -7
- package/useDarkMode/useDarkMode.d.ts +0 -45
- package/useDarkMode/useDarkMode.mjs +0 -38
- package/useDebounceCallback/index.d.ts +0 -2
- package/useDebounceCallback/index.mjs +0 -5
- package/useDebounceCallback/package.json +0 -7
- package/useDebounceCallback/useDebounceCallback.d.ts +0 -61
- package/useDebounceCallback/useDebounceCallback.mjs +0 -101
- package/useDebounceValue/index.d.ts +0 -1
- package/useDebounceValue/index.mjs +0 -4
- package/useDebounceValue/package.json +0 -7
- package/useDebounceValue/useDebounceValue.d.ts +0 -40
- package/useDebounceValue/useDebounceValue.mjs +0 -13
- package/useDocumentTitle/index.d.ts +0 -1
- package/useDocumentTitle/index.mjs +0 -4
- package/useDocumentTitle/package.json +0 -7
- package/useDocumentTitle/useDocumentTitle.d.ts +0 -18
- package/useDocumentTitle/useDocumentTitle.mjs +0 -16
- package/useEventCallback/index.d.ts +0 -1
- package/useEventCallback/index.mjs +0 -4
- package/useEventCallback/package.json +0 -7
- package/useEventCallback/useEventCallback.d.ts +0 -17
- package/useEventCallback/useEventCallback.mjs +0 -16
- package/useEventListener/index.d.ts +0 -1
- package/useEventListener/index.mjs +0 -4
- package/useEventListener/package.json +0 -7
- package/useEventListener/useEventListener.d.ts +0 -7
- package/useEventListener/useEventListener.mjs +0 -20
- package/useHover/index.d.ts +0 -1
- package/useHover/index.mjs +0 -4
- package/useHover/package.json +0 -7
- package/useHover/useHover.d.ts +0 -17
- package/useHover/useHover.mjs +0 -13
- package/useIntersectionObserver/index.d.ts +0 -1
- package/useIntersectionObserver/index.mjs +0 -4
- package/useIntersectionObserver/package.json +0 -7
- package/useIntersectionObserver/useIntersectionObserver.d.ts +0 -71
- package/useIntersectionObserver/useIntersectionObserver.mjs +0 -55
- package/useInterval/index.d.ts +0 -1
- package/useInterval/index.mjs +0 -4
- package/useInterval/package.json +0 -7
- package/useInterval/useInterval.d.ts +0 -15
- package/useInterval/useInterval.mjs +0 -20
- package/useIsClient/index.d.ts +0 -1
- package/useIsClient/index.mjs +0 -4
- package/useIsClient/package.json +0 -7
- package/useIsClient/useIsClient.d.ts +0 -12
- package/useIsClient/useIsClient.mjs +0 -10
- package/useIsMobile/index.d.ts +0 -2
- package/useIsMobile/index.mjs +0 -4
- package/useIsMobile/package.json +0 -7
- package/useIsMobile/types.d.ts +0 -3
- package/useIsMobile/types.mjs +0 -1
- package/useIsMobile/useIsMobile.d.ts +0 -3
- package/useIsMobile/useIsMobile.mjs +0 -16
- package/useIsMounted/index.d.ts +0 -1
- package/useIsMounted/index.mjs +0 -4
- package/useIsMounted/package.json +0 -7
- package/useIsMounted/useIsMounted.d.ts +0 -1
- package/useIsMounted/useIsMounted.mjs +0 -10
- package/useIsomorphicLayoutEffect/index.d.ts +0 -1
- package/useIsomorphicLayoutEffect/index.mjs +0 -4
- package/useIsomorphicLayoutEffect/package.json +0 -7
- package/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.d.ts +0 -16
- package/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.mjs +0 -5
- package/useLocalStorage/index.d.ts +0 -1
- package/useLocalStorage/index.mjs +0 -4
- package/useLocalStorage/package.json +0 -7
- package/useLocalStorage/useLocalStorage.d.ts +0 -39
- package/useLocalStorage/useLocalStorage.mjs +0 -65
- package/useLockBody/index.d.ts +0 -1
- package/useLockBody/index.mjs +0 -4
- package/useLockBody/package.json +0 -7
- package/useLockBody/useLockBody.d.ts +0 -1
- package/useLockBody/useLockBody.mjs +0 -12
- package/useMap/index.d.ts +0 -1
- package/useMap/index.mjs +0 -4
- package/useMap/package.json +0 -7
- package/useMap/useMap.d.ts +0 -47
- package/useMap/useMap.mjs +0 -27
- package/useMediaQuery/index.d.ts +0 -1
- package/useMediaQuery/index.mjs +0 -4
- package/useMediaQuery/package.json +0 -7
- package/useMediaQuery/useMediaQuery.d.ts +0 -28
- package/useMediaQuery/useMediaQuery.mjs +0 -21
- package/useOnClickOutside/index.d.ts +0 -1
- package/useOnClickOutside/index.mjs +0 -4
- package/useOnClickOutside/package.json +0 -7
- package/useOnClickOutside/useOnClickOutside.d.ts +0 -24
- package/useOnClickOutside/useOnClickOutside.mjs +0 -17
- package/useReadLocalStorage/index.d.ts +0 -1
- package/useReadLocalStorage/index.mjs +0 -4
- package/useReadLocalStorage/package.json +0 -7
- package/useReadLocalStorage/useReadLocalStorage.d.ts +0 -13
- package/useReadLocalStorage/useReadLocalStorage.mjs +0 -48
- package/useResizeObserver/index.d.ts +0 -1
- package/useResizeObserver/index.mjs +0 -4
- package/useResizeObserver/package.json +0 -7
- package/useResizeObserver/useResizeObserver.d.ts +0 -44
- package/useResizeObserver/useResizeObserver.mjs +0 -31
- package/useScreen/index.d.ts +0 -1
- package/useScreen/index.mjs +0 -4
- package/useScreen/package.json +0 -7
- package/useScreen/useScreen.d.ts +0 -19
- package/useScreen/useScreen.mjs +0 -48
- package/useScript/index.d.ts +0 -1
- package/useScript/index.mjs +0 -4
- package/useScript/package.json +0 -7
- package/useScript/useScript.d.ts +0 -23
- package/useScript/useScript.mjs +0 -45
- package/useScrollLock/index.d.ts +0 -1
- package/useScrollLock/index.mjs +0 -4
- package/useScrollLock/package.json +0 -7
- package/useScrollLock/useScrollLock.d.ts +0 -53
- package/useScrollLock/useScrollLock.mjs +0 -26
- package/useSessionStorage/index.d.ts +0 -1
- package/useSessionStorage/index.mjs +0 -4
- package/useSessionStorage/package.json +0 -7
- package/useSessionStorage/useSessionStorage.d.ts +0 -39
- package/useSessionStorage/useSessionStorage.mjs +0 -65
- package/useStep/index.d.ts +0 -1
- package/useStep/index.mjs +0 -4
- package/useStep/package.json +0 -7
- package/useStep/useStep.d.ts +0 -31
- package/useStep/useStep.mjs +0 -34
- package/useTernaryDarkMode/index.d.ts +0 -1
- package/useTernaryDarkMode/index.mjs +0 -4
- package/useTernaryDarkMode/package.json +0 -7
- package/useTernaryDarkMode/useTernaryDarkMode.d.ts +0 -46
- package/useTernaryDarkMode/useTernaryDarkMode.mjs +0 -27
- package/useTimeout/index.d.ts +0 -1
- package/useTimeout/index.mjs +0 -4
- package/useTimeout/package.json +0 -7
- package/useTimeout/useTimeout.d.ts +0 -16
- package/useTimeout/useTimeout.mjs +0 -20
- package/useToggle/index.d.ts +0 -1
- package/useToggle/index.mjs +0 -4
- package/useToggle/package.json +0 -7
- package/useToggle/useToggle.d.ts +0 -18
- package/useToggle/useToggle.mjs +0 -10
- package/useUnmount/index.d.ts +0 -1
- package/useUnmount/index.mjs +0 -4
- package/useUnmount/package.json +0 -7
- package/useUnmount/useUnmount.d.ts +0 -13
- package/useUnmount/useUnmount.mjs +0 -13
- package/useWindowSize/index.d.ts +0 -1
- package/useWindowSize/index.mjs +0 -4
- package/useWindowSize/package.json +0 -7
- package/useWindowSize/useWindowSize.d.ts +0 -29
- package/useWindowSize/useWindowSize.mjs +0 -31
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/** Configuration options for controlling the behavior of the debounced function. */
|
|
2
|
-
type DebounceOptions = {
|
|
3
|
-
/**
|
|
4
|
-
* Determines whether the function should be invoked on the leading edge of the timeout.
|
|
5
|
-
* @default false
|
|
6
|
-
*/
|
|
7
|
-
leading?: boolean;
|
|
8
|
-
/**
|
|
9
|
-
* Determines whether the function should be invoked on the trailing edge of the timeout.
|
|
10
|
-
* @default false
|
|
11
|
-
*/
|
|
12
|
-
trailing?: boolean;
|
|
13
|
-
/**
|
|
14
|
-
* The maximum time the specified function is allowed to be delayed before it is invoked.
|
|
15
|
-
*/
|
|
16
|
-
maxWait?: number;
|
|
17
|
-
};
|
|
18
|
-
/** Functions to manage a debounced callback. */
|
|
19
|
-
type ControlFunctions = {
|
|
20
|
-
/** Cancels pending function invocations. */
|
|
21
|
-
cancel: () => void;
|
|
22
|
-
/** Immediately invokes pending function invocations. */
|
|
23
|
-
flush: () => void;
|
|
24
|
-
/**
|
|
25
|
-
* Checks if there are any pending function invocations.
|
|
26
|
-
* @returns `true` if there are pending invocations, otherwise `false`.
|
|
27
|
-
*/
|
|
28
|
-
isPending: () => boolean;
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
* Represents the state and control functions of a debounced callback.
|
|
32
|
-
* Subsequent calls to the debounced function return the result of the last invocation.
|
|
33
|
-
* Note: If there are no previous invocations, the result will be undefined.
|
|
34
|
-
* Ensure proper handling in your code.
|
|
35
|
-
*/
|
|
36
|
-
export type DebouncedState<T extends (...args: any) => ReturnType<T>> = ((...args: Parameters<T>) => ReturnType<T> | undefined) & ControlFunctions;
|
|
37
|
-
/**
|
|
38
|
-
* Custom hook that creates a debounced version of a callback function.
|
|
39
|
-
* @template T - Type of the original callback function.
|
|
40
|
-
* @param {T} func - The callback function to be debounced.
|
|
41
|
-
* @param {number} delay - The delay in milliseconds before the callback is invoked (default is `500` milliseconds).
|
|
42
|
-
* @param {DebounceOptions} [options] - Options to control the behavior of the debounced function.
|
|
43
|
-
* @returns {DebouncedState<T>} A debounced version of the original callback along with control functions.
|
|
44
|
-
* @public
|
|
45
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-debounce-callback)
|
|
46
|
-
* @example
|
|
47
|
-
* ```tsx
|
|
48
|
-
* const debouncedCallback = useDebounceCallback(
|
|
49
|
-
* (searchTerm) => {
|
|
50
|
-
* // Perform search after user stops typing for 500 milliseconds
|
|
51
|
-
* searchApi(searchTerm);
|
|
52
|
-
* },
|
|
53
|
-
* 500
|
|
54
|
-
* );
|
|
55
|
-
*
|
|
56
|
-
* // Later in the component
|
|
57
|
-
* debouncedCallback('react hooks'); // Will invoke the callback after 500 milliseconds of inactivity.
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
export declare function useDebounceCallback<T extends (...args: any) => ReturnType<T>>(func: T, delay?: number, options?: DebounceOptions): DebouncedState<T>;
|
|
61
|
-
export {};
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { useRef as _, useMemo as $, useEffect as N } from "react";
|
|
2
|
-
import { useUnmount as P } from "../useUnmount/useUnmount.mjs";
|
|
3
|
-
var g = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
|
|
4
|
-
function R(e) {
|
|
5
|
-
return e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
|
|
6
|
-
}
|
|
7
|
-
var W = "Expected a function", E = NaN, w = "[object Symbol]", A = /^\s+|\s+$/g, B = /^[-+]0x[0-9a-f]+$/i, D = /^0b[01]+$/i, G = /^0o[0-7]+$/i, U = parseInt, H = typeof g == "object" && g && g.Object === Object && g, X = typeof self == "object" && self && self.Object === Object && self, q = H || X || Function("return this")(), z = Object.prototype, J = z.toString, K = Math.max, Q = Math.min, T = function() {
|
|
8
|
-
return q.Date.now();
|
|
9
|
-
};
|
|
10
|
-
function V(e, n, r) {
|
|
11
|
-
var o, a, u, f, i, s, d = 0, v = !1, l = !1, p = !0;
|
|
12
|
-
if (typeof e != "function")
|
|
13
|
-
throw new TypeError(W);
|
|
14
|
-
n = S(n) || 0, h(r) && (v = !!r.leading, l = "maxWait" in r, u = l ? K(S(r.maxWait) || 0, n) : u, p = "trailing" in r ? !!r.trailing : p);
|
|
15
|
-
function y(t) {
|
|
16
|
-
var c = o, b = a;
|
|
17
|
-
return o = a = void 0, d = t, f = e.apply(b, c), f;
|
|
18
|
-
}
|
|
19
|
-
function F(t) {
|
|
20
|
-
return d = t, i = setTimeout(m, n), v ? y(t) : f;
|
|
21
|
-
}
|
|
22
|
-
function C(t) {
|
|
23
|
-
var c = t - s, b = t - d, x = n - c;
|
|
24
|
-
return l ? Q(x, u - b) : x;
|
|
25
|
-
}
|
|
26
|
-
function O(t) {
|
|
27
|
-
var c = t - s, b = t - d;
|
|
28
|
-
return s === void 0 || c >= n || c < 0 || l && b >= u;
|
|
29
|
-
}
|
|
30
|
-
function m() {
|
|
31
|
-
var t = T();
|
|
32
|
-
if (O(t))
|
|
33
|
-
return I(t);
|
|
34
|
-
i = setTimeout(m, C(t));
|
|
35
|
-
}
|
|
36
|
-
function I(t) {
|
|
37
|
-
return i = void 0, p && o ? y(t) : (o = a = void 0, f);
|
|
38
|
-
}
|
|
39
|
-
function M() {
|
|
40
|
-
i !== void 0 && clearTimeout(i), d = 0, o = s = a = i = void 0;
|
|
41
|
-
}
|
|
42
|
-
function L() {
|
|
43
|
-
return i === void 0 ? f : I(T());
|
|
44
|
-
}
|
|
45
|
-
function j() {
|
|
46
|
-
var t = T(), c = O(t);
|
|
47
|
-
if (o = arguments, a = this, s = t, c) {
|
|
48
|
-
if (i === void 0)
|
|
49
|
-
return F(s);
|
|
50
|
-
if (l)
|
|
51
|
-
return i = setTimeout(m, n), y(s);
|
|
52
|
-
}
|
|
53
|
-
return i === void 0 && (i = setTimeout(m, n)), f;
|
|
54
|
-
}
|
|
55
|
-
return j.cancel = M, j.flush = L, j;
|
|
56
|
-
}
|
|
57
|
-
function h(e) {
|
|
58
|
-
var n = typeof e;
|
|
59
|
-
return !!e && (n == "object" || n == "function");
|
|
60
|
-
}
|
|
61
|
-
function Y(e) {
|
|
62
|
-
return !!e && typeof e == "object";
|
|
63
|
-
}
|
|
64
|
-
function Z(e) {
|
|
65
|
-
return typeof e == "symbol" || Y(e) && J.call(e) == w;
|
|
66
|
-
}
|
|
67
|
-
function S(e) {
|
|
68
|
-
if (typeof e == "number")
|
|
69
|
-
return e;
|
|
70
|
-
if (Z(e))
|
|
71
|
-
return E;
|
|
72
|
-
if (h(e)) {
|
|
73
|
-
var n = typeof e.valueOf == "function" ? e.valueOf() : e;
|
|
74
|
-
e = h(n) ? n + "" : n;
|
|
75
|
-
}
|
|
76
|
-
if (typeof e != "string")
|
|
77
|
-
return e === 0 ? e : +e;
|
|
78
|
-
e = e.replace(A, "");
|
|
79
|
-
var r = D.test(e);
|
|
80
|
-
return r || G.test(e) ? U(e.slice(2), r ? 2 : 8) : B.test(e) ? E : +e;
|
|
81
|
-
}
|
|
82
|
-
var ee = V;
|
|
83
|
-
const k = /* @__PURE__ */ R(ee);
|
|
84
|
-
function re(e, n = 500, r) {
|
|
85
|
-
const o = _(null);
|
|
86
|
-
P(() => {
|
|
87
|
-
o.current && o.current.cancel();
|
|
88
|
-
});
|
|
89
|
-
const a = $(() => {
|
|
90
|
-
const u = k(e, n, r), f = (...i) => u(...i);
|
|
91
|
-
return f.cancel = () => {
|
|
92
|
-
u.cancel();
|
|
93
|
-
}, f.isPending = () => !!o.current, f.flush = () => u.flush(), f;
|
|
94
|
-
}, [e, n, r]);
|
|
95
|
-
return N(() => {
|
|
96
|
-
o.current = k(e, n, r);
|
|
97
|
-
}, [e, n, r]), a;
|
|
98
|
-
}
|
|
99
|
-
export {
|
|
100
|
-
re as useDebounceCallback
|
|
101
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useDebounceValue';
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { DebouncedState } from '../useDebounceCallback';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Hook options.
|
|
5
|
-
* @template T - The type of the value.
|
|
6
|
-
*/
|
|
7
|
-
type UseDebounceValueOptions<T> = {
|
|
8
|
-
/**
|
|
9
|
-
* Determines whether the function should be invoked on the leading edge of the timeout.
|
|
10
|
-
* @default false
|
|
11
|
-
*/
|
|
12
|
-
leading?: boolean;
|
|
13
|
-
/**
|
|
14
|
-
* Determines whether the function should be invoked on the trailing edge of the timeout.
|
|
15
|
-
* @default false
|
|
16
|
-
*/
|
|
17
|
-
trailing?: boolean;
|
|
18
|
-
/**
|
|
19
|
-
* The maximum time the specified function is allowed to be delayed before it is invoked.
|
|
20
|
-
*/
|
|
21
|
-
maxWait?: number;
|
|
22
|
-
/** A function to determine if the value has changed. Defaults to a function that checks if the value is strictly equal to the previous value. */
|
|
23
|
-
equalityFn?: (left: T, right: T) => boolean;
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* Custom hook that returns a debounced version of the provided value, along with a function to update it.
|
|
27
|
-
* @template T - The type of the value.
|
|
28
|
-
* @param {T | (() => T)} initialValue - The value to be debounced.
|
|
29
|
-
* @param {number} delay - The delay in milliseconds before the value is updated (default is 500ms).
|
|
30
|
-
* @param {object} [options] - Optional configurations for the debouncing behavior.
|
|
31
|
-
* @returns {[T, DebouncedState<(value: T) => void>]} An array containing the debounced value and the function to update it.
|
|
32
|
-
* @public
|
|
33
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-debounce-value)
|
|
34
|
-
* @example
|
|
35
|
-
* ```tsx
|
|
36
|
-
* const [debouncedValue, updateDebouncedValue] = useDebounceValue(inputValue, 500, { leading: true });
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
export declare function useDebounceValue<T>(initialValue: T | (() => T), delay: number, options?: UseDebounceValueOptions<T>): [T, DebouncedState<(value: T) => void>];
|
|
40
|
-
export {};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { useState as d, useRef as l } from "react";
|
|
2
|
-
import { useDebounceCallback as m } from "../useDebounceCallback/useDebounceCallback.mjs";
|
|
3
|
-
function p(c, t, u) {
|
|
4
|
-
const a = (u == null ? void 0 : u.equalityFn) ?? ((s, b) => s === b), e = c instanceof Function ? c() : c, [o, f] = d(e), n = l(e), r = m(
|
|
5
|
-
f,
|
|
6
|
-
t,
|
|
7
|
-
u
|
|
8
|
-
);
|
|
9
|
-
return a(n.current, e) || (r(e), n.current = e), [o, r];
|
|
10
|
-
}
|
|
11
|
-
export {
|
|
12
|
-
p as useDebounceValue
|
|
13
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useDocumentTitle';
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/** Hook options. */
|
|
2
|
-
type UseDocumentTitleOptions = {
|
|
3
|
-
/** Whether to keep the title after unmounting the component (default is `true`). */
|
|
4
|
-
preserveTitleOnUnmount?: boolean;
|
|
5
|
-
};
|
|
6
|
-
/**
|
|
7
|
-
* Custom hook that sets the document title.
|
|
8
|
-
* @param {string} title - The title to set.
|
|
9
|
-
* @param {?UseDocumentTitleOptions} [options] - The options.
|
|
10
|
-
* @public
|
|
11
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-document-title)
|
|
12
|
-
* @example
|
|
13
|
-
* ```tsx
|
|
14
|
-
* useDocumentTitle('My new title');
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
export declare function useDocumentTitle(title: string, options?: UseDocumentTitleOptions): void;
|
|
18
|
-
export {};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { useRef as r } from "react";
|
|
2
|
-
import { useIsomorphicLayoutEffect as o } from "../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.mjs";
|
|
3
|
-
import { useUnmount as i } from "../useUnmount/useUnmount.mjs";
|
|
4
|
-
function l(e, n = {}) {
|
|
5
|
-
const { preserveTitleOnUnmount: u = !0 } = n, t = r(null);
|
|
6
|
-
o(() => {
|
|
7
|
-
t.current = window.document.title;
|
|
8
|
-
}, []), o(() => {
|
|
9
|
-
window.document.title = e;
|
|
10
|
-
}, [e]), i(() => {
|
|
11
|
-
!u && t.current && (window.document.title = t.current);
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
export {
|
|
15
|
-
l as useDocumentTitle
|
|
16
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useEventCallback';
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Custom hook that creates a memoized event callback.
|
|
3
|
-
* @template Args - An array of argument types for the event callback.
|
|
4
|
-
* @template R - The return type of the event callback.
|
|
5
|
-
* @param {(...args: Args) => R} fn - The callback function.
|
|
6
|
-
* @returns {(...args: Args) => R} A memoized event callback function.
|
|
7
|
-
* @public
|
|
8
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-event-callback)
|
|
9
|
-
* @example
|
|
10
|
-
* ```tsx
|
|
11
|
-
* const handleClick = useEventCallback((event) => {
|
|
12
|
-
* // Handle the event here
|
|
13
|
-
* });
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
export declare function useEventCallback<Args extends unknown[], R>(fn: (...args: Args) => R): (...args: Args) => R;
|
|
17
|
-
export declare function useEventCallback<Args extends unknown[], R>(fn: ((...args: Args) => R) | undefined): ((...args: Args) => R) | undefined;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { useRef as o, useCallback as a } from "react";
|
|
2
|
-
import { useIsomorphicLayoutEffect as c } from "../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.mjs";
|
|
3
|
-
function i(e) {
|
|
4
|
-
const r = o(() => {
|
|
5
|
-
throw new Error("Cannot call an event handler while rendering.");
|
|
6
|
-
});
|
|
7
|
-
return c(() => {
|
|
8
|
-
r.current = e;
|
|
9
|
-
}, [e]), a((...t) => {
|
|
10
|
-
var n;
|
|
11
|
-
return (n = r.current) == null ? void 0 : n.call(r, ...t);
|
|
12
|
-
}, [r]);
|
|
13
|
-
}
|
|
14
|
-
export {
|
|
15
|
-
i as useEventCallback
|
|
16
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useEventListener';
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { RefObject } from 'react';
|
|
2
|
-
|
|
3
|
-
declare function useEventListener<K extends keyof MediaQueryListEventMap>(eventName: K, handler: (event: MediaQueryListEventMap[K]) => void, element: RefObject<MediaQueryList>, options?: boolean | AddEventListenerOptions): void;
|
|
4
|
-
declare function useEventListener<K extends keyof WindowEventMap>(eventName: K, handler: (event: WindowEventMap[K]) => void, element?: undefined, options?: boolean | AddEventListenerOptions): void;
|
|
5
|
-
declare function useEventListener<K extends keyof HTMLElementEventMap & keyof SVGElementEventMap, T extends Element = K extends keyof HTMLElementEventMap ? HTMLDivElement : SVGElement>(eventName: K, handler: ((event: HTMLElementEventMap[K]) => void) | ((event: SVGElementEventMap[K]) => void), element: RefObject<T>, options?: boolean | AddEventListenerOptions): void;
|
|
6
|
-
declare function useEventListener<K extends keyof DocumentEventMap>(eventName: K, handler: (event: DocumentEventMap[K]) => void, element: RefObject<Document>, options?: boolean | AddEventListenerOptions): void;
|
|
7
|
-
export { useEventListener };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { useRef as f, useEffect as i } from "react";
|
|
2
|
-
import { useIsomorphicLayoutEffect as E } from "../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.mjs";
|
|
3
|
-
function v(s, e, r, n) {
|
|
4
|
-
const u = f(e);
|
|
5
|
-
E(() => {
|
|
6
|
-
u.current = e;
|
|
7
|
-
}, [e]), i(() => {
|
|
8
|
-
const t = (r == null ? void 0 : r.current) ?? window;
|
|
9
|
-
if (!(t && t.addEventListener)) return;
|
|
10
|
-
const c = (o) => {
|
|
11
|
-
u.current(o);
|
|
12
|
-
};
|
|
13
|
-
return t.addEventListener(s, c, n), () => {
|
|
14
|
-
t.removeEventListener(s, c, n);
|
|
15
|
-
};
|
|
16
|
-
}, [s, r, n]);
|
|
17
|
-
}
|
|
18
|
-
export {
|
|
19
|
-
v as useEventListener
|
|
20
|
-
};
|
package/useHover/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useHover';
|
package/useHover/index.mjs
DELETED
package/useHover/package.json
DELETED
package/useHover/useHover.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { RefObject } from 'react';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Custom hook that tracks whether a DOM element is being hovered over.
|
|
5
|
-
* @template T - The type of the DOM element. Defaults to `HTMLElement`.
|
|
6
|
-
* @param {RefObject<T>} elementRef - The ref object for the DOM element to track.
|
|
7
|
-
* @returns {boolean} A boolean value indicating whether the element is being hovered over.
|
|
8
|
-
* @public
|
|
9
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-hover)
|
|
10
|
-
* @example
|
|
11
|
-
* ```tsx
|
|
12
|
-
* const buttonRef = useRef<HTMLButtonElement>(null);
|
|
13
|
-
* const isHovered = useHover(buttonRef);
|
|
14
|
-
* // Access the isHovered variable to determine if the button is being hovered over.
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
export declare function useHover<T extends HTMLElement = HTMLElement>(elementRef: RefObject<T>): boolean;
|
package/useHover/useHover.mjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { useState as n } from "react";
|
|
2
|
-
import { useEventListener as o } from "../useEventListener/useEventListener.mjs";
|
|
3
|
-
function m(e) {
|
|
4
|
-
const [s, t] = n(!1), r = () => {
|
|
5
|
-
t(!0);
|
|
6
|
-
}, u = () => {
|
|
7
|
-
t(!1);
|
|
8
|
-
};
|
|
9
|
-
return o("mouseenter", r, e), o("mouseleave", u, e), s;
|
|
10
|
-
}
|
|
11
|
-
export {
|
|
12
|
-
m as useHover
|
|
13
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useIntersectionObserver';
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/** Represents the options for configuring the Intersection Observer. */
|
|
2
|
-
type UseIntersectionObserverOptions = {
|
|
3
|
-
/**
|
|
4
|
-
* The element that is used as the viewport for checking visibility of the target.
|
|
5
|
-
* @default null
|
|
6
|
-
*/
|
|
7
|
-
root?: Element | Document | null;
|
|
8
|
-
/**
|
|
9
|
-
* A margin around the root.
|
|
10
|
-
* @default '0%'
|
|
11
|
-
*/
|
|
12
|
-
rootMargin?: string;
|
|
13
|
-
/**
|
|
14
|
-
* A threshold indicating the percentage of the target's visibility needed to trigger the callback.
|
|
15
|
-
* @default 0
|
|
16
|
-
*/
|
|
17
|
-
threshold?: number | number[];
|
|
18
|
-
/**
|
|
19
|
-
* If true, freezes the intersection state once the element becomes visible.
|
|
20
|
-
* @default false
|
|
21
|
-
*/
|
|
22
|
-
freezeOnceVisible?: boolean;
|
|
23
|
-
/**
|
|
24
|
-
* A callback function to be invoked when the intersection state changes.
|
|
25
|
-
* @param {boolean} isIntersecting - A boolean indicating if the element is intersecting.
|
|
26
|
-
* @param {IntersectionObserverEntry} entry - The intersection observer Entry.
|
|
27
|
-
* @default undefined
|
|
28
|
-
*/
|
|
29
|
-
onChange?: (isIntersecting: boolean, entry: IntersectionObserverEntry) => void;
|
|
30
|
-
/**
|
|
31
|
-
* The initial state of the intersection.
|
|
32
|
-
* @default false
|
|
33
|
-
*/
|
|
34
|
-
initialIsIntersecting?: boolean;
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* The return type of the useIntersectionObserver hook.
|
|
38
|
-
*
|
|
39
|
-
* Supports both tuple and object destructing.
|
|
40
|
-
* @param {(node: Element | null) => void} ref - The ref callback function.
|
|
41
|
-
* @param {boolean} isIntersecting - A boolean indicating if the element is intersecting.
|
|
42
|
-
* @param {IntersectionObserverEntry | undefined} entry - The intersection observer Entry.
|
|
43
|
-
*/
|
|
44
|
-
type IntersectionReturn = [
|
|
45
|
-
(node?: Element | null) => void,
|
|
46
|
-
boolean,
|
|
47
|
-
IntersectionObserverEntry | undefined
|
|
48
|
-
] & {
|
|
49
|
-
ref: (node?: Element | null) => void;
|
|
50
|
-
isIntersecting: boolean;
|
|
51
|
-
entry?: IntersectionObserverEntry;
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* Custom hook that tracks the intersection of a DOM element with its containing element or the viewport using the [`Intersection Observer API`](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API).
|
|
55
|
-
* @param {UseIntersectionObserverOptions} options - The options for the Intersection Observer.
|
|
56
|
-
* @returns {IntersectionReturn} The ref callback, a boolean indicating if the element is intersecting, and the intersection observer entry.
|
|
57
|
-
* @public
|
|
58
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-intersection-observer)
|
|
59
|
-
* @example
|
|
60
|
-
* ```tsx
|
|
61
|
-
* // Example 1
|
|
62
|
-
* const [ref, isIntersecting, entry] = useIntersectionObserver({ threshold: 0.5 });
|
|
63
|
-
* ```
|
|
64
|
-
*
|
|
65
|
-
* ```tsx
|
|
66
|
-
* // Example 2
|
|
67
|
-
* const { ref, isIntersecting, entry } = useIntersectionObserver({ threshold: 0.5 });
|
|
68
|
-
* ```
|
|
69
|
-
*/
|
|
70
|
-
export declare function useIntersectionObserver({ threshold, root, rootMargin, freezeOnceVisible, initialIsIntersecting, onChange, }?: UseIntersectionObserverOptions): IntersectionReturn;
|
|
71
|
-
export {};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { useState as v, useRef as I, useEffect as R } from "react";
|
|
2
|
-
function E({
|
|
3
|
-
threshold: f = 0,
|
|
4
|
-
root: a = null,
|
|
5
|
-
rootMargin: l = "0%",
|
|
6
|
-
freezeOnceVisible: s = !1,
|
|
7
|
-
initialIsIntersecting: u = !1,
|
|
8
|
-
onChange: b
|
|
9
|
-
} = {}) {
|
|
10
|
-
var g;
|
|
11
|
-
const [n, m] = v(null), [t, d] = v(() => ({
|
|
12
|
-
isIntersecting: u,
|
|
13
|
-
entry: void 0
|
|
14
|
-
})), i = I(null);
|
|
15
|
-
i.current = b;
|
|
16
|
-
const c = ((g = t.entry) == null ? void 0 : g.isIntersecting) && s;
|
|
17
|
-
R(() => {
|
|
18
|
-
if (!n || !("IntersectionObserver" in window) || c) return;
|
|
19
|
-
const e = new IntersectionObserver(
|
|
20
|
-
(p) => {
|
|
21
|
-
const w = Array.isArray(e.thresholds) ? e.thresholds : [e.thresholds];
|
|
22
|
-
p.forEach((o) => {
|
|
23
|
-
const h = o.isIntersecting && w.some((S) => o.intersectionRatio >= S);
|
|
24
|
-
d({ isIntersecting: h, entry: o }), i.current && i.current(h, o);
|
|
25
|
-
});
|
|
26
|
-
},
|
|
27
|
-
{ threshold: f, root: a, rootMargin: l }
|
|
28
|
-
);
|
|
29
|
-
return e.observe(n), () => {
|
|
30
|
-
e.disconnect();
|
|
31
|
-
};
|
|
32
|
-
}, [
|
|
33
|
-
n,
|
|
34
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
35
|
-
JSON.stringify(f),
|
|
36
|
-
a,
|
|
37
|
-
l,
|
|
38
|
-
c,
|
|
39
|
-
s
|
|
40
|
-
]);
|
|
41
|
-
const y = I(null);
|
|
42
|
-
R(() => {
|
|
43
|
-
var e;
|
|
44
|
-
!n && ((e = t.entry) != null && e.target) && !s && !c && y.current !== t.entry.target && (y.current = t.entry.target, d({ isIntersecting: u, entry: void 0 }));
|
|
45
|
-
}, [n, t.entry, s, c, u]);
|
|
46
|
-
const r = [
|
|
47
|
-
m,
|
|
48
|
-
!!t.isIntersecting,
|
|
49
|
-
t.entry
|
|
50
|
-
];
|
|
51
|
-
return r.ref = r[0], r.isIntersecting = r[1], r.entry = r[2], r;
|
|
52
|
-
}
|
|
53
|
-
export {
|
|
54
|
-
E as useIntersectionObserver
|
|
55
|
-
};
|
package/useInterval/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useInterval';
|
package/useInterval/index.mjs
DELETED
package/useInterval/package.json
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Custom hook that creates an interval that invokes a callback function at a specified delay using the [`setInterval API`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval).
|
|
3
|
-
* @param {() => void} callback - The function to be invoked at each interval.
|
|
4
|
-
* @param {number | null} delay - The time, in milliseconds, between each invocation of the callback. Use `null` to clear the interval.
|
|
5
|
-
* @public
|
|
6
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-interval)
|
|
7
|
-
* @example
|
|
8
|
-
* ```tsx
|
|
9
|
-
* const handleInterval = () => {
|
|
10
|
-
* // Code to be executed at each interval
|
|
11
|
-
* };
|
|
12
|
-
* useInterval(handleInterval, 1000);
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
export declare function useInterval(callback: () => void, delay: number | null): void;
|