@plcmp/pl-virtual-scroll 0.1.12 → 0.1.14

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": "@plcmp/pl-virtual-scroll",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "description": "Component for lazy list render.",
5
5
  "main": "pl-virtual-scroll.js",
6
6
  "repository": {
@@ -22,7 +22,7 @@ class PlVirtualScroll extends PlElement {
22
22
  renderedStart: { type: Number, value: 0 },
23
23
  renderedCount: { type: Number, value: 0 },
24
24
  phyItems: { type: Array, value: () => [] },
25
- canvas: { type: Object },
25
+ canvas: { type: Object }
26
26
  }
27
27
  static template = html`
28
28
  <style>
@@ -74,19 +74,20 @@ class PlVirtualScroll extends PlElement {
74
74
  let [, index, ...rest] = normalizePath(mutation.path);
75
75
  switch (mutation.action) {
76
76
  case 'upd':
77
- if(Array.isArray(mutation.value) && Array.isArray(mutation.oldValue) && mutation.oldValue.length == mutation.value.length) {
77
+ if(mutation.path == 'items' && Array.isArray(mutation.value) && Array.isArray(mutation.oldValue)) {
78
78
  this.phyPool.forEach(i => {
79
- i.ctx.replace(this.items[i.index]);
80
- i.ctx.applyEffects();
81
- i.ctx._ti.applyBinds();
79
+ if (i.index !== null && i.index < this.items.length) {
80
+ if (this.items[i.index] instanceof PlaceHolder) this.items.load?.(this.items[i.index]);
81
+
82
+ i.ctx.replace(this.items[i.index]);
83
+ i.ctx.applyEffects();
84
+ i.ctx._ti.applyBinds();
85
+ } else if (i.index >= this.items.length) {
86
+ i.index = null;
87
+ }
82
88
  });
83
89
  }
84
90
 
85
- // Временный решение, занулям физический пулл в случаях когда значения массива приходят внутри объектов
86
- // Исправить в будущем на более умную замену значений
87
- if(Array.isArray(mutation.value) && Array.isArray(mutation.oldValue) && mutation.oldValue.length != mutation.value.length) {
88
- this.phyPool = [];
89
- }
90
91
  if (index !== undefined && +index >= 0) {
91
92
  let el = this.phyPool.find(i => i.index === +index);
92
93
  if (el && rest.length > 0) {
@@ -146,8 +147,8 @@ class PlVirtualScroll extends PlElement {
146
147
  /*let first = Math.floor(offset / this.elementHeight);
147
148
  let last = Math.ceil((offset+height) / this.elementHeight);*/
148
149
  // Reset scroll position if update data smaller than current visible index
149
- if (!scroll && this.items.length < (offset + height * 1.5) / this.elementHeight) {
150
- canvas.parentNode.scrollTop = 0;
150
+ if (!scroll && this.items.length < Math.floor((offset + height) / this.elementHeight)) {
151
+ canvas.parentNode.scrollTop = this.items.length * this.elementHeight - height;
151
152
  }
152
153
  let shadowEnd = Math.min(this.items.length, Math.ceil((offset + height * 1.5) / this.elementHeight));
153
154
  let shadowBegin = Math.max(0, Math.floor(Math.min((offset - height / 2) / this.elementHeight, shadowEnd - height * 2 / this.elementHeight)));
@@ -231,7 +232,7 @@ class PlVirtualScroll extends PlElement {
231
232
  if (n.style) {
232
233
  n.style.transform = `translateY(${target.offset}px)`;
233
234
  n.style.position = 'absolute';
234
- n.setAttribute('virtualOffser', target.offset);
235
+ n.setAttribute('virtualOffset', target.offset);
235
236
  }
236
237
  });
237
238
  return target;