@mui/x-codemod 8.0.0-alpha.9 → 8.0.0-beta.2

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
@@ -29,7 +29,7 @@ Options:
29
29
  --jscodeshift Pass options directly to jscodeshift [array]
30
30
 
31
31
  Examples:
32
- npx @mui/x-codemod@next v7.0.0/preset-safe src
32
+ npx @mui/x-codemod@next v8.0.0/preset-safe src
33
33
  npx @mui/x-codemod@next v6.0.0/component-rename-prop src --
34
34
  --component=DataGrid --from=prop --to=newProp
35
35
  ```
@@ -173,6 +173,24 @@ Replace `row` and `column` values by `horizontal` and `vertical` respectively.
173
173
  />
174
174
  ```
175
175
 
176
+ #### `replace-legend-position-values`
177
+
178
+ Replace `"left" | "middle" | "right"` values `"start" | "center" | "end"` respectively.
179
+ This is to align with the CSS values and reflect the RTL ability of the legend component.
180
+
181
+ ```diff
182
+ <BarChart
183
+ slotProps={{
184
+ legend: {
185
+ position: {
186
+ - horizontal: "left",
187
+ + horizontal: "start",
188
+ }
189
+ }
190
+ }}
191
+ />
192
+ ```
193
+
176
194
  #### `rename-responsive-chart-container`
177
195
 
178
196
  Renames `ResponsiveChartContainer` and `ResponsiveChartContainerPro` by `ChartContainer` and `ChartContainerPro` which have the same behavior in v8.
@@ -188,6 +206,15 @@ Renames `ResponsiveChartContainer` and `ResponsiveChartContainerPro` by `ChartCo
188
206
  +</ChartContainer>
189
207
  ```
190
208
 
209
+ #### `rename-legend-position-type`
210
+
211
+ Renames `LegendPosition` to `Position`.
212
+
213
+ ```diff
214
+ -import { LegendPosition } from '@mui/x-charts/ChartsLegend';
215
+ +import { Position } from '@mui/x-charts/models';
216
+ ```
217
+
191
218
  > [!WARNING]
192
219
  > If you imported both `ResponsiveChartContainer` and `ChartContainer` in the same file, you might end up with duplicated import.
193
220
  > Verify the git diff to remove the duplicate.
@@ -215,6 +242,73 @@ Renames `labelFontSize` and `tickFontSize` props to the corresponding `xxxStyle`
215
242
  />
216
243
  ```
217
244
 
245
+ #### `remove-on-axis-click-handler`
246
+
247
+ Remove the `<ChartsOnAxisClickHandler />` and move the associated `onAxisClick` prop to its parent.
248
+
249
+ > [!WARNING]
250
+ > This codemode does not work if component got renamed or if the handler is not a direct child of the container.
251
+
252
+ ```diff
253
+ + <ChartContainer onAxisClick={() => {}}>
254
+ - <ChartContainer>
255
+ - <ChartsOnAxisClickHandler onAxisClick={() => {}} />
256
+ </ChartContainer>
257
+ ```
258
+
259
+ #### `rename-unstable-use-series`
260
+
261
+ Remove `unstable_` prefix from `useSeries` and `use*Series` hooks, as they have now become stable.
262
+
263
+ ```diff
264
+ import {
265
+ - unstable_useSeries,
266
+ + useSeries,
267
+ - unstable_usePieSeries,
268
+ + usePieSeries,
269
+ - unstable_useLineSeries,
270
+ + useLineSeries,
271
+ - unstable_useBarSeries,
272
+ + useBarSeries,
273
+ - unstable_useScatterSeries,
274
+ + useScatterSeries,
275
+ } from '@mui/x-charts/hooks';
276
+ import {
277
+ - unstable_useHeatmapSeries,
278
+ + useHeatmapSeries,
279
+ } from '@mui/x-charts-pro/hooks';
280
+ ```
281
+
282
+ #### `rename-sparkline-colors-to-color`
283
+
284
+ Renames the `colors` prop of a `SparkLineChart` to `color` and accesses its first element.
285
+
286
+ ```diff
287
+ <SparkLineChart
288
+ - colors={['red']}
289
+ + color={'red'}
290
+ />
291
+ ```
292
+
293
+ If `colors` is a function, it will be wrapped in another function that returns its first element.
294
+
295
+ ```diff
296
+ <SparkLineChart
297
+ - colors={fn}
298
+ + color={typeof fn === 'function' ? mode => fn(mode)[0] : fn[0]}
299
+ />
300
+ ```
301
+
302
+ If there are cases that the codemod cannot handle, you should see a comment with a `mui-x-codemod` prefix in the code.
303
+
304
+ ```diff
305
+ <SparkLineChart
306
+ - colors={(mode) => (mode === 'light' ? ['black'] : ['white'])}
307
+ + /* mui-x-codemod: We renamed the `colors` prop to `color`, but didn't change the value. Please ensure sure this prop receives a string or a function that returns a string. */
308
+ + color={(mode) => (mode === 'light' ? ['black'] : ['white'])}
309
+ />
310
+ ```
311
+
218
312
  ### Data Grid codemods
219
313
 
220
314
  #### `preset-safe` for Data Grid v8.0.0
@@ -230,6 +324,12 @@ npx @mui/x-codemod@next v8.0.0/data-grid/preset-safe <path|folder>
230
324
  The list includes these transformers
231
325
 
232
326
  - [`remove-stabilized-v8-experimentalFeatures`](#remove-stabilized-v8-experimentalFeatures)
327
+ - [`remove-props`](#remove-props)
328
+ - [`rename-props`](#rename-props)
329
+ - [`rename-imports`](#rename-imports)
330
+ - [`reform-row-selection-model`](#reform-row-selection-model)
331
+ - [`rename-package`](#rename-package)
332
+ - [`add-showToolbar-prop`](#add-showToolbar-prop)
233
333
 
234
334
  #### `remove-stabilized-v8-experimentalFeatures`
235
335
 
@@ -249,6 +349,141 @@ Remove feature flags for stabilized `experimentalFeatures`.
249
349
  npx @mui/x-codemod@next v8.0.0/data-grid/remove-stabilized-experimentalFeatures <path>
250
350
  ```
251
351
 
352
+ #### `remove-props`
353
+
354
+ Remove props that are no longer supported.
355
+
356
+ The list includes these props:
357
+
358
+ - `indeterminateCheckboxAction`
359
+ - `rowPositionsDebounceMs`
360
+ - `resetPageOnSortFilter`
361
+
362
+ ```diff
363
+ <DataGrid
364
+ - indeterminateCheckboxAction="deselect"
365
+ - rowPositionsDebounceMs={100}
366
+ - resetPageOnSortFilter
367
+ />
368
+ ```
369
+
370
+ <!-- #default-branch-switch -->
371
+
372
+ ```bash
373
+ npx @mui/x-codemod@next v8.0.0/data-grid/remove-props <path>
374
+ ```
375
+
376
+ #### `rename-props`
377
+
378
+ Rename props to the new ones.
379
+
380
+ The list includes these props:
381
+
382
+ - `unstable_rowSpanning` to `rowSpanning`
383
+ - `unstable_dataSource` to `dataSource`
384
+ - `unstable_dataSourceCache` to `dataSourceCache`
385
+ - `unstable_lazyLoading` to `lazyLoading`
386
+ - `unstable_lazyLoadingRequestThrottleMs` to `lazyLoadingRequestThrottleMs`
387
+ - `unstable_onDataSourceError` to `onDataSourceError`
388
+
389
+ ```diff
390
+ <DataGrid
391
+ - unstable_rowSpanning
392
+ - unstable_dataSource={dataSource}
393
+ - unstable_dataSourceCache={dataSourceCache}
394
+ - unstable_lazyLoading
395
+ - unstable_lazyLoadingRequestThrottleMs={100}
396
+ - unstable_onDataSourceError={() => {}}
397
+ + rowSpanning
398
+ + dataSource={dataSource}
399
+ + dataSourceCache={dataSourceCache}
400
+ + lazyLoading
401
+ + lazyLoadingRequestThrottleMs={100}
402
+ + onDataSourceError={() => {}}
403
+ />
404
+ ```
405
+
406
+ <!-- #default-branch-switch -->
407
+
408
+ ```bash
409
+ npx @mui/x-codemod@next v8.0.0/data-grid/rename-props <path>
410
+ ```
411
+
412
+ #### `rename-imports`
413
+
414
+ This codemod renames the imports of the Data Grid components. The list includes these imports:
415
+
416
+ - `selectedGridRowsSelector` to `gridRowSelectionIdsSelector`
417
+ - `selectedGridRowsCountSelector` to `gridRowSelectionCountSelector`
418
+
419
+ ```diff
420
+ -import { selectedGridRowsSelector, selectedGridRowsCountSelector } from '@mui/x-data-grid';
421
+ +import { gridRowSelectionIdsSelector, gridRowSelectionCountSelector } from '@mui/x-data-grid';
422
+ ```
423
+
424
+ <!-- #default-branch-switch -->
425
+
426
+ ```bash
427
+ npx @mui/x-codemod@next v8.0.0/data-grid/rename-imports <path>
428
+ ```
429
+
430
+ #### `reform-row-selection-model`
431
+
432
+ Reforms the controlled `rowSelectionModel` prop value to the new one.
433
+
434
+ ```diff
435
+ -const [rowSelectionModel, setRowSelectionModel] = React.useState([1, 2]);
436
+ +const [rowSelectionModel, setRowSelectionModel] = React.useState({
437
+ + type: 'include',
438
+ + ids: new Set([1, 2]),
439
+ +});
440
+
441
+ <DataGrid
442
+ rowSelectionModel={rowSelectionModel}
443
+ onRowSelectionModelChange={setRowSelectionModel}
444
+ />
445
+ ```
446
+
447
+ <!-- #default-branch-switch -->
448
+
449
+ ```bash
450
+ npx @mui/x-codemod@next v8.0.0/data-grid/reform-row-selection-model <path>
451
+ ```
452
+
453
+ #### `rename-package`
454
+
455
+ Reorganizes the imports moved from `@mui/x-data-grid-pro` and `@mui/x-data-grid-premium`.
456
+
457
+ ```diff
458
+ -import { LicenseInfo } from '@mui/x-data-grid-pro';
459
+ +import { LicenseInfo } from '@mui/x-license';
460
+ ```
461
+
462
+ <!-- #default-branch-switch -->
463
+
464
+ ```bash
465
+ npx @mui/x-codemod@next v8.0.0/data-grid/rename-package <path>
466
+ ```
467
+
468
+ #### `add-showToolbar-prop`
469
+
470
+ Adds the `showToolbar` prop to the Data Grid components that are using `slots.toolbar` prop.
471
+
472
+ ```diff
473
+ <DataGridPremium
474
+ slots={{
475
+ toolbar: GridToolbar,
476
+ }}
477
+ + showToolbar
478
+ />
479
+ ```
480
+
481
+ <!-- #default-branch-switch -->
482
+
483
+ ```bash
484
+ npx @mui/x-codemod@next v8.0.0/data-grid/add-showToolbar-prop <path>
485
+ ```
486
+
252
487
  ### Pickers codemods
253
488
 
254
489
  #### `preset-safe` for Pickers v8.0.0
@@ -264,7 +499,7 @@ npx @mui/x-codemod@next v8.0.0/pickers/preset-safe <path|folder>
264
499
  The list includes these transformers
265
500
 
266
501
  - [`rename-adapter-date-fns-imports`](#rename-adapter-date-fns-imports)
267
- - [`rename-and-move-field-value-type`](#rename-and-move-field-value-type)
502
+ - [`rename-type-imports`](#rename-type-imports)
268
503
 
269
504
  #### `rename-adapter-date-fns-imports`
270
505
 
@@ -296,13 +531,25 @@ The list includes these transformers
296
531
  npx @mui/x-codemod@next v8.0.0/pickers/rename-adapter-date-fns-imports <path>
297
532
  ```
298
533
 
299
- #### `rename-and-move-field-value-type`
534
+ #### `rename-type-imports`
535
+
536
+ Renames:
300
537
 
301
- Renames `FieldValueType` to `PickerValueType`.
538
+ - `usePickersTranslations` to `usePickerTranslations`
539
+ - `usePickersContext` to `usePickerContext`
540
+ - `FieldValueType` to `PickerValueType`
541
+ - `RangeFieldSection` to `FieldRangeSection`
542
+ - `PickerShortcutChangeImportance` to `PickerChangeImportance`
302
543
 
303
544
  ```diff
545
+ -import { usePickersTranslations, usePickersContext } from '@mui/x-date-pickers/hooks';
546
+ +import { usePickerTranslations, usePickerContext } from '@mui/x-date-pickers/hooks';
304
547
  -import { FieldValueType } from '@mui/x-date-pickers';
305
548
  +import { PickerValueType } from '@mui/x-date-pickers';
549
+ -import { RangeFieldSection } from '@mui/x-date-pickers-pro/models';
550
+ +import { FieldRangeSection } from '@mui/x-date-pickers-pro/models';
551
+ -import { PickerShortcutChangeImportance } from '@mui/x-date-pickers/PickersShortcuts';
552
+ +import { PickerChangeImportance } from '@mui/x-date-pickers/models';
306
553
 
307
554
  interface MyComponentProps {
308
555
  - valueType: FieldValueType;
@@ -315,7 +562,7 @@ Renames `FieldValueType` to `PickerValueType`.
315
562
  <!-- #default-branch-switch -->
316
563
 
317
564
  ```bash
318
- npx @mui/x-codemod@next v8.0.0/pickers/rename-and-move-field-value-type <path>
565
+ npx @mui/x-codemod@next v8.0.0/pickers/rename-type-imports <path>
319
566
  ```
320
567
 
321
568
  ## v7.0.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-codemod",
3
- "version": "8.0.0-alpha.9",
3
+ "version": "8.0.0-beta.2",
4
4
  "bin": "./codemod.js",
5
5
  "private": false,
6
6
  "author": "MUI Team",
@@ -25,17 +25,17 @@
25
25
  "url": "https://opencollective.com/mui-org"
26
26
  },
27
27
  "dependencies": {
28
- "@babel/core": "^7.26.0",
29
- "@babel/runtime": "^7.26.0",
30
- "@babel/traverse": "^7.26.5",
28
+ "@babel/core": "^7.26.10",
29
+ "@babel/runtime": "^7.26.10",
30
+ "@babel/traverse": "^7.26.10",
31
31
  "jscodeshift": "17.1.2",
32
32
  "yargs": "^17.7.2",
33
- "@mui/x-internals": "8.0.0-alpha.9"
33
+ "@mui/x-internals": "8.0.0-beta.2"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/jscodeshift": "^0.12.0",
37
37
  "dayjs": "^1.11.13",
38
- "moment-timezone": "^0.5.46",
38
+ "moment-timezone": "^0.5.47",
39
39
  "rimraf": "^6.0.1"
40
40
  },
41
41
  "sideEffects": false,
@@ -9,11 +9,20 @@ var _renameLegendToSlotsLegend = _interopRequireDefault(require("../rename-legen
9
9
  var _renameResponsiveChartContainer = _interopRequireDefault(require("../rename-responsive-chart-container"));
10
10
  var _renameLabelAndTickFontSize = _interopRequireDefault(require("../rename-label-and-tick-font-size"));
11
11
  var _replaceLegendDirectionValues = _interopRequireDefault(require("../replace-legend-direction-values"));
12
+ var _replaceLegendPositionValues = _interopRequireDefault(require("../replace-legend-position-values"));
13
+ var _removeExperimentalMarkRendering = _interopRequireDefault(require("../remove-experimental-mark-rendering"));
14
+ var _renameLegendPositionType = _interopRequireDefault(require("../rename-legend-position-type"));
15
+ var _removeOnAxisClickHandler = _interopRequireDefault(require("../remove-on-axis-click-handler"));
16
+ var _renameUnstableUseSeries = _interopRequireDefault(require("../rename-unstable-use-series"));
12
17
  function transformer(file, api, options) {
13
18
  file.source = (0, _renameLegendToSlotsLegend.default)(file, api, options);
14
19
  file.source = (0, _renameResponsiveChartContainer.default)(file, api, options);
15
20
  file.source = (0, _renameLabelAndTickFontSize.default)(file, api, options);
16
- file.source = (0, _renameLabelAndTickFontSize.default)(file, api, options);
17
21
  file.source = (0, _replaceLegendDirectionValues.default)(file, api, options);
22
+ file.source = (0, _replaceLegendPositionValues.default)(file, api, options);
23
+ file.source = (0, _removeExperimentalMarkRendering.default)(file, api, options);
24
+ file.source = (0, _renameLegendPositionType.default)(file, api, options);
25
+ file.source = (0, _removeOnAxisClickHandler.default)(file, api, options);
26
+ file.source = (0, _renameUnstableUseSeries.default)(file, api, options);
18
27
  return file.source;
19
28
  }
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = transformer;
7
+ /**
8
+ * @param {import('jscodeshift').FileInfo} file
9
+ * @param {import('jscodeshift').API} api
10
+ */
11
+ function transformer(file, api, options) {
12
+ const j = api.jscodeshift;
13
+ const printOptions = options.printOptions;
14
+ const root = j(file.source);
15
+
16
+ // Move the handler to the container
17
+ root.findJSXElements().filter(path => Boolean(path.node.openingElement) && path.node.openingElement.name.type === 'JSXIdentifier' && path.node.openingElement.name.name.includes('ChartContainer')).forEach(path => {
18
+ // We find the <ChartsOnAxisClickHandler /> node
19
+ const clickHandler = path.node.children?.find(child => {
20
+ if (child.type !== 'JSXElement') {
21
+ return false;
22
+ }
23
+ if (child.openingElement.name.type !== 'JSXIdentifier') {
24
+ return false;
25
+ }
26
+ return child.openingElement.name.name === 'ChartsOnAxisClickHandler';
27
+ });
28
+ if (!clickHandler) {
29
+ return;
30
+ }
31
+ const clickCallback = clickHandler.openingElement.attributes?.find(attr => attr.type === 'JSXAttribute' && attr.name.name === 'onAxisClick');
32
+ if (!clickCallback) {
33
+ return;
34
+ }
35
+
36
+ // Move the callback to the container
37
+ path.node.openingElement.attributes?.push(clickCallback);
38
+
39
+ // Remove the children
40
+ path.node.children = path.node.children?.filter(child => {
41
+ if (child.type !== 'JSXElement') {
42
+ return true;
43
+ }
44
+ if (child.openingElement.name.type !== 'JSXIdentifier') {
45
+ return true;
46
+ }
47
+ return child.openingElement.name.name !== 'ChartsOnAxisClickHandler';
48
+ });
49
+ });
50
+
51
+ // Remove nested import
52
+ root.find(j.ImportDeclaration, {
53
+ source: {
54
+ value: '@mui/x-charts/ChartsOnAxisClickHandler'
55
+ }
56
+ }).remove();
57
+
58
+ // Remove global import
59
+ root.find(j.ImportDeclaration).forEach(path => {
60
+ if (typeof path.node.source.value !== 'string') {
61
+ return;
62
+ }
63
+ if (!path.node.source.value.includes('@mui/x-charts')) {
64
+ return;
65
+ }
66
+ path.node.specifiers = path.node.specifiers?.filter(specifier => {
67
+ if (specifier.type !== 'ImportSpecifier') {
68
+ return true;
69
+ }
70
+ return specifier.imported.name !== 'ChartsOnAxisClickHandler';
71
+ });
72
+ });
73
+ return root.toSource(printOptions);
74
+ }
@@ -10,16 +10,18 @@ function transformer(file, api, options) {
10
10
  const root = j(file.source);
11
11
  const printOptions = options.printOptions || {
12
12
  quote: 'single',
13
- trailingComma: true
13
+ trailingComma: true,
14
+ wrapColumn: 40
14
15
  };
15
16
  (0, _renameImports.renameImports)({
16
17
  j,
17
18
  root,
18
- packageNames: ['@mui/x-date-pickers', '@mui/x-date-pickers-pro'],
19
+ packageNames: ['@mui/x-charts', '@mui/x-charts-pro'],
19
20
  imports: [{
20
- oldEndpoint: 'models',
21
+ oldEndpoint: 'ChartsLegend',
22
+ newEndpoint: 'models',
21
23
  importsMapping: {
22
- FieldValueType: 'PickerValueType'
24
+ LegendPosition: 'Position'
23
25
  }
24
26
  }]
25
27
  });
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = transformer;
7
+ /**
8
+ * @param {import('jscodeshift').FileInfo} file
9
+ * @param {import('jscodeshift').API} api
10
+ */
11
+ function transformer(file, api, options) {
12
+ const j = api.jscodeshift;
13
+ const printOptions = options.printOptions;
14
+ const root = j(file.source);
15
+ const componentNames = ['SparkLineChart'];
16
+ const props = {
17
+ colors: 'color'
18
+ };
19
+ const colorAttributes = root.find(j.JSXElement).filter(path => {
20
+ return componentNames.includes(path.value.openingElement.name.name);
21
+ }).find(j.JSXAttribute).filter(attribute => Object.keys(props).includes(attribute.node.name.name));
22
+ return colorAttributes.forEach(attribute => {
23
+ const colorsAttributeExpression = attribute.node.value?.type === 'JSXExpressionContainer' ? attribute.node.value.expression : null;
24
+ let colorAttributeExpression;
25
+ if (colorsAttributeExpression?.type === 'ArrayExpression') {
26
+ colorAttributeExpression = colorsAttributeExpression.elements[0];
27
+ } else if (colorsAttributeExpression?.type === 'Identifier') {
28
+ colorAttributeExpression = j.conditionalExpression(j.binaryExpression('===', j.unaryExpression('typeof', colorsAttributeExpression), j.literal('function')), j.arrowFunctionExpression([j.identifier('mode')], j.chainExpression(j.optionalMemberExpression(j.callExpression(colorsAttributeExpression, [j.identifier('mode')]), j.literal(0)))), colorsAttributeExpression);
29
+ } else {
30
+ // Don't know how to handle this case
31
+ }
32
+
33
+ // Only transform the value if we know how to handle it, otherwise rename the prop and add a comment
34
+ if (colorAttributeExpression) {
35
+ j(attribute).replaceWith(j.jsxAttribute(j.jsxIdentifier(props[attribute.node.name.name]), j.jsxExpressionContainer(colorAttributeExpression)));
36
+ } else {
37
+ j(attribute).replaceWith(j.jsxAttribute(j.jsxIdentifier(props[attribute.node.name.name]), attribute.node.value)).insertBefore(j.commentBlock(" mui-x-codemod: We renamed the `colors` prop to `color`, but didn't change the value. Please ensure sure this prop receives a string or a function that returns a string. "));
38
+ }
39
+ }).toSource(printOptions);
40
+ }
@@ -0,0 +1,33 @@
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
+ wrapColumn: 40
15
+ };
16
+ (0, _renameImports.renameImports)({
17
+ j,
18
+ root,
19
+ packageNames: ['@mui/x-charts', '@mui/x-charts-pro'],
20
+ imports: [{
21
+ oldEndpoint: 'hooks',
22
+ importsMapping: {
23
+ unstable_useSeries: 'useSeries',
24
+ unstable_usePieSeries: 'usePieSeries',
25
+ unstable_useLineSeries: 'useLineSeries',
26
+ unstable_useBarSeries: 'useBarSeries',
27
+ unstable_useScatterSeries: 'useScatterSeries',
28
+ unstable_useHeatmapSeries: 'useHeatmapSeries'
29
+ }
30
+ }]
31
+ });
32
+ return root.toSource(printOptions);
33
+ }
@@ -0,0 +1,60 @@
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 position = 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 === 'position');
36
+ const horizontal = position?.value?.properties?.find(v => v?.key?.name === 'horizontal');
37
+ if (horizontal === undefined || horizontal?.value === undefined || horizontal?.value?.value === undefined) {
38
+ return;
39
+ }
40
+ const horizontalValue = horizontal.value;
41
+ horizontalValue.value = mapFix(horizontalValue.value);
42
+ (0, _addComponentsSlots.transformNestedProp)(elementPath, 'slotProps', 'legend.position.horizontal', horizontalValue, j);
43
+ });
44
+ });
45
+ });
46
+ const transformed = root.findJSXElements();
47
+ return transformed.toSource(printOptions);
48
+ }
49
+ function mapFix(v) {
50
+ switch (v) {
51
+ case 'left':
52
+ return 'start';
53
+ case 'right':
54
+ return 'end';
55
+ case 'middle':
56
+ return 'center';
57
+ default:
58
+ return v;
59
+ }
60
+ }
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = transformer;
7
+ function transformer(file, api, options) {
8
+ const j = api.jscodeshift;
9
+ const root = j(file.source);
10
+
11
+ // List of DataGrid components
12
+ const dataGridComponents = new Set(['DataGrid', 'DataGridPro', 'DataGridPremium']);
13
+ // List of allowed import sources
14
+ const dataGridSources = new Set(['@mui/x-data-grid', '@mui/x-data-grid-pro', '@mui/x-data-grid-premium']);
15
+
16
+ // Find relevant DataGrid imports
17
+ const importedDataGrids = new Set();
18
+ root.find(j.ImportDeclaration).forEach(path => {
19
+ if (dataGridSources.has(path.node.source.value)) {
20
+ path.node.specifiers?.forEach(specifier => {
21
+ if (specifier.imported && dataGridComponents.has(specifier.imported.name)) {
22
+ const localName = specifier.local?.name;
23
+ if (localName) {
24
+ importedDataGrids.add(localName);
25
+ }
26
+ }
27
+ });
28
+ }
29
+ });
30
+ if (importedDataGrids.size === 0) {
31
+ return file.source;
32
+ }
33
+ root.find(j.JSXOpeningElement).forEach(path => {
34
+ if (!importedDataGrids.has(path.node.name.name)) {
35
+ return;
36
+ }
37
+ let hasSlotsToolbar = false;
38
+ let hasShowToolbar = false;
39
+ path.node.attributes?.forEach(attr => {
40
+ if (attr.type === 'JSXAttribute') {
41
+ if (attr.name.name === 'slots') {
42
+ if (attr.value && attr.value.type === 'JSXExpressionContainer' && attr.value.expression.type === 'ObjectExpression') {
43
+ hasSlotsToolbar = attr.value.expression.properties.some(prop => prop.key.name === 'toolbar');
44
+ }
45
+ }
46
+ if (attr.name.name === 'showToolbar') {
47
+ hasShowToolbar = true;
48
+ }
49
+ }
50
+ });
51
+ if (hasSlotsToolbar && !hasShowToolbar) {
52
+ path.node.attributes?.push(j.jsxAttribute(j.jsxIdentifier('showToolbar')));
53
+ }
54
+ });
55
+ const printOptions = options.printOptions || {
56
+ quote: 'single',
57
+ trailingComma: true
58
+ };
59
+ return root.toSource(printOptions);
60
+ }
@@ -6,7 +6,19 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = transformer;
8
8
  var _removeStabilizedExperimentalFeatures = _interopRequireDefault(require("../remove-stabilized-experimentalFeatures"));
9
+ var _removeProps = _interopRequireDefault(require("../remove-props"));
10
+ var _renameProps = _interopRequireDefault(require("../rename-props"));
11
+ var _reformRowSelectionModel = _interopRequireDefault(require("../reform-row-selection-model"));
12
+ var _renameImports = _interopRequireDefault(require("../rename-imports"));
13
+ var _renamePackage = _interopRequireDefault(require("../rename-package"));
14
+ var _addShowToolbarProp = _interopRequireDefault(require("../add-showToolbar-prop"));
9
15
  function transformer(file, api, options) {
10
16
  file.source = (0, _removeStabilizedExperimentalFeatures.default)(file, api, options);
17
+ file.source = (0, _renameProps.default)(file, api, options);
18
+ file.source = (0, _removeProps.default)(file, api, options);
19
+ file.source = (0, _reformRowSelectionModel.default)(file, api, options);
20
+ file.source = (0, _renameImports.default)(file, api, options);
21
+ file.source = (0, _renamePackage.default)(file, api, options);
22
+ file.source = (0, _addShowToolbarProp.default)(file, api, options);
11
23
  return file.source;
12
24
  }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = transformer;
7
+ // @ts-nocheck - TODO: fix this
8
+
9
+ const componentNames = ['DataGrid', 'DataGridPro', 'DataGridPremium'];
10
+ const attrName = 'rowSelectionModel';
11
+ function transformer(file, api, options) {
12
+ const j = api.jscodeshift;
13
+ const root = j(file.source);
14
+
15
+ // Step 1: Collect variable names used in <DataGrid rowSelectionModel={...} />
16
+ const usedInDataGrid = new Set();
17
+ root.find(j.JSXOpeningElement).filter(path => j.JSXIdentifier.check(path.node.name) && componentNames.some(name => name === path.node.name.name)).forEach(path => {
18
+ path.node.attributes?.forEach(attr => {
19
+ if (j.JSXAttribute.check(attr) && j.JSXIdentifier.check(attr.name) && attr.name.name === attrName && attr.value && j.JSXExpressionContainer.check(attr.value) && j.Identifier.check(attr.value.expression)) {
20
+ usedInDataGrid.add(attr.value.expression.name);
21
+ }
22
+ });
23
+ });
24
+ if (usedInDataGrid.size === 0) {
25
+ return file.source; // No relevant transformations needed
26
+ }
27
+
28
+ // Step 2: Convert only relevant `useState` or `useMemo` variables
29
+ root.find(j.VariableDeclarator).filter(path => j.ArrayPattern.check(path.node.id) && path.node.id.elements.length === 2 && j.Identifier.check(path.node.id.elements[0]) && usedInDataGrid.has(path.node.id.elements[0].name) &&
30
+ // Only modify if used in `componentNames`
31
+ path.node.init && j.CallExpression.check(path.node.init) && (j.MemberExpression.check(path.node.init.callee) && j.Identifier.check(path.node.init.callee.object) && ['React', 'useState', 'useMemo'].includes(path.node.init.callee.object.name) || ['useState', 'useMemo'].includes(path.node.init.callee.name)) &&
32
+ // Handle direct calls
33
+ path.node.init.arguments.length > 0 && (j.ArrayExpression.check(path.node.init.arguments[0]) || j.ArrowFunctionExpression.check(path.node.init.arguments[0]) && j.BlockStatement.check(path.node.init.arguments[0].body) === false && j.ArrayExpression.check(path.node.init.arguments[0].body))).forEach(path => {
34
+ const arrayExpression = j.ArrayExpression.check(path.node.init?.arguments[0]) ? path.node.init?.arguments[0] : path.node.init?.arguments[0]?.body;
35
+ const newObject = j.objectExpression([j.property('init', j.identifier('type'), j.literal('include')), j.property('init', j.identifier('ids'), j.newExpression(j.identifier('Set'), [arrayExpression]))]);
36
+ if (j.ArrayExpression.check(path.node.init.arguments[0])) {
37
+ path.node.init.arguments[0] = newObject;
38
+ } else {
39
+ path.node.init.arguments[0].body = newObject;
40
+ }
41
+ });
42
+ const printOptions = options?.printOptions || {
43
+ quote: 'single',
44
+ trailingComma: true
45
+ };
46
+ return root.toSource(printOptions);
47
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = transformer;
8
+ var _removeProps = _interopRequireDefault(require("../../../util/removeProps"));
9
+ const componentNames = ['DataGrid', 'DataGridPro', 'DataGridPremium'];
10
+ const props = ['indeterminateCheckboxAction', 'rowPositionsDebounceMs', 'resetPageOnSortFilter'];
11
+ function transformer(file, api, options) {
12
+ const j = api.jscodeshift;
13
+ const root = j(file.source);
14
+ const printOptions = options.printOptions || {
15
+ quote: 'single',
16
+ trailingComma: true
17
+ };
18
+ return (0, _removeProps.default)({
19
+ root,
20
+ j,
21
+ props,
22
+ componentNames
23
+ }).toSource(printOptions);
24
+ }
@@ -0,0 +1,28 @@
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-data-grid', '@mui/x-data-grid-pro', '@mui/x-data-grid-premium'],
19
+ imports: [{
20
+ oldEndpoint: 'DataGrid',
21
+ importsMapping: {
22
+ selectedGridRowsSelector: 'gridRowSelectionIdsSelector',
23
+ selectedGridRowsCountSelector: 'gridRowSelectionCountSelector'
24
+ }
25
+ }]
26
+ });
27
+ return root.toSource(printOptions);
28
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = transformer;
7
+ // TODO: Make it generic and move to utils
8
+ function transformer(file, api, options) {
9
+ const j = api.jscodeshift;
10
+ const root = j(file.source);
11
+ root.find(j.ImportDeclaration).filter(path => ['@mui/x-data-grid-pro', '@mui/x-data-grid-premium'].includes(path.node.source.value)).forEach(path => {
12
+ const specifiers = path.node.specifiers;
13
+ const filteredSpecifiers = specifiers.filter(spec => !(j.ImportSpecifier.check(spec) && spec.imported.name === 'LicenseInfo'));
14
+
15
+ // If `LicenseInfo` was found and removed
16
+ if (filteredSpecifiers.length !== specifiers.length) {
17
+ const licenseImport = j.importDeclaration([j.importSpecifier(j.identifier('LicenseInfo'))], j.stringLiteral('@mui/x-license'));
18
+ if (filteredSpecifiers.length > 0) {
19
+ // Keep other imports but remove `LicenseInfo`
20
+ path.node.specifiers = filteredSpecifiers;
21
+ // Insert new import right after the modified import
22
+ j(path).insertAfter(licenseImport);
23
+ } else {
24
+ // Remove import entirely and insert new one at the same position
25
+ j(path).replaceWith(licenseImport);
26
+ }
27
+ }
28
+ });
29
+ const printOptions = options?.printOptions || {
30
+ quote: 'single',
31
+ trailingComma: true
32
+ };
33
+ return root.toSource(printOptions);
34
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ var _path = _interopRequireDefault(require("path"));
5
+ var _chai = require("chai");
6
+ var _jscodeshift = _interopRequireDefault(require("jscodeshift"));
7
+ var _ = _interopRequireDefault(require("."));
8
+ var _readFile = _interopRequireDefault(require("../../../util/readFile"));
9
+ function read(fileName) {
10
+ return (0, _readFile.default)(_path.default.join(__dirname, fileName));
11
+ }
12
+ describe('v8.0.0/data-grid', () => {
13
+ describe('rename package', () => {
14
+ it('transforms props as needed', () => {
15
+ const actual = (0, _.default)({
16
+ source: read('./actual.spec.js')
17
+ }, {
18
+ jscodeshift: _jscodeshift.default
19
+ });
20
+ const expected = read('./expected.spec.js');
21
+ (0, _chai.expect)(actual).to.equal(expected, 'The transformed version should be correct');
22
+ });
23
+ it('should be idempotent', () => {
24
+ const actual = (0, _.default)({
25
+ source: read('./expected.spec.js')
26
+ }, {
27
+ jscodeshift: _jscodeshift.default
28
+ });
29
+ const expected = read('./expected.spec.js');
30
+ (0, _chai.expect)(actual).to.equal(expected, 'The transformed version should be correct');
31
+ });
32
+ });
33
+ });
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = transformer;
8
+ var _renameProps = _interopRequireDefault(require("../../../util/renameProps"));
9
+ const componentNames = ['DataGrid', 'DataGridPro', 'DataGridPremium'];
10
+ const props = {
11
+ unstable_rowSpanning: 'rowSpanning',
12
+ unstable_dataSource: 'dataSource',
13
+ unstable_dataSourceCache: 'dataSourceCache',
14
+ unstable_lazyLoading: 'lazyLoading',
15
+ unstable_lazyLoadingRequestThrottleMs: 'lazyLoadingRequestThrottleMs',
16
+ unstable_onDataSourceError: 'onDataSourceError'
17
+ };
18
+ function transformer(file, api, options) {
19
+ const j = api.jscodeshift;
20
+ const root = j(file.source);
21
+ const printOptions = options.printOptions || {
22
+ quote: 'single',
23
+ trailingComma: true
24
+ };
25
+ return (0, _renameProps.default)({
26
+ root,
27
+ j,
28
+ props,
29
+ componentNames
30
+ }).toSource(printOptions);
31
+ }
@@ -6,9 +6,9 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = transformer;
8
8
  var _renameAdapterDateFnsImports = _interopRequireDefault(require("../rename-adapter-date-fns-imports"));
9
- var _renameAndMoveFieldValueType = _interopRequireDefault(require("../rename-and-move-field-value-type"));
9
+ var _renameTypeImports = _interopRequireDefault(require("../rename-type-imports"));
10
10
  function transformer(file, api, options) {
11
11
  file.source = (0, _renameAdapterDateFnsImports.default)(file, api, options);
12
- file.source = (0, _renameAndMoveFieldValueType.default)(file, api, options);
12
+ file.source = (0, _renameTypeImports.default)(file, api, options);
13
13
  return file.source;
14
14
  }
@@ -0,0 +1,50 @@
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
+ let root = j(file.source);
11
+ const printOptions = options.printOptions || {
12
+ quote: 'single',
13
+ trailingComma: true
14
+ };
15
+ root = (0, _renameImports.renameImports)({
16
+ j,
17
+ root,
18
+ packageNames: ['@mui/x-date-pickers', '@mui/x-date-pickers-pro'],
19
+ imports: [{
20
+ oldEndpoint: 'hooks',
21
+ importsMapping: {
22
+ usePickersTranslations: 'usePickerTranslations',
23
+ usePickersContext: 'usePickerContext'
24
+ }
25
+ }, {
26
+ oldEndpoint: 'models',
27
+ importsMapping: {
28
+ FieldValueType: 'PickerValueType'
29
+ }
30
+ }, {
31
+ oldEndpoint: 'PickersShortcuts',
32
+ newEndpoint: 'models',
33
+ importsMapping: {
34
+ PickerShortcutChangeImportance: 'PickerChangeImportance'
35
+ }
36
+ }]
37
+ });
38
+ root = (0, _renameImports.renameImports)({
39
+ j,
40
+ root,
41
+ packageNames: ['@mui/x-date-pickers-pro'],
42
+ imports: [{
43
+ oldEndpoint: 'models',
44
+ importsMapping: {
45
+ RangeFieldSection: 'FieldRangeSection'
46
+ }
47
+ }]
48
+ });
49
+ return root.toSource(printOptions);
50
+ }