@ringcentral/juno 2.33.0 → 2.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/components/Presence/styles/StyledPresence.js +3 -3
  2. package/components/Presence/utils/RcPresenceUtils.js +1 -1
  3. package/components/Tabs/Tabs/MoreMenuTab/MoreMenuTab.js +4 -5
  4. package/components/Tabs/Tabs/MoreMenuTabs/MoreMenuTabSentinel.d.ts +7 -0
  5. package/components/Tabs/Tabs/MoreMenuTabs/MoreMenuTabSentinel.js +9 -0
  6. package/components/Tabs/Tabs/MoreMenuTabs/MoreMenuTabs.d.ts +0 -1
  7. package/components/Tabs/Tabs/MoreMenuTabs/MoreMenuTabs.js +276 -197
  8. package/components/Tabs/Tabs/MoreMenuTabs/utils/MoreMenuTabsUtils.d.ts +3 -34
  9. package/components/Tabs/Tabs/MoreMenuTabs/utils/MoreMenuTabsUtils.js +0 -87
  10. package/components/Tabs/Tabs/MoreMenuTabs/utils/index.js +0 -2
  11. package/es6/components/Presence/styles/StyledPresence.js +3 -3
  12. package/es6/components/Presence/utils/RcPresenceUtils.js +1 -1
  13. package/es6/components/Tabs/Tabs/MoreMenuTab/MoreMenuTab.js +4 -5
  14. package/es6/components/Tabs/Tabs/MoreMenuTabs/MoreMenuTabSentinel.js +6 -0
  15. package/es6/components/Tabs/Tabs/MoreMenuTabs/MoreMenuTabs.js +278 -199
  16. package/es6/components/Tabs/Tabs/MoreMenuTabs/utils/MoreMenuTabsUtils.js +0 -87
  17. package/es6/components/Tabs/Tabs/MoreMenuTabs/utils/index.js +0 -1
  18. package/es6/foundation/hooks/useDebounce/useDebounce.js +3 -2
  19. package/es6/foundation/hooks/useOnReRender/useOnReRender.js +6 -3
  20. package/es6/foundation/hooks/useThrottle/useThrottle.js +4 -3
  21. package/foundation/hooks/useDebounce/useDebounce.d.ts +3 -2
  22. package/foundation/hooks/useDebounce/useDebounce.js +3 -2
  23. package/foundation/hooks/useOnReRender/useOnReRender.d.ts +1 -1
  24. package/foundation/hooks/useOnReRender/useOnReRender.js +5 -2
  25. package/foundation/hooks/useThrottle/useThrottle.d.ts +3 -2
  26. package/foundation/hooks/useThrottle/useThrottle.js +4 -3
  27. package/package.json +1 -1
@@ -15,11 +15,11 @@ export var _StyledPresence = forwardRef(function (_a, ref) {
15
15
  export var StyledPresence = styled(_StyledPresence)(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n display: flex;\n flex-shrink: 0;\n justify-content: center;\n align-items: center;\n border-radius: 50%;\n box-sizing: content-box;\n\n ", ";\n"], ["\n display: flex;\n flex-shrink: 0;\n justify-content: center;\n align-items: center;\n border-radius: 50%;\n box-sizing: content-box;\n\n ",
16
16
  ";\n"])), function (_a) {
17
17
  var type = _a.type, iconSizeValue = _a.iconSizeValue, borderSizeValue = _a.borderSizeValue, color = _a.color;
18
- return css(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n width: ", "px;\n height: ", "px;\n background: ", ";\n margin: ", "px;\n ", ";\n ", " {\n svg {\n width: ", "px;\n height: ", "px;\n }\n }\n "], ["\n width: ", "px;\n height: ", "px;\n background: ",
19
- ";\n margin: ", "px;\n ",
18
+ return css(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n width: ", "px;\n height: ", "px;\n background: ", ";\n ", ";\n ", " {\n svg {\n width: ", "px;\n height: ", "px;\n }\n }\n "], ["\n width: ", "px;\n height: ", "px;\n background: ",
19
+ ";\n ",
20
20
  ";\n ", " {\n svg {\n width: ", "px;\n height: ", "px;\n }\n }\n "])), iconSizeValue, iconSizeValue, color
21
21
  ? getParsePaletteColor(color)
22
- : RcPresenceBackgroundColors[type] || palette2('neutral', 'l01'), borderSizeValue, fakeBorder({
22
+ : RcPresenceBackgroundColors[type] || palette2('neutral', 'l01'), fakeBorder({
23
23
  inset: false,
24
24
  color: palette2('neutral', 'l01'),
25
25
  size: borderSizeValue,
@@ -2,7 +2,7 @@ import { palette2 } from '../../../foundation';
2
2
  // first is width, second is border
3
3
  export var RcPresenceSizes = {
4
4
  xxsmall: [8, 1],
5
- xsmall: [8, 2],
5
+ xsmall: [10, 1],
6
6
  small: [10, 2],
7
7
  medium: [12, 2],
8
8
  large: [16, 2],
@@ -7,7 +7,6 @@ import { RcListItemIcon, RcListItemText } from '../../../List';
7
7
  import { RcMenu, RcMenuItem, } from '../../../Menu';
8
8
  import { RcTooltip } from '../../../Tooltip';
9
9
  import { RcTab } from '../../Tab';
10
- import { getKey } from '../MoreMenuTabs/utils';
11
10
  import { MoreMenuTabStyle } from './styles';
12
11
  var DEFAULT_MORE_MENU_TAB_LABEL = 'more_menu_tab';
13
12
  var _MoreMenuTab = forwardRef(function (props, ref) {
@@ -43,19 +42,19 @@ var _MoreMenuTab = forwardRef(function (props, ref) {
43
42
  if (!menuItems || menuItems.length === 0) {
44
43
  return null;
45
44
  }
46
- return menuItems.map(function (item, idx) {
47
- var icon = item.icon, label = item.label, value = item.value, disabled = item.disabled, onClick = item.onClick, selected = item.selected, menuItemRest = __rest(item, ["icon", "label", "value", "disabled", "onClick", "selected"]);
45
+ return menuItems.map(function (item) {
46
+ var icon = item.icon, label = item.label, value = item.value, disabled = item.disabled, onClick = item.onClick, selected = item.selected, key = item.key, menuItemRest = __rest(item, ["icon", "label", "value", "disabled", "onClick", "selected", "key"]);
48
47
  var handleClick = function (event) {
49
48
  onChange === null || onChange === void 0 ? void 0 : onChange(event, value);
50
49
  onClick === null || onClick === void 0 ? void 0 : onClick(event);
51
50
  };
52
- return (React.createElement(MenuItemComponent, { key: getKey(menuItemRest.key, idx), disabled: disabled, selected: selected, value: value, onClick: handleClick, "data-test-automation-id": menuItemRest['data-test-automation-id'] },
51
+ return (React.createElement(MenuItemComponent, { key: key, disabled: disabled, selected: selected, value: value, onClick: handleClick, "data-test-automation-id": menuItemRest['data-test-automation-id'] },
53
52
  icon ? React.createElement(RcListItemIcon, null, icon) : null,
54
53
  React.createElement(RcListItemText, { primary: label || value })));
55
54
  });
56
55
  }, [MenuItemComponent, menuItems, onChange]);
57
56
  return (React.createElement(React.Fragment, null,
58
- React.createElement(RcTab, __assign({}, rest, { ref: ref, onClick: handleTabClick, label: MoreIcon, value: DEFAULT_MORE_MENU_TAB_LABEL, "aria-haspopup": "true", "aria-controls": menuId })),
57
+ React.createElement(RcTab, __assign({}, rest, { ref: ref, onClick: handleTabClick, label: MoreIcon, value: DEFAULT_MORE_MENU_TAB_LABEL, "aria-haspopup": "true", "aria-controls": menuId, "data-tab-more-button": "" })),
59
58
  React.createElement(RcMenu, __assign({ autoClose: true }, MenuPropsRest, { id: menuId, anchorEl: anchorEl, open: open, variant: "menu", onClose: handleMenuClose }), MenuList)));
60
59
  });
61
60
  /** inner component */
@@ -0,0 +1,6 @@
1
+ import React, { forwardRef } from 'react';
2
+ export var MoreMenuTabSentinel = forwardRef(function (props, ref) {
3
+ var onFocus = props.onFocus, id = props.id;
4
+ return (React.createElement("div", { ref: ref, "aria-hidden": true, style: { position: 'absolute', top: 0, left: 0, height: 0, width: 0 }, tabIndex: -1, "data-tab-sentinel": id, onFocus: onFocus }));
5
+ });
6
+ MoreMenuTabSentinel.displayName = 'MoreMenuTabSentinel';
@@ -1,230 +1,309 @@
1
- import { __assign, __makeTemplateObject, __read, __rest, __spread } from "tslib";
2
- import React, { createRef, forwardRef, useEffect, useMemo, useRef, useState, } from 'react';
3
- import isEqual from 'lodash/isEqual';
1
+ import { __assign, __makeTemplateObject, __read, __rest, __spread, __values } from "tslib";
4
2
  import MuiTabs from '@material-ui/core/Tabs';
5
- import { styled, useForceUpdate, useForkRef, usePrevious, useResizeObserver, useThrottle, } from '../../../../foundation';
3
+ import React, { cloneElement, forwardRef, isValidElement, useEffect, useRef, useState, } from 'react';
4
+ import { getResizeObserver, styled, useForkRef, useMountState, useOnReRender, useThrottle, useRcPortalWindowContext, } from '../../../../foundation';
6
5
  import { DEFAULT_MORE_MENU_TAB_LABEL, MoreMenuTab, } from '../MoreMenuTab';
7
- import { computeChildBySize, DEFAULT_SIZE, getDomBoundingClientSize, getKey, parseKey, } from './utils';
8
- export var findChildrenByKey = function (childrenProp, key) {
9
- var children;
10
- React.Children.forEach(childrenProp, function (child, idx) {
11
- if (React.isValidElement(child)) {
12
- var keyString = typeof child.key === 'string' ? child.key : '';
13
- if (getKey(keyString, idx) === key) {
14
- children = child;
15
- }
6
+ import { MoreMenuTabSentinel } from './MoreMenuTabSentinel';
7
+ // with of more button with a icon
8
+ var basicMoreButtonSize = 44;
9
+ var getTabsInfoFromChildren = function (children) {
10
+ var childrenInfo = React.Children.map(children, function (child, index) {
11
+ var _a, _b;
12
+ if (isValidElement(child)) {
13
+ var key = (_a = child.key) !== null && _a !== void 0 ? _a : index;
14
+ return {
15
+ index: index,
16
+ key: key,
17
+ value: (_b = child.props.value) !== null && _b !== void 0 ? _b : key,
18
+ element: child,
19
+ };
16
20
  }
21
+ return null;
17
22
  });
18
- return children;
23
+ if (!childrenInfo)
24
+ return [];
25
+ return childrenInfo.filter(function (info) { return Boolean(info); });
19
26
  };
20
27
  var _MoreMenuTabs = forwardRef(function (props, ref) {
21
- var orientation = props.orientation, childrenProp = props.children, valueProp = props.value, onChange = props.onChange, _a = props.MoreButtonProps, MoreButtonProps = _a === void 0 ? {} : _a, _b = props.resizeThrottleTime, resizeThrottleTime = _b === void 0 ? 300 : _b, rest = __rest(props, ["orientation", "children", "value", "onChange", "MoreButtonProps", "resizeThrottleTime"]);
28
+ var orientation = props.orientation, childrenProp = props.children, value = props.value, onChange = props.onChange, _a = props.MoreButtonProps, MoreButtonProps = _a === void 0 ? {} : _a, _b = props.resizeThrottleTime, resizeThrottleTime = _b === void 0 ? 100 : _b, rest = __rest(props, ["orientation", "children", "value", "onChange", "MoreButtonProps", "resizeThrottleTime"]);
22
29
  var onGroupInfoChange = MoreButtonProps.onGroupInfoChange, MoreButtonPropsRest = __rest(MoreButtonProps, ["onGroupInfoChange"]);
23
- var prevChildrenProp = usePrevious(function () { return childrenProp; });
24
30
  var isVertical = orientation === 'vertical';
25
- var oriStr = isVertical ? 'height' : 'width';
31
+ var sizeKey = isVertical ? 'offsetHeight' : 'offsetWidth';
26
32
  var innerRef = useRef(null);
27
33
  var moreTabRef = useRef(null);
34
+ var sentinelStartRef = useRef(null);
28
35
  var tabsRef = useForkRef(innerRef, ref);
29
- var tabRefsMapRef = useRef();
30
- var moreTabSizeRef = useRef(DEFAULT_SIZE);
31
- var allTabsSizeRef = useRef(DEFAULT_SIZE);
32
- var tabsTabChildRef = useRef([]);
33
- var tabsSizeRef = useRef(DEFAULT_SIZE);
34
- var groupingRef = useRef();
35
- var _c = __read(useState([]), 2), menuTabChild = _c[0], setMenuTabChild = _c[1];
36
- var _d = __read(useState(true), 2), useMoreMode = _d[0], setUseMoreMode = _d[1];
37
- var hasResizeRef = useRef(true);
38
- var forceUpdate = useForceUpdate();
39
- var sizeChange = function (size) {
40
- hasResizeRef.current = true;
41
- if (tabsSizeRef.current.height !== size.height ||
42
- tabsSizeRef.current.width !== size.width) {
43
- tabsSizeRef.current = size;
44
- forceUpdate();
45
- }
46
- };
47
- var throttleTabsSizeChange = useThrottle(sizeChange, resizeThrottleTime);
48
- useResizeObserver(innerRef, function (_a) {
49
- var _b = __read(_a, 1), entry = _b[0];
50
- var _c = entry.contentRect, width = _c.width, height = _c.height;
51
- var obj = { width: width, height: height };
52
- throttleTabsSizeChange(obj);
53
- }, { mode: 'none' });
54
- var tabsSize = tabsSizeRef.current;
55
- // initial tabRefsMapRef and tabsTabChildRef
56
- if (tabRefsMapRef.current === undefined ||
57
- prevChildrenProp !== childrenProp) {
58
- var tabRefs_1 = new Map();
59
- var tabsTabDefaultChild_1 = [];
60
- React.Children.forEach(childrenProp, function (child, index) {
61
- var _a = child.props, ref = _a.ref, value = _a.value;
62
- var innerRef = createRef();
63
- var tabRef = ref ? useForkRef(innerRef, ref) : innerRef;
64
- var childrenValue = value || index;
65
- var children = React.cloneElement(child, {
66
- ref: tabRef,
67
- value: childrenValue,
68
- });
69
- var keyString = typeof child.key === 'string' ? child.key : '';
70
- tabRefs_1.set(getKey(keyString, index), {
71
- ref: tabRef,
72
- size: null,
73
- index: index,
74
- value: childrenValue,
75
- });
76
- tabsTabDefaultChild_1.push(children);
77
- });
78
- tabRefsMapRef.current = tabRefs_1;
79
- tabsTabChildRef.current = tabsTabDefaultChild_1;
80
- }
81
- var updateAllTabsSize = function () {
82
- var tabRefsMap = tabRefsMapRef.current;
83
- var allTabsSize = __assign({}, DEFAULT_SIZE);
84
- if (tabRefsMap && tabRefsMap.size !== 0) {
85
- tabRefsMap.forEach(function (value, key) {
86
- var _a = getDomBoundingClientSize(value.ref.current), width = _a.width, height = _a.height;
87
- allTabsSize.width += width;
88
- allTabsSize.height += height;
89
- var newRef = {
90
- ref: value.ref,
91
- size: { width: width, height: height },
92
- index: value.index,
93
- value: value.value,
94
- };
95
- tabRefsMap.set(key, newRef);
96
- });
97
- allTabsSizeRef.current = allTabsSize;
36
+ var _c = useRcPortalWindowContext().externalWindow, externalWindow = _c === void 0 ? window : _c;
37
+ var mountStateRef = useMountState();
38
+ var _d = __read(useState(function () {
39
+ var tabsInfo = getTabsInfoFromChildren(childrenProp);
40
+ if (!tabsInfo) {
41
+ return {
42
+ all: [],
43
+ tab: [],
44
+ menu: [],
45
+ };
98
46
  }
99
- return allTabsSize;
100
- };
101
- // get real render size when render
102
- useEffect(function () {
103
- if (childrenProp === prevChildrenProp) {
47
+ return {
48
+ all: tabsInfo,
49
+ tab: tabsInfo,
50
+ menu: [],
51
+ };
52
+ }), 2), groupInfo = _d[0], setGroupInfo = _d[1];
53
+ var throttleCalculateGroupInfo = useThrottle(function () {
54
+ var e_1, _a;
55
+ var _b;
56
+ var tablist = (_b = innerRef.current) === null || _b === void 0 ? void 0 : _b.querySelector('[role="tablist"]');
57
+ if (!tablist)
104
58
  return;
59
+ var allTabs = Array.from(tablist.children);
60
+ var allTabsSize = [];
61
+ var selectedIndex = groupInfo.all.findIndex(function (info) { return info.value === value; });
62
+ var tablistSize = tablist[sizeKey];
63
+ var moreButtonSize = basicMoreButtonSize;
64
+ var allTabsSizeSumWidthoutMoreButton = 0;
65
+ try {
66
+ for (var allTabs_1 = __values(allTabs), allTabs_1_1 = allTabs_1.next(); !allTabs_1_1.done; allTabs_1_1 = allTabs_1.next()) {
67
+ var tabEl = allTabs_1_1.value;
68
+ if (typeof tabEl.dataset['tabOriginIndex'] === 'string') {
69
+ var tabOriginIndex = Number(tabEl.dataset['tabOriginIndex']);
70
+ var elSize = tabEl[sizeKey];
71
+ allTabsSize[tabOriginIndex] = elSize;
72
+ allTabsSizeSumWidthoutMoreButton += elSize;
73
+ }
74
+ else if (typeof tabEl.dataset['tabMoreButton'] === 'string') {
75
+ var elSize = tabEl[sizeKey];
76
+ moreButtonSize = elSize;
77
+ }
78
+ }
105
79
  }
106
- updateAllTabsSize();
107
- var moreElm = moreTabRef === null || moreTabRef === void 0 ? void 0 : moreTabRef.current;
108
- if (moreElm) {
109
- var size = getDomBoundingClientSize(moreElm);
110
- moreTabSizeRef.current = size;
80
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
81
+ finally {
82
+ try {
83
+ if (allTabs_1_1 && !allTabs_1_1.done && (_a = allTabs_1.return)) _a.call(allTabs_1);
84
+ }
85
+ finally { if (e_1) throw e_1.error; }
111
86
  }
112
- }, [childrenProp, prevChildrenProp]);
113
- useEffect(function () {
114
- var _a;
115
- var currSelectTabItem;
116
- var tabRefsMap = tabRefsMapRef.current;
117
- if (tabRefsMap) {
118
- currSelectTabItem = __spread(tabRefsMap).find(function (_a) {
119
- var _b = __read(_a, 2), mapValue = _b[1];
120
- return valueProp === mapValue.value || valueProp === mapValue.index;
121
- });
87
+ var newGroupInfo = {
88
+ all: groupInfo.all,
89
+ tab: [],
90
+ menu: [],
91
+ };
92
+ if (allTabsSizeSumWidthoutMoreButton > tablistSize) {
93
+ var allTabsSizeSum = allTabsSizeSumWidthoutMoreButton + moreButtonSize;
94
+ var targetSize = allTabsSizeSum;
95
+ for (var i = allTabsSize.length - 1; i >= 0; i--) {
96
+ if (i !== selectedIndex) {
97
+ targetSize -= allTabsSize[i];
98
+ newGroupInfo.menu.unshift(groupInfo.all[i]);
99
+ if (targetSize <= tablistSize) {
100
+ break;
101
+ }
102
+ }
103
+ }
104
+ newGroupInfo.tab = groupInfo.all.filter(function (info) { return !newGroupInfo.menu.some(function (_a) {
105
+ var index = _a.index;
106
+ return index === info.index;
107
+ }); });
122
108
  }
123
- var computeGroupingInfo = function (tabsTabLabel, menuTabLabel) {
124
- var newGrouping = {
125
- tabs: tabsTabLabel,
126
- menu: menuTabLabel,
127
- };
128
- if (!isEqual(groupingRef.current, newGrouping)) {
129
- groupingRef.current = newGrouping;
130
- onGroupInfoChange === null || onGroupInfoChange === void 0 ? void 0 : onGroupInfoChange([
131
- tabsTabLabel.map(function (key) { return parseKey(key); }),
132
- menuTabLabel.map(function (key) { return parseKey(key); }),
133
- ]);
109
+ else {
110
+ newGroupInfo.tab = newGroupInfo.all;
111
+ }
112
+ var shouldUpdateGroupInfo = false;
113
+ if (newGroupInfo.tab.length === groupInfo.tab.length &&
114
+ newGroupInfo.tab.length === groupInfo.tab.length) {
115
+ for (var i = 0; i < groupInfo.tab.length; i++) {
116
+ if (newGroupInfo.tab[i] !== groupInfo.tab[i]) {
117
+ shouldUpdateGroupInfo = true;
118
+ break;
119
+ }
134
120
  }
135
- };
136
- var computeWhetherToUseMoreMode = function (tabsSize, allTabsSize) {
137
- if (tabsSize.width === 0 || tabsSize.height === 0) {
138
- return false;
121
+ }
122
+ else {
123
+ shouldUpdateGroupInfo = true;
124
+ }
125
+ if (shouldUpdateGroupInfo) {
126
+ // prevent resize observer loop limit exceeded
127
+ setTimeout(function () {
128
+ if (mountStateRef.current)
129
+ setGroupInfo(newGroupInfo);
130
+ }, 0);
131
+ }
132
+ }, resizeThrottleTime);
133
+ useEffect(function () {
134
+ var e_2, _a;
135
+ var _b;
136
+ var tablist = (_b = innerRef.current) === null || _b === void 0 ? void 0 : _b.querySelector('[role="tablist"]');
137
+ if (!tablist)
138
+ return;
139
+ var resizeObserver = getResizeObserver(throttleCalculateGroupInfo, externalWindow);
140
+ resizeObserver.observe(tablist);
141
+ try {
142
+ for (var _c = __values(Array.from(tablist.children)), _d = _c.next(); !_d.done; _d = _c.next()) {
143
+ var tabItem = _d.value;
144
+ resizeObserver.observe(tabItem,
145
+ // TODO: remove this, after remove ResizeObserver polyfill
146
+ // @ts-ignore
147
+ { box: 'border-box' });
139
148
  }
140
- if (allTabsSize.width === 0 || allTabsSize.height === 0) {
141
- allTabsSize = updateAllTabsSize();
149
+ }
150
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
151
+ finally {
152
+ try {
153
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
142
154
  }
143
- if (!isVertical) {
144
- return allTabsSize.width > tabsSize.width;
155
+ finally { if (e_2) throw e_2.error; }
156
+ }
157
+ var mutationObserver = new externalWindow.MutationObserver(function (mutations) {
158
+ var e_3, _a;
159
+ try {
160
+ for (var mutations_1 = __values(mutations), mutations_1_1 = mutations_1.next(); !mutations_1_1.done; mutations_1_1 = mutations_1.next()) {
161
+ var mutation = mutations_1_1.value;
162
+ if (mutation.type === 'childList') {
163
+ mutation.removedNodes.forEach(function (removedNode) {
164
+ if (removedNode.getAttribute('role') === 'tab') {
165
+ resizeObserver.unobserve(removedNode);
166
+ }
167
+ });
168
+ mutation.addedNodes.forEach(function (addedNode) {
169
+ if (addedNode.getAttribute('role') === 'tab') {
170
+ resizeObserver.observe(addedNode,
171
+ // TODO: remove this, after remove ResizeObserver polyfill
172
+ // @ts-ignore
173
+ { box: 'border-box' });
174
+ }
175
+ });
176
+ // should re-calculate group info when dom is removed and not added
177
+ if (mutation.removedNodes.length && !mutation.addedNodes.length) {
178
+ setTimeout(function () {
179
+ if (mountStateRef.current)
180
+ throttleCalculateGroupInfo();
181
+ }, 0);
182
+ }
183
+ }
184
+ }
145
185
  }
146
- return allTabsSize.height > tabsSize.height;
147
- };
148
- var computedMoreModeChild = function (tabRefsMap) {
149
- var labelArray = [];
150
- tabRefsMap.forEach(function (value, key) {
151
- labelArray.push({
152
- key: key,
153
- size: value.size ? value.size[oriStr] : 0,
154
- });
155
- });
156
- var limitSize = tabsSizeRef.current[oriStr] - moreTabSizeRef.current[oriStr];
157
- var _a = computeChildBySize(labelArray, currSelectTabItem === null || currSelectTabItem === void 0 ? void 0 : currSelectTabItem[0], limitSize), tabsTabLabel = _a.plainArr, menuTabLabel = _a.groupArr;
158
- computeGroupingInfo(tabsTabLabel, menuTabLabel);
159
- var tabsTabChild = tabsTabLabel.map(function (key) {
160
- return findChildrenByKey(childrenProp, key);
161
- });
162
- var menuTabChild = menuTabLabel.map(function (key) {
163
- return findChildrenByKey(childrenProp, key);
164
- });
165
- tabsTabChildRef.current = tabsTabChild;
166
- setMenuTabChild(menuTabChild);
186
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
187
+ finally {
188
+ try {
189
+ if (mutations_1_1 && !mutations_1_1.done && (_a = mutations_1.return)) _a.call(mutations_1);
190
+ }
191
+ finally { if (e_3) throw e_3.error; }
192
+ }
193
+ });
194
+ mutationObserver.observe(tablist, {
195
+ childList: true,
196
+ });
197
+ return function () {
198
+ resizeObserver.disconnect();
199
+ mutationObserver.disconnect();
167
200
  };
168
- var computedStandardModeChild = function (tabRefsMap) {
169
- var tabsTabLabel = [];
170
- tabRefsMap.forEach(function (value, key) {
171
- tabsTabLabel.push(key);
172
- });
173
- computeGroupingInfo(tabsTabLabel, []);
174
- var tabsTabChild = tabsTabLabel.map(function (key) {
175
- return findChildrenByKey(childrenProp, key);
176
- });
177
- tabsTabChildRef.current = tabsTabChild;
178
- setMenuTabChild([]);
201
+ // eslint-disable-next-line react-hooks/exhaustive-deps
202
+ }, []);
203
+ // No need calculate during the first rendering,
204
+ // resize observer will do this
205
+ useOnReRender(function () {
206
+ throttleCalculateGroupInfo();
207
+ }, [value], false);
208
+ useOnReRender(function () {
209
+ var e_4, _a;
210
+ var tabsInfo = getTabsInfoFromChildren(childrenProp);
211
+ var newGroupInfo = {
212
+ all: tabsInfo,
213
+ tab: [],
214
+ menu: [],
179
215
  };
180
- var computeTabChild = function (tabsSize) {
181
- var useMoreMode = computeWhetherToUseMoreMode(tabsSize, allTabsSizeRef.current);
182
- setUseMoreMode(useMoreMode);
183
- if (tabRefsMap) {
184
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
185
- useMoreMode
186
- ? computedMoreModeChild(tabRefsMap)
187
- : computedStandardModeChild(tabRefsMap);
216
+ var _loop_1 = function (tabInfo) {
217
+ if (groupInfo.tab.some(function (_a) {
218
+ var key = _a.key;
219
+ return tabInfo.key === key;
220
+ })) {
221
+ newGroupInfo.tab.push(tabInfo);
222
+ }
223
+ else {
224
+ // push new tab or invisible old tab to menu group
225
+ newGroupInfo.menu.push(tabInfo);
188
226
  }
189
227
  };
190
- if (tabsSizeRef.current.width !== 0 && tabsSizeRef.current.height !== 0) {
191
- // computed: 1.resize 2. valueProp 3.moreMenuClick 4.children change
192
- // not computed: visible tab change
193
- if (((_a = groupingRef.current) === null || _a === void 0 ? void 0 : _a.tabs.includes((currSelectTabItem === null || currSelectTabItem === void 0 ? void 0 : currSelectTabItem[0]) || '')) &&
194
- !hasResizeRef.current &&
195
- prevChildrenProp === childrenProp) {
196
- return;
228
+ try {
229
+ // Prevent moreButton from flickering after children update
230
+ for (var tabsInfo_1 = __values(tabsInfo), tabsInfo_1_1 = tabsInfo_1.next(); !tabsInfo_1_1.done; tabsInfo_1_1 = tabsInfo_1.next()) {
231
+ var tabInfo = tabsInfo_1_1.value;
232
+ _loop_1(tabInfo);
197
233
  }
198
- // can't use tabsSize
199
- // It is possible that the children prop render effect will execute before the sizeChange effect
200
- // which get a old tabsSize value
201
- computeTabChild(tabsSizeRef.current);
202
- hasResizeRef.current = false;
203
234
  }
204
- }, [
205
- childrenProp,
206
- prevChildrenProp,
207
- isVertical,
208
- onGroupInfoChange,
209
- oriStr,
210
- tabsSize,
211
- valueProp,
212
- ]);
213
- var MoreMenuTabCmp = useMemo(function () {
214
- var menuItems = React.Children.map(menuTabChild, function (child) {
215
- return __assign({}, child.props);
235
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
236
+ finally {
237
+ try {
238
+ if (tabsInfo_1_1 && !tabsInfo_1_1.done && (_a = tabsInfo_1.return)) _a.call(tabsInfo_1);
239
+ }
240
+ finally { if (e_4) throw e_4.error; }
241
+ }
242
+ setGroupInfo(newGroupInfo);
243
+ }, [childrenProp], false);
244
+ useEffect(function () {
245
+ onGroupInfoChange === null || onGroupInfoChange === void 0 ? void 0 : onGroupInfoChange([
246
+ groupInfo.tab.map(function (_a) {
247
+ var index = _a.index, key = _a.key;
248
+ return ({ index: index, key: key });
249
+ }),
250
+ groupInfo.menu.map(function (_a) {
251
+ var index = _a.index, key = _a.key;
252
+ return ({ index: index, key: key });
253
+ }),
254
+ ]);
255
+ // eslint-disable-next-line react-hooks/exhaustive-deps
256
+ }, [groupInfo]); // ignore onGroupInfoChange
257
+ var useMoreMode = groupInfo.menu.length > 0;
258
+ var MoreMenuTabCmp = (function () {
259
+ if (!useMoreMode)
260
+ return null;
261
+ var menuItems = groupInfo.menu.map(function (_a) {
262
+ var key = _a.key, element = _a.element;
263
+ return __assign(__assign({}, element.props), { key: key });
216
264
  });
217
265
  return useMoreMode ? (React.createElement(MoreMenuTab, __assign({}, MoreButtonPropsRest, { key: DEFAULT_MORE_MENU_TAB_LABEL, size: rest.size, menuItems: menuItems, ref: moreTabRef, onChange: onChange, orientation: orientation }))) : null;
218
- }, [
219
- MoreButtonPropsRest,
220
- menuTabChild,
221
- onChange,
222
- orientation,
223
- rest.size,
224
- useMoreMode,
225
- ]);
226
- return (React.createElement(MuiTabs, __assign({}, rest, { ref: tabsRef, value: valueProp, variant: "standard", indicatorColor: "primary", textColor: "primary", onChange: onChange, orientation: orientation }),
227
- tabsTabChildRef.current,
266
+ })();
267
+ var children = (function () {
268
+ var tabGroupElements = groupInfo.tab.map(function (_a) {
269
+ var index = _a.index, key = _a.key, tabValue = _a.value, element = _a.element;
270
+ return cloneElement(element, {
271
+ key: key,
272
+ value: tabValue,
273
+ 'data-tab-origin-index': index,
274
+ 'data-tab-key': key,
275
+ });
276
+ });
277
+ if (!useMoreMode)
278
+ return tabGroupElements;
279
+ return __spread(tabGroupElements, [
280
+ React.createElement(MoreMenuTabSentinel, { id: "start", value: "sentinel-start", key: "sentinel-start", ref: sentinelStartRef, onFocus: function () {
281
+ var _a;
282
+ (_a = moreTabRef.current) === null || _a === void 0 ? void 0 : _a.focus();
283
+ } })
284
+ ], groupInfo.menu.map(function (_a) {
285
+ var index = _a.index, key = _a.key, tabValue = _a.value, element = _a.element;
286
+ return cloneElement(element, {
287
+ key: key,
288
+ value: tabValue,
289
+ 'data-tab-origin-index': index,
290
+ 'data-tab-key': key,
291
+ 'aria-hidden': true,
292
+ disabled: true,
293
+ style: __assign(__assign({}, element.props.style), { opacity: 0, position: 'absolute', top: 0, left: 0 }),
294
+ });
295
+ }), [
296
+ React.createElement(MoreMenuTabSentinel, { id: "end", value: "sentinel-end", key: "sentinel-end", onFocus: function () {
297
+ var _a;
298
+ var focusTarget = ((_a = sentinelStartRef.current) === null || _a === void 0 ? void 0 : _a.previousElementSibling) ||
299
+ moreTabRef.current;
300
+ if (focusTarget)
301
+ focusTarget.focus();
302
+ } }),
303
+ ]);
304
+ })();
305
+ return (React.createElement(MuiTabs, __assign({}, rest, { ref: tabsRef, value: value, variant: "standard", indicatorColor: "primary", textColor: "primary", onChange: onChange, orientation: orientation }),
306
+ children,
228
307
  MoreMenuTabCmp));
229
308
  });
230
309
  /** inner component */