hy-virtual-tree 1.1.24 → 1.1.25
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/CHANGELOG.md +7 -0
- package/dist/index.js +22 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -11,6 +11,7 @@ class VirtualScroll {
|
|
|
11
11
|
* @param {number} [options.maxHeight=26840000] Maximum height in pixels for the content wrapper
|
|
12
12
|
* @param {Function} [options.onRender] 节点刷新回调
|
|
13
13
|
*/
|
|
14
|
+
cacheNodeMap = new Map();
|
|
14
15
|
constructor(options) {
|
|
15
16
|
this.container = options.container;
|
|
16
17
|
this.items = options.items || [];
|
|
@@ -115,10 +116,13 @@ class VirtualScroll {
|
|
|
115
116
|
renderVisibleItems(startIndex, endIndex) {
|
|
116
117
|
this._onRender && this._onRender();
|
|
117
118
|
// Clear content container
|
|
118
|
-
this.contentContainer.innerHTML = ''
|
|
119
|
+
// this.contentContainer.innerHTML = ''
|
|
119
120
|
// Set position considering scaling factor
|
|
121
|
+
// const fragment = document.createDocumentFragment()
|
|
122
|
+
// const fragment = []
|
|
120
123
|
this.contentContainer.style.transform = `translateY(${startIndex * this.itemHeight * this.heightScale}px)`;
|
|
121
124
|
// Render visible items
|
|
125
|
+
const nodeMap = new Map();
|
|
122
126
|
for (let i = startIndex; i < endIndex; i++) {
|
|
123
127
|
const item = this.items[i];
|
|
124
128
|
if (this.customRenderItem) {
|
|
@@ -129,7 +133,17 @@ class VirtualScroll {
|
|
|
129
133
|
itemElement.style.height = `${this.itemHeight * this.heightScale}px`;
|
|
130
134
|
itemElement.style.boxSizing = 'border-box';
|
|
131
135
|
itemElement.style.width = '100%';
|
|
132
|
-
|
|
136
|
+
const innerHTML = itemElement.innerHTML;
|
|
137
|
+
if (this.cacheNodeMap.has(innerHTML)) {
|
|
138
|
+
const target = this.cacheNodeMap.get(innerHTML);
|
|
139
|
+
this.contentContainer.appendChild(target);
|
|
140
|
+
nodeMap.set(innerHTML, target);
|
|
141
|
+
this.cacheNodeMap.delete(innerHTML);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
this.contentContainer.appendChild(itemElement);
|
|
145
|
+
nodeMap.set(innerHTML, itemElement);
|
|
146
|
+
}
|
|
133
147
|
}
|
|
134
148
|
}
|
|
135
149
|
else {
|
|
@@ -146,6 +160,11 @@ class VirtualScroll {
|
|
|
146
160
|
this.contentContainer.appendChild(row);
|
|
147
161
|
}
|
|
148
162
|
}
|
|
163
|
+
for (const [key, value] of this.cacheNodeMap) {
|
|
164
|
+
this.contentContainer.removeChild(value);
|
|
165
|
+
}
|
|
166
|
+
this.cacheNodeMap.clear();
|
|
167
|
+
this.cacheNodeMap = nodeMap;
|
|
149
168
|
}
|
|
150
169
|
/**
|
|
151
170
|
* Update data items and re-render
|
|
@@ -480,7 +499,7 @@ const useConfig = (config) => {
|
|
|
480
499
|
config = {
|
|
481
500
|
itemHeight: 30,
|
|
482
501
|
itemGap: 10,
|
|
483
|
-
bufferSize:
|
|
502
|
+
bufferSize: 30,
|
|
484
503
|
color: '#fff',
|
|
485
504
|
placeholderColor: '#909399',
|
|
486
505
|
fontSize: 14,
|