@octanejs/aria 0.0.5 → 0.0.7
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/package.json +7 -7
- package/src/components/Table.ts +2618 -0
- package/src/components/Tree.ts +1450 -0
- package/src/components/TreeDropTargetDelegate.ts +363 -0
- package/src/components/index.ts +57 -0
- package/src/components/utils.ts +3 -6
- package/src/grid/GridKeyboardDelegate.ts +514 -0
- package/src/grid/useGrid.ts +263 -0
- package/src/grid/useGridCell.ts +346 -0
- package/src/grid/useGridRow.ts +108 -0
- package/src/grid/useGridRowGroup.ts +29 -0
- package/src/grid/utils.ts +24 -0
- package/src/index.ts +38 -0
- package/src/intl/autocomplete/index.ts +9 -2
- package/src/intl/breadcrumbs/index.ts +9 -2
- package/src/intl/combobox/index.ts +9 -2
- package/src/intl/compileMessages.ts +356 -0
- package/src/intl/grid/index.ts +9 -2
- package/src/intl/gridlist/index.ts +9 -2
- package/src/intl/menu/index.ts +9 -2
- package/src/intl/numberfield/index.ts +9 -2
- package/src/intl/overlays/index.ts +9 -2
- package/src/intl/searchfield/index.ts +9 -2
- package/src/intl/spinbutton/index.ts +9 -2
- package/src/intl/table/ar-AE.json +13 -0
- package/src/intl/table/bg-BG.json +13 -0
- package/src/intl/table/cs-CZ.json +13 -0
- package/src/intl/table/da-DK.json +13 -0
- package/src/intl/table/de-DE.json +13 -0
- package/src/intl/table/el-GR.json +13 -0
- package/src/intl/table/en-US.json +13 -0
- package/src/intl/table/es-ES.json +13 -0
- package/src/intl/table/et-EE.json +13 -0
- package/src/intl/table/fi-FI.json +13 -0
- package/src/intl/table/fr-FR.json +13 -0
- package/src/intl/table/he-IL.json +13 -0
- package/src/intl/table/hr-HR.json +13 -0
- package/src/intl/table/hu-HU.json +13 -0
- package/src/intl/table/index.ts +82 -0
- package/src/intl/table/it-IT.json +13 -0
- package/src/intl/table/ja-JP.json +13 -0
- package/src/intl/table/ko-KR.json +13 -0
- package/src/intl/table/lt-LT.json +13 -0
- package/src/intl/table/lv-LV.json +13 -0
- package/src/intl/table/nb-NO.json +13 -0
- package/src/intl/table/nl-NL.json +13 -0
- package/src/intl/table/pl-PL.json +13 -0
- package/src/intl/table/pt-BR.json +13 -0
- package/src/intl/table/pt-PT.json +13 -0
- package/src/intl/table/ro-RO.json +13 -0
- package/src/intl/table/ru-RU.json +13 -0
- package/src/intl/table/sk-SK.json +13 -0
- package/src/intl/table/sl-SI.json +13 -0
- package/src/intl/table/sr-SP.json +13 -0
- package/src/intl/table/sv-SE.json +13 -0
- package/src/intl/table/tr-TR.json +13 -0
- package/src/intl/table/uk-UA.json +13 -0
- package/src/intl/table/zh-CN.json +13 -0
- package/src/intl/table/zh-TW.json +13 -0
- package/src/intl/tag/index.ts +9 -2
- package/src/intl/tree/ar-AE.json +4 -0
- package/src/intl/tree/bg-BG.json +4 -0
- package/src/intl/tree/cs-CZ.json +4 -0
- package/src/intl/tree/da-DK.json +4 -0
- package/src/intl/tree/de-DE.json +4 -0
- package/src/intl/tree/el-GR.json +4 -0
- package/src/intl/tree/en-US.json +4 -0
- package/src/intl/tree/es-ES.json +4 -0
- package/src/intl/tree/et-EE.json +4 -0
- package/src/intl/tree/fi-FI.json +4 -0
- package/src/intl/tree/fr-FR.json +4 -0
- package/src/intl/tree/he-IL.json +4 -0
- package/src/intl/tree/hr-HR.json +4 -0
- package/src/intl/tree/hu-HU.json +4 -0
- package/src/intl/tree/index.ts +82 -0
- package/src/intl/tree/it-IT.json +4 -0
- package/src/intl/tree/ja-JP.json +4 -0
- package/src/intl/tree/ko-KR.json +4 -0
- package/src/intl/tree/lt-LT.json +4 -0
- package/src/intl/tree/lv-LV.json +4 -0
- package/src/intl/tree/nb-NO.json +4 -0
- package/src/intl/tree/nl-NL.json +4 -0
- package/src/intl/tree/pl-PL.json +4 -0
- package/src/intl/tree/pt-BR.json +4 -0
- package/src/intl/tree/pt-PT.json +4 -0
- package/src/intl/tree/ro-RO.json +4 -0
- package/src/intl/tree/ru-RU.json +4 -0
- package/src/intl/tree/sk-SK.json +4 -0
- package/src/intl/tree/sl-SI.json +4 -0
- package/src/intl/tree/sr-SP.json +4 -0
- package/src/intl/tree/sv-SE.json +4 -0
- package/src/intl/tree/tr-TR.json +4 -0
- package/src/intl/tree/uk-UA.json +4 -0
- package/src/intl/tree/zh-CN.json +4 -0
- package/src/intl/tree/zh-TW.json +4 -0
- package/src/stately/grid/GridCollection.ts +200 -0
- package/src/stately/grid/useGridState.ts +160 -0
- package/src/stately/index.ts +43 -0
- package/src/stately/table/Cell.ts +49 -0
- package/src/stately/table/Column.ts +121 -0
- package/src/stately/table/Row.ts +145 -0
- package/src/stately/table/TableBody.ts +66 -0
- package/src/stately/table/TableCollection.ts +390 -0
- package/src/stately/table/TableColumnLayout.ts +148 -0
- package/src/stately/table/TableHeader.ts +65 -0
- package/src/stately/table/TableUtils.ts +269 -0
- package/src/stately/table/useTableColumnResizeState.ts +202 -0
- package/src/stately/table/useTableState.ts +235 -0
- package/src/stately/table/useTreeGridState.ts +248 -0
- package/src/table/TableKeyboardDelegate.ts +205 -0
- package/src/table/useTable.ts +175 -0
- package/src/table/useTableCell.ts +81 -0
- package/src/table/useTableColumnHeader.ts +155 -0
- package/src/table/useTableColumnResize.ts +374 -0
- package/src/table/useTableHeaderRow.ts +57 -0
- package/src/table/useTableRow.ts +198 -0
- package/src/table/useTableRowGroup.ts +13 -0
- package/src/table/useTableSelectionCheckbox.ts +105 -0
- package/src/table/utils.ts +42 -0
- package/src/tree/useTree.ts +76 -0
- package/src/tree/useTreeItem.ts +109 -0
- package/src/utils/mergeRefs.ts +1 -4
- package/src/utils/useFormReset.ts +1 -2
- package/src/utils/useObjectRef.ts +2 -8
|
@@ -0,0 +1,514 @@
|
|
|
1
|
+
// Ported from react-aria (source: .react-spectrum/packages/react-aria/src/grid/GridKeyboardDelegate.ts).
|
|
2
|
+
// octane adaptations:
|
|
3
|
+
// - `IGridCollection`/`GridNode` come from the ported stately grid collection and
|
|
4
|
+
// `getChildNodes`/`getFirstItem`/`getLastItem`/`getNthItem` from the ported stately
|
|
5
|
+
// collections helpers; `DOMLayoutDelegate` from the ported selection area.
|
|
6
|
+
// - Pure class (no hooks) — no slot threading involved.
|
|
7
|
+
import type {
|
|
8
|
+
Direction,
|
|
9
|
+
DisabledBehavior,
|
|
10
|
+
Key,
|
|
11
|
+
KeyboardDelegate,
|
|
12
|
+
LayoutDelegate,
|
|
13
|
+
Node,
|
|
14
|
+
Rect,
|
|
15
|
+
RefObject,
|
|
16
|
+
Size,
|
|
17
|
+
} from '@react-types/shared';
|
|
18
|
+
import { DOMLayoutDelegate } from '../selection/DOMLayoutDelegate';
|
|
19
|
+
import {
|
|
20
|
+
getChildNodes,
|
|
21
|
+
getFirstItem,
|
|
22
|
+
getLastItem,
|
|
23
|
+
getNthItem,
|
|
24
|
+
} from '../stately/collections/getChildNodes';
|
|
25
|
+
import type { IGridCollection as GridCollection, GridNode } from '../stately/grid/GridCollection';
|
|
26
|
+
|
|
27
|
+
export interface GridKeyboardDelegateOptions<C> {
|
|
28
|
+
collection: C;
|
|
29
|
+
disabledKeys: Set<Key>;
|
|
30
|
+
disabledBehavior?: DisabledBehavior;
|
|
31
|
+
ref?: RefObject<HTMLElement | null>;
|
|
32
|
+
direction: Direction;
|
|
33
|
+
collator?: Intl.Collator;
|
|
34
|
+
layoutDelegate?: LayoutDelegate;
|
|
35
|
+
/** @deprecated - Use layoutDelegate instead. */
|
|
36
|
+
layout?: DeprecatedLayout;
|
|
37
|
+
focusMode?: 'row' | 'cell';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export class GridKeyboardDelegate<T, C extends GridCollection<T>> implements KeyboardDelegate {
|
|
41
|
+
collection: C;
|
|
42
|
+
protected disabledKeys: Set<Key>;
|
|
43
|
+
protected disabledBehavior: DisabledBehavior;
|
|
44
|
+
protected direction: Direction;
|
|
45
|
+
protected collator: Intl.Collator | undefined;
|
|
46
|
+
protected layoutDelegate: LayoutDelegate;
|
|
47
|
+
protected focusMode: 'row' | 'cell';
|
|
48
|
+
|
|
49
|
+
constructor(options: GridKeyboardDelegateOptions<C>) {
|
|
50
|
+
this.collection = options.collection;
|
|
51
|
+
this.disabledKeys = options.disabledKeys;
|
|
52
|
+
this.disabledBehavior = options.disabledBehavior || 'all';
|
|
53
|
+
this.direction = options.direction;
|
|
54
|
+
this.collator = options.collator;
|
|
55
|
+
if (!options.layout && !options.ref) {
|
|
56
|
+
throw new Error('Either a layout or a ref must be specified.');
|
|
57
|
+
}
|
|
58
|
+
this.layoutDelegate =
|
|
59
|
+
options.layoutDelegate ||
|
|
60
|
+
(options.layout
|
|
61
|
+
? new DeprecatedLayoutDelegate(options.layout)
|
|
62
|
+
: new DOMLayoutDelegate(options.ref!));
|
|
63
|
+
this.focusMode = options.focusMode ?? 'row';
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
protected isCell(node: Node<T>): boolean {
|
|
67
|
+
return node.type === 'cell';
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
protected isRow(node: Node<T>): boolean {
|
|
71
|
+
return node.type === 'row' || node.type === 'item';
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
private isDisabled(item: Node<unknown>) {
|
|
75
|
+
return (
|
|
76
|
+
this.disabledBehavior === 'all' &&
|
|
77
|
+
(item.props?.isDisabled || this.disabledKeys.has(item.key)) &&
|
|
78
|
+
item.props?.disabledBehavior !== 'selection'
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
protected findPreviousKey(
|
|
83
|
+
fromKey?: Key,
|
|
84
|
+
pred?: (item: Node<T>) => boolean,
|
|
85
|
+
includeDisabled = false,
|
|
86
|
+
): Key | null {
|
|
87
|
+
let key =
|
|
88
|
+
fromKey != null ? this.collection.getKeyBefore(fromKey) : this.collection.getLastKey();
|
|
89
|
+
|
|
90
|
+
while (key != null) {
|
|
91
|
+
let item = this.collection.getItem(key);
|
|
92
|
+
if (!item) {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
if ((includeDisabled || !this.isDisabled(item)) && (!pred || pred(item))) {
|
|
96
|
+
return key;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
key = this.collection.getKeyBefore(key);
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
protected findNextKey(
|
|
105
|
+
fromKey?: Key,
|
|
106
|
+
pred?: (item: Node<T>) => boolean,
|
|
107
|
+
includeDisabled = false,
|
|
108
|
+
): Key | null {
|
|
109
|
+
let key =
|
|
110
|
+
fromKey != null ? this.collection.getKeyAfter(fromKey) : this.collection.getFirstKey();
|
|
111
|
+
|
|
112
|
+
while (key != null) {
|
|
113
|
+
let item = this.collection.getItem(key);
|
|
114
|
+
if (!item) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
if ((includeDisabled || !this.isDisabled(item)) && (!pred || pred(item))) {
|
|
118
|
+
return key;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
key = this.collection.getKeyAfter(key);
|
|
122
|
+
if (key == null) {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
protected getKeyForItemInRowByIndex(key: Key, index: number = 0): Key | null {
|
|
130
|
+
if (index < 0) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
let item = this.collection.getItem(key);
|
|
135
|
+
if (!item) {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
let i = 0;
|
|
140
|
+
for (let child of getChildNodes(item, this.collection) as Iterable<GridNode<T>>) {
|
|
141
|
+
if (child.colSpan && child.colSpan + i > index) {
|
|
142
|
+
return child.key ?? null;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (child.colSpan) {
|
|
146
|
+
i = i + child.colSpan - 1;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (i === index) {
|
|
150
|
+
return child.key ?? null;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
i++;
|
|
154
|
+
}
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
getKeyBelow(fromKey: Key, options?: { includeDisabled?: boolean }): Key | null {
|
|
159
|
+
let key: Key | null = fromKey;
|
|
160
|
+
let startItem = this.collection.getItem(key);
|
|
161
|
+
if (!startItem) {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// If focus was on a cell, start searching from the parent row
|
|
166
|
+
if (this.isCell(startItem)) {
|
|
167
|
+
key = startItem.parentKey ?? null;
|
|
168
|
+
}
|
|
169
|
+
if (key == null) {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Find the next item
|
|
174
|
+
key = this.findNextKey(key, (item) => item.type === 'item', options?.includeDisabled);
|
|
175
|
+
if (key != null) {
|
|
176
|
+
// If focus was on a cell, focus the cell with the same index in the next row.
|
|
177
|
+
if (this.isCell(startItem)) {
|
|
178
|
+
let startIndex = startItem.colIndex ? startItem.colIndex : startItem.index;
|
|
179
|
+
return this.getKeyForItemInRowByIndex(key, startIndex);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Otherwise, focus the next row
|
|
183
|
+
if (this.focusMode === 'row') {
|
|
184
|
+
return key;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
getKeyAbove(fromKey: Key, options?: { includeDisabled?: boolean }): Key | null {
|
|
191
|
+
let key: Key | null = fromKey;
|
|
192
|
+
let startItem = this.collection.getItem(key);
|
|
193
|
+
if (!startItem) {
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// If focus is on a cell, start searching from the parent row
|
|
198
|
+
if (this.isCell(startItem)) {
|
|
199
|
+
key = startItem.parentKey ?? null;
|
|
200
|
+
}
|
|
201
|
+
if (key == null) {
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Find the previous item
|
|
206
|
+
key = this.findPreviousKey(key, (item) => item.type === 'item', options?.includeDisabled);
|
|
207
|
+
if (key != null) {
|
|
208
|
+
// If focus was on a cell, focus the cell with the same index in the previous row.
|
|
209
|
+
if (this.isCell(startItem)) {
|
|
210
|
+
let startIndex = startItem.colIndex ? startItem.colIndex : startItem.index;
|
|
211
|
+
return this.getKeyForItemInRowByIndex(key, startIndex);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Otherwise, focus the previous row
|
|
215
|
+
if (this.focusMode === 'row') {
|
|
216
|
+
return key;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
getKeyRightOf(key: Key): Key | null {
|
|
223
|
+
let item = this.collection.getItem(key);
|
|
224
|
+
if (!item) {
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// If focus is on a row, focus the first child cell.
|
|
229
|
+
if (this.isRow(item)) {
|
|
230
|
+
let children = getChildNodes(item, this.collection);
|
|
231
|
+
return (
|
|
232
|
+
(this.direction === 'rtl' ? getLastItem(children)?.key : getFirstItem(children)?.key) ??
|
|
233
|
+
null
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// If focus is on a cell, focus the next cell if any,
|
|
238
|
+
// otherwise focus the parent row.
|
|
239
|
+
if (this.isCell(item) && item.parentKey != null) {
|
|
240
|
+
let parent = this.collection.getItem(item.parentKey);
|
|
241
|
+
if (!parent) {
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
let children = getChildNodes(parent, this.collection);
|
|
245
|
+
let next =
|
|
246
|
+
(this.direction === 'rtl'
|
|
247
|
+
? getNthItem(children, item.index - 1)
|
|
248
|
+
: getNthItem(children, item.index + 1)) ?? null;
|
|
249
|
+
|
|
250
|
+
if (next) {
|
|
251
|
+
return next.key ?? null;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// focus row only if focusMode is set to row
|
|
255
|
+
if (this.focusMode === 'row') {
|
|
256
|
+
return item.parentKey ?? null;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return (this.direction === 'rtl' ? this.getFirstKey(key) : this.getLastKey(key)) ?? null;
|
|
260
|
+
}
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
getKeyLeftOf(key: Key): Key | null {
|
|
265
|
+
let item = this.collection.getItem(key);
|
|
266
|
+
if (!item) {
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// If focus is on a row, focus the last child cell.
|
|
271
|
+
if (this.isRow(item)) {
|
|
272
|
+
let children = getChildNodes(item, this.collection);
|
|
273
|
+
return (
|
|
274
|
+
(this.direction === 'rtl' ? getFirstItem(children)?.key : getLastItem(children)?.key) ??
|
|
275
|
+
null
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// If focus is on a cell, focus the previous cell if any,
|
|
280
|
+
// otherwise focus the parent row.
|
|
281
|
+
if (this.isCell(item) && item.parentKey != null) {
|
|
282
|
+
let parent = this.collection.getItem(item.parentKey);
|
|
283
|
+
if (!parent) {
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
let children = getChildNodes(parent, this.collection);
|
|
287
|
+
let prev =
|
|
288
|
+
(this.direction === 'rtl'
|
|
289
|
+
? getNthItem(children, item.index + 1)
|
|
290
|
+
: getNthItem(children, item.index - 1)) ?? null;
|
|
291
|
+
|
|
292
|
+
if (prev) {
|
|
293
|
+
return prev.key ?? null;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// focus row only if focusMode is set to row
|
|
297
|
+
if (this.focusMode === 'row') {
|
|
298
|
+
return item.parentKey ?? null;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
return (this.direction === 'rtl' ? this.getLastKey(key) : this.getFirstKey(key)) ?? null;
|
|
302
|
+
}
|
|
303
|
+
return null;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
getFirstKey(fromKey?: Key, global?: boolean): Key | null {
|
|
307
|
+
let key: Key | null = fromKey ?? null;
|
|
308
|
+
let item: Node<T> | undefined | null;
|
|
309
|
+
if (key != null) {
|
|
310
|
+
item = this.collection.getItem(key);
|
|
311
|
+
if (!item) {
|
|
312
|
+
return null;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// If global flag is not set, and a cell is currently focused,
|
|
316
|
+
// move focus to the first cell in the parent row.
|
|
317
|
+
if (this.isCell(item) && !global && item.parentKey != null) {
|
|
318
|
+
let parent = this.collection.getItem(item.parentKey);
|
|
319
|
+
if (!parent) {
|
|
320
|
+
return null;
|
|
321
|
+
}
|
|
322
|
+
return getFirstItem(getChildNodes(parent, this.collection))?.key ?? null;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// Find the first row
|
|
327
|
+
key = this.findNextKey(undefined, (item) => item.type === 'item');
|
|
328
|
+
|
|
329
|
+
// If global flag is set (or if focus mode is cell), focus the first cell in the first row.
|
|
330
|
+
if (key != null && ((item && this.isCell(item) && global) || this.focusMode === 'cell')) {
|
|
331
|
+
let item = this.collection.getItem(key);
|
|
332
|
+
if (!item) {
|
|
333
|
+
return null;
|
|
334
|
+
}
|
|
335
|
+
key = getFirstItem(getChildNodes(item, this.collection))?.key ?? null;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// Otherwise, focus the row itself.
|
|
339
|
+
return key;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
getLastKey(fromKey?: Key, global?: boolean): Key | null {
|
|
343
|
+
let key: Key | null = fromKey ?? null;
|
|
344
|
+
let item: Node<T> | undefined | null;
|
|
345
|
+
if (key != null) {
|
|
346
|
+
item = this.collection.getItem(key);
|
|
347
|
+
if (!item) {
|
|
348
|
+
return null;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// If global flag is not set, and a cell is currently focused,
|
|
352
|
+
// move focus to the last cell in the parent row.
|
|
353
|
+
if (this.isCell(item) && !global && item.parentKey != null) {
|
|
354
|
+
let parent = this.collection.getItem(item.parentKey);
|
|
355
|
+
if (!parent) {
|
|
356
|
+
return null;
|
|
357
|
+
}
|
|
358
|
+
let children = getChildNodes(parent, this.collection);
|
|
359
|
+
return getLastItem(children)?.key ?? null;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// Find the last row
|
|
364
|
+
key = this.findPreviousKey(undefined, (item) => item.type === 'item');
|
|
365
|
+
|
|
366
|
+
// If global flag is set (or if focus mode is cell), focus the last cell in the last row.
|
|
367
|
+
if (key != null && ((item && this.isCell(item) && global) || this.focusMode === 'cell')) {
|
|
368
|
+
let item = this.collection.getItem(key);
|
|
369
|
+
if (!item) {
|
|
370
|
+
return null;
|
|
371
|
+
}
|
|
372
|
+
let children = getChildNodes(item, this.collection);
|
|
373
|
+
key = getLastItem(children)?.key ?? null;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// Otherwise, focus the row itself.
|
|
377
|
+
return key;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
getKeyPageAbove(fromKey: Key): Key | null {
|
|
381
|
+
let key: Key | null = fromKey;
|
|
382
|
+
let itemRect = this.layoutDelegate.getItemRect(key);
|
|
383
|
+
if (!itemRect) {
|
|
384
|
+
return null;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
let pageY = Math.max(
|
|
388
|
+
0,
|
|
389
|
+
itemRect.y + itemRect.height - this.layoutDelegate.getVisibleRect().height,
|
|
390
|
+
);
|
|
391
|
+
|
|
392
|
+
while (itemRect && itemRect.y > pageY && key != null) {
|
|
393
|
+
key = this.getKeyAbove(key) ?? null;
|
|
394
|
+
if (key == null) {
|
|
395
|
+
break;
|
|
396
|
+
}
|
|
397
|
+
itemRect = this.layoutDelegate.getItemRect(key);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
return key;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
getKeyPageBelow(fromKey: Key): Key | null {
|
|
404
|
+
let key: Key | null = fromKey;
|
|
405
|
+
let itemRect = this.layoutDelegate.getItemRect(key);
|
|
406
|
+
|
|
407
|
+
if (!itemRect) {
|
|
408
|
+
return null;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
let pageHeight = this.layoutDelegate.getVisibleRect().height;
|
|
412
|
+
let pageY = Math.min(this.layoutDelegate.getContentSize().height, itemRect.y + pageHeight);
|
|
413
|
+
|
|
414
|
+
while (itemRect && itemRect.y + itemRect.height < pageY) {
|
|
415
|
+
let nextKey = this.getKeyBelow(key);
|
|
416
|
+
// If nextKey is undefined, we've reached the last row already
|
|
417
|
+
if (nextKey == null) {
|
|
418
|
+
break;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
itemRect = this.layoutDelegate.getItemRect(nextKey);
|
|
422
|
+
key = nextKey;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
return key;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
getKeyForSearch(search: string, fromKey?: Key): Key | null {
|
|
429
|
+
let key: Key | null = fromKey ?? null;
|
|
430
|
+
if (!this.collator) {
|
|
431
|
+
return null;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
let collection = this.collection;
|
|
435
|
+
key = fromKey ?? this.getFirstKey();
|
|
436
|
+
if (key == null) {
|
|
437
|
+
return null;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// If the starting key is a cell, search from its parent row.
|
|
441
|
+
let startItem = collection.getItem(key);
|
|
442
|
+
if (!startItem) {
|
|
443
|
+
return null;
|
|
444
|
+
}
|
|
445
|
+
if (startItem.type === 'cell') {
|
|
446
|
+
key = startItem.parentKey ?? null;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
let hasWrapped = false;
|
|
450
|
+
while (key != null) {
|
|
451
|
+
let item = collection.getItem(key);
|
|
452
|
+
if (!item) {
|
|
453
|
+
return null;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
// check row text value for match
|
|
457
|
+
if (item.textValue) {
|
|
458
|
+
let substring = item.textValue.slice(0, search.length);
|
|
459
|
+
if (this.collator.compare(substring, search) === 0) {
|
|
460
|
+
if (this.isRow(item) && this.focusMode === 'cell') {
|
|
461
|
+
return getFirstItem(getChildNodes(item, this.collection))?.key ?? null;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
return item.key;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
key = this.findNextKey(key, (item) => item.type === 'item');
|
|
469
|
+
|
|
470
|
+
// Wrap around when reaching the end of the collection
|
|
471
|
+
if (key == null && !hasWrapped) {
|
|
472
|
+
key = this.getFirstKey();
|
|
473
|
+
hasWrapped = true;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
return null;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/* Backward compatibility for old Virtualizer Layout interface. */
|
|
482
|
+
interface DeprecatedLayout {
|
|
483
|
+
getLayoutInfo(key: Key): DeprecatedLayoutInfo;
|
|
484
|
+
getContentSize(): Size;
|
|
485
|
+
virtualizer: DeprecatedVirtualizer;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
interface DeprecatedLayoutInfo {
|
|
489
|
+
rect: Rect;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
interface DeprecatedVirtualizer {
|
|
493
|
+
visibleRect: Rect;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
class DeprecatedLayoutDelegate implements LayoutDelegate {
|
|
497
|
+
layout: DeprecatedLayout;
|
|
498
|
+
|
|
499
|
+
constructor(layout: DeprecatedLayout) {
|
|
500
|
+
this.layout = layout;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
getContentSize(): Size {
|
|
504
|
+
return this.layout.getContentSize();
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
getItemRect(key: Key): Rect | null {
|
|
508
|
+
return this.layout.getLayoutInfo(key)?.rect || null;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
getVisibleRect(): Rect {
|
|
512
|
+
return this.layout.virtualizer.visibleRect;
|
|
513
|
+
}
|
|
514
|
+
}
|