(node: SceneNode)
| 21 | } |
| 22 | |
| 23 | export function getDesignComponent(node: SceneNode): DesignComponent | null { |
| 24 | const componentProperties = getComponentProperties(node) |
| 25 | if (!componentProperties) { |
| 26 | return null |
| 27 | } |
| 28 | |
| 29 | const properties: Record<string, ComponentPropertyValue> = {} |
| 30 | |
| 31 | for (const [name, data] of Object.entries(componentProperties)) { |
| 32 | const key = name.split('#')[0] |
| 33 | if (data.type === 'INSTANCE_SWAP') { |
| 34 | const component = figma.getNodeById(data.value as string) |
| 35 | if (component?.type === 'COMPONENT') { |
| 36 | properties[key] = { |
| 37 | name: component.name, |
| 38 | type: 'INSTANCE', |
| 39 | properties: {}, |
| 40 | children: [], |
| 41 | visible: true |
| 42 | } |
| 43 | } |
| 44 | } else { |
| 45 | properties[key] = data.value as ComponentPropertyValue |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | const main = getMainComponentSummary(node) |
| 50 | |
| 51 | return { |
| 52 | name: node.name, |
| 53 | type: 'INSTANCE', |
| 54 | properties, |
| 55 | visible: node.visible, |
| 56 | mainComponent: main, |
| 57 | children: getChildren(node) ?? [] |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | function getComponentProperties(node: SceneNode): Record<string, ComponentPropertyData> | null { |
| 62 | if (!('componentProperties' in node)) { |
no test coverage detected