2024-05-29 10:33:29 -05:00
|
|
|
import { componentsLibrary } from '@plugin/ComponentLibrary';
|
2024-06-03 10:29:33 -05:00
|
|
|
import { imagesLibrary } from '@plugin/ImageLibrary';
|
2024-05-29 10:33:29 -05:00
|
|
|
|
|
|
|
import { PenpotDocument } from '@ui/types';
|
2024-04-12 09:52:36 -05:00
|
|
|
|
|
|
|
import { transformPageNode } from '.';
|
2024-04-12 06:55:42 -05:00
|
|
|
|
|
|
|
export const transformDocumentNode = async (node: DocumentNode): Promise<PenpotDocument> => {
|
2024-05-31 04:25:32 -05:00
|
|
|
const children = [];
|
|
|
|
let currentPage = 0;
|
|
|
|
|
|
|
|
figma.ui.postMessage({
|
|
|
|
type: 'PROGRESS_TOTAL_PAGES',
|
|
|
|
data: node.children.length
|
|
|
|
});
|
|
|
|
|
|
|
|
for (const page of node.children) {
|
|
|
|
figma.ui.postMessage({
|
|
|
|
type: 'PROGRESS_PROCESSED_PAGES',
|
|
|
|
data: currentPage++
|
|
|
|
});
|
|
|
|
|
|
|
|
await page.loadAsync();
|
|
|
|
|
|
|
|
children.push(await transformPageNode(page));
|
|
|
|
}
|
|
|
|
|
2024-04-12 06:55:42 -05:00
|
|
|
return {
|
|
|
|
name: node.name,
|
2024-05-31 04:25:32 -05:00
|
|
|
children,
|
2024-06-03 10:29:33 -05:00
|
|
|
components: componentsLibrary.all(),
|
|
|
|
images: imagesLibrary.all()
|
2024-04-12 06:55:42 -05:00
|
|
|
};
|
|
|
|
};
|