@v-c/virtual-list 1.0.3 → 1.0.4
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/Filler.cjs +7 -4
- package/dist/Item.cjs +6 -3
- package/dist/List.cjs +64 -23
- package/dist/List.js +56 -18
- package/dist/ScrollBar.cjs +9 -6
- package/dist/hooks/useChildren.cjs +4 -1
- package/dist/hooks/useDiffItem.cjs +4 -1
- package/dist/hooks/useFrameWheel.cjs +4 -1
- package/dist/hooks/useGetSize.cjs +1 -0
- package/dist/hooks/useHeights.cjs +23 -2
- package/dist/hooks/useHeights.js +20 -2
- package/dist/hooks/useMobileTouchMove.cjs +4 -1
- package/dist/hooks/useOriginScroll.cjs +4 -1
- package/dist/hooks/useScrollDrag.cjs +4 -1
- package/dist/hooks/useScrollTo.cjs +6 -3
- package/dist/index.cjs +4 -1
- package/dist/interface.cjs +1 -0
- package/dist/utils/CacheMap.cjs +4 -1
- package/dist/utils/algorithmUtil.cjs +1 -0
- package/dist/utils/isFirefox.cjs +4 -1
- package/dist/utils/scrollbarUtil.cjs +1 -0
- package/package.json +3 -3
package/dist/Filler.cjs
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
Object.
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
2
5
|
const require_rolldown_runtime = require("./_virtual/rolldown_runtime.cjs");
|
|
3
6
|
let vue = require("vue");
|
|
4
|
-
let
|
|
5
|
-
|
|
7
|
+
let _v_c_resize_observer = require("@v-c/resize-observer");
|
|
8
|
+
_v_c_resize_observer = require_rolldown_runtime.__toESM(_v_c_resize_observer);
|
|
6
9
|
var Filler_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
7
10
|
name: "Filler",
|
|
8
11
|
props: {
|
|
@@ -39,7 +42,7 @@ var Filler_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
39
42
|
top: 0
|
|
40
43
|
};
|
|
41
44
|
}
|
|
42
|
-
return (0, vue.createVNode)("div", { "style": outerStyle }, [(0, vue.createVNode)(
|
|
45
|
+
return (0, vue.createVNode)("div", { "style": outerStyle }, [(0, vue.createVNode)(_v_c_resize_observer.default, { "onResize": ({ offsetHeight }) => {
|
|
43
46
|
if (offsetHeight && props.onInnerResize) props.onInnerResize();
|
|
44
47
|
} }, { default: () => [(0, vue.createVNode)("div", (0, vue.mergeProps)({
|
|
45
48
|
"style": innerStyle,
|
package/dist/Item.cjs
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
Object.
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
2
5
|
const require_rolldown_runtime = require("./_virtual/rolldown_runtime.cjs");
|
|
3
6
|
let vue = require("vue");
|
|
4
|
-
let
|
|
7
|
+
let _v_c_util_dist_props_util = require("@v-c/util/dist/props-util");
|
|
5
8
|
var Item_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
6
9
|
name: "Item",
|
|
7
10
|
props: { setRef: {
|
|
@@ -17,7 +20,7 @@ var Item_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
17
20
|
}
|
|
18
21
|
};
|
|
19
22
|
return () => {
|
|
20
|
-
const child = (0,
|
|
23
|
+
const child = (0, _v_c_util_dist_props_util.filterEmpty)(slots.default?.() ?? [])[0];
|
|
21
24
|
if (!child) return null;
|
|
22
25
|
return (0, vue.cloneVNode)(child, { ref: refFunc });
|
|
23
26
|
};
|
package/dist/List.cjs
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
Object.
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
2
5
|
const require_rolldown_runtime = require("./_virtual/rolldown_runtime.cjs");
|
|
3
6
|
const require_Filler = require("./Filler.cjs");
|
|
4
7
|
const require_useChildren = require("./hooks/useChildren.cjs");
|
|
@@ -12,9 +15,9 @@ const require_useScrollTo = require("./hooks/useScrollTo.cjs");
|
|
|
12
15
|
const require_ScrollBar = require("./ScrollBar.cjs");
|
|
13
16
|
const require_scrollbarUtil = require("./utils/scrollbarUtil.cjs");
|
|
14
17
|
let vue = require("vue");
|
|
15
|
-
let
|
|
16
|
-
|
|
17
|
-
let
|
|
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");
|
|
18
21
|
var EMPTY_DATA = [];
|
|
19
22
|
var ScrollStyle = {
|
|
20
23
|
overflowY: "auto",
|
|
@@ -66,10 +69,12 @@ var List_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
66
69
|
inheritAttrs: false,
|
|
67
70
|
setup(props, { expose, attrs, slots }) {
|
|
68
71
|
const itemHeight = (0, vue.computed)(() => props.itemHeight);
|
|
69
|
-
|
|
72
|
+
let itemKeyProp = props.itemKey;
|
|
73
|
+
(0, vue.watch)(() => props.itemKey, (val) => {
|
|
74
|
+
itemKeyProp = val;
|
|
75
|
+
});
|
|
70
76
|
const getKey = (item) => {
|
|
71
|
-
|
|
72
|
-
const _itemKey = itemKey.value;
|
|
77
|
+
const _itemKey = itemKeyProp;
|
|
73
78
|
if (typeof _itemKey === "function") return _itemKey(item);
|
|
74
79
|
return item?.[_itemKey];
|
|
75
80
|
};
|
|
@@ -79,10 +84,9 @@ var List_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
79
84
|
mergedData.value = props?.data || EMPTY_DATA;
|
|
80
85
|
});
|
|
81
86
|
const useVirtual = (0, vue.computed)(() => !!(props.virtual !== false && props.height && props.itemHeight));
|
|
82
|
-
const containerHeight = (0, vue.computed)(() => Object.values(heights.maps).reduce((total, curr) => total + curr, 0));
|
|
83
87
|
const inVirtual = (0, vue.computed)(() => {
|
|
84
88
|
const data = mergedData.value;
|
|
85
|
-
return useVirtual.value && data && (
|
|
89
|
+
return useVirtual.value && data && (props.itemHeight * data.length > props.height || !!props.scrollWidth);
|
|
86
90
|
});
|
|
87
91
|
const componentRef = (0, vue.ref)();
|
|
88
92
|
const fillerInnerRef = (0, vue.ref)();
|
|
@@ -131,35 +135,52 @@ var List_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
131
135
|
return;
|
|
132
136
|
}
|
|
133
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
|
+
}
|
|
134
159
|
let itemTop = 0;
|
|
135
160
|
let startIndex;
|
|
136
161
|
let startOffset;
|
|
137
162
|
let endIndex;
|
|
138
|
-
const dataLen = mergedData.value.length;
|
|
139
163
|
const data = (0, vue.toRaw)(mergedData.value);
|
|
164
|
+
const _offsetTop = offsetTop.value;
|
|
140
165
|
for (let i = 0; i < dataLen; i += 1) {
|
|
141
166
|
const item = data[i];
|
|
142
167
|
const key = getKey(item);
|
|
143
168
|
const cacheHeight = heights.get(key);
|
|
144
169
|
const currentItemBottom = itemTop + (cacheHeight === void 0 ? itemHeight$1 : cacheHeight);
|
|
145
|
-
if (currentItemBottom >=
|
|
170
|
+
if (currentItemBottom >= _offsetTop && startIndex === void 0) {
|
|
146
171
|
startIndex = i;
|
|
147
172
|
startOffset = itemTop;
|
|
148
173
|
}
|
|
149
|
-
if (currentItemBottom >
|
|
174
|
+
if (currentItemBottom > _offsetTop + height && endIndex === void 0) endIndex = i;
|
|
150
175
|
itemTop = currentItemBottom;
|
|
151
|
-
if (startIndex !== void 0 && endIndex !== void 0) {
|
|
152
|
-
itemTop = currentItemBottom + (dataLen - 1 - i) * itemHeight$1;
|
|
153
|
-
break;
|
|
154
|
-
}
|
|
155
176
|
}
|
|
156
177
|
if (startIndex === void 0) {
|
|
157
178
|
startIndex = 0;
|
|
158
179
|
startOffset = 0;
|
|
159
180
|
endIndex = Math.ceil(height / itemHeight$1);
|
|
160
181
|
}
|
|
161
|
-
if (endIndex === void 0) endIndex =
|
|
162
|
-
endIndex = Math.min(endIndex + 1,
|
|
182
|
+
if (endIndex === void 0) endIndex = data.length - 1;
|
|
183
|
+
endIndex = Math.min(endIndex + 1, data.length - 1);
|
|
163
184
|
scrollHeight.value = itemTop;
|
|
164
185
|
start.value = startIndex;
|
|
165
186
|
end.value = endIndex;
|
|
@@ -178,6 +199,10 @@ var List_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
178
199
|
}
|
|
179
200
|
}
|
|
180
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
|
+
}
|
|
181
206
|
heights.resetRecord();
|
|
182
207
|
});
|
|
183
208
|
const size = (0, vue.ref)({
|
|
@@ -274,7 +299,8 @@ var List_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
274
299
|
}, { immediate: true });
|
|
275
300
|
function onFallbackScroll(e) {
|
|
276
301
|
const newScrollTop = e.currentTarget.scrollTop;
|
|
277
|
-
if (
|
|
302
|
+
if (!useVirtual.value || !inVirtual.value) offsetTop.value = newScrollTop;
|
|
303
|
+
else if (newScrollTop !== offsetTop.value) syncScrollTop(newScrollTop);
|
|
278
304
|
props.onScroll?.(e);
|
|
279
305
|
triggerScroll();
|
|
280
306
|
}
|
|
@@ -307,7 +333,7 @@ var List_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
307
333
|
const renderList = mergedData.value.slice(start.value, end.value + 1);
|
|
308
334
|
props.onVisibleChange(renderList, mergedData.value);
|
|
309
335
|
}
|
|
310
|
-
});
|
|
336
|
+
}, { flush: "post" });
|
|
311
337
|
const getSize = require_useGetSize.useGetSize(mergedData, getKey, heights, itemHeight);
|
|
312
338
|
const listChildren = require_useChildren.default(mergedData, start, end, contentScrollWidth, offsetLeft, setInstanceRef, (item, index, props$1) => slots.default?.({
|
|
313
339
|
item,
|
|
@@ -316,14 +342,29 @@ var List_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
316
342
|
}), { getKey });
|
|
317
343
|
return () => {
|
|
318
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
|
+
};
|
|
319
357
|
if (props.height) {
|
|
320
358
|
componentStyle[props.fullHeight ? "height" : "maxHeight"] = `${props.height}px`;
|
|
321
359
|
Object.assign(componentStyle, ScrollStyle);
|
|
322
|
-
if (
|
|
360
|
+
if (inVirtual.value) {
|
|
323
361
|
componentStyle.overflowY = "hidden";
|
|
324
362
|
if (horizontalRange.value > 0) componentStyle.overflowX = "hidden";
|
|
325
363
|
if (scrollMoving.value) componentStyle.pointerEvents = "none";
|
|
326
364
|
}
|
|
365
|
+
} else {
|
|
366
|
+
const holderSizeStyle = getHolderSizeStyle(attrs.style);
|
|
367
|
+
if (holderSizeStyle.height !== void 0 || holderSizeStyle.maxHeight !== void 0) Object.assign(componentStyle, holderSizeStyle, ScrollStyle);
|
|
327
368
|
}
|
|
328
369
|
const extraContent = props.extraRender?.({
|
|
329
370
|
start: start.value,
|
|
@@ -335,7 +376,7 @@ var List_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
335
376
|
getSize: getSize.value
|
|
336
377
|
});
|
|
337
378
|
const Component = props.component;
|
|
338
|
-
return (0, vue.createVNode)("div", (0, vue.mergeProps)({ "ref": containerRef }, (0,
|
|
379
|
+
return (0, vue.createVNode)("div", (0, vue.mergeProps)({ "ref": containerRef }, (0, _v_c_util_dist_props_util.pureAttrs)(attrs), {
|
|
339
380
|
"style": {
|
|
340
381
|
position: "relative",
|
|
341
382
|
...attrs.style
|
|
@@ -347,7 +388,7 @@ var List_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
347
388
|
attrs.class
|
|
348
389
|
]
|
|
349
390
|
}), [
|
|
350
|
-
(0, vue.createVNode)(
|
|
391
|
+
(0, vue.createVNode)(_v_c_resize_observer.default, { "onResize": onHolderResize }, { default: () => [(0, vue.createVNode)(Component, {
|
|
351
392
|
"class": `${props.prefixCls}-holder`,
|
|
352
393
|
"style": componentStyle,
|
|
353
394
|
"ref": componentRef,
|
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,
|
|
12
|
+
import { computed, createVNode, defineComponent, mergeProps, ref, shallowRef, toRaw, 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 = [];
|
|
@@ -63,10 +63,12 @@ var List_default = /* @__PURE__ */ defineComponent({
|
|
|
63
63
|
inheritAttrs: false,
|
|
64
64
|
setup(props, { expose, attrs, slots }) {
|
|
65
65
|
const itemHeight = computed(() => props.itemHeight);
|
|
66
|
-
|
|
66
|
+
let itemKeyProp = props.itemKey;
|
|
67
|
+
watch(() => props.itemKey, (val) => {
|
|
68
|
+
itemKeyProp = val;
|
|
69
|
+
});
|
|
67
70
|
const getKey = (item) => {
|
|
68
|
-
|
|
69
|
-
const _itemKey = itemKey.value;
|
|
71
|
+
const _itemKey = itemKeyProp;
|
|
70
72
|
if (typeof _itemKey === "function") return _itemKey(item);
|
|
71
73
|
return item?.[_itemKey];
|
|
72
74
|
};
|
|
@@ -76,10 +78,9 @@ var List_default = /* @__PURE__ */ defineComponent({
|
|
|
76
78
|
mergedData.value = props?.data || EMPTY_DATA;
|
|
77
79
|
});
|
|
78
80
|
const useVirtual = computed(() => !!(props.virtual !== false && props.height && props.itemHeight));
|
|
79
|
-
const containerHeight = computed(() => Object.values(heights.maps).reduce((total, curr) => total + curr, 0));
|
|
80
81
|
const inVirtual = computed(() => {
|
|
81
82
|
const data = mergedData.value;
|
|
82
|
-
return useVirtual.value && data && (
|
|
83
|
+
return useVirtual.value && data && (props.itemHeight * data.length > props.height || !!props.scrollWidth);
|
|
83
84
|
});
|
|
84
85
|
const componentRef = ref();
|
|
85
86
|
const fillerInnerRef = ref();
|
|
@@ -128,35 +129,52 @@ var List_default = /* @__PURE__ */ defineComponent({
|
|
|
128
129
|
return;
|
|
129
130
|
}
|
|
130
131
|
const { itemHeight: itemHeight$1, height } = props;
|
|
132
|
+
const dataLen = mergedData.value.length;
|
|
133
|
+
if (!dataLen) {
|
|
134
|
+
scrollHeight.value = 0;
|
|
135
|
+
start.value = 0;
|
|
136
|
+
end.value = -1;
|
|
137
|
+
fillerOffset.value = 0;
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (heights.id === 0) {
|
|
141
|
+
const safeItemHeight = itemHeight$1;
|
|
142
|
+
const safeListHeight = height;
|
|
143
|
+
const startIndex$1 = Math.max(0, Math.floor(offsetTop.value / safeItemHeight));
|
|
144
|
+
const startOffset$1 = startIndex$1 * safeItemHeight;
|
|
145
|
+
let endIndex$1 = startIndex$1 + Math.ceil(safeListHeight / safeItemHeight);
|
|
146
|
+
endIndex$1 = Math.min(endIndex$1 + 1, dataLen - 1);
|
|
147
|
+
scrollHeight.value = dataLen * safeItemHeight;
|
|
148
|
+
start.value = startIndex$1;
|
|
149
|
+
end.value = endIndex$1;
|
|
150
|
+
fillerOffset.value = startOffset$1;
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
131
153
|
let itemTop = 0;
|
|
132
154
|
let startIndex;
|
|
133
155
|
let startOffset;
|
|
134
156
|
let endIndex;
|
|
135
|
-
const dataLen = mergedData.value.length;
|
|
136
157
|
const data = toRaw(mergedData.value);
|
|
158
|
+
const _offsetTop = offsetTop.value;
|
|
137
159
|
for (let i = 0; i < dataLen; i += 1) {
|
|
138
160
|
const item = data[i];
|
|
139
161
|
const key = getKey(item);
|
|
140
162
|
const cacheHeight = heights.get(key);
|
|
141
163
|
const currentItemBottom = itemTop + (cacheHeight === void 0 ? itemHeight$1 : cacheHeight);
|
|
142
|
-
if (currentItemBottom >=
|
|
164
|
+
if (currentItemBottom >= _offsetTop && startIndex === void 0) {
|
|
143
165
|
startIndex = i;
|
|
144
166
|
startOffset = itemTop;
|
|
145
167
|
}
|
|
146
|
-
if (currentItemBottom >
|
|
168
|
+
if (currentItemBottom > _offsetTop + height && endIndex === void 0) endIndex = i;
|
|
147
169
|
itemTop = currentItemBottom;
|
|
148
|
-
if (startIndex !== void 0 && endIndex !== void 0) {
|
|
149
|
-
itemTop = currentItemBottom + (dataLen - 1 - i) * itemHeight$1;
|
|
150
|
-
break;
|
|
151
|
-
}
|
|
152
170
|
}
|
|
153
171
|
if (startIndex === void 0) {
|
|
154
172
|
startIndex = 0;
|
|
155
173
|
startOffset = 0;
|
|
156
174
|
endIndex = Math.ceil(height / itemHeight$1);
|
|
157
175
|
}
|
|
158
|
-
if (endIndex === void 0) endIndex =
|
|
159
|
-
endIndex = Math.min(endIndex + 1,
|
|
176
|
+
if (endIndex === void 0) endIndex = data.length - 1;
|
|
177
|
+
endIndex = Math.min(endIndex + 1, data.length - 1);
|
|
160
178
|
scrollHeight.value = itemTop;
|
|
161
179
|
start.value = startIndex;
|
|
162
180
|
end.value = endIndex;
|
|
@@ -175,6 +193,10 @@ var List_default = /* @__PURE__ */ defineComponent({
|
|
|
175
193
|
}
|
|
176
194
|
}
|
|
177
195
|
}
|
|
196
|
+
if (useVirtual.value && props.height) {
|
|
197
|
+
const maxScrollTop = Math.max(0, scrollHeight.value - props.height);
|
|
198
|
+
if (offsetTop.value > maxScrollTop) syncScrollTop(maxScrollTop);
|
|
199
|
+
}
|
|
178
200
|
heights.resetRecord();
|
|
179
201
|
});
|
|
180
202
|
const size = ref({
|
|
@@ -271,7 +293,8 @@ var List_default = /* @__PURE__ */ defineComponent({
|
|
|
271
293
|
}, { immediate: true });
|
|
272
294
|
function onFallbackScroll(e) {
|
|
273
295
|
const newScrollTop = e.currentTarget.scrollTop;
|
|
274
|
-
if (
|
|
296
|
+
if (!useVirtual.value || !inVirtual.value) offsetTop.value = newScrollTop;
|
|
297
|
+
else if (newScrollTop !== offsetTop.value) syncScrollTop(newScrollTop);
|
|
275
298
|
props.onScroll?.(e);
|
|
276
299
|
triggerScroll();
|
|
277
300
|
}
|
|
@@ -304,7 +327,7 @@ var List_default = /* @__PURE__ */ defineComponent({
|
|
|
304
327
|
const renderList = mergedData.value.slice(start.value, end.value + 1);
|
|
305
328
|
props.onVisibleChange(renderList, mergedData.value);
|
|
306
329
|
}
|
|
307
|
-
});
|
|
330
|
+
}, { flush: "post" });
|
|
308
331
|
const getSize = useGetSize(mergedData, getKey, heights, itemHeight);
|
|
309
332
|
const listChildren = useChildren(mergedData, start, end, contentScrollWidth, offsetLeft, setInstanceRef, (item, index, props$1) => slots.default?.({
|
|
310
333
|
item,
|
|
@@ -313,14 +336,29 @@ var List_default = /* @__PURE__ */ defineComponent({
|
|
|
313
336
|
}), { getKey });
|
|
314
337
|
return () => {
|
|
315
338
|
const componentStyle = {};
|
|
339
|
+
const getHolderSizeStyle = (style) => {
|
|
340
|
+
if (!style) return {};
|
|
341
|
+
if (Array.isArray(style)) return style.reduce((acc, item) => Object.assign(acc, getHolderSizeStyle(item)), {});
|
|
342
|
+
if (typeof style === "object") {
|
|
343
|
+
const { height, maxHeight } = style;
|
|
344
|
+
const sizeStyle = {};
|
|
345
|
+
if (height !== void 0) sizeStyle.height = height;
|
|
346
|
+
if (maxHeight !== void 0) sizeStyle.maxHeight = maxHeight;
|
|
347
|
+
return sizeStyle;
|
|
348
|
+
}
|
|
349
|
+
return {};
|
|
350
|
+
};
|
|
316
351
|
if (props.height) {
|
|
317
352
|
componentStyle[props.fullHeight ? "height" : "maxHeight"] = `${props.height}px`;
|
|
318
353
|
Object.assign(componentStyle, ScrollStyle);
|
|
319
|
-
if (
|
|
354
|
+
if (inVirtual.value) {
|
|
320
355
|
componentStyle.overflowY = "hidden";
|
|
321
356
|
if (horizontalRange.value > 0) componentStyle.overflowX = "hidden";
|
|
322
357
|
if (scrollMoving.value) componentStyle.pointerEvents = "none";
|
|
323
358
|
}
|
|
359
|
+
} else {
|
|
360
|
+
const holderSizeStyle = getHolderSizeStyle(attrs.style);
|
|
361
|
+
if (holderSizeStyle.height !== void 0 || holderSizeStyle.maxHeight !== void 0) Object.assign(componentStyle, holderSizeStyle, ScrollStyle);
|
|
324
362
|
}
|
|
325
363
|
const extraContent = props.extraRender?.({
|
|
326
364
|
start: start.value,
|
package/dist/ScrollBar.cjs
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
Object.
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
2
5
|
const require_rolldown_runtime = require("./_virtual/rolldown_runtime.cjs");
|
|
3
6
|
let vue = require("vue");
|
|
4
|
-
let
|
|
5
|
-
|
|
7
|
+
let _v_c_util_dist_raf = require("@v-c/util/dist/raf");
|
|
8
|
+
_v_c_util_dist_raf = require_rolldown_runtime.__toESM(_v_c_util_dist_raf);
|
|
6
9
|
function getPageXY(e, horizontal) {
|
|
7
10
|
return ("touches" in e ? e.touches[0] : e)[horizontal ? "pageX" : "pageY"] - window[horizontal ? "scrollX" : "scrollY"];
|
|
8
11
|
}
|
|
@@ -149,7 +152,7 @@ var ScrollBar_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
149
152
|
let moveRafId = null;
|
|
150
153
|
const onMouseMove = (e) => {
|
|
151
154
|
const { dragging: stateDragging, pageY: statePageY, startTop: stateStartTop } = stateRef.value;
|
|
152
|
-
|
|
155
|
+
_v_c_util_dist_raf.default.cancel(moveRafId);
|
|
153
156
|
const rect = scrollbarRef.value.getBoundingClientRect();
|
|
154
157
|
const scale = props.containerSize / (props.horizontal ? rect.width : rect.height);
|
|
155
158
|
if (stateDragging) {
|
|
@@ -163,7 +166,7 @@ var ScrollBar_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
163
166
|
let newScrollTop = Math.ceil(ptg * tmpEnableScrollRange);
|
|
164
167
|
newScrollTop = Math.max(newScrollTop, 0);
|
|
165
168
|
newScrollTop = Math.min(newScrollTop, tmpEnableScrollRange);
|
|
166
|
-
moveRafId = (0,
|
|
169
|
+
moveRafId = (0, _v_c_util_dist_raf.default)(() => {
|
|
167
170
|
props?.onScroll?.(newScrollTop, props.horizontal);
|
|
168
171
|
});
|
|
169
172
|
}
|
|
@@ -181,7 +184,7 @@ var ScrollBar_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
181
184
|
window.removeEventListener("touchmove", onMouseMove);
|
|
182
185
|
window.removeEventListener("mouseup", onMouseUp);
|
|
183
186
|
window.removeEventListener("touchend", onMouseUp);
|
|
184
|
-
|
|
187
|
+
_v_c_util_dist_raf.default.cancel(moveRafId);
|
|
185
188
|
});
|
|
186
189
|
}
|
|
187
190
|
});
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
Object.
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
2
5
|
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
3
6
|
const require_Item = require("../Item.cjs");
|
|
4
7
|
let vue = require("vue");
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
Object.
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
2
5
|
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
3
6
|
const require_algorithmUtil = require("../utils/algorithmUtil.cjs");
|
|
4
7
|
let vue = require("vue");
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
Object.
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
2
5
|
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
3
6
|
const require_isFirefox = require("../utils/isFirefox.cjs");
|
|
4
7
|
const require_useOriginScroll = require("./useOriginScroll.cjs");
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
Object.
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
2
5
|
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
3
6
|
const require_CacheMap = require("../utils/CacheMap.cjs");
|
|
4
7
|
let vue = require("vue");
|
|
8
|
+
let _v_c_util_dist_Dom_findDOMNode = require("@v-c/util/dist/Dom/findDOMNode");
|
|
5
9
|
function parseNumber(value) {
|
|
6
10
|
const num = parseFloat(value);
|
|
7
11
|
return isNaN(num) ? 0 : num;
|
|
@@ -9,8 +13,12 @@ function parseNumber(value) {
|
|
|
9
13
|
function useHeights(getKey, onItemAdd, onItemRemove) {
|
|
10
14
|
const updatedMark = (0, vue.ref)(0);
|
|
11
15
|
const instanceRef = (0, vue.ref)(/* @__PURE__ */ new Map());
|
|
12
|
-
const heightsRef = new require_CacheMap.default();
|
|
16
|
+
const heightsRef = (0, vue.markRaw)(new require_CacheMap.default());
|
|
13
17
|
const promiseIdRef = (0, vue.ref)(0);
|
|
18
|
+
const observedElements = /* @__PURE__ */ new Map();
|
|
19
|
+
const resizeObserver = typeof window !== "undefined" && "ResizeObserver" in window ? new window.ResizeObserver(() => {
|
|
20
|
+
collectHeight();
|
|
21
|
+
}) : null;
|
|
14
22
|
function cancelRaf() {
|
|
15
23
|
promiseIdRef.value += 1;
|
|
16
24
|
}
|
|
@@ -19,6 +27,7 @@ function useHeights(getKey, onItemAdd, onItemRemove) {
|
|
|
19
27
|
const doCollect = () => {
|
|
20
28
|
let changed = false;
|
|
21
29
|
instanceRef.value.forEach((element, key) => {
|
|
30
|
+
element = (0, _v_c_util_dist_Dom_findDOMNode.getDOM)(element);
|
|
22
31
|
if (element && element.offsetParent) {
|
|
23
32
|
const { offsetHeight } = element;
|
|
24
33
|
const { marginTop, marginBottom } = getComputedStyle(element);
|
|
@@ -46,15 +55,27 @@ function useHeights(getKey, onItemAdd, onItemRemove) {
|
|
|
46
55
|
const key = getKey(item);
|
|
47
56
|
const origin = instanceRef.value.get(key);
|
|
48
57
|
if (origin === instance) return;
|
|
58
|
+
const prevObserved = observedElements.get(key);
|
|
59
|
+
if (prevObserved && resizeObserver) {
|
|
60
|
+
resizeObserver.unobserve(prevObserved);
|
|
61
|
+
observedElements.delete(key);
|
|
62
|
+
}
|
|
49
63
|
if (instance) {
|
|
50
64
|
instanceRef.value.set(key, instance);
|
|
51
65
|
collectHeight();
|
|
66
|
+
const element = (0, _v_c_util_dist_Dom_findDOMNode.getDOM)(instance);
|
|
67
|
+
if (element && element.nodeType === 1 && resizeObserver) {
|
|
68
|
+
resizeObserver.observe(element);
|
|
69
|
+
observedElements.set(key, element);
|
|
70
|
+
}
|
|
52
71
|
} else instanceRef.value.delete(key);
|
|
53
72
|
if (!origin !== !instance) if (instance) onItemAdd?.(item);
|
|
54
73
|
else onItemRemove?.(item);
|
|
55
74
|
}
|
|
56
75
|
(0, vue.onUnmounted)(() => {
|
|
57
76
|
cancelRaf();
|
|
77
|
+
resizeObserver?.disconnect?.();
|
|
78
|
+
observedElements.clear();
|
|
58
79
|
});
|
|
59
80
|
return [
|
|
60
81
|
setInstanceRef,
|
package/dist/hooks/useHeights.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import CacheMap_default from "../utils/CacheMap.js";
|
|
2
|
-
import { onUnmounted, ref } from "vue";
|
|
2
|
+
import { markRaw, onUnmounted, ref } from "vue";
|
|
3
|
+
import { getDOM } from "@v-c/util/dist/Dom/findDOMNode";
|
|
3
4
|
function parseNumber(value) {
|
|
4
5
|
const num = parseFloat(value);
|
|
5
6
|
return isNaN(num) ? 0 : num;
|
|
@@ -7,8 +8,12 @@ function parseNumber(value) {
|
|
|
7
8
|
function useHeights(getKey, onItemAdd, onItemRemove) {
|
|
8
9
|
const updatedMark = ref(0);
|
|
9
10
|
const instanceRef = ref(/* @__PURE__ */ new Map());
|
|
10
|
-
const heightsRef = new CacheMap_default();
|
|
11
|
+
const heightsRef = markRaw(new CacheMap_default());
|
|
11
12
|
const promiseIdRef = ref(0);
|
|
13
|
+
const observedElements = /* @__PURE__ */ new Map();
|
|
14
|
+
const resizeObserver = typeof window !== "undefined" && "ResizeObserver" in window ? new window.ResizeObserver(() => {
|
|
15
|
+
collectHeight();
|
|
16
|
+
}) : null;
|
|
12
17
|
function cancelRaf() {
|
|
13
18
|
promiseIdRef.value += 1;
|
|
14
19
|
}
|
|
@@ -17,6 +22,7 @@ function useHeights(getKey, onItemAdd, onItemRemove) {
|
|
|
17
22
|
const doCollect = () => {
|
|
18
23
|
let changed = false;
|
|
19
24
|
instanceRef.value.forEach((element, key) => {
|
|
25
|
+
element = getDOM(element);
|
|
20
26
|
if (element && element.offsetParent) {
|
|
21
27
|
const { offsetHeight } = element;
|
|
22
28
|
const { marginTop, marginBottom } = getComputedStyle(element);
|
|
@@ -44,15 +50,27 @@ function useHeights(getKey, onItemAdd, onItemRemove) {
|
|
|
44
50
|
const key = getKey(item);
|
|
45
51
|
const origin = instanceRef.value.get(key);
|
|
46
52
|
if (origin === instance) return;
|
|
53
|
+
const prevObserved = observedElements.get(key);
|
|
54
|
+
if (prevObserved && resizeObserver) {
|
|
55
|
+
resizeObserver.unobserve(prevObserved);
|
|
56
|
+
observedElements.delete(key);
|
|
57
|
+
}
|
|
47
58
|
if (instance) {
|
|
48
59
|
instanceRef.value.set(key, instance);
|
|
49
60
|
collectHeight();
|
|
61
|
+
const element = getDOM(instance);
|
|
62
|
+
if (element && element.nodeType === 1 && resizeObserver) {
|
|
63
|
+
resizeObserver.observe(element);
|
|
64
|
+
observedElements.set(key, element);
|
|
65
|
+
}
|
|
50
66
|
} else instanceRef.value.delete(key);
|
|
51
67
|
if (!origin !== !instance) if (instance) onItemAdd?.(item);
|
|
52
68
|
else onItemRemove?.(item);
|
|
53
69
|
}
|
|
54
70
|
onUnmounted(() => {
|
|
55
71
|
cancelRaf();
|
|
72
|
+
resizeObserver?.disconnect?.();
|
|
73
|
+
observedElements.clear();
|
|
56
74
|
});
|
|
57
75
|
return [
|
|
58
76
|
setInstanceRef,
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
Object.
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
2
5
|
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
3
6
|
let vue = require("vue");
|
|
4
7
|
var SMOOTH_PTG = 14 / 15;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
Object.
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
2
5
|
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
3
6
|
let vue = require("vue");
|
|
4
7
|
function useOriginScroll(isScrollAtTop, isScrollAtBottom, isScrollAtLeft, isScrollAtRight) {
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
Object.
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
2
5
|
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
3
6
|
let vue = require("vue");
|
|
4
7
|
function smoothScrollOffset(offset) {
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
Object.
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
2
5
|
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
3
6
|
let vue = require("vue");
|
|
4
|
-
let
|
|
7
|
+
let _v_c_util = require("@v-c/util");
|
|
5
8
|
var MAX_TIMES = 10;
|
|
6
9
|
function useScrollTo(containerRef, data, heights, itemHeight, getKey, collectHeight, syncScrollTop, triggerFlash) {
|
|
7
10
|
const syncState = (0, vue.shallowRef)(null);
|
|
@@ -73,7 +76,7 @@ function useScrollTo(containerRef, data, heights, itemHeight, getKey, collectHei
|
|
|
73
76
|
targetAlign: newTargetAlign,
|
|
74
77
|
lastTop: targetTop
|
|
75
78
|
};
|
|
76
|
-
} else if (process.env.NODE_ENV !== "production" && syncState.value?.times === MAX_TIMES) (0,
|
|
79
|
+
} else if (process.env.NODE_ENV !== "production" && syncState.value?.times === MAX_TIMES) (0, _v_c_util.warning)(false, "Seems `scrollTo` with `rc-virtual-list` reach the max limitation. Please fire issue for us. Thanks.");
|
|
77
80
|
}, {
|
|
78
81
|
immediate: true,
|
|
79
82
|
flush: "post"
|
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
Object.
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
2
5
|
const require_List = require("./List.cjs");
|
|
3
6
|
var src_default = require_List.default;
|
|
4
7
|
exports.default = src_default;
|
package/dist/interface.cjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
package/dist/utils/CacheMap.cjs
CHANGED
package/dist/utils/isFirefox.cjs
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
Object.
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
2
5
|
var isFF = typeof navigator === "object" && /Firefox/i.test(navigator.userAgent);
|
|
3
6
|
var isFirefox_default = isFF;
|
|
4
7
|
exports.default = isFirefox_default;
|
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
|
+
"version": "1.0.4",
|
|
5
5
|
"description": "Vue Virtual List Component",
|
|
6
6
|
"author": "",
|
|
7
7
|
"license": "MIT",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"vue": "^3.0.0"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@v-c/resize-observer": "^1.0.
|
|
35
|
-
"@v-c/util": "^1.0.
|
|
34
|
+
"@v-c/resize-observer": "^1.0.3",
|
|
35
|
+
"@v-c/util": "^1.0.4"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"build": "vite build",
|