react-solidlike 2.1.0 → 2.2.0
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 +1 -1
- package/dist/index.cjs +0 -161
package/package.json
CHANGED
package/dist/index.cjs
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
let react = require("react");
|
|
2
|
-
let react_jsx_runtime = require("react/jsx-runtime");
|
|
3
|
-
|
|
4
|
-
function Await({ promise, loading = null, error = null, children }) {
|
|
5
|
-
const [state, setState] = (0, react.useState)(() => {
|
|
6
|
-
if (!(promise instanceof Promise)) return {
|
|
7
|
-
status: "fulfilled",
|
|
8
|
-
value: promise
|
|
9
|
-
};
|
|
10
|
-
return { status: "pending" };
|
|
11
|
-
});
|
|
12
|
-
(0, react.useEffect)(() => {
|
|
13
|
-
if (!(promise instanceof Promise)) {
|
|
14
|
-
setState({
|
|
15
|
-
status: "fulfilled",
|
|
16
|
-
value: promise
|
|
17
|
-
});
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
setState({ status: "pending" });
|
|
21
|
-
let cancelled = false;
|
|
22
|
-
promise.then((value) => {
|
|
23
|
-
if (!cancelled) setState({
|
|
24
|
-
status: "fulfilled",
|
|
25
|
-
value
|
|
26
|
-
});
|
|
27
|
-
}).catch((err) => {
|
|
28
|
-
if (!cancelled) setState({
|
|
29
|
-
status: "rejected",
|
|
30
|
-
error: err
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
return () => {
|
|
34
|
-
cancelled = true;
|
|
35
|
-
};
|
|
36
|
-
}, [promise]);
|
|
37
|
-
if (state.status === "pending") return loading;
|
|
38
|
-
if (state.status === "rejected") {
|
|
39
|
-
if (typeof error === "function") return error(state.error);
|
|
40
|
-
return error;
|
|
41
|
-
}
|
|
42
|
-
if (typeof children === "function") return children(state.value);
|
|
43
|
-
return children;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function Dynamic({ component, fallback = null, ...props }) {
|
|
47
|
-
if (!component) return fallback;
|
|
48
|
-
return (0, react.createElement)(component, props);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
var ErrorBoundary = class extends react.Component {
|
|
52
|
-
constructor(props) {
|
|
53
|
-
super(props);
|
|
54
|
-
this.state = { error: null };
|
|
55
|
-
}
|
|
56
|
-
static getDerivedStateFromError(error) {
|
|
57
|
-
return { error };
|
|
58
|
-
}
|
|
59
|
-
componentDidCatch(error, errorInfo) {
|
|
60
|
-
this.props.onError?.(error, errorInfo);
|
|
61
|
-
}
|
|
62
|
-
componentDidUpdate(prevProps) {
|
|
63
|
-
if (this.state.error && prevProps.resetKey !== this.props.resetKey) this.reset();
|
|
64
|
-
}
|
|
65
|
-
reset = () => {
|
|
66
|
-
this.setState({ error: null });
|
|
67
|
-
};
|
|
68
|
-
render() {
|
|
69
|
-
const { error } = this.state;
|
|
70
|
-
const { fallback, children } = this.props;
|
|
71
|
-
if (error) {
|
|
72
|
-
if (typeof fallback === "function") return fallback(error, this.reset);
|
|
73
|
-
return fallback;
|
|
74
|
-
}
|
|
75
|
-
return children;
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
function For({ each, children, keyExtractor, fallback = null }) {
|
|
80
|
-
if (!each || each.length === 0) return fallback;
|
|
81
|
-
return each.map((item, index) => {
|
|
82
|
-
const key = keyExtractor ? keyExtractor(item, index) : index;
|
|
83
|
-
return (0, react_jsx_runtime.jsx)(react.Fragment, { children: children(item, index) }, key);
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function defaultIsEmpty(data) {
|
|
88
|
-
if (data == null) return true;
|
|
89
|
-
if (Array.isArray(data)) return data.length === 0;
|
|
90
|
-
if (typeof data === "object") return Object.keys(data).length === 0;
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function QueryBoundary({ query, loading = null, error = null, empty = null, children, isEmptyFn = defaultIsEmpty }) {
|
|
95
|
-
if (!query) return null;
|
|
96
|
-
const { data, isPending, isError, isEmpty: queryIsEmpty } = query;
|
|
97
|
-
if (isPending) return loading;
|
|
98
|
-
if (isError && isEmptyFn(data)) return error;
|
|
99
|
-
if (queryIsEmpty ?? isEmptyFn(data)) return empty;
|
|
100
|
-
if (typeof children === "function") return children(data);
|
|
101
|
-
return children;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function Repeat({ times, children }) {
|
|
105
|
-
if (times <= 0) return null;
|
|
106
|
-
const elements = [];
|
|
107
|
-
for (let i = 0; i < times; i++) elements.push( (0, react_jsx_runtime.jsx)(react.Fragment, { children: children(i) }, i));
|
|
108
|
-
return elements;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function Show({ when, children, fallback = null }) {
|
|
112
|
-
if (!when) return fallback;
|
|
113
|
-
if (typeof children === "function") return children(when);
|
|
114
|
-
return children;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function Match(_props) {
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function Default(_props) {
|
|
122
|
-
return null;
|
|
123
|
-
}
|
|
124
|
-
Match.__isMatch = true;
|
|
125
|
-
Default.__isDefault = true;
|
|
126
|
-
function isMatchElement(child) {
|
|
127
|
-
return child !== null && typeof child === "object" && "type" in child && typeof child.type === "function" && "__isMatch" in child.type && child.type.__isMatch === true;
|
|
128
|
-
}
|
|
129
|
-
function isDefaultElement(child) {
|
|
130
|
-
return child !== null && typeof child === "object" && "type" in child && typeof child.type === "function" && "__isDefault" in child.type && child.type.__isDefault === true;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function Switch({ children, fallback = null }) {
|
|
134
|
-
const childArray = react.Children.toArray(children);
|
|
135
|
-
let defaultContent = fallback;
|
|
136
|
-
for (const child of childArray) {
|
|
137
|
-
if (isDefaultElement(child)) {
|
|
138
|
-
defaultContent = child.props.children;
|
|
139
|
-
continue;
|
|
140
|
-
}
|
|
141
|
-
if (isMatchElement(child)) {
|
|
142
|
-
const { when, children: matchChildren } = child.props;
|
|
143
|
-
if (when) {
|
|
144
|
-
if (typeof matchChildren === "function") return matchChildren(when);
|
|
145
|
-
return matchChildren;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return defaultContent;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
exports.Await = Await;
|
|
153
|
-
exports.Default = Default;
|
|
154
|
-
exports.Dynamic = Dynamic;
|
|
155
|
-
exports.ErrorBoundary = ErrorBoundary;
|
|
156
|
-
exports.For = For;
|
|
157
|
-
exports.Match = Match;
|
|
158
|
-
exports.QueryBoundary = QueryBoundary;
|
|
159
|
-
exports.Repeat = Repeat;
|
|
160
|
-
exports.Show = Show;
|
|
161
|
-
exports.Switch = Switch;
|