@v-c/virtual-list 1.0.4 → 1.0.5
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/List.cjs +2 -2
- package/dist/List.js +2 -2
- package/dist/hooks/useGetSize.cjs +30 -22
- package/dist/hooks/useGetSize.d.ts +3 -6
- package/dist/hooks/useGetSize.js +31 -23
- package/dist/utils/CacheMap.cjs +4 -2
- package/dist/utils/CacheMap.d.ts +1 -1
- package/dist/utils/CacheMap.js +3 -2
- package/package.json +2 -2
package/dist/List.cjs
CHANGED
|
@@ -143,7 +143,7 @@ var List_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
143
143
|
fillerOffset.value = 0;
|
|
144
144
|
return;
|
|
145
145
|
}
|
|
146
|
-
if (heights.id === 0) {
|
|
146
|
+
if (heights.id.value === 0) {
|
|
147
147
|
const safeItemHeight = itemHeight$1;
|
|
148
148
|
const safeListHeight = height;
|
|
149
149
|
const startIndex$1 = Math.max(0, Math.floor(offsetTop.value / safeItemHeight));
|
|
@@ -373,7 +373,7 @@ var List_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
373
373
|
offsetX: offsetLeft.value,
|
|
374
374
|
offsetY: fillerOffset.value || 0,
|
|
375
375
|
rtl: isRTL.value,
|
|
376
|
-
getSize
|
|
376
|
+
getSize
|
|
377
377
|
});
|
|
378
378
|
const Component = props.component;
|
|
379
379
|
return (0, vue.createVNode)("div", (0, vue.mergeProps)({ "ref": containerRef }, (0, _v_c_util_dist_props_util.pureAttrs)(attrs), {
|
package/dist/List.js
CHANGED
|
@@ -137,7 +137,7 @@ var List_default = /* @__PURE__ */ defineComponent({
|
|
|
137
137
|
fillerOffset.value = 0;
|
|
138
138
|
return;
|
|
139
139
|
}
|
|
140
|
-
if (heights.id === 0) {
|
|
140
|
+
if (heights.id.value === 0) {
|
|
141
141
|
const safeItemHeight = itemHeight$1;
|
|
142
142
|
const safeListHeight = height;
|
|
143
143
|
const startIndex$1 = Math.max(0, Math.floor(offsetTop.value / safeItemHeight));
|
|
@@ -367,7 +367,7 @@ var List_default = /* @__PURE__ */ defineComponent({
|
|
|
367
367
|
offsetX: offsetLeft.value,
|
|
368
368
|
offsetY: fillerOffset.value || 0,
|
|
369
369
|
rtl: isRTL.value,
|
|
370
|
-
getSize
|
|
370
|
+
getSize
|
|
371
371
|
});
|
|
372
372
|
const Component = props.component;
|
|
373
373
|
return createVNode("div", mergeProps({ "ref": containerRef }, pureAttrs(attrs), {
|
|
@@ -2,29 +2,37 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
3
3
|
let vue = require("vue");
|
|
4
4
|
function useGetSize(mergedData, getKey, heights, itemHeight) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
5
|
+
let key2Index = /* @__PURE__ */ new Map();
|
|
6
|
+
let bottomList = [];
|
|
7
|
+
(0, vue.watch)([
|
|
8
|
+
mergedData,
|
|
9
|
+
() => heights.id.value,
|
|
10
|
+
itemHeight
|
|
11
|
+
], () => {
|
|
12
|
+
key2Index = /* @__PURE__ */ new Map();
|
|
13
|
+
bottomList = [];
|
|
14
|
+
});
|
|
15
|
+
const getSize = (startKey, endKey = startKey) => {
|
|
16
|
+
let startIndex = key2Index.get(startKey);
|
|
17
|
+
let endIndex = key2Index.get(endKey);
|
|
18
|
+
if (startIndex === void 0 || endIndex === void 0) {
|
|
19
|
+
const dataLen = mergedData.value.length;
|
|
20
|
+
for (let i = bottomList.length; i < dataLen; i += 1) {
|
|
21
|
+
const item = mergedData.value[i];
|
|
22
|
+
const key = getKey(item);
|
|
23
|
+
key2Index.set(key, i);
|
|
24
|
+
const cacheHeight = heights.get(key) ?? itemHeight.value;
|
|
25
|
+
bottomList[i] = (bottomList[i - 1] || 0) + cacheHeight;
|
|
26
|
+
if (key === startKey) startIndex = i;
|
|
27
|
+
if (key === endKey) endIndex = i;
|
|
28
|
+
if (startIndex !== void 0 && endIndex !== void 0) break;
|
|
22
29
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
top: bottomList[startIndex - 1] || 0,
|
|
33
|
+
bottom: bottomList[endIndex]
|
|
27
34
|
};
|
|
28
|
-
}
|
|
35
|
+
};
|
|
36
|
+
return getSize;
|
|
29
37
|
}
|
|
30
38
|
exports.useGetSize = useGetSize;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { GetKey } from '../interface';
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
import { GetKey, GetSize } from '../interface';
|
|
3
3
|
import { default as CacheMap } from '../utils/CacheMap';
|
|
4
|
-
export declare function useGetSize<T>(mergedData: Ref<T[]>, getKey: GetKey<T>, heights: CacheMap, itemHeight: Ref<number>):
|
|
5
|
-
top: number;
|
|
6
|
-
bottom: number;
|
|
7
|
-
}>;
|
|
4
|
+
export declare function useGetSize<T>(mergedData: Ref<T[]>, getKey: GetKey<T>, heights: CacheMap, itemHeight: Ref<number>): GetSize;
|
package/dist/hooks/useGetSize.js
CHANGED
|
@@ -1,28 +1,36 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { watch } from "vue";
|
|
2
2
|
function useGetSize(mergedData, getKey, heights, itemHeight) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
3
|
+
let key2Index = /* @__PURE__ */ new Map();
|
|
4
|
+
let bottomList = [];
|
|
5
|
+
watch([
|
|
6
|
+
mergedData,
|
|
7
|
+
() => heights.id.value,
|
|
8
|
+
itemHeight
|
|
9
|
+
], () => {
|
|
10
|
+
key2Index = /* @__PURE__ */ new Map();
|
|
11
|
+
bottomList = [];
|
|
12
|
+
});
|
|
13
|
+
const getSize = (startKey, endKey = startKey) => {
|
|
14
|
+
let startIndex = key2Index.get(startKey);
|
|
15
|
+
let endIndex = key2Index.get(endKey);
|
|
16
|
+
if (startIndex === void 0 || endIndex === void 0) {
|
|
17
|
+
const dataLen = mergedData.value.length;
|
|
18
|
+
for (let i = bottomList.length; i < dataLen; i += 1) {
|
|
19
|
+
const item = mergedData.value[i];
|
|
20
|
+
const key = getKey(item);
|
|
21
|
+
key2Index.set(key, i);
|
|
22
|
+
const cacheHeight = heights.get(key) ?? itemHeight.value;
|
|
23
|
+
bottomList[i] = (bottomList[i - 1] || 0) + cacheHeight;
|
|
24
|
+
if (key === startKey) startIndex = i;
|
|
25
|
+
if (key === endKey) endIndex = i;
|
|
26
|
+
if (startIndex !== void 0 && endIndex !== void 0) break;
|
|
20
27
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
top: bottomList[startIndex - 1] || 0,
|
|
31
|
+
bottom: bottomList[endIndex]
|
|
25
32
|
};
|
|
26
|
-
}
|
|
33
|
+
};
|
|
34
|
+
return getSize;
|
|
27
35
|
}
|
|
28
36
|
export { useGetSize };
|
package/dist/utils/CacheMap.cjs
CHANGED
|
@@ -2,9 +2,11 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
+
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
6
|
+
let vue = require("vue");
|
|
5
7
|
var CacheMap = class {
|
|
6
8
|
maps;
|
|
7
|
-
id = 0;
|
|
9
|
+
id = (0, vue.shallowRef)(0);
|
|
8
10
|
diffRecords = /* @__PURE__ */ new Map();
|
|
9
11
|
constructor() {
|
|
10
12
|
this.maps = Object.create(null);
|
|
@@ -12,7 +14,7 @@ var CacheMap = class {
|
|
|
12
14
|
set(key, value) {
|
|
13
15
|
this.diffRecords.set(key, this.maps[key]);
|
|
14
16
|
this.maps[key] = value;
|
|
15
|
-
this.id += 1;
|
|
17
|
+
this.id.value += 1;
|
|
16
18
|
}
|
|
17
19
|
get(key) {
|
|
18
20
|
return this.maps[key];
|
package/dist/utils/CacheMap.d.ts
CHANGED
package/dist/utils/CacheMap.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { shallowRef } from "vue";
|
|
1
2
|
var CacheMap = class {
|
|
2
3
|
maps;
|
|
3
|
-
id = 0;
|
|
4
|
+
id = shallowRef(0);
|
|
4
5
|
diffRecords = /* @__PURE__ */ new Map();
|
|
5
6
|
constructor() {
|
|
6
7
|
this.maps = Object.create(null);
|
|
@@ -8,7 +9,7 @@ var CacheMap = class {
|
|
|
8
9
|
set(key, value) {
|
|
9
10
|
this.diffRecords.set(key, this.maps[key]);
|
|
10
11
|
this.maps[key] = value;
|
|
11
|
-
this.id += 1;
|
|
12
|
+
this.id.value += 1;
|
|
12
13
|
}
|
|
13
14
|
get(key) {
|
|
14
15
|
return this.maps[key];
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@v-c/virtual-list",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.5",
|
|
5
5
|
"description": "Vue Virtual List Component",
|
|
6
6
|
"author": "",
|
|
7
7
|
"license": "MIT",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@v-c/resize-observer": "^1.0.3",
|
|
35
|
-
"@v-c/util": "^1.0.
|
|
35
|
+
"@v-c/util": "^1.0.5"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"build": "vite build",
|