@siberiacancode/reactuse 0.2.24 → 0.2.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/helpers/createStore/createStore.cjs +1 -1
- package/dist/cjs/helpers/createStore/createStore.cjs.map +1 -1
- package/dist/cjs/hooks/useActiveElement/useActiveElement.cjs +1 -1
- package/dist/cjs/hooks/useActiveElement/useActiveElement.cjs.map +1 -1
- package/dist/cjs/hooks/useAsync/useAsync.cjs.map +1 -1
- package/dist/cjs/hooks/useAutoScroll/useAutoScroll.cjs +1 -1
- package/dist/cjs/hooks/useAutoScroll/useAutoScroll.cjs.map +1 -1
- package/dist/cjs/hooks/useBoolean/useBoolean.cjs.map +1 -1
- package/dist/cjs/hooks/useBrowserLanguage/useBrowserLanguage.cjs.map +1 -1
- package/dist/cjs/hooks/useClickOutside/useClickOutside.cjs.map +1 -1
- package/dist/cjs/hooks/useCookie/useCookie.cjs.map +1 -1
- package/dist/cjs/hooks/useCookies/useCookies.cjs.map +1 -1
- package/dist/cjs/hooks/useCounter/useCounter.cjs.map +1 -1
- package/dist/cjs/hooks/useCssVar/useCssVar.cjs +1 -1
- package/dist/cjs/hooks/useCssVar/useCssVar.cjs.map +1 -1
- package/dist/cjs/hooks/useDefault/useDefault.cjs.map +1 -1
- package/dist/cjs/hooks/useDisclosure/useDisclosure.cjs.map +1 -1
- package/dist/cjs/hooks/useDisplayMedia/useDisplayMedia.cjs.map +1 -1
- package/dist/cjs/hooks/useDocumentTitle/useDocumentTitle.cjs.map +1 -1
- package/dist/cjs/hooks/useDoubleClick/useDoubleClick.cjs.map +1 -1
- package/dist/cjs/hooks/useElementSize/useElementSize.cjs.map +1 -1
- package/dist/cjs/hooks/useEvent/useEvent.cjs.map +1 -1
- package/dist/cjs/hooks/useEventSource/useEventSource.cjs.map +1 -1
- package/dist/cjs/hooks/useField/useField.cjs.map +1 -1
- package/dist/cjs/hooks/useFileDialog/useFileDialog.cjs.map +1 -1
- package/dist/cjs/hooks/useFocus/useFocus.cjs.map +1 -1
- package/dist/cjs/hooks/useFps/useFps.cjs.map +1 -1
- package/dist/cjs/hooks/useHash/useHash.cjs.map +1 -1
- package/dist/cjs/hooks/useHover/useHover.cjs.map +1 -1
- package/dist/cjs/hooks/useImage/useImage.cjs.map +1 -1
- package/dist/cjs/hooks/useInfiniteScroll/useInfiniteScroll.cjs +1 -1
- package/dist/cjs/hooks/useInfiniteScroll/useInfiniteScroll.cjs.map +1 -1
- package/dist/cjs/hooks/useIntersectionObserver/useIntersectionObserver.cjs +1 -1
- package/dist/cjs/hooks/useIntersectionObserver/useIntersectionObserver.cjs.map +1 -1
- package/dist/cjs/hooks/useLastChanged/useLastChanged.cjs.map +1 -1
- package/dist/cjs/hooks/useList/useList.cjs.map +1 -1
- package/dist/cjs/hooks/useLocalStorage/useLocalStorage.cjs.map +1 -1
- package/dist/cjs/hooks/useLockCallback/useLockCallback.cjs.map +1 -1
- package/dist/cjs/hooks/useLockScroll/useLockScroll.cjs +2 -0
- package/dist/cjs/hooks/useLockScroll/useLockScroll.cjs.map +1 -0
- package/dist/cjs/hooks/useLogger/useLogger.cjs.map +1 -1
- package/dist/cjs/hooks/useLongPress/useLongPress.cjs.map +1 -1
- package/dist/cjs/hooks/useMap/useMap.cjs.map +1 -1
- package/dist/cjs/hooks/useMutation/useMutation.cjs.map +1 -1
- package/dist/cjs/hooks/useMutationObserver/useMutationObserver.cjs.map +1 -1
- package/dist/cjs/hooks/useNetwork/useNetwork.cjs.map +1 -1
- package/dist/cjs/hooks/useOffsetPagination/useOffsetPagination.cjs.map +1 -1
- package/dist/cjs/hooks/useOnline/useOnline.cjs.map +1 -1
- package/dist/cjs/hooks/useOperatingSystem/useOperatingSystem.cjs.map +1 -1
- package/dist/cjs/hooks/useOptimistic/useOptimistic.cjs.map +1 -1
- package/dist/cjs/hooks/useOrientation/useOrientation.cjs +1 -1
- package/dist/cjs/hooks/useOrientation/useOrientation.cjs.map +1 -1
- package/dist/cjs/hooks/usePaint/usePaint.cjs.map +1 -1
- package/dist/cjs/hooks/useParallax/useParallax.cjs +1 -1
- package/dist/cjs/hooks/useParallax/useParallax.cjs.map +1 -1
- package/dist/cjs/hooks/usePointerLock/usePointerLock.cjs.map +1 -1
- package/dist/cjs/hooks/usePreferredColorScheme/usePreferredColorScheme.cjs.map +1 -1
- package/dist/cjs/hooks/usePreferredContrast/usePreferredContrast.cjs.map +1 -1
- package/dist/cjs/hooks/usePreferredDark/usePreferredDark.cjs.map +1 -1
- package/dist/cjs/hooks/usePreferredLanguages/usePreferredLanguages.cjs.map +1 -1
- package/dist/cjs/hooks/usePreferredReducedMotion/usePreferredReducedMotion.cjs.map +1 -1
- package/dist/cjs/hooks/useQuery/useQuery.cjs.map +1 -1
- package/dist/cjs/hooks/useQueue/useQueue.cjs.map +1 -1
- package/dist/cjs/hooks/useRaf/useRaf.cjs.map +1 -1
- package/dist/cjs/hooks/{useRafValue/useRafValue.cjs → useRafState/useRafState.cjs} +2 -2
- package/dist/cjs/hooks/useRafState/useRafState.cjs.map +1 -0
- package/dist/cjs/hooks/useRefState/useRefState.cjs.map +1 -1
- package/dist/cjs/hooks/useRenderCount/useRenderCount.cjs.map +1 -1
- package/dist/cjs/hooks/useRenderInfo/useRenderInfo.cjs.map +1 -1
- package/dist/cjs/hooks/useRerender/useRerender.cjs.map +1 -1
- package/dist/cjs/hooks/useResizeObserver/useResizeObserver.cjs.map +1 -1
- package/dist/cjs/hooks/useScript/useScript.cjs.map +1 -1
- package/dist/cjs/hooks/useScroll/useScroll.cjs.map +1 -1
- package/dist/cjs/hooks/useSessionStorage/useSessionStorage.cjs.map +1 -1
- package/dist/cjs/hooks/useSet/useSet.cjs.map +1 -1
- package/dist/cjs/hooks/useSpeechRecognition/useSpeechRecognition.cjs.map +1 -1
- package/dist/cjs/hooks/useSpeechSynthesis/useSpeechSynthesis.cjs.map +1 -1
- package/dist/cjs/hooks/useStateHistory/useStateHistory.cjs.map +1 -1
- package/dist/cjs/hooks/useStep/useStep.cjs.map +1 -1
- package/dist/cjs/hooks/useSticky/useSticky.cjs.map +1 -1
- package/dist/cjs/hooks/useStopwatch/useStopwatch.cjs +1 -1
- package/dist/cjs/hooks/useStopwatch/useStopwatch.cjs.map +1 -1
- package/dist/cjs/hooks/useStorage/useStorage.cjs.map +1 -1
- package/dist/cjs/hooks/useTextDirection/useTextDirection.cjs +1 -1
- package/dist/cjs/hooks/useTextDirection/useTextDirection.cjs.map +1 -1
- package/dist/cjs/hooks/useToggle/useToggle.cjs.map +1 -1
- package/dist/cjs/hooks/useUrlSearchParam/useUrlSearchParam.cjs.map +1 -1
- package/dist/cjs/hooks/useUrlSearchParams/useUrlSearchParams.cjs.map +1 -1
- package/dist/cjs/hooks/useWindowEvent/useWindowEvent.cjs.map +1 -1
- package/dist/cjs/hooks/useWizard/useWizard.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/esm/helpers/createStore/createStore.mjs +16 -16
- package/dist/esm/helpers/createStore/createStore.mjs.map +1 -1
- package/dist/esm/hooks/useActiveElement/useActiveElement.mjs +22 -17
- package/dist/esm/hooks/useActiveElement/useActiveElement.mjs.map +1 -1
- package/dist/esm/hooks/useAsync/useAsync.mjs.map +1 -1
- package/dist/esm/hooks/useAutoScroll/useAutoScroll.mjs +38 -29
- package/dist/esm/hooks/useAutoScroll/useAutoScroll.mjs.map +1 -1
- package/dist/esm/hooks/useBoolean/useBoolean.mjs.map +1 -1
- package/dist/esm/hooks/useBrowserLanguage/useBrowserLanguage.mjs.map +1 -1
- package/dist/esm/hooks/useClickOutside/useClickOutside.mjs.map +1 -1
- package/dist/esm/hooks/useCookie/useCookie.mjs.map +1 -1
- package/dist/esm/hooks/useCookies/useCookies.mjs.map +1 -1
- package/dist/esm/hooks/useCounter/useCounter.mjs.map +1 -1
- package/dist/esm/hooks/useCssVar/useCssVar.mjs +27 -24
- package/dist/esm/hooks/useCssVar/useCssVar.mjs.map +1 -1
- package/dist/esm/hooks/useDefault/useDefault.mjs.map +1 -1
- package/dist/esm/hooks/useDisclosure/useDisclosure.mjs.map +1 -1
- package/dist/esm/hooks/useDisplayMedia/useDisplayMedia.mjs.map +1 -1
- package/dist/esm/hooks/useDocumentTitle/useDocumentTitle.mjs +3 -1
- package/dist/esm/hooks/useDocumentTitle/useDocumentTitle.mjs.map +1 -1
- package/dist/esm/hooks/useDoubleClick/useDoubleClick.mjs.map +1 -1
- package/dist/esm/hooks/useElementSize/useElementSize.mjs.map +1 -1
- package/dist/esm/hooks/useEvent/useEvent.mjs.map +1 -1
- package/dist/esm/hooks/useEventSource/useEventSource.mjs +3 -1
- package/dist/esm/hooks/useEventSource/useEventSource.mjs.map +1 -1
- package/dist/esm/hooks/useField/useField.mjs.map +1 -1
- package/dist/esm/hooks/useFileDialog/useFileDialog.mjs.map +1 -1
- package/dist/esm/hooks/useFocus/useFocus.mjs.map +1 -1
- package/dist/esm/hooks/useFps/useFps.mjs.map +1 -1
- package/dist/esm/hooks/useHash/useHash.mjs.map +1 -1
- package/dist/esm/hooks/useHover/useHover.mjs.map +1 -1
- package/dist/esm/hooks/useImage/useImage.mjs.map +1 -1
- package/dist/esm/hooks/useInfiniteScroll/useInfiniteScroll.mjs +27 -27
- package/dist/esm/hooks/useInfiniteScroll/useInfiniteScroll.mjs.map +1 -1
- package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs +5 -5
- package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs.map +1 -1
- package/dist/esm/hooks/useLastChanged/useLastChanged.mjs.map +1 -1
- package/dist/esm/hooks/useList/useList.mjs +15 -6
- package/dist/esm/hooks/useList/useList.mjs.map +1 -1
- package/dist/esm/hooks/useLocalStorage/useLocalStorage.mjs.map +1 -1
- package/dist/esm/hooks/useLockCallback/useLockCallback.mjs.map +1 -1
- package/dist/esm/hooks/useLockScroll/useLockScroll.mjs +44 -0
- package/dist/esm/hooks/useLockScroll/useLockScroll.mjs.map +1 -0
- package/dist/esm/hooks/useLogger/useLogger.mjs.map +1 -1
- package/dist/esm/hooks/useLongPress/useLongPress.mjs.map +1 -1
- package/dist/esm/hooks/useMap/useMap.mjs.map +1 -1
- package/dist/esm/hooks/useMutation/useMutation.mjs.map +1 -1
- package/dist/esm/hooks/useMutationObserver/useMutationObserver.mjs.map +1 -1
- package/dist/esm/hooks/useNetwork/useNetwork.mjs.map +1 -1
- package/dist/esm/hooks/useOffsetPagination/useOffsetPagination.mjs.map +1 -1
- package/dist/esm/hooks/useOnline/useOnline.mjs.map +1 -1
- package/dist/esm/hooks/useOperatingSystem/useOperatingSystem.mjs.map +1 -1
- package/dist/esm/hooks/useOptimistic/useOptimistic.mjs.map +1 -1
- package/dist/esm/hooks/useOrientation/useOrientation.mjs +25 -9
- package/dist/esm/hooks/useOrientation/useOrientation.mjs.map +1 -1
- package/dist/esm/hooks/usePaint/usePaint.mjs +14 -2
- package/dist/esm/hooks/usePaint/usePaint.mjs.map +1 -1
- package/dist/esm/hooks/useParallax/useParallax.mjs +9 -9
- package/dist/esm/hooks/useParallax/useParallax.mjs.map +1 -1
- package/dist/esm/hooks/usePointerLock/usePointerLock.mjs.map +1 -1
- package/dist/esm/hooks/usePreferredColorScheme/usePreferredColorScheme.mjs.map +1 -1
- package/dist/esm/hooks/usePreferredContrast/usePreferredContrast.mjs.map +1 -1
- package/dist/esm/hooks/usePreferredDark/usePreferredDark.mjs.map +1 -1
- package/dist/esm/hooks/usePreferredLanguages/usePreferredLanguages.mjs.map +1 -1
- package/dist/esm/hooks/usePreferredReducedMotion/usePreferredReducedMotion.mjs.map +1 -1
- package/dist/esm/hooks/useQuery/useQuery.mjs.map +1 -1
- package/dist/esm/hooks/useQueue/useQueue.mjs.map +1 -1
- package/dist/esm/hooks/useRaf/useRaf.mjs.map +1 -1
- package/dist/esm/hooks/{useRafValue/useRafValue.mjs → useRafState/useRafState.mjs} +2 -2
- package/dist/esm/hooks/useRafState/useRafState.mjs.map +1 -0
- package/dist/esm/hooks/useRefState/useRefState.mjs.map +1 -1
- package/dist/esm/hooks/useRenderCount/useRenderCount.mjs.map +1 -1
- package/dist/esm/hooks/useRenderInfo/useRenderInfo.mjs.map +1 -1
- package/dist/esm/hooks/useRerender/useRerender.mjs.map +1 -1
- package/dist/esm/hooks/useResizeObserver/useResizeObserver.mjs.map +1 -1
- package/dist/esm/hooks/useScript/useScript.mjs.map +1 -1
- package/dist/esm/hooks/useScroll/useScroll.mjs.map +1 -1
- package/dist/esm/hooks/useSessionStorage/useSessionStorage.mjs.map +1 -1
- package/dist/esm/hooks/useSet/useSet.mjs.map +1 -1
- package/dist/esm/hooks/useSpeechRecognition/useSpeechRecognition.mjs +14 -4
- package/dist/esm/hooks/useSpeechRecognition/useSpeechRecognition.mjs.map +1 -1
- package/dist/esm/hooks/useSpeechSynthesis/useSpeechSynthesis.mjs.map +1 -1
- package/dist/esm/hooks/useStateHistory/useStateHistory.mjs.map +1 -1
- package/dist/esm/hooks/useStep/useStep.mjs.map +1 -1
- package/dist/esm/hooks/useSticky/useSticky.mjs.map +1 -1
- package/dist/esm/hooks/useStopwatch/useStopwatch.mjs +18 -18
- package/dist/esm/hooks/useStopwatch/useStopwatch.mjs.map +1 -1
- package/dist/esm/hooks/useStorage/useStorage.mjs.map +1 -1
- package/dist/esm/hooks/useTextDirection/useTextDirection.mjs +19 -20
- package/dist/esm/hooks/useTextDirection/useTextDirection.mjs.map +1 -1
- package/dist/esm/hooks/useToggle/useToggle.mjs.map +1 -1
- package/dist/esm/hooks/useUrlSearchParam/useUrlSearchParam.mjs.map +1 -1
- package/dist/esm/hooks/useUrlSearchParams/useUrlSearchParams.mjs.map +1 -1
- package/dist/esm/hooks/useWindowEvent/useWindowEvent.mjs.map +1 -1
- package/dist/esm/hooks/useWizard/useWizard.mjs.map +1 -1
- package/dist/esm/index.mjs +323 -323
- package/dist/types/helpers/createStore/createStore.d.ts +1 -1
- package/dist/types/hooks/async.d.ts +5 -0
- package/dist/types/hooks/browser.d.ts +32 -0
- package/dist/types/hooks/debug.d.ts +4 -0
- package/dist/types/hooks/elements.d.ts +14 -0
- package/dist/types/hooks/fun.d.ts +3 -0
- package/dist/types/hooks/index.d.ts +11 -143
- package/dist/types/hooks/lifecycle.d.ts +6 -0
- package/dist/types/hooks/sensors.d.ts +34 -0
- package/dist/types/hooks/state.d.ts +25 -0
- package/dist/types/hooks/time.d.ts +5 -0
- package/dist/types/hooks/useActiveElement/useActiveElement.d.ts +21 -2
- package/dist/types/hooks/useAsync/useAsync.d.ts +1 -1
- package/dist/types/hooks/useAutoScroll/useAutoScroll.d.ts +3 -1
- package/dist/types/hooks/useBoolean/useBoolean.d.ts +1 -1
- package/dist/types/hooks/useBrowserLanguage/useBrowserLanguage.d.ts +1 -1
- package/dist/types/hooks/useClickOutside/useClickOutside.d.ts +1 -1
- package/dist/types/hooks/useCookie/useCookie.d.ts +1 -1
- package/dist/types/hooks/useCookies/useCookies.d.ts +1 -1
- package/dist/types/hooks/useCounter/useCounter.d.ts +1 -1
- package/dist/types/hooks/useCssVar/useCssVar.d.ts +1 -1
- package/dist/types/hooks/useDefault/useDefault.d.ts +1 -1
- package/dist/types/hooks/useDisclosure/useDisclosure.d.ts +1 -1
- package/dist/types/hooks/useDocumentTitle/useDocumentTitle.d.ts +2 -0
- package/dist/types/hooks/useDoubleClick/useDoubleClick.d.ts +1 -1
- package/dist/types/hooks/useEvent/useEvent.d.ts +1 -1
- package/dist/types/hooks/useField/useField.d.ts +1 -1
- package/dist/types/hooks/useFileDialog/useFileDialog.d.ts +1 -1
- package/dist/types/hooks/useFocus/useFocus.d.ts +1 -1
- package/dist/types/hooks/useFps/useFps.d.ts +1 -1
- package/dist/types/hooks/useHash/useHash.d.ts +1 -1
- package/dist/types/hooks/useHover/useHover.d.ts +1 -1
- package/dist/types/hooks/useImage/useImage.d.ts +1 -1
- package/dist/types/hooks/useIntersectionObserver/useIntersectionObserver.d.ts +7 -6
- package/dist/types/hooks/useLastChanged/useLastChanged.d.ts +1 -1
- package/dist/types/hooks/useList/useList.d.ts +1 -1
- package/dist/types/hooks/useLocalStorage/useLocalStorage.d.ts +1 -1
- package/dist/types/hooks/useLockCallback/useLockCallback.d.ts +1 -1
- package/dist/types/hooks/useLockScroll/useLockScroll.d.ts +49 -0
- package/dist/types/hooks/useLogger/useLogger.d.ts +1 -1
- package/dist/types/hooks/useLongPress/useLongPress.d.ts +1 -1
- package/dist/types/hooks/useMap/useMap.d.ts +1 -1
- package/dist/types/hooks/useMutation/useMutation.d.ts +1 -1
- package/dist/types/hooks/useMutationObserver/useMutationObserver.d.ts +1 -1
- package/dist/types/hooks/useNetwork/useNetwork.d.ts +1 -1
- package/dist/types/hooks/useOffsetPagination/useOffsetPagination.d.ts +1 -1
- package/dist/types/hooks/useOnline/useOnline.d.ts +1 -1
- package/dist/types/hooks/useOperatingSystem/useOperatingSystem.d.ts +1 -1
- package/dist/types/hooks/useOptimistic/useOptimistic.d.ts +1 -1
- package/dist/types/hooks/useOrientation/useOrientation.d.ts +26 -11
- package/dist/types/hooks/usePaint/usePaint.d.ts +1 -1
- package/dist/types/hooks/usePointerLock/usePointerLock.d.ts +1 -1
- package/dist/types/hooks/usePreferredColorScheme/usePreferredColorScheme.d.ts +1 -1
- package/dist/types/hooks/usePreferredContrast/usePreferredContrast.d.ts +1 -1
- package/dist/types/hooks/usePreferredDark/usePreferredDark.d.ts +1 -1
- package/dist/types/hooks/usePreferredLanguages/usePreferredLanguages.d.ts +1 -1
- package/dist/types/hooks/usePreferredReducedMotion/usePreferredReducedMotion.d.ts +1 -1
- package/dist/types/hooks/useQuery/useQuery.d.ts +1 -1
- package/dist/types/hooks/useQueue/useQueue.d.ts +1 -1
- package/dist/types/hooks/useRaf/useRaf.d.ts +1 -1
- package/dist/types/hooks/{useRafValue/useRafValue.d.ts → useRafState/useRafState.d.ts} +6 -6
- package/dist/types/hooks/useRefState/useRefState.d.ts +1 -1
- package/dist/types/hooks/useRenderCount/useRenderCount.d.ts +1 -1
- package/dist/types/hooks/useRenderInfo/useRenderInfo.d.ts +6 -1
- package/dist/types/hooks/useRerender/useRerender.d.ts +1 -1
- package/dist/types/hooks/useResizeObserver/useResizeObserver.d.ts +1 -1
- package/dist/types/hooks/useRightClick/useRightClick.d.ts +37 -0
- package/dist/types/hooks/useScript/useScript.d.ts +1 -1
- package/dist/types/hooks/useSessionStorage/useSessionStorage.d.ts +1 -1
- package/dist/types/hooks/useSet/useSet.d.ts +1 -1
- package/dist/types/hooks/useSpeechRecognition/useSpeechRecognition.d.ts +1 -1
- package/dist/types/hooks/useSpeechSynthesis/useSpeechSynthesis.d.ts +1 -1
- package/dist/types/hooks/useStateHistory/useStateHistory.d.ts +1 -1
- package/dist/types/hooks/useStep/useStep.d.ts +1 -1
- package/dist/types/hooks/useSticky/useSticky.d.ts +1 -1
- package/dist/types/hooks/useStopwatch/useStopwatch.d.ts +2 -2
- package/dist/types/hooks/useStorage/useStorage.d.ts +1 -1
- package/dist/types/hooks/useTextDirection/useTextDirection.d.ts +2 -2
- package/dist/types/hooks/useToggle/useToggle.d.ts +1 -1
- package/dist/types/hooks/useUrlSearchParam/useUrlSearchParam.d.ts +1 -1
- package/dist/types/hooks/useUrlSearchParams/useUrlSearchParams.d.ts +1 -1
- package/dist/types/hooks/useWindowEvent/useWindowEvent.d.ts +1 -1
- package/dist/types/hooks/useWizard/useWizard.d.ts +1 -1
- package/dist/types/hooks/user.d.ts +7 -0
- package/dist/types/hooks/utilities.d.ts +9 -0
- package/dist/types/utils/helpers/getElement.d.ts +1 -1
- package/package.json +89 -89
- package/dist/cjs/hooks/useRafValue/useRafValue.cjs.map +0 -1
- package/dist/cjs/hooks/useScreenOrientation/useScreenOrientation.cjs +0 -2
- package/dist/cjs/hooks/useScreenOrientation/useScreenOrientation.cjs.map +0 -1
- package/dist/esm/hooks/useRafValue/useRafValue.mjs.map +0 -1
- package/dist/esm/hooks/useScreenOrientation/useScreenOrientation.mjs +0 -31
- package/dist/esm/hooks/useScreenOrientation/useScreenOrientation.mjs.map +0 -1
- package/dist/types/hooks/useScreenOrientation/useScreenOrientation.d.ts +0 -35
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react"),b=s=>{let e;const o=new Set,r=t=>{const S=typeof t=="function"?t(e):t;if(!Object.is(S,e)){const i=e;e=S,o.forEach(a=>a(e,i))}},n=()=>e,c=()=>e,u=t=>(o.add(t),()=>o.delete(t));return typeof s=="function"?e=s(r,n):e=s,{set:r,get:n,use:t=>f.useSyncExternalStore(u,()=>t?t(n()):n(),()=>t?t(c()):c()),subscribe:u}};exports.createStore=b;
|
|
2
2
|
//# sourceMappingURL=createStore.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createStore.cjs","sources":["../../../../src/helpers/createStore/createStore.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\ntype SetStateAction<Value> = ((prev: Value) => Value) | Value;\ntype StateCreator<Value> = (\n set: (action: SetStateAction<Value>) => void,\n get: () => Value\n) => Value;\n\nexport interface StoreApi<Value> {\n getInitialState: () => Value;\n getState: () => Value;\n setState: (action: SetStateAction<Value>) => void;\n subscribe: (listener: (state: Value, prevState: Value) => void) => () => void;\n}\n\n/**\n * @name createStore\n * @description - Creates a store with state management capabilities\n * @category Helpers\n *\n * @template Value - The type of the store state\n * @param {StateCreator<Value>} createState - Function that initializes the store state\n * @returns {StoreApi<Value>} - Object containing store methods and hook for accessing state\n *\n * @example\n * const { set, get, use, subscribe } = createStore((set) => ({\n * count: 0,\n * increment: () => set(state => ({ count: state.count + 1 }))\n * }));\n */\nexport const createStore = <Value>(createState: StateCreator<Value> | Value) => {\n type Listener = (state: Value, prevState: Value) => void;\n let state: Value;\n const listeners: Set<Listener> = new Set();\n\n const setState = (action: SetStateAction<Value>) => {\n const nextState =\n typeof action === 'function' ? (action as (state: Value) => Value)(state) : action;\n\n if (!Object.is(nextState, state)) {\n const prevState = state;\n state = nextState;\n listeners.forEach((listener) => listener(state, prevState));\n }\n };\n\n const getState = () => state;\n const getInitialState = () => state;\n\n const subscribe = (listener: Listener) => {\n listeners.add(listener);\n return () => listeners.delete(listener);\n };\n if (typeof createState === 'function') {\n state = (createState as StateCreator<Value>)(setState, getState);\n } else {\n state = createState;\n }\n\n const useStore = <Selected>(selector
|
|
1
|
+
{"version":3,"file":"createStore.cjs","sources":["../../../../src/helpers/createStore/createStore.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\ntype SetStateAction<Value> = ((prev: Value) => Value) | Value;\ntype StateCreator<Value> = (\n set: (action: SetStateAction<Value>) => void,\n get: () => Value\n) => Value;\n\nexport interface StoreApi<Value> {\n getInitialState: () => Value;\n getState: () => Value;\n setState: (action: SetStateAction<Value>) => void;\n subscribe: (listener: (state: Value, prevState: Value) => void) => () => void;\n}\n\n/**\n * @name createStore\n * @description - Creates a store with state management capabilities\n * @category Helpers\n *\n * @template Value - The type of the store state\n * @param {StateCreator<Value>} createState - Function that initializes the store state\n * @returns {StoreApi<Value>} - Object containing store methods and hook for accessing state\n *\n * @example\n * const { set, get, use, subscribe } = createStore((set) => ({\n * count: 0,\n * increment: () => set(state => ({ count: state.count + 1 }))\n * }));\n */\nexport const createStore = <Value>(createState: StateCreator<Value> | Value) => {\n type Listener = (state: Value, prevState: Value) => void;\n let state: Value;\n const listeners: Set<Listener> = new Set();\n\n const setState = (action: SetStateAction<Value>) => {\n const nextState =\n typeof action === 'function' ? (action as (state: Value) => Value)(state) : action;\n\n if (!Object.is(nextState, state)) {\n const prevState = state;\n state = nextState;\n listeners.forEach((listener) => listener(state, prevState));\n }\n };\n\n const getState = () => state;\n const getInitialState = () => state;\n\n const subscribe = (listener: Listener) => {\n listeners.add(listener);\n return () => listeners.delete(listener);\n };\n if (typeof createState === 'function') {\n state = (createState as StateCreator<Value>)(setState, getState);\n } else {\n state = createState;\n }\n\n const useStore = <Selected>(selector?: (state: Value) => Selected) =>\n useSyncExternalStore(\n subscribe,\n () => (selector ? selector(getState()) : getState()),\n () => (selector ? selector(getInitialState()) : getInitialState())\n );\n\n return {\n set: setState,\n get: getState,\n use: useStore,\n subscribe\n };\n};\n"],"names":["createStore","createState","state","listeners","setState","action","nextState","prevState","listener","getState","getInitialState","subscribe","selector","useSyncExternalStore"],"mappings":"yGA8BaA,EAAsBC,GAA6C,CAE9E,IAAIC,EACJ,MAAMC,MAA+B,IAE/BC,EAAYC,GAAkC,CAClD,MAAMC,EACJ,OAAOD,GAAW,WAAcA,EAAmCH,CAAK,EAAIG,EAE9E,GAAI,CAAC,OAAO,GAAGC,EAAWJ,CAAK,EAAG,CAChC,MAAMK,EAAYL,EAClBA,EAAQI,EACRH,EAAU,QAASK,GAAaA,EAASN,EAAOK,CAAS,CAAC,CAAA,CAC5D,EAGIE,EAAW,IAAMP,EACjBQ,EAAkB,IAAMR,EAExBS,EAAaH,IACjBL,EAAU,IAAIK,CAAQ,EACf,IAAML,EAAU,OAAOK,CAAQ,GAExC,OAAI,OAAOP,GAAgB,WACzBC,EAASD,EAAoCG,EAAUK,CAAQ,EAE/DP,EAAQD,EAUH,CACL,IAAKG,EACL,IAAKK,EACL,IAV0BG,GAC1BC,EAAAA,qBACEF,EACA,IAAOC,EAAWA,EAASH,EAAA,CAAU,EAAIA,EAAA,EACzC,IAAOG,EAAWA,EAASF,EAAA,CAAiB,EAAIA,EAAA,CAAgB,EAOlE,UAAAC,CAAA,CAEJ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react"),d=require("../useRefState/useRefState.cjs"),f=require("../../utils/helpers/isTarget.cjs"),m=require("../../utils/helpers/getElement.cjs"),E=(...s)=>{const r=f.isTarget(s[0])?s[0]:void 0,[o,c]=l.useState(null),u=d.useRefState(window);return l.useEffect(()=>{const e=r?m.getElement(r):u.current;if(!e)return;const i=new MutationObserver(v=>{v.filter(t=>t.removedNodes.length).map(t=>Array.from(t.removedNodes)).flat().forEach(t=>{c(a=>t===a?document.activeElement:a)})});i.observe(e,{childList:!0,subtree:!0});const n=()=>c(document?.activeElement);return e.addEventListener("focus",n,!0),e.addEventListener("blur",n,!0),()=>{i.disconnect(),e.removeEventListener("focus",n,!0),e.removeEventListener("blur",n,!0)}},[r,u.state]),r?o:{ref:u,value:o}};exports.useActiveElement=E;
|
|
2
2
|
//# sourceMappingURL=useActiveElement.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useActiveElement.cjs","sources":["../../../../src/hooks/useActiveElement/useActiveElement.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/**\n * @name useActiveElement\n * @description - Hook that returns the active element\n * @category Elements\n *\n * @returns {ActiveElement | null} The active element\n *\n * @example\n * const activeElement = useActiveElement();\n *\n * @see {@link https://siberiacancode.github.io/reactuse/functions/hooks/useActiveElement.html}\n */\nexport const useActiveElement =
|
|
1
|
+
{"version":3,"file":"useActiveElement.cjs","sources":["../../../../src/hooks/useActiveElement/useActiveElement.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\nexport interface UseActiveElement {\n (): HTMLElement | null;\n\n <Target extends Element, ActiveElement extends HTMLElement = HTMLElement>(\n target?: never\n ): {\n ref: StateRef<Target>;\n value: ActiveElement | null;\n };\n\n <ActiveElement extends HTMLElement = HTMLElement>(target: HookTarget): ActiveElement | null;\n}\n\n/**\n * @name useActiveElement\n * @description - Hook that returns the active element\n * @category Elements\n *\n * @overload\n * @param {HookTarget} [target=window] The target element to observe active element changes\n * @returns {ActiveElement | null} The active element\n *\n * @example\n * const activeElement = useActiveElement(ref);\n *\n * @overload\n * @template ActiveElement The active element type\n * @returns {{ ref: StateRef<Element>; activeElement: ActiveElement | null }} An object containing the ref and active element\n *\n * @example\n * const { ref, value } = useActiveElement();\n *\n * @see {@link https://siberiacancode.github.io/reactuse/functions/hooks/useActiveElement.html}\n */\nexport const useActiveElement = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n\n const [value, setValue] = useState<HTMLElement | null>(null);\n const internalRef = useRefState(window);\n\n useEffect(() => {\n const element = (target ? getElement(target) : internalRef.current) as Element;\n\n if (!element) return;\n\n const observer = new MutationObserver((mutations) => {\n mutations\n .filter((mutation) => mutation.removedNodes.length)\n .map((mutation) => Array.from(mutation.removedNodes))\n .flat()\n .forEach((node) => {\n setValue((prevActiveElement) => {\n if (node === prevActiveElement) return document.activeElement as HTMLElement | null;\n return prevActiveElement;\n });\n });\n });\n\n observer.observe(element, {\n childList: true,\n subtree: true\n });\n\n const onActiveElementChange = () => setValue(document?.activeElement as HTMLElement | null);\n\n element.addEventListener('focus', onActiveElementChange, true);\n element.addEventListener('blur', onActiveElementChange, true);\n\n return () => {\n observer.disconnect();\n element.removeEventListener('focus', onActiveElementChange, true);\n element.removeEventListener('blur', onActiveElementChange, true);\n };\n }, [target, internalRef.state]);\n\n if (target) return value;\n return {\n ref: internalRef,\n value\n };\n}) as UseActiveElement;\n"],"names":["useActiveElement","params","target","isTarget","value","setValue","useState","internalRef","useRefState","useEffect","element","getElement","observer","mutations","mutation","node","prevActiveElement","onActiveElementChange"],"mappings":"mPA4CaA,EAAoB,IAAIC,IAAkB,CACrD,MAAMC,EAAUC,EAAAA,SAASF,EAAO,CAAC,CAAC,EAAIA,EAAO,CAAC,EAAI,OAE5C,CAACG,EAAOC,CAAQ,EAAIC,EAAAA,SAA6B,IAAI,EACrDC,EAAcC,EAAAA,YAAY,MAAM,EAqCtC,OAnCAC,EAAAA,UAAU,IAAM,CACd,MAAMC,EAAWR,EAASS,EAAAA,WAAWT,CAAM,EAAIK,EAAY,QAE3D,GAAI,CAACG,EAAS,OAEd,MAAME,EAAW,IAAI,iBAAkBC,GAAc,CACnDA,EACG,OAAQC,GAAaA,EAAS,aAAa,MAAM,EACjD,IAAKA,GAAa,MAAM,KAAKA,EAAS,YAAY,CAAC,EACnD,OACA,QAASC,GAAS,CACjBV,EAAUW,GACJD,IAASC,EAA0B,SAAS,cACzCA,CACR,CAAA,CACF,CAAA,CACJ,EAEDJ,EAAS,QAAQF,EAAS,CACxB,UAAW,GACX,QAAS,EAAA,CACV,EAED,MAAMO,EAAwB,IAAMZ,EAAS,UAAU,aAAmC,EAE1F,OAAAK,EAAQ,iBAAiB,QAASO,EAAuB,EAAI,EAC7DP,EAAQ,iBAAiB,OAAQO,EAAuB,EAAI,EAErD,IAAM,CACXL,EAAS,WAAA,EACTF,EAAQ,oBAAoB,QAASO,EAAuB,EAAI,EAChEP,EAAQ,oBAAoB,OAAQO,EAAuB,EAAI,CAAA,CACjE,EACC,CAACf,EAAQK,EAAY,KAAK,CAAC,EAE1BL,EAAeE,EACZ,CACL,IAAKG,EACL,MAAAH,CAAA,CAEJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAsync.cjs","sources":["../../../../src/hooks/useAsync/useAsync.ts"],"sourcesContent":["import type { DependencyList } from 'react';\n\nimport { useEffect, useState } from 'react';\n\n/* The use query return type */\nexport interface UseAsyncReturn<Data> {\n /* The state of the query */\n data?: Data;\n /* The error of the query */\n error?: Error;\n /* The error state of the query */\n isError: boolean;\n /* The loading state of the query */\n isLoading: boolean;\n}\n\n/**\n * @name useAsync\n * @description - Hook that provides the state of an async callback\n * @category
|
|
1
|
+
{"version":3,"file":"useAsync.cjs","sources":["../../../../src/hooks/useAsync/useAsync.ts"],"sourcesContent":["import type { DependencyList } from 'react';\n\nimport { useEffect, useState } from 'react';\n\n/* The use query return type */\nexport interface UseAsyncReturn<Data> {\n /* The state of the query */\n data?: Data;\n /* The error of the query */\n error?: Error;\n /* The error state of the query */\n isError: boolean;\n /* The loading state of the query */\n isLoading: boolean;\n}\n\n/**\n * @name useAsync\n * @description - Hook that provides the state of an async callback\n * @category Async\n *\n * @param {() => Promise<Data>} callback The async callback\n * @param {DependencyList} deps The dependencies of the callback\n * @returns {UseAsyncReturn<Data>} The state of the async callback\n *\n * @example\n * const { data, isLoading, isError, error } = useAsync(() => fetch('url'), [deps]);\n */\nexport const useAsync = <Data>(\n callback: () => Promise<Data>,\n deps: DependencyList\n): UseAsyncReturn<Data> => {\n const [isLoading, setIsLoading] = useState(true);\n const [isError, setIsError] = useState(false);\n\n const [error, setError] = useState<Error | undefined>(undefined);\n const [data, setData] = useState<Data | undefined>(undefined);\n\n useEffect(() => {\n setIsLoading(true);\n callback()\n .then((response) => {\n setData(response);\n setError(undefined);\n setIsError(false);\n })\n .catch((error: Error) => {\n setError(error);\n setIsError(true);\n })\n .finally(() => {\n setIsLoading(false);\n });\n }, deps);\n\n return {\n data,\n isLoading,\n isError,\n error\n };\n};\n"],"names":["useAsync","callback","deps","isLoading","setIsLoading","useState","isError","setIsError","error","setError","data","setData","useEffect","response"],"mappings":"yGA4BaA,EAAW,CACtBC,EACAC,IACyB,CACzB,KAAM,CAACC,EAAWC,CAAY,EAAIC,EAAAA,SAAS,EAAI,EACzC,CAACC,EAASC,CAAU,EAAIF,EAAAA,SAAS,EAAK,EAEtC,CAACG,EAAOC,CAAQ,EAAIJ,EAAAA,SAA4B,MAAS,EACzD,CAACK,EAAMC,CAAO,EAAIN,EAAAA,SAA2B,MAAS,EAE5DO,OAAAA,EAAAA,UAAU,IAAM,CACdR,EAAa,EAAI,EACjBH,EAAA,EACG,KAAMY,GAAa,CAClBF,EAAQE,CAAQ,EAChBJ,EAAS,MAAS,EAClBF,EAAW,EAAK,CAAA,CACjB,EACA,MAAOC,GAAiB,CACvBC,EAASD,CAAK,EACdD,EAAW,EAAI,CAAA,CAChB,EACA,QAAQ,IAAM,CACbH,EAAa,EAAK,CAAA,CACnB,CAAA,EACFF,CAAI,EAEA,CACL,KAAAQ,EACA,UAAAP,EACA,QAAAG,EACA,MAAAE,CAAA,CAEJ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("react"),m=require("../useRefState/useRefState.cjs"),R=require("../../utils/helpers/isTarget.cjs"),q=require("../../utils/helpers/getElement.cjs"),H=(...n)=>{const c=R.isTarget(n[0])?n[0]:void 0,f=n[1]||(typeof n[0]=="object"?n[0]:{}),{enabled:v=!0}=f,l=m.useRefState(),o=L.useRef(f);if(o.current=f,L.useEffect(()=>{if(!v||!c&&!l.state)return;const e=c?q.getElement(c):l.state;if(!e)return;let s=!0,a=0,h=0;const g=()=>{if(o.current.force)return;const{scrollHeight:t,clientHeight:u,scrollTop:r}=e,i=t-u,d=i/2;console.log(i,r,d,r<h,i-r<=d),r<h?s=!1:i-r<=d&&(s=!0),h=r},S=t=>{o.current.force||(t.deltaY<0?s=!1:g())},E=t=>{o.current.force||(a=t.touches[0].clientY)},T=t=>{if(o.current.force)return;const u=t.touches[0].clientY;a-u<0?s=!1:g(),a=u},Y=()=>{!s&&!o.current.force||e.scrollTo({top:e.scrollHeight})};e.addEventListener("wheel",S),e.addEventListener("touchstart",E),e.addEventListener("touchmove",T);const b=new MutationObserver(Y);return b.observe(e,{childList:!0,subtree:!0,characterData:!0}),()=>{b.disconnect(),e.removeEventListener("wheel",S),e.removeEventListener("touchstart",E),e.removeEventListener("touchmove",T)}},[v,c,l.state]),!c)return l};exports.useAutoScroll=H;
|
|
2
2
|
//# sourceMappingURL=useAutoScroll.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAutoScroll.cjs","sources":["../../../../src/hooks/useAutoScroll/useAutoScroll.ts"],"sourcesContent":["import { useEffect } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use auto scroll options type */\nexport interface UseAutoScrollOptions {\n /** Whether auto-scrolling is enabled */\n enabled?: boolean;\n}\n\nexport interface UseAutoScroll {\n (target: HookTarget, options?: UseAutoScrollOptions): void;\n\n <Target extends HTMLElement>(options?: UseAutoScrollOptions): StateRef<Target>;\n}\n\n/**\n * @name useAutoScroll\n * @description - Hook that automatically scrolls a list element to the bottom\n * @category
|
|
1
|
+
{"version":3,"file":"useAutoScroll.cjs","sources":["../../../../src/hooks/useAutoScroll/useAutoScroll.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use auto scroll options type */\nexport interface UseAutoScrollOptions {\n /** Whether auto-scrolling is enabled */\n enabled?: boolean;\n /** Whether to force auto-scrolling regardless of user interactions */\n force?: boolean;\n}\n\nexport interface UseAutoScroll {\n (target: HookTarget, options?: UseAutoScrollOptions): void;\n\n <Target extends HTMLElement>(options?: UseAutoScrollOptions): StateRef<Target>;\n}\n\n/**\n * @name useAutoScroll\n * @description - Hook that automatically scrolls a list element to the bottom\n * @category Elements\n *\n * @overload\n * @param {HookTarget} target The target element to auto-scroll\n * @param {boolean} [options.enabled] Whether auto-scrolling is enabled\n * @returns {void}\n *\n * @example\n * useAutoScroll(ref);\n *\n * @overload\n * @template Target\n * @param {boolean} [options.enabled] Whether auto-scrolling is enabled\n * @returns {StateRef<Target>} A React ref to attach to the list element\n *\n * @example\n * const ref = useAutoScroll();\n */\nexport const useAutoScroll = ((...params: any[]) => {\n const target = isTarget(params[0]) ? params[0] : undefined;\n const options = (params[1] ||\n (typeof params[0] === 'object' ? params[0] : {})) as UseAutoScrollOptions;\n const { enabled = true } = options;\n\n const internalRef = useRefState<HTMLElement>();\n const internalOptionsRef = useRef<UseAutoScrollOptions>(options);\n internalOptionsRef.current = options;\n\n useEffect(() => {\n if (!enabled || (!target && !internalRef.state)) return;\n\n const element = (target ? getElement(target) : internalRef.state) as HTMLElement;\n\n if (!element) return;\n\n let shouldAutoScroll = true;\n let touchStartY = 0;\n let lastScrollTop = 0;\n\n const onCheckScrollPosition = () => {\n if (internalOptionsRef.current.force) return;\n\n const { scrollHeight, clientHeight, scrollTop } = element;\n const maxScrollHeight = scrollHeight - clientHeight;\n const scrollThreshold = maxScrollHeight / 2;\n console.log(\n maxScrollHeight,\n scrollTop,\n scrollThreshold,\n scrollTop < lastScrollTop,\n maxScrollHeight - scrollTop <= scrollThreshold\n );\n\n if (scrollTop < lastScrollTop) shouldAutoScroll = false;\n else if (maxScrollHeight - scrollTop <= scrollThreshold) shouldAutoScroll = true;\n\n lastScrollTop = scrollTop;\n };\n\n const onWheel = (event: WheelEvent) => {\n if (internalOptionsRef.current.force) return;\n\n if (event.deltaY < 0) shouldAutoScroll = false;\n else onCheckScrollPosition();\n };\n\n const onTouchStart = (event: TouchEvent) => {\n if (internalOptionsRef.current.force) return;\n touchStartY = event.touches[0].clientY;\n };\n\n const onTouchMove = (event: TouchEvent) => {\n if (internalOptionsRef.current.force) return;\n\n const touchEndY = event.touches[0].clientY;\n const deltaY = touchStartY - touchEndY;\n\n if (deltaY < 0) shouldAutoScroll = false;\n else onCheckScrollPosition();\n\n touchStartY = touchEndY;\n };\n\n const onMutation = () => {\n if (!shouldAutoScroll && !internalOptionsRef.current.force) return;\n element.scrollTo({ top: element.scrollHeight });\n };\n\n element.addEventListener('wheel', onWheel);\n element.addEventListener('touchstart', onTouchStart);\n element.addEventListener('touchmove', onTouchMove);\n\n const observer = new MutationObserver(onMutation);\n\n observer.observe(element, {\n childList: true,\n subtree: true,\n characterData: true\n });\n\n return () => {\n observer.disconnect();\n element.removeEventListener('wheel', onWheel);\n element.removeEventListener('touchstart', onTouchStart);\n element.removeEventListener('touchmove', onTouchMove);\n };\n }, [enabled, target, internalRef.state]);\n\n if (target) return;\n return internalRef;\n}) as UseAutoScroll;\n"],"names":["useAutoScroll","params","target","isTarget","options","enabled","internalRef","useRefState","internalOptionsRef","useRef","useEffect","element","getElement","shouldAutoScroll","touchStartY","lastScrollTop","onCheckScrollPosition","scrollHeight","clientHeight","scrollTop","maxScrollHeight","scrollThreshold","onWheel","event","onTouchStart","onTouchMove","touchEndY","onMutation","observer"],"mappings":"mPA6CaA,EAAiB,IAAIC,IAAkB,CAClD,MAAMC,EAASC,EAAAA,SAASF,EAAO,CAAC,CAAC,EAAIA,EAAO,CAAC,EAAI,OAC3CG,EAAWH,EAAO,CAAC,IACtB,OAAOA,EAAO,CAAC,GAAM,SAAWA,EAAO,CAAC,EAAI,CAAA,GACzC,CAAE,QAAAI,EAAU,EAAA,EAASD,EAErBE,EAAcC,EAAAA,YAAA,EACdC,EAAqBC,EAAAA,OAA6BL,CAAO,EAmF/D,GAlFAI,EAAmB,QAAUJ,EAE7BM,EAAAA,UAAU,IAAM,CACd,GAAI,CAACL,GAAY,CAACH,GAAU,CAACI,EAAY,MAAQ,OAEjD,MAAMK,EAAWT,EAASU,EAAAA,WAAWV,CAAM,EAAII,EAAY,MAE3D,GAAI,CAACK,EAAS,OAEd,IAAIE,EAAmB,GACnBC,EAAc,EACdC,EAAgB,EAEpB,MAAMC,EAAwB,IAAM,CAClC,GAAIR,EAAmB,QAAQ,MAAO,OAEtC,KAAM,CAAE,aAAAS,EAAc,aAAAC,EAAc,UAAAC,CAAA,EAAcR,EAC5CS,EAAkBH,EAAeC,EACjCG,EAAkBD,EAAkB,EAC1C,QAAQ,IACNA,EACAD,EACAE,EACAF,EAAYJ,EACZK,EAAkBD,GAAaE,CAAA,EAG7BF,EAAYJ,EAAeF,EAAmB,GACzCO,EAAkBD,GAAaE,IAAiBR,EAAmB,IAE5EE,EAAgBI,CAAA,EAGZG,EAAWC,GAAsB,CACjCf,EAAmB,QAAQ,QAE3Be,EAAM,OAAS,EAAGV,EAAmB,GACpCG,EAAA,EAAsB,EAGvBQ,EAAgBD,GAAsB,CACtCf,EAAmB,QAAQ,QAC/BM,EAAcS,EAAM,QAAQ,CAAC,EAAE,QAAA,EAG3BE,EAAeF,GAAsB,CACzC,GAAIf,EAAmB,QAAQ,MAAO,OAEtC,MAAMkB,EAAYH,EAAM,QAAQ,CAAC,EAAE,QACpBT,EAAcY,EAEhB,EAAGb,EAAmB,GAC9BG,EAAA,EAELF,EAAcY,CAAA,EAGVC,EAAa,IAAM,CACnB,CAACd,GAAoB,CAACL,EAAmB,QAAQ,OACrDG,EAAQ,SAAS,CAAE,IAAKA,EAAQ,aAAc,CAAA,EAGhDA,EAAQ,iBAAiB,QAASW,CAAO,EACzCX,EAAQ,iBAAiB,aAAca,CAAY,EACnDb,EAAQ,iBAAiB,YAAac,CAAW,EAEjD,MAAMG,EAAW,IAAI,iBAAiBD,CAAU,EAEhD,OAAAC,EAAS,QAAQjB,EAAS,CACxB,UAAW,GACX,QAAS,GACT,cAAe,EAAA,CAChB,EAEM,IAAM,CACXiB,EAAS,WAAA,EACTjB,EAAQ,oBAAoB,QAASW,CAAO,EAC5CX,EAAQ,oBAAoB,aAAca,CAAY,EACtDb,EAAQ,oBAAoB,YAAac,CAAW,CAAA,CACtD,EACC,CAACpB,EAASH,EAAQI,EAAY,KAAK,CAAC,EAEnC,CAAAJ,EACJ,OAAOI,CACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBoolean.cjs","sources":["../../../../src/hooks/useBoolean/useBoolean.ts"],"sourcesContent":["import { useState } from 'react';\n\n/** The use boolean return type */\nexport type UseBooleanReturn = [\n /** The current boolean state value */\n value: boolean,\n /** Function to toggle the boolean state */\n toggle: (value?: boolean) => void\n];\n\n/**\n * @name useBoolean\n * @description - Hook provides opportunity to manage boolean state\n * @category
|
|
1
|
+
{"version":3,"file":"useBoolean.cjs","sources":["../../../../src/hooks/useBoolean/useBoolean.ts"],"sourcesContent":["import { useState } from 'react';\n\n/** The use boolean return type */\nexport type UseBooleanReturn = [\n /** The current boolean state value */\n value: boolean,\n /** Function to toggle the boolean state */\n toggle: (value?: boolean) => void\n];\n\n/**\n * @name useBoolean\n * @description - Hook provides opportunity to manage boolean state\n * @category State\n *\n * @param {boolean} [initialValue=false] The initial boolean value\n * @returns {UseBooleanReturn} An object containing the boolean state value and utility functions to manipulate the state\n *\n * @example\n * const [on, toggle] = useBoolean()\n */\nexport const useBoolean = (initialValue = false): UseBooleanReturn => {\n const [value, setValue] = useState(initialValue);\n const toggle = (value?: boolean) => setValue((prevValue) => value ?? !prevValue);\n\n return [value, toggle];\n};\n"],"names":["useBoolean","initialValue","value","setValue","useState","prevValue"],"mappings":"yGAqBaA,EAAa,CAACC,EAAe,KAA4B,CACpE,KAAM,CAACC,EAAOC,CAAQ,EAAIC,EAAAA,SAASH,CAAY,EAG/C,MAAO,CAACC,EAFQA,GAAoBC,EAAUE,GAAcH,GAAS,CAACG,CAAS,CAE1D,CACvB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBrowserLanguage.cjs","sources":["../../../../src/hooks/useBrowserLanguage/useBrowserLanguage.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\nconst getSnapshot = () => navigator.language;\nconst getServerSnapshot = () => 'undetermined';\nconst subscribe = (callback: () => void) => {\n window.addEventListener('languagechange', callback);\n return () => window.removeEventListener('languagechange', callback);\n};\n\n/**\n * @name useBrowserLanguage\n * @description - Hook that returns the current browser language\n * @category
|
|
1
|
+
{"version":3,"file":"useBrowserLanguage.cjs","sources":["../../../../src/hooks/useBrowserLanguage/useBrowserLanguage.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\nconst getSnapshot = () => navigator.language;\nconst getServerSnapshot = () => 'undetermined';\nconst subscribe = (callback: () => void) => {\n window.addEventListener('languagechange', callback);\n return () => window.removeEventListener('languagechange', callback);\n};\n\n/**\n * @name useBrowserLanguage\n * @description - Hook that returns the current browser language\n * @category User\n *\n * @browserapi navigator.language https://developer.mozilla.org/en-US/docs/Web/API/Navigator/language\n *\n * @returns {string} The current browser language\n *\n * @example\n * const browserLanguage = useBrowserLanguage();\n */\nexport const useBrowserLanguage = () =>\n useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n"],"names":["getSnapshot","getServerSnapshot","subscribe","callback","useBrowserLanguage","useSyncExternalStore"],"mappings":"yGAEMA,EAAc,IAAM,UAAU,SAC9BC,EAAoB,IAAM,eAC1BC,EAAaC,IACjB,OAAO,iBAAiB,iBAAkBA,CAAQ,EAC3C,IAAM,OAAO,oBAAoB,iBAAkBA,CAAQ,GAevDC,EAAqB,IAChCC,EAAAA,qBAAqBH,EAAWF,EAAaC,CAAiB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useClickOutside.cjs","sources":["../../../../src/hooks/useClickOutside/useClickOutside.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\nexport interface UseClickOutside {\n (target: HookTarget, callback: (event: Event) => void): void;\n\n <Target extends Element>(callback: (event: Event) => void, target?: never): StateRef<Target>;\n}\n\n/**\n * @name useClickOutside\n * @description - Hook to handle click events outside the specified target element(s)\n * @category
|
|
1
|
+
{"version":3,"file":"useClickOutside.cjs","sources":["../../../../src/hooks/useClickOutside/useClickOutside.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\nexport interface UseClickOutside {\n (target: HookTarget, callback: (event: Event) => void): void;\n\n <Target extends Element>(callback: (event: Event) => void, target?: never): StateRef<Target>;\n}\n\n/**\n * @name useClickOutside\n * @description - Hook to handle click events outside the specified target element(s)\n * @category Elements\n *\n * @overload\n * @param {HookTarget} target The target element(s) to detect outside clicks for\n * @param {(event: Event) => void} callback The callback to execute when a click outside the target is detected\n * @returns {void}\n *\n * @example\n * useClickOutside(ref, () => console.log('click outside'));\n *\n * @overload\n * @template Target The target element(s)\n * @param {(event: Event) => void} callback The callback to execute when a click outside the target is detected\n * @returns {(node: Target) => void} A React ref to attach to the target element\n *\n * @example\n * const ref = useClickOutside<HTMLDivElement>(() => console.log('click outside'));\n *\n * @see {@link https://siberiacancode.github.io/reactuse/functions/hooks/useClickOutside.html}\n */\nexport const useClickOutside = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const callback = (params[1] ? params[1] : params[0]) as (event: Event) => void;\n\n const internalRef = useRefState<Element>();\n const internalCallbackRef = useRef(callback);\n internalCallbackRef.current = callback;\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n const onClick = (event: Event) => {\n const element = (target ? getElement(target) : internalRef.current) as Element;\n\n if (element && !element.contains(event.target as Node)) {\n internalCallbackRef.current(event);\n }\n };\n\n document.addEventListener('click', onClick);\n\n return () => {\n document.removeEventListener('click', onClick);\n };\n }, [target, internalRef.state]);\n\n if (target) return;\n return internalRef;\n}) as UseClickOutside;\n"],"names":["useClickOutside","params","target","isTarget","callback","internalRef","useRefState","internalCallbackRef","useRef","useEffect","onClick","event","element","getElement"],"mappings":"mPAuCaA,EAAmB,IAAIC,IAAkB,CACpD,MAAMC,EAAUC,EAAAA,SAASF,EAAO,CAAC,CAAC,EAAIA,EAAO,CAAC,EAAI,OAC5CG,EAAYH,EAAO,CAAC,EAAIA,EAAO,CAAC,EAAIA,EAAO,CAAC,EAE5CI,EAAcC,EAAAA,YAAA,EACdC,EAAsBC,EAAAA,OAAOJ,CAAQ,EAoB3C,GAnBAG,EAAoB,QAAUH,EAE9BK,EAAAA,UAAU,IAAM,CACd,GAAI,CAACP,GAAU,CAACG,EAAY,MAAO,OACnC,MAAMK,EAAWC,GAAiB,CAChC,MAAMC,EAAWV,EAASW,EAAAA,WAAWX,CAAM,EAAIG,EAAY,QAEvDO,GAAW,CAACA,EAAQ,SAASD,EAAM,MAAc,GACnDJ,EAAoB,QAAQI,CAAK,CACnC,EAGF,gBAAS,iBAAiB,QAASD,CAAO,EAEnC,IAAM,CACX,SAAS,oBAAoB,QAASA,CAAO,CAAA,CAC/C,EACC,CAACR,EAAQG,EAAY,KAAK,CAAC,EAE1B,CAAAH,EACJ,OAAOG,CACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCookie.cjs","sources":["../../../../src/hooks/useCookie/useCookie.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nexport const getCookies = () =>\n Object.fromEntries(\n document.cookie.split('; ').map((cookie) => {\n const [key, ...value] = cookie.split('=');\n const decodedValue = decodeURIComponent(value.join('='));\n return [key, decodedValue];\n })\n );\n\nexport interface RemoveCookieParams {\n domain?: string;\n expires?: Date;\n maxAge?: number;\n path?: string;\n sameSite?: 'Lax' | 'None' | 'Strict';\n secure?: boolean;\n}\n\nexport const removeCookie = (key: string, options: RemoveCookieParams = {}) => {\n document.cookie = `${encodeURIComponent(key)}=; expires=Thu, 01 Jan 1970 00:00:00 GMT${\n options.path ? `; path=${options.path}` : ''\n }${options.domain ? `; domain=${options.domain}` : ''}${\n options.maxAge ? `; max-age=0` : ''\n }${options.expires ? `; expires=Thu, 01 Jan 1970 00:00:00 GMT` : ''}${\n options.secure ? `; secure` : ''\n }${options.sameSite ? `; samesite=${options.sameSite}` : ''}`;\n};\n\nexport interface SetCookieParams {\n domain?: string;\n expires?: Date;\n httpOnly?: boolean;\n maxAge?: number;\n path?: string;\n sameSite?: 'Lax' | 'None' | 'Strict';\n secure?: boolean;\n}\n\nexport const setCookie = (key: string, value: string, options: SetCookieParams = {}) => {\n const cookie = [`${encodeURIComponent(key)}=${encodeURIComponent(value)}`];\n\n if (options.path) cookie.push(`path=${options.path}`);\n if (options.domain) cookie.push(`domain=${options.domain}`);\n if (typeof options.maxAge === 'number') cookie.push(`max-age=${options.maxAge}`);\n if (options.expires) cookie.push(`expires=${options.expires.toUTCString()}`);\n if (options.secure) cookie.push(`secure`);\n if (options.httpOnly) cookie.push(`httpOnly`);\n if (options.sameSite) cookie.push(`samesite=${options.sameSite}`);\n\n document.cookie = cookie.join('; ');\n};\n\n/* The use cookie initial value type */\nexport type UseCookieInitialValue<Value> = (() => Value) | Value;\n\n/* The use cookie options type */\nexport interface UseCookieOptions<Value> {\n /* The domain of the cookie */\n domain?: string;\n /* The expiration date of the cookie */\n expires?: Date;\n /* Whether the cookie is httpOnly */\n httpOnly?: boolean;\n /* The initial value of the storage */\n initialValue?: UseCookieInitialValue<Value>;\n /* The maximum age of the cookie */\n maxAge?: number;\n /* The path of the cookie */\n path?: string;\n /* The sameSite of the cookie */\n sameSite?: 'Lax' | 'None' | 'Strict';\n /* Whether the cookie is secure */\n secure?: boolean;\n /* The deserializer function to be invoked */\n deserializer?: (value: string) => Value;\n /* The serializer function to be invoked */\n serializer?: (value: Value) => string;\n}\n\n/* The use cookie return type */\nexport interface UseCookieReturn<Value> {\n /* The value of the cookie */\n value: Value;\n /* The remove function */\n remove: (options?: RemoveCookieParams) => void;\n /* The set function */\n set: (value: Value, options?: SetCookieParams) => void;\n}\n\nexport const COOKIE_EVENT = 'reactuse-cookie';\n\nexport const dispatchCookieEvent = () => window.dispatchEvent(new Event(COOKIE_EVENT));\n\nexport const setCookieItem = (key: string, value: string, options?: SetCookieParams) => {\n setCookie(key, value, options);\n dispatchCookieEvent();\n};\n\nexport const removeCookieItem = (key: string, options?: RemoveCookieParams) => {\n removeCookie(key, options);\n dispatchCookieEvent();\n};\n\nexport const getCookie = (key: string): string | undefined => {\n const cookies = getCookies();\n return cookies[key];\n};\n\nexport interface UseCookie {\n <Value>(\n key: string,\n options: UseCookieOptions<Value> & {\n initialValue: UseCookieInitialValue<Value>;\n }\n ): UseCookieReturn<Value>;\n\n <Value>(key: string, options?: UseCookieOptions<Value>): UseCookieReturn<Value | undefined>;\n\n <Value>(key: string, initialValue: UseCookieInitialValue<Value>): UseCookieReturn<Value>;\n\n <Value>(key: string): UseCookieReturn<Value | undefined>;\n}\n\n/**\n * @name useCookie\n * @description - Hook that manages cookie value\n * @category
|
|
1
|
+
{"version":3,"file":"useCookie.cjs","sources":["../../../../src/hooks/useCookie/useCookie.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nexport const getCookies = () =>\n Object.fromEntries(\n document.cookie.split('; ').map((cookie) => {\n const [key, ...value] = cookie.split('=');\n const decodedValue = decodeURIComponent(value.join('='));\n return [key, decodedValue];\n })\n );\n\nexport interface RemoveCookieParams {\n domain?: string;\n expires?: Date;\n maxAge?: number;\n path?: string;\n sameSite?: 'Lax' | 'None' | 'Strict';\n secure?: boolean;\n}\n\nexport const removeCookie = (key: string, options: RemoveCookieParams = {}) => {\n document.cookie = `${encodeURIComponent(key)}=; expires=Thu, 01 Jan 1970 00:00:00 GMT${\n options.path ? `; path=${options.path}` : ''\n }${options.domain ? `; domain=${options.domain}` : ''}${\n options.maxAge ? `; max-age=0` : ''\n }${options.expires ? `; expires=Thu, 01 Jan 1970 00:00:00 GMT` : ''}${\n options.secure ? `; secure` : ''\n }${options.sameSite ? `; samesite=${options.sameSite}` : ''}`;\n};\n\nexport interface SetCookieParams {\n domain?: string;\n expires?: Date;\n httpOnly?: boolean;\n maxAge?: number;\n path?: string;\n sameSite?: 'Lax' | 'None' | 'Strict';\n secure?: boolean;\n}\n\nexport const setCookie = (key: string, value: string, options: SetCookieParams = {}) => {\n const cookie = [`${encodeURIComponent(key)}=${encodeURIComponent(value)}`];\n\n if (options.path) cookie.push(`path=${options.path}`);\n if (options.domain) cookie.push(`domain=${options.domain}`);\n if (typeof options.maxAge === 'number') cookie.push(`max-age=${options.maxAge}`);\n if (options.expires) cookie.push(`expires=${options.expires.toUTCString()}`);\n if (options.secure) cookie.push(`secure`);\n if (options.httpOnly) cookie.push(`httpOnly`);\n if (options.sameSite) cookie.push(`samesite=${options.sameSite}`);\n\n document.cookie = cookie.join('; ');\n};\n\n/* The use cookie initial value type */\nexport type UseCookieInitialValue<Value> = (() => Value) | Value;\n\n/* The use cookie options type */\nexport interface UseCookieOptions<Value> {\n /* The domain of the cookie */\n domain?: string;\n /* The expiration date of the cookie */\n expires?: Date;\n /* Whether the cookie is httpOnly */\n httpOnly?: boolean;\n /* The initial value of the storage */\n initialValue?: UseCookieInitialValue<Value>;\n /* The maximum age of the cookie */\n maxAge?: number;\n /* The path of the cookie */\n path?: string;\n /* The sameSite of the cookie */\n sameSite?: 'Lax' | 'None' | 'Strict';\n /* Whether the cookie is secure */\n secure?: boolean;\n /* The deserializer function to be invoked */\n deserializer?: (value: string) => Value;\n /* The serializer function to be invoked */\n serializer?: (value: Value) => string;\n}\n\n/* The use cookie return type */\nexport interface UseCookieReturn<Value> {\n /* The value of the cookie */\n value: Value;\n /* The remove function */\n remove: (options?: RemoveCookieParams) => void;\n /* The set function */\n set: (value: Value, options?: SetCookieParams) => void;\n}\n\nexport const COOKIE_EVENT = 'reactuse-cookie';\n\nexport const dispatchCookieEvent = () => window.dispatchEvent(new Event(COOKIE_EVENT));\n\nexport const setCookieItem = (key: string, value: string, options?: SetCookieParams) => {\n setCookie(key, value, options);\n dispatchCookieEvent();\n};\n\nexport const removeCookieItem = (key: string, options?: RemoveCookieParams) => {\n removeCookie(key, options);\n dispatchCookieEvent();\n};\n\nexport const getCookie = (key: string): string | undefined => {\n const cookies = getCookies();\n return cookies[key];\n};\n\nexport interface UseCookie {\n <Value>(\n key: string,\n options: UseCookieOptions<Value> & {\n initialValue: UseCookieInitialValue<Value>;\n }\n ): UseCookieReturn<Value>;\n\n <Value>(key: string, options?: UseCookieOptions<Value>): UseCookieReturn<Value | undefined>;\n\n <Value>(key: string, initialValue: UseCookieInitialValue<Value>): UseCookieReturn<Value>;\n\n <Value>(key: string): UseCookieReturn<Value | undefined>;\n}\n\n/**\n * @name useCookie\n * @description - Hook that manages cookie value\n * @category State\n *\n * @overload\n * @template Value The type of the cookie value\n * @param {string} key The key of the cookie\n * @param {UseCookieInitialValue<Value>} [initialValue] The initial value of the cookie\n * @returns {UseCookieReturn<Value>} The value and the set function\n *\n * @overload\n * @template Value The type of the cookie value\n * @param {string} key The key of the cookie\n * @param {UseCookieOptions<Value>} options The options object\n * @param {UseCookieInitialValue<Value>} [options.initialValue] The initial value of the cookie\n * @param {(value: string) => Value} [options.deserializer] The deserializer function to be invoked\n * @param {(value: Value) => string} [options.serializer] The serializer function to be invoked\n * @returns {UseCookieReturn<Value | undefined>} The value and the set function\n *\n * @example\n * const { value, set, remove } = useCookie('key', 'value');\n */\nexport const useCookie = (<Value>(key: string, params?: any) => {\n const options = (\n typeof params === 'object' &&\n params &&\n ('serializer' in params || 'deserializer' in params || 'initialValue' in params)\n ? params\n : undefined\n ) as UseCookieOptions<Value>;\n const initialValue = (options ? options?.initialValue : params) as UseCookieInitialValue<Value>;\n\n if (typeof document === 'undefined')\n return {\n value: typeof initialValue === 'function' ? (initialValue as () => Value)() : initialValue\n } as UseCookieReturn<Value>;\n\n const serializer = (value: Value) => {\n if (options?.serializer) return options.serializer(value);\n if (typeof value === 'string') return value;\n return JSON.stringify(value);\n };\n\n const deserializer = (value: string) => {\n if (options?.deserializer) return options.deserializer(value);\n if (value === 'undefined') return undefined as unknown as Value;\n\n try {\n return JSON.parse(value) as Value;\n } catch {\n return value as Value;\n }\n };\n\n const [value, setValue] = useState<Value | undefined>(() => {\n const cookieValue = getCookie(key);\n if (cookieValue === undefined && initialValue !== undefined) {\n const value =\n typeof initialValue === 'function' ? (initialValue as () => Value)() : initialValue;\n setCookieItem(key, serializer(value), options);\n return value;\n }\n return cookieValue ? deserializer(cookieValue) : undefined;\n });\n\n useEffect(() => {\n const onChange = () => {\n const cookieValue = getCookie(key);\n setValue(cookieValue ? deserializer(cookieValue) : undefined);\n };\n window.addEventListener(COOKIE_EVENT, onChange);\n return () => window.removeEventListener(COOKIE_EVENT, onChange);\n }, [key]);\n\n const set = (value: Value, params?: SetCookieParams) =>\n setCookieItem(key, serializer(value), { ...options, ...params });\n const remove = (params?: RemoveCookieParams) => removeCookieItem(key, { ...options, ...params });\n\n return { value, set, remove };\n}) as UseCookie;\n"],"names":["getCookies","cookie","key","value","decodedValue","removeCookie","options","setCookie","COOKIE_EVENT","dispatchCookieEvent","setCookieItem","removeCookieItem","getCookie","useCookie","params","initialValue","serializer","deserializer","setValue","useState","cookieValue","useEffect","onChange"],"mappings":"yGAEaA,EAAa,IACxB,OAAO,YACL,SAAS,OAAO,MAAM,IAAI,EAAE,IAAKC,GAAW,CAC1C,KAAM,CAACC,EAAK,GAAGC,CAAK,EAAIF,EAAO,MAAM,GAAG,EAClCG,EAAe,mBAAmBD,EAAM,KAAK,GAAG,CAAC,EACvD,MAAO,CAACD,EAAKE,CAAY,CAAA,CAC1B,CACH,EAWWC,EAAe,CAACH,EAAaI,EAA8B,KAAO,CAC7E,SAAS,OAAS,GAAG,mBAAmBJ,CAAG,CAAC,2CAC1CI,EAAQ,KAAO,UAAUA,EAAQ,IAAI,GAAK,EAC5C,GAAGA,EAAQ,OAAS,YAAYA,EAAQ,MAAM,GAAK,EAAE,GACnDA,EAAQ,OAAS,cAAgB,EACnC,GAAGA,EAAQ,QAAU,0CAA4C,EAAE,GACjEA,EAAQ,OAAS,WAAa,EAChC,GAAGA,EAAQ,SAAW,cAAcA,EAAQ,QAAQ,GAAK,EAAE,EAC7D,EAYaC,EAAY,CAACL,EAAaC,EAAeG,EAA2B,CAAA,IAAO,CACtF,MAAML,EAAS,CAAC,GAAG,mBAAmBC,CAAG,CAAC,IAAI,mBAAmBC,CAAK,CAAC,EAAE,EAErEG,EAAQ,MAAML,EAAO,KAAK,QAAQK,EAAQ,IAAI,EAAE,EAChDA,EAAQ,QAAQL,EAAO,KAAK,UAAUK,EAAQ,MAAM,EAAE,EACtD,OAAOA,EAAQ,QAAW,YAAiB,KAAK,WAAWA,EAAQ,MAAM,EAAE,EAC3EA,EAAQ,SAASL,EAAO,KAAK,WAAWK,EAAQ,QAAQ,YAAA,CAAa,EAAE,EACvEA,EAAQ,QAAQL,EAAO,KAAK,QAAQ,EACpCK,EAAQ,UAAUL,EAAO,KAAK,UAAU,EACxCK,EAAQ,UAAUL,EAAO,KAAK,YAAYK,EAAQ,QAAQ,EAAE,EAEhE,SAAS,OAASL,EAAO,KAAK,IAAI,CACpC,EAuCaO,EAAe,kBAEfC,EAAsB,IAAM,OAAO,cAAc,IAAI,MAAMD,CAAY,CAAC,EAExEE,EAAgB,CAACR,EAAaC,EAAeG,IAA8B,CACtFC,EAAUL,EAAKC,EAAOG,CAAO,EAC7BG,EAAA,CACF,EAEaE,EAAmB,CAACT,EAAaI,IAAiC,CAC7ED,EAAaH,EAAKI,CAAO,EACzBG,EAAA,CACF,EAEaG,EAAaV,GACRF,EAAA,EACDE,CAAG,EAyCPW,EAAa,CAAQX,EAAaY,IAAiB,CAC9D,MAAMR,EACJ,OAAOQ,GAAW,UAClBA,IACC,eAAgBA,GAAU,iBAAkBA,GAAU,iBAAkBA,GACrEA,EACA,OAEAC,EAAgBT,EAAUA,GAAS,aAAeQ,EAExD,GAAI,OAAO,SAAa,IACtB,MAAO,CACL,MAAO,OAAOC,GAAiB,WAAcA,IAAiCA,CAAA,EAGlF,MAAMC,EAAcb,GACdG,GAAS,WAAmBA,EAAQ,WAAWH,CAAK,EACpD,OAAOA,GAAU,SAAiBA,EAC/B,KAAK,UAAUA,CAAK,EAGvBc,EAAgBd,GAAkB,CACtC,GAAIG,GAAS,aAAc,OAAOA,EAAQ,aAAaH,CAAK,EAC5D,GAAIA,IAAU,YAEd,GAAI,CACF,OAAO,KAAK,MAAMA,CAAK,CAAA,MACjB,CACN,OAAOA,CAAA,CACT,EAGI,CAACA,EAAOe,CAAQ,EAAIC,EAAAA,SAA4B,IAAM,CAC1D,MAAMC,EAAcR,EAAUV,CAAG,EACjC,GAAIkB,IAAgB,QAAaL,IAAiB,OAAW,CAC3D,MAAMZ,EACJ,OAAOY,GAAiB,WAAcA,IAAiCA,EACzE,OAAAL,EAAcR,EAAKc,EAAWb,CAAK,EAAGG,CAAO,EACtCH,CAAA,CAET,OAAOiB,EAAcH,EAAaG,CAAW,EAAI,MAAA,CAClD,EAEDC,OAAAA,EAAAA,UAAU,IAAM,CACd,MAAMC,EAAW,IAAM,CACrB,MAAMF,EAAcR,EAAUV,CAAG,EACjCgB,EAASE,EAAcH,EAAaG,CAAW,EAAI,MAAS,CAAA,EAE9D,cAAO,iBAAiBZ,EAAcc,CAAQ,EACvC,IAAM,OAAO,oBAAoBd,EAAcc,CAAQ,CAAA,EAC7D,CAACpB,CAAG,CAAC,EAMD,CAAE,MAAAC,EAAO,IAJJ,CAACA,EAAcW,IACzBJ,EAAcR,EAAKc,EAAWb,CAAK,EAAG,CAAE,GAAGG,EAAS,GAAGQ,EAAQ,EAG5C,OAFLA,GAAgCH,EAAiBT,EAAK,CAAE,GAAGI,EAAS,GAAGQ,EAAQ,CAE1E,CACvB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCookies.cjs","sources":["../../../../src/hooks/useCookies/useCookies.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport type { RemoveCookieParams, SetCookieParams } from '../useCookie/useCookie';\n\nimport {\n COOKIE_EVENT,\n dispatchCookieEvent,\n removeCookie,\n removeCookieItem,\n setCookieItem\n} from '../useCookie/useCookie';\n\n/** The cookies params type */\nexport type CookieParams = Record<string, any>;\n\n/* The use cookies options type */\nexport interface UseCookiesOptions<Value> {\n /* The deserializer function to be invoked */\n deserializer?: (value: string) => Value[keyof Value];\n /* The serializer function to be invoked */\n serializer?: (value: Value[keyof Value]) => string;\n}\n\nexport const clearCookies = () => {\n document.cookie.split('; ').forEach((cookie) => {\n const [name] = cookie.split('=');\n removeCookie(name);\n });\n};\n\nconst clearCookieItems = () => {\n clearCookies();\n dispatchCookieEvent();\n};\n\n/**\n * @name useCookies\n * @description - Hook that manages cookie values\n * @category
|
|
1
|
+
{"version":3,"file":"useCookies.cjs","sources":["../../../../src/hooks/useCookies/useCookies.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport type { RemoveCookieParams, SetCookieParams } from '../useCookie/useCookie';\n\nimport {\n COOKIE_EVENT,\n dispatchCookieEvent,\n removeCookie,\n removeCookieItem,\n setCookieItem\n} from '../useCookie/useCookie';\n\n/** The cookies params type */\nexport type CookieParams = Record<string, any>;\n\n/* The use cookies options type */\nexport interface UseCookiesOptions<Value> {\n /* The deserializer function to be invoked */\n deserializer?: (value: string) => Value[keyof Value];\n /* The serializer function to be invoked */\n serializer?: (value: Value[keyof Value]) => string;\n}\n\nexport const clearCookies = () => {\n document.cookie.split('; ').forEach((cookie) => {\n const [name] = cookie.split('=');\n removeCookie(name);\n });\n};\n\nconst clearCookieItems = () => {\n clearCookies();\n dispatchCookieEvent();\n};\n\n/**\n * @name useCookies\n * @description - Hook that manages cookie values\n * @category State\n *\n * @overload\n * @template {object} Value The type of the cookie values\n * @returns {UseCookieReturn<Value>} The value and the set function\n *\n * @example\n * const { value, set, remove, getAll, clear } = useCookies();\n */\nexport const useCookies = <Value extends CookieParams>(options?: UseCookiesOptions<Value>) => {\n const serializer = (value: Value[keyof Value]) => {\n if (options?.serializer) return options.serializer(value);\n if (typeof value === 'string') return value;\n return JSON.stringify(value);\n };\n\n const deserializer = (value: string) => {\n if (options?.deserializer) return options.deserializer(value);\n if (value === 'undefined') return undefined as unknown as Value[keyof Value];\n\n try {\n return JSON.parse(value) as Value;\n } catch {\n return value as Value[keyof Value];\n }\n };\n\n const getParsedCookies = () => {\n if (!document.cookie) return {};\n\n return Object.fromEntries(\n document.cookie\n .split('; ')\n .map((cookie) => {\n const [key, ...value] = cookie.split('=');\n if (!key || !value.length) return [];\n const decodedValue = decodeURIComponent(value.join('='));\n return [key, deserializer(decodedValue)];\n })\n .filter((entry) => entry.length)\n );\n };\n\n const [value, setValue] = useState(() => {\n if (typeof window === 'undefined') return {} as Value;\n return getParsedCookies() as Value;\n });\n\n useEffect(() => {\n const onChange = () => setValue(getParsedCookies() as Value);\n\n window.addEventListener(COOKIE_EVENT, onChange);\n return () => {\n window.removeEventListener(COOKIE_EVENT, onChange);\n };\n }, []);\n\n const set = <Key extends keyof Value>(key: Key, value: Value[Key], options?: SetCookieParams) =>\n setCookieItem(key as string, serializer(value), options);\n\n const remove = <Key extends keyof Value>(key: Key, options?: RemoveCookieParams) =>\n removeCookieItem(key as string, options);\n const getAll = () => getParsedCookies();\n const clear = () => clearCookieItems();\n\n return { value, set, remove, getAll, clear };\n};\n"],"names":["clearCookies","cookie","name","removeCookie","clearCookieItems","dispatchCookieEvent","useCookies","options","serializer","value","deserializer","getParsedCookies","key","decodedValue","entry","setValue","useState","useEffect","onChange","COOKIE_EVENT","setCookieItem","removeCookieItem"],"mappings":"iJAuBaA,EAAe,IAAM,CAChC,SAAS,OAAO,MAAM,IAAI,EAAE,QAASC,GAAW,CAC9C,KAAM,CAACC,CAAI,EAAID,EAAO,MAAM,GAAG,EAC/BE,EAAAA,aAAaD,CAAI,CAAA,CAClB,CACH,EAEME,EAAmB,IAAM,CAC7BJ,EAAA,EACAK,sBAAA,CACF,EAcaC,EAA0CC,GAAuC,CAC5F,MAAMC,EAAcC,GACdF,GAAS,WAAmBA,EAAQ,WAAWE,CAAK,EACpD,OAAOA,GAAU,SAAiBA,EAC/B,KAAK,UAAUA,CAAK,EAGvBC,EAAgBD,GAAkB,CACtC,GAAIF,GAAS,aAAc,OAAOA,EAAQ,aAAaE,CAAK,EAC5D,GAAIA,IAAU,YAEd,GAAI,CACF,OAAO,KAAK,MAAMA,CAAK,CAAA,MACjB,CACN,OAAOA,CAAA,CACT,EAGIE,EAAmB,IAClB,SAAS,OAEP,OAAO,YACZ,SAAS,OACN,MAAM,IAAI,EACV,IAAKV,GAAW,CACf,KAAM,CAACW,EAAK,GAAGH,CAAK,EAAIR,EAAO,MAAM,GAAG,EACxC,GAAI,CAACW,GAAO,CAACH,EAAM,aAAe,CAAA,EAClC,MAAMI,EAAe,mBAAmBJ,EAAM,KAAK,GAAG,CAAC,EACvD,MAAO,CAACG,EAAKF,EAAaG,CAAY,CAAC,CAAA,CACxC,EACA,OAAQC,GAAUA,EAAM,MAAM,CAAA,EAXN,CAAA,EAezB,CAACL,EAAOM,CAAQ,EAAIC,EAAAA,SAAS,IAC7B,OAAO,OAAW,IAAoB,CAAA,EACnCL,EAAA,CACR,EAEDM,OAAAA,EAAAA,UAAU,IAAM,CACd,MAAMC,EAAW,IAAMH,EAASJ,GAA2B,EAE3D,cAAO,iBAAiBQ,EAAAA,aAAcD,CAAQ,EACvC,IAAM,CACX,OAAO,oBAAoBC,EAAAA,aAAcD,CAAQ,CAAA,CACnD,EACC,EAAE,EAUE,CAAE,MAAAT,EAAO,IARJ,CAA0BG,EAAUH,EAAmBF,IACjEa,gBAAcR,EAAeJ,EAAWC,CAAK,EAAGF,CAAO,EAOpC,OALN,CAA0BK,EAAUL,IACjDc,EAAAA,iBAAiBT,EAAeL,CAAO,EAIZ,OAHd,IAAMI,EAAA,EAGgB,MAFvB,IAAMP,EAAA,CAEiB,CACvC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCounter.cjs","sources":["../../../../src/hooks/useCounter/useCounter.ts"],"sourcesContent":["import type { Dispatch, SetStateAction } from 'react';\n\nimport { useState } from 'react';\n\n/** The use counter options */\nexport interface UseCounterOptions {\n /** The max of count value */\n max?: number;\n /** The min of count value */\n min?: number;\n}\n\n/** The use counter return type */\nexport interface UseCounterReturn {\n /** Function to set a specific value to the counter */\n set: Dispatch<SetStateAction<number>>;\n /** The current count value */\n value: number;\n /** Function to decrement the counter */\n dec: (value?: number) => void;\n /** Function to increment the counter */\n inc: (value?: number) => void;\n /** Function to reset the counter to its initial value. */\n reset: () => void;\n}\n\nexport interface UseCounter {\n (initialValue?: number, options?: UseCounterOptions): UseCounterReturn;\n\n (options: UseCounterOptions & { initialValue?: number }, initialValue?: never): UseCounterReturn;\n}\n\n/**\n * @name useCounter\n * @description - Hook that manages a counter\n * @category
|
|
1
|
+
{"version":3,"file":"useCounter.cjs","sources":["../../../../src/hooks/useCounter/useCounter.ts"],"sourcesContent":["import type { Dispatch, SetStateAction } from 'react';\n\nimport { useState } from 'react';\n\n/** The use counter options */\nexport interface UseCounterOptions {\n /** The max of count value */\n max?: number;\n /** The min of count value */\n min?: number;\n}\n\n/** The use counter return type */\nexport interface UseCounterReturn {\n /** Function to set a specific value to the counter */\n set: Dispatch<SetStateAction<number>>;\n /** The current count value */\n value: number;\n /** Function to decrement the counter */\n dec: (value?: number) => void;\n /** Function to increment the counter */\n inc: (value?: number) => void;\n /** Function to reset the counter to its initial value. */\n reset: () => void;\n}\n\nexport interface UseCounter {\n (initialValue?: number, options?: UseCounterOptions): UseCounterReturn;\n\n (options: UseCounterOptions & { initialValue?: number }, initialValue?: never): UseCounterReturn;\n}\n\n/**\n * @name useCounter\n * @description - Hook that manages a counter\n * @category State\n *\n * @overload\n * @param {number} [initialValue=0] The initial number value\n * @param {number} [options.min=Number.NEGATIVE_INFINITY] The min of count value\n * @param {number} [options.max=Number.POSITIVE_INFINITY] The max of count value\n * @returns {UseCounterReturn} An object containing the current count and functions to interact with the counter\n\n * @overload\n * @param {number} [params.initialValue=0] The initial number value\n * @param {number} [params.min=Number.NEGATIVE_INFINITY] The min of count value\n * @param {number} [params.max=Number.POSITIVE_INFINITY] The max of count value\n * @returns {UseCounterReturn} An object containing the current count and functions to interact with the counter\n *\n * @example\n * const { count, dec, inc, reset, set } = useCounter(5);\n *\n * @example\n * const { count, dec, inc, reset, set } = useCounter({ initialValue: 5, min: 0, max: 10 });\n */\nexport const useCounter = ((...params: any[]) => {\n const initialValue =\n typeof params[0] === 'number'\n ? params[0]\n : (params[0] as UseCounterOptions & { initialValue?: number })?.initialValue;\n const { max = Number.POSITIVE_INFINITY, min = Number.NEGATIVE_INFINITY } =\n typeof params[0] === 'number'\n ? ((params[1] ?? {}) as UseCounterOptions)\n : ((params[0] ?? {}) as UseCounterOptions & { initialValue?: number });\n\n const [value, setValue] = useState(initialValue ?? 0);\n\n const inc = (value: number = 1) => {\n setValue((prevValue) => {\n if (typeof max === 'number' && prevValue === max) return prevValue;\n return Math.max(Math.min(max, prevValue + value), min);\n });\n };\n\n const dec = (value: number = 1) => {\n setValue((prevValue) => {\n if (typeof min === 'number' && prevValue === min) return prevValue;\n return Math.min(Math.max(min, prevValue - value), max);\n });\n };\n\n const reset = () => {\n const value = initialValue ?? 0;\n if (typeof max === 'number' && value > max) return setValue(max);\n if (typeof min === 'number' && value < min) return setValue(min);\n setValue(value);\n };\n\n const set = (value: SetStateAction<number>) => {\n setValue((prevValue) => {\n const updatedCount = Math.max(\n min,\n Math.min(max, typeof value === 'number' ? value : value(prevValue))\n );\n\n return updatedCount;\n });\n };\n\n return { value, set, inc, dec, reset };\n}) as UseCounter;\n"],"names":["useCounter","params","initialValue","max","min","value","setValue","useState","prevValue"],"mappings":"yGAuDaA,EAAc,IAAIC,IAAkB,CAC/C,MAAMC,EACJ,OAAOD,EAAO,CAAC,GAAM,SACjBA,EAAO,CAAC,EACPA,EAAO,CAAC,GAAqD,aAC9D,CAAE,IAAAE,EAAM,OAAO,kBAAmB,IAAAC,EAAM,OAAO,iBAAA,EACnD,OAAOH,EAAO,CAAC,GAAM,SACfA,EAAO,CAAC,GAAK,CAAA,EACbA,EAAO,CAAC,GAAK,CAAA,EAEf,CAACI,EAAOC,CAAQ,EAAIC,EAAAA,SAASL,GAAgB,CAAC,EAkCpD,MAAO,CAAE,MAAAG,EAAO,IAXHA,GAAkC,CAC7CC,EAAUE,GACa,KAAK,IACxBJ,EACA,KAAK,IAAID,EAAK,OAAOE,GAAU,SAAWA,EAAQA,EAAMG,CAAS,CAAC,CAAA,CAIrE,CAAA,EAGkB,IAhCT,CAACH,EAAgB,IAAM,CACjCC,EAAUE,GACJ,OAAOL,GAAQ,UAAYK,IAAcL,EAAYK,EAClD,KAAK,IAAI,KAAK,IAAIL,EAAKK,EAAYH,CAAK,EAAGD,CAAG,CACtD,CAAA,EA4BuB,IAzBd,CAACC,EAAgB,IAAM,CACjCC,EAAUE,GACJ,OAAOJ,GAAQ,UAAYI,IAAcJ,EAAYI,EAClD,KAAK,IAAI,KAAK,IAAIJ,EAAKI,EAAYH,CAAK,EAAGF,CAAG,CACtD,CAAA,EAqB4B,MAlBjB,IAAM,CAClB,MAAME,EAAQH,GAAgB,EAC9B,GAAI,OAAOC,GAAQ,UAAYE,EAAQF,EAAK,OAAOG,EAASH,CAAG,EAC/D,GAAI,OAAOC,GAAQ,UAAYC,EAAQD,EAAK,OAAOE,EAASF,CAAG,EAC/DE,EAASD,CAAK,CAAA,CAce,CACjC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react"),v=require("../useRefState/useRefState.cjs"),w=require("../../utils/helpers/isTarget.cjs"),d=require("../../utils/helpers/getElement.cjs"),E=(...n)=>{const t=w.isTarget(n[0])?n[0]:void 0,o=t?n[1]:n[0],r=t?n[2]:n[1],[f,u]=i.useState(r??""),c=v.useRefState(),s=i.useRef(null),y=e=>{if(!s.current)return;const l=s.current;l.style&&(l.style.setProperty(o,e),u(e))},m=()=>{if(!s.current)return;const e=s.current;e.style&&(e.style.removeProperty(o),u(""))};return i.useEffect(()=>{if(!r)return;const e=(t?d.getElement(t):c.current)??window.document.documentElement;e.style&&(e.style.setProperty(o,r),u(r))},[]),i.useEffect(()=>{const e=(t?d.getElement(t):c.current)??window.document.documentElement;s.current=e;const l=()=>{const g=window.getComputedStyle(e).getPropertyValue(o)?.trim();u(g??r)},a=new MutationObserver(l);return a.observe(e,{attributeFilter:["style","class"]}),()=>{a.disconnect()}},[t,c.state]),t?{value:f,set:y,remove:m}:{ref:c,value:f,set:y,remove:m}};exports.useCssVar=E;
|
|
2
2
|
//# sourceMappingURL=useCssVar.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCssVar.cjs","sources":["../../../../src/hooks/useCssVar/useCssVar.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The css variable return type */\nexport interface UseCssVarReturn {\n /** The value of the CSS variable */\n value: string;\n /** Remove the value of the CSS variable */\n remove: () => void;\n /** Set the value of the CSS variable */\n set: (value: string) => void;\n}\n\nexport interface UseCssVar {\n <Target extends HTMLElement>(\n key: string,\n initialValue?: string\n ): UseCssVarReturn & {\n ref: StateRef<Target>;\n };\n\n (target: HookTarget, key: string, initialValue?: string): UseCssVarReturn;\n}\n\n/**\n * @name useCssVar\n * @description - Hook that returns the value of a css variable\n * @category
|
|
1
|
+
{"version":3,"file":"useCssVar.cjs","sources":["../../../../src/hooks/useCssVar/useCssVar.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The css variable return type */\nexport interface UseCssVarReturn {\n /** The value of the CSS variable */\n value: string;\n /** Remove the value of the CSS variable */\n remove: () => void;\n /** Set the value of the CSS variable */\n set: (value: string) => void;\n}\n\nexport interface UseCssVar {\n <Target extends HTMLElement>(\n key: string,\n initialValue?: string\n ): UseCssVarReturn & {\n ref: StateRef<Target>;\n };\n\n (target: HookTarget, key: string, initialValue?: string): UseCssVarReturn;\n}\n\n/**\n * @name useCssVar\n * @description - Hook that returns the value of a css variable\n * @category Browser\n *\n * @overload\n * @param {string} key The CSS variable key\n * @param {string} initialValue The initial value of the CSS variable\n * @returns {UseCssVarReturn & { ref: StateRef<Element> }} The object containing the value of the CSS variable and ref\n *\n * @example\n * const { ref, value, set, remove } = useCssVar('--color', 'red');\n *\n * @overload\n * @param {HookTarget} target The target element\n * @param {string} key The CSS variable key\n * @param {string} initialValue The initial value of the CSS variable\n * @returns {UseCssVarReturn} The object containing the value of the CSS variable\n *\n * @example\n * const { value, set, remove } = useCssVar(ref, '--color', 'red');\n */\nexport const useCssVar = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const key = (target ? params[1] : params[0]) as string;\n const initialValue = (target ? params[2] : params[1]) as string | undefined;\n\n const [value, setValue] = useState(initialValue ?? '');\n const internalRef = useRefState<HTMLElement>();\n const elementRef = useRef<HTMLElement>(null);\n\n const set = (value: string) => {\n if (!elementRef.current) return;\n const element = elementRef.current;\n\n if (!element.style) return;\n element.style.setProperty(key, value);\n setValue(value);\n };\n\n const remove = () => {\n if (!elementRef.current) return;\n const element = elementRef.current;\n if (!element.style) return;\n\n element.style.removeProperty(key);\n setValue('');\n };\n\n useEffect(() => {\n if (!initialValue) return;\n\n const element =\n ((target ? getElement(target) : internalRef.current) as HTMLElement) ??\n window.document.documentElement;\n\n if (!element.style) return;\n element.style.setProperty(key, initialValue);\n setValue(initialValue);\n }, []);\n\n useEffect(() => {\n const element =\n ((target ? getElement(target) : internalRef.current) as HTMLElement) ??\n window.document.documentElement;\n\n elementRef.current = element;\n\n const onChange = () => {\n const value = window.getComputedStyle(element).getPropertyValue(key)?.trim();\n\n setValue(value ?? initialValue);\n };\n\n const observer = new MutationObserver(onChange);\n\n observer.observe(element, { attributeFilter: ['style', 'class'] });\n\n return () => {\n observer.disconnect();\n };\n }, [target, internalRef.state]);\n\n if (target) return { value, set, remove };\n return { ref: internalRef, value, set, remove };\n}) as UseCssVar;\n"],"names":["useCssVar","params","target","isTarget","key","initialValue","value","setValue","useState","internalRef","useRefState","elementRef","useRef","set","element","remove","useEffect","getElement","onChange","observer"],"mappings":"mPAqDaA,EAAa,IAAIC,IAAkB,CAC9C,MAAMC,EAAUC,EAAAA,SAASF,EAAO,CAAC,CAAC,EAAIA,EAAO,CAAC,EAAI,OAC5CG,EAAOF,EAASD,EAAO,CAAC,EAAIA,EAAO,CAAC,EACpCI,EAAgBH,EAASD,EAAO,CAAC,EAAIA,EAAO,CAAC,EAE7C,CAACK,EAAOC,CAAQ,EAAIC,EAAAA,SAASH,GAAgB,EAAE,EAC/CI,EAAcC,EAAAA,YAAA,EACdC,EAAaC,EAAAA,OAAoB,IAAI,EAErCC,EAAOP,GAAkB,CAC7B,GAAI,CAACK,EAAW,QAAS,OACzB,MAAMG,EAAUH,EAAW,QAEtBG,EAAQ,QACbA,EAAQ,MAAM,YAAYV,EAAKE,CAAK,EACpCC,EAASD,CAAK,EAAA,EAGVS,EAAS,IAAM,CACnB,GAAI,CAACJ,EAAW,QAAS,OACzB,MAAMG,EAAUH,EAAW,QACtBG,EAAQ,QAEbA,EAAQ,MAAM,eAAeV,CAAG,EAChCG,EAAS,EAAE,EAAA,EAqCb,OAlCAS,EAAAA,UAAU,IAAM,CACd,GAAI,CAACX,EAAc,OAEnB,MAAMS,GACFZ,EAASe,aAAWf,CAAM,EAAIO,EAAY,UAC5C,OAAO,SAAS,gBAEbK,EAAQ,QACbA,EAAQ,MAAM,YAAYV,EAAKC,CAAY,EAC3CE,EAASF,CAAY,EAAA,EACpB,EAAE,EAELW,EAAAA,UAAU,IAAM,CACd,MAAMF,GACFZ,EAASe,aAAWf,CAAM,EAAIO,EAAY,UAC5C,OAAO,SAAS,gBAElBE,EAAW,QAAUG,EAErB,MAAMI,EAAW,IAAM,CACrB,MAAMZ,EAAQ,OAAO,iBAAiBQ,CAAO,EAAE,iBAAiBV,CAAG,GAAG,KAAA,EAEtEG,EAASD,GAASD,CAAY,CAAA,EAG1Bc,EAAW,IAAI,iBAAiBD,CAAQ,EAE9C,OAAAC,EAAS,QAAQL,EAAS,CAAE,gBAAiB,CAAC,QAAS,OAAO,EAAG,EAE1D,IAAM,CACXK,EAAS,WAAA,CAAW,CACtB,EACC,CAACjB,EAAQO,EAAY,KAAK,CAAC,EAE1BP,EAAe,CAAE,MAAAI,EAAO,IAAAO,EAAK,OAAAE,CAAA,EAC1B,CAAE,IAAKN,EAAa,MAAAH,EAAO,IAAAO,EAAK,OAAAE,CAAA,CACzC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDefault.cjs","sources":["../../../../src/hooks/useDefault/useDefault.ts"],"sourcesContent":["import { useState } from 'react';\n\n/**\n * @name useDefault\n * @description - Hook that returns the default value\n * @category
|
|
1
|
+
{"version":3,"file":"useDefault.cjs","sources":["../../../../src/hooks/useDefault/useDefault.ts"],"sourcesContent":["import { useState } from 'react';\n\n/**\n * @name useDefault\n * @description - Hook that returns the default value\n * @category State\n *\n * @template Value The type of the value\n * @param {Value} initialValue The initial value\n * @param {Value} defaultValue The default value\n * @returns {[Value, (value: Value) => void]} An array containing the current value and a function to set the value\n *\n * @example\n * const [value, setValue] = useDefault(initialValue, defaultValue);\n */\nexport const useDefault = <Value>(initialValue: (() => Value) | Value, defaultValue: Value) => {\n const [value, setValue] = useState<Value | null | undefined>(initialValue);\n return [value === undefined || value === null ? defaultValue : value, setValue] as const;\n};\n"],"names":["useDefault","initialValue","defaultValue","value","setValue","useState"],"mappings":"yGAeaA,EAAa,CAAQC,EAAqCC,IAAwB,CAC7F,KAAM,CAACC,EAAOC,CAAQ,EAAIC,EAAAA,SAAmCJ,CAAY,EACzE,MAAO,CAAwBE,GAAiBD,EAAsBE,CAAQ,CAChF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDisclosure.cjs","sources":["../../../../src/hooks/useDisclosure/useDisclosure.ts"],"sourcesContent":["import { useState } from 'react';\n\n/** The use disclosure options type */\nexport interface UseDisclosureOptions {\n /** The callback function to be invoked on close */\n onClose?: () => void;\n /** The callback function to be invoked on open */\n onOpen?: () => void;\n}\n\n/** The use disclosure return type */\nexport interface UseDisclosureReturn {\n /** The opened value */\n opened: boolean;\n /** Function to close the modal */\n close: () => void;\n /** Function to open the modal */\n open: () => void;\n /** Function to toggle the modal */\n toggle: () => void;\n}\n\n/**\n * @name useDisclosure\n * @description - Hook that allows you to open and close a modal\n * @category
|
|
1
|
+
{"version":3,"file":"useDisclosure.cjs","sources":["../../../../src/hooks/useDisclosure/useDisclosure.ts"],"sourcesContent":["import { useState } from 'react';\n\n/** The use disclosure options type */\nexport interface UseDisclosureOptions {\n /** The callback function to be invoked on close */\n onClose?: () => void;\n /** The callback function to be invoked on open */\n onOpen?: () => void;\n}\n\n/** The use disclosure return type */\nexport interface UseDisclosureReturn {\n /** The opened value */\n opened: boolean;\n /** Function to close the modal */\n close: () => void;\n /** Function to open the modal */\n open: () => void;\n /** Function to toggle the modal */\n toggle: () => void;\n}\n\n/**\n * @name useDisclosure\n * @description - Hook that allows you to open and close a modal\n * @category State\n *\n * @param {boolean} [initialValue=false] The initial value of the component\n * @param {() => void} [options.onOpen] The callback function to be invoked on open\n * @param {() => void} [options.onClose] The callback function to be invoked on close\n * @returns {UseDisclosureReturn} An object with the opened, open, close, and toggle properties\n *\n * @example\n * const { opened, open, close, toggle } = useDisclosure();\n */\nexport const useDisclosure = (\n initialValue = false,\n options?: UseDisclosureOptions\n): UseDisclosureReturn => {\n const [opened, setOpened] = useState(initialValue);\n\n const open = () =>\n setOpened((opened) => {\n if (!opened) {\n options?.onOpen?.();\n return true;\n }\n return opened;\n });\n\n const close = () =>\n setOpened((opened) => {\n if (opened) {\n options?.onClose?.();\n return false;\n }\n return opened;\n });\n\n const toggle = () => (opened ? close() : open());\n\n return { opened, open, close, toggle };\n};\n"],"names":["useDisclosure","initialValue","options","opened","setOpened","useState","open","close"],"mappings":"yGAmCaA,EAAgB,CAC3BC,EAAe,GACfC,IACwB,CACxB,KAAM,CAACC,EAAQC,CAAS,EAAIC,EAAAA,SAASJ,CAAY,EAE3CK,EAAO,IACXF,EAAWD,GACJA,IACHD,GAAS,SAAA,EACF,GAGV,EAEGK,EAAQ,IACZH,EAAWD,GACLA,IACFD,GAAS,UAAA,EACF,GAGV,EAIH,MAAO,CAAE,OAAAC,EAAQ,KAAAG,EAAM,MAAAC,EAAO,OAFf,IAAOJ,EAASI,EAAA,EAAUD,EAAA,CAEX,CAChC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDisplayMedia.cjs","sources":["../../../../src/hooks/useDisplayMedia/useDisplayMedia.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use display media return type */\nexport interface UseDisplayMediaReturn {\n /** Whether screen sharing is currently active */\n sharing: boolean;\n /** The media stream object */\n stream: MediaStream | null;\n /** Whether the display media API is supported */\n supported: boolean;\n /** Start screen sharing */\n start: () => Promise<void>;\n /** Stop screen sharing */\n stop: () => void;\n}\n\n/** The use display media options type */\nexport interface UseDisplayMediaOptions {\n /** Whether to enable audio sharing */\n audio?: boolean | MediaTrackConstraints;\n /** Whether to start immediately */\n immediately?: boolean;\n /** Whether to enable video sharing */\n video?: boolean | MediaTrackConstraints;\n}\n\nexport interface UseDisplayMedia {\n (target: HookTarget, options?: UseDisplayMediaOptions): UseDisplayMediaReturn;\n\n <Target extends HTMLVideoElement>(\n options?: UseDisplayMediaOptions,\n target?: never\n ): { ref: StateRef<Target> } & UseDisplayMediaReturn;\n}\n\n/**\n * @name useDisplayMedia\n * @description - Hook that provides screen sharing functionality\n * @category Browser\n *\n * @browserapi mediaDevices.getDisplayMedia https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getDisplayMedia\n *\n * @overload\n * @param {HookTarget} target The target video element to display the media stream\n * @param {boolean | MediaTrackConstraints} [options.audio] Whether to enable audio sharing\n * @param {boolean} [options.immediately=false] Whether to start immediately\n * @param {boolean | MediaTrackConstraints} [options.video] Whether to enable video sharing\n * @returns {UseDisplayMediaReturn} Object containing stream, sharing status and control methods\n *\n * @example\n * const { stream, sharing, start, stop } = useDisplayMedia(ref);\n *\n * @overload\n * @template Target The target video element\n * @param {boolean | MediaTrackConstraints} [options.audio] Whether to enable audio sharing\n * @param {boolean} [options.immediately=false] Whether to start immediately\n * @param {boolean | MediaTrackConstraints} [options.video] Whether to enable video sharing\n * @returns {UseDisplayMediaReturn & { ref: StateRef<HTMLVideoElement> }} Object containing stream, sharing status, control methods and ref\n *\n * @example\n * const { ref, stream, sharing, start, stop } = useDisplayMedia<HTMLVideoElement>();\n */\nexport const useDisplayMedia = ((...params: any[]) => {\n const supported =\n typeof navigator !== 'undefined' &&\n 'mediaDevices' in navigator &&\n !!navigator.mediaDevices &&\n 'getDisplayMedia' in navigator.mediaDevices;\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const options = (params[1] ? params[1] : params[0]) as UseDisplayMediaOptions | undefined;\n const immediately = options?.immediately ?? false;\n\n const [sharing, setSharing] = useState(false);\n\n const elementRef = useRef<HTMLVideoElement
|
|
1
|
+
{"version":3,"file":"useDisplayMedia.cjs","sources":["../../../../src/hooks/useDisplayMedia/useDisplayMedia.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use display media return type */\nexport interface UseDisplayMediaReturn {\n /** Whether screen sharing is currently active */\n sharing: boolean;\n /** The media stream object */\n stream: MediaStream | null;\n /** Whether the display media API is supported */\n supported: boolean;\n /** Start screen sharing */\n start: () => Promise<void>;\n /** Stop screen sharing */\n stop: () => void;\n}\n\n/** The use display media options type */\nexport interface UseDisplayMediaOptions {\n /** Whether to enable audio sharing */\n audio?: boolean | MediaTrackConstraints;\n /** Whether to start immediately */\n immediately?: boolean;\n /** Whether to enable video sharing */\n video?: boolean | MediaTrackConstraints;\n}\n\nexport interface UseDisplayMedia {\n (target: HookTarget, options?: UseDisplayMediaOptions): UseDisplayMediaReturn;\n\n <Target extends HTMLVideoElement>(\n options?: UseDisplayMediaOptions,\n target?: never\n ): { ref: StateRef<Target> } & UseDisplayMediaReturn;\n}\n\n/**\n * @name useDisplayMedia\n * @description - Hook that provides screen sharing functionality\n * @category Browser\n *\n * @browserapi mediaDevices.getDisplayMedia https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getDisplayMedia\n *\n * @overload\n * @param {HookTarget} target The target video element to display the media stream\n * @param {boolean | MediaTrackConstraints} [options.audio] Whether to enable audio sharing\n * @param {boolean} [options.immediately=false] Whether to start immediately\n * @param {boolean | MediaTrackConstraints} [options.video] Whether to enable video sharing\n * @returns {UseDisplayMediaReturn} Object containing stream, sharing status and control methods\n *\n * @example\n * const { stream, sharing, start, stop } = useDisplayMedia(ref);\n *\n * @overload\n * @template Target The target video element\n * @param {boolean | MediaTrackConstraints} [options.audio] Whether to enable audio sharing\n * @param {boolean} [options.immediately=false] Whether to start immediately\n * @param {boolean | MediaTrackConstraints} [options.video] Whether to enable video sharing\n * @returns {UseDisplayMediaReturn & { ref: StateRef<HTMLVideoElement> }} Object containing stream, sharing status, control methods and ref\n *\n * @example\n * const { ref, stream, sharing, start, stop } = useDisplayMedia<HTMLVideoElement>();\n */\nexport const useDisplayMedia = ((...params: any[]) => {\n const supported =\n typeof navigator !== 'undefined' &&\n 'mediaDevices' in navigator &&\n !!navigator.mediaDevices &&\n 'getDisplayMedia' in navigator.mediaDevices;\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const options = (params[1] ? params[1] : params[0]) as UseDisplayMediaOptions | undefined;\n const immediately = options?.immediately ?? false;\n\n const [sharing, setSharing] = useState(false);\n\n const elementRef = useRef<HTMLVideoElement>(null);\n const streamRef = useRef<MediaStream>(null);\n const internalRef = useRefState<Element>();\n\n const stop = () => {\n if (!streamRef.current || !supported || !elementRef.current) return;\n\n setSharing(false);\n elementRef.current.srcObject = null;\n streamRef.current.getTracks().forEach((track) => track.stop());\n streamRef.current = null;\n };\n\n const start = async () => {\n if (!supported || !elementRef.current) return;\n\n const displayMedia = await navigator.mediaDevices.getDisplayMedia({\n video: options?.video,\n audio: options?.audio\n });\n\n setSharing(true);\n streamRef.current = displayMedia;\n elementRef.current.srcObject = displayMedia;\n\n displayMedia.getTracks().forEach((track) => (track.onended = stop));\n return displayMedia;\n };\n\n useEffect(() => {\n if (!supported || (!target && !internalRef.state)) return;\n\n const element = (target ? getElement(target) : internalRef.current) as HTMLVideoElement;\n\n if (!element) return;\n\n elementRef.current = element;\n\n if (!immediately) return;\n\n start();\n\n return () => {\n stop();\n };\n }, [target, internalRef.state]);\n\n if (target)\n return {\n stream: streamRef.current,\n sharing,\n supported,\n start,\n stop\n };\n\n return {\n stream: streamRef.current,\n sharing,\n supported,\n start,\n stop,\n ref: internalRef\n };\n}) as UseDisplayMedia;\n"],"names":["useDisplayMedia","params","supported","target","isTarget","options","immediately","sharing","setSharing","useState","elementRef","useRef","streamRef","internalRef","useRefState","stop","track","start","displayMedia","useEffect","element","getElement"],"mappings":"mPAsEaA,EAAmB,IAAIC,IAAkB,CACpD,MAAMC,EACJ,OAAO,UAAc,KACrB,iBAAkB,WAClB,CAAC,CAAC,UAAU,cACZ,oBAAqB,UAAU,aAC3BC,EAAUC,EAAAA,SAASH,EAAO,CAAC,CAAC,EAAIA,EAAO,CAAC,EAAI,OAC5CI,EAAWJ,EAAO,CAAC,EAAIA,EAAO,CAAC,EAAIA,EAAO,CAAC,EAC3CK,EAAcD,GAAS,aAAe,GAEtC,CAACE,EAASC,CAAU,EAAIC,EAAAA,SAAS,EAAK,EAEtCC,EAAaC,EAAAA,OAAyB,IAAI,EAC1CC,EAAYD,EAAAA,OAAoB,IAAI,EACpCE,EAAcC,EAAAA,YAAA,EAEdC,EAAO,IAAM,CACb,CAACH,EAAU,SAAW,CAACV,GAAa,CAACQ,EAAW,UAEpDF,EAAW,EAAK,EAChBE,EAAW,QAAQ,UAAY,KAC/BE,EAAU,QAAQ,YAAY,QAASI,GAAUA,EAAM,MAAM,EAC7DJ,EAAU,QAAU,KAAA,EAGhBK,EAAQ,SAAY,CACxB,GAAI,CAACf,GAAa,CAACQ,EAAW,QAAS,OAEvC,MAAMQ,EAAe,MAAM,UAAU,aAAa,gBAAgB,CAChE,MAAOb,GAAS,MAChB,MAAOA,GAAS,KAAA,CACjB,EAED,OAAAG,EAAW,EAAI,EACfI,EAAU,QAAUM,EACpBR,EAAW,QAAQ,UAAYQ,EAE/BA,EAAa,YAAY,QAASF,GAAWA,EAAM,QAAUD,CAAK,EAC3DG,CAAA,EAqBT,OAlBAC,EAAAA,UAAU,IAAM,CACd,GAAI,CAACjB,GAAc,CAACC,GAAU,CAACU,EAAY,MAAQ,OAEnD,MAAMO,EAAWjB,EAASkB,EAAAA,WAAWlB,CAAM,EAAIU,EAAY,QAE3D,GAAKO,IAELV,EAAW,QAAUU,EAEjB,EAACd,GAEL,OAAAW,EAAA,EAEO,IAAM,CACXF,EAAA,CAAK,CACP,EACC,CAACZ,EAAQU,EAAY,KAAK,CAAC,EAE1BV,EACK,CACL,OAAQS,EAAU,QAClB,QAAAL,EACA,UAAAL,EACA,MAAAe,EACA,KAAAF,CAAA,EAGG,CACL,OAAQH,EAAU,QAClB,QAAAL,EACA,UAAAL,EACA,MAAAe,EACA,KAAAF,EACA,IAAKF,CAAA,CAET"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDocumentTitle.cjs","sources":["../../../../src/hooks/useDocumentTitle/useDocumentTitle.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\n/** The use document title options type */\nexport interface UseDocumentTitleOptions {\n /** Restore the previous title on unmount */\n restoreOnUnmount?: boolean;\n}\n\n/** The use document title return type */\nexport interface UseDocumentTitleReturn {\n /** The current title */\n value: string;\n /** Function to update the title */\n set: (title: string) => void;\n}\n\n/**\n * @name useDocumentTitle\n * @description - Hook that manages the document title and allows updating it\n * @category Browser\n *\n * @param {string} [initialValue] The initial title. If not provided, the current document title will be used\n * @param {boolean} [options.restoreOnUnmount] Restore the previous title on unmount\n * @returns {UseDocumentTitleReturn} An array containing the current title and a function to update the title\n *\n * @example\n * const { value, set } = useDocumentTitle();\n */\nexport function useDocumentTitle(\n initialValue?: string,\n options?: UseDocumentTitleOptions\n): UseDocumentTitleReturn {\n const prevValueRef = useRef(document.title);\n const [value, setValue] = useState(initialValue ?? document.title);\n\n const set = (value: string) => {\n const updatedValue = value.trim();\n if (updatedValue.length > 0) document.title = updatedValue;\n };\n\n useEffect(() => {\n if (typeof value !== 'string') return;\n set(value);\n }, [value]);\n\n useEffect(() => {\n const observer = new MutationObserver(() => {\n setValue((prevValue) => {\n if (document && document.title !== prevValue) {\n return document.title;\n }\n return prevValue;\n });\n });\n\n observer.observe(document.head.querySelector('title')!, {
|
|
1
|
+
{"version":3,"file":"useDocumentTitle.cjs","sources":["../../../../src/hooks/useDocumentTitle/useDocumentTitle.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\n/** The use document title options type */\nexport interface UseDocumentTitleOptions {\n /** Restore the previous title on unmount */\n restoreOnUnmount?: boolean;\n}\n\n/** The use document title return type */\nexport interface UseDocumentTitleReturn {\n /** The current title */\n value: string;\n /** Function to update the title */\n set: (title: string) => void;\n}\n\n/**\n * @name useDocumentTitle\n * @description - Hook that manages the document title and allows updating it\n * @category Browser\n *\n * @browserapi document.title https://developer.mozilla.org/en-US/docs/Web/API/Document/title\n *\n * @param {string} [initialValue] The initial title. If not provided, the current document title will be used\n * @param {boolean} [options.restoreOnUnmount] Restore the previous title on unmount\n * @returns {UseDocumentTitleReturn} An array containing the current title and a function to update the title\n *\n * @example\n * const { value, set } = useDocumentTitle();\n */\nexport function useDocumentTitle(\n initialValue?: string,\n options?: UseDocumentTitleOptions\n): UseDocumentTitleReturn {\n const prevValueRef = useRef(document.title);\n const [value, setValue] = useState(initialValue ?? document.title);\n\n const set = (value: string) => {\n const updatedValue = value.trim();\n if (updatedValue.length > 0) document.title = updatedValue;\n };\n\n useEffect(() => {\n if (typeof value !== 'string') return;\n set(value);\n }, [value]);\n\n useEffect(() => {\n const observer = new MutationObserver(() => {\n setValue((prevValue) => {\n if (document && document.title !== prevValue) {\n return document.title;\n }\n return prevValue;\n });\n });\n\n observer.observe(document.head.querySelector('title')!, {\n childList: true\n });\n\n return () => {\n observer.disconnect();\n };\n }, []);\n\n useEffect(() => {\n if (options?.restoreOnUnmount) {\n return () => {\n document.title = prevValueRef.current;\n };\n }\n }, []);\n\n return { value, set };\n}\n"],"names":["useDocumentTitle","initialValue","options","prevValueRef","useRef","value","setValue","useState","set","updatedValue","useEffect","observer","prevValue"],"mappings":"yGA8BO,SAASA,EACdC,EACAC,EACwB,CACxB,MAAMC,EAAeC,EAAAA,OAAO,SAAS,KAAK,EACpC,CAACC,EAAOC,CAAQ,EAAIC,EAAAA,SAASN,GAAgB,SAAS,KAAK,EAE3DO,EAAOH,GAAkB,CAC7B,MAAMI,EAAeJ,EAAM,KAAA,EACvBI,EAAa,OAAS,IAAG,SAAS,MAAQA,EAAA,EAGhDC,OAAAA,EAAAA,UAAU,IAAM,CACV,OAAOL,GAAU,UACrBG,EAAIH,CAAK,CAAA,EACR,CAACA,CAAK,CAAC,EAEVK,EAAAA,UAAU,IAAM,CACd,MAAMC,EAAW,IAAI,iBAAiB,IAAM,CAC1CL,EAAUM,GACJ,UAAY,SAAS,QAAUA,EAC1B,SAAS,MAEXA,CACR,CAAA,CACF,EAED,OAAAD,EAAS,QAAQ,SAAS,KAAK,cAAc,OAAO,EAAI,CACtD,UAAW,EAAA,CACZ,EAEM,IAAM,CACXA,EAAS,WAAA,CAAW,CACtB,EACC,EAAE,EAELD,EAAAA,UAAU,IAAM,CACd,GAAIR,GAAS,iBACX,MAAO,IAAM,CACX,SAAS,MAAQC,EAAa,OAAA,CAElC,EACC,EAAE,EAEE,CAAE,MAAAE,EAAO,IAAAG,CAAA,CAClB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDoubleClick.cjs","sources":["../../../../src/hooks/useDoubleClick/useDoubleClick.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\nexport type DoubleClickEvents = MouseEvent | TouchEvent;\n\n/** The use double click options type */\nexport interface UseDoubleClickOptions {\n /** The threshold time in milliseconds between clicks */\n threshold?: number;\n /** The callback function to be invoked on single click */\n onSingleClick?: (event: DoubleClickEvents) => void;\n}\n\nexport interface UseDoubleClick {\n (\n target: HookTarget,\n callback: (event: DoubleClickEvents) => void,\n options?: UseDoubleClickOptions\n ): boolean;\n\n <Target extends Element>(\n callback: (event: DoubleClickEvents) => void,\n options?: UseDoubleClickOptions,\n target?: never\n ): StateRef<Target>;\n}\n\nexport const DEFAULT_THRESHOLD_TIME = 300;\n\n/**\n * @name useDoubleClick\n * @description - Hook that defines the logic when double clicking an element\n * @category
|
|
1
|
+
{"version":3,"file":"useDoubleClick.cjs","sources":["../../../../src/hooks/useDoubleClick/useDoubleClick.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\nexport type DoubleClickEvents = MouseEvent | TouchEvent;\n\n/** The use double click options type */\nexport interface UseDoubleClickOptions {\n /** The threshold time in milliseconds between clicks */\n threshold?: number;\n /** The callback function to be invoked on single click */\n onSingleClick?: (event: DoubleClickEvents) => void;\n}\n\nexport interface UseDoubleClick {\n (\n target: HookTarget,\n callback: (event: DoubleClickEvents) => void,\n options?: UseDoubleClickOptions\n ): boolean;\n\n <Target extends Element>(\n callback: (event: DoubleClickEvents) => void,\n options?: UseDoubleClickOptions,\n target?: never\n ): StateRef<Target>;\n}\n\nexport const DEFAULT_THRESHOLD_TIME = 300;\n\n/**\n * @name useDoubleClick\n * @description - Hook that defines the logic when double clicking an element\n * @category Elements\n *\n * @overload\n * @param {HookTarget} target The target element to be double clicked\n * @param {(event: DoubleClickEvents) => void} callback The callback function to be invoked on double click\n * @param {UseDoubleClickOptions} [options] The options for the double click\n * @returns {boolean} The double clicking state\n *\n * @example\n * useDoubleClick(ref, () => console.log('double clicked'));\n *\n * @overload\n * @template Target The target element\n * @param {(event: DoubleClickEvents) => void} callback The callback function to be invoked on double click\n * @param {UseDoubleClickOptions} [options] The options for the double click\n * @returns {boolean} The double clicking state\n *\n * @example\n * const ref = useDoubleClick(() => console.log('double clicked'));\n *\n * @see {@link https://siberiacancode.github.io/reactuse/functions/hooks/useDoubleClick.html}\n */\nexport const useDoubleClick = ((...params: any[]): any => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const callback = (target ? params[1] : params[0]) as (event: DoubleClickEvents) => void;\n const options = (target ? params[2] : params[1]) as UseDoubleClickOptions | undefined;\n\n const timeoutIdRef = useRef<ReturnType<typeof setTimeout>>(undefined);\n const clickCountRef = useRef(0);\n const internalRef = useRefState<Element>();\n\n const internalCallbackRef = useRef(callback);\n internalCallbackRef.current = callback;\n const internalOptionsRef = useRef(options);\n internalOptionsRef.current = options;\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n\n const element = target ? getElement(target) : internalRef.current;\n if (!element) return;\n\n const onClick = (event: DoubleClickEvents) => {\n clickCountRef.current += 1;\n\n if (clickCountRef.current === 1) {\n timeoutIdRef.current = setTimeout(() => {\n if (internalOptionsRef.current?.onSingleClick)\n internalOptionsRef.current.onSingleClick(event);\n clickCountRef.current = 0;\n }, internalOptionsRef.current?.threshold ?? DEFAULT_THRESHOLD_TIME);\n }\n\n if (clickCountRef.current === 2) {\n clearTimeout(timeoutIdRef.current);\n internalCallbackRef.current(event);\n clickCountRef.current = 0;\n }\n };\n\n element.addEventListener('mousedown', onClick as EventListener);\n element.addEventListener('touchstart', onClick as EventListener);\n\n return () => {\n element.removeEventListener('mousedown', onClick as EventListener);\n element.removeEventListener('touchstart', onClick as EventListener);\n if (timeoutIdRef.current) clearTimeout(timeoutIdRef.current);\n };\n }, [target, internalRef.state]);\n\n if (target) return;\n return internalRef;\n}) as UseDoubleClick;\n"],"names":["DEFAULT_THRESHOLD_TIME","useDoubleClick","params","target","isTarget","callback","options","timeoutIdRef","useRef","clickCountRef","internalRef","useRefState","internalCallbackRef","internalOptionsRef","useEffect","element","getElement","onClick","event"],"mappings":"mPAkCaA,EAAyB,IA2BzBC,EAAkB,IAAIC,IAAuB,CACxD,MAAMC,EAAUC,EAAAA,SAASF,EAAO,CAAC,CAAC,EAAIA,EAAO,CAAC,EAAI,OAC5CG,EAAYF,EAASD,EAAO,CAAC,EAAIA,EAAO,CAAC,EACzCI,EAAWH,EAASD,EAAO,CAAC,EAAIA,EAAO,CAAC,EAExCK,EAAeC,EAAAA,OAAsC,MAAS,EAC9DC,EAAgBD,EAAAA,OAAO,CAAC,EACxBE,EAAcC,EAAAA,YAAA,EAEdC,EAAsBJ,EAAAA,OAAOH,CAAQ,EAC3CO,EAAoB,QAAUP,EAC9B,MAAMQ,EAAqBL,EAAAA,OAAOF,CAAO,EAqCzC,GApCAO,EAAmB,QAAUP,EAE7BQ,EAAAA,UAAU,IAAM,CACd,GAAI,CAACX,GAAU,CAACO,EAAY,MAAO,OAEnC,MAAMK,EAAUZ,EAASa,EAAAA,WAAWb,CAAM,EAAIO,EAAY,QAC1D,GAAI,CAACK,EAAS,OAEd,MAAME,EAAWC,GAA6B,CAC5CT,EAAc,SAAW,EAErBA,EAAc,UAAY,IAC5BF,EAAa,QAAU,WAAW,IAAM,CAClCM,EAAmB,SAAS,eAC9BA,EAAmB,QAAQ,cAAcK,CAAK,EAChDT,EAAc,QAAU,CAAA,EACvBI,EAAmB,SAAS,WAAab,CAAsB,GAGhES,EAAc,UAAY,IAC5B,aAAaF,EAAa,OAAO,EACjCK,EAAoB,QAAQM,CAAK,EACjCT,EAAc,QAAU,EAC1B,EAGF,OAAAM,EAAQ,iBAAiB,YAAaE,CAAwB,EAC9DF,EAAQ,iBAAiB,aAAcE,CAAwB,EAExD,IAAM,CACXF,EAAQ,oBAAoB,YAAaE,CAAwB,EACjEF,EAAQ,oBAAoB,aAAcE,CAAwB,EAC9DV,EAAa,SAAS,aAAaA,EAAa,OAAO,CAAA,CAC7D,EACC,CAACJ,EAAQO,EAAY,KAAK,CAAC,EAE1B,CAAAP,EACJ,OAAOO,CACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useElementSize.cjs","sources":["../../../../src/hooks/useElementSize/useElementSize.ts"],"sourcesContent":["import { useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect';\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The element size value type */\nexport interface UseElementSizeValue {\n /** The element's height */\n height: number;\n /** The element's width */\n width: number;\n}\n\n/** The use element size return type */\nexport interface UseElementSizeReturn {\n value: UseElementSizeValue;\n}\n\nexport interface UseElementSize {\n (target: HookTarget): UseElementSizeReturn;\n\n <Target extends Element>(target?: never): {
|
|
1
|
+
{"version":3,"file":"useElementSize.cjs","sources":["../../../../src/hooks/useElementSize/useElementSize.ts"],"sourcesContent":["import { useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect';\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The element size value type */\nexport interface UseElementSizeValue {\n /** The element's height */\n height: number;\n /** The element's width */\n width: number;\n}\n\n/** The use element size return type */\nexport interface UseElementSizeReturn {\n value: UseElementSizeValue;\n}\n\nexport interface UseElementSize {\n (target: HookTarget): UseElementSizeReturn;\n\n <Target extends Element>(\n target?: never\n ): {\n ref: StateRef<Target>;\n } & UseElementSizeReturn;\n}\n\n/**\n * @name useElementSize\n * @description - Hook that observes and returns the width and height of element\n * @category Elements\n *\n * @overload\n * @param {HookTarget} target The target element to observe\n * @returns {UseElementSizeReturn} An object containing the current width and height of the element\n *\n * @example\n * const { value } = useElementSize(ref);\n *\n * @overload\n * @returns { { ref: StateRef<Target> } & UseElementSizeReturn } An object containing the current width and height of the element\n *\n * @example\n * const { ref, value } = useElementSize();\n */\nexport const useElementSize = ((...params: any[]) => {\n const target = params[0] as HookTarget | undefined;\n const [size, setSize] = useState({ width: 0, height: 0 });\n const internalRef = useRefState<Element>();\n\n useIsomorphicLayoutEffect(() => {\n const element = (target ? getElement(target) : internalRef.current) as Element;\n\n if (!element) return;\n\n const { width, height } = element.getBoundingClientRect();\n setSize({\n width,\n height\n });\n\n const observer = new ResizeObserver(() => {\n const { width, height } = element.getBoundingClientRect();\n setSize({ width, height });\n });\n\n observer.observe(element);\n\n return () => {\n observer.disconnect();\n };\n }, [internalRef.current, target]);\n\n if (target) return { value: size };\n return {\n ref: internalRef,\n value: size\n };\n}) as UseElementSize;\n"],"names":["useElementSize","params","target","size","setSize","useState","internalRef","useRefState","useIsomorphicLayoutEffect","element","getElement","width","height","observer"],"mappings":"6QAoDaA,EAAkB,IAAIC,IAAkB,CACnD,MAAMC,EAASD,EAAO,CAAC,EACjB,CAACE,EAAMC,CAAO,EAAIC,EAAAA,SAAS,CAAE,MAAO,EAAG,OAAQ,EAAG,EAClDC,EAAcC,EAAAA,YAAA,EAyBpB,OAvBAC,EAAAA,0BAA0B,IAAM,CAC9B,MAAMC,EAAWP,EAASQ,EAAAA,WAAWR,CAAM,EAAII,EAAY,QAE3D,GAAI,CAACG,EAAS,OAEd,KAAM,CAAE,MAAAE,EAAO,OAAAC,GAAWH,EAAQ,sBAAA,EAClCL,EAAQ,CACN,MAAAO,EACA,OAAAC,CAAA,CACD,EAED,MAAMC,EAAW,IAAI,eAAe,IAAM,CACxC,KAAM,CAAE,MAAAF,EAAO,OAAAC,CAAAA,EAAWH,EAAQ,sBAAA,EAClCL,EAAQ,CAAE,MAAAO,EAAO,OAAAC,EAAQ,CAAA,CAC1B,EAED,OAAAC,EAAS,QAAQJ,CAAO,EAEjB,IAAM,CACXI,EAAS,WAAA,CAAW,CACtB,EACC,CAACP,EAAY,QAASJ,CAAM,CAAC,EAE5BA,EAAe,CAAE,MAAOC,CAAA,EACrB,CACL,IAAKG,EACL,MAAOH,CAAA,CAEX"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEvent.cjs","sources":["../../../../src/hooks/useEvent/useEvent.ts"],"sourcesContent":["import { useCallback, useRef } from 'react';\n\n/**\n * @name useEvent\n * @description - Hook that creates an event and returns a stable reference of it\n * @category
|
|
1
|
+
{"version":3,"file":"useEvent.cjs","sources":["../../../../src/hooks/useEvent/useEvent.ts"],"sourcesContent":["import { useCallback, useRef } from 'react';\n\n/**\n * @name useEvent\n * @description - Hook that creates an event and returns a stable reference of it\n * @category Utilities\n *\n * @template Params The type of the params\n * @template Return The type of the return\n * @param {(...args: Params) => Return} callback The callback function\n * @returns {(...args: Params) => Return} The callback\n *\n * @example\n * const onClick = useEvent(() => console.log('clicked'));\n */\nexport const useEvent = <Params extends unknown[], Return>(\n callback: (...args: Params) => Return\n): ((...args: Params) => Return) => {\n const internalCallbackRef = useRef<typeof callback>(callback);\n internalCallbackRef.current = callback;\n\n return useCallback((...args) => {\n const fn = internalCallbackRef.current;\n return fn(...args);\n }, []);\n};\n"],"names":["useEvent","callback","internalCallbackRef","useRef","useCallback","args","fn"],"mappings":"yGAeaA,EACXC,GACkC,CAClC,MAAMC,EAAsBC,EAAAA,OAAwBF,CAAQ,EAC5D,OAAAC,EAAoB,QAAUD,EAEvBG,EAAAA,YAAY,IAAIC,IAAS,CAC9B,MAAMC,EAAKJ,EAAoB,QAC/B,OAAOI,EAAG,GAAGD,CAAI,CAAA,EAChB,EAAE,CACP"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEventSource.cjs","sources":["../../../../src/hooks/useEventSource/useEventSource.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport { getRetry } from '@/utils/helpers';\n\n/** The use event source options type */\nexport interface UseEventSourceOptions<QueryData, Data> extends EventSourceInit {\n /** Immediately open the connection when calling this hook */\n immediately?: boolean;\n /* The placeholder data for the hook */\n placeholderData?: (() => Data) | Data;\n /* The retry count of requests */\n retry?: boolean | number;\n /* The retry delay of requests */\n retryDelay?: ((retry: number, event: Event) => number) | number;\n /* The onError function to be invoked */\n onError?: (error: Event) => void;\n /* The onMessage function to be invoked */\n onMessage?: (event: Event & { data?: Data }) => void;\n /* The onOpen function to be invoked */\n onOpen?: () => void;\n /* The select function to be invoked */\n select?: (data: QueryData) => Data;\n}\n\n/** The use event source return type */\ninterface UseEventSourceReturn<Data = any> {\n /** The latest data received via the EventSource */\n data?: Data;\n /** The current error */\n error?: Event;\n /** The instance of the EventSource */\n instance?: EventSource;\n /* The connecting state of the query */\n isConnecting: boolean;\n /* The error state of the query */\n isError: boolean;\n /* The open state of the query */\n isOpen: boolean;\n /** Closes the EventSource connection gracefully */\n close: () => void;\n /** Reopen the EventSource connection */\n open: () => void;\n}\n\n/**\n * @name useEventSource\n * @description - Hook that provides a reactive wrapper for event source\n * @category Browser\n *\n * @browserapi EventSource https://developer.mozilla.org/en-US/docs/Web/API/EventSource\n *\n * @param {string | URL} url The URL of the EventSource\n * @param {string[]} [events=[]] List of events to listen to\n * @param {UseEventSourceOptions} [options={}] Configuration options\n * @returns {UseEventSourceReturn<Data>} The EventSource state and controls\n *\n * @example\n * const { instance, data, isConnecting, isOpen, isError, close, open } = useEventSource('url', ['message']);\n */\nexport const useEventSource = <QueryData = any, Data = QueryData>(\n url: string | URL,\n events: string[] = [],\n options: UseEventSourceOptions<QueryData, Data> = {}\n): UseEventSourceReturn<Data> => {\n const [isConnecting, setIsConnecting] = useState(false);\n const [isOpen, setIsOpen] = useState(false);\n const [isError, setIsError] = useState(false);\n\n const retryCountRef = useRef(options?.retry ? getRetry(options.retry) : 0);\n const [error, setError] = useState<Event | undefined>(undefined);\n const [data, setData] = useState<Data | undefined>(options?.placeholderData);\n\n const eventSourceRef = useRef<EventSource>(undefined);\n\n const immediately = options.immediately ?? true;\n\n const close = () => {\n if (!eventSourceRef.current) return;\n\n eventSourceRef.current.close();\n eventSourceRef.current = undefined;\n setIsOpen(false);\n setIsConnecting(false);\n setIsError(false);\n };\n\n const open = () => {\n close();\n\n const eventSource = new EventSource(url, {
|
|
1
|
+
{"version":3,"file":"useEventSource.cjs","sources":["../../../../src/hooks/useEventSource/useEventSource.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport { getRetry } from '@/utils/helpers';\n\n/** The use event source options type */\nexport interface UseEventSourceOptions<QueryData, Data> extends EventSourceInit {\n /** Immediately open the connection when calling this hook */\n immediately?: boolean;\n /* The placeholder data for the hook */\n placeholderData?: (() => Data) | Data;\n /* The retry count of requests */\n retry?: boolean | number;\n /* The retry delay of requests */\n retryDelay?: ((retry: number, event: Event) => number) | number;\n /* The onError function to be invoked */\n onError?: (error: Event) => void;\n /* The onMessage function to be invoked */\n onMessage?: (event: Event & { data?: Data }) => void;\n /* The onOpen function to be invoked */\n onOpen?: () => void;\n /* The select function to be invoked */\n select?: (data: QueryData) => Data;\n}\n\n/** The use event source return type */\ninterface UseEventSourceReturn<Data = any> {\n /** The latest data received via the EventSource */\n data?: Data;\n /** The current error */\n error?: Event;\n /** The instance of the EventSource */\n instance?: EventSource;\n /* The connecting state of the query */\n isConnecting: boolean;\n /* The error state of the query */\n isError: boolean;\n /* The open state of the query */\n isOpen: boolean;\n /** Closes the EventSource connection gracefully */\n close: () => void;\n /** Reopen the EventSource connection */\n open: () => void;\n}\n\n/**\n * @name useEventSource\n * @description - Hook that provides a reactive wrapper for event source\n * @category Browser\n *\n * @browserapi EventSource https://developer.mozilla.org/en-US/docs/Web/API/EventSource\n *\n * @param {string | URL} url The URL of the EventSource\n * @param {string[]} [events=[]] List of events to listen to\n * @param {UseEventSourceOptions} [options={}] Configuration options\n * @returns {UseEventSourceReturn<Data>} The EventSource state and controls\n *\n * @example\n * const { instance, data, isConnecting, isOpen, isError, close, open } = useEventSource('url', ['message']);\n */\nexport const useEventSource = <QueryData = any, Data = QueryData>(\n url: string | URL,\n events: string[] = [],\n options: UseEventSourceOptions<QueryData, Data> = {}\n): UseEventSourceReturn<Data> => {\n const [isConnecting, setIsConnecting] = useState(false);\n const [isOpen, setIsOpen] = useState(false);\n const [isError, setIsError] = useState(false);\n\n const retryCountRef = useRef(options?.retry ? getRetry(options.retry) : 0);\n const [error, setError] = useState<Event | undefined>(undefined);\n const [data, setData] = useState<Data | undefined>(options?.placeholderData);\n\n const eventSourceRef = useRef<EventSource>(undefined);\n\n const immediately = options.immediately ?? true;\n\n const close = () => {\n if (!eventSourceRef.current) return;\n\n eventSourceRef.current.close();\n eventSourceRef.current = undefined;\n setIsOpen(false);\n setIsConnecting(false);\n setIsError(false);\n };\n\n const open = () => {\n close();\n\n const eventSource = new EventSource(url, {\n withCredentials: options.withCredentials ?? false\n });\n eventSourceRef.current = eventSource;\n\n setIsConnecting(true);\n\n eventSource.onopen = () => {\n setIsOpen(true);\n setIsConnecting(false);\n setError(undefined);\n options?.onOpen?.();\n };\n\n eventSource.onerror = (event) => {\n setIsOpen(false);\n setIsConnecting(false);\n setIsError(true);\n setError(event);\n options?.onError?.(event);\n\n if (retryCountRef.current > 0) {\n retryCountRef.current -= 1;\n\n const retryDelay =\n typeof options?.retryDelay === 'function'\n ? options?.retryDelay(retryCountRef.current, event)\n : options?.retryDelay;\n\n if (retryDelay) {\n setTimeout(open, retryDelay);\n return;\n }\n }\n\n retryCountRef.current = options?.retry ? getRetry(options.retry) : 0;\n };\n\n eventSource.onmessage = (event) => {\n const data = options?.select ? options?.select(event.data) : event.data;\n setData(data);\n options?.onMessage?.(event);\n };\n\n events.forEach((eventName) => {\n eventSource.addEventListener(eventName, (event: Event & { data?: Data }) => {\n setData(event.data);\n });\n });\n };\n\n useEffect(() => {\n if (!immediately) return;\n\n open();\n return () => {\n close();\n };\n }, [immediately]);\n\n return {\n instance: eventSourceRef.current,\n data,\n error,\n isConnecting,\n isOpen,\n isError,\n close,\n open\n };\n};\n"],"names":["useEventSource","url","events","options","isConnecting","setIsConnecting","useState","isOpen","setIsOpen","isError","setIsError","retryCountRef","useRef","getRetry","error","setError","data","setData","eventSourceRef","immediately","close","open","eventSource","event","retryDelay","eventName","useEffect"],"mappings":"uJA2DaA,EAAiB,CAC5BC,EACAC,EAAmB,CAAA,EACnBC,EAAkD,CAAA,IACnB,CAC/B,KAAM,CAACC,EAAcC,CAAe,EAAIC,EAAAA,SAAS,EAAK,EAChD,CAACC,EAAQC,CAAS,EAAIF,EAAAA,SAAS,EAAK,EACpC,CAACG,EAASC,CAAU,EAAIJ,EAAAA,SAAS,EAAK,EAEtCK,EAAgBC,EAAAA,OAAOT,GAAS,MAAQU,EAAAA,SAASV,EAAQ,KAAK,EAAI,CAAC,EACnE,CAACW,EAAOC,CAAQ,EAAIT,EAAAA,SAA4B,MAAS,EACzD,CAACU,EAAMC,CAAO,EAAIX,EAAAA,SAA2BH,GAAS,eAAe,EAErEe,EAAiBN,EAAAA,OAAoB,MAAS,EAE9CO,EAAchB,EAAQ,aAAe,GAErCiB,EAAQ,IAAM,CACbF,EAAe,UAEpBA,EAAe,QAAQ,MAAA,EACvBA,EAAe,QAAU,OACzBV,EAAU,EAAK,EACfH,EAAgB,EAAK,EACrBK,EAAW,EAAK,EAAA,EAGZW,EAAO,IAAM,CACjBD,EAAA,EAEA,MAAME,EAAc,IAAI,YAAYrB,EAAK,CACvC,gBAAiBE,EAAQ,iBAAmB,EAAA,CAC7C,EACDe,EAAe,QAAUI,EAEzBjB,EAAgB,EAAI,EAEpBiB,EAAY,OAAS,IAAM,CACzBd,EAAU,EAAI,EACdH,EAAgB,EAAK,EACrBU,EAAS,MAAS,EAClBZ,GAAS,SAAA,CAAS,EAGpBmB,EAAY,QAAWC,GAAU,CAO/B,GANAf,EAAU,EAAK,EACfH,EAAgB,EAAK,EACrBK,EAAW,EAAI,EACfK,EAASQ,CAAK,EACdpB,GAAS,UAAUoB,CAAK,EAEpBZ,EAAc,QAAU,EAAG,CAC7BA,EAAc,SAAW,EAEzB,MAAMa,EACJ,OAAOrB,GAAS,YAAe,WAC3BA,GAAS,WAAWQ,EAAc,QAASY,CAAK,EAChDpB,GAAS,WAEf,GAAIqB,EAAY,CACd,WAAWH,EAAMG,CAAU,EAC3B,MAAA,CACF,CAGFb,EAAc,QAAUR,GAAS,MAAQU,EAAAA,SAASV,EAAQ,KAAK,EAAI,CAAA,EAGrEmB,EAAY,UAAaC,GAAU,CACjC,MAAMP,EAAOb,GAAS,OAASA,GAAS,OAAOoB,EAAM,IAAI,EAAIA,EAAM,KACnEN,EAAQD,CAAI,EACZb,GAAS,YAAYoB,CAAK,CAAA,EAG5BrB,EAAO,QAASuB,GAAc,CAC5BH,EAAY,iBAAiBG,EAAYF,GAAmC,CAC1EN,EAAQM,EAAM,IAAI,CAAA,CACnB,CAAA,CACF,CAAA,EAGHG,OAAAA,EAAAA,UAAU,IAAM,CACd,GAAKP,EAEL,OAAAE,EAAA,EACO,IAAM,CACXD,EAAA,CAAM,CACR,EACC,CAACD,CAAW,CAAC,EAET,CACL,SAAUD,EAAe,QACzB,KAAAF,EACA,MAAAF,EACA,aAAAV,EACA,OAAAG,EACA,QAAAE,EACA,MAAAW,EACA,KAAAC,CAAA,CAEJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useField.cjs","sources":["../../../../src/hooks/useField/useField.ts"],"sourcesContent":["import { useRef, useState } from 'react';\n\nimport { useRerender } from '../useRerender/useRerender';\n\n/** The use field params type */\nexport interface UseFieldParams<Value> {\n /** The auto focus */\n autoFocus?: boolean;\n /** The initial touched */\n initialTouched?: boolean;\n /** The initial value */\n initialValue?: Value;\n /** The validate on blur */\n validateOnBlur?: boolean;\n /** The validate on mount */\n validateOnChange?: boolean;\n /** The validate on mount */\n validateOnMount?: boolean;\n}\n\n/** The use field register params type */\nexport interface UseFieldRegisterParams {\n /** The required validation */\n required?: string;\n /** The custom validation */\n validate?: (value: string) => Promise<string | true>;\n /** The min value validation */\n max?: {\n value: number;\n message: string;\n };\n /** The max length validation */\n maxLength?: {\n value: number;\n message: string;\n };\n /** The max value validation */\n min?: {\n value: number;\n message: string;\n };\n /** The min length validation */\n minLength?: {\n value: number;\n message: string;\n };\n /** The pattern validation */\n pattern?: {\n value: RegExp;\n message: string;\n };\n}\n\n/** The use field return type */\nexport interface UseFieldReturn<Value> {\n /** The dirty state */\n dirty: boolean;\n /** The error state */\n error?: string;\n /** The set error function */\n touched: boolean;\n /** The set error function */\n clearError: () => void;\n /** The focus function */\n focus: () => void;\n /** The get value function */\n getValue: () => Value;\n /** The register function */\n register: (params?: UseFieldRegisterParams) => {\n onBlur: () => void;\n onChange: () => void;\n ref: (\n node: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement | null | undefined\n ) => void;\n };\n /** The reset function */\n reset: () => void;\n /** The set error function */\n setError: (error: string) => void;\n /** The set value function */\n setValue: (value: Value) => void;\n /** The watch function */\n watch: () => Value;\n}\n\n/**\n * @name useField\n * @description - Hook to manage a form field\n * @category
|
|
1
|
+
{"version":3,"file":"useField.cjs","sources":["../../../../src/hooks/useField/useField.ts"],"sourcesContent":["import { useRef, useState } from 'react';\n\nimport { useRerender } from '../useRerender/useRerender';\n\n/** The use field params type */\nexport interface UseFieldParams<Value> {\n /** The auto focus */\n autoFocus?: boolean;\n /** The initial touched */\n initialTouched?: boolean;\n /** The initial value */\n initialValue?: Value;\n /** The validate on blur */\n validateOnBlur?: boolean;\n /** The validate on mount */\n validateOnChange?: boolean;\n /** The validate on mount */\n validateOnMount?: boolean;\n}\n\n/** The use field register params type */\nexport interface UseFieldRegisterParams {\n /** The required validation */\n required?: string;\n /** The custom validation */\n validate?: (value: string) => Promise<string | true>;\n /** The min value validation */\n max?: {\n value: number;\n message: string;\n };\n /** The max length validation */\n maxLength?: {\n value: number;\n message: string;\n };\n /** The max value validation */\n min?: {\n value: number;\n message: string;\n };\n /** The min length validation */\n minLength?: {\n value: number;\n message: string;\n };\n /** The pattern validation */\n pattern?: {\n value: RegExp;\n message: string;\n };\n}\n\n/** The use field return type */\nexport interface UseFieldReturn<Value> {\n /** The dirty state */\n dirty: boolean;\n /** The error state */\n error?: string;\n /** The set error function */\n touched: boolean;\n /** The set error function */\n clearError: () => void;\n /** The focus function */\n focus: () => void;\n /** The get value function */\n getValue: () => Value;\n /** The register function */\n register: (params?: UseFieldRegisterParams) => {\n onBlur: () => void;\n onChange: () => void;\n ref: (\n node: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement | null | undefined\n ) => void;\n };\n /** The reset function */\n reset: () => void;\n /** The set error function */\n setError: (error: string) => void;\n /** The set value function */\n setValue: (value: Value) => void;\n /** The watch function */\n watch: () => Value;\n}\n\n/**\n * @name useField\n * @description - Hook to manage a form field\n * @category State\n *\n * @template Value The input value\n * @template Type The input value type\n * @param {Value} [params.initialValue] Initial value\n * @param {boolean} [params.initialTouched=false] Initial touched state\n * @param {boolean} [params.autoFocus=false] Auto focus\n * @param {boolean} [params.validateOnChange=false] Validate on change\n * @param {boolean} [params.validateOnBlur=false] Validate on blur\n * @param {boolean} [params.validateOnMount=false] Validate on mount\n * @returns {UseFieldReturn<Value>} An object containing input information\n *\n * @example\n * const { register, getValue, setValue, reset, dirty, error, setError, clearError, touched, focus, watch } = useField();\n */\nexport const useField = <\n Value extends boolean | number | string = string,\n Type = Value extends string ? string : Value extends boolean ? boolean : number\n>(\n params?: UseFieldParams<Value>\n): UseFieldReturn<Type> => {\n const initialValue = (params?.initialValue ?? '') as Value;\n\n const inputRef = useRef<HTMLInputElement | null>(null);\n const watchingRef = useRef(false);\n const rerender = useRerender();\n\n const [dirty, setDirty] = useState(false);\n const [touched, setTouched] = useState(params?.initialTouched ?? false);\n const [error, setError] = useState<string | undefined>(undefined);\n\n const getValue = () => {\n if (inputRef.current?.type === 'radio' || inputRef.current?.type === 'checkbox')\n return inputRef.current.checked as Type;\n return (inputRef.current?.value ?? initialValue) as Type;\n };\n\n const setValue = (value: Type) => {\n if (inputRef.current?.type === 'radio' || inputRef.current?.type === 'checkbox') {\n inputRef.current.checked = value as boolean;\n if (watchingRef.current) return rerender();\n return;\n }\n\n inputRef.current!.value = value as string;\n if (watchingRef.current) return rerender();\n };\n\n const reset = () => {\n setValue(initialValue as unknown as Type);\n setDirty(false);\n setTouched(false);\n setError(undefined);\n };\n\n const focus = () => inputRef.current!.focus();\n\n const validate = (params: UseFieldRegisterParams) => {\n if (params.required && !inputRef.current!.value) {\n return setError(params.required);\n }\n\n if (params.minLength && inputRef.current!.value.length < params.minLength.value) {\n return setError(params.minLength.message);\n }\n\n if (params.maxLength && inputRef.current!.value.length > params.maxLength.value) {\n return setError(params.maxLength.message);\n }\n\n if (params.min && Number(inputRef.current!.value) < params.min.value) {\n return setError(params.min.message);\n }\n\n if (params.max && Number(inputRef.current!.value) > params.max.value) {\n return setError(params.max.message);\n }\n\n if (params.pattern && !params.pattern.value.test(inputRef.current!.value)) {\n return setError(params.pattern.message);\n }\n\n if (params.validate) {\n const error = params.validate(inputRef.current!.value);\n if (typeof error === 'string') return setError(error);\n }\n\n setError(undefined);\n };\n\n const register = (registerParams?: UseFieldRegisterParams) => ({\n ref: (node: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement | null | undefined) => {\n if (!inputRef.current && node) {\n if (params?.autoFocus) node.focus();\n inputRef.current = node as HTMLInputElement;\n if (inputRef.current.type === 'radio') {\n inputRef.current.defaultChecked = params?.initialValue === node.value;\n return;\n }\n if (inputRef.current.type === 'checkbox') {\n inputRef.current.defaultChecked = !!params?.initialValue;\n return;\n }\n inputRef.current.defaultValue = String(initialValue);\n\n if (registerParams && params?.validateOnMount) validate(registerParams);\n }\n },\n onChange: async () => {\n if (watchingRef.current) return rerender();\n if (inputRef.current!.value !== initialValue) setDirty(true);\n if (dirty && inputRef.current!.value === initialValue) setDirty(false);\n if (registerParams && params?.validateOnChange) await validate(registerParams);\n if (registerParams && params?.validateOnBlur) setError(undefined);\n },\n onBlur: async () => {\n if (registerParams && params?.validateOnBlur) await validate(registerParams);\n setTouched(true);\n }\n });\n\n const watch = () => {\n watchingRef.current = true;\n return getValue();\n };\n\n const clearError = () => setError(undefined);\n\n return {\n register,\n dirty,\n touched,\n error,\n setError,\n clearError,\n getValue,\n setValue,\n reset,\n watch,\n focus\n };\n};\n"],"names":["useField","params","initialValue","inputRef","useRef","watchingRef","rerender","useRerender","dirty","setDirty","useState","touched","setTouched","error","setError","getValue","setValue","value","reset","focus","validate","registerParams","node"],"mappings":"qJAuGaA,EAIXC,GACyB,CACzB,MAAMC,EAAgBD,GAAQ,cAAgB,GAExCE,EAAWC,EAAAA,OAAgC,IAAI,EAC/CC,EAAcD,EAAAA,OAAO,EAAK,EAC1BE,EAAWC,EAAAA,YAAA,EAEX,CAACC,EAAOC,CAAQ,EAAIC,EAAAA,SAAS,EAAK,EAClC,CAACC,EAASC,CAAU,EAAIF,EAAAA,SAAST,GAAQ,gBAAkB,EAAK,EAChE,CAACY,EAAOC,CAAQ,EAAIJ,EAAAA,SAA6B,MAAS,EAE1DK,EAAW,IACXZ,EAAS,SAAS,OAAS,SAAWA,EAAS,SAAS,OAAS,WAC5DA,EAAS,QAAQ,QAClBA,EAAS,SAAS,OAASD,EAG/Bc,EAAYC,GAAgB,CAChC,GAAId,EAAS,SAAS,OAAS,SAAWA,EAAS,SAAS,OAAS,WAEnE,OADAA,EAAS,QAAQ,QAAUc,EACvBZ,EAAY,QAAgBC,EAAA,EAChC,OAIF,GADAH,EAAS,QAAS,MAAQc,EACtBZ,EAAY,QAAS,OAAOC,EAAA,CAAS,EAGrCY,EAAQ,IAAM,CAClBF,EAASd,CAA+B,EACxCO,EAAS,EAAK,EACdG,EAAW,EAAK,EAChBE,EAAS,MAAS,CAAA,EAGdK,EAAQ,IAAMhB,EAAS,QAAS,MAAA,EAEhCiB,EAAYnB,GAAmC,CACnD,GAAIA,EAAO,UAAY,CAACE,EAAS,QAAS,MACxC,OAAOW,EAASb,EAAO,QAAQ,EAGjC,GAAIA,EAAO,WAAaE,EAAS,QAAS,MAAM,OAASF,EAAO,UAAU,MACxE,OAAOa,EAASb,EAAO,UAAU,OAAO,EAG1C,GAAIA,EAAO,WAAaE,EAAS,QAAS,MAAM,OAASF,EAAO,UAAU,MACxE,OAAOa,EAASb,EAAO,UAAU,OAAO,EAG1C,GAAIA,EAAO,KAAO,OAAOE,EAAS,QAAS,KAAK,EAAIF,EAAO,IAAI,MAC7D,OAAOa,EAASb,EAAO,IAAI,OAAO,EAGpC,GAAIA,EAAO,KAAO,OAAOE,EAAS,QAAS,KAAK,EAAIF,EAAO,IAAI,MAC7D,OAAOa,EAASb,EAAO,IAAI,OAAO,EAGpC,GAAIA,EAAO,SAAW,CAACA,EAAO,QAAQ,MAAM,KAAKE,EAAS,QAAS,KAAK,EACtE,OAAOW,EAASb,EAAO,QAAQ,OAAO,EAGxC,GAAIA,EAAO,SAAU,CACnB,MAAMY,EAAQZ,EAAO,SAASE,EAAS,QAAS,KAAK,EACrD,GAAI,OAAOU,GAAU,SAAU,OAAOC,EAASD,CAAK,CAAA,CAGtDC,EAAS,MAAS,CAAA,EAyCpB,MAAO,CACL,SAvCgBO,IAA6C,CAC7D,IAAMC,GAAwF,CAC5F,GAAI,CAACnB,EAAS,SAAWmB,EAAM,CAG7B,GAFIrB,GAAQ,WAAWqB,EAAK,MAAA,EAC5BnB,EAAS,QAAUmB,EACfnB,EAAS,QAAQ,OAAS,QAAS,CACrCA,EAAS,QAAQ,eAAiBF,GAAQ,eAAiBqB,EAAK,MAChE,MAAA,CAEF,GAAInB,EAAS,QAAQ,OAAS,WAAY,CACxCA,EAAS,QAAQ,eAAiB,CAAC,CAACF,GAAQ,aAC5C,MAAA,CAEFE,EAAS,QAAQ,aAAe,OAAOD,CAAY,EAE/CmB,GAAkBpB,GAAQ,iBAAiBmB,EAASC,CAAc,CAAA,CACxE,EAEF,SAAU,SAAY,CACpB,GAAIhB,EAAY,QAAS,OAAOC,EAAA,EAC5BH,EAAS,QAAS,QAAUD,KAAuB,EAAI,EACvDM,GAASL,EAAS,QAAS,QAAUD,KAAuB,EAAK,EACjEmB,GAAkBpB,GAAQ,kBAAkB,MAAMmB,EAASC,CAAc,EACzEA,GAAkBpB,GAAQ,gBAAgBa,EAAS,MAAS,CAAA,EAElE,OAAQ,SAAY,CACdO,GAAkBpB,GAAQ,gBAAgB,MAAMmB,EAASC,CAAc,EAC3ET,EAAW,EAAI,CAAA,CACjB,GAYA,MAAAJ,EACA,QAAAG,EACA,MAAAE,EACA,SAAAC,EACA,WARiB,IAAMA,EAAS,MAAS,EASzC,SAAAC,EACA,SAAAC,EACA,MAAAE,EACA,MAjBY,KACZb,EAAY,QAAU,GACfU,EAAA,GAgBP,MAAAI,CAAA,CAEJ"}
|