1 line
11 KiB
JSON
1 line
11 KiB
JSON
|
{"ast":null,"code":"import { useContext } from '@rc-component/context';\nimport * as React from 'react';\nimport TableContext, { responseImmutable } from \"../context/TableContext\";\nimport devRenderTimes from \"../hooks/useRenderTimes\";\nimport HeaderRow from \"./HeaderRow\";\nfunction parseHeaderRows(rootColumns) {\n var rows = [];\n function fillRowCells(columns, colIndex) {\n var rowIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;\n // Init rows\n rows[rowIndex] = rows[rowIndex] || [];\n var currentColIndex = colIndex;\n var colSpans = columns.filter(Boolean).map(function (column) {\n var cell = {\n key: column.key,\n className: column.className || '',\n children: column.title,\n column: column,\n colStart: currentColIndex\n };\n var colSpan = 1;\n var subColumns = column.children;\n if (subColumns && subColumns.length > 0) {\n colSpan = fillRowCells(subColumns, currentColIndex, rowIndex + 1).reduce(function (total, count) {\n return total + count;\n }, 0);\n cell.hasSubColumns = true;\n }\n if ('colSpan' in column) {\n colSpan = column.colSpan;\n }\n if ('rowSpan' in column) {\n cell.rowSpan = column.rowSpan;\n }\n cell.colSpan = colSpan;\n cell.colEnd = cell.colStart + colSpan - 1;\n rows[rowIndex].push(cell);\n currentColIndex += colSpan;\n return colSpan;\n });\n return colSpans;\n }\n\n // Generate `rows` cell data\n fillRowCells(rootColumns, 0);\n\n // Handle `rowSpan`\n var rowCount = rows.length;\n var _loop = function _loop(rowIndex) {\n rows[rowIndex].forEach(function (cell) {\n if (!('rowSpan' in cell) && !cell.hasSubColumns) {\n // eslint-disable-next-line no-param-reassign\n cell.rowSpan = rowCount - rowIndex;\n }\n });\n };\n for (var rowIndex = 0; rowIndex < rowCount; rowIndex += 1) {\n _loop(rowIndex);\n }\n return rows;\n}\nvar Header = function Header(props) {\n if (process.env.NODE_ENV !== 'production') {\n devRenderTimes(props);\n }\n var stickyOffsets = props.stickyOffsets,\n columns = props.columns,\n flattenColumns = props.flattenColumns,\n onHeaderRow = props.onHeaderRow;\n var _useContext = useContext(TableContext, ['prefixCls', 'getComponent']),\n prefixCls = _useContext.prefixCls,\n getComponent = _useContext.getComponent;\n var rows = React.useMemo(function () {\n return parseHeaderRows(columns);\n }, [columns]);\n var WrapperComponent = getComponent(['header', 'wrapper'], 'thead');\n var trComponent = getComponent(['header', 'row'], 'tr');\n var thComponent = getComponent(['header', 'cell'], 'th');\n return /*#__PURE__*/React.createElement(WrapperComponent, {\n className: \"\".concat(prefixCls, \"-thead\")\n }, rows.map(function (row, rowIndex) {\n var rowNode = /*#__PURE__*/React.createElement(HeaderRow, {\n key: rowIndex,\n flattenColumns: flattenColumns,\n cells: row,\n stickyOffsets: stickyOffsets,\n rowComponent: trComponent,\n cellComponent: thComponent,\n onHeaderRow: onHeaderRow,\n index: rowIndex\n });\n return rowNode;\n }));\n};\nexport default responseImmutable(Header);","map":{"version":3,"names":["useContext","React","TableContext","responseImmutable","devRenderTimes","HeaderRow","parseHeaderRows","rootColumns","rows","fillRowCells","columns","colIndex","rowIndex","arguments","length","undefined","currentColIndex","colSpans","filter","Boolean","map","column","cell","key","className","children","title","colStart","colSpan","subColumns","reduce","total","count","hasSubColumns","rowSpan","colEnd","push","rowCount","_loop","forEach","Header","props","process","env","NODE_ENV","stickyOffsets","flattenColumns","onHeaderRow","_useContext","prefixCls","getComponent","useMemo","WrapperComponent","trComponent","thComponent","createElement","concat","row","rowNode","cells","rowComponent","cellComponent","index"],"sources":["C:/Users/Аришина)/sourc
|