MCPcopy Create free account
hub / github.com/ecomfe/tempad-dev / getDesignComponent

Function getDesignComponent

packages/extension/utils/component.ts:23–59  ·  view source on GitHub ↗
(node: SceneNode)

Source from the content-addressed store, hash-verified

21}
22
23export 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
61function getComponentProperties(node: SceneNode): Record<string, ComponentPropertyData> | null {
62 if (!('componentProperties' in node)) {

Callers 3

component.test.tsFile · 0.90
getChildrenFunction · 0.85

Calls 3

getMainComponentSummaryFunction · 0.85
getChildrenFunction · 0.85
getComponentPropertiesFunction · 0.70

Tested by

no test coverage detected