@angular/cdk 21.0.0-next.8 → 21.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/_adev_assets/cdk_drag_drop.json +13 -12
  2. package/_adev_assets/cdk_testing.json +15 -25
  3. package/_adev_assets/cdk_testing_protractor.json +1 -1
  4. package/_adev_assets/cdk_testing_selenium_webdriver.json +1 -1
  5. package/_adev_assets/cdk_testing_testbed.json +1 -1
  6. package/fesm2022/_a11y-module-chunk.mjs +755 -869
  7. package/fesm2022/_a11y-module-chunk.mjs.map +1 -1
  8. package/fesm2022/_activedescendant-key-manager-chunk.mjs +8 -8
  9. package/fesm2022/_activedescendant-key-manager-chunk.mjs.map +1 -1
  10. package/fesm2022/_array-chunk.mjs +1 -1
  11. package/fesm2022/_array-chunk.mjs.map +1 -1
  12. package/fesm2022/_breakpoints-observer-chunk.mjs +149 -152
  13. package/fesm2022/_breakpoints-observer-chunk.mjs.map +1 -1
  14. package/fesm2022/_css-pixel-value-chunk.mjs +4 -5
  15. package/fesm2022/_css-pixel-value-chunk.mjs.map +1 -1
  16. package/fesm2022/_data-source-chunk.mjs +2 -8
  17. package/fesm2022/_data-source-chunk.mjs.map +1 -1
  18. package/fesm2022/_directionality-chunk.mjs +54 -54
  19. package/fesm2022/_directionality-chunk.mjs.map +1 -1
  20. package/fesm2022/_dispose-view-repeater-strategy-chunk.mjs +25 -36
  21. package/fesm2022/_dispose-view-repeater-strategy-chunk.mjs.map +1 -1
  22. package/fesm2022/_element-chunk.mjs +6 -17
  23. package/fesm2022/_element-chunk.mjs.map +1 -1
  24. package/fesm2022/_fake-event-detection-chunk.mjs +3 -17
  25. package/fesm2022/_fake-event-detection-chunk.mjs.map +1 -1
  26. package/fesm2022/_focus-key-manager-chunk.mjs +10 -14
  27. package/fesm2022/_focus-key-manager-chunk.mjs.map +1 -1
  28. package/fesm2022/_focus-monitor-chunk.mjs +376 -566
  29. package/fesm2022/_focus-monitor-chunk.mjs.map +1 -1
  30. package/fesm2022/_id-generator-chunk.mjs +36 -27
  31. package/fesm2022/_id-generator-chunk.mjs.map +1 -1
  32. package/fesm2022/_keycodes-chunk.mjs +9 -9
  33. package/fesm2022/_keycodes-chunk.mjs.map +1 -1
  34. package/fesm2022/_list-key-manager-chunk.mjs +248 -336
  35. package/fesm2022/_list-key-manager-chunk.mjs.map +1 -1
  36. package/fesm2022/_overlay-module-chunk.mjs +2534 -2948
  37. package/fesm2022/_overlay-module-chunk.mjs.map +1 -1
  38. package/fesm2022/_passive-listeners-chunk.mjs +10 -22
  39. package/fesm2022/_passive-listeners-chunk.mjs.map +1 -1
  40. package/fesm2022/_platform-chunk.mjs +42 -65
  41. package/fesm2022/_platform-chunk.mjs.map +1 -1
  42. package/fesm2022/_recycle-view-repeater-strategy-chunk.mjs +78 -134
  43. package/fesm2022/_recycle-view-repeater-strategy-chunk.mjs.map +1 -1
  44. package/fesm2022/_scrolling-chunk.mjs +44 -85
  45. package/fesm2022/_scrolling-chunk.mjs.map +1 -1
  46. package/fesm2022/_selection-model-chunk.mjs +138 -209
  47. package/fesm2022/_selection-model-chunk.mjs.map +1 -1
  48. package/fesm2022/_shadow-dom-chunk.mjs +21 -35
  49. package/fesm2022/_shadow-dom-chunk.mjs.map +1 -1
  50. package/fesm2022/_style-loader-chunk.mjs +50 -37
  51. package/fesm2022/_style-loader-chunk.mjs.map +1 -1
  52. package/fesm2022/_test-environment-chunk.mjs +2 -14
  53. package/fesm2022/_test-environment-chunk.mjs.map +1 -1
  54. package/fesm2022/_tree-key-manager-chunk.mjs +229 -308
  55. package/fesm2022/_tree-key-manager-chunk.mjs.map +1 -1
  56. package/fesm2022/_typeahead-chunk.mjs +52 -74
  57. package/fesm2022/_typeahead-chunk.mjs.map +1 -1
  58. package/fesm2022/_unique-selection-dispatcher-chunk.mjs +43 -40
  59. package/fesm2022/_unique-selection-dispatcher-chunk.mjs.map +1 -1
  60. package/fesm2022/a11y.mjs +351 -449
  61. package/fesm2022/a11y.mjs.map +1 -1
  62. package/fesm2022/accordion.mjs +254 -192
  63. package/fesm2022/accordion.mjs.map +1 -1
  64. package/fesm2022/bidi.mjs +121 -64
  65. package/fesm2022/bidi.mjs.map +1 -1
  66. package/fesm2022/cdk.mjs +1 -2
  67. package/fesm2022/cdk.mjs.map +1 -1
  68. package/fesm2022/clipboard.mjs +208 -186
  69. package/fesm2022/clipboard.mjs.map +1 -1
  70. package/fesm2022/coercion-private.mjs +4 -8
  71. package/fesm2022/coercion-private.mjs.map +1 -1
  72. package/fesm2022/coercion.mjs +11 -29
  73. package/fesm2022/coercion.mjs.map +1 -1
  74. package/fesm2022/dialog.mjs +660 -808
  75. package/fesm2022/dialog.mjs.map +1 -1
  76. package/fesm2022/drag-drop.mjs +3347 -4286
  77. package/fesm2022/drag-drop.mjs.map +1 -1
  78. package/fesm2022/keycodes.mjs +4 -8
  79. package/fesm2022/keycodes.mjs.map +1 -1
  80. package/fesm2022/layout.mjs +44 -26
  81. package/fesm2022/layout.mjs.map +1 -1
  82. package/fesm2022/listbox.mjs +841 -895
  83. package/fesm2022/listbox.mjs.map +1 -1
  84. package/fesm2022/menu.mjs +1942 -1858
  85. package/fesm2022/menu.mjs.map +1 -1
  86. package/fesm2022/observers-private.mjs +88 -106
  87. package/fesm2022/observers-private.mjs.map +1 -1
  88. package/fesm2022/observers.mjs +262 -184
  89. package/fesm2022/observers.mjs.map +1 -1
  90. package/fesm2022/overlay.mjs +72 -68
  91. package/fesm2022/overlay.mjs.map +1 -1
  92. package/fesm2022/platform.mjs +43 -54
  93. package/fesm2022/platform.mjs.map +1 -1
  94. package/fesm2022/portal.mjs +402 -560
  95. package/fesm2022/portal.mjs.map +1 -1
  96. package/fesm2022/private.mjs +38 -10
  97. package/fesm2022/private.mjs.map +1 -1
  98. package/fesm2022/scrolling.mjs +1323 -1400
  99. package/fesm2022/scrolling.mjs.map +1 -1
  100. package/fesm2022/stepper.mjs +758 -590
  101. package/fesm2022/stepper.mjs.map +1 -1
  102. package/fesm2022/table.mjs +2327 -2319
  103. package/fesm2022/table.mjs.map +1 -1
  104. package/fesm2022/testing-selenium-webdriver.mjs +252 -325
  105. package/fesm2022/testing-selenium-webdriver.mjs.map +1 -1
  106. package/fesm2022/testing-testbed.mjs +592 -709
  107. package/fesm2022/testing-testbed.mjs.map +1 -1
  108. package/fesm2022/testing.mjs +368 -889
  109. package/fesm2022/testing.mjs.map +1 -1
  110. package/fesm2022/text-field.mjs +459 -388
  111. package/fesm2022/text-field.mjs.map +1 -1
  112. package/fesm2022/tree.mjs +1483 -1731
  113. package/fesm2022/tree.mjs.map +1 -1
  114. package/overlay/_index.scss +28 -0
  115. package/overlay-prebuilt.css +1 -1
  116. package/package.json +1 -1
  117. package/schematics/ng-add/index.js +1 -1
  118. package/types/_harness-environment-chunk.d.ts +1 -2
  119. package/types/_overlay-module-chunk.d.ts +59 -7
  120. package/types/_portal-directives-chunk.d.ts +2 -18
  121. package/types/accordion.d.ts +3 -1
  122. package/types/dialog.d.ts +1 -1
  123. package/types/overlay.d.ts +6 -2
  124. package/types/portal.d.ts +1 -1
@@ -4,356 +4,268 @@ import { Typeahead } from './_typeahead-chunk.mjs';
4
4
  import { hasModifierKey } from './keycodes.mjs';
5
5
  import { PAGE_DOWN, PAGE_UP, END, HOME, LEFT_ARROW, RIGHT_ARROW, UP_ARROW, DOWN_ARROW, TAB } from './_keycodes-chunk.mjs';
6
6
 
7
- /**
8
- * This class manages keyboard events for selectable lists. If you pass it a query list
9
- * of items, it will set the active item correctly when arrow events occur.
10
- */
11
7
  class ListKeyManager {
12
- _items;
13
- _activeItemIndex = signal(-1, ...(ngDevMode ? [{ debugName: "_activeItemIndex" }] : []));
14
- _activeItem = signal(null, ...(ngDevMode ? [{ debugName: "_activeItem" }] : []));
15
- _wrap = false;
16
- _typeaheadSubscription = Subscription.EMPTY;
17
- _itemChangesSubscription;
18
- _vertical = true;
19
- _horizontal;
20
- _allowedModifierKeys = [];
21
- _homeAndEnd = false;
22
- _pageUpAndDown = { enabled: false, delta: 10 };
23
- _effectRef;
24
- _typeahead;
25
- /**
26
- * Predicate function that can be used to check whether an item should be skipped
27
- * by the key manager. By default, disabled items are skipped.
28
- */
29
- _skipPredicateFn = (item) => item.disabled;
30
- constructor(_items, injector) {
31
- this._items = _items;
32
- // We allow for the items to be an array because, in some cases, the consumer may
33
- // not have access to a QueryList of the items they want to manage (e.g. when the
34
- // items aren't being collected via `ViewChildren` or `ContentChildren`).
35
- if (_items instanceof QueryList) {
36
- this._itemChangesSubscription = _items.changes.subscribe((newItems) => this._itemsChanged(newItems.toArray()));
37
- }
38
- else if (isSignal(_items)) {
39
- if (!injector && (typeof ngDevMode === 'undefined' || ngDevMode)) {
40
- throw new Error('ListKeyManager constructed with a signal must receive an injector');
41
- }
42
- this._effectRef = effect(() => this._itemsChanged(_items()), ...(ngDevMode ? [{ debugName: "_effectRef", injector }] : [{ injector }]));
43
- }
44
- }
45
- /**
46
- * Stream that emits any time the TAB key is pressed, so components can react
47
- * when focus is shifted off of the list.
48
- */
49
- tabOut = new Subject();
50
- /** Stream that emits whenever the active item of the list manager changes. */
51
- change = new Subject();
52
- /**
53
- * Sets the predicate function that determines which items should be skipped by the
54
- * list key manager.
55
- * @param predicate Function that determines whether the given item should be skipped.
56
- */
57
- skipPredicate(predicate) {
58
- this._skipPredicateFn = predicate;
59
- return this;
60
- }
61
- /**
62
- * Configures wrapping mode, which determines whether the active item will wrap to
63
- * the other end of list when there are no more items in the given direction.
64
- * @param shouldWrap Whether the list should wrap when reaching the end.
65
- */
66
- withWrap(shouldWrap = true) {
67
- this._wrap = shouldWrap;
68
- return this;
8
+ _items;
9
+ _activeItemIndex = signal(-1, ...(ngDevMode ? [{
10
+ debugName: "_activeItemIndex"
11
+ }] : []));
12
+ _activeItem = signal(null, ...(ngDevMode ? [{
13
+ debugName: "_activeItem"
14
+ }] : []));
15
+ _wrap = false;
16
+ _typeaheadSubscription = Subscription.EMPTY;
17
+ _itemChangesSubscription;
18
+ _vertical = true;
19
+ _horizontal;
20
+ _allowedModifierKeys = [];
21
+ _homeAndEnd = false;
22
+ _pageUpAndDown = {
23
+ enabled: false,
24
+ delta: 10
25
+ };
26
+ _effectRef;
27
+ _typeahead;
28
+ _skipPredicateFn = item => item.disabled;
29
+ constructor(_items, injector) {
30
+ this._items = _items;
31
+ if (_items instanceof QueryList) {
32
+ this._itemChangesSubscription = _items.changes.subscribe(newItems => this._itemsChanged(newItems.toArray()));
33
+ } else if (isSignal(_items)) {
34
+ if (!injector && (typeof ngDevMode === 'undefined' || ngDevMode)) {
35
+ throw new Error('ListKeyManager constructed with a signal must receive an injector');
36
+ }
37
+ this._effectRef = effect(() => this._itemsChanged(_items()), ...(ngDevMode ? [{
38
+ debugName: "_effectRef",
39
+ injector
40
+ }] : [{
41
+ injector
42
+ }]));
69
43
  }
70
- /**
71
- * Configures whether the key manager should be able to move the selection vertically.
72
- * @param enabled Whether vertical selection should be enabled.
73
- */
74
- withVerticalOrientation(enabled = true) {
75
- this._vertical = enabled;
76
- return this;
44
+ }
45
+ tabOut = new Subject();
46
+ change = new Subject();
47
+ skipPredicate(predicate) {
48
+ this._skipPredicateFn = predicate;
49
+ return this;
50
+ }
51
+ withWrap(shouldWrap = true) {
52
+ this._wrap = shouldWrap;
53
+ return this;
54
+ }
55
+ withVerticalOrientation(enabled = true) {
56
+ this._vertical = enabled;
57
+ return this;
58
+ }
59
+ withHorizontalOrientation(direction) {
60
+ this._horizontal = direction;
61
+ return this;
62
+ }
63
+ withAllowedModifierKeys(keys) {
64
+ this._allowedModifierKeys = keys;
65
+ return this;
66
+ }
67
+ withTypeAhead(debounceInterval = 200) {
68
+ if (typeof ngDevMode === 'undefined' || ngDevMode) {
69
+ const items = this._getItemsArray();
70
+ if (items.length > 0 && items.some(item => typeof item.getLabel !== 'function')) {
71
+ throw Error('ListKeyManager items in typeahead mode must implement the `getLabel` method.');
72
+ }
77
73
  }
78
- /**
79
- * Configures the key manager to move the selection horizontally.
80
- * Passing in `null` will disable horizontal movement.
81
- * @param direction Direction in which the selection can be moved.
82
- */
83
- withHorizontalOrientation(direction) {
84
- this._horizontal = direction;
85
- return this;
74
+ this._typeaheadSubscription.unsubscribe();
75
+ const items = this._getItemsArray();
76
+ this._typeahead = new Typeahead(items, {
77
+ debounceInterval: typeof debounceInterval === 'number' ? debounceInterval : undefined,
78
+ skipPredicate: item => this._skipPredicateFn(item)
79
+ });
80
+ this._typeaheadSubscription = this._typeahead.selectedItem.subscribe(item => {
81
+ this.setActiveItem(item);
82
+ });
83
+ return this;
84
+ }
85
+ cancelTypeahead() {
86
+ this._typeahead?.reset();
87
+ return this;
88
+ }
89
+ withHomeAndEnd(enabled = true) {
90
+ this._homeAndEnd = enabled;
91
+ return this;
92
+ }
93
+ withPageUpDown(enabled = true, delta = 10) {
94
+ this._pageUpAndDown = {
95
+ enabled,
96
+ delta
97
+ };
98
+ return this;
99
+ }
100
+ setActiveItem(item) {
101
+ const previousActiveItem = this._activeItem();
102
+ this.updateActiveItem(item);
103
+ if (this._activeItem() !== previousActiveItem) {
104
+ this.change.next(this._activeItemIndex());
86
105
  }
87
- /**
88
- * Modifier keys which are allowed to be held down and whose default actions will be prevented
89
- * as the user is pressing the arrow keys. Defaults to not allowing any modifier keys.
90
- */
91
- withAllowedModifierKeys(keys) {
92
- this._allowedModifierKeys = keys;
93
- return this;
94
- }
95
- /**
96
- * Turns on typeahead mode which allows users to set the active item by typing.
97
- * @param debounceInterval Time to wait after the last keystroke before setting the active item.
98
- */
99
- withTypeAhead(debounceInterval = 200) {
100
- if (typeof ngDevMode === 'undefined' || ngDevMode) {
101
- const items = this._getItemsArray();
102
- if (items.length > 0 && items.some(item => typeof item.getLabel !== 'function')) {
103
- throw Error('ListKeyManager items in typeahead mode must implement the `getLabel` method.');
104
- }
106
+ }
107
+ onKeydown(event) {
108
+ const keyCode = event.keyCode;
109
+ const modifiers = ['altKey', 'ctrlKey', 'metaKey', 'shiftKey'];
110
+ const isModifierAllowed = modifiers.every(modifier => {
111
+ return !event[modifier] || this._allowedModifierKeys.indexOf(modifier) > -1;
112
+ });
113
+ switch (keyCode) {
114
+ case TAB:
115
+ this.tabOut.next();
116
+ return;
117
+ case DOWN_ARROW:
118
+ if (this._vertical && isModifierAllowed) {
119
+ this.setNextItemActive();
120
+ break;
121
+ } else {
122
+ return;
105
123
  }
106
- this._typeaheadSubscription.unsubscribe();
107
- const items = this._getItemsArray();
108
- this._typeahead = new Typeahead(items, {
109
- debounceInterval: typeof debounceInterval === 'number' ? debounceInterval : undefined,
110
- skipPredicate: item => this._skipPredicateFn(item),
111
- });
112
- this._typeaheadSubscription = this._typeahead.selectedItem.subscribe(item => {
113
- this.setActiveItem(item);
114
- });
115
- return this;
116
- }
117
- /** Cancels the current typeahead sequence. */
118
- cancelTypeahead() {
119
- this._typeahead?.reset();
120
- return this;
121
- }
122
- /**
123
- * Configures the key manager to activate the first and last items
124
- * respectively when the Home or End key is pressed.
125
- * @param enabled Whether pressing the Home or End key activates the first/last item.
126
- */
127
- withHomeAndEnd(enabled = true) {
128
- this._homeAndEnd = enabled;
129
- return this;
130
- }
131
- /**
132
- * Configures the key manager to activate every 10th, configured or first/last element in up/down direction
133
- * respectively when the Page-Up or Page-Down key is pressed.
134
- * @param enabled Whether pressing the Page-Up or Page-Down key activates the first/last item.
135
- * @param delta Whether pressing the Home or End key activates the first/last item.
136
- */
137
- withPageUpDown(enabled = true, delta = 10) {
138
- this._pageUpAndDown = { enabled, delta };
139
- return this;
140
- }
141
- setActiveItem(item) {
142
- const previousActiveItem = this._activeItem();
143
- this.updateActiveItem(item);
144
- if (this._activeItem() !== previousActiveItem) {
145
- this.change.next(this._activeItemIndex());
124
+ case UP_ARROW:
125
+ if (this._vertical && isModifierAllowed) {
126
+ this.setPreviousItemActive();
127
+ break;
128
+ } else {
129
+ return;
146
130
  }
147
- }
148
- /**
149
- * Sets the active item depending on the key event passed in.
150
- * @param event Keyboard event to be used for determining which element should be active.
151
- */
152
- onKeydown(event) {
153
- const keyCode = event.keyCode;
154
- const modifiers = ['altKey', 'ctrlKey', 'metaKey', 'shiftKey'];
155
- const isModifierAllowed = modifiers.every(modifier => {
156
- return !event[modifier] || this._allowedModifierKeys.indexOf(modifier) > -1;
157
- });
158
- switch (keyCode) {
159
- case TAB:
160
- this.tabOut.next();
161
- return;
162
- case DOWN_ARROW:
163
- if (this._vertical && isModifierAllowed) {
164
- this.setNextItemActive();
165
- break;
166
- }
167
- else {
168
- return;
169
- }
170
- case UP_ARROW:
171
- if (this._vertical && isModifierAllowed) {
172
- this.setPreviousItemActive();
173
- break;
174
- }
175
- else {
176
- return;
177
- }
178
- case RIGHT_ARROW:
179
- if (this._horizontal && isModifierAllowed) {
180
- this._horizontal === 'rtl' ? this.setPreviousItemActive() : this.setNextItemActive();
181
- break;
182
- }
183
- else {
184
- return;
185
- }
186
- case LEFT_ARROW:
187
- if (this._horizontal && isModifierAllowed) {
188
- this._horizontal === 'rtl' ? this.setNextItemActive() : this.setPreviousItemActive();
189
- break;
190
- }
191
- else {
192
- return;
193
- }
194
- case HOME:
195
- if (this._homeAndEnd && isModifierAllowed) {
196
- this.setFirstItemActive();
197
- break;
198
- }
199
- else {
200
- return;
201
- }
202
- case END:
203
- if (this._homeAndEnd && isModifierAllowed) {
204
- this.setLastItemActive();
205
- break;
206
- }
207
- else {
208
- return;
209
- }
210
- case PAGE_UP:
211
- if (this._pageUpAndDown.enabled && isModifierAllowed) {
212
- const targetIndex = this._activeItemIndex() - this._pageUpAndDown.delta;
213
- this._setActiveItemByIndex(targetIndex > 0 ? targetIndex : 0, 1);
214
- break;
215
- }
216
- else {
217
- return;
218
- }
219
- case PAGE_DOWN:
220
- if (this._pageUpAndDown.enabled && isModifierAllowed) {
221
- const targetIndex = this._activeItemIndex() + this._pageUpAndDown.delta;
222
- const itemsLength = this._getItemsArray().length;
223
- this._setActiveItemByIndex(targetIndex < itemsLength ? targetIndex : itemsLength - 1, -1);
224
- break;
225
- }
226
- else {
227
- return;
228
- }
229
- default:
230
- if (isModifierAllowed || hasModifierKey(event, 'shiftKey')) {
231
- this._typeahead?.handleKey(event);
232
- }
233
- // Note that we return here, in order to avoid preventing
234
- // the default action of non-navigational keys.
235
- return;
131
+ case RIGHT_ARROW:
132
+ if (this._horizontal && isModifierAllowed) {
133
+ this._horizontal === 'rtl' ? this.setPreviousItemActive() : this.setNextItemActive();
134
+ break;
135
+ } else {
136
+ return;
236
137
  }
237
- this._typeahead?.reset();
238
- event.preventDefault();
239
- }
240
- /** Index of the currently active item. */
241
- get activeItemIndex() {
242
- return this._activeItemIndex();
243
- }
244
- /** The active item. */
245
- get activeItem() {
246
- return this._activeItem();
247
- }
248
- /** Gets whether the user is currently typing into the manager using the typeahead feature. */
249
- isTyping() {
250
- return !!this._typeahead && this._typeahead.isTyping();
251
- }
252
- /** Sets the active item to the first enabled item in the list. */
253
- setFirstItemActive() {
254
- this._setActiveItemByIndex(0, 1);
255
- }
256
- /** Sets the active item to the last enabled item in the list. */
257
- setLastItemActive() {
258
- this._setActiveItemByIndex(this._getItemsArray().length - 1, -1);
259
- }
260
- /** Sets the active item to the next enabled item in the list. */
261
- setNextItemActive() {
262
- this._activeItemIndex() < 0 ? this.setFirstItemActive() : this._setActiveItemByDelta(1);
263
- }
264
- /** Sets the active item to a previous enabled item in the list. */
265
- setPreviousItemActive() {
266
- this._activeItemIndex() < 0 && this._wrap
267
- ? this.setLastItemActive()
268
- : this._setActiveItemByDelta(-1);
269
- }
270
- updateActiveItem(item) {
271
- const itemArray = this._getItemsArray();
272
- const index = typeof item === 'number' ? item : itemArray.indexOf(item);
273
- const activeItem = itemArray[index];
274
- // Explicitly check for `null` and `undefined` because other falsy values are valid.
275
- this._activeItem.set(activeItem == null ? null : activeItem);
276
- this._activeItemIndex.set(index);
277
- this._typeahead?.setCurrentSelectedItemIndex(index);
278
- }
279
- /** Cleans up the key manager. */
280
- destroy() {
281
- this._typeaheadSubscription.unsubscribe();
282
- this._itemChangesSubscription?.unsubscribe();
283
- this._effectRef?.destroy();
284
- this._typeahead?.destroy();
285
- this.tabOut.complete();
286
- this.change.complete();
287
- }
288
- /**
289
- * This method sets the active item, given a list of items and the delta between the
290
- * currently active item and the new active item. It will calculate differently
291
- * depending on whether wrap mode is turned on.
292
- */
293
- _setActiveItemByDelta(delta) {
294
- this._wrap ? this._setActiveInWrapMode(delta) : this._setActiveInDefaultMode(delta);
295
- }
296
- /**
297
- * Sets the active item properly given "wrap" mode. In other words, it will continue to move
298
- * down the list until it finds an item that is not disabled, and it will wrap if it
299
- * encounters either end of the list.
300
- */
301
- _setActiveInWrapMode(delta) {
302
- const items = this._getItemsArray();
303
- for (let i = 1; i <= items.length; i++) {
304
- const index = (this._activeItemIndex() + delta * i + items.length) % items.length;
305
- const item = items[index];
306
- if (!this._skipPredicateFn(item)) {
307
- this.setActiveItem(index);
308
- return;
309
- }
138
+ case LEFT_ARROW:
139
+ if (this._horizontal && isModifierAllowed) {
140
+ this._horizontal === 'rtl' ? this.setNextItemActive() : this.setPreviousItemActive();
141
+ break;
142
+ } else {
143
+ return;
310
144
  }
311
- }
312
- /**
313
- * Sets the active item properly given the default mode. In other words, it will
314
- * continue to move down the list until it finds an item that is not disabled. If
315
- * it encounters either end of the list, it will stop and not wrap.
316
- */
317
- _setActiveInDefaultMode(delta) {
318
- this._setActiveItemByIndex(this._activeItemIndex() + delta, delta);
319
- }
320
- /**
321
- * Sets the active item to the first enabled item starting at the index specified. If the
322
- * item is disabled, it will move in the fallbackDelta direction until it either
323
- * finds an enabled item or encounters the end of the list.
324
- */
325
- _setActiveItemByIndex(index, fallbackDelta) {
326
- const items = this._getItemsArray();
327
- if (!items[index]) {
328
- return;
145
+ case HOME:
146
+ if (this._homeAndEnd && isModifierAllowed) {
147
+ this.setFirstItemActive();
148
+ break;
149
+ } else {
150
+ return;
151
+ }
152
+ case END:
153
+ if (this._homeAndEnd && isModifierAllowed) {
154
+ this.setLastItemActive();
155
+ break;
156
+ } else {
157
+ return;
329
158
  }
330
- while (this._skipPredicateFn(items[index])) {
331
- index += fallbackDelta;
332
- if (!items[index]) {
333
- return;
334
- }
159
+ case PAGE_UP:
160
+ if (this._pageUpAndDown.enabled && isModifierAllowed) {
161
+ const targetIndex = this._activeItemIndex() - this._pageUpAndDown.delta;
162
+ this._setActiveItemByIndex(targetIndex > 0 ? targetIndex : 0, 1);
163
+ break;
164
+ } else {
165
+ return;
335
166
  }
167
+ case PAGE_DOWN:
168
+ if (this._pageUpAndDown.enabled && isModifierAllowed) {
169
+ const targetIndex = this._activeItemIndex() + this._pageUpAndDown.delta;
170
+ const itemsLength = this._getItemsArray().length;
171
+ this._setActiveItemByIndex(targetIndex < itemsLength ? targetIndex : itemsLength - 1, -1);
172
+ break;
173
+ } else {
174
+ return;
175
+ }
176
+ default:
177
+ if (isModifierAllowed || hasModifierKey(event, 'shiftKey')) {
178
+ this._typeahead?.handleKey(event);
179
+ }
180
+ return;
181
+ }
182
+ this._typeahead?.reset();
183
+ event.preventDefault();
184
+ }
185
+ get activeItemIndex() {
186
+ return this._activeItemIndex();
187
+ }
188
+ get activeItem() {
189
+ return this._activeItem();
190
+ }
191
+ isTyping() {
192
+ return !!this._typeahead && this._typeahead.isTyping();
193
+ }
194
+ setFirstItemActive() {
195
+ this._setActiveItemByIndex(0, 1);
196
+ }
197
+ setLastItemActive() {
198
+ this._setActiveItemByIndex(this._getItemsArray().length - 1, -1);
199
+ }
200
+ setNextItemActive() {
201
+ this._activeItemIndex() < 0 ? this.setFirstItemActive() : this._setActiveItemByDelta(1);
202
+ }
203
+ setPreviousItemActive() {
204
+ this._activeItemIndex() < 0 && this._wrap ? this.setLastItemActive() : this._setActiveItemByDelta(-1);
205
+ }
206
+ updateActiveItem(item) {
207
+ const itemArray = this._getItemsArray();
208
+ const index = typeof item === 'number' ? item : itemArray.indexOf(item);
209
+ const activeItem = itemArray[index];
210
+ this._activeItem.set(activeItem == null ? null : activeItem);
211
+ this._activeItemIndex.set(index);
212
+ this._typeahead?.setCurrentSelectedItemIndex(index);
213
+ }
214
+ destroy() {
215
+ this._typeaheadSubscription.unsubscribe();
216
+ this._itemChangesSubscription?.unsubscribe();
217
+ this._effectRef?.destroy();
218
+ this._typeahead?.destroy();
219
+ this.tabOut.complete();
220
+ this.change.complete();
221
+ }
222
+ _setActiveItemByDelta(delta) {
223
+ this._wrap ? this._setActiveInWrapMode(delta) : this._setActiveInDefaultMode(delta);
224
+ }
225
+ _setActiveInWrapMode(delta) {
226
+ const items = this._getItemsArray();
227
+ for (let i = 1; i <= items.length; i++) {
228
+ const index = (this._activeItemIndex() + delta * i + items.length) % items.length;
229
+ const item = items[index];
230
+ if (!this._skipPredicateFn(item)) {
336
231
  this.setActiveItem(index);
232
+ return;
233
+ }
337
234
  }
338
- /** Returns the items as an array. */
339
- _getItemsArray() {
340
- if (isSignal(this._items)) {
341
- return this._items();
342
- }
343
- return this._items instanceof QueryList ? this._items.toArray() : this._items;
235
+ }
236
+ _setActiveInDefaultMode(delta) {
237
+ this._setActiveItemByIndex(this._activeItemIndex() + delta, delta);
238
+ }
239
+ _setActiveItemByIndex(index, fallbackDelta) {
240
+ const items = this._getItemsArray();
241
+ if (!items[index]) {
242
+ return;
344
243
  }
345
- /** Callback for when the items have changed. */
346
- _itemsChanged(newItems) {
347
- this._typeahead?.setItems(newItems);
348
- const activeItem = this._activeItem();
349
- if (activeItem) {
350
- const newIndex = newItems.indexOf(activeItem);
351
- if (newIndex > -1 && newIndex !== this._activeItemIndex()) {
352
- this._activeItemIndex.set(newIndex);
353
- this._typeahead?.setCurrentSelectedItemIndex(newIndex);
354
- }
355
- }
244
+ while (this._skipPredicateFn(items[index])) {
245
+ index += fallbackDelta;
246
+ if (!items[index]) {
247
+ return;
248
+ }
249
+ }
250
+ this.setActiveItem(index);
251
+ }
252
+ _getItemsArray() {
253
+ if (isSignal(this._items)) {
254
+ return this._items();
255
+ }
256
+ return this._items instanceof QueryList ? this._items.toArray() : this._items;
257
+ }
258
+ _itemsChanged(newItems) {
259
+ this._typeahead?.setItems(newItems);
260
+ const activeItem = this._activeItem();
261
+ if (activeItem) {
262
+ const newIndex = newItems.indexOf(activeItem);
263
+ if (newIndex > -1 && newIndex !== this._activeItemIndex()) {
264
+ this._activeItemIndex.set(newIndex);
265
+ this._typeahead?.setCurrentSelectedItemIndex(newIndex);
266
+ }
356
267
  }
268
+ }
357
269
  }
358
270
 
359
271
  export { ListKeyManager };