@v-c/virtual-list 0.0.1
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/LICENSE +21 -0
- package/dist/Filler.cjs +1 -0
- package/dist/Filler.d.ts +33 -0
- package/dist/Filler.js +57 -0
- package/dist/Item.cjs +1 -0
- package/dist/Item.d.ts +18 -0
- package/dist/Item.js +27 -0
- package/dist/List.cjs +1 -0
- package/dist/List.d.ts +108 -0
- package/dist/List.js +276 -0
- package/dist/ScrollBar.cjs +1 -0
- package/dist/ScrollBar.d.ts +116 -0
- package/dist/ScrollBar.js +193 -0
- package/dist/hooks/useDiffItem.cjs +1 -0
- package/dist/hooks/useDiffItem.d.ts +2 -0
- package/dist/hooks/useDiffItem.js +21 -0
- package/dist/hooks/useFrameWheel.cjs +1 -0
- package/dist/hooks/useFrameWheel.d.ts +11 -0
- package/dist/hooks/useFrameWheel.js +52 -0
- package/dist/hooks/useGetSize.cjs +1 -0
- package/dist/hooks/useGetSize.d.ts +7 -0
- package/dist/hooks/useGetSize.js +24 -0
- package/dist/hooks/useHeights.cjs +1 -0
- package/dist/hooks/useHeights.d.ts +9 -0
- package/dist/hooks/useHeights.js +43 -0
- package/dist/hooks/useMobileTouchMove.cjs +1 -0
- package/dist/hooks/useMobileTouchMove.d.ts +2 -0
- package/dist/hooks/useMobileTouchMove.js +44 -0
- package/dist/hooks/useOriginScroll.cjs +1 -0
- package/dist/hooks/useOriginScroll.d.ts +2 -0
- package/dist/hooks/useOriginScroll.js +17 -0
- package/dist/hooks/useScrollDrag.cjs +1 -0
- package/dist/hooks/useScrollDrag.d.ts +3 -0
- package/dist/hooks/useScrollDrag.js +51 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +4 -0
- package/dist/interface.cjs +1 -0
- package/dist/interface.d.ts +27 -0
- package/dist/interface.js +1 -0
- package/dist/utils/CacheMap.cjs +1 -0
- package/dist/utils/CacheMap.d.ts +16 -0
- package/dist/utils/CacheMap.js +29 -0
- package/dist/utils/isFirefox.cjs +1 -0
- package/dist/utils/isFirefox.d.ts +2 -0
- package/dist/utils/isFirefox.js +4 -0
- package/dist/utils/scrollbarUtil.cjs +1 -0
- package/dist/utils/scrollbarUtil.d.ts +1 -0
- package/dist/utils/scrollbarUtil.js +7 -0
- package/docs/basic.vue +175 -0
- package/docs/height.vue +48 -0
- package/docs/nest.vue +60 -0
- package/docs/no-virtual.vue +127 -0
- package/docs/switch.vue +101 -0
- package/docs/virtual-list.stories.vue +31 -0
- package/package.json +38 -0
- package/src/Filler.tsx +72 -0
- package/src/Item.tsx +34 -0
- package/src/List.tsx +577 -0
- package/src/ScrollBar.tsx +298 -0
- package/src/__tests__/List.test.ts +59 -0
- package/src/hooks/useDiffItem.ts +27 -0
- package/src/hooks/useFrameWheel.ts +141 -0
- package/src/hooks/useGetSize.ts +44 -0
- package/src/hooks/useHeights.ts +106 -0
- package/src/hooks/useMobileTouchMove.ts +131 -0
- package/src/hooks/useOriginScroll.ts +47 -0
- package/src/hooks/useScrollDrag.ts +123 -0
- package/src/index.ts +5 -0
- package/src/interface.ts +32 -0
- package/src/utils/CacheMap.ts +42 -0
- package/src/utils/isFirefox.ts +3 -0
- package/src/utils/scrollbarUtil.ts +10 -0
- package/vite.config.ts +18 -0
- package/vitest.config.ts +11 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 antdv-community
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/Filler.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("vue"),o=require("@v-c/resize-observer"),f=t.defineComponent({name:"Filler",props:{prefixCls:String,height:Number,offsetY:Number,offsetX:Number,scrollWidth:Number,onInnerResize:Function,innerProps:Object,rtl:Boolean,extra:Object},setup(e,{slots:r}){return()=>{let n={},i={display:"flex",flexDirection:"column"};return e.offsetY!==void 0&&(n={height:`${e.height}px`,position:"relative",overflow:"hidden"},i={...i,transform:`translateY(${e.offsetY}px)`,[e.rtl?"marginRight":"marginLeft"]:`-${e.offsetX||0}px`,position:"absolute",left:0,right:0,top:0}),t.createVNode("div",{style:n},[t.createVNode(o,{onResize:({offsetHeight:l})=>{l&&e.onInnerResize&&e.onInnerResize()}},{default:()=>[t.createVNode("div",t.mergeProps({style:i,class:e.prefixCls?`${e.prefixCls}-holder-inner`:void 0},e.innerProps),[r.default?.(),e.extra])]})])}}});exports.default=f;
|
package/dist/Filler.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { PropType, VNode } from 'vue';
|
|
2
|
+
export interface InnerProps {
|
|
3
|
+
role?: string;
|
|
4
|
+
id?: string;
|
|
5
|
+
}
|
|
6
|
+
declare const _default: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
|
|
7
|
+
prefixCls: StringConstructor;
|
|
8
|
+
/** Virtual filler height. Should be `count * itemMinHeight` */
|
|
9
|
+
height: NumberConstructor;
|
|
10
|
+
/** Set offset of visible items. Should be the top of start item position */
|
|
11
|
+
offsetY: NumberConstructor;
|
|
12
|
+
offsetX: NumberConstructor;
|
|
13
|
+
scrollWidth: NumberConstructor;
|
|
14
|
+
onInnerResize: PropType<() => void>;
|
|
15
|
+
innerProps: PropType<InnerProps>;
|
|
16
|
+
rtl: BooleanConstructor;
|
|
17
|
+
extra: PropType<VNode>;
|
|
18
|
+
}>, () => import("vue/jsx-runtime").JSX.Element, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
|
|
19
|
+
prefixCls: StringConstructor;
|
|
20
|
+
/** Virtual filler height. Should be `count * itemMinHeight` */
|
|
21
|
+
height: NumberConstructor;
|
|
22
|
+
/** Set offset of visible items. Should be the top of start item position */
|
|
23
|
+
offsetY: NumberConstructor;
|
|
24
|
+
offsetX: NumberConstructor;
|
|
25
|
+
scrollWidth: NumberConstructor;
|
|
26
|
+
onInnerResize: PropType<() => void>;
|
|
27
|
+
innerProps: PropType<InnerProps>;
|
|
28
|
+
rtl: BooleanConstructor;
|
|
29
|
+
extra: PropType<VNode>;
|
|
30
|
+
}>> & Readonly<{}>, {
|
|
31
|
+
rtl: boolean;
|
|
32
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
|
|
33
|
+
export default _default;
|
package/dist/Filler.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { defineComponent as f, createVNode as i, mergeProps as o } from "vue";
|
|
2
|
+
import s from "@v-c/resize-observer";
|
|
3
|
+
const u = /* @__PURE__ */ f({
|
|
4
|
+
name: "Filler",
|
|
5
|
+
props: {
|
|
6
|
+
prefixCls: String,
|
|
7
|
+
/** Virtual filler height. Should be `count * itemMinHeight` */
|
|
8
|
+
height: Number,
|
|
9
|
+
/** Set offset of visible items. Should be the top of start item position */
|
|
10
|
+
offsetY: Number,
|
|
11
|
+
offsetX: Number,
|
|
12
|
+
scrollWidth: Number,
|
|
13
|
+
onInnerResize: Function,
|
|
14
|
+
innerProps: Object,
|
|
15
|
+
rtl: Boolean,
|
|
16
|
+
extra: Object
|
|
17
|
+
},
|
|
18
|
+
setup(e, {
|
|
19
|
+
slots: r
|
|
20
|
+
}) {
|
|
21
|
+
return () => {
|
|
22
|
+
let n = {}, t = {
|
|
23
|
+
display: "flex",
|
|
24
|
+
flexDirection: "column"
|
|
25
|
+
};
|
|
26
|
+
return e.offsetY !== void 0 && (n = {
|
|
27
|
+
height: `${e.height}px`,
|
|
28
|
+
position: "relative",
|
|
29
|
+
overflow: "hidden"
|
|
30
|
+
}, t = {
|
|
31
|
+
...t,
|
|
32
|
+
transform: `translateY(${e.offsetY}px)`,
|
|
33
|
+
[e.rtl ? "marginRight" : "marginLeft"]: `-${e.offsetX || 0}px`,
|
|
34
|
+
position: "absolute",
|
|
35
|
+
left: 0,
|
|
36
|
+
right: 0,
|
|
37
|
+
top: 0
|
|
38
|
+
}), i("div", {
|
|
39
|
+
style: n
|
|
40
|
+
}, [i(s, {
|
|
41
|
+
onResize: ({
|
|
42
|
+
offsetHeight: l
|
|
43
|
+
}) => {
|
|
44
|
+
l && e.onInnerResize && e.onInnerResize();
|
|
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
|
+
}
|
|
54
|
+
});
|
|
55
|
+
export {
|
|
56
|
+
u as default
|
|
57
|
+
};
|
package/dist/Item.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const o=require("@v-c/util/dist/props-util"),t=require("vue"),s=t.defineComponent({name:"Item",props:{setRef:{type:Function,required:!0}},setup(u,{slots:n}){const r=t.shallowRef(null),l=e=>{r.value!==e&&(r.value=e,u.setRef(e))};return()=>{const e=o.filterEmpty(n.default?.()??[])[0];return e?t.cloneVNode(e,{ref:l}):null}}});exports.default=s;
|
package/dist/Item.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PropType } from 'vue';
|
|
2
|
+
export interface ItemProps {
|
|
3
|
+
setRef: (element: HTMLElement | null) => void;
|
|
4
|
+
}
|
|
5
|
+
declare const _default: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
|
|
6
|
+
setRef: {
|
|
7
|
+
type: PropType<(element: HTMLElement | null) => void>;
|
|
8
|
+
required: true;
|
|
9
|
+
};
|
|
10
|
+
}>, () => import('vue').VNode<import('vue').RendererNode, import('vue').RendererElement, {
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
}> | null, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
|
|
13
|
+
setRef: {
|
|
14
|
+
type: PropType<(element: HTMLElement | null) => void>;
|
|
15
|
+
required: true;
|
|
16
|
+
};
|
|
17
|
+
}>> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
|
|
18
|
+
export default _default;
|
package/dist/Item.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { filterEmpty as l } from "@v-c/util/dist/props-util";
|
|
2
|
+
import { defineComponent as o, shallowRef as f, cloneVNode as m } from "vue";
|
|
3
|
+
const i = /* @__PURE__ */ o({
|
|
4
|
+
name: "Item",
|
|
5
|
+
props: {
|
|
6
|
+
setRef: {
|
|
7
|
+
type: Function,
|
|
8
|
+
required: !0
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
setup(r, {
|
|
12
|
+
slots: n
|
|
13
|
+
}) {
|
|
14
|
+
const t = f(null), u = (e) => {
|
|
15
|
+
t.value !== e && (t.value = e, r.setRef(e));
|
|
16
|
+
};
|
|
17
|
+
return () => {
|
|
18
|
+
const e = l(n.default?.() ?? [])[0];
|
|
19
|
+
return e ? m(e, {
|
|
20
|
+
ref: u
|
|
21
|
+
}) : null;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
export {
|
|
26
|
+
i as default
|
|
27
|
+
};
|
package/dist/List.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("vue"),ne=require("@v-c/resize-observer"),ie=require("./Filler.cjs"),ae=require("./hooks/useDiffItem.cjs"),oe=require("./hooks/useFrameWheel.cjs"),ue=require("./hooks/useGetSize.cjs"),re=require("./hooks/useHeights.cjs"),ce=require("./hooks/useMobileTouchMove.cjs"),se=require("./hooks/useScrollDrag.cjs"),fe=require("./Item.cjs"),de=require("./ScrollBar.cjs"),ve=require("./utils/scrollbarUtil.cjs");function j(l){return typeof l=="function"||Object.prototype.toString.call(l)==="[object Object]"&&!n.isVNode(l)}const he=[],ge={overflowY:"auto",overflowAnchor:"none"},me=n.defineComponent({name:"VirtualList",props:{prefixCls:{type:String,default:"vc-virtual-list"},data:{type:Array},height:Number,itemHeight:Number,fullHeight:{type:Boolean,default:!0},itemKey:{type:[String,Number,Function],required:!0},component:{type:String,default:"div"},virtual:{type:Boolean,default:!0},onScroll:Function,onVirtualScroll:Function,onVisibleChange:Function,innerProps:Object,extraRender:Function},setup(l,{expose:F,attrs:q,slots:K}){const v=e=>typeof l.itemKey=="function"?l.itemKey(e):e?.[l.itemKey],[_,L,g,P]=re.default(v,void 0,void 0),o=n.computed(()=>l.data||he),V=n.computed(()=>!!(l.virtual!==!1&&l.height&&l.itemHeight)),W=n.computed(()=>Object.values(g.maps).reduce((e,t)=>e+t,0)),h=n.computed(()=>{const e=o.value;return V.value&&e&&Math.max(l.itemHeight*e.length,W.value)>l.height}),H=n.ref(),z=n.ref(),O=n.ref(),A=n.shallowRef(),f=n.ref(0),y=n.ref(0),M=n.ref(!1),k=n.ref(0),B=n.ref(0);function m(e){let t;typeof e=="function"?t=e(f.value):t=e;const a=c.value-l.height,i=Math.max(0,Math.min(t,a||0));H.value&&(H.value.scrollTop=i),f.value=i}ae.default(o,v);const c=n.ref(0),S=n.ref(0),x=n.ref(0),b=n.ref(void 0);n.watch([()=>h.value,()=>V.value,()=>f.value,()=>o.value,()=>P.value,()=>l.height],()=>{if(!V.value){c.value=0,S.value=0,x.value=o.value.length-1,b.value=void 0;return}if(!h.value){c.value=z.value?.offsetHeight||0,S.value=0,x.value=o.value.length-1,b.value=void 0;return}let e=0,t,a,i;const r=o.value.length,d=o.value;for(let u=0;u<r;u+=1){const s=d[u],I=v(s),N=g.get(I),w=e+(N===void 0?l.itemHeight:N);w>=f.value&&t===void 0&&(t=u,a=e),w>f.value+l.height&&i===void 0&&(i=u),e=w}t===void 0&&(t=0,a=0,i=Math.ceil(l.height/l.itemHeight)),i===void 0&&(i=o.value.length-1),i=Math.min(i+1,o.value.length-1),c.value=e,S.value=t,x.value=i,b.value=a},{immediate:!0}),n.watch(()=>c.value,()=>{const e=g.getRecord();if(e.size===1){const t=Array.from(e.keys())[0],a=e.get(t),i=o.value[S.value];if(i&&a===void 0&&v(i)===t){const u=g.get(t)-l.itemHeight;m(s=>s+u)}}g.resetRecord()});const R=n.ref({width:0,height:l.height||0}),Y=e=>{R.value={width:e.offsetWidth,height:e.offsetHeight}},T=()=>({x:y.value,y:f.value}),C=n.ref(T()),D=e=>{if(l.onVirtualScroll){const t={...T(),...e};(C.value.x!==t.x||C.value.y!==t.y)&&(l.onVirtualScroll(t),C.value=t)}},X=n.computed(()=>f.value===0),E=n.computed(()=>f.value+l.height>=c.value),G=n.computed(()=>y.value===0),U=n.computed(()=>y.value+R.value.width>=B.value),$=()=>{A.value?.delayHidden()},[J]=oe.default(h,X,E,G,U,!1,(e,t)=>{t||m(a=>a+e)});ce.default(h,H,(e,t,a,i)=>e?!1:(m(r=>r+t),!0)),se.default(h,H,e=>{m(t=>t+e)});const Q=(e,t)=>{t||m(e)},Z=()=>{M.value=!0},p=()=>{M.value=!1};n.watch([()=>l.height,()=>c.value,()=>h.value,()=>R.value.height],()=>{h.value&&l.height&&c.value&&(k.value=ve.getSpinSize(R.value.height,c.value))},{immediate:!0});function ee(e){const a=e.currentTarget.scrollTop;a!==f.value&&m(a),l.onScroll?.(e),D()}F({nativeElement:O,getScrollInfo:T,scrollTo:e=>{if(e!=null){if(typeof e=="number")m(e);else if(e&&typeof e=="object"){let t;if("left"in e&&(y.value=e.left||0),"top"in e)t=e.top;else if("index"in e){const a=e.index||0;if(o.value[a]){let r=0;for(let d=0;d<a;d+=1){const u=v(o.value[d]),s=g.get(u);r+=s===void 0?l.itemHeight:s}t=r}}else if("key"in e){const a=o.value.findIndex(i=>v(i)===e.key);if(a>=0){let i=0;for(let r=0;r<a;r+=1){const d=v(o.value[r]),u=g.get(d);i+=u===void 0?l.itemHeight:u}t=i}}t!==void 0&&m(t)}}}}),n.watch([()=>S.value,()=>x.value,()=>o.value],()=>{if(l.onVisibleChange){const e=o.value.slice(S.value,x.value+1);l.onVisibleChange(e,o.value)}});const te=()=>{const e=[],t=o.value,a=K.default;if(!a)return e;for(let i=S.value;i<=x.value;i+=1){const r=t[i],d=v(r),u=a({item:r,index:i,style:{},offsetX:y.value}),s=Array.isArray(u)?u[0]:u;s&&e.push(n.createVNode(fe.default,{key:d,setRef:I=>_(r,I)},j(s)?s:{default:()=>[s]}))}return e},le=ue.useGetSize(o,v,g,l.itemHeight);return()=>{let e;const t={};l.height&&(t[l.fullHeight?"height":"maxHeight"]=`${l.height}px`,Object.assign(t,ge),V.value&&(t.overflowY="hidden",B.value&&(t.overflowX="hidden"),M.value&&(t.pointerEvents="none")));const a=l.extraRender?.({start:S.value,end:x.value,virtual:h.value,offsetX:y.value,offsetY:b.value||0,rtl:!1,getSize:le.value}),i=l.component;return n.createVNode("div",{ref:O,style:{position:"relative",...q.style},class:[l.prefixCls,q.class]},[n.createVNode(ne,{onResize:Y},{default:()=>[n.createVNode(i,{class:`${l.prefixCls}-holder`,style:t,ref:H,onScroll:ee,onWheel:J,onMouseenter:$},{default:()=>[n.createVNode(ie.default,{prefixCls:l.prefixCls,height:c.value,offsetX:y.value,offsetY:b.value,onInnerResize:L,ref:z,innerProps:l.innerProps,rtl:!1,extra:a},j(e=te())?e:{default:()=>[e]})]})]}),h.value&&c.value>(l.height||0)&&n.createVNode(de.default,{ref:A,prefixCls:l.prefixCls,scrollOffset:f.value,scrollRange:c.value,rtl:!1,onScroll:Q,onStartMove:Z,onStopMove:p,spinSize:k.value,containerSize:R.value.height,showScrollBar:"optional"},null)])}}});exports.default=me;
|
package/dist/List.d.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { Key } from '../../util/src/type';
|
|
2
|
+
import { ExtraRenderInfo } from './interface';
|
|
3
|
+
import { PropType, VNode } from 'vue';
|
|
4
|
+
import { InnerProps } from './Filler';
|
|
5
|
+
export interface ScrollInfo {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
}
|
|
9
|
+
export interface ListRef {
|
|
10
|
+
nativeElement?: HTMLDivElement;
|
|
11
|
+
scrollTo: (arg?: number | ScrollConfig) => void;
|
|
12
|
+
getScrollInfo: () => ScrollInfo;
|
|
13
|
+
}
|
|
14
|
+
export interface ScrollPos {
|
|
15
|
+
left?: number;
|
|
16
|
+
top?: number;
|
|
17
|
+
}
|
|
18
|
+
export interface ScrollTarget {
|
|
19
|
+
index?: number;
|
|
20
|
+
key?: Key;
|
|
21
|
+
align?: 'top' | 'bottom' | 'auto';
|
|
22
|
+
offset?: number;
|
|
23
|
+
}
|
|
24
|
+
export type ScrollConfig = ScrollTarget | ScrollPos;
|
|
25
|
+
export interface ListProps<T = any> {
|
|
26
|
+
prefixCls?: string;
|
|
27
|
+
data?: T[];
|
|
28
|
+
height?: number;
|
|
29
|
+
itemHeight?: number;
|
|
30
|
+
fullHeight?: boolean;
|
|
31
|
+
itemKey: Key | ((item: T) => Key);
|
|
32
|
+
component?: string;
|
|
33
|
+
virtual?: boolean;
|
|
34
|
+
onScroll?: (e: Event) => void;
|
|
35
|
+
onVirtualScroll?: (info: ScrollInfo) => void;
|
|
36
|
+
onVisibleChange?: (visibleList: T[], fullList: T[]) => void;
|
|
37
|
+
innerProps?: InnerProps;
|
|
38
|
+
extraRender?: (info: ExtraRenderInfo) => VNode;
|
|
39
|
+
}
|
|
40
|
+
declare const _default: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
|
|
41
|
+
prefixCls: {
|
|
42
|
+
type: StringConstructor;
|
|
43
|
+
default: string;
|
|
44
|
+
};
|
|
45
|
+
data: {
|
|
46
|
+
type: PropType<any[]>;
|
|
47
|
+
};
|
|
48
|
+
height: NumberConstructor;
|
|
49
|
+
itemHeight: NumberConstructor;
|
|
50
|
+
fullHeight: {
|
|
51
|
+
type: BooleanConstructor;
|
|
52
|
+
default: boolean;
|
|
53
|
+
};
|
|
54
|
+
itemKey: {
|
|
55
|
+
type: PropType<Key | ((item: any) => Key)>;
|
|
56
|
+
required: true;
|
|
57
|
+
};
|
|
58
|
+
component: {
|
|
59
|
+
type: StringConstructor;
|
|
60
|
+
default: string;
|
|
61
|
+
};
|
|
62
|
+
virtual: {
|
|
63
|
+
type: BooleanConstructor;
|
|
64
|
+
default: boolean;
|
|
65
|
+
};
|
|
66
|
+
onScroll: PropType<(e: Event) => void>;
|
|
67
|
+
onVirtualScroll: PropType<(info: ScrollInfo) => void>;
|
|
68
|
+
onVisibleChange: PropType<(visibleList: any[], fullList: any[]) => void>;
|
|
69
|
+
innerProps: PropType<InnerProps>;
|
|
70
|
+
extraRender: PropType<(info: ExtraRenderInfo) => VNode>;
|
|
71
|
+
}>, () => import("vue/jsx-runtime").JSX.Element, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
|
|
72
|
+
prefixCls: {
|
|
73
|
+
type: StringConstructor;
|
|
74
|
+
default: string;
|
|
75
|
+
};
|
|
76
|
+
data: {
|
|
77
|
+
type: PropType<any[]>;
|
|
78
|
+
};
|
|
79
|
+
height: NumberConstructor;
|
|
80
|
+
itemHeight: NumberConstructor;
|
|
81
|
+
fullHeight: {
|
|
82
|
+
type: BooleanConstructor;
|
|
83
|
+
default: boolean;
|
|
84
|
+
};
|
|
85
|
+
itemKey: {
|
|
86
|
+
type: PropType<Key | ((item: any) => Key)>;
|
|
87
|
+
required: true;
|
|
88
|
+
};
|
|
89
|
+
component: {
|
|
90
|
+
type: StringConstructor;
|
|
91
|
+
default: string;
|
|
92
|
+
};
|
|
93
|
+
virtual: {
|
|
94
|
+
type: BooleanConstructor;
|
|
95
|
+
default: boolean;
|
|
96
|
+
};
|
|
97
|
+
onScroll: PropType<(e: Event) => void>;
|
|
98
|
+
onVirtualScroll: PropType<(info: ScrollInfo) => void>;
|
|
99
|
+
onVisibleChange: PropType<(visibleList: any[], fullList: any[]) => void>;
|
|
100
|
+
innerProps: PropType<InnerProps>;
|
|
101
|
+
extraRender: PropType<(info: ExtraRenderInfo) => VNode>;
|
|
102
|
+
}>> & Readonly<{}>, {
|
|
103
|
+
prefixCls: string;
|
|
104
|
+
component: string;
|
|
105
|
+
fullHeight: boolean;
|
|
106
|
+
virtual: boolean;
|
|
107
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
|
|
108
|
+
export default _default;
|
package/dist/List.js
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { defineComponent as ae, computed as y, ref as r, shallowRef as ue, watch as T, createVNode as b, isVNode as re } from "vue";
|
|
2
|
+
import ce from "@v-c/resize-observer";
|
|
3
|
+
import se from "./Filler.js";
|
|
4
|
+
import fe from "./hooks/useDiffItem.js";
|
|
5
|
+
import ve from "./hooks/useFrameWheel.js";
|
|
6
|
+
import { useGetSize as he } from "./hooks/useGetSize.js";
|
|
7
|
+
import de from "./hooks/useHeights.js";
|
|
8
|
+
import me from "./hooks/useMobileTouchMove.js";
|
|
9
|
+
import ge from "./hooks/useScrollDrag.js";
|
|
10
|
+
import Se from "./Item.js";
|
|
11
|
+
import ye from "./ScrollBar.js";
|
|
12
|
+
import { getSpinSize as xe } from "./utils/scrollbarUtil.js";
|
|
13
|
+
function W(l) {
|
|
14
|
+
return typeof l == "function" || Object.prototype.toString.call(l) === "[object Object]" && !re(l);
|
|
15
|
+
}
|
|
16
|
+
const He = [], be = {
|
|
17
|
+
overflowY: "auto",
|
|
18
|
+
overflowAnchor: "none"
|
|
19
|
+
}, Ke = /* @__PURE__ */ ae({
|
|
20
|
+
name: "VirtualList",
|
|
21
|
+
props: {
|
|
22
|
+
prefixCls: {
|
|
23
|
+
type: String,
|
|
24
|
+
default: "vc-virtual-list"
|
|
25
|
+
},
|
|
26
|
+
data: {
|
|
27
|
+
type: Array
|
|
28
|
+
},
|
|
29
|
+
height: Number,
|
|
30
|
+
itemHeight: Number,
|
|
31
|
+
fullHeight: {
|
|
32
|
+
type: Boolean,
|
|
33
|
+
default: !0
|
|
34
|
+
},
|
|
35
|
+
itemKey: {
|
|
36
|
+
type: [String, Number, Function],
|
|
37
|
+
required: !0
|
|
38
|
+
},
|
|
39
|
+
component: {
|
|
40
|
+
type: String,
|
|
41
|
+
default: "div"
|
|
42
|
+
},
|
|
43
|
+
virtual: {
|
|
44
|
+
type: Boolean,
|
|
45
|
+
default: !0
|
|
46
|
+
},
|
|
47
|
+
onScroll: Function,
|
|
48
|
+
onVirtualScroll: Function,
|
|
49
|
+
onVisibleChange: Function,
|
|
50
|
+
innerProps: Object,
|
|
51
|
+
extraRender: Function
|
|
52
|
+
},
|
|
53
|
+
setup(l, {
|
|
54
|
+
expose: Y,
|
|
55
|
+
attrs: k,
|
|
56
|
+
slots: _
|
|
57
|
+
}) {
|
|
58
|
+
const h = (e) => typeof l.itemKey == "function" ? l.itemKey(e) : e?.[l.itemKey], [D, P, m, X] = de(h, void 0, void 0), o = y(() => l.data || He), M = y(() => !!(l.virtual !== !1 && l.height && l.itemHeight)), E = y(() => Object.values(m.maps).reduce((e, t) => e + t, 0)), d = y(() => {
|
|
59
|
+
const e = o.value;
|
|
60
|
+
return M.value && e && Math.max(l.itemHeight * e.length, E.value) > l.height;
|
|
61
|
+
}), R = r(), B = r(), F = r(), K = ue(), f = r(0), x = r(0), V = r(!1), j = r(0), L = r(0);
|
|
62
|
+
function g(e) {
|
|
63
|
+
let t;
|
|
64
|
+
typeof e == "function" ? t = e(f.value) : t = e;
|
|
65
|
+
const i = c.value - l.height, n = Math.max(0, Math.min(t, i || 0));
|
|
66
|
+
R.value && (R.value.scrollTop = n), f.value = n;
|
|
67
|
+
}
|
|
68
|
+
fe(o, h);
|
|
69
|
+
const c = r(0), S = r(0), H = r(0), C = r(void 0);
|
|
70
|
+
T([() => d.value, () => M.value, () => f.value, () => o.value, () => X.value, () => l.height], () => {
|
|
71
|
+
if (!M.value) {
|
|
72
|
+
c.value = 0, S.value = 0, H.value = o.value.length - 1, C.value = void 0;
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (!d.value) {
|
|
76
|
+
c.value = B.value?.offsetHeight || 0, S.value = 0, H.value = o.value.length - 1, C.value = void 0;
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
let e = 0, t, i, n;
|
|
80
|
+
const u = o.value.length, v = o.value;
|
|
81
|
+
for (let a = 0; a < u; a += 1) {
|
|
82
|
+
const s = v[a], w = h(s), N = m.get(w), A = e + (N === void 0 ? l.itemHeight : N);
|
|
83
|
+
A >= f.value && t === void 0 && (t = a, i = e), A > f.value + l.height && n === void 0 && (n = a), e = A;
|
|
84
|
+
}
|
|
85
|
+
t === void 0 && (t = 0, i = 0, n = Math.ceil(l.height / l.itemHeight)), n === void 0 && (n = o.value.length - 1), n = Math.min(n + 1, o.value.length - 1), c.value = e, S.value = t, H.value = n, C.value = i;
|
|
86
|
+
}, {
|
|
87
|
+
immediate: !0
|
|
88
|
+
}), T(() => c.value, () => {
|
|
89
|
+
const e = m.getRecord();
|
|
90
|
+
if (e.size === 1) {
|
|
91
|
+
const t = Array.from(e.keys())[0], i = e.get(t), n = o.value[S.value];
|
|
92
|
+
if (n && i === void 0 && h(n) === t) {
|
|
93
|
+
const a = m.get(t) - l.itemHeight;
|
|
94
|
+
g((s) => s + a);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
m.resetRecord();
|
|
98
|
+
});
|
|
99
|
+
const I = r({
|
|
100
|
+
width: 0,
|
|
101
|
+
height: l.height || 0
|
|
102
|
+
}), $ = (e) => {
|
|
103
|
+
I.value = {
|
|
104
|
+
width: e.offsetWidth,
|
|
105
|
+
height: e.offsetHeight
|
|
106
|
+
};
|
|
107
|
+
}, z = () => ({
|
|
108
|
+
x: x.value,
|
|
109
|
+
y: f.value
|
|
110
|
+
}), O = r(z()), q = (e) => {
|
|
111
|
+
if (l.onVirtualScroll) {
|
|
112
|
+
const t = {
|
|
113
|
+
...z(),
|
|
114
|
+
...e
|
|
115
|
+
};
|
|
116
|
+
(O.value.x !== t.x || O.value.y !== t.y) && (l.onVirtualScroll(t), O.value = t);
|
|
117
|
+
}
|
|
118
|
+
}, G = y(() => f.value === 0), U = y(() => f.value + l.height >= c.value), J = y(() => x.value === 0), Q = y(() => x.value + I.value.width >= L.value), Z = () => {
|
|
119
|
+
K.value?.delayHidden();
|
|
120
|
+
}, [p] = ve(
|
|
121
|
+
d,
|
|
122
|
+
G,
|
|
123
|
+
U,
|
|
124
|
+
J,
|
|
125
|
+
Q,
|
|
126
|
+
!1,
|
|
127
|
+
// horizontalScroll
|
|
128
|
+
(e, t) => {
|
|
129
|
+
t || g((i) => i + e);
|
|
130
|
+
}
|
|
131
|
+
);
|
|
132
|
+
me(d, R, (e, t, i, n) => e ? !1 : (g((u) => u + t), !0)), ge(d, R, (e) => {
|
|
133
|
+
g((t) => t + e);
|
|
134
|
+
});
|
|
135
|
+
const ee = (e, t) => {
|
|
136
|
+
t || g(e);
|
|
137
|
+
}, te = () => {
|
|
138
|
+
V.value = !0;
|
|
139
|
+
}, le = () => {
|
|
140
|
+
V.value = !1;
|
|
141
|
+
};
|
|
142
|
+
T([() => l.height, () => c.value, () => d.value, () => I.value.height], () => {
|
|
143
|
+
d.value && l.height && c.value && (j.value = xe(I.value.height, c.value));
|
|
144
|
+
}, {
|
|
145
|
+
immediate: !0
|
|
146
|
+
});
|
|
147
|
+
function ne(e) {
|
|
148
|
+
const i = e.currentTarget.scrollTop;
|
|
149
|
+
i !== f.value && g(i), l.onScroll?.(e), q();
|
|
150
|
+
}
|
|
151
|
+
Y({
|
|
152
|
+
nativeElement: F,
|
|
153
|
+
getScrollInfo: z,
|
|
154
|
+
scrollTo: (e) => {
|
|
155
|
+
if (e != null) {
|
|
156
|
+
if (typeof e == "number")
|
|
157
|
+
g(e);
|
|
158
|
+
else if (e && typeof e == "object") {
|
|
159
|
+
let t;
|
|
160
|
+
if ("left" in e && (x.value = e.left || 0), "top" in e)
|
|
161
|
+
t = e.top;
|
|
162
|
+
else if ("index" in e) {
|
|
163
|
+
const i = e.index || 0;
|
|
164
|
+
if (o.value[i]) {
|
|
165
|
+
let u = 0;
|
|
166
|
+
for (let v = 0; v < i; v += 1) {
|
|
167
|
+
const a = h(o.value[v]), s = m.get(a);
|
|
168
|
+
u += s === void 0 ? l.itemHeight : s;
|
|
169
|
+
}
|
|
170
|
+
t = u;
|
|
171
|
+
}
|
|
172
|
+
} else if ("key" in e) {
|
|
173
|
+
const i = o.value.findIndex((n) => h(n) === e.key);
|
|
174
|
+
if (i >= 0) {
|
|
175
|
+
let n = 0;
|
|
176
|
+
for (let u = 0; u < i; u += 1) {
|
|
177
|
+
const v = h(o.value[u]), a = m.get(v);
|
|
178
|
+
n += a === void 0 ? l.itemHeight : a;
|
|
179
|
+
}
|
|
180
|
+
t = n;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
t !== void 0 && g(t);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}), T([() => S.value, () => H.value, () => o.value], () => {
|
|
188
|
+
if (l.onVisibleChange) {
|
|
189
|
+
const e = o.value.slice(S.value, H.value + 1);
|
|
190
|
+
l.onVisibleChange(e, o.value);
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
const ie = () => {
|
|
194
|
+
const e = [], t = o.value, i = _.default;
|
|
195
|
+
if (!i)
|
|
196
|
+
return e;
|
|
197
|
+
for (let n = S.value; n <= H.value; n += 1) {
|
|
198
|
+
const u = t[n], v = h(u), a = i({
|
|
199
|
+
item: u,
|
|
200
|
+
index: n,
|
|
201
|
+
style: {},
|
|
202
|
+
offsetX: x.value
|
|
203
|
+
}), s = Array.isArray(a) ? a[0] : a;
|
|
204
|
+
s && e.push(b(Se, {
|
|
205
|
+
key: v,
|
|
206
|
+
setRef: (w) => D(u, w)
|
|
207
|
+
}, W(s) ? s : {
|
|
208
|
+
default: () => [s]
|
|
209
|
+
}));
|
|
210
|
+
}
|
|
211
|
+
return e;
|
|
212
|
+
}, oe = he(o, h, m, l.itemHeight);
|
|
213
|
+
return () => {
|
|
214
|
+
let e;
|
|
215
|
+
const t = {};
|
|
216
|
+
l.height && (t[l.fullHeight ? "height" : "maxHeight"] = `${l.height}px`, Object.assign(t, be), M.value && (t.overflowY = "hidden", L.value && (t.overflowX = "hidden"), V.value && (t.pointerEvents = "none")));
|
|
217
|
+
const i = l.extraRender?.({
|
|
218
|
+
start: S.value,
|
|
219
|
+
end: H.value,
|
|
220
|
+
virtual: d.value,
|
|
221
|
+
offsetX: x.value,
|
|
222
|
+
offsetY: C.value || 0,
|
|
223
|
+
rtl: !1,
|
|
224
|
+
getSize: oe.value
|
|
225
|
+
}), n = l.component;
|
|
226
|
+
return b("div", {
|
|
227
|
+
ref: F,
|
|
228
|
+
style: {
|
|
229
|
+
position: "relative",
|
|
230
|
+
...k.style
|
|
231
|
+
},
|
|
232
|
+
class: [l.prefixCls, k.class]
|
|
233
|
+
}, [b(ce, {
|
|
234
|
+
onResize: $
|
|
235
|
+
}, {
|
|
236
|
+
default: () => [b(n, {
|
|
237
|
+
class: `${l.prefixCls}-holder`,
|
|
238
|
+
style: t,
|
|
239
|
+
ref: R,
|
|
240
|
+
onScroll: ne,
|
|
241
|
+
onWheel: p,
|
|
242
|
+
onMouseenter: Z
|
|
243
|
+
}, {
|
|
244
|
+
default: () => [b(se, {
|
|
245
|
+
prefixCls: l.prefixCls,
|
|
246
|
+
height: c.value,
|
|
247
|
+
offsetX: x.value,
|
|
248
|
+
offsetY: C.value,
|
|
249
|
+
onInnerResize: P,
|
|
250
|
+
ref: B,
|
|
251
|
+
innerProps: l.innerProps,
|
|
252
|
+
rtl: !1,
|
|
253
|
+
extra: i
|
|
254
|
+
}, W(e = ie()) ? e : {
|
|
255
|
+
default: () => [e]
|
|
256
|
+
})]
|
|
257
|
+
})]
|
|
258
|
+
}), d.value && c.value > (l.height || 0) && b(ye, {
|
|
259
|
+
ref: K,
|
|
260
|
+
prefixCls: l.prefixCls,
|
|
261
|
+
scrollOffset: f.value,
|
|
262
|
+
scrollRange: c.value,
|
|
263
|
+
rtl: !1,
|
|
264
|
+
onScroll: ee,
|
|
265
|
+
onStartMove: te,
|
|
266
|
+
onStopMove: le,
|
|
267
|
+
spinSize: j.value,
|
|
268
|
+
containerSize: I.value.height,
|
|
269
|
+
showScrollBar: "optional"
|
|
270
|
+
}, null)]);
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
export {
|
|
275
|
+
Ke as default
|
|
276
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("vue");function L(e,c){return("touches"in e?e.touches[0]:e)[c?"pageX":"pageY"]-window[c?"scrollX":"scrollY"]}const C=t.defineComponent({name:"ScrollBar",props:{prefixCls:{type:String,required:!0},scrollOffset:{type:Number,required:!0},scrollRange:{type:Number,required:!0},rtl:{type:Boolean,default:!1},onScroll:{type:Function,required:!0},onStartMove:{type:Function,required:!0},onStopMove:{type:Function,required:!0},horizontal:{type:Boolean,default:!1},style:Object,thumbStyle:Object,spinSize:{type:Number,required:!0},containerSize:{type:Number,required:!0},showScrollBar:{type:[Boolean,String]}},setup(e,{expose:c}){const a=t.ref(!1),v=t.ref(null),d=t.ref(null),h=t.computed(()=>!e.rtl),g=t.shallowRef(),y=t.shallowRef(),f=t.ref(e.showScrollBar==="optional"?!0:e.showScrollBar);let i=null;const m=()=>{e.showScrollBar===!0||e.showScrollBar===!1||(i&&clearTimeout(i),f.value=!0,i=setTimeout(()=>{f.value=!1},3e3))},b=t.computed(()=>e.scrollRange-e.containerSize||0),M=t.computed(()=>e.containerSize-e.spinSize||0),u=t.computed(()=>e.scrollOffset===0||b.value===0?0:e.scrollOffset/b.value*M.value),w=t.shallowRef({top:u.value,dragging:a.value,pageY:v.value,startTop:d.value});t.watch([u,a,v,d],()=>{w.value={top:u.value,dragging:a.value,pageY:v.value,startTop:d.value}});const O=o=>{o.stopPropagation(),o.preventDefault()},S=o=>{a.value=!0,v.value=L(o,e.horizontal||!1),d.value=w.value.top,e.onStartMove(),o.stopPropagation(),o.preventDefault()};return t.onMounted(()=>{const o=r=>{r.preventDefault()},n=g.value,l=y.value;n&&l&&(n.addEventListener("touchstart",o,{passive:!1}),l.addEventListener("touchstart",S,{passive:!1}),t.onUnmounted(()=>{n.removeEventListener("touchstart",o),l.removeEventListener("touchstart",S)}))}),t.watch(a,o=>{if(o){let n=null;const l=x=>{const{dragging:B,pageY:q,startTop:$}=w.value;n&&cancelAnimationFrame(n);const z=g.value.getBoundingClientRect(),j=e.containerSize/(e.horizontal?z.width:z.height);if(B){const E=(L(x,e.horizontal||!1)-(q||0))*j;let p=$||0;!h.value&&e.horizontal?p-=E:p+=E;const R=b.value,T=M.value,Y=T?p/T:0;let s=Math.ceil(Y*R);s=Math.max(s,0),s=Math.min(s,R),n=requestAnimationFrame(()=>{e.onScroll(s,e.horizontal)})}},r=()=>{a.value=!1,e.onStopMove()};window.addEventListener("mousemove",l,{passive:!0}),window.addEventListener("touchmove",l,{passive:!0}),window.addEventListener("mouseup",r,{passive:!0}),window.addEventListener("touchend",r,{passive:!0}),t.onUnmounted(()=>{window.removeEventListener("mousemove",l),window.removeEventListener("touchmove",l),window.removeEventListener("mouseup",r),window.removeEventListener("touchend",r),n&&cancelAnimationFrame(n)})}}),t.watch(()=>e.scrollOffset,()=>{m()}),t.onUnmounted(()=>{i&&clearTimeout(i)}),c({delayHidden:m}),()=>{const o=`${e.prefixCls}-scrollbar`,n={position:"absolute",visibility:f.value?void 0:"hidden"},l={position:"absolute",borderRadius:"99px",background:"var(--vc-virtual-list-scrollbar-bg, rgba(0, 0, 0, 0.5))",cursor:"pointer",userSelect:"none"};return e.horizontal?(Object.assign(n,{height:"8px",left:0,right:0,bottom:0}),Object.assign(l,{height:"100%",width:`${e.spinSize}px`,[h.value?"left":"right"]:`${u.value}px`})):(Object.assign(n,{width:"8px",top:0,bottom:0,[h.value?"right":"left"]:0}),Object.assign(l,{width:"100%",height:`${e.spinSize}px`,top:`${u.value}px`})),t.createVNode("div",{ref:g,class:[o,{[`${o}-horizontal`]:e.horizontal,[`${o}-vertical`]:!e.horizontal,[`${o}-visible`]:f.value}],style:{...n,...e.style},onMousedown:O,onMousemove:m},[t.createVNode("div",{ref:y,class:[`${o}-thumb`,{[`${o}-thumb-moving`]:a.value}],style:{...l,...e.thumbStyle},onMousedown:S},null)])}}});exports.default=C;
|