59 lines
1.5 KiB
JavaScript
59 lines
1.5 KiB
JavaScript
'use strict';
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.noop = noop;
|
|
exports.getKeyFromChildrenIndex = getKeyFromChildrenIndex;
|
|
exports.loopMenuItem = loopMenuItem;
|
|
exports.loopMenuItemRecusively = loopMenuItemRecusively;
|
|
|
|
var _react = require('react');
|
|
|
|
var _react2 = _interopRequireDefault(_react);
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
|
|
function noop() {}
|
|
|
|
function getKeyFromChildrenIndex(child, menuEventKey, index) {
|
|
var prefix = menuEventKey || '';
|
|
return child.key || prefix + 'item_' + index;
|
|
}
|
|
|
|
function loopMenuItem(children, cb) {
|
|
var index = -1;
|
|
_react2['default'].Children.forEach(children, function (c) {
|
|
index++;
|
|
if (c && c.type && c.type.isMenuItemGroup) {
|
|
_react2['default'].Children.forEach(c.props.children, function (c2) {
|
|
index++;
|
|
cb(c2, index);
|
|
});
|
|
} else {
|
|
cb(c, index);
|
|
}
|
|
});
|
|
}
|
|
|
|
function loopMenuItemRecusively(children, keys, ret) {
|
|
if (!children || ret.find) {
|
|
return;
|
|
}
|
|
_react2['default'].Children.forEach(children, function (c) {
|
|
if (ret.find) {
|
|
return;
|
|
}
|
|
if (c) {
|
|
var construt = c.type;
|
|
if (!construt || !(construt.isSubMenu || construt.isMenuItem || construt.isMenuItemGroup)) {
|
|
return;
|
|
}
|
|
if (keys.indexOf(c.key) !== -1) {
|
|
ret.find = true;
|
|
} else if (c.props.children) {
|
|
loopMenuItemRecusively(c.props.children, keys, ret);
|
|
}
|
|
}
|
|
});
|
|
} |