react-simplikit 0.0.50 → 0.0.52

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 (279) hide show
  1. package/dist/components/ImpressionArea/ImpressionArea.cjs +57 -0
  2. package/{esm/components/ImpressionArea/index.d.ts → dist/components/ImpressionArea/ImpressionArea.d.cts} +9 -8
  3. package/dist/components/ImpressionArea/ImpressionArea.d.mts +48 -0
  4. package/dist/components/ImpressionArea/ImpressionArea.mjs +57 -0
  5. package/dist/components/ImpressionArea/index.d.cts +2 -46
  6. package/dist/components/ImpressionArea/index.d.mts +3 -0
  7. package/dist/components/Separated/Separated.cjs +38 -0
  8. package/{esm/components/Separated/index.d.ts → dist/components/Separated/Separated.d.cts} +7 -7
  9. package/dist/components/Separated/Separated.d.mts +38 -0
  10. package/dist/components/Separated/Separated.mjs +38 -0
  11. package/dist/components/Separated/index.d.cts +2 -37
  12. package/dist/components/Separated/index.d.mts +3 -0
  13. package/dist/components/SwitchCase/SwitchCase.cjs +40 -0
  14. package/{esm/components/SwitchCase/index.d.ts → dist/components/SwitchCase/SwitchCase.d.cts} +7 -8
  15. package/dist/components/SwitchCase/SwitchCase.d.mts +45 -0
  16. package/dist/components/SwitchCase/SwitchCase.mjs +40 -0
  17. package/dist/components/SwitchCase/index.d.cts +2 -45
  18. package/dist/components/SwitchCase/index.d.mts +3 -0
  19. package/dist/hooks/useAsyncEffect/index.d.cts +2 -24
  20. package/dist/hooks/useAsyncEffect/index.d.mts +3 -0
  21. package/dist/hooks/useAsyncEffect/useAsyncEffect.cjs +39 -0
  22. package/{esm/hooks/useAsyncEffect/index.d.ts → dist/hooks/useAsyncEffect/useAsyncEffect.d.cts} +4 -3
  23. package/dist/hooks/useAsyncEffect/useAsyncEffect.d.mts +26 -0
  24. package/dist/hooks/useAsyncEffect/useAsyncEffect.mjs +39 -0
  25. package/dist/hooks/useBooleanState/useBooleanState.cjs +36 -0
  26. package/dist/hooks/useBooleanState/{index.d.cts → useBooleanState.d.cts} +4 -2
  27. package/{esm/hooks/useBooleanState/index.d.ts → dist/hooks/useBooleanState/useBooleanState.d.mts} +4 -2
  28. package/dist/hooks/useBooleanState/useBooleanState.mjs +36 -0
  29. package/dist/hooks/useCallbackOncePerRender/index.d.cts +2 -39
  30. package/dist/hooks/useCallbackOncePerRender/index.d.mts +3 -0
  31. package/dist/hooks/useCallbackOncePerRender/useCallbackOncePerRender.cjs +52 -0
  32. package/{esm/hooks/useCallbackOncePerRender/index.d.ts → dist/hooks/useCallbackOncePerRender/useCallbackOncePerRender.d.cts} +4 -3
  33. package/dist/hooks/useCallbackOncePerRender/useCallbackOncePerRender.d.mts +41 -0
  34. package/dist/hooks/useCallbackOncePerRender/useCallbackOncePerRender.mjs +52 -0
  35. package/dist/hooks/useConditionalEffect/index.d.cts +2 -42
  36. package/dist/hooks/useConditionalEffect/index.d.mts +3 -0
  37. package/dist/hooks/useConditionalEffect/useConditionalEffect.cjs +57 -0
  38. package/{esm/hooks/useConditionalEffect/index.d.ts → dist/hooks/useConditionalEffect/useConditionalEffect.d.cts} +4 -3
  39. package/dist/hooks/useConditionalEffect/useConditionalEffect.d.mts +44 -0
  40. package/dist/hooks/useConditionalEffect/useConditionalEffect.mjs +57 -0
  41. package/dist/hooks/useControlledState/index.d.cts +2 -50
  42. package/dist/hooks/useControlledState/index.d.mts +3 -0
  43. package/dist/hooks/useControlledState/useControlledState.cjs +60 -0
  44. package/{esm/hooks/useControlledState/index.d.ts → dist/hooks/useControlledState/useControlledState.d.cts} +11 -10
  45. package/dist/hooks/useControlledState/useControlledState.d.mts +52 -0
  46. package/dist/hooks/useControlledState/useControlledState.mjs +60 -0
  47. package/dist/hooks/useCounter/useCounter.cjs +75 -0
  48. package/{esm/hooks/useCounter/index.d.ts → dist/hooks/useCounter/useCounter.d.cts} +12 -10
  49. package/dist/hooks/useCounter/{index.d.cts → useCounter.d.mts} +12 -10
  50. package/dist/hooks/useCounter/useCounter.mjs +75 -0
  51. package/dist/hooks/useDebounce/debounce.cjs +49 -0
  52. package/dist/hooks/useDebounce/debounce.d.cts +8 -0
  53. package/dist/hooks/useDebounce/debounce.d.mts +8 -0
  54. package/dist/hooks/useDebounce/debounce.mjs +49 -0
  55. package/dist/hooks/useDebounce/useDebounce.cjs +66 -0
  56. package/{esm/hooks/useDebounce/index.d.ts → dist/hooks/useDebounce/useDebounce.d.cts} +6 -8
  57. package/dist/hooks/useDebounce/{index.d.cts → useDebounce.d.mts} +6 -8
  58. package/dist/hooks/useDebounce/useDebounce.mjs +66 -0
  59. package/dist/hooks/useDebouncedCallback/useDebouncedCallback.cjs +62 -0
  60. package/{esm/hooks/useDebouncedCallback/index.d.ts → dist/hooks/useDebouncedCallback/useDebouncedCallback.d.cts} +9 -7
  61. package/dist/hooks/useDebouncedCallback/{index.d.cts → useDebouncedCallback.d.mts} +9 -7
  62. package/dist/hooks/useDebouncedCallback/useDebouncedCallback.mjs +62 -0
  63. package/dist/hooks/useDoubleClick/index.d.cts +2 -45
  64. package/dist/hooks/useDoubleClick/index.d.mts +3 -0
  65. package/dist/hooks/useDoubleClick/useDoubleClick.cjs +64 -0
  66. package/{esm/hooks/useDoubleClick/index.d.ts → dist/hooks/useDoubleClick/useDoubleClick.d.cts} +8 -7
  67. package/dist/hooks/useDoubleClick/useDoubleClick.d.mts +47 -0
  68. package/dist/hooks/useDoubleClick/useDoubleClick.mjs +64 -0
  69. package/dist/hooks/useGeolocation/useGeolocation.cjs +210 -0
  70. package/{esm/hooks/useGeolocation/index.d.ts → dist/hooks/useGeolocation/useGeolocation.d.cts} +26 -24
  71. package/dist/hooks/useGeolocation/{index.d.cts → useGeolocation.d.mts} +26 -24
  72. package/dist/hooks/useGeolocation/useGeolocation.mjs +209 -0
  73. package/dist/hooks/useImpressionRef/useImpressionRef.cjs +67 -0
  74. package/{esm/hooks/useImpressionRef/index.d.ts → dist/hooks/useImpressionRef/useImpressionRef.d.cts} +10 -8
  75. package/dist/hooks/useImpressionRef/{index.d.cts → useImpressionRef.d.mts} +10 -8
  76. package/dist/hooks/useImpressionRef/useImpressionRef.mjs +67 -0
  77. package/dist/hooks/useInputState/index.d.cts +2 -22
  78. package/dist/hooks/useInputState/index.d.mts +3 -0
  79. package/dist/hooks/useInputState/useInputState.cjs +32 -0
  80. package/{esm/hooks/useInputState/index.d.ts → dist/hooks/useInputState/useInputState.d.cts} +4 -3
  81. package/dist/hooks/useInputState/useInputState.d.mts +24 -0
  82. package/dist/hooks/useInputState/useInputState.mjs +32 -0
  83. package/dist/hooks/useIntersectionObserver/useIntersectionObserver.cjs +58 -0
  84. package/dist/hooks/useIntersectionObserver/{index.d.cts → useIntersectionObserver.d.cts} +4 -2
  85. package/{esm/hooks/useIntersectionObserver/index.d.ts → dist/hooks/useIntersectionObserver/useIntersectionObserver.d.mts} +4 -2
  86. package/dist/hooks/useIntersectionObserver/useIntersectionObserver.mjs +58 -0
  87. package/dist/hooks/useInterval/useInterval.cjs +65 -0
  88. package/dist/hooks/useInterval/{index.d.cts → useInterval.d.cts} +7 -5
  89. package/{esm/hooks/useInterval/index.d.ts → dist/hooks/useInterval/useInterval.d.mts} +7 -5
  90. package/dist/hooks/useInterval/useInterval.mjs +65 -0
  91. package/dist/hooks/useIsClient/useIsClient.cjs +49 -0
  92. package/dist/hooks/useIsClient/{index.d.cts → useIsClient.d.cts} +4 -2
  93. package/{esm/hooks/useIsClient/index.d.ts → dist/hooks/useIsClient/useIsClient.d.mts} +4 -2
  94. package/dist/hooks/useIsClient/useIsClient.mjs +49 -0
  95. package/dist/hooks/useIsomorphicLayoutEffect/index.d.cts +2 -24
  96. package/dist/hooks/useIsomorphicLayoutEffect/index.d.mts +3 -0
  97. package/dist/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.cjs +25 -0
  98. package/{esm/hooks/useIsomorphicLayoutEffect/index.d.ts → dist/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.d.cts} +4 -3
  99. package/dist/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.d.mts +26 -0
  100. package/dist/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.mjs +25 -0
  101. package/dist/hooks/useList/useList.cjs +94 -0
  102. package/{esm/hooks/useList/index.d.ts → dist/hooks/useList/useList.d.cts} +10 -8
  103. package/dist/hooks/useList/{index.d.cts → useList.d.mts} +10 -8
  104. package/dist/hooks/useList/useList.mjs +94 -0
  105. package/dist/hooks/useLoading/useLoading.cjs +61 -0
  106. package/dist/hooks/useLoading/{index.d.cts → useLoading.d.cts} +4 -2
  107. package/{esm/hooks/useLoading/index.d.ts → dist/hooks/useLoading/useLoading.d.mts} +4 -2
  108. package/dist/hooks/useLoading/useLoading.mjs +61 -0
  109. package/dist/hooks/useLongPress/index.d.cts +2 -73
  110. package/dist/hooks/useLongPress/index.d.mts +3 -0
  111. package/dist/hooks/useLongPress/useLongPress.cjs +133 -0
  112. package/{esm/hooks/useLongPress/index.d.ts → dist/hooks/useLongPress/useLongPress.d.cts} +18 -17
  113. package/dist/hooks/useLongPress/useLongPress.d.mts +75 -0
  114. package/dist/hooks/useLongPress/useLongPress.mjs +133 -0
  115. package/dist/hooks/useMap/useMap.cjs +64 -0
  116. package/dist/hooks/useMap/{index.d.cts → useMap.d.cts} +12 -10
  117. package/{esm/hooks/useMap/index.d.ts → dist/hooks/useMap/useMap.d.mts} +12 -10
  118. package/dist/hooks/useMap/useMap.mjs +64 -0
  119. package/dist/hooks/useOutsideClickEffect/useOutsideClickEffect.cjs +51 -0
  120. package/{esm/hooks/useOutsideClickEffect/index.d.ts → dist/hooks/useOutsideClickEffect/useOutsideClickEffect.d.cts} +4 -2
  121. package/dist/hooks/useOutsideClickEffect/{index.d.cts → useOutsideClickEffect.d.mts} +4 -2
  122. package/dist/hooks/useOutsideClickEffect/useOutsideClickEffect.mjs +51 -0
  123. package/dist/hooks/usePreservedCallback/usePreservedCallback.cjs +41 -0
  124. package/dist/hooks/usePreservedCallback/{index.d.cts → usePreservedCallback.d.cts} +4 -2
  125. package/{esm/hooks/usePreservedCallback/index.d.ts → dist/hooks/usePreservedCallback/usePreservedCallback.d.mts} +4 -2
  126. package/dist/hooks/usePreservedCallback/usePreservedCallback.mjs +41 -0
  127. package/dist/hooks/usePreservedReference/usePreservedReference.cjs +55 -0
  128. package/dist/hooks/usePreservedReference/{index.d.cts → usePreservedReference.d.cts} +4 -2
  129. package/{esm/hooks/usePreservedReference/index.d.ts → dist/hooks/usePreservedReference/usePreservedReference.d.mts} +4 -2
  130. package/dist/hooks/usePreservedReference/usePreservedReference.mjs +55 -0
  131. package/dist/hooks/usePrevious/usePrevious.cjs +38 -0
  132. package/{esm/hooks/usePrevious/index.d.ts → dist/hooks/usePrevious/usePrevious.d.cts} +4 -2
  133. package/dist/hooks/usePrevious/{index.d.cts → usePrevious.d.mts} +4 -2
  134. package/dist/hooks/usePrevious/usePrevious.mjs +38 -0
  135. package/dist/hooks/useRefEffect/index.d.cts +2 -30
  136. package/dist/hooks/useRefEffect/index.d.mts +3 -0
  137. package/dist/hooks/useRefEffect/useRefEffect.cjs +42 -0
  138. package/{esm/hooks/useRefEffect/index.d.ts → dist/hooks/useRefEffect/useRefEffect.d.cts} +4 -3
  139. package/dist/hooks/useRefEffect/useRefEffect.d.mts +32 -0
  140. package/dist/hooks/useRefEffect/useRefEffect.mjs +42 -0
  141. package/dist/hooks/useSet/useSet.cjs +79 -0
  142. package/dist/hooks/useSet/{index.d.cts → useSet.d.cts} +9 -7
  143. package/{esm/hooks/useSet/index.d.ts → dist/hooks/useSet/useSet.d.mts} +9 -7
  144. package/dist/hooks/useSet/useSet.mjs +79 -0
  145. package/dist/hooks/useStorageState/index.d.cts +2 -60
  146. package/dist/hooks/useStorageState/index.d.mts +3 -0
  147. package/dist/hooks/useStorageState/storage.cjs +85 -0
  148. package/dist/hooks/useStorageState/storage.d.cts +10 -0
  149. package/dist/hooks/useStorageState/storage.d.mts +10 -0
  150. package/dist/hooks/useStorageState/storage.mjs +80 -0
  151. package/dist/hooks/useStorageState/useStorageState.cjs +81 -0
  152. package/{esm/hooks/useStorageState/index.d.ts → dist/hooks/useStorageState/useStorageState.d.cts} +10 -15
  153. package/dist/hooks/useStorageState/useStorageState.d.mts +56 -0
  154. package/dist/hooks/useStorageState/useStorageState.mjs +81 -0
  155. package/dist/hooks/useThrottle/throttle.cjs +19 -0
  156. package/dist/hooks/useThrottle/throttle.d.cts +19 -0
  157. package/dist/hooks/useThrottle/throttle.d.mts +19 -0
  158. package/dist/hooks/useThrottle/throttle.mjs +19 -0
  159. package/dist/hooks/useThrottle/useThrottle.cjs +49 -0
  160. package/dist/hooks/useThrottle/{index.d.cts → useThrottle.d.cts} +6 -19
  161. package/{esm/hooks/useThrottle/index.d.ts → dist/hooks/useThrottle/useThrottle.d.mts} +6 -19
  162. package/dist/hooks/useThrottle/useThrottle.mjs +49 -0
  163. package/dist/hooks/useThrottledCallback/useThrottledCallback.cjs +57 -0
  164. package/{esm/hooks/useThrottledCallback/index.d.ts → dist/hooks/useThrottledCallback/useThrottledCallback.d.cts} +8 -6
  165. package/dist/hooks/useThrottledCallback/{index.d.cts → useThrottledCallback.d.mts} +8 -6
  166. package/dist/hooks/useThrottledCallback/useThrottledCallback.mjs +57 -0
  167. package/dist/hooks/useTimeout/useTimeout.cjs +40 -0
  168. package/dist/hooks/useTimeout/{index.d.cts → useTimeout.d.cts} +4 -2
  169. package/{esm/hooks/useTimeout/index.d.ts → dist/hooks/useTimeout/useTimeout.d.mts} +4 -2
  170. package/dist/hooks/useTimeout/useTimeout.mjs +40 -0
  171. package/dist/hooks/useToggle/useToggle.cjs +34 -0
  172. package/dist/hooks/useToggle/{index.d.cts → useToggle.d.cts} +4 -4
  173. package/{esm/hooks/useToggle/index.d.ts → dist/hooks/useToggle/useToggle.d.mts} +4 -4
  174. package/dist/hooks/useToggle/useToggle.mjs +34 -0
  175. package/dist/hooks/useVisibilityEvent/useVisibilityEvent.cjs +42 -0
  176. package/{esm/hooks/useVisibilityEvent/index.d.ts → dist/hooks/useVisibilityEvent/useVisibilityEvent.d.cts} +5 -3
  177. package/dist/hooks/useVisibilityEvent/{index.d.cts → useVisibilityEvent.d.mts} +5 -3
  178. package/dist/hooks/useVisibilityEvent/useVisibilityEvent.mjs +42 -0
  179. package/dist/index.cjs +77 -1382
  180. package/dist/index.d.cts +56 -40
  181. package/dist/index.d.mts +56 -0
  182. package/dist/index.mjs +40 -0
  183. package/dist/utils/buildContext/buildContext.cjs +50 -0
  184. package/{esm/utils/buildContext/index.d.ts → dist/utils/buildContext/buildContext.d.cts} +7 -7
  185. package/dist/utils/buildContext/buildContext.d.mts +38 -0
  186. package/dist/utils/buildContext/buildContext.mjs +50 -0
  187. package/dist/utils/buildContext/index.d.cts +2 -37
  188. package/dist/utils/buildContext/index.d.mts +3 -0
  189. package/dist/utils/mergeProps/index.d.cts +2 -25
  190. package/dist/utils/mergeProps/index.d.mts +3 -0
  191. package/dist/utils/mergeProps/mergeProps.cjs +53 -0
  192. package/{esm/utils/mergeProps/index.d.ts → dist/utils/mergeProps/mergeProps.d.cts} +7 -8
  193. package/dist/utils/mergeProps/mergeProps.d.mts +25 -0
  194. package/dist/utils/mergeProps/mergeProps.mjs +53 -0
  195. package/dist/utils/mergeRefs/index.d.cts +2 -38
  196. package/dist/utils/mergeRefs/index.d.mts +3 -0
  197. package/dist/utils/mergeRefs/mergeRefs.cjs +50 -0
  198. package/{esm/utils/mergeRefs/index.d.ts → dist/utils/mergeRefs/mergeRefs.d.cts} +4 -3
  199. package/dist/utils/mergeRefs/mergeRefs.d.mts +40 -0
  200. package/dist/utils/mergeRefs/mergeRefs.mjs +50 -0
  201. package/package.json +9 -11
  202. package/dist/components/ImpressionArea/index.cjs +0 -295
  203. package/dist/components/Separated/index.cjs +0 -41
  204. package/dist/components/SwitchCase/index.cjs +0 -36
  205. package/dist/hooks/useAsyncEffect/index.cjs +0 -44
  206. package/dist/hooks/useBooleanState/index.cjs +0 -46
  207. package/dist/hooks/useCallbackOncePerRender/index.cjs +0 -63
  208. package/dist/hooks/useConditionalEffect/index.cjs +0 -51
  209. package/dist/hooks/useControlledState/index.cjs +0 -57
  210. package/dist/hooks/useCounter/index.cjs +0 -70
  211. package/dist/hooks/useDebounce/index.cjs +0 -130
  212. package/dist/hooks/useDebouncedCallback/index.cjs +0 -148
  213. package/dist/hooks/useDoubleClick/index.cjs +0 -79
  214. package/dist/hooks/useGeolocation/index.cjs +0 -154
  215. package/dist/hooks/useImpressionRef/index.cjs +0 -258
  216. package/dist/hooks/useInputState/index.cjs +0 -46
  217. package/dist/hooks/useIntersectionObserver/index.cjs +0 -95
  218. package/dist/hooks/useInterval/index.cjs +0 -74
  219. package/dist/hooks/useIsClient/index.cjs +0 -40
  220. package/dist/hooks/useIsomorphicLayoutEffect/index.cjs +0 -35
  221. package/dist/hooks/useList/index.cjs +0 -104
  222. package/dist/hooks/useLoading/index.cjs +0 -65
  223. package/dist/hooks/useLongPress/index.cjs +0 -127
  224. package/dist/hooks/useMap/index.cjs +0 -78
  225. package/dist/hooks/useOutsideClickEffect/index.cjs +0 -74
  226. package/dist/hooks/usePreservedCallback/index.cjs +0 -45
  227. package/dist/hooks/usePreservedReference/index.cjs +0 -45
  228. package/dist/hooks/usePrevious/index.cjs +0 -48
  229. package/dist/hooks/useRefEffect/index.cjs +0 -72
  230. package/dist/hooks/useSet/index.cjs +0 -105
  231. package/dist/hooks/useStorageState/index.cjs +0 -196
  232. package/dist/hooks/useThrottle/index.cjs +0 -151
  233. package/dist/hooks/useThrottledCallback/index.cjs +0 -172
  234. package/dist/hooks/useTimeout/index.cjs +0 -57
  235. package/dist/hooks/useToggle/index.cjs +0 -37
  236. package/dist/hooks/useVisibilityEvent/index.cjs +0 -47
  237. package/dist/utils/buildContext/index.cjs +0 -56
  238. package/dist/utils/mergeProps/index.cjs +0 -71
  239. package/dist/utils/mergeRefs/index.cjs +0 -46
  240. package/esm/components/ImpressionArea/index.js +0 -269
  241. package/esm/components/Separated/index.js +0 -15
  242. package/esm/components/SwitchCase/index.js +0 -10
  243. package/esm/hooks/useAsyncEffect/index.js +0 -18
  244. package/esm/hooks/useBooleanState/index.js +0 -20
  245. package/esm/hooks/useCallbackOncePerRender/index.js +0 -37
  246. package/esm/hooks/useConditionalEffect/index.js +0 -25
  247. package/esm/hooks/useControlledState/index.js +0 -31
  248. package/esm/hooks/useCounter/index.js +0 -44
  249. package/esm/hooks/useDebounce/index.js +0 -104
  250. package/esm/hooks/useDebouncedCallback/index.js +0 -122
  251. package/esm/hooks/useDoubleClick/index.js +0 -53
  252. package/esm/hooks/useGeolocation/index.js +0 -128
  253. package/esm/hooks/useImpressionRef/index.js +0 -232
  254. package/esm/hooks/useInputState/index.js +0 -20
  255. package/esm/hooks/useIntersectionObserver/index.js +0 -69
  256. package/esm/hooks/useInterval/index.js +0 -48
  257. package/esm/hooks/useIsClient/index.js +0 -14
  258. package/esm/hooks/useIsomorphicLayoutEffect/index.js +0 -9
  259. package/esm/hooks/useList/index.js +0 -78
  260. package/esm/hooks/useLoading/index.js +0 -39
  261. package/esm/hooks/useLongPress/index.js +0 -101
  262. package/esm/hooks/useMap/index.js +0 -52
  263. package/esm/hooks/useOutsideClickEffect/index.js +0 -48
  264. package/esm/hooks/usePreservedCallback/index.js +0 -19
  265. package/esm/hooks/usePreservedReference/index.js +0 -19
  266. package/esm/hooks/usePrevious/index.js +0 -22
  267. package/esm/hooks/useRefEffect/index.js +0 -46
  268. package/esm/hooks/useSet/index.js +0 -79
  269. package/esm/hooks/useStorageState/index.js +0 -170
  270. package/esm/hooks/useThrottle/index.js +0 -125
  271. package/esm/hooks/useThrottledCallback/index.js +0 -146
  272. package/esm/hooks/useTimeout/index.js +0 -31
  273. package/esm/hooks/useToggle/index.js +0 -11
  274. package/esm/hooks/useVisibilityEvent/index.js +0 -21
  275. package/esm/index.d.ts +0 -40
  276. package/esm/index.js +0 -1320
  277. package/esm/utils/buildContext/index.js +0 -30
  278. package/esm/utils/mergeProps/index.js +0 -45
  279. package/esm/utils/mergeRefs/index.js +0 -20
@@ -0,0 +1,66 @@
1
+ "use client";
2
+ const require_debounce = require("./debounce.cjs");
3
+ const require_usePreservedCallback = require("../usePreservedCallback/usePreservedCallback.cjs");
4
+ let react = require("react");
5
+ //#region src/hooks/useDebounce/useDebounce.ts
6
+ /**
7
+ * @description
8
+ * `useDebounce` is a React hook that returns a debounced version of the provided callback function.
9
+ * It helps optimize event handling by delaying function execution and grouping multiple calls into one.
10
+ *
11
+ * @template {(...args: any[]) => unknown} F - The type of the callback function.
12
+ * @param {F} callback - The function to debounce.
13
+ * @param {number} wait - The number of milliseconds to delay the function execution.
14
+ * @param {DebounceOptions} [options] - Configuration options for debounce behavior.
15
+ * @param {boolean} [options.leading=false] - If `true`, the function is called at the start of the sequence.
16
+ * @param {boolean} [options.trailing=true] - If `true`, the function is called at the end of the sequence.
17
+ *
18
+ * @returns {F & { cancel: () => void }} A debounced function that delays invoking the callback.
19
+ * It also includes a `cancel` method to cancel any pending debounced execution.
20
+ *
21
+ * @example
22
+ * function SearchInput() {
23
+ * const [query, setQuery] = useState('');
24
+ *
25
+ * const debouncedSearch = useDebounce((value: string) => {
26
+ * // Actual API call
27
+ * searchAPI(value);
28
+ * }, 300);
29
+ *
30
+ * return (
31
+ * <input
32
+ * value={query}
33
+ * onChange={e => {
34
+ * setQuery(e.target.value);
35
+ * debouncedSearch(e.target.value);
36
+ * }}
37
+ * placeholder="Enter search term"
38
+ * />
39
+ * );
40
+ * }
41
+ */
42
+ function useDebounce(callback, wait, options = {}) {
43
+ const preservedCallback = require_usePreservedCallback.usePreservedCallback(callback);
44
+ const { leading = false, trailing = true } = options;
45
+ const edges = (0, react.useMemo)(() => {
46
+ const _edges = [];
47
+ if (leading) _edges.push("leading");
48
+ if (trailing) _edges.push("trailing");
49
+ return _edges;
50
+ }, [leading, trailing]);
51
+ const debounced = (0, react.useMemo)(() => {
52
+ return require_debounce.debounce(preservedCallback, wait, { edges });
53
+ }, [
54
+ preservedCallback,
55
+ wait,
56
+ edges
57
+ ]);
58
+ (0, react.useEffect)(function cancelDebouncedOnUnmount() {
59
+ return () => {
60
+ debounced.cancel();
61
+ };
62
+ }, [debounced]);
63
+ return debounced;
64
+ }
65
+ //#endregion
66
+ exports.useDebounce = useDebounce;
@@ -1,11 +1,9 @@
1
- type DebouncedFunction<F extends (...args: any[]) => void> = {
2
- (...args: Parameters<F>): void;
3
- cancel: () => void;
4
- };
5
1
 
2
+ import { DebouncedFunction } from "./debounce.cjs";
3
+ //#region src/hooks/useDebounce/useDebounce.d.ts
6
4
  type DebounceOptions = {
7
- leading?: boolean;
8
- trailing?: boolean;
5
+ leading?: boolean;
6
+ trailing?: boolean;
9
7
  };
10
8
  /**
11
9
  * @description
@@ -44,5 +42,5 @@ type DebounceOptions = {
44
42
  * }
45
43
  */
46
44
  declare function useDebounce<F extends (...args: any[]) => unknown>(callback: F, wait: number, options?: DebounceOptions): DebouncedFunction<F>;
47
-
48
- export { useDebounce };
45
+ //#endregion
46
+ export { useDebounce };
@@ -1,11 +1,9 @@
1
- type DebouncedFunction<F extends (...args: any[]) => void> = {
2
- (...args: Parameters<F>): void;
3
- cancel: () => void;
4
- };
5
1
 
2
+ import { DebouncedFunction } from "./debounce.mjs";
3
+ //#region src/hooks/useDebounce/useDebounce.d.ts
6
4
  type DebounceOptions = {
7
- leading?: boolean;
8
- trailing?: boolean;
5
+ leading?: boolean;
6
+ trailing?: boolean;
9
7
  };
10
8
  /**
11
9
  * @description
@@ -44,5 +42,5 @@ type DebounceOptions = {
44
42
  * }
45
43
  */
46
44
  declare function useDebounce<F extends (...args: any[]) => unknown>(callback: F, wait: number, options?: DebounceOptions): DebouncedFunction<F>;
47
-
48
- export { useDebounce };
45
+ //#endregion
46
+ export { useDebounce };
@@ -0,0 +1,66 @@
1
+ "use client";
2
+ import { debounce } from "./debounce.mjs";
3
+ import { usePreservedCallback } from "../usePreservedCallback/usePreservedCallback.mjs";
4
+ import { useEffect, useMemo } from "react";
5
+ //#region src/hooks/useDebounce/useDebounce.ts
6
+ /**
7
+ * @description
8
+ * `useDebounce` is a React hook that returns a debounced version of the provided callback function.
9
+ * It helps optimize event handling by delaying function execution and grouping multiple calls into one.
10
+ *
11
+ * @template {(...args: any[]) => unknown} F - The type of the callback function.
12
+ * @param {F} callback - The function to debounce.
13
+ * @param {number} wait - The number of milliseconds to delay the function execution.
14
+ * @param {DebounceOptions} [options] - Configuration options for debounce behavior.
15
+ * @param {boolean} [options.leading=false] - If `true`, the function is called at the start of the sequence.
16
+ * @param {boolean} [options.trailing=true] - If `true`, the function is called at the end of the sequence.
17
+ *
18
+ * @returns {F & { cancel: () => void }} A debounced function that delays invoking the callback.
19
+ * It also includes a `cancel` method to cancel any pending debounced execution.
20
+ *
21
+ * @example
22
+ * function SearchInput() {
23
+ * const [query, setQuery] = useState('');
24
+ *
25
+ * const debouncedSearch = useDebounce((value: string) => {
26
+ * // Actual API call
27
+ * searchAPI(value);
28
+ * }, 300);
29
+ *
30
+ * return (
31
+ * <input
32
+ * value={query}
33
+ * onChange={e => {
34
+ * setQuery(e.target.value);
35
+ * debouncedSearch(e.target.value);
36
+ * }}
37
+ * placeholder="Enter search term"
38
+ * />
39
+ * );
40
+ * }
41
+ */
42
+ function useDebounce(callback, wait, options = {}) {
43
+ const preservedCallback = usePreservedCallback(callback);
44
+ const { leading = false, trailing = true } = options;
45
+ const edges = useMemo(() => {
46
+ const _edges = [];
47
+ if (leading) _edges.push("leading");
48
+ if (trailing) _edges.push("trailing");
49
+ return _edges;
50
+ }, [leading, trailing]);
51
+ const debounced = useMemo(() => {
52
+ return debounce(preservedCallback, wait, { edges });
53
+ }, [
54
+ preservedCallback,
55
+ wait,
56
+ edges
57
+ ]);
58
+ useEffect(function cancelDebouncedOnUnmount() {
59
+ return () => {
60
+ debounced.cancel();
61
+ };
62
+ }, [debounced]);
63
+ return debounced;
64
+ }
65
+ //#endregion
66
+ export { useDebounce };
@@ -0,0 +1,62 @@
1
+ "use client";
2
+ const require_debounce = require("../useDebounce/debounce.cjs");
3
+ const require_usePreservedCallback = require("../usePreservedCallback/usePreservedCallback.cjs");
4
+ let react = require("react");
5
+ //#region src/hooks/useDebouncedCallback/useDebouncedCallback.ts
6
+ /**
7
+ * @description
8
+ * `useDebouncedCallback` is a React hook that returns a debounced version of the provided callback function.
9
+ * It helps optimize event handling by delaying function execution and grouping multiple calls into one.
10
+ *
11
+ * Note that if both 'leading' and 'trailing' are set, the function will be called at both the start and end of the delay period. However, it must be called at least twice within debounceMs interval for this to happen, since one debounced function call cannot trigger the function twice.
12
+ *
13
+ * @param {Object} options - The options object.
14
+ * @param {Function} options.onChange - The callback function to debounce.
15
+ * @param {number} options.timeThreshold - The number of milliseconds to delay the function execution.
16
+ * @param {boolean} [options.leading=false] - If `true`, the function is called at the start of the sequence.
17
+ * @param {boolean} [options.trailing=true] - If `true`, the function is called at the end of the sequence.
18
+ *
19
+ * @returns {Function} A debounced function that delays invoking the callback.
20
+ *
21
+ * @example
22
+ * function SearchInput() {
23
+ * const [query, setQuery] = useState('');
24
+ * const debouncedSetQuery = useDebouncedCallback({ onChange: setQuery, timeThreshold: 100 });
25
+ * return <input type="text" onChange={(e) => debouncedSetQuery(e.target.value)} />;
26
+ * }
27
+ */
28
+ function useDebouncedCallback({ onChange, timeThreshold, leading = false, trailing = true }) {
29
+ const handleChange = require_usePreservedCallback.usePreservedCallback(onChange);
30
+ const ref = (0, react.useRef)({
31
+ value: false,
32
+ clearPreviousDebounce: () => {}
33
+ });
34
+ (0, react.useEffect)(function clearDebouncedOnUnmount() {
35
+ const current = ref.current;
36
+ return () => {
37
+ current.clearPreviousDebounce();
38
+ };
39
+ }, []);
40
+ const edges = (0, react.useMemo)(() => {
41
+ const _edges = [];
42
+ if (leading) _edges.push("leading");
43
+ if (trailing) _edges.push("trailing");
44
+ return _edges;
45
+ }, [leading, trailing]);
46
+ return (0, react.useCallback)((nextValue) => {
47
+ if (nextValue === ref.current.value) return;
48
+ const debounced = require_debounce.debounce(() => {
49
+ handleChange(nextValue);
50
+ ref.current.value = nextValue;
51
+ }, timeThreshold, { edges });
52
+ ref.current.clearPreviousDebounce();
53
+ debounced();
54
+ ref.current.clearPreviousDebounce = debounced.cancel;
55
+ }, [
56
+ handleChange,
57
+ timeThreshold,
58
+ edges
59
+ ]);
60
+ }
61
+ //#endregion
62
+ exports.useDebouncedCallback = useDebouncedCallback;
@@ -1,6 +1,8 @@
1
+
2
+ //#region src/hooks/useDebouncedCallback/useDebouncedCallback.d.ts
1
3
  type DebounceOptions = {
2
- leading?: boolean;
3
- trailing?: boolean;
4
+ leading?: boolean;
5
+ trailing?: boolean;
4
6
  };
5
7
  /**
6
8
  * @description
@@ -24,9 +26,9 @@ type DebounceOptions = {
24
26
  * return <input type="text" onChange={(e) => debouncedSetQuery(e.target.value)} />;
25
27
  * }
26
28
  */
27
- declare function useDebouncedCallback({ onChange, timeThreshold, leading, trailing, }: DebounceOptions & {
28
- onChange: (newValue: boolean) => void;
29
- timeThreshold: number;
29
+ declare function useDebouncedCallback({ onChange, timeThreshold, leading, trailing }: DebounceOptions & {
30
+ onChange: (newValue: boolean) => void;
31
+ timeThreshold: number;
30
32
  }): (nextValue: boolean) => void;
31
-
32
- export { useDebouncedCallback };
33
+ //#endregion
34
+ export { useDebouncedCallback };
@@ -1,6 +1,8 @@
1
+
2
+ //#region src/hooks/useDebouncedCallback/useDebouncedCallback.d.ts
1
3
  type DebounceOptions = {
2
- leading?: boolean;
3
- trailing?: boolean;
4
+ leading?: boolean;
5
+ trailing?: boolean;
4
6
  };
5
7
  /**
6
8
  * @description
@@ -24,9 +26,9 @@ type DebounceOptions = {
24
26
  * return <input type="text" onChange={(e) => debouncedSetQuery(e.target.value)} />;
25
27
  * }
26
28
  */
27
- declare function useDebouncedCallback({ onChange, timeThreshold, leading, trailing, }: DebounceOptions & {
28
- onChange: (newValue: boolean) => void;
29
- timeThreshold: number;
29
+ declare function useDebouncedCallback({ onChange, timeThreshold, leading, trailing }: DebounceOptions & {
30
+ onChange: (newValue: boolean) => void;
31
+ timeThreshold: number;
30
32
  }): (nextValue: boolean) => void;
31
-
32
- export { useDebouncedCallback };
33
+ //#endregion
34
+ export { useDebouncedCallback };
@@ -0,0 +1,62 @@
1
+ "use client";
2
+ import { debounce } from "../useDebounce/debounce.mjs";
3
+ import { usePreservedCallback } from "../usePreservedCallback/usePreservedCallback.mjs";
4
+ import { useCallback, useEffect, useMemo, useRef } from "react";
5
+ //#region src/hooks/useDebouncedCallback/useDebouncedCallback.ts
6
+ /**
7
+ * @description
8
+ * `useDebouncedCallback` is a React hook that returns a debounced version of the provided callback function.
9
+ * It helps optimize event handling by delaying function execution and grouping multiple calls into one.
10
+ *
11
+ * Note that if both 'leading' and 'trailing' are set, the function will be called at both the start and end of the delay period. However, it must be called at least twice within debounceMs interval for this to happen, since one debounced function call cannot trigger the function twice.
12
+ *
13
+ * @param {Object} options - The options object.
14
+ * @param {Function} options.onChange - The callback function to debounce.
15
+ * @param {number} options.timeThreshold - The number of milliseconds to delay the function execution.
16
+ * @param {boolean} [options.leading=false] - If `true`, the function is called at the start of the sequence.
17
+ * @param {boolean} [options.trailing=true] - If `true`, the function is called at the end of the sequence.
18
+ *
19
+ * @returns {Function} A debounced function that delays invoking the callback.
20
+ *
21
+ * @example
22
+ * function SearchInput() {
23
+ * const [query, setQuery] = useState('');
24
+ * const debouncedSetQuery = useDebouncedCallback({ onChange: setQuery, timeThreshold: 100 });
25
+ * return <input type="text" onChange={(e) => debouncedSetQuery(e.target.value)} />;
26
+ * }
27
+ */
28
+ function useDebouncedCallback({ onChange, timeThreshold, leading = false, trailing = true }) {
29
+ const handleChange = usePreservedCallback(onChange);
30
+ const ref = useRef({
31
+ value: false,
32
+ clearPreviousDebounce: () => {}
33
+ });
34
+ useEffect(function clearDebouncedOnUnmount() {
35
+ const current = ref.current;
36
+ return () => {
37
+ current.clearPreviousDebounce();
38
+ };
39
+ }, []);
40
+ const edges = useMemo(() => {
41
+ const _edges = [];
42
+ if (leading) _edges.push("leading");
43
+ if (trailing) _edges.push("trailing");
44
+ return _edges;
45
+ }, [leading, trailing]);
46
+ return useCallback((nextValue) => {
47
+ if (nextValue === ref.current.value) return;
48
+ const debounced = debounce(() => {
49
+ handleChange(nextValue);
50
+ ref.current.value = nextValue;
51
+ }, timeThreshold, { edges });
52
+ ref.current.clearPreviousDebounce();
53
+ debounced();
54
+ ref.current.clearPreviousDebounce = debounced.cancel;
55
+ }, [
56
+ handleChange,
57
+ timeThreshold,
58
+ edges
59
+ ]);
60
+ }
61
+ //#endregion
62
+ export { useDebouncedCallback };
@@ -1,46 +1,3 @@
1
- import { MouseEvent } from 'react';
2
1
 
3
- type UseDoubleClickProps<E extends HTMLElement> = {
4
- delay?: number;
5
- click?: (event: MouseEvent<E>) => void;
6
- doubleClick: (event: MouseEvent<E>) => void;
7
- };
8
- /**
9
- * @deprecated This hook is deprecated as it depends on browser-specific APIs (DOM events, window.setTimeout).
10
- * react-simplikit is now focused on platform-independent, pure state/logic hooks.
11
- * This hook will be removed in a future major version.
12
- *
13
- * @description
14
- * `useDoubleClick` is a React hook that differentiates between single and double click events.
15
- * It delays the single click callback execution for a specified time, and cancels it if a second click (i.e. a double click) occurs within that time.
16
- *
17
- * @template {HTMLElement} E - The specific type of HTMLElement to be used with this hook (e.g., HTMLButtonElement, HTMLDivElement).
18
- * @param {Object} props - Configuration options for click handling.
19
- * @param {number} [props.delay=250] - The number of milliseconds to wait before triggering the single click callback. Defaults to 250ms.
20
- * @param {(event: MouseEvent<E>) => void} [props.click] - The callback function to be executed on a single click.
21
- * @param {(event: MouseEvent<E>) => void} props.doubleClick - The callback function to be executed on a double click. Required.
22
- *
23
- * @returns {(event: MouseEvent<E>) => void} A click handler function to attach to an element's `onClick` event.
24
- *
25
- * @example
26
- * function GalleryCard() {
27
- * const [selected, setSelected] = useState(false);
28
- *
29
- * const handleClick = () => setSelected((prev) => !prev);
30
- * const handleDoubleClick = () => alert('Zoom in!');
31
- *
32
- * const handleEvent = useDoubleClick({
33
- * click: handleClick,
34
- * doubleClick: handleDoubleClick,
35
- * });
36
- *
37
- * return (
38
- * <div onClick={handleEvent}>
39
- * {selected ? 'Selected' : 'Not selected'}
40
- * </div>
41
- * );
42
- * }
43
- */
44
- declare function useDoubleClick<E extends HTMLElement = HTMLElement>({ delay, click, doubleClick, }: UseDoubleClickProps<E>): (event: MouseEvent<E>) => void;
45
-
46
- export { useDoubleClick };
2
+ import { useDoubleClick } from "./useDoubleClick.cjs";
3
+ export { useDoubleClick };
@@ -0,0 +1,3 @@
1
+
2
+ import { useDoubleClick } from "./useDoubleClick.mjs";
3
+ export { useDoubleClick };
@@ -0,0 +1,64 @@
1
+ "use client";
2
+ const require_usePreservedCallback = require("../usePreservedCallback/usePreservedCallback.cjs");
3
+ let react = require("react");
4
+ //#region src/hooks/useDoubleClick/useDoubleClick.ts
5
+ /**
6
+ * @deprecated This hook is deprecated as it depends on browser-specific APIs (DOM events, window.setTimeout).
7
+ * react-simplikit is now focused on platform-independent, pure state/logic hooks.
8
+ * This hook will be removed in a future major version.
9
+ *
10
+ * @description
11
+ * `useDoubleClick` is a React hook that differentiates between single and double click events.
12
+ * It delays the single click callback execution for a specified time, and cancels it if a second click (i.e. a double click) occurs within that time.
13
+ *
14
+ * @template {HTMLElement} E - The specific type of HTMLElement to be used with this hook (e.g., HTMLButtonElement, HTMLDivElement).
15
+ * @param {Object} props - Configuration options for click handling.
16
+ * @param {number} [props.delay=250] - The number of milliseconds to wait before triggering the single click callback. Defaults to 250ms.
17
+ * @param {(event: MouseEvent<E>) => void} [props.click] - The callback function to be executed on a single click.
18
+ * @param {(event: MouseEvent<E>) => void} props.doubleClick - The callback function to be executed on a double click. Required.
19
+ *
20
+ * @returns {(event: MouseEvent<E>) => void} A click handler function to attach to an element's `onClick` event.
21
+ *
22
+ * @example
23
+ * function GalleryCard() {
24
+ * const [selected, setSelected] = useState(false);
25
+ *
26
+ * const handleClick = () => setSelected((prev) => !prev);
27
+ * const handleDoubleClick = () => alert('Zoom in!');
28
+ *
29
+ * const handleEvent = useDoubleClick({
30
+ * click: handleClick,
31
+ * doubleClick: handleDoubleClick,
32
+ * });
33
+ *
34
+ * return (
35
+ * <div onClick={handleEvent}>
36
+ * {selected ? 'Selected' : 'Not selected'}
37
+ * </div>
38
+ * );
39
+ * }
40
+ */
41
+ function useDoubleClick({ delay = 250, click, doubleClick }) {
42
+ const clickTimeout = (0, react.useRef)(null);
43
+ const clearClickTimeout = require_usePreservedCallback.usePreservedCallback(() => {
44
+ if (clickTimeout.current != null) {
45
+ window.clearTimeout(clickTimeout.current);
46
+ clickTimeout.current = null;
47
+ }
48
+ });
49
+ (0, react.useEffect)(() => () => clearClickTimeout(), [clearClickTimeout]);
50
+ return (0, react.useCallback)((event) => {
51
+ clearClickTimeout();
52
+ if (click && event.detail === 1) clickTimeout.current = window.setTimeout(() => {
53
+ click(event);
54
+ }, delay);
55
+ if (event.detail === 2) doubleClick(event);
56
+ }, [
57
+ click,
58
+ doubleClick,
59
+ delay,
60
+ clearClickTimeout
61
+ ]);
62
+ }
63
+ //#endregion
64
+ exports.useDoubleClick = useDoubleClick;
@@ -1,9 +1,10 @@
1
- import { MouseEvent } from 'react';
2
1
 
2
+ import { MouseEvent } from "react";
3
+ //#region src/hooks/useDoubleClick/useDoubleClick.d.ts
3
4
  type UseDoubleClickProps<E extends HTMLElement> = {
4
- delay?: number;
5
- click?: (event: MouseEvent<E>) => void;
6
- doubleClick: (event: MouseEvent<E>) => void;
5
+ delay?: number;
6
+ click?: (event: MouseEvent<E>) => void;
7
+ doubleClick: (event: MouseEvent<E>) => void;
7
8
  };
8
9
  /**
9
10
  * @deprecated This hook is deprecated as it depends on browser-specific APIs (DOM events, window.setTimeout).
@@ -41,6 +42,6 @@ type UseDoubleClickProps<E extends HTMLElement> = {
41
42
  * );
42
43
  * }
43
44
  */
44
- declare function useDoubleClick<E extends HTMLElement = HTMLElement>({ delay, click, doubleClick, }: UseDoubleClickProps<E>): (event: MouseEvent<E>) => void;
45
-
46
- export { useDoubleClick };
45
+ declare function useDoubleClick<E extends HTMLElement = HTMLElement>({ delay, click, doubleClick }: UseDoubleClickProps<E>): (event: MouseEvent<E>) => void;
46
+ //#endregion
47
+ export { useDoubleClick };
@@ -0,0 +1,47 @@
1
+
2
+ import { MouseEvent } from "react";
3
+ //#region src/hooks/useDoubleClick/useDoubleClick.d.ts
4
+ type UseDoubleClickProps<E extends HTMLElement> = {
5
+ delay?: number;
6
+ click?: (event: MouseEvent<E>) => void;
7
+ doubleClick: (event: MouseEvent<E>) => void;
8
+ };
9
+ /**
10
+ * @deprecated This hook is deprecated as it depends on browser-specific APIs (DOM events, window.setTimeout).
11
+ * react-simplikit is now focused on platform-independent, pure state/logic hooks.
12
+ * This hook will be removed in a future major version.
13
+ *
14
+ * @description
15
+ * `useDoubleClick` is a React hook that differentiates between single and double click events.
16
+ * It delays the single click callback execution for a specified time, and cancels it if a second click (i.e. a double click) occurs within that time.
17
+ *
18
+ * @template {HTMLElement} E - The specific type of HTMLElement to be used with this hook (e.g., HTMLButtonElement, HTMLDivElement).
19
+ * @param {Object} props - Configuration options for click handling.
20
+ * @param {number} [props.delay=250] - The number of milliseconds to wait before triggering the single click callback. Defaults to 250ms.
21
+ * @param {(event: MouseEvent<E>) => void} [props.click] - The callback function to be executed on a single click.
22
+ * @param {(event: MouseEvent<E>) => void} props.doubleClick - The callback function to be executed on a double click. Required.
23
+ *
24
+ * @returns {(event: MouseEvent<E>) => void} A click handler function to attach to an element's `onClick` event.
25
+ *
26
+ * @example
27
+ * function GalleryCard() {
28
+ * const [selected, setSelected] = useState(false);
29
+ *
30
+ * const handleClick = () => setSelected((prev) => !prev);
31
+ * const handleDoubleClick = () => alert('Zoom in!');
32
+ *
33
+ * const handleEvent = useDoubleClick({
34
+ * click: handleClick,
35
+ * doubleClick: handleDoubleClick,
36
+ * });
37
+ *
38
+ * return (
39
+ * <div onClick={handleEvent}>
40
+ * {selected ? 'Selected' : 'Not selected'}
41
+ * </div>
42
+ * );
43
+ * }
44
+ */
45
+ declare function useDoubleClick<E extends HTMLElement = HTMLElement>({ delay, click, doubleClick }: UseDoubleClickProps<E>): (event: MouseEvent<E>) => void;
46
+ //#endregion
47
+ export { useDoubleClick };
@@ -0,0 +1,64 @@
1
+ "use client";
2
+ import { usePreservedCallback } from "../usePreservedCallback/usePreservedCallback.mjs";
3
+ import { useCallback, useEffect, useRef } from "react";
4
+ //#region src/hooks/useDoubleClick/useDoubleClick.ts
5
+ /**
6
+ * @deprecated This hook is deprecated as it depends on browser-specific APIs (DOM events, window.setTimeout).
7
+ * react-simplikit is now focused on platform-independent, pure state/logic hooks.
8
+ * This hook will be removed in a future major version.
9
+ *
10
+ * @description
11
+ * `useDoubleClick` is a React hook that differentiates between single and double click events.
12
+ * It delays the single click callback execution for a specified time, and cancels it if a second click (i.e. a double click) occurs within that time.
13
+ *
14
+ * @template {HTMLElement} E - The specific type of HTMLElement to be used with this hook (e.g., HTMLButtonElement, HTMLDivElement).
15
+ * @param {Object} props - Configuration options for click handling.
16
+ * @param {number} [props.delay=250] - The number of milliseconds to wait before triggering the single click callback. Defaults to 250ms.
17
+ * @param {(event: MouseEvent<E>) => void} [props.click] - The callback function to be executed on a single click.
18
+ * @param {(event: MouseEvent<E>) => void} props.doubleClick - The callback function to be executed on a double click. Required.
19
+ *
20
+ * @returns {(event: MouseEvent<E>) => void} A click handler function to attach to an element's `onClick` event.
21
+ *
22
+ * @example
23
+ * function GalleryCard() {
24
+ * const [selected, setSelected] = useState(false);
25
+ *
26
+ * const handleClick = () => setSelected((prev) => !prev);
27
+ * const handleDoubleClick = () => alert('Zoom in!');
28
+ *
29
+ * const handleEvent = useDoubleClick({
30
+ * click: handleClick,
31
+ * doubleClick: handleDoubleClick,
32
+ * });
33
+ *
34
+ * return (
35
+ * <div onClick={handleEvent}>
36
+ * {selected ? 'Selected' : 'Not selected'}
37
+ * </div>
38
+ * );
39
+ * }
40
+ */
41
+ function useDoubleClick({ delay = 250, click, doubleClick }) {
42
+ const clickTimeout = useRef(null);
43
+ const clearClickTimeout = usePreservedCallback(() => {
44
+ if (clickTimeout.current != null) {
45
+ window.clearTimeout(clickTimeout.current);
46
+ clickTimeout.current = null;
47
+ }
48
+ });
49
+ useEffect(() => () => clearClickTimeout(), [clearClickTimeout]);
50
+ return useCallback((event) => {
51
+ clearClickTimeout();
52
+ if (click && event.detail === 1) clickTimeout.current = window.setTimeout(() => {
53
+ click(event);
54
+ }, delay);
55
+ if (event.detail === 2) doubleClick(event);
56
+ }, [
57
+ click,
58
+ doubleClick,
59
+ delay,
60
+ clearClickTimeout
61
+ ]);
62
+ }
63
+ //#endregion
64
+ export { useDoubleClick };