Skip to content

Commit fd22d4c

Browse files
author
Guillaume Chau
committed
Version bump
1 parent 96fc0bd commit fd22d4c

File tree

4 files changed

+92
-52
lines changed

4 files changed

+92
-52
lines changed

dist/vue-virtual-scroller.esm.js

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,11 @@ if (GlobalVue$2) {
181181
}
182182

183183
var VirtualScroller = { render: function render() {
184-
var _vm = this;var _h = _vm.$createElement;var _c = _vm._self._c || _h;return _c(_vm.mainTag, { directives: [{ name: "observe-visibility", rawName: "v-observe-visibility", value: _vm.handleVisibilityChange, expression: "handleVisibilityChange" }], tag: "component", staticClass: "virtual-scroller", class: _vm.cssClass, on: { "scroll": _vm.handleScroll } }, [_vm._t("before-container"), _vm._v(" "), _c(_vm.containerTag, { tag: "component", staticClass: "item-container", class: _vm.containerClass, style: _vm.itemContainerStyle }, [_vm._t("before-content"), _vm._v(" "), _c(_vm.contentTag, { tag: "component", staticClass: "items", class: _vm.contentClass, style: _vm.itemsStyle }, [_vm.renderers ? _vm._l(_vm.visibleItems, function (item, index) {
184+
var _vm = this;var _h = _vm.$createElement;var _c = _vm._self._c || _h;return _c(_vm.mainTag, { directives: [{ name: "observe-visibility", rawName: "v-observe-visibility", value: _vm.handleVisibilityChange, expression: "handleVisibilityChange" }], tag: "component", staticClass: "virtual-scroller", class: _vm.cssClass, on: { "scroll": _vm.handleScroll } }, [_vm._t("before-container", [_c(_vm.containerTag, { ref: "itemContainer", tag: "component", staticClass: "item-container", class: _vm.containerClass, style: _vm.itemContainerStyle }, [_vm._t("before-content", [_c(_vm.contentTag, { ref: "items", tag: "component", staticClass: "items", class: _vm.contentClass, style: _vm.itemsStyle }, [_vm.renderers ? _vm._l(_vm.visibleItems, function (item, index) {
185185
return _c(_vm.renderers[item[_vm.typeField]], { key: _vm.keysEnabled && item[_vm.keyField] || '', tag: "component", staticClass: "item", attrs: { "item": item, "item-index": _vm._startIndex + index } });
186186
}) : [_vm._l(_vm.visibleItems, function (item, index) {
187187
return _vm._t("default", null, { item: item, itemIndex: _vm._startIndex + index, itemKey: _vm.keysEnabled && item[_vm.keyField] || '' });
188-
})]], 2), _vm._v(" "), _vm._t("after-content")], 2), _vm._v(" "), _vm._t("after-container"), _vm._v(" "), _c('resize-observer', { on: { "notify": _vm.handleResize } })], 2);
188+
})]], 2), _vm._v(" "), _vm._t("after-content")])], 2), _vm._v(" "), _vm._t("after-container", [_c('resize-observer', { on: { "notify": _vm.handleResize } })])])], 2);
189189
}, staticRenderFns: [], _scopeId: 'data-v-727d6836',
190190
name: 'virtual-scroller',
191191

@@ -270,6 +270,7 @@ var VirtualScroller = { render: function render() {
270270
};
271271
},
272272

273+
273274
computed: {
274275
cssClass: function cssClass() {
275276
return {
@@ -341,6 +342,8 @@ var VirtualScroller = { render: function render() {
341342
}
342343
},
343344
updateVisibleItems: function updateVisibleItems() {
345+
var _this = this;
346+
344347
var force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
345348

346349
var l = this.items.length;
@@ -355,10 +358,11 @@ var VirtualScroller = { render: function render() {
355358

356359
var buffer = parseInt(this.buffer);
357360
var poolSize = parseInt(this.poolSize);
358-
var scrollTop = ~~((scroll.top - buffer) / poolSize) * poolSize;
359-
var scrollBottom = ~~Math.ceil((scroll.bottom + buffer) / poolSize) * poolSize;
361+
var scrollTop = ~~(scroll.top / poolSize) * poolSize - buffer;
362+
var scrollBottom = Math.ceil(scroll.bottom / poolSize) * poolSize + buffer;
360363

361-
if (!force && scrollTop === this._oldScrollTop && scrollBottom === this._oldScrollBottom) {
364+
if (!force && (scrollTop === this._oldScrollTop && scrollBottom === this._oldScrollBottom || this._skip)) {
365+
this._skip = false;
362366
return;
363367
} else {
364368
this._oldScrollTop = scrollTop;
@@ -414,19 +418,30 @@ var VirtualScroller = { render: function render() {
414418
containerHeight = l * itemHeight;
415419
}
416420

417-
this.keysEnabled = !(startIndex > this._endIndex || endIndex < this._startIndex);
418-
this._startIndex = startIndex;
419-
this._endIndex = endIndex;
420-
this._length = l;
421-
this.visibleItems = items.slice(startIndex, endIndex);
422-
this.itemContainerStyle = {
423-
height: containerHeight + 'px'
424-
};
425-
this.itemsStyle = {
426-
marginTop: offsetTop + 'px'
427-
};
428-
429-
this.emitUpdate && this.$emit('update', startIndex, endIndex);
421+
if (this._startIndex !== startIndex || this._endIndex !== endIndex || this._offsetTop !== offsetTop || this._height !== containerHeight || this._length !== l) {
422+
this.keysEnabled = !(startIndex > this._endIndex || endIndex < this._startIndex);
423+
424+
// Add next items
425+
this.visibleItems = items.slice(this._startIndex, endIndex);
426+
this.itemContainerStyle = {
427+
height: containerHeight + 'px'
428+
};
429+
this.itemsStyle = {
430+
marginTop: offsetTop + 'px'
431+
432+
// Remove previous items
433+
};this.$nextTick(function () {
434+
_this.visibleItems = items.slice(startIndex, endIndex);
435+
});
436+
437+
this.emitUpdate && this.$emit('update', startIndex, endIndex);
438+
439+
this._startIndex = startIndex;
440+
this._endIndex = endIndex;
441+
this._length = l;
442+
this._offsetTop = offsetTop;
443+
this._height = containerHeight;
444+
}
430445
}
431446
},
432447
scrollToItem: function scrollToItem(index) {
@@ -461,14 +476,15 @@ var VirtualScroller = { render: function render() {
461476
this.updateVisibleItems();
462477
},
463478
handleResize: function handleResize() {
479+
this.$emit('resize');
464480
this._ready && this.updateVisibleItems();
465481
},
466482
handleVisibilityChange: function handleVisibilityChange(isVisible, entry) {
467-
var _this = this;
483+
var _this2 = this;
468484

469485
if (this._ready && (isVisible || entry.boundingClientRect.width !== 0 || entry.boundingClientRect.height !== 0)) {
470486
this.$nextTick(function () {
471-
_this.updateVisibleItems();
487+
_this2.updateVisibleItems();
472488
});
473489
}
474490
}
@@ -479,24 +495,28 @@ var VirtualScroller = { render: function render() {
479495
this._startIndex = 0;
480496
this._oldScrollTop = null;
481497
this._oldScrollBottom = null;
498+
this._offsetTop = 0;
499+
this._height = 0;
482500
var prerender = parseInt(this.prerender);
483501
if (prerender > 0) {
484502
this.visibleItems = this.items.slice(0, prerender);
485503
this._length = this.visibleItems.length;
486504
this._endIndex = this._length - 1;
505+
this._skip = true;
487506
} else {
488507
this._endIndex = 0;
489508
this._length = 0;
509+
this._skip = false;
490510
}
491511
},
492512
mounted: function mounted() {
493-
var _this2 = this;
513+
var _this3 = this;
494514

495515
this.applyPageMode();
496516
this.$nextTick(function () {
497-
_this2.updateVisibleItems(true);
498-
_this2._ready = true;
499-
_this2.$nextTick(_this2.updateVisibleItems);
517+
_this3.updateVisibleItems(true);
518+
_this3._ready = true;
519+
_this3.$nextTick(_this3.updateVisibleItems);
500520
});
501521
},
502522
beforeDestroy: function beforeDestroy() {
@@ -510,7 +530,7 @@ function registerComponents(Vue, prefix) {
510530

511531
var plugin = {
512532
// eslint-disable-next-line no-undef
513-
version: "0.10.1",
533+
version: "0.10.2",
514534
install: function install(Vue, options) {
515535
var finalOptions = Object.assign({}, {
516536
installComponents: true,

0 commit comments

Comments
 (0)