-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add responsive design field ingestion and rules #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b277d7b
feat: ingest responsive design fields and implement stub rules (#39)
claude df5bca5
feat: add grid layout fields (12 properties) to schema and transformer
claude 88358bd
feat: add responsive field mappings for Plugin and MCP adapters
claude 543f384
fix: address CodeRabbit review findings on responsive design PR
claude 38ff8fc
fix: address 2nd round CodeRabbit review findings
claude 983b38b
fix: address 3rd round CodeRabbit review findings
claude cb4bd25
fix: address 4th round CodeRabbit review findings
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| import { transformFigmaResponse } from "./figma-transformer.js"; | ||
| import type { GetFileResponse } from "@figma/rest-api-spec"; | ||
|
|
||
| function makeFigmaNode(overrides: Record<string, unknown>) { | ||
| return { | ||
| id: "0:1", | ||
| name: "Test", | ||
| type: "FRAME", | ||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| function makeFigmaResponse(document: Record<string, unknown>): GetFileResponse { | ||
| return { | ||
| name: "TestFile", | ||
| lastModified: "2024-01-01", | ||
| version: "1", | ||
| document: document as GetFileResponse["document"], | ||
| components: {}, | ||
| styles: {}, | ||
| schemaVersion: 0, | ||
| role: "owner", | ||
| thumbnailUrl: "", | ||
| editorType: "figma", | ||
| } as GetFileResponse; | ||
| } | ||
|
|
||
| describe("figma-transformer responsive fields", () => { | ||
| it("maps minWidth/maxWidth/minHeight/maxHeight", () => { | ||
| const response = makeFigmaResponse( | ||
| makeFigmaNode({ | ||
| minWidth: 100, | ||
| maxWidth: 800, | ||
| minHeight: 50, | ||
| maxHeight: 600, | ||
| }), | ||
| ); | ||
| const result = transformFigmaResponse("test-key", response); | ||
| expect(result.document.minWidth).toBe(100); | ||
| expect(result.document.maxWidth).toBe(800); | ||
| expect(result.document.minHeight).toBe(50); | ||
| expect(result.document.maxHeight).toBe(600); | ||
| }); | ||
|
|
||
| it("maps layoutGrow", () => { | ||
| const response = makeFigmaResponse( | ||
| makeFigmaNode({ layoutGrow: 1 }), | ||
| ); | ||
| const result = transformFigmaResponse("test-key", response); | ||
| expect(result.document.layoutGrow).toBe(1); | ||
| }); | ||
|
|
||
| it("maps constraints", () => { | ||
| const response = makeFigmaResponse( | ||
| makeFigmaNode({ | ||
| constraints: { horizontal: "LEFT_RIGHT", vertical: "TOP_BOTTOM" }, | ||
| }), | ||
| ); | ||
| const result = transformFigmaResponse("test-key", response); | ||
| expect(result.document.constraints).toEqual({ | ||
| horizontal: "LEFT_RIGHT", | ||
| vertical: "TOP_BOTTOM", | ||
| }); | ||
| }); | ||
|
|
||
| it("maps layoutWrap and counterAxisSpacing", () => { | ||
| const response = makeFigmaResponse( | ||
| makeFigmaNode({ | ||
| layoutWrap: "WRAP", | ||
| counterAxisSpacing: 16, | ||
| counterAxisAlignContent: "SPACE_BETWEEN", | ||
| }), | ||
| ); | ||
| const result = transformFigmaResponse("test-key", response); | ||
| expect(result.document.layoutWrap).toBe("WRAP"); | ||
| expect(result.document.counterAxisSpacing).toBe(16); | ||
| expect(result.document.counterAxisAlignContent).toBe("SPACE_BETWEEN"); | ||
| }); | ||
|
|
||
| it("maps clipsContent and overflowDirection", () => { | ||
| const response = makeFigmaResponse( | ||
| makeFigmaNode({ | ||
| clipsContent: true, | ||
| overflowDirection: "VERTICAL_SCROLLING", | ||
| }), | ||
| ); | ||
| const result = transformFigmaResponse("test-key", response); | ||
| expect(result.document.clipsContent).toBe(true); | ||
| expect(result.document.overflowDirection).toBe("VERTICAL_SCROLLING"); | ||
| }); | ||
|
|
||
| it("maps layoutMode GRID", () => { | ||
| const response = makeFigmaResponse( | ||
| makeFigmaNode({ layoutMode: "GRID" }), | ||
| ); | ||
| const result = transformFigmaResponse("test-key", response); | ||
| expect(result.document.layoutMode).toBe("GRID"); | ||
| }); | ||
|
|
||
| it("maps grid container fields", () => { | ||
| const response = makeFigmaResponse( | ||
| makeFigmaNode({ | ||
| layoutMode: "GRID", | ||
| gridRowCount: 3, | ||
| gridColumnCount: 4, | ||
| gridRowGap: 8, | ||
| gridColumnGap: 16, | ||
| gridColumnsSizing: "1fr 1fr 1fr 1fr", | ||
| gridRowsSizing: "auto auto auto", | ||
| }), | ||
| ); | ||
| const result = transformFigmaResponse("test-key", response); | ||
| expect(result.document.gridRowCount).toBe(3); | ||
| expect(result.document.gridColumnCount).toBe(4); | ||
| expect(result.document.gridRowGap).toBe(8); | ||
| expect(result.document.gridColumnGap).toBe(16); | ||
| expect(result.document.gridColumnsSizing).toBe("1fr 1fr 1fr 1fr"); | ||
| expect(result.document.gridRowsSizing).toBe("auto auto auto"); | ||
| }); | ||
|
|
||
| it("maps grid child fields", () => { | ||
| const response = makeFigmaResponse( | ||
| makeFigmaNode({ | ||
| gridChildHorizontalAlign: "CENTER", | ||
| gridChildVerticalAlign: "MAX", | ||
| gridRowSpan: 2, | ||
| gridColumnSpan: 3, | ||
| gridRowAnchorIndex: 0, | ||
| gridColumnAnchorIndex: 1, | ||
| }), | ||
| ); | ||
| const result = transformFigmaResponse("test-key", response); | ||
| expect(result.document.gridChildHorizontalAlign).toBe("CENTER"); | ||
| expect(result.document.gridChildVerticalAlign).toBe("MAX"); | ||
| expect(result.document.gridRowSpan).toBe(2); | ||
| expect(result.document.gridColumnSpan).toBe(3); | ||
| expect(result.document.gridRowAnchorIndex).toBe(0); | ||
| expect(result.document.gridColumnAnchorIndex).toBe(1); | ||
| }); | ||
|
|
||
| it("does not set fields when absent", () => { | ||
| const response = makeFigmaResponse(makeFigmaNode({})); | ||
| const result = transformFigmaResponse("test-key", response); | ||
| expect(result.document.minWidth).toBeUndefined(); | ||
| expect(result.document.maxWidth).toBeUndefined(); | ||
| expect(result.document.layoutWrap).toBeUndefined(); | ||
| expect(result.document.clipsContent).toBeUndefined(); | ||
| expect(result.document.constraints).toBeUndefined(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: let-sunny/canicode
Length of output: 773
🏁 Script executed:
Repository: let-sunny/canicode
Length of output: 94
🏁 Script executed:
Repository: let-sunny/canicode
Length of output: 1749
🏁 Script executed:
Repository: let-sunny/canicode
Length of output: 387
🏁 Script executed:
# Read the complete figma-node.ts contract file cat -n src/core/contracts/figma-node.tsRepository: let-sunny/canicode
Length of output: 7612
🏁 Script executed:
Repository: let-sunny/canicode
Length of output: 89
🏁 Script executed:
Repository: let-sunny/canicode
Length of output: 2508
🏁 Script executed:
Repository: let-sunny/canicode
Length of output: 956
🏁 Script executed:
Repository: let-sunny/canicode
Length of output: 1942
🏁 Script executed:
# Check imports in main.ts head -30 app/figma-plugin/src/main.tsRepository: let-sunny/canicode
Length of output: 830
🏁 Script executed:
Repository: let-sunny/canicode
Length of output: 206
🏁 Script executed:
Repository: let-sunny/canicode
Length of output: 44
Import and reuse
AnalysisNodetype from the shared contract instead of redefining it locally.The local interface in lines 40–115 claims to "match
src/core/contracts/figma-node.ts" but actually widens multiple fields to barestringtypes:layoutWrap,counterAxisAlignContent,gridChildHorizontalAlign,gridChildVerticalAlign,overflowDirection, and theconstraintsobject. The shared schema constrains these to specific enums and unions (LayoutWrap,GridChildAlign,OverflowDirection,LayoutConstraint, etc.).This divergence means the plugin—which is the data producer—can emit values that violate the shared contract, defeating compile-time safety and creating maintenance burden. Remove this local interface and import the actual
AnalysisNodetype fromsrc/core/contracts/figma-node.tsto ensure type alignment with the Zod-validated schema.🤖 Prompt for AI Agents