vlist-react 0.1.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/LICENSE +21 -0
- package/README.md +48 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +1 -0
- package/package.json +57 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Floor IO
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# vlist-react
|
|
2
|
+
|
|
3
|
+
React hooks for [vlist](https://github.com/floor/vlist) - lightweight, zero-dependency virtual scrolling.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @floor/vlist vlist-react
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
import { useVList } from 'vlist-react';
|
|
15
|
+
import '@floor/vlist/styles';
|
|
16
|
+
|
|
17
|
+
function UserList({ users }) {
|
|
18
|
+
const { containerRef, instanceRef } = useVList({
|
|
19
|
+
item: {
|
|
20
|
+
height: 48,
|
|
21
|
+
template: (user) => `<div class="user">${user.name}</div>`,
|
|
22
|
+
},
|
|
23
|
+
items: users,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return <div ref={containerRef} style={{ height: 400 }} />;
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## API
|
|
31
|
+
|
|
32
|
+
### `useVList(config)`
|
|
33
|
+
|
|
34
|
+
**Parameters:**
|
|
35
|
+
- `config` - VList configuration (same as core vlist, minus `container`)
|
|
36
|
+
|
|
37
|
+
**Returns:**
|
|
38
|
+
- `containerRef` - Ref to attach to your container element
|
|
39
|
+
- `instanceRef` - Reference to the vlist instance
|
|
40
|
+
- `getInstance()` - Helper function to get the instance
|
|
41
|
+
|
|
42
|
+
## Documentation
|
|
43
|
+
|
|
44
|
+
For full documentation, see [vlist.dev](https://vlist.dev)
|
|
45
|
+
|
|
46
|
+
## License
|
|
47
|
+
|
|
48
|
+
MIT © [Floor IO](https://floor.io)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React hooks for vlist - lightweight virtual scrolling
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
import type { VListConfig, VListItem, VList, VListEvents, EventHandler } from "@floor/vlist";
|
|
7
|
+
/** Configuration for useVList (VListConfig without container) */
|
|
8
|
+
export type UseVListConfig<T extends VListItem = VListItem> = Omit<VListConfig<T>, "container">;
|
|
9
|
+
/** Return value from the useVList hook */
|
|
10
|
+
export interface UseVListReturn<T extends VListItem = VListItem> {
|
|
11
|
+
containerRef: React.RefObject<HTMLDivElement | null>;
|
|
12
|
+
instanceRef: React.RefObject<VList<T> | null>;
|
|
13
|
+
getInstance: () => VList<T> | null;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* React hook for vlist integration.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* import { useVList } from 'vlist-react';
|
|
21
|
+
* import '@floor/vlist/styles';
|
|
22
|
+
*
|
|
23
|
+
* function UserList({ users }) {
|
|
24
|
+
* const { containerRef, instanceRef } = useVList({
|
|
25
|
+
* item: {
|
|
26
|
+
* height: 48,
|
|
27
|
+
* template: (user) => `<div>${user.name}</div>`,
|
|
28
|
+
* },
|
|
29
|
+
* items: users,
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* return <div ref={containerRef} style={{ height: 400 }} />;
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function useVList<T extends VListItem = VListItem>(config: UseVListConfig<T>): UseVListReturn<T>;
|
|
37
|
+
/**
|
|
38
|
+
* Subscribe to vlist events within React lifecycle
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```tsx
|
|
42
|
+
* useVListEvent(instanceRef, 'selection:change', ({ selected }) => {
|
|
43
|
+
* console.log('Selected:', selected);
|
|
44
|
+
* });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function useVListEvent<T extends VListItem, K extends keyof VListEvents<T>>(instanceRef: React.RefObject<VList<T> | null>, event: K, handler: EventHandler<VListEvents<T>[K]>): void;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useRef as J,useEffect as Q,useCallback as X}from"react";import{vlist as Y}from"@floor/vlist";import{withAsync as Z,withGrid as _,withSections as $,withSelection as U,withScrollbar as k,withScale as A,withSnapshots as G,withPage as H}from"@floor/vlist";function V(B){let F=J(null),z=J(null),q=J(B);q.current=B;let D=J(!1);Q(()=>{let M=F.current;if(!M)return;let j=Y({...q.current,container:M});if(q.current.scroll?.element===window)j=j.use(H());if(q.current.adapter)j=j.use(Z({adapter:q.current.adapter,...q.current.loading&&{loading:q.current.loading}}));if(q.current.layout==="grid"&&q.current.grid)j=j.use(_(q.current.grid));if(q.current.groups)j=j.use($(q.current.groups));if((q.current.selection?.mode||"none")!=="none")j=j.use(U(q.current.selection));else j=j.use(U({mode:"none"}));j=j.use(A());let N=q.current.scroll?.scrollbar||q.current.scrollbar;if(N!=="none"){let W=typeof N==="object"?N:{};j=j.use(k(W))}j=j.use(G());let T=j.build();return z.current=T,D.current=!0,()=>{D.current=!1,T.destroy(),z.current=null}},[]),Q(()=>{if(!D.current||!z.current)return;if(B.items)z.current.setItems(B.items)},[B.items]);let K=X(()=>{return z.current},[]);return{containerRef:F,instanceRef:z,getInstance:K}}function x(B,F,z){let q=J(z);q.current=z,Q(()=>{let D=B.current;if(!D)return;let K=(j)=>{q.current(j)};return D.on(F,K)},[B.current,F])}export{x as useVListEvent,V as useVList};
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vlist-react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "React hooks for vlist - lightweight virtual scrolling",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Floor IO",
|
|
7
|
+
"url": "https://floor.io"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/floor/vlist-react.git"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"vlist",
|
|
15
|
+
"virtual-list",
|
|
16
|
+
"react",
|
|
17
|
+
"hooks",
|
|
18
|
+
"virtual-scrolling",
|
|
19
|
+
"typescript"
|
|
20
|
+
],
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"type": "module",
|
|
23
|
+
"main": "./dist/index.js",
|
|
24
|
+
"module": "./dist/index.js",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"import": "./dist/index.js",
|
|
30
|
+
"default": "./dist/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./package.json": "./package.json"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@floor/vlist": "^0.6.0",
|
|
36
|
+
"react": ">=17.0.0"
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"dist/**/*.js",
|
|
40
|
+
"dist/**/*.d.ts",
|
|
41
|
+
"!dist/**/*.d.ts.map"
|
|
42
|
+
],
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "bun run build.ts",
|
|
45
|
+
"dev": "bun run build.ts --watch",
|
|
46
|
+
"typecheck": "tsc --noEmit",
|
|
47
|
+
"prepublishOnly": "bun run build"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@floor/vlist": "link:../vlist",
|
|
51
|
+
"@types/bun": "^1.0.0",
|
|
52
|
+
"@types/react": "^19.2.13",
|
|
53
|
+
"bun": "^1.0.0",
|
|
54
|
+
"react": "^19.2.4",
|
|
55
|
+
"typescript": "^5.0.0"
|
|
56
|
+
}
|
|
57
|
+
}
|