@builderx/bridge
Advanced tools
Comparing version 0.1.3 to 0.1.4
@@ -327,3 +327,6 @@ "use strict"; | ||
const fiber = getFiberNodeInOwner(child._owner, (_a = child.props) === null || _a === void 0 ? void 0 : _a['data-path'], child); | ||
const componentTree = buildReactFiberTree(fiber, withFiber); | ||
if (!fiber && !isValidElement(child)) { | ||
return null; | ||
} | ||
let componentTree = buildReactFiberTree(fiber, withFiber); | ||
const childElement = { | ||
@@ -337,11 +340,19 @@ displayName: getComponentName(child), | ||
}; | ||
// Only process children if they exist and we haven't processed this path before | ||
if ((_c = child.props) === null || _c === void 0 ? void 0 : _c.children) { | ||
childElement.children = prepareChildrenTree(child.props.children, withFiber //, | ||
// getComponentName(child) | ||
); | ||
if (Array.isArray(child.props.children)) { | ||
childElement.children = child.props.children | ||
.map((c) => processChild(c)) | ||
.filter(Boolean); | ||
} | ||
else { | ||
const processed = processChild(child.props.children); | ||
if (processed) { | ||
childElement.children = [processed]; | ||
} | ||
} | ||
} | ||
if (isComponent(fiber) && | ||
(childElement === null || childElement === void 0 ? void 0 : childElement.children) && | ||
(componentTree === null || componentTree === void 0 ? void 0 : componentTree.children)) { | ||
childElement.children = childElement === null || childElement === void 0 ? void 0 : childElement.children.filter((child) => !componentTree.children.some((treeChild) => treeChild.path === child.path)); | ||
// Filter out duplicate children that exist in component tree | ||
if (isComponent(fiber) && (childElement === null || childElement === void 0 ? void 0 : childElement.children) && (componentTree === null || componentTree === void 0 ? void 0 : componentTree.children)) { | ||
childElement.children = childElement.children.filter((child) => !componentTree.children.some((treeChild) => treeChild.path === child.path)); | ||
} | ||
@@ -348,0 +359,0 @@ return childElement; |
{ | ||
"name": "@builderx/bridge", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "types": "dist/index.d.ts", |
@@ -407,2 +407,4 @@ declare global { | ||
function processChild(child: any): any { | ||
const fiber = getFiberNodeInOwner( | ||
@@ -414,7 +416,12 @@ child._owner, | ||
const componentTree = buildReactFiberTree(fiber, withFiber); | ||
if (!fiber && !isValidElement(child)) { | ||
return null; | ||
} | ||
let componentTree = buildReactFiberTree(fiber, withFiber); | ||
const childElement: any = { | ||
displayName: getComponentName(child), | ||
path: child.props?.['data-path'] || null, | ||
fiber: withFiber? fiber : null, | ||
fiber: withFiber ? fiber : null, | ||
componentTree: componentTree, | ||
@@ -425,20 +432,23 @@ debugInfo: child?._debugInfo || null, | ||
if (child.props?.children) { | ||
childElement.children = prepareChildrenTree( | ||
child.props.children, | ||
withFiber //, | ||
// getComponentName(child) | ||
); | ||
// Only process children if they exist and we haven't processed this path before | ||
if (child.props?.children ) { | ||
if (Array.isArray(child.props.children)) { | ||
childElement.children = child.props.children | ||
.map((c: any) => processChild(c)) | ||
.filter(Boolean); | ||
} else { | ||
const processed = processChild(child.props.children); | ||
if (processed) { | ||
childElement.children = [processed]; | ||
} | ||
} | ||
} | ||
if ( | ||
isComponent(fiber) && | ||
childElement?.children && | ||
componentTree?.children | ||
) { | ||
childElement.children = childElement?.children.filter( | ||
(child: any) => | ||
!componentTree.children.some( | ||
(treeChild: any) => treeChild.path === child.path | ||
) | ||
// Filter out duplicate children that exist in component tree | ||
if (isComponent(fiber) && childElement?.children && componentTree?.children) { | ||
childElement.children = childElement.children.filter( | ||
(child: any) => !componentTree.children.some( | ||
(treeChild: any) => treeChild.path === child.path | ||
) | ||
); | ||
@@ -644,3 +654,2 @@ } | ||
return element; | ||
@@ -647,0 +656,0 @@ } |
Sorry, the diff of this file is not supported yet
82459
1560