2024-05-29 10:33:29 -05:00
|
|
|
import { componentsLibrary } from '@plugin/ComponentLibrary';
|
|
|
|
|
2024-05-29 05:52:21 -05:00
|
|
|
import { PenpotFile } from '@ui/lib/types/penpotFile';
|
2024-05-29 10:33:29 -05:00
|
|
|
import { uiComponents } from '@ui/parser/libraries';
|
|
|
|
import { ComponentRoot } from '@ui/types';
|
2024-05-29 05:52:21 -05:00
|
|
|
|
|
|
|
import { createArtboard } from '.';
|
|
|
|
|
2024-05-29 10:33:29 -05:00
|
|
|
export const createComponent = (file: PenpotFile, { figmaId }: ComponentRoot) => {
|
|
|
|
const component = componentsLibrary.get(figmaId);
|
|
|
|
if (!component) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-05-30 10:54:37 -05:00
|
|
|
const uiComponent = uiComponents.get(figmaId);
|
|
|
|
const componentId = uiComponent?.componentId ?? file.newId();
|
|
|
|
|
|
|
|
const frameId = createArtboard(file, {
|
2024-05-29 10:33:29 -05:00
|
|
|
...component,
|
2024-05-29 05:52:21 -05:00
|
|
|
componentFile: file.getId(),
|
2024-05-30 10:54:37 -05:00
|
|
|
componentId,
|
2024-05-29 05:52:21 -05:00
|
|
|
componentRoot: true,
|
|
|
|
mainInstance: true,
|
|
|
|
type: 'frame'
|
|
|
|
});
|
|
|
|
|
2024-05-30 10:54:37 -05:00
|
|
|
if (!frameId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-05-29 10:33:29 -05:00
|
|
|
uiComponents.register(figmaId, {
|
|
|
|
componentId,
|
2024-05-29 05:52:21 -05:00
|
|
|
mainInstancePage: file.getCurrentPageId(),
|
2024-05-29 10:33:29 -05:00
|
|
|
componentFigmaId: figmaId,
|
|
|
|
mainInstanceId: frameId
|
2024-05-29 05:52:21 -05:00
|
|
|
});
|
|
|
|
};
|