Improve shapeStructure

* Add information on component instance (component id, name; main instance id)
* Improve JSON result order (children should come last)
This commit is contained in:
Dominik Jain
2026-02-10 22:52:56 +01:00
parent b6dfdc23cd
commit f5afcde0de

View File

@@ -25,7 +25,6 @@ export class PenpotUtils {
id: shape.id, id: shape.id,
name: shape.name, name: shape.name,
type: shape.type, type: shape.type,
children: children,
}; };
// add layout information if present // add layout information if present
@@ -48,6 +47,23 @@ export class PenpotUtils {
}; };
} }
// add component instance information if present
if (shape.isComponentInstance()) {
result.componentInstance = {};
const component = shape.component();
if (component) {
result.componentInstance.componentId = component.id;
result.componentInstance.componentName = component.name;
const mainInstance = component.mainInstance();
if (mainInstance) {
result.componentInstance.mainInstanceId = mainInstance.id;
}
}
}
// finally, add children (last for more readable nesting order)
result.children = children;
return result; return result;
} }