sefiutils 1.0.10 → 1.0.11

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.
@@ -27,9 +27,9 @@ function createComponentNode(fiber/* : Fiber */, parent/* : ComponentNode|undefi
27
27
  parent: parent,
28
28
  children: []
29
29
  };
30
- if (parent) {
31
- parent.children.push(node);
32
- }
30
+
31
+ const debugType = fiber?._debugOwner?.type;
32
+
33
33
 
34
34
  if (!parent) {
35
35
  node.name = "root";
@@ -37,6 +37,12 @@ function createComponentNode(fiber/* : Fiber */, parent/* : ComponentNode|undefi
37
37
  } else if (fiber.type === null) {
38
38
  node.kind = "null";
39
39
  node.name = "null";
40
+ if (debugType) {
41
+ node.name = debugType.displayName();
42
+ if (typeof debugType.render === 'function') {
43
+ node.type = "function";
44
+ }
45
+ }
40
46
  } else if (typeof fiber.type === "function") {
41
47
  node.name = fiber.type.name;
42
48
  node.kind = "function";
@@ -45,11 +51,35 @@ function createComponentNode(fiber/* : Fiber */, parent/* : ComponentNode|undefi
45
51
  } else if (typeof fiber.type === "string") {
46
52
  node.name = fiber.type;
47
53
  node.kind = "html";
54
+
55
+ if (debugType) {
56
+ const debugNode/* : any */ = {
57
+ parent: parent,
58
+ children: []
59
+ };
60
+
61
+ debugNode.name = debugType.displayName;
62
+ if (typeof debugType.render === 'function') {
63
+ debugNode.type = "function";
64
+ } else {
65
+ debugNode.type = "null";
66
+ }
67
+ node.parent = debugNode;
68
+ if (parent) {
69
+ parent.children.push(debugNode);
70
+ parent = debugNode;
71
+ }
72
+
73
+ }
48
74
  } else {
49
75
  node.name = String(fiber.type);
50
76
  node.kind = "other";
51
77
  }
52
78
 
79
+ if (parent) {
80
+ parent.children.push(node);
81
+ }
82
+
53
83
  if (fiber.child) {
54
84
  createComponentNode(fiber.child, node);
55
85
  } else if (fiberAct.child) {
@@ -108,15 +138,15 @@ function getProps(fiber/* : Fiber */)/* : string[] */ {
108
138
  return props;
109
139
  }
110
140
 
111
- function getComponentTree(doc/* : Document */) {
112
- const root = getFiberRoot(doc);
141
+ function getComponentTree() {
142
+ const root = getFiberRoot();
113
143
  if (!root) {
114
144
  return undefined;
115
145
  }
116
146
  return createComponentNode(root, undefined)
117
147
  }
118
148
 
119
- function getFiberRoot(doc/* : Document */)/* : Fiber|undefined */ {
149
+ function getFiberRoot()/* : Fiber|undefined */ {
120
150
  const rootElement = document.getElementById("root");
121
151
  if (rootElement) {
122
152
  const reactContainerProp = Object.keys(rootElement).find(key => key.startsWith("__reactContainer$"));
@@ -126,7 +156,7 @@ function getFiberRoot(doc/* : Document */)/* : Fiber|undefined */ {
126
156
  }
127
157
  }
128
158
 
129
- function dump(node/* : ComponentNode */, indent/* : string */ = "") {
159
+ function dumpReactComponentTree(node/* : ComponentNode */, indent/* : string */ = "") {
130
160
  console.log(`${indent}${node.name} (${node.kind})${(node.props && node.props.length > 0) ? ": " + node.props.join(", ") : ""}`);
131
161
  for (const child of node.children) {
132
162
  dump(child, indent + " ");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sefiutils",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "Utilities (and Jest tests) for Selenium Webdriver Tests and some React tools as well",
5
5
  "author": "Jens von Pilgrim <jens.vonpilgrim@bht-berlin.de>",
6
6
  "license": "EPL-2.0",