UNPKG

@fe6/water-pro

Version:

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

60 lines (50 loc) 2.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.convertChildrenToData = convertChildrenToData; var _tslib = require("tslib"); var _propsUtil = require("../../_util/props-util"); 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); } function convertNodeToOption(node) { var key = node.key, children = node.children, _a = node.props, value = _a.value, disabled = _a.disabled, restProps = (0, _tslib.__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); } function convertChildrenToData(nodes) { var optionOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; var dd = (0, _propsUtil.flattenChildren)(nodes).map(function (node, index) { var _a; if (!(0, _propsUtil.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; }