@danielgindi/virtual-list-helper 1.0.4 → 1.0.6
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/dist/virtual-list-helper.cjs.js +241 -115
- package/dist/virtual-list-helper.cjs.js.map +1 -1
- package/dist/virtual-list-helper.cjs.min.js +2 -2
- package/dist/virtual-list-helper.cjs.min.js.map +1 -1
- package/dist/virtual-list-helper.es6.js +180 -54
- package/dist/virtual-list-helper.es6.js.map +1 -1
- package/dist/virtual-list-helper.es6.min.js +2 -2
- package/dist/virtual-list-helper.es6.min.js.map +1 -1
- package/dist/virtual-list-helper.umd.js +241 -115
- package/dist/virtual-list-helper.umd.js.map +1 -1
- package/dist/virtual-list-helper.umd.min.js +2 -2
- package/dist/virtual-list-helper.umd.min.js.map +1 -1
- package/lib/index.js +179 -53
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @danielgindi/virtual-list-helper 1.0.
|
|
2
|
+
* @danielgindi/virtual-list-helper 1.0.6
|
|
3
3
|
* git://github.com/danielgindi/virtual-list-helper.git
|
|
4
4
|
*/
|
|
5
5
|
'use strict';
|
|
@@ -4517,7 +4517,46 @@ if (DESCRIPTORS && isCallable(NativeSymbol) && (!('description' in SymbolPrototy
|
|
|
4517
4517
|
|
|
4518
4518
|
/** */
|
|
4519
4519
|
|
|
4520
|
-
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
4520
|
+
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
4521
|
+
|
|
4522
|
+
var hasInsertAdjacentElement = Element.prototype.insertAdjacentElement !== undefined;
|
|
4523
|
+
|
|
4524
|
+
function insertBefore(el, before, parent) {
|
|
4525
|
+
if (!before)
|
|
4526
|
+
parent.appendChild(el);else
|
|
4527
|
+
if (hasInsertAdjacentElement === true)
|
|
4528
|
+
before.insertAdjacentElement('beforebegin', el);else
|
|
4529
|
+
parent.insertBefore(el, before);
|
|
4530
|
+
}
|
|
4531
|
+
|
|
4532
|
+
/**
|
|
4533
|
+
*
|
|
4534
|
+
* @param {Element} itemEl
|
|
4535
|
+
* @param {DocumentFragment|null} fragment
|
|
4536
|
+
* @param {Node|undefined} before
|
|
4537
|
+
* @param {Element} itemParent
|
|
4538
|
+
* @returns {DocumentFragment|null}
|
|
4539
|
+
*/
|
|
4540
|
+
function insertBeforeWithFragment(itemEl, fragment, before, itemParent) {
|
|
4541
|
+
if (itemEl.parentNode !== itemParent) {
|
|
4542
|
+
if (!fragment)
|
|
4543
|
+
fragment = document.createDocumentFragment();
|
|
4544
|
+
fragment.appendChild(itemEl);
|
|
4545
|
+
} else {
|
|
4546
|
+
// insert fragment
|
|
4547
|
+
if (fragment && fragment.childNodes.length > 0) {
|
|
4548
|
+
insertBefore(fragment, before, itemParent);
|
|
4549
|
+
fragment = null;
|
|
4550
|
+
}
|
|
4551
|
+
|
|
4552
|
+
// insert element
|
|
4553
|
+
if (itemEl.nextSibling !== before) {
|
|
4554
|
+
insertBefore(itemEl, before, itemParent);
|
|
4555
|
+
}
|
|
4556
|
+
}
|
|
4557
|
+
|
|
4558
|
+
return fragment;
|
|
4559
|
+
}var VirtualListHelper = /*#__PURE__*/function () {
|
|
4521
4560
|
/**
|
|
4522
4561
|
* @param {VirtualListHelper~Options} opts
|
|
4523
4562
|
*/
|
|
@@ -4895,6 +4934,7 @@ var hasOwnProperty = Object.prototype.hasOwnProperty;var VirtualListHelper = /*#
|
|
|
4895
4934
|
var list = p.list;
|
|
4896
4935
|
var virtual = p.virtual;
|
|
4897
4936
|
var virtualWrapper = p.virtualWrapper;
|
|
4937
|
+
var itemParent = p.currentItemsParent;
|
|
4898
4938
|
var scrollTop = list.scrollTop;
|
|
4899
4939
|
var visibleHeight = list.clientHeight;
|
|
4900
4940
|
var visibleBottom = scrollTop + visibleHeight;
|
|
@@ -4904,123 +4944,172 @@ var hasOwnProperty = Object.prototype.hasOwnProperty;var VirtualListHelper = /*#
|
|
|
4904
4944
|
var existingEls = p.existingEls;
|
|
4905
4945
|
var existingCount = existingEls.length;
|
|
4906
4946
|
|
|
4907
|
-
if (virtual) {
|
|
4908
|
-
|
|
4947
|
+
if (virtual) {
|
|
4948
|
+
var originalWidth = list.clientWidth;
|
|
4909
4949
|
|
|
4950
|
+
if (!virtualWrapper) {
|
|
4951
|
+
virtualWrapper = p.virtualWrapper = p.userItemsParent;
|
|
4910
4952
|
if (!virtualWrapper) {
|
|
4911
|
-
virtualWrapper = p.virtualWrapper =
|
|
4912
|
-
|
|
4913
|
-
|
|
4914
|
-
list.appendChild(virtualWrapper);
|
|
4915
|
-
}
|
|
4953
|
+
virtualWrapper = p.virtualWrapper = document.createElement('div');
|
|
4954
|
+
list.appendChild(virtualWrapper);
|
|
4955
|
+
}
|
|
4916
4956
|
|
|
4917
|
-
|
|
4957
|
+
this._resetCurrentItemsParent();
|
|
4958
|
+
itemParent = p.currentItemsParent;
|
|
4918
4959
|
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
|
|
4960
|
+
if (p.autoVirtualWrapperWidth) {
|
|
4961
|
+
virtualWrapper.style.width = '100%';
|
|
4962
|
+
p.virtualWrapperWidthWasSet = true;
|
|
4963
|
+
} else {
|
|
4964
|
+
p.virtualWrapperWidthWasSet = false;
|
|
4965
|
+
}
|
|
4966
|
+
}
|
|
4967
|
+
|
|
4968
|
+
// Mark all of them for potential reuse
|
|
4969
|
+
for (var i = 0; i < existingCount; i++) {
|
|
4970
|
+
existingEls[i][ReuseElSymbol] = true;
|
|
4971
|
+
}
|
|
4972
|
+
|
|
4973
|
+
// Make sure we have at least estimated positions for all items so we can translate scroll position
|
|
4974
|
+
this._calculateItemPosition(p.count - 1);
|
|
4975
|
+
|
|
4976
|
+
// Find existing elements index range
|
|
4977
|
+
var existingRange = this._getExistingElsRange();
|
|
4978
|
+
|
|
4979
|
+
// Find first visible element
|
|
4980
|
+
var firstVisibleIndex = binarySearchPosition(p.cachedItemPositions, scrollTop);
|
|
4981
|
+
var firstRenderIndex = Math.max(0, firstVisibleIndex - buffer);
|
|
4982
|
+
|
|
4983
|
+
// Iterate over viewport
|
|
4984
|
+
var index = firstRenderIndex;
|
|
4985
|
+
var renderPos = this._calculateItemPosition(index);
|
|
4986
|
+
var bufferEnd = buffer;
|
|
4987
|
+
|
|
4988
|
+
// we want to render until viewport's bottom + buffer items
|
|
4989
|
+
var maxIndexToRender = Math.max(index, binarySearchPosition(p.cachedItemPositions, visibleBottom - 1) + 1 + buffer);
|
|
4990
|
+
|
|
4991
|
+
var insertedItems = [];
|
|
4992
|
+
|
|
4993
|
+
/** @type DocumentFragment|null */
|
|
4994
|
+
var fragment = null;
|
|
4995
|
+
|
|
4996
|
+
// Find the element to insert before
|
|
4997
|
+
var before = virtualWrapper.childNodes[0];
|
|
4998
|
+
|
|
4999
|
+
var findElementToReuse = function findElementToReuse(index) {
|
|
5000
|
+
// Find existing element to reuse
|
|
5001
|
+
/** @type Element|undefined */
|
|
5002
|
+
var existingEl = undefined;
|
|
5003
|
+
|
|
5004
|
+
if (existingRange.firstIndex !== -1 && index >= existingRange.firstIndex && index <= existingRange.lastIndex) {
|
|
5005
|
+
existingEl = existingEls.find(function (x) {return x[ItemIndexSymbol] === index && x[ReuseElSymbol] === true;});
|
|
4925
5006
|
}
|
|
4926
5007
|
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
existingEls
|
|
5008
|
+
if (existingEl === undefined) {
|
|
5009
|
+
existingEl = (existingRange.firstIndex < firstRenderIndex || existingRange.firstValidArrayIndex > 0 ?
|
|
5010
|
+
existingEls.find(function (x) {return (
|
|
5011
|
+
(x[ItemIndexSymbol] < firstRenderIndex || false === hasOwnProperty.call(x, ItemIndexSymbol)) &&
|
|
5012
|
+
x[ReuseElSymbol] === true);}) :
|
|
5013
|
+
undefined) ||
|
|
5014
|
+
findLast(existingEls, function (x) {return x[ReuseElSymbol] === true;});
|
|
4930
5015
|
}
|
|
4931
5016
|
|
|
4932
|
-
|
|
4933
|
-
|
|
5017
|
+
if (existingEl !== undefined) {
|
|
5018
|
+
delete existingEl[ReuseElSymbol];
|
|
5019
|
+
}
|
|
4934
5020
|
|
|
4935
|
-
|
|
4936
|
-
|
|
5021
|
+
return existingEl;
|
|
5022
|
+
};
|
|
4937
5023
|
|
|
4938
|
-
|
|
4939
|
-
|
|
4940
|
-
|
|
5024
|
+
// First we iterate and try to add all at once in a fragment, as much as we can.
|
|
5025
|
+
// And then reflow the at once.
|
|
5026
|
+
for (; index < count && index < maxIndexToRender; index++) {
|
|
5027
|
+
var existingEl = findElementToReuse(index);
|
|
4941
5028
|
|
|
4942
|
-
|
|
4943
|
-
|
|
4944
|
-
var renderPos = _this._calculateItemPosition(index);
|
|
4945
|
-
var bufferEnd = buffer;
|
|
5029
|
+
if (before && before === existingEl)
|
|
5030
|
+
before = before.nextSibling;
|
|
4946
5031
|
|
|
4947
|
-
|
|
4948
|
-
var
|
|
5032
|
+
// Dequeue the element by reusing or creating a new one
|
|
5033
|
+
var itemEl = this._dequeueElementForIndex(existingEl, index, before, true);
|
|
5034
|
+
insertedItems.push([itemEl, index]);
|
|
4949
5035
|
|
|
4950
|
-
|
|
4951
|
-
|
|
4952
|
-
while ((renderPos < visibleBottom || bufferEnd-- > 0) && index < count) {
|
|
4953
|
-
// Find existing element to reuse
|
|
4954
|
-
/** @type Element|undefined */
|
|
4955
|
-
var existingEl = undefined;
|
|
5036
|
+
fragment = insertBeforeWithFragment(itemEl, fragment, before, itemParent);
|
|
5037
|
+
}
|
|
4956
5038
|
|
|
4957
|
-
|
|
4958
|
-
|
|
4959
|
-
|
|
5039
|
+
// Insert any remaining fragment
|
|
5040
|
+
if (fragment && fragment.childNodes.length > 0) {
|
|
5041
|
+
insertBefore(fragment, before, itemParent);
|
|
5042
|
+
}
|
|
4960
5043
|
|
|
4961
|
-
|
|
4962
|
-
|
|
4963
|
-
|
|
4964
|
-
|
|
4965
|
-
|
|
4966
|
-
|
|
4967
|
-
findLast(existingEls, function (x) {return x[ReuseElSymbol] === true;});
|
|
4968
|
-
}
|
|
5044
|
+
// Iterate on inserted items and reflow them
|
|
5045
|
+
for (var _i = 0, _insertedItems = insertedItems; _i < _insertedItems.length; _i++) {var item = _insertedItems[_i];
|
|
5046
|
+
var _index = item[1];
|
|
5047
|
+
this._insertItemAndFlow(item[0], _index, false /* inserted already */);
|
|
5048
|
+
renderPos = p.cachedItemPositions[_index] + p.cachedItemHeights[_index];
|
|
5049
|
+
}
|
|
4969
5050
|
|
|
4970
|
-
|
|
4971
|
-
|
|
4972
|
-
|
|
5051
|
+
// See if we still need to insert more items
|
|
5052
|
+
if (renderPos < visibleBottom) {
|
|
5053
|
+
for (; (renderPos < visibleBottom || bufferEnd-- > 0) && index < count; index++) {
|
|
5054
|
+
var _existingEl = findElementToReuse(index);
|
|
4973
5055
|
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
if (insertBefore && insertBefore === existingEl)
|
|
4977
|
-
insertBefore = insertBefore.nextSibling;
|
|
5056
|
+
if (before && before === _existingEl)
|
|
5057
|
+
before = before.nextSibling;
|
|
4978
5058
|
|
|
4979
5059
|
// Dequeue the element by reusing or creating a new one
|
|
4980
|
-
|
|
5060
|
+
this._dequeueElementForIndex(_existingEl, index, before, false);
|
|
4981
5061
|
|
|
4982
5062
|
// Increment pointers
|
|
4983
5063
|
renderPos = p.cachedItemPositions[index] + p.cachedItemHeights[index];
|
|
4984
|
-
index++;
|
|
4985
5064
|
}
|
|
5065
|
+
}
|
|
4986
5066
|
|
|
4987
|
-
|
|
4988
|
-
|
|
4989
|
-
|
|
5067
|
+
// Calculate up-to-date scroll height
|
|
5068
|
+
var scrollHeight = this.estimateFullHeight();
|
|
5069
|
+
p.virtualWrapper.style.height = scrollHeight + 'px';
|
|
4990
5070
|
|
|
4991
|
-
|
|
4992
|
-
|
|
5071
|
+
if (originalWidth !== list.clientWidth)
|
|
5072
|
+
this.render();
|
|
4993
5073
|
} else {// non-virtual
|
|
4994
5074
|
if (count !== existingEls.length) {
|
|
4995
|
-
for (var
|
|
4996
|
-
existingEls[
|
|
5075
|
+
for (var _i2 = 0; _i2 < existingCount; _i2++) {
|
|
5076
|
+
existingEls[_i2][ReuseElSymbol] = true;
|
|
4997
5077
|
}
|
|
4998
5078
|
|
|
4999
|
-
|
|
5000
|
-
var
|
|
5001
|
-
|
|
5079
|
+
// Find the element to insert before
|
|
5080
|
+
var _before = list.childNodes[0];
|
|
5081
|
+
|
|
5082
|
+
/** @type DocumentFragment|null */
|
|
5083
|
+
var _fragment = null;var _loop = function _loop(
|
|
5084
|
+
|
|
5085
|
+
_index2) {
|
|
5002
5086
|
// Find existing element to reuse
|
|
5003
|
-
var existingEl = existingEls.find(function (x) {return x[ItemIndexSymbol] ===
|
|
5087
|
+
var existingEl = existingEls.find(function (x) {return x[ItemIndexSymbol] === _index2 && x[ReuseElSymbol] === true;});
|
|
5004
5088
|
|
|
5005
5089
|
if (existingEl !== undefined) {
|
|
5006
5090
|
delete existingEl[ReuseElSymbol];
|
|
5007
5091
|
}
|
|
5008
5092
|
|
|
5009
|
-
|
|
5010
|
-
|
|
5011
|
-
if (insertBefore && insertBefore === existingEl)
|
|
5012
|
-
insertBefore = insertBefore.nextSibling;
|
|
5093
|
+
if (_before && _before === existingEl)
|
|
5094
|
+
_before = _before.nextSibling;
|
|
5013
5095
|
|
|
5014
5096
|
// Dequeue the element by reusing or creating a new one
|
|
5015
|
-
|
|
5097
|
+
var itemEl = _this._dequeueElementForIndex(existingEl, _index2, _before, true);
|
|
5098
|
+
|
|
5099
|
+
_fragment = insertBeforeWithFragment(itemEl, _fragment, _before, itemParent);};for (var _index2 = 0; _index2 < count; _index2++) {_loop(_index2);
|
|
5100
|
+
}
|
|
5101
|
+
|
|
5102
|
+
// Insert any remaining fragment
|
|
5103
|
+
if (_fragment && _fragment.childNodes.length > 0) {
|
|
5104
|
+
insertBefore(_fragment, _before, itemParent);
|
|
5016
5105
|
}
|
|
5017
5106
|
}
|
|
5018
5107
|
}
|
|
5019
5108
|
|
|
5020
5109
|
// Cleanup extra unused elements
|
|
5021
5110
|
existingCount = existingEls.length; // May have changed
|
|
5022
|
-
for (var
|
|
5023
|
-
var el = existingEls[
|
|
5111
|
+
for (var _i3 = 0; _i3 < existingCount; _i3++) {
|
|
5112
|
+
var el = existingEls[_i3];
|
|
5024
5113
|
if (el[ReuseElSymbol] !== true) continue;
|
|
5025
5114
|
|
|
5026
5115
|
var parent = el.parentNode;
|
|
@@ -5028,9 +5117,9 @@ var hasOwnProperty = Object.prototype.hasOwnProperty;var VirtualListHelper = /*#
|
|
|
5028
5117
|
parent.removeChild(el);
|
|
5029
5118
|
if (onItemUnrender && el[ItemIndexSymbol] !== undefined)
|
|
5030
5119
|
onItemUnrender(el);
|
|
5031
|
-
existingEls.splice(
|
|
5120
|
+
existingEls.splice(_i3, 1);
|
|
5032
5121
|
|
|
5033
|
-
|
|
5122
|
+
_i3--;
|
|
5034
5123
|
existingCount--;
|
|
5035
5124
|
}
|
|
5036
5125
|
}
|
|
@@ -5068,16 +5157,28 @@ var hasOwnProperty = Object.prototype.hasOwnProperty;var VirtualListHelper = /*#
|
|
|
5068
5157
|
if (existingRange.firstValidArrayIndex === -1)
|
|
5069
5158
|
return this;
|
|
5070
5159
|
|
|
5160
|
+
var itemParent = p.currentItemsParent;
|
|
5161
|
+
|
|
5071
5162
|
var startIndex = existingRange.firstValidArrayIndex + atIndex - existingRange.firstIndex;
|
|
5072
5163
|
|
|
5073
5164
|
this._pushItemIndexesAt(atIndex, count);
|
|
5074
5165
|
|
|
5075
5166
|
/** @type Node|undefined */
|
|
5076
|
-
var
|
|
5167
|
+
var before = existingEls[startIndex - 1] ?
|
|
5168
|
+
existingEls[startIndex - 1].nextSibling :
|
|
5169
|
+
existingEls[0];
|
|
5170
|
+
|
|
5171
|
+
/** @type DocumentFragment|null */
|
|
5172
|
+
var fragment = null;
|
|
5077
5173
|
|
|
5078
5174
|
for (var index = atIndex, end = atIndex + count; index < end; index++) {
|
|
5079
|
-
var
|
|
5080
|
-
|
|
5175
|
+
var itemEl = this._dequeueElementForIndex(undefined, index, before, true);
|
|
5176
|
+
fragment = insertBeforeWithFragment(itemEl, fragment, before, itemParent);
|
|
5177
|
+
}
|
|
5178
|
+
|
|
5179
|
+
// Insert any remaining fragment
|
|
5180
|
+
if (fragment && fragment.childNodes.length > 0) {
|
|
5181
|
+
insertBefore(fragment, before, itemParent);
|
|
5081
5182
|
}
|
|
5082
5183
|
}
|
|
5083
5184
|
|
|
@@ -5160,7 +5261,7 @@ var hasOwnProperty = Object.prototype.hasOwnProperty;var VirtualListHelper = /*#
|
|
|
5160
5261
|
if (index >= existingRange.firstIndex && index <= existingRange.lastIndex) {
|
|
5161
5262
|
var itemEl = existingEls[existingRange.firstValidArrayIndex + index - existingRange.firstIndex];
|
|
5162
5263
|
delete itemEl[ItemIndexSymbol];
|
|
5163
|
-
this._dequeueElementForIndex(itemEl, index, itemEl.nextSibling);
|
|
5264
|
+
this._dequeueElementForIndex(itemEl, index, itemEl.nextSibling, false);
|
|
5164
5265
|
}
|
|
5165
5266
|
}
|
|
5166
5267
|
|
|
@@ -5303,7 +5404,7 @@ var hasOwnProperty = Object.prototype.hasOwnProperty;var VirtualListHelper = /*#
|
|
|
5303
5404
|
function createGhostItemElement(ghostIndex, append, ghostTester) {
|
|
5304
5405
|
var p = this._p;
|
|
5305
5406
|
|
|
5306
|
-
var itemEl = this._dequeueElementForIndex(null, ghostIndex, false);
|
|
5407
|
+
var itemEl = this._dequeueElementForIndex(null, ghostIndex, false, true);
|
|
5307
5408
|
try {
|
|
5308
5409
|
if (append) {
|
|
5309
5410
|
p.currentItemsParent.appendChild(itemEl);
|
|
@@ -5554,10 +5655,11 @@ var hasOwnProperty = Object.prototype.hasOwnProperty;var VirtualListHelper = /*#
|
|
|
5554
5655
|
* @param {Element|undefined} itemEl
|
|
5555
5656
|
* @param {number} index
|
|
5556
5657
|
* @param {Node|boolean|undefined} insertBefore
|
|
5658
|
+
* @param {boolean|undefined} avoidDomReflow
|
|
5557
5659
|
* @returns {Element}
|
|
5558
5660
|
* @private
|
|
5559
5661
|
*/ }, { key: "_dequeueElementForIndex", value:
|
|
5560
|
-
function _dequeueElementForIndex(itemEl, index, insertBefore) {
|
|
5662
|
+
function _dequeueElementForIndex(itemEl, index, insertBefore, avoidDomReflow) {
|
|
5561
5663
|
var p = this._p;
|
|
5562
5664
|
var virtualWrapper = p.virtualWrapper;
|
|
5563
5665
|
var itemParent = p.currentItemsParent;
|
|
@@ -5595,12 +5697,6 @@ var hasOwnProperty = Object.prototype.hasOwnProperty;var VirtualListHelper = /*#
|
|
|
5595
5697
|
if (!(insertBefore instanceof Node))
|
|
5596
5698
|
insertBefore = null;
|
|
5597
5699
|
|
|
5598
|
-
// Insert into DOM
|
|
5599
|
-
if (itemEl.parentNode !== itemParent ||
|
|
5600
|
-
itemEl.nextSibling !== insertBefore) {
|
|
5601
|
-
itemParent.insertBefore(itemEl, insertBefore);
|
|
5602
|
-
}
|
|
5603
|
-
|
|
5604
5700
|
// Remove from existing list
|
|
5605
5701
|
if (!isNew) {
|
|
5606
5702
|
var i = existingEls.indexOf(itemEl);
|
|
@@ -5616,35 +5712,65 @@ var hasOwnProperty = Object.prototype.hasOwnProperty;var VirtualListHelper = /*#
|
|
|
5616
5712
|
existingEls.splice(beforeIndex, 0, itemEl);
|
|
5617
5713
|
}
|
|
5618
5714
|
|
|
5619
|
-
if (
|
|
5620
|
-
|
|
5621
|
-
|
|
5715
|
+
if (!avoidDomReflow) {
|
|
5716
|
+
this._insertItemAndFlow(itemEl, index, insertBefore);
|
|
5717
|
+
}
|
|
5718
|
+
}
|
|
5622
5719
|
|
|
5623
|
-
|
|
5624
|
-
|
|
5625
|
-
if (!(cachedItemHeight === itemHeight ||
|
|
5626
|
-
cachedItemHeight === undefined && p.cachedItemEstimatedHeights[index] === itemHeight)) {
|
|
5720
|
+
// Add index metadata to item
|
|
5721
|
+
itemEl[ItemIndexSymbol] = index;
|
|
5627
5722
|
|
|
5628
|
-
|
|
5629
|
-
|
|
5630
|
-
|
|
5723
|
+
return itemEl;
|
|
5724
|
+
}
|
|
5725
|
+
|
|
5726
|
+
/**
|
|
5727
|
+
* Insert item element into the DOM, set it's flow in the DOM, and update the item's position. <br />
|
|
5728
|
+
* @param {Element|undefined} itemEl
|
|
5729
|
+
* @param {number} index
|
|
5730
|
+
* @param {Node|boolean|undefined} before
|
|
5731
|
+
* @private
|
|
5732
|
+
*/ }, { key: "_insertItemAndFlow", value:
|
|
5733
|
+
function _insertItemAndFlow(itemEl, index, before) {
|
|
5734
|
+
var p = this._p;
|
|
5735
|
+
var virtualWrapper = p.virtualWrapper;
|
|
5736
|
+
var itemParent = p.currentItemsParent;
|
|
5631
5737
|
|
|
5632
|
-
|
|
5633
|
-
|
|
5634
|
-
|
|
5738
|
+
if (before !== false) {
|
|
5739
|
+
if (!(before instanceof Node))
|
|
5740
|
+
before = null;
|
|
5635
5741
|
|
|
5636
|
-
|
|
5637
|
-
|
|
5638
|
-
|
|
5639
|
-
|
|
5640
|
-
}
|
|
5742
|
+
// Insert into DOM
|
|
5743
|
+
if (itemEl.parentNode !== itemParent ||
|
|
5744
|
+
itemEl.nextSibling !== before) {
|
|
5745
|
+
insertBefore(itemEl, before, itemParent);
|
|
5641
5746
|
}
|
|
5642
5747
|
}
|
|
5643
5748
|
|
|
5644
|
-
|
|
5645
|
-
|
|
5749
|
+
if (virtualWrapper) {
|
|
5750
|
+
// Calculate height
|
|
5751
|
+
var itemHeight = itemEl.getBoundingClientRect().height;
|
|
5646
5752
|
|
|
5647
|
-
|
|
5753
|
+
// Put calculated height into cache, and invalidate positions if it's different
|
|
5754
|
+
var cachedItemHeight = p.cachedItemHeights[index];
|
|
5755
|
+
if (cachedItemHeight !== itemHeight) {
|
|
5756
|
+
p.cachedItemHeights[index] = itemHeight;
|
|
5757
|
+
}
|
|
5758
|
+
|
|
5759
|
+
if (cachedItemHeight !== undefined && itemHeight !== cachedItemHeight ||
|
|
5760
|
+
cachedItemHeight === undefined && itemHeight !== p.cachedItemEstimatedHeights[index]) {
|
|
5761
|
+
this._setItemPositionsNeedsUpdate(index + 1);
|
|
5762
|
+
}
|
|
5763
|
+
|
|
5764
|
+
// Set item top position
|
|
5765
|
+
var pos = this._calculateItemPosition(index);
|
|
5766
|
+
var supportedTransform = getSupportedTransform();
|
|
5767
|
+
|
|
5768
|
+
if (supportedTransform === false) {
|
|
5769
|
+
/**@type ElementCSSInlineStyle*/itemEl.style.top = "".concat(pos, "px");
|
|
5770
|
+
} else {
|
|
5771
|
+
/**@type ElementCSSInlineStyle*/itemEl.style[supportedTransform] = "translateY(".concat(pos, "px)");
|
|
5772
|
+
}
|
|
5773
|
+
}
|
|
5648
5774
|
}
|
|
5649
5775
|
|
|
5650
5776
|
/**
|
|
@@ -5664,10 +5790,10 @@ var hasOwnProperty = Object.prototype.hasOwnProperty;var VirtualListHelper = /*#
|
|
|
5664
5790
|
break;
|
|
5665
5791
|
}
|
|
5666
5792
|
|
|
5667
|
-
for (var
|
|
5668
|
-
if (false === hasOwnProperty.call(existingEls[
|
|
5793
|
+
for (var _i4 = existingEls.length - 1; _i4 >= 0; _i4--) {
|
|
5794
|
+
if (false === hasOwnProperty.call(existingEls[_i4], ItemIndexSymbol))
|
|
5669
5795
|
continue;
|
|
5670
|
-
lastValidArrayIndex =
|
|
5796
|
+
lastValidArrayIndex = _i4;
|
|
5671
5797
|
break;
|
|
5672
5798
|
}
|
|
5673
5799
|
|
|
@@ -5788,7 +5914,7 @@ var getSupportedTransform = function getSupportedTransform() {
|
|
|
5788
5914
|
var prefixes = ['transform', 'WebkitTransform', 'MozTransform', 'OTransform', 'msTransform'];
|
|
5789
5915
|
var div = document.createElement('div');
|
|
5790
5916
|
_isTransformSupported = false;
|
|
5791
|
-
for (var
|
|
5917
|
+
for (var _i5 = 0, _prefixes = prefixes; _i5 < _prefixes.length; _i5++) {var item = _prefixes[_i5];
|
|
5792
5918
|
if (div && div.style[item] !== undefined) {
|
|
5793
5919
|
_isTransformSupported = item;
|
|
5794
5920
|
break;
|