UNPKG

tdesign-vue-next

Version:
223 lines (219 loc) 7.31 kB
/** * tdesign v1.15.2 * (c) 2025 tdesign * @license MIT */ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray'; import { pick } from 'lodash-es'; import { T as TreeStore } from '../../_chunks/dep-250cd3f5.js'; import { watch } from 'vue'; import '@babel/runtime/helpers/typeof'; import '../../_chunks/dep-e604a5ce.js'; import '../../config-provider/hooks/useConfig.js'; import '@babel/runtime/helpers/slicedToArray'; import '../../_chunks/dep-7324137b.js'; import '@babel/runtime/helpers/defineProperty'; 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 'mitt'; import '../../_chunks/dep-ec2f4297.js'; import '../../_chunks/dep-0ffe4637.js'; import '../../_chunks/dep-7fac49fa.js'; import '../../config-provider/utils/context.js'; import '../../_chunks/dep-3b49fbbe.js'; import 'dayjs'; 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 useTreeStore(state) { var props = state.props, context = state.context, refProps = state.refProps; var valueMode = props.valueMode, filter = props.filter, keys = props.keys; var store = new TreeStore({ valueMode: valueMode, filter: filter }); var tValue = state.vmValue[0]; var tActived = state.vmActived[0]; var tExpanded = state.vmExpanded[0]; var updateStoreConfig = function updateStoreConfig() { var storeProps = pick(props, ["expandAll", "expandLevel", "expandMutex", "expandParent", "activable", "activeMultiple", "disabled", "disableCheck", "checkable", "draggable", "checkStrictly", "load", "lazy", "valueMode", "filter", "allowFoldNodeOnFilter"]); store.setConfig(storeProps); }; var updateExpanded = function updateExpanded() { var expandParent = props.expandParent; if (!Array.isArray(tExpanded.value)) return; var expandedMap = /* @__PURE__ */new Map(); tExpanded.value.forEach(function (val) { expandedMap.set(val, true); if (expandParent) { var node = store.getNode(val); if (node) { node.getModel().getParents().forEach(function (tn) { expandedMap.set(tn.value, true); }); } } }); var expandedArr = Array.from(expandedMap.keys()); store.setExpanded(expandedArr); }; var filterChanged = false; var prevExpanded = null; var expandFilterPath = function expandFilterPath() { if (!props.allowFoldNodeOnFilter) return; if (!filterChanged) return; filterChanged = false; if (props.filter) { if (!prevExpanded) { prevExpanded = store.getExpanded(); } var pathValues = []; var allNodes = store.getNodes(); allNodes.forEach(function (node) { if (node.vmIsLocked) { pathValues.push(node.value); } }); store.setExpanded(pathValues); } else if (prevExpanded) { store.replaceExpanded(prevExpanded); prevExpanded = null; } }; var checkFilterExpand = function checkFilterExpand(newFilter, previousFilter) { if (!props.allowFoldNodeOnFilter) return; filterChanged = newFilter !== previousFilter; }; var handleLoad = function handleLoad(info) { var node = info.node; var evtCtx = { node: node.getModel() }; if (Array.isArray(tValue.value) && tValue.value.length > 0) { store.replaceChecked(tValue.value); } if (Array.isArray(tExpanded.value) && tExpanded.value.length > 0) { store.replaceExpanded(tExpanded.value); } if (Array.isArray(tActived.value) && tActived.value.length > 0) { store.replaceActived(tActived.value); } if (props !== null && props !== void 0 && props.onLoad) { props === null || props === void 0 || props.onLoad(evtCtx); } context.emit("load", evtCtx); }; var rebuild = function rebuild(list) { store.reload(list || []); store.refreshNodes(); if (Array.isArray(tValue.value)) { store.setChecked(tValue.value); } updateExpanded(); if (Array.isArray(tActived.value)) { store.setActived(tActived.value); } store.refreshState(); }; function initStore() { store.setConfig({ keys: keys }); updateStoreConfig(); store.append(props.data || []); store.refreshNodes(); if (Array.isArray(tValue.value)) { store.setChecked(tValue.value); } updateExpanded(); if (Array.isArray(tActived.value)) { store.setActived(tActived.value); } store.emitter.on("load", handleLoad); store.emitter.on("update", expandFilterPath); } initStore(); state.setStore(store); watch(function () { return _toConsumableArray(tValue.value || []); }, function (nVal) { store.replaceChecked(nVal); }); watch(function () { return _toConsumableArray(tExpanded.value || []); }, function (nVal) { store.replaceExpanded(nVal); }); watch(function () { return _toConsumableArray(tActived.value || []); }, function (nVal) { store.replaceActived(nVal); }); watch(refProps.filter, function (nVal, previousVal) { checkFilterExpand(nVal, previousVal); }); watch(refProps.keys, function (keys2) { store.setConfig({ keys: keys2 }); }); watch(refProps.expandAll, function (nVal) { if (nVal) { var valueList = store.getNodes().filter(function (node) { return Array.isArray(node.children) && node.children.length; }).map(function (node) { return node.value; }); store.setExpanded(valueList); } else { store.replaceExpanded(prevExpanded); prevExpanded = null; } }); return { store: store, rebuild: rebuild, checkFilterExpand: checkFilterExpand, updateStoreConfig: updateStoreConfig, updateExpanded: updateExpanded, expandFilterPath: expandFilterPath }; } export { useTreeStore as default }; //# sourceMappingURL=useTreeStore.js.map