react-anchorlist 0.1.0 → 0.2.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/README.md ADDED
@@ -0,0 +1,206 @@
1
+ # react-anchorlist
2
+
3
+ **High-performance virtualized list for React — built for chat.**
4
+
5
+ Zero flicker on prepend. Smooth scroll. Native pagination support. Drop-in replacement for react-virtuoso.
6
+
7
+ ```bash
8
+ npm install react-anchorlist
9
+ ```
10
+
11
+ ---
12
+
13
+ ## Why not react-virtuoso?
14
+
15
+ | Problem | react-virtuoso | react-anchorlist |
16
+ |---|---|---|
17
+ | Flicker when loading older messages | ✗ Yes | ✓ Zero — scroll anchor via `useLayoutEffect` |
18
+ | Prepend hack | `firstItemIndex=10000` | Native prepend detection |
19
+ | `scrollToIndex` needs double-RAF | ✗ Yes | ✓ No — direct offset calculation |
20
+ | Overscan as flicker band-aid | 3000px+ needed | 5 items (no pixels) |
21
+ | Bundle size | 88 kB | ~17 kB |
22
+ | Pagination built-in | ✗ No | ✓ Yes — `usePagination` hook |
23
+
24
+ ---
25
+
26
+ ## Quick start
27
+
28
+ ### Simple list (tickets, contacts, feeds)
29
+
30
+ ```tsx
31
+ import { VirtualList } from 'react-anchorlist'
32
+
33
+ <VirtualList
34
+ data={tickets}
35
+ computeItemKey={(index, item) => item.id}
36
+ itemContent={(index, item) => <TicketRow ticket={item} />}
37
+ onEndReached={loadMore}
38
+ style={{ height: '100%' }}
39
+ />
40
+ ```
41
+
42
+ ### Chat list (messages with pagination)
43
+
44
+ ```tsx
45
+ import { ChatVirtualList } from 'react-anchorlist'
46
+ import type { ChatVirtualListHandle } from 'react-anchorlist'
47
+
48
+ const listRef = useRef<ChatVirtualListHandle>(null)
49
+
50
+ <ChatVirtualList
51
+ ref={listRef}
52
+ data={messages}
53
+ computeItemKey={(index, item) => item._id}
54
+ itemContent={(index, item) => <Message data={item} />}
55
+ // Pagination — fires when scroll reaches top
56
+ onStartReached={loadOlderMessages}
57
+ // Stick to bottom when new messages arrive
58
+ followOutput="auto"
59
+ // Notify parent of bottom state (for scroll button)
60
+ onAtBottomChange={setIsAtBottom}
61
+ components={{
62
+ Header: () => loading ? <Spinner /> : null,
63
+ Footer: () => <QueueMessages />,
64
+ }}
65
+ style={{ height: '100%' }}
66
+ />
67
+ ```
68
+
69
+ ---
70
+
71
+ ## ChatVirtualList props
72
+
73
+ | Prop | Type | Default | Description |
74
+ |---|---|---|---|
75
+ | `data` | `T[]` | required | Array of items |
76
+ | `itemContent` | `(index, item) => ReactNode` | required | Render function |
77
+ | `computeItemKey` | `(index, item) => string \| number` | required | Stable key per item |
78
+ | `estimatedItemSize` | `number` | `80` | Initial height estimate (px) |
79
+ | `overscan` | `number` | `5` | Items to render beyond visible area |
80
+ | `followOutput` | `"auto" \| "smooth" \| false` | `"auto"` | Stick to bottom on new items |
81
+ | `atBottomThreshold` | `number` | `200` | px from bottom to consider "at bottom" |
82
+ | `initialAlignment` | `"top" \| "bottom"` | `"bottom"` | Initial scroll position |
83
+ | `onStartReached` | `() => void \| Promise<void>` | — | Fires when scroll nears top |
84
+ | `onEndReached` | `() => void \| Promise<void>` | — | Fires when scroll nears bottom |
85
+ | `startReachedThreshold` | `number` | `300` | px from top to trigger `onStartReached` |
86
+ | `endReachedThreshold` | `number` | `300` | px from bottom to trigger `onEndReached` |
87
+ | `onAtBottomChange` | `(isAtBottom: boolean) => void` | — | Called when bottom state changes |
88
+ | `scrollToMessageKey` | `string \| number \| null` | — | Scroll to item by key |
89
+ | `onScrollToMessageComplete` | `() => void` | — | Fires after scroll-to-key completes |
90
+ | `components` | `{ Header, Footer, EmptyPlaceholder }` | — | Slot components |
91
+ | `className` | `string` | — | CSS class for the scroller |
92
+ | `style` | `CSSProperties` | — | Inline style for the scroller |
93
+
94
+ ---
95
+
96
+ ## VirtualList props
97
+
98
+ | Prop | Type | Default | Description |
99
+ |---|---|---|---|
100
+ | `data` | `T[]` | required | Array of items |
101
+ | `itemContent` | `(index, item) => ReactNode` | required | Render function |
102
+ | `computeItemKey` | `(index, item) => string \| number` | required | Stable key per item |
103
+ | `estimatedItemSize` | `number` | `80` | Initial height estimate (px) |
104
+ | `overscan` | `number` | `5` | Items to render beyond visible area |
105
+ | `onEndReached` | `() => void \| Promise<void>` | — | Fires when scroll nears bottom |
106
+ | `endReachedThreshold` | `number` | `300` | px from bottom to trigger callback |
107
+ | `components` | `{ Header, Footer, EmptyPlaceholder }` | — | Slot components |
108
+ | `className` | `string` | — | CSS class for the scroller |
109
+ | `style` | `CSSProperties` | — | Inline style for the scroller |
110
+
111
+ ---
112
+
113
+ ## Ref handle (ChatVirtualList)
114
+
115
+ ```tsx
116
+ const listRef = useRef<ChatVirtualListHandle>(null)
117
+
118
+ listRef.current?.scrollToBottom()
119
+ listRef.current?.scrollToIndex(42, { align: 'center', behavior: 'smooth' })
120
+ listRef.current?.scrollToKey('msg-123', { align: 'center' })
121
+ listRef.current?.getScrollTop() // → number
122
+ listRef.current?.isAtBottom() // → boolean
123
+ listRef.current?.prepareAnchor() // call before manually prepending items
124
+ ```
125
+
126
+ | Method | Description |
127
+ |---|---|
128
+ | `scrollToBottom(behavior?)` | Scroll to last item |
129
+ | `scrollToIndex(index, opts?)` | Scroll to item by index |
130
+ | `scrollToKey(key, opts?)` | Scroll to item by key |
131
+ | `getScrollTop()` | Current scroll position |
132
+ | `isAtBottom()` | Whether list is at bottom |
133
+ | `prepareAnchor()` | Save scroll position before external prepend |
134
+
135
+ ---
136
+
137
+ ## usePagination hook
138
+
139
+ For back-end driven pagination with automatic deduplication:
140
+
141
+ ```tsx
142
+ import { usePagination, ChatVirtualList } from 'react-anchorlist'
143
+
144
+ const { items, loadPrevPage, hasPrevPage, loadingMore } = usePagination({
145
+ fetcher: async (page) => {
146
+ const res = await api.get(`/messages?page=${page}&per_page=50`)
147
+ return {
148
+ data: res.messages,
149
+ hasNextPage: res.pagination.current_page < res.pagination.last_page,
150
+ hasPrevPage: res.pagination.current_page > 1,
151
+ currentPage: res.pagination.current_page,
152
+ }
153
+ },
154
+ direction: 'prepend', // new pages go to the top (chat pattern)
155
+ getKey: (msg) => msg._id, // deduplication key
156
+ })
157
+
158
+ <ChatVirtualList
159
+ data={items}
160
+ computeItemKey={(_, item) => item._id}
161
+ itemContent={(_, item) => <Message data={item} />}
162
+ onStartReached={hasPrevPage ? loadPrevPage : undefined}
163
+ components={{
164
+ Header: () => loadingMore ? <Spinner /> : null,
165
+ }}
166
+ />
167
+ ```
168
+
169
+ ---
170
+
171
+ ## Migrating from react-virtuoso
172
+
173
+ | react-virtuoso | react-anchorlist |
174
+ |---|---|
175
+ | `<Virtuoso data={} itemContent={} />` | `<ChatVirtualList data={} itemContent={} />` |
176
+ | `computeItemKey={(_index, item) => item.id}` | `computeItemKey={(_index, item) => item.id}` ✓ same |
177
+ | `firstItemIndex={10000}` | Not needed — automatic |
178
+ | `initialTopMostItemIndex={n}` | Not needed — `initialAlignment="bottom"` |
179
+ | `alignToBottom` | `initialAlignment="bottom"` (default) |
180
+ | `followOutput={isAtBottom ? 'auto' : false}` | `followOutput="auto"` (default) |
181
+ | `atBottomStateChange={setIsAtBottom}` | `onAtBottomChange={setIsAtBottom}` |
182
+ | `atBottomThreshold={200}` | `atBottomThreshold={200}` ✓ same |
183
+ | `startReached={fn}` | `onStartReached={fn}` |
184
+ | `endReached={fn}` | `onEndReached={fn}` |
185
+ | `overscan={{ main: 3000, reverse: 3000 }}` | `overscan={5}` (items, not pixels) |
186
+ | `increaseViewportBy={{ top: 2200, bottom: 1100 }}` | Not needed |
187
+ | `components={{ Header, Footer }}` | `components={{ Header, Footer }}` ✓ same |
188
+ | `ref.scrollToIndex({ index, align, behavior })` | `ref.scrollToIndex(index, { align, behavior })` |
189
+
190
+ ---
191
+
192
+ ## How it works
193
+
194
+ **OffsetMap** — maintains cumulative Y offsets for all items. When an item is measured, only downstream offsets are recalculated (O(n−i), not O(n)).
195
+
196
+ **Scroll Anchor** — before prepending items, saves `scrollTop` and `scrollHeight`. After the DOM updates, `useLayoutEffect` adjusts `scrollTop` by the delta — synchronously, before the browser paints. Zero flicker.
197
+
198
+ **ResizeObserver per item** — each rendered item has its own observer. Real heights are measured as soon as the item enters the DOM and reported back to the engine. No estimation loops, no layout thrashing.
199
+
200
+ **Binary search** — given `scrollTop`, finds the first visible item in O(log n) using the offset array.
201
+
202
+ ---
203
+
204
+ ## License
205
+
206
+ MIT
@@ -1 +1 @@
1
- {"version":3,"file":"ChatVirtualList.d.ts","sourceRoot":"","sources":["../../src/components/ChatVirtualList.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAK9B,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAoB,EAAe,MAAM,UAAU,CAAA;AA6FxF,eAAO,MAAM,eAAe,EAAuC,CAAC,CAAC,EACnE,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAAG;IAAE,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAA;CAAE,KACxE,KAAK,CAAC,YAAY,CAAA"}
1
+ {"version":3,"file":"ChatVirtualList.d.ts","sourceRoot":"","sources":["../../src/components/ChatVirtualList.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAoB,EAAe,MAAM,UAAU,CAAA;AAgHxF,eAAO,MAAM,eAAe,EAAuC,CAAC,CAAC,EACnE,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAAG;IAAE,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAA;CAAE,KACxE,KAAK,CAAC,YAAY,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"VirtualList.d.ts","sourceRoot":"","sources":["../../src/components/VirtualList.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAe,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAE7D,gGAAgG;AAChG,wBAAgB,WAAW,CAAC,CAAC,EAAE,EAC7B,IAAI,EACJ,WAAW,EACX,cAAc,EACd,iBAAsB,EACtB,QAAY,EACZ,YAAY,EACZ,mBAAyB,EACzB,UAAe,EACf,SAAS,EACT,KAAK,GACN,EAAE,gBAAgB,CAAC,CAAC,CAAC,2CAoDrB"}
1
+ {"version":3,"file":"VirtualList.d.ts","sourceRoot":"","sources":["../../src/components/VirtualList.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAe,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAE7D,gGAAgG;AAChG,wBAAgB,WAAW,CAAC,CAAC,EAAE,EAC7B,IAAI,EACJ,WAAW,EACX,cAAc,EACd,iBAAsB,EACtB,QAAa,EACb,YAAY,EACZ,mBAAyB,EACzB,UAAe,EACf,SAAS,EACT,KAAK,GACN,EAAE,gBAAgB,CAAC,CAAC,CAAC,2CAwDrB"}
@@ -1,5 +1,15 @@
1
1
  import { UseVirtualEngineReturn } from '../types';
2
2
 
3
+ /**
4
+ * Core virtual engine.
5
+ *
6
+ * KEY DESIGN DECISIONS:
7
+ * - All scroll/layout state lives in refs, NOT in React state
8
+ * - A simple counter state is used ONLY to trigger re-renders
9
+ * - virtualItems are computed from refs DURING render (always fresh, zero lag)
10
+ * - Scroll handler uses rAF throttle to avoid excessive renders
11
+ * - Overscan defaults to 20 items (not 5) for smooth fast-scroll
12
+ */
3
13
  export declare function useVirtualEngine<T>(options: {
4
14
  items: T[];
5
15
  getKey: (item: T, index: number) => string | number;
@@ -1 +1 @@
1
- {"version":3,"file":"useVirtualEngine.d.ts","sourceRoot":"","sources":["../../src/hooks/useVirtualEngine.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,sBAAsB,EAAe,MAAM,UAAU,CAAA;AA6BnE,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,EAAE;IAC3C,KAAK,EAAE,CAAC,EAAE,CAAA;IACV,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAAA;IACnD,iBAAiB,EAAE,MAAM,CAAA;IACzB,QAAQ,EAAE,MAAM,CAAA;IAChB,gBAAgB,EAAE,KAAK,GAAG,QAAQ,CAAA;CACnC,GAAG,sBAAsB,CAAC,CAAC,CAAC,CA2K5B"}
1
+ {"version":3,"file":"useVirtualEngine.d.ts","sourceRoot":"","sources":["../../src/hooks/useVirtualEngine.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,sBAAsB,EAAe,MAAM,UAAU,CAAA;AAEnE;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,EAAE;IAC3C,KAAK,EAAE,CAAC,EAAE,CAAA;IACV,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAAA;IACnD,iBAAiB,EAAE,MAAM,CAAA;IACzB,QAAQ,EAAE,MAAM,CAAA;IAChB,gBAAgB,EAAE,KAAK,GAAG,QAAQ,CAAA;CACnC,GAAG,sBAAsB,CAAC,CAAC,CAAC,CAoN5B"}
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const A=require("react/jsx-runtime"),l=require("react");function _(s){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>s[t]})}}return e.default=s,Object.freeze(e)}const D=_(l);class q{constructor(e,t){this.defaultSize=t,this.sizes=e>0?Array(e).fill(t):[],this.offsets=e>0?Array(e).fill(0):[],e>0&&this._recalcFrom(0)}_recalcFrom(e){for(let t=e;t<this.sizes.length;t++)this.offsets[t]=t===0?0:(this.offsets[t-1]??0)+(this.sizes[t-1]??this.defaultSize)}getOffset(e){return this.offsets[e]??0}getSize(e){return this.sizes[e]??this.defaultSize}setSize(e,t){return this.sizes[e]===t?!1:(this.sizes[e]=t,this._recalcFrom(e+1),!0)}prepend(e){const t=Array(e).fill(this.defaultSize);this.sizes=[...t,...this.sizes],this.offsets=Array(this.sizes.length).fill(0),this._recalcFrom(0)}append(e){const t=this.sizes.length;for(let r=0;r<e;r++)this.sizes.push(this.defaultSize),this.offsets.push(0);this._recalcFrom(t)}resize(e){const t=this.sizes.length;e>t?this.append(e-t):e<t&&(this.sizes=this.sizes.slice(0,e),this.offsets=this.offsets.slice(0,e))}totalSize(){if(this.sizes.length===0)return 0;const e=this.sizes.length-1;return(this.offsets[e]??0)+(this.sizes[e]??this.defaultSize)}get count(){return this.sizes.length}getOffsets(){return this.offsets}getSizes(){return this.sizes}}class G{constructor(){this.cache=new Map}get(e){return this.cache.get(e)}set(e,t){this.cache.set(e,t)}has(e){return this.cache.has(e)}delete(e){this.cache.delete(e)}clear(){this.cache.clear()}applyToOffsetMap(e,t){for(const[r,i]of this.cache){const a=t.get(r);a!==void 0&&e.setSize(a,i)}}}function U(s,e){if(s.length===0)return 0;let t=0,r=s.length-1;for(;t<r;){const i=t+r>>1;(s[i]??0)<e?t=i+1:r=i}return Math.max(0,t>0&&(s[t]??0)>e?t-1:t)}function Z(s,e,t){if(s.length===0)return 0;for(let r=s.length-1;r>=0;r--)if((s[r]??0)<t)return r;return 0}function Y(s){const{firstVisible:e,lastVisible:t,itemCount:r,overscan:i}=s;return r===0?{start:0,end:-1}:{start:Math.max(0,e-i),end:Math.min(r-1,t+i)}}function $(s,e){return l.useCallback((t,r)=>{const i=s.current,a=e.current;if(!i||!a)return;const c=a.getOffset(t),d=a.getSize(t),S=(r==null?void 0:r.align)??"start",y=(r==null?void 0:r.behavior)??"auto",v=(r==null?void 0:r.offset)??0;let T;S==="start"?T=c+v:S==="center"?T=c-i.clientHeight/2+d/2+v:T=c-i.clientHeight+d+v,i.scrollTo({top:Math.max(0,T),behavior:y})},[s,e])}function J(s,e){switch(e.type){case"SCROLL":return{...s,scrollTop:e.scrollTop,totalSize:e.totalSize,renderRange:e.renderRange};case"RESIZE_CONTAINER":return{...s,containerHeight:e.height,totalSize:e.totalSize,renderRange:e.renderRange};case"MEASURE":return{...s,totalSize:e.totalSize};case"ITEMS_CHANGED":return{...s,renderRange:e.renderRange,totalSize:e.totalSize}}}function F(s){const{items:e,getKey:t,estimatedItemSize:r,overscan:i,initialAlignment:a}=s,c=l.useRef(null),d=l.useRef(null),S=l.useRef(new G),y=l.useRef([]),v=l.useRef(!1),T=l.useRef(i);T.current=i,d.current||(d.current=new q(e.length,r));const z=l.useCallback((o,m)=>{const n=d.current;if(!n||n.count===0)return{start:0,end:-1};const u=n.getOffsets(),h=n.getSizes(),x=U(u,o),P=Z(u,h,o+m);return Y({firstVisible:x,lastVisible:P,itemCount:n.count,overscan:T.current})},[]),[b,f]=l.useReducer(J,{renderRange:{start:0,end:Math.min(e.length-1,i*2)},scrollTop:0,containerHeight:0,totalSize:d.current.totalSize()});l.useEffect(()=>{const o=d.current,m=e.map((k,L)=>t(k,L)),n=y.current,u=n.length,h=m.length;h===0?o.resize(0):u===0?o.resize(h):h>u?n.length>0&&m[h-u]===n[0]?o.prepend(h-u):o.resize(h):h<u&&o.resize(h);const x=new Map;m.forEach((k,L)=>x.set(k,L)),S.current.applyToOffsetMap(o,x),y.current=m;const P=c.current,H=(P==null?void 0:P.scrollTop)??0,M=(P==null?void 0:P.clientHeight)??0,B=z(H,M);f({type:"ITEMS_CHANGED",renderRange:B,totalSize:o.totalSize()})},[e,t,z]),l.useEffect(()=>{const o=c.current;if(!o)return;const m=()=>{const n=d.current,u=o.scrollTop,h=o.clientHeight,x=z(u,h);f({type:"SCROLL",scrollTop:u,totalSize:n.totalSize(),renderRange:x})};return o.addEventListener("scroll",m,{passive:!0}),()=>o.removeEventListener("scroll",m)},[z]),l.useEffect(()=>{const o=c.current;if(!o)return;const m=new ResizeObserver(([n])=>{if(!n)return;const u=n.contentRect.height,h=d.current,x=o.scrollTop,P=z(x,u);f({type:"RESIZE_CONTAINER",height:u,totalSize:h.totalSize(),renderRange:P})});return m.observe(o),()=>m.disconnect()},[z]),l.useEffect(()=>{if(v.current||e.length===0)return;const o=c.current;o&&(a==="bottom"&&(o.scrollTop=o.scrollHeight),v.current=!0)},[a,e.length]);const w=l.useCallback((o,m)=>{const n=d.current;if(!n)return;S.current.set(o,m);const u=y.current.indexOf(o);if(u===-1)return;n.setSize(u,m)&&f({type:"MEASURE",totalSize:n.totalSize()})},[]),O=l.useCallback((o,m="auto")=>{var n;(n=c.current)==null||n.scrollTo({top:o,behavior:m})},[]),p=$(c,d),R=d.current,{start:I,end:E}=b.renderRange,j=[];if(R&&E>=I)for(let o=I;o<=E&&o<e.length;o++)j.push({key:y.current[o]??t(e[o],o),index:o,start:R.getOffset(o),size:R.getSize(o),data:e[o]});const g=c.current,C=g?g.scrollHeight-g.scrollTop-g.clientHeight:1/0;return{scrollerRef:c,virtualItems:j,totalSize:b.totalSize,measureItem:w,scrollToIndex:p,scrollToOffset:O,isAtTop:b.scrollTop<=0,isAtBottom:C<=0,scrollTop:b.scrollTop}}function Q(s,e){const t=l.useRef(0),r=l.useRef(0),i=l.useRef(!1),a=l.useCallback(()=>{const c=s.current;c&&(t.current=c.scrollTop,r.current=c.scrollHeight,i.current=!0)},[s]);return l.useLayoutEffect(()=>{if(!i.current)return;const c=s.current;if(!c)return;const d=c.scrollHeight-r.current;d>0&&(c.scrollTop=t.current+d),i.current=!1},[e,s]),{prepareAnchor:a}}function W(s,e){const[t,r]=l.useState(!0),i=l.useRef(null);return l.useEffect(()=>{const a=s.current;if(!a)return;const c=()=>{const S=a.scrollHeight-a.scrollTop-a.clientHeight;r(S<=e)},d=()=>{i.current!==null&&cancelAnimationFrame(i.current),i.current=requestAnimationFrame(c)};return a.addEventListener("scroll",d,{passive:!0}),c(),()=>{a.removeEventListener("scroll",d),i.current!==null&&cancelAnimationFrame(i.current)}},[s,e]),t}function X(s){const{itemCount:e,isAtBottom:t,scrollToIndex:r,mode:i}=s,a=l.useRef(e);l.useLayoutEffect(()=>{i&&(e>a.current&&t&&e>0&&r(e-1,{align:"end",behavior:i==="smooth"?"smooth":"auto"}),a.current=e)},[e,t,r,i])}function K(s){const{items:e,getKey:t,estimatedItemSize:r=80,overscan:i=5,atBottomThreshold:a=200,followOutput:c="auto",initialAlignment:d="bottom",onStartReached:S,onEndReached:y,startReachedThreshold:v=300,endReachedThreshold:T=300,scrollToMessageKey:z,onScrollToMessageComplete:b}=s,f=F({items:e,getKey:t,estimatedItemSize:r,overscan:i,initialAlignment:d}),w=W(f.scrollerRef,a),{prepareAnchor:O}=Q(f.scrollerRef,e.length);X({itemCount:e.length,isAtBottom:w,scrollToIndex:f.scrollToIndex,mode:c??!1});const p=l.useRef(!1);l.useEffect(()=>{const g=f.scrollerRef.current;if(!g||!S)return;const C=()=>{g.scrollTop<=v&&!p.current&&(p.current=!0,Promise.resolve(S()).finally(()=>{p.current=!1}))};return g.addEventListener("scroll",C,{passive:!0}),()=>g.removeEventListener("scroll",C)},[f.scrollerRef,S,v]);const R=l.useRef(!1);l.useEffect(()=>{const g=f.scrollerRef.current;if(!g||!y)return;const C=()=>{g.scrollHeight-g.scrollTop-g.clientHeight<=T&&!R.current&&(R.current=!0,Promise.resolve(y()).finally(()=>{R.current=!1}))};return g.addEventListener("scroll",C,{passive:!0}),()=>g.removeEventListener("scroll",C)},[f.scrollerRef,y,T]);const I=l.useRef(null);l.useEffect(()=>{if(!z||I.current===z)return;const g=e.findIndex((C,o)=>t(C,o)===z);g!==-1&&(I.current=z,f.scrollToIndex(g,{align:"center",behavior:"smooth"}),b==null||b())},[z,e,t,f,b]);const E=l.useCallback((g="auto")=>{e.length!==0&&f.scrollToIndex(e.length-1,{align:"end",behavior:g})},[e.length,f]),j=l.useCallback((g,C)=>{const o=e.findIndex((m,n)=>t(m,n)===g);o!==-1&&f.scrollToIndex(o,C)},[e,t,f]);return{scrollerRef:f.scrollerRef,virtualItems:f.virtualItems,totalSize:f.totalSize,measureItem:f.measureItem,scrollToIndex:f.scrollToIndex,scrollToBottom:E,scrollToKey:j,isAtBottom:w,prepareAnchor:O}}function N({scrollerRef:s,totalSize:e,children:t,className:r,style:i}){return A.jsx("div",{ref:s,className:r,style:{overflow:"auto",height:"100%",position:"relative",...i},children:A.jsx("div",{style:{height:e,position:"relative",width:"100%"},children:t})})}function V({virtualItem:s,measureItem:e,children:t}){const r=l.useRef(null);return l.useEffect(()=>{const i=r.current;if(!i)return;const a=new ResizeObserver(([c])=>{c&&e(s.key,c.contentRect.height)});return a.observe(i),()=>a.disconnect()},[s.key,e]),A.jsx("div",{ref:r,style:{position:"absolute",top:0,transform:`translateY(${s.start}px)`,width:"100%",minHeight:s.size},children:t})}function ee(s,e){const{data:t,itemContent:r,computeItemKey:i,estimatedItemSize:a=80,overscan:c=5,followOutput:d="auto",atBottomThreshold:S=200,initialAlignment:y="bottom",onStartReached:v,onEndReached:T,startReachedThreshold:z=300,endReachedThreshold:b=300,scrollToMessageKey:f,onScrollToMessageComplete:w,components:O={},className:p,style:R}=s,{scrollerRef:I,virtualItems:E,totalSize:j,measureItem:g,scrollToIndex:C,scrollToBottom:o,scrollToKey:m,isAtBottom:n,prepareAnchor:u}=K({items:t,getKey:(H,M)=>i(M,H),estimatedItemSize:a,overscan:c,atBottomThreshold:S,followOutput:d,initialAlignment:y,onStartReached:v,onEndReached:T,startReachedThreshold:z,endReachedThreshold:b,scrollToMessageKey:f,onScrollToMessageComplete:w});l.useImperativeHandle(e,()=>({scrollToBottom:o,scrollToIndex:C,scrollToKey:m,getScrollTop:()=>{var H;return((H=I.current)==null?void 0:H.scrollTop)??0},isAtBottom:()=>n,prepareAnchor:u}),[o,C,m,I,n,u]);const{Header:h,Footer:x,EmptyPlaceholder:P}=O;return t.length===0&&P?A.jsx(P,{}):A.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[h&&A.jsx(h,{}),A.jsx(N,{scrollerRef:I,totalSize:j,className:p,style:{flex:1,minHeight:0,...R},children:E.map(H=>A.jsx(V,{virtualItem:H,measureItem:g,children:r(H.index,H.data)},H.key))}),x&&A.jsx(x,{})]})}const te=l.forwardRef(ee);function re({data:s,itemContent:e,computeItemKey:t,estimatedItemSize:r=80,overscan:i=5,onEndReached:a,endReachedThreshold:c=300,components:d={},className:S,style:y}){const{scrollerRef:v,virtualItems:T,totalSize:z,measureItem:b}=F({items:s,getKey:(p,R)=>t(R,p),estimatedItemSize:r,overscan:i,initialAlignment:"top"});D.useEffect(()=>{const p=v.current;if(!p||!a)return;let R=!1;const I=()=>{p.scrollHeight-p.scrollTop-p.clientHeight<=c&&!R&&(R=!0,Promise.resolve(a()).finally(()=>{R=!1}))};return p.addEventListener("scroll",I,{passive:!0}),()=>p.removeEventListener("scroll",I)},[v,a,c]);const{Header:f,Footer:w,EmptyPlaceholder:O}=d;return s.length===0&&O?A.jsx(O,{}):A.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[f&&A.jsx(f,{}),A.jsx(N,{scrollerRef:v,totalSize:z,className:S,style:{flex:1,minHeight:0,...y},children:T.map(p=>A.jsx(V,{virtualItem:p,measureItem:b,children:e(p.index,p.data)},p.key))}),w&&A.jsx(w,{})]})}function se(s){const{fetcher:e,initialPage:t=1,direction:r="append",getKey:i,onPageLoaded:a,onError:c}=s,[d,S]=l.useState([]),[y,v]=l.useState(t),[T,z]=l.useState(!0),[b,f]=l.useState(!1),[w,O]=l.useState(!1),[p,R]=l.useState(!1),I=l.useRef(new Set),E=l.useRef(!1),j=l.useCallback(n=>i?n.filter(u=>{const h=i(u);return I.current.has(h)?!1:(I.current.add(h),!0)}):n,[i]),g=l.useCallback(async()=>{if(!(E.current||!T)){E.current=!0,R(!0);try{const n=y+1,u=await e(n),h=j(u.data);S(x=>r==="prepend"?[...h,...x]:[...x,...h]),v(n),z(u.hasNextPage),f(u.hasPrevPage),a==null||a(n,h)}catch(n){c==null||c(n instanceof Error?n:new Error(String(n)))}finally{R(!1),E.current=!1}}},[y,T,e,j,r,a,c]),C=l.useCallback(async()=>{if(!(E.current||!b)){E.current=!0,R(!0);try{const n=y-1,u=await e(n),h=j(u.data);S(x=>[...h,...x]),v(n),f(u.hasPrevPage),z(u.hasNextPage),a==null||a(n,h)}catch(n){c==null||c(n instanceof Error?n:new Error(String(n)))}finally{R(!1),E.current=!1}}},[y,b,e,j,a,c]),o=l.useCallback(async()=>{if(!E.current){E.current=!0,O(!0);try{const n=await e(t),u=n.data;if(i){const h=new Set(u.map(i));u.forEach(x=>I.current.add(i(x))),S(x=>{const P=x.filter(H=>!h.has(i(H)));return r==="prepend"?[...u,...P]:[...P,...u]})}else S(u);v(t),z(n.hasNextPage),f(n.hasPrevPage),a==null||a(t,u)}catch(n){c==null||c(n instanceof Error?n:new Error(String(n)))}finally{O(!1),E.current=!1}}},[e,t,i,r,a,c]),m=l.useCallback(()=>{S([]),v(t),z(!0),f(!1),O(!1),R(!1),I.current.clear(),E.current=!1},[t]);return{items:d,loadNextPage:g,loadPrevPage:C,hasNextPage:T,hasPrevPage:b,loading:w,loadingMore:p,refresh:o,reset:m,currentPage:y}}exports.ChatVirtualList=te;exports.VirtualList=re;exports.useChatVirtualizer=K;exports.usePagination=se;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("react/jsx-runtime"),r=require("react");function _(c){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(c){for(const t in c)if(t!=="default"){const s=Object.getOwnPropertyDescriptor(c,t);Object.defineProperty(e,t,s.get?s:{enumerable:!0,get:()=>c[t]})}}return e.default=c,Object.freeze(e)}const M=_(r);class q{constructor(e,t){this.defaultSize=t,this.sizes=e>0?Array(e).fill(t):[],this.offsets=e>0?Array(e).fill(0):[],e>0&&this._recalcFrom(0)}_recalcFrom(e){for(let t=e;t<this.sizes.length;t++)this.offsets[t]=t===0?0:(this.offsets[t-1]??0)+(this.sizes[t-1]??this.defaultSize)}getOffset(e){return this.offsets[e]??0}getSize(e){return this.sizes[e]??this.defaultSize}setSize(e,t){return this.sizes[e]===t?!1:(this.sizes[e]=t,this._recalcFrom(e+1),!0)}prepend(e){const t=Array(e).fill(this.defaultSize);this.sizes=[...t,...this.sizes],this.offsets=Array(this.sizes.length).fill(0),this._recalcFrom(0)}append(e){const t=this.sizes.length;for(let s=0;s<e;s++)this.sizes.push(this.defaultSize),this.offsets.push(0);this._recalcFrom(t)}resize(e){const t=this.sizes.length;e>t?this.append(e-t):e<t&&(this.sizes=this.sizes.slice(0,e),this.offsets=this.offsets.slice(0,e))}totalSize(){if(this.sizes.length===0)return 0;const e=this.sizes.length-1;return(this.offsets[e]??0)+(this.sizes[e]??this.defaultSize)}get count(){return this.sizes.length}getOffsets(){return this.offsets}getSizes(){return this.sizes}}class D{constructor(){this.cache=new Map}get(e){return this.cache.get(e)}set(e,t){this.cache.set(e,t)}has(e){return this.cache.has(e)}delete(e){this.cache.delete(e)}clear(){this.cache.clear()}applyToOffsetMap(e,t){for(const[s,i]of this.cache){const o=t.get(s);o!==void 0&&e.setSize(o,i)}}}function Y(c,e){if(c.length===0)return 0;let t=0,s=c.length-1;for(;t<s;){const i=t+s>>1;(c[i]??0)<e?t=i+1:s=i}return Math.max(0,t>0&&(c[t]??0)>e?t-1:t)}function $(c,e,t){if(c.length===0)return 0;for(let s=c.length-1;s>=0;s--)if((c[s]??0)<t)return s;return 0}function G(c){const{firstVisible:e,lastVisible:t,itemCount:s,overscan:i}=c;return s===0?{start:0,end:-1}:{start:Math.max(0,e-i),end:Math.min(s-1,t+i)}}function J(c,e){return r.useCallback((t,s)=>{const i=c.current,o=e.current;if(!i||!o)return;const l=o.getOffset(t),p=o.getSize(t),v=(s==null?void 0:s.align)??"start",z=(s==null?void 0:s.behavior)??"auto",x=(s==null?void 0:s.offset)??0;let T;v==="start"?T=l+x:v==="center"?T=l-i.clientHeight/2+p/2+x:T=l-i.clientHeight+p+x,i.scrollTo({top:Math.max(0,T),behavior:z})},[c,e])}function V(c){const{items:e,getKey:t,estimatedItemSize:s,overscan:i,initialAlignment:o}=c,l=r.useRef(null),p=r.useRef(null),v=r.useRef(new D),z=r.useRef([]),x=r.useRef(!1),T=r.useRef(0),b=r.useRef(0),I=r.useRef(null),[,f]=r.useState(0),A=r.useCallback(()=>f(n=>n+1),[]);p.current||(p.current=new q(e.length,s));const w=r.useRef(e.length);if(e.length!==w.current||e.some((n,a)=>{const R=t(n,a);return z.current[a]!==R})){const n=p.current,a=e.map((L,K)=>t(L,K)),R=z.current,k=R.length,C=a.length;C===0?n.resize(0):k===0?n.resize(C):C>k?R.length>0&&a[C-k]===R[0]?n.prepend(C-k):n.resize(C):C<k&&n.resize(C);const m=new Map;a.forEach((L,K)=>m.set(L,K)),v.current.applyToOffsetMap(n,m),z.current=a,w.current=e.length}r.useEffect(()=>{const n=l.current;if(!n)return;const a=()=>{I.current===null&&(I.current=requestAnimationFrame(()=>{I.current=null,T.current=n.scrollTop,b.current=n.clientHeight,A()}))};return n.addEventListener("scroll",a,{passive:!0}),()=>{n.removeEventListener("scroll",a),I.current!==null&&(cancelAnimationFrame(I.current),I.current=null)}},[A]),r.useEffect(()=>{const n=l.current;if(!n)return;b.current=n.clientHeight,T.current=n.scrollTop;const a=new ResizeObserver(([R])=>{R&&(b.current=R.contentRect.height,A())});return a.observe(n),()=>a.disconnect()},[A]),r.useLayoutEffect(()=>{if(x.current||e.length===0)return;const n=l.current;n&&(o==="bottom"&&(n.scrollTop=n.scrollHeight,T.current=n.scrollTop),x.current=!0)},[o,e.length]),r.useEffect(()=>{e.length===0&&(x.current=!1)},[e.length]);const P=r.useCallback((n,a)=>{const R=p.current;if(!R||v.current.get(n)===a)return;v.current.set(n,a);const C=z.current.indexOf(n);if(C===-1)return;R.setSize(C,a)&&A()},[A]),O=r.useCallback((n,a="auto")=>{var R;(R=l.current)==null||R.scrollTo({top:n,behavior:a})},[]),E=J(l,p),S=p.current,d=S?S.totalSize():0,g=l.current,H=(g==null?void 0:g.scrollTop)??T.current,F=(g==null?void 0:g.clientHeight)??b.current;let u=[];if(S&&S.count>0&&F>0){const n=S.getOffsets(),a=S.getSizes(),R=Y(n,H),k=$(n,a,H+F),C=G({firstVisible:R,lastVisible:k,itemCount:S.count,overscan:i});for(let m=C.start;m<=C.end&&m<e.length;m++)u.push({key:z.current[m]??t(e[m],m),index:m,start:S.getOffset(m),size:S.getSize(m),data:e[m]})}else if(S&&S.count>0){const n=Math.min(e.length-1,i*2);for(let a=0;a<=n;a++)u.push({key:z.current[a]??t(e[a],a),index:a,start:S.getOffset(a),size:S.getSize(a),data:e[a]})}const h=g?g.scrollHeight-g.scrollTop-g.clientHeight:1/0;return{scrollerRef:l,virtualItems:u,totalSize:d,measureItem:P,scrollToIndex:E,scrollToOffset:O,isAtTop:H<=0,isAtBottom:h<=0,scrollTop:H}}function Q(c,e){const t=r.useRef(0),s=r.useRef(0),i=r.useRef(!1),o=r.useCallback(()=>{const l=c.current;l&&(t.current=l.scrollTop,s.current=l.scrollHeight,i.current=!0)},[c]);return r.useLayoutEffect(()=>{if(!i.current)return;const l=c.current;if(!l)return;const p=l.scrollHeight-s.current;p>0&&(l.scrollTop=t.current+p),i.current=!1},[e,c]),{prepareAnchor:o}}function U(c,e){const[t,s]=r.useState(!0),i=r.useRef(null);return r.useEffect(()=>{const o=c.current;if(!o)return;const l=()=>{const v=o.scrollHeight-o.scrollTop-o.clientHeight;s(v<=e)},p=()=>{i.current!==null&&cancelAnimationFrame(i.current),i.current=requestAnimationFrame(l)};return o.addEventListener("scroll",p,{passive:!0}),l(),()=>{o.removeEventListener("scroll",p),i.current!==null&&cancelAnimationFrame(i.current)}},[c,e]),t}function W(c){const{itemCount:e,isAtBottom:t,scrollToIndex:s,mode:i}=c,o=r.useRef(e);r.useLayoutEffect(()=>{i&&(e>o.current&&t&&e>0&&s(e-1,{align:"end",behavior:i==="smooth"?"smooth":"auto"}),o.current=e)},[e,t,s,i])}function B(c){const{items:e,getKey:t,estimatedItemSize:s=80,overscan:i=20,atBottomThreshold:o=200,followOutput:l="auto",initialAlignment:p="bottom",onStartReached:v,onEndReached:z,startReachedThreshold:x=300,endReachedThreshold:T=300,scrollToMessageKey:b,onScrollToMessageComplete:I}=c,f=V({items:e,getKey:t,estimatedItemSize:s,overscan:i,initialAlignment:p}),A=U(f.scrollerRef,o),{prepareAnchor:w}=Q(f.scrollerRef,e.length);W({itemCount:e.length,isAtBottom:A,scrollToIndex:f.scrollToIndex,mode:l??!1});const y=r.useRef(!1);r.useEffect(()=>{const d=f.scrollerRef.current;if(!d||!v)return;const g=()=>{d.scrollTop<=x&&!y.current&&(y.current=!0,Promise.resolve(v()).finally(()=>{y.current=!1}))};return d.addEventListener("scroll",g,{passive:!0}),()=>d.removeEventListener("scroll",g)},[f.scrollerRef,v,x]);const P=r.useRef(!1);r.useEffect(()=>{const d=f.scrollerRef.current;if(!d||!z)return;const g=()=>{d.scrollHeight-d.scrollTop-d.clientHeight<=T&&!P.current&&(P.current=!0,Promise.resolve(z()).finally(()=>{P.current=!1}))};return d.addEventListener("scroll",g,{passive:!0}),()=>d.removeEventListener("scroll",g)},[f.scrollerRef,z,T]);const O=r.useRef(null);r.useEffect(()=>{if(!b||O.current===b)return;const d=e.findIndex((g,H)=>t(g,H)===b);d!==-1&&(O.current=b,f.scrollToIndex(d,{align:"center",behavior:"smooth"}),I==null||I())},[b,e,t,f,I]);const E=r.useCallback((d="auto")=>{e.length!==0&&f.scrollToIndex(e.length-1,{align:"end",behavior:d})},[e.length,f]),S=r.useCallback((d,g)=>{const H=e.findIndex((F,u)=>t(F,u)===d);H!==-1&&f.scrollToIndex(H,g)},[e,t,f]);return{scrollerRef:f.scrollerRef,virtualItems:f.virtualItems,totalSize:f.totalSize,measureItem:f.measureItem,scrollToIndex:f.scrollToIndex,scrollToBottom:E,scrollToKey:S,isAtBottom:A,prepareAnchor:w}}function N({virtualItem:c,measureItem:e,children:t}){const s=r.useRef(null);return r.useEffect(()=>{const i=s.current;if(!i)return;const o=new ResizeObserver(([l])=>{l&&e(c.key,l.contentRect.height)});return o.observe(i),()=>o.disconnect()},[c.key,e]),j.jsx("div",{ref:s,style:{position:"absolute",top:0,transform:`translateY(${c.start}px)`,width:"100%",minHeight:c.size},children:t})}function X(c,e){const{data:t,itemContent:s,computeItemKey:i,estimatedItemSize:o=80,overscan:l=20,followOutput:p="auto",atBottomThreshold:v=200,initialAlignment:z="bottom",onStartReached:x,onEndReached:T,startReachedThreshold:b=300,endReachedThreshold:I=300,scrollToMessageKey:f,onScrollToMessageComplete:A,onAtBottomChange:w,components:y={},className:P,style:O}=c,{scrollerRef:E,virtualItems:S,totalSize:d,measureItem:g,scrollToIndex:H,scrollToBottom:F,scrollToKey:u,isAtBottom:h,prepareAnchor:n}=B({items:t,getKey:(m,L)=>i(L,m),estimatedItemSize:o,overscan:l,atBottomThreshold:v,followOutput:p,initialAlignment:z,onStartReached:x,onEndReached:T,startReachedThreshold:b,endReachedThreshold:I,scrollToMessageKey:f,onScrollToMessageComplete:A}),a=M.useRef(h);M.useEffect(()=>{a.current!==h&&(a.current=h,w==null||w(h))},[h,w]),r.useImperativeHandle(e,()=>({scrollToBottom:F,scrollToIndex:H,scrollToKey:u,getScrollTop:()=>{var m;return((m=E.current)==null?void 0:m.scrollTop)??0},isAtBottom:()=>h,prepareAnchor:n}),[F,H,u,E,h,n]);const{Header:R,Footer:k,EmptyPlaceholder:C}=y;return t.length===0&&C?j.jsx(C,{}):j.jsxs("div",{ref:E,className:P,style:{overflow:"auto",height:"100%",position:"relative",...O},children:[R&&j.jsx(R,{}),j.jsx("div",{style:{height:d,position:"relative",width:"100%"},children:S.map(m=>j.jsx(N,{virtualItem:m,measureItem:g,children:s(m.index,m.data)},m.key))}),k&&j.jsx(k,{})]})}const Z=r.forwardRef(X);function ee({data:c,itemContent:e,computeItemKey:t,estimatedItemSize:s=60,overscan:i=20,onEndReached:o,endReachedThreshold:l=300,components:p={},className:v,style:z}){const{scrollerRef:x,virtualItems:T,totalSize:b,measureItem:I}=V({items:c,getKey:(y,P)=>t(P,y),estimatedItemSize:s,overscan:i,initialAlignment:"top"});M.useEffect(()=>{const y=x.current;if(!y||!o)return;let P=!1;const O=()=>{y.scrollHeight-y.scrollTop-y.clientHeight<=l&&!P&&(P=!0,Promise.resolve(o()).finally(()=>{P=!1}))};return y.addEventListener("scroll",O,{passive:!0}),()=>y.removeEventListener("scroll",O)},[x,o,l]);const{Header:f,Footer:A,EmptyPlaceholder:w}=p;return c.length===0&&w?j.jsx(w,{}):j.jsxs("div",{ref:x,className:v,style:{overflow:"auto",height:"100%",position:"relative",...z},children:[f&&j.jsx(f,{}),j.jsx("div",{style:{height:b,position:"relative",width:"100%"},children:T.map(y=>j.jsx(N,{virtualItem:y,measureItem:I,children:e(y.index,y.data)},y.key))}),A&&j.jsx(A,{})]})}function te(c){const{fetcher:e,initialPage:t=1,direction:s="append",getKey:i,onPageLoaded:o,onError:l}=c,[p,v]=r.useState([]),[z,x]=r.useState(t),[T,b]=r.useState(!0),[I,f]=r.useState(!1),[A,w]=r.useState(!1),[y,P]=r.useState(!1),O=r.useRef(new Set),E=r.useRef(!1),S=r.useCallback(u=>i?u.filter(h=>{const n=i(h);return O.current.has(n)?!1:(O.current.add(n),!0)}):u,[i]),d=r.useCallback(async()=>{if(!(E.current||!T)){E.current=!0,P(!0);try{const u=z+1,h=await e(u),n=S(h.data);v(a=>s==="prepend"?[...n,...a]:[...a,...n]),x(u),b(h.hasNextPage),f(h.hasPrevPage),o==null||o(u,n)}catch(u){l==null||l(u instanceof Error?u:new Error(String(u)))}finally{P(!1),E.current=!1}}},[z,T,e,S,s,o,l]),g=r.useCallback(async()=>{if(!(E.current||!I)){E.current=!0,P(!0);try{const u=z-1,h=await e(u),n=S(h.data);v(a=>[...n,...a]),x(u),f(h.hasPrevPage),b(h.hasNextPage),o==null||o(u,n)}catch(u){l==null||l(u instanceof Error?u:new Error(String(u)))}finally{P(!1),E.current=!1}}},[z,I,e,S,o,l]),H=r.useCallback(async()=>{if(!E.current){E.current=!0,w(!0);try{const u=await e(t),h=u.data;if(i){const n=new Set(h.map(i));h.forEach(a=>O.current.add(i(a))),v(a=>{const R=a.filter(k=>!n.has(i(k)));return s==="prepend"?[...h,...R]:[...R,...h]})}else v(h);x(t),b(u.hasNextPage),f(u.hasPrevPage),o==null||o(t,h)}catch(u){l==null||l(u instanceof Error?u:new Error(String(u)))}finally{w(!1),E.current=!1}}},[e,t,i,s,o,l]),F=r.useCallback(()=>{v([]),x(t),b(!0),f(!1),w(!1),P(!1),O.current.clear(),E.current=!1},[t]);return{items:p,loadNextPage:d,loadPrevPage:g,hasNextPage:T,hasPrevPage:I,loading:A,loadingMore:y,refresh:H,reset:F,currentPage:z}}exports.ChatVirtualList=Z;exports.VirtualList=ee;exports.useChatVirtualizer=B;exports.usePagination=te;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { jsx as b, jsxs as _ } from "react/jsx-runtime";
2
- import * as Z from "react";
3
- import { useCallback as C, useRef as A, useReducer as q, useEffect as K, useLayoutEffect as k, useState as L, forwardRef as Y, useImperativeHandle as $ } from "react";
1
+ import { jsx as M, jsxs as q } from "react/jsx-runtime";
2
+ import * as _ from "react";
3
+ import { useCallback as C, useRef as I, useState as L, useEffect as V, useLayoutEffect as j, forwardRef as $, useImperativeHandle as G } from "react";
4
4
  class J {
5
5
  constructor(e, t) {
6
6
  this.defaultSize = t, this.sizes = e > 0 ? Array(e).fill(t) : [], this.offsets = e > 0 ? Array(e).fill(0) : [], e > 0 && this._recalcFrom(0);
@@ -70,244 +70,241 @@ class Q {
70
70
  /** Re-applies all cached sizes to the OffsetMap using a key→index map */
71
71
  applyToOffsetMap(e, t) {
72
72
  for (const [n, s] of this.cache) {
73
- const c = t.get(n);
74
- c !== void 0 && e.setSize(c, s);
73
+ const i = t.get(n);
74
+ i !== void 0 && e.setSize(i, s);
75
75
  }
76
76
  }
77
77
  }
78
- function W(o, e) {
79
- if (o.length === 0) return 0;
80
- let t = 0, n = o.length - 1;
78
+ function U(l, e) {
79
+ if (l.length === 0) return 0;
80
+ let t = 0, n = l.length - 1;
81
81
  for (; t < n; ) {
82
82
  const s = t + n >> 1;
83
- (o[s] ?? 0) < e ? t = s + 1 : n = s;
83
+ (l[s] ?? 0) < e ? t = s + 1 : n = s;
84
84
  }
85
- return Math.max(0, t > 0 && (o[t] ?? 0) > e ? t - 1 : t);
85
+ return Math.max(0, t > 0 && (l[t] ?? 0) > e ? t - 1 : t);
86
86
  }
87
- function X(o, e, t) {
88
- if (o.length === 0) return 0;
89
- for (let n = o.length - 1; n >= 0; n--)
90
- if ((o[n] ?? 0) < t) return n;
87
+ function W(l, e, t) {
88
+ if (l.length === 0) return 0;
89
+ for (let n = l.length - 1; n >= 0; n--)
90
+ if ((l[n] ?? 0) < t) return n;
91
91
  return 0;
92
92
  }
93
- function ee(o) {
94
- const { firstVisible: e, lastVisible: t, itemCount: n, overscan: s } = o;
93
+ function X(l) {
94
+ const { firstVisible: e, lastVisible: t, itemCount: n, overscan: s } = l;
95
95
  return n === 0 ? { start: 0, end: -1 } : {
96
96
  start: Math.max(0, e - s),
97
97
  end: Math.min(n - 1, t + s)
98
98
  };
99
99
  }
100
- function te(o, e) {
100
+ function Z(l, e) {
101
101
  return C(
102
102
  (t, n) => {
103
- const s = o.current, c = e.current;
104
- if (!s || !c) return;
105
- const l = c.getOffset(t), h = c.getSize(t), p = (n == null ? void 0 : n.align) ?? "start", v = (n == null ? void 0 : n.behavior) ?? "auto", y = (n == null ? void 0 : n.offset) ?? 0;
106
- let R;
107
- p === "start" ? R = l + y : p === "center" ? R = l - s.clientHeight / 2 + h / 2 + y : R = l - s.clientHeight + h + y, s.scrollTo({ top: Math.max(0, R), behavior: v });
103
+ const s = l.current, i = e.current;
104
+ if (!s || !i) return;
105
+ const o = i.getOffset(t), m = i.getSize(t), p = (n == null ? void 0 : n.align) ?? "start", v = (n == null ? void 0 : n.behavior) ?? "auto", S = (n == null ? void 0 : n.offset) ?? 0;
106
+ let x;
107
+ p === "start" ? x = o + S : p === "center" ? x = o - s.clientHeight / 2 + m / 2 + S : x = o - s.clientHeight + m + S, s.scrollTo({ top: Math.max(0, x), behavior: v });
108
108
  },
109
- [o, e]
109
+ [l, e]
110
110
  );
111
111
  }
112
- function re(o, e) {
113
- switch (e.type) {
114
- case "SCROLL":
115
- return { ...o, scrollTop: e.scrollTop, totalSize: e.totalSize, renderRange: e.renderRange };
116
- case "RESIZE_CONTAINER":
117
- return { ...o, containerHeight: e.height, totalSize: e.totalSize, renderRange: e.renderRange };
118
- case "MEASURE":
119
- return { ...o, totalSize: e.totalSize };
120
- case "ITEMS_CHANGED":
121
- return { ...o, renderRange: e.renderRange, totalSize: e.totalSize };
112
+ function D(l) {
113
+ const { items: e, getKey: t, estimatedItemSize: n, overscan: s, initialAlignment: i } = l, o = I(null), m = I(null), p = I(new Q()), v = I([]), S = I(!1), x = I(0), R = I(0), P = I(null), [, u] = L(0), b = C(() => u((r) => r + 1), []);
114
+ m.current || (m.current = new J(e.length, n));
115
+ const E = I(e.length);
116
+ if (e.length !== E.current || e.some((r, c) => {
117
+ const T = t(r, c);
118
+ return v.current[c] !== T;
119
+ })) {
120
+ const r = m.current, c = e.map((k, N) => t(k, N)), T = v.current, K = T.length, w = c.length;
121
+ w === 0 ? r.resize(0) : K === 0 ? r.resize(w) : w > K ? T.length > 0 && c[w - K] === T[0] ? r.prepend(w - K) : r.resize(w) : w < K && r.resize(w);
122
+ const g = /* @__PURE__ */ new Map();
123
+ c.forEach((k, N) => g.set(k, N)), p.current.applyToOffsetMap(r, g), v.current = c, E.current = e.length;
122
124
  }
123
- }
124
- function D(o) {
125
- const { items: e, getKey: t, estimatedItemSize: n, overscan: s, initialAlignment: c } = o, l = A(null), h = A(null), p = A(new Q()), v = A([]), y = A(!1), R = A(s);
126
- R.current = s, h.current || (h.current = new J(e.length, n));
127
- const z = C((i, g) => {
128
- const r = h.current;
129
- if (!r || r.count === 0) return { start: 0, end: -1 };
130
- const a = r.getOffsets(), f = r.getSizes(), T = W(a, i), P = X(a, f, i + g);
131
- return ee({
132
- firstVisible: T,
133
- lastVisible: P,
134
- itemCount: r.count,
135
- overscan: R.current
136
- });
137
- }, []), [I, u] = q(re, {
138
- renderRange: { start: 0, end: Math.min(e.length - 1, s * 2) },
139
- scrollTop: 0,
140
- containerHeight: 0,
141
- totalSize: h.current.totalSize()
142
- });
143
- K(() => {
144
- const i = h.current, g = e.map((N, V) => t(N, V)), r = v.current, a = r.length, f = g.length;
145
- f === 0 ? i.resize(0) : a === 0 ? i.resize(f) : f > a ? r.length > 0 && g[f - a] === r[0] ? i.prepend(f - a) : i.resize(f) : f < a && i.resize(f);
146
- const T = /* @__PURE__ */ new Map();
147
- g.forEach((N, V) => T.set(N, V)), p.current.applyToOffsetMap(i, T), v.current = g;
148
- const P = l.current, w = (P == null ? void 0 : P.scrollTop) ?? 0, B = (P == null ? void 0 : P.clientHeight) ?? 0, U = z(w, B);
149
- u({ type: "ITEMS_CHANGED", renderRange: U, totalSize: i.totalSize() });
150
- }, [e, t, z]), K(() => {
151
- const i = l.current;
152
- if (!i) return;
153
- const g = () => {
154
- const r = h.current, a = i.scrollTop, f = i.clientHeight, T = z(a, f);
155
- u({ type: "SCROLL", scrollTop: a, totalSize: r.totalSize(), renderRange: T });
125
+ V(() => {
126
+ const r = o.current;
127
+ if (!r) return;
128
+ const c = () => {
129
+ P.current === null && (P.current = requestAnimationFrame(() => {
130
+ P.current = null, x.current = r.scrollTop, R.current = r.clientHeight, b();
131
+ }));
156
132
  };
157
- return i.addEventListener("scroll", g, { passive: !0 }), () => i.removeEventListener("scroll", g);
158
- }, [z]), K(() => {
159
- const i = l.current;
160
- if (!i) return;
161
- const g = new ResizeObserver(([r]) => {
162
- if (!r) return;
163
- const a = r.contentRect.height, f = h.current, T = i.scrollTop, P = z(T, a);
164
- u({ type: "RESIZE_CONTAINER", height: a, totalSize: f.totalSize(), renderRange: P });
165
- });
166
- return g.observe(i), () => g.disconnect();
167
- }, [z]), K(() => {
168
- if (y.current || e.length === 0) return;
169
- const i = l.current;
170
- i && (c === "bottom" && (i.scrollTop = i.scrollHeight), y.current = !0);
171
- }, [c, e.length]);
172
- const M = C((i, g) => {
173
- const r = h.current;
133
+ return r.addEventListener("scroll", c, { passive: !0 }), () => {
134
+ r.removeEventListener("scroll", c), P.current !== null && (cancelAnimationFrame(P.current), P.current = null);
135
+ };
136
+ }, [b]), V(() => {
137
+ const r = o.current;
174
138
  if (!r) return;
175
- p.current.set(i, g);
176
- const a = v.current.indexOf(i);
177
- if (a === -1) return;
178
- r.setSize(a, g) && u({ type: "MEASURE", totalSize: r.totalSize() });
179
- }, []), O = C(
180
- (i, g = "auto") => {
181
- var r;
182
- (r = l.current) == null || r.scrollTo({ top: i, behavior: g });
139
+ R.current = r.clientHeight, x.current = r.scrollTop;
140
+ const c = new ResizeObserver(([T]) => {
141
+ T && (R.current = T.contentRect.height, b());
142
+ });
143
+ return c.observe(r), () => c.disconnect();
144
+ }, [b]), j(() => {
145
+ if (S.current || e.length === 0) return;
146
+ const r = o.current;
147
+ r && (i === "bottom" && (r.scrollTop = r.scrollHeight, x.current = r.scrollTop), S.current = !0);
148
+ }, [i, e.length]), V(() => {
149
+ e.length === 0 && (S.current = !1);
150
+ }, [e.length]);
151
+ const A = C((r, c) => {
152
+ const T = m.current;
153
+ if (!T || p.current.get(r) === c) return;
154
+ p.current.set(r, c);
155
+ const w = v.current.indexOf(r);
156
+ if (w === -1) return;
157
+ T.setSize(w, c) && b();
158
+ }, [b]), O = C(
159
+ (r, c = "auto") => {
160
+ var T;
161
+ (T = o.current) == null || T.scrollTo({ top: r, behavior: c });
183
162
  },
184
163
  []
185
- ), m = te(l, h), S = h.current, { start: E, end: x } = I.renderRange, F = [];
186
- if (S && x >= E)
187
- for (let i = E; i <= x && i < e.length; i++)
188
- F.push({
189
- key: v.current[i] ?? t(e[i], i),
190
- index: i,
191
- start: S.getOffset(i),
192
- size: S.getSize(i),
193
- data: e[i]
164
+ ), H = Z(o, m), y = m.current, h = y ? y.totalSize() : 0, d = o.current, F = (d == null ? void 0 : d.scrollTop) ?? x.current, B = (d == null ? void 0 : d.clientHeight) ?? R.current;
165
+ let a = [];
166
+ if (y && y.count > 0 && B > 0) {
167
+ const r = y.getOffsets(), c = y.getSizes(), T = U(r, F), K = W(r, c, F + B), w = X({
168
+ firstVisible: T,
169
+ lastVisible: K,
170
+ itemCount: y.count,
171
+ overscan: s
172
+ });
173
+ for (let g = w.start; g <= w.end && g < e.length; g++)
174
+ a.push({
175
+ key: v.current[g] ?? t(e[g], g),
176
+ index: g,
177
+ start: y.getOffset(g),
178
+ size: y.getSize(g),
179
+ data: e[g]
180
+ });
181
+ } else if (y && y.count > 0) {
182
+ const r = Math.min(e.length - 1, s * 2);
183
+ for (let c = 0; c <= r; c++)
184
+ a.push({
185
+ key: v.current[c] ?? t(e[c], c),
186
+ index: c,
187
+ start: y.getOffset(c),
188
+ size: y.getSize(c),
189
+ data: e[c]
194
190
  });
195
- const d = l.current, H = d ? d.scrollHeight - d.scrollTop - d.clientHeight : 1 / 0;
191
+ }
192
+ const f = d ? d.scrollHeight - d.scrollTop - d.clientHeight : 1 / 0;
196
193
  return {
197
- scrollerRef: l,
198
- virtualItems: F,
199
- totalSize: I.totalSize,
200
- measureItem: M,
201
- scrollToIndex: m,
194
+ scrollerRef: o,
195
+ virtualItems: a,
196
+ totalSize: h,
197
+ measureItem: A,
198
+ scrollToIndex: H,
202
199
  scrollToOffset: O,
203
- isAtTop: I.scrollTop <= 0,
204
- isAtBottom: H <= 0,
205
- scrollTop: I.scrollTop
200
+ isAtTop: F <= 0,
201
+ isAtBottom: f <= 0,
202
+ scrollTop: F
206
203
  };
207
204
  }
208
- function ne(o, e) {
209
- const t = A(0), n = A(0), s = A(!1), c = C(() => {
210
- const l = o.current;
211
- l && (t.current = l.scrollTop, n.current = l.scrollHeight, s.current = !0);
212
- }, [o]);
213
- return k(() => {
205
+ function ee(l, e) {
206
+ const t = I(0), n = I(0), s = I(!1), i = C(() => {
207
+ const o = l.current;
208
+ o && (t.current = o.scrollTop, n.current = o.scrollHeight, s.current = !0);
209
+ }, [l]);
210
+ return j(() => {
214
211
  if (!s.current) return;
215
- const l = o.current;
216
- if (!l) return;
217
- const h = l.scrollHeight - n.current;
218
- h > 0 && (l.scrollTop = t.current + h), s.current = !1;
219
- }, [e, o]), { prepareAnchor: c };
212
+ const o = l.current;
213
+ if (!o) return;
214
+ const m = o.scrollHeight - n.current;
215
+ m > 0 && (o.scrollTop = t.current + m), s.current = !1;
216
+ }, [e, l]), { prepareAnchor: i };
220
217
  }
221
- function se(o, e) {
222
- const [t, n] = L(!0), s = A(null);
223
- return K(() => {
224
- const c = o.current;
225
- if (!c) return;
226
- const l = () => {
227
- const p = c.scrollHeight - c.scrollTop - c.clientHeight;
218
+ function te(l, e) {
219
+ const [t, n] = L(!0), s = I(null);
220
+ return V(() => {
221
+ const i = l.current;
222
+ if (!i) return;
223
+ const o = () => {
224
+ const p = i.scrollHeight - i.scrollTop - i.clientHeight;
228
225
  n(p <= e);
229
- }, h = () => {
230
- s.current !== null && cancelAnimationFrame(s.current), s.current = requestAnimationFrame(l);
226
+ }, m = () => {
227
+ s.current !== null && cancelAnimationFrame(s.current), s.current = requestAnimationFrame(o);
231
228
  };
232
- return c.addEventListener("scroll", h, { passive: !0 }), l(), () => {
233
- c.removeEventListener("scroll", h), s.current !== null && cancelAnimationFrame(s.current);
229
+ return i.addEventListener("scroll", m, { passive: !0 }), o(), () => {
230
+ i.removeEventListener("scroll", m), s.current !== null && cancelAnimationFrame(s.current);
234
231
  };
235
- }, [o, e]), t;
232
+ }, [l, e]), t;
236
233
  }
237
- function ie(o) {
238
- const { itemCount: e, isAtBottom: t, scrollToIndex: n, mode: s } = o, c = A(e);
239
- k(() => {
240
- s && (e > c.current && t && e > 0 && n(e - 1, {
234
+ function re(l) {
235
+ const { itemCount: e, isAtBottom: t, scrollToIndex: n, mode: s } = l, i = I(e);
236
+ j(() => {
237
+ s && (e > i.current && t && e > 0 && n(e - 1, {
241
238
  align: "end",
242
239
  behavior: s === "smooth" ? "smooth" : "auto"
243
- }), c.current = e);
240
+ }), i.current = e);
244
241
  }, [e, t, n, s]);
245
242
  }
246
- function oe(o) {
243
+ function ne(l) {
247
244
  const {
248
245
  items: e,
249
246
  getKey: t,
250
247
  estimatedItemSize: n = 80,
251
- overscan: s = 5,
252
- atBottomThreshold: c = 200,
253
- followOutput: l = "auto",
254
- initialAlignment: h = "bottom",
248
+ overscan: s = 20,
249
+ atBottomThreshold: i = 200,
250
+ followOutput: o = "auto",
251
+ initialAlignment: m = "bottom",
255
252
  onStartReached: p,
256
253
  onEndReached: v,
257
- startReachedThreshold: y = 300,
258
- endReachedThreshold: R = 300,
259
- scrollToMessageKey: z,
260
- onScrollToMessageComplete: I
261
- } = o, u = D({
254
+ startReachedThreshold: S = 300,
255
+ endReachedThreshold: x = 300,
256
+ scrollToMessageKey: R,
257
+ onScrollToMessageComplete: P
258
+ } = l, u = D({
262
259
  items: e,
263
260
  getKey: t,
264
261
  estimatedItemSize: n,
265
262
  overscan: s,
266
- initialAlignment: h
267
- }), M = se(u.scrollerRef, c), { prepareAnchor: O } = ne(u.scrollerRef, e.length);
268
- ie({
263
+ initialAlignment: m
264
+ }), b = te(u.scrollerRef, i), { prepareAnchor: E } = ee(u.scrollerRef, e.length);
265
+ re({
269
266
  itemCount: e.length,
270
- isAtBottom: M,
267
+ isAtBottom: b,
271
268
  scrollToIndex: u.scrollToIndex,
272
- mode: l ?? !1
269
+ mode: o ?? !1
273
270
  });
274
- const m = A(!1);
275
- K(() => {
276
- const d = u.scrollerRef.current;
277
- if (!d || !p) return;
278
- const H = () => {
279
- d.scrollTop <= y && !m.current && (m.current = !0, Promise.resolve(p()).finally(() => {
280
- m.current = !1;
271
+ const z = I(!1);
272
+ V(() => {
273
+ const h = u.scrollerRef.current;
274
+ if (!h || !p) return;
275
+ const d = () => {
276
+ h.scrollTop <= S && !z.current && (z.current = !0, Promise.resolve(p()).finally(() => {
277
+ z.current = !1;
281
278
  }));
282
279
  };
283
- return d.addEventListener("scroll", H, { passive: !0 }), () => d.removeEventListener("scroll", H);
284
- }, [u.scrollerRef, p, y]);
285
- const S = A(!1);
286
- K(() => {
287
- const d = u.scrollerRef.current;
288
- if (!d || !v) return;
289
- const H = () => {
290
- d.scrollHeight - d.scrollTop - d.clientHeight <= R && !S.current && (S.current = !0, Promise.resolve(v()).finally(() => {
291
- S.current = !1;
280
+ return h.addEventListener("scroll", d, { passive: !0 }), () => h.removeEventListener("scroll", d);
281
+ }, [u.scrollerRef, p, S]);
282
+ const A = I(!1);
283
+ V(() => {
284
+ const h = u.scrollerRef.current;
285
+ if (!h || !v) return;
286
+ const d = () => {
287
+ h.scrollHeight - h.scrollTop - h.clientHeight <= x && !A.current && (A.current = !0, Promise.resolve(v()).finally(() => {
288
+ A.current = !1;
292
289
  }));
293
290
  };
294
- return d.addEventListener("scroll", H, { passive: !0 }), () => d.removeEventListener("scroll", H);
295
- }, [u.scrollerRef, v, R]);
296
- const E = A(null);
297
- K(() => {
298
- if (!z || E.current === z) return;
299
- const d = e.findIndex((H, i) => t(H, i) === z);
300
- d !== -1 && (E.current = z, u.scrollToIndex(d, { align: "center", behavior: "smooth" }), I == null || I());
301
- }, [z, e, t, u, I]);
302
- const x = C(
303
- (d = "auto") => {
304
- e.length !== 0 && u.scrollToIndex(e.length - 1, { align: "end", behavior: d });
291
+ return h.addEventListener("scroll", d, { passive: !0 }), () => h.removeEventListener("scroll", d);
292
+ }, [u.scrollerRef, v, x]);
293
+ const O = I(null);
294
+ V(() => {
295
+ if (!R || O.current === R) return;
296
+ const h = e.findIndex((d, F) => t(d, F) === R);
297
+ h !== -1 && (O.current = R, u.scrollToIndex(h, { align: "center", behavior: "smooth" }), P == null || P());
298
+ }, [R, e, t, u, P]);
299
+ const H = C(
300
+ (h = "auto") => {
301
+ e.length !== 0 && u.scrollToIndex(e.length - 1, { align: "end", behavior: h });
305
302
  },
306
303
  [e.length, u]
307
- ), F = C(
308
- (d, H) => {
309
- const i = e.findIndex((g, r) => t(g, r) === d);
310
- i !== -1 && u.scrollToIndex(i, H);
304
+ ), y = C(
305
+ (h, d) => {
306
+ const F = e.findIndex((B, a) => t(B, a) === h);
307
+ F !== -1 && u.scrollToIndex(F, d);
311
308
  },
312
309
  [e, t, u]
313
310
  );
@@ -317,43 +314,26 @@ function oe(o) {
317
314
  totalSize: u.totalSize,
318
315
  measureItem: u.measureItem,
319
316
  scrollToIndex: u.scrollToIndex,
320
- scrollToBottom: x,
321
- scrollToKey: F,
322
- isAtBottom: M,
323
- prepareAnchor: O
317
+ scrollToBottom: H,
318
+ scrollToKey: y,
319
+ isAtBottom: b,
320
+ prepareAnchor: E
324
321
  };
325
322
  }
326
- function j({
327
- scrollerRef: o,
328
- totalSize: e,
329
- children: t,
330
- className: n,
331
- style: s
332
- }) {
333
- return /* @__PURE__ */ b(
334
- "div",
335
- {
336
- ref: o,
337
- className: n,
338
- style: { overflow: "auto", height: "100%", position: "relative", ...s },
339
- children: /* @__PURE__ */ b("div", { style: { height: e, position: "relative", width: "100%" }, children: t })
340
- }
341
- );
342
- }
343
- function G({
344
- virtualItem: o,
323
+ function Y({
324
+ virtualItem: l,
345
325
  measureItem: e,
346
326
  children: t
347
327
  }) {
348
- const n = A(null);
349
- return K(() => {
328
+ const n = I(null);
329
+ return V(() => {
350
330
  const s = n.current;
351
331
  if (!s) return;
352
- const c = new ResizeObserver(([l]) => {
353
- l && e(o.key, l.contentRect.height);
332
+ const i = new ResizeObserver(([o]) => {
333
+ o && e(l.key, o.contentRect.height);
354
334
  });
355
- return c.observe(s), () => c.disconnect();
356
- }, [o.key, e]), /* @__PURE__ */ b(
335
+ return i.observe(s), () => i.disconnect();
336
+ }, [l.key, e]), /* @__PURE__ */ M(
357
337
  "div",
358
338
  {
359
339
  ref: n,
@@ -361,232 +341,243 @@ function G({
361
341
  position: "absolute",
362
342
  top: 0,
363
343
  // transform instead of top: avoids reflow, uses GPU compositor layer
364
- transform: `translateY(${o.start}px)`,
344
+ transform: `translateY(${l.start}px)`,
365
345
  width: "100%",
366
346
  // Reserve estimated height to prevent layout collapse before first measure
367
- minHeight: o.size
347
+ minHeight: l.size
368
348
  },
369
349
  children: t
370
350
  }
371
351
  );
372
352
  }
373
- function le(o, e) {
353
+ function se(l, e) {
374
354
  const {
375
355
  data: t,
376
356
  itemContent: n,
377
357
  computeItemKey: s,
378
- estimatedItemSize: c = 80,
379
- overscan: l = 5,
380
- followOutput: h = "auto",
358
+ estimatedItemSize: i = 80,
359
+ overscan: o = 20,
360
+ followOutput: m = "auto",
381
361
  atBottomThreshold: p = 200,
382
362
  initialAlignment: v = "bottom",
383
- onStartReached: y,
384
- onEndReached: R,
385
- startReachedThreshold: z = 300,
386
- endReachedThreshold: I = 300,
363
+ onStartReached: S,
364
+ onEndReached: x,
365
+ startReachedThreshold: R = 300,
366
+ endReachedThreshold: P = 300,
387
367
  scrollToMessageKey: u,
388
- onScrollToMessageComplete: M,
389
- components: O = {},
390
- className: m,
391
- style: S
392
- } = o, {
393
- scrollerRef: E,
394
- virtualItems: x,
395
- totalSize: F,
368
+ onScrollToMessageComplete: b,
369
+ onAtBottomChange: E,
370
+ components: z = {},
371
+ className: A,
372
+ style: O
373
+ } = l, {
374
+ scrollerRef: H,
375
+ virtualItems: y,
376
+ totalSize: h,
396
377
  measureItem: d,
397
- scrollToIndex: H,
398
- scrollToBottom: i,
399
- scrollToKey: g,
400
- isAtBottom: r,
401
- prepareAnchor: a
402
- } = oe({
378
+ scrollToIndex: F,
379
+ scrollToBottom: B,
380
+ scrollToKey: a,
381
+ isAtBottom: f,
382
+ prepareAnchor: r
383
+ } = ne({
403
384
  items: t,
404
- getKey: (w, B) => s(B, w),
405
- estimatedItemSize: c,
406
- overscan: l,
385
+ getKey: (g, k) => s(k, g),
386
+ estimatedItemSize: i,
387
+ overscan: o,
407
388
  atBottomThreshold: p,
408
- followOutput: h,
389
+ followOutput: m,
409
390
  initialAlignment: v,
410
- onStartReached: y,
411
- onEndReached: R,
412
- startReachedThreshold: z,
413
- endReachedThreshold: I,
391
+ onStartReached: S,
392
+ onEndReached: x,
393
+ startReachedThreshold: R,
394
+ endReachedThreshold: P,
414
395
  scrollToMessageKey: u,
415
- onScrollToMessageComplete: M
416
- });
417
- $(
396
+ onScrollToMessageComplete: b
397
+ }), c = _.useRef(f);
398
+ _.useEffect(() => {
399
+ c.current !== f && (c.current = f, E == null || E(f));
400
+ }, [f, E]), G(
418
401
  e,
419
402
  () => ({
420
- scrollToBottom: i,
421
- scrollToIndex: H,
422
- scrollToKey: g,
403
+ scrollToBottom: B,
404
+ scrollToIndex: F,
405
+ scrollToKey: a,
423
406
  getScrollTop: () => {
424
- var w;
425
- return ((w = E.current) == null ? void 0 : w.scrollTop) ?? 0;
407
+ var g;
408
+ return ((g = H.current) == null ? void 0 : g.scrollTop) ?? 0;
426
409
  },
427
- isAtBottom: () => r,
428
- prepareAnchor: a
410
+ isAtBottom: () => f,
411
+ prepareAnchor: r
429
412
  }),
430
- [i, H, g, E, r, a]
413
+ [B, F, a, H, f, r]
431
414
  );
432
- const { Header: f, Footer: T, EmptyPlaceholder: P } = O;
433
- return t.length === 0 && P ? /* @__PURE__ */ b(P, {}) : /* @__PURE__ */ _("div", { style: { display: "flex", flexDirection: "column", height: "100%" }, children: [
434
- f && /* @__PURE__ */ b(f, {}),
435
- /* @__PURE__ */ b(
436
- j,
437
- {
438
- scrollerRef: E,
439
- totalSize: F,
440
- className: m,
441
- style: { flex: 1, minHeight: 0, ...S },
442
- children: x.map((w) => /* @__PURE__ */ b(
443
- G,
415
+ const { Header: T, Footer: K, EmptyPlaceholder: w } = z;
416
+ return t.length === 0 && w ? /* @__PURE__ */ M(w, {}) : /* @__PURE__ */ q(
417
+ "div",
418
+ {
419
+ ref: H,
420
+ className: A,
421
+ style: {
422
+ overflow: "auto",
423
+ height: "100%",
424
+ position: "relative",
425
+ ...O
426
+ },
427
+ children: [
428
+ T && /* @__PURE__ */ M(T, {}),
429
+ /* @__PURE__ */ M("div", { style: { height: h, position: "relative", width: "100%" }, children: y.map((g) => /* @__PURE__ */ M(
430
+ Y,
444
431
  {
445
- virtualItem: w,
432
+ virtualItem: g,
446
433
  measureItem: d,
447
- children: n(w.index, w.data)
434
+ children: n(g.index, g.data)
448
435
  },
449
- w.key
450
- ))
451
- }
452
- ),
453
- T && /* @__PURE__ */ b(T, {})
454
- ] });
436
+ g.key
437
+ )) }),
438
+ K && /* @__PURE__ */ M(K, {})
439
+ ]
440
+ }
441
+ );
455
442
  }
456
- const ue = Y(le);
457
- function fe({
458
- data: o,
443
+ const ce = $(se);
444
+ function le({
445
+ data: l,
459
446
  itemContent: e,
460
447
  computeItemKey: t,
461
- estimatedItemSize: n = 80,
462
- overscan: s = 5,
463
- onEndReached: c,
464
- endReachedThreshold: l = 300,
465
- components: h = {},
448
+ estimatedItemSize: n = 60,
449
+ overscan: s = 20,
450
+ onEndReached: i,
451
+ endReachedThreshold: o = 300,
452
+ components: m = {},
466
453
  className: p,
467
454
  style: v
468
455
  }) {
469
- const { scrollerRef: y, virtualItems: R, totalSize: z, measureItem: I } = D({
470
- items: o,
471
- getKey: (m, S) => t(S, m),
456
+ const { scrollerRef: S, virtualItems: x, totalSize: R, measureItem: P } = D({
457
+ items: l,
458
+ getKey: (z, A) => t(A, z),
472
459
  estimatedItemSize: n,
473
460
  overscan: s,
474
461
  initialAlignment: "top"
475
462
  });
476
- Z.useEffect(() => {
477
- const m = y.current;
478
- if (!m || !c) return;
479
- let S = !1;
480
- const E = () => {
481
- m.scrollHeight - m.scrollTop - m.clientHeight <= l && !S && (S = !0, Promise.resolve(c()).finally(() => {
482
- S = !1;
463
+ _.useEffect(() => {
464
+ const z = S.current;
465
+ if (!z || !i) return;
466
+ let A = !1;
467
+ const O = () => {
468
+ z.scrollHeight - z.scrollTop - z.clientHeight <= o && !A && (A = !0, Promise.resolve(i()).finally(() => {
469
+ A = !1;
483
470
  }));
484
471
  };
485
- return m.addEventListener("scroll", E, { passive: !0 }), () => m.removeEventListener("scroll", E);
486
- }, [y, c, l]);
487
- const { Header: u, Footer: M, EmptyPlaceholder: O } = h;
488
- return o.length === 0 && O ? /* @__PURE__ */ b(O, {}) : /* @__PURE__ */ _("div", { style: { display: "flex", flexDirection: "column", height: "100%" }, children: [
489
- u && /* @__PURE__ */ b(u, {}),
490
- /* @__PURE__ */ b(
491
- j,
492
- {
493
- scrollerRef: y,
494
- totalSize: z,
495
- className: p,
496
- style: { flex: 1, minHeight: 0, ...v },
497
- children: R.map((m) => /* @__PURE__ */ b(
498
- G,
472
+ return z.addEventListener("scroll", O, { passive: !0 }), () => z.removeEventListener("scroll", O);
473
+ }, [S, i, o]);
474
+ const { Header: u, Footer: b, EmptyPlaceholder: E } = m;
475
+ return l.length === 0 && E ? /* @__PURE__ */ M(E, {}) : /* @__PURE__ */ q(
476
+ "div",
477
+ {
478
+ ref: S,
479
+ className: p,
480
+ style: {
481
+ overflow: "auto",
482
+ height: "100%",
483
+ position: "relative",
484
+ ...v
485
+ },
486
+ children: [
487
+ u && /* @__PURE__ */ M(u, {}),
488
+ /* @__PURE__ */ M("div", { style: { height: R, position: "relative", width: "100%" }, children: x.map((z) => /* @__PURE__ */ M(
489
+ Y,
499
490
  {
500
- virtualItem: m,
501
- measureItem: I,
502
- children: e(m.index, m.data)
491
+ virtualItem: z,
492
+ measureItem: P,
493
+ children: e(z.index, z.data)
503
494
  },
504
- m.key
505
- ))
506
- }
507
- ),
508
- M && /* @__PURE__ */ b(M, {})
509
- ] });
495
+ z.key
496
+ )) }),
497
+ b && /* @__PURE__ */ M(b, {})
498
+ ]
499
+ }
500
+ );
510
501
  }
511
- function he(o) {
502
+ function ae(l) {
512
503
  const {
513
504
  fetcher: e,
514
505
  initialPage: t = 1,
515
506
  direction: n = "append",
516
507
  getKey: s,
517
- onPageLoaded: c,
518
- onError: l
519
- } = o, [h, p] = L([]), [v, y] = L(t), [R, z] = L(!0), [I, u] = L(!1), [M, O] = L(!1), [m, S] = L(!1), E = A(/* @__PURE__ */ new Set()), x = A(!1), F = C(
520
- (r) => s ? r.filter((a) => {
521
- const f = s(a);
522
- return E.current.has(f) ? !1 : (E.current.add(f), !0);
523
- }) : r,
508
+ onPageLoaded: i,
509
+ onError: o
510
+ } = l, [m, p] = L([]), [v, S] = L(t), [x, R] = L(!0), [P, u] = L(!1), [b, E] = L(!1), [z, A] = L(!1), O = I(/* @__PURE__ */ new Set()), H = I(!1), y = C(
511
+ (a) => s ? a.filter((f) => {
512
+ const r = s(f);
513
+ return O.current.has(r) ? !1 : (O.current.add(r), !0);
514
+ }) : a,
524
515
  [s]
525
- ), d = C(async () => {
526
- if (!(x.current || !R)) {
527
- x.current = !0, S(!0);
516
+ ), h = C(async () => {
517
+ if (!(H.current || !x)) {
518
+ H.current = !0, A(!0);
528
519
  try {
529
- const r = v + 1, a = await e(r), f = F(a.data);
520
+ const a = v + 1, f = await e(a), r = y(f.data);
530
521
  p(
531
- (T) => n === "prepend" ? [...f, ...T] : [...T, ...f]
532
- ), y(r), z(a.hasNextPage), u(a.hasPrevPage), c == null || c(r, f);
533
- } catch (r) {
534
- l == null || l(r instanceof Error ? r : new Error(String(r)));
522
+ (c) => n === "prepend" ? [...r, ...c] : [...c, ...r]
523
+ ), S(a), R(f.hasNextPage), u(f.hasPrevPage), i == null || i(a, r);
524
+ } catch (a) {
525
+ o == null || o(a instanceof Error ? a : new Error(String(a)));
535
526
  } finally {
536
- S(!1), x.current = !1;
527
+ A(!1), H.current = !1;
537
528
  }
538
529
  }
539
- }, [v, R, e, F, n, c, l]), H = C(async () => {
540
- if (!(x.current || !I)) {
541
- x.current = !0, S(!0);
530
+ }, [v, x, e, y, n, i, o]), d = C(async () => {
531
+ if (!(H.current || !P)) {
532
+ H.current = !0, A(!0);
542
533
  try {
543
- const r = v - 1, a = await e(r), f = F(a.data);
544
- p((T) => [...f, ...T]), y(r), u(a.hasPrevPage), z(a.hasNextPage), c == null || c(r, f);
545
- } catch (r) {
546
- l == null || l(r instanceof Error ? r : new Error(String(r)));
534
+ const a = v - 1, f = await e(a), r = y(f.data);
535
+ p((c) => [...r, ...c]), S(a), u(f.hasPrevPage), R(f.hasNextPage), i == null || i(a, r);
536
+ } catch (a) {
537
+ o == null || o(a instanceof Error ? a : new Error(String(a)));
547
538
  } finally {
548
- S(!1), x.current = !1;
539
+ A(!1), H.current = !1;
549
540
  }
550
541
  }
551
- }, [v, I, e, F, c, l]), i = C(async () => {
552
- if (!x.current) {
553
- x.current = !0, O(!0);
542
+ }, [v, P, e, y, i, o]), F = C(async () => {
543
+ if (!H.current) {
544
+ H.current = !0, E(!0);
554
545
  try {
555
- const r = await e(t), a = r.data;
546
+ const a = await e(t), f = a.data;
556
547
  if (s) {
557
- const f = new Set(a.map(s));
558
- a.forEach((T) => E.current.add(s(T))), p((T) => {
559
- const P = T.filter((w) => !f.has(s(w)));
560
- return n === "prepend" ? [...a, ...P] : [...P, ...a];
548
+ const r = new Set(f.map(s));
549
+ f.forEach((c) => O.current.add(s(c))), p((c) => {
550
+ const T = c.filter((K) => !r.has(s(K)));
551
+ return n === "prepend" ? [...f, ...T] : [...T, ...f];
561
552
  });
562
553
  } else
563
- p(a);
564
- y(t), z(r.hasNextPage), u(r.hasPrevPage), c == null || c(t, a);
565
- } catch (r) {
566
- l == null || l(r instanceof Error ? r : new Error(String(r)));
554
+ p(f);
555
+ S(t), R(a.hasNextPage), u(a.hasPrevPage), i == null || i(t, f);
556
+ } catch (a) {
557
+ o == null || o(a instanceof Error ? a : new Error(String(a)));
567
558
  } finally {
568
- O(!1), x.current = !1;
559
+ E(!1), H.current = !1;
569
560
  }
570
561
  }
571
- }, [e, t, s, n, c, l]), g = C(() => {
572
- p([]), y(t), z(!0), u(!1), O(!1), S(!1), E.current.clear(), x.current = !1;
562
+ }, [e, t, s, n, i, o]), B = C(() => {
563
+ p([]), S(t), R(!0), u(!1), E(!1), A(!1), O.current.clear(), H.current = !1;
573
564
  }, [t]);
574
565
  return {
575
- items: h,
576
- loadNextPage: d,
577
- loadPrevPage: H,
578
- hasNextPage: R,
579
- hasPrevPage: I,
580
- loading: M,
581
- loadingMore: m,
582
- refresh: i,
583
- reset: g,
566
+ items: m,
567
+ loadNextPage: h,
568
+ loadPrevPage: d,
569
+ hasNextPage: x,
570
+ hasPrevPage: P,
571
+ loading: b,
572
+ loadingMore: z,
573
+ refresh: F,
574
+ reset: B,
584
575
  currentPage: v
585
576
  };
586
577
  }
587
578
  export {
588
- ue as ChatVirtualList,
589
- fe as VirtualList,
590
- oe as useChatVirtualizer,
591
- he as usePagination
579
+ ce as ChatVirtualList,
580
+ le as VirtualList,
581
+ ne as useChatVirtualizer,
582
+ ae as usePagination
592
583
  };
package/dist/types.d.ts CHANGED
@@ -74,6 +74,7 @@ export interface ChatVirtualListProps<T> {
74
74
  endReachedThreshold?: number;
75
75
  scrollToMessageKey?: string | number | null;
76
76
  onScrollToMessageComplete?: () => void;
77
+ onAtBottomChange?: (isAtBottom: boolean) => void;
77
78
  components?: VirtualListComponents<T>;
78
79
  className?: string;
79
80
  style?: React.CSSProperties;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAA;AAEnC,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,OAAO;IACtC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,iCAAiC;IACjC,KAAK,EAAE,MAAM,CAAA;IACb,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,CAAC,CAAA;CACR;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,KAAK,CAAA;IAClC,QAAQ,CAAC,EAAE,cAAc,CAAA;IACzB,8CAA8C;IAC9C,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,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IAAI,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAA;IAChE,cAAc,EAAE,CAAC,QAAQ,CAAC,EAAE,cAAc,KAAK,IAAI,CAAA;IACnD,WAAW,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAA;IACrE,UAAU,EAAE,OAAO,CAAA;IACnB,aAAa,EAAE,MAAM,IAAI,CAAA;CAC1B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-anchorlist",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "High-performance chat virtualizer for React — no flicker, no hacks",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",