tdesign-vue-next
Version:
TDesign Component for vue-next
228 lines (224 loc) • 7.38 kB
JavaScript
/**
* tdesign v1.11.5
* (c) 2025 tdesign
* @license MIT
*/
import { _ as _toConsumableArray } from '../../_chunks/dep-03e058e5.mjs';
import { pick } from 'lodash-es';
import { T as TreeStore } from '../../_chunks/dep-0ba11368.mjs';
import '../adapt.mjs';
import { watch } from 'vue';
import '../../_chunks/dep-9f375e51.mjs';
import '../../_chunks/dep-7dcc7954.mjs';
import '../../_chunks/dep-da95471f.mjs';
import '../../_chunks/dep-4ed7019e.mjs';
import 'mitt';
import '../../_chunks/dep-3f189a8c.mjs';
import '../../_chunks/dep-3630a49c.mjs';
import '../../_chunks/dep-82d2a14f.mjs';
import '../../_chunks/dep-88187fb2.mjs';
import '../../_chunks/dep-198540b0.mjs';
import '../../utils/withInstall.mjs';
import '../../hooks/useVModel.mjs';
import '../../hooks/useDefaultValue.mjs';
import 'tdesign-icons-vue-next';
import '../../checkbox/index.mjs';
import '../../checkbox/checkbox.mjs';
import '../../_chunks/dep-6d9c1bfc.mjs';
import '../../checkbox/props.mjs';
import '../../hooks/useRipple.mjs';
import '../../hooks/useKeepAnimation.mjs';
import '../../hooks/useConfig.mjs';
import '../../config-provider/hooks/useConfig.mjs';
import '../../config-provider/utils/context.mjs';
import '../../_chunks/dep-a5ae2f3f.mjs';
import '../../_chunks/dep-37fa6ccb.mjs';
import '../../_chunks/dep-7fb24b17.mjs';
import '../../_chunks/dep-6cfc5734.mjs';
import '../../_chunks/dep-46ec3e86.mjs';
import '../../utils/render-tnode.mjs';
import '../../checkbox/consts/index.mjs';
import '../../checkbox/hooks/useCheckboxLazyLoad.mjs';
import '../../_chunks/dep-221379fb.mjs';
import '../../checkbox/hooks/useKeyboardEvent.mjs';
import '../../_chunks/dep-251d5b63.mjs';
import '../../hooks/useDisabled.mjs';
import '../../hooks/useReadonly.mjs';
import '../../checkbox/group.mjs';
import '../../checkbox/checkbox-group-props.mjs';
import '../../hooks/slot.mjs';
import './style/css.mjs';
import '../../loading/index.mjs';
import '../../loading/directive.mjs';
import '../../loading/plugin.mjs';
import '../../loading/loading.mjs';
import '../../loading/icon/gradient.mjs';
import '../../_chunks/dep-3d81ac0a.mjs';
import '../../_chunks/dep-6a79c950.mjs';
import '../../utils/dom.mjs';
import '../../hooks/useTeleport.mjs';
import '../../loading/props.mjs';
import '../../hooks/useGlobalIcon.mjs';
import '../../hooks/useLazyLoad.mjs';
import '../../hooks/useVirtualScrollNew.mjs';
import '../../hooks/useResizeObserver.mjs';
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.mjs.map