@sentry/scraps 0.3.0 → 0.5.0

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 (321) hide show
  1. package/README.md +6 -5
  2. package/dist/alert/alert.js +0 -3
  3. package/dist/badge/badge.js +1 -2
  4. package/dist/badge/tag.js +0 -2
  5. package/dist/button/index.d.ts +0 -1
  6. package/dist/button/index.js +0 -1
  7. package/dist/clipboard/copyToClipboardButton.d.ts +15 -0
  8. package/dist/clipboard/copyToClipboardButton.js +32 -0
  9. package/dist/clipboard/index.d.ts +1 -0
  10. package/dist/clipboard/index.js +1 -0
  11. package/dist/code/index.d.ts +1 -0
  12. package/dist/code/index.js +1 -0
  13. package/dist/codeBlock/codeBlock.d.ts +68 -0
  14. package/dist/codeBlock/codeBlock.js +242 -0
  15. package/dist/codeBlock/index.d.ts +2 -0
  16. package/dist/codeBlock/index.js +2 -0
  17. package/dist/codeBlock/prism.d.ts +11 -0
  18. package/dist/codeBlock/prism.js +101 -0
  19. package/dist/codeBlock/styles.d.ts +2 -0
  20. package/dist/codeBlock/styles.js +133 -0
  21. package/dist/compactSelect/compactSelect.d.ts +21 -0
  22. package/dist/compactSelect/compactSelect.js +150 -0
  23. package/dist/compactSelect/composite.d.ts +54 -0
  24. package/dist/compactSelect/composite.js +101 -0
  25. package/dist/compactSelect/control.d.ts +112 -0
  26. package/dist/compactSelect/control.js +354 -0
  27. package/dist/compactSelect/fzf.d.ts +8 -0
  28. package/dist/compactSelect/fzf.js +151 -0
  29. package/dist/compactSelect/gridList/index.d.ts +46 -0
  30. package/dist/compactSelect/gridList/index.js +102 -0
  31. package/dist/compactSelect/gridList/option.d.ts +15 -0
  32. package/dist/compactSelect/gridList/option.js +111 -0
  33. package/dist/compactSelect/gridList/section.d.ts +15 -0
  34. package/dist/compactSelect/gridList/section.js +58 -0
  35. package/dist/compactSelect/highlightText.d.ts +6 -0
  36. package/dist/compactSelect/highlightText.js +33 -0
  37. package/dist/compactSelect/index.d.ts +9 -0
  38. package/dist/compactSelect/index.js +8 -0
  39. package/dist/compactSelect/list.d.ts +94 -0
  40. package/dist/compactSelect/list.js +167 -0
  41. package/dist/compactSelect/listBox/index.d.ts +84 -0
  42. package/dist/compactSelect/listBox/index.js +175 -0
  43. package/dist/compactSelect/listBox/option.d.ts +19 -0
  44. package/dist/compactSelect/listBox/option.js +101 -0
  45. package/dist/compactSelect/listBox/section.d.ts +21 -0
  46. package/dist/compactSelect/listBox/section.js +58 -0
  47. package/dist/compactSelect/menuComponents.d.ts +89 -0
  48. package/dist/compactSelect/menuComponents.js +117 -0
  49. package/dist/compactSelect/selectFilterContext.d.ts +2 -0
  50. package/dist/compactSelect/selectFilterContext.js +3 -0
  51. package/dist/compactSelect/styles.d.ts +39 -0
  52. package/dist/compactSelect/styles.js +155 -0
  53. package/dist/compactSelect/types.d.ts +1 -0
  54. package/dist/compactSelect/types.js +0 -0
  55. package/dist/compactSelect/useVirtualizedItems.d.ts +52 -0
  56. package/dist/compactSelect/useVirtualizedItems.js +74 -0
  57. package/dist/compactSelect/utils.d.ts +80 -0
  58. package/dist/compactSelect/utils.js +268 -0
  59. package/dist/confirm/index.d.ts +153 -0
  60. package/dist/confirm/index.js +132 -0
  61. package/dist/descriptionList/descriptionList.js +4 -3
  62. package/dist/disclosure/disclosure.js +2 -2
  63. package/dist/dragHandle/dragHandle.d.ts +3 -1
  64. package/dist/dragHandle/dragHandle.js +8 -5
  65. package/dist/drawer/components.d.ts +46 -0
  66. package/dist/drawer/components.js +265 -0
  67. package/dist/drawer/globalDrawer.d.ts +106 -0
  68. package/dist/drawer/globalDrawer.js +173 -0
  69. package/dist/drawer/index.d.ts +3 -0
  70. package/dist/drawer/index.js +2 -0
  71. package/dist/drawer/useDrawerResizing.d.ts +19 -0
  72. package/dist/drawer/useDrawerResizing.js +111 -0
  73. package/dist/drawer/useDrawerWidth.d.ts +1 -0
  74. package/dist/drawer/useDrawerWidth.js +42 -0
  75. package/dist/dropdownMenu/content.d.ts +1 -0
  76. package/dist/dropdownMenu/content.js +1 -0
  77. package/dist/dropdownMenu/context.d.ts +24 -0
  78. package/dist/dropdownMenu/context.js +3 -0
  79. package/dist/dropdownMenu/dropdownMenu.d.ts +70 -0
  80. package/dist/dropdownMenu/dropdownMenu.js +103 -0
  81. package/dist/dropdownMenu/index.d.ts +2 -0
  82. package/dist/dropdownMenu/index.js +1 -0
  83. package/dist/dropdownMenu/item.d.ts +136 -0
  84. package/dist/dropdownMenu/item.js +182 -0
  85. package/dist/dropdownMenu/list.d.ts +59 -0
  86. package/dist/dropdownMenu/list.js +410 -0
  87. package/dist/dropdownMenu/search.d.ts +16 -0
  88. package/dist/dropdownMenu/search.js +16 -0
  89. package/dist/dropdownMenu/section.d.ts +21 -0
  90. package/dist/dropdownMenu/section.js +40 -0
  91. package/dist/dropdownMenu/separator.d.ts +7 -0
  92. package/dist/dropdownMenu/separator.js +15 -0
  93. package/dist/dropdownMenu/useDropdownMenuKeyboard.d.ts +260 -0
  94. package/dist/dropdownMenu/useDropdownMenuKeyboard.js +55 -0
  95. package/dist/dropdownMenu/useDropdownMenuRowLayout.d.ts +29 -0
  96. package/dist/dropdownMenu/useDropdownMenuRowLayout.js +64 -0
  97. package/dist/dropdownMenu/useSafetyTriangle.d.ts +12 -0
  98. package/dist/dropdownMenu/useSafetyTriangle.js +119 -0
  99. package/dist/dropdownMenu/utils.d.ts +21 -0
  100. package/dist/dropdownMenu/utils.js +57 -0
  101. package/dist/form/FormSearch.d.ts +19 -0
  102. package/dist/form/FormSearch.js +4 -0
  103. package/dist/form/autoSaveForm.d.ts +110 -0
  104. package/dist/form/autoSaveForm.js +100 -0
  105. package/dist/{formPresentation → form}/displayField.js +2 -2
  106. package/dist/form/field/baseField.d.ts +23 -0
  107. package/dist/form/field/baseField.js +116 -0
  108. package/dist/form/field/checkboxField.d.ts +11 -0
  109. package/dist/form/field/checkboxField.js +42 -0
  110. package/dist/form/field/checkboxGroupField.d.ts +16 -0
  111. package/dist/form/field/checkboxGroupField.js +80 -0
  112. package/dist/form/field/compactSelectField.d.ts +19 -0
  113. package/dist/form/field/compactSelectField.js +77 -0
  114. package/dist/{formPresentation → form/field}/fieldIds.js +1 -1
  115. package/dist/form/field/inputField.d.ts +19 -0
  116. package/dist/form/field/inputField.js +31 -0
  117. package/dist/{formPresentation → form/field}/meta.js +6 -6
  118. package/dist/form/field/numberField.d.ts +5 -0
  119. package/dist/form/field/numberField.js +11 -0
  120. package/dist/form/field/passwordField.d.ts +3 -0
  121. package/dist/form/field/passwordField.js +27 -0
  122. package/dist/form/field/radioGroupField.d.ts +16 -0
  123. package/dist/form/field/radioGroupField.js +92 -0
  124. package/dist/form/field/rangeField.d.ts +8 -0
  125. package/dist/form/field/rangeField.js +34 -0
  126. package/dist/form/field/selectAsyncField.d.ts +31 -0
  127. package/dist/form/field/selectAsyncField.js +22 -0
  128. package/dist/form/field/selectField.d.ts +9 -0
  129. package/dist/form/field/selectField.js +72 -0
  130. package/dist/form/field/switchField.d.ts +7 -0
  131. package/dist/form/field/switchField.js +37 -0
  132. package/dist/form/field/textAreaField.d.ts +7 -0
  133. package/dist/form/field/textAreaField.js +25 -0
  134. package/dist/{formPresentation → form}/formContext.js +1 -1
  135. package/dist/form/formErrorContext/index.d.ts +9 -0
  136. package/dist/form/formErrorContext/index.js +7 -0
  137. package/dist/form/index.d.ts +9 -0
  138. package/dist/form/index.js +8 -0
  139. package/dist/{formPresentation → form/layout}/base.d.ts +1 -1
  140. package/dist/{formPresentation → form/layout}/base.js +1 -1
  141. package/dist/form/layout/fieldGroup.d.ts +6 -0
  142. package/dist/form/layout/fieldGroup.js +60 -0
  143. package/dist/{formPresentation/fieldLayout.d.ts → form/layout/index.d.ts} +1 -1
  144. package/dist/{formPresentation/fieldLayout.js → form/layout/index.js} +3 -3
  145. package/dist/{formPresentation → form/layout}/useStackedLayout.js +1 -1
  146. package/dist/form/scrapsForm.d.ts +220 -0
  147. package/dist/form/scrapsForm.js +126 -0
  148. package/dist/hotkey/hotkey.d.ts +9 -8
  149. package/dist/hotkey/hotkey.js +13 -6
  150. package/dist/hotkey/index.d.ts +2 -1
  151. package/dist/hotkey/index.js +2 -1
  152. package/dist/hotkey/keyMappings.d.ts +1 -15
  153. package/dist/hotkey/keyMappings.js +29 -174
  154. package/dist/hotkey/useHotkeys.d.ts +3 -47
  155. package/dist/hotkey/useHotkeys.js +8 -42
  156. package/dist/image/image.js +2 -1
  157. package/dist/info/infoTip.d.ts +1 -1
  158. package/dist/info/infoTip.js +4 -3
  159. package/dist/input/index.d.ts +0 -3
  160. package/dist/input/index.js +0 -2
  161. package/dist/input/input.d.ts +2 -0
  162. package/dist/input/input.js +2 -0
  163. package/dist/input/passwordManagerIgnoreProps.d.ts +11 -0
  164. package/dist/input/passwordManagerIgnoreProps.js +8 -0
  165. package/dist/layout/index.d.ts +2 -2
  166. package/dist/layout/index.js +1 -1
  167. package/dist/layout/styles.d.ts +1 -1
  168. package/dist/link/link.js +4 -3
  169. package/dist/link/linkBehaviorContext.d.ts +2 -0
  170. package/dist/link/linkBehaviorContext.js +17 -10
  171. package/dist/menu/controlContext.d.ts +32 -0
  172. package/dist/menu/controlContext.js +7 -0
  173. package/dist/menu/dropdownButton.d.ts +18 -0
  174. package/dist/menu/dropdownButton.js +66 -0
  175. package/dist/menu/index.d.ts +7 -0
  176. package/dist/menu/index.js +3 -0
  177. package/dist/menu/menu.d.ts +167 -0
  178. package/dist/menu/menu.js +568 -0
  179. package/dist/menu/selectTypes.d.ts +96 -0
  180. package/dist/menu/selectTypes.js +0 -0
  181. package/dist/menu/selectValue.d.ts +13 -0
  182. package/dist/menu/selectValue.js +0 -0
  183. package/dist/modal/components.d.ts +19 -0
  184. package/dist/modal/components.js +99 -0
  185. package/dist/modal/errorBoundary.d.ts +2 -0
  186. package/dist/modal/errorBoundary.js +35 -0
  187. package/dist/modal/index.d.ts +33 -0
  188. package/dist/modal/index.js +260 -0
  189. package/dist/modal/portal.d.ts +1 -0
  190. package/dist/modal/portal.js +10 -0
  191. package/dist/modal/state.d.ts +17 -0
  192. package/dist/modal/state.js +41 -0
  193. package/dist/modal/types.d.ts +75 -0
  194. package/dist/modal/types.js +0 -0
  195. package/dist/numberInput/index.d.ts +3 -0
  196. package/dist/numberInput/index.js +2 -0
  197. package/dist/{input → numberInput}/numberDragInput.d.ts +1 -1
  198. package/dist/{input → numberInput}/numberDragInput.js +1 -1
  199. package/dist/{input → numberInput}/numberInput.d.ts +1 -1
  200. package/dist/{input → numberInput}/numberInput.js +1 -1
  201. package/dist/overlayContext.d.ts +29 -0
  202. package/dist/overlayContext.js +7 -0
  203. package/dist/overlayTrigger.d.ts +22 -0
  204. package/dist/overlayTrigger.js +30 -0
  205. package/dist/pagination/index.d.ts +1 -0
  206. package/dist/pagination/index.js +1 -0
  207. package/dist/pagination/pagination.d.ts +24 -0
  208. package/dist/pagination/pagination.js +63 -0
  209. package/dist/pictureInPicture/index.d.ts +2 -0
  210. package/dist/pictureInPicture/index.js +2 -0
  211. package/dist/pictureInPicture/pictureInPicture.d.ts +47 -0
  212. package/dist/pictureInPicture/pictureInPicture.js +100 -0
  213. package/dist/pictureInPicture/pictureInPicturePortal.d.ts +16 -0
  214. package/dist/pictureInPicture/pictureInPicturePortal.js +46 -0
  215. package/dist/pictureInPicture/portalContext.d.ts +2 -0
  216. package/dist/pictureInPicture/portalContext.js +3 -0
  217. package/dist/revealOnHover/revealOnHover.js +1 -1
  218. package/dist/segmentedControl/segmentedControl.js +1 -1
  219. package/dist/select/filter.d.ts +4 -0
  220. package/dist/select/filter.js +12 -0
  221. package/dist/select/index.d.ts +3 -0
  222. package/dist/select/index.js +2 -0
  223. package/dist/select/option.d.ts +16 -0
  224. package/dist/select/option.js +81 -0
  225. package/dist/select/reactSelectWrapper.d.ts +8 -0
  226. package/dist/select/reactSelectWrapper.js +25 -0
  227. package/dist/select/select.d.ts +79 -0
  228. package/dist/select/select.js +454 -0
  229. package/dist/select/styles.d.ts +9 -0
  230. package/dist/select/styles.js +27 -0
  231. package/dist/select/types.d.ts +60 -0
  232. package/dist/select/types.js +0 -0
  233. package/dist/select/virtualizedMenuList.d.ts +24 -0
  234. package/dist/select/virtualizedMenuList.js +123 -0
  235. package/dist/slideOverPanel.d.ts +20 -0
  236. package/dist/slideOverPanel.js +141 -0
  237. package/dist/slot/knownContexts.d.ts +1 -1
  238. package/dist/spinner/index.d.ts +1 -0
  239. package/dist/spinner/index.js +1 -0
  240. package/dist/spinner/spinner.d.ts +14 -0
  241. package/dist/spinner/spinner.js +126 -0
  242. package/dist/splitPanel/index.d.ts +1 -0
  243. package/dist/splitPanel/index.js +1 -0
  244. package/dist/splitPanel/splitPanel.d.ts +38 -0
  245. package/dist/splitPanel/splitPanel.js +145 -0
  246. package/dist/table/table.d.ts +1 -1
  247. package/dist/table/table.js +39 -20
  248. package/dist/table/useColumnResize.d.ts +6 -5
  249. package/dist/table/useColumnResize.js +5 -4
  250. package/dist/tabs/index.d.ts +4 -0
  251. package/dist/tabs/index.js +3 -0
  252. package/dist/tabs/item.d.ts +13 -0
  253. package/dist/tabs/item.js +4 -0
  254. package/dist/tabs/tab.d.ts +22 -0
  255. package/dist/tabs/tab.js +205 -0
  256. package/dist/tabs/tabList.d.ts +18 -0
  257. package/dist/tabs/tabList.js +256 -0
  258. package/dist/tabs/tabPanels.d.ts +14 -0
  259. package/dist/tabs/tabPanels.js +62 -0
  260. package/dist/tabs/tabs.d.ts +38 -0
  261. package/dist/tabs/tabs.js +56 -0
  262. package/dist/tabs/utils.d.ts +3 -0
  263. package/dist/tabs/utils.js +6 -0
  264. package/dist/text/heading.d.ts +1 -1
  265. package/dist/text/heading.js +1 -1
  266. package/dist/text/styles.js +1 -1
  267. package/dist/text/text.d.ts +1 -1
  268. package/dist/text/text.js +1 -1
  269. package/dist/theme/dark.js +9 -9
  270. package/dist/theme/light.js +9 -9
  271. package/dist/toast/index.d.ts +5 -0
  272. package/dist/toast/index.js +4 -0
  273. package/dist/toast/toast.d.ts +10 -0
  274. package/dist/toast/toast.js +182 -0
  275. package/dist/toast/toastApi.d.ts +10 -0
  276. package/dist/toast/toastApi.js +53 -0
  277. package/dist/toast/toaster.d.ts +4 -0
  278. package/dist/toast/toaster.js +42 -0
  279. package/dist/toast/types.d.ts +17 -0
  280. package/dist/toast/types.js +2 -0
  281. package/dist/toggleCard/index.d.ts +1 -0
  282. package/dist/toggleCard/index.js +1 -0
  283. package/dist/toggleCard/toggleCard.d.ts +32 -0
  284. package/dist/toggleCard/toggleCard.js +301 -0
  285. package/dist/tooltip/tooltip.js +2 -5
  286. package/dist/useDimensions.d.ts +12 -0
  287. package/dist/useDimensions.js +31 -0
  288. package/dist/useMedia.d.ts +15 -0
  289. package/dist/useMedia.js +24 -0
  290. package/dist/useOnClickOutside.d.ts +2 -0
  291. package/dist/useOnClickOutside.js +22 -0
  292. package/dist/useOverlay.d.ts +1 -0
  293. package/dist/useOverlay.js +1 -0
  294. package/dist/useResizableDrawer.d.ts +72 -0
  295. package/dist/useResizableDrawer.js +136 -0
  296. package/dist/useVirtualCollection.d.ts +154 -0
  297. package/dist/useVirtualCollection.js +143 -0
  298. package/dist/useVirtualRows.d.ts +26 -0
  299. package/dist/useVirtualRows.js +26 -0
  300. package/dist/virtualCollectionLayout.d.ts +51 -0
  301. package/dist/virtualCollectionLayout.js +49 -0
  302. package/package.json +148 -16
  303. package/dist/formPresentation/index.d.ts +0 -8
  304. package/dist/formPresentation/index.js +0 -8
  305. package/dist/interactionStateLayer/index.d.ts +0 -1
  306. package/dist/interactionStateLayer/index.js +0 -1
  307. package/dist/interactionStateLayer/interactionStateLayer.d.ts +0 -23
  308. package/dist/interactionStateLayer/interactionStateLayer.js +0 -67
  309. package/dist/unreachable.d.ts +0 -1
  310. package/dist/unreachable.js +0 -4
  311. /package/dist/{formPresentation → form}/autoSaveContext.d.ts +0 -0
  312. /package/dist/{formPresentation → form}/autoSaveContext.js +0 -0
  313. /package/dist/{formPresentation → form}/displayField.d.ts +0 -0
  314. /package/dist/{formPresentation → form/field}/fieldIds.d.ts +0 -0
  315. /package/dist/{formPresentation → form/field}/groupContext.d.ts +0 -0
  316. /package/dist/{formPresentation → form/field}/groupContext.js +0 -0
  317. /package/dist/{formPresentation → form/field}/meta.d.ts +0 -0
  318. /package/dist/{formPresentation → form}/formContext.d.ts +0 -0
  319. /package/dist/{formPresentation → form}/icons.d.ts +0 -0
  320. /package/dist/{formPresentation → form}/icons.js +0 -0
  321. /package/dist/{formPresentation → form/layout}/useStackedLayout.d.ts +0 -0
@@ -0,0 +1,12 @@
1
+ import type { RefObject } from 'react';
2
+ interface Props {
3
+ elementRef: RefObject<Element | null>;
4
+ }
5
+ /**
6
+ * Returns a ref to be added to an element and returns the dimensions of that element
7
+ */
8
+ export declare function useDimensions({ elementRef }: Props): {
9
+ height: number;
10
+ width: number;
11
+ };
12
+ export {};
@@ -0,0 +1,31 @@
1
+ import { useCallback, useLayoutEffect, useState } from "react";
2
+ import { useResizeObserver } from "@react-aria/utils";
3
+ function useDimensions({ elementRef }) {
4
+ const [dimensions, setDimensions] = useState({
5
+ height: 0,
6
+ width: 0
7
+ });
8
+ const element = elementRef.current;
9
+ useLayoutEffect(()=>{
10
+ setDimensions({
11
+ height: element?.clientHeight || 0,
12
+ width: element?.clientWidth || 0
13
+ });
14
+ }, [
15
+ element
16
+ ]);
17
+ const onResize = useCallback(()=>{
18
+ setDimensions({
19
+ height: element?.clientHeight || 0,
20
+ width: element?.clientWidth || 0
21
+ });
22
+ }, [
23
+ element
24
+ ]);
25
+ useResizeObserver({
26
+ ref: elementRef,
27
+ onResize
28
+ });
29
+ return dimensions;
30
+ }
31
+ export { useDimensions };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Hook that updates when a media query result changes.
3
+ *
4
+ * Prefer this only for genuine media features that aren't container-expressible
5
+ * — e.g. `(prefers-color-scheme: ...)`, `(hover: ...)`, `(pointer: ...)`,
6
+ * `(max-height: ...)`, `(resolution: ...)`.
7
+ *
8
+ * For width-based checks, prefer scraps responsive props — bare breakpoint
9
+ * keys react to the nearest container (`<Flex direction={{xs: 'column'}} />`),
10
+ * `screen:`-prefixed keys to the viewport — or, when you need the resolved
11
+ * value in JS, `useContainerBreakpoint()` from `@sentry/scraps/layout`.
12
+ * Those react to an element's available space rather than the raw viewport,
13
+ * which is almost always what width checks actually want.
14
+ */
15
+ export declare function useMedia(query: string): boolean;
@@ -0,0 +1,24 @@
1
+ import { useEffect, useState } from "react";
2
+ function useMedia(query) {
3
+ const [state, setState] = useState(()=>window.matchMedia?.(query)?.matches);
4
+ useEffect(()=>{
5
+ let mounted = true;
6
+ if (!window.matchMedia) return;
7
+ const mql = window.matchMedia(query);
8
+ const onChange = ()=>{
9
+ if (!mounted) return;
10
+ setState(!!mql.matches);
11
+ };
12
+ mql.addEventListener('change', onChange);
13
+ setState(mql.matches);
14
+ return ()=>{
15
+ mounted = false;
16
+ mql.removeEventListener('change', onChange);
17
+ };
18
+ }, [
19
+ query
20
+ ]);
21
+ if (!window.matchMedia) return false;
22
+ return state;
23
+ }
24
+ export { useMedia };
@@ -0,0 +1,2 @@
1
+ import type * as React from 'react';
2
+ export declare function useOnClickOutside<T extends HTMLElement = HTMLElement>(ref: React.RefObject<T | null> | T | null, handler: (event: MouseEvent | TouchEvent) => void): void;
@@ -0,0 +1,22 @@
1
+ import { useLayoutEffect } from "react";
2
+ function useOnClickOutside(ref, handler) {
3
+ useLayoutEffect(()=>{
4
+ const listener = (event)=>{
5
+ if (!ref) return;
6
+ let el;
7
+ el = 'current' in ref ? ref.current : ref;
8
+ if (!el || el.contains(event.target)) return;
9
+ handler(event);
10
+ };
11
+ document.addEventListener('mousedown', listener);
12
+ document.addEventListener('touchstart', listener);
13
+ return ()=>{
14
+ document.removeEventListener('mousedown', listener);
15
+ document.removeEventListener('touchstart', listener);
16
+ };
17
+ }, [
18
+ ref,
19
+ handler
20
+ ]);
21
+ }
22
+ export { useOnClickOutside };
@@ -63,6 +63,7 @@ interface UseOverlayResult {
63
63
  };
64
64
  isOpen: boolean;
65
65
  overlayProps: ReturnType<typeof useOverlayTriggerAria>['overlayProps'] & ReturnType<typeof useOverlayAria>['overlayProps'] & {
66
+ 'data-overlay-root': '';
66
67
  ref: React.Dispatch<React.SetStateAction<HTMLDivElement | null>>;
67
68
  style: React.CSSProperties | undefined;
68
69
  };
@@ -206,6 +206,7 @@ function useOverlay_useOverlay({ isOpen, onClose, defaultOpen, onOpenChange, typ
206
206
  overlayProps: {
207
207
  ref: setOverlayElement,
208
208
  style: overlayStyle,
209
+ 'data-overlay-root': '',
209
210
  ...mergeProps(overlayTriggerAriaProps, overlayAriaProps)
210
211
  },
211
212
  arrowProps: {
@@ -0,0 +1,72 @@
1
+ import type * as React from 'react';
2
+ export interface UseResizableDrawerOptions {
3
+ /**
4
+ * When dragging, which direction should be used for the delta
5
+ */
6
+ direction: 'right' | 'left' | 'down' | 'up';
7
+ /**
8
+ * The starting size of the container
9
+ */
10
+ initialSize: number;
11
+ /**
12
+ * The minimum sizes the container may be dragged to
13
+ */
14
+ min: number;
15
+ /**
16
+ * The maximum size the container may be dragged to. Optional — defaults
17
+ * to no upper bound. Only enforced during drag, mirroring `min`.
18
+ */
19
+ max?: number;
20
+ /**
21
+ * Triggered while dragging
22
+ */
23
+ onResize?: (newSize: number, maybeOldSize: number | undefined, userEvent: boolean) => void;
24
+ /**
25
+ * Fires once when a drag completes (on mouseUp). Receives the size at
26
+ * the start and end of the drag.
27
+ */
28
+ onResizeEnd?: (sizes: {
29
+ endSize: number;
30
+ startSize: number;
31
+ }) => void;
32
+ /**
33
+ * The local storage key used to persist the size of the container
34
+ */
35
+ sizeStorageKey?: string;
36
+ }
37
+ /**
38
+ * Hook to support draggable container resizing
39
+ *
40
+ * This only resizes one dimension at a time.
41
+ */
42
+ export declare function useResizableDrawer(options: UseResizableDrawerOptions): {
43
+ /**
44
+ * Indicates the drag handle is held. Useful to apply a styled to your handle
45
+ * that will not be removed if the mouse moves outside of the hitbox of your
46
+ * handle.
47
+ */
48
+ isHeld: boolean;
49
+ /**
50
+ * Apply this to include 'reset' functionality on the drag handle
51
+ */
52
+ onDoubleClick: React.MouseEventHandler<HTMLElement>;
53
+ /**
54
+ * Apply to the drag handle element
55
+ */
56
+ onMouseDown: React.MouseEventHandler<HTMLElement>;
57
+ /**
58
+ * Apply to the drag handle element. Supports touch and pen input.
59
+ */
60
+ onPointerDown: React.PointerEventHandler<HTMLElement>;
61
+ /**
62
+ * Call this function to manually set the size of the drawer.
63
+ */
64
+ setSize: (newSize: number, userEvent?: boolean) => void;
65
+ /**
66
+ * The resulting size of the container axis. Updated while dragging.
67
+ *
68
+ * NOTE: Be careful using this as this as react state updates are not
69
+ * synchronous, you may want to update the element size using onResize instead
70
+ */
71
+ size: number;
72
+ };
@@ -0,0 +1,136 @@
1
+ import { useCallback, useLayoutEffect, useRef, useState } from "react";
2
+ import { setDocumentDragging } from "./dragHandle/index.js";
3
+ function clampSize(value, min, max) {
4
+ return Math.min(max ?? 1 / 0, Math.max(min, value));
5
+ }
6
+ function useResizableDrawer(options) {
7
+ const rafIdRef = useRef(null);
8
+ const currentMouseVectorRaf = useRef(null);
9
+ const [size, setSize] = useState(()=>{
10
+ const storedSize = options.sizeStorageKey ? parseInt(localStorage.getItem(options.sizeStorageKey) ?? '', 10) : void 0;
11
+ return clampSize(storedSize || options.initialSize, options.min, options.max);
12
+ });
13
+ const [isHeld, setIsHeld] = useState(false);
14
+ const optionsRef = useRef(options);
15
+ useLayoutEffect(()=>{
16
+ optionsRef.current = options;
17
+ });
18
+ const updateSize = useCallback((newSize, userEvent = false)=>{
19
+ sizeRef.current = newSize;
20
+ setSize(newSize);
21
+ optionsRef.current.onResize?.(newSize, void 0, userEvent);
22
+ if (optionsRef.current.sizeStorageKey) localStorage.setItem(optionsRef.current.sizeStorageKey, newSize.toString());
23
+ }, []);
24
+ useLayoutEffect(()=>{
25
+ const clamped = clampSize(options.initialSize ?? 0, options.min, options.max);
26
+ options.onResize?.(clamped, size, false);
27
+ setSize(clamped);
28
+ }, [
29
+ options.direction
30
+ ]);
31
+ const sizeRef = useRef(size);
32
+ sizeRef.current = size;
33
+ const onDragMove = useCallback((event)=>{
34
+ event.stopPropagation();
35
+ event.preventDefault();
36
+ const isXAxis = 'left' === options.direction || 'right' === options.direction;
37
+ const isInverted = 'down' === options.direction || 'left' === options.direction;
38
+ setDocumentDragging(isXAxis ? 'ew-resize' : 'ns-resize');
39
+ if (null !== rafIdRef.current) window.cancelAnimationFrame(rafIdRef.current);
40
+ rafIdRef.current = window.requestAnimationFrame(()=>{
41
+ if (!currentMouseVectorRaf.current) return;
42
+ const newPositionVector = [
43
+ event.clientX,
44
+ event.clientY
45
+ ];
46
+ const newAxisPosition = isXAxis ? newPositionVector[0] : newPositionVector[1];
47
+ const currentAxisPosition = isXAxis ? currentMouseVectorRaf.current[0] : currentMouseVectorRaf.current[1];
48
+ const positionDelta = currentAxisPosition - newAxisPosition;
49
+ currentMouseVectorRaf.current = newPositionVector;
50
+ const newSize = Math.round(clampSize(sizeRef.current + positionDelta * (isInverted ? -1 : 1), options.min, options.max));
51
+ updateSize(newSize, true);
52
+ });
53
+ }, [
54
+ options.direction,
55
+ options.min,
56
+ options.max,
57
+ updateSize
58
+ ]);
59
+ const dragStartSizeRef = useRef(null);
60
+ const onDragEnd = useCallback(()=>{
61
+ setDocumentDragging(null);
62
+ document.removeEventListener('mousemove', onDragMove);
63
+ document.removeEventListener('mouseup', onDragEnd);
64
+ document.removeEventListener('pointermove', onDragMove);
65
+ document.removeEventListener('pointerup', onDragEnd);
66
+ document.removeEventListener('pointercancel', onDragEnd);
67
+ setIsHeld(false);
68
+ if (null !== dragStartSizeRef.current) {
69
+ options.onResizeEnd?.({
70
+ startSize: dragStartSizeRef.current,
71
+ endSize: sizeRef.current
72
+ });
73
+ dragStartSizeRef.current = null;
74
+ }
75
+ }, [
76
+ onDragMove,
77
+ options
78
+ ]);
79
+ const startDrag = useCallback((clientX, clientY)=>{
80
+ const { min, max } = optionsRef.current;
81
+ const clamped = clampSize(sizeRef.current, min, max);
82
+ sizeRef.current = clamped;
83
+ setSize(clamped);
84
+ setIsHeld(true);
85
+ dragStartSizeRef.current = clamped;
86
+ currentMouseVectorRaf.current = [
87
+ clientX,
88
+ clientY
89
+ ];
90
+ }, []);
91
+ const onMouseDown = useCallback((evt)=>{
92
+ if (0 !== evt.button) return;
93
+ evt.preventDefault();
94
+ startDrag(evt.clientX, evt.clientY);
95
+ document.addEventListener('mousemove', onDragMove, {
96
+ passive: false
97
+ });
98
+ document.addEventListener('mouseup', onDragEnd);
99
+ }, [
100
+ onDragMove,
101
+ onDragEnd,
102
+ startDrag
103
+ ]);
104
+ const onPointerDown = useCallback((evt)=>{
105
+ if (!evt.isPrimary || 'mouse' === evt.pointerType && 0 !== evt.button) return;
106
+ evt.preventDefault();
107
+ startDrag(evt.clientX, evt.clientY);
108
+ document.addEventListener('pointermove', onDragMove, {
109
+ passive: false
110
+ });
111
+ document.addEventListener('pointerup', onDragEnd);
112
+ document.addEventListener('pointercancel', onDragEnd);
113
+ }, [
114
+ onDragMove,
115
+ onDragEnd,
116
+ startDrag
117
+ ]);
118
+ const onDoubleClick = useCallback(()=>{
119
+ updateSize(options.initialSize, true);
120
+ }, [
121
+ updateSize,
122
+ options.initialSize
123
+ ]);
124
+ useLayoutEffect(()=>()=>{
125
+ if (null !== rafIdRef.current) window.cancelAnimationFrame(rafIdRef.current);
126
+ });
127
+ return {
128
+ size,
129
+ isHeld,
130
+ onMouseDown,
131
+ onPointerDown,
132
+ onDoubleClick,
133
+ setSize: updateSize
134
+ };
135
+ }
136
+ export { useResizableDrawer };
@@ -0,0 +1,154 @@
1
+ import type * as React from 'react';
2
+ import type { Key, Node } from '@react-types/shared';
3
+ import type { FormSize } from './theme/index.js';
4
+ export { estimateRowHeight, isAfterFirstInSection } from './virtualCollectionLayout.js';
5
+ /**
6
+ * Item count above which shared menu controls (CompactSelect, DropdownMenu)
7
+ * virtualize their list.
8
+ */
9
+ export declare const DEFAULT_VIRTUALIZE_THRESHOLD = 150;
10
+ /**
11
+ * Lists a collection's nodes in the order `useVirtualCollection` renders them:
12
+ * each section is followed by its child nodes, so a long section is windowed
13
+ * like any other run of rows instead of mounting all at once. Nodes in
14
+ * `hiddenKeys` are left out, whether they are sections, their children or
15
+ * top-level items.
16
+ */
17
+ export declare function flattenSections<T>(nodes: Iterable<Node<T>>, hiddenKeys?: ReadonlySet<Key>): Array<Node<T>>;
18
+ /** Props for the element that renders a row. Spread them onto the row's root element. */
19
+ export interface VirtualRowProps {
20
+ 'data-index': number;
21
+ ref: (element: Element | null) => void;
22
+ }
23
+ export interface VirtualRow<T> {
24
+ node: Node<T>;
25
+ /** Undefined when virtualization is disabled. */
26
+ props: VirtualRowProps | undefined;
27
+ /**
28
+ * Height of the unmounted rows between this row and the previous one. Render
29
+ * a `VirtualSpacer` of this height before the row. Usually only the first
30
+ * row has space before it, but the focused row stays mounted when it scrolls
31
+ * out of view, so there can be a gap on either side of it.
32
+ */
33
+ spaceBefore: number;
34
+ }
35
+ export interface UseVirtualCollectionOptions<T> {
36
+ /**
37
+ * The collection's top-level nodes, such as a React Aria `state.collection`.
38
+ * Each section's child nodes are windowed as rows of their own, see
39
+ * `flattenSections`.
40
+ */
41
+ collection: Iterable<Node<T>>;
42
+ /** Whether to virtualize. When false, every node is returned as a row. */
43
+ enabled: boolean;
44
+ /**
45
+ * The element that scrolls. Rows and spacers must render inside it.
46
+ */
47
+ scrollRef: React.RefObject<HTMLElement | null>;
48
+ /**
49
+ * Height to assume for a row that has not been measured yet. Read on every
50
+ * render, so it does not need to be stable. Defaults to the height of a menu
51
+ * `ListItem` of `size`, plus `sectionRowSpace`.
52
+ */
53
+ estimateSize?: (node: Node<T>, index: number) => number;
54
+ /**
55
+ * The collection's focused key. When it changes through the keyboard, the
56
+ * row is scrolled into view so it mounts and React Aria can focus it. The
57
+ * focused row also stays mounted while it is scrolled out of view, so it
58
+ * keeps DOM focus and the keyboard keeps working.
59
+ */
60
+ focusedKey?: Key | null;
61
+ /** Keys of nodes to leave out, whether they are sections, their children or top-level items. */
62
+ hiddenKeys?: ReadonlySet<Key>;
63
+ /**
64
+ * Vertical CSS padding (px) of the list, at each end. The first row starts
65
+ * below it, and rows scrolled into view keep clear of it.
66
+ */
67
+ listPadding?: number;
68
+ /**
69
+ * Space (px) above each row in a section except the first, if the rows are
70
+ * spaced that way. The virtualizer measures a row's border box, so the space
71
+ * must be padding on the row's own element for mounted rows to keep it. A
72
+ * margin, or a gap on the list, is not part of a measured row: the rows would
73
+ * lose it once they mount and the scroll range would shrink. Added to the
74
+ * estimates of unmounted rows so the range does not shrink until they mount.
75
+ */
76
+ sectionRowSpace?: number;
77
+ /**
78
+ * Item size of the default `estimateSize`. Defaults to `md`. Changing it, or
79
+ * `sectionRowSpace`, discards the measured row heights, since every row
80
+ * changes height. Pass it with a custom `estimateSize` too.
81
+ */
82
+ size?: FormSize;
83
+ /**
84
+ * A row to keep mounted wherever the list is scrolled, such as the one with
85
+ * the longest label. A list that sizes its width to its content is then as
86
+ * wide as that row from the start, instead of widening as wider rows scroll
87
+ * into view.
88
+ */
89
+ widestKey?: Key | null;
90
+ }
91
+ /** The result of `useVirtualCollection`. Render it with `VirtualRows`. */
92
+ export interface VirtualCollection<T> {
93
+ /** The rows to render, in order: every node, or the mounted ones when virtualized. */
94
+ rows: Array<VirtualRow<T>>;
95
+ /** Height of the unmounted rows after the last mounted one. */
96
+ spaceAfter: number;
97
+ }
98
+ /**
99
+ * Windows a React Aria collection so only the rows near the viewport mount.
100
+ *
101
+ * It owns layout only, never selection or focus. Callers keep their React Aria
102
+ * state and render the rows with `VirtualRows`, which puts each row in its
103
+ * section and fills the space of the unmounted rows:
104
+ *
105
+ * ```tsx
106
+ * const virtual = useVirtualCollection({
107
+ * collection: state.collection,
108
+ * enabled,
109
+ * size,
110
+ * scrollRef,
111
+ * focusedKey: state.selectionManager.focusedKey,
112
+ * });
113
+ * <ul ref={scrollRef}>
114
+ * <VirtualRows
115
+ * virtual={virtual}
116
+ * renderRow={({node, props}) => <Option {...props} node={node} />}
117
+ * renderSection={({node, props}, rows) => (
118
+ * <Section rowProps={props} node={node}>{rows}</Section>
119
+ * )}
120
+ * />
121
+ * </ul>
122
+ * ```
123
+ *
124
+ * Spacers keep the list's own element and padding intact, so a virtualized
125
+ * list has the same DOM structure and styling as a regular one.
126
+ */
127
+ export declare function useVirtualCollection<T>({ collection, enabled, scrollRef, estimateSize, focusedKey, hiddenKeys, listPadding, sectionRowSpace, size, widestKey, }: UseVirtualCollectionOptions<T>): VirtualCollection<T>;
128
+ interface VirtualRowsProps<T> {
129
+ /**
130
+ * Renders an item row. Spread `props` onto the element that is the row's
131
+ * height, so the virtualizer can measure it.
132
+ *
133
+ * The list re-renders on every scroll, and `props` is a new object each time.
134
+ * To let a row that did not change skip rendering, pass the row component
135
+ * `props['data-index']` and `props.ref` as separate props, which keep their
136
+ * identity, and rebuild the object inside it.
137
+ */
138
+ renderRow: (row: VirtualRow<T>) => React.ReactNode;
139
+ /** The result of `useVirtualCollection`. */
140
+ virtual: VirtualCollection<T>;
141
+ /**
142
+ * Renders a section around its rendered rows. Spread the section's `props`
143
+ * onto the element above its rows, such as the one holding its header.
144
+ * Required when the collection has sections; by default only the rows render.
145
+ */
146
+ renderSection?: (section: VirtualRow<T>, rows: React.ReactNode) => React.ReactNode;
147
+ }
148
+ /**
149
+ * Renders the rows of `useVirtualCollection`, with each row inside its section
150
+ * and spacers in place of the unmounted rows. Render it inside the scroll
151
+ * element. Rows outside sections stay siblings, so they keep their elements
152
+ * when the list reorders.
153
+ */
154
+ export declare function VirtualRows<T>({ virtual, renderRow, renderSection, }: VirtualRowsProps<T>): import("@emotion/react/jsx-runtime").JSX.Element;
@@ -0,0 +1,143 @@
1
+ import { jsx, jsxs } from "@emotion/react/jsx-runtime";
2
+ import { Fragment, useEffect } from "react";
3
+ import { getInteractionModality } from "@react-aria/interactions";
4
+ import { defaultRangeExtractor, observeElementRect } from "@tanstack/react-virtual";
5
+ import { Container } from "./layout/index.js";
6
+ import { useVirtualRows } from "./useVirtualRows.js";
7
+ import { estimateRowHeight, getMountedIndexes, getSectionIndexes, isAfterFirstInSection } from "./virtualCollectionLayout.js";
8
+ const DEFAULT_VIRTUALIZE_THRESHOLD = 150;
9
+ function flattenSections(nodes, hiddenKeys) {
10
+ const isVisible = (node)=>!hiddenKeys?.has(node.key);
11
+ return [
12
+ ...nodes
13
+ ].filter(isVisible).flatMap((node)=>'section' === node.type ? [
14
+ node,
15
+ ...[
16
+ ...node.childNodes
17
+ ].filter(isVisible)
18
+ ] : [
19
+ node
20
+ ]);
21
+ }
22
+ const observeViewportCappedRect = (instance, cb)=>observeElementRect(instance, (rect)=>cb({
23
+ width: rect.width,
24
+ height: Math.min(rect.height, instance.targetWindow?.innerHeight ?? rect.height)
25
+ }));
26
+ function useVirtualCollection({ collection, enabled, scrollRef, estimateSize, focusedKey, hiddenKeys, listPadding = 0, sectionRowSpace = 0, size = 'md', widestKey }) {
27
+ const nodes = flattenSections(collection, hiddenKeys);
28
+ const focusedIndex = enabled && null != focusedKey ? nodes.findIndex((node)=>node.key === focusedKey) : -1;
29
+ const widestIndex = enabled && null != widestKey ? nodes.findIndex((node)=>node.key === widestKey) : -1;
30
+ const sectionIndexes = getSectionIndexes(nodes);
31
+ const rangeExtractor = (range)=>getMountedIndexes({
32
+ windowIndexes: defaultRangeExtractor(range),
33
+ focusedIndex,
34
+ widestIndex,
35
+ sectionIndexes
36
+ });
37
+ const { virtualizer, virtualItems, totalSize } = useVirtualRows({
38
+ count: nodes.length,
39
+ enabled,
40
+ getScrollElement: ()=>scrollRef.current,
41
+ getItemKey: (index)=>nodes[index]?.key ?? index,
42
+ estimateSize: (index)=>{
43
+ const node = nodes[index];
44
+ return estimateSize && node ? estimateSize(node, index) : estimateRowHeight(node, nodes[sectionIndexes[index] ?? -1], size, sectionRowSpace);
45
+ },
46
+ estimateKey: `${size}-${sectionRowSpace}`,
47
+ paddingStart: listPadding,
48
+ scrollPaddingStart: listPadding,
49
+ scrollPaddingEnd: listPadding,
50
+ overscan: 1,
51
+ rangeExtractor,
52
+ observeElementRect: observeViewportCappedRect
53
+ });
54
+ useEffect(()=>{
55
+ if (-1 === focusedIndex || 'pointer' === getInteractionModality()) return;
56
+ virtualizer.scrollToIndex(focusedIndex, {
57
+ align: 'auto'
58
+ });
59
+ }, [
60
+ focusedIndex,
61
+ virtualizer
62
+ ]);
63
+ const rows = enabled ? virtualItems.flatMap((item, position)=>{
64
+ const node = nodes[item.index];
65
+ if (!node) return [];
66
+ const previousEnd = virtualItems[position - 1]?.end ?? listPadding;
67
+ return [
68
+ {
69
+ node,
70
+ props: {
71
+ 'data-index': item.index,
72
+ ref: virtualizer.measureElement
73
+ },
74
+ spaceBefore: Math.max(0, item.start - previousEnd)
75
+ }
76
+ ];
77
+ }) : nodes.map((node)=>({
78
+ node,
79
+ props: void 0,
80
+ spaceBefore: 0
81
+ }));
82
+ const last = virtualItems.at(-1);
83
+ return {
84
+ rows,
85
+ spaceAfter: enabled ? Math.max(0, totalSize - (last?.end ?? listPadding)) : 0
86
+ };
87
+ }
88
+ function groupVirtualRows(rows) {
89
+ const groups = [];
90
+ for (const row of rows){
91
+ const group = groups.at(-1);
92
+ if ('section' === row.node.type) groups.push({
93
+ section: row,
94
+ rows: []
95
+ });
96
+ else if (group?.section && group.section.node.key === row.node.parentKey) group.rows.push(row);
97
+ else groups.push({
98
+ rows: [
99
+ row
100
+ ]
101
+ });
102
+ }
103
+ return groups;
104
+ }
105
+ function VirtualSpacer({ height }) {
106
+ if (height <= 0) return null;
107
+ return /*#__PURE__*/ jsx(Container, {
108
+ as: "li",
109
+ "aria-hidden": true,
110
+ role: "presentation",
111
+ height: `${height}px`,
112
+ flexShrink: 0
113
+ });
114
+ }
115
+ function renderSectionRows(_section, rows) {
116
+ return rows;
117
+ }
118
+ function VirtualRows({ virtual, renderRow, renderSection = renderSectionRows }) {
119
+ const renderWithSpacer = (row)=>/*#__PURE__*/ jsxs(Fragment, {
120
+ children: [
121
+ /*#__PURE__*/ jsx(VirtualSpacer, {
122
+ height: row.spaceBefore
123
+ }),
124
+ renderRow(row)
125
+ ]
126
+ }, row.node.key);
127
+ return /*#__PURE__*/ jsxs(Fragment, {
128
+ children: [
129
+ groupVirtualRows(virtual.rows).flatMap(({ section, rows })=>section ? /*#__PURE__*/ jsxs(Fragment, {
130
+ children: [
131
+ /*#__PURE__*/ jsx(VirtualSpacer, {
132
+ height: section.spaceBefore
133
+ }),
134
+ renderSection(section, rows.map(renderWithSpacer))
135
+ ]
136
+ }, section.node.key) : rows.map(renderWithSpacer)),
137
+ /*#__PURE__*/ jsx(VirtualSpacer, {
138
+ height: virtual.spaceAfter
139
+ })
140
+ ]
141
+ });
142
+ }
143
+ export { DEFAULT_VIRTUALIZE_THRESHOLD, VirtualRows, estimateRowHeight, flattenSections, isAfterFirstInSection, useVirtualCollection };
@@ -0,0 +1,26 @@
1
+ import { type Range, type Rect, type VirtualizerOptions } from '@tanstack/react-virtual';
2
+ export interface UseVirtualRowsOptions {
3
+ count: number;
4
+ estimateSize: (index: number) => number;
5
+ getScrollElement: () => HTMLElement | null;
6
+ enabled?: boolean;
7
+ estimateKey?: unknown;
8
+ gap?: number;
9
+ getItemKey?: (index: number) => string | number | bigint;
10
+ initialRect?: Rect;
11
+ observeElementRect?: VirtualizerOptions<HTMLElement, Element>['observeElementRect'];
12
+ overscan?: number;
13
+ paddingEnd?: number;
14
+ paddingStart?: number;
15
+ rangeExtractor?: (range: Range) => number[];
16
+ scrollPaddingEnd?: number;
17
+ scrollPaddingStart?: number;
18
+ useAnimationFrameWithResizeObserver?: boolean;
19
+ }
20
+ export declare function useVirtualRows({ estimateKey, overscan, ...options }: UseVirtualRowsOptions): {
21
+ virtualizer: import("@tanstack/react-virtual").ReactVirtualizer<HTMLElement, Element>;
22
+ virtualItems: import("@tanstack/react-virtual").VirtualItem[];
23
+ paddingTop: number;
24
+ paddingBottom: number;
25
+ totalSize: number;
26
+ };