@progress/kendo-vue-grid
Version:
191 lines (190 loc) • 9.94 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
*-------------------------------------------------------------------------------------------
*/
import { getFlatColumnsState as g } from "../utils/main.mjs";
const x = 1, F = 20;
class E {
constructor(a) {
this.columns = [], this.columnsState = [], this.resizable = !1, this.isRtl = !1, this.setIsRtl = (r) => {
this.isRtl = r;
}, this.initWidths = () => {
var p;
const r = ((p = this.colGroupMain) == null ? void 0 : p.children) || [], c = g(this.columnsState), n = this.columns.filter((e) => {
var d;
return !((d = e.children) != null && d.length);
});
for (let e = 0; e < r.length; e++) {
const d = r[e], t = n[e];
let o = "";
const h = c.find((i) => i.id === n[e].id);
h && (o = this.applyWidthConstraints(h, t)), d.width = o, this.colGroupHeader && (this.colGroupHeader.children[e].width = o), this.colGroupFooter && (this.colGroupFooter.children[e].width = o), this.colGroupStickyHeader && (this.colGroupStickyHeader.children[e].width = o), this.colGroupStickyFooter && (this.colGroupStickyFooter.children[e].width = o), this.colGroupPinnedTop && (this.colGroupPinnedTop.children[e].width = o), this.colGroupPinnedBottom && (this.colGroupPinnedBottom.children[e].width = o);
}
}, this.dragHandler = (r, c, n, p) => {
const e = r.originalEvent;
p || (e.preventDefault(), e.stopPropagation(), e.stopImmediatePropagation());
const d = n.closest("th");
if (!d)
return;
const t = d.clientWidth;
let o = t;
if (this.isRtl ? o += n.getBoundingClientRect().right - n.offsetWidth / 2 - r.clientX : o += r.clientX - n.getBoundingClientRect().left - n.offsetWidth / 2, !p && Math.abs(o - t) < 1)
return;
this.fixateInitialWidths(d.parentElement.clientWidth), this.setWidths(c, Math.floor(o) / t);
const h = this.columns.filter((i) => !i.children.length).findIndex((i) => i.id === c.id);
this.onResize(h, t, o, e, p, this.columnsState, c.id);
}, this.dblClickHandler = (r, c) => {
const n = this.columns.filter((l) => c.indexOf(l.id) > -1), p = g(this.columnsState);
if (!this.colGroupMain || !n.length)
return;
const e = {}, d = n;
for (; d.length > 0; ) {
const l = d.pop();
if (!l)
break;
l.children.length ? d.push(...l.children) : e[l.id] = l;
}
const t = this.columns.filter((l) => !l.children.length), o = [];
t.forEach((l, s) => {
e[l.id] && o.push(s);
});
const h = [this.colGroupMain.parentElement], i = [this.colGroupMain];
this.colGroupHeader && (h.push(this.colGroupHeader.parentElement), i.push(this.colGroupHeader)), this.colGroupFooter && (h.push(this.colGroupFooter.parentElement), i.push(this.colGroupFooter)), this.colGroupStickyHeader && (h.push(this.colGroupStickyHeader.parentElement), i.push(this.colGroupStickyHeader)), this.colGroupStickyFooter && (h.push(this.colGroupStickyFooter.parentElement), i.push(this.colGroupStickyFooter)), this.colGroupPinnedTop && (h.push(this.colGroupPinnedTop.parentElement), i.push(this.colGroupPinnedTop)), this.colGroupPinnedBottom && (h.push(this.colGroupPinnedBottom.parentElement), i.push(this.colGroupPinnedBottom)), h.forEach((l) => l.classList.add("k-autofitting"));
const f = [];
i.forEach((l) => {
o.forEach((s) => {
l.children[s] && (l.children[s].width = "", f[s] = Math.max(
f[s] || 0,
l.children[s].offsetWidth + x
));
});
}), i.forEach((l) => {
o.forEach((s) => {
if (l.children[s]) {
l.children[s].width = f[s] + "px";
const w = p.find((k) => k.id === t[s].id);
w && (w.width = f[s]);
}
});
}), h.forEach((l) => l.classList.remove("k-autofitting")), this.onResize(o[0], 0, 0, r, !0, this.columnsState, c[0]);
}, this.updateColElements = (r) => {
var p, e, d, t, o, h, i;
const c = this.columns.filter((f) => !f.hidden && !f.children.length);
let n = 1e-10;
for (let f = 0; f < r.length; f++) {
const l = r[f], s = c.findIndex((u) => u.id === l.id), w = parseFloat((l.width || 0).toString()), k = Math.floor(w);
n += w - k;
const G = k + Math.floor(n);
n -= Math.floor(n);
const m = c.find((u) => u.id === l.id);
if (!m)
return;
if ((p = this.colGroupMain) != null && p.children[s]) {
const u = parseInt(this.colGroupMain.children[s].width, 10);
this.colGroupMain.children[s].width = G + "px", this.updateNextLockedCol(this.colGroupMain.parentElement, m, u - G);
}
if ((e = this.colGroupHeader) != null && e.children[s]) {
const u = parseInt(this.colGroupHeader.children[s].width, 10);
this.colGroupHeader.children[s].width = G + "px", this.updateNextLockedCol(this.colGroupHeader.parentElement, m, u - G);
}
if ((d = this.colGroupFooter) != null && d.children[s]) {
const u = parseInt(this.colGroupFooter.children[s].width, 10);
this.colGroupFooter.children[s].width = G + "px", this.updateNextLockedCol(this.colGroupFooter.parentElement, m, u - G);
}
if ((t = this.colGroupStickyHeader) != null && t.children[s]) {
const u = parseInt(this.colGroupStickyHeader.children[s].width, 10);
this.colGroupStickyHeader.children[s].width = G + "px", this.updateNextLockedCol(
this.colGroupStickyHeader.parentElement,
m,
u - G
);
}
if ((o = this.colGroupStickyFooter) != null && o.children[s]) {
const u = parseInt(this.colGroupStickyFooter.children[s].width, 10);
this.colGroupStickyFooter.children[s].width = G + "px", this.updateNextLockedCol(
this.colGroupStickyFooter.parentElement,
m,
u - G
);
}
if ((h = this.colGroupPinnedTop) != null && h.children[s]) {
const u = parseInt(this.colGroupPinnedTop.children[s].width, 10);
this.colGroupPinnedTop.children[s].width = G + "px", this.updateNextLockedCol(
this.colGroupPinnedTop.parentElement,
m,
u - G
);
}
if ((i = this.colGroupPinnedBottom) != null && i.children[s]) {
const u = parseInt(this.colGroupPinnedBottom.children[s].width, 10);
this.colGroupPinnedBottom.children[s].width = G + "px", this.updateNextLockedCol(
this.colGroupPinnedBottom.parentElement,
m,
u - G
);
}
}
}, this.onResize = a;
}
applyWidthConstraints(a, r, c = 1) {
var i;
if (!a.width)
return a.width || "";
const n = a.width.toString();
if (n.includes("%")) {
const l = parseFloat(n) * c, s = Math.max(0, Math.min(100, l));
return a.width = s + "%", a.width;
}
let e = parseFloat(n) * c;
const d = (i = r.minResizableWidth) != null ? i : 10, t = r.minWidth, o = t !== void 0 ? Math.max(d, t) : d, h = r == null ? void 0 : r.maxWidth;
return e < o && (e = o), h !== void 0 && e > h && (e = h), a.width = e, e;
}
fixateInitialWidths(a) {
var d;
let r = 0;
const c = ((d = this.colGroupMain) == null ? void 0 : d.children) || [];
for (let t = 0; t < c.length; t++)
c[t].width ? a -= c[t].clientWidth : r++;
if (r === 0)
return;
const n = Math.floor(a / r), p = g(this.columnsState), e = this.columns.filter((t) => !t.children.length);
for (let t = 0; t < c.length; t++) {
const o = c[t], h = o.width ? o.clientWidth : n;
o.width = h;
const i = p.find((f) => f.id === e[t].id);
i && (i.width = h.toString()), this.colGroupHeader && (this.colGroupHeader.children[t].width = h), this.colGroupFooter && (this.colGroupFooter.children[t].width = h), this.colGroupStickyHeader && (this.colGroupStickyHeader.children[t].width = h), this.colGroupStickyFooter && (this.colGroupStickyFooter.children[t].width = h);
}
}
setWidths(a, r) {
const c = g(this.columnsState), n = this.columns.findIndex((t) => t.id === a.id), p = [];
let e = a.children.filter((t) => !t.hidden).length;
for (let t = n + 1; t < this.columns.length && !(e <= 0); t++) {
const o = this.columns[t];
o.children.length ? e += o.children.filter((h) => !h.hidden).length : p.push(o), e--;
}
p.length === 0 && p.push(a);
const d = [];
p.forEach((t) => {
const o = c.find((h) => h.id === t.id);
o && (this.applyWidthConstraints(o, t, r), d.push(o));
}), this.updateColElements(d);
}
updateNextLockedCol(a, r, c) {
const n = r.index, p = this.colGroupMain.parentElement.closest(".k-grid"), e = p == null ? void 0 : p.clientWidth, d = this.columns.filter((t) => t.locked).map((t) => parseInt(t.width + "", 10)).reduce((t, o) => t + o, 0);
!r.locked || e <= d + F || this.columns.forEach((t) => {
if (t != null && t.locked && c) {
const o = a == null ? void 0 : a.querySelectorAll('[aria-colindex="' + t.ariaColumnIndex + '"]');
o == null || o.forEach((h) => {
const i = h.style;
this.isRtl ? (t.index > n && (i != null && i.right) && (i.right = parseInt(i.right, 10) - c + "px"), t.index < n && (i != null && i.left) && (i.left = parseInt(i.left, 10) - c + "px")) : (t.index > n && (i != null && i.left) && (i.left = parseInt(i.left, 10) - c + "px"), t.index < n && (i != null && i.right) && (i.right = parseInt(i.right, 10) - c + "px"));
});
}
});
}
}
export {
E as ColumnResize
};