@siberiacancode/reactuse 0.2.24 → 0.2.26

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 (281) hide show
  1. package/dist/cjs/helpers/createStore/createStore.cjs +1 -1
  2. package/dist/cjs/helpers/createStore/createStore.cjs.map +1 -1
  3. package/dist/cjs/hooks/useActiveElement/useActiveElement.cjs +1 -1
  4. package/dist/cjs/hooks/useActiveElement/useActiveElement.cjs.map +1 -1
  5. package/dist/cjs/hooks/useAsync/useAsync.cjs.map +1 -1
  6. package/dist/cjs/hooks/useAutoScroll/useAutoScroll.cjs +1 -1
  7. package/dist/cjs/hooks/useAutoScroll/useAutoScroll.cjs.map +1 -1
  8. package/dist/cjs/hooks/useBoolean/useBoolean.cjs.map +1 -1
  9. package/dist/cjs/hooks/useBrowserLanguage/useBrowserLanguage.cjs.map +1 -1
  10. package/dist/cjs/hooks/useClickOutside/useClickOutside.cjs.map +1 -1
  11. package/dist/cjs/hooks/useCookie/useCookie.cjs.map +1 -1
  12. package/dist/cjs/hooks/useCookies/useCookies.cjs.map +1 -1
  13. package/dist/cjs/hooks/useCounter/useCounter.cjs.map +1 -1
  14. package/dist/cjs/hooks/useCssVar/useCssVar.cjs +1 -1
  15. package/dist/cjs/hooks/useCssVar/useCssVar.cjs.map +1 -1
  16. package/dist/cjs/hooks/useDefault/useDefault.cjs.map +1 -1
  17. package/dist/cjs/hooks/useDisclosure/useDisclosure.cjs.map +1 -1
  18. package/dist/cjs/hooks/useDisplayMedia/useDisplayMedia.cjs.map +1 -1
  19. package/dist/cjs/hooks/useDocumentTitle/useDocumentTitle.cjs.map +1 -1
  20. package/dist/cjs/hooks/useDoubleClick/useDoubleClick.cjs.map +1 -1
  21. package/dist/cjs/hooks/useElementSize/useElementSize.cjs.map +1 -1
  22. package/dist/cjs/hooks/useEvent/useEvent.cjs.map +1 -1
  23. package/dist/cjs/hooks/useEventSource/useEventSource.cjs.map +1 -1
  24. package/dist/cjs/hooks/useField/useField.cjs.map +1 -1
  25. package/dist/cjs/hooks/useFileDialog/useFileDialog.cjs.map +1 -1
  26. package/dist/cjs/hooks/useFocus/useFocus.cjs.map +1 -1
  27. package/dist/cjs/hooks/useFps/useFps.cjs.map +1 -1
  28. package/dist/cjs/hooks/useHash/useHash.cjs.map +1 -1
  29. package/dist/cjs/hooks/useHover/useHover.cjs.map +1 -1
  30. package/dist/cjs/hooks/useImage/useImage.cjs.map +1 -1
  31. package/dist/cjs/hooks/useInfiniteScroll/useInfiniteScroll.cjs +1 -1
  32. package/dist/cjs/hooks/useInfiniteScroll/useInfiniteScroll.cjs.map +1 -1
  33. package/dist/cjs/hooks/useIntersectionObserver/useIntersectionObserver.cjs +1 -1
  34. package/dist/cjs/hooks/useIntersectionObserver/useIntersectionObserver.cjs.map +1 -1
  35. package/dist/cjs/hooks/useLastChanged/useLastChanged.cjs.map +1 -1
  36. package/dist/cjs/hooks/useList/useList.cjs.map +1 -1
  37. package/dist/cjs/hooks/useLocalStorage/useLocalStorage.cjs.map +1 -1
  38. package/dist/cjs/hooks/useLockCallback/useLockCallback.cjs.map +1 -1
  39. package/dist/cjs/hooks/useLockScroll/useLockScroll.cjs +2 -0
  40. package/dist/cjs/hooks/useLockScroll/useLockScroll.cjs.map +1 -0
  41. package/dist/cjs/hooks/useLogger/useLogger.cjs.map +1 -1
  42. package/dist/cjs/hooks/useLongPress/useLongPress.cjs.map +1 -1
  43. package/dist/cjs/hooks/useMap/useMap.cjs.map +1 -1
  44. package/dist/cjs/hooks/useMutation/useMutation.cjs.map +1 -1
  45. package/dist/cjs/hooks/useMutationObserver/useMutationObserver.cjs.map +1 -1
  46. package/dist/cjs/hooks/useNetwork/useNetwork.cjs.map +1 -1
  47. package/dist/cjs/hooks/useOffsetPagination/useOffsetPagination.cjs.map +1 -1
  48. package/dist/cjs/hooks/useOnline/useOnline.cjs.map +1 -1
  49. package/dist/cjs/hooks/useOperatingSystem/useOperatingSystem.cjs.map +1 -1
  50. package/dist/cjs/hooks/useOptimistic/useOptimistic.cjs.map +1 -1
  51. package/dist/cjs/hooks/useOrientation/useOrientation.cjs +1 -1
  52. package/dist/cjs/hooks/useOrientation/useOrientation.cjs.map +1 -1
  53. package/dist/cjs/hooks/usePaint/usePaint.cjs.map +1 -1
  54. package/dist/cjs/hooks/useParallax/useParallax.cjs +1 -1
  55. package/dist/cjs/hooks/useParallax/useParallax.cjs.map +1 -1
  56. package/dist/cjs/hooks/usePointerLock/usePointerLock.cjs.map +1 -1
  57. package/dist/cjs/hooks/usePreferredColorScheme/usePreferredColorScheme.cjs.map +1 -1
  58. package/dist/cjs/hooks/usePreferredContrast/usePreferredContrast.cjs.map +1 -1
  59. package/dist/cjs/hooks/usePreferredDark/usePreferredDark.cjs.map +1 -1
  60. package/dist/cjs/hooks/usePreferredLanguages/usePreferredLanguages.cjs.map +1 -1
  61. package/dist/cjs/hooks/usePreferredReducedMotion/usePreferredReducedMotion.cjs.map +1 -1
  62. package/dist/cjs/hooks/useQuery/useQuery.cjs.map +1 -1
  63. package/dist/cjs/hooks/useQueue/useQueue.cjs.map +1 -1
  64. package/dist/cjs/hooks/useRaf/useRaf.cjs.map +1 -1
  65. package/dist/cjs/hooks/{useRafValue/useRafValue.cjs → useRafState/useRafState.cjs} +2 -2
  66. package/dist/cjs/hooks/useRafState/useRafState.cjs.map +1 -0
  67. package/dist/cjs/hooks/useRefState/useRefState.cjs.map +1 -1
  68. package/dist/cjs/hooks/useRenderCount/useRenderCount.cjs.map +1 -1
  69. package/dist/cjs/hooks/useRenderInfo/useRenderInfo.cjs.map +1 -1
  70. package/dist/cjs/hooks/useRerender/useRerender.cjs.map +1 -1
  71. package/dist/cjs/hooks/useResizeObserver/useResizeObserver.cjs.map +1 -1
  72. package/dist/cjs/hooks/useScript/useScript.cjs.map +1 -1
  73. package/dist/cjs/hooks/useScroll/useScroll.cjs.map +1 -1
  74. package/dist/cjs/hooks/useSessionStorage/useSessionStorage.cjs.map +1 -1
  75. package/dist/cjs/hooks/useSet/useSet.cjs.map +1 -1
  76. package/dist/cjs/hooks/useSpeechRecognition/useSpeechRecognition.cjs.map +1 -1
  77. package/dist/cjs/hooks/useSpeechSynthesis/useSpeechSynthesis.cjs.map +1 -1
  78. package/dist/cjs/hooks/useStateHistory/useStateHistory.cjs.map +1 -1
  79. package/dist/cjs/hooks/useStep/useStep.cjs.map +1 -1
  80. package/dist/cjs/hooks/useSticky/useSticky.cjs.map +1 -1
  81. package/dist/cjs/hooks/useStopwatch/useStopwatch.cjs +1 -1
  82. package/dist/cjs/hooks/useStopwatch/useStopwatch.cjs.map +1 -1
  83. package/dist/cjs/hooks/useStorage/useStorage.cjs.map +1 -1
  84. package/dist/cjs/hooks/useTextDirection/useTextDirection.cjs +1 -1
  85. package/dist/cjs/hooks/useTextDirection/useTextDirection.cjs.map +1 -1
  86. package/dist/cjs/hooks/useToggle/useToggle.cjs.map +1 -1
  87. package/dist/cjs/hooks/useUrlSearchParam/useUrlSearchParam.cjs.map +1 -1
  88. package/dist/cjs/hooks/useUrlSearchParams/useUrlSearchParams.cjs.map +1 -1
  89. package/dist/cjs/hooks/useWindowEvent/useWindowEvent.cjs.map +1 -1
  90. package/dist/cjs/hooks/useWizard/useWizard.cjs.map +1 -1
  91. package/dist/cjs/index.cjs +1 -1
  92. package/dist/esm/helpers/createStore/createStore.mjs +16 -16
  93. package/dist/esm/helpers/createStore/createStore.mjs.map +1 -1
  94. package/dist/esm/hooks/useActiveElement/useActiveElement.mjs +22 -17
  95. package/dist/esm/hooks/useActiveElement/useActiveElement.mjs.map +1 -1
  96. package/dist/esm/hooks/useAsync/useAsync.mjs.map +1 -1
  97. package/dist/esm/hooks/useAutoScroll/useAutoScroll.mjs +38 -29
  98. package/dist/esm/hooks/useAutoScroll/useAutoScroll.mjs.map +1 -1
  99. package/dist/esm/hooks/useBoolean/useBoolean.mjs.map +1 -1
  100. package/dist/esm/hooks/useBrowserLanguage/useBrowserLanguage.mjs.map +1 -1
  101. package/dist/esm/hooks/useClickOutside/useClickOutside.mjs.map +1 -1
  102. package/dist/esm/hooks/useCookie/useCookie.mjs.map +1 -1
  103. package/dist/esm/hooks/useCookies/useCookies.mjs.map +1 -1
  104. package/dist/esm/hooks/useCounter/useCounter.mjs.map +1 -1
  105. package/dist/esm/hooks/useCssVar/useCssVar.mjs +27 -24
  106. package/dist/esm/hooks/useCssVar/useCssVar.mjs.map +1 -1
  107. package/dist/esm/hooks/useDefault/useDefault.mjs.map +1 -1
  108. package/dist/esm/hooks/useDisclosure/useDisclosure.mjs.map +1 -1
  109. package/dist/esm/hooks/useDisplayMedia/useDisplayMedia.mjs.map +1 -1
  110. package/dist/esm/hooks/useDocumentTitle/useDocumentTitle.mjs +3 -1
  111. package/dist/esm/hooks/useDocumentTitle/useDocumentTitle.mjs.map +1 -1
  112. package/dist/esm/hooks/useDoubleClick/useDoubleClick.mjs.map +1 -1
  113. package/dist/esm/hooks/useElementSize/useElementSize.mjs.map +1 -1
  114. package/dist/esm/hooks/useEvent/useEvent.mjs.map +1 -1
  115. package/dist/esm/hooks/useEventSource/useEventSource.mjs +3 -1
  116. package/dist/esm/hooks/useEventSource/useEventSource.mjs.map +1 -1
  117. package/dist/esm/hooks/useField/useField.mjs.map +1 -1
  118. package/dist/esm/hooks/useFileDialog/useFileDialog.mjs.map +1 -1
  119. package/dist/esm/hooks/useFocus/useFocus.mjs.map +1 -1
  120. package/dist/esm/hooks/useFps/useFps.mjs.map +1 -1
  121. package/dist/esm/hooks/useHash/useHash.mjs.map +1 -1
  122. package/dist/esm/hooks/useHover/useHover.mjs.map +1 -1
  123. package/dist/esm/hooks/useImage/useImage.mjs.map +1 -1
  124. package/dist/esm/hooks/useInfiniteScroll/useInfiniteScroll.mjs +27 -27
  125. package/dist/esm/hooks/useInfiniteScroll/useInfiniteScroll.mjs.map +1 -1
  126. package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs +5 -5
  127. package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs.map +1 -1
  128. package/dist/esm/hooks/useLastChanged/useLastChanged.mjs.map +1 -1
  129. package/dist/esm/hooks/useList/useList.mjs +15 -6
  130. package/dist/esm/hooks/useList/useList.mjs.map +1 -1
  131. package/dist/esm/hooks/useLocalStorage/useLocalStorage.mjs.map +1 -1
  132. package/dist/esm/hooks/useLockCallback/useLockCallback.mjs.map +1 -1
  133. package/dist/esm/hooks/useLockScroll/useLockScroll.mjs +44 -0
  134. package/dist/esm/hooks/useLockScroll/useLockScroll.mjs.map +1 -0
  135. package/dist/esm/hooks/useLogger/useLogger.mjs.map +1 -1
  136. package/dist/esm/hooks/useLongPress/useLongPress.mjs.map +1 -1
  137. package/dist/esm/hooks/useMap/useMap.mjs.map +1 -1
  138. package/dist/esm/hooks/useMutation/useMutation.mjs.map +1 -1
  139. package/dist/esm/hooks/useMutationObserver/useMutationObserver.mjs.map +1 -1
  140. package/dist/esm/hooks/useNetwork/useNetwork.mjs.map +1 -1
  141. package/dist/esm/hooks/useOffsetPagination/useOffsetPagination.mjs.map +1 -1
  142. package/dist/esm/hooks/useOnline/useOnline.mjs.map +1 -1
  143. package/dist/esm/hooks/useOperatingSystem/useOperatingSystem.mjs.map +1 -1
  144. package/dist/esm/hooks/useOptimistic/useOptimistic.mjs.map +1 -1
  145. package/dist/esm/hooks/useOrientation/useOrientation.mjs +25 -9
  146. package/dist/esm/hooks/useOrientation/useOrientation.mjs.map +1 -1
  147. package/dist/esm/hooks/usePaint/usePaint.mjs +14 -2
  148. package/dist/esm/hooks/usePaint/usePaint.mjs.map +1 -1
  149. package/dist/esm/hooks/useParallax/useParallax.mjs +9 -9
  150. package/dist/esm/hooks/useParallax/useParallax.mjs.map +1 -1
  151. package/dist/esm/hooks/usePointerLock/usePointerLock.mjs.map +1 -1
  152. package/dist/esm/hooks/usePreferredColorScheme/usePreferredColorScheme.mjs.map +1 -1
  153. package/dist/esm/hooks/usePreferredContrast/usePreferredContrast.mjs.map +1 -1
  154. package/dist/esm/hooks/usePreferredDark/usePreferredDark.mjs.map +1 -1
  155. package/dist/esm/hooks/usePreferredLanguages/usePreferredLanguages.mjs.map +1 -1
  156. package/dist/esm/hooks/usePreferredReducedMotion/usePreferredReducedMotion.mjs.map +1 -1
  157. package/dist/esm/hooks/useQuery/useQuery.mjs.map +1 -1
  158. package/dist/esm/hooks/useQueue/useQueue.mjs.map +1 -1
  159. package/dist/esm/hooks/useRaf/useRaf.mjs.map +1 -1
  160. package/dist/esm/hooks/{useRafValue/useRafValue.mjs → useRafState/useRafState.mjs} +2 -2
  161. package/dist/esm/hooks/useRafState/useRafState.mjs.map +1 -0
  162. package/dist/esm/hooks/useRefState/useRefState.mjs.map +1 -1
  163. package/dist/esm/hooks/useRenderCount/useRenderCount.mjs.map +1 -1
  164. package/dist/esm/hooks/useRenderInfo/useRenderInfo.mjs.map +1 -1
  165. package/dist/esm/hooks/useRerender/useRerender.mjs.map +1 -1
  166. package/dist/esm/hooks/useResizeObserver/useResizeObserver.mjs.map +1 -1
  167. package/dist/esm/hooks/useScript/useScript.mjs.map +1 -1
  168. package/dist/esm/hooks/useScroll/useScroll.mjs.map +1 -1
  169. package/dist/esm/hooks/useSessionStorage/useSessionStorage.mjs.map +1 -1
  170. package/dist/esm/hooks/useSet/useSet.mjs.map +1 -1
  171. package/dist/esm/hooks/useSpeechRecognition/useSpeechRecognition.mjs +14 -4
  172. package/dist/esm/hooks/useSpeechRecognition/useSpeechRecognition.mjs.map +1 -1
  173. package/dist/esm/hooks/useSpeechSynthesis/useSpeechSynthesis.mjs.map +1 -1
  174. package/dist/esm/hooks/useStateHistory/useStateHistory.mjs.map +1 -1
  175. package/dist/esm/hooks/useStep/useStep.mjs.map +1 -1
  176. package/dist/esm/hooks/useSticky/useSticky.mjs.map +1 -1
  177. package/dist/esm/hooks/useStopwatch/useStopwatch.mjs +18 -18
  178. package/dist/esm/hooks/useStopwatch/useStopwatch.mjs.map +1 -1
  179. package/dist/esm/hooks/useStorage/useStorage.mjs.map +1 -1
  180. package/dist/esm/hooks/useTextDirection/useTextDirection.mjs +19 -20
  181. package/dist/esm/hooks/useTextDirection/useTextDirection.mjs.map +1 -1
  182. package/dist/esm/hooks/useToggle/useToggle.mjs.map +1 -1
  183. package/dist/esm/hooks/useUrlSearchParam/useUrlSearchParam.mjs.map +1 -1
  184. package/dist/esm/hooks/useUrlSearchParams/useUrlSearchParams.mjs.map +1 -1
  185. package/dist/esm/hooks/useWindowEvent/useWindowEvent.mjs.map +1 -1
  186. package/dist/esm/hooks/useWizard/useWizard.mjs.map +1 -1
  187. package/dist/esm/index.mjs +323 -323
  188. package/dist/types/helpers/createStore/createStore.d.ts +1 -1
  189. package/dist/types/hooks/async.d.ts +5 -0
  190. package/dist/types/hooks/browser.d.ts +32 -0
  191. package/dist/types/hooks/debug.d.ts +4 -0
  192. package/dist/types/hooks/elements.d.ts +14 -0
  193. package/dist/types/hooks/fun.d.ts +3 -0
  194. package/dist/types/hooks/index.d.ts +11 -143
  195. package/dist/types/hooks/lifecycle.d.ts +6 -0
  196. package/dist/types/hooks/sensors.d.ts +34 -0
  197. package/dist/types/hooks/state.d.ts +25 -0
  198. package/dist/types/hooks/time.d.ts +5 -0
  199. package/dist/types/hooks/useActiveElement/useActiveElement.d.ts +21 -2
  200. package/dist/types/hooks/useAsync/useAsync.d.ts +1 -1
  201. package/dist/types/hooks/useAutoScroll/useAutoScroll.d.ts +3 -1
  202. package/dist/types/hooks/useBoolean/useBoolean.d.ts +1 -1
  203. package/dist/types/hooks/useBrowserLanguage/useBrowserLanguage.d.ts +1 -1
  204. package/dist/types/hooks/useClickOutside/useClickOutside.d.ts +1 -1
  205. package/dist/types/hooks/useCookie/useCookie.d.ts +1 -1
  206. package/dist/types/hooks/useCookies/useCookies.d.ts +1 -1
  207. package/dist/types/hooks/useCounter/useCounter.d.ts +1 -1
  208. package/dist/types/hooks/useCssVar/useCssVar.d.ts +1 -1
  209. package/dist/types/hooks/useDefault/useDefault.d.ts +1 -1
  210. package/dist/types/hooks/useDisclosure/useDisclosure.d.ts +1 -1
  211. package/dist/types/hooks/useDocumentTitle/useDocumentTitle.d.ts +2 -0
  212. package/dist/types/hooks/useDoubleClick/useDoubleClick.d.ts +1 -1
  213. package/dist/types/hooks/useEvent/useEvent.d.ts +1 -1
  214. package/dist/types/hooks/useField/useField.d.ts +1 -1
  215. package/dist/types/hooks/useFileDialog/useFileDialog.d.ts +1 -1
  216. package/dist/types/hooks/useFocus/useFocus.d.ts +1 -1
  217. package/dist/types/hooks/useFps/useFps.d.ts +1 -1
  218. package/dist/types/hooks/useHash/useHash.d.ts +1 -1
  219. package/dist/types/hooks/useHover/useHover.d.ts +1 -1
  220. package/dist/types/hooks/useImage/useImage.d.ts +1 -1
  221. package/dist/types/hooks/useIntersectionObserver/useIntersectionObserver.d.ts +7 -6
  222. package/dist/types/hooks/useLastChanged/useLastChanged.d.ts +1 -1
  223. package/dist/types/hooks/useList/useList.d.ts +1 -1
  224. package/dist/types/hooks/useLocalStorage/useLocalStorage.d.ts +1 -1
  225. package/dist/types/hooks/useLockCallback/useLockCallback.d.ts +1 -1
  226. package/dist/types/hooks/useLockScroll/useLockScroll.d.ts +49 -0
  227. package/dist/types/hooks/useLogger/useLogger.d.ts +1 -1
  228. package/dist/types/hooks/useLongPress/useLongPress.d.ts +1 -1
  229. package/dist/types/hooks/useMap/useMap.d.ts +1 -1
  230. package/dist/types/hooks/useMutation/useMutation.d.ts +1 -1
  231. package/dist/types/hooks/useMutationObserver/useMutationObserver.d.ts +1 -1
  232. package/dist/types/hooks/useNetwork/useNetwork.d.ts +1 -1
  233. package/dist/types/hooks/useOffsetPagination/useOffsetPagination.d.ts +1 -1
  234. package/dist/types/hooks/useOnline/useOnline.d.ts +1 -1
  235. package/dist/types/hooks/useOperatingSystem/useOperatingSystem.d.ts +1 -1
  236. package/dist/types/hooks/useOptimistic/useOptimistic.d.ts +1 -1
  237. package/dist/types/hooks/useOrientation/useOrientation.d.ts +26 -11
  238. package/dist/types/hooks/usePaint/usePaint.d.ts +1 -1
  239. package/dist/types/hooks/usePointerLock/usePointerLock.d.ts +1 -1
  240. package/dist/types/hooks/usePreferredColorScheme/usePreferredColorScheme.d.ts +1 -1
  241. package/dist/types/hooks/usePreferredContrast/usePreferredContrast.d.ts +1 -1
  242. package/dist/types/hooks/usePreferredDark/usePreferredDark.d.ts +1 -1
  243. package/dist/types/hooks/usePreferredLanguages/usePreferredLanguages.d.ts +1 -1
  244. package/dist/types/hooks/usePreferredReducedMotion/usePreferredReducedMotion.d.ts +1 -1
  245. package/dist/types/hooks/useQuery/useQuery.d.ts +1 -1
  246. package/dist/types/hooks/useQueue/useQueue.d.ts +1 -1
  247. package/dist/types/hooks/useRaf/useRaf.d.ts +1 -1
  248. package/dist/types/hooks/{useRafValue/useRafValue.d.ts → useRafState/useRafState.d.ts} +6 -6
  249. package/dist/types/hooks/useRefState/useRefState.d.ts +1 -1
  250. package/dist/types/hooks/useRenderCount/useRenderCount.d.ts +1 -1
  251. package/dist/types/hooks/useRenderInfo/useRenderInfo.d.ts +6 -1
  252. package/dist/types/hooks/useRerender/useRerender.d.ts +1 -1
  253. package/dist/types/hooks/useResizeObserver/useResizeObserver.d.ts +1 -1
  254. package/dist/types/hooks/useRightClick/useRightClick.d.ts +37 -0
  255. package/dist/types/hooks/useScript/useScript.d.ts +1 -1
  256. package/dist/types/hooks/useSessionStorage/useSessionStorage.d.ts +1 -1
  257. package/dist/types/hooks/useSet/useSet.d.ts +1 -1
  258. package/dist/types/hooks/useSpeechRecognition/useSpeechRecognition.d.ts +1 -1
  259. package/dist/types/hooks/useSpeechSynthesis/useSpeechSynthesis.d.ts +1 -1
  260. package/dist/types/hooks/useStateHistory/useStateHistory.d.ts +1 -1
  261. package/dist/types/hooks/useStep/useStep.d.ts +1 -1
  262. package/dist/types/hooks/useSticky/useSticky.d.ts +1 -1
  263. package/dist/types/hooks/useStopwatch/useStopwatch.d.ts +2 -2
  264. package/dist/types/hooks/useStorage/useStorage.d.ts +1 -1
  265. package/dist/types/hooks/useTextDirection/useTextDirection.d.ts +2 -2
  266. package/dist/types/hooks/useToggle/useToggle.d.ts +1 -1
  267. package/dist/types/hooks/useUrlSearchParam/useUrlSearchParam.d.ts +1 -1
  268. package/dist/types/hooks/useUrlSearchParams/useUrlSearchParams.d.ts +1 -1
  269. package/dist/types/hooks/useWindowEvent/useWindowEvent.d.ts +1 -1
  270. package/dist/types/hooks/useWizard/useWizard.d.ts +1 -1
  271. package/dist/types/hooks/user.d.ts +7 -0
  272. package/dist/types/hooks/utilities.d.ts +9 -0
  273. package/dist/types/utils/helpers/getElement.d.ts +1 -1
  274. package/package.json +89 -89
  275. package/dist/cjs/hooks/useRafValue/useRafValue.cjs.map +0 -1
  276. package/dist/cjs/hooks/useScreenOrientation/useScreenOrientation.cjs +0 -2
  277. package/dist/cjs/hooks/useScreenOrientation/useScreenOrientation.cjs.map +0 -1
  278. package/dist/esm/hooks/useRafValue/useRafValue.mjs.map +0 -1
  279. package/dist/esm/hooks/useScreenOrientation/useScreenOrientation.mjs +0 -31
  280. package/dist/esm/hooks/useScreenOrientation/useScreenOrientation.mjs.map +0 -1
  281. package/dist/types/hooks/useScreenOrientation/useScreenOrientation.d.ts +0 -35
@@ -1,4 +1,4 @@
1
- import { useState as f, useEffect as h } from "react";
1
+ import { useState as f, useEffect as y } from "react";
2
2
  const l = (t) => {
3
3
  if (!t)
4
4
  return {
@@ -8,14 +8,14 @@ const l = (t) => {
8
8
  seconds: 0,
9
9
  count: 0
10
10
  };
11
- const s = Math.floor(t / 86400), e = Math.floor(t % 86400 / 3600), c = Math.floor(t % 3600 / 60), u = Math.floor(t % 60);
12
- return { days: s, hours: e, minutes: c, seconds: u, count: t };
13
- }, M = (...t) => {
14
- const s = (typeof t[0] == "number" ? t[0] : t[0]?.initialTime) ?? 0, e = typeof t[0] == "number" ? t[1] : t[0], [c, u] = f(l(s)), [r, d] = f(!e?.enabled);
15
- return h(() => {
16
- if (r) return;
11
+ const s = Math.floor(t / 86400), d = Math.floor(t % 86400 / 3600), e = Math.floor(t % 3600 / 60), u = Math.floor(t % 60);
12
+ return { days: s, hours: d, minutes: e, seconds: u, count: t };
13
+ }, g = (...t) => {
14
+ const s = (typeof t[0] == "number" ? t[0] : t[0]?.initialTime) ?? 0, e = (typeof t[0] == "number" ? t[1] : t[0])?.immediately ?? !1, [u, i] = f(l(s)), [c, r] = f(!e && !s);
15
+ return y(() => {
16
+ if (c) return;
17
17
  const a = () => {
18
- u((n) => {
18
+ i((n) => {
19
19
  const o = n.count + 1;
20
20
  return o % 60 === 0 ? {
21
21
  ...n,
@@ -41,18 +41,18 @@ const l = (t) => {
41
41
  count: o
42
42
  };
43
43
  });
44
- }, i = setInterval(() => a(), 1e3);
45
- return () => clearInterval(i);
46
- }, [r]), {
47
- ...c,
48
- paused: r,
49
- pause: () => d(!0),
50
- start: () => d(!1),
51
- reset: () => u(l(s)),
52
- toggle: () => d((a) => !a)
44
+ }, h = setInterval(() => a(), 1e3);
45
+ return () => clearInterval(h);
46
+ }, [c]), {
47
+ ...u,
48
+ paused: c,
49
+ pause: () => r(!0),
50
+ start: () => r(!1),
51
+ reset: () => i(l(s)),
52
+ toggle: () => r((a) => !a)
53
53
  };
54
54
  };
55
55
  export {
56
- M as useStopwatch
56
+ g as useStopwatch
57
57
  };
58
58
  //# sourceMappingURL=useStopwatch.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useStopwatch.mjs","sources":["../../../../src/hooks/useStopwatch/useStopwatch.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nconst getStopwatchTime = (time: number) => {\n if (!time)\n return {\n days: 0,\n hours: 0,\n minutes: 0,\n seconds: 0,\n count: 0\n };\n\n const days = Math.floor(time / 86400);\n const hours = Math.floor((time % 86400) / 3600);\n const minutes = Math.floor((time % 3600) / 60);\n const seconds = Math.floor(time % 60);\n\n return { days, hours, minutes, seconds, count: time };\n};\n\n/** The use stopwatch return type */\nexport interface UseStopwatchReturn {\n /** The total count of the stopwatch */\n count: number;\n /** The day count of the stopwatch */\n days: number;\n /** The hour count of the stopwatch */\n hours: number;\n /** The minute count of the stopwatch */\n minutes: number;\n /** The over state of the stopwatch */\n over: boolean;\n /** The paused state of the stopwatch */\n paused: boolean;\n /** The second count of the stopwatch */\n seconds: number;\n /** The function to pause the stopwatch */\n pause: () => void;\n /** The function to reset the stopwatch */\n reset: () => void;\n /** The function to start the stopwatch */\n start: () => void;\n /** The function to toggle the stopwatch */\n toggle: () => void;\n}\n\n/** The use stopwatch options */\nexport interface UseStopwatchOptions {\n /** The enabled state of the timer */\n enabled?: boolean;\n}\n\ninterface UseStopwatch {\n (initialTime?: number, options?: UseStopwatchOptions): UseStopwatchReturn;\n (options?: UseStopwatchOptions & { initialTime?: number }): UseStopwatchReturn;\n}\n/**\n * @name useStopwatch\n * @description - Hook that creates a stopwatch functionality\n * @category Time\n *\n * @overload\n * @param {number} [initialTime=0] The initial time of the timer\n * @param {boolean} [options.enabled=true] The enabled state of the timer\n * @returns {UseStopwatchReturn} An object containing the current time and functions to interact with the timer\n *\n * @example\n * const { seconds, minutes, start, pause, reset } = useStopwatch(1000, { enabled: false });\n *\n * @overload\n * @param {number} [options.initialTime=0] -The initial time of the timer\n * @param {boolean} [options.enabled=true] The enabled state of the timer\n * @returns {UseStopwatchReturn} An object containing the current time and functions to interact with the timer\n *\n * @example\n * const { seconds, minutes, start, pause, reset } = useStopwatch({ initialTime: 1000, enabled: false });\n */\nexport const useStopwatch = ((...params: any[]) => {\n const initialTime =\n (typeof params[0] === 'number'\n ? (params[0] as number | undefined)\n : (params[0] as UseStopwatchOptions & { initialTime?: number })?.initialTime) ?? 0;\n\n const options =\n typeof params[0] === 'number'\n ? (params[1] as UseStopwatchOptions | undefined)\n : (params[0] as (UseStopwatchOptions & { initialTime?: number }) | undefined);\n\n const [time, setTime] = useState(getStopwatchTime(initialTime));\n const [paused, setPaused] = useState(!options?.enabled);\n\n useEffect(() => {\n if (paused) return;\n const onInterval = () => {\n setTime((prevTime) => {\n const updatedCount = prevTime.count + 1;\n\n if (updatedCount % 60 === 0) {\n return {\n ...prevTime,\n minutes: prevTime.minutes + 1,\n seconds: 0,\n count: updatedCount\n };\n }\n\n if (updatedCount % (60 * 60) === 0) {\n return {\n ...prevTime,\n hours: prevTime.hours + 1,\n minutes: 0,\n seconds: 0,\n count: updatedCount\n };\n }\n\n if (updatedCount % (60 * 60 * 24) === 0) {\n return {\n ...prevTime,\n days: prevTime.days + 1,\n hours: 0,\n minutes: 0,\n seconds: 0,\n count: updatedCount\n };\n }\n\n return {\n ...prevTime,\n seconds: prevTime.seconds + 1,\n count: updatedCount\n };\n });\n };\n\n const interval = setInterval(() => onInterval(), 1000);\n return () => clearInterval(interval);\n }, [paused]);\n\n return {\n ...time,\n paused,\n pause: () => setPaused(true),\n start: () => setPaused(false),\n reset: () => setTime(getStopwatchTime(initialTime)),\n toggle: () => setPaused((prevPause) => !prevPause)\n };\n}) as UseStopwatch;\n"],"names":["getStopwatchTime","time","days","hours","minutes","seconds","useStopwatch","params","initialTime","options","setTime","useState","paused","setPaused","useEffect","onInterval","prevTime","updatedCount","interval","prevPause"],"mappings":";AAEA,MAAMA,IAAmB,CAACC,MAAiB;AACzC,MAAI,CAACA;AACH,WAAO;AAAA,MACL,MAAM;AAAA,MACN,OAAO;AAAA,MACP,SAAS;AAAA,MACT,SAAS;AAAA,MACT,OAAO;AAAA,IAAA;AAGX,QAAMC,IAAO,KAAK,MAAMD,IAAO,KAAK,GAC9BE,IAAQ,KAAK,MAAOF,IAAO,QAAS,IAAI,GACxCG,IAAU,KAAK,MAAOH,IAAO,OAAQ,EAAE,GACvCI,IAAU,KAAK,MAAMJ,IAAO,EAAE;AAEpC,SAAO,EAAE,MAAAC,GAAM,OAAAC,GAAO,SAAAC,GAAS,SAAAC,GAAS,OAAOJ,EAAA;AACjD,GA2DaK,IAAgB,IAAIC,MAAkB;AACjD,QAAMC,KACH,OAAOD,EAAO,CAAC,KAAM,WACjBA,EAAO,CAAC,IACRA,EAAO,CAAC,GAA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c,CAACA,CAAS;AAAA,EAAA;AAErD;"}
1
+ {"version":3,"file":"useStopwatch.mjs","sources":["../../../../src/hooks/useStopwatch/useStopwatch.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nconst getStopwatchTime = (time: number) => {\n if (!time)\n return {\n days: 0,\n hours: 0,\n minutes: 0,\n seconds: 0,\n count: 0\n };\n\n const days = Math.floor(time / 86400);\n const hours = Math.floor((time % 86400) / 3600);\n const minutes = Math.floor((time % 3600) / 60);\n const seconds = Math.floor(time % 60);\n\n return { days, hours, minutes, seconds, count: time };\n};\n\n/** The use stopwatch return type */\nexport interface UseStopwatchReturn {\n /** The total count of the stopwatch */\n count: number;\n /** The day count of the stopwatch */\n days: number;\n /** The hour count of the stopwatch */\n hours: number;\n /** The minute count of the stopwatch */\n minutes: number;\n /** The over state of the stopwatch */\n over: boolean;\n /** The paused state of the stopwatch */\n paused: boolean;\n /** The second count of the stopwatch */\n seconds: number;\n /** The function to pause the stopwatch */\n pause: () => void;\n /** The function to reset the stopwatch */\n reset: () => void;\n /** The function to start the stopwatch */\n start: () => void;\n /** The function to toggle the stopwatch */\n toggle: () => void;\n}\n\n/** The use stopwatch options */\nexport interface UseStopwatchOptions {\n /** The immediately state of the timer */\n immediately?: boolean;\n}\n\ninterface UseStopwatch {\n (initialTime?: number, options?: UseStopwatchOptions): UseStopwatchReturn;\n (options?: UseStopwatchOptions & { initialTime?: number }): UseStopwatchReturn;\n}\n/**\n * @name useStopwatch\n * @description - Hook that creates a stopwatch functionality\n * @category Time\n *\n * @overload\n * @param {number} [initialTime=0] The initial time of the timer\n * @param {boolean} [options.enabled=true] The enabled state of the timer\n * @returns {UseStopwatchReturn} An object containing the current time and functions to interact with the timer\n *\n * @example\n * const { seconds, minutes, start, pause, reset } = useStopwatch(1000, { enabled: false });\n *\n * @overload\n * @param {number} [options.initialTime=0] -The initial time of the timer\n * @param {boolean} [options.enabled=true] The enabled state of the timer\n * @returns {UseStopwatchReturn} An object containing the current time and functions to interact with the timer\n *\n * @example\n * const { seconds, minutes, start, pause, reset } = useStopwatch({ initialTime: 1000, enabled: false });\n */\nexport const useStopwatch = ((...params: any[]) => {\n const initialTime =\n (typeof params[0] === 'number'\n ? (params[0] as number | undefined)\n : (params[0] as UseStopwatchOptions & { initialTime?: number })?.initialTime) ?? 0;\n\n const options =\n typeof params[0] === 'number'\n ? (params[1] as UseStopwatchOptions | undefined)\n : (params[0] as (UseStopwatchOptions & { initialTime?: number }) | undefined);\n\n const immediately = options?.immediately ?? false;\n\n const [time, setTime] = useState(getStopwatchTime(initialTime));\n const [paused, setPaused] = useState(!immediately && !initialTime);\n\n useEffect(() => {\n if (paused) return;\n const onInterval = () => {\n setTime((prevTime) => {\n const updatedCount = prevTime.count + 1;\n\n if (updatedCount % 60 === 0) {\n return {\n ...prevTime,\n minutes: prevTime.minutes + 1,\n seconds: 0,\n count: updatedCount\n };\n }\n\n if (updatedCount % (60 * 60) === 0) {\n return {\n ...prevTime,\n hours: prevTime.hours + 1,\n minutes: 0,\n seconds: 0,\n count: updatedCount\n };\n }\n\n if (updatedCount % (60 * 60 * 24) === 0) {\n return {\n ...prevTime,\n days: prevTime.days + 1,\n hours: 0,\n minutes: 0,\n seconds: 0,\n count: updatedCount\n };\n }\n\n return {\n ...prevTime,\n seconds: prevTime.seconds + 1,\n count: updatedCount\n };\n });\n };\n\n const interval = setInterval(() => onInterval(), 1000);\n return () => clearInterval(interval);\n }, [paused]);\n\n return {\n ...time,\n paused,\n pause: () => setPaused(true),\n start: () => setPaused(false),\n reset: () => setTime(getStopwatchTime(initialTime)),\n toggle: () => setPaused((prevPause) => !prevPause)\n };\n}) as UseStopwatch;\n"],"names":["getStopwatchTime","time","days","hours","minutes","seconds","useStopwatch","params","initialTime","immediately","setTime","useState","paused","setPaused","useEffect","onInterval","prevTime","updatedCount","interval","prevPause"],"mappings":";AAEA,MAAMA,IAAmB,CAACC,MAAiB;AACzC,MAAI,CAACA;AACH,WAAO;AAAA,MACL,MAAM;AAA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T,SAAS;AAAA,UACT,OAAOC;AAAA,QAAA,IAIJ;AAAA,UACL,GAAGD;AAAA,UACH,SAASA,EAAS,UAAU;AAAA,UAC5B,OAAOC;AAAA,QAAA;AAAA,MACT,CACD;AAAA,IAAA,GAGGC,IAAW,YAAY,MAAMH,EAAA,GAAc,GAAI;AACrD,WAAO,MAAM,cAAcG,CAAQ;AAAA,EAAA,GAClC,CAACN,CAAM,CAAC,GAEJ;AAAA,IACL,GAAGX;AAAA,IACH,QAAAW;AAAA,IACA,OAAO,MAAMC,EAAU,EAAI;AAAA,IAC3B,OAAO,MAAMA,EAAU,EAAK;AAAA,IAC5B,OAAO,MAAMH,EAAQV,EAAiBQ,CAAW,CAAC;AAAA,IAClD,QAAQ,MAAMK,EAAU,CAACM,MAAc,CAACA,CAAS;AAAA,EAAA;AAErD;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useStorage.mjs","sources":["../../../../src/hooks/useStorage/useStorage.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/* The use storage initial value type */\nexport type UseStorageInitialValue<Value> = (() => Value) | Value;\n\n/* The use storage options type */\nexport interface UseStorageOptions<Value> {\n /* The initial value of the storage */\n initialValue?: UseStorageInitialValue<Value>;\n /* The storage to be used */\n storage?: Storage;\n /* The deserializer function to be invoked */\n deserializer?: (value: string) => Value;\n /* The serializer function to be invoked */\n serializer?: (value: Value) => string;\n}\n\n/* The use storage return type */\nexport interface UseStorageReturn<Value> {\n /* The value of the storage */\n value: Value;\n /* The error state of the storage */\n remove: () => void;\n /* The loading state of the storage */\n set: (value: Value) => void;\n}\n\nexport interface UseStorage {\n <Value>(key: string, options?: UseStorageOptions<Value>): UseStorageReturn<Value | undefined>;\n\n <Value>(\n key: string,\n initialValue?: UseStorageInitialValue<Value>\n ): UseStorageReturn<Value | undefined>;\n}\n\nexport const STORAGE_EVENT = 'reactuse-storage';\n\nexport const dispatchStorageEvent = (params: Partial<StorageEvent>) =>\n window.dispatchEvent(new StorageEvent(STORAGE_EVENT, params));\n\nconst setStorageItem = (storage: Storage, key: string, value: string) => {\n const oldValue = storage.getItem(key);\n\n storage.setItem(key, value);\n dispatchStorageEvent({\n key,\n oldValue,\n newValue: value,\n storageArea: storage\n });\n};\n\nconst removeStorageItem = (storage: Storage, key: string) => {\n const oldValue = storage.getItem(key);\n\n storage.removeItem(key);\n dispatchStorageEvent({ key, oldValue, newValue: null, storageArea: storage });\n};\n\nconst getStorageItem = (storage: Storage, key: string) => {\n const value = storage.getItem(key);\n if (!value) return undefined;\n return value;\n};\n\n/**\n * @name useStorage\n * @description - Hook that manages storage value\n * @category Browser\n *\n * @overload\n * @param {string} key The key of the storage\n * @param {UseStorageInitialValue<Value>} [initialValue] The initial value of the storage\n * @returns {UseStorageReturn<Value>} The value and the set function\n *\n * @overload\n * @param {string} key The key of the storage\n * @param {(value: Value) => string} [params.serializer] The serializer function\n * @param {(value: string) => Value} [params.deserializer] The deserializer function\n * @param {Storage} [params.storage] The storage\n * @param {UseStorageInitialValue<Value>} [params.initialValue] The initial value of the storage\n * @returns {UseStorageReturn<Value>} The value and the set function\n *\n * @example\n * const { value, set, remove } = useStorage('key', 'value');\n */\nexport const useStorage = (<Value>(key: string, params?: any): UseStorageReturn<Value> => {\n const options = (\n typeof params === 'object' &&\n params &&\n ('serializer' in params ||\n 'deserializer' in params ||\n 'initialValue' in params ||\n 'storage' in params)\n ? params\n : undefined\n ) as UseStorageOptions<Value>;\n\n const initialValue = (options ? options?.initialValue : params) as UseStorageInitialValue<Value>;\n\n if (typeof window === 'undefined') {\n const value = typeof initialValue === 'function' ? (initialValue as () => any)() : initialValue;\n return {\n value,\n set: () => {},\n remove: () => {}\n };\n }\n\n const serializer = (value: Value) => {\n if (options?.serializer) return options.serializer(value);\n if (typeof value === 'string') return value;\n return JSON.stringify(value);\n };\n\n const storage = options?.storage ?? window?.localStorage;\n\n const set = (value: Value) => setStorageItem(storage, key, serializer(value));\n const remove = () => removeStorageItem(storage, key);\n\n const deserializer = (value: string) => {\n if (options?.deserializer) return options.deserializer(value);\n if (value === 'undefined') return undefined as unknown as Value;\n\n try {\n return JSON.parse(value) as Value;\n } catch {\n return value as Value;\n }\n };\n\n const [value, setValue] = useState<Value | undefined>(() => {\n const storageValue = getStorageItem(storage, key);\n if (storageValue === undefined && initialValue !== undefined) {\n const value =\n typeof initialValue === 'function' ? (initialValue as () => Value)() : initialValue;\n setStorageItem(storage, key, serializer(value));\n return value;\n }\n return storageValue ? deserializer(storageValue) : undefined;\n });\n\n useEffect(() => {\n const onChange = () => {\n const storageValue = getStorageItem(storage, key);\n setValue(storageValue ? deserializer(storageValue) : undefined);\n };\n window.addEventListener(STORAGE_EVENT, onChange);\n return () => window.removeEventListener(STORAGE_EVENT, onChange);\n }, [key]);\n\n return {\n value: value as Value,\n set,\n remove\n };\n}) as UseStorage;\n"],"names":["STORAGE_EVENT","dispatchStorageEvent","params","setStorageItem","storage","key","value","oldValue","removeStorageItem","getStorageItem","useStorage","options","initialValue","serializer","set","remove","deserializer","setValue","useState","storageValue","useEffect","onChange"],"mappings":";AAoCO,MAAMA,IAAgB,oBAEhBC,IAAuB,CAACC,MACnC,OAAO,cAAc,IAAI,aAAaF,GAAeE,CAAM,CAAC,GAExDC,IAAiB,CAACC,GAAkBC,GAAaC,MAAkB;AACvE,QAAMC,IAAWH,EAAQ,QAAQC,CAAG;AAEpC,EAAAD,EAAQ,QAAQC,GAAKC,CAAK,GAC1BL,EAAqB;AAAA,IACnB,KAAAI;AAAA,IACA,UAAAE;AAAA,IACA,UAAUD;AAAA,IACV,aAAaF;AAAA,EAAA,CACd;AACH,GAEMI,IAAoB,CAACJ,GAAkBC,MAAgB;AAC3D,QAAME,IAAWH,EAAQ,QAAQC,CAAG;AAEpC,EAAAD,EAAQ,WAAWC,CAAG,GACtBJ,EAAqB,EAAE,KAAAI,GAAK,UAAAE,GAAU,UAAU,MAAM,aAAaH,GAAS;AAC9E,GAEMK,IAAiB,CAACL,GAAkBC,MAAgB;AACxD,QAAMC,IA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,YAAMF,IAAeV,EAAeL,GAASC,CAAG;AAChD,MAAAY,EAASE,IAAeH,EAAaG,CAAY,IAAI,MAAS;AAAA,IAAA;AAEhE,kBAAO,iBAAiBnB,GAAeqB,CAAQ,GACxC,MAAM,OAAO,oBAAoBrB,GAAeqB,CAAQ;AAAA,EAAA,GAC9D,CAAChB,CAAG,CAAC,GAED;AAAA,IACL,OAAAC;AAAA,IACA,KAAAQ;AAAA,IACA,QAAAC;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"useStorage.mjs","sources":["../../../../src/hooks/useStorage/useStorage.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/* The use storage initial value type */\nexport type UseStorageInitialValue<Value> = (() => Value) | Value;\n\n/* The use storage options type */\nexport interface UseStorageOptions<Value> {\n /* The initial value of the storage */\n initialValue?: UseStorageInitialValue<Value>;\n /* The storage to be used */\n storage?: Storage;\n /* The deserializer function to be invoked */\n deserializer?: (value: string) => Value;\n /* The serializer function to be invoked */\n serializer?: (value: Value) => string;\n}\n\n/* The use storage return type */\nexport interface UseStorageReturn<Value> {\n /* The value of the storage */\n value: Value;\n /* The error state of the storage */\n remove: () => void;\n /* The loading state of the storage */\n set: (value: Value) => void;\n}\n\nexport interface UseStorage {\n <Value>(key: string, options?: UseStorageOptions<Value>): UseStorageReturn<Value | undefined>;\n\n <Value>(\n key: string,\n initialValue?: UseStorageInitialValue<Value>\n ): UseStorageReturn<Value | undefined>;\n}\n\nexport const STORAGE_EVENT = 'reactuse-storage';\n\nexport const dispatchStorageEvent = (params: Partial<StorageEvent>) =>\n window.dispatchEvent(new StorageEvent(STORAGE_EVENT, params));\n\nconst setStorageItem = (storage: Storage, key: string, value: string) => {\n const oldValue = storage.getItem(key);\n\n storage.setItem(key, value);\n dispatchStorageEvent({\n key,\n oldValue,\n newValue: value,\n storageArea: storage\n });\n};\n\nconst removeStorageItem = (storage: Storage, key: string) => {\n const oldValue = storage.getItem(key);\n\n storage.removeItem(key);\n dispatchStorageEvent({ key, oldValue, newValue: null, storageArea: storage });\n};\n\nconst getStorageItem = (storage: Storage, key: string) => {\n const value = storage.getItem(key);\n if (!value) return undefined;\n return value;\n};\n\n/**\n * @name useStorage\n * @description - Hook that manages storage value\n * @category State\n *\n * @overload\n * @param {string} key The key of the storage\n * @param {UseStorageInitialValue<Value>} [initialValue] The initial value of the storage\n * @returns {UseStorageReturn<Value>} The value and the set function\n *\n * @overload\n * @param {string} key The key of the storage\n * @param {(value: Value) => string} [params.serializer] The serializer function\n * @param {(value: string) => Value} [params.deserializer] The deserializer function\n * @param {Storage} [params.storage] The storage\n * @param {UseStorageInitialValue<Value>} [params.initialValue] The initial value of the storage\n * @returns {UseStorageReturn<Value>} The value and the set function\n *\n * @example\n * const { value, set, remove } = useStorage('key', 'value');\n */\nexport const useStorage = (<Value>(key: string, params?: any): UseStorageReturn<Value> => {\n const options = (\n typeof params === 'object' &&\n params &&\n ('serializer' in params ||\n 'deserializer' in params ||\n 'initialValue' in params ||\n 'storage' in params)\n ? params\n : undefined\n ) as UseStorageOptions<Value>;\n\n const initialValue = (options ? options?.initialValue : params) as UseStorageInitialValue<Value>;\n\n if (typeof window === 'undefined') {\n const value = typeof initialValue === 'function' ? (initialValue as () => any)() : initialValue;\n return {\n value,\n set: () => {},\n remove: () => {}\n };\n }\n\n const serializer = (value: Value) => {\n if (options?.serializer) return options.serializer(value);\n if (typeof value === 'string') return value;\n return JSON.stringify(value);\n };\n\n const storage = options?.storage ?? window?.localStorage;\n\n const set = (value: Value) => setStorageItem(storage, key, serializer(value));\n const remove = () => removeStorageItem(storage, key);\n\n const deserializer = (value: string) => {\n if (options?.deserializer) return options.deserializer(value);\n if (value === 'undefined') return undefined as unknown as Value;\n\n try {\n return JSON.parse(value) as Value;\n } catch {\n return value as Value;\n }\n };\n\n const [value, setValue] = useState<Value | undefined>(() => {\n const storageValue = getStorageItem(storage, key);\n if (storageValue === undefined && initialValue !== undefined) {\n const value =\n typeof initialValue === 'function' ? (initialValue as () => Value)() : initialValue;\n setStorageItem(storage, key, serializer(value));\n return value;\n }\n return storageValue ? deserializer(storageValue) : undefined;\n });\n\n useEffect(() => {\n const onChange = () => {\n const storageValue = getStorageItem(storage, key);\n setValue(storageValue ? deserializer(storageValue) : undefined);\n };\n window.addEventListener(STORAGE_EVENT, onChange);\n return () => window.removeEventListener(STORAGE_EVENT, onChange);\n }, [key]);\n\n return {\n value: value as Value,\n set,\n remove\n };\n}) as UseStorage;\n"],"names":["STORAGE_EVENT","dispatchStorageEvent","params","setStorageItem","storage","key","value","oldValue","removeStorageItem","getStorageItem","useStorage","options","initialValue","serializer","set","remove","deserializer","setValue","useState","storageValue","useEffect","onChange"],"mappings":";AAoCO,MAAMA,IAAgB,oBAEhBC,IAAuB,CAACC,MACnC,OAAO,cAAc,IAAI,aAAaF,GAAeE,CAAM,CAAC,GAExDC,IAAiB,CAACC,GAAkBC,GAAaC,MAAkB;AACvE,QAAMC,IAAWH,EAAQ,QAAQC,CAAG;AAEpC,EAAAD,EAAQ,QAAQC,GAAKC,CAAK,GAC1BL,EAAqB;AAAA,IACnB,KAAAI;AAAA,IACA,UAAAE;AAAA,IACA,UAAUD;AAAA,IACV,aAAaF;AAAA,EAAA,CACd;AACH,GAEMI,IAAoB,CAACJ,GAAkBC,MAAgB;AAC3D,QAAME,IAAWH,EAAQ,QAAQC,CAAG;AAEpC,EAAAD,EAAQ,WAAWC,CAAG,GACtBJ,EAAqB,EAAE,KAAAI,GAAK,UAAAE,GAAU,UAAU,MAAM,aAAaH,GAAS;AAC9E,GAEMK,IAAiB,CAACL,GAAkBC,MAAgB;AACxD,QAAMC,IAAQF,EAAQ,QAAQC,CAAG;AACjC,MAAKC;AACL,WAAOA;AACT,GAuBaI,IAAc,CAAQL,GAAaH,MAA0C;AACxF,QAAMS,IACJ,OAAOT,KAAW,YAClBA,MACC,gBAAgBA,KACf,kBAAkBA,KAClB,kBAAkBA,KAClB,aAAaA,KACXA,IACA,QAGAU,IAAgBD,IAAUA,GAAS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AAAA,IACL,OAAAC;AAAA,IACA,KAAAQ;AAAA,IACA,QAAAC;AAAA,EAAA;AAEJ;"}
@@ -1,30 +1,29 @@
1
- import { useState as d, useEffect as a } from "react";
2
- import { useRefState as v } from "../useRefState/useRefState.mjs";
3
- import { isTarget as g } from "../../utils/helpers/isTarget.mjs";
4
- import { getElement as i } from "../../utils/helpers/getElement.mjs";
1
+ import { useRef as a, useState as v, useEffect as g } from "react";
2
+ import { useRefState as A } from "../useRefState/useRefState.mjs";
3
+ import { isTarget as R } from "../../utils/helpers/isTarget.mjs";
4
+ import { getElement as b } from "../../utils/helpers/getElement.mjs";
5
5
  const E = (...o) => {
6
- const t = g(o[0]) ? o[0] : void 0, b = (t ? o[1] : o[0]) ?? "ltr", r = v(), s = () => (t ? i(t) : r.current)?.getAttribute("dir") ?? b, [u, c] = d(s()), f = () => {
7
- const e = t ? i(t) : r.current;
8
- e && e?.removeAttribute("dir");
9
- }, m = (e) => {
10
- const n = t ? i(t) : r.current;
11
- n && (c(e), n.setAttribute("dir", e));
6
+ const t = R(o[0]) ? o[0] : void 0, d = (t ? o[1] : o[0]) ?? "ltr", r = A(), n = a(null), i = () => (t ? b(t) : r.current)?.getAttribute("dir") ?? d, [u, c] = v(i()), s = () => {
7
+ n.current && n.current?.removeAttribute("dir");
8
+ }, f = (e) => {
9
+ n.current && (c(e), n.current.setAttribute("dir", e));
12
10
  };
13
- return a(() => {
11
+ return g(() => {
14
12
  if (!t && !r.state) return;
15
- const e = t ? i(t) : r.current;
13
+ const e = (t ? b(t) : r.current) ?? document.querySelector("html");
16
14
  if (!e) return;
17
- const n = s();
18
- e.setAttribute("dir", n), c(n);
19
- const l = new MutationObserver(s);
20
- return l.observe(e, { attributes: !0 }), () => {
21
- l.disconnect();
15
+ n.current = e;
16
+ const l = i();
17
+ e.setAttribute("dir", l), c(l);
18
+ const m = new MutationObserver(i);
19
+ return m.observe(e, { attributes: !0 }), () => {
20
+ m.disconnect();
22
21
  };
23
- }, [r.state, t]), t ? { value: u, set: m, remove: f } : {
22
+ }, [r.state, t]), t ? { value: u, set: f, remove: s } : {
24
23
  ref: r,
25
24
  value: u,
26
- set: m,
27
- remove: f
25
+ set: f,
26
+ remove: s
28
27
  };
29
28
  };
30
29
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"useTextDirection.mjs","sources":["../../../../src/hooks/useTextDirection/useTextDirection.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use text direction value type */\nexport type UseTextDirectionValue = 'auto' | 'ltr' | 'rtl';\n\n/** The use text direction return type */\nexport interface UseTextDirectionReturn {\n /** The current direction */\n value: UseTextDirectionValue;\n /*** The function to remove the direction */\n remove: () => void;\n /*** The function to set the direction */\n set: (value: UseTextDirectionValue | null) => void;\n}\n\nexport interface UseTextDirection {\n (target: HookTarget, initialValue?: UseTextDirectionValue): UseTextDirectionReturn;\n\n <Target extends Element>(\n initialValue?: UseTextDirectionValue,\n target?: never\n ): UseTextDirectionReturn & { ref: StateRef<Target> };\n}\n\n/**\n * @name useTextDirection\n * @description - Hook that can get and set the direction of the element\n * @category Browser\n *\n * @overload\n * @param {HookTarget} target The target element to observe\n * @param {UseTextDirectionValue} [initialValue = 'ltr'] The initial direction of the element\n * @returns {UseTextDirectionReturn} An object containing the current text direction of the element\n *\n * @example\n * const { value, set, remove } = useTextDirection(ref);\n *\n * @overload\n * @template Target The target element type\n * @param {UseTextDirectionValue} [initialValue = 'ltr'] The initial direction of the element\n * @returns { { ref: StateRef<Target> } & UseTextDirectionReturn } An object containing the current text direction of the element\n *\n * @example\n * const { ref, value, set, remove } = useTextDirection();\n */\nexport const useTextDirection = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const initialValue = ((target ? params[1] : params[0]) as UseTextDirectionValue) ?? 'ltr';\n\n const internalRef = useRefState<Element>();\n\n const getDirection = () => {\n const element = (target ? getElement(target) : internalRef.current) as Element;\n return (element?.getAttribute('dir') as UseTextDirectionValue) ?? initialValue;\n };\n\n const [value, setValue] = useState<UseTextDirectionValue>(getDirection());\n\n const remove = () => {\n const element = (target ? getElement(target) : internalRef.current) as Element;\n if (!element) return;\n\n element?.removeAttribute('dir');\n };\n\n const set = (value: UseTextDirectionValue) => {\n const element = (target ? getElement(target) : internalRef.current) as Element;\n if (!element) return;\n\n setValue(value);\n element.setAttribute('dir', value);\n };\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n\n const element = (target ? getElement(target) : internalRef.current) as Element;\n if (!element) return;\n\n const direction = getDirection();\n element.setAttribute('dir', direction);\n setValue(direction);\n\n const observer = new MutationObserver(getDirection);\n\n observer.observe(element, { attributes: true });\n\n return () => {\n observer.disconnect();\n };\n }, [internalRef.state, target]);\n\n if (target) return { value, set, remove };\n return {\n ref: internalRef,\n value,\n set,\n remove\n };\n}) as UseTextDirection;\n"],"names":["useTextDirection","params","target","isTarget","initialValue","internalRef","useRefState","getDirection","getElement","value","setValue","useState","remove","element","set","useEffect","direction","observer"],"mappings":";;;;AAqDO,MAAMA,IAAoB,IAAIC,MAAkB;AACrD,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,KAAiBF,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,MAAgC,OAE9EI,IAAcC,EAAA,GAEdC,IAAe,OACFL,IAASM,EAAWN,CAAM,IAAIG,EAAY,UAC1C,aAAa,KAAK,KAA+BD,GAG9D,CAACK,GAAOC,CAAQ,IAAIC,EAAgCJ,GAAc,GAElEK,IAAS,MAAM;AACnB,UAAMC,IAAWX,IAASM,EAAWN,CAAM,IAAIG,EAAY;AAC3D,IAAKQ,KAELA,GAAS,gBAAgB,KAAK;AAAA,EAAA,GAG1BC,IAAM,CAACL,MAAiC;AAC5C,UAAMI,IAAWX,IAASM,EAAWN,CAAM,IAAIG,EAAY;AAC3D,IAAKQ,MAELH,EAASD,CAAK,GACdI,EAAQ,aAAa,OAAOJ,CAAK;AAAA,EAAA;AAsBnC,SAnBAM,EAAU,MAAM;AACd,QAAI,CAACb,KAAU,CAACG,EAAY,MAAO;AAEnC,UAAMQ,IAAWX,IAASM,EAAWN,CAAM,IAAIG,EAAY;AAC3D,QAAI,CAACQ,EAAS;AAEd,UAAMG,IAAYT,EAAA;AAClB,IAAAM,EAAQ,aAAa,OAAOG,CAAS,GACrCN,EAASM,CAAS;AAElB,UAAMC,IAAW,IAAI,iBAAiBV,CAAY;AAElD,WAAAU,EAAS,QAAQJ,GAAS,EAAE,YAAY,IAAM,GAEvC,MAAM;AACX,MAAAI,EAAS,WAAA;AAAA,IAAW;AAAA,EACtB,GACC,CAACZ,EAAY,OAAOH,CAAM,CAAC,GAE1BA,IAAe,EAAE,OAAAO,GAAO,KAAAK,GAAK,QAAAF,EAAA,IAC1B;AAAA,IACL,KAAKP;AAAA,IACL,OAAAI;AAAA,IACA,KAAAK;AAAA,IACA,QAAAF;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"useTextDirection.mjs","sources":["../../../../src/hooks/useTextDirection/useTextDirection.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use text direction value type */\nexport type UseTextDirectionValue = 'auto' | 'ltr' | 'rtl';\n\n/** The use text direction return type */\nexport interface UseTextDirectionReturn {\n /** The current direction */\n value: UseTextDirectionValue;\n /*** The function to remove the direction */\n remove: () => void;\n /*** The function to set the direction */\n set: (value: UseTextDirectionValue | null) => void;\n}\n\nexport interface UseTextDirection {\n (target: HookTarget, initialValue?: UseTextDirectionValue): UseTextDirectionReturn;\n\n <Target extends Element>(\n initialValue?: UseTextDirectionValue,\n target?: never\n ): UseTextDirectionReturn & { ref: StateRef<Target> };\n}\n\n/**\n * @name useTextDirection\n * @description - Hook that can get and set the direction of the element\n * @category Elements\n *\n * @overload\n * @param {HookTarget} [target=document.querySelector('html')] The target element to observe\n * @param {UseTextDirectionValue} [initialValue = 'ltr'] The initial direction of the element\n * @returns {UseTextDirectionReturn} An object containing the current text direction of the element\n *\n * @example\n * const { value, set, remove } = useTextDirection(ref);\n *\n * @overload\n * @template Target The target element type\n * @param {UseTextDirectionValue} [initialValue = 'ltr'] The initial direction of the element\n * @returns { { ref: StateRef<Target> } & UseTextDirectionReturn } An object containing the current text direction of the element\n *\n * @example\n * const { ref, value, set, remove } = useTextDirection();\n */\nexport const useTextDirection = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const initialValue = ((target ? params[1] : params[0]) as UseTextDirectionValue) ?? 'ltr';\n\n const internalRef = useRefState();\n const elementRef = useRef<Element>(null);\n\n const getDirection = () => {\n const element = (target ? getElement(target) : internalRef.current) as Element;\n return (element?.getAttribute('dir') as UseTextDirectionValue) ?? initialValue;\n };\n\n const [value, setValue] = useState<UseTextDirectionValue>(getDirection());\n\n const remove = () => {\n if (!elementRef.current) return;\n\n elementRef.current?.removeAttribute('dir');\n };\n\n const set = (value: UseTextDirectionValue) => {\n if (!elementRef.current) return;\n\n setValue(value);\n elementRef.current.setAttribute('dir', value);\n };\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n\n const element =\n ((target ? getElement(target) : internalRef.current) as Element) ??\n document.querySelector('html');\n if (!element) return;\n\n elementRef.current = element;\n\n const direction = getDirection();\n element.setAttribute('dir', direction);\n setValue(direction);\n\n const observer = new MutationObserver(getDirection);\n\n observer.observe(element, { attributes: true });\n\n return () => {\n observer.disconnect();\n };\n }, [internalRef.state, target]);\n\n if (target) return { value, set, remove };\n return {\n ref: internalRef,\n value,\n set,\n remove\n };\n}) as UseTextDirection;\n"],"names":["useTextDirection","params","target","isTarget","initialValue","internalRef","useRefState","elementRef","useRef","getDirection","getElement","value","setValue","useState","remove","set","useEffect","element","direction","observer"],"mappings":";;;;AAqDO,MAAMA,IAAoB,IAAIC,MAAkB;AACrD,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,KAAiBF,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,MAAgC,OAE9EI,IAAcC,EAAA,GACdC,IAAaC,EAAgB,IAAI,GAEjCC,IAAe,OACFP,IAASQ,EAAWR,CAAM,IAAIG,EAAY,UAC1C,aAAa,KAAK,KAA+BD,GAG9D,CAACO,GAAOC,CAAQ,IAAIC,EAAgCJ,GAAc,GAElEK,IAAS,MAAM;AACnB,IAAKP,EAAW,WAEhBA,EAAW,SAAS,gBAAgB,KAAK;AAAA,EAAA,GAGrCQ,IAAM,CAACJ,MAAiC;AAC5C,IAAKJ,EAAW,YAEhBK,EAASD,CAAK,GACdJ,EAAW,QAAQ,aAAa,OAAOI,CAAK;AAAA,EAAA;AA0B9C,SAvBAK,EAAU,MAAM;AACd,QAAI,CAACd,KAAU,CAACG,EAAY,MAAO;AAEnC,UAAMY,KACFf,IAASQ,EAAWR,CAAM,IAAIG,EAAY,YAC5C,SAAS,cAAc,MAAM;AAC/B,QAAI,CAACY,EAAS;AAEd,IAAAV,EAAW,UAAUU;AAErB,UAAMC,IAAYT,EAAA;AAClB,IAAAQ,EAAQ,aAAa,OAAOC,CAAS,GACrCN,EAASM,CAAS;AAElB,UAAMC,IAAW,IAAI,iBAAiBV,CAAY;AAElD,WAAAU,EAAS,QAAQF,GAAS,EAAE,YAAY,IAAM,GAEvC,MAAM;AACX,MAAAE,EAAS,WAAA;AAAA,IAAW;AAAA,EACtB,GACC,CAACd,EAAY,OAAOH,CAAM,CAAC,GAE1BA,IAAe,EAAE,OAAAS,GAAO,KAAAI,GAAK,QAAAD,EAAA,IAC1B;AAAA,IACL,KAAKT;AAAA,IACL,OAAAM;AAAA,IACA,KAAAI;AAAA,IACA,QAAAD;AAAA,EAAA;AAEJ;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useToggle.mjs","sources":["../../../../src/hooks/useToggle/useToggle.ts"],"sourcesContent":["import type { SetStateAction } from 'react';\n\nimport { useReducer } from 'react';\n\n/** The use toggle return type */\nexport type UseToggleReturn<Value> = readonly [Value, (value?: Value) => void];\n\n/**\n * @name useToggle\n * @description - Hook that create toggle\n * @category Utilities\n *\n * @template Value The type of the value\n * @param {Value[]} [values=[false, true]] The values to toggle\n *\n * @example\n * const [on, toggle] = useToggle();\n *\n * @example\n * const [value, toggle] = useToggle(['light', 'dark'] as const);\n */\nexport const useToggle = <Value = boolean>(values: readonly Value[] = [false, true] as any) => {\n const [[option], toggle] = useReducer((state: Value[], action: SetStateAction<Value>) => {\n const value =\n typeof action === 'function' ? (action as (prevState: Value) => Value)(state[0]) : action;\n const index = Math.abs(state.indexOf(value));\n return state.slice(index).concat(state.slice(0, index));\n }, values as Value[]);\n\n return [option, toggle as (value?: SetStateAction<Value>) => void] as const;\n};\n"],"names":["useToggle","values","option","toggle","useReducer","state","action","value","index"],"mappings":";AAqBO,MAAMA,IAAY,CAAkBC,IAA2B,CAAC,IAAO,EAAI,MAAa;AAC7F,QAAM,CAAC,CAACC,CAAM,GAAGC,CAAM,IAAIC,EAAW,CAACC,GAAgBC,MAAkC;AACvF,UAAMC,IACJ,OAAOD,KAAW,aAAcA,EAAuCD,EAAM,CAAC,CAAC,IAAIC,GAC/EE,IAAQ,KAAK,IAAIH,EAAM,QAAQE,CAAK,CAAC;AAC3C,WAAOF,EAAM,MAAMG,CAAK,EAAE,OAAOH,EAAM,MAAM,GAAGG,CAAK,CAAC;AAAA,EAAA,GACrDP,CAAiB;AAEpB,SAAO,CAACC,GAAQC,CAAiD;AACnE;"}
1
+ {"version":3,"file":"useToggle.mjs","sources":["../../../../src/hooks/useToggle/useToggle.ts"],"sourcesContent":["import type { SetStateAction } from 'react';\n\nimport { useReducer } from 'react';\n\n/** The use toggle return type */\nexport type UseToggleReturn<Value> = readonly [Value, (value?: Value) => void];\n\n/**\n * @name useToggle\n * @description - Hook that create toggle\n * @category State\n *\n * @template Value The type of the value\n * @param {Value[]} [values=[false, true]] The values to toggle\n *\n * @example\n * const [on, toggle] = useToggle();\n *\n * @example\n * const [value, toggle] = useToggle(['light', 'dark'] as const);\n */\nexport const useToggle = <Value = boolean>(values: readonly Value[] = [false, true] as any) => {\n const [[option], toggle] = useReducer((state: Value[], action: SetStateAction<Value>) => {\n const value =\n typeof action === 'function' ? (action as (prevState: Value) => Value)(state[0]) : action;\n const index = Math.abs(state.indexOf(value));\n return state.slice(index).concat(state.slice(0, index));\n }, values as Value[]);\n\n return [option, toggle as (value?: SetStateAction<Value>) => void] as const;\n};\n"],"names":["useToggle","values","option","toggle","useReducer","state","action","value","index"],"mappings":";AAqBO,MAAMA,IAAY,CAAkBC,IAA2B,CAAC,IAAO,EAAI,MAAa;AAC7F,QAAM,CAAC,CAACC,CAAM,GAAGC,CAAM,IAAIC,EAAW,CAACC,GAAgBC,MAAkC;AACvF,UAAMC,IACJ,OAAOD,KAAW,aAAcA,EAAuCD,EAAM,CAAC,CAAC,IAAIC,GAC/EE,IAAQ,KAAK,IAAIH,EAAM,QAAQE,CAAK,CAAC;AAC3C,WAAOF,EAAM,MAAMG,CAAK,EAAE,OAAOH,EAAM,MAAM,GAAGG,CAAK,CAAC;AAAA,EAAA,GACrDP,CAAiB;AAEpB,SAAO,CAACC,GAAQC,CAAiD;AACnE;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useUrlSearchParam.mjs","sources":["../../../../src/hooks/useUrlSearchParam/useUrlSearchParam.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/** The url search params mode type */\nexport type UrlSearchParamMode = 'hash-params' | 'hash' | 'history';\n\n/** The use url search param options type */\nexport interface UseUrlSearchParamOptions<Value> {\n /** The initial value of the search param */\n initialValue?: Value;\n /** The mode to use for writing to the URL */\n mode?: UrlSearchParamMode;\n /** The mode to use for writing to the URL */\n write?: 'push' | 'replace';\n /** The deserializer function to be invoked */\n deserializer?: (value: string) => Value;\n /** The serializer function to be invoked */\n serializer?: (value: Value) => string;\n}\n\n/** The use url search params set options type */\nexport interface UseUrlSearchParamsActionOptions {\n /** The mode to use for writing to the URL */\n write?: 'push' | 'replace';\n}\n\n/** The use url search param return type */\nexport interface UseUrlSearchParamReturn<Value> {\n /** Current search param value */\n value: Value | undefined;\n /** Function to remove the search param */\n remove: (options?: UseUrlSearchParamsActionOptions) => void;\n /** Function to update search param */\n set: (value: Value, options?: UseUrlSearchParamsActionOptions) => void;\n}\n\nexport const URL_SEARCH_PARAMS_EVENT = 'reactuse-url-search-params-event';\n\nexport const getUrlSearchParams = (mode: UrlSearchParamMode = 'history') => {\n const { search, hash } = window.location;\n\n let path = '';\n\n if (mode === 'history') path = search;\n if (mode === 'hash-params') path = hash.replace(/^#/, '');\n if (mode === 'hash') {\n const index = hash.indexOf('?');\n path = ~index ? hash.slice(index) : '';\n }\n\n return new URLSearchParams(path);\n};\n\nexport const createQueryString = (searchParams: URLSearchParams, mode: UrlSearchParamMode) => {\n const searchParamsString = searchParams.toString();\n const { search, hash } = window.location;\n\n if (mode === 'history') return `${searchParamsString ? `?${searchParamsString}` : ''}${hash}`;\n if (mode === 'hash-params')\n return `${search}${searchParamsString ? `#${searchParamsString}` : ''}`;\n if (mode === 'hash') {\n const index = hash.indexOf('?');\n const base = index > -1 ? hash.slice(0, index) : hash;\n return `${search}${base}${searchParamsString ? `?${searchParamsString}` : ''}`;\n }\n\n throw new Error('Invalid mode');\n};\n\nexport const dispatchUrlSearchParamsEvent = () =>\n window.dispatchEvent(new Event(URL_SEARCH_PARAMS_EVENT));\n\nexport interface UseUrlSearchParam {\n <Value>(\n key: string,\n options: UseUrlSearchParamOptions<Value> & { initialValue: Value }\n ): UseUrlSearchParamReturn<Value>;\n\n <Value>(\n key: string,\n options?: UseUrlSearchParamOptions<Value>\n ): UseUrlSearchParamReturn<Value | undefined>;\n\n <Value>(key: string, initialValue: Value): UseUrlSearchParamReturn<Value>;\n\n <Value>(key: string): UseUrlSearchParamReturn<Value | undefined>;\n}\n\n/**\n * @name useUrlSearchParam\n * @description - Hook that provides reactive URLSearchParams for a single key\n * @category Browser\n *\n * @overload\n * @template Value The type of the url param values\n * @param {string} key The key of the url param\n * @param {UseUrlSearchParamOptions<Value> & { initialValue: Value }} options The options object with required initialValue\n * @param {Value} options.initialValue The initial value for the url param\n * @param {UrlSearchParamsMode} [options.mode='history'] The mode to use for the URL ('history' | 'hash-params' | 'hash')\n * @param {'push' | 'replace'} [options.write='replace'] The mode to use for writing to the URL\n * @param {(value: Value) => string} [options.serializer] Custom serializer function to convert value to string\n * @param {(value: string) => Value} [options.deserializer] Custom deserializer function to convert string to value\n * @returns {UseUrlSearchParamReturn<Value>} The object with value and function for change value\n *\n * @example\n * const { value, set } = useUrlSearchParam('page', { initialValue: 1 });\n *\n * @overload\n * @template Value The type of the url param values\n * @param {string} key The key of the url param\n * @param {Value} [initialValue] The initial value for the url param\n * @returns {UseUrlSearchParamReturn<Value>} The object with value and function for change value\n *\n * @example\n * const { value, set } = useUrlSearchParam('page', 1);\n */\nexport const useUrlSearchParam = (<Value>(key: string, params?: any) => {\n const options = (\n typeof params === 'object' &&\n params &&\n ('serializer' in params ||\n 'deserializer' in params ||\n 'initialValue' in params ||\n 'mode' in params ||\n 'write' in params)\n ? params\n : undefined\n ) as UseUrlSearchParamOptions<Value>;\n\n const initialValue = (options ? options?.initialValue : params) as Value;\n const { mode = 'history', write: writeMode = 'replace' } = options ?? {};\n\n if (typeof window === 'undefined') {\n return {\n value: initialValue,\n remove: () => {},\n set: () => {}\n } as UseUrlSearchParamReturn<Value>;\n }\n\n const serializer = (value: Value) => {\n if (options?.serializer) return options.serializer(value);\n if (typeof value === 'string') return value;\n\n return JSON.stringify(value);\n };\n\n const deserializer = (value: string) => {\n if (options?.deserializer) return options.deserializer(value);\n if (value === 'undefined' || value === 'null') return undefined as unknown as Value;\n\n try {\n return JSON.parse(value) as Value;\n } catch {\n return value as Value;\n }\n };\n\n const setUrlSearchParam = (\n key: string,\n value: Value | undefined,\n mode: UrlSearchParamMode,\n write: 'push' | 'replace' = 'replace'\n ) => {\n const searchParams = getUrlSearchParams(mode);\n const serializedValue =\n value !== undefined ? (serializer ? serializer(value) : String(value)) : '';\n\n if (value === undefined) {\n searchParams.delete(key);\n } else {\n searchParams.set(key, serializedValue);\n }\n\n const query = createQueryString(searchParams, mode);\n if (write === 'replace') window.history.replaceState({}, '', query);\n if (write === 'push') window.history.pushState({}, '', query);\n\n dispatchUrlSearchParamsEvent();\n };\n\n const [value, setValue] = useState<Value | undefined>(() => {\n const searchParams = getUrlSearchParams(mode);\n const currentValue = searchParams.get(key);\n\n if (currentValue === null && initialValue !== undefined) {\n setUrlSearchParam(key, initialValue, mode, writeMode);\n return initialValue;\n }\n\n return currentValue ? deserializer(currentValue) : undefined;\n });\n\n const set = (value: Value, options?: UseUrlSearchParamsActionOptions) => {\n setUrlSearchParam(key, value, mode, options?.write ?? writeMode);\n setValue(value);\n };\n\n const remove = (options?: UseUrlSearchParamsActionOptions) => {\n setUrlSearchParam(key, undefined, mode, options?.write ?? writeMode);\n setValue(undefined);\n };\n\n useEffect(() => {\n const onParamsChange = () => {\n const searchParams = getUrlSearchParams(mode);\n const newValue = searchParams.get(key);\n setValue(newValue ? deserializer(newValue) : undefined);\n };\n\n window.addEventListener(URL_SEARCH_PARAMS_EVENT, onParamsChange);\n window.addEventListener('popstate', onParamsChange);\n if (mode !== 'history') {\n window.addEventListener('hashchange', onParamsChange);\n }\n\n return () => {\n window.removeEventListener(URL_SEARCH_PARAMS_EVENT, onParamsChange);\n window.removeEventListener('popstate', onParamsChange);\n if (mode !== 'history') {\n window.removeEventListener('hashchange', onParamsChange);\n }\n };\n }, [key, mode]);\n\n return {\n value,\n remove,\n set\n };\n}) as UseUrlSearchParam;\n"],"names":["URL_SEARCH_PARAMS_EVENT","getUrlSearchParams","mode","search","hash","path","index","createQueryString","searchParams","searchParamsString","base","dispatchUrlSearchParamsEvent","useUrlSearchParam","key","params","options","initialValue","writeMode","serializer","value","deserializer","setUrlSearchParam","write","serializedValue","query","setValue","useState","currentValue","set","remove","useEffect","onParamsChange","newValue"],"mappings":";AAmCO,MAAMA,IAA0B,oCAE1BC,IAAqB,CAACC,IAA2B,cAAc;AAC1E,QAAM,EAAE,QAAAC,GAAQ,MAAAC,EAAA,IAAS,OAAO;AAEhC,MAAIC,IAAO;AAIX,MAFIH,MAAS,cAAWG,IAAOF,IAC3BD,MAAS,kBAAeG,IAAOD,EAAK,QAAQ,MAAM,EAAE,IACpDF,MAAS,QAAQ;AACnB,UAAMI,IAAQF,EAAK,QAAQ,GAAG;AAC9B,IAAAC,IAAO,CAACC,IAAQF,EAAK,MAAME,CAAK,IAAI;AAAA,EAAA;AAGtC,SAAO,IAAI,gBAAgBD,CAAI;AACjC,GAEaE,IAAoB,CAACC,GAA+BN,MAA6B;AAC5F,QAAMO,IAAqBD,EAAa,SAAA,GAClC,EAAE,QAAAL,GAAQ,MAAAC,EAAA,IAAS,OAAO;AAEhC,MAAIF,MAAS,UAAW,QAAO,GAAGO,IAAqB,IAAIA,CAAkB,KAAK,EAAE,GAAGL,CAAI;AAC3F,MAAIF,MAAS;AACX,WAAO,GAAGC,CAAM,GAAGM,IAAqB,IAAIA,CAAkB,KAAK,EAAE;AACvE,MAAIP,MAAS,QAAQ;AACnB,UAAMI,IAAQF,EAAK,QAAQ,GAAG,GACxBM,IAAOJ,IAAQ,KAAKF,EAAK,MAAM,GAAGE,CAAK,IAAIF;AACjD,WAAO,GAAGD,CAAM,GAAGO,CAAI,GAAGD,IAAqB,IAAIA,CAAkB,KAAK,EAAE;AAAA,EAAA;AAG9E,QAAM,IAAI,MAAM,cAAc;AAChC,GAEaE,IAA+B,MAC1C,OAAO,cAAc,IAAI,MAAMX,CAAuB,CAAC,GA8C5CY,IAAqB,CAAQC,GAAaC,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IADe1B,EAAmBC,CAAI,EACV,IAAIW,CAAG;AAEzC,WAAIc,MAAiB,QAAQX,MAAiB,UAC5CK,EAAkBR,GAAKG,GAAcd,GAAMe,CAAS,GAC7CD,KAGFW,IAAeP,EAAaO,CAAY,IAAI;AAAA,EAAA,CACpD,GAEKC,IAAM,CAACT,GAAcJ,MAA8C;AACvE,IAAAM,EAAkBR,GAAKM,GAAOjB,GAAMa,GAAS,SAASE,CAAS,GAC/DQ,EAASN,CAAK;AAAA,EAAA,GAGVU,IAAS,CAACd,MAA8C;AAC5D,IAAAM,EAAkBR,GAAK,QAAWX,GAAMa,GAAS,SAASE,CAAS,GACnEQ,EAAS,MAAS;AAAA,EAAA;AAGpB,SAAAK,EAAU,MAAM;AACd,UAAMC,IAAiB,MAAM;AAE3B,YAAMC,IADe/B,EAAmBC,CAAI,EACd,IAAIW,CAAG;AACrC,MAAAY,EAASO,IAAWZ,EAAaY,CAAQ,IAAI,MAAS;AAAA,IAAA;AAGxD,kBAAO,iBAAiBhC,GAAyB+B,CAAc,GAC/D,OAAO,iBAAiB,YAAYA,CAAc,GAC9C7B,MAAS,aACX,OAAO,iBAAiB,cAAc6B,CAAc,GAG/C,MAAM;AACX,aAAO,oBAAoB/B,GAAyB+B,CAAc,GAClE,OAAO,oBAAoB,YAAYA,CAAc,GACjD7B,MAAS,aACX,OAAO,oBAAoB,cAAc6B,CAAc;AAAA,IACzD;AAAA,EACF,GACC,CAAClB,GAAKX,CAAI,CAAC,GAEP;AAAA,IACL,OAAAiB;AAAA,IACA,QAAAU;AAAA,IACA,KAAAD;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"useUrlSearchParam.mjs","sources":["../../../../src/hooks/useUrlSearchParam/useUrlSearchParam.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/** The url search params mode type */\nexport type UrlSearchParamMode = 'hash-params' | 'hash' | 'history';\n\n/** The use url search param options type */\nexport interface UseUrlSearchParamOptions<Value> {\n /** The initial value of the search param */\n initialValue?: Value;\n /** The mode to use for writing to the URL */\n mode?: UrlSearchParamMode;\n /** The mode to use for writing to the URL */\n write?: 'push' | 'replace';\n /** The deserializer function to be invoked */\n deserializer?: (value: string) => Value;\n /** The serializer function to be invoked */\n serializer?: (value: Value) => string;\n}\n\n/** The use url search params set options type */\nexport interface UseUrlSearchParamsActionOptions {\n /** The mode to use for writing to the URL */\n write?: 'push' | 'replace';\n}\n\n/** The use url search param return type */\nexport interface UseUrlSearchParamReturn<Value> {\n /** Current search param value */\n value: Value | undefined;\n /** Function to remove the search param */\n remove: (options?: UseUrlSearchParamsActionOptions) => void;\n /** Function to update search param */\n set: (value: Value, options?: UseUrlSearchParamsActionOptions) => void;\n}\n\nexport const URL_SEARCH_PARAMS_EVENT = 'reactuse-url-search-params-event';\n\nexport const getUrlSearchParams = (mode: UrlSearchParamMode = 'history') => {\n const { search, hash } = window.location;\n\n let path = '';\n\n if (mode === 'history') path = search;\n if (mode === 'hash-params') path = hash.replace(/^#/, '');\n if (mode === 'hash') {\n const index = hash.indexOf('?');\n path = ~index ? hash.slice(index) : '';\n }\n\n return new URLSearchParams(path);\n};\n\nexport const createQueryString = (searchParams: URLSearchParams, mode: UrlSearchParamMode) => {\n const searchParamsString = searchParams.toString();\n const { search, hash } = window.location;\n\n if (mode === 'history') return `${searchParamsString ? `?${searchParamsString}` : ''}${hash}`;\n if (mode === 'hash-params')\n return `${search}${searchParamsString ? `#${searchParamsString}` : ''}`;\n if (mode === 'hash') {\n const index = hash.indexOf('?');\n const base = index > -1 ? hash.slice(0, index) : hash;\n return `${search}${base}${searchParamsString ? `?${searchParamsString}` : ''}`;\n }\n\n throw new Error('Invalid mode');\n};\n\nexport const dispatchUrlSearchParamsEvent = () =>\n window.dispatchEvent(new Event(URL_SEARCH_PARAMS_EVENT));\n\nexport interface UseUrlSearchParam {\n <Value>(\n key: string,\n options: UseUrlSearchParamOptions<Value> & { initialValue: Value }\n ): UseUrlSearchParamReturn<Value>;\n\n <Value>(\n key: string,\n options?: UseUrlSearchParamOptions<Value>\n ): UseUrlSearchParamReturn<Value | undefined>;\n\n <Value>(key: string, initialValue: Value): UseUrlSearchParamReturn<Value>;\n\n <Value>(key: string): UseUrlSearchParamReturn<Value | undefined>;\n}\n\n/**\n * @name useUrlSearchParam\n * @description - Hook that provides reactive URLSearchParams for a single key\n * @category State\n *\n * @overload\n * @template Value The type of the url param values\n * @param {string} key The key of the url param\n * @param {UseUrlSearchParamOptions<Value> & { initialValue: Value }} options The options object with required initialValue\n * @param {Value} options.initialValue The initial value for the url param\n * @param {UrlSearchParamsMode} [options.mode='history'] The mode to use for the URL ('history' | 'hash-params' | 'hash')\n * @param {'push' | 'replace'} [options.write='replace'] The mode to use for writing to the URL\n * @param {(value: Value) => string} [options.serializer] Custom serializer function to convert value to string\n * @param {(value: string) => Value} [options.deserializer] Custom deserializer function to convert string to value\n * @returns {UseUrlSearchParamReturn<Value>} The object with value and function for change value\n *\n * @example\n * const { value, set } = useUrlSearchParam('page', { initialValue: 1 });\n *\n * @overload\n * @template Value The type of the url param values\n * @param {string} key The key of the url param\n * @param {Value} [initialValue] The initial value for the url param\n * @returns {UseUrlSearchParamReturn<Value>} The object with value and function for change value\n *\n * @example\n * const { value, set } = useUrlSearchParam('page', 1);\n */\nexport const useUrlSearchParam = (<Value>(key: string, params?: any) => {\n const options = (\n typeof params === 'object' &&\n params &&\n ('serializer' in params ||\n 'deserializer' in params ||\n 'initialValue' in params ||\n 'mode' in params ||\n 'write' in params)\n ? params\n : undefined\n ) as UseUrlSearchParamOptions<Value>;\n\n const initialValue = (options ? options?.initialValue : params) as Value;\n const { mode = 'history', write: writeMode = 'replace' } = options ?? {};\n\n if (typeof window === 'undefined') {\n return {\n value: initialValue,\n remove: () => {},\n set: () => {}\n } as UseUrlSearchParamReturn<Value>;\n }\n\n const serializer = (value: Value) => {\n if (options?.serializer) return options.serializer(value);\n if (typeof value === 'string') return value;\n\n return JSON.stringify(value);\n };\n\n const deserializer = (value: string) => {\n if (options?.deserializer) return options.deserializer(value);\n if (value === 'undefined' || value === 'null') return undefined as unknown as Value;\n\n try {\n return JSON.parse(value) as Value;\n } catch {\n return value as Value;\n }\n };\n\n const setUrlSearchParam = (\n key: string,\n value: Value | undefined,\n mode: UrlSearchParamMode,\n write: 'push' | 'replace' = 'replace'\n ) => {\n const searchParams = getUrlSearchParams(mode);\n const serializedValue =\n value !== undefined ? (serializer ? serializer(value) : String(value)) : '';\n\n if (value === undefined) {\n searchParams.delete(key);\n } else {\n searchParams.set(key, serializedValue);\n }\n\n const query = createQueryString(searchParams, mode);\n if (write === 'replace') window.history.replaceState({}, '', query);\n if (write === 'push') window.history.pushState({}, '', query);\n\n dispatchUrlSearchParamsEvent();\n };\n\n const [value, setValue] = useState<Value | undefined>(() => {\n const searchParams = getUrlSearchParams(mode);\n const currentValue = searchParams.get(key);\n\n if (currentValue === null && initialValue !== undefined) {\n setUrlSearchParam(key, initialValue, mode, writeMode);\n return initialValue;\n }\n\n return currentValue ? deserializer(currentValue) : undefined;\n });\n\n const set = (value: Value, options?: UseUrlSearchParamsActionOptions) => {\n setUrlSearchParam(key, value, mode, options?.write ?? writeMode);\n setValue(value);\n };\n\n const remove = (options?: UseUrlSearchParamsActionOptions) => {\n setUrlSearchParam(key, undefined, mode, options?.write ?? writeMode);\n setValue(undefined);\n };\n\n useEffect(() => {\n const onParamsChange = () => {\n const searchParams = getUrlSearchParams(mode);\n const newValue = searchParams.get(key);\n setValue(newValue ? deserializer(newValue) : undefined);\n };\n\n window.addEventListener(URL_SEARCH_PARAMS_EVENT, onParamsChange);\n window.addEventListener('popstate', onParamsChange);\n if (mode !== 'history') {\n window.addEventListener('hashchange', onParamsChange);\n }\n\n return () => {\n window.removeEventListener(URL_SEARCH_PARAMS_EVENT, onParamsChange);\n window.removeEventListener('popstate', onParamsChange);\n if (mode !== 'history') {\n window.removeEventListener('hashchange', onParamsChange);\n }\n };\n }, [key, mode]);\n\n return {\n value,\n remove,\n set\n };\n}) as UseUrlSearchParam;\n"],"names":["URL_SEARCH_PARAMS_EVENT","getUrlSearchParams","mode","search","hash","path","index","createQueryString","searchParams","searchParamsString","base","dispatchUrlSearchParamsEvent","useUrlSearchParam","key","params","options","initialValue","writeMode","serializer","value","deserializer","setUrlSearchParam","write","serializedValue","query","setValue","useState","currentValue","set","remove","useEffect","onParamsChange","newValue"],"mappings":";AAmCO,MAAMA,IAA0B,oCAE1BC,IAAqB,CAACC,IAA2B,cAAc;AAC1E,QAAM,EAAE,QAAAC,GAAQ,MAAAC,EAAA,IAAS,OAAO;AAEhC,MAAIC,IAAO;AAIX,MAFIH,MAAS,cAAWG,IAAOF,IAC3BD,MAAS,kBAAeG,IAAOD,EAAK,QAAQ,MAAM,EAAE,IACpDF,MAAS,QAAQ;AACnB,UAAMI,IAAQF,EAAK,QAAQ,GAAG;AAC9B,IAAAC,IAAO,CAACC,IAAQF,EAAK,MAAME,CAAK,IAAI;AAAA,EAAA;AAGtC,SAAO,IAAI,gBAAgBD,CAAI;AACjC,GAEaE,IAAoB,CAACC,GAA+BN,MAA6B;AAC5F,QAAMO,IAAqBD,EAAa,SAAA,GAClC,EAAE,QAAAL,GAAQ,MAAAC,EAAA,IAAS,OAAO;AAEhC,MAAIF,MAAS,UAAW,QAAO,GAAGO,IAAqB,IAAIA,CAAkB,KAAK,EAAE,GAAGL,CAAI;AAC3F,MAAIF,MAAS;AACX,WAAO,GAAGC,CAAM,GAAGM,IAAqB,IAAIA,CAAkB,KAAK,EAAE;AACvE,MAAIP,MAAS,QAAQ;AACnB,UAAMI,IAAQF,EAAK,QAAQ,GAAG,GACxBM,IAAOJ,IAAQ,KAAKF,EAAK,MAAM,GAAGE,CAAK,IAAIF;AACjD,WAAO,GAAGD,CAAM,GAAGO,CAAI,GAAGD,IAAqB,IAAIA,CAAkB,KAAK,EAAE;AAAA,EAAA;AAG9E,QAAM,IAAI,MAAM,cAAc;AAChC,GAEaE,IAA+B,MAC1C,OAAO,cAAc,IAAI,MAAMX,CAAuB,CAAC,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IC,EAA4B,MAAM;AAE1D,UAAMC,IADe1B,EAAmBC,CAAI,EACV,IAAIW,CAAG;AAEzC,WAAIc,MAAiB,QAAQX,MAAiB,UAC5CK,EAAkBR,GAAKG,GAAcd,GAAMe,CAAS,GAC7CD,KAGFW,IAAeP,EAAaO,CAAY,IAAI;AAAA,EAAA,CACpD,GAEKC,IAAM,CAACT,GAAcJ,MAA8C;AACvE,IAAAM,EAAkBR,GAAKM,GAAOjB,GAAMa,GAAS,SAASE,CAAS,GAC/DQ,EAASN,CAAK;AAAA,EAAA,GAGVU,IAAS,CAACd,MAA8C;AAC5D,IAAAM,EAAkBR,GAAK,QAAWX,GAAMa,GAAS,SAASE,CAAS,GACnEQ,EAAS,MAAS;AAAA,EAAA;AAGpB,SAAAK,EAAU,MAAM;AACd,UAAMC,IAAiB,MAAM;AAE3B,YAAMC,IADe/B,EAAmBC,CAAI,EACd,IAAIW,CAAG;AACrC,MAAAY,EAASO,IAAWZ,EAAaY,CAAQ,IAAI,MAAS;AAAA,IAAA;AAGxD,kBAAO,iBAAiBhC,GAAyB+B,CAAc,GAC/D,OAAO,iBAAiB,YAAYA,CAAc,GAC9C7B,MAAS,aACX,OAAO,iBAAiB,cAAc6B,CAAc,GAG/C,MAAM;AACX,aAAO,oBAAoB/B,GAAyB+B,CAAc,GAClE,OAAO,oBAAoB,YAAYA,CAAc,GACjD7B,MAAS,aACX,OAAO,oBAAoB,cAAc6B,CAAc;AAAA,IACzD;AAAA,EACF,GACC,CAAClB,GAAKX,CAAI,CAAC,GAEP;AAAA,IACL,OAAAiB;AAAA,IACA,QAAAU;AAAA,IACA,KAAAD;AAAA,EAAA;AAEJ;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useUrlSearchParams.mjs","sources":["../../../../src/hooks/useUrlSearchParams/useUrlSearchParams.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport {\n createQueryString,\n dispatchUrlSearchParamsEvent,\n getUrlSearchParams,\n URL_SEARCH_PARAMS_EVENT\n} from '../useUrlSearchParam/useUrlSearchParam';\n\n/** The url params type */\nexport type UrlParams = Record<string, any>;\n\n/** The url search params mod */\nexport type UrlSearchParamsMode = 'hash-params' | 'hash' | 'history';\n\n/** The use url search params set options type */\nexport interface UseUrlSearchParamsSetOptions {\n /** The mode to use for writing to the URL */\n write?: 'push' | 'replace';\n}\n\n/* The use search params initial value type */\nexport type UseUrlSearchParamsInitialValue<Value> = (() => Value) | Value;\n\n/** The use url search params options type */\nexport interface UseUrlSearchParamsOptions<Value> {\n /* The initial value of the url search params */\n initialValue?: UseUrlSearchParamsInitialValue<string | URLSearchParams | Value>;\n /** The mode to use for writing to the URL */\n mode?: UrlSearchParamsMode;\n /** The mode to use for writing to the URL */\n write?: 'push' | 'replace';\n /* The deserializer function to be invoked */\n deserializer?: (value: string) => Value[keyof Value];\n /* The serializer function to be invoked */\n serializer?: (value: Value[keyof Value]) => string;\n}\n\n/** The use url search params return type */\nexport interface UseUrlSearchParamsReturn<Value> {\n /** The value of the url search params */\n value: Value;\n /** The set function */\n set: (value: Partial<Value>, options?: UseUrlSearchParamsSetOptions) => void;\n}\n\nexport interface UseUrlSearchParams {\n <Value>(\n key: string,\n options: UseUrlSearchParamsOptions<Value> & {\n initialValue: UseUrlSearchParamsInitialValue<Value>;\n }\n ): UseUrlSearchParamsReturn<Value>;\n\n <Value>(options?: UseUrlSearchParamsOptions<Value>): UseUrlSearchParamsReturn<Value | undefined>;\n\n <Value>(initialValue: UseUrlSearchParamsInitialValue<Value>): UseUrlSearchParamsReturn<Value>;\n\n <Value>(key: string): UseUrlSearchParamsReturn<Value | undefined>;\n}\n\n/**\n * @name useUrlSearchParams\n * @description - Hook that provides reactive URLSearchParams\n * @category Browser\n *\n * @overload\n * @template Value The type of the url param values\n * @param {UseUrlSearchParamsOptions<Value> & { initialValue: UseUrlSearchParamsInitialValue<Value> }} options The options object with required initialValue\n * @param {UseUrlSearchParamsInitialValue<Value>} [options.initialValue] The initial value for the url params\n * @param {UrlSearchParamsMode} [options.mode='history'] The mode to use for the URL ('history' | 'hash-params' | 'hash')\n * @param {'push' | 'replace'} [options.write='replace'] The mode to use for writing to the URL\n * @param {(value: Value[keyof Value]) => string} [options.serializer] Custom serializer function to convert value to string\n * @param {(value: string) => Value[keyof Value]} [options.deserializer] Custom deserializer function to convert string to value\n * @returns {UseUrlSearchParamsReturn<Value>} The object with value and function for change value\n *\n * @example\n * const { value, set } = useUrlSearchParams({ initialValue: { page: 1 } });\n *\n * @overload\n * @template Value The type of the url param values\n * @param {UseUrlSearchParamsInitialValue<Value>} [initialValue] The initial value for the url params\n * @returns {UseUrlSearchParamsReturn<Value>} The object with value and function for change value\n *\n * @example\n * const { value, set } = useUrlSearchParams({ page: 1 });\n */\nexport const useUrlSearchParams = (<Value extends UrlParams>(\n params: any\n): UseUrlSearchParamsReturn<Value> => {\n const options = (\n typeof params === 'object' &&\n params &&\n ('serializer' in params ||\n 'deserializer' in params ||\n 'initialValue' in params ||\n 'mode' in params ||\n 'write' in params)\n ? params\n : undefined\n ) as UseUrlSearchParamsOptions<Value>;\n const initialValue = (\n options ? options?.initialValue : params\n ) as UseUrlSearchParamsInitialValue<Value>;\n\n const { mode = 'history', write: writeMode = 'replace' } = options;\n\n const serializer = (value: Value[keyof Value]) => {\n if (options?.serializer) return options.serializer(value);\n if (typeof value === 'string') return value;\n return JSON.stringify(value);\n };\n\n const deserializer = (value: string) => {\n if (options?.deserializer) return options.deserializer(value);\n if (value === 'undefined') return undefined as unknown as Value[keyof Value];\n\n try {\n return JSON.parse(value) as Value;\n } catch {\n return value as Value[keyof Value];\n }\n };\n\n const setUrlSearchParams = <Value extends UrlParams>(\n mode: UrlSearchParamsMode,\n value: Partial<Value>,\n write: 'push' | 'replace' = 'replace'\n ) => {\n const urlSearchParams = new URLSearchParams();\n\n Object.entries(value).forEach(([key, param]) => {\n if (Array.isArray(param)) {\n param.forEach((value) => urlSearchParams.set(key, serializer(value)));\n } else {\n urlSearchParams.set(key, serializer(param));\n }\n });\n\n const query = createQueryString(urlSearchParams, mode);\n if (write === 'replace') window.history.replaceState({}, '', query);\n if (write === 'push') window.history.pushState({}, '', query);\n\n return urlSearchParams;\n };\n\n const getParsedUrlSearchParams = (searchParams: string | UrlParams | URLSearchParams) => {\n if (typeof searchParams === 'string') {\n return getParsedUrlSearchParams(new URLSearchParams(searchParams));\n }\n\n if (searchParams instanceof URLSearchParams) {\n return Array.from(searchParams.entries()).reduce(\n (acc, [key, value]) => {\n acc[key] = deserializer(value);\n return acc;\n },\n {} as Record<string, any>\n );\n }\n\n return searchParams;\n };\n\n const [value, setValue] = useState<Value>(() => {\n if (typeof window === 'undefined') return (initialValue ?? {}) as Value;\n\n const urlSearchParams = getUrlSearchParams(mode);\n const value = {\n ...(initialValue && getParsedUrlSearchParams(initialValue)),\n ...getParsedUrlSearchParams(urlSearchParams)\n } as Value;\n\n setUrlSearchParams(mode, value, writeMode);\n\n return value;\n });\n\n const set = (params: Partial<Value>, options?: UseUrlSearchParamsSetOptions) => {\n const searchParams = setUrlSearchParams(\n mode,\n { ...value, ...params },\n options?.write ?? writeMode\n );\n setValue(getParsedUrlSearchParams(searchParams) as Value);\n dispatchUrlSearchParamsEvent();\n };\n\n useEffect(() => {\n const onParamsChange = () => {\n const searchParams = getUrlSearchParams(mode);\n setValue(getParsedUrlSearchParams(searchParams) as Value);\n };\n\n window.addEventListener(URL_SEARCH_PARAMS_EVENT, onParamsChange);\n window.addEventListener('popstate', onParamsChange);\n if (mode !== 'history') window.addEventListener('hashchange', onParamsChange);\n\n return () => {\n window.removeEventListener(URL_SEARCH_PARAMS_EVENT, onParamsChange);\n window.removeEventListener('popstate', onParamsChange);\n if (mode !== 'history') window.removeEventListener('hashchange', onParamsChange);\n };\n }, [mode]);\n\n return {\n value,\n set\n };\n}) as UseUrlSearchParams;\n\nexport { createQueryString, dispatchUrlSearchParamsEvent, getUrlSearchParams };\n"],"names":["useUrlSearchParams","params","options","initialValue","mode","writeMode","serializer","value","deserializer","setUrlSearchParams","write","urlSearchParams","key","param","query","createQueryString","getParsedUrlSearchParams","searchParams","acc","setValue","useState","getUrlSearchParams","set","dispatchUrlSearchParamsEvent","useEffect","onParamsChange","URL_SEARCH_PARAMS_EVENT"],"mappings":";;AAuFO,MAAMA,IAAsB,CACjCC,MACoC;AACpC,QAAMC,IACJ,OAAOD,KAAW,YAClBA,MACC,gBAAgBA,KACf,kBAAkBA,KAClB,kBAAkBA,KAClB,UAAUA,KACV,WAAWA,KACTA,IACA,QAEAE,IACJD,IAAUA,GAAS,eAAeD,GAG9B,EAAE,MAAAG,IAAO,WAAW,OAAOC,IAAY,cAAcH,GAErDI,IAAa,CAACC,MACdL,GAAS,aAAmBA,EAAQ,WAAWK,CAAK,IACpD,OAAOA,KAAU,WAAiBA,IAC/B,KAAK,UAAUA,CAAK,GAGvBC,IAAe,CAACD,MAAkB;AACtC,QAAIL,GAAS,aAAc,QAAOA,EAAQ,aAAaK,CAAK;AAC5D,QAAIA,MAAU;AAEd,UAAI;AACF,eAAO,KAAK,MAAMA,CAAK;AAAA,MAAA,QACjB;AACN,eAAOA;AAAAA,MAAA;AAAA,EACT,GAGIE,IAAqB,CACzBL,GACAG,GACAG,IAA4B,cACzB;AACH,UAAMC,IAAkB,IAAI,gBAAA;AAE5B,WAAO,QAAQJ,CAAK,EAAE,QAAQ,CAAC,CAACK,GAAKC,CAAK,MAAM;AAC9C,MAAI,MAAM,QAAQA,CAAK,IACrBA,EAAM,QAAQ,CAACN,MAAUI,EAAgB,IAAIC,GAAKN,EAAWC,CAAK,CAAC,CAAC,IAEpEI,EAAgB,IAAIC,GAAKN,EAAWO,CAAK,CAAC;AAAA,IAC5C,CACD;AAED,UAAMC,IAAQC,EAAkBJ,GAAiBP,CAAI;AACrD,WAAIM,MAAU,aAAW,OAAO,QAAQ,aAAa,CAAA,GAAI,IAAII,CAAK,GAC9DJ,MAAU,UAAQ,OAAO,QAAQ,UAAU,CAAA,GAAI,IAAII,CAAK,GAErDH;AAAA,EAAA,GAG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AAI,CAAC,GAEF;AAAA,IACL,OAAAG;AAAA,IACA,KAAAe;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"useUrlSearchParams.mjs","sources":["../../../../src/hooks/useUrlSearchParams/useUrlSearchParams.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport {\n createQueryString,\n dispatchUrlSearchParamsEvent,\n getUrlSearchParams,\n URL_SEARCH_PARAMS_EVENT\n} from '../useUrlSearchParam/useUrlSearchParam';\n\n/** The url params type */\nexport type UrlParams = Record<string, any>;\n\n/** The url search params mod */\nexport type UrlSearchParamsMode = 'hash-params' | 'hash' | 'history';\n\n/** The use url search params set options type */\nexport interface UseUrlSearchParamsSetOptions {\n /** The mode to use for writing to the URL */\n write?: 'push' | 'replace';\n}\n\n/* The use search params initial value type */\nexport type UseUrlSearchParamsInitialValue<Value> = (() => Value) | Value;\n\n/** The use url search params options type */\nexport interface UseUrlSearchParamsOptions<Value> {\n /* The initial value of the url search params */\n initialValue?: UseUrlSearchParamsInitialValue<string | URLSearchParams | Value>;\n /** The mode to use for writing to the URL */\n mode?: UrlSearchParamsMode;\n /** The mode to use for writing to the URL */\n write?: 'push' | 'replace';\n /* The deserializer function to be invoked */\n deserializer?: (value: string) => Value[keyof Value];\n /* The serializer function to be invoked */\n serializer?: (value: Value[keyof Value]) => string;\n}\n\n/** The use url search params return type */\nexport interface UseUrlSearchParamsReturn<Value> {\n /** The value of the url search params */\n value: Value;\n /** The set function */\n set: (value: Partial<Value>, options?: UseUrlSearchParamsSetOptions) => void;\n}\n\nexport interface UseUrlSearchParams {\n <Value>(\n key: string,\n options: UseUrlSearchParamsOptions<Value> & {\n initialValue: UseUrlSearchParamsInitialValue<Value>;\n }\n ): UseUrlSearchParamsReturn<Value>;\n\n <Value>(options?: UseUrlSearchParamsOptions<Value>): UseUrlSearchParamsReturn<Value | undefined>;\n\n <Value>(initialValue: UseUrlSearchParamsInitialValue<Value>): UseUrlSearchParamsReturn<Value>;\n\n <Value>(key: string): UseUrlSearchParamsReturn<Value | undefined>;\n}\n\n/**\n * @name useUrlSearchParams\n * @description - Hook that provides reactive URLSearchParams\n * @category State\n *\n * @overload\n * @template Value The type of the url param values\n * @param {UseUrlSearchParamsOptions<Value> & { initialValue: UseUrlSearchParamsInitialValue<Value> }} options The options object with required initialValue\n * @param {UseUrlSearchParamsInitialValue<Value>} [options.initialValue] The initial value for the url params\n * @param {UrlSearchParamsMode} [options.mode='history'] The mode to use for the URL ('history' | 'hash-params' | 'hash')\n * @param {'push' | 'replace'} [options.write='replace'] The mode to use for writing to the URL\n * @param {(value: Value[keyof Value]) => string} [options.serializer] Custom serializer function to convert value to string\n * @param {(value: string) => Value[keyof Value]} [options.deserializer] Custom deserializer function to convert string to value\n * @returns {UseUrlSearchParamsReturn<Value>} The object with value and function for change value\n *\n * @example\n * const { value, set } = useUrlSearchParams({ initialValue: { page: 1 } });\n *\n * @overload\n * @template Value The type of the url param values\n * @param {UseUrlSearchParamsInitialValue<Value>} [initialValue] The initial value for the url params\n * @returns {UseUrlSearchParamsReturn<Value>} The object with value and function for change value\n *\n * @example\n * const { value, set } = useUrlSearchParams({ page: 1 });\n */\nexport const useUrlSearchParams = (<Value extends UrlParams>(\n params: any\n): UseUrlSearchParamsReturn<Value> => {\n const options = (\n typeof params === 'object' &&\n params &&\n ('serializer' in params ||\n 'deserializer' in params ||\n 'initialValue' in params ||\n 'mode' in params ||\n 'write' in params)\n ? params\n : undefined\n ) as UseUrlSearchParamsOptions<Value>;\n const initialValue = (\n options ? options?.initialValue : params\n ) as UseUrlSearchParamsInitialValue<Value>;\n\n const { mode = 'history', write: writeMode = 'replace' } = options;\n\n const serializer = (value: Value[keyof Value]) => {\n if (options?.serializer) return options.serializer(value);\n if (typeof value === 'string') return value;\n return JSON.stringify(value);\n };\n\n const deserializer = (value: string) => {\n if (options?.deserializer) return options.deserializer(value);\n if (value === 'undefined') return undefined as unknown as Value[keyof Value];\n\n try {\n return JSON.parse(value) as Value;\n } catch {\n return value as Value[keyof Value];\n }\n };\n\n const setUrlSearchParams = <Value extends UrlParams>(\n mode: UrlSearchParamsMode,\n value: Partial<Value>,\n write: 'push' | 'replace' = 'replace'\n ) => {\n const urlSearchParams = new URLSearchParams();\n\n Object.entries(value).forEach(([key, param]) => {\n if (Array.isArray(param)) {\n param.forEach((value) => urlSearchParams.set(key, serializer(value)));\n } else {\n urlSearchParams.set(key, serializer(param));\n }\n });\n\n const query = createQueryString(urlSearchParams, mode);\n if (write === 'replace') window.history.replaceState({}, '', query);\n if (write === 'push') window.history.pushState({}, '', query);\n\n return urlSearchParams;\n };\n\n const getParsedUrlSearchParams = (searchParams: string | UrlParams | URLSearchParams) => {\n if (typeof searchParams === 'string') {\n return getParsedUrlSearchParams(new URLSearchParams(searchParams));\n }\n\n if (searchParams instanceof URLSearchParams) {\n return Array.from(searchParams.entries()).reduce(\n (acc, [key, value]) => {\n acc[key] = deserializer(value);\n return acc;\n },\n {} as Record<string, any>\n );\n }\n\n return searchParams;\n };\n\n const [value, setValue] = useState<Value>(() => {\n if (typeof window === 'undefined') return (initialValue ?? {}) as Value;\n\n const urlSearchParams = getUrlSearchParams(mode);\n const value = {\n ...(initialValue && getParsedUrlSearchParams(initialValue)),\n ...getParsedUrlSearchParams(urlSearchParams)\n } as Value;\n\n setUrlSearchParams(mode, value, writeMode);\n\n return value;\n });\n\n const set = (params: Partial<Value>, options?: UseUrlSearchParamsSetOptions) => {\n const searchParams = setUrlSearchParams(\n mode,\n { ...value, ...params },\n options?.write ?? writeMode\n );\n setValue(getParsedUrlSearchParams(searchParams) as Value);\n dispatchUrlSearchParamsEvent();\n };\n\n useEffect(() => {\n const onParamsChange = () => {\n const searchParams = getUrlSearchParams(mode);\n setValue(getParsedUrlSearchParams(searchParams) as Value);\n };\n\n window.addEventListener(URL_SEARCH_PARAMS_EVENT, onParamsChange);\n window.addEventListener('popstate', onParamsChange);\n if (mode !== 'history') window.addEventListener('hashchange', onParamsChange);\n\n return () => {\n window.removeEventListener(URL_SEARCH_PARAMS_EVENT, onParamsChange);\n window.removeEventListener('popstate', onParamsChange);\n if (mode !== 'history') window.removeEventListener('hashchange', onParamsChange);\n };\n }, [mode]);\n\n return {\n value,\n set\n };\n}) as UseUrlSearchParams;\n\nexport { createQueryString, dispatchUrlSearchParamsEvent, getUrlSearchParams };\n"],"names":["useUrlSearchParams","params","options","initialValue","mode","writeMode","serializer","value","deserializer","setUrlSearchParams","write","urlSearchParams","key","param","query","createQueryString","getParsedUrlSearchParams","searchParams","acc","setValue","useState","getUrlSearchParams","set","dispatchUrlSearchParamsEvent","useEffect","onParamsChange","URL_SEARCH_PARAMS_EVENT"],"mappings":";;AAuFO,MAAMA,IAAsB,CACjCC,MACoC;AACpC,QAAMC,IACJ,OAAOD,KAAW,YAClBA,MACC,gBAAgBA,KACf,kBAAkBA,KAClB,kBAAkBA,KAClB,UAAUA,KACV,WAAWA,KACTA,IACA,QAEAE,IACJD,IAAUA,GAAS,eAAeD,GAG9B,EAAE,MAAAG,IAAO,WAAW,OAAOC,IAAY,cAAcH,GAErDI,IAAa,CAACC,MACdL,GAAS,aAAmBA,EAAQ,WAAWK,CAAK,IACpD,OAAOA,KAAU,WAAiBA,IAC/B,KAAK,UAAUA,CAAK,GAGvBC,IAAe,CAACD,MAAkB;AACtC,QAAIL,GAAS,aAAc,QAAOA,EAAQ,aAAaK,CAAK;AAC5D,QAAIA,MAAU;AAEd,UAAI;AACF,eAAO,KAAK,MAAMA,CAAK;AAAA,MAAA,QACjB;AACN,eAAOA;AAAAA,MAAA;AAAA,EACT,GAGIE,IAAqB,CACzBL,GACAG,GACAG,IAA4B,cACzB;AACH,UAAMC,IAAkB,IAAI,gBAAA;AAE5B,WAAO,QAAQJ,CAAK,EAAE,QAAQ,CAAC,CAACK,GAAKC,CAAK,MAAM;AAC9C,MAAI,MAAM,QAAQA,CAAK,IACrBA,EAAM,QAAQ,CAACN,MAAUI,EAAgB,IAAIC,GAAKN,EAAWC,CAAK,CAAC,CAAC,IAEpEI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D,CAAc,GAC/D,OAAO,iBAAiB,YAAYA,CAAc,GAC9CrB,MAAS,aAAW,OAAO,iBAAiB,cAAcqB,CAAc,GAErE,MAAM;AACX,aAAO,oBAAoBC,GAAyBD,CAAc,GAClE,OAAO,oBAAoB,YAAYA,CAAc,GACjDrB,MAAS,aAAW,OAAO,oBAAoB,cAAcqB,CAAc;AAAA,IAAA;AAAA,EACjF,GACC,CAACrB,CAAI,CAAC,GAEF;AAAA,IACL,OAAAG;AAAA,IACA,KAAAe;AAAA,EAAA;AAEJ;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useWindowEvent.mjs","sources":["../../../../src/hooks/useWindowEvent/useWindowEvent.ts"],"sourcesContent":["import { target } from '@/utils/helpers';\n\nimport type { UseEventListenerOptions } from '../useEventListener/useEventListener';\n\nimport { useEventListener } from '../useEventListener/useEventListener';\n\n/**\n * @name useWindowEvent\n * @description - Hook attaches an event listener to the window object for the specified event\n * @category Events\n *\n * @template Event Key of window event map.\n * @param {Event} event The event to listen for.\n * @param {(event: WindowEventMap[Event]) => void} listener The callback function to be executed when the event is triggered\n * @param {UseEventListenerOptions} [options] The options for the event listener\n * @returns {void}\n *\n * @example\n * useWindowEvent('click', () => console.log('clicked'));\n */\nexport const useWindowEvent = <Event extends keyof WindowEventMap>(\n event: Event,\n listener: (this: Window, event: WindowEventMap[Event]) => any,\n options?: UseEventListenerOptions\n) => useEventListener(target(window), event, listener, options);\n"],"names":["useWindowEvent","event","listener","options","useEventListener","target"],"mappings":";;AAoBO,MAAMA,IAAiB,CAC5BC,GACAC,GACAC,MACGC,EAAiBC,EAAO,MAAM,GAAGJ,GAAOC,GAAUC,CAAO;"}
1
+ {"version":3,"file":"useWindowEvent.mjs","sources":["../../../../src/hooks/useWindowEvent/useWindowEvent.ts"],"sourcesContent":["import { target } from '@/utils/helpers';\n\nimport type { UseEventListenerOptions } from '../useEventListener/useEventListener';\n\nimport { useEventListener } from '../useEventListener/useEventListener';\n\n/**\n * @name useWindowEvent\n * @description - Hook attaches an event listener to the window object for the specified event\n * @category Sensors\n *\n * @template Event Key of window event map.\n * @param {Event} event The event to listen for.\n * @param {(event: WindowEventMap[Event]) => void} listener The callback function to be executed when the event is triggered\n * @param {UseEventListenerOptions} [options] The options for the event listener\n * @returns {void}\n *\n * @example\n * useWindowEvent('click', () => console.log('clicked'));\n */\nexport const useWindowEvent = <Event extends keyof WindowEventMap>(\n event: Event,\n listener: (this: Window, event: WindowEventMap[Event]) => any,\n options?: UseEventListenerOptions\n) => useEventListener(target(window), event, listener, options);\n"],"names":["useWindowEvent","event","listener","options","useEventListener","target"],"mappings":";;AAoBO,MAAMA,IAAiB,CAC5BC,GACAC,GACAC,MACGC,EAAiBC,EAAO,MAAM,GAAGJ,GAAOC,GAAUC,CAAO;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useWizard.mjs","sources":["../../../../src/hooks/useWizard/useWizard.ts"],"sourcesContent":["import { useState } from 'react';\n\nexport interface WizardItem<WizardStepId> {\n id: WizardStepId;\n nodes?: WizardStepId[];\n}\n\n/**\n * @name useWizard\n * @description - Hook that manages a wizard\n * @category Utilities\n *\n * @param {WizardItem<WizardStepId>[]} map The map of the wizard\n * @param {WizardStepId} [initialStepId] The initial step id\n * @returns {UseWizardReturn<WizardStepId>} An object containing the current step id and functions to interact with the wizard\n *\n * @example\n * const { currentStepId, set, reset, back, next, history } = useWizard([\n * { id: 'step1', nodes: ['step2', 'step3'] },\n * { id: 'step2', nodes: ['step3'] },\n * { id: 'step3', nodes: [] },\n * ])\n */\nexport const useWizard = <WizardStepId extends string>(\n map: WizardItem<WizardStepId>[],\n initialStepId?: WizardStepId\n) => {\n const initialId = initialStepId ?? map[0].id;\n const wizardMap = new Map(map.map((wizardItem) => [wizardItem.id, wizardItem]));\n const [currentStepId, setCurrentStepId] = useState(initialId);\n const [history, setHistory] = useState<WizardStepId[]>([initialId]);\n\n const set = (id: WizardStepId) => {\n if (!wizardMap.get(currentStepId)?.nodes?.includes(id))\n throw new Error(`Can't go to ${id} from ${currentStepId}`);\n\n setHistory([...history, id]);\n setCurrentStepId(id);\n };\n\n const back = () => {\n if (history.length === 1) return;\n\n const previousStepId = history[history.length - 2];\n if (!wizardMap.get(currentStepId)?.nodes?.includes(previousStepId))\n throw new Error(`Can't go to ${previousStepId} from ${currentStepId}`);\n\n setHistory(history.slice(0, -1));\n setCurrentStepId(history[history.length - 2]);\n };\n\n const reset = () => {\n setCurrentStepId(initialId);\n setHistory([initialId]);\n };\n\n return { currentStepId, set, reset, back, history };\n};\n"],"names":["useWizard","map","initialStepId","initialId","wizardMap","wizardItem","currentStepId","setCurrentStepId","useState","history","setHistory","id","previousStepId"],"mappings":";AAuBO,MAAMA,IAAY,CACvBC,GACAC,MACG;AACH,QAAMC,IAAYD,KAAiBD,EAAI,CAAC,EAAE,IACpCG,IAAY,IAAI,IAAIH,EAAI,IAAI,CAACI,MAAe,CAACA,EAAW,IAAIA,CAAU,CAAC,CAAC,GACxE,CAACC,GAAeC,CAAgB,IAAIC,EAASL,CAAS,GACtD,CAACM,GAASC,CAAU,IAAIF,EAAyB,CAACL,CAAS,CAAC;AA0BlE,SAAO,EAAE,eAAAG,GAAe,KAxBZ,CAACK,MAAqB;AAChC,QAAI,CAACP,EAAU,IAAIE,CAAa,GAAG,OAAO,SAASK,CAAE;AACnD,YAAM,IAAI,MAAM,eAAeA,CAAE,SAASL,CAAa,EAAE;AAE3D,IAAAI,EAAW,CAAC,GAAGD,GAASE,CAAE,CAAC,GAC3BJ,EAAiBI,CAAE;AAAA,EAAA,GAmBQ,OALf,MAAM;AAClB,IAAAJ,EAAiBJ,CAAS,GAC1BO,EAAW,CAACP,CAAS,CAAC;AAAA,EAAA,GAGY,MAhBvB,MAAM;AACjB,QAAIM,EAAQ,WAAW,EAAG;AAE1B,UAAMG,IAAiBH,EAAQA,EAAQ,SAAS,CAAC;AACjD,QAAI,CAACL,EAAU,IAAIE,CAAa,GAAG,OAAO,SAASM,CAAc;AAC/D,YAAM,IAAI,MAAM,eAAeA,CAAc,SAASN,CAAa,EAAE;AAEvE,IAAAI,EAAWD,EAAQ,MAAM,GAAG,EAAE,CAAC,GAC/BF,EAAiBE,EAAQA,EAAQ,SAAS,CAAC,CAAC;AAAA,EAAA,GAQJ,SAAAA,EAAA;AAC5C;"}
1
+ {"version":3,"file":"useWizard.mjs","sources":["../../../../src/hooks/useWizard/useWizard.ts"],"sourcesContent":["import { useState } from 'react';\n\nexport interface WizardItem<WizardStepId> {\n id: WizardStepId;\n nodes?: WizardStepId[];\n}\n\n/**\n * @name useWizard\n * @description - Hook that manages a wizard\n * @category State\n *\n * @param {WizardItem<WizardStepId>[]} map The map of the wizard\n * @param {WizardStepId} [initialStepId] The initial step id\n * @returns {UseWizardReturn<WizardStepId>} An object containing the current step id and functions to interact with the wizard\n *\n * @example\n * const { currentStepId, set, reset, back, next, history } = useWizard([\n * { id: 'step1', nodes: ['step2', 'step3'] },\n * { id: 'step2', nodes: ['step3'] },\n * { id: 'step3', nodes: [] },\n * ])\n */\nexport const useWizard = <WizardStepId extends string>(\n map: WizardItem<WizardStepId>[],\n initialStepId?: WizardStepId\n) => {\n const initialId = initialStepId ?? map[0].id;\n const wizardMap = new Map(map.map((wizardItem) => [wizardItem.id, wizardItem]));\n const [currentStepId, setCurrentStepId] = useState(initialId);\n const [history, setHistory] = useState<WizardStepId[]>([initialId]);\n\n const set = (id: WizardStepId) => {\n if (!wizardMap.get(currentStepId)?.nodes?.includes(id))\n throw new Error(`Can't go to ${id} from ${currentStepId}`);\n\n setHistory([...history, id]);\n setCurrentStepId(id);\n };\n\n const back = () => {\n if (history.length === 1) return;\n\n const previousStepId = history[history.length - 2];\n if (!wizardMap.get(currentStepId)?.nodes?.includes(previousStepId))\n throw new Error(`Can't go to ${previousStepId} from ${currentStepId}`);\n\n setHistory(history.slice(0, -1));\n setCurrentStepId(history[history.length - 2]);\n };\n\n const reset = () => {\n setCurrentStepId(initialId);\n setHistory([initialId]);\n };\n\n return { currentStepId, set, reset, back, history };\n};\n"],"names":["useWizard","map","initialStepId","initialId","wizardMap","wizardItem","currentStepId","setCurrentStepId","useState","history","setHistory","id","previousStepId"],"mappings":";AAuBO,MAAMA,IAAY,CACvBC,GACAC,MACG;AACH,QAAMC,IAAYD,KAAiBD,EAAI,CAAC,EAAE,IACpCG,IAAY,IAAI,IAAIH,EAAI,IAAI,CAACI,MAAe,CAACA,EAAW,IAAIA,CAAU,CAAC,CAAC,GACxE,CAACC,GAAeC,CAAgB,IAAIC,EAASL,CAAS,GACtD,CAACM,GAASC,CAAU,IAAIF,EAAyB,CAACL,CAAS,CAAC;AA0BlE,SAAO,EAAE,eAAAG,GAAe,KAxBZ,CAACK,MAAqB;AAChC,QAAI,CAACP,EAAU,IAAIE,CAAa,GAAG,OAAO,SAASK,CAAE;AACnD,YAAM,IAAI,MAAM,eAAeA,CAAE,SAASL,CAAa,EAAE;AAE3D,IAAAI,EAAW,CAAC,GAAGD,GAASE,CAAE,CAAC,GAC3BJ,EAAiBI,CAAE;AAAA,EAAA,GAmBQ,OALf,MAAM;AAClB,IAAAJ,EAAiBJ,CAAS,GAC1BO,EAAW,CAACP,CAAS,CAAC;AAAA,EAAA,GAGY,MAhBvB,MAAM;AACjB,QAAIM,EAAQ,WAAW,EAAG;AAE1B,UAAMG,IAAiBH,EAAQA,EAAQ,SAAS,CAAC;AACjD,QAAI,CAACL,EAAU,IAAIE,CAAa,GAAG,OAAO,SAASM,CAAc;AAC/D,YAAM,IAAI,MAAM,eAAeA,CAAc,SAASN,CAAa,EAAE;AAEvE,IAAAI,EAAWD,EAAQ,MAAM,GAAG,EAAE,CAAC,GAC/BF,EAAiBE,EAAQA,EAAQ,SAAS,CAAC,CAAC;AAAA,EAAA,GAQJ,SAAAA,EAAA;AAC5C;"}