@ansight/react-native 1.3.0-preview.2 → 1.3.0-preview.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -77,8 +77,8 @@ bundle; its API requires the native Ansight module.
77
77
 
78
78
  This package version expects matching native SDK packages:
79
79
 
80
- - CocoaPods: `Ansight`, `AnsightObjC` version `1.3.0-preview.2`
81
- - Maven: `ai.ansight:ansight-android:1.3.0-preview.2`
80
+ - CocoaPods: `Ansight`, `AnsightObjC` version `1.3.0-preview.3`
81
+ - Maven: `ai.ansight:ansight-android:1.3.0-preview.3`
82
82
 
83
83
  ## Quickstart
84
84
 
@@ -67,6 +67,6 @@ repositories {
67
67
  dependencies {
68
68
  implementation("com.facebook.react:react-android")
69
69
  def ansightAndroidVersion =
70
- findProperty("ansightAndroidVersion") ?: "1.3.0-preview.2"
71
- implementation("ai.ansight:ansight-android:1.3.0-preview.2")
70
+ findProperty("ansightAndroidVersion") ?: "1.3.0-preview.3"
71
+ implementation("ai.ansight:ansight-android:1.3.0-preview.3")
72
72
  }
package/index.js CHANGED
@@ -1489,6 +1489,28 @@ function createReactVisual(fiber, props, maxStringLength) {
1489
1489
  return visual;
1490
1490
  }
1491
1491
 
1492
+ function createReactZIndex(props) {
1493
+ const style = StyleSheet && typeof StyleSheet.flatten === "function"
1494
+ ? StyleSheet.flatten(props && props.style)
1495
+ : props && props.style;
1496
+ const zIndex = style && style.zIndex != null ? Number(style.zIndex) : NaN;
1497
+ const elevation = style && style.elevation != null ? Number(style.elevation) : NaN;
1498
+ if (Number.isFinite(zIndex) && zIndex !== 0) return zIndex;
1499
+ if (Number.isFinite(elevation) && elevation !== 0) return elevation;
1500
+ return null;
1501
+ }
1502
+
1503
+ function registerReactType(context, typeName) {
1504
+ const normalizedTypeName = String(typeName || "UnknownComponent").trim() || "UnknownComponent";
1505
+ const existingTypeId = context.typeIdsByName.get(normalizedTypeName);
1506
+ if (existingTypeId != null) return existingTypeId;
1507
+
1508
+ const typeId = context.types.length;
1509
+ context.types.push(normalizedTypeName);
1510
+ context.typeIdsByName.set(normalizedTypeName, typeId);
1511
+ return typeId;
1512
+ }
1513
+
1492
1514
  function nativeTagForFiber(fiber) {
1493
1515
  const stateNode = fiber && fiber.stateNode;
1494
1516
  if (!stateNode) {
@@ -1560,17 +1582,17 @@ function serializeFiber(fiber, context, depth) {
1560
1582
 
1561
1583
  const props = fiber.memoizedProps || fiber.pendingProps || {};
1562
1584
  const type = reactFiberTypeName(fiber);
1563
- const kind = reactFiberKind(fiber.tag);
1564
1585
  const node = {
1565
1586
  id: reactFiberId(fiber),
1566
- type,
1567
- kind,
1587
+ typeId: registerReactType(context, type),
1568
1588
  tag: fiber.tag,
1569
1589
  key: fiber.key == null ? null : String(fiber.key),
1570
1590
  depth,
1571
1591
  visual: createReactVisual(fiber, props, context.maxStringLength),
1572
1592
  children: [],
1573
1593
  };
1594
+ const zIndex = createReactZIndex(props);
1595
+ if (zIndex != null) node.z = zIndex;
1574
1596
 
1575
1597
  if (fiber._debugSource) {
1576
1598
  node.source = {
@@ -1582,7 +1604,7 @@ function serializeFiber(fiber, context, depth) {
1582
1604
 
1583
1605
  const owner = fiber._debugOwner && reactFiberTypeName(fiber._debugOwner);
1584
1606
  if (owner) {
1585
- node.owner = owner;
1607
+ node.ownerTypeId = registerReactType(context, owner);
1586
1608
  }
1587
1609
 
1588
1610
  const nativeTag = nativeTagForFiber(fiber);
@@ -1641,14 +1663,15 @@ function createShadowTreeNode(fiber, context, depth) {
1641
1663
  const type = reactFiberTypeName(fiber);
1642
1664
  const node = {
1643
1665
  id: reactFiberId(fiber),
1644
- type,
1645
- kind: fiber.tag === 3 ? "root" : fiber.tag === 6 ? "text" : "host",
1666
+ typeId: registerReactType(context, type),
1646
1667
  tag: fiber.tag,
1647
1668
  key: fiber.key == null ? null : String(fiber.key),
1648
1669
  depth,
1649
1670
  visual: createReactVisual(fiber, props, context.maxStringLength),
1650
1671
  children: [],
1651
1672
  };
1673
+ const zIndex = createReactZIndex(props);
1674
+ if (zIndex != null) node.z = zIndex;
1652
1675
 
1653
1676
  const nativeTag = nativeTagForFiber(fiber);
1654
1677
  if (nativeTag != null) {
@@ -1732,19 +1755,21 @@ async function captureReactVisualTree(rawOptions = {}) {
1732
1755
  maxStringLength: rawOptions.maxStringLength || 180,
1733
1756
  maxValueDepth: rawOptions.maxValueDepth || 2,
1734
1757
  nodesWithNativeTags: [],
1758
+ typeIdsByName: new Map(),
1759
+ types: [],
1735
1760
  count: 0,
1736
1761
  truncated: false,
1737
1762
  visited: new Set(),
1738
1763
  };
1739
1764
  const roots = getReactRoots();
1740
- const rootNodes = roots.roots.map((root, index) => {
1765
+ const rootNodes = roots.roots.map((root) => {
1741
1766
  const node = serializeFiber(root.fiber, context, 0);
1742
1767
  if (node) {
1743
1768
  node.rendererId = root.rendererId;
1744
- node.rootIndex = index;
1745
1769
  }
1746
1770
  return node;
1747
1771
  }).filter(Boolean);
1772
+ const rootTypeId = registerReactType(context, "ReactRoots");
1748
1773
 
1749
1774
  if (includeBounds && context.nodesWithNativeTags.length > 0) {
1750
1775
  await Promise.all(context.nodesWithNativeTags.slice(0, 300).map(async (node) => {
@@ -1756,6 +1781,7 @@ async function captureReactVisualTree(rawOptions = {}) {
1756
1781
  }
1757
1782
 
1758
1783
  return {
1784
+ format: "ansight.react.visual-tree.compact.v2",
1759
1785
  platform: Platform.OS,
1760
1786
  source: "react",
1761
1787
  adapter: "react.fiber",
@@ -1765,11 +1791,11 @@ async function captureReactVisualTree(rawOptions = {}) {
1765
1791
  renderers: roots.renderers,
1766
1792
  root: {
1767
1793
  id: "react:roots",
1768
- type: "ReactRoots",
1769
- kind: "container",
1794
+ typeId: rootTypeId,
1795
+ childCount: rootNodes.length,
1770
1796
  children: rootNodes,
1771
1797
  },
1772
- roots: rootNodes,
1798
+ types: context.types,
1773
1799
  nodeCount: context.count,
1774
1800
  truncated: context.truncated,
1775
1801
  unavailableReason: roots.hookAvailable ? undefined : "React DevTools global hook is not available in this runtime.",
@@ -1789,19 +1815,21 @@ async function captureReactShadowTree(rawOptions = {}) {
1789
1815
  maxStringLength: rawOptions.maxStringLength || 180,
1790
1816
  maxValueDepth: rawOptions.maxValueDepth || 2,
1791
1817
  nodesWithNativeTags: [],
1818
+ typeIdsByName: new Map(),
1819
+ types: [],
1792
1820
  count: 0,
1793
1821
  truncated: false,
1794
1822
  visited: new Set(),
1795
1823
  };
1796
1824
  const roots = getReactRoots();
1797
- const rootNodes = roots.roots.flatMap((root, index) => {
1825
+ const rootNodes = roots.roots.flatMap((root) => {
1798
1826
  const nodes = serializeShadowFiber(root.fiber, context, 0);
1799
1827
  nodes.forEach((node) => {
1800
1828
  node.rendererId = root.rendererId;
1801
- node.rootIndex = index;
1802
1829
  });
1803
1830
  return nodes;
1804
1831
  });
1832
+ const rootTypeId = registerReactType(context, "ReactNativeShadowRoots");
1805
1833
 
1806
1834
  if (includeBounds && context.nodesWithNativeTags.length > 0) {
1807
1835
  await Promise.all(context.nodesWithNativeTags.slice(0, 300).map(async (node) => {
@@ -1813,6 +1841,7 @@ async function captureReactShadowTree(rawOptions = {}) {
1813
1841
  }
1814
1842
 
1815
1843
  return {
1844
+ format: "ansight.react.visual-tree.compact.v2",
1816
1845
  platform: Platform.OS,
1817
1846
  source: "react-native",
1818
1847
  adapter: "react-native.host-fiber",
@@ -1822,11 +1851,11 @@ async function captureReactShadowTree(rawOptions = {}) {
1822
1851
  renderers: roots.renderers,
1823
1852
  root: {
1824
1853
  id: "react:shadow-roots",
1825
- type: "ReactNativeShadowRoots",
1826
- kind: "container",
1854
+ typeId: rootTypeId,
1855
+ childCount: rootNodes.length,
1827
1856
  children: rootNodes,
1828
1857
  },
1829
- roots: rootNodes,
1858
+ types: context.types,
1830
1859
  nodeCount: context.count,
1831
1860
  truncated: context.truncated,
1832
1861
  unavailableReason: roots.hookAvailable ? undefined : "React DevTools global hook is not available in this runtime.",
@@ -1842,13 +1871,18 @@ function flattenReactTree(node, output = []) {
1842
1871
  return output;
1843
1872
  }
1844
1873
 
1845
- function nodeSearchText(node) {
1874
+ function createReactNodeSnapshot(node) {
1875
+ const snapshot = { ...node };
1876
+ delete snapshot.children;
1877
+ return snapshot;
1878
+ }
1879
+
1880
+ function nodeSearchText(node, types) {
1846
1881
  return [
1847
1882
  node.id,
1848
- node.type,
1849
- node.kind,
1883
+ types[node.typeId],
1850
1884
  node.label,
1851
- node.owner,
1885
+ types[node.ownerTypeId],
1852
1886
  node.propsSummary && node.propsSummary.testID,
1853
1887
  node.propsSummary && node.propsSummary.nativeID,
1854
1888
  node.propsSummary && node.propsSummary.accessibilityLabel,
@@ -1856,14 +1890,14 @@ function nodeSearchText(node) {
1856
1890
  ].filter(Boolean).join(" ").toLowerCase();
1857
1891
  }
1858
1892
 
1859
- function matchesReactNode(node, args) {
1893
+ function matchesReactNode(node, args, types) {
1860
1894
  const query = args.query ? String(args.query).toLowerCase() : null;
1861
1895
  const type = args.type ? String(args.type).toLowerCase() : null;
1862
1896
  const testID = args.testID ? String(args.testID).toLowerCase() : null;
1863
1897
  const text = args.text ? String(args.text).toLowerCase() : null;
1864
- const searchText = nodeSearchText(node);
1898
+ const searchText = nodeSearchText(node, types);
1865
1899
  return (!query || searchText.includes(query)) &&
1866
- (!type || String(node.type || "").toLowerCase().includes(type)) &&
1900
+ (!type || String(types[node.typeId] || "").toLowerCase().includes(type)) &&
1867
1901
  (!testID || String((node.propsSummary && node.propsSummary.testID) || "").toLowerCase() === testID) &&
1868
1902
  (!text || searchText.includes(text));
1869
1903
  }
@@ -2084,12 +2118,14 @@ function installReactTools(options = {}) {
2084
2118
  });
2085
2119
  const maxResults = parseInteger(args.maxResults, 50, 1, 500);
2086
2120
  const matches = flattenReactTree(tree.root)
2087
- .filter((node) => node.id !== "react:roots" && matchesReactNode(node, args))
2088
- .slice(0, maxResults);
2121
+ .filter((node) => node.id !== "react:roots" && matchesReactNode(node, args, tree.types))
2122
+ .slice(0, maxResults)
2123
+ .map(createReactNodeSnapshot);
2089
2124
  return {
2090
2125
  success: tree.hookAvailable,
2091
2126
  message: `Found ${matches.length} React component(s).`,
2092
2127
  result: {
2128
+ types: tree.types,
2093
2129
  matches,
2094
2130
  count: matches.length,
2095
2131
  truncated: matches.length === maxResults,
@@ -2101,7 +2137,11 @@ function installReactTools(options = {}) {
2101
2137
  const tree = await captureReactVisualTree(reactToolOptions(options, args));
2102
2138
  const node = flattenReactTree(tree.root).find((candidate) => candidate.id === args.nodeId);
2103
2139
  return node
2104
- ? { success: true, message: "React component captured.", result: node }
2140
+ ? {
2141
+ success: true,
2142
+ message: "React component captured.",
2143
+ result: { types: tree.types, node: createReactNodeSnapshot(node) },
2144
+ }
2105
2145
  : { success: false, message: `React component '${args.nodeId}' was not found.`, errorCode: "react_component_not_found" };
2106
2146
  }
2107
2147
 
@@ -2142,7 +2182,7 @@ function installReactTools(options = {}) {
2142
2182
  result: {
2143
2183
  nodeId: args.nodeId,
2144
2184
  prop,
2145
- type: node.type,
2185
+ type: tree.types[node.typeId],
2146
2186
  },
2147
2187
  };
2148
2188
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ansight/react-native",
3
- "version": "1.3.0-preview.2",
3
+ "version": "1.3.0-preview.3",
4
4
  "description": "React Native bridge for the Ansight mobile SDK.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",