AI-native design editor. Open-source Figma alternative.
fix(scene-graph): tighten component property helpers
Danila Poyarkov61e0e5fbe4aa
diff --git a/packages/scene-graph/src/component-properties.ts b/packages/scene-graph/src/component-properties.tsindex e64f825d2..233ab9b73 100644--- a/packages/scene-graph/src/component-properties.ts+++ b/packages/scene-graph/src/component-properties.ts@@ -39,13 +39,15 @@ export function resolveComponentPropertyValue(graph: SceneGraph, value: string):const componentId = direct.childIds.find((id) => graph.getNode(id)?.type === 'COMPONENT')return componentId ? (graph.getNode(componentId) ?? null) : null}- return (- [...graph.getAllNodes()].find(- (node) =>- node.type === 'COMPONENT' &&- (node.componentKey === value || node.sourceLibraryKey === value || node.source.id === value)- ) ?? null- )+ for (const node of graph.getAllNodes()) {+ if (+ node.type === 'COMPONENT' &&+ (node.componentKey === value || node.sourceLibraryKey === value || node.source.id === value)+ ) {+ return node+ }+ }+ return null}export function findComponentPropertyTarget(diff --git a/packages/scene-graph/src/index.ts b/packages/scene-graph/src/index.tsindex f9af9a0b0..391a0bc9c 100644--- a/packages/scene-graph/src/index.ts+++ b/packages/scene-graph/src/index.ts@@ -1,4 +1,5 @@/* eslint-disable max-lines -- SceneGraph exposes a stable facade over domain modules */+export * from './images'export * from './component-properties'export * from './copy'export { copyInstanceComponentProps } from './instances'diff --git a/tests/engine/scene-graph/component-properties.test.ts b/tests/engine/scene-graph/component-properties.test.tsindex 213db3027..28ab00ff3 100644--- a/tests/engine/scene-graph/component-properties.test.ts+++ b/tests/engine/scene-graph/component-properties.test.ts@@ -50,11 +50,14 @@ describe('component properties', () => {const icon = component(graph, 'Icon', page.id)const keyed = component(graph, 'Keyed', page.id)graph.updateNode(keyed.id, { componentKey: 'icon-key' })+ const library = component(graph, 'Library', page.id)+ graph.updateNode(library.id, { sourceLibraryKey: 'library-key' })const set = graph.createNode('COMPONENT_SET', page.id)graph.reparentNode(icon.id, set.id)expect(resolveComponentPropertyValue(graph, keyed.id)?.id).toBe(keyed.id)expect(resolveComponentPropertyValue(graph, 'icon-key')?.id).toBe(keyed.id)+ expect(resolveComponentPropertyValue(graph, 'library-key')?.id).toBe(library.id)expect(resolveComponentPropertyValue(graph, set.id)?.id).toBe(icon.id)})