legacyUtil.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
  2. import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
  3. var _excluded = ["value", "disabled"];
  4. import { flattenChildren, isValidElement } from '../../_util/props-util';
  5. function convertNodeToOption(node) {
  6. var key = node.key,
  7. children = node.children,
  8. _node$props = node.props,
  9. value = _node$props.value,
  10. disabled = _node$props.disabled,
  11. restProps = _objectWithoutProperties(_node$props, _excluded);
  12. var child = children === null || children === void 0 ? void 0 : children.default;
  13. return _objectSpread({
  14. key: key,
  15. value: value !== undefined ? value : key,
  16. children: child,
  17. disabled: disabled || disabled === ''
  18. }, restProps);
  19. }
  20. export function convertChildrenToData(nodes) {
  21. var optionOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  22. var dd = flattenChildren(nodes).map(function (node, index) {
  23. var _children$label;
  24. if (!isValidElement(node) || !node.type) {
  25. return null;
  26. }
  27. var isSelectOptGroup = node.type.isSelectOptGroup,
  28. key = node.key,
  29. children = node.children,
  30. props = node.props;
  31. if (optionOnly || !isSelectOptGroup) {
  32. return convertNodeToOption(node);
  33. }
  34. var child = children && children.default ? children.default() : undefined;
  35. var label = (props === null || props === void 0 ? void 0 : props.label) || ((_children$label = children.label) === null || _children$label === void 0 ? void 0 : _children$label.call(children)) || key;
  36. return _objectSpread(_objectSpread({
  37. key: "__RC_SELECT_GRP__".concat(key === null ? index : String(key), "__")
  38. }, props), {}, {
  39. label: label,
  40. options: convertChildrenToData(child || [])
  41. });
  42. }).filter(function (data) {
  43. return data;
  44. });
  45. return dd;
  46. }