react-window 2.0.0-alpha.5 → 2.0.0-alpha.7

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