legacyUtil.js
1.44 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
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import * as React from 'react';
import toArray from "rc-util/es/Children/toArray";
function convertNodeToOption(node) {
var key = node.key,
_node$props = node.props,
children = _node$props.children,
value = _node$props.value,
restProps = _objectWithoutProperties(_node$props, ["children", "value"]);
return _objectSpread({
key: key,
value: value !== undefined ? value : key,
children: children
}, restProps);
}
export function convertChildrenToData(nodes) {
var optionOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
return toArray(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 = _objectWithoutProperties(_node$props2, ["children"]);
if (optionOnly || !isSelectOptGroup) {
return convertNodeToOption(node);
}
return _objectSpread(_objectSpread({
key: "__RC_SELECT_GRP__".concat(key === null ? index : key, "__"),
label: key
}, restProps), {}, {
options: convertChildrenToData(children)
});
}).filter(function (data) {
return data;
});
}