forked from vueComponent/ant-design-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.js
140 lines (129 loc) · 3.02 KB
/
util.js
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import isMobile from './utils/isMobile';
import isObject from 'lodash-es/isObject';
export function noop() {}
export function getKeyFromChildrenIndex(child, menuEventKey, index) {
const prefix = menuEventKey || '';
return child.key === null ? `${prefix}item_${index}` : child.key;
}
export function getMenuIdFromSubMenuEventKey(eventKey) {
return `${eventKey}-menu-`;
}
export function loopMenuItem(children, cb) {
let index = -1;
children.forEach(c => {
index++;
if (c && c.type && c.type.isMenuItemGroup) {
c.children.default &&
c.children.default().forEach(c2 => {
index++;
cb(c2, index);
});
} else {
cb(c, index);
}
});
}
export function loopMenuItemRecursively(children, keys, ret) {
if (!children || ret.find) {
return;
}
children.forEach(c => {
if (ret.find) {
return;
}
const construct = c.type;
if (construct && isObject(construct)) {
if (
!construct ||
!(construct.isSubMenu || construct.isMenuItem || construct.isMenuItemGroup)
) {
return;
}
if (keys.indexOf(c.key) !== -1) {
ret.find = true;
} else if (c.children && c.children.default) {
loopMenuItemRecursively(c.children.default(), keys, ret);
}
}
});
}
export const menuAllProps = [
'defaultSelectedKeys',
'selectedKeys',
'defaultOpenKeys',
'openKeys',
'mode',
'getPopupContainer',
'openTransitionName',
'openAnimation',
'subMenuOpenDelay',
'subMenuCloseDelay',
'forceSubMenuRender',
'triggerSubMenuAction',
'level',
'selectable',
'multiple',
'visible',
'focusable',
'defaultActiveFirst',
'prefixCls',
'inlineIndent',
'title',
'rootPrefixCls',
'eventKey',
'active',
'popupAlign',
'popupOffset',
'isOpen',
'renderMenuItem',
'manualRef',
'subMenuKey',
'disabled',
'index',
'isSelected',
'store',
'activeKey',
'builtinPlacements',
'overflowedIndicator',
// the following keys found need to be removed from test regression
'attribute',
'value',
'popupClassName',
'inlineCollapsed',
'menu',
'theme',
'itemIcon',
'expandIcon',
'onSelect',
'onDeselect',
'onDestroy',
'onOpenChange',
'onItemHover',
'onTitleMouseenter',
'onTitleMouseleave',
'onTitleClick',
'slots',
'ref',
'isRootMenu',
];
// 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;
};
export const setStyle = (elem, styleProperty, value) => {
if (elem && typeof elem.style === 'object') {
elem.style[styleProperty] = value;
}
};
export const isMobileDevice = () => {
return isMobile.any;
};