@vaadin/grid 24.3.0-alpha1 → 24.3.0-alpha2

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.
@@ -4,6 +4,10 @@
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import type { Constructor } from '@open-wc/dedupe-mixin';
7
+ import type {
8
+ DataProvider,
9
+ DataProviderCallback,
10
+ } from '@vaadin/component-base/src/data-provider-controller/data-provider-controller.js';
7
11
  import { GridSorterDirection } from './vaadin-grid-sorter.js';
8
12
 
9
13
  export { GridSorterDirection };
@@ -18,7 +22,7 @@ export interface GridSorterDefinition {
18
22
  direction: GridSorterDirection;
19
23
  }
20
24
 
21
- export type GridDataProviderCallback<TItem> = (items: TItem[], size?: number) => void;
25
+ export type GridDataProviderCallback<TItem> = DataProviderCallback<TItem>;
22
26
 
23
27
  export type GridDataProviderParams<TItem> = {
24
28
  page: number;
@@ -28,10 +32,7 @@ export type GridDataProviderParams<TItem> = {
28
32
  parentItem?: TItem;
29
33
  };
30
34
 
31
- export type GridDataProvider<TItem> = (
32
- params: GridDataProviderParams<TItem>,
33
- callback: GridDataProviderCallback<TItem>,
34
- ) => void;
35
+ export type GridDataProvider<TItem> = DataProvider<TItem, GridDataProviderParams<TItem>>;
35
36
 
36
37
  export declare function DataProviderMixin<TItem, T extends Constructor<HTMLElement>>(
37
38
  base: T,
@@ -149,10 +149,28 @@ export const DataProviderMixin = (superClass) =>
149
149
  this._dataProviderController.addEventListener('page-loaded', this._onDataProviderPageLoaded.bind(this));
150
150
  }
151
151
 
152
+ /**
153
+ * @protected
154
+ * @deprecated since 24.3 and will be removed in Vaadin 25.
155
+ */
156
+ get _cache() {
157
+ console.warn('<vaadin-grid> The `_cache` property is deprecated and will be removed in Vaadin 25.');
158
+ return this._dataProviderController.rootCache;
159
+ }
160
+
161
+ /**
162
+ * @protected
163
+ * @deprecated since 24.3 and will be removed in Vaadin 25.
164
+ */
165
+ get _effectiveSize() {
166
+ console.warn('<vaadin-grid> The `_effectiveSize` property is deprecated and will be removed in Vaadin 25.');
167
+ return this._flatSize;
168
+ }
169
+
152
170
  /** @private */
153
171
  _sizeChanged(size) {
154
172
  this._dataProviderController.setSize(size);
155
- this._effectiveSize = this._dataProviderController.effectiveSize;
173
+ this._flatSize = this._dataProviderController.flatSize;
156
174
  }
157
175
 
158
176
  /** @private */
@@ -170,7 +188,7 @@ export const DataProviderMixin = (superClass) =>
170
188
  * @protected
171
189
  */
172
190
  _getItem(index, el) {
173
- if (index >= this._effectiveSize) {
191
+ if (index >= this._flatSize) {
174
192
  return;
175
193
  }
176
194
 
@@ -225,8 +243,8 @@ export const DataProviderMixin = (superClass) =>
225
243
 
226
244
  /** @private */
227
245
  _expandedItemsChanged() {
228
- this._dataProviderController.recalculateEffectiveSize();
229
- this._effectiveSize = this._dataProviderController.effectiveSize;
246
+ this._dataProviderController.recalculateFlatSize();
247
+ this._flatSize = this._dataProviderController.flatSize;
230
248
  this.__updateVisibleRows();
231
249
  }
232
250
 
@@ -271,6 +289,17 @@ export const DataProviderMixin = (superClass) =>
271
289
  return level;
272
290
  }
273
291
 
292
+ /**
293
+ * @param {number} page
294
+ * @param {ItemCache} cache
295
+ * @protected
296
+ * @deprecated since 24.3 and will be removed in Vaadin 25.
297
+ */
298
+ _loadPage(page, cache) {
299
+ console.warn('<vaadin-grid> The `_loadPage` method is deprecated and will be removed in Vaadin 25.');
300
+ this._dataProviderController.__loadCachePage(cache, page);
301
+ }
302
+
274
303
  /** @protected */
275
304
  _onDataProviderPageRequested() {
276
305
  this._setLoading(true);
@@ -279,7 +308,7 @@ export const DataProviderMixin = (superClass) =>
279
308
  /** @protected */
280
309
  _onDataProviderPageReceived() {
281
310
  // With the new items added, update the cache size and the grid's effective size
282
- this._effectiveSize = this._dataProviderController.effectiveSize;
311
+ this._flatSize = this._dataProviderController.flatSize;
283
312
 
284
313
  // After updating the cache, check if some of the expanded items should have sub-caches loaded
285
314
  this._getRenderedRows().forEach((row) => {
@@ -319,7 +348,7 @@ export const DataProviderMixin = (superClass) =>
319
348
  this._hasData = false;
320
349
  this.__updateVisibleRows();
321
350
 
322
- if (!this._effectiveSize) {
351
+ if (!this._flatSize) {
323
352
  this._dataProviderController.loadFirstPage();
324
353
  }
325
354
  }
@@ -335,7 +364,7 @@ export const DataProviderMixin = (superClass) =>
335
364
 
336
365
  /** @protected */
337
366
  _checkSize() {
338
- if (this.size === undefined && this._effectiveSize === 0) {
367
+ if (this.size === undefined && this._flatSize === 0) {
339
368
  console.warn(
340
369
  'The <vaadin-grid> needs the total number of items in' +
341
370
  ' order to display rows, which you can specify either by setting' +
@@ -211,7 +211,7 @@ export const DragAndDropMixin = (superClass) =>
211
211
 
212
212
  let row = e.composedPath().find((node) => node.localName === 'tr');
213
213
 
214
- if (!this._effectiveSize || this.dropMode === DropMode.ON_GRID) {
214
+ if (!this._flatSize || this.dropMode === DropMode.ON_GRID) {
215
215
  // The grid is empty or "on-grid" drop mode was used, always default to "empty"
216
216
  this._dropLocation = DropLocation.EMPTY;
217
217
  } else if (!row || row.parentNode !== this.$.items) {
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2016 - 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 { ControllerMixinClass } from '@vaadin/component-base/src/controller-mixin.js';
8
+
9
+ /**
10
+ * Fired when the `value` property changes.
11
+ */
12
+ export type GridFilterValueChangedEvent = CustomEvent<{ value: string }>;
13
+
14
+ export interface GridFilterCustomEventMap {
15
+ 'value-changed': GridFilterValueChangedEvent;
16
+ }
17
+
18
+ export interface GridFilterEventMap extends HTMLElementEventMap, GridFilterCustomEventMap {}
19
+
20
+ export declare function GridFilterElementMixin<T extends Constructor<HTMLElement>>(
21
+ base: T,
22
+ ): Constructor<ControllerMixinClass> & Constructor<GridFilterElementMixinClass> & T;
23
+
24
+ declare class GridFilterElementMixinClass {
25
+ /**
26
+ * JS Path of the property in the item used for filtering the data.
27
+ */
28
+ path: string | null | undefined;
29
+
30
+ /**
31
+ * Current filter value.
32
+ */
33
+ value: string | null | undefined;
34
+ }
@@ -0,0 +1,99 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2016 - 2023 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { timeOut } from '@vaadin/component-base/src/async.js';
7
+ import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
8
+ import { Debouncer } from '@vaadin/component-base/src/debounce.js';
9
+ import { SlotController } from '@vaadin/component-base/src/slot-controller.js';
10
+ import { css, registerStyles } from '@vaadin/vaadin-themable-mixin';
11
+
12
+ registerStyles(
13
+ 'vaadin-grid-filter',
14
+ css`
15
+ :host {
16
+ display: inline-flex;
17
+ max-width: 100%;
18
+ }
19
+
20
+ ::slotted(*) {
21
+ width: 100%;
22
+ box-sizing: border-box;
23
+ }
24
+ `,
25
+ { moduleId: 'vaadin-grid-filter-styles' },
26
+ );
27
+
28
+ /**
29
+ * @polymerMixin
30
+ *
31
+ * @mixes ControllerMixin
32
+ */
33
+ export const GridFilterElementMixin = (superClass) =>
34
+ class extends ControllerMixin(superClass) {
35
+ static get properties() {
36
+ return {
37
+ /**
38
+ * JS Path of the property in the item used for filtering the data.
39
+ */
40
+ path: String,
41
+
42
+ /**
43
+ * Current filter value.
44
+ */
45
+ value: {
46
+ type: String,
47
+ notify: true,
48
+ },
49
+
50
+ /** @private */
51
+ _textField: {
52
+ type: Object,
53
+ },
54
+ };
55
+ }
56
+
57
+ static get observers() {
58
+ return ['_filterChanged(path, value, _textField)'];
59
+ }
60
+
61
+ /** @protected */
62
+ ready() {
63
+ super.ready();
64
+
65
+ this._filterController = new SlotController(this, '', 'vaadin-text-field', {
66
+ initializer: (field) => {
67
+ field.addEventListener('value-changed', (e) => {
68
+ this.value = e.detail.value;
69
+ });
70
+
71
+ this._textField = field;
72
+ },
73
+ });
74
+ this.addController(this._filterController);
75
+ }
76
+
77
+ /** @private */
78
+ _filterChanged(path, value, textField) {
79
+ if (path === undefined || value === undefined || !textField) {
80
+ return;
81
+ }
82
+ if (this._previousValue === undefined && value === '') {
83
+ return;
84
+ }
85
+
86
+ textField.value = value;
87
+ this._previousValue = value;
88
+
89
+ this._debouncerFilterChanged = Debouncer.debounce(this._debouncerFilterChanged, timeOut.after(200), () => {
90
+ this.dispatchEvent(new CustomEvent('filter-changed', { bubbles: true }));
91
+ });
92
+ }
93
+
94
+ focus() {
95
+ if (this._textField) {
96
+ this._textField.focus();
97
+ }
98
+ }
99
+ };
@@ -3,18 +3,11 @@
3
3
  * Copyright (c) 2016 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
7
6
 
8
- /**
9
- * Fired when the `value` property changes.
10
- */
11
- export type GridFilterValueChangedEvent = CustomEvent<{ value: string }>;
12
-
13
- export interface GridFilterCustomEventMap {
14
- 'value-changed': GridFilterValueChangedEvent;
15
- }
7
+ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin';
8
+ import { GridFilterElementMixin, type GridFilterEventMap } from './vaadin-grid-filter-element-mixin.js';
16
9
 
17
- export interface GridFilterEventMap extends HTMLElementEventMap, GridFilterCustomEventMap {}
10
+ export * from './vaadin-grid-filter-element-mixin.js';
18
11
 
19
12
  /**
20
13
  * `<vaadin-grid-filter>` is a helper element for the `<vaadin-grid>` that provides out-of-the-box UI controls,
@@ -41,17 +34,7 @@ export interface GridFilterEventMap extends HTMLElementEventMap, GridFilterCusto
41
34
  *
42
35
  * @fires {CustomEvent} value-changed - Fired when the `value` property changes.
43
36
  */
44
- declare class GridFilter extends ControllerMixin(HTMLElement) {
45
- /**
46
- * JS Path of the property in the item used for filtering the data.
47
- */
48
- path: string | null | undefined;
49
-
50
- /**
51
- * Current filter value.
52
- */
53
- value: string | null | undefined;
54
-
37
+ declare class GridFilter extends GridFilterElementMixin(ThemableMixin(HTMLElement)) {
55
38
  addEventListener<K extends keyof GridFilterEventMap>(
56
39
  type: K,
57
40
  listener: (this: GridFilter, ev: GridFilterEventMap[K]) => void,
@@ -5,11 +5,9 @@
5
5
  */
6
6
  import '@vaadin/text-field/src/vaadin-text-field.js';
7
7
  import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
8
- import { timeOut } from '@vaadin/component-base/src/async.js';
9
- import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
10
- import { Debouncer } from '@vaadin/component-base/src/debounce.js';
11
8
  import { defineCustomElement } from '@vaadin/component-base/src/define.js';
12
- import { SlotController } from '@vaadin/component-base/src/slot-controller.js';
9
+ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin';
10
+ import { GridFilterElementMixin } from './vaadin-grid-filter-element-mixin.js';
13
11
 
14
12
  /**
15
13
  * `<vaadin-grid-filter>` is a helper element for the `<vaadin-grid>` that provides out-of-the-box UI controls,
@@ -38,93 +36,16 @@ import { SlotController } from '@vaadin/component-base/src/slot-controller.js';
38
36
  *
39
37
  * @customElement
40
38
  * @extends HTMLElement
39
+ * @mixes GridFilterElementMixin
41
40
  */
42
- class GridFilter extends ControllerMixin(PolymerElement) {
41
+ class GridFilter extends GridFilterElementMixin(ThemableMixin(PolymerElement)) {
43
42
  static get template() {
44
- return html`
45
- <style>
46
- :host {
47
- display: inline-flex;
48
- max-width: 100%;
49
- }
50
-
51
- ::slotted(*) {
52
- width: 100%;
53
- box-sizing: border-box;
54
- }
55
- </style>
56
- <slot></slot>
57
- `;
43
+ return html`<slot></slot>`;
58
44
  }
59
45
 
60
46
  static get is() {
61
47
  return 'vaadin-grid-filter';
62
48
  }
63
-
64
- static get properties() {
65
- return {
66
- /**
67
- * JS Path of the property in the item used for filtering the data.
68
- */
69
- path: String,
70
-
71
- /**
72
- * Current filter value.
73
- */
74
- value: {
75
- type: String,
76
- notify: true,
77
- },
78
-
79
- /** @private */
80
- _textField: {
81
- type: Object,
82
- },
83
- };
84
- }
85
-
86
- static get observers() {
87
- return ['_filterChanged(path, value, _textField)'];
88
- }
89
-
90
- /** @protected */
91
- ready() {
92
- super.ready();
93
-
94
- this._filterController = new SlotController(this, '', 'vaadin-text-field', {
95
- initializer: (field) => {
96
- field.addEventListener('value-changed', (e) => {
97
- this.value = e.detail.value;
98
- });
99
-
100
- this._textField = field;
101
- },
102
- });
103
- this.addController(this._filterController);
104
- }
105
-
106
- /** @private */
107
- _filterChanged(path, value, textField) {
108
- if (path === undefined || value === undefined || !textField) {
109
- return;
110
- }
111
- if (this._previousValue === undefined && value === '') {
112
- return;
113
- }
114
-
115
- textField.value = value;
116
- this._previousValue = value;
117
-
118
- this._debouncerFilterChanged = Debouncer.debounce(this._debouncerFilterChanged, timeOut.after(200), () => {
119
- this.dispatchEvent(new CustomEvent('filter-changed', { bubbles: true }));
120
- });
121
- }
122
-
123
- focus() {
124
- if (this._textField) {
125
- this._textField.focus();
126
- }
127
- }
128
49
  }
129
50
 
130
51
  defineCustomElement(GridFilter);
@@ -443,7 +443,7 @@ export const KeyboardNavigationMixin = (superClass) =>
443
443
  __navigateRows(dy, activeRow, activeCell) {
444
444
  const currentRowIndex = this.__getIndexInGroup(activeRow, this._focusedItemIndex);
445
445
  const activeRowGroup = activeRow.parentNode;
446
- const maxRowIndex = (activeRowGroup === this.$.items ? this._effectiveSize : activeRowGroup.children.length) - 1;
446
+ const maxRowIndex = (activeRowGroup === this.$.items ? this._flatSize : activeRowGroup.children.length) - 1;
447
447
 
448
448
  // Index of the destination row
449
449
  let dstRowIndex = Math.max(0, Math.min(currentRowIndex + dy, maxRowIndex));
@@ -88,7 +88,7 @@ export const GridMixin = (superClass) =>
88
88
  static get observers() {
89
89
  return [
90
90
  '_columnTreeChanged(_columnTree, _columnTree.*)',
91
- '_effectiveSizeChanged(_effectiveSize, __virtualizer, _hasData, _columnTree)',
91
+ '_flatSizeChanged(_flatSize, __virtualizer, _hasData, _columnTree)',
92
92
  ];
93
93
  }
94
94
 
@@ -294,20 +294,20 @@ export const GridMixin = (superClass) =>
294
294
  }
295
295
 
296
296
  /** @private */
297
- _effectiveSizeChanged(effectiveSize, virtualizer, hasData, columnTree) {
297
+ _flatSizeChanged(flatSize, virtualizer, hasData, columnTree) {
298
298
  if (virtualizer && hasData && columnTree) {
299
299
  // Changing the virtualizer size may result in the row with focus getting hidden
300
300
  const cell = this.shadowRoot.activeElement;
301
301
  const cellCoordinates = this.__getBodyCellCoordinates(cell);
302
302
 
303
303
  const previousSize = virtualizer.size || 0;
304
- virtualizer.size = effectiveSize;
304
+ virtualizer.size = flatSize;
305
305
 
306
306
  // Request an update for the previous last row to have the "last" state removed
307
307
  virtualizer.update(previousSize - 1, previousSize - 1);
308
- if (effectiveSize < previousSize) {
308
+ if (flatSize < previousSize) {
309
309
  // Size was decreased, so the new last row requires an explicit update
310
- virtualizer.update(effectiveSize - 1, effectiveSize - 1);
310
+ virtualizer.update(flatSize - 1, flatSize - 1);
311
311
  }
312
312
 
313
313
  // If the focused cell's parent row got hidden by the size change, focus the corresponding new cell
@@ -801,7 +801,7 @@ export const GridMixin = (superClass) =>
801
801
  _updateRowOrderParts(row, index = row.index) {
802
802
  updateBooleanRowStates(row, {
803
803
  first: index === 0,
804
- last: index === this._effectiveSize - 1,
804
+ last: index === this._flatSize - 1,
805
805
  odd: index % 2 !== 0,
806
806
  even: index % 2 === 0,
807
807
  });
@@ -160,7 +160,7 @@ export const ScrollMixin = (superClass) =>
160
160
  * @protected
161
161
  */
162
162
  _scrollToFlatIndex(index) {
163
- index = Math.min(this._effectiveSize - 1, Math.max(0, index));
163
+ index = Math.min(this._flatSize - 1, Math.max(0, index));
164
164
  this.__virtualizer.scrollToIndex(index);
165
165
  this.__scrollIntoViewport(index);
166
166
  }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2016 - 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
+ export type GridSorterDirection = 'asc' | 'desc' | null;
9
+
10
+ /**
11
+ * Fired when the `path` or `direction` property changes.
12
+ */
13
+ export type GridSorterChangedEvent = CustomEvent<{ shiftClick: boolean; fromSorterClick: boolean }>;
14
+
15
+ /**
16
+ * Fired when the `direction` property changes.
17
+ */
18
+ export type GridSorterDirectionChangedEvent = CustomEvent<{ value: GridSorterDirection }>;
19
+
20
+ export interface GridSorterCustomEventMap {
21
+ 'sorter-changed': GridSorterChangedEvent;
22
+
23
+ 'direction-changed': GridSorterDirectionChangedEvent;
24
+ }
25
+
26
+ export interface GridSorterEventMap extends HTMLElementEventMap, GridSorterCustomEventMap {}
27
+
28
+ export declare function GridSorterMixin<T extends Constructor<HTMLElement>>(
29
+ base: T,
30
+ ): Constructor<GridSorterMixinClass> & T;
31
+
32
+ declare class GridSorterMixinClass {
33
+ /**
34
+ * JS Path of the property in the item used for sorting the data.
35
+ */
36
+ path: string | null | undefined;
37
+
38
+ /**
39
+ * How to sort the data.
40
+ * Possible values are `asc` to use an ascending algorithm, `desc` to sort the data in
41
+ * descending direction, or `null` for not sorting the data.
42
+ */
43
+ direction: GridSorterDirection | null | undefined;
44
+ }