@progress/kendo-vue-grid
Version:
168 lines (167 loc) • 4.83 kB
JavaScript
/**
* @license
*-------------------------------------------------------------------------------------------
* Copyright © 2026 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the package root for more information
*-------------------------------------------------------------------------------------------
*/
function B(f, n, e) {
let a = 0, u = !1;
if (e > 0 && n)
for (let t = 0; t < e; t++) {
const c = n[t] || [];
for (let p = 0; p < c.length; p++) {
const h = c[p], S = f[h];
(S.rowSpan || 1) > e - t && (a += S.headerColSpan || 1, p === 0 && (u = !0));
}
}
return { emptyColSpan: a, skipOffset: u };
}
function M(f, n) {
const e = f[n];
return !e || e.parentIndex < 0 ? [] : [e.parentIndex, ...M(f, e.parentIndex)];
}
function P(f, n, e) {
n.forEach((a) => {
M(f, a).forEach((t) => e.add(t));
});
}
function U(f, n, e) {
var u;
const a = f[n];
((u = a == null ? void 0 : a.children) == null ? void 0 : u.length) > 0 && a.children.forEach((t) => {
let c = typeof t == "number" ? t : f.indexOf(t);
c >= 0 && !e.has(c) && (e.add(c), U(f, c, e));
});
}
function j(f) {
const { cellsToRender: n, columns: e, rowIndex: a, enableVirtualization: u, columnsMap: t } = f;
if (!u || !n || n.length === 0)
return { columnsToRender: [], colSpans: [] };
const c = [], p = [];
let h = -1, S = -1;
function g(o, r) {
let s = -1, i = -1;
for (let d = 0; d < r.length; d++)
o[r[d]].locked || (s === -1 && (s = d), i = d);
return { first: s, last: i };
}
const O = n.reduce((o, r) => o + r.colSpan, 0);
let w = 0;
for (const o of n) {
const r = e[o.columnIndex];
if (r != null && r.locked)
w += o.colSpan;
else
break;
}
const l = O - w;
let T = [], m = [];
const L = e.filter((o) => o.children.length === 0), V = /* @__PURE__ */ new Map();
e.forEach((o, r) => {
if (o.children.length === 0) {
const s = L.findIndex((i) => i === o);
s >= 0 && V.set(s, r);
}
});
const C = /* @__PURE__ */ new Set();
if (n.forEach((o) => {
const r = V.get(o.columnIndex);
if (r !== void 0) {
C.add(r);
const s = M(e, r);
s.forEach((i) => C.add(i)), P(e, s, C), U(e, r, C), s.forEach((i) => {
U(e, i, C);
});
}
}), t && Array.isArray(t)) {
for (let o = 0; o < t.length; o++)
T[o] = t[o].filter(
(r) => C.has(r)
);
m = T[a] || [];
}
const y = g(e, m);
h = y.first, S = y.last;
let A = 0;
for (let o = 0; o < h; o++) {
const r = e[m[o]];
r != null && r.locked && (A += r.headerColSpan || 1);
}
let v = 0, b = 0, F = !1;
return m.forEach((o, r) => {
c.push(o);
const s = e[o], i = (s == null ? void 0 : s.headerColSpan) || 1;
let d;
if (h === S)
d = l;
else if (r === h) {
const E = (s == null ? void 0 : s.virtualColumnOffset) || 0, { emptyColSpan: k, skipOffset: x } = B(e, T, a);
b += k;
const I = Math.max(0, E - A);
x && (b += I, F = !0), I > 0 && !x ? d = i + I : d = i;
} else if (r === S) {
let E = r === m.length - 1;
if (t != null && t[a]) {
const k = t[a], x = o;
let I = -1;
for (let R = k.length - 1; R >= 0; R--)
if (!e[k[R]].locked) {
I = k[R];
break;
}
E = x === I;
}
if (E)
d = i;
else {
const k = l - v - b;
if (d = Math.max(k, i), i > k && p.length > 0) {
const x = i - k;
p[0] -= x;
}
}
} else
d = i;
p.push(d), v += d;
}), {
columnsToRender: c,
colSpans: p,
skipOffset: F
};
}
function z(f) {
const { cellModels: n, columns: e = [], tableViewPortWidth: a, scrollLeft: u } = f;
let t = 0, c = n.length - 1, p = 0, h = 0;
for (let l = 0; l < n.length; l++)
if (!e[n[l].columnIndex].locked && (p = h, h += n[l].width || 10, h >= u)) {
t = l;
break;
}
for (let l = t; l < n.length; l++)
if (!e[n[l].columnIndex].locked)
if (p < a + u)
p += n[l].width || 10, c = l;
else
break;
t > 0 && t--, c < n.length - 1 && c++;
let S = 0, g = 0;
for (let l = 0; l < t; l++)
e[n[l].columnIndex].locked || (S += n[l].colSpan);
for (let l = c + 1; l < n.length; l++)
e[n[l].columnIndex].locked || (g += n[l].colSpan);
n[t].colSpan += S, n[c].colSpan += g;
const O = n.slice(0, t).filter((l) => e[l.columnIndex].locked), w = n.slice(c + 1).filter((l) => e[l.columnIndex].locked);
return [
...O,
...n.slice(t, c + 1),
...w
];
}
export {
P as addAllAncestors,
U as addDescendants,
M as getParentIndices,
z as getVirtualCellsToRender,
j as getVirtualHeaderCellsToRender
};