@react-aria/grid 3.0.0-beta.1 → 3.0.0-nightly-4980928d3-240906

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (239) hide show
  1. package/dist/GridKeyboardDelegate.main.js +247 -0
  2. package/dist/GridKeyboardDelegate.main.js.map +1 -0
  3. package/dist/GridKeyboardDelegate.mjs +242 -0
  4. package/dist/GridKeyboardDelegate.module.js +242 -0
  5. package/dist/GridKeyboardDelegate.module.js.map +1 -0
  6. package/dist/ar-AE.main.js +15 -0
  7. package/dist/ar-AE.main.js.map +1 -0
  8. package/dist/ar-AE.mjs +17 -0
  9. package/dist/ar-AE.module.js +17 -0
  10. package/dist/ar-AE.module.js.map +1 -0
  11. package/dist/bg-BG.main.js +15 -0
  12. package/dist/bg-BG.main.js.map +1 -0
  13. package/dist/bg-BG.mjs +17 -0
  14. package/dist/bg-BG.module.js +17 -0
  15. package/dist/bg-BG.module.js.map +1 -0
  16. package/dist/cs-CZ.main.js +15 -0
  17. package/dist/cs-CZ.main.js.map +1 -0
  18. package/dist/cs-CZ.mjs +17 -0
  19. package/dist/cs-CZ.module.js +17 -0
  20. package/dist/cs-CZ.module.js.map +1 -0
  21. package/dist/da-DK.main.js +15 -0
  22. package/dist/da-DK.main.js.map +1 -0
  23. package/dist/da-DK.mjs +17 -0
  24. package/dist/da-DK.module.js +17 -0
  25. package/dist/da-DK.module.js.map +1 -0
  26. package/dist/de-DE.main.js +15 -0
  27. package/dist/de-DE.main.js.map +1 -0
  28. package/dist/de-DE.mjs +17 -0
  29. package/dist/de-DE.module.js +17 -0
  30. package/dist/de-DE.module.js.map +1 -0
  31. package/dist/el-GR.main.js +15 -0
  32. package/dist/el-GR.main.js.map +1 -0
  33. package/dist/el-GR.mjs +17 -0
  34. package/dist/el-GR.module.js +17 -0
  35. package/dist/el-GR.module.js.map +1 -0
  36. package/dist/en-US.main.js +15 -0
  37. package/dist/en-US.main.js.map +1 -0
  38. package/dist/en-US.mjs +17 -0
  39. package/dist/en-US.module.js +17 -0
  40. package/dist/en-US.module.js.map +1 -0
  41. package/dist/es-ES.main.js +15 -0
  42. package/dist/es-ES.main.js.map +1 -0
  43. package/dist/es-ES.mjs +17 -0
  44. package/dist/es-ES.module.js +17 -0
  45. package/dist/es-ES.module.js.map +1 -0
  46. package/dist/et-EE.main.js +15 -0
  47. package/dist/et-EE.main.js.map +1 -0
  48. package/dist/et-EE.mjs +17 -0
  49. package/dist/et-EE.module.js +17 -0
  50. package/dist/et-EE.module.js.map +1 -0
  51. package/dist/fi-FI.main.js +15 -0
  52. package/dist/fi-FI.main.js.map +1 -0
  53. package/dist/fi-FI.mjs +17 -0
  54. package/dist/fi-FI.module.js +17 -0
  55. package/dist/fi-FI.module.js.map +1 -0
  56. package/dist/fr-FR.main.js +15 -0
  57. package/dist/fr-FR.main.js.map +1 -0
  58. package/dist/fr-FR.mjs +17 -0
  59. package/dist/fr-FR.module.js +17 -0
  60. package/dist/fr-FR.module.js.map +1 -0
  61. package/dist/he-IL.main.js +15 -0
  62. package/dist/he-IL.main.js.map +1 -0
  63. package/dist/he-IL.mjs +17 -0
  64. package/dist/he-IL.module.js +17 -0
  65. package/dist/he-IL.module.js.map +1 -0
  66. package/dist/hr-HR.main.js +15 -0
  67. package/dist/hr-HR.main.js.map +1 -0
  68. package/dist/hr-HR.mjs +17 -0
  69. package/dist/hr-HR.module.js +17 -0
  70. package/dist/hr-HR.module.js.map +1 -0
  71. package/dist/hu-HU.main.js +15 -0
  72. package/dist/hu-HU.main.js.map +1 -0
  73. package/dist/hu-HU.mjs +17 -0
  74. package/dist/hu-HU.module.js +17 -0
  75. package/dist/hu-HU.module.js.map +1 -0
  76. package/dist/import.mjs +31 -0
  77. package/dist/intlStrings.main.js +108 -0
  78. package/dist/intlStrings.main.js.map +1 -0
  79. package/dist/intlStrings.mjs +110 -0
  80. package/dist/intlStrings.module.js +110 -0
  81. package/dist/intlStrings.module.js.map +1 -0
  82. package/dist/it-IT.main.js +15 -0
  83. package/dist/it-IT.main.js.map +1 -0
  84. package/dist/it-IT.mjs +17 -0
  85. package/dist/it-IT.module.js +17 -0
  86. package/dist/it-IT.module.js.map +1 -0
  87. package/dist/ja-JP.main.js +15 -0
  88. package/dist/ja-JP.main.js.map +1 -0
  89. package/dist/ja-JP.mjs +17 -0
  90. package/dist/ja-JP.module.js +17 -0
  91. package/dist/ja-JP.module.js.map +1 -0
  92. package/dist/ko-KR.main.js +15 -0
  93. package/dist/ko-KR.main.js.map +1 -0
  94. package/dist/ko-KR.mjs +17 -0
  95. package/dist/ko-KR.module.js +17 -0
  96. package/dist/ko-KR.module.js.map +1 -0
  97. package/dist/lt-LT.main.js +15 -0
  98. package/dist/lt-LT.main.js.map +1 -0
  99. package/dist/lt-LT.mjs +17 -0
  100. package/dist/lt-LT.module.js +17 -0
  101. package/dist/lt-LT.module.js.map +1 -0
  102. package/dist/lv-LV.main.js +15 -0
  103. package/dist/lv-LV.main.js.map +1 -0
  104. package/dist/lv-LV.mjs +17 -0
  105. package/dist/lv-LV.module.js +17 -0
  106. package/dist/lv-LV.module.js.map +1 -0
  107. package/dist/main.js +23 -823
  108. package/dist/main.js.map +1 -1
  109. package/dist/module.js +10 -773
  110. package/dist/module.js.map +1 -1
  111. package/dist/nb-NO.main.js +15 -0
  112. package/dist/nb-NO.main.js.map +1 -0
  113. package/dist/nb-NO.mjs +17 -0
  114. package/dist/nb-NO.module.js +17 -0
  115. package/dist/nb-NO.module.js.map +1 -0
  116. package/dist/nl-NL.main.js +15 -0
  117. package/dist/nl-NL.main.js.map +1 -0
  118. package/dist/nl-NL.mjs +17 -0
  119. package/dist/nl-NL.module.js +17 -0
  120. package/dist/nl-NL.module.js.map +1 -0
  121. package/dist/pl-PL.main.js +15 -0
  122. package/dist/pl-PL.main.js.map +1 -0
  123. package/dist/pl-PL.mjs +17 -0
  124. package/dist/pl-PL.module.js +17 -0
  125. package/dist/pl-PL.module.js.map +1 -0
  126. package/dist/pt-BR.main.js +15 -0
  127. package/dist/pt-BR.main.js.map +1 -0
  128. package/dist/pt-BR.mjs +17 -0
  129. package/dist/pt-BR.module.js +17 -0
  130. package/dist/pt-BR.module.js.map +1 -0
  131. package/dist/pt-PT.main.js +15 -0
  132. package/dist/pt-PT.main.js.map +1 -0
  133. package/dist/pt-PT.mjs +17 -0
  134. package/dist/pt-PT.module.js +17 -0
  135. package/dist/pt-PT.module.js.map +1 -0
  136. package/dist/ro-RO.main.js +15 -0
  137. package/dist/ro-RO.main.js.map +1 -0
  138. package/dist/ro-RO.mjs +17 -0
  139. package/dist/ro-RO.module.js +17 -0
  140. package/dist/ro-RO.module.js.map +1 -0
  141. package/dist/ru-RU.main.js +15 -0
  142. package/dist/ru-RU.main.js.map +1 -0
  143. package/dist/ru-RU.mjs +17 -0
  144. package/dist/ru-RU.module.js +17 -0
  145. package/dist/ru-RU.module.js.map +1 -0
  146. package/dist/sk-SK.main.js +15 -0
  147. package/dist/sk-SK.main.js.map +1 -0
  148. package/dist/sk-SK.mjs +17 -0
  149. package/dist/sk-SK.module.js +17 -0
  150. package/dist/sk-SK.module.js.map +1 -0
  151. package/dist/sl-SI.main.js +15 -0
  152. package/dist/sl-SI.main.js.map +1 -0
  153. package/dist/sl-SI.mjs +17 -0
  154. package/dist/sl-SI.module.js +17 -0
  155. package/dist/sl-SI.module.js.map +1 -0
  156. package/dist/sr-SP.main.js +15 -0
  157. package/dist/sr-SP.main.js.map +1 -0
  158. package/dist/sr-SP.mjs +17 -0
  159. package/dist/sr-SP.module.js +17 -0
  160. package/dist/sr-SP.module.js.map +1 -0
  161. package/dist/sv-SE.main.js +15 -0
  162. package/dist/sv-SE.main.js.map +1 -0
  163. package/dist/sv-SE.mjs +17 -0
  164. package/dist/sv-SE.module.js +17 -0
  165. package/dist/sv-SE.module.js.map +1 -0
  166. package/dist/tr-TR.main.js +15 -0
  167. package/dist/tr-TR.main.js.map +1 -0
  168. package/dist/tr-TR.mjs +17 -0
  169. package/dist/tr-TR.module.js +17 -0
  170. package/dist/tr-TR.module.js.map +1 -0
  171. package/dist/types.d.ts +114 -36
  172. package/dist/types.d.ts.map +1 -1
  173. package/dist/uk-UA.main.js +15 -0
  174. package/dist/uk-UA.main.js.map +1 -0
  175. package/dist/uk-UA.mjs +17 -0
  176. package/dist/uk-UA.module.js +17 -0
  177. package/dist/uk-UA.module.js.map +1 -0
  178. package/dist/useGrid.main.js +132 -0
  179. package/dist/useGrid.main.js.map +1 -0
  180. package/dist/useGrid.mjs +127 -0
  181. package/dist/useGrid.module.js +127 -0
  182. package/dist/useGrid.module.js.map +1 -0
  183. package/dist/useGridCell.main.js +220 -0
  184. package/dist/useGridCell.main.js.map +1 -0
  185. package/dist/useGridCell.mjs +215 -0
  186. package/dist/useGridCell.module.js +215 -0
  187. package/dist/useGridCell.module.js.map +1 -0
  188. package/dist/useGridRow.main.js +53 -0
  189. package/dist/useGridRow.main.js.map +1 -0
  190. package/dist/useGridRow.mjs +48 -0
  191. package/dist/useGridRow.module.js +48 -0
  192. package/dist/useGridRow.module.js.map +1 -0
  193. package/dist/useGridRowGroup.main.js +26 -0
  194. package/dist/useGridRowGroup.main.js.map +1 -0
  195. package/dist/useGridRowGroup.mjs +21 -0
  196. package/dist/useGridRowGroup.module.js +21 -0
  197. package/dist/useGridRowGroup.module.js.map +1 -0
  198. package/dist/useGridSelectionAnnouncement.main.js +94 -0
  199. package/dist/useGridSelectionAnnouncement.main.js.map +1 -0
  200. package/dist/useGridSelectionAnnouncement.mjs +89 -0
  201. package/dist/useGridSelectionAnnouncement.module.js +89 -0
  202. package/dist/useGridSelectionAnnouncement.module.js.map +1 -0
  203. package/dist/useGridSelectionCheckbox.main.js +39 -0
  204. package/dist/useGridSelectionCheckbox.main.js.map +1 -0
  205. package/dist/useGridSelectionCheckbox.mjs +34 -0
  206. package/dist/useGridSelectionCheckbox.module.js +34 -0
  207. package/dist/useGridSelectionCheckbox.module.js.map +1 -0
  208. package/dist/useHighlightSelectionDescription.main.js +55 -0
  209. package/dist/useHighlightSelectionDescription.main.js.map +1 -0
  210. package/dist/useHighlightSelectionDescription.mjs +50 -0
  211. package/dist/useHighlightSelectionDescription.module.js +50 -0
  212. package/dist/useHighlightSelectionDescription.module.js.map +1 -0
  213. package/dist/utils.main.js +20 -0
  214. package/dist/utils.main.js.map +1 -0
  215. package/dist/utils.mjs +15 -0
  216. package/dist/utils.module.js +15 -0
  217. package/dist/utils.module.js.map +1 -0
  218. package/dist/zh-CN.main.js +15 -0
  219. package/dist/zh-CN.main.js.map +1 -0
  220. package/dist/zh-CN.mjs +17 -0
  221. package/dist/zh-CN.module.js +17 -0
  222. package/dist/zh-CN.module.js.map +1 -0
  223. package/dist/zh-TW.main.js +15 -0
  224. package/dist/zh-TW.main.js.map +1 -0
  225. package/dist/zh-TW.mjs +17 -0
  226. package/dist/zh-TW.module.js +17 -0
  227. package/dist/zh-TW.module.js.map +1 -0
  228. package/package.json +23 -15
  229. package/src/GridKeyboardDelegate.ts +93 -83
  230. package/src/index.ts +17 -5
  231. package/src/useGrid.ts +77 -78
  232. package/src/useGridCell.ts +96 -46
  233. package/src/useGridRow.ts +32 -21
  234. package/src/useGridRowGroup.ts +3 -3
  235. package/src/useGridSelectionAnnouncement.ts +115 -0
  236. package/src/useGridSelectionCheckbox.ts +48 -0
  237. package/src/useHighlightSelectionDescription.ts +52 -0
  238. package/src/utils.ts +13 -3
  239. package/LICENSE +0 -201
@@ -0,0 +1,247 @@
1
+ var $iKGCm$reactariaselection = require("@react-aria/selection");
2
+ var $iKGCm$reactstatelycollections = require("@react-stately/collections");
3
+
4
+
5
+ function $parcel$export(e, n, v, s) {
6
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
7
+ }
8
+
9
+ $parcel$export(module.exports, "GridKeyboardDelegate", () => $3187c0e19200cb16$export$de9feff04fda126e);
10
+ /*
11
+ * Copyright 2020 Adobe. All rights reserved.
12
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
13
+ * you may not use this file except in compliance with the License. You may obtain a copy
14
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software distributed under
17
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
18
+ * OF ANY KIND, either express or implied. See the License for the specific language
19
+ * governing permissions and limitations under the License.
20
+ */
21
+
22
+ class $3187c0e19200cb16$export$de9feff04fda126e {
23
+ isCell(node) {
24
+ return node.type === 'cell';
25
+ }
26
+ isRow(node) {
27
+ return node.type === 'row' || node.type === 'item';
28
+ }
29
+ isDisabled(item) {
30
+ var _item_props;
31
+ return this.disabledBehavior === 'all' && (((_item_props = item.props) === null || _item_props === void 0 ? void 0 : _item_props.isDisabled) || this.disabledKeys.has(item.key));
32
+ }
33
+ findPreviousKey(fromKey, pred) {
34
+ let key = fromKey != null ? this.collection.getKeyBefore(fromKey) : this.collection.getLastKey();
35
+ while(key != null){
36
+ let item = this.collection.getItem(key);
37
+ if (!this.isDisabled(item) && (!pred || pred(item))) return key;
38
+ key = this.collection.getKeyBefore(key);
39
+ }
40
+ }
41
+ findNextKey(fromKey, pred) {
42
+ let key = fromKey != null ? this.collection.getKeyAfter(fromKey) : this.collection.getFirstKey();
43
+ while(key != null){
44
+ let item = this.collection.getItem(key);
45
+ if (!this.isDisabled(item) && (!pred || pred(item))) return key;
46
+ key = this.collection.getKeyAfter(key);
47
+ }
48
+ }
49
+ getKeyBelow(key) {
50
+ let startItem = this.collection.getItem(key);
51
+ if (!startItem) return;
52
+ // If focus was on a cell, start searching from the parent row
53
+ if (this.isCell(startItem)) key = startItem.parentKey;
54
+ // Find the next item
55
+ key = this.findNextKey(key, (item)=>item.type === 'item');
56
+ if (key != null) {
57
+ // If focus was on a cell, focus the cell with the same index in the next row.
58
+ if (this.isCell(startItem)) {
59
+ let item = this.collection.getItem(key);
60
+ return (0, $iKGCm$reactstatelycollections.getNthItem)((0, $iKGCm$reactstatelycollections.getChildNodes)(item, this.collection), startItem.index).key;
61
+ }
62
+ // Otherwise, focus the next row
63
+ if (this.focusMode === 'row') return key;
64
+ }
65
+ }
66
+ getKeyAbove(key) {
67
+ let startItem = this.collection.getItem(key);
68
+ if (!startItem) return;
69
+ // If focus is on a cell, start searching from the parent row
70
+ if (this.isCell(startItem)) key = startItem.parentKey;
71
+ // Find the previous item
72
+ key = this.findPreviousKey(key, (item)=>item.type === 'item');
73
+ if (key != null) {
74
+ // If focus was on a cell, focus the cell with the same index in the previous row.
75
+ if (this.isCell(startItem)) {
76
+ let item = this.collection.getItem(key);
77
+ return (0, $iKGCm$reactstatelycollections.getNthItem)((0, $iKGCm$reactstatelycollections.getChildNodes)(item, this.collection), startItem.index).key;
78
+ }
79
+ // Otherwise, focus the previous row
80
+ if (this.focusMode === 'row') return key;
81
+ }
82
+ }
83
+ getKeyRightOf(key) {
84
+ let item = this.collection.getItem(key);
85
+ if (!item) return;
86
+ // If focus is on a row, focus the first child cell.
87
+ if (this.isRow(item)) {
88
+ let children = (0, $iKGCm$reactstatelycollections.getChildNodes)(item, this.collection);
89
+ return this.direction === 'rtl' ? (0, $iKGCm$reactstatelycollections.getLastItem)(children).key : (0, $iKGCm$reactstatelycollections.getFirstItem)(children).key;
90
+ }
91
+ // If focus is on a cell, focus the next cell if any,
92
+ // otherwise focus the parent row.
93
+ if (this.isCell(item)) {
94
+ let parent = this.collection.getItem(item.parentKey);
95
+ let children = (0, $iKGCm$reactstatelycollections.getChildNodes)(parent, this.collection);
96
+ let next = this.direction === 'rtl' ? (0, $iKGCm$reactstatelycollections.getNthItem)(children, item.index - 1) : (0, $iKGCm$reactstatelycollections.getNthItem)(children, item.index + 1);
97
+ if (next) return next.key;
98
+ // focus row only if focusMode is set to row
99
+ if (this.focusMode === 'row') return item.parentKey;
100
+ return this.direction === 'rtl' ? this.getFirstKey(key) : this.getLastKey(key);
101
+ }
102
+ }
103
+ getKeyLeftOf(key) {
104
+ let item = this.collection.getItem(key);
105
+ if (!item) return;
106
+ // If focus is on a row, focus the last child cell.
107
+ if (this.isRow(item)) {
108
+ let children = (0, $iKGCm$reactstatelycollections.getChildNodes)(item, this.collection);
109
+ return this.direction === 'rtl' ? (0, $iKGCm$reactstatelycollections.getFirstItem)(children).key : (0, $iKGCm$reactstatelycollections.getLastItem)(children).key;
110
+ }
111
+ // If focus is on a cell, focus the previous cell if any,
112
+ // otherwise focus the parent row.
113
+ if (this.isCell(item)) {
114
+ let parent = this.collection.getItem(item.parentKey);
115
+ let children = (0, $iKGCm$reactstatelycollections.getChildNodes)(parent, this.collection);
116
+ let prev = this.direction === 'rtl' ? (0, $iKGCm$reactstatelycollections.getNthItem)(children, item.index + 1) : (0, $iKGCm$reactstatelycollections.getNthItem)(children, item.index - 1);
117
+ if (prev) return prev.key;
118
+ // focus row only if focusMode is set to row
119
+ if (this.focusMode === 'row') return item.parentKey;
120
+ return this.direction === 'rtl' ? this.getLastKey(key) : this.getFirstKey(key);
121
+ }
122
+ }
123
+ getFirstKey(key, global) {
124
+ let item;
125
+ if (key != null) {
126
+ item = this.collection.getItem(key);
127
+ if (!item) return;
128
+ // If global flag is not set, and a cell is currently focused,
129
+ // move focus to the first cell in the parent row.
130
+ if (this.isCell(item) && !global) {
131
+ let parent = this.collection.getItem(item.parentKey);
132
+ return (0, $iKGCm$reactstatelycollections.getFirstItem)((0, $iKGCm$reactstatelycollections.getChildNodes)(parent, this.collection)).key;
133
+ }
134
+ }
135
+ // Find the first row
136
+ key = this.findNextKey(null, (item)=>item.type === 'item');
137
+ // If global flag is set (or if focus mode is cell), focus the first cell in the first row.
138
+ if (key != null && item && this.isCell(item) && global || this.focusMode === 'cell') {
139
+ let item = this.collection.getItem(key);
140
+ key = (0, $iKGCm$reactstatelycollections.getFirstItem)((0, $iKGCm$reactstatelycollections.getChildNodes)(item, this.collection)).key;
141
+ }
142
+ // Otherwise, focus the row itself.
143
+ return key;
144
+ }
145
+ getLastKey(key, global) {
146
+ let item;
147
+ if (key != null) {
148
+ item = this.collection.getItem(key);
149
+ if (!item) return;
150
+ // If global flag is not set, and a cell is currently focused,
151
+ // move focus to the last cell in the parent row.
152
+ if (this.isCell(item) && !global) {
153
+ let parent = this.collection.getItem(item.parentKey);
154
+ let children = (0, $iKGCm$reactstatelycollections.getChildNodes)(parent, this.collection);
155
+ return (0, $iKGCm$reactstatelycollections.getLastItem)(children).key;
156
+ }
157
+ }
158
+ // Find the last row
159
+ key = this.findPreviousKey(null, (item)=>item.type === 'item');
160
+ // If global flag is set (or if focus mode is cell), focus the last cell in the last row.
161
+ if (key != null && item && this.isCell(item) && global || this.focusMode === 'cell') {
162
+ let item = this.collection.getItem(key);
163
+ let children = (0, $iKGCm$reactstatelycollections.getChildNodes)(item, this.collection);
164
+ key = (0, $iKGCm$reactstatelycollections.getLastItem)(children).key;
165
+ }
166
+ // Otherwise, focus the row itself.
167
+ return key;
168
+ }
169
+ getKeyPageAbove(key) {
170
+ let itemRect = this.layoutDelegate.getItemRect(key);
171
+ if (!itemRect) return null;
172
+ let pageY = Math.max(0, itemRect.y + itemRect.height - this.layoutDelegate.getVisibleRect().height);
173
+ while(itemRect && itemRect.y > pageY){
174
+ key = this.getKeyAbove(key);
175
+ itemRect = this.layoutDelegate.getItemRect(key);
176
+ }
177
+ return key;
178
+ }
179
+ getKeyPageBelow(key) {
180
+ let itemRect = this.layoutDelegate.getItemRect(key);
181
+ if (!itemRect) return null;
182
+ let pageHeight = this.layoutDelegate.getVisibleRect().height;
183
+ let pageY = Math.min(this.layoutDelegate.getContentSize().height, itemRect.y + pageHeight);
184
+ while(itemRect && itemRect.y + itemRect.height < pageY){
185
+ let nextKey = this.getKeyBelow(key);
186
+ // If nextKey is undefined, we've reached the last row already
187
+ if (nextKey == null) break;
188
+ itemRect = this.layoutDelegate.getItemRect(nextKey);
189
+ key = nextKey;
190
+ }
191
+ return key;
192
+ }
193
+ getKeyForSearch(search, fromKey) {
194
+ if (!this.collator) return null;
195
+ let collection = this.collection;
196
+ let key = fromKey !== null && fromKey !== void 0 ? fromKey : this.getFirstKey();
197
+ // If the starting key is a cell, search from its parent row.
198
+ let startItem = collection.getItem(key);
199
+ if (startItem.type === 'cell') key = startItem.parentKey;
200
+ let hasWrapped = false;
201
+ while(key != null){
202
+ let item = collection.getItem(key);
203
+ // check row text value for match
204
+ if (item.textValue) {
205
+ let substring = item.textValue.slice(0, search.length);
206
+ if (this.collator.compare(substring, search) === 0) {
207
+ if (this.isRow(item) && this.focusMode === 'cell') return (0, $iKGCm$reactstatelycollections.getFirstItem)((0, $iKGCm$reactstatelycollections.getChildNodes)(item, this.collection)).key;
208
+ return item.key;
209
+ }
210
+ }
211
+ key = this.findNextKey(key, (item)=>item.type === 'item');
212
+ // Wrap around when reaching the end of the collection
213
+ if (key == null && !hasWrapped) {
214
+ key = this.getFirstKey();
215
+ hasWrapped = true;
216
+ }
217
+ }
218
+ return null;
219
+ }
220
+ constructor(options){
221
+ this.collection = options.collection;
222
+ this.disabledKeys = options.disabledKeys;
223
+ this.disabledBehavior = options.disabledBehavior || 'all';
224
+ this.direction = options.direction;
225
+ this.collator = options.collator;
226
+ this.layoutDelegate = options.layoutDelegate || (options.layout ? new $3187c0e19200cb16$var$DeprecatedLayoutDelegate(options.layout) : new (0, $iKGCm$reactariaselection.DOMLayoutDelegate)(options.ref));
227
+ this.focusMode = options.focusMode || 'row';
228
+ }
229
+ }
230
+ class $3187c0e19200cb16$var$DeprecatedLayoutDelegate {
231
+ getContentSize() {
232
+ return this.layout.getContentSize();
233
+ }
234
+ getItemRect(key) {
235
+ var _this_layout_getLayoutInfo;
236
+ return ((_this_layout_getLayoutInfo = this.layout.getLayoutInfo(key)) === null || _this_layout_getLayoutInfo === void 0 ? void 0 : _this_layout_getLayoutInfo.rect) || null;
237
+ }
238
+ getVisibleRect() {
239
+ return this.layout.virtualizer.visibleRect;
240
+ }
241
+ constructor(layout){
242
+ this.layout = layout;
243
+ }
244
+ }
245
+
246
+
247
+ //# sourceMappingURL=GridKeyboardDelegate.main.js.map
@@ -0,0 +1 @@
1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*\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 {Direction, DisabledBehavior, Key, KeyboardDelegate, LayoutDelegate, Node, Rect, RefObject, Size} from '@react-types/shared';\nimport {DOMLayoutDelegate} from '@react-aria/selection';\nimport {getChildNodes, getFirstItem, getLastItem, getNthItem} from '@react-stately/collections';\nimport {GridCollection} from '@react-types/grid';\n\nexport interface GridKeyboardDelegateOptions<C> {\n collection: C,\n disabledKeys: Set<Key>,\n disabledBehavior?: DisabledBehavior,\n ref?: RefObject<HTMLElement | null>,\n direction: Direction,\n collator?: Intl.Collator,\n layoutDelegate?: LayoutDelegate,\n /** @deprecated - Use layoutDelegate instead. */\n layout?: DeprecatedLayout,\n focusMode?: 'row' | 'cell'\n}\n\nexport class GridKeyboardDelegate<T, C extends GridCollection<T>> implements KeyboardDelegate {\n collection: C;\n protected disabledKeys: Set<Key>;\n protected disabledBehavior: DisabledBehavior;\n protected direction: Direction;\n protected collator: Intl.Collator;\n protected layoutDelegate: LayoutDelegate;\n protected focusMode;\n\n constructor(options: GridKeyboardDelegateOptions<C>) {\n this.collection = options.collection;\n this.disabledKeys = options.disabledKeys;\n this.disabledBehavior = options.disabledBehavior || 'all';\n this.direction = options.direction;\n this.collator = options.collator;\n this.layoutDelegate = options.layoutDelegate || (options.layout ? new DeprecatedLayoutDelegate(options.layout) : new DOMLayoutDelegate(options.ref));\n this.focusMode = options.focusMode || 'row';\n }\n\n protected isCell(node: Node<T>) {\n return node.type === 'cell';\n }\n\n protected isRow(node: Node<T>) {\n return node.type === 'row' || node.type === 'item';\n }\n\n private isDisabled(item: Node<unknown>) {\n return this.disabledBehavior === 'all' && (item.props?.isDisabled || this.disabledKeys.has(item.key));\n }\n\n protected findPreviousKey(fromKey?: Key, pred?: (item: Node<T>) => boolean) {\n let key = fromKey != null\n ? this.collection.getKeyBefore(fromKey)\n : this.collection.getLastKey();\n\n while (key != null) {\n let item = this.collection.getItem(key);\n if (!this.isDisabled(item) && (!pred || pred(item))) {\n return key;\n }\n\n key = this.collection.getKeyBefore(key);\n }\n }\n\n protected findNextKey(fromKey?: Key, pred?: (item: Node<T>) => boolean) {\n let key = fromKey != null\n ? this.collection.getKeyAfter(fromKey)\n : this.collection.getFirstKey();\n\n while (key != null) {\n let item = this.collection.getItem(key);\n if (!this.isDisabled(item) && (!pred || pred(item))) {\n return key;\n }\n\n key = this.collection.getKeyAfter(key);\n }\n }\n\n getKeyBelow(key: Key) {\n let startItem = this.collection.getItem(key);\n if (!startItem) {\n return;\n }\n\n // If focus was on a cell, start searching from the parent row\n if (this.isCell(startItem)) {\n key = startItem.parentKey;\n }\n\n // Find the next item\n key = this.findNextKey(key, (item => item.type === 'item'));\n if (key != null) {\n // If focus was on a cell, focus the cell with the same index in the next row.\n if (this.isCell(startItem)) {\n let item = this.collection.getItem(key);\n return getNthItem(getChildNodes(item, this.collection), startItem.index).key;\n }\n\n // Otherwise, focus the next row\n if (this.focusMode === 'row') {\n return key;\n }\n }\n }\n\n getKeyAbove(key: Key) {\n let startItem = this.collection.getItem(key);\n if (!startItem) {\n return;\n }\n\n // If focus is on a cell, start searching from the parent row\n if (this.isCell(startItem)) {\n key = startItem.parentKey;\n }\n\n // Find the previous item\n key = this.findPreviousKey(key, item => item.type === 'item');\n if (key != null) {\n // If focus was on a cell, focus the cell with the same index in the previous row.\n if (this.isCell(startItem)) {\n let item = this.collection.getItem(key);\n return getNthItem(getChildNodes(item, this.collection), startItem.index).key;\n }\n\n // Otherwise, focus the previous row\n if (this.focusMode === 'row') {\n return key;\n }\n }\n }\n\n getKeyRightOf(key: Key) {\n let item = this.collection.getItem(key);\n if (!item) {\n return;\n }\n\n // If focus is on a row, focus the first child cell.\n if (this.isRow(item)) {\n let children = getChildNodes(item, this.collection);\n return this.direction === 'rtl'\n ? getLastItem(children).key\n : getFirstItem(children).key;\n }\n\n // If focus is on a cell, focus the next cell if any,\n // otherwise focus the parent row.\n if (this.isCell(item)) {\n let parent = this.collection.getItem(item.parentKey);\n let children = getChildNodes(parent, this.collection);\n let next = this.direction === 'rtl'\n ? getNthItem(children, item.index - 1)\n : getNthItem(children, item.index + 1);\n\n if (next) {\n return next.key;\n }\n\n // focus row only if focusMode is set to row\n if (this.focusMode === 'row') {\n return item.parentKey;\n }\n\n return this.direction === 'rtl' ? this.getFirstKey(key) : this.getLastKey(key);\n }\n }\n\n getKeyLeftOf(key: Key) {\n let item = this.collection.getItem(key);\n if (!item) {\n return;\n }\n\n // If focus is on a row, focus the last child cell.\n if (this.isRow(item)) {\n let children = getChildNodes(item, this.collection);\n return this.direction === 'rtl'\n ? getFirstItem(children).key\n : getLastItem(children).key;\n }\n\n // If focus is on a cell, focus the previous cell if any,\n // otherwise focus the parent row.\n if (this.isCell(item)) {\n let parent = this.collection.getItem(item.parentKey);\n let children = getChildNodes(parent, this.collection);\n let prev = this.direction === 'rtl'\n ? getNthItem(children, item.index + 1)\n : getNthItem(children, item.index - 1);\n\n if (prev) {\n return prev.key;\n }\n\n // focus row only if focusMode is set to row\n if (this.focusMode === 'row') {\n return item.parentKey;\n }\n\n return this.direction === 'rtl' ? this.getLastKey(key) : this.getFirstKey(key);\n }\n }\n\n getFirstKey(key?: Key, global?: boolean) {\n let item: Node<T>;\n if (key != null) {\n item = this.collection.getItem(key);\n if (!item) {\n return;\n }\n\n // If global flag is not set, and a cell is currently focused,\n // move focus to the first cell in the parent row.\n if (this.isCell(item) && !global) {\n let parent = this.collection.getItem(item.parentKey);\n return getFirstItem(getChildNodes(parent, this.collection)).key;\n }\n }\n\n // Find the first row\n key = this.findNextKey(null, item => item.type === 'item');\n\n // If global flag is set (or if focus mode is cell), focus the first cell in the first row.\n if ((key != null && item && this.isCell(item) && global) || this.focusMode === 'cell') {\n let item = this.collection.getItem(key);\n key = getFirstItem(getChildNodes(item, this.collection)).key;\n }\n\n // Otherwise, focus the row itself.\n return key;\n }\n\n getLastKey(key?: Key, global?: boolean) {\n let item: Node<T>;\n if (key != null) {\n item = this.collection.getItem(key);\n if (!item) {\n return;\n }\n\n // If global flag is not set, and a cell is currently focused,\n // move focus to the last cell in the parent row.\n if (this.isCell(item) && !global) {\n let parent = this.collection.getItem(item.parentKey);\n let children = getChildNodes(parent, this.collection);\n return getLastItem(children).key;\n }\n }\n\n // Find the last row\n key = this.findPreviousKey(null, item => item.type === 'item');\n\n // If global flag is set (or if focus mode is cell), focus the last cell in the last row.\n if ((key != null && item && this.isCell(item) && global) || this.focusMode === 'cell') {\n let item = this.collection.getItem(key);\n let children = getChildNodes(item, this.collection);\n key = getLastItem(children).key;\n }\n\n // Otherwise, focus the row itself.\n return key;\n }\n\n getKeyPageAbove(key: Key) {\n let itemRect = this.layoutDelegate.getItemRect(key);\n if (!itemRect) {\n return null;\n }\n\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 = this.layoutDelegate.getItemRect(key);\n }\n\n return key;\n }\n\n getKeyPageBelow(key: Key) {\n let itemRect = this.layoutDelegate.getItemRect(key);\n\n if (!itemRect) {\n return null;\n }\n\n let pageHeight = this.layoutDelegate.getVisibleRect().height;\n let pageY = Math.min(this.layoutDelegate.getContentSize().height, itemRect.y + pageHeight);\n\n while (itemRect && (itemRect.y + itemRect.height) < pageY) {\n let nextKey = this.getKeyBelow(key);\n // If nextKey is undefined, we've reached the last row already\n if (nextKey == null) {\n break;\n }\n\n itemRect = this.layoutDelegate.getItemRect(nextKey);\n key = nextKey;\n }\n\n return key;\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\n // If the starting key is a cell, search from its parent row.\n let startItem = collection.getItem(key);\n if (startItem.type === 'cell') {\n key = startItem.parentKey;\n }\n\n let hasWrapped = false;\n while (key != null) {\n let item = collection.getItem(key);\n\n // check row text value for match\n if (item.textValue) {\n let substring = item.textValue.slice(0, search.length);\n if (this.collator.compare(substring, search) === 0) {\n if (this.isRow(item) && this.focusMode === 'cell') {\n return getFirstItem(getChildNodes(item, this.collection)).key;\n }\n\n return item.key;\n }\n }\n\n key = this.findNextKey(key, item => item.type === 'item');\n\n // Wrap around when reaching the end of the collection\n if (key == null && !hasWrapped) {\n key = this.getFirstKey();\n hasWrapped = true;\n }\n }\n\n return null;\n }\n}\n\n/* Backward compatibility for old Virtualizer Layout interface. */\ninterface DeprecatedLayout {\n getLayoutInfo(key: Key): DeprecatedLayoutInfo,\n getContentSize(): Size,\n virtualizer: DeprecatedVirtualizer\n}\n\ninterface DeprecatedLayoutInfo {\n rect: Rect\n}\n\ninterface DeprecatedVirtualizer {\n visibleRect: Rect\n}\n\nclass DeprecatedLayoutDelegate implements LayoutDelegate {\n layout: DeprecatedLayout;\n\n constructor(layout: DeprecatedLayout) {\n this.layout = layout;\n }\n\n getContentSize(): Size {\n return this.layout.getContentSize();\n }\n\n getItemRect(key: Key): Rect | null {\n return this.layout.getLayoutInfo(key)?.rect || null;\n }\n\n getVisibleRect(): Rect {\n return this.layout.virtualizer.visibleRect;\n }\n}\n"],"names":[],"version":3,"file":"GridKeyboardDelegate.main.js.map"}
@@ -0,0 +1,242 @@
1
+ import {DOMLayoutDelegate as $kbsd1$DOMLayoutDelegate} from "@react-aria/selection";
2
+ import {getNthItem as $kbsd1$getNthItem, getChildNodes as $kbsd1$getChildNodes, getLastItem as $kbsd1$getLastItem, getFirstItem as $kbsd1$getFirstItem} from "@react-stately/collections";
3
+
4
+ /*
5
+ * Copyright 2020 Adobe. All rights reserved.
6
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License. You may obtain a copy
8
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software distributed under
11
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12
+ * OF ANY KIND, either express or implied. See the License for the specific language
13
+ * governing permissions and limitations under the License.
14
+ */
15
+
16
+ class $d1c300d9c497e402$export$de9feff04fda126e {
17
+ isCell(node) {
18
+ return node.type === 'cell';
19
+ }
20
+ isRow(node) {
21
+ return node.type === 'row' || node.type === 'item';
22
+ }
23
+ isDisabled(item) {
24
+ var _item_props;
25
+ return this.disabledBehavior === 'all' && (((_item_props = item.props) === null || _item_props === void 0 ? void 0 : _item_props.isDisabled) || this.disabledKeys.has(item.key));
26
+ }
27
+ findPreviousKey(fromKey, pred) {
28
+ let key = fromKey != null ? this.collection.getKeyBefore(fromKey) : this.collection.getLastKey();
29
+ while(key != null){
30
+ let item = this.collection.getItem(key);
31
+ if (!this.isDisabled(item) && (!pred || pred(item))) return key;
32
+ key = this.collection.getKeyBefore(key);
33
+ }
34
+ }
35
+ findNextKey(fromKey, pred) {
36
+ let key = fromKey != null ? this.collection.getKeyAfter(fromKey) : this.collection.getFirstKey();
37
+ while(key != null){
38
+ let item = this.collection.getItem(key);
39
+ if (!this.isDisabled(item) && (!pred || pred(item))) return key;
40
+ key = this.collection.getKeyAfter(key);
41
+ }
42
+ }
43
+ getKeyBelow(key) {
44
+ let startItem = this.collection.getItem(key);
45
+ if (!startItem) return;
46
+ // If focus was on a cell, start searching from the parent row
47
+ if (this.isCell(startItem)) key = startItem.parentKey;
48
+ // Find the next item
49
+ key = this.findNextKey(key, (item)=>item.type === 'item');
50
+ if (key != null) {
51
+ // If focus was on a cell, focus the cell with the same index in the next row.
52
+ if (this.isCell(startItem)) {
53
+ let item = this.collection.getItem(key);
54
+ return (0, $kbsd1$getNthItem)((0, $kbsd1$getChildNodes)(item, this.collection), startItem.index).key;
55
+ }
56
+ // Otherwise, focus the next row
57
+ if (this.focusMode === 'row') return key;
58
+ }
59
+ }
60
+ getKeyAbove(key) {
61
+ let startItem = this.collection.getItem(key);
62
+ if (!startItem) return;
63
+ // If focus is on a cell, start searching from the parent row
64
+ if (this.isCell(startItem)) key = startItem.parentKey;
65
+ // Find the previous item
66
+ key = this.findPreviousKey(key, (item)=>item.type === 'item');
67
+ if (key != null) {
68
+ // If focus was on a cell, focus the cell with the same index in the previous row.
69
+ if (this.isCell(startItem)) {
70
+ let item = this.collection.getItem(key);
71
+ return (0, $kbsd1$getNthItem)((0, $kbsd1$getChildNodes)(item, this.collection), startItem.index).key;
72
+ }
73
+ // Otherwise, focus the previous row
74
+ if (this.focusMode === 'row') return key;
75
+ }
76
+ }
77
+ getKeyRightOf(key) {
78
+ let item = this.collection.getItem(key);
79
+ if (!item) return;
80
+ // If focus is on a row, focus the first child cell.
81
+ if (this.isRow(item)) {
82
+ let children = (0, $kbsd1$getChildNodes)(item, this.collection);
83
+ return this.direction === 'rtl' ? (0, $kbsd1$getLastItem)(children).key : (0, $kbsd1$getFirstItem)(children).key;
84
+ }
85
+ // If focus is on a cell, focus the next cell if any,
86
+ // otherwise focus the parent row.
87
+ if (this.isCell(item)) {
88
+ let parent = this.collection.getItem(item.parentKey);
89
+ let children = (0, $kbsd1$getChildNodes)(parent, this.collection);
90
+ let next = this.direction === 'rtl' ? (0, $kbsd1$getNthItem)(children, item.index - 1) : (0, $kbsd1$getNthItem)(children, item.index + 1);
91
+ if (next) return next.key;
92
+ // focus row only if focusMode is set to row
93
+ if (this.focusMode === 'row') return item.parentKey;
94
+ return this.direction === 'rtl' ? this.getFirstKey(key) : this.getLastKey(key);
95
+ }
96
+ }
97
+ getKeyLeftOf(key) {
98
+ let item = this.collection.getItem(key);
99
+ if (!item) return;
100
+ // If focus is on a row, focus the last child cell.
101
+ if (this.isRow(item)) {
102
+ let children = (0, $kbsd1$getChildNodes)(item, this.collection);
103
+ return this.direction === 'rtl' ? (0, $kbsd1$getFirstItem)(children).key : (0, $kbsd1$getLastItem)(children).key;
104
+ }
105
+ // If focus is on a cell, focus the previous cell if any,
106
+ // otherwise focus the parent row.
107
+ if (this.isCell(item)) {
108
+ let parent = this.collection.getItem(item.parentKey);
109
+ let children = (0, $kbsd1$getChildNodes)(parent, this.collection);
110
+ let prev = this.direction === 'rtl' ? (0, $kbsd1$getNthItem)(children, item.index + 1) : (0, $kbsd1$getNthItem)(children, item.index - 1);
111
+ if (prev) return prev.key;
112
+ // focus row only if focusMode is set to row
113
+ if (this.focusMode === 'row') return item.parentKey;
114
+ return this.direction === 'rtl' ? this.getLastKey(key) : this.getFirstKey(key);
115
+ }
116
+ }
117
+ getFirstKey(key, global) {
118
+ let item;
119
+ if (key != null) {
120
+ item = this.collection.getItem(key);
121
+ if (!item) return;
122
+ // If global flag is not set, and a cell is currently focused,
123
+ // move focus to the first cell in the parent row.
124
+ if (this.isCell(item) && !global) {
125
+ let parent = this.collection.getItem(item.parentKey);
126
+ return (0, $kbsd1$getFirstItem)((0, $kbsd1$getChildNodes)(parent, this.collection)).key;
127
+ }
128
+ }
129
+ // Find the first row
130
+ key = this.findNextKey(null, (item)=>item.type === 'item');
131
+ // If global flag is set (or if focus mode is cell), focus the first cell in the first row.
132
+ if (key != null && item && this.isCell(item) && global || this.focusMode === 'cell') {
133
+ let item = this.collection.getItem(key);
134
+ key = (0, $kbsd1$getFirstItem)((0, $kbsd1$getChildNodes)(item, this.collection)).key;
135
+ }
136
+ // Otherwise, focus the row itself.
137
+ return key;
138
+ }
139
+ getLastKey(key, global) {
140
+ let item;
141
+ if (key != null) {
142
+ item = this.collection.getItem(key);
143
+ if (!item) return;
144
+ // If global flag is not set, and a cell is currently focused,
145
+ // move focus to the last cell in the parent row.
146
+ if (this.isCell(item) && !global) {
147
+ let parent = this.collection.getItem(item.parentKey);
148
+ let children = (0, $kbsd1$getChildNodes)(parent, this.collection);
149
+ return (0, $kbsd1$getLastItem)(children).key;
150
+ }
151
+ }
152
+ // Find the last row
153
+ key = this.findPreviousKey(null, (item)=>item.type === 'item');
154
+ // If global flag is set (or if focus mode is cell), focus the last cell in the last row.
155
+ if (key != null && item && this.isCell(item) && global || this.focusMode === 'cell') {
156
+ let item = this.collection.getItem(key);
157
+ let children = (0, $kbsd1$getChildNodes)(item, this.collection);
158
+ key = (0, $kbsd1$getLastItem)(children).key;
159
+ }
160
+ // Otherwise, focus the row itself.
161
+ return key;
162
+ }
163
+ getKeyPageAbove(key) {
164
+ let itemRect = this.layoutDelegate.getItemRect(key);
165
+ if (!itemRect) return null;
166
+ let pageY = Math.max(0, itemRect.y + itemRect.height - this.layoutDelegate.getVisibleRect().height);
167
+ while(itemRect && itemRect.y > pageY){
168
+ key = this.getKeyAbove(key);
169
+ itemRect = this.layoutDelegate.getItemRect(key);
170
+ }
171
+ return key;
172
+ }
173
+ getKeyPageBelow(key) {
174
+ let itemRect = this.layoutDelegate.getItemRect(key);
175
+ if (!itemRect) return null;
176
+ let pageHeight = this.layoutDelegate.getVisibleRect().height;
177
+ let pageY = Math.min(this.layoutDelegate.getContentSize().height, itemRect.y + pageHeight);
178
+ while(itemRect && itemRect.y + itemRect.height < pageY){
179
+ let nextKey = this.getKeyBelow(key);
180
+ // If nextKey is undefined, we've reached the last row already
181
+ if (nextKey == null) break;
182
+ itemRect = this.layoutDelegate.getItemRect(nextKey);
183
+ key = nextKey;
184
+ }
185
+ return key;
186
+ }
187
+ getKeyForSearch(search, fromKey) {
188
+ if (!this.collator) return null;
189
+ let collection = this.collection;
190
+ let key = fromKey !== null && fromKey !== void 0 ? fromKey : this.getFirstKey();
191
+ // If the starting key is a cell, search from its parent row.
192
+ let startItem = collection.getItem(key);
193
+ if (startItem.type === 'cell') key = startItem.parentKey;
194
+ let hasWrapped = false;
195
+ while(key != null){
196
+ let item = collection.getItem(key);
197
+ // check row text value for match
198
+ if (item.textValue) {
199
+ let substring = item.textValue.slice(0, search.length);
200
+ if (this.collator.compare(substring, search) === 0) {
201
+ if (this.isRow(item) && this.focusMode === 'cell') return (0, $kbsd1$getFirstItem)((0, $kbsd1$getChildNodes)(item, this.collection)).key;
202
+ return item.key;
203
+ }
204
+ }
205
+ key = this.findNextKey(key, (item)=>item.type === 'item');
206
+ // Wrap around when reaching the end of the collection
207
+ if (key == null && !hasWrapped) {
208
+ key = this.getFirstKey();
209
+ hasWrapped = true;
210
+ }
211
+ }
212
+ return null;
213
+ }
214
+ constructor(options){
215
+ this.collection = options.collection;
216
+ this.disabledKeys = options.disabledKeys;
217
+ this.disabledBehavior = options.disabledBehavior || 'all';
218
+ this.direction = options.direction;
219
+ this.collator = options.collator;
220
+ this.layoutDelegate = options.layoutDelegate || (options.layout ? new $d1c300d9c497e402$var$DeprecatedLayoutDelegate(options.layout) : new (0, $kbsd1$DOMLayoutDelegate)(options.ref));
221
+ this.focusMode = options.focusMode || 'row';
222
+ }
223
+ }
224
+ class $d1c300d9c497e402$var$DeprecatedLayoutDelegate {
225
+ getContentSize() {
226
+ return this.layout.getContentSize();
227
+ }
228
+ getItemRect(key) {
229
+ var _this_layout_getLayoutInfo;
230
+ return ((_this_layout_getLayoutInfo = this.layout.getLayoutInfo(key)) === null || _this_layout_getLayoutInfo === void 0 ? void 0 : _this_layout_getLayoutInfo.rect) || null;
231
+ }
232
+ getVisibleRect() {
233
+ return this.layout.virtualizer.visibleRect;
234
+ }
235
+ constructor(layout){
236
+ this.layout = layout;
237
+ }
238
+ }
239
+
240
+
241
+ export {$d1c300d9c497e402$export$de9feff04fda126e as GridKeyboardDelegate};
242
+ //# sourceMappingURL=GridKeyboardDelegate.module.js.map