2019-01-08 23:03:13 +08:00
|
|
|
const isMobile = require('ismobilejs')
|
|
|
|
|
2017-12-08 14:31:53 +08:00
|
|
|
export function noop () {
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getKeyFromChildrenIndex (child, menuEventKey, index) {
|
|
|
|
const prefix = menuEventKey || ''
|
2018-09-19 13:14:46 +08:00
|
|
|
return child.key === undefined ? `${prefix}item_${index}` : child.key
|
2017-12-08 14:31:53 +08:00
|
|
|
}
|
|
|
|
|
2018-09-05 21:28:54 +08:00
|
|
|
export function getMenuIdFromSubMenuEventKey (eventKey) {
|
|
|
|
return `${eventKey}-menu-`
|
|
|
|
}
|
|
|
|
|
2017-12-08 14:31:53 +08:00
|
|
|
export function loopMenuItem (children, cb) {
|
2018-01-02 19:05:02 +08:00
|
|
|
let index = -1
|
|
|
|
children.forEach((c) => {
|
|
|
|
index++
|
|
|
|
if (c && c.type && c.type.isMenuItemGroup) {
|
|
|
|
c.$slots.default.forEach((c2) => {
|
|
|
|
index++
|
2018-01-16 19:15:07 +08:00
|
|
|
c.componentOptions && cb(c2, index)
|
2018-01-02 19:05:02 +08:00
|
|
|
})
|
|
|
|
} else {
|
2018-01-16 19:15:07 +08:00
|
|
|
c.componentOptions && cb(c, index)
|
2018-01-02 19:05:02 +08:00
|
|
|
}
|
|
|
|
})
|
2017-12-08 14:31:53 +08:00
|
|
|
}
|
|
|
|
|
2018-09-05 21:28:54 +08:00
|
|
|
export function loopMenuItemRecursively (children, keys, ret) {
|
2017-12-08 14:31:53 +08:00
|
|
|
if (!children || ret.find) {
|
|
|
|
return
|
|
|
|
}
|
2018-01-02 19:05:02 +08:00
|
|
|
children.forEach((c) => {
|
2017-12-08 14:31:53 +08:00
|
|
|
if (ret.find) {
|
|
|
|
return
|
|
|
|
}
|
2018-01-04 19:06:54 +08:00
|
|
|
if (c.data && c.data.slot && c.data.slot !== 'default') {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (c && c.componentOptions) {
|
|
|
|
const options = c.componentOptions.Ctor.options
|
|
|
|
if (!options || !(options.isSubMenu || options.isMenuItem || options.isMenuItemGroup)) {
|
2017-12-08 14:31:53 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if (keys.indexOf(c.key) !== -1) {
|
|
|
|
ret.find = true
|
2018-01-04 19:06:54 +08:00
|
|
|
} else if (c.componentOptions.children) {
|
2018-09-05 21:28:54 +08:00
|
|
|
loopMenuItemRecursively(c.componentOptions.children, keys, ret)
|
2017-12-08 14:31:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2018-09-05 21:28:54 +08:00
|
|
|
|
|
|
|
export const menuAllProps = {
|
|
|
|
props: [
|
|
|
|
'defaultSelectedKeys',
|
|
|
|
'selectedKeys',
|
|
|
|
'defaultOpenKeys',
|
|
|
|
'openKeys',
|
|
|
|
'mode',
|
|
|
|
'getPopupContainer',
|
|
|
|
'openTransitionName',
|
|
|
|
'openAnimation',
|
|
|
|
'subMenuOpenDelay',
|
|
|
|
'subMenuCloseDelay',
|
|
|
|
'forceSubMenuRender',
|
|
|
|
'triggerSubMenuAction',
|
|
|
|
'level',
|
|
|
|
'selectable',
|
|
|
|
'multiple',
|
|
|
|
'visible',
|
|
|
|
'focusable',
|
|
|
|
'defaultActiveFirst',
|
|
|
|
'prefixCls',
|
|
|
|
'inlineIndent',
|
|
|
|
'parentMenu',
|
|
|
|
'title',
|
|
|
|
'rootPrefixCls',
|
|
|
|
'eventKey',
|
|
|
|
'active',
|
2018-11-05 21:03:25 +08:00
|
|
|
'popupAlign',
|
2018-09-05 21:28:54 +08:00
|
|
|
'popupOffset',
|
|
|
|
'isOpen',
|
|
|
|
'renderMenuItem',
|
|
|
|
'manualRef',
|
|
|
|
'subMenuKey',
|
|
|
|
'disabled',
|
|
|
|
'index',
|
|
|
|
'isSelected',
|
|
|
|
'store',
|
|
|
|
'activeKey',
|
2018-11-05 21:03:25 +08:00
|
|
|
'builtinPlacements',
|
|
|
|
'overflowedIndicator',
|
2018-09-05 21:28:54 +08:00
|
|
|
|
|
|
|
// the following keys found need to be removed from test regression
|
|
|
|
'attribute',
|
|
|
|
'value',
|
|
|
|
'popupClassName',
|
|
|
|
'inlineCollapsed',
|
|
|
|
'menu',
|
|
|
|
'theme',
|
2018-11-05 21:03:25 +08:00
|
|
|
'itemIcon',
|
|
|
|
'expandIcon',
|
2018-09-05 21:28:54 +08:00
|
|
|
],
|
|
|
|
on: [
|
|
|
|
'select',
|
|
|
|
'deselect',
|
|
|
|
'destroy',
|
|
|
|
'openChange',
|
|
|
|
'itemHover',
|
|
|
|
'titleMouseenter',
|
|
|
|
'titleMouseleave',
|
|
|
|
'titleClick',
|
|
|
|
],
|
|
|
|
}
|
2018-11-05 21:03:25 +08:00
|
|
|
|
2019-01-08 23:03:13 +08:00
|
|
|
// ref: https://github.com/ant-design/ant-design/issues/14007
|
|
|
|
// ref: https://bugs.chromium.org/p/chromium/issues/detail?id=360889
|
|
|
|
// getBoundingClientRect return the full precision value, which is
|
|
|
|
// not the same behavior as on chrome. Set the precision to 6 to
|
|
|
|
// unify their behavior
|
|
|
|
export const getWidth = (elem) => {
|
|
|
|
let width = elem &&
|
|
|
|
typeof elem.getBoundingClientRect === 'function' &&
|
|
|
|
elem.getBoundingClientRect().width
|
|
|
|
if (width) {
|
|
|
|
width = +width.toFixed(6)
|
|
|
|
}
|
|
|
|
return width || 0
|
|
|
|
}
|
2018-11-05 21:03:25 +08:00
|
|
|
|
|
|
|
export const setStyle = (elem, styleProperty, value) => {
|
|
|
|
if (elem && typeof elem.style === 'object') {
|
|
|
|
elem.style[styleProperty] = value
|
|
|
|
}
|
|
|
|
}
|
2019-01-08 23:03:13 +08:00
|
|
|
|
|
|
|
export const isMobileDevice = () => {
|
|
|
|
return isMobile.any
|
|
|
|
}
|