@@ -37,11 +37,11 @@ const fixed_grid_1 = require("../fixed-grid");
37
37
const itemsLine = Array.from({ length: 300 }).map((_, i) => `item ${i}`);
38
38
const itemsGrid = Array.from({ length: 300 }).map((_, iy) => Array.from({ length: 300 }).map((_, ix) => `item ${ix} ${iy}`));
39
39
function ListWithHookExample() {
40
- const items = itemsLine ;
40
+ const [ items, setItems] = (0, react_1.useState)([]) ;
41
41
const containerRef = (0, react_1.useRef)(undefined);
42
42
const infoRef = (0, react_1.useRef)(undefined);
43
43
const itemHeight = 40;
44
- const { renderedItems, updateViewRect } = (0, __1.useVirtualOverflowY)({
44
+ const { renderedItems, updateViewRect, itemSlice } = (0, __1.useVirtualOverflowY)({
45
45
containerRef,
46
46
itemHeight,
47
47
itemsLengthY: items.length,
@@ -57,6 +57,12 @@ function ListWithHookExample() {
57
57
infoRef.current.innerText = `Visible rect of content:\n\n${JSON.stringify(visibleRect, null, 2)}`;
58
58
}, 24);
59
59
}, []);
60
+ (0, react_1.useEffect)(() => {
61
+ if (itemSlice.topStartIndex + itemSlice.lengthY >= items.length - 4) {
62
+ // load more
63
+ setItems(prev => [...prev, ...itemsLine]);
64
+ }
65
+ }, [itemSlice.topStartIndex, itemSlice.lengthY]);
60
66
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { ref: infoRef, style: { position: 'fixed', top: 0, right: 0, paddingRight: '40px', width: '200px' } }), (0, jsx_runtime_1.jsx)("div", { style: { overflowY: 'scroll', height: '300px', background: 'lightgreen' }, children: (0, jsx_runtime_1.jsx)("div", { ref: containerRef, style: { position: 'relative', height: `${itemHeight * items.length}px` }, children: renderedItems }) })] }));
61
67
}
62
68
function VerticalListExample() {
@@ -80,7 +86,7 @@ const rootElement = document.getElementById("demo");
80
86
const root = client_1.default.createRoot(rootElement);
81
87
root.render((0, jsx_runtime_1.jsx)(react_1.default.StrictMode, { children: (0, jsx_runtime_1.jsx)(App, {}) }));
82
88
83
- },{"..":4,"../fixed-grid":2,"../fixed-list-y":3,"../utils":5 ,"react":15 ,"react-dom/client":9 ,"react/jsx-runtime":16 }],2:[function(require,module,exports){
89
+ },{"..":4,"../fixed-grid":2,"../fixed-list-y":3,"../utils":6 ,"react":16 ,"react-dom/client":10 ,"react/jsx-runtime":17 }],2:[function(require,module,exports){
84
90
"use strict";
85
91
Object.defineProperty(exports, "__esModule", { value: true });
86
92
exports.VirtualGrid = void 0;
@@ -108,7 +114,7 @@ function VirtualGrid(props) {
108
114
}
109
115
exports.VirtualGrid = VirtualGrid;
110
116
111
- },{".":4,"react":15 ,"react/jsx-runtime":16 }],3:[function(require,module,exports){
117
+ },{".":4,"react":16 ,"react/jsx-runtime":17 }],3:[function(require,module,exports){
112
118
"use strict";
113
119
Object.defineProperty(exports, "__esModule", { value: true });
114
120
exports.VirtualListY = void 0;
@@ -134,21 +140,12 @@ function VirtualListY(props) {
134
140
}
135
141
exports.VirtualListY = VirtualListY;
136
142
137
- },{".":4,"react":15 ,"react/jsx-runtime":16 }],4:[function(require,module,exports){
143
+ },{".":4,"react":16 ,"react/jsx-runtime":17 }],4:[function(require,module,exports){
138
144
"use strict";
139
145
Object.defineProperty(exports, "__esModule", { value: true });
140
146
exports.useVirtualOverflowGrid = exports.useVirtualOverflowX = exports.useVirtualOverflowY = exports.useCalcVirtualOverflow = exports.virtualOverflowCalcItems = exports.virtualOverflowCalcVisibleRect = void 0;
141
147
const react_1 = require("react");
142
- function debounceAnimationFrame(func) {
143
- let frameRequest = 0;
144
- return {
145
- requestFrame: () => {
146
- cancelAnimationFrame(frameRequest);
147
- frameRequest = requestAnimationFrame((frameTime) => func.call(undefined, frameTime));
148
- },
149
- cancelFrame: () => cancelAnimationFrame(frameRequest)
150
- };
151
- }
148
+ const small_utils_1 = require("./small-utils");
152
149
function virtualOverflowCalcVisibleRect(element) {
153
150
const elementRect = element.getBoundingClientRect();
154
151
const visibleRect = {
@@ -204,7 +201,7 @@ function useCalcVirtualOverflow(params, deps) {
204
201
leftStartIndex: 0,
205
202
lengthX: 0,
206
203
});
207
- const { requestFrame: updateViewRect, cancelFrame } = (0, react_1.useMemo)(() => debounceAnimationFrame ((frameTime) => {
204
+ const { requestFrame: updateViewRect, cancelFrame } = (0, react_1.useMemo)(() => (0, small_utils_1.rvoDebounceAnimationFrame) ((frameTime) => {
208
205
if (!containerRef.current)
209
206
return;
210
207
const visibleRect = calcVisibleRect(containerRef.current, frameTime);
@@ -254,6 +251,7 @@ function useVirtualOverflowY(params, deps = []) {
254
251
return {
255
252
renderedItems: utilRenderItems1D(itemSlice.topStartIndex, itemSlice.lengthY, params.itemHeight, params.renderItem),
256
253
updateViewRect,
254
+ itemSlice,
257
255
};
258
256
}
259
257
exports.useVirtualOverflowY = useVirtualOverflowY;
@@ -262,6 +260,7 @@ function useVirtualOverflowX(params, deps = []) {
262
260
return {
263
261
renderedItems: utilRenderItems1D(itemSlice.leftStartIndex, itemSlice.lengthX, params.itemWidth, params.renderItem),
264
262
updateViewRect,
263
+ itemSlice,
265
264
};
266
265
}
267
266
exports.useVirtualOverflowX = useVirtualOverflowX;
@@ -277,12 +276,29 @@ function useVirtualOverflowGrid(params, deps = []) {
277
276
}
278
277
return {
279
278
renderedItems,
280
- updateViewRect
279
+ updateViewRect,
280
+ itemSlice
281
281
};
282
282
}
283
283
exports.useVirtualOverflowGrid = useVirtualOverflowGrid;
284
284
285
- },{"react":15}],5:[function(require,module,exports){
285
+ },{"./small-utils":5,"react":16}],5:[function(require,module,exports){
286
+ "use strict";
287
+ Object.defineProperty(exports, "__esModule", { value: true });
288
+ exports.rvoDebounceAnimationFrame = void 0;
289
+ function rvoDebounceAnimationFrame(func) {
290
+ let frameRequest = 0;
291
+ return {
292
+ requestFrame: () => {
293
+ cancelAnimationFrame(frameRequest);
294
+ frameRequest = requestAnimationFrame((frameTime) => func.call(undefined, frameTime));
295
+ },
296
+ cancelFrame: () => cancelAnimationFrame(frameRequest),
297
+ };
298
+ }
299
+ exports.rvoDebounceAnimationFrame = rvoDebounceAnimationFrame;
300
+
301
+ },{}],6:[function(require,module,exports){
286
302
"use strict";
287
303
Object.defineProperty(exports, "__esModule", { value: true });
288
304
exports.virtualOverflowUtils = void 0;
@@ -371,7 +387,7 @@ var virtualOverflowUtils;
371
387
virtualOverflowUtils.calcVisibleRectOverflowed = calcVisibleRectOverflowed;
372
388
})(virtualOverflowUtils || (exports.virtualOverflowUtils = virtualOverflowUtils = {}));
373
389
374
- },{}],6 :[function(require,module,exports){
390
+ },{}],7 :[function(require,module,exports){
375
391
// shim for using process in browser
376
392
var process = module.exports = {};
377
393
@@ -557,7 +573,7 @@ process.chdir = function (dir) {
557
573
};
558
574
process.umask = function() { return 0; };
559
575
560
- },{}],7 :[function(require,module,exports){
576
+ },{}],8 :[function(require,module,exports){
561
577
(function (process){(function (){
562
578
/**
563
579
* @license React
@@ -30429,7 +30445,7 @@ if (
30429
30445
}
30430
30446
30431
30447
}).call(this)}).call(this,require('_process'))
30432
- },{"_process":6 ,"react":15 ,"scheduler":19 }],8 :[function(require,module,exports){
30448
+ },{"_process":7 ,"react":16 ,"scheduler":20 }],9 :[function(require,module,exports){
30433
30449
/**
30434
30450
* @license React
30435
30451
* react-dom.production.min.js
@@ -30754,7 +30770,7 @@ exports.hydrateRoot=function(a,b,c){if(!ol(a))throw Error(p(405));var d=null!=c&
30754
30770
e);return new nl(b)};exports.render=function(a,b,c){if(!pl(b))throw Error(p(200));return sl(null,a,b,!1,c)};exports.unmountComponentAtNode=function(a){if(!pl(a))throw Error(p(40));return a._reactRootContainer?(Sk(function(){sl(null,null,a,!1,function(){a._reactRootContainer=null;a[uf]=null})}),!0):!1};exports.unstable_batchedUpdates=Rk;
30755
30771
exports.unstable_renderSubtreeIntoContainer=function(a,b,c,d){if(!pl(c))throw Error(p(200));if(null==a||void 0===a._reactInternals)throw Error(p(38));return sl(a,b,c,!1,d)};exports.version="18.2.0-next-9e3b772b8-20220608";
30756
30772
30757
- },{"react":15 ,"scheduler":19 }],9 :[function(require,module,exports){
30773
+ },{"react":16 ,"scheduler":20 }],10 :[function(require,module,exports){
30758
30774
(function (process){(function (){
30759
30775
'use strict';
30760
30776
@@ -30783,7 +30799,7 @@ if (process.env.NODE_ENV === 'production') {
30783
30799
}
30784
30800
30785
30801
}).call(this)}).call(this,require('_process'))
30786
- },{"_process":6 ,"react-dom":10 }],10 :[function(require,module,exports){
30802
+ },{"_process":7 ,"react-dom":11 }],11 :[function(require,module,exports){
30787
30803
(function (process){(function (){
30788
30804
'use strict';
30789
30805
@@ -30825,7 +30841,7 @@ if (process.env.NODE_ENV === 'production') {
30825
30841
}
30826
30842
30827
30843
}).call(this)}).call(this,require('_process'))
30828
- },{"./cjs/react-dom.development.js":7 ,"./cjs/react-dom.production.min.js":8 ,"_process":6 }],11 :[function(require,module,exports){
30844
+ },{"./cjs/react-dom.development.js":8 ,"./cjs/react-dom.production.min.js":9 ,"_process":7 }],12 :[function(require,module,exports){
30829
30845
(function (process){(function (){
30830
30846
/**
30831
30847
* @license React
@@ -32143,7 +32159,7 @@ exports.jsxs = jsxs;
32143
32159
}
32144
32160
32145
32161
}).call(this)}).call(this,require('_process'))
32146
- },{"_process":6 ,"react":15 }],12 :[function(require,module,exports){
32162
+ },{"_process":7 ,"react":16 }],13 :[function(require,module,exports){
32147
32163
/**
32148
32164
* @license React
32149
32165
* react-jsx-runtime.production.min.js
@@ -32156,7 +32172,7 @@ exports.jsxs = jsxs;
32156
32172
'use strict';var f=require("react"),k=Symbol.for("react.element"),l=Symbol.for("react.fragment"),m=Object.prototype.hasOwnProperty,n=f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,p={key:!0,ref:!0,__self:!0,__source:!0};
32157
32173
function q(c,a,g){var b,d={},e=null,h=null;void 0!==g&&(e=""+g);void 0!==a.key&&(e=""+a.key);void 0!==a.ref&&(h=a.ref);for(b in a)m.call(a,b)&&!p.hasOwnProperty(b)&&(d[b]=a[b]);if(c&&c.defaultProps)for(b in a=c.defaultProps,a)void 0===d[b]&&(d[b]=a[b]);return{$$typeof:k,type:c,key:e,ref:h,props:d,_owner:n.current}}exports.Fragment=l;exports.jsx=q;exports.jsxs=q;
32158
32174
32159
- },{"react":15 }],13 :[function(require,module,exports){
32175
+ },{"react":16 }],14 :[function(require,module,exports){
32160
32176
(function (process){(function (){
32161
32177
/**
32162
32178
* @license React
@@ -34899,7 +34915,7 @@ if (
34899
34915
}
34900
34916
34901
34917
}).call(this)}).call(this,require('_process'))
34902
- },{"_process":6 }],14 :[function(require,module,exports){
34918
+ },{"_process":7 }],15 :[function(require,module,exports){
34903
34919
/**
34904
34920
* @license React
34905
34921
* react.production.min.js
@@ -34927,7 +34943,7 @@ exports.useCallback=function(a,b){return U.current.useCallback(a,b)};exports.use
34927
34943
exports.useInsertionEffect=function(a,b){return U.current.useInsertionEffect(a,b)};exports.useLayoutEffect=function(a,b){return U.current.useLayoutEffect(a,b)};exports.useMemo=function(a,b){return U.current.useMemo(a,b)};exports.useReducer=function(a,b,e){return U.current.useReducer(a,b,e)};exports.useRef=function(a){return U.current.useRef(a)};exports.useState=function(a){return U.current.useState(a)};exports.useSyncExternalStore=function(a,b,e){return U.current.useSyncExternalStore(a,b,e)};
34928
34944
exports.useTransition=function(){return U.current.useTransition()};exports.version="18.2.0";
34929
34945
34930
- },{}],15 :[function(require,module,exports){
34946
+ },{}],16 :[function(require,module,exports){
34931
34947
(function (process){(function (){
34932
34948
'use strict';
34933
34949
@@ -34938,7 +34954,7 @@ if (process.env.NODE_ENV === 'production') {
34938
34954
}
34939
34955
34940
34956
}).call(this)}).call(this,require('_process'))
34941
- },{"./cjs/react.development.js":13 ,"./cjs/react.production.min.js":14 ,"_process":6 }],16 :[function(require,module,exports){
34957
+ },{"./cjs/react.development.js":14 ,"./cjs/react.production.min.js":15 ,"_process":7 }],17 :[function(require,module,exports){
34942
34958
(function (process){(function (){
34943
34959
'use strict';
34944
34960
@@ -34949,7 +34965,7 @@ if (process.env.NODE_ENV === 'production') {
34949
34965
}
34950
34966
34951
34967
}).call(this)}).call(this,require('_process'))
34952
- },{"./cjs/react-jsx-runtime.development.js":11 ,"./cjs/react-jsx-runtime.production.min.js":12 ,"_process":6 }],17 :[function(require,module,exports){
34968
+ },{"./cjs/react-jsx-runtime.development.js":12 ,"./cjs/react-jsx-runtime.production.min.js":13 ,"_process":7 }],18 :[function(require,module,exports){
34953
34969
(function (process,setImmediate){(function (){
34954
34970
/**
34955
34971
* @license React
@@ -35587,7 +35603,7 @@ if (
35587
35603
}
35588
35604
35589
35605
}).call(this)}).call(this,require('_process'),require("timers").setImmediate)
35590
- },{"_process":6 ,"timers":20 }],18 :[function(require,module,exports){
35606
+ },{"_process":7 ,"timers":21 }],19 :[function(require,module,exports){
35591
35607
(function (setImmediate){(function (){
35592
35608
/**
35593
35609
* @license React
@@ -35610,7 +35626,7 @@ exports.unstable_scheduleCallback=function(a,b,c){var d=exports.unstable_now();"
35610
35626
exports.unstable_shouldYield=M;exports.unstable_wrapCallback=function(a){var b=y;return function(){var c=y;y=b;try{return a.apply(this,arguments)}finally{y=c}}};
35611
35627
35612
35628
}).call(this)}).call(this,require("timers").setImmediate)
35613
- },{"timers":20 }],19 :[function(require,module,exports){
35629
+ },{"timers":21 }],20 :[function(require,module,exports){
35614
35630
(function (process){(function (){
35615
35631
'use strict';
35616
35632
@@ -35621,7 +35637,7 @@ if (process.env.NODE_ENV === 'production') {
35621
35637
}
35622
35638
35623
35639
}).call(this)}).call(this,require('_process'))
35624
- },{"./cjs/scheduler.development.js":17 ,"./cjs/scheduler.production.min.js":18 ,"_process":6 }],20 :[function(require,module,exports){
35640
+ },{"./cjs/scheduler.development.js":18 ,"./cjs/scheduler.production.min.js":19 ,"_process":7 }],21 :[function(require,module,exports){
35625
35641
(function (setImmediate,clearImmediate){(function (){
35626
35642
var nextTick = require('process/browser.js').nextTick;
35627
35643
var apply = Function.prototype.apply;
@@ -35700,4 +35716,4 @@ exports.clearImmediate = typeof clearImmediate === "function" ? clearImmediate :
35700
35716
delete immediateIds[id];
35701
35717
};
35702
35718
}).call(this)}).call(this,require("timers").setImmediate,require("timers").clearImmediate)
35703
- },{"process/browser.js":6 ,"timers":20 }]},{},[1]);
35719
+ },{"process/browser.js":7 ,"timers":21 }]},{},[1]);
0 commit comments