From c64e3a9d42541f8917a31d442febc910c793db0f Mon Sep 17 00:00:00 2001 From: Danila Poyarkov Date: Sun, 30 Aug 2026 22:28:49 +0300 Subject: [PATCH] fix(scene-graph): satisfy component property lint --- .../scene-graph/src/components/properties.ts | 79 ++++++++++++------- 1 file changed, 52 insertions(+), 27 deletions(-) diff --git a/packages/scene-graph/src/components/properties.ts b/packages/scene-graph/src/components/properties.ts index e56238ad8..0e0b67736 100644 --- a/packages/scene-graph/src/components/properties.ts +++ b/packages/scene-graph/src/components/properties.ts @@ -84,6 +84,54 @@ export function findComponentPropertyTargets( return targets } +function applyTextProperty( + graph: SceneGraph, + targets: ComponentPropertyTarget[], + value: string, + overrides: Record +): void { + for (const item of targets) { + if (item.field !== 'TEXT' || item.node.type !== 'TEXT') continue + graph.updateNode(item.node.id, { text: value }) + overrides[`${item.node.id}:text`] = value + } +} + +function applyBooleanProperty( + graph: SceneGraph, + targets: ComponentPropertyTarget[], + value: string, + overrides: Record +): void { + for (const item of targets) { + if (item.field !== 'VISIBLE') continue + graph.updateNode(item.node.id, { visible: value === 'true' }) + overrides[`${item.node.id}:visible`] = value === 'true' + } +} + +function applyInstanceSwapProperty( + graph: SceneGraph, + targets: ComponentPropertyTarget[], + target: SceneNode, + overrides: Record +): void { + for (const item of targets) { + if (item.field !== 'INSTANCE_SWAP' || item.node.type !== 'INSTANCE') continue + graph.swapInstanceComponent(item.node.id, target.id) + graph.updateNode(item.node.id, { + name: target.name, + overrides: { + ...item.node.overrides, + [`${item.node.id}:name`]: target.name + } + }) + overrides[`${item.node.id}:componentId`] = target.id + overrides[`${item.node.id}:sourceComponentId`] = item.source.id + overrides[`${item.node.id}:name`] = target.name + } +} + export function applyComponentPropertyValue( graph: SceneGraph, instanceId: string, @@ -98,34 +146,11 @@ export function applyComponentPropertyValue( if (definition.type === 'INSTANCE_SWAP' && !target) return null const overrides = { ...instance.overrides } if (definition.type === 'TEXT') { - for (const item of targets) { - if (item.field === 'TEXT' && item.node.type === 'TEXT') { - graph.updateNode(item.node.id, { text: value }) - overrides[`${item.node.id}:text`] = value - } - } + applyTextProperty(graph, targets, value, overrides) } else if (definition.type === 'BOOLEAN') { - for (const item of targets) { - if (item.field === 'VISIBLE') { - graph.updateNode(item.node.id, { visible: value === 'true' }) - overrides[`${item.node.id}:visible`] = value === 'true' - } - } - } else if (definition.type === 'INSTANCE_SWAP' && target) { - for (const item of targets) { - if (item.field !== 'INSTANCE_SWAP' || item.node.type !== 'INSTANCE') continue - graph.swapInstanceComponent(item.node.id, target.id) - graph.updateNode(item.node.id, { - name: target.name, - overrides: { - ...item.node.overrides, - [`${item.node.id}:name`]: target.name - } - }) - overrides[`${item.node.id}:componentId`] = target.id - overrides[`${item.node.id}:sourceComponentId`] = item.source.id - overrides[`${item.node.id}:name`] = target.name - } + applyBooleanProperty(graph, targets, value, overrides) + } else if (target) { + applyInstanceSwapProperty(graph, targets, target, overrides) } graph.updateNode(instance.id, { componentPropertyAssignments: {