Skip to content

AI-native design editor. Open-source Figma alternative.

Merge master into fix/create-component-drops-bound-variables

Danila Poyarkov8a976c1a0fe5
diff --cc tests/engine/figma/api/create/component-from-node.test.ts
index cf3954ed9,574b616fa..31125cb57
--- a/tests/engine/figma/api/create/component-from-node.test.ts
+++ b/tests/engine/figma/api/create/component-from-node.test.ts
@@@ -23,20 -25,40 +25,61 @@@ describe('createComponentFromNode', ()
expect(api.getNodeById(frameId)).toBeNull()
})
- test('preserves the frame own variable bindings', () => {
++ test('preserves root variable bindings and explicit modes', () => {
+ 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)
++ api.graph.updateNode(frame.id, {
++ variableModes: { [collection.id]: collection.defaultModeId }
++ })
+
+ const comp = api.createComponentFromNode(frame)
-
+ const raw = api.graph.getNode(comp.id)
++
+ expect(raw?.boundVariables.cornerRadius).toBe(variable.id)
++ expect(raw?.variableModes).toEqual({ [collection.id]: collection.defaultModeId })
++ })
++
+ test('preserves auto-layout HUG sizing when padding changes after conversion', () => {
+ const api = createAPI()
+ const frame = api.createFrame()
+ frame.layoutMode = 'HORIZONTAL'
+ frame.primaryAxisSizingMode = 'AUTO'
+ frame.counterAxisSizingMode = 'AUTO'
+ const child = api.createRectangle()
+ child.resize(40, 20)
+ frame.appendChild(child)
+ computeAllLayouts(api.graph, frame.id)
+
+ const comp = api.createComponentFromNode(frame)
+ const initialWidth = comp.width
+ const initialHeight = comp.height
+ comp.paddingLeft = 20
+ comp.paddingRight = 20
+ comp.paddingTop = 10
+ comp.paddingBottom = 10
+ computeAllLayouts(api.graph, comp.id)
+
+ expect(comp.width).toBe(initialWidth + 40)
+ expect(comp.height).toBe(initialHeight + 20)
+ })
+ test('preserves auto-layout HUG sizing mode', () => {
+ const api = createAPI()
+ const frame = api.createFrame()
+ frame.layoutMode = 'HORIZONTAL'
+ frame.primaryAxisSizingMode = 'AUTO'
+ frame.counterAxisSizingMode = 'AUTO'
+
+ const comp = api.createComponentFromNode(frame)
+ const raw = api.graph.getNode(comp.id)
+
+ expect(raw?.primaryAxisSizing).toBe('HUG')
+ expect(raw?.counterAxisSizing).toBe('HUG')
})
})