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,133 @@
1
+ "use client";
2
+ const require_usePreservedCallback = require("../usePreservedCallback/usePreservedCallback.cjs");
3
+ let react = require("react");
4
+ //#region src/hooks/useLongPress/useLongPress.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
+ * `useLongPress` is a React hook that detects when an element is pressed and held for a specified duration.
12
+ * It handles both mouse and touch events, making it work consistently across desktop and mobile devices.
13
+ *
14
+ * @template {HTMLElement} E - The HTML element type that will use the long press handlers.
15
+ * @param {(event: React.MouseEvent<E> | React.TouchEvent<E>) => void} onLongPress - The callback function to be executed when a long press is detected.
16
+ * @param {UseLongPressOptions} [options] - Configuration options for the long press behavior.
17
+ * @param {number} [options.delay=500] - The time in milliseconds before triggering the long press. Defaults to 500ms.
18
+ * @param {Object} [options.moveThreshold] - Maximum movement allowed before canceling a long press.
19
+ * @param {number} [options.moveThreshold.x] - Maximum horizontal movement in pixels.
20
+ * @param {number} [options.moveThreshold.y] - Maximum vertical movement in pixels.
21
+ * @param {(event) => void} [options.onClick] - Optional function to execute on a normal click (press and release before delay).
22
+ * @param {(event) => void} [options.onLongPressEnd] - Optional function to execute when a long press ends.
23
+ *
24
+ * @returns {Object} Event handlers to attach to an element.
25
+ * - onMouseDown `(event: MouseEvent<E> | TouchEvent<E>) => void` - Event handler for mouse down events.
26
+ * - onMouseUp `(event: MouseEvent<E> | TouchEvent<E>) => void` - Event handler for mouse up events.
27
+ * - onMouseLeave `(event: MouseEvent<E> | TouchEvent<E>) => void` - Event handler for mouse leave events.
28
+ * - onTouchStart `(event: MouseEvent<E> | TouchEvent<E>) => void` - Event handler for touch start events.
29
+ * - onTouchEnd `(event: MouseEvent<E> | TouchEvent<E>) => void` - Event handler for touch end events.
30
+ * - onMouseMove `(event: MouseEvent<E> | TouchEvent<E>) => void` - Event handler for mouse move events. Included if `moveThreshold` is provided.
31
+ * - onTouchMove `(event: MouseEvent<E> | TouchEvent<E>) => void` - Event handler for touch move events. Included if `moveThreshold` is provided.
32
+ *
33
+ * @example
34
+ * import { useLongPress } from 'react-simplikit';
35
+ *
36
+ * function ContextMenu() {
37
+ * const [menuVisible, setMenuVisible] = useState(false);
38
+ *
39
+ * const longPressHandlers = useLongPress(
40
+ * () => setMenuVisible(true),
41
+ * {
42
+ * delay: 400,
43
+ * onClick: () => console.log('Normal click'),
44
+ * onLongPressEnd: () => console.log('Long press completed')
45
+ * }
46
+ * );
47
+ *
48
+ * return (
49
+ * <div>
50
+ * <button {...longPressHandlers}>Press and hold</button>
51
+ * {menuVisible && <div className="context-menu">Context Menu</div>}
52
+ * </div>
53
+ * );
54
+ * }
55
+ */
56
+ function useLongPress(onLongPress, { delay = 500, moveThreshold, onClick, onLongPressEnd } = {}) {
57
+ const timeoutRef = (0, react.useRef)(null);
58
+ const isLongPressActiveRef = (0, react.useRef)(false);
59
+ const initialPositionRef = (0, react.useRef)({
60
+ x: 0,
61
+ y: 0
62
+ });
63
+ const preservedOnLongPress = require_usePreservedCallback.usePreservedCallback(onLongPress);
64
+ const preservedOnClick = require_usePreservedCallback.usePreservedCallback(onClick || (() => {}));
65
+ const preservedOnLongPressEnd = require_usePreservedCallback.usePreservedCallback(onLongPressEnd || (() => {}));
66
+ const hasThreshold = moveThreshold?.x !== void 0 || moveThreshold?.y !== void 0;
67
+ const getClientPosition = (0, react.useCallback)((event) => {
68
+ if ("touches" in event.nativeEvent) {
69
+ const touch = event.nativeEvent.touches[0];
70
+ return {
71
+ x: touch.clientX,
72
+ y: touch.clientY
73
+ };
74
+ }
75
+ return {
76
+ x: event.nativeEvent.clientX,
77
+ y: event.nativeEvent.clientY
78
+ };
79
+ }, []);
80
+ const isMovedBeyondThreshold = (0, react.useCallback)((event) => {
81
+ const { x, y } = getClientPosition(event);
82
+ const deltaX = Math.abs(x - initialPositionRef.current.x);
83
+ const deltaY = Math.abs(y - initialPositionRef.current.y);
84
+ return moveThreshold?.x !== void 0 && deltaX > moveThreshold.x || moveThreshold?.y !== void 0 && deltaY > moveThreshold.y;
85
+ }, [getClientPosition, moveThreshold]);
86
+ const cancelLongPress = (0, react.useCallback)(() => {
87
+ if (timeoutRef.current !== null) {
88
+ window.clearTimeout(timeoutRef.current);
89
+ timeoutRef.current = null;
90
+ }
91
+ }, []);
92
+ const handlePressStart = (0, react.useCallback)((event) => {
93
+ cancelLongPress();
94
+ const position = getClientPosition(event);
95
+ initialPositionRef.current = position;
96
+ isLongPressActiveRef.current = false;
97
+ timeoutRef.current = window.setTimeout(() => {
98
+ isLongPressActiveRef.current = true;
99
+ preservedOnLongPress(event);
100
+ }, delay);
101
+ }, [
102
+ cancelLongPress,
103
+ delay,
104
+ getClientPosition,
105
+ preservedOnLongPress
106
+ ]);
107
+ const handlePressEnd = (0, react.useCallback)((event) => {
108
+ if (isLongPressActiveRef.current) preservedOnLongPressEnd(event);
109
+ else if (timeoutRef.current !== null) preservedOnClick(event);
110
+ cancelLongPress();
111
+ isLongPressActiveRef.current = false;
112
+ }, [
113
+ cancelLongPress,
114
+ preservedOnClick,
115
+ preservedOnLongPressEnd
116
+ ]);
117
+ const handlePressMove = (0, react.useCallback)((event) => {
118
+ if (timeoutRef.current !== null && isMovedBeyondThreshold(event)) cancelLongPress();
119
+ }, [cancelLongPress, isMovedBeyondThreshold]);
120
+ return {
121
+ onMouseDown: handlePressStart,
122
+ onMouseUp: handlePressEnd,
123
+ onMouseLeave: cancelLongPress,
124
+ onTouchStart: handlePressStart,
125
+ onTouchEnd: handlePressEnd,
126
+ ...hasThreshold ? {
127
+ onTouchMove: handlePressMove,
128
+ onMouseMove: handlePressMove
129
+ } : {}
130
+ };
131
+ }
132
+ //#endregion
133
+ exports.useLongPress = useLongPress;
@@ -1,14 +1,15 @@
1
- import { MouseEvent, TouchEvent } from 'react';
2
1
 
2
+ import { MouseEvent, TouchEvent } from "react";
3
+ //#region src/hooks/useLongPress/useLongPress.d.ts
3
4
  type Handler<E extends HTMLElement> = (event: MouseEvent<E> | TouchEvent<E>) => void;
4
5
  type UseLongPressOptions<E extends HTMLElement> = {
5
- delay?: number;
6
- moveThreshold?: {
7
- x?: number;
8
- y?: number;
9
- };
10
- onClick?: Handler<E>;
11
- onLongPressEnd?: Handler<E>;
6
+ delay?: number;
7
+ moveThreshold?: {
8
+ x?: number;
9
+ y?: number;
10
+ };
11
+ onClick?: Handler<E>;
12
+ onLongPressEnd?: Handler<E>;
12
13
  };
13
14
  /**
14
15
  * @deprecated This hook is deprecated as it depends on browser-specific APIs (DOM events, window.setTimeout).
@@ -62,13 +63,13 @@ type UseLongPressOptions<E extends HTMLElement> = {
62
63
  * }
63
64
  */
64
65
  declare function useLongPress<E extends HTMLElement = HTMLElement>(onLongPress: Handler<E>, { delay, moveThreshold, onClick, onLongPressEnd }?: UseLongPressOptions<E>): {
65
- onTouchMove?: ((event: MouseEvent<E> | TouchEvent<E>) => void) | undefined;
66
- onMouseMove?: ((event: MouseEvent<E> | TouchEvent<E>) => void) | undefined;
67
- onMouseDown: (event: MouseEvent<E> | TouchEvent<E>) => void;
68
- onMouseUp: (event: MouseEvent<E> | TouchEvent<E>) => void;
69
- onMouseLeave: () => void;
70
- onTouchStart: (event: MouseEvent<E> | TouchEvent<E>) => void;
71
- onTouchEnd: (event: MouseEvent<E> | TouchEvent<E>) => void;
66
+ onTouchMove?: ((event: MouseEvent<E> | TouchEvent<E>) => void) | undefined;
67
+ onMouseMove?: ((event: MouseEvent<E> | TouchEvent<E>) => void) | undefined;
68
+ onMouseDown: (event: MouseEvent<E> | TouchEvent<E>) => void;
69
+ onMouseUp: (event: MouseEvent<E> | TouchEvent<E>) => void;
70
+ onMouseLeave: () => void;
71
+ onTouchStart: (event: MouseEvent<E> | TouchEvent<E>) => void;
72
+ onTouchEnd: (event: MouseEvent<E> | TouchEvent<E>) => void;
72
73
  };
73
-
74
- export { useLongPress };
74
+ //#endregion
75
+ export { UseLongPressOptions, useLongPress };
@@ -0,0 +1,75 @@
1
+
2
+ import { MouseEvent, TouchEvent } from "react";
3
+ //#region src/hooks/useLongPress/useLongPress.d.ts
4
+ type Handler<E extends HTMLElement> = (event: MouseEvent<E> | TouchEvent<E>) => void;
5
+ type UseLongPressOptions<E extends HTMLElement> = {
6
+ delay?: number;
7
+ moveThreshold?: {
8
+ x?: number;
9
+ y?: number;
10
+ };
11
+ onClick?: Handler<E>;
12
+ onLongPressEnd?: Handler<E>;
13
+ };
14
+ /**
15
+ * @deprecated This hook is deprecated as it depends on browser-specific APIs (DOM events, window.setTimeout).
16
+ * react-simplikit is now focused on platform-independent, pure state/logic hooks.
17
+ * This hook will be removed in a future major version.
18
+ *
19
+ * @description
20
+ * `useLongPress` is a React hook that detects when an element is pressed and held for a specified duration.
21
+ * It handles both mouse and touch events, making it work consistently across desktop and mobile devices.
22
+ *
23
+ * @template {HTMLElement} E - The HTML element type that will use the long press handlers.
24
+ * @param {(event: React.MouseEvent<E> | React.TouchEvent<E>) => void} onLongPress - The callback function to be executed when a long press is detected.
25
+ * @param {UseLongPressOptions} [options] - Configuration options for the long press behavior.
26
+ * @param {number} [options.delay=500] - The time in milliseconds before triggering the long press. Defaults to 500ms.
27
+ * @param {Object} [options.moveThreshold] - Maximum movement allowed before canceling a long press.
28
+ * @param {number} [options.moveThreshold.x] - Maximum horizontal movement in pixels.
29
+ * @param {number} [options.moveThreshold.y] - Maximum vertical movement in pixels.
30
+ * @param {(event) => void} [options.onClick] - Optional function to execute on a normal click (press and release before delay).
31
+ * @param {(event) => void} [options.onLongPressEnd] - Optional function to execute when a long press ends.
32
+ *
33
+ * @returns {Object} Event handlers to attach to an element.
34
+ * - onMouseDown `(event: MouseEvent<E> | TouchEvent<E>) => void` - Event handler for mouse down events.
35
+ * - onMouseUp `(event: MouseEvent<E> | TouchEvent<E>) => void` - Event handler for mouse up events.
36
+ * - onMouseLeave `(event: MouseEvent<E> | TouchEvent<E>) => void` - Event handler for mouse leave events.
37
+ * - onTouchStart `(event: MouseEvent<E> | TouchEvent<E>) => void` - Event handler for touch start events.
38
+ * - onTouchEnd `(event: MouseEvent<E> | TouchEvent<E>) => void` - Event handler for touch end events.
39
+ * - onMouseMove `(event: MouseEvent<E> | TouchEvent<E>) => void` - Event handler for mouse move events. Included if `moveThreshold` is provided.
40
+ * - onTouchMove `(event: MouseEvent<E> | TouchEvent<E>) => void` - Event handler for touch move events. Included if `moveThreshold` is provided.
41
+ *
42
+ * @example
43
+ * import { useLongPress } from 'react-simplikit';
44
+ *
45
+ * function ContextMenu() {
46
+ * const [menuVisible, setMenuVisible] = useState(false);
47
+ *
48
+ * const longPressHandlers = useLongPress(
49
+ * () => setMenuVisible(true),
50
+ * {
51
+ * delay: 400,
52
+ * onClick: () => console.log('Normal click'),
53
+ * onLongPressEnd: () => console.log('Long press completed')
54
+ * }
55
+ * );
56
+ *
57
+ * return (
58
+ * <div>
59
+ * <button {...longPressHandlers}>Press and hold</button>
60
+ * {menuVisible && <div className="context-menu">Context Menu</div>}
61
+ * </div>
62
+ * );
63
+ * }
64
+ */
65
+ declare function useLongPress<E extends HTMLElement = HTMLElement>(onLongPress: Handler<E>, { delay, moveThreshold, onClick, onLongPressEnd }?: UseLongPressOptions<E>): {
66
+ onTouchMove?: ((event: MouseEvent<E> | TouchEvent<E>) => void) | undefined;
67
+ onMouseMove?: ((event: MouseEvent<E> | TouchEvent<E>) => void) | undefined;
68
+ onMouseDown: (event: MouseEvent<E> | TouchEvent<E>) => void;
69
+ onMouseUp: (event: MouseEvent<E> | TouchEvent<E>) => void;
70
+ onMouseLeave: () => void;
71
+ onTouchStart: (event: MouseEvent<E> | TouchEvent<E>) => void;
72
+ onTouchEnd: (event: MouseEvent<E> | TouchEvent<E>) => void;
73
+ };
74
+ //#endregion
75
+ export { UseLongPressOptions, useLongPress };
@@ -0,0 +1,133 @@
1
+ "use client";
2
+ import { usePreservedCallback } from "../usePreservedCallback/usePreservedCallback.mjs";
3
+ import { useCallback, useRef } from "react";
4
+ //#region src/hooks/useLongPress/useLongPress.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
+ * `useLongPress` is a React hook that detects when an element is pressed and held for a specified duration.
12
+ * It handles both mouse and touch events, making it work consistently across desktop and mobile devices.
13
+ *
14
+ * @template {HTMLElement} E - The HTML element type that will use the long press handlers.
15
+ * @param {(event: React.MouseEvent<E> | React.TouchEvent<E>) => void} onLongPress - The callback function to be executed when a long press is detected.
16
+ * @param {UseLongPressOptions} [options] - Configuration options for the long press behavior.
17
+ * @param {number} [options.delay=500] - The time in milliseconds before triggering the long press. Defaults to 500ms.
18
+ * @param {Object} [options.moveThreshold] - Maximum movement allowed before canceling a long press.
19
+ * @param {number} [options.moveThreshold.x] - Maximum horizontal movement in pixels.
20
+ * @param {number} [options.moveThreshold.y] - Maximum vertical movement in pixels.
21
+ * @param {(event) => void} [options.onClick] - Optional function to execute on a normal click (press and release before delay).
22
+ * @param {(event) => void} [options.onLongPressEnd] - Optional function to execute when a long press ends.
23
+ *
24
+ * @returns {Object} Event handlers to attach to an element.
25
+ * - onMouseDown `(event: MouseEvent<E> | TouchEvent<E>) => void` - Event handler for mouse down events.
26
+ * - onMouseUp `(event: MouseEvent<E> | TouchEvent<E>) => void` - Event handler for mouse up events.
27
+ * - onMouseLeave `(event: MouseEvent<E> | TouchEvent<E>) => void` - Event handler for mouse leave events.
28
+ * - onTouchStart `(event: MouseEvent<E> | TouchEvent<E>) => void` - Event handler for touch start events.
29
+ * - onTouchEnd `(event: MouseEvent<E> | TouchEvent<E>) => void` - Event handler for touch end events.
30
+ * - onMouseMove `(event: MouseEvent<E> | TouchEvent<E>) => void` - Event handler for mouse move events. Included if `moveThreshold` is provided.
31
+ * - onTouchMove `(event: MouseEvent<E> | TouchEvent<E>) => void` - Event handler for touch move events. Included if `moveThreshold` is provided.
32
+ *
33
+ * @example
34
+ * import { useLongPress } from 'react-simplikit';
35
+ *
36
+ * function ContextMenu() {
37
+ * const [menuVisible, setMenuVisible] = useState(false);
38
+ *
39
+ * const longPressHandlers = useLongPress(
40
+ * () => setMenuVisible(true),
41
+ * {
42
+ * delay: 400,
43
+ * onClick: () => console.log('Normal click'),
44
+ * onLongPressEnd: () => console.log('Long press completed')
45
+ * }
46
+ * );
47
+ *
48
+ * return (
49
+ * <div>
50
+ * <button {...longPressHandlers}>Press and hold</button>
51
+ * {menuVisible && <div className="context-menu">Context Menu</div>}
52
+ * </div>
53
+ * );
54
+ * }
55
+ */
56
+ function useLongPress(onLongPress, { delay = 500, moveThreshold, onClick, onLongPressEnd } = {}) {
57
+ const timeoutRef = useRef(null);
58
+ const isLongPressActiveRef = useRef(false);
59
+ const initialPositionRef = useRef({
60
+ x: 0,
61
+ y: 0
62
+ });
63
+ const preservedOnLongPress = usePreservedCallback(onLongPress);
64
+ const preservedOnClick = usePreservedCallback(onClick || (() => {}));
65
+ const preservedOnLongPressEnd = usePreservedCallback(onLongPressEnd || (() => {}));
66
+ const hasThreshold = moveThreshold?.x !== void 0 || moveThreshold?.y !== void 0;
67
+ const getClientPosition = useCallback((event) => {
68
+ if ("touches" in event.nativeEvent) {
69
+ const touch = event.nativeEvent.touches[0];
70
+ return {
71
+ x: touch.clientX,
72
+ y: touch.clientY
73
+ };
74
+ }
75
+ return {
76
+ x: event.nativeEvent.clientX,
77
+ y: event.nativeEvent.clientY
78
+ };
79
+ }, []);
80
+ const isMovedBeyondThreshold = useCallback((event) => {
81
+ const { x, y } = getClientPosition(event);
82
+ const deltaX = Math.abs(x - initialPositionRef.current.x);
83
+ const deltaY = Math.abs(y - initialPositionRef.current.y);
84
+ return moveThreshold?.x !== void 0 && deltaX > moveThreshold.x || moveThreshold?.y !== void 0 && deltaY > moveThreshold.y;
85
+ }, [getClientPosition, moveThreshold]);
86
+ const cancelLongPress = useCallback(() => {
87
+ if (timeoutRef.current !== null) {
88
+ window.clearTimeout(timeoutRef.current);
89
+ timeoutRef.current = null;
90
+ }
91
+ }, []);
92
+ const handlePressStart = useCallback((event) => {
93
+ cancelLongPress();
94
+ const position = getClientPosition(event);
95
+ initialPositionRef.current = position;
96
+ isLongPressActiveRef.current = false;
97
+ timeoutRef.current = window.setTimeout(() => {
98
+ isLongPressActiveRef.current = true;
99
+ preservedOnLongPress(event);
100
+ }, delay);
101
+ }, [
102
+ cancelLongPress,
103
+ delay,
104
+ getClientPosition,
105
+ preservedOnLongPress
106
+ ]);
107
+ const handlePressEnd = useCallback((event) => {
108
+ if (isLongPressActiveRef.current) preservedOnLongPressEnd(event);
109
+ else if (timeoutRef.current !== null) preservedOnClick(event);
110
+ cancelLongPress();
111
+ isLongPressActiveRef.current = false;
112
+ }, [
113
+ cancelLongPress,
114
+ preservedOnClick,
115
+ preservedOnLongPressEnd
116
+ ]);
117
+ const handlePressMove = useCallback((event) => {
118
+ if (timeoutRef.current !== null && isMovedBeyondThreshold(event)) cancelLongPress();
119
+ }, [cancelLongPress, isMovedBeyondThreshold]);
120
+ return {
121
+ onMouseDown: handlePressStart,
122
+ onMouseUp: handlePressEnd,
123
+ onMouseLeave: cancelLongPress,
124
+ onTouchStart: handlePressStart,
125
+ onTouchEnd: handlePressEnd,
126
+ ...hasThreshold ? {
127
+ onTouchMove: handlePressMove,
128
+ onMouseMove: handlePressMove
129
+ } : {}
130
+ };
131
+ }
132
+ //#endregion
133
+ export { useLongPress };
@@ -0,0 +1,64 @@
1
+ "use client";
2
+ const require_usePreservedReference = require("../usePreservedReference/usePreservedReference.cjs");
3
+ let react = require("react");
4
+ //#region src/hooks/useMap/useMap.ts
5
+ /**
6
+ * @description
7
+ * A React hook that manages a key-value Map as state.
8
+ * Provides efficient state management and stable action functions.
9
+ *
10
+ * @param {MapOrEntries<K, V>} initialState - Initial Map state (Map object or array of key-value pairs)
11
+ * @returns {UseMapReturn<K, V>} A tuple containing the Map state and actions to manipulate it
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * const [userMap, actions] = useMap<string, User>([
16
+ * ['user1', { name: 'John', age: 30 }]
17
+ * ]);
18
+ *
19
+ * // Using values from the Map
20
+ * const user1 = userMap.get('user1');
21
+ *
22
+ * // Updating the Map
23
+ * actions.set('user2', { name: 'Jane', age: 25 });
24
+ * ```
25
+ */
26
+ function useMap(initialState = /* @__PURE__ */ new Map()) {
27
+ const [map, setMap] = (0, react.useState)(() => new Map(initialState));
28
+ const preservedInitialState = require_usePreservedReference.usePreservedReference(initialState);
29
+ const set = (0, react.useCallback)((key, value) => {
30
+ setMap((prev) => {
31
+ const nextMap = new Map(prev);
32
+ nextMap.set(key, value);
33
+ return nextMap;
34
+ });
35
+ }, []);
36
+ const setAll = (0, react.useCallback)((entries) => {
37
+ setMap(() => new Map(entries));
38
+ }, []);
39
+ const remove = (0, react.useCallback)((key) => {
40
+ setMap((prev) => {
41
+ const nextMap = new Map(prev);
42
+ nextMap.delete(key);
43
+ return nextMap;
44
+ });
45
+ }, []);
46
+ const reset = (0, react.useCallback)(() => {
47
+ setMap(() => new Map(preservedInitialState));
48
+ }, [preservedInitialState]);
49
+ return [map, (0, react.useMemo)(() => {
50
+ return {
51
+ set,
52
+ setAll,
53
+ remove,
54
+ reset
55
+ };
56
+ }, [
57
+ set,
58
+ setAll,
59
+ remove,
60
+ reset
61
+ ])];
62
+ }
63
+ //#endregion
64
+ exports.useMap = useMap;
@@ -1,3 +1,5 @@
1
+
2
+ //#region src/hooks/useMap/useMap.d.ts
1
3
  /**
2
4
  * Defines the type for either a Map or an array of key-value pairs.
3
5
  */
@@ -6,14 +8,14 @@ type MapOrEntries<K, V> = Map<K, V> | [K, V][];
6
8
  * Actions to manipulate the Map state.
7
9
  */
8
10
  type MapActions<K, V> = {
9
- /** Sets a key-value pair in the map. */
10
- set: (key: K, value: V) => void;
11
- /** Sets multiple key-value pairs in the map at once. */
12
- setAll: (entries: MapOrEntries<K, V>) => void;
13
- /** Removes a key from the map. */
14
- remove: (key: K) => void;
15
- /** Resets the map to its initial state. */
16
- reset: () => void;
11
+ /** Sets a key-value pair in the map. */
12
+ set: (key: K, value: V) => void;
13
+ /** Sets multiple key-value pairs in the map at once. */
14
+ setAll: (entries: MapOrEntries<K, V>) => void;
15
+ /** Removes a key from the map. */
16
+ remove: (key: K) => void;
17
+ /** Resets the map to its initial state. */
18
+ reset: () => void;
17
19
  };
18
20
  /**
19
21
  * Return type of the useMap hook.
@@ -42,5 +44,5 @@ type UseMapReturn<K, V> = [Omit<Map<K, V>, 'set' | 'clear' | 'delete'>, MapActio
42
44
  * ```
43
45
  */
44
46
  declare function useMap<K, V>(initialState?: MapOrEntries<K, V>): UseMapReturn<K, V>;
45
-
46
- export { useMap };
47
+ //#endregion
48
+ export { useMap };
@@ -1,3 +1,5 @@
1
+
2
+ //#region src/hooks/useMap/useMap.d.ts
1
3
  /**
2
4
  * Defines the type for either a Map or an array of key-value pairs.
3
5
  */
@@ -6,14 +8,14 @@ type MapOrEntries<K, V> = Map<K, V> | [K, V][];
6
8
  * Actions to manipulate the Map state.
7
9
  */
8
10
  type MapActions<K, V> = {
9
- /** Sets a key-value pair in the map. */
10
- set: (key: K, value: V) => void;
11
- /** Sets multiple key-value pairs in the map at once. */
12
- setAll: (entries: MapOrEntries<K, V>) => void;
13
- /** Removes a key from the map. */
14
- remove: (key: K) => void;
15
- /** Resets the map to its initial state. */
16
- reset: () => void;
11
+ /** Sets a key-value pair in the map. */
12
+ set: (key: K, value: V) => void;
13
+ /** Sets multiple key-value pairs in the map at once. */
14
+ setAll: (entries: MapOrEntries<K, V>) => void;
15
+ /** Removes a key from the map. */
16
+ remove: (key: K) => void;
17
+ /** Resets the map to its initial state. */
18
+ reset: () => void;
17
19
  };
18
20
  /**
19
21
  * Return type of the useMap hook.
@@ -42,5 +44,5 @@ type UseMapReturn<K, V> = [Omit<Map<K, V>, 'set' | 'clear' | 'delete'>, MapActio
42
44
  * ```
43
45
  */
44
46
  declare function useMap<K, V>(initialState?: MapOrEntries<K, V>): UseMapReturn<K, V>;
45
-
46
- export { useMap };
47
+ //#endregion
48
+ export { useMap };
@@ -0,0 +1,64 @@
1
+ "use client";
2
+ import { usePreservedReference } from "../usePreservedReference/usePreservedReference.mjs";
3
+ import { useCallback, useMemo, useState } from "react";
4
+ //#region src/hooks/useMap/useMap.ts
5
+ /**
6
+ * @description
7
+ * A React hook that manages a key-value Map as state.
8
+ * Provides efficient state management and stable action functions.
9
+ *
10
+ * @param {MapOrEntries<K, V>} initialState - Initial Map state (Map object or array of key-value pairs)
11
+ * @returns {UseMapReturn<K, V>} A tuple containing the Map state and actions to manipulate it
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * const [userMap, actions] = useMap<string, User>([
16
+ * ['user1', { name: 'John', age: 30 }]
17
+ * ]);
18
+ *
19
+ * // Using values from the Map
20
+ * const user1 = userMap.get('user1');
21
+ *
22
+ * // Updating the Map
23
+ * actions.set('user2', { name: 'Jane', age: 25 });
24
+ * ```
25
+ */
26
+ function useMap(initialState = /* @__PURE__ */ new Map()) {
27
+ const [map, setMap] = useState(() => new Map(initialState));
28
+ const preservedInitialState = usePreservedReference(initialState);
29
+ const set = useCallback((key, value) => {
30
+ setMap((prev) => {
31
+ const nextMap = new Map(prev);
32
+ nextMap.set(key, value);
33
+ return nextMap;
34
+ });
35
+ }, []);
36
+ const setAll = useCallback((entries) => {
37
+ setMap(() => new Map(entries));
38
+ }, []);
39
+ const remove = useCallback((key) => {
40
+ setMap((prev) => {
41
+ const nextMap = new Map(prev);
42
+ nextMap.delete(key);
43
+ return nextMap;
44
+ });
45
+ }, []);
46
+ const reset = useCallback(() => {
47
+ setMap(() => new Map(preservedInitialState));
48
+ }, [preservedInitialState]);
49
+ return [map, useMemo(() => {
50
+ return {
51
+ set,
52
+ setAll,
53
+ remove,
54
+ reset
55
+ };
56
+ }, [
57
+ set,
58
+ setAll,
59
+ remove,
60
+ reset
61
+ ])];
62
+ }
63
+ //#endregion
64
+ export { useMap };
@@ -0,0 +1,51 @@
1
+ "use client";
2
+ const require_usePreservedCallback = require("../usePreservedCallback/usePreservedCallback.cjs");
3
+ let react = require("react");
4
+ //#region src/hooks/useOutsideClickEffect/useOutsideClickEffect.ts
5
+ /**
6
+ * @deprecated This hook is deprecated as it depends on browser-specific APIs (DOM events, document).
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
+ * `useOutsideClickEffect` is a React hook that triggers a callback when a click event occurs outside the specified container(s).
12
+ * It is useful for closing modals, dropdowns, tooltips, and other UI components when clicking outside.
13
+ *
14
+ * @param {HTMLElement | HTMLElement[] | null} container - A single HTML element, an array of HTML elements, or `null`.
15
+ * If `null`, no event listener is attached.
16
+ * @param {() => void} callback - A function that is executed when clicking outside the specified container(s).
17
+ *
18
+ * @example
19
+ * import { useOutsideClickEffect } from 'react-simplikit';
20
+ * import { useState } from 'react';
21
+ *
22
+ * function Example() {
23
+ * const [wrapperEl, setWrapperEl] = useState<HTMLDivElement | null>(null);
24
+ *
25
+ * useOutsideClickEffect(wrapperEl, () => {
26
+ * console.log('Outside clicked!');
27
+ * });
28
+ *
29
+ * return <div ref={setWrapperEl}>Content</div>;
30
+ * }
31
+ */
32
+ function useOutsideClickEffect(container, callback) {
33
+ const containers = (0, react.useRef)([]);
34
+ const handleDocumentClick = require_usePreservedCallback.usePreservedCallback(({ target }) => {
35
+ if (target === null) return;
36
+ if (containers.current.length === 0) return;
37
+ if (containers.current.some((x) => x.contains(target))) return;
38
+ callback();
39
+ });
40
+ (0, react.useEffect)(() => {
41
+ containers.current = [container].flat(1).filter((item) => item != null);
42
+ }, [container]);
43
+ (0, react.useEffect)(() => {
44
+ document.addEventListener("click", handleDocumentClick);
45
+ return () => {
46
+ document.removeEventListener("click", handleDocumentClick);
47
+ };
48
+ }, [handleDocumentClick]);
49
+ }
50
+ //#endregion
51
+ exports.useOutsideClickEffect = useOutsideClickEffect;
@@ -1,3 +1,5 @@
1
+
2
+ //#region src/hooks/useOutsideClickEffect/useOutsideClickEffect.d.ts
1
3
  type OneOrMore<T> = T | T[];
2
4
  /**
3
5
  * @deprecated This hook is deprecated as it depends on browser-specific APIs (DOM events, document).
@@ -27,5 +29,5 @@ type OneOrMore<T> = T | T[];
27
29
  * }
28
30
  */
29
31
  declare function useOutsideClickEffect(container: OneOrMore<HTMLElement | null>, callback: () => void): void;
30
-
31
- export { useOutsideClickEffect };
32
+ //#endregion
33
+ export { useOutsideClickEffect };
@@ -1,3 +1,5 @@
1
+
2
+ //#region src/hooks/useOutsideClickEffect/useOutsideClickEffect.d.ts
1
3
  type OneOrMore<T> = T | T[];
2
4
  /**
3
5
  * @deprecated This hook is deprecated as it depends on browser-specific APIs (DOM events, document).
@@ -27,5 +29,5 @@ type OneOrMore<T> = T | T[];
27
29
  * }
28
30
  */
29
31
  declare function useOutsideClickEffect(container: OneOrMore<HTMLElement | null>, callback: () => void): void;
30
-
31
- export { useOutsideClickEffect };
32
+ //#endregion
33
+ export { useOutsideClickEffect };