Skip to content

Commit 469f9fe

Browse files
committed
Add flex-wrap, fix HUG
1 parent 3146e60 commit 469f9fe

10 files changed

Lines changed: 67 additions & 36 deletions

File tree

packages/backend/src/code.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,10 @@ export const run = async (settings: PluginSettings) => {
452452
const { framework } = settings;
453453
const selection = figma.currentPage.selection;
454454

455-
if (selection.length > 1) {
455+
if (selection.length === 0) {
456+
postEmptyMessage();
457+
return;
458+
} else if (selection.length > 1) {
456459
addWarning(
457460
"Ungrouped elements may have incorrect positioning. If this happens, try wrapping the selection in a Frame or Group.",
458461
);

packages/backend/src/common/commonChildrenOrder.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ export const commonSortChildrenWhenInferredAutoLayout = (
1818
// NONE is a bug from Figma.
1919
case "NONE":
2020
case "VERTICAL":
21-
console.log(
22-
"ordering",
23-
children.map((c) => c.name),
24-
children.sort((a, b) => a.y - b.y).map((c) => c.name),
25-
);
2621
return children.sort((a, b) => a.y - b.y);
2722
}
2823
}

packages/backend/src/common/nodeWidthHeight.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
11
import { Size } from "types";
22

33
export const nodeSize = (node: SceneNode, optimizeLayout: boolean): Size => {
4-
const nodeAuto =
5-
(optimizeLayout && "inferredAutoLayout" in node
6-
? node.inferredAutoLayout
7-
: null) ?? node;
8-
9-
// Check for explicit layout sizing properties
10-
if (
11-
"layoutSizingHorizontal" in nodeAuto &&
12-
"layoutSizingVertical" in nodeAuto
13-
) {
4+
if ("layoutSizingHorizontal" in node && "layoutSizingVertical" in node) {
145
const width =
15-
nodeAuto.layoutSizingHorizontal === "FILL"
6+
node.layoutSizingHorizontal === "FILL"
167
? "fill"
17-
: nodeAuto.layoutSizingHorizontal === "HUG"
8+
: node.layoutSizingHorizontal === "HUG"
189
? null
1910
: node.width;
2011

2112
const height =
22-
nodeAuto.layoutSizingVertical === "FILL"
13+
node.layoutSizingVertical === "FILL"
2314
? "fill"
24-
: nodeAuto.layoutSizingVertical === "HUG"
15+
: node.layoutSizingVertical === "HUG"
2516
? null
2617
: node.height;
2718

2819
return { width, height };
2920
}
3021

31-
if ("layoutMode" in nodeAuto && nodeAuto.layoutMode === "NONE") {
22+
const nodeAuto =
23+
(optimizeLayout && "inferredAutoLayout" in node
24+
? node.inferredAutoLayout
25+
: null) ?? node;
26+
27+
if (
28+
nodeAuto &&
29+
typeof nodeAuto === "object" &&
30+
"layoutMode" in nodeAuto &&
31+
nodeAuto.layoutMode === "NONE"
32+
) {
3233
return { width: node.width, height: node.height };
3334
}
3435

packages/backend/src/html/builderImpl/htmlAutoLayout.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,27 @@ const getGap = (node: InferredAutoLayoutResult): string | number =>
3737
? node.itemSpacing
3838
: "";
3939

40+
const getFlexWrap = (node: InferredAutoLayoutResult): string =>
41+
node.layoutWrap === "WRAP" ? "wrap" : "";
42+
43+
const getAlignContent = (node: InferredAutoLayoutResult): string => {
44+
if (node.layoutWrap !== "WRAP") return "";
45+
46+
switch (node.counterAxisAlignItems) {
47+
case undefined:
48+
case "MIN":
49+
return "flex-start";
50+
case "CENTER":
51+
return "center";
52+
case "MAX":
53+
return "flex-end";
54+
case "BASELINE":
55+
return "baseline";
56+
default:
57+
return "normal";
58+
}
59+
};
60+
4061
const getFlex = (
4162
node: SceneNode,
4263
autoLayout: InferredAutoLayoutResult,
@@ -59,6 +80,8 @@ export const htmlAutoLayoutProps = (
5980
"align-items": getAlignItems(autoLayout),
6081
gap: getGap(autoLayout),
6182
display: getFlex(node, autoLayout),
83+
"flex-wrap": getFlexWrap(autoLayout),
84+
"align-content": getAlignContent(autoLayout),
6285
},
6386
settings.htmlGenerationMode === "jsx",
6487
);

packages/backend/src/html/builderImpl/htmlSize.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const htmlSizePartial = (
1616
}
1717

1818
const size = nodeSize(node, optimizeLayout);
19+
console.log("size", size);
1920
const nodeParent =
2021
(node.parent && optimizeLayout && "inferredAutoLayout" in node.parent
2122
? node.parent.inferredAutoLayout

packages/backend/src/tailwind/builderImpl/tailwindAutoLayout.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,27 @@ const getGap = (node: InferredAutoLayoutResult): string =>
3636
? `gap-${pxToLayoutSize(node.itemSpacing)}`
3737
: "";
3838

39+
const getFlexWrap = (node: InferredAutoLayoutResult): string =>
40+
node.layoutWrap === "WRAP" ? "flex-wrap" : "";
41+
42+
const getAlignContent = (node: InferredAutoLayoutResult): string => {
43+
if (node.layoutWrap !== "WRAP") return "";
44+
45+
switch (node.counterAxisAlignItems) {
46+
case undefined:
47+
case "MIN":
48+
return "content-start";
49+
case "CENTER":
50+
return "content-center";
51+
case "MAX":
52+
return "content-end";
53+
case "BASELINE":
54+
return "content-baseline";
55+
default:
56+
return "content-normal";
57+
}
58+
};
59+
3960
const getFlex = (
4061
node: SceneNode,
4162
autoLayout: InferredAutoLayoutResult,
@@ -56,6 +77,8 @@ export const tailwindAutoLayoutProps = (
5677
getJustifyContent(autoLayout),
5778
getAlignItems(autoLayout),
5879
getGap(autoLayout),
80+
getFlexWrap(autoLayout),
81+
getAlignContent(autoLayout),
5982
].filter(Boolean);
6083

6184
return classes.join(" ");

packages/backend/src/tailwind/builderImpl/tailwindColor.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ export const tailwindSolidColor = (
6666
fill: SolidPaint | ColorStop,
6767
kind: TailwindColorType,
6868
): string => {
69-
console.log("fill is", fill);
7069
const { colorName } = getColorInfo(fill);
7170
const effectiveOpacity = calculateEffectiveOpacity(fill);
7271

packages/backend/src/tailwind/conversionTables.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ const pxToTailwind = (
7878
const keys = Object.keys(conversionMap).map((d) => +d);
7979
const convertedValue = exactValue(value, keys);
8080

81-
console.log("convertedValue", convertedValue, value, keys);
82-
8381
if (convertedValue) {
8482
return conversionMap[convertedValue];
8583
} else if (localTailwindSettings.roundTailwindValues) {
@@ -176,11 +174,6 @@ export function getColorInfo(fill: SolidPaint | ColorStop) {
176174
let hex: string = "#" + rgbTo6hex(fill.color);
177175
let meta: string = "";
178176

179-
console.log(
180-
"(fill as any).variableColorName",
181-
fill,
182-
(fill as any).variableColorName,
183-
);
184177
// variable
185178
if ((fill as any).variableColorName) {
186179
// Use pre-computed variable name if available

packages/backend/src/tailwind/tailwindTextBuilder.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ export class TailwindTextBuilder extends TailwindDefaultBuilder {
5858
.filter(Boolean)
5959
.join(" ");
6060

61-
console.log("styleClasses", styleClasses, segment);
62-
6361
const charsWithLineBreak = segment.characters.split("\n").join("<br/>");
6462
return {
6563
style: styleClasses,

packages/plugin-ui/src/components/CodePanel.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,6 @@ const CodePanel = (props: CodePanelProps) => {
135135
};
136136
}, [preferenceOptions, selectPreferenceOptions, selectedFramework]);
137137

138-
// Handle custom prefix change
139-
const handleCustomPrefixChange = (newValue: string) => {
140-
onPreferenceChanged("customTailwindPrefix", newValue);
141-
};
142-
143138
return (
144139
<div className="w-full flex flex-col gap-2 mt-2">
145140
<div className="flex items-center justify-between w-full">

0 commit comments

Comments
 (0)