UNPKG

el-table-infinite-scroll

Version:
67 lines (60 loc) 2.51 kB
/*! * el-table-infinite-scroll v3.0.7 * (c) 2019-2025 yujinpan */ import 'core-js/modules/es.array.concat.js'; import 'core-js/modules/es.error.cause.js'; import { ElInfiniteScroll, useGlobalConfig } from 'element-plus'; import { syncAttrs } from './utils.js'; var msgTitle = '[el-table-infinite-scroll]: '; var ElTableInfiniteScroll = { mounted: function mounted(el, binding, VNode, oldVNode) { var _useScrollElem = useScrollElem(el), scrollElem = _useScrollElem.scrollElem; scrollElem.style.overflowY = 'auto'; // after render setTimeout(function () { if (!el.style.height) { scrollElem.style.height = '400px'; // eslint-disable-next-line console.warn("".concat(msgTitle, "el-table height required, otherwise will set scrollbar default height: 400px")); } syncOptions(el, scrollElem); // use `ElInfiniteScroll` ElInfiniteScroll.mounted(scrollElem, binding, VNode, oldVNode); }, 0); }, updated: function updated(el) { var _useScrollElem2 = useScrollElem(el), scrollElem = _useScrollElem2.scrollElem; syncOptions(el, scrollElem); }, unmounted: function unmounted(el) { var _useScrollElem3 = useScrollElem(el), scrollElem = _useScrollElem3.scrollElem; for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { args[_key - 1] = arguments[_key]; } ElInfiniteScroll.unmounted.apply(ElInfiniteScroll, [scrollElem].concat(args)); } }; function useScrollElem(el) { var _config$value; var config = useGlobalConfig(); var elTableScrollWrapperClass = ".".concat(((_config$value = config.value) === null || _config$value === void 0 ? void 0 : _config$value.namespace) || 'el', "-scrollbar__wrap"); var scrollElem = el.querySelector(elTableScrollWrapperClass); if (!scrollElem) { throw new Error("".concat(msgTitle).concat(elTableScrollWrapperClass, " element not found.")); } return { scrollElem: scrollElem }; } function syncOptions(sourceElem, targetElem) { syncAttrs(sourceElem, targetElem, ['infinite-scroll-disabled', 'infinite-scroll-delay', 'infinite-scroll-immediate', 'infinite-scroll-distance']); // fix: windows/chrome `scrollTop + clientHeight` is difference with `scrollHeight` var name = 'infinite-scroll-distance'; var value = +(sourceElem.getAttribute(name) || 0); targetElem.setAttribute(name, (value < 1 ? 1 : value) + ''); } export { ElTableInfiniteScroll as default };