@angular/cdk-experimental 21.0.0-next.6 → 21.0.0-next.9
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/fesm2022/_polyfill-chunk.mjs.map +1 -1
- package/fesm2022/cdk-experimental.mjs +1 -1
- package/fesm2022/cdk-experimental.mjs.map +1 -1
- package/fesm2022/column-resize.mjs.map +1 -1
- package/fesm2022/popover-edit.mjs.map +1 -1
- package/fesm2022/scrolling.mjs.map +1 -1
- package/fesm2022/selection.mjs.map +1 -1
- package/fesm2022/table-scroll-container.mjs.map +1 -1
- package/package.json +3 -38
- package/types/column-resize.d.ts +37 -37
- package/types/popover-edit.d.ts +30 -30
- package/types/scrolling.d.ts +6 -6
- package/types/selection.d.ts +14 -14
- package/types/table-scroll-container.d.ts +6 -6
- package/fesm2022/_accordion-chunk.mjs +0 -153
- package/fesm2022/_accordion-chunk.mjs.map +0 -1
- package/fesm2022/_combobox-chunk.mjs +0 -278
- package/fesm2022/_combobox-chunk.mjs.map +0 -1
- package/fesm2022/_combobox-listbox-chunk.mjs +0 -278
- package/fesm2022/_combobox-listbox-chunk.mjs.map +0 -1
- package/fesm2022/_combobox-tree-chunk.mjs +0 -398
- package/fesm2022/_combobox-tree-chunk.mjs.map +0 -1
- package/fesm2022/_expansion-chunk.mjs +0 -87
- package/fesm2022/_expansion-chunk.mjs.map +0 -1
- package/fesm2022/_list-chunk.mjs +0 -374
- package/fesm2022/_list-chunk.mjs.map +0 -1
- package/fesm2022/_list-navigation-chunk.mjs +0 -131
- package/fesm2022/_list-navigation-chunk.mjs.map +0 -1
- package/fesm2022/_pointer-event-manager-chunk.mjs +0 -145
- package/fesm2022/_pointer-event-manager-chunk.mjs.map +0 -1
- package/fesm2022/_tabs-chunk.mjs +0 -211
- package/fesm2022/_tabs-chunk.mjs.map +0 -1
- package/fesm2022/_toolbar-chunk.mjs +0 -273
- package/fesm2022/_toolbar-chunk.mjs.map +0 -1
- package/fesm2022/_toolbar-radio-group-chunk.mjs +0 -222
- package/fesm2022/_toolbar-radio-group-chunk.mjs.map +0 -1
- package/fesm2022/accordion.mjs +0 -195
- package/fesm2022/accordion.mjs.map +0 -1
- package/fesm2022/combobox.mjs +0 -131
- package/fesm2022/combobox.mjs.map +0 -1
- package/fesm2022/deferred-content.mjs +0 -59
- package/fesm2022/deferred-content.mjs.map +0 -1
- package/fesm2022/listbox.mjs +0 -204
- package/fesm2022/listbox.mjs.map +0 -1
- package/fesm2022/radio-group.mjs +0 -200
- package/fesm2022/radio-group.mjs.map +0 -1
- package/fesm2022/tabs.mjs +0 -303
- package/fesm2022/tabs.mjs.map +0 -1
- package/fesm2022/toolbar.mjs +0 -221
- package/fesm2022/toolbar.mjs.map +0 -1
- package/fesm2022/tree.mjs +0 -333
- package/fesm2022/tree.mjs.map +0 -1
- package/fesm2022/ui-patterns.mjs +0 -24
- package/fesm2022/ui-patterns.mjs.map +0 -1
- package/types/_accordion-chunk.d.ts +0 -90
- package/types/_combobox-chunk.d.ts +0 -138
- package/types/_expansion-chunk.d.ts +0 -71
- package/types/_list-chunk.d.ts +0 -209
- package/types/_list-navigation-chunk.d.ts +0 -101
- package/types/_listbox-chunk.d.ts +0 -105
- package/types/_pointer-event-manager-chunk.d.ts +0 -98
- package/types/_radio-group-chunk.d.ts +0 -92
- package/types/_tabs-chunk.d.ts +0 -138
- package/types/_toolbar-chunk.d.ts +0 -150
- package/types/_tree-chunk.d.ts +0 -139
- package/types/accordion.d.ts +0 -95
- package/types/combobox.d.ts +0 -54
- package/types/deferred-content.d.ts +0 -37
- package/types/listbox.d.ts +0 -99
- package/types/radio-group.d.ts +0 -85
- package/types/tabs.d.ts +0 -160
- package/types/toolbar.d.ts +0 -115
- package/types/tree.d.ts +0 -155
- package/types/ui-patterns.d.ts +0 -157
package/fesm2022/_list-chunk.mjs
DELETED
|
@@ -1,374 +0,0 @@
|
|
|
1
|
-
import { signal, computed } from '@angular/core';
|
|
2
|
-
import { ListFocus, ListNavigation } from './_list-navigation-chunk.mjs';
|
|
3
|
-
|
|
4
|
-
/** Controls selection for a list of items. */
|
|
5
|
-
class ListSelection {
|
|
6
|
-
inputs;
|
|
7
|
-
/** The start index to use for range selection. */
|
|
8
|
-
rangeStartIndex = signal(0);
|
|
9
|
-
/** The end index to use for range selection. */
|
|
10
|
-
rangeEndIndex = signal(0);
|
|
11
|
-
/** The currently selected items. */
|
|
12
|
-
selectedItems = computed(() => this.inputs.items().filter(item => this.inputs.value().includes(item.value())));
|
|
13
|
-
constructor(inputs) {
|
|
14
|
-
this.inputs = inputs;
|
|
15
|
-
}
|
|
16
|
-
/** Selects the item at the current active index. */
|
|
17
|
-
select(item, opts = { anchor: true }) {
|
|
18
|
-
item = item ?? this.inputs.focusManager.inputs.activeItem();
|
|
19
|
-
if (!item || item.disabled() || this.inputs.value().includes(item.value())) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
if (!this.inputs.multi()) {
|
|
23
|
-
this.deselectAll();
|
|
24
|
-
}
|
|
25
|
-
const index = this.inputs.items().findIndex(i => i === item);
|
|
26
|
-
if (opts.anchor) {
|
|
27
|
-
this.beginRangeSelection(index);
|
|
28
|
-
}
|
|
29
|
-
this.inputs.value.update(values => values.concat(item.value()));
|
|
30
|
-
}
|
|
31
|
-
/** Deselects the item at the current active index. */
|
|
32
|
-
deselect(item) {
|
|
33
|
-
item = item ?? this.inputs.focusManager.inputs.activeItem();
|
|
34
|
-
if (item && !item.disabled()) {
|
|
35
|
-
this.inputs.value.update(values => values.filter(value => value !== item.value()));
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
/** Toggles the item at the current active index. */
|
|
39
|
-
toggle() {
|
|
40
|
-
const item = this.inputs.focusManager.inputs.activeItem();
|
|
41
|
-
if (item) {
|
|
42
|
-
this.inputs.value().includes(item.value()) ? this.deselect() : this.select();
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
/** Toggles only the item at the current active index. */
|
|
46
|
-
toggleOne() {
|
|
47
|
-
const item = this.inputs.focusManager.inputs.activeItem();
|
|
48
|
-
if (item) {
|
|
49
|
-
this.inputs.value().includes(item.value()) ? this.deselect() : this.selectOne();
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
/** Selects all items in the list. */
|
|
53
|
-
selectAll() {
|
|
54
|
-
if (!this.inputs.multi()) {
|
|
55
|
-
return; // Should we log a warning?
|
|
56
|
-
}
|
|
57
|
-
for (const item of this.inputs.items()) {
|
|
58
|
-
this.select(item, { anchor: false });
|
|
59
|
-
}
|
|
60
|
-
this.beginRangeSelection();
|
|
61
|
-
}
|
|
62
|
-
/** Deselects all items in the list. */
|
|
63
|
-
deselectAll() {
|
|
64
|
-
// If an item is not in the list, it forcefully gets deselected.
|
|
65
|
-
// This actually creates a bug for the following edge case:
|
|
66
|
-
//
|
|
67
|
-
// Setup: An item is not in the list (maybe it's lazily loaded), and it is disabled & selected.
|
|
68
|
-
// Expected: If deselectAll() is called, it should NOT get deselected (because it is disabled).
|
|
69
|
-
// Actual: Calling deselectAll() will still deselect the item.
|
|
70
|
-
//
|
|
71
|
-
// Why? Because we can't check if the item is disabled if it's not in the list.
|
|
72
|
-
//
|
|
73
|
-
// Alternatively, we could NOT deselect items that are not in the list, but this has the
|
|
74
|
-
// inverse (and more common) effect of keeping enabled items selected when they aren't in the
|
|
75
|
-
// list.
|
|
76
|
-
for (const value of this.inputs.value()) {
|
|
77
|
-
const item = this.inputs.items().find(i => i.value() === value);
|
|
78
|
-
item
|
|
79
|
-
? this.deselect(item)
|
|
80
|
-
: this.inputs.value.update(values => values.filter(v => v !== value));
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Selects all items in the list or deselects all
|
|
85
|
-
* items in the list if all items are already selected.
|
|
86
|
-
*/
|
|
87
|
-
toggleAll() {
|
|
88
|
-
const selectableValues = this.inputs
|
|
89
|
-
.items()
|
|
90
|
-
.filter(i => !i.disabled())
|
|
91
|
-
.map(i => i.value());
|
|
92
|
-
selectableValues.every(i => this.inputs.value().includes(i))
|
|
93
|
-
? this.deselectAll()
|
|
94
|
-
: this.selectAll();
|
|
95
|
-
}
|
|
96
|
-
/** Sets the selection to only the current active item. */
|
|
97
|
-
selectOne() {
|
|
98
|
-
const item = this.inputs.focusManager.inputs.activeItem();
|
|
99
|
-
if (item && item.disabled()) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
this.deselectAll();
|
|
103
|
-
if (this.inputs.value().length > 0 && !this.inputs.multi()) {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
this.select();
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Selects all items in the list up to the anchor item.
|
|
110
|
-
*
|
|
111
|
-
* Deselects all items that were previously within the
|
|
112
|
-
* selected range that are now outside of the selected range
|
|
113
|
-
*/
|
|
114
|
-
selectRange(opts = { anchor: true }) {
|
|
115
|
-
const isStartOfRange = this.inputs.focusManager.prevActiveIndex() === this.rangeStartIndex();
|
|
116
|
-
if (isStartOfRange && opts.anchor) {
|
|
117
|
-
this.beginRangeSelection(this.inputs.focusManager.prevActiveIndex());
|
|
118
|
-
}
|
|
119
|
-
const itemsInRange = this._getItemsFromIndex(this.rangeStartIndex());
|
|
120
|
-
const itemsOutOfRange = this._getItemsFromIndex(this.rangeEndIndex()).filter(i => !itemsInRange.includes(i));
|
|
121
|
-
for (const item of itemsOutOfRange) {
|
|
122
|
-
this.deselect(item);
|
|
123
|
-
}
|
|
124
|
-
for (const item of itemsInRange) {
|
|
125
|
-
this.select(item, { anchor: false });
|
|
126
|
-
}
|
|
127
|
-
if (itemsInRange.length) {
|
|
128
|
-
const item = itemsInRange.pop();
|
|
129
|
-
const index = this.inputs.items().findIndex(i => i === item);
|
|
130
|
-
this.rangeEndIndex.set(index);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
/** Marks the given index as the start of a range selection. */
|
|
134
|
-
beginRangeSelection(index = this.inputs.focusManager.activeIndex()) {
|
|
135
|
-
this.rangeStartIndex.set(index);
|
|
136
|
-
this.rangeEndIndex.set(index);
|
|
137
|
-
}
|
|
138
|
-
/** Returns the items in the list starting from the given index. */
|
|
139
|
-
_getItemsFromIndex(index) {
|
|
140
|
-
if (index === -1) {
|
|
141
|
-
return [];
|
|
142
|
-
}
|
|
143
|
-
const upper = Math.max(this.inputs.focusManager.activeIndex(), index);
|
|
144
|
-
const lower = Math.min(this.inputs.focusManager.activeIndex(), index);
|
|
145
|
-
const items = [];
|
|
146
|
-
for (let i = lower; i <= upper; i++) {
|
|
147
|
-
items.push(this.inputs.items()[i]);
|
|
148
|
-
}
|
|
149
|
-
if (this.inputs.focusManager.activeIndex() < index) {
|
|
150
|
-
return items.reverse();
|
|
151
|
-
}
|
|
152
|
-
return items;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/** Controls typeahead for a list of items. */
|
|
157
|
-
class ListTypeahead {
|
|
158
|
-
inputs;
|
|
159
|
-
/** A reference to the timeout for resetting the typeahead search. */
|
|
160
|
-
timeout;
|
|
161
|
-
/** The focus controller of the parent list. */
|
|
162
|
-
focusManager;
|
|
163
|
-
/** Whether the user is actively typing a typeahead search query. */
|
|
164
|
-
isTyping = computed(() => this._query().length > 0);
|
|
165
|
-
/** Keeps track of the characters that typeahead search is being called with. */
|
|
166
|
-
_query = signal('');
|
|
167
|
-
/** The index where that the typeahead search was initiated from. */
|
|
168
|
-
_startIndex = signal(undefined);
|
|
169
|
-
constructor(inputs) {
|
|
170
|
-
this.inputs = inputs;
|
|
171
|
-
this.focusManager = inputs.focusManager;
|
|
172
|
-
}
|
|
173
|
-
/** Performs a typeahead search, appending the given character to the search string. */
|
|
174
|
-
search(char) {
|
|
175
|
-
if (char.length !== 1) {
|
|
176
|
-
return false;
|
|
177
|
-
}
|
|
178
|
-
if (!this.isTyping() && char === ' ') {
|
|
179
|
-
return false;
|
|
180
|
-
}
|
|
181
|
-
if (this._startIndex() === undefined) {
|
|
182
|
-
this._startIndex.set(this.focusManager.activeIndex());
|
|
183
|
-
}
|
|
184
|
-
clearTimeout(this.timeout);
|
|
185
|
-
this._query.update(q => q + char.toLowerCase());
|
|
186
|
-
const item = this._getItem();
|
|
187
|
-
if (item) {
|
|
188
|
-
this.focusManager.focus(item);
|
|
189
|
-
}
|
|
190
|
-
this.timeout = setTimeout(() => {
|
|
191
|
-
this._query.set('');
|
|
192
|
-
this._startIndex.set(undefined);
|
|
193
|
-
}, this.inputs.typeaheadDelay() * 1000);
|
|
194
|
-
return true;
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Returns the first item whose search term matches the
|
|
198
|
-
* current query starting from the the current anchor index.
|
|
199
|
-
*/
|
|
200
|
-
_getItem() {
|
|
201
|
-
let items = this.focusManager.inputs.items();
|
|
202
|
-
const after = items.slice(this._startIndex() + 1);
|
|
203
|
-
const before = items.slice(0, this._startIndex());
|
|
204
|
-
items = after.concat(before);
|
|
205
|
-
items.push(this.inputs.items()[this._startIndex()]);
|
|
206
|
-
const focusableItems = [];
|
|
207
|
-
for (const item of items) {
|
|
208
|
-
if (this.focusManager.isFocusable(item)) {
|
|
209
|
-
focusableItems.push(item);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
return focusableItems.find(i => i.searchTerm().toLowerCase().startsWith(this._query()));
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/** Controls the state of a list. */
|
|
217
|
-
class List {
|
|
218
|
-
inputs;
|
|
219
|
-
/** Controls navigation for the list. */
|
|
220
|
-
navigationBehavior;
|
|
221
|
-
/** Controls selection for the list. */
|
|
222
|
-
selectionBehavior;
|
|
223
|
-
/** Controls typeahead for the list. */
|
|
224
|
-
typeaheadBehavior;
|
|
225
|
-
/** Controls focus for the list. */
|
|
226
|
-
focusBehavior;
|
|
227
|
-
/** Whether the list is disabled. */
|
|
228
|
-
disabled = computed(() => this.focusBehavior.isListDisabled());
|
|
229
|
-
/** The id of the current active item. */
|
|
230
|
-
activedescendant = computed(() => this.focusBehavior.getActiveDescendant());
|
|
231
|
-
/** The tabindex of the list. */
|
|
232
|
-
tabindex = computed(() => this.focusBehavior.getListTabindex());
|
|
233
|
-
/** The index of the currently active item in the list. */
|
|
234
|
-
activeIndex = computed(() => this.focusBehavior.activeIndex());
|
|
235
|
-
/**
|
|
236
|
-
* The uncommitted index for selecting a range of options.
|
|
237
|
-
*
|
|
238
|
-
* NOTE: This is subtly distinct from the "rangeStartIndex" in the ListSelection behavior.
|
|
239
|
-
* The anchorIndex does not necessarily represent the start of a range, but represents the most
|
|
240
|
-
* recent index where the user showed intent to begin a range selection. Usually, this is wherever
|
|
241
|
-
* the user most recently pressed the "Shift" key, but if the user presses shift + space to select
|
|
242
|
-
* from the anchor, the user is not intending to start a new range from this index.
|
|
243
|
-
*
|
|
244
|
-
* In other words, "rangeStartIndex" is only set when a user commits to starting a range selection
|
|
245
|
-
* while "anchorIndex" is set whenever a user indicates they may be starting a range selection.
|
|
246
|
-
*/
|
|
247
|
-
_anchorIndex = signal(0);
|
|
248
|
-
/** Whether the list should wrap. Used to disable wrapping while range selecting. */
|
|
249
|
-
_wrap = signal(true);
|
|
250
|
-
constructor(inputs) {
|
|
251
|
-
this.inputs = inputs;
|
|
252
|
-
this.focusBehavior = new ListFocus(inputs);
|
|
253
|
-
this.selectionBehavior = new ListSelection({ ...inputs, focusManager: this.focusBehavior });
|
|
254
|
-
this.typeaheadBehavior = new ListTypeahead({ ...inputs, focusManager: this.focusBehavior });
|
|
255
|
-
this.navigationBehavior = new ListNavigation({
|
|
256
|
-
...inputs,
|
|
257
|
-
focusManager: this.focusBehavior,
|
|
258
|
-
wrap: computed(() => this._wrap() && this.inputs.wrap()),
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
/** Returns the tabindex for the given item. */
|
|
262
|
-
getItemTabindex(item) {
|
|
263
|
-
return this.focusBehavior.getItemTabindex(item);
|
|
264
|
-
}
|
|
265
|
-
/** Navigates to the first option in the list. */
|
|
266
|
-
first(opts) {
|
|
267
|
-
this._navigate(opts, () => this.navigationBehavior.first());
|
|
268
|
-
}
|
|
269
|
-
/** Navigates to the last option in the list. */
|
|
270
|
-
last(opts) {
|
|
271
|
-
this._navigate(opts, () => this.navigationBehavior.last());
|
|
272
|
-
}
|
|
273
|
-
/** Navigates to the next option in the list. */
|
|
274
|
-
next(opts) {
|
|
275
|
-
this._navigate(opts, () => this.navigationBehavior.next());
|
|
276
|
-
}
|
|
277
|
-
/** Navigates to the previous option in the list. */
|
|
278
|
-
prev(opts) {
|
|
279
|
-
this._navigate(opts, () => this.navigationBehavior.prev());
|
|
280
|
-
}
|
|
281
|
-
/** Navigates to the given item in the list. */
|
|
282
|
-
goto(item, opts) {
|
|
283
|
-
this._navigate(opts, () => this.navigationBehavior.goto(item));
|
|
284
|
-
}
|
|
285
|
-
/** Removes focus from the list. */
|
|
286
|
-
unfocus() {
|
|
287
|
-
this.inputs.activeItem.set(undefined);
|
|
288
|
-
}
|
|
289
|
-
/** Marks the given index as the potential start of a range selection. */
|
|
290
|
-
anchor(index) {
|
|
291
|
-
this._anchorIndex.set(index);
|
|
292
|
-
}
|
|
293
|
-
/** Handles typeahead search navigation for the list. */
|
|
294
|
-
search(char, opts) {
|
|
295
|
-
this._navigate(opts, () => this.typeaheadBehavior.search(char));
|
|
296
|
-
}
|
|
297
|
-
/** Checks if the list is currently typing for typeahead search. */
|
|
298
|
-
isTyping() {
|
|
299
|
-
return this.typeaheadBehavior.isTyping();
|
|
300
|
-
}
|
|
301
|
-
/** Selects the currently active item in the list. */
|
|
302
|
-
select(item) {
|
|
303
|
-
this.selectionBehavior.select(item);
|
|
304
|
-
}
|
|
305
|
-
/** Sets the selection to only the current active item. */
|
|
306
|
-
selectOne() {
|
|
307
|
-
this.selectionBehavior.selectOne();
|
|
308
|
-
}
|
|
309
|
-
/** Deselects the currently active item in the list. */
|
|
310
|
-
deselect() {
|
|
311
|
-
this.selectionBehavior.deselect();
|
|
312
|
-
}
|
|
313
|
-
/** Deselects all items in the list. */
|
|
314
|
-
deselectAll() {
|
|
315
|
-
this.selectionBehavior.deselectAll();
|
|
316
|
-
}
|
|
317
|
-
/** Toggles the currently active item in the list. */
|
|
318
|
-
toggle() {
|
|
319
|
-
this.selectionBehavior.toggle();
|
|
320
|
-
}
|
|
321
|
-
/** Toggles the currently active item in the list, deselecting all other items. */
|
|
322
|
-
toggleOne() {
|
|
323
|
-
this.selectionBehavior.toggleOne();
|
|
324
|
-
}
|
|
325
|
-
/** Toggles the selection of all items in the list. */
|
|
326
|
-
toggleAll() {
|
|
327
|
-
this.selectionBehavior.toggleAll();
|
|
328
|
-
}
|
|
329
|
-
/** Checks if the given item is able to receive focus. */
|
|
330
|
-
isFocusable(item) {
|
|
331
|
-
return this.focusBehavior.isFocusable(item);
|
|
332
|
-
}
|
|
333
|
-
/** Handles updating selection for the list. */
|
|
334
|
-
updateSelection(opts = { anchor: true }) {
|
|
335
|
-
if (opts.toggle) {
|
|
336
|
-
this.selectionBehavior.toggle();
|
|
337
|
-
}
|
|
338
|
-
if (opts.select) {
|
|
339
|
-
this.selectionBehavior.select();
|
|
340
|
-
}
|
|
341
|
-
if (opts.selectOne) {
|
|
342
|
-
this.selectionBehavior.selectOne();
|
|
343
|
-
}
|
|
344
|
-
if (opts.selectRange) {
|
|
345
|
-
this.selectionBehavior.selectRange();
|
|
346
|
-
}
|
|
347
|
-
if (!opts.anchor) {
|
|
348
|
-
this.anchor(this.selectionBehavior.rangeStartIndex());
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
/**
|
|
352
|
-
* Safely performs a navigation operation.
|
|
353
|
-
*
|
|
354
|
-
* Handles conditionally disabling wrapping for when a navigation
|
|
355
|
-
* operation is occurring while the user is selecting a range of options.
|
|
356
|
-
*
|
|
357
|
-
* Handles boilerplate calling of focus & selection operations. Also ensures these
|
|
358
|
-
* additional operations are only called if the navigation operation moved focus to a new option.
|
|
359
|
-
*/
|
|
360
|
-
_navigate(opts = {}, operation) {
|
|
361
|
-
if (opts?.selectRange) {
|
|
362
|
-
this._wrap.set(false);
|
|
363
|
-
this.selectionBehavior.rangeStartIndex.set(this._anchorIndex());
|
|
364
|
-
}
|
|
365
|
-
const moved = operation();
|
|
366
|
-
if (moved) {
|
|
367
|
-
this.updateSelection(opts);
|
|
368
|
-
}
|
|
369
|
-
this._wrap.set(true);
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
export { List };
|
|
374
|
-
//# sourceMappingURL=_list-chunk.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_list-chunk.mjs","sources":["../../../../../k8-fastbuild-ST-199a4f3c4e20/bin/src/cdk-experimental/ui-patterns/behaviors/list-selection/list-selection.ts","../../../../../k8-fastbuild-ST-199a4f3c4e20/bin/src/cdk-experimental/ui-patterns/behaviors/list-typeahead/list-typeahead.ts","../../../../../k8-fastbuild-ST-199a4f3c4e20/bin/src/cdk-experimental/ui-patterns/behaviors/list/list.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {computed, signal} from '@angular/core';\nimport {SignalLike, WritableSignalLike} from '../signal-like/signal-like';\nimport {ListFocus, ListFocusInputs, ListFocusItem} from '../list-focus/list-focus';\n\n/** Represents an item in a collection, such as a listbox option, than can be selected. */\nexport interface ListSelectionItem<V> extends ListFocusItem {\n /** The value of the item. */\n value: SignalLike<V>;\n}\n\n/** Represents the required inputs for a collection that contains selectable items. */\nexport interface ListSelectionInputs<T extends ListSelectionItem<V>, V> extends ListFocusInputs<T> {\n /** Whether multiple items in the list can be selected at once. */\n multi: SignalLike<boolean>;\n\n /** The current value of the list selection. */\n value: WritableSignalLike<V[]>;\n\n /** The selection strategy used by the list. */\n selectionMode: SignalLike<'follow' | 'explicit'>;\n}\n\n/** Controls selection for a list of items. */\nexport class ListSelection<T extends ListSelectionItem<V>, V> {\n /** The start index to use for range selection. */\n rangeStartIndex = signal<number>(0);\n\n /** The end index to use for range selection. */\n rangeEndIndex = signal<number>(0);\n\n /** The currently selected items. */\n selectedItems = computed(() =>\n this.inputs.items().filter(item => this.inputs.value().includes(item.value())),\n );\n\n constructor(readonly inputs: ListSelectionInputs<T, V> & {focusManager: ListFocus<T>}) {}\n\n /** Selects the item at the current active index. */\n select(item?: ListSelectionItem<V>, opts = {anchor: true}) {\n item = item ?? (this.inputs.focusManager.inputs.activeItem() as ListSelectionItem<V>);\n\n if (!item || item.disabled() || this.inputs.value().includes(item.value())) {\n return;\n }\n\n if (!this.inputs.multi()) {\n this.deselectAll();\n }\n\n const index = this.inputs.items().findIndex(i => i === item);\n if (opts.anchor) {\n this.beginRangeSelection(index);\n }\n this.inputs.value.update(values => values.concat(item.value()));\n }\n\n /** Deselects the item at the current active index. */\n deselect(item?: T | null) {\n item = item ?? this.inputs.focusManager.inputs.activeItem();\n\n if (item && !item.disabled()) {\n this.inputs.value.update(values => values.filter(value => value !== item.value()));\n }\n }\n\n /** Toggles the item at the current active index. */\n toggle() {\n const item = this.inputs.focusManager.inputs.activeItem();\n if (item) {\n this.inputs.value().includes(item.value()) ? this.deselect() : this.select();\n }\n }\n\n /** Toggles only the item at the current active index. */\n toggleOne() {\n const item = this.inputs.focusManager.inputs.activeItem();\n if (item) {\n this.inputs.value().includes(item.value()) ? this.deselect() : this.selectOne();\n }\n }\n\n /** Selects all items in the list. */\n selectAll() {\n if (!this.inputs.multi()) {\n return; // Should we log a warning?\n }\n\n for (const item of this.inputs.items()) {\n this.select(item, {anchor: false});\n }\n\n this.beginRangeSelection();\n }\n\n /** Deselects all items in the list. */\n deselectAll() {\n // If an item is not in the list, it forcefully gets deselected.\n // This actually creates a bug for the following edge case:\n //\n // Setup: An item is not in the list (maybe it's lazily loaded), and it is disabled & selected.\n // Expected: If deselectAll() is called, it should NOT get deselected (because it is disabled).\n // Actual: Calling deselectAll() will still deselect the item.\n //\n // Why? Because we can't check if the item is disabled if it's not in the list.\n //\n // Alternatively, we could NOT deselect items that are not in the list, but this has the\n // inverse (and more common) effect of keeping enabled items selected when they aren't in the\n // list.\n\n for (const value of this.inputs.value()) {\n const item = this.inputs.items().find(i => i.value() === value);\n\n item\n ? this.deselect(item)\n : this.inputs.value.update(values => values.filter(v => v !== value));\n }\n }\n\n /**\n * Selects all items in the list or deselects all\n * items in the list if all items are already selected.\n */\n toggleAll() {\n const selectableValues = this.inputs\n .items()\n .filter(i => !i.disabled())\n .map(i => i.value());\n\n selectableValues.every(i => this.inputs.value().includes(i))\n ? this.deselectAll()\n : this.selectAll();\n }\n\n /** Sets the selection to only the current active item. */\n selectOne() {\n const item = this.inputs.focusManager.inputs.activeItem();\n if (item && item.disabled()) {\n return;\n }\n\n this.deselectAll();\n\n if (this.inputs.value().length > 0 && !this.inputs.multi()) {\n return;\n }\n\n this.select();\n }\n\n /**\n * Selects all items in the list up to the anchor item.\n *\n * Deselects all items that were previously within the\n * selected range that are now outside of the selected range\n */\n selectRange(opts = {anchor: true}) {\n const isStartOfRange = this.inputs.focusManager.prevActiveIndex() === this.rangeStartIndex();\n\n if (isStartOfRange && opts.anchor) {\n this.beginRangeSelection(this.inputs.focusManager.prevActiveIndex());\n }\n\n const itemsInRange = this._getItemsFromIndex(this.rangeStartIndex());\n const itemsOutOfRange = this._getItemsFromIndex(this.rangeEndIndex()).filter(\n i => !itemsInRange.includes(i),\n );\n\n for (const item of itemsOutOfRange) {\n this.deselect(item);\n }\n\n for (const item of itemsInRange) {\n this.select(item, {anchor: false});\n }\n\n if (itemsInRange.length) {\n const item = itemsInRange.pop();\n const index = this.inputs.items().findIndex(i => i === item);\n this.rangeEndIndex.set(index);\n }\n }\n\n /** Marks the given index as the start of a range selection. */\n beginRangeSelection(index: number = this.inputs.focusManager.activeIndex()) {\n this.rangeStartIndex.set(index);\n this.rangeEndIndex.set(index);\n }\n\n /** Returns the items in the list starting from the given index. */\n private _getItemsFromIndex(index: number) {\n if (index === -1) {\n return [];\n }\n\n const upper = Math.max(this.inputs.focusManager.activeIndex(), index);\n const lower = Math.min(this.inputs.focusManager.activeIndex(), index);\n\n const items = [];\n for (let i = lower; i <= upper; i++) {\n items.push(this.inputs.items()[i]);\n }\n\n if (this.inputs.focusManager.activeIndex() < index) {\n return items.reverse();\n }\n\n return items;\n }\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {computed, signal} from '@angular/core';\nimport {SignalLike} from '../signal-like/signal-like';\nimport {ListFocus, ListFocusInputs, ListFocusItem} from '../list-focus/list-focus';\n\n/**\n * Represents an item in a collection, such as a listbox option, than can be navigated to by\n * typeahead.\n */\nexport interface ListTypeaheadItem extends ListFocusItem {\n /** The text used by the typeahead search. */\n searchTerm: SignalLike<string>;\n}\n\n/**\n * Represents the required inputs for a collection that contains items that can be navigated to by\n * typeahead.\n */\nexport interface ListTypeaheadInputs<T extends ListTypeaheadItem> extends ListFocusInputs<T> {\n /** The amount of time before the typeahead search is reset. */\n typeaheadDelay: SignalLike<number>;\n}\n\n/** Controls typeahead for a list of items. */\nexport class ListTypeahead<T extends ListTypeaheadItem> {\n /** A reference to the timeout for resetting the typeahead search. */\n timeout?: ReturnType<typeof setTimeout> | undefined;\n\n /** The focus controller of the parent list. */\n focusManager: ListFocus<T>;\n\n /** Whether the user is actively typing a typeahead search query. */\n isTyping = computed(() => this._query().length > 0);\n\n /** Keeps track of the characters that typeahead search is being called with. */\n private _query = signal('');\n\n /** The index where that the typeahead search was initiated from. */\n private _startIndex = signal<number | undefined>(undefined);\n\n constructor(readonly inputs: ListTypeaheadInputs<T> & {focusManager: ListFocus<T>}) {\n this.focusManager = inputs.focusManager;\n }\n\n /** Performs a typeahead search, appending the given character to the search string. */\n search(char: string): boolean {\n if (char.length !== 1) {\n return false;\n }\n\n if (!this.isTyping() && char === ' ') {\n return false;\n }\n\n if (this._startIndex() === undefined) {\n this._startIndex.set(this.focusManager.activeIndex());\n }\n\n clearTimeout(this.timeout);\n this._query.update(q => q + char.toLowerCase());\n const item = this._getItem();\n\n if (item) {\n this.focusManager.focus(item);\n }\n\n this.timeout = setTimeout(() => {\n this._query.set('');\n this._startIndex.set(undefined);\n }, this.inputs.typeaheadDelay() * 1000);\n\n return true;\n }\n\n /**\n * Returns the first item whose search term matches the\n * current query starting from the the current anchor index.\n */\n private _getItem() {\n let items = this.focusManager.inputs.items();\n const after = items.slice(this._startIndex()! + 1);\n const before = items.slice(0, this._startIndex()!);\n items = after.concat(before);\n items.push(this.inputs.items()[this._startIndex()!]);\n\n const focusableItems = [];\n for (const item of items) {\n if (this.focusManager.isFocusable(item)) {\n focusableItems.push(item);\n }\n }\n\n return focusableItems.find(i => i.searchTerm().toLowerCase().startsWith(this._query()));\n }\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {computed, signal} from '@angular/core';\nimport {ListFocus, ListFocusInputs, ListFocusItem} from '../list-focus/list-focus';\nimport {\n ListNavigation,\n ListNavigationInputs,\n ListNavigationItem,\n} from '../list-navigation/list-navigation';\nimport {\n ListSelection,\n ListSelectionInputs,\n ListSelectionItem,\n} from '../list-selection/list-selection';\nimport {\n ListTypeahead,\n ListTypeaheadInputs,\n ListTypeaheadItem,\n} from '../list-typeahead/list-typeahead';\n\n/** The selection operations that the list can perform. */\ninterface SelectOptions {\n toggle?: boolean;\n select?: boolean;\n selectOne?: boolean;\n selectRange?: boolean;\n anchor?: boolean;\n}\n\n/** Represents an item in the list. */\nexport type ListItem<V> = ListTypeaheadItem &\n ListNavigationItem &\n ListSelectionItem<V> &\n ListFocusItem;\n\n/** The necessary inputs for the list behavior. */\nexport type ListInputs<T extends ListItem<V>, V> = ListFocusInputs<T> &\n ListNavigationInputs<T> &\n ListSelectionInputs<T, V> &\n ListTypeaheadInputs<T>;\n\n/** Controls the state of a list. */\nexport class List<T extends ListItem<V>, V> {\n /** Controls navigation for the list. */\n navigationBehavior: ListNavigation<T>;\n\n /** Controls selection for the list. */\n selectionBehavior: ListSelection<T, V>;\n\n /** Controls typeahead for the list. */\n typeaheadBehavior: ListTypeahead<T>;\n\n /** Controls focus for the list. */\n focusBehavior: ListFocus<T>;\n\n /** Whether the list is disabled. */\n disabled = computed(() => this.focusBehavior.isListDisabled());\n\n /** The id of the current active item. */\n activedescendant = computed(() => this.focusBehavior.getActiveDescendant());\n\n /** The tabindex of the list. */\n tabindex = computed(() => this.focusBehavior.getListTabindex());\n\n /** The index of the currently active item in the list. */\n activeIndex = computed(() => this.focusBehavior.activeIndex());\n\n /**\n * The uncommitted index for selecting a range of options.\n *\n * NOTE: This is subtly distinct from the \"rangeStartIndex\" in the ListSelection behavior.\n * The anchorIndex does not necessarily represent the start of a range, but represents the most\n * recent index where the user showed intent to begin a range selection. Usually, this is wherever\n * the user most recently pressed the \"Shift\" key, but if the user presses shift + space to select\n * from the anchor, the user is not intending to start a new range from this index.\n *\n * In other words, \"rangeStartIndex\" is only set when a user commits to starting a range selection\n * while \"anchorIndex\" is set whenever a user indicates they may be starting a range selection.\n */\n private _anchorIndex = signal(0);\n\n /** Whether the list should wrap. Used to disable wrapping while range selecting. */\n private _wrap = signal(true);\n\n constructor(readonly inputs: ListInputs<T, V>) {\n this.focusBehavior = new ListFocus(inputs);\n this.selectionBehavior = new ListSelection({...inputs, focusManager: this.focusBehavior});\n this.typeaheadBehavior = new ListTypeahead({...inputs, focusManager: this.focusBehavior});\n this.navigationBehavior = new ListNavigation({\n ...inputs,\n focusManager: this.focusBehavior,\n wrap: computed(() => this._wrap() && this.inputs.wrap()),\n });\n }\n\n /** Returns the tabindex for the given item. */\n getItemTabindex(item: T) {\n return this.focusBehavior.getItemTabindex(item);\n }\n\n /** Navigates to the first option in the list. */\n first(opts?: SelectOptions) {\n this._navigate(opts, () => this.navigationBehavior.first());\n }\n\n /** Navigates to the last option in the list. */\n last(opts?: SelectOptions) {\n this._navigate(opts, () => this.navigationBehavior.last());\n }\n\n /** Navigates to the next option in the list. */\n next(opts?: SelectOptions) {\n this._navigate(opts, () => this.navigationBehavior.next());\n }\n\n /** Navigates to the previous option in the list. */\n prev(opts?: SelectOptions) {\n this._navigate(opts, () => this.navigationBehavior.prev());\n }\n\n /** Navigates to the given item in the list. */\n goto(item: T, opts?: SelectOptions) {\n this._navigate(opts, () => this.navigationBehavior.goto(item));\n }\n\n /** Removes focus from the list. */\n unfocus() {\n this.inputs.activeItem.set(undefined);\n }\n\n /** Marks the given index as the potential start of a range selection. */\n anchor(index: number) {\n this._anchorIndex.set(index);\n }\n\n /** Handles typeahead search navigation for the list. */\n search(char: string, opts?: SelectOptions) {\n this._navigate(opts, () => this.typeaheadBehavior.search(char));\n }\n\n /** Checks if the list is currently typing for typeahead search. */\n isTyping() {\n return this.typeaheadBehavior.isTyping();\n }\n\n /** Selects the currently active item in the list. */\n select(item?: T) {\n this.selectionBehavior.select(item);\n }\n\n /** Sets the selection to only the current active item. */\n selectOne() {\n this.selectionBehavior.selectOne();\n }\n\n /** Deselects the currently active item in the list. */\n deselect() {\n this.selectionBehavior.deselect();\n }\n\n /** Deselects all items in the list. */\n deselectAll() {\n this.selectionBehavior.deselectAll();\n }\n\n /** Toggles the currently active item in the list. */\n toggle() {\n this.selectionBehavior.toggle();\n }\n\n /** Toggles the currently active item in the list, deselecting all other items. */\n toggleOne() {\n this.selectionBehavior.toggleOne();\n }\n\n /** Toggles the selection of all items in the list. */\n toggleAll() {\n this.selectionBehavior.toggleAll();\n }\n\n /** Checks if the given item is able to receive focus. */\n isFocusable(item: T) {\n return this.focusBehavior.isFocusable(item);\n }\n\n /** Handles updating selection for the list. */\n updateSelection(opts: SelectOptions = {anchor: true}) {\n if (opts.toggle) {\n this.selectionBehavior.toggle();\n }\n if (opts.select) {\n this.selectionBehavior.select();\n }\n if (opts.selectOne) {\n this.selectionBehavior.selectOne();\n }\n if (opts.selectRange) {\n this.selectionBehavior.selectRange();\n }\n if (!opts.anchor) {\n this.anchor(this.selectionBehavior.rangeStartIndex());\n }\n }\n\n /**\n * Safely performs a navigation operation.\n *\n * Handles conditionally disabling wrapping for when a navigation\n * operation is occurring while the user is selecting a range of options.\n *\n * Handles boilerplate calling of focus & selection operations. Also ensures these\n * additional operations are only called if the navigation operation moved focus to a new option.\n */\n private _navigate(opts: SelectOptions = {}, operation: () => boolean) {\n if (opts?.selectRange) {\n this._wrap.set(false);\n this.selectionBehavior.rangeStartIndex.set(this._anchorIndex());\n }\n\n const moved = operation();\n\n if (moved) {\n this.updateSelection(opts);\n }\n\n this._wrap.set(true);\n }\n}\n"],"names":[],"mappings":";;;AA8BA;MACa,aAAa,CAAA;AAYH,IAAA,MAAA;;AAVrB,IAAA,eAAe,GAAG,MAAM,CAAS,CAAC,CAAC;;AAGnC,IAAA,aAAa,GAAG,MAAM,CAAS,CAAC,CAAC;;AAGjC,IAAA,aAAa,GAAG,QAAQ,CAAC,MACvB,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,MAAM,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAC/E;AAED,IAAA,WAAA,CAAqB,MAAgE,EAAA;QAAhE,IAAM,CAAA,MAAA,GAAN,MAAM;;;IAG3B,MAAM,CAAC,IAA2B,EAAE,IAAI,GAAG,EAAC,MAAM,EAAE,IAAI,EAAC,EAAA;AACvD,QAAA,IAAI,GAAG,IAAI,IAAK,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,UAAU,EAA2B;QAErF,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,QAAQ,EAAE,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE;YAC1E;;QAGF,IAAI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AI,KAAK,EAAE;AACT,YAAA,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC;;AAG5B,QAAA,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;;AAEvB;;;;"}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { signal, computed } from '@angular/core';
|
|
2
|
-
|
|
3
|
-
/** Controls focus for a list of items. */
|
|
4
|
-
class ListFocus {
|
|
5
|
-
inputs;
|
|
6
|
-
/** The last item that was active. */
|
|
7
|
-
prevActiveItem = signal(undefined);
|
|
8
|
-
/** The index of the last item that was active. */
|
|
9
|
-
prevActiveIndex = computed(() => {
|
|
10
|
-
return this.prevActiveItem() ? this.inputs.items().indexOf(this.prevActiveItem()) : -1;
|
|
11
|
-
});
|
|
12
|
-
/** The current active index in the list. */
|
|
13
|
-
activeIndex = computed(() => {
|
|
14
|
-
return this.inputs.activeItem() ? this.inputs.items().indexOf(this.inputs.activeItem()) : -1;
|
|
15
|
-
});
|
|
16
|
-
constructor(inputs) {
|
|
17
|
-
this.inputs = inputs;
|
|
18
|
-
}
|
|
19
|
-
/** Whether the list is in a disabled state. */
|
|
20
|
-
isListDisabled() {
|
|
21
|
-
return this.inputs.disabled() || this.inputs.items().every(i => i.disabled());
|
|
22
|
-
}
|
|
23
|
-
/** The id of the current active item. */
|
|
24
|
-
getActiveDescendant() {
|
|
25
|
-
if (this.isListDisabled()) {
|
|
26
|
-
return undefined;
|
|
27
|
-
}
|
|
28
|
-
if (this.inputs.focusMode() === 'roving') {
|
|
29
|
-
return undefined;
|
|
30
|
-
}
|
|
31
|
-
return this.inputs.activeItem()?.id() ?? undefined;
|
|
32
|
-
}
|
|
33
|
-
/** The tabindex for the list. */
|
|
34
|
-
getListTabindex() {
|
|
35
|
-
if (this.isListDisabled()) {
|
|
36
|
-
return 0;
|
|
37
|
-
}
|
|
38
|
-
return this.inputs.focusMode() === 'activedescendant' ? 0 : -1;
|
|
39
|
-
}
|
|
40
|
-
/** Returns the tabindex for the given item. */
|
|
41
|
-
getItemTabindex(item) {
|
|
42
|
-
if (this.isListDisabled()) {
|
|
43
|
-
return -1;
|
|
44
|
-
}
|
|
45
|
-
if (this.inputs.focusMode() === 'activedescendant') {
|
|
46
|
-
return -1;
|
|
47
|
-
}
|
|
48
|
-
return this.inputs.activeItem() === item ? 0 : -1;
|
|
49
|
-
}
|
|
50
|
-
/** Moves focus to the given item if it is focusable. */
|
|
51
|
-
focus(item) {
|
|
52
|
-
if (this.isListDisabled() || !this.isFocusable(item)) {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
this.prevActiveItem.set(this.inputs.activeItem());
|
|
56
|
-
this.inputs.activeItem.set(item);
|
|
57
|
-
this.inputs.focusMode() === 'roving' ? item.element().focus() : this.inputs.element()?.focus();
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
/** Returns true if the given item can be navigated to. */
|
|
61
|
-
isFocusable(item) {
|
|
62
|
-
return !item.disabled() || !this.inputs.skipDisabled();
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/** Controls navigation for a list of items. */
|
|
67
|
-
class ListNavigation {
|
|
68
|
-
inputs;
|
|
69
|
-
constructor(inputs) {
|
|
70
|
-
this.inputs = inputs;
|
|
71
|
-
}
|
|
72
|
-
/** Navigates to the given item. */
|
|
73
|
-
goto(item) {
|
|
74
|
-
return item ? this.inputs.focusManager.focus(item) : false;
|
|
75
|
-
}
|
|
76
|
-
/** Navigates to the next item in the list. */
|
|
77
|
-
next() {
|
|
78
|
-
return this._advance(1);
|
|
79
|
-
}
|
|
80
|
-
/** Peeks the next item in the list. */
|
|
81
|
-
peekNext() {
|
|
82
|
-
return this._peek(1);
|
|
83
|
-
}
|
|
84
|
-
/** Navigates to the previous item in the list. */
|
|
85
|
-
prev() {
|
|
86
|
-
return this._advance(-1);
|
|
87
|
-
}
|
|
88
|
-
/** Peeks the previous item in the list. */
|
|
89
|
-
peekPrev() {
|
|
90
|
-
return this._peek(-1);
|
|
91
|
-
}
|
|
92
|
-
/** Navigates to the first item in the list. */
|
|
93
|
-
first() {
|
|
94
|
-
const item = this.inputs.items().find(i => this.inputs.focusManager.isFocusable(i));
|
|
95
|
-
return item ? this.goto(item) : false;
|
|
96
|
-
}
|
|
97
|
-
/** Navigates to the last item in the list. */
|
|
98
|
-
last() {
|
|
99
|
-
const items = this.inputs.items();
|
|
100
|
-
for (let i = items.length - 1; i >= 0; i--) {
|
|
101
|
-
if (this.inputs.focusManager.isFocusable(items[i])) {
|
|
102
|
-
return this.goto(items[i]);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return false;
|
|
106
|
-
}
|
|
107
|
-
/** Advances to the next or previous focusable item in the list based on the given delta. */
|
|
108
|
-
_advance(delta) {
|
|
109
|
-
const item = this._peek(delta);
|
|
110
|
-
return item ? this.goto(item) : false;
|
|
111
|
-
}
|
|
112
|
-
/** Peeks the next or previous focusable item in the list based on the given delta. */
|
|
113
|
-
_peek(delta) {
|
|
114
|
-
const items = this.inputs.items();
|
|
115
|
-
const itemCount = items.length;
|
|
116
|
-
const startIndex = this.inputs.focusManager.activeIndex();
|
|
117
|
-
const step = (i) => this.inputs.wrap() ? (i + delta + itemCount) % itemCount : i + delta;
|
|
118
|
-
// If wrapping is enabled, this loop ultimately terminates when `i` gets back to `startIndex`
|
|
119
|
-
// in the case that all options are disabled. If wrapping is disabled, the loop terminates
|
|
120
|
-
// when the index goes out of bounds.
|
|
121
|
-
for (let i = step(startIndex); i !== startIndex && i < itemCount && i >= 0; i = step(i)) {
|
|
122
|
-
if (this.inputs.focusManager.isFocusable(items[i])) {
|
|
123
|
-
return items[i];
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export { ListFocus, ListNavigation };
|
|
131
|
-
//# sourceMappingURL=_list-navigation-chunk.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_list-navigation-chunk.mjs","sources":["../../../../../k8-fastbuild-ST-199a4f3c4e20/bin/src/cdk-experimental/ui-patterns/behaviors/list-focus/list-focus.ts","../../../../../k8-fastbuild-ST-199a4f3c4e20/bin/src/cdk-experimental/ui-patterns/behaviors/list-navigation/list-navigation.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {computed, signal} from '@angular/core';\nimport {SignalLike, WritableSignalLike} from '../signal-like/signal-like';\n\n/** Represents an item in a collection, such as a listbox option, than may receive focus. */\nexport interface ListFocusItem {\n /** A unique identifier for the item. */\n id: SignalLike<string>;\n\n /** The html element that should receive focus. */\n element: SignalLike<HTMLElement>;\n\n /** Whether an item is disabled. */\n disabled: SignalLike<boolean>;\n\n /** The index of the item in the list. */\n index: SignalLike<number>;\n}\n\n/** Represents the required inputs for a collection that contains focusable items. */\nexport interface ListFocusInputs<T extends ListFocusItem> {\n /** The focus strategy used by the list. */\n focusMode: SignalLike<'roving' | 'activedescendant'>;\n\n /** Whether the list is disabled. */\n disabled: SignalLike<boolean>;\n\n /** The items in the list. */\n items: SignalLike<T[]>;\n\n /** The active item. */\n activeItem: WritableSignalLike<T | undefined>;\n\n /** Whether disabled items in the list should be skipped when navigating. */\n skipDisabled: SignalLike<boolean>;\n\n element: SignalLike<HTMLElement | undefined>;\n}\n\n/** Controls focus for a list of items. */\nexport class ListFocus<T extends ListFocusItem> {\n /** The last item that was active. */\n prevActiveItem = signal<T | undefined>(undefined);\n\n /** The index of the last item that was active. */\n prevActiveIndex = computed(() => {\n return this.prevActiveItem() ? this.inputs.items().indexOf(this.prevActiveItem()!) : -1;\n });\n\n /** The current active index in the list. */\n activeIndex = computed(() => {\n return this.inputs.activeItem() ? this.inputs.items().indexOf(this.inputs.activeItem()!) : -1;\n });\n\n constructor(readonly inputs: ListFocusInputs<T>) {}\n\n /** Whether the list is in a disabled state. */\n isListDisabled(): boolean {\n return this.inputs.disabled() || this.inputs.items().every(i => i.disabled());\n }\n\n /** The id of the current active item. */\n getActiveDescendant(): string | undefined {\n if (this.isListDisabled()) {\n return undefined;\n }\n if (this.inputs.focusMode() === 'roving') {\n return undefined;\n }\n return this.inputs.activeItem()?.id() ?? undefined;\n }\n\n /** The tabindex for the list. */\n getListTabindex(): -1 | 0 {\n if (this.isListDisabled()) {\n return 0;\n }\n return this.inputs.focusMode() === 'activedescendant' ? 0 : -1;\n }\n\n /** Returns the tabindex for the given item. */\n getItemTabindex(item: T): -1 | 0 {\n if (this.isListDisabled()) {\n return -1;\n }\n if (this.inputs.focusMode() === 'activedescendant') {\n return -1;\n }\n return this.inputs.activeItem() === item ? 0 : -1;\n }\n\n /** Moves focus to the given item if it is focusable. */\n focus(item: T): boolean {\n if (this.isListDisabled() || !this.isFocusable(item)) {\n return false;\n }\n\n this.prevActiveItem.set(this.inputs.activeItem());\n this.inputs.activeItem.set(item);\n\n this.inputs.focusMode() === 'roving' ? item.element().focus() : this.inputs.element()?.focus();\n\n return true;\n }\n\n /** Returns true if the given item can be navigated to. */\n isFocusable(item: T): boolean {\n return !item.disabled() || !this.inputs.skipDisabled();\n }\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {SignalLike} from '../signal-like/signal-like';\nimport {ListFocus, ListFocusInputs, ListFocusItem} from '../list-focus/list-focus';\n\n/** Represents an item in a collection, such as a listbox option, than can be navigated to. */\nexport interface ListNavigationItem extends ListFocusItem {}\n\n/** Represents the required inputs for a collection that has navigable items. */\nexport interface ListNavigationInputs<T extends ListNavigationItem> extends ListFocusInputs<T> {\n /** Whether focus should wrap when navigating. */\n wrap: SignalLike<boolean>;\n\n /** Whether the list is vertically or horizontally oriented. */\n orientation: SignalLike<'vertical' | 'horizontal'>;\n\n /** The direction that text is read based on the users locale. */\n textDirection: SignalLike<'rtl' | 'ltr'>;\n}\n\n/** Controls navigation for a list of items. */\nexport class ListNavigation<T extends ListNavigationItem> {\n constructor(readonly inputs: ListNavigationInputs<T> & {focusManager: ListFocus<T>}) {}\n\n /** Navigates to the given item. */\n goto(item?: T): boolean {\n return item ? this.inputs.focusManager.focus(item) : false;\n }\n\n /** Navigates to the next item in the list. */\n next(): boolean {\n return this._advance(1);\n }\n\n /** Peeks the next item in the list. */\n peekNext(): T | undefined {\n return this._peek(1);\n }\n\n /** Navigates to the previous item in the list. */\n prev(): boolean {\n return this._advance(-1);\n }\n\n /** Peeks the previous item in the list. */\n peekPrev(): T | undefined {\n return this._peek(-1);\n }\n\n /** Navigates to the first item in the list. */\n first(): boolean {\n const item = this.inputs.items().find(i => this.inputs.focusManager.isFocusable(i));\n return item ? this.goto(item) : false;\n }\n\n /** Navigates to the last item in the list. */\n last(): boolean {\n const items = this.inputs.items();\n for (let i = items.length - 1; i >= 0; i--) {\n if (this.inputs.focusManager.isFocusable(items[i])) {\n return this.goto(items[i]);\n }\n }\n return false;\n }\n\n /** Advances to the next or previous focusable item in the list based on the given delta. */\n private _advance(delta: 1 | -1): boolean {\n const item = this._peek(delta);\n return item ? this.goto(item) : false;\n }\n\n /** Peeks the next or previous focusable item in the list based on the given delta. */\n private _peek(delta: 1 | -1): T | undefined {\n const items = this.inputs.items();\n const itemCount = items.length;\n const startIndex = this.inputs.focusManager.activeIndex();\n const step = (i: number) =>\n this.inputs.wrap() ? (i + delta + itemCount) % itemCount : i + delta;\n\n // If wrapping is enabled, this loop ultimately terminates when `i` gets back to `startIndex`\n // in the case that all options are disabled. If wrapping is disabled, the loop terminates\n // when the index goes out of bounds.\n for (let i = step(startIndex); i !== startIndex && i < itemCount && i >= 0; i = step(i)) {\n if (this.inputs.focusManager.isFocusable(items[i])) {\n return items[i];\n }\n }\n\n return;\n }\n}\n"],"names":[],"mappings":";;AA8CA;MACa,SAAS,CAAA;AAcC,IAAA,MAAA;;AAZrB,IAAA,cA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