@mui/x-codemod 8.0.0-alpha.6 → 8.0.0-alpha.7

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
@@ -143,6 +143,7 @@ npx @mui/x-codemod@next v8.0.0/charts/preset-safe <path|folder>
143
143
  The list includes these transformers
144
144
 
145
145
  - [`rename-legend-to-slots-legend`](#rename-legend-to-slots-legend)
146
+ - [`replace-legend-direction-values`](#replace-legend-direction-values)
146
147
  - [`rename-responsive-chart-container`](#rename-responsive-chart-container)
147
148
  - [`rename-label-and-tick-font-size`](#rename-label-and-tick-font-size)
148
149
 
@@ -157,6 +158,21 @@ Renames legend props to the corresponding slotProps.
157
158
  />
158
159
  ```
159
160
 
161
+ #### `replace-legend-direction-values`
162
+
163
+ Replace `row` and `column` values by `horizontal` and `vertical` respectively.
164
+
165
+ ```diff
166
+ <BarChart
167
+ slotProps={{
168
+ legend: {
169
+ - direction: "row"
170
+ + direction: "horizontal"
171
+ }
172
+ }}
173
+ />
174
+ ```
175
+
160
176
  #### `rename-responsive-chart-container`
161
177
 
162
178
  Renames `ResponsiveChartContainer` and `ResponsiveChartContainerPro` by `ChartContainer` and `ChartContainerPro` which have the same behavior in v8.
@@ -172,17 +188,15 @@ Renames `ResponsiveChartContainer` and `ResponsiveChartContainerPro` by `ChartCo
172
188
  +</ChartContainer>
173
189
  ```
174
190
 
175
- :::warning
176
- If you imported both `ResponsiveChartContainer` and `ChartContainer` in the same file, you might end up with duplicated import.
177
- Verify the git diff to remove the duplicate.
178
-
179
- ```diff
180
- import { ChartContainer } from '@mui/x-charts/ChartContainer';
181
- -import { ResponsiveChartContainer } from '@mui/x-charts/ResponsiveChartContainer';
182
- +import { ChartContainer } from '@mui/x-charts/ChartContainer';
183
- ```
184
-
185
- :::
191
+ > [!WARNING]
192
+ > If you imported both `ResponsiveChartContainer` and `ChartContainer` in the same file, you might end up with duplicated import.
193
+ > Verify the git diff to remove the duplicate.
194
+ >
195
+ > ```diff
196
+ > import { ChartContainer } from '@mui/x-charts/ChartContainer';
197
+ > -import { ResponsiveChartContainer } from '@mui/x-charts/ResponsiveChartContainer';
198
+ > +import { ChartContainer } from '@mui/x-charts/ChartContainer';
199
+ > ```
186
200
 
187
201
  #### `rename-label-and-tick-font-size`
188
202
 
@@ -249,8 +263,39 @@ npx @mui/x-codemod@next v8.0.0/pickers/preset-safe <path|folder>
249
263
 
250
264
  The list includes these transformers
251
265
 
266
+ - [`rename-adapter-date-fns-imports`](#rename-adapter-date-fns-imports)
252
267
  - [`rename-and-move-field-value-type`](#rename-and-move-field-value-type)
253
268
 
269
+ #### `rename-adapter-date-fns-imports`
270
+
271
+ > [!WARNING]
272
+ > This codemod is not idempotent. Running it multiple times will rename the imports back and forth.
273
+ > Usage of `AdapterDateFnsV3` would be replaced by `AdapterDateFns` and a subsequent run would rename it to `AdapterDateFnsV2`.
274
+
275
+ - Renames `AdapterDateFns` and `AdapterDateFnsJalali` imports to `AdapterDateFnsV2` and `AdapterDateFnsJalaliV2` respectfully.
276
+
277
+ ```diff
278
+ -import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns';
279
+ -import { AdapterDateFnsJalali } from '@mui/x-date-pickers/AdapterDateFnsJalali';
280
+ +import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFnsV2';
281
+ +import { AdapterDateFnsJalali } from '@mui/x-date-pickers/AdapterDateFnsJalaliV2';
282
+ ```
283
+
284
+ - Renames `AdapterDateFnsV3` and `AdapterDateFnsJalaliV3` imports to `AdapterDateFns` and `AdapterDateFnsJalali` respectfully.
285
+
286
+ ```diff
287
+ -import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFnsV3';
288
+ -import { AdapterDateFnsJalali } from '@mui/x-date-pickers/AdapterDateFnsJalaliV3';
289
+ +import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns';
290
+ +import { AdapterDateFnsJalali } from '@mui/x-date-pickers/AdapterDateFnsJalali';
291
+ ```
292
+
293
+ <!-- #default-branch-switch -->
294
+
295
+ ```bash
296
+ npx @mui/x-codemod@next v8.0.0/pickers/rename-adapter-date-fns-imports <path>
297
+ ```
298
+
254
299
  #### `rename-and-move-field-value-type`
255
300
 
256
301
  Renames `FieldValueType` to `PickerValueType`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-codemod",
3
- "version": "8.0.0-alpha.6",
3
+ "version": "8.0.0-alpha.7",
4
4
  "bin": "./codemod.js",
5
5
  "private": false,
6
6
  "author": "MUI Team",
@@ -30,7 +30,7 @@
30
30
  "@babel/traverse": "^7.26.4",
31
31
  "jscodeshift": "17.1.1",
32
32
  "yargs": "^17.7.2",
33
- "@mui/x-internals": "8.0.0-alpha.6"
33
+ "@mui/x-internals": "8.0.0-alpha.7"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/jscodeshift": "^0.12.0",
@@ -8,9 +8,12 @@ exports.default = transformer;
8
8
  var _renameLegendToSlotsLegend = _interopRequireDefault(require("../rename-legend-to-slots-legend"));
9
9
  var _renameResponsiveChartContainer = _interopRequireDefault(require("../rename-responsive-chart-container"));
10
10
  var _renameLabelAndTickFontSize = _interopRequireDefault(require("../rename-label-and-tick-font-size"));
11
+ var _replaceLegendDirectionValues = _interopRequireDefault(require("../replace-legend-direction-values"));
11
12
  function transformer(file, api, options) {
12
13
  file.source = (0, _renameLegendToSlotsLegend.default)(file, api, options);
13
14
  file.source = (0, _renameResponsiveChartContainer.default)(file, api, options);
14
15
  file.source = (0, _renameLabelAndTickFontSize.default)(file, api, options);
16
+ file.source = (0, _renameLabelAndTickFontSize.default)(file, api, options);
17
+ file.source = (0, _replaceLegendDirectionValues.default)(file, api, options);
15
18
  return file.source;
16
19
  }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = transformer;
7
+ var _addComponentsSlots = require("../../../util/addComponentsSlots");
8
+ /**
9
+ * @param {import('jscodeshift').FileInfo} file
10
+ * @param {import('jscodeshift').API} api
11
+ */
12
+ function transformer(file, api, options) {
13
+ const j = api.jscodeshift;
14
+ const printOptions = options.printOptions;
15
+ const root = j(file.source);
16
+ root.find(j.ImportDeclaration).filter(({
17
+ node
18
+ }) => {
19
+ return typeof node.source.value === 'string' && node.source.value.startsWith('@mui/x-charts');
20
+ }).forEach(path => {
21
+ path.node.specifiers?.forEach(node => {
22
+ root.findJSXElements(node.local?.name).forEach(elementPath => {
23
+ if (elementPath.node.type !== 'JSXElement') {
24
+ return;
25
+ }
26
+ const slotProps = elementPath.node.openingElement.attributes?.find(elementNode => elementNode.type === 'JSXAttribute' && elementNode.name.name === 'slotProps');
27
+ if (slotProps === null) {
28
+ // No slotProps to manage
29
+ return;
30
+ }
31
+ const direction = slotProps?.value?.expression?.properties
32
+ // @ts-expect-error
33
+ ?.find(v => v?.key?.name === 'legend')
34
+ // @ts-expect-error
35
+ ?.value?.properties?.find(v => v?.key?.name === 'direction');
36
+ if (direction === undefined || direction?.value === undefined || direction?.value?.value === undefined) {
37
+ return;
38
+ }
39
+ const directionValue = direction.value;
40
+ directionValue.value = mapFix(directionValue.value);
41
+ (0, _addComponentsSlots.transformNestedProp)(elementPath, 'slotProps', 'legend.direction', directionValue, j);
42
+ });
43
+ });
44
+ });
45
+ const transformed = root.findJSXElements();
46
+ return transformed.toSource(printOptions);
47
+ }
48
+ function mapFix(v) {
49
+ switch (v) {
50
+ case 'row':
51
+ return 'horizontal';
52
+ case 'column':
53
+ return 'vertical';
54
+ default:
55
+ return v;
56
+ }
57
+ }
@@ -5,8 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = transformer;
8
+ var _renameAdapterDateFnsImports = _interopRequireDefault(require("../rename-adapter-date-fns-imports"));
8
9
  var _renameAndMoveFieldValueType = _interopRequireDefault(require("../rename-and-move-field-value-type"));
9
10
  function transformer(file, api, options) {
11
+ file.source = (0, _renameAdapterDateFnsImports.default)(file, api, options);
10
12
  file.source = (0, _renameAndMoveFieldValueType.default)(file, api, options);
11
13
  return file.source;
12
14
  }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = transformer;
7
+ var _renameImports = require("../../../util/renameImports");
8
+ function transformer(file, api, options) {
9
+ const j = api.jscodeshift;
10
+ const root = j(file.source);
11
+ const printOptions = options.printOptions || {
12
+ quote: 'single',
13
+ trailingComma: true
14
+ };
15
+ (0, _renameImports.renameImports)({
16
+ j,
17
+ root,
18
+ packageNames: ['@mui/x-date-pickers', '@mui/x-date-pickers-pro'],
19
+ imports: [{
20
+ oldEndpoint: 'AdapterDateFns',
21
+ newEndpoint: 'AdapterDateFnsV2',
22
+ importsMapping: {
23
+ AdapterDateFns: 'AdapterDateFns'
24
+ }
25
+ }, {
26
+ oldEndpoint: 'AdapterDateFnsV3',
27
+ newEndpoint: 'AdapterDateFns',
28
+ importsMapping: {
29
+ AdapterDateFns: 'AdapterDateFns'
30
+ }
31
+ }, {
32
+ oldEndpoint: 'AdapterDateFnsJalali',
33
+ newEndpoint: 'AdapterDateFnsJalaliV2',
34
+ importsMapping: {
35
+ AdapterDateFnsJalali: 'AdapterDateFnsJalali'
36
+ }
37
+ }, {
38
+ oldEndpoint: 'AdapterDateFnsJalaliV3',
39
+ newEndpoint: 'AdapterDateFnsJalali',
40
+ importsMapping: {
41
+ AdapterDateFnsJalali: 'AdapterDateFnsJalali'
42
+ }
43
+ }]
44
+ });
45
+ return root.toSource(printOptions);
46
+ }