@whitesev/utils 2.7.6 → 2.7.7
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/dist/index.amd.js +8 -3
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +8 -3
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +8 -3
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +8 -3
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +8 -3
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +8 -3
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Utils.d.ts +2 -8
- package/dist/types/src/types/React.d.ts +119 -0
- package/package.json +1 -1
- package/src/Utils.ts +10 -11
- package/src/types/React.d.ts +119 -0
|
@@ -15,6 +15,7 @@ import { Vue } from "./Vue";
|
|
|
15
15
|
import { type ArgsType, type JSTypeNames, type UtilsOwnObject } from "./types/global";
|
|
16
16
|
import type { WindowApiOption } from "./types/WindowApi";
|
|
17
17
|
import { ModuleRaid } from "./ModuleRaid";
|
|
18
|
+
import type { ReactInstance } from "./types/React";
|
|
18
19
|
declare class Utils {
|
|
19
20
|
private windowApi;
|
|
20
21
|
constructor(option?: WindowApiOption);
|
|
@@ -529,14 +530,7 @@ declare class Utils {
|
|
|
529
530
|
* @example
|
|
530
531
|
* Utils.getReactObj(document.querySelector("input"))?.reactProps?.onChange({target:{value:"123"}});
|
|
531
532
|
*/
|
|
532
|
-
getReactObj(element: HTMLElement | Element):
|
|
533
|
-
reactFiber?: any;
|
|
534
|
-
reactProps?: any;
|
|
535
|
-
reactEvents?: any;
|
|
536
|
-
reactEventHandlers?: any;
|
|
537
|
-
reactInternalInstance?: any;
|
|
538
|
-
reactContainer?: any;
|
|
539
|
-
};
|
|
533
|
+
getReactObj(element: HTMLElement | Element): ReactInstance;
|
|
540
534
|
/**
|
|
541
535
|
* 获取对象上的Symbol属性,如果没设置keyName,那么返回一个对象,对象是所有遍历到的Symbol对象
|
|
542
536
|
* @param target 目标对象
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
export declare interface ReactFiberNode {
|
|
2
|
+
/**
|
|
3
|
+
* 指向当前节点在上一次更新时的对应节点。
|
|
4
|
+
*/
|
|
5
|
+
alternate: ReactFiberNode;
|
|
6
|
+
/**
|
|
7
|
+
* 指向该 FiberNode 的第一个子节点
|
|
8
|
+
*/
|
|
9
|
+
child: ReactFiberNode | null;
|
|
10
|
+
/**
|
|
11
|
+
* 代表子节点上的更新优先级。
|
|
12
|
+
*/
|
|
13
|
+
childLanes: number;
|
|
14
|
+
/**
|
|
15
|
+
* 存储节点的依赖信息,用于处理 useEffect 等情况。
|
|
16
|
+
*/
|
|
17
|
+
dependencies: any | null;
|
|
18
|
+
/**
|
|
19
|
+
* 大部分情况与 type 相同,某些情况不同,比如 FunctionComponent 使用 React.memo 包裹,表示元素的类型
|
|
20
|
+
*/
|
|
21
|
+
elementType: string;
|
|
22
|
+
/**
|
|
23
|
+
* 存储 FiberNode 的标记,表示节点上的各种状态和变化(删除、新增、替换等)。flags 的定义在 packages\react-reconciler\src\ReactFiberFlags.js 文件中,flags 为 number 类型。
|
|
24
|
+
*/
|
|
25
|
+
flags: number;
|
|
26
|
+
/**
|
|
27
|
+
* 当前节点在父节点的子节点列表中的索引
|
|
28
|
+
*/
|
|
29
|
+
index: number;
|
|
30
|
+
/**
|
|
31
|
+
* 节点的唯一标识符,用于进行节点的 diff 和更新
|
|
32
|
+
*/
|
|
33
|
+
key: any | null;
|
|
34
|
+
/**
|
|
35
|
+
* 代表当前节点上的更新优先级。
|
|
36
|
+
*/
|
|
37
|
+
lanes: number;
|
|
38
|
+
/**
|
|
39
|
+
* 表示节点上一次渲染的 props 。在完成本次更新之前,memoizedProps 中存储的是上一次渲染时的 props ,用于对比新旧 props 是否发生变化。
|
|
40
|
+
*/
|
|
41
|
+
memoizedProps: any;
|
|
42
|
+
/**
|
|
43
|
+
* 类组件保存上次渲染后的 state ,函数组件保存的 hooks 信息。
|
|
44
|
+
*/
|
|
45
|
+
memoizedState: any | null;
|
|
46
|
+
/**
|
|
47
|
+
* 表示节点的模式,如 ConcurrentMode 、StrictMode 等。
|
|
48
|
+
*/
|
|
49
|
+
mode: number;
|
|
50
|
+
/**
|
|
51
|
+
* 表示即将被应用到节点的 props 。当父组件发生更新时,会将新的 props 存储在 pendingProps 中,之后会被应用到节点。
|
|
52
|
+
*/
|
|
53
|
+
pendingProps: any;
|
|
54
|
+
/**
|
|
55
|
+
* 存储 FiberNode 的引用信息,与 React 的 Ref 有关。使用 ref 引用值
|
|
56
|
+
*/
|
|
57
|
+
ref: any | null;
|
|
58
|
+
/**
|
|
59
|
+
* 指向该 FiberNode 的父节点
|
|
60
|
+
*/
|
|
61
|
+
return: ReactFiberNode | null;
|
|
62
|
+
/**
|
|
63
|
+
* 指向右边第一个兄弟 Fiber 节点
|
|
64
|
+
*/
|
|
65
|
+
sibling: ReactFiberNode | null;
|
|
66
|
+
/**
|
|
67
|
+
* FiberNode 对应的真实 DOM 节点
|
|
68
|
+
*/
|
|
69
|
+
stateNode: HTMLElement;
|
|
70
|
+
/**
|
|
71
|
+
* 表示节点类型的标记,例如 FunctionComponent 、ClassComponent 等
|
|
72
|
+
*/
|
|
73
|
+
tag: number;
|
|
74
|
+
/**
|
|
75
|
+
* 表示元素的类型, 对于 FunctionComponent,指函数本身,对于ClassComponent,指 class,对于 HostComponent,指 DOM 节点 tagName
|
|
76
|
+
*/
|
|
77
|
+
type: string;
|
|
78
|
+
/**
|
|
79
|
+
* 用于存储组件的更新状态,比如新的状态、属性或者 context 的变化。通过 updateQueue ,React 可以跟踪组件的更新并在合适的时机执行更新。
|
|
80
|
+
*/
|
|
81
|
+
updateQueue: any;
|
|
82
|
+
[key: string | symbol]: any;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export declare interface ReactProps {
|
|
86
|
+
$$typeof: symbol;
|
|
87
|
+
children: (boolean | ReactProps)[] | ReactProps;
|
|
88
|
+
key: string | null;
|
|
89
|
+
ref: any;
|
|
90
|
+
props: ReactProps;
|
|
91
|
+
type: string;
|
|
92
|
+
_owner: any;
|
|
93
|
+
[key: string | symbol]: any;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export declare interface ReactEvents {
|
|
97
|
+
[key: string | symbol]: any;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export declare interface ReactEventHandlers {
|
|
101
|
+
[key: string | symbol]: any;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export declare interface ReactInternalInstance {
|
|
105
|
+
[key: string | symbol]: any;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export declare interface ReactContainer {
|
|
109
|
+
[key: string | symbol]: any;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export declare interface ReactInstance {
|
|
113
|
+
reactFiber?: ReactFiberNode;
|
|
114
|
+
reactProps?: ReactProps;
|
|
115
|
+
reactEvents?: ReactEvents;
|
|
116
|
+
reactEventHandlers?: ReactEventHandlers;
|
|
117
|
+
reactInternalInstance?: ReactInternalInstance;
|
|
118
|
+
reactContainer?: ReactContainer;
|
|
119
|
+
}
|
package/package.json
CHANGED
package/src/Utils.ts
CHANGED
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
import { ModuleRaid } from "./ModuleRaid";
|
|
29
29
|
import { domUtils } from "./DOMUtils";
|
|
30
30
|
import { CommonUtil } from "./CommonUtil";
|
|
31
|
+
import type { ReactInstance } from "./types/React";
|
|
31
32
|
|
|
32
33
|
class Utils {
|
|
33
34
|
private windowApi: typeof WindowApi.prototype;
|
|
@@ -1337,22 +1338,20 @@ class Utils {
|
|
|
1337
1338
|
* @example
|
|
1338
1339
|
* Utils.getReactObj(document.querySelector("input"))?.reactProps?.onChange({target:{value:"123"}});
|
|
1339
1340
|
*/
|
|
1340
|
-
getReactObj(element: HTMLElement | Element): {
|
|
1341
|
-
reactFiber?: any;
|
|
1342
|
-
reactProps?: any;
|
|
1343
|
-
reactEvents?: any;
|
|
1344
|
-
reactEventHandlers?: any;
|
|
1345
|
-
reactInternalInstance?: any;
|
|
1346
|
-
reactContainer?: any;
|
|
1347
|
-
} {
|
|
1341
|
+
getReactObj(element: HTMLElement | Element): ReactInstance {
|
|
1348
1342
|
let result = {};
|
|
1349
|
-
|
|
1343
|
+
if (element == null) {
|
|
1344
|
+
return result;
|
|
1345
|
+
}
|
|
1346
|
+
const keys = Object.keys(element);
|
|
1347
|
+
keys.forEach((domPropsName) => {
|
|
1350
1348
|
if (domPropsName.startsWith("__react")) {
|
|
1351
|
-
|
|
1349
|
+
const propsName = domPropsName.replace(/__(.+)\$.+/i, "$1");
|
|
1350
|
+
const propsValue = Reflect.get(element, domPropsName);
|
|
1352
1351
|
if (propsName in result) {
|
|
1353
1352
|
new Error("重复属性 " + domPropsName);
|
|
1354
1353
|
} else {
|
|
1355
|
-
(result
|
|
1354
|
+
Reflect.set(result, propsName, propsValue);
|
|
1356
1355
|
}
|
|
1357
1356
|
}
|
|
1358
1357
|
});
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
export declare interface ReactFiberNode {
|
|
2
|
+
/**
|
|
3
|
+
* 指向当前节点在上一次更新时的对应节点。
|
|
4
|
+
*/
|
|
5
|
+
alternate: ReactFiberNode;
|
|
6
|
+
/**
|
|
7
|
+
* 指向该 FiberNode 的第一个子节点
|
|
8
|
+
*/
|
|
9
|
+
child: ReactFiberNode | null;
|
|
10
|
+
/**
|
|
11
|
+
* 代表子节点上的更新优先级。
|
|
12
|
+
*/
|
|
13
|
+
childLanes: number;
|
|
14
|
+
/**
|
|
15
|
+
* 存储节点的依赖信息,用于处理 useEffect 等情况。
|
|
16
|
+
*/
|
|
17
|
+
dependencies: any | null;
|
|
18
|
+
/**
|
|
19
|
+
* 大部分情况与 type 相同,某些情况不同,比如 FunctionComponent 使用 React.memo 包裹,表示元素的类型
|
|
20
|
+
*/
|
|
21
|
+
elementType: string;
|
|
22
|
+
/**
|
|
23
|
+
* 存储 FiberNode 的标记,表示节点上的各种状态和变化(删除、新增、替换等)。flags 的定义在 packages\react-reconciler\src\ReactFiberFlags.js 文件中,flags 为 number 类型。
|
|
24
|
+
*/
|
|
25
|
+
flags: number;
|
|
26
|
+
/**
|
|
27
|
+
* 当前节点在父节点的子节点列表中的索引
|
|
28
|
+
*/
|
|
29
|
+
index: number;
|
|
30
|
+
/**
|
|
31
|
+
* 节点的唯一标识符,用于进行节点的 diff 和更新
|
|
32
|
+
*/
|
|
33
|
+
key: any | null;
|
|
34
|
+
/**
|
|
35
|
+
* 代表当前节点上的更新优先级。
|
|
36
|
+
*/
|
|
37
|
+
lanes: number;
|
|
38
|
+
/**
|
|
39
|
+
* 表示节点上一次渲染的 props 。在完成本次更新之前,memoizedProps 中存储的是上一次渲染时的 props ,用于对比新旧 props 是否发生变化。
|
|
40
|
+
*/
|
|
41
|
+
memoizedProps: any;
|
|
42
|
+
/**
|
|
43
|
+
* 类组件保存上次渲染后的 state ,函数组件保存的 hooks 信息。
|
|
44
|
+
*/
|
|
45
|
+
memoizedState: any | null;
|
|
46
|
+
/**
|
|
47
|
+
* 表示节点的模式,如 ConcurrentMode 、StrictMode 等。
|
|
48
|
+
*/
|
|
49
|
+
mode: number;
|
|
50
|
+
/**
|
|
51
|
+
* 表示即将被应用到节点的 props 。当父组件发生更新时,会将新的 props 存储在 pendingProps 中,之后会被应用到节点。
|
|
52
|
+
*/
|
|
53
|
+
pendingProps: any;
|
|
54
|
+
/**
|
|
55
|
+
* 存储 FiberNode 的引用信息,与 React 的 Ref 有关。使用 ref 引用值
|
|
56
|
+
*/
|
|
57
|
+
ref: any | null;
|
|
58
|
+
/**
|
|
59
|
+
* 指向该 FiberNode 的父节点
|
|
60
|
+
*/
|
|
61
|
+
return: ReactFiberNode | null;
|
|
62
|
+
/**
|
|
63
|
+
* 指向右边第一个兄弟 Fiber 节点
|
|
64
|
+
*/
|
|
65
|
+
sibling: ReactFiberNode | null;
|
|
66
|
+
/**
|
|
67
|
+
* FiberNode 对应的真实 DOM 节点
|
|
68
|
+
*/
|
|
69
|
+
stateNode: HTMLElement;
|
|
70
|
+
/**
|
|
71
|
+
* 表示节点类型的标记,例如 FunctionComponent 、ClassComponent 等
|
|
72
|
+
*/
|
|
73
|
+
tag: number;
|
|
74
|
+
/**
|
|
75
|
+
* 表示元素的类型, 对于 FunctionComponent,指函数本身,对于ClassComponent,指 class,对于 HostComponent,指 DOM 节点 tagName
|
|
76
|
+
*/
|
|
77
|
+
type: string;
|
|
78
|
+
/**
|
|
79
|
+
* 用于存储组件的更新状态,比如新的状态、属性或者 context 的变化。通过 updateQueue ,React 可以跟踪组件的更新并在合适的时机执行更新。
|
|
80
|
+
*/
|
|
81
|
+
updateQueue: any;
|
|
82
|
+
[key: string | symbol]: any;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export declare interface ReactProps {
|
|
86
|
+
$$typeof: symbol;
|
|
87
|
+
children: (boolean | ReactProps)[] | ReactProps;
|
|
88
|
+
key: string | null;
|
|
89
|
+
ref: any;
|
|
90
|
+
props: ReactProps;
|
|
91
|
+
type: string;
|
|
92
|
+
_owner: any;
|
|
93
|
+
[key: string | symbol]: any;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export declare interface ReactEvents {
|
|
97
|
+
[key: string | symbol]: any;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export declare interface ReactEventHandlers {
|
|
101
|
+
[key: string | symbol]: any;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export declare interface ReactInternalInstance {
|
|
105
|
+
[key: string | symbol]: any;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export declare interface ReactContainer {
|
|
109
|
+
[key: string | symbol]: any;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export declare interface ReactInstance {
|
|
113
|
+
reactFiber?: ReactFiberNode;
|
|
114
|
+
reactProps?: ReactProps;
|
|
115
|
+
reactEvents?: ReactEvents;
|
|
116
|
+
reactEventHandlers?: ReactEventHandlers;
|
|
117
|
+
reactInternalInstance?: ReactInternalInstance;
|
|
118
|
+
reactContainer?: ReactContainer;
|
|
119
|
+
}
|