mirror of
https://github.com/penpot/penpot-exporter-figma-plugin.git
synced 2024-12-22 13:43:03 -05:00
Filter missing component set (#131)
* filtering missing component sets * fixes * fixes * fixes
This commit is contained in:
parent
3f9189c7c1
commit
90d6dfd95a
1 changed files with 20 additions and 9 deletions
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue