Skip to content

Commit a4f5ae8

Browse files
committed
Refactor.
Improve size with optimized parent.
1 parent c6b4475 commit a4f5ae8

File tree

20 files changed

+607
-1120
lines changed

20 files changed

+607
-1120
lines changed

__tests__/tailwind/conversionTables.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe("Tailwind Conversion Table", () => {
3131
expect(pxToBorderRadius(2)).toEqual("-sm");
3232
expect(pxToBorderRadius(8)).toEqual("-lg");
3333

34-
expect(pxToLayoutSize(4)).toEqual("1");
35-
expect(pxToLayoutSize(385)).toEqual("96");
34+
expect(pxToLayoutSize(4, false)).toEqual("1");
35+
expect(pxToLayoutSize(385, false)).toEqual("96");
3636
});
3737
});

apps/debug/package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@
1010
"lint": "next lint"
1111
},
1212
"dependencies": {
13+
"backend": "workspace:*",
1314
"next": "latest",
15+
"plugin-ui": "workspace:*",
1416
"react": "^18.2.0",
15-
"react-dom": "^18.2.0",
16-
"backend": "workspace:*",
17-
"plugin-ui": "workspace:*"
17+
"react-dom": "^18.2.0"
1818
},
1919
"devDependencies": {
20-
"@types/node": "^18.15.3",
21-
"@types/react": "^18.0.28",
22-
"@types/react-dom": "^18.0.11",
20+
"@types/node": "^18.16.18",
21+
"@types/react": "^18.2.14",
22+
"@types/react-dom": "^18.2.6",
2323
"autoprefixer": "^10.4.14",
2424
"eslint-config-custom": "workspace:*",
25-
"postcss": "^8.4.21",
26-
"tsconfig": "workspace:*",
25+
"postcss": "^8.4.24",
2726
"tailwindcss": "3.2.7",
28-
"typescript": "^5.0.2"
27+
"tsconfig": "workspace:*",
28+
"typescript": "^5.1.3"
2929
}
3030
}

apps/plugin/package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"scripts": {
66
"build": "pnpm run build:ui && pnpm run build:main --minify --tree-shaking=true",
77
"build:main": "esbuild plugin-src/code.ts --bundle --target=ES6 --outfile=dist/code.js",
8-
"build:ui": "npx vite build --minify esbuild --emptyOutDir=false",
8+
"build:ui": "vite build --minify esbuild --emptyOutDir=false",
99
"build:watch": "concurrently -n backend,ui \"pnpm run build:main --watch\" \"pnpm run build:ui --watch\"",
1010
"dev": "pnpm build:watch"
1111
},
@@ -18,23 +18,23 @@
1818
},
1919
"devDependencies": {
2020
"@types/node": "^17.0.45",
21-
"@types/react": "^18.2.6",
22-
"@types/react-dom": "^18.2.4",
23-
"@typescript-eslint/eslint-plugin": "^5.59.6",
24-
"@typescript-eslint/parser": "^5.59.6",
25-
"@vitejs/plugin-react": "^4.0.0",
26-
"@vitejs/plugin-react-swc": "^3.3.1",
21+
"@types/react": "^18.2.14",
22+
"@types/react-dom": "^18.2.6",
23+
"@typescript-eslint/eslint-plugin": "^5.60.0",
24+
"@typescript-eslint/parser": "^5.60.0",
25+
"@vitejs/plugin-react": "^4.0.1",
26+
"@vitejs/plugin-react-swc": "^3.3.2",
2727
"autoprefixer": "^10.4.14",
28-
"concurrently": "^8.0.1",
28+
"concurrently": "^8.2.0",
2929
"esbuild": "^0.17.19",
3030
"eslint-config-custom": "workspace:*",
3131
"eslint-plugin-react-hooks": "^4.6.0",
3232
"eslint-plugin-react-refresh": "^0.4.1",
33-
"postcss": "^8.4.23",
33+
"postcss": "^8.4.24",
3434
"tailwindcss": "3.3.2",
3535
"tsconfig": "workspace:*",
36-
"typescript": "^5.0.4",
37-
"vite": "^4.3.7",
36+
"typescript": "^5.1.3",
37+
"vite": "^4.3.9",
3838
"vite-plugin-singlefile": "^0.13.5"
3939
}
4040
}

manifest.json

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,19 @@
11
{
2-
"name": "Figma to Code [Dev]",
3-
"id": "1248037579235937673",
2+
"name": "Figma to Code [HTML, Tailwind, Flutter, SwiftUI]",
3+
"id": "842128343887142055",
44
"api": "1.0.0",
55
"main": "apps/plugin/dist/code.js",
66
"ui": "apps/plugin/dist/index.html",
77
"editorType": ["figma", "dev"],
88
"capabilities": ["inspect", "codegen"],
99
"permissions": [],
10+
1011
"codegenLanguages": [
1112
{ "label": "HTML", "value": "html" },
1213
{ "label": "React (JSX)", "value": "html_jsx" },
1314
{ "label": "Tailwind", "value": "tailwind" },
1415
{ "label": "Tailwind (JSX)", "value": "tailwind_jsx" },
1516
{ "label": "Flutter", "value": "flutter" },
1617
{ "label": "SwiftUI", "value": "swiftUI" }
17-
],
18-
"codegenPreferences": [
19-
{
20-
"itemType": "alternative-unit",
21-
"scaledUnit": "Pixels",
22-
"defaultScaleFactor": 16,
23-
"default": true,
24-
"includedLanguages": ["tailwind"]
25-
},
26-
27-
{
28-
"itemType": "select",
29-
"propertyName": "tabSize",
30-
"label": "Tab Size",
31-
"options": [
32-
{ "label": "2", "value": "2", "isDefault": true },
33-
{ "label": "4", "value": "4" }
34-
],
35-
"includedLanguages": ["tailwind"]
36-
}
3718
]
3819
}

manifest_original.json

Lines changed: 0 additions & 38 deletions
This file was deleted.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
"format": "prettier --write \"**/*.{ts,tsx,md}\""
99
},
1010
"devDependencies": {
11-
"eslint": "^8.42.0",
11+
"eslint": "^8.43.0",
1212
"eslint-config-custom": "workspace:*",
1313
"prettier": "^2.8.8",
14-
"turbo": "^1.10.3"
14+
"turbo": "^1.10.6"
1515
},
1616
"packageManager": "[email protected]"
1717
}

packages/backend/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
"react-dom": "18.2.0"
2020
},
2121
"devDependencies": {
22-
"@types/react": "^18.2.9",
23-
"@types/react-dom": "^18.2.4",
24-
"eslint": "^8.42.0",
22+
"@types/react": "^18.2.14",
23+
"@types/react-dom": "^18.2.6",
24+
"eslint": "^8.43.0",
2525
"eslint-config-custom": "workspace:*",
2626
"tsconfig": "workspace:*",
2727
"tsup": "^6.7.0",

packages/backend/src/altNodes/altConversion.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ export const cloneNode = <T extends BaseNode>(node: T): T => {
1818
prop !== "masterComponent" &&
1919
prop !== "variantProperties" &&
2020
prop !== "componentPropertyDefinitions" &&
21-
prop !== "exposedInstances"
21+
prop !== "exposedInstances" &&
22+
prop !== "componentProperties" &&
23+
prop !== "componenPropertyReferences"
2224
) {
2325
cloned[prop as keyof T] = node[prop as keyof T];
2426
}

packages/backend/src/common/commonChildrenOrder.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,5 @@ export const commonSortChildrenWhenInferredAutoLayout = (
2626
return children.sort((a, b) => a.y - b.y);
2727
}
2828
}
29-
console.log("no inferredAutoLayout for ", node.name);
3029
return node.children;
3130
};

packages/backend/src/flutter/builderImpl/flutterSize.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,21 @@ export const flutterSize = (
1515
const size = nodeSize(node, optimizeLayout);
1616
let isExpanded: boolean = false;
1717

18+
const nodeParent =
19+
(node.parent && optimizeLayout && "inferredAutoLayout" in node.parent
20+
? node.parent.inferredAutoLayout
21+
: null) ?? node.parent;
22+
1823
// this cast will always be true, since nodeWidthHeight was called with false to relative.
1924
let propWidth = "";
2025
if (typeof size.width === "number") {
2126
propWidth = sliceNum(size.width);
2227
} else if (size.width === "fill") {
2328
// When parent is a Row, child must be Expanded.
2429
if (
25-
node.parent &&
26-
"layoutMode" in node.parent &&
27-
node.parent.layoutMode === "HORIZONTAL"
30+
nodeParent &&
31+
"layoutMode" in nodeParent &&
32+
nodeParent.layoutMode === "HORIZONTAL"
2833
) {
2934
isExpanded = true;
3035
} else {
@@ -38,9 +43,9 @@ export const flutterSize = (
3843
} else if (size.height === "fill") {
3944
// When parent is a Column, child must be Expanded.
4045
if (
41-
node.parent &&
42-
"layoutMode" in node.parent &&
43-
node.parent.layoutMode === "VERTICAL"
46+
nodeParent &&
47+
"layoutMode" in nodeParent &&
48+
nodeParent.layoutMode === "VERTICAL"
4449
) {
4550
isExpanded = true;
4651
} else {

0 commit comments

Comments
 (0)