@mui/x-codemod 6.0.0-alpha.9 → 6.0.0-beta.1
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 +399 -4
- package/codemod.js +1 -1
- package/package.json +4 -4
- package/util/addComponentsSlots.js +67 -0
- package/util/removeProps.js +22 -0
- package/util/renameComponentsSlots.js +31 -0
- package/util/renameProps.js +7 -8
- package/v6.0.0/component-rename-prop/index.js +3 -2
- package/v6.0.0/data-grid/column-menu-components-rename/index.js +50 -0
- package/v6.0.0/data-grid/preset-safe/index.js +20 -0
- package/v6.0.0/data-grid/remove-disableExtendRowFullWidth-prop/index.js +24 -0
- package/v6.0.0/data-grid/rename-rowsPerPageOptions-prop/index.js +26 -0
- package/v6.0.0/data-grid/rename-selectors-and-events/index.js +39 -0
- package/v6.0.0/data-grid/row-selection-props-rename/index.js +32 -0
- package/v6.0.0/pickers/adapter-change-import/index.js +56 -0
- package/v6.0.0/{localization-provider-rename-locale → pickers/localization-provider-rename-locale}/index.js +4 -3
- package/v6.0.0/pickers/migrate-to-components-componentsProps/index.js +101 -0
- package/v6.0.0/pickers/preset-safe/index.js +32 -0
- package/v6.0.0/pickers/rename-components-to-slots/index.js +62 -0
- package/v6.0.0/pickers/rename-should-disable-time/index.js +39 -0
- package/v6.0.0/pickers/replace-arrows-button-slot/index.js +41 -0
- package/v6.0.0/pickers/replace-tabs-props/index.js +53 -0
- package/v6.0.0/pickers/replace-toolbar-props-by-slot/index.js +69 -0
- package/v6.0.0/pickers/text-props-to-localeText/index.js +101 -0
- package/v6.0.0/pickers/view-components-rename/index.js +83 -0
- package/v6.0.0/pickers/view-components-rename-value-prop/index.js +22 -0
- package/v6.0.0/preset-safe/index.js +4 -2
|
@@ -0,0 +1,20 @@
|
|
|
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 _columnMenuComponentsRename = _interopRequireDefault(require("../column-menu-components-rename"));
|
|
9
|
+
var _rowSelectionPropsRename = _interopRequireDefault(require("../row-selection-props-rename"));
|
|
10
|
+
var _renameRowsPerPageOptionsProp = _interopRequireDefault(require("../rename-rowsPerPageOptions-prop"));
|
|
11
|
+
var _removeDisableExtendRowFullWidthProp = _interopRequireDefault(require("../remove-disableExtendRowFullWidth-prop"));
|
|
12
|
+
var _renameSelectorsAndEvents = _interopRequireDefault(require("../rename-selectors-and-events"));
|
|
13
|
+
function transformer(file, api, options) {
|
|
14
|
+
file.source = (0, _columnMenuComponentsRename.default)(file, api, options);
|
|
15
|
+
file.source = (0, _rowSelectionPropsRename.default)(file, api, options);
|
|
16
|
+
file.source = (0, _renameRowsPerPageOptionsProp.default)(file, api, options);
|
|
17
|
+
file.source = (0, _removeDisableExtendRowFullWidthProp.default)(file, api, options);
|
|
18
|
+
file.source = (0, _renameSelectorsAndEvents.default)(file, api, options);
|
|
19
|
+
return file.source;
|
|
20
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
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 _removeProps = _interopRequireDefault(require("../../../util/removeProps"));
|
|
9
|
+
const componentNames = ['DataGrid', 'DataGridPro', 'DataGridPremium'];
|
|
10
|
+
const props = ['disableExtendRowFullWidth'];
|
|
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,26 @@
|
|
|
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 = ['DataGrid', 'DataGridPro', 'DataGridPremium'];
|
|
10
|
+
const props = {
|
|
11
|
+
rowsPerPageOptions: 'pageSizeOptions'
|
|
12
|
+
};
|
|
13
|
+
function transformer(file, api, options) {
|
|
14
|
+
const j = api.jscodeshift;
|
|
15
|
+
const root = j(file.source);
|
|
16
|
+
const printOptions = options.printOptions || {
|
|
17
|
+
quote: 'single',
|
|
18
|
+
trailingComma: true
|
|
19
|
+
};
|
|
20
|
+
return (0, _renameProps.default)({
|
|
21
|
+
root,
|
|
22
|
+
j,
|
|
23
|
+
props,
|
|
24
|
+
componentNames
|
|
25
|
+
}).toSource(printOptions);
|
|
26
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = transformer;
|
|
7
|
+
const renamedSelectors = {
|
|
8
|
+
gridSelectionStateSelector: 'gridRowSelectionStateSelector',
|
|
9
|
+
gridVisibleSortedRowIdsSelector: 'gridExpandedSortedRowIdsSelector',
|
|
10
|
+
gridVisibleSortedRowEntriesSelector: 'gridExpandedSortedRowEntriesSelector',
|
|
11
|
+
gridVisibleRowCountSelector: 'gridExpandedRowCountSelector',
|
|
12
|
+
gridVisibleSortedTopLevelRowEntriesSelector: 'gridFilteredSortedTopLevelRowEntriesSelector',
|
|
13
|
+
gridVisibleTopLevelRowCountSelector: 'gridFilteredTopLevelRowCountSelector'
|
|
14
|
+
};
|
|
15
|
+
const renamedEvents = {
|
|
16
|
+
selectionChange: 'rowSelectionChange',
|
|
17
|
+
rowsScroll: 'scrollPositionChange'
|
|
18
|
+
};
|
|
19
|
+
function transformer(file, api, options) {
|
|
20
|
+
const j = api.jscodeshift;
|
|
21
|
+
const root = j(file.source);
|
|
22
|
+
const printOptions = options.printOptions || {
|
|
23
|
+
quote: 'single',
|
|
24
|
+
trailingComma: true
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// Rename the import and usage of renamed selectors
|
|
28
|
+
// - import { gridSelectionStateSelector } from '@mui/x-data-grid'
|
|
29
|
+
// + import { gridRowSelectionStateSelector } from '@mui/x-data-grid'
|
|
30
|
+
root.find(j.Identifier).filter(path => !!renamedSelectors[path.node.name]).replaceWith(path => j.identifier(renamedSelectors[path.node.name]));
|
|
31
|
+
|
|
32
|
+
// Rename the usage of renamed event literals
|
|
33
|
+
// - useGridApiEventHandler('selectionChange', handleEvent);
|
|
34
|
+
// - apiRef.current.subscribeEvent('selectionChange', handleEvent);
|
|
35
|
+
// + useGridApiEventHandler('rowSelectionChange', handleEvent);
|
|
36
|
+
// + apiRef.current.subscribeEvent('rowSelectionChange', handleEvent);
|
|
37
|
+
root.find(j.CallExpression).find(j.Literal).filter(path => !!renamedEvents[path.node.value]).replaceWith(path => j.literal(renamedEvents[path.node.value]));
|
|
38
|
+
return root.toSource(printOptions);
|
|
39
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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 props = {
|
|
10
|
+
selectionModel: 'rowSelectionModel',
|
|
11
|
+
onSelectionModelChange: 'onRowSelectionModelChange',
|
|
12
|
+
disableSelectionOnClick: 'disableRowSelectionOnClick',
|
|
13
|
+
disableMultipleSelection: 'disableMultipleRowSelection',
|
|
14
|
+
showCellRightBorder: 'showCellVerticalBorder',
|
|
15
|
+
showColumnRightBorder: 'showColumnVerticalBorder',
|
|
16
|
+
headerHeight: 'columnHeaderHeight'
|
|
17
|
+
};
|
|
18
|
+
const componentNames = ['DataGrid', 'DataGridPro', 'DataGridPremium'];
|
|
19
|
+
function transformer(file, api, options) {
|
|
20
|
+
const j = api.jscodeshift;
|
|
21
|
+
const root = j(file.source);
|
|
22
|
+
const printOptions = options.printOptions || {
|
|
23
|
+
quote: 'single',
|
|
24
|
+
trailingComma: true
|
|
25
|
+
};
|
|
26
|
+
return (0, _renameProps.default)({
|
|
27
|
+
root,
|
|
28
|
+
componentNames,
|
|
29
|
+
props,
|
|
30
|
+
j
|
|
31
|
+
}).toSource(printOptions);
|
|
32
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = transformer;
|
|
7
|
+
const adapters = {
|
|
8
|
+
'date-fns': 'AdapterDateFns',
|
|
9
|
+
'date-fns-jalali': 'AdapterDateFnsJalali',
|
|
10
|
+
dayjs: 'AdapterDayjs',
|
|
11
|
+
luxon: 'AdapterLuxon',
|
|
12
|
+
moment: 'AdapterMoment',
|
|
13
|
+
hijri: 'AdapterMomentHijri',
|
|
14
|
+
jalaali: 'AdapterMomentJalaali'
|
|
15
|
+
};
|
|
16
|
+
const getDateIoSubPackage = path => (path.node.source.value?.toString() ?? '').match(/@date-io\/(.*)/)?.[1];
|
|
17
|
+
function transformer(file, api, options) {
|
|
18
|
+
const j = api.jscodeshift;
|
|
19
|
+
const root = j(file.source);
|
|
20
|
+
const printOptions = options.printOptions || {
|
|
21
|
+
quote: 'single',
|
|
22
|
+
trailingComma: true
|
|
23
|
+
};
|
|
24
|
+
const matchingImports = root.find(j.ImportDeclaration).filter(path => {
|
|
25
|
+
const subPackage = getDateIoSubPackage(path);
|
|
26
|
+
return !!subPackage && !!adapters[subPackage];
|
|
27
|
+
});
|
|
28
|
+
const adapterVariableNames = {};
|
|
29
|
+
|
|
30
|
+
// Replace the default import specifier by an import specifiers
|
|
31
|
+
// - import WhateverDateFns from '@mui/x-date-pickers/MonthPicker'
|
|
32
|
+
// + import { AdapterDateFns } from '@mui/x-date-pickers/MonthPicker'
|
|
33
|
+
matchingImports.find(j.ImportDefaultSpecifier).replaceWith(path => {
|
|
34
|
+
const subPackage = getDateIoSubPackage(path.parentPath.parentPath);
|
|
35
|
+
const adapterVariableName = path.value.local?.name ?? '';
|
|
36
|
+
adapterVariableNames[adapterVariableName] = adapters[subPackage];
|
|
37
|
+
return j.importSpecifier(j.identifier(adapters[subPackage]));
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Rename the import declarations
|
|
41
|
+
// - import {} from '@date-io/date-fns'
|
|
42
|
+
// + import {} from '@mui/x-date-pickers/AdapterDateFns'
|
|
43
|
+
matchingImports.replaceWith(path => {
|
|
44
|
+
const subPackage = getDateIoSubPackage(path);
|
|
45
|
+
return j.importDeclaration(path.node.specifiers,
|
|
46
|
+
// copy over the existing import specifiers
|
|
47
|
+
j.stringLiteral(`@mui/x-date-pickers/${adapters[subPackage]}`) // Replace the source with our new source
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Rename the import usage
|
|
52
|
+
// - <LocalizationProvider dateAdapter={WhateverDateFns} />
|
|
53
|
+
// + <LocalizationProvider dateAdapter={AdapterDateFns} />
|
|
54
|
+
root.find(j.Identifier).filter(path => !!adapterVariableNames[path.node.name]).replaceWith(path => j.identifier(adapterVariableNames[path.node.name]));
|
|
55
|
+
return root.toSource(printOptions);
|
|
56
|
+
}
|
|
@@ -5,16 +5,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = transformer;
|
|
8
|
-
var _renameProps = _interopRequireDefault(require("
|
|
8
|
+
var _renameProps = _interopRequireDefault(require("../../../util/renameProps"));
|
|
9
9
|
function transformer(file, api, options) {
|
|
10
10
|
const j = api.jscodeshift;
|
|
11
11
|
const root = j(file.source);
|
|
12
12
|
const printOptions = options.printOptions;
|
|
13
13
|
return (0, _renameProps.default)({
|
|
14
14
|
root,
|
|
15
|
-
|
|
15
|
+
componentNames: ['LocalizationProvider'],
|
|
16
16
|
props: {
|
|
17
17
|
locale: 'adapterLocale'
|
|
18
|
-
}
|
|
18
|
+
},
|
|
19
|
+
j
|
|
19
20
|
}).toSource(printOptions);
|
|
20
21
|
}
|
|
@@ -0,0 +1,101 @@
|
|
|
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 _addComponentsSlots = require("../../../util/addComponentsSlots");
|
|
9
|
+
var _removeProps = _interopRequireDefault(require("../../../util/removeProps"));
|
|
10
|
+
var _renameComponentsSlots = _interopRequireDefault(require("../../../util/renameComponentsSlots"));
|
|
11
|
+
const propsToSlots = {
|
|
12
|
+
// components
|
|
13
|
+
TransitionComponent: {
|
|
14
|
+
prop: 'components',
|
|
15
|
+
path: 'DesktopTransition'
|
|
16
|
+
},
|
|
17
|
+
// componentsProps
|
|
18
|
+
PopperProps: {
|
|
19
|
+
prop: 'componentsProps',
|
|
20
|
+
path: 'popper'
|
|
21
|
+
},
|
|
22
|
+
DialogProps: {
|
|
23
|
+
prop: 'componentsProps',
|
|
24
|
+
path: 'dialog'
|
|
25
|
+
},
|
|
26
|
+
PaperProps: {
|
|
27
|
+
prop: 'componentsProps',
|
|
28
|
+
path: 'desktopPaper'
|
|
29
|
+
},
|
|
30
|
+
TrapFocusProps: {
|
|
31
|
+
prop: 'componentsProps',
|
|
32
|
+
path: 'desktopTrapFocus'
|
|
33
|
+
},
|
|
34
|
+
InputProps: {
|
|
35
|
+
prop: 'componentsProps',
|
|
36
|
+
path: 'textField.InputProps'
|
|
37
|
+
},
|
|
38
|
+
InputAdornmentProps: {
|
|
39
|
+
prop: 'componentsProps',
|
|
40
|
+
path: 'inputAdornment'
|
|
41
|
+
},
|
|
42
|
+
OpenPickerButtonProps: {
|
|
43
|
+
prop: 'componentsProps',
|
|
44
|
+
path: 'openPickerButton'
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
function transformer(file, api, options) {
|
|
48
|
+
const j = api.jscodeshift;
|
|
49
|
+
const root = j(file.source);
|
|
50
|
+
const printOptions = options.printOptions || {
|
|
51
|
+
quote: 'single',
|
|
52
|
+
trailingComma: true
|
|
53
|
+
};
|
|
54
|
+
const componentNames = new Set();
|
|
55
|
+
root.find(j.ImportDeclaration).filter(({
|
|
56
|
+
node
|
|
57
|
+
}) => {
|
|
58
|
+
return node.source.value.startsWith('@mui/x-date-pickers');
|
|
59
|
+
}).forEach(path => {
|
|
60
|
+
path.node.specifiers.forEach(node => {
|
|
61
|
+
// Process only date-pickers components
|
|
62
|
+
root.findJSXElements(node.local.name).forEach(elementPath => {
|
|
63
|
+
if (elementPath.node.type !== 'JSXElement') {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
componentNames.add(node.local.name);
|
|
67
|
+
const attributesToTransform = j(elementPath).find(j.JSXAttribute).filter(attribute => {
|
|
68
|
+
const attributeParent = attribute.parentPath.parentPath;
|
|
69
|
+
if (attribute.parentPath.parentPath.value.type !== 'JSXOpeningElement' || attributeParent.value.name.name !== node.local.name) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
return Object.keys(propsToSlots).includes(attribute.value.name.name);
|
|
73
|
+
});
|
|
74
|
+
attributesToTransform.forEach(attribute => {
|
|
75
|
+
const attributeName = attribute.value.name.name;
|
|
76
|
+
|
|
77
|
+
// Get the value in case it's:
|
|
78
|
+
// - prop={value}
|
|
79
|
+
// - prop="value"
|
|
80
|
+
// - prop (which means true)
|
|
81
|
+
const value = attribute.value.value?.type === 'JSXExpressionContainer' ? attribute.value.value.expression : attribute.value.value || j.booleanLiteral(true);
|
|
82
|
+
(0, _addComponentsSlots.transformNestedProp)(elementPath, propsToSlots[attributeName].prop, propsToSlots[attributeName].path, value, j);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
(0, _removeProps.default)({
|
|
86
|
+
root,
|
|
87
|
+
componentNames: [node.local.name],
|
|
88
|
+
props: Object.keys(propsToSlots),
|
|
89
|
+
j
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
return (0, _renameComponentsSlots.default)({
|
|
94
|
+
root,
|
|
95
|
+
componentNames: Array.from(componentNames),
|
|
96
|
+
translation: {
|
|
97
|
+
input: 'textField'
|
|
98
|
+
},
|
|
99
|
+
j
|
|
100
|
+
}).toSource(printOptions);
|
|
101
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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 _localizationProviderRenameLocale = _interopRequireDefault(require("../localization-provider-rename-locale"));
|
|
9
|
+
var _textPropsToLocaleText = _interopRequireDefault(require("../text-props-to-localeText"));
|
|
10
|
+
var _viewComponentsRename = _interopRequireDefault(require("../view-components-rename"));
|
|
11
|
+
var _viewComponentsRenameValueProp = _interopRequireDefault(require("../view-components-rename-value-prop"));
|
|
12
|
+
var _adapterChangeImport = _interopRequireDefault(require("../adapter-change-import"));
|
|
13
|
+
var _replaceTabsProps = _interopRequireDefault(require("../replace-tabs-props"));
|
|
14
|
+
var _replaceToolbarPropsBySlot = _interopRequireDefault(require("../replace-toolbar-props-by-slot"));
|
|
15
|
+
var _migrateToComponentsComponentsProps = _interopRequireDefault(require("../migrate-to-components-componentsProps"));
|
|
16
|
+
var _replaceArrowsButtonSlot = _interopRequireDefault(require("../replace-arrows-button-slot"));
|
|
17
|
+
var _renameShouldDisableTime = _interopRequireDefault(require("../rename-should-disable-time"));
|
|
18
|
+
function transformer(file, api, options) {
|
|
19
|
+
file.source = (0, _localizationProviderRenameLocale.default)(file, api, options);
|
|
20
|
+
|
|
21
|
+
// All the codemods impacting the view components should be run before renaming these components
|
|
22
|
+
file.source = (0, _textPropsToLocaleText.default)(file, api, options);
|
|
23
|
+
file.source = (0, _viewComponentsRenameValueProp.default)(file, api, options);
|
|
24
|
+
file.source = (0, _viewComponentsRename.default)(file, api, options);
|
|
25
|
+
file.source = (0, _adapterChangeImport.default)(file, api, options);
|
|
26
|
+
file.source = (0, _replaceTabsProps.default)(file, api, options);
|
|
27
|
+
file.source = (0, _replaceToolbarPropsBySlot.default)(file, api, options);
|
|
28
|
+
file.source = (0, _migrateToComponentsComponentsProps.default)(file, api, options);
|
|
29
|
+
file.source = (0, _replaceArrowsButtonSlot.default)(file, api, options);
|
|
30
|
+
file.source = (0, _renameShouldDisableTime.default)(file, api, options);
|
|
31
|
+
return file.source;
|
|
32
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = transformer;
|
|
7
|
+
function transformComponentsProp(attributeNode) {
|
|
8
|
+
attributeNode.name.name = 'slots';
|
|
9
|
+
const valueExpression = attributeNode.value.expression;
|
|
10
|
+
if (valueExpression?.type !== 'ObjectExpression') {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
valueExpression.properties.forEach(property => {
|
|
14
|
+
property.key.name = property.key.name[0].toLowerCase() + property.key.name.slice(1);
|
|
15
|
+
if (property.shorthand) {
|
|
16
|
+
property.shorthand = false;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function transformComponentsPropsProp(attributeNode) {
|
|
21
|
+
attributeNode.name.name = 'slotProps';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param {import('jscodeshift').FileInfo} file
|
|
26
|
+
* @param {import('jscodeshift').API} api
|
|
27
|
+
*/
|
|
28
|
+
function transformer(file, api, options) {
|
|
29
|
+
const j = api.jscodeshift;
|
|
30
|
+
const printOptions = options.printOptions;
|
|
31
|
+
const root = j(file.source);
|
|
32
|
+
root.find(j.ImportDeclaration).filter(({
|
|
33
|
+
node
|
|
34
|
+
}) => {
|
|
35
|
+
return node.source.value.startsWith('@mui/x-date-pickers');
|
|
36
|
+
}).forEach(path => {
|
|
37
|
+
path.node.specifiers.forEach(node => {
|
|
38
|
+
// Process only date-pickers components
|
|
39
|
+
root.findJSXElements(node.local.name).forEach(elementPath => {
|
|
40
|
+
if (elementPath.node.type !== 'JSXElement') {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
elementPath.node.openingElement.attributes.forEach(elementNode => {
|
|
44
|
+
if (elementNode.type !== 'JSXAttribute') {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
switch (elementNode.name.name) {
|
|
48
|
+
case 'components':
|
|
49
|
+
transformComponentsProp(elementNode);
|
|
50
|
+
break;
|
|
51
|
+
case 'componentsProps':
|
|
52
|
+
transformComponentsPropsProp(elementNode);
|
|
53
|
+
break;
|
|
54
|
+
default:
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
const transformed = root.findJSXElements();
|
|
61
|
+
return transformed.toSource(printOptions);
|
|
62
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
root.find(j.ImportDeclaration).filter(({
|
|
16
|
+
node
|
|
17
|
+
}) => {
|
|
18
|
+
return node.source.value.startsWith('@mui/x-date-pickers');
|
|
19
|
+
}).forEach(path => {
|
|
20
|
+
path.node.specifiers.forEach(node => {
|
|
21
|
+
// Process only date-pickers components
|
|
22
|
+
root.findJSXElements(node.local.name).forEach(elementPath => {
|
|
23
|
+
if (elementPath.node.type !== 'JSXElement') {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
elementPath.node.openingElement.attributes.forEach(elementNode => {
|
|
27
|
+
if (elementNode.type !== 'JSXAttribute') {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (elementNode.name.name === 'shouldDisableTime') {
|
|
31
|
+
elementNode.name.name = 'shouldDisableClock';
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
const transformed = root.findJSXElements();
|
|
38
|
+
return transformed.toSource(printOptions);
|
|
39
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
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 _renameComponentsSlots = _interopRequireDefault(require("../../../util/renameComponentsSlots"));
|
|
9
|
+
function transformer(file, api, options) {
|
|
10
|
+
const j = api.jscodeshift;
|
|
11
|
+
const root = j(file.source);
|
|
12
|
+
const printOptions = options.printOptions || {
|
|
13
|
+
quote: 'single',
|
|
14
|
+
trailingComma: true
|
|
15
|
+
};
|
|
16
|
+
const componentNames = new Set();
|
|
17
|
+
root.find(j.ImportDeclaration).filter(({
|
|
18
|
+
node
|
|
19
|
+
}) => {
|
|
20
|
+
return node.source.value.startsWith('@mui/x-date-pickers');
|
|
21
|
+
}).forEach(path => {
|
|
22
|
+
path.node.specifiers.forEach(node => {
|
|
23
|
+
// Process only date-pickers components
|
|
24
|
+
root.findJSXElements(node.local.name).forEach(elementPath => {
|
|
25
|
+
if (elementPath.node.type !== 'JSXElement') {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
componentNames.add(node.local.name);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
return (0, _renameComponentsSlots.default)({
|
|
33
|
+
root,
|
|
34
|
+
componentNames: Array.from(componentNames),
|
|
35
|
+
translation: {
|
|
36
|
+
LeftArrowButton: 'PreviousIconButton',
|
|
37
|
+
RightArrowButton: 'NextIconButton'
|
|
38
|
+
},
|
|
39
|
+
j
|
|
40
|
+
}).toSource(printOptions);
|
|
41
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
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 _renameComponentsSlots = _interopRequireDefault(require("../../../util/renameComponentsSlots"));
|
|
9
|
+
var _addComponentsSlots = require("../../../util/addComponentsSlots");
|
|
10
|
+
var _removeProps = _interopRequireDefault(require("../../../util/removeProps"));
|
|
11
|
+
const propsToComponentsProps = {
|
|
12
|
+
hideTabs: 'tabs.hidden',
|
|
13
|
+
dateRangeIcon: 'tabs.dateIcon',
|
|
14
|
+
timeIcon: 'tabs.timeIcon'
|
|
15
|
+
};
|
|
16
|
+
const COMPONENTS = ['DateTimePicker', 'MobileDateTimePicker', 'DesktopDateTimePicker', 'StaticDateTimePicker'];
|
|
17
|
+
function transformer(file, api, options) {
|
|
18
|
+
const j = api.jscodeshift;
|
|
19
|
+
const root = j(file.source);
|
|
20
|
+
const printOptions = options.printOptions || {
|
|
21
|
+
quote: 'single',
|
|
22
|
+
trailingComma: true
|
|
23
|
+
};
|
|
24
|
+
root.find(j.JSXElement).filter(path => {
|
|
25
|
+
return COMPONENTS.includes(path.value.openingElement.name.name);
|
|
26
|
+
}).forEach(path => {
|
|
27
|
+
const attributesToTransform = j(path).find(j.JSXAttribute).filter(attribute => Object.keys(propsToComponentsProps).includes(attribute.value.name.name));
|
|
28
|
+
attributesToTransform.forEach(attribute => {
|
|
29
|
+
const attributeName = attribute.value.name.name;
|
|
30
|
+
|
|
31
|
+
// Get the value in case it's:
|
|
32
|
+
// - prop={value}
|
|
33
|
+
// - prop="value"
|
|
34
|
+
// - prop (which means true)
|
|
35
|
+
const value = attribute.value.value?.type === 'JSXExpressionContainer' ? attribute.value.value.expression : attribute.value.value || j.booleanLiteral(true);
|
|
36
|
+
(0, _addComponentsSlots.transformNestedProp)(path, 'componentsProps', propsToComponentsProps[attributeName], value, j);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
(0, _removeProps.default)({
|
|
40
|
+
root,
|
|
41
|
+
componentNames: COMPONENTS,
|
|
42
|
+
props: Object.keys(propsToComponentsProps),
|
|
43
|
+
j
|
|
44
|
+
});
|
|
45
|
+
return (0, _renameComponentsSlots.default)({
|
|
46
|
+
root,
|
|
47
|
+
componentNames: COMPONENTS,
|
|
48
|
+
translation: {
|
|
49
|
+
dateRangeIcon: 'dateIcon'
|
|
50
|
+
},
|
|
51
|
+
j
|
|
52
|
+
}).toSource(printOptions);
|
|
53
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
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 _addComponentsSlots = require("../../../util/addComponentsSlots");
|
|
9
|
+
var _removeProps = _interopRequireDefault(require("../../../util/removeProps"));
|
|
10
|
+
const propsToSlots = {
|
|
11
|
+
ToolbarComponent: {
|
|
12
|
+
prop: 'components',
|
|
13
|
+
path: 'Toolbar'
|
|
14
|
+
},
|
|
15
|
+
toolbarPlaceholder: {
|
|
16
|
+
prop: 'componentsProps',
|
|
17
|
+
path: 'toolbar.toolbarPlaceholder'
|
|
18
|
+
},
|
|
19
|
+
toolbarFormat: {
|
|
20
|
+
prop: 'componentsProps',
|
|
21
|
+
path: 'toolbar.toolbarFormat'
|
|
22
|
+
},
|
|
23
|
+
showToolbar: {
|
|
24
|
+
prop: 'componentsProps',
|
|
25
|
+
path: 'toolbar.hidden'
|
|
26
|
+
},
|
|
27
|
+
toolbarTitle: {
|
|
28
|
+
prop: 'localeText',
|
|
29
|
+
path: 'toolbarTitle'
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const COMPONENTS = ['DateTimePicker', 'MobileDateTimePicker', 'DesktopDateTimePicker', 'StaticDateTimePicker', 'DatePicker', 'MobileDatePicker', 'DesktopDatePicker', 'StaticDatePicker', 'TimePicker', 'MobileTimePicker', 'DesktopTimePicker', 'StaticTimePicker', 'DateRangePicker', 'MobileDateRangePicker', 'DesktopDateRangePicker', 'StaticDateRangePicker'];
|
|
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
|
+
root.find(j.JSXElement).filter(path => {
|
|
41
|
+
return COMPONENTS.includes(path.value.openingElement.name.name);
|
|
42
|
+
}).forEach(path => {
|
|
43
|
+
const attributesToTransform = j(path).find(j.JSXAttribute).filter(attribute => Object.keys(propsToSlots).includes(attribute.value.name.name));
|
|
44
|
+
attributesToTransform.forEach(attribute => {
|
|
45
|
+
const attributeName = attribute.value.name.name;
|
|
46
|
+
|
|
47
|
+
// Get the value in case it's:
|
|
48
|
+
// - prop={value}
|
|
49
|
+
// - prop="value"
|
|
50
|
+
// - prop (which means true)
|
|
51
|
+
let value = attribute.value.value?.type === 'JSXExpressionContainer' ? attribute.value.value.expression : attribute.value.value || j.booleanLiteral(true);
|
|
52
|
+
if (attributeName === 'showToolbar') {
|
|
53
|
+
if (value.type === 'BooleanLiteral' || value.type === 'Literal' && typeof value.value === 'boolean') {
|
|
54
|
+
value.value = !value.value;
|
|
55
|
+
} else {
|
|
56
|
+
value = j.unaryExpression('!', value);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
(0, _addComponentsSlots.transformNestedProp)(path, propsToSlots[attributeName].prop, propsToSlots[attributeName].path, value, j);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
(0, _removeProps.default)({
|
|
63
|
+
root,
|
|
64
|
+
componentNames: COMPONENTS,
|
|
65
|
+
props: Object.keys(propsToSlots),
|
|
66
|
+
j
|
|
67
|
+
});
|
|
68
|
+
return root.toSource(printOptions);
|
|
69
|
+
}
|