@react-aria/grid 3.0.0-beta.0 → 3.0.0-nightly-641446f65-240905

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 (239) hide show
  1. package/dist/GridKeyboardDelegate.main.js +247 -0
  2. package/dist/GridKeyboardDelegate.main.js.map +1 -0
  3. package/dist/GridKeyboardDelegate.mjs +242 -0
  4. package/dist/GridKeyboardDelegate.module.js +242 -0
  5. package/dist/GridKeyboardDelegate.module.js.map +1 -0
  6. package/dist/ar-AE.main.js +15 -0
  7. package/dist/ar-AE.main.js.map +1 -0
  8. package/dist/ar-AE.mjs +17 -0
  9. package/dist/ar-AE.module.js +17 -0
  10. package/dist/ar-AE.module.js.map +1 -0
  11. package/dist/bg-BG.main.js +15 -0
  12. package/dist/bg-BG.main.js.map +1 -0
  13. package/dist/bg-BG.mjs +17 -0
  14. package/dist/bg-BG.module.js +17 -0
  15. package/dist/bg-BG.module.js.map +1 -0
  16. package/dist/cs-CZ.main.js +15 -0
  17. package/dist/cs-CZ.main.js.map +1 -0
  18. package/dist/cs-CZ.mjs +17 -0
  19. package/dist/cs-CZ.module.js +17 -0
  20. package/dist/cs-CZ.module.js.map +1 -0
  21. package/dist/da-DK.main.js +15 -0
  22. package/dist/da-DK.main.js.map +1 -0
  23. package/dist/da-DK.mjs +17 -0
  24. package/dist/da-DK.module.js +17 -0
  25. package/dist/da-DK.module.js.map +1 -0
  26. package/dist/de-DE.main.js +15 -0
  27. package/dist/de-DE.main.js.map +1 -0
  28. package/dist/de-DE.mjs +17 -0
  29. package/dist/de-DE.module.js +17 -0
  30. package/dist/de-DE.module.js.map +1 -0
  31. package/dist/el-GR.main.js +15 -0
  32. package/dist/el-GR.main.js.map +1 -0
  33. package/dist/el-GR.mjs +17 -0
  34. package/dist/el-GR.module.js +17 -0
  35. package/dist/el-GR.module.js.map +1 -0
  36. package/dist/en-US.main.js +15 -0
  37. package/dist/en-US.main.js.map +1 -0
  38. package/dist/en-US.mjs +17 -0
  39. package/dist/en-US.module.js +17 -0
  40. package/dist/en-US.module.js.map +1 -0
  41. package/dist/es-ES.main.js +15 -0
  42. package/dist/es-ES.main.js.map +1 -0
  43. package/dist/es-ES.mjs +17 -0
  44. package/dist/es-ES.module.js +17 -0
  45. package/dist/es-ES.module.js.map +1 -0
  46. package/dist/et-EE.main.js +15 -0
  47. package/dist/et-EE.main.js.map +1 -0
  48. package/dist/et-EE.mjs +17 -0
  49. package/dist/et-EE.module.js +17 -0
  50. package/dist/et-EE.module.js.map +1 -0
  51. package/dist/fi-FI.main.js +15 -0
  52. package/dist/fi-FI.main.js.map +1 -0
  53. package/dist/fi-FI.mjs +17 -0
  54. package/dist/fi-FI.module.js +17 -0
  55. package/dist/fi-FI.module.js.map +1 -0
  56. package/dist/fr-FR.main.js +15 -0
  57. package/dist/fr-FR.main.js.map +1 -0
  58. package/dist/fr-FR.mjs +17 -0
  59. package/dist/fr-FR.module.js +17 -0
  60. package/dist/fr-FR.module.js.map +1 -0
  61. package/dist/he-IL.main.js +15 -0
  62. package/dist/he-IL.main.js.map +1 -0
  63. package/dist/he-IL.mjs +17 -0
  64. package/dist/he-IL.module.js +17 -0
  65. package/dist/he-IL.module.js.map +1 -0
  66. package/dist/hr-HR.main.js +15 -0
  67. package/dist/hr-HR.main.js.map +1 -0
  68. package/dist/hr-HR.mjs +17 -0
  69. package/dist/hr-HR.module.js +17 -0
  70. package/dist/hr-HR.module.js.map +1 -0
  71. package/dist/hu-HU.main.js +15 -0
  72. package/dist/hu-HU.main.js.map +1 -0
  73. package/dist/hu-HU.mjs +17 -0
  74. package/dist/hu-HU.module.js +17 -0
  75. package/dist/hu-HU.module.js.map +1 -0
  76. package/dist/import.mjs +31 -0
  77. package/dist/intlStrings.main.js +108 -0
  78. package/dist/intlStrings.main.js.map +1 -0
  79. package/dist/intlStrings.mjs +110 -0
  80. package/dist/intlStrings.module.js +110 -0
  81. package/dist/intlStrings.module.js.map +1 -0
  82. package/dist/it-IT.main.js +15 -0
  83. package/dist/it-IT.main.js.map +1 -0
  84. package/dist/it-IT.mjs +17 -0
  85. package/dist/it-IT.module.js +17 -0
  86. package/dist/it-IT.module.js.map +1 -0
  87. package/dist/ja-JP.main.js +15 -0
  88. package/dist/ja-JP.main.js.map +1 -0
  89. package/dist/ja-JP.mjs +17 -0
  90. package/dist/ja-JP.module.js +17 -0
  91. package/dist/ja-JP.module.js.map +1 -0
  92. package/dist/ko-KR.main.js +15 -0
  93. package/dist/ko-KR.main.js.map +1 -0
  94. package/dist/ko-KR.mjs +17 -0
  95. package/dist/ko-KR.module.js +17 -0
  96. package/dist/ko-KR.module.js.map +1 -0
  97. package/dist/lt-LT.main.js +15 -0
  98. package/dist/lt-LT.main.js.map +1 -0
  99. package/dist/lt-LT.mjs +17 -0
  100. package/dist/lt-LT.module.js +17 -0
  101. package/dist/lt-LT.module.js.map +1 -0
  102. package/dist/lv-LV.main.js +15 -0
  103. package/dist/lv-LV.main.js.map +1 -0
  104. package/dist/lv-LV.mjs +17 -0
  105. package/dist/lv-LV.module.js +17 -0
  106. package/dist/lv-LV.module.js.map +1 -0
  107. package/dist/main.js +23 -825
  108. package/dist/main.js.map +1 -1
  109. package/dist/module.js +10 -775
  110. package/dist/module.js.map +1 -1
  111. package/dist/nb-NO.main.js +15 -0
  112. package/dist/nb-NO.main.js.map +1 -0
  113. package/dist/nb-NO.mjs +17 -0
  114. package/dist/nb-NO.module.js +17 -0
  115. package/dist/nb-NO.module.js.map +1 -0
  116. package/dist/nl-NL.main.js +15 -0
  117. package/dist/nl-NL.main.js.map +1 -0
  118. package/dist/nl-NL.mjs +17 -0
  119. package/dist/nl-NL.module.js +17 -0
  120. package/dist/nl-NL.module.js.map +1 -0
  121. package/dist/pl-PL.main.js +15 -0
  122. package/dist/pl-PL.main.js.map +1 -0
  123. package/dist/pl-PL.mjs +17 -0
  124. package/dist/pl-PL.module.js +17 -0
  125. package/dist/pl-PL.module.js.map +1 -0
  126. package/dist/pt-BR.main.js +15 -0
  127. package/dist/pt-BR.main.js.map +1 -0
  128. package/dist/pt-BR.mjs +17 -0
  129. package/dist/pt-BR.module.js +17 -0
  130. package/dist/pt-BR.module.js.map +1 -0
  131. package/dist/pt-PT.main.js +15 -0
  132. package/dist/pt-PT.main.js.map +1 -0
  133. package/dist/pt-PT.mjs +17 -0
  134. package/dist/pt-PT.module.js +17 -0
  135. package/dist/pt-PT.module.js.map +1 -0
  136. package/dist/ro-RO.main.js +15 -0
  137. package/dist/ro-RO.main.js.map +1 -0
  138. package/dist/ro-RO.mjs +17 -0
  139. package/dist/ro-RO.module.js +17 -0
  140. package/dist/ro-RO.module.js.map +1 -0
  141. package/dist/ru-RU.main.js +15 -0
  142. package/dist/ru-RU.main.js.map +1 -0
  143. package/dist/ru-RU.mjs +17 -0
  144. package/dist/ru-RU.module.js +17 -0
  145. package/dist/ru-RU.module.js.map +1 -0
  146. package/dist/sk-SK.main.js +15 -0
  147. package/dist/sk-SK.main.js.map +1 -0
  148. package/dist/sk-SK.mjs +17 -0
  149. package/dist/sk-SK.module.js +17 -0
  150. package/dist/sk-SK.module.js.map +1 -0
  151. package/dist/sl-SI.main.js +15 -0
  152. package/dist/sl-SI.main.js.map +1 -0
  153. package/dist/sl-SI.mjs +17 -0
  154. package/dist/sl-SI.module.js +17 -0
  155. package/dist/sl-SI.module.js.map +1 -0
  156. package/dist/sr-SP.main.js +15 -0
  157. package/dist/sr-SP.main.js.map +1 -0
  158. package/dist/sr-SP.mjs +17 -0
  159. package/dist/sr-SP.module.js +17 -0
  160. package/dist/sr-SP.module.js.map +1 -0
  161. package/dist/sv-SE.main.js +15 -0
  162. package/dist/sv-SE.main.js.map +1 -0
  163. package/dist/sv-SE.mjs +17 -0
  164. package/dist/sv-SE.module.js +17 -0
  165. package/dist/sv-SE.module.js.map +1 -0
  166. package/dist/tr-TR.main.js +15 -0
  167. package/dist/tr-TR.main.js.map +1 -0
  168. package/dist/tr-TR.mjs +17 -0
  169. package/dist/tr-TR.module.js +17 -0
  170. package/dist/tr-TR.module.js.map +1 -0
  171. package/dist/types.d.ts +115 -48
  172. package/dist/types.d.ts.map +1 -1
  173. package/dist/uk-UA.main.js +15 -0
  174. package/dist/uk-UA.main.js.map +1 -0
  175. package/dist/uk-UA.mjs +17 -0
  176. package/dist/uk-UA.module.js +17 -0
  177. package/dist/uk-UA.module.js.map +1 -0
  178. package/dist/useGrid.main.js +132 -0
  179. package/dist/useGrid.main.js.map +1 -0
  180. package/dist/useGrid.mjs +127 -0
  181. package/dist/useGrid.module.js +127 -0
  182. package/dist/useGrid.module.js.map +1 -0
  183. package/dist/useGridCell.main.js +220 -0
  184. package/dist/useGridCell.main.js.map +1 -0
  185. package/dist/useGridCell.mjs +215 -0
  186. package/dist/useGridCell.module.js +215 -0
  187. package/dist/useGridCell.module.js.map +1 -0
  188. package/dist/useGridRow.main.js +53 -0
  189. package/dist/useGridRow.main.js.map +1 -0
  190. package/dist/useGridRow.mjs +48 -0
  191. package/dist/useGridRow.module.js +48 -0
  192. package/dist/useGridRow.module.js.map +1 -0
  193. package/dist/useGridRowGroup.main.js +26 -0
  194. package/dist/useGridRowGroup.main.js.map +1 -0
  195. package/dist/useGridRowGroup.mjs +21 -0
  196. package/dist/useGridRowGroup.module.js +21 -0
  197. package/dist/useGridRowGroup.module.js.map +1 -0
  198. package/dist/useGridSelectionAnnouncement.main.js +94 -0
  199. package/dist/useGridSelectionAnnouncement.main.js.map +1 -0
  200. package/dist/useGridSelectionAnnouncement.mjs +89 -0
  201. package/dist/useGridSelectionAnnouncement.module.js +89 -0
  202. package/dist/useGridSelectionAnnouncement.module.js.map +1 -0
  203. package/dist/useGridSelectionCheckbox.main.js +39 -0
  204. package/dist/useGridSelectionCheckbox.main.js.map +1 -0
  205. package/dist/useGridSelectionCheckbox.mjs +34 -0
  206. package/dist/useGridSelectionCheckbox.module.js +34 -0
  207. package/dist/useGridSelectionCheckbox.module.js.map +1 -0
  208. package/dist/useHighlightSelectionDescription.main.js +55 -0
  209. package/dist/useHighlightSelectionDescription.main.js.map +1 -0
  210. package/dist/useHighlightSelectionDescription.mjs +50 -0
  211. package/dist/useHighlightSelectionDescription.module.js +50 -0
  212. package/dist/useHighlightSelectionDescription.module.js.map +1 -0
  213. package/dist/utils.main.js +20 -0
  214. package/dist/utils.main.js.map +1 -0
  215. package/dist/utils.mjs +15 -0
  216. package/dist/utils.module.js +15 -0
  217. package/dist/utils.module.js.map +1 -0
  218. package/dist/zh-CN.main.js +15 -0
  219. package/dist/zh-CN.main.js.map +1 -0
  220. package/dist/zh-CN.mjs +17 -0
  221. package/dist/zh-CN.module.js +17 -0
  222. package/dist/zh-CN.module.js.map +1 -0
  223. package/dist/zh-TW.main.js +15 -0
  224. package/dist/zh-TW.main.js.map +1 -0
  225. package/dist/zh-TW.mjs +17 -0
  226. package/dist/zh-TW.module.js +17 -0
  227. package/dist/zh-TW.module.js.map +1 -0
  228. package/package.json +23 -15
  229. package/src/GridKeyboardDelegate.ts +93 -83
  230. package/src/index.ts +17 -5
  231. package/src/useGrid.ts +78 -81
  232. package/src/useGridCell.ts +96 -51
  233. package/src/useGridRow.ts +33 -28
  234. package/src/useGridRowGroup.ts +3 -3
  235. package/src/useGridSelectionAnnouncement.ts +115 -0
  236. package/src/useGridSelectionCheckbox.ts +48 -0
  237. package/src/useHighlightSelectionDescription.ts +52 -0
  238. package/src/utils.ts +13 -3
  239. package/LICENSE +0 -201
package/dist/main.js CHANGED
@@ -1,418 +1,25 @@
1
- var {
2
- focusSafely,
3
- getFocusableTreeWalker
4
- } = require("@react-aria/focus");
5
-
6
- var {
7
- usePress,
8
- isFocusVisible
9
- } = require("@react-aria/interactions");
10
-
11
- var {
12
- useSelectableCollection,
13
- useSelectableItem
14
- } = require("@react-aria/selection");
15
-
16
- var {
17
- useCollator,
18
- useLocale,
19
- useMessageFormatter
20
- } = require("@react-aria/i18n");
21
-
22
- var {
23
- useMemo,
24
- useRef
25
- } = require("react");
26
-
27
- var {
28
- filterDOMProps,
29
- mergeProps,
30
- useId,
31
- useUpdateEffect
32
- } = require("@react-aria/utils");
33
-
34
- var {
35
- announce
36
- } = require("@react-aria/live-announcer");
37
-
38
- var _babelRuntimeHelpersInteropRequireDefault = $parcel$interopDefault(require("@babel/runtime/helpers/interopRequireDefault"));
39
-
40
- var _babelRuntimeHelpersExtends = $parcel$interopDefault(require("@babel/runtime/helpers/extends"));
41
-
42
- var {
43
- Rect
44
- } = require("@react-stately/virtualizer");
45
-
46
- function $parcel$interopDefault(a) {
47
- return a && a.__esModule ? a.default : a;
48
- }
49
-
50
- class GridKeyboardDelegate {
51
- constructor(options) {
52
- this.collection = void 0;
53
- this.disabledKeys = void 0;
54
- this.ref = void 0;
55
- this.direction = void 0;
56
- this.collator = void 0;
57
- this.layout = void 0;
58
- this.focusMode = void 0;
59
- this.collection = options.collection;
60
- this.disabledKeys = options.disabledKeys;
61
- this.ref = options.ref;
62
- this.direction = options.direction;
63
- this.collator = options.collator;
64
- this.layout = options.layout;
65
- this.focusMode = options.focusMode || 'row';
66
- }
67
-
68
- isCell(node) {
69
- return node.type === 'cell';
70
- }
71
-
72
- isRow(node) {
73
- return node.type === 'row' || node.type === 'item';
74
- }
75
-
76
- findPreviousKey(fromKey, pred) {
77
- let key = fromKey != null ? this.collection.getKeyBefore(fromKey) : this.collection.getLastKey();
78
-
79
- while (key != null) {
80
- let item = this.collection.getItem(key);
81
-
82
- if (!pred || pred(item)) {
83
- return key;
84
- }
85
-
86
- key = this.collection.getKeyBefore(key);
87
- }
88
- }
89
-
90
- findNextKey(fromKey, pred) {
91
- let key = fromKey != null ? this.collection.getKeyAfter(fromKey) : this.collection.getFirstKey();
92
-
93
- while (key != null) {
94
- let item = this.collection.getItem(key);
95
-
96
- if (!pred || pred(item)) {
97
- return key;
98
- }
99
-
100
- key = this.collection.getKeyAfter(key);
101
- }
102
- }
103
-
104
- getKeyBelow(key) {
105
- let startItem = this.collection.getItem(key);
106
-
107
- if (!startItem) {
108
- return;
109
- } // If focus was on a cell, start searching from the parent row
110
-
111
-
112
- if (this.isCell(startItem)) {
113
- key = startItem.parentKey;
114
- } // Find the next item
115
-
116
-
117
- key = this.findNextKey(key);
118
-
119
- if (key != null) {
120
- // If focus was on a cell, focus the cell with the same index in the next row.
121
- if (this.isCell(startItem)) {
122
- let item = this.collection.getItem(key);
123
- return [...item.childNodes][startItem.index].key;
124
- } // Otherwise, focus the next row
125
-
126
-
127
- if (this.focusMode === 'row') {
128
- return key;
129
- }
130
- }
131
- }
132
-
133
- getKeyAbove(key) {
134
- let startItem = this.collection.getItem(key);
135
-
136
- if (!startItem) {
137
- return;
138
- } // If focus is on a cell, start searching from the parent row
139
-
140
-
141
- if (this.isCell(startItem)) {
142
- key = startItem.parentKey;
143
- } // Find the previous item
144
-
145
-
146
- key = this.findPreviousKey(key);
147
-
148
- if (key != null) {
149
- // If focus was on a cell, focus the cell with the same index in the previous row.
150
- if (this.isCell(startItem)) {
151
- let item = this.collection.getItem(key);
152
- return [...item.childNodes][startItem.index].key;
153
- } // Otherwise, focus the previous row
154
-
155
-
156
- if (this.focusMode === 'row') {
157
- return key;
158
- }
159
- }
160
- }
161
-
162
- getKeyRightOf(key) {
163
- let item = this.collection.getItem(key);
164
-
165
- if (!item) {
166
- return;
167
- } // If focus is on a row, focus the first child cell.
168
-
169
-
170
- if (this.isRow(item)) {
171
- let children = [...item.childNodes];
172
- return this.direction === 'rtl' ? children[children.length - 1].key : children[0].key;
173
- } // If focus is on a cell, focus the next cell if any,
174
- // otherwise focus the parent row.
175
-
176
-
177
- if (this.isCell(item)) {
178
- let parent = this.collection.getItem(item.parentKey);
179
- let children = [...parent.childNodes];
180
- let next = this.direction === 'rtl' ? children[item.index - 1] : children[item.index + 1];
181
-
182
- if (next) {
183
- return next.key;
184
- } // focus row only if focusMode is set to row
185
-
186
-
187
- if (this.focusMode === 'row') {
188
- return item.parentKey;
189
- }
190
-
191
- return this.direction === 'rtl' ? this.getFirstKey(key) : this.getLastKey(key);
192
- }
193
- }
194
-
195
- getKeyLeftOf(key) {
196
- let item = this.collection.getItem(key);
197
-
198
- if (!item) {
199
- return;
200
- } // If focus is on a row, focus the last child cell.
201
-
202
-
203
- if (this.isRow(item)) {
204
- let children = [...item.childNodes];
205
- return this.direction === 'rtl' ? children[0].key : children[children.length - 1].key;
206
- } // If focus is on a cell, focus the previous cell if any,
207
- // otherwise focus the parent row.
208
-
209
-
210
- if (this.isCell(item)) {
211
- let parent = this.collection.getItem(item.parentKey);
212
- let children = [...parent.childNodes];
213
- let prev = this.direction === 'rtl' ? children[item.index + 1] : children[item.index - 1];
214
-
215
- if (prev) {
216
- return prev.key;
217
- } // focus row only if focusMode is set to row
218
-
219
-
220
- if (this.focusMode === 'row') {
221
- return item.parentKey;
222
- }
223
-
224
- return this.direction === 'rtl' ? this.getLastKey(key) : this.getFirstKey(key);
225
- }
226
- }
227
-
228
- getFirstKey(key, global) {
229
- let item;
230
-
231
- if (key != null) {
232
- item = this.collection.getItem(key);
233
-
234
- if (!item) {
235
- return;
236
- } // If global flag is not set, and a cell is currently focused,
237
- // move focus to the first cell in the parent row.
238
-
239
-
240
- if (this.isCell(item) && !global) {
241
- let parent = this.collection.getItem(item.parentKey);
242
- return [...parent.childNodes][0].key;
243
- }
244
- } // Find the first row
245
-
246
-
247
- key = this.findNextKey(); // If global flag is set (or if focus mode is cell), focus the first cell in the first row.
248
-
249
- if (key != null && item && this.isCell(item) && global || this.focusMode === 'cell') {
250
- let item = this.collection.getItem(key);
251
- key = [...item.childNodes][0].key;
252
- } // Otherwise, focus the row itself.
253
-
254
-
255
- return key;
256
- }
257
-
258
- getLastKey(key, global) {
259
- let item;
260
-
261
- if (key != null) {
262
- item = this.collection.getItem(key);
263
-
264
- if (!item) {
265
- return;
266
- } // If global flag is not set, and a cell is currently focused,
267
- // move focus to the last cell in the parent row.
268
-
269
-
270
- if (this.isCell(item) && !global) {
271
- let parent = this.collection.getItem(item.parentKey);
272
- let children = [...parent.childNodes];
273
- return children[children.length - 1].key;
274
- }
275
- } // Find the last row
276
-
277
-
278
- key = this.findPreviousKey(); // If global flag is set (or if focus mode is cell), focus the last cell in the last row.
279
-
280
- if (key != null && item && this.isCell(item) && global || this.focusMode === 'cell') {
281
- let item = this.collection.getItem(key);
282
- let children = [...item.childNodes];
283
- key = children[children.length - 1].key;
284
- } // Otherwise, focus the row itself.
285
-
286
-
287
- return key;
288
- }
289
-
290
- getItem(key) {
291
- return this.ref.current.querySelector("[data-key=\"" + key + "\"]");
292
- }
293
-
294
- getItemRect(key) {
295
- if (this.layout) {
296
- var _this$layout$getLayou;
297
-
298
- return (_this$layout$getLayou = this.layout.getLayoutInfo(key)) == null ? void 0 : _this$layout$getLayou.rect;
299
- }
300
-
301
- let item = this.getItem(key);
302
-
303
- if (item) {
304
- return new Rect(item.offsetLeft, item.offsetTop, item.offsetWidth, item.offsetHeight);
305
- }
306
- }
307
-
308
- getPageHeight() {
309
- var _this$ref, _this$ref$current;
310
-
311
- if (this.layout) {
312
- var _this$layout$virtuali;
313
-
314
- return (_this$layout$virtuali = this.layout.virtualizer) == null ? void 0 : _this$layout$virtuali.visibleRect.height;
315
- }
316
-
317
- return (_this$ref = this.ref) == null ? void 0 : (_this$ref$current = _this$ref.current) == null ? void 0 : _this$ref$current.offsetHeight;
318
- }
319
-
320
- getContentHeight() {
321
- var _this$ref2, _this$ref2$current;
322
-
323
- if (this.layout) {
324
- return this.layout.getContentSize().height;
325
- }
326
-
327
- return (_this$ref2 = this.ref) == null ? void 0 : (_this$ref2$current = _this$ref2.current) == null ? void 0 : _this$ref2$current.scrollHeight;
328
- }
329
-
330
- getKeyPageAbove(key) {
331
- let itemRect = this.getItemRect(key);
332
-
333
- if (!itemRect) {
334
- return null;
335
- }
336
-
337
- let pageY = Math.max(0, itemRect.maxY - this.getPageHeight());
338
-
339
- while (itemRect && itemRect.y > pageY) {
340
- key = this.getKeyAbove(key);
341
- itemRect = this.getItemRect(key);
342
- }
343
-
344
- return key;
345
- }
346
-
347
- getKeyPageBelow(key) {
348
- let itemRect = this.getItemRect(key);
349
-
350
- if (!itemRect) {
351
- return null;
352
- }
353
-
354
- let pageHeight = this.getPageHeight();
355
- let pageY = Math.min(this.getContentHeight(), itemRect.y + pageHeight);
356
-
357
- while (itemRect && itemRect.maxY < pageY) {
358
- let nextKey = this.getKeyBelow(key);
359
- itemRect = this.getItemRect(nextKey); // Guard against case where maxY of the last key is barely less than pageY due to rounding
360
- // and thus it attempts to set key to null
361
-
362
- if (nextKey != null) {
363
- key = nextKey;
364
- }
365
- }
366
-
367
- return key;
368
- }
369
-
370
- getKeyForSearch(search, fromKey) {
371
- if (!this.collator) {
372
- return null;
373
- }
374
-
375
- let collection = this.collection;
376
- let key = fromKey != null ? fromKey : this.getFirstKey(); // If the starting key is a cell, search from its parent row.
377
-
378
- let startItem = collection.getItem(key);
379
-
380
- if (startItem.type === 'cell') {
381
- key = startItem.parentKey;
382
- }
383
-
384
- let hasWrapped = false;
385
-
386
- while (key != null) {
387
- let item = collection.getItem(key); // check row text value for match
388
-
389
- if (item.textValue) {
390
- let substring = item.textValue.slice(0, search.length);
391
-
392
- if (this.collator.compare(substring, search) === 0) {
393
- if (this.isRow(item) && this.focusMode === 'cell') {
394
- return [...item.childNodes][0].key;
395
- }
396
-
397
- return item.key;
398
- }
399
- }
400
-
401
- key = this.findNextKey(key); // Wrap around when reaching the end of the collection
402
-
403
- if (key == null && !hasWrapped) {
404
- key = this.getFirstKey();
405
- hasWrapped = true;
406
- }
407
- }
408
-
409
- return null;
410
- }
411
-
412
- }
413
-
414
- exports.GridKeyboardDelegate = GridKeyboardDelegate;
415
-
1
+ var $3187c0e19200cb16$exports = require("./GridKeyboardDelegate.main.js");
2
+ var $11d770dfabe45077$exports = require("./useGrid.main.js");
3
+ var $c7def85a57100898$exports = require("./useGridRowGroup.main.js");
4
+ var $eed398987c639831$exports = require("./useGridRow.main.js");
5
+ var $cf2021be63b01ef4$exports = require("./useGridCell.main.js");
6
+ var $d8385f73d3701365$exports = require("./useGridSelectionCheckbox.main.js");
7
+ var $340f2fcd0ef9ce8d$exports = require("./useHighlightSelectionDescription.main.js");
8
+ var $1eb174acfe8a0f16$exports = require("./useGridSelectionAnnouncement.main.js");
9
+
10
+
11
+ function $parcel$export(e, n, v, s) {
12
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
13
+ }
14
+
15
+ $parcel$export(module.exports, "GridKeyboardDelegate", () => $3187c0e19200cb16$exports.GridKeyboardDelegate);
16
+ $parcel$export(module.exports, "useGrid", () => $11d770dfabe45077$exports.useGrid);
17
+ $parcel$export(module.exports, "useGridRowGroup", () => $c7def85a57100898$exports.useGridRowGroup);
18
+ $parcel$export(module.exports, "useGridRow", () => $eed398987c639831$exports.useGridRow);
19
+ $parcel$export(module.exports, "useGridCell", () => $cf2021be63b01ef4$exports.useGridCell);
20
+ $parcel$export(module.exports, "useGridSelectionCheckbox", () => $d8385f73d3701365$exports.useGridSelectionCheckbox);
21
+ $parcel$export(module.exports, "useHighlightSelectionDescription", () => $340f2fcd0ef9ce8d$exports.useHighlightSelectionDescription);
22
+ $parcel$export(module.exports, "useGridSelectionAnnouncement", () => $1eb174acfe8a0f16$exports.useGridSelectionAnnouncement);
416
23
  /*
417
24
  * Copyright 2020 Adobe. All rights reserved.
418
25
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
@@ -423,423 +30,14 @@ exports.GridKeyboardDelegate = GridKeyboardDelegate;
423
30
  * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
424
31
  * OF ANY KIND, either express or implied. See the License for the specific language
425
32
  * governing permissions and limitations under the License.
426
- */
427
- // Used to share keyboard delegate between useGrid and useGridCell
428
- const $e6fd609a4e1bd40f6df88a69c08b6746$export$gridKeyboardDelegates = new WeakMap();
429
- // ASSET: /Users/govett/dev/react-spectrum-v3/packages/@react-aria/grid/intl/en-US.json
430
- var $d13b1ea919d49253cf46bbc8c5ad0e4f$exports = {};
431
- $d13b1ea919d49253cf46bbc8c5ad0e4f$exports = JSON.parse("{\"selectedCount\":\"{count, plural, =0 {No items selected} one {# item selected} other {# items selected}}.\",\"selectedAll\":\"All items selected.\",\"selectedItem\":\"{item} selected.\",\"deselectedItem\":\"{item} not selected.\"}");
432
- // @ts-ignore
433
- const $df311f3c863e8abccff59a8ae65a46d3$var$intlMessages = {
434
- "en-US": _babelRuntimeHelpersInteropRequireDefault($d13b1ea919d49253cf46bbc8c5ad0e4f$exports).default
435
- };
436
-
437
- /**
438
- * Provides the behavior and accessibility implementation for a grid component.
439
- * A grid displays data in one or more rows and columns and enables a user to navigate its contents via directional navigation keys.
440
- * @param props - Props for the grid.
441
- * @param state - State for the grid, as returned by `useGridState`.
442
- */
443
- function useGrid(props, state) {
444
- let {
445
- ref,
446
- isVirtualized,
447
- keyboardDelegate,
448
- focusMode,
449
- getRowText = key => {
450
- var _state$collection$get;
451
-
452
- return (_state$collection$get = state.collection.getItem(key)) == null ? void 0 : _state$collection$get.textValue;
453
- }
454
- } = props;
455
- let formatMessage = useMessageFormatter($df311f3c863e8abccff59a8ae65a46d3$var$intlMessages);
456
-
457
- if (!props['aria-label'] && !props['aria-labelledby']) {
458
- console.warn('An aria-label or aria-labelledby prop is required for accessibility.');
459
- } // By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).
460
- // When virtualized, the layout object will be passed in as a prop and override this.
461
-
462
-
463
- let collator = useCollator({
464
- usage: 'search',
465
- sensitivity: 'base'
466
- });
467
- let {
468
- direction
469
- } = useLocale();
470
- let delegate = useMemo(() => keyboardDelegate || new GridKeyboardDelegate({
471
- collection: state.collection,
472
- disabledKeys: state.disabledKeys,
473
- ref,
474
- direction,
475
- collator,
476
- focusMode
477
- }), [keyboardDelegate, state.collection, state.disabledKeys, ref, direction, collator, focusMode]);
478
- let {
479
- collectionProps
480
- } = useSelectableCollection({
481
- ref,
482
- selectionManager: state.selectionManager,
483
- keyboardDelegate: delegate
484
- });
485
- let id = useId();
486
- $e6fd609a4e1bd40f6df88a69c08b6746$export$gridKeyboardDelegates.set(state, delegate);
487
- let domProps = filterDOMProps(props, {
488
- labelable: true
489
- });
490
- let gridProps = mergeProps(domProps, _babelRuntimeHelpersExtends({
491
- role: 'grid',
492
- id,
493
- 'aria-multiselectable': state.selectionManager.selectionMode === 'multiple' ? 'true' : undefined
494
- }, collectionProps));
495
-
496
- if (isVirtualized) {
497
- gridProps['aria-rowcount'] = state.collection.size;
498
- gridProps['aria-colcount'] = state.collection.columnCount;
499
- } // Many screen readers do not announce when items in a grid are selected/deselected.
500
- // We do this using an ARIA live region.
501
-
502
-
503
- let selection = state.selectionManager.rawSelection;
504
- let lastSelection = useRef(selection);
505
- useUpdateEffect(() => {
506
- if (!state.selectionManager.isFocused) {
507
- return;
508
- }
509
-
510
- let addedKeys = $df311f3c863e8abccff59a8ae65a46d3$var$diffSelection(selection, lastSelection.current);
511
- let removedKeys = $df311f3c863e8abccff59a8ae65a46d3$var$diffSelection(lastSelection.current, selection); // If adding or removing a single row from the selection, announce the name of that item.
512
-
513
- let messages = [];
33
+ */
514
34
 
515
- if (addedKeys.size === 1 && removedKeys.size === 0) {
516
- let addedText = getRowText(addedKeys.keys().next().value);
517
35
 
518
- if (addedText) {
519
- messages.push(formatMessage('selectedItem', {
520
- item: addedText
521
- }));
522
- }
523
- } else if (removedKeys.size === 1 && addedKeys.size === 0) {
524
- let removedText = getRowText(removedKeys.keys().next().value);
525
36
 
526
- if (removedText) {
527
- messages.push(formatMessage('deselectedItem', {
528
- item: removedText
529
- }));
530
- }
531
- } // Announce how many items are selected, except when selecting the first item.
532
37
 
533
38
 
534
- if (state.selectionManager.selectionMode === 'multiple') {
535
- if (messages.length === 0 || selection === 'all' || selection.size > 1 || lastSelection.current === 'all' || lastSelection.current.size > 1) {
536
- messages.push(selection === 'all' ? formatMessage('selectedAll') : formatMessage('selectedCount', {
537
- count: selection.size
538
- }));
539
- }
540
- }
541
-
542
- if (messages.length > 0) {
543
- announce(messages.join(' '));
544
- }
545
-
546
- lastSelection.current = selection;
547
- }, [selection]);
548
- return {
549
- gridProps
550
- };
551
- }
552
-
553
- exports.useGrid = useGrid;
554
-
555
- function $df311f3c863e8abccff59a8ae65a46d3$var$diffSelection(a, b) {
556
- let res = new Set();
557
-
558
- if (a === 'all' || b === 'all') {
559
- return res;
560
- }
561
-
562
- for (let key of a.keys()) {
563
- if (!b.has(key)) {
564
- res.add(key);
565
- }
566
- }
567
-
568
- return res;
569
- }
570
-
571
- /**
572
- * Provides the accessibility implementation for a row group in a grid.
573
- */
574
- function useGridRowGroup() {
575
- return {
576
- rowGroupProps: {
577
- role: 'rowgroup'
578
- }
579
- };
580
- }
581
39
 
582
- exports.useGridRowGroup = useGridRowGroup;
583
40
 
584
- /**
585
- * Provides the behavior and accessibility implementation for a row in a grid.
586
- * @param props - Props for the row.
587
- * @param state - State of the parent grid, as returned by `useGridState`.
588
- */
589
- function useGridRow(props, state) {
590
- let {
591
- node,
592
- ref,
593
- isVirtualized,
594
- isSelected,
595
- isDisabled,
596
- shouldSelectOnPressUp
597
- } = props;
598
- let {
599
- itemProps
600
- } = useSelectableItem({
601
- selectionManager: state.selectionManager,
602
- key: node.key,
603
- ref,
604
- isVirtualized,
605
- shouldSelectOnPressUp
606
- }); // TODO: move into useSelectableItem?
607
41
 
608
- let {
609
- pressProps
610
- } = usePress(_babelRuntimeHelpersExtends({}, itemProps, {
611
- isDisabled
612
- }));
613
42
 
614
- let rowProps = _babelRuntimeHelpersExtends({
615
- role: 'row',
616
- 'aria-selected': isSelected
617
- }, pressProps);
618
-
619
- if (isVirtualized) {
620
- rowProps['aria-rowindex'] = node.index + 1; // aria-rowindex is 1 based
621
- }
622
-
623
- return {
624
- rowProps
625
- };
626
- }
627
-
628
- exports.useGridRow = useGridRow;
629
-
630
- /**
631
- * Provides the behavior and accessibility implementation for a cell in a grid.
632
- * @param props - Props for the cell.
633
- * @param state - State of the parent grid, as returned by `useGridState`.
634
- */
635
- function useGridCell(props, state) {
636
- let {
637
- node,
638
- ref,
639
- isVirtualized,
640
- isDisabled,
641
- focusMode = 'child',
642
- shouldSelectOnPressUp
643
- } = props;
644
- let {
645
- direction
646
- } = useLocale();
647
- let keyboardDelegate = $e6fd609a4e1bd40f6df88a69c08b6746$export$gridKeyboardDelegates.get(state); // Handles focusing the cell. If there is a focusable child,
648
- // it is focused, otherwise the cell itself is focused.
649
-
650
- let focus = () => {
651
- let treeWalker = getFocusableTreeWalker(ref.current);
652
-
653
- if (focusMode === 'child') {
654
- let focusable = state.selectionManager.childFocusStrategy === 'last' ? $f9bcfab6f4b3fd6f2359f40ca9cd9cf4$var$last(treeWalker) : treeWalker.firstChild();
655
-
656
- if (focusable) {
657
- focusSafely(focusable);
658
- return;
659
- }
660
- }
661
-
662
- if (!ref.current.contains(document.activeElement)) {
663
- focusSafely(ref.current);
664
- }
665
- };
666
-
667
- let {
668
- itemProps
669
- } = useSelectableItem({
670
- selectionManager: state.selectionManager,
671
- key: node.key,
672
- ref,
673
- isVirtualized,
674
- focus,
675
- shouldSelectOnPressUp
676
- }); // TODO: move into useSelectableItem?
677
-
678
- let {
679
- pressProps
680
- } = usePress(_babelRuntimeHelpersExtends({}, itemProps, {
681
- isDisabled
682
- }));
683
-
684
- let onKeyDown = e => {
685
- if (!e.currentTarget.contains(e.target)) {
686
- return;
687
- }
688
-
689
- let walker = getFocusableTreeWalker(ref.current);
690
- walker.currentNode = document.activeElement;
691
-
692
- switch (e.key) {
693
- case 'ArrowLeft':
694
- {
695
- // Find the next focusable element within the cell.
696
- let focusable = direction === 'rtl' ? walker.nextNode() : walker.previousNode(); // Don't focus the cell itself if focusMode is "child"
697
-
698
- if (focusMode === 'child' && focusable === ref.current) {
699
- focusable = null;
700
- }
701
-
702
- if (focusable) {
703
- e.preventDefault();
704
- e.stopPropagation();
705
- focusSafely(focusable);
706
- } else {
707
- // If there is no next focusable child, then move to the next cell to the left of this one.
708
- // This will be handled by useSelectableCollection. However, if there is no cell to the left
709
- // of this one, only one column, and the grid doesn't focus rows, then the next key will be the
710
- // same as this one. In that case we need to handle focusing either the cell or the first/last
711
- // child, depending on the focus mode.
712
- let prev = keyboardDelegate.getKeyLeftOf(node.key);
713
-
714
- if (prev !== node.key) {
715
- break;
716
- }
717
-
718
- e.preventDefault();
719
- e.stopPropagation();
720
-
721
- if (focusMode === 'cell' && direction === 'rtl') {
722
- focusSafely(ref.current);
723
- } else {
724
- walker.currentNode = ref.current;
725
- focusable = direction === 'rtl' ? walker.firstChild() : $f9bcfab6f4b3fd6f2359f40ca9cd9cf4$var$last(walker);
726
-
727
- if (focusable) {
728
- focusSafely(focusable);
729
- }
730
- }
731
- }
732
-
733
- break;
734
- }
735
-
736
- case 'ArrowRight':
737
- {
738
- let focusable = direction === 'rtl' ? walker.previousNode() : walker.nextNode();
739
-
740
- if (focusMode === 'child' && focusable === ref.current) {
741
- focusable = null;
742
- }
743
-
744
- if (focusable) {
745
- e.preventDefault();
746
- e.stopPropagation();
747
- focusSafely(focusable);
748
- } else {
749
- let next = keyboardDelegate.getKeyRightOf(node.key);
750
-
751
- if (next !== node.key) {
752
- break;
753
- }
754
-
755
- e.preventDefault();
756
- e.stopPropagation();
757
-
758
- if (focusMode === 'cell' && direction === 'ltr') {
759
- focusSafely(ref.current);
760
- } else {
761
- walker.currentNode = ref.current;
762
- focusable = direction === 'rtl' ? $f9bcfab6f4b3fd6f2359f40ca9cd9cf4$var$last(walker) : walker.firstChild();
763
-
764
- if (focusable) {
765
- focusSafely(focusable);
766
- }
767
- }
768
- }
769
-
770
- break;
771
- }
772
-
773
- case 'ArrowUp':
774
- case 'ArrowDown':
775
- // Prevent this event from reaching cell children, e.g. menu buttons. We want arrow keys to navigate
776
- // to the cell above/below instead. We need to re-dispatch the event from a higher parent so it still
777
- // bubbles and gets handled by useSelectableCollection.
778
- if (!e.altKey && ref.current.contains(e.target)) {
779
- e.stopPropagation();
780
- e.preventDefault();
781
- ref.current.parentElement.dispatchEvent(new KeyboardEvent(e.nativeEvent.type, e.nativeEvent));
782
- }
783
-
784
- break;
785
- }
786
- }; // Grid cells can have focusable elements inside them. In this case, focus should
787
- // be marshalled to that element rather than focusing the cell itself.
788
-
789
-
790
- let onFocus = e => {
791
- if (e.target !== ref.current) {
792
- // useSelectableItem only handles setting the focused key when
793
- // the focused element is the gridcell itself. We also want to
794
- // set the focused key when a child element receives focus.
795
- // If focus is currently visible (e.g. the user is navigating with the keyboard),
796
- // then skip this. We want to restore focus to the previously focused row/cell
797
- // in that case since the table should act like a single tab stop.
798
- if (!isFocusVisible()) {
799
- state.selectionManager.setFocusedKey(node.key);
800
- }
801
-
802
- return;
803
- } // If the cell itself is focused, wait a frame so that focus finishes propagatating
804
- // up to the tree, and move focus to a focusable child if possible.
805
-
806
-
807
- requestAnimationFrame(() => {
808
- if (focusMode === 'child' && document.activeElement === ref.current) {
809
- focus();
810
- }
811
- });
812
- };
813
-
814
- let gridCellProps = mergeProps(pressProps, {
815
- role: 'gridcell',
816
- onKeyDownCapture: onKeyDown,
817
- onFocus
818
- });
819
-
820
- if (isVirtualized) {
821
- gridCellProps['aria-colindex'] = node.index + 1; // aria-colindex is 1-based
822
- }
823
-
824
- return {
825
- gridCellProps
826
- };
827
- }
828
-
829
- exports.useGridCell = useGridCell;
830
-
831
- function $f9bcfab6f4b3fd6f2359f40ca9cd9cf4$var$last(walker) {
832
- let next;
833
- let last;
834
-
835
- do {
836
- last = walker.lastChild();
837
-
838
- if (last) {
839
- next = last;
840
- }
841
- } while (last);
842
-
843
- return next;
844
- }
845
43
  //# sourceMappingURL=main.js.map