fix(scene-graph): tighten component property helpers

This commit is contained in:
Danila Poyarkov 2026-08-30 21:31:31 +03:00
parent 7bda8cc17a
commit 61e0e5fbe4
3 changed files with 13 additions and 7 deletions

View file

@ -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(

View file

@ -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'

View file

@ -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)
})