@antv/s2
Version:
effective spreadsheet render core lib
55 lines • 3 kB
JavaScript
import { get } from 'lodash';
import { CellType } from '../../common/constant';
import { getActionIconConfig } from './header-cell';
export const getTableColIconsWidth = (s2, meta, cellType, iconStyle) => {
var _a, _b;
const iconSize = iconStyle === null || iconStyle === void 0 ? void 0 : iconStyle.size;
const iconMargin = iconStyle === null || iconStyle === void 0 ? void 0 : iconStyle.margin;
let iconCount = 0;
if (s2.options.showDefaultHeaderActionIcon) {
iconCount = 1;
}
else {
iconCount =
(_b = (_a = getActionIconConfig(s2.options.headerActionIcons, meta, cellType)) === null || _a === void 0 ? void 0 : _a.icons.length) !== null && _b !== void 0 ? _b : 0;
}
return (iconCount * (iconSize + iconMargin.left) +
(iconCount > 0 ? iconMargin.right : 0));
};
export const getExtraPaddingForExpandIcon = (s2, field, style) => {
var _a, _b, _c, _d;
const iconMarginLeft = ((_b = (_a = style.icon) === null || _a === void 0 ? void 0 : _a.margin) === null || _b === void 0 ? void 0 : _b.left) || 0;
const iconMarginRight = ((_d = (_c = style.icon) === null || _c === void 0 ? void 0 : _c.margin) === null || _d === void 0 ? void 0 : _d.right) || 0;
const hiddenColumnsDetail = s2.store.get('hiddenColumnsDetail', []);
let hasPrevSiblingCell = false;
let hasNextSiblingCell = false;
hiddenColumnsDetail.forEach((column) => {
var _a, _b, _c, _d;
if (((_b = (_a = column === null || column === void 0 ? void 0 : column.displaySiblingNode) === null || _a === void 0 ? void 0 : _a.prev) === null || _b === void 0 ? void 0 : _b.field) === field) {
hasPrevSiblingCell = true;
}
if (((_d = (_c = column === null || column === void 0 ? void 0 : column.displaySiblingNode) === null || _c === void 0 ? void 0 : _c.next) === null || _d === void 0 ? void 0 : _d.field) === field) {
hasNextSiblingCell = true;
}
});
const iconSize = get(style, 'icon.size');
// 图标本身宽度 + 主题配置的 icon margin
return {
left: hasNextSiblingCell ? iconSize + iconMarginRight : 0,
right: hasPrevSiblingCell ? iconSize + iconMarginLeft : 0,
};
};
export const getOccupiedWidthForTableCol = (s2, meta, style) => {
var _a, _b;
const padding = get(style, 'cell.padding');
const horizontalBorderWidth = (_b = (_a = style === null || style === void 0 ? void 0 : style.cell) === null || _a === void 0 ? void 0 : _a.horizontalBorderWidth) !== null && _b !== void 0 ? _b : 1;
const expandIconPadding = getExtraPaddingForExpandIcon(s2, meta.field, style);
const iconsWidth = getTableColIconsWidth(s2, meta, CellType.COL_CELL, style === null || style === void 0 ? void 0 : style.icon);
return (padding.left +
padding.right +
iconsWidth +
expandIconPadding.left +
expandIconPadding.right +
horizontalBorderWidth);
};
//# sourceMappingURL=table-col-cell.js.map