virtua 0.51.3 → 0.52.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 (46) hide show
  1. package/README.md +37 -13
  2. package/lib/angular/VGrid.d.ts +249 -0
  3. package/lib/angular/VList.d.ts +3 -3
  4. package/lib/angular/Virtualizer.d.ts +3 -3
  5. package/lib/angular/WindowVirtualizer.d.ts +3 -3
  6. package/lib/angular/index.d.ts +2 -0
  7. package/lib/angular/index.js +1150 -327
  8. package/lib/angular/index.js.map +1 -1
  9. package/lib/core/grid.d.ts +30 -0
  10. package/lib/core/index.cjs +484 -270
  11. package/lib/core/index.cjs.map +1 -1
  12. package/lib/core/index.d.ts +5 -3
  13. package/lib/core/index.js +462 -249
  14. package/lib/core/index.js.map +1 -1
  15. package/lib/core/layouts/grid.d.ts +21 -0
  16. package/lib/core/scroll-to.d.ts +50 -1
  17. package/lib/core/types.d.ts +0 -25
  18. package/lib/index.cjs +761 -558
  19. package/lib/index.cjs.map +1 -1
  20. package/lib/index.d.ts +2 -1
  21. package/lib/index.js +730 -509
  22. package/lib/index.js.map +1 -1
  23. package/lib/react/VGrid.d.ts +105 -80
  24. package/lib/react/index.d.ts +3 -2
  25. package/lib/solid/VGrid.d.ts +193 -0
  26. package/lib/solid/index.cjs +817 -288
  27. package/lib/solid/index.cjs.map +1 -1
  28. package/lib/solid/index.d.ts +3 -0
  29. package/lib/solid/index.js +786 -270
  30. package/lib/solid/index.js.map +1 -1
  31. package/lib/solid/index.jsx +743 -124
  32. package/lib/solid/index.jsx.map +1 -1
  33. package/lib/svelte/GridCell.svelte +44 -0
  34. package/lib/svelte/GridRow.svelte +42 -0
  35. package/lib/svelte/GridRowGroup.svelte +42 -0
  36. package/lib/svelte/VGrid.svelte +238 -0
  37. package/lib/svelte/VGrid.type.d.ts +185 -0
  38. package/lib/svelte/index.d.ts +3 -0
  39. package/lib/svelte/index.js +2 -1
  40. package/lib/vue/VGrid.d.ts +194 -0
  41. package/lib/vue/index.cjs +886 -376
  42. package/lib/vue/index.cjs.map +1 -1
  43. package/lib/vue/index.d.ts +3 -0
  44. package/lib/vue/index.js +858 -349
  45. package/lib/vue/index.js.map +1 -1
  46. package/package.json +4 -3
@@ -1,14 +1,6 @@
1
- import { default as React, JSX, CSSProperties, ReactNode, Ref } from 'react';
1
+ import { ReactElement, ReactNode, Ref } from 'react';
2
+ import { VGridAxis, VGridCell, VGridSize, VGridSpan, VGridScrollToIndexOpts } from '../core/index.js';
2
3
  import { ViewportComponentAttributes } from './types.js';
3
- /**
4
- * Props of customized cell component for {@link VGrid}.
5
- */
6
- export interface CustomCellComponentProps {
7
- style: CSSProperties;
8
- children: ReactNode;
9
- }
10
- export type CustomCellComponent = React.ForwardRefExoticComponent<React.PropsWithoutRef<CustomCellComponentProps> & React.RefAttributes<any>>;
11
- export type VGridItemResize = readonly [index: number, size: number];
12
4
  /**
13
5
  * Methods of {@link VGrid}.
14
6
  */
@@ -16,11 +8,11 @@ export interface VGridHandle {
16
8
  /**
17
9
  * Get current scrollTop.
18
10
  */
19
- readonly scrollTop: number;
11
+ readonly verticalScrollOffset: number;
20
12
  /**
21
13
  * Get current scrollLeft. Always positive even in RTL.
22
14
  */
23
- readonly scrollLeft: number;
15
+ readonly horizontalScrollOffset: number;
24
16
  /**
25
17
  * Get current scrollHeight.
26
18
  */
@@ -39,128 +31,161 @@ export interface VGridHandle {
39
31
  readonly viewportWidth: number;
40
32
  /**
41
33
  * Find nearest row index from offset.
42
- * @param offset offset in pixels from the start of the scroll container
34
+ * @param offset offset in pixels from the top of the scroll container
43
35
  */
44
- findRowIndex: (offset: number) => number;
36
+ findRowIndex(offset: number): number;
45
37
  /**
46
- * Find nearest col index from offset.
38
+ * Find nearest column index from offset.
47
39
  * @param offset offset in pixels from the start of the scroll container
48
40
  */
49
- findColIndex: (offset: number) => number;
41
+ findColIndex(offset: number): number;
50
42
  /**
51
- * Get row offset from start.
43
+ * Get offset of the row from the top.
52
44
  * @param index index of row
53
45
  */
54
46
  getRowOffset(index: number): number;
55
47
  /**
56
- * Get col offset from start.
57
- * @param index index of col
48
+ * Get offset of the column from the start.
49
+ * @param index index of column
58
50
  */
59
51
  getColOffset(index: number): number;
60
52
  /**
61
- * Get row size.
53
+ * Get size of the row.
62
54
  * @param index index of row
63
55
  */
64
56
  getRowSize(index: number): number;
65
57
  /**
66
- * Get col size.
67
- * @param index index of col
58
+ * Get size of the column.
59
+ * @param index index of column
68
60
  */
69
61
  getColSize(index: number): number;
70
62
  /**
71
- * Resize individual columns.
72
- * @param cols array of `[index, size]` to update column sizes
73
- */
74
- resizeCols(cols: VGridItemResize[]): void;
75
- /**
76
- * Resize individual rows.
77
- * @param rows array of `[index, size]` to update row sizes
63
+ * Scroll to the cell specified by the indexes. The cell is not hidden behind the rows and the columns sticking over it.
64
+ * @param opts the indexes of the cell and the options. See {@link VGridScrollToIndexOpts}.
78
65
  */
79
- resizeRows(rows: VGridItemResize[]): void;
66
+ scrollToIndex(opts: VGridScrollToIndexOpts): void;
80
67
  /**
81
- * Scroll to the item specified by index.
82
- * @param indexX horizontal index of item
83
- * @param indexY vertical index of item
68
+ * Scroll to the given offsets from the top/start of the scroll container.
69
+ * @param offset the offsets. The axis whose offset is omitted is not scrolled.
84
70
  */
85
- scrollToIndex(indexX?: number, indexY?: number): void;
71
+ scrollTo(offset: {
72
+ vertical?: number;
73
+ horizontal?: number;
74
+ }): void;
86
75
  /**
87
- * Scroll to the given offset.
88
- * @param offsetX offset from left
89
- * @param offsetY offset from top
76
+ * Scroll by the given offsets from the current position.
77
+ * @param offset the offsets. The axis whose offset is omitted is not scrolled.
90
78
  */
91
- scrollTo(offsetX?: number, offsetY?: number): void;
92
- /**
93
- * Scroll by the given offset.
94
- * @param offsetX horizontal offset from current position
95
- * @param offsetY vertical offset from current position
96
- */
97
- scrollBy(offsetX?: number, offsetY?: number): void;
79
+ scrollBy(offset: {
80
+ vertical?: number;
81
+ horizontal?: number;
82
+ }): void;
98
83
  }
99
84
  /**
100
85
  * Props of {@link VGrid}.
101
86
  */
102
- export interface VGridProps extends ViewportComponentAttributes {
87
+ export interface VGridProps<R = number, C = number> extends Omit<ViewportComponentAttributes, "role"> {
88
+ /**
89
+ * A function to create cell elements rendered by this component.
90
+ * @param row the item of {@link VGridProps.rows} at the row of the cell, or the row index if {@link VGridProps.rows} is a number
91
+ * @param col the item of {@link VGridProps.cols} at the column of the cell, or the column index if {@link VGridProps.cols} is a number
92
+ * @param cell the row index and the column index of the cell
93
+ */
94
+ children: (row: R, col: C, cell: Readonly<VGridCell>) => ReactNode;
95
+ /**
96
+ * The rows of the grid. See {@link VGridAxis} for the accepted values.
97
+ */
98
+ rows: VGridAxis<R>;
99
+ /**
100
+ * The columns of the grid. See {@link VGridAxis} for the accepted values.
101
+ */
102
+ cols: VGridAxis<C>;
103
+ /**
104
+ * The heights of the rows. See {@link VGridSize} for the accepted values.
105
+ */
106
+ rowHeight: NoInfer<VGridSize<R>>;
107
+ /**
108
+ * The widths of the columns. See {@link VGridSize} for the accepted values.
109
+ */
110
+ colWidth: NoInfer<VGridSize<C>>;
111
+ /**
112
+ * The number of the leading rows pinned to the start, which are the column headers (`role="columnheader"`).
113
+ *
114
+ * **The pinned cells are rendered over the other cells, so give them an opaque background.**
115
+ * @defaultValue 0
116
+ */
117
+ headerRows?: number;
118
+ /**
119
+ * Indexes of the rows which start sections. A section lasts until the next section row or the footer rows, and its first row sticks below the header rows while the section is scrolled through.
120
+ *
121
+ * **The section rows are rendered over the other cells while they stick, so give them an opaque background.**
122
+ */
123
+ sectionRows?: readonly number[];
103
124
  /**
104
- * A function to create elements rendered by this component.
125
+ * The number of the trailing rows pinned to the end.
126
+ *
127
+ * **The pinned cells are rendered over the other cells, so give them an opaque background.**
128
+ * @defaultValue 0
105
129
  */
106
- children: (arg: {
107
- /**
108
- * row index of cell
109
- */
110
- rowIndex: number;
111
- /**
112
- * column index of cell
113
- */
114
- colIndex: number;
115
- }) => ReactNode;
130
+ footerRows?: number;
116
131
  /**
117
- * Total row length of grid.
132
+ * The number of the leading columns pinned to the start, the last of which is the row header (`role="rowheader"`).
133
+ *
134
+ * **The pinned cells are rendered over the other cells, so give them an opaque background.**
135
+ * @defaultValue 0
118
136
  */
119
- row: number;
137
+ headerCols?: number;
120
138
  /**
121
- * Total column length of grid.
139
+ * The number of the trailing columns pinned to the end.
140
+ *
141
+ * **The pinned cells are rendered over the other cells, so give them an opaque background.**
142
+ * @defaultValue 0
122
143
  */
123
- col: number;
144
+ footerCols?: number;
124
145
  /**
125
- * Cell height hint for unmeasured items. It's recommended to specify this prop if item sizes are fixed and known, or much larger than the defaultValue. It will help to reduce scroll jump when items are measured.
126
- * @defaultValue 40
146
+ * Cells merged over multiple rows and/or columns. See {@link VGridSpan} for the accepted values.
147
+ *
148
+ * The cell at the origin is stretched over the merged area, and the other cells in it are not rendered. Spans must not overlap each other or cross the boundaries of the pinned rows/columns or the sections. A spanning cell is not measured for `"auto"` sizes on the axes it spans, and doesn't enlarge those tracks.
127
149
  */
128
- cellHeight?: number;
150
+ spans?: readonly VGridSpan[];
129
151
  /**
130
- * Cell width hint for unmeasured items. It's recommended to specify this prop if item sizes are fixed and known, or much larger than the defaultValue. It will help to reduce scroll jump when items are measured.
131
- * @defaultValue 100
152
+ * List of cells that should be always mounted, even when off screen.
132
153
  */
133
- cellWidth?: number;
154
+ keepMounted?: readonly VGridCell[];
134
155
  /**
135
- * 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.
156
+ * Extra 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 cells in fast scrolling.
136
157
  * @defaultValue 200
137
158
  */
138
159
  bufferSize?: number;
139
160
  /**
140
- * A prop for SSR. If set, the specified amount of rows will be mounted in the initial rendering regardless of the container size until hydrated.
161
+ * The gap between the rows and the columns in pixels, which is not included in the sizes. Must not be changed after mount.
162
+ * @defaultValue 0
141
163
  */
142
- ssrRowCount?: number;
164
+ gap?: number;
143
165
  /**
144
- * A prop for SSR. If set, the specified amount of cols will be mounted in the initial rendering regardless of the container size until hydrated.
166
+ * The header cell of the sorted column or row, and the sort order (`aria-sort`).
145
167
  */
146
- ssrColCount?: number;
168
+ ariaSort?: VGridCell & {
169
+ order: "ascending" | "descending" | "other";
170
+ };
147
171
  /**
148
- * Component or element type for cell element. This component will get {@link CustomCellComponentProps} as props.
149
- * @defaultValue "div"
172
+ * Callback invoked whenever the vertical scroll offset changes.
173
+ * @param offset Current scrollTop.
150
174
  */
151
- item?: keyof JSX.IntrinsicElements | CustomCellComponent;
152
- /** Reference to the rendered DOM element (the one that scrolls). */
153
- domRef?: Ref<HTMLDivElement>;
175
+ onVerticalScroll?: (offset: number) => void;
154
176
  /**
155
- * Callback invoked whenever scroll offset changes.
177
+ * Callback invoked whenever the horizontal scroll offset changes.
178
+ * @param offset Current scrollLeft. Always positive even in RTL.
156
179
  */
157
- onScroll?: (offset: number) => void;
180
+ onHorizontalScroll?: (offset: number) => void;
158
181
  /**
159
182
  * Callback invoked when scrolling stops.
160
183
  */
161
184
  onScrollEnd?: () => void;
162
185
  }
163
186
  /**
164
- * Virtualized grid component. See {@link VGridProps} and {@link VGridHandle}.
187
+ * Virtualized grid component for tabular data. See {@link VGridProps} and {@link VGridHandle}.
165
188
  */
166
- export declare const VGrid: React.ForwardRefExoticComponent<VGridProps & React.RefAttributes<VGridHandle>>;
189
+ export declare const VGrid: <R = number, C = number>(props: VGridProps<R, C> & {
190
+ ref?: Ref<VGridHandle>;
191
+ }) => ReactElement;
@@ -4,6 +4,7 @@ export { Virtualizer } from './Virtualizer.js';
4
4
  export type { VirtualizerProps, VirtualizerHandle } from './Virtualizer.js';
5
5
  export { WindowVirtualizer } from './WindowVirtualizer.js';
6
6
  export type { WindowVirtualizerProps, WindowVirtualizerHandle, } from './WindowVirtualizer.js';
7
- export { VGrid as experimental_VGrid } from './VGrid.js';
8
- export type { VGridItemResize, VGridProps, VGridHandle, CustomCellComponent, CustomCellComponentProps, } from './VGrid.js';
7
+ export { VGrid } from './VGrid.js';
8
+ export type { VGridProps, VGridHandle } from './VGrid.js';
9
+ export type { VGridSize, VGridSpan } from '../core/index.js';
9
10
  export type * from './types.js';
@@ -0,0 +1,193 @@
1
+ import { JSX } from 'solid-js';
2
+ import { VGridScrollToIndexOpts, VGridAxis, VGridCell, VGridSize, VGridSpan } from '../core/index.js';
3
+ import { ViewportComponentAttributes } from './types.js';
4
+ /**
5
+ * Methods of {@link VGrid}.
6
+ */
7
+ export interface VGridHandle {
8
+ /**
9
+ * Get current scrollTop.
10
+ */
11
+ readonly verticalScrollOffset: number;
12
+ /**
13
+ * Get current scrollLeft. Always positive even in RTL.
14
+ */
15
+ readonly horizontalScrollOffset: number;
16
+ /**
17
+ * Get current scrollHeight.
18
+ */
19
+ readonly scrollHeight: number;
20
+ /**
21
+ * Get current scrollWidth.
22
+ */
23
+ readonly scrollWidth: number;
24
+ /**
25
+ * Get current clientHeight.
26
+ */
27
+ readonly viewportHeight: number;
28
+ /**
29
+ * Get current clientWidth.
30
+ */
31
+ readonly viewportWidth: number;
32
+ /**
33
+ * Find nearest row index from offset.
34
+ * @param offset offset in pixels from the top of the scroll container
35
+ */
36
+ findRowIndex(offset: number): number;
37
+ /**
38
+ * Find nearest column index from offset.
39
+ * @param offset offset in pixels from the start of the scroll container
40
+ */
41
+ findColIndex(offset: number): number;
42
+ /**
43
+ * Get offset of the row from the top.
44
+ * @param index index of row
45
+ */
46
+ getRowOffset(index: number): number;
47
+ /**
48
+ * Get offset of the column from the start.
49
+ * @param index index of column
50
+ */
51
+ getColOffset(index: number): number;
52
+ /**
53
+ * Get size of the row.
54
+ * @param index index of row
55
+ */
56
+ getRowSize(index: number): number;
57
+ /**
58
+ * Get size of the column.
59
+ * @param index index of column
60
+ */
61
+ getColSize(index: number): number;
62
+ /**
63
+ * Scroll to the cell specified by the indexes. The cell is not hidden behind the rows and the columns sticking over it.
64
+ * @param opts the indexes of the cell and the options. See {@link VGridScrollToIndexOpts}.
65
+ */
66
+ scrollToIndex(opts: VGridScrollToIndexOpts): void;
67
+ /**
68
+ * Scroll to the given offsets from the top/start of the scroll container.
69
+ * @param offset the offsets. The axis whose offset is omitted is not scrolled.
70
+ */
71
+ scrollTo(offset: {
72
+ vertical?: number;
73
+ horizontal?: number;
74
+ }): void;
75
+ /**
76
+ * Scroll by the given offsets from the current position.
77
+ * @param offset the offsets. The axis whose offset is omitted is not scrolled.
78
+ */
79
+ scrollBy(offset: {
80
+ vertical?: number;
81
+ horizontal?: number;
82
+ }): void;
83
+ }
84
+ /**
85
+ * Props of {@link VGrid}.
86
+ */
87
+ export interface VGridProps<R = number, C = number> extends Omit<ViewportComponentAttributes, "role"> {
88
+ /**
89
+ * Get reference to {@link VGridHandle}.
90
+ */
91
+ ref?: VGridHandle | ((handle?: VGridHandle) => void);
92
+ /**
93
+ * A function to create cell elements rendered by this component.
94
+ * @param row the item of {@link VGridProps.rows} at the row of the cell, or the row index if {@link VGridProps.rows} is a number
95
+ * @param col the item of {@link VGridProps.cols} at the column of the cell, or the column index if {@link VGridProps.cols} is a number
96
+ * @param cell the row index and the column index of the cell
97
+ */
98
+ children: (row: R, col: C, cell: Readonly<VGridCell>) => JSX.Element;
99
+ /**
100
+ * The rows of the grid. See {@link VGridAxis} for the accepted values.
101
+ */
102
+ rows: VGridAxis<R>;
103
+ /**
104
+ * The columns of the grid. See {@link VGridAxis} for the accepted values.
105
+ */
106
+ cols: VGridAxis<C>;
107
+ /**
108
+ * The heights of the rows. See {@link VGridSize} for the accepted values.
109
+ */
110
+ rowHeight: NoInfer<VGridSize<R>>;
111
+ /**
112
+ * The widths of the columns. See {@link VGridSize} for the accepted values.
113
+ */
114
+ colWidth: NoInfer<VGridSize<C>>;
115
+ /**
116
+ * The number of the leading rows pinned to the start, which are the column headers (`role="columnheader"`).
117
+ *
118
+ * **The pinned cells are rendered over the other cells, so give them an opaque background.**
119
+ * @defaultValue 0
120
+ */
121
+ headerRows?: number;
122
+ /**
123
+ * Indexes of the rows which start sections. A section lasts until the next section row or the footer rows, and its first row sticks below the header rows while the section is scrolled through.
124
+ *
125
+ * **The section rows are rendered over the other cells while they stick, so give them an opaque background.**
126
+ */
127
+ sectionRows?: readonly number[];
128
+ /**
129
+ * The number of the trailing rows pinned to the end.
130
+ *
131
+ * **The pinned cells are rendered over the other cells, so give them an opaque background.**
132
+ * @defaultValue 0
133
+ */
134
+ footerRows?: number;
135
+ /**
136
+ * The number of the leading columns pinned to the start, the last of which is the row header (`role="rowheader"`).
137
+ *
138
+ * **The pinned cells are rendered over the other cells, so give them an opaque background.**
139
+ * @defaultValue 0
140
+ */
141
+ headerCols?: number;
142
+ /**
143
+ * The number of the trailing columns pinned to the end.
144
+ *
145
+ * **The pinned cells are rendered over the other cells, so give them an opaque background.**
146
+ * @defaultValue 0
147
+ */
148
+ footerCols?: number;
149
+ /**
150
+ * Cells merged over multiple rows and/or columns. See {@link VGridSpan} for the accepted values.
151
+ *
152
+ * The cell at the origin is stretched over the merged area, and the other cells in it are not rendered. Spans must not overlap each other or cross the boundaries of the pinned rows/columns or the sections. A spanning cell is not measured for `"auto"` sizes on the axes it spans, and doesn't enlarge those tracks.
153
+ */
154
+ spans?: readonly VGridSpan[];
155
+ /**
156
+ * List of cells that should be always mounted, even when off screen.
157
+ */
158
+ keepMounted?: readonly VGridCell[];
159
+ /**
160
+ * Extra 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 cells in fast scrolling.
161
+ * @defaultValue 200
162
+ */
163
+ bufferSize?: number;
164
+ /**
165
+ * The gap between the rows and the columns in pixels, which is not included in the sizes. Must not be changed after mount.
166
+ * @defaultValue 0
167
+ */
168
+ gap?: number;
169
+ /**
170
+ * The header cell of the sorted column or row, and the sort order (`aria-sort`).
171
+ */
172
+ ariaSort?: VGridCell & {
173
+ order: "ascending" | "descending" | "other";
174
+ };
175
+ /**
176
+ * Callback invoked whenever the vertical scroll offset changes.
177
+ * @param offset Current scrollTop.
178
+ */
179
+ onVerticalScroll?: (offset: number) => void;
180
+ /**
181
+ * Callback invoked whenever the horizontal scroll offset changes.
182
+ * @param offset Current scrollLeft. Always positive even in RTL.
183
+ */
184
+ onHorizontalScroll?: (offset: number) => void;
185
+ /**
186
+ * Callback invoked when scrolling stops.
187
+ */
188
+ onScrollEnd?: () => void;
189
+ }
190
+ /**
191
+ * Virtualized grid component for tabular data. See {@link VGridProps} and {@link VGridHandle}.
192
+ */
193
+ export declare const VGrid: <R = number, C = number>(props: VGridProps<R, C>) => JSX.Element;