@react-aria/selection 3.17.5 → 3.18.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 (42) hide show
  1. package/dist/ListKeyboardDelegate.main.js +200 -0
  2. package/dist/ListKeyboardDelegate.main.js.map +1 -0
  3. package/dist/ListKeyboardDelegate.mjs +195 -0
  4. package/dist/ListKeyboardDelegate.module.js +195 -0
  5. package/dist/ListKeyboardDelegate.module.js.map +1 -0
  6. package/dist/import.mjs +5 -794
  7. package/dist/main.js +10 -799
  8. package/dist/main.js.map +1 -1
  9. package/dist/module.js +5 -794
  10. package/dist/module.js.map +1 -1
  11. package/dist/types.d.ts +2 -1
  12. package/dist/types.d.ts.map +1 -1
  13. package/dist/useSelectableCollection.main.js +304 -0
  14. package/dist/useSelectableCollection.main.js.map +1 -0
  15. package/dist/useSelectableCollection.mjs +299 -0
  16. package/dist/useSelectableCollection.module.js +299 -0
  17. package/dist/useSelectableCollection.module.js.map +1 -0
  18. package/dist/useSelectableItem.main.js +213 -0
  19. package/dist/useSelectableItem.main.js.map +1 -0
  20. package/dist/useSelectableItem.mjs +208 -0
  21. package/dist/useSelectableItem.module.js +208 -0
  22. package/dist/useSelectableItem.module.js.map +1 -0
  23. package/dist/useSelectableList.main.js +61 -0
  24. package/dist/useSelectableList.main.js.map +1 -0
  25. package/dist/useSelectableList.mjs +56 -0
  26. package/dist/useSelectableList.module.js +56 -0
  27. package/dist/useSelectableList.module.js.map +1 -0
  28. package/dist/useTypeSelect.main.js +73 -0
  29. package/dist/useTypeSelect.main.js.map +1 -0
  30. package/dist/useTypeSelect.mjs +68 -0
  31. package/dist/useTypeSelect.module.js +68 -0
  32. package/dist/useTypeSelect.module.js.map +1 -0
  33. package/dist/utils.main.js +32 -0
  34. package/dist/utils.main.js.map +1 -0
  35. package/dist/utils.mjs +26 -0
  36. package/dist/utils.module.js +26 -0
  37. package/dist/utils.module.js.map +1 -0
  38. package/package.json +8 -8
  39. package/src/ListKeyboardDelegate.ts +15 -7
  40. package/src/useSelectableCollection.ts +5 -3
  41. package/src/useSelectableItem.ts +4 -2
  42. package/src/useSelectableList.ts +7 -1
package/dist/main.js CHANGED
@@ -1,45 +1,19 @@
1
- var $glPPV$reactdom = require("react-dom");
2
- var $glPPV$react = require("react");
3
- var $glPPV$reactariafocus = require("@react-aria/focus");
4
- var $glPPV$reactariautils = require("@react-aria/utils");
5
- var $glPPV$reactariainteractions = require("@react-aria/interactions");
6
- var $glPPV$reactariai18n = require("@react-aria/i18n");
1
+ var $b6837c2f80a3c32f$exports = require("./useSelectableCollection.main.js");
2
+ var $433b1145b0781e10$exports = require("./useSelectableItem.main.js");
3
+ var $bd230acee196f50c$exports = require("./useSelectableList.main.js");
4
+ var $836f880b12dcae5c$exports = require("./ListKeyboardDelegate.main.js");
5
+ var $a1189052f36475e8$exports = require("./useTypeSelect.main.js");
7
6
 
8
7
 
9
8
  function $parcel$export(e, n, v, s) {
10
9
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
11
10
  }
12
11
 
13
- $parcel$export(module.exports, "useSelectableCollection", () => $b6837c2f80a3c32f$export$d6daf82dcd84e87c);
14
- $parcel$export(module.exports, "useSelectableItem", () => $433b1145b0781e10$export$ecf600387e221c37);
15
- $parcel$export(module.exports, "useSelectableList", () => $bd230acee196f50c$export$b95089534ab7c1fd);
16
- $parcel$export(module.exports, "ListKeyboardDelegate", () => $836f880b12dcae5c$export$a05409b8bb224a5a);
17
- $parcel$export(module.exports, "useTypeSelect", () => $a1189052f36475e8$export$e32c88dfddc6e1d8);
18
- /*
19
- * Copyright 2020 Adobe. All rights reserved.
20
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
21
- * you may not use this file except in compliance with the License. You may obtain a copy
22
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
23
- *
24
- * Unless required by applicable law or agreed to in writing, software distributed under
25
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
26
- * OF ANY KIND, either express or implied. See the License for the specific language
27
- * governing permissions and limitations under the License.
28
- */ /*
29
- * Copyright 2020 Adobe. All rights reserved.
30
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
31
- * you may not use this file except in compliance with the License. You may obtain a copy
32
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
33
- *
34
- * Unless required by applicable law or agreed to in writing, software distributed under
35
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
36
- * OF ANY KIND, either express or implied. See the License for the specific language
37
- * governing permissions and limitations under the License.
38
- */
39
-
40
-
41
-
42
-
12
+ $parcel$export(module.exports, "useSelectableCollection", () => $b6837c2f80a3c32f$exports.useSelectableCollection);
13
+ $parcel$export(module.exports, "useSelectableItem", () => $433b1145b0781e10$exports.useSelectableItem);
14
+ $parcel$export(module.exports, "useSelectableList", () => $bd230acee196f50c$exports.useSelectableList);
15
+ $parcel$export(module.exports, "ListKeyboardDelegate", () => $836f880b12dcae5c$exports.ListKeyboardDelegate);
16
+ $parcel$export(module.exports, "useTypeSelect", () => $a1189052f36475e8$exports.useTypeSelect);
43
17
  /*
44
18
  * Copyright 2020 Adobe. All rights reserved.
45
19
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
@@ -51,769 +25,6 @@ $parcel$export(module.exports, "useTypeSelect", () => $a1189052f36475e8$export$e
51
25
  * OF ANY KIND, either express or implied. See the License for the specific language
52
26
  * governing permissions and limitations under the License.
53
27
  */
54
- function $ee0bdf4faa47f2a8$export$d3e3bd3e26688c04(e) {
55
- // Ctrl + Arrow Up/Arrow Down has a system wide meaning on macOS, so use Alt instead.
56
- // On Windows and Ubuntu, Alt + Space has a system wide meaning.
57
- return (0, $glPPV$reactariautils.isAppleDevice)() ? e.altKey : e.ctrlKey;
58
- }
59
- function $ee0bdf4faa47f2a8$export$16792effe837dba3(e) {
60
- if ((0, $glPPV$reactariautils.isMac)()) return e.metaKey;
61
- return e.ctrlKey;
62
- }
63
-
64
-
65
-
66
- /*
67
- * Copyright 2020 Adobe. All rights reserved.
68
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
69
- * you may not use this file except in compliance with the License. You may obtain a copy
70
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
71
- *
72
- * Unless required by applicable law or agreed to in writing, software distributed under
73
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
74
- * OF ANY KIND, either express or implied. See the License for the specific language
75
- * governing permissions and limitations under the License.
76
- */
77
- /**
78
- * Controls how long to wait before clearing the typeahead buffer.
79
- */ const $a1189052f36475e8$var$TYPEAHEAD_DEBOUNCE_WAIT_MS = 1000; // 1 second
80
- function $a1189052f36475e8$export$e32c88dfddc6e1d8(options) {
81
- let { keyboardDelegate: keyboardDelegate, selectionManager: selectionManager, onTypeSelect: onTypeSelect } = options;
82
- let state = (0, $glPPV$react.useRef)({
83
- search: "",
84
- timeout: null
85
- }).current;
86
- let onKeyDown = (e)=>{
87
- let character = $a1189052f36475e8$var$getStringForKey(e.key);
88
- if (!character || e.ctrlKey || e.metaKey || !e.currentTarget.contains(e.target)) return;
89
- // Do not propagate the Spacebar event if it's meant to be part of the search.
90
- // When we time out, the search term becomes empty, hence the check on length.
91
- // Trimming is to account for the case of pressing the Spacebar more than once,
92
- // which should cycle through the selection/deselection of the focused item.
93
- if (character === " " && state.search.trim().length > 0) {
94
- e.preventDefault();
95
- if (!("continuePropagation" in e)) e.stopPropagation();
96
- }
97
- state.search += character;
98
- // Use the delegate to find a key to focus.
99
- // Prioritize items after the currently focused item, falling back to searching the whole list.
100
- let key = keyboardDelegate.getKeyForSearch(state.search, selectionManager.focusedKey);
101
- // If no key found, search from the top.
102
- if (key == null) key = keyboardDelegate.getKeyForSearch(state.search);
103
- if (key != null) {
104
- selectionManager.setFocusedKey(key);
105
- if (onTypeSelect) onTypeSelect(key);
106
- }
107
- clearTimeout(state.timeout);
108
- state.timeout = setTimeout(()=>{
109
- state.search = "";
110
- }, $a1189052f36475e8$var$TYPEAHEAD_DEBOUNCE_WAIT_MS);
111
- };
112
- return {
113
- typeSelectProps: {
114
- // Using a capturing listener to catch the keydown event before
115
- // other hooks in order to handle the Spacebar event.
116
- onKeyDownCapture: keyboardDelegate.getKeyForSearch ? onKeyDown : null
117
- }
118
- };
119
- }
120
- function $a1189052f36475e8$var$getStringForKey(key) {
121
- // If the key is of length 1, it is an ASCII value.
122
- // Otherwise, if there are no ASCII characters in the key name,
123
- // it is a Unicode character.
124
- // See https://www.w3.org/TR/uievents-key/
125
- if (key.length === 1 || !/^[A-Z]/i.test(key)) return key;
126
- return "";
127
- }
128
-
129
-
130
- function $b6837c2f80a3c32f$export$d6daf82dcd84e87c(options) {
131
- let { selectionManager: manager, keyboardDelegate: delegate, ref: ref, autoFocus: autoFocus = false, shouldFocusWrap: shouldFocusWrap = false, disallowEmptySelection: disallowEmptySelection = false, disallowSelectAll: disallowSelectAll = false, selectOnFocus: selectOnFocus = manager.selectionBehavior === "replace", disallowTypeAhead: disallowTypeAhead = false, shouldUseVirtualFocus: shouldUseVirtualFocus, allowsTabNavigation: allowsTabNavigation = false, isVirtualized: isVirtualized, scrollRef: // If no scrollRef is provided, assume the collection ref is the scrollable region
132
- scrollRef = ref, linkBehavior: linkBehavior = "action" } = options;
133
- let { direction: direction } = (0, $glPPV$reactariai18n.useLocale)();
134
- let router = (0, $glPPV$reactariautils.useRouter)();
135
- let onKeyDown = (e)=>{
136
- // Prevent option + tab from doing anything since it doesn't move focus to the cells, only buttons/checkboxes
137
- if (e.altKey && e.key === "Tab") e.preventDefault();
138
- // Keyboard events bubble through portals. Don't handle keyboard events
139
- // for elements outside the collection (e.g. menus).
140
- if (!ref.current.contains(e.target)) return;
141
- const navigateToKey = (key, childFocus)=>{
142
- if (key != null) {
143
- if (manager.isLink(key) && linkBehavior === "selection" && selectOnFocus && !(0, $ee0bdf4faa47f2a8$export$d3e3bd3e26688c04)(e)) {
144
- // Set focused key and re-render synchronously to bring item into view if needed.
145
- (0, $glPPV$reactdom.flushSync)(()=>{
146
- manager.setFocusedKey(key, childFocus);
147
- });
148
- let item = scrollRef.current.querySelector(`[data-key="${CSS.escape(key.toString())}"]`);
149
- router.open(item, e);
150
- return;
151
- }
152
- manager.setFocusedKey(key, childFocus);
153
- if (manager.isLink(key) && linkBehavior === "override") return;
154
- if (e.shiftKey && manager.selectionMode === "multiple") manager.extendSelection(key);
155
- else if (selectOnFocus && !(0, $ee0bdf4faa47f2a8$export$d3e3bd3e26688c04)(e)) manager.replaceSelection(key);
156
- }
157
- };
158
- switch(e.key){
159
- case "ArrowDown":
160
- if (delegate.getKeyBelow) {
161
- var _delegate_getFirstKey, _delegate_getFirstKey1;
162
- e.preventDefault();
163
- let nextKey = manager.focusedKey != null ? delegate.getKeyBelow(manager.focusedKey) : (_delegate_getFirstKey = delegate.getFirstKey) === null || _delegate_getFirstKey === void 0 ? void 0 : _delegate_getFirstKey.call(delegate);
164
- if (nextKey == null && shouldFocusWrap) nextKey = (_delegate_getFirstKey1 = delegate.getFirstKey) === null || _delegate_getFirstKey1 === void 0 ? void 0 : _delegate_getFirstKey1.call(delegate, manager.focusedKey);
165
- navigateToKey(nextKey);
166
- }
167
- break;
168
- case "ArrowUp":
169
- if (delegate.getKeyAbove) {
170
- var _delegate_getLastKey, _delegate_getLastKey1;
171
- e.preventDefault();
172
- let nextKey = manager.focusedKey != null ? delegate.getKeyAbove(manager.focusedKey) : (_delegate_getLastKey = delegate.getLastKey) === null || _delegate_getLastKey === void 0 ? void 0 : _delegate_getLastKey.call(delegate);
173
- if (nextKey == null && shouldFocusWrap) nextKey = (_delegate_getLastKey1 = delegate.getLastKey) === null || _delegate_getLastKey1 === void 0 ? void 0 : _delegate_getLastKey1.call(delegate, manager.focusedKey);
174
- navigateToKey(nextKey);
175
- }
176
- break;
177
- case "ArrowLeft":
178
- if (delegate.getKeyLeftOf) {
179
- var _delegate_getFirstKey2, _delegate_getLastKey2;
180
- e.preventDefault();
181
- let nextKey = delegate.getKeyLeftOf(manager.focusedKey);
182
- if (nextKey == null && shouldFocusWrap) nextKey = direction === "rtl" ? (_delegate_getFirstKey2 = delegate.getFirstKey) === null || _delegate_getFirstKey2 === void 0 ? void 0 : _delegate_getFirstKey2.call(delegate, manager.focusedKey) : (_delegate_getLastKey2 = delegate.getLastKey) === null || _delegate_getLastKey2 === void 0 ? void 0 : _delegate_getLastKey2.call(delegate, manager.focusedKey);
183
- navigateToKey(nextKey, direction === "rtl" ? "first" : "last");
184
- }
185
- break;
186
- case "ArrowRight":
187
- if (delegate.getKeyRightOf) {
188
- var _delegate_getLastKey3, _delegate_getFirstKey3;
189
- e.preventDefault();
190
- let nextKey = delegate.getKeyRightOf(manager.focusedKey);
191
- if (nextKey == null && shouldFocusWrap) nextKey = direction === "rtl" ? (_delegate_getLastKey3 = delegate.getLastKey) === null || _delegate_getLastKey3 === void 0 ? void 0 : _delegate_getLastKey3.call(delegate, manager.focusedKey) : (_delegate_getFirstKey3 = delegate.getFirstKey) === null || _delegate_getFirstKey3 === void 0 ? void 0 : _delegate_getFirstKey3.call(delegate, manager.focusedKey);
192
- navigateToKey(nextKey, direction === "rtl" ? "last" : "first");
193
- }
194
- break;
195
- case "Home":
196
- if (delegate.getFirstKey) {
197
- e.preventDefault();
198
- let firstKey = delegate.getFirstKey(manager.focusedKey, (0, $ee0bdf4faa47f2a8$export$16792effe837dba3)(e));
199
- manager.setFocusedKey(firstKey);
200
- if ((0, $ee0bdf4faa47f2a8$export$16792effe837dba3)(e) && e.shiftKey && manager.selectionMode === "multiple") manager.extendSelection(firstKey);
201
- else if (selectOnFocus) manager.replaceSelection(firstKey);
202
- }
203
- break;
204
- case "End":
205
- if (delegate.getLastKey) {
206
- e.preventDefault();
207
- let lastKey = delegate.getLastKey(manager.focusedKey, (0, $ee0bdf4faa47f2a8$export$16792effe837dba3)(e));
208
- manager.setFocusedKey(lastKey);
209
- if ((0, $ee0bdf4faa47f2a8$export$16792effe837dba3)(e) && e.shiftKey && manager.selectionMode === "multiple") manager.extendSelection(lastKey);
210
- else if (selectOnFocus) manager.replaceSelection(lastKey);
211
- }
212
- break;
213
- case "PageDown":
214
- if (delegate.getKeyPageBelow) {
215
- e.preventDefault();
216
- let nextKey = delegate.getKeyPageBelow(manager.focusedKey);
217
- navigateToKey(nextKey);
218
- }
219
- break;
220
- case "PageUp":
221
- if (delegate.getKeyPageAbove) {
222
- e.preventDefault();
223
- let nextKey = delegate.getKeyPageAbove(manager.focusedKey);
224
- navigateToKey(nextKey);
225
- }
226
- break;
227
- case "a":
228
- if ((0, $ee0bdf4faa47f2a8$export$16792effe837dba3)(e) && manager.selectionMode === "multiple" && disallowSelectAll !== true) {
229
- e.preventDefault();
230
- manager.selectAll();
231
- }
232
- break;
233
- case "Escape":
234
- e.preventDefault();
235
- if (!disallowEmptySelection) manager.clearSelection();
236
- break;
237
- case "Tab":
238
- if (!allowsTabNavigation) {
239
- // There may be elements that are "tabbable" inside a collection (e.g. in a grid cell).
240
- // However, collections should be treated as a single tab stop, with arrow key navigation internally.
241
- // We don't control the rendering of these, so we can't override the tabIndex to prevent tabbing.
242
- // Instead, we handle the Tab key, and move focus manually to the first/last tabbable element
243
- // in the collection, so that the browser default behavior will apply starting from that element
244
- // rather than the currently focused one.
245
- if (e.shiftKey) ref.current.focus();
246
- else {
247
- let walker = (0, $glPPV$reactariafocus.getFocusableTreeWalker)(ref.current, {
248
- tabbable: true
249
- });
250
- let next;
251
- let last;
252
- do {
253
- last = walker.lastChild();
254
- if (last) next = last;
255
- }while (last);
256
- if (next && !next.contains(document.activeElement)) (0, $glPPV$reactariautils.focusWithoutScrolling)(next);
257
- }
258
- break;
259
- }
260
- }
261
- };
262
- // Store the scroll position so we can restore it later.
263
- let scrollPos = (0, $glPPV$react.useRef)({
264
- top: 0,
265
- left: 0
266
- });
267
- (0, $glPPV$reactariautils.useEvent)(scrollRef, "scroll", isVirtualized ? null : ()=>{
268
- scrollPos.current = {
269
- top: scrollRef.current.scrollTop,
270
- left: scrollRef.current.scrollLeft
271
- };
272
- });
273
- let onFocus = (e)=>{
274
- if (manager.isFocused) {
275
- // If a focus event bubbled through a portal, reset focus state.
276
- if (!e.currentTarget.contains(e.target)) manager.setFocused(false);
277
- return;
278
- }
279
- // Focus events can bubble through portals. Ignore these events.
280
- if (!e.currentTarget.contains(e.target)) return;
281
- manager.setFocused(true);
282
- if (manager.focusedKey == null) {
283
- let navigateToFirstKey = (key)=>{
284
- if (key != null) {
285
- manager.setFocusedKey(key);
286
- if (selectOnFocus) manager.replaceSelection(key);
287
- }
288
- };
289
- // If the user hasn't yet interacted with the collection, there will be no focusedKey set.
290
- // Attempt to detect whether the user is tabbing forward or backward into the collection
291
- // and either focus the first or last item accordingly.
292
- let relatedTarget = e.relatedTarget;
293
- var _manager_lastSelectedKey, _manager_firstSelectedKey;
294
- if (relatedTarget && e.currentTarget.compareDocumentPosition(relatedTarget) & Node.DOCUMENT_POSITION_FOLLOWING) navigateToFirstKey((_manager_lastSelectedKey = manager.lastSelectedKey) !== null && _manager_lastSelectedKey !== void 0 ? _manager_lastSelectedKey : delegate.getLastKey());
295
- else navigateToFirstKey((_manager_firstSelectedKey = manager.firstSelectedKey) !== null && _manager_firstSelectedKey !== void 0 ? _manager_firstSelectedKey : delegate.getFirstKey());
296
- } else if (!isVirtualized) {
297
- // Restore the scroll position to what it was before.
298
- scrollRef.current.scrollTop = scrollPos.current.top;
299
- scrollRef.current.scrollLeft = scrollPos.current.left;
300
- }
301
- if (!isVirtualized && manager.focusedKey != null) {
302
- // Refocus and scroll the focused item into view if it exists within the scrollable region.
303
- let element = scrollRef.current.querySelector(`[data-key="${CSS.escape(manager.focusedKey.toString())}"]`);
304
- if (element) {
305
- // This prevents a flash of focus on the first/last element in the collection, or the collection itself.
306
- if (!element.contains(document.activeElement)) (0, $glPPV$reactariautils.focusWithoutScrolling)(element);
307
- let modality = (0, $glPPV$reactariainteractions.getInteractionModality)();
308
- if (modality === "keyboard") (0, $glPPV$reactariautils.scrollIntoViewport)(element, {
309
- containingElement: ref.current
310
- });
311
- }
312
- }
313
- };
314
- let onBlur = (e)=>{
315
- // Don't set blurred and then focused again if moving focus within the collection.
316
- if (!e.currentTarget.contains(e.relatedTarget)) manager.setFocused(false);
317
- };
318
- const autoFocusRef = (0, $glPPV$react.useRef)(autoFocus);
319
- (0, $glPPV$react.useEffect)(()=>{
320
- if (autoFocusRef.current) {
321
- let focusedKey = null;
322
- // Check focus strategy to determine which item to focus
323
- if (autoFocus === "first") focusedKey = delegate.getFirstKey();
324
- if (autoFocus === "last") focusedKey = delegate.getLastKey();
325
- // If there are any selected keys, make the first one the new focus target
326
- let selectedKeys = manager.selectedKeys;
327
- if (selectedKeys.size) {
328
- for (let key of selectedKeys)if (manager.canSelectItem(key)) {
329
- focusedKey = key;
330
- break;
331
- }
332
- }
333
- manager.setFocused(true);
334
- manager.setFocusedKey(focusedKey);
335
- // If no default focus key is selected, focus the collection itself.
336
- if (focusedKey == null && !shouldUseVirtualFocus) (0, $glPPV$reactariafocus.focusSafely)(ref.current);
337
- }
338
- // eslint-disable-next-line react-hooks/exhaustive-deps
339
- }, []);
340
- // If not virtualized, scroll the focused element into view when the focusedKey changes.
341
- // When virtualized, Virtualizer handles this internally.
342
- let lastFocusedKey = (0, $glPPV$react.useRef)(manager.focusedKey);
343
- (0, $glPPV$react.useEffect)(()=>{
344
- let modality = (0, $glPPV$reactariainteractions.getInteractionModality)();
345
- if (manager.isFocused && manager.focusedKey != null && (scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current)) {
346
- let element = scrollRef.current.querySelector(`[data-key="${CSS.escape(manager.focusedKey.toString())}"]`);
347
- if (element && (modality === "keyboard" || autoFocusRef.current)) {
348
- if (!isVirtualized) (0, $glPPV$reactariautils.scrollIntoView)(scrollRef.current, element);
349
- // Avoid scroll in iOS VO, since it may cause overlay to close (i.e. RAC submenu)
350
- if (modality !== "virtual") (0, $glPPV$reactariautils.scrollIntoViewport)(element, {
351
- containingElement: ref.current
352
- });
353
- }
354
- }
355
- // If the focused key becomes null (e.g. the last item is deleted), focus the whole collection.
356
- if (manager.isFocused && manager.focusedKey == null && lastFocusedKey.current != null) (0, $glPPV$reactariafocus.focusSafely)(ref.current);
357
- lastFocusedKey.current = manager.focusedKey;
358
- autoFocusRef.current = false;
359
- }, [
360
- isVirtualized,
361
- scrollRef,
362
- manager.focusedKey,
363
- manager.isFocused,
364
- ref
365
- ]);
366
- let handlers = {
367
- onKeyDown: onKeyDown,
368
- onFocus: onFocus,
369
- onBlur: onBlur,
370
- onMouseDown (e) {
371
- // Ignore events that bubbled through portals.
372
- if (scrollRef.current === e.target) // Prevent focus going to the collection when clicking on the scrollbar.
373
- e.preventDefault();
374
- }
375
- };
376
- let { typeSelectProps: typeSelectProps } = (0, $a1189052f36475e8$export$e32c88dfddc6e1d8)({
377
- keyboardDelegate: delegate,
378
- selectionManager: manager
379
- });
380
- if (!disallowTypeAhead) handlers = (0, $glPPV$reactariautils.mergeProps)(typeSelectProps, handlers);
381
- // If nothing is focused within the collection, make the collection itself tabbable.
382
- // This will be marshalled to either the first or last item depending on where focus came from.
383
- // If using virtual focus, don't set a tabIndex at all so that VoiceOver on iOS 14 doesn't try
384
- // to move real DOM focus to the element anyway.
385
- let tabIndex;
386
- if (!shouldUseVirtualFocus) tabIndex = manager.focusedKey == null ? 0 : -1;
387
- return {
388
- collectionProps: {
389
- ...handlers,
390
- tabIndex: tabIndex
391
- }
392
- };
393
- }
394
-
395
-
396
- /*
397
- * Copyright 2020 Adobe. All rights reserved.
398
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
399
- * you may not use this file except in compliance with the License. You may obtain a copy
400
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
401
- *
402
- * Unless required by applicable law or agreed to in writing, software distributed under
403
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
404
- * OF ANY KIND, either express or implied. See the License for the specific language
405
- * governing permissions and limitations under the License.
406
- */
407
-
408
-
409
-
410
-
411
- function $433b1145b0781e10$export$ecf600387e221c37(options) {
412
- let { selectionManager: manager, key: key, ref: ref, shouldSelectOnPressUp: shouldSelectOnPressUp, shouldUseVirtualFocus: shouldUseVirtualFocus, focus: focus, isDisabled: isDisabled, onAction: onAction, allowsDifferentPressOrigin: allowsDifferentPressOrigin, linkBehavior: linkBehavior = "action" } = options;
413
- let router = (0, $glPPV$reactariautils.useRouter)();
414
- let onSelect = (e)=>{
415
- if (e.pointerType === "keyboard" && (0, $ee0bdf4faa47f2a8$export$d3e3bd3e26688c04)(e)) manager.toggleSelection(key);
416
- else {
417
- if (manager.selectionMode === "none") return;
418
- if (manager.isLink(key)) {
419
- if (linkBehavior === "selection") {
420
- router.open(ref.current, e);
421
- // Always set selected keys back to what they were so that select and combobox close.
422
- manager.setSelectedKeys(manager.selectedKeys);
423
- return;
424
- } else if (linkBehavior === "override" || linkBehavior === "none") return;
425
- }
426
- if (manager.selectionMode === "single") {
427
- if (manager.isSelected(key) && !manager.disallowEmptySelection) manager.toggleSelection(key);
428
- else manager.replaceSelection(key);
429
- } else if (e && e.shiftKey) manager.extendSelection(key);
430
- else if (manager.selectionBehavior === "toggle" || e && ((0, $ee0bdf4faa47f2a8$export$16792effe837dba3)(e) || e.pointerType === "touch" || e.pointerType === "virtual")) // if touch or virtual (VO) then we just want to toggle, otherwise it's impossible to multi select because they don't have modifier keys
431
- manager.toggleSelection(key);
432
- else manager.replaceSelection(key);
433
- }
434
- };
435
- // Focus the associated DOM node when this item becomes the focusedKey
436
- (0, $glPPV$react.useEffect)(()=>{
437
- let isFocused = key === manager.focusedKey;
438
- if (isFocused && manager.isFocused && !shouldUseVirtualFocus) {
439
- if (focus) focus();
440
- else if (document.activeElement !== ref.current) (0, $glPPV$reactariafocus.focusSafely)(ref.current);
441
- }
442
- // eslint-disable-next-line react-hooks/exhaustive-deps
443
- }, [
444
- ref,
445
- key,
446
- manager.focusedKey,
447
- manager.childFocusStrategy,
448
- manager.isFocused,
449
- shouldUseVirtualFocus
450
- ]);
451
- isDisabled = isDisabled || manager.isDisabled(key);
452
- // Set tabIndex to 0 if the element is focused, or -1 otherwise so that only the last focused
453
- // item is tabbable. If using virtual focus, don't set a tabIndex at all so that VoiceOver
454
- // on iOS 14 doesn't try to move real DOM focus to the item anyway.
455
- let itemProps = {};
456
- if (!shouldUseVirtualFocus && !isDisabled) itemProps = {
457
- tabIndex: key === manager.focusedKey ? 0 : -1,
458
- onFocus (e) {
459
- if (e.target === ref.current) manager.setFocusedKey(key);
460
- }
461
- };
462
- else if (isDisabled) itemProps.onMouseDown = (e)=>{
463
- // Prevent focus going to the body when clicking on a disabled item.
464
- e.preventDefault();
465
- };
466
- // With checkbox selection, onAction (i.e. navigation) becomes primary, and occurs on a single click of the row.
467
- // Clicking the checkbox enters selection mode, after which clicking anywhere on any row toggles selection for that row.
468
- // With highlight selection, onAction is secondary, and occurs on double click. Single click selects the row.
469
- // With touch, onAction occurs on single tap, and long press enters selection mode.
470
- let isLinkOverride = manager.isLink(key) && linkBehavior === "override";
471
- let hasLinkAction = manager.isLink(key) && linkBehavior !== "selection" && linkBehavior !== "none";
472
- let allowsSelection = !isDisabled && manager.canSelectItem(key) && !isLinkOverride;
473
- let allowsActions = (onAction || hasLinkAction) && !isDisabled;
474
- let hasPrimaryAction = allowsActions && (manager.selectionBehavior === "replace" ? !allowsSelection : !allowsSelection || manager.isEmpty);
475
- let hasSecondaryAction = allowsActions && allowsSelection && manager.selectionBehavior === "replace";
476
- let hasAction = hasPrimaryAction || hasSecondaryAction;
477
- let modality = (0, $glPPV$react.useRef)(null);
478
- let longPressEnabled = hasAction && allowsSelection;
479
- let longPressEnabledOnPressStart = (0, $glPPV$react.useRef)(false);
480
- let hadPrimaryActionOnPressStart = (0, $glPPV$react.useRef)(false);
481
- let performAction = (e)=>{
482
- if (onAction) onAction();
483
- if (hasLinkAction) router.open(ref.current, e);
484
- };
485
- // By default, selection occurs on pointer down. This can be strange if selecting an
486
- // item causes the UI to disappear immediately (e.g. menus).
487
- // If shouldSelectOnPressUp is true, we use onPressUp instead of onPressStart.
488
- // onPress requires a pointer down event on the same element as pointer up. For menus,
489
- // we want to be able to have the pointer down on the trigger that opens the menu and
490
- // the pointer up on the menu item rather than requiring a separate press.
491
- // For keyboard events, selection still occurs on key down.
492
- let itemPressProps = {};
493
- if (shouldSelectOnPressUp) {
494
- itemPressProps.onPressStart = (e)=>{
495
- modality.current = e.pointerType;
496
- longPressEnabledOnPressStart.current = longPressEnabled;
497
- if (e.pointerType === "keyboard" && (!hasAction || $433b1145b0781e10$var$isSelectionKey())) onSelect(e);
498
- };
499
- // If allowsDifferentPressOrigin, make selection happen on pressUp (e.g. open menu on press down, selection on menu item happens on press up.)
500
- // Otherwise, have selection happen onPress (prevents listview row selection when clicking on interactable elements in the row)
501
- if (!allowsDifferentPressOrigin) itemPressProps.onPress = (e)=>{
502
- if (hasPrimaryAction || hasSecondaryAction && e.pointerType !== "mouse") {
503
- if (e.pointerType === "keyboard" && !$433b1145b0781e10$var$isActionKey()) return;
504
- performAction(e);
505
- } else if (e.pointerType !== "keyboard" && allowsSelection) onSelect(e);
506
- };
507
- else {
508
- itemPressProps.onPressUp = hasPrimaryAction ? null : (e)=>{
509
- if (e.pointerType !== "keyboard" && allowsSelection) onSelect(e);
510
- };
511
- itemPressProps.onPress = hasPrimaryAction ? performAction : null;
512
- }
513
- } else {
514
- itemPressProps.onPressStart = (e)=>{
515
- modality.current = e.pointerType;
516
- longPressEnabledOnPressStart.current = longPressEnabled;
517
- hadPrimaryActionOnPressStart.current = hasPrimaryAction;
518
- // Select on mouse down unless there is a primary action which will occur on mouse up.
519
- // For keyboard, select on key down. If there is an action, the Space key selects on key down,
520
- // and the Enter key performs onAction on key up.
521
- if (allowsSelection && (e.pointerType === "mouse" && !hasPrimaryAction || e.pointerType === "keyboard" && (!allowsActions || $433b1145b0781e10$var$isSelectionKey()))) onSelect(e);
522
- };
523
- itemPressProps.onPress = (e)=>{
524
- // Selection occurs on touch up. Primary actions always occur on pointer up.
525
- // Both primary and secondary actions occur on Enter key up. The only exception
526
- // is secondary actions, which occur on double click with a mouse.
527
- if (e.pointerType === "touch" || e.pointerType === "pen" || e.pointerType === "virtual" || e.pointerType === "keyboard" && hasAction && $433b1145b0781e10$var$isActionKey() || e.pointerType === "mouse" && hadPrimaryActionOnPressStart.current) {
528
- if (hasAction) performAction(e);
529
- else if (allowsSelection) onSelect(e);
530
- }
531
- };
532
- }
533
- itemProps["data-key"] = key;
534
- itemPressProps.preventFocusOnPress = shouldUseVirtualFocus;
535
- let { pressProps: pressProps, isPressed: isPressed } = (0, $glPPV$reactariainteractions.usePress)(itemPressProps);
536
- // Double clicking with a mouse with selectionBehavior = 'replace' performs an action.
537
- let onDoubleClick = hasSecondaryAction ? (e)=>{
538
- if (modality.current === "mouse") {
539
- e.stopPropagation();
540
- e.preventDefault();
541
- performAction(e);
542
- }
543
- } : undefined;
544
- // Long pressing an item with touch when selectionBehavior = 'replace' switches the selection behavior
545
- // to 'toggle'. This changes the single tap behavior from performing an action (i.e. navigating) to
546
- // selecting, and may toggle the appearance of a UI affordance like checkboxes on each item.
547
- let { longPressProps: longPressProps } = (0, $glPPV$reactariainteractions.useLongPress)({
548
- isDisabled: !longPressEnabled,
549
- onLongPress (e) {
550
- if (e.pointerType === "touch") {
551
- onSelect(e);
552
- manager.setSelectionBehavior("toggle");
553
- }
554
- }
555
- });
556
- // Prevent native drag and drop on long press if we also select on long press.
557
- // Once the user is in selection mode, they can long press again to drag.
558
- // Use a capturing listener to ensure this runs before useDrag, regardless of
559
- // the order the props get merged.
560
- let onDragStartCapture = (e)=>{
561
- if (modality.current === "touch" && longPressEnabledOnPressStart.current) e.preventDefault();
562
- };
563
- // Prevent default on link clicks so that we control exactly
564
- // when they open (to match selection behavior).
565
- let onClick = manager.isLink(key) ? (e)=>{
566
- if (!(0, $glPPV$reactariautils.openLink).isOpening) e.preventDefault();
567
- } : undefined;
568
- return {
569
- itemProps: (0, $glPPV$reactariautils.mergeProps)(itemProps, allowsSelection || hasPrimaryAction ? pressProps : {}, longPressEnabled ? longPressProps : {}, {
570
- onDoubleClick: onDoubleClick,
571
- onDragStartCapture: onDragStartCapture,
572
- onClick: onClick
573
- }),
574
- isPressed: isPressed,
575
- isSelected: manager.isSelected(key),
576
- isFocused: manager.isFocused && manager.focusedKey === key,
577
- isDisabled: isDisabled,
578
- allowsSelection: allowsSelection,
579
- hasAction: hasAction
580
- };
581
- }
582
- function $433b1145b0781e10$var$isActionKey() {
583
- let event = window.event;
584
- return (event === null || event === void 0 ? void 0 : event.key) === "Enter";
585
- }
586
- function $433b1145b0781e10$var$isSelectionKey() {
587
- let event = window.event;
588
- return (event === null || event === void 0 ? void 0 : event.key) === " " || (event === null || event === void 0 ? void 0 : event.code) === "Space";
589
- }
590
-
591
-
592
- /*
593
- * Copyright 2020 Adobe. All rights reserved.
594
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
595
- * you may not use this file except in compliance with the License. You may obtain a copy
596
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
597
- *
598
- * Unless required by applicable law or agreed to in writing, software distributed under
599
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
600
- * OF ANY KIND, either express or implied. See the License for the specific language
601
- * governing permissions and limitations under the License.
602
- */
603
- /*
604
- * Copyright 2020 Adobe. All rights reserved.
605
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
606
- * you may not use this file except in compliance with the License. You may obtain a copy
607
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
608
- *
609
- * Unless required by applicable law or agreed to in writing, software distributed under
610
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
611
- * OF ANY KIND, either express or implied. See the License for the specific language
612
- * governing permissions and limitations under the License.
613
- */
614
- class $836f880b12dcae5c$export$a05409b8bb224a5a {
615
- getNextKey(key) {
616
- key = this.collection.getKeyAfter(key);
617
- while(key != null){
618
- let item = this.collection.getItem(key);
619
- if (item.type === "item" && !this.disabledKeys.has(key)) return key;
620
- key = this.collection.getKeyAfter(key);
621
- }
622
- return null;
623
- }
624
- getPreviousKey(key) {
625
- key = this.collection.getKeyBefore(key);
626
- while(key != null){
627
- let item = this.collection.getItem(key);
628
- if (item.type === "item" && !this.disabledKeys.has(key)) return key;
629
- key = this.collection.getKeyBefore(key);
630
- }
631
- return null;
632
- }
633
- findKey(key, nextKey, shouldSkip) {
634
- let item = this.getItem(key);
635
- if (!item) return null;
636
- // Find the item above or below in the same column.
637
- let prevRect = item.getBoundingClientRect();
638
- do {
639
- key = nextKey(key);
640
- item = this.getItem(key);
641
- }while (item && shouldSkip(prevRect, item.getBoundingClientRect()));
642
- return key;
643
- }
644
- isSameRow(prevRect, itemRect) {
645
- return prevRect.top === itemRect.top || prevRect.left !== itemRect.left;
646
- }
647
- isSameColumn(prevRect, itemRect) {
648
- return prevRect.left === itemRect.left || prevRect.top !== itemRect.top;
649
- }
650
- getKeyBelow(key) {
651
- if (this.layout === "grid" && this.orientation === "vertical") return this.findKey(key, (key)=>this.getNextKey(key), this.isSameRow);
652
- else return this.getNextKey(key);
653
- }
654
- getKeyAbove(key) {
655
- if (this.layout === "grid" && this.orientation === "vertical") return this.findKey(key, (key)=>this.getPreviousKey(key), this.isSameRow);
656
- else return this.getPreviousKey(key);
657
- }
658
- getNextColumn(key, right) {
659
- return right ? this.getPreviousKey(key) : this.getNextKey(key);
660
- }
661
- getKeyRightOf(key) {
662
- if (this.layout === "grid") {
663
- if (this.orientation === "vertical") return this.getNextColumn(key, this.direction === "rtl");
664
- else return this.findKey(key, (key)=>this.getNextColumn(key, this.direction === "rtl"), this.isSameColumn);
665
- } else if (this.orientation === "horizontal") return this.getNextColumn(key, this.direction === "rtl");
666
- return null;
667
- }
668
- getKeyLeftOf(key) {
669
- if (this.layout === "grid") {
670
- if (this.orientation === "vertical") return this.getNextColumn(key, this.direction === "ltr");
671
- else return this.findKey(key, (key)=>this.getNextColumn(key, this.direction === "ltr"), this.isSameColumn);
672
- } else if (this.orientation === "horizontal") return this.getNextColumn(key, this.direction === "ltr");
673
- return null;
674
- }
675
- getFirstKey() {
676
- let key = this.collection.getFirstKey();
677
- while(key != null){
678
- let item = this.collection.getItem(key);
679
- if ((item === null || item === void 0 ? void 0 : item.type) === "item" && !this.disabledKeys.has(key)) return key;
680
- key = this.collection.getKeyAfter(key);
681
- }
682
- return null;
683
- }
684
- getLastKey() {
685
- let key = this.collection.getLastKey();
686
- while(key != null){
687
- let item = this.collection.getItem(key);
688
- if (item.type === "item" && !this.disabledKeys.has(key)) return key;
689
- key = this.collection.getKeyBefore(key);
690
- }
691
- return null;
692
- }
693
- getItem(key) {
694
- return this.ref.current.querySelector(`[data-key="${CSS.escape(key.toString())}"]`);
695
- }
696
- getKeyPageAbove(key) {
697
- let menu = this.ref.current;
698
- let item = this.getItem(key);
699
- if (!item) return null;
700
- if (!(0, $glPPV$reactariautils.isScrollable)(menu)) return this.getFirstKey();
701
- let containerRect = menu.getBoundingClientRect();
702
- let itemRect = item.getBoundingClientRect();
703
- if (this.orientation === "horizontal") {
704
- let containerX = containerRect.x - menu.scrollLeft;
705
- let pageX = Math.max(0, itemRect.x - containerX + itemRect.width - containerRect.width);
706
- while(item && itemRect.x - containerX > pageX){
707
- key = this.getKeyAbove(key);
708
- item = key == null ? null : this.getItem(key);
709
- itemRect = item === null || item === void 0 ? void 0 : item.getBoundingClientRect();
710
- }
711
- } else {
712
- let containerY = containerRect.y - menu.scrollTop;
713
- let pageY = Math.max(0, itemRect.y - containerY + itemRect.height - containerRect.height);
714
- while(item && itemRect.y - containerY > pageY){
715
- key = this.getKeyAbove(key);
716
- item = key == null ? null : this.getItem(key);
717
- itemRect = item === null || item === void 0 ? void 0 : item.getBoundingClientRect();
718
- }
719
- }
720
- return key !== null && key !== void 0 ? key : this.getFirstKey();
721
- }
722
- getKeyPageBelow(key) {
723
- let menu = this.ref.current;
724
- let item = this.getItem(key);
725
- if (!item) return null;
726
- if (!(0, $glPPV$reactariautils.isScrollable)(menu)) return this.getLastKey();
727
- let containerRect = menu.getBoundingClientRect();
728
- let itemRect = item.getBoundingClientRect();
729
- if (this.orientation === "horizontal") {
730
- let containerX = containerRect.x - menu.scrollLeft;
731
- let pageX = Math.min(menu.scrollWidth, itemRect.x - containerX - itemRect.width + containerRect.width);
732
- while(item && itemRect.x - containerX < pageX){
733
- key = this.getKeyBelow(key);
734
- item = key == null ? null : this.getItem(key);
735
- itemRect = item === null || item === void 0 ? void 0 : item.getBoundingClientRect();
736
- }
737
- } else {
738
- let containerY = containerRect.y - menu.scrollTop;
739
- let pageY = Math.min(menu.scrollHeight, itemRect.y - containerY - itemRect.height + containerRect.height);
740
- while(item && itemRect.y - containerY < pageY){
741
- key = this.getKeyBelow(key);
742
- item = key == null ? null : this.getItem(key);
743
- itemRect = item === null || item === void 0 ? void 0 : item.getBoundingClientRect();
744
- }
745
- }
746
- return key !== null && key !== void 0 ? key : this.getLastKey();
747
- }
748
- getKeyForSearch(search, fromKey) {
749
- if (!this.collator) return null;
750
- let collection = this.collection;
751
- let key = fromKey || this.getFirstKey();
752
- while(key != null){
753
- let item = collection.getItem(key);
754
- let substring = item.textValue.slice(0, search.length);
755
- if (item.textValue && this.collator.compare(substring, search) === 0) return key;
756
- key = this.getKeyBelow(key);
757
- }
758
- return null;
759
- }
760
- constructor(...args){
761
- if (args.length === 1) {
762
- let opts = args[0];
763
- this.collection = opts.collection;
764
- this.ref = opts.ref;
765
- this.collator = opts.collator;
766
- this.disabledKeys = opts.disabledKeys || new Set();
767
- this.orientation = opts.orientation;
768
- this.direction = opts.direction;
769
- this.layout = opts.layout || "stack";
770
- } else {
771
- this.collection = args[0];
772
- this.disabledKeys = args[1];
773
- this.ref = args[2];
774
- this.collator = args[3];
775
- this.layout = "stack";
776
- this.orientation = "vertical";
777
- }
778
- // If this is a vertical stack, remove the left/right methods completely
779
- // so they aren't called by useDroppableCollection.
780
- if (this.layout === "stack" && this.orientation === "vertical") {
781
- this.getKeyLeftOf = undefined;
782
- this.getKeyRightOf = undefined;
783
- }
784
- }
785
- }
786
-
787
-
788
-
789
-
790
- function $bd230acee196f50c$export$b95089534ab7c1fd(props) {
791
- let { selectionManager: selectionManager, collection: collection, disabledKeys: disabledKeys, ref: ref, keyboardDelegate: keyboardDelegate } = props;
792
- // By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).
793
- // When virtualized, the layout object will be passed in as a prop and override this.
794
- let collator = (0, $glPPV$reactariai18n.useCollator)({
795
- usage: "search",
796
- sensitivity: "base"
797
- });
798
- let disabledBehavior = selectionManager.disabledBehavior;
799
- let delegate = (0, $glPPV$react.useMemo)(()=>keyboardDelegate || new (0, $836f880b12dcae5c$export$a05409b8bb224a5a)(collection, disabledBehavior === "selection" ? new Set() : disabledKeys, ref, collator), [
800
- keyboardDelegate,
801
- collection,
802
- disabledKeys,
803
- ref,
804
- collator,
805
- disabledBehavior
806
- ]);
807
- let { collectionProps: collectionProps } = (0, $b6837c2f80a3c32f$export$d6daf82dcd84e87c)({
808
- ...props,
809
- ref: ref,
810
- selectionManager: selectionManager,
811
- keyboardDelegate: delegate
812
- });
813
- return {
814
- listProps: collectionProps
815
- };
816
- }
817
28
 
818
29
 
819
30