1 line
14 KiB
JSON
1 line
14 KiB
JSON
{"ast":null,"code":"import _extends from \"@babel/runtime/helpers/esm/extends\";\nimport * as React from 'react';\nimport { GridDensityTypes } from '../../../models/gridDensity';\nimport { useGridLogger } from '../../utils/useGridLogger';\nimport { useGridApiMethod } from '../../utils/useGridApiMethod';\nimport { gridDensitySelector } from './densitySelector';\nimport { isDeepEqual } from '../../../utils/utils';\nimport { useGridSelector } from '../../utils/useGridSelector';\nimport { gridVisibleColumnDefinitionsSelector } from '../columns';\nimport { unwrapGroupingColumnModel } from '../columnGrouping/useGridColumnGrouping';\nexport const COMPACT_DENSITY_FACTOR = 0.7;\nexport const COMFORTABLE_DENSITY_FACTOR = 1.3; // TODO v6: revise keeping headerHeight and rowHeight in state\n\nconst getUpdatedDensityState = (newDensity, newHeaderHeight, newRowHeight, newMaxDepth) => {\n switch (newDensity) {\n case GridDensityTypes.Compact:\n return {\n value: newDensity,\n headerHeight: Math.floor(newHeaderHeight * COMPACT_DENSITY_FACTOR),\n rowHeight: Math.floor(newRowHeight * COMPACT_DENSITY_FACTOR),\n headerGroupingMaxDepth: newMaxDepth,\n factor: COMPACT_DENSITY_FACTOR\n };\n case GridDensityTypes.Comfortable:\n return {\n value: newDensity,\n headerHeight: Math.floor(newHeaderHeight * COMFORTABLE_DENSITY_FACTOR),\n rowHeight: Math.floor(newRowHeight * COMFORTABLE_DENSITY_FACTOR),\n headerGroupingMaxDepth: newMaxDepth,\n factor: COMFORTABLE_DENSITY_FACTOR\n };\n default:\n return {\n value: newDensity,\n headerHeight: newHeaderHeight,\n rowHeight: newRowHeight,\n headerGroupingMaxDepth: newMaxDepth,\n factor: 1\n };\n }\n};\nexport const densityStateInitializer = (state, props) => {\n // TODO: think about improving this initialization. Could it be done in the useColumn initializer?\n // TODO: manage to remove ts-ignore\n let maxDepth;\n if (props.columnGroupingModel == null || Object.keys(props.columnGroupingModel).length === 0) {\n maxDepth = 0;\n } else {\n const unwrappedGroupingColumnModel = unwrapGroupingColumnModel(props.columnGroupingModel);\n const columnsState = state.columns;\n const visibleColumns = columnsState.all.filter(field => columnsState.columnVisibilityModel[field] !== false);\n if (visibleColumns.length === 0) {\n maxDepth = 0;\n } else {\n maxDepth = Math.max(...visibleColumns.map(field => {\n var _unwrappedGroupingCol, _unwrappedGroupingCol2;\n return (_unwrappedGroupingCol = (_unwrappedGroupingCol2 = unwrappedGroupingColumnModel[field]) == null ? void 0 : _unwrappedGroupingCol2.length) != null ? _unwrappedGroupingCol : 0;\n }));\n }\n }\n return _extends({}, state, {\n density: getUpdatedDensityState(props.density, props.headerHeight, props.rowHeight, maxDepth)\n });\n};\nexport const useGridDensity = (apiRef, props) => {\n const visibleColumns = useGridSelector(apiRef, gridVisibleColumnDefinitionsSelector);\n const maxDepth = visibleColumns.length > 0 ? Math.max(...visibleColumns.map(column => {\n var _column$groupPath$len, _column$groupPath;\n return (_column$groupPath$len = (_column$groupPath = column.groupPath) == null ? void 0 : _column$groupPath.length) != null ? _column$groupPath$len : 0;\n })) : 0;\n const logger = useGridLogger(apiRef, 'useDensity');\n const setDensity = React.useCallback((newDensity, newHeaderHeight = props.headerHeight, newRowHeight = props.rowHeight, newMaxDepth = maxDepth) => {\n logger.debug(`Set grid density to ${newDensity}`);\n apiRef.current.setState(state => {\n const currentDensityState = gridDensitySelector(state);\n const newDensityState = getUpdatedDensityState(newDensity, newHeaderHeight, newRowHeight, newMaxDepth);\n if (isDeepEqual(currentDensityState, newDensityState)) {\n return state;\n }\n return _extends({}, state, {\n density: newDensityState\n });\n });\n apiRef.current.forceUpdate();\n }, [logger, apiRef, props.headerHeight, props.rowHeight, maxDepth]);\n React.useEffect(() => {\n apiRef.current.setDensity(props.density, props.headerHeight, props.rowHeight, maxDepth);\n }, [apiRef, props.density, props.rowHeight, props.headerHeight, maxDepth]);\n const densityApi = {\n setDensity\n };\n useGridApiMethod(apiRef, densityApi, 'GridDensityApi');\n};","map":{"version":3,"names":["_extends","React","GridDensityTypes","useGridLogger","useGridApiMethod","gridDensitySelector","isDeepEqual","useGridSelector","gridVisibleColumnDefinitionsSelector","unwrapGroupingColumnModel","COMPACT_DENSITY_FACTOR","COMFORTABLE_DENSITY_FACTOR","getUpdatedDensityState","newDensity","newHeaderHeight","newRowHeight","newMaxDepth","Compact","value","headerHeight","Math","floor","rowHeight","headerGroupingMaxDepth","factor","Comfortable","densityStateInitializer","state","props","maxDepth","columnGroupingModel","Object","keys","length","unwrappedGroupingColumnModel","columnsState","columns","visibleColumns","all","filter","field","columnVisibilityModel","max","map","_unwrappedGroupingCol","_unwrappedGroupingCol2","density","useGridDensity","apiRef","column","_column$groupPath$len","_column$groupPath","groupPath","logger","setDensity","useCallback","debug","current","setState","currentDensityState","newDensityState","forceUpdate","useEffect","densityApi"],"sources":["/home/gnx/Desktop/ETB/ETB-FrontEnd/node_modules/@mui/x-data-grid/hooks/features/density/useGridDensity.js"],"sourcesContent":["import _extends from \"@babel/runtime/helpers/esm/extends\";\nimport * as React from 'react';\nimport { GridDensityTypes } from '../../../models/gridDensity';\nimport { useGridLogger } from '../../utils/useGridLogger';\nimport { useGridApiMethod } from '../../utils/useGridApiMethod';\nimport { gridDensitySelector } from './densitySelector';\nimport { isDeepEqual } from '../../../utils/utils';\nimport { useGridSelector } from '../../utils/useGridSelector';\nimport { gridVisibleColumnDefinitionsSelector } from '../columns';\nimport { unwrapGroupingColumnModel } from '../columnGrouping/useGridColumnGrouping';\nexport const COMPACT_DENSITY_FACTOR = 0.7;\nexport const COMFORTABLE_DENSITY_FACTOR = 1.3; // TODO v6: revise keeping headerHeight and rowHeight in state\n\nconst getUpdatedDensityState = (newDensity, newHeaderHeight, newRowHeight, newMaxDepth) => {\n switch (newDensity) {\n case GridDensityTypes.Compact:\n return {\n value: newDensity,\n headerHeight: Math.floor(newHeaderHeight * COMPACT_DENSITY_FACTOR),\n rowHeight: Math.floor(newRowHeight * COMPACT_DENSITY_FACTOR),\n headerGroupingMaxDepth: newMaxDepth,\n factor: COMPACT_DENSITY_FACTOR\n };\n\n case GridDensityTypes.Comfortable:\n return {\n value: newDensity,\n headerHeight: Math.floor(newHeaderHeight * COMFORTABLE_DENSITY_FACTOR),\n rowHeight: Math.floor(newRowHeight * COMFORTABLE_DENSITY_FACTOR),\n headerGroupingMaxDepth: newMaxDepth,\n factor: COMFORTABLE_DENSITY_FACTOR\n };\n\n default:\n return {\n value: newDensity,\n headerHeight: newHeaderHeight,\n rowHeight: newRowHeight,\n headerGroupingMaxDepth: newMaxDepth,\n factor: 1\n };\n }\n};\n\nexport const densityStateInitializer = (state, props) => {\n // TODO: think about improving this initialization. Could it be done in the useColumn initializer?\n // TODO: manage to remove ts-ignore\n let maxDepth;\n\n if (props.columnGroupingModel == null || Object.keys(props.columnGroupingModel).length === 0) {\n maxDepth = 0;\n } else {\n const unwrappedGroupingColumnModel = unwrapGroupingColumnModel(props.columnGroupingModel);\n const columnsState = state.columns;\n const visibleColumns = columnsState.all.filter(field => columnsState.columnVisibilityModel[field] !== false);\n\n if (visibleColumns.length === 0) {\n maxDepth = 0;\n } else {\n maxDepth = Math.max(...visibleColumns.map(field => {\n var _unwrappedGroupingCol, _unwrappedGroupingCol2;\n\n return (_unwrappedGroupingCol = (_unwrappedGroupingCol2 = unwrappedGroupingColumnModel[field]) == null ? void 0 : _unwrappedGroupingCol2.length) != null ? _unwrappedGroupingCol : 0;\n }));\n }\n }\n\n return _extends({}, state, {\n density: getUpdatedDensityState(props.density, props.headerHeight, props.rowHeight, maxDepth)\n });\n};\nexport const useGridDensity = (apiRef, props) => {\n const visibleColumns = useGridSelector(apiRef, gridVisibleColumnDefinitionsSelector);\n const maxDepth = visibleColumns.length > 0 ? Math.max(...visibleColumns.map(column => {\n var _column$groupPath$len, _column$groupPath;\n\n return (_column$groupPath$len = (_column$groupPath = column.groupPath) == null ? void 0 : _column$groupPath.length) != null ? _column$groupPath$len : 0;\n })) : 0;\n const logger = useGridLogger(apiRef, 'useDensity');\n const setDensity = React.useCallback((newDensity, newHeaderHeight = props.headerHeight, newRowHeight = props.rowHeight, newMaxDepth = maxDepth) => {\n logger.debug(`Set grid density to ${newDensity}`);\n apiRef.current.setState(state => {\n const currentDensityState = gridDensitySelector(state);\n const newDensityState = getUpdatedDensityState(newDensity, newHeaderHeight, newRowHeight, newMaxDepth);\n\n if (isDeepEqual(currentDensityState, newDensityState)) {\n return state;\n }\n\n return _extends({}, state, {\n density: newDensityState\n });\n });\n apiRef.current.forceUpdate();\n }, [logger, apiRef, props.headerHeight, props.rowHeight, maxDepth]);\n React.useEffect(() => {\n apiRef.current.setDensity(props.density, props.headerHeight, props.rowHeight, maxDepth);\n }, [apiRef, props.density, props.rowHeight, props.headerHeight, maxDepth]);\n const densityApi = {\n setDensity\n };\n useGridApiMethod(apiRef, densityApi, 'GridDensityApi');\n};"],"mappings":"AAAA,OAAOA,QAAQ,MAAM,oCAAoC;AACzD,OAAO,KAAKC,KAAK,MAAM,OAAO;AAC9B,SAASC,gBAAgB,QAAQ,6BAA6B;AAC9D,SAASC,aAAa,QAAQ,2BAA2B;AACzD,SAASC,gBAAgB,QAAQ,8BAA8B;AAC/D,SAASC,mBAAmB,QAAQ,mBAAmB;AACvD,SAASC,WAAW,QAAQ,sBAAsB;AAClD,SAASC,eAAe,QAAQ,6BAA6B;AAC7D,SAASC,oCAAoC,QAAQ,YAAY;AACjE,SAASC,yBAAyB,QAAQ,yCAAyC;AACnF,OAAO,MAAMC,sBAAsB,GAAG,GAAG;AACzC,OAAO,MAAMC,0BAA0B,GAAG,GAAG,CAAC,CAAC;;AAE/C,MAAMC,sBAAsB,GAAGA,CAACC,UAAU,EAAEC,eAAe,EAAEC,YAAY,EAAEC,WAAW,KAAK;EACzF,QAAQH,UAAU;IAChB,KAAKX,gBAAgB,CAACe,OAAO;MAC3B,OAAO;QACLC,KAAK,EAAEL,UAAU;QACjBM,YAAY,EAAEC,IAAI,CAACC,KAAK,CAACP,eAAe,GAAGJ,sBAAsB,CAAC;QAClEY,SAAS,EAAEF,IAAI,CAACC,KAAK,CAACN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