@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,9 @@
|
|
|
1
|
+
import { type RefObject } from 'react';
|
|
2
|
+
export interface IState {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Хук отслеживает позицию скролла внутри HTML-элемента, на который передан ref.
|
|
8
|
+
*/
|
|
9
|
+
export declare const useScroll: (ref: RefObject<HTMLElement | null>) => IState;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { useRafState } from '../useRafState';
|
|
3
|
+
import { addEventListenerSafe } from '../utils/addEventListenerSafe';
|
|
4
|
+
import { removeEventListenerSafe } from '../utils/removeEventListenerSafe';
|
|
5
|
+
/**
|
|
6
|
+
* Хук отслеживает позицию скролла внутри HTML-элемента, на который передан ref.
|
|
7
|
+
*/
|
|
8
|
+
export const useScroll = (ref) => {
|
|
9
|
+
if (process.env.NODE_ENV === 'development' &&
|
|
10
|
+
(typeof ref !== 'object' || typeof ref.current === 'undefined')) {
|
|
11
|
+
throw new Error('`useScroll` expects a single ref argument.');
|
|
12
|
+
}
|
|
13
|
+
const [state, setState] = useRafState({
|
|
14
|
+
x: 0,
|
|
15
|
+
y: 0,
|
|
16
|
+
});
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
const handler = () => {
|
|
19
|
+
if (ref.current) {
|
|
20
|
+
setState({
|
|
21
|
+
x: ref.current.scrollLeft,
|
|
22
|
+
y: ref.current.scrollTop,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
if (ref.current) {
|
|
27
|
+
addEventListenerSafe(ref.current, 'scroll', handler, {
|
|
28
|
+
capture: false,
|
|
29
|
+
passive: true,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return () => {
|
|
33
|
+
if (ref.current) {
|
|
34
|
+
removeEventListenerSafe(ref.current, 'scroll', handler);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}, [ref]);
|
|
38
|
+
return state;
|
|
39
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './useSet';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './useSet';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './useSet';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './useSet';
|
|
@@ -1 +1,14 @@
|
|
|
1
|
-
export
|
|
1
|
+
export interface IStableActions<TKey> {
|
|
2
|
+
add: (key: TKey) => void;
|
|
3
|
+
remove: (key: TKey) => void;
|
|
4
|
+
toggle: (key: TKey) => void;
|
|
5
|
+
reset: () => void;
|
|
6
|
+
clear: () => void;
|
|
7
|
+
}
|
|
8
|
+
export interface IActions<TKey> extends IStableActions<TKey> {
|
|
9
|
+
has: (key: TKey) => boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Хук отслеживает состояние Set и предоставляет методы для его изменения.
|
|
13
|
+
*/
|
|
14
|
+
export declare const useSet: <TKey>(initialSet?: Set<TKey>) => [Set<TKey>, IActions<TKey>];
|
|
@@ -1 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Хук отслеживает состояние Set и предоставляет методы для его изменения.
|
|
4
|
+
*/
|
|
5
|
+
export const useSet = (initialSet = new Set()) => {
|
|
6
|
+
const [set, setSet] = useState(initialSet);
|
|
7
|
+
const stableActions = useMemo(() => {
|
|
8
|
+
const add = (item) => setSet((prevSet) => new Set([...Array.from(prevSet), item]));
|
|
9
|
+
const remove = (item) => setSet((prevSet) => new Set(Array.from(prevSet).filter((i) => i !== item)));
|
|
10
|
+
const toggle = (item) => setSet((prevSet) => prevSet.has(item)
|
|
11
|
+
? new Set(Array.from(prevSet).filter((i) => i !== item))
|
|
12
|
+
: new Set([...Array.from(prevSet), item]));
|
|
13
|
+
return {
|
|
14
|
+
add,
|
|
15
|
+
remove,
|
|
16
|
+
toggle,
|
|
17
|
+
reset: () => setSet(initialSet),
|
|
18
|
+
clear: () => setSet(new Set()),
|
|
19
|
+
};
|
|
20
|
+
}, [setSet]);
|
|
21
|
+
const utils = {
|
|
22
|
+
has: useCallback((item) => set.has(item), [set]),
|
|
23
|
+
...stableActions,
|
|
24
|
+
};
|
|
25
|
+
return [set, utils];
|
|
26
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as useSize } from './useSize';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as useSize } from './useSize';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as useSize } from './useSize';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as useSize } from './useSize';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
type ElementProps = {
|
|
3
|
+
style?: React.CSSProperties;
|
|
4
|
+
children?: React.ReactNode;
|
|
5
|
+
};
|
|
6
|
+
export type Element = ((state: IState) => React.ReactElement<ElementProps>) | React.ReactElement<ElementProps>;
|
|
7
|
+
export interface IState {
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Хук отслеживает размеры HTML-элемента.
|
|
13
|
+
* Создает iframe, который растягивается на весь размер элемента и слушает событие resize.
|
|
14
|
+
*/
|
|
15
|
+
export declare const useSize: (element: Element, { width, height }?: Partial<IState>) => [React.ReactElement<ElementProps>, IState];
|
|
16
|
+
declare const useSizeExport: (element: Element, { width, height }?: Partial<IState>) => [React.ReactElement<ElementProps>, IState];
|
|
17
|
+
export default useSizeExport;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { addEventListenerSafe } from '../utils/addEventListenerSafe';
|
|
3
|
+
import { isBrowser } from '../utils/isBrowser';
|
|
4
|
+
import { removeEventListenerSafe } from '../utils/removeEventListenerSafe';
|
|
5
|
+
const { useState, useEffect, useRef } = React;
|
|
6
|
+
const defer = (callback) => setTimeout(callback, 35);
|
|
7
|
+
/**
|
|
8
|
+
* Хук отслеживает размеры HTML-элемента.
|
|
9
|
+
* Создает iframe, который растягивается на весь размер элемента и слушает событие resize.
|
|
10
|
+
*/
|
|
11
|
+
export const useSize = (element, { width = Infinity, height = Infinity } = {}) => {
|
|
12
|
+
const [state, setState] = useState({ width, height });
|
|
13
|
+
const elementNode = typeof element === 'function' ? element(state) : element;
|
|
14
|
+
const style = elementNode.props.style || {};
|
|
15
|
+
const ref = useRef(null);
|
|
16
|
+
let window = null;
|
|
17
|
+
const setSize = () => {
|
|
18
|
+
const iframe = ref.current;
|
|
19
|
+
const size = iframe
|
|
20
|
+
? {
|
|
21
|
+
width: iframe.offsetWidth,
|
|
22
|
+
height: iframe.offsetHeight,
|
|
23
|
+
}
|
|
24
|
+
: { width, height };
|
|
25
|
+
setState(size);
|
|
26
|
+
};
|
|
27
|
+
const onWindow = (windowToListenOn) => {
|
|
28
|
+
addEventListenerSafe(windowToListenOn, 'resize', setSize);
|
|
29
|
+
defer(setSize);
|
|
30
|
+
};
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
const iframe = ref.current;
|
|
33
|
+
if (!iframe) {
|
|
34
|
+
// iframe will be undefined if component is already unmounted
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (iframe.contentWindow) {
|
|
38
|
+
window = iframe.contentWindow;
|
|
39
|
+
onWindow(window);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
const onLoad = () => {
|
|
43
|
+
addEventListenerSafe(iframe, 'load', onLoad);
|
|
44
|
+
window = iframe.contentWindow;
|
|
45
|
+
onWindow(window);
|
|
46
|
+
};
|
|
47
|
+
removeEventListenerSafe(iframe, 'load', onLoad);
|
|
48
|
+
}
|
|
49
|
+
return () => {
|
|
50
|
+
if (window) {
|
|
51
|
+
removeEventListenerSafe(window, 'resize', setSize);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}, []);
|
|
55
|
+
style.position = 'relative';
|
|
56
|
+
const sized = React.cloneElement(elementNode, { style }, ...[
|
|
57
|
+
React.createElement('iframe', {
|
|
58
|
+
ref,
|
|
59
|
+
style: {
|
|
60
|
+
background: 'transparent',
|
|
61
|
+
border: 'none',
|
|
62
|
+
height: '100%',
|
|
63
|
+
left: 0,
|
|
64
|
+
position: 'absolute',
|
|
65
|
+
top: 0,
|
|
66
|
+
width: '100%',
|
|
67
|
+
zIndex: -1,
|
|
68
|
+
},
|
|
69
|
+
}),
|
|
70
|
+
...React.Children.toArray(elementNode.props.children),
|
|
71
|
+
]);
|
|
72
|
+
return [sized, state];
|
|
73
|
+
};
|
|
74
|
+
const useSizeFallback = ((element, { width = Infinity, height = Infinity } = {}) => [
|
|
75
|
+
typeof element === 'function' ? element({ width, height }) : element,
|
|
76
|
+
{ width, height },
|
|
77
|
+
]);
|
|
78
|
+
const useSizeExport = isBrowser ? useSize : useSizeFallback;
|
|
79
|
+
export default useSizeExport;
|
|
@@ -37,6 +37,7 @@ type UseToggleOptions<TCloseArgs extends Arguments, TOpenArgs extends Arguments>
|
|
|
37
37
|
onInactive?: CloseHandler<TCloseArgs>;
|
|
38
38
|
};
|
|
39
39
|
/**
|
|
40
|
+
* @deprecated
|
|
40
41
|
* хук хранящий стейт активности, и предоставляющий методы переключения с проксируемыми аргументами, позволяет уменьшить бойлерплейт код
|
|
41
42
|
*/
|
|
42
43
|
export declare const useToggle: <TCloseArgs extends Arguments, TOpenArgs extends Arguments>(params?: UseToggleOptions<TCloseArgs, TOpenArgs> | undefined) => UseToggleResultTuple<TCloseArgs, TOpenArgs>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './useUpdateEffect';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './useUpdateEffect';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './useUpdateEffect';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './useUpdateEffect';
|
|
@@ -1 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { useFirstMountState } from '../useFirstMountState';
|
|
3
|
+
/**
|
|
4
|
+
* Хук, который выполняет эффект только после первого монтирования компонента.
|
|
5
|
+
*/
|
|
6
|
+
export const useUpdateEffect = (effect, deps) => {
|
|
7
|
+
const isFirstMount = useFirstMountState();
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
if (!isFirstMount) {
|
|
10
|
+
return effect();
|
|
11
|
+
}
|
|
12
|
+
}, deps);
|
|
13
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useWindowScroll';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useWindowScroll';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useWindowScroll';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useWindowScroll';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { useRafState } from '../useRafState';
|
|
3
|
+
import { addEventListenerSafe } from '../utils/addEventListenerSafe';
|
|
4
|
+
import { isBrowser } from '../utils/isBrowser';
|
|
5
|
+
import { removeEventListenerSafe } from '../utils/removeEventListenerSafe';
|
|
6
|
+
/**
|
|
7
|
+
* Хук отслеживает позицию скролла в окне браузера.
|
|
8
|
+
*/
|
|
9
|
+
export const useWindowScroll = () => {
|
|
10
|
+
const [state, setState] = useRafState(() => ({
|
|
11
|
+
x: isBrowser ? window.pageXOffset : 0,
|
|
12
|
+
y: isBrowser ? window.pageYOffset : 0,
|
|
13
|
+
}));
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
const handler = () => {
|
|
16
|
+
setState((newState) => {
|
|
17
|
+
const { pageXOffset, pageYOffset } = window;
|
|
18
|
+
//Check state for change, return same state if no change happened to prevent rerender
|
|
19
|
+
//(see useState/setState documentation). useState/setState is used internally in useRafState/setState.
|
|
20
|
+
return newState.x !== pageXOffset || newState.y !== pageYOffset
|
|
21
|
+
? {
|
|
22
|
+
x: pageXOffset,
|
|
23
|
+
y: pageYOffset,
|
|
24
|
+
}
|
|
25
|
+
: newState;
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
//We have to update window scroll at mount, before subscription.
|
|
29
|
+
//Window scroll may be changed between render and effect handler.
|
|
30
|
+
handler();
|
|
31
|
+
addEventListenerSafe(window, 'scroll', handler, {
|
|
32
|
+
capture: false,
|
|
33
|
+
passive: true,
|
|
34
|
+
});
|
|
35
|
+
return () => {
|
|
36
|
+
removeEventListenerSafe(window, 'scroll', handler);
|
|
37
|
+
};
|
|
38
|
+
}, []);
|
|
39
|
+
return state;
|
|
40
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function addEventListenerSafe<T extends Window | Document | HTMLElement | EventTarget>(obj: T | null, ...args: Parameters<T['addEventListener']>): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './addEventListenerSafe';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './addEventListenerSafe';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './isBrowser';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './isBrowser';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isBrowser: boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const isBrowser = typeof window !== 'undefined';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './removeEventListenerSafe';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './removeEventListenerSafe';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function removeEventListenerSafe<T extends Window | Document | HTMLElement | EventTarget>(obj: T | null, ...args: Parameters<T['removeEventListener']>): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const defaultFrameDuration: number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const defaultFrameDuration = 1000 / 60;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './replaceRaf';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './replaceRaf';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type Stub = {
|
|
2
|
+
add: (cb: Function) => number;
|
|
3
|
+
remove: (id: number) => void;
|
|
4
|
+
flush: (duration?: number) => void;
|
|
5
|
+
reset: () => void;
|
|
6
|
+
step: (steps?: number, duration?: number) => void;
|
|
7
|
+
};
|
|
8
|
+
export declare function createStub(frameDuration?: number, startTime?: number): Stub;
|
|
9
|
+
type ReplaceRafOptions = {
|
|
10
|
+
frameDuration?: number;
|
|
11
|
+
startTime?: number;
|
|
12
|
+
};
|
|
13
|
+
type ReplaceRafRoot = {
|
|
14
|
+
requestAnimationFrame: (callback: FrameRequestCallback) => number;
|
|
15
|
+
cancelAnimationFrame: (handle: number) => void;
|
|
16
|
+
};
|
|
17
|
+
export declare function replaceRaf(roots?: ReplaceRafRoot[], { frameDuration, startTime, }?: ReplaceRafOptions): void;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { defaultFrameDuration } from './constants';
|
|
2
|
+
const now = () => {
|
|
3
|
+
if (performance) {
|
|
4
|
+
return performance.now();
|
|
5
|
+
}
|
|
6
|
+
return Date.now();
|
|
7
|
+
};
|
|
8
|
+
export function createStub(frameDuration = defaultFrameDuration, startTime = now()) {
|
|
9
|
+
const frames = [];
|
|
10
|
+
let frameId = 0;
|
|
11
|
+
let currentTime = startTime;
|
|
12
|
+
const add = (cb) => {
|
|
13
|
+
const id = ++frameId;
|
|
14
|
+
const callback = (time) => {
|
|
15
|
+
cb(time);
|
|
16
|
+
// remove callback from frames after calling it
|
|
17
|
+
remove(id);
|
|
18
|
+
};
|
|
19
|
+
frames.push({
|
|
20
|
+
id,
|
|
21
|
+
callback,
|
|
22
|
+
});
|
|
23
|
+
return id;
|
|
24
|
+
};
|
|
25
|
+
const remove = (id) => {
|
|
26
|
+
const index = frames.findIndex((frame) => frame.id === id);
|
|
27
|
+
if (index === -1) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
// remove frame from array
|
|
31
|
+
frames.splice(index, 1);
|
|
32
|
+
};
|
|
33
|
+
const flush = (duration = frameDuration) => {
|
|
34
|
+
while (frames.length) {
|
|
35
|
+
step(1, duration);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const reset = () => {
|
|
39
|
+
frames.length = 0;
|
|
40
|
+
currentTime = startTime;
|
|
41
|
+
};
|
|
42
|
+
const step = (steps = 1, duration = frameDuration) => {
|
|
43
|
+
if (steps === 0) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
// This line can cause a precision error if both `currentTime`
|
|
47
|
+
// and `duration` are numbers with decimal components.
|
|
48
|
+
currentTime = currentTime + duration;
|
|
49
|
+
const shallow = frames.slice(0);
|
|
50
|
+
shallow.forEach((frame) => {
|
|
51
|
+
frame.callback(currentTime);
|
|
52
|
+
});
|
|
53
|
+
return step(steps - 1, duration);
|
|
54
|
+
};
|
|
55
|
+
const api = {
|
|
56
|
+
add,
|
|
57
|
+
remove,
|
|
58
|
+
reset,
|
|
59
|
+
flush,
|
|
60
|
+
step,
|
|
61
|
+
};
|
|
62
|
+
return api;
|
|
63
|
+
}
|
|
64
|
+
export function replaceRaf(roots = [], { frameDuration = defaultFrameDuration, startTime = now(), } = {}) {
|
|
65
|
+
// automatic usage of 'window' or 'global' if no roots are provided
|
|
66
|
+
if (!roots.length) {
|
|
67
|
+
roots.push(typeof window !== 'undefined' ? window : global);
|
|
68
|
+
}
|
|
69
|
+
// all roots share the same stub
|
|
70
|
+
const stub = createStub(frameDuration, startTime);
|
|
71
|
+
roots.forEach((root) => {
|
|
72
|
+
root.requestAnimationFrame = stub.add;
|
|
73
|
+
// $FlowFixMe - incorrect typing
|
|
74
|
+
Object.assign(root.requestAnimationFrame, {
|
|
75
|
+
step: stub.step,
|
|
76
|
+
flush: stub.flush,
|
|
77
|
+
reset: stub.reset,
|
|
78
|
+
});
|
|
79
|
+
root.cancelAnimationFrame = stub.remove;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useLogic = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
|
-
const
|
|
5
|
+
const useIntersection_1 = require("../../../useIntersection");
|
|
6
6
|
const useLogic = ({ id, onDelete, onViewNotification, isUnread, }) => {
|
|
7
7
|
const ref = (0, react_1.useRef)(null);
|
|
8
|
-
const entry = (0,
|
|
8
|
+
const entry = (0, useIntersection_1.useIntersection)(ref, {
|
|
9
9
|
root: null,
|
|
10
10
|
threshold: 0.95,
|
|
11
11
|
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type IHookStateInitAction, type IHookStateSetAction } from './utils/types';
|
|
2
|
+
export declare function createGlobalState<TState>(initialState: IHookStateInitAction<TState>): () => [TState, (state: IHookStateSetAction<TState>) => void];
|
|
3
|
+
export declare function createGlobalState<TState = undefined>(): () => [
|
|
4
|
+
TState,
|
|
5
|
+
(state: IHookStateSetAction<TState>) => void
|
|
6
|
+
];
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createGlobalState = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const useIsomorphicLayoutEffect_1 = require("../useIsomorphicLayoutEffect");
|
|
6
|
+
const resolveHookState_1 = require("./utils/resolveHookState");
|
|
7
|
+
function createGlobalState(initialState) {
|
|
8
|
+
const store = {
|
|
9
|
+
state: initialState instanceof Function ? initialState() : initialState,
|
|
10
|
+
setState(nextState) {
|
|
11
|
+
store.state = (0, resolveHookState_1.resolveHookState)(nextState, store.state);
|
|
12
|
+
store.setters.forEach((setter) => setter(store.state));
|
|
13
|
+
},
|
|
14
|
+
setters: [],
|
|
15
|
+
};
|
|
16
|
+
return () => {
|
|
17
|
+
const [globalState, stateSetter] = (0, react_1.useState)(store.state);
|
|
18
|
+
(0, react_1.useEffect)(() => () => {
|
|
19
|
+
store.setters = store.setters.filter((setter) => setter !== stateSetter);
|
|
20
|
+
}, []);
|
|
21
|
+
(0, useIsomorphicLayoutEffect_1.useIsomorphicLayoutEffect)(() => {
|
|
22
|
+
if (!store.setters.includes(stateSetter)) {
|
|
23
|
+
store.setters.push(stateSetter);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
return [globalState, store.setState];
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
exports.createGlobalState = createGlobalState;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './createGlobalState';
|
|
@@ -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("./createGlobalState"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './createGlobalState';
|
|
@@ -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("./createGlobalState"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './resolveHookState';
|
|
@@ -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 @@
|
|
|
1
|
+
export * from './resolveHookState';
|