legacyUtil.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. var __rest = this && this.__rest || function (s, e) {
  3. var t = {};
  4. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
  5. if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  6. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
  7. }
  8. return t;
  9. };
  10. import { flattenChildren, isValidElement } from '../../_util/props-util';
  11. function convertNodeToOption(node) {
  12. const _a = node,
  13. {
  14. key,
  15. children
  16. } = _a,
  17. _b = _a.props,
  18. {
  19. value,
  20. disabled
  21. } = _b,
  22. restProps = __rest(_b, ["value", "disabled"]);
  23. const child = children === null || children === void 0 ? void 0 : children.default;
  24. return _extends({
  25. key,
  26. value: value !== undefined ? value : key,
  27. children: child,
  28. disabled: disabled || disabled === ''
  29. }, restProps);
  30. }
  31. export function convertChildrenToData(nodes) {
  32. let optionOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  33. const dd = flattenChildren(nodes).map((node, index) => {
  34. var _a;
  35. if (!isValidElement(node) || !node.type) {
  36. return null;
  37. }
  38. const {
  39. type: {
  40. isSelectOptGroup
  41. },
  42. key,
  43. children,
  44. props
  45. } = node;
  46. if (optionOnly || !isSelectOptGroup) {
  47. return convertNodeToOption(node);
  48. }
  49. const child = children && children.default ? children.default() : undefined;
  50. const label = (props === null || props === void 0 ? void 0 : props.label) || ((_a = children.label) === null || _a === void 0 ? void 0 : _a.call(children)) || key;
  51. return _extends(_extends({
  52. key: `__RC_SELECT_GRP__${key === null ? index : String(key)}__`
  53. }, props), {
  54. label,
  55. options: convertChildrenToData(child || [])
  56. });
  57. }).filter(data => data);
  58. return dd;
  59. }