UNPKG

tdesign-react

Version:
86 lines (82 loc) 3.08 kB
/** * tdesign v1.16.2 * (c) 2025 tdesign * @license MIT */ import { _ as _slicedToArray } from '../../_chunks/dep-10d5731f.js'; import { useState, useEffect } from 'react'; import { get } from 'lodash-es'; import '../../_chunks/dep-1144c9da.js'; import { l as log } from '../../_chunks/dep-2ba7b13f.js'; import '../../_chunks/dep-74a10cfb.js'; function getCellKey(row, rowKey, colKey, colIndex) { var rowValue = get(row, rowKey); if (rowValue === void 0) { log.error("Table", "rowKey is wrong, can not get unique identifier of row."); } return [rowValue, colKey || colIndex].join("_"); } function useRowspanAndColspan(data, columns, rowKey, rowspanAndColspan) { var _useState = useState(function () { return /* @__PURE__ */new Map(); }), _useState2 = _slicedToArray(_useState, 2), skipSpansMap = _useState2[0], setKipSnapsMap = _useState2[1]; var onTrRowspanOrColspan = function onTrRowspanOrColspan(params, skipSpansValue, map) { var rowIndex = params.rowIndex, colIndex = params.colIndex; if (!skipSpansValue.rowspan && !skipSpansValue.colspan) return; var maxRowIndex = rowIndex + (skipSpansValue.rowspan || 1); var maxColIndex = colIndex + (skipSpansValue.colspan || 1); for (var i = rowIndex; i < maxRowIndex; i++) { for (var j = colIndex; j < maxColIndex; j++) { if (i !== rowIndex || j !== colIndex) { if (!data[i] || !columns[j]) return; var cellKey = getCellKey(data[i], rowKey, columns[j].colKey, j); var state = map.get(cellKey) || {}; state.skipped = true; map.set(cellKey, state); } } } }; var getSkipSpansMap = function getSkipSpansMap(data2, columns2, rowspanAndColspan2) { if (!data2 || !rowspanAndColspan2) return; var map = /* @__PURE__ */new Map(); for (var i = 0, len = data2.length; i < len; i++) { var row = data2[i]; for (var j = 0, colLen = columns2.length; j < colLen; j++) { var col = columns2[j]; var params = { row: row, col: col, rowIndex: i, colIndex: j }; var cellKey = getCellKey(row, rowKey, col.colKey, j); var state = map.get(cellKey) || {}; var o = rowspanAndColspan2(params) || {}; if (o.rowspan || o.colspan || state.rowspan || state.colspan) { o.rowspan && (state.rowspan = o.rowspan); o.colspan && (state.colspan = o.colspan); map.set(cellKey, state); } onTrRowspanOrColspan === null || onTrRowspanOrColspan === void 0 || onTrRowspanOrColspan(params, state, map); } } return map; }; useEffect(function () { if (!rowspanAndColspan) return; skipSpansMap.clear(); var result = getSkipSpansMap(data, columns, rowspanAndColspan); setKipSnapsMap(result); }, [data, columns, rowspanAndColspan]); return { skipSpansMap: skipSpansMap, getSkipSpansMap: getSkipSpansMap }; } export { useRowspanAndColspan as default, getCellKey }; //# sourceMappingURL=useRowspanAndColspan.js.map