react-easy-loading 0.1.1 → 0.3.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/README.md +34 -8
- package/dist/create-loading.d.ts +8 -0
- package/dist/create-loading.d.ts.map +1 -1
- package/dist/create-local-loading.d.ts +3 -0
- package/dist/create-local-loading.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/main.esm.js +297 -422
- package/dist/main.min.js +2 -7
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -106,6 +106,31 @@ function Avatar() {
|
|
|
106
106
|
}
|
|
107
107
|
```
|
|
108
108
|
|
|
109
|
+
## Local Loading State
|
|
110
|
+
|
|
111
|
+
Sometimes you want a loading state that is tied to the lifecycle of a component
|
|
112
|
+
(just like useState).
|
|
113
|
+
`useCreateLocalLoading` creates a loading instance that is automatically destroyed when the component unmounts.
|
|
114
|
+
|
|
115
|
+
```javascript
|
|
116
|
+
import { useCreateLocalLoading } from 'react-easy-loading';
|
|
117
|
+
|
|
118
|
+
function MyComponent() {
|
|
119
|
+
const loading = useCreateLocalLoading();
|
|
120
|
+
// You can pass options or just the initial state (by default it's loading)
|
|
121
|
+
//const loading = useCreateLocalLoading('idle');
|
|
122
|
+
|
|
123
|
+
// Use it just like a regular loading instance
|
|
124
|
+
const isLoading = loading.useIsLoading();
|
|
125
|
+
|
|
126
|
+
return (
|
|
127
|
+
<div>
|
|
128
|
+
{isLoading ? 'Loading...' : 'Done'}
|
|
129
|
+
</div>
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
109
134
|
## ✨ Automatic State Management with `wrap`
|
|
110
135
|
|
|
111
136
|
The `wrap` function automates state management.
|
|
@@ -269,14 +294,15 @@ Use these to get the current value without subscribing to updates.
|
|
|
269
294
|
|
|
270
295
|
Use these to control the state from anywhere.
|
|
271
296
|
|
|
272
|
-
| Method | Description
|
|
273
|
-
|
|
274
|
-
| `set(state)` | Manually sets the loading state.
|
|
275
|
-
| `reset()` | Resets the state to its initial value.
|
|
276
|
-
| `retry()` | Re-runs the last wrapped async function.
|
|
277
|
-
| `setRetry(fn)` | Manually provides a custom retry function.
|
|
278
|
-
| `setErrors(errors)` | Overwrites the errors array.
|
|
279
|
-
| `addError(error)` | Adds an error to the errors array.
|
|
297
|
+
| Method | Description |
|
|
298
|
+
|---------------------|-----------------------------------------------------|
|
|
299
|
+
| `set(state)` | Manually sets the loading state. |
|
|
300
|
+
| `reset()` | Resets the state to its initial value. |
|
|
301
|
+
| `retry()` | Re-runs the last wrapped async function. |
|
|
302
|
+
| `setRetry(fn)` | Manually provides a custom retry function. |
|
|
303
|
+
| `setErrors(errors)` | Overwrites the errors array. |
|
|
304
|
+
| `addError(error)` | Adds an error to the errors array. |
|
|
305
|
+
| `destroy()` | Destroys the loading instance and clears its state. |
|
|
280
306
|
|
|
281
307
|
---
|
|
282
308
|
|
package/dist/create-loading.d.ts
CHANGED
|
@@ -57,6 +57,14 @@ export type Loading<Errors extends unknown[] = string[], Context extends Record<
|
|
|
57
57
|
ShowWhen: React.FC<PropsWithChildren<{
|
|
58
58
|
state: LoadingState;
|
|
59
59
|
}>>;
|
|
60
|
+
destroy: () => void;
|
|
61
|
+
/**
|
|
62
|
+
* @internal THIS IS USED FOR INTERNAL PURPOSES ONLY,
|
|
63
|
+
* DON'T USE IT,
|
|
64
|
+
* DON'T RELY ON IT,
|
|
65
|
+
* DON'T REPORT ANY ISSUE RELATED TO IT
|
|
66
|
+
*/
|
|
67
|
+
__get__id: () => string;
|
|
60
68
|
};
|
|
61
69
|
export type CreateLoadingOptions = {
|
|
62
70
|
initialState?: LoadingState;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-loading.d.ts","sourceRoot":"","sources":["../src/create-loading.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAC,KAAK,iBAAiB,EAAE,KAAK,SAAS,EAAC,MAAM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K,CAAC,EAAE,CAAC,iBAAiB,CAAC;QAAE,KAAK,EAAE,YAAY,CAAA;KAAE,CAAC,CAAC,CAAC;IAC/D,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB;;;;;OAKG;IACH,SAAS,EAAE,MAAM,MAAM,CAAC;CAC3B,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG;IAC/B,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,eAAe,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAClC,oBAAoB,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACvC,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;CAC7B,CAAA;AAGD,eAAO,MAAM,aAAa,GAAI,MAAM,SAAS,OAAO,EAAE,GAAG,MAAM,EAAE,EAAE,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,GAAG,EAAE,wEAKG,oBAAyB,KAAG,OAAO,CAAC,MAAM,EAAE,OAAO,CAsMvK,CAAA"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { CreateLoadingOptions, Loading } from './create-loading';
|
|
2
|
+
export declare const useCreateLocalLoading: <Errors extends unknown[] = string[], Context extends Record<string, unknown> = any>(createLoadingOptions?: CreateLoadingOptions | CreateLoadingOptions["initialState"]) => Loading<Errors, Context>;
|
|
3
|
+
//# sourceMappingURL=create-local-loading.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-local-loading.d.ts","sourceRoot":"","sources":["../src/create-local-loading.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,oBAAoB,EAAE,KAAK,OAAO,EAAC,MAAM,kBAAkB,CAAC;AAGxF,eAAO,MAAM,qBAAqB,GAAI,MAAM,SAAS,OAAO,EAAE,GAAG,MAAM,EAAE,EAAE,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,GAAG,EAAE,uBAAsB,oBAAoB,GAAC,oBAAoB,CAAC,cAAc,CAAM,KAAG,OAAO,CAAC,MAAM,EAAE,OAAO,CAYvO,CAAA"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC"}
|
package/dist/main.esm.js
CHANGED
|
@@ -1,570 +1,445 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* react-easy-loading v0.
|
|
2
|
+
* react-easy-loading v0.3.0
|
|
3
3
|
* (c) Hichem Taboukouyout
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
* Github: github.com/HichemTab-tech/react-easy-loading
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { jsx as p, jsxs as
|
|
9
|
-
import { createContext as
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
},
|
|
13
|
-
C[
|
|
8
|
+
import { jsx as p, jsxs as $, Fragment as w } from "react/jsx-runtime";
|
|
9
|
+
import { createContext as F, useEffect as O, useRef as j, useMemo as D, useSyncExternalStore as W, useContext as z } from "react";
|
|
10
|
+
const k = {}, C = {}, se = (o, e) => {
|
|
11
|
+
k[o] = e;
|
|
12
|
+
}, ne = (o, e) => {
|
|
13
|
+
C[o] = e;
|
|
14
14
|
};
|
|
15
|
-
let
|
|
15
|
+
let V = /* @__PURE__ */ p("div", { children: "Loading..." }), R = (o, e) => /* @__PURE__ */ $("div", { children: [
|
|
16
16
|
/* @__PURE__ */ p("h3", { children: "Errors:" }),
|
|
17
|
-
/* @__PURE__ */ p("ul", { children:
|
|
17
|
+
/* @__PURE__ */ p("ul", { children: o?.map((s, i) => /* @__PURE__ */ p("li", { children: s }, i)) }),
|
|
18
18
|
/* @__PURE__ */ p("button", { onClick: e, disabled: !e, children: "Retry" })
|
|
19
19
|
] });
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
},
|
|
23
|
-
R =
|
|
24
|
-
},
|
|
25
|
-
function B(
|
|
26
|
-
return
|
|
20
|
+
const ie = (o) => {
|
|
21
|
+
V = o;
|
|
22
|
+
}, ae = (o) => {
|
|
23
|
+
R = o;
|
|
24
|
+
}, I = () => V, K = () => R, P = (o, e) => M(I, k, o, e);
|
|
25
|
+
function B(o, e) {
|
|
26
|
+
return M(K, C, o, e);
|
|
27
27
|
}
|
|
28
|
-
function
|
|
29
|
-
return
|
|
28
|
+
function M(o, e, s, i) {
|
|
29
|
+
return i ? typeof i == "string" ? e[i] ?? i : i : i === null ? null : s ? typeof s == "string" ? e[s] ?? s : s : o();
|
|
30
30
|
}
|
|
31
|
-
function
|
|
32
|
-
return typeof
|
|
31
|
+
function L(o, ...e) {
|
|
32
|
+
return typeof o == "function" ? o(...e) : o;
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (!a) throw new Error("Value is empty");
|
|
43
|
-
return a;
|
|
44
|
-
}, N = () => Math.random().toString(36).substring(2, 15), q = $(void 0), G = () => K(q), A = [];
|
|
45
|
-
class c {
|
|
46
|
-
data = /* @__PURE__ */ new Map();
|
|
47
|
-
defaultValue() {
|
|
48
|
-
return {};
|
|
49
|
-
}
|
|
50
|
-
addListener(e, t, r) {
|
|
51
|
-
this.data.has(c.prefix(e, t)) || this.data.set(c.prefix(e, t), {
|
|
52
|
-
...this.defaultValue(),
|
|
53
|
-
listeners: []
|
|
54
|
-
}), this.data.get(c.prefix(e, t)).listeners.push(r);
|
|
55
|
-
}
|
|
56
|
-
removeListener(e, t, r) {
|
|
57
|
-
this.data.has(c.prefix(e, t)) && (this.data.get(c.prefix(e, t)).listeners = this.data.get(c.prefix(e, t)).listeners.filter((s) => s !== r));
|
|
58
|
-
}
|
|
59
|
-
callListeners(e, t) {
|
|
60
|
-
this.data.has(c.prefix(e, t)) && this.data.get(c.prefix(e, t)).listeners.forEach((r) => r());
|
|
34
|
+
const U = (...o) => {
|
|
35
|
+
}, b = (o) => {
|
|
36
|
+
if (!o) throw new Error("Value is empty");
|
|
37
|
+
return o;
|
|
38
|
+
}, q = () => Math.random().toString(36).substring(2, 15), N = F(void 0), T = () => z(N), A = [];
|
|
39
|
+
class d {
|
|
40
|
+
constructor(e = () => null) {
|
|
41
|
+
this.defaultValue = e;
|
|
61
42
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
43
|
+
data = /* @__PURE__ */ new Map();
|
|
44
|
+
addListener(e, s, i) {
|
|
45
|
+
const r = d.prefix(e, s), t = this.data.get(r);
|
|
46
|
+
t && t.listeners.push(i);
|
|
47
|
+
}
|
|
48
|
+
removeListener(e, s, i) {
|
|
49
|
+
const r = d.prefix(e, s), t = this.data.get(r);
|
|
50
|
+
t && (t.listeners = t.listeners.filter((a) => a !== i));
|
|
51
|
+
}
|
|
52
|
+
callListeners(e, s) {
|
|
53
|
+
const i = d.prefix(e, s), r = this.data.get(i);
|
|
54
|
+
r && r.listeners.forEach((t) => t());
|
|
55
|
+
}
|
|
56
|
+
init(e, s, i, r = !1) {
|
|
57
|
+
const t = d.prefix(e, s);
|
|
58
|
+
this.data.has(t) || this.data.set(t, {
|
|
59
|
+
value: i,
|
|
60
|
+
isStatic: r || void 0,
|
|
66
61
|
listeners: []
|
|
67
62
|
});
|
|
68
63
|
}
|
|
69
|
-
createStatic(e,
|
|
70
|
-
const r =
|
|
71
|
-
key:
|
|
64
|
+
createStatic(e, s, i) {
|
|
65
|
+
const r = i ?? "_global", t = {
|
|
66
|
+
key: q(),
|
|
72
67
|
prefix: r,
|
|
73
68
|
...e
|
|
74
69
|
};
|
|
75
|
-
return A.push(
|
|
70
|
+
return A.push(t), this.init(t.key, t.prefix, s, !0), this.defaultValue = () => s, t;
|
|
76
71
|
}
|
|
77
72
|
initStatic(e) {
|
|
78
|
-
const { key:
|
|
79
|
-
this.init(
|
|
73
|
+
const { key: s, prefix: i } = e;
|
|
74
|
+
this.init(s, i, this.defaultValue(), !0);
|
|
80
75
|
}
|
|
81
|
-
clearAll(e = !1,
|
|
82
|
-
this.data.forEach((
|
|
83
|
-
const [
|
|
84
|
-
this.clear(
|
|
76
|
+
clearAll(e = !1, s = !1) {
|
|
77
|
+
this.data.forEach((i, r) => {
|
|
78
|
+
const [t, a] = d.extractPrefix(r);
|
|
79
|
+
this.clear(a, t, e, s);
|
|
85
80
|
});
|
|
86
81
|
}
|
|
87
|
-
clear(e,
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const u = A.find((n) => n.key === e && n.prefix === t);
|
|
82
|
+
clear(e, s, i = !1, r = !1) {
|
|
83
|
+
const t = d.prefix(e, s);
|
|
84
|
+
i || this.callListeners(e, s);
|
|
85
|
+
const a = this.data.get(t);
|
|
86
|
+
if (a && (this.data.delete(t), a.isStatic && !r)) {
|
|
87
|
+
const u = A.find((n) => n.key === e && n.prefix === s);
|
|
94
88
|
u && this.initStatic(u);
|
|
95
89
|
}
|
|
96
90
|
}
|
|
97
|
-
get(e,
|
|
98
|
-
let
|
|
99
|
-
if (
|
|
100
|
-
return this.data.get(
|
|
91
|
+
get(e, s) {
|
|
92
|
+
let i = this.has(e, s);
|
|
93
|
+
if (i)
|
|
94
|
+
return this.data.get(i);
|
|
101
95
|
}
|
|
102
|
-
setValue(e,
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
...r
|
|
106
|
-
});
|
|
96
|
+
setValue(e, s, i) {
|
|
97
|
+
const r = d.prefix(e, s), t = this.data.get(r);
|
|
98
|
+
t && (t.value = i, this.data.set(r, t));
|
|
107
99
|
}
|
|
108
|
-
has(e,
|
|
109
|
-
return this.data.has(
|
|
100
|
+
has(e, s) {
|
|
101
|
+
return this.data.has(d.prefix(e, s)) ? d.prefix(e, s) : this.data.has(d.prefix(e, "_global")) ? d.prefix(e, "_global") : void 0;
|
|
110
102
|
}
|
|
111
|
-
static prefix(e,
|
|
103
|
+
static prefix(e, s) {
|
|
112
104
|
if (e.includes("//")) throw new Error("key cannot contain '//'");
|
|
113
|
-
return `${
|
|
105
|
+
return `${s}//${e}`;
|
|
114
106
|
}
|
|
115
107
|
static extractPrefix(e) {
|
|
116
|
-
|
|
108
|
+
const s = e.split("//");
|
|
109
|
+
return [s[0], s.slice(1).join("//")];
|
|
117
110
|
}
|
|
118
|
-
useEffect(e,
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
111
|
+
useEffect(e, s, i = null) {
|
|
112
|
+
O(() => () => {
|
|
113
|
+
i?.(), U(`[${d.prefix(e, s)}]`, "unmount effect");
|
|
114
|
+
const r = this.get(e, s);
|
|
115
|
+
r && r.listeners?.length === 0 && this.clear(e, s);
|
|
116
|
+
}, [e, s]);
|
|
122
117
|
}
|
|
123
118
|
}
|
|
124
|
-
class
|
|
119
|
+
class G {
|
|
125
120
|
constructor(e) {
|
|
126
121
|
this.sharedData = e;
|
|
127
122
|
}
|
|
128
|
-
|
|
129
|
-
let
|
|
123
|
+
_get(e, s) {
|
|
124
|
+
let i, r = s;
|
|
130
125
|
if (typeof e != "string") {
|
|
131
|
-
const { key:
|
|
132
|
-
|
|
126
|
+
const { key: u, prefix: n } = e;
|
|
127
|
+
i = u, r = n;
|
|
133
128
|
} else
|
|
134
|
-
|
|
135
|
-
const
|
|
136
|
-
return
|
|
129
|
+
i = b(e);
|
|
130
|
+
const t = r || "_global", a = this.sharedData.get(i, t);
|
|
131
|
+
return a ? { value: a.value, key: i, prefix: t } : {
|
|
132
|
+
key: i,
|
|
133
|
+
prefix: t,
|
|
134
|
+
value: void 0
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
get(e, s) {
|
|
138
|
+
return this._get(e, s).value;
|
|
137
139
|
}
|
|
138
|
-
set(e,
|
|
139
|
-
let
|
|
140
|
+
set(e, s, i) {
|
|
141
|
+
let r, t = i;
|
|
140
142
|
if (typeof e != "string") {
|
|
141
143
|
const { key: u, prefix: n } = e;
|
|
142
|
-
|
|
144
|
+
r = u, t = n;
|
|
143
145
|
} else
|
|
144
|
-
|
|
145
|
-
const
|
|
146
|
-
this.sharedData.init(
|
|
147
|
-
}
|
|
148
|
-
update(e,
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
146
|
+
r = b(e);
|
|
147
|
+
const a = t || "_global";
|
|
148
|
+
this.sharedData.init(r, a, s), this.sharedData.setValue(r, a, s), this.sharedData.callListeners(r, a);
|
|
149
|
+
}
|
|
150
|
+
update(e, s, i) {
|
|
151
|
+
const r = this._get(e, i);
|
|
152
|
+
if (r) {
|
|
153
|
+
const t = s(r.value);
|
|
154
|
+
this.set(r.key, t, r.prefix);
|
|
155
|
+
}
|
|
153
156
|
}
|
|
154
|
-
/**
|
|
155
|
-
* clear all values from the shared data
|
|
156
|
-
*/
|
|
157
157
|
clearAll() {
|
|
158
158
|
this.sharedData.clearAll();
|
|
159
159
|
}
|
|
160
|
-
/**
|
|
161
|
-
* clear all values from the shared data in a scope
|
|
162
|
-
* @param scopeName
|
|
163
|
-
*/
|
|
164
160
|
clearScope(e) {
|
|
165
|
-
const
|
|
166
|
-
this.sharedData.data.forEach((
|
|
167
|
-
const [
|
|
168
|
-
|
|
169
|
-
this.sharedData.clear(o, i), this.sharedData.callListeners(o, i);
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
161
|
+
const s = e || "_global";
|
|
162
|
+
this.sharedData.data.forEach((i, r) => {
|
|
163
|
+
const [t, a] = d.extractPrefix(r);
|
|
164
|
+
t === s && (this.sharedData.clear(a, t), this.sharedData.callListeners(a, t));
|
|
172
165
|
});
|
|
173
166
|
}
|
|
174
|
-
/**
|
|
175
|
-
* resolve a shared created object to a value
|
|
176
|
-
* @param sharedCreated
|
|
177
|
-
*/
|
|
178
167
|
resolve(e) {
|
|
179
|
-
const { key:
|
|
180
|
-
return this.get(
|
|
168
|
+
const { key: s, prefix: i } = e;
|
|
169
|
+
return this.get(s, i);
|
|
181
170
|
}
|
|
182
|
-
clear(e,
|
|
183
|
-
let
|
|
184
|
-
typeof e == "string" ? (
|
|
171
|
+
clear(e, s) {
|
|
172
|
+
let i, r;
|
|
173
|
+
typeof e == "string" ? (i = e, r = s || "_global") : (i = e.key, r = e.prefix), this.sharedData.clear(i, r);
|
|
185
174
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
* @param scopeName
|
|
190
|
-
*/
|
|
191
|
-
has(e, t = "_global") {
|
|
192
|
-
const r = t || "_global";
|
|
193
|
-
return !!this.sharedData.has(e, r);
|
|
175
|
+
has(e, s = "_global") {
|
|
176
|
+
const i = s || "_global";
|
|
177
|
+
return !!this.sharedData.has(e, i);
|
|
194
178
|
}
|
|
195
|
-
/**
|
|
196
|
-
* get all values from the shared data
|
|
197
|
-
*/
|
|
198
179
|
getAll() {
|
|
199
180
|
const e = {};
|
|
200
|
-
return this.sharedData.data.forEach((
|
|
201
|
-
const [
|
|
202
|
-
e[
|
|
181
|
+
return this.sharedData.data.forEach((s, i) => {
|
|
182
|
+
const [r, t] = d.extractPrefix(i);
|
|
183
|
+
e[r] = e[r] || {}, e[r][t] = s.value;
|
|
203
184
|
}), e;
|
|
204
185
|
}
|
|
205
|
-
subscribe(e,
|
|
206
|
-
let
|
|
207
|
-
return typeof e == "string" ? (
|
|
208
|
-
this.sharedData.removeListener(
|
|
186
|
+
subscribe(e, s, i) {
|
|
187
|
+
let r, t;
|
|
188
|
+
return typeof e == "string" ? (r = e, t = i || "_global") : (r = e.key, t = e.prefix), this.sharedData.addListener(r, t, s), () => {
|
|
189
|
+
this.sharedData.removeListener(r, t, s);
|
|
209
190
|
};
|
|
210
191
|
}
|
|
211
192
|
}
|
|
212
|
-
const H = (
|
|
213
|
-
const e =
|
|
193
|
+
const H = (o) => {
|
|
194
|
+
const e = T();
|
|
214
195
|
return {
|
|
215
|
-
prefix:
|
|
196
|
+
prefix: o ?? e?.scopeName ?? "_global"
|
|
216
197
|
};
|
|
217
198
|
};
|
|
218
|
-
function J(
|
|
219
|
-
return
|
|
199
|
+
function J(o) {
|
|
200
|
+
return o && o.__esModule && Object.prototype.hasOwnProperty.call(o, "default") ? o.default : o;
|
|
220
201
|
}
|
|
221
|
-
var
|
|
202
|
+
var S, _;
|
|
222
203
|
function Q() {
|
|
223
|
-
if (
|
|
224
|
-
|
|
225
|
-
var
|
|
226
|
-
function
|
|
227
|
-
if (
|
|
228
|
-
if (
|
|
229
|
-
if (
|
|
230
|
-
var u, n,
|
|
231
|
-
if (Array.isArray(
|
|
232
|
-
if (u =
|
|
204
|
+
if (_) return S;
|
|
205
|
+
_ = 1;
|
|
206
|
+
var o = typeof Element < "u", e = typeof Map == "function", s = typeof Set == "function", i = typeof ArrayBuffer == "function" && !!ArrayBuffer.isView;
|
|
207
|
+
function r(t, a) {
|
|
208
|
+
if (t === a) return !0;
|
|
209
|
+
if (t && a && typeof t == "object" && typeof a == "object") {
|
|
210
|
+
if (t.constructor !== a.constructor) return !1;
|
|
211
|
+
var u, n, f;
|
|
212
|
+
if (Array.isArray(t)) {
|
|
213
|
+
if (u = t.length, u != a.length) return !1;
|
|
233
214
|
for (n = u; n-- !== 0; )
|
|
234
|
-
if (!
|
|
215
|
+
if (!r(t[n], a[n])) return !1;
|
|
235
216
|
return !0;
|
|
236
217
|
}
|
|
237
|
-
var
|
|
238
|
-
if (e &&
|
|
239
|
-
if (
|
|
240
|
-
for (
|
|
241
|
-
if (!
|
|
242
|
-
for (
|
|
243
|
-
if (!
|
|
218
|
+
var c;
|
|
219
|
+
if (e && t instanceof Map && a instanceof Map) {
|
|
220
|
+
if (t.size !== a.size) return !1;
|
|
221
|
+
for (c = t.entries(); !(n = c.next()).done; )
|
|
222
|
+
if (!a.has(n.value[0])) return !1;
|
|
223
|
+
for (c = t.entries(); !(n = c.next()).done; )
|
|
224
|
+
if (!r(n.value[1], a.get(n.value[0]))) return !1;
|
|
244
225
|
return !0;
|
|
245
226
|
}
|
|
246
|
-
if (
|
|
247
|
-
if (
|
|
248
|
-
for (
|
|
249
|
-
if (!
|
|
227
|
+
if (s && t instanceof Set && a instanceof Set) {
|
|
228
|
+
if (t.size !== a.size) return !1;
|
|
229
|
+
for (c = t.entries(); !(n = c.next()).done; )
|
|
230
|
+
if (!a.has(n.value[0])) return !1;
|
|
250
231
|
return !0;
|
|
251
232
|
}
|
|
252
|
-
if (
|
|
253
|
-
if (u =
|
|
233
|
+
if (i && ArrayBuffer.isView(t) && ArrayBuffer.isView(a)) {
|
|
234
|
+
if (u = t.length, u != a.length) return !1;
|
|
254
235
|
for (n = u; n-- !== 0; )
|
|
255
|
-
if (
|
|
236
|
+
if (t[n] !== a[n]) return !1;
|
|
256
237
|
return !0;
|
|
257
238
|
}
|
|
258
|
-
if (
|
|
259
|
-
if (
|
|
260
|
-
if (
|
|
261
|
-
if (
|
|
239
|
+
if (t.constructor === RegExp) return t.source === a.source && t.flags === a.flags;
|
|
240
|
+
if (t.valueOf !== Object.prototype.valueOf && typeof t.valueOf == "function" && typeof a.valueOf == "function") return t.valueOf() === a.valueOf();
|
|
241
|
+
if (t.toString !== Object.prototype.toString && typeof t.toString == "function" && typeof a.toString == "function") return t.toString() === a.toString();
|
|
242
|
+
if (f = Object.keys(t), u = f.length, u !== Object.keys(a).length) return !1;
|
|
262
243
|
for (n = u; n-- !== 0; )
|
|
263
|
-
if (!Object.prototype.hasOwnProperty.call(
|
|
264
|
-
if (
|
|
244
|
+
if (!Object.prototype.hasOwnProperty.call(a, f[n])) return !1;
|
|
245
|
+
if (o && t instanceof Element) return !1;
|
|
265
246
|
for (n = u; n-- !== 0; )
|
|
266
|
-
if (!((
|
|
247
|
+
if (!((f[n] === "_owner" || f[n] === "__v" || f[n] === "__o") && t.$$typeof) && !r(t[f[n]], a[f[n]]))
|
|
267
248
|
return !1;
|
|
268
249
|
return !0;
|
|
269
250
|
}
|
|
270
|
-
return
|
|
251
|
+
return t !== t && a !== a;
|
|
271
252
|
}
|
|
272
|
-
return
|
|
253
|
+
return S = function(t, a) {
|
|
273
254
|
try {
|
|
274
|
-
return
|
|
255
|
+
return r(t, a);
|
|
275
256
|
} catch (u) {
|
|
276
257
|
if ((u.message || "").match(/stack|recursion/i))
|
|
277
258
|
return console.warn("react-fast-compare cannot handle circular refs"), !1;
|
|
278
259
|
throw u;
|
|
279
260
|
}
|
|
280
|
-
},
|
|
261
|
+
}, S;
|
|
281
262
|
}
|
|
282
263
|
var X = Q();
|
|
283
|
-
const Y = /* @__PURE__ */ J(X);
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
super.init(e, t, { value: r }, s);
|
|
290
|
-
}
|
|
291
|
-
initStatic(e) {
|
|
292
|
-
const { key: t, prefix: r, initialValue: s } = e;
|
|
293
|
-
this.initValue(t, r, s, !0);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
class ee extends V {
|
|
297
|
-
constructor(e) {
|
|
298
|
-
super(e);
|
|
299
|
-
}
|
|
300
|
-
get(e, t = "_global") {
|
|
301
|
-
return typeof e != "string" ? super.get(e)?.value : super.get(e, t)?.value;
|
|
302
|
-
}
|
|
303
|
-
set(e, t, r = "_global") {
|
|
304
|
-
if (typeof e != "string") {
|
|
305
|
-
super.set(e, { value: t });
|
|
306
|
-
return;
|
|
307
|
-
}
|
|
308
|
-
super.set(e, { value: t }, r);
|
|
309
|
-
}
|
|
310
|
-
update(e, t, r = "_global") {
|
|
311
|
-
let s;
|
|
312
|
-
typeof e == "string" ? s = this.get(e, r) : s = this.get(e);
|
|
313
|
-
const i = t(s);
|
|
314
|
-
typeof e == "string" ? this.set(e, i, r) : this.set(e, i);
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
const E = new Z(), g = new ee(E), te = (a, e) => E.createStatic({ initialValue: a }, e);
|
|
318
|
-
function v(a, e, t) {
|
|
319
|
-
let r, s = t;
|
|
320
|
-
if (typeof a != "string") {
|
|
321
|
-
const { key: f, prefix: h } = a;
|
|
322
|
-
r = f, s = h;
|
|
264
|
+
const Y = /* @__PURE__ */ J(X), x = new d(), h = new G(x), Z = (o, e) => x.createStatic({ initialValue: o }, o, e);
|
|
265
|
+
function E(o, e, s) {
|
|
266
|
+
let i, r = s;
|
|
267
|
+
if (typeof o != "string") {
|
|
268
|
+
const { key: c, prefix: l } = o;
|
|
269
|
+
i = c, r = l;
|
|
323
270
|
} else
|
|
324
|
-
|
|
325
|
-
const { prefix:
|
|
326
|
-
|
|
327
|
-
}), []), n = D(() => () => {
|
|
328
|
-
const
|
|
329
|
-
return Y(
|
|
330
|
-
}, []),
|
|
331
|
-
return
|
|
271
|
+
i = b(o);
|
|
272
|
+
const { prefix: t } = H(r), a = j(void 0), u = D(() => (c) => (x.init(i, t, void 0), x.addListener(i, t, c), () => {
|
|
273
|
+
x.removeListener(i, t, c);
|
|
274
|
+
}), [i, t]), n = D(() => () => {
|
|
275
|
+
const c = x.get(i, t)?.value, l = e(c);
|
|
276
|
+
return Y(a.current, l) ? a.current : (a.current = l, l);
|
|
277
|
+
}, [i, t, e]), f = W(u, n);
|
|
278
|
+
return x.useEffect(i, t), f;
|
|
332
279
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
return {
|
|
336
|
-
fnState: {
|
|
337
|
-
results: void 0,
|
|
338
|
-
isLoading: !1,
|
|
339
|
-
error: void 0
|
|
340
|
-
}
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
initValue(e, t, r = !1) {
|
|
344
|
-
super.init(e, t, this.defaultValue(), r);
|
|
345
|
-
}
|
|
346
|
-
setValue(e, t, r) {
|
|
347
|
-
super.setValue(e, t, r);
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
class se extends V {
|
|
351
|
-
constructor(e) {
|
|
352
|
-
super(e);
|
|
353
|
-
}
|
|
354
|
-
get(e, t = "_global") {
|
|
355
|
-
return typeof e != "string" ? super.get(e)?.fnState : super.get(e, t)?.fnState;
|
|
356
|
-
}
|
|
357
|
-
set(e, t, r = "_global") {
|
|
358
|
-
if (typeof e != "string") {
|
|
359
|
-
super.set(e, t);
|
|
360
|
-
return;
|
|
361
|
-
}
|
|
362
|
-
super.set(e, t, r);
|
|
363
|
-
}
|
|
364
|
-
update(e, t, r = "_global") {
|
|
365
|
-
let s;
|
|
366
|
-
typeof e == "string" ? s = this.get(e, r) : s = this.get(e);
|
|
367
|
-
const i = t(s);
|
|
368
|
-
typeof e == "string" ? this.set(e, i, r) : this.set(e, i);
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
const ie = new re();
|
|
372
|
-
new se(ie);
|
|
373
|
-
class ne extends c {
|
|
374
|
-
defaultValue() {
|
|
375
|
-
return {
|
|
376
|
-
fnState: {
|
|
377
|
-
data: void 0,
|
|
378
|
-
isLoading: !1,
|
|
379
|
-
error: void 0,
|
|
380
|
-
subscribed: !1
|
|
381
|
-
}
|
|
382
|
-
};
|
|
383
|
-
}
|
|
384
|
-
initValue(e, t, r = !1) {
|
|
385
|
-
super.init(e, t, this.defaultValue(), r);
|
|
386
|
-
}
|
|
387
|
-
setValue(e, t, r) {
|
|
388
|
-
super.setValue(e, t, r);
|
|
389
|
-
}
|
|
390
|
-
useEffect(e, t) {
|
|
391
|
-
j(() => () => {
|
|
392
|
-
M(`[${c.prefix(e, t)}]`, "unmount effect2"), this.get(e, t)?.listeners.length === 0 && this.unsubscribe(e, t);
|
|
393
|
-
}, []), super.useEffect(e, t);
|
|
394
|
-
}
|
|
395
|
-
async unsubscribe(e, t) {
|
|
396
|
-
const r = this.get(e, t);
|
|
397
|
-
r && (r.unsubscribe && (r.unsubscribe(), r.unsubscribe = void 0), r.fnState = { ...r.fnState, subscribed: !1 }, this.callListeners(e, t));
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
class ae extends V {
|
|
401
|
-
constructor(e) {
|
|
402
|
-
super(e);
|
|
403
|
-
}
|
|
404
|
-
get(e, t = "_global") {
|
|
405
|
-
return typeof e != "string" ? super.get(e)?.fnState : super.get(e, t)?.fnState;
|
|
406
|
-
}
|
|
407
|
-
set(e, t, r = "_global") {
|
|
408
|
-
if (typeof e != "string") {
|
|
409
|
-
super.set(e, t);
|
|
410
|
-
return;
|
|
411
|
-
}
|
|
412
|
-
super.set(e, t, r);
|
|
413
|
-
}
|
|
414
|
-
update(e, t, r = "_global") {
|
|
415
|
-
let s;
|
|
416
|
-
typeof e == "string" ? s = this.get(e, r) : s = this.get(e);
|
|
417
|
-
const i = t(s);
|
|
418
|
-
typeof e == "string" ? this.set(e, i, r) : this.set(e, i);
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
const oe = new ne();
|
|
422
|
-
new ae(oe);
|
|
423
|
-
const S = (a, e) => Array.isArray(e) && e.includes(a) || a === e, de = ({
|
|
424
|
-
initialState: a = "loading",
|
|
280
|
+
const m = (o, e) => Array.isArray(e) && e.includes(o) || o === e, ee = ({
|
|
281
|
+
initialState: o = "loading",
|
|
425
282
|
defaultFallback: e,
|
|
426
|
-
defaultErrorFallback:
|
|
427
|
-
defaultRetry:
|
|
283
|
+
defaultErrorFallback: s,
|
|
284
|
+
defaultRetry: i
|
|
428
285
|
} = {}) => {
|
|
429
|
-
const
|
|
430
|
-
state:
|
|
431
|
-
retry:
|
|
432
|
-
}),
|
|
433
|
-
let
|
|
434
|
-
return new Promise((
|
|
435
|
-
if (
|
|
436
|
-
|
|
286
|
+
const r = Z({
|
|
287
|
+
state: o,
|
|
288
|
+
retry: i
|
|
289
|
+
}), t = (n) => {
|
|
290
|
+
let f = u.get();
|
|
291
|
+
return new Promise((c, l) => {
|
|
292
|
+
if (m(u.get(), n)) {
|
|
293
|
+
c();
|
|
437
294
|
return;
|
|
438
295
|
}
|
|
439
|
-
const
|
|
440
|
-
|
|
296
|
+
const g = h.subscribe(r, () => {
|
|
297
|
+
m(u.get(), n) ? (g(), c()) : f !== u.get() && l();
|
|
441
298
|
});
|
|
442
299
|
});
|
|
443
|
-
},
|
|
444
|
-
return (
|
|
300
|
+
}, a = function(n, f = () => []) {
|
|
301
|
+
return (c) => E(r, (g) => m(g.state, n)) ? /* @__PURE__ */ p(w, { children: L(c.children, ...f()) }) : null;
|
|
445
302
|
}, u = {
|
|
446
303
|
//hooks
|
|
447
|
-
use: () =>
|
|
448
|
-
useIsLoading: () =>
|
|
449
|
-
useErrors: () =>
|
|
450
|
-
useContext: () =>
|
|
451
|
-
set: (n) =>
|
|
452
|
-
retry: (n) => (
|
|
304
|
+
use: () => E(r, (n) => n.state),
|
|
305
|
+
useIsLoading: () => E(r, (n) => n.state) === "loading",
|
|
306
|
+
useErrors: () => E(r, (n) => n.errors),
|
|
307
|
+
useContext: () => E(r, (n) => n.context),
|
|
308
|
+
set: (n) => h.update(r, (f) => ({ ...f, state: n })),
|
|
309
|
+
retry: (n) => (h.get(r).retry ?? n)?.(),
|
|
453
310
|
// getters
|
|
454
|
-
isLoading: () =>
|
|
455
|
-
isIdle: () =>
|
|
456
|
-
isSuccess: () =>
|
|
457
|
-
isError: () =>
|
|
458
|
-
isFinished: () =>
|
|
459
|
-
is: (n) =>
|
|
460
|
-
hasErrors: () =>
|
|
461
|
-
get: () =>
|
|
462
|
-
getErrors: () =>
|
|
463
|
-
getContext: () =>
|
|
311
|
+
isLoading: () => h.get(r).state === "loading",
|
|
312
|
+
isIdle: () => h.get(r).state === "idle",
|
|
313
|
+
isSuccess: () => h.get(r).state === "success",
|
|
314
|
+
isError: () => h.get(r).state === "error",
|
|
315
|
+
isFinished: () => h.get(r).state === "success" || h.get(r).state === "error",
|
|
316
|
+
is: (n) => m(u.get(), n),
|
|
317
|
+
hasErrors: () => h.get(r).errors !== void 0,
|
|
318
|
+
get: () => h.get(r).state,
|
|
319
|
+
getErrors: () => h.get(r).errors,
|
|
320
|
+
getContext: () => h.get(r).context,
|
|
464
321
|
// setters
|
|
465
|
-
reset: () =>
|
|
466
|
-
state:
|
|
322
|
+
reset: () => h.set(r, {
|
|
323
|
+
state: o
|
|
467
324
|
}),
|
|
468
325
|
addError: (n) => {
|
|
469
|
-
|
|
470
|
-
...
|
|
471
|
-
errors: [...
|
|
326
|
+
h.update(r, (f) => ({
|
|
327
|
+
...f,
|
|
328
|
+
errors: [...f.errors ?? [], n]
|
|
472
329
|
}));
|
|
473
330
|
},
|
|
474
331
|
setContext: (n) => {
|
|
475
|
-
|
|
332
|
+
h.update(r, (f) => ({ ...f, context: n }));
|
|
476
333
|
},
|
|
477
334
|
setErrors: (n) => {
|
|
478
|
-
|
|
335
|
+
h.update(r, (f) => ({ ...f, errors: n }));
|
|
479
336
|
},
|
|
480
337
|
clearErrors: () => {
|
|
481
|
-
|
|
338
|
+
h.update(r, (n) => ({ ...n, errors: void 0 }));
|
|
482
339
|
},
|
|
483
340
|
// set a retry function
|
|
484
|
-
setRetry: (n) =>
|
|
341
|
+
setRetry: (n) => h.update(r, (f) => ({ ...f, retry: n })),
|
|
485
342
|
// promises
|
|
486
|
-
whenLoaded: () =>
|
|
343
|
+
whenLoaded: () => t("success").catch((n) => {
|
|
487
344
|
throw new Error("loading failed", { cause: n });
|
|
488
345
|
}),
|
|
489
|
-
whenFinished: () =>
|
|
346
|
+
whenFinished: () => t(["success", "error"]),
|
|
490
347
|
// wrap a promise
|
|
491
348
|
wrap(n) {
|
|
492
|
-
const
|
|
493
|
-
u.clearErrors(), u.set("loading"), n().then((
|
|
494
|
-
u.set("success"),
|
|
495
|
-
}).catch((
|
|
496
|
-
u.set("error"),
|
|
349
|
+
const f = () => new Promise((c, l) => {
|
|
350
|
+
u.clearErrors(), u.set("loading"), n().then((g) => {
|
|
351
|
+
u.set("success"), c(g);
|
|
352
|
+
}).catch((g) => {
|
|
353
|
+
u.set("error"), g && u.setErrors([g]), l(g);
|
|
497
354
|
});
|
|
498
355
|
});
|
|
499
|
-
return u.setRetry(
|
|
356
|
+
return u.setRetry(f), f();
|
|
500
357
|
},
|
|
501
358
|
wrapWithControl(n) {
|
|
502
|
-
const
|
|
359
|
+
const f = {
|
|
503
360
|
thens: [],
|
|
504
361
|
catchs: [],
|
|
505
362
|
finallies: []
|
|
506
|
-
},
|
|
507
|
-
then: (...
|
|
508
|
-
catch_: (...
|
|
509
|
-
finally_: (...
|
|
510
|
-
start: () => new Promise((
|
|
363
|
+
}, c = {
|
|
364
|
+
then: (...l) => (f.thens.push(l), c),
|
|
365
|
+
catch_: (...l) => (f.catchs.push(l), c),
|
|
366
|
+
finally_: (...l) => (f.finallies.push(l), c),
|
|
367
|
+
start: () => new Promise((l, g) => {
|
|
511
368
|
u.clearErrors(), u.set("loading");
|
|
512
|
-
let
|
|
513
|
-
|
|
369
|
+
let v = n();
|
|
370
|
+
v.then(() => {
|
|
514
371
|
u.set("success");
|
|
515
|
-
}),
|
|
372
|
+
}), v.catch((y) => {
|
|
516
373
|
u.set("error"), y && u.setErrors([y]);
|
|
517
374
|
});
|
|
518
|
-
for (const y of
|
|
519
|
-
|
|
520
|
-
for (const y of
|
|
521
|
-
|
|
522
|
-
for (const y of
|
|
523
|
-
|
|
524
|
-
|
|
375
|
+
for (const y of f.thens)
|
|
376
|
+
v.then(...y);
|
|
377
|
+
for (const y of f.catchs)
|
|
378
|
+
v.catch(...y);
|
|
379
|
+
for (const y of f.finallies)
|
|
380
|
+
v.finally(...y);
|
|
381
|
+
v.then(l, g);
|
|
525
382
|
})
|
|
526
383
|
};
|
|
527
|
-
return u.setRetry(
|
|
384
|
+
return u.setRetry(c.start), c;
|
|
528
385
|
},
|
|
529
386
|
// components
|
|
530
387
|
// - show when
|
|
531
|
-
ShowWhenLoaded: ({ children: n, fallback:
|
|
532
|
-
const
|
|
533
|
-
return
|
|
388
|
+
ShowWhenLoaded: ({ children: n, fallback: f, errorFallback: c }) => {
|
|
389
|
+
const l = E(r, (g) => g.state);
|
|
390
|
+
return l === "idle" ? null : (f = P(e, f), c = B(s, c === !0 ? void 0 : c), l === "loading" ? /* @__PURE__ */ p(w, { children: f }) : l === "error" ? /* @__PURE__ */ p(w, { children: L(c, u.getErrors() ?? [], () => u.retry()) }) : /* @__PURE__ */ p(w, { children: n }));
|
|
534
391
|
},
|
|
535
|
-
ShowWhileLoading:
|
|
536
|
-
ShowWhenError:
|
|
537
|
-
ShowWhenFinish:
|
|
538
|
-
ShowWhen: ({ children: n, state:
|
|
539
|
-
const
|
|
540
|
-
return /* @__PURE__ */ p(
|
|
541
|
-
}
|
|
392
|
+
ShowWhileLoading: a("loading"),
|
|
393
|
+
ShowWhenError: a("error", () => [u.getErrors() ?? [], () => u.retry()]),
|
|
394
|
+
ShowWhenFinish: a(["error", "success"], () => [u.getErrors(), () => u.retry()]),
|
|
395
|
+
ShowWhen: ({ children: n, state: f }) => {
|
|
396
|
+
const c = a(f);
|
|
397
|
+
return /* @__PURE__ */ p(c, { children: n });
|
|
398
|
+
},
|
|
399
|
+
destroy: () => {
|
|
400
|
+
h.clear(r);
|
|
401
|
+
},
|
|
402
|
+
/**
|
|
403
|
+
* @internal THIS IS USED FOR INTERNAL PURPOSES ONLY,
|
|
404
|
+
* DON'T USE IT,
|
|
405
|
+
* DON'T RELY ON IT,
|
|
406
|
+
* DON'T REPORT ANY ISSUE RELATED TO IT
|
|
407
|
+
*/
|
|
408
|
+
__get__id: () => `loading_id//${r.prefix}/${r.key}`
|
|
542
409
|
};
|
|
543
410
|
return u;
|
|
544
|
-
},
|
|
545
|
-
const
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
411
|
+
}, oe = (o = {}) => {
|
|
412
|
+
const e = j(ee(typeof o == "string" ? {
|
|
413
|
+
initialState: o
|
|
414
|
+
} : o));
|
|
415
|
+
return O(() => () => {
|
|
416
|
+
e.current.destroy();
|
|
417
|
+
}, []), e.current;
|
|
418
|
+
}, ue = ({ of: o, fallback: e, errorFallback: s, children: i }) => {
|
|
419
|
+
const r = o.map((t) => t.use());
|
|
420
|
+
return e = P(void 0, e), r.some((t) => t === "loading") ? e : r.every((t) => t !== "loading") ? r.some((t) => t === "error") ? (s = B(void 0, s), /* @__PURE__ */ p(w, { children: L(
|
|
421
|
+
s,
|
|
422
|
+
o.reduce((t, a) => [...t, ...a.getErrors() ?? []], []),
|
|
549
423
|
() => {
|
|
550
|
-
|
|
551
|
-
|
|
424
|
+
o.map((t) => {
|
|
425
|
+
t.isError() && t.retry();
|
|
552
426
|
});
|
|
553
427
|
}
|
|
554
|
-
) })) : /* @__PURE__ */ p(
|
|
428
|
+
) })) : /* @__PURE__ */ p(w, { children: i }) : null;
|
|
555
429
|
};
|
|
556
430
|
export {
|
|
557
|
-
|
|
558
|
-
|
|
431
|
+
ue as AllLoaded,
|
|
432
|
+
ee as createLoading,
|
|
559
433
|
C as errorFallbacks,
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
434
|
+
k as fallbacks,
|
|
435
|
+
K as getDefaultErrorFallback,
|
|
436
|
+
I as getDefaultFallback,
|
|
437
|
+
L as reactNodeOrFunctionValue,
|
|
438
|
+
ae as registerDefaultErrorFallback,
|
|
439
|
+
ie as registerDefaultFallback,
|
|
440
|
+
ne as registerErrorFallback,
|
|
441
|
+
se as registerFallback,
|
|
568
442
|
B as resolveErrorFallback,
|
|
569
|
-
|
|
443
|
+
P as resolveLoadingFallback,
|
|
444
|
+
oe as useCreateLocalLoading
|
|
570
445
|
};
|
package/dist/main.min.js
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* react-easy-loading v0.
|
|
2
|
+
* react-easy-loading v0.3.0
|
|
3
3
|
* (c) Hichem Taboukouyout
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
* Github: github.com/HichemTab-tech/react-easy-loading
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
(function(d,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],h):(d=typeof globalThis<"u"?globalThis:d||self,h(d.ReactEasyLoading={},d.jsxRuntime,d.React))})(this,(function(d,h,b){"use strict";const V={},D={},$=(a,e)=>{V[a]=e},z=(a,e)=>{D[a]=e};let _=h.jsx("div",{children:"Loading..."}),C=(a,e)=>h.jsxs("div",{children:[h.jsx("h3",{children:"Errors:"}),h.jsx("ul",{children:a?.map((t,r)=>h.jsx("li",{children:t},r))}),h.jsx("button",{onClick:e,disabled:!e,children:"Retry"})]});const q=a=>{_=a},I=a=>{C=a},P=()=>_,j=()=>C,F=(a,e)=>M(P,V,a,e);function A(a,e){return M(j,D,a,e)}function M(a,e,t,r){return r?typeof r=="string"?e[r]??r:r:r===null?null:t?typeof t=="string"?e[t]??t:t:a()}function w(a,...e){return typeof a=="function"?a(...e):a}/*!
|
|
9
|
-
* react-shared-states v1.0.22
|
|
10
|
-
* (c) Hichem Taboukouyout
|
|
11
|
-
* Released under the MIT License.
|
|
12
|
-
* Github: github.com/HichemTab-tech/react-shared-states
|
|
13
|
-
*/const B=(...a)=>{},O=a=>{if(!a)throw new Error("Value is empty");return a},K=()=>Math.random().toString(36).substring(2,15),N=b.createContext(void 0),U=()=>b.useContext(N),W=[];class c{data=new Map;defaultValue(){return{}}addListener(e,t,r){this.data.has(c.prefix(e,t))||this.data.set(c.prefix(e,t),{...this.defaultValue(),listeners:[]}),this.data.get(c.prefix(e,t)).listeners.push(r)}removeListener(e,t,r){this.data.has(c.prefix(e,t))&&(this.data.get(c.prefix(e,t)).listeners=this.data.get(c.prefix(e,t)).listeners.filter(s=>s!==r))}callListeners(e,t){this.data.has(c.prefix(e,t))&&this.data.get(c.prefix(e,t)).listeners.forEach(r=>r())}init(e,t,r,s=!1){this.data.has(c.prefix(e,t))||this.data.set(c.prefix(e,t),{...r,isStatic:s,listeners:[]})}createStatic(e,t){const r=t??t??"_global",s={key:K(),prefix:r,...e};return W.push(s),this.initStatic(s),s}initStatic(e){const{key:t,prefix:r}=e;this.init(t,r,this.defaultValue(),!0)}clearAll(e=!1,t=!1){this.data.forEach((r,s)=>{const[i,o]=c.extractPrefix(s);this.clear(o,i,e,t)})}clear(e,t,r=!1,s=!1){r||this.callListeners(e,t);const i=this.data.get(c.prefix(e,t));if(!i)return;const o={...i};if(this.data.delete(c.prefix(e,t)),o.isStatic&&!s){const l=W.find(n=>n.key===e&&n.prefix===t);l&&this.initStatic(l)}}get(e,t){let r=this.has(e,t);if(r)return this.data.get(r)}setValue(e,t,r){this.data.has(c.prefix(e,t))&&this.data.set(c.prefix(e,t),{...this.data.get(c.prefix(e,t)),...r})}has(e,t){return this.data.has(c.prefix(e,t))?c.prefix(e,t):this.data.has(c.prefix(e,"_global"))?c.prefix(e,"_global"):void 0}static prefix(e,t){if(e.includes("//"))throw new Error("key cannot contain '//'");return`${t}//${e}`}static extractPrefix(e){return e.split("//")}useEffect(e,t,r=null){b.useEffect(()=>()=>{r?.(),B(`[${c.prefix(e,t)}]`,"unmount effect"),this.data.get(c.prefix(e,t)).listeners?.length===0&&this.clear(e,t)},[])}}class k{constructor(e){this.sharedData=e}get(e,t){let r,s=t;if(typeof e!="string"){const{key:o,prefix:l}=e;r=o,s=l}else r=O(e);const i=s||"_global";return this.sharedData.get(r,i)}set(e,t,r){let s,i=r;if(typeof e!="string"){const{key:l,prefix:n}=e;s=l,i=n}else s=O(e);const o=i||"_global";this.sharedData.init(s,o,t),this.sharedData.setValue(s,o,t),this.sharedData.callListeners(s,o)}update(e,t,r){let s;typeof e=="string"?s=this.get(e,r):s=this.get(e);const i=t(s);typeof e=="string"?this.set(e,i,r):this.set(e,i)}clearAll(){this.sharedData.clearAll()}clearScope(e){const t=e||"_global";this.sharedData.data.forEach((r,s)=>{const[i,o]=c.extractPrefix(s);if(i===t){this.sharedData.clear(o,i),this.sharedData.callListeners(o,i);return}})}resolve(e){const{key:t,prefix:r}=e;return this.get(t,r)}clear(e,t){let r,s;typeof e=="string"?(r=e,s=t||"_global"):(r=e.key,s=e.prefix),this.sharedData.clear(r,s)}has(e,t="_global"){const r=t||"_global";return!!this.sharedData.has(e,r)}getAll(){const e={};return this.sharedData.data.forEach((t,r)=>{const[s,i]=c.extractPrefix(r);e[s]=e[s]||{},e[s][i]=t}),e}subscribe(e,t,r){let s,i;return typeof e=="string"?(s=e,i=r||"_global"):(s=e.key,i=e.prefix),this.sharedData.addListener(s,i,t),()=>{this.sharedData.removeListener(s,i,t)}}}const G=a=>{const e=U();return{prefix:a??e?.scopeName??"_global"}};function H(a){return a&&a.__esModule&&Object.prototype.hasOwnProperty.call(a,"default")?a.default:a}var m,T;function J(){if(T)return m;T=1;var a=typeof Element<"u",e=typeof Map=="function",t=typeof Set=="function",r=typeof ArrayBuffer=="function"&&!!ArrayBuffer.isView;function s(i,o){if(i===o)return!0;if(i&&o&&typeof i=="object"&&typeof o=="object"){if(i.constructor!==o.constructor)return!1;var l,n,u;if(Array.isArray(i)){if(l=i.length,l!=o.length)return!1;for(n=l;n--!==0;)if(!s(i[n],o[n]))return!1;return!0}var f;if(e&&i instanceof Map&&o instanceof Map){if(i.size!==o.size)return!1;for(f=i.entries();!(n=f.next()).done;)if(!o.has(n.value[0]))return!1;for(f=i.entries();!(n=f.next()).done;)if(!s(n.value[1],o.get(n.value[0])))return!1;return!0}if(t&&i instanceof Set&&o instanceof Set){if(i.size!==o.size)return!1;for(f=i.entries();!(n=f.next()).done;)if(!o.has(n.value[0]))return!1;return!0}if(r&&ArrayBuffer.isView(i)&&ArrayBuffer.isView(o)){if(l=i.length,l!=o.length)return!1;for(n=l;n--!==0;)if(i[n]!==o[n])return!1;return!0}if(i.constructor===RegExp)return i.source===o.source&&i.flags===o.flags;if(i.valueOf!==Object.prototype.valueOf&&typeof i.valueOf=="function"&&typeof o.valueOf=="function")return i.valueOf()===o.valueOf();if(i.toString!==Object.prototype.toString&&typeof i.toString=="function"&&typeof o.toString=="function")return i.toString()===o.toString();if(u=Object.keys(i),l=u.length,l!==Object.keys(o).length)return!1;for(n=l;n--!==0;)if(!Object.prototype.hasOwnProperty.call(o,u[n]))return!1;if(a&&i instanceof Element)return!1;for(n=l;n--!==0;)if(!((u[n]==="_owner"||u[n]==="__v"||u[n]==="__o")&&i.$$typeof)&&!s(i[u[n]],o[u[n]]))return!1;return!0}return i!==i&&o!==o}return m=function(i,o){try{return s(i,o)}catch(l){if((l.message||"").match(/stack|recursion/i))return console.warn("react-fast-compare cannot handle circular refs"),!1;throw l}},m}var Q=J();const X=H(Q);class Y extends c{defaultValue(){return{value:void 0}}initValue(e,t,r,s=!1){super.init(e,t,{value:r},s)}initStatic(e){const{key:t,prefix:r,initialValue:s}=e;this.initValue(t,r,s,!0)}}class Z extends k{constructor(e){super(e)}get(e,t="_global"){return typeof e!="string"?super.get(e)?.value:super.get(e,t)?.value}set(e,t,r="_global"){if(typeof e!="string"){super.set(e,{value:t});return}super.set(e,{value:t},r)}update(e,t,r="_global"){let s;typeof e=="string"?s=this.get(e,r):s=this.get(e);const i=t(s);typeof e=="string"?this.set(e,i,r):this.set(e,i)}}const x=new Y,p=new Z(x),R=(a,e)=>x.createStatic({initialValue:a},e);function E(a,e,t){let r,s=t;if(typeof a!="string"){const{key:f,prefix:g}=a;r=f,s=g}else r=O(a);const{prefix:i}=G(s),o=b.useRef(void 0),l=b.useMemo(()=>f=>(x.addListener(r,i,f),()=>{x.removeListener(r,i,f)}),[]),n=b.useMemo(()=>()=>{const f=x.get(r,i)?.value,g=e(f);return X(o.current,g)?o.current:g},[]),u=b.useSyncExternalStore(l,n);return x.useEffect(r,i),u}class ee extends c{defaultValue(){return{fnState:{results:void 0,isLoading:!1,error:void 0}}}initValue(e,t,r=!1){super.init(e,t,this.defaultValue(),r)}setValue(e,t,r){super.setValue(e,t,r)}}class te extends k{constructor(e){super(e)}get(e,t="_global"){return typeof e!="string"?super.get(e)?.fnState:super.get(e,t)?.fnState}set(e,t,r="_global"){if(typeof e!="string"){super.set(e,t);return}super.set(e,t,r)}update(e,t,r="_global"){let s;typeof e=="string"?s=this.get(e,r):s=this.get(e);const i=t(s);typeof e=="string"?this.set(e,i,r):this.set(e,i)}}const re=new ee;new te(re);class se extends c{defaultValue(){return{fnState:{data:void 0,isLoading:!1,error:void 0,subscribed:!1}}}initValue(e,t,r=!1){super.init(e,t,this.defaultValue(),r)}setValue(e,t,r){super.setValue(e,t,r)}useEffect(e,t){b.useEffect(()=>()=>{B(`[${c.prefix(e,t)}]`,"unmount effect2"),this.get(e,t)?.listeners.length===0&&this.unsubscribe(e,t)},[]),super.useEffect(e,t)}async unsubscribe(e,t){const r=this.get(e,t);r&&(r.unsubscribe&&(r.unsubscribe(),r.unsubscribe=void 0),r.fnState={...r.fnState,subscribed:!1},this.callListeners(e,t))}}class ie extends k{constructor(e){super(e)}get(e,t="_global"){return typeof e!="string"?super.get(e)?.fnState:super.get(e,t)?.fnState}set(e,t,r="_global"){if(typeof e!="string"){super.set(e,t);return}super.set(e,t,r)}update(e,t,r="_global"){let s;typeof e=="string"?s=this.get(e,r):s=this.get(e);const i=t(s);typeof e=="string"?this.set(e,i,r):this.set(e,i)}}const ne=new se;new ie(ne);const L=(a,e)=>Array.isArray(e)&&e.includes(a)||a===e,ae=({initialState:a="loading",defaultFallback:e,defaultErrorFallback:t,defaultRetry:r}={})=>{const s=R({state:a,retry:r}),i=n=>{let u=l.get();return new Promise((f,g)=>{if(L(l.get(),n)){f();return}const y=p.subscribe(s,()=>{L(l.get(),n)?(y(),f()):u!==l.get()&&g()})})},o=function(n,u=()=>[]){return f=>E(s,y=>L(y.state,n))?h.jsx(h.Fragment,{children:w(f.children,...u())}):null},l={use:()=>E(s,n=>n.state),useIsLoading:()=>E(s,n=>n.state)==="loading",useErrors:()=>E(s,n=>n.errors),useContext:()=>E(s,n=>n.context),set:n=>p.update(s,u=>({...u,state:n})),retry:n=>(p.get(s).retry??n)?.(),isLoading:()=>p.get(s).state==="loading",isIdle:()=>p.get(s).state==="idle",isSuccess:()=>p.get(s).state==="success",isError:()=>p.get(s).state==="error",isFinished:()=>p.get(s).state==="success"||p.get(s).state==="error",is:n=>L(l.get(),n),hasErrors:()=>p.get(s).errors!==void 0,get:()=>p.get(s).state,getErrors:()=>p.get(s).errors,getContext:()=>p.get(s).context,reset:()=>p.set(s,{state:a}),addError:n=>{p.update(s,u=>({...u,errors:[...u.errors??[],n]}))},setContext:n=>{p.update(s,u=>({...u,context:n}))},setErrors:n=>{p.update(s,u=>({...u,errors:n}))},clearErrors:()=>{p.update(s,n=>({...n,errors:void 0}))},setRetry:n=>p.update(s,u=>({...u,retry:n})),whenLoaded:()=>i("success").catch(n=>{throw new Error("loading failed",{cause:n})}),whenFinished:()=>i(["success","error"]),wrap(n){const u=()=>new Promise((f,g)=>{l.clearErrors(),l.set("loading"),n().then(y=>{l.set("success"),f(y)}).catch(y=>{l.set("error"),y&&l.setErrors([y]),g(y)})});return l.setRetry(u),u()},wrapWithControl(n){const u={thens:[],catchs:[],finallies:[]},f={then:(...g)=>(u.thens.push(g),f),catch_:(...g)=>(u.catchs.push(g),f),finally_:(...g)=>(u.finallies.push(g),f),start:()=>new Promise((g,y)=>{l.clearErrors(),l.set("loading");let S=n();S.then(()=>{l.set("success")}),S.catch(v=>{l.set("error"),v&&l.setErrors([v])});for(const v of u.thens)S.then(...v);for(const v of u.catchs)S.catch(...v);for(const v of u.finallies)S.finally(...v);S.then(g,y)})};return l.setRetry(f.start),f},ShowWhenLoaded:({children:n,fallback:u,errorFallback:f})=>{const g=E(s,y=>y.state);return g==="idle"?null:(u=F(e,u),f=A(t,f===!0?void 0:f),g==="loading"?h.jsx(h.Fragment,{children:u}):g==="error"?h.jsx(h.Fragment,{children:w(f,l.getErrors()??[],()=>l.retry())}):h.jsx(h.Fragment,{children:n}))},ShowWhileLoading:o("loading"),ShowWhenError:o("error",()=>[l.getErrors()??[],()=>l.retry()]),ShowWhenFinish:o(["error","success"],()=>[l.getErrors(),()=>l.retry()]),ShowWhen:({children:n,state:u})=>{const f=o(u);return h.jsx(f,{children:n})}};return l},oe=({of:a,fallback:e,errorFallback:t,children:r})=>{const s=a.map(i=>i.use());return e=F(void 0,e),s.some(i=>i==="loading")?e:s.every(i=>i!=="loading")?s.some(i=>i==="error")?(t=A(void 0,t),h.jsx(h.Fragment,{children:w(t,a.reduce((i,o)=>[...i,...o.getErrors()??[]],[]),()=>{a.map(i=>{i.isError()&&i.retry()})})})):h.jsx(h.Fragment,{children:r}):null};d.AllLoaded=oe,d.createLoading=ae,d.errorFallbacks=D,d.fallbacks=V,d.getDefaultErrorFallback=j,d.getDefaultFallback=P,d.reactNodeOrFunctionValue=w,d.registerDefaultErrorFallback=I,d.registerDefaultFallback=q,d.registerErrorFallback=z,d.registerFallback=$,d.resolveErrorFallback=A,d.resolveLoadingFallback=F,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})}));
|
|
8
|
+
(function(d,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],u):(d=typeof globalThis<"u"?globalThis:d||self,u(d.ReactEasyLoading={},d.jsxRuntime,d.React))})(this,(function(d,u,v){"use strict";const D={},k={},W=(o,e)=>{D[o]=e},T=(o,e)=>{k[o]=e};let O=u.jsx("div",{children:"Loading..."}),C=(o,e)=>u.jsxs("div",{children:[u.jsx("h3",{children:"Errors:"}),u.jsx("ul",{children:o?.map((s,i)=>u.jsx("li",{children:s},i))}),u.jsx("button",{onClick:e,disabled:!e,children:"Retry"})]});const q=o=>{O=o},z=o=>{C=o},V=()=>O,j=()=>C,F=(o,e)=>P(V,D,o,e);function A(o,e){return P(j,k,o,e)}function P(o,e,s,i){return i?typeof i=="string"?e[i]??i:i:i===null?null:s?typeof s=="string"?e[s]??s:s:o()}function w(o,...e){return typeof o=="function"?o(...e):o}const I=(...o)=>{},_=o=>{if(!o)throw new Error("Value is empty");return o},K=()=>Math.random().toString(36).substring(2,15),N=v.createContext(void 0),U=()=>v.useContext(N),M=[];class y{constructor(e=()=>null){this.defaultValue=e}data=new Map;addListener(e,s,i){const r=y.prefix(e,s),t=this.data.get(r);t&&t.listeners.push(i)}removeListener(e,s,i){const r=y.prefix(e,s),t=this.data.get(r);t&&(t.listeners=t.listeners.filter(a=>a!==i))}callListeners(e,s){const i=y.prefix(e,s),r=this.data.get(i);r&&r.listeners.forEach(t=>t())}init(e,s,i,r=!1){const t=y.prefix(e,s);this.data.has(t)||this.data.set(t,{value:i,isStatic:r||void 0,listeners:[]})}createStatic(e,s,i){const r=i??"_global",t={key:K(),prefix:r,...e};return M.push(t),this.init(t.key,t.prefix,s,!0),this.defaultValue=()=>s,t}initStatic(e){const{key:s,prefix:i}=e;this.init(s,i,this.defaultValue(),!0)}clearAll(e=!1,s=!1){this.data.forEach((i,r)=>{const[t,a]=y.extractPrefix(r);this.clear(a,t,e,s)})}clear(e,s,i=!1,r=!1){const t=y.prefix(e,s);i||this.callListeners(e,s);const a=this.data.get(t);if(a&&(this.data.delete(t),a.isStatic&&!r)){const l=M.find(n=>n.key===e&&n.prefix===s);l&&this.initStatic(l)}}get(e,s){let i=this.has(e,s);if(i)return this.data.get(i)}setValue(e,s,i){const r=y.prefix(e,s),t=this.data.get(r);t&&(t.value=i,this.data.set(r,t))}has(e,s){return this.data.has(y.prefix(e,s))?y.prefix(e,s):this.data.has(y.prefix(e,"_global"))?y.prefix(e,"_global"):void 0}static prefix(e,s){if(e.includes("//"))throw new Error("key cannot contain '//'");return`${s}//${e}`}static extractPrefix(e){const s=e.split("//");return[s[0],s.slice(1).join("//")]}useEffect(e,s,i=null){v.useEffect(()=>()=>{i?.(),I(`[${y.prefix(e,s)}]`,"unmount effect");const r=this.get(e,s);r&&r.listeners?.length===0&&this.clear(e,s)},[e,s])}}class G{constructor(e){this.sharedData=e}_get(e,s){let i,r=s;if(typeof e!="string"){const{key:l,prefix:n}=e;i=l,r=n}else i=_(e);const t=r||"_global",a=this.sharedData.get(i,t);return a?{value:a.value,key:i,prefix:t}:{key:i,prefix:t,value:void 0}}get(e,s){return this._get(e,s).value}set(e,s,i){let r,t=i;if(typeof e!="string"){const{key:l,prefix:n}=e;r=l,t=n}else r=_(e);const a=t||"_global";this.sharedData.init(r,a,s),this.sharedData.setValue(r,a,s),this.sharedData.callListeners(r,a)}update(e,s,i){const r=this._get(e,i);if(r){const t=s(r.value);this.set(r.key,t,r.prefix)}}clearAll(){this.sharedData.clearAll()}clearScope(e){const s=e||"_global";this.sharedData.data.forEach((i,r)=>{const[t,a]=y.extractPrefix(r);t===s&&(this.sharedData.clear(a,t),this.sharedData.callListeners(a,t))})}resolve(e){const{key:s,prefix:i}=e;return this.get(s,i)}clear(e,s){let i,r;typeof e=="string"?(i=e,r=s||"_global"):(i=e.key,r=e.prefix),this.sharedData.clear(i,r)}has(e,s="_global"){const i=s||"_global";return!!this.sharedData.has(e,i)}getAll(){const e={};return this.sharedData.data.forEach((s,i)=>{const[r,t]=y.extractPrefix(i);e[r]=e[r]||{},e[r][t]=s.value}),e}subscribe(e,s,i){let r,t;return typeof e=="string"?(r=e,t=i||"_global"):(r=e.key,t=e.prefix),this.sharedData.addListener(r,t,s),()=>{this.sharedData.removeListener(r,t,s)}}}const H=o=>{const e=U();return{prefix:o??e?.scopeName??"_global"}};function J(o){return o&&o.__esModule&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o}var m,B;function Q(){if(B)return m;B=1;var o=typeof Element<"u",e=typeof Map=="function",s=typeof Set=="function",i=typeof ArrayBuffer=="function"&&!!ArrayBuffer.isView;function r(t,a){if(t===a)return!0;if(t&&a&&typeof t=="object"&&typeof a=="object"){if(t.constructor!==a.constructor)return!1;var l,n,f;if(Array.isArray(t)){if(l=t.length,l!=a.length)return!1;for(n=l;n--!==0;)if(!r(t[n],a[n]))return!1;return!0}var c;if(e&&t instanceof Map&&a instanceof Map){if(t.size!==a.size)return!1;for(c=t.entries();!(n=c.next()).done;)if(!a.has(n.value[0]))return!1;for(c=t.entries();!(n=c.next()).done;)if(!r(n.value[1],a.get(n.value[0])))return!1;return!0}if(s&&t instanceof Set&&a instanceof Set){if(t.size!==a.size)return!1;for(c=t.entries();!(n=c.next()).done;)if(!a.has(n.value[0]))return!1;return!0}if(i&&ArrayBuffer.isView(t)&&ArrayBuffer.isView(a)){if(l=t.length,l!=a.length)return!1;for(n=l;n--!==0;)if(t[n]!==a[n])return!1;return!0}if(t.constructor===RegExp)return t.source===a.source&&t.flags===a.flags;if(t.valueOf!==Object.prototype.valueOf&&typeof t.valueOf=="function"&&typeof a.valueOf=="function")return t.valueOf()===a.valueOf();if(t.toString!==Object.prototype.toString&&typeof t.toString=="function"&&typeof a.toString=="function")return t.toString()===a.toString();if(f=Object.keys(t),l=f.length,l!==Object.keys(a).length)return!1;for(n=l;n--!==0;)if(!Object.prototype.hasOwnProperty.call(a,f[n]))return!1;if(o&&t instanceof Element)return!1;for(n=l;n--!==0;)if(!((f[n]==="_owner"||f[n]==="__v"||f[n]==="__o")&&t.$$typeof)&&!r(t[f[n]],a[f[n]]))return!1;return!0}return t!==t&&a!==a}return m=function(t,a){try{return r(t,a)}catch(l){if((l.message||"").match(/stack|recursion/i))return console.warn("react-fast-compare cannot handle circular refs"),!1;throw l}},m}var X=Q();const Y=J(X),x=new y,g=new G(x),Z=(o,e)=>x.createStatic({initialValue:o},o,e);function b(o,e,s){let i,r=s;if(typeof o!="string"){const{key:c,prefix:h}=o;i=c,r=h}else i=_(o);const{prefix:t}=H(r),a=v.useRef(void 0),l=v.useMemo(()=>c=>(x.init(i,t,void 0),x.addListener(i,t,c),()=>{x.removeListener(i,t,c)}),[i,t]),n=v.useMemo(()=>()=>{const c=x.get(i,t)?.value,h=e(c);return Y(a.current,h)?a.current:(a.current=h,h)},[i,t,e]),f=v.useSyncExternalStore(l,n);return x.useEffect(i,t),f}const S=(o,e)=>Array.isArray(e)&&e.includes(o)||o===e,$=({initialState:o="loading",defaultFallback:e,defaultErrorFallback:s,defaultRetry:i}={})=>{const r=Z({state:o,retry:i}),t=n=>{let f=l.get();return new Promise((c,h)=>{if(S(l.get(),n)){c();return}const p=g.subscribe(r,()=>{S(l.get(),n)?(p(),c()):f!==l.get()&&h()})})},a=function(n,f=()=>[]){return c=>b(r,p=>S(p.state,n))?u.jsx(u.Fragment,{children:w(c.children,...f())}):null},l={use:()=>b(r,n=>n.state),useIsLoading:()=>b(r,n=>n.state)==="loading",useErrors:()=>b(r,n=>n.errors),useContext:()=>b(r,n=>n.context),set:n=>g.update(r,f=>({...f,state:n})),retry:n=>(g.get(r).retry??n)?.(),isLoading:()=>g.get(r).state==="loading",isIdle:()=>g.get(r).state==="idle",isSuccess:()=>g.get(r).state==="success",isError:()=>g.get(r).state==="error",isFinished:()=>g.get(r).state==="success"||g.get(r).state==="error",is:n=>S(l.get(),n),hasErrors:()=>g.get(r).errors!==void 0,get:()=>g.get(r).state,getErrors:()=>g.get(r).errors,getContext:()=>g.get(r).context,reset:()=>g.set(r,{state:o}),addError:n=>{g.update(r,f=>({...f,errors:[...f.errors??[],n]}))},setContext:n=>{g.update(r,f=>({...f,context:n}))},setErrors:n=>{g.update(r,f=>({...f,errors:n}))},clearErrors:()=>{g.update(r,n=>({...n,errors:void 0}))},setRetry:n=>g.update(r,f=>({...f,retry:n})),whenLoaded:()=>t("success").catch(n=>{throw new Error("loading failed",{cause:n})}),whenFinished:()=>t(["success","error"]),wrap(n){const f=()=>new Promise((c,h)=>{l.clearErrors(),l.set("loading"),n().then(p=>{l.set("success"),c(p)}).catch(p=>{l.set("error"),p&&l.setErrors([p]),h(p)})});return l.setRetry(f),f()},wrapWithControl(n){const f={thens:[],catchs:[],finallies:[]},c={then:(...h)=>(f.thens.push(h),c),catch_:(...h)=>(f.catchs.push(h),c),finally_:(...h)=>(f.finallies.push(h),c),start:()=>new Promise((h,p)=>{l.clearErrors(),l.set("loading");let L=n();L.then(()=>{l.set("success")}),L.catch(E=>{l.set("error"),E&&l.setErrors([E])});for(const E of f.thens)L.then(...E);for(const E of f.catchs)L.catch(...E);for(const E of f.finallies)L.finally(...E);L.then(h,p)})};return l.setRetry(c.start),c},ShowWhenLoaded:({children:n,fallback:f,errorFallback:c})=>{const h=b(r,p=>p.state);return h==="idle"?null:(f=F(e,f),c=A(s,c===!0?void 0:c),h==="loading"?u.jsx(u.Fragment,{children:f}):h==="error"?u.jsx(u.Fragment,{children:w(c,l.getErrors()??[],()=>l.retry())}):u.jsx(u.Fragment,{children:n}))},ShowWhileLoading:a("loading"),ShowWhenError:a("error",()=>[l.getErrors()??[],()=>l.retry()]),ShowWhenFinish:a(["error","success"],()=>[l.getErrors(),()=>l.retry()]),ShowWhen:({children:n,state:f})=>{const c=a(f);return u.jsx(c,{children:n})},destroy:()=>{g.clear(r)},__get__id:()=>`loading_id//${r.prefix}/${r.key}`};return l},R=(o={})=>{const e=v.useRef($(typeof o=="string"?{initialState:o}:o));return v.useEffect(()=>()=>{e.current.destroy()},[]),e.current},ee=({of:o,fallback:e,errorFallback:s,children:i})=>{const r=o.map(t=>t.use());return e=F(void 0,e),r.some(t=>t==="loading")?e:r.every(t=>t!=="loading")?r.some(t=>t==="error")?(s=A(void 0,s),u.jsx(u.Fragment,{children:w(s,o.reduce((t,a)=>[...t,...a.getErrors()??[]],[]),()=>{o.map(t=>{t.isError()&&t.retry()})})})):u.jsx(u.Fragment,{children:i}):null};d.AllLoaded=ee,d.createLoading=$,d.errorFallbacks=k,d.fallbacks=D,d.getDefaultErrorFallback=j,d.getDefaultFallback=V,d.reactNodeOrFunctionValue=w,d.registerDefaultErrorFallback=z,d.registerDefaultFallback=q,d.registerErrorFallback=T,d.registerFallback=W,d.resolveErrorFallback=A,d.resolveLoadingFallback=F,d.useCreateLocalLoading=R,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-easy-loading",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@tailwindcss/vite": "^4.1.14",
|
|
37
37
|
"@testing-library/dom": "^10.4.1",
|
|
38
38
|
"@testing-library/react": "^16.3.0",
|
|
39
|
-
"@types/node": "^
|
|
39
|
+
"@types/node": "^25.0.2",
|
|
40
40
|
"@types/react": "^19.2.0",
|
|
41
41
|
"@types/react-dom": "^19.2.0",
|
|
42
42
|
"@vitejs/plugin-react": "^5.0.4",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"react": "^19.2.0",
|
|
46
46
|
"react-dom": "^19.2.0",
|
|
47
47
|
"react-exposed-states": "^1.0.5",
|
|
48
|
-
"react-shared-states": "^1.0
|
|
48
|
+
"react-shared-states": "^2.1.0",
|
|
49
49
|
"tailwindcss": "^4.1.14",
|
|
50
50
|
"typescript": "^5.9.3",
|
|
51
51
|
"use-effect-skip-first": "^0.1.2",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"vite-plugin-banner": "^0.8.1",
|
|
54
54
|
"vite-plugin-css-injected-by-js": "^3.5.2",
|
|
55
55
|
"vite-plugin-dts": "^4.5.4",
|
|
56
|
-
"vitest": "^
|
|
56
|
+
"vitest": "^4.0.15"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "vite build",
|