@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,20 +0,0 @@
|
|
|
1
|
-
import { useRef as o, useEffect as u } from "react";
|
|
2
|
-
import { useIsomorphicLayoutEffect as f } from "../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.mjs";
|
|
3
|
-
function i(r, t) {
|
|
4
|
-
const e = o(r);
|
|
5
|
-
f(() => {
|
|
6
|
-
e.current = r;
|
|
7
|
-
}, [r]), u(() => {
|
|
8
|
-
if (t === null)
|
|
9
|
-
return;
|
|
10
|
-
const n = setInterval(() => {
|
|
11
|
-
e.current();
|
|
12
|
-
}, t);
|
|
13
|
-
return () => {
|
|
14
|
-
clearInterval(n);
|
|
15
|
-
};
|
|
16
|
-
}, [t]);
|
|
17
|
-
}
|
|
18
|
-
export {
|
|
19
|
-
i as useInterval
|
|
20
|
-
};
|
package/useIsClient/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useIsClient';
|
package/useIsClient/index.mjs
DELETED
package/useIsClient/package.json
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Custom hook that determines if the code is running on the client side (in the browser).
|
|
3
|
-
* @returns {boolean} A boolean value indicating whether the code is running on the client side.
|
|
4
|
-
* @public
|
|
5
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-is-client)
|
|
6
|
-
* @example
|
|
7
|
-
* ```tsx
|
|
8
|
-
* const isClient = useIsClient();
|
|
9
|
-
* // Use isClient to conditionally render or execute code specific to the client side.
|
|
10
|
-
* ```
|
|
11
|
-
*/
|
|
12
|
-
export declare function useIsClient(): boolean;
|
package/useIsMobile/index.d.ts
DELETED
package/useIsMobile/index.mjs
DELETED
package/useIsMobile/package.json
DELETED
package/useIsMobile/types.d.ts
DELETED
package/useIsMobile/types.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import * as o from "react";
|
|
2
|
-
const a = 768;
|
|
3
|
-
function c(s = {}) {
|
|
4
|
-
const {
|
|
5
|
-
mobileBreakpoint: e = a
|
|
6
|
-
} = s, [r, n] = o.useState(void 0);
|
|
7
|
-
return o.useEffect(() => {
|
|
8
|
-
const t = window.matchMedia(`(max-width: ${e - 1}px)`), i = () => {
|
|
9
|
-
n(window.innerWidth < e);
|
|
10
|
-
};
|
|
11
|
-
return t.addEventListener("change", i), n(window.innerWidth < e), () => t.removeEventListener("change", i);
|
|
12
|
-
}, [e]), !!r;
|
|
13
|
-
}
|
|
14
|
-
export {
|
|
15
|
-
c as useIsMobile
|
|
16
|
-
};
|
package/useIsMounted/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useIsMounted';
|
package/useIsMounted/index.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function useIsMounted(): () => boolean;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useIsomorphicLayoutEffect';
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { useLayoutEffect } from 'react';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Custom hook that uses either `useLayoutEffect` or `useEffect` based on the environment (client-side or server-side).
|
|
5
|
-
* @param {Function} effect - The effect function to be executed.
|
|
6
|
-
* @param {Array<any>} [dependencies] - An array of dependencies for the effect (optional).
|
|
7
|
-
* @public
|
|
8
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-isomorphic-layout-effect)
|
|
9
|
-
* @example
|
|
10
|
-
* ```tsx
|
|
11
|
-
* useIsomorphicLayoutEffect(() => {
|
|
12
|
-
* // Code to be executed during the layout phase on the client side
|
|
13
|
-
* }, [dependency1, dependency2]);
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
export declare const useIsomorphicLayoutEffect: typeof useLayoutEffect;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useLocalStorage';
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
-
|
|
3
|
-
declare global {
|
|
4
|
-
interface WindowEventMap {
|
|
5
|
-
'local-storage': CustomEvent;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Options for customizing the behavior of serialization and deserialization.
|
|
10
|
-
* @template T - The type of the state to be stored in local storage.
|
|
11
|
-
*/
|
|
12
|
-
type UseLocalStorageOptions<T> = {
|
|
13
|
-
/** A function to serialize the value before storing it. */
|
|
14
|
-
serializer?: (value: T) => string;
|
|
15
|
-
/** A function to deserialize the stored value. */
|
|
16
|
-
deserializer?: (value: string) => T;
|
|
17
|
-
/**
|
|
18
|
-
* If `true` (default), the hook will initialize reading the local storage. In SSR, you should set it to `false`, returning the initial value initially.
|
|
19
|
-
* @default true
|
|
20
|
-
*/
|
|
21
|
-
initializeWithValue?: boolean;
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Custom hook that uses the [`localStorage API`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) to persist state across page reloads.
|
|
25
|
-
* @template T - The type of the state to be stored in local storage.
|
|
26
|
-
* @param {string} key - The key under which the value will be stored in local storage.
|
|
27
|
-
* @param {T | (() => T)} initialValue - The initial value of the state or a function that returns the initial value.
|
|
28
|
-
* @param {UseLocalStorageOptions<T>} [options] - Options for customizing the behavior of serialization and deserialization (optional).
|
|
29
|
-
* @returns {[T, Dispatch<SetStateAction<T>>, () => void]} A tuple containing the stored value, a function to set the value and a function to remove the key from storage.
|
|
30
|
-
* @public
|
|
31
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-local-storage)
|
|
32
|
-
* @example
|
|
33
|
-
* ```tsx
|
|
34
|
-
* const [count, setCount, removeCount] = useLocalStorage('count', 0);
|
|
35
|
-
* // Access the `count` value, the `setCount` function to update it and `removeCount` function to remove the key from storage.
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
export declare function useLocalStorage<T>(key: string, initialValue: T | (() => T), options?: UseLocalStorageOptions<T>): [T, Dispatch<SetStateAction<T>>, () => void];
|
|
39
|
-
export {};
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { useCallback as a, useState as z, useEffect as F } from "react";
|
|
2
|
-
import { useEventCallback as i } from "../useEventCallback/useEventCallback.mjs";
|
|
3
|
-
import { useEventListener as l } from "../useEventListener/useEventListener.mjs";
|
|
4
|
-
const d = typeof window > "u";
|
|
5
|
-
function C(t, r, o = {}) {
|
|
6
|
-
const { initializeWithValue: w = !0 } = o, S = a(
|
|
7
|
-
(e) => o.serializer ? o.serializer(e) : JSON.stringify(e),
|
|
8
|
-
[o]
|
|
9
|
-
), f = a(
|
|
10
|
-
(e) => {
|
|
11
|
-
if (o.deserializer)
|
|
12
|
-
return o.deserializer(e);
|
|
13
|
-
if (e === "undefined")
|
|
14
|
-
return;
|
|
15
|
-
const n = r instanceof Function ? r() : r;
|
|
16
|
-
let u;
|
|
17
|
-
try {
|
|
18
|
-
u = JSON.parse(e);
|
|
19
|
-
} catch (v) {
|
|
20
|
-
return console.error("Error parsing JSON:", v), n;
|
|
21
|
-
}
|
|
22
|
-
return u;
|
|
23
|
-
},
|
|
24
|
-
[o, r]
|
|
25
|
-
), c = a(() => {
|
|
26
|
-
const e = r instanceof Function ? r() : r;
|
|
27
|
-
if (d)
|
|
28
|
-
return e;
|
|
29
|
-
try {
|
|
30
|
-
const n = window.localStorage.getItem(t);
|
|
31
|
-
return n ? f(n) : e;
|
|
32
|
-
} catch (n) {
|
|
33
|
-
return console.warn(`Error reading localStorage key “${t}”:`, n), e;
|
|
34
|
-
}
|
|
35
|
-
}, [r, t, f]), [m, s] = z(() => w ? c() : r instanceof Function ? r() : r), h = i((e) => {
|
|
36
|
-
d && console.warn(
|
|
37
|
-
`Tried setting localStorage key “${t}” even though environment is not a client`
|
|
38
|
-
);
|
|
39
|
-
try {
|
|
40
|
-
const n = e instanceof Function ? e(c()) : e;
|
|
41
|
-
window.localStorage.setItem(t, S(n)), s(n), window.dispatchEvent(new StorageEvent("local-storage", { key: t }));
|
|
42
|
-
} catch (n) {
|
|
43
|
-
console.warn(`Error setting localStorage key “${t}”:`, n);
|
|
44
|
-
}
|
|
45
|
-
}), E = i(() => {
|
|
46
|
-
d && console.warn(
|
|
47
|
-
`Tried removing localStorage key “${t}” even though environment is not a client`
|
|
48
|
-
);
|
|
49
|
-
const e = r instanceof Function ? r() : r;
|
|
50
|
-
window.localStorage.removeItem(t), s(e), window.dispatchEvent(new StorageEvent("local-storage", { key: t }));
|
|
51
|
-
});
|
|
52
|
-
F(() => {
|
|
53
|
-
s(c());
|
|
54
|
-
}, [t]);
|
|
55
|
-
const g = a(
|
|
56
|
-
(e) => {
|
|
57
|
-
e.key && e.key !== t || s(c());
|
|
58
|
-
},
|
|
59
|
-
[t, c]
|
|
60
|
-
);
|
|
61
|
-
return l("storage", g), l("local-storage", g), [m, h, E];
|
|
62
|
-
}
|
|
63
|
-
export {
|
|
64
|
-
C as useLocalStorage
|
|
65
|
-
};
|
package/useLockBody/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useLockBody';
|
package/useLockBody/index.mjs
DELETED
package/useLockBody/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function useLockBody(): void;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import * as e from "react";
|
|
2
|
-
function t() {
|
|
3
|
-
e.useLayoutEffect(() => {
|
|
4
|
-
const o = window.getComputedStyle(
|
|
5
|
-
document.body
|
|
6
|
-
).overflow;
|
|
7
|
-
return document.body.style.overflow = "hidden", () => document.body.style.overflow = o;
|
|
8
|
-
}, []);
|
|
9
|
-
}
|
|
10
|
-
export {
|
|
11
|
-
t as useLockBody
|
|
12
|
-
};
|
package/useMap/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useMap';
|
package/useMap/index.mjs
DELETED
package/useMap/package.json
DELETED
package/useMap/useMap.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Represents the type for either a Map or an array of key-value pairs.
|
|
3
|
-
* @template K - The type of keys in the map.
|
|
4
|
-
* @template V - The type of values in the map.
|
|
5
|
-
*/
|
|
6
|
-
type MapOrEntries<K, V> = Map<K, V> | [K, V][];
|
|
7
|
-
/**
|
|
8
|
-
* Represents the actions available to interact with the map state.
|
|
9
|
-
* @template K - The type of keys in the map.
|
|
10
|
-
* @template V - The type of values in the map.
|
|
11
|
-
*/
|
|
12
|
-
type UseMapActions<K, V> = {
|
|
13
|
-
/** Set a key-value pair in the map. */
|
|
14
|
-
set: (key: K, value: V) => void;
|
|
15
|
-
/** Set all key-value pairs in the map. */
|
|
16
|
-
setAll: (entries: MapOrEntries<K, V>) => void;
|
|
17
|
-
/** Remove a key-value pair from the map. */
|
|
18
|
-
remove: (key: K) => void;
|
|
19
|
-
/** Reset the map to an empty state. */
|
|
20
|
-
reset: Map<K, V>['clear'];
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* Represents the return type of the `useMap` hook.
|
|
24
|
-
* We hide some setters from the returned map to disable autocompletion.
|
|
25
|
-
* @template K - The type of keys in the map.
|
|
26
|
-
* @template V - The type of values in the map.
|
|
27
|
-
*/
|
|
28
|
-
type UseMapReturn<K, V> = [
|
|
29
|
-
Omit<Map<K, V>, 'set' | 'clear' | 'delete'>,
|
|
30
|
-
UseMapActions<K, V>
|
|
31
|
-
];
|
|
32
|
-
/**
|
|
33
|
-
* Custom hook that manages a key-value [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) state with setter actions.
|
|
34
|
-
* @template K - The type of keys in the map.
|
|
35
|
-
* @template V - The type of values in the map.
|
|
36
|
-
* @param {MapOrEntries<K, V>} [initialState] - The initial state of the map as a Map or an array of key-value pairs (optional).
|
|
37
|
-
* @returns {UseMapReturn<K, V>} A tuple containing the map state and actions to interact with the map.
|
|
38
|
-
* @public
|
|
39
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-map)
|
|
40
|
-
* @example
|
|
41
|
-
* ```tsx
|
|
42
|
-
* const [map, mapActions] = useMap();
|
|
43
|
-
* // Access the `map` state and use `mapActions` to set, remove, or reset entries.
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
export declare function useMap<K, V>(initialState?: MapOrEntries<K, V>): UseMapReturn<K, V>;
|
|
47
|
-
export {};
|
package/useMap/useMap.mjs
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { useState as M, useCallback as a } from "react";
|
|
2
|
-
function w(o = /* @__PURE__ */ new Map()) {
|
|
3
|
-
const [r, t] = M(new Map(o)), c = {
|
|
4
|
-
set: a((e, p) => {
|
|
5
|
-
t((n) => {
|
|
6
|
-
const s = new Map(n);
|
|
7
|
-
return s.set(e, p), s;
|
|
8
|
-
});
|
|
9
|
-
}, []),
|
|
10
|
-
setAll: a((e) => {
|
|
11
|
-
t(() => new Map(e));
|
|
12
|
-
}, []),
|
|
13
|
-
remove: a((e) => {
|
|
14
|
-
t((p) => {
|
|
15
|
-
const n = new Map(p);
|
|
16
|
-
return n.delete(e), n;
|
|
17
|
-
});
|
|
18
|
-
}, []),
|
|
19
|
-
reset: a(() => {
|
|
20
|
-
t(() => /* @__PURE__ */ new Map());
|
|
21
|
-
}, [])
|
|
22
|
-
};
|
|
23
|
-
return [r, c];
|
|
24
|
-
}
|
|
25
|
-
export {
|
|
26
|
-
w as useMap
|
|
27
|
-
};
|
package/useMediaQuery/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useMediaQuery';
|
package/useMediaQuery/index.mjs
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/** Hook options. */
|
|
2
|
-
type UseMediaQueryOptions = {
|
|
3
|
-
/**
|
|
4
|
-
* The default value to return if the hook is being run on the server.
|
|
5
|
-
* @default false
|
|
6
|
-
*/
|
|
7
|
-
defaultValue?: boolean;
|
|
8
|
-
/**
|
|
9
|
-
* If `true` (default), the hook will initialize reading the media query. In SSR, you should set it to `false`, returning `options.defaultValue` or `false` initially.
|
|
10
|
-
* @default true
|
|
11
|
-
*/
|
|
12
|
-
initializeWithValue?: boolean;
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Custom hook that tracks the state of a media query using the [`Match Media API`](https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia).
|
|
16
|
-
* @param {string} query - The media query to track.
|
|
17
|
-
* @param {?UseMediaQueryOptions} [options] - The options for customizing the behavior of the hook (optional).
|
|
18
|
-
* @returns {boolean} The current state of the media query (true if the query matches, false otherwise).
|
|
19
|
-
* @public
|
|
20
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-media-query)
|
|
21
|
-
* @example
|
|
22
|
-
* ```tsx
|
|
23
|
-
* const isSmallScreen = useMediaQuery('(max-width: 600px)');
|
|
24
|
-
* // Use `isSmallScreen` to conditionally apply styles or logic based on the screen size.
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
export declare function useMediaQuery(query: string, { defaultValue, initializeWithValue, }?: UseMediaQueryOptions): boolean;
|
|
28
|
-
export {};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { useState as c } from "react";
|
|
2
|
-
import { useIsomorphicLayoutEffect as d } from "../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.mjs";
|
|
3
|
-
const m = typeof window > "u";
|
|
4
|
-
function u(n, {
|
|
5
|
-
defaultValue: r = !1,
|
|
6
|
-
initializeWithValue: s = !0
|
|
7
|
-
} = {}) {
|
|
8
|
-
const i = (e) => m ? r : window.matchMedia(e).matches, [o, a] = c(() => s ? i(n) : r);
|
|
9
|
-
function t() {
|
|
10
|
-
a(i(n));
|
|
11
|
-
}
|
|
12
|
-
return d(() => {
|
|
13
|
-
const e = window.matchMedia(n);
|
|
14
|
-
return t(), e.addListener ? e.addListener(t) : e.addEventListener("change", t), () => {
|
|
15
|
-
e.removeListener ? e.removeListener(t) : e.removeEventListener("change", t);
|
|
16
|
-
};
|
|
17
|
-
}, [n]), o;
|
|
18
|
-
}
|
|
19
|
-
export {
|
|
20
|
-
u as useMediaQuery
|
|
21
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useOnClickOutside';
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { RefObject } from 'react';
|
|
2
|
-
|
|
3
|
-
/** Supported event types. */
|
|
4
|
-
type EventType = 'mousedown' | 'mouseup' | 'touchstart' | 'touchend' | 'focusin' | 'focusout';
|
|
5
|
-
/**
|
|
6
|
-
* Custom hook that handles clicks outside a specified element.
|
|
7
|
-
* @template T - The type of the element's reference.
|
|
8
|
-
* @param {RefObject<T> | RefObject<T>[]} ref - The React ref object(s) representing the element(s) to watch for outside clicks.
|
|
9
|
-
* @param {(event: MouseEvent | TouchEvent | FocusEvent) => void} handler - The callback function to be executed when a click outside the element occurs.
|
|
10
|
-
* @param {EventType} [eventType] - The mouse event type to listen for (optional, default is 'mousedown').
|
|
11
|
-
* @param {?AddEventListenerOptions} [eventListenerOptions] - The options object to be passed to the `addEventListener` method (optional).
|
|
12
|
-
* @returns {void}
|
|
13
|
-
* @public
|
|
14
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-on-click-outside)
|
|
15
|
-
* @example
|
|
16
|
-
* ```tsx
|
|
17
|
-
* const containerRef = useRef(null);
|
|
18
|
-
* useOnClickOutside([containerRef], () => {
|
|
19
|
-
* // Handle clicks outside the container.
|
|
20
|
-
* });
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export declare function useOnClickOutside<T extends HTMLElement = HTMLElement>(ref: RefObject<T> | RefObject<T>[], handler: (event: MouseEvent | TouchEvent | FocusEvent) => void, eventType?: EventType, eventListenerOptions?: AddEventListenerOptions): void;
|
|
24
|
-
export {};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { useEventListener as o } from "../useEventListener/useEventListener.mjs";
|
|
2
|
-
function d(t, i, s = "mousedown", u = {}) {
|
|
3
|
-
o(
|
|
4
|
-
s,
|
|
5
|
-
(r) => {
|
|
6
|
-
const n = r.target;
|
|
7
|
-
if (!n || !n.isConnected)
|
|
8
|
-
return;
|
|
9
|
-
(Array.isArray(t) ? t.filter((e) => !!e.current).every((e) => e.current && !e.current.contains(n)) : t.current && !t.current.contains(n)) && i(r);
|
|
10
|
-
},
|
|
11
|
-
void 0,
|
|
12
|
-
u
|
|
13
|
-
);
|
|
14
|
-
}
|
|
15
|
-
export {
|
|
16
|
-
d as useOnClickOutside
|
|
17
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useReadLocalStorage';
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Represents the type for the options available when reading from local storage.
|
|
3
|
-
* @template T - The type of the stored value.
|
|
4
|
-
*/
|
|
5
|
-
type Options<T, InitializeWithValue extends boolean | undefined> = {
|
|
6
|
-
/** Custom deserializer function to convert the stored string value to the desired type (optional). */
|
|
7
|
-
deserializer?: (value: string) => T;
|
|
8
|
-
/** If `true` (default), the hook will initialize reading the local storage. In SSR, you should set it to `false`, returning `undefined` initially. */
|
|
9
|
-
initializeWithValue: InitializeWithValue;
|
|
10
|
-
};
|
|
11
|
-
export declare function useReadLocalStorage<T>(key: string, options: Options<T, false>): T | null | undefined;
|
|
12
|
-
export declare function useReadLocalStorage<T>(key: string, options?: Partial<Options<T, true>>): T | null;
|
|
13
|
-
export {};
|