react-component-instance 0.0.4 → 0.0.6
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/package.json +3 -2
- package/src/common/index.mjs +11 -11
- package/src/container/index.mjs +10 -0
- package/src/index.mjs +12 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-component-instance",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "Get a React class component instance from its DOM Element",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -41,7 +41,8 @@
|
|
|
41
41
|
"@testing-library/react": "^16.2.0",
|
|
42
42
|
"@types/debug": "^4.1.12",
|
|
43
43
|
"@types/jest": "^29.5.14",
|
|
44
|
-
"@types/
|
|
44
|
+
"@types/prop-types": "^15.7.14",
|
|
45
|
+
"@types/react": "^19.0.11",
|
|
45
46
|
"core-js": "^3.41.0",
|
|
46
47
|
"eslint": "^9.22.0",
|
|
47
48
|
"eslint-plugin-react": "^7.37.4",
|
package/src/common/index.mjs
CHANGED
|
@@ -137,41 +137,41 @@ export function getContainerFiberFrom (element) {
|
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
/**
|
|
140
|
-
*
|
|
141
|
-
*
|
|
140
|
+
* @param {FiberNode} fiber
|
|
141
|
+
* @returns {FiberNode | null | undefined}
|
|
142
142
|
*/
|
|
143
143
|
export function getParentFiber ({ return: parentFiber }) {
|
|
144
144
|
return parentFiber
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
/**
|
|
148
|
-
*
|
|
149
|
-
*
|
|
148
|
+
* @param {FiberNode} fiber
|
|
149
|
+
* @returns {FiberNode | null | undefined}
|
|
150
150
|
*/
|
|
151
151
|
export function getChildFiber ({ child: childFiber }) {
|
|
152
152
|
return childFiber
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
/**
|
|
156
|
-
*
|
|
157
|
-
*
|
|
156
|
+
* @param {FiberNode} fiber
|
|
157
|
+
* @returns {React.Component<any, any, any> | HTMLElement | Text | null}
|
|
158
158
|
*/
|
|
159
159
|
export function getComponentInstance ({ stateNode: instance }) {
|
|
160
160
|
return instance
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
/**
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
164
|
+
* @param {(() => React.JSX.Element) | typeof React.Component} Component
|
|
165
|
+
* @param {FiberNode} fiber
|
|
166
|
+
* @returns {boolean}
|
|
167
167
|
*/
|
|
168
168
|
export function isComponentType (Component, { type }) {
|
|
169
169
|
return Component === type
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
/**
|
|
173
|
-
*
|
|
174
|
-
*
|
|
173
|
+
* @param {(() => React.JSX.Element) | typeof React.Component} Component
|
|
174
|
+
* @returns {(fiber: FiberNode) => boolean}
|
|
175
175
|
*/
|
|
176
176
|
export function getIsComponentType (Component) {
|
|
177
177
|
return function isComponentType ({ type }) {
|
package/src/container/index.mjs
CHANGED
|
@@ -20,6 +20,16 @@ export function getContainerFiberNodeFrom (container) {
|
|
|
20
20
|
throw new Error('Container is not an Element')
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* @param {{ container: Element }} component
|
|
25
|
+
* @returns {Element}
|
|
26
|
+
*/
|
|
27
|
+
export function getComponentElement ({
|
|
28
|
+
container
|
|
29
|
+
}) {
|
|
30
|
+
return container
|
|
31
|
+
}
|
|
32
|
+
|
|
23
33
|
/**
|
|
24
34
|
* @param {Element | null | undefined} container
|
|
25
35
|
* @returns {React.Component<any, any, any> | HTMLElement | Text | null}
|
package/src/index.mjs
CHANGED
|
@@ -86,6 +86,18 @@ export function getChildFiberNodeFrom (element) {
|
|
|
86
86
|
throw new Error('Element is not an Element')
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
+
/**
|
|
90
|
+
* @param {{ container: { firstElementChild: Element | null } }} component
|
|
91
|
+
* @returns {Element | null}
|
|
92
|
+
*/
|
|
93
|
+
export function getComponentElement ({
|
|
94
|
+
container: {
|
|
95
|
+
firstElementChild: element
|
|
96
|
+
}
|
|
97
|
+
}) {
|
|
98
|
+
return element
|
|
99
|
+
}
|
|
100
|
+
|
|
89
101
|
/**
|
|
90
102
|
* @param {Element | null | undefined} element
|
|
91
103
|
* @returns {React.Component<any, any, any> | HTMLElement | Text | null}
|