@jingoz/react-virtual-list
Version:
503 lines (500 loc) • 18 kB
JavaScript
import Se, { useState as Te, useRef as _e, useLayoutEffect as Ae, forwardRef as Ce, useImperativeHandle as ke } from "react";
var W = { exports: {} }, N = {};
/**
* @license React
* react-jsx-runtime.production.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var me;
function Oe() {
if (me) return N;
me = 1;
var u = Symbol.for("react.transitional.element"), v = Symbol.for("react.fragment");
function d(c, s, l) {
var m = null;
if (l !== void 0 && (m = "" + l), s.key !== void 0 && (m = "" + s.key), "key" in s) {
l = {};
for (var _ in s)
_ !== "key" && (l[_] = s[_]);
} else l = s;
return s = l.ref, {
$$typeof: u,
type: c,
key: m,
ref: s !== void 0 ? s : null,
props: l
};
}
return N.Fragment = v, N.jsx = d, N.jsxs = d, N;
}
var P = {};
/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var be;
function Ne() {
return be || (be = 1, process.env.NODE_ENV !== "production" && function() {
function u(e) {
if (e == null) return null;
if (typeof e == "function")
return e.$$typeof === ye ? null : e.displayName || e.name || null;
if (typeof e == "string") return e;
switch (e) {
case G:
return "Fragment";
case pe:
return "Portal";
case Q:
return "Profiler";
case K:
return "StrictMode";
case z:
return "Suspense";
case F:
return "SuspenseList";
}
if (typeof e == "object")
switch (typeof e.tag == "number" && console.error(
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
), e.$$typeof) {
case ee:
return (e.displayName || "Context") + ".Provider";
case D:
return (e._context.displayName || "Context") + ".Consumer";
case q:
var r = e.render;
return e = e.displayName, e || (e = r.displayName || r.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
case J:
return r = e.displayName || null, r !== null ? r : u(e.type) || "Memo";
case H:
r = e._payload, e = e._init;
try {
return u(e(r));
} catch {
}
}
return null;
}
function v(e) {
return "" + e;
}
function d(e) {
try {
v(e);
var r = !1;
} catch {
r = !0;
}
if (r) {
r = console;
var t = r.error, n = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
return t.call(
r,
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
n
), v(e);
}
}
function c() {
}
function s() {
if (k === 0) {
oe = console.log, ne = console.info, ae = console.warn, le = console.error, ue = console.group, se = console.groupCollapsed, ie = console.groupEnd;
var e = {
configurable: !0,
enumerable: !0,
value: c,
writable: !0
};
Object.defineProperties(console, {
info: e,
log: e,
warn: e,
error: e,
group: e,
groupCollapsed: e,
groupEnd: e
});
}
k++;
}
function l() {
if (k--, k === 0) {
var e = { configurable: !0, enumerable: !0, writable: !0 };
Object.defineProperties(console, {
log: p({}, e, { value: oe }),
info: p({}, e, { value: ne }),
warn: p({}, e, { value: ae }),
error: p({}, e, { value: le }),
group: p({}, e, { value: ue }),
groupCollapsed: p({}, e, { value: se }),
groupEnd: p({}, e, { value: ie })
});
}
0 > k && console.error(
"disabledDepth fell below zero. This is a bug in React. Please file an issue."
);
}
function m(e) {
if (X === void 0)
try {
throw Error();
} catch (t) {
var r = t.stack.trim().match(/\n( *(at )?)/);
X = r && r[1] || "", ce = -1 < t.stack.indexOf(`
at`) ? " (<anonymous>)" : -1 < t.stack.indexOf("@") ? "@unknown:0:0" : "";
}
return `
` + X + e + ce;
}
function _(e, r) {
if (!e || B) return "";
var t = Z.get(e);
if (t !== void 0) return t;
B = !0, t = Error.prepareStackTrace, Error.prepareStackTrace = void 0;
var n = null;
n = x.H, x.H = null, s();
try {
var i = {
DetermineComponentFrameRoot: function() {
try {
if (r) {
var h = function() {
throw Error();
};
if (Object.defineProperty(h.prototype, "props", {
set: function() {
throw Error();
}
}), typeof Reflect == "object" && Reflect.construct) {
try {
Reflect.construct(h, []);
} catch (T) {
var $ = T;
}
Reflect.construct(e, [], h);
} else {
try {
h.call();
} catch (T) {
$ = T;
}
e.call(h.prototype);
}
} else {
try {
throw Error();
} catch (T) {
$ = T;
}
(h = e()) && typeof h.catch == "function" && h.catch(function() {
});
}
} catch (T) {
if (T && $ && typeof T.stack == "string")
return [T.stack, $.stack];
}
return [null, null];
}
};
i.DetermineComponentFrameRoot.displayName = "DetermineComponentFrameRoot";
var a = Object.getOwnPropertyDescriptor(
i.DetermineComponentFrameRoot,
"name"
);
a && a.configurable && Object.defineProperty(
i.DetermineComponentFrameRoot,
"name",
{ value: "DetermineComponentFrameRoot" }
);
var o = i.DetermineComponentFrameRoot(), g = o[0], w = o[1];
if (g && w) {
var E = g.split(`
`), R = w.split(`
`);
for (o = a = 0; a < E.length && !E[a].includes(
"DetermineComponentFrameRoot"
); )
a++;
for (; o < R.length && !R[o].includes(
"DetermineComponentFrameRoot"
); )
o++;
if (a === E.length || o === R.length)
for (a = E.length - 1, o = R.length - 1; 1 <= a && 0 <= o && E[a] !== R[o]; )
o--;
for (; 1 <= a && 0 <= o; a--, o--)
if (E[a] !== R[o]) {
if (a !== 1 || o !== 1)
do
if (a--, o--, 0 > o || E[a] !== R[o]) {
var O = `
` + E[a].replace(
" at new ",
" at "
);
return e.displayName && O.includes("<anonymous>") && (O = O.replace("<anonymous>", e.displayName)), typeof e == "function" && Z.set(e, O), O;
}
while (1 <= a && 0 <= o);
break;
}
}
} finally {
B = !1, x.H = n, l(), Error.prepareStackTrace = t;
}
return E = (E = e ? e.displayName || e.name : "") ? m(E) : "", typeof e == "function" && Z.set(e, E), E;
}
function b(e) {
if (e == null) return "";
if (typeof e == "function") {
var r = e.prototype;
return _(
e,
!(!r || !r.isReactComponent)
);
}
if (typeof e == "string") return m(e);
switch (e) {
case z:
return m("Suspense");
case F:
return m("SuspenseList");
}
if (typeof e == "object")
switch (e.$$typeof) {
case q:
return e = _(e.render, !1), e;
case J:
return b(e.type);
case H:
r = e._payload, e = e._init;
try {
return b(e(r));
} catch {
}
}
return "";
}
function S() {
var e = x.A;
return e === null ? null : e.getOwner();
}
function U(e) {
if (te.call(e, "key")) {
var r = Object.getOwnPropertyDescriptor(e, "key").get;
if (r && r.isReactWarning) return !1;
}
return e.key !== void 0;
}
function I(e, r) {
function t() {
fe || (fe = !0, console.error(
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
r
));
}
t.isReactWarning = !0, Object.defineProperty(e, "key", {
get: t,
configurable: !0
});
}
function y() {
var e = u(this.type);
return Ee[e] || (Ee[e] = !0, console.error(
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
)), e = this.props.ref, e !== void 0 ? e : null;
}
function A(e, r, t, n, i, a) {
return t = a.ref, e = {
$$typeof: V,
type: e,
key: r,
props: a,
_owner: i
}, (t !== void 0 ? t : null) !== null ? Object.defineProperty(e, "ref", {
enumerable: !1,
get: y
}) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
configurable: !1,
enumerable: !1,
writable: !0,
value: 0
}), Object.defineProperty(e, "_debugInfo", {
configurable: !1,
enumerable: !1,
writable: !0,
value: null
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
}
function C(e, r, t, n, i, a) {
if (typeof e == "string" || typeof e == "function" || e === G || e === Q || e === K || e === z || e === F || e === Re || typeof e == "object" && e !== null && (e.$$typeof === H || e.$$typeof === J || e.$$typeof === ee || e.$$typeof === D || e.$$typeof === q || e.$$typeof === je || e.getModuleId !== void 0)) {
var o = r.children;
if (o !== void 0)
if (n)
if (L(o)) {
for (n = 0; n < o.length; n++)
M(o[n], e);
Object.freeze && Object.freeze(o);
} else
console.error(
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
);
else M(o, e);
} else
o = "", (e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (o += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports."), e === null ? n = "null" : L(e) ? n = "array" : e !== void 0 && e.$$typeof === V ? (n = "<" + (u(e.type) || "Unknown") + " />", o = " Did you accidentally export a JSX literal instead of a component?") : n = typeof e, console.error(
"React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",
n,
o
);
if (te.call(r, "key")) {
o = u(e);
var g = Object.keys(r).filter(function(E) {
return E !== "key";
});
n = 0 < g.length ? "{key: someKey, " + g.join(": ..., ") + ": ...}" : "{key: someKey}", de[o + n] || (g = 0 < g.length ? "{" + g.join(": ..., ") + ": ...}" : "{}", console.error(
`A props object containing a "key" prop is being spread into JSX:
let props = %s;
<%s {...props} />
React keys must be passed directly to JSX without using spread:
let props = %s;
<%s key={someKey} {...props} />`,
n,
o,
g,
o
), de[o + n] = !0);
}
if (o = null, t !== void 0 && (d(t), o = "" + t), U(r) && (d(r.key), o = "" + r.key), "key" in r) {
t = {};
for (var w in r)
w !== "key" && (t[w] = r[w]);
} else t = r;
return o && I(
t,
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
), A(e, o, a, i, S(), t);
}
function M(e, r) {
if (typeof e == "object" && e && e.$$typeof !== we) {
if (L(e))
for (var t = 0; t < e.length; t++) {
var n = e[t];
f(n) && j(n, r);
}
else if (f(e))
e._store && (e._store.validated = 1);
else if (e === null || typeof e != "object" ? t = null : (t = re && e[re] || e["@@iterator"], t = typeof t == "function" ? t : null), typeof t == "function" && t !== e.entries && (t = t.call(e), t !== e))
for (; !(e = t.next()).done; )
f(e.value) && j(e.value, r);
}
}
function f(e) {
return typeof e == "object" && e !== null && e.$$typeof === V;
}
function j(e, r) {
if (e._store && !e._store.validated && e.key == null && (e._store.validated = 1, r = he(r), !ve[r])) {
ve[r] = !0;
var t = "";
e && e._owner != null && e._owner !== S() && (t = null, typeof e._owner.tag == "number" ? t = u(e._owner.type) : typeof e._owner.name == "string" && (t = e._owner.name), t = " It was passed a child from " + t + ".");
var n = x.getCurrentStack;
x.getCurrentStack = function() {
var i = b(e.type);
return n && (i += n() || ""), i;
}, console.error(
'Each child in a list should have a unique "key" prop.%s%s See https://react.dev/link/warning-keys for more information.',
r,
t
), x.getCurrentStack = n;
}
}
function he(e) {
var r = "", t = S();
return t && (t = u(t.type)) && (r = `
Check the render method of \`` + t + "`."), r || (e = u(e)) && (r = `
Check the top-level render call using <` + e + ">."), r;
}
var xe = Se, V = Symbol.for("react.transitional.element"), pe = Symbol.for("react.portal"), G = Symbol.for("react.fragment"), K = Symbol.for("react.strict_mode"), Q = Symbol.for("react.profiler"), D = Symbol.for("react.consumer"), ee = Symbol.for("react.context"), q = Symbol.for("react.forward_ref"), z = Symbol.for("react.suspense"), F = Symbol.for("react.suspense_list"), J = Symbol.for("react.memo"), H = Symbol.for("react.lazy"), Re = Symbol.for("react.offscreen"), re = Symbol.iterator, ye = Symbol.for("react.client.reference"), x = xe.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, te = Object.prototype.hasOwnProperty, p = Object.assign, je = Symbol.for("react.client.reference"), L = Array.isArray, k = 0, oe, ne, ae, le, ue, se, ie;
c.__reactDisabledLog = !0;
var X, ce, B = !1, Z = new (typeof WeakMap == "function" ? WeakMap : Map)(), we = Symbol.for("react.client.reference"), fe, Ee = {}, de = {}, ve = {};
P.Fragment = G, P.jsx = function(e, r, t, n, i) {
return C(e, r, t, !1, n, i);
}, P.jsxs = function(e, r, t, n, i) {
return C(e, r, t, !0, n, i);
};
}()), P;
}
var ge;
function Pe() {
return ge || (ge = 1, process.env.NODE_ENV === "production" ? W.exports = Oe() : W.exports = Ne()), W.exports;
}
var Y = Pe();
function Ve({ children: u }) {
const [v, d] = Te({ width: 0, height: 0 }), c = _e(null);
return Ae(() => {
if (!c.current) return;
const { width: s, height: l } = c.current.getBoundingClientRect();
d({ width: s, height: l });
}, []), /* @__PURE__ */ Y.jsx("div", { ref: c, style: { width: "100%", height: "100%" }, children: u(v) });
}
function Ye({ index: u, offset: v, rowHeight: d, children: c }) {
return /* @__PURE__ */ Y.jsx(
"div",
{
style: {
position: "absolute",
width: "100%",
height: d,
top: v
},
children: c ? c(u) : null
}
);
}
const Me = "react-virtual-list-fixed-height-item", Ge = Ce(function({
className: u = "",
style: v = {},
total: d = 0,
viewHeight: c = $e,
padding: s = Ue,
rowHeight: l = We,
children: m
}, _) {
const b = _e(null), [S, U] = Te(0), I = Math.max(d * l, c);
let y = Math.floor(S / l), A = Math.ceil(c / l) + y;
y = Math.max(y - s, 0), A = Math.min(A + s, d - 1);
const C = [];
for (let f = y; f < A; f++)
C.push(/* @__PURE__ */ Y.jsx(Ye, { index: f, offset: f * l, rowHeight: l, children: m }, `${Me}-${f}`));
const M = (f) => {
const j = f.currentTarget.scrollTop;
requestAnimationFrame(() => {
U(j);
});
};
return ke(_, () => ({
scrollToViaIndex: (f) => {
const j = f * l;
b.current && b.current.scrollTo({ top: j });
},
scrollToViaScrollTop: (f) => {
b.current && b.current.scrollTo({ top: f });
}
})), /* @__PURE__ */ Y.jsx("div", { ref: b, className: `virtual-list-viewer ${u}`, style: { ...v, height: c, overflowY: "auto" }, onScroll: M, children: /* @__PURE__ */ Y.jsx("div", { className: "virtual-list-container", style: { position: "relative", height: I }, children: C }) });
}), $e = 300, We = 40, Ue = 3;
export {
Ve as AutoSizer,
Ue as DEFAULT_PADDING,
We as DEFAULT_ROW_HEIGHT,
$e as DEFAULT_VIEW_HEIGHT,
Ge as FixedHeightVirtualList
};