AI-native design editor. Open-source Figma alternative.
fix(figma-api): preserve variable bindings when converting a node to a component
xemc814352ec90b5
diff --git a/packages/core/src/figma-api/index.ts b/packages/core/src/figma-api/index.tsindex ef1ef4dab..38017a6a7 100644--- a/packages/core/src/figma-api/index.ts+++ b/packages/core/src/figma-api/index.ts@@ -256,7 +256,9 @@ export class FigmaAPI implements NodeProxyHost {paddingBottom: raw.paddingBottom,paddingLeft: raw.paddingLeft,pluginData: structuredClone(raw.pluginData),- pluginRelaunchData: structuredClone(raw.pluginRelaunchData)+ pluginRelaunchData: structuredClone(raw.pluginRelaunchData),+ boundVariables: { ...raw.boundVariables },+ variableModes: { ...raw.variableModes }})for (const childId of raw.childIds) {this.graph.cloneTree(childId, comp.id)diff --git a/tests/engine/figma/api/create/component-from-node.test.ts b/tests/engine/figma/api/create/component-from-node.test.tsindex 6180763df..cf3954ed9 100644--- a/tests/engine/figma/api/create/component-from-node.test.ts+++ b/tests/engine/figma/api/create/component-from-node.test.ts@@ -22,4 +22,21 @@ describe('createComponentFromNode', () => {expect(comp.children[0].name).toBe('Background')expect(api.getNodeById(frameId)).toBeNull()})++ test('preserves the frame own variable bindings', () => {+ const api = createAPI()+ const collection = api.createVariableCollection('Radii')+ const variable = api.createVariable('radius/md', 'FLOAT', collection.id, 8)++ const frame = api.createFrame()+ frame.name = 'Card'+ frame.resize(200, 50)+ frame.cornerRadius = 8+ api.bindVariable(frame.id, 'cornerRadius', variable.id)++ const comp = api.createComponentFromNode(frame)++ const raw = api.graph.getNode(comp.id)+ expect(raw?.boundVariables.cornerRadius).toBe(variable.id)+ })})