@siberiacancode/reactuse 0.3.7 → 0.3.9

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 (179) 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/useAutoScroll/useAutoScroll.cjs +1 -1
  4. package/dist/cjs/hooks/useAutoScroll/useAutoScroll.cjs.map +1 -1
  5. package/dist/cjs/hooks/useClickOutside/useClickOutside.cjs +1 -1
  6. package/dist/cjs/hooks/useClickOutside/useClickOutside.cjs.map +1 -1
  7. package/dist/cjs/hooks/useCssVar/useCssVar.cjs +1 -1
  8. package/dist/cjs/hooks/useCssVar/useCssVar.cjs.map +1 -1
  9. package/dist/cjs/hooks/useDebounceEffect/useDebounceEffect.cjs +2 -0
  10. package/dist/cjs/hooks/useDebounceEffect/useDebounceEffect.cjs.map +1 -0
  11. package/dist/cjs/hooks/useDidUpdate/useDidUpdate.cjs.map +1 -1
  12. package/dist/cjs/hooks/useDisplayMedia/useDisplayMedia.cjs +1 -1
  13. package/dist/cjs/hooks/useDisplayMedia/useDisplayMedia.cjs.map +1 -1
  14. package/dist/cjs/hooks/useDoubleClick/useDoubleClick.cjs +1 -1
  15. package/dist/cjs/hooks/useDoubleClick/useDoubleClick.cjs.map +1 -1
  16. package/dist/cjs/hooks/useDropZone/useDropZone.cjs +1 -1
  17. package/dist/cjs/hooks/useDropZone/useDropZone.cjs.map +1 -1
  18. package/dist/cjs/hooks/useEventListener/useEventListener.cjs +1 -1
  19. package/dist/cjs/hooks/useEventListener/useEventListener.cjs.map +1 -1
  20. package/dist/cjs/hooks/useFocus/useFocus.cjs +1 -1
  21. package/dist/cjs/hooks/useFocus/useFocus.cjs.map +1 -1
  22. package/dist/cjs/hooks/useFocusTrap/useFocusTrap.cjs +1 -1
  23. package/dist/cjs/hooks/useFocusTrap/useFocusTrap.cjs.map +1 -1
  24. package/dist/cjs/hooks/useHotkeys/useHotkeys.cjs +1 -1
  25. package/dist/cjs/hooks/useHotkeys/useHotkeys.cjs.map +1 -1
  26. package/dist/cjs/hooks/useHover/useHover.cjs +1 -1
  27. package/dist/cjs/hooks/useHover/useHover.cjs.map +1 -1
  28. package/dist/cjs/hooks/useInfiniteScroll/useInfiniteScroll.cjs +1 -1
  29. package/dist/cjs/hooks/useInfiniteScroll/useInfiniteScroll.cjs.map +1 -1
  30. package/dist/cjs/hooks/useIntersectionObserver/useIntersectionObserver.cjs +1 -1
  31. package/dist/cjs/hooks/useIntersectionObserver/useIntersectionObserver.cjs.map +1 -1
  32. package/dist/cjs/hooks/useKeyPress/useKeyPress.cjs +1 -1
  33. package/dist/cjs/hooks/useKeyPress/useKeyPress.cjs.map +1 -1
  34. package/dist/cjs/hooks/useKeyPressEvent/useKeyPressEvent.cjs +1 -1
  35. package/dist/cjs/hooks/useKeyPressEvent/useKeyPressEvent.cjs.map +1 -1
  36. package/dist/cjs/hooks/useKeyboard/useKeyboard.cjs +1 -1
  37. package/dist/cjs/hooks/useKeyboard/useKeyboard.cjs.map +1 -1
  38. package/dist/cjs/hooks/useKeysPressed/useKeysPressed.cjs +1 -1
  39. package/dist/cjs/hooks/useKeysPressed/useKeysPressed.cjs.map +1 -1
  40. package/dist/cjs/hooks/useLockScroll/useLockScroll.cjs +1 -1
  41. package/dist/cjs/hooks/useLockScroll/useLockScroll.cjs.map +1 -1
  42. package/dist/cjs/hooks/useLongPress/useLongPress.cjs +1 -1
  43. package/dist/cjs/hooks/useLongPress/useLongPress.cjs.map +1 -1
  44. package/dist/cjs/hooks/useMeasure/useMeasure.cjs +1 -1
  45. package/dist/cjs/hooks/useMeasure/useMeasure.cjs.map +1 -1
  46. package/dist/cjs/hooks/useMediaControls/useMediaControls.cjs +1 -1
  47. package/dist/cjs/hooks/useMediaControls/useMediaControls.cjs.map +1 -1
  48. package/dist/cjs/hooks/useMouse/useMouse.cjs +1 -1
  49. package/dist/cjs/hooks/useMouse/useMouse.cjs.map +1 -1
  50. package/dist/cjs/hooks/useMutationObserver/useMutationObserver.cjs +1 -1
  51. package/dist/cjs/hooks/useMutationObserver/useMutationObserver.cjs.map +1 -1
  52. package/dist/cjs/hooks/usePaint/usePaint.cjs +1 -1
  53. package/dist/cjs/hooks/usePaint/usePaint.cjs.map +1 -1
  54. package/dist/cjs/hooks/useParallax/useParallax.cjs +1 -1
  55. package/dist/cjs/hooks/useParallax/useParallax.cjs.map +1 -1
  56. package/dist/cjs/hooks/usePictureInPicture/usePictureInPicture.cjs +1 -1
  57. package/dist/cjs/hooks/usePictureInPicture/usePictureInPicture.cjs.map +1 -1
  58. package/dist/cjs/hooks/useResizeObserver/useResizeObserver.cjs +1 -1
  59. package/dist/cjs/hooks/useResizeObserver/useResizeObserver.cjs.map +1 -1
  60. package/dist/cjs/hooks/useRightClick/useRightClick.cjs +1 -1
  61. package/dist/cjs/hooks/useRightClick/useRightClick.cjs.map +1 -1
  62. package/dist/cjs/hooks/useScroll/useScroll.cjs +1 -1
  63. package/dist/cjs/hooks/useScroll/useScroll.cjs.map +1 -1
  64. package/dist/cjs/hooks/useScrollIntoView/useScrollIntoView.cjs +1 -1
  65. package/dist/cjs/hooks/useScrollIntoView/useScrollIntoView.cjs.map +1 -1
  66. package/dist/cjs/hooks/useScrollTo/useScrollTo.cjs +1 -1
  67. package/dist/cjs/hooks/useScrollTo/useScrollTo.cjs.map +1 -1
  68. package/dist/cjs/hooks/useSize/useSize.cjs +2 -0
  69. package/dist/cjs/hooks/useSize/useSize.cjs.map +1 -0
  70. package/dist/cjs/hooks/useSticky/useSticky.cjs +1 -1
  71. package/dist/cjs/hooks/useSticky/useSticky.cjs.map +1 -1
  72. package/dist/cjs/hooks/useTextDirection/useTextDirection.cjs +1 -1
  73. package/dist/cjs/hooks/useTextDirection/useTextDirection.cjs.map +1 -1
  74. package/dist/cjs/hooks/useTextareaAutosize/useTextareaAutosize.cjs +1 -1
  75. package/dist/cjs/hooks/useTextareaAutosize/useTextareaAutosize.cjs.map +1 -1
  76. package/dist/cjs/hooks/useThrottleEffect/useThrottleEffect.cjs +2 -0
  77. package/dist/cjs/hooks/useThrottleEffect/useThrottleEffect.cjs.map +1 -0
  78. package/dist/cjs/hooks/useVisibility/useVisibility.cjs +1 -1
  79. package/dist/cjs/hooks/useVisibility/useVisibility.cjs.map +1 -1
  80. package/dist/cjs/index.cjs +1 -1
  81. package/dist/cjs/utils/helpers/isTarget.cjs +1 -1
  82. package/dist/cjs/utils/helpers/isTarget.cjs.map +1 -1
  83. package/dist/esm/hooks/useActiveElement/useActiveElement.mjs +5 -5
  84. package/dist/esm/hooks/useActiveElement/useActiveElement.mjs.map +1 -1
  85. package/dist/esm/hooks/useAutoScroll/useAutoScroll.mjs +6 -6
  86. package/dist/esm/hooks/useAutoScroll/useAutoScroll.mjs.map +1 -1
  87. package/dist/esm/hooks/useClickOutside/useClickOutside.mjs +6 -6
  88. package/dist/esm/hooks/useClickOutside/useClickOutside.mjs.map +1 -1
  89. package/dist/esm/hooks/useCssVar/useCssVar.mjs +5 -5
  90. package/dist/esm/hooks/useCssVar/useCssVar.mjs.map +1 -1
  91. package/dist/esm/hooks/useDebounceEffect/useDebounceEffect.mjs +19 -0
  92. package/dist/esm/hooks/useDebounceEffect/useDebounceEffect.mjs.map +1 -0
  93. package/dist/esm/hooks/useDidUpdate/useDidUpdate.mjs +7 -7
  94. package/dist/esm/hooks/useDidUpdate/useDidUpdate.mjs.map +1 -1
  95. package/dist/esm/hooks/useDisplayMedia/useDisplayMedia.mjs +6 -6
  96. package/dist/esm/hooks/useDisplayMedia/useDisplayMedia.mjs.map +1 -1
  97. package/dist/esm/hooks/useDoubleClick/useDoubleClick.mjs +12 -12
  98. package/dist/esm/hooks/useDoubleClick/useDoubleClick.mjs.map +1 -1
  99. package/dist/esm/hooks/useDropZone/useDropZone.mjs +3 -3
  100. package/dist/esm/hooks/useDropZone/useDropZone.mjs.map +1 -1
  101. package/dist/esm/hooks/useEventListener/useEventListener.mjs +10 -10
  102. package/dist/esm/hooks/useEventListener/useEventListener.mjs.map +1 -1
  103. package/dist/esm/hooks/useFocus/useFocus.mjs +10 -10
  104. package/dist/esm/hooks/useFocus/useFocus.mjs.map +1 -1
  105. package/dist/esm/hooks/useFocusTrap/useFocusTrap.mjs +5 -5
  106. package/dist/esm/hooks/useFocusTrap/useFocusTrap.mjs.map +1 -1
  107. package/dist/esm/hooks/useHotkeys/useHotkeys.mjs +7 -8
  108. package/dist/esm/hooks/useHotkeys/useHotkeys.mjs.map +1 -1
  109. package/dist/esm/hooks/useHover/useHover.mjs +7 -7
  110. package/dist/esm/hooks/useHover/useHover.mjs.map +1 -1
  111. package/dist/esm/hooks/useInfiniteScroll/useInfiniteScroll.mjs +6 -6
  112. package/dist/esm/hooks/useInfiniteScroll/useInfiniteScroll.mjs.map +1 -1
  113. package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs +17 -18
  114. package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs.map +1 -1
  115. package/dist/esm/hooks/useKeyPress/useKeyPress.mjs +5 -5
  116. package/dist/esm/hooks/useKeyPress/useKeyPress.mjs.map +1 -1
  117. package/dist/esm/hooks/useKeyPressEvent/useKeyPressEvent.mjs +3 -4
  118. package/dist/esm/hooks/useKeyPressEvent/useKeyPressEvent.mjs.map +1 -1
  119. package/dist/esm/hooks/useKeyboard/useKeyboard.mjs +8 -8
  120. package/dist/esm/hooks/useKeyboard/useKeyboard.mjs.map +1 -1
  121. package/dist/esm/hooks/useKeysPressed/useKeysPressed.mjs +8 -8
  122. package/dist/esm/hooks/useKeysPressed/useKeysPressed.mjs.map +1 -1
  123. package/dist/esm/hooks/useLockScroll/useLockScroll.mjs +13 -13
  124. package/dist/esm/hooks/useLockScroll/useLockScroll.mjs.map +1 -1
  125. package/dist/esm/hooks/useLongPress/useLongPress.mjs +7 -7
  126. package/dist/esm/hooks/useLongPress/useLongPress.mjs.map +1 -1
  127. package/dist/esm/hooks/useMeasure/useMeasure.mjs +3 -3
  128. package/dist/esm/hooks/useMeasure/useMeasure.mjs.map +1 -1
  129. package/dist/esm/hooks/useMediaControls/useMediaControls.mjs +4 -4
  130. package/dist/esm/hooks/useMediaControls/useMediaControls.mjs.map +1 -1
  131. package/dist/esm/hooks/useMouse/useMouse.mjs +10 -10
  132. package/dist/esm/hooks/useMouse/useMouse.mjs.map +1 -1
  133. package/dist/esm/hooks/useMutationObserver/useMutationObserver.mjs +7 -8
  134. package/dist/esm/hooks/useMutationObserver/useMutationObserver.mjs.map +1 -1
  135. package/dist/esm/hooks/usePaint/usePaint.mjs +15 -15
  136. package/dist/esm/hooks/usePaint/usePaint.mjs.map +1 -1
  137. package/dist/esm/hooks/useParallax/useParallax.mjs +24 -25
  138. package/dist/esm/hooks/useParallax/useParallax.mjs.map +1 -1
  139. package/dist/esm/hooks/usePictureInPicture/usePictureInPicture.mjs +6 -6
  140. package/dist/esm/hooks/usePictureInPicture/usePictureInPicture.mjs.map +1 -1
  141. package/dist/esm/hooks/useResizeObserver/useResizeObserver.mjs +7 -7
  142. package/dist/esm/hooks/useResizeObserver/useResizeObserver.mjs.map +1 -1
  143. package/dist/esm/hooks/useRightClick/useRightClick.mjs +5 -5
  144. package/dist/esm/hooks/useRightClick/useRightClick.mjs.map +1 -1
  145. package/dist/esm/hooks/useScroll/useScroll.mjs +13 -13
  146. package/dist/esm/hooks/useScroll/useScroll.mjs.map +1 -1
  147. package/dist/esm/hooks/useScrollIntoView/useScrollIntoView.mjs +9 -9
  148. package/dist/esm/hooks/useScrollIntoView/useScrollIntoView.mjs.map +1 -1
  149. package/dist/esm/hooks/useScrollTo/useScrollTo.mjs +1 -1
  150. package/dist/esm/hooks/useScrollTo/useScrollTo.mjs.map +1 -1
  151. package/dist/esm/hooks/useSize/useSize.mjs +31 -0
  152. package/dist/esm/hooks/useSize/useSize.mjs.map +1 -0
  153. package/dist/esm/hooks/useSticky/useSticky.mjs +10 -10
  154. package/dist/esm/hooks/useSticky/useSticky.mjs.map +1 -1
  155. package/dist/esm/hooks/useTextDirection/useTextDirection.mjs +3 -3
  156. package/dist/esm/hooks/useTextDirection/useTextDirection.mjs.map +1 -1
  157. package/dist/esm/hooks/useTextareaAutosize/useTextareaAutosize.mjs +13 -13
  158. package/dist/esm/hooks/useTextareaAutosize/useTextareaAutosize.mjs.map +1 -1
  159. package/dist/esm/hooks/useThrottleEffect/useThrottleEffect.mjs +22 -0
  160. package/dist/esm/hooks/useThrottleEffect/useThrottleEffect.mjs.map +1 -0
  161. package/dist/esm/hooks/useVisibility/useVisibility.mjs +22 -23
  162. package/dist/esm/hooks/useVisibility/useVisibility.mjs.map +1 -1
  163. package/dist/esm/index.mjs +110 -102
  164. package/dist/esm/index.mjs.map +1 -1
  165. package/dist/esm/utils/helpers/isTarget.mjs +12 -7
  166. package/dist/esm/utils/helpers/isTarget.mjs.map +1 -1
  167. package/dist/types/hooks/sensors.d.ts +1 -1
  168. package/dist/types/hooks/useDebounceEffect/useDebounceEffect.d.ts +15 -0
  169. package/dist/types/hooks/useSize/useSize.d.ts +43 -0
  170. package/dist/types/hooks/useThrottleEffect/useThrottleEffect.d.ts +15 -0
  171. package/dist/types/hooks/useVisibility/useVisibility.d.ts +1 -1
  172. package/dist/types/hooks/utilities.d.ts +2 -0
  173. package/dist/types/utils/helpers/isTarget.d.ts +10 -4
  174. package/package.json +1 -1
  175. package/dist/cjs/hooks/useElementSize/useElementSize.cjs +0 -2
  176. package/dist/cjs/hooks/useElementSize/useElementSize.cjs.map +0 -1
  177. package/dist/esm/hooks/useElementSize/useElementSize.mjs +0 -30
  178. package/dist/esm/hooks/useElementSize/useElementSize.mjs.map +0 -1
  179. package/dist/types/hooks/useElementSize/useElementSize.d.ts +0 -39
@@ -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>\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;"}
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;"}
@@ -4,7 +4,6 @@ export * from './useDeviceOrientation/useDeviceOrientation';
4
4
  export * from './useDevicePixelRatio/useDevicePixelRatio';
5
5
  export * from './useDocumentEvent/useDocumentEvent';
6
6
  export * from './useDocumentVisibility/useDocumentVisibility';
7
- export * from './useElementSize/useElementSize';
8
7
  export * from './useEventListener/useEventListener';
9
8
  export * from './useHotkeys/useHotkeys';
10
9
  export * from './useIdle/useIdle';
@@ -27,6 +26,7 @@ export * from './useResizeObserver/useResizeObserver';
27
26
  export * from './useScroll/useScroll';
28
27
  export * from './useScrollIntoView/useScrollIntoView';
29
28
  export * from './useScrollTo/useScrollTo';
29
+ export * from './useSize/useSize';
30
30
  export * from './useTextSelection/useTextSelection';
31
31
  export * from './useVisibility/useVisibility';
32
32
  export * from './useWindowEvent/useWindowEvent';
@@ -0,0 +1,15 @@
1
+ import { DependencyList, EffectCallback } from 'react';
2
+ /**
3
+ * @name useDebounceEffect
4
+ * @description – Hook that runs an effect after a delay when dependencies change
5
+ * @category Utilities
6
+ * @usage high
7
+ *
8
+ * @param {EffectCallback} effect The effect callback to run
9
+ * @param {number} delay The delay in milliseconds
10
+ * @param {DependencyList} deps The dependencies list for the effect
11
+ *
12
+ * @example
13
+ * useDebounceEffect(() => console.log('effect'), 500, [value]);
14
+ */
15
+ export declare const useDebounceEffect: (effect: EffectCallback, delay: number, deps?: DependencyList) => void;
@@ -0,0 +1,43 @@
1
+ import { HookTarget } from '../../utils/helpers';
2
+ import { StateRef } from '../useRefState/useRefState';
3
+ /** The size value type */
4
+ export interface UseSizeValue {
5
+ /** The element's height */
6
+ height: number;
7
+ /** The element's width */
8
+ width: number;
9
+ }
10
+ /** The use size return type */
11
+ export interface UseSizeReturn {
12
+ /** The resize observer instance */
13
+ observer?: ResizeObserver;
14
+ /** The current size value */
15
+ value: UseSizeValue;
16
+ }
17
+ export interface UseSize {
18
+ (target: HookTarget): UseSizeReturn;
19
+ <Target extends Element>(target?: never): {
20
+ ref: StateRef<Target>;
21
+ } & UseSizeReturn;
22
+ }
23
+ /**
24
+ * @name useSize
25
+ * @description - Hook that observes and returns the width and height of element
26
+ * @category Elements
27
+ * @usage low
28
+ *
29
+ * @overload
30
+ * @param {HookTarget} target The target element to observe
31
+ * @returns {UseSizeReturn} An object containing the resize observer, current width and height of the element
32
+ *
33
+ * @example
34
+ * const { value, observer } = useSize(ref);
35
+ *
36
+ * @overload
37
+ * @template Target The target element type
38
+ * @returns { { ref: StateRef<Target> } & UseSizeReturn } An object containing the resize observer, current width and height of the element
39
+ *
40
+ * @example
41
+ * const { ref, value, observer } = useSize();
42
+ */
43
+ export declare const useSize: UseSize;
@@ -0,0 +1,15 @@
1
+ import { DependencyList, EffectCallback } from 'react';
2
+ /**
3
+ * @name useThrottleEffect
4
+ * @description – Hook that runs an effect at most once per delay period when dependencies change
5
+ * @category Utilities
6
+ * @usage medium
7
+ *
8
+ * @param {EffectCallback} effect The effect callback to run
9
+ * @param {number} delay The delay in milliseconds
10
+ * @param {DependencyList} deps The dependencies list for the effect
11
+ *
12
+ * @example
13
+ * useThrottleEffect(() => console.log('effect'), 500, [value]);
14
+ */
15
+ export declare const useThrottleEffect: (effect: EffectCallback, delay: number, deps?: DependencyList) => void;
@@ -16,7 +16,7 @@ export interface UseVisibilityReturn {
16
16
  /** The intersection observer entry */
17
17
  entry?: IntersectionObserverEntry;
18
18
  /** The intersection observer in view */
19
- inView?: boolean;
19
+ inView: boolean;
20
20
  /** The intersection observer instance */
21
21
  observer?: IntersectionObserver;
22
22
  }
@@ -1,6 +1,7 @@
1
1
  export * from './useBatchedCallback/useBatchedCallback';
2
2
  export * from './useConst/useConst';
3
3
  export * from './useDebounceCallback/useDebounceCallback';
4
+ export * from './useDebounceEffect/useDebounceEffect';
4
5
  export * from './useDebounceState/useDebounceState';
5
6
  export * from './useDebounceValue/useDebounceValue';
6
7
  export * from './useEvent/useEvent';
@@ -8,5 +9,6 @@ export * from './useLastChanged/useLastChanged';
8
9
  export * from './useLatest/useLatest';
9
10
  export * from './usePrevious/usePrevious';
10
11
  export * from './useThrottleCallback/useThrottleCallback';
12
+ export * from './useThrottleEffect/useThrottleEffect';
11
13
  export * from './useThrottleState/useThrottleState';
12
14
  export * from './useThrottleValue/useThrottleValue';
@@ -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 {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@siberiacancode/reactuse",
3
- "version": "0.3.7",
3
+ "version": "0.3.9",
4
4
  "description": "The ultimate collection of react hooks",
5
5
  "author": {
6
6
  "name": "SIBERIA CAN CODE 🧊",
@@ -1,2 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react"),l=require("../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.cjs"),d=require("../useRefState/useRefState.cjs"),o=require("../../utils/helpers/isTarget.cjs"),S=((...u)=>{const e=u[0],[i,n]=f.useState({width:0,height:0}),r=d.useRefState();return l.useIsomorphicLayoutEffect(()=>{const t=e?o.isTarget.getElement(e):r.current;if(!t)return;const{width:c,height:a}=t.getBoundingClientRect();n({width:c,height:a});const s=new ResizeObserver(()=>{const{width:g,height:h}=t.getBoundingClientRect();n({width:g,height:h})});return s.observe(t),()=>{s.disconnect()}},[r.state,e,o.isTarget.getRefState(e)]),e?{value:i}:{ref:r,value:i}});exports.useElementSize=S;
2
- //# sourceMappingURL=useElementSize.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useElementSize.cjs","sources":["../../../../src/hooks/useElementSize/useElementSize.ts"],"sourcesContent":["import { 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 { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect';\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The element size value type */\nexport interface UseElementSizeValue {\n /** The element's height */\n height: number;\n /** The element's width */\n width: number;\n}\n\n/** The use element size return type */\nexport interface UseElementSizeReturn {\n value: UseElementSizeValue;\n}\n\nexport interface UseElementSize {\n (target: HookTarget): UseElementSizeReturn;\n\n <Target extends Element>(\n target?: never\n ): {\n ref: StateRef<Target>;\n } & UseElementSizeReturn;\n}\n\n/**\n * @name useElementSize\n * @description - Hook that observes and returns the width and height of element\n * @category Elements\n * @usage low\n\n * @overload\n * @param {HookTarget} target The target element to observe\n * @returns {UseElementSizeReturn} An object containing the current width and height of the element\n *\n * @example\n * const { value } = useElementSize(ref);\n *\n * @overload\n * @returns { { ref: StateRef<Target> } & UseElementSizeReturn } An object containing the current width and height of the element\n *\n * @example\n * const { ref, value } = useElementSize();\n */\nexport const useElementSize = ((...params: any[]) => {\n const target = params[0] as HookTarget | undefined;\n const [size, setSize] = useState({ width: 0, height: 0 });\n const internalRef = useRefState<Element>();\n\n useIsomorphicLayoutEffect(() => {\n const element = (target ? isTarget.getElement(target) : internalRef.current) as Element;\n\n if (!element) return;\n\n const { width, height } = element.getBoundingClientRect();\n setSize({\n width,\n height\n });\n\n const observer = new ResizeObserver(() => {\n const { width, height } = element.getBoundingClientRect();\n setSize({ width, height });\n });\n\n observer.observe(element);\n\n return () => {\n observer.disconnect();\n };\n }, [internalRef.state, target, isTarget.getRefState(target)]);\n\n if (target) return { value: size };\n return {\n ref: internalRef,\n value: size\n };\n}) as UseElementSize;\n"],"names":["useElementSize","params","target","size","setSize","useState","internalRef","useRefState","useIsomorphicLayoutEffect","element","isTarget","width","height","observer"],"mappings":"2QAqDaA,GAAkB,IAAIC,IAAkB,CACnD,MAAMC,EAASD,EAAO,CAAC,EACjB,CAACE,EAAMC,CAAO,EAAIC,EAAAA,SAAS,CAAE,MAAO,EAAG,OAAQ,EAAG,EAClDC,EAAcC,EAAAA,YAAA,EAyBpB,OAvBAC,EAAAA,0BAA0B,IAAM,CAC9B,MAAMC,EAAWP,EAASQ,EAAAA,SAAS,WAAWR,CAAM,EAAII,EAAY,QAEpE,GAAI,CAACG,EAAS,OAEd,KAAM,CAAE,MAAAE,EAAO,OAAAC,GAAWH,EAAQ,sBAAA,EAClCL,EAAQ,CACN,MAAAO,EACA,OAAAC,CAAA,CACD,EAED,MAAMC,EAAW,IAAI,eAAe,IAAM,CACxC,KAAM,CAAE,MAAAF,EAAO,OAAAC,CAAAA,EAAWH,EAAQ,sBAAA,EAClCL,EAAQ,CAAE,MAAAO,EAAO,OAAAC,EAAQ,CAAA,CAC1B,EAED,OAAAC,EAAS,QAAQJ,CAAO,EAEjB,IAAM,CACXI,EAAS,WAAA,CAAW,CACtB,EACC,CAACP,EAAY,MAAOJ,EAAQQ,EAAAA,SAAS,YAAYR,CAAM,CAAC,CAAC,EAExDA,EAAe,CAAE,MAAOC,CAAA,EACrB,CACL,IAAKG,EACL,MAAOH,CAAA,CAEX"}
@@ -1,30 +0,0 @@
1
- import { useState as m } from "react";
2
- import { useIsomorphicLayoutEffect as a } from "../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.mjs";
3
- import { useRefState as d } from "../useRefState/useRefState.mjs";
4
- import { isTarget as s } from "../../utils/helpers/isTarget.mjs";
5
- const v = ((...h) => {
6
- const e = h[0], [i, n] = m({ width: 0, height: 0 }), r = d();
7
- return a(() => {
8
- const t = e ? s.getElement(e) : r.current;
9
- if (!t) return;
10
- const { width: c, height: u } = t.getBoundingClientRect();
11
- n({
12
- width: c,
13
- height: u
14
- });
15
- const o = new ResizeObserver(() => {
16
- const { width: g, height: f } = t.getBoundingClientRect();
17
- n({ width: g, height: f });
18
- });
19
- return o.observe(t), () => {
20
- o.disconnect();
21
- };
22
- }, [r.state, e, s.getRefState(e)]), e ? { value: i } : {
23
- ref: r,
24
- value: i
25
- };
26
- });
27
- export {
28
- v as useElementSize
29
- };
30
- //# sourceMappingURL=useElementSize.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useElementSize.mjs","sources":["../../../../src/hooks/useElementSize/useElementSize.ts"],"sourcesContent":["import { 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 { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect';\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The element size value type */\nexport interface UseElementSizeValue {\n /** The element's height */\n height: number;\n /** The element's width */\n width: number;\n}\n\n/** The use element size return type */\nexport interface UseElementSizeReturn {\n value: UseElementSizeValue;\n}\n\nexport interface UseElementSize {\n (target: HookTarget): UseElementSizeReturn;\n\n <Target extends Element>(\n target?: never\n ): {\n ref: StateRef<Target>;\n } & UseElementSizeReturn;\n}\n\n/**\n * @name useElementSize\n * @description - Hook that observes and returns the width and height of element\n * @category Elements\n * @usage low\n\n * @overload\n * @param {HookTarget} target The target element to observe\n * @returns {UseElementSizeReturn} An object containing the current width and height of the element\n *\n * @example\n * const { value } = useElementSize(ref);\n *\n * @overload\n * @returns { { ref: StateRef<Target> } & UseElementSizeReturn } An object containing the current width and height of the element\n *\n * @example\n * const { ref, value } = useElementSize();\n */\nexport const useElementSize = ((...params: any[]) => {\n const target = params[0] as HookTarget | undefined;\n const [size, setSize] = useState({ width: 0, height: 0 });\n const internalRef = useRefState<Element>();\n\n useIsomorphicLayoutEffect(() => {\n const element = (target ? isTarget.getElement(target) : internalRef.current) as Element;\n\n if (!element) return;\n\n const { width, height } = element.getBoundingClientRect();\n setSize({\n width,\n height\n });\n\n const observer = new ResizeObserver(() => {\n const { width, height } = element.getBoundingClientRect();\n setSize({ width, height });\n });\n\n observer.observe(element);\n\n return () => {\n observer.disconnect();\n };\n }, [internalRef.state, target, isTarget.getRefState(target)]);\n\n if (target) return { value: size };\n return {\n ref: internalRef,\n value: size\n };\n}) as UseElementSize;\n"],"names":["useElementSize","params","target","size","setSize","useState","internalRef","useRefState","useIsomorphicLayoutEffect","element","isTarget","width","height","observer"],"mappings":";;;;AAqDO,MAAMA,KAAkB,IAAIC,MAAkB;AACnD,QAAMC,IAASD,EAAO,CAAC,GACjB,CAACE,GAAMC,CAAO,IAAIC,EAAS,EAAE,OAAO,GAAG,QAAQ,GAAG,GAClDC,IAAcC,EAAA;AAyBpB,SAvBAC,EAA0B,MAAM;AAC9B,UAAMC,IAAWP,IAASQ,EAAS,WAAWR,CAAM,IAAII,EAAY;AAEpE,QAAI,CAACG,EAAS;AAEd,UAAM,EAAE,OAAAE,GAAO,QAAAC,MAAWH,EAAQ,sBAAA;AAClC,IAAAL,EAAQ;AAAA,MACN,OAAAO;AAAA,MACA,QAAAC;AAAA,IAAA,CACD;AAED,UAAMC,IAAW,IAAI,eAAe,MAAM;AACxC,YAAM,EAAE,OAAAF,GAAO,QAAAC,EAAAA,IAAWH,EAAQ,sBAAA;AAClC,MAAAL,EAAQ,EAAE,OAAAO,GAAO,QAAAC,GAAQ;AAAA,IAAA,CAC1B;AAED,WAAAC,EAAS,QAAQJ,CAAO,GAEjB,MAAM;AACX,MAAAI,EAAS,WAAA;AAAA,IAAW;AAAA,EACtB,GACC,CAACP,EAAY,OAAOJ,GAAQQ,EAAS,YAAYR,CAAM,CAAC,CAAC,GAExDA,IAAe,EAAE,OAAOC,EAAA,IACrB;AAAA,IACL,KAAKG;AAAA,IACL,OAAOH;AAAA,EAAA;AAEX;"}
@@ -1,39 +0,0 @@
1
- import { HookTarget } from '../../utils/helpers';
2
- import { StateRef } from '../useRefState/useRefState';
3
- /** The element size value type */
4
- export interface UseElementSizeValue {
5
- /** The element's height */
6
- height: number;
7
- /** The element's width */
8
- width: number;
9
- }
10
- /** The use element size return type */
11
- export interface UseElementSizeReturn {
12
- value: UseElementSizeValue;
13
- }
14
- export interface UseElementSize {
15
- (target: HookTarget): UseElementSizeReturn;
16
- <Target extends Element>(target?: never): {
17
- ref: StateRef<Target>;
18
- } & UseElementSizeReturn;
19
- }
20
- /**
21
- * @name useElementSize
22
- * @description - Hook that observes and returns the width and height of element
23
- * @category Elements
24
- * @usage low
25
-
26
- * @overload
27
- * @param {HookTarget} target The target element to observe
28
- * @returns {UseElementSizeReturn} An object containing the current width and height of the element
29
- *
30
- * @example
31
- * const { value } = useElementSize(ref);
32
- *
33
- * @overload
34
- * @returns { { ref: StateRef<Target> } & UseElementSizeReturn } An object containing the current width and height of the element
35
- *
36
- * @example
37
- * const { ref, value } = useElementSize();
38
- */
39
- export declare const useElementSize: UseElementSize;