@planningcenter/tapestry-migration-cli 3.6.0 → 3.6.1-qa-1035.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.
Files changed (25) hide show
  1. package/dist/tapestry-react-shim.cjs +195 -11
  2. package/package.json +3 -3
  3. package/src/components/flex/index.test.ts +151 -0
  4. package/src/components/flex/index.ts +14 -0
  5. package/src/components/flex/transforms/auditSpreadProps.test.ts +93 -0
  6. package/src/components/flex/transforms/auditSpreadProps.ts +6 -0
  7. package/src/components/flex/transforms/axisToDirection.test.ts +15 -0
  8. package/src/components/flex/transforms/axisToDirection.ts +26 -0
  9. package/src/components/flex/transforms/convertStyleProps.test.ts +147 -0
  10. package/src/components/flex/transforms/convertStyleProps.ts +23 -0
  11. package/src/components/flex/transforms/cssFlexAliasesToProps.test.ts +202 -0
  12. package/src/components/flex/transforms/cssFlexAliasesToProps.ts +110 -0
  13. package/src/components/flex/transforms/flexPropToExpand.test.ts +156 -0
  14. package/src/components/flex/transforms/flexPropToExpand.ts +100 -0
  15. package/src/components/flex/transforms/mediaQueriesToResponsive.test.ts +714 -0
  16. package/src/components/flex/transforms/mediaQueriesToResponsive.ts +523 -0
  17. package/src/components/flex/transforms/paddingPropsToFlex.test.ts +252 -0
  18. package/src/components/flex/transforms/paddingPropsToFlex.ts +150 -0
  19. package/src/components/flex/transforms/setDefaultAxis.test.ts +12 -0
  20. package/src/components/flex/transforms/setDefaultAxis.ts +1 -0
  21. package/src/components/flex/transforms/unsupportedProps.test.ts +141 -0
  22. package/src/components/flex/transforms/unsupportedProps.ts +17 -0
  23. package/src/components/shared/helpers/unsupportedPropsHelpers.ts +41 -0
  24. package/src/components/shared/transformFactories/stylePropTransformFactory.test.ts +47 -0
  25. package/src/components/shared/transformFactories/stylePropTransformFactory.ts +16 -0
@@ -0,0 +1,100 @@
1
+ import { addCommentToAttribute } from "../../shared/actions/addCommentToAttribute"
2
+ import { getAttribute } from "../../shared/actions/getAttribute"
3
+ import { hasAttribute } from "../../shared/conditions/hasAttribute"
4
+ import { attributeTransformFactory } from "../../shared/transformFactories/attributeTransformFactory"
5
+
6
+ function parseFlexShorthand(
7
+ value: string
8
+ ): { basis: string; grow: number; shrink: number } | null {
9
+ const parts = value.trim().split(/\s+/)
10
+ if (parts.length !== 3) return null
11
+
12
+ const grow = Number(parts[0])
13
+ const shrink = Number(parts[1])
14
+ const basis = parts[2]
15
+
16
+ if (!Number.isFinite(grow) || !Number.isFinite(shrink)) return null
17
+
18
+ return { basis, grow, shrink }
19
+ }
20
+
21
+ const TODO_TEXT =
22
+ "could not migrate flex automatically; use grow, shrink, basis, or expand individually"
23
+
24
+ export default attributeTransformFactory({
25
+ condition: hasAttribute("flex"),
26
+ targetComponent: "StackView",
27
+ targetPackage: "@planningcenter/tapestry-react",
28
+ transform: (element, { j }) => {
29
+ const flexAttr = getAttribute({ element, name: "flex" })
30
+ if (!flexAttr) return false
31
+
32
+ const value = flexAttr.value
33
+ const attrs = element.openingElement.attributes
34
+
35
+ // flex={1} or flex="1" → expand
36
+ const isExpandValue =
37
+ (value?.type === "JSXExpressionContainer" &&
38
+ value.expression.type === "NumericLiteral" &&
39
+ (value.expression as { value: number }).value === 1) ||
40
+ (value?.type === "StringLiteral" &&
41
+ (value as { value: string }).value === "1")
42
+
43
+ if (isExpandValue) {
44
+ const idx = attrs.indexOf(flexAttr)
45
+ attrs.splice(idx, 1, j.jsxAttribute(j.jsxIdentifier("expand")))
46
+ return true
47
+ }
48
+
49
+ // flex={0} → grow={0} shrink={1} basis="0"
50
+ if (
51
+ value?.type === "JSXExpressionContainer" &&
52
+ value.expression.type === "NumericLiteral" &&
53
+ (value.expression as { value: number }).value === 0
54
+ ) {
55
+ const idx = attrs.indexOf(flexAttr)
56
+ attrs.splice(
57
+ idx,
58
+ 1,
59
+ j.jsxAttribute(
60
+ j.jsxIdentifier("grow"),
61
+ j.jsxExpressionContainer(j.numericLiteral(0))
62
+ ),
63
+ j.jsxAttribute(
64
+ j.jsxIdentifier("shrink"),
65
+ j.jsxExpressionContainer(j.numericLiteral(1))
66
+ ),
67
+ j.jsxAttribute(j.jsxIdentifier("basis"), j.stringLiteral("0"))
68
+ )
69
+ return true
70
+ }
71
+
72
+ // flex="N N basis" → grow={N} shrink={N} basis="X"
73
+ if (value?.type === "StringLiteral") {
74
+ const parsed = parseFlexShorthand((value as { value: string }).value)
75
+ if (parsed) {
76
+ const idx = attrs.indexOf(flexAttr)
77
+ attrs.splice(
78
+ idx,
79
+ 1,
80
+ j.jsxAttribute(
81
+ j.jsxIdentifier("grow"),
82
+ j.jsxExpressionContainer(j.numericLiteral(parsed.grow))
83
+ ),
84
+ j.jsxAttribute(
85
+ j.jsxIdentifier("shrink"),
86
+ j.jsxExpressionContainer(j.numericLiteral(parsed.shrink))
87
+ ),
88
+ j.jsxAttribute(
89
+ j.jsxIdentifier("basis"),
90
+ j.stringLiteral(parsed.basis)
91
+ )
92
+ )
93
+ return true
94
+ }
95
+ }
96
+
97
+ addCommentToAttribute({ attribute: flexAttr, j, text: TODO_TEXT })
98
+ return true
99
+ },
100
+ })