@indielayer/ui
Version:
Indielayer UI Components with Tailwind CSS build for Vue 3
43 lines (42 loc) • 1.18 kB
JavaScript
import { reactive as I, computed as a, toValue as s } from "vue";
import { scanForUnloadedIndices as v } from "./scanForUnloadedIndices.js";
function z(d) {
const e = I(/* @__PURE__ */ new Set()), r = a(
() => s(d).isRowLoaded
), m = a(
() => s(d).loadMoreRows
), w = a(
() => s(d).minimumBatchSize ?? 10
), u = a(
() => s(d).rowCount
), c = a(
() => s(d).threshold ?? 15
), f = (t) => r.value(t) ? (e.has(t) && e.delete(t), !0) : e.has(t);
return {
onRowsRendered: ({ startIndex: t, stopIndex: R }) => {
if (e.size > 0) {
const n = [];
e.forEach((o) => {
r.value(o) && n.push(o);
}), n.forEach((o) => e.delete(o));
}
const l = v({
isRowLoaded: f,
minimumBatchSize: w.value,
rowCount: u.value,
startIndex: Math.max(0, t - c.value),
stopIndex: Math.min(u.value - 1, R + c.value)
});
for (let n = 0; n < l.length; n++) {
const { startIndex: o, stopIndex: h } = l[n];
for (let i = o; i <= h; i++)
e.add(i);
m.value(o, h);
}
},
pendingRowsCache: e
};
}
export {
z as useInfiniteLoader
};