Skip to content

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

Populate instance children from component on clipboard paste

Danila Poyarkov3d4f083d5e18
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 136f4b796..6e3fc0e85 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,9 @@
### Fixes
+- Fix Figma clipboard paste: extract shared kiwi→SceneNode conversion, fixing broken auto-layout, missing gradient/image fills, effects, style runs, and text properties
+- Fix vector rendering on paste — scale path coordinates from Figma's normalizedSize to actual node bounds
+- Fix pasted instances having no children — populate from component via symbolData when both are in clipboard
- Fix flip buttons using rotation math instead of actual mirroring
- Fix flip transform encoding — scale first matrix column only (was incorrectly producing 180° rotation)
- Decode flip state from .fig transform matrix on import
diff --git a/packages/core/src/clipboard.ts b/packages/core/src/clipboard.ts
index d5ff7f2ad..a53b2336a 100644
--- a/packages/core/src/clipboard.ts
+++ b/packages/core/src/clipboard.ts
@@ -202,6 +202,20 @@ export function importClipboardNodes(
createNode(id, targetParentId)
}
+ for (const [, ourId] of created) {
+ const node = graph.getNode(ourId)
+ if (!node || node.type !== 'INSTANCE' || node.childIds.length > 0) continue
+
+ const figmaComponentId = node.componentId
+ if (!figmaComponentId) continue
+
+ const ourComponentId = created.get(figmaComponentId)
+ if (!ourComponentId) continue
+
+ graph.updateNode(ourId, { componentId: ourComponentId })
+ graph.populateInstanceChildren(ourId, ourComponentId)
+ }
+
return createdIds
}
diff --git a/packages/core/src/kiwi/kiwi-convert.ts b/packages/core/src/kiwi/kiwi-convert.ts
index e53426ed4..a8024b2a9 100644
--- a/packages/core/src/kiwi/kiwi-convert.ts
+++ b/packages/core/src/kiwi/kiwi-convert.ts
@@ -503,6 +503,15 @@ export function nodeChangeToProps(
textTruncation: (ext(nc).textTruncation as string) === 'ENDING' ? 'ENDING' : 'DISABLED',
autoRename: (ext(nc).autoRename as boolean) ?? true,
boundVariables: extractBoundVariables(nc),
- clipsContent: nc.frameMaskDisabled === false
+ clipsContent: nc.frameMaskDisabled === false,
+ componentId: extractSymbolId(nc)
}
}
+
+function extractSymbolId(nc: NodeChange): string {
+ const sd = (nc as unknown as Record<string, unknown>).symbolData as
+ | { symbolID?: GUID }
+ | undefined
+ if (!sd?.symbolID) return ''
+ return guidToString(sd.symbolID)
+}
diff --git a/packages/core/src/scene-graph.ts b/packages/core/src/scene-graph.ts
index 186e7bf43..5923fe88c 100644
--- a/packages/core/src/scene-graph.ts
+++ b/packages/core/src/scene-graph.ts
@@ -922,6 +922,13 @@ export class SceneGraph {
return instance
}
+ populateInstanceChildren(instanceId: string, componentId: string): void {
+ const instance = this.nodes.get(instanceId)
+ const component = this.nodes.get(componentId)
+ if (!instance || !component || instance.type !== 'INSTANCE') return
+ this.cloneChildrenWithMapping(componentId, instanceId)
+ }
+
private cloneChildrenWithMapping(sourceParentId: string, destParentId: string): void {
const sourceParent = this.nodes.get(sourceParentId)
if (!sourceParent) return
diff --git a/tests/engine/clipboard.test.ts b/tests/engine/clipboard.test.ts
index ac38ed40e..e0c209792 100644
--- a/tests/engine/clipboard.test.ts
+++ b/tests/engine/clipboard.test.ts
@@ -257,6 +257,36 @@ describe('importClipboardNodes', () => {
expect(children[1].name).toBe('Divider')
})
+ it('populates instance children from pasted component', () => {
+ const { graph, pageId } = createGraphWithPage()
+
+ const nodeChanges = [
+ { guid: { sessionID: 0, localID: 0 }, type: 'DOCUMENT', name: 'Doc' },
+ { guid: { sessionID: 0, localID: 1 }, parentIndex: { guid: { sessionID: 0, localID: 0 }, position: '!' }, type: 'CANVAS', name: 'Page' },
+ // Component with a child
+ { guid: { sessionID: 1, localID: 10 }, parentIndex: { guid: { sessionID: 0, localID: 1 }, position: '!' }, type: 'SYMBOL', name: 'Icon/Warning', size: { x: 48, y: 48 }, transform: { m00: 1, m01: 0, m02: 0, m10: 0, m11: 1, m12: 0 } },
+ { guid: { sessionID: 1, localID: 11 }, parentIndex: { guid: { sessionID: 1, localID: 10 }, position: '!' }, type: 'VECTOR', name: 'Triangle', size: { x: 48, y: 42 }, transform: { m00: 1, m01: 0, m02: 0, m10: 0, m11: 1, m12: 3 } },
+ // Instance referencing the component
+ { guid: { sessionID: 2, localID: 20 }, parentIndex: { guid: { sessionID: 0, localID: 1 }, position: '"' }, type: 'INSTANCE', name: 'Icon/Warning', size: { x: 48, y: 48 }, transform: { m00: 1, m01: 0, m02: 100, m10: 0, m11: 1, m12: 0 }, symbolData: { symbolID: { sessionID: 1, localID: 10 } } },
+ ] as any[]
+
+ const created = importClipboardNodes(nodeChanges, graph, pageId)
+ expect(created).toHaveLength(2)
+
+ const component = graph.getNode(created[0])!
+ expect(component.type).toBe('COMPONENT')
+ expect(graph.getChildren(component.id)).toHaveLength(1)
+
+ const instance = graph.getNode(created[1])!
+ expect(instance.type).toBe('INSTANCE')
+ expect(instance.componentId).toBe(component.id)
+
+ const instanceChildren = graph.getChildren(instance.id)
+ expect(instanceChildren).toHaveLength(1)
+ expect(instanceChildren[0].name).toBe('Triangle')
+ expect(instanceChildren[0].type).toBe('VECTOR')
+ })
+
it('imports textAutoResize from clipboard data', () => {
const { graph, pageId } = createGraphWithPage()