@astral/ui 4.86.0 → 4.87.0
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/components/NotificationList/ListItem/useLogic/useLogic.js +1 -1
- package/components/createGlobalState/createGlobalState.d.ts +6 -0
- package/components/createGlobalState/createGlobalState.js +25 -0
- package/components/createGlobalState/index.d.ts +1 -0
- package/components/createGlobalState/index.js +1 -0
- package/components/createGlobalState/public.d.ts +1 -0
- package/components/createGlobalState/public.js +1 -0
- package/components/createGlobalState/utils/index.d.ts +1 -0
- package/components/createGlobalState/utils/index.js +1 -0
- package/components/createGlobalState/utils/resolveHookState/index.d.ts +1 -0
- package/components/createGlobalState/utils/resolveHookState/index.js +1 -0
- package/components/createGlobalState/utils/resolveHookState/resolveHookState.d.ts +4 -0
- package/components/createGlobalState/utils/resolveHookState/resolveHookState.js +8 -0
- package/components/createGlobalState/utils/types.d.ts +5 -0
- package/components/createGlobalState/utils/types.js +1 -0
- package/components/useDebounce/hooks/useTimeoutFn/index.d.ts +1 -0
- package/components/useDebounce/hooks/useTimeoutFn/index.js +1 -0
- package/components/useDebounce/hooks/useTimeoutFn/useTimeoutFn.d.ts +2 -0
- package/components/useDebounce/hooks/useTimeoutFn/useTimeoutFn.js +29 -0
- package/components/useDebounce/index.d.ts +1 -0
- package/components/useDebounce/index.js +1 -0
- package/components/useDebounce/public.d.ts +1 -0
- package/components/useDebounce/public.js +1 -0
- package/components/useDebounce/useDebounce.d.ts +6 -0
- package/components/useDebounce/useDebounce.js +10 -0
- package/components/useFirstMountState/index.d.ts +1 -1
- package/components/useFirstMountState/index.js +1 -1
- package/components/useFirstMountState/public.d.ts +1 -1
- package/components/useFirstMountState/public.js +1 -1
- package/components/useFirstMountState/useFirstMountState.d.ts +4 -1
- package/components/useFirstMountState/useFirstMountState.js +12 -1
- package/components/useIntersection/index.d.ts +1 -0
- package/components/useIntersection/index.js +1 -0
- package/components/useIntersection/public.d.ts +1 -0
- package/components/useIntersection/public.js +1 -0
- package/components/useIntersection/useIntersection.d.ts +5 -0
- package/components/useIntersection/useIntersection.js +22 -0
- package/components/useInterval/index.d.ts +1 -1
- package/components/useInterval/index.js +1 -1
- package/components/useInterval/public.d.ts +1 -1
- package/components/useInterval/public.js +1 -1
- package/components/useInterval/useInterval.d.ts +6 -1
- package/components/useInterval/useInterval.js +19 -1
- package/components/useIsomorphicLayoutEffect/index.d.ts +1 -0
- package/components/useIsomorphicLayoutEffect/index.js +1 -0
- package/components/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.d.ts +2 -0
- package/components/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js +5 -0
- package/components/useLocalStorage/index.d.ts +1 -1
- package/components/useLocalStorage/index.js +1 -1
- package/components/useLocalStorage/public.d.ts +1 -1
- package/components/useLocalStorage/public.js +1 -1
- package/components/useLocalStorage/useLocalStorage.d.ts +15 -1
- package/components/useLocalStorage/useLocalStorage.js +96 -1
- package/components/useMeasure/index.d.ts +1 -0
- package/components/useMeasure/index.js +1 -0
- package/components/useMeasure/public.d.ts +1 -0
- package/components/useMeasure/public.js +1 -0
- package/components/useMeasure/useMeasure.d.ts +13 -0
- package/components/useMeasure/useMeasure.js +42 -0
- package/components/useNewToggle/index.d.ts +1 -0
- package/components/useNewToggle/index.js +1 -0
- package/components/useNewToggle/public.d.ts +1 -0
- package/components/useNewToggle/public.js +1 -0
- package/components/useNewToggle/useNewToggle.d.ts +4 -0
- package/components/useNewToggle/useNewToggle.js +8 -0
- package/components/useRafState/hooks/useUnmount/index.d.ts +1 -0
- package/components/useRafState/hooks/useUnmount/index.js +1 -0
- package/components/useRafState/hooks/useUnmount/useUnmount.d.ts +1 -0
- package/components/useRafState/hooks/useUnmount/useUnmount.js +7 -0
- package/components/useRafState/index.d.ts +1 -0
- package/components/useRafState/index.js +1 -0
- package/components/useRafState/useRafState.d.ts +2 -0
- package/components/useRafState/useRafState.js +16 -0
- package/components/useScroll/index.d.ts +1 -0
- package/components/useScroll/index.js +1 -0
- package/components/useScroll/public.d.ts +1 -0
- package/components/useScroll/public.js +1 -0
- package/components/useScroll/useScroll.d.ts +9 -0
- package/components/useScroll/useScroll.js +39 -0
- package/components/useSet/index.d.ts +1 -1
- package/components/useSet/index.js +1 -1
- package/components/useSet/public.d.ts +1 -1
- package/components/useSet/public.js +1 -1
- package/components/useSet/useSet.d.ts +14 -1
- package/components/useSet/useSet.js +26 -1
- package/components/useSize/index.d.ts +1 -0
- package/components/useSize/index.js +1 -0
- package/components/useSize/public.d.ts +1 -0
- package/components/useSize/public.js +1 -0
- package/components/useSize/useSize.d.ts +17 -0
- package/components/useSize/useSize.js +79 -0
- package/components/useToggle/useToggle.d.ts +1 -0
- package/components/useToggle/useToggle.js +1 -0
- package/components/useUpdateEffect/index.d.ts +1 -1
- package/components/useUpdateEffect/index.js +1 -1
- package/components/useUpdateEffect/public.d.ts +1 -1
- package/components/useUpdateEffect/public.js +1 -1
- package/components/useUpdateEffect/useUpdateEffect.d.ts +5 -1
- package/components/useUpdateEffect/useUpdateEffect.js +13 -1
- package/components/useWindowScroll/index.d.ts +1 -0
- package/components/useWindowScroll/index.js +1 -0
- package/components/useWindowScroll/public.d.ts +1 -0
- package/components/useWindowScroll/public.js +1 -0
- package/components/useWindowScroll/useWindowScroll.d.ts +8 -0
- package/components/useWindowScroll/useWindowScroll.js +40 -0
- package/components/utils/addEventListenerSafe/addEventListenerSafe.d.ts +1 -0
- package/components/utils/addEventListenerSafe/addEventListenerSafe.js +5 -0
- package/components/utils/addEventListenerSafe/index.d.ts +1 -0
- package/components/utils/addEventListenerSafe/index.js +1 -0
- package/components/utils/isBrowser/index.d.ts +1 -0
- package/components/utils/isBrowser/index.js +1 -0
- package/components/utils/isBrowser/isBrowser.d.ts +1 -0
- package/components/utils/isBrowser/isBrowser.js +1 -0
- package/components/utils/removeEventListenerSafe/index.d.ts +1 -0
- package/components/utils/removeEventListenerSafe/index.js +1 -0
- package/components/utils/removeEventListenerSafe/removeEventListenerSafe.d.ts +1 -0
- package/components/utils/removeEventListenerSafe/removeEventListenerSafe.js +5 -0
- package/components/utils/replaceRaf/constants.d.ts +1 -0
- package/components/utils/replaceRaf/constants.js +1 -0
- package/components/utils/replaceRaf/index.d.ts +1 -0
- package/components/utils/replaceRaf/index.js +1 -0
- package/components/utils/replaceRaf/replaceRaf.d.ts +18 -0
- package/components/utils/replaceRaf/replaceRaf.js +81 -0
- package/node/components/NotificationList/ListItem/useLogic/useLogic.js +2 -2
- package/node/components/createGlobalState/createGlobalState.d.ts +6 -0
- package/node/components/createGlobalState/createGlobalState.js +29 -0
- package/node/components/createGlobalState/index.d.ts +1 -0
- package/node/components/createGlobalState/index.js +17 -0
- package/node/components/createGlobalState/public.d.ts +1 -0
- package/node/components/createGlobalState/public.js +17 -0
- package/node/components/createGlobalState/utils/index.d.ts +1 -0
- package/node/components/createGlobalState/utils/index.js +17 -0
- package/node/components/createGlobalState/utils/resolveHookState/index.d.ts +1 -0
- package/node/components/createGlobalState/utils/resolveHookState/index.js +17 -0
- package/node/components/createGlobalState/utils/resolveHookState/resolveHookState.d.ts +4 -0
- package/node/components/createGlobalState/utils/resolveHookState/resolveHookState.js +12 -0
- package/node/components/createGlobalState/utils/types.d.ts +5 -0
- package/node/components/createGlobalState/utils/types.js +2 -0
- package/node/components/useDebounce/hooks/useTimeoutFn/index.d.ts +1 -0
- package/node/components/useDebounce/hooks/useTimeoutFn/index.js +17 -0
- package/node/components/useDebounce/hooks/useTimeoutFn/useTimeoutFn.d.ts +2 -0
- package/node/components/useDebounce/hooks/useTimeoutFn/useTimeoutFn.js +33 -0
- package/node/components/useDebounce/index.d.ts +1 -0
- package/node/components/useDebounce/index.js +17 -0
- package/node/components/useDebounce/public.d.ts +1 -0
- package/node/components/useDebounce/public.js +17 -0
- package/node/components/useDebounce/useDebounce.d.ts +6 -0
- package/node/components/useDebounce/useDebounce.js +14 -0
- package/node/components/useFirstMountState/index.d.ts +1 -1
- package/node/components/useFirstMountState/index.js +15 -3
- package/node/components/useFirstMountState/public.d.ts +1 -1
- package/node/components/useFirstMountState/public.js +15 -3
- package/node/components/useFirstMountState/useFirstMountState.d.ts +4 -1
- package/node/components/useFirstMountState/useFirstMountState.js +13 -2
- package/node/components/useIntersection/index.d.ts +1 -0
- package/node/components/useIntersection/index.js +17 -0
- package/node/components/useIntersection/public.d.ts +1 -0
- package/node/components/useIntersection/public.js +17 -0
- package/node/components/useIntersection/useIntersection.d.ts +5 -0
- package/node/components/useIntersection/useIntersection.js +26 -0
- package/node/components/useInterval/index.d.ts +1 -1
- package/node/components/useInterval/index.js +15 -3
- package/node/components/useInterval/public.d.ts +1 -1
- package/node/components/useInterval/public.js +15 -3
- package/node/components/useInterval/useInterval.d.ts +6 -1
- package/node/components/useInterval/useInterval.js +20 -2
- package/node/components/useIsomorphicLayoutEffect/index.d.ts +1 -0
- package/node/components/useIsomorphicLayoutEffect/index.js +17 -0
- package/node/components/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.d.ts +2 -0
- package/node/components/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js +8 -0
- package/node/components/useLocalStorage/index.d.ts +1 -1
- package/node/components/useLocalStorage/index.js +5 -14
- package/node/components/useLocalStorage/public.d.ts +1 -1
- package/node/components/useLocalStorage/public.js +5 -14
- package/node/components/useLocalStorage/useLocalStorage.d.ts +15 -1
- package/node/components/useLocalStorage/useLocalStorage.js +97 -2
- package/node/components/useMeasure/index.d.ts +1 -0
- package/node/components/useMeasure/index.js +8 -0
- package/node/components/useMeasure/public.d.ts +1 -0
- package/node/components/useMeasure/public.js +8 -0
- package/node/components/useMeasure/useMeasure.d.ts +13 -0
- package/node/components/useMeasure/useMeasure.js +44 -0
- package/node/components/useNewToggle/index.d.ts +1 -0
- package/node/components/useNewToggle/index.js +17 -0
- package/node/components/useNewToggle/public.d.ts +1 -0
- package/node/components/useNewToggle/public.js +17 -0
- package/node/components/useNewToggle/useNewToggle.d.ts +4 -0
- package/node/components/useNewToggle/useNewToggle.js +12 -0
- package/node/components/useRafState/hooks/useUnmount/index.d.ts +1 -0
- package/node/components/useRafState/hooks/useUnmount/index.js +17 -0
- package/node/components/useRafState/hooks/useUnmount/useUnmount.d.ts +1 -0
- package/node/components/useRafState/hooks/useUnmount/useUnmount.js +11 -0
- package/node/components/useRafState/index.d.ts +1 -0
- package/node/components/useRafState/index.js +17 -0
- package/node/components/useRafState/useRafState.d.ts +2 -0
- package/node/components/useRafState/useRafState.js +20 -0
- package/node/components/useScroll/index.d.ts +1 -0
- package/node/components/useScroll/index.js +17 -0
- package/node/components/useScroll/public.d.ts +1 -0
- package/node/components/useScroll/public.js +17 -0
- package/node/components/useScroll/useScroll.d.ts +9 -0
- package/node/components/useScroll/useScroll.js +43 -0
- package/node/components/useSet/index.d.ts +1 -1
- package/node/components/useSet/index.js +15 -3
- package/node/components/useSet/public.d.ts +1 -1
- package/node/components/useSet/public.js +15 -3
- package/node/components/useSet/useSet.d.ts +14 -1
- package/node/components/useSet/useSet.js +27 -2
- package/node/components/useSize/index.d.ts +1 -0
- package/node/components/useSize/index.js +8 -0
- package/node/components/useSize/public.d.ts +1 -0
- package/node/components/useSize/public.js +8 -0
- package/node/components/useSize/useSize.d.ts +17 -0
- package/node/components/useSize/useSize.js +106 -0
- package/node/components/useToggle/useToggle.d.ts +1 -0
- package/node/components/useToggle/useToggle.js +1 -0
- package/node/components/useUpdateEffect/index.d.ts +1 -1
- package/node/components/useUpdateEffect/index.js +15 -3
- package/node/components/useUpdateEffect/public.d.ts +1 -1
- package/node/components/useUpdateEffect/public.js +15 -3
- package/node/components/useUpdateEffect/useUpdateEffect.d.ts +5 -1
- package/node/components/useUpdateEffect/useUpdateEffect.js +14 -2
- package/node/components/useWindowScroll/index.d.ts +1 -0
- package/node/components/useWindowScroll/index.js +17 -0
- package/node/components/useWindowScroll/public.d.ts +1 -0
- package/node/components/useWindowScroll/public.js +17 -0
- package/node/components/useWindowScroll/useWindowScroll.d.ts +8 -0
- package/node/components/useWindowScroll/useWindowScroll.js +44 -0
- package/node/components/utils/addEventListenerSafe/addEventListenerSafe.d.ts +1 -0
- package/node/components/utils/addEventListenerSafe/addEventListenerSafe.js +9 -0
- package/node/components/utils/addEventListenerSafe/index.d.ts +1 -0
- package/node/components/utils/addEventListenerSafe/index.js +17 -0
- package/node/components/utils/isBrowser/index.d.ts +1 -0
- package/node/components/utils/isBrowser/index.js +17 -0
- package/node/components/utils/isBrowser/isBrowser.d.ts +1 -0
- package/node/components/utils/isBrowser/isBrowser.js +4 -0
- package/node/components/utils/removeEventListenerSafe/index.d.ts +1 -0
- package/node/components/utils/removeEventListenerSafe/index.js +17 -0
- package/node/components/utils/removeEventListenerSafe/removeEventListenerSafe.d.ts +1 -0
- package/node/components/utils/removeEventListenerSafe/removeEventListenerSafe.js +9 -0
- package/node/components/utils/replaceRaf/constants.d.ts +1 -0
- package/node/components/utils/replaceRaf/constants.js +4 -0
- package/node/components/utils/replaceRaf/index.d.ts +1 -0
- package/node/components/utils/replaceRaf/index.js +17 -0
- package/node/components/utils/replaceRaf/replaceRaf.d.ts +18 -0
- package/node/components/utils/replaceRaf/replaceRaf.js +86 -0
- package/package.json +1 -2
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./resolveHookState"), exports);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type IHookStateInitAction, type IHookStateResolvable, type IHookStateSetAction } from '../types';
|
|
2
|
+
export declare function resolveHookState<TState>(nextState: IHookStateInitAction<TState>): TState;
|
|
3
|
+
export declare function resolveHookState<TState, TCurrentState extends TState>(nextState: IHookStateSetAction<TState>, currentState?: TCurrentState): TState;
|
|
4
|
+
export declare function resolveHookState<TState, TCurrentState extends TState>(nextState: IHookStateResolvable<TState>, currentState?: TCurrentState): TState;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveHookState = void 0;
|
|
4
|
+
function resolveHookState(nextState, currentState) {
|
|
5
|
+
if (typeof nextState === 'function') {
|
|
6
|
+
return nextState.length
|
|
7
|
+
? nextState(currentState)
|
|
8
|
+
: nextState();
|
|
9
|
+
}
|
|
10
|
+
return nextState;
|
|
11
|
+
}
|
|
12
|
+
exports.resolveHookState = resolveHookState;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type IHookStateInitialSetter<TState> = () => TState;
|
|
2
|
+
export type IHookStateInitAction<TState> = TState | IHookStateInitialSetter<TState>;
|
|
3
|
+
export type IHookStateSetter<TState> = ((prevState: TState) => TState) | (() => TState);
|
|
4
|
+
export type IHookStateSetAction<TState> = TState | IHookStateSetter<TState>;
|
|
5
|
+
export type IHookStateResolvable<TState> = TState | IHookStateInitialSetter<TState> | IHookStateSetter<TState>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useTimeoutFn';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./useTimeoutFn"), exports);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useTimeoutFn = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
function useTimeoutFn(fn, ms = 0) {
|
|
6
|
+
const ready = (0, react_1.useRef)(false);
|
|
7
|
+
const timeout = (0, react_1.useRef)(null);
|
|
8
|
+
const callback = (0, react_1.useRef)(fn);
|
|
9
|
+
const isReady = (0, react_1.useCallback)(() => ready.current, []);
|
|
10
|
+
const set = (0, react_1.useCallback)(() => {
|
|
11
|
+
ready.current = false;
|
|
12
|
+
timeout.current && clearTimeout(timeout.current);
|
|
13
|
+
timeout.current = setTimeout(() => {
|
|
14
|
+
ready.current = true;
|
|
15
|
+
callback.current();
|
|
16
|
+
}, ms);
|
|
17
|
+
}, [ms]);
|
|
18
|
+
const clear = (0, react_1.useCallback)(() => {
|
|
19
|
+
ready.current = null;
|
|
20
|
+
timeout.current && clearTimeout(timeout.current);
|
|
21
|
+
}, []);
|
|
22
|
+
// update ref when function changes
|
|
23
|
+
(0, react_1.useEffect)(() => {
|
|
24
|
+
callback.current = fn;
|
|
25
|
+
}, [fn]);
|
|
26
|
+
// set on mount, clear on unmount
|
|
27
|
+
(0, react_1.useEffect)(() => {
|
|
28
|
+
set();
|
|
29
|
+
return clear;
|
|
30
|
+
}, [ms]);
|
|
31
|
+
return [isReady, clear, set];
|
|
32
|
+
}
|
|
33
|
+
exports.useTimeoutFn = useTimeoutFn;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useDebounce';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./useDebounce"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useDebounce';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./useDebounce"), exports);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type DependencyList } from 'react';
|
|
2
|
+
export type UseDebounceReturn = [() => boolean | null, () => void];
|
|
3
|
+
/**
|
|
4
|
+
* Хук откладывает вызов функции, пока не пройдет переданное число миллисекунд после последнего вызова debounce-функции.
|
|
5
|
+
*/
|
|
6
|
+
export declare function useDebounce(fn: Function, ms?: number, deps?: DependencyList): UseDebounceReturn;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useDebounce = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const useTimeoutFn_1 = require("./hooks/useTimeoutFn");
|
|
6
|
+
/**
|
|
7
|
+
* Хук откладывает вызов функции, пока не пройдет переданное число миллисекунд после последнего вызова debounce-функции.
|
|
8
|
+
*/
|
|
9
|
+
function useDebounce(fn, ms = 0, deps = []) {
|
|
10
|
+
const [isReady, cancel, reset] = (0, useTimeoutFn_1.useTimeoutFn)(fn, ms);
|
|
11
|
+
(0, react_1.useEffect)(reset, deps);
|
|
12
|
+
return [isReady, cancel];
|
|
13
|
+
}
|
|
14
|
+
exports.useDebounce = useDebounce;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './useFirstMountState';
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
var useFirstMountState_1 = require("./useFirstMountState");
|
|
5
|
-
Object.defineProperty(exports, "useFirstMountState", { enumerable: true, get: function () { return useFirstMountState_1.useFirstMountState; } });
|
|
17
|
+
__exportStar(require("./useFirstMountState"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './useFirstMountState';
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
var useFirstMountState_1 = require("./useFirstMountState");
|
|
5
|
-
Object.defineProperty(exports, "useFirstMountState", { enumerable: true, get: function () { return useFirstMountState_1.useFirstMountState; } });
|
|
17
|
+
__exportStar(require("./useFirstMountState"), exports);
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useFirstMountState = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
/**
|
|
6
|
+
* Хук возвращает true если компонент только монтировался (при первом рендере) и false в другом случае.
|
|
7
|
+
*/
|
|
8
|
+
function useFirstMountState() {
|
|
9
|
+
const isFirst = (0, react_1.useRef)(true);
|
|
10
|
+
if (isFirst.current) {
|
|
11
|
+
isFirst.current = false;
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
return isFirst.current;
|
|
15
|
+
}
|
|
16
|
+
exports.useFirstMountState = useFirstMountState;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useIntersection';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./useIntersection"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useIntersection';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./useIntersection"), exports);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type RefObject } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Хук отслеживает изменения в пересечении целевого элемента с родительским элементом или с верхним уровнем области просмотра документа.
|
|
4
|
+
*/
|
|
5
|
+
export declare const useIntersection: (ref: RefObject<HTMLElement | null>, options: IntersectionObserverInit) => IntersectionObserverEntry | null;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useIntersection = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
/**
|
|
6
|
+
* Хук отслеживает изменения в пересечении целевого элемента с родительским элементом или с верхним уровнем области просмотра документа.
|
|
7
|
+
*/
|
|
8
|
+
const useIntersection = (ref, options) => {
|
|
9
|
+
const [intersectionObserverEntry, setIntersectionObserverEntry] = (0, react_1.useState)(null);
|
|
10
|
+
(0, react_1.useEffect)(() => {
|
|
11
|
+
if (ref.current && typeof IntersectionObserver === 'function') {
|
|
12
|
+
const handler = (entries) => {
|
|
13
|
+
setIntersectionObserverEntry(entries[0]);
|
|
14
|
+
};
|
|
15
|
+
const observer = new IntersectionObserver(handler, options);
|
|
16
|
+
observer.observe(ref.current);
|
|
17
|
+
return () => {
|
|
18
|
+
setIntersectionObserverEntry(null);
|
|
19
|
+
observer.disconnect();
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return () => { };
|
|
23
|
+
}, [ref.current, options.threshold, options.root, options.rootMargin]);
|
|
24
|
+
return intersectionObserverEntry;
|
|
25
|
+
};
|
|
26
|
+
exports.useIntersection = useIntersection;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './useInterval';
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
var useInterval_1 = require("./useInterval");
|
|
5
|
-
Object.defineProperty(exports, "useInterval", { enumerable: true, get: function () { return useInterval_1.useInterval; } });
|
|
17
|
+
__exportStar(require("./useInterval"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './useInterval';
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
var useInterval_1 = require("./useInterval");
|
|
5
|
-
Object.defineProperty(exports, "useInterval", { enumerable: true, get: function () { return useInterval_1.useInterval; } });
|
|
17
|
+
__exportStar(require("./useInterval"), exports);
|
|
@@ -1 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Хук для запуска функции с заданным интервалом.
|
|
3
|
+
* Если передать null, интервал не будет запущен (или будет остановлен).
|
|
4
|
+
* Если значение не указано (undefined), используется задержка 0 мс.
|
|
5
|
+
*/
|
|
6
|
+
export declare const useInterval: (callback: Function, delay?: number | null) => void;
|
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useInterval = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
/**
|
|
6
|
+
* Хук для запуска функции с заданным интервалом.
|
|
7
|
+
* Если передать null, интервал не будет запущен (или будет остановлен).
|
|
8
|
+
* Если значение не указано (undefined), используется задержка 0 мс.
|
|
9
|
+
*/
|
|
10
|
+
const useInterval = (callback, delay) => {
|
|
11
|
+
const savedCallback = (0, react_1.useRef)(() => { });
|
|
12
|
+
(0, react_1.useEffect)(() => {
|
|
13
|
+
savedCallback.current = callback;
|
|
14
|
+
});
|
|
15
|
+
(0, react_1.useEffect)(() => {
|
|
16
|
+
if (delay !== null) {
|
|
17
|
+
const interval = setInterval(() => savedCallback.current(), delay || 0);
|
|
18
|
+
return () => clearInterval(interval);
|
|
19
|
+
}
|
|
20
|
+
return undefined;
|
|
21
|
+
}, [delay]);
|
|
22
|
+
};
|
|
23
|
+
exports.useInterval = useInterval;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useIsomorphicLayoutEffect';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./useIsomorphicLayoutEffect"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useIsomorphicLayoutEffect = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const isBrowser_1 = require("../utils/isBrowser");
|
|
6
|
+
exports.useIsomorphicLayoutEffect = isBrowser_1.isBrowser
|
|
7
|
+
? react_1.useLayoutEffect
|
|
8
|
+
: react_1.useEffect;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { default as useLocalStorage } from './useLocalStorage';
|
|
@@ -1,17 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
16
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
6
|
+
exports.useLocalStorage = void 0;
|
|
7
|
+
var useLocalStorage_1 = require("./useLocalStorage");
|
|
8
|
+
Object.defineProperty(exports, "useLocalStorage", { enumerable: true, get: function () { return __importDefault(useLocalStorage_1).default; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { default as useLocalStorage } from './useLocalStorage';
|
|
@@ -1,17 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
16
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
6
|
+
exports.useLocalStorage = void 0;
|
|
7
|
+
var useLocalStorage_1 = require("./useLocalStorage");
|
|
8
|
+
Object.defineProperty(exports, "useLocalStorage", { enumerable: true, get: function () { return __importDefault(useLocalStorage_1).default; } });
|
|
@@ -1 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import { type Dispatch, type SetStateAction } from 'react';
|
|
2
|
+
type ParserOptions<T> = {
|
|
3
|
+
raw: true;
|
|
4
|
+
} | {
|
|
5
|
+
raw: false;
|
|
6
|
+
serializer: (value: T) => string;
|
|
7
|
+
deserializer: (value: string) => T;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Хук управляет состоянием, которое синхронизируется с localStorage браузера.
|
|
11
|
+
* Возвращает текущее значение, функцию для его обновления и функцию для удаления значения из localStorage.
|
|
12
|
+
*/
|
|
13
|
+
export declare const useLocalStorage: <T>(key: string, initialValue?: T | undefined, options?: ParserOptions<T> | undefined) => [T | undefined, Dispatch<SetStateAction<T | undefined>>, () => void];
|
|
14
|
+
declare const useLocalStorageExport: <T>(key: string, initialValue?: T | undefined, options?: ParserOptions<T> | undefined) => [T | undefined, Dispatch<SetStateAction<T | undefined>>, () => void];
|
|
15
|
+
export default useLocalStorageExport;
|
|
@@ -1,5 +1,100 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useLocalStorage = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const isBrowser_1 = require("../utils/isBrowser");
|
|
6
|
+
const noop = () => { };
|
|
7
|
+
/**
|
|
8
|
+
* Хук управляет состоянием, которое синхронизируется с localStorage браузера.
|
|
9
|
+
* Возвращает текущее значение, функцию для его обновления и функцию для удаления значения из localStorage.
|
|
10
|
+
*/
|
|
11
|
+
const useLocalStorage = (key, initialValue, options) => {
|
|
12
|
+
if (!key) {
|
|
13
|
+
throw new Error('useLocalStorage key may not be falsy');
|
|
14
|
+
}
|
|
15
|
+
const deserializer = (() => {
|
|
16
|
+
if (!options) {
|
|
17
|
+
return JSON.parse;
|
|
18
|
+
}
|
|
19
|
+
if (options.raw) {
|
|
20
|
+
return (value) => value;
|
|
21
|
+
}
|
|
22
|
+
return options.deserializer;
|
|
23
|
+
})();
|
|
24
|
+
const serializer = (() => {
|
|
25
|
+
if (!options) {
|
|
26
|
+
return JSON.stringify;
|
|
27
|
+
}
|
|
28
|
+
if (options.raw) {
|
|
29
|
+
return String;
|
|
30
|
+
}
|
|
31
|
+
return options.serializer;
|
|
32
|
+
})();
|
|
33
|
+
const initializer = (0, react_1.useRef)((newKey) => {
|
|
34
|
+
try {
|
|
35
|
+
const localStorageValue = localStorage.getItem(newKey);
|
|
36
|
+
if (localStorageValue !== null) {
|
|
37
|
+
return deserializer(localStorageValue);
|
|
38
|
+
}
|
|
39
|
+
if (initialValue) {
|
|
40
|
+
localStorage.setItem(newKey, serializer(initialValue));
|
|
41
|
+
}
|
|
42
|
+
return initialValue;
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
// If user is in private mode or has storage restriction
|
|
46
|
+
// localStorage can throw. JSON.parse and JSON.stringify
|
|
47
|
+
// can throw, too.
|
|
48
|
+
return initialValue;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
const [state, setState] = (0, react_1.useState)(() => initializer.current(key));
|
|
52
|
+
(0, react_1.useLayoutEffect)(() => setState(initializer.current(key)), [key]);
|
|
53
|
+
const serializeValue = (value, parserOptions) => {
|
|
54
|
+
if (!parserOptions) {
|
|
55
|
+
return JSON.stringify(value);
|
|
56
|
+
}
|
|
57
|
+
if (parserOptions.raw) {
|
|
58
|
+
return typeof value === 'string' ? value : JSON.stringify(value);
|
|
59
|
+
}
|
|
60
|
+
return parserOptions.serializer(value);
|
|
61
|
+
};
|
|
62
|
+
const set = (0, react_1.useCallback)((valOrFunc) => {
|
|
63
|
+
try {
|
|
64
|
+
const newState = typeof valOrFunc === 'function'
|
|
65
|
+
? valOrFunc(state)
|
|
66
|
+
: valOrFunc;
|
|
67
|
+
if (typeof newState === 'undefined') {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const value = serializeValue(newState, options);
|
|
71
|
+
localStorage.setItem(key, value);
|
|
72
|
+
setState(deserializer(value));
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
// If user is in private mode or has storage restriction
|
|
76
|
+
// localStorage can throw. Also JSON.stringify can throw.
|
|
77
|
+
}
|
|
78
|
+
}, [key, setState]);
|
|
79
|
+
const remove = (0, react_1.useCallback)(() => {
|
|
80
|
+
try {
|
|
81
|
+
localStorage.removeItem(key);
|
|
82
|
+
setState(undefined);
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
// If user is in private mode or has storage restriction
|
|
86
|
+
// localStorage can throw.
|
|
87
|
+
}
|
|
88
|
+
}, [key, setState]);
|
|
89
|
+
return [state, set, remove];
|
|
90
|
+
};
|
|
91
|
+
exports.useLocalStorage = useLocalStorage;
|
|
92
|
+
const useLocalStorageFallback = ((initialValue) => [
|
|
93
|
+
initialValue,
|
|
94
|
+
noop,
|
|
95
|
+
noop,
|
|
96
|
+
]);
|
|
97
|
+
const useLocalStorageExport = isBrowser_1.isBrowser
|
|
98
|
+
? exports.useLocalStorage
|
|
99
|
+
: useLocalStorageFallback;
|
|
100
|
+
exports.default = useLocalStorageExport;
|