@planningcenter/tapestry-migration-cli 3.6.0 → 3.7.0-rc.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/dist/tapestry-react-shim.cjs +195 -11
- package/package.json +3 -3
- package/src/components/flex/index.test.ts +181 -0
- package/src/components/flex/index.ts +16 -0
- package/src/components/flex/transforms/alignmentToAlign.test.ts +101 -0
- package/src/components/flex/transforms/alignmentToAlign.ts +74 -20
- package/src/components/flex/transforms/auditSpreadProps.test.ts +93 -0
- package/src/components/flex/transforms/auditSpreadProps.ts +6 -0
- package/src/components/flex/transforms/axisToDirection.test.ts +15 -0
- package/src/components/flex/transforms/axisToDirection.ts +26 -0
- package/src/components/flex/transforms/constants.ts +4 -0
- package/src/components/flex/transforms/convertStyleProps.test.ts +147 -0
- package/src/components/flex/transforms/convertStyleProps.ts +23 -0
- package/src/components/flex/transforms/cssFlexAliasesToProps.test.ts +202 -0
- package/src/components/flex/transforms/cssFlexAliasesToProps.ts +106 -0
- package/src/components/flex/transforms/dedupeAttributes.test.ts +120 -0
- package/src/components/flex/transforms/dedupeAttributes.ts +49 -0
- package/src/components/flex/transforms/distributionToJustify.test.ts +59 -0
- package/src/components/flex/transforms/distributionToJustify.ts +69 -20
- package/src/components/flex/transforms/flexPropToExpand.test.ts +172 -0
- package/src/components/flex/transforms/flexPropToExpand.ts +100 -0
- package/src/components/flex/transforms/mediaQueriesToResponsive.test.ts +795 -0
- package/src/components/flex/transforms/mediaQueriesToResponsive.ts +562 -0
- package/src/components/flex/transforms/paddingPropsToFlex.test.ts +252 -0
- package/src/components/flex/transforms/paddingPropsToFlex.ts +150 -0
- package/src/components/flex/transforms/setDefaultAxis.test.ts +12 -0
- package/src/components/flex/transforms/setDefaultAxis.ts +1 -0
- package/src/components/flex/transforms/spacingToGap.test.ts +87 -0
- package/src/components/flex/transforms/spacingToGap.ts +28 -10
- package/src/components/flex/transforms/unsupportedProps.test.ts +141 -0
- package/src/components/flex/transforms/unsupportedProps.ts +17 -0
- package/src/components/shared/helpers/unsupportedPropsHelpers.ts +41 -0
- package/src/components/shared/transformFactories/stylePropTransformFactory.test.ts +47 -0
- 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={N} (N !== 1) → grow={N} shrink={1} basis="0"
|
|
50
|
+
if (
|
|
51
|
+
value?.type === "JSXExpressionContainer" &&
|
|
52
|
+
value.expression.type === "NumericLiteral"
|
|
53
|
+
) {
|
|
54
|
+
const grow = (value.expression as { value: number }).value
|
|
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(grow))
|
|
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
|
+
})
|