@oxyhq/bloom 0.24.1 → 0.25.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/lib/commonjs/list/index.js +94 -0
- package/lib/commonjs/list/index.js.map +1 -0
- package/lib/commonjs/list/index.web.js +216 -0
- package/lib/commonjs/list/index.web.js.map +1 -0
- package/lib/commonjs/list/types.js +6 -0
- package/lib/commonjs/list/types.js.map +1 -0
- package/lib/module/list/index.js +89 -0
- package/lib/module/list/index.js.map +1 -0
- package/lib/module/list/index.web.js +211 -0
- package/lib/module/list/index.web.js.map +1 -0
- package/lib/module/list/types.js +4 -0
- package/lib/module/list/types.js.map +1 -0
- package/lib/typescript/commonjs/list/index.d.ts +29 -0
- package/lib/typescript/commonjs/list/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/list/index.web.d.ts +45 -0
- package/lib/typescript/commonjs/list/index.web.d.ts.map +1 -0
- package/lib/typescript/commonjs/list/types.d.ts +77 -0
- package/lib/typescript/commonjs/list/types.d.ts.map +1 -0
- package/lib/typescript/module/list/index.d.ts +29 -0
- package/lib/typescript/module/list/index.d.ts.map +1 -0
- package/lib/typescript/module/list/index.web.d.ts +45 -0
- package/lib/typescript/module/list/index.web.d.ts.map +1 -0
- package/lib/typescript/module/list/types.d.ts +77 -0
- package/lib/typescript/module/list/types.d.ts.map +1 -0
- package/package.json +20 -1
- package/src/__tests__/VirtualList.native.test.tsx +67 -0
- package/src/__tests__/VirtualList.web.test.tsx +127 -0
- package/src/list/index.tsx +121 -0
- package/src/list/index.web.tsx +261 -0
- package/src/list/types.ts +85 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.VirtualList = void 0;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
11
|
+
/**
|
|
12
|
+
* `VirtualList` — the canonical cross-platform virtualized list for the Oxy
|
|
13
|
+
* ecosystem. Every app uses this ONE implementation for grouped/stacked row
|
|
14
|
+
* lists (who-to-follow, starter packs, connections, settings rows, …) so the
|
|
15
|
+
* virtualization behaviour is identical everywhere.
|
|
16
|
+
*
|
|
17
|
+
* NATIVE variant: a thin, correctly-typed wrapper over React Native `FlatList`.
|
|
18
|
+
* The consumer lists this component replaces are short and uniform, so the
|
|
19
|
+
* platform's own virtualization is the simplest robust choice — no
|
|
20
|
+
* `@legendapp/list`, no app-specific scroll bridge, nothing for a consumer to
|
|
21
|
+
* wire up. Bloom stays app-agnostic.
|
|
22
|
+
*
|
|
23
|
+
* WEB variant (`index.web.tsx`, selected via the `"browser"` export condition):
|
|
24
|
+
* a document-scroll window virtualizer built on `@tanstack/react-virtual`.
|
|
25
|
+
*
|
|
26
|
+
* This default file has NO platform-only imports, so consumer `tsc` and web
|
|
27
|
+
* bundlers resolve it cleanly (mirrors the `../scroll` / `../content-panel`
|
|
28
|
+
* fork pattern). The public API is shared via `./types`, so both forks expose
|
|
29
|
+
* an identical, generic, strongly-typed surface.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
function renderSlot(slot) {
|
|
33
|
+
if (!slot) return null;
|
|
34
|
+
return typeof slot === 'function' ? slot() : slot;
|
|
35
|
+
}
|
|
36
|
+
function VirtualListNativeInner(props, ref) {
|
|
37
|
+
const {
|
|
38
|
+
data,
|
|
39
|
+
renderItem,
|
|
40
|
+
keyExtractor,
|
|
41
|
+
ListHeaderComponent,
|
|
42
|
+
ListEmptyComponent,
|
|
43
|
+
ListFooterComponent,
|
|
44
|
+
style,
|
|
45
|
+
contentContainerStyle,
|
|
46
|
+
onEndReached,
|
|
47
|
+
onEndReachedThreshold,
|
|
48
|
+
refreshing,
|
|
49
|
+
onRefresh,
|
|
50
|
+
initialNumToRender,
|
|
51
|
+
maxToRenderPerBatch,
|
|
52
|
+
windowSize,
|
|
53
|
+
removeClippedSubviews,
|
|
54
|
+
testID
|
|
55
|
+
} = props;
|
|
56
|
+
const listRef = React.useRef(null);
|
|
57
|
+
React.useImperativeHandle(ref, () => ({
|
|
58
|
+
scrollToOffset: params => listRef.current?.scrollToOffset({
|
|
59
|
+
offset: params?.offset ?? 0,
|
|
60
|
+
animated: params?.animated ?? true
|
|
61
|
+
}),
|
|
62
|
+
scrollTo: params => listRef.current?.scrollToOffset({
|
|
63
|
+
offset: params?.y ?? 0,
|
|
64
|
+
animated: params?.animated ?? true
|
|
65
|
+
})
|
|
66
|
+
}), []);
|
|
67
|
+
const renderFlatItem = React.useCallback(info => renderItem ? renderItem({
|
|
68
|
+
item: info.item,
|
|
69
|
+
index: info.index
|
|
70
|
+
}) : null, [renderItem]);
|
|
71
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.FlatList, {
|
|
72
|
+
ref: listRef,
|
|
73
|
+
data: data ?? undefined,
|
|
74
|
+
renderItem: renderFlatItem,
|
|
75
|
+
keyExtractor: keyExtractor,
|
|
76
|
+
ListHeaderComponent: renderSlot(ListHeaderComponent),
|
|
77
|
+
ListEmptyComponent: renderSlot(ListEmptyComponent),
|
|
78
|
+
ListFooterComponent: renderSlot(ListFooterComponent),
|
|
79
|
+
style: style,
|
|
80
|
+
contentContainerStyle: contentContainerStyle,
|
|
81
|
+
onEndReached: onEndReached ? () => onEndReached() : undefined,
|
|
82
|
+
onEndReachedThreshold: onEndReachedThreshold,
|
|
83
|
+
refreshing: refreshing,
|
|
84
|
+
onRefresh: onRefresh,
|
|
85
|
+
initialNumToRender: initialNumToRender,
|
|
86
|
+
maxToRenderPerBatch: maxToRenderPerBatch,
|
|
87
|
+
windowSize: windowSize,
|
|
88
|
+
removeClippedSubviews: removeClippedSubviews,
|
|
89
|
+
testID: testID
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
const VirtualList = exports.VirtualList = /*#__PURE__*/React.forwardRef(VirtualListNativeInner);
|
|
93
|
+
var _default = exports.default = VirtualList;
|
|
94
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","_interopRequireWildcard","require","_reactNative","_jsxRuntime","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","renderSlot","slot","VirtualListNativeInner","props","ref","data","renderItem","keyExtractor","ListHeaderComponent","ListEmptyComponent","ListFooterComponent","style","contentContainerStyle","onEndReached","onEndReachedThreshold","refreshing","onRefresh","initialNumToRender","maxToRenderPerBatch","windowSize","removeClippedSubviews","testID","listRef","useRef","useImperativeHandle","scrollToOffset","params","current","offset","animated","scrollTo","y","renderFlatItem","useCallback","info","item","index","jsx","FlatList","undefined","VirtualList","exports","forwardRef","_default"],"sourceRoot":"../../../src","sources":["list/index.tsx"],"mappings":";;;;;;AAoBA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAAiE,IAAAE,WAAA,GAAAF,OAAA;AAAA,SAAAD,wBAAAI,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAN,uBAAA,YAAAA,CAAAI,CAAA,EAAAC,CAAA,SAAAA,C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,mBAAmB,CAAE;IACrDC,KAAK,EAAEA,KAAM;IACbC,qBAAqB,EAAEA,qBAAsB;IAC7CC,YAAY,EAAEA,YAAY,GAAG,MAAMA,YAAY,CAAC,CAAC,GAAG0B,SAAU;IAC9DzB,qBAAqB,EAAEA,qBAAsB;IAC7CC,UAAU,EAAEA,UAAW;IACvBC,SAAS,EAAEA,SAAU;IACrBC,kBAAkB,EAAEA,kBAAmB;IACvCC,mBAAmB,EAAEA,mBAAoB;IACzCC,UAAU,EAAEA,UAAW;IACvBC,qBAAqB,EAAEA,qBAAsB;IAC7CC,MAAM,EAAEA;EAAO,CAChB,CAAC;AAEN;AAEA,MAAMmB,WAAW,GAAAC,OAAA,CAAAD,WAAA,gBAAGhE,KAAK,CAACkE,UAAU,CAACxC,sBAAsB,CAEpC;AAAC,IAAAyC,QAAA,GAAAF,OAAA,CAAAlD,OAAA,GAGTiD,WAAW","ignoreList":[]}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.VirtualList = void 0;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
var _reactVirtual = require("@tanstack/react-virtual");
|
|
10
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
12
|
+
/**
|
|
13
|
+
* `VirtualList` — WEB variant. A document-scroll (window) virtualizer built on
|
|
14
|
+
* `@tanstack/react-virtual`'s `useWindowVirtualizer`, mirroring the proven
|
|
15
|
+
* Mention feed virtualizer. The BODY scrolls (so scrolling works from anywhere,
|
|
16
|
+
* including over sticky side columns) and only the rows in the virtual window
|
|
17
|
+
* are mounted, so the DOM stays bounded.
|
|
18
|
+
*
|
|
19
|
+
* Why this exists (the bug it fixes): a previous app-local list used the same
|
|
20
|
+
* hook but rendered ZERO rows in production — the wrapper grew to the right
|
|
21
|
+
* height (`getTotalSize()` was correct) yet `getVirtualItems()` came back empty,
|
|
22
|
+
* so only the header painted. Root cause: `useWindowVirtualizer` can latch an
|
|
23
|
+
* initial frame in which the window rect measured as `0` (or `scrollMargin` was
|
|
24
|
+
* still stale), which leaves the computed range empty; a STATIC, finite list
|
|
25
|
+
* re-renders too few times to self-correct and sticks on that bad frame. (The
|
|
26
|
+
* feed only survived by incidental re-render churn — data/loading updates and
|
|
27
|
+
* scroll/intersection observers — which a plain list does not have.)
|
|
28
|
+
*
|
|
29
|
+
* This implementation is SELF-SUFFICIENT and does not rely on incidental churn:
|
|
30
|
+
*
|
|
31
|
+
* 1. `scrollMargin` (the wrapper's offset from the document top) is measured in
|
|
32
|
+
* a layout effect AND re-synced on window `resize`.
|
|
33
|
+
* 2. An explicit post-mount recompute (`virtualizer.measure()`) forces the
|
|
34
|
+
* range to be recomputed once the real viewport height + offset are known —
|
|
35
|
+
* guaranteeing a short list mounts EVERY row in the first viewport even with
|
|
36
|
+
* zero further re-renders. Re-run on resize.
|
|
37
|
+
* 3. The measured spacer is `Math.max(totalSize, lastItemEnd)`, so it always
|
|
38
|
+
* contains every absolutely-positioned row even when `scrollMargin` is
|
|
39
|
+
* momentarily stale; the document therefore always grows to the full content
|
|
40
|
+
* height (keeping sticky side rails pinned) and the window-scroll geometry
|
|
41
|
+
* the virtualizer reads stays consistent.
|
|
42
|
+
* 4. Per-row `measureElement` refs are STABLE (cached per key), so rows are not
|
|
43
|
+
* detached/re-measured on every render.
|
|
44
|
+
*
|
|
45
|
+
* Native bundlers use `./index.tsx` (a `FlatList` wrapper); web bundlers select
|
|
46
|
+
* this file via the `"browser"` export condition in `package.json`.
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
// Rows in these lists (user rows, pack cards) are short and fairly uniform; a
|
|
50
|
+
// small estimate + per-row measurement keeps the mounted node count bounded.
|
|
51
|
+
const DEFAULT_ESTIMATED_ITEM_SIZE = 72;
|
|
52
|
+
const DEFAULT_OVERSCAN = 8;
|
|
53
|
+
|
|
54
|
+
// Bound the per-key ref-callback cache so a very long scroll session does not
|
|
55
|
+
// accumulate one closure per key forever.
|
|
56
|
+
const ROW_REF_CACHE_CAP = 500;
|
|
57
|
+
function renderSlot(slot) {
|
|
58
|
+
if (!slot) return null;
|
|
59
|
+
return typeof slot === 'function' ? slot() : slot;
|
|
60
|
+
}
|
|
61
|
+
function VirtualListWebInner(props, ref) {
|
|
62
|
+
const {
|
|
63
|
+
data,
|
|
64
|
+
renderItem,
|
|
65
|
+
keyExtractor,
|
|
66
|
+
ListHeaderComponent,
|
|
67
|
+
ListEmptyComponent,
|
|
68
|
+
ListFooterComponent,
|
|
69
|
+
style,
|
|
70
|
+
contentContainerStyle,
|
|
71
|
+
estimatedItemSize,
|
|
72
|
+
overscan,
|
|
73
|
+
testID
|
|
74
|
+
} = props;
|
|
75
|
+
const items = data ?? [];
|
|
76
|
+
const count = items.length;
|
|
77
|
+
|
|
78
|
+
// Wrapper element used as the virtualizer's measurement origin. The window is
|
|
79
|
+
// the scroller; `scrollMargin` is the wrapper's offset from the document top
|
|
80
|
+
// (everything above the rows), so virtual offsets map to page offsets.
|
|
81
|
+
const wrapperRef = React.useRef(null);
|
|
82
|
+
const [scrollMargin, setScrollMargin] = React.useState(0);
|
|
83
|
+
const measureScrollMargin = React.useCallback(() => {
|
|
84
|
+
const node = wrapperRef.current;
|
|
85
|
+
if (!node || typeof window === 'undefined') return;
|
|
86
|
+
const top = node.getBoundingClientRect().top + window.scrollY;
|
|
87
|
+
setScrollMargin(prev => prev !== top ? top : prev);
|
|
88
|
+
}, []);
|
|
89
|
+
|
|
90
|
+
// Read the wrapper's top offset synchronously after layout so the first
|
|
91
|
+
// virtual frame already positions rows correctly. Re-run when the row count
|
|
92
|
+
// changes (content above/below the window shifts the wrapper).
|
|
93
|
+
React.useLayoutEffect(() => {
|
|
94
|
+
measureScrollMargin();
|
|
95
|
+
}, [measureScrollMargin, count]);
|
|
96
|
+
const estimate = estimatedItemSize ?? DEFAULT_ESTIMATED_ITEM_SIZE;
|
|
97
|
+
const virtualizer = (0, _reactVirtual.useWindowVirtualizer)({
|
|
98
|
+
count,
|
|
99
|
+
estimateSize: () => estimate,
|
|
100
|
+
overscan: overscan ?? DEFAULT_OVERSCAN,
|
|
101
|
+
scrollMargin,
|
|
102
|
+
getItemKey: keyExtractor ? index => {
|
|
103
|
+
const item = items[index];
|
|
104
|
+
return item !== undefined ? keyExtractor(item, index) : index;
|
|
105
|
+
} : undefined
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// Explicit post-mount recompute + resize re-sync. `useWindowVirtualizer` can
|
|
109
|
+
// latch a frame where the window rect read as 0 / `scrollMargin` was stale,
|
|
110
|
+
// leaving `getVirtualItems()` empty even though rows exist. A static list does
|
|
111
|
+
// not re-render enough to self-correct, so we force the range to recompute
|
|
112
|
+
// once the real viewport + offset are known — and again on every resize.
|
|
113
|
+
React.useEffect(() => {
|
|
114
|
+
if (typeof window === 'undefined') return;
|
|
115
|
+
const sync = () => {
|
|
116
|
+
measureScrollMargin();
|
|
117
|
+
virtualizer.measure();
|
|
118
|
+
};
|
|
119
|
+
sync();
|
|
120
|
+
window.addEventListener('resize', sync);
|
|
121
|
+
return () => window.removeEventListener('resize', sync);
|
|
122
|
+
}, [measureScrollMargin, virtualizer]);
|
|
123
|
+
React.useImperativeHandle(ref, () => ({
|
|
124
|
+
scrollToOffset: params => {
|
|
125
|
+
if (typeof window === 'undefined') return;
|
|
126
|
+
window.scrollTo({
|
|
127
|
+
top: params?.offset ?? 0,
|
|
128
|
+
behavior: params?.animated === false ? 'auto' : 'smooth'
|
|
129
|
+
});
|
|
130
|
+
},
|
|
131
|
+
scrollTo: params => {
|
|
132
|
+
if (typeof window === 'undefined') return;
|
|
133
|
+
window.scrollTo({
|
|
134
|
+
top: params?.y ?? 0,
|
|
135
|
+
behavior: params?.animated === false ? 'auto' : 'smooth'
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}), []);
|
|
139
|
+
|
|
140
|
+
// Stable per-key ref factory wiring the virtualizer's measurement ref. A fresh
|
|
141
|
+
// inline arrow each render would make React detach/re-attach (and re-measure)
|
|
142
|
+
// every row on every render; the cached callback is reused for the same key so
|
|
143
|
+
// the ref only fires on real mount/unmount.
|
|
144
|
+
const measureElement = virtualizer.measureElement;
|
|
145
|
+
const rowRefCallbacks = React.useRef(new Map());
|
|
146
|
+
const getRowRef = React.useCallback(key => {
|
|
147
|
+
const cache = rowRefCallbacks.current;
|
|
148
|
+
const existing = cache.get(key);
|
|
149
|
+
if (existing) return existing;
|
|
150
|
+
if (cache.size > ROW_REF_CACHE_CAP) cache.clear();
|
|
151
|
+
const cb = node => measureElement(node);
|
|
152
|
+
cache.set(key, cb);
|
|
153
|
+
return cb;
|
|
154
|
+
}, [measureElement]);
|
|
155
|
+
const flatStyle = _reactNative.StyleSheet.flatten(style);
|
|
156
|
+
const flatContentStyle = _reactNative.StyleSheet.flatten(contentContainerStyle);
|
|
157
|
+
const header = renderSlot(ListHeaderComponent);
|
|
158
|
+
const footer = renderSlot(ListFooterComponent);
|
|
159
|
+
if (count === 0) {
|
|
160
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
|
|
161
|
+
style: [{
|
|
162
|
+
minHeight: 0
|
|
163
|
+
}, flatStyle],
|
|
164
|
+
testID: testID,
|
|
165
|
+
children: [header, renderSlot(ListEmptyComponent), footer]
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
const virtualItems = virtualizer.getVirtualItems();
|
|
169
|
+
const totalSize = virtualizer.getTotalSize();
|
|
170
|
+
|
|
171
|
+
// The measured spacer MUST contain every absolutely-positioned row; size it to
|
|
172
|
+
// the MAX of `totalSize` and the rows' real extent so the document always
|
|
173
|
+
// grows to full content height even when `scrollMargin` is momentarily stale.
|
|
174
|
+
const lastItem = virtualItems.length > 0 ? virtualItems[virtualItems.length - 1] : undefined;
|
|
175
|
+
const lastItemEnd = lastItem ? lastItem.start + lastItem.size - virtualizer.options.scrollMargin : 0;
|
|
176
|
+
const spacerHeight = Math.max(totalSize, lastItemEnd);
|
|
177
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
|
|
178
|
+
style: [{
|
|
179
|
+
minHeight: 0
|
|
180
|
+
}, flatStyle],
|
|
181
|
+
testID: testID,
|
|
182
|
+
children: [header, /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
183
|
+
style: flatContentStyle,
|
|
184
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
185
|
+
ref: wrapperRef,
|
|
186
|
+
style: {
|
|
187
|
+
height: spacerHeight,
|
|
188
|
+
width: '100%',
|
|
189
|
+
position: 'relative'
|
|
190
|
+
},
|
|
191
|
+
children: virtualItems.map(virtualRow => {
|
|
192
|
+
const item = items[virtualRow.index];
|
|
193
|
+
if (item === undefined) return null;
|
|
194
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
195
|
+
ref: getRowRef(String(virtualRow.key)),
|
|
196
|
+
"data-index": virtualRow.index,
|
|
197
|
+
style: {
|
|
198
|
+
position: 'absolute',
|
|
199
|
+
top: 0,
|
|
200
|
+
left: 0,
|
|
201
|
+
width: '100%',
|
|
202
|
+
transform: `translateY(${virtualRow.start - virtualizer.options.scrollMargin}px)`
|
|
203
|
+
},
|
|
204
|
+
children: renderItem ? renderItem({
|
|
205
|
+
item,
|
|
206
|
+
index: virtualRow.index
|
|
207
|
+
}) : null
|
|
208
|
+
}, virtualRow.key);
|
|
209
|
+
})
|
|
210
|
+
})
|
|
211
|
+
}), footer]
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
const VirtualList = exports.VirtualList = /*#__PURE__*/React.forwardRef(VirtualListWebInner);
|
|
215
|
+
var _default = exports.default = VirtualList;
|
|
216
|
+
//# sourceMappingURL=index.web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","_interopRequireWildcard","require","_reactNative","_reactVirtual","_jsxRuntime","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","DEFAULT_ESTIMATED_ITEM_SIZE","DEFAULT_OVERSCAN","ROW_REF_CACHE_CAP","renderSlot","slot","VirtualListWebInner","props","ref","data","renderItem","keyExtractor","ListHeaderComponent","ListEmptyComponent","ListFooterComponent","style","contentContainerStyle","estimatedItemSize","overscan","testID","items","count","length","wrapperRef","useRef","scrollMargin","setScrollMargin","useState","measureScrollMargin","useCallback","node","current","window","top","getBoundingClientRect","scrollY","prev","useLayoutEffect","estimate","virtualizer","useWindowVirtualizer","estimateSize","getItemKey","index","item","undefined","useEffect","sync","measure","addEventListener","removeEventListener","useImperativeHandle","scrollToOffset","params","scrollTo","offset","behavior","animated","y","measureElement","rowRefCallbacks","Map","getRowRef","key","cache","existing","size","clear","cb","flatStyle","StyleSheet","flatten","flatContentStyle","header","footer","jsxs","View","minHeight","children","virtualItems","getVirtualItems","totalSize","getTotalSize","lastItem","lastItemEnd","start","options","spacerHeight","Math","max","jsx","height","width","position","map","virtualRow","String","left","transform","VirtualList","exports","forwardRef","_default"],"sourceRoot":"../../../src","sources":["list/index.web.tsx"],"mappings":";;;;;;AAoCA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,YAAA,GAAAD,OAA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AAE;QAAAf,QAAA,EAEpEC,YAAY,CAACe,GAAG,CAAEC,UAAU,IAAK;UAChC,MAAMnD,IAAI,GAAGxB,KAAK,CAAC2E,UAAU,CAACpD,KAAK,CAAC;UACpC,IAAIC,IAAI,KAAKC,SAAS,EAAE,OAAO,IAAI;UACnC,oBACE,IAAAhE,WAAA,CAAA6G,GAAA;YAEElF,GAAG,EAAEsD,SAAS,CAACkC,MAAM,CAACD,UAAU,CAAChC,GAAG,CAAC,CAAE;YACvC,cAAYgC,UAAU,CAACpD,KAAM;YAC7B5B,KAAK,EAAE;cACL8E,QAAQ,EAAE,UAAU;cACpB5D,GAAG,EAAE,CAAC;cACNgE,IAAI,EAAE,CAAC;cACPL,KAAK,EAAE,MAAM;cACbM,SAAS,EAAE,cACTH,UAAU,CAACV,KAAK,GAAG9C,WAAW,CAAC+C,OAAO,CAAC7D,YAAY;YAEvD,CAAE;YAAAqD,QAAA,EAEDpE,UAAU,GACPA,UAAU,CAAC;cAAEkC,IAAI;cAAED,KAAK,EAAEoD,UAAU,CAACpD;YAAM,CAAC,CAAC,GAC7C;UAAI,GAfHoD,UAAU,CAAChC,GAgBb,CAAC;QAEV,CAAC;MAAC,CACC;IAAC,CACH,CAAC,EACLW,MAAM;EAAA,CACH,CAAC;AAEX;AAEA,MAAMyB,WAAW,GAAAC,OAAA,CAAAD,WAAA,gBAAG3H,KAAK,CAAC6H,UAAU,CAAC/F,mBAAmB,CAEjC;AAAC,IAAAgG,QAAA,GAAAF,OAAA,CAAA5G,OAAA,GAGT2G,WAAW","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["list/types.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `VirtualList` — the canonical cross-platform virtualized list for the Oxy
|
|
5
|
+
* ecosystem. Every app uses this ONE implementation for grouped/stacked row
|
|
6
|
+
* lists (who-to-follow, starter packs, connections, settings rows, …) so the
|
|
7
|
+
* virtualization behaviour is identical everywhere.
|
|
8
|
+
*
|
|
9
|
+
* NATIVE variant: a thin, correctly-typed wrapper over React Native `FlatList`.
|
|
10
|
+
* The consumer lists this component replaces are short and uniform, so the
|
|
11
|
+
* platform's own virtualization is the simplest robust choice — no
|
|
12
|
+
* `@legendapp/list`, no app-specific scroll bridge, nothing for a consumer to
|
|
13
|
+
* wire up. Bloom stays app-agnostic.
|
|
14
|
+
*
|
|
15
|
+
* WEB variant (`index.web.tsx`, selected via the `"browser"` export condition):
|
|
16
|
+
* a document-scroll window virtualizer built on `@tanstack/react-virtual`.
|
|
17
|
+
*
|
|
18
|
+
* This default file has NO platform-only imports, so consumer `tsc` and web
|
|
19
|
+
* bundlers resolve it cleanly (mirrors the `../scroll` / `../content-panel`
|
|
20
|
+
* fork pattern). The public API is shared via `./types`, so both forks expose
|
|
21
|
+
* an identical, generic, strongly-typed surface.
|
|
22
|
+
*/
|
|
23
|
+
import * as React from 'react';
|
|
24
|
+
import { FlatList } from 'react-native';
|
|
25
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
26
|
+
function renderSlot(slot) {
|
|
27
|
+
if (!slot) return null;
|
|
28
|
+
return typeof slot === 'function' ? slot() : slot;
|
|
29
|
+
}
|
|
30
|
+
function VirtualListNativeInner(props, ref) {
|
|
31
|
+
const {
|
|
32
|
+
data,
|
|
33
|
+
renderItem,
|
|
34
|
+
keyExtractor,
|
|
35
|
+
ListHeaderComponent,
|
|
36
|
+
ListEmptyComponent,
|
|
37
|
+
ListFooterComponent,
|
|
38
|
+
style,
|
|
39
|
+
contentContainerStyle,
|
|
40
|
+
onEndReached,
|
|
41
|
+
onEndReachedThreshold,
|
|
42
|
+
refreshing,
|
|
43
|
+
onRefresh,
|
|
44
|
+
initialNumToRender,
|
|
45
|
+
maxToRenderPerBatch,
|
|
46
|
+
windowSize,
|
|
47
|
+
removeClippedSubviews,
|
|
48
|
+
testID
|
|
49
|
+
} = props;
|
|
50
|
+
const listRef = React.useRef(null);
|
|
51
|
+
React.useImperativeHandle(ref, () => ({
|
|
52
|
+
scrollToOffset: params => listRef.current?.scrollToOffset({
|
|
53
|
+
offset: params?.offset ?? 0,
|
|
54
|
+
animated: params?.animated ?? true
|
|
55
|
+
}),
|
|
56
|
+
scrollTo: params => listRef.current?.scrollToOffset({
|
|
57
|
+
offset: params?.y ?? 0,
|
|
58
|
+
animated: params?.animated ?? true
|
|
59
|
+
})
|
|
60
|
+
}), []);
|
|
61
|
+
const renderFlatItem = React.useCallback(info => renderItem ? renderItem({
|
|
62
|
+
item: info.item,
|
|
63
|
+
index: info.index
|
|
64
|
+
}) : null, [renderItem]);
|
|
65
|
+
return /*#__PURE__*/_jsx(FlatList, {
|
|
66
|
+
ref: listRef,
|
|
67
|
+
data: data ?? undefined,
|
|
68
|
+
renderItem: renderFlatItem,
|
|
69
|
+
keyExtractor: keyExtractor,
|
|
70
|
+
ListHeaderComponent: renderSlot(ListHeaderComponent),
|
|
71
|
+
ListEmptyComponent: renderSlot(ListEmptyComponent),
|
|
72
|
+
ListFooterComponent: renderSlot(ListFooterComponent),
|
|
73
|
+
style: style,
|
|
74
|
+
contentContainerStyle: contentContainerStyle,
|
|
75
|
+
onEndReached: onEndReached ? () => onEndReached() : undefined,
|
|
76
|
+
onEndReachedThreshold: onEndReachedThreshold,
|
|
77
|
+
refreshing: refreshing,
|
|
78
|
+
onRefresh: onRefresh,
|
|
79
|
+
initialNumToRender: initialNumToRender,
|
|
80
|
+
maxToRenderPerBatch: maxToRenderPerBatch,
|
|
81
|
+
windowSize: windowSize,
|
|
82
|
+
removeClippedSubviews: removeClippedSubviews,
|
|
83
|
+
testID: testID
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
const VirtualList = /*#__PURE__*/React.forwardRef(VirtualListNativeInner);
|
|
87
|
+
export { VirtualList };
|
|
88
|
+
export default VirtualList;
|
|
89
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","FlatList","jsx","_jsx","renderSlot","slot","VirtualListNativeInner","props","ref","data","renderItem","keyExtractor","ListHeaderComponent","ListEmptyComponent","ListFooterComponent","style","contentContainerStyle","onEndReached","onEndReachedThreshold","refreshing","onRefresh","initialNumToRender","maxToRenderPerBatch","windowSize","removeClippedSubviews","testID","listRef","useRef","useImperativeHandle","scrollToOffset","params","current","offset","animated","scrollTo","y","renderFlatItem","useCallback","info","item","index","undefined","VirtualList","forwardRef"],"sourceRoot":"../../../src","sources":["list/index.tsx"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,QAAQ,QAAiC,cAAc;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAgBjE,SAASC,UAAUA,CAACC,IAAqB,EAA6B;EACpE,IAAI,CAACA,IAAI,EAAE,OAAO,IAAI;EACtB,OAAO,OAAOA,IAAI,KAAK,UAAU,GAAGA,IAAI,CAAC,CAAC,GAAGA,IAAI;AACnD;AAEA,SAASC,sBAAsBA,CAC7BC,KAA0B,EAC1BC,GAA0C,EAC1C;EACA,MAAM;IACJC,IAAI;IACJC,UAAU;IACVC,YAAY;IACZC,mBAAmB;IACnBC,kBAAkB;IAClBC,mBAAmB;IACnBC,KAAK;IACLC,qBAAqB;IACrBC,YAAY;IACZC,qBAAqB;IACrBC,UAAU;IACVC,SAAS;IACTC,kBAAkB;IAClBC,mBAAmB;IACnBC,UAAU;IACVC,qBAAqB;IACrBC;EACF,CAAC,GAAGlB,KAAK;EAET,MAAMmB,OAAO,GAAG1B,KAAK,CAAC2B,MAAM,CAAc,IAAI,CAAC;EAE/C3B,KAAK,CAAC4B,mBAAmB,CACvBpB,GAAG,EACH,OAAO;IACLqB,cAAc,EAAGC,MA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C,qBAAqB,EAAEA,qBAAsB;IAC7CC,MAAM,EAAEA;EAAO,CAChB,CAAC;AAEN;AAEA,MAAMiB,WAAW,gBAAG1C,KAAK,CAAC2C,UAAU,CAACrC,sBAAsB,CAEpC;AAEvB,SAASoC,WAAW;AACpB,eAAeA,WAAW","ignoreList":[]}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `VirtualList` — WEB variant. A document-scroll (window) virtualizer built on
|
|
5
|
+
* `@tanstack/react-virtual`'s `useWindowVirtualizer`, mirroring the proven
|
|
6
|
+
* Mention feed virtualizer. The BODY scrolls (so scrolling works from anywhere,
|
|
7
|
+
* including over sticky side columns) and only the rows in the virtual window
|
|
8
|
+
* are mounted, so the DOM stays bounded.
|
|
9
|
+
*
|
|
10
|
+
* Why this exists (the bug it fixes): a previous app-local list used the same
|
|
11
|
+
* hook but rendered ZERO rows in production — the wrapper grew to the right
|
|
12
|
+
* height (`getTotalSize()` was correct) yet `getVirtualItems()` came back empty,
|
|
13
|
+
* so only the header painted. Root cause: `useWindowVirtualizer` can latch an
|
|
14
|
+
* initial frame in which the window rect measured as `0` (or `scrollMargin` was
|
|
15
|
+
* still stale), which leaves the computed range empty; a STATIC, finite list
|
|
16
|
+
* re-renders too few times to self-correct and sticks on that bad frame. (The
|
|
17
|
+
* feed only survived by incidental re-render churn — data/loading updates and
|
|
18
|
+
* scroll/intersection observers — which a plain list does not have.)
|
|
19
|
+
*
|
|
20
|
+
* This implementation is SELF-SUFFICIENT and does not rely on incidental churn:
|
|
21
|
+
*
|
|
22
|
+
* 1. `scrollMargin` (the wrapper's offset from the document top) is measured in
|
|
23
|
+
* a layout effect AND re-synced on window `resize`.
|
|
24
|
+
* 2. An explicit post-mount recompute (`virtualizer.measure()`) forces the
|
|
25
|
+
* range to be recomputed once the real viewport height + offset are known —
|
|
26
|
+
* guaranteeing a short list mounts EVERY row in the first viewport even with
|
|
27
|
+
* zero further re-renders. Re-run on resize.
|
|
28
|
+
* 3. The measured spacer is `Math.max(totalSize, lastItemEnd)`, so it always
|
|
29
|
+
* contains every absolutely-positioned row even when `scrollMargin` is
|
|
30
|
+
* momentarily stale; the document therefore always grows to the full content
|
|
31
|
+
* height (keeping sticky side rails pinned) and the window-scroll geometry
|
|
32
|
+
* the virtualizer reads stays consistent.
|
|
33
|
+
* 4. Per-row `measureElement` refs are STABLE (cached per key), so rows are not
|
|
34
|
+
* detached/re-measured on every render.
|
|
35
|
+
*
|
|
36
|
+
* Native bundlers use `./index.tsx` (a `FlatList` wrapper); web bundlers select
|
|
37
|
+
* this file via the `"browser"` export condition in `package.json`.
|
|
38
|
+
*/
|
|
39
|
+
import * as React from 'react';
|
|
40
|
+
import { StyleSheet, View } from 'react-native';
|
|
41
|
+
import { useWindowVirtualizer } from '@tanstack/react-virtual';
|
|
42
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
43
|
+
// Rows in these lists (user rows, pack cards) are short and fairly uniform; a
|
|
44
|
+
// small estimate + per-row measurement keeps the mounted node count bounded.
|
|
45
|
+
const DEFAULT_ESTIMATED_ITEM_SIZE = 72;
|
|
46
|
+
const DEFAULT_OVERSCAN = 8;
|
|
47
|
+
|
|
48
|
+
// Bound the per-key ref-callback cache so a very long scroll session does not
|
|
49
|
+
// accumulate one closure per key forever.
|
|
50
|
+
const ROW_REF_CACHE_CAP = 500;
|
|
51
|
+
function renderSlot(slot) {
|
|
52
|
+
if (!slot) return null;
|
|
53
|
+
return typeof slot === 'function' ? slot() : slot;
|
|
54
|
+
}
|
|
55
|
+
function VirtualListWebInner(props, ref) {
|
|
56
|
+
const {
|
|
57
|
+
data,
|
|
58
|
+
renderItem,
|
|
59
|
+
keyExtractor,
|
|
60
|
+
ListHeaderComponent,
|
|
61
|
+
ListEmptyComponent,
|
|
62
|
+
ListFooterComponent,
|
|
63
|
+
style,
|
|
64
|
+
contentContainerStyle,
|
|
65
|
+
estimatedItemSize,
|
|
66
|
+
overscan,
|
|
67
|
+
testID
|
|
68
|
+
} = props;
|
|
69
|
+
const items = data ?? [];
|
|
70
|
+
const count = items.length;
|
|
71
|
+
|
|
72
|
+
// Wrapper element used as the virtualizer's measurement origin. The window is
|
|
73
|
+
// the scroller; `scrollMargin` is the wrapper's offset from the document top
|
|
74
|
+
// (everything above the rows), so virtual offsets map to page offsets.
|
|
75
|
+
const wrapperRef = React.useRef(null);
|
|
76
|
+
const [scrollMargin, setScrollMargin] = React.useState(0);
|
|
77
|
+
const measureScrollMargin = React.useCallback(() => {
|
|
78
|
+
const node = wrapperRef.current;
|
|
79
|
+
if (!node || typeof window === 'undefined') return;
|
|
80
|
+
const top = node.getBoundingClientRect().top + window.scrollY;
|
|
81
|
+
setScrollMargin(prev => prev !== top ? top : prev);
|
|
82
|
+
}, []);
|
|
83
|
+
|
|
84
|
+
// Read the wrapper's top offset synchronously after layout so the first
|
|
85
|
+
// virtual frame already positions rows correctly. Re-run when the row count
|
|
86
|
+
// changes (content above/below the window shifts the wrapper).
|
|
87
|
+
React.useLayoutEffect(() => {
|
|
88
|
+
measureScrollMargin();
|
|
89
|
+
}, [measureScrollMargin, count]);
|
|
90
|
+
const estimate = estimatedItemSize ?? DEFAULT_ESTIMATED_ITEM_SIZE;
|
|
91
|
+
const virtualizer = useWindowVirtualizer({
|
|
92
|
+
count,
|
|
93
|
+
estimateSize: () => estimate,
|
|
94
|
+
overscan: overscan ?? DEFAULT_OVERSCAN,
|
|
95
|
+
scrollMargin,
|
|
96
|
+
getItemKey: keyExtractor ? index => {
|
|
97
|
+
const item = items[index];
|
|
98
|
+
return item !== undefined ? keyExtractor(item, index) : index;
|
|
99
|
+
} : undefined
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// Explicit post-mount recompute + resize re-sync. `useWindowVirtualizer` can
|
|
103
|
+
// latch a frame where the window rect read as 0 / `scrollMargin` was stale,
|
|
104
|
+
// leaving `getVirtualItems()` empty even though rows exist. A static list does
|
|
105
|
+
// not re-render enough to self-correct, so we force the range to recompute
|
|
106
|
+
// once the real viewport + offset are known — and again on every resize.
|
|
107
|
+
React.useEffect(() => {
|
|
108
|
+
if (typeof window === 'undefined') return;
|
|
109
|
+
const sync = () => {
|
|
110
|
+
measureScrollMargin();
|
|
111
|
+
virtualizer.measure();
|
|
112
|
+
};
|
|
113
|
+
sync();
|
|
114
|
+
window.addEventListener('resize', sync);
|
|
115
|
+
return () => window.removeEventListener('resize', sync);
|
|
116
|
+
}, [measureScrollMargin, virtualizer]);
|
|
117
|
+
React.useImperativeHandle(ref, () => ({
|
|
118
|
+
scrollToOffset: params => {
|
|
119
|
+
if (typeof window === 'undefined') return;
|
|
120
|
+
window.scrollTo({
|
|
121
|
+
top: params?.offset ?? 0,
|
|
122
|
+
behavior: params?.animated === false ? 'auto' : 'smooth'
|
|
123
|
+
});
|
|
124
|
+
},
|
|
125
|
+
scrollTo: params => {
|
|
126
|
+
if (typeof window === 'undefined') return;
|
|
127
|
+
window.scrollTo({
|
|
128
|
+
top: params?.y ?? 0,
|
|
129
|
+
behavior: params?.animated === false ? 'auto' : 'smooth'
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}), []);
|
|
133
|
+
|
|
134
|
+
// Stable per-key ref factory wiring the virtualizer's measurement ref. A fresh
|
|
135
|
+
// inline arrow each render would make React detach/re-attach (and re-measure)
|
|
136
|
+
// every row on every render; the cached callback is reused for the same key so
|
|
137
|
+
// the ref only fires on real mount/unmount.
|
|
138
|
+
const measureElement = virtualizer.measureElement;
|
|
139
|
+
const rowRefCallbacks = React.useRef(new Map());
|
|
140
|
+
const getRowRef = React.useCallback(key => {
|
|
141
|
+
const cache = rowRefCallbacks.current;
|
|
142
|
+
const existing = cache.get(key);
|
|
143
|
+
if (existing) return existing;
|
|
144
|
+
if (cache.size > ROW_REF_CACHE_CAP) cache.clear();
|
|
145
|
+
const cb = node => measureElement(node);
|
|
146
|
+
cache.set(key, cb);
|
|
147
|
+
return cb;
|
|
148
|
+
}, [measureElement]);
|
|
149
|
+
const flatStyle = StyleSheet.flatten(style);
|
|
150
|
+
const flatContentStyle = StyleSheet.flatten(contentContainerStyle);
|
|
151
|
+
const header = renderSlot(ListHeaderComponent);
|
|
152
|
+
const footer = renderSlot(ListFooterComponent);
|
|
153
|
+
if (count === 0) {
|
|
154
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
155
|
+
style: [{
|
|
156
|
+
minHeight: 0
|
|
157
|
+
}, flatStyle],
|
|
158
|
+
testID: testID,
|
|
159
|
+
children: [header, renderSlot(ListEmptyComponent), footer]
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
const virtualItems = virtualizer.getVirtualItems();
|
|
163
|
+
const totalSize = virtualizer.getTotalSize();
|
|
164
|
+
|
|
165
|
+
// The measured spacer MUST contain every absolutely-positioned row; size it to
|
|
166
|
+
// the MAX of `totalSize` and the rows' real extent so the document always
|
|
167
|
+
// grows to full content height even when `scrollMargin` is momentarily stale.
|
|
168
|
+
const lastItem = virtualItems.length > 0 ? virtualItems[virtualItems.length - 1] : undefined;
|
|
169
|
+
const lastItemEnd = lastItem ? lastItem.start + lastItem.size - virtualizer.options.scrollMargin : 0;
|
|
170
|
+
const spacerHeight = Math.max(totalSize, lastItemEnd);
|
|
171
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
172
|
+
style: [{
|
|
173
|
+
minHeight: 0
|
|
174
|
+
}, flatStyle],
|
|
175
|
+
testID: testID,
|
|
176
|
+
children: [header, /*#__PURE__*/_jsx("div", {
|
|
177
|
+
style: flatContentStyle,
|
|
178
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
179
|
+
ref: wrapperRef,
|
|
180
|
+
style: {
|
|
181
|
+
height: spacerHeight,
|
|
182
|
+
width: '100%',
|
|
183
|
+
position: 'relative'
|
|
184
|
+
},
|
|
185
|
+
children: virtualItems.map(virtualRow => {
|
|
186
|
+
const item = items[virtualRow.index];
|
|
187
|
+
if (item === undefined) return null;
|
|
188
|
+
return /*#__PURE__*/_jsx("div", {
|
|
189
|
+
ref: getRowRef(String(virtualRow.key)),
|
|
190
|
+
"data-index": virtualRow.index,
|
|
191
|
+
style: {
|
|
192
|
+
position: 'absolute',
|
|
193
|
+
top: 0,
|
|
194
|
+
left: 0,
|
|
195
|
+
width: '100%',
|
|
196
|
+
transform: `translateY(${virtualRow.start - virtualizer.options.scrollMargin}px)`
|
|
197
|
+
},
|
|
198
|
+
children: renderItem ? renderItem({
|
|
199
|
+
item,
|
|
200
|
+
index: virtualRow.index
|
|
201
|
+
}) : null
|
|
202
|
+
}, virtualRow.key);
|
|
203
|
+
})
|
|
204
|
+
})
|
|
205
|
+
}), footer]
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
const VirtualList = /*#__PURE__*/React.forwardRef(VirtualListWebInner);
|
|
209
|
+
export { VirtualList };
|
|
210
|
+
export default VirtualList;
|
|
211
|
+
//# sourceMappingURL=index.web.js.map
|