@pdanpdan/virtual-scroll 0.9.1 → 0.10.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.
- package/README.md +82 -4
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +170 -153
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +833 -692
- package/dist/index.mjs.map +1 -1
- package/dist/virtual-scroll.css +1 -1
- package/package.json +1 -1
- package/src/components/VirtualScroll.vue +30 -20
- package/src/composables/useVirtualScroll.ts +365 -804
- package/src/composables/useVirtualScrollSizes.ts +28 -37
- package/src/composables/useVirtualScrollbar.ts +16 -0
- package/src/extensions/all.ts +7 -0
- package/src/extensions/coordinate-scaling.ts +30 -0
- package/src/extensions/index.ts +88 -0
- package/src/extensions/infinite-loading.ts +47 -0
- package/src/extensions/prepend-restoration.ts +49 -0
- package/src/extensions/rtl.ts +42 -0
- package/src/extensions/snapping.ts +82 -0
- package/src/extensions/sticky.ts +43 -0
- package/src/types.ts +27 -7
- package/src/utils/scroll.ts +1 -1
- package/src/utils/virtual-scroll-logic.ts +33 -0
package/src/utils/scroll.ts
CHANGED
|
@@ -22,7 +22,7 @@ export const BROWSER_MAX_SIZE = 10000000;
|
|
|
22
22
|
* @returns `true` if the container is the global window object.
|
|
23
23
|
*/
|
|
24
24
|
export function isWindow(container?: HTMLElement | Window | null): container is Window {
|
|
25
|
-
return container === null || container === document.documentElement || (typeof window !== 'undefined' && container === window);
|
|
25
|
+
return container === null || (typeof document !== 'undefined' && container === document.documentElement) || (typeof window !== 'undefined' && container === window);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/**
|
|
@@ -1189,6 +1189,39 @@ export function resolveSnap(
|
|
|
1189
1189
|
}
|
|
1190
1190
|
}
|
|
1191
1191
|
|
|
1192
|
+
if (mode === 'next') {
|
|
1193
|
+
if (dir === 'start') {
|
|
1194
|
+
effectiveMode = 'end';
|
|
1195
|
+
} else if (dir === 'end') {
|
|
1196
|
+
effectiveMode = 'start';
|
|
1197
|
+
} else {
|
|
1198
|
+
return null;
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
if (effectiveMode === 'start') {
|
|
1202
|
+
// Scrolling towards end (dir === 'end') -> snap to NEXT item start
|
|
1203
|
+
const size = getSize(currentIdx);
|
|
1204
|
+
if (size > viewSize) {
|
|
1205
|
+
return null;
|
|
1206
|
+
}
|
|
1207
|
+
return {
|
|
1208
|
+
index: Math.min(count - 1, currentIdx + 1),
|
|
1209
|
+
align: 'start' as const,
|
|
1210
|
+
};
|
|
1211
|
+
}
|
|
1212
|
+
if (effectiveMode === 'end') {
|
|
1213
|
+
// Scrolling towards start (dir === 'start') -> snap to PREVIOUS item end
|
|
1214
|
+
const size = getSize(currentEndIdx);
|
|
1215
|
+
if (size > viewSize) {
|
|
1216
|
+
return null;
|
|
1217
|
+
}
|
|
1218
|
+
return {
|
|
1219
|
+
index: Math.max(0, currentEndIdx - 1),
|
|
1220
|
+
align: 'end' as const,
|
|
1221
|
+
};
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1192
1225
|
if (effectiveMode === 'start') {
|
|
1193
1226
|
const size = getSize(currentIdx);
|
|
1194
1227
|
// Ignore items larger than viewport to prevent jarring jumps
|