react-window 2.0.0-alpha.4 → 2.0.0-alpha.6

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.
@@ -1,595 +1,688 @@
1
- import { jsx as j } from "react/jsx-runtime";
2
- import { useLayoutEffect as D, useEffect as W, useMemo as k, useState as L, useRef as B, useCallback as P, memo as N, useImperativeHandle as Y, createElement as q } from "react";
3
- const U = typeof window < "u" ? D : W;
4
- function V(t) {
5
- if (t !== void 0)
6
- switch (typeof t) {
1
+ import { jsx as U } from "react/jsx-runtime";
2
+ import { useLayoutEffect as K, useEffect as A, useMemo as E, useState as H, useRef as V, useCallback as G, memo as Q, useImperativeHandle as X, createElement as Z } from "react";
3
+ const F = typeof window < "u" ? K : A;
4
+ function P(e) {
5
+ if (e !== void 0)
6
+ switch (typeof e) {
7
7
  case "number":
8
- return t;
8
+ return e;
9
9
  case "string": {
10
- if (t.endsWith("px"))
11
- return parseFloat(t);
10
+ if (e.endsWith("px"))
11
+ return parseFloat(e);
12
12
  break;
13
13
  }
14
14
  }
15
15
  }
16
- function J({
17
- box: t,
18
- defaultHeight: o,
19
- defaultWidth: n,
20
- disabled: s,
21
- element: e,
16
+ function te({
17
+ box: e,
18
+ defaultHeight: t,
19
+ defaultWidth: s,
20
+ disabled: i,
21
+ element: o,
22
22
  mode: f,
23
- style: l
23
+ style: n
24
24
  }) {
25
- const { styleHeight: c, styleWidth: r } = k(
25
+ const { styleHeight: c, styleWidth: r } = E(
26
26
  () => ({
27
- styleHeight: V(l?.height),
28
- styleWidth: V(l?.width)
27
+ styleHeight: P(n?.height),
28
+ styleWidth: P(n?.width)
29
29
  }),
30
- [l?.height, l?.width]
31
- ), [u, w] = L({
32
- height: o,
33
- width: n
34
- }), I = s || f === "only-height" && c !== void 0 || f === "only-width" && r !== void 0 || c !== void 0 && r !== void 0;
35
- return U(() => {
36
- if (e === null || I)
30
+ [n?.height, n?.width]
31
+ ), [d, h] = H({
32
+ height: t,
33
+ width: s
34
+ }), m = i || f === "only-height" && c !== void 0 || f === "only-width" && r !== void 0 || c !== void 0 && r !== void 0;
35
+ return F(() => {
36
+ if (o === null || m)
37
37
  return;
38
- const O = new ResizeObserver((S) => {
39
- for (const m of S) {
40
- const { contentRect: a, target: b } = m;
41
- e === b && w((d) => d.height === a.height && d.width === a.width ? d : {
42
- height: a.height,
43
- width: a.width
38
+ const b = new ResizeObserver((v) => {
39
+ for (const a of v) {
40
+ const { contentRect: w, target: g } = a;
41
+ o === g && h((u) => u.height === w.height && u.width === w.width ? u : {
42
+ height: w.height,
43
+ width: w.width
44
44
  });
45
45
  }
46
46
  });
47
- return O.observe(e, { box: t }), () => {
48
- O?.unobserve(e);
47
+ return b.observe(o, { box: e }), () => {
48
+ b?.unobserve(o);
49
49
  };
50
- }, [t, I, e, c, r]), k(
50
+ }, [e, m, o, c, r]), E(
51
51
  () => ({
52
- height: c ?? u.height,
53
- width: r ?? u.width
52
+ height: c ?? d.height,
53
+ width: r ?? d.width
54
54
  }),
55
- [u, c, r]
55
+ [d, c, r]
56
56
  );
57
57
  }
58
- function $(t, o = "Assertion error") {
59
- if (!t)
60
- throw console.error(o), Error(o);
58
+ function se(e) {
59
+ const t = V(() => {
60
+ throw new Error("Cannot call an event handler while rendering.");
61
+ });
62
+ return F(() => {
63
+ t.current = e;
64
+ }, [e]), G((s) => t.current?.(s), [t]);
61
65
  }
62
- function K({
63
- cachedBounds: t,
64
- itemCount: o,
65
- itemSize: n
66
+ function $(e, t = "Assertion error") {
67
+ if (!e)
68
+ throw console.error(t), Error(t);
69
+ }
70
+ function _({
71
+ cachedBounds: e,
72
+ itemCount: t,
73
+ itemSize: s
66
74
  }) {
67
- if (typeof n == "number")
68
- return o * n;
69
- if (t.size > 0) {
70
- const s = t.get(t.size - 1);
71
- $(s !== void 0, "Unexpected bounds cache miss");
72
- const e = (s.scrollOffset + s.size) / t.size;
73
- return o * e;
74
- } else
75
+ if (t === 0)
75
76
  return 0;
77
+ if (typeof s == "number")
78
+ return t * s;
79
+ {
80
+ const i = e.get(
81
+ e.size === 0 ? 0 : e.size - 1
82
+ );
83
+ $(i !== void 0, "Unexpected bounds cache miss");
84
+ const o = (i.scrollOffset + i.size) / e.size;
85
+ return t * o;
86
+ }
76
87
  }
77
- function Q({
78
- align: t,
79
- cachedBounds: o,
80
- index: n,
81
- itemCount: s,
82
- containerScrollOffset: e,
83
- containerSize: f
88
+ function oe({
89
+ align: e,
90
+ cachedBounds: t,
91
+ index: s,
92
+ itemCount: i,
93
+ itemSize: o,
94
+ containerScrollOffset: f,
95
+ containerSize: n
84
96
  }) {
85
- const l = o.get(s - 1).scrollOffset, c = l + l - f, r = Math.max(
97
+ const c = _({
98
+ cachedBounds: t,
99
+ itemCount: i,
100
+ itemSize: o
101
+ }), r = t.get(s), d = Math.max(
86
102
  0,
87
- o.get(n + 1).scrollOffset - f
88
- ), u = Math.min(
89
- l,
90
- o.get(n).scrollOffset
103
+ Math.min(c - n, r.scrollOffset)
104
+ ), h = Math.max(
105
+ 0,
106
+ r.scrollOffset - n + r.size
91
107
  );
92
- switch (t === "smart" && (e >= r && e <= u ? t = "auto" : t = "center"), t) {
108
+ switch (e === "smart" && (f >= h && f <= d ? e = "auto" : e = "center"), e) {
93
109
  case "start":
94
- return Math.min(c, u);
110
+ return d;
95
111
  case "end":
96
- return r;
97
- case "center": {
98
- const w = Math.round(
99
- r + (u - r) / 2
100
- );
101
- return w < Math.ceil(f / 2) ? 0 : w > c ? c : w;
102
- }
112
+ return h;
113
+ case "center":
114
+ return r.scrollOffset <= n / 2 ? 0 : r.scrollOffset + r.size / 2 >= c - n / 2 ? c - n : r.scrollOffset + r.size / 2 - n / 2;
103
115
  case "auto":
104
116
  default:
105
- return e >= r && e <= u ? e : e < r ? r : u;
117
+ return f >= h && f <= d ? f : f < h ? h : d;
106
118
  }
107
119
  }
108
- function X({
109
- cachedBounds: t,
110
- containerScrollOffset: o,
111
- containerSize: n,
112
- itemCount: s,
113
- overscanCount: e
120
+ function D({
121
+ cachedBounds: e,
122
+ containerScrollOffset: t,
123
+ containerSize: s,
124
+ itemCount: i,
125
+ overscanCount: o
114
126
  }) {
115
- const f = s - 1;
116
- let l = 0, c = -1, r = 0;
127
+ const f = i - 1;
128
+ let n = 0, c = -1, r = 0;
117
129
  for (; r < f; ) {
118
- const u = t.get(r);
119
- if (u.scrollOffset + u.size > o)
130
+ const d = e.get(r);
131
+ if (d.scrollOffset + d.size > t)
120
132
  break;
121
133
  r++;
122
134
  }
123
- for (l = r, l = Math.max(0, l - e); r < f; ) {
124
- const u = t.get(r);
125
- if (u.scrollOffset + u.size >= o + n)
135
+ for (n = r, n = Math.max(0, n - o); r < f; ) {
136
+ const d = e.get(r);
137
+ if (d.scrollOffset + d.size >= t + s)
126
138
  break;
127
139
  r++;
128
140
  }
129
- return c = Math.min(f, r), c = Math.min(s - 1, c + e), l < 0 ? [0, -1] : [l, c];
141
+ return c = Math.min(f, r), c = Math.min(i - 1, c + o), n < 0 ? [0, -1] : [n, c];
130
142
  }
131
- function Z({
132
- itemCount: t,
133
- itemProps: o,
134
- itemSize: n
143
+ function re({
144
+ itemCount: e,
145
+ itemProps: t,
146
+ itemSize: s
135
147
  }) {
136
- const s = /* @__PURE__ */ new Map();
148
+ const i = /* @__PURE__ */ new Map();
137
149
  return {
138
- get(e) {
139
- for ($(e < t, `Invalid index ${e}`); s.size - 1 < e; ) {
140
- const l = s.size, c = typeof n == "number" ? n : n(l, o);
141
- if (l === 0)
142
- s.set(l, {
150
+ get(o) {
151
+ for ($(o < e, `Invalid index ${o}`); i.size - 1 < o; ) {
152
+ const n = i.size;
153
+ let c;
154
+ switch (typeof s) {
155
+ case "function": {
156
+ c = s(n, t);
157
+ break;
158
+ }
159
+ case "number": {
160
+ c = s;
161
+ break;
162
+ }
163
+ }
164
+ if (n === 0)
165
+ i.set(n, {
143
166
  size: c,
144
167
  scrollOffset: 0
145
168
  });
146
169
  else {
147
- const r = s.get(l - 1);
170
+ const r = i.get(n - 1);
148
171
  $(
149
172
  r !== void 0,
150
- `Unexpected bounds cache miss for index ${e}`
151
- ), s.set(l, {
173
+ `Unexpected bounds cache miss for index ${o}`
174
+ ), i.set(n, {
152
175
  scrollOffset: r.scrollOffset + r.size,
153
176
  size: c
154
177
  });
155
178
  }
156
179
  }
157
- const f = s.get(e);
180
+ const f = i.get(o);
158
181
  return $(
159
182
  f !== void 0,
160
- `Unexpected bounds cache miss for index ${e}`
183
+ `Unexpected bounds cache miss for index ${o}`
161
184
  ), f;
162
185
  },
163
- set(e, f) {
164
- s.set(e, f);
186
+ set(o, f) {
187
+ i.set(o, f);
165
188
  },
166
189
  get size() {
167
- return s.size;
190
+ return i.size;
168
191
  }
169
192
  };
170
193
  }
171
- function tt({
172
- itemCount: t,
173
- itemProps: o,
174
- itemSize: n
194
+ function ie({
195
+ itemCount: e,
196
+ itemProps: t,
197
+ itemSize: s
175
198
  }) {
176
- return k(
177
- () => Z({
178
- itemCount: t,
179
- itemProps: o,
180
- itemSize: n
199
+ return E(
200
+ () => re({
201
+ itemCount: e,
202
+ itemProps: t,
203
+ itemSize: s
181
204
  }),
182
- [t, o, n]
205
+ [e, t, s]
183
206
  );
184
207
  }
185
- function et(t) {
186
- const o = B(() => {
187
- throw new Error("Cannot call an event handler while rendering.");
188
- });
189
- return U(() => {
190
- o.current = t;
191
- }, [t]), P((n) => o.current?.(n), [o]);
208
+ function ne({
209
+ containerSize: e,
210
+ itemSize: t
211
+ }) {
212
+ let s;
213
+ switch (typeof t) {
214
+ case "string": {
215
+ $(
216
+ t.endsWith("%"),
217
+ `Invalid item size: "${t}"; string values must be percentages (e.g. "100%")`
218
+ ), $(
219
+ e !== void 0,
220
+ "Container size must be defined if a percentage item size is specified"
221
+ ), s = e * parseInt(t) / 100;
222
+ break;
223
+ }
224
+ default: {
225
+ s = t;
226
+ break;
227
+ }
228
+ }
229
+ return s;
192
230
  }
193
- function G({
194
- containerElement: t,
195
- containerStyle: o,
196
- defaultContainerSize: n = 0,
197
- direction: s,
198
- itemCount: e,
231
+ function q({
232
+ containerElement: e,
233
+ containerStyle: t,
234
+ defaultContainerSize: s = 0,
235
+ direction: i,
236
+ itemCount: o,
199
237
  itemProps: f,
200
- itemSize: l,
201
- overscanCount: c
238
+ itemSize: n,
239
+ onResize: c,
240
+ overscanCount: r
202
241
  }) {
203
- const [r, u] = L([0, -1]), [w, I] = [
204
- Math.min(e - 1, r[0]),
205
- Math.min(e - 1, r[1])
206
- ], { height: O = n, width: S = n } = J({
207
- defaultHeight: s === "vertical" ? n : void 0,
208
- defaultWidth: s === "horizontal" ? n : void 0,
209
- element: t,
210
- mode: s === "vertical" ? "only-height" : "only-width",
211
- style: o
212
- }), m = s === "vertical" ? O : S, a = tt({
213
- itemCount: e,
242
+ const [d, h] = H([0, -1]), [m, b] = [
243
+ Math.min(o - 1, d[0]),
244
+ Math.min(o - 1, d[1])
245
+ ], { height: v = s, width: a = s } = te({
246
+ defaultHeight: i === "vertical" ? s : void 0,
247
+ defaultWidth: i === "horizontal" ? s : void 0,
248
+ element: e,
249
+ mode: i === "vertical" ? "only-height" : "only-width",
250
+ style: t
251
+ }), w = V({
252
+ height: 0,
253
+ width: 0
254
+ }), g = i === "vertical" ? v : a, u = ne({ containerSize: g, itemSize: n });
255
+ K(() => {
256
+ if (typeof c == "function") {
257
+ const l = w.current;
258
+ (l.height !== v || l.width !== a) && (c({ height: v, width: a }, { ...l }), l.height = v, l.width = a);
259
+ }
260
+ }, [v, c, a]);
261
+ const p = ie({
262
+ itemCount: o,
214
263
  itemProps: f,
215
- itemSize: l
216
- }), b = P(
217
- (i) => a.get(i),
218
- [a]
219
- ), d = P(
220
- () => K({
221
- cachedBounds: a,
222
- itemCount: e,
223
- itemSize: l
264
+ itemSize: u
265
+ }), O = G(
266
+ (l) => p.get(l),
267
+ [p]
268
+ ), T = G(
269
+ () => _({
270
+ cachedBounds: p,
271
+ itemCount: o,
272
+ itemSize: u
224
273
  }),
225
- [a, e, l]
226
- ), E = P(
227
- (i) => X({
228
- cachedBounds: a,
229
- containerScrollOffset: i,
230
- containerSize: m,
231
- itemCount: e,
232
- overscanCount: c
274
+ [p, o, u]
275
+ ), y = G(
276
+ (l) => D({
277
+ cachedBounds: p,
278
+ containerScrollOffset: l,
279
+ containerSize: g,
280
+ itemCount: o,
281
+ overscanCount: r
233
282
  }),
234
- [a, m, e, c]
283
+ [p, g, o, r]
235
284
  );
236
- U(() => {
237
- const i = (s === "vertical" ? t?.scrollTop : t?.scrollLeft) ?? 0;
238
- u(E(i));
239
- }, [t, s, E]);
240
- const g = et(
285
+ F(() => {
286
+ const l = (i === "vertical" ? e?.scrollTop : e?.scrollLeft) ?? 0;
287
+ h(y(l));
288
+ }, [e, i, y]), F(() => {
289
+ if (!e)
290
+ return;
291
+ const l = () => {
292
+ h((x) => {
293
+ const R = i === "vertical" ? e.scrollTop : e.scrollLeft, I = D({
294
+ cachedBounds: p,
295
+ containerScrollOffset: R,
296
+ containerSize: g,
297
+ itemCount: o,
298
+ overscanCount: r
299
+ });
300
+ return I[0] === x[0] && I[1] === x[1] ? x : I;
301
+ });
302
+ };
303
+ return e.addEventListener("scroll", l), () => {
304
+ e.removeEventListener("scroll", l);
305
+ };
306
+ }, [
307
+ p,
308
+ e,
309
+ g,
310
+ i,
311
+ o,
312
+ r
313
+ ]);
314
+ const S = se(
241
315
  ({
242
- align: i = "auto",
243
- behavior: p = "auto",
244
- containerScrollOffset: z,
245
- index: x
316
+ align: l = "auto",
317
+ behavior: x = "auto",
318
+ containerScrollOffset: R,
319
+ index: I
246
320
  }) => {
247
- const h = Q({
248
- align: i,
249
- cachedBounds: a,
250
- containerScrollOffset: z,
251
- containerSize: m,
252
- index: x,
253
- itemCount: e
254
- });
255
- s === "horizontal" ? t?.scrollTo({
256
- left: h,
257
- behavior: p || void 0
258
- }) : t?.scrollTo({
259
- behavior: p || void 0,
260
- top: h
321
+ const W = oe({
322
+ align: l,
323
+ cachedBounds: p,
324
+ containerScrollOffset: R,
325
+ containerSize: g,
326
+ index: I,
327
+ itemCount: o,
328
+ itemSize: u
261
329
  });
330
+ if (e)
331
+ if (typeof e.scrollTo == "function")
332
+ i === "horizontal" ? e.scrollTo({
333
+ left: W,
334
+ behavior: x || void 0
335
+ }) : e.scrollTo({
336
+ behavior: x || void 0,
337
+ top: W
338
+ });
339
+ else {
340
+ const k = y(W);
341
+ (k[0] !== m || k[1] !== b) && h(k);
342
+ }
262
343
  }
263
344
  );
264
345
  return {
265
- getCellBounds: b,
266
- getEstimatedHeight: d,
267
- onScroll: () => {
268
- const i = E(
269
- (s === "vertical" ? t?.scrollTop : t?.scrollLeft) ?? 0
270
- );
271
- (i[0] !== w || i[1] !== I) && u(i);
272
- },
273
- scrollToIndex: g,
274
- startIndex: w,
275
- stopIndex: I
346
+ getCellBounds: O,
347
+ getEstimatedSize: T,
348
+ scrollToIndex: S,
349
+ startIndex: m,
350
+ stopIndex: b
276
351
  };
277
352
  }
278
- function A(t) {
279
- return k(() => t, Object.values(t));
353
+ function N(e) {
354
+ return E(() => e, Object.values(e));
280
355
  }
281
- function F(t, o) {
282
- if (t === o)
356
+ function J(e, t) {
357
+ if (e === t)
283
358
  return !0;
284
- if (!!t != !!o || ($(t !== void 0), $(o !== void 0), Object.keys(t).length !== Object.keys(o).length))
359
+ if (!!e != !!t || ($(e !== void 0), $(t !== void 0), Object.keys(e).length !== Object.keys(t).length))
285
360
  return !1;
286
- for (const n in t)
287
- if (!Object.is(o[n], t[n]))
361
+ for (const s in e)
362
+ if (!Object.is(t[s], e[s]))
288
363
  return !1;
289
364
  return !0;
290
365
  }
291
- function _(t, o) {
292
- const { style: n, ...s } = t, { style: e, ...f } = o;
293
- return F(n, e) && F(s, f);
366
+ function C(e, t) {
367
+ const { style: s, ...i } = e, { style: o, ...f } = t;
368
+ return J(s, o) && J(i, f);
294
369
  }
295
- const C = () => {
296
- };
297
- function rt({
298
- cellComponent: t,
299
- cellProps: o,
300
- className: n,
301
- columnCount: s,
302
- columnWidth: e,
370
+ function fe({
371
+ cellComponent: e,
372
+ cellProps: t,
373
+ className: s,
374
+ columnCount: i,
375
+ columnWidth: o,
303
376
  defaultHeight: f = 0,
304
- defaultWidth: l = 0,
377
+ defaultWidth: n = 0,
305
378
  gridRef: c,
306
379
  onCellsRendered: r,
307
- onScroll: u = C,
308
- overscanCount: w = 3,
309
- rowCount: I,
310
- rowHeight: O,
311
- style: S,
312
- ...m
380
+ onResize: d,
381
+ overscanCount: h = 3,
382
+ rowCount: m,
383
+ rowHeight: b,
384
+ style: v,
385
+ ...a
313
386
  }) {
314
- const a = A(o), b = k(
315
- () => N(t, _),
316
- [t]
317
- ), [d, E] = L(null), g = G({
318
- containerElement: d,
319
- defaultContainerSize: l,
387
+ const w = N(t), g = E(
388
+ () => Q(e, C),
389
+ [e]
390
+ ), [u, p] = H(null), {
391
+ getCellBounds: O,
392
+ getEstimatedSize: T,
393
+ startIndex: y,
394
+ scrollToIndex: S,
395
+ stopIndex: l
396
+ } = q({
397
+ containerElement: u,
398
+ defaultContainerSize: n,
320
399
  direction: "horizontal",
321
- itemCount: s,
322
- itemProps: a,
323
- itemSize: e,
324
- overscanCount: w
325
- }), i = G({
326
- containerElement: d,
400
+ itemCount: i,
401
+ itemProps: w,
402
+ itemSize: o,
403
+ onResize: d,
404
+ overscanCount: h
405
+ }), {
406
+ getCellBounds: x,
407
+ getEstimatedSize: R,
408
+ startIndex: I,
409
+ scrollToIndex: W,
410
+ stopIndex: k
411
+ } = q({
412
+ containerElement: u,
327
413
  defaultContainerSize: f,
328
414
  direction: "vertical",
329
- itemCount: I,
330
- itemProps: a,
331
- itemSize: O,
332
- overscanCount: w
333
- }), { startIndex: p, stopIndex: z } = g, { startIndex: x, stopIndex: h } = i;
334
- Y(
415
+ itemCount: m,
416
+ itemProps: w,
417
+ itemSize: b,
418
+ onResize: d,
419
+ overscanCount: h
420
+ });
421
+ X(
335
422
  c,
336
423
  () => ({
337
424
  get element() {
338
- return d;
425
+ return u;
339
426
  },
340
427
  scrollToCell({
341
- behavior: v = "auto",
342
- columnAlign: y = "auto",
343
- columnIndex: T,
344
- rowAlign: H = "auto",
345
- rowIndex: R
428
+ behavior: L = "auto",
429
+ columnAlign: z = "auto",
430
+ columnIndex: M,
431
+ rowAlign: B = "auto",
432
+ rowIndex: j
346
433
  }) {
347
- i?.scrollToIndex({
348
- align: H,
349
- behavior: v,
350
- containerScrollOffset: d?.scrollTop ?? 0,
351
- index: R
352
- }), g?.scrollToIndex({
353
- align: y,
354
- behavior: v,
355
- containerScrollOffset: d?.scrollLeft ?? 0,
356
- index: T
434
+ W({
435
+ align: B,
436
+ behavior: L,
437
+ containerScrollOffset: u?.scrollTop ?? 0,
438
+ index: j
439
+ }), S({
440
+ align: z,
441
+ behavior: L,
442
+ containerScrollOffset: u?.scrollLeft ?? 0,
443
+ index: M
357
444
  });
358
445
  },
359
446
  scrollToColumn({
360
- align: v = "auto",
361
- behavior: y = "auto",
362
- index: T
447
+ align: L = "auto",
448
+ behavior: z = "auto",
449
+ index: M
363
450
  }) {
364
- g?.scrollToIndex({
365
- align: v,
366
- behavior: y,
367
- containerScrollOffset: d?.scrollLeft ?? 0,
368
- index: T
451
+ S({
452
+ align: L,
453
+ behavior: z,
454
+ containerScrollOffset: u?.scrollLeft ?? 0,
455
+ index: M
369
456
  });
370
457
  },
371
458
  scrollToRow({
372
- align: v = "auto",
373
- behavior: y = "auto",
374
- index: T
459
+ align: L = "auto",
460
+ behavior: z = "auto",
461
+ index: M
375
462
  }) {
376
- i?.scrollToIndex({
377
- align: v,
378
- behavior: y,
379
- containerScrollOffset: d?.scrollTop ?? 0,
380
- index: T
463
+ W({
464
+ align: L,
465
+ behavior: z,
466
+ containerScrollOffset: u?.scrollTop ?? 0,
467
+ index: M
381
468
  });
382
469
  }
383
470
  }),
384
- [g, d, i]
385
- ), W(() => {
386
- p >= 0 && z >= 0 && x >= 0 && h >= 0 && r && r({
387
- columnStartIndex: p,
388
- columnStopIndex: z,
389
- rowStartIndex: x,
390
- rowStopIndex: h
471
+ [u, S, W]
472
+ ), A(() => {
473
+ y >= 0 && l >= 0 && I >= 0 && k >= 0 && r && r({
474
+ columnStartIndex: y,
475
+ columnStopIndex: l,
476
+ rowStartIndex: I,
477
+ rowStopIndex: k
391
478
  });
392
479
  }, [
393
480
  r,
394
- p,
395
- z,
396
- x,
397
- h
481
+ y,
482
+ l,
483
+ I,
484
+ k
398
485
  ]);
399
- const M = k(() => {
400
- const v = [];
401
- if (g && s > 0 && i && I > 0)
402
- for (let y = x; y <= h; y++) {
403
- const T = i.getCellBounds(y);
404
- for (let H = p; H <= z; H++) {
405
- const R = g.getCellBounds(H);
406
- v.push(
407
- /* @__PURE__ */ q(
408
- b,
486
+ const ee = E(() => {
487
+ const L = [];
488
+ if (i > 0 && m > 0)
489
+ for (let z = I; z <= k; z++) {
490
+ const M = x(z);
491
+ for (let B = y; B <= l; B++) {
492
+ const j = O(B);
493
+ L.push(
494
+ /* @__PURE__ */ Z(
495
+ g,
409
496
  {
410
- ...a,
411
- columnIndex: H,
412
- key: `${y}-${H}`,
413
- rowIndex: y,
497
+ ...w,
498
+ columnIndex: B,
499
+ key: `${z}-${B}`,
500
+ rowIndex: z,
414
501
  style: {
415
502
  position: "absolute",
416
503
  left: 0,
417
- transform: `translate(${R.scrollOffset}px, ${T.scrollOffset}px)`,
418
- height: T.size,
419
- width: R.size
504
+ transform: `translate(${j.scrollOffset}px, ${M.scrollOffset}px)`,
505
+ height: m > 1 ? M.size : "100%",
506
+ width: j.size
420
507
  }
421
508
  }
422
509
  )
423
510
  );
424
511
  }
425
512
  }
426
- return v;
513
+ return L;
427
514
  }, [
428
- b,
429
- a,
430
- s,
431
- p,
432
- z,
433
515
  g,
434
- I,
516
+ w,
517
+ i,
518
+ y,
519
+ l,
520
+ O,
435
521
  x,
436
- h,
437
- i
522
+ m,
523
+ I,
524
+ k
438
525
  ]);
439
- return /* @__PURE__ */ j(
526
+ return /* @__PURE__ */ U(
440
527
  "div",
441
528
  {
442
529
  role: "grid",
443
- ...m,
444
- className: n,
445
- onScroll: (v) => {
446
- g.onScroll(), i.onScroll(), u(v);
447
- },
448
- ref: E,
530
+ ...a,
531
+ className: s,
532
+ ref: p,
449
533
  style: {
450
- ...S,
534
+ width: "100%",
535
+ height: "100%",
536
+ ...v,
451
537
  maxHeight: "100%",
452
538
  maxWidth: "100%",
453
539
  flexGrow: 1,
454
540
  overflow: "auto"
455
541
  },
456
- children: /* @__PURE__ */ j(
542
+ children: /* @__PURE__ */ U(
457
543
  "div",
458
544
  {
459
- className: n,
545
+ className: s,
460
546
  style: {
461
547
  position: "relative",
462
- height: i?.getEstimatedHeight(),
463
- width: g?.getEstimatedHeight()
548
+ height: R(),
549
+ width: T()
464
550
  },
465
- children: M
551
+ children: ee
466
552
  }
467
553
  )
468
554
  }
469
555
  );
470
556
  }
471
- const nt = L, lt = B;
472
- function it({
473
- className: t,
474
- defaultHeight: o = 0,
475
- listRef: n,
476
- onRowsRendered: s,
477
- onScroll: e = C,
557
+ const de = H, ue = V;
558
+ function he({
559
+ className: e,
560
+ defaultHeight: t = 0,
561
+ listRef: s,
562
+ onResize: i,
563
+ onRowsRendered: o,
478
564
  overscanCount: f = 3,
479
- rowComponent: l,
565
+ rowComponent: n,
480
566
  rowCount: c,
481
567
  rowHeight: r,
482
- rowProps: u,
483
- style: w,
484
- ...I
568
+ rowProps: d,
569
+ style: h,
570
+ ...m
485
571
  }) {
486
- const O = A(u), S = k(
487
- () => N(l, _),
488
- [l]
489
- ), [m, a] = L(null), {
490
- getCellBounds: b,
491
- getEstimatedHeight: d,
492
- onScroll: E,
493
- scrollToIndex: g,
494
- startIndex: i,
495
- stopIndex: p
496
- } = G({
497
- containerElement: m,
498
- defaultContainerSize: o,
572
+ const b = N(d), v = E(
573
+ () => Q(n, C),
574
+ [n]
575
+ ), [a, w] = H(null), {
576
+ getCellBounds: g,
577
+ getEstimatedSize: u,
578
+ scrollToIndex: p,
579
+ startIndex: O,
580
+ stopIndex: T
581
+ } = q({
582
+ containerElement: a,
583
+ defaultContainerSize: t,
499
584
  direction: "vertical",
500
585
  itemCount: c,
501
- itemProps: O,
586
+ itemProps: b,
502
587
  itemSize: r,
588
+ onResize: i,
503
589
  overscanCount: f
504
590
  });
505
- Y(
506
- n,
591
+ X(
592
+ s,
507
593
  () => ({
508
594
  get element() {
509
- return m;
595
+ return a;
510
596
  },
511
597
  scrollToRow({
512
- align: x = "auto",
513
- behavior: h = "auto",
514
- index: M
598
+ align: S = "auto",
599
+ behavior: l = "auto",
600
+ index: x
515
601
  }) {
516
- g({
517
- align: x,
518
- behavior: h,
519
- containerScrollOffset: m?.scrollTop ?? 0,
520
- index: M
602
+ p({
603
+ align: S,
604
+ behavior: l,
605
+ containerScrollOffset: a?.scrollTop ?? 0,
606
+ index: x
521
607
  });
522
608
  }
523
609
  }),
524
- [m, g]
525
- ), W(() => {
526
- i >= 0 && p >= 0 && s && s({
527
- startIndex: i,
528
- stopIndex: p
610
+ [a, p]
611
+ ), A(() => {
612
+ O >= 0 && T >= 0 && o && o({
613
+ startIndex: O,
614
+ stopIndex: T
529
615
  });
530
- }, [s, i, p]);
531
- const z = k(() => {
532
- const x = [];
616
+ }, [o, O, T]);
617
+ const y = E(() => {
618
+ const S = [];
533
619
  if (c > 0)
534
- for (let h = i; h <= p; h++) {
535
- const M = b(h);
536
- x.push(
537
- /* @__PURE__ */ q(
538
- S,
620
+ for (let l = O; l <= T; l++) {
621
+ const x = g(l);
622
+ S.push(
623
+ /* @__PURE__ */ Z(
624
+ v,
539
625
  {
540
- ...O,
541
- key: h,
542
- index: h,
626
+ ...b,
627
+ key: l,
628
+ index: l,
543
629
  style: {
544
630
  position: "absolute",
545
631
  left: 0,
546
- transform: `translateY(${M.scrollOffset}px)`,
547
- height: M.size,
632
+ transform: `translateY(${x.scrollOffset}px)`,
633
+ height: x.size,
548
634
  width: "100%"
549
635
  }
550
636
  }
551
637
  )
552
638
  );
553
639
  }
554
- return x;
555
- }, [S, b, c, O, i, p]);
556
- return /* @__PURE__ */ j(
640
+ return S;
641
+ }, [v, g, c, b, O, T]);
642
+ return /* @__PURE__ */ U(
557
643
  "div",
558
644
  {
559
645
  role: "list",
560
- ...I,
561
- className: t,
562
- onScroll: (x) => {
563
- E(), e(x);
564
- },
565
- ref: a,
646
+ ...m,
647
+ className: e,
648
+ ref: w,
566
649
  style: {
567
- ...w,
650
+ ...h,
568
651
  maxHeight: "100%",
569
652
  flexGrow: 1,
570
653
  overflowY: "auto"
571
654
  },
572
- children: /* @__PURE__ */ j(
655
+ children: /* @__PURE__ */ U(
573
656
  "div",
574
657
  {
575
- className: t,
658
+ className: e,
576
659
  style: {
577
- height: d(),
660
+ height: u(),
578
661
  position: "relative",
579
662
  width: "100%"
580
663
  },
581
- children: z
664
+ children: y
582
665
  }
583
666
  )
584
667
  }
585
668
  );
586
669
  }
587
- const ct = L, ft = B;
670
+ const ae = H, ge = V;
671
+ let Y = -1;
672
+ function pe(e = !1) {
673
+ if (Y === -1 || e) {
674
+ const t = document.createElement("div"), s = t.style;
675
+ s.width = "50px", s.height = "50px", s.overflow = "scroll", document.body.appendChild(t), Y = t.offsetWidth - t.clientWidth, document.body.removeChild(t);
676
+ }
677
+ return Y;
678
+ }
588
679
  export {
589
- rt as Grid,
590
- it as List,
591
- nt as useGridCallbackRef,
592
- lt as useGridRef,
593
- ct as useListCallbackRef,
594
- ft as useListRef
680
+ fe as Grid,
681
+ he as List,
682
+ pe as getScrollbarSize,
683
+ de as useGridCallbackRef,
684
+ ue as useGridRef,
685
+ ae as useListCallbackRef,
686
+ ge as useListRef
595
687
  };
688
+ //# sourceMappingURL=react-window.js.map