amis-rpc-design/node_modules/rc-tabs/lib/hooks/useVisibleRange.js
2023-10-07 19:42:30 +08:00

56 lines
1.6 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = useVisibleRange;
var _react = require("react");
var DEFAULT_SIZE = {
width: 0,
height: 0,
left: 0,
top: 0,
right: 0
};
function useVisibleRange(tabOffsets, visibleTabContentValue, transform, tabContentSizeValue, addNodeSizeValue, operationNodeSizeValue, _ref) {
var tabs = _ref.tabs,
tabPosition = _ref.tabPosition,
rtl = _ref.rtl;
var charUnit;
var position;
var transformSize;
if (['top', 'bottom'].includes(tabPosition)) {
charUnit = 'width';
position = rtl ? 'right' : 'left';
transformSize = Math.abs(transform);
} else {
charUnit = 'height';
position = 'top';
transformSize = -transform;
}
return (0, _react.useMemo)(function () {
if (!tabs.length) {
return [0, 0];
}
var len = tabs.length;
var endIndex = len;
for (var i = 0; i < len; i += 1) {
var offset = tabOffsets.get(tabs[i].key) || DEFAULT_SIZE;
if (offset[position] + offset[charUnit] > transformSize + visibleTabContentValue) {
endIndex = i - 1;
break;
}
}
var startIndex = 0;
for (var _i = len - 1; _i >= 0; _i -= 1) {
var _offset = tabOffsets.get(tabs[_i].key) || DEFAULT_SIZE;
if (_offset[position] < transformSize) {
startIndex = _i + 1;
break;
}
}
return startIndex >= endIndex ? [0, 0] : [startIndex, endIndex];
}, [tabOffsets, visibleTabContentValue, tabContentSizeValue, addNodeSizeValue, operationNodeSizeValue, transformSize, tabPosition, tabs.map(function (tab) {
return tab.key;
}).join('_'), rtl]);
}