|
|
@ -84,16 +84,13 @@ const List = defineComponent({
|
|
|
|
},
|
|
|
|
},
|
|
|
|
setup(props) {
|
|
|
|
setup(props) {
|
|
|
|
// ================================= MISC =================================
|
|
|
|
// ================================= MISC =================================
|
|
|
|
|
|
|
|
const useVirtual = computed(()=>{
|
|
|
|
|
|
|
|
const { height, itemHeight, virtual } = props;
|
|
|
|
|
|
|
|
return !!(virtual !== false && height && itemHeight);
|
|
|
|
|
|
|
|
})
|
|
|
|
const inVirtual = computed(() => {
|
|
|
|
const inVirtual = computed(() => {
|
|
|
|
const { height, itemHeight, data, virtual } = props;
|
|
|
|
const { height, itemHeight, data } = props;
|
|
|
|
return !!(
|
|
|
|
return useVirtual.value && data && itemHeight * data.length > height;
|
|
|
|
virtual !== false &&
|
|
|
|
|
|
|
|
height &&
|
|
|
|
|
|
|
|
itemHeight &&
|
|
|
|
|
|
|
|
data &&
|
|
|
|
|
|
|
|
itemHeight * data.length > height
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const state = reactive<ListState>({
|
|
|
|
const state = reactive<ListState>({
|
|
|
@ -103,7 +100,8 @@ const List = defineComponent({
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const componentRef = ref<HTMLDivElement>();
|
|
|
|
const componentRef = ref<HTMLDivElement>();
|
|
|
|
|
|
|
|
const fillerInnerRef = ref<HTMLDivElement>();
|
|
|
|
|
|
|
|
const scrollBarRef = ref<any>(); // Hack on scrollbar to enable flash call
|
|
|
|
// =============================== Item Key ===============================
|
|
|
|
// =============================== Item Key ===============================
|
|
|
|
const getKey = (item: Record<string, any>) => {
|
|
|
|
const getKey = (item: Record<string, any>) => {
|
|
|
|
if (typeof props.itemKey === 'function') {
|
|
|
|
if (typeof props.itemKey === 'function') {
|
|
|
@ -135,10 +133,9 @@ const List = defineComponent({
|
|
|
|
|
|
|
|
|
|
|
|
// ================================ Height ================================
|
|
|
|
// ================================ Height ================================
|
|
|
|
const [setInstance, collectHeight, heights, heightUpdatedMark] = useHeights(getKey, null, null);
|
|
|
|
const [setInstance, collectHeight, heights, heightUpdatedMark] = useHeights(getKey, null, null);
|
|
|
|
|
|
|
|
|
|
|
|
// ========================== Visible Calculation =========================
|
|
|
|
// ========================== Visible Calculation =========================
|
|
|
|
const calRes = computed(() => {
|
|
|
|
const calRes = computed(() => {
|
|
|
|
if (!inVirtual.value) {
|
|
|
|
if (!useVirtual.value) {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
scrollHeight: undefined,
|
|
|
|
scrollHeight: undefined,
|
|
|
|
start: 0,
|
|
|
|
start: 0,
|
|
|
@ -146,6 +143,17 @@ const List = defineComponent({
|
|
|
|
offset: undefined,
|
|
|
|
offset: undefined,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Always use virtual scroll bar in avoid shaking
|
|
|
|
|
|
|
|
if (!inVirtual.value) {
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
scrollHeight: fillerInnerRef.value?.offsetHeight || 0,
|
|
|
|
|
|
|
|
start: 0,
|
|
|
|
|
|
|
|
end: state.mergedData.length - 1,
|
|
|
|
|
|
|
|
offset: undefined,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let itemTop = 0;
|
|
|
|
let itemTop = 0;
|
|
|
|
let startIndex: number | undefined;
|
|
|
|
let startIndex: number | undefined;
|
|
|
|
let startOffset: number | undefined;
|
|
|
|
let startOffset: number | undefined;
|
|
|
@ -228,7 +236,7 @@ const List = defineComponent({
|
|
|
|
|
|
|
|
|
|
|
|
// Since this added in global,should use ref to keep update
|
|
|
|
// Since this added in global,should use ref to keep update
|
|
|
|
const [onRawWheel, onFireFoxScroll] = useFrameWheel(
|
|
|
|
const [onRawWheel, onFireFoxScroll] = useFrameWheel(
|
|
|
|
inVirtual,
|
|
|
|
useVirtual,
|
|
|
|
isScrollAtTop,
|
|
|
|
isScrollAtTop,
|
|
|
|
isScrollAtBottom,
|
|
|
|
isScrollAtBottom,
|
|
|
|
offsetY => {
|
|
|
|
offsetY => {
|
|
|
@ -240,7 +248,7 @@ const List = defineComponent({
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// Mobile touch move
|
|
|
|
// Mobile touch move
|
|
|
|
useMobileTouchMove(inVirtual, componentRef, (deltaY, smoothOffset) => {
|
|
|
|
useMobileTouchMove(useVirtual, componentRef, (deltaY, smoothOffset) => {
|
|
|
|
if (originScroll(deltaY, smoothOffset)) {
|
|
|
|
if (originScroll(deltaY, smoothOffset)) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -250,7 +258,7 @@ const List = defineComponent({
|
|
|
|
});
|
|
|
|
});
|
|
|
|
// Firefox only
|
|
|
|
// Firefox only
|
|
|
|
function onMozMousePixelScroll(e: MouseEvent) {
|
|
|
|
function onMozMousePixelScroll(e: MouseEvent) {
|
|
|
|
if (inVirtual.value) {
|
|
|
|
if (useVirtual.value) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -285,6 +293,9 @@ const List = defineComponent({
|
|
|
|
getKey,
|
|
|
|
getKey,
|
|
|
|
collectHeight,
|
|
|
|
collectHeight,
|
|
|
|
syncScrollTop,
|
|
|
|
syncScrollTop,
|
|
|
|
|
|
|
|
() => {
|
|
|
|
|
|
|
|
scrollBarRef.value?.delayHidden();
|
|
|
|
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
const componentStyle = computed(() => {
|
|
|
|
const componentStyle = computed(() => {
|
|
|
@ -292,7 +303,7 @@ const List = defineComponent({
|
|
|
|
if (props.height) {
|
|
|
|
if (props.height) {
|
|
|
|
cs = { [props.fullHeight ? 'height' : 'maxHeight']: props.height + 'px', ...ScrollStyle };
|
|
|
|
cs = { [props.fullHeight ? 'height' : 'maxHeight']: props.height + 'px', ...ScrollStyle };
|
|
|
|
|
|
|
|
|
|
|
|
if (inVirtual.value) {
|
|
|
|
if (useVirtual.value) {
|
|
|
|
cs!.overflowY = 'hidden';
|
|
|
|
cs!.overflowY = 'hidden';
|
|
|
|
|
|
|
|
|
|
|
|
if (state.scrollMoving) {
|
|
|
|
if (state.scrollMoving) {
|
|
|
@ -310,11 +321,13 @@ const List = defineComponent({
|
|
|
|
onFallbackScroll,
|
|
|
|
onFallbackScroll,
|
|
|
|
onScrollBar,
|
|
|
|
onScrollBar,
|
|
|
|
componentRef,
|
|
|
|
componentRef,
|
|
|
|
inVirtual,
|
|
|
|
useVirtual,
|
|
|
|
calRes,
|
|
|
|
calRes,
|
|
|
|
collectHeight,
|
|
|
|
collectHeight,
|
|
|
|
setInstance,
|
|
|
|
setInstance,
|
|
|
|
sharedConfig,
|
|
|
|
sharedConfig,
|
|
|
|
|
|
|
|
scrollBarRef,
|
|
|
|
|
|
|
|
fillerInnerRef
|
|
|
|
};
|
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
|
|
|
render() {
|
|
|
|
render() {
|
|
|
@ -341,7 +354,7 @@ const List = defineComponent({
|
|
|
|
componentStyle,
|
|
|
|
componentStyle,
|
|
|
|
onFallbackScroll,
|
|
|
|
onFallbackScroll,
|
|
|
|
onScrollBar,
|
|
|
|
onScrollBar,
|
|
|
|
inVirtual,
|
|
|
|
useVirtual,
|
|
|
|
collectHeight,
|
|
|
|
collectHeight,
|
|
|
|
sharedConfig,
|
|
|
|
sharedConfig,
|
|
|
|
setInstance,
|
|
|
|
setInstance,
|
|
|
@ -375,13 +388,15 @@ const List = defineComponent({
|
|
|
|
height={scrollHeight}
|
|
|
|
height={scrollHeight}
|
|
|
|
offset={offset}
|
|
|
|
offset={offset}
|
|
|
|
onInnerResize={collectHeight}
|
|
|
|
onInnerResize={collectHeight}
|
|
|
|
|
|
|
|
ref="fillerInnerRef"
|
|
|
|
>
|
|
|
|
>
|
|
|
|
{listChildren}
|
|
|
|
{listChildren}
|
|
|
|
</Filler>
|
|
|
|
</Filler>
|
|
|
|
</Component>
|
|
|
|
</Component>
|
|
|
|
|
|
|
|
|
|
|
|
{inVirtual && (
|
|
|
|
{useVirtual && (
|
|
|
|
<ScrollBar
|
|
|
|
<ScrollBar
|
|
|
|
|
|
|
|
ref="scrollBarRef"
|
|
|
|
prefixCls={prefixCls}
|
|
|
|
prefixCls={prefixCls}
|
|
|
|
scrollTop={scrollTop}
|
|
|
|
scrollTop={scrollTop}
|
|
|
|
height={height}
|
|
|
|
height={height}
|
|
|
|