@onepercentio/one-ui 0.29.2 → 0.29.5

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 (289) hide show
  1. package/dist/components/Switch/Switch.d.ts +1 -1
  2. package/dist/components/Switch/Switch.js +1 -1
  3. package/dist/hooks/useHero.js +3 -2
  4. package/dist-ts/components/Switch/Switch.d.ts +1 -1
  5. package/dist-ts/hooks/useHero.js +5 -4
  6. package/dist-ts/hooks/useHero.js.map +1 -1
  7. package/package.json +5 -1
  8. package/src/assets/img/svg/checkbox.svg +0 -3
  9. package/src/assets/styles/index.scss +0 -2
  10. package/src/assets/styles/mixins.scss +0 -12
  11. package/src/assets/styles/variables.scss +0 -49
  12. package/src/components/AdaptiveButton/AdaptiveButton.module.scss +0 -7
  13. package/src/components/AdaptiveButton/AdaptiveButton.tsx +0 -26
  14. package/src/components/AdaptiveButton/index.tsx +0 -2
  15. package/src/components/AdaptiveContainer/AdaptiveContainer.module.scss +0 -53
  16. package/src/components/AdaptiveContainer/AdaptiveContainer.tsx +0 -200
  17. package/src/components/AdaptiveContainer/index.tsx +0 -2
  18. package/src/components/AdaptiveDialog/AdaptiveDialog.module.scss +0 -147
  19. package/src/components/AdaptiveDialog/AdaptiveDialog.tsx +0 -97
  20. package/src/components/AdaptiveDialog/index.tsx +0 -2
  21. package/src/components/AdaptiveSidebar/AdaptiveSidebar.module.scss +0 -49
  22. package/src/components/AdaptiveSidebar/AdaptiveSidebar.sample.tsx +0 -10
  23. package/src/components/AdaptiveSidebar/AdaptiveSidebar.tsx +0 -123
  24. package/src/components/AdaptiveSidebar/index.tsx +0 -2
  25. package/src/components/AnchoredTooltip/AnchoredTooltip.module.scss +0 -64
  26. package/src/components/AnchoredTooltip/AnchoredTooltip.tsx +0 -250
  27. package/src/components/AnchoredTooltip/index.tsx +0 -2
  28. package/src/components/AnimatedEntrance/AnimatedEntrance.module.scss +0 -108
  29. package/src/components/AnimatedEntrance/AnimatedEntrance.tsx +0 -227
  30. package/src/components/AnimatedEntrance/index.tsx +0 -2
  31. package/src/components/AsyncWrapper/AsyncWrapper.tsx +0 -38
  32. package/src/components/AsyncWrapper/index.tsx +0 -2
  33. package/src/components/Avatar/Avatar.module.scss +0 -22
  34. package/src/components/Avatar/Avatar.tsx +0 -31
  35. package/src/components/Avatar/index.tsx +0 -2
  36. package/src/components/BucketFill/BucketFill.module.scss +0 -36
  37. package/src/components/BucketFill/BucketFill.tsx +0 -65
  38. package/src/components/BucketFill/index.tsx +0 -2
  39. package/src/components/Button/Button.module.scss +0 -45
  40. package/src/components/Button/Button.tsx +0 -40
  41. package/src/components/Button/index.tsx +0 -2
  42. package/src/components/Card/Card.module.scss +0 -12
  43. package/src/components/Card/Card.tsx +0 -9
  44. package/src/components/Card/index.tsx +0 -2
  45. package/src/components/Chart/Chart.e2e.ts +0 -4
  46. package/src/components/Chart/Chart.logic.tsx +0 -8
  47. package/src/components/Chart/Chart.module.scss +0 -58
  48. package/src/components/Chart/Chart.tsx +0 -2
  49. package/src/components/Chart/Chart.types.ts +0 -35
  50. package/src/components/Chart/Chart.view.tsx +0 -241
  51. package/src/components/Chart/index.tsx +0 -2
  52. package/src/components/CheckBox/CheckBox.module.scss +0 -36
  53. package/src/components/CheckBox/CheckBox.tsx +0 -63
  54. package/src/components/CheckBox/index.tsx +0 -2
  55. package/src/components/CodeInput/CodeInput.module.scss +0 -5
  56. package/src/components/CodeInput/CodeInput.tsx +0 -84
  57. package/src/components/CodeInput/index.tsx +0 -2
  58. package/src/components/Collapsable/Collapsable.module.scss +0 -42
  59. package/src/components/Collapsable/Collapsable.tsx +0 -253
  60. package/src/components/Collapsable/index.tsx +0 -2
  61. package/src/components/Countdown/Countdown.tsx +0 -130
  62. package/src/components/Countdown/index.tsx +0 -2
  63. package/src/components/CurrencyInput/CurrencyInput.hook.ts +0 -37
  64. package/src/components/CurrencyInput/CurrencyInput.tsx +0 -25
  65. package/src/components/CurrencyInput/index.tsx +0 -2
  66. package/src/components/Divider/Divider.module.scss +0 -7
  67. package/src/components/Divider/Divider.tsx +0 -13
  68. package/src/components/Divider/index.tsx +0 -2
  69. package/src/components/EmailInput/EmailInput.module.scss +0 -0
  70. package/src/components/EmailInput/EmailInput.tsx +0 -51
  71. package/src/components/EmailInput/index.tsx +0 -2
  72. package/src/components/FadeIn/FadeIn.module.scss +0 -9
  73. package/src/components/FadeIn/FadeIn.tsx +0 -77
  74. package/src/components/FadeIn/index.tsx +0 -2
  75. package/src/components/FileInput/FileInput.module.scss +0 -6
  76. package/src/components/FileInput/FileInput.tsx +0 -75
  77. package/src/components/FileInput/View/BigFactory/BigFactory.module.scss +0 -20
  78. package/src/components/FileInput/View/BigFactory/BigFactory.tsx +0 -48
  79. package/src/components/FileInput/View/BigFactory/index.tsx +0 -2
  80. package/src/components/FileInput/View/Compact/Compact.module.scss +0 -68
  81. package/src/components/FileInput/View/Compact/Compact.tsx +0 -151
  82. package/src/components/FileInput/View/Compact/index.tsx +0 -2
  83. package/src/components/FileInput/View/View.types.ts +0 -12
  84. package/src/components/FileInput/index.tsx +0 -2
  85. package/src/components/FlowController/FlowController.module.scss +0 -47
  86. package/src/components/FlowController/FlowController.tsx +0 -93
  87. package/src/components/FlowController/index.tsx +0 -2
  88. package/src/components/Form/Form.tsx +0 -243
  89. package/src/components/Form/index.ts +0 -2
  90. package/src/components/Form/v2/Form.hook.ts +0 -341
  91. package/src/components/Form/v2/Form.module.scss +0 -0
  92. package/src/components/Form/v2/Form.tsx +0 -78
  93. package/src/components/Form/v2/Form.types.ts +0 -118
  94. package/src/components/Form/v2/FormField/Extensions/DateField/DateField.module.scss +0 -0
  95. package/src/components/Form/v2/FormField/Extensions/DateField/DateField.tsx +0 -73
  96. package/src/components/Form/v2/FormField/Extensions/DateField/index.tsx +0 -2
  97. package/src/components/Form/v2/FormField/Extensions/PhoneField/PhoneField.module.scss +0 -0
  98. package/src/components/Form/v2/FormField/Extensions/PhoneField/PhoneField.tsx +0 -91
  99. package/src/components/Form/v2/FormField/Extensions/PhoneField/index.tsx +0 -2
  100. package/src/components/Form/v2/FormField/FormField.module.scss +0 -0
  101. package/src/components/Form/v2/FormField/FormField.tsx +0 -378
  102. package/src/components/Form/v2/FormField/FormField.types.ts +0 -129
  103. package/src/components/Form/v2/FormField/index.tsx +0 -2
  104. package/src/components/Form/v2/index.tsx +0 -2
  105. package/src/components/Freeze/Freeze.tsx +0 -9
  106. package/src/components/Freeze/index.tsx +0 -2
  107. package/src/components/HSForms/HSForms.tsx +0 -57
  108. package/src/components/HSForms/index.tsx +0 -2
  109. package/src/components/Header/Header.module.scss +0 -119
  110. package/src/components/Header/Header.tsx +0 -138
  111. package/src/components/Header/index.tsx +0 -2
  112. package/src/components/HeaderCloseBtn/HeaderCloseBtn.module.scss +0 -44
  113. package/src/components/HeaderCloseBtn/HeaderCloseBtn.tsx +0 -28
  114. package/src/components/HeaderCloseBtn/index.tsx +0 -2
  115. package/src/components/InfinityScroll/InfinityScroll.module.scss +0 -30
  116. package/src/components/InfinityScroll/InfinityScroll.tsx +0 -187
  117. package/src/components/InfinityScroll/index.tsx +0 -2
  118. package/src/components/Input/Input.module.scss +0 -71
  119. package/src/components/Input/Input.tsx +0 -134
  120. package/src/components/Input/index.tsx +0 -2
  121. package/src/components/InstantCounter/InstantCounter.tsx +0 -77
  122. package/src/components/InstantCounter/index.tsx +0 -2
  123. package/src/components/LavaLamp/LavaLamp.data.tsx +0 -114
  124. package/src/components/LavaLamp/LavaLamp.module.scss +0 -26
  125. package/src/components/LavaLamp/LavaLamp.tsx +0 -131
  126. package/src/components/LavaLamp/index.tsx +0 -2
  127. package/src/components/LavaLamp/v2/LavaLamp.module.scss +0 -23
  128. package/src/components/LavaLamp/v2/LavaLamp.tsx +0 -197
  129. package/src/components/LinkToId/LinkToId.module.scss +0 -4
  130. package/src/components/LinkToId/LinkToId.tsx +0 -51
  131. package/src/components/LinkToId/index.tsx +0 -2
  132. package/src/components/Loader/Loader.module.scss +0 -40
  133. package/src/components/Loader/Loader.tsx +0 -18
  134. package/src/components/Loader/index.tsx +0 -2
  135. package/src/components/LoaderDotsIndicator/LoaderDotsIndicator.tsx +0 -34
  136. package/src/components/LoaderDotsIndicator/index.tsx +0 -2
  137. package/src/components/LoopableVideo/LoopableVideo.tsx +0 -37
  138. package/src/components/LoopableVideo/index.tsx +0 -2
  139. package/src/components/MainGrid/MainGrid.module.scss +0 -28
  140. package/src/components/MainGrid/MainGrid.tsx +0 -68
  141. package/src/components/MainGrid/index.tsx +0 -2
  142. package/src/components/MutableHamburgerButton/MutableHamburgerButton.module.scss +0 -220
  143. package/src/components/MutableHamburgerButton/MutableHamburgerButton.tsx +0 -38
  144. package/src/components/MutableHamburgerButton/index.tsx +0 -2
  145. package/src/components/Notification/Notification.module.scss +0 -25
  146. package/src/components/Notification/Notification.tsx +0 -13
  147. package/src/components/Notification/index.tsx +0 -2
  148. package/src/components/OrderableList/OrderableList.module.scss +0 -98
  149. package/src/components/OrderableList/OrderableList.tsx +0 -564
  150. package/src/components/OrderableList/index.tsx +0 -2
  151. package/src/components/PaginationIndicator/PaginationIndicator.tsx +0 -365
  152. package/src/components/PaginationIndicator/index.tsx +0 -2
  153. package/src/components/Parallax/Parallax.module.scss +0 -28
  154. package/src/components/Parallax/Parallax.tsx +0 -225
  155. package/src/components/Parallax/index.tsx +0 -2
  156. package/src/components/Parallax/math/helpers.ts +0 -289
  157. package/src/components/PasswordInput/PasswordInput.module.scss +0 -17
  158. package/src/components/PasswordInput/PasswordInput.tsx +0 -154
  159. package/src/components/PasswordInput/index.tsx +0 -2
  160. package/src/components/PingPongText/PingPongText.module.scss +0 -4
  161. package/src/components/PingPongText/PingPongText.tsx +0 -83
  162. package/src/components/PingPongText/index.tsx +0 -2
  163. package/src/components/PixelatedScan/PixelatedScan.module.scss +0 -86
  164. package/src/components/PixelatedScan/PixelatedScan.tsx +0 -175
  165. package/src/components/PixelatedScan/index.tsx +0 -2
  166. package/src/components/Portal/Portal.module.scss +0 -3
  167. package/src/components/Portal/Portal.tsx +0 -68
  168. package/src/components/Portal/index.tsx +0 -2
  169. package/src/components/ProgressBar/ProgressBar.module.scss +0 -44
  170. package/src/components/ProgressBar/ProgressBar.tsx +0 -124
  171. package/src/components/ProgressBar/index.tsx +0 -2
  172. package/src/components/ProgressTexts/ProgressTexts.module.scss +0 -37
  173. package/src/components/ProgressTexts/ProgressTexts.tsx +0 -85
  174. package/src/components/ProgressTexts/index.tsx +0 -2
  175. package/src/components/Radio/Radio.module.scss +0 -36
  176. package/src/components/Radio/Radio.tsx +0 -53
  177. package/src/components/Radio/index.tsx +0 -2
  178. package/src/components/SectionContainer/SectionContainer.module.scss +0 -30
  179. package/src/components/SectionContainer/SectionContainer.tsx +0 -49
  180. package/src/components/SectionContainer/index.tsx +0 -2
  181. package/src/components/Select/Select.module.scss +0 -58
  182. package/src/components/Select/Select.tsx +0 -192
  183. package/src/components/Select/index.tsx +0 -2
  184. package/src/components/Skeleton/Skeleton.module.scss +0 -21
  185. package/src/components/Skeleton/Skeleton.tsx +0 -29
  186. package/src/components/Skeleton/index.tsx +0 -2
  187. package/src/components/Spacing/Spacing.module.scss +0 -13
  188. package/src/components/Spacing/Spacing.tsx +0 -24
  189. package/src/components/Spacing/index.tsx +0 -2
  190. package/src/components/StaticScroller/StaticScroller.module.scss +0 -14
  191. package/src/components/StaticScroller/StaticScroller.tsx +0 -83
  192. package/src/components/StaticScroller/index.tsx +0 -2
  193. package/src/components/Switch/Switch.module.scss +0 -43
  194. package/src/components/Switch/Switch.tsx +0 -41
  195. package/src/components/Switch/index.tsx +0 -2
  196. package/src/components/Table/Table.module.scss +0 -76
  197. package/src/components/Table/Table.tsx +0 -152
  198. package/src/components/Table/index.tsx +0 -2
  199. package/src/components/Tabs/Tabs.module.scss +0 -40
  200. package/src/components/Tabs/Tabs.tsx +0 -104
  201. package/src/components/Tabs/index.tsx +0 -2
  202. package/src/components/Text/Text.module.scss +0 -81
  203. package/src/components/Text/Text.tsx +0 -42
  204. package/src/components/Text/index.tsx +0 -2
  205. package/src/components/Transition/MasksFactory/DiagonalReveal.tsx +0 -47
  206. package/src/components/Transition/MasksFactory/DiagonalSquareToBalls.tsx +0 -78
  207. package/src/components/Transition/MasksFactory/PhysicsSquares.tsx +0 -106
  208. package/src/components/Transition/MasksFactory/SquareToBalls.tsx +0 -66
  209. package/src/components/Transition/MasksFactory/utils.ts +0 -35
  210. package/src/components/Transition/Transition.module.scss +0 -211
  211. package/src/components/Transition/Transition.tsx +0 -495
  212. package/src/components/Transition/index.tsx +0 -2
  213. package/src/components/UncontrolledTransition/UncontrolledTransition.ai.md +0 -9
  214. package/src/components/UncontrolledTransition/UncontrolledTransition.sample.tsx +0 -34
  215. package/src/components/UncontrolledTransition/UncontrolledTransition.tsx +0 -143
  216. package/src/components/UncontrolledTransition/index.tsx +0 -2
  217. package/src/components/WalletConnectionWrapper/WalletConnectionWrapper.tsx +0 -212
  218. package/src/components/WalletConnectionWrapper/index.tsx +0 -2
  219. package/src/components/utilitary/ScrollAndFocusLock/ScrollAndFocusLock.module.scss +0 -5
  220. package/src/components/utilitary/ScrollAndFocusLock/ScrollAndFocusLock.tsx +0 -52
  221. package/src/components/utilitary/ScrollAndFocusLock/index.tsx +0 -2
  222. package/src/context/AsyncProcess.tsx +0 -107
  223. package/src/context/ContextAsyncControl.tsx +0 -89
  224. package/src/context/CustomBrowserRouter.tsx +0 -55
  225. package/src/context/OneUIProvider.tsx +0 -308
  226. package/src/hooks/logs/useDependencyChangeDetection.ts +0 -25
  227. package/src/hooks/logs/useIsMounting.ts +0 -7
  228. package/src/hooks/persistence/useLocalStorage.ts +0 -45
  229. package/src/hooks/shims/ObjectWatchShim.ts +0 -56
  230. package/src/hooks/ui/useAdaptiveImage.tsx +0 -36
  231. package/src/hooks/ui/useAlternating.tsx +0 -22
  232. package/src/hooks/ui/useBreakpoint.tsx +0 -21
  233. package/src/hooks/ui/useCustomScrollbar.module.scss +0 -20
  234. package/src/hooks/ui/useCustomScrollbar.tsx +0 -22
  235. package/src/hooks/ui/useEffectIf.ts +0 -11
  236. package/src/hooks/ui/useMouseHover.tsx +0 -26
  237. package/src/hooks/ui/usePaginationControls.module.scss +0 -16
  238. package/src/hooks/ui/usePaginationControls.tsx +0 -176
  239. package/src/hooks/ui/useSnapToViewport.module.scss +0 -6
  240. package/src/hooks/ui/useSnapToViewport.ts +0 -28
  241. package/src/hooks/ui/useTilt.tsx +0 -219
  242. package/src/hooks/ui/useZoomable.module.scss +0 -34
  243. package/src/hooks/ui/useZoomable.tsx +0 -144
  244. package/src/hooks/useAsyncControl.ai.md +0 -25
  245. package/src/hooks/useAsyncControl.ts +0 -101
  246. package/src/hooks/useContainedRepositioning.ts +0 -110
  247. package/src/hooks/useCustomHistory.ts +0 -14
  248. package/src/hooks/useElementFit.ts +0 -82
  249. package/src/hooks/useFirestoreWatch.ts +0 -54
  250. package/src/hooks/useForm.ts +0 -49
  251. package/src/hooks/useFreeze.ts +0 -12
  252. package/src/hooks/useHero.module.scss +0 -41
  253. package/src/hooks/useHero.ts +0 -512
  254. package/src/hooks/useIntersection.ts +0 -32
  255. package/src/hooks/useMergeRefs.ts +0 -29
  256. package/src/hooks/useObserve.ts +0 -24
  257. package/src/hooks/usePagination.ts +0 -228
  258. package/src/hooks/usePooledOperation.ts +0 -54
  259. package/src/hooks/usePooling.ts +0 -46
  260. package/src/hooks/useRebound.ts +0 -23
  261. package/src/hooks/useShortIntl.ai.md +0 -5
  262. package/src/hooks/useShortIntl.ts +0 -97
  263. package/src/hooks/utility/useAsyncMemo.ts +0 -43
  264. package/src/hooks/utility/useDepChange.ts +0 -11
  265. package/src/hooks/utility/useEvents.ts +0 -33
  266. package/src/hooks/utility/useImmediate.ts +0 -8
  267. package/src/hooks/utility/useManualInit.ts +0 -24
  268. package/src/hooks/utility/useModule.ts +0 -15
  269. package/src/hooks/utility/useQuery.ts +0 -15
  270. package/src/hooks/utility/useUniqueEffect.ts +0 -22
  271. package/src/index.preprocess.ts +0 -82
  272. package/src/index.ts +0 -229
  273. package/src/models/DebugLogger.ts +0 -7
  274. package/src/models/GenericContract.ts +0 -169
  275. package/src/models/Orbs.ts +0 -97
  276. package/src/reac-app-env.d.ts +0 -6
  277. package/src/storybook/assets/video/txt-reversed.mp4 +0 -0
  278. package/src/storybookUtils/index.tsx +0 -53
  279. package/src/test.tsx +0 -0
  280. package/src/type-utils.ts +0 -49
  281. package/src/types.ts +0 -199
  282. package/src/utility.d.ts +0 -70
  283. package/src/utils/blockchain.ts +0 -43
  284. package/src/utils/e2e.ts +0 -55
  285. package/src/utils/flatten.ts +0 -17
  286. package/src/utils/formatters.ts +0 -36
  287. package/src/utils/html.utils.ts +0 -3
  288. package/src/utils/ownEvent.ts +0 -8
  289. package/src/utils/test.ts +0 -20
@@ -1,228 +0,0 @@
1
- import {
2
- useCallback,
3
- useEffect,
4
- useLayoutEffect,
5
- useMemo,
6
- useRef,
7
- useState,
8
- } from "react";
9
- import useAsyncControl from "./useAsyncControl";
10
- import throttle from "lodash/throttle";
11
-
12
- type UpdateEvent<I extends any> = {
13
- finished: boolean;
14
- items: I[];
15
- totalItems: number;
16
- };
17
-
18
- export default function usePagination<I extends any>(
19
- request: (
20
- page: number,
21
- pageSize: number | "all",
22
- currItems?: I[]
23
- ) => Promise<UpdateEvent<I>>,
24
- paginationId: object | any[] | (() => string) = () => "default",
25
- startingItems?: I[]
26
- ): Paginable<I> {
27
- const paginationDataRef = useRef<{
28
- [d: string]:
29
- | {
30
- finished: boolean;
31
- totalItems: number;
32
- }
33
- | undefined;
34
- }>({});
35
- const { current: paginationData } = paginationDataRef;
36
- const paginationIdFactory = useMemo(
37
- () => {
38
- if (typeof paginationId === "object") {
39
- const randId = Math.random();
40
- return () => randId.toString();
41
- } else return paginationId;
42
- },
43
- Array.isArray(paginationId) ? paginationId : [paginationId]
44
- );
45
-
46
- const [items, setItems] =
47
- useState<[paginationId: string, items: I[]] | undefined>();
48
-
49
- const [id, setId] = useState(() => paginationIdFactory());
50
-
51
- useEffect(() => {
52
- setId(paginationIdFactory());
53
- if (startingItems) setItems([paginationIdFactory(), startingItems]);
54
- else setItems(undefined);
55
- }, [paginationIdFactory()]);
56
-
57
- const { process, ...control } = useAsyncControl();
58
-
59
- function updateItems(cb: (prevItems?: I) => UpdateEvent<I>["items"]) {
60
- setItems((prev) => [prev![0], cb()]);
61
- }
62
-
63
- const derivateCurrentPage = (pageSize: number) => {
64
- if (items === undefined) return 0;
65
- const currentPage = Math.floor((items?.[1].length ?? 0) / pageSize) - 1;
66
- return currentPage;
67
- };
68
-
69
- const _requestPage = useCallback(
70
- function (page: number, pageSize: number | "all") {
71
- const id = paginationIdFactory();
72
- if (paginationData[id]?.finished) return;
73
- process(async () => {
74
- const result = await request(
75
- page,
76
- pageSize,
77
- items?.[0] === id && page !== 0
78
- ? pageSize === "all"
79
- ? undefined
80
- : items?.[1].slice(0, page * pageSize)
81
- : undefined
82
- );
83
- paginationData[id] = {
84
- finished: result.finished,
85
- totalItems: result.totalItems,
86
- };
87
- setItems((prev) => {
88
- if (page === 0) return [id, result.items];
89
- else if (!prev || id === prev[0]) return [id, result.items];
90
- return prev;
91
- });
92
- });
93
- },
94
- [items, request]
95
- );
96
-
97
- return {
98
- updateItems,
99
- getNextPage: (pageSize: number) => {
100
- _requestPage(derivateCurrentPage(pageSize) + 1, pageSize);
101
- },
102
- getPage: _requestPage,
103
- getAll: () => {
104
- _requestPage(0, "all");
105
- },
106
- refreshCurrentPage: (pageSize: number) => {
107
- _requestPage(derivateCurrentPage(pageSize), pageSize);
108
- },
109
- totalItems: () => paginationData[paginationIdFactory()]?.totalItems,
110
- id: () => id,
111
- loading: control.loading,
112
- error: control.error,
113
- items: items?.[1],
114
- setError: control.setError,
115
- };
116
- }
117
-
118
- export type Paginable<I extends any, E extends any = any> = {
119
- updateItems: (cb: (prevItems?: I) => UpdateEvent<I>["items"]) => void;
120
- getNextPage: (pageSize: number) => void;
121
- refreshCurrentPage: (pageSize: number) => void;
122
- getPage: (page: number, pageSize: number) => void;
123
- getAll: () => void;
124
- totalItems: () => number | undefined;
125
- loading: boolean;
126
- error: E | Error | undefined;
127
- items: I[] | undefined;
128
- setError: ReturnType<typeof useAsyncControl>["setError"];
129
- id: () => string;
130
- };
131
-
132
- export type LocalPaginable<I extends any, E extends any = any> = Paginable<
133
- I,
134
- E
135
- > & {
136
- src: I;
137
- };
138
-
139
- /**
140
- * This returns a ref to be bound to an elements so it can be able to detect when a pagination whould occur
141
- */
142
- export function useContainerPagination(
143
- cb: (pageSize: number) => void,
144
- pageSize: number,
145
- direction: "h" | "v" = "v"
146
- ) {
147
- const scrollableRef = useRef<HTMLDivElement>(undefined);
148
- const customOptionsRef =
149
- useRef<() => { offsetBottom?: number; offsetLeft?: number }>(undefined);
150
-
151
- useEffect(() => {
152
- const el = scrollableRef.current!;
153
- const scrollElement =
154
- (el as unknown as typeof window.document).scrollingElement || el;
155
- const calculateIfReachedLimit = throttle(
156
- (e: Event) => {
157
- if (e.target !== el) return;
158
- const { offsetBottom = 0, offsetLeft = 0 } =
159
- customOptionsRef.current?.() || {};
160
- const offsetLimit =
161
- direction === "v"
162
- ? scrollElement.scrollHeight -
163
- offsetBottom -
164
- scrollElement.clientHeight * 0.6
165
- : scrollElement.scrollWidth -
166
- offsetLeft -
167
- scrollElement.clientWidth * 0.6;
168
- const offset =
169
- direction === "v"
170
- ? scrollElement.clientHeight + scrollElement.scrollTop
171
- : scrollElement.clientWidth + scrollElement.scrollLeft;
172
- if (offset >= offsetLimit) {
173
- cb(pageSize);
174
- }
175
- },
176
- 250,
177
- {
178
- leading: false,
179
- trailing: true,
180
- }
181
- );
182
-
183
- el.addEventListener("scroll", calculateIfReachedLimit, {
184
- passive: true,
185
- });
186
- return () => el.removeEventListener("scroll", calculateIfReachedLimit);
187
- }, [cb, pageSize]);
188
-
189
- return {
190
- scrollableRef,
191
- customOptionsRef,
192
- };
193
- }
194
-
195
- /**
196
- * This function receives an amount of local instances and paginates it
197
- */
198
- export function useLocalPagination<L>(items: L[] | undefined) {
199
- const instanceID = useMemo(() => Date.now(), [items]);
200
- const cb = useCallback(
201
- (page: number, pageSize: number | "all", currItems: L[] = []) => {
202
- if (!items)
203
- return Promise.resolve({
204
- finished: false,
205
- totalItems: 0,
206
- items: [],
207
- });
208
- if (pageSize === "all") pageSize = items.length;
209
- const from = pageSize * page;
210
- const newArray = [...currItems, ...items.slice(from, from + pageSize)];
211
-
212
- return Promise.resolve({
213
- finished: newArray.length === items.length,
214
- totalItems: items.length,
215
- items: newArray,
216
- });
217
- },
218
- [items]
219
- );
220
- const pagination = usePagination<L>(cb, () => `${instanceID}`);
221
- const pagSrc = useMemo(() => items, [pagination.items]);
222
-
223
- return {
224
- ...pagination,
225
- loading: items === undefined,
226
- src: pagSrc,
227
- };
228
- }
@@ -1,54 +0,0 @@
1
- import { createRef, useRef } from "react";
2
- import useAsyncControl from "./useAsyncControl";
3
- import usePooling from "./usePooling";
4
-
5
- /**
6
- * A toolkit hook to trigger an request to start a process and execute a pooling operation to validate when the operation is finished
7
- */
8
- export default function usePooledOperation() {
9
- const requestOperation = useRef<() => Promise<void>>(undefined);
10
- const poolingOperation = useRef<() => Promise<boolean>>(undefined);
11
- const requestControl = useAsyncControl();
12
- const pollingControl = usePooling();
13
-
14
- function triggerRequest() {
15
- requestControl.process(async () => {
16
- await requestOperation.current!();
17
- triggerPooling();
18
- });
19
- }
20
-
21
- function triggerPooling() {
22
- pollingControl.startPolling(poolingOperation.current!);
23
- }
24
-
25
- return {
26
- /** Indicates when it's loading */
27
- loading: requestControl.loading || pollingControl.isPooling,
28
- /** Indicates error of pooling or request */
29
- error: !!requestControl.error || !!pollingControl.failed,
30
- /** Retries the operation based on the current failed step */
31
- retry: requestControl.error
32
- ? triggerRequest
33
- : pollingControl.failed
34
- ? triggerPooling
35
- : undefined,
36
- /** Initiates the request followed by the pooling operation */
37
- start: (
38
- /** An arbitrary request */
39
- _requestOperation: () => Promise<void>,
40
- /** Resolves to a boolean that indicated if is finished (true) or not (false) */
41
- _poolingOperation: () => Promise<boolean>
42
- ) => {
43
- requestOperation.current = _requestOperation;
44
- poolingOperation.current = _poolingOperation;
45
-
46
- triggerRequest();
47
- },
48
- /** Clear any error that is registered */
49
- clearError: () => {
50
- requestControl.setError(undefined);
51
- pollingControl.setFailed(false);
52
- },
53
- };
54
- }
@@ -1,46 +0,0 @@
1
- import { useEffect, useState } from "react";
2
-
3
- /**
4
- * This callback should return a boolean that indicates if the pooling has finished (true) or it should continue (false)
5
- */
6
- type PoolingAction = () => Promise<boolean>;
7
-
8
- export default function usePooling(intervalMs = 1000, maxPoolingTime: number | null = 60000) {
9
- const [intervalId, setIntervalId] = useState<NodeJS.Timer>();
10
- const [failed, setFailed] = useState<boolean>(false);
11
-
12
- const cancelPooling = () => {
13
- if (intervalId) clearInterval(intervalId);
14
- }
15
- useEffect(
16
- () => cancelPooling,
17
- [intervalId]
18
- );
19
-
20
- return {
21
- failed,
22
- setFailed,
23
- isPooling: !!intervalId,
24
- /**
25
- *
26
- * @param cb {@link PoolingAction} - Executes and returns if has finished (true) or not (false)
27
- */
28
- startPolling: (cb: PoolingAction) => {
29
- let poolingCount = 0;
30
- const maxPoolings = (maxPoolingTime !== null) ? Math.ceil(maxPoolingTime / intervalMs) : undefined;
31
- const intervalId = setInterval(async () => {
32
- poolingCount++;
33
- const finished = await cb();
34
- if (finished) setIntervalId(undefined);
35
- else if (poolingCount === maxPoolings) {
36
- setIntervalId(undefined);
37
- setFailed(true);
38
- }
39
- }, intervalMs);
40
- setIntervalId(intervalId);
41
- setFailed(false);
42
- return () => clearInterval(intervalId)
43
- },
44
- stop: cancelPooling,
45
- };
46
- }
@@ -1,23 +0,0 @@
1
- import { useEffect, useState } from "react"
2
-
3
- /**
4
- * This hook adds a prop that you can toggle and returns to initial
5
- * state after a defined time (usefull for notification)
6
- */
7
- export default function useRebound<T extends any>(initialValue: T, timeoutSec: number = 1) {
8
- const [state, setState] = useState<T>(initialValue)
9
-
10
- useEffect(() => {
11
- if (state !== initialValue) {
12
- const timeout = setTimeout(() => {
13
- setState(initialValue)
14
- }, timeoutSec * 1000);
15
-
16
- return () => clearTimeout(timeout);
17
- }
18
- }, [state]);
19
- return {
20
- current: state,
21
- setState
22
- }
23
- }
@@ -1,5 +0,0 @@
1
- # Referencing a text
2
- ```tsx
3
- const { txt } = useShortIntl();
4
- const theText = txt("text.hierarchy.id");
5
- ```
@@ -1,97 +0,0 @@
1
- import { IntlFormatters, IntlShape, useIntl } from "react-intl";
2
- import { BigNumber } from "bignumber.js";
3
- import { ReactElement, useEffect, useState } from "react";
4
-
5
- export default function useShortIntl(): IntlShape & {
6
- txt: <R extends ReturnType<IntlFormatters["formatMessage"]> = string>(
7
- id: OnepercentUtility.IntlIds,
8
- params?: Record<string, string | ReactElement>
9
- ) => R;
10
- formatToDoubleDecimal(
11
- number: number,
12
- options?: Parameters<IntlFormatters["formatNumber"]>[1]
13
- ): string;
14
- formatBigNumber(
15
- number: BigNumber,
16
- options?: Parameters<IntlFormatters["formatNumber"]>[1]
17
- ): string;
18
- } {
19
- const intl = useIntl();
20
- const { formatMessage, formatNumber } = intl;
21
- const [devMode, setDevMode] = useState(false);
22
-
23
- useEffect(() => {
24
- if (process.env.NODE_ENV === "development") {
25
- const keyDownDetect = (ev: KeyboardEvent) => {
26
- if (ev.key === "i" && ev.ctrlKey) {
27
- const keyUpDetect = (ev: KeyboardEvent) => {
28
- if (ev.key === "i") {
29
- setDevMode(false);
30
- }
31
- };
32
- setDevMode(true);
33
- window.addEventListener("keyup", keyUpDetect);
34
- }
35
- };
36
- window.addEventListener("keydown", keyDownDetect);
37
- }
38
- });
39
-
40
- return {
41
- ...intl,
42
- txt: (id, params) => {
43
- return devMode ? id : formatMessage({ id }, params) as any;
44
- },
45
- formatToDoubleDecimal(val: number, options = {}) {
46
- return formatNumber(val, {
47
- minimumFractionDigits: 2,
48
- maximumFractionDigits: 2,
49
- ...options,
50
- });
51
- },
52
- formatBigNumber(bigNumber, options) {
53
- const { decimalSeparator } = intl
54
- .formatNumberToParts(1000.1)
55
- .reduce((r, a) => {
56
- if (a.type === "decimal") return { ...r, decimalSeparator: a.value };
57
- if (a.type === "group") return { ...r, thousandSeparator: a.value };
58
- return r;
59
- }, {} as { decimalSeparator: string; thousandSeparator: string });
60
-
61
- const integerPart = bigNumber.integerValue(1);
62
- const integer = intl.formatNumber(integerPart.toNumber(), options);
63
- const decimals = bigNumber
64
- .minus(integerPart)
65
- .decimalPlaces(
66
- options?.maximumFractionDigits || bigNumber.decimalPlaces()!,
67
- 5
68
- )
69
- .toString()
70
- .replace("0.", "");
71
- return `${integer}${
72
- decimals !== "0" ? `${decimalSeparator}${decimals}` : ""
73
- }`;
74
- },
75
- };
76
- }
77
-
78
- type StrMap = {
79
- [s: string]: string;
80
- };
81
-
82
- type IsolatedMessages<A extends string, M extends StrMap, P extends string> = {
83
- [s1 in `${P}.${keyof M extends string ? keyof M : ""}`]: M[keyof M];
84
- };
85
-
86
- export function isolateMessages<A extends string, M extends StrMap>(
87
- preffix: A,
88
- strings: M
89
- ) {
90
- return Object.entries(strings).reduce(
91
- (r, [k, v]) => ({
92
- ...r,
93
- [`${preffix}.${k}`]: v,
94
- }),
95
- {} as IsolatedMessages<A, M, typeof preffix>
96
- );
97
- }
@@ -1,43 +0,0 @@
1
- import { useEffect, useState } from "react";
2
- import useAsyncControl from "../useAsyncControl";
3
-
4
- /**
5
- * It can assume 3 states
6
- * [undefined] = The hook has just initialized, and will call the memoize function
7
- * [T] = The hook initialized the value
8
- * [null, error] = The hook failed to initialize and the error is available
9
- */
10
- export default function useAsyncMemo<T>(
11
- funcToMemoize: () => Promise<T>,
12
- depArr: any[]
13
- ): [
14
- value: T | undefined | null,
15
- error: any,
16
- loading: boolean,
17
- retry: () => Promise<void>,
18
- setValue: (value: T) => void
19
- ] {
20
- const { process, error, ...control } = useAsyncControl();
21
- const [memo, setMemo] = useState<T | null>();
22
-
23
- useEffect(() => {
24
- let depBasedSet: typeof setMemo | undefined = setMemo;
25
- process(funcToMemoize)
26
- .then((whatToStore) => depBasedSet?.(() => whatToStore))
27
- .catch(() => depBasedSet?.(null));
28
- return () => {
29
- depBasedSet = undefined;
30
- };
31
- }, depArr);
32
-
33
- return [
34
- memo,
35
- error,
36
- control.loading,
37
- () =>
38
- process(funcToMemoize)
39
- .then((whatToStore) => setMemo(() => whatToStore))
40
- .catch(() => setMemo(null)),
41
- setMemo,
42
- ];
43
- }
@@ -1,11 +0,0 @@
1
- import { useInsertionEffect, useRef } from "react";
2
-
3
- export default function useDepChange<T>(callback: (prevDep: T) => void, dep: T) {
4
- const prevStep = useRef<T>(undefined);
5
- useInsertionEffect(() => {
6
- if (prevStep.current) callback(prevStep.current);
7
- return () => {
8
- prevStep.current = dep;
9
- };
10
- }, [dep]);
11
- }
@@ -1,33 +0,0 @@
1
- import { useRef } from "react";
2
-
3
- /**
4
- * This hook allows for easier declaration of events and unsubscribers
5
- */
6
- export default function useEvents<
7
- EN extends string,
8
- E extends { [k in EN]: any[] }
9
- >() {
10
- const _eventSUbscriptionsMap = useRef<
11
- {
12
- [k in EN]?: ((...args: E[k]) => void)[];
13
- }
14
- >({});
15
- const subscriber = <X extends EN>(e: X, cb: (...args: E[X]) => void) => {
16
- if (!_eventSUbscriptionsMap.current[e])
17
- _eventSUbscriptionsMap.current[e] = [];
18
- _eventSUbscriptionsMap.current[e]!.push(cb);
19
- return () => {
20
- const arr = _eventSUbscriptionsMap.current[e]!;
21
- arr.splice(arr.indexOf(cb), 1);
22
- };
23
- };
24
- const dispatcher = <X extends EN>(eventName: X, ...args: E[X]) => {
25
- const subscriptions = _eventSUbscriptionsMap.current[eventName] || [];
26
-
27
- subscriptions.forEach((cb) => cb(...args));
28
- };
29
- return {
30
- subscriber,
31
- dispatcher,
32
- };
33
- }
@@ -1,8 +0,0 @@
1
- import { useMemo } from "react";
2
-
3
- /**
4
- * Runs this function as soon as the hook is invoked
5
- */
6
- export default function useImmediate(execute: () => void, deps?: any[]) {
7
- useMemo(execute, deps ?? []);
8
- }
@@ -1,24 +0,0 @@
1
- import { useCallback, useEffect, useState } from "react";
2
- import useAsyncControl from "../useAsyncControl";
3
-
4
- /**
5
- * Provides a way to manually trigger a function and store it's result on a state
6
- */
7
- export default function useManualInit<T>(
8
- funcToMemoize: () => Promise<T>,
9
- depArr: any[]
10
- ): [init: () => Promise<T>, memo: T | undefined | null, error: any] {
11
- const { process, error } = useAsyncControl();
12
- const [memo, setMemo] = useState<T | null>();
13
- const initCb = useCallback(
14
- () =>
15
- process(funcToMemoize)
16
- .then((result) => {
17
- setMemo(result);
18
- return result;
19
- })
20
- .catch(() => setMemo(null)),
21
- depArr
22
- );
23
- return [initCb, memo, error];
24
- }
@@ -1,15 +0,0 @@
1
- import { useLayoutEffect, useState } from "react";
2
-
3
- /**
4
- * This provides an interface for async loading of modules
5
- */
6
- export default function useModule<T>(
7
- moduleLoadPromiseFactory: () => Promise<T>
8
- ): T | undefined {
9
- const [moduleLoaded, setModuleLoaded] = useState<T>();
10
- useLayoutEffect(() => {
11
- moduleLoadPromiseFactory().then(setModuleLoaded);
12
- }, []);
13
-
14
- return moduleLoaded;
15
- }
@@ -1,15 +0,0 @@
1
- /**
2
- *
3
- * @returns A hook to obtain the query params from a url
4
- */
5
-
6
- import { useMemo } from "react";
7
- import { useLocation } from "react-router-dom";
8
-
9
- export default function useQuery<E extends {}>() {
10
- const { search } = useLocation();
11
-
12
- return useMemo(() => new URLSearchParams(search), [search]) as unknown as {
13
- get: (p: keyof E) => E[typeof p];
14
- };
15
- }
@@ -1,22 +0,0 @@
1
- import { useLayoutEffect, useMemo } from "react";
2
- import { useShareState } from "../../context/ContextAsyncControl";
3
-
4
- export default function useUniqueEffect(
5
- id: string,
6
- effect: () => void,
7
- deps: any[]
8
- ) {
9
- const lockId = useMemo(() => Math.random(), []);
10
- const [currLock, setCurrLock] = useShareState<number | undefined>(
11
- "unique-effect",
12
- id
13
- );
14
- useLayoutEffect(() => {
15
- if (currLock === lockId) effect();
16
- }, [...deps, currLock]);
17
-
18
- useLayoutEffect(() => {
19
- if (currLock === undefined) setCurrLock(lockId);
20
- if (currLock === lockId) return () => setCurrLock(undefined);
21
- }, [currLock]);
22
- }