@mui/x-codemod 8.0.0-alpha.10 → 8.0.0-alpha.11
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
|
@@ -242,6 +242,20 @@ Renames `labelFontSize` and `tickFontSize` props to the corresponding `xxxStyle`
|
|
|
242
242
|
/>
|
|
243
243
|
```
|
|
244
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
|
+
|
|
245
259
|
### Data Grid codemods
|
|
246
260
|
|
|
247
261
|
#### `preset-safe` for Data Grid v8.0.0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/x-codemod",
|
|
3
|
-
"version": "8.0.0-alpha.
|
|
3
|
+
"version": "8.0.0-alpha.11",
|
|
4
4
|
"bin": "./codemod.js",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "MUI Team",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"@babel/traverse": "^7.26.7",
|
|
31
31
|
"jscodeshift": "17.1.2",
|
|
32
32
|
"yargs": "^17.7.2",
|
|
33
|
-
"@mui/x-internals": "8.0.0-alpha.
|
|
33
|
+
"@mui/x-internals": "8.0.0-alpha.11"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/jscodeshift": "^0.12.0",
|
|
@@ -12,6 +12,7 @@ var _replaceLegendDirectionValues = _interopRequireDefault(require("../replace-l
|
|
|
12
12
|
var _replaceLegendPositionValues = _interopRequireDefault(require("../replace-legend-position-values"));
|
|
13
13
|
var _removeExperimentalMarkRendering = _interopRequireDefault(require("../remove-experimental-mark-rendering"));
|
|
14
14
|
var _renameLegendPositionType = _interopRequireDefault(require("../rename-legend-position-type"));
|
|
15
|
+
var _removeOnAxisClickHandler = _interopRequireDefault(require("../remove-on-axis-click-handler"));
|
|
15
16
|
function transformer(file, api, options) {
|
|
16
17
|
file.source = (0, _renameLegendToSlotsLegend.default)(file, api, options);
|
|
17
18
|
file.source = (0, _renameResponsiveChartContainer.default)(file, api, options);
|
|
@@ -20,5 +21,6 @@ function transformer(file, api, options) {
|
|
|
20
21
|
file.source = (0, _replaceLegendPositionValues.default)(file, api, options);
|
|
21
22
|
file.source = (0, _removeExperimentalMarkRendering.default)(file, api, options);
|
|
22
23
|
file.source = (0, _renameLegendPositionType.default)(file, api, options);
|
|
24
|
+
file.source = (0, _removeOnAxisClickHandler.default)(file, api, options);
|
|
23
25
|
return file.source;
|
|
24
26
|
}
|
|
@@ -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
|
+
}
|