@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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDocumentTitle.mjs","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.mjs","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":";AA8BO,SAASA,EACdC,GACAC,GACwB;AACxB,QAAMC,IAAeC,EAAO,SAAS,KAAK,GACpC,CAACC,GAAOC,CAAQ,IAAIC,EAASN,KAAgB,SAAS,KAAK,GAE3DO,IAAM,CAACH,MAAkB;AAC7B,UAAMI,IAAeJ,EAAM,KAAA;AAC3B,IAAII,EAAa,SAAS,MAAG,SAAS,QAAQA;AAAA,EAAA;AAGhD,SAAAC,EAAU,MAAM;AACd,IAAI,OAAOL,KAAU,YACrBG,EAAIH,CAAK;AAAA,EAAA,GACR,CAACA,CAAK,CAAC,GAEVK,EAAU,MAAM;AACd,UAAMC,IAAW,IAAI,iBAAiB,MAAM;AAC1C,MAAAL,EAAS,CAACM,MACJ,YAAY,SAAS,UAAUA,IAC1B,SAAS,QAEXA,CACR;AAAA,IAAA,CACF;AAED,WAAAD,EAAS,QAAQ,SAAS,KAAK,cAAc,OAAO,GAAI;AAAA,MACtD,WAAW;AAAA,IAAA,CACZ,GAEM,MAAM;AACX,MAAAA,EAAS,WAAA;AAAA,IAAW;AAAA,EACtB,GACC,EAAE,GAELD,EAAU,MAAM;AACd,QAAIR,GAAS;AACX,aAAO,MAAM;AACX,iBAAS,QAAQC,EAAa;AAAA,MAAA;AAAA,EAElC,GACC,EAAE,GAEE,EAAE,OAAAE,GAAO,KAAAG,EAAA;AAClB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDoubleClick.mjs","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.mjs","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":";;;;AAkCO,MAAMA,IAAyB,KA2BzBC,IAAkB,IAAIC,MAAuB;AACxD,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,IAAYF,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,GACzCI,IAAWH,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,GAExCK,IAAeC,EAAsC,MAAS,GAC9DC,IAAgBD,EAAO,CAAC,GACxBE,IAAcC,EAAA,GAEdC,IAAsBJ,EAAOH,CAAQ;AAC3C,EAAAO,EAAoB,UAAUP;AAC9B,QAAMQ,IAAqBL,EAAOF,CAAO;AAqCzC,MApCAO,EAAmB,UAAUP,GAE7BQ,EAAU,MAAM;AACd,QAAI,CAACX,KAAU,CAACO,EAAY,MAAO;AAEnC,UAAMK,IAAUZ,IAASa,EAAWb,CAAM,IAAIO,EAAY;AAC1D,QAAI,CAACK,EAAS;AAEd,UAAME,IAAU,CAACC,MAA6B;AAC5C,MAAAT,EAAc,WAAW,GAErBA,EAAc,YAAY,MAC5BF,EAAa,UAAU,WAAW,MAAM;AACtC,QAAIM,EAAmB,SAAS,iBAC9BA,EAAmB,QAAQ,cAAcK,CAAK,GAChDT,EAAc,UAAU;AAAA,MAAA,GACvBI,EAAmB,SAAS,aAAab,CAAsB,IAGhES,EAAc,YAAY,MAC5B,aAAaF,EAAa,OAAO,GACjCK,EAAoB,QAAQM,CAAK,GACjCT,EAAc,UAAU;AAAA,IAC1B;AAGF,WAAAM,EAAQ,iBAAiB,aAAaE,CAAwB,GAC9DF,EAAQ,iBAAiB,cAAcE,CAAwB,GAExD,MAAM;AACX,MAAAF,EAAQ,oBAAoB,aAAaE,CAAwB,GACjEF,EAAQ,oBAAoB,cAAcE,CAAwB,GAC9DV,EAAa,WAAS,aAAaA,EAAa,OAAO;AAAA,IAAA;AAAA,EAC7D,GACC,CAACJ,GAAQO,EAAY,KAAK,CAAC,GAE1B,CAAAP;AACJ,WAAOO;AACT;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useElementSize.mjs","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.mjs","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":";;;;AAoDO,MAAMA,IAAkB,IAAIC,MAAkB;AACnD,QAAMC,IAASD,EAAO,CAAC,GACjB,CAACE,GAAMC,CAAO,IAAIC,EAAS,EAAE,OAAO,GAAG,QAAQ,GAAG,GAClDC,IAAcC,EAAA;AAyBpB,SAvBAC,EAA0B,MAAM;AAC9B,UAAMC,IAAWP,IAASQ,EAAWR,CAAM,IAAII,EAAY;AAE3D,QAAI,CAACG,EAAS;AAEd,UAAM,EAAE,OAAAE,GAAO,QAAAC,MAAWH,EAAQ,sBAAA;AAClC,IAAAL,EAAQ;AAAA,MACN,OAAAO;AAAA,MACA,QAAAC;AAAA,IAAA,CACD;AAED,UAAMC,IAAW,IAAI,eAAe,MAAM;AACxC,YAAM,EAAE,OAAAF,GAAO,QAAAC,EAAAA,IAAWH,EAAQ,sBAAA;AAClC,MAAAL,EAAQ,EAAE,OAAAO,GAAO,QAAAC,GAAQ;AAAA,IAAA,CAC1B;AAED,WAAAC,EAAS,QAAQJ,CAAO,GAEjB,MAAM;AACX,MAAAI,EAAS,WAAA;AAAA,IAAW;AAAA,EACtB,GACC,CAACP,EAAY,SAASJ,CAAM,CAAC,GAE5BA,IAAe,EAAE,OAAOC,EAAA,IACrB;AAAA,IACL,KAAKG;AAAA,IACL,OAAOH;AAAA,EAAA;AAEX;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEvent.mjs","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.mjs","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":";AAeO,MAAMA,IAAW,CACtBC,MACkC;AAClC,QAAMC,IAAsBC,EAAwBF,CAAQ;AAC5D,SAAAC,EAAoB,UAAUD,GAEvBG,EAAY,IAAIC,MAAS;AAC9B,UAAMC,IAAKJ,EAAoB;AAC/B,WAAOI,EAAG,GAAGD,CAAI;AAAA,EAAA,GAChB,EAAE;AACP;"}
|
|
@@ -5,7 +5,9 @@ const L = (g, v = [], e = {}) => {
|
|
|
5
5
|
n.current && (n.current.close(), n.current = void 0, f(!1), s(!1), y(!1));
|
|
6
6
|
}, o = () => {
|
|
7
7
|
l();
|
|
8
|
-
const a = new EventSource(g, {
|
|
8
|
+
const a = new EventSource(g, {
|
|
9
|
+
withCredentials: e.withCredentials ?? !1
|
|
10
|
+
});
|
|
9
11
|
n.current = a, s(!0), a.onopen = () => {
|
|
10
12
|
f(!0), s(!1), d(void 0), e?.onOpen?.();
|
|
11
13
|
}, a.onerror = (r) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEventSource.mjs","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.mjs","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":";;AA2DO,MAAMA,IAAiB,CAC5BC,GACAC,IAAmB,CAAA,GACnBC,IAAkD,CAAA,MACnB;AAC/B,QAAM,CAACC,GAAcC,CAAe,IAAIC,EAAS,EAAK,GAChD,CAACC,GAAQC,CAAS,IAAIF,EAAS,EAAK,GACpC,CAACG,GAASC,CAAU,IAAIJ,EAAS,EAAK,GAEtCK,IAAgBC,EAAOT,GAAS,QAAQU,EAASV,EAAQ,KAAK,IAAI,CAAC,GACnE,CAACW,GAAOC,CAAQ,IAAIT,EAA4B,MAAS,GACzD,CAACU,GAAMC,CAAO,IAAIX,EAA2BH,GAAS,eAAe,GAErEe,IAAiBN,EAAoB,MAAS,GAE9CO,IAAchB,EAAQ,eAAe,IAErCiB,IAAQ,MAAM;AAClB,IAAKF,EAAe,YAEpBA,EAAe,QAAQ,MAAA,GACvBA,EAAe,UAAU,QACzBV,EAAU,EAAK,GACfH,EAAgB,EAAK,GACrBK,EAAW,EAAK;AAAA,EAAA,GAGZW,IAAO,MAAM;AACjB,IAAAD,EAAA;AAEA,UAAME,IAAc,IAAI,YAAYrB,GAAK;AAAA,MACvC,iBAAiBE,EAAQ,mBAAmB;AAAA,IAAA,CAC7C;AACD,IAAAe,EAAe,UAAUI,GAEzBjB,EAAgB,EAAI,GAEpBiB,EAAY,SAAS,MAAM;AACzB,MAAAd,EAAU,EAAI,GACdH,EAAgB,EAAK,GACrBU,EAAS,MAAS,GAClBZ,GAAS,SAAA;AAAA,IAAS,GAGpBmB,EAAY,UAAU,CAACC,MAAU;AAO/B,UANAf,EAAU,EAAK,GACfH,EAAgB,EAAK,GACrBK,EAAW,EAAI,GACfK,EAASQ,CAAK,GACdpB,GAAS,UAAUoB,CAAK,GAEpBZ,EAAc,UAAU,GAAG;AAC7B,QAAAA,EAAc,WAAW;AAEzB,cAAMa,IACJ,OAAOrB,GAAS,cAAe,aAC3BA,GAAS,WAAWQ,EAAc,SAASY,CAAK,IAChDpB,GAAS;AAEf,YAAIqB,GAAY;AACd,qBAAWH,GAAMG,CAAU;AAC3B;AAAA,QAAA;AAAA,MACF;AAGF,MAAAb,EAAc,UAAUR,GAAS,QAAQU,EAASV,EAAQ,KAAK,IAAI;AAAA,IAAA,GAGrEmB,EAAY,YAAY,CAACC,MAAU;AACjC,YAAMP,IAAOb,GAAS,SAASA,GAAS,OAAOoB,EAAM,IAAI,IAAIA,EAAM;AACnE,MAAAN,EAAQD,CAAI,GACZb,GAAS,YAAYoB,CAAK;AAAA,IAAA,GAG5BrB,EAAO,QAAQ,CAACuB,MAAc;AAC5B,MAAAH,EAAY,iBAAiBG,GAAW,CAACF,MAAmC;AAC1E,QAAAN,EAAQM,EAAM,IAAI;AAAA,MAAA,CACnB;AAAA,IAAA,CACF;AAAA,EAAA;AAGH,SAAAG,EAAU,MAAM;AACd,QAAKP;AAEL,aAAAE,EAAA,GACO,MAAM;AACX,QAAAD,EAAA;AAAA,MAAM;AAAA,EACR,GACC,CAACD,CAAW,CAAC,GAET;AAAA,IACL,UAAUD,EAAe;AAAA,IACzB,MAAAF;AAAA,IACA,OAAAF;AAAA,IACA,cAAAV;AAAA,IACA,QAAAG;AAAA,IACA,SAAAE;AAAA,IACA,OAAAW;AAAA,IACA,MAAAC;AAAA,EAAA;AAEJ;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useField.mjs","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.mjs","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":";;AAuGO,MAAMA,IAAW,CAItBC,MACyB;AACzB,QAAMC,IAAgBD,GAAQ,gBAAgB,IAExCE,IAAWC,EAAgC,IAAI,GAC/CC,IAAcD,EAAO,EAAK,GAC1BE,IAAWC,EAAA,GAEX,CAACC,GAAOC,CAAQ,IAAIC,EAAS,EAAK,GAClC,CAACC,GAASC,CAAU,IAAIF,EAAST,GAAQ,kBAAkB,EAAK,GAChE,CAACY,GAAOC,CAAQ,IAAIJ,EAA6B,MAAS,GAE1DK,IAAW,MACXZ,EAAS,SAAS,SAAS,WAAWA,EAAS,SAAS,SAAS,aAC5DA,EAAS,QAAQ,UAClBA,EAAS,SAAS,SAASD,GAG/Bc,IAAW,CAACC,MAAgB;AAChC,QAAId,EAAS,SAAS,SAAS,WAAWA,EAAS,SAAS,SAAS;AAEnE,aADAA,EAAS,QAAQ,UAAUc,GACvBZ,EAAY,UAAgBC,EAAA,IAChC;AAIF,QADAH,EAAS,QAAS,QAAQc,GACtBZ,EAAY,QAAS,QAAOC,EAAA;AAAA,EAAS,GAGrCY,IAAQ,MAAM;AAClB,IAAAF,EAASd,CAA+B,GACxCO,EAAS,EAAK,GACdG,EAAW,EAAK,GAChBE,EAAS,MAAS;AAAA,EAAA,GAGdK,IAAQ,MAAMhB,EAAS,QAAS,MAAA,GAEhCiB,IAAW,CAACnB,MAAmC;AACnD,QAAIA,EAAO,YAAY,CAACE,EAAS,QAAS;AACxC,aAAOW,EAASb,EAAO,QAAQ;AAGjC,QAAIA,EAAO,aAAaE,EAAS,QAAS,MAAM,SAASF,EAAO,UAAU;AACxE,aAAOa,EAASb,EAAO,UAAU,OAAO;AAG1C,QAAIA,EAAO,aAAaE,EAAS,QAAS,MAAM,SAASF,EAAO,UAAU;AACxE,aAAOa,EAASb,EAAO,UAAU,OAAO;AAG1C,QAAIA,EAAO,OAAO,OAAOE,EAAS,QAAS,KAAK,IAAIF,EAAO,IAAI;AAC7D,aAAOa,EAASb,EAAO,IAAI,OAAO;AAGpC,QAAIA,EAAO,OAAO,OAAOE,EAAS,QAAS,KAAK,IAAIF,EAAO,IAAI;AAC7D,aAAOa,EAASb,EAAO,IAAI,OAAO;AAGpC,QAAIA,EAAO,WAAW,CAACA,EAAO,QAAQ,MAAM,KAAKE,EAAS,QAAS,KAAK;AACtE,aAAOW,EAASb,EAAO,QAAQ,OAAO;AAGxC,QAAIA,EAAO,UAAU;AACnB,YAAMY,IAAQZ,EAAO,SAASE,EAAS,QAAS,KAAK;AACrD,UAAI,OAAOU,KAAU,SAAU,QAAOC,EAASD,CAAK;AAAA,IAAA;AAGtD,IAAAC,EAAS,MAAS;AAAA,EAAA;AAyCpB,SAAO;AAAA,IACL,UAvCe,CAACO,OAA6C;AAAA,MAC7D,KAAK,CAACC,MAAwF;AAC5F,YAAI,CAACnB,EAAS,WAAWmB,GAAM;AAG7B,cAFIrB,GAAQ,aAAWqB,EAAK,MAAA,GAC5BnB,EAAS,UAAUmB,GACfnB,EAAS,QAAQ,SAAS,SAAS;AACrC,YAAAA,EAAS,QAAQ,iBAAiBF,GAAQ,iBAAiBqB,EAAK;AAChE;AAAA,UAAA;AAEF,cAAInB,EAAS,QAAQ,SAAS,YAAY;AACxC,YAAAA,EAAS,QAAQ,iBAAiB,CAAC,CAACF,GAAQ;AAC5C;AAAA,UAAA;AAEF,UAAAE,EAAS,QAAQ,eAAe,OAAOD,CAAY,GAE/CmB,KAAkBpB,GAAQ,mBAAiBmB,EAASC,CAAc;AAAA,QAAA;AAAA,MACxE;AAAA,MAEF,UAAU,YAAY;AACpB,YAAIhB,EAAY,QAAS,QAAOC,EAAA;AAChC,QAAIH,EAAS,QAAS,UAAUD,OAAuB,EAAI,GACvDM,KAASL,EAAS,QAAS,UAAUD,OAAuB,EAAK,GACjEmB,KAAkBpB,GAAQ,oBAAkB,MAAMmB,EAASC,CAAc,GACzEA,KAAkBpB,GAAQ,kBAAgBa,EAAS,MAAS;AAAA,MAAA;AAAA,MAElE,QAAQ,YAAY;AAClB,QAAIO,KAAkBpB,GAAQ,kBAAgB,MAAMmB,EAASC,CAAc,GAC3ET,EAAW,EAAI;AAAA,MAAA;AAAA,IACjB;AAAA,IAYA,OAAAJ;AAAA,IACA,SAAAG;AAAA,IACA,OAAAE;AAAA,IACA,UAAAC;AAAA,IACA,YARiB,MAAMA,EAAS,MAAS;AAAA,IASzC,UAAAC;AAAA,IACA,UAAAC;AAAA,IACA,OAAAE;AAAA,IACA,OAjBY,OACZb,EAAY,UAAU,IACfU,EAAA;AAAA,IAgBP,OAAAI;AAAA,EAAA;AAEJ;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFileDialog.mjs","sources":["../../../../src/hooks/useFileDialog/useFileDialog.ts"],"sourcesContent":["import type { ComponentProps } from 'react';\n\nimport { useEffect, useRef, useState } from 'react';\n\n/* The use file dialog options */\nexport interface UseFileDialogOptions extends Pick<ComponentProps<'input'>, 'accept' | 'multiple'> {\n /** The capture value */\n capture?: string;\n /** The reset value */\n reset?: boolean;\n}\n\nconst DEFAULT_OPTIONS = {\n multiple: true,\n accept: '*',\n reset: false\n} satisfies UseFileDialogOptions;\n\n/* The use file dialog return type */\nexport interface UseFileDialogReturn {\n /** The selected files */\n value: FileList | null;\n /** The open function */\n open: (openParams?: UseFileDialogOptions) => void;\n /** The reset function */\n reset: () => void;\n}\n\nexport interface UseFileDialog {\n (\n callback?: (value: FileList | null) => void,\n options?: UseFileDialogOptions\n ): UseFileDialogReturn;\n\n (options?: UseFileDialogOptions, callback?: never): UseFileDialogReturn;\n}\n\n/**\n * @name useFileDialog\n * @description - Hook to handle file input\n * @category
|
|
1
|
+
{"version":3,"file":"useFileDialog.mjs","sources":["../../../../src/hooks/useFileDialog/useFileDialog.ts"],"sourcesContent":["import type { ComponentProps } from 'react';\n\nimport { useEffect, useRef, useState } from 'react';\n\n/* The use file dialog options */\nexport interface UseFileDialogOptions extends Pick<ComponentProps<'input'>, 'accept' | 'multiple'> {\n /** The capture value */\n capture?: string;\n /** The reset value */\n reset?: boolean;\n}\n\nconst DEFAULT_OPTIONS = {\n multiple: true,\n accept: '*',\n reset: false\n} satisfies UseFileDialogOptions;\n\n/* The use file dialog return type */\nexport interface UseFileDialogReturn {\n /** The selected files */\n value: FileList | null;\n /** The open function */\n open: (openParams?: UseFileDialogOptions) => void;\n /** The reset function */\n reset: () => void;\n}\n\nexport interface UseFileDialog {\n (\n callback?: (value: FileList | null) => void,\n options?: UseFileDialogOptions\n ): UseFileDialogReturn;\n\n (options?: UseFileDialogOptions, callback?: never): UseFileDialogReturn;\n}\n\n/**\n * @name useFileDialog\n * @description - Hook to handle file input\n * @category Elements\n *\n * @overload\n * @param {(value: FileList | null) => void} callback The callback to execute when a file is selected\n * @param {boolean} [options.multiple=true] Whether multiple files can be selected\n * @param {string} [options.accept='*'] The accepted file types\n * @param {boolean} [options.reset=false] Whether the input should be reset when the callback is called\n * @param {string} [options.capture] The capture value\n * @returns {UseFileDialogReturn} An object containing the selected files\n *\n * @example\n * const { values, open, reset } = useFileDialog((value) => console.log(value));\n *\n * @overload\n * @param {boolean} [options.multiple=true] Whether multiple files can be selected\n * @param {string} [options.accept='*'] The accepted file types\n * @param {boolean} [options.reset=false] Whether the input should be reset when the callback is called\n * @param {string} [options.capture] The capture value\n * @returns {UseFileDialogReturn} An object containing the selected files\n *\n * @example\n * const { values, open, reset } = useFileDialog({ accept: 'image/*' });\n */\nexport const useFileDialog = ((...params: any[]) => {\n const callback = (typeof params[0] === 'function' ? params[0] : undefined) as\n | ((value: FileList | null) => void)\n | undefined;\n const options = (callback ? params[0] : params[1]) as UseFileDialogOptions | undefined;\n\n const [value, setValue] = useState<FileList | null>(null);\n const inputRef = useRef<HTMLInputElement | null>(null);\n const internalCallbackRef = useRef(callback);\n internalCallbackRef.current = callback;\n\n const reset = () => {\n setValue(null);\n internalCallbackRef.current?.(null);\n if (inputRef.current) inputRef.current.value = '';\n };\n\n const open = (openParams?: UseFileDialogOptions) => {\n if (!inputRef.current) return;\n\n inputRef.current.multiple =\n openParams?.multiple ?? options?.multiple ?? DEFAULT_OPTIONS.multiple;\n inputRef.current.accept = openParams?.accept ?? options?.accept ?? DEFAULT_OPTIONS.accept;\n\n const capture = openParams?.capture ?? options?.capture;\n if (capture) inputRef.current.capture = capture;\n\n if (openParams?.reset ?? options?.reset ?? DEFAULT_OPTIONS.reset) reset();\n\n inputRef.current.click();\n };\n\n useEffect(() => {\n const init = () => {\n const input = document.createElement('input');\n input.type = 'file';\n\n input.onchange = (event: Event) => {\n const { files } = event.target as HTMLInputElement;\n setValue(files);\n internalCallbackRef.current?.(files);\n };\n return input;\n };\n\n inputRef.current = init();\n return () => {\n inputRef.current?.remove();\n };\n }, [options?.multiple, options?.accept, options?.capture, options?.reset]);\n\n return { value, open, reset };\n}) as UseFileDialog;\n"],"names":["DEFAULT_OPTIONS","useFileDialog","params","callback","options","value","setValue","useState","inputRef","useRef","internalCallbackRef","reset","open","openParams","capture","useEffect","init","input","event","files"],"mappings":";AAYA,MAAMA,IAAkB;AAAA,EACtB,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,OAAO;AACT,GA+CaC,IAAiB,IAAIC,MAAkB;AAClD,QAAMC,IAAY,OAAOD,EAAO,CAAC,KAAM,aAAaA,EAAO,CAAC,IAAI,QAG1DE,IAAWD,IAAWD,EAAO,CAAC,IAAIA,EAAO,CAAC,GAE1C,CAACG,GAAOC,CAAQ,IAAIC,EAA0B,IAAI,GAClDC,IAAWC,EAAgC,IAAI,GAC/CC,IAAsBD,EAAON,CAAQ;AAC3C,EAAAO,EAAoB,UAAUP;AAE9B,QAAMQ,IAAQ,MAAM;AAClB,IAAAL,EAAS,IAAI,GACbI,EAAoB,UAAU,IAAI,GAC9BF,EAAS,YAASA,EAAS,QAAQ,QAAQ;AAAA,EAAA,GAG3CI,IAAO,CAACC,MAAsC;AAClD,QAAI,CAACL,EAAS,QAAS;AAEvB,IAAAA,EAAS,QAAQ,WACfK,GAAY,YAAYT,GAAS,YAAYJ,EAAgB,UAC/DQ,EAAS,QAAQ,SAASK,GAAY,UAAUT,GAAS,UAAUJ,EAAgB;AAEnF,UAAMc,IAAUD,GAAY,WAAWT,GAAS;AAChD,IAAIU,MAASN,EAAS,QAAQ,UAAUM,KAEpCD,GAAY,SAAST,GAAS,SAASJ,EAAgB,UAAOW,EAAA,GAElEH,EAAS,QAAQ,MAAA;AAAA,EAAM;AAGzB,SAAAO,EAAU,MAAM;AACd,UAAMC,IAAO,MAAM;AACjB,YAAMC,IAAQ,SAAS,cAAc,OAAO;AAC5C,aAAAA,EAAM,OAAO,QAEbA,EAAM,WAAW,CAACC,MAAiB;AACjC,cAAM,EAAE,OAAAC,MAAUD,EAAM;AACxB,QAAAZ,EAASa,CAAK,GACdT,EAAoB,UAAUS,CAAK;AAAA,MAAA,GAE9BF;AAAA,IAAA;AAGT,WAAAT,EAAS,UAAUQ,EAAA,GACZ,MAAM;AACX,MAAAR,EAAS,SAAS,OAAA;AAAA,IAAO;AAAA,EAC3B,GACC,CAACJ,GAAS,UAAUA,GAAS,QAAQA,GAAS,SAASA,GAAS,KAAK,CAAC,GAElE,EAAE,OAAAC,GAAO,MAAAO,GAAM,OAAAD,EAAA;AACxB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFocus.mjs","sources":["../../../../src/hooks/useFocus/useFocus.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 focus options type */\nexport interface UseFocusOptions {\n /** The initial focus state of the target */\n initialValue?: boolean;\n /** The on blur callback */\n onBlur?: (event: FocusEvent) => void;\n /** The on focus callback */\n onFocus?: (event: FocusEvent) => void;\n}\n\n/** The use focus return type */\nexport interface UseFocusReturn {\n /** The boolean state value of the target */\n focused: boolean;\n /** Blur the target */\n blur: () => void;\n /** Focus the target */\n focus: () => void;\n}\n\nexport interface UseFocus {\n (target: HookTarget, options?: UseFocusOptions): UseFocusReturn;\n\n <Target extends Element>(\n options?: UseFocusOptions,\n target?: never\n ): UseFocusReturn & { ref: StateRef<Target> };\n}\n\n/**\n * @name useFocus\n * @description - Hook that allows you to focus on a specific element\n * @category
|
|
1
|
+
{"version":3,"file":"useFocus.mjs","sources":["../../../../src/hooks/useFocus/useFocus.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 focus options type */\nexport interface UseFocusOptions {\n /** The initial focus state of the target */\n initialValue?: boolean;\n /** The on blur callback */\n onBlur?: (event: FocusEvent) => void;\n /** The on focus callback */\n onFocus?: (event: FocusEvent) => void;\n}\n\n/** The use focus return type */\nexport interface UseFocusReturn {\n /** The boolean state value of the target */\n focused: boolean;\n /** Blur the target */\n blur: () => void;\n /** Focus the target */\n focus: () => void;\n}\n\nexport interface UseFocus {\n (target: HookTarget, options?: UseFocusOptions): UseFocusReturn;\n\n <Target extends Element>(\n options?: UseFocusOptions,\n target?: never\n ): UseFocusReturn & { ref: StateRef<Target> };\n}\n\n/**\n * @name useFocus\n * @description - Hook that allows you to focus on a specific element\n * @category Elements\n *\n * @overload\n * @param {HookTarget} target The target element to focus\n * @param {boolean} [options.initialValue=false] The initial focus state of the target\n * @param {(event: FocusEvent) => void} [options.onFocus] The callback function to be invoked on focus\n * @param {(event: FocusEvent) => void} [options.onBlur] The callback function to be invoked on blur\n * @returns {UseFocusReturn} An object with focus state and methods\n *\n * @example\n * const { focus, blur, focused } = useFocus(ref);\n *\n * @overload\n * @template Target The target element\n * @param {boolean} [options.initialValue=false] The initial focus state of the target\n * @param {(event: FocusEvent) => void} [options.onFocus] The callback function to be invoked on focus\n * @param {(event: FocusEvent) => void} [options.onBlur] The callback function to be invoked on blur\n * @returns {UseFocusReturn & { ref: StateRef<Target> }} An object with focus state, methods and ref\n *\n * @example\n * const { ref, focus, blur, focused } = useFocus();\n */\nexport const useFocus = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const options = ((target ? params[1] : params[0]) as UseFocusOptions) ?? {};\n const initialValue = options.initialValue ?? false;\n\n const [focused, setFocused] = useState(initialValue);\n const internalRef = useRefState<Element>();\n const internalOptionsRef = useRef(options);\n internalOptionsRef.current = options;\n\n const elementRef = useRef<HTMLElement | null>(null);\n\n const focus = () => elementRef.current?.focus();\n const blur = () => elementRef.current?.blur();\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n const element = (target ? getElement(target) : internalRef.current) as HTMLElement;\n if (!element) return;\n\n elementRef.current = element;\n\n const onFocus = (event: FocusEvent) => {\n internalOptionsRef.current?.onFocus?.(event);\n if (!focus || (event.target as HTMLElement).matches?.(':focus-visible')) setFocused(true);\n };\n\n const onBlur = (event: FocusEvent) => {\n internalOptionsRef.current?.onBlur?.(event);\n setFocused(false);\n };\n\n if (initialValue) element.focus();\n\n element.addEventListener('focus', onFocus);\n element.addEventListener('blur', onBlur);\n\n return () => {\n element.removeEventListener('focus', onFocus);\n element.removeEventListener('blur', onBlur);\n };\n }, [target, internalRef.state]);\n\n if (target) return { focus, blur, focused };\n return {\n ref: internalRef,\n focus,\n blur,\n focused\n };\n}) as UseFocus;\n"],"names":["useFocus","params","target","isTarget","options","initialValue","focused","setFocused","useState","internalRef","useRefState","internalOptionsRef","useRef","elementRef","focus","blur","useEffect","element","getElement","onFocus","event","onBlur"],"mappings":";;;;AAgEO,MAAMA,IAAY,IAAIC,MAAkB;AAC7C,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,KAAYF,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,MAA0B,CAAA,GACnEI,IAAeD,EAAQ,gBAAgB,IAEvC,CAACE,GAASC,CAAU,IAAIC,EAASH,CAAY,GAC7CI,IAAcC,EAAA,GACdC,IAAqBC,EAAOR,CAAO;AACzC,EAAAO,EAAmB,UAAUP;AAE7B,QAAMS,IAAaD,EAA2B,IAAI,GAE5CE,IAAQ,MAAMD,EAAW,SAAS,MAAA,GAClCE,IAAO,MAAMF,EAAW,SAAS,KAAA;AA8BvC,SA5BAG,EAAU,MAAM;AACd,QAAI,CAACd,KAAU,CAACO,EAAY,MAAO;AACnC,UAAMQ,IAAWf,IAASgB,EAAWhB,CAAM,IAAIO,EAAY;AAC3D,QAAI,CAACQ,EAAS;AAEd,IAAAJ,EAAW,UAAUI;AAErB,UAAME,IAAU,CAACC,MAAsB;AACrC,MAAAT,EAAmB,SAAS,UAAUS,CAAK,IACvC,CAACN,KAAUM,EAAM,OAAuB,UAAU,gBAAgB,QAAc,EAAI;AAAA,IAAA,GAGpFC,IAAS,CAACD,MAAsB;AACpC,MAAAT,EAAmB,SAAS,SAASS,CAAK,GAC1Cb,EAAW,EAAK;AAAA,IAAA;AAGlB,WAAIF,OAAsB,MAAA,GAE1BY,EAAQ,iBAAiB,SAASE,CAAO,GACzCF,EAAQ,iBAAiB,QAAQI,CAAM,GAEhC,MAAM;AACX,MAAAJ,EAAQ,oBAAoB,SAASE,CAAO,GAC5CF,EAAQ,oBAAoB,QAAQI,CAAM;AAAA,IAAA;AAAA,EAC5C,GACC,CAACnB,GAAQO,EAAY,KAAK,CAAC,GAE1BP,IAAe,EAAE,OAAAY,GAAO,MAAAC,GAAM,SAAAT,EAAA,IAC3B;AAAA,IACL,KAAKG;AAAA,IACL,OAAAK;AAAA,IACA,MAAAC;AAAA,IACA,SAAAT;AAAA,EAAA;AAEJ;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFps.mjs","sources":["../../../../src/hooks/useFps/useFps.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/**\n * @name useFps\n * @description - Hook that measures frames per second\n * @category
|
|
1
|
+
{"version":3,"file":"useFps.mjs","sources":["../../../../src/hooks/useFps/useFps.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/**\n * @name useFps\n * @description - Hook that measures frames per second\n * @category Browser\n *\n * @browserapi requestAnimationFrame https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame\n *\n * @returns {number} A number which determines frames per second\n *\n * @example\n * const fps = useFps();\n */\nexport const useFps = () => {\n const [fps, setFps] = useState(0);\n\n useEffect(() => {\n let frameCount = 0;\n let startTime = performance.now();\n let rafId: number;\n\n const onRequestAnimationFrame = () => {\n frameCount += 1;\n const currentTime = performance.now();\n const elapsedTime = currentTime - startTime;\n\n if (elapsedTime >= 1000) {\n const calculatedFps = Math.round((frameCount * 1000) / elapsedTime);\n setFps(calculatedFps);\n frameCount = 0;\n startTime = currentTime;\n }\n\n rafId = requestAnimationFrame(onRequestAnimationFrame);\n };\n\n rafId = requestAnimationFrame(onRequestAnimationFrame);\n\n return () => {\n cancelAnimationFrame(rafId);\n };\n }, []);\n\n return fps;\n};\n"],"names":["useFps","fps","setFps","useState","useEffect","frameCount","startTime","rafId","onRequestAnimationFrame","currentTime","elapsedTime","calculatedFps"],"mappings":";AAcO,MAAMA,IAAS,MAAM;AAC1B,QAAM,CAACC,GAAKC,CAAM,IAAIC,EAAS,CAAC;AAEhC,SAAAC,EAAU,MAAM;AACd,QAAIC,IAAa,GACbC,IAAY,YAAY,IAAA,GACxBC;AAEJ,UAAMC,IAA0B,MAAM;AACpC,MAAAH,KAAc;AACd,YAAMI,IAAc,YAAY,IAAA,GAC1BC,IAAcD,IAAcH;AAElC,UAAII,KAAe,KAAM;AACvB,cAAMC,IAAgB,KAAK,MAAON,IAAa,MAAQK,CAAW;AAClE,QAAAR,EAAOS,CAAa,GACpBN,IAAa,GACbC,IAAYG;AAAA,MAAA;AAGd,MAAAF,IAAQ,sBAAsBC,CAAuB;AAAA,IAAA;AAGvD,WAAAD,IAAQ,sBAAsBC,CAAuB,GAE9C,MAAM;AACX,2BAAqBD,CAAK;AAAA,IAAA;AAAA,EAC5B,GACC,EAAE,GAEEN;AACT;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useHash.mjs","sources":["../../../../src/hooks/useHash/useHash.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nconst getHash = () => decodeURIComponent(window.location.hash.replace('#', ''));\n\n/** The use hash return type */\ntype UseHashReturn = [string, (value: string) => void];\n\n/**\n * @name useHash\n * @description - Hook that manages the hash value\n * @category
|
|
1
|
+
{"version":3,"file":"useHash.mjs","sources":["../../../../src/hooks/useHash/useHash.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nconst getHash = () => decodeURIComponent(window.location.hash.replace('#', ''));\n\n/** The use hash return type */\ntype UseHashReturn = [string, (value: string) => void];\n\n/**\n * @name useHash\n * @description - Hook that manages the hash value\n * @category State\n *\n * @param {string} [initialValue] The initial hash value if no hash exists\n * @returns {UseHashReturn} An array containing the hash value and a function to set the hash value\n *\n * @example\n * const [hash, setHash] = useHash(\"initial\");\n */\nexport const useHash = (\n initialValue = '',\n mode: 'initial' | 'replace' = 'replace'\n): UseHashReturn => {\n const [hash, setHash] = useState(() => {\n if (typeof window === 'undefined') return initialValue;\n return getHash() || initialValue;\n });\n\n const set = (value: string) => {\n window.location.hash = value;\n setHash(value);\n };\n\n useEffect(() => {\n if (mode === 'replace') window.location.hash = hash;\n\n const onHashChange = () => setHash(getHash());\n window.addEventListener('hashchange', onHashChange);\n return () => {\n window.removeEventListener('hashchange', onHashChange);\n };\n }, []);\n\n return [hash, set] as const;\n};\n"],"names":["getHash","useHash","initialValue","mode","hash","setHash","useState","set","value","useEffect","onHashChange"],"mappings":";AAEA,MAAMA,IAAU,MAAM,mBAAmB,OAAO,SAAS,KAAK,QAAQ,KAAK,EAAE,CAAC,GAgBjEC,IAAU,CACrBC,IAAe,IACfC,IAA8B,cACZ;AAClB,QAAM,CAACC,GAAMC,CAAO,IAAIC,EAAS,MAC3B,OAAO,SAAW,MAAoBJ,IACnCF,OAAaE,CACrB,GAEKK,IAAM,CAACC,MAAkB;AAC7B,WAAO,SAAS,OAAOA,GACvBH,EAAQG,CAAK;AAAA,EAAA;AAGf,SAAAC,EAAU,MAAM;AACd,IAAIN,MAAS,cAAW,OAAO,SAAS,OAAOC;AAE/C,UAAMM,IAAe,MAAML,EAAQL,GAAS;AAC5C,kBAAO,iBAAiB,cAAcU,CAAY,GAC3C,MAAM;AACX,aAAO,oBAAoB,cAAcA,CAAY;AAAA,IAAA;AAAA,EACvD,GACC,EAAE,GAEE,CAACN,GAAMG,CAAG;AACnB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useHover.mjs","sources":["../../../../src/hooks/useHover/useHover.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 hover options type */\nexport interface UseHoverOptions {\n /** The on entry callback */\n onEntry?: (event: Event) => void;\n /** The on leave callback */\n onLeave?: (event: Event) => void;\n}\n\nexport interface UseHoverReturn {\n value: boolean;\n}\n\nexport interface UseHover {\n (target: HookTarget, callback?: (event: Event) => void): boolean;\n\n (target: HookTarget, options?: UseHoverOptions): boolean;\n\n <Target extends Element>(\n callback?: (event: Event) => void,\n target?: never\n ): {
|
|
1
|
+
{"version":3,"file":"useHover.mjs","sources":["../../../../src/hooks/useHover/useHover.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 hover options type */\nexport interface UseHoverOptions {\n /** The on entry callback */\n onEntry?: (event: Event) => void;\n /** The on leave callback */\n onLeave?: (event: Event) => void;\n}\n\nexport interface UseHoverReturn {\n value: boolean;\n}\n\nexport interface UseHover {\n (target: HookTarget, callback?: (event: Event) => void): boolean;\n\n (target: HookTarget, options?: UseHoverOptions): boolean;\n\n <Target extends Element>(\n callback?: (event: Event) => void,\n target?: never\n ): {\n ref: StateRef<Target>;\n } & UseHoverReturn;\n\n <Target extends Element>(\n options?: UseHoverOptions,\n target?: never\n ): {\n ref: StateRef<Target>;\n } & UseHoverReturn;\n}\n\n/**\n * @name useHover\n * @description - Hook that defines the logic when hovering an element\n * @category Elements\n *\n * @overload\n * @param {HookTarget} target The target element to be hovered\n * @param {(event: Event) => void} [callback] The callback function to be invoked on mouse enter\n * @returns {boolean} The state of the hover\n *\n * @example\n * const hovering = useHover(ref, () => console.log('callback'));\n *\n * @overload\n * @param {HookTarget} target The target element to be hovered\n * @param {(event: Event) => void} [options.onEntry] The callback function to be invoked on mouse enter\n * @param {(event: Event) => void} [options.onLeave] The callback function to be invoked on mouse leave\n * @returns {boolean} The state of the hover\n *\n * @example\n * const hovering = useHover(ref, options);\n *\n * @overload\n * @template Target The target element\n * @param {(event: Event) => void} [callback] The callback function to be invoked on mouse enter\n * @returns {{ ref: StateRef<Target> } & UseHoverReturn} The state of the hover\n *\n * @example\n * const [ref, hovering] = useHover(() => console.log('callback'));\n *\n * @overload\n * @template Target The target element\n * @param {(event: Event) => void} [options.onEntry] The callback function to be invoked on mouse enter\n * @param {(event: Event) => void} [options.onLeave] The callback function to be invoked on mouse leave\n * @returns {{ ref: StateRef<Target> } & UseHoverReturn} The state of the hover\n *\n * @example\n * const [ref, hovering] = useHover(options);\n */\nexport const useHover = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n\n const options = (\n target\n ? typeof params[1] === 'object'\n ? params[1]\n : { onEntry: params[1] }\n : typeof params[0] === 'object'\n ? params[0]\n : { onEntry: params[0] }\n ) as UseHoverOptions | undefined;\n\n const [hovering, setHovering] = useState(false);\n const internalRef = useRefState<Element>();\n const internalOptionsRef = useRef(options);\n internalOptionsRef.current = options;\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n const element = (target ? getElement(target) : internalRef.current) as Element;\n\n if (!element) return;\n\n const onMouseEnter = (event: Event) => {\n internalOptionsRef.current?.onEntry?.(event);\n setHovering(true);\n };\n\n const onMouseLeave = (event: Event) => {\n internalOptionsRef.current?.onLeave?.(event);\n setHovering(false);\n };\n\n element.addEventListener('mouseenter', onMouseEnter);\n element.addEventListener('mouseleave', onMouseLeave);\n\n return () => {\n element.removeEventListener('mouseenter', onMouseEnter);\n element.removeEventListener('mouseleave', onMouseLeave);\n };\n }, [target, internalRef.state]);\n\n if (target) return hovering;\n return {\n ref: internalRef,\n value: hovering\n } as const;\n}) as UseHover;\n"],"names":["useHover","params","target","isTarget","options","hovering","setHovering","useState","internalRef","useRefState","internalOptionsRef","useRef","useEffect","element","getElement","onMouseEnter","event","onMouseLeave"],"mappings":";;;;AAiFO,MAAMA,IAAY,IAAIC,MAAkB;AAC7C,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAE5CG,IACJF,IACI,OAAOD,EAAO,CAAC,KAAM,WACnBA,EAAO,CAAC,IACR,EAAE,SAASA,EAAO,CAAC,EAAA,IACrB,OAAOA,EAAO,CAAC,KAAM,WACnBA,EAAO,CAAC,IACR,EAAE,SAASA,EAAO,CAAC,EAAA,GAGrB,CAACI,GAAUC,CAAW,IAAIC,EAAS,EAAK,GACxCC,IAAcC,EAAA,GACdC,IAAqBC,EAAOP,CAAO;AA4BzC,SA3BAM,EAAmB,UAAUN,GAE7BQ,EAAU,MAAM;AACd,QAAI,CAACV,KAAU,CAACM,EAAY,MAAO;AACnC,UAAMK,IAAWX,IAASY,EAAWZ,CAAM,IAAIM,EAAY;AAE3D,QAAI,CAACK,EAAS;AAEd,UAAME,IAAe,CAACC,MAAiB;AACrC,MAAAN,EAAmB,SAAS,UAAUM,CAAK,GAC3CV,EAAY,EAAI;AAAA,IAAA,GAGZW,IAAe,CAACD,MAAiB;AACrC,MAAAN,EAAmB,SAAS,UAAUM,CAAK,GAC3CV,EAAY,EAAK;AAAA,IAAA;AAGnB,WAAAO,EAAQ,iBAAiB,cAAcE,CAAY,GACnDF,EAAQ,iBAAiB,cAAcI,CAAY,GAE5C,MAAM;AACX,MAAAJ,EAAQ,oBAAoB,cAAcE,CAAY,GACtDF,EAAQ,oBAAoB,cAAcI,CAAY;AAAA,IAAA;AAAA,EACxD,GACC,CAACf,GAAQM,EAAY,KAAK,CAAC,GAE1BN,IAAeG,IACZ;AAAA,IACL,KAAKG;AAAA,IACL,OAAOH;AAAA,EAAA;AAEX;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useImage.mjs","sources":["../../../../src/hooks/useImage/useImage.ts"],"sourcesContent":["import type { UseQueryOptions, UseQueryReturn } from '../useQuery/useQuery';\n\nimport { useQuery } from '../useQuery/useQuery';\n\n/** The use image options */\nexport interface UseImageOptions {\n /** The alt of the image */\n alt?: string;\n /** The class of the image */\n class?: string;\n /** The crossorigin of the image */\n crossorigin?: string;\n /** The loading of the image */\n loading?: HTMLImageElement['loading'];\n /** The referrer policy of the image */\n referrerPolicy?: HTMLImageElement['referrerPolicy'];\n /** The sizes of the image */\n sizes?: string;\n /** The srcset of the image */\n srcset?: string;\n}\n\n/** The use image return type */\nexport type UseImageReturn = UseQueryReturn<HTMLImageElement>;\n\nconst loadImage = async (src: string, options: UseImageOptions = {}): Promise<HTMLImageElement> =>\n new Promise((resolve, reject) => {\n const img = new Image();\n const { srcset, sizes, class: className, loading, crossorigin, referrerPolicy } = options;\n\n img.src = src;\n if (srcset) img.srcset = srcset;\n if (sizes) img.sizes = sizes;\n if (className) img.className = className;\n if (loading) img.loading = loading;\n if (crossorigin) img.crossOrigin = crossorigin;\n\n if (referrerPolicy) img.referrerPolicy = referrerPolicy;\n\n img.onload = () => resolve(img);\n img.onerror = reject;\n });\n\n/**\n * @name useImage\n * @description - Hook that load an image in the browser\n * @category
|
|
1
|
+
{"version":3,"file":"useImage.mjs","sources":["../../../../src/hooks/useImage/useImage.ts"],"sourcesContent":["import type { UseQueryOptions, UseQueryReturn } from '../useQuery/useQuery';\n\nimport { useQuery } from '../useQuery/useQuery';\n\n/** The use image options */\nexport interface UseImageOptions {\n /** The alt of the image */\n alt?: string;\n /** The class of the image */\n class?: string;\n /** The crossorigin of the image */\n crossorigin?: string;\n /** The loading of the image */\n loading?: HTMLImageElement['loading'];\n /** The referrer policy of the image */\n referrerPolicy?: HTMLImageElement['referrerPolicy'];\n /** The sizes of the image */\n sizes?: string;\n /** The srcset of the image */\n srcset?: string;\n}\n\n/** The use image return type */\nexport type UseImageReturn = UseQueryReturn<HTMLImageElement>;\n\nconst loadImage = async (src: string, options: UseImageOptions = {}): Promise<HTMLImageElement> =>\n new Promise((resolve, reject) => {\n const img = new Image();\n const { srcset, sizes, class: className, loading, crossorigin, referrerPolicy } = options;\n\n img.src = src;\n if (srcset) img.srcset = srcset;\n if (sizes) img.sizes = sizes;\n if (className) img.className = className;\n if (loading) img.loading = loading;\n if (crossorigin) img.crossOrigin = crossorigin;\n\n if (referrerPolicy) img.referrerPolicy = referrerPolicy;\n\n img.onload = () => resolve(img);\n img.onerror = reject;\n });\n\n/**\n * @name useImage\n * @description - Hook that load an image in the browser\n * @category Elements\n *\n * @param {string} src The source of the image\n * @param {string} [options.srcset] The srcset of the image\n * @param {string} [options.sizes] The sizes of the image\n * @param {string} [options.alt] The alt of the image\n * @param {string} [options.class] The class of the image\n * @param {HTMLImageElement['loading']} [options.loading] The loading of the image\n * @param {string} [options.crossorigin] The crossorigin of the image\n * @param {HTMLImageElement['referrerPolicy']} [options.referrerPolicy] The referrerPolicy of the image\n * @param {DependencyList} [useQueryOptions.keys] The dependencies for the hook\n * @param {(data: Data) => void} [useQueryOptions.onSuccess] The callback function to be invoked on success\n * @param {(error: Error) => void} [useQueryOptions.onError] The callback function to be invoked on error\n * @param {number} [useQueryOptions.refetchInterval] The refetch interval\n * @param {boolean | number} [useQueryOptions.retry] The retry count of requests\n * @returns {UseImageReturn} An object with the state of the image\n *\n * @example\n * const { data, isLoading, isError, isSuccess, error, refetch, isRefetching } = useImage('https://example.com/image.png');\n */\nexport const useImage = (\n src: string,\n options?: UseImageOptions,\n useQueryOptions: Omit<\n UseQueryOptions<HTMLImageElement, HTMLImageElement>,\n 'initialData' | 'placeholderData' | 'select'\n > = {}\n) =>\n useQuery(() => loadImage(src, options), {\n keys: [src, ...(useQueryOptions.keys ?? [])],\n ...useQueryOptions\n });\n"],"names":["loadImage","src","options","resolve","reject","img","srcset","sizes","className","loading","crossorigin","referrerPolicy","useImage","useQueryOptions","useQuery"],"mappings":";AAyBA,MAAMA,IAAY,OAAOC,GAAaC,IAA2B,CAAA,MAC/D,IAAI,QAAQ,CAACC,GAASC,MAAW;AAC/B,QAAMC,IAAM,IAAI,MAAA,GACV,EAAE,QAAAC,GAAQ,OAAAC,GAAO,OAAOC,GAAW,SAAAC,GAAS,aAAAC,GAAa,gBAAAC,MAAmBT;AAElF,EAAAG,EAAI,MAAMJ,GACNK,QAAY,SAASA,IACrBC,QAAW,QAAQA,IACnBC,QAAe,YAAYA,IAC3BC,QAAa,UAAUA,IACvBC,QAAiB,cAAcA,IAE/BC,QAAoB,iBAAiBA,IAEzCN,EAAI,SAAS,MAAMF,EAAQE,CAAG,GAC9BA,EAAI,UAAUD;AAChB,CAAC,GAyBUQ,IAAW,CACtBX,GACAC,GACAW,IAGI,CAAA,MAEJC,EAAS,MAAMd,EAAUC,GAAKC,CAAO,GAAG;AAAA,EACtC,MAAM,CAACD,GAAK,GAAIY,EAAgB,QAAQ,CAAA,CAAG;AAAA,EAC3C,GAAGA;AACL,CAAC;"}
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { getElement as T } from "../../utils/helpers/getElement.mjs";
|
|
1
|
+
import { useState as k, useRef as L, useEffect as H } from "react";
|
|
2
|
+
import { useRefState as I } from "../useRefState/useRefState.mjs";
|
|
3
|
+
import { isTarget as T } from "../../utils/helpers/isTarget.mjs";
|
|
4
|
+
import { getElement as W } from "../../utils/helpers/getElement.mjs";
|
|
6
5
|
const M = (...e) => {
|
|
7
|
-
const t =
|
|
8
|
-
a.current =
|
|
9
|
-
const u =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
6
|
+
const t = T(e[0]) ? e[0] : void 0, c = t ? e[1] : e[0], s = t ? e[2] : e[1], i = s?.direction ?? "bottom", l = s?.distance ?? 10, [n, f] = k(!1), o = I(), a = L(c);
|
|
7
|
+
a.current = c;
|
|
8
|
+
const u = L(n);
|
|
9
|
+
return u.current = n, H(() => {
|
|
10
|
+
if (!t && !o.state) return;
|
|
11
|
+
const r = t ? W(t) : o.current;
|
|
12
|
+
if (!r) return;
|
|
13
|
+
const d = async (g) => {
|
|
14
|
+
if (u.current) return;
|
|
15
|
+
const { clientHeight: R, scrollHeight: b, scrollTop: m, clientWidth: E, scrollWidth: p, scrollLeft: h } = g.target, v = b - (m + R), S = p - (h + E);
|
|
16
|
+
({
|
|
17
|
+
bottom: v,
|
|
18
|
+
top: m,
|
|
19
|
+
right: S,
|
|
20
|
+
left: h
|
|
21
|
+
})[i] <= l && (f(!0), await a.current(g), f(!1));
|
|
22
|
+
};
|
|
23
|
+
return r.addEventListener("scroll", d), () => {
|
|
24
|
+
r.removeEventListener("scroll", d);
|
|
25
|
+
};
|
|
26
|
+
}, [t, o.state, i, l]), t ? n : {
|
|
27
|
+
ref: o,
|
|
28
|
+
loading: n
|
|
29
29
|
};
|
|
30
30
|
};
|
|
31
31
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInfiniteScroll.mjs","sources":["../../../../src/hooks/useInfiniteScroll/useInfiniteScroll.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 {
|
|
1
|
+
{"version":3,"file":"useInfiniteScroll.mjs","sources":["../../../../src/hooks/useInfiniteScroll/useInfiniteScroll.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 infinite scroll options type */\nexport interface UseInfiniteScrollOptions {\n /** The direction to trigger the callback */\n direction?: 'bottom' | 'left' | 'right' | 'top';\n /** The distance in pixels to trigger the callback */\n distance?: number;\n}\n\nexport interface UseInfiniteScroll {\n (\n target: HookTarget,\n callback: (event: Event) => void,\n options?: UseInfiniteScrollOptions\n ): boolean;\n\n <Target extends Element>(\n callback: (event: Event) => void,\n options?: UseInfiniteScrollOptions,\n target?: never\n ): {\n ref: StateRef<Target>;\n loading: boolean;\n };\n}\n\n/**\n * @name useInfiniteScroll\n * @description - Hook that defines the logic for infinite scroll\n * @category Sensors\n *\n * @overload\n * @template Target The target element\n * @param {(event: Event) => void} callback The callback to execute when a click outside the target is detected\n * @param {number} [options.distance=10] The distance in pixels to trigger the callback\n * @param {string} [options.direction='bottom'] The direction to trigger the callback\n * @returns {{ ref: StateRef<Target>, loading: boolean }} An object containing the ref and loading\n *\n * @example\n * const { ref, loading } = useInfiniteScroll(() => console.log('infinite scroll'));\n *\n * @overload\n * @param {HookTarget} target The target element to detect infinite scroll for\n * @param {(event: Event) => void} callback The callback to execute when a click outside the target is detected\n * @param {number} [options.distance=10] The distance in pixels to trigger the callback\n * @param {string} [options.direction='bottom'] The direction to trigger the callback\n * @returns {boolean} A loading indicator of the infinite scroll\n *\n * @example\n * const loading = useInfiniteScroll(ref, () => console.log('infinite scroll'));\n */\nexport const useInfiniteScroll = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const callback = (target ? params[1] : params[0]) as (event: Event) => void;\n const options = (target ? params[2] : params[1]) as UseInfiniteScrollOptions | undefined;\n\n const direction = options?.direction ?? 'bottom';\n const distance = options?.distance ?? 10;\n\n const [loading, setIsLoading] = useState(false);\n\n const internalRef = useRefState<Element>();\n const internalCallbackRef = useRef(callback);\n internalCallbackRef.current = callback;\n const internalLoadingRef = useRef(loading);\n internalLoadingRef.current = loading;\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n const element = (target ? getElement(target) : internalRef.current) as Element;\n if (!element) return;\n\n const onLoadMore = async (event: Event) => {\n if (internalLoadingRef.current) return;\n\n const { clientHeight, scrollHeight, scrollTop, clientWidth, scrollWidth, scrollLeft } =\n event.target as Element;\n const scrollBottom = scrollHeight - (scrollTop + clientHeight);\n const scrollRight = scrollWidth - (scrollLeft + clientWidth);\n\n const distances = {\n bottom: scrollBottom,\n top: scrollTop,\n right: scrollRight,\n left: scrollLeft\n };\n\n if (distances[direction] <= distance) {\n setIsLoading(true);\n await internalCallbackRef.current(event);\n setIsLoading(false);\n }\n };\n\n element.addEventListener('scroll', onLoadMore);\n\n return () => {\n element.removeEventListener('scroll', onLoadMore);\n };\n }, [target, internalRef.state, direction, distance]);\n\n if (target) return loading;\n return {\n ref: internalRef,\n loading\n };\n}) as UseInfiniteScroll;\n"],"names":["useInfiniteScroll","params","target","isTarget","callback","options","direction","distance","loading","setIsLoading","useState","internalRef","useRefState","internalCallbackRef","useRef","internalLoadingRef","useEffect","element","getElement","onLoadMore","event","clientHeight","scrollHeight","scrollTop","clientWidth","scrollWidth","scrollLeft","scrollBottom","scrollRight"],"mappings":";;;;AA4DO,MAAMA,IAAqB,IAAIC,MAAkB;AACtD,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,IAAYF,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,GACzCI,IAAWH,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,GAExCK,IAAYD,GAAS,aAAa,UAClCE,IAAWF,GAAS,YAAY,IAEhC,CAACG,GAASC,CAAY,IAAIC,EAAS,EAAK,GAExCC,IAAcC,EAAA,GACdC,IAAsBC,EAAOV,CAAQ;AAC3C,EAAAS,EAAoB,UAAUT;AAC9B,QAAMW,IAAqBD,EAAON,CAAO;AAqCzC,SApCAO,EAAmB,UAAUP,GAE7BQ,EAAU,MAAM;AACd,QAAI,CAACd,KAAU,CAACS,EAAY,MAAO;AACnC,UAAMM,IAAWf,IAASgB,EAAWhB,CAAM,IAAIS,EAAY;AAC3D,QAAI,CAACM,EAAS;AAEd,UAAME,IAAa,OAAOC,MAAiB;AACzC,UAAIL,EAAmB,QAAS;AAEhC,YAAM,EAAE,cAAAM,GAAc,cAAAC,GAAc,WAAAC,GAAW,aAAAC,GAAa,aAAAC,GAAa,YAAAC,MACvEN,EAAM,QACFO,IAAeL,KAAgBC,IAAYF,IAC3CO,IAAcH,KAAeC,IAAaF;AAShD,OAPkB;AAAA,QAChB,QAAQG;AAAA,QACR,KAAKJ;AAAA,QACL,OAAOK;AAAA,QACP,MAAMF;AAAA,MAAA,GAGMpB,CAAS,KAAKC,MAC1BE,EAAa,EAAI,GACjB,MAAMI,EAAoB,QAAQO,CAAK,GACvCX,EAAa,EAAK;AAAA,IACpB;AAGF,WAAAQ,EAAQ,iBAAiB,UAAUE,CAAU,GAEtC,MAAM;AACX,MAAAF,EAAQ,oBAAoB,UAAUE,CAAU;AAAA,IAAA;AAAA,EAClD,GACC,CAACjB,GAAQS,EAAY,OAAOL,GAAWC,CAAQ,CAAC,GAE/CL,IAAeM,IACZ;AAAA,IACL,KAAKG;AAAA,IACL,SAAAH;AAAA,EAAA;AAEJ;"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { useState as d, useRef as h, useEffect as v } from "react";
|
|
2
|
-
import { useRefState as
|
|
3
|
-
import { isTarget as
|
|
2
|
+
import { useRefState as a } from "../useRefState/useRefState.mjs";
|
|
3
|
+
import { isTarget as m } from "../../utils/helpers/isTarget.mjs";
|
|
4
4
|
import { getElement as b } from "../../utils/helpers/getElement.mjs";
|
|
5
5
|
const y = (...e) => {
|
|
6
|
-
const n =
|
|
6
|
+
const n = m(e[0]) ? e[0] : void 0, t = n ? typeof e[1] == "object" ? e[1] : { onChange: e[1] } : typeof e[0] == "object" ? e[0] : { onChange: e[0] }, c = t?.onChange, s = t?.enabled ?? !0, [o, g] = d(), r = a(), i = h(c);
|
|
7
7
|
return i.current = c, v(() => {
|
|
8
8
|
if (!s || !n && !r.state) return;
|
|
9
9
|
const f = n ? b(n) : r.current;
|
|
10
10
|
if (!f) return;
|
|
11
11
|
const u = new IntersectionObserver(
|
|
12
|
-
([
|
|
13
|
-
l
|
|
12
|
+
([l]) => {
|
|
13
|
+
g(l), i.current?.(l);
|
|
14
14
|
},
|
|
15
15
|
{
|
|
16
16
|
...t,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntersectionObserver.mjs","sources":["../../../../src/hooks/useIntersectionObserver/useIntersectionObserver.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 intersection observer options type */\nexport interface UseIntersectionObserverOptions extends Omit<IntersectionObserverInit, 'root'> {\n enabled?: boolean;\n
|
|
1
|
+
{"version":3,"file":"useIntersectionObserver.mjs","sources":["../../../../src/hooks/useIntersectionObserver/useIntersectionObserver.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\nexport type UseIntersectionObserverCallback = (entry: IntersectionObserverEntry) => void;\n\n/** The intersection observer options type */\nexport interface UseIntersectionObserverOptions extends Omit<IntersectionObserverInit, 'root'> {\n enabled?: boolean;\n onChange?: UseIntersectionObserverCallback;\n root?: HookTarget;\n}\n\n/** The intersection observer return type */\nexport interface UseIntersectionObserverReturn {\n entry?: IntersectionObserverEntry;\n inView: boolean;\n}\n\nexport interface UseIntersectionObserver {\n <Target extends Element>(\n options?: UseIntersectionObserverOptions,\n target?: never\n ): UseIntersectionObserverReturn & { ref: StateRef<Target> };\n\n (target: HookTarget, options?: UseIntersectionObserverOptions): UseIntersectionObserverReturn;\n\n <Target extends Element>(\n callback: UseIntersectionObserverCallback,\n target?: never\n ): UseIntersectionObserverReturn & { ref: StateRef<Target> };\n\n (callback: UseIntersectionObserverCallback, target: HookTarget): UseIntersectionObserverReturn;\n}\n\n/**\n * @name useIntersectionObserver\n * @description - Hook that gives you intersection observer state\n * @category Sensors\n *\n * @browserapi IntersectionObserver https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver\n *\n * @overload\n * @param {HookTarget} target The target element to detect intersection\n * @param {boolean} [options.enabled=true] The IntersectionObserver options\n * @param {((entries: IntersectionObserverEntry[], observer: IntersectionObserver) => void) | undefined} [options.onChange] The callback to execute when intersection is detected\n * @param {HookTarget} [options.root=document] The root element to observe\n * @returns {UseIntersectionObserverReturn} An object containing the state\n *\n * @example\n * const { ref, entry, inView } = useIntersectionObserver();\n *\n * @overload\n * @template Target The target element\n * @param {boolean} [options.enabled=true] The IntersectionObserver options\n * @param {((entries: IntersectionObserverEntry[], observer: IntersectionObserver) => void) | undefined} [options.onChange] The callback to execute when intersection is detected\n * @param {HookTarget} [options.root=document] The root element to observe\n * @returns {UseIntersectionObserverReturn & { ref: StateRef<Target> }} A React ref to attach to the target element\n *\n * @example\n * const { entry, inView } = useIntersectionObserver(ref);\n *\n * @overload\n * @template Target The target element\n * @param {UseIntersectionObserverCallback} callback The callback to execute when intersection is detected\n * @returns {UseIntersectionObserverReturn & { ref: StateRef<Target> }} A React ref to attach to the target element\n *\n * @example\n * const { ref, entry, inView } = useIntersectionObserver(() => console.log('callback'));\n *\n * @overload\n * @param {UseIntersectionObserverCallback} callback The callback to execute when intersection is detected\n * @param {HookTarget} target The target element to detect intersection\n * @returns {UseIntersectionObserverReturn} An object containing the state\n *\n * @example\n * const { entry, inView } = useIntersectionObserver(() => console.log('callback'), ref);\n */\nexport const useIntersectionObserver = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n\n const options = (\n target\n ? typeof params[1] === 'object'\n ? params[1]\n : { onChange: params[1] }\n : typeof params[0] === 'object'\n ? params[0]\n : { onChange: params[0] }\n ) as UseIntersectionObserverOptions | undefined;\n\n const callback = options?.onChange;\n const enabled = options?.enabled ?? true;\n\n const [entry, setEntry] = useState<IntersectionObserverEntry>();\n\n const internalRef = useRefState<Element>();\n const internalCallbackRef = useRef(callback);\n internalCallbackRef.current = callback;\n\n useEffect(() => {\n if (!enabled || (!target && !internalRef.state)) return;\n\n const element = target ? getElement(target) : internalRef.current;\n if (!element) return;\n\n const observer = new IntersectionObserver(\n ([entry]) => {\n setEntry(entry);\n internalCallbackRef.current?.(entry);\n },\n {\n ...options,\n root: options?.root ? (getElement(options.root) as Document | Element) : document\n }\n );\n\n observer.observe(element as Element);\n\n return () => {\n observer.disconnect();\n };\n }, [target, internalRef.state, options?.rootMargin, options?.threshold, options?.root, enabled]);\n\n if (target) return { entry, inView: !!entry?.isIntersecting };\n return {\n ref: internalRef,\n entry,\n inView: !!entry?.isIntersecting\n };\n}) as UseIntersectionObserver;\n"],"names":["useIntersectionObserver","params","target","isTarget","options","callback","enabled","entry","setEntry","useState","internalRef","useRefState","internalCallbackRef","useRef","useEffect","element","getElement","observer"],"mappings":";;;;AAoFO,MAAMA,IAA2B,IAAIC,MAAkB;AAC5D,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAE5CG,IACJF,IACI,OAAOD,EAAO,CAAC,KAAM,WACnBA,EAAO,CAAC,IACR,EAAE,UAAUA,EAAO,CAAC,EAAA,IACtB,OAAOA,EAAO,CAAC,KAAM,WACnBA,EAAO,CAAC,IACR,EAAE,UAAUA,EAAO,CAAC,EAAA,GAGtBI,IAAWD,GAAS,UACpBE,IAAUF,GAAS,WAAW,IAE9B,CAACG,GAAOC,CAAQ,IAAIC,EAAA,GAEpBC,IAAcC,EAAA,GACdC,IAAsBC,EAAOR,CAAQ;AA2B3C,SA1BAO,EAAoB,UAAUP,GAE9BS,EAAU,MAAM;AACd,QAAI,CAACR,KAAY,CAACJ,KAAU,CAACQ,EAAY,MAAQ;AAEjD,UAAMK,IAAUb,IAASc,EAAWd,CAAM,IAAIQ,EAAY;AAC1D,QAAI,CAACK,EAAS;AAEd,UAAME,IAAW,IAAI;AAAA,MACnB,CAAC,CAACV,CAAK,MAAM;AACX,QAAAC,EAASD,CAAK,GACdK,EAAoB,UAAUL,CAAK;AAAA,MAAA;AAAA,MAErC;AAAA,QACE,GAAGH;AAAA,QACH,MAAMA,GAAS,OAAQY,EAAWZ,EAAQ,IAAI,IAA2B;AAAA,MAAA;AAAA,IAC3E;AAGF,WAAAa,EAAS,QAAQF,CAAkB,GAE5B,MAAM;AACX,MAAAE,EAAS,WAAA;AAAA,IAAW;AAAA,EACtB,GACC,CAACf,GAAQQ,EAAY,OAAON,GAAS,YAAYA,GAAS,WAAWA,GAAS,MAAME,CAAO,CAAC,GAE3FJ,IAAe,EAAE,OAAAK,GAAO,QAAQ,CAAC,CAACA,GAAO,eAAA,IACtC;AAAA,IACL,KAAKG;AAAA,IACL,OAAAH;AAAA,IACA,QAAQ,CAAC,CAACA,GAAO;AAAA,EAAA;AAErB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLastChanged.mjs","sources":["../../../../src/hooks/useLastChanged/useLastChanged.ts"],"sourcesContent":["import { useState } from 'react';\n\nimport { useDidUpdate } from '../useDidUpdate/useDidUpdate';\n\n/** The use last changed options type */\nexport interface UseLastChangedOptions {\n initialValue?: number;\n}\n\n/**\n * @name useLastChanged\n * @description - Hook for records the timestamp of the last change\n * @category
|
|
1
|
+
{"version":3,"file":"useLastChanged.mjs","sources":["../../../../src/hooks/useLastChanged/useLastChanged.ts"],"sourcesContent":["import { useState } from 'react';\n\nimport { useDidUpdate } from '../useDidUpdate/useDidUpdate';\n\n/** The use last changed options type */\nexport interface UseLastChangedOptions {\n initialValue?: number;\n}\n\n/**\n * @name useLastChanged\n * @description - Hook for records the timestamp of the last change\n * @category Utilities\n *\n * @param {any} source The source of the last change\n * @param {number | null} [options.initialValue=null] The initial value\n * @returns {number | null} Return timestamp of the last change\n *\n * @example\n * const lastChanged = useLastChanged(source);\n */\nexport const useLastChanged = (source: any, options?: UseLastChangedOptions): number | null => {\n const [lastChanged, setLastChanged] = useState(options?.initialValue ?? null);\n\n useDidUpdate(() => setLastChanged(Date.now()), [source]);\n\n return lastChanged;\n};\n"],"names":["useLastChanged","source","options","lastChanged","setLastChanged","useState","useDidUpdate"],"mappings":";;AAqBO,MAAMA,IAAiB,CAACC,GAAaC,MAAmD;AAC7F,QAAM,CAACC,GAAaC,CAAc,IAAIC,EAASH,GAAS,gBAAgB,IAAI;AAE5E,SAAAI,EAAa,MAAMF,EAAe,KAAK,IAAA,CAAK,GAAG,CAACH,CAAM,CAAC,GAEhDE;AACT;"}
|
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
import { useState as a } from "react";
|
|
2
2
|
const v = (o = []) => {
|
|
3
3
|
const [r, e] = a(o);
|
|
4
|
-
return {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
(
|
|
9
|
-
|
|
4
|
+
return {
|
|
5
|
+
value: r,
|
|
6
|
+
set: e,
|
|
7
|
+
push: (t) => e((s) => [...s, t]),
|
|
8
|
+
removeAt: (t) => e((s) => [
|
|
9
|
+
...s.slice(0, t),
|
|
10
|
+
...s.slice(t + 1)
|
|
11
|
+
]),
|
|
12
|
+
insertAt: (t, s) => e((c) => [...c.slice(0, t), s, ...c.slice(t)]),
|
|
13
|
+
updateAt: (t, s) => e(
|
|
14
|
+
(c) => c.map((u, n) => n === t ? s : u)
|
|
15
|
+
),
|
|
16
|
+
clear: () => e([]),
|
|
17
|
+
reset: () => e(o)
|
|
18
|
+
};
|
|
10
19
|
};
|
|
11
20
|
export {
|
|
12
21
|
v as useList
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useList.mjs","sources":["../../../../src/hooks/useList/useList.ts"],"sourcesContent":["import { useState } from 'react';\n\n/** The use list return type */\nexport interface UseListReturn<Item> {\n /** The current list of items */\n value: Item[];\n /** Clears the list */\n clear: () => void;\n /** Inserts an item at the specified index */\n insertAt: (insertAtIndex: number, item: Item) => void;\n /** Adds an item to the list */\n push: (item: Item) => void;\n /** Removes an item from the list */\n removeAt: (removeAtIndex: number) => void;\n /** Sets the list of items */\n set: (list: Item[]) => void;\n /** Updates an item at the specified index */\n updateAt: (updateAtIndex: number, item: Item) => void;\n}\n\n/**\n * @name useList\n * @description - Hook that provides state and helper methods to manage a list of items\n * @category
|
|
1
|
+
{"version":3,"file":"useList.mjs","sources":["../../../../src/hooks/useList/useList.ts"],"sourcesContent":["import { useState } from 'react';\n\n/** The use list return type */\nexport interface UseListReturn<Item> {\n /** The current list of items */\n value: Item[];\n /** Clears the list */\n clear: () => void;\n /** Inserts an item at the specified index */\n insertAt: (insertAtIndex: number, item: Item) => void;\n /** Adds an item to the list */\n push: (item: Item) => void;\n /** Removes an item from the list */\n removeAt: (removeAtIndex: number) => void;\n /** Sets the list of items */\n set: (list: Item[]) => void;\n /** Updates an item at the specified index */\n updateAt: (updateAtIndex: number, item: Item) => void;\n}\n\n/**\n * @name useList\n * @description - Hook that provides state and helper methods to manage a list of items\n * @category State\n *\n * @template Item The type of the item\n * @param {Item[] | (() => Item[])} initialList The initial list of items\n * @returns {UseListReturn} An object containing the current list and functions to interact with the list\n *\n * @example\n * const { value, set, push, removeAt, insertAt, updateAt, clear } = useList();\n */\nexport const useList = <Item>(initialList: Item[] = []) => {\n const [list, setList] = useState(initialList);\n\n const push = (item: Item) => setList((prevList) => [...prevList, item]);\n\n const removeAt = (removeAtIndex: number) =>\n setList((prevList) => [\n ...prevList.slice(0, removeAtIndex),\n ...prevList.slice(removeAtIndex + 1)\n ]);\n\n const insertAt = (insertAtIndex: number, item: Item) =>\n setList((l) => [...l.slice(0, insertAtIndex), item, ...l.slice(insertAtIndex)]);\n\n const updateAt = (updateAtIndex: number, item: Item) =>\n setList((prevList) =>\n prevList.map((element, index) => (index === updateAtIndex ? item : element))\n );\n\n const clear = () => setList([]);\n\n const reset = () => setList(initialList);\n\n return {\n value: list,\n set: setList,\n push,\n removeAt,\n insertAt,\n updateAt,\n clear,\n reset\n };\n};\n"],"names":["useList","initialList","list","setList","useState","item","prevList","removeAtIndex","insertAtIndex","l","updateAtIndex","element","index"],"mappings":";AAgCO,MAAMA,IAAU,CAAOC,IAAsB,OAAO;AACzD,QAAM,CAACC,GAAMC,CAAO,IAAIC,EAASH,CAAW;AAsB5C,SAAO;AAAA,IACL,OAAOC;AAAA,IACP,KAAKC;AAAA,IACL,MAvBW,CAACE,MAAeF,EAAQ,CAACG,MAAa,CAAC,GAAGA,GAAUD,CAAI,CAAC;AAAA,IAwBpE,UAtBe,CAACE,MAChBJ,EAAQ,CAACG,MAAa;AAAA,MACpB,GAAGA,EAAS,MAAM,GAAGC,CAAa;AAAA,MAClC,GAAGD,EAAS,MAAMC,IAAgB,CAAC;AAAA,IAAA,CACpC;AAAA,IAmBD,UAjBe,CAACC,GAAuBH,MACvCF,EAAQ,CAACM,MAAM,CAAC,GAAGA,EAAE,MAAM,GAAGD,CAAa,GAAGH,GAAM,GAAGI,EAAE,MAAMD,CAAa,CAAC,CAAC;AAAA,IAiB9E,UAfe,CAACE,GAAuBL,MACvCF;AAAA,MAAQ,CAACG,MACPA,EAAS,IAAI,CAACK,GAASC,MAAWA,MAAUF,IAAgBL,IAAOM,CAAQ;AAAA,IAAA;AAAA,IAc7E,OAXY,MAAMR,EAAQ,EAAE;AAAA,IAY5B,OAVY,MAAMA,EAAQF,CAAW;AAAA,EAUrC;AAEJ;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocalStorage.mjs","sources":["../../../../src/hooks/useLocalStorage/useLocalStorage.ts"],"sourcesContent":["import type { UseStorageInitialValue, UseStorageOptions } from '../useStorage/useStorage';\n\nimport { useStorage } from '../useStorage/useStorage';\n\n/**\n * @name useLocalStorage\n * @description - Hook that manages local storage value\n * @category
|
|
1
|
+
{"version":3,"file":"useLocalStorage.mjs","sources":["../../../../src/hooks/useLocalStorage/useLocalStorage.ts"],"sourcesContent":["import type { UseStorageInitialValue, UseStorageOptions } from '../useStorage/useStorage';\n\nimport { useStorage } from '../useStorage/useStorage';\n\n/**\n * @name useLocalStorage\n * @description - Hook that manages local storage value\n * @category State\n *\n * @browserapi localStorage https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage\n *\n * @template Value The type of the value\n * @param {string} key The key of the storage\n * @param {UseStorageInitialValue<Value>} [initialValue] The initial value of the storage\n * @param {UseStorageOptions<Value>} [options] The options of the storage\n *\n * @example\n * const { value, set, remove } = useLocalStorage('key', 'value');\n */\nexport const useLocalStorage = <Value>(\n key: string,\n initialValue?: UseStorageInitialValue<Value>,\n options?: Omit<UseStorageOptions<Value>, 'initialValue' | 'storage'>\n) =>\n useStorage(key, {\n ...options,\n initialValue,\n storage: typeof window !== 'undefined' ? window.localStorage : undefined\n });\n"],"names":["useLocalStorage","key","initialValue","options","useStorage"],"mappings":";AAmBO,MAAMA,IAAkB,CAC7BC,GACAC,GACAC,MAEAC,EAAWH,GAAK;AAAA,EACd,GAAGE;AAAA,EACH,cAAAD;AAAA,EACA,SAAS,OAAO,SAAW,MAAc,OAAO,eAAe;AACjE,CAAC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLockCallback.mjs","sources":["../../../../src/hooks/useLockCallback/useLockCallback.ts"],"sourcesContent":["import { useRef } from 'react';\n\n/**\n * @name useLockCallback\n * @description - Hook that prevents a callback from being executed multiple times simultaneously\n * @category
|
|
1
|
+
{"version":3,"file":"useLockCallback.mjs","sources":["../../../../src/hooks/useLockCallback/useLockCallback.ts"],"sourcesContent":["import { useRef } from 'react';\n\n/**\n * @name useLockCallback\n * @description - Hook that prevents a callback from being executed multiple times simultaneously\n * @category Async\n *\n * @param {Function} callback The callback to be locked\n * @returns {Function} The locked callback\n *\n * @example\n * const lockedCallback = useLockCallback(() => promise());\n */\nexport const useLockCallback = <Callback extends (...args: any[]) => any>(callback: Callback) => {\n const lockRef = useRef(false);\n const internalCallbackRef = useRef(callback);\n internalCallbackRef.current = callback;\n\n return async (...args: Parameters<Callback>) => {\n if (lockRef.current) return;\n lockRef.current = true;\n\n try {\n return await internalCallbackRef.current(...args);\n } finally {\n lockRef.current = false;\n }\n };\n};\n"],"names":["useLockCallback","callback","lockRef","useRef","internalCallbackRef","args"],"mappings":";AAaO,MAAMA,IAAkB,CAA2CC,MAAuB;AAC/F,QAAMC,IAAUC,EAAO,EAAK,GACtBC,IAAsBD,EAAOF,CAAQ;AAC3C,SAAAG,EAAoB,UAAUH,GAEvB,UAAUI,MAA+B;AAC9C,QAAI,CAAAH,EAAQ,SACZ;AAAA,MAAAA,EAAQ,UAAU;AAElB,UAAI;AACF,eAAO,MAAME,EAAoB,QAAQ,GAAGC,CAAI;AAAA,MAAA,UAClD;AACE,QAAAH,EAAQ,UAAU;AAAA,MAAA;AAAA;AAAA,EACpB;AAEJ;"}
|