mirror of
https://github.com/penpot/penpot-exporter-figma-plugin.git
synced 2024-12-23 06:04:01 -05:00
39 lines
855 B
TypeScript
39 lines
855 B
TypeScript
|
import { PenpotFile } from '@ui/lib/types/penpotFile';
|
||
|
import { ComponentShape } from '@ui/lib/types/shapes/componentShape';
|
||
|
import { components } from '@ui/parser/libraries';
|
||
|
|
||
|
import { createArtboard } from '.';
|
||
|
|
||
|
export const createComponent = (
|
||
|
file: PenpotFile,
|
||
|
{ type, path, children = [], ...rest }: ComponentShape
|
||
|
) => {
|
||
|
const frameId = file.newId();
|
||
|
const componentId = file.newId();
|
||
|
|
||
|
const commonStructure = {
|
||
|
...rest,
|
||
|
children,
|
||
|
componentFile: file.getId(),
|
||
|
componentId: componentId,
|
||
|
componentRoot: true,
|
||
|
mainInstance: true
|
||
|
};
|
||
|
|
||
|
createArtboard(file, {
|
||
|
...commonStructure,
|
||
|
id: frameId,
|
||
|
mainInstance: true,
|
||
|
type: 'frame'
|
||
|
});
|
||
|
|
||
|
components.add({
|
||
|
...commonStructure,
|
||
|
id: componentId,
|
||
|
mainInstanceId: frameId,
|
||
|
mainInstancePage: file.getCurrentPageId(),
|
||
|
path,
|
||
|
type
|
||
|
});
|
||
|
};
|