hightable
Version:
A dynamic windowed scrolling table component for react
1,546 lines (1,545 loc) • 53.3 kB
JavaScript
import { jsx as m, jsxs as J, Fragment as $e } from "react/jsx-runtime";
import { createContext as X, useState as k, useEffect as Y, useMemo as S, useContext as I, useCallback as w, useRef as ie, useId as Ke } from "react";
import { arrayDataFrame as Qe, serializeOrderBy as Ne, checkSignal as Ye, toggleColumnExclusive as Ze, toggleColumn as et, stringify as tt } from "./dataframe.js";
import { createEventTarget as bn, createGetRowNumber as mn, sortableDataFrame as yn, validateColumn as Cn, validateFetchParams as xn, validateGetCellParams as Rn, validateGetRowNumberParams as Sn, validateOrderBy as En, validateRow as Pn } from "./dataframe.js";
import { createPortal as nt, flushSync as rt } from "react-dom";
const ot = {
onError: console.error
}, ue = X(ot);
function it() {
return {
data: Qe([]),
key: 0,
version: 0,
maxRowNumber: 0,
numRows: 0
};
}
const te = X(it());
function st({ children: t, data: e, maxRowNumber: n }) {
const [s, l] = k(0), [r, o] = k(e), [a, u] = k(0), [f, d] = k(e.numRows);
Y(() => {
function h() {
u((p) => p + 1);
}
function i() {
d(e.numRows);
}
return e.eventTarget?.addEventListener("numrowschange", i), e.eventTarget?.addEventListener("resolve", h), e.eventTarget?.addEventListener("update", h), () => {
e.eventTarget?.removeEventListener("numrowschange", i), e.eventTarget?.removeEventListener("resolve", h), e.eventTarget?.removeEventListener("update", h);
};
}, [e]), e !== r && (l((h) => h + 1), o(e), u(0), d(e.numRows));
const g = S(() => n ?? f, [n, f]);
return /* @__PURE__ */ m(
te.Provider,
{
value: {
data: e,
key: s,
version: a,
maxRowNumber: g,
numRows: f
},
children: t
}
);
}
const at = {
containerRef: { current: null }
}, Le = X(at), Ce = 33, ct = 20, lt = 20, ut = 20, dt = "2", ft = `:${dt}:column:widths`, ht = "2", vt = `:${ht}:column:visibility`, ee = 2, Ae = 8e6, gt = "_hightable_1u86t_1", pt = "_table-scroll_1u86t_19", wt = "_mock-row-label_1u86t_209", bt = "_styled_1u86t_223", mt = "_top-border_1u86t_318", oe = {
hightable: gt,
tableScroll: pt,
mockRowLabel: wt,
styled: bt,
topBorder: mt
}, be = {
colCount: 1,
colIndex: 1,
rowCount: 1,
rowIndex: 1,
shouldFocus: !1,
setColIndex: () => {
},
setRowIndex: () => {
},
setShouldFocus: () => {
},
focusFirstCell: () => {
}
}, se = X(be), yt = {
numberOfVisibleColumns: 0
}, de = X(yt);
function Ct({ children: t, focus: e = !0 }) {
const [n, s] = k(be.colIndex), [l, r] = k(be.rowIndex), [o, a] = k(!1), [u, f] = k(void 0), { data: d } = I(te), { numRows: g } = I(te), h = g + 1, [i, p] = k(h), { numberOfVisibleColumns: x } = I(de), c = x + 1, [y, b] = k(c);
h !== i && (p(h), l > h && r(h)), c !== y && (b(c), n > c && s(c));
const v = w(() => {
s(1), r(1), a(!0);
}, []);
d !== u && (f(d), e && v());
const E = S(() => ({
colCount: c,
colIndex: n,
rowCount: h,
rowIndex: l,
setColIndex: s,
setRowIndex: r,
shouldFocus: o,
setShouldFocus: a,
focusFirstCell: v
}), [c, n, h, l, o, v]);
return /* @__PURE__ */ m(se.Provider, { value: E, children: t });
}
const xt = [], xe = X(xt);
function Rt({ columnConfiguration: t, columnDescriptors: e, children: n }) {
const s = S(() => {
const l = new Set(e.map((o) => o.name)), r = e.map(({ name: o, sortable: a }, u) => ({
name: o,
index: u,
sortable: a ?? !1,
// Default to false if not specified
...t?.[o] ?? {}
}));
if (t)
for (const o of Object.keys(t))
l.has(o) || console.warn(
`[HighTable] columnConfiguration has unknown key “${o}”. It will be ignored.`
);
return r;
}, [e, t]);
return /* @__PURE__ */ m(xe.Provider, { value: s, children: n });
}
function St({ key: t, parse: e }) {
const n = localStorage.getItem(t);
return n ? (e ?? JSON.parse)(n) : void 0;
}
function Et({ key: t, value: e, stringify: n }) {
t !== void 0 && (e === void 0 ? localStorage.removeItem(t) : localStorage.setItem(t, (n ?? JSON.stringify)(e)));
}
function He({ key: t, parse: e, stringify: n } = {}) {
const [s, l] = k(void 0), [r, o] = k(void 0);
return t !== r && (t !== void 0 && l(St({ key: t, parse: e })), o(t)), Y(() => {
Et({ key: t, value: s, stringify: n });
}, [s, t, n]), [s, l];
}
function Pt({ children: t, localStorageKey: e, columnNames: n, initialVisibilityStates: s, onColumnsVisibilityChange: l }) {
const r = n.length, [o, a] = He({ key: e, parse: f, stringify: u });
function u(b) {
return JSON.stringify(b);
}
function f(b) {
const v = JSON.parse(b);
if (typeof v != "object" || v === null)
return {};
const E = {};
for (const [M, O] of Object.entries(v))
O != null && typeof O == "object" && "hidden" in O && O.hidden === !0 && (E[M] = { hidden: !0 });
return E;
}
const d = S(
() => o ?? s ?? {},
[o, s]
), g = w((b) => d[b]?.hidden === !0, [d]), { numberOfHiddenColumns: h, numberOfVisibleColumns: i } = S(() => {
let b = 0;
for (const v of n)
g(v) && b++;
return { numberOfHiddenColumns: b, numberOfVisibleColumns: r - b };
}, [n, g, r]), p = w((b) => !g(b) && i > 1, [g, i]), x = w((b) => {
if (!(!n.includes(b) || !p(b)))
return () => {
a((v) => {
const E = { ...v ?? s ?? {} };
return E[b] = { hidden: !0 }, l?.(E), E;
});
};
}, [p, n, a, l, s]), c = S(() => {
if (h !== 0)
return () => {
const b = {};
a(b), l?.(b);
};
}, [h, a, l]), y = S(() => ({
getHideColumn: x,
showAllColumns: c,
isHiddenColumn: g,
numberOfVisibleColumns: i
}), [x, c, g, i]);
return /* @__PURE__ */ m(de.Provider, { value: y, children: t });
}
const kt = {}, Re = X(kt);
function Dt(t) {
if (t === void 0)
return {};
const e = `${t}px`;
return { minWidth: e, maxWidth: e };
}
function Mt(t) {
return t.offsetWidth;
}
const At = 50, It = 3, Wt = 150, Ot = 3;
function Ft({ children: t, localStorageKey: e, numColumns: n, minWidth: s, viewportWidth: l, tableCornerWidth: r }) {
if (!Number.isInteger(n) || n < 0)
throw new Error(`Invalid numColumns: ${n}. It must be a positive integer.`);
const o = w((C) => C !== void 0 && Number.isInteger(C) && C >= 0 && C < n, [n]);
if (s ??= At, !re(s))
throw new Error(`Invalid minWidth: ${s}. It must be a positive number.`);
const a = I(xe), u = S(() => a.map((C) => C.minWidth), [a]), f = w((C) => (o(C) ? u[C] : void 0) ?? s, [o, u, s]), d = w((C) => {
if (!C)
return C;
function $(N, U) {
return N !== void 0 && (!re(N) || N < f(U));
}
return C.some((N, U) => $(N, U)) ? C.map((N, U) => {
if (!$(N, U))
return N;
}) : C;
}, [f]), g = S(() => {
if (r === void 0 || l === void 0)
return;
const C = l - r;
if (re(C))
return C;
}, [l, r]), [h, i] = He({ key: e, parse: p, stringify: JSON.stringify });
function p(C) {
const $ = JSON.parse(C);
return Array.isArray($) ? $.map((K) => typeof K == "number" ? K : void 0) : [];
}
const x = ie(h), c = w((C) => {
i(($) => {
const K = C($);
return x.current = K ?? [], K;
});
}, [i]), y = w((C, $) => {
if (!re($) || !o(C))
return;
const K = Math.max($, f(C));
c((N) => {
const U = [...N ?? []];
return U[C] = K, U;
});
}, [o, f, c]), b = w(() => {
c((C) => d(C));
}, [c, d]), v = w((C) => {
if (o(C) && h?.[C] !== void 0)
return !0;
}, [h, o]), [E, M] = k(), O = w((C, $) => {
if (!re($) || !o(C))
return;
const K = Math.max($ + 1, f(C));
M((N) => {
const U = [...N ?? []];
return U[C] = K, U;
});
}, [o, f, M]), F = w(() => {
M((C) => d(C));
}, [M, d]), P = w((C) => {
o(C) && (c(($) => {
const K = [...$ ?? []];
return K[C] = void 0, K;
}), M(($) => {
const K = [...$ ?? []];
return K[C] = void 0, K;
}));
}, [o, c, M]), [D, R] = k();
Y(() => {
b(), F(), R(Tt({ fixedWidths: x.current, measuredWidths: E, maxTotalWidth: g, numColumns: n, getMinWidth: f }));
}, [n, E, g, f, b, F]);
const W = w((C) => {
if (o(C))
return h?.[C] ?? D?.[C] ?? E?.[C];
}, [o, h, E, D]), A = w((C) => Dt(W(C)), [W]), B = S(() => ({
getWidth: W,
getStyle: A,
getDataFixedWidth: v,
releaseWidth: P,
setFixedWidth: y,
setMeasuredWidth: O
}), [W, A, v, P, y, O]);
return /* @__PURE__ */ m(Re.Provider, { value: B, children: t });
}
function Tt({
fixedWidths: t,
measuredWidths: e,
maxTotalWidth: n,
getMinWidth: s,
numColumns: l
}) {
if (n === void 0)
return [];
if (!e || e.every((g) => g === void 0))
return [];
const r = new Array(l).fill(void 0);
let o = 0;
for (const g of r.keys()) {
const h = t?.[g] ?? e[g] ?? s(g);
o += h;
}
let a = o - Math.max(0, n - Ot);
if (a <= 0)
return [];
const u = /* @__PURE__ */ new Map();
for (const [g, h] of e.entries())
if (h !== void 0) {
const i = Math.max(
s(g),
Math.floor(h / It),
Wt
);
if (h < i)
continue;
const p = u.get(h);
p ? p.push({ index: g, minWidth: i }) : u.set(h, [{ index: g, minWidth: i }]);
}
const f = [...u.entries()].map(
([g, h]) => ({ width: g, columns: h })
).sort((g, h) => g.width - h.width);
let d = 0;
for (; f.length > 0 && d < 100 && a > 0; ) {
d++;
const g = f.pop();
if (g === void 0)
break;
const { width: h, columns: i } = g;
if (i.length === 0)
throw new Error(`Incoherent width group with no columns: ${h}`);
const p = f.pop(), x = Math.max(...i.map((v) => v.minWidth)), c = p === void 0 ? x : Math.max(x, p.width), y = Math.ceil(h - a / i.length);
if (y >= c) {
for (const v of i)
r[v.index] = y;
a -= (h - y) * i.length;
break;
}
for (const v of i)
r[v.index] = c;
a -= (h - c) * i.length;
const b = i.filter((v) => v.minWidth < c);
p?.width === c ? f.push({ width: c, columns: [...p.columns, ...b] }) : (p !== void 0 && f.push(p), b.length > 0 && f.push({ width: c, columns: b }));
}
if (a < 0 && a > -10) {
const g = r.map((i, p) => {
const x = t?.[p], c = e[p];
return {
index: p,
fixed: x !== void 0,
width: i ?? c
};
}).filter(
// tell typescript that width is defined
(i) => !i.fixed && i.width !== void 0
), h = g.length;
if (h > 0) {
const i = Math.floor(-a / h), p = -a % h;
for (const { index: x, width: c } of g.slice(0, p))
r[x] = c + i + 1;
for (const { index: x, width: c } of g.slice(p))
r[x] = c + i;
}
}
return r;
}
function re(t) {
return typeof t == "number" && Number.isFinite(t) && !isNaN(t) && t >= 0;
}
const Vt = {}, fe = X(Vt);
function _e({ value: t, onChange: e, defaultValue: n, disabled: s }) {
const [l] = k(t), [r] = k(t !== void 0), [o] = k(s ?? !1), [a, u] = k(n), f = w((d) => {
e?.(d), u(d);
}, [e]);
return o ? {} : r ? (t === void 0 && console.warn("The value is controlled (it has no local state) because the property was initially defined. It cannot be set to undefined now (it is set back to the initial value)."), {
value: t ?? l,
// read-only if onChange is undefined
onChange: e
}) : (t !== void 0 && console.warn("The value is uncontrolled (it only has a local state) because the property was initially undefined. It cannot be set to a value now and is ignored."), { value: a, onChange: f });
}
function $t({ children: t, orderBy: e, onOrderByChange: n }) {
const s = _e({
value: e,
onChange: n,
defaultValue: []
});
return /* @__PURE__ */ m(
fe.Provider,
{
value: {
orderBy: s.value,
onOrderByChange: s.onChange
},
children: t
}
);
}
const Kt = {}, Se = X(Kt);
function Nt({ padding: t = ct, overscan: e = lt, children: n }) {
const [s, l] = k(void 0), r = w((v) => {
l((E) => E?.start === v?.start && E?.end === v?.end ? E : v);
}, []), { onError: o } = I(ue), { data: a, numRows: u } = I(te), { orderBy: f } = I(fe), d = I(xe), { isHiddenColumn: g } = I(de), h = S(() => d.filter((v) => !g?.(v.name)), [d, g]), i = S(() => {
if (s)
return {
start: Math.max(0, s.start - e),
end: Math.min(u, s.end + e)
};
}, [s, u, e]), p = S(() => {
if (i)
return {
start: Math.max(0, i.start - t),
end: Math.min(u, i.end + t)
};
}, [i, u, t]), x = S(() => ({
orderBy: f,
columnsParameters: h,
fetchedRowsRange: i,
abortController: new AbortController()
}), [f, h, i]), [c, y] = k(x);
(c.orderBy !== f || c.fetchedRowsRange !== i || c.columnsParameters !== h) && (c.abortController.abort(), y(x), a.fetch !== void 0 && i !== void 0 && a.fetch({
rowStart: i.start,
rowEnd: i.end,
columns: h.map(({ name: v }) => v),
orderBy: f,
signal: x.abortController.signal
}).catch((v) => {
v instanceof DOMException && v.name === "AbortError" || o?.(v);
}));
const b = S(() => ({
columnsParameters: h,
visibleRowsRange: s,
renderedRowsRange: p,
fetchedRowsRange: i,
setVisibleRowsRange: r
}), [h, i, r, p, s]);
return /* @__PURE__ */ m(Se.Provider, { value: b, children: n });
}
const Lt = {}, ae = X(Lt);
function Ht({ children: t, canvasHeight: e, numRows: n }) {
const [s, l] = k(void 0), { fetchedRowsRange: r, renderedRowsRange: o, setVisibleRowsRange: a } = I(Se);
if (e <= 0)
throw new Error(`invalid canvasHeight ${e}`);
const u = w(({ clientHeight: i, scrollTop: p }) => {
const x = i === 0 ? 100 : i, c = Math.max(0, Math.floor(n * p / e)), y = Math.min(n, Math.ceil(n * (p + x) / e));
if (isNaN(c)) throw new Error(`invalid start row ${c}`);
if (isNaN(y)) throw new Error(`invalid end row ${y}`);
if (y - c > 1e3) throw new Error(`attempted to render too many rows ${y - c}`);
a?.({ start: c, end: y });
}, [n, e, a]), f = w((i) => i * Ce, []), d = w(({ rowIndex: i }) => {
if (s === void 0 || r === void 0)
return;
if (i < 1)
throw new Error(`invalid rowIndex ${i}`);
if (i === 1)
return;
const p = i - ee;
(p < r.start || p >= r.end) && s(f(p));
}, [r, s, f]), g = S(() => f(o?.start ?? 0), [o, f]), h = S(() => ({
scrollMode: "native",
canvasHeight: e,
sliceTop: g,
onViewportChange: u,
scrollRowIntoView: d,
setScrollToTop: l
}), [e, g, u, d]);
return /* @__PURE__ */ m(ae.Provider, { value: h, children: t });
}
function _t({ children: t, canvasHeight: e }) {
const { onError: n } = I(ue);
Y(() => {
n?.(new Error("Virtual scroll mode is not implemented yet."));
}, [n]);
const s = S(() => ({
scrollMode: "virtual",
canvasHeight: e
// TODO(SL): provide the rest of the context
}), [e]);
return /* @__PURE__ */ m(ae.Provider, { value: s, children: t });
}
function zt({ children: t, headerHeight: e, numRows: n }) {
const s = S(() => e + n * Ce, [n, e]);
return s < Ae ? /* @__PURE__ */ m(Ht, { canvasHeight: s, numRows: n, children: t }) : /* @__PURE__ */ m(_t, { canvasHeight: Ae, children: t });
}
const Ut = {}, ze = X(Ut);
function Ie() {
return { ranges: [], anchor: void 0 };
}
function le(t) {
return Number.isInteger(t) && t >= 0;
}
function Ee(t) {
return le(t.start) && le(t.end) && t.end > t.start;
}
function Pe(t) {
if (t.length === 0)
return !0;
if (t.some((e) => !Ee(e)))
return !1;
for (let e = 0; e < t.length - 1; e++) {
const n = t[e], s = t[e + 1];
if (!n || !s || n.end >= s.start)
return !1;
}
return !0;
}
function he({ ranges: t, index: e }) {
if (!le(e))
throw new Error("Invalid index");
if (!Pe(t))
throw new Error("Invalid ranges");
return t.some((n) => n.start <= e && e < n.end);
}
function Ue({ ranges: t, range: e }) {
if (!Pe(t))
throw new Error("Invalid ranges");
if (!Ee(e))
throw new Error("Invalid range");
const n = [], { start: s, end: l } = e;
let r = 0;
for (; r < t.length; ) {
const o = t[r];
if (!o)
throw new Error("Invalid range");
if (o.end >= s)
break;
n.push({ ...o }), r++;
}
for (; r < t.length; ) {
const o = t[r];
if (!o)
throw new Error("Invalid range");
if (o.start > l)
break;
e.start = Math.min(e.start, o.start), e.end = Math.max(e.end, o.end), r++;
}
for (n.push(e); r < t.length; ) {
const o = t[r];
if (!o)
throw new Error("Invalid range");
n.push({ ...o }), r++;
}
return n;
}
function je({ ranges: t, index: e }) {
return Ue({ ranges: t, range: { start: e, end: e + 1 } });
}
function Be({ ranges: t, index: e }) {
return Ge({ ranges: t, range: { start: e, end: e + 1 } });
}
function Ge({ ranges: t, range: e }) {
if (!Pe(t))
throw new Error("Invalid ranges");
if (!Ee(e))
throw new Error("Invalid range");
const n = [], { start: s, end: l } = e;
let r = 0;
for (; r < t.length; ) {
const o = t[r];
if (!o)
throw new Error("Invalid range");
if (o.end >= s)
break;
n.push({ ...o }), r++;
}
for (; r < t.length; ) {
const o = t[r];
if (!o)
throw new Error("Invalid range");
if (o.start >= l)
break;
o.start < s && n.push({ start: o.start, end: s }), o.end > l && n.push({ start: l, end: o.end }), r++;
}
for (; r < t.length; ) {
const o = t[r];
if (!o)
throw new Error("Invalid range");
n.push({ ...o }), r++;
}
return n;
}
function Je({ ranges: t, index: e }) {
if (!le(e))
throw new Error("Invalid index");
const n = { start: e, end: e + 1 };
return he({ ranges: t, index: e }) ? Ge({ ranges: t, range: n }) : Ue({ ranges: t, range: n });
}
function me({ selection: t, index: e }) {
return { ranges: Je({ ranges: t.ranges, index: e }), anchor: e };
}
function jt({ selection: t }) {
return t.ranges.reduce((e, n) => e + (n.end - n.start), 0);
}
function Bt({ children: t, data: e, numRows: n, selection: s, onSelectionChange: l }) {
const [r, o] = k(n), { value: a, onChange: u } = _e({
value: s,
onChange: l,
defaultValue: Ie(),
disabled: s === void 0 && l === void 0
}), [f] = k(() => /* @__PURE__ */ new Map()), [d, g] = k(ye({ numRows: n, selection: a })), { orderBy: h } = I(fe), { onError: i } = I(ue);
n !== r && (o(n), g(ye({ numRows: n, selection: a })), f.clear());
const [p, x] = k(void 0), c = w(({ gesture: P }) => {
P.controller.abort(), x((D) => {
if (D !== P)
return D;
});
}, [x]), y = w(() => {
const P = { controller: new AbortController() };
return x((D) => (D && D.controller.abort(), P)), P;
}, []), b = S(() => a !== void 0, [a]), v = S(() => {
if (a)
return ({ rowNumber: P }) => {
if (P !== void 0)
return he({ ranges: a.ranges, index: P });
};
}, [a]), E = S(() => {
if (!(!a || !u))
return ({ rowNumber: P }) => {
const D = y();
try {
u(me({ selection: a, index: P }));
} finally {
c({ gesture: D });
}
};
}, [u, a, y, c]), M = S(() => {
if (!(!a || !u))
return ({ row: P, rowNumber: D }) => {
const R = y(), { signal: W } = R.controller;
Jt({ data: e, numRows: n, row: P, rowNumber: D, selection: a, orderBy: h, signal: W, rowByRowNumberAndOrderBy: f }).finally(() => {
c({ gesture: R });
}).then((A) => {
u(A);
}).catch((A) => {
A instanceof Error && A.name === "AbortError" || i?.(A);
});
};
}, [u, a, f, e, n, h, y, c, i]), O = S(() => {
if (!(!a || !u))
return () => {
const P = y(), { signal: D } = P.controller;
We({ data: e, numRows: n, selection: a, signal: D }).finally(() => {
c({ gesture: P });
}).then((R) => {
u(R);
}).catch((R) => {
R instanceof Error && R.name === "AbortError" || i?.(R);
});
};
}, [u, e, n, a, y, c, i]), F = w((P) => {
const { key: D, shiftKey: R } = P;
if (D === "Escape") {
const W = y();
try {
u?.(Ie());
} finally {
c({ gesture: W });
}
} else if (D === "a" && (P.ctrlKey || P.metaKey)) {
const W = y(), { signal: A } = W.controller;
P.preventDefault(), a && u && We({ data: e, numRows: n, selection: a, signal: A }).finally(() => {
c({ gesture: W });
}).then((B) => {
u(B);
}).catch((B) => {
B instanceof Error && B.name === "AbortError" || i?.(B);
});
} else if (D === " " && R) {
const { target: W } = P;
if (!a || !u || !(W instanceof HTMLTableCellElement))
return;
const A = Number(W.getAttribute("data-rownumber"));
if (!(W.getAttribute("role") === "cell") || isNaN(A) || !Number.isInteger(A) || A < 0 || A >= n)
return;
P.preventDefault();
const C = y();
try {
u({ ranges: Je({ ranges: a.ranges, index: A }), anchor: A });
} finally {
c({ gesture: C });
}
}
}, [a, u, y, c, e, n, i]);
return Y(() => {
if (!a) return;
const P = y(), { signal: D } = P.controller;
Xe({ data: e, numRows: n, selection: a, signal: D }).finally(() => {
c({ gesture: P });
}).then((R) => {
g(R);
}).catch((R) => {
R instanceof Error && R.name === "AbortError" || i?.(R);
});
}, [a, e, n, y, c, i]), /* @__PURE__ */ m(
ze.Provider,
{
value: {
selectable: b,
pendingSelectionGesture: p !== void 0,
isRowSelected: v,
toggleRowNumber: E,
toggleRangeToRowNumber: M,
onTableKeyDown: F,
toggleAllRows: O,
allRowsSelected: d
},
children: t
}
);
}
async function ke({ data: t, rowStart: e, rowEnd: n, orderBy: s, signal: l }) {
return await t.fetch?.({ rowStart: e, rowEnd: n, orderBy: s, signal: l }), Array.from({ length: n - e }, (o, a) => {
const u = a + e, f = t.getRowNumber({ row: u, orderBy: s })?.value;
if (f === void 0)
throw new Error(`Row number is undefined for row ${u} with orderBy ${JSON.stringify(s ?? [])}`);
return f;
});
}
async function Gt({ data: t, numRows: e, rowNumber: n, orderBy: s, signal: l, rowByRowNumberAndOrderBy: r }) {
Ye(l);
const o = Ne(s ?? []), a = r?.get(o);
if (a)
return a.get(n);
const u = /* @__PURE__ */ new Map();
await t.fetch?.({ rowStart: 0, rowEnd: e, orderBy: s, signal: l });
for (let f = 0; f < e; f++) {
const d = t.getRowNumber({ row: f, orderBy: s })?.value;
if (d === void 0)
throw new Error(`Row number is undefined for row ${f} with orderBy ${o}`);
u.set(d, f);
}
return r?.set(o, u), u.get(n);
}
async function Jt({ data: t, numRows: e, row: n, rowNumber: s, selection: l, orderBy: r, signal: o, rowByRowNumberAndOrderBy: a }) {
const { anchor: u } = l;
if (u === void 0 || u === s)
return me({ selection: l, index: s });
const f = await Gt({ data: t, numRows: e, rowNumber: u, orderBy: r, signal: o, rowByRowNumberAndOrderBy: a });
if (f === void 0 || f === n)
return me({ selection: l, index: s });
const [d, g] = f < n ? [f + 1, n + 1] : [n, f], h = await ke({ data: t, rowStart: d, rowEnd: g, orderBy: r, signal: o });
let { ranges: i } = l;
const p = t.getRowNumber({ row: n, orderBy: r })?.value;
if (p === void 0)
throw new Error(`Row number for row ${n} not found in orderBy ${Ne(r ?? [])}`);
const x = he({ ranges: i, index: u });
for (const c of h)
i = x ? je({ ranges: i, index: c }) : Be({ ranges: i, index: c });
return { ranges: i, anchor: p };
}
async function We({ data: t, numRows: e, selection: n, signal: s }) {
const l = await Xe({ data: t, numRows: e, selection: n, signal: s }), r = await ke({ data: t, rowStart: 0, rowEnd: e, signal: s });
let { ranges: o } = n;
for (const a of r)
o = l ? Be({ ranges: o, index: a }) : je({ ranges: o, index: a });
return { ranges: o };
}
function ye({ numRows: t, selection: e }) {
if (!e || t === 0 || jt({ selection: e }) < t)
return !1;
}
async function Xe({ data: t, numRows: e, selection: n, signal: s }) {
const l = ye({ numRows: e, selection: n });
if (l !== void 0)
return l;
const r = await ke({ data: t, rowStart: 0, rowEnd: e, signal: s });
return r.length > 0 && r.every((o) => he({ ranges: n.ranges, index: o }));
}
function Xt({
children: t,
setViewportWidth: e
}) {
const { setShouldFocus: n, rowIndex: s } = I(se), { canvasHeight: l, sliceTop: r, onViewportChange: o, scrollRowIntoView: a, setScrollToTop: u } = I(ae), f = w((i) => {
if (i.target !== i.currentTarget)
return;
const { key: p } = i;
(p === "Tab" && !i.shiftKey || p === "Enter" || p === " ") && (i.stopPropagation(), i.preventDefault(), a?.({ rowIndex: s }), n(!0));
}, [s, n, a]), d = w((i) => {
const p = () => {
e(i.clientWidth), o?.(i);
}, x = () => {
o?.(i);
};
p(), x(), "scrollTo" in i ? u?.(() => (y) => {
i.scrollTo({ top: y });
}) : u?.(void 0);
const c = "ResizeObserver" in window ? new window.ResizeObserver(([y]) => {
if (!y) {
console.warn("ResizeObserver entry is not available.");
return;
}
p();
}) : void 0;
return c?.observe(i), i.addEventListener("scroll", x), () => {
c?.unobserve(i), c?.disconnect(), i.removeEventListener("scroll", x);
};
}, [u, e, o]), g = S(() => l !== void 0 ? { height: `${l}px` } : {}, [l]), h = S(() => r !== void 0 ? { top: `${r}px` } : {}, [r]);
return /* @__PURE__ */ m("div", { className: oe.tableScroll, ref: d, role: "group", "aria-labelledby": "caption", onKeyDown: f, tabIndex: 0, children: /* @__PURE__ */ m("div", { style: g, children: /* @__PURE__ */ m("div", { style: h, children: t }) }) });
}
function ve({ ariaColIndex: t, ariaRowIndex: e }) {
const { colIndex: n, rowIndex: s, setColIndex: l, setRowIndex: r, shouldFocus: o, setShouldFocus: a } = I(se), { scrollMode: u } = I(ae), f = t === n && e === s, d = e === 1 || t === 1, g = w((p) => {
p && (u === "virtual" || f && o && (d || p.scrollIntoView({ behavior: "auto", block: "nearest", inline: "nearest" }), p.focus(), a(!1)));
}, [f, d, o, a, u]), h = f ? 0 : -1, i = w(() => {
l(t), r(e), a(!0);
}, [l, r, a, t, e]);
return {
tabIndex: h,
focusCellIfNeeded: g,
navigateToCell: i
};
}
function De(t) {
return w((e) => {
t === void 0 || !document.getSelection()?.isCollapsed || (e.preventDefault(), navigator.clipboard.writeText(t).catch((n) => {
console.debug("Failed to write to clipboard: ", n);
}));
}, [t]);
}
function qt({ cell: t, onDoubleClickCell: e, onMouseDownCell: n, onKeyDownCell: s, stringify: l, columnIndex: r, visibleColumnIndex: o, className: a, ariaColIndex: u, ariaRowIndex: f, rowNumber: d, renderCellContent: g }) {
const { tabIndex: h, navigateToCell: i, focusCellIfNeeded: p } = ve({ ariaColIndex: u, ariaRowIndex: f }), x = I(Re).getStyle?.(o), c = S(() => l(t?.value), [l, t]), y = S(() => {
if (c !== void 0) {
if (c.length > 400)
return `${c.slice(0, 397)}…`;
if (c.length > 100)
return c;
}
}, [c]), b = S(() => g?.({ cell: t, stringify: l, col: r, row: d }) ?? c, [t, l, r, d, g, c]), v = w((F) => {
i(), n && d !== void 0 && n(F, r, d);
}, [i, n, d, r]), E = w((F) => {
i(), e && d !== void 0 && e(F, r, d);
}, [i, e, d, r]), M = w((F) => {
s && d !== void 0 && s(F, r, d);
}, [s, d, r]), O = De(c);
return /* @__PURE__ */ m(
"td",
{
ref: p,
role: "cell",
"aria-busy": t === void 0,
"aria-rowindex": f,
"aria-colindex": u,
"data-rownumber": d,
tabIndex: h,
onCopy: O,
onDoubleClick: E,
onMouseDown: v,
onKeyDown: M,
style: x,
className: a,
title: y,
children: b
}
);
}
function ce({
children: t,
ariaRowIndex: e,
selected: n,
rowNumber: s,
title: l
}) {
return /* @__PURE__ */ m(
"tr",
{
role: "row",
"aria-rowindex": e,
title: l,
"aria-selected": n,
"data-rownumber": s,
children: t
}
);
}
function Qt(t) {
return t === void 0 ? "" : (t + 1).toLocaleString("en-US");
}
function pe({ onCheckboxPress: t, pendingSelectionGesture: e, style: n, ariaColIndex: s, ariaRowIndex: l, selected: r, rowNumber: o }) {
const { tabIndex: a, navigateToCell: u, focusCellIfNeeded: f } = ve({ ariaColIndex: s, ariaRowIndex: l }), d = w((c) => {
u(), t?.({ shiftKey: c.shiftKey });
}, [t, u]), g = w((c) => {
(c.key === "Enter" || c.key === " ") && (c.preventDefault(), c.stopPropagation(), t?.({ shiftKey: c.shiftKey }));
}, [t]), h = t === void 0, i = w((c) => {
c.preventDefault();
}, []), p = S(() => Qt(o), [o]), x = De(p);
return /* @__PURE__ */ J(
"th",
{
ref: f,
scope: "row",
role: "rowheader",
style: n,
onClick: d,
onCopy: x,
onKeyDown: g,
"aria-busy": o === void 0,
"aria-checked": r,
"aria-rowindex": l,
"aria-colindex": s,
"aria-disabled": h,
tabIndex: a,
"data-rownumber": o,
children: [
/* @__PURE__ */ m("span", { children: p }),
r !== void 0 && /* @__PURE__ */ m(
"input",
{
type: "checkbox",
onChange: i,
readOnly: h,
disabled: h,
"aria-busy": e,
checked: r,
role: "presentation",
tabIndex: -1
}
)
]
}
);
}
function Yt({ children: t, checked: e, onCheckboxPress: n, pendingSelectionGesture: s, style: l, ariaColIndex: r, ariaRowIndex: o, setTableCornerSize: a }) {
const { tabIndex: u, navigateToCell: f, focusCellIfNeeded: d } = ve({ ariaColIndex: r, ariaRowIndex: o }), g = w(() => {
f(), n?.();
}, [n, f]), h = w((b) => {
(b.key === "Enter" || b.key === " ") && (b.preventDefault(), b.stopPropagation(), n?.());
}, [n]), i = e !== void 0, p = n === void 0, x = w((b) => {
b.preventDefault();
}, []), c = w((b) => {
if (!a || !b || !window.ResizeObserver)
return;
const v = () => {
a({ width: b.offsetWidth, height: b.offsetHeight });
};
v();
const E = new window.ResizeObserver(([M]) => {
if (!M) {
console.warn("ResizeObserver entry is not available.");
return;
}
v();
});
return E.observe(b), () => {
E.unobserve(b), E.disconnect();
};
}, [a]), y = w((b) => (d(b), c(b)), [d, c]);
return /* @__PURE__ */ m(
"td",
{
ref: y,
style: l,
onClick: g,
onKeyDown: h,
"aria-checked": e,
"aria-rowindex": o,
"aria-colindex": r,
"aria-disabled": p,
tabIndex: u,
children: i ? /* @__PURE__ */ m(
"input",
{
type: "checkbox",
onChange: x,
readOnly: p,
disabled: p,
"aria-busy": s,
checked: e,
role: "presentation",
tabIndex: -1
}
) : /* @__PURE__ */ m("span", { children: t })
}
);
}
function Zt(t, e) {
const [n, s] = k({ left: 0, top: 0 }), [l, r] = k(!1), o = Ke(), a = w(() => {
r(!1);
}, []), u = w(
(f) => {
f.stopPropagation();
const d = t.current?.getBoundingClientRect(), g = f.currentTarget.getBoundingClientRect();
s({
left: g.left,
top: d?.bottom ?? 0
}), e(), r((h) => !h);
},
[t, e]
);
return {
isOpen: l,
position: n,
menuId: o,
close: a,
handleMenuClick: u
};
}
const en = 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';
function tn(t, e) {
const n = ie(null), s = w(() => [...e.current?.querySelectorAll(en) ?? []].filter((r) => r instanceof HTMLElement), [e]);
Y(() => {
if (t) {
const { activeElement: r } = document;
r instanceof HTMLElement && (n.current = document.activeElement);
const o = s().at(0);
o && requestAnimationFrame(() => {
o.focus();
});
} else n.current && (n.current.focus(), n.current = null);
}, [t, s]);
const l = w((r) => {
const o = s();
if (!o.length)
return;
const { activeElement: a } = document;
if (!a || !(a instanceof HTMLElement))
return;
const u = Array.from(o).indexOf(a);
let f;
switch (r) {
case "first":
f = 0;
break;
case "last":
f = o.length - 1;
break;
case "next":
f = u >= o.length - 1 ? 0 : u + 1;
break;
case "previous":
f = u <= 0 ? o.length - 1 : u - 1;
break;
}
o[f]?.focus();
}, [s]);
return { getFocusableElements: s, navigateFocus: l };
}
function nn(t) {
switch (t) {
case "ascending":
return "Ascending";
case "descending":
return "Descending";
default:
return "No sort";
}
}
function Oe({ title: t, children: e }) {
return /* @__PURE__ */ J($e, { children: [
/* @__PURE__ */ m("div", { role: "separator", children: t }),
e
] });
}
function we({ onClick: t, label: e }) {
const n = w((l) => {
l.preventDefault(), l.stopPropagation(), t?.();
}, [t]), s = w((l) => {
(l.key === "Enter" || l.key === " ") && (l.stopPropagation(), l.preventDefault(), t?.());
}, [t]);
return /* @__PURE__ */ m(
"button",
{
role: "menuitem",
onClick: n,
onKeyDown: s,
tabIndex: 0,
type: "button",
children: e
}
);
}
function rn({ onClick: t }) {
return /* @__PURE__ */ m("div", { role: "presentation", onClick: t });
}
function on({
columnName: t,
isOpen: e,
position: n,
direction: s,
sortable: l,
toggleOrderBy: r,
hideColumn: o,
showAllColumns: a,
close: u,
id: f
}) {
const { containerRef: d } = I(Le), [g, h] = k(void 0);
Y(() => {
g || !d.current || h(d.current);
}, [g, d]);
const { top: i, left: p } = n, x = ie(null), c = Ke(), { navigateFocus: y } = tn(e, x), { focusFirstCell: b } = I(se), v = w((R) => {
switch (R.preventDefault(), R.stopPropagation(), R.key) {
case "Escape":
u();
break;
case "Enter":
case " ":
break;
case "ArrowUp":
case "ArrowLeft":
y("previous");
break;
case "ArrowDown":
case "ArrowRight":
y("next");
break;
case "Home":
y("first");
break;
case "End":
y("last");
break;
case "Tab":
y(R.shiftKey ? "previous" : "next");
break;
}
}, [y, u]), E = w(
(R) => {
R.preventDefault(), R.stopPropagation(), u();
},
[u]
), M = w((R) => {
R.preventDefault(), R.stopPropagation();
}, []), O = S(() => {
if (o)
return () => {
o(), b(), u();
};
}, [o, u, b]), F = S(() => {
if (a)
return () => {
a(), u();
};
}, [a, u]);
if (!e)
return null;
const P = nn(s), D = !(!O && !F);
return g ? nt(
/* @__PURE__ */ J($e, { children: [
/* @__PURE__ */ m(rn, { onClick: E }),
/* @__PURE__ */ J(
"div",
{
id: f,
role: "menu",
style: { top: i, left: p },
ref: x,
tabIndex: -1,
"aria-labelledby": c,
"aria-orientation": "vertical",
onKeyDown: v,
onClick: M,
children: [
/* @__PURE__ */ m("div", { role: "presentation", id: c, "aria-hidden": "true", children: t }),
l && /* @__PURE__ */ m(Oe, { title: "Sort order", children: /* @__PURE__ */ m(
we,
{
onClick: r,
label: P
}
) }),
D && /* @__PURE__ */ J(Oe, { title: "Visibility", children: [
O && /* @__PURE__ */ m(
we,
{
onClick: O,
label: "Hide column"
}
),
F && /* @__PURE__ */ m(
we,
{
onClick: F,
label: "Show all columns"
}
)
] })
]
}
)
] }),
g
) : null;
}
function Fe({
onClick: t,
onEscape: e,
tabIndex: n = 0,
isExpanded: s = !1,
menuId: l,
disabled: r = !1,
"aria-label": o = "Column menu",
icon: a = /* @__PURE__ */ m("span", { "aria-hidden": "true", children: "⋮" })
}) {
const u = w((d) => {
d.key === "Enter" || d.key === " " ? (d.preventDefault(), d.stopPropagation(), t?.(d)) : d.key === "Escape" && (d.preventDefault(), d.stopPropagation(), e?.(d));
}, [t, e]), f = w((d) => {
t?.(d);
}, [t]);
return /* @__PURE__ */ m(
"button",
{
type: "button",
onClick: r ? void 0 : f,
onKeyDown: r ? void 0 : u,
"aria-label": o,
"aria-haspopup": "menu",
"aria-expanded": s,
"aria-controls": l,
disabled: r,
tabIndex: r ? -1 : n,
children: a
}
);
}
const Te = 10, Ve = 100;
function sn({ autoResize: t, resizeTo: e, width: n, tabIndex: s, navigateToCell: l }) {
const [r, o] = k(void 0), [a, u] = k(!1), f = w(() => {
r || t?.(), l?.();
}, [t, l, r]), d = w((v) => {
v.stopPropagation();
}, []), g = w((v) => {
if (v.button !== 0 || v.ctrlKey || v.metaKey || (l?.(), v.stopPropagation(), n === void 0))
return;
const { clientX: E, currentTarget: M, pointerId: O } = v;
o({ clientX: E, pointerId: O, width: n }), "setPointerCapture" in M && M.setPointerCapture(O);
}, [l, n]), h = w((v) => {
v.pointerId === r?.pointerId && e?.(r.width - r.clientX + v.clientX);
}, [e, r]), i = w((v) => {
v.stopPropagation(), o((E) => {
if (v.pointerId !== E?.pointerId)
return E;
});
}, []), p = w(() => {
u(!0);
}, []), x = w(() => {
u(!1);
}, []), c = w((v) => {
if (a && ([" ", "ArrowRight", "ArrowLeft", "ArrowUp", "ArrowDown", "PageUp", "PageDown", "Home", "End"].includes(v.key) && v.preventDefault(), v.stopPropagation(), !r)) {
if (v.key === "Escape") {
u(!1), l?.();
return;
}
if (v.key === "Enter" || v.key === " ") {
f();
return;
}
n !== void 0 && (v.key === "ArrowRight" || v.key === "ArrowUp" ? e?.(n + Te) : v.key === "ArrowLeft" || v.key === "ArrowDown" ? e?.(n - Te) : v.key === "PageUp" ? e?.(n + Ve) : v.key === "PageDown" ? e?.(n - Ve) : v.key === "Home" && e?.(0));
}
}, [f, r, e, n, a, l]), y = r !== void 0 || a, b = S(() => n === void 0 ? "No width set." : `Width set to ${n} pixels.`, [n]);
return /* @__PURE__ */ m(
"span",
{
role: "spinbutton",
"aria-orientation": "vertical",
"aria-busy": y,
"aria-valuemin": 0,
"aria-valuenow": n,
"aria-valuetext": b,
"aria-label": "Resize column",
"aria-description": 'Press "Enter" or "Space" to autoresize the column (press again to unset the width). Press "Escape" to cancel resizing. Press "ArrowRight/ArrowUp" or "ArrowLeft/ArrowDown" to resize the column by 10 pixels. Press PageUp/PageDown to resize the column by 100 pixels.',
onDoubleClick: f,
onPointerDown: g,
onPointerMove: h,
onPointerUp: i,
onClick: d,
onFocus: p,
onBlur: x,
onKeyDown: c,
tabIndex: s
}
);
}
function an({ columnIndex: t, columnName: e, columnConfig: n, canMeasureWidth: s, direction: l, toggleOrderBy: r, orderByIndex: o, orderBySize: a, ariaColIndex: u, ariaRowIndex: f, className: d, children: g }) {
const h = ie(null), { tabIndex: i, navigateToCell: p, focusCellIfNeeded: x } = ve({ ariaColIndex: u, ariaRowIndex: f }), { sortable: c } = n, { isOpen: y, position: b, menuId: v, close: E, handleMenuClick: M } = Zt(h, p), { getHideColumn: O, showAllColumns: F } = I(de), P = w((_) => {
x(_), h.current = _;
}, [x]), D = w(() => {
p(), c && r?.();
}, [r, p, c]), R = S(() => O?.(e), [O, e]), W = S(() => !(!c && !R && !F), [c, R, F]), { getStyle: A, getDataFixedWidth: B, getWidth: C, setMeasuredWidth: $, setFixedWidth: K, releaseWidth: N } = I(Re), U = A?.(t), ge = B?.(t), T = C?.(t), V = w((_) => {
K?.(t, _);
}, [K, t]), L = w(() => {
const _ = h.current;
if (s && _ && T === void 0 && $) {
const ne = Mt(_);
if (isNaN(ne))
return;
$(t, ne);
}
}, [s, $, T, t]);
Y(() => {
L();
}, [L]);
const q = w(() => {
N && (rt(() => {
N(t);
}), L());
}, [L, N, t]), j = S(() => c ? o !== void 0 && o > 0 ? `Press to sort by ${e} in ascending order` : l === "ascending" ? `Press to sort by ${e} in descending order` : l === "descending" ? `Press to stop sorting by ${e}` : `Press to sort by ${e} in ascending order` : `The column ${e} cannot be sorted`, [c, e, l, o]), Z = w((_) => {
_.target !== h.current || !c || (_.key === "Enter" || _.key === " ") && (_.preventDefault(), _.stopPropagation(), r?.());
}, [c, r]), Q = De(e), z = S(
() => /* @__PURE__ */ J("div", { role: "group", children: [
c && /* @__PURE__ */ m("span", { role: "img", "aria-hidden": "true", children: l === "ascending" ? "⭡" : l === "descending" ? "⭣" : "⇅" }),
W && /* @__PURE__ */ m(
Fe,
{
onClick: M,
onEscape: p,
tabIndex: i,
isExpanded: y,
menuId: v,
"aria-label": `Column menu for ${e}`
}
)
] }),
[c, l, W, M, p, i, y, v, e]
), H = S(() => {
const { headerComponent: _ } = n;
return typeof _ == "function" ? _(z) : _ ?? g;
}, [n, z, g]), G = S(() => typeof n.headerComponent == "function", [n]);
return /* @__PURE__ */ J(
"th",
{
ref: P,
scope: "col",
role: "columnheader",
"aria-sort": l ?? (c ? "none" : void 0),
"data-order-by-index": a !== void 0 ? o : void 0,
"data-order-by-size": a,
"data-functional-header": G ? "true" : void 0,
"aria-label": e,
"aria-description": j,
"aria-rowindex": f,
"aria-colindex": u,
tabIndex: i,
title: j,
onClick: D,
onCopy: Q,
onKeyDown: Z,
style: U,
className: d,
"data-fixed-width": ge,
children: [
H,
G ? null : W && /* @__PURE__ */ m(
Fe,
{
onClick: M,
onEscape: p,
tabIndex: i,
isExpanded: y,
menuId: v,
"aria-label": `Column menu for ${e}`
}
),
/* @__PURE__ */ m(
sn,
{
resizeTo: V,
autoResize: q,
width: T,
tabIndex: i,
navigateToCell: p
}
),
/* @__PURE__ */ m(
on,
{
columnName: e,
isOpen: y,
position: b,
direction: l,
sortable: c,
toggleOrderBy: r,
hideColumn: R,
showAllColumns: F,
close: E,
id: v
}
)
]
}
);
}
function cn({
columnsParameters: t,
orderBy: e,
onOrderByChange: n,
canMeasureColumn: s,
ariaRowIndex: l,
exclusiveSort: r
}) {
const o = w(
(u) => {
if (!(!n || !e))
return () => {
const f = r ? Ze(u, e) : et(u, e);
n(f);
};
},
[e, n, r]
), a = S(() => new Map((e ?? []).map(({ column: u, direction: f }, d) => [u, { direction: f, index: d }])), [e]);
return t.map((u, f) => {
const { name: d, index: g, className: h, ...i } = u;
return (
// The ColumnHeader component width is controlled by the parent
/* @__PURE__ */ m(
an,
{
canMeasureWidth: s?.[d] === !0,
direction: a.get(d)?.direction,
orderByIndex: a.get(d)?.index,
orderBySize: e?.length,
toggleOrderBy: o(d),
columnName: d,
columnIndex: g,
className: h,
ariaColIndex: f + ee,
ariaRowIndex: l,
columnConfig: i,
children: d
},
g
)
);
});
}
function ln({
numRowsPerPage: t = ut,
onDoubleClickCell: e,
onKeyDownCell: n,
onMouseDownCell: s,
renderCellContent: l,
setTableCornerSize: r,
stringify: o = tt
}) {
const { data: a, version: u, numRows: f } = I(te), { rowIndex: d, colCount: g, rowCount: h, setColIndex: i, setRowIndex: p, setShouldFocus: x } = I(se), { orderBy: c, onOrderByChange: y } = I(fe), { selectable: b, toggleAllRows: v, pendingSelectionGesture: E, onTableKeyDown: M, allRowsSelected: O, isRowSelected: F, toggleRowNumber: P, toggleRangeToRowNumber: D } = I(ze), { columnsParameters: R, renderedRowsRange: W, fetchedRowsRange: A } = I(Se), { scrollRowIntoView: B } = I(ae), C = w((T, { numRowsPerPage: V }) => {
const { key: L, altKey: q, ctrlKey: j, metaKey: Z, shiftKey: Q } = T;
if (q || Z || Q)
return;
let z;
if (L === "ArrowRight")
i(j ? g : (H) => H < g ? H + 1 : H);
else if (L === "ArrowLeft")
i(j ? 1 : (H) => H > 1 ? H - 1 : H);
else if (L === "ArrowDown")
j ? z = h : z = d < h ? d + 1 : d;
else if (L === "ArrowUp")
j ? z = 1 : z = d > 1 ? d - 1 : d;
else if (L === "Home")
j && (z = 1), i(1);
else if (L === "End")
j && (z = h), i(g);
else if (L === "PageDown")
z = d + V <= h ? d + V : h;
else if (L === "PageUp")
z = d - V >= 1 ? d - V : 1;
else if (L !== " ")
return;
T.stopPropagation(), T.preventDefault(), z !== void 0 && (p(z), B?.({ rowIndex: z })), x(!0);
}, [d, g, h, i, p, x, B]), $ = w((T) => {
C(T, { numRowsPerPage: t }), M?.(T);
}, [C, M, t]), K = w(({ row: T, rowNumber: V }) => {
if (!(V === void 0 || !P || !D))
return ({ shiftKey: L }) => {
L ? D({ row: T, rowNumber: V }) : P({ rowNumber: V });
};
}, [P, D]), N = S(() => {
if (!W || !A)
return {
prePadding: [],
postPadding: [],
rowContents: [],
canMeasureColumn: {},
version: u
};
const T = Math.max(0, A.start - W.start), V = A.end - A.start, L = Math.max(0, W.end - A.end), q = Array.from({ length: T }, (H, G) => ({ row: W.start + G })), j = Array.from({ length: V }, (H, G) => A.start + G), Z = Array.from({ length: L }, (H, G) => ({ row: A.end + G })), Q = {}, z = j.map((H) => {
const G = a.getRowNumber({ row: H, orderBy: c })?.value, _ = (R ?? []).map(({ name: ne, index: qe }) => {
const Me = a.getCell({ row: H, column: ne, orderBy: c });
return Q[ne] ||= Me !== void 0, { columnIndex: qe, cell: Me };
});
return {
row: H,
rowNumber: G,
cells: _
};
});
return {
prePadding: q,
postPadding: Z,
rowContents: z,
canMeasureColumn: Q,
version: u
};
}, [a, R, W, A, c, u]);
if (!R) return;
const U = R.length + 1, ge = f + 1;
return /* @__PURE__ */ J(
"table",
{
"aria-readonly": !0,
"aria-colcount": U,
"aria-rowcount": ge,
"aria-multiselectable": b,
"aria-busy": E,
role: "grid",
onKeyDown: $,
children: [
/* @__PURE__ */ m("caption", { id: "caption", hidden: !0, children: "Virtual-scroll table" }),
/* @__PURE__ */ m("thead", { role: "rowgroup", children: /* @__PURE__ */ J(ce, { ariaRowIndex: 1, children: [
/* @__PURE__ */ m(
Yt,
{
onCheckboxPress: v,
checked: O,
pendingSelectionGesture: E,
ariaColIndex: 1,
ariaRowIndex: 1,
setTableCornerSize: r
}
),
/* @__PURE__ */ m(
cn,
{
canMeasureColumn: N.canMeasureColumn,
columnsParameters: R,
orderBy: c,
onOrderByChange: y,
ariaRowIndex: 1,
exclusiveSort: a.exclusiveSort === !0
}
)
] }) }),
/* @__PURE__ */ J("tbody", { role: "rowgroup", children: [
N.prePadding.map(({ row: T }) => {
const V = T + ee;
return /* @__PURE__ */ m(ce, { ariaRowIndex: V, children: /* @__PURE__ */ m(pe, { ariaColIndex: 1, ariaRowIndex: V }) }, T);
}),
N.rowContents.map(({ row: T, rowNumber: V, cells: L }) => {
const q = T + ee, j = F?.({ rowNumber: V }), Z = `${T}`;
return /* @__PURE__ */ J(
ce,
{
ariaRowIndex: q,
selected: j,
rowNumber: V,
children: [
/* @__PURE__ */ m(
pe,
{
selected: j,
rowNumber: V,
onCheckboxPress: K({ rowNumber: V, row: T }),
pendingSelectionGesture: E,
ariaColIndex: 1,
ariaRowIndex: q
}
),
L.map(({ columnIndex: Q, cell: z }, H) => {
const G = R[H]?.className;
return /* @__PURE__ */ m(
qt,
{
onDoubleClickCell: e,
onMouseDownCell: s,
onKeyDownCell: n,
stringify: o,
columnIndex: Q,
visibleColumnIndex: H,
className: G,
ariaColIndex: H + ee,
ariaRowIndex: q,
cell: z,
rowNumber: V,
renderCellContent: l
},
Q
);