1 line
7.4 KiB
JSON
1 line
7.4 KiB
JSON
|
{"ast":null,"code":"import _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport * as React from 'react';\nfunction parseColWidth(totalWidth) {\n var width = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';\n if (typeof width === 'number') {\n return width;\n }\n if (width.endsWith('%')) {\n return totalWidth * parseFloat(width) / 100;\n }\n return null;\n}\n\n/**\n * Fill all column with width\n */\nexport default function useWidthColumns(flattenColumns, scrollWidth, clientWidth) {\n return React.useMemo(function () {\n // Fill width if needed\n if (scrollWidth && scrollWidth > 0) {\n var totalWidth = 0;\n var missWidthCount = 0;\n\n // collect not given width column\n flattenColumns.forEach(function (col) {\n var colWidth = parseColWidth(scrollWidth, col.width);\n if (colWidth) {\n totalWidth += colWidth;\n } else {\n missWidthCount += 1;\n }\n });\n\n // Fill width\n var maxFitWidth = Math.max(scrollWidth, clientWidth);\n var restWidth = Math.max(maxFitWidth - totalWidth, missWidthCount);\n var restCount = missWidthCount;\n var avgWidth = restWidth / missWidthCount;\n var realTotal = 0;\n var filledColumns = flattenColumns.map(function (col) {\n var clone = _objectSpread({}, col);\n var colWidth = parseColWidth(scrollWidth, clone.width);\n if (colWidth) {\n clone.width = colWidth;\n } else {\n var colAvgWidth = Math.floor(avgWidth);\n clone.width = restCount === 1 ? restWidth : colAvgWidth;\n restWidth -= colAvgWidth;\n restCount -= 1;\n }\n realTotal += clone.width;\n return clone;\n });\n\n // If realTotal is less than clientWidth,\n // We need extend column width\n if (realTotal < maxFitWidth) {\n var scale = maxFitWidth / realTotal;\n restWidth = maxFitWidth;\n filledColumns.forEach(function (col, index) {\n var colWidth = Math.floor(col.width * scale);\n col.width = index === filledColumns.length - 1 ? restWidth : colWidth;\n restWidth -= colWidth;\n });\n }\n return [filledColumns, Math.max(realTotal, maxFitWidth)];\n }\n return [flattenColumns, scrollWidth];\n }, [flattenColumns, scrollWidth, clientWidth]);\n}","map":{"version":3,"names":["_objectSpread","React","parseColWidth","totalWidth","width","arguments","length","undefined","endsWith","parseFloat","useWidthColumns","flattenColumns","scrollWidth","clientWidth","useMemo","missWidthCount","forEach","col","colWidth","maxFitWidth","Math","max","restWidth","restCount","avgWidth","realTotal","filledColumns","map","clone","colAvgWidth","floor","scale","index"],"sources":["C:/Users/Аришина)/Desktop/promo/node_modules/rc-table/es/hooks/useColumns/useWidthColumns.js"],"sourcesContent":["import _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport * as React from 'react';\nfunction parseColWidth(totalWidth) {\n var width = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';\n if (typeof width === 'number') {\n return width;\n }\n if (width.endsWith('%')) {\n return totalWidth * parseFloat(width) / 100;\n }\n return null;\n}\n\n/**\n * Fill all column with width\n */\nexport default function useWidthColumns(flattenColumns, scrollWidth, clientWidth) {\n return React.useMemo(function () {\n // Fill width if needed\n if (scrollWidth && scrollWidth > 0) {\n var totalWidth = 0;\n var missWidthCount = 0;\n\n // collect not given width column\n flattenColumns.forEach(function (col) {\n var colWidth = parseColWidth(scrollWidth, col.width);\n if (colWidth) {\n totalWidth += colWidth;\n } else {\n missWidthCount += 1;\n }\n });\n\n // Fill width\n var maxFitWidth = Math.max(scrollWidth, clientWidth);\n var restWidth = Math.max(maxFitWidth - totalWidth, missWidthCount);\n var r
|