@vaadin/component-base 25.2.0 → 25.2.2

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/component-base",
3
- "version": "25.2.0",
3
+ "version": "25.2.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -38,11 +38,11 @@
38
38
  "lit": "^3.0.0"
39
39
  },
40
40
  "devDependencies": {
41
- "@vaadin/chai-plugins": "~25.2.0",
42
- "@vaadin/test-runner-commands": "~25.2.0",
41
+ "@vaadin/chai-plugins": "~25.2.2",
42
+ "@vaadin/test-runner-commands": "~25.2.2",
43
43
  "@vaadin/testing-helpers": "^2.0.0",
44
44
  "sinon": "^22.0.0"
45
45
  },
46
46
  "customElements": "custom-elements.json",
47
- "gitHead": "f4aa4498fd81ba46a1f03507c104c599f5c85cb7"
47
+ "gitHead": "7d89c827505a3c4112a7aa228da445e39b5fed9a"
48
48
  }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2025 - 2026 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+
7
+ /**
8
+ * Registers a CSS custom property, tolerating the case where the property has
9
+ * already been registered. This can happen when a module is evaluated more than
10
+ * once (e.g. duplicate bundle chunks or two copies of the library on the page),
11
+ * in which case `CSS.registerProperty` throws `InvalidModificationError`. That
12
+ * error is caught and logged as a warning rather than allowed to break loading.
13
+ *
14
+ * @param {PropertyDefinition} definition
15
+ */
16
+ export function registerCSSProperty(definition) {
17
+ try {
18
+ CSS.registerProperty(definition);
19
+ } catch (e) {
20
+ if (e instanceof DOMException && e.name === 'InvalidModificationError') {
21
+ console.warn(`The CSS property ${definition.name} has already been registered.`);
22
+ } else {
23
+ throw e;
24
+ }
25
+ }
26
+ }
27
+
28
+ /**
29
+ * Add a `<style>` block with given styles to the document.
30
+ *
31
+ * @param {string} id the id to set on the created element, only for informational purposes
32
+ * @param {CSSResultGroup[]} styles the styles to add
33
+ */
34
+ export const addGlobalStyles = (id, ...styles) => {
35
+ const styleTag = document.createElement('style');
36
+ styleTag.id = id;
37
+ styleTag.textContent = styles.map((style) => style.toString()).join('\n');
38
+
39
+ document.head.insertAdjacentElement('afterbegin', styleTag);
40
+ };
@@ -15,13 +15,6 @@ export class Cache {
15
15
  */
16
16
  context;
17
17
 
18
- /**
19
- * The number of items to display per page.
20
- *
21
- * @type {number}
22
- */
23
- pageSize;
24
-
25
18
  /**
26
19
  * An array of cached items.
27
20
  *
@@ -50,6 +43,14 @@ export class Cache {
50
43
  */
51
44
  #subCacheByIndex = {};
52
45
 
46
+ /**
47
+ * The number of items per page.
48
+ *
49
+ * @type {number}
50
+ * @private
51
+ */
52
+ #pageSize;
53
+
53
54
  /**
54
55
  * The number of items.
55
56
  *
@@ -123,6 +124,29 @@ export class Cache {
123
124
  return this.#flatSize;
124
125
  }
125
126
 
127
+ /**
128
+ * The number of items per page.
129
+ *
130
+ * @return {number}
131
+ */
132
+ get pageSize() {
133
+ return this.#pageSize;
134
+ }
135
+
136
+ /**
137
+ * Sets the number of items per page for this cache and its descendants.
138
+ * Changing the page size discards all pending page requests.
139
+ *
140
+ * @param {number} pageSize
141
+ */
142
+ set pageSize(pageSize) {
143
+ this.#pageSize = pageSize;
144
+ this.pendingRequests = {};
145
+ this.subCaches.forEach((subCache) => {
146
+ subCache.pageSize = pageSize;
147
+ });
148
+ }
149
+
126
150
  /**
127
151
  * The number of items.
128
152
  *
@@ -29,13 +29,6 @@ export class DataProviderController extends EventTarget {
29
29
  */
30
30
  dataProviderParams;
31
31
 
32
- /**
33
- * A number of items to display per page.
34
- *
35
- * @type {number}
36
- */
37
- pageSize;
38
-
39
32
  /**
40
33
  * A callback that returns whether the given item is expanded.
41
34
  *
@@ -78,14 +71,13 @@ export class DataProviderController extends EventTarget {
78
71
  ) {
79
72
  super();
80
73
  this.host = host;
81
- this.pageSize = pageSize;
82
74
  this.getItemId = getItemId;
83
75
  this.isExpanded = isExpanded;
84
76
  this.placeholder = placeholder;
85
77
  this.isPlaceholder = isPlaceholder;
86
78
  this.dataProvider = dataProvider;
87
79
  this.dataProviderParams = dataProviderParams;
88
- this.rootCache = this.#createRootCache(size);
80
+ this.rootCache = this.#createRootCache(pageSize, size);
89
81
  }
90
82
 
91
83
  /**
@@ -95,6 +87,13 @@ export class DataProviderController extends EventTarget {
95
87
  return this.rootCache.flatSize;
96
88
  }
97
89
 
90
+ /**
91
+ * The number of items per page in the root cache.
92
+ */
93
+ get pageSize() {
94
+ return this.rootCache.pageSize;
95
+ }
96
+
98
97
  /** @private */
99
98
  get #cacheContext() {
100
99
  return {
@@ -113,13 +112,12 @@ export class DataProviderController extends EventTarget {
113
112
  }
114
113
 
115
114
  /**
116
- * Sets the page size and clears the cache.
115
+ * Sets the number of items per page in the root cache and any of its descendants.
117
116
  *
118
117
  * @param {number} pageSize
119
118
  */
120
119
  setPageSize(pageSize) {
121
- this.pageSize = pageSize;
122
- this.clearCache();
120
+ this.rootCache.pageSize = pageSize;
123
121
  }
124
122
 
125
123
  /**
@@ -129,7 +127,6 @@ export class DataProviderController extends EventTarget {
129
127
  */
130
128
  setDataProvider(dataProvider) {
131
129
  this.dataProvider = dataProvider;
132
- this.clearCache();
133
130
  }
134
131
 
135
132
  /**
@@ -143,7 +140,7 @@ export class DataProviderController extends EventTarget {
143
140
  * Clears the cache.
144
141
  */
145
142
  clearCache() {
146
- this.rootCache = this.#createRootCache(this.rootCache.size);
143
+ this.rootCache = this.#createRootCache(this.rootCache.pageSize, this.rootCache.size);
147
144
  }
148
145
 
149
146
  /**
@@ -238,8 +235,8 @@ export class DataProviderController extends EventTarget {
238
235
  }
239
236
 
240
237
  /** @private */
241
- #createRootCache(size) {
242
- return new Cache(this.#cacheContext, this.pageSize, size);
238
+ #createRootCache(pageSize, size) {
239
+ return new Cache(this.#cacheContext, pageSize, size);
243
240
  }
244
241
 
245
242
  /** @private */
@@ -250,7 +247,7 @@ export class DataProviderController extends EventTarget {
250
247
 
251
248
  let params = {
252
249
  page,
253
- pageSize: this.pageSize,
250
+ pageSize: cache.pageSize,
254
251
  parentItem: cache.parentItem,
255
252
  };
256
253
 
package/src/define.js CHANGED
@@ -13,7 +13,7 @@ function dashToCamelCase(dash) {
13
13
 
14
14
  const experimentalMap = {};
15
15
 
16
- export function defineCustomElement(CustomElement, version = '25.2.0') {
16
+ export function defineCustomElement(CustomElement, version = '25.2.2') {
17
17
  Object.defineProperty(CustomElement, 'version', {
18
18
  get() {
19
19
  return version;
@@ -4,7 +4,7 @@
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { css } from 'lit';
7
- import { addGlobalStyles } from './add-global-styles.js';
7
+ import { addGlobalStyles, registerCSSProperty } from '../css-utils.js';
8
8
 
9
9
  // NOTE: Base color CSS custom properties are explicitly registered as `<color>`
10
10
  // here to avoid performance issues in Aura. Aura overrides these properties with
@@ -18,7 +18,7 @@ import { addGlobalStyles } from './add-global-styles.js';
18
18
  '--vaadin-border-color-secondary',
19
19
  '--vaadin-background-color',
20
20
  ].forEach((propertyName) => {
21
- CSS.registerProperty({
21
+ registerCSSProperty({
22
22
  name: propertyName,
23
23
  syntax: '<color>',
24
24
  inherits: true,
@@ -4,7 +4,7 @@
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { css } from 'lit';
7
- import { addGlobalStyles } from './add-global-styles.js';
7
+ import { addGlobalStyles } from '../css-utils.js';
8
8
 
9
9
  addGlobalStyles(
10
10
  'vaadin-base-user-colors',
@@ -1,19 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2025 - 2026 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
-
7
- /**
8
- * Add a `<style>` block with given styles to the document.
9
- *
10
- * @param {string} id the id to set on the created element, only for informational purposes
11
- * @param {CSSResultGroup[]} styles the styles to add
12
- */
13
- export const addGlobalStyles = (id, ...styles) => {
14
- const styleTag = document.createElement('style');
15
- styleTag.id = id;
16
- styleTag.textContent = styles.map((style) => style.toString()).join('\n');
17
-
18
- document.head.insertAdjacentElement('afterbegin', styleTag);
19
- };