@v-c/virtual-list 0.0.1 → 1.0.0
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/bump.config.ts +6 -0
- package/dist/Filler.cjs +51 -1
- package/dist/Filler.js +47 -56
- package/dist/Item.cjs +26 -1
- package/dist/Item.js +23 -26
- package/dist/List.cjs +408 -1
- package/dist/List.d.ts +45 -9
- package/dist/List.js +403 -274
- package/dist/ScrollBar.cjs +259 -1
- package/dist/ScrollBar.d.ts +3 -97
- package/dist/ScrollBar.js +254 -191
- package/dist/_virtual/rolldown_runtime.cjs +21 -0
- package/dist/hooks/useDiffItem.cjs +19 -1
- package/dist/hooks/useDiffItem.js +16 -20
- package/dist/hooks/useFrameWheel.cjs +63 -1
- package/dist/hooks/useFrameWheel.js +60 -51
- package/dist/hooks/useGetSize.cjs +29 -1
- package/dist/hooks/useGetSize.d.ts +2 -2
- package/dist/hooks/useGetSize.js +27 -23
- package/dist/hooks/useHeights.cjs +66 -1
- package/dist/hooks/useHeights.d.ts +1 -1
- package/dist/hooks/useHeights.js +62 -41
- package/dist/hooks/useMobileTouchMove.cjs +82 -1
- package/dist/hooks/useMobileTouchMove.js +79 -43
- package/dist/hooks/useOriginScroll.cjs +23 -1
- package/dist/hooks/useOriginScroll.js +20 -16
- package/dist/hooks/useScrollDrag.cjs +83 -1
- package/dist/hooks/useScrollDrag.js +77 -48
- package/dist/hooks/useScrollTo.cjs +97 -0
- package/dist/hooks/useScrollTo.d.ts +19 -0
- package/dist/hooks/useScrollTo.js +94 -0
- package/dist/index.cjs +4 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -4
- package/dist/interface.cjs +0 -1
- package/dist/interface.d.ts +1 -1
- package/dist/interface.js +0 -1
- package/dist/utils/CacheMap.cjs +25 -1
- package/dist/utils/CacheMap.d.ts +1 -1
- package/dist/utils/CacheMap.js +23 -28
- package/dist/utils/isFirefox.cjs +4 -1
- package/dist/utils/isFirefox.js +2 -4
- package/dist/utils/scrollbarUtil.cjs +8 -1
- package/dist/utils/scrollbarUtil.js +7 -6
- package/docs/animate.less +31 -0
- package/docs/animate.vue +159 -0
- package/docs/basic.vue +2 -1
- package/docs/nest.vue +1 -1
- package/docs/switch.vue +2 -1
- package/docs/virtual-list.stories.vue +4 -0
- package/package.json +16 -14
- package/src/Filler.tsx +2 -1
- package/src/Item.tsx +2 -1
- package/src/List.tsx +189 -124
- package/src/ScrollBar.tsx +33 -44
- package/src/hooks/useDiffItem.ts +3 -2
- package/src/hooks/useFrameWheel.ts +2 -1
- package/src/hooks/useGetSize.ts +5 -4
- package/src/hooks/useHeights.ts +7 -6
- package/src/hooks/useMobileTouchMove.ts +2 -1
- package/src/hooks/useOriginScroll.ts +2 -1
- package/src/hooks/useScrollDrag.ts +2 -1
- package/src/hooks/useScrollTo.tsx +184 -0
- package/src/index.ts +1 -1
- package/tsconfig.json +7 -0
- package/vitest.config.ts +1 -1
package/bump.config.ts
ADDED
package/dist/Filler.cjs
CHANGED
|
@@ -1 +1,51 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
const require_rolldown_runtime = require("./_virtual/rolldown_runtime.cjs");
|
|
3
|
+
let vue = require("vue");
|
|
4
|
+
let __v_c_resize_observer = require("@v-c/resize-observer");
|
|
5
|
+
__v_c_resize_observer = require_rolldown_runtime.__toESM(__v_c_resize_observer);
|
|
6
|
+
var Filler_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
7
|
+
name: "Filler",
|
|
8
|
+
props: {
|
|
9
|
+
prefixCls: String,
|
|
10
|
+
height: Number,
|
|
11
|
+
offsetY: Number,
|
|
12
|
+
offsetX: Number,
|
|
13
|
+
scrollWidth: Number,
|
|
14
|
+
onInnerResize: Function,
|
|
15
|
+
innerProps: Object,
|
|
16
|
+
rtl: Boolean,
|
|
17
|
+
extra: Object
|
|
18
|
+
},
|
|
19
|
+
setup(props, { slots }) {
|
|
20
|
+
return () => {
|
|
21
|
+
let outerStyle = {};
|
|
22
|
+
let innerStyle = {
|
|
23
|
+
display: "flex",
|
|
24
|
+
flexDirection: "column"
|
|
25
|
+
};
|
|
26
|
+
if (props.offsetY !== void 0) {
|
|
27
|
+
outerStyle = {
|
|
28
|
+
height: `${props.height}px`,
|
|
29
|
+
position: "relative",
|
|
30
|
+
overflow: "hidden"
|
|
31
|
+
};
|
|
32
|
+
innerStyle = {
|
|
33
|
+
...innerStyle,
|
|
34
|
+
transform: `translateY(${props.offsetY}px)`,
|
|
35
|
+
[props.rtl ? "marginRight" : "marginLeft"]: `-${props.offsetX || 0}px`,
|
|
36
|
+
position: "absolute",
|
|
37
|
+
left: 0,
|
|
38
|
+
right: 0,
|
|
39
|
+
top: 0
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return (0, vue.createVNode)("div", { "style": outerStyle }, [(0, vue.createVNode)(__v_c_resize_observer.default, { "onResize": ({ offsetHeight }) => {
|
|
43
|
+
if (offsetHeight && props.onInnerResize) props.onInnerResize();
|
|
44
|
+
} }, { default: () => [(0, vue.createVNode)("div", (0, vue.mergeProps)({
|
|
45
|
+
"style": innerStyle,
|
|
46
|
+
"class": props.prefixCls ? `${props.prefixCls}-holder-inner` : void 0
|
|
47
|
+
}, props.innerProps), [slots.default?.(), props.extra])] })]);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
exports.default = Filler_default;
|
package/dist/Filler.js
CHANGED
|
@@ -1,57 +1,48 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
default: () => [i("div", o({
|
|
48
|
-
style: t,
|
|
49
|
-
class: e.prefixCls ? `${e.prefixCls}-holder-inner` : void 0
|
|
50
|
-
}, e.innerProps), [r.default?.(), e.extra])]
|
|
51
|
-
})]);
|
|
52
|
-
};
|
|
53
|
-
}
|
|
1
|
+
import { createVNode, defineComponent, mergeProps } from "vue";
|
|
2
|
+
import ResizeObserver from "@v-c/resize-observer";
|
|
3
|
+
var Filler_default = /* @__PURE__ */ defineComponent({
|
|
4
|
+
name: "Filler",
|
|
5
|
+
props: {
|
|
6
|
+
prefixCls: String,
|
|
7
|
+
height: Number,
|
|
8
|
+
offsetY: Number,
|
|
9
|
+
offsetX: Number,
|
|
10
|
+
scrollWidth: Number,
|
|
11
|
+
onInnerResize: Function,
|
|
12
|
+
innerProps: Object,
|
|
13
|
+
rtl: Boolean,
|
|
14
|
+
extra: Object
|
|
15
|
+
},
|
|
16
|
+
setup(props, { slots }) {
|
|
17
|
+
return () => {
|
|
18
|
+
let outerStyle = {};
|
|
19
|
+
let innerStyle = {
|
|
20
|
+
display: "flex",
|
|
21
|
+
flexDirection: "column"
|
|
22
|
+
};
|
|
23
|
+
if (props.offsetY !== void 0) {
|
|
24
|
+
outerStyle = {
|
|
25
|
+
height: `${props.height}px`,
|
|
26
|
+
position: "relative",
|
|
27
|
+
overflow: "hidden"
|
|
28
|
+
};
|
|
29
|
+
innerStyle = {
|
|
30
|
+
...innerStyle,
|
|
31
|
+
transform: `translateY(${props.offsetY}px)`,
|
|
32
|
+
[props.rtl ? "marginRight" : "marginLeft"]: `-${props.offsetX || 0}px`,
|
|
33
|
+
position: "absolute",
|
|
34
|
+
left: 0,
|
|
35
|
+
right: 0,
|
|
36
|
+
top: 0
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return createVNode("div", { "style": outerStyle }, [createVNode(ResizeObserver, { "onResize": ({ offsetHeight }) => {
|
|
40
|
+
if (offsetHeight && props.onInnerResize) props.onInnerResize();
|
|
41
|
+
} }, { default: () => [createVNode("div", mergeProps({
|
|
42
|
+
"style": innerStyle,
|
|
43
|
+
"class": props.prefixCls ? `${props.prefixCls}-holder-inner` : void 0
|
|
44
|
+
}, props.innerProps), [slots.default?.(), props.extra])] })]);
|
|
45
|
+
};
|
|
46
|
+
}
|
|
54
47
|
});
|
|
55
|
-
export {
|
|
56
|
-
u as default
|
|
57
|
-
};
|
|
48
|
+
export { Filler_default as default };
|
package/dist/Item.cjs
CHANGED
|
@@ -1 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
const require_rolldown_runtime = require("./_virtual/rolldown_runtime.cjs");
|
|
3
|
+
let vue = require("vue");
|
|
4
|
+
let __v_c_util_dist_props_util = require("@v-c/util/dist/props-util");
|
|
5
|
+
var Item_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
6
|
+
name: "Item",
|
|
7
|
+
props: { setRef: {
|
|
8
|
+
type: Function,
|
|
9
|
+
required: true
|
|
10
|
+
} },
|
|
11
|
+
setup(props, { slots }) {
|
|
12
|
+
const currentElement = (0, vue.shallowRef)(null);
|
|
13
|
+
const refFunc = (node) => {
|
|
14
|
+
if (currentElement.value !== node) {
|
|
15
|
+
currentElement.value = node;
|
|
16
|
+
props.setRef(node);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
return () => {
|
|
20
|
+
const child = (0, __v_c_util_dist_props_util.filterEmpty)(slots.default?.() ?? [])[0];
|
|
21
|
+
if (!child) return null;
|
|
22
|
+
return (0, vue.cloneVNode)(child, { ref: refFunc });
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
exports.default = Item_default;
|
package/dist/Item.js
CHANGED
|
@@ -1,27 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
1
|
+
import { cloneVNode, defineComponent, shallowRef } from "vue";
|
|
2
|
+
import { filterEmpty } from "@v-c/util/dist/props-util";
|
|
3
|
+
var Item_default = /* @__PURE__ */ defineComponent({
|
|
4
|
+
name: "Item",
|
|
5
|
+
props: { setRef: {
|
|
6
|
+
type: Function,
|
|
7
|
+
required: true
|
|
8
|
+
} },
|
|
9
|
+
setup(props, { slots }) {
|
|
10
|
+
const currentElement = shallowRef(null);
|
|
11
|
+
const refFunc = (node) => {
|
|
12
|
+
if (currentElement.value !== node) {
|
|
13
|
+
currentElement.value = node;
|
|
14
|
+
props.setRef(node);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
return () => {
|
|
18
|
+
const child = filterEmpty(slots.default?.() ?? [])[0];
|
|
19
|
+
if (!child) return null;
|
|
20
|
+
return cloneVNode(child, { ref: refFunc });
|
|
21
|
+
};
|
|
22
|
+
}
|
|
24
23
|
});
|
|
25
|
-
export {
|
|
26
|
-
i as default
|
|
27
|
-
};
|
|
24
|
+
export { Item_default as default };
|
package/dist/List.cjs
CHANGED
|
@@ -1 +1,408 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
const require_rolldown_runtime = require("./_virtual/rolldown_runtime.cjs");
|
|
3
|
+
const require_Filler = require("./Filler.cjs");
|
|
4
|
+
const require_Item = require("./Item.cjs");
|
|
5
|
+
const require_useDiffItem = require("./hooks/useDiffItem.cjs");
|
|
6
|
+
const require_useFrameWheel = require("./hooks/useFrameWheel.cjs");
|
|
7
|
+
const require_useGetSize = require("./hooks/useGetSize.cjs");
|
|
8
|
+
const require_useHeights = require("./hooks/useHeights.cjs");
|
|
9
|
+
const require_useMobileTouchMove = require("./hooks/useMobileTouchMove.cjs");
|
|
10
|
+
const require_useScrollDrag = require("./hooks/useScrollDrag.cjs");
|
|
11
|
+
const require_useScrollTo = require("./hooks/useScrollTo.cjs");
|
|
12
|
+
const require_ScrollBar = require("./ScrollBar.cjs");
|
|
13
|
+
const require_scrollbarUtil = require("./utils/scrollbarUtil.cjs");
|
|
14
|
+
let vue = require("vue");
|
|
15
|
+
let __v_c_resize_observer = require("@v-c/resize-observer");
|
|
16
|
+
__v_c_resize_observer = require_rolldown_runtime.__toESM(__v_c_resize_observer);
|
|
17
|
+
let __v_c_util_dist_props_util = require("@v-c/util/dist/props-util");
|
|
18
|
+
function _isSlot(s) {
|
|
19
|
+
return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !(0, vue.isVNode)(s);
|
|
20
|
+
}
|
|
21
|
+
var EMPTY_DATA = [];
|
|
22
|
+
var ScrollStyle = {
|
|
23
|
+
overflowY: "auto",
|
|
24
|
+
overflowAnchor: "none"
|
|
25
|
+
};
|
|
26
|
+
var List_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
27
|
+
name: "VirtualList",
|
|
28
|
+
props: {
|
|
29
|
+
prefixCls: {
|
|
30
|
+
type: String,
|
|
31
|
+
default: "vc-virtual-list"
|
|
32
|
+
},
|
|
33
|
+
data: { type: Array },
|
|
34
|
+
height: Number,
|
|
35
|
+
itemHeight: Number,
|
|
36
|
+
fullHeight: {
|
|
37
|
+
type: Boolean,
|
|
38
|
+
default: true
|
|
39
|
+
},
|
|
40
|
+
itemKey: {
|
|
41
|
+
type: [
|
|
42
|
+
String,
|
|
43
|
+
Number,
|
|
44
|
+
Function
|
|
45
|
+
],
|
|
46
|
+
required: true
|
|
47
|
+
},
|
|
48
|
+
component: {
|
|
49
|
+
type: String,
|
|
50
|
+
default: "div"
|
|
51
|
+
},
|
|
52
|
+
direction: { type: String },
|
|
53
|
+
scrollWidth: Number,
|
|
54
|
+
styles: Object,
|
|
55
|
+
showScrollBar: {
|
|
56
|
+
type: [Boolean, String],
|
|
57
|
+
default: "optional"
|
|
58
|
+
},
|
|
59
|
+
virtual: {
|
|
60
|
+
type: Boolean,
|
|
61
|
+
default: true
|
|
62
|
+
},
|
|
63
|
+
onScroll: Function,
|
|
64
|
+
onVirtualScroll: Function,
|
|
65
|
+
onVisibleChange: Function,
|
|
66
|
+
innerProps: Object,
|
|
67
|
+
extraRender: Function
|
|
68
|
+
},
|
|
69
|
+
inheritAttrs: false,
|
|
70
|
+
setup(props, { expose, attrs, slots }) {
|
|
71
|
+
const itemHeight = (0, vue.computed)(() => props.itemHeight);
|
|
72
|
+
const getKey = (item) => {
|
|
73
|
+
if (typeof props.itemKey === "function") return props.itemKey(item);
|
|
74
|
+
return item?.[props.itemKey];
|
|
75
|
+
};
|
|
76
|
+
const [setInstanceRef, collectHeight, heights, heightUpdatedMark] = require_useHeights.default(getKey, void 0, void 0);
|
|
77
|
+
const mergedData = (0, vue.computed)(() => props.data || EMPTY_DATA);
|
|
78
|
+
const useVirtual = (0, vue.computed)(() => !!(props.virtual !== false && props.height && props.itemHeight));
|
|
79
|
+
const containerHeight = (0, vue.computed)(() => Object.values(heights.maps).reduce((total, curr) => total + curr, 0));
|
|
80
|
+
const inVirtual = (0, vue.computed)(() => {
|
|
81
|
+
const data = mergedData.value;
|
|
82
|
+
return useVirtual.value && data && (Math.max(props.itemHeight * data.length, containerHeight.value) > props.height || !!props.scrollWidth);
|
|
83
|
+
});
|
|
84
|
+
const componentRef = (0, vue.ref)();
|
|
85
|
+
const fillerInnerRef = (0, vue.ref)();
|
|
86
|
+
const containerRef = (0, vue.ref)();
|
|
87
|
+
const verticalScrollBarRef = (0, vue.shallowRef)();
|
|
88
|
+
const horizontalScrollBarRef = (0, vue.shallowRef)();
|
|
89
|
+
const offsetTop = (0, vue.ref)(0);
|
|
90
|
+
const offsetLeft = (0, vue.ref)(0);
|
|
91
|
+
const scrollMoving = (0, vue.ref)(false);
|
|
92
|
+
const verticalScrollBarSpinSize = (0, vue.ref)(0);
|
|
93
|
+
const horizontalScrollBarSpinSize = (0, vue.ref)(0);
|
|
94
|
+
const contentScrollWidth = (0, vue.ref)(props.scrollWidth || 0);
|
|
95
|
+
const scrollHeight = (0, vue.ref)(0);
|
|
96
|
+
const start = (0, vue.ref)(0);
|
|
97
|
+
const end = (0, vue.ref)(0);
|
|
98
|
+
const fillerOffset = (0, vue.ref)(void 0);
|
|
99
|
+
function syncScrollTop(newTop) {
|
|
100
|
+
let value;
|
|
101
|
+
if (typeof newTop === "function") value = newTop(offsetTop.value);
|
|
102
|
+
else value = newTop;
|
|
103
|
+
const maxScrollHeight = scrollHeight.value - props.height;
|
|
104
|
+
const alignedTop = Math.max(0, Math.min(value, maxScrollHeight || 0));
|
|
105
|
+
if (componentRef.value) componentRef.value.scrollTop = alignedTop;
|
|
106
|
+
offsetTop.value = alignedTop;
|
|
107
|
+
}
|
|
108
|
+
require_useDiffItem.default(mergedData, getKey);
|
|
109
|
+
(0, vue.watch)([
|
|
110
|
+
inVirtual,
|
|
111
|
+
useVirtual,
|
|
112
|
+
offsetTop,
|
|
113
|
+
mergedData,
|
|
114
|
+
heightUpdatedMark,
|
|
115
|
+
() => props.height
|
|
116
|
+
], () => {
|
|
117
|
+
if (!useVirtual.value) {
|
|
118
|
+
scrollHeight.value = 0;
|
|
119
|
+
start.value = 0;
|
|
120
|
+
end.value = mergedData.value.length - 1;
|
|
121
|
+
fillerOffset.value = void 0;
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (!inVirtual.value) {
|
|
125
|
+
scrollHeight.value = fillerInnerRef.value?.offsetHeight || 0;
|
|
126
|
+
start.value = 0;
|
|
127
|
+
end.value = mergedData.value.length - 1;
|
|
128
|
+
fillerOffset.value = void 0;
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
let itemTop = 0;
|
|
132
|
+
let startIndex;
|
|
133
|
+
let startOffset;
|
|
134
|
+
let endIndex;
|
|
135
|
+
const dataLen = mergedData.value.length;
|
|
136
|
+
const data = mergedData.value;
|
|
137
|
+
for (let i = 0; i < dataLen; i += 1) {
|
|
138
|
+
const item = data[i];
|
|
139
|
+
const key = getKey(item);
|
|
140
|
+
const cacheHeight = heights.get(key);
|
|
141
|
+
const currentItemBottom = itemTop + (cacheHeight === void 0 ? props.itemHeight : cacheHeight);
|
|
142
|
+
if (currentItemBottom >= offsetTop.value && startIndex === void 0) {
|
|
143
|
+
startIndex = i;
|
|
144
|
+
startOffset = itemTop;
|
|
145
|
+
}
|
|
146
|
+
if (currentItemBottom > offsetTop.value + props.height && endIndex === void 0) endIndex = i;
|
|
147
|
+
itemTop = currentItemBottom;
|
|
148
|
+
}
|
|
149
|
+
if (startIndex === void 0) {
|
|
150
|
+
startIndex = 0;
|
|
151
|
+
startOffset = 0;
|
|
152
|
+
endIndex = Math.ceil(props.height / props.itemHeight);
|
|
153
|
+
}
|
|
154
|
+
if (endIndex === void 0) endIndex = mergedData.value.length - 1;
|
|
155
|
+
endIndex = Math.min(endIndex + 1, mergedData.value.length - 1);
|
|
156
|
+
scrollHeight.value = itemTop;
|
|
157
|
+
start.value = startIndex;
|
|
158
|
+
end.value = endIndex;
|
|
159
|
+
fillerOffset.value = startOffset;
|
|
160
|
+
}, { immediate: true });
|
|
161
|
+
(0, vue.watch)(scrollHeight, () => {
|
|
162
|
+
const changedRecord = heights.getRecord();
|
|
163
|
+
if (changedRecord.size === 1) {
|
|
164
|
+
const recordKey = Array.from(changedRecord.keys())[0];
|
|
165
|
+
const prevCacheHeight = changedRecord.get(recordKey);
|
|
166
|
+
const startItem = mergedData.value[start.value];
|
|
167
|
+
if (startItem && prevCacheHeight === void 0) {
|
|
168
|
+
if (getKey(startItem) === recordKey) {
|
|
169
|
+
const diffHeight = heights.get(recordKey) - props.itemHeight;
|
|
170
|
+
syncScrollTop((ori) => ori + diffHeight);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
heights.resetRecord();
|
|
175
|
+
});
|
|
176
|
+
const size = (0, vue.ref)({
|
|
177
|
+
width: 0,
|
|
178
|
+
height: props.height || 0
|
|
179
|
+
});
|
|
180
|
+
const onHolderResize = (sizeInfo) => {
|
|
181
|
+
size.value = {
|
|
182
|
+
width: sizeInfo.offsetWidth,
|
|
183
|
+
height: sizeInfo.offsetHeight
|
|
184
|
+
};
|
|
185
|
+
contentScrollWidth.value = props.scrollWidth ?? sizeInfo.offsetWidth;
|
|
186
|
+
};
|
|
187
|
+
const isRTL = (0, vue.computed)(() => props.direction === "rtl");
|
|
188
|
+
const getVirtualScrollInfo = () => ({
|
|
189
|
+
x: isRTL.value ? -offsetLeft.value : offsetLeft.value,
|
|
190
|
+
y: offsetTop.value
|
|
191
|
+
});
|
|
192
|
+
const lastVirtualScrollInfo = (0, vue.ref)(getVirtualScrollInfo());
|
|
193
|
+
const triggerScroll = (params) => {
|
|
194
|
+
if (props.onVirtualScroll) {
|
|
195
|
+
const nextInfo = {
|
|
196
|
+
...getVirtualScrollInfo(),
|
|
197
|
+
...params
|
|
198
|
+
};
|
|
199
|
+
if (lastVirtualScrollInfo.value.x !== nextInfo.x || lastVirtualScrollInfo.value.y !== nextInfo.y) {
|
|
200
|
+
props.onVirtualScroll(nextInfo);
|
|
201
|
+
lastVirtualScrollInfo.value = nextInfo;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
const horizontalRange = (0, vue.computed)(() => Math.max(0, (contentScrollWidth.value || 0) - size.value.width));
|
|
206
|
+
const isScrollAtTop = (0, vue.computed)(() => offsetTop.value === 0);
|
|
207
|
+
const isScrollAtBottom = (0, vue.computed)(() => offsetTop.value + props.height >= scrollHeight.value);
|
|
208
|
+
const isScrollAtLeft = (0, vue.computed)(() => offsetLeft.value === 0);
|
|
209
|
+
const isScrollAtRight = (0, vue.computed)(() => offsetLeft.value >= horizontalRange.value);
|
|
210
|
+
const keepInHorizontalRange = (nextOffsetLeft) => {
|
|
211
|
+
const max = horizontalRange.value;
|
|
212
|
+
return Math.max(0, Math.min(nextOffsetLeft, max));
|
|
213
|
+
};
|
|
214
|
+
const delayHideScrollBar = () => {
|
|
215
|
+
verticalScrollBarRef.value?.delayHidden();
|
|
216
|
+
horizontalScrollBarRef.value?.delayHidden();
|
|
217
|
+
};
|
|
218
|
+
const [onWheel] = require_useFrameWheel.default(inVirtual, isScrollAtTop, isScrollAtBottom, isScrollAtLeft, isScrollAtRight, horizontalRange.value > 0, (offsetY, isHorizontal) => {
|
|
219
|
+
if (isHorizontal) {
|
|
220
|
+
const aligned = keepInHorizontalRange(isRTL.value ? offsetLeft.value - offsetY : offsetLeft.value + offsetY);
|
|
221
|
+
offsetLeft.value = aligned;
|
|
222
|
+
triggerScroll({ x: isRTL.value ? -aligned : aligned });
|
|
223
|
+
} else syncScrollTop((top) => top + offsetY);
|
|
224
|
+
});
|
|
225
|
+
require_useMobileTouchMove.default(inVirtual, componentRef, (isHorizontal, offset, _smoothOffset, _e) => {
|
|
226
|
+
if (isHorizontal) {
|
|
227
|
+
const aligned = keepInHorizontalRange(isRTL.value ? offsetLeft.value - offset : offsetLeft.value + offset);
|
|
228
|
+
offsetLeft.value = aligned;
|
|
229
|
+
triggerScroll({ x: isRTL.value ? -aligned : aligned });
|
|
230
|
+
return true;
|
|
231
|
+
} else {
|
|
232
|
+
syncScrollTop((top) => top + offset);
|
|
233
|
+
return true;
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
require_useScrollDrag.default(inVirtual, componentRef, (offset) => {
|
|
237
|
+
syncScrollTop((top) => top + offset);
|
|
238
|
+
});
|
|
239
|
+
const onScrollBar = (newScrollOffset, horizontal) => {
|
|
240
|
+
const newOffset = newScrollOffset;
|
|
241
|
+
if (horizontal) {
|
|
242
|
+
offsetLeft.value = newOffset;
|
|
243
|
+
triggerScroll({ x: isRTL.value ? -newOffset : newOffset });
|
|
244
|
+
} else syncScrollTop(newOffset);
|
|
245
|
+
};
|
|
246
|
+
const onScrollbarStartMove = () => {
|
|
247
|
+
scrollMoving.value = true;
|
|
248
|
+
};
|
|
249
|
+
const onScrollbarStopMove = () => {
|
|
250
|
+
scrollMoving.value = false;
|
|
251
|
+
};
|
|
252
|
+
(0, vue.watch)([
|
|
253
|
+
() => props.height,
|
|
254
|
+
scrollHeight,
|
|
255
|
+
inVirtual,
|
|
256
|
+
() => size.value.height
|
|
257
|
+
], () => {
|
|
258
|
+
if (inVirtual.value && props.height && scrollHeight.value) verticalScrollBarSpinSize.value = require_scrollbarUtil.getSpinSize(size.value.height, scrollHeight.value);
|
|
259
|
+
}, { immediate: true });
|
|
260
|
+
(0, vue.watch)([() => size.value.width, () => contentScrollWidth.value], () => {
|
|
261
|
+
if (inVirtual.value && contentScrollWidth.value) horizontalScrollBarSpinSize.value = require_scrollbarUtil.getSpinSize(size.value.width, contentScrollWidth.value);
|
|
262
|
+
}, { immediate: true });
|
|
263
|
+
(0, vue.watch)(() => props.scrollWidth, (val) => {
|
|
264
|
+
contentScrollWidth.value = val ?? size.value.width;
|
|
265
|
+
offsetLeft.value = keepInHorizontalRange(offsetLeft.value);
|
|
266
|
+
}, { immediate: true });
|
|
267
|
+
function onFallbackScroll(e) {
|
|
268
|
+
const newScrollTop = e.currentTarget.scrollTop;
|
|
269
|
+
if (newScrollTop !== offsetTop.value) syncScrollTop(newScrollTop);
|
|
270
|
+
props.onScroll?.(e);
|
|
271
|
+
triggerScroll();
|
|
272
|
+
}
|
|
273
|
+
const scrollTo = require_useScrollTo.default(componentRef, mergedData, heights, itemHeight, getKey, () => collectHeight(true), syncScrollTop, delayHideScrollBar);
|
|
274
|
+
expose({
|
|
275
|
+
nativeElement: containerRef,
|
|
276
|
+
getScrollInfo: getVirtualScrollInfo,
|
|
277
|
+
scrollTo: (config) => {
|
|
278
|
+
function isPosScroll(arg) {
|
|
279
|
+
return arg && typeof arg === "object" && ("left" in arg || "top" in arg);
|
|
280
|
+
}
|
|
281
|
+
if (isPosScroll(config)) {
|
|
282
|
+
if (config.left !== void 0) offsetLeft.value = keepInHorizontalRange(config.left);
|
|
283
|
+
scrollTo(config.top);
|
|
284
|
+
} else scrollTo(config);
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
(0, vue.watch)([
|
|
288
|
+
start,
|
|
289
|
+
end,
|
|
290
|
+
mergedData
|
|
291
|
+
], () => {
|
|
292
|
+
if (props.onVisibleChange) {
|
|
293
|
+
const renderList = mergedData.value.slice(start.value, end.value + 1);
|
|
294
|
+
props.onVisibleChange(renderList, mergedData.value);
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
const getSize = require_useGetSize.useGetSize(mergedData, getKey, heights, itemHeight);
|
|
298
|
+
return () => {
|
|
299
|
+
let _slot;
|
|
300
|
+
const renderChildren = () => {
|
|
301
|
+
const children = [];
|
|
302
|
+
const data = mergedData.value;
|
|
303
|
+
const defaultSlot = slots.default;
|
|
304
|
+
if (!defaultSlot) return children;
|
|
305
|
+
for (let i = start.value; i <= end.value; i += 1) {
|
|
306
|
+
const item = data[i];
|
|
307
|
+
const key = getKey(item);
|
|
308
|
+
const nodes = defaultSlot({
|
|
309
|
+
item,
|
|
310
|
+
index: i,
|
|
311
|
+
style: {},
|
|
312
|
+
offsetX: offsetLeft.value
|
|
313
|
+
});
|
|
314
|
+
const node = Array.isArray(nodes) ? nodes[0] : nodes;
|
|
315
|
+
if (node) children.push((0, vue.createVNode)(require_Item.default, {
|
|
316
|
+
"key": key,
|
|
317
|
+
"setRef": (ele) => setInstanceRef(item, ele)
|
|
318
|
+
}, _isSlot(node) ? node : { default: () => [node] }));
|
|
319
|
+
}
|
|
320
|
+
return children;
|
|
321
|
+
};
|
|
322
|
+
const componentStyle = {};
|
|
323
|
+
if (props.height) {
|
|
324
|
+
componentStyle[props.fullHeight ? "height" : "maxHeight"] = `${props.height}px`;
|
|
325
|
+
Object.assign(componentStyle, ScrollStyle);
|
|
326
|
+
if (useVirtual.value) {
|
|
327
|
+
componentStyle.overflowY = "hidden";
|
|
328
|
+
if (horizontalRange.value > 0) componentStyle.overflowX = "hidden";
|
|
329
|
+
if (scrollMoving.value) componentStyle.pointerEvents = "none";
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
const extraContent = props.extraRender?.({
|
|
333
|
+
start: start.value,
|
|
334
|
+
end: end.value,
|
|
335
|
+
virtual: inVirtual.value,
|
|
336
|
+
offsetX: offsetLeft.value,
|
|
337
|
+
offsetY: fillerOffset.value || 0,
|
|
338
|
+
rtl: isRTL.value,
|
|
339
|
+
getSize: getSize.value
|
|
340
|
+
});
|
|
341
|
+
const Component = props.component;
|
|
342
|
+
return (0, vue.createVNode)("div", (0, vue.mergeProps)({ "ref": containerRef }, (0, __v_c_util_dist_props_util.pureAttrs)(attrs), {
|
|
343
|
+
"style": {
|
|
344
|
+
position: "relative",
|
|
345
|
+
...attrs.style
|
|
346
|
+
},
|
|
347
|
+
"dir": isRTL.value ? "rtl" : void 0,
|
|
348
|
+
"class": [
|
|
349
|
+
props.prefixCls,
|
|
350
|
+
{ [`${props.prefixCls}-rtl`]: isRTL.value },
|
|
351
|
+
attrs.class
|
|
352
|
+
]
|
|
353
|
+
}), [
|
|
354
|
+
(0, vue.createVNode)(__v_c_resize_observer.default, { "onResize": onHolderResize }, { default: () => [(0, vue.createVNode)(Component, {
|
|
355
|
+
"class": `${props.prefixCls}-holder`,
|
|
356
|
+
"style": componentStyle,
|
|
357
|
+
"ref": componentRef,
|
|
358
|
+
"onScroll": onFallbackScroll,
|
|
359
|
+
"onWheel": onWheel,
|
|
360
|
+
"onMouseenter": delayHideScrollBar
|
|
361
|
+
}, { default: () => [(0, vue.createVNode)(require_Filler.default, {
|
|
362
|
+
"prefixCls": props.prefixCls,
|
|
363
|
+
"height": scrollHeight.value,
|
|
364
|
+
"offsetX": offsetLeft.value,
|
|
365
|
+
"offsetY": fillerOffset.value,
|
|
366
|
+
"scrollWidth": contentScrollWidth.value,
|
|
367
|
+
"onInnerResize": collectHeight,
|
|
368
|
+
"ref": fillerInnerRef,
|
|
369
|
+
"innerProps": props.innerProps,
|
|
370
|
+
"rtl": isRTL.value,
|
|
371
|
+
"extra": extraContent
|
|
372
|
+
}, _isSlot(_slot = renderChildren()) ? _slot : { default: () => [_slot] })] })] }),
|
|
373
|
+
inVirtual.value && scrollHeight.value > (props.height || 0) && (0, vue.createVNode)(require_ScrollBar.default, {
|
|
374
|
+
"ref": verticalScrollBarRef,
|
|
375
|
+
"prefixCls": props.prefixCls,
|
|
376
|
+
"scrollOffset": offsetTop.value,
|
|
377
|
+
"scrollRange": scrollHeight.value,
|
|
378
|
+
"rtl": isRTL.value,
|
|
379
|
+
"onScroll": onScrollBar,
|
|
380
|
+
"onStartMove": onScrollbarStartMove,
|
|
381
|
+
"onStopMove": onScrollbarStopMove,
|
|
382
|
+
"spinSize": verticalScrollBarSpinSize.value,
|
|
383
|
+
"containerSize": size.value.height,
|
|
384
|
+
"showScrollBar": props.showScrollBar,
|
|
385
|
+
"style": props.styles?.verticalScrollBar,
|
|
386
|
+
"thumbStyle": props.styles?.verticalScrollBarThumb
|
|
387
|
+
}, null),
|
|
388
|
+
inVirtual.value && contentScrollWidth.value > size.value.width && (0, vue.createVNode)(require_ScrollBar.default, {
|
|
389
|
+
"ref": horizontalScrollBarRef,
|
|
390
|
+
"prefixCls": props.prefixCls,
|
|
391
|
+
"scrollOffset": offsetLeft.value,
|
|
392
|
+
"scrollRange": contentScrollWidth.value,
|
|
393
|
+
"rtl": isRTL.value,
|
|
394
|
+
"onScroll": onScrollBar,
|
|
395
|
+
"onStartMove": onScrollbarStartMove,
|
|
396
|
+
"onStopMove": onScrollbarStopMove,
|
|
397
|
+
"spinSize": horizontalScrollBarSpinSize.value,
|
|
398
|
+
"containerSize": size.value.width,
|
|
399
|
+
"horizontal": true,
|
|
400
|
+
"showScrollBar": props.showScrollBar,
|
|
401
|
+
"style": props.styles?.horizontalScrollBar,
|
|
402
|
+
"thumbStyle": props.styles?.horizontalScrollBarThumb
|
|
403
|
+
}, null)
|
|
404
|
+
]);
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
exports.default = List_default;
|