vlist-react 0.1.0 → 0.1.1
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/dist/index.d.ts +5 -39
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,47 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* React hooks for vlist - lightweight virtual scrolling
|
|
3
|
-
*
|
|
4
|
-
* @packageDocumentation
|
|
5
3
|
*/
|
|
6
|
-
import type { VListConfig, VListItem,
|
|
7
|
-
|
|
4
|
+
import type { VListConfig, VListItem, VListEvents, EventHandler } from "@floor/vlist";
|
|
5
|
+
import { type BuiltVList } from "@floor/vlist";
|
|
8
6
|
export type UseVListConfig<T extends VListItem = VListItem> = Omit<VListConfig<T>, "container">;
|
|
9
|
-
/** Return value from the useVList hook */
|
|
10
7
|
export interface UseVListReturn<T extends VListItem = VListItem> {
|
|
11
8
|
containerRef: React.RefObject<HTMLDivElement | null>;
|
|
12
|
-
instanceRef: React.RefObject<
|
|
13
|
-
getInstance: () =>
|
|
9
|
+
instanceRef: React.RefObject<BuiltVList<T> | null>;
|
|
10
|
+
getInstance: () => BuiltVList<T> | null;
|
|
14
11
|
}
|
|
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
12
|
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;
|
|
13
|
+
export declare function useVListEvent<T extends VListItem, K extends keyof VListEvents<T>>(instanceRef: React.RefObject<BuiltVList<T> | null>, event: K, handler: EventHandler<VListEvents<T>[K]>): void;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useRef as
|
|
1
|
+
import{useRef as c,useEffect as f,useCallback as p}from"react";import{vlist as V}from"@floor/vlist";import{withAsync as g,withGrid as h,withSections as T,withSelection as m,withScrollbar as b,withScale as R,withSnapshots as v,withPage as I}from"@floor/vlist";function H(s){let u=c(null),n=c(null),t=c(s);t.current=s;let i=c(!1);f(()=>{let l=u.current;if(!l)return;let e=V({...t.current,container:l});if(t.current.scroll?.element===window)e=e.use(I());if(t.current.adapter)e=e.use(g({adapter:t.current.adapter,...t.current.loading&&{loading:t.current.loading}}));if(t.current.layout==="grid"&&t.current.grid)e=e.use(h(t.current.grid));if(t.current.groups){let r=t.current.groups,L=typeof r.headerHeight==="function"?r.headerHeight("",0):r.headerHeight;e=e.use(T({getGroupForIndex:r.getGroupForIndex,headerHeight:L,headerTemplate:r.headerTemplate,...r.sticky!==void 0&&{sticky:r.sticky}}))}if((t.current.selection?.mode||"none")!=="none")e=e.use(m(t.current.selection));else e=e.use(m({mode:"none"}));e=e.use(R());let a=t.current.scroll?.scrollbar||t.current.scrollbar;if(a!=="none"){let r=typeof a==="object"?a:{};e=e.use(b(r))}e=e.use(v());let d=e.build();return n.current=d,i.current=!0,()=>{i.current=!1,d.destroy(),n.current=null}},[]),f(()=>{if(!i.current||!n.current)return;if(s.items)n.current.setItems(s.items)},[s.items]);let o=p(()=>{return n.current},[]);return{containerRef:u,instanceRef:n,getInstance:o}}function C(s,u,n){let t=c(n);t.current=n,f(()=>{let i=s.current;if(!i)return;let o=(e)=>{t.current(e)};return i.on(u,o)},[s.current,u])}export{C as useVListEvent,H as useVList};
|