From 0fce54a14e596489098d448f98de532ae468dd48 Mon Sep 17 00:00:00 2001 From: Jaya Krishna Namburu Date: Wed, 17 Jul 2024 21:46:18 +0530 Subject: [PATCH] (feat): Parse element nodes in attrs for elements (#912) --- .../src/resolvers/abilities/utils.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/teleport-uidl-resolver/src/resolvers/abilities/utils.ts b/packages/teleport-uidl-resolver/src/resolvers/abilities/utils.ts index 9147bc527..b768bb088 100644 --- a/packages/teleport-uidl-resolver/src/resolvers/abilities/utils.ts +++ b/packages/teleport-uidl-resolver/src/resolvers/abilities/utils.ts @@ -12,11 +12,9 @@ export const insertLinks = ( linkInParent: boolean = false, parentNode?: UIDLElementNode ): UIDLElementNode => { - // TODO_NOW - const { abilities, children, elementType, semanticType } = node.content + const { abilities, children, elementType, semanticType, attrs = {} } = node.content const linkInNode = linkInParent || !!abilities?.link - // TODO: think of a way to reuse the traversal that modifies the tree node.content.children = children?.map((child) => { if (child.type === 'element') { return insertLinks(child, options, linkInNode, node) @@ -106,6 +104,14 @@ export const insertLinks = ( return child }) + for (const attrKey of Object.keys(attrs)) { + const attr = attrs[attrKey] + + if (attr.type === 'element') { + node.content.attrs[attrKey] = insertLinks(attr as UIDLElementNode, options, false, node) + } + } + if (abilities?.link) { if (linkInParent) { console.warn('parent node has a link capability, nesting links is illegal')