commonUtil.js 1.0 KB

12345678910111213141516171819202122232425
  1. import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
  2. import toArray from "rc-util/es/Children/toArray";
  3. import * as React from 'react';
  4. export function parseChildren(children, keyPath) {
  5. return toArray(children).map(function (child, index) {
  6. if ( /*#__PURE__*/React.isValidElement(child)) {
  7. var _eventKey, _child$props;
  8. var key = child.key;
  9. var eventKey = (_eventKey = (_child$props = child.props) === null || _child$props === void 0 ? void 0 : _child$props.eventKey) !== null && _eventKey !== void 0 ? _eventKey : key;
  10. var emptyKey = eventKey === null || eventKey === undefined;
  11. if (emptyKey) {
  12. eventKey = "tmp_key-".concat([].concat(_toConsumableArray(keyPath), [index]).join('-'));
  13. }
  14. var cloneProps = {
  15. key: eventKey,
  16. eventKey: eventKey
  17. };
  18. if (process.env.NODE_ENV !== 'production' && emptyKey) {
  19. cloneProps.warnKey = true;
  20. }
  21. return /*#__PURE__*/React.cloneElement(child, cloneProps);
  22. }
  23. return child;
  24. });
  25. }