0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2024-12-22 21:53:27 -05:00
penpot-exporter-figma-plugin/ui-src/parser/creators/createComponentInstance.ts
Alex Sánchez 7b3192936e
Component Instances (#124)
* wip

* wip

* wipo

* more structure

* wip

* id library wip

* wip

* main instance working

* improvements

* fix node order

* refactor

* remove not used method

* refactor

* fix component set translation

* refactor

* add changelog

* penpot lib update

---------

Co-authored-by: Jordi Sala Morales <jordism91@gmail.com>
2024-05-30 17:54:37 +02:00

44 lines
1 KiB
TypeScript

import { PenpotFile } from '@ui/lib/types/penpotFile';
import { parseFigmaId } from '@ui/parser';
import { uiComponents } from '@ui/parser/libraries';
import { ComponentInstance } from '@ui/types';
import { createArtboard } from '.';
export const createComponentInstance = (
file: PenpotFile,
{
type,
mainComponentFigmaId,
figmaId,
figmaRelatedId,
isComponentRoot,
...rest
}: ComponentInstance
) => {
let uiComponent = uiComponents.get(mainComponentFigmaId);
if (!uiComponent) {
const mainInstanceId = parseFigmaId(file, mainComponentFigmaId);
if (!mainInstanceId) {
return;
}
uiComponent = {
componentId: file.newId(),
componentFigmaId: mainComponentFigmaId,
mainInstanceId
};
uiComponents.register(mainComponentFigmaId, uiComponent);
}
createArtboard(file, {
...rest,
showContent: true,
shapeRef: uiComponent.mainInstanceId,
componentFile: file.getId(),
componentRoot: isComponentRoot,
componentId: uiComponent.componentId,
type: 'frame'
});
};