0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2024-12-22 05:33:02 -05:00

Filter missing component set (#131)

* filtering missing component sets

* fixes

* fixes

* fixes
This commit is contained in:
Alex Sánchez 2024-06-03 13:27:30 +02:00 committed by GitHub
parent 3f9189c7c1
commit 90d6dfd95a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -20,21 +20,14 @@ export const transformInstanceNode = async (
): Promise<ComponentInstance | undefined> => {
const mainComponent = await node.getMainComponentAsync();
/**
* We do not want to process component instances in the following scenarios:
*
* 1. If the component does not have a main component.
* 2. If the component comes from an external design system.
* 3. If th component does not have a parent. (it's been removed)
*/
if (!mainComponent || mainComponent.remote || mainComponent.parent === null) {
if (!isNodeProcessable(node, mainComponent)) {
return;
}
return {
type: 'instance',
name: node.name,
mainComponentFigmaId: mainComponent.id,
mainComponentFigmaId: mainComponent?.id ?? '',
isComponentRoot: isComponentRoot(node),
...transformFigmaIds(node),
...(await transformFills(node)),
@ -49,6 +42,24 @@ export const transformInstanceNode = async (
};
};
const isNodeProcessable = (node: SceneNode, mainComponent: ComponentNode | null): boolean => {
/**
* We do not want to process component instances in the following scenarios:
*
* 1. If the component does not have a main component.
* 2. If the component comes from an external design system.
* 3. If th component does not have a parent. (it's been removed)
* 4. Main component can be in a ComponentSet removed from the page or external design system.
*/
return !(
!mainComponent ||
mainComponent.remote ||
mainComponent.parent === null ||
(mainComponent.parent?.type === 'COMPONENT_SET' &&
(mainComponent.parent.parent === null || mainComponent.parent.remote))
);
};
const isComponentRoot = (node: InstanceNode): boolean => {
let parent = node.parent;
while (parent !== null) {