@progress/kendo-vue-data-tools
Version:
68 lines (67 loc) • 3 kB
JavaScript
/**
* @license
*-------------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the package root for more information
*-------------------------------------------------------------------------------------------
*/
class a {
constructor(n) {
this.resizable = !1, this.isRtl = !1, this.setIsRtl = (h) => {
this.isRtl = h;
}, this.onResize = n, this.dragHandler = this.dragHandler.bind(this);
}
dragHandler(n, h, o, i) {
const l = n.originalEvent;
i || (l.preventDefault(), l.stopPropagation(), l.stopImmediatePropagation());
const t = o.parentElement;
if (!t || !t.parentElement)
return;
const e = t.clientWidth;
let s;
if (this.isRtl ? (s = o.getBoundingClientRect().right - o.offsetWidth / 2 - n.clientX, s += e) : s = e + n.clientX - o.getBoundingClientRect().left - o.offsetWidth / 2, !i && Math.abs(s - e) < 1)
return;
this.fixateInitialWidths(t.parentElement.clientWidth), this.setWidths(h, Math.floor(s) / e);
const r = this.columns.filter((c) => !c.children.length).indexOf(h);
this.onResize(r, e, s, l, i);
}
fixateInitialWidths(n) {
const h = this.columns.filter((t) => !t.children.length);
let o = 0, i = this.colGroupMain ? this.colGroupMain.children : [];
for (let t = 0; t < i.length; t++)
i[t].width ? n -= parseFloat(i[t].width) : o++;
if (o === 0)
return;
const l = Math.floor(n / o);
for (let t = 0; t < i.length; t++) {
const e = i[t];
e.width || (e.width = l, h[t].width = l.toString(), this.colGroupHeader && (this.colGroupHeader.children[t].width = l), this.colGroupFooter && (this.colGroupFooter.children[t].width = l));
}
}
setWidths(n, h) {
const o = this.columns.indexOf(n), i = [];
let l = n.children.length;
for (let t = o + 1; l > 0 && t < this.columns.length; t++) {
const e = this.columns[t];
e.children.length ? l += e.children.length : i.push(e), l--;
}
i.length === 0 && i.push(n), i.forEach((t) => {
let e = t.width ? parseFloat(t.width.toString()) * h : 0;
const s = t.minResizableWidth === void 0 ? 10 : t.minResizableWidth;
e < s && (e = s), t.width = e;
}), this.updateColElements(i);
}
updateColElements(n) {
const h = this.columns.filter((i) => !i.children.length);
let o = 1e-10;
for (let i = 0; i < n.length; i++) {
const l = h.indexOf(n[i]), t = parseFloat((n[i].width || 0).toString());
o += t - Math.floor(t);
const e = Math.floor(t) + Math.floor(o);
o -= Math.floor(o), this.colGroupMain && (this.colGroupMain.children[l].width = e + "px"), this.colGroupHeader && (this.colGroupHeader.children[l].width = e + "px"), this.colGroupFooter && this.colGroupFooter.children[l] && (this.colGroupFooter.children[l].width = e + "px");
}
}
}
export {
a as ColumnResize
};