diff --git a/plugin-src/transformers/partials/index.ts b/plugin-src/transformers/partials/index.ts index c38a8eb..ff265eb 100644 --- a/plugin-src/transformers/partials/index.ts +++ b/plugin-src/transformers/partials/index.ts @@ -1 +1,2 @@ +export * from './transformChildren'; export * from './transformDimensionAndPosition'; diff --git a/plugin-src/transformers/partials/transformChildren.ts b/plugin-src/transformers/partials/transformChildren.ts new file mode 100644 index 0000000..f646f02 --- /dev/null +++ b/plugin-src/transformers/partials/transformChildren.ts @@ -0,0 +1,13 @@ +import { Children } from '@ui/lib/types/utils/children'; + +import { transformSceneNode } from '../transformSceneNode'; + +export const transformChildren = async ( + node: ChildrenMixin, + baseX: number = 0, + baseY: number = 0 +): Promise => { + return { + children: await Promise.all(node.children.map(child => transformSceneNode(child, baseX, baseY))) + }; +}; diff --git a/plugin-src/transformers/transformFrameNode.ts b/plugin-src/transformers/transformFrameNode.ts index ec3d340..db541f2 100644 --- a/plugin-src/transformers/transformFrameNode.ts +++ b/plugin-src/transformers/transformFrameNode.ts @@ -1,10 +1,9 @@ import { transformDimensionAndPosition } from '@plugin/transformers/partials'; +import { transformChildren } from '@plugin/transformers/partials'; import { translateFills } from '@plugin/translators'; import { FrameShape } from '@ui/lib/types/frame/frameShape'; -import { transformSceneNode } from '.'; - export const transformFrameNode = async ( node: FrameNode, baseX: number, @@ -14,9 +13,7 @@ export const transformFrameNode = async ( type: 'frame', name: node.name, fills: translateFills(node.fills, node.width, node.height), - children: await Promise.all( - node.children.map(child => transformSceneNode(child, baseX + node.x, baseY + node.y)) - ), + ...(await transformChildren(node, baseX, baseY)), ...transformDimensionAndPosition(node, baseX, baseY) }; }; diff --git a/plugin-src/transformers/transformGroupNode.ts b/plugin-src/transformers/transformGroupNode.ts index 998c827..893225f 100644 --- a/plugin-src/transformers/transformGroupNode.ts +++ b/plugin-src/transformers/transformGroupNode.ts @@ -1,9 +1,8 @@ import { transformDimensionAndPosition } from '@plugin/transformers/partials'; +import { transformChildren } from '@plugin/transformers/partials'; import { GroupShape } from '@ui/lib/types/group/groupShape'; -import { transformSceneNode } from '.'; - export const transformGroupNode = async ( node: GroupNode, baseX: number, @@ -12,9 +11,7 @@ export const transformGroupNode = async ( return { type: 'group', name: node.name, - children: await Promise.all( - node.children.map(child => transformSceneNode(child, baseX, baseY)) - ), + ...(await transformChildren(node, baseX, baseY)), ...transformDimensionAndPosition(node, baseX, baseY) }; }; diff --git a/plugin-src/transformers/transformPageNode.ts b/plugin-src/transformers/transformPageNode.ts index b995c43..c1a7e6c 100644 --- a/plugin-src/transformers/transformPageNode.ts +++ b/plugin-src/transformers/transformPageNode.ts @@ -1,10 +1,10 @@ -import { PenpotPage } from '@ui/lib/types/penpotPage'; +import { transformChildren } from '@plugin/transformers/partials'; -import { transformSceneNode } from '.'; +import { PenpotPage } from '@ui/lib/types/penpotPage'; export const transformPageNode = async (node: PageNode): Promise => { return { name: node.name, - children: await Promise.all(node.children.map(child => transformSceneNode(child))) + ...(await transformChildren(node)) }; };