@sentry/scraps 0.5.0 → 0.7.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 (177) hide show
  1. package/README.md +95 -3
  2. package/dist/alert/alert.js +10 -7
  3. package/dist/badge/tag.js +4 -2
  4. package/dist/button/button.js +1 -0
  5. package/dist/button/linkButton.js +1 -0
  6. package/dist/button/styles.js +157 -152
  7. package/dist/codeBlock/codeBlock.js +1 -0
  8. package/dist/compactSelect/compactSelect.d.ts +2 -2
  9. package/dist/compactSelect/compactSelect.js +37 -23
  10. package/dist/compactSelect/control.js +14 -10
  11. package/dist/compactSelect/gridList/index.js +35 -36
  12. package/dist/compactSelect/gridList/option.d.ts +4 -1
  13. package/dist/compactSelect/gridList/option.js +4 -3
  14. package/dist/compactSelect/gridList/section.d.ts +10 -3
  15. package/dist/compactSelect/gridList/section.js +16 -33
  16. package/dist/compactSelect/listBox/index.d.ts +1 -1
  17. package/dist/compactSelect/listBox/index.js +46 -58
  18. package/dist/compactSelect/listBox/section.d.ts +10 -8
  19. package/dist/compactSelect/listBox/section.js +11 -30
  20. package/dist/compactSelect/styles.d.ts +6 -7
  21. package/dist/compactSelect/styles.js +1 -23
  22. package/dist/compactSelect/utils.js +2 -6
  23. package/dist/dateTime/config.d.ts +23 -0
  24. package/dist/dateTime/config.js +50 -0
  25. package/dist/dateTime/context.d.ts +18 -0
  26. package/dist/dateTime/context.js +46 -0
  27. package/dist/dateTime/dateTime.d.ts +6 -0
  28. package/dist/dateTime/dateTime.js +30 -0
  29. package/dist/dateTime/format.d.ts +24 -0
  30. package/dist/dateTime/format.js +45 -0
  31. package/dist/dateTime/index.d.ts +6 -0
  32. package/dist/dateTime/index.js +6 -0
  33. package/dist/dateTime/intlFormatter.d.ts +9 -0
  34. package/dist/dateTime/intlFormatter.js +16 -0
  35. package/dist/dateTime/parseDate.d.ts +3 -0
  36. package/dist/dateTime/parseDate.js +12 -0
  37. package/dist/diagnostics/context.d.ts +12 -0
  38. package/dist/diagnostics/context.js +11 -0
  39. package/dist/diagnostics/index.d.ts +2 -0
  40. package/dist/diagnostics/index.js +1 -0
  41. package/dist/disclosure/disclosure.js +1 -1
  42. package/dist/dragHandle/dragHandle.js +3 -5
  43. package/dist/dropdownMenu/context.d.ts +36 -11
  44. package/dist/dropdownMenu/context.js +2 -1
  45. package/dist/dropdownMenu/dropdownMenu.d.ts +2 -2
  46. package/dist/dropdownMenu/dropdownMenu.js +9 -3
  47. package/dist/dropdownMenu/item.d.ts +7 -8
  48. package/dist/dropdownMenu/item.js +43 -77
  49. package/dist/dropdownMenu/list.d.ts +31 -5
  50. package/dist/dropdownMenu/list.js +154 -133
  51. package/dist/dropdownMenu/useDropdownMenuKeyboard.d.ts +5 -241
  52. package/dist/dropdownMenu/useDropdownMenuKeyboard.js +5 -29
  53. package/dist/dropdownMenu/useDropdownMenuRowLayout.js +6 -14
  54. package/dist/dropdownMenu/useDropdownRootMenuState.d.ts +13 -0
  55. package/dist/dropdownMenu/useDropdownRootMenuState.js +30 -0
  56. package/dist/dropdownMenu/useDropdownSubmenuState.d.ts +19 -0
  57. package/dist/dropdownMenu/useDropdownSubmenuState.js +25 -0
  58. package/dist/dropdownMenu/utils.js +5 -7
  59. package/dist/duration/formatElapsedDuration.d.ts +4 -0
  60. package/dist/duration/formatElapsedDuration.js +10 -0
  61. package/dist/duration/getDuration.d.ts +68 -0
  62. package/dist/duration/getDuration.js +80 -0
  63. package/dist/duration/index.d.ts +2 -0
  64. package/dist/duration/index.js +2 -0
  65. package/dist/form/field/radioGroupField.d.ts +7 -0
  66. package/dist/form/field/radioGroupField.js +14 -0
  67. package/dist/form/field/selectField.d.ts +3 -4
  68. package/dist/form/field/selectField.js +16 -24
  69. package/dist/{compactSelect/fzf.d.ts → fzf.d.ts} +1 -0
  70. package/dist/{compactSelect/fzf.js → fzf.js} +5 -1
  71. package/dist/layout/container.d.ts +24 -7
  72. package/dist/layout/container.js +9 -12
  73. package/dist/layout/flex.js +1 -1
  74. package/dist/layout/grid.js +2 -2
  75. package/dist/layout/index.d.ts +1 -1
  76. package/dist/layout/index.js +1 -1
  77. package/dist/layout/stack.js +1 -1
  78. package/dist/layout/styles.d.ts +28 -7
  79. package/dist/layout/styles.js +76 -16
  80. package/dist/layout/surface.d.ts +2 -2
  81. package/dist/layout/surface.js +6 -3
  82. package/dist/legacyDatetime.d.ts +21 -0
  83. package/dist/legacyDatetime.js +13 -0
  84. package/dist/link/index.d.ts +1 -1
  85. package/dist/link/index.js +1 -1
  86. package/dist/link/linkBehaviorContext.d.ts +9 -0
  87. package/dist/link/linkBehaviorContext.js +37 -7
  88. package/dist/menu/menu.d.ts +1 -3
  89. package/dist/menu/menu.js +5 -6
  90. package/dist/menu/selectValue.d.ts +2 -6
  91. package/dist/modal/components.js +2 -2
  92. package/dist/overlayArrow.js +2 -2
  93. package/dist/relativeTime/getRelativeDate.d.ts +14 -0
  94. package/dist/relativeTime/getRelativeDate.js +107 -0
  95. package/dist/relativeTime/index.d.ts +3 -0
  96. package/dist/relativeTime/index.js +3 -0
  97. package/dist/relativeTime/relativeTime.d.ts +55 -0
  98. package/dist/relativeTime/relativeTime.js +102 -0
  99. package/dist/relativeTime/useRelativeTimeFormatter.d.ts +2 -0
  100. package/dist/relativeTime/useRelativeTimeFormatter.js +10 -0
  101. package/dist/select/chips.d.ts +14 -0
  102. package/dist/select/chips.js +45 -0
  103. package/dist/select/filter.js +7 -11
  104. package/dist/select/index.d.ts +1 -1
  105. package/dist/select/indicators.d.ts +11 -0
  106. package/dist/select/indicators.js +61 -0
  107. package/dist/select/menu.d.ts +44 -0
  108. package/dist/select/menu.js +103 -0
  109. package/dist/select/option.d.ts +23 -15
  110. package/dist/select/option.js +66 -58
  111. package/dist/select/options.d.ts +31 -0
  112. package/dist/select/options.js +74 -0
  113. package/dist/select/select.d.ts +24 -11
  114. package/dist/select/select.js +527 -429
  115. package/dist/select/styles.d.ts +148 -2
  116. package/dist/select/styles.js +156 -1
  117. package/dist/select/types.d.ts +6 -7
  118. package/dist/select/types.js +4 -0
  119. package/dist/select/utils.d.ts +2 -0
  120. package/dist/select/utils.js +4 -0
  121. package/dist/separator/separator.d.ts +2 -2
  122. package/dist/separator/separator.js +4 -3
  123. package/dist/slot/slot.js +16 -12
  124. package/dist/tabs/context.d.ts +9 -0
  125. package/dist/tabs/context.js +9 -0
  126. package/dist/tabs/index.d.ts +2 -4
  127. package/dist/tabs/index.js +1 -3
  128. package/dist/tabs/item.d.ts +16 -5
  129. package/dist/tabs/tab.js +9 -4
  130. package/dist/tabs/tabList.d.ts +5 -5
  131. package/dist/tabs/tabList.js +8 -6
  132. package/dist/tabs/tabPanels.d.ts +2 -3
  133. package/dist/tabs/tabPanels.js +1 -1
  134. package/dist/tabs/tabs.d.ts +46 -31
  135. package/dist/tabs/tabs.js +38 -35
  136. package/dist/text/prose.d.ts +2 -2
  137. package/dist/theme/index.d.ts +2 -0
  138. package/dist/theme/index.js +2 -0
  139. package/dist/theme/theme.d.ts +34 -34
  140. package/dist/theme/theme.js +9 -0
  141. package/dist/theme/types.d.ts +21 -2
  142. package/dist/theme/useResolvedTheme.d.ts +12 -0
  143. package/dist/theme/useResolvedTheme.js +20 -0
  144. package/dist/theme/variables.css +1116 -0
  145. package/dist/theme/variables.d.ts +985 -0
  146. package/dist/theme/variables.js +455 -0
  147. package/dist/translation/index.d.ts +1 -0
  148. package/dist/translation/index.js +1 -0
  149. package/dist/translation/translate.d.ts +9 -0
  150. package/dist/translation/translate.js +5 -0
  151. package/dist/translation/translationContext.d.ts +2 -1
  152. package/dist/translation/translationContext.js +2 -1
  153. package/dist/useVirtualCollection.d.ts +14 -1
  154. package/dist/useVirtualCollection.js +59 -3
  155. package/fonts/OFL.txt +94 -0
  156. package/fonts/roboto-mono-variable-cyrillic-ext.woff2 +0 -0
  157. package/fonts/roboto-mono-variable-cyrillic.woff2 +0 -0
  158. package/fonts/roboto-mono-variable-greek.woff2 +0 -0
  159. package/fonts/roboto-mono-variable-latin-ext.woff2 +0 -0
  160. package/fonts/roboto-mono-variable-vietnamese.woff2 +0 -0
  161. package/fonts/roboto-mono-variable.woff2 +0 -0
  162. package/fonts/rubik-variable-cyrillic-ext.woff2 +0 -0
  163. package/fonts/rubik-variable-cyrillic.woff2 +0 -0
  164. package/fonts/rubik-variable-latin-ext.woff2 +0 -0
  165. package/fonts/rubik-variable.woff2 +0 -0
  166. package/fonts.css +211 -0
  167. package/package.json +39 -15
  168. package/dist/compactSelect/useVirtualizedItems.d.ts +0 -52
  169. package/dist/compactSelect/useVirtualizedItems.js +0 -74
  170. package/dist/datetime.d.ts +0 -39
  171. package/dist/datetime.js +0 -20
  172. package/dist/dropdownMenu/useSafetyTriangle.d.ts +0 -12
  173. package/dist/dropdownMenu/useSafetyTriangle.js +0 -119
  174. package/dist/select/reactSelectWrapper.d.ts +0 -8
  175. package/dist/select/reactSelectWrapper.js +0 -25
  176. package/dist/select/virtualizedMenuList.d.ts +0 -24
  177. package/dist/select/virtualizedMenuList.js +0 -123
@@ -3,13 +3,15 @@ import { createElement } from "@emotion/react";
3
3
  import { useCallback, useEffect, useId, useMemo, useRef, useState } from "react";
4
4
  import { Item, Section } from "@react-stately/collections";
5
5
  import { useTranslation } from "../translation/index.js";
6
+ import { DEFAULT_VIRTUALIZE_THRESHOLD } from "../useVirtualCollection.js";
7
+ import { useDiagnostics } from "../diagnostics/context.js";
6
8
  import { Control } from "./control.js";
7
9
  import { List } from "./list.js";
8
10
  import { EmptyMessage } from "./styles.js";
9
11
  import { getDuplicateOptionKeysInfo, getItemsWithKeys, shouldCloseOnSelect } from "./utils.js";
10
- import * as __rspack_external__sentry_react_f0cda475 from "@sentry/react";
11
12
  function CompactSelect({ options, value, onChange, multiple, clearable, isOptionDisabled, sizeLimit, sizeLimitMessage, virtualizeThreshold, mode, disabled, emptyMessage, size = 'md', closeOnSelect, menuWidth, ...controlProps }) {
12
13
  const { t } = useTranslation();
14
+ const diagnostics = useDiagnostics();
13
15
  const generatedTriggerId = useId();
14
16
  const triggerId = controlProps.triggerId ?? generatedTriggerId;
15
17
  const listProps = useMemo(()=>{
@@ -43,23 +45,7 @@ function CompactSelect({ options, value, onChange, multiple, clearable, isOption
43
45
  const allItemsWithKey = useMemo(()=>getItemsWithKeys(options), [
44
46
  options
45
47
  ]);
46
- const longestOptionItemsWithKey = useMemo(()=>{
47
- if (needsMeasuring) {
48
- let longestOption;
49
- let longestLength = -1;
50
- for (const option of options){
51
- const length = 'options' in option ? 0 : option.textValue ? option.textValue.length : 'string' == typeof option.label ? option.label.length : 0;
52
- if (length > longestLength) {
53
- longestOption = option;
54
- longestLength = length;
55
- }
56
- }
57
- return longestOption ? getItemsWithKeys([
58
- longestOption
59
- ]) : [];
60
- }
61
- return [];
62
- }, [
48
+ const longestOptionItemsWithKey = useMemo(()=>needsMeasuring ? getItemsWithKeys(getLongestOptionItems(options)) : [], [
63
49
  needsMeasuring,
64
50
  options
65
51
  ]);
@@ -77,7 +63,7 @@ function CompactSelect({ options, value, onChange, multiple, clearable, isOption
77
63
  const duplicateOptionKeySignature = duplicateOptionKeys.join(',');
78
64
  if (lastLoggedDuplicateKeySignatureRef.current === duplicateOptionKeySignature) return;
79
65
  lastLoggedDuplicateKeySignatureRef.current = duplicateOptionKeySignature;
80
- __rspack_external__sentry_react_f0cda475.logger.error('CompactSelect has duplicate option keys', {
66
+ diagnostics.logger.error('CompactSelect has duplicate option keys', {
81
67
  component_title: componentTitle,
82
68
  duplicate_option_key_count: duplicateOptionKeys.length,
83
69
  duplicate_option_key_signature: duplicateOptionKeySignature,
@@ -88,6 +74,7 @@ function CompactSelect({ options, value, onChange, multiple, clearable, isOption
88
74
  }, [
89
75
  allItemsWithKey,
90
76
  componentTitle,
77
+ diagnostics,
91
78
  virtualizeThreshold
92
79
  ]);
93
80
  return /*#__PURE__*/ jsxs(Control, {
@@ -142,9 +129,36 @@ function CompactSelect({ options, value, onChange, multiple, clearable, isOption
142
129
  ]
143
130
  });
144
131
  }
145
- function shouldVirtualize(items, virtualizeThreshold = 150) {
146
- const hasSections = items.some((item)=>'options' in item);
147
- if (hasSections) return false;
148
- return items.length > virtualizeThreshold;
132
+ function shouldVirtualize(items, virtualizeThreshold = DEFAULT_VIRTUALIZE_THRESHOLD) {
133
+ const optionCount = items.reduce((count, item)=>count + ('options' in item ? item.options.length : 1), 0);
134
+ return optionCount > virtualizeThreshold;
135
+ }
136
+ function getLabelLength(option) {
137
+ if (option.textValue) return option.textValue.length;
138
+ return 'string' == typeof option.label ? option.label.length : 0;
139
+ }
140
+ function getLongestOptionItems(items) {
141
+ let longest;
142
+ let longestLength = -1;
143
+ for (const item of items){
144
+ const options = 'options' in item ? item.options : [
145
+ item
146
+ ];
147
+ for (const option of options){
148
+ const length = getLabelLength(option);
149
+ if (length > longestLength) {
150
+ longestLength = length;
151
+ longest = 'options' in item ? {
152
+ ...item,
153
+ options: [
154
+ option
155
+ ]
156
+ } : option;
157
+ }
158
+ }
159
+ }
160
+ return longest ? [
161
+ longest
162
+ ] : [];
149
163
  }
150
164
  export { CompactSelect };
@@ -193,6 +193,7 @@ function Control({ autoFocus, trigger, triggerId, isOpen, onClose, isDismissable
193
193
  return /*#__PURE__*/ jsx(ControlContext, {
194
194
  value: contextValue,
195
195
  children: /*#__PURE__*/ jsxs(Container, {
196
+ display: "flex",
196
197
  width: "max-content",
197
198
  position: "relative",
198
199
  ...wrapperProps,
@@ -222,13 +223,13 @@ function Control({ autoFocus, trigger, triggerId, isOpen, onClose, isDismissable
222
223
  contain: true,
223
224
  children: [
224
225
  hasHeader && /*#__PURE__*/ jsx(Header, {
225
- borderBottom: searchEnabled ? 'none' : 'muted',
226
+ borderBottomColor: searchEnabled ? 'none' : 'secondary',
227
+ padding: searchEnabled ? 'xs lg 0 lg' : 'xs lg',
226
228
  children: /*#__PURE__*/ jsxs(Flex, {
227
229
  align: "center",
228
230
  justify: "between",
229
231
  gap: "xl",
230
232
  minHeight: "24px",
231
- padding: searchEnabled ? 'xs lg 0 lg' : 'xs lg',
232
233
  children: [
233
234
  menuTitle && /*#__PURE__*/ jsx(Title, {
234
235
  children: menuTitle
@@ -259,14 +260,17 @@ function Control({ autoFocus, trigger, triggerId, isOpen, onClose, isDismissable
259
260
  ]
260
261
  })
261
262
  }),
262
- searchEnabled && /*#__PURE__*/ jsx(Search, {
263
- ref: searchRef,
264
- placeholder: normalizedSearch?.placeholder ?? 'Search…',
265
- value: searchInputValue,
266
- onFocus: onSearchFocus,
267
- onBlur: onSearchBlur,
268
- onChange: (e)=>updateSearch(e.target.value),
269
- ...searchKeyboardProps
263
+ searchEnabled && /*#__PURE__*/ jsx(Container, {
264
+ borderBottomColor: "secondary",
265
+ children: /*#__PURE__*/ jsx(Search, {
266
+ ref: searchRef,
267
+ placeholder: normalizedSearch?.placeholder ?? 'Search…',
268
+ value: searchInputValue,
269
+ onFocus: onSearchFocus,
270
+ onBlur: onSearchBlur,
271
+ onChange: (e)=>updateSearch(e.target.value),
272
+ ...searchKeyboardProps
273
+ })
270
274
  }),
271
275
  'function' == typeof menuBody ? menuBody({
272
276
  closeOverlay: overlayState.close
@@ -1,20 +1,22 @@
1
1
  import { jsx, jsxs } from "@emotion/react/jsx-runtime";
2
- import { createElement } from "@emotion/react";
2
+ import { createElement, useTheme } from "@emotion/react";
3
3
  import { useContext, useId, useMemo, useRef } from "react";
4
4
  import { useGridList } from "@react-aria/gridlist";
5
5
  import { mergeProps } from "@react-aria/utils";
6
6
  import { SelectFilterContext } from "../selectFilterContext.js";
7
7
  import { ListLabel, ListSeparator, ListWrap, SizeLimitMessage } from "../styles.js";
8
- import { useVirtualizedItems } from "../useVirtualizedItems.js";
9
8
  import { hasVisibleLeadingItems } from "../utils.js";
10
9
  import { Container } from "../../layout/index.js";
11
10
  import { ControlContext, ReserveLeadingSlot } from "../../menu/index.js";
12
11
  import { useTranslation } from "../../translation/index.js";
12
+ import { VirtualRows, useVirtualCollection } from "../../useVirtualCollection.js";
13
13
  import { GridListOption } from "./option.js";
14
14
  import { GridListSection } from "./section.js";
15
15
  function GridList({ listState, size = 'md', label, sizeLimitMessage, keyDownHandler, virtualized, ...props }) {
16
16
  const { t } = useTranslation();
17
+ const theme = useTheme();
17
18
  const ref = useRef(null);
19
+ const scrollElementRef = useRef(null);
18
20
  const labelId = useId();
19
21
  const { gridProps } = useGridList({
20
22
  ...props,
@@ -41,9 +43,13 @@ function GridList({ listState, size = 'md', label, sizeLimitMessage, keyDownHand
41
43
  listItems,
42
44
  hiddenOptions
43
45
  ]);
44
- const virtualizer = useVirtualizedItems({
45
- listItems,
46
- virtualized,
46
+ const virtual = useVirtualCollection({
47
+ collection: listItems,
48
+ enabled: !!virtualized,
49
+ scrollRef: scrollElementRef,
50
+ focusedKey: listState.selectionManager.focusedKey,
51
+ hiddenKeys: hiddenOptions,
52
+ listPadding: parseFloat(theme.space.xs),
47
53
  size
48
54
  });
49
55
  const mergedProps = mergeProps(gridProps, props);
@@ -58,42 +64,35 @@ function GridList({ listState, size = 'md', label, sizeLimitMessage, keyDownHand
58
64
  children: label
59
65
  }),
60
66
  overlayIsOpen && /*#__PURE__*/ jsx(Container, {
61
- ref: virtualizer.scrollElementRef,
67
+ ref: scrollElementRef,
62
68
  height: "100%",
63
69
  overflowY: "auto",
64
- children: /*#__PURE__*/ jsx(Container, {
65
- ...virtualizer.wrapperProps,
66
- children: /*#__PURE__*/ jsxs(ListWrap, {
67
- ...mergedProps,
68
- style: {
69
- ...mergedProps.style,
70
- ...virtualizer.listWrapStyle
71
- },
72
- onKeyDown: onKeyDown,
73
- ref: ref,
74
- children: [
75
- virtualizer.items.map((row)=>{
76
- const item = listItems[row.index];
77
- if (!item) return null;
78
- if ('section' === item.type) return /*#__PURE__*/ createElement(GridListSection, {
79
- ...virtualizer.itemProps(row.index),
80
- key: item.key,
81
- node: item,
70
+ children: /*#__PURE__*/ jsxs(ListWrap, {
71
+ ...mergedProps,
72
+ onKeyDown: onKeyDown,
73
+ ref: ref,
74
+ children: [
75
+ /*#__PURE__*/ jsx(VirtualRows, {
76
+ virtual: virtual,
77
+ renderRow: ({ node, props: rowProps })=>/*#__PURE__*/ createElement(GridListOption, {
78
+ ...rowProps,
79
+ key: node.key,
80
+ node: node,
82
81
  listState: listState,
83
82
  size: size
84
- });
85
- return /*#__PURE__*/ jsx(GridListOption, {
86
- ...virtualizer.itemProps(row.index),
87
- node: item,
83
+ }),
84
+ renderSection: (section, rows)=>/*#__PURE__*/ jsx(GridListSection, {
85
+ node: section.node,
88
86
  listState: listState,
89
- size: size
90
- }, item.key);
91
- }),
92
- !searchable && hiddenOptions.size > 0 && /*#__PURE__*/ jsx(SizeLimitMessage, {
93
- children: sizeLimitMessage ?? t('Use search to find more options…')
94
- })
95
- ]
96
- })
87
+ rowProps: section.props,
88
+ showSeparator: section.node !== listItems[0],
89
+ children: rows
90
+ })
91
+ }),
92
+ !searchable && hiddenOptions.size > 0 && /*#__PURE__*/ jsx(SizeLimitMessage, {
93
+ children: sizeLimitMessage ?? t('Use search to find more options…')
94
+ })
95
+ ]
97
96
  })
98
97
  })
99
98
  ]
@@ -1,3 +1,4 @@
1
+ import type * as React from 'react';
1
2
  import type { AriaGridListItemOptions } from '@react-aria/gridlist';
2
3
  import type { ListState } from '@react-stately/list';
3
4
  import type { Node } from '@react-types/shared';
@@ -7,9 +8,11 @@ export interface GridListOptionProps<T extends ListItemBase> extends AriaGridLis
7
8
  listState: ListState<T>;
8
9
  node: Node<T>;
9
10
  size: FormSize;
11
+ 'data-index'?: number;
12
+ ref?: React.Ref<HTMLLIElement>;
10
13
  }
11
14
  /**
12
15
  * A <li /> element with accessibile behaviors & attributes.
13
16
  * https://react-spectrum.adobe.com/react-aria/useGridList.html
14
17
  */
15
- export declare function GridListOption<T extends ListItemBase>({ node, listState, size, }: GridListOptionProps<T>): import("@emotion/react/jsx-runtime").JSX.Element;
18
+ export declare function GridListOption<T extends ListItemBase>({ node, listState, size, ref: refProp, 'data-index': dataIndex, }: GridListOptionProps<T>): import("@emotion/react/jsx-runtime").JSX.Element;
@@ -2,13 +2,13 @@ import { jsx, jsxs } from "@emotion/react/jsx-runtime";
2
2
  import { Fragment, useContext, useMemo, useRef, useState } from "react";
3
3
  import { useGridListItem, useGridListSelectionCheckbox } from "@react-aria/gridlist";
4
4
  import { useFocusWithin, useHover } from "@react-aria/interactions";
5
- import { mergeProps } from "@react-aria/utils";
5
+ import { mergeProps, mergeRefs } from "@react-aria/utils";
6
6
  import { IconCheckmark } from "@sentry/icons/checkmark";
7
7
  import { Checkbox } from "../../checkbox/index.js";
8
8
  import { HighlightText } from "../highlightText.js";
9
9
  import { LeadWrap, getOptionPaddingLeft } from "../styles.js";
10
10
  import { ControlContext, ListItem, useReserveLeadingSlot } from "../../menu/index.js";
11
- function GridListOption({ node, listState, size }) {
11
+ function GridListOption({ node, listState, size, ref: refProp, 'data-index': dataIndex }) {
12
12
  const ref = useRef(null);
13
13
  const { label, details, trailingItems, priority, hideCheck, tooltip, tooltipOptions, selectionMode } = node.props;
14
14
  const multiple = selectionMode ? 'multiple' === selectionMode : 'multiple' === listState.selectionManager.selectionMode;
@@ -84,7 +84,8 @@ function GridListOption({ node, listState, size }) {
84
84
  ]);
85
85
  return /*#__PURE__*/ jsx(ListItem, {
86
86
  ...rowPropsMerged,
87
- ref: ref,
87
+ "data-index": dataIndex,
88
+ ref: mergeRefs(ref, refProp),
88
89
  size: size,
89
90
  label: renderedLabel,
90
91
  details: details,
@@ -1,15 +1,22 @@
1
+ import type * as React from 'react';
1
2
  import type { ListState } from '@react-stately/list';
2
3
  import type { Node } from '@react-types/shared';
3
4
  import type { ListItemBase } from '../types.js';
4
- import { type GridListOptionProps } from './option.js';
5
+ import type { VirtualRowProps } from '../../useVirtualCollection.js';
5
6
  interface GridListSectionProps<T extends ListItemBase> {
7
+ children: React.ReactNode;
6
8
  listState: ListState<T>;
7
9
  node: Node<T>;
8
- size: GridListOptionProps<T>['size'];
10
+ showSeparator: boolean;
11
+ /**
12
+ * Measurement props for the section's own row when the list is virtualized.
13
+ * The row holds the separator and header above the section's options.
14
+ */
15
+ rowProps?: VirtualRowProps;
9
16
  }
10
17
  /**
11
18
  * A <li /> element that functions as a grid list section (renders a nested <ul />
12
19
  * inside). https://react-spectrum.adobe.com/react-aria/useGridList.html
13
20
  */
14
- export declare function GridListSection<T extends ListItemBase>({ node, listState, size, }: GridListSectionProps<T>): import("@emotion/react/jsx-runtime").JSX.Element;
21
+ export declare function GridListSection<T extends ListItemBase>({ children, node, listState, showSeparator, rowProps, }: GridListSectionProps<T>): import("@emotion/react/jsx-runtime").JSX.Element;
15
22
  export {};
@@ -1,37 +1,23 @@
1
1
  import { jsx, jsxs } from "@emotion/react/jsx-runtime";
2
- import { Fragment, useContext, useId, useMemo } from "react";
3
- import { useSeparator } from "@react-aria/separator";
4
- import { SelectFilterContext } from "../selectFilterContext.js";
2
+ import { useId } from "react";
5
3
  import { SectionSeparator } from "../styles.js";
6
4
  import { SectionToggle } from "../utils.js";
7
5
  import { SectionGroup, SectionHeader, SectionLabel, SectionList } from "../../menu/index.js";
8
- import { GridListOption } from "./option.js";
9
- function GridListSection({ node, listState, size }) {
6
+ function GridListSection({ children, node, listState, showSeparator, rowProps }) {
10
7
  const titleId = useId();
11
- const { separatorProps } = useSeparator({
12
- elementType: 'li'
13
- });
14
8
  const showToggleAllButton = 'multiple' === listState.selectionManager.selectionMode && node.value?.showToggleAllButton;
15
- const hiddenOptions = useContext(SelectFilterContext);
16
- const childNodes = useMemo(()=>[
17
- ...node.childNodes
18
- ].filter((child)=>!hiddenOptions.has(child.key)), [
19
- node.childNodes,
20
- hiddenOptions
21
- ]);
22
- return /*#__PURE__*/ jsxs(Fragment, {
9
+ return /*#__PURE__*/ jsxs(SectionGroup, {
10
+ role: "rowgroup",
11
+ ...node['aria-label'] ? {
12
+ 'aria-label': node['aria-label']
13
+ } : {
14
+ 'aria-labelledby': titleId
15
+ },
23
16
  children: [
24
- /*#__PURE__*/ jsx(SectionSeparator, {
25
- ...separatorProps
26
- }),
27
- /*#__PURE__*/ jsxs(SectionGroup, {
28
- role: "rowgroup",
29
- ...node['aria-label'] ? {
30
- 'aria-label': node['aria-label']
31
- } : {
32
- 'aria-labelledby': titleId
33
- },
17
+ /*#__PURE__*/ jsxs("div", {
18
+ ...rowProps,
34
19
  children: [
20
+ showSeparator && /*#__PURE__*/ jsx(SectionSeparator, {}),
35
21
  (node.rendered || showToggleAllButton) && /*#__PURE__*/ jsx(SectionHeader, {
36
22
  trailingAction: showToggleAllButton ? /*#__PURE__*/ jsx(SectionToggle, {
37
23
  item: node,
@@ -39,18 +25,15 @@ function GridListSection({ node, listState, size }) {
39
25
  }) : null,
40
26
  children: node.rendered && /*#__PURE__*/ jsx(SectionLabel, {
41
27
  id: titleId,
28
+ size: "md",
42
29
  "aria-hidden": true,
43
30
  children: node.rendered
44
31
  })
45
- }),
46
- /*#__PURE__*/ jsx(SectionList, {
47
- children: childNodes.map((child)=>/*#__PURE__*/ jsx(GridListOption, {
48
- node: child,
49
- listState: listState,
50
- size: size
51
- }, child.key))
52
32
  })
53
33
  ]
34
+ }),
35
+ /*#__PURE__*/ jsx(SectionList, {
36
+ children: children
54
37
  })
55
38
  ]
56
39
  });
@@ -66,7 +66,7 @@ interface ListBoxProps<T extends ListItemBase> extends Omit<React.HTMLAttributes
66
66
  */
67
67
  virtualized?: boolean;
68
68
  /**
69
- * Vertical padding (in px) added to the virtualizer height. Defaults to 4 (theme.space.xs).
69
+ * Vertical padding (in px) added to the virtualizer height. Defaults to ListWrap's padding, theme.space.xs.
70
70
  */
71
71
  virtualizedListPadding?: number;
72
72
  }
@@ -1,15 +1,14 @@
1
1
  import { jsx, jsxs } from "@emotion/react/jsx-runtime";
2
- import { createElement } from "@emotion/react";
2
+ import { createElement, useTheme } from "@emotion/react";
3
3
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
4
- import { getInteractionModality } from "@react-aria/interactions";
5
4
  import { useListBox } from "@react-aria/listbox";
6
5
  import { mergeProps, mergeRefs } from "@react-aria/utils";
7
6
  import { ListLabel, ListSeparator, ListWrap, SizeLimitMessage } from "../styles.js";
8
- import { useVirtualizedItems } from "../useVirtualizedItems.js";
9
7
  import { hasVisibleLeadingItems } from "../utils.js";
10
8
  import { Container } from "../../layout/index.js";
11
9
  import { ReserveLeadingSlot } from "../../menu/index.js";
12
10
  import { useTranslation } from "../../translation/index.js";
11
+ import { VirtualRows, useVirtualCollection } from "../../useVirtualCollection.js";
13
12
  import { ListBoxDetailsHoverContext, ListBoxOption } from "./option.js";
14
13
  import { ListBoxSection } from "./section.js";
15
14
  const EMPTY_SET = new Set();
@@ -17,10 +16,11 @@ const DETAILS_CLOSE_DELAY = 150;
17
16
  const DEFAULT_KEY_DOWN_HANDLER = ()=>true;
18
17
  function ListBox({ ref, listState, autoFocus, size = 'md', shouldFocusWrap = true, shouldFocusOnHover = true, sizeLimitMessage, keyDownHandler = DEFAULT_KEY_DOWN_HANDLER, label, hiddenOptions = EMPTY_SET, hasSearch, searchable, overlayIsOpen, showSectionHeaders = true, showDetails = true, onAction, virtualized, virtualizedListPadding, scrollContainerRef, className, ...props }) {
19
18
  const { t } = useTranslation();
19
+ const theme = useTheme();
20
20
  const listElementRef = useRef(null);
21
21
  const scrollElementRef = useRef(null);
22
22
  const [hasEverOverflowed, setHasEverOverflowed] = useState(false);
23
- const { listBoxProps, labelProps } = useListBox({
23
+ const listBoxOptions = {
24
24
  ...props,
25
25
  scrollRef: scrollElementRef,
26
26
  autoFocus,
@@ -29,7 +29,8 @@ function ListBox({ ref, listState, autoFocus, size = 'md', shouldFocusWrap = tru
29
29
  shouldFocusOnHover,
30
30
  shouldSelectOnPressUp: true,
31
31
  onAction
32
- }, listState, listElementRef);
32
+ };
33
+ const { listBoxProps, labelProps } = useListBox(listBoxOptions, listState, listElementRef);
33
34
  const onKeyDown = (e)=>{
34
35
  const continueCallback = keyDownHandler?.(e);
35
36
  if (continueCallback && 'Escape' !== e.key) listBoxProps.onKeyDown?.(e);
@@ -79,31 +80,26 @@ function ListBox({ ref, listState, autoFocus, size = 'md', shouldFocusWrap = tru
79
80
  mergedProps.onMouseEnter?.(e);
80
81
  cancelFocusClear();
81
82
  };
82
- const virtualizer = useVirtualizedItems({
83
- listItems,
84
- virtualized,
85
- size,
86
- listPadding: virtualizedListPadding
83
+ const virtual = useVirtualCollection({
84
+ collection: listItems,
85
+ enabled: !!virtualized,
86
+ scrollRef: scrollElementRef,
87
+ focusedKey: listState.selectionManager.focusedKey,
88
+ hiddenKeys: hiddenOptions,
89
+ listPadding: virtualizedListPadding ?? parseFloat(theme.space.xs),
90
+ size
87
91
  });
88
- useEffect(()=>{
89
- if (!virtualized || null === listState.selectionManager.focusedKey || 'pointer' === getInteractionModality()) return;
90
- const focusedIndex = listItems.findIndex((item)=>item.key === listState.selectionManager.focusedKey);
91
- if (-1 !== focusedIndex) virtualizer.scrollToIndex(focusedIndex);
92
- }, [
93
- virtualized,
94
- listItems,
95
- listState.selectionManager.focusedKey,
96
- virtualizer
97
- ]);
98
92
  const refs = useMemo(()=>{
99
93
  const overflowTracker = (scrollContainer)=>{
100
94
  if (hasEverOverflowed || 0 === listItems.length || !scrollContainer) return;
101
- setHasEverOverflowed(scrollContainer.scrollHeight > scrollContainer.clientHeight);
95
+ requestAnimationFrame(()=>{
96
+ const overflowed = scrollContainer.scrollHeight - scrollContainer.clientHeight > 1;
97
+ setHasEverOverflowed((prev)=>prev || overflowed);
98
+ });
102
99
  };
103
- return mergeRefs(scrollElementRef, overflowTracker, virtualizer.scrollElementRef, scrollContainerRef);
100
+ return mergeRefs(scrollElementRef, overflowTracker, scrollContainerRef);
104
101
  }, [
105
102
  hasEverOverflowed,
106
- virtualizer.scrollElementRef,
107
103
  listItems,
108
104
  scrollContainerRef
109
105
  ]);
@@ -121,51 +117,43 @@ function ListBox({ ref, listState, autoFocus, size = 'md', shouldFocusWrap = tru
121
117
  }),
122
118
  /*#__PURE__*/ jsx(Container, {
123
119
  ref: refs,
120
+ "data-test-id": "compact-select-scroll-container",
124
121
  height: "100%",
125
122
  overflowY: "auto",
126
123
  className: className,
127
124
  style: hasEverOverflowed ? {
128
125
  scrollbarGutter: 'stable'
129
126
  } : void 0,
130
- children: /*#__PURE__*/ jsx(Container, {
131
- ...virtualizer.wrapperProps,
132
- children: /*#__PURE__*/ jsxs(ListWrap, {
133
- ...mergedProps,
134
- style: {
135
- ...mergedProps.style,
136
- ...virtualizer.listWrapStyle
137
- },
138
- onKeyDown: onKeyDown,
139
- onMouseEnter: onMouseEnter,
140
- onMouseLeave: onMouseLeave,
141
- ref: mergeRefs(listElementRef, ref),
142
- children: [
143
- overlayIsOpen && virtualizer.items.map((row)=>{
144
- const item = listItems[row.index];
145
- if (!item) return null;
146
- if ('section' === item.type) return /*#__PURE__*/ createElement(ListBoxSection, {
147
- ...virtualizer.itemProps(row.index),
148
- key: item.key,
149
- item: item,
127
+ children: /*#__PURE__*/ jsxs(ListWrap, {
128
+ ...mergedProps,
129
+ onKeyDown: onKeyDown,
130
+ onMouseEnter: onMouseEnter,
131
+ onMouseLeave: onMouseLeave,
132
+ ref: mergeRefs(listElementRef, ref),
133
+ children: [
134
+ overlayIsOpen && /*#__PURE__*/ jsx(VirtualRows, {
135
+ virtual: virtual,
136
+ renderRow: ({ node, props: rowProps })=>/*#__PURE__*/ createElement(ListBoxOption, {
137
+ ...rowProps,
138
+ key: node.key,
139
+ item: node,
150
140
  listState: listState,
151
- hiddenOptions: hiddenOptions,
152
141
  size: size,
153
- showSectionHeaders: showSectionHeaders,
154
142
  showDetails: showDetails
155
- });
156
- return /*#__PURE__*/ jsx(ListBoxOption, {
157
- ...virtualizer.itemProps(row.index),
158
- item: item,
143
+ }),
144
+ renderSection: (section, rows)=>/*#__PURE__*/ jsx(ListBoxSection, {
145
+ item: section.node,
159
146
  listState: listState,
160
- size: size,
161
- showDetails: showDetails
162
- }, item.key);
163
- }),
164
- !searchable && !hasSearch && hiddenOptions.size > 0 && /*#__PURE__*/ jsx(SizeLimitMessage, {
165
- children: sizeLimitMessage ?? t('Use search to find more options…')
166
- })
167
- ]
168
- })
147
+ rowProps: section.props,
148
+ showSectionHeaders: showSectionHeaders,
149
+ showSeparator: section.node !== listItems[0],
150
+ children: rows
151
+ })
152
+ }),
153
+ !searchable && !hasSearch && hiddenOptions.size > 0 && /*#__PURE__*/ jsx(SizeLimitMessage, {
154
+ children: sizeLimitMessage ?? t('Use search to find more options…')
155
+ })
156
+ ]
169
157
  })
170
158
  })
171
159
  ]
@@ -1,21 +1,23 @@
1
1
  import type * as React from 'react';
2
2
  import type { ListState } from '@react-stately/list';
3
3
  import type { Node } from '@react-types/shared';
4
- import type { SelectKey, ListItemBase } from '../types.js';
5
- import { type ListBoxOptionProps } from './option.js';
4
+ import type { ListItemBase } from '../types.js';
5
+ import type { VirtualRowProps } from '../../useVirtualCollection.js';
6
6
  interface ListBoxSectionProps<T extends ListItemBase> {
7
- hiddenOptions: Set<SelectKey>;
7
+ children: React.ReactNode;
8
8
  item: Node<T>;
9
9
  listState: ListState<T>;
10
10
  showSectionHeaders: boolean;
11
- size: ListBoxOptionProps['size'];
12
- 'data-index'?: number;
13
- ref?: React.Ref<HTMLLIElement>;
14
- showDetails?: boolean;
11
+ showSeparator: boolean;
12
+ /**
13
+ * Measurement props for the section's own row when the list is virtualized.
14
+ * The row holds the separator and header above the section's options.
15
+ */
16
+ rowProps?: VirtualRowProps;
15
17
  }
16
18
  /**
17
19
  * A <li /> element that functions as a list box section (renders a nested <ul />
18
20
  * inside). https://react-spectrum.adobe.com/react-aria/useListBox.html
19
21
  */
20
- export declare function ListBoxSection<T extends ListItemBase>({ item, listState, size, hiddenOptions, showSectionHeaders, showDetails, ref, 'data-index': dataIndex, }: ListBoxSectionProps<T>): import("@emotion/react/jsx-runtime").JSX.Element;
22
+ export declare function ListBoxSection<T extends ListItemBase>({ children, item, listState, showSectionHeaders, showSeparator, rowProps, }: ListBoxSectionProps<T>): import("@emotion/react/jsx-runtime").JSX.Element;
21
23
  export {};