UNPKG

@fe6/water-pro

Version:

An enterprise-class UI design language and Vue-based implementation

53 lines (45 loc) 1.92 kB
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } import { __rest } from "tslib"; import { flattenChildren, isValidElement } from '../../_util/props-util'; function convertNodeToOption(node) { var key = node.key, children = node.children, _a = node.props, value = _a.value, disabled = _a.disabled, restProps = __rest(_a, ["value", "disabled"]); var child = children && children.default ? children.default() : undefined; return _extends({ key: key, value: value !== undefined ? value : key, children: child, disabled: disabled || disabled === '' }, restProps); } export function convertChildrenToData(nodes) { var optionOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; var dd = flattenChildren(nodes).map(function (node, index) { var _a; if (!isValidElement(node) || !node.type) { return null; } var isSelectOptGroup = node.type.isSelectOptGroup, key = node.key, children = node.children, props = node.props; if (optionOnly || !isSelectOptGroup) { return convertNodeToOption(node); } var child = children && children.default ? children.default() : undefined; var label = (props === null || props === void 0 ? void 0 : props.label) || ((_a = children.label) === null || _a === void 0 ? void 0 : _a.call(children)) || key; return _extends(_extends({ key: "__RC_SELECT_GRP__".concat(key === null ? index : key, "__") }, props), { label: label, options: convertChildrenToData(child || []) }); }).filter(function (data) { return data; }); return dd; }