legacyUtil.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
  2. import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
  3. var _excluded = ["children", "value"],
  4. _excluded2 = ["children"];
  5. import * as React from 'react';
  6. import toArray from "rc-util/es/Children/toArray";
  7. function convertNodeToOption(node) {
  8. var _ref = node,
  9. key = _ref.key,
  10. _ref$props = _ref.props,
  11. children = _ref$props.children,
  12. value = _ref$props.value,
  13. restProps = _objectWithoutProperties(_ref$props, _excluded);
  14. return _objectSpread({
  15. key: key,
  16. value: value !== undefined ? value : key,
  17. children: children
  18. }, restProps);
  19. }
  20. export function convertChildrenToData(nodes) {
  21. var optionOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  22. return toArray(nodes).map(function (node, index) {
  23. if (! /*#__PURE__*/React.isValidElement(node) || !node.type) {
  24. return null;
  25. }
  26. var _ref2 = node,
  27. isSelectOptGroup = _ref2.type.isSelectOptGroup,
  28. key = _ref2.key,
  29. _ref2$props = _ref2.props,
  30. children = _ref2$props.children,
  31. restProps = _objectWithoutProperties(_ref2$props, _excluded2);
  32. if (optionOnly || !isSelectOptGroup) {
  33. return convertNodeToOption(node);
  34. }
  35. return _objectSpread(_objectSpread({
  36. key: "__RC_SELECT_GRP__".concat(key === null ? index : key, "__"),
  37. label: key
  38. }, restProps), {}, {
  39. options: convertChildrenToData(children)
  40. });
  41. }).filter(function (data) {
  42. return data;
  43. });
  44. }