Repository URL to install this package:
|
Version:
3.12.16 ▾
|
var _excluded = ["height"];
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
export var getLayoutInfo = function getLayoutInfo(gridContainer, scrollableParent, columnMinWidth) {
if (!gridContainer || !scrollableParent) return {};
var _gridContainer$getBou = gridContainer.getBoundingClientRect(),
width = _gridContainer$getBou.width;
var _gridContainer$firstC = gridContainer.firstChild,
firstChild = _gridContainer$firstC === void 0 ? {} : _gridContainer$firstC;
var _ref = (firstChild === null || firstChild === void 0 ? void 0 : firstChild.getBoundingClientRect()) || {},
elementHeight = _ref.height,
boundingRect = _objectWithoutProperties(_ref, _excluded);
var elementWidth = boundingRect.width || columnMinWidth;
var _window$getComputedSt = window.getComputedStyle(gridContainer),
rowGap = _window$getComputedSt.rowGap,
columnGap = _window$getComputedSt.columnGap;
rowGap = parseFloat(rowGap) || 0;
columnGap = parseFloat(columnGap) || 0;
var visibleHeight = scrollableParent.clientHeight;
// We are adding the row/column gap to the height/width, cause the gaps are applied for the rows/columns' count - 1
// if we didn't add the gap to the height/width, the equation's result won't be accurate as there is additional pixels (for additional un-rendered gap) considered
// So we are considering removing that additional pixels by adding the gap to the height/width and in that case it will be removed after dividing by the element's height/width + gap
// Summary: grid N elements have N-1 gaps, adding the gap to the element's height/width will add additional gap in the calculations but it is not added in the DOM, we're removing that by adding the gap to the container's height/width
var rowsCount = Math.floor((visibleHeight + rowGap) / (elementHeight + rowGap)) || 1;
var columnsCount = Math.floor((width + columnGap) / (elementWidth + columnGap)) || 1;
return {
elementWidth: elementWidth,
elementHeight: elementHeight,
columnsCount: columnsCount,
rowsCount: rowsCount,
rowGap: rowGap,
columnGap: columnGap
};
};
export var defaultGetItemKey = function defaultGetItemKey(item, index) {
return (_typeof(item) === 'object' ? item.uuid || item.id : item) || index;
};