UNPKG

tdesign-vue-next

Version:
166 lines (162 loc) 6.47 kB
/** * tdesign v1.15.2 * (c) 2025 tdesign * @license MIT */ import _defineProperty from '@babel/runtime/helpers/defineProperty'; import { computed, onMounted } from 'vue'; import { get } from 'lodash-es'; import '@babel/runtime/helpers/toConsumableArray'; import '@babel/runtime/helpers/typeof'; import '../../_chunks/dep-e604a5ce.js'; import '../../config-provider/hooks/useConfig.js'; import '@babel/runtime/helpers/slicedToArray'; import { l as log } from '../../_chunks/dep-0ffe4637.js'; import '../../_chunks/dep-7324137b.js'; import { u as useVirtualScrollNew } from '../../_chunks/dep-ddde4ba1.js'; import 'tdesign-icons-vue-next'; import '../../checkbox/index.js'; import '../../loading/index.js'; import '@babel/runtime/helpers/asyncToGenerator'; import '@babel/runtime/helpers/classCallCheck'; import '@babel/runtime/helpers/createClass'; import '@babel/runtime/regenerator'; import '../../_chunks/dep-7fac49fa.js'; import '../../config-provider/utils/context.js'; import '../../_chunks/dep-3b49fbbe.js'; import 'dayjs'; import '../../_chunks/dep-82e44120.js'; import '../../checkbox/checkbox.js'; import '../../checkbox/props.js'; import '../../_chunks/dep-1d44782f.js'; import '../../_chunks/dep-1f7ad104.js'; import '../../_chunks/dep-6c13cc0e.js'; import '../../_chunks/dep-b9ab7399.js'; import '../../_chunks/dep-79c44a11.js'; import '../../_chunks/dep-5360ac56.js'; import '../../_chunks/dep-41ae8479.js'; import '../../_chunks/dep-7b209207.js'; import '../../_chunks/dep-3ba91e12.js'; import '../../_chunks/dep-34e44a4e.js'; import '../../checkbox/consts/index.js'; import '../../checkbox/hooks/useCheckboxLazyLoad.js'; import '../../_chunks/dep-6f34ddfa.js'; import '../../checkbox/hooks/useKeyboardEvent.js'; import '../../_chunks/dep-01e48141.js'; import '../../checkbox/group.js'; import '../../checkbox/checkbox-group-props.js'; import '../../_chunks/dep-0f8c45fe.js'; import '../../_chunks/dep-37a2e7c8.js'; import 'tdesign-vue-next/esm/common/style/web/components/checkbox/_index.less'; import '../../loading/directive.js'; import '../../loading/plugin.js'; import '../../_chunks/dep-199af351.js'; import '../../loading/icon/gradient.js'; import '../../_chunks/dep-a72765fe.js'; import '@babel/runtime/helpers/objectWithoutProperties'; import '../../loading/props.js'; import 'tdesign-vue-next/esm/common/style/web/components/loading/_index.less'; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function useTreeScroll(state) { var treeState = state; var props = treeState.props, context = treeState.context, allNodes = treeState.allNodes, nodes = treeState.nodes, scope = treeState.scope, treeContentRef = treeState.treeContentRef, isScrolling = treeState.isScrolling; var scrollProps = computed(function () { return _objectSpread({ rowHeight: 34 }, props.scroll); }); scope.scrollProps = scrollProps; var virtualScrollParams = computed(function () { var list = allNodes.value.filter(function (node) { return node.visible; }); return { data: list, scroll: scrollProps.value, preventResizeRefresh: true }; }); var virtualConfig = useVirtualScrollNew(treeContentRef, virtualScrollParams); scope.virtualConfig = virtualConfig; treeState.virtualConfig = virtualConfig; onMounted(function () { var isVirtual = virtualConfig === null || virtualConfig === void 0 ? void 0 : virtualConfig.isVirtualScroll.value; if (isVirtual) { virtualConfig.handleScroll(); } }); var emitScrollEvent = function emitScrollEvent(e) { var _props$onScroll; (_props$onScroll = props.onScroll) === null || _props$onScroll === void 0 || _props$onScroll.call(props, { e: e }); context.emit("scroll", { e: e }); }; var scrollStopTimer = null; var setScrolling = function setScrolling() { isScrolling.value = true; if (scrollStopTimer) { clearTimeout(scrollStopTimer); scrollStopTimer = null; } scrollStopTimer = setTimeout(function () { scrollStopTimer = null; isScrolling.value = false; }, 100); }; var lastScrollY = 0; var onInnerVirtualScroll = function onInnerVirtualScroll(e) { setScrolling(); var isVirtual = virtualConfig === null || virtualConfig === void 0 ? void 0 : virtualConfig.isVirtualScroll.value; var target = e.target || e.srcElement; var top = target.scrollTop; if (lastScrollY !== top) { if (isVirtual) { virtualConfig.handleScroll(); nodes.value = virtualConfig.visibleData.value; } } else { lastScrollY = 0; } lastScrollY = top; emitScrollEvent(e); }; var handleScrollTo = function handleScrollTo(params) { var index = params.index; if (!index && index !== 0) { var _allNodes$value; if (!params.key) { log.error("Tree", "scrollToElement: one of `index` or `key` must exist."); return; } index = (_allNodes$value = allNodes.value) === null || _allNodes$value === void 0 ? void 0 : _allNodes$value.findIndex(function (item) { var _props$keys; return [get(item.data, "key"), get(item.data, ((_props$keys = props.keys) === null || _props$keys === void 0 ? void 0 : _props$keys["value"]) || "value")].includes(params.key); }); if (index < 0) { log.error("Tree", "".concat(params.key, " does not exist in data, check `key` or `data` please.")); return; } } virtualConfig.scrollToElement(_objectSpread(_objectSpread({}, params), {}, { index: index - 1 })); }; return { treeContentRef: treeContentRef, onInnerVirtualScroll: onInnerVirtualScroll, virtualConfig: virtualConfig, scrollToElement: handleScrollTo }; } export { useTreeScroll as default }; //# sourceMappingURL=useTreeScroll.js.map