@vaadin/virtual-list 24.3.0-alpha10 → 24.3.0-alpha11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/virtual-list",
3
- "version": "24.3.0-alpha10",
3
+ "version": "24.3.0-alpha11",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -37,12 +37,13 @@
37
37
  "web-component"
38
38
  ],
39
39
  "dependencies": {
40
+ "@open-wc/dedupe-mixin": "^1.3.0",
40
41
  "@polymer/polymer": "^3.0.0",
41
- "@vaadin/component-base": "24.3.0-alpha10",
42
- "@vaadin/lit-renderer": "24.3.0-alpha10",
43
- "@vaadin/vaadin-lumo-styles": "24.3.0-alpha10",
44
- "@vaadin/vaadin-material-styles": "24.3.0-alpha10",
45
- "@vaadin/vaadin-themable-mixin": "24.3.0-alpha10"
42
+ "@vaadin/component-base": "24.3.0-alpha11",
43
+ "@vaadin/lit-renderer": "24.3.0-alpha11",
44
+ "@vaadin/vaadin-lumo-styles": "24.3.0-alpha11",
45
+ "@vaadin/vaadin-material-styles": "24.3.0-alpha11",
46
+ "@vaadin/vaadin-themable-mixin": "24.3.0-alpha11"
46
47
  },
47
48
  "devDependencies": {
48
49
  "@esm-bundle/chai": "^4.3.4",
@@ -54,5 +55,5 @@
54
55
  "web-types.json",
55
56
  "web-types.lit.json"
56
57
  ],
57
- "gitHead": "0271523d93fe5df0425ff64206886614f3c6f401"
58
+ "gitHead": "123cf569a1b6ef6f4ef5fe8e60cb8d988699b98c"
58
59
  }
@@ -0,0 +1,68 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2021 - 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
+ import type { VirtualList } from './vaadin-virtual-list.js';
9
+
10
+ export type VirtualListDefaultItem = any;
11
+
12
+ export interface VirtualListItemModel<TItem> {
13
+ index: number;
14
+ item: TItem;
15
+ }
16
+
17
+ export type VirtualListRenderer<TItem> = (
18
+ root: HTMLElement,
19
+ virtualList: VirtualList<TItem>,
20
+ model: VirtualListItemModel<TItem>,
21
+ ) => void;
22
+
23
+ export declare function VirtualListMixin<TItem, T extends Constructor<HTMLElement>>(
24
+ base: T,
25
+ ): Constructor<ControllerMixinClass> & Constructor<VirtualListMixinClass<TItem>> & T;
26
+
27
+ export declare class VirtualListMixinClass<TItem = VirtualListDefaultItem> {
28
+ /**
29
+ * Gets the index of the first visible item in the viewport.
30
+ */
31
+ readonly firstVisibleIndex: number;
32
+
33
+ /**
34
+ * Gets the index of the last visible item in the viewport.
35
+ */
36
+ readonly lastVisibleIndex: number;
37
+
38
+ /**
39
+ * Custom function for rendering the content of every item.
40
+ * Receives three arguments:
41
+ *
42
+ * - `root` The render target element representing one item at a time.
43
+ * - `virtualList` The reference to the `<vaadin-virtual-list>` element.
44
+ * - `model` The object with the properties related with the rendered
45
+ * item, contains:
46
+ * - `model.index` The index of the rendered item.
47
+ * - `model.item` The item.
48
+ */
49
+ renderer: VirtualListRenderer<TItem> | undefined;
50
+
51
+ /**
52
+ * An array containing items determining how many instances to render.
53
+ */
54
+ items: TItem[] | undefined;
55
+
56
+ /**
57
+ * Scroll to a specific index in the virtual list.
58
+ */
59
+ scrollToIndex(index: number): void;
60
+
61
+ /**
62
+ * Requests an update for the content of the rows.
63
+ * While performing the update, it invokes the renderer passed in the `renderer` property for each visible row.
64
+ *
65
+ * It is not guaranteed that the update happens immediately (synchronously) after it is requested.
66
+ */
67
+ requestContentUpdate(): void;
68
+ }
@@ -0,0 +1,146 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
7
+ import { OverflowController } from '@vaadin/component-base/src/overflow-controller.js';
8
+ import { processTemplates } from '@vaadin/component-base/src/templates.js';
9
+ import { Virtualizer } from '@vaadin/component-base/src/virtualizer.js';
10
+
11
+ /**
12
+ * @polymerMixin
13
+ * @mixes ControllerMixin
14
+ */
15
+ export const VirtualListMixin = (superClass) =>
16
+ class VirtualListMixinClass extends ControllerMixin(superClass) {
17
+ static get properties() {
18
+ return {
19
+ /**
20
+ * An array containing items determining how many instances to render.
21
+ * @type {Array<!VirtualListItem> | undefined}
22
+ */
23
+ items: { type: Array },
24
+
25
+ /**
26
+ * Custom function for rendering the content of every item.
27
+ * Receives three arguments:
28
+ *
29
+ * - `root` The render target element representing one item at a time.
30
+ * - `virtualList` The reference to the `<vaadin-virtual-list>` element.
31
+ * - `model` The object with the properties related with the rendered
32
+ * item, contains:
33
+ * - `model.index` The index of the rendered item.
34
+ * - `model.item` The item.
35
+ * @type {VirtualListRenderer | undefined}
36
+ */
37
+ renderer: Function,
38
+
39
+ /** @private */
40
+ __virtualizer: Object,
41
+ };
42
+ }
43
+
44
+ static get observers() {
45
+ return ['__itemsOrRendererChanged(items, renderer, __virtualizer)'];
46
+ }
47
+
48
+ /**
49
+ * Gets the index of the first visible item in the viewport.
50
+ *
51
+ * @return {number}
52
+ */
53
+ get firstVisibleIndex() {
54
+ return this.__virtualizer.firstVisibleIndex;
55
+ }
56
+
57
+ /**
58
+ * Gets the index of the last visible item in the viewport.
59
+ *
60
+ * @return {number}
61
+ */
62
+ get lastVisibleIndex() {
63
+ return this.__virtualizer.lastVisibleIndex;
64
+ }
65
+
66
+ /** @protected */
67
+ ready() {
68
+ super.ready();
69
+
70
+ this.__virtualizer = new Virtualizer({
71
+ createElements: this.__createElements,
72
+ updateElement: this.__updateElement.bind(this),
73
+ elementsContainer: this,
74
+ scrollTarget: this,
75
+ scrollContainer: this.shadowRoot.querySelector('#items'),
76
+ });
77
+
78
+ this.__overflowController = new OverflowController(this);
79
+ this.addController(this.__overflowController);
80
+
81
+ processTemplates(this);
82
+ }
83
+
84
+ /**
85
+ * Scroll to a specific index in the virtual list.
86
+ *
87
+ * @param {number} index Index to scroll to
88
+ */
89
+ scrollToIndex(index) {
90
+ this.__virtualizer.scrollToIndex(index);
91
+ }
92
+
93
+ /** @private */
94
+ __createElements(count) {
95
+ return [...Array(count)].map(() => document.createElement('div'));
96
+ }
97
+
98
+ /** @private */
99
+ __updateElement(el, index) {
100
+ if (el.__renderer !== this.renderer) {
101
+ el.__renderer = this.renderer;
102
+ this.__clearRenderTargetContent(el);
103
+ }
104
+
105
+ if (this.renderer) {
106
+ this.renderer(el, this, { item: this.items[index], index });
107
+ }
108
+ }
109
+
110
+ /**
111
+ * Clears the content of a render target.
112
+ * @private
113
+ */
114
+ __clearRenderTargetContent(element) {
115
+ element.innerHTML = '';
116
+ // Whenever a Lit-based renderer is used, it assigns a Lit part to the node it was rendered into.
117
+ // When clearing the rendered content, this part needs to be manually disposed of.
118
+ // Otherwise, using a Lit-based renderer on the same node will throw an exception or render nothing afterward.
119
+ delete element._$litPart$;
120
+ }
121
+
122
+ /** @private */
123
+ __itemsOrRendererChanged(items, renderer, virtualizer) {
124
+ // If the renderer is removed but there are elements created by
125
+ // a previous renderer, we need to request an update from the virtualizer
126
+ // to get the already existing elements properly cleared.
127
+ const hasRenderedItems = this.childElementCount > 0;
128
+
129
+ if ((renderer || hasRenderedItems) && virtualizer) {
130
+ virtualizer.size = (items || []).length;
131
+ virtualizer.update();
132
+ }
133
+ }
134
+
135
+ /**
136
+ * Requests an update for the content of the rows.
137
+ * While performing the update, it invokes the renderer passed in the `renderer` property for each visible row.
138
+ *
139
+ * It is not guaranteed that the update happens immediately (synchronously) after it is requested.
140
+ */
141
+ requestContentUpdate() {
142
+ if (this.__virtualizer) {
143
+ this.__virtualizer.update();
144
+ }
145
+ }
146
+ };
@@ -0,0 +1,8 @@
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 { CSSResult } from 'lit';
7
+
8
+ export const virtualListStyles: CSSResult;
@@ -0,0 +1,28 @@
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 { css } from 'lit';
7
+
8
+ export const virtualListStyles = css`
9
+ :host {
10
+ display: block;
11
+ height: 400px;
12
+ overflow: auto;
13
+ flex: auto;
14
+ align-self: stretch;
15
+ }
16
+
17
+ :host([hidden]) {
18
+ display: none !important;
19
+ }
20
+
21
+ :host(:not([grid])) #items > ::slotted(*) {
22
+ width: 100%;
23
+ }
24
+
25
+ #items {
26
+ position: relative;
27
+ }
28
+ `;
@@ -3,22 +3,16 @@
3
3
  * Copyright (c) 2021 - 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
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
8
7
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
8
+ import type {
9
+ VirtualListDefaultItem,
10
+ VirtualListItemModel,
11
+ VirtualListMixinClass,
12
+ VirtualListRenderer,
13
+ } from './vaadin-virtual-list-mixin.js';
9
14
 
10
- export type VirtualListDefaultItem = any;
11
-
12
- export interface VirtualListItemModel<TItem> {
13
- index: number;
14
- item: TItem;
15
- }
16
-
17
- export type VirtualListRenderer<TItem> = (
18
- root: HTMLElement,
19
- virtualList: VirtualList<TItem>,
20
- model: VirtualListItemModel<TItem>,
21
- ) => void;
15
+ export { VirtualListDefaultItem, VirtualListItemModel, VirtualListRenderer };
22
16
 
23
17
  /**
24
18
  * `<vaadin-virtual-list>` is a Web Component for displaying a virtual/infinite list of items.
@@ -46,51 +40,11 @@ export type VirtualListRenderer<TItem> = (
46
40
  * @extends HTMLElement
47
41
  * @mixes ElementMixin
48
42
  * @mixes ThemableMixin
43
+ * @mixes VirtualListMixin
49
44
  */
50
- declare class VirtualList<TItem = VirtualListDefaultItem> extends ElementMixin(
51
- ControllerMixin(ThemableMixin(HTMLElement)),
52
- ) {
53
- /**
54
- * Gets the index of the first visible item in the viewport.
55
- */
56
- readonly firstVisibleIndex: number;
57
-
58
- /**
59
- * Gets the index of the last visible item in the viewport.
60
- */
61
- readonly lastVisibleIndex: number;
45
+ declare class VirtualList<TItem = VirtualListDefaultItem> extends ThemableMixin(ElementMixin(HTMLElement)) {}
62
46
 
63
- /**
64
- * Custom function for rendering the content of every item.
65
- * Receives three arguments:
66
- *
67
- * - `root` The render target element representing one item at a time.
68
- * - `virtualList` The reference to the `<vaadin-virtual-list>` element.
69
- * - `model` The object with the properties related with the rendered
70
- * item, contains:
71
- * - `model.index` The index of the rendered item.
72
- * - `model.item` The item.
73
- */
74
- renderer: VirtualListRenderer<TItem> | undefined;
75
-
76
- /**
77
- * An array containing items determining how many instances to render.
78
- */
79
- items: TItem[] | undefined;
80
-
81
- /**
82
- * Scroll to a specific index in the virtual list.
83
- */
84
- scrollToIndex(index: number): void;
85
-
86
- /**
87
- * Requests an update for the content of the rows.
88
- * While performing the update, it invokes the renderer passed in the `renderer` property for each visible row.
89
- *
90
- * It is not guaranteed that the update happens immediately (synchronously) after it is requested.
91
- */
92
- requestContentUpdate(): void;
93
- }
47
+ interface VirtualList<TItem = VirtualListDefaultItem> extends VirtualListMixinClass<TItem> {}
94
48
 
95
49
  declare global {
96
50
  interface HTMLElementTagNameMap {
@@ -4,13 +4,13 @@
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
7
- import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
8
7
  import { defineCustomElement } from '@vaadin/component-base/src/define.js';
9
8
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
10
- import { OverflowController } from '@vaadin/component-base/src/overflow-controller.js';
11
- import { processTemplates } from '@vaadin/component-base/src/templates.js';
12
- import { Virtualizer } from '@vaadin/component-base/src/virtualizer.js';
13
- import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
9
+ import { registerStyles, ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
10
+ import { VirtualListMixin } from './vaadin-virtual-list-mixin.js';
11
+ import { virtualListStyles } from './vaadin-virtual-list-styles.js';
12
+
13
+ registerStyles('vaadin-virtual-list', virtualListStyles, { moduleId: 'vaadin-virtual-list-styles' });
14
14
 
15
15
  /**
16
16
  * `<vaadin-virtual-list>` is a Web Component for displaying a virtual/infinite list of items.
@@ -37,35 +37,13 @@ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mix
37
37
  *
38
38
  * @customElement
39
39
  * @extends HTMLElement
40
- * @mixes ControllerMixin
41
40
  * @mixes ElementMixin
42
41
  * @mixes ThemableMixin
42
+ * @mixes VirtualListMixin
43
43
  */
44
- class VirtualList extends ElementMixin(ControllerMixin(ThemableMixin(PolymerElement))) {
44
+ class VirtualList extends ElementMixin(ThemableMixin(VirtualListMixin(PolymerElement))) {
45
45
  static get template() {
46
46
  return html`
47
- <style>
48
- :host {
49
- display: block;
50
- height: 400px;
51
- overflow: auto;
52
- flex: auto;
53
- align-self: stretch;
54
- }
55
-
56
- :host([hidden]) {
57
- display: none !important;
58
- }
59
-
60
- :host(:not([grid])) #items > ::slotted(*) {
61
- width: 100%;
62
- }
63
-
64
- #items {
65
- position: relative;
66
- }
67
- </style>
68
-
69
47
  <div id="items">
70
48
  <slot></slot>
71
49
  </div>
@@ -75,136 +53,6 @@ class VirtualList extends ElementMixin(ControllerMixin(ThemableMixin(PolymerElem
75
53
  static get is() {
76
54
  return 'vaadin-virtual-list';
77
55
  }
78
-
79
- static get properties() {
80
- return {
81
- /**
82
- * An array containing items determining how many instances to render.
83
- * @type {Array<!VirtualListItem> | undefined}
84
- */
85
- items: { type: Array },
86
-
87
- /**
88
- * Custom function for rendering the content of every item.
89
- * Receives three arguments:
90
- *
91
- * - `root` The render target element representing one item at a time.
92
- * - `virtualList` The reference to the `<vaadin-virtual-list>` element.
93
- * - `model` The object with the properties related with the rendered
94
- * item, contains:
95
- * - `model.index` The index of the rendered item.
96
- * - `model.item` The item.
97
- * @type {VirtualListRenderer | undefined}
98
- */
99
- renderer: Function,
100
-
101
- /** @private */
102
- __virtualizer: Object,
103
- };
104
- }
105
-
106
- static get observers() {
107
- return ['__itemsOrRendererChanged(items, renderer, __virtualizer)'];
108
- }
109
-
110
- /**
111
- * Gets the index of the first visible item in the viewport.
112
- *
113
- * @return {number}
114
- */
115
- get firstVisibleIndex() {
116
- return this.__virtualizer.firstVisibleIndex;
117
- }
118
-
119
- /**
120
- * Gets the index of the last visible item in the viewport.
121
- *
122
- * @return {number}
123
- */
124
- get lastVisibleIndex() {
125
- return this.__virtualizer.lastVisibleIndex;
126
- }
127
-
128
- /** @protected */
129
- ready() {
130
- super.ready();
131
-
132
- this.__virtualizer = new Virtualizer({
133
- createElements: this.__createElements,
134
- updateElement: this.__updateElement.bind(this),
135
- elementsContainer: this,
136
- scrollTarget: this,
137
- scrollContainer: this.shadowRoot.querySelector('#items'),
138
- });
139
-
140
- this.__overflowController = new OverflowController(this);
141
- this.addController(this.__overflowController);
142
-
143
- processTemplates(this);
144
- }
145
-
146
- /**
147
- * Scroll to a specific index in the virtual list.
148
- *
149
- * @param {number} index Index to scroll to
150
- */
151
- scrollToIndex(index) {
152
- this.__virtualizer.scrollToIndex(index);
153
- }
154
-
155
- /** @private */
156
- __createElements(count) {
157
- return [...Array(count)].map(() => document.createElement('div'));
158
- }
159
-
160
- /** @private */
161
- __updateElement(el, index) {
162
- if (el.__renderer !== this.renderer) {
163
- el.__renderer = this.renderer;
164
- this.__clearRenderTargetContent(el);
165
- }
166
-
167
- if (this.renderer) {
168
- this.renderer(el, this, { item: this.items[index], index });
169
- }
170
- }
171
-
172
- /**
173
- * Clears the content of a render target.
174
- * @private
175
- */
176
- __clearRenderTargetContent(element) {
177
- element.innerHTML = '';
178
- // Whenever a Lit-based renderer is used, it assigns a Lit part to the node it was rendered into.
179
- // When clearing the rendered content, this part needs to be manually disposed of.
180
- // Otherwise, using a Lit-based renderer on the same node will throw an exception or render nothing afterward.
181
- delete element._$litPart$;
182
- }
183
-
184
- /** @private */
185
- __itemsOrRendererChanged(items, renderer, virtualizer) {
186
- // If the renderer is removed but there are elements created by
187
- // a previous renderer, we need to request an update from the virtualizer
188
- // to get the already existing elements properly cleared.
189
- const hasRenderedItems = this.childElementCount > 0;
190
-
191
- if ((renderer || hasRenderedItems) && virtualizer) {
192
- virtualizer.size = (items || []).length;
193
- virtualizer.update();
194
- }
195
- }
196
-
197
- /**
198
- * Requests an update for the content of the rows.
199
- * While performing the update, it invokes the renderer passed in the `renderer` property for each visible row.
200
- *
201
- * It is not guaranteed that the update happens immediately (synchronously) after it is requested.
202
- */
203
- requestContentUpdate() {
204
- if (this.__virtualizer) {
205
- this.__virtualizer.update();
206
- }
207
- }
208
56
  }
209
57
 
210
58
  defineCustomElement(VirtualList);
package/web-types.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/virtual-list",
4
- "version": "24.3.0-alpha10",
4
+ "version": "24.3.0-alpha11",
5
5
  "description-markup": "markdown",
6
6
  "contributions": {
7
7
  "html": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/virtual-list",
4
- "version": "24.3.0-alpha10",
4
+ "version": "24.3.0-alpha11",
5
5
  "description-markup": "markdown",
6
6
  "framework": "lit",
7
7
  "framework-config": {