Skip to content

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

Apply instance symbolOverrides on clipboard paste

Danila Poyarkov157c776c0c73
diff --git a/packages/core/src/clipboard.ts b/packages/core/src/clipboard.ts
index 62ac23096..3d609ed54 100644
--- a/packages/core/src/clipboard.ts
+++ b/packages/core/src/clipboard.ts
@@ -8,7 +8,7 @@ import {
} from './kiwi-serialize'
import { initCodec, getCompiledSchema, getSchemaBytes } from './kiwi/codec'
import { decodeBinarySchema, compileSchema, ByteBuffer } from './kiwi/kiwi-schema'
-import { nodeChangeToProps } from './kiwi/kiwi-convert'
+import { nodeChangeToProps, convertFills } from './kiwi/kiwi-convert'
import type { NodeChange as KiwiNodeChange } from './kiwi/codec'
import type { SceneGraph, SceneNode } from './scene-graph'
@@ -226,7 +226,15 @@ export function importClipboardNodes(
createNode(id, targetParentId)
}
- for (const [, ourId] of created) {
+ const overrideKeyToFigmaId = new Map<string, string>()
+ for (const [id, nc] of guidMap) {
+ const ok = (nc as unknown as Record<string, unknown>).overrideKey as
+ | { sessionID: number; localID: number }
+ | undefined
+ if (ok) overrideKeyToFigmaId.set(`${ok.sessionID}:${ok.localID}`, id)
+ }
+
+ for (const [figmaId, ourId] of created) {
const node = graph.getNode(ourId)
if (!node || node.type !== 'INSTANCE' || node.childIds.length > 0) continue
@@ -238,6 +246,41 @@ export function importClipboardNodes(
graph.updateNode(ourId, { componentId: ourComponentId })
graph.populateInstanceChildren(ourId, ourComponentId)
+
+ const nc = guidMap.get(figmaId)
+ const sd = (nc as unknown as Record<string, unknown>).symbolData as
+ | { symbolOverrides?: Array<Record<string, unknown>> }
+ | undefined
+ if (!sd?.symbolOverrides?.length) continue
+
+ const compChildIdMap = new Map<string, string>()
+ for (const childId of node.childIds) {
+ const child = graph.getNode(childId)
+ if (child?.componentId) compChildIdMap.set(child.componentId, childId)
+ }
+
+ for (const ov of sd.symbolOverrides) {
+ const gp = ov.guidPath as { guids?: Array<{ sessionID: number; localID: number }> } | undefined
+ if (!gp?.guids?.length) continue
+ const targetKey = `${gp.guids[0].sessionID}:${gp.guids[0].localID}`
+
+ const figmaChildId = overrideKeyToFigmaId.get(targetKey)
+ if (!figmaChildId) continue
+
+ const compChildOurId = created.get(figmaChildId)
+ if (!compChildOurId) continue
+
+ const instanceChildId = compChildIdMap.get(compChildOurId)
+ if (!instanceChildId) continue
+
+ const updates: Partial<SceneNode> = {}
+ const ovTd = ov.textData as { characters?: string } | undefined
+ if (ovTd?.characters != null) updates.text = ovTd.characters
+ if (ov.fillPaints) updates.fills = convertFills(ov.fillPaints as KiwiNodeChange['fillPaints'])
+ if (ov.visible != null) updates.visible = ov.visible as boolean
+
+ if (Object.keys(updates).length > 0) graph.updateNode(instanceChildId, updates)
+ }
}
for (const figmaId of internalTopLevel) {
diff --git a/tests/engine/clipboard.test.ts b/tests/engine/clipboard.test.ts
index 0d13bfac4..adade4092 100644
--- a/tests/engine/clipboard.test.ts
+++ b/tests/engine/clipboard.test.ts
@@ -321,6 +321,31 @@ describe('importClipboardNodes', () => {
}
})
+ it('applies symbolOverrides text to instance children via overrideKey', () => {
+ 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 1' },
+ { guid: { sessionID: 99, localID: 2 }, parentIndex: { guid: { sessionID: 0, localID: 0 }, position: '"' }, type: 'CANVAS', name: 'Internal Only Canvas', internalOnly: true },
+ // Component on internal canvas
+ { guid: { sessionID: 1, localID: 10 }, parentIndex: { guid: { sessionID: 99, localID: 2 }, position: '!' }, type: 'SYMBOL', name: 'Day', size: { x: 46, y: 46 }, 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: 'TEXT', name: 'Number', size: { x: 14, y: 17 }, transform: { m00: 1, m01: 0, m02: 0, m10: 0, m11: 1, m12: 0 }, textData: { characters: '1' }, overrideKey: { sessionID: 50, localID: 100 } },
+ // Instance on visible page with text override
+ { guid: { sessionID: 2, localID: 20 }, parentIndex: { guid: { sessionID: 0, localID: 1 }, position: '!' }, type: 'INSTANCE', name: 'Day', size: { x: 46, y: 46 }, transform: { m00: 1, m01: 0, m02: 0, m10: 0, m11: 1, m12: 0 },
+ symbolData: { symbolID: { sessionID: 1, localID: 10 }, symbolOverrides: [{ guidPath: { guids: [{ sessionID: 50, localID: 100 }] }, textData: { characters: '25' } }] } },
+ ] as any[]
+
+ const created = importClipboardNodes(nodeChanges, graph, pageId)
+ expect(created).toHaveLength(1)
+
+ const instance = graph.getNode(created[0])!
+ expect(instance.type).toBe('INSTANCE')
+ const children = graph.getChildren(instance.id)
+ expect(children).toHaveLength(1)
+ expect(children[0].text).toBe('25')
+ })
+
it('imports textAutoResize from clipboard data', () => {
const { graph, pageId } = createGraphWithPage()