@react-aria/selection 3.0.0-nightly.2843 → 3.0.0-nightly.2848

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