@react-spectrum/codemods 3.0.0-nightly-3f44370de-241117 → 3.0.0-nightly-b3a4d6c11-241119

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.
@@ -140,7 +140,7 @@ const UNIT_RE = /(%|px|em|rem|vw|vh|auto|cm|mm|in|pt|pc|ex|ch|rem|vmin|vmax|fr)$
140
140
  const FUNC_RE = /^\s*\w+\(/;
141
141
  // const SPECTRUM_VARIABLE_RE = /(static-)?size-\d+|single-line-(height|width)/g;
142
142
  const SIZING_RE = /auto|100vh|min-content|max-content|fit-content/;
143
- function convertDimension(value, toPixels = false) {
143
+ function convertDimension(value, type) {
144
144
  let pixelValue;
145
145
  if (typeof value === 'number') {
146
146
  pixelValue = value;
@@ -170,10 +170,10 @@ function convertDimension(value, toPixels = false) {
170
170
  if (pixelValue == null) {
171
171
  throw new Error('invalid dimension: ' + value);
172
172
  }
173
- if (toPixels) {
173
+ if (type === 'px') {
174
174
  return `${pixelValue}px`;
175
175
  }
176
- if (spacingValues.includes(pixelValue)) {
176
+ if (type === 'size' || spacingValues.includes(pixelValue)) {
177
177
  return pixelValue;
178
178
  }
179
179
  // TODO: Convert to rems? Find nearest value?
@@ -184,16 +184,16 @@ function convertGridTrack(value, toPixels = false) {
184
184
  return value;
185
185
  }
186
186
  else {
187
- return convertDimension(value, toPixels);
187
+ return convertDimension(value, toPixels ? 'px' : 'space');
188
188
  }
189
189
  }
190
- function convertUnsafeDimension(value) {
190
+ function convertUnsafeDimension(value, type) {
191
191
  if (typeof value === 'number') {
192
- return convertDimension(value);
192
+ return convertDimension(value, type);
193
193
  }
194
194
  let m = value.match(/^var\(--spectrum-global-dimension-(static-)?size-(.*)\)$/);
195
195
  if (m) {
196
- return convertDimension(`${m[1] || ''}size-${m[2]}`);
196
+ return convertDimension(`${m[1] || ''}size-${m[2]}`, type);
197
197
  }
198
198
  return null;
199
199
  }
@@ -63,7 +63,21 @@ function getStylePropValue(prop, value, element, colorVersion, condition = '') {
63
63
  case 'maxWidth':
64
64
  case 'height':
65
65
  case 'minHeight':
66
- case 'maxHeight':
66
+ case 'maxHeight': {
67
+ if (value.type === 'StringLiteral' || value.type === 'NumericLiteral') {
68
+ let val = (0, dimensions_1.convertDimension)(value.value, 'size');
69
+ if (val != null) {
70
+ return {
71
+ macroValues: [{ key: mappedProp, value: val }]
72
+ };
73
+ }
74
+ }
75
+ else if (value.type === 'ObjectExpression') {
76
+ return getResponsiveValue(prop, value, element, colorVersion);
77
+ }
78
+ // return [mappedProp, customProp, [[customProp, value]]];
79
+ return null;
80
+ }
67
81
  case 'margin':
68
82
  case 'marginStart':
69
83
  case 'marginEnd':
@@ -79,7 +93,7 @@ function getStylePropValue(prop, value, element, colorVersion, condition = '') {
79
93
  case 'end':
80
94
  case 'flexBasis': {
81
95
  if (value.type === 'StringLiteral' || value.type === 'NumericLiteral') {
82
- let val = (0, dimensions_1.convertDimension)(value.value);
96
+ let val = (0, dimensions_1.convertDimension)(value.value, 'space');
83
97
  if (val != null) {
84
98
  return {
85
99
  macroValues: [{ key: mappedProp, value: val }]
@@ -182,7 +196,7 @@ function getStylePropValue(prop, value, element, colorVersion, condition = '') {
182
196
  case 'rowGap':
183
197
  if (element === 'Flex' || element === 'Grid') {
184
198
  if (value.type === 'StringLiteral' || value.type === 'NumericLiteral') {
185
- let val = (0, dimensions_1.convertDimension)(value.value);
199
+ let val = (0, dimensions_1.convertDimension)(value.value, 'space');
186
200
  if (val != null) {
187
201
  return {
188
202
  macroValues: [{ key: mappedProp, value: val }]
@@ -308,7 +322,7 @@ function getStylePropValue(prop, value, element, colorVersion, condition = '') {
308
322
  case 'paddingBottom':
309
323
  if (element === 'View') {
310
324
  if (value.type === 'StringLiteral' || value.type === 'NumericLiteral') {
311
- let val = (0, dimensions_1.convertDimension)(value.value);
325
+ let val = (0, dimensions_1.convertDimension)(value.value, 'space');
312
326
  if (val != null) {
313
327
  return {
314
328
  macroValues: [{ key: mappedProp, value: val }]
@@ -410,7 +424,7 @@ function getStylePropValue(prop, value, element, colorVersion, condition = '') {
410
424
  // Try to automatically convert size prop to a macro value for components that supported size.
411
425
  if (element === 'ColorArea' || element === 'ColorWheel') {
412
426
  if (value.type === 'StringLiteral' || value.type === 'NumericLiteral') {
413
- let val = (0, dimensions_1.convertDimension)(value.value);
427
+ let val = (0, dimensions_1.convertDimension)(value.value, 'size');
414
428
  if (val != null) {
415
429
  return {
416
430
  macroValues: [{ key: 'size', value: val }]
@@ -541,7 +541,7 @@ function convertDimensionValueToPx(path, options) {
541
541
  if (attrPath && t.isJSXAttribute(attrPath.node) && attrPath.node.name.name === propToConvertValue) {
542
542
  if (t.isStringLiteral(attrPath.node.value)) {
543
543
  try {
544
- let value = (0, dimensions_1.convertDimension)(attrPath.node.value.value);
544
+ let value = (0, dimensions_1.convertDimension)(attrPath.node.value.value, 'size');
545
545
  if (value && typeof value === 'number') {
546
546
  attrPath.node.value = t.jsxExpressionContainer(t.numericLiteral(value));
547
547
  }
@@ -160,7 +160,12 @@ function handleProperty(element, property, value) {
160
160
  case 'maxWidth':
161
161
  case 'height':
162
162
  case 'minHeight':
163
- case 'maxHeight':
163
+ case 'maxHeight': {
164
+ if (value.type === 'NumericLiteral' || value.type === 'StringLiteral') {
165
+ return (0, dimensions_1.convertUnsafeDimension)(value.value, 'size');
166
+ }
167
+ break;
168
+ }
164
169
  case 'margin':
165
170
  case 'marginInlineStart':
166
171
  case 'marginInlineEnd':
@@ -178,7 +183,7 @@ function handleProperty(element, property, value) {
178
183
  case 'insetInlineEnd':
179
184
  case 'flexBasis': {
180
185
  if (value.type === 'NumericLiteral' || value.type === 'StringLiteral') {
181
- return (0, dimensions_1.convertUnsafeDimension)(value.value);
186
+ return (0, dimensions_1.convertUnsafeDimension)(value.value, 'space');
182
187
  }
183
188
  break;
184
189
  }
@@ -196,7 +201,7 @@ function handleProperty(element, property, value) {
196
201
  case 'columnGap': {
197
202
  if (element === 'View' || element === 'Flex' || element === 'Grid') {
198
203
  if (value.type === 'NumericLiteral' || value.type === 'StringLiteral') {
199
- return (0, dimensions_1.convertUnsafeDimension)(value.value);
204
+ return (0, dimensions_1.convertUnsafeDimension)(value.value, 'space');
200
205
  }
201
206
  }
202
207
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-spectrum/codemods",
3
- "version": "3.0.0-nightly-3f44370de-241117",
3
+ "version": "3.0.0-nightly-b3a4d6c11-241119",
4
4
  "main": "dist/index.js",
5
5
  "source": "src/index.ts",
6
6
  "bin": "dist/index.js",
@@ -24,8 +24,8 @@
24
24
  "@babel/parser": "^7.24.5",
25
25
  "@babel/traverse": "^7.24.5",
26
26
  "@babel/types": "^7.24.5",
27
- "@react-spectrum/s2": "^3.0.0-nightly-3f44370de-241117",
28
- "@react-types/shared": "^3.0.0-nightly-3f44370de-241117",
27
+ "@react-spectrum/s2": "^3.0.0-nightly-b3a4d6c11-241119",
28
+ "@react-types/shared": "^3.0.0-nightly-b3a4d6c11-241119",
29
29
  "@types/node": "^20",
30
30
  "boxen": "^5.1.2",
31
31
  "build": "^0.1.4",