@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.
Files changed (227) hide show
  1. package/dist/cjs/hooks/useActiveElement/useActiveElement.cjs +1 -1
  2. package/dist/cjs/hooks/useActiveElement/useActiveElement.cjs.map +1 -1
  3. package/dist/cjs/hooks/useAudio/useAudio.cjs +1 -1
  4. package/dist/cjs/hooks/useAudio/useAudio.cjs.map +1 -1
  5. package/dist/cjs/hooks/useAutoScroll/useAutoScroll.cjs +1 -1
  6. package/dist/cjs/hooks/useAutoScroll/useAutoScroll.cjs.map +1 -1
  7. package/dist/cjs/hooks/useBreakpoints/useBreakpoints.cjs +1 -1
  8. package/dist/cjs/hooks/useBreakpoints/useBreakpoints.cjs.map +1 -1
  9. package/dist/cjs/hooks/useClickOutside/useClickOutside.cjs +1 -1
  10. package/dist/cjs/hooks/useClickOutside/useClickOutside.cjs.map +1 -1
  11. package/dist/cjs/hooks/useCookie/useCookie.cjs +1 -1
  12. package/dist/cjs/hooks/useCookie/useCookie.cjs.map +1 -1
  13. package/dist/cjs/hooks/useCounter/useCounter.cjs +1 -1
  14. package/dist/cjs/hooks/useCounter/useCounter.cjs.map +1 -1
  15. package/dist/cjs/hooks/useCssVar/useCssVar.cjs +1 -1
  16. package/dist/cjs/hooks/useCssVar/useCssVar.cjs.map +1 -1
  17. package/dist/cjs/hooks/useDeviceMotion/useDeviceMotion.cjs +1 -1
  18. package/dist/cjs/hooks/useDeviceMotion/useDeviceMotion.cjs.map +1 -1
  19. package/dist/cjs/hooks/useDisplayMedia/useDisplayMedia.cjs +1 -1
  20. package/dist/cjs/hooks/useDisplayMedia/useDisplayMedia.cjs.map +1 -1
  21. package/dist/cjs/hooks/useDoubleClick/useDoubleClick.cjs +1 -1
  22. package/dist/cjs/hooks/useDoubleClick/useDoubleClick.cjs.map +1 -1
  23. package/dist/cjs/hooks/useDropZone/useDropZone.cjs +1 -1
  24. package/dist/cjs/hooks/useDropZone/useDropZone.cjs.map +1 -1
  25. package/dist/cjs/hooks/useElementSize/useElementSize.cjs +1 -1
  26. package/dist/cjs/hooks/useElementSize/useElementSize.cjs.map +1 -1
  27. package/dist/cjs/hooks/useEventListener/useEventListener.cjs +1 -1
  28. package/dist/cjs/hooks/useEventListener/useEventListener.cjs.map +1 -1
  29. package/dist/cjs/hooks/useFileDialog/useFileDialog.cjs +1 -1
  30. package/dist/cjs/hooks/useFileDialog/useFileDialog.cjs.map +1 -1
  31. package/dist/cjs/hooks/useFocus/useFocus.cjs +1 -1
  32. package/dist/cjs/hooks/useFocus/useFocus.cjs.map +1 -1
  33. package/dist/cjs/hooks/useFocusTrap/useFocusTrap.cjs +1 -1
  34. package/dist/cjs/hooks/useFocusTrap/useFocusTrap.cjs.map +1 -1
  35. package/dist/cjs/hooks/useFullscreen/useFullscreen.cjs +1 -1
  36. package/dist/cjs/hooks/useFullscreen/useFullscreen.cjs.map +1 -1
  37. package/dist/cjs/hooks/useHash/useHash.cjs +1 -1
  38. package/dist/cjs/hooks/useHash/useHash.cjs.map +1 -1
  39. package/dist/cjs/hooks/useHotkeys/useHotkeys.cjs +1 -1
  40. package/dist/cjs/hooks/useHotkeys/useHotkeys.cjs.map +1 -1
  41. package/dist/cjs/hooks/useHover/useHover.cjs +1 -1
  42. package/dist/cjs/hooks/useHover/useHover.cjs.map +1 -1
  43. package/dist/cjs/hooks/useInfiniteScroll/useInfiniteScroll.cjs +1 -1
  44. package/dist/cjs/hooks/useInfiniteScroll/useInfiniteScroll.cjs.map +1 -1
  45. package/dist/cjs/hooks/useIntersectionObserver/useIntersectionObserver.cjs +1 -1
  46. package/dist/cjs/hooks/useIntersectionObserver/useIntersectionObserver.cjs.map +1 -1
  47. package/dist/cjs/hooks/useInterval/useInterval.cjs +1 -1
  48. package/dist/cjs/hooks/useInterval/useInterval.cjs.map +1 -1
  49. package/dist/cjs/hooks/useKeyPress/useKeyPress.cjs +1 -1
  50. package/dist/cjs/hooks/useKeyPress/useKeyPress.cjs.map +1 -1
  51. package/dist/cjs/hooks/useKeyPressEvent/useKeyPressEvent.cjs +1 -1
  52. package/dist/cjs/hooks/useKeyPressEvent/useKeyPressEvent.cjs.map +1 -1
  53. package/dist/cjs/hooks/useKeyboard/useKeyboard.cjs +1 -1
  54. package/dist/cjs/hooks/useKeyboard/useKeyboard.cjs.map +1 -1
  55. package/dist/cjs/hooks/useKeysPressed/useKeysPressed.cjs +1 -1
  56. package/dist/cjs/hooks/useKeysPressed/useKeysPressed.cjs.map +1 -1
  57. package/dist/cjs/hooks/useLockScroll/useLockScroll.cjs +1 -1
  58. package/dist/cjs/hooks/useLockScroll/useLockScroll.cjs.map +1 -1
  59. package/dist/cjs/hooks/useLongPress/useLongPress.cjs +1 -1
  60. package/dist/cjs/hooks/useLongPress/useLongPress.cjs.map +1 -1
  61. package/dist/cjs/hooks/useMeasure/useMeasure.cjs +1 -1
  62. package/dist/cjs/hooks/useMeasure/useMeasure.cjs.map +1 -1
  63. package/dist/cjs/hooks/useMediaControls/useMediaControls.cjs +1 -1
  64. package/dist/cjs/hooks/useMediaControls/useMediaControls.cjs.map +1 -1
  65. package/dist/cjs/hooks/useMouse/useMouse.cjs +1 -1
  66. package/dist/cjs/hooks/useMouse/useMouse.cjs.map +1 -1
  67. package/dist/cjs/hooks/useMutationObserver/useMutationObserver.cjs +1 -1
  68. package/dist/cjs/hooks/useMutationObserver/useMutationObserver.cjs.map +1 -1
  69. package/dist/cjs/hooks/useOtpCredential/useOtpCredential.cjs +1 -1
  70. package/dist/cjs/hooks/useOtpCredential/useOtpCredential.cjs.map +1 -1
  71. package/dist/cjs/hooks/usePaint/usePaint.cjs +1 -1
  72. package/dist/cjs/hooks/usePaint/usePaint.cjs.map +1 -1
  73. package/dist/cjs/hooks/useParallax/useParallax.cjs +1 -1
  74. package/dist/cjs/hooks/useParallax/useParallax.cjs.map +1 -1
  75. package/dist/cjs/hooks/usePictureInPicture/usePictureInPicture.cjs +1 -1
  76. package/dist/cjs/hooks/usePictureInPicture/usePictureInPicture.cjs.map +1 -1
  77. package/dist/cjs/hooks/useRefState/useRefState.cjs +1 -1
  78. package/dist/cjs/hooks/useRefState/useRefState.cjs.map +1 -1
  79. package/dist/cjs/hooks/useResizeObserver/useResizeObserver.cjs +1 -1
  80. package/dist/cjs/hooks/useResizeObserver/useResizeObserver.cjs.map +1 -1
  81. package/dist/cjs/hooks/useRightClick/useRightClick.cjs +1 -1
  82. package/dist/cjs/hooks/useRightClick/useRightClick.cjs.map +1 -1
  83. package/dist/cjs/hooks/useScroll/useScroll.cjs +1 -1
  84. package/dist/cjs/hooks/useScroll/useScroll.cjs.map +1 -1
  85. package/dist/cjs/hooks/useScrollIntoView/useScrollIntoView.cjs +1 -1
  86. package/dist/cjs/hooks/useScrollIntoView/useScrollIntoView.cjs.map +1 -1
  87. package/dist/cjs/hooks/useScrollTo/useScrollTo.cjs +1 -1
  88. package/dist/cjs/hooks/useScrollTo/useScrollTo.cjs.map +1 -1
  89. package/dist/cjs/hooks/useSticky/useSticky.cjs +1 -1
  90. package/dist/cjs/hooks/useSticky/useSticky.cjs.map +1 -1
  91. package/dist/cjs/hooks/useStopwatch/useStopwatch.cjs +1 -1
  92. package/dist/cjs/hooks/useStopwatch/useStopwatch.cjs.map +1 -1
  93. package/dist/cjs/hooks/useStorage/useStorage.cjs +1 -1
  94. package/dist/cjs/hooks/useStorage/useStorage.cjs.map +1 -1
  95. package/dist/cjs/hooks/useTextDirection/useTextDirection.cjs +1 -1
  96. package/dist/cjs/hooks/useTextDirection/useTextDirection.cjs.map +1 -1
  97. package/dist/cjs/hooks/useTextareaAutosize/useTextareaAutosize.cjs +2 -0
  98. package/dist/cjs/hooks/useTextareaAutosize/useTextareaAutosize.cjs.map +1 -0
  99. package/dist/cjs/hooks/useTimer/useTimer.cjs +1 -1
  100. package/dist/cjs/hooks/useTimer/useTimer.cjs.map +1 -1
  101. package/dist/cjs/hooks/useUrlSearchParam/useUrlSearchParam.cjs +1 -1
  102. package/dist/cjs/hooks/useUrlSearchParam/useUrlSearchParam.cjs.map +1 -1
  103. package/dist/cjs/hooks/useUrlSearchParams/useUrlSearchParams.cjs +1 -1
  104. package/dist/cjs/hooks/useUrlSearchParams/useUrlSearchParams.cjs.map +1 -1
  105. package/dist/cjs/hooks/useVisibility/useVisibility.cjs +1 -1
  106. package/dist/cjs/hooks/useVisibility/useVisibility.cjs.map +1 -1
  107. package/dist/cjs/index.cjs +1 -1
  108. package/dist/cjs/utils/helpers/isTarget.cjs +1 -1
  109. package/dist/cjs/utils/helpers/isTarget.cjs.map +1 -1
  110. package/dist/esm/hooks/useActiveElement/useActiveElement.mjs +13 -13
  111. package/dist/esm/hooks/useActiveElement/useActiveElement.mjs.map +1 -1
  112. package/dist/esm/hooks/useAudio/useAudio.mjs +29 -23
  113. package/dist/esm/hooks/useAudio/useAudio.mjs.map +1 -1
  114. package/dist/esm/hooks/useAutoScroll/useAutoScroll.mjs +24 -24
  115. package/dist/esm/hooks/useAutoScroll/useAutoScroll.mjs.map +1 -1
  116. package/dist/esm/hooks/useBreakpoints/useBreakpoints.mjs +30 -35
  117. package/dist/esm/hooks/useBreakpoints/useBreakpoints.mjs.map +1 -1
  118. package/dist/esm/hooks/useClickOutside/useClickOutside.mjs +15 -14
  119. package/dist/esm/hooks/useClickOutside/useClickOutside.mjs.map +1 -1
  120. package/dist/esm/hooks/useCookie/useCookie.mjs +2 -2
  121. package/dist/esm/hooks/useCookie/useCookie.mjs.map +1 -1
  122. package/dist/esm/hooks/useCounter/useCounter.mjs +2 -2
  123. package/dist/esm/hooks/useCounter/useCounter.mjs.map +1 -1
  124. package/dist/esm/hooks/useCssVar/useCssVar.mjs +8 -8
  125. package/dist/esm/hooks/useCssVar/useCssVar.mjs.map +1 -1
  126. package/dist/esm/hooks/useDeviceMotion/useDeviceMotion.mjs +2 -2
  127. package/dist/esm/hooks/useDeviceMotion/useDeviceMotion.mjs.map +1 -1
  128. package/dist/esm/hooks/useDisplayMedia/useDisplayMedia.mjs +17 -17
  129. package/dist/esm/hooks/useDisplayMedia/useDisplayMedia.mjs.map +1 -1
  130. package/dist/esm/hooks/useDoubleClick/useDoubleClick.mjs +14 -14
  131. package/dist/esm/hooks/useDoubleClick/useDoubleClick.mjs.map +1 -1
  132. package/dist/esm/hooks/useDropZone/useDropZone.mjs +23 -23
  133. package/dist/esm/hooks/useDropZone/useDropZone.mjs.map +1 -1
  134. package/dist/esm/hooks/useElementSize/useElementSize.mjs +14 -14
  135. package/dist/esm/hooks/useElementSize/useElementSize.mjs.map +1 -1
  136. package/dist/esm/hooks/useEventListener/useEventListener.mjs +14 -14
  137. package/dist/esm/hooks/useEventListener/useEventListener.mjs.map +1 -1
  138. package/dist/esm/hooks/useFileDialog/useFileDialog.mjs +2 -2
  139. package/dist/esm/hooks/useFileDialog/useFileDialog.mjs.map +1 -1
  140. package/dist/esm/hooks/useFocus/useFocus.mjs +20 -20
  141. package/dist/esm/hooks/useFocus/useFocus.mjs.map +1 -1
  142. package/dist/esm/hooks/useFocusTrap/useFocusTrap.mjs +21 -21
  143. package/dist/esm/hooks/useFocusTrap/useFocusTrap.mjs.map +1 -1
  144. package/dist/esm/hooks/useFullscreen/useFullscreen.mjs +2 -2
  145. package/dist/esm/hooks/useFullscreen/useFullscreen.mjs.map +1 -1
  146. package/dist/esm/hooks/useHash/useHash.mjs +2 -2
  147. package/dist/esm/hooks/useHash/useHash.mjs.map +1 -1
  148. package/dist/esm/hooks/useHotkeys/useHotkeys.mjs +24 -16
  149. package/dist/esm/hooks/useHotkeys/useHotkeys.mjs.map +1 -1
  150. package/dist/esm/hooks/useHover/useHover.mjs +16 -16
  151. package/dist/esm/hooks/useHover/useHover.mjs.map +1 -1
  152. package/dist/esm/hooks/useInfiniteScroll/useInfiniteScroll.mjs +16 -16
  153. package/dist/esm/hooks/useInfiniteScroll/useInfiniteScroll.mjs.map +1 -1
  154. package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs +26 -18
  155. package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs.map +1 -1
  156. package/dist/esm/hooks/useInterval/useInterval.mjs +2 -2
  157. package/dist/esm/hooks/useInterval/useInterval.mjs.map +1 -1
  158. package/dist/esm/hooks/useKeyPress/useKeyPress.mjs +15 -15
  159. package/dist/esm/hooks/useKeyPress/useKeyPress.mjs.map +1 -1
  160. package/dist/esm/hooks/useKeyPressEvent/useKeyPressEvent.mjs +22 -15
  161. package/dist/esm/hooks/useKeyPressEvent/useKeyPressEvent.mjs.map +1 -1
  162. package/dist/esm/hooks/useKeyboard/useKeyboard.mjs +10 -10
  163. package/dist/esm/hooks/useKeyboard/useKeyboard.mjs.map +1 -1
  164. package/dist/esm/hooks/useKeysPressed/useKeysPressed.mjs +12 -12
  165. package/dist/esm/hooks/useKeysPressed/useKeysPressed.mjs.map +1 -1
  166. package/dist/esm/hooks/useLockScroll/useLockScroll.mjs +23 -23
  167. package/dist/esm/hooks/useLockScroll/useLockScroll.mjs.map +1 -1
  168. package/dist/esm/hooks/useLongPress/useLongPress.mjs +16 -16
  169. package/dist/esm/hooks/useLongPress/useLongPress.mjs.map +1 -1
  170. package/dist/esm/hooks/useMeasure/useMeasure.mjs +15 -15
  171. package/dist/esm/hooks/useMeasure/useMeasure.mjs.map +1 -1
  172. package/dist/esm/hooks/useMediaControls/useMediaControls.mjs +28 -28
  173. package/dist/esm/hooks/useMediaControls/useMediaControls.mjs.map +1 -1
  174. package/dist/esm/hooks/useMouse/useMouse.mjs +17 -17
  175. package/dist/esm/hooks/useMouse/useMouse.mjs.map +1 -1
  176. package/dist/esm/hooks/useMutationObserver/useMutationObserver.mjs +17 -16
  177. package/dist/esm/hooks/useMutationObserver/useMutationObserver.mjs.map +1 -1
  178. package/dist/esm/hooks/useOtpCredential/useOtpCredential.mjs +2 -2
  179. package/dist/esm/hooks/useOtpCredential/useOtpCredential.mjs.map +1 -1
  180. package/dist/esm/hooks/usePaint/usePaint.mjs +31 -31
  181. package/dist/esm/hooks/usePaint/usePaint.mjs.map +1 -1
  182. package/dist/esm/hooks/useParallax/useParallax.mjs +24 -23
  183. package/dist/esm/hooks/useParallax/useParallax.mjs.map +1 -1
  184. package/dist/esm/hooks/usePictureInPicture/usePictureInPicture.mjs +25 -25
  185. package/dist/esm/hooks/usePictureInPicture/usePictureInPicture.mjs.map +1 -1
  186. package/dist/esm/hooks/useRefState/useRefState.mjs +1 -0
  187. package/dist/esm/hooks/useRefState/useRefState.mjs.map +1 -1
  188. package/dist/esm/hooks/useResizeObserver/useResizeObserver.mjs +16 -16
  189. package/dist/esm/hooks/useResizeObserver/useResizeObserver.mjs.map +1 -1
  190. package/dist/esm/hooks/useRightClick/useRightClick.mjs +14 -14
  191. package/dist/esm/hooks/useRightClick/useRightClick.mjs.map +1 -1
  192. package/dist/esm/hooks/useScroll/useScroll.mjs +22 -22
  193. package/dist/esm/hooks/useScroll/useScroll.mjs.map +1 -1
  194. package/dist/esm/hooks/useScrollIntoView/useScrollIntoView.mjs +16 -16
  195. package/dist/esm/hooks/useScrollIntoView/useScrollIntoView.mjs.map +1 -1
  196. package/dist/esm/hooks/useScrollTo/useScrollTo.mjs +10 -10
  197. package/dist/esm/hooks/useScrollTo/useScrollTo.mjs.map +1 -1
  198. package/dist/esm/hooks/useSticky/useSticky.mjs +17 -17
  199. package/dist/esm/hooks/useSticky/useSticky.mjs.map +1 -1
  200. package/dist/esm/hooks/useStopwatch/useStopwatch.mjs +4 -4
  201. package/dist/esm/hooks/useStopwatch/useStopwatch.mjs.map +1 -1
  202. package/dist/esm/hooks/useStorage/useStorage.mjs +2 -2
  203. package/dist/esm/hooks/useStorage/useStorage.mjs.map +1 -1
  204. package/dist/esm/hooks/useTextDirection/useTextDirection.mjs +12 -12
  205. package/dist/esm/hooks/useTextDirection/useTextDirection.mjs.map +1 -1
  206. package/dist/esm/hooks/useTextareaAutosize/useTextareaAutosize.mjs +58 -0
  207. package/dist/esm/hooks/useTextareaAutosize/useTextareaAutosize.mjs.map +1 -0
  208. package/dist/esm/hooks/useTimer/useTimer.mjs +3 -3
  209. package/dist/esm/hooks/useTimer/useTimer.mjs.map +1 -1
  210. package/dist/esm/hooks/useUrlSearchParam/useUrlSearchParam.mjs +2 -2
  211. package/dist/esm/hooks/useUrlSearchParam/useUrlSearchParam.mjs.map +1 -1
  212. package/dist/esm/hooks/useUrlSearchParams/useUrlSearchParams.mjs +2 -2
  213. package/dist/esm/hooks/useUrlSearchParams/useUrlSearchParams.mjs.map +1 -1
  214. package/dist/esm/hooks/useVisibility/useVisibility.mjs +25 -17
  215. package/dist/esm/hooks/useVisibility/useVisibility.mjs.map +1 -1
  216. package/dist/esm/index.mjs +255 -251
  217. package/dist/esm/index.mjs.map +1 -1
  218. package/dist/esm/utils/helpers/isTarget.mjs +10 -8
  219. package/dist/esm/utils/helpers/isTarget.mjs.map +1 -1
  220. package/dist/types/hooks/elements.d.ts +1 -0
  221. package/dist/types/hooks/useBreakpoints/useBreakpoints.d.ts +1 -11
  222. package/dist/types/hooks/useClickOutside/useClickOutside.d.ts +1 -1
  223. package/dist/types/hooks/useHover/useHover.d.ts +6 -6
  224. package/dist/types/hooks/useRefState/useRefState.d.ts +1 -0
  225. package/dist/types/hooks/useTextareaAutosize/useTextareaAutosize.d.ts +60 -0
  226. package/dist/types/utils/helpers/isTarget.d.ts +9 -1
  227. package/package.json +12 -12
@@ -1,12 +1,14 @@
1
- const n = 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), l = (e) => ({
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: n
4
- }), u = (e) => typeof e == "object" && ("current" in e || e && e.type === n);
5
- u.wrap = l;
6
- u.getElement = o;
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
- u as isTarget,
9
- l as target,
10
- n as targetSymbol
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 ('current' in target || (target && (target as any).type === targetSymbol));\n\nisTarget.wrap = target;\nisTarget.getElement = getElement;\n"],"names":["targetSymbol","getElement","target","isTarget"],"mappings":"AAEO,MAAMA,IAAe,OAAO,QAAQ,GAWrCC,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,MACvB,OAAOA,KAAW,aACjB,aAAaA,KAAWA,KAAWA,EAAe,SAASF;AAE9DG,EAAS,OAAOD;AAChBC,EAAS,aAAaF;"}
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 { greaterOrEqual, smallerOrEqual, current } = useBreakpoints({ mobile: 0, tablet: 640, laptop: 1024, desktop: 1280 });
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 {(node: Target) => void} A React ref to attach to the target element
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 state of the hover
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 state of the hover
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 state of the hover
51
+ * @returns {{ ref: StateRef<Target> } & UseHoverReturn} The object with the ref and the value of the hover
52
52
  *
53
53
  * @example
54
- * const [ref, hovering] = useHover(() => console.log('callback'));
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 state of the hover
60
+ * @returns {{ ref: StateRef<Target> } & UseHoverReturn} The object with the ref and the value of the hover
61
61
  *
62
62
  * @example
63
- * const [ref, hovering] = useHover(options);
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
- export type HookTarget = RefObject<Element | null | undefined> | {
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.2",
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.1.0",
67
+ "@siberiacancode/vitest": "^2.3.0",
68
68
  "@testing-library/dom": "^10.4.1",
69
- "@testing-library/react": "^16.3.0",
70
- "@types/dom-speech-recognition": "^0.0.6",
71
- "@types/react": "^19.1.10",
72
- "@types/react-dom": "^19.1.7",
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.0.1",
75
- "core-js": "^3.45.0",
76
- "react": "^19.1.1",
77
- "react-dom": "^19.1.1",
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.1.3",
79
+ "vite": "^7.3.0",
80
80
  "vite-plugin-dts": "^4.5.4",
81
- "vitest": "^3.2.4"
81
+ "vitest": "^4.0.16"
82
82
  },
83
83
  "lint-staged": {
84
84
  "*.{js,ts,tsx}": [