@react-aria/grid 3.10.5 → 3.11.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 (107) hide show
  1. package/dist/GridKeyboardDelegate.main.js +104 -43
  2. package/dist/GridKeyboardDelegate.main.js.map +1 -1
  3. package/dist/GridKeyboardDelegate.mjs +104 -43
  4. package/dist/GridKeyboardDelegate.module.js +104 -43
  5. package/dist/GridKeyboardDelegate.module.js.map +1 -1
  6. package/dist/ar-AE.main.js.map +1 -1
  7. package/dist/ar-AE.module.js.map +1 -1
  8. package/dist/bg-BG.main.js.map +1 -1
  9. package/dist/bg-BG.module.js.map +1 -1
  10. package/dist/cs-CZ.main.js.map +1 -1
  11. package/dist/cs-CZ.module.js.map +1 -1
  12. package/dist/da-DK.main.js.map +1 -1
  13. package/dist/da-DK.module.js.map +1 -1
  14. package/dist/de-DE.main.js.map +1 -1
  15. package/dist/de-DE.module.js.map +1 -1
  16. package/dist/el-GR.main.js.map +1 -1
  17. package/dist/el-GR.module.js.map +1 -1
  18. package/dist/en-US.main.js.map +1 -1
  19. package/dist/en-US.module.js.map +1 -1
  20. package/dist/es-ES.main.js.map +1 -1
  21. package/dist/es-ES.module.js.map +1 -1
  22. package/dist/et-EE.main.js.map +1 -1
  23. package/dist/et-EE.module.js.map +1 -1
  24. package/dist/fi-FI.main.js.map +1 -1
  25. package/dist/fi-FI.module.js.map +1 -1
  26. package/dist/fr-FR.main.js.map +1 -1
  27. package/dist/fr-FR.module.js.map +1 -1
  28. package/dist/he-IL.main.js.map +1 -1
  29. package/dist/he-IL.module.js.map +1 -1
  30. package/dist/hr-HR.main.js.map +1 -1
  31. package/dist/hr-HR.module.js.map +1 -1
  32. package/dist/hu-HU.main.js.map +1 -1
  33. package/dist/hu-HU.module.js.map +1 -1
  34. package/dist/it-IT.main.js.map +1 -1
  35. package/dist/it-IT.module.js.map +1 -1
  36. package/dist/ja-JP.main.js.map +1 -1
  37. package/dist/ja-JP.module.js.map +1 -1
  38. package/dist/ko-KR.main.js.map +1 -1
  39. package/dist/ko-KR.module.js.map +1 -1
  40. package/dist/lt-LT.main.js.map +1 -1
  41. package/dist/lt-LT.module.js.map +1 -1
  42. package/dist/lv-LV.main.js.map +1 -1
  43. package/dist/lv-LV.module.js.map +1 -1
  44. package/dist/nb-NO.main.js.map +1 -1
  45. package/dist/nb-NO.module.js.map +1 -1
  46. package/dist/nl-NL.main.js.map +1 -1
  47. package/dist/nl-NL.module.js.map +1 -1
  48. package/dist/pl-PL.main.js.map +1 -1
  49. package/dist/pl-PL.module.js.map +1 -1
  50. package/dist/pt-BR.main.js.map +1 -1
  51. package/dist/pt-BR.module.js.map +1 -1
  52. package/dist/pt-PT.main.js.map +1 -1
  53. package/dist/pt-PT.module.js.map +1 -1
  54. package/dist/ro-RO.main.js.map +1 -1
  55. package/dist/ro-RO.module.js.map +1 -1
  56. package/dist/ru-RU.main.js.map +1 -1
  57. package/dist/ru-RU.module.js.map +1 -1
  58. package/dist/sk-SK.main.js.map +1 -1
  59. package/dist/sk-SK.module.js.map +1 -1
  60. package/dist/sl-SI.main.js.map +1 -1
  61. package/dist/sl-SI.module.js.map +1 -1
  62. package/dist/sr-SP.main.js.map +1 -1
  63. package/dist/sr-SP.module.js.map +1 -1
  64. package/dist/sv-SE.main.js.map +1 -1
  65. package/dist/sv-SE.module.js.map +1 -1
  66. package/dist/tr-TR.main.js.map +1 -1
  67. package/dist/tr-TR.module.js.map +1 -1
  68. package/dist/types.d.ts +12 -12
  69. package/dist/types.d.ts.map +1 -1
  70. package/dist/uk-UA.main.js.map +1 -1
  71. package/dist/uk-UA.module.js.map +1 -1
  72. package/dist/useGrid.main.js +1 -1
  73. package/dist/useGrid.main.js.map +1 -1
  74. package/dist/useGrid.mjs +1 -1
  75. package/dist/useGrid.module.js +1 -1
  76. package/dist/useGrid.module.js.map +1 -1
  77. package/dist/useGridCell.main.js +27 -20
  78. package/dist/useGridCell.main.js.map +1 -1
  79. package/dist/useGridCell.mjs +27 -20
  80. package/dist/useGridCell.module.js +27 -20
  81. package/dist/useGridCell.module.js.map +1 -1
  82. package/dist/useGridRow.main.js +4 -1
  83. package/dist/useGridRow.main.js.map +1 -1
  84. package/dist/useGridRow.mjs +4 -1
  85. package/dist/useGridRow.module.js +4 -1
  86. package/dist/useGridRow.module.js.map +1 -1
  87. package/dist/useGridSelectionAnnouncement.main.js.map +1 -1
  88. package/dist/useGridSelectionAnnouncement.module.js.map +1 -1
  89. package/dist/useHighlightSelectionDescription.main.js +1 -1
  90. package/dist/useHighlightSelectionDescription.main.js.map +1 -1
  91. package/dist/useHighlightSelectionDescription.mjs +1 -1
  92. package/dist/useHighlightSelectionDescription.module.js +1 -1
  93. package/dist/useHighlightSelectionDescription.module.js.map +1 -1
  94. package/dist/utils.main.js.map +1 -1
  95. package/dist/utils.module.js.map +1 -1
  96. package/dist/zh-CN.main.js.map +1 -1
  97. package/dist/zh-CN.module.js.map +1 -1
  98. package/dist/zh-TW.main.js.map +1 -1
  99. package/dist/zh-TW.module.js.map +1 -1
  100. package/package.json +16 -16
  101. package/src/GridKeyboardDelegate.ts +120 -53
  102. package/src/useGrid.ts +1 -1
  103. package/src/useGridCell.ts +37 -33
  104. package/src/useGridRow.ts +2 -2
  105. package/src/useGridSelectionAnnouncement.ts +1 -1
  106. package/src/useHighlightSelectionDescription.ts +1 -1
  107. package/src/utils.ts +2 -2
@@ -28,149 +28,202 @@ class $d1c300d9c497e402$export$de9feff04fda126e {
28
28
  let key = fromKey != null ? this.collection.getKeyBefore(fromKey) : this.collection.getLastKey();
29
29
  while(key != null){
30
30
  let item = this.collection.getItem(key);
31
+ if (!item) return null;
31
32
  if (!this.isDisabled(item) && (!pred || pred(item))) return key;
32
33
  key = this.collection.getKeyBefore(key);
33
34
  }
35
+ return null;
34
36
  }
35
37
  findNextKey(fromKey, pred) {
36
38
  let key = fromKey != null ? this.collection.getKeyAfter(fromKey) : this.collection.getFirstKey();
37
39
  while(key != null){
38
40
  let item = this.collection.getItem(key);
41
+ if (!item) return null;
39
42
  if (!this.isDisabled(item) && (!pred || pred(item))) return key;
40
43
  key = this.collection.getKeyAfter(key);
44
+ if (key == null) return null;
41
45
  }
46
+ return null;
42
47
  }
43
- getKeyBelow(key) {
48
+ getKeyBelow(fromKey) {
49
+ let key = fromKey;
44
50
  let startItem = this.collection.getItem(key);
45
- if (!startItem) return;
51
+ if (!startItem) return null;
52
+ var _startItem_parentKey;
46
53
  // If focus was on a cell, start searching from the parent row
47
- if (this.isCell(startItem)) key = startItem.parentKey;
54
+ if (this.isCell(startItem)) key = (_startItem_parentKey = startItem.parentKey) !== null && _startItem_parentKey !== void 0 ? _startItem_parentKey : null;
55
+ if (key == null) return null;
48
56
  // Find the next item
49
57
  key = this.findNextKey(key, (item)=>item.type === 'item');
50
58
  if (key != null) {
51
59
  // If focus was on a cell, focus the cell with the same index in the next row.
52
60
  if (this.isCell(startItem)) {
61
+ var _getNthItem;
53
62
  let item = this.collection.getItem(key);
54
- return (0, $kbsd1$getNthItem)((0, $kbsd1$getChildNodes)(item, this.collection), startItem.index).key;
63
+ if (!item) return null;
64
+ var _startItem_index, _getNthItem_key;
65
+ return (_getNthItem_key = (_getNthItem = (0, $kbsd1$getNthItem)((0, $kbsd1$getChildNodes)(item, this.collection), (_startItem_index = startItem.index) !== null && _startItem_index !== void 0 ? _startItem_index : 0)) === null || _getNthItem === void 0 ? void 0 : _getNthItem.key) !== null && _getNthItem_key !== void 0 ? _getNthItem_key : null;
55
66
  }
56
67
  // Otherwise, focus the next row
57
68
  if (this.focusMode === 'row') return key;
58
69
  }
70
+ return null;
59
71
  }
60
- getKeyAbove(key) {
72
+ getKeyAbove(fromKey) {
73
+ let key = fromKey;
61
74
  let startItem = this.collection.getItem(key);
62
- if (!startItem) return;
75
+ if (!startItem) return null;
76
+ var _startItem_parentKey;
63
77
  // If focus is on a cell, start searching from the parent row
64
- if (this.isCell(startItem)) key = startItem.parentKey;
78
+ if (this.isCell(startItem)) key = (_startItem_parentKey = startItem.parentKey) !== null && _startItem_parentKey !== void 0 ? _startItem_parentKey : null;
79
+ if (key == null) return null;
65
80
  // Find the previous item
66
81
  key = this.findPreviousKey(key, (item)=>item.type === 'item');
67
82
  if (key != null) {
68
83
  // If focus was on a cell, focus the cell with the same index in the previous row.
69
84
  if (this.isCell(startItem)) {
85
+ var _getNthItem;
70
86
  let item = this.collection.getItem(key);
71
- return (0, $kbsd1$getNthItem)((0, $kbsd1$getChildNodes)(item, this.collection), startItem.index).key;
87
+ if (!item) return null;
88
+ var _startItem_index;
89
+ return ((_getNthItem = (0, $kbsd1$getNthItem)((0, $kbsd1$getChildNodes)(item, this.collection), (_startItem_index = startItem.index) !== null && _startItem_index !== void 0 ? _startItem_index : 0)) === null || _getNthItem === void 0 ? void 0 : _getNthItem.key) || null;
72
90
  }
73
91
  // Otherwise, focus the previous row
74
92
  if (this.focusMode === 'row') return key;
75
93
  }
94
+ return null;
76
95
  }
77
96
  getKeyRightOf(key) {
78
97
  let item = this.collection.getItem(key);
79
- if (!item) return;
98
+ if (!item) return null;
80
99
  // If focus is on a row, focus the first child cell.
81
100
  if (this.isRow(item)) {
101
+ var _getLastItem, _getFirstItem;
82
102
  let children = (0, $kbsd1$getChildNodes)(item, this.collection);
83
- return this.direction === 'rtl' ? (0, $kbsd1$getLastItem)(children).key : (0, $kbsd1$getFirstItem)(children).key;
103
+ var _ref;
104
+ return (_ref = this.direction === 'rtl' ? (_getLastItem = (0, $kbsd1$getLastItem)(children)) === null || _getLastItem === void 0 ? void 0 : _getLastItem.key : (_getFirstItem = (0, $kbsd1$getFirstItem)(children)) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key) !== null && _ref !== void 0 ? _ref : null;
84
105
  }
85
106
  // If focus is on a cell, focus the next cell if any,
86
107
  // otherwise focus the parent row.
87
- if (this.isCell(item)) {
108
+ if (this.isCell(item) && item.parentKey != null) {
88
109
  let parent = this.collection.getItem(item.parentKey);
110
+ if (!parent) return null;
89
111
  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;
112
+ var _ref1;
113
+ let next = (_ref1 = this.direction === 'rtl' ? (0, $kbsd1$getNthItem)(children, item.index - 1) : (0, $kbsd1$getNthItem)(children, item.index + 1)) !== null && _ref1 !== void 0 ? _ref1 : null;
114
+ var _next_key;
115
+ if (next) return (_next_key = next.key) !== null && _next_key !== void 0 ? _next_key : null;
116
+ var _item_parentKey;
92
117
  // 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);
118
+ if (this.focusMode === 'row') return (_item_parentKey = item.parentKey) !== null && _item_parentKey !== void 0 ? _item_parentKey : null;
119
+ var _ref2;
120
+ return (_ref2 = this.direction === 'rtl' ? this.getFirstKey(key) : this.getLastKey(key)) !== null && _ref2 !== void 0 ? _ref2 : null;
95
121
  }
122
+ return null;
96
123
  }
97
124
  getKeyLeftOf(key) {
98
125
  let item = this.collection.getItem(key);
99
- if (!item) return;
126
+ if (!item) return null;
100
127
  // If focus is on a row, focus the last child cell.
101
128
  if (this.isRow(item)) {
129
+ var _getFirstItem, _getLastItem;
102
130
  let children = (0, $kbsd1$getChildNodes)(item, this.collection);
103
- return this.direction === 'rtl' ? (0, $kbsd1$getFirstItem)(children).key : (0, $kbsd1$getLastItem)(children).key;
131
+ var _ref;
132
+ return (_ref = this.direction === 'rtl' ? (_getFirstItem = (0, $kbsd1$getFirstItem)(children)) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key : (_getLastItem = (0, $kbsd1$getLastItem)(children)) === null || _getLastItem === void 0 ? void 0 : _getLastItem.key) !== null && _ref !== void 0 ? _ref : null;
104
133
  }
105
134
  // If focus is on a cell, focus the previous cell if any,
106
135
  // otherwise focus the parent row.
107
- if (this.isCell(item)) {
136
+ if (this.isCell(item) && item.parentKey != null) {
108
137
  let parent = this.collection.getItem(item.parentKey);
138
+ if (!parent) return null;
109
139
  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;
140
+ var _ref1;
141
+ let prev = (_ref1 = this.direction === 'rtl' ? (0, $kbsd1$getNthItem)(children, item.index + 1) : (0, $kbsd1$getNthItem)(children, item.index - 1)) !== null && _ref1 !== void 0 ? _ref1 : null;
142
+ var _prev_key;
143
+ if (prev) return (_prev_key = prev.key) !== null && _prev_key !== void 0 ? _prev_key : null;
144
+ var _item_parentKey;
112
145
  // 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);
146
+ if (this.focusMode === 'row') return (_item_parentKey = item.parentKey) !== null && _item_parentKey !== void 0 ? _item_parentKey : null;
147
+ var _ref2;
148
+ return (_ref2 = this.direction === 'rtl' ? this.getLastKey(key) : this.getFirstKey(key)) !== null && _ref2 !== void 0 ? _ref2 : null;
115
149
  }
150
+ return null;
116
151
  }
117
- getFirstKey(key, global) {
152
+ getFirstKey(fromKey, global) {
153
+ let key = fromKey !== null && fromKey !== void 0 ? fromKey : null;
118
154
  let item;
119
155
  if (key != null) {
120
156
  item = this.collection.getItem(key);
121
- if (!item) return;
157
+ if (!item) return null;
122
158
  // If global flag is not set, and a cell is currently focused,
123
159
  // move focus to the first cell in the parent row.
124
- if (this.isCell(item) && !global) {
160
+ if (this.isCell(item) && !global && item.parentKey != null) {
161
+ var _getFirstItem;
125
162
  let parent = this.collection.getItem(item.parentKey);
126
- return (0, $kbsd1$getFirstItem)((0, $kbsd1$getChildNodes)(parent, this.collection)).key;
163
+ if (!parent) return null;
164
+ var _getFirstItem_key;
165
+ return (_getFirstItem_key = (_getFirstItem = (0, $kbsd1$getFirstItem)((0, $kbsd1$getChildNodes)(parent, this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key) !== null && _getFirstItem_key !== void 0 ? _getFirstItem_key : null;
127
166
  }
128
167
  }
129
168
  // Find the first row
130
- key = this.findNextKey(null, (item)=>item.type === 'item');
169
+ key = this.findNextKey(undefined, (item)=>item.type === 'item');
131
170
  // 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') {
171
+ if (key != null && (item && this.isCell(item) && global || this.focusMode === 'cell')) {
172
+ var _getFirstItem1;
133
173
  let item = this.collection.getItem(key);
134
- key = (0, $kbsd1$getFirstItem)((0, $kbsd1$getChildNodes)(item, this.collection)).key;
174
+ if (!item) return null;
175
+ var _getFirstItem_key1;
176
+ key = (_getFirstItem_key1 = (_getFirstItem1 = (0, $kbsd1$getFirstItem)((0, $kbsd1$getChildNodes)(item, this.collection))) === null || _getFirstItem1 === void 0 ? void 0 : _getFirstItem1.key) !== null && _getFirstItem_key1 !== void 0 ? _getFirstItem_key1 : null;
135
177
  }
136
178
  // Otherwise, focus the row itself.
137
179
  return key;
138
180
  }
139
- getLastKey(key, global) {
181
+ getLastKey(fromKey, global) {
182
+ let key = fromKey !== null && fromKey !== void 0 ? fromKey : null;
140
183
  let item;
141
184
  if (key != null) {
142
185
  item = this.collection.getItem(key);
143
- if (!item) return;
186
+ if (!item) return null;
144
187
  // If global flag is not set, and a cell is currently focused,
145
188
  // move focus to the last cell in the parent row.
146
- if (this.isCell(item) && !global) {
189
+ if (this.isCell(item) && !global && item.parentKey != null) {
190
+ var _getLastItem;
147
191
  let parent = this.collection.getItem(item.parentKey);
192
+ if (!parent) return null;
148
193
  let children = (0, $kbsd1$getChildNodes)(parent, this.collection);
149
- return (0, $kbsd1$getLastItem)(children).key;
194
+ var _getLastItem_key;
195
+ return (_getLastItem_key = (_getLastItem = (0, $kbsd1$getLastItem)(children)) === null || _getLastItem === void 0 ? void 0 : _getLastItem.key) !== null && _getLastItem_key !== void 0 ? _getLastItem_key : null;
150
196
  }
151
197
  }
152
198
  // Find the last row
153
- key = this.findPreviousKey(null, (item)=>item.type === 'item');
199
+ key = this.findPreviousKey(undefined, (item)=>item.type === 'item');
154
200
  // 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') {
201
+ if (key != null && (item && this.isCell(item) && global || this.focusMode === 'cell')) {
202
+ var _getLastItem1;
156
203
  let item = this.collection.getItem(key);
204
+ if (!item) return null;
157
205
  let children = (0, $kbsd1$getChildNodes)(item, this.collection);
158
- key = (0, $kbsd1$getLastItem)(children).key;
206
+ var _getLastItem_key1;
207
+ key = (_getLastItem_key1 = (_getLastItem1 = (0, $kbsd1$getLastItem)(children)) === null || _getLastItem1 === void 0 ? void 0 : _getLastItem1.key) !== null && _getLastItem_key1 !== void 0 ? _getLastItem_key1 : null;
159
208
  }
160
209
  // Otherwise, focus the row itself.
161
210
  return key;
162
211
  }
163
- getKeyPageAbove(key) {
212
+ getKeyPageAbove(fromKey) {
213
+ let key = fromKey;
164
214
  let itemRect = this.layoutDelegate.getItemRect(key);
165
215
  if (!itemRect) return null;
166
216
  let pageY = Math.max(0, itemRect.y + itemRect.height - this.layoutDelegate.getVisibleRect().height);
167
- while(itemRect && itemRect.y > pageY){
168
- key = this.getKeyAbove(key);
217
+ while(itemRect && itemRect.y > pageY && key != null){
218
+ var _this_getKeyAbove;
219
+ key = (_this_getKeyAbove = this.getKeyAbove(key)) !== null && _this_getKeyAbove !== void 0 ? _this_getKeyAbove : null;
220
+ if (key == null) break;
169
221
  itemRect = this.layoutDelegate.getItemRect(key);
170
222
  }
171
223
  return key;
172
224
  }
173
- getKeyPageBelow(key) {
225
+ getKeyPageBelow(fromKey) {
226
+ let key = fromKey;
174
227
  let itemRect = this.layoutDelegate.getItemRect(key);
175
228
  if (!itemRect) return null;
176
229
  let pageHeight = this.layoutDelegate.getVisibleRect().height;
@@ -185,20 +238,27 @@ class $d1c300d9c497e402$export$de9feff04fda126e {
185
238
  return key;
186
239
  }
187
240
  getKeyForSearch(search, fromKey) {
241
+ let key = fromKey !== null && fromKey !== void 0 ? fromKey : null;
188
242
  if (!this.collator) return null;
189
243
  let collection = this.collection;
190
- let key = fromKey !== null && fromKey !== void 0 ? fromKey : this.getFirstKey();
244
+ key = fromKey !== null && fromKey !== void 0 ? fromKey : this.getFirstKey();
245
+ if (key == null) return null;
191
246
  // If the starting key is a cell, search from its parent row.
192
247
  let startItem = collection.getItem(key);
193
- if (startItem.type === 'cell') key = startItem.parentKey;
248
+ if (!startItem) return null;
249
+ var _startItem_parentKey;
250
+ if (startItem.type === 'cell') key = (_startItem_parentKey = startItem.parentKey) !== null && _startItem_parentKey !== void 0 ? _startItem_parentKey : null;
194
251
  let hasWrapped = false;
195
252
  while(key != null){
196
253
  let item = collection.getItem(key);
254
+ if (!item) return null;
197
255
  // check row text value for match
198
256
  if (item.textValue) {
199
257
  let substring = item.textValue.slice(0, search.length);
200
258
  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;
259
+ var _getFirstItem;
260
+ var _getFirstItem_key;
261
+ if (this.isRow(item) && this.focusMode === 'cell') return (_getFirstItem_key = (_getFirstItem = (0, $kbsd1$getFirstItem)((0, $kbsd1$getChildNodes)(item, this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key) !== null && _getFirstItem_key !== void 0 ? _getFirstItem_key : null;
202
262
  return item.key;
203
263
  }
204
264
  }
@@ -217,6 +277,7 @@ class $d1c300d9c497e402$export$de9feff04fda126e {
217
277
  this.disabledBehavior = options.disabledBehavior || 'all';
218
278
  this.direction = options.direction;
219
279
  this.collator = options.collator;
280
+ if (!options.layout && !options.ref) throw new Error('Either a layout or a ref must be specified.');
220
281
  this.layoutDelegate = options.layoutDelegate || (options.layout ? new $d1c300d9c497e402$var$DeprecatedLayoutDelegate(options.layout) : new (0, $kbsd1$DOMLayoutDelegate)(options.ref));
221
282
  this.focusMode = options.focusMode || 'row';
222
283
  }
@@ -28,149 +28,202 @@ class $d1c300d9c497e402$export$de9feff04fda126e {
28
28
  let key = fromKey != null ? this.collection.getKeyBefore(fromKey) : this.collection.getLastKey();
29
29
  while(key != null){
30
30
  let item = this.collection.getItem(key);
31
+ if (!item) return null;
31
32
  if (!this.isDisabled(item) && (!pred || pred(item))) return key;
32
33
  key = this.collection.getKeyBefore(key);
33
34
  }
35
+ return null;
34
36
  }
35
37
  findNextKey(fromKey, pred) {
36
38
  let key = fromKey != null ? this.collection.getKeyAfter(fromKey) : this.collection.getFirstKey();
37
39
  while(key != null){
38
40
  let item = this.collection.getItem(key);
41
+ if (!item) return null;
39
42
  if (!this.isDisabled(item) && (!pred || pred(item))) return key;
40
43
  key = this.collection.getKeyAfter(key);
44
+ if (key == null) return null;
41
45
  }
46
+ return null;
42
47
  }
43
- getKeyBelow(key) {
48
+ getKeyBelow(fromKey) {
49
+ let key = fromKey;
44
50
  let startItem = this.collection.getItem(key);
45
- if (!startItem) return;
51
+ if (!startItem) return null;
52
+ var _startItem_parentKey;
46
53
  // If focus was on a cell, start searching from the parent row
47
- if (this.isCell(startItem)) key = startItem.parentKey;
54
+ if (this.isCell(startItem)) key = (_startItem_parentKey = startItem.parentKey) !== null && _startItem_parentKey !== void 0 ? _startItem_parentKey : null;
55
+ if (key == null) return null;
48
56
  // Find the next item
49
57
  key = this.findNextKey(key, (item)=>item.type === 'item');
50
58
  if (key != null) {
51
59
  // If focus was on a cell, focus the cell with the same index in the next row.
52
60
  if (this.isCell(startItem)) {
61
+ var _getNthItem;
53
62
  let item = this.collection.getItem(key);
54
- return (0, $kbsd1$getNthItem)((0, $kbsd1$getChildNodes)(item, this.collection), startItem.index).key;
63
+ if (!item) return null;
64
+ var _startItem_index, _getNthItem_key;
65
+ return (_getNthItem_key = (_getNthItem = (0, $kbsd1$getNthItem)((0, $kbsd1$getChildNodes)(item, this.collection), (_startItem_index = startItem.index) !== null && _startItem_index !== void 0 ? _startItem_index : 0)) === null || _getNthItem === void 0 ? void 0 : _getNthItem.key) !== null && _getNthItem_key !== void 0 ? _getNthItem_key : null;
55
66
  }
56
67
  // Otherwise, focus the next row
57
68
  if (this.focusMode === 'row') return key;
58
69
  }
70
+ return null;
59
71
  }
60
- getKeyAbove(key) {
72
+ getKeyAbove(fromKey) {
73
+ let key = fromKey;
61
74
  let startItem = this.collection.getItem(key);
62
- if (!startItem) return;
75
+ if (!startItem) return null;
76
+ var _startItem_parentKey;
63
77
  // If focus is on a cell, start searching from the parent row
64
- if (this.isCell(startItem)) key = startItem.parentKey;
78
+ if (this.isCell(startItem)) key = (_startItem_parentKey = startItem.parentKey) !== null && _startItem_parentKey !== void 0 ? _startItem_parentKey : null;
79
+ if (key == null) return null;
65
80
  // Find the previous item
66
81
  key = this.findPreviousKey(key, (item)=>item.type === 'item');
67
82
  if (key != null) {
68
83
  // If focus was on a cell, focus the cell with the same index in the previous row.
69
84
  if (this.isCell(startItem)) {
85
+ var _getNthItem;
70
86
  let item = this.collection.getItem(key);
71
- return (0, $kbsd1$getNthItem)((0, $kbsd1$getChildNodes)(item, this.collection), startItem.index).key;
87
+ if (!item) return null;
88
+ var _startItem_index;
89
+ return ((_getNthItem = (0, $kbsd1$getNthItem)((0, $kbsd1$getChildNodes)(item, this.collection), (_startItem_index = startItem.index) !== null && _startItem_index !== void 0 ? _startItem_index : 0)) === null || _getNthItem === void 0 ? void 0 : _getNthItem.key) || null;
72
90
  }
73
91
  // Otherwise, focus the previous row
74
92
  if (this.focusMode === 'row') return key;
75
93
  }
94
+ return null;
76
95
  }
77
96
  getKeyRightOf(key) {
78
97
  let item = this.collection.getItem(key);
79
- if (!item) return;
98
+ if (!item) return null;
80
99
  // If focus is on a row, focus the first child cell.
81
100
  if (this.isRow(item)) {
101
+ var _getLastItem, _getFirstItem;
82
102
  let children = (0, $kbsd1$getChildNodes)(item, this.collection);
83
- return this.direction === 'rtl' ? (0, $kbsd1$getLastItem)(children).key : (0, $kbsd1$getFirstItem)(children).key;
103
+ var _ref;
104
+ return (_ref = this.direction === 'rtl' ? (_getLastItem = (0, $kbsd1$getLastItem)(children)) === null || _getLastItem === void 0 ? void 0 : _getLastItem.key : (_getFirstItem = (0, $kbsd1$getFirstItem)(children)) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key) !== null && _ref !== void 0 ? _ref : null;
84
105
  }
85
106
  // If focus is on a cell, focus the next cell if any,
86
107
  // otherwise focus the parent row.
87
- if (this.isCell(item)) {
108
+ if (this.isCell(item) && item.parentKey != null) {
88
109
  let parent = this.collection.getItem(item.parentKey);
110
+ if (!parent) return null;
89
111
  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;
112
+ var _ref1;
113
+ let next = (_ref1 = this.direction === 'rtl' ? (0, $kbsd1$getNthItem)(children, item.index - 1) : (0, $kbsd1$getNthItem)(children, item.index + 1)) !== null && _ref1 !== void 0 ? _ref1 : null;
114
+ var _next_key;
115
+ if (next) return (_next_key = next.key) !== null && _next_key !== void 0 ? _next_key : null;
116
+ var _item_parentKey;
92
117
  // 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);
118
+ if (this.focusMode === 'row') return (_item_parentKey = item.parentKey) !== null && _item_parentKey !== void 0 ? _item_parentKey : null;
119
+ var _ref2;
120
+ return (_ref2 = this.direction === 'rtl' ? this.getFirstKey(key) : this.getLastKey(key)) !== null && _ref2 !== void 0 ? _ref2 : null;
95
121
  }
122
+ return null;
96
123
  }
97
124
  getKeyLeftOf(key) {
98
125
  let item = this.collection.getItem(key);
99
- if (!item) return;
126
+ if (!item) return null;
100
127
  // If focus is on a row, focus the last child cell.
101
128
  if (this.isRow(item)) {
129
+ var _getFirstItem, _getLastItem;
102
130
  let children = (0, $kbsd1$getChildNodes)(item, this.collection);
103
- return this.direction === 'rtl' ? (0, $kbsd1$getFirstItem)(children).key : (0, $kbsd1$getLastItem)(children).key;
131
+ var _ref;
132
+ return (_ref = this.direction === 'rtl' ? (_getFirstItem = (0, $kbsd1$getFirstItem)(children)) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key : (_getLastItem = (0, $kbsd1$getLastItem)(children)) === null || _getLastItem === void 0 ? void 0 : _getLastItem.key) !== null && _ref !== void 0 ? _ref : null;
104
133
  }
105
134
  // If focus is on a cell, focus the previous cell if any,
106
135
  // otherwise focus the parent row.
107
- if (this.isCell(item)) {
136
+ if (this.isCell(item) && item.parentKey != null) {
108
137
  let parent = this.collection.getItem(item.parentKey);
138
+ if (!parent) return null;
109
139
  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;
140
+ var _ref1;
141
+ let prev = (_ref1 = this.direction === 'rtl' ? (0, $kbsd1$getNthItem)(children, item.index + 1) : (0, $kbsd1$getNthItem)(children, item.index - 1)) !== null && _ref1 !== void 0 ? _ref1 : null;
142
+ var _prev_key;
143
+ if (prev) return (_prev_key = prev.key) !== null && _prev_key !== void 0 ? _prev_key : null;
144
+ var _item_parentKey;
112
145
  // 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);
146
+ if (this.focusMode === 'row') return (_item_parentKey = item.parentKey) !== null && _item_parentKey !== void 0 ? _item_parentKey : null;
147
+ var _ref2;
148
+ return (_ref2 = this.direction === 'rtl' ? this.getLastKey(key) : this.getFirstKey(key)) !== null && _ref2 !== void 0 ? _ref2 : null;
115
149
  }
150
+ return null;
116
151
  }
117
- getFirstKey(key, global) {
152
+ getFirstKey(fromKey, global) {
153
+ let key = fromKey !== null && fromKey !== void 0 ? fromKey : null;
118
154
  let item;
119
155
  if (key != null) {
120
156
  item = this.collection.getItem(key);
121
- if (!item) return;
157
+ if (!item) return null;
122
158
  // If global flag is not set, and a cell is currently focused,
123
159
  // move focus to the first cell in the parent row.
124
- if (this.isCell(item) && !global) {
160
+ if (this.isCell(item) && !global && item.parentKey != null) {
161
+ var _getFirstItem;
125
162
  let parent = this.collection.getItem(item.parentKey);
126
- return (0, $kbsd1$getFirstItem)((0, $kbsd1$getChildNodes)(parent, this.collection)).key;
163
+ if (!parent) return null;
164
+ var _getFirstItem_key;
165
+ return (_getFirstItem_key = (_getFirstItem = (0, $kbsd1$getFirstItem)((0, $kbsd1$getChildNodes)(parent, this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key) !== null && _getFirstItem_key !== void 0 ? _getFirstItem_key : null;
127
166
  }
128
167
  }
129
168
  // Find the first row
130
- key = this.findNextKey(null, (item)=>item.type === 'item');
169
+ key = this.findNextKey(undefined, (item)=>item.type === 'item');
131
170
  // 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') {
171
+ if (key != null && (item && this.isCell(item) && global || this.focusMode === 'cell')) {
172
+ var _getFirstItem1;
133
173
  let item = this.collection.getItem(key);
134
- key = (0, $kbsd1$getFirstItem)((0, $kbsd1$getChildNodes)(item, this.collection)).key;
174
+ if (!item) return null;
175
+ var _getFirstItem_key1;
176
+ key = (_getFirstItem_key1 = (_getFirstItem1 = (0, $kbsd1$getFirstItem)((0, $kbsd1$getChildNodes)(item, this.collection))) === null || _getFirstItem1 === void 0 ? void 0 : _getFirstItem1.key) !== null && _getFirstItem_key1 !== void 0 ? _getFirstItem_key1 : null;
135
177
  }
136
178
  // Otherwise, focus the row itself.
137
179
  return key;
138
180
  }
139
- getLastKey(key, global) {
181
+ getLastKey(fromKey, global) {
182
+ let key = fromKey !== null && fromKey !== void 0 ? fromKey : null;
140
183
  let item;
141
184
  if (key != null) {
142
185
  item = this.collection.getItem(key);
143
- if (!item) return;
186
+ if (!item) return null;
144
187
  // If global flag is not set, and a cell is currently focused,
145
188
  // move focus to the last cell in the parent row.
146
- if (this.isCell(item) && !global) {
189
+ if (this.isCell(item) && !global && item.parentKey != null) {
190
+ var _getLastItem;
147
191
  let parent = this.collection.getItem(item.parentKey);
192
+ if (!parent) return null;
148
193
  let children = (0, $kbsd1$getChildNodes)(parent, this.collection);
149
- return (0, $kbsd1$getLastItem)(children).key;
194
+ var _getLastItem_key;
195
+ return (_getLastItem_key = (_getLastItem = (0, $kbsd1$getLastItem)(children)) === null || _getLastItem === void 0 ? void 0 : _getLastItem.key) !== null && _getLastItem_key !== void 0 ? _getLastItem_key : null;
150
196
  }
151
197
  }
152
198
  // Find the last row
153
- key = this.findPreviousKey(null, (item)=>item.type === 'item');
199
+ key = this.findPreviousKey(undefined, (item)=>item.type === 'item');
154
200
  // 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') {
201
+ if (key != null && (item && this.isCell(item) && global || this.focusMode === 'cell')) {
202
+ var _getLastItem1;
156
203
  let item = this.collection.getItem(key);
204
+ if (!item) return null;
157
205
  let children = (0, $kbsd1$getChildNodes)(item, this.collection);
158
- key = (0, $kbsd1$getLastItem)(children).key;
206
+ var _getLastItem_key1;
207
+ key = (_getLastItem_key1 = (_getLastItem1 = (0, $kbsd1$getLastItem)(children)) === null || _getLastItem1 === void 0 ? void 0 : _getLastItem1.key) !== null && _getLastItem_key1 !== void 0 ? _getLastItem_key1 : null;
159
208
  }
160
209
  // Otherwise, focus the row itself.
161
210
  return key;
162
211
  }
163
- getKeyPageAbove(key) {
212
+ getKeyPageAbove(fromKey) {
213
+ let key = fromKey;
164
214
  let itemRect = this.layoutDelegate.getItemRect(key);
165
215
  if (!itemRect) return null;
166
216
  let pageY = Math.max(0, itemRect.y + itemRect.height - this.layoutDelegate.getVisibleRect().height);
167
- while(itemRect && itemRect.y > pageY){
168
- key = this.getKeyAbove(key);
217
+ while(itemRect && itemRect.y > pageY && key != null){
218
+ var _this_getKeyAbove;
219
+ key = (_this_getKeyAbove = this.getKeyAbove(key)) !== null && _this_getKeyAbove !== void 0 ? _this_getKeyAbove : null;
220
+ if (key == null) break;
169
221
  itemRect = this.layoutDelegate.getItemRect(key);
170
222
  }
171
223
  return key;
172
224
  }
173
- getKeyPageBelow(key) {
225
+ getKeyPageBelow(fromKey) {
226
+ let key = fromKey;
174
227
  let itemRect = this.layoutDelegate.getItemRect(key);
175
228
  if (!itemRect) return null;
176
229
  let pageHeight = this.layoutDelegate.getVisibleRect().height;
@@ -185,20 +238,27 @@ class $d1c300d9c497e402$export$de9feff04fda126e {
185
238
  return key;
186
239
  }
187
240
  getKeyForSearch(search, fromKey) {
241
+ let key = fromKey !== null && fromKey !== void 0 ? fromKey : null;
188
242
  if (!this.collator) return null;
189
243
  let collection = this.collection;
190
- let key = fromKey !== null && fromKey !== void 0 ? fromKey : this.getFirstKey();
244
+ key = fromKey !== null && fromKey !== void 0 ? fromKey : this.getFirstKey();
245
+ if (key == null) return null;
191
246
  // If the starting key is a cell, search from its parent row.
192
247
  let startItem = collection.getItem(key);
193
- if (startItem.type === 'cell') key = startItem.parentKey;
248
+ if (!startItem) return null;
249
+ var _startItem_parentKey;
250
+ if (startItem.type === 'cell') key = (_startItem_parentKey = startItem.parentKey) !== null && _startItem_parentKey !== void 0 ? _startItem_parentKey : null;
194
251
  let hasWrapped = false;
195
252
  while(key != null){
196
253
  let item = collection.getItem(key);
254
+ if (!item) return null;
197
255
  // check row text value for match
198
256
  if (item.textValue) {
199
257
  let substring = item.textValue.slice(0, search.length);
200
258
  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;
259
+ var _getFirstItem;
260
+ var _getFirstItem_key;
261
+ if (this.isRow(item) && this.focusMode === 'cell') return (_getFirstItem_key = (_getFirstItem = (0, $kbsd1$getFirstItem)((0, $kbsd1$getChildNodes)(item, this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key) !== null && _getFirstItem_key !== void 0 ? _getFirstItem_key : null;
202
262
  return item.key;
203
263
  }
204
264
  }
@@ -217,6 +277,7 @@ class $d1c300d9c497e402$export$de9feff04fda126e {
217
277
  this.disabledBehavior = options.disabledBehavior || 'all';
218
278
  this.direction = options.direction;
219
279
  this.collator = options.collator;
280
+ if (!options.layout && !options.ref) throw new Error('Either a layout or a ref must be specified.');
220
281
  this.layoutDelegate = options.layoutDelegate || (options.layout ? new $d1c300d9c497e402$var$DeprecatedLayoutDelegate(options.layout) : new (0, $kbsd1$DOMLayoutDelegate)(options.ref));
221
282
  this.focusMode = options.focusMode || 'row';
222
283
  }