@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,48 +0,0 @@
|
|
|
1
|
-
import { useCallback as a, useState as S, useEffect as w } from "react";
|
|
2
|
-
import { useEventListener as d } from "../useEventListener/useEventListener.mjs";
|
|
3
|
-
const c = typeof window > "u";
|
|
4
|
-
function m(e, t = {}) {
|
|
5
|
-
let { initializeWithValue: o = !0 } = t;
|
|
6
|
-
c && (o = !1);
|
|
7
|
-
const l = a(
|
|
8
|
-
(r) => {
|
|
9
|
-
if (t.deserializer)
|
|
10
|
-
return t.deserializer(r);
|
|
11
|
-
if (r === "undefined")
|
|
12
|
-
return;
|
|
13
|
-
let s;
|
|
14
|
-
try {
|
|
15
|
-
s = JSON.parse(r);
|
|
16
|
-
} catch (g) {
|
|
17
|
-
return console.error("Error parsing JSON:", g), null;
|
|
18
|
-
}
|
|
19
|
-
return s;
|
|
20
|
-
},
|
|
21
|
-
[t]
|
|
22
|
-
), n = a(() => {
|
|
23
|
-
if (c)
|
|
24
|
-
return null;
|
|
25
|
-
try {
|
|
26
|
-
const r = window.localStorage.getItem(e);
|
|
27
|
-
return r ? l(r) : null;
|
|
28
|
-
} catch (r) {
|
|
29
|
-
return console.warn(`Error reading localStorage key “${e}”:`, r), null;
|
|
30
|
-
}
|
|
31
|
-
}, [e, l]), [f, u] = S(() => {
|
|
32
|
-
if (o)
|
|
33
|
-
return n();
|
|
34
|
-
});
|
|
35
|
-
w(() => {
|
|
36
|
-
u(n());
|
|
37
|
-
}, [e]);
|
|
38
|
-
const i = a(
|
|
39
|
-
(r) => {
|
|
40
|
-
r.key && r.key !== e || u(n());
|
|
41
|
-
},
|
|
42
|
-
[e, n]
|
|
43
|
-
);
|
|
44
|
-
return d("storage", i), d("local-storage", i), f;
|
|
45
|
-
}
|
|
46
|
-
export {
|
|
47
|
-
m as useReadLocalStorage
|
|
48
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useResizeObserver';
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { RefObject } from 'react';
|
|
2
|
-
|
|
3
|
-
/** The size of the observed element. */
|
|
4
|
-
type Size = {
|
|
5
|
-
/** The width of the observed element. */
|
|
6
|
-
width: number | undefined;
|
|
7
|
-
/** The height of the observed element. */
|
|
8
|
-
height: number | undefined;
|
|
9
|
-
};
|
|
10
|
-
/** The options for the ResizeObserver. */
|
|
11
|
-
type UseResizeObserverOptions<T extends HTMLElement = HTMLElement> = {
|
|
12
|
-
/** The ref of the element to observe. */
|
|
13
|
-
ref: RefObject<T>;
|
|
14
|
-
/**
|
|
15
|
-
* When using `onResize`, the hook doesn't re-render on element size changes; it delegates handling to the provided callback.
|
|
16
|
-
* @default undefined
|
|
17
|
-
*/
|
|
18
|
-
onResize?: (size: Size) => void;
|
|
19
|
-
/**
|
|
20
|
-
* The box model to use for the ResizeObserver.
|
|
21
|
-
* @default 'content-box'
|
|
22
|
-
*/
|
|
23
|
-
box?: 'border-box' | 'content-box' | 'device-pixel-content-box';
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* Custom hook that observes the size of an element using the [`ResizeObserver API`](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver).
|
|
27
|
-
* @template T - The type of the element to observe.
|
|
28
|
-
* @param {UseResizeObserverOptions<T>} options - The options for the ResizeObserver.
|
|
29
|
-
* @returns {Size} - The size of the observed element.
|
|
30
|
-
* @public
|
|
31
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-resize-observer)
|
|
32
|
-
* @example
|
|
33
|
-
* ```tsx
|
|
34
|
-
* const myRef = useRef(null);
|
|
35
|
-
* const { width = 0, height = 0 } = useResizeObserver({
|
|
36
|
-
* ref: myRef,
|
|
37
|
-
* box: 'content-box',
|
|
38
|
-
* });
|
|
39
|
-
*
|
|
40
|
-
* <div ref={myRef}>Hello, world!</div>
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
export declare function useResizeObserver<T extends HTMLElement = HTMLElement>(options: UseResizeObserverOptions<T>): Size;
|
|
44
|
-
export {};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { useState as x, useRef as z, useEffect as v } from "react";
|
|
2
|
-
import { useIsMounted as l } from "../useIsMounted/useIsMounted.mjs";
|
|
3
|
-
const w = {
|
|
4
|
-
width: void 0,
|
|
5
|
-
height: void 0
|
|
6
|
-
};
|
|
7
|
-
function B(n) {
|
|
8
|
-
const { ref: e, box: t = "content-box" } = n, [{ width: a, height: b }, g] = x(w), s = l(), i = z({ ...w }), r = z(void 0);
|
|
9
|
-
return r.current = n.onResize, v(() => {
|
|
10
|
-
if (!e.current || typeof window > "u" || !("ResizeObserver" in window)) return;
|
|
11
|
-
const u = new ResizeObserver(([d]) => {
|
|
12
|
-
const h = t === "border-box" ? "borderBoxSize" : t === "device-pixel-content-box" ? "devicePixelContentBoxSize" : "contentBoxSize", o = S(d, h, "inlineSize"), c = S(d, h, "blockSize");
|
|
13
|
-
if (i.current.width !== o || i.current.height !== c) {
|
|
14
|
-
const f = { width: o, height: c };
|
|
15
|
-
i.current.width = o, i.current.height = c, r.current ? r.current(f) : s() && g(f);
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
return u.observe(e.current, { box: t }), () => {
|
|
19
|
-
u.disconnect();
|
|
20
|
-
};
|
|
21
|
-
}, [t, e, s]), { width: a, height: b };
|
|
22
|
-
}
|
|
23
|
-
function S(n, e, t) {
|
|
24
|
-
return n[e] ? Array.isArray(n[e]) ? n[e][0][t] : (
|
|
25
|
-
// @ts-ignore Support Firefox's non-standard behavior
|
|
26
|
-
n[e][t]
|
|
27
|
-
) : e === "contentBoxSize" ? n.contentRect[t === "inlineSize" ? "width" : "height"] : void 0;
|
|
28
|
-
}
|
|
29
|
-
export {
|
|
30
|
-
B as useResizeObserver
|
|
31
|
-
};
|
package/useScreen/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useScreen';
|
package/useScreen/index.mjs
DELETED
package/useScreen/package.json
DELETED
package/useScreen/useScreen.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The hooks options.
|
|
3
|
-
* @template InitializeWithValue - If `true` (default), the hook will initialize reading the screen dimensions. In SSR, you should set it to `false`, returning `undefined` initially.
|
|
4
|
-
*/
|
|
5
|
-
type UseScreenOptions<InitializeWithValue extends boolean | undefined> = {
|
|
6
|
-
/**
|
|
7
|
-
* If `true` (default), the hook will initialize reading the screen dimensions. In SSR, you should set it to `false`, returning `undefined` initially.
|
|
8
|
-
* @default true
|
|
9
|
-
*/
|
|
10
|
-
initializeWithValue: InitializeWithValue;
|
|
11
|
-
/**
|
|
12
|
-
* The delay in milliseconds before the state is updated (disabled by default for retro-compatibility).
|
|
13
|
-
* @default undefined
|
|
14
|
-
*/
|
|
15
|
-
debounceDelay?: number;
|
|
16
|
-
};
|
|
17
|
-
export declare function useScreen(options: UseScreenOptions<false>): Screen | undefined;
|
|
18
|
-
export declare function useScreen(options?: Partial<UseScreenOptions<true>>): Screen;
|
|
19
|
-
export {};
|
package/useScreen/useScreen.mjs
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { useState as w } from "react";
|
|
2
|
-
import { useDebounceCallback as b } from "../useDebounceCallback/useDebounceCallback.mjs";
|
|
3
|
-
import { useEventListener as D } from "../useEventListener/useEventListener.mjs";
|
|
4
|
-
import { useIsomorphicLayoutEffect as y } from "../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.mjs";
|
|
5
|
-
const c = typeof window > "u";
|
|
6
|
-
function x(e = {}) {
|
|
7
|
-
let { initializeWithValue: n = !0 } = e;
|
|
8
|
-
c && (n = !1);
|
|
9
|
-
const t = () => {
|
|
10
|
-
if (!c)
|
|
11
|
-
return window.screen;
|
|
12
|
-
}, [u, r] = w(() => {
|
|
13
|
-
if (n)
|
|
14
|
-
return t();
|
|
15
|
-
}), s = b(
|
|
16
|
-
r,
|
|
17
|
-
e.debounceDelay
|
|
18
|
-
);
|
|
19
|
-
function i() {
|
|
20
|
-
const o = t(), f = e.debounceDelay ? s : r;
|
|
21
|
-
if (o) {
|
|
22
|
-
const {
|
|
23
|
-
width: a,
|
|
24
|
-
height: d,
|
|
25
|
-
availHeight: l,
|
|
26
|
-
availWidth: S,
|
|
27
|
-
colorDepth: h,
|
|
28
|
-
orientation: m,
|
|
29
|
-
pixelDepth: p
|
|
30
|
-
} = o;
|
|
31
|
-
f({
|
|
32
|
-
width: a,
|
|
33
|
-
height: d,
|
|
34
|
-
availHeight: l,
|
|
35
|
-
availWidth: S,
|
|
36
|
-
colorDepth: h,
|
|
37
|
-
orientation: m,
|
|
38
|
-
pixelDepth: p
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return D("resize", i), y(() => {
|
|
43
|
-
i();
|
|
44
|
-
}, []), u;
|
|
45
|
-
}
|
|
46
|
-
export {
|
|
47
|
-
x as useScreen
|
|
48
|
-
};
|
package/useScript/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useScript';
|
package/useScript/index.mjs
DELETED
package/useScript/package.json
DELETED
package/useScript/useScript.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/** Script loading status. */
|
|
2
|
-
type UseScriptStatus = 'idle' | 'loading' | 'ready' | 'error';
|
|
3
|
-
/** Hook options. */
|
|
4
|
-
type UseScriptOptions = {
|
|
5
|
-
/** If `true`, prevents the script from being loaded (optional). */
|
|
6
|
-
shouldPreventLoad?: boolean;
|
|
7
|
-
/** If `true`, removes the script from the DOM when the component unmounts (optional). */
|
|
8
|
-
removeOnUnmount?: boolean;
|
|
9
|
-
/** Script's `id` (optional). */
|
|
10
|
-
id?: string;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Custom hook that dynamically loads scripts and tracking their loading status.
|
|
14
|
-
* @param {string | null} src - The source URL of the script to load. Set to `null` or omit to prevent loading (optional).
|
|
15
|
-
* @param {UseScriptOptions} [options] - Additional options for controlling script loading (optional).
|
|
16
|
-
* @returns {UseScriptStatus} The status of the script loading, which can be one of 'idle', 'loading', 'ready', or 'error'.
|
|
17
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-script)
|
|
18
|
-
* @example
|
|
19
|
-
* const scriptStatus = useScript('https://example.com/script.js', { removeOnUnmount: true });
|
|
20
|
-
* // Access the status of the script loading (e.g., 'loading', 'ready', 'error').
|
|
21
|
-
*/
|
|
22
|
-
export declare function useScript(src: string | null, options?: UseScriptOptions): UseScriptStatus;
|
|
23
|
-
export {};
|
package/useScript/useScript.mjs
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { useState as S, useEffect as s } from "react";
|
|
2
|
-
const c = /* @__PURE__ */ new Map();
|
|
3
|
-
function E(r) {
|
|
4
|
-
const e = document.querySelector(
|
|
5
|
-
`script[src="${r}"]`
|
|
6
|
-
), l = e == null ? void 0 : e.getAttribute("data-status");
|
|
7
|
-
return {
|
|
8
|
-
node: e,
|
|
9
|
-
status: l
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
function L(r, e) {
|
|
13
|
-
const [l, v] = S(() => !r || e != null && e.shouldPreventLoad ? "idle" : typeof window > "u" ? "loading" : c.get(r) ?? "loading");
|
|
14
|
-
return s(() => {
|
|
15
|
-
if (!r || e != null && e.shouldPreventLoad)
|
|
16
|
-
return;
|
|
17
|
-
const d = c.get(r);
|
|
18
|
-
if (d === "ready" || d === "error") {
|
|
19
|
-
v(d);
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
const f = E(r);
|
|
23
|
-
let t = f.node;
|
|
24
|
-
if (t)
|
|
25
|
-
v(f.status ?? d ?? "loading");
|
|
26
|
-
else {
|
|
27
|
-
t = document.createElement("script"), t.src = r, t.async = !0, e != null && e.id && (t.id = e.id), t.setAttribute("data-status", "loading"), document.body.appendChild(t);
|
|
28
|
-
const u = (n) => {
|
|
29
|
-
const m = n.type === "load" ? "ready" : "error";
|
|
30
|
-
t == null || t.setAttribute("data-status", m);
|
|
31
|
-
};
|
|
32
|
-
t.addEventListener("load", u), t.addEventListener("error", u);
|
|
33
|
-
}
|
|
34
|
-
const a = (u) => {
|
|
35
|
-
const n = u.type === "load" ? "ready" : "error";
|
|
36
|
-
v(n), c.set(r, n);
|
|
37
|
-
};
|
|
38
|
-
return t.addEventListener("load", a), t.addEventListener("error", a), () => {
|
|
39
|
-
t && (t.removeEventListener("load", a), t.removeEventListener("error", a)), t && (e != null && e.removeOnUnmount) && (t.remove(), c.delete(r));
|
|
40
|
-
};
|
|
41
|
-
}, [r, e == null ? void 0 : e.shouldPreventLoad, e == null ? void 0 : e.removeOnUnmount, e == null ? void 0 : e.id]), l;
|
|
42
|
-
}
|
|
43
|
-
export {
|
|
44
|
-
L as useScript
|
|
45
|
-
};
|
package/useScrollLock/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useScrollLock';
|
package/useScrollLock/index.mjs
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/** Hook options. */
|
|
2
|
-
type UseScrollLockOptions = {
|
|
3
|
-
/**
|
|
4
|
-
* Whether to lock the scroll initially.
|
|
5
|
-
* @default true
|
|
6
|
-
*/
|
|
7
|
-
autoLock?: boolean;
|
|
8
|
-
/**
|
|
9
|
-
* The target element to lock the scroll (default is the body element).
|
|
10
|
-
* @default document.body
|
|
11
|
-
*/
|
|
12
|
-
lockTarget?: HTMLElement | string;
|
|
13
|
-
/**
|
|
14
|
-
* Whether to prevent width reflow when locking the scroll.
|
|
15
|
-
* @default true
|
|
16
|
-
*/
|
|
17
|
-
widthReflow?: boolean;
|
|
18
|
-
};
|
|
19
|
-
/** Hook return type. */
|
|
20
|
-
type UseScrollLockReturn = {
|
|
21
|
-
/** Whether the scroll is locked. */
|
|
22
|
-
isLocked: boolean;
|
|
23
|
-
/** Lock the scroll. */
|
|
24
|
-
lock: () => void;
|
|
25
|
-
/** Unlock the scroll. */
|
|
26
|
-
unlock: () => void;
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* A custom hook that locks and unlocks scroll.
|
|
30
|
-
* @param {UseScrollLockOptions} [options] - Options to configure the hook, by default it will lock the scroll automatically.
|
|
31
|
-
* @returns {UseScrollLockReturn} - An object containing the lock and unlock functions.
|
|
32
|
-
* @public
|
|
33
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-scroll-lock)
|
|
34
|
-
* @example
|
|
35
|
-
* ```tsx
|
|
36
|
-
* // Lock the scroll when the modal is mounted, and unlock it when it's unmounted
|
|
37
|
-
* useScrollLock()
|
|
38
|
-
* ```
|
|
39
|
-
* @example
|
|
40
|
-
* ```tsx
|
|
41
|
-
* // Manually lock and unlock the scroll
|
|
42
|
-
* const { lock, unlock } = useScrollLock({ autoLock: false })
|
|
43
|
-
*
|
|
44
|
-
* return (
|
|
45
|
-
* <div>
|
|
46
|
-
* <button onClick={lock}>Lock</button>
|
|
47
|
-
* <button onClick={unlock}>Unlock</button>
|
|
48
|
-
* </div>
|
|
49
|
-
* )
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
|
-
export declare function useScrollLock(options?: UseScrollLockOptions): UseScrollLockReturn;
|
|
53
|
-
export {};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { useState as y, useRef as d } from "react";
|
|
2
|
-
import { useIsomorphicLayoutEffect as w } from "../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.mjs";
|
|
3
|
-
const R = typeof window > "u";
|
|
4
|
-
function S(s = {}) {
|
|
5
|
-
const { autoLock: o = !0, lockTarget: e, widthReflow: n = !0 } = s, [l, c] = y(!1), t = d(null), r = d(null), u = () => {
|
|
6
|
-
if (t.current) {
|
|
7
|
-
const { overflow: f, paddingRight: g } = t.current.style;
|
|
8
|
-
if (r.current = { overflow: f, paddingRight: g }, n) {
|
|
9
|
-
const a = t.current === document.body ? window.innerWidth : t.current.offsetWidth, h = parseInt(window.getComputedStyle(t.current).paddingRight, 10) || 0, p = a - t.current.scrollWidth;
|
|
10
|
-
t.current.style.paddingRight = `${p + h}px`;
|
|
11
|
-
}
|
|
12
|
-
t.current.style.overflow = "hidden", c(!0);
|
|
13
|
-
}
|
|
14
|
-
}, i = () => {
|
|
15
|
-
t.current && r.current && (t.current.style.overflow = r.current.overflow, n && (t.current.style.paddingRight = r.current.paddingRight)), c(!1);
|
|
16
|
-
};
|
|
17
|
-
return w(() => {
|
|
18
|
-
if (!R)
|
|
19
|
-
return e && (t.current = typeof e == "string" ? document.querySelector(e) : e), t.current || (t.current = document.body), o && u(), () => {
|
|
20
|
-
i();
|
|
21
|
-
};
|
|
22
|
-
}, [o, e, n]), { isLocked: l, lock: u, unlock: i };
|
|
23
|
-
}
|
|
24
|
-
export {
|
|
25
|
-
S as useScrollLock
|
|
26
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useSessionStorage';
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
-
|
|
3
|
-
declare global {
|
|
4
|
-
interface WindowEventMap {
|
|
5
|
-
'session-storage': CustomEvent;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Represents the options for customizing the behavior of serialization and deserialization.
|
|
10
|
-
* @template T - The type of the state to be stored in session storage.
|
|
11
|
-
*/
|
|
12
|
-
type UseSessionStorageOptions<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 session 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 [`sessionStorage API`](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage) to persist state across page reloads.
|
|
25
|
-
* @template T - The type of the state to be stored in session storage.
|
|
26
|
-
* @param {string} key - The key under which the value will be stored in session storage.
|
|
27
|
-
* @param {T | (() => T)} initialValue - The initial value of the state or a function that returns the initial value.
|
|
28
|
-
* @param {?UseSessionStorageOptions<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-session-storage)
|
|
32
|
-
* @example
|
|
33
|
-
* ```tsx
|
|
34
|
-
* const [count, setCount, removeCount] = useSessionStorage('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 useSessionStorage<T>(key: string, initialValue: T | (() => T), options?: UseSessionStorageOptions<T>): [T, Dispatch<SetStateAction<T>>, () => void];
|
|
39
|
-
export {};
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { useCallback as i, useState as F, useEffect as p } from "react";
|
|
2
|
-
import { useEventCallback as u } from "../useEventCallback/useEventCallback.mjs";
|
|
3
|
-
import { useEventListener as w } from "../useEventListener/useEventListener.mjs";
|
|
4
|
-
const a = typeof window > "u";
|
|
5
|
-
function J(n, r, o = {}) {
|
|
6
|
-
const { initializeWithValue: S = !0 } = o, m = i(
|
|
7
|
-
(e) => o.serializer ? o.serializer(e) : JSON.stringify(e),
|
|
8
|
-
[o]
|
|
9
|
-
), d = i(
|
|
10
|
-
(e) => {
|
|
11
|
-
if (o.deserializer)
|
|
12
|
-
return o.deserializer(e);
|
|
13
|
-
if (e === "undefined")
|
|
14
|
-
return;
|
|
15
|
-
const t = r instanceof Function ? r() : r;
|
|
16
|
-
let g;
|
|
17
|
-
try {
|
|
18
|
-
g = JSON.parse(e);
|
|
19
|
-
} catch (z) {
|
|
20
|
-
return console.error("Error parsing JSON:", z), t;
|
|
21
|
-
}
|
|
22
|
-
return g;
|
|
23
|
-
},
|
|
24
|
-
[o, r]
|
|
25
|
-
), s = i(() => {
|
|
26
|
-
const e = r instanceof Function ? r() : r;
|
|
27
|
-
if (a)
|
|
28
|
-
return e;
|
|
29
|
-
try {
|
|
30
|
-
const t = window.sessionStorage.getItem(n);
|
|
31
|
-
return t ? d(t) : e;
|
|
32
|
-
} catch (t) {
|
|
33
|
-
return console.warn(`Error reading sessionStorage key “${n}”:`, t), e;
|
|
34
|
-
}
|
|
35
|
-
}, [r, n, d]), [h, c] = F(() => S ? s() : r instanceof Function ? r() : r), E = u((e) => {
|
|
36
|
-
a && console.warn(
|
|
37
|
-
`Tried setting sessionStorage key “${n}” even though environment is not a client`
|
|
38
|
-
);
|
|
39
|
-
try {
|
|
40
|
-
const t = e instanceof Function ? e(s()) : e;
|
|
41
|
-
window.sessionStorage.setItem(n, m(t)), c(t), window.dispatchEvent(new StorageEvent("session-storage", { key: n }));
|
|
42
|
-
} catch (t) {
|
|
43
|
-
console.warn(`Error setting sessionStorage key “${n}”:`, t);
|
|
44
|
-
}
|
|
45
|
-
}), v = u(() => {
|
|
46
|
-
a && console.warn(
|
|
47
|
-
`Tried removing sessionStorage key “${n}” even though environment is not a client`
|
|
48
|
-
);
|
|
49
|
-
const e = r instanceof Function ? r() : r;
|
|
50
|
-
window.sessionStorage.removeItem(n), c(e), window.dispatchEvent(new StorageEvent("session-storage", { key: n }));
|
|
51
|
-
});
|
|
52
|
-
p(() => {
|
|
53
|
-
c(s());
|
|
54
|
-
}, [n]);
|
|
55
|
-
const f = i(
|
|
56
|
-
(e) => {
|
|
57
|
-
e.key && e.key !== n || c(s());
|
|
58
|
-
},
|
|
59
|
-
[n, s]
|
|
60
|
-
);
|
|
61
|
-
return w("storage", f), w("session-storage", f), [h, E, v];
|
|
62
|
-
}
|
|
63
|
-
export {
|
|
64
|
-
J as useSessionStorage
|
|
65
|
-
};
|
package/useStep/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useStep';
|
package/useStep/index.mjs
DELETED
package/useStep/package.json
DELETED
package/useStep/useStep.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
-
|
|
3
|
-
/** Represents the second element of the output of the `useStep` hook. */
|
|
4
|
-
type UseStepActions = {
|
|
5
|
-
/** Go to the next step in the process. */
|
|
6
|
-
goToNextStep: () => void;
|
|
7
|
-
/** Go to the previous step in the process. */
|
|
8
|
-
goToPrevStep: () => void;
|
|
9
|
-
/** Reset the step to the initial step. */
|
|
10
|
-
reset: () => void;
|
|
11
|
-
/** Check if the next step is available. */
|
|
12
|
-
canGoToNextStep: boolean;
|
|
13
|
-
/** Check if the previous step is available. */
|
|
14
|
-
canGoToPrevStep: boolean;
|
|
15
|
-
/** Set the current step to a specific value. */
|
|
16
|
-
setStep: Dispatch<SetStateAction<number>>;
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Custom hook that manages and navigates between steps in a multi-step process.
|
|
20
|
-
* @param {number} maxStep - The maximum step in the process.
|
|
21
|
-
* @returns {[number, UseStepActions]} An tuple containing the current step and helper functions for navigating steps.
|
|
22
|
-
* @public
|
|
23
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-step)
|
|
24
|
-
* @example
|
|
25
|
-
* ```tsx
|
|
26
|
-
* const [currentStep, { goToNextStep, goToPrevStep, reset, canGoToNextStep, canGoToPrevStep, setStep }] = useStep(3);
|
|
27
|
-
* // Access and use the current step and provided helper functions.
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
export declare function useStep(maxStep: number): [number, UseStepActions];
|
|
31
|
-
export {};
|
package/useStep/useStep.mjs
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { useState as a, useCallback as n } from "react";
|
|
2
|
-
function l(r) {
|
|
3
|
-
const [e, o] = a(1), c = e + 1 <= r, s = e - 1 > 0, S = n(
|
|
4
|
-
(t) => {
|
|
5
|
-
const u = t instanceof Function ? t(e) : t;
|
|
6
|
-
if (u >= 1 && u <= r) {
|
|
7
|
-
o(u);
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
throw new Error("Step not valid");
|
|
11
|
-
},
|
|
12
|
-
[r, e]
|
|
13
|
-
), i = n(() => {
|
|
14
|
-
c && o((t) => t + 1);
|
|
15
|
-
}, [c]), p = n(() => {
|
|
16
|
-
s && o((t) => t - 1);
|
|
17
|
-
}, [s]), f = n(() => {
|
|
18
|
-
o(1);
|
|
19
|
-
}, []);
|
|
20
|
-
return [
|
|
21
|
-
e,
|
|
22
|
-
{
|
|
23
|
-
goToNextStep: i,
|
|
24
|
-
goToPrevStep: p,
|
|
25
|
-
canGoToNextStep: c,
|
|
26
|
-
canGoToPrevStep: s,
|
|
27
|
-
setStep: S,
|
|
28
|
-
reset: f
|
|
29
|
-
}
|
|
30
|
-
];
|
|
31
|
-
}
|
|
32
|
-
export {
|
|
33
|
-
l as useStep
|
|
34
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useTernaryDarkMode';
|