0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2025-01-03 05:10:13 -05:00

Little refactor (#132)

This commit is contained in:
Jordi Sala Morales 2024-06-03 13:52:50 +02:00 committed by GitHub
parent 90d6dfd95a
commit a4113382bb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -20,14 +20,14 @@ export const transformInstanceNode = async (
): Promise<ComponentInstance | undefined> => {
const mainComponent = await node.getMainComponentAsync();
if (!isNodeProcessable(node, mainComponent)) {
if (mainComponent === null || isUnprocessableComponent(mainComponent)) {
return;
}
return {
type: 'instance',
name: node.name,
mainComponentFigmaId: mainComponent?.id ?? '',
mainComponentFigmaId: mainComponent.id,
isComponentRoot: isComponentRoot(node),
...transformFigmaIds(node),
...(await transformFills(node)),
@ -42,17 +42,15 @@ 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.
* 1. If the component comes from an external design system.
* 2. If the component does not have a parent. (it's been removed)
* 3. Main component can be in a ComponentSet (the same logic applies to the parent).
*/
return !(
!mainComponent ||
const isUnprocessableComponent = (mainComponent: ComponentNode): boolean => {
return (
mainComponent.remote ||
mainComponent.parent === null ||
(mainComponent.parent?.type === 'COMPONENT_SET' &&