@basic-ui/core 0.0.40 → 0.0.43

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 (348) hide show
  1. package/build/cjs/index.js +1312 -464
  2. package/build/cjs/index.js.map +1 -1
  3. package/build/esm/Accordion/Accordion.d.ts +7 -7
  4. package/build/esm/Accordion/Accordion.js +4 -4
  5. package/build/esm/Accordion/Accordion.js.map +1 -1
  6. package/build/esm/Accordion/AccordionBody.d.ts +5 -5
  7. package/build/esm/Accordion/AccordionBody.js +4 -4
  8. package/build/esm/Accordion/AccordionBody.js.map +1 -1
  9. package/build/esm/Accordion/AccordionHeader.d.ts +6 -6
  10. package/build/esm/Accordion/AccordionHeader.js +4 -4
  11. package/build/esm/Accordion/AccordionHeader.js.map +1 -1
  12. package/build/esm/Accordion/AccordionItem.d.ts +7 -7
  13. package/build/esm/Accordion/AccordionItem.js +2 -2
  14. package/build/esm/Accordion/AccordionItem.js.map +1 -1
  15. package/build/esm/Accordion/context.d.ts +3 -3
  16. package/build/esm/Accordion/context.js.map +1 -1
  17. package/build/esm/Accordion/index.d.ts +0 -0
  18. package/build/esm/Accordion/index.js.map +1 -1
  19. package/build/esm/Accordion/scopeQuery.d.ts +0 -0
  20. package/build/esm/Accordion/scopeQuery.js.map +1 -1
  21. package/build/esm/CheckBox/CheckBox.d.ts +6 -6
  22. package/build/esm/CheckBox/CheckBox.js +2 -2
  23. package/build/esm/CheckBox/CheckBox.js.map +1 -1
  24. package/build/esm/CheckBox/index.d.ts +0 -0
  25. package/build/esm/CheckBox/index.js.map +1 -1
  26. package/build/esm/ComboBox/Combobox.d.ts +10 -10
  27. package/build/esm/ComboBox/Combobox.js +3 -3
  28. package/build/esm/ComboBox/Combobox.js.map +1 -1
  29. package/build/esm/ComboBox/ComboboxButton.d.ts +8 -8
  30. package/build/esm/ComboBox/ComboboxButton.js +4 -4
  31. package/build/esm/ComboBox/ComboboxButton.js.map +1 -1
  32. package/build/esm/ComboBox/ComboboxInput.d.ts +10 -10
  33. package/build/esm/ComboBox/ComboboxInput.js +3 -3
  34. package/build/esm/ComboBox/ComboboxInput.js.map +1 -1
  35. package/build/esm/ComboBox/ComboboxLabel.d.ts +5 -5
  36. package/build/esm/ComboBox/ComboboxLabel.js +2 -2
  37. package/build/esm/ComboBox/ComboboxLabel.js.map +1 -1
  38. package/build/esm/ComboBox/ComboboxList.d.ts +6 -6
  39. package/build/esm/ComboBox/ComboboxList.js +3 -3
  40. package/build/esm/ComboBox/ComboboxList.js.map +1 -1
  41. package/build/esm/ComboBox/ComboboxOption.d.ts +7 -7
  42. package/build/esm/ComboBox/ComboboxOption.js +4 -4
  43. package/build/esm/ComboBox/ComboboxOption.js.map +1 -1
  44. package/build/esm/ComboBox/ComboboxPopover.d.ts +8 -8
  45. package/build/esm/ComboBox/ComboboxPopover.js +5 -5
  46. package/build/esm/ComboBox/ComboboxPopover.js.map +1 -1
  47. package/build/esm/ComboBox/cities.d.ts +0 -0
  48. package/build/esm/ComboBox/cities.js.map +1 -1
  49. package/build/esm/ComboBox/context.d.ts +10 -10
  50. package/build/esm/ComboBox/context.js.map +1 -1
  51. package/build/esm/ComboBox/hooks.d.ts +3 -3
  52. package/build/esm/ComboBox/hooks.js +11 -11
  53. package/build/esm/ComboBox/hooks.js.map +1 -1
  54. package/build/esm/ComboBox/index.d.ts +0 -0
  55. package/build/esm/ComboBox/index.js.map +1 -1
  56. package/build/esm/ComboBox/makeHash.d.ts +0 -0
  57. package/build/esm/ComboBox/makeHash.js.map +1 -1
  58. package/build/esm/ComboBox/scopeQuery.d.ts +0 -0
  59. package/build/esm/ComboBox/scopeQuery.js.map +1 -1
  60. package/build/esm/FocusLock/FocusLock.d.ts +7 -7
  61. package/build/esm/FocusLock/FocusLock.js +2 -2
  62. package/build/esm/FocusLock/FocusLock.js.map +1 -1
  63. package/build/esm/FocusLock/index.d.ts +0 -0
  64. package/build/esm/FocusLock/index.js.map +1 -1
  65. package/build/esm/FocusLock/tabUtils.d.ts +0 -0
  66. package/build/esm/FocusLock/tabUtils.js.map +1 -1
  67. package/build/esm/FocusLock/useFocusLock.d.ts +4 -4
  68. package/build/esm/FocusLock/useFocusLock.js.map +1 -1
  69. package/build/esm/List/List.d.ts +6 -6
  70. package/build/esm/List/List.js +2 -2
  71. package/build/esm/List/List.js.map +1 -1
  72. package/build/esm/List/ListItem.d.ts +6 -6
  73. package/build/esm/List/ListItem.js +2 -2
  74. package/build/esm/List/ListItem.js.map +1 -1
  75. package/build/esm/List/context.d.ts +0 -0
  76. package/build/esm/List/context.js.map +1 -1
  77. package/build/esm/List/index.d.ts +0 -0
  78. package/build/esm/List/index.js.map +1 -1
  79. package/build/esm/Menu/Menu.d.ts +6 -6
  80. package/build/esm/Menu/Menu.js +2 -2
  81. package/build/esm/Menu/Menu.js.map +1 -1
  82. package/build/esm/Menu/MenuButton.d.ts +10 -10
  83. package/build/esm/Menu/MenuButton.js +3 -3
  84. package/build/esm/Menu/MenuButton.js.map +1 -1
  85. package/build/esm/Menu/MenuItem.d.ts +6 -6
  86. package/build/esm/Menu/MenuItem.js +4 -4
  87. package/build/esm/Menu/MenuItem.js.map +1 -1
  88. package/build/esm/Menu/MenuList.d.ts +5 -5
  89. package/build/esm/Menu/MenuList.js +6 -6
  90. package/build/esm/Menu/MenuList.js.map +1 -1
  91. package/build/esm/Menu/MenuPopover.d.ts +5 -5
  92. package/build/esm/Menu/MenuPopover.js +2 -2
  93. package/build/esm/Menu/MenuPopover.js.map +1 -1
  94. package/build/esm/Menu/context.d.ts +2 -2
  95. package/build/esm/Menu/context.js.map +1 -1
  96. package/build/esm/Menu/index.d.ts +0 -0
  97. package/build/esm/Menu/index.js.map +1 -1
  98. package/build/esm/Menu/scope.d.ts +0 -0
  99. package/build/esm/Menu/scope.js.map +1 -1
  100. package/build/esm/Modal/Modal.d.ts +6 -7
  101. package/build/esm/Modal/Modal.js +5 -5
  102. package/build/esm/Modal/Modal.js.map +1 -1
  103. package/build/esm/Modal/ModalBackdrop.d.ts +6 -6
  104. package/build/esm/Modal/ModalBackdrop.js +6 -6
  105. package/build/esm/Modal/ModalBackdrop.js.map +1 -1
  106. package/build/esm/Modal/index.d.ts +0 -0
  107. package/build/esm/Modal/index.js.map +1 -1
  108. package/build/esm/Popper/Popper.d.ts +7 -7
  109. package/build/esm/Popper/Popper.js +6 -6
  110. package/build/esm/Popper/Popper.js.map +1 -1
  111. package/build/esm/Popper/PopperArrow.d.ts +5 -5
  112. package/build/esm/Popper/PopperArrow.js +5 -6
  113. package/build/esm/Popper/PopperArrow.js.map +1 -1
  114. package/build/esm/Popper/context.d.ts +0 -0
  115. package/build/esm/Popper/context.js.map +1 -1
  116. package/build/esm/Popper/index.d.ts +0 -0
  117. package/build/esm/Popper/index.js.map +1 -1
  118. package/build/esm/Portal/Portal.d.ts +0 -0
  119. package/build/esm/Portal/Portal.js.map +1 -1
  120. package/build/esm/Portal/index.d.ts +0 -0
  121. package/build/esm/Portal/index.js.map +1 -1
  122. package/build/esm/RadioButton/RadioButton.d.ts +6 -6
  123. package/build/esm/RadioButton/RadioButton.js +5 -3
  124. package/build/esm/RadioButton/RadioButton.js.map +1 -1
  125. package/build/esm/RadioButton/RadioGroup.d.ts +7 -7
  126. package/build/esm/RadioButton/RadioGroup.js +2 -2
  127. package/build/esm/RadioButton/RadioGroup.js.map +1 -1
  128. package/build/esm/RadioButton/context.d.ts +2 -2
  129. package/build/esm/RadioButton/context.js.map +1 -1
  130. package/build/esm/RadioButton/index.d.ts +0 -0
  131. package/build/esm/RadioButton/index.js.map +1 -1
  132. package/build/esm/SkipNav/SkipNav.d.ts +6 -6
  133. package/build/esm/SkipNav/SkipNav.js +2 -2
  134. package/build/esm/SkipNav/SkipNav.js.map +1 -1
  135. package/build/esm/SkipNav/index.d.ts +0 -0
  136. package/build/esm/SkipNav/index.js.map +1 -1
  137. package/build/esm/Slider/Slider.d.ts +218 -0
  138. package/build/esm/Slider/Slider.js +842 -0
  139. package/build/esm/Slider/Slider.js.map +1 -0
  140. package/build/esm/Slider/index.d.ts +1 -0
  141. package/build/esm/Slider/index.js +2 -0
  142. package/build/esm/Slider/index.js.map +1 -0
  143. package/build/esm/Spinner/Spinner.d.ts +7 -7
  144. package/build/esm/Spinner/Spinner.js +2 -2
  145. package/build/esm/Spinner/Spinner.js.map +1 -1
  146. package/build/esm/Spinner/SpinnerButton.d.ts +6 -6
  147. package/build/esm/Spinner/SpinnerButton.js +3 -3
  148. package/build/esm/Spinner/SpinnerButton.js.map +1 -1
  149. package/build/esm/Spinner/context.d.ts +2 -2
  150. package/build/esm/Spinner/context.js.map +1 -1
  151. package/build/esm/Spinner/index.d.ts +0 -0
  152. package/build/esm/Spinner/index.js.map +1 -1
  153. package/build/esm/Tabs/Tab.d.ts +6 -6
  154. package/build/esm/Tabs/Tab.js +3 -3
  155. package/build/esm/Tabs/Tab.js.map +1 -1
  156. package/build/esm/Tabs/TabList.d.ts +6 -6
  157. package/build/esm/Tabs/TabList.js +4 -4
  158. package/build/esm/Tabs/TabList.js.map +1 -1
  159. package/build/esm/Tabs/TabPanel.d.ts +6 -6
  160. package/build/esm/Tabs/TabPanel.js +4 -4
  161. package/build/esm/Tabs/TabPanel.js.map +1 -1
  162. package/build/esm/Tabs/TabPanels.d.ts +5 -5
  163. package/build/esm/Tabs/TabPanels.js +4 -4
  164. package/build/esm/Tabs/TabPanels.js.map +1 -1
  165. package/build/esm/Tabs/Tabs.d.ts +6 -6
  166. package/build/esm/Tabs/Tabs.js +2 -2
  167. package/build/esm/Tabs/Tabs.js.map +1 -1
  168. package/build/esm/Tabs/context.d.ts +2 -2
  169. package/build/esm/Tabs/context.js.map +1 -1
  170. package/build/esm/Tabs/index.d.ts +0 -0
  171. package/build/esm/Tabs/index.js.map +1 -1
  172. package/build/esm/Tabs/scopeQuery.d.ts +0 -0
  173. package/build/esm/Tabs/scopeQuery.js.map +1 -1
  174. package/build/esm/Tooltip/Tooltip.d.ts +7 -8
  175. package/build/esm/Tooltip/Tooltip.js +5 -3
  176. package/build/esm/Tooltip/Tooltip.js.map +1 -1
  177. package/build/esm/Tooltip/index.d.ts +0 -0
  178. package/build/esm/Tooltip/index.js.map +1 -1
  179. package/build/esm/Tooltip/stateMachine.d.ts +0 -0
  180. package/build/esm/Tooltip/stateMachine.js +9 -9
  181. package/build/esm/Tooltip/stateMachine.js.map +1 -1
  182. package/build/esm/Tooltip/useTooltip.d.ts +7 -7
  183. package/build/esm/Tooltip/useTooltip.js +6 -5
  184. package/build/esm/Tooltip/useTooltip.js.map +1 -1
  185. package/build/esm/hooks/index.d.ts +0 -0
  186. package/build/esm/hooks/index.js.map +1 -1
  187. package/build/esm/hooks/useAutoFocus.d.ts +2 -2
  188. package/build/esm/hooks/useAutoFocus.js.map +1 -1
  189. package/build/esm/hooks/useChildrenCounter.d.ts +0 -0
  190. package/build/esm/hooks/useChildrenCounter.js.map +1 -1
  191. package/build/esm/hooks/useControlledState.d.ts +2 -6
  192. package/build/esm/hooks/useControlledState.js +8 -7
  193. package/build/esm/hooks/useControlledState.js.map +1 -1
  194. package/build/esm/hooks/useFocusReturn.d.ts +0 -0
  195. package/build/esm/hooks/useFocusReturn.js +2 -2
  196. package/build/esm/hooks/useFocusReturn.js.map +1 -1
  197. package/build/esm/hooks/useFocusState.d.ts +5 -5
  198. package/build/esm/hooks/useFocusState.js +1 -1
  199. package/build/esm/hooks/useFocusState.js.map +1 -1
  200. package/build/esm/hooks/useGestureHandlers.d.ts +5 -5
  201. package/build/esm/hooks/useGestureHandlers.js +23 -15
  202. package/build/esm/hooks/useGestureHandlers.js.map +1 -1
  203. package/build/esm/hooks/useMeasure.d.ts +2 -2
  204. package/build/esm/hooks/useMeasure.js +0 -1
  205. package/build/esm/hooks/useMeasure.js.map +1 -1
  206. package/build/esm/hooks/useOnClickOutside.d.ts +2 -2
  207. package/build/esm/hooks/useOnClickOutside.js.map +1 -1
  208. package/build/esm/hooks/useOnKeyDown.d.ts +1 -1
  209. package/build/esm/hooks/useOnKeyDown.js +5 -5
  210. package/build/esm/hooks/useOnKeyDown.js.map +1 -1
  211. package/build/esm/hooks/useReducerMachine.d.ts +0 -0
  212. package/build/esm/hooks/useReducerMachine.js +2 -1
  213. package/build/esm/hooks/useReducerMachine.js.map +1 -1
  214. package/build/esm/hooks/useRemoveBodyScroll.d.ts +2 -1
  215. package/build/esm/hooks/useRemoveBodyScroll.js +12 -8
  216. package/build/esm/hooks/useRemoveBodyScroll.js.map +1 -1
  217. package/build/esm/hooks/useScope.d.ts +0 -0
  218. package/build/esm/hooks/useScope.js.map +1 -1
  219. package/build/esm/hooks/useThrottle.d.ts +0 -0
  220. package/build/esm/hooks/useThrottle.js.map +1 -1
  221. package/build/esm/index.d.ts +1 -0
  222. package/build/esm/index.js +1 -0
  223. package/build/esm/index.js.map +1 -1
  224. package/build/esm/utils/assign-ref.d.ts +3 -0
  225. package/build/esm/utils/{assignRef.js → assign-ref.js} +1 -1
  226. package/build/esm/utils/assign-ref.js.map +1 -0
  227. package/build/esm/utils/can-use-dom.d.ts +1 -0
  228. package/build/esm/utils/can-use-dom.js +4 -0
  229. package/build/esm/utils/can-use-dom.js.map +1 -0
  230. package/build/esm/utils/clamp.d.ts +0 -0
  231. package/build/esm/utils/clamp.js.map +1 -1
  232. package/build/esm/utils/context.d.ts +7 -0
  233. package/build/esm/utils/context.js +41 -0
  234. package/build/esm/utils/context.js.map +1 -0
  235. package/build/esm/utils/{createSubscription.d.ts → create-subscription.d.ts} +0 -0
  236. package/build/esm/utils/{createSubscription.js → create-subscription.js} +1 -1
  237. package/build/esm/utils/create-subscription.js.map +1 -0
  238. package/build/esm/utils/{getCircularIndex.d.ts → get-circular-index.d.ts} +0 -0
  239. package/build/esm/utils/{getCircularIndex.js → get-circular-index.js} +1 -1
  240. package/build/esm/utils/get-circular-index.js.map +1 -0
  241. package/build/esm/utils/index.d.ts +10 -4
  242. package/build/esm/utils/index.js +10 -4
  243. package/build/esm/utils/index.js.map +1 -1
  244. package/build/esm/utils/is-right-click.d.ts +6 -0
  245. package/build/esm/utils/is-right-click.js +9 -0
  246. package/build/esm/utils/is-right-click.js.map +1 -0
  247. package/build/esm/utils/owner-document.d.ts +7 -0
  248. package/build/esm/utils/owner-document.js +12 -0
  249. package/build/esm/utils/owner-document.js.map +1 -0
  250. package/build/esm/utils/polymorphic.d.ts +32 -0
  251. package/build/esm/utils/polymorphic.js +2 -0
  252. package/build/esm/utils/polymorphic.js.map +1 -0
  253. package/build/esm/utils/{rubberBandClamp.d.ts → rubber-band-clamp.d.ts} +0 -0
  254. package/build/esm/utils/{rubberBandClamp.js → rubber-band-clamp.js} +1 -1
  255. package/build/esm/utils/rubber-band-clamp.js.map +1 -0
  256. package/build/esm/utils/use-stable-callback.d.ts +16 -0
  257. package/build/esm/utils/use-stable-callback.js +43 -0
  258. package/build/esm/utils/use-stable-callback.js.map +1 -0
  259. package/build/esm/utils/wrap-event.d.ts +3 -0
  260. package/build/esm/utils/{wrapEvent.js → wrap-event.js} +1 -1
  261. package/build/esm/utils/wrap-event.js.map +1 -0
  262. package/build/tsconfig-build.tsbuildinfo +1 -0
  263. package/package.json +5 -6
  264. package/src/Accordion/Accordion.tsx +12 -6
  265. package/src/Accordion/AccordionBody.tsx +4 -5
  266. package/src/Accordion/AccordionHeader.tsx +30 -27
  267. package/src/Accordion/AccordionItem.tsx +12 -6
  268. package/src/Accordion/context.ts +3 -2
  269. package/src/CheckBox/CheckBox.tsx +5 -6
  270. package/src/ComboBox/ComboBox.story.tsx +3 -3
  271. package/src/ComboBox/Combobox.tsx +5 -8
  272. package/src/ComboBox/ComboboxButton.tsx +15 -9
  273. package/src/ComboBox/ComboboxInput.tsx +18 -10
  274. package/src/ComboBox/ComboboxLabel.tsx +4 -4
  275. package/src/ComboBox/ComboboxList.tsx +5 -6
  276. package/src/ComboBox/ComboboxOption.tsx +12 -8
  277. package/src/ComboBox/ComboboxPopover.tsx +15 -10
  278. package/src/ComboBox/context.ts +10 -9
  279. package/src/ComboBox/hooks.tsx +4 -3
  280. package/src/FocusLock/FocusLock.tsx +13 -7
  281. package/src/FocusLock/useFocusLock.ts +4 -3
  282. package/src/List/List.tsx +5 -5
  283. package/src/List/ListItem.tsx +5 -5
  284. package/src/Menu/Menu.story.tsx +2 -2
  285. package/src/Menu/Menu.tsx +13 -7
  286. package/src/Menu/MenuButton.tsx +13 -10
  287. package/src/Menu/MenuItem.tsx +15 -11
  288. package/src/Menu/MenuList.tsx +6 -6
  289. package/src/Menu/MenuPopover.tsx +4 -4
  290. package/src/Menu/context.ts +9 -4
  291. package/src/Modal/Modal.tsx +11 -7
  292. package/src/Modal/ModalBackdrop.tsx +16 -11
  293. package/src/Popper/Popper.tsx +7 -7
  294. package/src/Popper/PopperArrow.tsx +6 -8
  295. package/src/RadioButton/RadioButton.tsx +11 -6
  296. package/src/RadioButton/RadioGroup.tsx +11 -9
  297. package/src/RadioButton/context.ts +2 -4
  298. package/src/SkipNav/SkipNav.tsx +5 -5
  299. package/src/Slider/Slider.story.tsx +45 -0
  300. package/src/Slider/Slider.tsx +1106 -0
  301. package/src/Slider/index.ts +1 -0
  302. package/src/Slider/styles.css +131 -0
  303. package/src/Spinner/Spinner.tsx +13 -9
  304. package/src/Spinner/SpinnerButton.tsx +11 -6
  305. package/src/Spinner/context.ts +2 -3
  306. package/src/Tabs/Tab.tsx +13 -8
  307. package/src/Tabs/TabList.tsx +5 -5
  308. package/src/Tabs/TabPanel.tsx +5 -5
  309. package/src/Tabs/TabPanels.tsx +4 -4
  310. package/src/Tabs/Tabs.tsx +5 -7
  311. package/src/Tabs/context.ts +2 -3
  312. package/src/Tooltip/Tooltip.story.tsx +3 -3
  313. package/src/Tooltip/Tooltip.tsx +13 -7
  314. package/src/Tooltip/stateMachine.ts +9 -13
  315. package/src/Tooltip/useTooltip.ts +17 -11
  316. package/src/hooks/useAutoFocus.ts +2 -1
  317. package/src/hooks/useControlledState.ts +14 -14
  318. package/src/hooks/useFocusState.ts +4 -3
  319. package/src/hooks/useGestureHandlers.ts +33 -19
  320. package/src/hooks/useMeasure.ts +2 -2
  321. package/src/hooks/useOnClickOutside.ts +2 -2
  322. package/src/hooks/useOnKeyDown.ts +4 -3
  323. package/src/hooks/useRemoveBodyScroll.ts +18 -8
  324. package/src/index.ts +1 -0
  325. package/src/utils/{assignRef.ts → assign-ref.ts} +4 -4
  326. package/src/utils/can-use-dom.ts +7 -0
  327. package/src/utils/context.tsx +48 -0
  328. package/src/utils/{createSubscription.ts → create-subscription.ts} +0 -0
  329. package/src/utils/{getCircularIndex.ts → get-circular-index.ts} +0 -0
  330. package/src/utils/index.ts +10 -4
  331. package/src/utils/is-right-click.ts +14 -0
  332. package/src/utils/owner-document.ts +13 -0
  333. package/src/utils/polymorphic.ts +72 -0
  334. package/src/utils/{rubberBandClamp.ts → rubber-band-clamp.ts} +0 -0
  335. package/src/utils/use-stable-callback.ts +58 -0
  336. package/src/utils/wrap-event.ts +22 -0
  337. package/build/esm/hooks/useId.d.ts +0 -3
  338. package/build/esm/hooks/useId.js +0 -16
  339. package/build/esm/hooks/useId.js.map +0 -1
  340. package/build/esm/utils/assignRef.d.ts +0 -3
  341. package/build/esm/utils/assignRef.js.map +0 -1
  342. package/build/esm/utils/createSubscription.js.map +0 -1
  343. package/build/esm/utils/getCircularIndex.js.map +0 -1
  344. package/build/esm/utils/rubberBandClamp.js.map +0 -1
  345. package/build/esm/utils/wrapEvent.d.ts +0 -3
  346. package/build/esm/utils/wrapEvent.js.map +0 -1
  347. package/build/tsconfig.tsbuildinfo +0 -1
  348. package/src/utils/wrapEvent.ts +0 -20
@@ -1,5 +1,11 @@
1
+ import type {
2
+ MutableRefObject,
3
+ MouseEvent as ReactMouseEvent,
4
+ TouchEvent as ReactTouchEvent,
5
+ } from 'react';
1
6
  import { useRef } from 'react';
2
- import type * as React from 'react';
7
+
8
+ import { getOwnerDocument } from '../utils';
3
9
 
4
10
  export interface GestureHandlersState {
5
11
  target: null | EventTarget;
@@ -26,8 +32,8 @@ type SetStateFunc<S> = (
26
32
  ) => void;
27
33
 
28
34
  export interface GestureHandlersReturn {
29
- onMouseDown: (e: React.MouseEvent<HTMLElement>) => void;
30
- onTouchStart: (e: React.TouchEvent<HTMLElement>) => void;
35
+ onMouseDown: (e: ReactMouseEvent<HTMLElement>) => void;
36
+ onTouchStart: (e: ReactTouchEvent<HTMLElement>) => void;
31
37
  }
32
38
 
33
39
  export interface GestureHandlerOptions {
@@ -59,7 +65,7 @@ const VELOCITY_DEPR_FACTOR = FRAMERATE_CONST * 2;
59
65
 
60
66
  export function gestureHandlers(
61
67
  set: SetStateFunc<GestureHandlersState>,
62
- containerRef?: React.MutableRefObject<HTMLElement | null>,
68
+ containerRef?: MutableRefObject<HTMLElement | null>,
63
69
  options: GestureHandlerOptions = {}
64
70
  ): GestureHandlersReturn {
65
71
  const { ensureTargetIsContainer = false, minTouchDelta = 0 } = options;
@@ -192,7 +198,7 @@ export function gestureHandlers(
192
198
  handleMove(e.touches.item(0) as any);
193
199
  }
194
200
 
195
- function handleTouchStart(e: React.TouchEvent<HTMLElement>) {
201
+ function handleTouchStart(e: ReactTouchEvent<HTMLElement>) {
196
202
  // making sure we're not dragging the element when more than one finger press the screen
197
203
  const { touches } = e;
198
204
  if (touches.length > 1) {
@@ -207,21 +213,26 @@ export function gestureHandlers(
207
213
  return;
208
214
  }
209
215
 
210
- window.addEventListener('touchmove', handleTouchMove, { passive: false });
211
- window.addEventListener('touchend', handleTouchEnd);
212
- window.addEventListener('touchcancel', handleTouchEnd);
216
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
217
+ const ownerDocument = getOwnerDocument(e.currentTarget)!;
218
+ const ownerWindow = ownerDocument.defaultView || window;
219
+ ownerWindow.addEventListener('touchmove', handleTouchMove, {
220
+ passive: false,
221
+ });
222
+ ownerWindow.addEventListener('touchend', handleTouchEnd);
223
+ ownerWindow.addEventListener('touchcancel', handleTouchEnd);
213
224
  handleDown(e.touches.item(0) as any);
214
225
  }
215
226
 
216
- function handleTouchEnd() {
217
- window.removeEventListener('touchmove', handleTouchMove);
218
- window.removeEventListener('touchend', handleTouchEnd);
219
- window.removeEventListener('touchcancel', handleTouchEnd);
227
+ function handleTouchEnd(this: Window) {
228
+ this.removeEventListener('touchmove', handleTouchMove);
229
+ this.removeEventListener('touchend', handleTouchEnd);
230
+ this.removeEventListener('touchcancel', handleTouchEnd);
220
231
  handleUp();
221
232
  }
222
233
 
223
234
  // Mouse handlers
224
- function handleMouseDown(e: React.MouseEvent<HTMLElement>) {
235
+ function handleMouseDown(e: ReactMouseEvent<HTMLElement>) {
225
236
  if (
226
237
  ensureTargetIsContainer &&
227
238
  containerRef &&
@@ -230,16 +241,19 @@ export function gestureHandlers(
230
241
  return;
231
242
  }
232
243
 
244
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
245
+ const ownerDocument = getOwnerDocument(e.currentTarget)!;
246
+ const ownerWindow = ownerDocument.defaultView || window;
233
247
  if (e.button === 0) {
234
- window.addEventListener('mousemove', handleMove);
235
- window.addEventListener('mouseup', handleMouseUp);
248
+ ownerWindow.addEventListener('mousemove', handleMove);
249
+ ownerWindow.addEventListener('mouseup', handleMouseUp);
236
250
  handleDown(e as any);
237
251
  }
238
252
  }
239
253
 
240
- function handleMouseUp() {
241
- window.removeEventListener('mousemove', handleMove);
242
- window.removeEventListener('mouseup', handleMouseUp);
254
+ function handleMouseUp(this: Window) {
255
+ this.removeEventListener('mousemove', handleMove);
256
+ this.removeEventListener('mouseup', handleMouseUp);
243
257
  handleUp();
244
258
  }
245
259
  /* eslint-enable @typescript-eslint/no-use-before-define */
@@ -251,7 +265,7 @@ export function gestureHandlers(
251
265
  }
252
266
 
253
267
  export const useGestureHandlers = (
254
- containerRef: React.MutableRefObject<HTMLElement | null> | undefined,
268
+ containerRef: MutableRefObject<HTMLElement | null> | undefined,
255
269
  onGesture: (e: GestureHandlersState) => void,
256
270
  options: GestureHandlerOptions = {}
257
271
  ) => {
@@ -1,7 +1,7 @@
1
+ import type { MutableRefObject } from 'react';
1
2
  import { useRef, useState, useEffect } from 'react';
2
- import ResizeObserver from 'resize-observer-polyfill';
3
3
 
4
- export function useMeasure(ref: React.MutableRefObject<HTMLElement | null>) {
4
+ export function useMeasure(ref: MutableRefObject<HTMLElement | null>) {
5
5
  const ro = useRef<ResizeObserver | null>(null);
6
6
  const [bounds, setBounds] = useState({
7
7
  left: 0,
@@ -1,8 +1,8 @@
1
+ import type { RefObject } from 'react';
1
2
  import { useEffect, useCallback } from 'react';
2
- import type * as React from 'react';
3
3
 
4
4
  export function useOnClickOutside(
5
- ref: React.RefObject<any>,
5
+ ref: RefObject<any>,
6
6
  handler: (e: PointerEvent) => void,
7
7
  active = true
8
8
  ) {
@@ -1,18 +1,19 @@
1
1
  import { useEffect } from 'react';
2
2
 
3
3
  export function useOnKeyDown(
4
+ ownerWindow: Window,
4
5
  handler: (e: KeyboardEvent) => void,
5
6
  active = true
6
7
  ) {
7
8
  useEffect(() => {
8
9
  if (active) {
9
- window.addEventListener('keydown', handler);
10
+ ownerWindow.addEventListener('keydown', handler);
10
11
 
11
12
  return () => {
12
- window.removeEventListener('keydown', handler);
13
+ ownerWindow.removeEventListener('keydown', handler);
13
14
  };
14
15
  }
15
16
 
16
17
  return;
17
- }, [active, handler]);
18
+ }, [ownerWindow, active, handler]);
18
19
  }
@@ -1,29 +1,39 @@
1
+ import type { RefObject } from 'react';
1
2
  import { useEffect } from 'react';
2
3
 
4
+ import { getOwnerDocument } from '../utils';
5
+
3
6
  let scrollBodyCount = 0;
4
- export function useRemoveBodyScroll(open: boolean) {
7
+ export function useRemoveBodyScroll(
8
+ open: boolean,
9
+ elementRef: RefObject<HTMLElement | null>
10
+ ) {
5
11
  useEffect(() => {
6
- if (open) {
12
+ if (open && elementRef.current) {
13
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
14
+ const ownerDocument = getOwnerDocument(elementRef.current)!;
15
+ const ownerWindow = ownerDocument.defaultView || window;
7
16
  scrollBodyCount += 1;
8
17
 
9
18
  // calculate scrollbar width if mounting the first scroll lock
10
19
  let scrollBarWidth = 0;
11
20
  if (scrollBodyCount === 1) {
12
- scrollBarWidth = window.innerWidth - document.body.clientWidth;
21
+ scrollBarWidth =
22
+ ownerWindow.innerWidth - ownerDocument.body.clientWidth;
13
23
  }
14
24
 
15
- document.body.style.overflow = 'hidden';
25
+ ownerDocument.body.style.overflow = 'hidden';
16
26
  if (scrollBarWidth > 0) {
17
- document.body.style.marginRight = `${scrollBarWidth}px`;
27
+ ownerDocument.body.style.marginRight = `${scrollBarWidth}px`;
18
28
  }
19
29
 
20
30
  return () => {
21
31
  scrollBodyCount -= 1;
22
32
  if (scrollBodyCount === 0) {
23
- document.body.style.overflow = '';
24
- document.body.style.marginRight = '';
33
+ ownerDocument.body.style.overflow = '';
34
+ ownerDocument.body.style.marginRight = '';
25
35
  }
26
36
  };
27
37
  }
28
- }, [open]);
38
+ }, [elementRef, open]);
29
39
  }
package/src/index.ts CHANGED
@@ -8,6 +8,7 @@ export * from './Modal';
8
8
  export * from './Popper';
9
9
  export * from './Portal';
10
10
  export * from './RadioButton';
11
+ export * from './Slider';
11
12
  export * from './Spinner';
12
13
  export * from './Tabs';
13
14
  export * from './Tooltip';
@@ -1,7 +1,7 @@
1
- import type { LegacyRef, MutableRefObject, Ref, RefCallback } from 'react';
1
+ import type { MutableRefObject, RefCallback } from 'react';
2
2
 
3
3
  export function assignRef<T>(
4
- ref: LegacyRef<T> | MutableRefObject<T> | Ref<T> | null | undefined,
4
+ ref: MutableRefObject<T> | RefCallback<T> | null | undefined,
5
5
  value: T
6
6
  ) {
7
7
  if (ref == null) return;
@@ -9,7 +9,7 @@ export function assignRef<T>(
9
9
  ref(value);
10
10
  } else {
11
11
  try {
12
- (ref as MutableRefObject<T>).current = value;
12
+ ref.current = value;
13
13
  } catch (error) {
14
14
  throw new Error(`Cannot assign value "${value}" to ref "${ref}"`);
15
15
  }
@@ -17,7 +17,7 @@ export function assignRef<T>(
17
17
  }
18
18
 
19
19
  export function assignMultipleRefs<T>(
20
- ...refs: (LegacyRef<T> | MutableRefObject<T> | Ref<T> | null | undefined)[]
20
+ ...refs: (MutableRefObject<T> | RefCallback<T> | null | undefined)[]
21
21
  ): RefCallback<T> {
22
22
  return (node: T | null) => {
23
23
  refs.forEach((ref) => {
@@ -0,0 +1,7 @@
1
+ export function canUseDOM() {
2
+ return !!(
3
+ typeof window !== 'undefined' &&
4
+ window.document &&
5
+ window.document.createElement
6
+ );
7
+ }
@@ -0,0 +1,48 @@
1
+ import type { FC, PropsWithChildren } from 'react';
2
+ import {
3
+ useMemo,
4
+ createContext as ReactCreateContext,
5
+ useContext as useReactContext,
6
+ } from 'react';
7
+
8
+ ////////////////////////////////////////////////////////////////////////////////
9
+
10
+ type ContextProvider<T> = FC<PropsWithChildren<T>>;
11
+
12
+ export function createContext<ContextValueType extends object | null>(
13
+ rootName: string,
14
+ defaultContext?: ContextValueType
15
+ ): [
16
+ ContextProvider<ContextValueType>,
17
+ (childName: string) => ContextValueType
18
+ ] {
19
+ const Ctx = ReactCreateContext<ContextValueType | undefined>(defaultContext);
20
+
21
+ function Provider(props: PropsWithChildren<ContextValueType>) {
22
+ const { children, ...context } = props;
23
+ const value = useMemo(
24
+ () => context,
25
+ // eslint-disable-next-line react-hooks/exhaustive-deps
26
+ Object.values(context)
27
+ ) as ContextValueType;
28
+ return <Ctx.Provider value={value}>{children}</Ctx.Provider>;
29
+ }
30
+
31
+ function useContext(childName: string) {
32
+ const context = useReactContext(Ctx);
33
+ if (context) {
34
+ return context;
35
+ }
36
+ if (defaultContext) {
37
+ return defaultContext;
38
+ }
39
+ throw Error(
40
+ `${childName} must be rendered inside of a ${rootName} component.`
41
+ );
42
+ }
43
+
44
+ Ctx.displayName = `${rootName}Context`;
45
+ Provider.displayName = `${rootName}Provider`;
46
+
47
+ return [Provider, useContext];
48
+ }
@@ -1,4 +1,10 @@
1
- export * from './assignRef';
2
- export * from './wrapEvent';
3
- export * from './getCircularIndex';
4
- export * from './rubberBandClamp';
1
+ export * from './assign-ref';
2
+ export * from './can-use-dom';
3
+ export * from './context';
4
+ export * from './get-circular-index';
5
+ export * from './is-right-click';
6
+ export * from './owner-document';
7
+ export * from './polymorphic';
8
+ export * from './rubber-band-clamp';
9
+ export * from './use-stable-callback';
10
+ export * from './wrap-event';
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Detects right clicks
3
+ *
4
+ * @param nativeEvent
5
+ */
6
+ export function isRightClick(
7
+ nativeEvent: MouseEvent | PointerEvent | TouchEvent
8
+ ) {
9
+ return 'which' in nativeEvent
10
+ ? nativeEvent.which === 3
11
+ : 'button' in nativeEvent
12
+ ? (nativeEvent as any).button === 2
13
+ : false;
14
+ }
@@ -0,0 +1,13 @@
1
+ import { canUseDOM } from './can-use-dom';
2
+
3
+ /**
4
+ * Get an element's owner document. Useful when components are used in iframes
5
+ * or other environments like dev tools.
6
+ *
7
+ * @param element
8
+ */
9
+ export function getOwnerDocument<T extends Element>(
10
+ element: T | null | undefined
11
+ ) {
12
+ return canUseDOM() ? (element ? element.ownerDocument : document) : null;
13
+ }
@@ -0,0 +1,72 @@
1
+ /* eslint-disable @typescript-eslint/ban-types */
2
+ // adapted from https://github.com/radix-ui/primitives/blob/2f139a832ba0cdfd445c937ebf63c2e79e0ef7ed/packages/react/polymorphic/src/polymorphic.ts
3
+ // Would have liked to use it directly instead of copying but they are
4
+ // (rightfully) treating it as an internal utility, so copy/paste it is to
5
+ // prevent any needless churn if they make breaking changes. Big thanks to Jenna
6
+ // for the heavy lifting! https://github.com/jjenzz
7
+
8
+ import type * as React from 'react';
9
+
10
+ // eslint-disable-next-line @typescript-eslint/ban-types
11
+ export type Merge<P1 = {}, P2 = {}> = Omit<P1, keyof P2> & P2;
12
+
13
+ /**
14
+ * Infers the OwnProps if E is a ForwardRefExoticComponentWithAs
15
+ */
16
+ export type OwnProps<E> = E extends ForwardRefComponent<any, infer P> ? P : {};
17
+
18
+ /**
19
+ * Infers the JSX.IntrinsicElement if E is a ForwardRefExoticComponentWithAs
20
+ */
21
+ export type IntrinsicElement<E> = E extends ForwardRefComponent<infer I, any>
22
+ ? I
23
+ : never;
24
+
25
+ type ForwardRefExoticComponent<E, OwnProps> = React.ForwardRefExoticComponent<
26
+ Merge<
27
+ E extends React.ElementType ? React.ComponentPropsWithRef<E> : never,
28
+ OwnProps & { as?: E }
29
+ >
30
+ >;
31
+
32
+ export interface ForwardRefComponent<
33
+ IntrinsicElementString,
34
+ OwnProps = {}
35
+ /*
36
+ * Extends original type to ensure built in React types play nice with
37
+ * polymorphic components still e.g. `React.ElementRef` etc.
38
+ */
39
+ > extends ForwardRefExoticComponent<IntrinsicElementString, OwnProps> {
40
+ /*
41
+ * When `as` prop is passed, use this overload. Merges original own props
42
+ * (without DOM props) and the inferred props from `as` element with the own
43
+ * props taking precendence.
44
+ *
45
+ * We explicitly avoid `React.ElementType` and manually narrow the prop types
46
+ * so that events are typed when using JSX.IntrinsicElements.
47
+ */
48
+ <As = IntrinsicElementString>(
49
+ props: As extends ''
50
+ ? { as: keyof JSX.IntrinsicElements }
51
+ : As extends React.ComponentType<infer P>
52
+ ? Merge<P, OwnProps & { as: As }>
53
+ : As extends keyof JSX.IntrinsicElements
54
+ ? Merge<JSX.IntrinsicElements[As], OwnProps & { as: As }>
55
+ : never
56
+ ): React.ReactElement | null;
57
+ }
58
+
59
+ export interface MemoComponent<IntrinsicElementString, OwnProps = {}>
60
+ extends React.MemoExoticComponent<
61
+ ForwardRefComponent<IntrinsicElementString, OwnProps>
62
+ > {
63
+ <As = IntrinsicElementString>(
64
+ props: As extends ''
65
+ ? { as: keyof JSX.IntrinsicElements }
66
+ : As extends React.ComponentType<infer P>
67
+ ? Merge<P, OwnProps & { as: As }>
68
+ : As extends keyof JSX.IntrinsicElements
69
+ ? Merge<JSX.IntrinsicElements[As], OwnProps & { as: As }>
70
+ : never
71
+ ): React.ReactElement | null;
72
+ }
@@ -0,0 +1,58 @@
1
+ /* eslint-disable react-hooks/rules-of-hooks */
2
+ import { useRef, useEffect, useCallback, useLayoutEffect } from 'react';
3
+ import type * as React from 'react';
4
+
5
+ const useEnhancedEffect =
6
+ typeof window !== 'undefined' ? useLayoutEffect : useEffect;
7
+
8
+ /**
9
+ * Converts a callback to a ref to avoid triggering re-renders when passed as a
10
+ * prop and exposed as a stable function to avoid executing effects when
11
+ * passed as a dependency.
12
+ */
13
+ function createStableCallbackHook<T extends (...args: any[]) => any>(
14
+ useEffectHook: (
15
+ effect: React.EffectCallback,
16
+ deps?: React.DependencyList | undefined
17
+ ) => void,
18
+ callback: T | null | undefined
19
+ ): T {
20
+ const callbackRef = useRef(callback);
21
+ useEffectHook(() => {
22
+ callbackRef.current = callback;
23
+ });
24
+
25
+ // eslint-disable-next-line react-hooks/exhaustive-deps
26
+ return useCallback(
27
+ ((...args) => {
28
+ callbackRef.current && callbackRef.current(...args);
29
+ }) as T,
30
+ []
31
+ );
32
+ }
33
+
34
+ /**
35
+ * Converts a callback to a ref to avoid triggering re-renders when passed as a
36
+ * prop and exposed as a stable function to avoid executing effects when passed
37
+ * as a dependency.
38
+ */
39
+ export function useStableCallback<T extends (...args: any[]) => any>(
40
+ callback: T | null | undefined
41
+ ): T {
42
+ return createStableCallbackHook(useEffect, callback);
43
+ }
44
+
45
+ /**
46
+ * Converts a callback to a ref to avoid triggering re-renders when passed as a
47
+ * prop and exposed as a stable function to avoid executing effects when passed
48
+ * as a dependency.
49
+ *
50
+ * Use this over `useStableCallback` when you want the callback to be cached in
51
+ * `useLayoutEffect` instead of `useEffect` to deal with timing issues only when
52
+ * needed.
53
+ */
54
+ export function useStableLayoutCallback<T extends (...args: any[]) => any>(
55
+ callback: T | null | undefined
56
+ ): T {
57
+ return createStableCallbackHook(useEnhancedEffect, callback);
58
+ }
@@ -0,0 +1,22 @@
1
+ import type { SyntheticEvent } from 'react';
2
+
3
+ export type CustomEventHandler<
4
+ E extends SyntheticEvent<any> | Event,
5
+ H extends unknown[]
6
+ > = (e: E, ...args: H) => void;
7
+
8
+ export function wrapEvent<
9
+ EventType extends SyntheticEvent<any> | Event,
10
+ H extends unknown[]
11
+ >(
12
+ theirHandler: CustomEventHandler<EventType, H> | undefined,
13
+ ourHandler: CustomEventHandler<EventType, H>
14
+ ): CustomEventHandler<EventType, H> {
15
+ return (event: EventType, ...otherArgs: H) => {
16
+ const ret = theirHandler && theirHandler(event, ...otherArgs);
17
+ if (!event.defaultPrevented) {
18
+ return ourHandler(event, ...otherArgs);
19
+ }
20
+ return ret;
21
+ };
22
+ }
@@ -1,3 +0,0 @@
1
- export declare function useId(): string | undefined;
2
- export declare function useId(preferredId: string): string;
3
- export declare function useId(preferredId: string | undefined): string | undefined;
@@ -1,16 +0,0 @@
1
- import { useEffect, useState } from 'react'; // Could use UUID but if we hit 9,007,199,254,740,991 unique components over
2
- // the lifetime of the app before it gets reloaded, I mean ... come on.
3
- // I don't even know what xillion that is.
4
- // /me googles
5
- // Oh duh, quadrillion. Nine quadrillion components. I think we're okay.
6
-
7
- let id = 0;
8
-
9
- const genId = () => "".concat(++id);
10
-
11
- export function useId(preferredId) {
12
- const [id, setId] = useState(preferredId);
13
- useEffect(() => setId(genId()), []);
14
- return id;
15
- }
16
- //# sourceMappingURL=useId.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/hooks/useId.ts"],"names":["useEffect","useState","id","genId","useId","preferredId","setId"],"mappings":"AAAA,SAASA,SAAT,EAAoBC,QAApB,QAAoC,OAApC,C,CAEA;AACA;AACA;AACA;AACA;;AACA,IAAIC,EAAE,GAAG,CAAT;;AACA,MAAMC,KAAK,GAAG,gBAAS,EAAED,EAAX,CAAd;;AAKA,OAAO,SAASE,KAAT,CAAeC,WAAf,EAAyD;AAC9D,QAAM,CAACH,EAAD,EAAKI,KAAL,IAAcL,QAAQ,CAAqBI,WAArB,CAA5B;AACAL,EAAAA,SAAS,CAAC,MAAMM,KAAK,CAACH,KAAK,EAAN,CAAZ,EAAuB,EAAvB,CAAT;AACA,SAAOD,EAAP;AACD","sourcesContent":["import { useEffect, useState } from 'react';\n\n// Could use UUID but if we hit 9,007,199,254,740,991 unique components over\n// the lifetime of the app before it gets reloaded, I mean ... come on.\n// I don't even know what xillion that is.\n// /me googles\n// Oh duh, quadrillion. Nine quadrillion components. I think we're okay.\nlet id = 0;\nconst genId = () => `${++id}`;\n\nexport function useId(): string | undefined;\nexport function useId(preferredId: string): string;\nexport function useId(preferredId: string | undefined): string | undefined;\nexport function useId(preferredId?: string): string | undefined {\n const [id, setId] = useState<string | undefined>(preferredId);\n useEffect(() => setId(genId()), []);\n return id;\n}\n"],"file":"useId.js"}
@@ -1,3 +0,0 @@
1
- import type { LegacyRef, MutableRefObject, Ref, RefCallback } from 'react';
2
- export declare function assignRef<T>(ref: LegacyRef<T> | MutableRefObject<T> | Ref<T> | null | undefined, value: T): void;
3
- export declare function assignMultipleRefs<T>(...refs: (LegacyRef<T> | MutableRefObject<T> | Ref<T> | null | undefined)[]): RefCallback<T>;
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/utils/assignRef.ts"],"names":["assignRef","ref","value","current","error","Error","assignMultipleRefs","refs","node","forEach"],"mappings":"AAEA,OAAO,SAASA,SAAT,CACLC,GADK,EAELC,KAFK,EAGL;AACA,MAAID,GAAG,IAAI,IAAX,EAAiB;;AACjB,MAAI,OAAOA,GAAP,KAAe,UAAnB,EAA+B;AAC7BA,IAAAA,GAAG,CAACC,KAAD,CAAH;AACD,GAFD,MAEO;AACL,QAAI;AACDD,MAAAA,GAAD,CAA6BE,OAA7B,GAAuCD,KAAvC;AACD,KAFD,CAEE,OAAOE,KAAP,EAAc;AACd,YAAM,IAAIC,KAAJ,iCAAkCH,KAAlC,yBAAoDD,GAApD,QAAN;AACD;AACF;AACF;AAED,OAAO,SAASK,kBAAT,GAEW;AAAA,oCADbC,IACa;AADbA,IAAAA,IACa;AAAA;;AAChB,SAAO,UAACC,IAAD,EAAoB;AACzBD,IAAAA,IAAI,CAACE,OAAL,CAAa,UAACR,GAAD,EAAS;AACpBD,MAAAA,SAAS,CAACC,GAAD,EAAMO,IAAN,CAAT;AACD,KAFD;AAGD,GAJD;AAKD","sourcesContent":["import type { LegacyRef, MutableRefObject, Ref, RefCallback } from 'react';\n\nexport function assignRef<T>(\n ref: LegacyRef<T> | MutableRefObject<T> | Ref<T> | null | undefined,\n value: T\n) {\n if (ref == null) return;\n if (typeof ref === 'function') {\n ref(value);\n } else {\n try {\n (ref as MutableRefObject<T>).current = value;\n } catch (error) {\n throw new Error(`Cannot assign value \"${value}\" to ref \"${ref}\"`);\n }\n }\n}\n\nexport function assignMultipleRefs<T>(\n ...refs: (LegacyRef<T> | MutableRefObject<T> | Ref<T> | null | undefined)[]\n): RefCallback<T> {\n return (node: T | null) => {\n refs.forEach((ref) => {\n assignRef(ref, node);\n });\n };\n}\n"],"file":"assignRef.js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/utils/createSubscription.ts"],"names":["createSubscription","subscriptions","subscribe","fn","push","splice","indexOf","notify","forEach"],"mappings":"AAAA,OAAO,SAASA,kBAAT,GAA8B;AACnC,MAAMC,aAA6B,GAAG,EAAtC;;AAEA,WAASC,SAAT,CAAmBC,EAAnB,EAAmC;AACjCF,IAAAA,aAAa,CAACG,IAAd,CAAmBD,EAAnB;AACA,WAAO,YAAM;AACXF,MAAAA,aAAa,CAACI,MAAd,CAAqBJ,aAAa,CAACK,OAAd,CAAsBH,EAAtB,CAArB,EAAgD,CAAhD;AACD,KAFD;AAGD;;AAED,WAASI,MAAT,GAAkB;AAChBN,IAAAA,aAAa,CAACO,OAAd,CAAsB,UAACL,EAAD;AAAA,aAAQA,EAAE,EAAV;AAAA,KAAtB;AACD;;AAED,SAAO;AAAED,IAAAA,SAAS,EAATA,SAAF;AAAaK,IAAAA,MAAM,EAANA;AAAb,GAAP;AACD","sourcesContent":["export function createSubscription() {\n const subscriptions: (() => void)[] = [];\n\n function subscribe(fn: () => void) {\n subscriptions.push(fn);\n return () => {\n subscriptions.splice(subscriptions.indexOf(fn), 1);\n };\n }\n\n function notify() {\n subscriptions.forEach((fn) => fn());\n }\n\n return { subscribe, notify };\n}\n"],"file":"createSubscription.js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/utils/getCircularIndex.ts"],"names":["getCircularIndex","index","maxLength"],"mappings":"AAAA,OAAO,SAASA,gBAAT,CAA0BC,KAA1B,EAAyCC,SAAzC,EAA4D;AACjE,MAAIA,SAAS,GAAG,CAAhB,EAAmB;AACjB,WAAO,IAAP;AACD;;AAED,SAAO,CAAED,KAAK,GAAGC,SAAT,GAAsBA,SAAvB,IAAoCA,SAA3C;AACD","sourcesContent":["export function getCircularIndex(index: number, maxLength: number) {\n if (maxLength < 0) {\n return null;\n }\n\n return ((index % maxLength) + maxLength) % maxLength;\n}\n"],"file":"getCircularIndex.js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/utils/rubberBandClamp.ts"],"names":["rubberBand","distance","dimension","constant","rubberBandClamp","min","max","delta"],"mappings":"AAAA;AACA;AACA,OAAO,SAASA,UAAT,CACLC,QADK,EAELC,SAFK,EAIL;AAAA,MADAC,QACA,uEADW,IACX;AACA,SAAQF,QAAQ,GAAGC,SAAX,GAAuBC,QAAxB,IAAqCD,SAAS,GAAGC,QAAQ,GAAGF,QAA5D,CAAP;AACD;AAED,OAAO,SAASG,eAAT,CACLC,GADK,EAELC,GAFK,EAGLC,KAHK,EAKL;AAAA,MADAJ,QACA,uEADW,IACX;;AACA,MAAII,KAAK,GAAGF,GAAZ,EAAiB;AACf,WAAO,CAACL,UAAU,CAACK,GAAG,GAAGE,KAAP,EAAcD,GAAG,GAAGD,GAApB,EAAyBF,QAAzB,CAAX,GAAgDE,GAAvD;AACD;;AACD,MAAIE,KAAK,GAAGD,GAAZ,EAAiB;AACf,WAAON,UAAU,CAACO,KAAK,GAAGD,GAAT,EAAcA,GAAG,GAAGD,GAApB,EAAyBF,QAAzB,CAAV,GAA+CG,GAAtD;AACD;;AAED,SAAOC,KAAP;AACD","sourcesContent":["// https://twitter.com/chpwn/status/285540192096497664\n// iOS constant = 0.55\nexport function rubberBand(\n distance: number,\n dimension: number,\n constant = 0.15\n) {\n return (distance * dimension * constant) / (dimension + constant * distance);\n}\n\nexport function rubberBandClamp(\n min: number,\n max: number,\n delta: number,\n constant = 0.15\n) {\n if (delta < min) {\n return -rubberBand(min - delta, max - min, constant) + min;\n }\n if (delta > max) {\n return rubberBand(delta - max, max - min, constant) + max;\n }\n\n return delta;\n}\n"],"file":"rubberBandClamp.js"}
@@ -1,3 +0,0 @@
1
- /// <reference types="react" />
2
- export declare type CustomEventHandler<E extends React.SyntheticEvent<any>, H extends unknown[]> = (e: E, ...args: H) => void;
3
- export declare function wrapEvent<E extends React.SyntheticEvent<any>, H extends unknown[]>(theirHandler: CustomEventHandler<E, H> | undefined, ourHandler: CustomEventHandler<E, H>): CustomEventHandler<E, H>;
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/utils/wrapEvent.ts"],"names":["wrapEvent","theirHandler","ourHandler","event","otherArgs","ret","defaultPrevented"],"mappings":"AAKA,OAAO,SAASA,SAAT,CAILC,YAJK,EAKLC,UALK,EAMqB;AAC1B,SAAO,UAACC,KAAD,EAA+B;AAAA,sCAAjBC,SAAiB;AAAjBA,MAAAA,SAAiB;AAAA;;AACpC,QAAMC,GAAG,GAAGJ,YAAY,IAAIA,YAAY,MAAZ,UAAaE,KAAb,SAAuBC,SAAvB,EAA5B;;AACA,QAAI,CAACD,KAAK,CAACG,gBAAX,EAA6B;AAC3B,aAAOJ,UAAU,MAAV,UAAWC,KAAX,SAAqBC,SAArB,EAAP;AACD;;AACD,WAAOC,GAAP;AACD,GAND;AAOD","sourcesContent":["export type CustomEventHandler<\n E extends React.SyntheticEvent<any>,\n H extends unknown[]\n> = (e: E, ...args: H) => void;\n\nexport function wrapEvent<\n E extends React.SyntheticEvent<any>,\n H extends unknown[]\n>(\n theirHandler: CustomEventHandler<E, H> | undefined,\n ourHandler: CustomEventHandler<E, H>\n): CustomEventHandler<E, H> {\n return (event: E, ...otherArgs: H) => {\n const ret = theirHandler && theirHandler(event, ...otherArgs);\n if (!event.defaultPrevented) {\n return ourHandler(event, ...otherArgs);\n }\n return ret;\n };\n}\n"],"file":"wrapEvent.js"}