diff --git a/plugin-src/transformers/partials/transformChildren.ts b/plugin-src/transformers/partials/transformChildren.ts index 20bb5e5..6013fea 100644 --- a/plugin-src/transformers/partials/transformChildren.ts +++ b/plugin-src/transformers/partials/transformChildren.ts @@ -6,13 +6,13 @@ const nodeActsAsMask = (node: SceneNode): boolean => { return 'isMask' in node && node.isMask; }; -export const transformChildren = async (node: ChildrenMixin): Promise => { +export const transformChildren = (node: ChildrenMixin): Children => { const maskIndex = node.children.findIndex(nodeActsAsMask); const containsMask = maskIndex !== -1; return { children: containsMask - ? await translateMaskChildren(node.children, maskIndex) - : await translateChildren(node.children) + ? translateMaskChildren(node.children, maskIndex) + : translateChildren(node.children) }; }; diff --git a/plugin-src/transformers/transformBooleanNode.ts b/plugin-src/transformers/transformBooleanNode.ts index c31481f..78401ae 100644 --- a/plugin-src/transformers/transformBooleanNode.ts +++ b/plugin-src/transformers/transformBooleanNode.ts @@ -22,7 +22,7 @@ export const transformBooleanNode = async (node: BooleanOperationNode): Promise< name: node.name, boolType: translateBoolType(node.booleanOperation), ...transformFigmaIds(node), - ...(await transformChildren(node)), + ...transformChildren(node), ...transformFills(node), ...transformEffects(node), ...transformStrokes(node), diff --git a/plugin-src/transformers/transformComponentNode.ts b/plugin-src/transformers/transformComponentNode.ts index 311d872..671dcfa 100644 --- a/plugin-src/transformers/transformComponentNode.ts +++ b/plugin-src/transformers/transformComponentNode.ts @@ -18,7 +18,7 @@ import { import { ComponentRoot } from '@ui/types'; -export const transformComponentNode = async (node: ComponentNode): Promise => { +export const transformComponentNode = (node: ComponentNode): ComponentRoot => { componentsLibrary.register(node.id, { type: 'component', name: node.name, @@ -33,7 +33,7 @@ export const transformComponentNode = async (node: ComponentNode): Promise 0) { children.push({ name: 'External Components', - children: await translateRemoteChildren() + children: translateRemoteChildren() }); } diff --git a/plugin-src/transformers/transformFrameNode.ts b/plugin-src/transformers/transformFrameNode.ts index 870a7d3..d6d9a48 100644 --- a/plugin-src/transformers/transformFrameNode.ts +++ b/plugin-src/transformers/transformFrameNode.ts @@ -23,9 +23,9 @@ const isSectionNode = (node: FrameNode | SectionNode | ComponentSetNode): node i return node.type === 'SECTION'; }; -export const transformFrameNode = async ( +export const transformFrameNode = ( node: FrameNode | SectionNode | ComponentSetNode -): Promise => { +): FrameShape => { let frameSpecificAttributes: Partial = {}; let referencePoint: Point = { x: node.absoluteTransform[0][2], y: node.absoluteTransform[1][2] }; @@ -60,7 +60,7 @@ export const transformFrameNode = async ( ...referencePoint, ...frameSpecificAttributes, ...transformDimension(node), - ...(await transformChildren(node)), + ...transformChildren(node), ...transformSceneNode(node), ...transformOverrides(node) }; diff --git a/plugin-src/transformers/transformGroupNode.ts b/plugin-src/transformers/transformGroupNode.ts index 471c718..10be8a8 100644 --- a/plugin-src/transformers/transformGroupNode.ts +++ b/plugin-src/transformers/transformGroupNode.ts @@ -11,20 +11,20 @@ import { transformChildren } from '@plugin/transformers/partials'; import { GroupShape } from '@ui/lib/types/shapes/groupShape'; -export const transformGroupNode = async (node: GroupNode): Promise => { +export const transformGroupNode = (node: GroupNode): GroupShape => { return { ...transformFigmaIds(node), ...transformGroupNodeLike(node), ...transformEffects(node), ...transformBlend(node), - ...(await transformChildren(node)), + ...transformChildren(node), ...transformOverrides(node) }; }; export const transformGroupNodeLike = ( node: BaseNodeMixin & LayoutMixin & SceneNodeMixin -): GroupShape => { +): Omit => { return { type: 'group', name: node.name, diff --git a/plugin-src/transformers/transformInstanceNode.ts b/plugin-src/transformers/transformInstanceNode.ts index 2843d5c..53927aa 100644 --- a/plugin-src/transformers/transformInstanceNode.ts +++ b/plugin-src/transformers/transformInstanceNode.ts @@ -64,7 +64,7 @@ export const transformInstanceNode = async ( ...transformRotationAndPosition(node), ...transformConstraints(node), ...transformAutoLayout(node), - ...(await transformChildren(node)), + ...transformChildren(node), ...transformOverrides(node) }; }; diff --git a/plugin-src/transformers/transformPageNode.ts b/plugin-src/transformers/transformPageNode.ts index 3f658bc..af6c194 100644 --- a/plugin-src/transformers/transformPageNode.ts +++ b/plugin-src/transformers/transformPageNode.ts @@ -9,6 +9,6 @@ export const transformPageNode = async (node: PageNode): Promise => options: { background: node.backgrounds.length ? translatePageFill(node.backgrounds[0]) : undefined }, - children: await translateChildren(node.children) + children: translateChildren(node.children) }; }; diff --git a/plugin-src/transformers/transformSceneNode.ts b/plugin-src/transformers/transformSceneNode.ts index a4a7b90..9a712ca 100644 --- a/plugin-src/transformers/transformSceneNode.ts +++ b/plugin-src/transformers/transformSceneNode.ts @@ -54,7 +54,7 @@ export const transformSceneNode = async (node: SceneNode): Promise => { +): Promise[] => { const maskChild = children[maskIndex]; - const unmaskedChildren = await translateChildren(children.slice(0, maskIndex)); - const maskedChildren = await translateChildren(children.slice(maskIndex)); + const unmaskedChildren = translateChildren(children.slice(0, maskIndex)); + const maskedChildren = translateChildren(children.slice(maskIndex)); if ( maskChild.type === 'STICKY' || @@ -38,32 +38,30 @@ export const translateMaskChildren = async ( return [...unmaskedChildren, ...maskedChildren]; } - const maskGroup = { + const maskGroup = Promise.resolve({ ...transformMaskFigmaIds(maskChild), ...transformGroupNodeLike(maskChild), children: maskedChildren, maskedGroup: true - }; + }); return [...unmaskedChildren, maskGroup]; }; -export const translateChildren = async (children: readonly SceneNode[]): Promise => { - const transformedChildren: PenpotNode[] = []; +export const translateChildren = ( + children: readonly SceneNode[] +): Promise[] => { + const transformedChildren: Promise[] = []; for (const child of children) { - const penpotNode = await transformSceneNode(child); - - if (penpotNode) transformedChildren.push(penpotNode); - - await sleep(0); + transformedChildren.push(transformSceneNode(child)); } return transformedChildren; }; -export const translateRemoteChildren = async (): Promise => { - const transformedChildren: PenpotNode[] = []; +export const translateRemoteChildren = (): Promise[] => { + const transformedChildren: Promise[] = []; let currentRemote = 1; figma.ui.postMessage({ @@ -79,16 +77,12 @@ export const translateRemoteChildren = async (): Promise => { const child = remoteComponentLibrary.next(); - const penpotNode = await transformSceneNode(child); - - if (penpotNode) transformedChildren.push(penpotNode); + transformedChildren.push(transformSceneNode(child)); figma.ui.postMessage({ type: 'PROGRESS_PROCESSED_ITEMS', data: currentRemote++ }); - - await sleep(0); } return transformedChildren; diff --git a/ui-src/lib/types/utils/children.ts b/ui-src/lib/types/utils/children.ts index d39f696..abb0585 100644 --- a/ui-src/lib/types/utils/children.ts +++ b/ui-src/lib/types/utils/children.ts @@ -1,3 +1,3 @@ import { PenpotNode } from '@ui/types'; -export type Children = { children?: PenpotNode[] }; +export type Children = { children: Promise[] | (PenpotNode | undefined)[] };