mirror of
https://github.com/penpot/penpot.git
synced 2026-02-12 14:42:56 +00:00
✨ 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:
@@ -25,7 +25,6 @@ export class PenpotUtils {
|
||||
id: shape.id,
|
||||
name: shape.name,
|
||||
type: shape.type,
|
||||
children: children,
|
||||
};
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user