@react-aria/grid 3.8.9-nightly.4555 → 3.8.9-nightly.4560
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.
- package/dist/GridKeyboardDelegate.main.js +252 -0
- package/dist/GridKeyboardDelegate.main.js.map +1 -0
- package/dist/GridKeyboardDelegate.mjs +247 -0
- package/dist/GridKeyboardDelegate.module.js +247 -0
- package/dist/GridKeyboardDelegate.module.js.map +1 -0
- package/dist/ar-AE.mjs +1 -1
- package/dist/bg-BG.mjs +1 -1
- package/dist/cs-CZ.mjs +1 -1
- package/dist/da-DK.mjs +1 -1
- package/dist/de-DE.mjs +1 -1
- package/dist/el-GR.mjs +1 -1
- package/dist/en-US.mjs +1 -1
- package/dist/es-ES.mjs +1 -1
- package/dist/et-EE.mjs +1 -1
- package/dist/fi-FI.mjs +1 -1
- package/dist/fr-FR.mjs +1 -1
- package/dist/he-IL.mjs +1 -1
- package/dist/hr-HR.mjs +1 -1
- package/dist/hu-HU.mjs +1 -1
- package/dist/import.mjs +8 -884
- package/dist/intlStrings.main.js +108 -0
- package/dist/intlStrings.main.js.map +1 -0
- package/dist/intlStrings.mjs +110 -0
- package/dist/intlStrings.module.js +110 -0
- package/dist/intlStrings.module.js.map +1 -0
- package/dist/it-IT.mjs +1 -1
- package/dist/ja-JP.mjs +1 -1
- package/dist/ko-KR.mjs +1 -1
- package/dist/lt-LT.mjs +1 -1
- package/dist/lv-LV.mjs +1 -1
- package/dist/main.js +16 -892
- package/dist/main.js.map +1 -1
- package/dist/module.js +8 -884
- package/dist/module.js.map +1 -1
- package/dist/nb-NO.mjs +1 -1
- package/dist/nl-NL.mjs +1 -1
- package/dist/pl-PL.mjs +1 -1
- package/dist/pt-BR.mjs +1 -1
- package/dist/pt-PT.mjs +1 -1
- package/dist/ro-RO.mjs +1 -1
- package/dist/ru-RU.mjs +1 -1
- package/dist/sk-SK.mjs +1 -1
- package/dist/sl-SI.mjs +1 -1
- package/dist/sr-SP.mjs +1 -1
- package/dist/sv-SE.mjs +1 -1
- package/dist/tr-TR.mjs +1 -1
- package/dist/uk-UA.mjs +1 -1
- package/dist/useGrid.main.js +132 -0
- package/dist/useGrid.main.js.map +1 -0
- package/dist/useGrid.mjs +127 -0
- package/dist/useGrid.module.js +127 -0
- package/dist/useGrid.module.js.map +1 -0
- package/dist/useGridCell.main.js +220 -0
- package/dist/useGridCell.main.js.map +1 -0
- package/dist/useGridCell.mjs +215 -0
- package/dist/useGridCell.module.js +215 -0
- package/dist/useGridCell.module.js.map +1 -0
- package/dist/useGridRow.main.js +53 -0
- package/dist/useGridRow.main.js.map +1 -0
- package/dist/useGridRow.mjs +48 -0
- package/dist/useGridRow.module.js +48 -0
- package/dist/useGridRow.module.js.map +1 -0
- package/dist/useGridRowGroup.main.js +26 -0
- package/dist/useGridRowGroup.main.js.map +1 -0
- package/dist/useGridRowGroup.mjs +21 -0
- package/dist/useGridRowGroup.module.js +21 -0
- package/dist/useGridRowGroup.module.js.map +1 -0
- package/dist/useGridSelectionAnnouncement.main.js +94 -0
- package/dist/useGridSelectionAnnouncement.main.js.map +1 -0
- package/dist/useGridSelectionAnnouncement.mjs +89 -0
- package/dist/useGridSelectionAnnouncement.module.js +89 -0
- package/dist/useGridSelectionAnnouncement.module.js.map +1 -0
- package/dist/useGridSelectionCheckbox.main.js +38 -0
- package/dist/useGridSelectionCheckbox.main.js.map +1 -0
- package/dist/useGridSelectionCheckbox.mjs +33 -0
- package/dist/useGridSelectionCheckbox.module.js +33 -0
- package/dist/useGridSelectionCheckbox.module.js.map +1 -0
- package/dist/useHighlightSelectionDescription.main.js +55 -0
- package/dist/useHighlightSelectionDescription.main.js.map +1 -0
- package/dist/useHighlightSelectionDescription.mjs +50 -0
- package/dist/useHighlightSelectionDescription.module.js +50 -0
- package/dist/useHighlightSelectionDescription.module.js.map +1 -0
- package/dist/utils.main.js +20 -0
- package/dist/utils.main.js.map +1 -0
- package/dist/utils.mjs +15 -0
- package/dist/utils.module.js +15 -0
- package/dist/utils.module.js.map +1 -0
- package/dist/zh-CN.mjs +1 -1
- package/dist/zh-TW.mjs +1 -1
- package/package.json +15 -15
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
var $iKGCm$reactstatelycollections = require("@react-stately/collections");
|
|
2
|
+
var $iKGCm$reactstatelyvirtualizer = require("@react-stately/virtualizer");
|
|
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);
|
|
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);
|
|
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();
|
|
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();
|
|
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
|
+
getItem(key) {
|
|
170
|
+
return this.ref.current.querySelector(`[data-key="${CSS.escape(key.toString())}"]`);
|
|
171
|
+
}
|
|
172
|
+
getItemRect(key) {
|
|
173
|
+
var _this_layout_getLayoutInfo;
|
|
174
|
+
if (this.layout) return (_this_layout_getLayoutInfo = this.layout.getLayoutInfo(key)) === null || _this_layout_getLayoutInfo === void 0 ? void 0 : _this_layout_getLayoutInfo.rect;
|
|
175
|
+
let item = this.getItem(key);
|
|
176
|
+
if (item) return new (0, $iKGCm$reactstatelyvirtualizer.Rect)(item.offsetLeft, item.offsetTop, item.offsetWidth, item.offsetHeight);
|
|
177
|
+
}
|
|
178
|
+
getPageHeight() {
|
|
179
|
+
var _this_layout_virtualizer, _this_ref_current, _this_ref;
|
|
180
|
+
if (this.layout) return (_this_layout_virtualizer = this.layout.virtualizer) === null || _this_layout_virtualizer === void 0 ? void 0 : _this_layout_virtualizer.visibleRect.height;
|
|
181
|
+
return (_this_ref = this.ref) === null || _this_ref === void 0 ? void 0 : (_this_ref_current = _this_ref.current) === null || _this_ref_current === void 0 ? void 0 : _this_ref_current.offsetHeight;
|
|
182
|
+
}
|
|
183
|
+
getContentHeight() {
|
|
184
|
+
var _this_ref_current, _this_ref;
|
|
185
|
+
if (this.layout) return this.layout.getContentSize().height;
|
|
186
|
+
return (_this_ref = this.ref) === null || _this_ref === void 0 ? void 0 : (_this_ref_current = _this_ref.current) === null || _this_ref_current === void 0 ? void 0 : _this_ref_current.scrollHeight;
|
|
187
|
+
}
|
|
188
|
+
getKeyPageAbove(key) {
|
|
189
|
+
let itemRect = this.getItemRect(key);
|
|
190
|
+
if (!itemRect) return null;
|
|
191
|
+
let pageY = Math.max(0, itemRect.maxY - this.getPageHeight());
|
|
192
|
+
while(itemRect && itemRect.y > pageY){
|
|
193
|
+
key = this.getKeyAbove(key);
|
|
194
|
+
itemRect = this.getItemRect(key);
|
|
195
|
+
}
|
|
196
|
+
return key;
|
|
197
|
+
}
|
|
198
|
+
getKeyPageBelow(key) {
|
|
199
|
+
let itemRect = this.getItemRect(key);
|
|
200
|
+
if (!itemRect) return null;
|
|
201
|
+
let pageHeight = this.getPageHeight();
|
|
202
|
+
let pageY = Math.min(this.getContentHeight(), itemRect.y + pageHeight);
|
|
203
|
+
while(itemRect && itemRect.maxY < pageY){
|
|
204
|
+
let nextKey = this.getKeyBelow(key);
|
|
205
|
+
itemRect = this.getItemRect(nextKey);
|
|
206
|
+
// Guard against case where maxY of the last key is barely less than pageY due to rounding
|
|
207
|
+
// and thus it attempts to set key to null
|
|
208
|
+
if (nextKey != null) key = nextKey;
|
|
209
|
+
}
|
|
210
|
+
return key;
|
|
211
|
+
}
|
|
212
|
+
getKeyForSearch(search, fromKey) {
|
|
213
|
+
if (!this.collator) return null;
|
|
214
|
+
let collection = this.collection;
|
|
215
|
+
let key = fromKey !== null && fromKey !== void 0 ? fromKey : this.getFirstKey();
|
|
216
|
+
// If the starting key is a cell, search from its parent row.
|
|
217
|
+
let startItem = collection.getItem(key);
|
|
218
|
+
if (startItem.type === "cell") key = startItem.parentKey;
|
|
219
|
+
let hasWrapped = false;
|
|
220
|
+
while(key != null){
|
|
221
|
+
let item = collection.getItem(key);
|
|
222
|
+
// check row text value for match
|
|
223
|
+
if (item.textValue) {
|
|
224
|
+
let substring = item.textValue.slice(0, search.length);
|
|
225
|
+
if (this.collator.compare(substring, search) === 0) {
|
|
226
|
+
if (this.isRow(item) && this.focusMode === "cell") return (0, $iKGCm$reactstatelycollections.getFirstItem)((0, $iKGCm$reactstatelycollections.getChildNodes)(item, this.collection)).key;
|
|
227
|
+
return item.key;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
key = this.findNextKey(key);
|
|
231
|
+
// Wrap around when reaching the end of the collection
|
|
232
|
+
if (key == null && !hasWrapped) {
|
|
233
|
+
key = this.getFirstKey();
|
|
234
|
+
hasWrapped = true;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
constructor(options){
|
|
240
|
+
this.collection = options.collection;
|
|
241
|
+
this.disabledKeys = options.disabledKeys;
|
|
242
|
+
this.disabledBehavior = options.disabledBehavior || "all";
|
|
243
|
+
this.ref = options.ref;
|
|
244
|
+
this.direction = options.direction;
|
|
245
|
+
this.collator = options.collator;
|
|
246
|
+
this.layout = options.layout;
|
|
247
|
+
this.focusMode = options.focusMode || "row";
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
//# sourceMappingURL=GridKeyboard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,GAAG,QAAQ,SAAS;QAClC,IAAI,CAAC,QAAQ,GAAG,QAAQ,QAAQ;QAChC,IAAI,CAAC,MAAM,GAAG,QAAQ,MAAM;QAC5B,IAAI,CAAC,SAAS,GAAG,QAAQ,SAAS,IAAI;IACxC;AAsVF","sources":["packages/@react-aria/grid/src/GridKeyboardDelegate.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 {Direction, DisabledBehavior, Key, KeyboardDelegate, Node} from '@react-types/shared';\nimport {getChildNodes, getFirstItem, getLastItem, getNthItem} from '@react-stately/collections';\nimport {GridCollection} from '@react-types/grid';\nimport {Layout, Rect} from '@react-stately/virtualizer';\nimport {RefObject} from 'react';\n\nexport interface GridKeyboardDelegateOptions<T, C> {\n collection: C,\n disabledKeys: Set<Key>,\n disabledBehavior?: DisabledBehavior,\n ref?: RefObject<HTMLElement>,\n direction: Direction,\n collator?: Intl.Collator,\n layout?: Layout<Node<T>>,\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 ref: RefObject<HTMLElement>;\n protected direction: Direction;\n protected collator: Intl.Collator;\n protected layout: Layout<Node<T>>;\n protected focusMode;\n\n constructor(options: GridKeyboardDelegateOptions<T, C>) {\n this.collection = options.collection;\n this.disabledKeys = options.disabledKeys;\n this.disabledBehavior = options.disabledBehavior || 'all';\n this.ref = options.ref;\n this.direction = options.direction;\n this.collator = options.collator;\n this.layout = options.layout;\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);\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);\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();\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();\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 private getItem(key: Key): HTMLElement {\n return this.ref.current.querySelector(`[data-key=\"${CSS.escape(key.toString())}\"]`);\n }\n\n private getItemRect(key: Key): Rect {\n if (this.layout) {\n return this.layout.getLayoutInfo(key)?.rect;\n }\n\n let item = this.getItem(key);\n if (item) {\n return new Rect(item.offsetLeft, item.offsetTop, item.offsetWidth, item.offsetHeight);\n }\n }\n\n private getPageHeight(): number {\n if (this.layout) {\n return this.layout.virtualizer?.visibleRect.height;\n }\n\n return this.ref?.current?.offsetHeight;\n }\n\n private getContentHeight(): number {\n if (this.layout) {\n return this.layout.getContentSize().height;\n }\n\n return this.ref?.current?.scrollHeight;\n }\n\n getKeyPageAbove(key: Key) {\n let itemRect = this.getItemRect(key);\n if (!itemRect) {\n return null;\n }\n\n let pageY = Math.max(0, itemRect.maxY - this.getPageHeight());\n\n while (itemRect && itemRect.y > pageY) {\n key = this.getKeyAbove(key);\n itemRect = this.getItemRect(key);\n }\n\n return key;\n }\n\n getKeyPageBelow(key: Key) {\n let itemRect = this.getItemRect(key);\n\n if (!itemRect) {\n return null;\n }\n\n let pageHeight = this.getPageHeight();\n let pageY = Math.min(this.getContentHeight(), itemRect.y + pageHeight);\n\n while (itemRect && itemRect.maxY < pageY) {\n let nextKey = this.getKeyBelow(key);\n itemRect = this.getItemRect(nextKey);\n\n // Guard against case where maxY of the last key is barely less than pageY due to rounding\n // and thus it attempts to set key to null\n if (nextKey != null) {\n key = nextKey;\n }\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);\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"],"names":[],"version":3,"file":"GridKeyboardDelegate.main.js.map"}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import {getNthItem as $kbsd1$getNthItem, getChildNodes as $kbsd1$getChildNodes, getLastItem as $kbsd1$getLastItem, getFirstItem as $kbsd1$getFirstItem} from "@react-stately/collections";
|
|
2
|
+
import {Rect as $kbsd1$Rect} from "@react-stately/virtualizer";
|
|
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);
|
|
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);
|
|
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();
|
|
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();
|
|
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
|
+
getItem(key) {
|
|
164
|
+
return this.ref.current.querySelector(`[data-key="${CSS.escape(key.toString())}"]`);
|
|
165
|
+
}
|
|
166
|
+
getItemRect(key) {
|
|
167
|
+
var _this_layout_getLayoutInfo;
|
|
168
|
+
if (this.layout) return (_this_layout_getLayoutInfo = this.layout.getLayoutInfo(key)) === null || _this_layout_getLayoutInfo === void 0 ? void 0 : _this_layout_getLayoutInfo.rect;
|
|
169
|
+
let item = this.getItem(key);
|
|
170
|
+
if (item) return new (0, $kbsd1$Rect)(item.offsetLeft, item.offsetTop, item.offsetWidth, item.offsetHeight);
|
|
171
|
+
}
|
|
172
|
+
getPageHeight() {
|
|
173
|
+
var _this_layout_virtualizer, _this_ref_current, _this_ref;
|
|
174
|
+
if (this.layout) return (_this_layout_virtualizer = this.layout.virtualizer) === null || _this_layout_virtualizer === void 0 ? void 0 : _this_layout_virtualizer.visibleRect.height;
|
|
175
|
+
return (_this_ref = this.ref) === null || _this_ref === void 0 ? void 0 : (_this_ref_current = _this_ref.current) === null || _this_ref_current === void 0 ? void 0 : _this_ref_current.offsetHeight;
|
|
176
|
+
}
|
|
177
|
+
getContentHeight() {
|
|
178
|
+
var _this_ref_current, _this_ref;
|
|
179
|
+
if (this.layout) return this.layout.getContentSize().height;
|
|
180
|
+
return (_this_ref = this.ref) === null || _this_ref === void 0 ? void 0 : (_this_ref_current = _this_ref.current) === null || _this_ref_current === void 0 ? void 0 : _this_ref_current.scrollHeight;
|
|
181
|
+
}
|
|
182
|
+
getKeyPageAbove(key) {
|
|
183
|
+
let itemRect = this.getItemRect(key);
|
|
184
|
+
if (!itemRect) return null;
|
|
185
|
+
let pageY = Math.max(0, itemRect.maxY - this.getPageHeight());
|
|
186
|
+
while(itemRect && itemRect.y > pageY){
|
|
187
|
+
key = this.getKeyAbove(key);
|
|
188
|
+
itemRect = this.getItemRect(key);
|
|
189
|
+
}
|
|
190
|
+
return key;
|
|
191
|
+
}
|
|
192
|
+
getKeyPageBelow(key) {
|
|
193
|
+
let itemRect = this.getItemRect(key);
|
|
194
|
+
if (!itemRect) return null;
|
|
195
|
+
let pageHeight = this.getPageHeight();
|
|
196
|
+
let pageY = Math.min(this.getContentHeight(), itemRect.y + pageHeight);
|
|
197
|
+
while(itemRect && itemRect.maxY < pageY){
|
|
198
|
+
let nextKey = this.getKeyBelow(key);
|
|
199
|
+
itemRect = this.getItemRect(nextKey);
|
|
200
|
+
// Guard against case where maxY of the last key is barely less than pageY due to rounding
|
|
201
|
+
// and thus it attempts to set key to null
|
|
202
|
+
if (nextKey != null) key = nextKey;
|
|
203
|
+
}
|
|
204
|
+
return key;
|
|
205
|
+
}
|
|
206
|
+
getKeyForSearch(search, fromKey) {
|
|
207
|
+
if (!this.collator) return null;
|
|
208
|
+
let collection = this.collection;
|
|
209
|
+
let key = fromKey !== null && fromKey !== void 0 ? fromKey : this.getFirstKey();
|
|
210
|
+
// If the starting key is a cell, search from its parent row.
|
|
211
|
+
let startItem = collection.getItem(key);
|
|
212
|
+
if (startItem.type === "cell") key = startItem.parentKey;
|
|
213
|
+
let hasWrapped = false;
|
|
214
|
+
while(key != null){
|
|
215
|
+
let item = collection.getItem(key);
|
|
216
|
+
// check row text value for match
|
|
217
|
+
if (item.textValue) {
|
|
218
|
+
let substring = item.textValue.slice(0, search.length);
|
|
219
|
+
if (this.collator.compare(substring, search) === 0) {
|
|
220
|
+
if (this.isRow(item) && this.focusMode === "cell") return (0, $kbsd1$getFirstItem)((0, $kbsd1$getChildNodes)(item, this.collection)).key;
|
|
221
|
+
return item.key;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
key = this.findNextKey(key);
|
|
225
|
+
// Wrap around when reaching the end of the collection
|
|
226
|
+
if (key == null && !hasWrapped) {
|
|
227
|
+
key = this.getFirstKey();
|
|
228
|
+
hasWrapped = true;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
constructor(options){
|
|
234
|
+
this.collection = options.collection;
|
|
235
|
+
this.disabledKeys = options.disabledKeys;
|
|
236
|
+
this.disabledBehavior = options.disabledBehavior || "all";
|
|
237
|
+
this.ref = options.ref;
|
|
238
|
+
this.direction = options.direction;
|
|
239
|
+
this.collator = options.collator;
|
|
240
|
+
this.layout = options.layout;
|
|
241
|
+
this.focusMode = options.focusMode || "row";
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
export {$d1c300d9c497e402$export$de9feff04fda126e as GridKeyboardDelegate};
|
|
247
|
+
//# sourceMappingURL=GridKeyboardDelegate.mjs.map
|