tdesign-react
Version:
TDesign Component for React
106 lines (102 loc) • 3.4 kB
JavaScript
/**
* tdesign v1.15.1
* (c) 2025 tdesign
* @license MIT
*/
import { _ as _typeof } from '../../_chunks/dep-eca3a3de.js';
import { isEmpty } from 'lodash-es';
function getSingleContent(cascaderContext) {
var value = cascaderContext.value,
multiple = cascaderContext.multiple,
treeStore = cascaderContext.treeStore,
showAllLevels = cascaderContext.showAllLevels;
var BooleanIsFalseExceptZero = 0;
if (multiple || !value && value !== BooleanIsFalseExceptZero) return "";
if (Array.isArray(value)) return "";
var node = treeStore && treeStore.getNodes(value);
if (!(node && node.length)) {
return value;
}
var path = node && node[0].getPath();
if (path && path.length) {
return showAllLevels ? path.map(function (node2) {
return node2.label;
}).join(" / ") : path[path.length - 1].label;
}
return value;
}
function getMultipleContent(cascaderContext) {
var value = cascaderContext.value,
multiple = cascaderContext.multiple,
treeStore = cascaderContext.treeStore,
showAllLevels = cascaderContext.showAllLevels;
if (!multiple) return [];
if (multiple && !Array.isArray(value)) return [];
var node = treeStore && treeStore.getNodes(value);
if (!node) return [];
return value.map(function (item) {
var _node2$;
var node2 = treeStore.getNodes(item);
return showAllLevels ? getFullPathLabel(node2 === null || node2 === void 0 ? void 0 : node2[0]) : node2 === null || node2 === void 0 || (_node2$ = node2[0]) === null || _node2$ === void 0 ? void 0 : _node2$.label;
}).filter(function (item) {
return !!item;
});
}
function getPanels(treeNodes) {
var panels = [];
treeNodes.forEach(function (node) {
if (panels[node.level]) {
panels[node.level].push(node);
} else {
panels[node.level] = [node];
}
});
return panels;
}
function getFullPathLabel(node) {
var separator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "/";
return node === null || node === void 0 ? void 0 : node.getPath().map(function (node2) {
return node2.label;
}).join(separator);
}
var getTreeValue = function getTreeValue(value) {
var treeValue = [];
if (Array.isArray(value)) {
if (value.length > 0 && _typeof(value[0]) === "object") {
treeValue = value.map(function (val) {
return val.value;
});
} else if (value.length) {
treeValue = value;
}
} else if (value) {
if (_typeof(value) === "object") {
treeValue = [value.value];
} else {
treeValue = [value];
}
}
return treeValue;
};
var getCascaderValue = function getCascaderValue(value, valueType, multiple) {
if (valueType === "single") {
return value;
}
if (multiple) {
return value.map(function (item) {
return item[item.length - 1];
});
}
return value[value.length - 1];
};
function isEmptyValues(value) {
if (typeof value === "number" && !isNaN(value)) return false;
return isEmpty(value);
}
function isValueInvalid(value, cascaderContext) {
var multiple = cascaderContext.multiple,
showAllLevels = cascaderContext.showAllLevels;
return multiple && !Array.isArray(value) || !multiple && Array.isArray(value) && !showAllLevels;
}
export { getCascaderValue, getFullPathLabel, getMultipleContent, getPanels, getSingleContent, getTreeValue, isEmptyValues, isValueInvalid };
//# sourceMappingURL=helper.js.map