tdesign-react
Version:
TDesign Component for React
226 lines (222 loc) • 10.5 kB
JavaScript
/**
* tdesign v1.11.6
* (c) 2025 tdesign
* @license MIT
*/
import { _ as _toConsumableArray } from '../../_chunks/dep-7a114245.js';
import { _ as _defineProperty } from '../../_chunks/dep-fb209a0c.js';
import { get, isPlainObject } from 'lodash-es';
import OptionGroup from '../base/OptionGroup.js';
import Option from '../base/Option.js';
import '../../_chunks/dep-901cf2d8.js';
import '../../_chunks/dep-9a3c539e.js';
import 'react';
import 'classnames';
import '../../hooks/useConfig.js';
import '../../config-provider/ConfigContext.js';
import '../../_chunks/dep-14e7d402.js';
import '../../_chunks/dep-72ba05e7.js';
import 'dayjs';
import '../defaultProps.js';
import '../../hooks/useDefaultProps.js';
import '../../_chunks/dep-889449c8.js';
import '../../hooks/useDomRefCallback.js';
import '../../hooks/useRipple.js';
import '../../hooks/useAnimation.js';
import '../../_util/setStyle.js';
import '../../_util/dom.js';
import 'raf';
import '../../_util/easing.js';
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 setValueToOptionFormOptionDom(dom, valueToOption, keys) {
var _dom$props = dom.props,
value = _dom$props.value,
label = _dom$props.label,
children = _dom$props.children;
valueToOption[value] = _defineProperty(_defineProperty({}, (keys === null || keys === void 0 ? void 0 : keys.value) || "value", value), (keys === null || keys === void 0 ? void 0 : keys.label) || "label", label || children || value);
}
var getValueToOption = function getValueToOption(children, options, keys) {
var valueToOption = {};
if (Array.isArray(options)) {
options.forEach(function (option) {
if (option.group) {
var _option$children;
option === null || option === void 0 || (_option$children = option.children) === null || _option$children === void 0 || _option$children.forEach(function (child) {
valueToOption[get(child, (keys === null || keys === void 0 ? void 0 : keys.value) || "value")] = _objectSpread(_objectSpread({}, child), {}, {
value: get(child, (keys === null || keys === void 0 ? void 0 : keys.value) || "value"),
label: get(child, (keys === null || keys === void 0 ? void 0 : keys.label) || "label")
});
});
} else {
valueToOption[get(option, (keys === null || keys === void 0 ? void 0 : keys.value) || "value")] = _objectSpread(_objectSpread({}, option), {}, {
value: get(option, (keys === null || keys === void 0 ? void 0 : keys.value) || "value"),
label: get(option, (keys === null || keys === void 0 ? void 0 : keys.label) || "label")
});
}
});
return valueToOption;
}
if (isPlainObject(children)) {
if (children.type === Option) {
setValueToOptionFormOptionDom(children, valueToOption, keys);
return valueToOption;
}
if (children.type === OptionGroup) {
var groupChildren = children.props.children;
if (Array.isArray(groupChildren)) {
groupChildren.forEach(function (item) {
setValueToOptionFormOptionDom(item, valueToOption, keys);
});
return valueToOption;
}
}
}
if (Array.isArray(children)) {
var _handlerElement = function handlerElement(item) {
if (item.type === Option) {
setValueToOptionFormOptionDom(item, valueToOption, keys);
}
if (item.type === OptionGroup) {
var _groupChildren = item.props.children;
if (Array.isArray(_groupChildren)) {
_groupChildren.forEach(function (groupItem) {
setValueToOptionFormOptionDom(groupItem, valueToOption, keys);
});
}
}
if (Array.isArray(item)) {
item.forEach(function (child) {
_handlerElement(child);
});
}
};
children.forEach(function (item) {
return _handlerElement(item);
});
}
return valueToOption;
};
var getLabel = function getLabel(children, value, options, keys) {
var selectedLabel = "";
if (Array.isArray(options)) {
options.some(function (option) {
if ([get(value, (keys === null || keys === void 0 ? void 0 : keys.value) || "value"), value].includes(option.value)) {
selectedLabel = option.label;
return true;
}
return false;
});
return selectedLabel;
}
if (isPlainObject(children)) {
selectedLabel = children.props.label;
if (children.type === OptionGroup) {
var groupChildren = children.props.children;
if (Array.isArray(groupChildren)) {
groupChildren.some(function (item) {
var selectedValue = isPlainObject(value) ? get(value, "value") : value;
if (isPlainObject(item.props) && item.props.value === selectedValue) {
selectedLabel = item.props.label || item.props.children;
return true;
}
return false;
});
}
}
}
if (Array.isArray(children)) {
children.some(function (item) {
if (item.type === OptionGroup) {
var _groupChildren2 = item.props.children;
if (Array.isArray(_groupChildren2)) {
var isSelected = _groupChildren2.some(function (item2) {
var selectedValue2 = isPlainObject(value) ? get(value, "value") : value;
if (isPlainObject(item2.props) && item2.props.value === selectedValue2) {
selectedLabel = item2.props.label || item2.props.children;
return true;
}
return false;
});
return isSelected;
}
}
var selectedValue = isPlainObject(value) ? get(value, "value") : value;
if (isPlainObject(item.props) && item.props.value === selectedValue) {
selectedLabel = item.props.label || item.props.children;
return true;
}
return false;
});
}
return selectedLabel;
};
var getMultipleTags = function getMultipleTags(values, keys) {
var tags = values.map(function (item) {
return {
label: get(item, (keys === null || keys === void 0 ? void 0 : keys.label) || "label") || item.toString(),
value: get(item, (keys === null || keys === void 0 ? void 0 : keys.value) || "value") || item
};
});
return tags;
};
var getSelectValueArr = function getSelectValueArr(values, activeValue, selected, valueType, keys, objVal) {
values = Array.isArray(values) ? values : [];
if (Array.isArray(values)) {
var currentValues = _toConsumableArray(values);
var isValueObj = valueType === "object";
if (selected) {
currentValues = currentValues.filter(function (item) {
if (isValueObj) {
if (isPlainObject(activeValue)) {
return get(item, (keys === null || keys === void 0 ? void 0 : keys.value) || "value") !== get(activeValue, (keys === null || keys === void 0 ? void 0 : keys.value) || "value");
}
return get(item, (keys === null || keys === void 0 ? void 0 : keys.value) || "value") !== activeValue;
}
return item !== activeValue;
});
} else {
var item = isValueObj ? objVal : activeValue;
currentValues.push(item);
}
return currentValues;
}
};
var getSelectedOptions = function getSelectedOptions(value, multiple, valueType, keys, valueToOption, selectedValue) {
var isObjectType = valueType === "object";
var currentSelectedOptions = [];
var currentOption;
var allSelectedValue;
var tmpPropOptions = Object.values(valueToOption);
if (multiple) {
var _tmpPropOptions$filte, _currentSelectedOptio, _currentSelectedOptio2;
currentSelectedOptions = isObjectType ? value : tmpPropOptions === null || tmpPropOptions === void 0 || (_tmpPropOptions$filte = tmpPropOptions.filter) === null || _tmpPropOptions$filte === void 0 ? void 0 : _tmpPropOptions$filte.call(tmpPropOptions, function (v) {
var _value$includes;
return (_value$includes = value.includes) === null || _value$includes === void 0 ? void 0 : _value$includes.call(value, v[(keys === null || keys === void 0 ? void 0 : keys.value) || "value"]);
});
allSelectedValue = isObjectType ? currentSelectedOptions : (_currentSelectedOptio = currentSelectedOptions) === null || _currentSelectedOptio === void 0 ? void 0 : _currentSelectedOptio.map(function (v) {
return v[(keys === null || keys === void 0 ? void 0 : keys.value) || "value"];
});
currentOption = isObjectType ? value.find(function (v) {
return v[(keys === null || keys === void 0 ? void 0 : keys.value) || "value"] === selectedValue;
}) : (_currentSelectedOptio2 = currentSelectedOptions) === null || _currentSelectedOptio2 === void 0 ? void 0 : _currentSelectedOptio2.find(function (option) {
return option[(keys === null || keys === void 0 ? void 0 : keys.value) || "value"] === selectedValue;
});
} else {
var _tmpPropOptions$filte2, _currentSelectedOptio3;
currentSelectedOptions = isObjectType ? [value] : (tmpPropOptions === null || tmpPropOptions === void 0 || (_tmpPropOptions$filte2 = tmpPropOptions.filter) === null || _tmpPropOptions$filte2 === void 0 ? void 0 : _tmpPropOptions$filte2.call(tmpPropOptions, function (v) {
return value === v[(keys === null || keys === void 0 ? void 0 : keys.value) || "value"];
})) || [];
allSelectedValue = currentSelectedOptions;
currentOption = isObjectType ? value : (_currentSelectedOptio3 = currentSelectedOptions) === null || _currentSelectedOptio3 === void 0 ? void 0 : _currentSelectedOptio3.find(function (option) {
return option[(keys === null || keys === void 0 ? void 0 : keys.value) || "value"] === selectedValue;
});
}
return {
currentSelectedOptions: currentSelectedOptions,
currentOption: currentOption,
allSelectedValue: allSelectedValue
};
};
export { getLabel, getMultipleTags, getSelectValueArr, getSelectedOptions, getValueToOption };
//# sourceMappingURL=helper.js.map