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/createItems.ts
Jordi Sala Morales 8697902e08
Add loaders when the file is being built so we can track the progress (#172)
* Add loaders when the file is being built so we can track the progress

* add changelog

* improve

* refactor
2024-06-18 09:50:38 +02:00

49 lines
1.1 KiB
TypeScript

import { sendMessage } from '@ui/context';
import { PenpotFile } from '@ui/lib/types/penpotFile';
import { PenpotNode } from '@ui/types';
import {
createArtboard,
createBool,
createCircle,
createComponent,
createComponentInstance,
createGroup,
createPath,
createRectangle,
createText
} from '.';
export const createItems = (file: PenpotFile, nodes: PenpotNode[]) => {
for (const node of nodes) {
createItem(file, node);
}
};
const createItem = (file: PenpotFile, node: PenpotNode) => {
sendMessage({
type: 'PROGRESS_CURRENT_ITEM',
data: node.name
});
switch (node.type) {
case 'rect':
return createRectangle(file, node);
case 'circle':
return createCircle(file, node);
case 'frame':
return createArtboard(file, node);
case 'group':
return createGroup(file, node);
case 'path':
return createPath(file, node);
case 'text':
return createText(file, node);
case 'bool':
return createBool(file, node);
case 'component':
return createComponent(file, node);
case 'instance':
return createComponentInstance(file, node);
}
};