@progress/kendo-react-data-tools
Version:
Includes React Pager & React Filter component, an intuitive interface to create complex filter descriptions. KendoReact Data Tools package
58 lines (57 loc) • 2.43 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 c {
constructor(e) {
this.columns = [], this.resizable = !1, this.isRtl = !1, this.setIsRtl = (h) => {
this.isRtl = h;
}, this.onResize = e, this.dragHandler = this.dragHandler.bind(this);
}
dragHandler(e, h, n, s) {
const l = e.originalEvent;
s || (l.preventDefault(), l.stopPropagation(), l.stopImmediatePropagation());
const t = n.parentElement;
if (!t || !t.parentElement)
return;
const i = t.clientWidth;
let o;
if (this.isRtl ? (o = n.getBoundingClientRect().right - n.offsetWidth / 2 - e.clientX, o += i) : o = i + e.clientX - n.getBoundingClientRect().left - n.offsetWidth / 2, !s && Math.abs(o - i) < 1)
return;
this.setWidths(h, Math.floor(o) / i);
const r = this.columns.filter((d) => !d.children.length).indexOf(h);
this.onResize(r, i, o, l, s);
}
setWidths(e, h) {
const n = this.columns.indexOf(e), s = [];
let l = e.children.length;
for (let t = n + 1; t < this.columns.length && !(l <= 0); t++) {
const i = this.columns[t];
i.children.length ? l += i.children.length : s.push(i), l--;
}
s.length === 0 && s.push(e), s.forEach((t) => {
let i = t.width ? parseFloat(t.width.toString()) * h : 0;
const o = t.minResizableWidth === void 0 ? 10 : t.minResizableWidth;
i < o && (i = o), t.width = Math.floor(i);
}), this.updateColElements(s);
}
updateColElements(e) {
const h = this.columns.filter((s) => !s.children.length);
let n = 1e-10;
for (let s = 0; s < e.length; s++) {
const l = h.indexOf(e[s]), t = parseFloat((e[s].width || 0).toString());
n += t - Math.floor(t);
const i = Math.floor(t) + Math.floor(n);
n -= Math.floor(n), this.setColWidth(this.colGroupMain && this.colGroupMain.children[l], i), this.setColWidth(this.colGroupHeader && this.colGroupHeader.children[l], i), this.setColWidth(this.colGroupFooter && this.colGroupFooter.children[l], i);
}
}
setColWidth(e, h) {
e && (e.style.width = h + "px");
}
}
export {
c as ColumnResize
};