virtua 0.4.5 → 0.6.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.
@@ -1,5 +1,5 @@
1
1
  import { CSSProperties, ReactNode } from "react";
2
- import { CustomWindowComponent, WindowComponentAttributes } from "..";
2
+ import { CustomViewportComponent, ViewportComponentAttributes } from "..";
3
3
  /**
4
4
  * Props of customized cell component for {@link VGrid}.
5
5
  */
@@ -47,7 +47,7 @@ export interface VGridHandle {
47
47
  /**
48
48
  * Props of {@link VGrid}.
49
49
  */
50
- export interface VGridProps extends WindowComponentAttributes {
50
+ export interface VGridProps extends ViewportComponentAttributes {
51
51
  /**
52
52
  * A function to create elements rendered by this component.
53
53
  */
@@ -97,15 +97,20 @@ export interface VGridProps extends WindowComponentAttributes {
97
97
  */
98
98
  rtl?: boolean;
99
99
  /**
100
- * Customized element type for scrollable element. This element will get {@link CustomWindowComponentProps} as props.
101
- * @defaultValue {@link Window}
100
+ * Customized components for advanced usage.
102
101
  */
103
- element?: CustomWindowComponent;
104
- /**
105
- * Customized element type for cell element. This element will get {@link CustomCellComponentProps} as props.
106
- * @defaultValue "div"
107
- */
108
- cellElement?: CustomCellComponentOrElement;
102
+ components?: {
103
+ /**
104
+ * Component for scrollable element. This component will get {@link CustomViewportComponentProps} as props.
105
+ * @defaultValue {@link DefaultViewport}
106
+ */
107
+ Root?: CustomViewportComponent;
108
+ /**
109
+ * Component or element type for cell element. This component will get {@link CustomCellComponentProps} as props.
110
+ * @defaultValue "div"
111
+ */
112
+ Cell?: CustomCellComponentOrElement;
113
+ };
109
114
  }
110
115
  /**
111
116
  * Virtualized grid component. See {@link VGridProps} and {@link VGridHandle}.
@@ -1,6 +1,6 @@
1
1
  import { ReactNode } from "react";
2
- import { WindowComponentAttributes } from "..";
3
- import { CustomWindowComponent } from "./Window";
2
+ import { ViewportComponentAttributes } from "..";
3
+ import { CustomViewportComponent } from "./Viewport";
4
4
  import { CustomItemComponent } from "./ListItem";
5
5
  import { CacheSnapshot } from "../core/types";
6
6
  export type ScrollMode = "reverse" | "rtl";
@@ -44,7 +44,7 @@ export interface VListHandle {
44
44
  /**
45
45
  * Props of {@link VList}.
46
46
  */
47
- export interface VListProps extends WindowComponentAttributes {
47
+ export interface VListProps extends ViewportComponentAttributes {
48
48
  /**
49
49
  * Elements rendered by this component.
50
50
  */
@@ -81,15 +81,20 @@ export interface VListProps extends WindowComponentAttributes {
81
81
  */
82
82
  cache?: CacheSnapshot;
83
83
  /**
84
- * Customized element type for scrollable element. This element will get {@link CustomWindowComponentProps} as props.
85
- * @defaultValue {@link Window}
84
+ * Customized components for advanced usage.
86
85
  */
87
- element?: CustomWindowComponent;
88
- /**
89
- * Customized element type for item element. This element will get {@link CustomItemComponentProps} as props.
90
- * @defaultValue "div"
91
- */
92
- itemElement?: CustomItemComponentOrElement;
86
+ components?: {
87
+ /**
88
+ * Component for scrollable element. This component will get {@link CustomViewportComponentProps} as props.
89
+ * @defaultValue {@link DefaultViewport}
90
+ */
91
+ Root?: CustomViewportComponent;
92
+ /**
93
+ * Component or element type for item element. This component will get {@link CustomItemComponentProps} as props.
94
+ * @defaultValue "div"
95
+ */
96
+ Item?: CustomItemComponentOrElement;
97
+ };
93
98
  /**
94
99
  * Callback invoked whenever scroll offset changes.
95
100
  * @param offset Current scrollTop or scrollLeft.
@@ -102,20 +107,15 @@ export interface VListProps extends WindowComponentAttributes {
102
107
  /**
103
108
  * Callback invoked when visible items range changes.
104
109
  */
105
- onRangeChange?: (payload: {
106
- /**
107
- * The start index of viewable items.
108
- */
109
- start: number;
110
- /**
111
- * The end index of viewable items.
112
- */
113
- end: number;
114
- /**
115
- * The total count of items.
116
- */
117
- count: number;
118
- }) => void;
110
+ onRangeChange?: (
111
+ /**
112
+ * The start index of viewable items.
113
+ */
114
+ startIndex: number,
115
+ /**
116
+ * The end index of viewable items.
117
+ */
118
+ endIndex: number) => void;
119
119
  }
120
120
  /**
121
121
  * Virtualized list component. See {@link VListProps} and {@link VListHandle}.
@@ -1,9 +1,9 @@
1
1
  import { ReactNode } from "react";
2
- export type WindowComponentAttributes = Pick<React.HTMLAttributes<HTMLElement>, "className" | "style" | "id" | "role" | "tabIndex"> & React.AriaAttributes;
2
+ export type ViewportComponentAttributes = Pick<React.HTMLAttributes<HTMLElement>, "className" | "style" | "id" | "role" | "tabIndex"> & React.AriaAttributes;
3
3
  /**
4
4
  * Props of customized scrollable component.
5
5
  */
6
- export interface CustomWindowComponentProps {
6
+ export interface CustomViewportComponentProps {
7
7
  /**
8
8
  * Renderable item elements.
9
9
  */
@@ -11,7 +11,7 @@ export interface CustomWindowComponentProps {
11
11
  /**
12
12
  * Attributes that should be passed to the scrollable element.
13
13
  */
14
- attrs: WindowComponentAttributes;
14
+ attrs: ViewportComponentAttributes;
15
15
  /**
16
16
  * Total height of items. It's undefined if component is not vertically scrollable.
17
17
  */
@@ -25,5 +25,5 @@ export interface CustomWindowComponentProps {
25
25
  */
26
26
  scrolling: boolean;
27
27
  }
28
- export declare const Window: import("react").ForwardRefExoticComponent<CustomWindowComponentProps & import("react").RefAttributes<any>>;
29
- export type CustomWindowComponent = typeof Window;
28
+ export declare const Viewport: import("react").ForwardRefExoticComponent<CustomViewportComponentProps & import("react").RefAttributes<any>>;
29
+ export type CustomViewportComponent = typeof Viewport;
@@ -1,6 +1,6 @@
1
1
  import { ReactNode } from "react";
2
- import { CacheSnapshot, WindowComponentAttributes } from "..";
3
- import { CustomWindowComponent } from "./Window";
2
+ import { CacheSnapshot, ViewportComponentAttributes } from "..";
3
+ import { CustomViewportComponent } from "./Viewport";
4
4
  import { CustomItemComponent } from "./ListItem";
5
5
  type CustomItemComponentOrElement = keyof JSX.IntrinsicElements | CustomItemComponent;
6
6
  /**
@@ -15,7 +15,7 @@ export interface WVListHandle {
15
15
  /**
16
16
  * Props of {@link WVList}.
17
17
  */
18
- export interface WVListProps extends WindowComponentAttributes {
18
+ export interface WVListProps extends ViewportComponentAttributes {
19
19
  /**
20
20
  * Elements rendered by this component.
21
21
  */
@@ -45,15 +45,20 @@ export interface WVListProps extends WindowComponentAttributes {
45
45
  */
46
46
  cache?: CacheSnapshot;
47
47
  /**
48
- * Customized element type for scrollable element. This element will get {@link CustomWindowComponentProps} as props.
49
- * @defaultValue {@link Window}
48
+ * Customized components for advanced usage.
50
49
  */
51
- element?: CustomWindowComponent;
52
- /**
53
- * Customized element type for item element. This element will get {@link CustomItemComponentProps} as props.
54
- * @defaultValue "div"
55
- */
56
- itemElement?: CustomItemComponentOrElement;
50
+ components?: {
51
+ /**
52
+ * Component for scrollable element. This component will get {@link CustomViewportComponentProps} as props.
53
+ * @defaultValue {@link DefaultViewport}
54
+ */
55
+ Root?: CustomViewportComponent;
56
+ /**
57
+ * Component or element type for item element. This component will get {@link CustomItemComponentProps} as props.
58
+ * @defaultValue "div"
59
+ */
60
+ Item?: CustomItemComponentOrElement;
61
+ };
57
62
  /**
58
63
  * Callback invoked when scrolling stops.
59
64
  */
@@ -61,23 +66,18 @@ export interface WVListProps extends WindowComponentAttributes {
61
66
  /**
62
67
  * Callback invoked when visible items range changes.
63
68
  */
64
- onRangeChange?: (payload: {
65
- /**
66
- * The start index of viewable items.
67
- */
68
- start: number;
69
- /**
70
- * The end index of viewable items.
71
- */
72
- end: number;
73
- /**
74
- * The total count of items.
75
- */
76
- count: number;
77
- }) => void;
69
+ onRangeChange?: (
70
+ /**
71
+ * The start index of viewable items.
72
+ */
73
+ startIndex: number,
74
+ /**
75
+ * The end index of viewable items.
76
+ */
77
+ endIndex: number) => void;
78
78
  }
79
79
  /**
80
- * Virtualized list component controlled by the window scrolling. See {@link WVListProps}.
80
+ * Virtualized list component controlled by the window scrolling. See {@link WVListProps} and {@link WVListHandle}.
81
81
  */
82
82
  export declare const WVList: import("react").ForwardRefExoticComponent<WVListProps & import("react").RefAttributes<WVListHandle>>;
83
83
  export {};
@@ -0,0 +1,8 @@
1
+ export { VList } from "./VList";
2
+ export type { VListProps, VListHandle, ScrollMode } from "./VList";
3
+ export { VGrid } from "./VGrid";
4
+ export type { VGridProps, VGridHandle, CustomCellComponent, CustomCellComponentProps, } from "./VGrid";
5
+ export { WVList } from "./WVList";
6
+ export type { WVListProps, WVListHandle } from "./WVList";
7
+ export type { ViewportComponentAttributes, CustomViewportComponent, CustomViewportComponentProps, } from "./Viewport";
8
+ export type { CustomItemComponent, CustomItemComponentProps } from "./ListItem";
@@ -1,2 +1,7 @@
1
1
  import { VirtualStore } from "../core/store";
2
- export declare const useSelector: <T>(store: VirtualStore, getSnapShot: () => T, shouldGetLatest?: boolean) => T;
2
+ export declare const SELECT_RANGE: number;
3
+ export declare const SELECT_SCROLL_SIZE = 2;
4
+ export declare const SELECT_JUMP_COUNT = 4;
5
+ export declare const SELECT_IS_SCROLLING = 8;
6
+ export declare const SELECT_ITEM = 2;
7
+ export declare const useSelector: <T>(store: VirtualStore, getSnapShot: () => T, target: number, shouldGetLatest?: boolean) => T;
@@ -1,5 +1,6 @@
1
1
  import { ReactElement, ReactFragment, ReactNode } from "react";
2
2
  export declare const refKey = "current";
3
+ export declare const emptyComponents: {};
3
4
  export declare const flattenChildren: (children: ReactNode) => (string | number | ReactElement<any, string | import("react").JSXElementConstructor<any>> | ReactFragment)[];
4
5
  export type MayHaveKey = {
5
6
  key?: React.Key;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "virtua",
3
- "version": "0.4.5",
3
+ "version": "0.6.0",
4
4
  "description": "A zero-config, fast and small (~3kB) virtual list and grid component for React.",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.mjs",
@@ -29,22 +29,22 @@
29
29
  "@emotion/react": "11.10.8",
30
30
  "@emotion/styled": "11.10.8",
31
31
  "@faker-js/faker": "8.0.2",
32
- "@mui/material": "5.12.3",
33
- "@playwright/test": "^1.36.1",
32
+ "@mui/material": "5.14.2",
33
+ "@playwright/test": "^1.36.2",
34
34
  "@rollup/plugin-babel": "6.0.3",
35
35
  "@rollup/plugin-terser": "0.4.3",
36
36
  "@rollup/plugin-typescript": "11.1.2",
37
37
  "@size-limit/preset-small-lib": "^8.2.6",
38
- "@storybook/addon-docs": "7.1.0",
39
- "@storybook/react": "7.1.0",
40
- "@storybook/react-vite": "^7.1.0",
41
- "@storybook/test-runner": "0.11.0",
38
+ "@storybook/addon-storysource": "7.1.1",
39
+ "@storybook/react": "7.1.1",
40
+ "@storybook/react-vite": "^7.1.1",
41
+ "@storybook/test-runner": "0.12.0",
42
42
  "@tanstack/react-virtual": "3.0.0-alpha.0",
43
43
  "@testing-library/react": "14.0.0",
44
- "@types/react": "18.2.15",
44
+ "@types/react": "18.2.17",
45
45
  "@types/react-virtualized": "9.21.22",
46
46
  "@types/react-window": "1.8.5",
47
- "@typescript-eslint/parser": "6.1.0",
47
+ "@typescript-eslint/parser": "6.2.0",
48
48
  "concurrently": "8.2.0",
49
49
  "eslint": "8.45.0",
50
50
  "eslint-plugin-react-hooks": "4.6.0",
@@ -58,21 +58,21 @@
58
58
  "react-is": "18.2.0",
59
59
  "react-merge-refs": "2.0.2",
60
60
  "react-pull-to-refresh": "2.0.1",
61
- "react-select": "5.7.3",
61
+ "react-select": "5.7.4",
62
62
  "react-virtualized": "9.22.5",
63
- "react-virtuoso": "4.4.1",
63
+ "react-virtuoso": "4.4.2",
64
64
  "react-window": "1.8.9",
65
65
  "rimraf": "5.0.1",
66
66
  "rollup": "3.26.3",
67
67
  "rollup-plugin-banner2": "1.2.2",
68
68
  "size-limit": "^8.2.6",
69
- "storybook": "^7.1.0",
69
+ "storybook": "^7.1.1",
70
70
  "ts-jest": "29.1.1",
71
- "typedoc": "0.24.7",
72
- "typedoc-plugin-markdown": "3.15.3",
71
+ "typedoc": "0.24.8",
72
+ "typedoc-plugin-markdown": "3.15.4",
73
73
  "typescript": "5.1.6",
74
- "virtua": "^0.4.4",
75
- "vite": "4.4.6",
74
+ "virtua": "^0.4.5",
75
+ "vite": "4.4.7",
76
76
  "wait-on": "7.0.1"
77
77
  },
78
78
  "peerDependencies": {