@mui/codemod 6.0.0-alpha.7 → 6.0.0-alpha.9

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.
Files changed (124) hide show
  1. package/README.md +227 -30
  2. package/node/deprecations/accordion-props/test-cases/actual.js +6 -3
  3. package/node/deprecations/accordion-props/test-cases/expected.js +14 -10
  4. package/node/deprecations/accordion-props/test-cases/theme.expected.js +8 -7
  5. package/node/deprecations/alert-props/test-cases/expected.js +12 -4
  6. package/node/deprecations/alert-props/test-cases/theme.expected.js +12 -5
  7. package/node/deprecations/all/deprecations-all.js +6 -0
  8. package/node/deprecations/autocomplete-props/test-cases/expected.js +8 -6
  9. package/node/deprecations/autocomplete-props/test-cases/theme.expected.js +8 -7
  10. package/node/deprecations/avatar-group-props/avatar-group-props.js +87 -0
  11. package/node/deprecations/avatar-group-props/index.js +13 -0
  12. package/node/deprecations/avatar-group-props/test-cases/actual.js +56 -0
  13. package/node/deprecations/avatar-group-props/test-cases/expected.js +58 -0
  14. package/node/deprecations/avatar-group-props/test-cases/theme.actual.js +48 -0
  15. package/node/deprecations/avatar-group-props/test-cases/theme.expected.js +50 -0
  16. package/node/deprecations/avatar-props/test-cases/expected.js +8 -6
  17. package/node/deprecations/avatar-props/test-cases/theme.expected.js +8 -7
  18. package/node/deprecations/backdrop-props/test-cases/actual.js +3 -2
  19. package/node/deprecations/backdrop-props/test-cases/expected.js +3 -3
  20. package/node/deprecations/badge-props/test-cases/expected.js +12 -5
  21. package/node/deprecations/badge-props/test-cases/theme.expected.js +12 -5
  22. package/node/deprecations/form-control-label-props/test-cases/expected.js +4 -2
  23. package/node/deprecations/form-control-label-props/test-cases/theme.expected.js +4 -3
  24. package/node/deprecations/grid-props/grid-props.js +51 -0
  25. package/node/deprecations/grid-props/index.js +13 -0
  26. package/node/deprecations/grid-props/test-cases/actual.js +25 -0
  27. package/node/deprecations/grid-props/test-cases/expected.js +23 -0
  28. package/node/deprecations/grid-props/test-cases/theme.actual.js +24 -0
  29. package/node/deprecations/grid-props/test-cases/theme.expected.js +23 -0
  30. package/node/deprecations/list-item-props/index.js +13 -0
  31. package/node/deprecations/list-item-props/list-item-props.js +22 -0
  32. package/node/deprecations/list-item-props/test-cases/actual.js +43 -0
  33. package/node/deprecations/list-item-props/test-cases/expected.js +40 -0
  34. package/node/deprecations/list-item-props/test-cases/theme.actual.js +56 -0
  35. package/node/deprecations/list-item-props/test-cases/theme.expected.js +53 -0
  36. package/node/deprecations/popper-props/index.js +13 -0
  37. package/node/deprecations/popper-props/popper-props.js +22 -0
  38. package/node/deprecations/popper-props/test-cases/actual.js +27 -0
  39. package/node/deprecations/popper-props/test-cases/expected.js +24 -0
  40. package/node/deprecations/popper-props/test-cases/theme.actual.js +32 -0
  41. package/node/deprecations/popper-props/test-cases/theme.expected.js +29 -0
  42. package/node/deprecations/slider-props/test-cases/expected.js +12 -4
  43. package/node/deprecations/slider-props/test-cases/theme.expected.js +12 -5
  44. package/node/deprecations/speed-dial-props/test-cases/actual.js +3 -2
  45. package/node/deprecations/speed-dial-props/test-cases/expected.js +3 -3
  46. package/node/deprecations/step-label-props/test-cases/expected.js +8 -3
  47. package/node/deprecations/step-label-props/test-cases/theme.expected.js +8 -4
  48. package/node/deprecations/text-field-props/index.js +13 -0
  49. package/node/deprecations/text-field-props/test-cases/actual.js +27 -0
  50. package/node/deprecations/text-field-props/test-cases/expected.js +31 -0
  51. package/node/deprecations/text-field-props/test-cases/theme.actual.js +13 -0
  52. package/node/deprecations/text-field-props/test-cases/theme.expected.js +15 -0
  53. package/node/deprecations/text-field-props/text-field-props.js +48 -0
  54. package/node/deprecations/tooltip-props/index.js +13 -0
  55. package/node/deprecations/tooltip-props/test-cases/actual.js +92 -0
  56. package/node/deprecations/tooltip-props/test-cases/expected.js +84 -0
  57. package/node/deprecations/tooltip-props/test-cases/theme.actual.js +73 -0
  58. package/node/deprecations/tooltip-props/test-cases/theme.expected.js +65 -0
  59. package/node/deprecations/tooltip-props/tooltip-props.js +22 -0
  60. package/node/deprecations/utils/replaceComponentsWithSlots.js +29 -17
  61. package/node/util/migrateToVariants.js +198 -121
  62. package/node/v5.0.0/badge-overlap-value.test/actual.js +3 -4
  63. package/node/v5.0.0/badge-overlap-value.test/expected.js +3 -4
  64. package/node/v5.0.0/base-remove-component-prop.test/actual.js +4 -4
  65. package/node/v5.0.0/base-remove-component-prop.test/expected.js +4 -4
  66. package/node/v5.0.0/box-sx-prop.test/actual.js +4 -4
  67. package/node/v5.0.0/box-sx-prop.test/expected.js +3 -3
  68. package/node/v5.0.0/create-theme.test/custom-fn.actual.js +3 -4
  69. package/node/v5.0.0/create-theme.test/custom-fn.expected.js +3 -4
  70. package/node/v5.0.0/jss-to-styled.test/first.actual.js +11 -14
  71. package/node/v5.0.0/jss-to-styled.test/first.expected.js +11 -14
  72. package/node/v5.0.0/jss-to-styled.test/seventh.actual.js +4 -4
  73. package/node/v5.0.0/jss-to-styled.test/seventh.expected.js +4 -4
  74. package/node/v5.0.0/jss-to-styled.test/sixth.actual.js +3 -3
  75. package/node/v5.0.0/jss-to-styled.test/sixth.expected.js +3 -3
  76. package/node/v5.0.0/jss-to-styled.test/withCreateStyles.actual.js +3 -3
  77. package/node/v5.0.0/jss-to-styled.test/withCreateStyles.expected.js +3 -4
  78. package/node/v5.0.0/jss-to-styled.test/withCreateStyles1.actual.js +3 -3
  79. package/node/v5.0.0/jss-to-styled.test/withCreateStyles1.expected.js +3 -4
  80. package/node/v5.0.0/jss-to-styled.test/withCreateStyles2.actual.js +3 -3
  81. package/node/v5.0.0/jss-to-styled.test/withCreateStyles2.expected.js +3 -4
  82. package/node/v5.0.0/jss-to-styled.test/withCreateStyles3.actual.js +3 -3
  83. package/node/v5.0.0/jss-to-styled.test/withCreateStyles3.expected.js +3 -4
  84. package/node/v5.0.0/jss-to-tss-react.test/actual-mixins-pattern.js +6 -5
  85. package/node/v5.0.0/jss-to-tss-react.test/expected-mixins-pattern.js +6 -5
  86. package/node/v5.0.0/preset-safe.test/actual.js +6 -4
  87. package/node/v5.0.0/preset-safe.test/expected.js +9 -6
  88. package/node/v5.0.0/table-props.test/actual.js +4 -5
  89. package/node/v5.0.0/table-props.test/expected.js +4 -5
  90. package/node/v5.0.0/theme-spacing.test/large-actual.js +10 -10
  91. package/node/v5.0.0/theme-spacing.test/large-expected.js +10 -10
  92. package/node/v5.0.0/variant-prop.test/actual.js +12 -6
  93. package/node/v5.0.0/variant-prop.test/expected.js +15 -12
  94. package/node/v5.0.0/with-mobile-dialog.test/expected.js +6 -5
  95. package/node/v5.0.0/with-width.test/expected.js +6 -5
  96. package/node/v6.0.0/styled/test-cases/BasicStyled.actual.js +55 -44
  97. package/node/v6.0.0/styled/test-cases/BasicStyled.expected.js +5 -6
  98. package/node/v6.0.0/styled/test-cases/ConditionalStyled.actual.js +80 -70
  99. package/node/v6.0.0/styled/test-cases/ConditionalStyled.expected.js +7 -6
  100. package/node/v6.0.0/styled/test-cases/NestedSpread.actual.js +32 -26
  101. package/node/v6.0.0/styled/test-cases/NestedSpread.expected.js +7 -6
  102. package/node/v6.0.0/styled/test-cases/ThemePaletteMode.expected.js +28 -26
  103. package/node/v6.0.0/styled/test-cases/VariantAndModeStyled.actual.js +6 -5
  104. package/node/v6.0.0/styled/test-cases/VariantAndModeStyled.expected.js +8 -8
  105. package/node/v6.0.0/sx-prop/index.js +13 -0
  106. package/node/v6.0.0/sx-prop/sx-v6.js +355 -0
  107. package/node/v6.0.0/sx-prop/test-cases/basic-sx.actual.js +36 -0
  108. package/node/v6.0.0/sx-prop/test-cases/basic-sx.expected.js +46 -0
  109. package/node/v6.0.0/sx-prop/test-cases/sx-css-vars.actual.js +41 -0
  110. package/node/v6.0.0/sx-prop/test-cases/sx-css-vars.expected.js +71 -0
  111. package/node/v6.0.0/sx-prop/test-cases/sx-dynamic.actual.js +87 -0
  112. package/node/v6.0.0/sx-prop/test-cases/sx-dynamic.expected.js +102 -0
  113. package/node/v6.0.0/sx-prop/test-cases/sx-dynamic2.actual.js +49 -0
  114. package/node/v6.0.0/sx-prop/test-cases/sx-dynamic2.expected.js +64 -0
  115. package/node/v6.0.0/system-props/index.js +13 -0
  116. package/node/v6.0.0/system-props/removeSystemProps.js +242 -0
  117. package/node/v6.0.0/system-props/test-cases/system-props.actual.js +79 -0
  118. package/node/v6.0.0/system-props/test-cases/system-props.expected.js +92 -0
  119. package/node/v6.0.0/theme-v6/test-cases/basicTheme.actual.js +254 -225
  120. package/node/v6.0.0/theme-v6/test-cases/basicTheme.expected.js +180 -162
  121. package/node/v6.0.0/theme-v6/test-cases/themeVariants.actual.js +23 -21
  122. package/node/v6.0.0/theme-v6/test-cases/themeVariants.expected.js +20 -19
  123. package/node/v6.0.0/theme-v6/theme-v6.js +2 -2
  124. package/package.json +4 -4
@@ -1,7 +1,5 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
5
3
  const Component = styled('div')(({
6
4
  theme
7
5
  }) => {
@@ -71,14 +69,17 @@ const Component = styled('div')(({
71
69
  ownerState
72
70
  }) => ownerState.color !== 'inherit' && ownerState.color !== 'default' && !ownerState.disableRipple,
73
71
  style: {
74
- '&:hover': (0, _extends2.default)({}, palette && {
75
- backgroundColor: theme.vars ? `rgba(${palette.mainChannel} / ${theme.vars.palette.action.hoverOpacity})` : alpha(palette.main, theme.palette.action.hoverOpacity)
76
- }, {
72
+ '&:hover': {
73
+ // The codemod won't handle this case when the variable is not declared in the style argument.
74
+ // In this case, the `palette` create a new variable in the style argument.
75
+ ...(palette && {
76
+ backgroundColor: theme.vars ? `rgba(${palette.mainChannel} / ${theme.vars.palette.action.hoverOpacity})` : alpha(palette.main, theme.palette.action.hoverOpacity)
77
+ }),
77
78
  // Reset on touch devices, it doesn't add specificity
78
79
  '@media (hover: none)': {
79
80
  backgroundColor: 'transparent'
80
81
  }
81
- })
82
+ }
82
83
  }
83
84
  }]
84
85
  };
@@ -1,19 +1,18 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
5
3
  const Test = styled('div')(({
6
4
  theme
7
- }) => (0, _extends2.default)({
5
+ }) => ({
8
6
  color: theme.palette.primary.main,
9
- background: `linear-gradient(45deg, ${theme.palette.primary[600]} 30%, ${theme.palette.primary[500]} 90%})`
10
- }, theme.applyStyles("dark", {
11
- color: theme.palette.primary.light,
12
- background: `linear-gradient(45deg, ${theme.palette.primary[400]} 30%, ${theme.palette.primary[200]} 90%})`
13
- })));
7
+ background: `linear-gradient(45deg, ${theme.palette.primary[600]} 30%, ${theme.palette.primary[500]} 90%})`,
8
+ ...theme.applyStyles("dark", {
9
+ color: theme.palette.primary.light,
10
+ background: `linear-gradient(45deg, ${theme.palette.primary[400]} 30%, ${theme.palette.primary[200]} 90%})`
11
+ })
12
+ }));
14
13
  const StyledPopper = styled(Popper)(({
15
14
  theme
16
- }) => (0, _extends2.default)({
15
+ }) => ({
17
16
  border: `1px solid ${'#30363d'}`,
18
17
  boxShadow: `0 8px 24px ${'rgb(1, 4, 9)'}`,
19
18
  borderRadius: 6,
@@ -21,13 +20,14 @@ const StyledPopper = styled(Popper)(({
21
20
  zIndex: theme.zIndex.modal,
22
21
  fontSize: 13,
23
22
  color: '#c9d1d9',
24
- backgroundColor: '#1c2128'
25
- }, theme.applyStyles("light", {
26
- border: `1px solid ${'#e1e4e8'}`,
27
- boxShadow: `0 8px 24px ${'rgba(149, 157, 165, 0.2)'}`,
28
- color: '#24292e',
29
- backgroundColor: '#fff'
30
- })));
23
+ backgroundColor: '#1c2128',
24
+ ...theme.applyStyles("light", {
25
+ border: `1px solid ${'#e1e4e8'}`,
26
+ boxShadow: `0 8px 24px ${'rgba(149, 157, 165, 0.2)'}`,
27
+ color: '#24292e',
28
+ backgroundColor: '#fff'
29
+ })
30
+ }));
31
31
  const AntSwitch = styled(Switch)(({
32
32
  theme
33
33
  }) => ({
@@ -48,12 +48,13 @@ const AntSwitch = styled(Switch)(({
48
48
  '&.Mui-checked': {
49
49
  transform: 'translateX(12px)',
50
50
  color: '#fff',
51
- '& + .MuiSwitch-track': (0, _extends2.default)({
51
+ '& + .MuiSwitch-track': {
52
52
  opacity: 1,
53
- backgroundColor: '#1890ff'
54
- }, theme.applyStyles("dark", {
55
- backgroundColor: '#177ddc'
56
- }))
53
+ backgroundColor: '#1890ff',
54
+ ...theme.applyStyles("dark", {
55
+ backgroundColor: '#177ddc'
56
+ })
57
+ }
57
58
  }
58
59
  },
59
60
  '& .MuiSwitch-thumb': {
@@ -65,12 +66,13 @@ const AntSwitch = styled(Switch)(({
65
66
  duration: 200
66
67
  })
67
68
  },
68
- '& .MuiSwitch-track': (0, _extends2.default)({
69
+ '& .MuiSwitch-track': {
69
70
  borderRadius: 16 / 2,
70
71
  opacity: 1,
71
72
  backgroundColor: 'rgba(0,0,0,.25)',
72
- boxSizing: 'border-box'
73
- }, theme.applyStyles("dark", {
74
- backgroundColor: 'rgba(255,255,255,.35)'
75
- }))
73
+ boxSizing: 'border-box',
74
+ ...theme.applyStyles("dark", {
75
+ backgroundColor: 'rgba(255,255,255,.35)'
76
+ })
77
+ }
76
78
  }));
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
5
3
  const Component = styled.div(({
6
4
  theme,
7
5
  ownerState
8
- }) => (0, _extends2.default)({}, theme.typography.caption, ownerState.size === 'small' && {
9
- marginTop: (theme.vars || theme).spacing(1),
10
- color: theme.palette.mode === 'dark' ? theme.palette.primary.light : theme.palette.primary.main
6
+ }) => ({
7
+ ...theme.typography.caption,
8
+ ...(ownerState.size === 'small' && {
9
+ marginTop: (theme.vars || theme).spacing(1),
10
+ color: theme.palette.mode === 'dark' ? theme.palette.primary.light : theme.palette.primary.main
11
+ })
11
12
  }));
@@ -1,19 +1,19 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
5
3
  const Component = styled.div(({
6
4
  theme
7
- }) => (0, _extends2.default)({}, theme.typography.caption, {
5
+ }) => ({
6
+ ...theme.typography.caption,
8
7
  variants: [{
9
8
  props: {
10
9
  size: 'small'
11
10
  },
12
- style: (0, _extends2.default)({
11
+ style: {
13
12
  marginTop: (theme.vars || theme).spacing(1),
14
- color: theme.palette.primary.main
15
- }, theme.applyStyles("dark", {
16
- color: theme.palette.primary.light
17
- }))
13
+ color: theme.palette.primary.main,
14
+ ...theme.applyStyles("dark", {
15
+ color: theme.palette.primary.light
16
+ })
17
+ }
18
18
  }]
19
19
  }));
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ Object.defineProperty(exports, "default", {
8
+ enumerable: true,
9
+ get: function () {
10
+ return _sxV.default;
11
+ }
12
+ });
13
+ var _sxV = _interopRequireDefault(require("./sx-v6"));
@@ -0,0 +1,355 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = sxV6;
8
+ var _getReturnExpression = _interopRequireDefault(require("../../util/getReturnExpression"));
9
+ var _migrateToVariants = require("../../util/migrateToVariants");
10
+ /**
11
+ *
12
+ * @param {import('jscodeshift').MemberExpression | import('jscodeshift').Identifier} node
13
+ */
14
+ function getCssVarName(node) {
15
+ if (node.type === 'MemberExpression') {
16
+ var _getObjectKey;
17
+ return `--${(_getObjectKey = (0, _migrateToVariants.getObjectKey)(node)) == null ? void 0 : _getObjectKey.name}-${node.property.name}`;
18
+ }
19
+ if (node.type === 'Identifier') {
20
+ return `--${node.name}`;
21
+ }
22
+ return '';
23
+ }
24
+
25
+ /**
26
+ * @param {import('jscodeshift').FileInfo} file
27
+ * @param {import('jscodeshift').API} api
28
+ */
29
+ function sxV6(file, api, options) {
30
+ const j = api.jscodeshift;
31
+ const root = j(file.source);
32
+ const printOptions = options.printOptions;
33
+ const createBuildStyle = (0, _migrateToVariants.getCreateBuildStyle)(j);
34
+ const appendPaletteModeStyles = (0, _migrateToVariants.getAppendPaletteModeStyles)(j);
35
+ const buildArrowFunctionAST = (0, _migrateToVariants.getBuildArrowFunctionAST)(j);
36
+
37
+ /**
38
+ *
39
+ * @param {import('jscodeshift').Identifier} node
40
+ */
41
+ function replaceUndefined(node, replacement = j.nullLiteral()) {
42
+ if ((node == null ? void 0 : node.type) === 'Identifier' && node.name === 'undefined') {
43
+ return replacement;
44
+ }
45
+ return node;
46
+ }
47
+ let shouldTransform = false;
48
+ root.find(j.JSXAttribute, {
49
+ name: {
50
+ name: 'sx'
51
+ },
52
+ value: {
53
+ type: 'JSXExpressionContainer'
54
+ }
55
+ }).forEach(path => {
56
+ /**
57
+ * @type {[import('jscodeshift').StringLiteral, import('jscodeshift').Expression][]}
58
+ */
59
+ const cssVars = [];
60
+ const conditionalExpressions = []; // for ensuring the sequence of styles
61
+ let currentIndex = 0;
62
+ const sxContainer = path.node.value;
63
+ if (['ArrowFunctionExpression', 'ObjectExpression', 'ArrayExpression'].includes(sxContainer.expression.type)) {
64
+ shouldTransform = true;
65
+ (sxContainer.expression.type === 'ArrayExpression' ? sxContainer.expression.elements : [sxContainer.expression]).forEach((item, index) => {
66
+ currentIndex = index;
67
+ recurseObjectExpression({
68
+ root: item,
69
+ replaceRoot: newRoot => {
70
+ sxContainer.expression = newRoot;
71
+ },
72
+ node: item,
73
+ buildStyle: createBuildStyle()
74
+ });
75
+ });
76
+ if (cssVars.length) {
77
+ const cssVarsObject = j.objectExpression(cssVars.map(([varName, value]) => j.objectProperty(varName, value)));
78
+ if (path.parent.node.type === 'JSXOpeningElement') {
79
+ const styleAttribute = path.parent.node.attributes.find(attribute => attribute.type === 'JSXAttribute' && attribute.name.name === 'style');
80
+ const spreadAttribute = path.parent.node.attributes.find(attribute => attribute.type === 'JSXSpreadAttribute');
81
+ if (styleAttribute) {
82
+ if (styleAttribute.value.expression.type === 'ObjectExpression') {
83
+ styleAttribute.value.expression.properties = [...cssVarsObject.properties, ...styleAttribute.value.expression.properties];
84
+ } else if (styleAttribute.value.expression.type === 'Identifier' || styleAttribute.value.expression.type === 'MemberExpression') {
85
+ styleAttribute.value.expression = j.objectExpression([...cssVarsObject.properties, j.spreadElement(styleAttribute.value.expression)]);
86
+ }
87
+ } else if (spreadAttribute) {
88
+ path.parent.node.attributes.push(j.jsxAttribute(j.jsxIdentifier('style'), j.jsxExpressionContainer(j.objectExpression([...cssVarsObject.properties, j.spreadElement(j.memberExpression(spreadAttribute.argument, j.identifier('style')))]))));
89
+ } else {
90
+ path.parent.node.attributes.push(j.jsxAttribute(j.jsxIdentifier('style'), j.jsxExpressionContainer(cssVarsObject)));
91
+ }
92
+ }
93
+ }
94
+ if (conditionalExpressions.length && sxContainer.expression.type === 'ArrayExpression') {
95
+ // insert the conditional expressions in the correct order
96
+ let cumulativeIndex = 0;
97
+ conditionalExpressions.forEach(([index, newElement]) => {
98
+ sxContainer.expression.elements.splice(index + 1 + cumulativeIndex, 0, newElement);
99
+ cumulativeIndex += 1;
100
+ });
101
+ }
102
+ if (sxContainer.expression.type === 'ArrayExpression') {
103
+ sxContainer.expression.elements = sxContainer.expression.elements.filter(item => item.type !== 'ObjectExpression' || item.properties.length > 0);
104
+ }
105
+ }
106
+ function wrapSxInArray(newElement) {
107
+ if (sxContainer.expression.type === 'ObjectExpression' || sxContainer.expression.type === 'ArrowFunctionExpression') {
108
+ sxContainer.expression = j.arrayExpression([sxContainer.expression]);
109
+ }
110
+ if (sxContainer.expression.type === 'ArrayExpression') {
111
+ // store in a list to be added later to ensure the sequence of styles
112
+ conditionalExpressions.push([currentIndex, newElement]);
113
+ }
114
+ }
115
+
116
+ /**
117
+ *
118
+ * @param {{ node: import('jscodeshift').Expression }} data
119
+ */
120
+ function recurseObjectExpression(data) {
121
+ if (data.node.type === 'ArrowFunctionExpression') {
122
+ const returnExpression = (0, _getReturnExpression.default)(data.node);
123
+ if (returnExpression) {
124
+ recurseObjectExpression({
125
+ ...data,
126
+ node: returnExpression
127
+ });
128
+ }
129
+ }
130
+ if (data.node.type === 'ObjectExpression') {
131
+ const modeStyles = {}; // to collect styles from `theme.palette.mode === '...'`
132
+ data.node.properties.forEach(prop => {
133
+ if (prop.type === 'ObjectProperty') {
134
+ recurseObjectExpression({
135
+ ...data,
136
+ node: prop.value,
137
+ parentNode: data.node,
138
+ key: prop.key,
139
+ buildStyle: createBuildStyle(prop.key, data.buildStyle),
140
+ replaceValue: newValue => {
141
+ prop.value = newValue;
142
+ },
143
+ deleteSelf: () => {
144
+ (0, _migrateToVariants.removeProperty)(data.node, prop);
145
+ if (data.node.properties.length === 0) {
146
+ var _data$deleteSelf;
147
+ (_data$deleteSelf = data.deleteSelf) == null || _data$deleteSelf.call(data);
148
+ }
149
+ },
150
+ modeStyles
151
+ });
152
+ } else {
153
+ recurseObjectExpression({
154
+ ...data,
155
+ node: prop,
156
+ parentNode: data.node,
157
+ buildStyle: createBuildStyle(prop.key, data.buildStyle)
158
+ });
159
+ }
160
+ });
161
+ appendPaletteModeStyles(data.node, modeStyles);
162
+ }
163
+ if (data.node.type === 'SpreadElement') {
164
+ if (data.node.argument.type === 'LogicalExpression') {
165
+ var _getObjectKey2, _getObjectKey3;
166
+ const paramName = data.node.argument.left.type === 'BinaryExpression' ? (_getObjectKey2 = (0, _migrateToVariants.getObjectKey)(data.node.argument.left.left)) == null ? void 0 : _getObjectKey2.name : (_getObjectKey3 = (0, _migrateToVariants.getObjectKey)(data.node.argument.left)) == null ? void 0 : _getObjectKey3.name;
167
+ if (paramName === 'theme' && data.node.argument.left.right.type === 'StringLiteral') {
168
+ if (data.node.argument.right.type === 'ObjectExpression') {
169
+ const mode = data.node.argument.left.right.value;
170
+ data.node.argument.right.properties.forEach(prop => {
171
+ if (prop.type === 'ObjectProperty') {
172
+ recurseObjectExpression({
173
+ ...data,
174
+ node: prop.value,
175
+ parentNode: data.node.argument.right,
176
+ key: prop.key,
177
+ buildStyle: createBuildStyle(prop.key, data.buildStyle, mode),
178
+ replaceValue: newValue => {
179
+ prop.value = newValue;
180
+ }
181
+ });
182
+ } else {
183
+ recurseObjectExpression({
184
+ ...data,
185
+ node: prop,
186
+ parentNode: data.node.argument.right,
187
+ buildStyle: createBuildStyle(prop.key, data.buildStyle, mode)
188
+ });
189
+ }
190
+ });
191
+ appendPaletteModeStyles(data.parentNode, {
192
+ [mode]: data.node.argument.right
193
+ });
194
+ }
195
+ if (data.deleteSelf) {
196
+ data.deleteSelf();
197
+ } else {
198
+ (0, _migrateToVariants.removeProperty)(data.parentNode, data.node);
199
+ }
200
+ return;
201
+ }
202
+ if (data.node.argument.right.type === 'ObjectExpression') {
203
+ recurseObjectExpression({
204
+ ...data,
205
+ node: data.node.argument.right,
206
+ root: data.node.argument.right,
207
+ replaceRoot: newRoot => {
208
+ data.node.argument.right = newRoot;
209
+ }
210
+ });
211
+ }
212
+ wrapSxInArray(j.logicalExpression(data.node.argument.operator, data.node.argument.left, data.node.argument.right));
213
+ if (data.deleteSelf) {
214
+ data.deleteSelf();
215
+ } else {
216
+ (0, _migrateToVariants.removeProperty)(data.parentNode, data.node);
217
+ }
218
+ }
219
+ if (data.node.argument.type === 'ConditionalExpression') {
220
+ recurseObjectExpression({
221
+ ...data,
222
+ node: data.node.argument,
223
+ parentNode: data.node
224
+ });
225
+ if (data.deleteSelf) {
226
+ data.deleteSelf();
227
+ } else {
228
+ (0, _migrateToVariants.removeProperty)(data.parentNode, data.node);
229
+ }
230
+ }
231
+ }
232
+ if (data.node.type === 'ConditionalExpression') {
233
+ if (data.node.test.type === 'BinaryExpression' || data.node.test.type === 'UnaryExpression' || data.node.test.type === 'Identifier' || data.node.test.type === 'MemberExpression') {
234
+ var _data$parentNode, _data$node$test, _data$node$test2;
235
+ if (((_data$parentNode = data.parentNode) == null ? void 0 : _data$parentNode.type) === 'ObjectExpression' && (((_data$node$test = data.node.test) == null ? void 0 : _data$node$test.type) === 'BinaryExpression' || ((_data$node$test2 = data.node.test) == null ? void 0 : _data$node$test2.type) === 'Identifier')) {
236
+ if (data.node.consequent.type !== 'ObjectExpression' && data.node.alternate.type !== 'ObjectExpression') {
237
+ if ((0, _migrateToVariants.isThemePaletteMode)(data.node.test.left)) {
238
+ var _data$replaceValue;
239
+ const consequentKey = (0, _migrateToVariants.getObjectKey)(data.node.consequent);
240
+ if (consequentKey.type === 'Identifier' && consequentKey.name !== 'theme') {
241
+ const varName = getCssVarName(data.node.consequent);
242
+ cssVars.push([j.stringLiteral(varName), data.node.consequent]);
243
+ data.node.consequent = j.stringLiteral(`var(${varName})`);
244
+ }
245
+ const alternateKey = (0, _migrateToVariants.getObjectKey)(data.node.alternate);
246
+ if (alternateKey.type === 'Identifier' && alternateKey.name !== 'theme') {
247
+ const varName = getCssVarName(data.node.alternate);
248
+ cssVars.push([j.stringLiteral(varName), data.node.alternate]);
249
+ data.node.alternate = j.stringLiteral(`var(${varName})`);
250
+ }
251
+ if (data.modeStyles) {
252
+ if (!data.modeStyles[data.node.test.right.value]) {
253
+ data.modeStyles[data.node.test.right.value] = [];
254
+ }
255
+ data.modeStyles[data.node.test.right.value].push(j.objectProperty(data.key, replaceUndefined(data.node.consequent)));
256
+ }
257
+ (_data$replaceValue = data.replaceValue) == null || _data$replaceValue.call(data, replaceUndefined(data.node.alternate));
258
+ if (data.root.type === 'ObjectExpression') {
259
+ var _data$replaceRoot;
260
+ (_data$replaceRoot = data.replaceRoot) == null || _data$replaceRoot.call(data, buildArrowFunctionAST([j.identifier('theme')], data.root));
261
+ } else if (data.root.type === 'ArrayExpression') {
262
+ data.root.elements.forEach((item, index) => {
263
+ if (item === data.node) {
264
+ data.root.elements[index] = buildArrowFunctionAST([j.identifier('theme')], data.root);
265
+ }
266
+ });
267
+ }
268
+ } else {
269
+ var _data$buildStyle, _data$buildStyle2;
270
+ wrapSxInArray(j.conditionalExpression(data.node.test, (_data$buildStyle = data.buildStyle) == null ? void 0 : _data$buildStyle.call(data, replaceUndefined(data.node.consequent)), (_data$buildStyle2 = data.buildStyle) == null ? void 0 : _data$buildStyle2.call(data, replaceUndefined(data.node.alternate))));
271
+ if (data.deleteSelf) {
272
+ data.deleteSelf();
273
+ } else {
274
+ (0, _migrateToVariants.removeProperty)(data.parentNode, data.node);
275
+ }
276
+ }
277
+ }
278
+ }
279
+ }
280
+ }
281
+ if (data.node.type === 'TemplateLiteral') {
282
+ var _data$parentNode2;
283
+ if (((_data$parentNode2 = data.parentNode) == null ? void 0 : _data$parentNode2.type) === 'ObjectExpression') {
284
+ const modeStyles = {};
285
+ data.node.expressions.forEach((expression, index) => {
286
+ if (expression.type === 'MemberExpression') {
287
+ const memberKey = (0, _migrateToVariants.getObjectKey)(expression);
288
+ if (memberKey.type === 'Identifier' && memberKey.name !== 'theme') {
289
+ const varName = getCssVarName(expression);
290
+ cssVars.push([j.stringLiteral(varName), expression]);
291
+ data.node.expressions[index] = j.stringLiteral(`var(${varName})`);
292
+ }
293
+ } else {
294
+ recurseObjectExpression({
295
+ ...data,
296
+ node: expression,
297
+ parentNode: data.parentNode,
298
+ buildStyle: createBuildStyle(data.key, data.buildStyle),
299
+ replaceValue: newValue => {
300
+ data.node.expressions[index] = newValue;
301
+ },
302
+ modeStyles
303
+ });
304
+ }
305
+ });
306
+ if (data.modeStyles) {
307
+ Object.entries(modeStyles).forEach(([mode, objectStyles]) => {
308
+ const clonedNode = {
309
+ ...data.node,
310
+ expressions: data.node.expressions.map(expression => ({
311
+ ...expression
312
+ }))
313
+ };
314
+ clonedNode.expressions = objectStyles.map(item => item.value);
315
+ if (!data.modeStyles[mode]) {
316
+ data.modeStyles[mode] = [];
317
+ }
318
+ data.modeStyles[mode].push(j.objectProperty(data.key, clonedNode));
319
+ });
320
+ if (data.key) {
321
+ var _data$replaceValue2;
322
+ (_data$replaceValue2 = data.replaceValue) == null || _data$replaceValue2.call(data, data.node);
323
+ }
324
+ }
325
+ }
326
+ }
327
+ }
328
+ });
329
+ const transformed = root.toSource(printOptions);
330
+ if (shouldTransform) {
331
+ // recast adds extra newlines that we don't want, https://github.com/facebook/jscodeshift/issues/249
332
+ // need to remove them manually
333
+ const lines = [];
334
+ let isInStyled = false;
335
+ let spaceMatch;
336
+ transformed.split('\n').forEach(line => {
337
+ if (!isInStyled) {
338
+ lines.push(line);
339
+ } else if (line !== '') {
340
+ var _line$match, _spaceMatch;
341
+ if (spaceMatch && ((_line$match = line.match(/^\s+/)) == null ? void 0 : _line$match[0]) === ((_spaceMatch = spaceMatch) == null ? void 0 : _spaceMatch[0]) && line.endsWith('}')) {
342
+ isInStyled = false;
343
+ spaceMatch = null;
344
+ }
345
+ lines.push(line);
346
+ }
347
+ if (line.includes('sx=')) {
348
+ isInStyled = true;
349
+ spaceMatch = line.match(/^\s+/);
350
+ }
351
+ });
352
+ return lines.join('\n');
353
+ }
354
+ return transformed;
355
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ var _jsxRuntime = require("react/jsx-runtime");
4
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(Toolbar, {
5
+ variant: "regular",
6
+ sx: theme => ({
7
+ display: 'flex',
8
+ alignItems: 'center',
9
+ justifyContent: 'space-between',
10
+ flexShrink: 0,
11
+ borderRadius: '999px',
12
+ bgcolor: theme.palette.mode === 'light' ? 'hsla(220, 60%, 99%, 0.6)' : 'hsla(220, 0%, 0%, 0.7)',
13
+ backdropFilter: 'blur(24px)',
14
+ maxHeight: 40,
15
+ border: '1px solid',
16
+ borderColor: 'divider',
17
+ boxShadow: theme.palette.mode === 'light' ? '0 1px 2px hsla(210, 0%, 0%, 0.05), 0 2px 12px hsla(210, 100%, 80%, 0.5)' : '0 1px 2px hsla(210, 0%, 0%, 0.5), 0 2px 12px hsla(210, 100%, 25%, 0.3)'
18
+ })
19
+ });
20
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(Box, {
21
+ component: "main",
22
+ sx: {
23
+ backgroundColor: theme => theme.palette.mode === 'light' ? theme.palette.grey[100] : theme.palette.grey[900],
24
+ flexGrow: 1,
25
+ height: '100vh',
26
+ overflow: 'auto'
27
+ }
28
+ });
29
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(Box, {
30
+ sx: {
31
+ borderBottom: theme => `1px solid ${theme.palette.mode === 'light' ? 'grey.200' : 'grey.800'}`,
32
+ backgroundSize: 'cover',
33
+ backgroundPosition: 'center',
34
+ minHeight: 280
35
+ }
36
+ });
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ var _jsxRuntime = require("react/jsx-runtime");
4
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(Toolbar, {
5
+ variant: "regular",
6
+ sx: theme => ({
7
+ display: 'flex',
8
+ alignItems: 'center',
9
+ justifyContent: 'space-between',
10
+ flexShrink: 0,
11
+ borderRadius: '999px',
12
+ bgcolor: 'hsla(220, 0%, 0%, 0.7)',
13
+ backdropFilter: 'blur(24px)',
14
+ maxHeight: 40,
15
+ border: '1px solid',
16
+ borderColor: 'divider',
17
+ boxShadow: '0 1px 2px hsla(210, 0%, 0%, 0.5), 0 2px 12px hsla(210, 100%, 25%, 0.3)',
18
+ ...theme.applyStyles("light", {
19
+ bgcolor: 'hsla(220, 60%, 99%, 0.6)',
20
+ boxShadow: '0 1px 2px hsla(210, 0%, 0%, 0.05), 0 2px 12px hsla(210, 100%, 80%, 0.5)'
21
+ })
22
+ })
23
+ });
24
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(Box, {
25
+ component: "main",
26
+ sx: theme => ({
27
+ backgroundColor: theme.palette.grey[900],
28
+ flexGrow: 1,
29
+ height: '100vh',
30
+ overflow: 'auto',
31
+ ...theme.applyStyles("light", {
32
+ backgroundColor: theme.palette.grey[100]
33
+ })
34
+ })
35
+ });
36
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(Box, {
37
+ sx: theme => ({
38
+ borderBottom: `1px solid ${'grey.800'}`,
39
+ backgroundSize: 'cover',
40
+ backgroundPosition: 'center',
41
+ minHeight: 280,
42
+ ...theme.applyStyles("light", {
43
+ borderBottom: `1px solid ${'grey.200'}`
44
+ })
45
+ })
46
+ });
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ var _jsxRuntime = require("react/jsx-runtime");
4
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(Box, {
5
+ sx: {
6
+ backgroundImage: theme => theme.palette.mode === 'light' ? items[selectedItemIndex].imageLight : items[selectedItemIndex].imageDark
7
+ }
8
+ });
9
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(Box, {
10
+ style: props.style,
11
+ sx: {
12
+ backgroundImage: theme => theme.palette.mode === 'light' ? items[selectedItemIndex].imageLight : items[selectedItemIndex].imageDark
13
+ }
14
+ });
15
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(Box, {
16
+ style: {
17
+ color: 'red',
18
+ ...props.style
19
+ },
20
+ sx: {
21
+ backgroundImage: theme => theme.palette.mode === 'light' ? items[selectedItemIndex].imageLight : items[selectedItemIndex].imageDark
22
+ }
23
+ });
24
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(Box, {
25
+ ...props,
26
+ sx: {
27
+ backgroundImage: theme => theme.palette.mode === 'light' ? items[selectedItemIndex].imageLight : items[selectedItemIndex].imageDark
28
+ }
29
+ });
30
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(Paper, {
31
+ sx: {
32
+ position: 'relative',
33
+ backgroundColor: 'grey.800',
34
+ color: '#fff',
35
+ mb: 4,
36
+ backgroundSize: 'cover',
37
+ backgroundRepeat: 'no-repeat',
38
+ backgroundPosition: 'center',
39
+ backgroundImage: `url(${post.image})`
40
+ }
41
+ });