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