tdesign-vue
Version:
248 lines (244 loc) • 8.14 kB
JavaScript
/**
* tdesign v1.12.1
* (c) 2025 tdesign
* @license MIT
*/
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
import { pick } from 'lodash-es';
import { TreeStore } from '../../_common/js/tree/tree-store.js';
import '../adapt.js';
import { watch } from '@vue/composition-api';
import '@babel/runtime/helpers/classCallCheck';
import '@babel/runtime/helpers/createClass';
import '@babel/runtime/helpers/defineProperty';
import 'mitt';
import '../../_common/js/tree/tree-node.js';
import '@babel/runtime/helpers/asyncToGenerator';
import '@babel/runtime/regenerator';
import '../../_common/js/tree/tree-node-model.js';
import '../../_common/js/log/log.js';
import '../../_common/js/log/index.js';
import 'vue';
import '../../utils/withInstall.js';
import '../../hooks/useVModel.js';
import '../../hooks/useDefaultValue.js';
import 'tdesign-icons-vue';
import '../../checkbox/index.js';
import '../../checkbox/group.js';
import '../../_chunks/dep-323b993c.js';
import '@babel/runtime/helpers/typeof';
import '@babel/runtime/helpers/slicedToArray';
import '../../utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '../../checkbox/checkbox.js';
import '../../checkbox/props.js';
import '../../hooks/index.js';
import '../../utils/render-tnode.js';
import '@babel/runtime/helpers/readOnlyError';
import '../../hooks/slots.js';
import '../../hooks/useCommonClassName.js';
import '../../config-provider/useConfig.js';
import '../../config-provider/context.js';
import '../../_common/js/global-config/default-config.js';
import '../../_common/js/global-config/locale/zh_CN.js';
import '../../_chunks/dep-c44a474d.js';
import '../../_chunks/dep-d639fbd7.js';
import 'dayjs';
import '../../_chunks/dep-3c66615e.js';
import '../../config-provider/type.js';
import '../../_common/js/global-config/t.js';
import '../../hooks/useConfig.js';
import '../../hooks/useDestroyOnClose.js';
import '../../hooks/useElementLazyRender.js';
import '../../_common/js/utils/observe.js';
import '../../hooks/useFormDisabled.js';
import '../../hooks/useGlobalIcon.js';
import '../../hooks/useLazyLoad.js';
import '../../hooks/useResizeObserver.js';
import '../../hooks/useVirtualScrollNew.js';
import '../../hooks/useImagePreviewUrl.js';
import '../../_common/js/upload/utils.js';
import '../../checkbox/constants.js';
import '../../checkbox/store.js';
import '../../checkbox/hooks/useKeyboardEvent.js';
import '../../_common/js/common.js';
import '../../checkbox/checkbox-group-props.js';
import './style/index.js';
import '../../checkbox/type.js';
import '../../loading/index.js';
import '../../loading/directive.js';
import '../../loading/plugin.js';
import '../../loading/loading.js';
import '../../loading/icon/gradient.js';
import '../../_common/js/loading/circle-adapter.js';
import '../../_common/js/utils/setStyle.js';
import '../../_common/js/utils/helper.js';
import '../../config-provider/config-receiver.js';
import '../../utils/mixins.js';
import '../../utils/dom.js';
import 'raf';
import '../../utils/easing.js';
import '../../utils/transfer-dom.js';
import '../../loading/props.js';
import '../../config.js';
import '../../loading/type.js';
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