@astral/ui 4.86.0 → 4.87.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (257) hide show
  1. package/components/NotificationList/ListItem/useLogic/useLogic.js +1 -1
  2. package/components/Select/Select.js +1 -1
  3. package/components/Select/useLogic/useLogic.d.ts +1 -1
  4. package/components/TagsList/types.d.ts +2 -2
  5. package/components/TagsList/useLogic/useLogic.js +16 -10
  6. package/components/TagsList/utils/getKey/getKey.js +4 -4
  7. package/components/createGlobalState/createGlobalState.d.ts +6 -0
  8. package/components/createGlobalState/createGlobalState.js +25 -0
  9. package/components/createGlobalState/index.d.ts +1 -0
  10. package/components/createGlobalState/index.js +1 -0
  11. package/components/createGlobalState/public.d.ts +1 -0
  12. package/components/createGlobalState/public.js +1 -0
  13. package/components/createGlobalState/utils/index.d.ts +1 -0
  14. package/components/createGlobalState/utils/index.js +1 -0
  15. package/components/createGlobalState/utils/resolveHookState/index.d.ts +1 -0
  16. package/components/createGlobalState/utils/resolveHookState/index.js +1 -0
  17. package/components/createGlobalState/utils/resolveHookState/resolveHookState.d.ts +4 -0
  18. package/components/createGlobalState/utils/resolveHookState/resolveHookState.js +8 -0
  19. package/components/createGlobalState/utils/types.d.ts +5 -0
  20. package/components/createGlobalState/utils/types.js +1 -0
  21. package/components/useDebounce/hooks/useTimeoutFn/index.d.ts +1 -0
  22. package/components/useDebounce/hooks/useTimeoutFn/index.js +1 -0
  23. package/components/useDebounce/hooks/useTimeoutFn/useTimeoutFn.d.ts +2 -0
  24. package/components/useDebounce/hooks/useTimeoutFn/useTimeoutFn.js +29 -0
  25. package/components/useDebounce/index.d.ts +1 -0
  26. package/components/useDebounce/index.js +1 -0
  27. package/components/useDebounce/public.d.ts +1 -0
  28. package/components/useDebounce/public.js +1 -0
  29. package/components/useDebounce/useDebounce.d.ts +6 -0
  30. package/components/useDebounce/useDebounce.js +10 -0
  31. package/components/useFirstMountState/index.d.ts +1 -1
  32. package/components/useFirstMountState/index.js +1 -1
  33. package/components/useFirstMountState/public.d.ts +1 -1
  34. package/components/useFirstMountState/public.js +1 -1
  35. package/components/useFirstMountState/useFirstMountState.d.ts +4 -1
  36. package/components/useFirstMountState/useFirstMountState.js +12 -1
  37. package/components/useIntersection/index.d.ts +1 -0
  38. package/components/useIntersection/index.js +1 -0
  39. package/components/useIntersection/public.d.ts +1 -0
  40. package/components/useIntersection/public.js +1 -0
  41. package/components/useIntersection/useIntersection.d.ts +5 -0
  42. package/components/useIntersection/useIntersection.js +22 -0
  43. package/components/useInterval/index.d.ts +1 -1
  44. package/components/useInterval/index.js +1 -1
  45. package/components/useInterval/public.d.ts +1 -1
  46. package/components/useInterval/public.js +1 -1
  47. package/components/useInterval/useInterval.d.ts +6 -1
  48. package/components/useInterval/useInterval.js +19 -1
  49. package/components/useIsomorphicLayoutEffect/index.d.ts +1 -0
  50. package/components/useIsomorphicLayoutEffect/index.js +1 -0
  51. package/components/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.d.ts +2 -0
  52. package/components/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js +5 -0
  53. package/components/useLocalStorage/index.d.ts +1 -1
  54. package/components/useLocalStorage/index.js +1 -1
  55. package/components/useLocalStorage/public.d.ts +1 -1
  56. package/components/useLocalStorage/public.js +1 -1
  57. package/components/useLocalStorage/useLocalStorage.d.ts +15 -1
  58. package/components/useLocalStorage/useLocalStorage.js +96 -1
  59. package/components/useMeasure/index.d.ts +1 -0
  60. package/components/useMeasure/index.js +1 -0
  61. package/components/useMeasure/public.d.ts +1 -0
  62. package/components/useMeasure/public.js +1 -0
  63. package/components/useMeasure/useMeasure.d.ts +13 -0
  64. package/components/useMeasure/useMeasure.js +42 -0
  65. package/components/useNewToggle/index.d.ts +1 -0
  66. package/components/useNewToggle/index.js +1 -0
  67. package/components/useNewToggle/public.d.ts +1 -0
  68. package/components/useNewToggle/public.js +1 -0
  69. package/components/useNewToggle/useNewToggle.d.ts +4 -0
  70. package/components/useNewToggle/useNewToggle.js +8 -0
  71. package/components/useRafState/hooks/useUnmount/index.d.ts +1 -0
  72. package/components/useRafState/hooks/useUnmount/index.js +1 -0
  73. package/components/useRafState/hooks/useUnmount/useUnmount.d.ts +1 -0
  74. package/components/useRafState/hooks/useUnmount/useUnmount.js +7 -0
  75. package/components/useRafState/index.d.ts +1 -0
  76. package/components/useRafState/index.js +1 -0
  77. package/components/useRafState/useRafState.d.ts +2 -0
  78. package/components/useRafState/useRafState.js +16 -0
  79. package/components/useScroll/index.d.ts +1 -0
  80. package/components/useScroll/index.js +1 -0
  81. package/components/useScroll/public.d.ts +1 -0
  82. package/components/useScroll/public.js +1 -0
  83. package/components/useScroll/useScroll.d.ts +9 -0
  84. package/components/useScroll/useScroll.js +39 -0
  85. package/components/useSet/index.d.ts +1 -1
  86. package/components/useSet/index.js +1 -1
  87. package/components/useSet/public.d.ts +1 -1
  88. package/components/useSet/public.js +1 -1
  89. package/components/useSet/useSet.d.ts +14 -1
  90. package/components/useSet/useSet.js +26 -1
  91. package/components/useSize/index.d.ts +1 -0
  92. package/components/useSize/index.js +1 -0
  93. package/components/useSize/public.d.ts +1 -0
  94. package/components/useSize/public.js +1 -0
  95. package/components/useSize/useSize.d.ts +17 -0
  96. package/components/useSize/useSize.js +79 -0
  97. package/components/useToggle/useToggle.d.ts +1 -0
  98. package/components/useToggle/useToggle.js +1 -0
  99. package/components/useUpdateEffect/index.d.ts +1 -1
  100. package/components/useUpdateEffect/index.js +1 -1
  101. package/components/useUpdateEffect/public.d.ts +1 -1
  102. package/components/useUpdateEffect/public.js +1 -1
  103. package/components/useUpdateEffect/useUpdateEffect.d.ts +5 -1
  104. package/components/useUpdateEffect/useUpdateEffect.js +13 -1
  105. package/components/useWindowScroll/index.d.ts +1 -0
  106. package/components/useWindowScroll/index.js +1 -0
  107. package/components/useWindowScroll/public.d.ts +1 -0
  108. package/components/useWindowScroll/public.js +1 -0
  109. package/components/useWindowScroll/useWindowScroll.d.ts +8 -0
  110. package/components/useWindowScroll/useWindowScroll.js +40 -0
  111. package/components/utils/addEventListenerSafe/addEventListenerSafe.d.ts +1 -0
  112. package/components/utils/addEventListenerSafe/addEventListenerSafe.js +5 -0
  113. package/components/utils/addEventListenerSafe/index.d.ts +1 -0
  114. package/components/utils/addEventListenerSafe/index.js +1 -0
  115. package/components/utils/isBrowser/index.d.ts +1 -0
  116. package/components/utils/isBrowser/index.js +1 -0
  117. package/components/utils/isBrowser/isBrowser.d.ts +1 -0
  118. package/components/utils/isBrowser/isBrowser.js +1 -0
  119. package/components/utils/removeEventListenerSafe/index.d.ts +1 -0
  120. package/components/utils/removeEventListenerSafe/index.js +1 -0
  121. package/components/utils/removeEventListenerSafe/removeEventListenerSafe.d.ts +1 -0
  122. package/components/utils/removeEventListenerSafe/removeEventListenerSafe.js +5 -0
  123. package/components/utils/replaceRaf/constants.d.ts +1 -0
  124. package/components/utils/replaceRaf/constants.js +1 -0
  125. package/components/utils/replaceRaf/index.d.ts +1 -0
  126. package/components/utils/replaceRaf/index.js +1 -0
  127. package/components/utils/replaceRaf/replaceRaf.d.ts +18 -0
  128. package/components/utils/replaceRaf/replaceRaf.js +81 -0
  129. package/node/components/NotificationList/ListItem/useLogic/useLogic.js +2 -2
  130. package/node/components/Select/Select.js +1 -1
  131. package/node/components/Select/useLogic/useLogic.d.ts +1 -1
  132. package/node/components/TagsList/types.d.ts +2 -2
  133. package/node/components/TagsList/useLogic/useLogic.js +16 -10
  134. package/node/components/TagsList/utils/getKey/getKey.js +4 -4
  135. package/node/components/createGlobalState/createGlobalState.d.ts +6 -0
  136. package/node/components/createGlobalState/createGlobalState.js +29 -0
  137. package/node/components/createGlobalState/index.d.ts +1 -0
  138. package/node/components/createGlobalState/index.js +17 -0
  139. package/node/components/createGlobalState/public.d.ts +1 -0
  140. package/node/components/createGlobalState/public.js +17 -0
  141. package/node/components/createGlobalState/utils/index.d.ts +1 -0
  142. package/node/components/createGlobalState/utils/index.js +17 -0
  143. package/node/components/createGlobalState/utils/resolveHookState/index.d.ts +1 -0
  144. package/node/components/createGlobalState/utils/resolveHookState/index.js +17 -0
  145. package/node/components/createGlobalState/utils/resolveHookState/resolveHookState.d.ts +4 -0
  146. package/node/components/createGlobalState/utils/resolveHookState/resolveHookState.js +12 -0
  147. package/node/components/createGlobalState/utils/types.d.ts +5 -0
  148. package/node/components/createGlobalState/utils/types.js +2 -0
  149. package/node/components/useDebounce/hooks/useTimeoutFn/index.d.ts +1 -0
  150. package/node/components/useDebounce/hooks/useTimeoutFn/index.js +17 -0
  151. package/node/components/useDebounce/hooks/useTimeoutFn/useTimeoutFn.d.ts +2 -0
  152. package/node/components/useDebounce/hooks/useTimeoutFn/useTimeoutFn.js +33 -0
  153. package/node/components/useDebounce/index.d.ts +1 -0
  154. package/node/components/useDebounce/index.js +17 -0
  155. package/node/components/useDebounce/public.d.ts +1 -0
  156. package/node/components/useDebounce/public.js +17 -0
  157. package/node/components/useDebounce/useDebounce.d.ts +6 -0
  158. package/node/components/useDebounce/useDebounce.js +14 -0
  159. package/node/components/useFirstMountState/index.d.ts +1 -1
  160. package/node/components/useFirstMountState/index.js +15 -3
  161. package/node/components/useFirstMountState/public.d.ts +1 -1
  162. package/node/components/useFirstMountState/public.js +15 -3
  163. package/node/components/useFirstMountState/useFirstMountState.d.ts +4 -1
  164. package/node/components/useFirstMountState/useFirstMountState.js +13 -2
  165. package/node/components/useIntersection/index.d.ts +1 -0
  166. package/node/components/useIntersection/index.js +17 -0
  167. package/node/components/useIntersection/public.d.ts +1 -0
  168. package/node/components/useIntersection/public.js +17 -0
  169. package/node/components/useIntersection/useIntersection.d.ts +5 -0
  170. package/node/components/useIntersection/useIntersection.js +26 -0
  171. package/node/components/useInterval/index.d.ts +1 -1
  172. package/node/components/useInterval/index.js +15 -3
  173. package/node/components/useInterval/public.d.ts +1 -1
  174. package/node/components/useInterval/public.js +15 -3
  175. package/node/components/useInterval/useInterval.d.ts +6 -1
  176. package/node/components/useInterval/useInterval.js +20 -2
  177. package/node/components/useIsomorphicLayoutEffect/index.d.ts +1 -0
  178. package/node/components/useIsomorphicLayoutEffect/index.js +17 -0
  179. package/node/components/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.d.ts +2 -0
  180. package/node/components/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js +8 -0
  181. package/node/components/useLocalStorage/index.d.ts +1 -1
  182. package/node/components/useLocalStorage/index.js +5 -14
  183. package/node/components/useLocalStorage/public.d.ts +1 -1
  184. package/node/components/useLocalStorage/public.js +5 -14
  185. package/node/components/useLocalStorage/useLocalStorage.d.ts +15 -1
  186. package/node/components/useLocalStorage/useLocalStorage.js +97 -2
  187. package/node/components/useMeasure/index.d.ts +1 -0
  188. package/node/components/useMeasure/index.js +8 -0
  189. package/node/components/useMeasure/public.d.ts +1 -0
  190. package/node/components/useMeasure/public.js +8 -0
  191. package/node/components/useMeasure/useMeasure.d.ts +13 -0
  192. package/node/components/useMeasure/useMeasure.js +44 -0
  193. package/node/components/useNewToggle/index.d.ts +1 -0
  194. package/node/components/useNewToggle/index.js +17 -0
  195. package/node/components/useNewToggle/public.d.ts +1 -0
  196. package/node/components/useNewToggle/public.js +17 -0
  197. package/node/components/useNewToggle/useNewToggle.d.ts +4 -0
  198. package/node/components/useNewToggle/useNewToggle.js +12 -0
  199. package/node/components/useRafState/hooks/useUnmount/index.d.ts +1 -0
  200. package/node/components/useRafState/hooks/useUnmount/index.js +17 -0
  201. package/node/components/useRafState/hooks/useUnmount/useUnmount.d.ts +1 -0
  202. package/node/components/useRafState/hooks/useUnmount/useUnmount.js +11 -0
  203. package/node/components/useRafState/index.d.ts +1 -0
  204. package/node/components/useRafState/index.js +17 -0
  205. package/node/components/useRafState/useRafState.d.ts +2 -0
  206. package/node/components/useRafState/useRafState.js +20 -0
  207. package/node/components/useScroll/index.d.ts +1 -0
  208. package/node/components/useScroll/index.js +17 -0
  209. package/node/components/useScroll/public.d.ts +1 -0
  210. package/node/components/useScroll/public.js +17 -0
  211. package/node/components/useScroll/useScroll.d.ts +9 -0
  212. package/node/components/useScroll/useScroll.js +43 -0
  213. package/node/components/useSet/index.d.ts +1 -1
  214. package/node/components/useSet/index.js +15 -3
  215. package/node/components/useSet/public.d.ts +1 -1
  216. package/node/components/useSet/public.js +15 -3
  217. package/node/components/useSet/useSet.d.ts +14 -1
  218. package/node/components/useSet/useSet.js +27 -2
  219. package/node/components/useSize/index.d.ts +1 -0
  220. package/node/components/useSize/index.js +8 -0
  221. package/node/components/useSize/public.d.ts +1 -0
  222. package/node/components/useSize/public.js +8 -0
  223. package/node/components/useSize/useSize.d.ts +17 -0
  224. package/node/components/useSize/useSize.js +106 -0
  225. package/node/components/useToggle/useToggle.d.ts +1 -0
  226. package/node/components/useToggle/useToggle.js +1 -0
  227. package/node/components/useUpdateEffect/index.d.ts +1 -1
  228. package/node/components/useUpdateEffect/index.js +15 -3
  229. package/node/components/useUpdateEffect/public.d.ts +1 -1
  230. package/node/components/useUpdateEffect/public.js +15 -3
  231. package/node/components/useUpdateEffect/useUpdateEffect.d.ts +5 -1
  232. package/node/components/useUpdateEffect/useUpdateEffect.js +14 -2
  233. package/node/components/useWindowScroll/index.d.ts +1 -0
  234. package/node/components/useWindowScroll/index.js +17 -0
  235. package/node/components/useWindowScroll/public.d.ts +1 -0
  236. package/node/components/useWindowScroll/public.js +17 -0
  237. package/node/components/useWindowScroll/useWindowScroll.d.ts +8 -0
  238. package/node/components/useWindowScroll/useWindowScroll.js +44 -0
  239. package/node/components/utils/addEventListenerSafe/addEventListenerSafe.d.ts +1 -0
  240. package/node/components/utils/addEventListenerSafe/addEventListenerSafe.js +9 -0
  241. package/node/components/utils/addEventListenerSafe/index.d.ts +1 -0
  242. package/node/components/utils/addEventListenerSafe/index.js +17 -0
  243. package/node/components/utils/isBrowser/index.d.ts +1 -0
  244. package/node/components/utils/isBrowser/index.js +17 -0
  245. package/node/components/utils/isBrowser/isBrowser.d.ts +1 -0
  246. package/node/components/utils/isBrowser/isBrowser.js +4 -0
  247. package/node/components/utils/removeEventListenerSafe/index.d.ts +1 -0
  248. package/node/components/utils/removeEventListenerSafe/index.js +17 -0
  249. package/node/components/utils/removeEventListenerSafe/removeEventListenerSafe.d.ts +1 -0
  250. package/node/components/utils/removeEventListenerSafe/removeEventListenerSafe.js +9 -0
  251. package/node/components/utils/replaceRaf/constants.d.ts +1 -0
  252. package/node/components/utils/replaceRaf/constants.js +4 -0
  253. package/node/components/utils/replaceRaf/index.d.ts +1 -0
  254. package/node/components/utils/replaceRaf/index.js +17 -0
  255. package/node/components/utils/replaceRaf/replaceRaf.d.ts +18 -0
  256. package/node/components/utils/replaceRaf/replaceRaf.js +86 -0
  257. package/package.json +1 -2
@@ -1,5 +1,5 @@
1
1
  import { useEffect, useRef } from 'react';
2
- import { useIntersection } from 'react-use';
2
+ import { useIntersection } from '../../../useIntersection';
3
3
  export const useLogic = ({ id, onDelete, onViewNotification, isUnread, }) => {
4
4
  const ref = useRef(null);
5
5
  const entry = useIntersection(ref, {
@@ -34,7 +34,7 @@ const SelectInner = ({ required, getOptionLabel, placeholder, helperText, hideHe
34
34
  const renderValue = (selectedOptions) => {
35
35
  // Массив с выбранными опциями
36
36
  if (Array.isArray(selectedOptions) && selectedOptions.length) {
37
- return (_jsx(TagsList, { data: selectedOptions, keyId: "value", getOptionLabel: getOptionLabel || ((optionLabel) => optionLabel), onChange: handleChangeArrayValue, onClick: openSelect }));
37
+ return (_jsx(TagsList, { data: selectedOptions, getOptionLabel: getOptionLabel || ((optionLabel) => optionLabel), onChange: handleChangeArrayValue, onClick: openSelect }));
38
38
  }
39
39
  // Пустой массив или пустая строка
40
40
  if ((Array.isArray(selectedOptions) || typeof selectedOptions === 'string') &&
@@ -13,7 +13,7 @@ export declare const useLogic: <TValue>({ value, onChange, children, open: exter
13
13
  isSelectedAll: boolean | undefined;
14
14
  isIndeterminate: boolean | undefined;
15
15
  optionsLength: number | null;
16
- handleChangeArrayValue: (inputValue: TValue[] | undefined) => void | undefined;
16
+ handleChangeArrayValue: (inputValue: unknown[] | undefined) => void | undefined;
17
17
  selectAllClassName: string | undefined;
18
18
  findMenuItemsLabel: (nodes: ReactNode, selectedValue: TValue) => ReactNode;
19
19
  isShowingPlaceholder: boolean;
@@ -1,5 +1,5 @@
1
1
  import { type MouseEvent, type RefObject } from 'react';
2
- export type TagValue = string | Record<string, unknown>;
2
+ export type TagValue = string | number | Record<string, unknown>;
3
3
  export type TagsListProps<TData extends TagValue = TagValue> = {
4
4
  /**
5
5
  * Название класса, применяется к корневому компоненту
@@ -17,7 +17,7 @@ export type TagsListProps<TData extends TagValue = TagValue> = {
17
17
  * Поле, используемое в качестве ключа списка.
18
18
  * Если не передано, для генерации ключа будет использоваться getOptionLabel
19
19
  */
20
- keyId?: TData extends string ? never : keyof TData;
20
+ keyId?: TData extends object ? keyof TData : never;
21
21
  /**
22
22
  * Используется для определения строкового значения опции
23
23
  */
@@ -79,19 +79,25 @@ export const useLogic = ({ data = [], keyId, getOptionLabel, onChange, inputCont
79
79
  resizeObserver.disconnect();
80
80
  };
81
81
  }, [data]);
82
+ /**
83
+ * Возвращает значение, по которому определяется идентичность тегов.
84
+ * Для примитивов сравнение идет по самому значению, keyId применим только к объектам
85
+ */
86
+ const getComparableValue = (option) => {
87
+ if (typeof option !== 'object' || option === null) {
88
+ return option;
89
+ }
90
+ if (keyId) {
91
+ return option[keyId];
92
+ }
93
+ return getOptionLabel(option);
94
+ };
82
95
  const getTagProps = (option) => {
83
96
  const label = getOptionLabel(option);
84
97
  const onDelete = () => {
85
- const newValue = data.filter((value) => {
86
- if (typeof value === 'string') {
87
- return value !== option;
88
- }
89
- if (keyId) {
90
- return value[keyId] !== option[keyId];
91
- }
92
- return getOptionLabel(value) !== getOptionLabel(option);
93
- });
94
- onChange(newValue.length ? newValue : []);
98
+ const deletedValue = getComparableValue(option);
99
+ const newValue = data.filter((value) => getComparableValue(value) !== deletedValue);
100
+ onChange(newValue);
95
101
  };
96
102
  return { label, shrinks: false, onDelete };
97
103
  };
@@ -1,10 +1,10 @@
1
1
  export const getKey = (option, keyId, getOptionLabel) => {
2
- if (typeof option === 'string') {
3
- return option;
2
+ const isObjectOption = typeof option === 'object' && option !== null;
3
+ if (!isObjectOption) {
4
+ return String(option);
4
5
  }
5
6
  if (keyId) {
6
- const key = option[keyId];
7
- return typeof key === 'number' ? key.toString() : key;
7
+ return String(option[keyId]);
8
8
  }
9
9
  return getOptionLabel(option).toString();
10
10
  };
@@ -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,25 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect';
3
+ import { resolveHookState } from './utils/resolveHookState';
4
+ export function createGlobalState(initialState) {
5
+ const store = {
6
+ state: initialState instanceof Function ? initialState() : initialState,
7
+ setState(nextState) {
8
+ store.state = resolveHookState(nextState, store.state);
9
+ store.setters.forEach((setter) => setter(store.state));
10
+ },
11
+ setters: [],
12
+ };
13
+ return () => {
14
+ const [globalState, stateSetter] = useState(store.state);
15
+ useEffect(() => () => {
16
+ store.setters = store.setters.filter((setter) => setter !== stateSetter);
17
+ }, []);
18
+ useIsomorphicLayoutEffect(() => {
19
+ if (!store.setters.includes(stateSetter)) {
20
+ store.setters.push(stateSetter);
21
+ }
22
+ });
23
+ return [globalState, store.setState];
24
+ };
25
+ }
@@ -0,0 +1 @@
1
+ export * from './createGlobalState';
@@ -0,0 +1 @@
1
+ export * from './createGlobalState';
@@ -0,0 +1 @@
1
+ export * from './createGlobalState';
@@ -0,0 +1 @@
1
+ export * from './createGlobalState';
@@ -0,0 +1 @@
1
+ export * from './resolveHookState';
@@ -0,0 +1 @@
1
+ export * from './resolveHookState';
@@ -0,0 +1 @@
1
+ export * from './resolveHookState';
@@ -0,0 +1 @@
1
+ export * from './resolveHookState';
@@ -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,8 @@
1
+ export function resolveHookState(nextState, currentState) {
2
+ if (typeof nextState === 'function') {
3
+ return nextState.length
4
+ ? nextState(currentState)
5
+ : nextState();
6
+ }
7
+ return nextState;
8
+ }
@@ -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 {};
@@ -0,0 +1 @@
1
+ export * from './useTimeoutFn';
@@ -0,0 +1 @@
1
+ export * from './useTimeoutFn';
@@ -0,0 +1,2 @@
1
+ export type UseTimeoutFnReturn = [() => boolean | null, () => void, () => void];
2
+ export declare function useTimeoutFn(fn: Function, ms?: number): UseTimeoutFnReturn;
@@ -0,0 +1,29 @@
1
+ import { useCallback, useEffect, useRef } from 'react';
2
+ export function useTimeoutFn(fn, ms = 0) {
3
+ const ready = useRef(false);
4
+ const timeout = useRef(null);
5
+ const callback = useRef(fn);
6
+ const isReady = useCallback(() => ready.current, []);
7
+ const set = useCallback(() => {
8
+ ready.current = false;
9
+ timeout.current && clearTimeout(timeout.current);
10
+ timeout.current = setTimeout(() => {
11
+ ready.current = true;
12
+ callback.current();
13
+ }, ms);
14
+ }, [ms]);
15
+ const clear = useCallback(() => {
16
+ ready.current = null;
17
+ timeout.current && clearTimeout(timeout.current);
18
+ }, []);
19
+ // update ref when function changes
20
+ useEffect(() => {
21
+ callback.current = fn;
22
+ }, [fn]);
23
+ // set on mount, clear on unmount
24
+ useEffect(() => {
25
+ set();
26
+ return clear;
27
+ }, [ms]);
28
+ return [isReady, clear, set];
29
+ }
@@ -0,0 +1 @@
1
+ export * from './useDebounce';
@@ -0,0 +1 @@
1
+ export * from './useDebounce';
@@ -0,0 +1 @@
1
+ export * from './useDebounce';
@@ -0,0 +1 @@
1
+ export * from './useDebounce';
@@ -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,10 @@
1
+ import { useEffect } from 'react';
2
+ import { useTimeoutFn } from './hooks/useTimeoutFn';
3
+ /**
4
+ * Хук откладывает вызов функции, пока не пройдет переданное число миллисекунд после последнего вызова debounce-функции.
5
+ */
6
+ export function useDebounce(fn, ms = 0, deps = []) {
7
+ const [isReady, cancel, reset] = useTimeoutFn(fn, ms);
8
+ useEffect(reset, deps);
9
+ return [isReady, cancel];
10
+ }
@@ -1 +1 @@
1
- export { useFirstMountState } from './useFirstMountState';
1
+ export * from './useFirstMountState';
@@ -1 +1 @@
1
- export { useFirstMountState } from './useFirstMountState';
1
+ export * from './useFirstMountState';
@@ -1 +1 @@
1
- export { useFirstMountState } from './useFirstMountState';
1
+ export * from './useFirstMountState';
@@ -1 +1 @@
1
- export { useFirstMountState } from './useFirstMountState';
1
+ export * from './useFirstMountState';
@@ -1 +1,4 @@
1
- export { useFirstMountState } from 'react-use';
1
+ /**
2
+ * Хук возвращает true если компонент только монтировался (при первом рендере) и false в другом случае.
3
+ */
4
+ export declare function useFirstMountState(): boolean;
@@ -1 +1,12 @@
1
- export { useFirstMountState } from 'react-use';
1
+ import { useRef } from 'react';
2
+ /**
3
+ * Хук возвращает true если компонент только монтировался (при первом рендере) и false в другом случае.
4
+ */
5
+ export function useFirstMountState() {
6
+ const isFirst = useRef(true);
7
+ if (isFirst.current) {
8
+ isFirst.current = false;
9
+ return true;
10
+ }
11
+ return isFirst.current;
12
+ }
@@ -0,0 +1 @@
1
+ export * from './useIntersection';
@@ -0,0 +1 @@
1
+ export * from './useIntersection';
@@ -0,0 +1 @@
1
+ export * from './useIntersection';
@@ -0,0 +1 @@
1
+ export * from './useIntersection';
@@ -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,22 @@
1
+ import { useEffect, useState } from 'react';
2
+ /**
3
+ * Хук отслеживает изменения в пересечении целевого элемента с родительским элементом или с верхним уровнем области просмотра документа.
4
+ */
5
+ export const useIntersection = (ref, options) => {
6
+ const [intersectionObserverEntry, setIntersectionObserverEntry] = useState(null);
7
+ useEffect(() => {
8
+ if (ref.current && typeof IntersectionObserver === 'function') {
9
+ const handler = (entries) => {
10
+ setIntersectionObserverEntry(entries[0]);
11
+ };
12
+ const observer = new IntersectionObserver(handler, options);
13
+ observer.observe(ref.current);
14
+ return () => {
15
+ setIntersectionObserverEntry(null);
16
+ observer.disconnect();
17
+ };
18
+ }
19
+ return () => { };
20
+ }, [ref.current, options.threshold, options.root, options.rootMargin]);
21
+ return intersectionObserverEntry;
22
+ };
@@ -1 +1 @@
1
- export { useInterval } from './useInterval';
1
+ export * from './useInterval';
@@ -1 +1 @@
1
- export { useInterval } from './useInterval';
1
+ export * from './useInterval';
@@ -1 +1 @@
1
- export { useInterval } from './useInterval';
1
+ export * from './useInterval';
@@ -1 +1 @@
1
- export { useInterval } from './useInterval';
1
+ export * from './useInterval';
@@ -1 +1,6 @@
1
- export { useInterval } from 'react-use';
1
+ /**
2
+ * Хук для запуска функции с заданным интервалом.
3
+ * Если передать null, интервал не будет запущен (или будет остановлен).
4
+ * Если значение не указано (undefined), используется задержка 0 мс.
5
+ */
6
+ export declare const useInterval: (callback: Function, delay?: number | null) => void;
@@ -1 +1,19 @@
1
- export { useInterval } from 'react-use';
1
+ import { useEffect, useRef } from 'react';
2
+ /**
3
+ * Хук для запуска функции с заданным интервалом.
4
+ * Если передать null, интервал не будет запущен (или будет остановлен).
5
+ * Если значение не указано (undefined), используется задержка 0 мс.
6
+ */
7
+ export const useInterval = (callback, delay) => {
8
+ const savedCallback = useRef(() => { });
9
+ useEffect(() => {
10
+ savedCallback.current = callback;
11
+ });
12
+ useEffect(() => {
13
+ if (delay !== null) {
14
+ const interval = setInterval(() => savedCallback.current(), delay || 0);
15
+ return () => clearInterval(interval);
16
+ }
17
+ return undefined;
18
+ }, [delay]);
19
+ };
@@ -0,0 +1 @@
1
+ export * from './useIsomorphicLayoutEffect';
@@ -0,0 +1 @@
1
+ export * from './useIsomorphicLayoutEffect';
@@ -0,0 +1,2 @@
1
+ import { useEffect } from 'react';
2
+ export declare const useIsomorphicLayoutEffect: typeof useEffect;
@@ -0,0 +1,5 @@
1
+ import { useEffect, useLayoutEffect } from 'react';
2
+ import { isBrowser } from '../utils/isBrowser';
3
+ export const useIsomorphicLayoutEffect = isBrowser
4
+ ? useLayoutEffect
5
+ : useEffect;
@@ -1 +1 @@
1
- export * from './useLocalStorage';
1
+ export { default as useLocalStorage } from './useLocalStorage';
@@ -1 +1 @@
1
- export * from './useLocalStorage';
1
+ export { default as useLocalStorage } from './useLocalStorage';
@@ -1 +1 @@
1
- export * from './useLocalStorage';
1
+ export { default as useLocalStorage } from './useLocalStorage';
@@ -1 +1 @@
1
- export * from './useLocalStorage';
1
+ export { default as useLocalStorage } from './useLocalStorage';
@@ -1 +1,15 @@
1
- export { useLocalStorage } from 'react-use';
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 +1,96 @@
1
- export { useLocalStorage } from 'react-use';
1
+ import { useCallback, useLayoutEffect, useRef, useState, } from 'react';
2
+ import { isBrowser } from '../utils/isBrowser';
3
+ const noop = () => { };
4
+ /**
5
+ * Хук управляет состоянием, которое синхронизируется с localStorage браузера.
6
+ * Возвращает текущее значение, функцию для его обновления и функцию для удаления значения из localStorage.
7
+ */
8
+ export const useLocalStorage = (key, initialValue, options) => {
9
+ if (!key) {
10
+ throw new Error('useLocalStorage key may not be falsy');
11
+ }
12
+ const deserializer = (() => {
13
+ if (!options) {
14
+ return JSON.parse;
15
+ }
16
+ if (options.raw) {
17
+ return (value) => value;
18
+ }
19
+ return options.deserializer;
20
+ })();
21
+ const serializer = (() => {
22
+ if (!options) {
23
+ return JSON.stringify;
24
+ }
25
+ if (options.raw) {
26
+ return String;
27
+ }
28
+ return options.serializer;
29
+ })();
30
+ const initializer = useRef((newKey) => {
31
+ try {
32
+ const localStorageValue = localStorage.getItem(newKey);
33
+ if (localStorageValue !== null) {
34
+ return deserializer(localStorageValue);
35
+ }
36
+ if (initialValue) {
37
+ localStorage.setItem(newKey, serializer(initialValue));
38
+ }
39
+ return initialValue;
40
+ }
41
+ catch {
42
+ // If user is in private mode or has storage restriction
43
+ // localStorage can throw. JSON.parse and JSON.stringify
44
+ // can throw, too.
45
+ return initialValue;
46
+ }
47
+ });
48
+ const [state, setState] = useState(() => initializer.current(key));
49
+ useLayoutEffect(() => setState(initializer.current(key)), [key]);
50
+ const serializeValue = (value, parserOptions) => {
51
+ if (!parserOptions) {
52
+ return JSON.stringify(value);
53
+ }
54
+ if (parserOptions.raw) {
55
+ return typeof value === 'string' ? value : JSON.stringify(value);
56
+ }
57
+ return parserOptions.serializer(value);
58
+ };
59
+ const set = useCallback((valOrFunc) => {
60
+ try {
61
+ const newState = typeof valOrFunc === 'function'
62
+ ? valOrFunc(state)
63
+ : valOrFunc;
64
+ if (typeof newState === 'undefined') {
65
+ return;
66
+ }
67
+ const value = serializeValue(newState, options);
68
+ localStorage.setItem(key, value);
69
+ setState(deserializer(value));
70
+ }
71
+ catch {
72
+ // If user is in private mode or has storage restriction
73
+ // localStorage can throw. Also JSON.stringify can throw.
74
+ }
75
+ }, [key, setState]);
76
+ const remove = useCallback(() => {
77
+ try {
78
+ localStorage.removeItem(key);
79
+ setState(undefined);
80
+ }
81
+ catch {
82
+ // If user is in private mode or has storage restriction
83
+ // localStorage can throw.
84
+ }
85
+ }, [key, setState]);
86
+ return [state, set, remove];
87
+ };
88
+ const useLocalStorageFallback = ((initialValue) => [
89
+ initialValue,
90
+ noop,
91
+ noop,
92
+ ]);
93
+ const useLocalStorageExport = isBrowser
94
+ ? useLocalStorage
95
+ : useLocalStorageFallback;
96
+ export default useLocalStorageExport;
@@ -0,0 +1 @@
1
+ export { default as useMeasure } from './useMeasure';
@@ -0,0 +1 @@
1
+ export { default as useMeasure } from './useMeasure';
@@ -0,0 +1 @@
1
+ export { default as useMeasure } from './useMeasure';
@@ -0,0 +1 @@
1
+ export { default as useMeasure } from './useMeasure';
@@ -0,0 +1,13 @@
1
+ export type UseMeasureRect = Pick<DOMRectReadOnly, 'x' | 'y' | 'top' | 'left' | 'right' | 'bottom' | 'height' | 'width'>;
2
+ export type UseMeasureRef<TElement extends Element = Element> = (element: TElement) => void;
3
+ export type UseMeasureResult<TElement extends Element = Element> = [
4
+ UseMeasureRef<TElement>,
5
+ UseMeasureRect
6
+ ];
7
+ /**
8
+ * Хук отслеживает размеры HTML-элемента с помощью Resize Observer API.
9
+ * Принимает ref на HTML-элемент и возвращает объект с размерами элемента.
10
+ */
11
+ declare function useMeasure<TElement extends Element = Element>(): UseMeasureResult<TElement>;
12
+ declare const useMeasureExport: typeof useMeasure;
13
+ export default useMeasureExport;
@@ -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';