@sanity/ui-codemod 1.0.0-alpha.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.
Files changed (157) hide show
  1. package/bin/run.js +5 -0
  2. package/dist/_chunks-es/addAttribute.js +11 -0
  3. package/dist/_chunks-es/addAttribute.js.map +1 -0
  4. package/dist/_chunks-es/box.mods.js +186 -0
  5. package/dist/_chunks-es/box.mods.js.map +1 -0
  6. package/dist/_chunks-es/flex.mods.js +74 -0
  7. package/dist/_chunks-es/flex.mods.js.map +1 -0
  8. package/dist/_chunks-es/getTransformPath.js +75 -0
  9. package/dist/_chunks-es/getTransformPath.js.map +1 -0
  10. package/dist/_chunks-es/grid.mods.js +110 -0
  11. package/dist/_chunks-es/grid.mods.js.map +1 -0
  12. package/dist/_chunks-es/layout-mods.js +424 -0
  13. package/dist/_chunks-es/layout-mods.js.map +1 -0
  14. package/dist/_chunks-es/transformComponent.js +359 -0
  15. package/dist/_chunks-es/transformComponent.js.map +1 -0
  16. package/dist/commands/latest/box.d.ts +47 -0
  17. package/dist/commands/latest/box.js +17 -0
  18. package/dist/commands/latest/box.js.map +1 -0
  19. package/dist/commands/latest/card.d.ts +47 -0
  20. package/dist/commands/latest/card.js +17 -0
  21. package/dist/commands/latest/card.js.map +1 -0
  22. package/dist/commands/latest/code.d.ts +47 -0
  23. package/dist/commands/latest/code.js +17 -0
  24. package/dist/commands/latest/code.js.map +1 -0
  25. package/dist/commands/latest/container.d.ts +47 -0
  26. package/dist/commands/latest/container.js +17 -0
  27. package/dist/commands/latest/container.js.map +1 -0
  28. package/dist/commands/latest/flex.d.ts +47 -0
  29. package/dist/commands/latest/flex.js +17 -0
  30. package/dist/commands/latest/flex.js.map +1 -0
  31. package/dist/commands/latest/grid.d.ts +47 -0
  32. package/dist/commands/latest/grid.js +17 -0
  33. package/dist/commands/latest/grid.js.map +1 -0
  34. package/dist/commands/latest/heading.d.ts +47 -0
  35. package/dist/commands/latest/heading.js +17 -0
  36. package/dist/commands/latest/heading.js.map +1 -0
  37. package/dist/commands/latest/text.d.ts +47 -0
  38. package/dist/commands/latest/text.js +17 -0
  39. package/dist/commands/latest/text.js.map +1 -0
  40. package/dist/transforms/latest/box/box.d.ts +18 -0
  41. package/dist/transforms/latest/box/box.js +101 -0
  42. package/dist/transforms/latest/box/box.js.map +1 -0
  43. package/dist/transforms/latest/card/card.d.ts +18 -0
  44. package/dist/transforms/latest/card/card.js +618 -0
  45. package/dist/transforms/latest/card/card.js.map +1 -0
  46. package/dist/transforms/latest/code/code.d.ts +18 -0
  47. package/dist/transforms/latest/code/code.js +73 -0
  48. package/dist/transforms/latest/code/code.js.map +1 -0
  49. package/dist/transforms/latest/container/container.d.ts +18 -0
  50. package/dist/transforms/latest/container/container.js +91 -0
  51. package/dist/transforms/latest/container/container.js.map +1 -0
  52. package/dist/transforms/latest/flex/flex.d.ts +18 -0
  53. package/dist/transforms/latest/flex/flex.js +19 -0
  54. package/dist/transforms/latest/flex/flex.js.map +1 -0
  55. package/dist/transforms/latest/grid/grid.d.ts +18 -0
  56. package/dist/transforms/latest/grid/grid.js +19 -0
  57. package/dist/transforms/latest/grid/grid.js.map +1 -0
  58. package/dist/transforms/latest/heading/heading.d.ts +18 -0
  59. package/dist/transforms/latest/heading/heading.js +85 -0
  60. package/dist/transforms/latest/heading/heading.js.map +1 -0
  61. package/dist/transforms/latest/text/text.d.ts +18 -0
  62. package/dist/transforms/latest/text/text.js +88 -0
  63. package/dist/transforms/latest/text/text.js.map +1 -0
  64. package/package.json +68 -0
  65. package/src/baseCommand.ts +74 -0
  66. package/src/commands/latest/box.ts +21 -0
  67. package/src/commands/latest/card.ts +21 -0
  68. package/src/commands/latest/code.ts +21 -0
  69. package/src/commands/latest/container.ts +21 -0
  70. package/src/commands/latest/flex.ts +21 -0
  71. package/src/commands/latest/grid.ts +21 -0
  72. package/src/commands/latest/heading.ts +21 -0
  73. package/src/commands/latest/inline.ts +21 -0
  74. package/src/commands/latest/label.ts +21 -0
  75. package/src/commands/latest/stack.ts +21 -0
  76. package/src/commands/latest/text.ts +21 -0
  77. package/src/constants/latest/layout-mods.ts +422 -0
  78. package/src/transforms/latest/box/box.mods.ts +88 -0
  79. package/src/transforms/latest/box/box.test.ts +204 -0
  80. package/src/transforms/latest/box/box.ts +104 -0
  81. package/src/transforms/latest/card/card.mods.ts +592 -0
  82. package/src/transforms/latest/card/card.test.ts +207 -0
  83. package/src/transforms/latest/card/card.ts +71 -0
  84. package/src/transforms/latest/code/code.mods.ts +57 -0
  85. package/src/transforms/latest/code/code.test.ts +61 -0
  86. package/src/transforms/latest/code/code.ts +53 -0
  87. package/src/transforms/latest/container/container.mods.ts +77 -0
  88. package/src/transforms/latest/container/container.test.ts +105 -0
  89. package/src/transforms/latest/container/container.ts +42 -0
  90. package/src/transforms/latest/flex/flex.mods.ts +73 -0
  91. package/src/transforms/latest/flex/flex.test.ts +80 -0
  92. package/src/transforms/latest/flex/flex.ts +42 -0
  93. package/src/transforms/latest/grid/grid.mods.ts +109 -0
  94. package/src/transforms/latest/grid/grid.test.ts +97 -0
  95. package/src/transforms/latest/grid/grid.ts +42 -0
  96. package/src/transforms/latest/heading/heading.mods.ts +70 -0
  97. package/src/transforms/latest/heading/heading.test.ts +87 -0
  98. package/src/transforms/latest/heading/heading.ts +53 -0
  99. package/src/transforms/latest/inline/inline.mods.ts +65 -0
  100. package/src/transforms/latest/inline/inline.test.ts +57 -0
  101. package/src/transforms/latest/inline/inline.ts +42 -0
  102. package/src/transforms/latest/label/label.mods.ts +72 -0
  103. package/src/transforms/latest/label/label.test.ts +113 -0
  104. package/src/transforms/latest/label/label.ts +67 -0
  105. package/src/transforms/latest/stack/stack.mods.ts +12 -0
  106. package/src/transforms/latest/stack/stack.test.ts +160 -0
  107. package/src/transforms/latest/stack/stack.ts +102 -0
  108. package/src/transforms/latest/text/text.mods.ts +72 -0
  109. package/src/transforms/latest/text/text.test.ts +113 -0
  110. package/src/transforms/latest/text/text.ts +57 -0
  111. package/src/types/AnyExpression.ts +9 -0
  112. package/src/types/AttributeMods.ts +16 -0
  113. package/src/types/BaseOptions.ts +6 -0
  114. package/src/utils/addAttribute.test.ts +43 -0
  115. package/src/utils/addAttribute.ts +26 -0
  116. package/src/utils/addImportSpecifier.test.ts +36 -0
  117. package/src/utils/addImportSpecifier.ts +42 -0
  118. package/src/utils/getAttribute.ts +22 -0
  119. package/src/utils/getAttributeExpression.ts +22 -0
  120. package/src/utils/getAttributeValue.ts +20 -0
  121. package/src/utils/getClonedImportSpecifiers.ts +29 -0
  122. package/src/utils/getComponentJsxNames.ts +17 -0
  123. package/src/utils/getComponentLocalNames.ts +69 -0
  124. package/src/utils/getCompositeAttrValue.ts +39 -0
  125. package/src/utils/getMappingArray.ts +36 -0
  126. package/src/utils/getMappingExpression.ts +22 -0
  127. package/src/utils/getMappingValue.ts +52 -0
  128. package/src/utils/getShorthandAttributes.ts +54 -0
  129. package/src/utils/getSplitImportSpecifiers.ts +40 -0
  130. package/src/utils/getStaticAttributeExpression.ts +35 -0
  131. package/src/utils/getStyleExpression.ts +37 -0
  132. package/src/utils/getStyledComponentAliases.ts +28 -0
  133. package/src/utils/getStyledComponentName.ts +52 -0
  134. package/src/utils/getTransformPath.ts +17 -0
  135. package/src/utils/insertTodoWarning.ts +48 -0
  136. package/src/utils/isImportBindingUsed.ts +53 -0
  137. package/src/utils/isValidStyleType.ts +21 -0
  138. package/src/utils/mergeStyle.ts +64 -0
  139. package/src/utils/removeUnusedImport.test.ts +77 -0
  140. package/src/utils/removeUnusedImport.ts +57 -0
  141. package/src/utils/replaceElement.test.ts +181 -0
  142. package/src/utils/replaceElement.ts +106 -0
  143. package/src/utils/replaceStyledComponent.test.ts +57 -0
  144. package/src/utils/replaceStyledComponent.ts +60 -0
  145. package/src/utils/shouldTransformComponent.test.ts +61 -0
  146. package/src/utils/shouldTransformComponent.ts +40 -0
  147. package/src/utils/testUtils.ts +54 -0
  148. package/src/utils/transformAttributes.test.ts +544 -0
  149. package/src/utils/transformAttributes.ts +248 -0
  150. package/src/utils/transformComponent.test.ts +45 -0
  151. package/src/utils/transformComponent.ts +31 -0
  152. package/src/utils/transformImport.test.ts +175 -0
  153. package/src/utils/transformImport.ts +55 -0
  154. package/src/utils/transformImportAlias.test.ts +40 -0
  155. package/src/utils/transformImportAlias.ts +49 -0
  156. package/src/utils/transformStyledComponents.test.ts +172 -0
  157. package/src/utils/transformStyledComponents.ts +58 -0
@@ -0,0 +1,207 @@
1
+ import {defineInlineTest} from '../../../utils/testUtils'
2
+ import transform from './card'
3
+
4
+ defineInlineTest(
5
+ transform,
6
+ {fromPackage: '@legacy/ui', toPackage: '@sanity/ui'},
7
+ `
8
+ import {Card} from '@legacy/ui'
9
+
10
+ <Card padding={4} radius={3} border />
11
+ `,
12
+ `
13
+ import {Card} from "@sanity/ui"
14
+
15
+ <Card density="regular" />
16
+ `,
17
+ 'updates Card import path based on fromPackage and toPackage',
18
+ )
19
+
20
+ defineInlineTest(
21
+ transform,
22
+ {fromPackage: '@legacy/ui', toPackage: '@sanity/ui'},
23
+ `
24
+ import {Card} from '@legacy/ui'
25
+
26
+ <Card />
27
+ `,
28
+ `
29
+ import {Box} from "@sanity/ui"
30
+
31
+ <Box />
32
+ `,
33
+ 'replaces Card with Box and updates import path based on fromPackage and toPackage',
34
+ )
35
+
36
+ defineInlineTest(
37
+ transform,
38
+ {fromPackage: '@legacy/ui', toPackage: '@sanity/ui'},
39
+ `
40
+ import {Card, Text} from '@legacy/ui'
41
+
42
+ <Card />
43
+ `,
44
+ `
45
+ import { Text } from '@legacy/ui';
46
+
47
+ import { Box } from "@sanity/ui";
48
+
49
+ <Box />
50
+ `,
51
+ 'replaces Card and updates import path with multiple specifiers',
52
+ )
53
+
54
+ defineInlineTest(
55
+ transform,
56
+ {},
57
+ `
58
+ <Card padding={4} radius={3} border />
59
+ `,
60
+ `
61
+ <Card density="regular" />
62
+ `,
63
+ 'preserves Card if padding and radius match density',
64
+ )
65
+
66
+ defineInlineTest(
67
+ transform,
68
+ {},
69
+ `
70
+ import {Card} from '@sanity/ui'
71
+
72
+ <Card padding={2} border={true} />
73
+ `,
74
+ `
75
+ import {Box} from '@sanity/ui'
76
+
77
+ <Box padding={2} border={true} />
78
+ `,
79
+ 'replaces Card with Box if padding and radius do not match density',
80
+ )
81
+
82
+ defineInlineTest(
83
+ transform,
84
+ {},
85
+ `
86
+ import {Card} from '@sanity/ui'
87
+
88
+ <>
89
+ <Card padding={1} />
90
+ <Card padding={4} radius={3} border />
91
+ </>
92
+ `,
93
+ `
94
+ import { Card, Box } from '@sanity/ui';
95
+
96
+ <>
97
+ <Box padding={1} />
98
+ <Card density="regular" />
99
+ </>
100
+ `,
101
+ 'replaces Card with Box and adds Box import',
102
+ )
103
+
104
+ defineInlineTest(
105
+ transform,
106
+ {},
107
+ `
108
+ import {Card} from '@sanity/ui'
109
+
110
+ <Card padding={1} />
111
+ `,
112
+ `
113
+ import {Box} from '@sanity/ui'
114
+
115
+ <Box padding={1} />
116
+ `,
117
+ 'replaces Card with Box and removes Card import',
118
+ )
119
+
120
+ defineInlineTest(
121
+ transform,
122
+ {},
123
+ `
124
+ <Card padding={1}>
125
+ <span />
126
+ </Card>
127
+ `,
128
+ `
129
+ <Box padding={1}>
130
+ <span />
131
+ </Box>
132
+ `,
133
+ 'replaces Card with Box and updates closing tag',
134
+ )
135
+
136
+ defineInlineTest(
137
+ transform,
138
+ {},
139
+ `
140
+ <Card padding={4} radius={3} border sizing="content" />
141
+ `,
142
+ `
143
+ <Card
144
+ density="regular"
145
+ style={{
146
+ boxSizing: "content-box"
147
+ }} />
148
+ `,
149
+ 'preserves Card and transforms attributes',
150
+ )
151
+
152
+ defineInlineTest(
153
+ transform,
154
+ {},
155
+ `
156
+ <Card padding={1} alignItems="center" />
157
+ `,
158
+ `
159
+ <Box padding={1} style={{
160
+ alignItems: "center"
161
+ }} />
162
+ `,
163
+ 'replaces Card with Box and transforms attributes',
164
+ )
165
+
166
+ defineInlineTest(
167
+ transform,
168
+ {},
169
+ `
170
+ <Card
171
+ padding={3}
172
+ border
173
+ radius={2}
174
+ style={{ borderStyle: 'dotted' }}
175
+ />
176
+ `,
177
+ `
178
+ <Card density="compact" style={{ borderStyle: 'dotted' }} />
179
+ `,
180
+ 'preserves Card and transforms attributes with style',
181
+ )
182
+
183
+ defineInlineTest(
184
+ transform,
185
+ {},
186
+ `
187
+ <Card scheme="light" />
188
+ `,
189
+ `
190
+ // UI-CODEMOD TODO: Please double check the Card migration below. The scheme prop has been deprecated.
191
+ <Card scheme="light" />
192
+ `,
193
+ 'warns if Card includes scheme prop',
194
+ )
195
+
196
+ defineInlineTest(
197
+ transform,
198
+ {},
199
+ `
200
+ <Card muted />
201
+ `,
202
+ `
203
+ // UI-CODEMOD TODO: Please double check the Card migration below. The muted prop has been deprecated.
204
+ <Card muted />
205
+ `,
206
+ 'warns if Card includes muted prop',
207
+ )
@@ -0,0 +1,71 @@
1
+ import {type API, type FileInfo} from 'jscodeshift'
2
+
3
+ import type {BaseOptions} from '../../../types/BaseOptions'
4
+ import {getAttribute} from '../../../utils/getAttribute'
5
+ import {getComponentLocalNames} from '../../../utils/getComponentLocalNames'
6
+ import {getStaticAttributeExpression} from '../../../utils/getStaticAttributeExpression'
7
+ import {replaceElement} from '../../../utils/replaceElement'
8
+ import {shouldTransformComponent} from '../../../utils/shouldTransformComponent'
9
+ import {transformAttributes} from '../../../utils/transformAttributes'
10
+ import {transformComponent} from '../../../utils/transformComponent'
11
+ import {transformImport} from '../../../utils/transformImport'
12
+ import {BOX_MODS} from '../box/box.mods'
13
+ import {CARD_MODS} from './card.mods'
14
+
15
+ const CARD_TODO_WARNING = 'Please double check the Card migration below'
16
+ const BOX_TODO_WARNING = 'Please double check the Box migration below'
17
+
18
+ /** @internal */
19
+ export default function transform(
20
+ fileInfo: FileInfo,
21
+ api: API,
22
+ options?: BaseOptions,
23
+ ): string | undefined {
24
+ const {fromPackage, toPackage} = options || {}
25
+
26
+ return transformComponent(fileInfo, api, ({j, root, markChanged}) => {
27
+ const localNames = getComponentLocalNames(j, root, 'Card', options)
28
+
29
+ if (!shouldTransformComponent(j, root, 'Card', localNames, options)) {
30
+ return
31
+ }
32
+
33
+ if (transformImport(j, root, 'Card', fromPackage, toPackage)) {
34
+ markChanged()
35
+ }
36
+
37
+ if (
38
+ replaceElement(
39
+ j,
40
+ root,
41
+ (attrs) => {
42
+ const density = getAttribute(attrs, 'density')
43
+ const muted = getAttribute(attrs, 'muted')
44
+ const scheme = getAttribute(attrs, 'scheme')
45
+ const border = getAttribute(attrs, 'border')
46
+ const padding = getStaticAttributeExpression(j, attrs, 'padding')
47
+ const radius = getStaticAttributeExpression(j, attrs, 'radius')
48
+
49
+ return !(
50
+ density ||
51
+ muted ||
52
+ scheme ||
53
+ (border && padding === 3 && radius == 2) ||
54
+ (border && padding === 4 && radius == 3) ||
55
+ (border && padding === 5 && radius == 4)
56
+ )
57
+ },
58
+ {
59
+ element: 'Card',
60
+ callback: (path) => transformAttributes(j, path, CARD_MODS, CARD_TODO_WARNING),
61
+ },
62
+ {
63
+ element: 'Box',
64
+ callback: (path) => transformAttributes(j, path, BOX_MODS, BOX_TODO_WARNING),
65
+ },
66
+ )
67
+ ) {
68
+ markChanged()
69
+ }
70
+ })
71
+ }
@@ -0,0 +1,57 @@
1
+ import type {AttributeMods} from '../../../types/AttributeMods'
2
+
3
+ /** @internal */
4
+ export const CODE_MODS: AttributeMods = {
5
+ flex: {
6
+ type: 'style-mapped',
7
+ style: 'flex',
8
+ mapping: {
9
+ none: '0 0 auto',
10
+ auto: '1 1 auto',
11
+ initial: '0 1 auto',
12
+ 1: '1',
13
+ 2: '2',
14
+ 3: '3',
15
+ 4: '4',
16
+ 5: '5',
17
+ 6: '6',
18
+ 7: '7',
19
+ 8: '8',
20
+ 9: '9',
21
+ 10: '10',
22
+ 11: '11',
23
+ 12: '12',
24
+ },
25
+ },
26
+ maxWidth: {
27
+ type: 'style-mapped',
28
+ style: 'maxWidth',
29
+ mapping: {
30
+ auto: 'none',
31
+ fill: '100%',
32
+ 0: '20rem',
33
+ 1: '40rem',
34
+ 2: '60rem',
35
+ 3: '80rem',
36
+ 4: '100rem',
37
+ 5: '120rem',
38
+ },
39
+ },
40
+ width: {
41
+ type: 'style-mapped',
42
+ style: 'width',
43
+ mapping: {
44
+ auto: 'auto',
45
+ fill: '100%',
46
+ stretch: 'stretch',
47
+ min: 'min-content',
48
+ max: 'max-content',
49
+ 0: '20rem',
50
+ 1: '40rem',
51
+ 2: '60rem',
52
+ 3: '80rem',
53
+ 4: '100rem',
54
+ 5: '120rem',
55
+ },
56
+ },
57
+ }
@@ -0,0 +1,61 @@
1
+ import {defineInlineTest} from '../../../utils/testUtils'
2
+ import transform from './code'
3
+
4
+ defineInlineTest(
5
+ transform,
6
+ {fromPackage: '@legacy/ui', toPackage: '@sanity/ui'},
7
+ `
8
+ import {Code} from '@legacy/ui'
9
+
10
+ <Code />
11
+ `,
12
+ `
13
+ import {Code} from "@sanity/ui"
14
+
15
+ <Code trim={true} />
16
+ `,
17
+ 'updates Code import path based on fromPackage and toPackage',
18
+ )
19
+
20
+ defineInlineTest(
21
+ transform,
22
+ {},
23
+ `
24
+ <Code />
25
+ `,
26
+ `
27
+ <Code trim={true} />
28
+ `,
29
+ 'adds trim prop',
30
+ )
31
+
32
+ defineInlineTest(
33
+ transform,
34
+ {},
35
+ `
36
+ <Code flex="auto" />
37
+ `,
38
+ `
39
+ <Code
40
+ style={{
41
+ flex: "1 1 auto"
42
+ }}
43
+ trim={true} />
44
+ `,
45
+ 'moves flex prop to style',
46
+ )
47
+
48
+ defineInlineTest(
49
+ transform,
50
+ {},
51
+ `
52
+ <Code width={1} maxWidth="fill" />
53
+ `,
54
+ `
55
+ <Code style={{
56
+ width: "40rem",
57
+ maxWidth: "100%"
58
+ }} trim={true} />
59
+ `,
60
+ 'moves width props to style and uppdates mapped values',
61
+ )
@@ -0,0 +1,53 @@
1
+ import {type API, type FileInfo} from 'jscodeshift'
2
+
3
+ import type {BaseOptions} from '../../../types/BaseOptions'
4
+ import {addAttribute} from '../../../utils/addAttribute'
5
+ import {getComponentLocalNames} from '../../../utils/getComponentLocalNames'
6
+ import {shouldTransformComponent} from '../../../utils/shouldTransformComponent'
7
+ import {transformAttributes} from '../../../utils/transformAttributes'
8
+ import {transformComponent} from '../../../utils/transformComponent'
9
+ import {transformImport} from '../../../utils/transformImport'
10
+ import {CODE_MODS} from './code.mods'
11
+
12
+ const TODO_WARNING = 'Please double check the Code migration below'
13
+
14
+ /** @internal */
15
+ export default function transform(
16
+ fileInfo: FileInfo,
17
+ api: API,
18
+ options: BaseOptions,
19
+ ): string | undefined {
20
+ const {fromPackage, toPackage} = options || {}
21
+
22
+ return transformComponent(fileInfo, api, ({j, root, markChanged}) => {
23
+ const localNames = getComponentLocalNames(j, root, 'Code', options)
24
+
25
+ if (!shouldTransformComponent(j, root, 'Code', localNames, options)) {
26
+ return
27
+ }
28
+
29
+ if (transformImport(j, root, 'Code', fromPackage, toPackage)) {
30
+ markChanged()
31
+ }
32
+
33
+ root
34
+ .find(j.JSXOpeningElement, {
35
+ name: {type: 'JSXIdentifier', name: 'Code'},
36
+ })
37
+ .forEach((path) => {
38
+ let changed = false
39
+
40
+ if (transformAttributes(j, path, CODE_MODS, TODO_WARNING)) {
41
+ changed = true
42
+ }
43
+
44
+ if (addAttribute(j, path.node, 'trim', true)) {
45
+ changed = true
46
+ }
47
+
48
+ if (changed) {
49
+ markChanged()
50
+ }
51
+ })
52
+ })
53
+ }
@@ -0,0 +1,77 @@
1
+ import {LAYOUT_MODS} from '../../../constants/latest/layout-mods'
2
+ import type {AttributeMods} from '../../../types/AttributeMods'
3
+
4
+ /** @internal */
5
+ export const CONTAINER_MODS: AttributeMods = {
6
+ ...LAYOUT_MODS,
7
+ alignItems: {
8
+ type: 'style-only',
9
+ style: 'alignItems',
10
+ },
11
+ flexDirection: {
12
+ type: 'style-only',
13
+ style: 'flexDirection',
14
+ },
15
+ flexWrap: {
16
+ type: 'style-only',
17
+ style: 'flexWrap',
18
+ },
19
+ gridAutoColumns: {
20
+ type: 'style-only',
21
+ style: 'gridAutoColumns',
22
+ },
23
+ gridAutoFlow: {
24
+ type: 'style-only',
25
+ style: 'gridAutoFlow',
26
+ },
27
+ gridAutoRows: {
28
+ type: 'style-only',
29
+ style: 'gridAutoRows',
30
+ },
31
+ gridTemplateColumns: {
32
+ type: 'style-mapped',
33
+ style: 'gridTemplateColumns',
34
+ mapping: {
35
+ 0: '0px',
36
+ 1: 'repeat(1, 1fr)',
37
+ 2: 'repeat(2, 1fr)',
38
+ 3: 'repeat(3, 1fr)',
39
+ 4: 'repeat(4, 1fr)',
40
+ 5: 'repeat(5, 1fr)',
41
+ 6: 'repeat(6, 1fr)',
42
+ 7: 'repeat(7, 1fr)',
43
+ 8: 'repeat(8, 1fr)',
44
+ 9: 'repeat(9, 1fr)',
45
+ 10: 'repeat(10, 1fr)',
46
+ 11: 'repeat(11, 1fr)',
47
+ 12: 'repeat(12, 1fr)',
48
+ },
49
+ },
50
+ gridTemplateRows: {
51
+ type: 'style-mapped',
52
+ style: 'gridTemplateRows',
53
+ mapping: {
54
+ 0: '0px',
55
+ 1: 'repeat(1, 1fr)',
56
+ 2: 'repeat(2, 1fr)',
57
+ 3: 'repeat(3, 1fr)',
58
+ 4: 'repeat(4, 1fr)',
59
+ 5: 'repeat(5, 1fr)',
60
+ 6: 'repeat(6, 1fr)',
61
+ 7: 'repeat(7, 1fr)',
62
+ 8: 'repeat(8, 1fr)',
63
+ 9: 'repeat(9, 1fr)',
64
+ 10: 'repeat(10, 1fr)',
65
+ 11: 'repeat(11, 1fr)',
66
+ 12: 'repeat(12, 1fr)',
67
+ },
68
+ },
69
+ justifyContent: {
70
+ type: 'style-only',
71
+ style: 'justifyContent',
72
+ },
73
+ width: {
74
+ type: 'rename-only',
75
+ name: 'size',
76
+ },
77
+ }
@@ -0,0 +1,105 @@
1
+ import {defineInlineTest} from '../../../utils/testUtils'
2
+ import transform from './container'
3
+
4
+ defineInlineTest(
5
+ transform,
6
+ {fromPackage: '@legacy/ui', toPackage: '@sanity/ui'},
7
+ `
8
+ import {Container} from '@legacy/ui'
9
+
10
+ <Container />
11
+ `,
12
+ `
13
+ import {Container} from "@sanity/ui"
14
+
15
+ <Container />
16
+ `,
17
+ 'updates Container import path based on fromPackage and toPackage',
18
+ )
19
+
20
+ defineInlineTest(
21
+ transform,
22
+ {},
23
+ `
24
+ <Container width={2} />
25
+ `,
26
+ `
27
+ <Container size={2} />
28
+ `,
29
+ 'renames width to size',
30
+ )
31
+
32
+ defineInlineTest(
33
+ transform,
34
+ {},
35
+ `
36
+ <Container width={[1, 2, 3]} />
37
+ `,
38
+ `
39
+ <Container size={[1, 2, 3]} />
40
+ `,
41
+ 'renames responsive width to size',
42
+ )
43
+
44
+ defineInlineTest(
45
+ transform,
46
+ {},
47
+ `
48
+ <Container
49
+ alignItems="center"
50
+ flexDirection="row"
51
+ flexWrap="wrap"
52
+ justifyContent="center"
53
+ />
54
+ `,
55
+ `
56
+ <Container
57
+ style={{
58
+ alignItems: "center",
59
+ flexDirection: "row",
60
+ flexWrap: "wrap",
61
+ justifyContent: "center"
62
+ }} />
63
+ `,
64
+ 'moves flex props to style',
65
+ )
66
+
67
+ defineInlineTest(
68
+ transform,
69
+ {},
70
+ `
71
+ <Container
72
+ gridAutoColumns="auto"
73
+ gridAutoFlow="row"
74
+ gridAutoRows="auto"
75
+ />
76
+ `,
77
+ `
78
+ <Container
79
+ style={{
80
+ gridAutoColumns: "auto",
81
+ gridAutoFlow: "row",
82
+ gridAutoRows: "auto"
83
+ }} />
84
+ `,
85
+ 'moves grid props to style',
86
+ )
87
+
88
+ defineInlineTest(
89
+ transform,
90
+ {},
91
+ `
92
+ <Container
93
+ gridTemplateColumns={1}
94
+ gridTemplateRows={2}
95
+ />
96
+ `,
97
+ `
98
+ <Container
99
+ style={{
100
+ gridTemplateColumns: "repeat(1, 1fr)",
101
+ gridTemplateRows: "repeat(2, 1fr)"
102
+ }} />
103
+ `,
104
+ 'moves grid props to style and updates mapped values',
105
+ )
@@ -0,0 +1,42 @@
1
+ import {type API, type FileInfo} from 'jscodeshift'
2
+
3
+ import type {BaseOptions} from '../../../types/BaseOptions'
4
+ import {getComponentLocalNames} from '../../../utils/getComponentLocalNames'
5
+ import {shouldTransformComponent} from '../../../utils/shouldTransformComponent'
6
+ import {transformAttributes} from '../../../utils/transformAttributes'
7
+ import {transformComponent} from '../../../utils/transformComponent'
8
+ import {transformImport} from '../../../utils/transformImport'
9
+ import {CONTAINER_MODS} from './container.mods'
10
+
11
+ const TODO_WARNING = 'Please double check the Container migration below'
12
+
13
+ /** @internal */
14
+ export default function transform(
15
+ fileInfo: FileInfo,
16
+ api: API,
17
+ options?: BaseOptions,
18
+ ): string | undefined {
19
+ const {fromPackage, toPackage} = options || {}
20
+
21
+ return transformComponent(fileInfo, api, ({j, root, markChanged}) => {
22
+ const localNames = getComponentLocalNames(j, root, 'Container', options)
23
+
24
+ if (!shouldTransformComponent(j, root, 'Container', localNames, options)) {
25
+ return
26
+ }
27
+
28
+ if (transformImport(j, root, 'Container', fromPackage, toPackage)) {
29
+ markChanged()
30
+ }
31
+
32
+ root
33
+ .find(j.JSXOpeningElement, {
34
+ name: {type: 'JSXIdentifier', name: 'Container'},
35
+ })
36
+ .forEach((path) => {
37
+ if (transformAttributes(j, path, CONTAINER_MODS, TODO_WARNING)) {
38
+ markChanged()
39
+ }
40
+ })
41
+ })
42
+ }