virtua 0.4.0 → 0.4.2

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.
@@ -0,0 +1,22 @@
1
+ import { CSSProperties, ReactElement, ReactNode } from "react";
2
+ import { VirtualStore } from "../core/store";
3
+ import { ListResizer } from "../core/resizer";
4
+ /**
5
+ * Props of customized item component for {@link VList}.
6
+ */
7
+ export interface CustomItemComponentProps {
8
+ style: CSSProperties;
9
+ children: ReactNode;
10
+ }
11
+ export type CustomItemComponent = React.ForwardRefExoticComponent<React.PropsWithoutRef<CustomItemComponentProps> & React.RefAttributes<any>>;
12
+ type ListItemProps = {
13
+ _children: ReactNode;
14
+ _resizer: ListResizer;
15
+ _store: VirtualStore;
16
+ _index: number;
17
+ _element: "div";
18
+ _isHorizontal: boolean;
19
+ _isRtl: boolean;
20
+ };
21
+ export declare const ListItem: import("react").MemoExoticComponent<({ _children: children, _resizer: resizer, _store: store, _index: index, _element: Element, _isHorizontal: isHorizontal, _isRtl: isRtl, }: ListItemProps) => ReactElement>;
22
+ export {};
@@ -1,15 +1,8 @@
1
- import { CSSProperties, ReactNode } from "react";
1
+ import { ReactNode } from "react";
2
2
  import { WindowComponentAttributes } from "..";
3
3
  import { CustomWindowComponent } from "./DefaultWindow";
4
+ import { CustomItemComponent } from "./ListItem";
4
5
  export type ScrollMode = "reverse" | "rtl";
5
- /**
6
- * Props of customized item component for {@link VList}.
7
- */
8
- export interface CustomItemComponentProps {
9
- style: CSSProperties;
10
- children: ReactNode;
11
- }
12
- export type CustomItemComponent = React.ForwardRefExoticComponent<React.PropsWithoutRef<CustomItemComponentProps> & React.RefAttributes<any>>;
13
6
  type CustomItemComponentOrElement = keyof JSX.IntrinsicElements | CustomItemComponent;
14
7
  /**
15
8
  * Methods of {@link VList}.
@@ -74,7 +67,7 @@ export interface VListProps extends WindowComponentAttributes {
74
67
  /**
75
68
  * Scroll modes that should be set in certain situations.
76
69
  *
77
- * - `reverse`: This mode will Adjust some styles to be suitable for bottom-to-top scrolling.
70
+ * - `reverse`: This mode will adjust some styles to be suitable for bottom-to-top scrolling.
78
71
  * - `rtl`: You have to set this mode if you use this component under `direction: rtl` style.
79
72
  */
80
73
  mode?: ScrollMode;
@@ -0,0 +1,75 @@
1
+ import { ReactElement, ReactNode } from "react";
2
+ import { WindowComponentAttributes } from "..";
3
+ import { CustomWindowComponent } from "./DefaultWindow";
4
+ import { CustomItemComponent } from "./ListItem";
5
+ type CustomItemComponentOrElement = keyof JSX.IntrinsicElements | CustomItemComponent;
6
+ /**
7
+ * Props of {@link WVList}.
8
+ */
9
+ export interface WVListProps extends WindowComponentAttributes {
10
+ /**
11
+ * Elements rendered by this component.
12
+ */
13
+ children: ReactNode;
14
+ /**
15
+ * Number of items to render above/below the visible bounds of the list. You can increase to avoid showing blank items in fast scrolling.
16
+ * @defaultValue 4
17
+ */
18
+ overscan?: number;
19
+ /**
20
+ * Item size hint for unmeasured items. It will help to reduce scroll jump when items are measured if used properly.
21
+ *
22
+ * - If not set, initial item sizes will be automatically estimated from measured sizes. This is recommended for most cases.
23
+ * - If set, you can opt out estimation and use the value as initial item size.
24
+ */
25
+ initialItemSize?: number;
26
+ /**
27
+ * If set, the specified amount of items will be mounted in the initial rendering regardless of the container size. This prop is mostly for SSR.
28
+ */
29
+ initialItemCount?: number;
30
+ /**
31
+ * If true, rendered as a horizontally scrollable list. Otherwise rendered as a vertically scrollable list.
32
+ */
33
+ horizontal?: boolean;
34
+ /**
35
+ * Customized element type for scrollable element. This element will get {@link CustomWindowComponentProps} as props.
36
+ * @defaultValue {@link DefaultWindow}
37
+ */
38
+ element?: CustomWindowComponent;
39
+ /**
40
+ * Customized element type for item element. This element will get {@link CustomItemComponentProps} as props.
41
+ * @defaultValue "div"
42
+ */
43
+ itemElement?: CustomItemComponentOrElement;
44
+ /**
45
+ * Callback invoked whenever scroll offset changes.
46
+ * @param offset Current scrollTop or scrollLeft.
47
+ */
48
+ onScroll?: (offset: number) => void;
49
+ /**
50
+ * Callback invoked when scrolling stops.
51
+ */
52
+ onScrollStop?: () => void;
53
+ /**
54
+ * Callback invoked when visible items range changes.
55
+ */
56
+ onRangeChange?: (payload: {
57
+ /**
58
+ * The start index of viewable items.
59
+ */
60
+ start: number;
61
+ /**
62
+ * The end index of viewable items.
63
+ */
64
+ end: number;
65
+ /**
66
+ * The total count of items.
67
+ */
68
+ count: number;
69
+ }) => void;
70
+ }
71
+ /**
72
+ * Virtualized list component controlled by the window scrolling. See {@link WVListProps}.
73
+ */
74
+ export declare const WVList: ({ children, overscan, initialItemSize, initialItemCount, horizontal: horizontalProp, element, itemElement, onScroll: onScrollProp, onScrollStop: onScrollStopProp, onRangeChange: onRangeChangeProp, ...windowAttrs }: WVListProps) => ReactElement;
75
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "virtua",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
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",
@@ -19,6 +19,7 @@
19
19
  "storybook:test": "concurrently -k -s first -n \"SB,TEST\" -c \"magenta,blue\" \"npm run storybook -- --quiet --no-open\" \"wait-on tcp:6006 && test-storybook\"",
20
20
  "e2e": "npx playwright test",
21
21
  "typedoc": "typedoc",
22
+ "size": "size-limit",
22
23
  "prepublishOnly": "npm run typedoc && rimraf lib && npm run build"
23
24
  },
24
25
  "devDependencies": {
@@ -33,6 +34,7 @@
33
34
  "@rollup/plugin-babel": "6.0.3",
34
35
  "@rollup/plugin-terser": "0.4.3",
35
36
  "@rollup/plugin-typescript": "11.1.2",
37
+ "@size-limit/preset-small-lib": "^8.2.6",
36
38
  "@storybook/addon-docs": "7.0.18",
37
39
  "@storybook/react": "7.0.18",
38
40
  "@storybook/react-vite": "^7.0.18",
@@ -63,12 +65,13 @@
63
65
  "rimraf": "5.0.0",
64
66
  "rollup": "3.23.0",
65
67
  "rollup-plugin-banner2": "1.2.2",
68
+ "size-limit": "^8.2.6",
66
69
  "storybook": "^7.0.18",
67
70
  "ts-jest": "29.1.0",
68
71
  "typedoc": "0.24.7",
69
72
  "typedoc-plugin-markdown": "3.15.3",
70
73
  "typescript": "5.1.3",
71
- "virtua": "^0.3.0",
74
+ "virtua": "^0.4.0",
72
75
  "vite": "4.3.9",
73
76
  "wait-on": "7.0.1"
74
77
  },