0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2024-12-22 13:43:03 -05:00
penpot-exporter-figma-plugin/plugin-src/transformers/transformDocumentNode.ts
Jordi Sala Morales 7895daaea8
Improve UX for larger files, when the download also takes time to process (#136)
* Improve UX for larger files, when the download also takes time to process

* add changelog
2024-06-04 12:44:02 +02:00

37 lines
851 B
TypeScript

import { componentsLibrary } from '@plugin/ComponentLibrary';
import { imagesLibrary } from '@plugin/ImageLibrary';
import { sleep } from '@plugin/utils';
import { PenpotDocument } from '@ui/types';
import { transformPageNode } from '.';
export const transformDocumentNode = async (node: DocumentNode): Promise<PenpotDocument> => {
const children = [];
let currentPage = 1;
figma.ui.postMessage({
type: 'PROGRESS_TOTAL_PAGES',
data: node.children.length
});
for (const page of node.children) {
await page.loadAsync();
children.push(await transformPageNode(page));
figma.ui.postMessage({
type: 'PROGRESS_PROCESSED_PAGES',
data: currentPage++
});
await sleep(0);
}
return {
name: node.name,
children,
components: componentsLibrary.all(),
images: imagesLibrary.all()
};
};