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