UNPKG

@progress/kendo-vue-grid

Version:
351 lines (350 loc) 12 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2026 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ import { ref as B, onUpdated as be, watch as Ce } from "vue"; import "@progress/kendo-vue-common"; import "@progress/kendo-vue-data-tools"; function Fe(d) { const h = [], a = []; for (let t = 0; t < d.length; t++) { const n = d[t]; if (n.rowType === "groupHeader") { for (let e = a.length - 1; e >= 0; e--) if (a[e].level >= n.level) { const r = a[e]; h.push({ headerIndex: r.headerIndex, footerIndex: null, firstChildIndex: r.headerIndex + 1, lastChildIndex: t - 1, level: r.level }), a.splice(e, 1); } a.push({ headerIndex: t, level: n.level }); } else if (n.rowType === "groupFooter") { for (let e = a.length - 1; e >= 0; e--) if (a[e].level === n.level) { const r = a[e]; h.push({ headerIndex: r.headerIndex, footerIndex: t, firstChildIndex: r.headerIndex + 1, lastChildIndex: t - 1, level: n.level }), a.splice(e, 1); break; } } } for (const t of a) h.push({ headerIndex: t.headerIndex, footerIndex: null, firstChildIndex: t.headerIndex + 1, lastChildIndex: d.length - 1, level: t.level }); const p = /* @__PURE__ */ new Map(); for (const t of h) p.set(t.headerIndex, t); return p; } function $e(d, h, a, p, t) { var I; const n = [], e = t != null ? t : a, r = []; for (const f of h.values()) if (f.headerIndex < a) { const v = (I = f.footerIndex) != null ? I : f.lastChildIndex; v > f.headerIndex && v >= e && r.push(f); } const o = /* @__PURE__ */ new Map(); for (const f of r) { const v = o.get(f.level); (!v || f.headerIndex > v.headerIndex) && o.set(f.level, f); } const c = Array.from(o.keys()).sort((f, v) => f - v); for (const f of c) { const v = o.get(f); n.push({ item: d[v.headerIndex], flatIndex: v.headerIndex }); } return n; } function Me(d, h, a, p) { const t = [], n = []; for (const o of h.values()) o.footerIndex !== null && o.footerIndex > p && o.headerIndex <= p && n.push(o); const e = /* @__PURE__ */ new Map(); for (const o of n) { const c = e.get(o.level); (!c || o.footerIndex < c.footerIndex) && e.set(o.level, o); } const r = Array.from(e.keys()).sort((o, c) => c - o); for (const o of r) { const c = e.get(o); t.push({ item: d[c.footerIndex], flatIndex: c.footerIndex }); } return t; } function _(d, h) { if (d.length !== h.length) return !0; for (let a = 0; a < d.length; a++) if (d[a].flatIndex !== h[a].flatIndex) return !0; return !1; } function we(d, h) { const a = d.querySelectorAll("tbody > tr"); let p = 0, t = !1; for (let n = 0; n < a.length && n < h.length; n++) { const e = a[n], r = e.offsetHeight || e.getBoundingClientRect().height, o = h[n]; if (o < 0) { t = !0; const c = -o, I = Math.max(r - c, 0); p += I, I <= 0 ? (e.style.display = "none", e.style.transform = "", e.style.clipPath = "") : (e.style.display = "", e.style.transform = `translateY(${o}px)`, e.style.clipPath = `inset(${c}px 0 0 0)`); } else p += r, e.style.display = "", e.style.transform = "", e.style.clipPath = ""; } d.style.height = t ? p + "px" : ""; } function Pe(d, h) { const a = d.querySelectorAll("tbody > tr"); let p = 0, t = !1, n = 0; const e = []; for (let r = 0; r < a.length && r < h.length; r++) { const o = a[r], c = o.offsetHeight || o.getBoundingClientRect().height; e.push(c); const I = h[r]; if (I > 0) { t = !0; const f = Math.max(c - I, 0); p += f, n += c - f; } else p += c; } for (let r = 0; r < a.length && r < h.length; r++) { const o = a[r], c = h[r], I = e[r]; c > 0 ? Math.max(I - c, 0) <= 0 ? (o.style.display = "", o.style.transform = "", o.style.clipPath = "inset(0 0 100% 0)") : (o.style.display = "", o.style.transform = "", o.style.clipPath = `inset(0 0 ${c}px 0)`) : (o.style.display = "", o.style.transform = t ? `translateY(${-n}px)` : "", o.style.clipPath = ""); } d.style.height = t ? p + "px" : ""; } function Ae(d) { const { enabled: h, enabledFooters: a, flatData: p, stickyHeaderRef: t, stickyFooterRef: n, containerRef: e, tableBodyRef: r, isGrouped: o, virtualSkipRef: c, rowHeight: I, rowHeightServiceRef: f } = d, v = h && o.value, O = !!a && o.value, V = B([]), ee = B([]), K = B([]), N = B([]), te = B([]), Q = B([]), oe = B(!1), se = B(!1); be(() => { var u; oe.value && ((u = t.value) != null && u.$el) && ee.value.length > 0 && (we(t.value.$el, ee.value), oe.value = !1), t.value && e.value && (t.value.$el.scrollLeft = e.value.scrollLeft); }), be(() => { var u, H; se.value && ((u = n.value) != null && u.$el) && te.value.length > 0 && (Pe((H = n.value) == null ? void 0 : H.$el, te.value), se.value = !1), n.value && e.value && (n.value.$el.scrollLeft = e.value.scrollLeft); }); const ke = () => { var ge, ve, pe, ye, me, xe, Ie; if (!v && !O) return; const u = p.value, H = Fe(u); if (H.size === 0) return; const L = /* @__PURE__ */ new Map(); if (O) for (const s of H.values()) s.footerIndex !== null && L.set(s.footerIndex, s); const k = e.value, G = r.value; if (!k || !G) return; const b = k.scrollTop, q = k.clientHeight, Y = G.children; if (Y.length === 0) return; const R = f == null ? void 0 : f.value, W = I || 36, g = (c == null ? void 0 : c.value) || 0, $ = k.getBoundingClientRect(), M = G.getBoundingClientRect().top - $.top + b, w = Y.length, z = new Array(w), X = new Array(w); for (let s = 0; s < w; s++) { const l = Y[s]; z[s] = M + l.offsetTop, X[s] = l.offsetHeight; } const le = (s) => { const l = s - g; return l >= 0 && l < w ? X[l] : R && s >= 0 && s < u.length ? R.height(s) : W; }, ae = (s) => { const l = s - g; if (l >= 0 && l < w) return z[l]; if (R && s >= 0 && s < u.length) return R.offset(s); }, Te = (s) => { let l = 0, i = w; for (; l < i; ) { const y = l + i >> 1; z[y] < s ? l = y + 1 : i = y; } return l; }, ie = (s) => { const l = Te(s); return l < w ? g + l : g; }, ce = (s) => { let l = 0, i = w - 1; for (; l <= i; ) { const y = l + i >> 1; z[y] + X[y] <= s ? l = y + 1 : i = y - 1; } return i >= 0 ? g + i : u.length - 1; }, fe = Math.min(ie(b), u.length - 1); let U = fe; const he = (s) => { const l = s.querySelectorAll("tbody > tr"); for (let i = 0; i < l.length; i++) { const y = l[i]; y.style.transform = "", y.style.clipPath = "", y.style.display = ""; } s.style.height = ""; }; if (v && t.value) { let s = 0, l = [], i = []; const y = (P) => { var x; const T = []; let m = 0; for (const C of P) { const F = le(C); let S = 0; const A = H.get(C); if (A) { const Z = (x = A.footerIndex) != null ? x : A.lastChildIndex + 1, E = ae(Z); if (E !== void 0) { const J = m + F, He = E - b; He < J && (S = He - J); } } T.push(S), m += Math.max(F + S, 0); } return { totalHeight: m, offsets: T }; }, j = /* @__PURE__ */ new Set(); for (; ; ) { U = Math.min( ie(b + Math.max(s, 0)), u.length - 1 ); const P = j.has(U); j.add(U); const T = Math.min( ce(b + q), u.length - 1 ), m = $e( u, H, U, T, fe ), x = y(m.map((F) => F.flatIndex)), C = !_(m, i) && Math.abs(x.totalHeight - s) < 1; if (i = m, s = x.totalHeight, l = x.offsets, C || P) break; } const ne = i.length > 0, re = V.value, D = _(i, re); ne ? D ? (V.value = i, ee.value = l, oe.value = !0) : (t.value.$el.style.display = "", we((ve = t.value) == null ? void 0 : ve.$el, l)) : (t.value.$el.style.display = "none", he((ge = t.value) == null ? void 0 : ge.$el)), D && (K.value = i, V.value = i); } if (O && n.value) { let s = 0, l = [], i = []; const y = (P) => { const T = []; let m = 0; for (let x = P.length - 1; x >= 0; x--) { const C = P[x], F = le(C); let S = 0; const A = L.get(C); if (A) { const Z = ae(A.headerIndex); if (Z !== void 0) { const E = Z + le(A.headerIndex), J = b + q - m - F; E > J && (S = E - J); } } T[x] = S, m += Math.max(F - S, 0); } return { totalHeight: m, offsets: T }; }, j = /* @__PURE__ */ new Set(); for (; ; ) { const P = Math.min( ce(b + q - s), u.length - 1 ), T = j.has(P); j.add(P); const m = Me( u, H, U, P ), x = y(m.map((F) => F.flatIndex)), C = !_(m, i) && Math.abs(x.totalHeight - s) < 1; if (i = m, s = x.totalHeight, l = x.offsets, C || T) break; } const ne = i.length > 0, re = N.value, D = _(i, re); ne ? D ? (N.value = i, te.value = l, se.value = !0) : (n.value.$el.style.display = "", Pe(n.value.$el, l)) : (n.value.$el.style.display = "none", he((pe = n.value) == null ? void 0 : pe.$el)), D && (Q.value = i, N.value = i); } const de = ((me = (ye = t.value) == null ? void 0 : ye.$el) == null ? void 0 : me.offsetHeight) || 0, ue = ((Ie = (xe = n.value) == null ? void 0 : xe.$el) == null ? void 0 : Ie.offsetHeight) || 0; return k.style.scrollPaddingTop = de > 0 ? de + "px" : "", k.style.scrollPaddingBottom = ue > 0 ? ue + "px" : "", { stickyHeaderItems: K, stickyFooterItems: Q }; }, Re = (u) => { var W; if (!v) return; const H = V.value.find( (g) => { var $, M; return (($ = g.item.group) == null ? void 0 : $.field) === u.field && ((M = g.item.group) == null ? void 0 : M.value) === u.value; } ); if (!H) return; const L = e.value; if (!L) return; let k = 0; const G = I || 36, b = (W = t.value.$el) == null ? void 0 : W.querySelectorAll("tbody > tr"), q = V.value; for (let g = 0; g < q.length; g++) if (q[g].item.level < H.item.level) { const $ = b && g < b.length && b[g].offsetHeight || G; k += $; } const Y = f == null ? void 0 : f.value; let R; if (Y) R = Y.offset(H.flatIndex); else { const g = r.value, $ = (c == null ? void 0 : c.value) || 0, M = H.flatIndex - $; if (g && M >= 0 && M < g.children.length) { const w = g.children[M], z = L.getBoundingClientRect(); R = g.getBoundingClientRect().top - z.top + L.scrollTop + w.offsetTop; } } R !== void 0 && (L.scrollTop = R - k); }; return Ce([() => v, () => O, e], () => { v || (V.value = [], K.value = []), O || (N.value = [], Q.value = []), !v && !O && e.value && (e.value.style.scrollPaddingTop = "", e.value.style.scrollPaddingBottom = ""); }), { stickyHeaderItems: K, stickyFooterItems: Q, scrollToStickyGroup: Re, update: ke }; } export { Fe as buildGroupRangeMap, Me as computeStickyFooterItems, $e as computeStickyItems, Ae as useStickyGroups };