@v-c/virtual-list 1.0.4 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/List.js CHANGED
@@ -9,7 +9,7 @@ import useScrollDrag from "./hooks/useScrollDrag.js";
9
9
  import useScrollTo from "./hooks/useScrollTo.js";
10
10
  import ScrollBar_default from "./ScrollBar.js";
11
11
  import { getSpinSize } from "./utils/scrollbarUtil.js";
12
- import { computed, createVNode, defineComponent, mergeProps, ref, shallowRef, toRaw, watch } from "vue";
12
+ import { computed, createVNode, defineComponent, mergeProps, ref, shallowRef, toRaw, unref, watch } from "vue";
13
13
  import ResizeObserver from "@v-c/resize-observer";
14
14
  import { pureAttrs } from "@v-c/util/dist/props-util";
15
15
  var EMPTY_DATA = [];
@@ -137,7 +137,7 @@ var List_default = /* @__PURE__ */ defineComponent({
137
137
  fillerOffset.value = 0;
138
138
  return;
139
139
  }
140
- if (heights.id === 0) {
140
+ if (unref(heights.id) === 0) {
141
141
  const safeItemHeight = itemHeight$1;
142
142
  const safeListHeight = height;
143
143
  const startIndex$1 = Math.max(0, Math.floor(offsetTop.value / safeItemHeight));
@@ -367,7 +367,7 @@ var List_default = /* @__PURE__ */ defineComponent({
367
367
  offsetX: offsetLeft.value,
368
368
  offsetY: fillerOffset.value || 0,
369
369
  rtl: isRTL.value,
370
- getSize: getSize.value
370
+ getSize
371
371
  });
372
372
  const Component = props.component;
373
373
  return createVNode("div", mergeProps({ "ref": containerRef }, pureAttrs(attrs), {
@@ -1,7 +1,4 @@
1
- import { ComputedRef, Ref } from 'vue';
2
- import { GetKey } from '../interface';
1
+ import { Ref } from 'vue';
2
+ import { GetKey, GetSize } from '../interface';
3
3
  import { default as CacheMap } from '../utils/CacheMap';
4
- export declare function useGetSize<T>(mergedData: Ref<T[]>, getKey: GetKey<T>, heights: CacheMap, itemHeight: Ref<number>): ComputedRef<(startKey: any, endKey?: any) => {
5
- top: number;
6
- bottom: number;
7
- }>;
4
+ export declare function useGetSize<T>(mergedData: Ref<T[]>, getKey: GetKey<T>, heights: CacheMap, itemHeight: Ref<number>): GetSize;
@@ -1,28 +1,36 @@
1
- import { computed } from "vue";
1
+ import { watch } from "vue";
2
2
  function useGetSize(mergedData, getKey, heights, itemHeight) {
3
- return computed(() => {
4
- return (startKey, endKey) => {
5
- let topIndex = 0;
6
- let bottomIndex = mergedData.value.length - 1;
7
- if (startKey !== void 0 && startKey !== null) topIndex = mergedData.value.findIndex((item) => getKey(item) === startKey);
8
- if (endKey !== void 0 && endKey !== null) bottomIndex = mergedData.value.findIndex((item) => getKey(item) === endKey);
9
- let top = 0;
10
- for (let i = 0; i < topIndex; i += 1) {
11
- const key = getKey(mergedData.value[i]);
12
- const cacheHeight = heights.get(key);
13
- top += cacheHeight === void 0 ? itemHeight.value : cacheHeight;
14
- }
15
- let bottom = 0;
16
- for (let i = mergedData.value.length - 1; i > bottomIndex; i -= 1) {
17
- const key = getKey(mergedData.value[i]);
18
- const cacheHeight = heights.get(key);
19
- bottom += cacheHeight === void 0 ? itemHeight.value : cacheHeight;
3
+ let key2Index = /* @__PURE__ */ new Map();
4
+ let bottomList = [];
5
+ watch([
6
+ mergedData,
7
+ () => heights.id.value,
8
+ itemHeight
9
+ ], () => {
10
+ key2Index = /* @__PURE__ */ new Map();
11
+ bottomList = [];
12
+ });
13
+ const getSize = (startKey, endKey = startKey) => {
14
+ let startIndex = key2Index.get(startKey);
15
+ let endIndex = key2Index.get(endKey);
16
+ if (startIndex === void 0 || endIndex === void 0) {
17
+ const dataLen = mergedData.value.length;
18
+ for (let i = bottomList.length; i < dataLen; i += 1) {
19
+ const item = mergedData.value[i];
20
+ const key = getKey(item);
21
+ key2Index.set(key, i);
22
+ const cacheHeight = heights.get(key) ?? itemHeight.value;
23
+ bottomList[i] = (bottomList[i - 1] || 0) + cacheHeight;
24
+ if (key === startKey) startIndex = i;
25
+ if (key === endKey) endIndex = i;
26
+ if (startIndex !== void 0 && endIndex !== void 0) break;
20
27
  }
21
- return {
22
- top,
23
- bottom
24
- };
28
+ }
29
+ return {
30
+ top: bottomList[startIndex - 1] || 0,
31
+ bottom: bottomList[endIndex]
25
32
  };
26
- });
33
+ };
34
+ return getSize;
27
35
  }
28
36
  export { useGetSize };
@@ -1,7 +1,7 @@
1
1
  import { Key } from '@v-c/util/dist/type';
2
2
  declare class CacheMap {
3
3
  maps: Record<string, number>;
4
- id: number;
4
+ id: import('vue').ShallowRef<number, number>;
5
5
  diffRecords: Map<Key, number>;
6
6
  constructor();
7
7
  set(key: Key, value: number): void;
@@ -1,6 +1,7 @@
1
+ import { shallowRef } from "vue";
1
2
  var CacheMap = class {
2
3
  maps;
3
- id = 0;
4
+ id = shallowRef(0);
4
5
  diffRecords = /* @__PURE__ */ new Map();
5
6
  constructor() {
6
7
  this.maps = Object.create(null);
@@ -8,7 +9,7 @@ var CacheMap = class {
8
9
  set(key, value) {
9
10
  this.diffRecords.set(key, this.maps[key]);
10
11
  this.maps[key] = value;
11
- this.id += 1;
12
+ this.id.value += 1;
12
13
  }
13
14
  get(key) {
14
15
  return this.maps[key];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@v-c/virtual-list",
3
3
  "type": "module",
4
- "version": "1.0.4",
4
+ "version": "1.0.6",
5
5
  "description": "Vue Virtual List Component",
6
6
  "author": "",
7
7
  "license": "MIT",
@@ -14,7 +14,7 @@
14
14
  ".": {
15
15
  "types": "./dist/index.d.ts",
16
16
  "import": "./dist/index.js",
17
- "require": "./dist/index.cjs"
17
+ "default": "./dist/index.js"
18
18
  },
19
19
  "./dist/*": "./dist/*",
20
20
  "./package.json": "./package.json"
@@ -31,8 +31,8 @@
31
31
  "vue": "^3.0.0"
32
32
  },
33
33
  "dependencies": {
34
- "@v-c/resize-observer": "^1.0.3",
35
- "@v-c/util": "^1.0.4"
34
+ "@v-c/resize-observer": "^1.0.8",
35
+ "@v-c/util": "^1.0.14"
36
36
  },
37
37
  "scripts": {
38
38
  "build": "vite build",
package/dist/Filler.cjs DELETED
@@ -1,54 +0,0 @@
1
- Object.defineProperties(exports, {
2
- __esModule: { value: true },
3
- [Symbol.toStringTag]: { value: "Module" }
4
- });
5
- const require_rolldown_runtime = require("./_virtual/rolldown_runtime.cjs");
6
- let vue = require("vue");
7
- let _v_c_resize_observer = require("@v-c/resize-observer");
8
- _v_c_resize_observer = require_rolldown_runtime.__toESM(_v_c_resize_observer);
9
- var Filler_default = /* @__PURE__ */ (0, vue.defineComponent)({
10
- name: "Filler",
11
- props: {
12
- prefixCls: String,
13
- height: Number,
14
- offsetY: Number,
15
- offsetX: Number,
16
- scrollWidth: Number,
17
- onInnerResize: Function,
18
- innerProps: Object,
19
- rtl: Boolean,
20
- extra: Object
21
- },
22
- setup(props, { slots }) {
23
- return () => {
24
- let outerStyle = {};
25
- let innerStyle = {
26
- display: "flex",
27
- flexDirection: "column"
28
- };
29
- if (props.offsetY !== void 0) {
30
- outerStyle = {
31
- height: `${props.height}px`,
32
- position: "relative",
33
- overflow: "hidden"
34
- };
35
- innerStyle = {
36
- ...innerStyle,
37
- transform: `translateY(${props.offsetY}px)`,
38
- [props.rtl ? "marginRight" : "marginLeft"]: `-${props.offsetX || 0}px`,
39
- position: "absolute",
40
- left: 0,
41
- right: 0,
42
- top: 0
43
- };
44
- }
45
- return (0, vue.createVNode)("div", { "style": outerStyle }, [(0, vue.createVNode)(_v_c_resize_observer.default, { "onResize": ({ offsetHeight }) => {
46
- if (offsetHeight && props.onInnerResize) props.onInnerResize();
47
- } }, { default: () => [(0, vue.createVNode)("div", (0, vue.mergeProps)({
48
- "style": innerStyle,
49
- "class": props.prefixCls ? `${props.prefixCls}-holder-inner` : void 0
50
- }, props.innerProps), [slots.default?.(), props.extra])] })]);
51
- };
52
- }
53
- });
54
- exports.default = Filler_default;
package/dist/Item.cjs DELETED
@@ -1,29 +0,0 @@
1
- Object.defineProperties(exports, {
2
- __esModule: { value: true },
3
- [Symbol.toStringTag]: { value: "Module" }
4
- });
5
- const require_rolldown_runtime = require("./_virtual/rolldown_runtime.cjs");
6
- let vue = require("vue");
7
- let _v_c_util_dist_props_util = require("@v-c/util/dist/props-util");
8
- var Item_default = /* @__PURE__ */ (0, vue.defineComponent)({
9
- name: "Item",
10
- props: { setRef: {
11
- type: Function,
12
- required: true
13
- } },
14
- setup(props, { slots }) {
15
- const currentElement = (0, vue.shallowRef)(null);
16
- const refFunc = (node) => {
17
- if (currentElement.value !== node) {
18
- currentElement.value = node;
19
- props.setRef(node);
20
- }
21
- };
22
- return () => {
23
- const child = (0, _v_c_util_dist_props_util.filterEmpty)(slots.default?.() ?? [])[0];
24
- if (!child) return null;
25
- return (0, vue.cloneVNode)(child, { ref: refFunc });
26
- };
27
- }
28
- });
29
- exports.default = Item_default;
package/dist/List.cjs DELETED
@@ -1,445 +0,0 @@
1
- Object.defineProperties(exports, {
2
- __esModule: { value: true },
3
- [Symbol.toStringTag]: { value: "Module" }
4
- });
5
- const require_rolldown_runtime = require("./_virtual/rolldown_runtime.cjs");
6
- const require_Filler = require("./Filler.cjs");
7
- const require_useChildren = require("./hooks/useChildren.cjs");
8
- const require_useDiffItem = require("./hooks/useDiffItem.cjs");
9
- const require_useFrameWheel = require("./hooks/useFrameWheel.cjs");
10
- const require_useGetSize = require("./hooks/useGetSize.cjs");
11
- const require_useHeights = require("./hooks/useHeights.cjs");
12
- const require_useMobileTouchMove = require("./hooks/useMobileTouchMove.cjs");
13
- const require_useScrollDrag = require("./hooks/useScrollDrag.cjs");
14
- const require_useScrollTo = require("./hooks/useScrollTo.cjs");
15
- const require_ScrollBar = require("./ScrollBar.cjs");
16
- const require_scrollbarUtil = require("./utils/scrollbarUtil.cjs");
17
- let vue = require("vue");
18
- let _v_c_resize_observer = require("@v-c/resize-observer");
19
- _v_c_resize_observer = require_rolldown_runtime.__toESM(_v_c_resize_observer);
20
- let _v_c_util_dist_props_util = require("@v-c/util/dist/props-util");
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
- let itemKeyProp = props.itemKey;
73
- (0, vue.watch)(() => props.itemKey, (val) => {
74
- itemKeyProp = val;
75
- });
76
- const getKey = (item) => {
77
- const _itemKey = itemKeyProp;
78
- if (typeof _itemKey === "function") return _itemKey(item);
79
- return item?.[_itemKey];
80
- };
81
- const [setInstanceRef, collectHeight, heights, heightUpdatedMark] = require_useHeights.default(getKey, void 0, void 0);
82
- const mergedData = (0, vue.shallowRef)(props?.data || EMPTY_DATA);
83
- (0, vue.watch)(() => props.data, () => {
84
- mergedData.value = props?.data || EMPTY_DATA;
85
- });
86
- const useVirtual = (0, vue.computed)(() => !!(props.virtual !== false && props.height && props.itemHeight));
87
- const inVirtual = (0, vue.computed)(() => {
88
- const data = mergedData.value;
89
- return useVirtual.value && data && (props.itemHeight * data.length > props.height || !!props.scrollWidth);
90
- });
91
- const componentRef = (0, vue.ref)();
92
- const fillerInnerRef = (0, vue.ref)();
93
- const containerRef = (0, vue.ref)();
94
- const verticalScrollBarRef = (0, vue.shallowRef)();
95
- const horizontalScrollBarRef = (0, vue.shallowRef)();
96
- const offsetTop = (0, vue.ref)(0);
97
- const offsetLeft = (0, vue.ref)(0);
98
- const scrollMoving = (0, vue.ref)(false);
99
- const verticalScrollBarSpinSize = (0, vue.ref)(0);
100
- const horizontalScrollBarSpinSize = (0, vue.ref)(0);
101
- const contentScrollWidth = (0, vue.ref)(props.scrollWidth || 0);
102
- const scrollHeight = (0, vue.ref)(0);
103
- const start = (0, vue.ref)(0);
104
- const end = (0, vue.ref)(0);
105
- const fillerOffset = (0, vue.ref)(void 0);
106
- function syncScrollTop(newTop) {
107
- let value;
108
- if (typeof newTop === "function") value = newTop(offsetTop.value);
109
- else value = newTop;
110
- const maxScrollHeight = scrollHeight.value - props.height;
111
- const alignedTop = Math.max(0, Math.min(value, maxScrollHeight || 0));
112
- if (componentRef.value) componentRef.value.scrollTop = alignedTop;
113
- offsetTop.value = alignedTop;
114
- }
115
- (0, vue.watch)([
116
- inVirtual,
117
- useVirtual,
118
- offsetTop,
119
- mergedData,
120
- heightUpdatedMark,
121
- () => props.height
122
- ], () => {
123
- if (!useVirtual.value) {
124
- scrollHeight.value = 0;
125
- start.value = 0;
126
- end.value = mergedData.value.length - 1;
127
- fillerOffset.value = void 0;
128
- return;
129
- }
130
- if (!inVirtual.value) {
131
- scrollHeight.value = fillerInnerRef.value?.offsetHeight || 0;
132
- start.value = 0;
133
- end.value = mergedData.value.length - 1;
134
- fillerOffset.value = void 0;
135
- return;
136
- }
137
- const { itemHeight: itemHeight$1, height } = props;
138
- const dataLen = mergedData.value.length;
139
- if (!dataLen) {
140
- scrollHeight.value = 0;
141
- start.value = 0;
142
- end.value = -1;
143
- fillerOffset.value = 0;
144
- return;
145
- }
146
- if (heights.id === 0) {
147
- const safeItemHeight = itemHeight$1;
148
- const safeListHeight = height;
149
- const startIndex$1 = Math.max(0, Math.floor(offsetTop.value / safeItemHeight));
150
- const startOffset$1 = startIndex$1 * safeItemHeight;
151
- let endIndex$1 = startIndex$1 + Math.ceil(safeListHeight / safeItemHeight);
152
- endIndex$1 = Math.min(endIndex$1 + 1, dataLen - 1);
153
- scrollHeight.value = dataLen * safeItemHeight;
154
- start.value = startIndex$1;
155
- end.value = endIndex$1;
156
- fillerOffset.value = startOffset$1;
157
- return;
158
- }
159
- let itemTop = 0;
160
- let startIndex;
161
- let startOffset;
162
- let endIndex;
163
- const data = (0, vue.toRaw)(mergedData.value);
164
- const _offsetTop = offsetTop.value;
165
- for (let i = 0; i < dataLen; i += 1) {
166
- const item = data[i];
167
- const key = getKey(item);
168
- const cacheHeight = heights.get(key);
169
- const currentItemBottom = itemTop + (cacheHeight === void 0 ? itemHeight$1 : cacheHeight);
170
- if (currentItemBottom >= _offsetTop && startIndex === void 0) {
171
- startIndex = i;
172
- startOffset = itemTop;
173
- }
174
- if (currentItemBottom > _offsetTop + height && endIndex === void 0) endIndex = i;
175
- itemTop = currentItemBottom;
176
- }
177
- if (startIndex === void 0) {
178
- startIndex = 0;
179
- startOffset = 0;
180
- endIndex = Math.ceil(height / itemHeight$1);
181
- }
182
- if (endIndex === void 0) endIndex = data.length - 1;
183
- endIndex = Math.min(endIndex + 1, data.length - 1);
184
- scrollHeight.value = itemTop;
185
- start.value = startIndex;
186
- end.value = endIndex;
187
- fillerOffset.value = startOffset;
188
- }, { immediate: true });
189
- (0, vue.watch)(scrollHeight, () => {
190
- const changedRecord = heights.getRecord();
191
- if (changedRecord.size === 1) {
192
- const recordKey = Array.from(changedRecord.keys())[0];
193
- const prevCacheHeight = changedRecord.get(recordKey);
194
- const startItem = mergedData.value[start.value];
195
- if (startItem && prevCacheHeight === void 0) {
196
- if (getKey(startItem) === recordKey) {
197
- const diffHeight = heights.get(recordKey) - props.itemHeight;
198
- syncScrollTop((ori) => ori + diffHeight);
199
- }
200
- }
201
- }
202
- if (useVirtual.value && props.height) {
203
- const maxScrollTop = Math.max(0, scrollHeight.value - props.height);
204
- if (offsetTop.value > maxScrollTop) syncScrollTop(maxScrollTop);
205
- }
206
- heights.resetRecord();
207
- });
208
- const size = (0, vue.ref)({
209
- width: 0,
210
- height: props.height || 0
211
- });
212
- const onHolderResize = (sizeInfo) => {
213
- size.value = {
214
- width: sizeInfo.offsetWidth,
215
- height: sizeInfo.offsetHeight
216
- };
217
- contentScrollWidth.value = props.scrollWidth ?? sizeInfo.offsetWidth;
218
- };
219
- const isRTL = (0, vue.computed)(() => props.direction === "rtl");
220
- const getVirtualScrollInfo = () => ({
221
- x: isRTL.value ? -offsetLeft.value : offsetLeft.value,
222
- y: offsetTop.value
223
- });
224
- const lastVirtualScrollInfo = (0, vue.ref)(getVirtualScrollInfo());
225
- const triggerScroll = (params) => {
226
- if (props.onVirtualScroll) {
227
- const nextInfo = {
228
- ...getVirtualScrollInfo(),
229
- ...params
230
- };
231
- if (lastVirtualScrollInfo.value.x !== nextInfo.x || lastVirtualScrollInfo.value.y !== nextInfo.y) {
232
- props.onVirtualScroll(nextInfo);
233
- lastVirtualScrollInfo.value = nextInfo;
234
- }
235
- }
236
- };
237
- const horizontalRange = (0, vue.computed)(() => Math.max(0, (contentScrollWidth.value || 0) - size.value.width));
238
- const isScrollAtTop = (0, vue.computed)(() => offsetTop.value === 0);
239
- const isScrollAtBottom = (0, vue.computed)(() => offsetTop.value + props.height >= scrollHeight.value);
240
- const isScrollAtLeft = (0, vue.computed)(() => offsetLeft.value === 0);
241
- const isScrollAtRight = (0, vue.computed)(() => offsetLeft.value >= horizontalRange.value);
242
- const keepInHorizontalRange = (nextOffsetLeft) => {
243
- const max = horizontalRange.value;
244
- return Math.max(0, Math.min(nextOffsetLeft, max));
245
- };
246
- const delayHideScrollBar = () => {
247
- verticalScrollBarRef.value?.delayHidden();
248
- horizontalScrollBarRef.value?.delayHidden();
249
- };
250
- const [onWheel] = require_useFrameWheel.default(inVirtual, isScrollAtTop, isScrollAtBottom, isScrollAtLeft, isScrollAtRight, horizontalRange.value > 0, (offsetY, isHorizontal) => {
251
- if (isHorizontal) {
252
- const aligned = keepInHorizontalRange(isRTL.value ? offsetLeft.value - offsetY : offsetLeft.value + offsetY);
253
- offsetLeft.value = aligned;
254
- triggerScroll({ x: isRTL.value ? -aligned : aligned });
255
- } else syncScrollTop((top) => top + offsetY);
256
- });
257
- require_useMobileTouchMove.default(inVirtual, componentRef, (isHorizontal, offset, _smoothOffset, _e) => {
258
- if (isHorizontal) {
259
- const aligned = keepInHorizontalRange(isRTL.value ? offsetLeft.value - offset : offsetLeft.value + offset);
260
- offsetLeft.value = aligned;
261
- triggerScroll({ x: isRTL.value ? -aligned : aligned });
262
- return true;
263
- } else {
264
- syncScrollTop((top) => top + offset);
265
- return true;
266
- }
267
- });
268
- require_useScrollDrag.default(inVirtual, componentRef, (offset) => {
269
- syncScrollTop((top) => top + offset);
270
- });
271
- const onScrollBar = (newScrollOffset, horizontal) => {
272
- const newOffset = newScrollOffset;
273
- if (horizontal) {
274
- offsetLeft.value = newOffset;
275
- triggerScroll({ x: isRTL.value ? -newOffset : newOffset });
276
- } else syncScrollTop(newOffset);
277
- };
278
- const onScrollbarStartMove = () => {
279
- scrollMoving.value = true;
280
- };
281
- const onScrollbarStopMove = () => {
282
- scrollMoving.value = false;
283
- };
284
- require_useDiffItem.default(mergedData, getKey);
285
- (0, vue.watch)([
286
- () => props.height,
287
- scrollHeight,
288
- inVirtual,
289
- () => size.value.height
290
- ], () => {
291
- if (inVirtual.value && props.height && scrollHeight.value) verticalScrollBarSpinSize.value = require_scrollbarUtil.getSpinSize(size.value.height, scrollHeight.value);
292
- }, { immediate: true });
293
- (0, vue.watch)([() => size.value.width, contentScrollWidth], () => {
294
- if (inVirtual.value && contentScrollWidth.value) horizontalScrollBarSpinSize.value = require_scrollbarUtil.getSpinSize(size.value.width, contentScrollWidth.value);
295
- }, { immediate: true });
296
- (0, vue.watch)(() => props.scrollWidth, (val) => {
297
- contentScrollWidth.value = val ?? size.value.width;
298
- offsetLeft.value = keepInHorizontalRange(offsetLeft.value);
299
- }, { immediate: true });
300
- function onFallbackScroll(e) {
301
- const newScrollTop = e.currentTarget.scrollTop;
302
- if (!useVirtual.value || !inVirtual.value) offsetTop.value = newScrollTop;
303
- else if (newScrollTop !== offsetTop.value) syncScrollTop(newScrollTop);
304
- props.onScroll?.(e);
305
- triggerScroll();
306
- }
307
- const [scrollTo, getTotalHeight] = require_useScrollTo.default(componentRef, mergedData, heights, itemHeight, getKey, () => collectHeight(true), (newTop) => {
308
- const totalHeight = getTotalHeight();
309
- const maxScrollHeight = Math.max(scrollHeight.value, totalHeight) - props.height;
310
- const alignedTop = Math.max(0, Math.min(newTop, maxScrollHeight || 0));
311
- if (componentRef.value) componentRef.value.scrollTop = alignedTop;
312
- offsetTop.value = alignedTop;
313
- }, delayHideScrollBar);
314
- expose({
315
- nativeElement: containerRef,
316
- getScrollInfo: getVirtualScrollInfo,
317
- scrollTo: (config) => {
318
- function isPosScroll(arg) {
319
- return arg && typeof arg === "object" && ("left" in arg || "top" in arg);
320
- }
321
- if (isPosScroll(config)) {
322
- if (config.left !== void 0) offsetLeft.value = keepInHorizontalRange(config.left);
323
- scrollTo(config.top);
324
- } else scrollTo(config);
325
- }
326
- });
327
- (0, vue.watch)([
328
- start,
329
- end,
330
- mergedData
331
- ], () => {
332
- if (props.onVisibleChange) {
333
- const renderList = mergedData.value.slice(start.value, end.value + 1);
334
- props.onVisibleChange(renderList, mergedData.value);
335
- }
336
- }, { flush: "post" });
337
- const getSize = require_useGetSize.useGetSize(mergedData, getKey, heights, itemHeight);
338
- const listChildren = require_useChildren.default(mergedData, start, end, contentScrollWidth, offsetLeft, setInstanceRef, (item, index, props$1) => slots.default?.({
339
- item,
340
- index,
341
- ...props$1
342
- }), { getKey });
343
- return () => {
344
- const componentStyle = {};
345
- const getHolderSizeStyle = (style) => {
346
- if (!style) return {};
347
- if (Array.isArray(style)) return style.reduce((acc, item) => Object.assign(acc, getHolderSizeStyle(item)), {});
348
- if (typeof style === "object") {
349
- const { height, maxHeight } = style;
350
- const sizeStyle = {};
351
- if (height !== void 0) sizeStyle.height = height;
352
- if (maxHeight !== void 0) sizeStyle.maxHeight = maxHeight;
353
- return sizeStyle;
354
- }
355
- return {};
356
- };
357
- if (props.height) {
358
- componentStyle[props.fullHeight ? "height" : "maxHeight"] = `${props.height}px`;
359
- Object.assign(componentStyle, ScrollStyle);
360
- if (inVirtual.value) {
361
- componentStyle.overflowY = "hidden";
362
- if (horizontalRange.value > 0) componentStyle.overflowX = "hidden";
363
- if (scrollMoving.value) componentStyle.pointerEvents = "none";
364
- }
365
- } else {
366
- const holderSizeStyle = getHolderSizeStyle(attrs.style);
367
- if (holderSizeStyle.height !== void 0 || holderSizeStyle.maxHeight !== void 0) Object.assign(componentStyle, holderSizeStyle, ScrollStyle);
368
- }
369
- const extraContent = props.extraRender?.({
370
- start: start.value,
371
- end: end.value,
372
- virtual: inVirtual.value,
373
- offsetX: offsetLeft.value,
374
- offsetY: fillerOffset.value || 0,
375
- rtl: isRTL.value,
376
- getSize: getSize.value
377
- });
378
- const Component = props.component;
379
- return (0, vue.createVNode)("div", (0, vue.mergeProps)({ "ref": containerRef }, (0, _v_c_util_dist_props_util.pureAttrs)(attrs), {
380
- "style": {
381
- position: "relative",
382
- ...attrs.style
383
- },
384
- "dir": isRTL.value ? "rtl" : void 0,
385
- "class": [
386
- props.prefixCls,
387
- { [`${props.prefixCls}-rtl`]: isRTL.value },
388
- attrs.class
389
- ]
390
- }), [
391
- (0, vue.createVNode)(_v_c_resize_observer.default, { "onResize": onHolderResize }, { default: () => [(0, vue.createVNode)(Component, {
392
- "class": `${props.prefixCls}-holder`,
393
- "style": componentStyle,
394
- "ref": componentRef,
395
- "onScroll": onFallbackScroll,
396
- "onWheel": onWheel,
397
- "onMouseenter": delayHideScrollBar
398
- }, { default: () => [(0, vue.createVNode)(require_Filler.default, {
399
- "prefixCls": props.prefixCls,
400
- "height": scrollHeight.value,
401
- "offsetX": offsetLeft.value,
402
- "offsetY": fillerOffset.value,
403
- "scrollWidth": contentScrollWidth.value,
404
- "onInnerResize": collectHeight,
405
- "ref": fillerInnerRef,
406
- "innerProps": props.innerProps,
407
- "rtl": isRTL.value,
408
- "extra": extraContent
409
- }, { default: () => [listChildren.value] })] })] }),
410
- inVirtual.value && scrollHeight.value > (props.height || 0) && (0, vue.createVNode)(require_ScrollBar.default, {
411
- "ref": verticalScrollBarRef,
412
- "prefixCls": props.prefixCls,
413
- "scrollOffset": offsetTop.value,
414
- "scrollRange": scrollHeight.value,
415
- "rtl": isRTL.value,
416
- "onScroll": onScrollBar,
417
- "onStartMove": onScrollbarStartMove,
418
- "onStopMove": onScrollbarStopMove,
419
- "spinSize": verticalScrollBarSpinSize.value,
420
- "containerSize": size.value.height,
421
- "showScrollBar": props.showScrollBar,
422
- "style": props.styles?.verticalScrollBar,
423
- "thumbStyle": props.styles?.verticalScrollBarThumb
424
- }, null),
425
- inVirtual.value && contentScrollWidth.value > size.value.width && (0, vue.createVNode)(require_ScrollBar.default, {
426
- "ref": horizontalScrollBarRef,
427
- "prefixCls": props.prefixCls,
428
- "scrollOffset": offsetLeft.value,
429
- "scrollRange": contentScrollWidth.value,
430
- "rtl": isRTL.value,
431
- "onScroll": onScrollBar,
432
- "onStartMove": onScrollbarStartMove,
433
- "onStopMove": onScrollbarStopMove,
434
- "spinSize": horizontalScrollBarSpinSize.value,
435
- "containerSize": size.value.width,
436
- "horizontal": true,
437
- "showScrollBar": props.showScrollBar,
438
- "style": props.styles?.horizontalScrollBar,
439
- "thumbStyle": props.styles?.horizontalScrollBarThumb
440
- }, null)
441
- ]);
442
- };
443
- }
444
- });
445
- exports.default = List_default;