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