@siberiacancode/reactuse 0.2.28 → 0.2.30
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/README.md +71 -71
- package/dist/cjs/helpers/createContext/createContext.cjs.map +1 -1
- package/dist/cjs/helpers/createEventEmitter/createEventEmitter.cjs.map +1 -1
- package/dist/cjs/helpers/createReactiveContext/createReactiveContext.cjs.map +1 -1
- package/dist/cjs/helpers/createStore/createStore.cjs.map +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/useAudio/useAudio.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/useBattery/useBattery.cjs +1 -1
- package/dist/cjs/hooks/useBattery/useBattery.cjs.map +1 -1
- package/dist/cjs/hooks/useBluetooth/useBluetooth.cjs +1 -1
- package/dist/cjs/hooks/useBluetooth/useBluetooth.cjs.map +1 -1
- package/dist/cjs/hooks/useBoolean/useBoolean.cjs.map +1 -1
- package/dist/cjs/hooks/useBreakpoints/useBreakpoints.cjs.map +1 -1
- package/dist/cjs/hooks/useBroadcastChannel/useBroadcastChannel.cjs +1 -1
- package/dist/cjs/hooks/useBroadcastChannel/useBroadcastChannel.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/useClipboard/useClipboard.cjs.map +1 -1
- package/dist/cjs/hooks/useConst/useConst.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/useCopy/useCopy.cjs.map +1 -1
- package/dist/cjs/hooks/useCounter/useCounter.cjs.map +1 -1
- package/dist/cjs/hooks/useCssVar/useCssVar.cjs.map +1 -1
- package/dist/cjs/hooks/useDebounceCallback/useDebounceCallback.cjs.map +1 -1
- package/dist/cjs/hooks/useDebounceState/useDebounceState.cjs +2 -0
- package/dist/cjs/hooks/useDebounceState/useDebounceState.cjs.map +1 -0
- package/dist/cjs/hooks/useDebounceValue/useDebounceValue.cjs.map +1 -1
- package/dist/cjs/hooks/useDefault/useDefault.cjs.map +1 -1
- package/dist/cjs/hooks/useDeviceMotion/useDeviceMotion.cjs.map +1 -1
- package/dist/cjs/hooks/useDeviceOrientation/useDeviceOrientation.cjs +1 -1
- package/dist/cjs/hooks/useDeviceOrientation/useDeviceOrientation.cjs.map +1 -1
- package/dist/cjs/hooks/useDevicePixelRatio/useDevicePixelRatio.cjs +1 -1
- package/dist/cjs/hooks/useDevicePixelRatio/useDevicePixelRatio.cjs.map +1 -1
- package/dist/cjs/hooks/useDidUpdate/useDidUpdate.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/useDocumentEvent/useDocumentEvent.cjs.map +1 -1
- package/dist/cjs/hooks/useDocumentTitle/useDocumentTitle.cjs.map +1 -1
- package/dist/cjs/hooks/useDocumentVisibility/useDocumentVisibility.cjs.map +1 -1
- package/dist/cjs/hooks/useDoubleClick/useDoubleClick.cjs.map +1 -1
- package/dist/cjs/hooks/useDropZone/useDropZone.cjs +1 -1
- package/dist/cjs/hooks/useDropZone/useDropZone.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/useEventListener/useEventListener.cjs +1 -1
- package/dist/cjs/hooks/useEventListener/useEventListener.cjs.map +1 -1
- package/dist/cjs/hooks/useEventSource/useEventSource.cjs.map +1 -1
- package/dist/cjs/hooks/useEyeDropper/useEyeDropper.cjs +1 -1
- package/dist/cjs/hooks/useEyeDropper/useEyeDropper.cjs.map +1 -1
- package/dist/cjs/hooks/useFavicon/useFavicon.cjs +1 -1
- package/dist/cjs/hooks/useFavicon/useFavicon.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 +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/useFul/useFul.cjs.map +1 -1
- package/dist/cjs/hooks/useFullscreen/useFullscreen.cjs.map +1 -1
- package/dist/cjs/hooks/useGamepad/useGamepad.cjs +1 -1
- package/dist/cjs/hooks/useGamepad/useGamepad.cjs.map +1 -1
- package/dist/cjs/hooks/useGeolocation/useGeolocation.cjs.map +1 -1
- package/dist/cjs/hooks/useHash/useHash.cjs.map +1 -1
- package/dist/cjs/hooks/useHotkeys/useHotkeys.cjs.map +1 -1
- package/dist/cjs/hooks/useHover/useHover.cjs +1 -1
- package/dist/cjs/hooks/useHover/useHover.cjs.map +1 -1
- package/dist/cjs/hooks/useIdle/useIdle.cjs.map +1 -1
- package/dist/cjs/hooks/useImage/useImage.cjs.map +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/useInterval/useInterval.cjs.map +1 -1
- package/dist/cjs/hooks/useIsFirstRender/useIsFirstRender.cjs.map +1 -1
- package/dist/cjs/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.cjs.map +1 -1
- package/dist/cjs/hooks/useKeyPress/useKeyPress.cjs.map +1 -1
- package/dist/cjs/hooks/useKeyPressEvent/useKeyPressEvent.cjs.map +1 -1
- package/dist/cjs/hooks/useKeyboard/useKeyboard.cjs.map +1 -1
- package/dist/cjs/hooks/useKeysPressed/useKeysPressed.cjs.map +1 -1
- package/dist/cjs/hooks/useLastChanged/useLastChanged.cjs.map +1 -1
- package/dist/cjs/hooks/useLatest/useLatest.cjs.map +1 -1
- package/dist/cjs/hooks/useLess/useLess.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.map +1 -1
- 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/useMeasure/useMeasure.cjs.map +1 -1
- package/dist/cjs/hooks/useMediaControls/useMediaControls.cjs.map +1 -1
- package/dist/cjs/hooks/useMediaQuery/useMediaQuery.cjs.map +1 -1
- package/dist/cjs/hooks/useMemory/useMemory.cjs +1 -1
- package/dist/cjs/hooks/useMemory/useMemory.cjs.map +1 -1
- package/dist/cjs/hooks/useMergedRef/useMergedRef.cjs +2 -0
- package/dist/cjs/hooks/useMergedRef/useMergedRef.cjs.map +1 -0
- package/dist/cjs/hooks/useMount/useMount.cjs.map +1 -1
- package/dist/cjs/hooks/useMouse/useMouse.cjs.map +1 -1
- package/dist/cjs/hooks/useMutation/useMutation.cjs +1 -1
- package/dist/cjs/hooks/useMutation/useMutation.cjs.map +1 -1
- package/dist/cjs/hooks/useMutationObserver/useMutationObserver.cjs +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 +1 -1
- package/dist/cjs/hooks/useOffsetPagination/useOffsetPagination.cjs.map +1 -1
- package/dist/cjs/hooks/useOnce/useOnce.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/useOtpCredential/useOtpCredential.cjs +1 -1
- package/dist/cjs/hooks/useOtpCredential/useOtpCredential.cjs.map +1 -1
- package/dist/cjs/hooks/usePageLeave/usePageLeave.cjs.map +1 -1
- package/dist/cjs/hooks/usePaint/usePaint.cjs.map +1 -1
- package/dist/cjs/hooks/useParallax/useParallax.cjs.map +1 -1
- package/dist/cjs/hooks/usePerformanceObserver/usePerformanceObserver.cjs +1 -1
- package/dist/cjs/hooks/usePerformanceObserver/usePerformanceObserver.cjs.map +1 -1
- package/dist/cjs/hooks/usePermission/usePermission.cjs +1 -1
- package/dist/cjs/hooks/usePermission/usePermission.cjs.map +1 -1
- package/dist/cjs/hooks/usePictureInPicture/usePictureInPicture.cjs +1 -1
- package/dist/cjs/hooks/usePictureInPicture/usePictureInPicture.cjs.map +1 -1
- package/dist/cjs/hooks/usePointerLock/usePointerLock.cjs +1 -1
- package/dist/cjs/hooks/usePointerLock/usePointerLock.cjs.map +1 -1
- package/dist/cjs/hooks/usePostMessage/usePostMessage.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/usePrevious/usePrevious.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/useRafState/useRafState.cjs.map +1 -1
- 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 +1 -1
- package/dist/cjs/hooks/useResizeObserver/useResizeObserver.cjs.map +1 -1
- package/dist/cjs/hooks/useRightClick/useRightClick.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/useScrollIntoView/useScrollIntoView.cjs.map +1 -1
- package/dist/cjs/hooks/useScrollTo/useScrollTo.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/useShallowEffect/useShallowEffect.cjs.map +1 -1
- package/dist/cjs/hooks/useShare/useShare.cjs +1 -1
- package/dist/cjs/hooks/useShare/useShare.cjs.map +1 -1
- package/dist/cjs/hooks/useSpeechRecognition/useSpeechRecognition.cjs.map +1 -1
- package/dist/cjs/hooks/useSpeechSynthesis/useSpeechSynthesis.cjs +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.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/useTextSelection/useTextSelection.cjs.map +1 -1
- package/dist/cjs/hooks/useThrottleCallback/useThrottleCallback.cjs.map +1 -1
- package/dist/cjs/hooks/useThrottleState/useThrottleState.cjs +2 -0
- package/dist/cjs/hooks/useThrottleState/useThrottleState.cjs.map +1 -0
- package/dist/cjs/hooks/useThrottleValue/useThrottleValue.cjs.map +1 -1
- package/dist/cjs/hooks/useTime/useTime.cjs.map +1 -1
- package/dist/cjs/hooks/useTimeout/useTimeout.cjs.map +1 -1
- package/dist/cjs/hooks/useTimer/useTimer.cjs.map +1 -1
- package/dist/cjs/hooks/useToggle/useToggle.cjs.map +1 -1
- package/dist/cjs/hooks/useUnmount/useUnmount.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/useVibrate/useVibrate.cjs +1 -1
- package/dist/cjs/hooks/useVibrate/useVibrate.cjs.map +1 -1
- package/dist/cjs/hooks/useVirtualKeyboard/useVirtualKeyboard.cjs +1 -1
- package/dist/cjs/hooks/useVirtualKeyboard/useVirtualKeyboard.cjs.map +1 -1
- package/dist/cjs/hooks/useWakeLock/useWakeLock.cjs +1 -1
- package/dist/cjs/hooks/useWakeLock/useWakeLock.cjs.map +1 -1
- package/dist/cjs/hooks/useWebSocket/useWebSocket.cjs.map +1 -1
- package/dist/cjs/hooks/useWindowEvent/useWindowEvent.cjs.map +1 -1
- package/dist/cjs/hooks/useWindowFocus/useWindowFocus.cjs.map +1 -1
- package/dist/cjs/hooks/useWindowScroll/useWindowScroll.cjs.map +1 -1
- package/dist/cjs/hooks/useWindowSize/useWindowSize.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/createContext/createContext.mjs.map +1 -1
- package/dist/esm/helpers/createEventEmitter/createEventEmitter.mjs.map +1 -1
- package/dist/esm/helpers/createReactiveContext/createReactiveContext.mjs.map +1 -1
- package/dist/esm/helpers/createStore/createStore.mjs.map +1 -1
- package/dist/esm/hooks/useActiveElement/useActiveElement.mjs.map +1 -1
- package/dist/esm/hooks/useAsync/useAsync.mjs.map +1 -1
- package/dist/esm/hooks/useAudio/useAudio.mjs.map +1 -1
- package/dist/esm/hooks/useAutoScroll/useAutoScroll.mjs +25 -31
- package/dist/esm/hooks/useAutoScroll/useAutoScroll.mjs.map +1 -1
- package/dist/esm/hooks/useBattery/useBattery.mjs +1 -1
- package/dist/esm/hooks/useBattery/useBattery.mjs.map +1 -1
- package/dist/esm/hooks/useBluetooth/useBluetooth.mjs +16 -18
- package/dist/esm/hooks/useBluetooth/useBluetooth.mjs.map +1 -1
- package/dist/esm/hooks/useBoolean/useBoolean.mjs.map +1 -1
- package/dist/esm/hooks/useBreakpoints/useBreakpoints.mjs.map +1 -1
- package/dist/esm/hooks/useBroadcastChannel/useBroadcastChannel.mjs +8 -8
- package/dist/esm/hooks/useBroadcastChannel/useBroadcastChannel.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/useClipboard/useClipboard.mjs.map +1 -1
- package/dist/esm/hooks/useConst/useConst.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/useCopy/useCopy.mjs.map +1 -1
- package/dist/esm/hooks/useCounter/useCounter.mjs.map +1 -1
- package/dist/esm/hooks/useCssVar/useCssVar.mjs.map +1 -1
- package/dist/esm/hooks/useDebounceCallback/useDebounceCallback.mjs.map +1 -1
- package/dist/esm/hooks/useDebounceState/useDebounceState.mjs +10 -0
- package/dist/esm/hooks/useDebounceState/useDebounceState.mjs.map +1 -0
- package/dist/esm/hooks/useDebounceValue/useDebounceValue.mjs.map +1 -1
- package/dist/esm/hooks/useDefault/useDefault.mjs.map +1 -1
- package/dist/esm/hooks/useDeviceMotion/useDeviceMotion.mjs.map +1 -1
- package/dist/esm/hooks/useDeviceOrientation/useDeviceOrientation.mjs +1 -1
- package/dist/esm/hooks/useDeviceOrientation/useDeviceOrientation.mjs.map +1 -1
- package/dist/esm/hooks/useDevicePixelRatio/useDevicePixelRatio.mjs +1 -1
- package/dist/esm/hooks/useDevicePixelRatio/useDevicePixelRatio.mjs.map +1 -1
- package/dist/esm/hooks/useDidUpdate/useDidUpdate.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/useDocumentEvent/useDocumentEvent.mjs.map +1 -1
- package/dist/esm/hooks/useDocumentTitle/useDocumentTitle.mjs.map +1 -1
- package/dist/esm/hooks/useDocumentVisibility/useDocumentVisibility.mjs.map +1 -1
- package/dist/esm/hooks/useDoubleClick/useDoubleClick.mjs.map +1 -1
- package/dist/esm/hooks/useDropZone/useDropZone.mjs +12 -12
- package/dist/esm/hooks/useDropZone/useDropZone.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/useEventListener/useEventListener.mjs +15 -15
- package/dist/esm/hooks/useEventListener/useEventListener.mjs.map +1 -1
- package/dist/esm/hooks/useEventSource/useEventSource.mjs.map +1 -1
- package/dist/esm/hooks/useEyeDropper/useEyeDropper.mjs +3 -3
- package/dist/esm/hooks/useEyeDropper/useEyeDropper.mjs.map +1 -1
- package/dist/esm/hooks/useFavicon/useFavicon.mjs +12 -15
- package/dist/esm/hooks/useFavicon/useFavicon.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 +26 -22
- package/dist/esm/hooks/useFocus/useFocus.mjs.map +1 -1
- package/dist/esm/hooks/useFps/useFps.mjs.map +1 -1
- package/dist/esm/hooks/useFul/useFul.mjs.map +1 -1
- package/dist/esm/hooks/useFullscreen/useFullscreen.mjs.map +1 -1
- package/dist/esm/hooks/useGamepad/useGamepad.mjs +13 -13
- package/dist/esm/hooks/useGamepad/useGamepad.mjs.map +1 -1
- package/dist/esm/hooks/useGeolocation/useGeolocation.mjs.map +1 -1
- package/dist/esm/hooks/useHash/useHash.mjs.map +1 -1
- package/dist/esm/hooks/useHotkeys/useHotkeys.mjs.map +1 -1
- package/dist/esm/hooks/useHover/useHover.mjs +15 -15
- package/dist/esm/hooks/useHover/useHover.mjs.map +1 -1
- package/dist/esm/hooks/useIdle/useIdle.mjs.map +1 -1
- package/dist/esm/hooks/useImage/useImage.mjs.map +1 -1
- package/dist/esm/hooks/useInfiniteScroll/useInfiniteScroll.mjs.map +1 -1
- package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs +19 -18
- package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs.map +1 -1
- package/dist/esm/hooks/useInterval/useInterval.mjs.map +1 -1
- package/dist/esm/hooks/useIsFirstRender/useIsFirstRender.mjs.map +1 -1
- package/dist/esm/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.mjs.map +1 -1
- package/dist/esm/hooks/useKeyPress/useKeyPress.mjs.map +1 -1
- package/dist/esm/hooks/useKeyPressEvent/useKeyPressEvent.mjs.map +1 -1
- package/dist/esm/hooks/useKeyboard/useKeyboard.mjs.map +1 -1
- package/dist/esm/hooks/useKeysPressed/useKeysPressed.mjs.map +1 -1
- package/dist/esm/hooks/useLastChanged/useLastChanged.mjs.map +1 -1
- package/dist/esm/hooks/useLatest/useLatest.mjs.map +1 -1
- package/dist/esm/hooks/useLess/useLess.mjs.map +1 -1
- 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.map +1 -1
- 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/useMeasure/useMeasure.mjs.map +1 -1
- package/dist/esm/hooks/useMediaControls/useMediaControls.mjs.map +1 -1
- package/dist/esm/hooks/useMediaQuery/useMediaQuery.mjs.map +1 -1
- package/dist/esm/hooks/useMemory/useMemory.mjs +4 -4
- package/dist/esm/hooks/useMemory/useMemory.mjs.map +1 -1
- package/dist/esm/hooks/useMergedRef/useMergedRef.mjs +25 -0
- package/dist/esm/hooks/useMergedRef/useMergedRef.mjs.map +1 -0
- package/dist/esm/hooks/useMount/useMount.mjs.map +1 -1
- package/dist/esm/hooks/useMouse/useMouse.mjs.map +1 -1
- package/dist/esm/hooks/useMutation/useMutation.mjs +18 -18
- package/dist/esm/hooks/useMutation/useMutation.mjs.map +1 -1
- package/dist/esm/hooks/useMutationObserver/useMutationObserver.mjs +28 -20
- 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 +34 -41
- package/dist/esm/hooks/useOffsetPagination/useOffsetPagination.mjs.map +1 -1
- package/dist/esm/hooks/useOnce/useOnce.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 +9 -9
- package/dist/esm/hooks/useOrientation/useOrientation.mjs.map +1 -1
- package/dist/esm/hooks/useOtpCredential/useOtpCredential.mjs +3 -3
- package/dist/esm/hooks/useOtpCredential/useOtpCredential.mjs.map +1 -1
- package/dist/esm/hooks/usePageLeave/usePageLeave.mjs.map +1 -1
- package/dist/esm/hooks/usePaint/usePaint.mjs.map +1 -1
- package/dist/esm/hooks/useParallax/useParallax.mjs.map +1 -1
- package/dist/esm/hooks/usePerformanceObserver/usePerformanceObserver.mjs +11 -11
- package/dist/esm/hooks/usePerformanceObserver/usePerformanceObserver.mjs.map +1 -1
- package/dist/esm/hooks/usePermission/usePermission.mjs +4 -4
- package/dist/esm/hooks/usePermission/usePermission.mjs.map +1 -1
- package/dist/esm/hooks/usePictureInPicture/usePictureInPicture.mjs +17 -17
- package/dist/esm/hooks/usePictureInPicture/usePictureInPicture.mjs.map +1 -1
- package/dist/esm/hooks/usePointerLock/usePointerLock.mjs +3 -3
- package/dist/esm/hooks/usePointerLock/usePointerLock.mjs.map +1 -1
- package/dist/esm/hooks/usePostMessage/usePostMessage.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/usePrevious/usePrevious.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/useRafState/useRafState.mjs.map +1 -1
- 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 +17 -16
- package/dist/esm/hooks/useResizeObserver/useResizeObserver.mjs.map +1 -1
- package/dist/esm/hooks/useRightClick/useRightClick.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/useScrollIntoView/useScrollIntoView.mjs.map +1 -1
- package/dist/esm/hooks/useScrollTo/useScrollTo.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/useShallowEffect/useShallowEffect.mjs.map +1 -1
- package/dist/esm/hooks/useShare/useShare.mjs +1 -1
- package/dist/esm/hooks/useShare/useShare.mjs.map +1 -1
- package/dist/esm/hooks/useSpeechRecognition/useSpeechRecognition.mjs.map +1 -1
- package/dist/esm/hooks/useSpeechSynthesis/useSpeechSynthesis.mjs +11 -11
- 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.map +1 -1
- package/dist/esm/hooks/useStorage/useStorage.mjs.map +1 -1
- package/dist/esm/hooks/useTextDirection/useTextDirection.mjs +14 -14
- package/dist/esm/hooks/useTextDirection/useTextDirection.mjs.map +1 -1
- package/dist/esm/hooks/useTextSelection/useTextSelection.mjs.map +1 -1
- package/dist/esm/hooks/useThrottleCallback/useThrottleCallback.mjs.map +1 -1
- package/dist/esm/hooks/useThrottleState/useThrottleState.mjs +10 -0
- package/dist/esm/hooks/useThrottleState/useThrottleState.mjs.map +1 -0
- package/dist/esm/hooks/useThrottleValue/useThrottleValue.mjs.map +1 -1
- package/dist/esm/hooks/useTime/useTime.mjs.map +1 -1
- package/dist/esm/hooks/useTimeout/useTimeout.mjs.map +1 -1
- package/dist/esm/hooks/useTimer/useTimer.mjs.map +1 -1
- package/dist/esm/hooks/useToggle/useToggle.mjs.map +1 -1
- package/dist/esm/hooks/useUnmount/useUnmount.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/useVibrate/useVibrate.mjs +12 -12
- package/dist/esm/hooks/useVibrate/useVibrate.mjs.map +1 -1
- package/dist/esm/hooks/useVirtualKeyboard/useVirtualKeyboard.mjs +7 -7
- package/dist/esm/hooks/useVirtualKeyboard/useVirtualKeyboard.mjs.map +1 -1
- package/dist/esm/hooks/useWakeLock/useWakeLock.mjs +1 -1
- package/dist/esm/hooks/useWakeLock/useWakeLock.mjs.map +1 -1
- package/dist/esm/hooks/useWebSocket/useWebSocket.mjs.map +1 -1
- package/dist/esm/hooks/useWindowEvent/useWindowEvent.mjs.map +1 -1
- package/dist/esm/hooks/useWindowFocus/useWindowFocus.mjs.map +1 -1
- package/dist/esm/hooks/useWindowScroll/useWindowScroll.mjs.map +1 -1
- package/dist/esm/hooks/useWindowSize/useWindowSize.mjs.map +1 -1
- package/dist/esm/hooks/useWizard/useWizard.mjs.map +1 -1
- package/dist/esm/index.mjs +147 -139
- package/dist/esm/index.mjs.map +1 -1
- package/dist/types/helpers/createContext/createContext.d.ts +1 -0
- package/dist/types/helpers/createEventEmitter/createEventEmitter.d.ts +1 -0
- package/dist/types/helpers/createReactiveContext/createReactiveContext.d.ts +1 -0
- package/dist/types/helpers/createStore/createStore.d.ts +1 -0
- package/dist/types/hooks/state.d.ts +1 -0
- package/dist/types/hooks/useActiveElement/useActiveElement.d.ts +1 -0
- package/dist/types/hooks/useAsync/useAsync.d.ts +1 -0
- package/dist/types/hooks/useAudio/useAudio.d.ts +2 -1
- package/dist/types/hooks/useAutoScroll/useAutoScroll.d.ts +1 -0
- package/dist/types/hooks/useBattery/useBattery.d.ts +1 -0
- package/dist/types/hooks/useBluetooth/useBluetooth.d.ts +1 -0
- package/dist/types/hooks/useBoolean/useBoolean.d.ts +2 -1
- package/dist/types/hooks/useBreakpoints/useBreakpoints.d.ts +1 -0
- package/dist/types/hooks/useBroadcastChannel/useBroadcastChannel.d.ts +1 -0
- package/dist/types/hooks/useBrowserLanguage/useBrowserLanguage.d.ts +2 -1
- package/dist/types/hooks/useClickOutside/useClickOutside.d.ts +2 -1
- package/dist/types/hooks/useClipboard/useClipboard.d.ts +2 -1
- package/dist/types/hooks/useConst/useConst.d.ts +2 -1
- package/dist/types/hooks/useCookie/useCookie.d.ts +2 -1
- package/dist/types/hooks/useCookies/useCookies.d.ts +2 -1
- package/dist/types/hooks/useCopy/useCopy.d.ts +2 -1
- package/dist/types/hooks/useCounter/useCounter.d.ts +2 -1
- package/dist/types/hooks/useCssVar/useCssVar.d.ts +2 -1
- package/dist/types/hooks/useDebounceCallback/useDebounceCallback.d.ts +1 -0
- package/dist/types/hooks/useDebounceState/useDebounceState.d.ts +15 -0
- package/dist/types/hooks/useDebounceValue/useDebounceValue.d.ts +2 -1
- package/dist/types/hooks/useDefault/useDefault.d.ts +2 -1
- package/dist/types/hooks/useDeviceMotion/useDeviceMotion.d.ts +2 -1
- package/dist/types/hooks/useDeviceOrientation/useDeviceOrientation.d.ts +1 -0
- package/dist/types/hooks/useDevicePixelRatio/useDevicePixelRatio.d.ts +1 -0
- package/dist/types/hooks/useDidUpdate/useDidUpdate.d.ts +2 -1
- package/dist/types/hooks/useDisclosure/useDisclosure.d.ts +2 -1
- package/dist/types/hooks/useDisplayMedia/useDisplayMedia.d.ts +1 -0
- package/dist/types/hooks/useDocumentEvent/useDocumentEvent.d.ts +2 -1
- package/dist/types/hooks/useDocumentTitle/useDocumentTitle.d.ts +2 -1
- package/dist/types/hooks/useDocumentVisibility/useDocumentVisibility.d.ts +2 -1
- package/dist/types/hooks/useDoubleClick/useDoubleClick.d.ts +2 -1
- package/dist/types/hooks/useDropZone/useDropZone.d.ts +2 -1
- package/dist/types/hooks/useElementSize/useElementSize.d.ts +2 -1
- package/dist/types/hooks/useEvent/useEvent.d.ts +2 -1
- package/dist/types/hooks/useEventListener/useEventListener.d.ts +5 -2
- package/dist/types/hooks/useEventSource/useEventSource.d.ts +1 -0
- package/dist/types/hooks/useEyeDropper/useEyeDropper.d.ts +1 -0
- package/dist/types/hooks/useFavicon/useFavicon.d.ts +2 -1
- package/dist/types/hooks/useField/useField.d.ts +1 -0
- package/dist/types/hooks/useFileDialog/useFileDialog.d.ts +1 -0
- package/dist/types/hooks/useFocus/useFocus.d.ts +25 -0
- package/dist/types/hooks/useFps/useFps.d.ts +1 -0
- package/dist/types/hooks/useFul/useFul.d.ts +1 -0
- package/dist/types/hooks/useFullscreen/useFullscreen.d.ts +1 -0
- package/dist/types/hooks/useGamepad/useGamepad.d.ts +1 -0
- package/dist/types/hooks/useGeolocation/useGeolocation.d.ts +1 -0
- package/dist/types/hooks/useHash/useHash.d.ts +1 -0
- package/dist/types/hooks/useHotkeys/useHotkeys.d.ts +1 -0
- package/dist/types/hooks/useHover/useHover.d.ts +3 -0
- package/dist/types/hooks/useIdle/useIdle.d.ts +1 -0
- package/dist/types/hooks/useImage/useImage.d.ts +1 -0
- package/dist/types/hooks/useInfiniteScroll/useInfiniteScroll.d.ts +1 -0
- package/dist/types/hooks/useIntersectionObserver/useIntersectionObserver.d.ts +15 -6
- package/dist/types/hooks/useInterval/useInterval.d.ts +1 -0
- package/dist/types/hooks/useIsFirstRender/useIsFirstRender.d.ts +1 -0
- package/dist/types/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.d.ts +1 -0
- package/dist/types/hooks/useKeyPress/useKeyPress.d.ts +1 -0
- package/dist/types/hooks/useKeyPressEvent/useKeyPressEvent.d.ts +1 -0
- package/dist/types/hooks/useKeyboard/useKeyboard.d.ts +1 -0
- package/dist/types/hooks/useKeysPressed/useKeysPressed.d.ts +1 -2
- package/dist/types/hooks/useLastChanged/useLastChanged.d.ts +1 -0
- package/dist/types/hooks/useLatest/useLatest.d.ts +1 -0
- package/dist/types/hooks/useLess/useLess.d.ts +1 -0
- package/dist/types/hooks/useList/useList.d.ts +1 -0
- package/dist/types/hooks/useLocalStorage/useLocalStorage.d.ts +1 -0
- package/dist/types/hooks/useLockCallback/useLockCallback.d.ts +1 -0
- package/dist/types/hooks/useLockScroll/useLockScroll.d.ts +1 -1
- package/dist/types/hooks/useLogger/useLogger.d.ts +1 -0
- package/dist/types/hooks/useLongPress/useLongPress.d.ts +1 -0
- package/dist/types/hooks/useMap/useMap.d.ts +1 -0
- package/dist/types/hooks/useMeasure/useMeasure.d.ts +1 -0
- package/dist/types/hooks/useMediaControls/useMediaControls.d.ts +1 -0
- package/dist/types/hooks/useMediaQuery/useMediaQuery.d.ts +1 -0
- package/dist/types/hooks/useMemory/useMemory.d.ts +1 -0
- package/dist/types/hooks/useMergedRef/useMergedRef.d.ts +17 -0
- package/dist/types/hooks/useMount/useMount.d.ts +1 -0
- package/dist/types/hooks/useMouse/useMouse.d.ts +1 -0
- package/dist/types/hooks/useMutation/useMutation.d.ts +1 -0
- package/dist/types/hooks/useMutationObserver/useMutationObserver.d.ts +43 -26
- package/dist/types/hooks/useNetwork/useNetwork.d.ts +1 -0
- package/dist/types/hooks/useObject/useObject.d.ts +35 -0
- package/dist/types/hooks/useOffsetPagination/useOffsetPagination.d.ts +12 -24
- package/dist/types/hooks/useOnce/useOnce.d.ts +1 -0
- package/dist/types/hooks/useOnline/useOnline.d.ts +1 -0
- package/dist/types/hooks/useOperatingSystem/useOperatingSystem.d.ts +1 -0
- package/dist/types/hooks/useOptimistic/useOptimistic.d.ts +1 -0
- package/dist/types/hooks/useOrientation/useOrientation.d.ts +2 -1
- package/dist/types/hooks/useOtpCredential/useOtpCredential.d.ts +1 -0
- package/dist/types/hooks/usePageLeave/usePageLeave.d.ts +1 -0
- package/dist/types/hooks/usePaint/usePaint.d.ts +1 -0
- package/dist/types/hooks/useParallax/useParallax.d.ts +1 -0
- package/dist/types/hooks/usePerformanceObserver/usePerformanceObserver.d.ts +1 -0
- package/dist/types/hooks/usePermission/usePermission.d.ts +1 -0
- package/dist/types/hooks/usePictureInPicture/usePictureInPicture.d.ts +1 -0
- package/dist/types/hooks/usePointerLock/usePointerLock.d.ts +1 -0
- package/dist/types/hooks/usePostMessage/usePostMessage.d.ts +1 -0
- package/dist/types/hooks/usePreferredColorScheme/usePreferredColorScheme.d.ts +1 -0
- package/dist/types/hooks/usePreferredContrast/usePreferredContrast.d.ts +1 -0
- package/dist/types/hooks/usePreferredDark/usePreferredDark.d.ts +1 -0
- package/dist/types/hooks/usePreferredLanguages/usePreferredLanguages.d.ts +1 -0
- package/dist/types/hooks/usePreferredReducedMotion/usePreferredReducedMotion.d.ts +1 -0
- package/dist/types/hooks/usePrevious/usePrevious.d.ts +1 -0
- package/dist/types/hooks/useQuery/useQuery.d.ts +1 -0
- package/dist/types/hooks/useQueue/useQueue.d.ts +1 -0
- package/dist/types/hooks/useRaf/useRaf.d.ts +1 -0
- package/dist/types/hooks/useRafState/useRafState.d.ts +3 -0
- package/dist/types/hooks/useRefState/useRefState.d.ts +1 -0
- package/dist/types/hooks/useRenderCount/useRenderCount.d.ts +1 -0
- package/dist/types/hooks/useRenderInfo/useRenderInfo.d.ts +1 -0
- package/dist/types/hooks/useRerender/useRerender.d.ts +1 -0
- package/dist/types/hooks/useResizeObserver/useResizeObserver.d.ts +55 -31
- package/dist/types/hooks/useRightClick/useRightClick.d.ts +1 -0
- package/dist/types/hooks/useScript/useScript.d.ts +1 -0
- package/dist/types/hooks/useScroll/useScroll.d.ts +1 -0
- package/dist/types/hooks/useScrollIntoView/useScrollIntoView.d.ts +1 -0
- package/dist/types/hooks/useScrollTo/useScrollTo.d.ts +1 -0
- package/dist/types/hooks/useSessionStorage/useSessionStorage.d.ts +1 -0
- package/dist/types/hooks/useSet/useSet.d.ts +1 -0
- package/dist/types/hooks/useShallowEffect/useShallowEffect.d.ts +1 -0
- package/dist/types/hooks/useShare/useShare.d.ts +1 -0
- package/dist/types/hooks/useSpeechRecognition/useSpeechRecognition.d.ts +1 -0
- package/dist/types/hooks/useSpeechSynthesis/useSpeechSynthesis.d.ts +1 -0
- package/dist/types/hooks/useStateHistory/useStateHistory.d.ts +1 -0
- package/dist/types/hooks/useStep/useStep.d.ts +1 -0
- package/dist/types/hooks/useSticky/useSticky.d.ts +1 -0
- package/dist/types/hooks/useStopwatch/useStopwatch.d.ts +1 -0
- package/dist/types/hooks/useStorage/useStorage.d.ts +1 -0
- package/dist/types/hooks/useTextDirection/useTextDirection.d.ts +1 -0
- package/dist/types/hooks/useTextSelection/useTextSelection.d.ts +1 -0
- package/dist/types/hooks/useThrottleCallback/useThrottleCallback.d.ts +1 -0
- package/dist/types/hooks/useThrottleState/useThrottleState.d.ts +15 -0
- package/dist/types/hooks/useThrottleValue/useThrottleValue.d.ts +1 -0
- package/dist/types/hooks/useTime/useTime.d.ts +1 -0
- package/dist/types/hooks/useTimeout/useTimeout.d.ts +1 -0
- package/dist/types/hooks/useTimer/useTimer.d.ts +1 -0
- package/dist/types/hooks/useToggle/useToggle.d.ts +1 -0
- package/dist/types/hooks/useUnmount/useUnmount.d.ts +1 -0
- package/dist/types/hooks/useUrlSearchParam/useUrlSearchParam.d.ts +1 -0
- package/dist/types/hooks/useUrlSearchParams/useUrlSearchParams.d.ts +1 -0
- package/dist/types/hooks/useVibrate/useVibrate.d.ts +1 -0
- package/dist/types/hooks/useVirtualKeyboard/useVirtualKeyboard.d.ts +1 -0
- package/dist/types/hooks/useWakeLock/useWakeLock.d.ts +1 -0
- package/dist/types/hooks/useWebSocket/useWebSocket.d.ts +17 -0
- package/dist/types/hooks/useWindowEvent/useWindowEvent.d.ts +1 -0
- package/dist/types/hooks/useWindowFocus/useWindowFocus.d.ts +1 -0
- package/dist/types/hooks/useWindowScroll/useWindowScroll.d.ts +1 -0
- package/dist/types/hooks/useWindowSize/useWindowSize.d.ts +1 -0
- package/dist/types/hooks/useWizard/useWizard.d.ts +1 -0
- package/dist/types/hooks/utilities.d.ts +2 -0
- package/package.json +89 -89
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMergedRef.mjs","sources":["../../../../src/hooks/useMergedRef/useMergedRef.ts"],"sourcesContent":["import type { Ref, RefCallback } from 'react';\n\nimport { useCallback } from 'react';\n\nexport const assignRef = <Element>(\n ref: Ref<Element>,\n value: Element\n): ReturnType<RefCallback<Element>> => {\n if (typeof ref === 'function') return ref(value);\n if (typeof ref === 'object' && ref !== null && 'current' in ref) ref.current = value;\n};\n\nexport const mergeRefs = <Element>(...refs: Ref<Element>[]): RefCallback<Element> => {\n const cleanupMap = new Map<Ref<Element>, Exclude<ReturnType<RefCallback<Element>>, void>>();\n\n return (node: Element | null) => {\n refs.forEach((ref) => {\n const cleanup = assignRef(ref, node);\n if (cleanup) cleanupMap.set(ref, cleanup);\n });\n\n if (!cleanupMap.size) return;\n\n return () => {\n refs.forEach((ref) => {\n const cleanup = cleanupMap.get(ref);\n if (cleanup && typeof cleanup === 'function') cleanup();\n else assignRef(ref, null);\n });\n cleanupMap.clear();\n };\n };\n};\n\n/**\n * @name useMergedRef\n * @description - Hook that merges multiple refs into a single ref\n * @category State\n * @usage medium\n *\n * @template Element The element type\n * @param {...Ref<Element>[]} refs The refs to merge\n * @returns {RefCallback<Element>} A memoized ref callback that assigns to all provided refs\n *\n * @example\n * const mergedRef = useMergedRef(firstRef, secondRef);\n */\nexport const useMergedRef = <Element>(...refs: Ref<Element>[]) =>\n useCallback(mergeRefs(...refs), refs);\n"],"names":["assignRef","ref","value","mergeRefs","refs","cleanupMap","node","cleanup","useMergedRef","useCallback"],"mappings":";AAIO,MAAMA,IAAY,CACvBC,GACAC,MACqC;AACrC,MAAI,OAAOD,KAAQ,WAAY,QAAOA,EAAIC,CAAK;AAC/C,EAAI,OAAOD,KAAQ,YAAYA,MAAQ,QAAQ,aAAaA,QAAS,UAAUC;AACjF,GAEaC,IAAY,IAAaC,MAA+C;AACnF,QAAMC,wBAAiB,IAAA;AAEvB,SAAO,CAACC,MAAyB;AAM/B,QALAF,EAAK,QAAQ,CAACH,MAAQ;AACpB,YAAMM,IAAUP,EAAUC,GAAKK,CAAI;AACnC,MAAIC,KAASF,EAAW,IAAIJ,GAAKM,CAAO;AAAA,IAAA,CACzC,GAEG,EAACF,EAAW;AAEhB,aAAO,MAAM;AACX,QAAAD,EAAK,QAAQ,CAACH,MAAQ;AACpB,gBAAMM,IAAUF,EAAW,IAAIJ,CAAG;AAClC,UAAIM,KAAW,OAAOA,KAAY,aAAYA,EAAA,IACzCP,EAAUC,GAAK,IAAI;AAAA,QAAA,CACzB,GACDI,EAAW,MAAA;AAAA,MAAM;AAAA,EACnB;AAEJ,GAeaG,IAAe,IAAaJ,MACvCK,EAAYN,EAAU,GAAGC,CAAI,GAAGA,CAAI;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMount.mjs","sources":["../../../../src/hooks/useMount/useMount.ts"],"sourcesContent":["import type { EffectCallback } from 'react';\n\nimport { useEffect } from 'react';\n\n/**\n * @name useMount\n * @description - Hook that executes a callback when the component mounts\n * @category Lifecycle\n *\n * @param {EffectCallback} effect The callback to execute\n *\n * @example\n * useMount(() => console.log('This effect runs on the initial render'));\n */\nexport const useMount = (effect: EffectCallback) => useEffect(effect, []);\n"],"names":["useMount","effect","useEffect"],"mappings":";
|
|
1
|
+
{"version":3,"file":"useMount.mjs","sources":["../../../../src/hooks/useMount/useMount.ts"],"sourcesContent":["import type { EffectCallback } from 'react';\n\nimport { useEffect } from 'react';\n\n/**\n * @name useMount\n * @description - Hook that executes a callback when the component mounts\n * @category Lifecycle\n * @usage necessary\n *\n * @param {EffectCallback} effect The callback to execute\n *\n * @example\n * useMount(() => console.log('This effect runs on the initial render'));\n */\nexport const useMount = (effect: EffectCallback) => useEffect(effect, []);\n"],"names":["useMount","effect","useEffect"],"mappings":";AAeO,MAAMA,IAAW,CAACC,MAA2BC,EAAUD,GAAQ,CAAA,CAAE;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMouse.mjs","sources":["../../../../src/hooks/useMouse/useMouse.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use mouse return type */\nexport interface UseMouseReturn {\n /** The current mouse client x position */\n clientX: number;\n /** The current mouse client y position */\n clientY: number;\n /** The current element position x */\n elementPositionX: number;\n /** The current element position y */\n elementPositionY: number;\n /** The current element x position */\n elementX: number;\n /** The current element y position */\n elementY: number;\n /** The current mouse x position */\n x: number;\n /** The current mouse y position */\n y: number;\n}\n\nexport interface UseMouse {\n (target: HookTarget): UseMouseReturn;\n\n <Target extends Element>(\n target?: never\n ): UseMouseReturn & {\n ref: StateRef<Target>;\n };\n\n (target?: Window): UseMouseReturn;\n}\n\n/**\n * @name useMouse\n * @description - Hook that manages a mouse position\n * @category Sensors\n *\n * @overload\n * @param {HookTarget} [target=window] The target element to manage the mouse position for\n * @returns {UseMouseReturn} An object with the current mouse position\n *\n * @example\n * const { x, y, clientX, clientY, elementX, elementY, elementPositionX, elementPositionY } = useMouse(ref);\n *\n * @overload\n * @template Target The target element\n * @returns {UseMouseReturn & { ref: StateRef<Target> }} An object with the current mouse position and a ref\n *\n * @example\n * const { ref, x, y, clientX, clientY, elementX, elementY, elementPositionX, elementPositionY } = useMouse();\n */\nexport const useMouse = ((...params: any[]) => {\n const target = isTarget(params[0]) ? params[0] : undefined;\n\n const [value, setValue] = useState<UseMouseReturn>({\n x: 0,\n y: 0,\n elementX: 0,\n elementY: 0,\n elementPositionX: 0,\n elementPositionY: 0,\n clientX: 0,\n clientY: 0\n });\n\n const internalRef = useRefState<Element>();\n\n useEffect(() => {\n const onMouseMove = (event: MouseEvent) => {\n const element = (target ? getElement(target) : internalRef.current) as Element | undefined;\n\n const updatedValue = {\n x: event.pageX,\n y: event.pageY,\n clientX: event.clientX,\n clientY: event.clientY\n } as typeof value;\n\n if (element) {\n const { left, top } = element.getBoundingClientRect();\n const elementPositionX = left + window.scrollX;\n const elementPositionY = top + window.scrollY;\n const elementX = event.pageX - elementPositionX;\n const elementY = event.pageY - elementPositionY;\n\n updatedValue.elementX = elementX;\n updatedValue.elementY = elementY;\n updatedValue.elementPositionX = elementPositionX;\n updatedValue.elementPositionY = elementPositionY;\n\n setValue((prevValue) => ({\n ...prevValue,\n ...updatedValue\n }));\n } else {\n updatedValue.elementX = event.pageX;\n updatedValue.elementY = event.pageY;\n updatedValue.elementPositionX = 0;\n updatedValue.elementPositionY = 0;\n\n setValue((prevValue) => ({\n ...prevValue,\n ...updatedValue\n }));\n }\n };\n\n const onScroll = () => {\n setValue((prevValue) => ({\n ...prevValue,\n x: prevValue.x + window.scrollX - prevValue.elementPositionX,\n y: prevValue.y + window.scrollY - prevValue.elementPositionY,\n elementPositionX: window.scrollX,\n elementPositionY: window.scrollY\n }));\n };\n\n document.addEventListener('scroll', onScroll, { passive: true });\n document.addEventListener('mousemove', onMouseMove);\n return () => {\n document.removeEventListener('scroll', onScroll);\n document.removeEventListener('mousemove', onMouseMove);\n };\n }, [internalRef.state, target]);\n\n if (target) return value;\n return {\n ref: internalRef,\n ...value\n };\n}) as UseMouse;\n"],"names":["useMouse","params","target","isTarget","value","setValue","useState","internalRef","useRefState","useEffect","onMouseMove","event","element","getElement","updatedValue","left","top","elementPositionX","elementPositionY","elementX","elementY","prevValue","onScroll"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"useMouse.mjs","sources":["../../../../src/hooks/useMouse/useMouse.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use mouse return type */\nexport interface UseMouseReturn {\n /** The current mouse client x position */\n clientX: number;\n /** The current mouse client y position */\n clientY: number;\n /** The current element position x */\n elementPositionX: number;\n /** The current element position y */\n elementPositionY: number;\n /** The current element x position */\n elementX: number;\n /** The current element y position */\n elementY: number;\n /** The current mouse x position */\n x: number;\n /** The current mouse y position */\n y: number;\n}\n\nexport interface UseMouse {\n (target: HookTarget): UseMouseReturn;\n\n <Target extends Element>(\n target?: never\n ): UseMouseReturn & {\n ref: StateRef<Target>;\n };\n\n (target?: Window): UseMouseReturn;\n}\n\n/**\n * @name useMouse\n * @description - Hook that manages a mouse position\n * @category Sensors\n * @usage low\n *\n * @overload\n * @param {HookTarget} [target=window] The target element to manage the mouse position for\n * @returns {UseMouseReturn} An object with the current mouse position\n *\n * @example\n * const { x, y, clientX, clientY, elementX, elementY, elementPositionX, elementPositionY } = useMouse(ref);\n *\n * @overload\n * @template Target The target element\n * @returns {UseMouseReturn & { ref: StateRef<Target> }} An object with the current mouse position and a ref\n *\n * @example\n * const { ref, x, y, clientX, clientY, elementX, elementY, elementPositionX, elementPositionY } = useMouse();\n */\nexport const useMouse = ((...params: any[]) => {\n const target = isTarget(params[0]) ? params[0] : undefined;\n\n const [value, setValue] = useState<UseMouseReturn>({\n x: 0,\n y: 0,\n elementX: 0,\n elementY: 0,\n elementPositionX: 0,\n elementPositionY: 0,\n clientX: 0,\n clientY: 0\n });\n\n const internalRef = useRefState<Element>();\n\n useEffect(() => {\n const onMouseMove = (event: MouseEvent) => {\n const element = (target ? getElement(target) : internalRef.current) as Element | undefined;\n\n const updatedValue = {\n x: event.pageX,\n y: event.pageY,\n clientX: event.clientX,\n clientY: event.clientY\n } as typeof value;\n\n if (element) {\n const { left, top } = element.getBoundingClientRect();\n const elementPositionX = left + window.scrollX;\n const elementPositionY = top + window.scrollY;\n const elementX = event.pageX - elementPositionX;\n const elementY = event.pageY - elementPositionY;\n\n updatedValue.elementX = elementX;\n updatedValue.elementY = elementY;\n updatedValue.elementPositionX = elementPositionX;\n updatedValue.elementPositionY = elementPositionY;\n\n setValue((prevValue) => ({\n ...prevValue,\n ...updatedValue\n }));\n } else {\n updatedValue.elementX = event.pageX;\n updatedValue.elementY = event.pageY;\n updatedValue.elementPositionX = 0;\n updatedValue.elementPositionY = 0;\n\n setValue((prevValue) => ({\n ...prevValue,\n ...updatedValue\n }));\n }\n };\n\n const onScroll = () => {\n setValue((prevValue) => ({\n ...prevValue,\n x: prevValue.x + window.scrollX - prevValue.elementPositionX,\n y: prevValue.y + window.scrollY - prevValue.elementPositionY,\n elementPositionX: window.scrollX,\n elementPositionY: window.scrollY\n }));\n };\n\n document.addEventListener('scroll', onScroll, { passive: true });\n document.addEventListener('mousemove', onMouseMove);\n return () => {\n document.removeEventListener('scroll', onScroll);\n document.removeEventListener('mousemove', onMouseMove);\n };\n }, [internalRef.state, target]);\n\n if (target) return value;\n return {\n ref: internalRef,\n ...value\n };\n}) as UseMouse;\n"],"names":["useMouse","params","target","isTarget","value","setValue","useState","internalRef","useRefState","useEffect","onMouseMove","event","element","getElement","updatedValue","left","top","elementPositionX","elementPositionY","elementX","elementY","prevValue","onScroll"],"mappings":";;;;AA8DO,MAAMA,IAAY,IAAIC,MAAkB;AAC7C,QAAMC,IAASC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAE3C,CAACG,GAAOC,CAAQ,IAAIC,EAAyB;AAAA,IACjD,GAAG;AAAA,IACH,GAAG;AAAA,IACH,UAAU;AAAA,IACV,UAAU;AAAA,IACV,kBAAkB;AAAA,IAClB,kBAAkB;AAAA,IAClB,SAAS;AAAA,IACT,SAAS;AAAA,EAAA,CACV,GAEKC,IAAcC,EAAA;AA4DpB,SA1DAC,EAAU,MAAM;AACd,UAAMC,IAAc,CAACC,MAAsB;AACzC,YAAMC,IAAWV,IAASW,EAAWX,CAAM,IAAIK,EAAY,SAErDO,IAAe;AAAA,QACnB,GAAGH,EAAM;AAAA,QACT,GAAGA,EAAM;AAAA,QACT,SAASA,EAAM;AAAA,QACf,SAASA,EAAM;AAAA,MAAA;AAGjB,UAAIC,GAAS;AACX,cAAM,EAAE,MAAAG,GAAM,KAAAC,MAAQJ,EAAQ,sBAAA,GACxBK,IAAmBF,IAAO,OAAO,SACjCG,IAAmBF,IAAM,OAAO,SAChCG,IAAWR,EAAM,QAAQM,GACzBG,IAAWT,EAAM,QAAQO;AAE/B,QAAAJ,EAAa,WAAWK,GACxBL,EAAa,WAAWM,GACxBN,EAAa,mBAAmBG,GAChCH,EAAa,mBAAmBI,GAEhCb,EAAS,CAACgB,OAAe;AAAA,UACvB,GAAGA;AAAA,UACH,GAAGP;AAAA,QAAA,EACH;AAAA,MAAA;AAEF,QAAAA,EAAa,WAAWH,EAAM,OAC9BG,EAAa,WAAWH,EAAM,OAC9BG,EAAa,mBAAmB,GAChCA,EAAa,mBAAmB,GAEhCT,EAAS,CAACgB,OAAe;AAAA,UACvB,GAAGA;AAAA,UACH,GAAGP;AAAA,QAAA,EACH;AAAA,IACJ,GAGIQ,IAAW,MAAM;AACrB,MAAAjB,EAAS,CAACgB,OAAe;AAAA,QACvB,GAAGA;AAAA,QACH,GAAGA,EAAU,IAAI,OAAO,UAAUA,EAAU;AAAA,QAC5C,GAAGA,EAAU,IAAI,OAAO,UAAUA,EAAU;AAAA,QAC5C,kBAAkB,OAAO;AAAA,QACzB,kBAAkB,OAAO;AAAA,MAAA,EACzB;AAAA,IAAA;AAGJ,oBAAS,iBAAiB,UAAUC,GAAU,EAAE,SAAS,IAAM,GAC/D,SAAS,iBAAiB,aAAaZ,CAAW,GAC3C,MAAM;AACX,eAAS,oBAAoB,UAAUY,CAAQ,GAC/C,SAAS,oBAAoB,aAAaZ,CAAW;AAAA,IAAA;AAAA,EACvD,GACC,CAACH,EAAY,OAAOL,CAAM,CAAC,GAE1BA,IAAeE,IACZ;AAAA,IACL,KAAKG;AAAA,IACL,GAAGH;AAAA,EAAA;AAEP;"}
|
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
import { useState as n } from "react";
|
|
2
2
|
const M = (S, c) => {
|
|
3
|
-
const [m, u] = n(!1), [
|
|
3
|
+
const [m, u] = n(!1), [g, o] = n(!1), [I, f] = n(!1), [h, D] = n(null), [A, E] = n(null), a = (t, r) => {
|
|
4
4
|
u(!0);
|
|
5
5
|
const e = r?.attempt ?? 0;
|
|
6
|
-
return S(t).then((
|
|
7
|
-
const
|
|
8
|
-
if (
|
|
9
|
-
if (
|
|
6
|
+
return S(t).then((y) => (r?.onSuccess?.(y), E(y), f(!0), u(!1), D(null), o(!1), y)).catch((y) => {
|
|
7
|
+
const s = typeof r?.retry == "function" ? r?.retry(e, y) : r?.retry, l = typeof r?.retryDelay == "function" ? r?.retryDelay(e, y) : r?.retryDelay;
|
|
8
|
+
if (console.log("retryDelay", l), typeof s == "boolean" && s) {
|
|
9
|
+
if (l) {
|
|
10
10
|
setTimeout(
|
|
11
|
-
() =>
|
|
12
|
-
|
|
11
|
+
() => a(t, { ...r, attempt: e + 1 }),
|
|
12
|
+
l
|
|
13
13
|
);
|
|
14
14
|
return;
|
|
15
15
|
}
|
|
16
|
-
return
|
|
16
|
+
return a(t, { ...r, attempt: e + 1 });
|
|
17
17
|
}
|
|
18
|
-
if (
|
|
19
|
-
if (
|
|
18
|
+
if (s && s > e) {
|
|
19
|
+
if (l) {
|
|
20
20
|
setTimeout(
|
|
21
|
-
() =>
|
|
22
|
-
|
|
21
|
+
() => a(t, { ...r, attempt: e + 1 }),
|
|
22
|
+
l
|
|
23
23
|
);
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
|
-
return
|
|
26
|
+
return a(t, { ...r, attempt: e + 1 });
|
|
27
27
|
}
|
|
28
|
-
r?.onError?.(
|
|
28
|
+
r?.onError?.(y), E(null), f(!1), u(!1), D(y), o(!0);
|
|
29
29
|
});
|
|
30
30
|
};
|
|
31
31
|
return {
|
|
@@ -38,7 +38,7 @@ const M = (S, c) => {
|
|
|
38
38
|
onSuccess: r?.onSuccess ?? c?.onSuccess,
|
|
39
39
|
onError: r?.onError ?? c?.onError
|
|
40
40
|
};
|
|
41
|
-
|
|
41
|
+
a(t, e);
|
|
42
42
|
},
|
|
43
43
|
mutateAsync: async (t, r) => {
|
|
44
44
|
const e = {
|
|
@@ -47,11 +47,11 @@ const M = (S, c) => {
|
|
|
47
47
|
onSuccess: r?.onSuccess ?? c?.onSuccess,
|
|
48
48
|
onError: r?.onError ?? c?.onError
|
|
49
49
|
};
|
|
50
|
-
return
|
|
50
|
+
return a(t, e);
|
|
51
51
|
},
|
|
52
52
|
isLoading: m,
|
|
53
|
-
isError:
|
|
54
|
-
isSuccess:
|
|
53
|
+
isError: g,
|
|
54
|
+
isSuccess: I
|
|
55
55
|
};
|
|
56
56
|
};
|
|
57
57
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMutation.mjs","sources":["../../../../src/hooks/useMutation/useMutation.ts"],"sourcesContent":["import { useState } from 'react';\n\n/* The type of the options */\ninterface UseMutationOptions<Data> {\n /* The retry count of requests */\n retry?: ((failureCount: number, error: Error) => boolean) | boolean | number;\n /* The retry delay of requests */\n retryDelay?: ((retry: number, error: Error) => number) | number;\n /* The callback function to be invoked on error */\n onError?: (error: Error) => void;\n /* The callback function to be invoked on success */\n onSuccess?: (data: Data) => void;\n}\n\n/* The use mutation return type */\ninterface UseMutationReturn<Body, Data> {\n /* The data of the mutation */\n data: Data | null;\n /* The error of the mutation */\n error: Error | null;\n /* The error state of the mutation */\n isError: boolean;\n /* The loading state of the mutation */\n isLoading: boolean;\n /* The success state of the mutation */\n isSuccess: boolean;\n /* The mutate function */\n mutate: (body?: Body, options?: UseMutationOptions<Data>) => void;\n /* The mutate async function */\n mutateAsync: (body?: Body, options?: UseMutationOptions<Data>) => Promise<Data>;\n}\n\nexport interface RequestOptions<Data> extends UseMutationOptions<Data> {\n /* The attempt count */\n attempt?: number;\n}\n\n/**\n * @name useMutation\n * @description - Hook that defines the logic when mutate data\n * @category Async\n *\n * @template Body The type of the body\n * @template Data The type of the data\n * @param {(body: Body) => Promise<Data>} callback The callback function to be invoked\n * @param {boolean | number} [options.retry] The retry count of requests\n * @param {(data: Data) => void} [options.onSuccess] The callback function to be invoked on success\n * @param {(error: Error) => void} [options.onError] The callback function to be invoked on error\n * @returns {UseMutationReturn<Data>} An object with the state of the mutation\n *\n * @example\n * const { mutate, mutateAsync, isLoading, isError, isSuccess, error, data } = useMutation((name) => Promise.resolve(name));\n */\nexport const useMutation = <Body, Data>(\n callback: (body: Body) => Promise<Data>,\n options?: UseMutationOptions<Data>\n) => {\n const [isLoading, setIsLoading] = useState(false);\n const [isError, setIsError] = useState(false);\n const [isSuccess, setIsSuccess] = useState(false);\n\n const [error, setError] = useState<Error | null>(null);\n const [data, setData] = useState<Data | null>(null);\n\n const request = (\n body: Body,\n requestOptions?: RequestOptions<Data>\n ): Promise<Data | undefined> => {\n setIsLoading(true);\n const attempt = requestOptions?.attempt ?? 0;\n\n return callback(body)\n .then((response) => {\n requestOptions?.onSuccess?.(response);\n\n setData(response);\n setIsSuccess(true);\n setIsLoading(false);\n setError(null);\n setIsError(false);\n return response;\n })\n .catch((error: Error) => {\n const retry =\n typeof requestOptions?.retry === 'function'\n ? requestOptions?.retry(attempt, error)\n : requestOptions?.retry;\n\n const retryDelay =\n typeof requestOptions?.retryDelay === 'function'\n ? requestOptions?.retryDelay(attempt, error)\n : requestOptions?.retryDelay;\n\n if (typeof retry === 'boolean' && retry) {\n if (retryDelay) {\n setTimeout(\n () => request(body, { ...requestOptions, attempt: attempt + 1 }),\n retryDelay\n );\n return;\n }\n return request(body, { ...requestOptions, attempt: attempt + 1 });\n }\n\n if (retry && retry > attempt) {\n if (retryDelay) {\n setTimeout(\n () => request(body, { ...requestOptions, attempt: attempt + 1 }),\n retryDelay\n );\n return;\n }\n return request(body, { ...requestOptions, attempt: attempt + 1 });\n }\n\n requestOptions?.onError?.(error);\n setData(null);\n setIsSuccess(false);\n setIsLoading(false);\n setError(error);\n setIsError(true);\n });\n };\n const mutate = (body: Body, mutateOptions?: UseMutationOptions<Data>) => {\n const requestOptions = {\n retry: mutateOptions?.retry ?? options?.retry,\n retryDelay: mutateOptions?.retryDelay ?? options?.retryDelay,\n onSuccess: mutateOptions?.onSuccess ?? options?.onSuccess,\n onError: mutateOptions?.onError ?? options?.onError\n };\n\n request(body, requestOptions);\n };\n\n const mutateAsync = async (body: Body, mutateOptions?: UseMutationOptions<Data>) => {\n const requestOptions = {\n retry: mutateOptions?.retry ?? options?.retry,\n retryDelay: mutateOptions?.retryDelay ?? options?.retryDelay,\n onSuccess: mutateOptions?.onSuccess ?? options?.onSuccess,\n onError: mutateOptions?.onError ?? options?.onError\n };\n\n return request(body, requestOptions) as Promise<Data>;\n };\n\n return {\n data,\n error,\n mutate,\n mutateAsync,\n isLoading,\n isError,\n isSuccess\n } as UseMutationReturn<Body, Data>;\n};\n"],"names":["useMutation","callback","options","isLoading","setIsLoading","useState","isError","setIsError","isSuccess","setIsSuccess","error","setError","data","setData","request","body","requestOptions","attempt","response","retry","retryDelay","mutateOptions"],"mappings":";
|
|
1
|
+
{"version":3,"file":"useMutation.mjs","sources":["../../../../src/hooks/useMutation/useMutation.ts"],"sourcesContent":["import { useState } from 'react';\n\n/* The type of the options */\ninterface UseMutationOptions<Data> {\n /* The retry count of requests */\n retry?: ((failureCount: number, error: Error) => boolean) | boolean | number;\n /* The retry delay of requests */\n retryDelay?: ((retry: number, error: Error) => number) | number;\n /* The callback function to be invoked on error */\n onError?: (error: Error) => void;\n /* The callback function to be invoked on success */\n onSuccess?: (data: Data) => void;\n}\n\n/* The use mutation return type */\ninterface UseMutationReturn<Body, Data> {\n /* The data of the mutation */\n data: Data | null;\n /* The error of the mutation */\n error: Error | null;\n /* The error state of the mutation */\n isError: boolean;\n /* The loading state of the mutation */\n isLoading: boolean;\n /* The success state of the mutation */\n isSuccess: boolean;\n /* The mutate function */\n mutate: (body?: Body, options?: UseMutationOptions<Data>) => void;\n /* The mutate async function */\n mutateAsync: (body?: Body, options?: UseMutationOptions<Data>) => Promise<Data>;\n}\n\nexport interface RequestOptions<Data> extends UseMutationOptions<Data> {\n /* The attempt count */\n attempt?: number;\n}\n\n/**\n * @name useMutation\n * @description - Hook that defines the logic when mutate data\n * @category Async\n * @usage high\n *\n * @template Body The type of the body\n * @template Data The type of the data\n * @param {(body: Body) => Promise<Data>} callback The callback function to be invoked\n * @param {boolean | number} [options.retry] The retry count of requests\n * @param {(data: Data) => void} [options.onSuccess] The callback function to be invoked on success\n * @param {(error: Error) => void} [options.onError] The callback function to be invoked on error\n * @returns {UseMutationReturn<Data>} An object with the state of the mutation\n *\n * @example\n * const { mutate, mutateAsync, isLoading, isError, isSuccess, error, data } = useMutation((name) => Promise.resolve(name));\n */\nexport const useMutation = <Body, Data>(\n callback: (body: Body) => Promise<Data>,\n options?: UseMutationOptions<Data>\n) => {\n const [isLoading, setIsLoading] = useState(false);\n const [isError, setIsError] = useState(false);\n const [isSuccess, setIsSuccess] = useState(false);\n\n const [error, setError] = useState<Error | null>(null);\n const [data, setData] = useState<Data | null>(null);\n\n const request = (\n body: Body,\n requestOptions?: RequestOptions<Data>\n ): Promise<Data | undefined> => {\n setIsLoading(true);\n const attempt = requestOptions?.attempt ?? 0;\n\n return callback(body)\n .then((response) => {\n requestOptions?.onSuccess?.(response);\n\n setData(response);\n setIsSuccess(true);\n setIsLoading(false);\n setError(null);\n setIsError(false);\n return response;\n })\n .catch((error: Error) => {\n const retry =\n typeof requestOptions?.retry === 'function'\n ? requestOptions?.retry(attempt, error)\n : requestOptions?.retry;\n\n const retryDelay =\n typeof requestOptions?.retryDelay === 'function'\n ? requestOptions?.retryDelay(attempt, error)\n : requestOptions?.retryDelay;\n\n console.log('retryDelay', retryDelay);\n\n if (typeof retry === 'boolean' && retry) {\n if (retryDelay) {\n setTimeout(\n () => request(body, { ...requestOptions, attempt: attempt + 1 }),\n retryDelay\n );\n return;\n }\n return request(body, { ...requestOptions, attempt: attempt + 1 });\n }\n\n if (retry && retry > attempt) {\n if (retryDelay) {\n setTimeout(\n () => request(body, { ...requestOptions, attempt: attempt + 1 }),\n retryDelay\n );\n return;\n }\n return request(body, { ...requestOptions, attempt: attempt + 1 });\n }\n\n requestOptions?.onError?.(error);\n setData(null);\n setIsSuccess(false);\n setIsLoading(false);\n setError(error);\n setIsError(true);\n });\n };\n const mutate = (body: Body, mutateOptions?: UseMutationOptions<Data>) => {\n const requestOptions = {\n retry: mutateOptions?.retry ?? options?.retry,\n retryDelay: mutateOptions?.retryDelay ?? options?.retryDelay,\n onSuccess: mutateOptions?.onSuccess ?? options?.onSuccess,\n onError: mutateOptions?.onError ?? options?.onError\n };\n\n request(body, requestOptions);\n };\n\n const mutateAsync = async (body: Body, mutateOptions?: UseMutationOptions<Data>) => {\n const requestOptions = {\n retry: mutateOptions?.retry ?? options?.retry,\n retryDelay: mutateOptions?.retryDelay ?? options?.retryDelay,\n onSuccess: mutateOptions?.onSuccess ?? options?.onSuccess,\n onError: mutateOptions?.onError ?? options?.onError\n };\n\n return request(body, requestOptions) as Promise<Data>;\n };\n\n return {\n data,\n error,\n mutate,\n mutateAsync,\n isLoading,\n isError,\n isSuccess\n } as UseMutationReturn<Body, Data>;\n};\n"],"names":["useMutation","callback","options","isLoading","setIsLoading","useState","isError","setIsError","isSuccess","setIsSuccess","error","setError","data","setData","request","body","requestOptions","attempt","response","retry","retryDelay","mutateOptions"],"mappings":";AAsDO,MAAMA,IAAc,CACzBC,GACAC,MACG;AACH,QAAM,CAACC,GAAWC,CAAY,IAAIC,EAAS,EAAK,GAC1C,CAACC,GAASC,CAAU,IAAIF,EAAS,EAAK,GACtC,CAACG,GAAWC,CAAY,IAAIJ,EAAS,EAAK,GAE1C,CAACK,GAAOC,CAAQ,IAAIN,EAAuB,IAAI,GAC/C,CAACO,GAAMC,CAAO,IAAIR,EAAsB,IAAI,GAE5CS,IAAU,CACdC,GACAC,MAC8B;AAC9B,IAAAZ,EAAa,EAAI;AACjB,UAAMa,IAAUD,GAAgB,WAAW;AAE3C,WAAOf,EAASc,CAAI,EACjB,KAAK,CAACG,OACLF,GAAgB,YAAYE,CAAQ,GAEpCL,EAAQK,CAAQ,GAChBT,EAAa,EAAI,GACjBL,EAAa,EAAK,GAClBO,EAAS,IAAI,GACbJ,EAAW,EAAK,GACTW,EACR,EACA,MAAM,CAACR,MAAiB;AACvB,YAAMS,IACJ,OAAOH,GAAgB,SAAU,aAC7BA,GAAgB,MAAMC,GAASP,CAAK,IACpCM,GAAgB,OAEhBI,IACJ,OAAOJ,GAAgB,cAAe,aAClCA,GAAgB,WAAWC,GAASP,CAAK,IACzCM,GAAgB;AAItB,UAFA,QAAQ,IAAI,cAAcI,CAAU,GAEhC,OAAOD,KAAU,aAAaA,GAAO;AACvC,YAAIC,GAAY;AACd;AAAA,YACE,MAAMN,EAAQC,GAAM,EAAE,GAAGC,GAAgB,SAASC,IAAU,GAAG;AAAA,YAC/DG;AAAA,UAAA;AAEF;AAAA,QAAA;AAEF,eAAON,EAAQC,GAAM,EAAE,GAAGC,GAAgB,SAASC,IAAU,GAAG;AAAA,MAAA;AAGlE,UAAIE,KAASA,IAAQF,GAAS;AAC5B,YAAIG,GAAY;AACd;AAAA,YACE,MAAMN,EAAQC,GAAM,EAAE,GAAGC,GAAgB,SAASC,IAAU,GAAG;AAAA,YAC/DG;AAAA,UAAA;AAEF;AAAA,QAAA;AAEF,eAAON,EAAQC,GAAM,EAAE,GAAGC,GAAgB,SAASC,IAAU,GAAG;AAAA,MAAA;AAGlE,MAAAD,GAAgB,UAAUN,CAAK,GAC/BG,EAAQ,IAAI,GACZJ,EAAa,EAAK,GAClBL,EAAa,EAAK,GAClBO,EAASD,CAAK,GACdH,EAAW,EAAI;AAAA,IAAA,CAChB;AAAA,EAAA;AAwBL,SAAO;AAAA,IACL,MAAAK;AAAA,IACA,OAAAF;AAAA,IACA,QAzBa,CAACK,GAAYM,MAA6C;AACvE,YAAML,IAAiB;AAAA,QACrB,OAAOK,GAAe,SAASnB,GAAS;AAAA,QACxC,YAAYmB,GAAe,cAAcnB,GAAS;AAAA,QAClD,WAAWmB,GAAe,aAAanB,GAAS;AAAA,QAChD,SAASmB,GAAe,WAAWnB,GAAS;AAAA,MAAA;AAG9C,MAAAY,EAAQC,GAAMC,CAAc;AAAA,IAAA;AAAA,IAkB5B,aAfkB,OAAOD,GAAYM,MAA6C;AAClF,YAAML,IAAiB;AAAA,QACrB,OAAOK,GAAe,SAASnB,GAAS;AAAA,QACxC,YAAYmB,GAAe,cAAcnB,GAAS;AAAA,QAClD,WAAWmB,GAAe,aAAanB,GAAS;AAAA,QAChD,SAASmB,GAAe,WAAWnB,GAAS;AAAA,MAAA;AAG9C,aAAOY,EAAQC,GAAMC,CAAc;AAAA,IAAA;AAAA,IAQnC,WAAAb;AAAA,IACA,SAAAG;AAAA,IACA,WAAAE;AAAA,EAAA;AAEJ;"}
|
|
@@ -1,28 +1,36 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
import { useRefState as
|
|
1
|
+
import { useState as d, useRef as v, useEffect as g } from "react";
|
|
2
|
+
import { useRefState as h } from "../useRefState/useRefState.mjs";
|
|
3
3
|
import { isTarget as O } from "../../utils/helpers/isTarget.mjs";
|
|
4
|
-
import { getElement as
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (!
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return
|
|
15
|
-
|
|
4
|
+
import { getElement as C } from "../../utils/helpers/getElement.mjs";
|
|
5
|
+
const y = (...t) => {
|
|
6
|
+
const r = O(t[0]) ? t[0] : void 0, e = r ? typeof t[1] == "object" ? t[1] : { onChange: t[1] } : typeof t[0] == "object" ? t[0] : { onChange: t[0] }, c = e?.onChange, s = e?.enabled ?? !0, [u, b] = d(), n = h(), i = v(c);
|
|
7
|
+
return i.current = c, g(() => {
|
|
8
|
+
if (!s || !r && !n.state) return;
|
|
9
|
+
const a = r ? C(r) : n.current;
|
|
10
|
+
if (!a) return;
|
|
11
|
+
const o = new MutationObserver((f, l) => {
|
|
12
|
+
i.current?.(f, l);
|
|
13
|
+
});
|
|
14
|
+
return b(o), o.observe(a, e), () => {
|
|
15
|
+
o.disconnect();
|
|
16
16
|
};
|
|
17
|
-
}, [
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
}, [
|
|
18
|
+
r,
|
|
19
|
+
n.state,
|
|
20
|
+
e?.childList,
|
|
21
|
+
e?.attributes,
|
|
22
|
+
e?.characterData,
|
|
23
|
+
e?.subtree,
|
|
24
|
+
e?.attributeOldValue,
|
|
25
|
+
e?.characterDataOldValue,
|
|
26
|
+
e?.attributeFilter,
|
|
27
|
+
s
|
|
28
|
+
]), r ? { observer: u } : {
|
|
20
29
|
ref: n,
|
|
21
|
-
|
|
22
|
-
observer: o
|
|
30
|
+
observer: u
|
|
23
31
|
};
|
|
24
32
|
};
|
|
25
33
|
export {
|
|
26
|
-
|
|
34
|
+
y as useMutationObserver
|
|
27
35
|
};
|
|
28
36
|
//# sourceMappingURL=useMutationObserver.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMutationObserver.mjs","sources":["../../../../src/hooks/useMutationObserver/useMutationObserver.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 mutation observer
|
|
1
|
+
{"version":3,"file":"useMutationObserver.mjs","sources":["../../../../src/hooks/useMutationObserver/useMutationObserver.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 mutation observer callback type */\nexport type UseMutationObserverCallback = (\n mutations: MutationRecord[],\n observer: MutationObserver\n) => void;\n\n/** The mutation observer options type */\nexport interface UseMutationObserverOptions extends MutationObserverInit {\n /** The enabled state of the mutation observer */\n enabled?: boolean;\n /** The callback to execute when mutation is detected */\n onChange?: UseMutationObserverCallback;\n}\n\n/** The mutation observer return type */\nexport interface UseMutationObserverReturn {\n /** The mutation observer instance */\n observer?: MutationObserver;\n}\n\nexport interface UseMutationObserver {\n <Target extends Element>(\n options?: UseMutationObserverOptions,\n target?: never\n ): UseMutationObserverReturn & { ref: StateRef<Target> };\n\n (target: HookTarget, options?: UseMutationObserverOptions): UseMutationObserverReturn;\n\n <Target extends Element>(\n callback: UseMutationObserverCallback,\n target?: never\n ): UseMutationObserverReturn & { ref: StateRef<Target> };\n\n (target: HookTarget, callback: UseMutationObserverCallback): UseMutationObserverReturn;\n}\n\n/**\n * @name useMutationObserver\n * @description - Hook that gives you mutation observer state\n * @category Sensors\n * @usage low\n *\n * @browserapi MutationObserver https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver\n *\n * @overload\n * @param {HookTarget} target The target element to observe\n * @param {boolean} [options.enabled=true] The enabled state of the mutation observer\n * @param {UseMutationObserverCallback} [options.onChange] The callback to execute when mutation is detected\n * @param {boolean} [options.attributes] Set to true if mutations to target's attributes are to be observed\n * @param {boolean} [options.characterData] Set to true if mutations to target's data are to be observed\n * @param {boolean} [options.childList] Set to true if mutations to target's children are to be observed\n * @param {boolean} [options.subtree] Set to true if mutations to not just target, but also target's descendants are to be observed\n * @returns {UseMutationObserverReturn} An object containing the mutation observer state\n *\n * @example\n * const { observer, stop } = useMutationObserver(ref, { childList: true });\n *\n * @overload\n * @template Target The target element\n * @param {boolean} [options.enabled=true] The enabled state of the mutation observer\n * @param {UseMutationObserverCallback} [options.onChange] The callback to execute when mutation is detected\n * @param {boolean} [options.attributes] Set to true if mutations to target's attributes are to be observed\n * @param {boolean} [options.characterData] Set to true if mutations to target's data are to be observed\n * @param {boolean} [options.childList] Set to true if mutations to target's children are to be observed\n * @param {boolean} [options.subtree] Set to true if mutations to not just target, but also target's descendants are to be observed\n * @returns {UseMutationObserverReturn & { ref: StateRef<Target> }} A React ref to attach to the target element\n *\n * @example\n * const { ref, observer, stop } = useMutationObserver({ childList: true });\n *\n * @overload\n * @template Target The target element\n * @param {UseMutationObserverCallback} callback The callback to execute when mutation is detected\n * @returns {UseMutationObserverReturn & { ref: StateRef<Target> }} A React ref to attach to the target element\n *\n * @example\n * const { ref, observer, stop } = useMutationObserver((mutations) => console.log(mutations));\n *\n * @overload\n * @param {UseMutationObserverCallback} callback The callback to execute when mutation is detected\n * @param {HookTarget} target The target element to observe\n * @returns {UseMutationObserverReturn} An object containing the mutation observer state\n *\n * @example\n * const { observer, stop } = useMutationObserver((mutations) => console.log(mutations), ref);\n */\nexport const useMutationObserver = ((...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 UseMutationObserverOptions | undefined;\n\n const callback = options?.onChange;\n const enabled = options?.enabled ?? true;\n\n const [observer, setObserver] = useState<MutationObserver>();\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 MutationObserver((mutations, observer) => {\n internalCallbackRef.current?.(mutations, observer);\n });\n\n setObserver(observer);\n observer.observe(element as Element, options);\n\n return () => {\n observer.disconnect();\n };\n }, [\n target,\n internalRef.state,\n options?.childList,\n options?.attributes,\n options?.characterData,\n options?.subtree,\n options?.attributeOldValue,\n options?.characterDataOldValue,\n options?.attributeFilter,\n enabled\n ]);\n\n if (target) return { observer };\n return {\n ref: internalRef,\n observer\n };\n}) as UseMutationObserver;\n"],"names":["useMutationObserver","params","target","isTarget","options","callback","enabled","observer","setObserver","useState","internalRef","useRefState","internalCallbackRef","useRef","useEffect","element","getElement","mutations"],"mappings":";;;;AAgGO,MAAMA,IAAuB,IAAIC,MAAkB;AACxD,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,GAAUC,CAAW,IAAIC,EAAA,GAE1BC,IAAcC,EAAA,GACdC,IAAsBC,EAAOR,CAAQ;AAgC3C,SA/BAO,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,UAAMR,IAAW,IAAI,iBAAiB,CAACU,GAAWV,MAAa;AAC7D,MAAAK,EAAoB,UAAUK,GAAWV,CAAQ;AAAA,IAAA,CAClD;AAED,WAAAC,EAAYD,CAAQ,GACpBA,EAAS,QAAQQ,GAAoBX,CAAO,GAErC,MAAM;AACXG,MAAAA,EAAS,WAAA;AAAA,IAAW;AAAA,EACtB,GACC;AAAA,IACDL;AAAA,IACAQ,EAAY;AAAA,IACZN,GAAS;AAAA,IACTA,GAAS;AAAA,IACTA,GAAS;AAAA,IACTA,GAAS;AAAA,IACTA,GAAS;AAAA,IACTA,GAAS;AAAA,IACTA,GAAS;AAAA,IACTE;AAAA,EAAA,CACD,GAEGJ,IAAe,EAAE,UAAAK,EAAA,IACd;AAAA,IACL,KAAKG;AAAA,IACL,UAAAH;AAAA,EAAA;AAEJ;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNetwork.mjs","sources":["../../../../src/hooks/useNetwork/useNetwork.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nexport interface Connection extends EventTarget {\n readonly downlink: number;\n readonly downlinkMax: number;\n readonly effectiveType: '2g' | '3g' | '4g' | 'slow-2g';\n readonly rtt: number;\n readonly saveData: boolean;\n onChange: (event: Event) => void;\n readonly type:\n | 'bluetooth'\n | 'cellular'\n | 'ethernet'\n | 'mixed'\n | 'none'\n | 'other'\n | 'unknown'\n | 'wifi'\n | 'wimax';\n}\n\ndeclare global {\n interface Navigator {\n readonly connection: Connection;\n readonly mozConnection: Connection;\n readonly webkitConnection: Connection;\n }\n}\n\n/** The type of network connection */\nexport type ConnectionType = Connection['type'];\n/** The effective type of connection */\nexport type ConnectionEffectiveType = Connection['effectiveType'];\n\n/** The use network return type */\nexport interface UseNetworkReturn {\n /** The estimated downlink speed in megabits per seconds */\n downlink?: Connection['downlink'];\n /** The maximum downlink speed, if available */\n downlinkMax?: Connection['downlinkMax'];\n /** The effective type of connection (e.g., '2g', '3g', '4g') */\n effectiveType?: Connection['effectiveType'];\n /** Indicates if the device is currently online */\n online: boolean;\n /** The estimated round-trip time in milliseconds */\n rtt?: Connection['rtt'];\n /** Indicates if the user has enabled data saving mode */\n saveData?: Connection['saveData'];\n /** The type of network connection (e.g., 'wifi', 'cellular') */\n type?: Connection['type'];\n}\n\nexport const getConnection = () =>\n navigator?.connection || navigator?.mozConnection || navigator?.webkitConnection;\n\n/**\n * @name useNetwork\n * @description - Hook to track network status\n * @category Browser\n *\n * @browserapi navigator.connection https://developer.mozilla.org/en-US/docs/Web/API/Navigator/connection\n *\n * @returns {UseNetworkReturn} An object containing the network status\n *\n * @example\n * const { online, downlink, downlinkMax, effectiveType, rtt, saveData, type } = useNetwork();\n */\nexport const useNetwork = (): UseNetworkReturn => {\n const [value, setValue] = useState(() => {\n if (typeof navigator === 'undefined') {\n return {\n online: false,\n type: undefined,\n effectiveType: undefined,\n saveData: false,\n downlink: 0,\n downlinkMax: 0,\n rtt: 0\n };\n }\n const online = navigator.onLine;\n const connection = getConnection();\n\n return {\n online,\n downlink: connection?.downlink,\n downlinkMax: connection?.downlinkMax,\n effectiveType: connection?.effectiveType,\n rtt: connection?.rtt,\n saveData: connection?.saveData,\n type: connection?.type\n };\n });\n\n useEffect(() => {\n const callback = () => {\n const online = navigator.onLine;\n const connection = getConnection();\n\n setValue({\n online,\n downlink: connection?.downlink,\n downlinkMax: connection?.downlinkMax,\n effectiveType: connection?.effectiveType,\n rtt: connection?.rtt,\n saveData: connection?.saveData,\n type: connection?.type\n });\n };\n window.addEventListener('online', callback, { passive: true });\n window.addEventListener('offline', callback, { passive: true });\n\n const connection = getConnection();\n\n if (connection) {\n connection.addEventListener('change', callback, { passive: true });\n }\n\n return () => {\n window.removeEventListener('online', callback);\n window.removeEventListener('offline', callback);\n\n if (connection) {\n connection.removeEventListener('change', callback);\n }\n };\n });\n\n return value;\n};\n"],"names":["getConnection","useNetwork","value","setValue","useState","online","connection","useEffect","callback"],"mappings":";AAoDO,MAAMA,IAAgB,MAC3B,WAAW,cAAc,WAAW,iBAAiB,WAAW,
|
|
1
|
+
{"version":3,"file":"useNetwork.mjs","sources":["../../../../src/hooks/useNetwork/useNetwork.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nexport interface Connection extends EventTarget {\n readonly downlink: number;\n readonly downlinkMax: number;\n readonly effectiveType: '2g' | '3g' | '4g' | 'slow-2g';\n readonly rtt: number;\n readonly saveData: boolean;\n onChange: (event: Event) => void;\n readonly type:\n | 'bluetooth'\n | 'cellular'\n | 'ethernet'\n | 'mixed'\n | 'none'\n | 'other'\n | 'unknown'\n | 'wifi'\n | 'wimax';\n}\n\ndeclare global {\n interface Navigator {\n readonly connection: Connection;\n readonly mozConnection: Connection;\n readonly webkitConnection: Connection;\n }\n}\n\n/** The type of network connection */\nexport type ConnectionType = Connection['type'];\n/** The effective type of connection */\nexport type ConnectionEffectiveType = Connection['effectiveType'];\n\n/** The use network return type */\nexport interface UseNetworkReturn {\n /** The estimated downlink speed in megabits per seconds */\n downlink?: Connection['downlink'];\n /** The maximum downlink speed, if available */\n downlinkMax?: Connection['downlinkMax'];\n /** The effective type of connection (e.g., '2g', '3g', '4g') */\n effectiveType?: Connection['effectiveType'];\n /** Indicates if the device is currently online */\n online: boolean;\n /** The estimated round-trip time in milliseconds */\n rtt?: Connection['rtt'];\n /** Indicates if the user has enabled data saving mode */\n saveData?: Connection['saveData'];\n /** The type of network connection (e.g., 'wifi', 'cellular') */\n type?: Connection['type'];\n}\n\nexport const getConnection = () =>\n navigator?.connection || navigator?.mozConnection || navigator?.webkitConnection;\n\n/**\n * @name useNetwork\n * @description - Hook to track network status\n * @category Browser\n * @usage low\n *\n * @browserapi navigator.connection https://developer.mozilla.org/en-US/docs/Web/API/Navigator/connection\n *\n * @returns {UseNetworkReturn} An object containing the network status\n *\n * @example\n * const { online, downlink, downlinkMax, effectiveType, rtt, saveData, type } = useNetwork();\n */\nexport const useNetwork = (): UseNetworkReturn => {\n const [value, setValue] = useState(() => {\n if (typeof navigator === 'undefined') {\n return {\n online: false,\n type: undefined,\n effectiveType: undefined,\n saveData: false,\n downlink: 0,\n downlinkMax: 0,\n rtt: 0\n };\n }\n const online = navigator.onLine;\n const connection = getConnection();\n\n return {\n online,\n downlink: connection?.downlink,\n downlinkMax: connection?.downlinkMax,\n effectiveType: connection?.effectiveType,\n rtt: connection?.rtt,\n saveData: connection?.saveData,\n type: connection?.type\n };\n });\n\n useEffect(() => {\n const callback = () => {\n const online = navigator.onLine;\n const connection = getConnection();\n\n setValue({\n online,\n downlink: connection?.downlink,\n downlinkMax: connection?.downlinkMax,\n effectiveType: connection?.effectiveType,\n rtt: connection?.rtt,\n saveData: connection?.saveData,\n type: connection?.type\n });\n };\n window.addEventListener('online', callback, { passive: true });\n window.addEventListener('offline', callback, { passive: true });\n\n const connection = getConnection();\n\n if (connection) {\n connection.addEventListener('change', callback, { passive: true });\n }\n\n return () => {\n window.removeEventListener('online', callback);\n window.removeEventListener('offline', callback);\n\n if (connection) {\n connection.removeEventListener('change', callback);\n }\n };\n });\n\n return value;\n};\n"],"names":["getConnection","useNetwork","value","setValue","useState","online","connection","useEffect","callback"],"mappings":";AAoDO,MAAMA,IAAgB,MAC3B,WAAW,cAAc,WAAW,iBAAiB,WAAW,kBAerDC,IAAa,MAAwB;AAChD,QAAM,CAACC,GAAOC,CAAQ,IAAIC,EAAS,MAAM;AACvC,QAAI,OAAO,YAAc;AACvB,aAAO;AAAA,QACL,QAAQ;AAAA,QACR,MAAM;AAAA,QACN,eAAe;AAAA,QACf,UAAU;AAAA,QACV,UAAU;AAAA,QACV,aAAa;AAAA,QACb,KAAK;AAAA,MAAA;AAGT,UAAMC,IAAS,UAAU,QACnBC,IAAaN,EAAA;AAEnB,WAAO;AAAA,MACL,QAAAK;AAAA,MACA,UAAUC,GAAY;AAAA,MACtB,aAAaA,GAAY;AAAA,MACzB,eAAeA,GAAY;AAAA,MAC3B,KAAKA,GAAY;AAAA,MACjB,UAAUA,GAAY;AAAA,MACtB,MAAMA,GAAY;AAAA,IAAA;AAAA,EACpB,CACD;AAED,SAAAC,EAAU,MAAM;AACd,UAAMC,IAAW,MAAM;AACrB,YAAMH,IAAS,UAAU,QACnBC,IAAaN,EAAA;AAEnB,MAAAG,EAAS;AAAA,QACP,QAAAE;AAAA,QACA,UAAUC,GAAY;AAAA,QACtB,aAAaA,GAAY;AAAA,QACzB,eAAeA,GAAY;AAAA,QAC3B,KAAKA,GAAY;AAAA,QACjB,UAAUA,GAAY;AAAA,QACtB,MAAMA,GAAY;AAAA,MAAA,CACnB;AAAA,IAAA;AAEH,WAAO,iBAAiB,UAAUE,GAAU,EAAE,SAAS,IAAM,GAC7D,OAAO,iBAAiB,WAAWA,GAAU,EAAE,SAAS,IAAM;AAE9D,UAAMF,IAAaN,EAAA;AAEnB,WAAIM,KACFA,EAAW,iBAAiB,UAAUE,GAAU,EAAE,SAAS,IAAM,GAG5D,MAAM;AACX,aAAO,oBAAoB,UAAUA,CAAQ,GAC7C,OAAO,oBAAoB,WAAWA,CAAQ,GAE1CF,KACFA,EAAW,oBAAoB,UAAUE,CAAQ;AAAA,IACnD;AAAA,EACF,CACD,GAEMN;AACT;"}
|
|
@@ -1,48 +1,41 @@
|
|
|
1
|
-
import { useState as i, useRef as
|
|
2
|
-
const
|
|
3
|
-
total:
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
},
|
|
8
|
-
onPageCountChange: f = () => {
|
|
9
|
-
},
|
|
10
|
-
onPageSizeChange: I = () => {
|
|
1
|
+
import { useState as i, useRef as m } from "react";
|
|
2
|
+
const z = ({
|
|
3
|
+
total: u = Number.POSITIVE_INFINITY,
|
|
4
|
+
initialPage: g = 1,
|
|
5
|
+
initialPageSize: f = 10,
|
|
6
|
+
onChange: e = () => {
|
|
11
7
|
}
|
|
12
8
|
} = {}) => {
|
|
13
|
-
const [
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
pageCount: u,
|
|
41
|
-
next: O,
|
|
42
|
-
prev: T
|
|
9
|
+
const [a, c] = i(g), [t, P] = i(f), I = m(e);
|
|
10
|
+
I.current = e;
|
|
11
|
+
const n = Math.max(1, Math.ceil(u / t)), p = a === 1, o = a === n;
|
|
12
|
+
return {
|
|
13
|
+
page: a,
|
|
14
|
+
setPage: (s) => {
|
|
15
|
+
c(s), e({ page: s, pageSize: t });
|
|
16
|
+
},
|
|
17
|
+
setPageSize: P,
|
|
18
|
+
pageSize: t,
|
|
19
|
+
isFirstPage: p,
|
|
20
|
+
isLastPage: o,
|
|
21
|
+
pageCount: n,
|
|
22
|
+
next: () => {
|
|
23
|
+
if (o) return e({ page: n, pageSize: t });
|
|
24
|
+
c((s) => {
|
|
25
|
+
const r = s + 1;
|
|
26
|
+
return e({ page: r, pageSize: t }), r;
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
prev: () => {
|
|
30
|
+
if (p) return e({ page: 1, pageSize: t });
|
|
31
|
+
c((s) => {
|
|
32
|
+
const r = s - 1;
|
|
33
|
+
return e({ page: r, pageSize: t }), r;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
43
36
|
};
|
|
44
37
|
};
|
|
45
38
|
export {
|
|
46
|
-
|
|
39
|
+
z as useOffsetPagination
|
|
47
40
|
};
|
|
48
41
|
//# sourceMappingURL=useOffsetPagination.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOffsetPagination.mjs","sources":["../../../../src/hooks/useOffsetPagination/useOffsetPagination.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"useOffsetPagination.mjs","sources":["../../../../src/hooks/useOffsetPagination/useOffsetPagination.ts"],"sourcesContent":["import { useRef, useState } from 'react';\n\n/** The use offset pagination return type */\nexport interface UseOffsetPaginationOptions {\n /** The initial page number */\n initialPage?: number;\n /** The number of items per page */\n initialPageSize?: number;\n /** The total number of items */\n total?: number;\n /** The callback function to be invoked when page changes */\n onChange?: ({ page, pageSize }: { page: number; pageSize: number }) => void;\n}\n\n/** The use offset pagination return type */\nexport interface UseOffsetPaginationReturn {\n /** Whether the current page is the first page */\n isFirstPage: boolean;\n /** Whether the current page is the last page */\n isLastPage: boolean;\n /** The current page number */\n page: number;\n /** The total number of pages */\n pageCount: number;\n /** The number of items per page */\n pageSize: number;\n /** The callback function to go to the next page */\n next: () => void;\n /** The callback function to go to the previous page */\n prev: () => void;\n /** The callback function to set the current page */\n setPage: (page: number) => void;\n /** The callback function to set the page size */\n setPageSize: (pageSize: number) => void;\n}\n\n/**\n * @name useOffsetPagination\n * @description - Hook that defines the logic when pagination\n * @category State\n * @usage medium\n *\n * @param {UseOffsetPaginationOptions} options - The options for the hook\n * @param {number} [options.total] - The total number of items\n * @param {number} [options.pageSize] - The number of items per page\n * @param {number} [options.initialPage] - The current page\n * @param {({ page, pageSize }: { page: number; pageSize: number }) => void} [options.onChange] - The callback function to be invoked when page changes\n * @returns {UseOffsetPaginationReturn} - The state of the hook\n *\n * @example\n * const { currentPage, currentPageSize, pageCount, isFirstPage, isLastPage, prev, next } = useOffsetPagination({\n * total: 100,\n * initialPageSize: 10,\n * initialPage: 1\n * });\n */\nexport const useOffsetPagination = ({\n total = Number.POSITIVE_INFINITY,\n initialPage = 1,\n initialPageSize = 10,\n onChange = () => {}\n}: UseOffsetPaginationOptions = {}): UseOffsetPaginationReturn => {\n const [page, setPage] = useState(initialPage);\n const [pageSize, setPageSize] = useState(initialPageSize);\n\n const onChangeRef = useRef(onChange);\n onChangeRef.current = onChange;\n\n const pageCount = Math.max(1, Math.ceil(total / pageSize));\n\n const isFirstPage = page === 1;\n const isLastPage = page === pageCount;\n\n const next = () => {\n if (isLastPage) return onChange({ page: pageCount, pageSize });\n\n setPage((prevPage) => {\n const page = prevPage + 1;\n onChange({ page, pageSize });\n return page;\n });\n };\n\n const prev = () => {\n if (isFirstPage) return onChange({ page: 1, pageSize });\n\n setPage((prevPage) => {\n const page = prevPage - 1;\n onChange({ page, pageSize });\n return page;\n });\n };\n\n const set = (page: number) => {\n setPage(page);\n onChange({ page, pageSize });\n };\n\n return {\n page,\n setPage: set,\n setPageSize,\n pageSize,\n isFirstPage,\n isLastPage,\n pageCount,\n next,\n prev\n };\n};\n"],"names":["useOffsetPagination","total","initialPage","initialPageSize","onChange","page","setPage","useState","pageSize","setPageSize","onChangeRef","useRef","pageCount","isFirstPage","isLastPage","prevPage"],"mappings":";AAwDO,MAAMA,IAAsB,CAAC;AAAA,EAClC,OAAAC,IAAQ,OAAO;AAAA,EACf,aAAAC,IAAc;AAAA,EACd,iBAAAC,IAAkB;AAAA,EAClB,UAAAC,IAAW,MAAM;AAAA,EAAA;AACnB,IAAgC,OAAkC;AAChE,QAAM,CAACC,GAAMC,CAAO,IAAIC,EAASL,CAAW,GACtC,CAACM,GAAUC,CAAW,IAAIF,EAASJ,CAAe,GAElDO,IAAcC,EAAOP,CAAQ;AACnC,EAAAM,EAAY,UAAUN;AAEtB,QAAMQ,IAAY,KAAK,IAAI,GAAG,KAAK,KAAKX,IAAQO,CAAQ,CAAC,GAEnDK,IAAcR,MAAS,GACvBS,IAAaT,MAASO;AA2B5B,SAAO;AAAA,IACL,MAAAP;AAAA,IACA,SAPU,CAACA,MAAiB;AAC5B,MAAAC,EAAQD,CAAI,GACZD,EAAS,EAAE,MAAAC,GAAM,UAAAG,EAAA,CAAU;AAAA,IAAA;AAAA,IAM3B,aAAAC;AAAA,IACA,UAAAD;AAAA,IACA,aAAAK;AAAA,IACA,YAAAC;AAAA,IACA,WAAAF;AAAA,IACA,MAjCW,MAAM;AACjB,UAAIE,EAAY,QAAOV,EAAS,EAAE,MAAMQ,GAAW,UAAAJ,GAAU;AAE7D,MAAAF,EAAQ,CAACS,MAAa;AACpB,cAAMV,IAAOU,IAAW;AACxB,eAAAX,EAAS,EAAE,MAAAC,GAAM,UAAAG,EAAA,CAAU,GACpBH;AAAAA,MAAA,CACR;AAAA,IAAA;AAAA,IA2BD,MAxBW,MAAM;AACjB,UAAIQ,EAAa,QAAOT,EAAS,EAAE,MAAM,GAAG,UAAAI,GAAU;AAEtD,MAAAF,EAAQ,CAACS,MAAa;AACpB,cAAMV,IAAOU,IAAW;AACxB,eAAAX,EAAS,EAAE,MAAAC,GAAM,UAAAG,EAAA,CAAU,GACpBH;AAAAA,MAAA,CACR;AAAA,IAAA;AAAA,EAiBD;AAEJ;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOnce.mjs","sources":["../../../../src/hooks/useOnce/useOnce.ts"],"sourcesContent":["import type { EffectCallback } from 'react';\n\nimport { useEffect, useRef } from 'react';\n\n/**\n * @name useEffectOnce\n * @description - Hook that runs an effect only once. Please do not use it in production code!\n * @category Humor\n *\n * @warning - This hook will run effect only once even in strict mode. Please do not use it in production code!\n *\n * @param {EffectCallback} effect The effect to run\n *\n * @example\n * useOnce(() => console.log('effect once'));\n */\nexport function useOnce(effect: EffectCallback) {\n const cleanupRef = useRef<ReturnType<EffectCallback>>(undefined);\n const hasRunRef = useRef(false);\n const hasRenderedAfterRun = useRef(false);\n\n if (hasRunRef.current) {\n hasRenderedAfterRun.current = true;\n }\n\n useEffect(() => {\n if (hasRunRef.current) return;\n\n hasRunRef.current = true;\n cleanupRef.current = effect();\n\n return () => {\n if (!hasRenderedAfterRun.current) return;\n\n if (typeof cleanupRef.current === 'function') {\n cleanupRef.current();\n }\n };\n }, []);\n}\n"],"names":["useOnce","effect","cleanupRef","useRef","hasRunRef","hasRenderedAfterRun","useEffect"],"mappings":";
|
|
1
|
+
{"version":3,"file":"useOnce.mjs","sources":["../../../../src/hooks/useOnce/useOnce.ts"],"sourcesContent":["import type { EffectCallback } from 'react';\n\nimport { useEffect, useRef } from 'react';\n\n/**\n * @name useEffectOnce\n * @description - Hook that runs an effect only once. Please do not use it in production code!\n * @category Humor\n * @usage low\n *\n * @warning - This hook will run effect only once even in strict mode. Please do not use it in production code!\n *\n * @param {EffectCallback} effect The effect to run\n *\n * @example\n * useOnce(() => console.log('effect once'));\n */\nexport function useOnce(effect: EffectCallback) {\n const cleanupRef = useRef<ReturnType<EffectCallback>>(undefined);\n const hasRunRef = useRef(false);\n const hasRenderedAfterRun = useRef(false);\n\n if (hasRunRef.current) {\n hasRenderedAfterRun.current = true;\n }\n\n useEffect(() => {\n if (hasRunRef.current) return;\n\n hasRunRef.current = true;\n cleanupRef.current = effect();\n\n return () => {\n if (!hasRenderedAfterRun.current) return;\n\n if (typeof cleanupRef.current === 'function') {\n cleanupRef.current();\n }\n };\n }, []);\n}\n"],"names":["useOnce","effect","cleanupRef","useRef","hasRunRef","hasRenderedAfterRun","useEffect"],"mappings":";AAiBO,SAASA,EAAQC,GAAwB;AAC9C,QAAMC,IAAaC,EAAmC,MAAS,GACzDC,IAAYD,EAAO,EAAK,GACxBE,IAAsBF,EAAO,EAAK;AAExC,EAAIC,EAAU,YACZC,EAAoB,UAAU,KAGhCC,EAAU,MAAM;AACd,QAAI,CAAAF,EAAU;AAEd,aAAAA,EAAU,UAAU,IACpBF,EAAW,UAAUD,EAAA,GAEd,MAAM;AACX,QAAKI,EAAoB,WAErB,OAAOH,EAAW,WAAY,cAChCA,EAAW,QAAA;AAAA,MACb;AAAA,EACF,GACC,EAAE;AACP;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOnline.mjs","sources":["../../../../src/hooks/useOnline/useOnline.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\nconst getSnapshot = () => navigator.onLine;\nconst getServerSnapshot = () => false;\nconst subscribe = (callback: () => void) => {\n window.addEventListener('online', callback);\n window.addEventListener('offline', callback);\n return () => {\n window.removeEventListener('online', callback);\n window.removeEventListener('offline', callback);\n };\n};\n\n/**\n * @name useOnline\n * @description - Hook that manages if the user is online\n * @category Browser\n *\n * @browserapi navigator.onLine https://developer.mozilla.org/en-US/docs/Web/API/Navigator/onLine\n *\n * @returns {boolean} A boolean indicating if the user is online\n *\n * @example\n * const online = useOnline();\n */\nexport const useOnline = () => useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n"],"names":["getSnapshot","getServerSnapshot","subscribe","callback","useOnline","useSyncExternalStore"],"mappings":";AAEA,MAAMA,IAAc,MAAM,UAAU,QAC9BC,IAAoB,MAAM,IAC1BC,IAAY,CAACC,OACjB,OAAO,iBAAiB,UAAUA,CAAQ,GAC1C,OAAO,iBAAiB,WAAWA,CAAQ,GACpC,MAAM;AACX,SAAO,oBAAoB,UAAUA,CAAQ,GAC7C,OAAO,oBAAoB,WAAWA,CAAQ;AAAA,
|
|
1
|
+
{"version":3,"file":"useOnline.mjs","sources":["../../../../src/hooks/useOnline/useOnline.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\nconst getSnapshot = () => navigator.onLine;\nconst getServerSnapshot = () => false;\nconst subscribe = (callback: () => void) => {\n window.addEventListener('online', callback);\n window.addEventListener('offline', callback);\n return () => {\n window.removeEventListener('online', callback);\n window.removeEventListener('offline', callback);\n };\n};\n\n/**\n * @name useOnline\n * @description - Hook that manages if the user is online\n * @category Browser\n * @usage medium\n *\n * @browserapi navigator.onLine https://developer.mozilla.org/en-US/docs/Web/API/Navigator/onLine\n *\n * @returns {boolean} A boolean indicating if the user is online\n *\n * @example\n * const online = useOnline();\n */\nexport const useOnline = () => useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n"],"names":["getSnapshot","getServerSnapshot","subscribe","callback","useOnline","useSyncExternalStore"],"mappings":";AAEA,MAAMA,IAAc,MAAM,UAAU,QAC9BC,IAAoB,MAAM,IAC1BC,IAAY,CAACC,OACjB,OAAO,iBAAiB,UAAUA,CAAQ,GAC1C,OAAO,iBAAiB,WAAWA,CAAQ,GACpC,MAAM;AACX,SAAO,oBAAoB,UAAUA,CAAQ,GAC7C,OAAO,oBAAoB,WAAWA,CAAQ;AAAA,IAiBrCC,IAAY,MAAMC,EAAqBH,GAAWF,GAAaC,CAAiB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOperatingSystem.mjs","sources":["../../../../src/hooks/useOperatingSystem/useOperatingSystem.ts"],"sourcesContent":["import { useState } from 'react';\n\n/** The operating system type */\nexport type OperatingSystem = 'android' | 'ios' | 'linux' | 'macos' | 'undetermined' | 'windows';\n\nexport const getOperatingSystem = (): OperatingSystem => {\n if (typeof window === 'undefined') return 'undetermined';\n\n const { userAgent } = window.navigator;\n\n if (/Macintosh|MacIntel|MacPPC|Mac68K/i.test(userAgent)) return 'macos';\n if (/iPhone|iPad|iPod/i.test(userAgent)) return 'ios';\n if (/Win32|Win64|Windows|WinCE/i.test(userAgent)) return 'windows';\n if (/Android/i.test(userAgent)) return 'android';\n if (/Linux/i.test(userAgent)) return 'linux';\n\n return 'undetermined';\n};\n\n/**\n * @name useOperatingSystem\n * @description - Hook that returns the operating system of the current browser\n * @category User\n *\n * @returns {OperatingSystem} The operating system\n *\n * @example\n * const operatingSystem = useOperatingSystem();\n */\nexport const useOperatingSystem = () => {\n const [osOperatingSystem] = useState<OperatingSystem>(getOperatingSystem());\n return osOperatingSystem;\n};\n"],"names":["getOperatingSystem","userAgent","useOperatingSystem","osOperatingSystem","useState"],"mappings":";AAKO,MAAMA,IAAqB,MAAuB;AACvD,MAAI,OAAO,SAAW,IAAa,QAAO;AAE1C,QAAM,EAAE,WAAAC,MAAc,OAAO;AAE7B,SAAI,oCAAoC,KAAKA,CAAS,IAAU,UAC5D,oBAAoB,KAAKA,CAAS,IAAU,QAC5C,6BAA6B,KAAKA,CAAS,IAAU,YACrD,WAAW,KAAKA,CAAS,IAAU,YACnC,SAAS,KAAKA,CAAS,IAAU,UAE9B;AACT,
|
|
1
|
+
{"version":3,"file":"useOperatingSystem.mjs","sources":["../../../../src/hooks/useOperatingSystem/useOperatingSystem.ts"],"sourcesContent":["import { useState } from 'react';\n\n/** The operating system type */\nexport type OperatingSystem = 'android' | 'ios' | 'linux' | 'macos' | 'undetermined' | 'windows';\n\nexport const getOperatingSystem = (): OperatingSystem => {\n if (typeof window === 'undefined') return 'undetermined';\n\n const { userAgent } = window.navigator;\n\n if (/Macintosh|MacIntel|MacPPC|Mac68K/i.test(userAgent)) return 'macos';\n if (/iPhone|iPad|iPod/i.test(userAgent)) return 'ios';\n if (/Win32|Win64|Windows|WinCE/i.test(userAgent)) return 'windows';\n if (/Android/i.test(userAgent)) return 'android';\n if (/Linux/i.test(userAgent)) return 'linux';\n\n return 'undetermined';\n};\n\n/**\n * @name useOperatingSystem\n * @description - Hook that returns the operating system of the current browser\n * @category User\n * @usage low\n *\n * @returns {OperatingSystem} The operating system\n *\n * @example\n * const operatingSystem = useOperatingSystem();\n */\nexport const useOperatingSystem = () => {\n const [osOperatingSystem] = useState<OperatingSystem>(getOperatingSystem());\n return osOperatingSystem;\n};\n"],"names":["getOperatingSystem","userAgent","useOperatingSystem","osOperatingSystem","useState"],"mappings":";AAKO,MAAMA,IAAqB,MAAuB;AACvD,MAAI,OAAO,SAAW,IAAa,QAAO;AAE1C,QAAM,EAAE,WAAAC,MAAc,OAAO;AAE7B,SAAI,oCAAoC,KAAKA,CAAS,IAAU,UAC5D,oBAAoB,KAAKA,CAAS,IAAU,QAC5C,6BAA6B,KAAKA,CAAS,IAAU,YACrD,WAAW,KAAKA,CAAS,IAAU,YACnC,SAAS,KAAKA,CAAS,IAAU,UAE9B;AACT,GAaaC,IAAqB,MAAM;AACtC,QAAM,CAACC,CAAiB,IAAIC,EAA0BJ,GAAoB;AAC1E,SAAOG;AACT;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOptimistic.mjs","sources":["../../../../src/hooks/useOptimistic/useOptimistic.ts"],"sourcesContent":["import { useRef, useState } from 'react';\n\nimport { useDidUpdate } from '../useDidUpdate/useDidUpdate';\n\nexport type UseOptimisticReturn<State> = [\n State,\n (optimisticValue: State, promise: Promise<any>) => void\n];\n\n/**\n * @name useOptimistic\n * @description - Hook that allows get optimistic value before its update\n * @category Async\n *\n * @template State The type of the state\n * @param {State} state The value to be returned initially and whenever no action is pending\n * @param {(currentState: State, optimisticValue: State) => State} update A pure function that takes the current state and the optimistic value passed to updateOptimistic and returns the resulting optimistic state\n * @returns {UseOptimisticReturn<State>} The resulting optimistic state, and the function to update it\n *\n * @example\n * const [optimisticValue, updateOptimistic] = useOptimistic<number>(count, (currentState, optimisticValue) => currentState + optimisticValue);\n */\nexport const useOptimistic = <State, OptimisticState = State>(\n externalState: State,\n update: (currentState: State, optimisticState: OptimisticState) => State\n) => {\n const [state, setState] = useState<State>(externalState);\n const internalUpdateRef = useRef(update);\n internalUpdateRef.current = update;\n\n const [promised, setPromised] = useState(false);\n\n useDidUpdate(() => {\n if (!promised) return;\n setState(externalState);\n setPromised(false);\n }, [promised]);\n\n const updateState = (optimisticValue: OptimisticState, promise: Promise<any>) => {\n setState((currentState) => internalUpdateRef.current(currentState, optimisticValue));\n return promise.finally(() => setPromised(true));\n };\n\n return [state, updateState] as const;\n};\n"],"names":["useOptimistic","externalState","update","state","setState","useState","internalUpdateRef","useRef","promised","setPromised","useDidUpdate","optimisticValue","promise","currentState"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"useOptimistic.mjs","sources":["../../../../src/hooks/useOptimistic/useOptimistic.ts"],"sourcesContent":["import { useRef, useState } from 'react';\n\nimport { useDidUpdate } from '../useDidUpdate/useDidUpdate';\n\nexport type UseOptimisticReturn<State> = [\n State,\n (optimisticValue: State, promise: Promise<any>) => void\n];\n\n/**\n * @name useOptimistic\n * @description - Hook that allows get optimistic value before its update\n * @category Async\n * @usage medium\n *\n * @template State The type of the state\n * @param {State} state The value to be returned initially and whenever no action is pending\n * @param {(currentState: State, optimisticValue: State) => State} update A pure function that takes the current state and the optimistic value passed to updateOptimistic and returns the resulting optimistic state\n * @returns {UseOptimisticReturn<State>} The resulting optimistic state, and the function to update it\n *\n * @example\n * const [optimisticValue, updateOptimistic] = useOptimistic<number>(count, (currentState, optimisticValue) => currentState + optimisticValue);\n */\nexport const useOptimistic = <State, OptimisticState = State>(\n externalState: State,\n update: (currentState: State, optimisticState: OptimisticState) => State\n) => {\n const [state, setState] = useState<State>(externalState);\n const internalUpdateRef = useRef(update);\n internalUpdateRef.current = update;\n\n const [promised, setPromised] = useState(false);\n\n useDidUpdate(() => {\n if (!promised) return;\n setState(externalState);\n setPromised(false);\n }, [promised]);\n\n const updateState = (optimisticValue: OptimisticState, promise: Promise<any>) => {\n setState((currentState) => internalUpdateRef.current(currentState, optimisticValue));\n return promise.finally(() => setPromised(true));\n };\n\n return [state, updateState] as const;\n};\n"],"names":["useOptimistic","externalState","update","state","setState","useState","internalUpdateRef","useRef","promised","setPromised","useDidUpdate","optimisticValue","promise","currentState"],"mappings":";;AAuBO,MAAMA,IAAgB,CAC3BC,GACAC,MACG;AACH,QAAM,CAACC,GAAOC,CAAQ,IAAIC,EAAgBJ,CAAa,GACjDK,IAAoBC,EAAOL,CAAM;AACvC,EAAAI,EAAkB,UAAUJ;AAE5B,QAAM,CAACM,GAAUC,CAAW,IAAIJ,EAAS,EAAK;AAE9C,SAAAK,EAAa,MAAM;AACjB,IAAKF,MACLJ,EAASH,CAAa,GACtBQ,EAAY,EAAK;AAAA,EAAA,GAChB,CAACD,CAAQ,CAAC,GAON,CAACL,GALY,CAACQ,GAAkCC,OACrDR,EAAS,CAACS,MAAiBP,EAAkB,QAAQO,GAAcF,CAAe,CAAC,GAC5EC,EAAQ,QAAQ,MAAMH,EAAY,EAAI,CAAC,EAGtB;AAC5B;"}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { useState as r, useEffect as c } from "react";
|
|
2
|
-
const
|
|
3
|
-
const e = typeof window < "u" && "screen" in window && "orientation" in window.screen, n = e ? window.screen.orientation : {}, [t, i] = r(
|
|
4
|
-
angle: n
|
|
5
|
-
orientationType: n
|
|
6
|
-
})
|
|
2
|
+
const w = () => {
|
|
3
|
+
const e = typeof window < "u" && "screen" in window && "orientation" in window.screen, n = e ? window.screen.orientation : {}, [t, i] = r({
|
|
4
|
+
angle: n.angle ?? 0,
|
|
5
|
+
orientationType: n.type
|
|
6
|
+
});
|
|
7
7
|
return c(() => {
|
|
8
8
|
if (!e) return;
|
|
9
9
|
const o = () => i({
|
|
10
|
-
angle:
|
|
11
|
-
orientationType:
|
|
10
|
+
angle: window.screen.orientation.angle,
|
|
11
|
+
orientationType: window.screen.orientation.type
|
|
12
12
|
});
|
|
13
13
|
return window.addEventListener("orientationchange", o), () => {
|
|
14
14
|
window.removeEventListener("orientationchange", o);
|
|
15
15
|
};
|
|
16
|
-
}), {
|
|
16
|
+
}, []), {
|
|
17
17
|
supported: e,
|
|
18
18
|
value: t,
|
|
19
19
|
lock: (o) => {
|
|
@@ -25,6 +25,6 @@ const l = () => {
|
|
|
25
25
|
};
|
|
26
26
|
};
|
|
27
27
|
export {
|
|
28
|
-
|
|
28
|
+
w as useOrientation
|
|
29
29
|
};
|
|
30
30
|
//# sourceMappingURL=useOrientation.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOrientation.mjs","sources":["../../../../src/hooks/useOrientation/useOrientation.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\ndeclare global {\n interface ScreenOrientation {\n lock: (orientation: OrientationLockType) => Promise<void>;\n }\n}\n\n/* The use device orientation value type */\nexport interface UseOrientationValue {\n /** The current angle */\n angle: number;\n /** The current orientation type */\n orientationType
|
|
1
|
+
{"version":3,"file":"useOrientation.mjs","sources":["../../../../src/hooks/useOrientation/useOrientation.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\ndeclare global {\n interface ScreenOrientation {\n lock: (orientation: OrientationLockType) => Promise<void>;\n }\n}\n\n/* The use device orientation value type */\nexport interface UseOrientationValue {\n /** The current angle */\n angle: number;\n /** The current orientation type */\n orientationType?: OrientationType;\n}\n\n/* The screen lock orientation type */\nexport type OrientationLockType =\n | 'any'\n | 'landscape-primary'\n | 'landscape-secondary'\n | 'landscape'\n | 'natural'\n | 'portrait-primary'\n | 'portrait-secondary'\n | 'portrait';\n\n/* The use device orientation return type */\nexport interface useOrientationReturn {\n /** Whether the screen orientation is supported */\n supported: boolean;\n /** The current screen orientation value */\n value: UseOrientationValue;\n /** Lock the screen orientation */\n lock: (orientation: OrientationLockType) => void;\n /** Unlock the screen orientation */\n unlock: () => void;\n}\n\n/**\n * @name useOrientation\n * @description - Hook that provides the current screen orientation\n * @category Sensors\n * @usage low\n *\n * @browserapi screen.orientation https://developer.mozilla.org/en-US/docs/Web/API/Screen/orientation\n *\n * @returns {useOrientationReturn} The current screen orientation\n *\n * @example\n * const { supported, value, lock, unlock } = useOrientation();\n */\nexport const useOrientation = (): useOrientationReturn => {\n const supported =\n typeof window !== 'undefined' && 'screen' in window && 'orientation' in window.screen;\n const orientation = (supported ? window.screen.orientation : {}) as ScreenOrientation;\n\n const [value, setValue] = useState<UseOrientationValue>({\n angle: orientation.angle ?? 0,\n orientationType: orientation.type\n });\n\n useEffect(() => {\n if (!supported) return;\n\n const onOrientationChange = () =>\n setValue({\n angle: window.screen.orientation.angle,\n orientationType: window.screen.orientation.type\n });\n\n window.addEventListener('orientationchange', onOrientationChange);\n return () => {\n window.removeEventListener('orientationchange', onOrientationChange);\n };\n }, []);\n\n const lock = (type: OrientationLockType) => {\n if (supported && typeof orientation.lock === 'function') return orientation.lock(type);\n };\n\n const unlock = () => {\n if (supported && typeof orientation.unlock === 'function') orientation.unlock();\n };\n\n return {\n supported,\n value,\n lock,\n unlock\n };\n};\n"],"names":["useOrientation","supported","orientation","value","setValue","useState","useEffect","onOrientationChange","type"],"mappings":";AAoDO,MAAMA,IAAiB,MAA4B;AACxD,QAAMC,IACJ,OAAO,SAAW,OAAe,YAAY,UAAU,iBAAiB,OAAO,QAC3EC,IAAeD,IAAY,OAAO,OAAO,cAAc,CAAA,GAEvD,CAACE,GAAOC,CAAQ,IAAIC,EAA8B;AAAA,IACtD,OAAOH,EAAY,SAAS;AAAA,IAC5B,iBAAiBA,EAAY;AAAA,EAAA,CAC9B;AAED,SAAAI,EAAU,MAAM;AACd,QAAI,CAACL,EAAW;AAEhB,UAAMM,IAAsB,MAC1BH,EAAS;AAAA,MACP,OAAO,OAAO,OAAO,YAAY;AAAA,MACjC,iBAAiB,OAAO,OAAO,YAAY;AAAA,IAAA,CAC5C;AAEH,kBAAO,iBAAiB,qBAAqBG,CAAmB,GACzD,MAAM;AACX,aAAO,oBAAoB,qBAAqBA,CAAmB;AAAA,IAAA;AAAA,EACrE,GACC,EAAE,GAUE;AAAA,IACL,WAAAN;AAAA,IACA,OAAAE;AAAA,IACA,MAXW,CAACK,MAA8B;AAC1C,UAAIP,KAAa,OAAOC,EAAY,QAAS,WAAY,QAAOA,EAAY,KAAKM,CAAI;AAAA,IAAA;AAAA,IAWrF,QARa,MAAM;AACnB,MAAIP,KAAa,OAAOC,EAAY,UAAW,gBAAwB,OAAA;AAAA,IAAO;AAAA,EAO9E;AAEJ;"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { useState as
|
|
1
|
+
import { useState as i, useRef as l } from "react";
|
|
2
2
|
const b = (...t) => {
|
|
3
|
-
const c = typeof t[0] == "function" ? t[0] : t[0]?.onSuccess, s = typeof t[0] == "function" ? t[0]?.onError : void 0,
|
|
3
|
+
const e = typeof navigator < "u" && "OTPCredential" in navigator && !!navigator.OTPCredential, c = typeof t[0] == "function" ? t[0] : t[0]?.onSuccess, s = typeof t[0] == "function" ? t[0]?.onError : void 0, [a, n] = i(!1), r = l(new AbortController());
|
|
4
4
|
return { supported: e, abort: () => {
|
|
5
5
|
r.current.abort(), r.current = new AbortController(), r.current.signal.onabort = () => n(!0);
|
|
6
|
-
}, aborted:
|
|
6
|
+
}, aborted: a, get: async () => {
|
|
7
7
|
if (e) {
|
|
8
8
|
r.current = new AbortController();
|
|
9
9
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOtpCredential.mjs","sources":["../../../../src/hooks/useOtpCredential/useOtpCredential.ts"],"sourcesContent":["import { useRef, useState } from 'react';\n\ndeclare global {\n interface OTPOptions {\n readonly transport: string[];\n }\n\n interface CredentialRequestOptions {\n readonly otp: OTPOptions;\n }\n\n interface Credential {\n readonly code: string;\n }\n}\n\n/* The use otp credential callback type */\nexport type UseOtpCredentialCallback = (otp: Credential | null) => void;\n\n/* The use otp credential options type */\nexport interface UseOtpCredentialParams {\n /* The callback function to be invoked on error */\n onError: (error: any) => void;\n /* The callback function to be invoked on success */\n onSuccess: (credential: Credential | null) => void;\n}\n\n/* The use otp credential return type */\nexport interface UseOtpCredentialReturn {\n /* The abort function */\n abort: AbortController['abort'];\n /* The aborted state of the query */\n aborted: boolean;\n /* The supported state of the otp credential */\n supported: boolean;\n /* The get otp credential function */\n get: () => Promise<Credential | null>;\n}\n\nexport interface UseOtpCredential {\n (callback?: UseOtpCredentialCallback): UseOtpCredentialReturn;\n\n (params?: UseOtpCredentialParams): UseOtpCredentialReturn;\n}\n\n/**\n * @name useOtpCredential\n * @description - Hook that creates an otp credential\n * @category Browser\n *\n * @browserapi navigator.credentials https://developer.mozilla.org/en-US/docs/Web/API/Navigator/credentials\n *\n * @overload\n * @param {UseOtpCredentialCallback} callback The callback function to be invoked\n * @returns {UseOtpCredentialReturn}\n *\n * @example\n * useOtpCredential((credential) => console.log(credential));\n *\n * @overload\n * @param {UseOtpCredentialCallback} params.onSuccess The callback function to be invoked on success\n * @param {UseOtpCredentialCallback} params.onError The callback function to be invoked on error\n * @returns {UseOtpCredentialReturn}\n *\n * @example\n * useOtpCredential({ onSuccess: (credential) => console.log(credential), onError: (error) => console.log(error) });\n */\nexport const useOtpCredential = ((...params: any[]) => {\n const onSuccess =\n typeof params[0] === 'function'\n ? (params[0] as UseOtpCredentialCallback | undefined)\n : (params[0] as UseOtpCredentialParams | undefined)?.onSuccess;\n\n const onError =\n typeof params[0] === 'function'\n ? (params[0] as UseOtpCredentialParams | undefined)?.onError\n : undefined;\n\n const
|
|
1
|
+
{"version":3,"file":"useOtpCredential.mjs","sources":["../../../../src/hooks/useOtpCredential/useOtpCredential.ts"],"sourcesContent":["import { useRef, useState } from 'react';\n\ndeclare global {\n interface OTPOptions {\n readonly transport: string[];\n }\n\n interface CredentialRequestOptions {\n readonly otp: OTPOptions;\n }\n\n interface Credential {\n readonly code: string;\n }\n}\n\n/* The use otp credential callback type */\nexport type UseOtpCredentialCallback = (otp: Credential | null) => void;\n\n/* The use otp credential options type */\nexport interface UseOtpCredentialParams {\n /* The callback function to be invoked on error */\n onError: (error: any) => void;\n /* The callback function to be invoked on success */\n onSuccess: (credential: Credential | null) => void;\n}\n\n/* The use otp credential return type */\nexport interface UseOtpCredentialReturn {\n /* The abort function */\n abort: AbortController['abort'];\n /* The aborted state of the query */\n aborted: boolean;\n /* The supported state of the otp credential */\n supported: boolean;\n /* The get otp credential function */\n get: () => Promise<Credential | null>;\n}\n\nexport interface UseOtpCredential {\n (callback?: UseOtpCredentialCallback): UseOtpCredentialReturn;\n\n (params?: UseOtpCredentialParams): UseOtpCredentialReturn;\n}\n\n/**\n * @name useOtpCredential\n * @description - Hook that creates an otp credential\n * @category Browser\n * @usage low\n *\n * @browserapi navigator.credentials https://developer.mozilla.org/en-US/docs/Web/API/Navigator/credentials\n *\n * @overload\n * @param {UseOtpCredentialCallback} callback The callback function to be invoked\n * @returns {UseOtpCredentialReturn}\n *\n * @example\n * useOtpCredential((credential) => console.log(credential));\n *\n * @overload\n * @param {UseOtpCredentialCallback} params.onSuccess The callback function to be invoked on success\n * @param {UseOtpCredentialCallback} params.onError The callback function to be invoked on error\n * @returns {UseOtpCredentialReturn}\n *\n * @example\n * useOtpCredential({ onSuccess: (credential) => console.log(credential), onError: (error) => console.log(error) });\n */\nexport const useOtpCredential = ((...params: any[]) => {\n const supported =\n typeof navigator !== 'undefined' && 'OTPCredential' in navigator && !!navigator.OTPCredential;\n\n const onSuccess =\n typeof params[0] === 'function'\n ? (params[0] as UseOtpCredentialCallback | undefined)\n : (params[0] as UseOtpCredentialParams | undefined)?.onSuccess;\n\n const onError =\n typeof params[0] === 'function'\n ? (params[0] as UseOtpCredentialParams | undefined)?.onError\n : undefined;\n\n const [aborted, setAborted] = useState(false);\n\n const abortControllerRef = useRef<AbortController>(new AbortController());\n\n const get = async () => {\n if (!supported) return;\n\n abortControllerRef.current = new AbortController();\n try {\n const credential = await navigator.credentials.get({\n otp: { transport: ['sms'] },\n signal: abortControllerRef.current.signal\n });\n onSuccess?.(credential);\n setAborted(false);\n return credential;\n } catch (error) {\n onError?.(error);\n }\n };\n\n const abort = () => {\n abortControllerRef.current.abort();\n abortControllerRef.current = new AbortController();\n abortControllerRef.current.signal.onabort = () => setAborted(true);\n };\n\n return { supported, abort, aborted, get };\n}) as UseOtpCredential;\n"],"names":["useOtpCredential","params","supported","onSuccess","onError","aborted","setAborted","useState","abortControllerRef","useRef","credential","error"],"mappings":";AAoEO,MAAMA,IAAoB,IAAIC,MAAkB;AACrD,QAAMC,IACJ,OAAO,YAAc,OAAe,mBAAmB,aAAa,CAAC,CAAC,UAAU,eAE5EC,IACJ,OAAOF,EAAO,CAAC,KAAM,aAChBA,EAAO,CAAC,IACRA,EAAO,CAAC,GAA0C,WAEnDG,IACJ,OAAOH,EAAO,CAAC,KAAM,aAChBA,EAAO,CAAC,GAA0C,UACnD,QAEA,CAACI,GAASC,CAAU,IAAIC,EAAS,EAAK,GAEtCC,IAAqBC,EAAwB,IAAI,iBAAiB;AAyBxE,SAAO,EAAE,WAAAP,GAAW,OANN,MAAM;AAClB,IAAAM,EAAmB,QAAQ,MAAA,GAC3BA,EAAmB,UAAU,IAAI,gBAAA,GACjCA,EAAmB,QAAQ,OAAO,UAAU,MAAMF,EAAW,EAAI;AAAA,EAAA,GAGxC,SAAAD,GAAS,KAvBxB,YAAY;AACtB,QAAKH,GAEL;AAAA,MAAAM,EAAmB,UAAU,IAAI,gBAAA;AACjC,UAAI;AACF,cAAME,IAAa,MAAM,UAAU,YAAY,IAAI;AAAA,UACjD,KAAK,EAAE,WAAW,CAAC,KAAK,EAAA;AAAA,UACxB,QAAQF,EAAmB,QAAQ;AAAA,QAAA,CACpC;AACD,eAAAL,IAAYO,CAAU,GACtBJ,EAAW,EAAK,GACTI;AAAA,MAAA,SACAC,GAAO;AACd,QAAAP,IAAUO,CAAK;AAAA,MAAA;AAAA;AAAA,EACjB,EASkC;AACtC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePageLeave.mjs","sources":["../../../../src/hooks/usePageLeave/usePageLeave.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { useEvent } from '../useEvent/useEvent';\n\n/**\n * @name usePageLeave\n * @description - Hook what calls given function when mouse leaves the page\n * @category Sensors\n *\n * @param {() => void} [callback] The callback function what calls then mouse leaves the page\n * @returns {boolean} A boolean which determines if the mouse left the page\n *\n * @example\n * const isLeft = usePageLeave(() => console.log('on leave'))\n */\nexport const usePageLeave = (callback?: () => void) => {\n const [isLeft, setIsLeft] = useState(false);\n\n const onMouse = useEvent(() => {\n if (isLeft) return setIsLeft(false);\n callback?.();\n setIsLeft(true);\n });\n\n useEffect(() => {\n document.addEventListener('mouseleave', onMouse, { passive: true });\n document.addEventListener('mouseenter', onMouse, { passive: true });\n\n return () => {\n document.removeEventListener('mouseenter', onMouse);\n document.removeEventListener('mouseleave', onMouse);\n };\n }, []);\n\n return isLeft;\n};\n"],"names":["usePageLeave","callback","isLeft","setIsLeft","useState","onMouse","useEvent","useEffect"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"usePageLeave.mjs","sources":["../../../../src/hooks/usePageLeave/usePageLeave.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { useEvent } from '../useEvent/useEvent';\n\n/**\n * @name usePageLeave\n * @description - Hook what calls given function when mouse leaves the page\n * @category Sensors\n * @usage low\n *\n * @param {() => void} [callback] The callback function what calls then mouse leaves the page\n * @returns {boolean} A boolean which determines if the mouse left the page\n *\n * @example\n * const isLeft = usePageLeave(() => console.log('on leave'))\n */\nexport const usePageLeave = (callback?: () => void) => {\n const [isLeft, setIsLeft] = useState(false);\n\n const onMouse = useEvent(() => {\n if (isLeft) return setIsLeft(false);\n callback?.();\n setIsLeft(true);\n });\n\n useEffect(() => {\n document.addEventListener('mouseleave', onMouse, { passive: true });\n document.addEventListener('mouseenter', onMouse, { passive: true });\n\n return () => {\n document.removeEventListener('mouseenter', onMouse);\n document.removeEventListener('mouseleave', onMouse);\n };\n }, []);\n\n return isLeft;\n};\n"],"names":["usePageLeave","callback","isLeft","setIsLeft","useState","onMouse","useEvent","useEffect"],"mappings":";;AAgBO,MAAMA,IAAe,CAACC,MAA0B;AACrD,QAAM,CAACC,GAAQC,CAAS,IAAIC,EAAS,EAAK,GAEpCC,IAAUC,EAAS,MAAM;AAC7B,QAAIJ,EAAQ,QAAOC,EAAU,EAAK;AAClC,IAAAF,IAAA,GACAE,EAAU,EAAI;AAAA,EAAA,CACf;AAED,SAAAI,EAAU,OACR,SAAS,iBAAiB,cAAcF,GAAS,EAAE,SAAS,IAAM,GAClE,SAAS,iBAAiB,cAAcA,GAAS,EAAE,SAAS,IAAM,GAE3D,MAAM;AACX,aAAS,oBAAoB,cAAcA,CAAO,GAClD,SAAS,oBAAoB,cAAcA,CAAO;AAAA,EAAA,IAEnD,EAAE,GAEEH;AACT;"}
|