@plcmp/pl-virtual-scroll 1.0.2 → 1.0.4

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": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Component for lazy list render.",
5
5
  "main": "pl-virtual-scroll.js",
6
6
  "repository": {
@@ -100,33 +100,36 @@ class PlVirtualScroll extends PlElement {
100
100
  setTimeout(() => this.render(), 0);
101
101
  }
102
102
  break;
103
+
103
104
  case 'splice': {
104
105
  let { index: spliceIndex } = mutation;
105
- // if mutation is not root try to apply effects to children (need when pushing to array inside array)
106
- if (rest.length > 0) {
107
- let path = [this.as, ...rest].join('.');
108
- this.phyPool[index].ctx.applyEffects({ ...mutation, path });
109
- } else {
110
- this.phyPool.forEach((i) => {
111
- if (i.index !== null && i.index >= spliceIndex && i.index < this.items.length) {
112
- if (this.items[i.index] instanceof PlaceHolder) this.items.load?.(this.items[i.index]);
113
-
114
- i.ctx.replace(this.items[i.index]);
115
- i.ctx.applyEffects(undefined);
116
- i.ctx._ti.applyBinds();
117
- } else if (i.index >= this.items.length) {
118
- i.index = null;
119
- i.offset = -10000;
120
- fixOffset(i);
121
- }
122
- });
123
- }
106
+ if (Number(index) >= 0) {
107
+ // if mutation is not root try to apply effects to children (need when pushing to array inside array)
108
+ if (rest.length > 0) {
109
+ let path = [this.as, ...rest].join('.');
110
+ this.phyPool[index].ctx.applyEffects({...mutation, path});
111
+ } else {
112
+ this.phyPool.forEach((i) => {
113
+ if (i.index !== null && i.index >= spliceIndex && i.index < this.items.length) {
114
+ if (this.items[i.index] instanceof PlaceHolder) this.items.load?.(this.items[i.index]);
115
+
116
+ i.ctx.replace(this.items[i.index]);
117
+ i.ctx.applyEffects(undefined);
118
+ i.ctx._ti.applyBinds();
119
+ } else if (i.index >= this.items.length) {
120
+ i.index = null;
121
+ i.offset = -10000;
122
+ fixOffset(i);
123
+ }
124
+ });
125
+ }
124
126
 
125
- // TODO: add more Heuristic to scroll list if visible elements that not changed? like insert rows before
126
- // visible area
127
+ // TODO: add more Heuristic to scroll list if visible elements that not changed? like insert rows before
128
+ // visible area
127
129
 
128
- // refresh all PHY if they can be affected
129
- setTimeout(() => this.render(), 0);
130
+ // refresh all PHY if they can be affected
131
+ setTimeout(() => this.render(), 0);
132
+ }
130
133
 
131
134
  break;
132
135
  }
@@ -211,8 +214,9 @@ class PlVirtualScroll extends PlElement {
211
214
  : 32; // TODO: replace w/o constant
212
215
  const predictedStart = Math.min(Math.ceil(this.canvas.parentNode.scrollTop / heightForStart), this.items.length - 1);
213
216
  firstShadow = lastShadow = this.renderItem(predictedStart, unused.pop(), this.canvas.parentNode.scrollTop);
214
- used.unshift(firstShadow);
215
217
  }
218
+
219
+ used.unshift(firstShadow);
216
220
  }
217
221
 
218
222
  // render forward