@intlayer/design-system 3.4.9 → 3.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (343) hide show
  1. package/dist/.vite/manifest.json +0 -1
  2. package/dist/Form-BDcoNTLV.cjs.map +1 -1
  3. package/dist/Form-DhsgC7kB.js.map +1 -1
  4. package/dist/components/Accordion/Accordion.cjs.map +1 -1
  5. package/dist/components/Accordion/Accordion.mjs.map +1 -1
  6. package/dist/components/Auth/AuthModal/index.cjs.map +1 -1
  7. package/dist/components/Auth/AuthModal/index.mjs.map +1 -1
  8. package/dist/components/Auth/AuthenticationBarrier/AuthenticationBarrierClient.cjs.map +1 -1
  9. package/dist/components/Auth/AuthenticationBarrier/AuthenticationBarrierClient.mjs.map +1 -1
  10. package/dist/components/Auth/AuthenticationBarrier/AuthenticationBarrierServer.cjs.map +1 -1
  11. package/dist/components/Auth/AuthenticationBarrier/AuthenticationBarrierServer.mjs.map +1 -1
  12. package/dist/components/Auth/AuthenticationBarrier/accessValidation.cjs.map +1 -1
  13. package/dist/components/Auth/AuthenticationBarrier/accessValidation.mjs.map +1 -1
  14. package/dist/components/Auth/ChangePasswordForm/ChangePasswordForm.cjs.map +1 -1
  15. package/dist/components/Auth/ChangePasswordForm/ChangePasswordForm.mjs.map +1 -1
  16. package/dist/components/Auth/ChangePasswordForm/ChangePasswordSchema.cjs.map +1 -1
  17. package/dist/components/Auth/ChangePasswordForm/ChangePasswordSchema.mjs.map +1 -1
  18. package/dist/components/Auth/ChangePasswordForm/index.content.cjs.map +1 -1
  19. package/dist/components/Auth/ChangePasswordForm/index.content.mjs.map +1 -1
  20. package/dist/components/Auth/ExternalsLoginButtons/ExternalsLoginButtons.cjs.map +1 -1
  21. package/dist/components/Auth/ExternalsLoginButtons/ExternalsLoginButtons.mjs.map +1 -1
  22. package/dist/components/Auth/ExternalsLoginButtons/assets/GoogleLogo.cjs.map +1 -1
  23. package/dist/components/Auth/ExternalsLoginButtons/assets/GoogleLogo.mjs.map +1 -1
  24. package/dist/components/Auth/ExternalsLoginButtons/externalsLoginButtons.content.cjs.map +1 -1
  25. package/dist/components/Auth/ExternalsLoginButtons/externalsLoginButtons.content.mjs.map +1 -1
  26. package/dist/components/Auth/ResetPasswordForm/ResetPasswordForm.cjs.map +1 -1
  27. package/dist/components/Auth/ResetPasswordForm/ResetPasswordForm.mjs.map +1 -1
  28. package/dist/components/Auth/ResetPasswordForm/ResetPasswordSchema.cjs.map +1 -1
  29. package/dist/components/Auth/ResetPasswordForm/ResetPasswordSchema.mjs.map +1 -1
  30. package/dist/components/Auth/ResetPasswordForm/index.content.cjs.map +1 -1
  31. package/dist/components/Auth/ResetPasswordForm/index.content.mjs.map +1 -1
  32. package/dist/components/Auth/SignInForm/SignInForm.cjs.map +1 -1
  33. package/dist/components/Auth/SignInForm/SignInForm.mjs.map +1 -1
  34. package/dist/components/Auth/SignInForm/SignInSchema.cjs.map +1 -1
  35. package/dist/components/Auth/SignInForm/SignInSchema.mjs.map +1 -1
  36. package/dist/components/Auth/SignInForm/index.content.cjs.map +1 -1
  37. package/dist/components/Auth/SignInForm/index.content.mjs.map +1 -1
  38. package/dist/components/Auth/SignUpForm/SignUpForm.cjs.map +1 -1
  39. package/dist/components/Auth/SignUpForm/SignUpForm.mjs.map +1 -1
  40. package/dist/components/Auth/SignUpForm/SignUpSchema.cjs.map +1 -1
  41. package/dist/components/Auth/SignUpForm/SignUpSchema.mjs.map +1 -1
  42. package/dist/components/Auth/SignUpForm/index.content.cjs.map +1 -1
  43. package/dist/components/Auth/SignUpForm/index.content.mjs.map +1 -1
  44. package/dist/components/Auth/useAuth/index.cjs.map +1 -1
  45. package/dist/components/Auth/useAuth/index.mjs.map +1 -1
  46. package/dist/components/Auth/useAuth/useCSRF.cjs.map +1 -1
  47. package/dist/components/Auth/useAuth/useCSRF.mjs.map +1 -1
  48. package/dist/components/Auth/useAuth/useOAuth2.cjs.map +1 -1
  49. package/dist/components/Auth/useAuth/useOAuth2.mjs.map +1 -1
  50. package/dist/components/Auth/useAuth/useSession.cjs.map +1 -1
  51. package/dist/components/Auth/useAuth/useSession.mjs.map +1 -1
  52. package/dist/components/Auth/useUser/index.cjs.map +1 -1
  53. package/dist/components/Auth/useUser/index.mjs.map +1 -1
  54. package/dist/components/Avatar/index.cjs.map +1 -1
  55. package/dist/components/Avatar/index.mjs.map +1 -1
  56. package/dist/components/Badge/index.cjs.map +1 -1
  57. package/dist/components/Badge/index.mjs.map +1 -1
  58. package/dist/components/Breadcrumb/index.cjs.map +1 -1
  59. package/dist/components/Breadcrumb/index.mjs.map +1 -1
  60. package/dist/components/Button/Button.cjs.map +1 -1
  61. package/dist/components/Button/Button.mjs.map +1 -1
  62. package/dist/components/Command/index.cjs.map +1 -1
  63. package/dist/components/Command/index.mjs.map +1 -1
  64. package/dist/components/Container/index.cjs.map +1 -1
  65. package/dist/components/Container/index.mjs.map +1 -1
  66. package/dist/components/ContentEditor/ContentEditor.cjs.map +1 -1
  67. package/dist/components/ContentEditor/ContentEditor.mjs.map +1 -1
  68. package/dist/components/ContentEditor/ContentEditorTextArea.cjs.map +1 -1
  69. package/dist/components/ContentEditor/ContentEditorTextArea.mjs.map +1 -1
  70. package/dist/components/CopyToClipboard/index.cjs.map +1 -1
  71. package/dist/components/CopyToClipboard/index.mjs.map +1 -1
  72. package/dist/components/DictionaryEditor/DictionaryEditor.cjs.map +1 -1
  73. package/dist/components/DictionaryEditor/DictionaryEditor.mjs.map +1 -1
  74. package/dist/components/DictionaryEditor/ItemLayout.cjs.map +1 -1
  75. package/dist/components/DictionaryEditor/ItemLayout.mjs.map +1 -1
  76. package/dist/components/DictionaryEditor/NodeWrapper/StringWrapper.cjs.map +1 -1
  77. package/dist/components/DictionaryEditor/NodeWrapper/StringWrapper.mjs.map +1 -1
  78. package/dist/components/DictionaryEditor/ValidDictionaryChangeButtons.cjs.map +1 -1
  79. package/dist/components/DictionaryEditor/ValidDictionaryChangeButtons.mjs.map +1 -1
  80. package/dist/components/DictionaryEditor/useEditedContentStore.cjs.map +1 -1
  81. package/dist/components/DictionaryEditor/useEditedContentStore.mjs.map +1 -1
  82. package/dist/components/DictionaryEditor/useEditionPanelStore.cjs.map +1 -1
  83. package/dist/components/DictionaryEditor/useEditionPanelStore.mjs.map +1 -1
  84. package/dist/components/DictionaryEditor/validDictionaryChangeButtons.content.cjs.map +1 -1
  85. package/dist/components/DictionaryEditor/validDictionaryChangeButtons.content.mjs.map +1 -1
  86. package/dist/components/DictionaryEditor/validDictionaryChangeButtonsSchema.cjs.map +1 -1
  87. package/dist/components/DictionaryEditor/validDictionaryChangeButtonsSchema.mjs.map +1 -1
  88. package/dist/components/DictionaryFieldEditor/DictionariesSelector/DictionariesSelector.cjs.map +1 -1
  89. package/dist/components/DictionaryFieldEditor/DictionariesSelector/DictionariesSelector.mjs.map +1 -1
  90. package/dist/components/DictionaryFieldEditor/DictionariesSelector/dictionariesSelector.content.cjs.map +1 -1
  91. package/dist/components/DictionaryFieldEditor/DictionariesSelector/dictionariesSelector.content.mjs.map +1 -1
  92. package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/DictionaryCreationForm.cjs.map +1 -1
  93. package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/DictionaryCreationForm.mjs.map +1 -1
  94. package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/dictionaryCreationForm.content.cjs.map +1 -1
  95. package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/dictionaryCreationForm.content.mjs.map +1 -1
  96. package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/dictionaryFormSchema.cjs.map +1 -1
  97. package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/dictionaryFormSchema.mjs.map +1 -1
  98. package/dist/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.cjs.map +1 -1
  99. package/dist/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.mjs.map +1 -1
  100. package/dist/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsSchema.cjs.map +1 -1
  101. package/dist/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsSchema.mjs.map +1 -1
  102. package/dist/components/DictionaryFieldEditor/DictionaryDetails/dictionaryDetails.content.cjs.map +1 -1
  103. package/dist/components/DictionaryFieldEditor/DictionaryDetails/dictionaryDetails.content.mjs.map +1 -1
  104. package/dist/components/DictionaryFieldEditor/DictionaryFieldEditor.cjs.map +1 -1
  105. package/dist/components/DictionaryFieldEditor/DictionaryFieldEditor.mjs.map +1 -1
  106. package/dist/components/DictionaryFieldEditor/EditorView/EditorView.cjs.map +1 -1
  107. package/dist/components/DictionaryFieldEditor/EditorView/EditorView.mjs.map +1 -1
  108. package/dist/components/DictionaryFieldEditor/EditorView/TextEditor.cjs.map +1 -1
  109. package/dist/components/DictionaryFieldEditor/EditorView/TextEditor.mjs.map +1 -1
  110. package/dist/components/DictionaryFieldEditor/EnumKeyInput.cjs.map +1 -1
  111. package/dist/components/DictionaryFieldEditor/EnumKeyInput.mjs.map +1 -1
  112. package/dist/components/DictionaryFieldEditor/JSONEditor.cjs.map +1 -1
  113. package/dist/components/DictionaryFieldEditor/JSONEditor.mjs.map +1 -1
  114. package/dist/components/DictionaryFieldEditor/KeyPathBreadcrumb.cjs.map +1 -1
  115. package/dist/components/DictionaryFieldEditor/KeyPathBreadcrumb.mjs.map +1 -1
  116. package/dist/components/DictionaryFieldEditor/NavigationView/NavigationViewNode.cjs.map +1 -1
  117. package/dist/components/DictionaryFieldEditor/NavigationView/NavigationViewNode.mjs.map +1 -1
  118. package/dist/components/DictionaryFieldEditor/NavigationView/navigationViewNode.content.cjs.map +1 -1
  119. package/dist/components/DictionaryFieldEditor/NavigationView/navigationViewNode.content.mjs.map +1 -1
  120. package/dist/components/DictionaryFieldEditor/NodeEditor.cjs.map +1 -1
  121. package/dist/components/DictionaryFieldEditor/NodeEditor.mjs.map +1 -1
  122. package/dist/components/DictionaryFieldEditor/NodeTypeSelector.cjs.map +1 -1
  123. package/dist/components/DictionaryFieldEditor/NodeTypeSelector.mjs.map +1 -1
  124. package/dist/components/DictionaryFieldEditor/SaveForm/SaveForm.cjs.map +1 -1
  125. package/dist/components/DictionaryFieldEditor/SaveForm/SaveForm.mjs.map +1 -1
  126. package/dist/components/DictionaryFieldEditor/SaveForm/SaveFormSchema.cjs.map +1 -1
  127. package/dist/components/DictionaryFieldEditor/SaveForm/SaveFormSchema.mjs.map +1 -1
  128. package/dist/components/DictionaryFieldEditor/SaveForm/saveForm.content.cjs.map +1 -1
  129. package/dist/components/DictionaryFieldEditor/SaveForm/saveForm.content.mjs.map +1 -1
  130. package/dist/components/DictionaryFieldEditor/dictionaryFieldEditor.content.cjs.map +1 -1
  131. package/dist/components/DictionaryFieldEditor/dictionaryFieldEditor.content.mjs.map +1 -1
  132. package/dist/components/DictionaryFieldEditor/editorView.content.cjs.map +1 -1
  133. package/dist/components/DictionaryFieldEditor/editorView.content.mjs.map +1 -1
  134. package/dist/components/DictionaryFieldEditor/getIsEditableSection.cjs.map +1 -1
  135. package/dist/components/DictionaryFieldEditor/getIsEditableSection.mjs.map +1 -1
  136. package/dist/components/DictionaryFieldEditor/nodeTypeSelector.content.cjs.map +1 -1
  137. package/dist/components/DictionaryFieldEditor/nodeTypeSelector.content.mjs.map +1 -1
  138. package/dist/components/DropDown/index.cjs.map +1 -1
  139. package/dist/components/DropDown/index.mjs.map +1 -1
  140. package/dist/components/EditableField/EditableFieldInput.cjs.map +1 -1
  141. package/dist/components/EditableField/EditableFieldInput.mjs.map +1 -1
  142. package/dist/components/EditableField/EditableFieldLayout.cjs.map +1 -1
  143. package/dist/components/EditableField/EditableFieldLayout.mjs.map +1 -1
  144. package/dist/components/EditableField/EditableFieldTextArea.cjs.map +1 -1
  145. package/dist/components/EditableField/EditableFieldTextArea.mjs.map +1 -1
  146. package/dist/components/Footer/index.cjs.map +1 -1
  147. package/dist/components/Footer/index.mjs.map +1 -1
  148. package/dist/components/Form/FormBase.cjs.map +1 -1
  149. package/dist/components/Form/FormBase.mjs.map +1 -1
  150. package/dist/components/Form/FormControl.cjs.map +1 -1
  151. package/dist/components/Form/FormControl.mjs.map +1 -1
  152. package/dist/components/Form/FormDescription.cjs.map +1 -1
  153. package/dist/components/Form/FormDescription.mjs.map +1 -1
  154. package/dist/components/Form/FormField.cjs.map +1 -1
  155. package/dist/components/Form/FormField.mjs.map +1 -1
  156. package/dist/components/Form/FormItem.cjs.map +1 -1
  157. package/dist/components/Form/FormItem.mjs.map +1 -1
  158. package/dist/components/Form/FormLabel.cjs.map +1 -1
  159. package/dist/components/Form/FormLabel.mjs.map +1 -1
  160. package/dist/components/Form/FormMessage.cjs.map +1 -1
  161. package/dist/components/Form/FormMessage.mjs.map +1 -1
  162. package/dist/components/Form/elements/FormElementWrapper.cjs.map +1 -1
  163. package/dist/components/Form/elements/FormElementWrapper.mjs.map +1 -1
  164. package/dist/components/Form/layout/FormLabelLayout.cjs.map +1 -1
  165. package/dist/components/Form/layout/FormLabelLayout.mjs.map +1 -1
  166. package/dist/components/Headers/SectionScroller.cjs.map +1 -1
  167. package/dist/components/Headers/SectionScroller.mjs.map +1 -1
  168. package/dist/components/Headers/index.cjs.map +1 -1
  169. package/dist/components/Headers/index.mjs.map +1 -1
  170. package/dist/components/IDE/CodeRender.cjs +9 -3
  171. package/dist/components/IDE/CodeRender.cjs.map +1 -1
  172. package/dist/components/IDE/CodeRender.d.ts.map +1 -1
  173. package/dist/components/IDE/CodeRender.mjs +9 -3
  174. package/dist/components/IDE/CodeRender.mjs.map +1 -1
  175. package/dist/components/IDE/FileList.cjs.map +1 -1
  176. package/dist/components/IDE/FileList.mjs.map +1 -1
  177. package/dist/components/IDE/FileTree.cjs.map +1 -1
  178. package/dist/components/IDE/FileTree.mjs.map +1 -1
  179. package/dist/components/IDE/IDE.cjs +1 -1
  180. package/dist/components/IDE/IDE.cjs.map +1 -1
  181. package/dist/components/IDE/IDE.mjs +1 -1
  182. package/dist/components/IDE/IDE.mjs.map +1 -1
  183. package/dist/components/IDE/MarkDownRender.cjs.map +1 -1
  184. package/dist/components/IDE/MarkDownRender.mjs.map +1 -1
  185. package/dist/components/IDE/createFileTree.cjs.map +1 -1
  186. package/dist/components/IDE/createFileTree.mjs.map +1 -1
  187. package/dist/components/Input/Checkbox.cjs.map +1 -1
  188. package/dist/components/Input/Checkbox.mjs.map +1 -1
  189. package/dist/components/Input/Input.cjs.map +1 -1
  190. package/dist/components/Input/Input.mjs.map +1 -1
  191. package/dist/components/Input/InputPassword.cjs.map +1 -1
  192. package/dist/components/Input/InputPassword.mjs.map +1 -1
  193. package/dist/components/Link/Link.cjs.map +1 -1
  194. package/dist/components/Link/Link.mjs.map +1 -1
  195. package/dist/components/Loader/spinner.cjs.map +1 -1
  196. package/dist/components/Loader/spinner.mjs.map +1 -1
  197. package/dist/components/LocaleSwitcherDropDown/LocaleSwitcher.cjs.map +1 -1
  198. package/dist/components/LocaleSwitcherDropDown/LocaleSwitcher.mjs.map +1 -1
  199. package/dist/components/Logo/LogoCircle.cjs.map +1 -1
  200. package/dist/components/Logo/LogoCircle.mjs.map +1 -1
  201. package/dist/components/Logo/LogoNoFrame.cjs.map +1 -1
  202. package/dist/components/Logo/LogoNoFrame.mjs.map +1 -1
  203. package/dist/components/Logo/LogoSquare.cjs.map +1 -1
  204. package/dist/components/Logo/LogoSquare.mjs.map +1 -1
  205. package/dist/components/Logo/LogoSquircle.cjs.map +1 -1
  206. package/dist/components/Logo/LogoSquircle.mjs.map +1 -1
  207. package/dist/components/Logo/LogoTextOnly.cjs.map +1 -1
  208. package/dist/components/Logo/LogoTextOnly.mjs.map +1 -1
  209. package/dist/components/Logo/LogoWithTextBelowCircle.cjs.map +1 -1
  210. package/dist/components/Logo/LogoWithTextBelowCircle.mjs.map +1 -1
  211. package/dist/components/Logo/LogoWithTextBelowNoFrame.cjs.map +1 -1
  212. package/dist/components/Logo/LogoWithTextBelowNoFrame.mjs.map +1 -1
  213. package/dist/components/Logo/LogoWithTextBelowSquircle.cjs.map +1 -1
  214. package/dist/components/Logo/LogoWithTextBelowSquircle.mjs.map +1 -1
  215. package/dist/components/Logo/LogoWithTextCircle.cjs.map +1 -1
  216. package/dist/components/Logo/LogoWithTextCircle.mjs.map +1 -1
  217. package/dist/components/Logo/LogoWithTextNoFrame.cjs.map +1 -1
  218. package/dist/components/Logo/LogoWithTextNoFrame.mjs.map +1 -1
  219. package/dist/components/Logo/LogoWithTextSquircle.cjs.map +1 -1
  220. package/dist/components/Logo/LogoWithTextSquircle.mjs.map +1 -1
  221. package/dist/components/Logo/index.cjs.map +1 -1
  222. package/dist/components/Logo/index.mjs.map +1 -1
  223. package/dist/components/MarkDownRender/index.cjs.map +1 -1
  224. package/dist/components/MarkDownRender/index.mjs.map +1 -1
  225. package/dist/components/MaxHeightSmoother/index.cjs.map +1 -1
  226. package/dist/components/MaxHeightSmoother/index.mjs.map +1 -1
  227. package/dist/components/MaxWidthSmoother/index.cjs.map +1 -1
  228. package/dist/components/MaxWidthSmoother/index.mjs.map +1 -1
  229. package/dist/components/Modal/Modal.cjs.map +1 -1
  230. package/dist/components/Modal/Modal.mjs.map +1 -1
  231. package/dist/components/Navbar/Burger.cjs.map +1 -1
  232. package/dist/components/Navbar/Burger.mjs.map +1 -1
  233. package/dist/components/Navbar/DesktopNavbar.cjs.map +1 -1
  234. package/dist/components/Navbar/DesktopNavbar.mjs.map +1 -1
  235. package/dist/components/Navbar/MobileNavbar.cjs.map +1 -1
  236. package/dist/components/Navbar/MobileNavbar.mjs.map +1 -1
  237. package/dist/components/Navbar/index.cjs.map +1 -1
  238. package/dist/components/Navbar/index.mjs.map +1 -1
  239. package/dist/components/Navbar/useNavigation.cjs.map +1 -1
  240. package/dist/components/Navbar/useNavigation.mjs.map +1 -1
  241. package/dist/components/Pattern/DotPattern.cjs.map +1 -1
  242. package/dist/components/Pattern/DotPattern.mjs.map +1 -1
  243. package/dist/components/Pattern/GridPattern.cjs.map +1 -1
  244. package/dist/components/Pattern/GridPattern.mjs.map +1 -1
  245. package/dist/components/Pattern/SpotLight.cjs.map +1 -1
  246. package/dist/components/Pattern/SpotLight.mjs.map +1 -1
  247. package/dist/components/Popover/index.cjs.map +1 -1
  248. package/dist/components/Popover/index.mjs.map +1 -1
  249. package/dist/components/PressableSpan/PressableSpan.cjs.map +1 -1
  250. package/dist/components/PressableSpan/PressableSpan.mjs.map +1 -1
  251. package/dist/components/ProfileDropDown/index.cjs.map +1 -1
  252. package/dist/components/ProfileDropDown/index.mjs.map +1 -1
  253. package/dist/components/RightDrawer/RightDrawer.cjs.map +1 -1
  254. package/dist/components/RightDrawer/RightDrawer.mjs.map +1 -1
  255. package/dist/components/RightDrawer/useRightDrawerStore.cjs.map +1 -1
  256. package/dist/components/RightDrawer/useRightDrawerStore.mjs.map +1 -1
  257. package/dist/components/Select/Multiselect.cjs.map +1 -1
  258. package/dist/components/Select/Multiselect.mjs.map +1 -1
  259. package/dist/components/Select/Select.cjs.map +1 -1
  260. package/dist/components/Select/Select.mjs.map +1 -1
  261. package/dist/components/SwitchSelector/index.cjs.map +1 -1
  262. package/dist/components/SwitchSelector/index.mjs.map +1 -1
  263. package/dist/components/TabSelector/TabSelector.cjs.map +1 -1
  264. package/dist/components/TabSelector/TabSelector.mjs.map +1 -1
  265. package/dist/components/Tag/index.cjs.map +1 -1
  266. package/dist/components/Tag/index.mjs.map +1 -1
  267. package/dist/components/TextArea/AutoSizeTextArea.cjs.map +1 -1
  268. package/dist/components/TextArea/AutoSizeTextArea.mjs.map +1 -1
  269. package/dist/components/TextArea/TextArea.cjs.map +1 -1
  270. package/dist/components/TextArea/TextArea.mjs.map +1 -1
  271. package/dist/components/ThemeSwitcherDropDown/DesktopThemeSwitcher.cjs.map +1 -1
  272. package/dist/components/ThemeSwitcherDropDown/DesktopThemeSwitcher.mjs.map +1 -1
  273. package/dist/components/ThemeSwitcherDropDown/MobileThemeSwitcher.cjs.map +1 -1
  274. package/dist/components/ThemeSwitcherDropDown/MobileThemeSwitcher.mjs.map +1 -1
  275. package/dist/components/Toaster/Toast.cjs.map +1 -1
  276. package/dist/components/Toaster/Toast.mjs.map +1 -1
  277. package/dist/components/Toaster/Toaster.cjs.map +1 -1
  278. package/dist/components/Toaster/Toaster.mjs.map +1 -1
  279. package/dist/components/Toaster/useToast.cjs.map +1 -1
  280. package/dist/components/Toaster/useToast.mjs.map +1 -1
  281. package/dist/components/WithResizer/index.cjs.map +1 -1
  282. package/dist/components/WithResizer/index.mjs.map +1 -1
  283. package/dist/hooks/intlayerAPIHooks.cjs.map +1 -1
  284. package/dist/hooks/intlayerAPIHooks.mjs.map +1 -1
  285. package/dist/hooks/useAsync/useAsync.cjs.map +1 -1
  286. package/dist/hooks/useAsync/useAsync.mjs.map +1 -1
  287. package/dist/hooks/useAsync/useAsyncStateStore.cjs.map +1 -1
  288. package/dist/hooks/useAsync/useAsyncStateStore.mjs.map +1 -1
  289. package/dist/hooks/useDevice.cjs.map +1 -1
  290. package/dist/hooks/useDevice.mjs.map +1 -1
  291. package/dist/hooks/useGetAllDictionaries.cjs.map +1 -1
  292. package/dist/hooks/useGetAllDictionaries.mjs.map +1 -1
  293. package/dist/hooks/useGetElementOrWindow.cjs.map +1 -1
  294. package/dist/hooks/useIntlayerAPI.cjs.map +1 -1
  295. package/dist/hooks/useIntlayerAPI.mjs.map +1 -1
  296. package/dist/hooks/useIsMounted.cjs.map +1 -1
  297. package/dist/hooks/useIsMounted.mjs.map +1 -1
  298. package/dist/hooks/useItemSelector.cjs.map +1 -1
  299. package/dist/hooks/useItemSelector.mjs.map +1 -1
  300. package/dist/hooks/usePersistedStore.cjs.map +1 -1
  301. package/dist/hooks/usePersistedStore.mjs.map +1 -1
  302. package/dist/hooks/useScrollBlockage/index.cjs.map +1 -1
  303. package/dist/hooks/useScrollBlockage/index.mjs.map +1 -1
  304. package/dist/hooks/useScrollBlockage/useScrollBlockageStore.cjs.map +1 -1
  305. package/dist/hooks/useScrollBlockage/useScrollBlockageStore.mjs.map +1 -1
  306. package/dist/hooks/useScrollDetection.cjs.map +1 -1
  307. package/dist/hooks/useScrollDetection.mjs.map +1 -1
  308. package/dist/index-BtZWYJhL.cjs.map +1 -1
  309. package/dist/index-D9oaKvKC.js.map +1 -1
  310. package/dist/jsx-runtime-DaNGiM0W.js.map +1 -1
  311. package/dist/jsx-runtime-XHKiWCTo.cjs.map +1 -1
  312. package/dist/libs/intlayer-api/auth.cjs.map +1 -1
  313. package/dist/libs/intlayer-api/auth.mjs.map +1 -1
  314. package/dist/libs/intlayer-api/dictionary.cjs.map +1 -1
  315. package/dist/libs/intlayer-api/dictionary.mjs.map +1 -1
  316. package/dist/libs/intlayer-api/fetcher.cjs.map +1 -1
  317. package/dist/libs/intlayer-api/fetcher.mjs.map +1 -1
  318. package/dist/libs/intlayer-api/organization.cjs.map +1 -1
  319. package/dist/libs/intlayer-api/organization.mjs.map +1 -1
  320. package/dist/libs/intlayer-api/project.cjs.map +1 -1
  321. package/dist/libs/intlayer-api/project.mjs.map +1 -1
  322. package/dist/libs/intlayer-api/stripe.cjs.map +1 -1
  323. package/dist/libs/intlayer-api/stripe.mjs.map +1 -1
  324. package/dist/libs/intlayer-api/user.cjs.map +1 -1
  325. package/dist/libs/intlayer-api/user.mjs.map +1 -1
  326. package/dist/shallow-lhDIFtEp.cjs.map +1 -1
  327. package/dist/shallow-m9BpCkKh.js.map +1 -1
  328. package/dist/tailwind.config.cjs.map +1 -1
  329. package/dist/tailwind.config.mjs.map +1 -1
  330. package/dist/tailwind.css +1 -1
  331. package/dist/utils/camelCase.cjs.map +1 -1
  332. package/dist/utils/camelCase.mjs.map +1 -1
  333. package/dist/utils/capitalize.cjs.map +1 -1
  334. package/dist/utils/capitalize.mjs.map +1 -1
  335. package/dist/utils/dictionary.cjs.map +1 -1
  336. package/dist/utils/dictionary.mjs.map +1 -1
  337. package/dist/utils/isElementAtTopAndNotCovered.cjs.map +1 -1
  338. package/dist/utils/isElementAtTopAndNotCovered.mjs.map +1 -1
  339. package/dist/utils/object.cjs.map +1 -1
  340. package/dist/utils/object.mjs.map +1 -1
  341. package/dist/zod-BV4nCGJE.js.map +1 -1
  342. package/dist/zod-DSrtTSD_.cjs.map +1 -1
  343. package/package.json +14 -14
@@ -1 +1 @@
1
- {"version":3,"file":"useAsync.cjs","sources":["../../../src/hooks/useAsync/useAsync.ts"],"sourcesContent":["'use client';\n\n// This is an ESLint directive to disable specific rules.\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { useCallback, useEffect, useMemo, useRef } from 'react';\nimport { useShallow } from 'zustand/react/shallow';\nimport { useAsyncStateStore } from './useAsyncStateStore';\n\n// Pending promises cache to prevent parallel requests when multiple components use the hook\nconst pendingPromises = new Map();\n\n// Defines the base structure for the result of the custom hook.\ntype UseAsyncResultBase<T extends (...args: any[]) => Promise<any>> = {\n isFetched: boolean;\n isLoading: boolean;\n isInvalidated: boolean;\n isSuccess: boolean;\n isDisabled: boolean;\n error: string | null;\n data: Awaited<ReturnType<T>> | null;\n retryCount: number;\n revalidate: T;\n setData: (data: Awaited<ReturnType<T> | null>) => void;\n};\n\n// Options type for the hook, allowing customization of behavior.\nexport type UseAsyncOptions<T extends (...args: any[]) => Promise<any>> = {\n retryLimit?: number; // The number of times the hook should retry the function on failure before giving up\n retryTime?: number; // Time in milliseconds for retrying the data\n cache?: boolean; // Cache the result of the function using zustand\n store?: boolean; // Store the result of the function in session storage\n enable?: boolean; // Enable the hook\n autoFetch?: boolean; // Automatically fetch the data when the hook is mounted\n revalidation?: boolean; // Enable revalidation\n revalidateTime?: number; // Time in milliseconds for revalidating the data\n invalidateQueries?: string[]; // Invalidate other queries when the data is updated\n updateQueries?: string[]; // Update other queries when the data is updated\n onSuccess?: (data: Awaited<ReturnType<T>>) => void; // Callback function that is called when the asynchronous function resolves successfully\n onError?: (error: string) => void; // Callback function that is called when the asynchronous function rejects or encounters an error\n args?: Parameters<T>; // Arguments to pass to the asynchronous function\n};\n\n// Default values for the hook's options\nconst DEFAULT_CACHE_ENABLED = false;\nconst DEFAULT_STORE_ENABLED = false;\nconst DEFAULT_ENABLED = true;\nconst DEFAULT_AUTO_FETCH = false;\nconst DEFAULT_RETRY_LIMIT = 1;\nconst DEFAULT_REVALIDATION_ENABLED = false;\nconst DEFAULT_REVALIDATE_TIME = 5 * 60 * 1000; // 5 minutes\nconst DEFAULT_RETRY_TIME = 5 * 60 * 1000; // 5 minutes\n\n// The main hook type that includes the async function along with its additional properties.\nexport type UseAsyncResult<\n U extends string,\n T extends (...args: any[]) => Promise<any>,\n> = UseAsyncResultBase<T> & Record<U, T>;\n\nconst getArgs = (args?: any[]): any[] =>\n args ? (Array.isArray(args) ? args : [args]) : [];\n\nconst getKeyWithArgs = (key: string, args: any[]) =>\n getArgs(args).length > 0 ? `${key}/${JSON.stringify(args)}` : key;\n\n/**\n * A custom React hook that manages asynchronous operations, providing easy-to-use states and controls over fetching, caching, and retry mechanisms.\n * This hook abstracts away the complexity of handling loading, error, and success states for any asynchronous function.\n *\n * @template U - A string type that extends the keys of the async function, used as a key to store and retrieve state.\n * @template T - A function type that must return a Promise, representing the asynchronous operation to be managed.\n *\n * @param {U} key - A unique identifier for the async operation, used to handle state internally and avoid conflicts.\n * @param {T} asyncFunction - The asynchronous function that will be managed by this hook. This function should return a Promise.\n * @param {UseAsyncOptions<T>} [options] - Optional configuration options to customize the behavior of the hook.\n * @returns {UseAsyncResult<U, T>} The states and controls related to the managed async function. Includes states like isLoading, isSuccess, and provides control methods like revalidate and setData.\n *\n * @typedef {Object} UseAsyncOptions\n * @property {number} [retryTime=300000] - Time in milliseconds for retrying the data after an error occurs.\n * @property {number} [retryLimit=1] - The number of times the hook should retry the asynchronous function on failure before giving up.\n * @property {boolean} [revalidation=false] - Enable revalidation.\n * @property {number} [revalidateTime=300000] - Time in milliseconds after which the cached data is considered stale and the async function is re-invoked, if caching is enabled.\n * @property {boolean} [cache=false] - Whether to cache the result of the async function. When enabled, revalidation is controlled by `revalidateTime`.\n * @property {boolean} [store=false] - Store the result of the function in session storage.\n * @property {boolean} [autoFetch=false] - Whether the hook should automatically invoke the asynchronous function on mount.\n * @property {number} [revalidateTime=300000] - Time in milliseconds after which the cached data is considered stale and the async function is re-invoked, if caching is enabled.\n * @property {string[]} [updateQueries=[]] - Update other queries when the data is updated.\n * @property {string[]} [invalidateQueries=[]] - Invalidate other queries when the data is updated.\n * @property {(data: Awaited<ReturnType<T>>) => void} [onSuccess] - Callback function that is called when the asynchronous function resolves successfully.\n * @property {(error: string) => void} [onError] - Callback function that is called when the asynchronous function rejects or encounters an error.\n * @property {Parameters<T>} [args=[]] - Arguments to pass to the asynchronous function.\n *\n *\n * @example\n * // Example of using useAsync to manage fetching user data from an API.\n * const fetchUserData = async (userId) => {\n * const response = await fetch(`/api/users/${userId}`);\n * if (!response.ok) throw new Error('Failed to fetch');\n * return await response.json();\n * };\n *\n * const UserDetails = ({ userId }) => {\n * const {\n * isLoading,\n * data,\n * error,\n * revalidate,\n * } = useAsync('userDetails', fetchUserData, {\n * cache: true,\n * revalidateTime: 60000, // 1 minute\n * autoFetch: true,\n * onSuccess: (data) => console.log('User data fetched successfully:', data),\n * onError: (error) => console.error('Error fetching user data:', error),\n * });\n *\n * if (isLoading) return <div>Loading...</div>;\n * if (error) return <div>Error: {error}</div>;\n * return (\n * <div>\n * <h1>{data.name}</h1>\n * <button onClick={() => revalidate()}>Refresh</button>\n * </div>\n * );\n * };\n */\nexport const useAsync = <\n U extends string,\n T extends (...args: any[]) => Promise<any>,\n>(\n key: U,\n asyncFunction: T,\n options?: UseAsyncOptions<T>\n): UseAsyncResult<U, T> => {\n // Resolving optional parameters with default values\n const retryLimit = options?.retryLimit ?? DEFAULT_RETRY_LIMIT;\n const autoFetch = options?.autoFetch ?? DEFAULT_AUTO_FETCH;\n const retryTime = options?.retryTime ?? DEFAULT_RETRY_TIME;\n const cacheEnabled = options?.cache ?? DEFAULT_CACHE_ENABLED;\n const storeEnabled = options?.store ?? DEFAULT_STORE_ENABLED;\n const enabled = options?.enable ?? DEFAULT_ENABLED;\n const revalidationEnabled =\n options?.revalidation ?? DEFAULT_REVALIDATION_ENABLED;\n const revalidateTime = options?.revalidateTime ?? DEFAULT_REVALIDATE_TIME;\n const updateQueries = options?.updateQueries ?? [];\n const invalidateQueries = options?.invalidateQueries ?? [];\n const onSuccess = options?.onSuccess;\n const onError = options?.onError;\n const args = getArgs(options?.args ?? []);\n\n // Using a custom hook to manage state specific to asynchronous operations\n const { setQueryState, setQueriesState, makeQueryInError } =\n useAsyncStateStore(\n useShallow((state) => ({\n setQueryState: state.setQueryState,\n setQueriesState: state.setQueriesState,\n makeQueryInError: state.makeQueryInError,\n }))\n );\n\n // Storing the last arguments used to call the async function\n const storedArgsRef = useRef<any[]>(args);\n\n // Apply different key for different requests\n const keyWithArgs = getKeyWithArgs(key, storedArgsRef.current);\n\n // Retrieving the current state of async operations using the same custom hook\n const {\n isFetched,\n fetchedDateTime,\n isLoading,\n isEnabled,\n error,\n isSuccess,\n isInvalidated,\n data,\n retryCount: errorCount,\n } = useAsyncStateStore(useShallow((state) => state.getStates(keyWithArgs)));\n\n // The core fetching function, designed to be called directly or automatically based on configuration\n const fetch: T = useCallback<T>(\n (async (...args) => {\n const keyWithArgs = getKeyWithArgs(key, args);\n\n if (pendingPromises.has(keyWithArgs)) {\n // Return the existing pending promise\n return pendingPromises.get(keyWithArgs);\n }\n\n const promise = (async () => {\n setQueryState(keyWithArgs, { isLoading: true });\n let response = null;\n\n await asyncFunction(...args)\n .then((result) => {\n response = result;\n\n setQueryState(keyWithArgs, {\n data: result,\n retryCount: 0,\n isLoading: false,\n isFetched: true,\n isSuccess: true,\n isInvalidated: false,\n error: null,\n });\n\n onSuccess?.(result);\n\n // Invalidate other queries if necessary\n if (invalidateQueries.length > 0) {\n setQueriesState(invalidateQueries, {\n isInvalidated: true,\n });\n }\n\n // Update other queries if necessary\n if (updateQueries.length > 0) {\n setQueriesState(updateQueries, {\n data: result,\n });\n }\n\n // Store the result in session storage\n if (storeEnabled) {\n sessionStorage.setItem(keyWithArgs, JSON.stringify(result));\n }\n })\n .catch((error) => {\n makeQueryInError(keyWithArgs, error.message);\n onError?.(error.message);\n })\n .finally(() => {\n // Remove the pending promise from the cache\n pendingPromises.delete(keyWithArgs);\n });\n\n return response;\n })();\n\n // Store the pending promise in the cache\n pendingPromises.set(keyWithArgs, promise);\n\n return await promise;\n }) as T,\n [asyncFunction, keyWithArgs, storeEnabled, cacheEnabled, onSuccess, onError]\n );\n\n // Wrapped execution function to handle disabled state and check for success before re-fetching\n const execute: T = useCallback<T>(\n (async (...args) => {\n if (!isEnabled || !enabled) return;\n if (isLoading) return;\n if (!isInvalidated && isSuccess && cacheEnabled && data) return data;\n\n if (args) {\n storedArgsRef.current = getArgs(...args);\n }\n\n return await fetch(...args);\n }) as T,\n [\n isEnabled,\n enabled,\n isInvalidated,\n cacheEnabled,\n isSuccess,\n data,\n isLoading,\n fetch,\n ]\n );\n\n // Function to revalidate the data when necessary\n const revalidate: T = useCallback<T>(\n (async (...args) => {\n if (!isEnabled || !enabled) return;\n\n if (args) {\n storedArgsRef.current = getArgs(...args);\n }\n\n const result = await fetch(...storedArgsRef.current);\n\n return result;\n }) as T,\n [isEnabled, enabled, storedArgsRef, fetch]\n );\n\n const autoRevalidate = useCallback(async () => {\n if (!isEnabled || !enabled) return;\n if (isLoading) return;\n if (!(cacheEnabled || storeEnabled)) return;\n if (!isSuccess) return;\n if (!revalidationEnabled || revalidateTime <= 0) return;\n if (!fetchedDateTime) return;\n\n const now = new Date().getTime();\n const lastFetchedTime = new Date(fetchedDateTime).getTime();\n const shouldRevalidate = now - lastFetchedTime >= revalidateTime;\n if (shouldRevalidate) {\n return await fetch(...storedArgsRef.current);\n }\n }, [\n cacheEnabled,\n revalidationEnabled,\n revalidateTime,\n isSuccess,\n fetchedDateTime,\n isLoading,\n isEnabled,\n enabled,\n ]);\n\n useEffect(() => {\n if (enabled !== isEnabled) {\n setQueryState(keyWithArgs, {\n isEnabled,\n });\n }\n }, [enabled, isEnabled, keyWithArgs]);\n\n // Auto-fetch data on hook mount if autoFetch is true\n useEffect(() => {\n if (!autoFetch) return;\n if (!isEnabled || !enabled) return;\n if (isFetched && !isInvalidated) return;\n if (isLoading) return;\n\n fetch(...storedArgsRef.current);\n }, [\n autoFetch,\n isFetched,\n isInvalidated,\n isEnabled,\n enabled,\n isLoading,\n fetch,\n ]);\n\n // Handle retry based on conditions set in options\n useEffect(() => {\n const isRetryEnabled = errorCount > 0 && retryLimit > 0;\n const isRetryLimitReached = errorCount >= retryLimit;\n if (!isEnabled || !enabled) return;\n if (!(cacheEnabled || storeEnabled)) return;\n if (!isRetryEnabled || isRetryLimitReached) return;\n if (isSuccess) return;\n if (isLoading) return;\n\n const timeOut = setTimeout(() => {\n fetch(...storedArgsRef.current);\n }, retryTime);\n\n return () => clearTimeout(timeOut);\n }, [\n fetch,\n errorCount,\n retryLimit,\n retryTime,\n isSuccess,\n isEnabled,\n enabled,\n isLoading,\n cacheEnabled,\n storeEnabled,\n ]);\n\n // Handle periodic revalidation if caching is enabled\n useEffect(() => {\n const interval = setInterval(autoRevalidate, revalidateTime);\n\n return () => clearInterval(interval);\n }, [autoRevalidate, revalidateTime]);\n\n // Load data from session storage if storeEnabled is true\n useEffect(() => {\n if (!isEnabled || !enabled) return;\n if (!storeEnabled) return;\n if (isInvalidated) return;\n if (isFetched) return;\n if (data) return;\n\n const storedData = sessionStorage.getItem(keyWithArgs);\n\n if (storedData && JSON.stringify(storedData) !== JSON.stringify(data)) {\n setQueryState(keyWithArgs, {\n data: JSON.parse(storedData),\n });\n }\n }, [\n storeEnabled,\n keyWithArgs,\n isFetched,\n isInvalidated,\n isEnabled,\n enabled,\n data,\n ]);\n\n // Memoization of the setData function to prevent unnecessary re-renders\n const setDataMemo = useCallback(\n (data: Awaited<ReturnType<T> | null>) => {\n setQueryState(keyWithArgs, {\n data,\n });\n },\n [keyWithArgs]\n );\n\n const memoResult = useMemo(\n () => ({\n isFetched,\n isLoading,\n isInvalidated,\n error,\n isSuccess,\n data,\n retryCount: errorCount,\n isDisabled: !isEnabled,\n isEnabled,\n [key]: execute,\n revalidate,\n setData: setDataMemo,\n }),\n [\n isFetched,\n isLoading,\n isInvalidated,\n error,\n isSuccess,\n data,\n errorCount,\n isEnabled,\n key,\n execute,\n revalidate,\n setDataMemo,\n ]\n );\n\n // Return the hook's result, including all state and control functions\n return memoResult as UseAsyncResultBase<T> & Record<U, T>;\n};\n"],"names":["useAsyncStateStore","useShallow","useRef","useCallback","args","keyWithArgs","error","useEffect","data","useMemo"],"mappings":";;;;;;AAUA,MAAM,sCAAsB;AAkC5B,MAAM,wBAAwB;AAC9B,MAAM,wBAAwB;AAC9B,MAAM,kBAAkB;AACxB,MAAM,qBAAqB;AAC3B,MAAM,sBAAsB;AAC5B,MAAM,+BAA+B;AACrC,MAAM,0BAA0B,IAAI,KAAK;AACzC,MAAM,qBAAqB,IAAI,KAAK;AAQpC,MAAM,UAAU,CAAC,SACf,OAAQ,MAAM,QAAQ,IAAI,IAAI,OAAO,CAAC,IAAI,IAAK,CAAA;AAEjD,MAAM,iBAAiB,CAAC,KAAa,SACnC,QAAQ,IAAI,EAAE,SAAS,IAAI,GAAG,GAAG,IAAI,KAAK,UAAU,IAAI,CAAC,KAAK;AA8DzD,MAAM,WAAW,CAItB,KACA,eACA,YACyB;AAEnB,QAAA,aAAa,SAAS,cAAc;AACpC,QAAA,YAAY,SAAS,aAAa;AAClC,QAAA,YAAY,SAAS,aAAa;AAClC,QAAA,eAAe,SAAS,SAAS;AACjC,QAAA,eAAe,SAAS,SAAS;AACjC,QAAA,UAAU,SAAS,UAAU;AAC7B,QAAA,sBACJ,SAAS,gBAAgB;AACrB,QAAA,iBAAiB,SAAS,kBAAkB;AAC5C,QAAA,gBAAgB,SAAS,iBAAiB;AAC1C,QAAA,oBAAoB,SAAS,qBAAqB;AACxD,QAAM,YAAY,SAAS;AAC3B,QAAM,UAAU,SAAS;AACzB,QAAM,OAAO,QAAQ,SAAS,QAAQ,CAAE,CAAA;AAGxC,QAAM,E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ync/useAsync.ts"],"sourcesContent":["'use client';\n\n// This is an ESLint directive to disable specific rules.\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { useCallback, useEffect, useMemo, useRef } from 'react';\nimport { useShallow } from 'zustand/react/shallow';\nimport { useAsyncStateStore } from './useAsyncStateStore';\n\n// Pending promises cache to prevent parallel requests when multiple components use the hook\nconst pendingPromises = new Map();\n\n// Defines the base structure for the result of the custom hook.\ntype UseAsyncResultBase<T extends (...args: any[]) => Promise<any>> = {\n isFetched: boolean;\n isLoading: boolean;\n isInvalidated: boolean;\n isSuccess: boolean;\n isDisabled: boolean;\n error: string | null;\n data: Awaited<ReturnType<T>> | null;\n retryCount: number;\n revalidate: T;\n setData: (data: Awaited<ReturnType<T> | null>) => void;\n};\n\n// Options type for the hook, allowing customization of behavior.\nexport type UseAsyncOptions<T extends (...args: any[]) => Promise<any>> = {\n retryLimit?: number; // The number of times the hook should retry the function on failure before giving up\n retryTime?: number; // Time in milliseconds for retrying the data\n cache?: boolean; // Cache the result of the function using zustand\n store?: boolean; // Store the result of the function in session storage\n enable?: boolean; // Enable the hook\n autoFetch?: boolean; // Automatically fetch the data when the hook is mounted\n revalidation?: boolean; // Enable revalidation\n revalidateTime?: number; // Time in milliseconds for revalidating the data\n invalidateQueries?: string[]; // Invalidate other queries when the data is updated\n updateQueries?: string[]; // Update other queries when the data is updated\n onSuccess?: (data: Awaited<ReturnType<T>>) => void; // Callback function that is called when the asynchronous function resolves successfully\n onError?: (error: string) => void; // Callback function that is called when the asynchronous function rejects or encounters an error\n args?: Parameters<T>; // Arguments to pass to the asynchronous function\n};\n\n// Default values for the hook's options\nconst DEFAULT_CACHE_ENABLED = false;\nconst DEFAULT_STORE_ENABLED = false;\nconst DEFAULT_ENABLED = true;\nconst DEFAULT_AUTO_FETCH = false;\nconst DEFAULT_RETRY_LIMIT = 1;\nconst DEFAULT_REVALIDATION_ENABLED = false;\nconst DEFAULT_REVALIDATE_TIME = 5 * 60 * 1000; // 5 minutes\nconst DEFAULT_RETRY_TIME = 5 * 60 * 1000; // 5 minutes\n\n// The main hook type that includes the async function along with its additional properties.\nexport type UseAsyncResult<\n U extends string,\n T extends (...args: any[]) => Promise<any>,\n> = UseAsyncResultBase<T> & Record<U, T>;\n\nconst getArgs = (args?: any[]): any[] =>\n args ? (Array.isArray(args) ? args : [args]) : [];\n\nconst getKeyWithArgs = (key: string, args: any[]) =>\n getArgs(args).length > 0 ? `${key}/${JSON.stringify(args)}` : key;\n\n/**\n * A custom React hook that manages asynchronous operations, providing easy-to-use states and controls over fetching, caching, and retry mechanisms.\n * This hook abstracts away the complexity of handling loading, error, and success states for any asynchronous function.\n *\n * @template U - A string type that extends the keys of the async function, used as a key to store and retrieve state.\n * @template T - A function type that must return a Promise, representing the asynchronous operation to be managed.\n *\n * @param {U} key - A unique identifier for the async operation, used to handle state internally and avoid conflicts.\n * @param {T} asyncFunction - The asynchronous function that will be managed by this hook. This function should return a Promise.\n * @param {UseAsyncOptions<T>} [options] - Optional configuration options to customize the behavior of the hook.\n * @returns {UseAsyncResult<U, T>} The states and controls related to the managed async function. Includes states like isLoading, isSuccess, and provides control methods like revalidate and setData.\n *\n * @typedef {Object} UseAsyncOptions\n * @property {number} [retryTime=300000] - Time in milliseconds for retrying the data after an error occurs.\n * @property {number} [retryLimit=1] - The number of times the hook should retry the asynchronous function on failure before giving up.\n * @property {boolean} [revalidation=false] - Enable revalidation.\n * @property {number} [revalidateTime=300000] - Time in milliseconds after which the cached data is considered stale and the async function is re-invoked, if caching is enabled.\n * @property {boolean} [cache=false] - Whether to cache the result of the async function. When enabled, revalidation is controlled by `revalidateTime`.\n * @property {boolean} [store=false] - Store the result of the function in session storage.\n * @property {boolean} [autoFetch=false] - Whether the hook should automatically invoke the asynchronous function on mount.\n * @property {number} [revalidateTime=300000] - Time in milliseconds after which the cached data is considered stale and the async function is re-invoked, if caching is enabled.\n * @property {string[]} [updateQueries=[]] - Update other queries when the data is updated.\n * @property {string[]} [invalidateQueries=[]] - Invalidate other queries when the data is updated.\n * @property {(data: Awaited<ReturnType<T>>) => void} [onSuccess] - Callback function that is called when the asynchronous function resolves successfully.\n * @property {(error: string) => void} [onError] - Callback function that is called when the asynchronous function rejects or encounters an error.\n * @property {Parameters<T>} [args=[]] - Arguments to pass to the asynchronous function.\n *\n *\n * @example\n * // Example of using useAsync to manage fetching user data from an API.\n * const fetchUserData = async (userId) => {\n * const response = await fetch(`/api/users/${userId}`);\n * if (!response.ok) throw new Error('Failed to fetch');\n * return await response.json();\n * };\n *\n * const UserDetails = ({ userId }) => {\n * const {\n * isLoading,\n * data,\n * error,\n * revalidate,\n * } = useAsync('userDetails', fetchUserData, {\n * cache: true,\n * revalidateTime: 60000, // 1 minute\n * autoFetch: true,\n * onSuccess: (data) => console.log('User data fetched successfully:', data),\n * onError: (error) => console.error('Error fetching user data:', error),\n * });\n *\n * if (isLoading) return <div>Loading...</div>;\n * if (error) return <div>Error: {error}</div>;\n * return (\n * <div>\n * <h1>{data.name}</h1>\n * <button onClick={() => revalidate()}>Refresh</button>\n * </div>\n * );\n * };\n */\nexport const useAsync = <\n U extends string,\n T extends (...args: any[]) => Promise<any>,\n>(\n key: U,\n asyncFunction: T,\n options?: UseAsyncOptions<T>\n): UseAsyncResult<U, T> => {\n // Resolving optional parameters with default values\n const retryLimit = options?.retryLimit ?? DEFAULT_RETRY_LIMIT;\n const autoFetch = options?.autoFetch ?? DEFAULT_AUTO_FETCH;\n const retryTime = options?.retryTime ?? DEFAULT_RETRY_TIME;\n const cacheEnabled = options?.cache ?? DEFAULT_CACHE_ENABLED;\n const storeEnabled = options?.store ?? DEFAULT_STORE_ENABLED;\n const enabled = options?.enable ?? DEFAULT_ENABLED;\n const revalidationEnabled =\n options?.revalidation ?? DEFAULT_REVALIDATION_ENABLED;\n const revalidateTime = options?.revalidateTime ?? DEFAULT_REVALIDATE_TIME;\n const updateQueries = options?.updateQueries ?? [];\n const invalidateQueries = options?.invalidateQueries ?? [];\n const onSuccess = options?.onSuccess;\n const onError = options?.onError;\n const args = getArgs(options?.args ?? []);\n\n // Using a custom hook to manage state specific to asynchronous operations\n const { setQueryState, setQueriesState, makeQueryInError } =\n useAsyncStateStore(\n useShallow((state) => ({\n setQueryState: state.setQueryState,\n setQueriesState: state.setQueriesState,\n makeQueryInError: state.makeQueryInError,\n }))\n );\n\n // Storing the last arguments used to call the async function\n const storedArgsRef = useRef<any[]>(args);\n\n // Apply different key for different requests\n const keyWithArgs = getKeyWithArgs(key, storedArgsRef.current);\n\n // Retrieving the current state of async operations using the same custom hook\n const {\n isFetched,\n fetchedDateTime,\n isLoading,\n isEnabled,\n error,\n isSuccess,\n isInvalidated,\n data,\n retryCount: errorCount,\n } = useAsyncStateStore(useShallow((state) => state.getStates(keyWithArgs)));\n\n // The core fetching function, designed to be called directly or automatically based on configuration\n const fetch: T = useCallback<T>(\n (async (...args) => {\n const keyWithArgs = getKeyWithArgs(key, args);\n\n if (pendingPromises.has(keyWithArgs)) {\n // Return the existing pending promise\n return pendingPromises.get(keyWithArgs);\n }\n\n const promise = (async () => {\n setQueryState(keyWithArgs, { isLoading: true });\n let response = null;\n\n await asyncFunction(...args)\n .then((result) => {\n response = result;\n\n setQueryState(keyWithArgs, {\n data: result,\n retryCount: 0,\n isLoading: false,\n isFetched: true,\n isSuccess: true,\n isInvalidated: false,\n error: null,\n });\n\n onSuccess?.(result);\n\n // Invalidate other queries if necessary\n if (invalidateQueries.length > 0) {\n setQueriesState(invalidateQueries, {\n isInvalidated: true,\n });\n }\n\n // Update other queries if necessary\n if (updateQueries.length > 0) {\n setQueriesState(updateQueries, {\n data: result,\n });\n }\n\n // Store the result in session storage\n if (storeEnabled) {\n sessionStorage.setItem(keyWithArgs, JSON.stringify(result));\n }\n })\n .catch((error) => {\n makeQueryInError(keyWithArgs, error.message);\n onError?.(error.message);\n })\n .finally(() => {\n // Remove the pending promise from the cache\n pendingPromises.delete(keyWithArgs);\n });\n\n return response;\n })();\n\n // Store the pending promise in the cache\n pendingPromises.set(keyWithArgs, promise);\n\n return await promise;\n }) as T,\n [asyncFunction, keyWithArgs, storeEnabled, cacheEnabled, onSuccess, onError]\n );\n\n // Wrapped execution function to handle disabled state and check for success before re-fetching\n const execute: T = useCallback<T>(\n (async (...args) => {\n if (!isEnabled || !enabled) return;\n if (isLoading) return;\n if (!isInvalidated && isSuccess && cacheEnabled && data) return data;\n\n if (args) {\n storedArgsRef.current = getArgs(...args);\n }\n\n return await fetch(...args);\n }) as T,\n [\n isEnabled,\n enabled,\n isInvalidated,\n cacheEnabled,\n isSuccess,\n data,\n isLoading,\n fetch,\n ]\n );\n\n // Function to revalidate the data when necessary\n const revalidate: T = useCallback<T>(\n (async (...args) => {\n if (!isEnabled || !enabled) return;\n\n if (args) {\n storedArgsRef.current = getArgs(...args);\n }\n\n const result = await fetch(...storedArgsRef.current);\n\n return result;\n }) as T,\n [isEnabled, enabled, storedArgsRef, fetch]\n );\n\n const autoRevalidate = useCallback(async () => {\n if (!isEnabled || !enabled) return;\n if (isLoading) return;\n if (!(cacheEnabled || storeEnabled)) return;\n if (!isSuccess) return;\n if (!revalidationEnabled || revalidateTime <= 0) return;\n if (!fetchedDateTime) return;\n\n const now = new Date().getTime();\n const lastFetchedTime = new Date(fetchedDateTime).getTime();\n const shouldRevalidate = now - lastFetchedTime >= revalidateTime;\n if (shouldRevalidate) {\n return await fetch(...storedArgsRef.current);\n }\n }, [\n cacheEnabled,\n revalidationEnabled,\n revalidateTime,\n isSuccess,\n fetchedDateTime,\n isLoading,\n isEnabled,\n enabled,\n ]);\n\n useEffect(() => {\n if (enabled !== isEnabled) {\n setQueryState(keyWithArgs, {\n isEnabled,\n });\n }\n }, [enabled, isEnabled, keyWithArgs]);\n\n // Auto-fetch data on hook mount if autoFetch is true\n useEffect(() => {\n if (!autoFetch) return;\n if (!isEnabled || !enabled) return;\n if (isFetched && !isInvalidated) return;\n if (isLoading) return;\n\n fetch(...storedArgsRef.current);\n }, [\n autoFetch,\n isFetched,\n isInvalidated,\n isEnabled,\n enabled,\n isLoading,\n fetch,\n ]);\n\n // Handle retry based on conditions set in options\n useEffect(() => {\n const isRetryEnabled = errorCount > 0 && retryLimit > 0;\n const isRetryLimitReached = errorCount >= retryLimit;\n if (!isEnabled || !enabled) return;\n if (!(cacheEnabled || storeEnabled)) return;\n if (!isRetryEnabled || isRetryLimitReached) return;\n if (isSuccess) return;\n if (isLoading) return;\n\n const timeOut = setTimeout(() => {\n fetch(...storedArgsRef.current);\n }, retryTime);\n\n return () => clearTimeout(timeOut);\n }, [\n fetch,\n errorCount,\n retryLimit,\n retryTime,\n isSuccess,\n isEnabled,\n enabled,\n isLoading,\n cacheEnabled,\n storeEnabled,\n ]);\n\n // Handle periodic revalidation if caching is enabled\n useEffect(() => {\n const interval = setInterval(autoRevalidate, revalidateTime);\n\n return () => clearInterval(interval);\n }, [autoRevalidate, revalidateTime]);\n\n // Load data from session storage if storeEnabled is true\n useEffect(() => {\n if (!isEnabled || !enabled) return;\n if (!storeEnabled) return;\n if (isInvalidated) return;\n if (isFetched) return;\n if (data) return;\n\n const storedData = sessionStorage.getItem(keyWithArgs);\n\n if (storedData && JSON.stringify(storedData) !== JSON.stringify(data)) {\n setQueryState(keyWithArgs, {\n data: JSON.parse(storedData),\n });\n }\n }, [\n storeEnabled,\n keyWithArgs,\n isFetched,\n isInvalidated,\n isEnabled,\n enabled,\n data,\n ]);\n\n // Memoization of the setData function to prevent unnecessary re-renders\n const setDataMemo = useCallback(\n (data: Awaited<ReturnType<T> | null>) => {\n setQueryState(keyWithArgs, {\n data,\n });\n },\n [keyWithArgs]\n );\n\n const memoResult = useMemo(\n () => ({\n isFetched,\n isLoading,\n isInvalidated,\n error,\n isSuccess,\n data,\n retryCount: errorCount,\n isDisabled: !isEnabled,\n isEnabled,\n [key]: execute,\n revalidate,\n setData: setDataMemo,\n }),\n [\n isFetched,\n isLoading,\n isInvalidated,\n error,\n isSuccess,\n data,\n errorCount,\n isEnabled,\n key,\n execute,\n revalidate,\n setDataMemo,\n ]\n );\n\n // Return the hook's result, including all state and control functions\n return memoResult as UseAsyncResultBase<T> & Record<U, T>;\n};\n"],"names":["useAsyncStateStore","useShallow","useRef","useCallback","args","keyWithArgs","error","useEffect","data","useMemo"],"mappings":";;;;;;AAUA,MAAM,sCAAsB,IAAI;AAkChC,MAAM,wBAAwB;AAC9B,MAAM,wBAAwB;AAC9B,MAAM,kBAAkB;AACxB,MAAM,qBAAqB;AAC3B,MAAM,sBAAsB;AAC5B,MAAM,+BAA+B;AACrC,MAAM,0BAA0B,IAAI,KAAK;AACzC,MAAM,qBAAqB,IAAI,KAAK;AAQpC,MAAM,UAAU,CAAC,SACf,OAAQ,MAAM,QAAQ,IAAI,IAAI,OAAO,CAAC,IAAI,IAAK,CAAC;AAElD,MAAM,iBAAiB,CAAC,KAAa,SACnC,QAAQ,IAAI,EAAE,SAAS,IAAI,GAAG,GAAG,IAAI,KAAK,UAAU,IAAI,CAAC,KAAK;AA8DzD,MAAM,WAAW,CAItB,KACA,eACA,YACyB;AAEnB,QAAA,aAAa,SAAS,cAAc;AACpC,QAAA,YAAY,SAAS,aAAa;AAClC,QAAA,YAAY,SAAS,aAAa;AAClC,QAAA,eAAe,SAAS,SAAS;AACjC,QAAA,eAAe,SAAS,SAAS;AACjC,QAAA,UAAU,SAAS,UAAU;AAC7B,QAAA,sBACJ,SAAS,gBAAgB;AACrB,QAAA,iBAAiB,SAAS,kBAAkB;AAC5C,QAAA,gBAAgB,SAAS,iBAAiB,CAAC;AAC3C,QAAA,oBAAoB,SAAS,qBAAqB,CAAC;AACzD,QAAM,YAAY,SAAS;AAC3B,QAAM,UAAU,SAAS;AACzB,QAAM,OAAO,QAAQ,SAAS,QAAQ,CAAA,CAAE;AAGxC,QAAM,EAAE,eAAe,iBAAiB,iBACtC,IAAAA,kCAAA;AAAA,IACEC,QAAA,WAAW,CAAC,WAAW;AAAA,MACrB,eAAe,MAAM;AAAA,MACrB,iBAAiB,MAAM;AAAA,MACvB,kBAAkB,MAAM;AA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AAA,EAAA,GAClC,CAAC,gBAAgB,cAAc,CAAC;AAGnCA,aAAAA,UAAU,MAAM;AACV,QAAA,CAAC,aAAa,CAAC,QAAS;AAC5B,QAAI,CAAC,aAAc;AACnB,QAAI,cAAe;AACnB,QAAI,UAAW;AACf,QAAI,KAAM;AAEJ,UAAA,aAAa,eAAe,QAAQ,WAAW;AAEjD,QAAA,cAAc,KAAK,UAAU,UAAU,MAAM,KAAK,UAAU,IAAI,GAAG;AACrE,oBAAc,aAAa;AAAA,QACzB,MAAM,KAAK,MAAM,UAAU;AAAA,MAAA,CAC5B;AAAA,IAAA;AAAA,EACH,GACC;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACD;AAGD,QAAM,cAAcJ,WAAA;AAAA,IAClB,CAACK,UAAwC;AACvC,oBAAc,aAAa;AAAA,QACzB,MAAAA;AAAAA,MAAA,CACD;AAAA,IACH;AAAA,IACA,CAAC,WAAW;AAAA,EACd;AAEA,QAAM,aAAaC,WAAA;AAAA,IACjB,OAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,YAAY;AAAA,MACZ,YAAY,CAAC;AAAA,MACb;AAAA,MACA,CAAC,GAAG,GAAG;AAAA,MACP;AAAA,MACA,SAAS;AAAA,IAAA;AAAA,IAEX;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA;AAAA,EAEJ;AAGO,SAAA;AACT;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useAsync.mjs","sources":["../../../src/hooks/useAsync/useAsync.ts"],"sourcesContent":["'use client';\n\n// This is an ESLint directive to disable specific rules.\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { useCallback, useEffect, useMemo, useRef } from 'react';\nimport { useShallow } from 'zustand/react/shallow';\nimport { useAsyncStateStore } from './useAsyncStateStore';\n\n// Pending promises cache to prevent parallel requests when multiple components use the hook\nconst pendingPromises = new Map();\n\n// Defines the base structure for the result of the custom hook.\ntype UseAsyncResultBase<T extends (...args: any[]) => Promise<any>> = {\n isFetched: boolean;\n isLoading: boolean;\n isInvalidated: boolean;\n isSuccess: boolean;\n isDisabled: boolean;\n error: string | null;\n data: Awaited<ReturnType<T>> | null;\n retryCount: number;\n revalidate: T;\n setData: (data: Awaited<ReturnType<T> | null>) => void;\n};\n\n// Options type for the hook, allowing customization of behavior.\nexport type UseAsyncOptions<T extends (...args: any[]) => Promise<any>> = {\n retryLimit?: number; // The number of times the hook should retry the function on failure before giving up\n retryTime?: number; // Time in milliseconds for retrying the data\n cache?: boolean; // Cache the result of the function using zustand\n store?: boolean; // Store the result of the function in session storage\n enable?: boolean; // Enable the hook\n autoFetch?: boolean; // Automatically fetch the data when the hook is mounted\n revalidation?: boolean; // Enable revalidation\n revalidateTime?: number; // Time in milliseconds for revalidating the data\n invalidateQueries?: string[]; // Invalidate other queries when the data is updated\n updateQueries?: string[]; // Update other queries when the data is updated\n onSuccess?: (data: Awaited<ReturnType<T>>) => void; // Callback function that is called when the asynchronous function resolves successfully\n onError?: (error: string) => void; // Callback function that is called when the asynchronous function rejects or encounters an error\n args?: Parameters<T>; // Arguments to pass to the asynchronous function\n};\n\n// Default values for the hook's options\nconst DEFAULT_CACHE_ENABLED = false;\nconst DEFAULT_STORE_ENABLED = false;\nconst DEFAULT_ENABLED = true;\nconst DEFAULT_AUTO_FETCH = false;\nconst DEFAULT_RETRY_LIMIT = 1;\nconst DEFAULT_REVALIDATION_ENABLED = false;\nconst DEFAULT_REVALIDATE_TIME = 5 * 60 * 1000; // 5 minutes\nconst DEFAULT_RETRY_TIME = 5 * 60 * 1000; // 5 minutes\n\n// The main hook type that includes the async function along with its additional properties.\nexport type UseAsyncResult<\n U extends string,\n T extends (...args: any[]) => Promise<any>,\n> = UseAsyncResultBase<T> & Record<U, T>;\n\nconst getArgs = (args?: any[]): any[] =>\n args ? (Array.isArray(args) ? args : [args]) : [];\n\nconst getKeyWithArgs = (key: string, args: any[]) =>\n getArgs(args).length > 0 ? `${key}/${JSON.stringify(args)}` : key;\n\n/**\n * A custom React hook that manages asynchronous operations, providing easy-to-use states and controls over fetching, caching, and retry mechanisms.\n * This hook abstracts away the complexity of handling loading, error, and success states for any asynchronous function.\n *\n * @template U - A string type that extends the keys of the async function, used as a key to store and retrieve state.\n * @template T - A function type that must return a Promise, representing the asynchronous operation to be managed.\n *\n * @param {U} key - A unique identifier for the async operation, used to handle state internally and avoid conflicts.\n * @param {T} asyncFunction - The asynchronous function that will be managed by this hook. This function should return a Promise.\n * @param {UseAsyncOptions<T>} [options] - Optional configuration options to customize the behavior of the hook.\n * @returns {UseAsyncResult<U, T>} The states and controls related to the managed async function. Includes states like isLoading, isSuccess, and provides control methods like revalidate and setData.\n *\n * @typedef {Object} UseAsyncOptions\n * @property {number} [retryTime=300000] - Time in milliseconds for retrying the data after an error occurs.\n * @property {number} [retryLimit=1] - The number of times the hook should retry the asynchronous function on failure before giving up.\n * @property {boolean} [revalidation=false] - Enable revalidation.\n * @property {number} [revalidateTime=300000] - Time in milliseconds after which the cached data is considered stale and the async function is re-invoked, if caching is enabled.\n * @property {boolean} [cache=false] - Whether to cache the result of the async function. When enabled, revalidation is controlled by `revalidateTime`.\n * @property {boolean} [store=false] - Store the result of the function in session storage.\n * @property {boolean} [autoFetch=false] - Whether the hook should automatically invoke the asynchronous function on mount.\n * @property {number} [revalidateTime=300000] - Time in milliseconds after which the cached data is considered stale and the async function is re-invoked, if caching is enabled.\n * @property {string[]} [updateQueries=[]] - Update other queries when the data is updated.\n * @property {string[]} [invalidateQueries=[]] - Invalidate other queries when the data is updated.\n * @property {(data: Awaited<ReturnType<T>>) => void} [onSuccess] - Callback function that is called when the asynchronous function resolves successfully.\n * @property {(error: string) => void} [onError] - Callback function that is called when the asynchronous function rejects or encounters an error.\n * @property {Parameters<T>} [args=[]] - Arguments to pass to the asynchronous function.\n *\n *\n * @example\n * // Example of using useAsync to manage fetching user data from an API.\n * const fetchUserData = async (userId) => {\n * const response = await fetch(`/api/users/${userId}`);\n * if (!response.ok) throw new Error('Failed to fetch');\n * return await response.json();\n * };\n *\n * const UserDetails = ({ userId }) => {\n * const {\n * isLoading,\n * data,\n * error,\n * revalidate,\n * } = useAsync('userDetails', fetchUserData, {\n * cache: true,\n * revalidateTime: 60000, // 1 minute\n * autoFetch: true,\n * onSuccess: (data) => console.log('User data fetched successfully:', data),\n * onError: (error) => console.error('Error fetching user data:', error),\n * });\n *\n * if (isLoading) return <div>Loading...</div>;\n * if (error) return <div>Error: {error}</div>;\n * return (\n * <div>\n * <h1>{data.name}</h1>\n * <button onClick={() => revalidate()}>Refresh</button>\n * </div>\n * );\n * };\n */\nexport const useAsync = <\n U extends string,\n T extends (...args: any[]) => Promise<any>,\n>(\n key: U,\n asyncFunction: T,\n options?: UseAsyncOptions<T>\n): UseAsyncResult<U, T> => {\n // Resolving optional parameters with default values\n const retryLimit = options?.retryLimit ?? DEFAULT_RETRY_LIMIT;\n const autoFetch = options?.autoFetch ?? DEFAULT_AUTO_FETCH;\n const retryTime = options?.retryTime ?? DEFAULT_RETRY_TIME;\n const cacheEnabled = options?.cache ?? DEFAULT_CACHE_ENABLED;\n const storeEnabled = options?.store ?? DEFAULT_STORE_ENABLED;\n const enabled = options?.enable ?? DEFAULT_ENABLED;\n const revalidationEnabled =\n options?.revalidation ?? DEFAULT_REVALIDATION_ENABLED;\n const revalidateTime = options?.revalidateTime ?? DEFAULT_REVALIDATE_TIME;\n const updateQueries = options?.updateQueries ?? [];\n const invalidateQueries = options?.invalidateQueries ?? [];\n const onSuccess = options?.onSuccess;\n const onError = options?.onError;\n const args = getArgs(options?.args ?? []);\n\n // Using a custom hook to manage state specific to asynchronous operations\n const { setQueryState, setQueriesState, makeQueryInError } =\n useAsyncStateStore(\n useShallow((state) => ({\n setQueryState: state.setQueryState,\n setQueriesState: state.setQueriesState,\n makeQueryInError: state.makeQueryInError,\n }))\n );\n\n // Storing the last arguments used to call the async function\n const storedArgsRef = useRef<any[]>(args);\n\n // Apply different key for different requests\n const keyWithArgs = getKeyWithArgs(key, storedArgsRef.current);\n\n // Retrieving the current state of async operations using the same custom hook\n const {\n isFetched,\n fetchedDateTime,\n isLoading,\n isEnabled,\n error,\n isSuccess,\n isInvalidated,\n data,\n retryCount: errorCount,\n } = useAsyncStateStore(useShallow((state) => state.getStates(keyWithArgs)));\n\n // The core fetching function, designed to be called directly or automatically based on configuration\n const fetch: T = useCallback<T>(\n (async (...args) => {\n const keyWithArgs = getKeyWithArgs(key, args);\n\n if (pendingPromises.has(keyWithArgs)) {\n // Return the existing pending promise\n return pendingPromises.get(keyWithArgs);\n }\n\n const promise = (async () => {\n setQueryState(keyWithArgs, { isLoading: true });\n let response = null;\n\n await asyncFunction(...args)\n .then((result) => {\n response = result;\n\n setQueryState(keyWithArgs, {\n data: result,\n retryCount: 0,\n isLoading: false,\n isFetched: true,\n isSuccess: true,\n isInvalidated: false,\n error: null,\n });\n\n onSuccess?.(result);\n\n // Invalidate other queries if necessary\n if (invalidateQueries.length > 0) {\n setQueriesState(invalidateQueries, {\n isInvalidated: true,\n });\n }\n\n // Update other queries if necessary\n if (updateQueries.length > 0) {\n setQueriesState(updateQueries, {\n data: result,\n });\n }\n\n // Store the result in session storage\n if (storeEnabled) {\n sessionStorage.setItem(keyWithArgs, JSON.stringify(result));\n }\n })\n .catch((error) => {\n makeQueryInError(keyWithArgs, error.message);\n onError?.(error.message);\n })\n .finally(() => {\n // Remove the pending promise from the cache\n pendingPromises.delete(keyWithArgs);\n });\n\n return response;\n })();\n\n // Store the pending promise in the cache\n pendingPromises.set(keyWithArgs, promise);\n\n return await promise;\n }) as T,\n [asyncFunction, keyWithArgs, storeEnabled, cacheEnabled, onSuccess, onError]\n );\n\n // Wrapped execution function to handle disabled state and check for success before re-fetching\n const execute: T = useCallback<T>(\n (async (...args) => {\n if (!isEnabled || !enabled) return;\n if (isLoading) return;\n if (!isInvalidated && isSuccess && cacheEnabled && data) return data;\n\n if (args) {\n storedArgsRef.current = getArgs(...args);\n }\n\n return await fetch(...args);\n }) as T,\n [\n isEnabled,\n enabled,\n isInvalidated,\n cacheEnabled,\n isSuccess,\n data,\n isLoading,\n fetch,\n ]\n );\n\n // Function to revalidate the data when necessary\n const revalidate: T = useCallback<T>(\n (async (...args) => {\n if (!isEnabled || !enabled) return;\n\n if (args) {\n storedArgsRef.current = getArgs(...args);\n }\n\n const result = await fetch(...storedArgsRef.current);\n\n return result;\n }) as T,\n [isEnabled, enabled, storedArgsRef, fetch]\n );\n\n const autoRevalidate = useCallback(async () => {\n if (!isEnabled || !enabled) return;\n if (isLoading) return;\n if (!(cacheEnabled || storeEnabled)) return;\n if (!isSuccess) return;\n if (!revalidationEnabled || revalidateTime <= 0) return;\n if (!fetchedDateTime) return;\n\n const now = new Date().getTime();\n const lastFetchedTime = new Date(fetchedDateTime).getTime();\n const shouldRevalidate = now - lastFetchedTime >= revalidateTime;\n if (shouldRevalidate) {\n return await fetch(...storedArgsRef.current);\n }\n }, [\n cacheEnabled,\n revalidationEnabled,\n revalidateTime,\n isSuccess,\n fetchedDateTime,\n isLoading,\n isEnabled,\n enabled,\n ]);\n\n useEffect(() => {\n if (enabled !== isEnabled) {\n setQueryState(keyWithArgs, {\n isEnabled,\n });\n }\n }, [enabled, isEnabled, keyWithArgs]);\n\n // Auto-fetch data on hook mount if autoFetch is true\n useEffect(() => {\n if (!autoFetch) return;\n if (!isEnabled || !enabled) return;\n if (isFetched && !isInvalidated) return;\n if (isLoading) return;\n\n fetch(...storedArgsRef.current);\n }, [\n autoFetch,\n isFetched,\n isInvalidated,\n isEnabled,\n enabled,\n isLoading,\n fetch,\n ]);\n\n // Handle retry based on conditions set in options\n useEffect(() => {\n const isRetryEnabled = errorCount > 0 && retryLimit > 0;\n const isRetryLimitReached = errorCount >= retryLimit;\n if (!isEnabled || !enabled) return;\n if (!(cacheEnabled || storeEnabled)) return;\n if (!isRetryEnabled || isRetryLimitReached) return;\n if (isSuccess) return;\n if (isLoading) return;\n\n const timeOut = setTimeout(() => {\n fetch(...storedArgsRef.current);\n }, retryTime);\n\n return () => clearTimeout(timeOut);\n }, [\n fetch,\n errorCount,\n retryLimit,\n retryTime,\n isSuccess,\n isEnabled,\n enabled,\n isLoading,\n cacheEnabled,\n storeEnabled,\n ]);\n\n // Handle periodic revalidation if caching is enabled\n useEffect(() => {\n const interval = setInterval(autoRevalidate, revalidateTime);\n\n return () => clearInterval(interval);\n }, [autoRevalidate, revalidateTime]);\n\n // Load data from session storage if storeEnabled is true\n useEffect(() => {\n if (!isEnabled || !enabled) return;\n if (!storeEnabled) return;\n if (isInvalidated) return;\n if (isFetched) return;\n if (data) return;\n\n const storedData = sessionStorage.getItem(keyWithArgs);\n\n if (storedData && JSON.stringify(storedData) !== JSON.stringify(data)) {\n setQueryState(keyWithArgs, {\n data: JSON.parse(storedData),\n });\n }\n }, [\n storeEnabled,\n keyWithArgs,\n isFetched,\n isInvalidated,\n isEnabled,\n enabled,\n data,\n ]);\n\n // Memoization of the setData function to prevent unnecessary re-renders\n const setDataMemo = useCallback(\n (data: Awaited<ReturnType<T> | null>) => {\n setQueryState(keyWithArgs, {\n data,\n });\n },\n [keyWithArgs]\n );\n\n const memoResult = useMemo(\n () => ({\n isFetched,\n isLoading,\n isInvalidated,\n error,\n isSuccess,\n data,\n retryCount: errorCount,\n isDisabled: !isEnabled,\n isEnabled,\n [key]: execute,\n revalidate,\n setData: setDataMemo,\n }),\n [\n isFetched,\n isLoading,\n isInvalidated,\n error,\n isSuccess,\n data,\n errorCount,\n isEnabled,\n key,\n execute,\n revalidate,\n setDataMemo,\n ]\n );\n\n // Return the hook's result, including all state and control functions\n return memoResult as UseAsyncResultBase<T> & Record<U, T>;\n};\n"],"names":["args","keyWithArgs","error","data"],"mappings":";;;;AAUA,M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c,aAAa;AAAA,QACzB,MAAM,KAAK,MAAM,UAAU;AAAA,MAAA,CAC5B;AAAA,IACH;AAAA,EAAA,GACC;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACD;AAGD,QAAM,cAAc;AAAA,IAClB,CAACG,UAAwC;AACvC,oBAAc,aAAa;AAAA,QACzB,MAAAA;AAAAA,MAAA,CACD;AAAA,IACH;AAAA,IACA,CAAC,WAAW;AAAA,EAAA;AAGd,QAAM,aAAa;AAAA,IACjB,OAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,YAAY;AAAA,MACZ,YAAY,CAAC;AAAA,MACb;AAAA,MACA,CAAC,GAAG,GAAG;AAAA,MACP;AAAA,MACA,SAAS;AAAA,IAAA;AAAA,IAEX;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EAAA;AAIK,SAAA;AACT;"}
1
+ {"version":3,"file":"useAsync.mjs","sources":["../../../src/hooks/useAsync/useAsync.ts"],"sourcesContent":["'use client';\n\n// This is an ESLint directive to disable specific rules.\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { useCallback, useEffect, useMemo, useRef } from 'react';\nimport { useShallow } from 'zustand/react/shallow';\nimport { useAsyncStateStore } from './useAsyncStateStore';\n\n// Pending promises cache to prevent parallel requests when multiple components use the hook\nconst pendingPromises = new Map();\n\n// Defines the base structure for the result of the custom hook.\ntype UseAsyncResultBase<T extends (...args: any[]) => Promise<any>> = {\n isFetched: boolean;\n isLoading: boolean;\n isInvalidated: boolean;\n isSuccess: boolean;\n isDisabled: boolean;\n error: string | null;\n data: Awaited<ReturnType<T>> | null;\n retryCount: number;\n revalidate: T;\n setData: (data: Awaited<ReturnType<T> | null>) => void;\n};\n\n// Options type for the hook, allowing customization of behavior.\nexport type UseAsyncOptions<T extends (...args: any[]) => Promise<any>> = {\n retryLimit?: number; // The number of times the hook should retry the function on failure before giving up\n retryTime?: number; // Time in milliseconds for retrying the data\n cache?: boolean; // Cache the result of the function using zustand\n store?: boolean; // Store the result of the function in session storage\n enable?: boolean; // Enable the hook\n autoFetch?: boolean; // Automatically fetch the data when the hook is mounted\n revalidation?: boolean; // Enable revalidation\n revalidateTime?: number; // Time in milliseconds for revalidating the data\n invalidateQueries?: string[]; // Invalidate other queries when the data is updated\n updateQueries?: string[]; // Update other queries when the data is updated\n onSuccess?: (data: Awaited<ReturnType<T>>) => void; // Callback function that is called when the asynchronous function resolves successfully\n onError?: (error: string) => void; // Callback function that is called when the asynchronous function rejects or encounters an error\n args?: Parameters<T>; // Arguments to pass to the asynchronous function\n};\n\n// Default values for the hook's options\nconst DEFAULT_CACHE_ENABLED = false;\nconst DEFAULT_STORE_ENABLED = false;\nconst DEFAULT_ENABLED = true;\nconst DEFAULT_AUTO_FETCH = false;\nconst DEFAULT_RETRY_LIMIT = 1;\nconst DEFAULT_REVALIDATION_ENABLED = false;\nconst DEFAULT_REVALIDATE_TIME = 5 * 60 * 1000; // 5 minutes\nconst DEFAULT_RETRY_TIME = 5 * 60 * 1000; // 5 minutes\n\n// The main hook type that includes the async function along with its additional properties.\nexport type UseAsyncResult<\n U extends string,\n T extends (...args: any[]) => Promise<any>,\n> = UseAsyncResultBase<T> & Record<U, T>;\n\nconst getArgs = (args?: any[]): any[] =>\n args ? (Array.isArray(args) ? args : [args]) : [];\n\nconst getKeyWithArgs = (key: string, args: any[]) =>\n getArgs(args).length > 0 ? `${key}/${JSON.stringify(args)}` : key;\n\n/**\n * A custom React hook that manages asynchronous operations, providing easy-to-use states and controls over fetching, caching, and retry mechanisms.\n * This hook abstracts away the complexity of handling loading, error, and success states for any asynchronous function.\n *\n * @template U - A string type that extends the keys of the async function, used as a key to store and retrieve state.\n * @template T - A function type that must return a Promise, representing the asynchronous operation to be managed.\n *\n * @param {U} key - A unique identifier for the async operation, used to handle state internally and avoid conflicts.\n * @param {T} asyncFunction - The asynchronous function that will be managed by this hook. This function should return a Promise.\n * @param {UseAsyncOptions<T>} [options] - Optional configuration options to customize the behavior of the hook.\n * @returns {UseAsyncResult<U, T>} The states and controls related to the managed async function. Includes states like isLoading, isSuccess, and provides control methods like revalidate and setData.\n *\n * @typedef {Object} UseAsyncOptions\n * @property {number} [retryTime=300000] - Time in milliseconds for retrying the data after an error occurs.\n * @property {number} [retryLimit=1] - The number of times the hook should retry the asynchronous function on failure before giving up.\n * @property {boolean} [revalidation=false] - Enable revalidation.\n * @property {number} [revalidateTime=300000] - Time in milliseconds after which the cached data is considered stale and the async function is re-invoked, if caching is enabled.\n * @property {boolean} [cache=false] - Whether to cache the result of the async function. When enabled, revalidation is controlled by `revalidateTime`.\n * @property {boolean} [store=false] - Store the result of the function in session storage.\n * @property {boolean} [autoFetch=false] - Whether the hook should automatically invoke the asynchronous function on mount.\n * @property {number} [revalidateTime=300000] - Time in milliseconds after which the cached data is considered stale and the async function is re-invoked, if caching is enabled.\n * @property {string[]} [updateQueries=[]] - Update other queries when the data is updated.\n * @property {string[]} [invalidateQueries=[]] - Invalidate other queries when the data is updated.\n * @property {(data: Awaited<ReturnType<T>>) => void} [onSuccess] - Callback function that is called when the asynchronous function resolves successfully.\n * @property {(error: string) => void} [onError] - Callback function that is called when the asynchronous function rejects or encounters an error.\n * @property {Parameters<T>} [args=[]] - Arguments to pass to the asynchronous function.\n *\n *\n * @example\n * // Example of using useAsync to manage fetching user data from an API.\n * const fetchUserData = async (userId) => {\n * const response = await fetch(`/api/users/${userId}`);\n * if (!response.ok) throw new Error('Failed to fetch');\n * return await response.json();\n * };\n *\n * const UserDetails = ({ userId }) => {\n * const {\n * isLoading,\n * data,\n * error,\n * revalidate,\n * } = useAsync('userDetails', fetchUserData, {\n * cache: true,\n * revalidateTime: 60000, // 1 minute\n * autoFetch: true,\n * onSuccess: (data) => console.log('User data fetched successfully:', data),\n * onError: (error) => console.error('Error fetching user data:', error),\n * });\n *\n * if (isLoading) return <div>Loading...</div>;\n * if (error) return <div>Error: {error}</div>;\n * return (\n * <div>\n * <h1>{data.name}</h1>\n * <button onClick={() => revalidate()}>Refresh</button>\n * </div>\n * );\n * };\n */\nexport const useAsync = <\n U extends string,\n T extends (...args: any[]) => Promise<any>,\n>(\n key: U,\n asyncFunction: T,\n options?: UseAsyncOptions<T>\n): UseAsyncResult<U, T> => {\n // Resolving optional parameters with default values\n const retryLimit = options?.retryLimit ?? DEFAULT_RETRY_LIMIT;\n const autoFetch = options?.autoFetch ?? DEFAULT_AUTO_FETCH;\n const retryTime = options?.retryTime ?? DEFAULT_RETRY_TIME;\n const cacheEnabled = options?.cache ?? DEFAULT_CACHE_ENABLED;\n const storeEnabled = options?.store ?? DEFAULT_STORE_ENABLED;\n const enabled = options?.enable ?? DEFAULT_ENABLED;\n const revalidationEnabled =\n options?.revalidation ?? DEFAULT_REVALIDATION_ENABLED;\n const revalidateTime = options?.revalidateTime ?? DEFAULT_REVALIDATE_TIME;\n const updateQueries = options?.updateQueries ?? [];\n const invalidateQueries = options?.invalidateQueries ?? [];\n const onSuccess = options?.onSuccess;\n const onError = options?.onError;\n const args = getArgs(options?.args ?? []);\n\n // Using a custom hook to manage state specific to asynchronous operations\n const { setQueryState, setQueriesState, makeQueryInError } =\n useAsyncStateStore(\n useShallow((state) => ({\n setQueryState: state.setQueryState,\n setQueriesState: state.setQueriesState,\n makeQueryInError: state.makeQueryInError,\n }))\n );\n\n // Storing the last arguments used to call the async function\n const storedArgsRef = useRef<any[]>(args);\n\n // Apply different key for different requests\n const keyWithArgs = getKeyWithArgs(key, storedArgsRef.current);\n\n // Retrieving the current state of async operations using the same custom hook\n const {\n isFetched,\n fetchedDateTime,\n isLoading,\n isEnabled,\n error,\n isSuccess,\n isInvalidated,\n data,\n retryCount: errorCount,\n } = useAsyncStateStore(useShallow((state) => state.getStates(keyWithArgs)));\n\n // The core fetching function, designed to be called directly or automatically based on configuration\n const fetch: T = useCallback<T>(\n (async (...args) => {\n const keyWithArgs = getKeyWithArgs(key, args);\n\n if (pendingPromises.has(keyWithArgs)) {\n // Return the existing pending promise\n return pendingPromises.get(keyWithArgs);\n }\n\n const promise = (async () => {\n setQueryState(keyWithArgs, { isLoading: true });\n let response = null;\n\n await asyncFunction(...args)\n .then((result) => {\n response = result;\n\n setQueryState(keyWithArgs, {\n data: result,\n retryCount: 0,\n isLoading: false,\n isFetched: true,\n isSuccess: true,\n isInvalidated: false,\n error: null,\n });\n\n onSuccess?.(result);\n\n // Invalidate other queries if necessary\n if (invalidateQueries.length > 0) {\n setQueriesState(invalidateQueries, {\n isInvalidated: true,\n });\n }\n\n // Update other queries if necessary\n if (updateQueries.length > 0) {\n setQueriesState(updateQueries, {\n data: result,\n });\n }\n\n // Store the result in session storage\n if (storeEnabled) {\n sessionStorage.setItem(keyWithArgs, JSON.stringify(result));\n }\n })\n .catch((error) => {\n makeQueryInError(keyWithArgs, error.message);\n onError?.(error.message);\n })\n .finally(() => {\n // Remove the pending promise from the cache\n pendingPromises.delete(keyWithArgs);\n });\n\n return response;\n })();\n\n // Store the pending promise in the cache\n pendingPromises.set(keyWithArgs, promise);\n\n return await promise;\n }) as T,\n [asyncFunction, keyWithArgs, storeEnabled, cacheEnabled, onSuccess, onError]\n );\n\n // Wrapped execution function to handle disabled state and check for success before re-fetching\n const execute: T = useCallback<T>(\n (async (...args) => {\n if (!isEnabled || !enabled) return;\n if (isLoading) return;\n if (!isInvalidated && isSuccess && cacheEnabled && data) return data;\n\n if (args) {\n storedArgsRef.current = getArgs(...args);\n }\n\n return await fetch(...args);\n }) as T,\n [\n isEnabled,\n enabled,\n isInvalidated,\n cacheEnabled,\n isSuccess,\n data,\n isLoading,\n fetch,\n ]\n );\n\n // Function to revalidate the data when necessary\n const revalidate: T = useCallback<T>(\n (async (...args) => {\n if (!isEnabled || !enabled) return;\n\n if (args) {\n storedArgsRef.current = getArgs(...args);\n }\n\n const result = await fetch(...storedArgsRef.current);\n\n return result;\n }) as T,\n [isEnabled, enabled, storedArgsRef, fetch]\n );\n\n const autoRevalidate = useCallback(async () => {\n if (!isEnabled || !enabled) return;\n if (isLoading) return;\n if (!(cacheEnabled || storeEnabled)) return;\n if (!isSuccess) return;\n if (!revalidationEnabled || revalidateTime <= 0) return;\n if (!fetchedDateTime) return;\n\n const now = new Date().getTime();\n const lastFetchedTime = new Date(fetchedDateTime).getTime();\n const shouldRevalidate = now - lastFetchedTime >= revalidateTime;\n if (shouldRevalidate) {\n return await fetch(...storedArgsRef.current);\n }\n }, [\n cacheEnabled,\n revalidationEnabled,\n revalidateTime,\n isSuccess,\n fetchedDateTime,\n isLoading,\n isEnabled,\n enabled,\n ]);\n\n useEffect(() => {\n if (enabled !== isEnabled) {\n setQueryState(keyWithArgs, {\n isEnabled,\n });\n }\n }, [enabled, isEnabled, keyWithArgs]);\n\n // Auto-fetch data on hook mount if autoFetch is true\n useEffect(() => {\n if (!autoFetch) return;\n if (!isEnabled || !enabled) return;\n if (isFetched && !isInvalidated) return;\n if (isLoading) return;\n\n fetch(...storedArgsRef.current);\n }, [\n autoFetch,\n isFetched,\n isInvalidated,\n isEnabled,\n enabled,\n isLoading,\n fetch,\n ]);\n\n // Handle retry based on conditions set in options\n useEffect(() => {\n const isRetryEnabled = errorCount > 0 && retryLimit > 0;\n const isRetryLimitReached = errorCount >= retryLimit;\n if (!isEnabled || !enabled) return;\n if (!(cacheEnabled || storeEnabled)) return;\n if (!isRetryEnabled || isRetryLimitReached) return;\n if (isSuccess) return;\n if (isLoading) return;\n\n const timeOut = setTimeout(() => {\n fetch(...storedArgsRef.current);\n }, retryTime);\n\n return () => clearTimeout(timeOut);\n }, [\n fetch,\n errorCount,\n retryLimit,\n retryTime,\n isSuccess,\n isEnabled,\n enabled,\n isLoading,\n cacheEnabled,\n storeEnabled,\n ]);\n\n // Handle periodic revalidation if caching is enabled\n useEffect(() => {\n const interval = setInterval(autoRevalidate, revalidateTime);\n\n return () => clearInterval(interval);\n }, [autoRevalidate, revalidateTime]);\n\n // Load data from session storage if storeEnabled is true\n useEffect(() => {\n if (!isEnabled || !enabled) return;\n if (!storeEnabled) return;\n if (isInvalidated) return;\n if (isFetched) return;\n if (data) return;\n\n const storedData = sessionStorage.getItem(keyWithArgs);\n\n if (storedData && JSON.stringify(storedData) !== JSON.stringify(data)) {\n setQueryState(keyWithArgs, {\n data: JSON.parse(storedData),\n });\n }\n }, [\n storeEnabled,\n keyWithArgs,\n isFetched,\n isInvalidated,\n isEnabled,\n enabled,\n data,\n ]);\n\n // Memoization of the setData function to prevent unnecessary re-renders\n const setDataMemo = useCallback(\n (data: Awaited<ReturnType<T> | null>) => {\n setQueryState(keyWithArgs, {\n data,\n });\n },\n [keyWithArgs]\n );\n\n const memoResult = useMemo(\n () => ({\n isFetched,\n isLoading,\n isInvalidated,\n error,\n isSuccess,\n data,\n retryCount: errorCount,\n isDisabled: !isEnabled,\n isEnabled,\n [key]: execute,\n revalidate,\n setData: setDataMemo,\n }),\n [\n isFetched,\n isLoading,\n isInvalidated,\n error,\n isSuccess,\n data,\n errorCount,\n isEnabled,\n key,\n execute,\n revalidate,\n setDataMemo,\n ]\n );\n\n // Return the hook's result, including all state and control functions\n return memoResult as UseAsyncResultBase<T> & Record<U, T>;\n};\n"],"names":["args","keyWithArgs","error","data"],"mappings":";;;;AAUA,MAAM,sCAAsB,IAAI;AAkChC,MAAM,wBAAwB;AAC9B,MAAM,wBAAwB;AAC9B,MAAM,kBAAkB;AACxB,MAAM,qBAAqB;AAC3B,MAAM,sBAAsB;AAC5B,MAAM,+BAA+B;AACrC,MAAM,0BAA0B,IAAI,KAAK;AACzC,MAAM,qBAAqB,IAAI,KAAK;AAQpC,MAAM,UAAU,CAAC,SACf,OAAQ,MAAM,QAAQ,IAAI,IAAI,OAAO,CAAC,IAAI,IAAK,CAAC;AAElD,MAAM,iBAAiB,CAAC,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IACA,CAAC,WAAW;AAAA,EACd;AAEA,QAAM,aAAa;AAAA,IACjB,OAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,YAAY;AAAA,MACZ,YAAY,CAAC;AAAA,MACb;AAAA,MACA,CAAC,GAAG,GAAG;AAAA,MACP;AAAA,MACA,SAAS;AAAA,IAAA;AAAA,IAEX;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA;AAAA,EAEJ;AAGO,SAAA;AACT;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useAsyncStateStore.cjs","sources":["../../../src/hooks/useAsync/useAsyncStateStore.ts"],"sourcesContent":["import { create } from 'zustand';\n\ntype States<T> = {\n isLoading: boolean;\n isFetched: boolean;\n isInvalidated: boolean;\n fetchedDateTime: null | Date;\n error: string | null;\n isSuccess: boolean;\n data: T | null;\n retryCount: number;\n isEnabled: boolean;\n};\n\ntype StateSlice<T> = {\n [key: string]: States<T>;\n};\n\ntype Actions<T> = {\n getStates: (key: string) => States<T>;\n setQueryState: (key: string, value: Partial<States<T>>) => void;\n setQueriesState: (key: string[], value: Partial<States<T>>) => void;\n makeQueryInError: (key: string, error: string) => void;\n resetKeyState: (key: string[]) => void;\n resetState: (excludedKey: string[]) => void;\n};\n\ntype AsyncState<T> = {\n states: StateSlice<T>;\n} & Actions<T>;\n\nconst createDefaultStates = <T>(): States<T> => ({\n isFetched: false,\n fetchedDateTime: null,\n isLoading: false,\n isInvalidated: false,\n error: null,\n isSuccess: false,\n data: null,\n retryCount: 0,\n isEnabled: true,\n});\n\n/**\n * If the value is not an array. Transform it en array\n *\n * @param value value to transform en array if not array\n * @returns array\n */\nconst ensureArray = <T>(value?: T | T[]): T[] => {\n if (!value) {\n return [];\n } else if (Array.isArray(value)) {\n return value;\n }\n\n return [value];\n};\n\n/**\n * Return all keys that match\n *\n * @param {string[]} selectorsKeys - List of key to check - example: ['getProducts']\n * @param {string[]} keysWithArgs - List of keys that can includes args - example: [\"getProducts\", \"getProducts/{'ids':['id1','id2']}\", \"getUsers\", \"getUsers/{'ids':['id1','id2']}\" ]\n * @returns {string[]} - key that match the selectors - example: [\"getProducts\", \"getProducts/{'ids':['id1','id2']}\" ]\n */\nconst getMatchKeys = (\n selectorsKeys: string[],\n keysWithArgs: string[]\n): string[] => {\n const matchedKeys: string[] = keysWithArgs.filter((key) =>\n selectorsKeys.includes(key.split('/')[0])\n );\n\n return matchedKeys;\n};\n\nexport const useAsyncStateStore = create<AsyncState<unknown>>((set, get) => ({\n states: {},\n\n getStates: (key) => get().states[key] ?? createDefaultStates<unknown>(),\n\n setQueryState: (key, value) =>\n set((state) => ({\n states: {\n ...state.states,\n [key]: {\n ...(state.states[key] ?? createDefaultStates<unknown>()),\n ...value,\n },\n },\n })),\n\n makeQueryInError: (key, error) =>\n set((state) => ({\n states: {\n ...state.states,\n [key]: {\n ...(state.states[key] ?? createDefaultStates<unknown>()),\n error: error,\n isFetched: true,\n isSuccess: false,\n retryCount: (state.states[key]?.retryCount ?? 0) + 1,\n isLoading: false,\n isInvalidated: false,\n },\n },\n })),\n\n setQueriesState: (keys, value) => {\n const keyArray = ensureArray(keys);\n if (keyArray.length === 0) return;\n\n set((state) => ({\n states: {\n ...state.states,\n ...keyArray.reduce((acc, key) => {\n acc[key] = {\n ...(state.states[key] ?? createDefaultStates<unknown>()),\n ...value,\n };\n return acc;\n }, {} as StateSlice<unknown>),\n },\n }));\n },\n\n resetKeyState: (keys) => {\n const keyArray = ensureArray(keys);\n if (keyArray.length === 0) return;\n\n set((state) => {\n const allKeys = Object.keys(state.states);\n const matchedKeys = getMatchKeys(keyArray, allKeys);\n\n if (matchedKeys.length === 0) return {};\n\n const resetStates = matchedKeys.reduce((acc, key) => {\n acc[key] = createDefaultStates<unknown>();\n return acc;\n }, {} as StateSlice<unknown>);\n\n return {\n states: {\n ...state.states,\n ...resetStates,\n },\n };\n });\n },\n\n resetState: (excludedKeys) => {\n const excludeArray = ensureArray(excludedKeys);\n const allKeys = Object.keys(get().states);\n const matchedKeys = getMatchKeys(excludeArray, allKeys);\n\n set((state) => {\n const newStates = allKeys.reduce((acc, key) => {\n acc[key] = matchedKeys.includes(key)\n ? state.states[key]\n : createDefaultStates<unknown>();\n return acc;\n }, {} as StateSlice<unknown>);\n\n return {\n states: newStates,\n };\n });\n },\n}));\n"],"names":["create"],"mappings":";;;AA+BA,MAAM,sBAAsB,OAAqB;AAAA,EAC/C,WAAW;AAAA,EACX,iBAAiB;AAAA,EACjB,WAAW;AAAA,EACX,eAAe;AAAA,EACf,OAAO;AAAA,EACP,WAAW;AAAA,EACX,MAAM;AAAA,EACN,YAAY;AAAA,EACZ,WAAW;AACb;AAQA,MAAM,cAAc,CAAI,UAAyB;AAC/C,MAAI,CAAC,OAAO;AACV,WAAO;EACE,WAAA,MAAM,QAAQ,KAAK,GAAG;AACxB,WAAA;AAAA,EACT;AAEA,SAAO,CAAC,KAAK;AACf;AASA,MAAM,eAAe,CACnB,eACA,iBACa;AACb,QAAM,cAAwB,aAAa;AAAA,IAAO,CAAC,QACjD,cAAc,SAAS,IAAI,MAAM,GAAG,EAAE,CAAC,CAAC;AAAA,EAAA;AAGnC,SAAA;AACT;AAEO,MAAM,qBAAqBA,QAAA,OAA4B,CAAC,KAAK,SAAS;AAAA,EAC3E,QAAQ,CAAC;AAAA,EAET,WAAW,CAAC,QAAQ,IAAA,EAAM,OAAO,GAAG,KAAK,oBAA6B;AAAA,EAEtE,eAAe,CAAC,KAAK,UACnB,IAAI,CAAC,WAAW;AAAA,IACd,QAAQ;AAAA,MACN,GAAG,MAAM;AAAA,MACT,CAAC,GAAG,GAAG;AAAA,QACL,GAAI,MAAM,OAAO,GAAG,KAAK,oBAA6B;AAAA,QACtD,GAAG;AAAA,MACL;AAAA,IACF;AAAA,EAAA,EACA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EA,YAAY,CAAC,iBAAiB;AACtB,UAAA,eAAe,YAAY,YAAY;AAC7C,UAAM,UAAU,OAAO,KAAK,MAAM,MAAM;AAClC,UAAA,cAAc,aAAa,cAAc,OAAO;AAEtD,QAAI,CAAC,UAAU;AACb,YAAM,YAAY,QAAQ,OAAO,CAAC,KAAK,QAAQ;AACzC,YAAA,GAAG,IAAI,YAAY,SAAS,GAAG,IAC/B,MAAM,OAAO,GAAG,IAChB,oBAA6B;AAC1B,eAAA;AAAA,MACT,GAAG,CAAyB,CAAA;AAErB,aAAA;AAAA,QACL,QAAQ;AAAA,MAAA;AAAA,IACV,CACD;AAAA,EACH;AACF,EAAE;;"}
1
+ {"version":3,"file":"useAsyncStateStore.cjs","sources":["../../../src/hooks/useAsync/useAsyncStateStore.ts"],"sourcesContent":["import { create } from 'zustand';\n\ntype States<T> = {\n isLoading: boolean;\n isFetched: boolean;\n isInvalidated: boolean;\n fetchedDateTime: null | Date;\n error: string | null;\n isSuccess: boolean;\n data: T | null;\n retryCount: number;\n isEnabled: boolean;\n};\n\ntype StateSlice<T> = {\n [key: string]: States<T>;\n};\n\ntype Actions<T> = {\n getStates: (key: string) => States<T>;\n setQueryState: (key: string, value: Partial<States<T>>) => void;\n setQueriesState: (key: string[], value: Partial<States<T>>) => void;\n makeQueryInError: (key: string, error: string) => void;\n resetKeyState: (key: string[]) => void;\n resetState: (excludedKey: string[]) => void;\n};\n\ntype AsyncState<T> = {\n states: StateSlice<T>;\n} & Actions<T>;\n\nconst createDefaultStates = <T>(): States<T> => ({\n isFetched: false,\n fetchedDateTime: null,\n isLoading: false,\n isInvalidated: false,\n error: null,\n isSuccess: false,\n data: null,\n retryCount: 0,\n isEnabled: true,\n});\n\n/**\n * If the value is not an array. Transform it en array\n *\n * @param value value to transform en array if not array\n * @returns array\n */\nconst ensureArray = <T>(value?: T | T[]): T[] => {\n if (!value) {\n return [];\n } else if (Array.isArray(value)) {\n return value;\n }\n\n return [value];\n};\n\n/**\n * Return all keys that match\n *\n * @param {string[]} selectorsKeys - List of key to check - example: ['getProducts']\n * @param {string[]} keysWithArgs - List of keys that can includes args - example: [\"getProducts\", \"getProducts/{'ids':['id1','id2']}\", \"getUsers\", \"getUsers/{'ids':['id1','id2']}\" ]\n * @returns {string[]} - key that match the selectors - example: [\"getProducts\", \"getProducts/{'ids':['id1','id2']}\" ]\n */\nconst getMatchKeys = (\n selectorsKeys: string[],\n keysWithArgs: string[]\n): string[] => {\n const matchedKeys: string[] = keysWithArgs.filter((key) =>\n selectorsKeys.includes(key.split('/')[0])\n );\n\n return matchedKeys;\n};\n\nexport const useAsyncStateStore = create<AsyncState<unknown>>((set, get) => ({\n states: {},\n\n getStates: (key) => get().states[key] ?? createDefaultStates<unknown>(),\n\n setQueryState: (key, value) =>\n set((state) => ({\n states: {\n ...state.states,\n [key]: {\n ...(state.states[key] ?? createDefaultStates<unknown>()),\n ...value,\n },\n },\n })),\n\n makeQueryInError: (key, error) =>\n set((state) => ({\n states: {\n ...state.states,\n [key]: {\n ...(state.states[key] ?? createDefaultStates<unknown>()),\n error: error,\n isFetched: true,\n isSuccess: false,\n retryCount: (state.states[key]?.retryCount ?? 0) + 1,\n isLoading: false,\n isInvalidated: false,\n },\n },\n })),\n\n setQueriesState: (keys, value) => {\n const keyArray = ensureArray(keys);\n if (keyArray.length === 0) return;\n\n set((state) => ({\n states: {\n ...state.states,\n ...keyArray.reduce((acc, key) => {\n acc[key] = {\n ...(state.states[key] ?? createDefaultStates<unknown>()),\n ...value,\n };\n return acc;\n }, {} as StateSlice<unknown>),\n },\n }));\n },\n\n resetKeyState: (keys) => {\n const keyArray = ensureArray(keys);\n if (keyArray.length === 0) return;\n\n set((state) => {\n const allKeys = Object.keys(state.states);\n const matchedKeys = getMatchKeys(keyArray, allKeys);\n\n if (matchedKeys.length === 0) return {};\n\n const resetStates = matchedKeys.reduce((acc, key) => {\n acc[key] = createDefaultStates<unknown>();\n return acc;\n }, {} as StateSlice<unknown>);\n\n return {\n states: {\n ...state.states,\n ...resetStates,\n },\n };\n });\n },\n\n resetState: (excludedKeys) => {\n const excludeArray = ensureArray(excludedKeys);\n const allKeys = Object.keys(get().states);\n const matchedKeys = getMatchKeys(excludeArray, allKeys);\n\n set((state) => {\n const newStates = allKeys.reduce((acc, key) => {\n acc[key] = matchedKeys.includes(key)\n ? state.states[key]\n : createDefaultStates<unknown>();\n return acc;\n }, {} as StateSlice<unknown>);\n\n return {\n states: newStates,\n };\n });\n },\n}));\n"],"names":["create"],"mappings":";;;AA+BA,MAAM,sBAAsB,OAAqB;AAAA,EAC/C,WAAW;AAAA,EACX,iBAAiB;AAAA,EACjB,WAAW;AAAA,EACX,eAAe;AAAA,EACf,OAAO;AAAA,EACP,WAAW;AAAA,EACX,MAAM;AAAA,EACN,YAAY;AAAA,EACZ,WAAW;AACb;AAQA,MAAM,cAAc,CAAI,UAAyB;AAC/C,MAAI,CAAC,OAAO;AACV,WAAO,CAAC;AAAA,EACC,WAAA,MAAM,QAAQ,KAAK,GAAG;AACxB,WAAA;AAAA,EAAA;AAGT,SAAO,CAAC,KAAK;AACf;AASA,MAAM,eAAe,CACnB,eACA,iBACa;AACb,QAAM,cAAwB,aAAa;AAAA,IAAO,CAAC,QACjD,cAAc,SAAS,IAAI,MAAM,GAAG,EAAE,CAAC,CAAC;AAAA,EAC1C;AAEO,SAAA;AACT;AAEO,MAAM,qBAAqBA,QAAA,OAA4B,CAAC,KAAK,SAAS;AAAA,EAC3E,QAAQ,CAAC;AAAA,EAET,WAAW,CAAC,QAAQ,IAAA,EAAM,OAAO,GAAG,KAAK,oBAA6B;AAAA,EAEtE,eAAe,CAAC,KAAK,UACnB,IAAI,CAAC,WAAW;AAAA,IACd,QAAQ;AAAA,MACN,GAAG,MAAM;AAAA,MACT,CAAC,GAAG,GAAG;AAAA,QACL,GAAI,MAAM,OAAO,GAAG,KAAK,oBAA6B;AAAA,QACtD,GAAG;AAAA,MAAA;AAAA,IACL;AAAA,EACF,EACA;AAAA,EAEJ,kBAA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CAAC,iBAAiB;AACtB,UAAA,eAAe,YAAY,YAAY;AAC7C,UAAM,UAAU,OAAO,KAAK,IAAA,EAAM,MAAM;AAClC,UAAA,cAAc,aAAa,cAAc,OAAO;AAEtD,QAAI,CAAC,UAAU;AACb,YAAM,YAAY,QAAQ,OAAO,CAAC,KAAK,QAAQ;AACzC,YAAA,GAAG,IAAI,YAAY,SAAS,GAAG,IAC/B,MAAM,OAAO,GAAG,IAChB,oBAA6B;AAC1B,eAAA;AAAA,MACT,GAAG,EAAyB;AAErB,aAAA;AAAA,QACL,QAAQ;AAAA,MACV;AAAA,IAAA,CACD;AAAA,EAAA;AAEL,EAAE;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useAsyncStateStore.mjs","sources":["../../../src/hooks/useAsync/useAsyncStateStore.ts"],"sourcesContent":["import { create } from 'zustand';\n\ntype States<T> = {\n isLoading: boolean;\n isFetched: boolean;\n isInvalidated: boolean;\n fetchedDateTime: null | Date;\n error: string | null;\n isSuccess: boolean;\n data: T | null;\n retryCount: number;\n isEnabled: boolean;\n};\n\ntype StateSlice<T> = {\n [key: string]: States<T>;\n};\n\ntype Actions<T> = {\n getStates: (key: string) => States<T>;\n setQueryState: (key: string, value: Partial<States<T>>) => void;\n setQueriesState: (key: string[], value: Partial<States<T>>) => void;\n makeQueryInError: (key: string, error: string) => void;\n resetKeyState: (key: string[]) => void;\n resetState: (excludedKey: string[]) => void;\n};\n\ntype AsyncState<T> = {\n states: StateSlice<T>;\n} & Actions<T>;\n\nconst createDefaultStates = <T>(): States<T> => ({\n isFetched: false,\n fetchedDateTime: null,\n isLoading: false,\n isInvalidated: false,\n error: null,\n isSuccess: false,\n data: null,\n retryCount: 0,\n isEnabled: true,\n});\n\n/**\n * If the value is not an array. Transform it en array\n *\n * @param value value to transform en array if not array\n * @returns array\n */\nconst ensureArray = <T>(value?: T | T[]): T[] => {\n if (!value) {\n return [];\n } else if (Array.isArray(value)) {\n return value;\n }\n\n return [value];\n};\n\n/**\n * Return all keys that match\n *\n * @param {string[]} selectorsKeys - List of key to check - example: ['getProducts']\n * @param {string[]} keysWithArgs - List of keys that can includes args - example: [\"getProducts\", \"getProducts/{'ids':['id1','id2']}\", \"getUsers\", \"getUsers/{'ids':['id1','id2']}\" ]\n * @returns {string[]} - key that match the selectors - example: [\"getProducts\", \"getProducts/{'ids':['id1','id2']}\" ]\n */\nconst getMatchKeys = (\n selectorsKeys: string[],\n keysWithArgs: string[]\n): string[] => {\n const matchedKeys: string[] = keysWithArgs.filter((key) =>\n selectorsKeys.includes(key.split('/')[0])\n );\n\n return matchedKeys;\n};\n\nexport const useAsyncStateStore = create<AsyncState<unknown>>((set, get) => ({\n states: {},\n\n getStates: (key) => get().states[key] ?? createDefaultStates<unknown>(),\n\n setQueryState: (key, value) =>\n set((state) => ({\n states: {\n ...state.states,\n [key]: {\n ...(state.states[key] ?? createDefaultStates<unknown>()),\n ...value,\n },\n },\n })),\n\n makeQueryInError: (key, error) =>\n set((state) => ({\n states: {\n ...state.states,\n [key]: {\n ...(state.states[key] ?? createDefaultStates<unknown>()),\n error: error,\n isFetched: true,\n isSuccess: false,\n retryCount: (state.states[key]?.retryCount ?? 0) + 1,\n isLoading: false,\n isInvalidated: false,\n },\n },\n })),\n\n setQueriesState: (keys, value) => {\n const keyArray = ensureArray(keys);\n if (keyArray.length === 0) return;\n\n set((state) => ({\n states: {\n ...state.states,\n ...keyArray.reduce((acc, key) => {\n acc[key] = {\n ...(state.states[key] ?? createDefaultStates<unknown>()),\n ...value,\n };\n return acc;\n }, {} as StateSlice<unknown>),\n },\n }));\n },\n\n resetKeyState: (keys) => {\n const keyArray = ensureArray(keys);\n if (keyArray.length === 0) return;\n\n set((state) => {\n const allKeys = Object.keys(state.states);\n const matchedKeys = getMatchKeys(keyArray, allKeys);\n\n if (matchedKeys.length === 0) return {};\n\n const resetStates = matchedKeys.reduce((acc, key) => {\n acc[key] = createDefaultStates<unknown>();\n return acc;\n }, {} as StateSlice<unknown>);\n\n return {\n states: {\n ...state.states,\n ...resetStates,\n },\n };\n });\n },\n\n resetState: (excludedKeys) => {\n const excludeArray = ensureArray(excludedKeys);\n const allKeys = Object.keys(get().states);\n const matchedKeys = getMatchKeys(excludeArray, allKeys);\n\n set((state) => {\n const newStates = allKeys.reduce((acc, key) => {\n acc[key] = matchedKeys.includes(key)\n ? state.states[key]\n : createDefaultStates<unknown>();\n return acc;\n }, {} as StateSlice<unknown>);\n\n return {\n states: newStates,\n };\n });\n },\n}));\n"],"names":[],"mappings":";AA+BA,MAAM,sBAAsB,OAAqB;AAAA,EAC/C,WAAW;AAAA,EACX,iBAAiB;AAAA,EACjB,WAAW;AAAA,EACX,eAAe;AAAA,EACf,OAAO;AAAA,EACP,WAAW;AAAA,EACX,MAAM;AAAA,EACN,YAAY;AAAA,EACZ,WAAW;AACb;AAQA,MAAM,cAAc,CAAI,UAAyB;AAC/C,MAAI,CAAC,OAAO;AACV,WAAO;EACE,WAAA,MAAM,QAAQ,KAAK,GAAG;AACxB,WAAA;AAAA,EACT;AAEA,SAAO,CAAC,KAAK;AACf;AASA,MAAM,eAAe,CACnB,eACA,iBACa;AACb,QAAM,cAAwB,aAAa;AAAA,IAAO,CAAC,QACjD,cAAc,SAAS,IAAI,MAAM,GAAG,EAAE,CAAC,CAAC;AAAA,EAAA;AAGnC,SAAA;AACT;AAEO,MAAM,qBAAqB,OAA4B,CAAC,KAAK,SAAS;AAAA,EAC3E,QAAQ,CAAC;AAAA,EAET,WAAW,CAAC,QAAQ,IAAA,EAAM,OAAO,GAAG,KAAK,oBAA6B;AAAA,EAEtE,eAAe,CAAC,KAAK,UACnB,IAAI,CAAC,WAAW;AAAA,IACd,QAAQ;AAAA,MACN,GAAG,MAAM;AAAA,MACT,CAAC,GAAG,GAAG;AAAA,QACL,GAAI,MAAM,OAAO,GAAG,KAAK,oBAA6B;AAAA,QACtD,GAAG;AAAA,MACL;AAAA,IACF;AAAA,EAAA,EACA;AAAA,EAEJ,kBAAkB,CAAC,KAAK,UACt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Ae,YAAY,YAAY;AAC7C,UAAM,UAAU,OAAO,KAAK,MAAM,MAAM;AAClC,UAAA,cAAc,aAAa,cAAc,OAAO;AAEtD,QAAI,CAAC,UAAU;AACb,YAAM,YAAY,QAAQ,OAAO,CAAC,KAAK,QAAQ;AACzC,YAAA,GAAG,IAAI,YAAY,SAAS,GAAG,IAC/B,MAAM,OAAO,GAAG,IAChB,oBAA6B;AAC1B,eAAA;AAAA,MACT,GAAG,CAAyB,CAAA;AAErB,aAAA;AAAA,QACL,QAAQ;AAAA,MAAA;AAAA,IACV,CACD;AAAA,EACH;AACF,EAAE;"}
1
+ {"version":3,"file":"useAsyncStateStore.mjs","sources":["../../../src/hooks/useAsync/useAsyncStateStore.ts"],"sourcesContent":["import { create } from 'zustand';\n\ntype States<T> = {\n isLoading: boolean;\n isFetched: boolean;\n isInvalidated: boolean;\n fetchedDateTime: null | Date;\n error: string | null;\n isSuccess: boolean;\n data: T | null;\n retryCount: number;\n isEnabled: boolean;\n};\n\ntype StateSlice<T> = {\n [key: string]: States<T>;\n};\n\ntype Actions<T> = {\n getStates: (key: string) => States<T>;\n setQueryState: (key: string, value: Partial<States<T>>) => void;\n setQueriesState: (key: string[], value: Partial<States<T>>) => void;\n makeQueryInError: (key: string, error: string) => void;\n resetKeyState: (key: string[]) => void;\n resetState: (excludedKey: string[]) => void;\n};\n\ntype AsyncState<T> = {\n states: StateSlice<T>;\n} & Actions<T>;\n\nconst createDefaultStates = <T>(): States<T> => ({\n isFetched: false,\n fetchedDateTime: null,\n isLoading: false,\n isInvalidated: false,\n error: null,\n isSuccess: false,\n data: null,\n retryCount: 0,\n isEnabled: true,\n});\n\n/**\n * If the value is not an array. Transform it en array\n *\n * @param value value to transform en array if not array\n * @returns array\n */\nconst ensureArray = <T>(value?: T | T[]): T[] => {\n if (!value) {\n return [];\n } else if (Array.isArray(value)) {\n return value;\n }\n\n return [value];\n};\n\n/**\n * Return all keys that match\n *\n * @param {string[]} selectorsKeys - List of key to check - example: ['getProducts']\n * @param {string[]} keysWithArgs - List of keys that can includes args - example: [\"getProducts\", \"getProducts/{'ids':['id1','id2']}\", \"getUsers\", \"getUsers/{'ids':['id1','id2']}\" ]\n * @returns {string[]} - key that match the selectors - example: [\"getProducts\", \"getProducts/{'ids':['id1','id2']}\" ]\n */\nconst getMatchKeys = (\n selectorsKeys: string[],\n keysWithArgs: string[]\n): string[] => {\n const matchedKeys: string[] = keysWithArgs.filter((key) =>\n selectorsKeys.includes(key.split('/')[0])\n );\n\n return matchedKeys;\n};\n\nexport const useAsyncStateStore = create<AsyncState<unknown>>((set, get) => ({\n states: {},\n\n getStates: (key) => get().states[key] ?? createDefaultStates<unknown>(),\n\n setQueryState: (key, value) =>\n set((state) => ({\n states: {\n ...state.states,\n [key]: {\n ...(state.states[key] ?? createDefaultStates<unknown>()),\n ...value,\n },\n },\n })),\n\n makeQueryInError: (key, error) =>\n set((state) => ({\n states: {\n ...state.states,\n [key]: {\n ...(state.states[key] ?? createDefaultStates<unknown>()),\n error: error,\n isFetched: true,\n isSuccess: false,\n retryCount: (state.states[key]?.retryCount ?? 0) + 1,\n isLoading: false,\n isInvalidated: false,\n },\n },\n })),\n\n setQueriesState: (keys, value) => {\n const keyArray = ensureArray(keys);\n if (keyArray.length === 0) return;\n\n set((state) => ({\n states: {\n ...state.states,\n ...keyArray.reduce((acc, key) => {\n acc[key] = {\n ...(state.states[key] ?? createDefaultStates<unknown>()),\n ...value,\n };\n return acc;\n }, {} as StateSlice<unknown>),\n },\n }));\n },\n\n resetKeyState: (keys) => {\n const keyArray = ensureArray(keys);\n if (keyArray.length === 0) return;\n\n set((state) => {\n const allKeys = Object.keys(state.states);\n const matchedKeys = getMatchKeys(keyArray, allKeys);\n\n if (matchedKeys.length === 0) return {};\n\n const resetStates = matchedKeys.reduce((acc, key) => {\n acc[key] = createDefaultStates<unknown>();\n return acc;\n }, {} as StateSlice<unknown>);\n\n return {\n states: {\n ...state.states,\n ...resetStates,\n },\n };\n });\n },\n\n resetState: (excludedKeys) => {\n const excludeArray = ensureArray(excludedKeys);\n const allKeys = Object.keys(get().states);\n const matchedKeys = getMatchKeys(excludeArray, allKeys);\n\n set((state) => {\n const newStates = allKeys.reduce((acc, key) => {\n acc[key] = matchedKeys.includes(key)\n ? state.states[key]\n : createDefaultStates<unknown>();\n return acc;\n }, {} as StateSlice<unknown>);\n\n return {\n states: newStates,\n };\n });\n },\n}));\n"],"names":[],"mappings":";AA+BA,MAAM,sBAAsB,OAAqB;AAAA,EAC/C,WAAW;AAAA,EACX,iBAAiB;AAAA,EACjB,WAAW;AAAA,EACX,eAAe;AAAA,EACf,OAAO;AAAA,EACP,WAAW;AAAA,EACX,MAAM;AAAA,EACN,YAAY;AAAA,EACZ,WAAW;AACb;AAQA,MAAM,cAAc,CAAI,UAAyB;AAC/C,MAAI,CAAC,OAAO;AACV,WAAO,CAAC;AAAA,EACC,WAAA,MAAM,QAAQ,KAAK,GAAG;AACxB,WAAA;AAAA,EAAA;AAGT,SAAO,CAAC,KAAK;AACf;AASA,MAAM,eAAe,CACnB,eACA,iBACa;AACb,QAAM,cAAwB,aAAa;AAAA,IAAO,CAAC,QACjD,cAAc,SAAS,IAAI,MAAM,GAAG,EAAE,CAAC,CAAC;AAAA,EAC1C;AAEO,SAAA;AACT;AAEO,MAAM,qBAAqB,OAA4B,CAAC,KAAK,SAAS;AAAA,EAC3E,QAAQ,CAAC;AAAA,EAET,WAAW,CAAC,QAAQ,IAAA,EAAM,OAAO,GAAG,KAAK,oBAA6B;AAAA,EAEtE,eAAe,CAAC,KAAK,UACnB,IAAI,CAAC,WAAW;AAAA,IACd,QAAQ;AAAA,MACN,GAAG,MAAM;AAAA,MACT,CAAC,GAAG,GAAG;AAAA,QACL,GAAI,MAAM,OAAO,GAAG,KAAK,oBAA6B;AAAA,QACtD,GAAG;AAAA,MAAA;AAAA,IACL;AAAA,EACF,EACA;AAAA,EAEJ,kBAAkB,CAAC,KAAK,UACtB,IAAI,CAAC,WAAW;AAAA,IACd,Q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UAAM,UAAU,OAAO,KAAK,IAAA,EAAM,MAAM;AAClC,UAAA,cAAc,aAAa,cAAc,OAAO;AAEtD,QAAI,CAAC,UAAU;AACb,YAAM,YAAY,QAAQ,OAAO,CAAC,KAAK,QAAQ;AACzC,YAAA,GAAG,IAAI,YAAY,SAAS,GAAG,IAC/B,MAAM,OAAO,GAAG,IAChB,oBAA6B;AAC1B,eAAA;AAAA,MACT,GAAG,EAAyB;AAErB,aAAA;AAAA,QACL,QAAQ;AAAA,MACV;AAAA,IAAA,CACD;AAAA,EAAA;AAEL,EAAE;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useDevice.cjs","sources":["../../src/hooks/useDevice.ts"],"sourcesContent":["'use client';\n\nimport { useEffect, useState } from 'react';\n\nexport type SizeType = 'sm' | 'md' | 'lg' | 'xl' | '2xl';\n\nconst getBreakpointFromSize = (breakpoint: SizeType | number) => {\n switch (breakpoint) {\n case 'sm':\n return 640;\n case 'md':\n return 768;\n case 'lg':\n return 1024;\n case 'xl':\n return 1280;\n case '2xl':\n return 1536;\n default:\n return breakpoint;\n }\n};\n\nconst checkIsMobileUserAgent = (): boolean | undefined => {\n if (typeof window === 'undefined') return;\n\n const userAgent = window.navigator?.userAgent;\n\n if (typeof userAgent === 'undefined') return;\n\n // eslint-disable-next-line sonarjs/regex-complexity\n return /android|bb\\d+|meego|avantgo|bada\\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(?:hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(?:ob|in)i|palm(?: os)?|phone|p(?:ixi|re)\\/|plucker|pocket|psp|series(?:4|6)0|symbian|treo|up\\.(?:browser|link)|vodafone|wap|windows ce|windows phone|xda|xiino|zte-/i.test(\n userAgent\n );\n};\n\nconst checkIsMobileScreen = (breakpoint: number): boolean | undefined => {\n if (typeof window === 'undefined') return;\n\n return (window?.innerWidth ?? 0) <= breakpoint;\n};\n\ntype UseDeviceState = {\n isMobileScreen: boolean | undefined;\n isMobileUserAgent: boolean | undefined;\n isMobile: boolean | undefined;\n};\n\nconst calculateIsMobile = (breakpoint: SizeType | number) => {\n const breakpointValue = getBreakpointFromSize(breakpoint);\n\n const isMobileUserAgent = checkIsMobileUserAgent();\n const isMobileScreen = checkIsMobileScreen(breakpointValue);\n const isMobile = isMobileScreen ?? isMobileUserAgent;\n\n return {\n isMobileScreen, // Is the screen width within a mobile breakpoint.\n isMobileUserAgent, // Is the user agent indicative of a mobile device.\n isMobile, // Combines both checks to determine if the device is mobile.\n };\n};\n\nexport const useDevice = (breakpoint: SizeType | number = 'md') => {\n const [result, setResult] = useState<UseDeviceState>(\n calculateIsMobile(breakpoint)\n );\n\n useEffect(() => {\n const handleResize = () => {\n setResult(calculateIsMobile(breakpoint));\n };\n\n window.addEventListener('resize', handleResize);\n\n // Cleanup listener on unmount\n return () => window.removeEventListener('resize', handleResize);\n }, [breakpoint]); // Empty dependency array ensures this effect runs only once on mount\n\n return result;\n};\n"],"names":["useState","useEffect"],"mappings":";;;;AAMA,MAAM,wBAAwB,CAAC,eAAkC;AAC/D,UAAQ,YAAY;AAAA,IAClB,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT;AACS,aAAA;AAAA,EACX;AACF;AAEA,MAAM,yBAAyB,MAA2B;AACpD,MAAA,OAAO,WAAW,YAAa;AAE7B,QAAA,YAAY,OAAO,WAAW;AAEhC,MAAA,OAAO,cAAc,YAAa;AAGtC,SAAO,mVAAmV;AAAA,IACxV;AAAA,EAAA;AAEJ;AAEA,MAAM,sBAAsB,CAAC,eAA4C;AACnE,MAAA,OAAO,WAAW,YAAa;AAE3B,UAAA,QAAQ,cAAc,MAAM;AACtC;AAQA,MAAM,oBAAoB,CAAC,eAAkC;AACrD,QAAA,kBAAkB,sBAAsB,UAAU;AAExD,QAAM,oBAAoB;AACpB,QAAA,iBAAiB,oBAAoB,eAAe;AAC1D,QAAM,WAAW,kBAAkB;AAE5B,SAAA;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EAAA;AAEJ;AAEa,MAAA,YAAY,CAAC,aAAgC,SAAS;AAC3D,QAAA,CAAC,QAAQ,SAAS,IAAIA,WAAA;AAAA,IAC1B,kBAAkB,UAAU;AAAA,EAAA;AAG9BC,aAAAA,UAAU,MAAM;AACd,UAAM,eAAe,MAAM;AACf,gBAAA,kBAAkB,UAAU,CAAC;AAAA,IAAA;AAGlC,WAAA,iBAAiB,UAAU,YAAY;AAG9C,WAAO,MAAM,OAAO,oBAAoB,UAAU,YAAY;AAAA,EAAA,GAC7D,CAAC,UAAU,CAAC;AAER,SAAA;AACT;;"}
1
+ {"version":3,"file":"useDevice.cjs","sources":["../../src/hooks/useDevice.ts"],"sourcesContent":["'use client';\n\nimport { useEffect, useState } from 'react';\n\nexport type SizeType = 'sm' | 'md' | 'lg' | 'xl' | '2xl';\n\nconst getBreakpointFromSize = (breakpoint: SizeType | number) => {\n switch (breakpoint) {\n case 'sm':\n return 640;\n case 'md':\n return 768;\n case 'lg':\n return 1024;\n case 'xl':\n return 1280;\n case '2xl':\n return 1536;\n default:\n return breakpoint;\n }\n};\n\nconst checkIsMobileUserAgent = (): boolean | undefined => {\n if (typeof window === 'undefined') return;\n\n const userAgent = window.navigator?.userAgent;\n\n if (typeof userAgent === 'undefined') return;\n\n // eslint-disable-next-line sonarjs/regex-complexity\n return /android|bb\\d+|meego|avantgo|bada\\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(?:hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(?:ob|in)i|palm(?: os)?|phone|p(?:ixi|re)\\/|plucker|pocket|psp|series(?:4|6)0|symbian|treo|up\\.(?:browser|link)|vodafone|wap|windows ce|windows phone|xda|xiino|zte-/i.test(\n userAgent\n );\n};\n\nconst checkIsMobileScreen = (breakpoint: number): boolean | undefined => {\n if (typeof window === 'undefined') return;\n\n return (window?.innerWidth ?? 0) <= breakpoint;\n};\n\ntype UseDeviceState = {\n isMobileScreen: boolean | undefined;\n isMobileUserAgent: boolean | undefined;\n isMobile: boolean | undefined;\n};\n\nconst calculateIsMobile = (breakpoint: SizeType | number) => {\n const breakpointValue = getBreakpointFromSize(breakpoint);\n\n const isMobileUserAgent = checkIsMobileUserAgent();\n const isMobileScreen = checkIsMobileScreen(breakpointValue);\n const isMobile = isMobileScreen ?? isMobileUserAgent;\n\n return {\n isMobileScreen, // Is the screen width within a mobile breakpoint.\n isMobileUserAgent, // Is the user agent indicative of a mobile device.\n isMobile, // Combines both checks to determine if the device is mobile.\n };\n};\n\nexport const useDevice = (breakpoint: SizeType | number = 'md') => {\n const [result, setResult] = useState<UseDeviceState>(\n calculateIsMobile(breakpoint)\n );\n\n useEffect(() => {\n const handleResize = () => {\n setResult(calculateIsMobile(breakpoint));\n };\n\n window.addEventListener('resize', handleResize);\n\n // Cleanup listener on unmount\n return () => window.removeEventListener('resize', handleResize);\n }, [breakpoint]); // Empty dependency array ensures this effect runs only once on mount\n\n return result;\n};\n"],"names":["useState","useEffect"],"mappings":";;;;AAMA,MAAM,wBAAwB,CAAC,eAAkC;AAC/D,UAAQ,YAAY;AAAA,IAClB,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT;AACS,aAAA;AAAA,EAAA;AAEb;AAEA,MAAM,yBAAyB,MAA2B;AACpD,MAAA,OAAO,WAAW,YAAa;AAE7B,QAAA,YAAY,OAAO,WAAW;AAEhC,MAAA,OAAO,cAAc,YAAa;AAGtC,SAAO,mVAAmV;AAAA,IACxV;AAAA,EACF;AACF;AAEA,MAAM,sBAAsB,CAAC,eAA4C;AACnE,MAAA,OAAO,WAAW,YAAa;AAE3B,UAAA,QAAQ,cAAc,MAAM;AACtC;AAQA,MAAM,oBAAoB,CAAC,eAAkC;AACrD,QAAA,kBAAkB,sBAAsB,UAAU;AAExD,QAAM,oBAAoB,uBAAuB;AAC3C,QAAA,iBAAiB,oBAAoB,eAAe;AAC1D,QAAM,WAAW,kBAAkB;AAE5B,SAAA;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AACF;AAEa,MAAA,YAAY,CAAC,aAAgC,SAAS;AAC3D,QAAA,CAAC,QAAQ,SAAS,IAAIA,WAAA;AAAA,IAC1B,kBAAkB,UAAU;AAAA,EAC9B;AAEAC,aAAAA,UAAU,MAAM;AACd,UAAM,eAAe,MAAM;AACf,gBAAA,kBAAkB,UAAU,CAAC;AAAA,IACzC;AAEO,WAAA,iBAAiB,UAAU,YAAY;AAG9C,WAAO,MAAM,OAAO,oBAAoB,UAAU,YAAY;AAAA,EAAA,GAC7D,CAAC,UAAU,CAAC;AAER,SAAA;AACT;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useDevice.mjs","sources":["../../src/hooks/useDevice.ts"],"sourcesContent":["'use client';\n\nimport { useEffect, useState } from 'react';\n\nexport type SizeType = 'sm' | 'md' | 'lg' | 'xl' | '2xl';\n\nconst getBreakpointFromSize = (breakpoint: SizeType | number) => {\n switch (breakpoint) {\n case 'sm':\n return 640;\n case 'md':\n return 768;\n case 'lg':\n return 1024;\n case 'xl':\n return 1280;\n case '2xl':\n return 1536;\n default:\n return breakpoint;\n }\n};\n\nconst checkIsMobileUserAgent = (): boolean | undefined => {\n if (typeof window === 'undefined') return;\n\n const userAgent = window.navigator?.userAgent;\n\n if (typeof userAgent === 'undefined') return;\n\n // eslint-disable-next-line sonarjs/regex-complexity\n return /android|bb\\d+|meego|avantgo|bada\\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(?:hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(?:ob|in)i|palm(?: os)?|phone|p(?:ixi|re)\\/|plucker|pocket|psp|series(?:4|6)0|symbian|treo|up\\.(?:browser|link)|vodafone|wap|windows ce|windows phone|xda|xiino|zte-/i.test(\n userAgent\n );\n};\n\nconst checkIsMobileScreen = (breakpoint: number): boolean | undefined => {\n if (typeof window === 'undefined') return;\n\n return (window?.innerWidth ?? 0) <= breakpoint;\n};\n\ntype UseDeviceState = {\n isMobileScreen: boolean | undefined;\n isMobileUserAgent: boolean | undefined;\n isMobile: boolean | undefined;\n};\n\nconst calculateIsMobile = (breakpoint: SizeType | number) => {\n const breakpointValue = getBreakpointFromSize(breakpoint);\n\n const isMobileUserAgent = checkIsMobileUserAgent();\n const isMobileScreen = checkIsMobileScreen(breakpointValue);\n const isMobile = isMobileScreen ?? isMobileUserAgent;\n\n return {\n isMobileScreen, // Is the screen width within a mobile breakpoint.\n isMobileUserAgent, // Is the user agent indicative of a mobile device.\n isMobile, // Combines both checks to determine if the device is mobile.\n };\n};\n\nexport const useDevice = (breakpoint: SizeType | number = 'md') => {\n const [result, setResult] = useState<UseDeviceState>(\n calculateIsMobile(breakpoint)\n );\n\n useEffect(() => {\n const handleResize = () => {\n setResult(calculateIsMobile(breakpoint));\n };\n\n window.addEventListener('resize', handleResize);\n\n // Cleanup listener on unmount\n return () => window.removeEventListener('resize', handleResize);\n }, [breakpoint]); // Empty dependency array ensures this effect runs only once on mount\n\n return result;\n};\n"],"names":[],"mappings":";;AAMA,MAAM,wBAAwB,CAAC,eAAkC;AAC/D,UAAQ,YAAY;AAAA,IAClB,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT;AACS,aAAA;AAAA,EACX;AACF;AAEA,MAAM,yBAAyB,MAA2B;AACpD,MAAA,OAAO,WAAW,YAAa;AAE7B,QAAA,YAAY,OAAO,WAAW;AAEhC,MAAA,OAAO,cAAc,YAAa;AAGtC,SAAO,mVAAmV;AAAA,IACxV;AAAA,EAAA;AAEJ;AAEA,MAAM,sBAAsB,CAAC,eAA4C;AACnE,MAAA,OAAO,WAAW,YAAa;AAE3B,UAAA,QAAQ,cAAc,MAAM;AACtC;AAQA,MAAM,oBAAoB,CAAC,eAAkC;AACrD,QAAA,kBAAkB,sBAAsB,UAAU;AAExD,QAAM,oBAAoB;AACpB,QAAA,iBAAiB,oBAAoB,eAAe;AAC1D,QAAM,WAAW,kBAAkB;AAE5B,SAAA;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EAAA;AAEJ;AAEa,MAAA,YAAY,CAAC,aAAgC,SAAS;AAC3D,QAAA,CAAC,QAAQ,SAAS,IAAI;AAAA,IAC1B,kBAAkB,UAAU;AAAA,EAAA;AAG9B,YAAU,MAAM;AACd,UAAM,eAAe,MAAM;AACf,gBAAA,kBAAkB,UAAU,CAAC;AAAA,IAAA;AAGlC,WAAA,iBAAiB,UAAU,YAAY;AAG9C,WAAO,MAAM,OAAO,oBAAoB,UAAU,YAAY;AAAA,EAAA,GAC7D,CAAC,UAAU,CAAC;AAER,SAAA;AACT;"}
1
+ {"version":3,"file":"useDevice.mjs","sources":["../../src/hooks/useDevice.ts"],"sourcesContent":["'use client';\n\nimport { useEffect, useState } from 'react';\n\nexport type SizeType = 'sm' | 'md' | 'lg' | 'xl' | '2xl';\n\nconst getBreakpointFromSize = (breakpoint: SizeType | number) => {\n switch (breakpoint) {\n case 'sm':\n return 640;\n case 'md':\n return 768;\n case 'lg':\n return 1024;\n case 'xl':\n return 1280;\n case '2xl':\n return 1536;\n default:\n return breakpoint;\n }\n};\n\nconst checkIsMobileUserAgent = (): boolean | undefined => {\n if (typeof window === 'undefined') return;\n\n const userAgent = window.navigator?.userAgent;\n\n if (typeof userAgent === 'undefined') return;\n\n // eslint-disable-next-line sonarjs/regex-complexity\n return /android|bb\\d+|meego|avantgo|bada\\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(?:hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(?:ob|in)i|palm(?: os)?|phone|p(?:ixi|re)\\/|plucker|pocket|psp|series(?:4|6)0|symbian|treo|up\\.(?:browser|link)|vodafone|wap|windows ce|windows phone|xda|xiino|zte-/i.test(\n userAgent\n );\n};\n\nconst checkIsMobileScreen = (breakpoint: number): boolean | undefined => {\n if (typeof window === 'undefined') return;\n\n return (window?.innerWidth ?? 0) <= breakpoint;\n};\n\ntype UseDeviceState = {\n isMobileScreen: boolean | undefined;\n isMobileUserAgent: boolean | undefined;\n isMobile: boolean | undefined;\n};\n\nconst calculateIsMobile = (breakpoint: SizeType | number) => {\n const breakpointValue = getBreakpointFromSize(breakpoint);\n\n const isMobileUserAgent = checkIsMobileUserAgent();\n const isMobileScreen = checkIsMobileScreen(breakpointValue);\n const isMobile = isMobileScreen ?? isMobileUserAgent;\n\n return {\n isMobileScreen, // Is the screen width within a mobile breakpoint.\n isMobileUserAgent, // Is the user agent indicative of a mobile device.\n isMobile, // Combines both checks to determine if the device is mobile.\n };\n};\n\nexport const useDevice = (breakpoint: SizeType | number = 'md') => {\n const [result, setResult] = useState<UseDeviceState>(\n calculateIsMobile(breakpoint)\n );\n\n useEffect(() => {\n const handleResize = () => {\n setResult(calculateIsMobile(breakpoint));\n };\n\n window.addEventListener('resize', handleResize);\n\n // Cleanup listener on unmount\n return () => window.removeEventListener('resize', handleResize);\n }, [breakpoint]); // Empty dependency array ensures this effect runs only once on mount\n\n return result;\n};\n"],"names":[],"mappings":";;AAMA,MAAM,wBAAwB,CAAC,eAAkC;AAC/D,UAAQ,YAAY;AAAA,IAClB,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT;AACS,aAAA;AAAA,EAAA;AAEb;AAEA,MAAM,yBAAyB,MAA2B;AACpD,MAAA,OAAO,WAAW,YAAa;AAE7B,QAAA,YAAY,OAAO,WAAW;AAEhC,MAAA,OAAO,cAAc,YAAa;AAGtC,SAAO,mVAAmV;AAAA,IACxV;AAAA,EACF;AACF;AAEA,MAAM,sBAAsB,CAAC,eAA4C;AACnE,MAAA,OAAO,WAAW,YAAa;AAE3B,UAAA,QAAQ,cAAc,MAAM;AACtC;AAQA,MAAM,oBAAoB,CAAC,eAAkC;AACrD,QAAA,kBAAkB,sBAAsB,UAAU;AAExD,QAAM,oBAAoB,uBAAuB;AAC3C,QAAA,iBAAiB,oBAAoB,eAAe;AAC1D,QAAM,WAAW,kBAAkB;AAE5B,SAAA;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AACF;AAEa,MAAA,YAAY,CAAC,aAAgC,SAAS;AAC3D,QAAA,CAAC,QAAQ,SAAS,IAAI;AAAA,IAC1B,kBAAkB,UAAU;AAAA,EAC9B;AAEA,YAAU,MAAM;AACd,UAAM,eAAe,MAAM;AACf,gBAAA,kBAAkB,UAAU,CAAC;AAAA,IACzC;AAEO,WAAA,iBAAiB,UAAU,YAAY;AAG9C,WAAO,MAAM,OAAO,oBAAoB,UAAU,YAAY;AAAA,EAAA,GAC7D,CAAC,UAAU,CAAC;AAER,SAAA;AACT;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useGetAllDictionaries.cjs","sources":["../../src/hooks/useGetAllDictionaries.tsx"],"sourcesContent":["'use client';\n\n/**\n * @intlayer/dictionaries-entry is a package that only returns the dictionary entry path.\n * Using an external package allow to alias it in the bundle configuration (such as webpack).\n * The alias allow hot reload the app (such as nextjs) on any dictionary change.\n */\nimport { Dictionary } from '@intlayer/core';\nimport localeDictionaries from '@intlayer/dictionaries-entry';\nimport merge from 'deepmerge';\nimport { useMemo } from 'react';\nimport { useGetDictionaries } from './intlayerAPIHooks';\n\nexport const useGetAllDictionaries = () => {\n const { data: onlineDictionariesAPI, isLoading } = useGetDictionaries();\n\n const onlineDictionaries: Record<string, Dictionary> = useMemo(\n () =>\n (onlineDictionariesAPI?.data ?? []).reduce(\n (acc, dictionary) => {\n acc[dictionary.key] = dictionary;\n return acc;\n },\n {} as Record<string, Dictionary>\n ),\n [onlineDictionariesAPI]\n );\n\n const allDictionaries: Record<string, Dictionary> = useMemo(\n () => merge(onlineDictionaries ?? {}, localeDictionaries),\n [onlineDictionaries]\n );\n\n return {\n online: onlineDictionaries,\n locale: localeDictionaries,\n all: allDictionaries,\n isLoading,\n };\n};\n"],"names":["useGetDictionaries","useMemo"],"mappings":";;;;;;;AAaO,MAAM,wBAAwB,MAAM;AACzC,QAAM,EAAE,MAAM,uBAAuB,cAAcA,uBAAmB,mBAAA;AAEtE,QAAM,qBAAiDC,WAAA;AAAA,IACrD,OACG,uBAAuB,QAAQ,CAAA,GAAI;AAAA,MAClC,CAAC,KAAK,eAAe;AACf,YAAA,WAAW,GAAG,IAAI;AACf,eAAA;AAAA,MACT;AAAA,MACA,CAAC;AAAA,IACH;AAAA,IACF,CAAC,qBAAqB;AAAA,EAAA;AAGxB,QAAM,kBAA8CA,WAAA;AAAA,IAClD,MAAM,MAAM,sBAAsB,IAAI,kBAAkB;AAAA,IACxD,CAAC,kBAAkB;AAAA,EAAA;AAGd,SAAA;AAAA,IACL,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,KAAK;AAAA,IACL;AAAA,EAAA;AAEJ;;"}
1
+ {"version":3,"file":"useGetAllDictionaries.cjs","sources":["../../src/hooks/useGetAllDictionaries.tsx"],"sourcesContent":["'use client';\n\n/**\n * @intlayer/dictionaries-entry is a package that only returns the dictionary entry path.\n * Using an external package allow to alias it in the bundle configuration (such as webpack).\n * The alias allow hot reload the app (such as nextjs) on any dictionary change.\n */\nimport { Dictionary } from '@intlayer/core';\nimport localeDictionaries from '@intlayer/dictionaries-entry';\nimport merge from 'deepmerge';\nimport { useMemo } from 'react';\nimport { useGetDictionaries } from './intlayerAPIHooks';\n\nexport const useGetAllDictionaries = () => {\n const { data: onlineDictionariesAPI, isLoading } = useGetDictionaries();\n\n const onlineDictionaries: Record<string, Dictionary> = useMemo(\n () =>\n (onlineDictionariesAPI?.data ?? []).reduce(\n (acc, dictionary) => {\n acc[dictionary.key] = dictionary;\n return acc;\n },\n {} as Record<string, Dictionary>\n ),\n [onlineDictionariesAPI]\n );\n\n const allDictionaries: Record<string, Dictionary> = useMemo(\n () => merge(onlineDictionaries ?? {}, localeDictionaries),\n [onlineDictionaries]\n );\n\n return {\n online: onlineDictionaries,\n locale: localeDictionaries,\n all: allDictionaries,\n isLoading,\n };\n};\n"],"names":["useGetDictionaries","useMemo"],"mappings":";;;;;;;AAaO,MAAM,wBAAwB,MAAM;AACzC,QAAM,EAAE,MAAM,uBAAuB,UAAA,IAAcA,uBAAAA,mBAAmB;AAEtE,QAAM,qBAAiDC,WAAA;AAAA,IACrD,OACG,uBAAuB,QAAQ,CAAA,GAAI;AAAA,MAClC,CAAC,KAAK,eAAe;AACf,YAAA,WAAW,GAAG,IAAI;AACf,eAAA;AAAA,MACT;AAAA,MACA,CAAA;AAAA,IACF;AAAA,IACF,CAAC,qBAAqB;AAAA,EACxB;AAEA,QAAM,kBAA8CA,WAAA;AAAA,IAClD,MAAM,MAAM,sBAAsB,IAAI,kBAAkB;AAAA,IACxD,CAAC,kBAAkB;AAAA,EACrB;AAEO,SAAA;AAAA,IACL,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,KAAK;AAAA,IACL;AAAA,EACF;AACF;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useGetAllDictionaries.mjs","sources":["../../src/hooks/useGetAllDictionaries.tsx"],"sourcesContent":["'use client';\n\n/**\n * @intlayer/dictionaries-entry is a package that only returns the dictionary entry path.\n * Using an external package allow to alias it in the bundle configuration (such as webpack).\n * The alias allow hot reload the app (such as nextjs) on any dictionary change.\n */\nimport { Dictionary } from '@intlayer/core';\nimport localeDictionaries from '@intlayer/dictionaries-entry';\nimport merge from 'deepmerge';\nimport { useMemo } from 'react';\nimport { useGetDictionaries } from './intlayerAPIHooks';\n\nexport const useGetAllDictionaries = () => {\n const { data: onlineDictionariesAPI, isLoading } = useGetDictionaries();\n\n const onlineDictionaries: Record<string, Dictionary> = useMemo(\n () =>\n (onlineDictionariesAPI?.data ?? []).reduce(\n (acc, dictionary) => {\n acc[dictionary.key] = dictionary;\n return acc;\n },\n {} as Record<string, Dictionary>\n ),\n [onlineDictionariesAPI]\n );\n\n const allDictionaries: Record<string, Dictionary> = useMemo(\n () => merge(onlineDictionaries ?? {}, localeDictionaries),\n [onlineDictionaries]\n );\n\n return {\n online: onlineDictionaries,\n locale: localeDictionaries,\n all: allDictionaries,\n isLoading,\n };\n};\n"],"names":[],"mappings":";;;;;AAaO,MAAM,wBAAwB,MAAM;AACzC,QAAM,EAAE,MAAM,uBAAuB,cAAc,mBAAmB;AAEtE,QAAM,qBAAiD;AAAA,IACrD,OACG,uBAAuB,QAAQ,CAAA,GAAI;AAAA,MAClC,CAAC,KAAK,eAAe;AACf,YAAA,WAAW,GAAG,IAAI;AACf,eAAA;AAAA,MACT;AAAA,MACA,CAAC;AAAA,IACH;AAAA,IACF,CAAC,qBAAqB;AAAA,EAAA;AAGxB,QAAM,kBAA8C;AAAA,IAClD,MAAM,MAAM,sBAAsB,IAAI,kBAAkB;AAAA,IACxD,CAAC,kBAAkB;AAAA,EAAA;AAGd,SAAA;AAAA,IACL,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,KAAK;AAAA,IACL;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"useGetAllDictionaries.mjs","sources":["../../src/hooks/useGetAllDictionaries.tsx"],"sourcesContent":["'use client';\n\n/**\n * @intlayer/dictionaries-entry is a package that only returns the dictionary entry path.\n * Using an external package allow to alias it in the bundle configuration (such as webpack).\n * The alias allow hot reload the app (such as nextjs) on any dictionary change.\n */\nimport { Dictionary } from '@intlayer/core';\nimport localeDictionaries from '@intlayer/dictionaries-entry';\nimport merge from 'deepmerge';\nimport { useMemo } from 'react';\nimport { useGetDictionaries } from './intlayerAPIHooks';\n\nexport const useGetAllDictionaries = () => {\n const { data: onlineDictionariesAPI, isLoading } = useGetDictionaries();\n\n const onlineDictionaries: Record<string, Dictionary> = useMemo(\n () =>\n (onlineDictionariesAPI?.data ?? []).reduce(\n (acc, dictionary) => {\n acc[dictionary.key] = dictionary;\n return acc;\n },\n {} as Record<string, Dictionary>\n ),\n [onlineDictionariesAPI]\n );\n\n const allDictionaries: Record<string, Dictionary> = useMemo(\n () => merge(onlineDictionaries ?? {}, localeDictionaries),\n [onlineDictionaries]\n );\n\n return {\n online: onlineDictionaries,\n locale: localeDictionaries,\n all: allDictionaries,\n isLoading,\n };\n};\n"],"names":[],"mappings":";;;;;AAaO,MAAM,wBAAwB,MAAM;AACzC,QAAM,EAAE,MAAM,uBAAuB,UAAA,IAAc,mBAAmB;AAEtE,QAAM,qBAAiD;AAAA,IACrD,OACG,uBAAuB,QAAQ,CAAA,GAAI;AAAA,MAClC,CAAC,KAAK,eAAe;AACf,YAAA,WAAW,GAAG,IAAI;AACf,eAAA;AAAA,MACT;AAAA,MACA,CAAA;AAAA,IACF;AAAA,IACF,CAAC,qBAAqB;AAAA,EACxB;AAEA,QAAM,kBAA8C;AAAA,IAClD,MAAM,MAAM,sBAAsB,IAAI,kBAAkB;AAAA,IACxD,CAAC,kBAAkB;AAAA,EACrB;AAEO,SAAA;AAAA,IACL,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,KAAK;AAAA,IACL;AAAA,EACF;AACF;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useGetElementOrWindow.cjs","sources":["../../src/hooks/useGetElementOrWindow.ts"],"sourcesContent":["'use client';\n\nimport { useEffect, useState } from 'react';\n\nexport const useGetElementOrWindow = (container?: HTMLElement) => {\n const [containerElement, setContainerElement] = useState<\n HTMLElement | undefined\n >(container);\n\n // This useEffect avoids the error of not finding the container\n useEffect(() => {\n setContainerElement(container ?? window.document.body);\n }, [container]);\n\n return containerElement;\n};\n"],"names":["useState","useEffect"],"mappings":";;;;AAIa,MAAA,wBAAwB,CAAC,cAA4B;AAChE,QAAM,CAAC,kBAAkB,mBAAmB,IAAIA,oBAE9C,SAAS;AAGXC,aAAAA,UAAU,MAAM;AACM,wBAAA,aAAa,OAAO,SAAS,IAAI;AAAA,EAAA,GACpD,CAAC,SAAS,CAAC;AAEP,SAAA;AACT;;"}
1
+ {"version":3,"file":"useGetElementOrWindow.cjs","sources":["../../src/hooks/useGetElementOrWindow.ts"],"sourcesContent":["'use client';\n\nimport { useEffect, useState } from 'react';\n\nexport const useGetElementOrWindow = (container?: HTMLElement) => {\n const [containerElement, setContainerElement] = useState<\n HTMLElement | undefined\n >(container);\n\n // This useEffect avoids the error of not finding the container\n useEffect(() => {\n setContainerElement(container ?? window.document.body);\n }, [container]);\n\n return containerElement;\n};\n"],"names":["useState","useEffect"],"mappings":";;;;AAIa,MAAA,wBAAwB,CAAC,cAA4B;AAChE,QAAM,CAAC,kBAAkB,mBAAmB,IAAIA,WAAAA,SAE9C,SAAS;AAGXC,aAAAA,UAAU,MAAM;AACM,wBAAA,aAAa,OAAO,SAAS,IAAI;AAAA,EAAA,GACpD,CAAC,SAAS,CAAC;AAEP,SAAA;AACT;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useIntlayerAPI.cjs","sources":["../../src/hooks/useIntlayerAPI.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport { useAuth } from '../components/Auth/useAuth';\nimport { getIntlayerAPI } from '../libs/intlayer-api';\nimport { FetcherOptions } from '../libs/intlayer-api/fetcher';\n\nexport const useIntlayerAuth = (options?: FetcherOptions) => {\n const { csrfToken, oAuth2AccessToken } = useAuth();\n\n const headers = useMemo(\n () =>\n oAuth2AccessToken?.accessToken\n ? {\n Authorization: `Bearer ${oAuth2AccessToken.accessToken}`,\n }\n : undefined,\n [oAuth2AccessToken?.accessToken]\n );\n\n const body = useMemo(\n () => (csrfToken ? { csrf_token: csrfToken } : undefined),\n [csrfToken]\n );\n\n return useMemo(\n () =>\n getIntlayerAPI({\n headers,\n body,\n ...options,\n }),\n [body, headers]\n );\n};\n"],"names":["useAuth","useMemo","getIntlayerAPI"],"mappings":";;;;;AAKa,MAAA,kBAAkB,CAAC,YAA6B;AAC3D,QAAM,EAAE,WAAW,kBAAkB,IAAIA,8BAAQ,QAAA;AAEjD,QAAM,UAAUC,WAAA;AAAA,IACd,MACE,mBAAmB,cACf;AAAA,MACE,eAAe,UAAU,kBAAkB,WAAW;AAAA,IAExD,IAAA;AAAA,IACN,CAAC,mBAAmB,WAAW;AAAA,EAAA;AAGjC,QAAM,OAAOA,WAAA;AAAA,IACX,MAAO,YAAY,EAAE,YAAY,cAAc;AAAA,IAC/C,CAAC,SAAS;AAAA,EAAA;AAGL,SAAAA,WAAA;AAAA,IACL,MACEC,sCAAe;AAAA,MACb;AAAA,MACA;AAAA,MACA,GAAG;AAAA,IAAA,CACJ;AAAA,IACH,CAAC,MAAM,OAAO;AAAA,EAAA;AAElB;;"}
1
+ {"version":3,"file":"useIntlayerAPI.cjs","sources":["../../src/hooks/useIntlayerAPI.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport { useAuth } from '../components/Auth/useAuth';\nimport { getIntlayerAPI } from '../libs/intlayer-api';\nimport { FetcherOptions } from '../libs/intlayer-api/fetcher';\n\nexport const useIntlayerAuth = (options?: FetcherOptions) => {\n const { csrfToken, oAuth2AccessToken } = useAuth();\n\n const headers = useMemo(\n () =>\n oAuth2AccessToken?.accessToken\n ? {\n Authorization: `Bearer ${oAuth2AccessToken.accessToken}`,\n }\n : undefined,\n [oAuth2AccessToken?.accessToken]\n );\n\n const body = useMemo(\n () => (csrfToken ? { csrf_token: csrfToken } : undefined),\n [csrfToken]\n );\n\n return useMemo(\n () =>\n getIntlayerAPI({\n headers,\n body,\n ...options,\n }),\n [body, headers]\n );\n};\n"],"names":["useAuth","useMemo","getIntlayerAPI"],"mappings":";;;;;AAKa,MAAA,kBAAkB,CAAC,YAA6B;AAC3D,QAAM,EAAE,WAAW,kBAAkB,IAAIA,sCAAQ;AAEjD,QAAM,UAAUC,WAAA;AAAA,IACd,MACE,mBAAmB,cACf;AAAA,MACE,eAAe,UAAU,kBAAkB,WAAW;AAAA,IAExD,IAAA;AAAA,IACN,CAAC,mBAAmB,WAAW;AAAA,EACjC;AAEA,QAAM,OAAOA,WAAA;AAAA,IACX,MAAO,YAAY,EAAE,YAAY,cAAc;AAAA,IAC/C,CAAC,SAAS;AAAA,EACZ;AAEO,SAAAA,WAAA;AAAA,IACL,MACEC,sCAAe;AAAA,MACb;AAAA,MACA;AAAA,MACA,GAAG;AAAA,IAAA,CACJ;AAAA,IACH,CAAC,MAAM,OAAO;AAAA,EAChB;AACF;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useIntlayerAPI.mjs","sources":["../../src/hooks/useIntlayerAPI.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport { useAuth } from '../components/Auth/useAuth';\nimport { getIntlayerAPI } from '../libs/intlayer-api';\nimport { FetcherOptions } from '../libs/intlayer-api/fetcher';\n\nexport const useIntlayerAuth = (options?: FetcherOptions) => {\n const { csrfToken, oAuth2AccessToken } = useAuth();\n\n const headers = useMemo(\n () =>\n oAuth2AccessToken?.accessToken\n ? {\n Authorization: `Bearer ${oAuth2AccessToken.accessToken}`,\n }\n : undefined,\n [oAuth2AccessToken?.accessToken]\n );\n\n const body = useMemo(\n () => (csrfToken ? { csrf_token: csrfToken } : undefined),\n [csrfToken]\n );\n\n return useMemo(\n () =>\n getIntlayerAPI({\n headers,\n body,\n ...options,\n }),\n [body, headers]\n );\n};\n"],"names":[],"mappings":";;;AAKa,MAAA,kBAAkB,CAAC,YAA6B;AAC3D,QAAM,EAAE,WAAW,kBAAkB,IAAI,QAAQ;AAEjD,QAAM,UAAU;AAAA,IACd,MACE,mBAAmB,cACf;AAAA,MACE,eAAe,UAAU,kBAAkB,WAAW;AAAA,IAExD,IAAA;AAAA,IACN,CAAC,mBAAmB,WAAW;AAAA,EAAA;AAGjC,QAAM,OAAO;AAAA,IACX,MAAO,YAAY,EAAE,YAAY,cAAc;AAAA,IAC/C,CAAC,SAAS;AAAA,EAAA;AAGL,SAAA;AAAA,IACL,MACE,eAAe;AAAA,MACb;AAAA,MACA;AAAA,MACA,GAAG;AAAA,IAAA,CACJ;AAAA,IACH,CAAC,MAAM,OAAO;AAAA,EAAA;AAElB;"}
1
+ {"version":3,"file":"useIntlayerAPI.mjs","sources":["../../src/hooks/useIntlayerAPI.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport { useAuth } from '../components/Auth/useAuth';\nimport { getIntlayerAPI } from '../libs/intlayer-api';\nimport { FetcherOptions } from '../libs/intlayer-api/fetcher';\n\nexport const useIntlayerAuth = (options?: FetcherOptions) => {\n const { csrfToken, oAuth2AccessToken } = useAuth();\n\n const headers = useMemo(\n () =>\n oAuth2AccessToken?.accessToken\n ? {\n Authorization: `Bearer ${oAuth2AccessToken.accessToken}`,\n }\n : undefined,\n [oAuth2AccessToken?.accessToken]\n );\n\n const body = useMemo(\n () => (csrfToken ? { csrf_token: csrfToken } : undefined),\n [csrfToken]\n );\n\n return useMemo(\n () =>\n getIntlayerAPI({\n headers,\n body,\n ...options,\n }),\n [body, headers]\n );\n};\n"],"names":[],"mappings":";;;AAKa,MAAA,kBAAkB,CAAC,YAA6B;AAC3D,QAAM,EAAE,WAAW,kBAAkB,IAAI,QAAQ;AAEjD,QAAM,UAAU;AAAA,IACd,MACE,mBAAmB,cACf;AAAA,MACE,eAAe,UAAU,kBAAkB,WAAW;AAAA,IAExD,IAAA;AAAA,IACN,CAAC,mBAAmB,WAAW;AAAA,EACjC;AAEA,QAAM,OAAO;AAAA,IACX,MAAO,YAAY,EAAE,YAAY,cAAc;AAAA,IAC/C,CAAC,SAAS;AAAA,EACZ;AAEO,SAAA;AAAA,IACL,MACE,eAAe;AAAA,MACb;AAAA,MACA;AAAA,MACA,GAAG;AAAA,IAAA,CACJ;AAAA,IACH,CAAC,MAAM,OAAO;AAAA,EAChB;AACF;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useIsMounted.cjs","sources":["../../src/hooks/useIsMounted.ts"],"sourcesContent":["'use client';\n\nimport { useEffect, useState } from 'react';\n\nexport const useIsMounted = () => {\n const [isMounted, setIsMounted] = useState(false);\n\n useEffect(() => {\n setIsMounted(true);\n }, []);\n\n return isMounted;\n};\n"],"names":["useState","useEffect"],"mappings":";;;;AAIO,MAAM,eAAe,MAAM;AAChC,QAAM,CAAC,WAAW,YAAY,IAAIA,oBAAS,KAAK;AAEhDC,aAAAA,UAAU,MAAM;AACd,iBAAa,IAAI;AAAA,EACnB,GAAG,CAAE,CAAA;AAEE,SAAA;AACT;;"}
1
+ {"version":3,"file":"useIsMounted.cjs","sources":["../../src/hooks/useIsMounted.ts"],"sourcesContent":["'use client';\n\nimport { useEffect, useState } from 'react';\n\nexport const useIsMounted = () => {\n const [isMounted, setIsMounted] = useState(false);\n\n useEffect(() => {\n setIsMounted(true);\n }, []);\n\n return isMounted;\n};\n"],"names":["useState","useEffect"],"mappings":";;;;AAIO,MAAM,eAAe,MAAM;AAChC,QAAM,CAAC,WAAW,YAAY,IAAIA,WAAAA,SAAS,KAAK;AAEhDC,aAAAA,UAAU,MAAM;AACd,iBAAa,IAAI;AAAA,EACnB,GAAG,EAAE;AAEE,SAAA;AACT;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useIsMounted.mjs","sources":["../../src/hooks/useIsMounted.ts"],"sourcesContent":["'use client';\n\nimport { useEffect, useState } from 'react';\n\nexport const useIsMounted = () => {\n const [isMounted, setIsMounted] = useState(false);\n\n useEffect(() => {\n setIsMounted(true);\n }, []);\n\n return isMounted;\n};\n"],"names":[],"mappings":";;AAIO,MAAM,eAAe,MAAM;AAChC,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,KAAK;AAEhD,YAAU,MAAM;AACd,iBAAa,IAAI;AAAA,EACnB,GAAG,CAAE,CAAA;AAEE,SAAA;AACT;"}
1
+ {"version":3,"file":"useIsMounted.mjs","sources":["../../src/hooks/useIsMounted.ts"],"sourcesContent":["'use client';\n\nimport { useEffect, useState } from 'react';\n\nexport const useIsMounted = () => {\n const [isMounted, setIsMounted] = useState(false);\n\n useEffect(() => {\n setIsMounted(true);\n }, []);\n\n return isMounted;\n};\n"],"names":[],"mappings":";;AAIO,MAAM,eAAe,MAAM;AAChC,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,KAAK;AAEhD,YAAU,MAAM;AACd,iBAAa,IAAI;AAAA,EACnB,GAAG,EAAE;AAEE,SAAA;AACT;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useItemSelector.cjs","sources":["../../src/hooks/useItemSelector.ts"],"sourcesContent":["'use client';\n\nimport { useEffect, useState, type MutableRefObject } from 'react';\n\ntype StyleState = {\n left: number;\n width: number;\n opacity: number;\n};\n\nconst selectorDefault = (option: HTMLElement) =>\n option?.getAttribute('aria-selected') === 'true';\n\nexport const useItemSelector = (\n optionsRefs: MutableRefObject<HTMLElement[]>,\n selector: (option: HTMLElement, index: number) => boolean = selectorDefault,\n isHoverable = false\n) => {\n const [choiceIndicatorPosition, setChoiceIndicatorPosition] =\n useState<StyleState | null>(null);\n\n const [hoveredItem, setHoveredItem] = useState<HTMLElement | null>(null);\n\n const itemsLength = optionsRefs.current.length;\n\n useEffect(() => {\n const calculatePosition = () => {\n let targetElement: HTMLElement | null = null;\n\n if (hoveredItem) {\n targetElement = hoveredItem;\n } else {\n targetElement = optionsRefs.current.find(selector) ?? null;\n }\n\n if (!targetElement) {\n setChoiceIndicatorPosition((prev) => ({\n left: 0,\n width: 0,\n ...prev,\n opacity: 0,\n }));\n return;\n }\n\n const left = targetElement.offsetLeft;\n const width = targetElement.offsetWidth;\n\n setChoiceIndicatorPosition({\n left,\n width,\n opacity: 1,\n });\n };\n\n calculatePosition();\n\n // Event listeners for window events\n window.addEventListener('resize', calculatePosition);\n window.addEventListener('DOMContentLoaded', calculatePosition);\n\n // MutationObserver to watch for 'aria-selected' changes\n const mutationObservers: MutationObserver[] = [];\n\n optionsRefs.current.forEach((option) => {\n if (option) {\n const observer = new MutationObserver((mutations) => {\n for (const mutation of mutations) {\n if (\n mutation.type === 'attributes' &&\n mutation.attributeName === 'aria-selected'\n ) {\n calculatePosition();\n break;\n }\n }\n });\n\n observer.observe(option, {\n attributes: true,\n attributeFilter: ['aria-selected'],\n });\n\n mutationObservers.push(observer);\n }\n });\n\n // ResizeObserver to watch for size changes\n const resizeObservers: ResizeObserver[] = [];\n\n const observeSize = (element: HTMLElement) => {\n if (!element) return;\n const resizeObserver = new ResizeObserver(() => {\n calculatePosition();\n });\n resizeObserver.observe(element);\n resizeObservers.push(resizeObserver);\n };\n\n // Observe the selected item\n const selectedItem = optionsRefs.current.find(selector) ?? null;\n\n if (selectedItem) {\n observeSize(selectedItem);\n }\n\n // Observe the hovered item\n if (hoveredItem) {\n observeSize(hoveredItem);\n }\n\n // Add hover event listeners\n const handleMouseEnter = (event: Event) => {\n setHoveredItem(event.currentTarget as HTMLElement);\n };\n\n const handleMouseLeave = () => {\n setHoveredItem(null);\n };\n\n if (isHoverable) {\n optionsRefs.current.forEach((option) => {\n option?.addEventListener('mouseenter', handleMouseEnter);\n option?.addEventListener('mouseleave', handleMouseLeave);\n });\n }\n\n return () => {\n // Cleanup window event listeners\n window.removeEventListener('resize', calculatePosition);\n window.removeEventListener('DOMContentLoaded', calculatePosition);\n\n // Disconnect MutationObservers\n mutationObservers.forEach((observer) => observer.disconnect());\n\n // Disconnect ResizeObservers\n resizeObservers.forEach((observer) => observer.disconnect());\n\n // Remove hover event listeners\n optionsRefs.current.forEach((option) => {\n option?.removeEventListener('mouseenter', handleMouseEnter);\n option?.removeEventListener('mouseleave', handleMouseLeave);\n });\n };\n }, [optionsRefs, selector, hoveredItem, itemsLength]);\n\n return { choiceIndicatorPosition };\n};\n"],"names":["useState","useEffect"],"mappings":";;;;AAUA,MAAM,kBAAkB,CAAC,WACvB,QAAQ,aAAa,eA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AAC,QAAS;AACR,YAAA,iBAAiB,IAAI,eAAe,MAAM;AAC5B;MAAA,CACnB;AACD,qBAAe,QAAQ,OAAO;AAC9B,sBAAgB,KAAK,cAAc;AAAA,IAAA;AAIrC,UAAM,eAAe,YAAY,QAAQ,KAAK,QAAQ,KAAK;AAE3D,QAAI,cAAc;AAChB,kBAAY,YAAY;AAAA,IAC1B;AAGA,QAAI,aAAa;AACf,kBAAY,WAAW;AAAA,IACzB;AAGM,UAAA,mBAAmB,CAAC,UAAiB;AACzC,qBAAe,MAAM,aAA4B;AAAA,IAAA;AAGnD,UAAM,mBAAmB,MAAM;AAC7B,qBAAe,IAAI;AAAA,IAAA;AAGrB,QAAI,aAAa;AACH,kBAAA,QAAQ,QAAQ,CAAC,WAAW;AAC9B,gBAAA,iBAAiB,cAAc,gBAAgB;AAC/C,gBAAA,iBAAiB,cAAc,gBAAgB;AAAA,MAAA,CACxD;AAAA,IACH;AAEA,WAAO,MAAM;AAEJ,aAAA,oBAAoB,UAAU,iBAAiB;AAC/C,aAAA,oBAAoB,oBAAoB,iBAAiB;AAGhE,wBAAkB,QAAQ,CAAC,aAAa,SAAS,WAAY,CAAA;AAG7D,sBAAgB,QAAQ,CAAC,aAAa,SAAS,WAAY,CAAA;AAG/C,kBAAA,QAAQ,QAAQ,CAAC,WAAW;AAC9B,gBAAA,oBAAoB,cAAc,gBAAgB;AAClD,gBAAA,oBAAoB,cAAc,gBAAgB;AAAA,MAAA,CAC3D;AAAA,IAAA;AAAA,KAEF,CAAC,aAAa,UAAU,aAAa,WAAW,CAAC;AAEpD,SAAO,EAAE,wBAAwB;AACnC;;"}
1
+ {"version":3,"file":"useItemSelector.cjs","sources":["../../src/hooks/useItemSelector.ts"],"sourcesContent":["'use client';\n\nimport { useEffect, useState, type MutableRefObject } from 'react';\n\ntype StyleState = {\n left: number;\n width: number;\n opacity: number;\n};\n\nconst selectorDefault = (option: HTMLElement) =>\n option?.getAttribute('aria-selected') === 'true';\n\nexport const useItemSelector = (\n optionsRefs: MutableRefObject<HTMLElement[]>,\n selector: (option: HTMLElement, index: number) => boolean = selectorDefault,\n isHoverable = false\n) => {\n const [choiceIndicatorPosition, setChoiceIndicatorPosition] =\n useState<StyleState | null>(null);\n\n const [hoveredItem, setHoveredItem] = useState<HTMLElement | null>(null);\n\n const itemsLength = optionsRefs.current.length;\n\n useEffect(() => {\n const calculatePosition = () => {\n let targetElement: HTMLElement | null = null;\n\n if (hoveredItem) {\n targetElement = hoveredItem;\n } else {\n targetElement = optionsRefs.current.find(selector) ?? null;\n }\n\n if (!targetElement) {\n setChoiceIndicatorPosition((prev) => ({\n left: 0,\n width: 0,\n ...prev,\n opacity: 0,\n }));\n return;\n }\n\n const left = targetElement.offsetLeft;\n const width = targetElement.offsetWidth;\n\n setChoiceIndicatorPosition({\n left,\n width,\n opacity: 1,\n });\n };\n\n calculatePosition();\n\n // Event listeners for window events\n window.addEventListener('resize', calculatePosition);\n window.addEventListener('DOMContentLoaded', calculatePosition);\n\n // MutationObserver to watch for 'aria-selected' changes\n const mutationObservers: MutationObserver[] = [];\n\n optionsRefs.current.forEach((option) => {\n if (option) {\n const observer = new MutationObserver((mutations) => {\n for (const mutation of mutations) {\n if (\n mutation.type === 'attributes' &&\n mutation.attributeName === 'aria-selected'\n ) {\n calculatePosition();\n break;\n }\n }\n });\n\n observer.observe(option, {\n attributes: true,\n attributeFilter: ['aria-selected'],\n });\n\n mutationObservers.push(observer);\n }\n });\n\n // ResizeObserver to watch for size changes\n const resizeObservers: ResizeObserver[] = [];\n\n const observeSize = (element: HTMLElement) => {\n if (!element) return;\n const resizeObserver = new ResizeObserver(() => {\n calculatePosition();\n });\n resizeObserver.observe(element);\n resizeObservers.push(resizeObserver);\n };\n\n // Observe the selected item\n const selectedItem = optionsRefs.current.find(selector) ?? null;\n\n if (selectedItem) {\n observeSize(selectedItem);\n }\n\n // Observe the hovered item\n if (hoveredItem) {\n observeSize(hoveredItem);\n }\n\n // Add hover event listeners\n const handleMouseEnter = (event: Event) => {\n setHoveredItem(event.currentTarget as HTMLElement);\n };\n\n const handleMouseLeave = () => {\n setHoveredItem(null);\n };\n\n if (isHoverable) {\n optionsRefs.current.forEach((option) => {\n option?.addEventListener('mouseenter', handleMouseEnter);\n option?.addEventListener('mouseleave', handleMouseLeave);\n });\n }\n\n return () => {\n // Cleanup window event listeners\n window.removeEventListener('resize', calculatePosition);\n window.removeEventListener('DOMContentLoaded', calculatePosition);\n\n // Disconnect MutationObservers\n mutationObservers.forEach((observer) => observer.disconnect());\n\n // Disconnect ResizeObservers\n resizeObservers.forEach((observer) => observer.disconnect());\n\n // Remove hover event listeners\n optionsRefs.current.forEach((option) => {\n option?.removeEventListener('mouseenter', handleMouseEnter);\n option?.removeEventListener('mouseleave', handleMouseLeave);\n });\n };\n }, [optionsRefs, selector, hoveredItem, itemsLength]);\n\n return { choiceIndicatorPosition };\n};\n"],"names":["useState","useEffect"],"mappings":";;;;AAUA,MAAM,kBAAkB,CAAC,WACvB,QAAQ,aAAa,eAAe,MAAM;AAErC,MAAM,kBAAkB,CAC7B,aACA,WAA4D,iBAC5D,cAAc,UACX;AACH,QAAM,CAAC,yBAAyB,0BAA0B,IACxDA,WAAAA,SAA4B,IAAI;AAElC,QAAM,CAAC,aAAa,cAAc,IAAIA,WAAAA,SAA6B,IAAI;AAEjE,QAAA,cAAc,YAAY,QAAQ;AAExCC,aAAAA,UAAU,MAAM;AACd,UAAM,oBAAoB,MAAM;AAC9B,UAAI,gBAAoC;AAExC,UAAI,aAAa;AACC,wBAAA;AAAA,MAAA,OACX;AACL,wBAAgB,YAAY,QAAQ,KAAK,QAAQ,KAAK;AAAA,MAAA;AAGxD,UAAI,CAAC,eAAe;AAClB,mCAA2B,CAAC,UAAU;AAAA,UACpC,MAAM;AAAA,UACN,OAAO;AAAA,UACP,GAAG;AAAA,UACH,SAAS;AAAA,QAAA,EACT;AACF;AAAA,MAAA;AAGF,YAAM,OAAO,cAAc;AAC3B,YAAM,QAAQ,cAAc;AAED,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AA,IAAA;AAGH,WAAO,MAAM;AAEJ,aAAA,oBAAoB,UAAU,iBAAiB;AAC/C,aAAA,oBAAoB,oBAAoB,iBAAiB;AAGhE,wBAAkB,QAAQ,CAAC,aAAa,SAAS,YAAY;AAG7D,sBAAgB,QAAQ,CAAC,aAAa,SAAS,YAAY;AAG/C,kBAAA,QAAQ,QAAQ,CAAC,WAAW;AAC9B,gBAAA,oBAAoB,cAAc,gBAAgB;AAClD,gBAAA,oBAAoB,cAAc,gBAAgB;AAAA,MAAA,CAC3D;AAAA,IACH;AAAA,KACC,CAAC,aAAa,UAAU,aAAa,WAAW,CAAC;AAEpD,SAAO,EAAE,wBAAwB;AACnC;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useItemSelector.mjs","sources":["../../src/hooks/useItemSelector.ts"],"sourcesContent":["'use client';\n\nimport { useEffect, useState, type MutableRefObject } from 'react';\n\ntype StyleState = {\n left: number;\n width: number;\n opacity: number;\n};\n\nconst selectorDefault = (option: HTMLElement) =>\n option?.getAttribute('aria-selected') === 'true';\n\nexport const useItemSelector = (\n optionsRefs: MutableRefObject<HTMLElement[]>,\n selector: (option: HTMLElement, index: number) => boolean = selectorDefault,\n isHoverable = false\n) => {\n const [choiceIndicatorPosition, setChoiceIndicatorPosition] =\n useState<StyleState | null>(null);\n\n const [hoveredItem, setHoveredItem] = useState<HTMLElement | null>(null);\n\n const itemsLength = optionsRefs.current.length;\n\n useEffect(() => {\n const calculatePosition = () => {\n let targetElement: HTMLElement | null = null;\n\n if (hoveredItem) {\n targetElement = hoveredItem;\n } else {\n targetElement = optionsRefs.current.find(selector) ?? null;\n }\n\n if (!targetElement) {\n setChoiceIndicatorPosition((prev) => ({\n left: 0,\n width: 0,\n ...prev,\n opacity: 0,\n }));\n return;\n }\n\n const left = targetElement.offsetLeft;\n const width = targetElement.offsetWidth;\n\n setChoiceIndicatorPosition({\n left,\n width,\n opacity: 1,\n });\n };\n\n calculatePosition();\n\n // Event listeners for window events\n window.addEventListener('resize', calculatePosition);\n window.addEventListener('DOMContentLoaded', calculatePosition);\n\n // MutationObserver to watch for 'aria-selected' changes\n const mutationObservers: MutationObserver[] = [];\n\n optionsRefs.current.forEach((option) => {\n if (option) {\n const observer = new MutationObserver((mutations) => {\n for (const mutation of mutations) {\n if (\n mutation.type === 'attributes' &&\n mutation.attributeName === 'aria-selected'\n ) {\n calculatePosition();\n break;\n }\n }\n });\n\n observer.observe(option, {\n attributes: true,\n attributeFilter: ['aria-selected'],\n });\n\n mutationObservers.push(observer);\n }\n });\n\n // ResizeObserver to watch for size changes\n const resizeObservers: ResizeObserver[] = [];\n\n const observeSize = (element: HTMLElement) => {\n if (!element) return;\n const resizeObserver = new ResizeObserver(() => {\n calculatePosition();\n });\n resizeObserver.observe(element);\n resizeObservers.push(resizeObserver);\n };\n\n // Observe the selected item\n const selectedItem = optionsRefs.current.find(selector) ?? null;\n\n if (selectedItem) {\n observeSize(selectedItem);\n }\n\n // Observe the hovered item\n if (hoveredItem) {\n observeSize(hoveredItem);\n }\n\n // Add hover event listeners\n const handleMouseEnter = (event: Event) => {\n setHoveredItem(event.currentTarget as HTMLElement);\n };\n\n const handleMouseLeave = () => {\n setHoveredItem(null);\n };\n\n if (isHoverable) {\n optionsRefs.current.forEach((option) => {\n option?.addEventListener('mouseenter', handleMouseEnter);\n option?.addEventListener('mouseleave', handleMouseLeave);\n });\n }\n\n return () => {\n // Cleanup window event listeners\n window.removeEventListener('resize', calculatePosition);\n window.removeEventListener('DOMContentLoaded', calculatePosition);\n\n // Disconnect MutationObservers\n mutationObservers.forEach((observer) => observer.disconnect());\n\n // Disconnect ResizeObservers\n resizeObservers.forEach((observer) => observer.disconnect());\n\n // Remove hover event listeners\n optionsRefs.current.forEach((option) => {\n option?.removeEventListener('mouseenter', handleMouseEnter);\n option?.removeEventListener('mouseleave', handleMouseLeave);\n });\n };\n }, [optionsRefs, selector, hoveredItem, itemsLength]);\n\n return { choiceIndicatorPosition };\n};\n"],"names":[],"mappings":";;AAUA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c,CAAC,YAAyB;AAC5C,UAAI,CAAC,QAAS;AACR,YAAA,iBAAiB,IAAI,eAAe,MAAM;AAC5B;MAAA,CACnB;AACD,qBAAe,QAAQ,OAAO;AAC9B,sBAAgB,KAAK,cAAc;AAAA,IAAA;AAIrC,UAAM,eAAe,YAAY,QAAQ,KAAK,QAAQ,KAAK;AAE3D,QAAI,cAAc;AAChB,kBAAY,YAAY;AAAA,IAC1B;AAGA,QAAI,aAAa;AACf,kBAAY,WAAW;AAAA,IACzB;AAGM,UAAA,mBAAmB,CAAC,UAAiB;AACzC,qBAAe,MAAM,aAA4B;AAAA,IAAA;AAGnD,UAAM,mBAAmB,MAAM;AAC7B,qBAAe,IAAI;AAAA,IAAA;AAGrB,QAAI,aAAa;AACH,kBAAA,QAAQ,QAAQ,CAAC,WAAW;AAC9B,gBAAA,iBAAiB,cAAc,gBAAgB;AAC/C,gBAAA,iBAAiB,cAAc,gBAAgB;AAAA,MAAA,CACxD;AAAA,IACH;AAEA,WAAO,MAAM;AAEJ,aAAA,oBAAoB,UAAU,iBAAiB;AAC/C,aAAA,oBAAoB,oBAAoB,iBAAiB;AAGhE,wBAAkB,QAAQ,CAAC,aAAa,SAAS,WAAY,CAAA;AAG7D,sBAAgB,QAAQ,CAAC,aAAa,SAAS,WAAY,CAAA;AAG/C,kBAAA,QAAQ,QAAQ,CAAC,WAAW;AAC9B,gBAAA,oBAAoB,cAAc,gBAAgB;AAClD,gBAAA,oBAAoB,cAAc,gBAAgB;AAAA,MAAA,CAC3D;AAAA,IAAA;AAAA,KAEF,CAAC,aAAa,UAAU,aAAa,WAAW,CAAC;AAEpD,SAAO,EAAE,wBAAwB;AACnC;"}
1
+ {"version":3,"file":"useItemSelector.mjs","sources":["../../src/hooks/useItemSelector.ts"],"sourcesContent":["'use client';\n\nimport { useEffect, useState, type MutableRefObject } from 'react';\n\ntype StyleState = {\n left: number;\n width: number;\n opacity: number;\n};\n\nconst selectorDefault = (option: HTMLElement) =>\n option?.getAttribute('aria-selected') === 'true';\n\nexport const useItemSelector = (\n optionsRefs: MutableRefObject<HTMLElement[]>,\n selector: (option: HTMLElement, index: number) => boolean = selectorDefault,\n isHoverable = false\n) => {\n const [choiceIndicatorPosition, setChoiceIndicatorPosition] =\n useState<StyleState | null>(null);\n\n const [hoveredItem, setHoveredItem] = useState<HTMLElement | null>(null);\n\n const itemsLength = optionsRefs.current.length;\n\n useEffect(() => {\n const calculatePosition = () => {\n let targetElement: HTMLElement | null = null;\n\n if (hoveredItem) {\n targetElement = hoveredItem;\n } else {\n targetElement = optionsRefs.current.find(selector) ?? null;\n }\n\n if (!targetElement) {\n setChoiceIndicatorPosition((prev) => ({\n left: 0,\n width: 0,\n ...prev,\n opacity: 0,\n }));\n return;\n }\n\n const left = targetElement.offsetLeft;\n const width = targetElement.offsetWidth;\n\n setChoiceIndicatorPosition({\n left,\n width,\n opacity: 1,\n });\n };\n\n calculatePosition();\n\n // Event listeners for window events\n window.addEventListener('resize', calculatePosition);\n window.addEventListener('DOMContentLoaded', calculatePosition);\n\n // MutationObserver to watch for 'aria-selected' changes\n const mutationObservers: MutationObserver[] = [];\n\n optionsRefs.current.forEach((option) => {\n if (option) {\n const observer = new MutationObserver((mutations) => {\n for (const mutation of mutations) {\n if (\n mutation.type === 'attributes' &&\n mutation.attributeName === 'aria-selected'\n ) {\n calculatePosition();\n break;\n }\n }\n });\n\n observer.observe(option, {\n attributes: true,\n attributeFilter: ['aria-selected'],\n });\n\n mutationObservers.push(observer);\n }\n });\n\n // ResizeObserver to watch for size changes\n const resizeObservers: ResizeObserver[] = [];\n\n const observeSize = (element: HTMLElement) => {\n if (!element) return;\n const resizeObserver = new ResizeObserver(() => {\n calculatePosition();\n });\n resizeObserver.observe(element);\n resizeObservers.push(resizeObserver);\n };\n\n // Observe the selected item\n const selectedItem = optionsRefs.current.find(selector) ?? null;\n\n if (selectedItem) {\n observeSize(selectedItem);\n }\n\n // Observe the hovered item\n if (hoveredItem) {\n observeSize(hoveredItem);\n }\n\n // Add hover event listeners\n const handleMouseEnter = (event: Event) => {\n setHoveredItem(event.currentTarget as HTMLElement);\n };\n\n const handleMouseLeave = () => {\n setHoveredItem(null);\n };\n\n if (isHoverable) {\n optionsRefs.current.forEach((option) => {\n option?.addEventListener('mouseenter', handleMouseEnter);\n option?.addEventListener('mouseleave', handleMouseLeave);\n });\n }\n\n return () => {\n // Cleanup window event listeners\n window.removeEventListener('resize', calculatePosition);\n window.removeEventListener('DOMContentLoaded', calculatePosition);\n\n // Disconnect MutationObservers\n mutationObservers.forEach((observer) => observer.disconnect());\n\n // Disconnect ResizeObservers\n resizeObservers.forEach((observer) => observer.disconnect());\n\n // Remove hover event listeners\n optionsRefs.current.forEach((option) => {\n option?.removeEventListener('mouseenter', handleMouseEnter);\n option?.removeEventListener('mouseleave', handleMouseLeave);\n });\n };\n }, [optionsRefs, selector, hoveredItem, itemsLength]);\n\n return { choiceIndicatorPosition };\n};\n"],"names":[],"mappings":";;AAUA,MAAM,kBAAkB,CAAC,WACvB,QAAQ,aAAa,eAAe,MAAM;AAErC,MAAM,kBAAkB,CAC7B,aACA,WAA4D,iBAC5D,cAAc,UACX;AACH,QAAM,CAAC,yBAAyB,0BAA0B,IACxD,SAA4B,IAAI;AAElC,QAAM,CAAC,aAAa,cAAc,IAAI,SAA6B,IAAI;AAEjE,QAAA,cAAc,YAAY,QAAQ;AAExC,YAAU,MAAM;AACd,UAAM,oBAAoB,MAAM;AAC9B,UAAI,gBAAoC;AAExC,UAAI,aAAa;AACC,wBAAA;AAAA,MAAA,OACX;AACL,wBAAgB,YAAY,QAAQ,KAAK,QAAQ,KAAK;AAAA,MAAA;AAGxD,UAAI,CAAC,eAAe;AAClB,mCAA2B,CAAC,UAAU;AAAA,UACpC,MAAM;AAAA,UACN,OAAO;AAAA,UACP,GAAG;AAAA,UACH,SAAS;AAAA,QAAA,EACT;AACF;AAAA,MAAA;AAGF,YAAM,OAAO,cAAc;AAC3B,YAAM,QAAQ,cAAc;AAED,iCAAA;A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;AAGH,WAAO,MAAM;AAEJ,aAAA,oBAAoB,UAAU,iBAAiB;AAC/C,aAAA,oBAAoB,oBAAoB,iBAAiB;AAGhE,wBAAkB,QAAQ,CAAC,aAAa,SAAS,YAAY;AAG7D,sBAAgB,QAAQ,CAAC,aAAa,SAAS,YAAY;AAG/C,kBAAA,QAAQ,QAAQ,CAAC,WAAW;AAC9B,gBAAA,oBAAoB,cAAc,gBAAgB;AAClD,gBAAA,oBAAoB,cAAc,gBAAgB;AAAA,MAAA,CAC3D;AAAA,IACH;AAAA,KACC,CAAC,aAAa,UAAU,aAAa,WAAW,CAAC;AAEpD,SAAO,EAAE,wBAAwB;AACnC;"}
@@ -1 +1 @@
1
- {"version":3,"file":"usePersistedStore.cjs","sources":["../../src/hooks/usePersistedStore.ts"],"sourcesContent":["'use client';\n\nimport { useState, useEffect } from 'react';\n\nexport const usePersistedStore = <T>(key: string, initialValue?: T) => {\n const [state, setState] = useState<T>(() => {\n if (typeof window === 'undefined') return initialValue as T;\n\n const persistedState = sessionStorage?.getItem(key);\n\n if (persistedState) {\n return JSON.parse(persistedState);\n }\n\n return initialValue as T;\n });\n\n useEffect(() => {\n const persistedState = sessionStorage?.getItem(key);\n\n if (persistedState) {\n setState(JSON.parse(persistedState));\n }\n }, [key, initialValue]);\n\n return [state, setState] as const;\n};\n"],"names":["useState","useEffect"],"mappings":";;;;AAIa,MAAA,oBAAoB,CAAI,KAAa,iBAAqB;AACrE,QAAM,CAAC,OAAO,QAAQ,IAAIA,oBAAY,MAAM;AACtC,QAAA,OAAO,WAAW,YAAoB,QAAA;AAEpC,UAAA,iBAAiB,gBAAgB,QAAQ,GAAG;AAElD,QAAI,gBAAgB;AACX,aAAA,KAAK,MAAM,cAAc;AAAA,IAClC;AAEO,WAAA;AAAA,EAAA,CACR;AAEDC,aAAAA,UAAU,MAAM;AACR,UAAA,iBAAiB,gBAAgB,QAAQ,GAAG;AAElD,QAAI,gBAAgB;AACT,eAAA,KAAK,MAAM,cAAc,CAAC;AAAA,IACrC;AAAA,EAAA,GACC,CAAC,KAAK,YAAY,CAAC;AAEf,SAAA,CAAC,OAAO,QAAQ;AACzB;;"}
1
+ {"version":3,"file":"usePersistedStore.cjs","sources":["../../src/hooks/usePersistedStore.ts"],"sourcesContent":["'use client';\n\nimport { useState, useEffect } from 'react';\n\nexport const usePersistedStore = <T>(key: string, initialValue?: T) => {\n const [state, setState] = useState<T>(() => {\n if (typeof window === 'undefined') return initialValue as T;\n\n const persistedState = sessionStorage?.getItem(key);\n\n if (persistedState) {\n return JSON.parse(persistedState);\n }\n\n return initialValue as T;\n });\n\n useEffect(() => {\n const persistedState = sessionStorage?.getItem(key);\n\n if (persistedState) {\n setState(JSON.parse(persistedState));\n }\n }, [key, initialValue]);\n\n return [state, setState] as const;\n};\n"],"names":["useState","useEffect"],"mappings":";;;;AAIa,MAAA,oBAAoB,CAAI,KAAa,iBAAqB;AACrE,QAAM,CAAC,OAAO,QAAQ,IAAIA,oBAAY,MAAM;AACtC,QAAA,OAAO,WAAW,YAAoB,QAAA;AAEpC,UAAA,iBAAiB,gBAAgB,QAAQ,GAAG;AAElD,QAAI,gBAAgB;AACX,aAAA,KAAK,MAAM,cAAc;AAAA,IAAA;AAG3B,WAAA;AAAA,EAAA,CACR;AAEDC,aAAAA,UAAU,MAAM;AACR,UAAA,iBAAiB,gBAAgB,QAAQ,GAAG;AAElD,QAAI,gBAAgB;AACT,eAAA,KAAK,MAAM,cAAc,CAAC;AAAA,IAAA;AAAA,EACrC,GACC,CAAC,KAAK,YAAY,CAAC;AAEf,SAAA,CAAC,OAAO,QAAQ;AACzB;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"usePersistedStore.mjs","sources":["../../src/hooks/usePersistedStore.ts"],"sourcesContent":["'use client';\n\nimport { useState, useEffect } from 'react';\n\nexport const usePersistedStore = <T>(key: string, initialValue?: T) => {\n const [state, setState] = useState<T>(() => {\n if (typeof window === 'undefined') return initialValue as T;\n\n const persistedState = sessionStorage?.getItem(key);\n\n if (persistedState) {\n return JSON.parse(persistedState);\n }\n\n return initialValue as T;\n });\n\n useEffect(() => {\n const persistedState = sessionStorage?.getItem(key);\n\n if (persistedState) {\n setState(JSON.parse(persistedState));\n }\n }, [key, initialValue]);\n\n return [state, setState] as const;\n};\n"],"names":[],"mappings":";;AAIa,MAAA,oBAAoB,CAAI,KAAa,iBAAqB;AACrE,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAY,MAAM;AACtC,QAAA,OAAO,WAAW,YAAoB,QAAA;AAEpC,UAAA,iBAAiB,gBAAgB,QAAQ,GAAG;AAElD,QAAI,gBAAgB;AACX,aAAA,KAAK,MAAM,cAAc;AAAA,IAClC;AAEO,WAAA;AAAA,EAAA,CACR;AAED,YAAU,MAAM;AACR,UAAA,iBAAiB,gBAAgB,QAAQ,GAAG;AAElD,QAAI,gBAAgB;AACT,eAAA,KAAK,MAAM,cAAc,CAAC;AAAA,IACrC;AAAA,EAAA,GACC,CAAC,KAAK,YAAY,CAAC;AAEf,SAAA,CAAC,OAAO,QAAQ;AACzB;"}
1
+ {"version":3,"file":"usePersistedStore.mjs","sources":["../../src/hooks/usePersistedStore.ts"],"sourcesContent":["'use client';\n\nimport { useState, useEffect } from 'react';\n\nexport const usePersistedStore = <T>(key: string, initialValue?: T) => {\n const [state, setState] = useState<T>(() => {\n if (typeof window === 'undefined') return initialValue as T;\n\n const persistedState = sessionStorage?.getItem(key);\n\n if (persistedState) {\n return JSON.parse(persistedState);\n }\n\n return initialValue as T;\n });\n\n useEffect(() => {\n const persistedState = sessionStorage?.getItem(key);\n\n if (persistedState) {\n setState(JSON.parse(persistedState));\n }\n }, [key, initialValue]);\n\n return [state, setState] as const;\n};\n"],"names":[],"mappings":";;AAIa,MAAA,oBAAoB,CAAI,KAAa,iBAAqB;AACrE,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAY,MAAM;AACtC,QAAA,OAAO,WAAW,YAAoB,QAAA;AAEpC,UAAA,iBAAiB,gBAAgB,QAAQ,GAAG;AAElD,QAAI,gBAAgB;AACX,aAAA,KAAK,MAAM,cAAc;AAAA,IAAA;AAG3B,WAAA;AAAA,EAAA,CACR;AAED,YAAU,MAAM;AACR,UAAA,iBAAiB,gBAAgB,QAAQ,GAAG;AAElD,QAAI,gBAAgB;AACT,eAAA,KAAK,MAAM,cAAc,CAAC;AAAA,IAAA;AAAA,EACrC,GACC,CAAC,KAAK,YAAY,CAAC;AAEf,SAAA,CAAC,OAAO,QAAQ;AACzB;"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../../src/hooks/useScrollBlockage/index.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect } from 'react';\nimport { useShallow } from 'zustand/react/shallow';\nimport { useGetElementOrWindow } from '../useGetElementOrWindow';\n\nimport { useScrollBlockageStore } from './useScrollBlockageStore';\n\ntype useScrollBlockagePropsReadOnly = {\n disableScroll: undefined;\n key: undefined;\n element?: HTMLElement; // The element to block the scroll. If not defined, the window will be used\n};\n\ntype useScrollBlockageProps = {\n disableScroll: boolean;\n key: string; // The key to identify the blockage to avoid conflicts. Required if disableScroll is defined\n element?: HTMLElement; // The element to block the scroll. If not defined, the window will be used\n};\n\nexport const useScrollBlockage = (\n props?: useScrollBlockageProps | useScrollBlockagePropsReadOnly\n) => {\n const {\n disableScroll = false,\n element,\n key = 'unnamed_blocker',\n } = props ?? {};\n\n const { isElementScrollBlocked, addBlockage, removeBlockage } =\n useScrollBlockageStore(\n useShallow((s) => ({\n isElementScrollBlocked: s.isElementScrollBlocked,\n addBlockage: s.addBlockage,\n removeBlockage: s.removeBlockage,\n }))\n );\n\n const containerElement = useGetElementOrWindow(element);\n\n useEffect(() => {\n const el = element ?? window.document.body;\n\n if (disableScroll) {\n addBlockage(key, el);\n } else {\n removeBlockage(key, el);\n }\n }, [addBlockage, disableScroll, element, key, removeBlockage]);\n\n const isScrollBlocked = containerElement\n ? isElementScrollBlocked(containerElement)\n : false;\n\n return { isScrollBlocked };\n};\n"],"names":["useScrollBlockageStore","useShallow","useGetElementOrWindow","useEffect"],"mappings":";;;;;;;AAoBa,MAAA,oBAAoB,CAC/B,UACG;AACG,QAAA;AAAA,IACJ,gBAAgB;AAAA,IAChB;AAAA,IACA,MAAM;AAAA,EAAA,IACJ,SAAS,CAAA;AAEb,QAAM,EAAE,wBAAwB,aAAa,eAC3C,IAAAA,+CAAA;AAAA,IACEC,QAAA,WAAW,CAAC,OAAO;AAAA,MACjB,wBAAwB,EAAE;AAAA,MAC1B,aAAa,EAAE;AAAA,MACf,gBAAgB,EAAE;AAAA,IAAA,EAClB;AAAA,EAAA;AAGA,QAAA,mBAAmBC,kDAAsB,OAAO;AAEtDC,aAAAA,UAAU,MAAM;AACR,UAAA,KAAK,WAAW,OAAO,SAAS;AAEtC,QAAI,eAAe;AACjB,kBAAY,KAAK,EAAE;AAAA,IAAA,OACd;AACL,qBAAe,KAAK,EAAE;AAAA,IACxB;AAAA,EAAA,GACC,CAAC,aAAa,eAAe,SAAS,KAAK,cAAc,CAAC;AAE7D,QAAM,kBAAkB,mBACpB,uBAAuB,gBAAgB,IACvC;AAEJ,SAAO,EAAE,gBAAgB;AAC3B;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../../../src/hooks/useScrollBlockage/index.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect } from 'react';\nimport { useShallow } from 'zustand/react/shallow';\nimport { useGetElementOrWindow } from '../useGetElementOrWindow';\n\nimport { useScrollBlockageStore } from './useScrollBlockageStore';\n\ntype useScrollBlockagePropsReadOnly = {\n disableScroll: undefined;\n key: undefined;\n element?: HTMLElement; // The element to block the scroll. If not defined, the window will be used\n};\n\ntype useScrollBlockageProps = {\n disableScroll: boolean;\n key: string; // The key to identify the blockage to avoid conflicts. Required if disableScroll is defined\n element?: HTMLElement; // The element to block the scroll. If not defined, the window will be used\n};\n\nexport const useScrollBlockage = (\n props?: useScrollBlockageProps | useScrollBlockagePropsReadOnly\n) => {\n const {\n disableScroll = false,\n element,\n key = 'unnamed_blocker',\n } = props ?? {};\n\n const { isElementScrollBlocked, addBlockage, removeBlockage } =\n useScrollBlockageStore(\n useShallow((s) => ({\n isElementScrollBlocked: s.isElementScrollBlocked,\n addBlockage: s.addBlockage,\n removeBlockage: s.removeBlockage,\n }))\n );\n\n const containerElement = useGetElementOrWindow(element);\n\n useEffect(() => {\n const el = element ?? window.document.body;\n\n if (disableScroll) {\n addBlockage(key, el);\n } else {\n removeBlockage(key, el);\n }\n }, [addBlockage, disableScroll, element, key, removeBlockage]);\n\n const isScrollBlocked = containerElement\n ? isElementScrollBlocked(containerElement)\n : false;\n\n return { isScrollBlocked };\n};\n"],"names":["useScrollBlockageStore","useShallow","useGetElementOrWindow","useEffect"],"mappings":";;;;;;;AAoBa,MAAA,oBAAoB,CAC/B,UACG;AACG,QAAA;AAAA,IACJ,gBAAgB;AAAA,IAChB;AAAA,IACA,MAAM;AAAA,EACR,IAAI,SAAS,CAAC;AAEd,QAAM,EAAE,wBAAwB,aAAa,eAC3C,IAAAA,+CAAA;AAAA,IACEC,QAAA,WAAW,CAAC,OAAO;AAAA,MACjB,wBAAwB,EAAE;AAAA,MAC1B,aAAa,EAAE;AAAA,MACf,gBAAgB,EAAE;AAAA,IAAA,EAClB;AAAA,EACJ;AAEI,QAAA,mBAAmBC,kDAAsB,OAAO;AAEtDC,aAAAA,UAAU,MAAM;AACR,UAAA,KAAK,WAAW,OAAO,SAAS;AAEtC,QAAI,eAAe;AACjB,kBAAY,KAAK,EAAE;AAAA,IAAA,OACd;AACL,qBAAe,KAAK,EAAE;AAAA,IAAA;AAAA,EACxB,GACC,CAAC,aAAa,eAAe,SAAS,KAAK,cAAc,CAAC;AAE7D,QAAM,kBAAkB,mBACpB,uBAAuB,gBAAgB,IACvC;AAEJ,SAAO,EAAE,gBAAgB;AAC3B;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../../../src/hooks/useScrollBlockage/index.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect } from 'react';\nimport { useShallow } from 'zustand/react/shallow';\nimport { useGetElementOrWindow } from '../useGetElementOrWindow';\n\nimport { useScrollBlockageStore } from './useScrollBlockageStore';\n\ntype useScrollBlockagePropsReadOnly = {\n disableScroll: undefined;\n key: undefined;\n element?: HTMLElement; // The element to block the scroll. If not defined, the window will be used\n};\n\ntype useScrollBlockageProps = {\n disableScroll: boolean;\n key: string; // The key to identify the blockage to avoid conflicts. Required if disableScroll is defined\n element?: HTMLElement; // The element to block the scroll. If not defined, the window will be used\n};\n\nexport const useScrollBlockage = (\n props?: useScrollBlockageProps | useScrollBlockagePropsReadOnly\n) => {\n const {\n disableScroll = false,\n element,\n key = 'unnamed_blocker',\n } = props ?? {};\n\n const { isElementScrollBlocked, addBlockage, removeBlockage } =\n useScrollBlockageStore(\n useShallow((s) => ({\n isElementScrollBlocked: s.isElementScrollBlocked,\n addBlockage: s.addBlockage,\n removeBlockage: s.removeBlockage,\n }))\n );\n\n const containerElement = useGetElementOrWindow(element);\n\n useEffect(() => {\n const el = element ?? window.document.body;\n\n if (disableScroll) {\n addBlockage(key, el);\n } else {\n removeBlockage(key, el);\n }\n }, [addBlockage, disableScroll, element, key, removeBlockage]);\n\n const isScrollBlocked = containerElement\n ? isElementScrollBlocked(containerElement)\n : false;\n\n return { isScrollBlocked };\n};\n"],"names":[],"mappings":";;;;;AAoBa,MAAA,oBAAoB,CAC/B,UACG;AACG,QAAA;AAAA,IACJ,gBAAgB;AAAA,IAChB;AAAA,IACA,MAAM;AAAA,EAAA,IACJ,SAAS,CAAA;AAEb,QAAM,EAAE,wBAAwB,aAAa,eAC3C,IAAA;AAAA,IACE,WAAW,CAAC,OAAO;AAAA,MACjB,wBAAwB,EAAE;AAAA,MAC1B,aAAa,EAAE;AAAA,MACf,gBAAgB,EAAE;AAAA,IAAA,EAClB;AAAA,EAAA;AAGA,QAAA,mBAAmB,sBAAsB,OAAO;AAEtD,YAAU,MAAM;AACR,UAAA,KAAK,WAAW,OAAO,SAAS;AAEtC,QAAI,eAAe;AACjB,kBAAY,KAAK,EAAE;AAAA,IAAA,OACd;AACL,qBAAe,KAAK,EAAE;AAAA,IACxB;AAAA,EAAA,GACC,CAAC,aAAa,eAAe,SAAS,KAAK,cAAc,CAAC;AAE7D,QAAM,kBAAkB,mBACpB,uBAAuB,gBAAgB,IACvC;AAEJ,SAAO,EAAE,gBAAgB;AAC3B;"}
1
+ {"version":3,"file":"index.mjs","sources":["../../../src/hooks/useScrollBlockage/index.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect } from 'react';\nimport { useShallow } from 'zustand/react/shallow';\nimport { useGetElementOrWindow } from '../useGetElementOrWindow';\n\nimport { useScrollBlockageStore } from './useScrollBlockageStore';\n\ntype useScrollBlockagePropsReadOnly = {\n disableScroll: undefined;\n key: undefined;\n element?: HTMLElement; // The element to block the scroll. If not defined, the window will be used\n};\n\ntype useScrollBlockageProps = {\n disableScroll: boolean;\n key: string; // The key to identify the blockage to avoid conflicts. Required if disableScroll is defined\n element?: HTMLElement; // The element to block the scroll. If not defined, the window will be used\n};\n\nexport const useScrollBlockage = (\n props?: useScrollBlockageProps | useScrollBlockagePropsReadOnly\n) => {\n const {\n disableScroll = false,\n element,\n key = 'unnamed_blocker',\n } = props ?? {};\n\n const { isElementScrollBlocked, addBlockage, removeBlockage } =\n useScrollBlockageStore(\n useShallow((s) => ({\n isElementScrollBlocked: s.isElementScrollBlocked,\n addBlockage: s.addBlockage,\n removeBlockage: s.removeBlockage,\n }))\n );\n\n const containerElement = useGetElementOrWindow(element);\n\n useEffect(() => {\n const el = element ?? window.document.body;\n\n if (disableScroll) {\n addBlockage(key, el);\n } else {\n removeBlockage(key, el);\n }\n }, [addBlockage, disableScroll, element, key, removeBlockage]);\n\n const isScrollBlocked = containerElement\n ? isElementScrollBlocked(containerElement)\n : false;\n\n return { isScrollBlocked };\n};\n"],"names":[],"mappings":";;;;;AAoBa,MAAA,oBAAoB,CAC/B,UACG;AACG,QAAA;AAAA,IACJ,gBAAgB;AAAA,IAChB;AAAA,IACA,MAAM;AAAA,EACR,IAAI,SAAS,CAAC;AAEd,QAAM,EAAE,wBAAwB,aAAa,eAC3C,IAAA;AAAA,IACE,WAAW,CAAC,OAAO;AAAA,MACjB,wBAAwB,EAAE;AAAA,MAC1B,aAAa,EAAE;AAAA,MACf,gBAAgB,EAAE;AAAA,IAAA,EAClB;AAAA,EACJ;AAEI,QAAA,mBAAmB,sBAAsB,OAAO;AAEtD,YAAU,MAAM;AACR,UAAA,KAAK,WAAW,OAAO,SAAS;AAEtC,QAAI,eAAe;AACjB,kBAAY,KAAK,EAAE;AAAA,IAAA,OACd;AACL,qBAAe,KAAK,EAAE;AAAA,IAAA;AAAA,EACxB,GACC,CAAC,aAAa,eAAe,SAAS,KAAK,cAAc,CAAC;AAE7D,QAAM,kBAAkB,mBACpB,uBAAuB,gBAAgB,IACvC;AAEJ,SAAO,EAAE,gBAAgB;AAC3B;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useScrollBlockageStore.cjs","sources":["../../../src/hooks/useScrollBlockage/useScrollBlockageStore.ts"],"sourcesContent":["import { create } from 'zustand';\n\ntype Blocker = {\n element: Element;\n blockers: string[];\n};\n\ntype ScrollBlockageStore = {\n scrollBlockers: Blocker[];\n addBlockage: (blockerName: string, element: HTMLElement) => void;\n removeBlockage: (blockerName: string, element: HTMLElement) => void;\n isElementScrollBlocked: (element: HTMLElement) => boolean;\n};\n\nexport const useScrollBlockageStore = create<ScrollBlockageStore>(\n (set, get) => ({\n scrollBlockers: [],\n\n addBlockage: (blockerName: string, element: HTMLElement) =>\n set((state) => {\n const scrollBlockers = state.scrollBlockers;\n const blockersElement = scrollBlockers.find(\n (blocker) => blocker.element === element\n );\n\n if (blockersElement) {\n const isBlockerNameExist =\n blockersElement.blockers.includes(blockerName);\n\n const newBlockers = isBlockerNameExist\n ? blockersElement.blockers\n : [...blockersElement.blockers, blockerName];\n\n return {\n scrollBlockers: scrollBlockers.map((blocker) =>\n blocker.element === element\n ? { ...blocker, blockers: newBlockers }\n : blocker\n ),\n };\n }\n\n element.style.overflowY = 'hidden';\n element.style.overflowX = 'hidden';\n return {\n scrollBlockers: [\n ...scrollBlockers,\n { element, blockers: [blockerName] },\n ],\n };\n }),\n\n removeBlockage: (blockerName: string, element: HTMLElement) =>\n set((state) => {\n const scrollBlockers = state.scrollBlockers;\n const blocker = scrollBlockers.find(\n (blocker) => blocker.element === element\n );\n\n if (blocker) {\n // if there are more than one blocker, remove the blockerName from the list\n if (blocker.blockers.length > 1) {\n return {\n scrollBlockers: scrollBlockers.map((blocker) =>\n blocker.element === element\n ? {\n ...blocker,\n blockers: blocker.blockers.filter(\n (b) => b !== blockerName\n ),\n }\n : blocker\n ),\n };\n }\n\n // if there is only one blocker, remove the full blocker element\n element.style.overflowY = 'auto';\n return {\n scrollBlockers: scrollBlockers.filter(\n (blocker) => blocker.element !== element\n ),\n };\n }\n\n return {\n scrollBlockers,\n };\n }),\n\n isElementScrollBlocked: (element: HTMLElement) =>\n get().scrollBlockers.some((blocker) => blocker.element === element),\n })\n);\n"],"names":["create","blocker"],"mappings":";;;AAcO,MAAM,yBAAyBA,QAAA;AAAA,EACpC,CAAC,KAAK,SAAS;AAAA,IACb,gBAAgB,CAAC;AAAA,IAEjB,aAAa,CAAC,aAAqB,YACjC,IAAI,CAAC,UAAU;AACb,YAAM,iBAAiB,MAAM;AAC7B,YAAM,kBAAkB,eAAe;AAAA,QACrC,CAAC,YAAY,QAAQ,YAAY;AAAA,MAAA;AAGnC,UAAI,iBAAiB;AACnB,cAAM,qBACJ,gBAAgB,SAAS,SAAS,WAAW;AAEzC,cAAA,cAAc,qBAChB,gBAAgB,WAChB,CAAC,GAAG,gBAAgB,UAAU,WAAW;AAEtC,eAAA;AAAA,UACL,gBAAgB,eAAe;AAAA,YAAI,CAAC,YAClC,QAAQ,YAAY,UAChB,EAAE,GAAG,SAAS,UAAU,YAAA,IACxB;AAAA,UACN;AAAA,QAAA;AAAA,MAEJ;AAEA,cAAQ,MAAM,YAAY;AAC1B,cAAQ,MAAM,YAAY;AACnB,aAAA;AAAA,QACL,gBAAgB;AAAA,UACd,GAAG;AAAA,UACH,EAAE,SAAS,UAAU,CAAC,WAAW,EAAE;AAAA,QACrC;AAAA,MAAA;AAAA,IACF,CACD;AAAA,IAEH,gBAAgB,CAAC,aAAqB,YACpC,IAAI,CAAC,UAAU;AACb,YAAM,iBAAiB,MAAM;AAC7B,YAAM,UAAU,eAAe;AAAA,QAC7B,CAACC,aAAYA,SAAQ,YAAY;AAAA,MAAA;AAGnC,UAAI,SAAS;AAEP,YAAA,QAAQ,SAAS,SAAS,GAAG;AACxB,iBAAA;AAAA,YACL,gBAAgB,eAAe;AAAA,cAAI,CAACA,aAClCA,SAAQ,YAAY,UAChB;AAAA,gBACE,GAAGA;AAAAA,gBACH,UAAUA,SAAQ,SAAS;AAAA,kBACzB,CAAC,MAAM,MAAM;AAAA,gBACf;AAAA,cAAA,IAEFA;AAAAA,YACN;AAAA,UAAA;AAAA,QAEJ;AAGA,gBAAQ,MAAM,YAAY;AACnB,eAAA;AAAA,UACL,gBAAgB,eAAe;AAAA,YAC7B,CAACA,aAAYA,SAAQ,YAAY;AAAA,UACnC;AAAA,QAAA;AAAA,MAEJ;AAEO,aAAA;AAAA,QACL;AAAA,MAAA;AAAA,IACF,CACD;AAAA,IAEH,wBAAwB,CAAC,YACvB,IAAI,EAAE,eAAe,KAAK,CAAC,YAAY,QAAQ,YAAY,OAAO;AAAA,EAAA;AAExE;;"}
1
+ {"version":3,"file":"useScrollBlockageStore.cjs","sources":["../../../src/hooks/useScrollBlockage/useScrollBlockageStore.ts"],"sourcesContent":["import { create } from 'zustand';\n\ntype Blocker = {\n element: Element;\n blockers: string[];\n};\n\ntype ScrollBlockageStore = {\n scrollBlockers: Blocker[];\n addBlockage: (blockerName: string, element: HTMLElement) => void;\n removeBlockage: (blockerName: string, element: HTMLElement) => void;\n isElementScrollBlocked: (element: HTMLElement) => boolean;\n};\n\nexport const useScrollBlockageStore = create<ScrollBlockageStore>(\n (set, get) => ({\n scrollBlockers: [],\n\n addBlockage: (blockerName: string, element: HTMLElement) =>\n set((state) => {\n const scrollBlockers = state.scrollBlockers;\n const blockersElement = scrollBlockers.find(\n (blocker) => blocker.element === element\n );\n\n if (blockersElement) {\n const isBlockerNameExist =\n blockersElement.blockers.includes(blockerName);\n\n const newBlockers = isBlockerNameExist\n ? blockersElement.blockers\n : [...blockersElement.blockers, blockerName];\n\n return {\n scrollBlockers: scrollBlockers.map((blocker) =>\n blocker.element === element\n ? { ...blocker, blockers: newBlockers }\n : blocker\n ),\n };\n }\n\n element.style.overflowY = 'hidden';\n element.style.overflowX = 'hidden';\n return {\n scrollBlockers: [\n ...scrollBlockers,\n { element, blockers: [blockerName] },\n ],\n };\n }),\n\n removeBlockage: (blockerName: string, element: HTMLElement) =>\n set((state) => {\n const scrollBlockers = state.scrollBlockers;\n const blocker = scrollBlockers.find(\n (blocker) => blocker.element === element\n );\n\n if (blocker) {\n // if there are more than one blocker, remove the blockerName from the list\n if (blocker.blockers.length > 1) {\n return {\n scrollBlockers: scrollBlockers.map((blocker) =>\n blocker.element === element\n ? {\n ...blocker,\n blockers: blocker.blockers.filter(\n (b) => b !== blockerName\n ),\n }\n : blocker\n ),\n };\n }\n\n // if there is only one blocker, remove the full blocker element\n element.style.overflowY = 'auto';\n return {\n scrollBlockers: scrollBlockers.filter(\n (blocker) => blocker.element !== element\n ),\n };\n }\n\n return {\n scrollBlockers,\n };\n }),\n\n isElementScrollBlocked: (element: HTMLElement) =>\n get().scrollBlockers.some((blocker) => blocker.element === element),\n })\n);\n"],"names":["create","blocker"],"mappings":";;;AAcO,MAAM,yBAAyBA,QAAA;AAAA,EACpC,CAAC,KAAK,SAAS;AAAA,IACb,gBAAgB,CAAC;AAAA,IAEjB,aAAa,CAAC,aAAqB,YACjC,IAAI,CAAC,UAAU;AACb,YAAM,iBAAiB,MAAM;AAC7B,YAAM,kBAAkB,eAAe;AAAA,QACrC,CAAC,YAAY,QAAQ,Y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;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useScrollBlockageStore.mjs","sources":["../../../src/hooks/useScrollBlockage/useScrollBlockageStore.ts"],"sourcesContent":["import { create } from 'zustand';\n\ntype Blocker = {\n element: Element;\n blockers: string[];\n};\n\ntype ScrollBlockageStore = {\n scrollBlockers: Blocker[];\n addBlockage: (blockerName: string, element: HTMLElement) => void;\n removeBlockage: (blockerName: string, element: HTMLElement) => void;\n isElementScrollBlocked: (element: HTMLElement) => boolean;\n};\n\nexport const useScrollBlockageStore = create<ScrollBlockageStore>(\n (set, get) => ({\n scrollBlockers: [],\n\n addBlockage: (blockerName: string, element: HTMLElement) =>\n set((state) => {\n const scrollBlockers = state.scrollBlockers;\n const blockersElement = scrollBlockers.find(\n (blocker) => blocker.element === element\n );\n\n if (blockersElement) {\n const isBlockerNameExist =\n blockersElement.blockers.includes(blockerName);\n\n const newBlockers = isBlockerNameExist\n ? blockersElement.blockers\n : [...blockersElement.blockers, blockerName];\n\n return {\n scrollBlockers: scrollBlockers.map((blocker) =>\n blocker.element === element\n ? { ...blocker, blockers: newBlockers }\n : blocker\n ),\n };\n }\n\n element.style.overflowY = 'hidden';\n element.style.overflowX = 'hidden';\n return {\n scrollBlockers: [\n ...scrollBlockers,\n { element, blockers: [blockerName] },\n ],\n };\n }),\n\n removeBlockage: (blockerName: string, element: HTMLElement) =>\n set((state) => {\n const scrollBlockers = state.scrollBlockers;\n const blocker = scrollBlockers.find(\n (blocker) => blocker.element === element\n );\n\n if (blocker) {\n // if there are more than one blocker, remove the blockerName from the list\n if (blocker.blockers.length > 1) {\n return {\n scrollBlockers: scrollBlockers.map((blocker) =>\n blocker.element === element\n ? {\n ...blocker,\n blockers: blocker.blockers.filter(\n (b) => b !== blockerName\n ),\n }\n : blocker\n ),\n };\n }\n\n // if there is only one blocker, remove the full blocker element\n element.style.overflowY = 'auto';\n return {\n scrollBlockers: scrollBlockers.filter(\n (blocker) => blocker.element !== element\n ),\n };\n }\n\n return {\n scrollBlockers,\n };\n }),\n\n isElementScrollBlocked: (element: HTMLElement) =>\n get().scrollBlockers.some((blocker) => blocker.element === element),\n })\n);\n"],"names":["blocker"],"mappings":";AAcO,MAAM,yBAAyB;AAAA,EACpC,CAAC,KAAK,SAAS;AAAA,IACb,gBAAgB,CAAC;AAAA,IAEjB,aAAa,CAAC,aAAqB,YACjC,IAAI,CAAC,UAAU;AACb,YAAM,iBAAiB,MAAM;AAC7B,YAAM,kBAAkB,eAAe;AAAA,QACrC,CAAC,YAAY,QAAQ,YAAY;AAAA,MAAA;AAGnC,UAAI,iBAAiB;AACnB,cAAM,qBACJ,gBAAgB,SAAS,SAAS,WAAW;AAEzC,cAAA,cAAc,qBAChB,gBAAgB,WAChB,CAAC,GAAG,gBAAgB,UAAU,WAAW;AAEtC,eAAA;AAAA,UACL,gBAAgB,eAAe;AAAA,YAAI,CAAC,YAClC,QAAQ,YAAY,UAChB,EAAE,GAAG,SAAS,UAAU,YAAA,IACxB;AAAA,UACN;AAAA,QAAA;AAAA,MAEJ;AAEA,cAAQ,MAAM,YAAY;AAC1B,cAAQ,MAAM,YAAY;AACnB,aAAA;AAAA,QACL,gBAAgB;AAAA,UACd,GAAG;AAAA,UACH,EAAE,SAAS,UAAU,CAAC,WAAW,EAAE;AAAA,QACrC;AAAA,MAAA;AAAA,IACF,CACD;AAAA,IAEH,gBAAgB,CAAC,aAAqB,YACpC,IAAI,CAAC,UAAU;AACb,YAAM,iBAAiB,MAAM;AAC7B,YAAM,UAAU,eAAe;AAAA,QAC7B,CAACA,aAAYA,SAAQ,YAAY;AAAA,MAAA;AAGnC,UAAI,SAAS;AAEP,YAAA,QAAQ,SAAS,SAAS,GAAG;AACxB,iBAAA;AAAA,YACL,gBAAgB,eAAe;AAAA,cAAI,CAACA,aAClCA,SAAQ,YAAY,UAChB;AAAA,gBACE,GAAGA;AAAAA,gBACH,UAAUA,SAAQ,SAAS;AAAA,kBACzB,CAAC,MAAM,MAAM;AAAA,gBACf;AAAA,cAAA,IAEFA;AAAAA,YACN;AAAA,UAAA;AAAA,QAEJ;AAGA,gBAAQ,MAAM,YAAY;AACnB,eAAA;AAAA,UACL,gBAAgB,eAAe;AAAA,YAC7B,CAACA,aAAYA,SAAQ,YAAY;AAAA,UACnC;AAAA,QAAA;AAAA,MAEJ;AAEO,aAAA;AAAA,QACL;AAAA,MAAA;AAAA,IACF,CACD;AAAA,IAEH,wBAAwB,CAAC,YACvB,IAAI,EAAE,eAAe,KAAK,CAAC,YAAY,QAAQ,YAAY,OAAO;AAAA,EAAA;AAExE;"}
1
+ {"version":3,"file":"useScrollBlockageStore.mjs","sources":["../../../src/hooks/useScrollBlockage/useScrollBlockageStore.ts"],"sourcesContent":["import { create } from 'zustand';\n\ntype Blocker = {\n element: Element;\n blockers: string[];\n};\n\ntype ScrollBlockageStore = {\n scrollBlockers: Blocker[];\n addBlockage: (blockerName: string, element: HTMLElement) => void;\n removeBlockage: (blockerName: string, element: HTMLElement) => void;\n isElementScrollBlocked: (element: HTMLElement) => boolean;\n};\n\nexport const useScrollBlockageStore = create<ScrollBlockageStore>(\n (set, get) => ({\n scrollBlockers: [],\n\n addBlockage: (blockerName: string, element: HTMLElement) =>\n set((state) => {\n const scrollBlockers = state.scrollBlockers;\n const blockersElement = scrollBlockers.find(\n (blocker) => blocker.element === element\n );\n\n if (blockersElement) {\n const isBlockerNameExist =\n blockersElement.blockers.includes(blockerName);\n\n const newBlockers = isBlockerNameExist\n ? blockersElement.blockers\n : [...blockersElement.blockers, blockerName];\n\n return {\n scrollBlockers: scrollBlockers.map((blocker) =>\n blocker.element === element\n ? { ...blocker, blockers: newBlockers }\n : blocker\n ),\n };\n }\n\n element.style.overflowY = 'hidden';\n element.style.overflowX = 'hidden';\n return {\n scrollBlockers: [\n ...scrollBlockers,\n { element, blockers: [blockerName] },\n ],\n };\n }),\n\n removeBlockage: (blockerName: string, element: HTMLElement) =>\n set((state) => {\n const scrollBlockers = state.scrollBlockers;\n const blocker = scrollBlockers.find(\n (blocker) => blocker.element === element\n );\n\n if (blocker) {\n // if there are more than one blocker, remove the blockerName from the list\n if (blocker.blockers.length > 1) {\n return {\n scrollBlockers: scrollBlockers.map((blocker) =>\n blocker.element === element\n ? {\n ...blocker,\n blockers: blocker.blockers.filter(\n (b) => b !== blockerName\n ),\n }\n : blocker\n ),\n };\n }\n\n // if there is only one blocker, remove the full blocker element\n element.style.overflowY = 'auto';\n return {\n scrollBlockers: scrollBlockers.filter(\n (blocker) => blocker.element !== element\n ),\n };\n }\n\n return {\n scrollBlockers,\n };\n }),\n\n isElementScrollBlocked: (element: HTMLElement) =>\n get().scrollBlockers.some((blocker) => blocker.element === element),\n })\n);\n"],"names":["blocker"],"mappings":";AAcO,MAAM,yBAAyB;AAAA,EACpC,CAAC,KAAK,SAAS;AAAA,IACb,gBAAgB,CAAC;AAAA,IAEjB,aAAa,CAAC,aAAqB,YACjC,IAAI,CAAC,UAAU;AACb,YAAM,iBAAiB,MAAM;AAC7B,YAAM,kBAAkB,eAAe;AAAA,QACrC,CAAC,YAAY,QAAQ,YAAY;AAAA,MACnC;AAEA,UAAI,iBAAiB;AACnB,cAAM,qBACJ,gBAAgB,SAAS,SAAS,WAAW;AAEzC,cAAA,cAAc,qBAChB,gBAAgB,WAChB,CAAC,GAAG,gBAAgB,UAAU,WAAW;AAEtC,eAAA;AAAA,UACL,gBAAgB,eAAe;AAAA,YAAI,CAAC,YAClC,QAAQ,YAAY,UAChB,EAAE,GAAG,SAAS,UAAU,gBACxB;AAAA,UAAA;AAAA,QAER;AAAA,MAAA;AAGF,cAAQ,MAAM,YAAY;AAC1B,cAAQ,MAAM,YAAY;AACnB,aAAA;AAAA,QACL,gBAAgB;AAAA,UACd,GAAG;AAAA,UACH,EAAE,SAAS,UAAU,CAAC,WAAW,EAAE;AAAA,QAAA;AAAA,MAEvC;AAAA,IAAA,CACD;AAAA,IAEH,gBAAgB,CAAC,aAAqB,YACpC,IAAI,CAAC,UAAU;AACb,YAAM,iBAAiB,MAAM;AAC7B,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