0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2025-03-09 06:11:26 -05:00
penpot-exporter-figma-plugin/ui-src/parser/creators/createComponent.ts
Jordi Sala Morales 738ebfeffe
Remove symbols when possible (#173)
* remove symbols for blend mode

* remove symbol for gradients

* optimize symbols for path contents

* optimize code

* remove symbols
2024-06-18 11:20:51 +02:00

42 lines
1 KiB
TypeScript

import { componentsLibrary } from '@plugin/ComponentLibrary';
import { PenpotFile } from '@ui/lib/types/penpotFile';
import { uiComponents } from '@ui/parser/libraries';
import { ComponentRoot } from '@ui/types';
import { createArtboard } from '.';
export const createComponent = (file: PenpotFile, { figmaId }: ComponentRoot) => {
const component = componentsLibrary.get(figmaId);
if (!component) {
return;
}
const componentId = getComponentId(file, figmaId);
const { type, ...shape } = component;
shape.componentFile = file.getId();
shape.componentId = componentId;
shape.componentRoot = true;
shape.mainInstance = true;
const frameId = createArtboard(file, shape);
if (!frameId) {
return;
}
uiComponents.register(figmaId, {
componentId,
mainInstancePage: file.getCurrentPageId(),
componentFigmaId: figmaId,
mainInstanceId: frameId
});
};
const getComponentId = (file: PenpotFile, figmaId: string) => {
const uiComponent = uiComponents.get(figmaId);
return uiComponent?.componentId ?? file.newId();
};