@ringcentral/juno 2.31.0-hotfix.5 → 2.31.0-hotfix.6

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.
@@ -1,230 +1,310 @@
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, } 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 mountStateRef = useMountState();
37
+ var _c = __read(useState(function () {
38
+ var tabsInfo = getTabsInfoFromChildren(childrenProp);
39
+ if (!tabsInfo) {
40
+ return {
41
+ all: [],
42
+ tab: [],
43
+ menu: [],
44
+ };
98
45
  }
99
- return allTabsSize;
100
- };
101
- // get real render size when render
102
- useEffect(function () {
103
- if (childrenProp === prevChildrenProp) {
46
+ return {
47
+ all: tabsInfo,
48
+ tab: tabsInfo,
49
+ menu: [],
50
+ };
51
+ }), 2), groupInfo = _c[0], setGroupInfo = _c[1];
52
+ var throttleCalculateGroupInfo = useThrottle(function () {
53
+ var e_1, _a;
54
+ var _b;
55
+ var tablist = (_b = innerRef.current) === null || _b === void 0 ? void 0 : _b.querySelector('[role="tablist"]');
56
+ if (!tablist)
104
57
  return;
58
+ var allTabs = Array.from(tablist.children);
59
+ var allTabsSize = [];
60
+ var selectedIndex = groupInfo.all.findIndex(function (info) { return info.value === value; });
61
+ var tablistSize = tablist[sizeKey];
62
+ var moreButtonSize = basicMoreButtonSize;
63
+ var allTabsSizeSumWidthoutMoreButton = 0;
64
+ try {
65
+ for (var allTabs_1 = __values(allTabs), allTabs_1_1 = allTabs_1.next(); !allTabs_1_1.done; allTabs_1_1 = allTabs_1.next()) {
66
+ var tabEl = allTabs_1_1.value;
67
+ if (tabEl instanceof HTMLElement) {
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
+ }
79
+ }
105
80
  }
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;
81
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
82
+ finally {
83
+ try {
84
+ if (allTabs_1_1 && !allTabs_1_1.done && (_a = allTabs_1.return)) _a.call(allTabs_1);
85
+ }
86
+ finally { if (e_1) throw e_1.error; }
111
87
  }
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
- });
88
+ var newGroupInfo = {
89
+ all: groupInfo.all,
90
+ tab: [],
91
+ menu: [],
92
+ };
93
+ if (allTabsSizeSumWidthoutMoreButton > tablistSize) {
94
+ var allTabsSizeSum = allTabsSizeSumWidthoutMoreButton + moreButtonSize;
95
+ var targetSize = allTabsSizeSum;
96
+ for (var i = allTabsSize.length - 1; i >= 0; i--) {
97
+ if (i !== selectedIndex) {
98
+ targetSize -= allTabsSize[i];
99
+ newGroupInfo.menu.unshift(groupInfo.all[i]);
100
+ if (targetSize <= tablistSize) {
101
+ break;
102
+ }
103
+ }
104
+ }
105
+ newGroupInfo.tab = groupInfo.all.filter(function (info) { return !newGroupInfo.menu.some(function (_a) {
106
+ var index = _a.index;
107
+ return index === info.index;
108
+ }); });
122
109
  }
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
- ]);
110
+ else {
111
+ newGroupInfo.tab = newGroupInfo.all;
112
+ }
113
+ var shouldUpdateGroupInfo = false;
114
+ if (newGroupInfo.tab.length === groupInfo.tab.length &&
115
+ newGroupInfo.tab.length === groupInfo.tab.length) {
116
+ for (var i = 0; i < groupInfo.tab.length; i++) {
117
+ if (newGroupInfo.tab[i] !== groupInfo.tab[i]) {
118
+ shouldUpdateGroupInfo = true;
119
+ break;
120
+ }
134
121
  }
135
- };
136
- var computeWhetherToUseMoreMode = function (tabsSize, allTabsSize) {
137
- if (tabsSize.width === 0 || tabsSize.height === 0) {
138
- return false;
122
+ }
123
+ else {
124
+ shouldUpdateGroupInfo = true;
125
+ }
126
+ if (shouldUpdateGroupInfo) {
127
+ // prevent resize observer loop limit exceeded
128
+ setTimeout(function () {
129
+ if (mountStateRef.current)
130
+ setGroupInfo(newGroupInfo);
131
+ }, 0);
132
+ }
133
+ }, resizeThrottleTime);
134
+ useEffect(function () {
135
+ var e_2, _a;
136
+ var _b;
137
+ var tablist = (_b = innerRef.current) === null || _b === void 0 ? void 0 : _b.querySelector('[role="tablist"]');
138
+ if (!tablist)
139
+ return;
140
+ var resizeObserver = getResizeObserver(throttleCalculateGroupInfo);
141
+ resizeObserver.observe(tablist);
142
+ try {
143
+ for (var _c = __values(Array.from(tablist.children)), _d = _c.next(); !_d.done; _d = _c.next()) {
144
+ var tabItem = _d.value;
145
+ resizeObserver.observe(tabItem,
146
+ // TODO: remove this, after remove ResizeObserver polyfill
147
+ // @ts-ignore
148
+ { box: 'border-box' });
139
149
  }
140
- if (allTabsSize.width === 0 || allTabsSize.height === 0) {
141
- allTabsSize = updateAllTabsSize();
150
+ }
151
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
152
+ finally {
153
+ try {
154
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
142
155
  }
143
- if (!isVertical) {
144
- return allTabsSize.width > tabsSize.width;
156
+ finally { if (e_2) throw e_2.error; }
157
+ }
158
+ var mutationObserver = new MutationObserver(function (mutations) {
159
+ var e_3, _a;
160
+ try {
161
+ for (var mutations_1 = __values(mutations), mutations_1_1 = mutations_1.next(); !mutations_1_1.done; mutations_1_1 = mutations_1.next()) {
162
+ var mutation = mutations_1_1.value;
163
+ if (mutation.type === 'childList') {
164
+ mutation.removedNodes.forEach(function (removedNode) {
165
+ if (removedNode instanceof Element) {
166
+ resizeObserver.unobserve(removedNode);
167
+ }
168
+ });
169
+ mutation.addedNodes.forEach(function (addedNode) {
170
+ if (addedNode instanceof Element) {
171
+ resizeObserver.observe(addedNode,
172
+ // TODO: remove this, after remove ResizeObserver polyfill
173
+ // @ts-ignore
174
+ { box: 'border-box' });
175
+ }
176
+ });
177
+ // should re-calculate group info when dom is removed and not added
178
+ if (mutation.removedNodes.length && !mutation.addedNodes.length) {
179
+ setTimeout(function () {
180
+ if (mountStateRef.current)
181
+ throttleCalculateGroupInfo();
182
+ }, 0);
183
+ }
184
+ }
185
+ }
145
186
  }
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);
187
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
188
+ finally {
189
+ try {
190
+ if (mutations_1_1 && !mutations_1_1.done && (_a = mutations_1.return)) _a.call(mutations_1);
191
+ }
192
+ finally { if (e_3) throw e_3.error; }
193
+ }
194
+ });
195
+ mutationObserver.observe(tablist, {
196
+ childList: true,
197
+ });
198
+ return function () {
199
+ resizeObserver.disconnect();
200
+ mutationObserver.disconnect();
167
201
  };
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([]);
202
+ // eslint-disable-next-line react-hooks/exhaustive-deps
203
+ }, []);
204
+ // No need calculate during the first rendering,
205
+ // resize observer will do this
206
+ useOnReRender(function () {
207
+ throttleCalculateGroupInfo();
208
+ }, [value], false);
209
+ useOnReRender(function () {
210
+ var e_4, _a;
211
+ var tabsInfo = getTabsInfoFromChildren(childrenProp);
212
+ var newGroupInfo = {
213
+ all: tabsInfo,
214
+ tab: [],
215
+ menu: [],
179
216
  };
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);
217
+ var _loop_1 = function (tabInfo) {
218
+ if (groupInfo.tab.some(function (_a) {
219
+ var key = _a.key;
220
+ return tabInfo.key === key;
221
+ })) {
222
+ newGroupInfo.tab.push(tabInfo);
223
+ }
224
+ else {
225
+ // push new tab or invisible old tab to menu group
226
+ newGroupInfo.menu.push(tabInfo);
188
227
  }
189
228
  };
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;
229
+ try {
230
+ // Prevent moreButton from flickering after children update
231
+ for (var tabsInfo_1 = __values(tabsInfo), tabsInfo_1_1 = tabsInfo_1.next(); !tabsInfo_1_1.done; tabsInfo_1_1 = tabsInfo_1.next()) {
232
+ var tabInfo = tabsInfo_1_1.value;
233
+ _loop_1(tabInfo);
197
234
  }
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
235
  }
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);
236
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
237
+ finally {
238
+ try {
239
+ if (tabsInfo_1_1 && !tabsInfo_1_1.done && (_a = tabsInfo_1.return)) _a.call(tabsInfo_1);
240
+ }
241
+ finally { if (e_4) throw e_4.error; }
242
+ }
243
+ setGroupInfo(newGroupInfo);
244
+ }, [childrenProp], false);
245
+ useEffect(function () {
246
+ onGroupInfoChange === null || onGroupInfoChange === void 0 ? void 0 : onGroupInfoChange([
247
+ groupInfo.tab.map(function (_a) {
248
+ var index = _a.index, key = _a.key;
249
+ return ({ index: index, key: key });
250
+ }),
251
+ groupInfo.menu.map(function (_a) {
252
+ var index = _a.index, key = _a.key;
253
+ return ({ index: index, key: key });
254
+ }),
255
+ ]);
256
+ // eslint-disable-next-line react-hooks/exhaustive-deps
257
+ }, [groupInfo]); // ignore onGroupInfoChange
258
+ var useMoreMode = groupInfo.menu.length > 0;
259
+ var MoreMenuTabCmp = (function () {
260
+ if (!useMoreMode)
261
+ return null;
262
+ var menuItems = groupInfo.menu.map(function (_a) {
263
+ var key = _a.key, element = _a.element;
264
+ return __assign(__assign({}, element.props), { key: key });
216
265
  });
217
266
  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,
267
+ })();
268
+ var children = (function () {
269
+ var tabGroupElements = groupInfo.tab.map(function (_a) {
270
+ var index = _a.index, key = _a.key, tabValue = _a.value, element = _a.element;
271
+ return cloneElement(element, {
272
+ key: key,
273
+ value: tabValue,
274
+ 'data-tab-origin-index': index,
275
+ 'data-tab-key': key,
276
+ });
277
+ });
278
+ if (!useMoreMode)
279
+ return tabGroupElements;
280
+ return __spread(tabGroupElements, [
281
+ React.createElement(MoreMenuTabSentinel, { id: "start", value: "sentinel-start", key: "sentinel-start", ref: sentinelStartRef, onFocus: function () {
282
+ var _a;
283
+ (_a = moreTabRef.current) === null || _a === void 0 ? void 0 : _a.focus();
284
+ } })
285
+ ], groupInfo.menu.map(function (_a) {
286
+ var index = _a.index, key = _a.key, tabValue = _a.value, element = _a.element;
287
+ return cloneElement(element, {
288
+ key: key,
289
+ value: tabValue,
290
+ 'data-tab-origin-index': index,
291
+ 'data-tab-key': key,
292
+ 'aria-hidden': true,
293
+ disabled: true,
294
+ style: __assign(__assign({}, element.props.style), { opacity: 0, position: 'absolute', top: 0, left: 0 }),
295
+ });
296
+ }), [
297
+ React.createElement(MoreMenuTabSentinel, { id: "end", value: "sentinel-end", key: "sentinel-end", onFocus: function () {
298
+ var _a;
299
+ var focusTarget = ((_a = sentinelStartRef.current) === null || _a === void 0 ? void 0 : _a.previousElementSibling) ||
300
+ moreTabRef.current;
301
+ if (focusTarget)
302
+ focusTarget.focus();
303
+ } }),
304
+ ]);
305
+ })();
306
+ return (React.createElement(MuiTabs, __assign({}, rest, { ref: tabsRef, value: value, variant: "standard", indicatorColor: "primary", textColor: "primary", onChange: onChange, orientation: orientation }),
307
+ children,
228
308
  MoreMenuTabCmp));
229
309
  });
230
310
  /** inner component */
@@ -1,87 +0,0 @@
1
- export var DEFAULT_SIZE = {
2
- width: 0,
3
- height: 0,
4
- };
5
- export var computeChildBySize = function (labelArray, fixLabel, limitSize) {
6
- var plainArr = [];
7
- var groupArr = [];
8
- var sumSize = 0;
9
- var groupFlag = false;
10
- labelArray.forEach(function (_label) {
11
- var label = _label.key, size = _label.size;
12
- if (groupFlag === false && sumSize + size < limitSize) {
13
- sumSize += size;
14
- plainArr.push(label);
15
- }
16
- else {
17
- groupFlag = true;
18
- groupArr.push(label);
19
- }
20
- });
21
- if (fixLabel && groupArr.includes(fixLabel)) {
22
- plainArr = [];
23
- groupArr = [];
24
- var fixLabelSize_1 = 0;
25
- labelArray.forEach(function (_label) {
26
- var label = _label.key, size = _label.size;
27
- if (label === fixLabel) {
28
- fixLabelSize_1 = size;
29
- }
30
- });
31
- var sumFixSize_1 = 0;
32
- var groupFlag_1 = false;
33
- labelArray.forEach(function (_label) {
34
- var label = _label.key, size = _label.size;
35
- if (label === fixLabel) {
36
- return;
37
- }
38
- if (groupFlag_1 === false && sumFixSize_1 + size < limitSize - fixLabelSize_1) {
39
- sumFixSize_1 += size;
40
- plainArr.push(label);
41
- }
42
- else {
43
- groupFlag_1 = true;
44
- groupArr.push(label);
45
- }
46
- });
47
- plainArr.push(fixLabel);
48
- }
49
- return {
50
- plainArr: plainArr,
51
- groupArr: groupArr,
52
- };
53
- };
54
- export var getDomBoundingClientSize = function (dom) {
55
- if (!dom || dom.nodeType !== 1) {
56
- return DEFAULT_SIZE;
57
- }
58
- var _a = dom.getBoundingClientRect(), width = _a.width, height = _a.height;
59
- return {
60
- width: width,
61
- height: height,
62
- };
63
- };
64
- /**
65
- *
66
- * @param keyProp React.key
67
- * @param idx string
68
- * @example
69
- * getKey('tab_0', 0) => childIdx_0_propKey_tab_0
70
- * getKey(undefined, 1) => childIdx_1
71
- */
72
- export var getKey = function (keyProp, idx) {
73
- return "childIdx_" + idx + (keyProp ? "_propKey_" + keyProp : '');
74
- };
75
- /**
76
- *
77
- * @example
78
- * parseKey(childIdx_1) => { index: 1 }
79
- * parseKey(childIdx_1_propKey_tab_1) => { index: 1, key: tab_1 }
80
- */
81
- export var parseKey = function (key) {
82
- var match = /^(?:childIdx_)(\d+)(?:_propKey_)?(.*)/gi.exec(key);
83
- return {
84
- index: match === null || match === void 0 ? void 0 : match[1],
85
- key: match === null || match === void 0 ? void 0 : match[2].replace(/^\.\$/i, ''),
86
- };
87
- };
@@ -1 +0,0 @@
1
- export * from './MoreMenuTabsUtils';
@@ -1,12 +1,15 @@
1
- import { useLayoutEffect, useRef } from 'react';
1
+ import { useLayoutEffect, useRef, useEffect } from 'react';
2
2
  import { useEventCallback } from '../useEventCallback';
3
3
  /**
4
4
  * only trigger when re-render, not trigger on component first render
5
5
  */
6
- export var useOnReRender = function (cb, deps) {
6
+ export var useOnReRender = function (cb, deps, isLayout) {
7
+ if (isLayout === void 0) { isLayout = true; }
7
8
  var count = useRef(0);
8
9
  var method = useEventCallback(cb);
9
- useLayoutEffect(function () {
10
+ var isLayoutRef = useRef(isLayout);
11
+ var useTargetEffect = isLayoutRef.current ? useLayoutEffect : useEffect;
12
+ useTargetEffect(function () {
10
13
  if (count.current === 0) {
11
14
  count.current = 1;
12
15
  return function () { };
@@ -2,4 +2,4 @@ import { DependencyList } from 'react';
2
2
  /**
3
3
  * only trigger when re-render, not trigger on component first render
4
4
  */
5
- export declare const useOnReRender: (cb: () => any, deps?: DependencyList | undefined) => void;
5
+ export declare const useOnReRender: (cb: () => any, deps?: DependencyList | undefined, isLayout?: boolean) => void;
@@ -5,10 +5,13 @@ var useEventCallback_1 = require("../useEventCallback");
5
5
  /**
6
6
  * only trigger when re-render, not trigger on component first render
7
7
  */
8
- exports.useOnReRender = function (cb, deps) {
8
+ exports.useOnReRender = function (cb, deps, isLayout) {
9
+ if (isLayout === void 0) { isLayout = true; }
9
10
  var count = react_1.useRef(0);
10
11
  var method = useEventCallback_1.useEventCallback(cb);
11
- react_1.useLayoutEffect(function () {
12
+ var isLayoutRef = react_1.useRef(isLayout);
13
+ var useTargetEffect = isLayoutRef.current ? react_1.useLayoutEffect : react_1.useEffect;
14
+ useTargetEffect(function () {
12
15
  if (count.current === 0) {
13
16
  count.current = 1;
14
17
  return function () { };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ringcentral/juno",
3
- "version": "2.31.0-hotfix.5",
3
+ "version": "2.31.0-hotfix.6",
4
4
  "author": "RingCentral",
5
5
  "license": "MIT",
6
6
  "main": "./index.js",