@siberiacancode/reactuse 0.3.2 → 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/useAudio/useAudio.cjs +1 -1
- package/dist/cjs/hooks/useAudio/useAudio.cjs.map +1 -1
- package/dist/cjs/hooks/useAutoScroll/useAutoScroll.cjs +1 -1
- package/dist/cjs/hooks/useAutoScroll/useAutoScroll.cjs.map +1 -1
- package/dist/cjs/hooks/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 +2 -0
- package/dist/cjs/hooks/useTextareaAutosize/useTextareaAutosize.cjs.map +1 -0
- 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/useAudio/useAudio.mjs +29 -23
- package/dist/esm/hooks/useAudio/useAudio.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 +58 -0
- package/dist/esm/hooks/useTextareaAutosize/useTextareaAutosize.mjs.map +1 -0
- 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 +255 -251
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/utils/helpers/isTarget.mjs +10 -8
- package/dist/esm/utils/helpers/isTarget.mjs.map +1 -1
- package/dist/types/hooks/elements.d.ts +1 -0
- 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/hooks/useTextareaAutosize/useTextareaAutosize.d.ts +60 -0
- package/dist/types/utils/helpers/isTarget.d.ts +9 -1
- package/package.json +12 -12
|
@@ -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;"}
|
|
@@ -13,4 +13,5 @@ export * from './usePaint/usePaint';
|
|
|
13
13
|
export * from './useRightClick/useRightClick';
|
|
14
14
|
export * from './useScript/useScript';
|
|
15
15
|
export * from './useSticky/useSticky';
|
|
16
|
+
export * from './useTextareaAutosize/useTextareaAutosize';
|
|
16
17
|
export * from './useTextDirection/useTextDirection';
|
|
@@ -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
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { HookTarget } from '../../utils/helpers';
|
|
2
|
+
import { StateRef } from '../useRefState/useRefState';
|
|
3
|
+
/** The use textarea autosize options */
|
|
4
|
+
export interface UseTextareaAutosizeOptions {
|
|
5
|
+
/** The initial value for the textarea */
|
|
6
|
+
initialValue?: string;
|
|
7
|
+
/** Callback function called when the textarea size changes */
|
|
8
|
+
onResize?: () => void;
|
|
9
|
+
}
|
|
10
|
+
/** The use textarea autosize return type */
|
|
11
|
+
export interface UseTextareaAutosizeReturn {
|
|
12
|
+
/** The current value of the textarea */
|
|
13
|
+
value: string;
|
|
14
|
+
/** Function to clear the textarea value */
|
|
15
|
+
clear: () => void;
|
|
16
|
+
/** Function to set the textarea value */
|
|
17
|
+
setValue: (value: string) => void;
|
|
18
|
+
}
|
|
19
|
+
export interface UseTextareaAutosize {
|
|
20
|
+
(target: HookTarget, options?: UseTextareaAutosizeOptions): UseTextareaAutosizeReturn;
|
|
21
|
+
<Target extends HTMLTextAreaElement = HTMLTextAreaElement>(initialValue: string, target?: never): UseTextareaAutosizeReturn & {
|
|
22
|
+
ref: StateRef<Target>;
|
|
23
|
+
};
|
|
24
|
+
<Target extends HTMLTextAreaElement = HTMLTextAreaElement>(options?: UseTextareaAutosizeOptions, target?: never): UseTextareaAutosizeReturn & {
|
|
25
|
+
ref: StateRef<Target>;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @name useTextareaAutosize
|
|
30
|
+
* @description - Hook that automatically adjusts textarea height based on content
|
|
31
|
+
* @category Elements
|
|
32
|
+
* @usage medium
|
|
33
|
+
*
|
|
34
|
+
* @overload
|
|
35
|
+
* @param {HookTarget} target The target textarea element
|
|
36
|
+
* @param {string} [options.initialValue] The initial value for the textarea
|
|
37
|
+
* @param {Function} [options.onResize] Callback function called when the textarea size changes
|
|
38
|
+
* @returns {UseTextareaAutosizeReturn} An object containing value, setValue and clear
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* const { value, setValue, clear } = useTextareaAutosize(ref);
|
|
42
|
+
*
|
|
43
|
+
* @overload
|
|
44
|
+
* @template Target The textarea element type
|
|
45
|
+
* @param {string} initialValue The initial value for the textarea
|
|
46
|
+
* @returns {UseTextareaAutosizeReturn & { ref: StateRef<Target> }} An object containing ref, value, setValue and clear
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* const { ref, value, setValue, clear } = useTextareaAutosize('initial');
|
|
50
|
+
*
|
|
51
|
+
* @overload
|
|
52
|
+
* @template Target The textarea element type
|
|
53
|
+
* @param {string} [options.initialValue] The initial value for the textarea
|
|
54
|
+
* @param {Function} [options.onResize] Callback function called when the textarea size changes
|
|
55
|
+
* @returns {UseTextareaAutosizeReturn & { ref: StateRef<Target> }} An object containing ref, value, setValue and clear
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* const { ref, value, setValue, clear } = useTextareaAutosize();
|
|
59
|
+
*/
|
|
60
|
+
export declare const useTextareaAutosize: UseTextareaAutosize;
|
|
@@ -1,7 +1,12 @@
|
|
|
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
|
-
|
|
4
|
+
interface StateRef<Value> {
|
|
5
|
+
(node: Value): void;
|
|
6
|
+
current: Value;
|
|
7
|
+
state: Value;
|
|
8
|
+
}
|
|
9
|
+
export type HookTarget = RefObject<Element | null | undefined> | StateRef<Element | null | undefined> | {
|
|
5
10
|
value: Target;
|
|
6
11
|
type: symbol;
|
|
7
12
|
};
|
|
@@ -16,4 +21,7 @@ export declare const isTarget: {
|
|
|
16
21
|
type: symbol;
|
|
17
22
|
};
|
|
18
23
|
getElement: (target: HookTarget) => Window | Document | Element | null | undefined;
|
|
24
|
+
getRefState: (target?: HookTarget) => false | Element | null | undefined;
|
|
19
25
|
};
|
|
26
|
+
export declare const getRefState: (target?: HookTarget) => false | Element | null | undefined;
|
|
27
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@siberiacancode/reactuse",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "The ultimate collection of react hooks",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "SIBERIA CAN CODE 🧊",
|
|
@@ -64,21 +64,21 @@
|
|
|
64
64
|
"screenfull": "^6.0.2"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@siberiacancode/vitest": "^2.
|
|
67
|
+
"@siberiacancode/vitest": "^2.3.0",
|
|
68
68
|
"@testing-library/dom": "^10.4.1",
|
|
69
|
-
"@testing-library/react": "^16.3.
|
|
70
|
-
"@types/dom-speech-recognition": "^0.0.
|
|
71
|
-
"@types/react": "^19.
|
|
72
|
-
"@types/react-dom": "^19.
|
|
69
|
+
"@testing-library/react": "^16.3.1",
|
|
70
|
+
"@types/dom-speech-recognition": "^0.0.7",
|
|
71
|
+
"@types/react": "^19.2.7",
|
|
72
|
+
"@types/react-dom": "^19.2.3",
|
|
73
73
|
"@types/web-bluetooth": "^0.0.21",
|
|
74
|
-
"@vitejs/plugin-react": "^5.
|
|
75
|
-
"core-js": "^3.
|
|
76
|
-
"react": "^19.
|
|
77
|
-
"react-dom": "^19.
|
|
74
|
+
"@vitejs/plugin-react": "^5.1.2",
|
|
75
|
+
"core-js": "^3.47.0",
|
|
76
|
+
"react": "^19.2.3",
|
|
77
|
+
"react-dom": "^19.2.3",
|
|
78
78
|
"shx": "^0.4.0",
|
|
79
|
-
"vite": "^7.
|
|
79
|
+
"vite": "^7.3.0",
|
|
80
80
|
"vite-plugin-dts": "^4.5.4",
|
|
81
|
-
"vitest": "^
|
|
81
|
+
"vitest": "^4.0.16"
|
|
82
82
|
},
|
|
83
83
|
"lint-staged": {
|
|
84
84
|
"*.{js,ts,tsx}": [
|