@oxy.so/bloom-language-codemod 0.2.1 → 0.3.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Compatibility
6
+
7
+ - Its peer is `@oxy.so/bloom-language` 1.4.0 or newer, the language it writes.
8
+
9
+ ### Added
10
+
11
+ - A `VirtualList`'s `overrideItemLayout` is `.itemLayout(handler)`, as written, and a `ListHeaderComponentStyle` of exactly `{ flexGrow: 0, flexShrink: 0, alignSelf: 'stretch' }` (a literal or a module constant) is `.headerFitsContent()`. Any other header style stays a reason.
12
+
3
13
  ## 0.2.1
4
14
 
5
15
  ### Changed
@@ -43,7 +43,9 @@ export type Form = 'string' | 'token' | 'flag' | 'boolean' | 'mark' | 'number' |
43
43
  /** A style that is its fill alone (`{ backgroundColor }`): a role or an app colour. */
44
44
  | 'fill'
45
45
  /** Bloom Screen's `reselect` handler: `.onReselect(refresh)` and `.reselectTop(isAtTop, scrollToTop)`. */
46
- | 'reselect';
46
+ | 'reselect'
47
+ /** A list header container style that keeps the header to its content (`{ flexGrow: 0, flexShrink: 0, alignSelf: 'stretch' }`): the bare modifier. */
48
+ | 'headerStyle';
47
49
  /** A prop as a modifier: its name and form, and for a token, Bloom's value to the language's. */
48
50
  export interface PropRule {
49
51
  readonly modifier: string;
package/lib/components.js CHANGED
@@ -690,10 +690,12 @@ exports.COMPONENT_RULES = {
690
690
  estimatedItemSize: p('estimatedItemSize', 'number'),
691
691
  contentContainerStyle: p('contentMargins', 'contentStyle'),
692
692
  numColumns: p('columns', 'number'),
693
+ overrideItemLayout: p('itemLayout', 'handler'),
693
694
  onEndReached: { ...p('onEndReached', 'handler'), with: ['onEndReachedThreshold', 'number'] },
694
695
  restorationKey: p('restorationKey', 'string'),
695
696
  stickyHeaderIndices: p('stickyIndices', 'items'),
696
697
  ListHeaderComponent: p('headerContent', 'element'),
698
+ ListHeaderComponentStyle: p('headerFitsContent', 'headerStyle'),
697
699
  ListFooterComponent: p('footerContent', 'element'),
698
700
  ListEmptyComponent: p('emptyState', 'element'),
699
701
  // A query-driven pull to refresh: `.refreshable({ refreshing, onRefresh })`, as written.
package/lib/transform.js CHANGED
@@ -2354,6 +2354,13 @@ function transformSource(source, options) {
2354
2354
  unmapped(name);
2355
2355
  continue;
2356
2356
  }
2357
+ if (prop?.form === 'headerStyle') {
2358
+ if (value && fitsContent(attributeExpression(value)))
2359
+ props.push({ name: prop.modifier, args: [] });
2360
+ else
2361
+ unmapped(name);
2362
+ continue;
2363
+ }
2357
2364
  if (prop?.marks) {
2358
2365
  // A static string naming the bare modifier, or none.
2359
2366
  const text = staticString(value);
@@ -2864,6 +2871,34 @@ function transformSource(source, options) {
2864
2871
  styleLiterals.set(expression, recast.print(object).code);
2865
2872
  return mods;
2866
2873
  }
2874
+ /**
2875
+ * A list header container style (an object literal or a module constant)
2876
+ * that is exactly `{ flexGrow: 0, flexShrink: 0, alignSelf: 'stretch' }`,
2877
+ * in any order: the header kept to its content, `.headerFitsContent()`.
2878
+ */
2879
+ function fitsContent(expression) {
2880
+ const object = moduleStyleReads.has(expression)
2881
+ ? styleSheets.get(expression.object.name)?.get(expression.property.name)
2882
+ : (styleConstantReads.get(expression) ?? expression);
2883
+ if (!n.ObjectExpression.check(object))
2884
+ return false;
2885
+ const seen = new Map();
2886
+ for (const property of object.properties) {
2887
+ if (!(n.ObjectProperty.check(property) || n.Property.check(property)) ||
2888
+ property.computed ||
2889
+ !n.Identifier.check(property.key))
2890
+ return false;
2891
+ const key = property.key.name;
2892
+ seen.set(key, key === 'alignSelf' ? staticString(property.value) : staticNumber(property.value));
2893
+ }
2894
+ const fits = seen.size === 3 &&
2895
+ seen.get('flexGrow') === 0 &&
2896
+ seen.get('flexShrink') === 0 &&
2897
+ seen.get('alignSelf') === 'stretch';
2898
+ if (fits && object !== expression)
2899
+ styleLiterals.set(expression, recast.print(object).code);
2900
+ return fits;
2901
+ }
2867
2902
  /** A style that is a fill alone (`{ backgroundColor: '#000' }`) as its colour (`inkOf`). */
2868
2903
  function fillOf(node, expression) {
2869
2904
  const [property, ...rest] = n.ObjectExpression.check(expression) ? expression.properties : [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oxy.so/bloom-language-codemod",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Moves an app's NativeWind className JSX and Bloom JSX to Bloom's UI language, only where the rendered result stays identical, and proves it with the language's parity harness.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "repository": {
@@ -51,10 +51,10 @@
51
51
  "recast": "0.23.11"
52
52
  },
53
53
  "peerDependencies": {
54
- "@oxy.so/bloom-language": ">=1.1.0"
54
+ "@oxy.so/bloom-language": ">=1.4.0"
55
55
  },
56
56
  "devDependencies": {
57
- "@oxy.so/bloom-language": "1.2.0",
57
+ "@oxy.so/bloom-language": "1.4.0",
58
58
  "bloom-22": "https://registry.npmjs.org/@oxy.so/bloom/-/bloom-22.1.11.tgz",
59
59
  "lightningcss": "1.30.1",
60
60
  "nativewind": "5.0.0-rc.0",