UNPKG

@progress/kendo-vue-grid

Version:
320 lines (319 loc) 10.2 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 { findGroupExpand as T, updateLeft as k, updateRight as L, tableKeyboardNavigationTools as A } from "@progress/kendo-vue-data-tools"; import { getter as S, canUseDOM as b } from "@progress/kendo-vue-common"; import { gridDefaultProps as R } from "../GridColumn.mjs"; const u = "string"; function y(e, t) { const n = e.split("."); let i = t; return n.forEach((a) => { i = i ? i[a] : void 0; }), i; } function N(e, t, n, i, a, s, r, d, o, h, p = 0, f) { let c = p; for (let g = 0; g < t.length; g++) { let l; if (!a || t[g].value === void 0 || t[g].items === void 0) { const C = o ? !!(s != null && s[S(o)(t[g])]) : !1; e[e.length] = { dataIndex: i.index, dataItem: t[g], rowType: "data", level: p, group: f, // This is related to detail-row expansion expanded: h !== void 0 ? y(h, t[g]) : C != null ? C : !1 }, i.index++; continue; } else { let C; f != null && f.parents ? C = [{ field: f.field, value: f.value }, ...f.parents] : f ? C = [f] : C = [], l = { field: t[g].field, value: t[g].value, parents: C }; } c = Math.max(c, p + 1); let x = !1; const w = T(r || [], l); h ? x = h === void 0 || y(h, t[g]) === void 0 || y(h, t[g]) : x = w ? w.expanded !== !1 : d !== !1, e[e.length] = { dataIndex: -1, dataItem: t[g], level: p, group: l, rowType: "groupHeader", expanded: x }, x && (l.expanded = x, c = Math.max( N( e, t[g].items, n, i, a, s, r, d, o, h, p + 1, l ), c )), (n === "always" || x && n === "visible") && (e[e.length] = { dataIndex: -1, dataItem: t[g], rowType: "groupFooter", level: p, expanded: x }); } return c; } function U(e) { return e && getComputedStyle(e).direction === "rtl" || !1; } function V(e, t) { if (!t || !e || !e.originalEvent || !b) return -1; let n = document.elementFromPoint(e.clientX, e.originalEvent.clientY); for (; n && n.parentElement !== t; ) n = n.parentElement; const i = t.children; for (let a = 0; a < i.length; a++) if (i[a] === n) return a; return -1; } const E = [ "sortChange", "filterChange", "groupChange", "pageChange", "expandChange", "selectionChange", "headerSelectionChange", "rowClick", "itemChange", "dataStateChange", "columnResize", "columnReorder" ], O = (e, t) => `The ${e} event handler property is deprecated, use https://www.telerik.com/kendo-vue-ui/components/grid/api/GridProps/#toc-${t} instead`; function P(e) { for (let t = 0; t < E.length; t++) { const n = E[t]; if (e[n] !== void 0) { const i = "on" + n.charAt(0).toUpperCase() + n.slice(1); console.warn(O(n, i)); } } } function W(e, t) { const n = [[]]; let i = 0; for (let r = e.length - 1; r >= 0; r--) i = Math.max(i, e[r].depth), e[r].headerColSpan = e[r].headerColSpan || 1, e[r].children.length > 0 && (e[r].headerColSpan = e[r].children.reduce( (d, o) => o.hidden ? d : d + o.headerColSpan, 0 )); const a = []; let s = 1; return e.forEach((r, d) => { n[r.depth] = n[r.depth] || []; let o = !1; n[r.depth].length === 0 && (s <= 1 ? s = 1 + (r.children.length > 0 ? 0 : i - r.depth) : (s--, o = !0)), r.rowSpan = 1 + (r.children.length > 0 ? 0 : i - r.depth), r.kFirst = o, r.index = n[r.depth].length, r.ariaColumnIndex = a[r.depth] ? a[r.depth] + 1 : 1; let h = 0; const p = [], f = /* @__PURE__ */ new Set(); let c = r.parentIndex; for (; c >= 0 && !f.has(c); ) f.add(c), p.unshift(c), c = e[c].parentIndex; for (let l = 0; l < p.length; l++) { const x = p[l], w = e[x], C = n[w.depth], v = C.indexOf(x); for (let I = 0; I < v; I++) { const F = C[I]; h += e[F].headerColSpan; } } for (let l = 0; l < r.depth; l++) { const x = n[l] || []; for (const w of x) { const C = e[w]; C.depth + C.rowSpan - 1 >= r.depth && (p.includes(w) || (h += C.headerColSpan)); } } const g = n[r.depth]; for (const l of g) { const x = e[l]; x.parentIndex === r.parentIndex && (h += x.headerColSpan); } r.virtualColumnOffset = h, n[r.depth].push(d); for (let l = r.depth; l < r.depth + r.rowSpan; l++) a[l] = (a[l] || 0) + r.headerColSpan; }), k(n, e, t), L(n, e, t), n; } function H(e, t, n, i = 0, a = !1) { const s = []; if (!e) return []; e && e.length === void 0 && (e = [e]), e.forEach((d, o) => { d = d; const h = d.id ? d.id : A.generateNavigatableId(`${n.prevId++}`, n.idPrefix, "column"), p = b && d.media && window.matchMedia ? !window.matchMedia(d.media).matches : !1, f = a || p || d.hidden, c = t == null ? void 0 : t.find((l) => l.id === h), g = H(d.children, (c == null ? void 0 : c.children) || [], n, i + 1, f); s.push( { depth: i, ...R, ...g.length ? { cell: () => null, filterCell: () => null } : {}, ...d, id: h, declarationIndex: s.length, children: g, headerColSpan: 0, rowSpan: 0, columnType: d.columnType || "data", colSpan: d.colSpan || 1, isAccessible: !0, hidden: f, left: null, right: null, rowSpannable: d.rowSpannable, ...c ? { width: c.width, orderIndex: c.orderIndex } : {} } ); }); const r = (d, o) => d.orderIndex === o.orderIndex ? d.declarationIndex - o.declarationIndex : (d.orderIndex || 0) - (o.orderIndex || 0); if (s.sort(r), i === 0) { const d = [], o = (h, p) => h.forEach((f) => { f.parentIndex = p, o(f.children, d.push(f) - 1); }); return o(s, -1), d; } return s; } const j = (e) => Array.isArray(e) ? e : e ? e.data : []; function X(e, t, n, i) { const a = j(e), s = []; if (a.length > 0) { let r = a[0]; if (t) for (let o = 0; o < t.length; o++) r = r.items && r.items[0]; Object.getOwnPropertyNames(r).forEach((o) => { o !== n.column && s.push( { id: A.generateNavigatableId(`${i.prevId++}`, i.idPrefix, "column"), declarationIndex: -1, parentIndex: -1, depth: 0, colSpan: 0, headerColSpan: 0, rowSpan: 0, index: 0, columnType: "data", left: 0, right: 0, rightBorder: !1, children: [], ariaColumnIndex: 0, isAccessible: !0, ...R, field: o } ); }); } return s; } const $ = (e, t) => { let n = e[t.parentIndex]; for (; n; ) { if (n.footerCell) return !0; n = e[n.parentIndex]; } return !1; }, Y = (e) => e.filter((t) => $(e, t) ? !1 : !!t.footerCell || !(t.children && t.children.length > 0)), J = { number: function(e, t, n) { return typeof e === u && e.toLowerCase() === "null" ? null : t.parseNumber(e, n); }, date: function(e, t, n) { return typeof e === u && e.toLowerCase() === "null" ? null : t.parseDate(e, n); }, boolean: function(e) { return typeof e === u ? e.toLowerCase() === "null" ? null : e.toLowerCase() === "true" : e != null ? !!e : e; }, string: function(e) { return typeof e === u && e.toLowerCase() === "null" ? null : e != null ? e + "" : e; }, default: function(e) { return e; } }; function M(e, t, n, i) { return e.forEach((a) => { a.expanded = t[i] && !t[i].includes(D(a, n)), a.items && a.items.length && (a.items = M(a.items, t, n, i + 1)); }), e; } function Q(e, t, n) { return t && t.length && e.data.forEach((i) => { i.expanded = i.expanded !== void 0 ? i.expanded : t[0] && !t[0].includes(D(i, n)), i.items && i.items.length && (i.items = M(i.items, t, n, 1)); }), e; } function D(e, t) { let n = e; for (; n.items && n.items.length; ) n = n.items[0]; return t ? n[t] : e.value; } const Z = (e) => { const t = [], n = (i) => i == null ? void 0 : i.forEach((a) => { t.push(a), n(a.children); }); return n(e), t; }, _ = typeof window != "undefined" && /Firefox/.test(window.navigator.userAgent), q = 17895697, G = (e) => e.width !== void 0 ? Math.floor(parseFloat(e.width.toString())) + "px" : void 0, ee = (e, t) => t && t.filter((n) => n.field === e).length > 0, B = (e) => (e.sort((t, n) => t.declarationIndex - n.declarationIndex), e.map((t) => { const { declarationIndex: n, parentIndex: i, depth: a, headerColSpan: s, rowSpan: r, index: d, kFirst: o, children: h, ...p } = t; return h.length ? { children: B(h), ...p } : p; })), te = (e, t) => typeof e.colSpan == "function" ? e.colSpan({ dataItem: t, column: e }) : e.colSpan || 1, ne = (e) => { var i, a; const t = typeof e == "object" ? (i = e.enabled) != null ? i : !0 : e != null ? e : !1, n = typeof e == "object" ? (a = e.valueGetter) != null ? a : (s, r) => S(r)(s) : (s, r) => S(r)(s); return { enabled: t, valueGetter: n }; }, re = (e) => { let t = 0; if (e) { const n = e.insertRow(0), i = n.insertCell(0); i.textContent = "&nbsp;", t = n.getBoundingClientRect().height, e.deleteRow(0); } return t; }; export { Q as applyExpandedState, X as autoGenerateColumns, re as calcRowHeight, P as checkPropCompatibility, _ as firefox, q as firefoxMaxHeight, N as flatData, Y as footerColumns, te as getColSpan, G as getColumnWidth, j as getDataAsArray, Z as getFlatColumnsState, V as getIndex, y as getNestedValue, ne as getRowSpanOptions, D as groupedFirstItemValue, U as isRtl, ee as isSorted, W as mapColumns, J as parsers, H as readColumns, B as sanitizeColumns };