@vaadin/component-base 25.1.0-beta2 → 25.1.0-beta4

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.
@@ -97,15 +97,22 @@
97
97
  {
98
98
  "kind": "field",
99
99
  "name": "i18n",
100
- "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.",
100
+ "privacy": "public",
101
101
  "type": {
102
102
  "text": "Object"
103
- }
103
+ },
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"
104
106
  }
105
107
  ],
106
108
  "attributes": [
107
109
  {
108
- "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"
109
116
  }
110
117
  ],
111
118
  "parameters": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/component-base",
3
- "version": "25.1.0-beta2",
3
+ "version": "25.1.0-beta4",
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-beta2",
42
- "@vaadin/test-runner-commands": "25.1.0-beta2",
41
+ "@vaadin/chai-plugins": "25.1.0-beta4",
42
+ "@vaadin/test-runner-commands": "25.1.0-beta4",
43
43
  "@vaadin/testing-helpers": "^2.0.0",
44
- "sinon": "^21.0.0"
44
+ "sinon": "^21.0.2"
45
45
  },
46
46
  "customElements": "custom-elements.json",
47
- "gitHead": "ffbedbae08a5160d13bcd1c6fcaa328df5103a05"
47
+ "gitHead": "b27f6706a2b5c07cedec353fccbdecee95d53024"
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-beta2') {
16
+ export function defineCustomElement(CustomElement, version = '25.1.0-beta4') {
17
17
  Object.defineProperty(CustomElement, 'version', {
18
18
  get() {
19
19
  return version;
@@ -18,6 +18,4 @@ export declare function ElementMixin<T extends Constructor<HTMLElement>>(
18
18
  export declare class ElementMixinClass {
19
19
  static is: string;
20
20
  static version: string;
21
-
22
- protected static finalize(): void;
23
21
  }
@@ -38,9 +38,7 @@ const registered = new Set();
38
38
  export const ElementMixin = (superClass) =>
39
39
  class VaadinElementMixin extends DirMixin(superClass) {
40
40
  /** @protected */
41
- static finalize() {
42
- super.finalize();
43
-
41
+ static _ensureRegistrations() {
44
42
  const { is } = this;
45
43
 
46
44
  // Registers a class prototype for telemetry purposes.
@@ -66,5 +64,7 @@ export const ElementMixin = (superClass) =>
66
64
  'Vaadin components require the "standards mode" declaration. Please add <!DOCTYPE html> to the HTML document.',
67
65
  );
68
66
  }
67
+
68
+ this.constructor._ensureRegistrations();
69
69
  }
70
70
  };
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
@@ -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
  }
@@ -382,10 +395,7 @@ export class IronListAdapter {
382
395
  // and remove exceeding items when size is decreased.
383
396
  this.scrollToIndex(fvi);
384
397
 
385
- const fviOffsetAfter = this.__getIndexScrollOffset(fvi);
386
- if (fviOffsetBefore !== undefined && fviOffsetAfter !== undefined) {
387
- this._scrollTop += fviOffsetBefore - fviOffsetAfter;
388
- }
398
+ this.__restoreScrollOffset(fvi, fviOffsetBefore);
389
399
  }
390
400
 
391
401
  this.__preventElementUpdates = false;
@@ -851,27 +861,43 @@ export class IronListAdapter {
851
861
  const threshold = OFFSET_ADJUST_MIN_THRESHOLD;
852
862
  const maxShift = 100;
853
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
+
854
872
  // Near start
855
873
  if (this._scrollTop === 0) {
856
- this._vidxOffset = 0;
857
- if (oldOffset !== this._vidxOffset) {
874
+ if (oldOffset !== 0) {
875
+ captureScrollState();
876
+ this._vidxOffset = 0;
858
877
  super.scrollToIndex(0);
859
878
  }
860
879
  } else if (this.firstVisibleIndex < threshold && this._vidxOffset > 0) {
880
+ captureScrollState();
861
881
  this._vidxOffset -= Math.min(this._vidxOffset, maxShift);
862
882
  super.scrollToIndex(this.firstVisibleIndex + (oldOffset - this._vidxOffset));
863
883
  }
864
884
 
865
885
  // Near end
866
886
  if (this._scrollTop >= this._maxScrollTop && this._maxScrollTop > 0) {
867
- this._vidxOffset = maxOffset;
868
- if (oldOffset !== this._vidxOffset) {
887
+ if (oldOffset !== maxOffset) {
888
+ captureScrollState();
889
+ this._vidxOffset = maxOffset;
869
890
  super.scrollToIndex(this._virtualCount - 1);
870
891
  }
871
892
  } else if (this.firstVisibleIndex > this._virtualCount - threshold && this._vidxOffset < maxOffset) {
893
+ captureScrollState();
872
894
  this._vidxOffset += Math.min(maxOffset - this._vidxOffset, maxShift);
873
895
  super.scrollToIndex(this.firstVisibleIndex - (this._vidxOffset - oldOffset));
874
896
  }
897
+
898
+ if (fvi !== undefined) {
899
+ this.__restoreScrollOffset(fvi, fviOffsetBefore);
900
+ }
875
901
  }
876
902
  }
877
903
  }