@mui/x-codemod 6.0.0-beta.3 → 6.0.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -381,7 +381,7 @@ Rename toolbar related translation keys, removing `Default` part from them to be
|
|
|
381
381
|
npx @mui/x-codemod v6.0.0/pickers/rename-default-toolbar-title-localeText <path>
|
|
382
382
|
```
|
|
383
383
|
|
|
384
|
-
#### `rename-components-to-slots`
|
|
384
|
+
#### `rename-components-to-slots-pickers`
|
|
385
385
|
|
|
386
386
|
Renames the `components` and `componentsProps` props to `slots` and `slotProps`, respectively.
|
|
387
387
|
|
|
@@ -603,7 +603,7 @@ Rename selectors and events.
|
|
|
603
603
|
|
|
604
604
|
```diff
|
|
605
605
|
function App() {
|
|
606
|
-
- useGridApiEventHandler('selectionChange', handleEvent);
|
|
606
|
+
- useGridApiEventHandler(apiRef, 'selectionChange', handleEvent);
|
|
607
607
|
- apiRef.current.subscribeEvent('selectionChange', handleEvent);
|
|
608
608
|
- const selection = useGridSelector(apiRef, gridSelectionStateSelector);
|
|
609
609
|
- const sortedRowIds = useGridSelector(apiRef, gridVisibleSortedRowIdsSelector);
|
|
@@ -616,7 +616,7 @@ Rename selectors and events.
|
|
|
616
616
|
- const visibleGridColumns = useGridSelector(apiRef, visibleGridColumnsSelector);
|
|
617
617
|
- const filterableGridColumns = useGridSelector(apiRef, filterableGridColumnsSelector);
|
|
618
618
|
- const getGridNumericColumn = useGridSelector(apiRef, getGridNumericColumnOperators);
|
|
619
|
-
+ useGridApiEventHandler('rowSelectionChange', handleEvent);
|
|
619
|
+
+ useGridApiEventHandler(apiRef, 'rowSelectionChange', handleEvent);
|
|
620
620
|
+ apiRef.current.subscribeEvent('rowSelectionChange', handleEvent);
|
|
621
621
|
+ const selection = useGridSelector(apiRef, gridRowSelectionStateSelector);
|
|
622
622
|
+ const sortedRowIds = useGridSelector(apiRef, gridExpandedSortedRowIdsSelector);
|
|
@@ -680,4 +680,23 @@ Replace `onCellFocusOut` prop with `componentsProps.cell.onBlur`.
|
|
|
680
680
|
npx @mui/x-codemod v6.0.0/data-grid/replace-onCellFocusOut-prop <path>
|
|
681
681
|
```
|
|
682
682
|
|
|
683
|
+
#### `rename-components-to-slots-data-grid`
|
|
684
|
+
|
|
685
|
+
Renames the `components` and `componentsProps` props to `slots` and `slotProps`, respectively.
|
|
686
|
+
|
|
687
|
+
This change only affects data grid components.
|
|
688
|
+
|
|
689
|
+
```diff
|
|
690
|
+
<DataGrid
|
|
691
|
+
- components={{ Toolbar: CustomToolbar }}
|
|
692
|
+
+ slots={{ toolbar: CustomToolbar }}
|
|
693
|
+
- componentsProps={{ actionBar: { actions: ['clear'] } }}
|
|
694
|
+
+ slotProps={{ actionBar: { actions: ['clear'] } }}
|
|
695
|
+
/>;
|
|
696
|
+
```
|
|
697
|
+
|
|
698
|
+
```sh
|
|
699
|
+
npx @mui/x-codemod v6.0.0/data-grid/rename-components-to-slots <path>
|
|
700
|
+
```
|
|
701
|
+
|
|
683
702
|
You can find more details about Data Grid breaking change in [the migration guide](https://next.mui.com/x/migration/migration-data-grid-v5/).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/x-codemod",
|
|
3
|
-
"version": "6.0.0-beta.
|
|
3
|
+
"version": "6.0.0-beta.5",
|
|
4
4
|
"bin": "./codemod.js",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "MUI Team",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@babel/traverse": "^7.20.13",
|
|
37
37
|
"jscodeshift": "0.13.1",
|
|
38
38
|
"jscodeshift-add-imports": "^1.0.10",
|
|
39
|
-
"yargs": "^17.
|
|
39
|
+
"yargs": "^17.7.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/jscodeshift": "^0.11.5"
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = transformer;
|
|
7
|
+
var _renameIdentifiers = require("../../../util/renameIdentifiers");
|
|
8
|
+
const preRequisites = {
|
|
9
|
+
components: ['DataGrid', 'DataGridPro', 'DataGridPremium'],
|
|
10
|
+
packageRegex: /@mui\/x-data-grid(-pro|-premium)?/
|
|
11
|
+
};
|
|
12
|
+
function transformComponentsProp(attributeNode) {
|
|
13
|
+
attributeNode.value.name.name = 'slots';
|
|
14
|
+
const valueExpression = attributeNode.value.value.expression;
|
|
15
|
+
if (!valueExpression || valueExpression.type !== 'ObjectExpression') {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
valueExpression.properties.forEach(property => {
|
|
19
|
+
property.key.name = property.key.name[0].toLowerCase() + property.key.name.slice(1);
|
|
20
|
+
if (property.shorthand) {
|
|
21
|
+
property.shorthand = false;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function transformComponentsPropsProp(attributeNode) {
|
|
26
|
+
attributeNode.value.name.name = 'slotProps';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @param {import('jscodeshift').FileInfo} file
|
|
31
|
+
* @param {import('jscodeshift').API} api
|
|
32
|
+
*/
|
|
33
|
+
function transformer(file, api, options) {
|
|
34
|
+
const j = api.jscodeshift;
|
|
35
|
+
const root = j(file.source);
|
|
36
|
+
const printOptions = options.printOptions || {
|
|
37
|
+
quote: 'single',
|
|
38
|
+
trailingComma: true
|
|
39
|
+
};
|
|
40
|
+
const isGridUsed = (0, _renameIdentifiers.checkPreRequisitesSatisfied)(j, root, preRequisites);
|
|
41
|
+
if (isGridUsed) {
|
|
42
|
+
root.find(j.JSXElement).filter(path => {
|
|
43
|
+
return preRequisites.components.includes(path.value.openingElement.name.name);
|
|
44
|
+
}).find(j.JSXAttribute).forEach(attribute => {
|
|
45
|
+
// Only remove props from components in componentNames. Not nested ones.
|
|
46
|
+
if (!preRequisites.components.includes(attribute.parent.value.name.name)) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (attribute.value.name.name === 'components') {
|
|
50
|
+
transformComponentsProp(attribute);
|
|
51
|
+
} else if (attribute.value.name.name === 'componentsProps') {
|
|
52
|
+
transformComponentsPropsProp(attribute);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return root.toSource(printOptions);
|
|
57
|
+
}
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = transform;
|
|
8
|
-
var _renameCSSClasses = _interopRequireDefault(require("
|
|
8
|
+
var _renameCSSClasses = _interopRequireDefault(require("../../../util/renameCSSClasses"));
|
|
9
9
|
var _renameIdentifiers = _interopRequireWildcard(require("../../../util/renameIdentifiers"));
|
|
10
10
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
11
11
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -14,7 +14,8 @@ const renamedIdentifiers = {
|
|
|
14
14
|
linkOperatorInputProps: 'logicOperatorInputProps',
|
|
15
15
|
linkOperator: 'logicOperator',
|
|
16
16
|
linkOperators: 'logicOperators',
|
|
17
|
-
setFilterLinkOperator: 'setFilterLogicOperator'
|
|
17
|
+
setFilterLinkOperator: 'setFilterLogicOperator',
|
|
18
|
+
getRowIndex: 'getRowIndexRelativeToVisibleRows'
|
|
18
19
|
};
|
|
19
20
|
const PACKAGE_REGEXP = /@mui\/x-data-grid(-pro|-premium)?/;
|
|
20
21
|
const GridComponents = ['DataGrid', 'DataGridPro', 'DataGridPremium'];
|
|
@@ -38,6 +39,14 @@ const preRequisiteUsages = {
|
|
|
38
39
|
possiblePaths: ['componentsProps.filter'],
|
|
39
40
|
components: GridComponents,
|
|
40
41
|
packageRegex: PACKAGE_REGEXP
|
|
42
|
+
},
|
|
43
|
+
setFilterLinkOperator: {
|
|
44
|
+
components: GridComponents,
|
|
45
|
+
packageRegex: PACKAGE_REGEXP
|
|
46
|
+
},
|
|
47
|
+
getRowIndex: {
|
|
48
|
+
components: GridComponents,
|
|
49
|
+
packageRegex: PACKAGE_REGEXP
|
|
41
50
|
}
|
|
42
51
|
};
|
|
43
52
|
const renamedLiterals = {
|
|
@@ -41,9 +41,9 @@ function transformer(file, api, options) {
|
|
|
41
41
|
root.find(j.Identifier).filter(path => !!renamedSelectors[path.node.name]).replaceWith(path => j.identifier(renamedSelectors[path.node.name]));
|
|
42
42
|
|
|
43
43
|
// Rename the usage of renamed event literals
|
|
44
|
-
// - useGridApiEventHandler('selectionChange', handleEvent);
|
|
44
|
+
// - useGridApiEventHandler(apiRef, 'selectionChange', handleEvent);
|
|
45
45
|
// - apiRef.current.subscribeEvent('selectionChange', handleEvent);
|
|
46
|
-
// + useGridApiEventHandler('rowSelectionChange', handleEvent);
|
|
46
|
+
// + useGridApiEventHandler(apiRef, 'rowSelectionChange', handleEvent);
|
|
47
47
|
// + apiRef.current.subscribeEvent('rowSelectionChange', handleEvent);
|
|
48
48
|
root.find(j.CallExpression).find(j.Literal).filter(path => !!renamedEvents[path.node.value]).replaceWith(path => j.literal(renamedEvents[path.node.value]));
|
|
49
49
|
}
|