@siberiacancode/reactuse 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/hooks/useActiveElement/useActiveElement.cjs +1 -1
- package/dist/cjs/hooks/useActiveElement/useActiveElement.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/useBreakpoints/useBreakpoints.cjs +1 -1
- package/dist/cjs/hooks/useBreakpoints/useBreakpoints.cjs.map +1 -1
- package/dist/cjs/hooks/useClickOutside/useClickOutside.cjs +1 -1
- package/dist/cjs/hooks/useClickOutside/useClickOutside.cjs.map +1 -1
- package/dist/cjs/hooks/useCookie/useCookie.cjs +1 -1
- package/dist/cjs/hooks/useCookie/useCookie.cjs.map +1 -1
- package/dist/cjs/hooks/useCounter/useCounter.cjs +1 -1
- package/dist/cjs/hooks/useCounter/useCounter.cjs.map +1 -1
- package/dist/cjs/hooks/useCssVar/useCssVar.cjs +1 -1
- package/dist/cjs/hooks/useCssVar/useCssVar.cjs.map +1 -1
- package/dist/cjs/hooks/useDeviceMotion/useDeviceMotion.cjs +1 -1
- package/dist/cjs/hooks/useDeviceMotion/useDeviceMotion.cjs.map +1 -1
- package/dist/cjs/hooks/useDisplayMedia/useDisplayMedia.cjs +1 -1
- package/dist/cjs/hooks/useDisplayMedia/useDisplayMedia.cjs.map +1 -1
- package/dist/cjs/hooks/useDoubleClick/useDoubleClick.cjs +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 +1 -1
- package/dist/cjs/hooks/useElementSize/useElementSize.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/useFileDialog/useFileDialog.cjs +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/useFocusTrap/useFocusTrap.cjs +1 -1
- package/dist/cjs/hooks/useFocusTrap/useFocusTrap.cjs.map +1 -1
- package/dist/cjs/hooks/useFullscreen/useFullscreen.cjs +1 -1
- package/dist/cjs/hooks/useFullscreen/useFullscreen.cjs.map +1 -1
- package/dist/cjs/hooks/useHash/useHash.cjs +1 -1
- package/dist/cjs/hooks/useHash/useHash.cjs.map +1 -1
- package/dist/cjs/hooks/useHotkeys/useHotkeys.cjs +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/useInfiniteScroll/useInfiniteScroll.cjs +1 -1
- package/dist/cjs/hooks/useInfiniteScroll/useInfiniteScroll.cjs.map +1 -1
- package/dist/cjs/hooks/useIntersectionObserver/useIntersectionObserver.cjs +1 -1
- package/dist/cjs/hooks/useIntersectionObserver/useIntersectionObserver.cjs.map +1 -1
- package/dist/cjs/hooks/useInterval/useInterval.cjs +1 -1
- package/dist/cjs/hooks/useInterval/useInterval.cjs.map +1 -1
- package/dist/cjs/hooks/useKeyPress/useKeyPress.cjs +1 -1
- package/dist/cjs/hooks/useKeyPress/useKeyPress.cjs.map +1 -1
- package/dist/cjs/hooks/useKeyPressEvent/useKeyPressEvent.cjs +1 -1
- package/dist/cjs/hooks/useKeyPressEvent/useKeyPressEvent.cjs.map +1 -1
- package/dist/cjs/hooks/useKeyboard/useKeyboard.cjs +1 -1
- package/dist/cjs/hooks/useKeyboard/useKeyboard.cjs.map +1 -1
- package/dist/cjs/hooks/useKeysPressed/useKeysPressed.cjs +1 -1
- package/dist/cjs/hooks/useKeysPressed/useKeysPressed.cjs.map +1 -1
- package/dist/cjs/hooks/useLockScroll/useLockScroll.cjs +1 -1
- package/dist/cjs/hooks/useLockScroll/useLockScroll.cjs.map +1 -1
- package/dist/cjs/hooks/useLongPress/useLongPress.cjs +1 -1
- package/dist/cjs/hooks/useLongPress/useLongPress.cjs.map +1 -1
- package/dist/cjs/hooks/useMeasure/useMeasure.cjs +1 -1
- package/dist/cjs/hooks/useMeasure/useMeasure.cjs.map +1 -1
- package/dist/cjs/hooks/useMediaControls/useMediaControls.cjs +1 -1
- package/dist/cjs/hooks/useMediaControls/useMediaControls.cjs.map +1 -1
- package/dist/cjs/hooks/useMouse/useMouse.cjs +1 -1
- package/dist/cjs/hooks/useMouse/useMouse.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/useOtpCredential/useOtpCredential.cjs +1 -1
- package/dist/cjs/hooks/useOtpCredential/useOtpCredential.cjs.map +1 -1
- package/dist/cjs/hooks/usePaint/usePaint.cjs +1 -1
- package/dist/cjs/hooks/usePaint/usePaint.cjs.map +1 -1
- package/dist/cjs/hooks/useParallax/useParallax.cjs +1 -1
- package/dist/cjs/hooks/useParallax/useParallax.cjs.map +1 -1
- package/dist/cjs/hooks/usePictureInPicture/usePictureInPicture.cjs +1 -1
- package/dist/cjs/hooks/usePictureInPicture/usePictureInPicture.cjs.map +1 -1
- package/dist/cjs/hooks/useRefState/useRefState.cjs +1 -1
- package/dist/cjs/hooks/useRefState/useRefState.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 +1 -1
- package/dist/cjs/hooks/useRightClick/useRightClick.cjs.map +1 -1
- package/dist/cjs/hooks/useScroll/useScroll.cjs +1 -1
- package/dist/cjs/hooks/useScroll/useScroll.cjs.map +1 -1
- package/dist/cjs/hooks/useScrollIntoView/useScrollIntoView.cjs +1 -1
- package/dist/cjs/hooks/useScrollIntoView/useScrollIntoView.cjs.map +1 -1
- package/dist/cjs/hooks/useScrollTo/useScrollTo.cjs +1 -1
- package/dist/cjs/hooks/useScrollTo/useScrollTo.cjs.map +1 -1
- package/dist/cjs/hooks/useSticky/useSticky.cjs +1 -1
- package/dist/cjs/hooks/useSticky/useSticky.cjs.map +1 -1
- package/dist/cjs/hooks/useStopwatch/useStopwatch.cjs +1 -1
- package/dist/cjs/hooks/useStopwatch/useStopwatch.cjs.map +1 -1
- package/dist/cjs/hooks/useStorage/useStorage.cjs +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/useTextareaAutosize/useTextareaAutosize.cjs +1 -1
- package/dist/cjs/hooks/useTextareaAutosize/useTextareaAutosize.cjs.map +1 -1
- package/dist/cjs/hooks/useTimer/useTimer.cjs +1 -1
- package/dist/cjs/hooks/useTimer/useTimer.cjs.map +1 -1
- package/dist/cjs/hooks/useUrlSearchParam/useUrlSearchParam.cjs +1 -1
- package/dist/cjs/hooks/useUrlSearchParam/useUrlSearchParam.cjs.map +1 -1
- package/dist/cjs/hooks/useUrlSearchParams/useUrlSearchParams.cjs +1 -1
- package/dist/cjs/hooks/useUrlSearchParams/useUrlSearchParams.cjs.map +1 -1
- package/dist/cjs/hooks/useVisibility/useVisibility.cjs +1 -1
- package/dist/cjs/hooks/useVisibility/useVisibility.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/utils/helpers/isTarget.cjs +1 -1
- package/dist/cjs/utils/helpers/isTarget.cjs.map +1 -1
- package/dist/esm/hooks/useActiveElement/useActiveElement.mjs +13 -13
- package/dist/esm/hooks/useActiveElement/useActiveElement.mjs.map +1 -1
- package/dist/esm/hooks/useAutoScroll/useAutoScroll.mjs +24 -24
- package/dist/esm/hooks/useAutoScroll/useAutoScroll.mjs.map +1 -1
- package/dist/esm/hooks/useBreakpoints/useBreakpoints.mjs +30 -35
- package/dist/esm/hooks/useBreakpoints/useBreakpoints.mjs.map +1 -1
- package/dist/esm/hooks/useClickOutside/useClickOutside.mjs +15 -14
- package/dist/esm/hooks/useClickOutside/useClickOutside.mjs.map +1 -1
- package/dist/esm/hooks/useCookie/useCookie.mjs +2 -2
- package/dist/esm/hooks/useCookie/useCookie.mjs.map +1 -1
- package/dist/esm/hooks/useCounter/useCounter.mjs +2 -2
- package/dist/esm/hooks/useCounter/useCounter.mjs.map +1 -1
- package/dist/esm/hooks/useCssVar/useCssVar.mjs +8 -8
- package/dist/esm/hooks/useCssVar/useCssVar.mjs.map +1 -1
- package/dist/esm/hooks/useDeviceMotion/useDeviceMotion.mjs +2 -2
- package/dist/esm/hooks/useDeviceMotion/useDeviceMotion.mjs.map +1 -1
- package/dist/esm/hooks/useDisplayMedia/useDisplayMedia.mjs +17 -17
- package/dist/esm/hooks/useDisplayMedia/useDisplayMedia.mjs.map +1 -1
- package/dist/esm/hooks/useDoubleClick/useDoubleClick.mjs +14 -14
- package/dist/esm/hooks/useDoubleClick/useDoubleClick.mjs.map +1 -1
- package/dist/esm/hooks/useDropZone/useDropZone.mjs +23 -23
- package/dist/esm/hooks/useDropZone/useDropZone.mjs.map +1 -1
- package/dist/esm/hooks/useElementSize/useElementSize.mjs +14 -14
- package/dist/esm/hooks/useElementSize/useElementSize.mjs.map +1 -1
- package/dist/esm/hooks/useEventListener/useEventListener.mjs +14 -14
- package/dist/esm/hooks/useEventListener/useEventListener.mjs.map +1 -1
- package/dist/esm/hooks/useFileDialog/useFileDialog.mjs +2 -2
- package/dist/esm/hooks/useFileDialog/useFileDialog.mjs.map +1 -1
- package/dist/esm/hooks/useFocus/useFocus.mjs +20 -20
- package/dist/esm/hooks/useFocus/useFocus.mjs.map +1 -1
- package/dist/esm/hooks/useFocusTrap/useFocusTrap.mjs +21 -21
- package/dist/esm/hooks/useFocusTrap/useFocusTrap.mjs.map +1 -1
- package/dist/esm/hooks/useFullscreen/useFullscreen.mjs +2 -2
- package/dist/esm/hooks/useFullscreen/useFullscreen.mjs.map +1 -1
- package/dist/esm/hooks/useHash/useHash.mjs +2 -2
- package/dist/esm/hooks/useHash/useHash.mjs.map +1 -1
- package/dist/esm/hooks/useHotkeys/useHotkeys.mjs +24 -16
- package/dist/esm/hooks/useHotkeys/useHotkeys.mjs.map +1 -1
- package/dist/esm/hooks/useHover/useHover.mjs +16 -16
- package/dist/esm/hooks/useHover/useHover.mjs.map +1 -1
- package/dist/esm/hooks/useInfiniteScroll/useInfiniteScroll.mjs +16 -16
- package/dist/esm/hooks/useInfiniteScroll/useInfiniteScroll.mjs.map +1 -1
- package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs +26 -18
- package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs.map +1 -1
- package/dist/esm/hooks/useInterval/useInterval.mjs +2 -2
- package/dist/esm/hooks/useInterval/useInterval.mjs.map +1 -1
- package/dist/esm/hooks/useKeyPress/useKeyPress.mjs +15 -15
- package/dist/esm/hooks/useKeyPress/useKeyPress.mjs.map +1 -1
- package/dist/esm/hooks/useKeyPressEvent/useKeyPressEvent.mjs +22 -15
- package/dist/esm/hooks/useKeyPressEvent/useKeyPressEvent.mjs.map +1 -1
- package/dist/esm/hooks/useKeyboard/useKeyboard.mjs +10 -10
- package/dist/esm/hooks/useKeyboard/useKeyboard.mjs.map +1 -1
- package/dist/esm/hooks/useKeysPressed/useKeysPressed.mjs +12 -12
- package/dist/esm/hooks/useKeysPressed/useKeysPressed.mjs.map +1 -1
- package/dist/esm/hooks/useLockScroll/useLockScroll.mjs +23 -23
- package/dist/esm/hooks/useLockScroll/useLockScroll.mjs.map +1 -1
- package/dist/esm/hooks/useLongPress/useLongPress.mjs +16 -16
- package/dist/esm/hooks/useLongPress/useLongPress.mjs.map +1 -1
- package/dist/esm/hooks/useMeasure/useMeasure.mjs +15 -15
- package/dist/esm/hooks/useMeasure/useMeasure.mjs.map +1 -1
- package/dist/esm/hooks/useMediaControls/useMediaControls.mjs +28 -28
- package/dist/esm/hooks/useMediaControls/useMediaControls.mjs.map +1 -1
- package/dist/esm/hooks/useMouse/useMouse.mjs +17 -17
- package/dist/esm/hooks/useMouse/useMouse.mjs.map +1 -1
- package/dist/esm/hooks/useMutationObserver/useMutationObserver.mjs +17 -16
- package/dist/esm/hooks/useMutationObserver/useMutationObserver.mjs.map +1 -1
- package/dist/esm/hooks/useOtpCredential/useOtpCredential.mjs +2 -2
- package/dist/esm/hooks/useOtpCredential/useOtpCredential.mjs.map +1 -1
- package/dist/esm/hooks/usePaint/usePaint.mjs +31 -31
- package/dist/esm/hooks/usePaint/usePaint.mjs.map +1 -1
- package/dist/esm/hooks/useParallax/useParallax.mjs +24 -23
- package/dist/esm/hooks/useParallax/useParallax.mjs.map +1 -1
- package/dist/esm/hooks/usePictureInPicture/usePictureInPicture.mjs +25 -25
- package/dist/esm/hooks/usePictureInPicture/usePictureInPicture.mjs.map +1 -1
- package/dist/esm/hooks/useRefState/useRefState.mjs +1 -0
- package/dist/esm/hooks/useRefState/useRefState.mjs.map +1 -1
- package/dist/esm/hooks/useResizeObserver/useResizeObserver.mjs +16 -16
- package/dist/esm/hooks/useResizeObserver/useResizeObserver.mjs.map +1 -1
- package/dist/esm/hooks/useRightClick/useRightClick.mjs +14 -14
- package/dist/esm/hooks/useRightClick/useRightClick.mjs.map +1 -1
- package/dist/esm/hooks/useScroll/useScroll.mjs +22 -22
- package/dist/esm/hooks/useScroll/useScroll.mjs.map +1 -1
- package/dist/esm/hooks/useScrollIntoView/useScrollIntoView.mjs +16 -16
- package/dist/esm/hooks/useScrollIntoView/useScrollIntoView.mjs.map +1 -1
- package/dist/esm/hooks/useScrollTo/useScrollTo.mjs +10 -10
- package/dist/esm/hooks/useScrollTo/useScrollTo.mjs.map +1 -1
- package/dist/esm/hooks/useSticky/useSticky.mjs +17 -17
- package/dist/esm/hooks/useSticky/useSticky.mjs.map +1 -1
- package/dist/esm/hooks/useStopwatch/useStopwatch.mjs +4 -4
- package/dist/esm/hooks/useStopwatch/useStopwatch.mjs.map +1 -1
- package/dist/esm/hooks/useStorage/useStorage.mjs +2 -2
- package/dist/esm/hooks/useStorage/useStorage.mjs.map +1 -1
- package/dist/esm/hooks/useTextDirection/useTextDirection.mjs +12 -12
- package/dist/esm/hooks/useTextDirection/useTextDirection.mjs.map +1 -1
- package/dist/esm/hooks/useTextareaAutosize/useTextareaAutosize.mjs +20 -20
- package/dist/esm/hooks/useTextareaAutosize/useTextareaAutosize.mjs.map +1 -1
- package/dist/esm/hooks/useTimer/useTimer.mjs +3 -3
- package/dist/esm/hooks/useTimer/useTimer.mjs.map +1 -1
- package/dist/esm/hooks/useUrlSearchParam/useUrlSearchParam.mjs +2 -2
- package/dist/esm/hooks/useUrlSearchParam/useUrlSearchParam.mjs.map +1 -1
- package/dist/esm/hooks/useUrlSearchParams/useUrlSearchParams.mjs +2 -2
- package/dist/esm/hooks/useUrlSearchParams/useUrlSearchParams.mjs.map +1 -1
- package/dist/esm/hooks/useVisibility/useVisibility.mjs +25 -17
- package/dist/esm/hooks/useVisibility/useVisibility.mjs.map +1 -1
- package/dist/esm/index.mjs +98 -96
- package/dist/esm/utils/helpers/isTarget.mjs +10 -8
- package/dist/esm/utils/helpers/isTarget.mjs.map +1 -1
- package/dist/types/hooks/useBreakpoints/useBreakpoints.d.ts +1 -11
- package/dist/types/hooks/useClickOutside/useClickOutside.d.ts +1 -1
- package/dist/types/hooks/useHover/useHover.d.ts +6 -6
- package/dist/types/hooks/useRefState/useRefState.d.ts +1 -0
- package/dist/types/utils/helpers/isTarget.d.ts +9 -1
- package/package.json +89 -89
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUrlSearchParams.mjs","sources":["../../../../src/hooks/useUrlSearchParams/useUrlSearchParams.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport {\n createQueryString,\n dispatchUrlSearchParamsEvent,\n getUrlSearchParams,\n URL_SEARCH_PARAMS_EVENT\n} from '../useUrlSearchParam/useUrlSearchParam';\n\n/** The url params type */\nexport type UrlParams = Record<string, any>;\n\n/** The url search params mod */\nexport type UrlSearchParamsMode = 'hash-params' | 'hash' | 'history';\n\n/** The use url search params set options type */\nexport interface UseUrlSearchParamsSetOptions {\n /** The mode to use for writing to the URL */\n write?: 'push' | 'replace';\n}\n\n/* The use search params initial value type */\nexport type UseUrlSearchParamsInitialValue<Value> = (() => Value) | Value;\n\n/** The use url search params options type */\nexport interface UseUrlSearchParamsOptions<Value> {\n /* The initial value of the url search params */\n initialValue?: UseUrlSearchParamsInitialValue<string | URLSearchParams | Value>;\n /** The mode to use for writing to the URL */\n mode?: UrlSearchParamsMode;\n /** The mode to use for writing to the URL */\n write?: 'push' | 'replace';\n /* The deserializer function to be invoked */\n deserializer?: (value: string) => Value[keyof Value];\n /* The serializer function to be invoked */\n serializer?: (value: Value[keyof Value]) => string;\n}\n\n/** The use url search params return type */\nexport interface UseUrlSearchParamsReturn<Value> {\n /** The value of the url search params */\n value: Value;\n /** The set function */\n set: (value: Partial<Value>, options?: UseUrlSearchParamsSetOptions) => void;\n}\n\nexport interface UseUrlSearchParams {\n <Value>(\n key: string,\n options: UseUrlSearchParamsOptions<Value> & {\n initialValue: UseUrlSearchParamsInitialValue<Value>;\n }\n ): UseUrlSearchParamsReturn<Value>;\n\n <Value>(options?: UseUrlSearchParamsOptions<Value>): UseUrlSearchParamsReturn<Value | undefined>;\n\n <Value>(initialValue: UseUrlSearchParamsInitialValue<Value>): UseUrlSearchParamsReturn<Value>;\n\n <Value>(key: string): UseUrlSearchParamsReturn<Value | undefined>;\n}\n\n/**\n * @name useUrlSearchParams\n * @description - Hook that provides reactive URLSearchParams\n * @category State\n * @usage high\n *\n * @overload\n * @template Value The type of the url param values\n * @param {UseUrlSearchParamsOptions<Value> & { initialValue: UseUrlSearchParamsInitialValue<Value> }} options The options object with required initialValue\n * @param {UseUrlSearchParamsInitialValue<Value>} [options.initialValue] The initial value for the url params\n * @param {UrlSearchParamsMode} [options.mode='history'] The mode to use for the URL ('history' | 'hash-params' | 'hash')\n * @param {'push' | 'replace'} [options.write='replace'] The mode to use for writing to the URL\n * @param {(value: Value[keyof Value]) => string} [options.serializer] Custom serializer function to convert value to string\n * @param {(value: string) => Value[keyof Value]} [options.deserializer] Custom deserializer function to convert string to value\n * @returns {UseUrlSearchParamsReturn<Value>} The object with value and function for change value\n *\n * @example\n * const { value, set } = useUrlSearchParams({ initialValue: { page: 1 } });\n *\n * @overload\n * @template Value The type of the url param values\n * @param {UseUrlSearchParamsInitialValue<Value>} [initialValue] The initial value for the url params\n * @returns {UseUrlSearchParamsReturn<Value>} The object with value and function for change value\n *\n * @example\n * const { value, set } = useUrlSearchParams({ page: 1 });\n */\nexport const useUrlSearchParams = (<Value extends UrlParams>(\n params: any\n): UseUrlSearchParamsReturn<Value> => {\n const options = (\n typeof params === 'object' &&\n params &&\n ('serializer' in params ||\n 'deserializer' in params ||\n 'initialValue' in params ||\n 'mode' in params ||\n 'write' in params)\n ? params\n : {}\n ) as UseUrlSearchParamsOptions<Value>;\n const initialValue = (\n options ? options?.initialValue : params\n ) as UseUrlSearchParamsInitialValue<Value>;\n\n const { mode = 'history', write: writeMode = 'replace' } = options;\n\n const serializer = (value: Value[keyof Value]) => {\n if (options?.serializer) return options.serializer(value);\n if (typeof value === 'string') return value;\n return JSON.stringify(value);\n };\n\n const deserializer = (value: string) => {\n if (options?.deserializer) return options.deserializer(value);\n if (value === 'undefined') return undefined as unknown as Value[keyof Value];\n\n try {\n return JSON.parse(value) as Value;\n } catch {\n return value as Value[keyof Value];\n }\n };\n\n const setUrlSearchParams = <Value extends UrlParams>(\n mode: UrlSearchParamsMode,\n value: Partial<Value>,\n write: 'push' | 'replace' = 'replace'\n ) => {\n const urlSearchParams = getUrlSearchParams(mode);\n\n Object.entries(value).forEach(([key, param]) => {\n if (param === undefined) {\n urlSearchParams.delete(key);\n } else {\n const serializedValue = serializer ? serializer(param) : String(param);\n urlSearchParams.set(key, serializedValue);\n }\n });\n\n const query = createQueryString(urlSearchParams, mode);\n if (write === 'replace') window.history.replaceState({}, '', query);\n if (write === 'push') window.history.pushState({}, '', query);\n dispatchUrlSearchParamsEvent();\n\n return urlSearchParams;\n };\n\n const getParsedUrlSearchParams = (searchParams: string | UrlParams | URLSearchParams) => {\n if (typeof searchParams === 'string') {\n return getParsedUrlSearchParams(new URLSearchParams(searchParams));\n }\n\n if (searchParams instanceof URLSearchParams) {\n return Array.from(searchParams.entries()).reduce(\n (acc, [key, value]) => {\n acc[key] = deserializer(value);\n return acc;\n },\n {} as Record<string, any>\n );\n }\n\n return searchParams;\n };\n\n const [value, setValue] = useState<Value>(() => {\n if (typeof window === 'undefined') return (initialValue ?? {}) as Value;\n\n const urlSearchParams = getUrlSearchParams(mode);\n const value = {\n ...(initialValue && getParsedUrlSearchParams(initialValue)),\n ...getParsedUrlSearchParams(urlSearchParams)\n } as Value;\n\n setUrlSearchParams(mode, value, writeMode);\n\n return value;\n });\n\n const set = (params: Partial<Value>, options?: UseUrlSearchParamsSetOptions) => {\n const searchParams = setUrlSearchParams(\n mode,\n { ...value, ...params },\n options?.write ?? writeMode\n );\n setValue(getParsedUrlSearchParams(searchParams) as Value);\n };\n\n useEffect(() => {\n const onParamsChange = () => {\n const searchParams = getUrlSearchParams(mode);\n setValue(getParsedUrlSearchParams(searchParams) as Value);\n };\n\n window.addEventListener(URL_SEARCH_PARAMS_EVENT, onParamsChange);\n window.addEventListener('popstate', onParamsChange);\n if (mode !== 'history') window.addEventListener('hashchange', onParamsChange);\n\n return () => {\n window.removeEventListener(URL_SEARCH_PARAMS_EVENT, onParamsChange);\n window.removeEventListener('popstate', onParamsChange);\n if (mode !== 'history') window.removeEventListener('hashchange', onParamsChange);\n };\n }, [mode]);\n\n return {\n value,\n set\n };\n}) as UseUrlSearchParams;\n\nexport { createQueryString, dispatchUrlSearchParamsEvent, getUrlSearchParams };\n"],"names":["useUrlSearchParams","params","options","initialValue","mode","writeMode","serializer","value","deserializer","setUrlSearchParams","write","urlSearchParams","getUrlSearchParams","key","param","serializedValue","query","createQueryString","dispatchUrlSearchParamsEvent","getParsedUrlSearchParams","searchParams","acc","setValue","useState","set","useEffect","onParamsChange","URL_SEARCH_PARAMS_EVENT"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"useUrlSearchParams.mjs","sources":["../../../../src/hooks/useUrlSearchParams/useUrlSearchParams.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport {\n createQueryString,\n dispatchUrlSearchParamsEvent,\n getUrlSearchParams,\n URL_SEARCH_PARAMS_EVENT\n} from '../useUrlSearchParam/useUrlSearchParam';\n\n/** The url params type */\nexport type UrlParams = Record<string, any>;\n\n/** The url search params mod */\nexport type UrlSearchParamsMode = 'hash-params' | 'hash' | 'history';\n\n/** The use url search params set options type */\nexport interface UseUrlSearchParamsSetOptions {\n /** The mode to use for writing to the URL */\n write?: 'push' | 'replace';\n}\n\n/* The use search params initial value type */\nexport type UseUrlSearchParamsInitialValue<Value> = (() => Value) | Value;\n\n/** The use url search params options type */\nexport interface UseUrlSearchParamsOptions<Value> {\n /* The initial value of the url search params */\n initialValue?: UseUrlSearchParamsInitialValue<string | URLSearchParams | Value>;\n /** The mode to use for writing to the URL */\n mode?: UrlSearchParamsMode;\n /** The mode to use for writing to the URL */\n write?: 'push' | 'replace';\n /* The deserializer function to be invoked */\n deserializer?: (value: string) => Value[keyof Value];\n /* The serializer function to be invoked */\n serializer?: (value: Value[keyof Value]) => string;\n}\n\n/** The use url search params return type */\nexport interface UseUrlSearchParamsReturn<Value> {\n /** The value of the url search params */\n value: Value;\n /** The set function */\n set: (value: Partial<Value>, options?: UseUrlSearchParamsSetOptions) => void;\n}\n\nexport interface UseUrlSearchParams {\n <Value>(\n key: string,\n options: UseUrlSearchParamsOptions<Value> & {\n initialValue: UseUrlSearchParamsInitialValue<Value>;\n }\n ): UseUrlSearchParamsReturn<Value>;\n\n <Value>(options?: UseUrlSearchParamsOptions<Value>): UseUrlSearchParamsReturn<Value | undefined>;\n\n <Value>(initialValue: UseUrlSearchParamsInitialValue<Value>): UseUrlSearchParamsReturn<Value>;\n\n <Value>(key: string): UseUrlSearchParamsReturn<Value | undefined>;\n}\n\n/**\n * @name useUrlSearchParams\n * @description - Hook that provides reactive URLSearchParams\n * @category State\n * @usage high\n *\n * @overload\n * @template Value The type of the url param values\n * @param {UseUrlSearchParamsOptions<Value> & { initialValue: UseUrlSearchParamsInitialValue<Value> }} options The options object with required initialValue\n * @param {UseUrlSearchParamsInitialValue<Value>} [options.initialValue] The initial value for the url params\n * @param {UrlSearchParamsMode} [options.mode='history'] The mode to use for the URL ('history' | 'hash-params' | 'hash')\n * @param {'push' | 'replace'} [options.write='replace'] The mode to use for writing to the URL\n * @param {(value: Value[keyof Value]) => string} [options.serializer] Custom serializer function to convert value to string\n * @param {(value: string) => Value[keyof Value]} [options.deserializer] Custom deserializer function to convert string to value\n * @returns {UseUrlSearchParamsReturn<Value>} The object with value and function for change value\n *\n * @example\n * const { value, set } = useUrlSearchParams({ initialValue: { page: 1 } });\n *\n * @overload\n * @template Value The type of the url param values\n * @param {UseUrlSearchParamsInitialValue<Value>} [initialValue] The initial value for the url params\n * @returns {UseUrlSearchParamsReturn<Value>} The object with value and function for change value\n *\n * @example\n * const { value, set } = useUrlSearchParams({ page: 1 });\n */\nexport const useUrlSearchParams = (<Value extends UrlParams>(\n params: any\n): UseUrlSearchParamsReturn<Value> => {\n const options = (\n typeof params === 'object' &&\n params &&\n ('serializer' in params ||\n 'deserializer' in params ||\n 'initialValue' in params ||\n 'mode' in params ||\n 'write' in params)\n ? params\n : {}\n ) as UseUrlSearchParamsOptions<Value>;\n const initialValue = (\n options ? options?.initialValue : params\n ) as UseUrlSearchParamsInitialValue<Value>;\n\n const { mode = 'history', write: writeMode = 'replace' } = options;\n\n const serializer = (value: Value[keyof Value]) => {\n if (options?.serializer) return options.serializer(value);\n if (typeof value === 'string') return value;\n return JSON.stringify(value);\n };\n\n const deserializer = (value: string) => {\n if (options?.deserializer) return options.deserializer(value);\n if (value === 'undefined') return undefined as unknown as Value[keyof Value];\n\n try {\n return JSON.parse(value) as Value;\n } catch {\n return value as Value[keyof Value];\n }\n };\n\n const setUrlSearchParams = <Value extends UrlParams>(\n mode: UrlSearchParamsMode,\n value: Partial<Value>,\n write: 'push' | 'replace' = 'replace'\n ) => {\n const urlSearchParams = getUrlSearchParams(mode);\n\n Object.entries(value).forEach(([key, param]) => {\n if (param === undefined) {\n urlSearchParams.delete(key);\n } else {\n const serializedValue = serializer ? serializer(param) : String(param);\n urlSearchParams.set(key, serializedValue);\n }\n });\n\n const query = createQueryString(urlSearchParams, mode);\n if (write === 'replace') window.history.replaceState({}, '', query);\n if (write === 'push') window.history.pushState({}, '', query);\n dispatchUrlSearchParamsEvent();\n\n return urlSearchParams;\n };\n\n const getParsedUrlSearchParams = (searchParams: string | UrlParams | URLSearchParams) => {\n if (typeof searchParams === 'string') {\n return getParsedUrlSearchParams(new URLSearchParams(searchParams));\n }\n\n if (searchParams instanceof URLSearchParams) {\n return Array.from(searchParams.entries()).reduce(\n (acc, [key, value]) => {\n acc[key] = deserializer(value);\n return acc;\n },\n {} as Record<string, any>\n );\n }\n\n return searchParams;\n };\n\n const [value, setValue] = useState<Value>(() => {\n if (typeof window === 'undefined') return (initialValue ?? {}) as Value;\n\n const urlSearchParams = getUrlSearchParams(mode);\n const value = {\n ...(initialValue && getParsedUrlSearchParams(initialValue)),\n ...getParsedUrlSearchParams(urlSearchParams)\n } as Value;\n\n setUrlSearchParams(mode, value, writeMode);\n\n return value;\n });\n\n const set = (params: Partial<Value>, options?: UseUrlSearchParamsSetOptions) => {\n const searchParams = setUrlSearchParams(\n mode,\n { ...value, ...params },\n options?.write ?? writeMode\n );\n setValue(getParsedUrlSearchParams(searchParams) as Value);\n };\n\n useEffect(() => {\n const onParamsChange = () => {\n const searchParams = getUrlSearchParams(mode);\n setValue(getParsedUrlSearchParams(searchParams) as Value);\n };\n\n window.addEventListener(URL_SEARCH_PARAMS_EVENT, onParamsChange);\n window.addEventListener('popstate', onParamsChange);\n if (mode !== 'history') window.addEventListener('hashchange', onParamsChange);\n\n return () => {\n window.removeEventListener(URL_SEARCH_PARAMS_EVENT, onParamsChange);\n window.removeEventListener('popstate', onParamsChange);\n if (mode !== 'history') window.removeEventListener('hashchange', onParamsChange);\n };\n }, [mode]);\n\n return {\n value,\n set\n };\n}) as UseUrlSearchParams;\n\nexport { createQueryString, dispatchUrlSearchParamsEvent, getUrlSearchParams };\n"],"names":["useUrlSearchParams","params","options","initialValue","mode","writeMode","serializer","value","deserializer","setUrlSearchParams","write","urlSearchParams","getUrlSearchParams","key","param","serializedValue","query","createQueryString","dispatchUrlSearchParamsEvent","getParsedUrlSearchParams","searchParams","acc","setValue","useState","set","useEffect","onParamsChange","URL_SEARCH_PARAMS_EVENT"],"mappings":"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"}
|
|
@@ -1,33 +1,41 @@
|
|
|
1
|
-
import { useState as d, useRef as
|
|
2
|
-
import { useRefState as
|
|
3
|
-
import { isTarget as
|
|
4
|
-
const
|
|
5
|
-
const n =
|
|
6
|
-
return l.current = i,
|
|
1
|
+
import { useState as d, useRef as R, useEffect as C } from "react";
|
|
2
|
+
import { useRefState as E } from "../useRefState/useRefState.mjs";
|
|
3
|
+
import { isTarget as s } from "../../utils/helpers/isTarget.mjs";
|
|
4
|
+
const S = ((...e) => {
|
|
5
|
+
const n = s(e[0]) ? e[0] : void 0, t = n ? typeof e[1] == "object" ? e[1] : { onChange: e[1] } : typeof e[0] == "object" ? e[0] : { onChange: e[0] }, i = t?.onChange, f = t?.enabled ?? !0, [u, v] = d(), [o, y] = d(), r = E(), l = R(i);
|
|
6
|
+
return l.current = i, C(() => {
|
|
7
7
|
if (!f || !n && !r.state) return;
|
|
8
|
-
const b = n ?
|
|
8
|
+
const b = n ? s.getElement(n) : r.current;
|
|
9
9
|
if (!b) return;
|
|
10
|
-
const
|
|
11
|
-
(
|
|
12
|
-
const g =
|
|
13
|
-
y(g), l.current?.(g,
|
|
10
|
+
const c = new IntersectionObserver(
|
|
11
|
+
(a, h) => {
|
|
12
|
+
const g = a.pop();
|
|
13
|
+
y(g), l.current?.(g, h);
|
|
14
14
|
},
|
|
15
15
|
{
|
|
16
16
|
...t,
|
|
17
|
-
root: t?.root ?
|
|
17
|
+
root: t?.root ? s.getElement(t.root) : document
|
|
18
18
|
}
|
|
19
19
|
);
|
|
20
|
-
return v(
|
|
21
|
-
|
|
20
|
+
return v(c), c.observe(b), () => {
|
|
21
|
+
c.disconnect();
|
|
22
22
|
};
|
|
23
|
-
}, [
|
|
23
|
+
}, [
|
|
24
|
+
n,
|
|
25
|
+
r.state,
|
|
26
|
+
s.getRefState(n),
|
|
27
|
+
t?.rootMargin,
|
|
28
|
+
t?.threshold,
|
|
29
|
+
t?.root,
|
|
30
|
+
f
|
|
31
|
+
]), n ? { observer: u, entry: o, inView: !!o?.isIntersecting } : {
|
|
24
32
|
observer: u,
|
|
25
33
|
ref: r,
|
|
26
34
|
entry: o,
|
|
27
35
|
inView: !!o?.isIntersecting
|
|
28
36
|
};
|
|
29
|
-
};
|
|
37
|
+
});
|
|
30
38
|
export {
|
|
31
|
-
|
|
39
|
+
S as useVisibility
|
|
32
40
|
};
|
|
33
41
|
//# sourceMappingURL=useVisibility.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useVisibility.mjs","sources":["../../../../src/hooks/useVisibility/useVisibility.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The visibility callback type */\nexport type UseVisibilityCallback = (\n entry: IntersectionObserverEntry,\n observer: IntersectionObserver\n) => void;\n\n/** The visibility options type */\nexport interface UseVisibilityOptions extends Omit<IntersectionObserverInit, 'root'> {\n /** The enabled state of the intersection */\n enabled?: boolean;\n /** The callback to execute when intersection is detected */\n onChange?: UseVisibilityCallback;\n /** The root element to observe */\n root?: HookTarget;\n}\n\n/** The intersection observer return type */\nexport interface UseVisibilityReturn {\n /** The intersection observer entry */\n entry?: IntersectionObserverEntry;\n /** The intersection observer in view */\n inView?: boolean;\n\n /** The intersection observer instance */\n observer?: IntersectionObserver;\n}\n\nexport interface UseVisibility {\n <Target extends Element>(\n options?: UseVisibilityOptions,\n target?: never\n ): UseVisibilityReturn & { ref: StateRef<Target> };\n\n (target: HookTarget, options?: UseVisibilityOptions): UseVisibilityReturn;\n\n <Target extends Element>(\n callback: UseVisibilityCallback,\n target?: never\n ): UseVisibilityReturn & { ref: StateRef<Target> };\n\n (target: HookTarget, callback: UseVisibilityCallback): UseVisibilityReturn;\n}\n\n/**\n * @name useVisibility\n * @description - Hook that gives you visibility observer state\n * @category Sensors\n * @usage medium\n *\n * @browserapi IntersectionObserver https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver\n *\n * @overload\n * @param {HookTarget} target The target element to detect intersection\n * @param {boolean} [options.enabled=true] The Intersection options\n * @param {((entries: IntersectionEntry[], observer: Intersection) => void) | undefined} [options.onChange] The callback to execute when intersection is detected\n * @param {HookTarget} [options.root=document] The root element to observe\n * @returns {UseVisibilityReturn} An object containing the state\n *\n * @example\n * const { ref, entries, observer } = useVisibility();\n *\n * @overload\n * @template Target The target element\n * @param {boolean} [options.enabled=true] The Intersection options\n * @param {((entries: IntersectionEntry[], observer: Intersection) => void) | undefined} [options.onChange] The callback to execute when intersection is detected\n * @param {HookTarget} [options.root=document] The root element to observe\n * @returns {UseVisibilityReturn & { ref: StateRef<Target> }} A React ref to attach to the target element\n *\n * @example\n * const { entries, observer } = useVisibility(ref);\n *\n * @overload\n * @template Target The target element\n * @param {UseVisibilityCallback} callback The callback to execute when intersection is detected\n * @returns {UseVisibilityReturn & { ref: StateRef<Target> }} A React ref to attach to the target element\n *\n * @example\n * const { ref, entries, observer } = useVisibility(() => console.log('callback'));\n *\n * @overload\n * @param {UseVisibilityCallback} callback The callback to execute when intersection is detected\n * @param {HookTarget} target The target element to detect intersection\n * @returns {UseVisibilityReturn} An object containing the state\n *\n * @example\n * const { entries, observer } = useVisibility(ref, () => console.log('callback'));\n */\nexport const useVisibility = ((...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 UseVisibilityOptions | undefined;\n\n const callback = options?.onChange;\n const enabled = options?.enabled ?? true;\n\n const [observer, setObserver] = useState<IntersectionObserver>();\n const [entry, setEntry] = useState<IntersectionObserverEntry>();\n\n const internalRef = useRefState<Element>();\n const internalCallbackRef = useRef(callback);\n internalCallbackRef.current = callback;\n\n useEffect(() => {\n if (!enabled || (!target && !internalRef.state)) return;\n\n const element = target ? isTarget.getElement(target) : internalRef.current;\n if (!element) return;\n\n const observer = new IntersectionObserver(\n (entries: IntersectionObserverEntry[], observer: IntersectionObserver) => {\n const entry = entries.pop()!;\n setEntry(entry);\n internalCallbackRef.current?.(entry, observer);\n },\n {\n ...options,\n root: options?.root ? (isTarget.getElement(options.root) as Document | Element) : document\n }\n );\n\n setObserver(observer);\n observer.observe(element as Element);\n\n return () => {\n observer.disconnect();\n };\n }, [target
|
|
1
|
+
{"version":3,"file":"useVisibility.mjs","sources":["../../../../src/hooks/useVisibility/useVisibility.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The visibility callback type */\nexport type UseVisibilityCallback = (\n entry: IntersectionObserverEntry,\n observer: IntersectionObserver\n) => void;\n\n/** The visibility options type */\nexport interface UseVisibilityOptions extends Omit<IntersectionObserverInit, 'root'> {\n /** The enabled state of the intersection */\n enabled?: boolean;\n /** The callback to execute when intersection is detected */\n onChange?: UseVisibilityCallback;\n /** The root element to observe */\n root?: HookTarget;\n}\n\n/** The intersection observer return type */\nexport interface UseVisibilityReturn {\n /** The intersection observer entry */\n entry?: IntersectionObserverEntry;\n /** The intersection observer in view */\n inView?: boolean;\n\n /** The intersection observer instance */\n observer?: IntersectionObserver;\n}\n\nexport interface UseVisibility {\n <Target extends Element>(\n options?: UseVisibilityOptions,\n target?: never\n ): UseVisibilityReturn & { ref: StateRef<Target> };\n\n (target: HookTarget, options?: UseVisibilityOptions): UseVisibilityReturn;\n\n <Target extends Element>(\n callback: UseVisibilityCallback,\n target?: never\n ): UseVisibilityReturn & { ref: StateRef<Target> };\n\n (target: HookTarget, callback: UseVisibilityCallback): UseVisibilityReturn;\n}\n\n/**\n * @name useVisibility\n * @description - Hook that gives you visibility observer state\n * @category Sensors\n * @usage medium\n *\n * @browserapi IntersectionObserver https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver\n *\n * @overload\n * @param {HookTarget} target The target element to detect intersection\n * @param {boolean} [options.enabled=true] The Intersection options\n * @param {((entries: IntersectionEntry[], observer: Intersection) => void) | undefined} [options.onChange] The callback to execute when intersection is detected\n * @param {HookTarget} [options.root=document] The root element to observe\n * @returns {UseVisibilityReturn} An object containing the state\n *\n * @example\n * const { ref, entries, observer } = useVisibility();\n *\n * @overload\n * @template Target The target element\n * @param {boolean} [options.enabled=true] The Intersection options\n * @param {((entries: IntersectionEntry[], observer: Intersection) => void) | undefined} [options.onChange] The callback to execute when intersection is detected\n * @param {HookTarget} [options.root=document] The root element to observe\n * @returns {UseVisibilityReturn & { ref: StateRef<Target> }} A React ref to attach to the target element\n *\n * @example\n * const { entries, observer } = useVisibility(ref);\n *\n * @overload\n * @template Target The target element\n * @param {UseVisibilityCallback} callback The callback to execute when intersection is detected\n * @returns {UseVisibilityReturn & { ref: StateRef<Target> }} A React ref to attach to the target element\n *\n * @example\n * const { ref, entries, observer } = useVisibility(() => console.log('callback'));\n *\n * @overload\n * @param {UseVisibilityCallback} callback The callback to execute when intersection is detected\n * @param {HookTarget} target The target element to detect intersection\n * @returns {UseVisibilityReturn} An object containing the state\n *\n * @example\n * const { entries, observer } = useVisibility(ref, () => console.log('callback'));\n */\nexport const useVisibility = ((...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 UseVisibilityOptions | undefined;\n\n const callback = options?.onChange;\n const enabled = options?.enabled ?? true;\n\n const [observer, setObserver] = useState<IntersectionObserver>();\n const [entry, setEntry] = useState<IntersectionObserverEntry>();\n\n const internalRef = useRefState<Element>();\n const internalCallbackRef = useRef(callback);\n internalCallbackRef.current = callback;\n\n useEffect(() => {\n if (!enabled || (!target && !internalRef.state)) return;\n\n const element = target ? isTarget.getElement(target) : internalRef.current;\n if (!element) return;\n\n const observer = new IntersectionObserver(\n (entries: IntersectionObserverEntry[], observer: IntersectionObserver) => {\n const entry = entries.pop()!;\n setEntry(entry);\n internalCallbackRef.current?.(entry, observer);\n },\n {\n ...options,\n root: options?.root ? (isTarget.getElement(options.root) as Document | Element) : document\n }\n );\n\n setObserver(observer);\n observer.observe(element as Element);\n\n return () => {\n observer.disconnect();\n };\n }, [\n target,\n internalRef.state,\n isTarget.getRefState(target),\n options?.rootMargin,\n options?.threshold,\n options?.root,\n enabled\n ]);\n\n if (target) return { observer, entry, inView: !!entry?.isIntersecting };\n return {\n observer,\n ref: internalRef,\n entry,\n inView: !!entry?.isIntersecting\n };\n}) as UseVisibility;\n"],"names":["useVisibility","params","target","isTarget","options","callback","enabled","observer","setObserver","useState","entry","setEntry","internalRef","useRefState","internalCallbackRef","useRef","useEffect","element","entries"],"mappings":";;;AAiGO,MAAMA,KAAiB,IAAIC,MAAkB;AAClD,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,GAC1B,CAACC,GAAOC,CAAQ,IAAIF,EAAA,GAEpBG,IAAcC,EAAA,GACdC,IAAsBC,EAAOV,CAAQ;AAqC3C,SApCAS,EAAoB,UAAUT,GAE9BW,EAAU,MAAM;AACd,QAAI,CAACV,KAAY,CAACJ,KAAU,CAACU,EAAY,MAAQ;AAEjD,UAAMK,IAAUf,IAASC,EAAS,WAAWD,CAAM,IAAIU,EAAY;AACnE,QAAI,CAACK,EAAS;AAEd,UAAMV,IAAW,IAAI;AAAA,MACnB,CAACW,GAAsCX,MAAmC;AACxE,cAAMG,IAAQQ,EAAQ,IAAA;AACtB,QAAAP,EAASD,CAAK,GACdI,EAAoB,UAAUJ,GAAOH,CAAQ;AAAA,MAAA;AAAA,MAE/C;AAAA,QACE,GAAGH;AAAA,QACH,MAAMA,GAAS,OAAQD,EAAS,WAAWC,EAAQ,IAAI,IAA2B;AAAA,MAAA;AAAA,IACpF;AAGF,WAAAI,EAAYD,CAAQ,GACpBA,EAAS,QAAQU,CAAkB,GAE5B,MAAM;AACXV,MAAAA,EAAS,WAAA;AAAA,IAAW;AAAA,EACtB,GACC;AAAA,IACDL;AAAA,IACAU,EAAY;AAAA,IACZT,EAAS,YAAYD,CAAM;AAAA,IAC3BE,GAAS;AAAA,IACTA,GAAS;AAAA,IACTA,GAAS;AAAA,IACTE;AAAA,EAAA,CACD,GAEGJ,IAAe,EAAE,UAAAK,GAAU,OAAAG,GAAO,QAAQ,CAAC,CAACA,GAAO,eAAA,IAChD;AAAA,IACL,UAAAH;AAAA,IACA,KAAKK;AAAA,IACL,OAAAF;AAAA,IACA,QAAQ,CAAC,CAACA,GAAO;AAAA,EAAA;AAErB;"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import { useLockCallback as n } from "./hooks/useLockCallback/useLockCallback.mj
|
|
|
7
7
|
import { useMutation as l } from "./hooks/useMutation/useMutation.mjs";
|
|
8
8
|
import { useOptimistic as E } from "./hooks/useOptimistic/useOptimistic.mjs";
|
|
9
9
|
import { useQuery as g } from "./hooks/useQuery/useQuery.mjs";
|
|
10
|
-
import { useAudio as
|
|
10
|
+
import { useAudio as d } from "./hooks/useAudio/useAudio.mjs";
|
|
11
11
|
import { useBattery as P } from "./hooks/useBattery/useBattery.mjs";
|
|
12
12
|
import { useBluetooth as I } from "./hooks/useBluetooth/useBluetooth.mjs";
|
|
13
13
|
import { useBroadcastChannel as O } from "./hooks/useBroadcastChannel/useBroadcastChannel.mjs";
|
|
@@ -32,7 +32,7 @@ import { usePermission as ie } from "./hooks/usePermission/usePermission.mjs";
|
|
|
32
32
|
import { usePictureInPicture as ce } from "./hooks/usePictureInPicture/usePictureInPicture.mjs";
|
|
33
33
|
import { usePointerLock as Se } from "./hooks/usePointerLock/usePointerLock.mjs";
|
|
34
34
|
import { usePostMessage as Te } from "./hooks/usePostMessage/usePostMessage.mjs";
|
|
35
|
-
import { useRaf as
|
|
35
|
+
import { useRaf as Re } from "./hooks/useRaf/useRaf.mjs";
|
|
36
36
|
import { useShare as Ce } from "./hooks/useShare/useShare.mjs";
|
|
37
37
|
import { getSpeechRecognition as Ae, useSpeechRecognition as Ie } from "./hooks/useSpeechRecognition/useSpeechRecognition.mjs";
|
|
38
38
|
import { useSpeechSynthesis as Oe } from "./hooks/useSpeechSynthesis/useSpeechSynthesis.mjs";
|
|
@@ -78,7 +78,7 @@ import { useDevicePixelRatio as nr } from "./hooks/useDevicePixelRatio/useDevice
|
|
|
78
78
|
import { useDocumentEvent as lr } from "./hooks/useDocumentEvent/useDocumentEvent.mjs";
|
|
79
79
|
import { useDocumentVisibility as Er } from "./hooks/useDocumentVisibility/useDocumentVisibility.mjs";
|
|
80
80
|
import { useElementSize as gr } from "./hooks/useElementSize/useElementSize.mjs";
|
|
81
|
-
import { useEventListener as
|
|
81
|
+
import { useEventListener as dr } from "./hooks/useEventListener/useEventListener.mjs";
|
|
82
82
|
import { isHotkeyMatch as Pr, useHotkeys as Ar } from "./hooks/useHotkeys/useHotkeys.mjs";
|
|
83
83
|
import { useIdle as yr } from "./hooks/useIdle/useIdle.mjs";
|
|
84
84
|
import { useInfiniteScroll as kr } from "./hooks/useInfiniteScroll/useInfiniteScroll.mjs";
|
|
@@ -104,7 +104,7 @@ import { getRangesSelection as it, useTextSelection as nt } from "./hooks/useTex
|
|
|
104
104
|
import { useVisibility as lt } from "./hooks/useVisibility/useVisibility.mjs";
|
|
105
105
|
import { useWindowEvent as Et } from "./hooks/useWindowEvent/useWindowEvent.mjs";
|
|
106
106
|
import { useWindowFocus as gt } from "./hooks/useWindowFocus/useWindowFocus.mjs";
|
|
107
|
-
import { scrollTo as
|
|
107
|
+
import { scrollTo as dt, useWindowScroll as Ct } from "./hooks/useWindowScroll/useWindowScroll.mjs";
|
|
108
108
|
import { useWindowSize as At } from "./hooks/useWindowSize/useWindowSize.mjs";
|
|
109
109
|
import { useBoolean as yt } from "./hooks/useBoolean/useBoolean.mjs";
|
|
110
110
|
import { useControllableState as kt } from "./hooks/useControllableState/useControllableState.mjs";
|
|
@@ -122,45 +122,45 @@ import { assignRef as us, mergeRefs as ms, useMergedRef as ps } from "./hooks/us
|
|
|
122
122
|
import { useOffsetPagination as xs } from "./hooks/useOffsetPagination/useOffsetPagination.mjs";
|
|
123
123
|
import { useQueue as is } from "./hooks/useQueue/useQueue.mjs";
|
|
124
124
|
import { useRafState as cs } from "./hooks/useRafState/useRafState.mjs";
|
|
125
|
-
import {
|
|
126
|
-
import { useSessionStorage as
|
|
125
|
+
import { createRefState as Ss, useRefState as Es } from "./hooks/useRefState/useRefState.mjs";
|
|
126
|
+
import { useSessionStorage as gs } from "./hooks/useSessionStorage/useSessionStorage.mjs";
|
|
127
127
|
import { useSet as ds } from "./hooks/useSet/useSet.mjs";
|
|
128
|
-
import { stateHistoryReducer as
|
|
129
|
-
import { useStep as
|
|
130
|
-
import { STORAGE_EVENT as
|
|
131
|
-
import { useToggle as
|
|
132
|
-
import { URL_SEARCH_PARAMS_EVENT as
|
|
133
|
-
import { useUrlSearchParams as
|
|
134
|
-
import { useWizard as
|
|
135
|
-
import { useInterval as
|
|
136
|
-
import { useStopwatch as
|
|
137
|
-
import { useTime as
|
|
138
|
-
import { useTimeout as
|
|
139
|
-
import { getTimeFromSeconds as
|
|
140
|
-
import { useBrowserLanguage as
|
|
141
|
-
import { getOperatingSystem as
|
|
142
|
-
import { usePreferredColorScheme as
|
|
143
|
-
import { usePreferredContrast as
|
|
144
|
-
import { usePreferredDark as
|
|
145
|
-
import { usePreferredLanguages as
|
|
146
|
-
import { usePreferredReducedMotion as
|
|
147
|
-
import { useConst as
|
|
148
|
-
import { useDebounceCallback as
|
|
149
|
-
import { useDebounceState as
|
|
150
|
-
import { useDebounceValue as
|
|
151
|
-
import { useEvent as
|
|
152
|
-
import { useLastChanged as
|
|
153
|
-
import { useLatest as
|
|
154
|
-
import { usePrevious as
|
|
155
|
-
import { useThrottleCallback as
|
|
156
|
-
import { useThrottleState as
|
|
157
|
-
import { useThrottleValue as
|
|
158
|
-
import { copy as
|
|
159
|
-
import { debounce as
|
|
160
|
-
import { getDate as
|
|
161
|
-
import { getRetry as
|
|
162
|
-
import { isTarget as
|
|
163
|
-
import { throttle as
|
|
128
|
+
import { stateHistoryReducer as Ps, useStateHistory as As } from "./hooks/useStateHistory/useStateHistory.mjs";
|
|
129
|
+
import { useStep as ys } from "./hooks/useStep/useStep.mjs";
|
|
130
|
+
import { STORAGE_EVENT as ks, dispatchStorageEvent as hs, useStorage as vs } from "./hooks/useStorage/useStorage.mjs";
|
|
131
|
+
import { useToggle as Ds } from "./hooks/useToggle/useToggle.mjs";
|
|
132
|
+
import { URL_SEARCH_PARAMS_EVENT as Ls, createQueryString as Ms, dispatchUrlSearchParamsEvent as Ns, getUrlSearchParams as Bs, useUrlSearchParam as Ks } from "./hooks/useUrlSearchParam/useUrlSearchParam.mjs";
|
|
133
|
+
import { useUrlSearchParams as Us } from "./hooks/useUrlSearchParams/useUrlSearchParams.mjs";
|
|
134
|
+
import { useWizard as Hs } from "./hooks/useWizard/useWizard.mjs";
|
|
135
|
+
import { useInterval as Ws } from "./hooks/useInterval/useInterval.mjs";
|
|
136
|
+
import { useStopwatch as Gs } from "./hooks/useStopwatch/useStopwatch.mjs";
|
|
137
|
+
import { useTime as Xs } from "./hooks/useTime/useTime.mjs";
|
|
138
|
+
import { useTimeout as Zs } from "./hooks/useTimeout/useTimeout.mjs";
|
|
139
|
+
import { getTimeFromSeconds as Js, useTimer as Ys } from "./hooks/useTimer/useTimer.mjs";
|
|
140
|
+
import { useBrowserLanguage as eu } from "./hooks/useBrowserLanguage/useBrowserLanguage.mjs";
|
|
141
|
+
import { getOperatingSystem as ru, useOperatingSystem as tu } from "./hooks/useOperatingSystem/useOperatingSystem.mjs";
|
|
142
|
+
import { usePreferredColorScheme as uu } from "./hooks/usePreferredColorScheme/usePreferredColorScheme.mjs";
|
|
143
|
+
import { usePreferredContrast as pu } from "./hooks/usePreferredContrast/usePreferredContrast.mjs";
|
|
144
|
+
import { usePreferredDark as xu } from "./hooks/usePreferredDark/usePreferredDark.mjs";
|
|
145
|
+
import { usePreferredLanguages as iu } from "./hooks/usePreferredLanguages/usePreferredLanguages.mjs";
|
|
146
|
+
import { usePreferredReducedMotion as cu } from "./hooks/usePreferredReducedMotion/usePreferredReducedMotion.mjs";
|
|
147
|
+
import { useConst as Su } from "./hooks/useConst/useConst.mjs";
|
|
148
|
+
import { useDebounceCallback as Tu } from "./hooks/useDebounceCallback/useDebounceCallback.mjs";
|
|
149
|
+
import { useDebounceState as Ru } from "./hooks/useDebounceState/useDebounceState.mjs";
|
|
150
|
+
import { useDebounceValue as Cu } from "./hooks/useDebounceValue/useDebounceValue.mjs";
|
|
151
|
+
import { useEvent as Au } from "./hooks/useEvent/useEvent.mjs";
|
|
152
|
+
import { useLastChanged as yu } from "./hooks/useLastChanged/useLastChanged.mjs";
|
|
153
|
+
import { useLatest as ku } from "./hooks/useLatest/useLatest.mjs";
|
|
154
|
+
import { usePrevious as vu } from "./hooks/usePrevious/usePrevious.mjs";
|
|
155
|
+
import { useThrottleCallback as Du } from "./hooks/useThrottleCallback/useThrottleCallback.mjs";
|
|
156
|
+
import { useThrottleState as Lu } from "./hooks/useThrottleState/useThrottleState.mjs";
|
|
157
|
+
import { useThrottleValue as Nu } from "./hooks/useThrottleValue/useThrottleValue.mjs";
|
|
158
|
+
import { copy as Ku, legacyCopyToClipboard as Fu } from "./utils/helpers/copy.mjs";
|
|
159
|
+
import { debounce as Vu } from "./utils/helpers/debounce.mjs";
|
|
160
|
+
import { getDate as wu } from "./utils/helpers/getDate.mjs";
|
|
161
|
+
import { getRetry as zu } from "./utils/helpers/getRetry.mjs";
|
|
162
|
+
import { getRefState as Qu, isTarget as Xu, target as qu, targetSymbol as Zu } from "./utils/helpers/isTarget.mjs";
|
|
163
|
+
import { throttle as Ju } from "./utils/helpers/throttle.mjs";
|
|
164
164
|
export {
|
|
165
165
|
Jo as BREAKPOINTS_ANT_DESIGN,
|
|
166
166
|
Yo as BREAKPOINTS_BOOTSTRAP_V5,
|
|
@@ -177,70 +177,72 @@ export {
|
|
|
177
177
|
lo as Paint,
|
|
178
178
|
So as Pointer,
|
|
179
179
|
Co as SCRIPT_STATUS_ATTRIBUTE_NAME,
|
|
180
|
-
|
|
181
|
-
|
|
180
|
+
ks as STORAGE_EVENT,
|
|
181
|
+
Ls as URL_SEARCH_PARAMS_EVENT,
|
|
182
182
|
us as assignRef,
|
|
183
183
|
Ut as clearCookies,
|
|
184
|
-
|
|
184
|
+
Ku as copy,
|
|
185
185
|
r as createContext,
|
|
186
186
|
s as createEventEmitter,
|
|
187
|
-
|
|
187
|
+
Ms as createQueryString,
|
|
188
188
|
m as createReactiveContext,
|
|
189
|
+
Ss as createRefState,
|
|
189
190
|
f as createStore,
|
|
190
|
-
|
|
191
|
+
Vu as debounce,
|
|
191
192
|
Qo as deepEqual,
|
|
192
193
|
_t as dispatchCookieEvent,
|
|
193
|
-
|
|
194
|
-
|
|
194
|
+
hs as dispatchStorageEvent,
|
|
195
|
+
Ns as dispatchUrlSearchParamsEvent,
|
|
195
196
|
se as getConnection,
|
|
196
197
|
Dt as getCookie,
|
|
197
198
|
bt as getCookies,
|
|
198
|
-
|
|
199
|
+
wu as getDate,
|
|
199
200
|
jt as getHash,
|
|
200
|
-
|
|
201
|
+
ru as getOperatingSystem,
|
|
201
202
|
it as getRangesSelection,
|
|
202
|
-
|
|
203
|
+
Qu as getRefState,
|
|
204
|
+
zu as getRetry,
|
|
203
205
|
Ae as getSpeechRecognition,
|
|
204
|
-
|
|
205
|
-
|
|
206
|
+
Js as getTimeFromSeconds,
|
|
207
|
+
Bs as getUrlSearchParams,
|
|
206
208
|
Pr as isHotkeyMatch,
|
|
207
|
-
|
|
208
|
-
|
|
209
|
+
Xu as isTarget,
|
|
210
|
+
Fu as legacyCopyToClipboard,
|
|
209
211
|
q as mapGamepadToXbox360Controller,
|
|
210
212
|
ms as mergeRefs,
|
|
211
213
|
Lt as removeCookie,
|
|
212
214
|
Mt as removeCookieItem,
|
|
213
|
-
|
|
215
|
+
dt as scrollTo,
|
|
214
216
|
Nt as setCookie,
|
|
215
217
|
Bt as setCookieItem,
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
218
|
+
Ps as stateHistoryReducer,
|
|
219
|
+
qu as target,
|
|
220
|
+
Zu as targetSymbol,
|
|
221
|
+
Ju as throttle,
|
|
220
222
|
$ as timeRangeToArray,
|
|
221
223
|
ze as useActiveElement,
|
|
222
224
|
a as useAsync,
|
|
223
225
|
Bo as useAsyncEffect,
|
|
224
|
-
|
|
226
|
+
d as useAudio,
|
|
225
227
|
Qe as useAutoScroll,
|
|
226
228
|
P as useBattery,
|
|
227
229
|
I as useBluetooth,
|
|
228
230
|
yt as useBoolean,
|
|
229
231
|
mr as useBreakpoints,
|
|
230
232
|
O as useBroadcastChannel,
|
|
231
|
-
|
|
233
|
+
eu as useBrowserLanguage,
|
|
232
234
|
qe as useClickOutside,
|
|
233
235
|
h as useClipboard,
|
|
234
|
-
|
|
236
|
+
Su as useConst,
|
|
235
237
|
kt as useControllableState,
|
|
236
238
|
Kt as useCookie,
|
|
237
239
|
Vt as useCookies,
|
|
238
240
|
_ as useCopy,
|
|
239
241
|
wt as useCounter,
|
|
240
242
|
b as useCssVar,
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
243
|
+
Tu as useDebounceCallback,
|
|
244
|
+
Ru as useDebounceState,
|
|
245
|
+
Cu as useDebounceValue,
|
|
244
246
|
zt as useDefault,
|
|
245
247
|
fr as useDeviceMotion,
|
|
246
248
|
ar as useDeviceOrientation,
|
|
@@ -254,8 +256,8 @@ export {
|
|
|
254
256
|
Je as useDoubleClick,
|
|
255
257
|
$e as useDropZone,
|
|
256
258
|
gr as useElementSize,
|
|
257
|
-
|
|
258
|
-
|
|
259
|
+
Au as useEvent,
|
|
260
|
+
dr as useEventListener,
|
|
259
261
|
F as useEventSource,
|
|
260
262
|
V as useEyeDropper,
|
|
261
263
|
w as useFavicon,
|
|
@@ -275,15 +277,15 @@ export {
|
|
|
275
277
|
ao as useImage,
|
|
276
278
|
kr as useInfiniteScroll,
|
|
277
279
|
vr as useIntersectionObserver,
|
|
278
|
-
|
|
280
|
+
Ws as useInterval,
|
|
279
281
|
Vo as useIsFirstRender,
|
|
280
282
|
wo as useIsomorphicLayoutEffect,
|
|
281
283
|
Lr as useKeyPress,
|
|
282
284
|
Nr as useKeyPressEvent,
|
|
283
285
|
Dr as useKeyboard,
|
|
284
286
|
Kr as useKeysPressed,
|
|
285
|
-
|
|
286
|
-
|
|
287
|
+
yu as useLastChanged,
|
|
288
|
+
ku as useLatest,
|
|
287
289
|
bo as useLess,
|
|
288
290
|
$t as useList,
|
|
289
291
|
os as useLocalStorage,
|
|
@@ -305,7 +307,7 @@ export {
|
|
|
305
307
|
xs as useOffsetPagination,
|
|
306
308
|
Mo as useOnce,
|
|
307
309
|
pe as useOnline,
|
|
308
|
-
|
|
310
|
+
tu as useOperatingSystem,
|
|
309
311
|
E as useOptimistic,
|
|
310
312
|
Zr as useOrientation,
|
|
311
313
|
xe as useOtpCredential,
|
|
@@ -317,17 +319,17 @@ export {
|
|
|
317
319
|
ce as usePictureInPicture,
|
|
318
320
|
Se as usePointerLock,
|
|
319
321
|
Te as usePostMessage,
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
322
|
+
uu as usePreferredColorScheme,
|
|
323
|
+
pu as usePreferredContrast,
|
|
324
|
+
xu as usePreferredDark,
|
|
325
|
+
iu as usePreferredLanguages,
|
|
326
|
+
cu as usePreferredReducedMotion,
|
|
327
|
+
vu as usePrevious,
|
|
326
328
|
g as useQuery,
|
|
327
329
|
is as useQueue,
|
|
328
|
-
|
|
330
|
+
Re as useRaf,
|
|
329
331
|
cs as useRafState,
|
|
330
|
-
|
|
332
|
+
Es as useRefState,
|
|
331
333
|
Fe as useRenderCount,
|
|
332
334
|
Ve as useRenderInfo,
|
|
333
335
|
we as useRerender,
|
|
@@ -337,30 +339,30 @@ export {
|
|
|
337
339
|
ut as useScroll,
|
|
338
340
|
pt as useScrollIntoView,
|
|
339
341
|
xt as useScrollTo,
|
|
340
|
-
|
|
342
|
+
gs as useSessionStorage,
|
|
341
343
|
ds as useSet,
|
|
342
344
|
Xo as useShallowEffect,
|
|
343
345
|
Ce as useShare,
|
|
344
346
|
Ie as useSpeechRecognition,
|
|
345
347
|
Oe as useSpeechSynthesis,
|
|
346
|
-
|
|
347
|
-
|
|
348
|
+
As as useStateHistory,
|
|
349
|
+
ys as useStep,
|
|
348
350
|
Io as useSticky,
|
|
349
|
-
|
|
350
|
-
|
|
351
|
+
Gs as useStopwatch,
|
|
352
|
+
vs as useStorage,
|
|
351
353
|
ho as useTextDirection,
|
|
352
354
|
nt as useTextSelection,
|
|
353
355
|
Oo as useTextareaAutosize,
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
356
|
+
Du as useThrottleCallback,
|
|
357
|
+
Lu as useThrottleState,
|
|
358
|
+
Nu as useThrottleValue,
|
|
359
|
+
Xs as useTime,
|
|
360
|
+
Zs as useTimeout,
|
|
361
|
+
Ys as useTimer,
|
|
362
|
+
Ds as useToggle,
|
|
361
363
|
Zo as useUnmount,
|
|
362
|
-
|
|
363
|
-
|
|
364
|
+
Ks as useUrlSearchParam,
|
|
365
|
+
Us as useUrlSearchParams,
|
|
364
366
|
he as useVibrate,
|
|
365
367
|
_e as useVirtualKeyboard,
|
|
366
368
|
lt as useVisibility,
|
|
@@ -370,6 +372,6 @@ export {
|
|
|
370
372
|
gt as useWindowFocus,
|
|
371
373
|
Ct as useWindowScroll,
|
|
372
374
|
At as useWindowSize,
|
|
373
|
-
|
|
375
|
+
Hs as useWizard
|
|
374
376
|
};
|
|
375
377
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
const
|
|
1
|
+
const u = /* @__PURE__ */ Symbol("target"), o = (e) => "current" in e ? e.current : typeof e.value == "function" ? e.value() : typeof e.value == "string" ? document.querySelector(e.value) : (e.value instanceof Document || e.value instanceof Window || e.value instanceof Element, e.value), i = (e) => ({
|
|
2
2
|
value: e,
|
|
3
|
-
type:
|
|
4
|
-
}),
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
type: u
|
|
4
|
+
}), n = (e) => typeof e == "object" && ("current" in e || e && e.type === u) || typeof e == "function" && "state" in e && "current" in e, c = (e) => e && "state" in e && e.state;
|
|
5
|
+
n.wrap = i;
|
|
6
|
+
n.getElement = o;
|
|
7
|
+
n.getRefState = c;
|
|
7
8
|
export {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
c as getRefState,
|
|
10
|
+
n as isTarget,
|
|
11
|
+
i as target,
|
|
12
|
+
u as targetSymbol
|
|
11
13
|
};
|
|
12
14
|
//# sourceMappingURL=isTarget.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isTarget.mjs","sources":["../../../../src/utils/helpers/isTarget.ts"],"sourcesContent":["import type { RefObject } from 'react';\n\nexport const targetSymbol = Symbol('target');\n\nexport type Target = (() => Element) | string | Document | Element | Window;\n\nexport type HookTarget =\n | RefObject<Element | null | undefined>\n | {\n value: Target;\n type: symbol;\n };\n\nconst getElement = (target: HookTarget) => {\n if ('current' in target) {\n return target.current;\n }\n\n if (typeof target.value === 'function') {\n return target.value();\n }\n\n if (typeof target.value === 'string') {\n return document.querySelector(target.value);\n }\n\n if (target.value instanceof Document) {\n return target.value;\n }\n\n if (target.value instanceof Window) {\n return target.value;\n }\n\n if (target.value instanceof Element) {\n return target.value;\n }\n\n return target.value;\n};\n\nexport const target = (target: Target) => ({\n value: target,\n type: targetSymbol\n});\n\nexport const isTarget = (target: HookTarget) =>\n typeof target === 'object' &&\n
|
|
1
|
+
{"version":3,"file":"isTarget.mjs","sources":["../../../../src/utils/helpers/isTarget.ts"],"sourcesContent":["import type { RefObject } from 'react';\n\nexport const targetSymbol = Symbol('target');\n\nexport type Target = (() => Element) | string | Document | Element | Window;\ninterface StateRef<Value> {\n (node: Value): void;\n current: Value;\n state: Value;\n}\n\nexport type HookTarget =\n | RefObject<Element | null | undefined>\n | StateRef<Element | null | undefined>\n | {\n value: Target;\n type: symbol;\n };\n\nconst getElement = (target: HookTarget) => {\n if ('current' in target) {\n return target.current;\n }\n\n if (typeof target.value === 'function') {\n return target.value();\n }\n\n if (typeof target.value === 'string') {\n return document.querySelector(target.value);\n }\n\n if (target.value instanceof Document) {\n return target.value;\n }\n\n if (target.value instanceof Window) {\n return target.value;\n }\n\n if (target.value instanceof Element) {\n return target.value;\n }\n\n return target.value;\n};\n\nexport const target = (target: Target) => ({\n value: target,\n type: targetSymbol\n});\n\nexport const isTarget = (target: HookTarget) =>\n (typeof target === 'object' &&\n ('current' in target || (target && (target as any).type === targetSymbol))) ||\n (typeof target === 'function' && 'state' in target && 'current' in target);\n\nexport const getRefState = (target?: HookTarget) => target && 'state' in target && target.state;\n\nisTarget.wrap = target;\nisTarget.getElement = getElement;\nisTarget.getRefState = getRefState;\n"],"names":["targetSymbol","getElement","target","isTarget","getRefState"],"mappings":"AAEO,MAAMA,2BAAsB,QAAQ,GAiBrCC,IAAa,CAACC,MACd,aAAaA,IACRA,EAAO,UAGZ,OAAOA,EAAO,SAAU,aACnBA,EAAO,MAAA,IAGZ,OAAOA,EAAO,SAAU,WACnB,SAAS,cAAcA,EAAO,KAAK,KAGxCA,EAAO,iBAAiB,YAIxBA,EAAO,iBAAiB,UAIxBA,EAAO,iBAAiB,SACnBA,EAAO,QAMLA,IAAS,CAACA,OAAoB;AAAA,EACzC,OAAOA;AAAAA,EACP,MAAMF;AACR,IAEaG,IAAW,CAACD,MACtB,OAAOA,KAAW,aAChB,aAAaA,KAAWA,KAAWA,EAAe,SAASF,MAC7D,OAAOE,KAAW,cAAc,WAAWA,KAAU,aAAaA,GAExDE,IAAc,CAACF,MAAwBA,KAAU,WAAWA,KAAUA,EAAO;AAE1FC,EAAS,OAAOD;AAChBC,EAAS,aAAaF;AACtBE,EAAS,cAAcC;"}
|
|
@@ -14,16 +14,6 @@ export type UseBreakpointsReturn<Breakpoint extends string = string> = {
|
|
|
14
14
|
smallerOrEqual: (breakpoint: Breakpoint) => boolean;
|
|
15
15
|
/** The function that checks if the current breakpoint is between to the given breakpoints */
|
|
16
16
|
between: (a: Breakpoint, b: Breakpoint) => boolean;
|
|
17
|
-
/** The function that checks if the current breakpoint is greater than to the given breakpoint */
|
|
18
|
-
isGreater: (breakpoint: Breakpoint) => boolean;
|
|
19
|
-
/** The function that checks if the current breakpoint is greater than or equal to the given breakpoint */
|
|
20
|
-
isGreaterOrEqual: (breakpoint: Breakpoint) => boolean;
|
|
21
|
-
/** The function that checks if the current breakpoint is smaller than to the given breakpoint */
|
|
22
|
-
isSmaller: (breakpoint: Breakpoint) => boolean;
|
|
23
|
-
/** The function that checks if the current breakpoint is smaller than or equal to the given breakpoint */
|
|
24
|
-
isSmallerOrEqual: (breakpoint: Breakpoint) => boolean;
|
|
25
|
-
/** The function that checks if the current breakpoint is between to the given breakpoints */
|
|
26
|
-
isInBetween: (a: Breakpoint, b: Breakpoint) => boolean;
|
|
27
17
|
/** The function that returns the current breakpoints */
|
|
28
18
|
current: () => Breakpoint[];
|
|
29
19
|
/** The function that returns the current active breakpoint */
|
|
@@ -41,7 +31,7 @@ export type UseBreakpointsReturn<Breakpoint extends string = string> = {
|
|
|
41
31
|
* @returns {UseBreakpointsReturn<Breakpoint>} An object containing the current breakpoint
|
|
42
32
|
*
|
|
43
33
|
* @example
|
|
44
|
-
* const {
|
|
34
|
+
* const { greater, smaller, between, current, active, ...breakpoints } = useBreakpoints({ mobile: 0, tablet: 640, laptop: 1024, desktop: 1280 });
|
|
45
35
|
*/
|
|
46
36
|
export declare const useBreakpoints: <Breakpoint extends string>(breakpoints: Breakpoints<Breakpoint>, strategy?: UseBreakpointsStrategy) => UseBreakpointsReturn<Breakpoint>;
|
|
47
37
|
/** Breakpoints from Material UI */
|
|
@@ -21,7 +21,7 @@ export interface UseClickOutside {
|
|
|
21
21
|
* @overload
|
|
22
22
|
* @template Target The target element(s)
|
|
23
23
|
* @param {(event: Event) => void} callback The callback to execute when a click outside the target is detected
|
|
24
|
-
* @returns {
|
|
24
|
+
* @returns {StateRef<Target>} A ref to attach to the target element
|
|
25
25
|
*
|
|
26
26
|
* @example
|
|
27
27
|
* const ref = useClickOutside<HTMLDivElement>(() => console.log('click outside'));
|
|
@@ -31,7 +31,7 @@ export interface UseHover {
|
|
|
31
31
|
* @overload
|
|
32
32
|
* @param {HookTarget} target The target element to be hovered
|
|
33
33
|
* @param {(event: Event) => void} [callback] The callback function to be invoked on mouse enter
|
|
34
|
-
* @returns {boolean} The
|
|
34
|
+
* @returns {boolean} The value of the hover
|
|
35
35
|
*
|
|
36
36
|
* @example
|
|
37
37
|
* const hovering = useHover(ref, () => console.log('callback'));
|
|
@@ -40,7 +40,7 @@ export interface UseHover {
|
|
|
40
40
|
* @param {HookTarget} target The target element to be hovered
|
|
41
41
|
* @param {(event: Event) => void} [options.onEntry] The callback function to be invoked on mouse enter
|
|
42
42
|
* @param {(event: Event) => void} [options.onLeave] The callback function to be invoked on mouse leave
|
|
43
|
-
* @returns {boolean} The
|
|
43
|
+
* @returns {boolean} The value of the hover
|
|
44
44
|
*
|
|
45
45
|
* @example
|
|
46
46
|
* const hovering = useHover(ref, options);
|
|
@@ -48,18 +48,18 @@ export interface UseHover {
|
|
|
48
48
|
* @overload
|
|
49
49
|
* @template Target The target element
|
|
50
50
|
* @param {(event: Event) => void} [callback] The callback function to be invoked on mouse enter
|
|
51
|
-
* @returns {{ ref: StateRef<Target> } & UseHoverReturn} The
|
|
51
|
+
* @returns {{ ref: StateRef<Target> } & UseHoverReturn} The object with the ref and the value of the hover
|
|
52
52
|
*
|
|
53
53
|
* @example
|
|
54
|
-
* const
|
|
54
|
+
* const { ref, value } = useHover(() => console.log('callback'));
|
|
55
55
|
*
|
|
56
56
|
* @overload
|
|
57
57
|
* @template Target The target element
|
|
58
58
|
* @param {(event: Event) => void} [options.onEntry] The callback function to be invoked on mouse enter
|
|
59
59
|
* @param {(event: Event) => void} [options.onLeave] The callback function to be invoked on mouse leave
|
|
60
|
-
* @returns {{ ref: StateRef<Target> } & UseHoverReturn} The
|
|
60
|
+
* @returns {{ ref: StateRef<Target> } & UseHoverReturn} The object with the ref and the value of the hover
|
|
61
61
|
*
|
|
62
62
|
* @example
|
|
63
|
-
* const
|
|
63
|
+
* const { ref, value } = useHover(options);
|
|
64
64
|
*/
|
|
65
65
|
export declare const useHover: UseHover;
|
|
@@ -3,6 +3,7 @@ export interface StateRef<Value> {
|
|
|
3
3
|
current: Value;
|
|
4
4
|
state?: Value;
|
|
5
5
|
}
|
|
6
|
+
export declare const createRefState: <Value>(initialValue: Value | undefined, setState: (value: Value) => void) => StateRef<Value>;
|
|
6
7
|
/**
|
|
7
8
|
* @name useRefState
|
|
8
9
|
* @description - Hook that returns the state reference of the value
|