@astral/ui 4.85.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.
Files changed (263) hide show
  1. package/components/NotificationList/ListItem/useLogic/useLogic.js +1 -1
  2. package/components/PageHeader/HeaderContent/HeaderContent.d.ts +2 -2
  3. package/components/PageHeader/HeaderContent/HeaderContent.js +3 -3
  4. package/components/PageHeader/HeaderContent/styles.d.ts +4 -0
  5. package/components/PageHeader/HeaderContent/styles.js +11 -1
  6. package/components/PageHeader/PageHeader.js +2 -2
  7. package/components/PageHeader/styles.js +2 -2
  8. package/components/PageHeader/types.d.ts +10 -0
  9. package/components/createGlobalState/createGlobalState.d.ts +6 -0
  10. package/components/createGlobalState/createGlobalState.js +25 -0
  11. package/components/createGlobalState/index.d.ts +1 -0
  12. package/components/createGlobalState/index.js +1 -0
  13. package/components/createGlobalState/public.d.ts +1 -0
  14. package/components/createGlobalState/public.js +1 -0
  15. package/components/createGlobalState/utils/index.d.ts +1 -0
  16. package/components/createGlobalState/utils/index.js +1 -0
  17. package/components/createGlobalState/utils/resolveHookState/index.d.ts +1 -0
  18. package/components/createGlobalState/utils/resolveHookState/index.js +1 -0
  19. package/components/createGlobalState/utils/resolveHookState/resolveHookState.d.ts +4 -0
  20. package/components/createGlobalState/utils/resolveHookState/resolveHookState.js +8 -0
  21. package/components/createGlobalState/utils/types.d.ts +5 -0
  22. package/components/createGlobalState/utils/types.js +1 -0
  23. package/components/useDebounce/hooks/useTimeoutFn/index.d.ts +1 -0
  24. package/components/useDebounce/hooks/useTimeoutFn/index.js +1 -0
  25. package/components/useDebounce/hooks/useTimeoutFn/useTimeoutFn.d.ts +2 -0
  26. package/components/useDebounce/hooks/useTimeoutFn/useTimeoutFn.js +29 -0
  27. package/components/useDebounce/index.d.ts +1 -0
  28. package/components/useDebounce/index.js +1 -0
  29. package/components/useDebounce/public.d.ts +1 -0
  30. package/components/useDebounce/public.js +1 -0
  31. package/components/useDebounce/useDebounce.d.ts +6 -0
  32. package/components/useDebounce/useDebounce.js +10 -0
  33. package/components/useFirstMountState/index.d.ts +1 -1
  34. package/components/useFirstMountState/index.js +1 -1
  35. package/components/useFirstMountState/public.d.ts +1 -1
  36. package/components/useFirstMountState/public.js +1 -1
  37. package/components/useFirstMountState/useFirstMountState.d.ts +4 -1
  38. package/components/useFirstMountState/useFirstMountState.js +12 -1
  39. package/components/useIntersection/index.d.ts +1 -0
  40. package/components/useIntersection/index.js +1 -0
  41. package/components/useIntersection/public.d.ts +1 -0
  42. package/components/useIntersection/public.js +1 -0
  43. package/components/useIntersection/useIntersection.d.ts +5 -0
  44. package/components/useIntersection/useIntersection.js +22 -0
  45. package/components/useInterval/index.d.ts +1 -1
  46. package/components/useInterval/index.js +1 -1
  47. package/components/useInterval/public.d.ts +1 -1
  48. package/components/useInterval/public.js +1 -1
  49. package/components/useInterval/useInterval.d.ts +6 -1
  50. package/components/useInterval/useInterval.js +19 -1
  51. package/components/useIsomorphicLayoutEffect/index.d.ts +1 -0
  52. package/components/useIsomorphicLayoutEffect/index.js +1 -0
  53. package/components/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.d.ts +2 -0
  54. package/components/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js +5 -0
  55. package/components/useLocalStorage/index.d.ts +1 -1
  56. package/components/useLocalStorage/index.js +1 -1
  57. package/components/useLocalStorage/public.d.ts +1 -1
  58. package/components/useLocalStorage/public.js +1 -1
  59. package/components/useLocalStorage/useLocalStorage.d.ts +15 -1
  60. package/components/useLocalStorage/useLocalStorage.js +96 -1
  61. package/components/useMeasure/index.d.ts +1 -0
  62. package/components/useMeasure/index.js +1 -0
  63. package/components/useMeasure/public.d.ts +1 -0
  64. package/components/useMeasure/public.js +1 -0
  65. package/components/useMeasure/useMeasure.d.ts +13 -0
  66. package/components/useMeasure/useMeasure.js +42 -0
  67. package/components/useNewToggle/index.d.ts +1 -0
  68. package/components/useNewToggle/index.js +1 -0
  69. package/components/useNewToggle/public.d.ts +1 -0
  70. package/components/useNewToggle/public.js +1 -0
  71. package/components/useNewToggle/useNewToggle.d.ts +4 -0
  72. package/components/useNewToggle/useNewToggle.js +8 -0
  73. package/components/useRafState/hooks/useUnmount/index.d.ts +1 -0
  74. package/components/useRafState/hooks/useUnmount/index.js +1 -0
  75. package/components/useRafState/hooks/useUnmount/useUnmount.d.ts +1 -0
  76. package/components/useRafState/hooks/useUnmount/useUnmount.js +7 -0
  77. package/components/useRafState/index.d.ts +1 -0
  78. package/components/useRafState/index.js +1 -0
  79. package/components/useRafState/useRafState.d.ts +2 -0
  80. package/components/useRafState/useRafState.js +16 -0
  81. package/components/useScroll/index.d.ts +1 -0
  82. package/components/useScroll/index.js +1 -0
  83. package/components/useScroll/public.d.ts +1 -0
  84. package/components/useScroll/public.js +1 -0
  85. package/components/useScroll/useScroll.d.ts +9 -0
  86. package/components/useScroll/useScroll.js +39 -0
  87. package/components/useSet/index.d.ts +1 -1
  88. package/components/useSet/index.js +1 -1
  89. package/components/useSet/public.d.ts +1 -1
  90. package/components/useSet/public.js +1 -1
  91. package/components/useSet/useSet.d.ts +14 -1
  92. package/components/useSet/useSet.js +26 -1
  93. package/components/useSize/index.d.ts +1 -0
  94. package/components/useSize/index.js +1 -0
  95. package/components/useSize/public.d.ts +1 -0
  96. package/components/useSize/public.js +1 -0
  97. package/components/useSize/useSize.d.ts +17 -0
  98. package/components/useSize/useSize.js +79 -0
  99. package/components/useToggle/useToggle.d.ts +1 -0
  100. package/components/useToggle/useToggle.js +1 -0
  101. package/components/useUpdateEffect/index.d.ts +1 -1
  102. package/components/useUpdateEffect/index.js +1 -1
  103. package/components/useUpdateEffect/public.d.ts +1 -1
  104. package/components/useUpdateEffect/public.js +1 -1
  105. package/components/useUpdateEffect/useUpdateEffect.d.ts +5 -1
  106. package/components/useUpdateEffect/useUpdateEffect.js +13 -1
  107. package/components/useWindowScroll/index.d.ts +1 -0
  108. package/components/useWindowScroll/index.js +1 -0
  109. package/components/useWindowScroll/public.d.ts +1 -0
  110. package/components/useWindowScroll/public.js +1 -0
  111. package/components/useWindowScroll/useWindowScroll.d.ts +8 -0
  112. package/components/useWindowScroll/useWindowScroll.js +40 -0
  113. package/components/utils/addEventListenerSafe/addEventListenerSafe.d.ts +1 -0
  114. package/components/utils/addEventListenerSafe/addEventListenerSafe.js +5 -0
  115. package/components/utils/addEventListenerSafe/index.d.ts +1 -0
  116. package/components/utils/addEventListenerSafe/index.js +1 -0
  117. package/components/utils/isBrowser/index.d.ts +1 -0
  118. package/components/utils/isBrowser/index.js +1 -0
  119. package/components/utils/isBrowser/isBrowser.d.ts +1 -0
  120. package/components/utils/isBrowser/isBrowser.js +1 -0
  121. package/components/utils/removeEventListenerSafe/index.d.ts +1 -0
  122. package/components/utils/removeEventListenerSafe/index.js +1 -0
  123. package/components/utils/removeEventListenerSafe/removeEventListenerSafe.d.ts +1 -0
  124. package/components/utils/removeEventListenerSafe/removeEventListenerSafe.js +5 -0
  125. package/components/utils/replaceRaf/constants.d.ts +1 -0
  126. package/components/utils/replaceRaf/constants.js +1 -0
  127. package/components/utils/replaceRaf/index.d.ts +1 -0
  128. package/components/utils/replaceRaf/index.js +1 -0
  129. package/components/utils/replaceRaf/replaceRaf.d.ts +18 -0
  130. package/components/utils/replaceRaf/replaceRaf.js +81 -0
  131. package/hook-form/FormPageLayoutBase/useLogic/useLogic.d.ts +1 -0
  132. package/node/components/NotificationList/ListItem/useLogic/useLogic.js +2 -2
  133. package/node/components/PageHeader/HeaderContent/HeaderContent.d.ts +2 -2
  134. package/node/components/PageHeader/HeaderContent/HeaderContent.js +2 -2
  135. package/node/components/PageHeader/HeaderContent/styles.d.ts +4 -0
  136. package/node/components/PageHeader/HeaderContent/styles.js +12 -2
  137. package/node/components/PageHeader/PageHeader.js +2 -2
  138. package/node/components/PageHeader/styles.js +2 -2
  139. package/node/components/PageHeader/types.d.ts +10 -0
  140. package/node/components/createGlobalState/createGlobalState.d.ts +6 -0
  141. package/node/components/createGlobalState/createGlobalState.js +29 -0
  142. package/node/components/createGlobalState/index.d.ts +1 -0
  143. package/node/components/createGlobalState/index.js +17 -0
  144. package/node/components/createGlobalState/public.d.ts +1 -0
  145. package/node/components/createGlobalState/public.js +17 -0
  146. package/node/components/createGlobalState/utils/index.d.ts +1 -0
  147. package/node/components/createGlobalState/utils/index.js +17 -0
  148. package/node/components/createGlobalState/utils/resolveHookState/index.d.ts +1 -0
  149. package/node/components/createGlobalState/utils/resolveHookState/index.js +17 -0
  150. package/node/components/createGlobalState/utils/resolveHookState/resolveHookState.d.ts +4 -0
  151. package/node/components/createGlobalState/utils/resolveHookState/resolveHookState.js +12 -0
  152. package/node/components/createGlobalState/utils/types.d.ts +5 -0
  153. package/node/components/createGlobalState/utils/types.js +2 -0
  154. package/node/components/useDebounce/hooks/useTimeoutFn/index.d.ts +1 -0
  155. package/node/components/useDebounce/hooks/useTimeoutFn/index.js +17 -0
  156. package/node/components/useDebounce/hooks/useTimeoutFn/useTimeoutFn.d.ts +2 -0
  157. package/node/components/useDebounce/hooks/useTimeoutFn/useTimeoutFn.js +33 -0
  158. package/node/components/useDebounce/index.d.ts +1 -0
  159. package/node/components/useDebounce/index.js +17 -0
  160. package/node/components/useDebounce/public.d.ts +1 -0
  161. package/node/components/useDebounce/public.js +17 -0
  162. package/node/components/useDebounce/useDebounce.d.ts +6 -0
  163. package/node/components/useDebounce/useDebounce.js +14 -0
  164. package/node/components/useFirstMountState/index.d.ts +1 -1
  165. package/node/components/useFirstMountState/index.js +15 -3
  166. package/node/components/useFirstMountState/public.d.ts +1 -1
  167. package/node/components/useFirstMountState/public.js +15 -3
  168. package/node/components/useFirstMountState/useFirstMountState.d.ts +4 -1
  169. package/node/components/useFirstMountState/useFirstMountState.js +13 -2
  170. package/node/components/useIntersection/index.d.ts +1 -0
  171. package/node/components/useIntersection/index.js +17 -0
  172. package/node/components/useIntersection/public.d.ts +1 -0
  173. package/node/components/useIntersection/public.js +17 -0
  174. package/node/components/useIntersection/useIntersection.d.ts +5 -0
  175. package/node/components/useIntersection/useIntersection.js +26 -0
  176. package/node/components/useInterval/index.d.ts +1 -1
  177. package/node/components/useInterval/index.js +15 -3
  178. package/node/components/useInterval/public.d.ts +1 -1
  179. package/node/components/useInterval/public.js +15 -3
  180. package/node/components/useInterval/useInterval.d.ts +6 -1
  181. package/node/components/useInterval/useInterval.js +20 -2
  182. package/node/components/useIsomorphicLayoutEffect/index.d.ts +1 -0
  183. package/node/components/useIsomorphicLayoutEffect/index.js +17 -0
  184. package/node/components/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.d.ts +2 -0
  185. package/node/components/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js +8 -0
  186. package/node/components/useLocalStorage/index.d.ts +1 -1
  187. package/node/components/useLocalStorage/index.js +5 -14
  188. package/node/components/useLocalStorage/public.d.ts +1 -1
  189. package/node/components/useLocalStorage/public.js +5 -14
  190. package/node/components/useLocalStorage/useLocalStorage.d.ts +15 -1
  191. package/node/components/useLocalStorage/useLocalStorage.js +97 -2
  192. package/node/components/useMeasure/index.d.ts +1 -0
  193. package/node/components/useMeasure/index.js +8 -0
  194. package/node/components/useMeasure/public.d.ts +1 -0
  195. package/node/components/useMeasure/public.js +8 -0
  196. package/node/components/useMeasure/useMeasure.d.ts +13 -0
  197. package/node/components/useMeasure/useMeasure.js +44 -0
  198. package/node/components/useNewToggle/index.d.ts +1 -0
  199. package/node/components/useNewToggle/index.js +17 -0
  200. package/node/components/useNewToggle/public.d.ts +1 -0
  201. package/node/components/useNewToggle/public.js +17 -0
  202. package/node/components/useNewToggle/useNewToggle.d.ts +4 -0
  203. package/node/components/useNewToggle/useNewToggle.js +12 -0
  204. package/node/components/useRafState/hooks/useUnmount/index.d.ts +1 -0
  205. package/node/components/useRafState/hooks/useUnmount/index.js +17 -0
  206. package/node/components/useRafState/hooks/useUnmount/useUnmount.d.ts +1 -0
  207. package/node/components/useRafState/hooks/useUnmount/useUnmount.js +11 -0
  208. package/node/components/useRafState/index.d.ts +1 -0
  209. package/node/components/useRafState/index.js +17 -0
  210. package/node/components/useRafState/useRafState.d.ts +2 -0
  211. package/node/components/useRafState/useRafState.js +20 -0
  212. package/node/components/useScroll/index.d.ts +1 -0
  213. package/node/components/useScroll/index.js +17 -0
  214. package/node/components/useScroll/public.d.ts +1 -0
  215. package/node/components/useScroll/public.js +17 -0
  216. package/node/components/useScroll/useScroll.d.ts +9 -0
  217. package/node/components/useScroll/useScroll.js +43 -0
  218. package/node/components/useSet/index.d.ts +1 -1
  219. package/node/components/useSet/index.js +15 -3
  220. package/node/components/useSet/public.d.ts +1 -1
  221. package/node/components/useSet/public.js +15 -3
  222. package/node/components/useSet/useSet.d.ts +14 -1
  223. package/node/components/useSet/useSet.js +27 -2
  224. package/node/components/useSize/index.d.ts +1 -0
  225. package/node/components/useSize/index.js +8 -0
  226. package/node/components/useSize/public.d.ts +1 -0
  227. package/node/components/useSize/public.js +8 -0
  228. package/node/components/useSize/useSize.d.ts +17 -0
  229. package/node/components/useSize/useSize.js +106 -0
  230. package/node/components/useToggle/useToggle.d.ts +1 -0
  231. package/node/components/useToggle/useToggle.js +1 -0
  232. package/node/components/useUpdateEffect/index.d.ts +1 -1
  233. package/node/components/useUpdateEffect/index.js +15 -3
  234. package/node/components/useUpdateEffect/public.d.ts +1 -1
  235. package/node/components/useUpdateEffect/public.js +15 -3
  236. package/node/components/useUpdateEffect/useUpdateEffect.d.ts +5 -1
  237. package/node/components/useUpdateEffect/useUpdateEffect.js +14 -2
  238. package/node/components/useWindowScroll/index.d.ts +1 -0
  239. package/node/components/useWindowScroll/index.js +17 -0
  240. package/node/components/useWindowScroll/public.d.ts +1 -0
  241. package/node/components/useWindowScroll/public.js +17 -0
  242. package/node/components/useWindowScroll/useWindowScroll.d.ts +8 -0
  243. package/node/components/useWindowScroll/useWindowScroll.js +44 -0
  244. package/node/components/utils/addEventListenerSafe/addEventListenerSafe.d.ts +1 -0
  245. package/node/components/utils/addEventListenerSafe/addEventListenerSafe.js +9 -0
  246. package/node/components/utils/addEventListenerSafe/index.d.ts +1 -0
  247. package/node/components/utils/addEventListenerSafe/index.js +17 -0
  248. package/node/components/utils/isBrowser/index.d.ts +1 -0
  249. package/node/components/utils/isBrowser/index.js +17 -0
  250. package/node/components/utils/isBrowser/isBrowser.d.ts +1 -0
  251. package/node/components/utils/isBrowser/isBrowser.js +4 -0
  252. package/node/components/utils/removeEventListenerSafe/index.d.ts +1 -0
  253. package/node/components/utils/removeEventListenerSafe/index.js +17 -0
  254. package/node/components/utils/removeEventListenerSafe/removeEventListenerSafe.d.ts +1 -0
  255. package/node/components/utils/removeEventListenerSafe/removeEventListenerSafe.js +9 -0
  256. package/node/components/utils/replaceRaf/constants.d.ts +1 -0
  257. package/node/components/utils/replaceRaf/constants.js +4 -0
  258. package/node/components/utils/replaceRaf/index.d.ts +1 -0
  259. package/node/components/utils/replaceRaf/index.js +17 -0
  260. package/node/components/utils/replaceRaf/replaceRaf.d.ts +18 -0
  261. package/node/components/utils/replaceRaf/replaceRaf.js +86 -0
  262. package/node/hook-form/FormPageLayoutBase/useLogic/useLogic.d.ts +1 -0
  263. package/package.json +1 -2
@@ -0,0 +1,42 @@
1
+ import { useMemo, useState } from 'react';
2
+ import { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect';
3
+ import { isBrowser } from '../utils/isBrowser';
4
+ const noop = () => { };
5
+ const defaultState = {
6
+ x: 0,
7
+ y: 0,
8
+ width: 0,
9
+ height: 0,
10
+ top: 0,
11
+ left: 0,
12
+ bottom: 0,
13
+ right: 0,
14
+ };
15
+ /**
16
+ * Хук отслеживает размеры HTML-элемента с помощью Resize Observer API.
17
+ * Принимает ref на HTML-элемент и возвращает объект с размерами элемента.
18
+ */
19
+ function useMeasure() {
20
+ const [element, ref] = useState(null);
21
+ const [rect, setRect] = useState(defaultState);
22
+ const observer = useMemo(() => new window.ResizeObserver((entries) => {
23
+ if (entries[0]) {
24
+ setRect(entries[0].contentRect);
25
+ }
26
+ }), []);
27
+ useIsomorphicLayoutEffect(() => {
28
+ if (!element) {
29
+ return;
30
+ }
31
+ observer.observe(element);
32
+ return () => {
33
+ observer.disconnect();
34
+ };
35
+ }, [element]);
36
+ return [ref, rect];
37
+ }
38
+ const useMeasureFallback = (() => [noop, defaultState]);
39
+ const useMeasureExport = isBrowser && typeof window.ResizeObserver !== 'undefined'
40
+ ? useMeasure
41
+ : useMeasureFallback;
42
+ export default useMeasureExport;
@@ -0,0 +1 @@
1
+ export * from './useNewToggle';
@@ -0,0 +1 @@
1
+ export * from './useNewToggle';
@@ -0,0 +1 @@
1
+ export * from './useNewToggle';
@@ -0,0 +1 @@
1
+ export * from './useNewToggle';
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Хук отслеживает значение типа boolean.
3
+ */
4
+ export declare const useNewToggle: (initialValue: boolean) => [boolean, (nextValue?: unknown) => void];
@@ -0,0 +1,8 @@
1
+ import { useReducer } from 'react';
2
+ const toggleReducer = (state, nextValue) => typeof nextValue === 'boolean' ? nextValue : !state;
3
+ /**
4
+ * Хук отслеживает значение типа boolean.
5
+ */
6
+ export const useNewToggle = (initialValue) => {
7
+ return useReducer(toggleReducer, initialValue);
8
+ };
@@ -0,0 +1 @@
1
+ export * from './useUnmount';
@@ -0,0 +1 @@
1
+ export * from './useUnmount';
@@ -0,0 +1 @@
1
+ export declare const useUnmount: (fn: () => void) => void;
@@ -0,0 +1,7 @@
1
+ import { useEffect, useRef } from 'react';
2
+ export const useUnmount = (fn) => {
3
+ const fnRef = useRef(fn);
4
+ // update the ref each render so if it change the newest callback will be invoked
5
+ fnRef.current = fn;
6
+ useEffect(() => () => fnRef.current(), []);
7
+ };
@@ -0,0 +1 @@
1
+ export * from './useRafState';
@@ -0,0 +1 @@
1
+ export * from './useRafState';
@@ -0,0 +1,2 @@
1
+ import { type Dispatch, type SetStateAction } from 'react';
2
+ export declare const useRafState: <TState>(initialState: TState | (() => TState)) => [TState, Dispatch<SetStateAction<TState>>];
@@ -0,0 +1,16 @@
1
+ import { useCallback, useRef, useState, } from 'react';
2
+ import { useUnmount } from './hooks/useUnmount';
3
+ export const useRafState = (initialState) => {
4
+ const frame = useRef(0);
5
+ const [state, setState] = useState(initialState);
6
+ const setRafState = useCallback((value) => {
7
+ cancelAnimationFrame(frame.current);
8
+ frame.current = requestAnimationFrame(() => {
9
+ setState(value);
10
+ });
11
+ }, []);
12
+ useUnmount(() => {
13
+ cancelAnimationFrame(frame.current);
14
+ });
15
+ return [state, setRafState];
16
+ };
@@ -0,0 +1 @@
1
+ export * from './useScroll';
@@ -0,0 +1 @@
1
+ export * from './useScroll';
@@ -0,0 +1 @@
1
+ export * from './useScroll';
@@ -0,0 +1 @@
1
+ export * from './useScroll';
@@ -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 { useSet } from './useSet';
1
+ export * from './useSet';
@@ -1 +1 @@
1
- export { useSet } from './useSet';
1
+ export * from './useSet';
@@ -1 +1 @@
1
- export { useSet } from './useSet';
1
+ export * from './useSet';
@@ -1 +1 @@
1
- export { useSet } from './useSet';
1
+ export * from './useSet';
@@ -1 +1,14 @@
1
- export { useSet } from 'react-use';
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
- export { useSet } from 'react-use';
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,5 +1,6 @@
1
1
  import { useState } from 'react';
2
2
  /**
3
+ * @deprecated
3
4
  * хук хранящий стейт активности, и предоставляющий методы переключения с проксируемыми аргументами, позволяет уменьшить бойлерплейт код
4
5
  */
5
6
  export const useToggle = (params) => {
@@ -1 +1 @@
1
- export { useUpdateEffect } from './useUpdateEffect';
1
+ export * from './useUpdateEffect';
@@ -1 +1 @@
1
- export { useUpdateEffect } from './useUpdateEffect';
1
+ export * from './useUpdateEffect';
@@ -1 +1 @@
1
- export { useUpdateEffect } from './useUpdateEffect';
1
+ export * from './useUpdateEffect';
@@ -1 +1 @@
1
- export { useUpdateEffect } from './useUpdateEffect';
1
+ export * from './useUpdateEffect';
@@ -1 +1,5 @@
1
- export { useUpdateEffect } from 'react-use';
1
+ import { useEffect } from 'react';
2
+ /**
3
+ * Хук, который выполняет эффект только после первого монтирования компонента.
4
+ */
5
+ export declare const useUpdateEffect: typeof useEffect;
@@ -1 +1,13 @@
1
- export { useUpdateEffect } from 'react-use';
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,8 @@
1
+ export interface IState {
2
+ x: number;
3
+ y: number;
4
+ }
5
+ /**
6
+ * Хук отслеживает позицию скролла в окне браузера.
7
+ */
8
+ export declare const useWindowScroll: () => IState;
@@ -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,5 @@
1
+ export function addEventListenerSafe(obj, ...args) {
2
+ if (obj?.addEventListener) {
3
+ obj.addEventListener(...args);
4
+ }
5
+ }
@@ -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,5 @@
1
+ export function removeEventListenerSafe(obj, ...args) {
2
+ if (obj?.removeEventListener) {
3
+ obj.removeEventListener(...args);
4
+ }
5
+ }
@@ -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 {};