ideaz-element
Version:
<p align="center"> <a href="" target="_blank" rel="noopener noreferrer"> <img src="./docs/public/logo.svg" alt="Ideaz Element" width="180" style="width: 180px;" /> </a> </p>
71 lines (70 loc) • 2.7 kB
JavaScript
import "../utils/index.mjs";
import { isObject as _ } from "../utils/is.mjs";
function i(e, t) {
return !e || [...e.classList].includes(t) ? e : i(e.parentNode, t);
}
function v(e) {
return i(e, "el-table").getBoundingClientRect().width;
}
function B(e, t) {
var b;
let l = t.value.top || 0;
const h = t.value.zIndex || 0;
l = Number.parseFloat(l);
let a = e.querySelector(".el-table__header");
a = i(a, "el-table__header-wrapper");
const s = e.querySelector(".el-scrollbar") || e.querySelector(".el-table__body"), m = e.querySelector(".el-table__body-wrapper"), o = a.cloneNode(!0);
o.classList.add("el-table_header-copy"), o.style.display = "none", o.style.position = "fixed", o.style.zIndex = h || 1994, o.style.top = `${l}px`, o.style.backgroundColor = "#fff", _((b = t.value) == null ? void 0 : b.style) && Object.keys(t.value.style).forEach((r) => {
o.style[r] = t.value.style[r];
}), a.parentNode.insertBefore(o, m);
const d = v(a), y = t.value.parent === "document" ? document : document.querySelector(t.value.parent || "body");
if (!(!y || t.value.disabled === !0)) {
y.addEventListener("scroll", () => {
const r = a.clientHeight, p = a.getBoundingClientRect().top, c = s.getBoundingClientRect().top, n = s.getBoundingClientRect().bottom;
p <= l && (o.style.display = "block", o.style.width = `${s.offsetWidth < d ? s.offsetWidth : d}px`), (c - r > l || n - r / 2 <= l) && (o.style.display = "none");
});
try {
const r = e.querySelector(
".el-table__body-wrapper .el-scrollbar .el-scrollbar__bar.is-horizontal .el-scrollbar__thumb"
);
r && new MutationObserver((c) => {
for (const n of c)
if (n.type === "attributes" && n.attributeName === "style") {
const f = r.style.transform;
f && (o.querySelector(
".el-table__header"
).style.marginLeft = `-${f.replace(/[a-z()]/gi, "")}`);
}
}).observe(r, { attributes: !0 });
} catch {
}
}
}
let u = null;
const g = {
mounted(e, t) {
if (!t.value)
return;
const l = Number.parseInt(`${Math.random() * 10}`);
u = setTimeout(() => {
B(e, t);
}, 1e3 + l);
},
// update(el: any, binding: DirectiveBinding) {
// if (!binding.value)
// return
// const random = Number.parseInt(`${Math.random() * 10}`)
// // TIP delay Settings to ensure successful rendering of the table!
// clearTimeId = setTimeout(() => {
// createTableSticky(el, binding)
// // clearTimeout(clearTimeId)
// }, 1000 + random)
// },
unmounted() {
u && clearTimeout(u);
}
};
export {
g as sticky
};
//# sourceMappingURL=sticky.mjs.map