UNPKG

@integec/grid-tools

Version:
97 lines (80 loc) 3.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _min2 = _interopRequireDefault(require("ramda/src/min")); var _isNil2 = _interopRequireDefault(require("ramda/src/isNil")); var _takeWhile2 = _interopRequireDefault(require("ramda/src/takeWhile")); var _compose2 = _interopRequireDefault(require("ramda/src/compose")); var _drop2 = _interopRequireDefault(require("ramda/src/drop")); var _take2 = _interopRequireDefault(require("ramda/src/take")); var _utils = require("./utils"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } var splitFixedCols = function splitFixedCols(numOfFixedCols, headers) { return { rowHeaders: (0, _take2["default"])(numOfFixedCols, headers), dataHeaders: (0, _drop2["default"])(numOfFixedCols, headers) }; }; var countKeyCols = (0, _compose2["default"])(function (l) { return l.length; }, (0, _takeWhile2["default"])(function (h) { return h.isKey; })); var computeGridViewProps = function computeGridViewProps(_ref) { var headers = _ref.headers, data = _ref.data, rowHeight = _ref.rowHeight, width = _ref.width, height = _ref.height, _ref$scrollBarWidthAd = _ref.scrollBarWidthAdjustment, scrollBarWidthAdjustment = _ref$scrollBarWidthAd === void 0 ? 17 : _ref$scrollBarWidthAd, _ref$scrollBarHeightA = _ref.scrollBarHeightAdjustment, scrollBarHeightAdjustment = _ref$scrollBarHeightA === void 0 ? 17 : _ref$scrollBarHeightA, _ref$borderSize = _ref.borderSize, borderSize = _ref$borderSize === void 0 ? 1 : _ref$borderSize, fixedColCount = _ref.fixedColCount, autoFixColByKey = _ref.autoFixColByKey, headerRowHeight = _ref.headerRowHeight, hasPaging = _ref.hasPaging, pagerHeight = _ref.pagerHeight; var rawDataWidth = (0, _utils.sumWidth)(headers); var rawDataHeight = (0, _utils.sumHeight)({ data: data, rowHeight: rowHeight }); var normalizedWidth = (0, _isNil2["default"])(width) ? rawDataWidth : (0, _min2["default"])(width, rawDataWidth); /* do not scroll when we can fit everything */ var scroll = width && height && headerRowHeight && (width < rawDataWidth || height < rawDataHeight); var scrollX = scroll && width < rawDataWidth; var scrollY = scroll && height < rawDataHeight; var numOfFixedCols = !scrollX ? 0 : autoFixColByKey ? countKeyCols(headers) : fixedColCount; var _splitFixedCols = splitFixedCols(numOfFixedCols, headers), rowHeaders = _splitFixedCols.rowHeaders, dataHeaders = _splitFixedCols.dataHeaders; var containerWidth = normalizedWidth + (headers.length - 1) * borderSize + (scrollY ? scrollBarWidthAdjustment : 0); var scrollPaneHeight = numOfFixedCols > 0 && scrollX ? height + 5 + scrollBarHeightAdjustment : height + 5; var fixedPaneHeight = height; // TODO: min of rawDataHeight or specified width var containerHeight = (0, _isNil2["default"])(height) ? undefined : height + (scroll ? scrollBarHeightAdjustment : 0) + (hasPaging ? pagerHeight : 0); var hasFixedCols = numOfFixedCols > 0; return { scroll: scroll, scrollX: scrollX, scrollY: scrollY, numOfFixedCols: numOfFixedCols, rowHeaders: rowHeaders, dataHeaders: dataHeaders, containerWidth: containerWidth, scrollPaneHeight: scrollPaneHeight, fixedPaneHeight: fixedPaneHeight, containerHeight: containerHeight, hasFixedCols: hasFixedCols, fixedHeaderWidth: (0, _utils.sumWidth)(rowHeaders), contentViewPortWidth: hasFixedCols ? containerWidth - (0, _utils.sumWidth)(rowHeaders) : scroll ? containerWidth : null, totalWidth: (0, _utils.sumWidth)(headers) }; }; var _default = computeGridViewProps; exports["default"] = _default; //# sourceMappingURL=computeGridProps.js.map