@builderx/bridge
Advanced tools
Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "@builderx/bridge", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "types": "dist/index.d.ts", |
@@ -10,2 +10,3 @@ declare global { | ||
export function initBridge(): void { | ||
if (typeof window !== 'undefined' && !window.isInitialized) { | ||
@@ -246,2 +247,6 @@ window.isInitialized = true; | ||
function getDomNodeFromPath(path: string): Element | null { | ||
return document.querySelector(`[data-path="${path}"]`); | ||
} | ||
// Update this function | ||
@@ -252,5 +257,10 @@ function getLayerById(args: { layerId: string }): any { | ||
const fiberNode = getFibreNodeFromPath(layerId); | ||
// console.log(fiberNode, 'fiberNode in getLayerById initBridge') | ||
let element: Element | null = null; | ||
if (fiberNode) { | ||
element = getDomNodeFromFiber(fiberNode); | ||
} else { | ||
element = getDomNodeFromPath(layerId); | ||
} | ||
const element = getDomNodeFromFiber(fiberNode); | ||
if (element) { | ||
@@ -282,3 +292,3 @@ const rect = element.getBoundingClientRect(); | ||
const computedStyle = window.getComputedStyle(domNode); | ||
console.log(JSON.parse(JSON.stringify(computedStyle)),"JSON.parse(JSON.stringify(computedStyle))") | ||
console.log(JSON.parse(JSON.stringify(computedStyle)),"JSON.parse(JSON.stringify(computedStyle))") | ||
return JSON.parse(JSON.stringify(computedStyle)); | ||
@@ -329,5 +339,5 @@ | ||
} | ||
const rootFiber = getFiberFromDOMNode(rootElement); | ||
return rootFiber; | ||
@@ -387,2 +397,3 @@ } | ||
function getComponentName(child: any): string { | ||
const displayName = | ||
@@ -408,5 +419,2 @@ child?.displayName || | ||
if (!fiber) { | ||
return null; | ||
} | ||
const componentTree = buildReactFiberTree(fiber, withFiber); | ||
@@ -416,4 +424,5 @@ const childElement: any = { | ||
path: child.props?.['data-path'] || null, | ||
fiber: withFiber ? fiber : null, | ||
fiber: withFiber? fiber : null, | ||
componentTree: componentTree, | ||
debugInfo: child?._debugInfo || null, | ||
children: [], | ||
@@ -529,2 +538,3 @@ }; | ||
displayName: getComponentName(memoizedChild), | ||
debugInfo: memoizedChild?._owner?._debugInfo || null, | ||
path: memoizedChild?.props?.['data-path'] || null, | ||
@@ -540,2 +550,3 @@ props: { ...memoizedChild?.props }, | ||
displayName: getComponentName(child), | ||
debugInfo: child?._debugInfo || null, | ||
path: child.memoizedProps?.['data-path'] || null, | ||
@@ -565,2 +576,3 @@ props: { ...child.memoizedProps, children: childChildren }, | ||
displayName: 'Component-' + getComponentName(fiber), | ||
debugInfo: fiber?._debugInfo || null, | ||
path: fiber.memoizedProps?.['data-path'] || null, | ||
@@ -589,2 +601,3 @@ fiber: withFiber ? fiber : null, | ||
// Check if this fiber node has a data-path | ||
const hasDataPath = | ||
@@ -612,2 +625,3 @@ fiber.memoizedProps && | ||
displayName: getComponentName(fiber), | ||
debugInfo: fiber?._debugInfo || null, | ||
path: fiber.memoizedProps['data-path'], | ||
@@ -634,2 +648,3 @@ fiber: withFiber ? fiber : null, | ||
if (children) { | ||
@@ -639,2 +654,4 @@ element.children = prepareChildrenTree(children, withFiber); | ||
return element; | ||
@@ -647,2 +664,3 @@ } | ||
const elementTree = buildReactElementTree(rootFiber, true); | ||
@@ -649,0 +667,0 @@ // Helper function to traverse the fiber tree |
79710
1532