@siberiacancode/reactuse 0.3.6 → 0.3.8
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/useClickOutside/useClickOutside.cjs +1 -1
- package/dist/cjs/hooks/useClickOutside/useClickOutside.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/useDisclosure/useDisclosure.cjs +1 -1
- package/dist/cjs/hooks/useDisclosure/useDisclosure.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/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/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/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/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/useSpeechRecognition/useSpeechRecognition.cjs +1 -1
- package/dist/cjs/hooks/useSpeechRecognition/useSpeechRecognition.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/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/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 +5 -5
- package/dist/esm/hooks/useActiveElement/useActiveElement.mjs.map +1 -1
- package/dist/esm/hooks/useAutoScroll/useAutoScroll.mjs +6 -6
- package/dist/esm/hooks/useAutoScroll/useAutoScroll.mjs.map +1 -1
- package/dist/esm/hooks/useClickOutside/useClickOutside.mjs +6 -6
- package/dist/esm/hooks/useClickOutside/useClickOutside.mjs.map +1 -1
- package/dist/esm/hooks/useCssVar/useCssVar.mjs +5 -5
- package/dist/esm/hooks/useCssVar/useCssVar.mjs.map +1 -1
- package/dist/esm/hooks/useDisclosure/useDisclosure.mjs +1 -1
- package/dist/esm/hooks/useDisclosure/useDisclosure.mjs.map +1 -1
- package/dist/esm/hooks/useDisplayMedia/useDisplayMedia.mjs +6 -6
- package/dist/esm/hooks/useDisplayMedia/useDisplayMedia.mjs.map +1 -1
- package/dist/esm/hooks/useDoubleClick/useDoubleClick.mjs +12 -12
- package/dist/esm/hooks/useDoubleClick/useDoubleClick.mjs.map +1 -1
- package/dist/esm/hooks/useDropZone/useDropZone.mjs +3 -3
- package/dist/esm/hooks/useDropZone/useDropZone.mjs.map +1 -1
- package/dist/esm/hooks/useElementSize/useElementSize.mjs +6 -6
- package/dist/esm/hooks/useElementSize/useElementSize.mjs.map +1 -1
- package/dist/esm/hooks/useEventListener/useEventListener.mjs +10 -10
- package/dist/esm/hooks/useEventListener/useEventListener.mjs.map +1 -1
- package/dist/esm/hooks/useFocus/useFocus.mjs +10 -10
- package/dist/esm/hooks/useFocus/useFocus.mjs.map +1 -1
- package/dist/esm/hooks/useFocusTrap/useFocusTrap.mjs +5 -5
- package/dist/esm/hooks/useFocusTrap/useFocusTrap.mjs.map +1 -1
- package/dist/esm/hooks/useHotkeys/useHotkeys.mjs +7 -8
- package/dist/esm/hooks/useHotkeys/useHotkeys.mjs.map +1 -1
- package/dist/esm/hooks/useHover/useHover.mjs +7 -7
- package/dist/esm/hooks/useHover/useHover.mjs.map +1 -1
- package/dist/esm/hooks/useInfiniteScroll/useInfiniteScroll.mjs +6 -6
- package/dist/esm/hooks/useInfiniteScroll/useInfiniteScroll.mjs.map +1 -1
- package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs +17 -18
- package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs.map +1 -1
- package/dist/esm/hooks/useInterval/useInterval.mjs +6 -6
- package/dist/esm/hooks/useInterval/useInterval.mjs.map +1 -1
- package/dist/esm/hooks/useKeyPress/useKeyPress.mjs +5 -5
- package/dist/esm/hooks/useKeyPress/useKeyPress.mjs.map +1 -1
- package/dist/esm/hooks/useKeyPressEvent/useKeyPressEvent.mjs +3 -4
- package/dist/esm/hooks/useKeyPressEvent/useKeyPressEvent.mjs.map +1 -1
- package/dist/esm/hooks/useKeyboard/useKeyboard.mjs +8 -8
- package/dist/esm/hooks/useKeyboard/useKeyboard.mjs.map +1 -1
- package/dist/esm/hooks/useKeysPressed/useKeysPressed.mjs +8 -8
- package/dist/esm/hooks/useKeysPressed/useKeysPressed.mjs.map +1 -1
- package/dist/esm/hooks/useLockScroll/useLockScroll.mjs +19 -22
- package/dist/esm/hooks/useLockScroll/useLockScroll.mjs.map +1 -1
- package/dist/esm/hooks/useLongPress/useLongPress.mjs +7 -7
- package/dist/esm/hooks/useLongPress/useLongPress.mjs.map +1 -1
- package/dist/esm/hooks/useMeasure/useMeasure.mjs +3 -3
- package/dist/esm/hooks/useMeasure/useMeasure.mjs.map +1 -1
- package/dist/esm/hooks/useMediaControls/useMediaControls.mjs +5 -5
- package/dist/esm/hooks/useMediaControls/useMediaControls.mjs.map +1 -1
- package/dist/esm/hooks/useMouse/useMouse.mjs +10 -10
- package/dist/esm/hooks/useMouse/useMouse.mjs.map +1 -1
- package/dist/esm/hooks/useMutationObserver/useMutationObserver.mjs +7 -8
- package/dist/esm/hooks/useMutationObserver/useMutationObserver.mjs.map +1 -1
- package/dist/esm/hooks/usePaint/usePaint.mjs +15 -15
- package/dist/esm/hooks/usePaint/usePaint.mjs.map +1 -1
- package/dist/esm/hooks/useParallax/useParallax.mjs +24 -25
- package/dist/esm/hooks/useParallax/useParallax.mjs.map +1 -1
- package/dist/esm/hooks/usePictureInPicture/usePictureInPicture.mjs +6 -6
- package/dist/esm/hooks/usePictureInPicture/usePictureInPicture.mjs.map +1 -1
- package/dist/esm/hooks/useResizeObserver/useResizeObserver.mjs +7 -7
- package/dist/esm/hooks/useResizeObserver/useResizeObserver.mjs.map +1 -1
- package/dist/esm/hooks/useRightClick/useRightClick.mjs +5 -5
- package/dist/esm/hooks/useRightClick/useRightClick.mjs.map +1 -1
- package/dist/esm/hooks/useScroll/useScroll.mjs +13 -13
- package/dist/esm/hooks/useScroll/useScroll.mjs.map +1 -1
- package/dist/esm/hooks/useScrollIntoView/useScrollIntoView.mjs +9 -9
- package/dist/esm/hooks/useScrollIntoView/useScrollIntoView.mjs.map +1 -1
- package/dist/esm/hooks/useScrollTo/useScrollTo.mjs +1 -1
- package/dist/esm/hooks/useScrollTo/useScrollTo.mjs.map +1 -1
- package/dist/esm/hooks/useSpeechRecognition/useSpeechRecognition.mjs +1 -4
- package/dist/esm/hooks/useSpeechRecognition/useSpeechRecognition.mjs.map +1 -1
- package/dist/esm/hooks/useSticky/useSticky.mjs +10 -10
- package/dist/esm/hooks/useSticky/useSticky.mjs.map +1 -1
- package/dist/esm/hooks/useTextDirection/useTextDirection.mjs +3 -3
- package/dist/esm/hooks/useTextDirection/useTextDirection.mjs.map +1 -1
- package/dist/esm/hooks/useTextareaAutosize/useTextareaAutosize.mjs +13 -13
- package/dist/esm/hooks/useTextareaAutosize/useTextareaAutosize.mjs.map +1 -1
- package/dist/esm/hooks/useVisibility/useVisibility.mjs +7 -8
- package/dist/esm/hooks/useVisibility/useVisibility.mjs.map +1 -1
- package/dist/esm/index.mjs +25 -21
- package/dist/esm/utils/helpers/isTarget.mjs +12 -7
- package/dist/esm/utils/helpers/isTarget.mjs.map +1 -1
- package/dist/types/hooks/useLockScroll/useLockScroll.d.ts +1 -1
- package/dist/types/utils/helpers/isTarget.d.ts +10 -4
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useRef as a, useState as g, useEffect as v } from "react";
|
|
2
2
|
import { useRefState as R } from "../useRefState/useRefState.mjs";
|
|
3
3
|
import { isTarget as o } from "../../utils/helpers/isTarget.mjs";
|
|
4
|
-
const
|
|
4
|
+
const S = ((...i) => {
|
|
5
5
|
const e = o(i[0]) ? i[0] : void 0, s = (e ? i[1] : i[0]) ?? "ltr", r = R(), n = a(null), u = () => typeof window > "u" ? s : (e ? o.getElement(e) : r.current)?.getAttribute("dir") ?? s, [f, c] = g(u()), l = () => {
|
|
6
6
|
n.current && n.current?.removeAttribute("dir");
|
|
7
7
|
}, m = (t) => {
|
|
@@ -18,7 +18,7 @@ const E = ((...i) => {
|
|
|
18
18
|
return b.observe(t, { attributes: !0 }), () => {
|
|
19
19
|
b.disconnect();
|
|
20
20
|
};
|
|
21
|
-
}, [r.state, e
|
|
21
|
+
}, [r.state, e && o.getRawElement(e)]), e ? { value: f, set: m, remove: l } : {
|
|
22
22
|
ref: r,
|
|
23
23
|
value: f,
|
|
24
24
|
set: m,
|
|
@@ -26,6 +26,6 @@ const E = ((...i) => {
|
|
|
26
26
|
};
|
|
27
27
|
});
|
|
28
28
|
export {
|
|
29
|
-
|
|
29
|
+
S as useTextDirection
|
|
30
30
|
};
|
|
31
31
|
//# sourceMappingURL=useTextDirection.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTextDirection.mjs","sources":["../../../../src/hooks/useTextDirection/useTextDirection.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 use text direction value type */\nexport type UseTextDirectionValue = 'auto' | 'ltr' | 'rtl';\n\n/** The use text direction return type */\nexport interface UseTextDirectionReturn {\n /** The current direction */\n value: UseTextDirectionValue;\n /*** The function to remove the direction */\n remove: () => void;\n /*** The function to set the direction */\n set: (value: UseTextDirectionValue | null) => void;\n}\n\nexport interface UseTextDirection {\n (target: HookTarget, initialValue?: UseTextDirectionValue): UseTextDirectionReturn;\n\n <Target extends Element>(\n initialValue?: UseTextDirectionValue,\n target?: never\n ): UseTextDirectionReturn & { ref: StateRef<Target> };\n}\n\n/**\n * @name useTextDirection\n * @description - Hook that can get and set the direction of the element\n * @category Elements\n * @usage medium\n *\n * @overload\n * @param {HookTarget} [target=document.querySelector('html')] The target element to observe\n * @param {UseTextDirectionValue} [initialValue = 'ltr'] The initial direction of the element\n * @returns {UseTextDirectionReturn} An object containing the current text direction of the element\n *\n * @example\n * const { value, set, remove } = useTextDirection(ref);\n *\n * @overload\n * @template Target The target element type\n * @param {UseTextDirectionValue} [initialValue = 'ltr'] The initial direction of the element\n * @returns { { ref: StateRef<Target> } & UseTextDirectionReturn } An object containing the current text direction of the element\n *\n * @example\n * const { ref, value, set, remove } = useTextDirection();\n */\nexport const useTextDirection = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const initialValue = ((target ? params[1] : params[0]) as UseTextDirectionValue) ?? 'ltr';\n\n const internalRef = useRefState();\n const elementRef = useRef<Element>(null);\n\n const getDirection = () => {\n if (typeof window === 'undefined') return initialValue;\n const element = (target ? isTarget.getElement(target) : internalRef.current) as Element;\n return (element?.getAttribute('dir') as UseTextDirectionValue) ?? initialValue;\n };\n\n const [value, setValue] = useState<UseTextDirectionValue>(getDirection());\n\n const remove = () => {\n if (!elementRef.current) return;\n\n elementRef.current?.removeAttribute('dir');\n };\n\n const set = (value: UseTextDirectionValue) => {\n if (!elementRef.current) return;\n\n setValue(value);\n elementRef.current.setAttribute('dir', value);\n };\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n\n const element =\n ((target ? isTarget.getElement(target) : internalRef.current) as Element) ??\n document.querySelector('html');\n if (!element) return;\n\n elementRef.current = element;\n\n const direction = getDirection();\n element.setAttribute('dir', direction);\n setValue(direction);\n\n const observer = new MutationObserver(() => setValue(getDirection()));\n\n observer.observe(element, { attributes: true });\n\n return () => {\n observer.disconnect();\n };\n }, [internalRef.state, target
|
|
1
|
+
{"version":3,"file":"useTextDirection.mjs","sources":["../../../../src/hooks/useTextDirection/useTextDirection.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 use text direction value type */\nexport type UseTextDirectionValue = 'auto' | 'ltr' | 'rtl';\n\n/** The use text direction return type */\nexport interface UseTextDirectionReturn {\n /** The current direction */\n value: UseTextDirectionValue;\n /*** The function to remove the direction */\n remove: () => void;\n /*** The function to set the direction */\n set: (value: UseTextDirectionValue | null) => void;\n}\n\nexport interface UseTextDirection {\n (target: HookTarget, initialValue?: UseTextDirectionValue): UseTextDirectionReturn;\n\n <Target extends Element>(\n initialValue?: UseTextDirectionValue,\n target?: never\n ): UseTextDirectionReturn & { ref: StateRef<Target> };\n}\n\n/**\n * @name useTextDirection\n * @description - Hook that can get and set the direction of the element\n * @category Elements\n * @usage medium\n *\n * @overload\n * @param {HookTarget} [target=document.querySelector('html')] The target element to observe\n * @param {UseTextDirectionValue} [initialValue = 'ltr'] The initial direction of the element\n * @returns {UseTextDirectionReturn} An object containing the current text direction of the element\n *\n * @example\n * const { value, set, remove } = useTextDirection(ref);\n *\n * @overload\n * @template Target The target element type\n * @param {UseTextDirectionValue} [initialValue = 'ltr'] The initial direction of the element\n * @returns { { ref: StateRef<Target> } & UseTextDirectionReturn } An object containing the current text direction of the element\n *\n * @example\n * const { ref, value, set, remove } = useTextDirection();\n */\nexport const useTextDirection = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const initialValue = ((target ? params[1] : params[0]) as UseTextDirectionValue) ?? 'ltr';\n\n const internalRef = useRefState();\n const elementRef = useRef<Element>(null);\n\n const getDirection = () => {\n if (typeof window === 'undefined') return initialValue;\n const element = (target ? isTarget.getElement(target) : internalRef.current) as Element;\n return (element?.getAttribute('dir') as UseTextDirectionValue) ?? initialValue;\n };\n\n const [value, setValue] = useState<UseTextDirectionValue>(getDirection());\n\n const remove = () => {\n if (!elementRef.current) return;\n\n elementRef.current?.removeAttribute('dir');\n };\n\n const set = (value: UseTextDirectionValue) => {\n if (!elementRef.current) return;\n\n setValue(value);\n elementRef.current.setAttribute('dir', value);\n };\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n\n const element =\n ((target ? isTarget.getElement(target) : internalRef.current) as Element) ??\n document.querySelector('html');\n if (!element) return;\n\n elementRef.current = element;\n\n const direction = getDirection();\n element.setAttribute('dir', direction);\n setValue(direction);\n\n const observer = new MutationObserver(() => setValue(getDirection()));\n\n observer.observe(element, { attributes: true });\n\n return () => {\n observer.disconnect();\n };\n }, [internalRef.state, target && isTarget.getRawElement(target)]);\n\n if (target) return { value, set, remove };\n return {\n ref: internalRef,\n value,\n set,\n remove\n };\n}) as UseTextDirection;\n"],"names":["useTextDirection","params","target","isTarget","initialValue","internalRef","useRefState","elementRef","useRef","getDirection","value","setValue","useState","remove","set","useEffect","element","direction","observer"],"mappings":";;;AAsDO,MAAMA,KAAoB,IAAIC,MAAkB;AACrD,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,KAAiBF,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,MAAgC,OAE9EI,IAAcC,EAAA,GACdC,IAAaC,EAAgB,IAAI,GAEjCC,IAAe,MACf,OAAO,SAAW,MAAoBL,KACzBF,IAASC,EAAS,WAAWD,CAAM,IAAIG,EAAY,UACnD,aAAa,KAAK,KAA+BD,GAG9D,CAACM,GAAOC,CAAQ,IAAIC,EAAgCH,GAAc,GAElEI,IAAS,MAAM;AACnB,IAAKN,EAAW,WAEhBA,EAAW,SAAS,gBAAgB,KAAK;AAAA,EAAA,GAGrCO,IAAM,CAACJ,MAAiC;AAC5C,IAAKH,EAAW,YAEhBI,EAASD,CAAK,GACdH,EAAW,QAAQ,aAAa,OAAOG,CAAK;AAAA,EAAA;AA0B9C,SAvBAK,EAAU,MAAM;AACd,QAAI,CAACb,KAAU,CAACG,EAAY,MAAO;AAEnC,UAAMW,KACFd,IAASC,EAAS,WAAWD,CAAM,IAAIG,EAAY,YACrD,SAAS,cAAc,MAAM;AAC/B,QAAI,CAACW,EAAS;AAEd,IAAAT,EAAW,UAAUS;AAErB,UAAMC,IAAYR,EAAA;AAClB,IAAAO,EAAQ,aAAa,OAAOC,CAAS,GACrCN,EAASM,CAAS;AAElB,UAAMC,IAAW,IAAI,iBAAiB,MAAMP,EAASF,EAAA,CAAc,CAAC;AAEpE,WAAAS,EAAS,QAAQF,GAAS,EAAE,YAAY,IAAM,GAEvC,MAAM;AACX,MAAAE,EAAS,WAAA;AAAA,IAAW;AAAA,EACtB,GACC,CAACb,EAAY,OAAOH,KAAUC,EAAS,cAAcD,CAAM,CAAC,CAAC,GAE5DA,IAAe,EAAE,OAAAQ,GAAO,KAAAI,GAAK,QAAAD,EAAA,IAC1B;AAAA,IACL,KAAKR;AAAA,IACL,OAAAK;AAAA,IACA,KAAAI;AAAA,IACA,QAAAD;AAAA,EAAA;AAEJ;"}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { useState as y, useRef as v, useEffect as R } from "react";
|
|
2
|
-
import { useRefState as
|
|
2
|
+
import { useRefState as E } from "../useRefState/useRefState.mjs";
|
|
3
3
|
import { isTarget as f } from "../../utils/helpers/isTarget.mjs";
|
|
4
4
|
const p = ((...t) => {
|
|
5
|
-
const n = f(t[0]) ? t[0] : void 0, o = n ? typeof t[1] == "object" ? t[1] : { initialValue: t[1] } : typeof t[0] == "object" ? t[0] : { initialValue: t[0] }, [g,
|
|
6
|
-
const e =
|
|
5
|
+
const n = f(t[0]) ? t[0] : void 0, o = n ? typeof t[1] == "object" ? t[1] : { initialValue: t[1] } : typeof t[0] == "object" ? t[0] : { initialValue: t[0] }, [g, m] = y(o?.initialValue ?? ""), s = E(), u = v(null), h = v(0), a = () => {
|
|
6
|
+
const e = u.current;
|
|
7
7
|
if (!e) return;
|
|
8
|
-
const i = e.style.minHeight,
|
|
8
|
+
const i = e.style.minHeight, l = e.style.maxHeight;
|
|
9
9
|
e.style.height = "auto", e.style.minHeight = "auto", e.style.maxHeight = "none";
|
|
10
10
|
const r = e.scrollHeight;
|
|
11
|
-
e.style.height = `${r}px`, e.style.minHeight = i, e.style.maxHeight =
|
|
11
|
+
e.style.height = `${r}px`, e.style.minHeight = i, e.style.maxHeight = l, r !== h.current && o?.onResize?.(), h.current = r;
|
|
12
12
|
}, c = (e) => {
|
|
13
|
-
|
|
14
|
-
const i =
|
|
13
|
+
m(e);
|
|
14
|
+
const i = u.current;
|
|
15
15
|
i && (i.value = e, requestAnimationFrame(() => {
|
|
16
16
|
a();
|
|
17
17
|
}));
|
|
@@ -20,22 +20,22 @@ const p = ((...t) => {
|
|
|
20
20
|
if (!n && !s.state) return;
|
|
21
21
|
const e = n ? f.getElement(n) : s.current;
|
|
22
22
|
if (!e) return;
|
|
23
|
-
|
|
23
|
+
u.current = e, o?.initialValue && (e.value = o.initialValue), a();
|
|
24
24
|
const i = (r) => {
|
|
25
25
|
const H = r.target.value;
|
|
26
26
|
c(H), requestAnimationFrame(() => {
|
|
27
27
|
a();
|
|
28
28
|
});
|
|
29
|
-
},
|
|
29
|
+
}, l = () => {
|
|
30
30
|
requestAnimationFrame(() => {
|
|
31
31
|
a();
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
|
-
return e.addEventListener("input", i), e.addEventListener("resize",
|
|
35
|
-
e.removeEventListener("input", i), e.removeEventListener("resize",
|
|
34
|
+
return e.addEventListener("input", i), e.addEventListener("resize", l), () => {
|
|
35
|
+
e.removeEventListener("input", i), e.removeEventListener("resize", l);
|
|
36
36
|
};
|
|
37
|
-
}, [n
|
|
38
|
-
const x = () =>
|
|
37
|
+
}, [n && f.getRawElement(n), s.state]);
|
|
38
|
+
const x = () => m("");
|
|
39
39
|
return n ? {
|
|
40
40
|
value: g,
|
|
41
41
|
set: c,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTextareaAutosize.mjs","sources":["../../../../src/hooks/useTextareaAutosize/useTextareaAutosize.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 use textarea autosize options */\nexport interface UseTextareaAutosizeOptions {\n /** The initial value for the textarea */\n initialValue?: string;\n /** Callback function called when the textarea size changes */\n onResize?: () => void;\n}\n\n/** The use textarea autosize return type */\nexport interface UseTextareaAutosizeReturn {\n /** The current value of the textarea */\n value: string;\n /** Function to clear the textarea value */\n clear: () => void;\n /** Function to set the textarea value */\n set: (value: string) => void;\n}\n\nexport interface UseTextareaAutosize {\n (target: HookTarget, options?: UseTextareaAutosizeOptions): UseTextareaAutosizeReturn;\n\n (target: HookTarget, initialValue: string): UseTextareaAutosizeReturn;\n\n <Target extends HTMLTextAreaElement = HTMLTextAreaElement>(\n initialValue: string,\n target?: never\n ): UseTextareaAutosizeReturn & {\n ref: StateRef<Target>;\n };\n\n <Target extends HTMLTextAreaElement = HTMLTextAreaElement>(\n options?: UseTextareaAutosizeOptions,\n target?: never\n ): UseTextareaAutosizeReturn & {\n ref: StateRef<Target>;\n };\n}\n\n/**\n * @name useTextareaAutosize\n * @description - Hook that automatically adjusts textarea height based on content\n * @category Elements\n * @usage medium\n *\n * @overload\n * @param {HookTarget} target The target textarea element\n * @param {string} [options.initialValue] The initial value for the textarea\n * @param {Function} [options.onResize] Callback function called when the textarea size changes\n * @returns {UseTextareaAutosizeReturn} An object containing value, setValue and clear\n *\n * @example\n * const { value, setValue, clear } = useTextareaAutosize(ref);\n *\n * @overload\n * @param {HookTarget} target The target textarea element\n * @param {string} initialValue The initial value for the textarea\n * @returns {UseTextareaAutosizeReturn} An object containing value, setValue and clear\n *\n * @example\n * const { value, setValue, clear } = useTextareaAutosize(ref, 'initial');\n *\n * @overload\n * @template Target The textarea element type\n * @param {string} initialValue The initial value for the textarea\n * @returns {UseTextareaAutosizeReturn & { ref: StateRef<Target> }} An object containing ref, value, setValue and clear\n *\n * @example\n * const { ref, value, setValue, clear } = useTextareaAutosize('initial');\n *\n * @overload\n * @template Target The textarea element type\n * @param {string} [options.initialValue] The initial value for the textarea\n * @param {Function} [options.onResize] Callback function called when the textarea size changes\n * @returns {UseTextareaAutosizeReturn & { ref: StateRef<Target> }} An object containing ref, value, setValue and clear\n *\n * @example\n * const { ref, value, setValue, clear } = useTextareaAutosize();\n */\nexport const useTextareaAutosize = ((...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 : { initialValue: params[1] }\n : typeof params[0] === 'object'\n ? params[0]\n : { initialValue: params[0] }\n ) as UseTextareaAutosizeOptions | undefined;\n\n const [value, setValue] = useState(options?.initialValue ?? '');\n const internalRef = useRefState<HTMLTextAreaElement>();\n const textareaRef = useRef<HTMLTextAreaElement | null>(null);\n const scrollHeightRef = useRef(0);\n\n const onTextareaResize = () => {\n const textarea = textareaRef.current;\n if (!textarea) return;\n\n const originalMinHeight = textarea.style.minHeight;\n const originalMaxHeight = textarea.style.maxHeight;\n\n textarea.style.height = 'auto';\n textarea.style.minHeight = 'auto';\n textarea.style.maxHeight = 'none';\n\n const scrollHeight = textarea.scrollHeight;\n\n textarea.style.height = `${scrollHeight}px`;\n textarea.style.minHeight = originalMinHeight;\n textarea.style.maxHeight = originalMaxHeight;\n\n if (scrollHeight !== scrollHeightRef.current) options?.onResize?.();\n scrollHeightRef.current = scrollHeight;\n };\n\n const setTextareaValue = (newValue: string) => {\n setValue(newValue);\n const textarea = textareaRef.current;\n if (!textarea) return;\n textarea.value = newValue;\n requestAnimationFrame(() => {\n onTextareaResize();\n });\n };\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n\n const element = (\n target ? isTarget.getElement(target) : internalRef.current\n ) as HTMLTextAreaElement;\n if (!element) return;\n\n textareaRef.current = element;\n if (options?.initialValue) element.value = options.initialValue;\n\n onTextareaResize();\n\n const onInput = (event: InputEvent) => {\n const newValue = (event.target as HTMLTextAreaElement).value;\n setTextareaValue(newValue);\n\n requestAnimationFrame(() => {\n onTextareaResize();\n });\n };\n\n const onResize = () => {\n requestAnimationFrame(() => {\n onTextareaResize();\n });\n };\n\n element.addEventListener('input', onInput as EventListener);\n element.addEventListener('resize', onResize as EventListener);\n\n return () => {\n element.removeEventListener('input', onInput as EventListener);\n element.removeEventListener('resize', onResize as EventListener);\n };\n }, [target
|
|
1
|
+
{"version":3,"file":"useTextareaAutosize.mjs","sources":["../../../../src/hooks/useTextareaAutosize/useTextareaAutosize.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 use textarea autosize options */\nexport interface UseTextareaAutosizeOptions {\n /** The initial value for the textarea */\n initialValue?: string;\n /** Callback function called when the textarea size changes */\n onResize?: () => void;\n}\n\n/** The use textarea autosize return type */\nexport interface UseTextareaAutosizeReturn {\n /** The current value of the textarea */\n value: string;\n /** Function to clear the textarea value */\n clear: () => void;\n /** Function to set the textarea value */\n set: (value: string) => void;\n}\n\nexport interface UseTextareaAutosize {\n (target: HookTarget, options?: UseTextareaAutosizeOptions): UseTextareaAutosizeReturn;\n\n (target: HookTarget, initialValue: string): UseTextareaAutosizeReturn;\n\n <Target extends HTMLTextAreaElement = HTMLTextAreaElement>(\n initialValue: string,\n target?: never\n ): UseTextareaAutosizeReturn & {\n ref: StateRef<Target>;\n };\n\n <Target extends HTMLTextAreaElement = HTMLTextAreaElement>(\n options?: UseTextareaAutosizeOptions,\n target?: never\n ): UseTextareaAutosizeReturn & {\n ref: StateRef<Target>;\n };\n}\n\n/**\n * @name useTextareaAutosize\n * @description - Hook that automatically adjusts textarea height based on content\n * @category Elements\n * @usage medium\n *\n * @overload\n * @param {HookTarget} target The target textarea element\n * @param {string} [options.initialValue] The initial value for the textarea\n * @param {Function} [options.onResize] Callback function called when the textarea size changes\n * @returns {UseTextareaAutosizeReturn} An object containing value, setValue and clear\n *\n * @example\n * const { value, setValue, clear } = useTextareaAutosize(ref);\n *\n * @overload\n * @param {HookTarget} target The target textarea element\n * @param {string} initialValue The initial value for the textarea\n * @returns {UseTextareaAutosizeReturn} An object containing value, setValue and clear\n *\n * @example\n * const { value, setValue, clear } = useTextareaAutosize(ref, 'initial');\n *\n * @overload\n * @template Target The textarea element type\n * @param {string} initialValue The initial value for the textarea\n * @returns {UseTextareaAutosizeReturn & { ref: StateRef<Target> }} An object containing ref, value, setValue and clear\n *\n * @example\n * const { ref, value, setValue, clear } = useTextareaAutosize('initial');\n *\n * @overload\n * @template Target The textarea element type\n * @param {string} [options.initialValue] The initial value for the textarea\n * @param {Function} [options.onResize] Callback function called when the textarea size changes\n * @returns {UseTextareaAutosizeReturn & { ref: StateRef<Target> }} An object containing ref, value, setValue and clear\n *\n * @example\n * const { ref, value, setValue, clear } = useTextareaAutosize();\n */\nexport const useTextareaAutosize = ((...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 : { initialValue: params[1] }\n : typeof params[0] === 'object'\n ? params[0]\n : { initialValue: params[0] }\n ) as UseTextareaAutosizeOptions | undefined;\n\n const [value, setValue] = useState(options?.initialValue ?? '');\n const internalRef = useRefState<HTMLTextAreaElement>();\n const textareaRef = useRef<HTMLTextAreaElement | null>(null);\n const scrollHeightRef = useRef(0);\n\n const onTextareaResize = () => {\n const textarea = textareaRef.current;\n if (!textarea) return;\n\n const originalMinHeight = textarea.style.minHeight;\n const originalMaxHeight = textarea.style.maxHeight;\n\n textarea.style.height = 'auto';\n textarea.style.minHeight = 'auto';\n textarea.style.maxHeight = 'none';\n\n const scrollHeight = textarea.scrollHeight;\n\n textarea.style.height = `${scrollHeight}px`;\n textarea.style.minHeight = originalMinHeight;\n textarea.style.maxHeight = originalMaxHeight;\n\n if (scrollHeight !== scrollHeightRef.current) options?.onResize?.();\n scrollHeightRef.current = scrollHeight;\n };\n\n const setTextareaValue = (newValue: string) => {\n setValue(newValue);\n const textarea = textareaRef.current;\n if (!textarea) return;\n textarea.value = newValue;\n requestAnimationFrame(() => {\n onTextareaResize();\n });\n };\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n\n const element = (\n target ? isTarget.getElement(target) : internalRef.current\n ) as HTMLTextAreaElement;\n if (!element) return;\n\n textareaRef.current = element;\n if (options?.initialValue) element.value = options.initialValue;\n\n onTextareaResize();\n\n const onInput = (event: InputEvent) => {\n const newValue = (event.target as HTMLTextAreaElement).value;\n setTextareaValue(newValue);\n\n requestAnimationFrame(() => {\n onTextareaResize();\n });\n };\n\n const onResize = () => {\n requestAnimationFrame(() => {\n onTextareaResize();\n });\n };\n\n element.addEventListener('input', onInput as EventListener);\n element.addEventListener('resize', onResize as EventListener);\n\n return () => {\n element.removeEventListener('input', onInput as EventListener);\n element.removeEventListener('resize', onResize as EventListener);\n };\n }, [target && isTarget.getRawElement(target), internalRef.state]);\n\n const clear = () => setValue('');\n\n if (target)\n return {\n value,\n set: setTextareaValue,\n clear\n };\n return {\n ref: internalRef,\n value,\n set: setTextareaValue,\n clear\n };\n}) as UseTextareaAutosize;\n"],"names":["useTextareaAutosize","params","target","isTarget","options","value","setValue","useState","internalRef","useRefState","textareaRef","useRef","scrollHeightRef","onTextareaResize","textarea","originalMinHeight","originalMaxHeight","scrollHeight","setTextareaValue","newValue","useEffect","element","onInput","event","onResize","clear"],"mappings":";;;AAwFO,MAAMA,KAAuB,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,cAAcA,EAAO,CAAC,EAAA,IAC1B,OAAOA,EAAO,CAAC,KAAM,WACnBA,EAAO,CAAC,IACR,EAAE,cAAcA,EAAO,CAAC,EAAA,GAG1B,CAACI,GAAOC,CAAQ,IAAIC,EAASH,GAAS,gBAAgB,EAAE,GACxDI,IAAcC,EAAA,GACdC,IAAcC,EAAmC,IAAI,GACrDC,IAAkBD,EAAO,CAAC,GAE1BE,IAAmB,MAAM;AAC7B,UAAMC,IAAWJ,EAAY;AAC7B,QAAI,CAACI,EAAU;AAEf,UAAMC,IAAoBD,EAAS,MAAM,WACnCE,IAAoBF,EAAS,MAAM;AAEzC,IAAAA,EAAS,MAAM,SAAS,QACxBA,EAAS,MAAM,YAAY,QAC3BA,EAAS,MAAM,YAAY;AAE3B,UAAMG,IAAeH,EAAS;AAE9B,IAAAA,EAAS,MAAM,SAAS,GAAGG,CAAY,MACvCH,EAAS,MAAM,YAAYC,GAC3BD,EAAS,MAAM,YAAYE,GAEvBC,MAAiBL,EAAgB,WAASR,GAAS,WAAA,GACvDQ,EAAgB,UAAUK;AAAA,EAAA,GAGtBC,IAAmB,CAACC,MAAqB;AAC7C,IAAAb,EAASa,CAAQ;AACjB,UAAML,IAAWJ,EAAY;AAC7B,IAAKI,MACLA,EAAS,QAAQK,GACjB,sBAAsB,MAAM;AAC1B,MAAAN,EAAA;AAAA,IAAiB,CAClB;AAAA,EAAA;AAGH,EAAAO,EAAU,MAAM;AACd,QAAI,CAAClB,KAAU,CAACM,EAAY,MAAO;AAEnC,UAAMa,IACJnB,IAASC,EAAS,WAAWD,CAAM,IAAIM,EAAY;AAErD,QAAI,CAACa,EAAS;AAEd,IAAAX,EAAY,UAAUW,GAClBjB,GAAS,iBAAciB,EAAQ,QAAQjB,EAAQ,eAEnDS,EAAA;AAEA,UAAMS,IAAU,CAACC,MAAsB;AACrC,YAAMJ,IAAYI,EAAM,OAA+B;AACvD,MAAAL,EAAiBC,CAAQ,GAEzB,sBAAsB,MAAM;AAC1B,QAAAN,EAAA;AAAA,MAAiB,CAClB;AAAA,IAAA,GAGGW,IAAW,MAAM;AACrB,4BAAsB,MAAM;AAC1B,QAAAX,EAAA;AAAA,MAAiB,CAClB;AAAA,IAAA;AAGH,WAAAQ,EAAQ,iBAAiB,SAASC,CAAwB,GAC1DD,EAAQ,iBAAiB,UAAUG,CAAyB,GAErD,MAAM;AACX,MAAAH,EAAQ,oBAAoB,SAASC,CAAwB,GAC7DD,EAAQ,oBAAoB,UAAUG,CAAyB;AAAA,IAAA;AAAA,EACjE,GACC,CAACtB,KAAUC,EAAS,cAAcD,CAAM,GAAGM,EAAY,KAAK,CAAC;AAEhE,QAAMiB,IAAQ,MAAMnB,EAAS,EAAE;AAE/B,SAAIJ,IACK;AAAA,IACL,OAAAG;AAAA,IACA,KAAKa;AAAA,IACL,OAAAO;AAAA,EAAA,IAEG;AAAA,IACL,KAAKjB;AAAA,IACL,OAAAH;AAAA,IACA,KAAKa;AAAA,IACL,OAAAO;AAAA,EAAA;AAEJ;"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { useState as d, useRef as
|
|
2
|
-
import { useRefState as
|
|
1
|
+
import { useState as d, useRef as E, useEffect as R } from "react";
|
|
2
|
+
import { useRefState as m } from "../useRefState/useRefState.mjs";
|
|
3
3
|
import { isTarget as s } from "../../utils/helpers/isTarget.mjs";
|
|
4
|
-
const
|
|
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 =
|
|
6
|
-
return l.current = i,
|
|
4
|
+
const V = ((...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 = m(), l = E(i);
|
|
6
|
+
return l.current = i, R(() => {
|
|
7
7
|
if (!f || !n && !r.state) return;
|
|
8
8
|
const b = n ? s.getElement(n) : r.current;
|
|
9
9
|
if (!b) return;
|
|
@@ -21,9 +21,8 @@ const S = ((...e) => {
|
|
|
21
21
|
c.disconnect();
|
|
22
22
|
};
|
|
23
23
|
}, [
|
|
24
|
-
n,
|
|
24
|
+
n && s.getRawElement(n),
|
|
25
25
|
r.state,
|
|
26
|
-
s.getRefState(n),
|
|
27
26
|
t?.rootMargin,
|
|
28
27
|
t?.threshold,
|
|
29
28
|
t?.root,
|
|
@@ -36,6 +35,6 @@ const S = ((...e) => {
|
|
|
36
35
|
};
|
|
37
36
|
});
|
|
38
37
|
export {
|
|
39
|
-
|
|
38
|
+
V as useVisibility
|
|
40
39
|
};
|
|
41
40
|
//# 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 }, [\n target,\n internalRef.state,\n
|
|
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 && isTarget.getRawElement(target),\n internalRef.state,\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;AAoC3C,SAnCAS,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,KAAUC,EAAS,cAAcD,CAAM;AAAA,IACvCU,EAAY;AAAA,IACZR,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
|
@@ -18,7 +18,7 @@ import { useDisplayMedia as M } from "./hooks/useDisplayMedia/useDisplayMedia.mj
|
|
|
18
18
|
import { useDocumentTitle as B } from "./hooks/useDocumentTitle/useDocumentTitle.mjs";
|
|
19
19
|
import { useEventSource as F } from "./hooks/useEventSource/useEventSource.mjs";
|
|
20
20
|
import { useEyeDropper as V } from "./hooks/useEyeDropper/useEyeDropper.mjs";
|
|
21
|
-
import { useFavicon as
|
|
21
|
+
import { useFavicon as H } from "./hooks/useFavicon/useFavicon.mjs";
|
|
22
22
|
import { useFps as z } from "./hooks/useFps/useFps.mjs";
|
|
23
23
|
import { useFullscreen as Q } from "./hooks/useFullscreen/useFullscreen.mjs";
|
|
24
24
|
import { mapGamepadToXbox360Controller as q, useGamepad as Z } from "./hooks/useGamepad/useGamepad.mjs";
|
|
@@ -43,7 +43,7 @@ import { useWebSocket as Me } from "./hooks/useWebSocket/useWebSocket.mjs";
|
|
|
43
43
|
import { useLogger as Be } from "./hooks/useLogger/useLogger.mjs";
|
|
44
44
|
import { useRenderCount as Fe } from "./hooks/useRenderCount/useRenderCount.mjs";
|
|
45
45
|
import { useRenderInfo as Ve } from "./hooks/useRenderInfo/useRenderInfo.mjs";
|
|
46
|
-
import { useRerender as
|
|
46
|
+
import { useRerender as He } from "./hooks/useRerender/useRerender.mjs";
|
|
47
47
|
import { useActiveElement as ze } from "./hooks/useActiveElement/useActiveElement.mjs";
|
|
48
48
|
import { useAutoScroll as Qe } from "./hooks/useAutoScroll/useAutoScroll.mjs";
|
|
49
49
|
import { useClickOutside as qe } from "./hooks/useClickOutside/useClickOutside.mjs";
|
|
@@ -67,7 +67,7 @@ import { useOnce as Mo } from "./hooks/useOnce/useOnce.mjs";
|
|
|
67
67
|
import { useAsyncEffect as Bo } from "./hooks/useAsyncEffect/useAsyncEffect.mjs";
|
|
68
68
|
import { useDidUpdate as Fo } from "./hooks/useDidUpdate/useDidUpdate.mjs";
|
|
69
69
|
import { useIsFirstRender as Vo } from "./hooks/useIsFirstRender/useIsFirstRender.mjs";
|
|
70
|
-
import { useIsomorphicLayoutEffect as
|
|
70
|
+
import { useIsomorphicLayoutEffect as Ho } from "./hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.mjs";
|
|
71
71
|
import { useMount as zo } from "./hooks/useMount/useMount.mjs";
|
|
72
72
|
import { deepEqual as Qo, useShallowEffect as Xo } from "./hooks/useShallowEffect/useShallowEffect.mjs";
|
|
73
73
|
import { useUnmount as Zo } from "./hooks/useUnmount/useUnmount.mjs";
|
|
@@ -88,7 +88,7 @@ import { useKeyPress as Lr } from "./hooks/useKeyPress/useKeyPress.mjs";
|
|
|
88
88
|
import { useKeyPressEvent as Nr } from "./hooks/useKeyPressEvent/useKeyPressEvent.mjs";
|
|
89
89
|
import { useKeysPressed as Kr } from "./hooks/useKeysPressed/useKeysPressed.mjs";
|
|
90
90
|
import { useLockScroll as Ur } from "./hooks/useLockScroll/useLockScroll.mjs";
|
|
91
|
-
import { useMeasure as
|
|
91
|
+
import { useMeasure as wr } from "./hooks/useMeasure/useMeasure.mjs";
|
|
92
92
|
import { useMediaQuery as Wr } from "./hooks/useMediaQuery/useMediaQuery.mjs";
|
|
93
93
|
import { useMouse as Gr } from "./hooks/useMouse/useMouse.mjs";
|
|
94
94
|
import { useMutationObserver as Xr } from "./hooks/useMutationObserver/useMutationObserver.mjs";
|
|
@@ -110,7 +110,7 @@ import { useBoolean as yt } from "./hooks/useBoolean/useBoolean.mjs";
|
|
|
110
110
|
import { useControllableState as kt } from "./hooks/useControllableState/useControllableState.mjs";
|
|
111
111
|
import { COOKIE_EVENT as vt, dispatchCookieEvent as _t, getCookie as bt, getCookies as Dt, removeCookie as Lt, removeCookieItem as Mt, setCookie as Nt, setCookieItem as Bt, useCookie as Kt } from "./hooks/useCookie/useCookie.mjs";
|
|
112
112
|
import { clearCookies as Ut, useCookies as Vt } from "./hooks/useCookies/useCookies.mjs";
|
|
113
|
-
import { useCounter as
|
|
113
|
+
import { useCounter as Ht } from "./hooks/useCounter/useCounter.mjs";
|
|
114
114
|
import { useDefault as zt } from "./hooks/useDefault/useDefault.mjs";
|
|
115
115
|
import { useDisclosure as Qt } from "./hooks/useDisclosure/useDisclosure.mjs";
|
|
116
116
|
import { useField as qt } from "./hooks/useField/useField.mjs";
|
|
@@ -131,7 +131,7 @@ import { STORAGE_EVENT as ks, dispatchStorageEvent as hs, useStorage as vs } fro
|
|
|
131
131
|
import { useToggle as bs } from "./hooks/useToggle/useToggle.mjs";
|
|
132
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
133
|
import { useUrlSearchParams as Us } from "./hooks/useUrlSearchParams/useUrlSearchParams.mjs";
|
|
134
|
-
import { useWizard as
|
|
134
|
+
import { useWizard as ws } from "./hooks/useWizard/useWizard.mjs";
|
|
135
135
|
import { useInterval as Ws } from "./hooks/useInterval/useInterval.mjs";
|
|
136
136
|
import { useStopwatch as Gs } from "./hooks/useStopwatch/useStopwatch.mjs";
|
|
137
137
|
import { useTime as Xs } from "./hooks/useTime/useTime.mjs";
|
|
@@ -157,11 +157,11 @@ import { useThrottleCallback as Lu } from "./hooks/useThrottleCallback/useThrott
|
|
|
157
157
|
import { useThrottleState as Nu } from "./hooks/useThrottleState/useThrottleState.mjs";
|
|
158
158
|
import { useThrottleValue as Ku } from "./hooks/useThrottleValue/useThrottleValue.mjs";
|
|
159
159
|
import { copy as Uu, legacyCopyToClipboard as Vu } from "./utils/helpers/copy.mjs";
|
|
160
|
-
import { debounce as
|
|
160
|
+
import { debounce as Hu } from "./utils/helpers/debounce.mjs";
|
|
161
161
|
import { getDate as zu } from "./utils/helpers/getDate.mjs";
|
|
162
162
|
import { getRetry as Qu } from "./utils/helpers/getRetry.mjs";
|
|
163
|
-
import {
|
|
164
|
-
import { throttle as
|
|
163
|
+
import { getRawElement as qu, getRefState as Zu, isBrowserTarget as ju, isRef as Ju, isRefState as Yu, isTarget as $u, target as em, targetSymbol as om } from "./utils/helpers/isTarget.mjs";
|
|
164
|
+
import { throttle as tm } from "./utils/helpers/throttle.mjs";
|
|
165
165
|
export {
|
|
166
166
|
Jo as BREAKPOINTS_ANT_DESIGN,
|
|
167
167
|
Yo as BREAKPOINTS_BOOTSTRAP_V5,
|
|
@@ -189,7 +189,7 @@ export {
|
|
|
189
189
|
m as createReactiveContext,
|
|
190
190
|
Ss as createRefState,
|
|
191
191
|
f as createStore,
|
|
192
|
-
|
|
192
|
+
Hu as debounce,
|
|
193
193
|
Qo as deepEqual,
|
|
194
194
|
_t as dispatchCookieEvent,
|
|
195
195
|
hs as dispatchStorageEvent,
|
|
@@ -201,13 +201,17 @@ export {
|
|
|
201
201
|
jt as getHash,
|
|
202
202
|
ru as getOperatingSystem,
|
|
203
203
|
it as getRangesSelection,
|
|
204
|
-
qu as
|
|
204
|
+
qu as getRawElement,
|
|
205
|
+
Zu as getRefState,
|
|
205
206
|
Qu as getRetry,
|
|
206
207
|
Ae as getSpeechRecognition,
|
|
207
208
|
Js as getTimeFromSeconds,
|
|
208
209
|
Bs as getUrlSearchParams,
|
|
210
|
+
ju as isBrowserTarget,
|
|
209
211
|
Pr as isHotkeyMatch,
|
|
210
|
-
|
|
212
|
+
Ju as isRef,
|
|
213
|
+
Yu as isRefState,
|
|
214
|
+
$u as isTarget,
|
|
211
215
|
Vu as legacyCopyToClipboard,
|
|
212
216
|
q as mapGamepadToXbox360Controller,
|
|
213
217
|
ms as mergeRefs,
|
|
@@ -217,9 +221,9 @@ export {
|
|
|
217
221
|
Nt as setCookie,
|
|
218
222
|
Bt as setCookieItem,
|
|
219
223
|
Ps as stateHistoryReducer,
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
224
|
+
em as target,
|
|
225
|
+
om as targetSymbol,
|
|
226
|
+
tm as throttle,
|
|
223
227
|
$ as timeRangeToArray,
|
|
224
228
|
ze as useActiveElement,
|
|
225
229
|
a as useAsync,
|
|
@@ -240,7 +244,7 @@ export {
|
|
|
240
244
|
Kt as useCookie,
|
|
241
245
|
Vt as useCookies,
|
|
242
246
|
_ as useCopy,
|
|
243
|
-
|
|
247
|
+
Ht as useCounter,
|
|
244
248
|
D as useCssVar,
|
|
245
249
|
Ru as useDebounceCallback,
|
|
246
250
|
Cu as useDebounceState,
|
|
@@ -262,7 +266,7 @@ export {
|
|
|
262
266
|
dr as useEventListener,
|
|
263
267
|
F as useEventSource,
|
|
264
268
|
V as useEyeDropper,
|
|
265
|
-
|
|
269
|
+
H as useFavicon,
|
|
266
270
|
qt as useField,
|
|
267
271
|
oo as useFileDialog,
|
|
268
272
|
to as useFocus,
|
|
@@ -281,7 +285,7 @@ export {
|
|
|
281
285
|
vr as useIntersectionObserver,
|
|
282
286
|
Ws as useInterval,
|
|
283
287
|
Vo as useIsFirstRender,
|
|
284
|
-
|
|
288
|
+
Ho as useIsomorphicLayoutEffect,
|
|
285
289
|
Lr as useKeyPress,
|
|
286
290
|
Nr as useKeyPressEvent,
|
|
287
291
|
br as useKeyboard,
|
|
@@ -296,7 +300,7 @@ export {
|
|
|
296
300
|
Be as useLogger,
|
|
297
301
|
no as useLongPress,
|
|
298
302
|
ts as useMap,
|
|
299
|
-
|
|
303
|
+
wr as useMeasure,
|
|
300
304
|
ee as useMediaControls,
|
|
301
305
|
Wr as useMediaQuery,
|
|
302
306
|
re as useMemory,
|
|
@@ -334,7 +338,7 @@ export {
|
|
|
334
338
|
Es as useRefState,
|
|
335
339
|
Fe as useRenderCount,
|
|
336
340
|
Ve as useRenderInfo,
|
|
337
|
-
|
|
341
|
+
He as useRerender,
|
|
338
342
|
tt as useResizeObserver,
|
|
339
343
|
go as useRightClick,
|
|
340
344
|
Po as useScript,
|
|
@@ -374,6 +378,6 @@ export {
|
|
|
374
378
|
gt as useWindowFocus,
|
|
375
379
|
Ct as useWindowScroll,
|
|
376
380
|
At as useWindowSize,
|
|
377
|
-
|
|
381
|
+
ws as useWizard
|
|
378
382
|
};
|
|
379
383
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,14 +1,19 @@
|
|
|
1
|
-
const u = /* @__PURE__ */ Symbol("target"),
|
|
1
|
+
const u = /* @__PURE__ */ Symbol("target"), c = (e) => ({
|
|
2
2
|
value: e,
|
|
3
3
|
type: u
|
|
4
|
-
}),
|
|
5
|
-
n.wrap =
|
|
6
|
-
n.getElement =
|
|
7
|
-
n.getRefState =
|
|
4
|
+
}), f = (e) => typeof e == "object" && "current" in e, o = (e) => typeof e == "function" && "state" in e && "current" in e, i = (e) => typeof e == "object" && e && "type" in e && e.type === u && "value" in e, n = (e) => f(e) || o(e) || i(e), l = (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), s = (e) => e && "state" in e && e.state, t = (e) => o(e) ? e.state : i(e) ? e.value : e;
|
|
5
|
+
n.wrap = c;
|
|
6
|
+
n.getElement = l;
|
|
7
|
+
n.getRefState = s;
|
|
8
|
+
n.getRawElement = t;
|
|
8
9
|
export {
|
|
9
|
-
|
|
10
|
+
t as getRawElement,
|
|
11
|
+
s as getRefState,
|
|
12
|
+
i as isBrowserTarget,
|
|
13
|
+
f as isRef,
|
|
14
|
+
o as isRefState,
|
|
10
15
|
n as isTarget,
|
|
11
|
-
|
|
16
|
+
c as target,
|
|
12
17
|
u as targetSymbol
|
|
13
18
|
};
|
|
14
19
|
//# 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;\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
|
|
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 BrowserTarget {\n type: symbol;\n value: Target;\n}\ninterface StateRef<Value> {\n (node: Value): void;\n current: Value;\n state: Value;\n}\n\nexport type HookTarget =\n | BrowserTarget\n | RefObject<Element | null | undefined>\n | StateRef<Element | null | undefined>;\n\nexport const target = (target: Target) => ({\n value: target,\n type: targetSymbol\n});\n\nexport const isRef = (target: HookTarget) => typeof target === 'object' && 'current' in target;\n\nexport const isRefState = (target: HookTarget) =>\n typeof target === 'function' && 'state' in target && 'current' in target;\n\nexport const isBrowserTarget = (target: HookTarget) =>\n typeof target === 'object' &&\n target &&\n 'type' in target &&\n target.type === targetSymbol &&\n 'value' in target;\n\nexport const isTarget = (target: HookTarget) =>\n isRef(target) || isRefState(target) || isBrowserTarget(target);\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};\nexport const getRefState = (target?: HookTarget) => target && 'state' in target && target.state;\nexport const getRawElement = (target: HookTarget) => {\n if (isRefState(target)) return target.state;\n if (isBrowserTarget(target)) return (target as BrowserTarget).value;\n\n return target;\n};\n\nisTarget.wrap = target;\nisTarget.getElement = getElement;\nisTarget.getRefState = getRefState;\nisTarget.getRawElement = getRawElement;\n"],"names":["targetSymbol","target","isRef","isRefState","isBrowserTarget","isTarget","getElement","getRefState","getRawElement"],"mappings":"AAEO,MAAMA,2BAAsB,QAAQ,GAkB9BC,IAAS,CAACA,OAAoB;AAAA,EACzC,OAAOA;AAAAA,EACP,MAAMD;AACR,IAEaE,IAAQ,CAACD,MAAuB,OAAOA,KAAW,YAAY,aAAaA,GAE3EE,IAAa,CAACF,MACzB,OAAOA,KAAW,cAAc,WAAWA,KAAU,aAAaA,GAEvDG,IAAkB,CAACH,MAC9B,OAAOA,KAAW,YAClBA,KACA,UAAUA,KACVA,EAAO,SAASD,KAChB,WAAWC,GAEAI,IAAW,CAACJ,MACvBC,EAAMD,CAAM,KAAKE,EAAWF,CAAM,KAAKG,EAAgBH,CAAM,GAEzDK,IAAa,CAACL,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,QAKLM,IAAc,CAACN,MAAwBA,KAAU,WAAWA,KAAUA,EAAO,OAC7EO,IAAgB,CAACP,MACxBE,EAAWF,CAAM,IAAUA,EAAO,QAClCG,EAAgBH,CAAM,IAAWA,EAAyB,QAEvDA;AAGTI,EAAS,OAAOJ;AAChBI,EAAS,aAAaC;AACtBD,EAAS,cAAcE;AACvBF,EAAS,gBAAgBG;"}
|
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
import { RefObject } from 'react';
|
|
2
2
|
export declare const targetSymbol: unique symbol;
|
|
3
3
|
export type Target = (() => Element) | string | Document | Element | Window;
|
|
4
|
+
interface BrowserTarget {
|
|
5
|
+
type: symbol;
|
|
6
|
+
value: Target;
|
|
7
|
+
}
|
|
4
8
|
interface StateRef<Value> {
|
|
5
9
|
(node: Value): void;
|
|
6
10
|
current: Value;
|
|
7
11
|
state: Value;
|
|
8
12
|
}
|
|
9
|
-
export type HookTarget = RefObject<Element | null | undefined> | StateRef<Element | null | undefined
|
|
10
|
-
value: Target;
|
|
11
|
-
type: symbol;
|
|
12
|
-
};
|
|
13
|
+
export type HookTarget = BrowserTarget | RefObject<Element | null | undefined> | StateRef<Element | null | undefined>;
|
|
13
14
|
export declare const target: (target: Target) => {
|
|
14
15
|
value: Target;
|
|
15
16
|
type: symbol;
|
|
16
17
|
};
|
|
18
|
+
export declare const isRef: (target: HookTarget) => target is RefObject<Element | null | undefined>;
|
|
19
|
+
export declare const isRefState: (target: HookTarget) => target is StateRef<Element | null | undefined>;
|
|
20
|
+
export declare const isBrowserTarget: (target: HookTarget) => boolean;
|
|
17
21
|
export declare const isTarget: {
|
|
18
22
|
(target: HookTarget): boolean;
|
|
19
23
|
wrap: (target: Target) => {
|
|
@@ -22,6 +26,8 @@ export declare const isTarget: {
|
|
|
22
26
|
};
|
|
23
27
|
getElement: (target: HookTarget) => Window | Document | Element | null | undefined;
|
|
24
28
|
getRefState: (target?: HookTarget) => false | Element | null | undefined;
|
|
29
|
+
getRawElement: (target: HookTarget) => Target | BrowserTarget | RefObject<Element | null | undefined> | null | undefined;
|
|
25
30
|
};
|
|
26
31
|
export declare const getRefState: (target?: HookTarget) => false | Element | null | undefined;
|
|
32
|
+
export declare const getRawElement: (target: HookTarget) => Target | BrowserTarget | RefObject<Element | null | undefined> | null | undefined;
|
|
27
33
|
export {};
|