@v-c/virtual-list 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/List.js +3 -3
- package/dist/hooks/useGetSize.d.ts +3 -6
- package/dist/hooks/useGetSize.js +31 -23
- package/dist/utils/CacheMap.d.ts +1 -1
- package/dist/utils/CacheMap.js +3 -2
- package/package.json +4 -4
- package/dist/Filler.cjs +0 -54
- package/dist/Item.cjs +0 -29
- package/dist/List.cjs +0 -445
- package/dist/ScrollBar.cjs +0 -262
- package/dist/_virtual/rolldown_runtime.cjs +0 -21
- package/dist/hooks/useChildren.cjs +0 -26
- package/dist/hooks/useDiffItem.cjs +0 -21
- package/dist/hooks/useFrameWheel.cjs +0 -66
- package/dist/hooks/useGetSize.cjs +0 -30
- package/dist/hooks/useHeights.cjs +0 -87
- package/dist/hooks/useMobileTouchMove.cjs +0 -85
- package/dist/hooks/useOriginScroll.cjs +0 -26
- package/dist/hooks/useScrollDrag.cjs +0 -86
- package/dist/hooks/useScrollTo.cjs +0 -106
- package/dist/index.cjs +0 -7
- package/dist/interface.cjs +0 -1
- package/dist/utils/CacheMap.cjs +0 -28
- package/dist/utils/algorithmUtil.cjs +0 -47
- package/dist/utils/isFirefox.cjs +0 -7
- package/dist/utils/scrollbarUtil.cjs +0 -9
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
Object.defineProperties(exports, {
|
|
2
|
-
__esModule: { value: true },
|
|
3
|
-
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
-
});
|
|
5
|
-
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
6
|
-
let vue = require("vue");
|
|
7
|
-
function smoothScrollOffset(offset) {
|
|
8
|
-
return Math.floor(offset ** .5);
|
|
9
|
-
}
|
|
10
|
-
function getPageXY(e, horizontal) {
|
|
11
|
-
return ("touches" in e ? e.touches[0] : e)[horizontal ? "pageX" : "pageY"] - window[horizontal ? "scrollX" : "scrollY"];
|
|
12
|
-
}
|
|
13
|
-
function useScrollDrag(inVirtual, componentRef, onScrollOffset) {
|
|
14
|
-
let cachedElement = null;
|
|
15
|
-
let cachedDocument = null;
|
|
16
|
-
let mouseDownLock = false;
|
|
17
|
-
let rafId = null;
|
|
18
|
-
let offset = 0;
|
|
19
|
-
const stopScroll = () => {
|
|
20
|
-
if (rafId !== null) {
|
|
21
|
-
cancelAnimationFrame(rafId);
|
|
22
|
-
rafId = null;
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
const continueScroll = () => {
|
|
26
|
-
stopScroll();
|
|
27
|
-
rafId = requestAnimationFrame(() => {
|
|
28
|
-
onScrollOffset(offset);
|
|
29
|
-
continueScroll();
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
const clearDragState = () => {
|
|
33
|
-
mouseDownLock = false;
|
|
34
|
-
stopScroll();
|
|
35
|
-
};
|
|
36
|
-
const onMouseDown = (e) => {
|
|
37
|
-
if (e.target.draggable || e.button !== 0) return;
|
|
38
|
-
const event = e;
|
|
39
|
-
if (!event._virtualHandled) {
|
|
40
|
-
event._virtualHandled = true;
|
|
41
|
-
mouseDownLock = true;
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
const onMouseMove = (e) => {
|
|
45
|
-
if (mouseDownLock && cachedElement) {
|
|
46
|
-
const mouseY = getPageXY(e, false);
|
|
47
|
-
const { top, bottom } = cachedElement.getBoundingClientRect();
|
|
48
|
-
if (mouseY <= top) {
|
|
49
|
-
offset = -smoothScrollOffset(top - mouseY);
|
|
50
|
-
continueScroll();
|
|
51
|
-
} else if (mouseY >= bottom) {
|
|
52
|
-
offset = smoothScrollOffset(mouseY - bottom);
|
|
53
|
-
continueScroll();
|
|
54
|
-
} else stopScroll();
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
const teardown = () => {
|
|
58
|
-
if (cachedElement) {
|
|
59
|
-
cachedElement.removeEventListener("mousedown", onMouseDown);
|
|
60
|
-
cachedElement = null;
|
|
61
|
-
}
|
|
62
|
-
if (cachedDocument) {
|
|
63
|
-
cachedDocument.removeEventListener("mouseup", clearDragState);
|
|
64
|
-
cachedDocument.removeEventListener("mousemove", onMouseMove);
|
|
65
|
-
cachedDocument.removeEventListener("dragend", clearDragState);
|
|
66
|
-
cachedDocument = null;
|
|
67
|
-
}
|
|
68
|
-
clearDragState();
|
|
69
|
-
};
|
|
70
|
-
(0, vue.onUnmounted)(teardown);
|
|
71
|
-
(0, vue.watch)([inVirtual, componentRef], ([enabled, ele], _prev, onCleanup) => {
|
|
72
|
-
if (enabled && ele) {
|
|
73
|
-
cachedElement = ele;
|
|
74
|
-
cachedDocument = ele.ownerDocument;
|
|
75
|
-
cachedElement.addEventListener("mousedown", onMouseDown);
|
|
76
|
-
cachedDocument.addEventListener("mouseup", clearDragState);
|
|
77
|
-
cachedDocument.addEventListener("mousemove", onMouseMove);
|
|
78
|
-
cachedDocument.addEventListener("dragend", clearDragState);
|
|
79
|
-
onCleanup(() => {
|
|
80
|
-
teardown();
|
|
81
|
-
});
|
|
82
|
-
} else teardown();
|
|
83
|
-
}, { immediate: true });
|
|
84
|
-
}
|
|
85
|
-
exports.default = useScrollDrag;
|
|
86
|
-
exports.getPageXY = getPageXY;
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
Object.defineProperties(exports, {
|
|
2
|
-
__esModule: { value: true },
|
|
3
|
-
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
-
});
|
|
5
|
-
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
6
|
-
let vue = require("vue");
|
|
7
|
-
let _v_c_util = require("@v-c/util");
|
|
8
|
-
var MAX_TIMES = 10;
|
|
9
|
-
function useScrollTo(containerRef, data, heights, itemHeight, getKey, collectHeight, syncScrollTop, triggerFlash) {
|
|
10
|
-
const syncState = (0, vue.shallowRef)(null);
|
|
11
|
-
const getTotalHeight = () => {
|
|
12
|
-
let totalHeight = 0;
|
|
13
|
-
for (let i = 0; i < data.value.length; i += 1) {
|
|
14
|
-
const key = getKey(data.value[i]);
|
|
15
|
-
const cacheHeight = heights.get(key);
|
|
16
|
-
totalHeight += cacheHeight === void 0 ? itemHeight.value : cacheHeight;
|
|
17
|
-
}
|
|
18
|
-
return totalHeight;
|
|
19
|
-
};
|
|
20
|
-
(0, vue.watch)(syncState, () => {
|
|
21
|
-
if (syncState.value && syncState.value.times < MAX_TIMES) {
|
|
22
|
-
if (!containerRef.value) {
|
|
23
|
-
syncState.value = { ...syncState.value };
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
collectHeight();
|
|
27
|
-
const { targetAlign, originAlign, index, offset } = syncState.value;
|
|
28
|
-
const height = containerRef.value.clientHeight;
|
|
29
|
-
let needCollectHeight = false;
|
|
30
|
-
let newTargetAlign = targetAlign ?? null;
|
|
31
|
-
let targetTop = null;
|
|
32
|
-
if (height) {
|
|
33
|
-
const mergedAlign = targetAlign || originAlign;
|
|
34
|
-
let stackTop = 0;
|
|
35
|
-
let itemTop = 0;
|
|
36
|
-
let itemBottom = 0;
|
|
37
|
-
const maxLen = Math.min(data.value.length - 1, index);
|
|
38
|
-
for (let i = 0; i <= maxLen; i += 1) {
|
|
39
|
-
const key = getKey(data.value[i]);
|
|
40
|
-
itemTop = stackTop;
|
|
41
|
-
const cacheHeight = heights.get(key);
|
|
42
|
-
itemBottom = itemTop + (cacheHeight === void 0 ? itemHeight.value : cacheHeight);
|
|
43
|
-
stackTop = itemBottom;
|
|
44
|
-
}
|
|
45
|
-
let leftHeight = mergedAlign === "top" ? offset : height - offset;
|
|
46
|
-
for (let i = maxLen; i >= 0; i -= 1) {
|
|
47
|
-
const key = getKey(data.value[i]);
|
|
48
|
-
const cacheHeight = heights.get(key);
|
|
49
|
-
if (cacheHeight === void 0) {
|
|
50
|
-
needCollectHeight = true;
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
leftHeight -= cacheHeight;
|
|
54
|
-
if (leftHeight <= 0) break;
|
|
55
|
-
}
|
|
56
|
-
switch (mergedAlign) {
|
|
57
|
-
case "top":
|
|
58
|
-
targetTop = itemTop - offset;
|
|
59
|
-
break;
|
|
60
|
-
case "bottom":
|
|
61
|
-
targetTop = itemBottom - height + offset;
|
|
62
|
-
break;
|
|
63
|
-
default: {
|
|
64
|
-
const { scrollTop } = containerRef.value;
|
|
65
|
-
const scrollBottom = scrollTop + height;
|
|
66
|
-
if (itemTop < scrollTop) newTargetAlign = "top";
|
|
67
|
-
else if (itemBottom > scrollBottom) newTargetAlign = "bottom";
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
if (targetTop !== null) syncScrollTop(targetTop);
|
|
71
|
-
if (targetTop !== syncState.value.lastTop) needCollectHeight = true;
|
|
72
|
-
}
|
|
73
|
-
if (needCollectHeight) syncState.value = {
|
|
74
|
-
...syncState.value,
|
|
75
|
-
times: syncState.value.times + 1,
|
|
76
|
-
targetAlign: newTargetAlign,
|
|
77
|
-
lastTop: targetTop
|
|
78
|
-
};
|
|
79
|
-
} else if (process.env.NODE_ENV !== "production" && syncState.value?.times === MAX_TIMES) (0, _v_c_util.warning)(false, "Seems `scrollTo` with `rc-virtual-list` reach the max limitation. Please fire issue for us. Thanks.");
|
|
80
|
-
}, {
|
|
81
|
-
immediate: true,
|
|
82
|
-
flush: "post"
|
|
83
|
-
});
|
|
84
|
-
const scrollTo = (arg) => {
|
|
85
|
-
if (arg === null || arg === void 0) {
|
|
86
|
-
triggerFlash();
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
if (typeof arg === "number") syncScrollTop(arg);
|
|
90
|
-
else if (arg && typeof arg === "object") {
|
|
91
|
-
let index;
|
|
92
|
-
const { align } = arg;
|
|
93
|
-
if ("index" in arg) ({index} = arg);
|
|
94
|
-
else index = data.value.findIndex((item) => getKey(item) === arg.key);
|
|
95
|
-
const { offset = 0 } = arg;
|
|
96
|
-
syncState.value = {
|
|
97
|
-
times: 0,
|
|
98
|
-
index,
|
|
99
|
-
offset,
|
|
100
|
-
originAlign: align
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
return [scrollTo, getTotalHeight];
|
|
105
|
-
}
|
|
106
|
-
exports.default = useScrollTo;
|
package/dist/index.cjs
DELETED
package/dist/interface.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
package/dist/utils/CacheMap.cjs
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
Object.defineProperties(exports, {
|
|
2
|
-
__esModule: { value: true },
|
|
3
|
-
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
-
});
|
|
5
|
-
var CacheMap = class {
|
|
6
|
-
maps;
|
|
7
|
-
id = 0;
|
|
8
|
-
diffRecords = /* @__PURE__ */ new Map();
|
|
9
|
-
constructor() {
|
|
10
|
-
this.maps = Object.create(null);
|
|
11
|
-
}
|
|
12
|
-
set(key, value) {
|
|
13
|
-
this.diffRecords.set(key, this.maps[key]);
|
|
14
|
-
this.maps[key] = value;
|
|
15
|
-
this.id += 1;
|
|
16
|
-
}
|
|
17
|
-
get(key) {
|
|
18
|
-
return this.maps[key];
|
|
19
|
-
}
|
|
20
|
-
resetRecord() {
|
|
21
|
-
this.diffRecords.clear();
|
|
22
|
-
}
|
|
23
|
-
getRecord() {
|
|
24
|
-
return this.diffRecords;
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
var CacheMap_default = CacheMap;
|
|
28
|
-
exports.default = CacheMap_default;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
function getIndexByStartLoc(min, max, start, index) {
|
|
3
|
-
const beforeCount = start - min;
|
|
4
|
-
const afterCount = max - start;
|
|
5
|
-
if (index <= Math.min(beforeCount, afterCount) * 2) {
|
|
6
|
-
const stepIndex = Math.floor(index / 2);
|
|
7
|
-
if (index % 2) return start + stepIndex + 1;
|
|
8
|
-
return start - stepIndex;
|
|
9
|
-
}
|
|
10
|
-
if (beforeCount > afterCount) return start - (index - afterCount);
|
|
11
|
-
return start + (index - beforeCount);
|
|
12
|
-
}
|
|
13
|
-
function findListDiffIndex(originList, targetList, getKey) {
|
|
14
|
-
const originLen = originList.length;
|
|
15
|
-
const targetLen = targetList.length;
|
|
16
|
-
let shortList;
|
|
17
|
-
let longList;
|
|
18
|
-
if (originLen === 0 && targetLen === 0) return null;
|
|
19
|
-
if (originLen < targetLen) {
|
|
20
|
-
shortList = originList;
|
|
21
|
-
longList = targetList;
|
|
22
|
-
} else {
|
|
23
|
-
shortList = targetList;
|
|
24
|
-
longList = originList;
|
|
25
|
-
}
|
|
26
|
-
const notExistKey = { __EMPTY_ITEM__: true };
|
|
27
|
-
function getItemKey(item) {
|
|
28
|
-
if (item !== void 0) return getKey(item);
|
|
29
|
-
return notExistKey;
|
|
30
|
-
}
|
|
31
|
-
let diffIndex = null;
|
|
32
|
-
let multiple = Math.abs(originLen - targetLen) !== 1;
|
|
33
|
-
for (let i = 0; i < longList.length; i += 1) {
|
|
34
|
-
const shortKey = getItemKey(shortList[i]);
|
|
35
|
-
if (shortKey !== getItemKey(longList[i])) {
|
|
36
|
-
diffIndex = i;
|
|
37
|
-
multiple = multiple || shortKey !== getItemKey(longList[i + 1]);
|
|
38
|
-
break;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return diffIndex === null ? null : {
|
|
42
|
-
index: diffIndex,
|
|
43
|
-
multiple
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
exports.findListDiffIndex = findListDiffIndex;
|
|
47
|
-
exports.getIndexByStartLoc = getIndexByStartLoc;
|
package/dist/utils/isFirefox.cjs
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
Object.defineProperties(exports, {
|
|
2
|
-
__esModule: { value: true },
|
|
3
|
-
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
-
});
|
|
5
|
-
var isFF = typeof navigator === "object" && /Firefox/i.test(navigator.userAgent);
|
|
6
|
-
var isFirefox_default = isFF;
|
|
7
|
-
exports.default = isFirefox_default;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
var MIN_SIZE = 20;
|
|
3
|
-
function getSpinSize(containerSize = 0, scrollRange = 0) {
|
|
4
|
-
let baseSize = containerSize / scrollRange * containerSize;
|
|
5
|
-
if (isNaN(baseSize)) baseSize = 0;
|
|
6
|
-
baseSize = Math.max(baseSize, MIN_SIZE);
|
|
7
|
-
return Math.floor(baseSize);
|
|
8
|
-
}
|
|
9
|
-
exports.getSpinSize = getSpinSize;
|