@react-aria/selection 3.18.1 → 3.19.1

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/DOMLayoutDelegate.main.js +53 -0
  2. package/dist/DOMLayoutDelegate.main.js.map +1 -0
  3. package/dist/DOMLayoutDelegate.mjs +48 -0
  4. package/dist/DOMLayoutDelegate.module.js +48 -0
  5. package/dist/DOMLayoutDelegate.module.js.map +1 -0
  6. package/dist/ListKeyboardDelegate.main.js +28 -39
  7. package/dist/ListKeyboardDelegate.main.js.map +1 -1
  8. package/dist/ListKeyboardDelegate.mjs +28 -39
  9. package/dist/ListKeyboardDelegate.module.js +28 -39
  10. package/dist/ListKeyboardDelegate.module.js.map +1 -1
  11. package/dist/import.mjs +3 -1
  12. package/dist/main.js +3 -0
  13. package/dist/main.js.map +1 -1
  14. package/dist/module.js +3 -1
  15. package/dist/module.js.map +1 -1
  16. package/dist/types.d.ts +19 -7
  17. package/dist/types.d.ts.map +1 -1
  18. package/dist/useSelectableCollection.main.js +17 -15
  19. package/dist/useSelectableCollection.main.js.map +1 -1
  20. package/dist/useSelectableCollection.mjs +17 -15
  21. package/dist/useSelectableCollection.module.js +17 -15
  22. package/dist/useSelectableCollection.module.js.map +1 -1
  23. package/dist/useSelectableItem.main.js.map +1 -1
  24. package/dist/useSelectableItem.module.js.map +1 -1
  25. package/dist/useSelectableList.main.js +4 -2
  26. package/dist/useSelectableList.main.js.map +1 -1
  27. package/dist/useSelectableList.mjs +4 -2
  28. package/dist/useSelectableList.module.js +4 -2
  29. package/dist/useSelectableList.module.js.map +1 -1
  30. package/package.json +10 -10
  31. package/src/DOMLayoutDelegate.ts +57 -0
  32. package/src/ListKeyboardDelegate.ts +37 -49
  33. package/src/index.ts +1 -0
  34. package/src/useSelectableCollection.ts +26 -15
  35. package/src/useSelectableItem.ts +3 -3
  36. package/src/useSelectableList.ts +12 -4
@@ -1,3 +1,4 @@
1
+ import {DOMLayoutDelegate as $657e4dc4a6e88df0$export$8f5ed9ff9f511381} from "./DOMLayoutDelegate.module.js";
1
2
  import {isScrollable as $eak97$isScrollable} from "@react-aria/utils";
2
3
 
3
4
  /*
@@ -11,6 +12,7 @@ import {isScrollable as $eak97$isScrollable} from "@react-aria/utils";
11
12
  * OF ANY KIND, either express or implied. See the License for the specific language
12
13
  * governing permissions and limitations under the License.
13
14
  */
15
+
14
16
  class $2a25aae57d74318e$export$a05409b8bb224a5a {
15
17
  isDisabled(item) {
16
18
  var _item_props;
@@ -35,21 +37,21 @@ class $2a25aae57d74318e$export$a05409b8bb224a5a {
35
37
  return null;
36
38
  }
37
39
  findKey(key, nextKey, shouldSkip) {
38
- let item = this.getItem(key);
39
- if (!item) return null;
40
+ let itemRect = this.layoutDelegate.getItemRect(key);
41
+ if (!itemRect) return null;
40
42
  // Find the item above or below in the same column.
41
- let prevRect = item.getBoundingClientRect();
43
+ let prevRect = itemRect;
42
44
  do {
43
45
  key = nextKey(key);
44
- item = this.getItem(key);
45
- }while (item && shouldSkip(prevRect, item.getBoundingClientRect()));
46
+ itemRect = this.layoutDelegate.getItemRect(key);
47
+ }while (itemRect && shouldSkip(prevRect, itemRect));
46
48
  return key;
47
49
  }
48
50
  isSameRow(prevRect, itemRect) {
49
- return prevRect.top === itemRect.top || prevRect.left !== itemRect.left;
51
+ return prevRect.y === itemRect.y || prevRect.x !== itemRect.x;
50
52
  }
51
53
  isSameColumn(prevRect, itemRect) {
52
- return prevRect.left === itemRect.left || prevRect.top !== itemRect.top;
54
+ return prevRect.x === itemRect.x || prevRect.y !== itemRect.y;
53
55
  }
54
56
  getKeyBelow(key) {
55
57
  if (this.layout === 'grid' && this.orientation === 'vertical') return this.findKey(key, (key)=>this.getNextKey(key), this.isSameRow);
@@ -94,57 +96,42 @@ class $2a25aae57d74318e$export$a05409b8bb224a5a {
94
96
  }
95
97
  return null;
96
98
  }
97
- getItem(key) {
98
- return key !== null ? this.ref.current.querySelector(`[data-key="${CSS.escape(key.toString())}"]`) : null;
99
- }
100
99
  getKeyPageAbove(key) {
101
100
  let menu = this.ref.current;
102
- let item = this.getItem(key);
103
- if (!item) return null;
101
+ let itemRect = this.layoutDelegate.getItemRect(key);
102
+ if (!itemRect) return null;
104
103
  if (!(0, $eak97$isScrollable)(menu)) return this.getFirstKey();
105
- let containerRect = menu.getBoundingClientRect();
106
- let itemRect = item.getBoundingClientRect();
107
104
  if (this.orientation === 'horizontal') {
108
- let containerX = containerRect.x - menu.scrollLeft;
109
- let pageX = Math.max(0, itemRect.x - containerX + itemRect.width - containerRect.width);
110
- while(item && itemRect.x - containerX > pageX){
105
+ let pageX = Math.max(0, itemRect.x + itemRect.width - this.layoutDelegate.getVisibleRect().width);
106
+ while(itemRect && itemRect.x > pageX){
111
107
  key = this.getKeyAbove(key);
112
- item = key == null ? null : this.getItem(key);
113
- itemRect = item === null || item === void 0 ? void 0 : item.getBoundingClientRect();
108
+ itemRect = key == null ? null : this.layoutDelegate.getItemRect(key);
114
109
  }
115
110
  } else {
116
- let containerY = containerRect.y - menu.scrollTop;
117
- let pageY = Math.max(0, itemRect.y - containerY + itemRect.height - containerRect.height);
118
- while(item && itemRect.y - containerY > pageY){
111
+ let pageY = Math.max(0, itemRect.y + itemRect.height - this.layoutDelegate.getVisibleRect().height);
112
+ while(itemRect && itemRect.y > pageY){
119
113
  key = this.getKeyAbove(key);
120
- item = key == null ? null : this.getItem(key);
121
- itemRect = item === null || item === void 0 ? void 0 : item.getBoundingClientRect();
114
+ itemRect = key == null ? null : this.layoutDelegate.getItemRect(key);
122
115
  }
123
116
  }
124
117
  return key !== null && key !== void 0 ? key : this.getFirstKey();
125
118
  }
126
119
  getKeyPageBelow(key) {
127
120
  let menu = this.ref.current;
128
- let item = this.getItem(key);
129
- if (!item) return null;
121
+ let itemRect = this.layoutDelegate.getItemRect(key);
122
+ if (!itemRect) return null;
130
123
  if (!(0, $eak97$isScrollable)(menu)) return this.getLastKey();
131
- let containerRect = menu.getBoundingClientRect();
132
- let itemRect = item.getBoundingClientRect();
133
124
  if (this.orientation === 'horizontal') {
134
- let containerX = containerRect.x - menu.scrollLeft;
135
- let pageX = Math.min(menu.scrollWidth, itemRect.x - containerX - itemRect.width + containerRect.width);
136
- while(item && itemRect.x - containerX < pageX){
125
+ let pageX = Math.min(this.layoutDelegate.getContentSize().width, itemRect.y - itemRect.width + this.layoutDelegate.getVisibleRect().width);
126
+ while(itemRect && itemRect.x < pageX){
137
127
  key = this.getKeyBelow(key);
138
- item = key == null ? null : this.getItem(key);
139
- itemRect = item === null || item === void 0 ? void 0 : item.getBoundingClientRect();
128
+ itemRect = key == null ? null : this.layoutDelegate.getItemRect(key);
140
129
  }
141
130
  } else {
142
- let containerY = containerRect.y - menu.scrollTop;
143
- let pageY = Math.min(menu.scrollHeight, itemRect.y - containerY - itemRect.height + containerRect.height);
144
- while(item && itemRect.y - containerY < pageY){
131
+ let pageY = Math.min(this.layoutDelegate.getContentSize().height, itemRect.y - itemRect.height + this.layoutDelegate.getVisibleRect().height);
132
+ while(itemRect && itemRect.y < pageY){
145
133
  key = this.getKeyBelow(key);
146
- item = key == null ? null : this.getItem(key);
147
- itemRect = item === null || item === void 0 ? void 0 : item.getBoundingClientRect();
134
+ itemRect = key == null ? null : this.layoutDelegate.getItemRect(key);
148
135
  }
149
136
  }
150
137
  return key !== null && key !== void 0 ? key : this.getLastKey();
@@ -169,9 +156,10 @@ class $2a25aae57d74318e$export$a05409b8bb224a5a {
169
156
  this.collator = opts.collator;
170
157
  this.disabledKeys = opts.disabledKeys || new Set();
171
158
  this.disabledBehavior = opts.disabledBehavior || 'all';
172
- this.orientation = opts.orientation;
159
+ this.orientation = opts.orientation || 'vertical';
173
160
  this.direction = opts.direction;
174
161
  this.layout = opts.layout || 'stack';
162
+ this.layoutDelegate = opts.layoutDelegate || new (0, $657e4dc4a6e88df0$export$8f5ed9ff9f511381)(opts.ref);
175
163
  } else {
176
164
  this.collection = args[0];
177
165
  this.disabledKeys = args[1];
@@ -180,6 +168,7 @@ class $2a25aae57d74318e$export$a05409b8bb224a5a {
180
168
  this.layout = 'stack';
181
169
  this.orientation = 'vertical';
182
170
  this.disabledBehavior = 'all';
171
+ this.layoutDelegate = new (0, $657e4dc4a6e88df0$export$8f5ed9ff9f511381)(this.ref);
183
172
  }
184
173
  // If this is a vertical stack, remove the left/right methods completely
185
174
  // so they aren't called by useDroppableCollection.
@@ -1 +1 @@
1
- {"mappings":";;AAAA;;;;;;;;;;CAUC;AAiBM,MAAM;IAyCH,WAAW,IAAmB,EAAE;YACK;QAA3C,OAAO,IAAI,CAAC,gBAAgB,KAAK,SAAU,CAAA,EAAA,cAAA,KAAK,KAAK,cAAV,kCAAA,YAAY,UAAU,KAAI,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,GAAG,CAAA;IACrG;IAEA,WAAW,GAAQ,EAAE;QACnB,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC;QAClC,MAAO,OAAO,KAAM;YAClB,IAAI,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;YACnC,IAAI,KAAK,IAAI,KAAK,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,OAC3C,OAAO;YAGT,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC;QACpC;QAEA,OAAO;IACT;IAEA,eAAe,GAAQ,EAAE;QACvB,MAAM,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC;QACnC,MAAO,OAAO,KAAM;YAClB,IAAI,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;YACnC,IAAI,KAAK,IAAI,KAAK,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,OAC3C,OAAO;YAGT,MAAM,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC;QACrC;QAEA,OAAO;IACT;IAEQ,QACN,GAAQ,EACR,OAA0B,EAC1B,UAA6D,EAC7D;QACA,IAAI,OAAO,IAAI,CAAC,OAAO,CAAC;QACxB,IAAI,CAAC,MACH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,mDAAmD;QACnD,IAAI,IAAI,CAAC,MAAM,KAAK,WAAW,IAAI,CAAC,WAAW,KAAK,YAAY;YAC9D,IAAI,CAAC,YAAY,GAAG;YACpB,IAAI,CAAC,aAAa,GAAG;QACvB;IACF;AAyOF","sources":["packages/@react-aria/selection/src/ListKeyboardDelegate.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, Direction, DisabledBehavior, Key, KeyboardDelegate, Node, Orientation} from '@react-types/shared';\nimport {isScrollable} from '@react-aria/utils';\nimport {RefObject} from 'react';\n\ninterface ListKeyboardDelegateOptions<T> {\n collection: Collection<Node<T>>,\n ref: RefObject<HTMLElement>,\n collator?: Intl.Collator,\n layout?: 'stack' | 'grid',\n orientation?: Orientation,\n direction?: Direction,\n disabledKeys?: Set<Key>,\n disabledBehavior?: DisabledBehavior\n}\n\nexport class ListKeyboardDelegate<T> implements KeyboardDelegate {\n private collection: Collection<Node<T>>;\n private disabledKeys: Set<Key>;\n private disabledBehavior: DisabledBehavior;\n private ref: RefObject<HTMLElement>;\n private collator: Intl.Collator | undefined;\n private layout: 'stack' | 'grid';\n private orientation?: Orientation;\n private direction?: Direction;\n\n constructor(collection: Collection<Node<T>>, disabledKeys: Set<Key>, ref: RefObject<HTMLElement>, collator?: Intl.Collator);\n constructor(options: ListKeyboardDelegateOptions<T>);\n constructor(...args: any[]) {\n if (args.length === 1) {\n let opts = args[0] as ListKeyboardDelegateOptions<T>;\n this.collection = opts.collection;\n this.ref = opts.ref;\n this.collator = opts.collator;\n this.disabledKeys = opts.disabledKeys || new Set();\n this.disabledBehavior = opts.disabledBehavior || 'all';\n this.orientation = opts.orientation;\n this.direction = opts.direction;\n this.layout = opts.layout || 'stack';\n } else {\n this.collection = args[0];\n this.disabledKeys = args[1];\n this.ref = args[2];\n this.collator = args[3];\n this.layout = 'stack';\n this.orientation = 'vertical';\n this.disabledBehavior = 'all';\n }\n\n // If this is a vertical stack, remove the left/right methods completely\n // so they aren't called by useDroppableCollection.\n if (this.layout === 'stack' && this.orientation === 'vertical') {\n this.getKeyLeftOf = undefined;\n this.getKeyRightOf = undefined;\n }\n }\n\n private isDisabled(item: Node<unknown>) {\n return this.disabledBehavior === 'all' && (item.props?.isDisabled || this.disabledKeys.has(item.key));\n }\n\n getNextKey(key: Key) {\n key = this.collection.getKeyAfter(key);\n while (key != null) {\n let item = this.collection.getItem(key);\n if (item.type === 'item' && !this.isDisabled(item)) {\n return key;\n }\n\n key = this.collection.getKeyAfter(key);\n }\n\n return null;\n }\n\n getPreviousKey(key: Key) {\n key = this.collection.getKeyBefore(key);\n while (key != null) {\n let item = this.collection.getItem(key);\n if (item.type === 'item' && !this.isDisabled(item)) {\n return key;\n }\n\n key = this.collection.getKeyBefore(key);\n }\n\n return null;\n }\n\n private findKey(\n key: Key,\n nextKey: (key: Key) => Key,\n shouldSkip: (prevRect: DOMRect, itemRect: DOMRect) => boolean\n ) {\n let item = this.getItem(key);\n if (!item) {\n return null;\n }\n\n // Find the item above or below in the same column.\n let prevRect = item.getBoundingClientRect();\n do {\n key = nextKey(key);\n item = this.getItem(key);\n } while (item && shouldSkip(prevRect, item.getBoundingClientRect()));\n\n return key;\n }\n\n private isSameRow(prevRect: DOMRect, itemRect: DOMRect) {\n return prevRect.top === itemRect.top || prevRect.left !== itemRect.left;\n }\n\n private isSameColumn(prevRect: DOMRect, itemRect: DOMRect) {\n return prevRect.left === itemRect.left || prevRect.top !== itemRect.top;\n }\n\n getKeyBelow(key: Key) {\n if (this.layout === 'grid' && this.orientation === 'vertical') {\n return this.findKey(key, (key) => this.getNextKey(key), this.isSameRow);\n } else {\n return this.getNextKey(key);\n }\n }\n\n getKeyAbove(key: Key) {\n if (this.layout === 'grid' && this.orientation === 'vertical') {\n return this.findKey(key, (key) => this.getPreviousKey(key), this.isSameRow);\n } else {\n return this.getPreviousKey(key);\n }\n }\n\n private getNextColumn(key: Key, right: boolean) {\n return right ? this.getPreviousKey(key) : this.getNextKey(key);\n }\n\n getKeyRightOf(key: Key) {\n if (this.layout === 'grid') {\n if (this.orientation === 'vertical') {\n return this.getNextColumn(key, this.direction === 'rtl');\n } else {\n return this.findKey(key, (key) => this.getNextColumn(key, this.direction === 'rtl'), this.isSameColumn);\n }\n } else if (this.orientation === 'horizontal') {\n return this.getNextColumn(key, this.direction === 'rtl');\n }\n\n return null;\n }\n\n getKeyLeftOf(key: Key) {\n if (this.layout === 'grid') {\n if (this.orientation === 'vertical') {\n return this.getNextColumn(key, this.direction === 'ltr');\n } else {\n return this.findKey(key, (key) => this.getNextColumn(key, this.direction === 'ltr'), this.isSameColumn);\n }\n } else if (this.orientation === 'horizontal') {\n return this.getNextColumn(key, this.direction === 'ltr');\n }\n\n return null;\n }\n\n getFirstKey() {\n let key = this.collection.getFirstKey();\n while (key != null) {\n let item = this.collection.getItem(key);\n if (item?.type === 'item' && !this.isDisabled(item)) {\n return key;\n }\n\n key = this.collection.getKeyAfter(key);\n }\n\n return null;\n }\n\n getLastKey() {\n let key = this.collection.getLastKey();\n while (key != null) {\n let item = this.collection.getItem(key);\n if (item.type === 'item' && !this.isDisabled(item)) {\n return key;\n }\n\n key = this.collection.getKeyBefore(key);\n }\n\n return null;\n }\n\n private getItem(key: Key): HTMLElement {\n return key !== null ? this.ref.current.querySelector(`[data-key=\"${CSS.escape(key.toString())}\"]`) : null;\n }\n\n getKeyPageAbove(key: Key) {\n let menu = this.ref.current;\n let item = this.getItem(key);\n if (!item) {\n return null;\n }\n\n if (!isScrollable(menu)) {\n return this.getFirstKey();\n }\n\n let containerRect = menu.getBoundingClientRect();\n let itemRect = item.getBoundingClientRect();\n if (this.orientation === 'horizontal') {\n let containerX = containerRect.x - menu.scrollLeft;\n let pageX = Math.max(0, (itemRect.x - containerX) + itemRect.width - containerRect.width);\n\n while (item && (itemRect.x - containerX) > pageX) {\n key = this.getKeyAbove(key);\n item = key == null ? null : this.getItem(key);\n itemRect = item?.getBoundingClientRect();\n }\n } else {\n let containerY = containerRect.y - menu.scrollTop;\n let pageY = Math.max(0, (itemRect.y - containerY) + itemRect.height - containerRect.height);\n\n while (item && (itemRect.y - containerY) > pageY) {\n key = this.getKeyAbove(key);\n item = key == null ? null : this.getItem(key);\n itemRect = item?.getBoundingClientRect();\n }\n }\n\n return key ?? this.getFirstKey();\n }\n\n getKeyPageBelow(key: Key) {\n let menu = this.ref.current;\n let item = this.getItem(key);\n if (!item) {\n return null;\n }\n\n if (!isScrollable(menu)) {\n return this.getLastKey();\n }\n\n let containerRect = menu.getBoundingClientRect();\n let itemRect = item.getBoundingClientRect();\n if (this.orientation === 'horizontal') {\n let containerX = containerRect.x - menu.scrollLeft;\n let pageX = Math.min(menu.scrollWidth, (itemRect.x - containerX) - itemRect.width + containerRect.width);\n\n while (item && (itemRect.x - containerX) < pageX) {\n key = this.getKeyBelow(key);\n item = key == null ? null : this.getItem(key);\n itemRect = item?.getBoundingClientRect();\n }\n } else {\n let containerY = containerRect.y - menu.scrollTop;\n let pageY = Math.min(menu.scrollHeight, (itemRect.y - containerY) - itemRect.height + containerRect.height);\n\n while (item && (itemRect.y - containerY) < pageY) {\n key = this.getKeyBelow(key);\n item = key == null ? null : this.getItem(key);\n itemRect = item?.getBoundingClientRect();\n }\n }\n\n return key ?? this.getLastKey();\n }\n\n getKeyForSearch(search: string, fromKey?: Key) {\n if (!this.collator) {\n return null;\n }\n\n let collection = this.collection;\n let key = fromKey || this.getFirstKey();\n while (key != null) {\n let item = collection.getItem(key);\n let substring = item.textValue.slice(0, search.length);\n if (item.textValue && this.collator.compare(substring, search) === 0) {\n return key;\n }\n\n key = this.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;YAC7C,IAAI,CAAC,gBAAgB,GAAG,KAAK,gBAAgB,IAAI;YACjD,IAAI,CAAC,WAAW,GAAG,KAAK,WAAW,IAAI;YACvC,IAAI,CAAC,SAAS,GAAG,KAAK,SAAS;YAC/B,IAAI,CAAC,MAAM,GAAG,KAAK,MAAM,IAAI;YAC7B,IAAI,CAAC,cAAc,GAAG,KAAK,cAAc,IAAI,IAAI,CAAA,GAAA,yCAAgB,EAAE,KAAK,GAAG;QAC7E,OAAO;YACL,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,EAAE;YACzB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,EAAE;YAC3B,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,EAAE;YAClB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,EAAE;YACvB,IAAI,CAAC,MAAM,GAAG;YACd,IAAI,CAAC,WAAW,GAAG;YACnB,IAAI,CAAC,gBAAgB,GAAG;YACxB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAA,GAAA,yCAAgB,EAAE,IAAI,CAAC,GAAG;QACtD;QAEA,wEAAwE;QACxE,mDAAmD;QACnD,IAAI,IAAI,CAAC,MAAM,KAAK,WAAW,IAAI,CAAC,WAAW,KAAK,YAAY;YAC9D,IAAI,CAAC,YAAY,GAAG;YACpB,IAAI,CAAC,aAAa,GAAG;QACvB;IACF;AAyNF","sources":["packages/@react-aria/selection/src/ListKeyboardDelegate.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, Direction, DisabledBehavior, Key, KeyboardDelegate, LayoutDelegate, Node, Orientation, Rect, RefObject} from '@react-types/shared';\nimport {DOMLayoutDelegate} from './DOMLayoutDelegate';\nimport {isScrollable} from '@react-aria/utils';\n\ninterface ListKeyboardDelegateOptions<T> {\n collection: Collection<Node<T>>,\n ref: RefObject<HTMLElement | null>,\n collator?: Intl.Collator,\n layout?: 'stack' | 'grid',\n orientation?: Orientation,\n direction?: Direction,\n disabledKeys?: Set<Key>,\n disabledBehavior?: DisabledBehavior,\n layoutDelegate?: LayoutDelegate\n}\n\nexport class ListKeyboardDelegate<T> implements KeyboardDelegate {\n private collection: Collection<Node<T>>;\n private disabledKeys: Set<Key>;\n private disabledBehavior: DisabledBehavior;\n private ref: RefObject<HTMLElement | null>;\n private collator: Intl.Collator | undefined;\n private layout: 'stack' | 'grid';\n private orientation?: Orientation;\n private direction?: Direction;\n private layoutDelegate: LayoutDelegate;\n\n constructor(collection: Collection<Node<T>>, disabledKeys: Set<Key>, ref: RefObject<HTMLElement | null>, collator?: Intl.Collator);\n constructor(options: ListKeyboardDelegateOptions<T>);\n constructor(...args: any[]) {\n if (args.length === 1) {\n let opts = args[0] as ListKeyboardDelegateOptions<T>;\n this.collection = opts.collection;\n this.ref = opts.ref;\n this.collator = opts.collator;\n this.disabledKeys = opts.disabledKeys || new Set();\n this.disabledBehavior = opts.disabledBehavior || 'all';\n this.orientation = opts.orientation || 'vertical';\n this.direction = opts.direction;\n this.layout = opts.layout || 'stack';\n this.layoutDelegate = opts.layoutDelegate || new DOMLayoutDelegate(opts.ref);\n } else {\n this.collection = args[0];\n this.disabledKeys = args[1];\n this.ref = args[2];\n this.collator = args[3];\n this.layout = 'stack';\n this.orientation = 'vertical';\n this.disabledBehavior = 'all';\n this.layoutDelegate = new DOMLayoutDelegate(this.ref);\n }\n\n // If this is a vertical stack, remove the left/right methods completely\n // so they aren't called by useDroppableCollection.\n if (this.layout === 'stack' && this.orientation === 'vertical') {\n this.getKeyLeftOf = undefined;\n this.getKeyRightOf = undefined;\n }\n }\n\n private isDisabled(item: Node<unknown>) {\n return this.disabledBehavior === 'all' && (item.props?.isDisabled || this.disabledKeys.has(item.key));\n }\n\n getNextKey(key: Key) {\n key = this.collection.getKeyAfter(key);\n while (key != null) {\n let item = this.collection.getItem(key);\n if (item.type === 'item' && !this.isDisabled(item)) {\n return key;\n }\n\n key = this.collection.getKeyAfter(key);\n }\n\n return null;\n }\n\n getPreviousKey(key: Key) {\n key = this.collection.getKeyBefore(key);\n while (key != null) {\n let item = this.collection.getItem(key);\n if (item.type === 'item' && !this.isDisabled(item)) {\n return key;\n }\n\n key = this.collection.getKeyBefore(key);\n }\n\n return null;\n }\n\n private findKey(\n key: Key,\n nextKey: (key: Key) => Key,\n shouldSkip: (prevRect: Rect, itemRect: Rect) => boolean\n ) {\n let itemRect = this.layoutDelegate.getItemRect(key);\n if (!itemRect) {\n return null;\n }\n\n // Find the item above or below in the same column.\n let prevRect = itemRect;\n do {\n key = nextKey(key);\n itemRect = this.layoutDelegate.getItemRect(key);\n } while (itemRect && shouldSkip(prevRect, itemRect));\n\n return key;\n }\n\n private isSameRow(prevRect: Rect, itemRect: Rect) {\n return prevRect.y === itemRect.y || prevRect.x !== itemRect.x;\n }\n\n private isSameColumn(prevRect: Rect, itemRect: Rect) {\n return prevRect.x === itemRect.x || prevRect.y !== itemRect.y;\n }\n\n getKeyBelow(key: Key) {\n if (this.layout === 'grid' && this.orientation === 'vertical') {\n return this.findKey(key, (key) => this.getNextKey(key), this.isSameRow);\n } else {\n return this.getNextKey(key);\n }\n }\n\n getKeyAbove(key: Key) {\n if (this.layout === 'grid' && this.orientation === 'vertical') {\n return this.findKey(key, (key) => this.getPreviousKey(key), this.isSameRow);\n } else {\n return this.getPreviousKey(key);\n }\n }\n\n private getNextColumn(key: Key, right: boolean) {\n return right ? this.getPreviousKey(key) : this.getNextKey(key);\n }\n\n getKeyRightOf(key: Key) {\n if (this.layout === 'grid') {\n if (this.orientation === 'vertical') {\n return this.getNextColumn(key, this.direction === 'rtl');\n } else {\n return this.findKey(key, (key) => this.getNextColumn(key, this.direction === 'rtl'), this.isSameColumn);\n }\n } else if (this.orientation === 'horizontal') {\n return this.getNextColumn(key, this.direction === 'rtl');\n }\n\n return null;\n }\n\n getKeyLeftOf(key: Key) {\n if (this.layout === 'grid') {\n if (this.orientation === 'vertical') {\n return this.getNextColumn(key, this.direction === 'ltr');\n } else {\n return this.findKey(key, (key) => this.getNextColumn(key, this.direction === 'ltr'), this.isSameColumn);\n }\n } else if (this.orientation === 'horizontal') {\n return this.getNextColumn(key, this.direction === 'ltr');\n }\n\n return null;\n }\n\n getFirstKey() {\n let key = this.collection.getFirstKey();\n while (key != null) {\n let item = this.collection.getItem(key);\n if (item?.type === 'item' && !this.isDisabled(item)) {\n return key;\n }\n\n key = this.collection.getKeyAfter(key);\n }\n\n return null;\n }\n\n getLastKey() {\n let key = this.collection.getLastKey();\n while (key != null) {\n let item = this.collection.getItem(key);\n if (item.type === 'item' && !this.isDisabled(item)) {\n return key;\n }\n\n key = this.collection.getKeyBefore(key);\n }\n\n return null;\n }\n\n getKeyPageAbove(key: Key) {\n let menu = this.ref.current;\n let itemRect = this.layoutDelegate.getItemRect(key);\n if (!itemRect) {\n return null;\n }\n\n if (!isScrollable(menu)) {\n return this.getFirstKey();\n }\n\n if (this.orientation === 'horizontal') {\n let pageX = Math.max(0, itemRect.x + itemRect.width - this.layoutDelegate.getVisibleRect().width);\n\n while (itemRect && itemRect.x > pageX) {\n key = this.getKeyAbove(key);\n itemRect = key == null ? null : this.layoutDelegate.getItemRect(key);\n }\n } else {\n let pageY = Math.max(0, itemRect.y + itemRect.height - this.layoutDelegate.getVisibleRect().height);\n\n while (itemRect && itemRect.y > pageY) {\n key = this.getKeyAbove(key);\n itemRect = key == null ? null : this.layoutDelegate.getItemRect(key);\n }\n }\n\n return key ?? this.getFirstKey();\n }\n\n getKeyPageBelow(key: Key) {\n let menu = this.ref.current;\n let itemRect = this.layoutDelegate.getItemRect(key);\n if (!itemRect) {\n return null;\n }\n\n if (!isScrollable(menu)) {\n return this.getLastKey();\n }\n\n if (this.orientation === 'horizontal') {\n let pageX = Math.min(this.layoutDelegate.getContentSize().width, itemRect.y - itemRect.width + this.layoutDelegate.getVisibleRect().width);\n\n while (itemRect && itemRect.x < pageX) {\n key = this.getKeyBelow(key);\n itemRect = key == null ? null : this.layoutDelegate.getItemRect(key);\n }\n } else {\n let pageY = Math.min(this.layoutDelegate.getContentSize().height, itemRect.y - itemRect.height + this.layoutDelegate.getVisibleRect().height);\n\n while (itemRect && itemRect.y < pageY) {\n key = this.getKeyBelow(key);\n itemRect = key == null ? null : this.layoutDelegate.getItemRect(key);\n }\n }\n\n return key ?? this.getLastKey();\n }\n\n getKeyForSearch(search: string, fromKey?: Key) {\n if (!this.collator) {\n return null;\n }\n\n let collection = this.collection;\n let key = fromKey || this.getFirstKey();\n while (key != null) {\n let item = collection.getItem(key);\n let substring = item.textValue.slice(0, search.length);\n if (item.textValue && this.collator.compare(substring, search) === 0) {\n return key;\n }\n\n key = this.getKeyBelow(key);\n }\n\n return null;\n }\n}\n"],"names":[],"version":3,"file":"ListKeyboardDelegate.module.js.map"}
package/dist/import.mjs CHANGED
@@ -2,6 +2,7 @@ import {useSelectableCollection as $ae20dd8cbca75726$export$d6daf82dcd84e87c} fr
2
2
  import {useSelectableItem as $880e95eb8b93ba9a$export$ecf600387e221c37} from "./useSelectableItem.mjs";
3
3
  import {useSelectableList as $982254629710d113$export$b95089534ab7c1fd} from "./useSelectableList.mjs";
4
4
  import {ListKeyboardDelegate as $2a25aae57d74318e$export$a05409b8bb224a5a} from "./ListKeyboardDelegate.mjs";
5
+ import {DOMLayoutDelegate as $657e4dc4a6e88df0$export$8f5ed9ff9f511381} from "./DOMLayoutDelegate.mjs";
5
6
  import {useTypeSelect as $fb3050f43d946246$export$e32c88dfddc6e1d8} from "./useTypeSelect.mjs";
6
7
 
7
8
  /*
@@ -21,5 +22,6 @@ import {useTypeSelect as $fb3050f43d946246$export$e32c88dfddc6e1d8} from "./useT
21
22
 
22
23
 
23
24
 
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};
25
+
26
+ export {$ae20dd8cbca75726$export$d6daf82dcd84e87c as useSelectableCollection, $880e95eb8b93ba9a$export$ecf600387e221c37 as useSelectableItem, $982254629710d113$export$b95089534ab7c1fd as useSelectableList, $2a25aae57d74318e$export$a05409b8bb224a5a as ListKeyboardDelegate, $657e4dc4a6e88df0$export$8f5ed9ff9f511381 as DOMLayoutDelegate, $fb3050f43d946246$export$e32c88dfddc6e1d8 as useTypeSelect};
25
27
  //# sourceMappingURL=module.js.map
package/dist/main.js CHANGED
@@ -2,6 +2,7 @@ var $b6837c2f80a3c32f$exports = require("./useSelectableCollection.main.js");
2
2
  var $433b1145b0781e10$exports = require("./useSelectableItem.main.js");
3
3
  var $bd230acee196f50c$exports = require("./useSelectableList.main.js");
4
4
  var $836f880b12dcae5c$exports = require("./ListKeyboardDelegate.main.js");
5
+ var $2ac4508142683dcb$exports = require("./DOMLayoutDelegate.main.js");
5
6
  var $a1189052f36475e8$exports = require("./useTypeSelect.main.js");
6
7
 
7
8
 
@@ -13,6 +14,7 @@ $parcel$export(module.exports, "useSelectableCollection", () => $b6837c2f80a3c32
13
14
  $parcel$export(module.exports, "useSelectableItem", () => $433b1145b0781e10$exports.useSelectableItem);
14
15
  $parcel$export(module.exports, "useSelectableList", () => $bd230acee196f50c$exports.useSelectableList);
15
16
  $parcel$export(module.exports, "ListKeyboardDelegate", () => $836f880b12dcae5c$exports.ListKeyboardDelegate);
17
+ $parcel$export(module.exports, "DOMLayoutDelegate", () => $2ac4508142683dcb$exports.DOMLayoutDelegate);
16
18
  $parcel$export(module.exports, "useTypeSelect", () => $a1189052f36475e8$exports.useTypeSelect);
17
19
  /*
18
20
  * Copyright 2020 Adobe. All rights reserved.
@@ -31,4 +33,5 @@ $parcel$export(module.exports, "useTypeSelect", () => $a1189052f36475e8$exports.
31
33
 
32
34
 
33
35
 
36
+
34
37
  //# sourceMappingURL=main.js.map
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/selection/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useSelectableCollection} from './useSelectableCollection';\nexport {useSelectableItem} from './useSelectableItem';\nexport {useSelectableList} from './useSelectableList';\nexport {ListKeyboardDelegate} from './ListKeyboardDelegate';\nexport {useTypeSelect} from './useTypeSelect';\n\nexport type {AriaSelectableCollectionOptions, SelectableCollectionAria} from './useSelectableCollection';\nexport type {AriaSelectableListOptions, SelectableListAria} from './useSelectableList';\nexport type {SelectableItemOptions, SelectableItemStates, SelectableItemAria} from './useSelectableItem';\nexport type {AriaTypeSelectOptions, TypeSelectAria} from './useTypeSelect';\n"],"names":[],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/selection/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useSelectableCollection} from './useSelectableCollection';\nexport {useSelectableItem} from './useSelectableItem';\nexport {useSelectableList} from './useSelectableList';\nexport {ListKeyboardDelegate} from './ListKeyboardDelegate';\nexport {DOMLayoutDelegate} from './DOMLayoutDelegate';\nexport {useTypeSelect} from './useTypeSelect';\n\nexport type {AriaSelectableCollectionOptions, SelectableCollectionAria} from './useSelectableCollection';\nexport type {AriaSelectableListOptions, SelectableListAria} from './useSelectableList';\nexport type {SelectableItemOptions, SelectableItemStates, SelectableItemAria} from './useSelectableItem';\nexport type {AriaTypeSelectOptions, TypeSelectAria} from './useTypeSelect';\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -2,6 +2,7 @@ import {useSelectableCollection as $ae20dd8cbca75726$export$d6daf82dcd84e87c} fr
2
2
  import {useSelectableItem as $880e95eb8b93ba9a$export$ecf600387e221c37} from "./useSelectableItem.module.js";
3
3
  import {useSelectableList as $982254629710d113$export$b95089534ab7c1fd} from "./useSelectableList.module.js";
4
4
  import {ListKeyboardDelegate as $2a25aae57d74318e$export$a05409b8bb224a5a} from "./ListKeyboardDelegate.module.js";
5
+ import {DOMLayoutDelegate as $657e4dc4a6e88df0$export$8f5ed9ff9f511381} from "./DOMLayoutDelegate.module.js";
5
6
  import {useTypeSelect as $fb3050f43d946246$export$e32c88dfddc6e1d8} from "./useTypeSelect.module.js";
6
7
 
7
8
  /*
@@ -21,5 +22,6 @@ import {useTypeSelect as $fb3050f43d946246$export$e32c88dfddc6e1d8} from "./useT
21
22
 
22
23
 
23
24
 
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};
25
+
26
+ export {$ae20dd8cbca75726$export$d6daf82dcd84e87c as useSelectableCollection, $880e95eb8b93ba9a$export$ecf600387e221c37 as useSelectableItem, $982254629710d113$export$b95089534ab7c1fd as useSelectableList, $2a25aae57d74318e$export$a05409b8bb224a5a as ListKeyboardDelegate, $657e4dc4a6e88df0$export$8f5ed9ff9f511381 as DOMLayoutDelegate, $fb3050f43d946246$export$e32c88dfddc6e1d8 as useTypeSelect};
25
27
  //# sourceMappingURL=module.js.map
@@ -1 +1 @@
1
- {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/selection/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useSelectableCollection} from './useSelectableCollection';\nexport {useSelectableItem} from './useSelectableItem';\nexport {useSelectableList} from './useSelectableList';\nexport {ListKeyboardDelegate} from './ListKeyboardDelegate';\nexport {useTypeSelect} from './useTypeSelect';\n\nexport type {AriaSelectableCollectionOptions, SelectableCollectionAria} from './useSelectableCollection';\nexport type {AriaSelectableListOptions, SelectableListAria} from './useSelectableList';\nexport type {SelectableItemOptions, SelectableItemStates, SelectableItemAria} from './useSelectableItem';\nexport type {AriaTypeSelectOptions, TypeSelectAria} from './useTypeSelect';\n"],"names":[],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/selection/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useSelectableCollection} from './useSelectableCollection';\nexport {useSelectableItem} from './useSelectableItem';\nexport {useSelectableList} from './useSelectableList';\nexport {ListKeyboardDelegate} from './ListKeyboardDelegate';\nexport {DOMLayoutDelegate} from './DOMLayoutDelegate';\nexport {useTypeSelect} from './useTypeSelect';\n\nexport type {AriaSelectableCollectionOptions, SelectableCollectionAria} from './useSelectableCollection';\nexport type {AriaSelectableListOptions, SelectableListAria} from './useSelectableList';\nexport type {SelectableItemOptions, SelectableItemStates, SelectableItemAria} from './useSelectableItem';\nexport type {AriaTypeSelectOptions, TypeSelectAria} from './useTypeSelect';\n"],"names":[],"version":3,"file":"module.js.map"}
package/dist/types.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { DOMAttributes, Key, KeyboardDelegate, FocusStrategy, FocusableElement, Collection, Direction, DisabledBehavior, Node, Orientation } from "@react-types/shared";
1
+ import { DOMAttributes, Key, KeyboardDelegate, FocusStrategy, RefObject, FocusableElement, LayoutDelegate, Rect, Size, Collection, Direction, DisabledBehavior, Node, Orientation } from "@react-types/shared";
2
2
  import { MultipleSelectionManager } from "@react-stately/selection";
3
- import { RefObject } from "react";
4
3
  export interface AriaTypeSelectOptions {
5
4
  /**
6
5
  * A delegate that returns collection item keys with respect to visual layout.
@@ -37,7 +36,7 @@ export interface AriaSelectableCollectionOptions {
37
36
  /**
38
37
  * The ref attached to the element representing the collection.
39
38
  */
40
- ref: RefObject<HTMLElement>;
39
+ ref: RefObject<HTMLElement | null>;
41
40
  /**
42
41
  * Whether the collection or one of its items should be automatically focused upon render.
43
42
  * @default false
@@ -84,7 +83,7 @@ export interface AriaSelectableCollectionOptions {
84
83
  * The ref attached to the scrollable body. Used to provide automatic scrolling on item focus for non-virtualized collections.
85
84
  * If not provided, defaults to the collection ref.
86
85
  */
87
- scrollRef?: RefObject<HTMLElement>;
86
+ scrollRef?: RefObject<HTMLElement | null>;
88
87
  /**
89
88
  * The behavior of links in the collection.
90
89
  * - 'action': link behaves like onAction.
@@ -114,7 +113,7 @@ export interface SelectableItemOptions {
114
113
  /**
115
114
  * Ref to the item.
116
115
  */
117
- ref: RefObject<FocusableElement>;
116
+ ref: RefObject<FocusableElement | null>;
118
117
  /**
119
118
  * By default, selection occurs on pointer down. This can be strange if selecting an
120
119
  * item causes the UI to disappear immediately (e.g. menus).
@@ -188,18 +187,25 @@ export interface SelectableItemAria extends SelectableItemStates {
188
187
  * Handles interactions with an item in a selectable collection.
189
188
  */
190
189
  export function useSelectableItem(options: SelectableItemOptions): SelectableItemAria;
190
+ export class DOMLayoutDelegate implements LayoutDelegate {
191
+ constructor(ref: RefObject<HTMLElement>);
192
+ getItemRect(key: Key): Rect | null;
193
+ getContentSize(): Size;
194
+ getVisibleRect(): Rect;
195
+ }
191
196
  interface ListKeyboardDelegateOptions<T> {
192
197
  collection: Collection<Node<T>>;
193
- ref: RefObject<HTMLElement>;
198
+ ref: RefObject<HTMLElement | null>;
194
199
  collator?: Intl.Collator;
195
200
  layout?: 'stack' | 'grid';
196
201
  orientation?: Orientation;
197
202
  direction?: Direction;
198
203
  disabledKeys?: Set<Key>;
199
204
  disabledBehavior?: DisabledBehavior;
205
+ layoutDelegate?: LayoutDelegate;
200
206
  }
201
207
  export class ListKeyboardDelegate<T> implements KeyboardDelegate {
202
- constructor(collection: Collection<Node<T>>, disabledKeys: Set<Key>, ref: RefObject<HTMLElement>, collator?: Intl.Collator);
208
+ constructor(collection: Collection<Node<T>>, disabledKeys: Set<Key>, ref: RefObject<HTMLElement | null>, collator?: Intl.Collator);
203
209
  constructor(options: ListKeyboardDelegateOptions<T>);
204
210
  getNextKey(key: Key): Key;
205
211
  getPreviousKey(key: Key): Key;
@@ -222,6 +228,12 @@ export interface AriaSelectableListOptions extends Omit<AriaSelectableCollection
222
228
  * A delegate object that implements behavior for keyboard focus movement.
223
229
  */
224
230
  keyboardDelegate?: KeyboardDelegate;
231
+ /**
232
+ * A delegate object that provides layout information for items in the collection.
233
+ * By default this uses the DOM, but this can be overridden to implement things like
234
+ * virtualized scrolling.
235
+ */
236
+ layoutDelegate?: LayoutDelegate;
225
237
  /**
226
238
  * The item keys that are disabled. These items cannot be selected, focused, or otherwise interacted with.
227
239
  */
@@ -1 +1 @@
1
- {"mappings":";;;ACqBA;IACE;;OAEG;IACH,gBAAgB,EAAE,gBAAgB,CAAC;IACnC;;OAEG;IACH,gBAAgB,EAAE,wBAAwB,CAAC;IAC3C;;OAEG;IACH,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAA;CAClC;AAED;IACE;;OAEG;IACH,eAAe,EAAE,aAAa,CAAA;CAC/B;AAED;;GAEG;AACH,8BAA8B,OAAO,EAAE,qBAAqB,GAAG,cAAc,CAuD5E;AC9ED;IACE;;OAEG;IACH,gBAAgB,EAAE,wBAAwB,CAAC;IAC3C;;OAEG;IACH,gBAAgB,EAAE,gBAAgB,CAAC;IACnC;;OAEG;IACH,GAAG,EAAE,UAAU,WAAW,CAAC,CAAC;IAC5B;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,GAAG,aAAa,CAAC;IACpC;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;OAGG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;OAEG;IACH,qBAAqB,CAAC,EAAE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0CAA2C,SAAQ,IAAI,CAAC,+BAA+B,EAAE,kBAAkB,CAAC;IAC1G;;OAEG;IACH,UAAU,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC;IACtC;;OAEG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC;;OAEG;IACH,YAAY,EAAE,GAAG,CAAC,GAAG,CAAC,CAAA;CACvB;AAED;IACE;;OAEG;IACH,SAAS,EAAE,aAAa,CAAA;CACzB;AAED;;GAEG;AACH,kCAAkC,KAAK,EAAE,yBAAyB,GAAG,kBAAkB,CAiCtF","sources":["packages/@react-aria/selection/src/packages/@react-aria/selection/src/utils.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/useTypeSelect.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/useSelectableCollection.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/useSelectableItem.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/ListKeyboardDelegate.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/useSelectableList.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/index.ts","packages/@react-aria/selection/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useSelectableCollection} from './useSelectableCollection';\nexport {useSelectableItem} from './useSelectableItem';\nexport {useSelectableList} from './useSelectableList';\nexport {ListKeyboardDelegate} from './ListKeyboardDelegate';\nexport {useTypeSelect} from './useTypeSelect';\n\nexport type {AriaSelectableCollectionOptions, SelectableCollectionAria} from './useSelectableCollection';\nexport type {AriaSelectableListOptions, SelectableListAria} from './useSelectableList';\nexport type {SelectableItemOptions, SelectableItemStates, SelectableItemAria} from './useSelectableItem';\nexport type {AriaTypeSelectOptions, TypeSelectAria} from './useTypeSelect';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
1
+ {"mappings":";;ACqBA;IACE;;OAEG;IACH,gBAAgB,EAAE,gBAAgB,CAAC;IACnC;;OAEG;IACH,gBAAgB,EAAE,wBAAwB,CAAC;IAC3C;;OAEG;IACH,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAA;CAClC;AAED;IACE;;OAEG;IACH,eAAe,EAAE,aAAa,CAAA;CAC/B;AAED;;GAEG;AACH,8BAA8B,OAAO,EAAE,qBAAqB,GAAG,cAAc,CAuD5E;AC9ED;IACE;;OAEG;IACH,gBAAgB,EAAE,wBAAwB,CAAC;IAC3C;;OAEG;IACH,gBAAgB,EAAE,gBAAgB,CAAC;IACnC;;OAEG;IACH,GAAG,EAAE,UAAU,WAAW,GAAG,IAAI,CAAC,CAAC;IACnC;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,GAAG,aAAa,CAAC;IACpC;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;OAGG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;OAEG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC;;OAEG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;OAGG;IACH,SAAS,CAAC,EAAE,UAAU,WAAW,GAAG,IAAI,CAAC,CAAC;IAC1C;;;;;;OAMG;IACH,YAAY,C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AM,EAAE,OAAO,CAAC,EAAE,GAAG;CAmB9C;AC7QD,0CAA2C,SAAQ,IAAI,CAAC,+BAA+B,EAAE,kBAAkB,CAAC;IAC1G;;OAEG;IACH,UAAU,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC;IACtC;;OAEG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC;;;;OAIG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC;;OAEG;IACH,YAAY,EAAE,GAAG,CAAC,GAAG,CAAC,CAAA;CACvB;AAED;IACE;;OAEG;IACH,SAAS,EAAE,aAAa,CAAA;CACzB;AAED;;GAEG;AACH,kCAAkC,KAAK,EAAE,yBAAyB,GAAG,kBAAkB,CAmCtF","sources":["packages/@react-aria/selection/src/packages/@react-aria/selection/src/utils.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/useTypeSelect.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/useSelectableCollection.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/useSelectableItem.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/DOMLayoutDelegate.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/ListKeyboardDelegate.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/useSelectableList.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/index.ts","packages/@react-aria/selection/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useSelectableCollection} from './useSelectableCollection';\nexport {useSelectableItem} from './useSelectableItem';\nexport {useSelectableList} from './useSelectableList';\nexport {ListKeyboardDelegate} from './ListKeyboardDelegate';\nexport {DOMLayoutDelegate} from './DOMLayoutDelegate';\nexport {useTypeSelect} from './useTypeSelect';\n\nexport type {AriaSelectableCollectionOptions, SelectableCollectionAria} from './useSelectableCollection';\nexport type {AriaSelectableListOptions, SelectableListAria} from './useSelectableList';\nexport type {SelectableItemOptions, SelectableItemStates, SelectableItemAria} from './useSelectableItem';\nexport type {AriaTypeSelectOptions, TypeSelectAria} from './useTypeSelect';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
@@ -168,6 +168,7 @@ function $b6837c2f80a3c32f$export$d6daf82dcd84e87c(options) {
168
168
  }
169
169
  };
170
170
  // Store the scroll position so we can restore it later.
171
+ /// TODO: should this happen all the time??
171
172
  let scrollPos = (0, $bT8Bh$react.useRef)({
172
173
  top: 0,
173
174
  left: 0
@@ -206,7 +207,7 @@ function $b6837c2f80a3c32f$export$d6daf82dcd84e87c(options) {
206
207
  scrollRef.current.scrollTop = scrollPos.current.top;
207
208
  scrollRef.current.scrollLeft = scrollPos.current.left;
208
209
  }
209
- if (!isVirtualized && manager.focusedKey != null) {
210
+ if (manager.focusedKey != null) {
210
211
  // Refocus and scroll the focused item into view if it exists within the scrollable region.
211
212
  let element = scrollRef.current.querySelector(`[data-key="${CSS.escape(manager.focusedKey.toString())}"]`);
212
213
  if (element) {
@@ -245,15 +246,17 @@ function $b6837c2f80a3c32f$export$d6daf82dcd84e87c(options) {
245
246
  }
246
247
  // eslint-disable-next-line react-hooks/exhaustive-deps
247
248
  }, []);
248
- // If not virtualized, scroll the focused element into view when the focusedKey changes.
249
- // When virtualized, Virtualizer handles this internally.
249
+ // Scroll the focused element into view when the focusedKey changes.
250
250
  let lastFocusedKey = (0, $bT8Bh$react.useRef)(manager.focusedKey);
251
251
  (0, $bT8Bh$react.useEffect)(()=>{
252
- let modality = (0, $bT8Bh$reactariainteractions.getInteractionModality)();
253
- if (manager.isFocused && manager.focusedKey != null && (scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current)) {
254
- let element = scrollRef.current.querySelector(`[data-key="${CSS.escape(manager.focusedKey.toString())}"]`);
255
- if (element && (modality === 'keyboard' || autoFocusRef.current)) {
256
- if (!isVirtualized) (0, $bT8Bh$reactariautils.scrollIntoView)(scrollRef.current, element);
252
+ if (manager.isFocused && manager.focusedKey != null && (manager.focusedKey !== lastFocusedKey.current || autoFocusRef.current) && (scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current)) {
253
+ let modality = (0, $bT8Bh$reactariainteractions.getInteractionModality)();
254
+ let element = ref.current.querySelector(`[data-key="${CSS.escape(manager.focusedKey.toString())}"]`);
255
+ if (!element) // If item element wasn't found, return early (don't update autoFocusRef and lastFocusedKey).
256
+ // The collection may initially be empty (e.g. virtualizer), so wait until the element exists.
257
+ return;
258
+ if (modality === 'keyboard' || autoFocusRef.current) {
259
+ (0, $bT8Bh$reactariautils.scrollIntoView)(scrollRef.current, element);
257
260
  // Avoid scroll in iOS VO, since it may cause overlay to close (i.e. RAC submenu)
258
261
  if (modality !== 'virtual') (0, $bT8Bh$reactariautils.scrollIntoViewport)(element, {
259
262
  containingElement: ref.current
@@ -264,13 +267,12 @@ function $b6837c2f80a3c32f$export$d6daf82dcd84e87c(options) {
264
267
  if (manager.isFocused && manager.focusedKey == null && lastFocusedKey.current != null) (0, $bT8Bh$reactariafocus.focusSafely)(ref.current);
265
268
  lastFocusedKey.current = manager.focusedKey;
266
269
  autoFocusRef.current = false;
267
- }, [
268
- isVirtualized,
269
- scrollRef,
270
- manager.focusedKey,
271
- manager.isFocused,
272
- ref
273
- ]);
270
+ });
271
+ // Intercept FocusScope restoration since virtualized collections can reuse DOM nodes.
272
+ (0, $bT8Bh$reactariautils.useEvent)(ref, 'react-aria-focus-scope-restore', (e)=>{
273
+ e.preventDefault();
274
+ manager.setFocused(true);
275
+ });
274
276
  let handlers = {
275
277
  onKeyDown: onKeyDown,
276
278
  onFocus: onFocus,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CAAC,eACH,CAAA,GAAA,oCAAa,EAAE,UAAU,OAAO,EAAE;gBAEpC,iFAAiF;gBACjF,IAAI,aAAa,WACf,CAAA,GAAA,wCAAiB,EAAE,SAAS;oBAAC,mBAAmB,IAAI,OAAO;gBAAA;YAE/D;QACF;QAEA,+FAA+F;QAC/F,IAAI,QAAQ,SAAS,IAAI,QAAQ,UAAU,IAAI,QAAQ,eAAe,OAAO,IAAI,MAC/E,CAAA,GAAA,iCAAU,EAAE,IAAI,OAAO;QAGzB,eAAe,OAAO,GAAG,QAAQ,UAAU;QAC3C,aAAa,OAAO,GAAG;IACzB,GAAG;QAAC;QAAe;QAAW,QAAQ,UAAU;QAAE,QAAQ,SAAS;QAAE;KAAI;IAEzE,IAAI,WAAW;mBACb;iBACA;gBACA;QACA,aAAY,CAAC;YACX,8CAA8C;YAC9C,IAAI,UAAU,OAAO,KAAK,EAAE,MAAM,EAChC,wEAAwE;YACxE,EAAE,cAAc;QAEpB;IACF;IAEA,IAAI,mBAAC,eAAe,EAAC,GAAG,CAAA,GAAA,uCAAY,EAAE;QACpC,kBAAkB;QAClB,kBAAkB;IACpB;IAEA,IAAI,CAAC,mBACH,WAAW,CAAA,GAAA,gCAAS,EAAE,iBAAiB;IAGzC,oFAAoF;IACpF,+FAA+F;IAC/F,8FAA8F;IAC9F,gDAAgD;IAChD,IAAI;IACJ,IAAI,CAAC,uBACH,WAAW,QAAQ,UAAU,IAAI,OAAO,IAAI;IAG9C,OAAO;QACL,iBAAiB;YACf,GAAG,QAAQ;sBACX;QACF;IACF;AACF","sources":["packages/@react-aria/selection/src/useSelectableCollection.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {DOMAttributes, FocusableElement, FocusStrategy, Key, KeyboardDelegate} from '@react-types/shared';\nimport {flushSync} from 'react-dom';\nimport {FocusEvent, KeyboardEvent, RefObject, useEffect, useRef} from 'react';\nimport {focusSafely, getFocusableTreeWalker} from '@react-aria/focus';\nimport {focusWithoutScrolling, mergeProps, scrollIntoView, scrollIntoViewport, useEvent, useRouter} from '@react-aria/utils';\nimport {getInteractionModality} from '@react-aria/interactions';\nimport {isCtrlKeyPressed, isNonContiguousSelectionModifier} from './utils';\nimport {MultipleSelectionManager} from '@react-stately/selection';\nimport {useLocale} from '@react-aria/i18n';\nimport {useTypeSelect} from './useTypeSelect';\n\nexport interface AriaSelectableCollectionOptions {\n /**\n * An interface for reading and updating multiple selection state.\n */\n selectionManager: MultipleSelectionManager,\n /**\n * A delegate object that implements behavior for keyboard focus movement.\n */\n keyboardDelegate: KeyboardDelegate,\n /**\n * The ref attached to the element representing the collection.\n */\n ref: RefObject<HTMLElement>,\n /**\n * Whether the collection or one of its items should be automatically focused upon render.\n * @default false\n */\n autoFocus?: boolean | FocusStrategy,\n /**\n * Whether focus should wrap around when the end/start is reached.\n * @default false\n */\n shouldFocusWrap?: boolean,\n /**\n * Whether the collection allows empty selection.\n * @default false\n */\n disallowEmptySelection?: boolean,\n /**\n * Whether the collection allows the user to select all items via keyboard shortcut.\n * @default false\n */\n disallowSelectAll?: boolean,\n /**\n * Whether selection should occur automatically on focus.\n * @default false\n */\n selectOnFocus?: boolean,\n /**\n * Whether typeahead is disabled.\n * @default false\n */\n disallowTypeAhead?: boolean,\n /**\n * Whether the collection items should use virtual focus instead of being focused directly.\n */\n shouldUseVirtualFocus?: boolean,\n /**\n * Whether navigation through tab key is enabled.\n */\n allowsTabNavigation?: boolean,\n /**\n * Whether the collection items are contained in a virtual scroller.\n */\n isVirtualized?: boolean,\n /**\n * The ref attached to the scrollable body. Used to provide automatic scrolling on item focus for non-virtualized collections.\n * If not provided, defaults to the collection ref.\n */\n scrollRef?: RefObject<HTMLElement>,\n /**\n * The behavior of links in the collection.\n * - 'action': link behaves like onAction.\n * - 'selection': link follows selection interactions (e.g. if URL drives selection).\n * - 'override': links override all other interactions (link items are not selectable).\n * @default 'action'\n */\n linkBehavior?: 'action' | 'selection' | 'override'\n}\n\nexport interface SelectableCollectionAria {\n /** Props for the collection element. */\n collectionProps: DOMAttributes\n}\n\n/**\n * Handles interactions with selectable collections.\n */\nexport function useSelectableCollection(options: AriaSelectableCollectionOptions): SelectableCollectionAria {\n let {\n selectionManager: manager,\n keyboardDelegate: delegate,\n ref,\n autoFocus = false,\n shouldFocusWrap = false,\n disallowEmptySelection = false,\n disallowSelectAll = false,\n selectOnFocus = manager.selectionBehavior === 'replace',\n disallowTypeAhead = false,\n shouldUseVirtualFocus,\n allowsTabNavigation = false,\n isVirtualized,\n // If no scrollRef is provided, assume the collection ref is the scrollable region\n scrollRef = ref,\n linkBehavior = 'action'\n } = options;\n let {direction} = useLocale();\n let router = useRouter();\n\n let onKeyDown = (e: KeyboardEvent) => {\n // Prevent option + tab from doing anything since it doesn't move focus to the cells, only buttons/checkboxes\n if (e.altKey && e.key === 'Tab') {\n e.preventDefault();\n }\n\n // Keyboard events bubble through portals. Don't handle keyboard events\n // for elements outside the collection (e.g. menus).\n if (!ref.current.contains(e.target as Element)) {\n return;\n }\n\n const navigateToKey = (key: Key | undefined, childFocus?: FocusStrategy) => {\n if (key != null) {\n if (manager.isLink(key) && linkBehavior === 'selection' && selectOnFocus && !isNonContiguousSelectionModifier(e)) {\n // Set focused key and re-render synchronously to bring item into view if needed.\n flushSync(() => {\n manager.setFocusedKey(key, childFocus);\n });\n\n let item = scrollRef.current.querySelector(`[data-key=\"${CSS.escape(key.toString())}\"]`);\n let itemProps = manager.getItemProps(key);\n router.open(item, e, itemProps.href, itemProps.routerOptions);\n\n return;\n }\n\n manager.setFocusedKey(key, childFocus);\n\n if (manager.isLink(key) && linkBehavior === 'override') {\n return;\n }\n\n if (e.shiftKey && manager.selectionMode === 'multiple') {\n manager.extendSelection(key);\n } else if (selectOnFocus && !isNonContiguousSelectionModifier(e)) {\n manager.replaceSelection(key);\n }\n }\n };\n\n switch (e.key) {\n case 'ArrowDown': {\n if (delegate.getKeyBelow) {\n e.preventDefault();\n let nextKey = manager.focusedKey != null\n ? delegate.getKeyBelow(manager.focusedKey)\n : delegate.getFirstKey?.();\n if (nextKey == null && shouldFocusWrap) {\n nextKey = delegate.getFirstKey?.(manager.focusedKey);\n }\n navigateToKey(nextKey);\n }\n break;\n }\n case 'ArrowUp': {\n if (delegate.getKeyAbove) {\n e.preventDefault();\n let nextKey = manager.focusedKey != null\n ? delegate.getKeyAbove(manager.focusedKey)\n : delegate.getLastKey?.();\n if (nextKey == null && shouldFocusWrap) {\n nextKey = delegate.getLastKey?.(manager.focusedKey);\n }\n navigateToKey(nextKey);\n }\n break;\n }\n case 'ArrowLeft': {\n if (delegate.getKeyLeftOf) {\n e.preventDefault();\n let nextKey = delegate.getKeyLeftOf(manager.focusedKey);\n if (nextKey == null && shouldFocusWrap) {\n nextKey = direction === 'rtl' ? delegate.getFirstKey?.(manager.focusedKey) : delegate.getLastKey?.(manager.focusedKey);\n }\n navigateToKey(nextKey, direction === 'rtl' ? 'first' : 'last');\n }\n break;\n }\n case 'ArrowRight': {\n if (delegate.getKeyRightOf) {\n e.preventDefault();\n let nextKey = delegate.getKeyRightOf(manager.focusedKey);\n if (nextKey == null && shouldFocusWrap) {\n nextKey = direction === 'rtl' ? delegate.getLastKey?.(manager.focusedKey) : delegate.getFirstKey?.(manager.focusedKey);\n }\n navigateToKey(nextKey, direction === 'rtl' ? 'last' : 'first');\n }\n break;\n }\n case 'Home':\n if (delegate.getFirstKey) {\n e.preventDefault();\n let firstKey = delegate.getFirstKey(manager.focusedKey, isCtrlKeyPressed(e));\n manager.setFocusedKey(firstKey);\n if (isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {\n manager.extendSelection(firstKey);\n } else if (selectOnFocus) {\n manager.replaceSelection(firstKey);\n }\n }\n break;\n case 'End':\n if (delegate.getLastKey) {\n e.preventDefault();\n let lastKey = delegate.getLastKey(manager.focusedKey, isCtrlKeyPressed(e));\n manager.setFocusedKey(lastKey);\n if (isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {\n manager.extendSelection(lastKey);\n } else if (selectOnFocus) {\n manager.replaceSelection(lastKey);\n }\n }\n break;\n case 'PageDown':\n if (delegate.getKeyPageBelow) {\n e.preventDefault();\n let nextKey = delegate.getKeyPageBelow(manager.focusedKey);\n navigateToKey(nextKey);\n }\n break;\n case 'PageUp':\n if (delegate.getKeyPageAbove) {\n e.preventDefault();\n let nextKey = delegate.getKeyPageAbove(manager.focusedKey);\n navigateToKey(nextKey);\n }\n break;\n case 'a':\n if (isCtrlKeyPressed(e) && manager.selectionMode === 'multiple' && disallowSelectAll !== true) {\n e.preventDefault();\n manager.selectAll();\n }\n break;\n case 'Escape':\n if (!disallowEmptySelection && manager.selectedKeys.size !== 0) {\n e.stopPropagation();\n e.preventDefault();\n manager.clearSelection();\n }\n break;\n case 'Tab': {\n if (!allowsTabNavigation) {\n // There may be elements that are \"tabbable\" inside a collection (e.g. in a grid cell).\n // However, collections should be treated as a single tab stop, with arrow key navigation internally.\n // We don't control the rendering of these, so we can't override the tabIndex to prevent tabbing.\n // Instead, we handle the Tab key, and move focus manually to the first/last tabbable element\n // in the collection, so that the browser default behavior will apply starting from that element\n // rather than the currently focused one.\n if (e.shiftKey) {\n ref.current.focus();\n } else {\n let walker = getFocusableTreeWalker(ref.current, {tabbable: true});\n let next: FocusableElement;\n let last: FocusableElement;\n do {\n last = walker.lastChild() as FocusableElement;\n if (last) {\n next = last;\n }\n } while (last);\n\n if (next && !next.contains(document.activeElement)) {\n focusWithoutScrolling(next);\n }\n }\n break;\n }\n }\n }\n };\n\n // Store the scroll position so we can restore it later.\n let scrollPos = useRef({top: 0, left: 0});\n useEvent(scrollRef, 'scroll', isVirtualized ? null : () => {\n scrollPos.current = {\n top: scrollRef.current.scrollTop,\n left: scrollRef.current.scrollLeft\n };\n });\n\n let onFocus = (e: FocusEvent) => {\n if (manager.isFocused) {\n // If a focus event bubbled through a portal, reset focus state.\n if (!e.currentTarget.contains(e.target)) {\n manager.setFocused(false);\n }\n\n return;\n }\n\n // Focus events can bubble through portals. Ignore these events.\n if (!e.currentTarget.contains(e.target)) {\n return;\n }\n\n manager.setFocused(true);\n\n if (manager.focusedKey == null) {\n let navigateToFirstKey = (key: Key | undefined) => {\n if (key != null) {\n manager.setFocusedKey(key);\n if (selectOnFocus) {\n manager.replaceSelection(key);\n }\n }\n };\n // If the user hasn't yet interacted with the collection, there will be no focusedKey set.\n // Attempt to detect whether the user is tabbing forward or backward into the collection\n // and either focus the first or last item accordingly.\n let relatedTarget = e.relatedTarget as Element;\n if (relatedTarget && (e.currentTarget.compareDocumentPosition(relatedTarget) & Node.DOCUMENT_POSITION_FOLLOWING)) {\n navigateToFirstKey(manager.lastSelectedKey ?? delegate.getLastKey());\n } else {\n navigateToFirstKey(manager.firstSelectedKey ?? delegate.getFirstKey());\n }\n } else if (!isVirtualized) {\n // Restore the scroll position to what it was before.\n scrollRef.current.scrollTop = scrollPos.current.top;\n scrollRef.current.scrollLeft = scrollPos.current.left;\n }\n\n if (!isVirtualized && manager.focusedKey != null) {\n // Refocus and scroll the focused item into view if it exists within the scrollable region.\n let element = scrollRef.current.querySelector(`[data-key=\"${CSS.escape(manager.focusedKey.toString())}\"]`) as HTMLElement;\n if (element) {\n // This prevents a flash of focus on the first/last element in the collection, or the collection itself.\n if (!element.contains(document.activeElement)) {\n focusWithoutScrolling(element);\n }\n\n let modality = getInteractionModality();\n if (modality === 'keyboard') {\n scrollIntoViewport(element, {containingElement: ref.current});\n }\n }\n }\n };\n\n let onBlur = (e) => {\n // Don't set blurred and then focused again if moving focus within the collection.\n if (!e.currentTarget.contains(e.relatedTarget as HTMLElement)) {\n manager.setFocused(false);\n }\n };\n\n const autoFocusRef = useRef(autoFocus);\n useEffect(() => {\n if (autoFocusRef.current) {\n let focusedKey = null;\n\n // Check focus strategy to determine which item to focus\n if (autoFocus === 'first') {\n focusedKey = delegate.getFirstKey();\n } if (autoFocus === 'last') {\n focusedKey = delegate.getLastKey();\n }\n\n // If there are any selected keys, make the first one the new focus target\n let selectedKeys = manager.selectedKeys;\n if (selectedKeys.size) {\n for (let key of selectedKeys) {\n if (manager.canSelectItem(key)) {\n focusedKey = key;\n break;\n }\n }\n }\n\n manager.setFocused(true);\n manager.setFocusedKey(focusedKey);\n\n // If no default focus key is selected, focus the collection itself.\n if (focusedKey == null && !shouldUseVirtualFocus) {\n focusSafely(ref.current);\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // If not virtualized, scroll the focused element into view when the focusedKey changes.\n // When virtualized, Virtualizer handles this internally.\n let lastFocusedKey = useRef(manager.focusedKey);\n useEffect(() => {\n let modality = getInteractionModality();\n if (manager.isFocused && manager.focusedKey != null && scrollRef?.current) {\n let element = scrollRef.current.querySelector(`[data-key=\"${CSS.escape(manager.focusedKey.toString())}\"]`) as HTMLElement;\n if (element && (modality === 'keyboard' || autoFocusRef.current)) {\n if (!isVirtualized) {\n scrollIntoView(scrollRef.current, element);\n }\n // Avoid scroll in iOS VO, since it may cause overlay to close (i.e. RAC submenu)\n if (modality !== 'virtual') {\n scrollIntoViewport(element, {containingElement: ref.current});\n }\n }\n }\n\n // If the focused key becomes null (e.g. the last item is deleted), focus the whole collection.\n if (manager.isFocused && manager.focusedKey == null && lastFocusedKey.current != null) {\n focusSafely(ref.current);\n }\n\n lastFocusedKey.current = manager.focusedKey;\n autoFocusRef.current = false;\n }, [isVirtualized, scrollRef, manager.focusedKey, manager.isFocused, ref]);\n\n let handlers = {\n onKeyDown,\n onFocus,\n onBlur,\n onMouseDown(e) {\n // Ignore events that bubbled through portals.\n if (scrollRef.current === e.target) {\n // Prevent focus going to the collection when clicking on the scrollbar.\n e.preventDefault();\n }\n }\n };\n\n let {typeSelectProps} = useTypeSelect({\n keyboardDelegate: delegate,\n selectionManager: manager\n });\n\n if (!disallowTypeAhead) {\n handlers = mergeProps(typeSelectProps, handlers);\n }\n\n // If nothing is focused within the collection, make the collection itself tabbable.\n // This will be marshalled to either the first or last item depending on where focus came from.\n // If using virtual focus, don't set a tabIndex at all so that VoiceOver on iOS 14 doesn't try\n // to move real DOM focus to the element anyway.\n let tabIndex: number;\n if (!shouldUseVirtualFocus) {\n tabIndex = manager.focusedKey == null ? 0 : -1;\n }\n\n return {\n collectionProps: {\n ...handlers,\n tabIndex\n }\n };\n}\n"],"names":[],"version":3,"file":"useSelectableCollection.main.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;AA2FM,SAAS,0CAAwB,OAAwC;IAC9E,IAAI,EACF,kBAAkB,OAAO,EACzB,kBAAkB,QAAQ,OAC1B,GAAG,aACH,YAAY,wBACZ,kBAAkB,+BAClB,yBAAyB,0BACzB,oBAAoB,sBACpB,gBAAgB,QAAQ,iBAAiB,KAAK,8BAC9C,oBAAoB,8BACpB,qBAAqB,uBACrB,sBAAsB,sBACtB,aAAa,aACb,kFAAkF;IAClF,YAAY,mBACZ,eAAe,UAChB,GAAG;IACJ,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,8BAAQ;IAC1B,IAAI,SAAS,CAAA,GAAA,+BAAQ;IAErB,IAAI,YAAY,CAAC;QACf,6GAA6G;QAC7G,IAAI,EAAE,MAAM,IAAI,EAAE,GAAG,KAAK,OACxB,EAAE,cAAc;QAGlB,uEAAuE;QACvE,oDAAoD;QACpD,IAAI,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,EAAE,MAAM,GAChC;QAGF,MAAM,gBAAgB,CAAC,KAAsB;YAC3C,IAAI,OAAO,MAAM;gBACf,IAAI,QAAQ,MAAM,CAAC,QAAQ,iBAAiB,eAAe,i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C,kBAAkB;QAClB,kBAAkB;IACpB;IAEA,IAAI,CAAC,mBACH,WAAW,CAAA,GAAA,gCAAS,EAAE,iBAAiB;IAGzC,oFAAoF;IACpF,+FAA+F;IAC/F,8FAA8F;IAC9F,gDAAgD;IAChD,IAAI;IACJ,IAAI,CAAC,uBACH,WAAW,QAAQ,UAAU,IAAI,OAAO,IAAI;IAG9C,OAAO;QACL,iBAAiB;YACf,GAAG,QAAQ;sBACX;QACF;IACF;AACF","sources":["packages/@react-aria/selection/src/useSelectableCollection.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {DOMAttributes, FocusableElement, FocusStrategy, Key, KeyboardDelegate, RefObject} from '@react-types/shared';\nimport {flushSync} from 'react-dom';\nimport {FocusEvent, KeyboardEvent, useEffect, useRef} from 'react';\nimport {focusSafely, getFocusableTreeWalker} from '@react-aria/focus';\nimport {focusWithoutScrolling, mergeProps, scrollIntoView, scrollIntoViewport, useEvent, useRouter} from '@react-aria/utils';\nimport {getInteractionModality} from '@react-aria/interactions';\nimport {isCtrlKeyPressed, isNonContiguousSelectionModifier} from './utils';\nimport {MultipleSelectionManager} from '@react-stately/selection';\nimport {useLocale} from '@react-aria/i18n';\nimport {useTypeSelect} from './useTypeSelect';\n\nexport interface AriaSelectableCollectionOptions {\n /**\n * An interface for reading and updating multiple selection state.\n */\n selectionManager: MultipleSelectionManager,\n /**\n * A delegate object that implements behavior for keyboard focus movement.\n */\n keyboardDelegate: KeyboardDelegate,\n /**\n * The ref attached to the element representing the collection.\n */\n ref: RefObject<HTMLElement | null>,\n /**\n * Whether the collection or one of its items should be automatically focused upon render.\n * @default false\n */\n autoFocus?: boolean | FocusStrategy,\n /**\n * Whether focus should wrap around when the end/start is reached.\n * @default false\n */\n shouldFocusWrap?: boolean,\n /**\n * Whether the collection allows empty selection.\n * @default false\n */\n disallowEmptySelection?: boolean,\n /**\n * Whether the collection allows the user to select all items via keyboard shortcut.\n * @default false\n */\n disallowSelectAll?: boolean,\n /**\n * Whether selection should occur automatically on focus.\n * @default false\n */\n selectOnFocus?: boolean,\n /**\n * Whether typeahead is disabled.\n * @default false\n */\n disallowTypeAhead?: boolean,\n /**\n * Whether the collection items should use virtual focus instead of being focused directly.\n */\n shouldUseVirtualFocus?: boolean,\n /**\n * Whether navigation through tab key is enabled.\n */\n allowsTabNavigation?: boolean,\n /**\n * Whether the collection items are contained in a virtual scroller.\n */\n isVirtualized?: boolean,\n /**\n * The ref attached to the scrollable body. Used to provide automatic scrolling on item focus for non-virtualized collections.\n * If not provided, defaults to the collection ref.\n */\n scrollRef?: RefObject<HTMLElement | null>,\n /**\n * The behavior of links in the collection.\n * - 'action': link behaves like onAction.\n * - 'selection': link follows selection interactions (e.g. if URL drives selection).\n * - 'override': links override all other interactions (link items are not selectable).\n * @default 'action'\n */\n linkBehavior?: 'action' | 'selection' | 'override'\n}\n\nexport interface SelectableCollectionAria {\n /** Props for the collection element. */\n collectionProps: DOMAttributes\n}\n\n/**\n * Handles interactions with selectable collections.\n */\nexport function useSelectableCollection(options: AriaSelectableCollectionOptions): SelectableCollectionAria {\n let {\n selectionManager: manager,\n keyboardDelegate: delegate,\n ref,\n autoFocus = false,\n shouldFocusWrap = false,\n disallowEmptySelection = false,\n disallowSelectAll = false,\n selectOnFocus = manager.selectionBehavior === 'replace',\n disallowTypeAhead = false,\n shouldUseVirtualFocus,\n allowsTabNavigation = false,\n isVirtualized,\n // If no scrollRef is provided, assume the collection ref is the scrollable region\n scrollRef = ref,\n linkBehavior = 'action'\n } = options;\n let {direction} = useLocale();\n let router = useRouter();\n\n let onKeyDown = (e: KeyboardEvent) => {\n // Prevent option + tab from doing anything since it doesn't move focus to the cells, only buttons/checkboxes\n if (e.altKey && e.key === 'Tab') {\n e.preventDefault();\n }\n\n // Keyboard events bubble through portals. Don't handle keyboard events\n // for elements outside the collection (e.g. menus).\n if (!ref.current.contains(e.target as Element)) {\n return;\n }\n\n const navigateToKey = (key: Key | undefined, childFocus?: FocusStrategy) => {\n if (key != null) {\n if (manager.isLink(key) && linkBehavior === 'selection' && selectOnFocus && !isNonContiguousSelectionModifier(e)) {\n // Set focused key and re-render synchronously to bring item into view if needed.\n flushSync(() => {\n manager.setFocusedKey(key, childFocus);\n });\n\n let item = scrollRef.current.querySelector(`[data-key=\"${CSS.escape(key.toString())}\"]`);\n let itemProps = manager.getItemProps(key);\n router.open(item, e, itemProps.href, itemProps.routerOptions);\n\n return;\n }\n\n manager.setFocusedKey(key, childFocus);\n\n if (manager.isLink(key) && linkBehavior === 'override') {\n return;\n }\n\n if (e.shiftKey && manager.selectionMode === 'multiple') {\n manager.extendSelection(key);\n } else if (selectOnFocus && !isNonContiguousSelectionModifier(e)) {\n manager.replaceSelection(key);\n }\n }\n };\n\n switch (e.key) {\n case 'ArrowDown': {\n if (delegate.getKeyBelow) {\n e.preventDefault();\n let nextKey = manager.focusedKey != null\n ? delegate.getKeyBelow(manager.focusedKey)\n : delegate.getFirstKey?.();\n if (nextKey == null && shouldFocusWrap) {\n nextKey = delegate.getFirstKey?.(manager.focusedKey);\n }\n navigateToKey(nextKey);\n }\n break;\n }\n case 'ArrowUp': {\n if (delegate.getKeyAbove) {\n e.preventDefault();\n let nextKey = manager.focusedKey != null\n ? delegate.getKeyAbove(manager.focusedKey)\n : delegate.getLastKey?.();\n if (nextKey == null && shouldFocusWrap) {\n nextKey = delegate.getLastKey?.(manager.focusedKey);\n }\n navigateToKey(nextKey);\n }\n break;\n }\n case 'ArrowLeft': {\n if (delegate.getKeyLeftOf) {\n e.preventDefault();\n let nextKey = delegate.getKeyLeftOf(manager.focusedKey);\n if (nextKey == null && shouldFocusWrap) {\n nextKey = direction === 'rtl' ? delegate.getFirstKey?.(manager.focusedKey) : delegate.getLastKey?.(manager.focusedKey);\n }\n navigateToKey(nextKey, direction === 'rtl' ? 'first' : 'last');\n }\n break;\n }\n case 'ArrowRight': {\n if (delegate.getKeyRightOf) {\n e.preventDefault();\n let nextKey = delegate.getKeyRightOf(manager.focusedKey);\n if (nextKey == null && shouldFocusWrap) {\n nextKey = direction === 'rtl' ? delegate.getLastKey?.(manager.focusedKey) : delegate.getFirstKey?.(manager.focusedKey);\n }\n navigateToKey(nextKey, direction === 'rtl' ? 'last' : 'first');\n }\n break;\n }\n case 'Home':\n if (delegate.getFirstKey) {\n e.preventDefault();\n let firstKey = delegate.getFirstKey(manager.focusedKey, isCtrlKeyPressed(e));\n manager.setFocusedKey(firstKey);\n if (isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {\n manager.extendSelection(firstKey);\n } else if (selectOnFocus) {\n manager.replaceSelection(firstKey);\n }\n }\n break;\n case 'End':\n if (delegate.getLastKey) {\n e.preventDefault();\n let lastKey = delegate.getLastKey(manager.focusedKey, isCtrlKeyPressed(e));\n manager.setFocusedKey(lastKey);\n if (isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {\n manager.extendSelection(lastKey);\n } else if (selectOnFocus) {\n manager.replaceSelection(lastKey);\n }\n }\n break;\n case 'PageDown':\n if (delegate.getKeyPageBelow) {\n e.preventDefault();\n let nextKey = delegate.getKeyPageBelow(manager.focusedKey);\n navigateToKey(nextKey);\n }\n break;\n case 'PageUp':\n if (delegate.getKeyPageAbove) {\n e.preventDefault();\n let nextKey = delegate.getKeyPageAbove(manager.focusedKey);\n navigateToKey(nextKey);\n }\n break;\n case 'a':\n if (isCtrlKeyPressed(e) && manager.selectionMode === 'multiple' && disallowSelectAll !== true) {\n e.preventDefault();\n manager.selectAll();\n }\n break;\n case 'Escape':\n if (!disallowEmptySelection && manager.selectedKeys.size !== 0) {\n e.stopPropagation();\n e.preventDefault();\n manager.clearSelection();\n }\n break;\n case 'Tab': {\n if (!allowsTabNavigation) {\n // There may be elements that are \"tabbable\" inside a collection (e.g. in a grid cell).\n // However, collections should be treated as a single tab stop, with arrow key navigation internally.\n // We don't control the rendering of these, so we can't override the tabIndex to prevent tabbing.\n // Instead, we handle the Tab key, and move focus manually to the first/last tabbable element\n // in the collection, so that the browser default behavior will apply starting from that element\n // rather than the currently focused one.\n if (e.shiftKey) {\n ref.current.focus();\n } else {\n let walker = getFocusableTreeWalker(ref.current, {tabbable: true});\n let next: FocusableElement;\n let last: FocusableElement;\n do {\n last = walker.lastChild() as FocusableElement;\n if (last) {\n next = last;\n }\n } while (last);\n\n if (next && !next.contains(document.activeElement)) {\n focusWithoutScrolling(next);\n }\n }\n break;\n }\n }\n }\n };\n\n // Store the scroll position so we can restore it later.\n /// TODO: should this happen all the time??\n let scrollPos = useRef({top: 0, left: 0});\n useEvent(scrollRef, 'scroll', isVirtualized ? null : () => {\n scrollPos.current = {\n top: scrollRef.current.scrollTop,\n left: scrollRef.current.scrollLeft\n };\n });\n\n let onFocus = (e: FocusEvent) => {\n if (manager.isFocused) {\n // If a focus event bubbled through a portal, reset focus state.\n if (!e.currentTarget.contains(e.target)) {\n manager.setFocused(false);\n }\n\n return;\n }\n\n // Focus events can bubble through portals. Ignore these events.\n if (!e.currentTarget.contains(e.target)) {\n return;\n }\n\n manager.setFocused(true);\n\n if (manager.focusedKey == null) {\n let navigateToFirstKey = (key: Key | undefined) => {\n if (key != null) {\n manager.setFocusedKey(key);\n if (selectOnFocus) {\n manager.replaceSelection(key);\n }\n }\n };\n // If the user hasn't yet interacted with the collection, there will be no focusedKey set.\n // Attempt to detect whether the user is tabbing forward or backward into the collection\n // and either focus the first or last item accordingly.\n let relatedTarget = e.relatedTarget as Element;\n if (relatedTarget && (e.currentTarget.compareDocumentPosition(relatedTarget) & Node.DOCUMENT_POSITION_FOLLOWING)) {\n navigateToFirstKey(manager.lastSelectedKey ?? delegate.getLastKey());\n } else {\n navigateToFirstKey(manager.firstSelectedKey ?? delegate.getFirstKey());\n }\n } else if (!isVirtualized) {\n // Restore the scroll position to what it was before.\n scrollRef.current.scrollTop = scrollPos.current.top;\n scrollRef.current.scrollLeft = scrollPos.current.left;\n }\n\n if (manager.focusedKey != null) {\n // Refocus and scroll the focused item into view if it exists within the scrollable region.\n let element = scrollRef.current.querySelector(`[data-key=\"${CSS.escape(manager.focusedKey.toString())}\"]`) as HTMLElement;\n if (element) {\n // This prevents a flash of focus on the first/last element in the collection, or the collection itself.\n if (!element.contains(document.activeElement)) {\n focusWithoutScrolling(element);\n }\n\n let modality = getInteractionModality();\n if (modality === 'keyboard') {\n scrollIntoViewport(element, {containingElement: ref.current});\n }\n }\n }\n };\n\n let onBlur = (e) => {\n // Don't set blurred and then focused again if moving focus within the collection.\n if (!e.currentTarget.contains(e.relatedTarget as HTMLElement)) {\n manager.setFocused(false);\n }\n };\n\n const autoFocusRef = useRef(autoFocus);\n useEffect(() => {\n if (autoFocusRef.current) {\n let focusedKey = null;\n\n // Check focus strategy to determine which item to focus\n if (autoFocus === 'first') {\n focusedKey = delegate.getFirstKey();\n } if (autoFocus === 'last') {\n focusedKey = delegate.getLastKey();\n }\n\n // If there are any selected keys, make the first one the new focus target\n let selectedKeys = manager.selectedKeys;\n if (selectedKeys.size) {\n for (let key of selectedKeys) {\n if (manager.canSelectItem(key)) {\n focusedKey = key;\n break;\n }\n }\n }\n\n manager.setFocused(true);\n manager.setFocusedKey(focusedKey);\n\n // If no default focus key is selected, focus the collection itself.\n if (focusedKey == null && !shouldUseVirtualFocus) {\n focusSafely(ref.current);\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // Scroll the focused element into view when the focusedKey changes.\n let lastFocusedKey = useRef(manager.focusedKey);\n useEffect(() => {\n if (manager.isFocused && manager.focusedKey != null && (manager.focusedKey !== lastFocusedKey.current || autoFocusRef.current) && scrollRef?.current) {\n let modality = getInteractionModality();\n let element = ref.current.querySelector(`[data-key=\"${CSS.escape(manager.focusedKey.toString())}\"]`) as HTMLElement;\n if (!element) {\n // If item element wasn't found, return early (don't update autoFocusRef and lastFocusedKey).\n // The collection may initially be empty (e.g. virtualizer), so wait until the element exists.\n return;\n }\n\n if (modality === 'keyboard' || autoFocusRef.current) {\n scrollIntoView(scrollRef.current, element);\n\n // Avoid scroll in iOS VO, since it may cause overlay to close (i.e. RAC submenu)\n if (modality !== 'virtual') {\n scrollIntoViewport(element, {containingElement: ref.current});\n }\n }\n }\n\n // If the focused key becomes null (e.g. the last item is deleted), focus the whole collection.\n if (manager.isFocused && manager.focusedKey == null && lastFocusedKey.current != null) {\n focusSafely(ref.current);\n }\n\n lastFocusedKey.current = manager.focusedKey;\n autoFocusRef.current = false;\n });\n\n // Intercept FocusScope restoration since virtualized collections can reuse DOM nodes.\n useEvent(ref, 'react-aria-focus-scope-restore', e => {\n e.preventDefault();\n manager.setFocused(true);\n });\n\n let handlers = {\n onKeyDown,\n onFocus,\n onBlur,\n onMouseDown(e) {\n // Ignore events that bubbled through portals.\n if (scrollRef.current === e.target) {\n // Prevent focus going to the collection when clicking on the scrollbar.\n e.preventDefault();\n }\n }\n };\n\n let {typeSelectProps} = useTypeSelect({\n keyboardDelegate: delegate,\n selectionManager: manager\n });\n\n if (!disallowTypeAhead) {\n handlers = mergeProps(typeSelectProps, handlers);\n }\n\n // If nothing is focused within the collection, make the collection itself tabbable.\n // This will be marshalled to either the first or last item depending on where focus came from.\n // If using virtual focus, don't set a tabIndex at all so that VoiceOver on iOS 14 doesn't try\n // to move real DOM focus to the element anyway.\n let tabIndex: number;\n if (!shouldUseVirtualFocus) {\n tabIndex = manager.focusedKey == null ? 0 : -1;\n }\n\n return {\n collectionProps: {\n ...handlers,\n tabIndex\n }\n };\n}\n"],"names":[],"version":3,"file":"useSelectableCollection.main.js.map"}