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