@vaadin/component-base 23.2.16 → 23.2.17

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 (70) hide show
  1. package/custom_typings/vaadin-usage-statistics.d.ts +2 -2
  2. package/index.d.ts +1 -0
  3. package/index.js +1 -0
  4. package/package.json +3 -3
  5. package/src/a11y-announcer.d.ts +1 -1
  6. package/src/a11y-announcer.js +1 -1
  7. package/src/active-mixin.d.ts +1 -1
  8. package/src/active-mixin.js +1 -1
  9. package/src/async.d.ts +0 -3
  10. package/src/async.js +1 -2
  11. package/src/browser-utils.js +7 -7
  12. package/src/controller-mixin.d.ts +1 -1
  13. package/src/controller-mixin.js +1 -1
  14. package/src/debounce.js +2 -2
  15. package/src/dir-helper.d.ts +42 -0
  16. package/src/dir-helper.js +93 -0
  17. package/src/dir-mixin.d.ts +4 -2
  18. package/src/dir-mixin.js +39 -17
  19. package/src/disabled-mixin.d.ts +1 -1
  20. package/src/disabled-mixin.js +1 -1
  21. package/src/dom-utils.d.ts +1 -6
  22. package/src/dom-utils.js +1 -11
  23. package/src/element-mixin.d.ts +1 -1
  24. package/src/element-mixin.js +5 -11
  25. package/src/focus-mixin.d.ts +1 -1
  26. package/src/focus-mixin.js +2 -2
  27. package/src/focus-trap-controller.d.ts +1 -1
  28. package/src/focus-trap-controller.js +22 -22
  29. package/src/focus-utils.d.ts +1 -1
  30. package/src/focus-utils.js +57 -57
  31. package/src/gestures.d.ts +12 -6
  32. package/src/gestures.js +4 -6
  33. package/src/iron-list-core.js +11 -21
  34. package/src/keyboard-mixin.d.ts +1 -1
  35. package/src/keyboard-mixin.js +1 -1
  36. package/src/media-query-controller.d.ts +1 -1
  37. package/src/media-query-controller.js +1 -1
  38. package/src/overflow-controller.d.ts +1 -1
  39. package/src/overflow-controller.js +3 -3
  40. package/src/polylit-mixin.d.ts +3 -3
  41. package/src/polylit-mixin.js +4 -9
  42. package/src/resize-mixin.d.ts +1 -1
  43. package/src/resize-mixin.js +21 -11
  44. package/src/slot-controller.d.ts +5 -33
  45. package/src/slot-controller.js +40 -103
  46. package/src/slot-mixin.d.ts +18 -0
  47. package/src/slot-mixin.js +60 -0
  48. package/src/tabindex-mixin.d.ts +1 -1
  49. package/src/tabindex-mixin.js +1 -1
  50. package/src/templates.js +1 -1
  51. package/src/unique-id-utils.d.ts +1 -1
  52. package/src/unique-id-utils.js +1 -1
  53. package/src/virtualizer-iron-list-adapter.js +2 -6
  54. package/src/virtualizer.js +18 -18
  55. package/src/delegate-focus-mixin.d.ts +0 -48
  56. package/src/delegate-focus-mixin.js +0 -228
  57. package/src/delegate-state-mixin.d.ts +0 -20
  58. package/src/delegate-state-mixin.js +0 -125
  59. package/src/dir-utils.d.ts +0 -19
  60. package/src/dir-utils.js +0 -36
  61. package/src/keyboard-direction-mixin.d.ts +0 -41
  62. package/src/keyboard-direction-mixin.js +0 -192
  63. package/src/list-mixin.d.ts +0 -57
  64. package/src/list-mixin.js +0 -354
  65. package/src/overlay-class-mixin.d.ts +0 -33
  66. package/src/overlay-class-mixin.js +0 -79
  67. package/src/slot-child-observe-controller.d.ts +0 -28
  68. package/src/slot-child-observe-controller.js +0 -176
  69. package/src/tooltip-controller.d.ts +0 -86
  70. package/src/tooltip-controller.js +0 -130
@@ -1,57 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2017 - 2023 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
- import type { Constructor } from '@open-wc/dedupe-mixin';
7
- import type { KeyboardDirectionMixinClass } from './keyboard-direction-mixin.js';
8
- import type { KeyboardMixinClass } from './keyboard-mixin.js';
9
-
10
- /**
11
- * A mixin for list elements, facilitating navigation and selection of items.
12
- */
13
- export declare function ListMixin<T extends Constructor<HTMLElement>>(
14
- base: T,
15
- ): Constructor<KeyboardDirectionMixinClass> & Constructor<KeyboardMixinClass> & Constructor<ListMixinClass> & T;
16
-
17
- export declare class ListMixinClass {
18
- /**
19
- * Used for mixin detection because `instanceof` does not work with mixins.
20
- */
21
- _hasVaadinListMixin: boolean;
22
-
23
- /**
24
- * If true, the user cannot interact with this element.
25
- * When the element is disabled, the selected item is
26
- * not updated when `selected` property is changed.
27
- */
28
- disabled: boolean;
29
-
30
- /**
31
- * The index of the item selected in the items array.
32
- * Note: Not updated when used in `multiple` selection mode.
33
- */
34
- selected: number | null | undefined;
35
-
36
- /**
37
- * Define how items are disposed in the dom.
38
- * Possible values are: `horizontal|vertical`.
39
- * It also changes navigation keys from left/right to up/down.
40
- */
41
- orientation: 'horizontal' | 'vertical';
42
-
43
- /**
44
- * The list of items from which a selection can be made.
45
- * It is populated from the elements passed to the light DOM,
46
- * and updated dynamically when adding or removing items.
47
- *
48
- * The item elements must implement `Vaadin.ItemMixin`.
49
- *
50
- * Note: unlike `<vaadin-combo-box>`, this property is read-only,
51
- * so if you want to provide items by iterating array of data,
52
- * you have to use `dom-repeat` and place it to the light DOM.
53
- */
54
- readonly items: Element[] | undefined;
55
-
56
- protected readonly _scrollerElement: HTMLElement;
57
- }
package/src/list-mixin.js DELETED
@@ -1,354 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2017 - 2023 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
- import { FlattenedNodesObserver } from '@polymer/polymer/lib/utils/flattened-nodes-observer.js';
7
- import { timeOut } from './async.js';
8
- import { Debouncer } from './debounce.js';
9
- import { getNormalizedScrollLeft, setNormalizedScrollLeft } from './dir-utils.js';
10
- import { KeyboardDirectionMixin } from './keyboard-direction-mixin.js';
11
-
12
- /**
13
- * A mixin for list elements, facilitating navigation and selection of items.
14
- *
15
- * @polymerMixin
16
- * @mixes KeyboardDirectionMixin
17
- */
18
- export const ListMixin = (superClass) =>
19
- class ListMixinClass extends KeyboardDirectionMixin(superClass) {
20
- static get properties() {
21
- return {
22
- /**
23
- * Used for mixin detection because `instanceof` does not work with mixins.
24
- * @type {boolean}
25
- */
26
- _hasVaadinListMixin: {
27
- value: true,
28
- },
29
-
30
- /**
31
- * If true, the user cannot interact with this element.
32
- * When the element is disabled, the selected item is
33
- * not updated when `selected` property is changed.
34
- */
35
- disabled: {
36
- type: Boolean,
37
- value: false,
38
- reflectToAttribute: true,
39
- },
40
-
41
- /**
42
- * The index of the item selected in the items array.
43
- * Note: Not updated when used in `multiple` selection mode.
44
- */
45
- selected: {
46
- type: Number,
47
- reflectToAttribute: true,
48
- notify: true,
49
- },
50
-
51
- /**
52
- * Define how items are disposed in the dom.
53
- * Possible values are: `horizontal|vertical`.
54
- * It also changes navigation keys from left/right to up/down.
55
- * @type {!ListOrientation}
56
- */
57
- orientation: {
58
- type: String,
59
- reflectToAttribute: true,
60
- value: '',
61
- },
62
-
63
- /**
64
- * The list of items from which a selection can be made.
65
- * It is populated from the elements passed to the light DOM,
66
- * and updated dynamically when adding or removing items.
67
- *
68
- * The item elements must implement `Vaadin.ItemMixin`.
69
- *
70
- * Note: unlike `<vaadin-combo-box>`, this property is read-only,
71
- * so if you want to provide items by iterating array of data,
72
- * you have to use `dom-repeat` and place it to the light DOM.
73
- * @type {!Array<!Element> | undefined}
74
- */
75
- items: {
76
- type: Array,
77
- readOnly: true,
78
- notify: true,
79
- },
80
-
81
- /**
82
- * The search buffer for the keyboard selection feature.
83
- * @private
84
- */
85
- _searchBuf: {
86
- type: String,
87
- value: '',
88
- },
89
- };
90
- }
91
-
92
- static get observers() {
93
- return ['_enhanceItems(items, orientation, selected, disabled)'];
94
- }
95
-
96
- /**
97
- * @return {boolean}
98
- * @protected
99
- */
100
- get _isRTL() {
101
- return !this._vertical && this.getAttribute('dir') === 'rtl';
102
- }
103
-
104
- /**
105
- * @return {!HTMLElement}
106
- * @protected
107
- */
108
- get _scrollerElement() {
109
- // Returning scroller element of the component
110
- console.warn(`Please implement the '_scrollerElement' property in <${this.localName}>`);
111
- return this;
112
- }
113
-
114
- /**
115
- * @return {boolean}
116
- * @protected
117
- */
118
- get _vertical() {
119
- return this.orientation !== 'horizontal';
120
- }
121
-
122
- focus() {
123
- // In initialization (e.g vaadin-select) observer might not been run yet.
124
- if (this._observer) {
125
- this._observer.flush();
126
- }
127
- const firstItem = this.querySelector('[tabindex="0"]') || (this.items ? this.items[0] : null);
128
- this._focusItem(firstItem);
129
- }
130
-
131
- /** @protected */
132
- ready() {
133
- super.ready();
134
-
135
- this.addEventListener('click', (e) => this._onClick(e));
136
-
137
- this._observer = new FlattenedNodesObserver(this, () => {
138
- this._setItems(this._filterItems(FlattenedNodesObserver.getFlattenedNodes(this)));
139
- });
140
- }
141
-
142
- /**
143
- * Override method inherited from `KeyboardDirectionMixin`
144
- * to use the stored list of item elements.
145
- *
146
- * @return {Element[]}
147
- * @protected
148
- * @override
149
- */
150
- _getItems() {
151
- return this.items;
152
- }
153
-
154
- /** @private */
155
- _enhanceItems(items, orientation, selected, disabled) {
156
- if (!disabled) {
157
- if (items) {
158
- this.setAttribute('aria-orientation', orientation || 'vertical');
159
- items.forEach((item) => {
160
- if (orientation) {
161
- item.setAttribute('orientation', orientation);
162
- } else {
163
- item.removeAttribute('orientation');
164
- }
165
- });
166
-
167
- this._setFocusable(selected || 0);
168
-
169
- const itemToSelect = items[selected];
170
- items.forEach((item) => {
171
- item.selected = item === itemToSelect;
172
- });
173
- if (itemToSelect && !itemToSelect.disabled) {
174
- this._scrollToItem(selected);
175
- }
176
- }
177
- }
178
- }
179
-
180
- /**
181
- * @param {!Array<!Element>} array
182
- * @return {!Array<!Element>}
183
- * @protected
184
- */
185
- _filterItems(array) {
186
- return array.filter((e) => e._hasVaadinItemMixin);
187
- }
188
-
189
- /**
190
- * @param {!MouseEvent} event
191
- * @protected
192
- */
193
- _onClick(event) {
194
- if (event.metaKey || event.shiftKey || event.ctrlKey || event.defaultPrevented) {
195
- return;
196
- }
197
-
198
- const item = this._filterItems(event.composedPath())[0];
199
- let idx;
200
- if (item && !item.disabled && (idx = this.items.indexOf(item)) >= 0) {
201
- this.selected = idx;
202
- }
203
- }
204
-
205
- /**
206
- * @param {number} currentIdx
207
- * @param {string} key
208
- * @return {number}
209
- * @protected
210
- */
211
- _searchKey(currentIdx, key) {
212
- this._searchReset = Debouncer.debounce(this._searchReset, timeOut.after(500), () => {
213
- this._searchBuf = '';
214
- });
215
- this._searchBuf += key.toLowerCase();
216
-
217
- if (!this.items.some((item) => this.__isMatchingKey(item))) {
218
- this._searchBuf = key.toLowerCase();
219
- }
220
-
221
- const idx = this._searchBuf.length === 1 ? currentIdx + 1 : currentIdx;
222
- return this._getAvailableIndex(
223
- this.items,
224
- idx,
225
- 1,
226
- (item) => this.__isMatchingKey(item) && getComputedStyle(item).display !== 'none',
227
- );
228
- }
229
-
230
- /** @private */
231
- __isMatchingKey(item) {
232
- return item.textContent
233
- .replace(/[^\p{L}\p{Nd}]/gu, '')
234
- .toLowerCase()
235
- .startsWith(this._searchBuf);
236
- }
237
-
238
- /**
239
- * Override an event listener from `KeyboardMixin`
240
- * to search items by key.
241
- *
242
- * @param {!KeyboardEvent} event
243
- * @protected
244
- * @override
245
- */
246
- _onKeyDown(event) {
247
- if (event.metaKey || event.ctrlKey) {
248
- return;
249
- }
250
-
251
- const key = event.key;
252
-
253
- const currentIdx = this.items.indexOf(this.focused);
254
- if (/[a-zA-Z0-9]/u.test(key) && key.length === 1) {
255
- const idx = this._searchKey(currentIdx, key);
256
- if (idx >= 0) {
257
- this._focus(idx);
258
- }
259
- return;
260
- }
261
-
262
- super._onKeyDown(event);
263
- }
264
-
265
- /**
266
- * @param {!Element} item
267
- * @return {boolean}
268
- * @protected
269
- */
270
- _isItemHidden(item) {
271
- return getComputedStyle(item).display === 'none';
272
- }
273
-
274
- /**
275
- * @param {number} idx
276
- * @protected
277
- */
278
- _setFocusable(idx) {
279
- idx = this._getAvailableIndex(this.items, idx, 1);
280
- const item = this.items[idx];
281
- this.items.forEach((e) => {
282
- e.tabIndex = e === item ? 0 : -1;
283
- });
284
- }
285
-
286
- /**
287
- * @param {number} idx
288
- * @protected
289
- */
290
- _focus(idx) {
291
- this.items.forEach((e, index) => {
292
- e.focused = index === idx;
293
- });
294
- this._setFocusable(idx);
295
- this._scrollToItem(idx);
296
- super._focus(idx);
297
- }
298
-
299
- /**
300
- * Scroll the container to have the next item by the edge of the viewport.
301
- * @param {number} idx
302
- * @protected
303
- */
304
- _scrollToItem(idx) {
305
- const item = this.items[idx];
306
- if (!item) {
307
- return;
308
- }
309
-
310
- const props = this._vertical ? ['top', 'bottom'] : this._isRTL ? ['right', 'left'] : ['left', 'right'];
311
-
312
- const scrollerRect = this._scrollerElement.getBoundingClientRect();
313
- const nextItemRect = (this.items[idx + 1] || item).getBoundingClientRect();
314
- const prevItemRect = (this.items[idx - 1] || item).getBoundingClientRect();
315
-
316
- let scrollDistance = 0;
317
- if (
318
- (!this._isRTL && nextItemRect[props[1]] >= scrollerRect[props[1]]) ||
319
- (this._isRTL && nextItemRect[props[1]] <= scrollerRect[props[1]])
320
- ) {
321
- scrollDistance = nextItemRect[props[1]] - scrollerRect[props[1]];
322
- } else if (
323
- (!this._isRTL && prevItemRect[props[0]] <= scrollerRect[props[0]]) ||
324
- (this._isRTL && prevItemRect[props[0]] >= scrollerRect[props[0]])
325
- ) {
326
- scrollDistance = prevItemRect[props[0]] - scrollerRect[props[0]];
327
- }
328
-
329
- this._scroll(scrollDistance);
330
- }
331
-
332
- /**
333
- * @param {number} pixels
334
- * @protected
335
- */
336
- _scroll(pixels) {
337
- if (this._vertical) {
338
- this._scrollerElement.scrollTop += pixels;
339
- } else {
340
- const dir = this.getAttribute('dir') || 'ltr';
341
- const scrollLeft = getNormalizedScrollLeft(this._scrollerElement, dir) + pixels;
342
- setNormalizedScrollLeft(this._scrollerElement, dir, scrollLeft);
343
- }
344
- }
345
-
346
- /**
347
- * Fired when the selection is changed.
348
- * Not fired when used in `multiple` selection mode.
349
- *
350
- * @event selected-changed
351
- * @param {Object} detail
352
- * @param {Object} detail.value the index of the item selected in the items array.
353
- */
354
- };
@@ -1,33 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2023 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
- import type { Constructor } from '@open-wc/dedupe-mixin';
7
-
8
- /**
9
- * A mixin that forwards CSS class names to the internal overlay element
10
- * by setting the `overlayClass` property or `overlay-class` attribute.
11
- */
12
- export declare function OverlayClassMixin<T extends Constructor<HTMLElement>>(
13
- base: T,
14
- ): Constructor<OverlayClassMixinClass> & T;
15
-
16
- export declare class OverlayClassMixinClass {
17
- /**
18
- * A space-delimited list of CSS class names to set on the overlay element.
19
- * This property does not affect other CSS class names set manually via JS.
20
- *
21
- * Note, if the CSS class name was set with this property, clearing it will
22
- * remove it from the overlay, even if the same class name was also added
23
- * manually, e.g. by using `classList.add()` in the `renderer` function.
24
- *
25
- * @attr {string} overlay-class
26
- */
27
- overlayClass: string;
28
-
29
- /**
30
- * An overlay element on which CSS class names are set.
31
- */
32
- protected _overlayElement: HTMLElement;
33
- }
@@ -1,79 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2023 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
-
7
- /**
8
- * A mixin that forwards CSS class names to the internal overlay element
9
- * by setting the `overlayClass` property or `overlay-class` attribute.
10
- *
11
- * @polymerMixin
12
- */
13
- export const OverlayClassMixin = (superclass) =>
14
- class OverlayClassMixinClass extends superclass {
15
- static get properties() {
16
- return {
17
- /**
18
- * A space-delimited list of CSS class names to set on the overlay element.
19
- * This property does not affect other CSS class names set manually via JS.
20
- *
21
- * Note, if the CSS class name was set with this property, clearing it will
22
- * remove it from the overlay, even if the same class name was also added
23
- * manually, e.g. by using `classList.add()` in the `renderer` function.
24
- *
25
- * @attr {string} overlay-class
26
- */
27
- overlayClass: {
28
- type: String,
29
- },
30
-
31
- /**
32
- * An overlay element on which CSS class names are set.
33
- *
34
- * @protected
35
- */
36
- _overlayElement: {
37
- type: Object,
38
- },
39
- };
40
- }
41
-
42
- static get observers() {
43
- return ['__updateOverlayClassNames(overlayClass, _overlayElement)'];
44
- }
45
-
46
- /** @private */
47
- __updateOverlayClassNames(overlayClass, overlayElement) {
48
- if (!overlayElement) {
49
- return;
50
- }
51
-
52
- // Overlay is set but overlayClass is not set
53
- if (overlayClass === undefined) {
54
- return;
55
- }
56
-
57
- const { classList } = overlayElement;
58
-
59
- if (!this.__initialClasses) {
60
- this.__initialClasses = new Set(classList);
61
- }
62
-
63
- if (Array.isArray(this.__previousClasses)) {
64
- // Remove old classes that no longer apply
65
- const classesToRemove = this.__previousClasses.filter((name) => !this.__initialClasses.has(name));
66
- if (classesToRemove.length > 0) {
67
- classList.remove(...classesToRemove);
68
- }
69
- }
70
-
71
- // Add new classes based on the overlayClass
72
- const classesToAdd = typeof overlayClass === 'string' ? overlayClass.split(' ') : [];
73
- if (classesToAdd.length > 0) {
74
- classList.add(...classesToAdd);
75
- }
76
-
77
- this.__previousClasses = classesToAdd;
78
- }
79
- };
@@ -1,28 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2022 - 2023 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
- import { SlotController } from './slot-controller.js';
7
-
8
- /**
9
- * A controller that observes slotted element mutations, especially ID attribute
10
- * and the text content, and fires an event to notify host element about those.
11
- */
12
- export class SlotChildObserveController extends SlotController {
13
- /**
14
- * Setup the mutation observer on the node to update ID and notify host.
15
- * Node doesn't get observed automatically until this method is called.
16
- */
17
- protected observeNode(node: Node): void;
18
-
19
- /**
20
- * Override to restore default node when a custom one is removed.
21
- */
22
- protected restoreDefaultNode(): void;
23
-
24
- /**
25
- * Override to update default node text on property change.
26
- */
27
- protected updateDefaultNode(node: Node): void;
28
- }