virtua 0.52.10 → 0.53.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 (55) hide show
  1. package/README.md +286 -193
  2. package/lib/angular/VList.d.ts +3 -1
  3. package/lib/angular/VMasonry.d.ts +114 -0
  4. package/lib/angular/Virtualizer.d.ts +3 -1
  5. package/lib/angular/WindowVirtualizer.d.ts +3 -1
  6. package/lib/angular/index.d.ts +1 -0
  7. package/lib/angular/index.js +733 -352
  8. package/lib/angular/index.js.map +1 -1
  9. package/lib/core/index.cjs +180 -104
  10. package/lib/core/index.cjs.map +1 -1
  11. package/lib/core/index.d.ts +1 -0
  12. package/lib/core/index.js +257 -181
  13. package/lib/core/index.js.map +1 -1
  14. package/lib/core/layouts/masonry.d.ts +1 -0
  15. package/lib/index.cjs +555 -385
  16. package/lib/index.cjs.map +1 -1
  17. package/lib/index.js +572 -404
  18. package/lib/index.js.map +1 -1
  19. package/lib/react/VMasonry.d.ts +105 -0
  20. package/lib/react/Virtualizer.d.ts +3 -1
  21. package/lib/react/WindowVirtualizer.d.ts +3 -1
  22. package/lib/react/index.d.ts +2 -0
  23. package/lib/react/types.d.ts +1 -1
  24. package/lib/solid/VMasonry.d.ts +107 -0
  25. package/lib/solid/Virtualizer.d.ts +3 -1
  26. package/lib/solid/WindowVirtualizer.d.ts +3 -1
  27. package/lib/solid/index.cjs +720 -514
  28. package/lib/solid/index.cjs.map +1 -1
  29. package/lib/solid/index.d.ts +2 -0
  30. package/lib/solid/index.js +691 -494
  31. package/lib/solid/index.js.map +1 -1
  32. package/lib/solid/index.jsx +329 -8
  33. package/lib/solid/index.jsx.map +1 -1
  34. package/lib/solid/types.d.ts +1 -1
  35. package/lib/svelte/MasonryItem.svelte +49 -0
  36. package/lib/svelte/VGrid.svelte +1 -1
  37. package/lib/svelte/VList.svelte +1 -1
  38. package/lib/svelte/VMasonry.svelte +182 -0
  39. package/lib/svelte/VMasonry.type.d.ts +104 -0
  40. package/lib/svelte/Virtualizer.svelte +1 -1
  41. package/lib/svelte/Virtualizer.type.d.ts +3 -1
  42. package/lib/svelte/WindowVirtualizer.svelte +1 -1
  43. package/lib/svelte/WindowVirtualizer.type.d.ts +3 -1
  44. package/lib/svelte/index.d.ts +2 -0
  45. package/lib/svelte/index.js +2 -1
  46. package/lib/svelte/types.d.ts +2 -2
  47. package/lib/vue/VMasonry.d.ts +110 -0
  48. package/lib/vue/Virtualizer.d.ts +3 -1
  49. package/lib/vue/WindowVirtualizer.d.ts +3 -1
  50. package/lib/vue/index.cjs +625 -403
  51. package/lib/vue/index.cjs.map +1 -1
  52. package/lib/vue/index.d.ts +2 -0
  53. package/lib/vue/index.js +672 -455
  54. package/lib/vue/index.js.map +1 -1
  55. package/package.json +6 -16
@@ -0,0 +1,105 @@
1
+ import { ReactElement, Ref } from 'react';
2
+ import { CacheSnapshot, ScrollToIndexOpts } from '../core/index.js';
3
+ import { ViewportComponentAttributes } from './types.js';
4
+ /**
5
+ * Methods of {@link VMasonry}.
6
+ */
7
+ export interface VMasonryHandle {
8
+ /**
9
+ * Get current {@link CacheSnapshot}.
10
+ */
11
+ readonly cache: CacheSnapshot;
12
+ /**
13
+ * Get current scrollTop.
14
+ */
15
+ readonly scrollOffset: number;
16
+ /**
17
+ * Get current scrollHeight.
18
+ */
19
+ readonly scrollSize: number;
20
+ /**
21
+ * Get current clientHeight.
22
+ */
23
+ readonly viewportSize: number;
24
+ /**
25
+ * Get item offset from start.
26
+ * @param index index of item
27
+ */
28
+ getItemOffset(index: number): number;
29
+ /**
30
+ * Get item size.
31
+ * @param index index of item
32
+ */
33
+ getItemSize(index: number): number;
34
+ /**
35
+ * Scroll to the item specified by index.
36
+ * @param index index of item
37
+ * @param opts options
38
+ */
39
+ scrollToIndex(index: number, opts?: ScrollToIndexOpts): void;
40
+ /**
41
+ * Scroll to the given offset.
42
+ * @param offset offset from start
43
+ */
44
+ scrollTo(offset: number): void;
45
+ /**
46
+ * Scroll by the given offset.
47
+ * @param offset offset from current position
48
+ */
49
+ scrollBy(offset: number): void;
50
+ }
51
+ /**
52
+ * Props of {@link VMasonry}.
53
+ */
54
+ export interface VMasonryProps<T> extends ViewportComponentAttributes {
55
+ /**
56
+ * The elements renderer function.
57
+ */
58
+ children: (data: T, index: number) => ReactElement;
59
+ /**
60
+ * The data items rendered by this component.
61
+ */
62
+ data: ArrayLike<T>;
63
+ /**
64
+ * The number of lanes (columns) which items are laid out into. Each item is placed into the shortest lane in order. It must be an integer and the minimum value is 1.
65
+ */
66
+ lanes: number;
67
+ /**
68
+ * The gap between the items and the lanes in pixels, which is not included in the sizes.
69
+ * @defaultValue 0
70
+ */
71
+ gap?: number;
72
+ /**
73
+ * Item size hint for unmeasured items in pixels. It will help to reduce scroll jump when items are measured if used properly.
74
+ *
75
+ * - If not set, initial item sizes will be automatically estimated from measured sizes. This is recommended for most cases.
76
+ * - If set, you can opt out estimation and use the value as initial item size.
77
+ */
78
+ itemSize?: number;
79
+ /**
80
+ * Extra item space in pixels to render before/after the viewport. The minimum value is 0. Lower value will give better performance but you can increase to avoid showing blank items in fast scrolling.
81
+ * @defaultValue 200
82
+ */
83
+ bufferSize?: number;
84
+ /**
85
+ * You can restore cache by passing a {@link CacheSnapshot} on mount. This is useful when you want to restore scroll position after navigation. The snapshot can be obtained from {@link VMasonryHandle.cache}.
86
+ *
87
+ * **The length of items should be the same as when you take the snapshot, otherwise restoration may not work as expected.**
88
+ */
89
+ cache?: CacheSnapshot;
90
+ /**
91
+ * Callback invoked whenever scroll offset changes.
92
+ * @param offset Current scrollTop.
93
+ */
94
+ onScroll?: (offset: number) => void;
95
+ /**
96
+ * Callback invoked when scrolling stops.
97
+ */
98
+ onScrollEnd?: () => void;
99
+ }
100
+ /**
101
+ * Virtualized masonry component. See {@link VMasonryProps} and {@link VMasonryHandle}.
102
+ */
103
+ export declare const VMasonry: <T>(props: VMasonryProps<T> & {
104
+ ref?: Ref<VMasonryHandle>;
105
+ }) => ReactElement;
@@ -80,7 +80,9 @@ export interface VirtualizerProps<T = unknown> {
80
80
  */
81
81
  itemSize?: number;
82
82
  /**
83
- * While true is set, scroll position will be maintained from the end not usual start when items are added to/removed from start. It's recommended to set false if you add to/remove from mid/end of the list because it can cause unexpected behavior. This prop is useful for reverse infinite scrolling.
83
+ * Set true only when items are added to or removed from the start of the list, such as when older items are loaded in reverse infinite scrolling. In that case, the scroll position is maintained from the end of the list instead of the start.
84
+ *
85
+ * **Do not set true in any other case, as it can cause unexpected behavior.**
84
86
  */
85
87
  shift?: boolean;
86
88
  /**
@@ -66,7 +66,9 @@ export interface WindowVirtualizerProps<T = unknown> {
66
66
  */
67
67
  itemSize?: number;
68
68
  /**
69
- * While true is set, scroll position will be maintained from the end not usual start when items are added to/removed from start. It's recommended to set false if you add to/remove from mid/end of the list because it can cause unexpected behavior. This prop is useful for reverse infinite scrolling.
69
+ * Set true only when items are added to or removed from the start of the list, such as when older items are loaded in reverse infinite scrolling. In that case, the scroll position is maintained from the end of the list instead of the start.
70
+ *
71
+ * **Do not set true in any other case, as it can cause unexpected behavior.**
70
72
  */
71
73
  shift?: boolean;
72
74
  /**
@@ -7,4 +7,6 @@ export type { WindowVirtualizerProps, WindowVirtualizerHandle, } from './WindowV
7
7
  export { VGrid } from './VGrid.js';
8
8
  export type { VGridProps, VGridHandle } from './VGrid.js';
9
9
  export type { GridSize, GridSpan } from '../core/index.js';
10
+ export { VMasonry } from './VMasonry.js';
11
+ export type { VMasonryProps, VMasonryHandle } from './VMasonry.js';
10
12
  export type * from './types.js';
@@ -1,5 +1,5 @@
1
1
  import { ComponentType, CSSProperties, LegacyRef, ReactNode } from 'react';
2
- export type ViewportComponentAttributes = Pick<React.HTMLAttributes<HTMLElement>, "className" | "style" | "id" | "role" | "tabIndex" | "onKeyDown" | "onWheel"> & React.AriaAttributes;
2
+ export type ViewportComponentAttributes = Omit<React.HTMLAttributes<HTMLDivElement>, "children" | "onScroll" | "onScrollEnd">;
3
3
  export interface CustomContainerComponentProps {
4
4
  style: CSSProperties;
5
5
  children: ReactNode;
@@ -0,0 +1,107 @@
1
+ import { JSX, Accessor } from 'solid-js';
2
+ import { ScrollToIndexOpts, CacheSnapshot } from '../core/index.js';
3
+ import { ViewportComponentAttributes } from './types.js';
4
+ /**
5
+ * Methods of {@link VMasonry}.
6
+ */
7
+ export interface VMasonryHandle {
8
+ /**
9
+ * Get current {@link CacheSnapshot}.
10
+ */
11
+ readonly cache: CacheSnapshot;
12
+ /**
13
+ * Get current scrollTop.
14
+ */
15
+ readonly scrollOffset: number;
16
+ /**
17
+ * Get current scrollHeight.
18
+ */
19
+ readonly scrollSize: number;
20
+ /**
21
+ * Get current clientHeight.
22
+ */
23
+ readonly viewportSize: number;
24
+ /**
25
+ * Get item offset from start.
26
+ * @param index index of item
27
+ */
28
+ getItemOffset(index: number): number;
29
+ /**
30
+ * Get item size.
31
+ * @param index index of item
32
+ */
33
+ getItemSize(index: number): number;
34
+ /**
35
+ * Scroll to the item specified by index.
36
+ * @param index index of item
37
+ * @param opts options
38
+ */
39
+ scrollToIndex(index: number, opts?: ScrollToIndexOpts): void;
40
+ /**
41
+ * Scroll to the given offset.
42
+ * @param offset offset from start
43
+ */
44
+ scrollTo(offset: number): void;
45
+ /**
46
+ * Scroll by the given offset.
47
+ * @param offset offset from current position
48
+ */
49
+ scrollBy(offset: number): void;
50
+ }
51
+ /**
52
+ * Props of {@link VMasonry}.
53
+ */
54
+ export interface VMasonryProps<T> extends ViewportComponentAttributes {
55
+ /**
56
+ * Get reference to {@link VMasonryHandle}.
57
+ */
58
+ ref?: VMasonryHandle | ((handle?: VMasonryHandle) => void);
59
+ /**
60
+ * The data items rendered by this component.
61
+ */
62
+ data: readonly T[];
63
+ /**
64
+ * The elements renderer function.
65
+ */
66
+ children: (data: T, index: Accessor<number>) => JSX.Element;
67
+ /**
68
+ * The number of lanes (columns) which items are laid out into. Each item is placed into the shortest lane in order. It must be an integer and the minimum value is 1.
69
+ */
70
+ lanes: number;
71
+ /**
72
+ * The gap between the items and the lanes in pixels, which is not included in the sizes.
73
+ * @defaultValue 0
74
+ */
75
+ gap?: number;
76
+ /**
77
+ * Item size hint for unmeasured items in pixels. It will help to reduce scroll jump when items are measured if used properly.
78
+ *
79
+ * - If not set, initial item sizes will be automatically estimated from measured sizes. This is recommended for most cases.
80
+ * - If set, you can opt out estimation and use the value as initial item size.
81
+ */
82
+ itemSize?: number;
83
+ /**
84
+ * Extra item space in pixels to render before/after the viewport. The minimum value is 0. Lower value will give better performance but you can increase to avoid showing blank items in fast scrolling.
85
+ * @defaultValue 200
86
+ */
87
+ bufferSize?: number;
88
+ /**
89
+ * You can restore cache by passing a {@link CacheSnapshot} on mount. This is useful when you want to restore scroll position after navigation. The snapshot can be obtained from {@link VMasonryHandle.cache}.
90
+ *
91
+ * **The length of items should be the same as when you take the snapshot, otherwise restoration may not work as expected.**
92
+ */
93
+ cache?: CacheSnapshot;
94
+ /**
95
+ * Callback invoked whenever scroll offset changes.
96
+ * @param offset Current scrollTop.
97
+ */
98
+ onScroll?: (offset: number) => void;
99
+ /**
100
+ * Callback invoked when scrolling stops.
101
+ */
102
+ onScrollEnd?: () => void;
103
+ }
104
+ /**
105
+ * Virtualized masonry component. See {@link VMasonryProps} and {@link VMasonryHandle}.
106
+ */
107
+ export declare const VMasonry: <T>(props: VMasonryProps<T>) => JSX.Element;
@@ -99,7 +99,9 @@ export interface VirtualizerProps<T> {
99
99
  */
100
100
  ssrCount?: number;
101
101
  /**
102
- * While true is set, scroll position will be maintained from the end not usual start when items are added to/removed from start. It's recommended to set false if you add to/remove from mid/end of the list because it can cause unexpected behavior. This prop is useful for reverse infinite scrolling.
102
+ * Set true only when items are added to or removed from the start of the list, such as when older items are loaded in reverse infinite scrolling. In that case, the scroll position is maintained from the end of the list instead of the start.
103
+ *
104
+ * **Do not set true in any other case, as it can cause unexpected behavior.**
103
105
  */
104
106
  shift?: boolean;
105
107
  /**
@@ -71,7 +71,9 @@ export interface WindowVirtualizerProps<T> {
71
71
  */
72
72
  ssrCount?: number;
73
73
  /**
74
- * While true is set, scroll position will be maintained from the end not usual start when items are added to/removed from start. It's recommended to set false if you add to/remove from mid/end of the list because it can cause unexpected behavior. This prop is useful for reverse infinite scrolling.
74
+ * Set true only when items are added to or removed from the start of the list, such as when older items are loaded in reverse infinite scrolling. In that case, the scroll position is maintained from the end of the list instead of the start.
75
+ *
76
+ * **Do not set true in any other case, as it can cause unexpected behavior.**
75
77
  */
76
78
  shift?: boolean;
77
79
  /**