@vaadin/component-base 25.1.0-beta1 → 25.1.0-beta3
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/custom-elements.json +11 -14
- package/package.json +5 -5
- package/src/define.js +1 -1
- package/src/i18n-mixin.js +7 -27
- package/src/styles/style-props.js +1 -0
- package/src/virtualizer-iron-list-adapter.js +52 -14
package/custom-elements.json
CHANGED
|
@@ -97,25 +97,22 @@
|
|
|
97
97
|
{
|
|
98
98
|
"kind": "field",
|
|
99
99
|
"name": "i18n",
|
|
100
|
-
"
|
|
101
|
-
"
|
|
102
|
-
"
|
|
103
|
-
"text": "Object"
|
|
104
|
-
}
|
|
100
|
+
"privacy": "public",
|
|
101
|
+
"type": {
|
|
102
|
+
"text": "Object"
|
|
105
103
|
},
|
|
106
|
-
"
|
|
107
|
-
|
|
108
|
-
"name": "value",
|
|
109
|
-
"type": {
|
|
110
|
-
"text": "Object"
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
]
|
|
104
|
+
"description": "The object used to localize this component. To change the default\nlocalization, replace this with an object that provides all properties, or\njust the individual properties you want to change.\n\nShould be overridden by subclasses to provide a custom JSDoc with the\ndefault I18N properties.",
|
|
105
|
+
"attribute": "i18n"
|
|
114
106
|
}
|
|
115
107
|
],
|
|
116
108
|
"attributes": [
|
|
117
109
|
{
|
|
118
|
-
"name": "i18n"
|
|
110
|
+
"name": "i18n",
|
|
111
|
+
"type": {
|
|
112
|
+
"text": "Object"
|
|
113
|
+
},
|
|
114
|
+
"description": "The object used to localize this component. To change the default\nlocalization, replace this with an object that provides all properties, or\njust the individual properties you want to change.\n\nShould be overridden by subclasses to provide a custom JSDoc with the\ndefault I18N properties.",
|
|
115
|
+
"fieldName": "i18n"
|
|
119
116
|
}
|
|
120
117
|
],
|
|
121
118
|
"parameters": [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/component-base",
|
|
3
|
-
"version": "25.1.0-
|
|
3
|
+
"version": "25.1.0-beta3",
|
|
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.1.0-
|
|
42
|
-
"@vaadin/test-runner-commands": "25.1.0-
|
|
41
|
+
"@vaadin/chai-plugins": "25.1.0-beta3",
|
|
42
|
+
"@vaadin/test-runner-commands": "25.1.0-beta3",
|
|
43
43
|
"@vaadin/testing-helpers": "^2.0.0",
|
|
44
|
-
"sinon": "^21.0.
|
|
44
|
+
"sinon": "^21.0.2"
|
|
45
45
|
},
|
|
46
46
|
"customElements": "custom-elements.json",
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "4251850231a42298fda23b83928da588831cdb5d"
|
|
48
48
|
}
|
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.1.0-
|
|
16
|
+
export function defineCustomElement(CustomElement, version = '25.1.0-beta3') {
|
|
17
17
|
Object.defineProperty(CustomElement, 'version', {
|
|
18
18
|
get() {
|
|
19
19
|
return version;
|
package/src/i18n-mixin.js
CHANGED
|
@@ -41,6 +41,12 @@ export const I18nMixin = (defaultI18n, superClass) =>
|
|
|
41
41
|
class I18nMixinClass extends superClass {
|
|
42
42
|
static get properties() {
|
|
43
43
|
return {
|
|
44
|
+
// Even though the property is overridden by a custom getter/setter, it needs to be declared here to initialize
|
|
45
|
+
// __effectiveI18n properly if the i18n property is set before upgrading the element.
|
|
46
|
+
i18n: {
|
|
47
|
+
type: Object,
|
|
48
|
+
},
|
|
49
|
+
|
|
44
50
|
/** @private */
|
|
45
51
|
__effectiveI18n: {
|
|
46
52
|
type: Object,
|
|
@@ -49,28 +55,12 @@ export const I18nMixin = (defaultI18n, superClass) =>
|
|
|
49
55
|
};
|
|
50
56
|
}
|
|
51
57
|
|
|
52
|
-
static get observedAttributes() {
|
|
53
|
-
return [...super.observedAttributes, 'i18n'];
|
|
54
|
-
}
|
|
55
|
-
|
|
56
58
|
constructor() {
|
|
57
59
|
super();
|
|
58
60
|
|
|
59
61
|
this.i18n = deepMerge({}, defaultI18n);
|
|
60
62
|
}
|
|
61
63
|
|
|
62
|
-
/** @protected */
|
|
63
|
-
attributeChangedCallback(name, oldValue, newValue) {
|
|
64
|
-
super.attributeChangedCallback(name, oldValue, newValue);
|
|
65
|
-
if (name === 'i18n') {
|
|
66
|
-
try {
|
|
67
|
-
this.i18n = JSON.parse(newValue);
|
|
68
|
-
} catch (_) {
|
|
69
|
-
// Invalid JSON, ignore
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
64
|
/**
|
|
75
65
|
* The object used to localize this component. To change the default
|
|
76
66
|
* localization, replace this with an object that provides all properties, or
|
|
@@ -79,22 +69,12 @@ export const I18nMixin = (defaultI18n, superClass) =>
|
|
|
79
69
|
* Should be overridden by subclasses to provide a custom JSDoc with the
|
|
80
70
|
* default I18N properties.
|
|
81
71
|
*
|
|
82
|
-
* @
|
|
72
|
+
* @type {Object}
|
|
83
73
|
*/
|
|
84
74
|
get i18n() {
|
|
85
75
|
return this.__customI18n;
|
|
86
76
|
}
|
|
87
77
|
|
|
88
|
-
/**
|
|
89
|
-
* The object used to localize this component. To change the default
|
|
90
|
-
* localization, replace this with an object that provides all properties, or
|
|
91
|
-
* just the individual properties you want to change.
|
|
92
|
-
*
|
|
93
|
-
* Should be overridden by subclasses to provide a custom JSDoc with the
|
|
94
|
-
* default I18N properties.
|
|
95
|
-
*
|
|
96
|
-
* @param {Object} value
|
|
97
|
-
*/
|
|
98
78
|
set i18n(value) {
|
|
99
79
|
if (value === this.__customI18n) {
|
|
100
80
|
return;
|
|
@@ -91,6 +91,7 @@ addGlobalStyles(
|
|
|
91
91
|
--_vaadin-icon-drag: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none"><path d="M11 7c0 .82843-.6716 1.5-1.5 1.5C8.67157 8.5 8 7.82843 8 7s.67157-1.5 1.5-1.5c.8284 0 1.5.67157 1.5 1.5Zm0 5c0 .8284-.6716 1.5-1.5 1.5-.82843 0-1.5-.6716-1.5-1.5s.67157-1.5 1.5-1.5c.8284 0 1.5.6716 1.5 1.5Zm0 5c0 .8284-.6716 1.5-1.5 1.5-.82843 0-1.5-.6716-1.5-1.5s.67157-1.5 1.5-1.5c.8284 0 1.5.6716 1.5 1.5Zm5-10c0 .82843-.6716 1.5-1.5 1.5S13 7.82843 13 7s.6716-1.5 1.5-1.5S16 6.17157 16 7Zm0 5c0 .8284-.6716 1.5-1.5 1.5S13 12.8284 13 12s.6716-1.5 1.5-1.5 1.5.6716 1.5 1.5Zm0 5c0 .8284-.6716 1.5-1.5 1.5S13 17.8284 13 17s.6716-1.5 1.5-1.5 1.5.6716 1.5 1.5Z" fill="currentColor"/></svg>');
|
|
92
92
|
--_vaadin-icon-eye: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M2.036 12.322a1.012 1.012 0 0 1 0-.639C3.423 7.51 7.36 4.5 12 4.5c4.638 0 8.573 3.007 9.963 7.178.07.207.07.431 0 .639C20.577 16.49 16.64 19.5 12 19.5c-4.638 0-8.573-3.007-9.963-7.178Z" /><path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z" /></svg>');
|
|
93
93
|
--_vaadin-icon-eye-slash: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M3.98 8.223A10.477 10.477 0 0 0 1.934 12C3.226 16.338 7.244 19.5 12 19.5c.993 0 1.953-.138 2.863-.395M6.228 6.228A10.451 10.451 0 0 1 12 4.5c4.756 0 8.773 3.162 10.065 7.498a10.522 10.522 0 0 1-4.293 5.774M6.228 6.228 3 3m3.228 3.228 3.65 3.65m7.894 7.894L21 21m-3.228-3.228-3.65-3.65m0 0a3 3 0 1 0-4.243-4.243m4.242 4.242L9.88 9.88" /></svg>');
|
|
94
|
+
--_vaadin-icon-file: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"/><path d="M14 2v4a2 2 0 0 0 2 2h4"/></svg>');
|
|
94
95
|
--_vaadin-icon-fullscreen: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M3.75 3.75v4.5m0-4.5h4.5m-4.5 0L9 9M3.75 20.25v-4.5m0 4.5h4.5m-4.5 0L9 15M20.25 3.75h-4.5m4.5 0v4.5m0-4.5L15 9m5.25 11.25h-4.5m4.5 0v-4.5m0 4.5L15 15" /></svg>');
|
|
95
96
|
--_vaadin-icon-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="18" height="18" x="3" y="3" rx="2" ry="2"/><circle cx="9" cy="9" r="2"/><path d="m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"/></svg>');
|
|
96
97
|
--_vaadin-icon-link: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></svg>');
|
|
@@ -333,6 +333,19 @@ export class IronListAdapter {
|
|
|
333
333
|
return element ? this.scrollTarget.getBoundingClientRect().top - element.getBoundingClientRect().top : undefined;
|
|
334
334
|
}
|
|
335
335
|
|
|
336
|
+
/**
|
|
337
|
+
* Adjusts the scroll position to compensate for any offset change of a given index.
|
|
338
|
+
* @param {number} index - The index whose scroll offset to restore
|
|
339
|
+
* @param {number|undefined} offsetBefore - The scroll offset of the index before the change
|
|
340
|
+
* @private
|
|
341
|
+
*/
|
|
342
|
+
__restoreScrollOffset(index, offsetBefore) {
|
|
343
|
+
const offsetAfter = this.__getIndexScrollOffset(index);
|
|
344
|
+
if (offsetBefore !== undefined && offsetAfter !== undefined) {
|
|
345
|
+
this._scrollTop += offsetBefore - offsetAfter;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
336
349
|
get size() {
|
|
337
350
|
return this.__size;
|
|
338
351
|
}
|
|
@@ -350,13 +363,12 @@ export class IronListAdapter {
|
|
|
350
363
|
this._debouncers._increasePoolIfNeeded.cancel();
|
|
351
364
|
}
|
|
352
365
|
|
|
353
|
-
|
|
354
|
-
this.__preventElementUpdates = true;
|
|
366
|
+
const shouldRestoreScrollPosition = size > 0 && this._scrollTop > 0;
|
|
355
367
|
|
|
356
368
|
// Record the scroll position before changing the size
|
|
357
369
|
let fvi; // First visible index
|
|
358
370
|
let fviOffsetBefore; // Scroll offset of the first visible index
|
|
359
|
-
if (
|
|
371
|
+
if (shouldRestoreScrollPosition) {
|
|
360
372
|
fvi = this.adjustedFirstVisibleIndex;
|
|
361
373
|
fviOffsetBefore = this.__getIndexScrollOffset(fvi);
|
|
362
374
|
}
|
|
@@ -364,23 +376,26 @@ export class IronListAdapter {
|
|
|
364
376
|
// Change the size
|
|
365
377
|
this.__size = size;
|
|
366
378
|
|
|
379
|
+
// Attempts to update elements during _itemsChanged and the subsequent
|
|
380
|
+
// scrollToIndex should be skipped when the scroll position needs to be
|
|
381
|
+
// restored (scroll position > 0 before size change). Otherwise, these
|
|
382
|
+
// element updates can cause the component to make incorrect server
|
|
383
|
+
// requests in its updateElement callback.
|
|
384
|
+
this.__preventElementUpdates = shouldRestoreScrollPosition;
|
|
385
|
+
|
|
367
386
|
this._itemsChanged({
|
|
368
387
|
path: 'items',
|
|
369
388
|
});
|
|
370
389
|
flush();
|
|
371
390
|
|
|
372
|
-
|
|
373
|
-
if (size > 0) {
|
|
391
|
+
if (shouldRestoreScrollPosition) {
|
|
374
392
|
fvi = Math.min(fvi, size - 1);
|
|
375
393
|
// Note, calling scrollToIndex also updates the virtual index offset,
|
|
376
394
|
// causing the virtualizer to add more items when size is increased,
|
|
377
395
|
// and remove exceeding items when size is decreased.
|
|
378
396
|
this.scrollToIndex(fvi);
|
|
379
397
|
|
|
380
|
-
|
|
381
|
-
if (fviOffsetBefore !== undefined && fviOffsetAfter !== undefined) {
|
|
382
|
-
this._scrollTop += fviOffsetBefore - fviOffsetAfter;
|
|
383
|
-
}
|
|
398
|
+
this.__restoreScrollOffset(fvi, fviOffsetBefore);
|
|
384
399
|
}
|
|
385
400
|
|
|
386
401
|
this.__preventElementUpdates = false;
|
|
@@ -396,9 +411,16 @@ export class IronListAdapter {
|
|
|
396
411
|
requestAnimationFrame(() => this._resizeHandler());
|
|
397
412
|
}
|
|
398
413
|
|
|
399
|
-
//
|
|
414
|
+
// Re-render items once the scroll position has been restored.
|
|
415
|
+
// This call also updates the cached scrollTarget height and
|
|
416
|
+
// rechecks whether more virtual elements are needed, since the
|
|
417
|
+
// scrollTarget's height may change after the scrollContainer's
|
|
418
|
+
// height is determined and set, requiring more elements to fill
|
|
419
|
+
// the viewport (e.g., in combo-box, where the scroller height
|
|
420
|
+
// depends on the height of #selector element in the shadow DOM).
|
|
400
421
|
this._resizeHandler();
|
|
401
422
|
flush();
|
|
423
|
+
|
|
402
424
|
// Schedule an update to ensure item positions are correct after subsequent size changes
|
|
403
425
|
// Fix for https://github.com/vaadin/flow-components/issues/6269
|
|
404
426
|
this._debounce('_update', this._update, microTask);
|
|
@@ -839,27 +861,43 @@ export class IronListAdapter {
|
|
|
839
861
|
const threshold = OFFSET_ADJUST_MIN_THRESHOLD;
|
|
840
862
|
const maxShift = 100;
|
|
841
863
|
|
|
864
|
+
// Lazily capture scroll state before the first offset change,
|
|
865
|
+
// so it can be restored afterwards.
|
|
866
|
+
let fvi, fviOffsetBefore;
|
|
867
|
+
const captureScrollState = () => {
|
|
868
|
+
fvi = this.adjustedFirstVisibleIndex;
|
|
869
|
+
fviOffsetBefore = this.__getIndexScrollOffset(fvi);
|
|
870
|
+
};
|
|
871
|
+
|
|
842
872
|
// Near start
|
|
843
873
|
if (this._scrollTop === 0) {
|
|
844
|
-
|
|
845
|
-
|
|
874
|
+
if (oldOffset !== 0) {
|
|
875
|
+
captureScrollState();
|
|
876
|
+
this._vidxOffset = 0;
|
|
846
877
|
super.scrollToIndex(0);
|
|
847
878
|
}
|
|
848
879
|
} else if (this.firstVisibleIndex < threshold && this._vidxOffset > 0) {
|
|
880
|
+
captureScrollState();
|
|
849
881
|
this._vidxOffset -= Math.min(this._vidxOffset, maxShift);
|
|
850
882
|
super.scrollToIndex(this.firstVisibleIndex + (oldOffset - this._vidxOffset));
|
|
851
883
|
}
|
|
852
884
|
|
|
853
885
|
// Near end
|
|
854
886
|
if (this._scrollTop >= this._maxScrollTop && this._maxScrollTop > 0) {
|
|
855
|
-
|
|
856
|
-
|
|
887
|
+
if (oldOffset !== maxOffset) {
|
|
888
|
+
captureScrollState();
|
|
889
|
+
this._vidxOffset = maxOffset;
|
|
857
890
|
super.scrollToIndex(this._virtualCount - 1);
|
|
858
891
|
}
|
|
859
892
|
} else if (this.firstVisibleIndex > this._virtualCount - threshold && this._vidxOffset < maxOffset) {
|
|
893
|
+
captureScrollState();
|
|
860
894
|
this._vidxOffset += Math.min(maxOffset - this._vidxOffset, maxShift);
|
|
861
895
|
super.scrollToIndex(this.firstVisibleIndex - (this._vidxOffset - oldOffset));
|
|
862
896
|
}
|
|
897
|
+
|
|
898
|
+
if (fvi !== undefined) {
|
|
899
|
+
this.__restoreScrollOffset(fvi, fviOffsetBefore);
|
|
900
|
+
}
|
|
863
901
|
}
|
|
864
902
|
}
|
|
865
903
|
}
|