@mui/x-codemod 7.0.0-alpha.2 → 7.0.0-alpha.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
@@ -88,7 +88,8 @@ The list includes these transformers
88
88
 
89
89
  - [`rename-components-to-slots-pickers`](#rename-components-to-slots-pickers)
90
90
  - [`rename-default-calendar-month-to-reference-date`](#rename-default-calendar-month-to-reference-date)
91
- - [`rename-day-picker-classes`](/rename-day-picker-classes)
91
+ - [`rename-day-picker-classes`](#rename-day-picker-classes)
92
+ - [`rename-slots-types`](#rename-slots-types)
92
93
 
93
94
  #### `rename-components-to-slots-pickers`
94
95
 
@@ -135,6 +136,21 @@ Rename the `dayPickerClasses` variable to `dayCalendarClasses`.
135
136
  npx @mui/x-codemod v7.0.0/pickers/rename-day-picker-classes <path>
136
137
  ```
137
138
 
139
+ #### `rename-slots-types`
140
+
141
+ Replace types suffix `SlotsComponent` by `Slots` and `SlotsComponentsProps` by `SlotProps`.
142
+
143
+ ```diff
144
+ - DateCalendarSlotsComponent
145
+ + DateCalendarSlots
146
+ - DateCalendarSlotsComponentsProps
147
+ + DateCalendarSlotProps
148
+ ```
149
+
150
+ ```bash
151
+ npx @mui/x-codemod v7.0.0/pickers/rename-slots-types <path>
152
+ ```
153
+
138
154
  ### Data grid codemods
139
155
 
140
156
  #### `preset-safe` for data grid v7.0.0
@@ -148,6 +164,7 @@ npx @mui/x-codemod v7.0.0/data-grid/preset-safe <path|folder>
148
164
  The list includes these transformers
149
165
 
150
166
  - [`rename-components-to-slots-data-grid`](#rename-components-to-slots-data-grid)
167
+ - [`rename-cell-selection-props`](#rename-cell-selection-props)
151
168
 
152
169
  #### `rename-components-to-slots-data-grid`
153
170
 
@@ -168,6 +185,25 @@ This change only affects Data Grid components.
168
185
  npx @mui/x-codemod v7.0.0/data-grid/rename-components-to-slots <path>
169
186
  ```
170
187
 
188
+ #### `rename-cell-selection-props`
189
+
190
+ Rename props related to `cellSelection` feature.
191
+
192
+ ```diff
193
+ <DataGridPremium
194
+ - unstable_cellSelection
195
+ + cellSelection
196
+ - cellSelectionModel={{ 0: { id: true, currencyPair: true, price1M: false } }}
197
+ + cellSelectionModel={{ 0: { id: true, currencyPair: true, price1M: false } }}
198
+ - unstable_onCellSelectionModelChange={() => {}}
199
+ + onCellSelectionModelChange={() => {}}
200
+ />;
201
+ ```
202
+
203
+ ```bash
204
+ npx @mui/x-codemod v7.0.0/data-grid/rename-cell-selection-props <path>
205
+ ```
206
+
171
207
  ## v6.0.0
172
208
 
173
209
  ### 🚀 `preset-safe` for v6.0.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-codemod",
3
- "version": "7.0.0-alpha.2",
3
+ "version": "7.0.0-alpha.5",
4
4
  "bin": "./codemod.js",
5
5
  "private": false,
6
6
  "author": "MUI Team",
@@ -32,9 +32,9 @@
32
32
  "url": "https://opencollective.com/mui-org"
33
33
  },
34
34
  "dependencies": {
35
- "@babel/core": "^7.23.3",
36
- "@babel/runtime": "^7.23.4",
37
- "@babel/traverse": "^7.23.4",
35
+ "@babel/core": "^7.23.5",
36
+ "@babel/runtime": "^7.23.5",
37
+ "@babel/traverse": "^7.23.5",
38
38
  "jscodeshift": "0.13.1",
39
39
  "jscodeshift-add-imports": "^1.0.10",
40
40
  "yargs": "^17.7.2"
@@ -89,7 +89,6 @@ function transformer(file, api, options) {
89
89
  // Add the new localeText prop
90
90
  j.jsxAttribute(j.jsxIdentifier('localeText'), j.jsxExpressionContainer(j.objectExpression(newLocaleText)))]), j.jsxClosingElement(j.jsxIdentifier('LocalizationProvider')), [path.value] // Pass in the original component as children
91
91
  );
92
-
93
92
  j(path).replaceWith(wrappedComponent);
94
93
  } else {
95
94
  attributes.push(j.jsxAttribute(j.jsxIdentifier('localeText'), j.jsxExpressionContainer(j.objectExpression(newLocaleText))));
@@ -5,8 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = transformer;
8
- var _renameComponentsToSlots = _interopRequireDefault(require("../../../v6.0.0/data-grid/rename-components-to-slots"));
8
+ var _renameComponentsToSlots = _interopRequireDefault(require("../rename-components-to-slots"));
9
+ var _renameCellSelectionProps = _interopRequireDefault(require("../rename-cell-selection-props"));
9
10
  function transformer(file, api, options) {
10
11
  file.source = (0, _renameComponentsToSlots.default)(file, api, options);
12
+ file.source = (0, _renameCellSelectionProps.default)(file, api, options);
11
13
  return file.source;
12
14
  }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = transformer;
8
+ var _renameProps = _interopRequireDefault(require("../../../util/renameProps"));
9
+ const componentNames = ['DataGridPremium'];
10
+ const props = {
11
+ unstable_cellSelection: 'cellSelection',
12
+ unstable_cellSelectionModel: 'cellSelectionModel',
13
+ unstable_onCellSelectionModelChange: 'onCellSelectionModelChange'
14
+ };
15
+ function transformer(file, api, options) {
16
+ const j = api.jscodeshift;
17
+ const root = j(file.source);
18
+ const printOptions = options.printOptions || {
19
+ quote: 'single',
20
+ trailingComma: true
21
+ };
22
+ return (0, _renameProps.default)({
23
+ root,
24
+ j,
25
+ props,
26
+ componentNames
27
+ }).toSource(printOptions);
28
+ }
@@ -8,9 +8,11 @@ exports.default = transformer;
8
8
  var _renameComponentsToSlots = _interopRequireDefault(require("../rename-components-to-slots"));
9
9
  var _renameDefaultCalendarMonthToReferenceDate = _interopRequireDefault(require("../rename-default-calendar-month-to-reference-date"));
10
10
  var _renameDayPickerClasses = _interopRequireDefault(require("../rename-day-picker-classes"));
11
+ var _renameSlotsTypes = _interopRequireDefault(require("../rename-slots-types"));
11
12
  function transformer(file, api, options) {
12
13
  file.source = (0, _renameComponentsToSlots.default)(file, api, options);
13
14
  file.source = (0, _renameDefaultCalendarMonthToReferenceDate.default)(file, api, options);
14
15
  file.source = (0, _renameDayPickerClasses.default)(file, api, options);
16
+ file.source = (0, _renameSlotsTypes.default)(file, api, options);
15
17
  return file.source;
16
18
  }
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = transformer;
7
+ const PACKAGE_REGEXP = /@mui\/x-date-pickers(-pro|)(\/(.*)|)/;
8
+ const rename = {
9
+ DateCalendarSlotsComponent: 'DateCalendarSlots',
10
+ DateCalendarSlotsComponentsProps: 'DateCalendarSlotProps',
11
+ DatePickerSlotsComponents: 'DatePickerSlots',
12
+ DatePickerSlotsComponentsProps: 'DatePickerSlotProps',
13
+ DateTimePickerSlotsComponents: 'DateTimePickerSlots',
14
+ DateTimePickerSlotsComponentsProps: 'DateTimePickerSlotProps',
15
+ DesktopDatePickerSlotsComponent: 'DesktopDatePickerSlots',
16
+ DesktopDatePickerSlotsComponentsProps: 'DesktopDatePickerSlotProps',
17
+ DesktopDateTimePickerSlotsComponent: 'DesktopDateTimePickerSlots',
18
+ DesktopDateTimePickerSlotsComponentsProps: 'DesktopDateTimePickerSlotProps',
19
+ DesktopTimePickerSlotsComponent: 'DesktopTimePickerSlots',
20
+ DesktopTimePickerSlotsComponentsProps: 'DesktopTimePickerSlotProps',
21
+ DigitalClockSlotsComponent: 'DigitalClockSlots',
22
+ DigitalClockSlotsComponentsProps: 'DigitalClockSlotProps',
23
+ ExportedPickersLayoutSlotsComponent: 'ExportedPickersLayoutSlots',
24
+ ExportedPickersLayoutSlotsComponentsProps: 'ExportedPickersLayoutSlotProps',
25
+ MobileDatePickerSlotsComponent: 'MobileDatePickerSlots',
26
+ MobileDatePickerSlotsComponentsProps: 'MobileDatePickerSlotProps',
27
+ MobileDateTimePickerSlotsComponent: 'MobileDateTimePickerSlots',
28
+ MobileDateTimePickerSlotsComponentsProps: 'MobileDateTimePickerSlotProps',
29
+ MobileTimePickerSlotsComponent: 'MobileTimePickerSlots',
30
+ MobileTimePickerSlotsComponentsProps: 'MobileTimePickerSlotProps',
31
+ MultiSectionDigitalClockSlotsComponent: 'MultiSectionDigitalClockSlots',
32
+ MultiSectionDigitalClockSlotsComponentsProps: 'MultiSectionDigitalClockSlotProps',
33
+ PickersCalendarHeaderSlotsComponent: 'PickersCalendarHeaderSlots',
34
+ PickersCalendarHeaderSlotsComponentsProps: 'PickersCalendarHeaderSlotProps',
35
+ PickersLayoutSlotsComponent: 'PickersLayoutSlots',
36
+ PickersLayoutSlotsComponentsProps: 'PickersLayoutSlotProps',
37
+ StaticDatePickerSlotsComponent: 'StaticDatePickerSlots',
38
+ StaticDatePickerSlotsComponentsProps: 'StaticDatePickerSlotProps',
39
+ StaticDateTimePickerSlotsComponent: 'StaticDateTimePickerSlots',
40
+ StaticDateTimePickerSlotsComponentsProps: 'StaticDateTimePickerSlotProps',
41
+ StaticTimePickerSlotsComponent: 'StaticTimePickerSlots',
42
+ StaticTimePickerSlotsComponentsProps: 'StaticTimePickerSlotProps',
43
+ TimeClockSlotsComponent: 'TimeClockSlots',
44
+ TimeClockSlotsComponentsProps: 'TimeClockSlotProps',
45
+ TimePickerSlotsComponents: 'TimePickerSlots',
46
+ TimePickerSlotsComponentsProps: 'TimePickerSlotProps',
47
+ DateRangeCalendarSlotsComponent: 'DateRangeCalendarSlots',
48
+ DateRangeCalendarSlotsComponentsProps: 'DateRangeCalendarSlotProps',
49
+ DateRangePickerSlotsComponents: 'DateRangePickerSlots',
50
+ DateRangePickerSlotsComponentsProps: 'DateRangePickerSlotProps',
51
+ DesktopDateRangePickerSlotsComponent: 'DesktopDateRangePickerSlots',
52
+ DesktopDateRangePickerSlotsComponentsProps: 'DesktopDateRangePickerSlotProps',
53
+ MobileDateRangePickerSlotsComponent: 'MobileDateRangePickerSlots',
54
+ MobileDateRangePickerSlotsComponentsProps: 'MobileDateRangePickerSlotProps',
55
+ StaticDateRangePickerSlotsComponent: 'StaticDateRangePickerSlots',
56
+ StaticDateRangePickerSlotsComponentsProps: 'StaticDateRangePickerSlotProps',
57
+ // Next elements are internal types
58
+ DayCalendarSlotsComponent: 'DayCalendarSlots',
59
+ DayCalendarSlotsComponentsProps: 'DayCalendarSlotProps',
60
+ SingleInputTimeRangeFieldSlotsComponent: 'SingleInputTimeRangeFieldSlots',
61
+ SingleInputTimeRangeFieldSlotsComponentsProps: 'SingleInputTimeRangeFieldSlotProps',
62
+ SingleInputDateRangeFieldSlotsComponentsProps: 'SingleInputDateRangeFieldSlotProps',
63
+ SingleInputDateRangeFieldSlotsComponent: 'SingleInputDateRangeFieldSlots',
64
+ SingleInputDateTimeRangeFieldSlotsComponent: 'SingleInputDateTimeRangeFieldSlots',
65
+ SingleInputDateTimeRangeFieldSlotsComponentsProps: 'SingleInputDateTimeRangeFieldSlotProps',
66
+ UseMobileRangePickerSlotsComponent: 'UseMobileRangePickerSlots',
67
+ UseMobileRangePickerSlotsComponentsProps: 'UseMobileRangePickerSlotProps',
68
+ BaseDateRangePickerSlotsComponent: 'BaseDateRangePickerSlots',
69
+ BaseDateRangePickerSlotsComponentsProps: 'BaseDateRangePickerSlotProps',
70
+ PickersArrowSwitcherSlotsComponent: 'PickersArrowSwitcherSlots',
71
+ PickersArrowSwitcherSlotsComponentsProps: 'PickersArrowSwitcherSlotProps',
72
+ PickersArrowSwitcherComponentsPropsOverrides: 'PickersArrowSwitcherSlotPropsOverrides',
73
+ UseStaticRangePickerSlotsComponent: 'UseStaticRangePickerSlots',
74
+ UseStaticRangePickerSlotsComponentsProps: 'UseStaticRangePickerSlotProps',
75
+ PickersModalDialogSlotsComponent: 'PickersModalDialogSlots',
76
+ PickersModalDialogSlotsComponentsProps: 'PickersModalDialogSlotProps',
77
+ RangePickerFieldSlotsComponent: 'RangePickerFieldSlots',
78
+ RangePickerFieldSlotsComponentsProps: 'RangePickerFieldSlotProps',
79
+ FieldSlotsComponents: 'FieldSlots',
80
+ FieldSlotsComponentsProps: 'FieldSlotProps',
81
+ PickersPopperSlotsComponent: 'PickersPopperSlots',
82
+ PickersPopperSlotsComponentsProps: 'PickersPopperSlotProps',
83
+ UseDesktopRangePickerSlotsComponent: 'UseDesktopRangePickerSlots',
84
+ UseDesktopRangePickerSlotsComponentsProps: 'UseDesktopRangePickerSlotProps',
85
+ MultiInputFieldSlotRootProps: 'MultiInputFieldSlotRootProps',
86
+ MultiInputFieldSlotTextFieldProps: 'MultiInputFieldSlotTextFieldProps',
87
+ UseDesktopPickerSlotsComponent: 'UseDesktopPickerSlots',
88
+ UseDesktopPickerSlotsComponentsProps: 'UseDesktopPickerSlotProps',
89
+ ExportedUseDesktopPickerSlotsComponentsProps: 'ExportedUseDesktopPickerSlotProps',
90
+ BaseDatePickerSlotsComponent: 'BaseDatePickerSlots',
91
+ BaseDatePickerSlotsComponentsProps: 'BaseDatePickerSlotProps',
92
+ UseStaticPickerSlotsComponent: 'UseStaticPickerSlots',
93
+ UseStaticPickerSlotsComponentsProps: 'UseStaticPickerSlotProps',
94
+ BaseDateTimePickerSlotsComponent: 'BaseDateTimePickerSlots',
95
+ BaseDateTimePickerSlotsComponentsProps: 'BaseDateTimePickerSlotProps',
96
+ BaseTimePickerSlotsComponent: 'BaseTimePickerSlots',
97
+ BaseTimePickerSlotsComponentsProps: 'BaseTimePickerSlotProps',
98
+ UseMobilePickerSlotsComponent: 'UseMobilePickerSlots',
99
+ UseMobilePickerSlotsComponentsProps: 'UseMobilePickerSlotProps',
100
+ ExportedUseMobilePickerSlotsComponentsProps: 'ExportedUseMobilePickerSlotProps',
101
+ DateTimeFieldSlotsComponent: 'DateTimeFieldSlots',
102
+ DateTimeFieldSlotsComponentsProps: 'DateTimeFieldSlotProps',
103
+ TimeFieldSlotsComponent: 'TimeFieldSlots',
104
+ TimeFieldSlotsComponentsProps: 'TimeFieldSlotProps',
105
+ DateFieldSlotsComponent: 'DateFieldSlots',
106
+ DateFieldSlotsComponentsProps: 'DateFieldSlotProps',
107
+ MultiInputDateRangeFieldSlotsComponent: 'MultiInputDateRangeFieldSlots',
108
+ MultiInputDateRangeFieldSlotsComponentsProps: 'MultiInputDateRangeFieldSlotProps',
109
+ MultiInputDateTimeRangeFieldSlotsComponent: 'MultiInputDateTimeRangeFieldSlots',
110
+ MultiInputDateTimeRangeFieldSlotsComponentsProps: 'MultiInputDateTimeRangeFieldSlotProps',
111
+ MultiInputTimeRangeFieldSlotsComponent: 'MultiInputTimeRangeFieldSlots',
112
+ MultiInputTimeRangeFieldSlotsComponentsProps: 'MultiInputTimeRangeFieldSlotProps'
113
+ };
114
+ const matchImport = path => (path.node.source.value?.toString() ?? '').match(PACKAGE_REGEXP);
115
+ function transformer(file, api, options) {
116
+ const j = api.jscodeshift;
117
+ const root = j(file.source);
118
+ const printOptions = options.printOptions || {
119
+ quote: 'single',
120
+ trailingComma: true
121
+ };
122
+ const matchingImports = root.find(j.ImportDeclaration).filter(path => !!matchImport(path));
123
+
124
+ // Rename the import specifiers
125
+ // - import { DayCalendarSlotsComponent } from '@mui/x-date-pickers'
126
+ // + import { DayCalendarSlots } from '@mui/x-date-pickers'
127
+ matchingImports.find(j.ImportSpecifier).filter(path => Object.keys(rename).includes(path.node.imported.name)).replaceWith(path => j.importSpecifier(j.identifier(rename[path.node.imported.name]), path.value.local));
128
+
129
+ // Rename the import usage
130
+ // - DayCalendarSlotsComponent
131
+ // + DayCalendarSlots
132
+ root.find(j.Identifier).filter(path => Object.keys(rename).includes(path.node.name)).replaceWith(path => j.identifier(rename[path.node.name]));
133
+ return root.toSource(printOptions);
134
+ }