UNPKG

tdesign-vue-next

Version:
102 lines (96 loc) 3.91 kB
/** * tdesign v1.19.2 * (c) 2026 tdesign * @license MIT */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var Vue = require('vue'); var log = require('../../_chunks/dep-692bdebe.js'); var get = require('../../_chunks/dep-74a5bebe.js'); require('../../_chunks/dep-4eca9add.js'); require('../../_chunks/dep-4cb26289.js'); require('@babel/runtime/helpers/typeof'); require('../../_chunks/dep-80a41429.js'); require('../../_chunks/dep-22dc294c.js'); require('../../_chunks/dep-e1d22111.js'); require('../../_chunks/dep-930a2de5.js'); require('../../_chunks/dep-2dcf9237.js'); require('../../_chunks/dep-bf76dead.js'); require('../../_chunks/dep-c3bbd06c.js'); require('../../_chunks/dep-2fb8d44f.js'); function getCellKey(row, rowKey, colKey, colIndex, rowIndex) { var rowValue = get.get(row, rowKey); if (rowValue === void 0) { if (rowIndex === void 0) { log.log.error("Table", "rowKey is wrong, can not get unique identifier of row."); } return ["__row_".concat(rowIndex, "__"), colKey || colIndex].join("_"); } return [rowValue, colKey || colIndex].join("_"); } function getRowKeyFromCell(cellKey) { var _cellKey$split; return (_cellKey$split = cellKey.split("_")) === null || _cellKey$split === void 0 ? void 0 : _cellKey$split[0]; } function useRowspanAndColspan(data, columns, rowKey, rowspanAndColspan) { var skipSpansMap = Vue.ref(/* @__PURE__ */new Map()); var onTrRowspanOrColspan = function onTrRowspanOrColspan(params, skipSpansValue) { 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.value[i] || !columns.value[j]) return; var cellKey = getCellKey(data.value[i], rowKey.value, columns.value[j].colKey, j, i); var state = skipSpansMap.value.get(cellKey) || {}; state.skipped = true; skipSpansMap.value.set(cellKey, state); } } } }; var updateSkipSpansMap = function updateSkipSpansMap(data2, columns2, rowspanAndColspan2) { var _skipSpansMap$value; (_skipSpansMap$value = skipSpansMap.value) === null || _skipSpansMap$value === void 0 || _skipSpansMap$value.clear(); if (!data2 || !rowspanAndColspan2) return; 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.value, col.colKey, j, i); var state = skipSpansMap.value.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); skipSpansMap.value.set(cellKey, state); } onTrRowspanOrColspan === null || onTrRowspanOrColspan === void 0 || onTrRowspanOrColspan(params, state); } } }; Vue.watch(function () { return [data.value, columns.value, rowspanAndColspan]; }, function () { updateSkipSpansMap(data.value, columns.value, rowspanAndColspan === null || rowspanAndColspan === void 0 ? void 0 : rowspanAndColspan.value); }, { immediate: true }); return { skipSpansMap: skipSpansMap }; } exports["default"] = useRowspanAndColspan; exports.getCellKey = getCellKey; exports.getRowKeyFromCell = getRowKeyFromCell; //# sourceMappingURL=useRowspanAndColspan.js.map