legacyUtil.js
1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.convertChildrenToData = convertChildrenToData;
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var React = _interopRequireWildcard(require("react"));
var _toArray = _interopRequireDefault(require("rc-util/lib/Children/toArray"));
function convertNodeToOption(node) {
var key = node.key,
_node$props = node.props,
children = _node$props.children,
value = _node$props.value,
restProps = (0, _objectWithoutProperties2.default)(_node$props, ["children", "value"]);
return (0, _objectSpread2.default)({
key: key,
value: value !== undefined ? value : key,
children: children
}, restProps);
}
function convertChildrenToData(nodes) {
var optionOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
return (0, _toArray.default)(nodes).map(function (node, index) {
if (!React.isValidElement(node) || !node.type) {
return null;
}
var isSelectOptGroup = node.type.isSelectOptGroup,
key = node.key,
_node$props2 = node.props,
children = _node$props2.children,
restProps = (0, _objectWithoutProperties2.default)(_node$props2, ["children"]);
if (optionOnly || !isSelectOptGroup) {
return convertNodeToOption(node);
}
return (0, _objectSpread2.default)((0, _objectSpread2.default)({
key: "__RC_SELECT_GRP__".concat(key === null ? index : key, "__"),
label: key
}, restProps), {}, {
options: convertChildrenToData(children)
});
}).filter(function (data) {
return data;
});
}