@wwog/react 1.1.2 → 1.1.4
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.d.mts +23 -23
- package/dist/index.js +16 -18
- package/package.json +1 -1
- package/src/Common/ArrayRender.tsx +1 -1
- package/src/Common/SizeBox.tsx +1 -1
- package/src/ProcessControl/If.tsx +5 -10
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React, { FC, ReactNode } from 'react';
|
|
2
2
|
|
|
3
3
|
interface SwitchProps<T> {
|
|
4
4
|
value: T;
|
|
@@ -7,7 +7,7 @@ interface SwitchProps<T> {
|
|
|
7
7
|
* @description_en optional compare function, default to () => a === b
|
|
8
8
|
**/
|
|
9
9
|
compare?: (a: T, b: T) => boolean;
|
|
10
|
-
children?: React
|
|
10
|
+
children?: React.ReactNode;
|
|
11
11
|
/**
|
|
12
12
|
* @description 是否严格模式,默认 false.建议跟随开发环境变化,严格模式下,会循环所有节点来提供更多的错误提示
|
|
13
13
|
* @description_en strict mode, default to false. It is recommended to follow the development environment changes. In strict mode, all nodes will be looped to provide more error prompts
|
|
@@ -22,58 +22,58 @@ interface SwitchProps<T> {
|
|
|
22
22
|
}
|
|
23
23
|
interface SwitchCaseProps<T> {
|
|
24
24
|
value: T;
|
|
25
|
-
children?: React
|
|
25
|
+
children?: React.ReactNode;
|
|
26
26
|
}
|
|
27
27
|
interface SwitchDefaultProps {
|
|
28
|
-
children?: React
|
|
28
|
+
children?: React.ReactNode;
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
31
|
* @description Switch 组件用于根据传入的 value 渲染不同的子组件
|
|
32
32
|
* @description_en The Switch component is used to render different child components based on the passed value
|
|
33
33
|
*/
|
|
34
34
|
declare const Switch: {
|
|
35
|
-
<T>(props: SwitchProps<T>): React
|
|
35
|
+
<T>(props: SwitchProps<T>): React.ReactElement | null;
|
|
36
36
|
displayName: string;
|
|
37
37
|
Case: {
|
|
38
|
-
<T>(props: SwitchCaseProps<T>): React
|
|
38
|
+
<T>(props: SwitchCaseProps<T>): React.ReactElement;
|
|
39
39
|
displayName: string;
|
|
40
40
|
};
|
|
41
41
|
Default: {
|
|
42
|
-
(props: SwitchDefaultProps): React
|
|
42
|
+
(props: SwitchDefaultProps): React.ReactElement;
|
|
43
43
|
displayName: string;
|
|
44
44
|
};
|
|
45
45
|
createTyped<T>(): {
|
|
46
|
-
Switch: (props: SwitchProps<T>) => React
|
|
47
|
-
Case: (props: SwitchCaseProps<T>) => React
|
|
48
|
-
Default: (props: SwitchDefaultProps) => React
|
|
46
|
+
Switch: (props: SwitchProps<T>) => React.ReactElement | null;
|
|
47
|
+
Case: (props: SwitchCaseProps<T>) => React.ReactElement;
|
|
48
|
+
Default: (props: SwitchDefaultProps) => React.ReactElement;
|
|
49
49
|
};
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
interface IfProps {
|
|
53
53
|
condition: boolean;
|
|
54
|
-
children?: React
|
|
54
|
+
children?: React.ReactNode;
|
|
55
55
|
}
|
|
56
56
|
interface ThenProps {
|
|
57
|
-
children?: React
|
|
57
|
+
children?: React.ReactNode;
|
|
58
58
|
}
|
|
59
59
|
interface ElseProps {
|
|
60
|
-
children?: React
|
|
60
|
+
children?: React.ReactNode;
|
|
61
61
|
}
|
|
62
62
|
interface ElseIfProps {
|
|
63
63
|
condition: boolean;
|
|
64
|
-
children?: React
|
|
64
|
+
children?: React.ReactNode;
|
|
65
65
|
}
|
|
66
66
|
declare const If: {
|
|
67
|
-
({ condition, children, }: IfProps): React
|
|
67
|
+
({ condition, children, }: IfProps): React.ReactElement | null;
|
|
68
68
|
displayName: string;
|
|
69
|
-
Then: React
|
|
70
|
-
ElseIf: React
|
|
71
|
-
Else: React
|
|
69
|
+
Then: React.FC<ThenProps>;
|
|
70
|
+
ElseIf: React.FC<ElseIfProps>;
|
|
71
|
+
Else: React.FC<ElseProps>;
|
|
72
72
|
createTyped(): {
|
|
73
|
-
If: (props: IfProps) => React
|
|
74
|
-
Then: (props: ThenProps) => React
|
|
75
|
-
ElseIf: (props: ElseIfProps) => React
|
|
76
|
-
Else: (props: ElseProps) => React
|
|
73
|
+
If: (props: IfProps) => React.ReactElement | null;
|
|
74
|
+
Then: (props: ThenProps) => React.ReactElement;
|
|
75
|
+
ElseIf: (props: ElseIfProps) => React.ReactElement;
|
|
76
|
+
Else: (props: ElseProps) => React.ReactElement;
|
|
77
77
|
};
|
|
78
78
|
};
|
|
79
79
|
|
|
@@ -101,7 +101,7 @@ declare function ArrayRender<T>(props: ArrayRenderProps<T>): ReactNode;
|
|
|
101
101
|
* @description 性能优化,替代 React.Children.forEach, 回调可以返回 false 来中断循环
|
|
102
102
|
* @description_en Replace React.Children.forEach, the callback can return false to interrupt the loop
|
|
103
103
|
*/
|
|
104
|
-
declare function childrenLoop(children: React
|
|
104
|
+
declare function childrenLoop(children: React.ReactNode | undefined, callback: (child: React.ReactNode, index: number) => boolean | void): void;
|
|
105
105
|
|
|
106
106
|
export { ArrayRender, If, SizeBox, Switch, childrenLoop };
|
|
107
107
|
export type { ArrayRenderProps, ElseIfProps, ElseProps, IfProps, SwitchCaseProps, SwitchDefaultProps, SwitchProps, ThenProps };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React, { Fragment } from 'react';
|
|
2
2
|
|
|
3
3
|
function childrenLoop(children, callback) {
|
|
4
4
|
if (children === void 0) return;
|
|
@@ -19,11 +19,11 @@ const defaultCompare = (a, b) => {
|
|
|
19
19
|
return a === b;
|
|
20
20
|
};
|
|
21
21
|
const Case = (props) => {
|
|
22
|
-
return /* @__PURE__ */ React
|
|
22
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, props.children);
|
|
23
23
|
};
|
|
24
24
|
Case.displayName = "Switch_Case";
|
|
25
25
|
const Default = (props) => {
|
|
26
|
-
return /* @__PURE__ */ React
|
|
26
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, props.children);
|
|
27
27
|
};
|
|
28
28
|
Default.displayName = "Switch_Default";
|
|
29
29
|
const Switch = (props) => {
|
|
@@ -33,7 +33,7 @@ const Switch = (props) => {
|
|
|
33
33
|
let defaultChild = null;
|
|
34
34
|
let hasDefault = false;
|
|
35
35
|
childrenLoop(children, (child, index) => {
|
|
36
|
-
if (!React
|
|
36
|
+
if (!React.isValidElement(child)) {
|
|
37
37
|
throw new Error(
|
|
38
38
|
`Switch Children only accepts valid React elements at index ${index}`
|
|
39
39
|
);
|
|
@@ -74,7 +74,7 @@ const Switch = (props) => {
|
|
|
74
74
|
);
|
|
75
75
|
}
|
|
76
76
|
});
|
|
77
|
-
return /* @__PURE__ */ React
|
|
77
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, matchedChildren ?? defaultChild);
|
|
78
78
|
};
|
|
79
79
|
Switch.displayName = "Switch";
|
|
80
80
|
Switch.Case = Case;
|
|
@@ -88,13 +88,13 @@ Switch.createTyped = function() {
|
|
|
88
88
|
};
|
|
89
89
|
|
|
90
90
|
const Then = (props) => {
|
|
91
|
-
return /* @__PURE__ */ React
|
|
91
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, props.children);
|
|
92
92
|
};
|
|
93
93
|
const Else = ({ children }) => {
|
|
94
|
-
return /* @__PURE__ */ React
|
|
94
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, children);
|
|
95
95
|
};
|
|
96
96
|
const ElseIf = (props) => {
|
|
97
|
-
return /* @__PURE__ */ React
|
|
97
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, props.children);
|
|
98
98
|
};
|
|
99
99
|
Then.displayName = "If_Then";
|
|
100
100
|
Else.displayName = "If_Else";
|
|
@@ -106,8 +106,8 @@ const If = ({
|
|
|
106
106
|
let thenChild = null;
|
|
107
107
|
let elseChild = null;
|
|
108
108
|
const elseIfChildren = [];
|
|
109
|
-
React
|
|
110
|
-
if (!React
|
|
109
|
+
React.Children.forEach(children, (child) => {
|
|
110
|
+
if (!React.isValidElement(child)) {
|
|
111
111
|
throw new Error("If component only accepts valid React elements");
|
|
112
112
|
}
|
|
113
113
|
const type = child.type;
|
|
@@ -132,17 +132,15 @@ const If = ({
|
|
|
132
132
|
}
|
|
133
133
|
});
|
|
134
134
|
if (condition) {
|
|
135
|
-
return thenChild ? /* @__PURE__ */ React
|
|
135
|
+
return thenChild ? /* @__PURE__ */ React.createElement(React.Fragment, null, thenChild.props.children) : null;
|
|
136
136
|
}
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if (matchedElseIf) {
|
|
142
|
-
return /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, matchedElseIf.props.children);
|
|
137
|
+
for (const elseIf of elseIfChildren) {
|
|
138
|
+
if (elseIf.props.condition) {
|
|
139
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, elseIf.props.children);
|
|
140
|
+
}
|
|
143
141
|
}
|
|
144
142
|
if (elseChild) {
|
|
145
|
-
return
|
|
143
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, elseChild.props.children);
|
|
146
144
|
}
|
|
147
145
|
return null;
|
|
148
146
|
};
|
package/package.json
CHANGED
package/src/Common/SizeBox.tsx
CHANGED
|
@@ -72,19 +72,14 @@ export const If = ({
|
|
|
72
72
|
return thenChild ? <>{thenChild.props.children}</> : null;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (matchedElseIf) {
|
|
81
|
-
return <>{matchedElseIf.props.children}</>;
|
|
75
|
+
for (const elseIf of elseIfChildren) {
|
|
76
|
+
if (elseIf.props.condition) {
|
|
77
|
+
return <>{elseIf.props.children}</>;
|
|
78
|
+
}
|
|
82
79
|
}
|
|
83
80
|
|
|
84
81
|
if (elseChild) {
|
|
85
|
-
return elseChild
|
|
86
|
-
<>{(elseChild as React.ReactElement<ElseProps>).props.children}</>
|
|
87
|
-
) : null;
|
|
82
|
+
return <>{(elseChild as React.ReactElement<ElseProps>).props.children}</>;
|
|
88
83
|
}
|
|
89
84
|
|
|
90
85
|
return null;
|