react-easy-loading 0.1.0 → 0.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/README.md CHANGED
@@ -106,6 +106,29 @@ 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
+
121
+ // Use it just like a regular loading instance
122
+ const isLoading = loading.useIsLoading();
123
+
124
+ return (
125
+ <div>
126
+ {isLoading ? 'Loading...' : 'Done'}
127
+ </div>
128
+ );
129
+ }
130
+ ```
131
+
109
132
  ## ✨ Automatic State Management with `wrap`
110
133
 
111
134
  The `wrap` function automates state management.
@@ -269,14 +292,15 @@ Use these to get the current value without subscribing to updates.
269
292
 
270
293
  Use these to control the state from anywhere.
271
294
 
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. |
295
+ | Method | Description |
296
+ |---------------------|-----------------------------------------------------|
297
+ | `set(state)` | Manually sets the loading state. |
298
+ | `reset()` | Resets the state to its initial value. |
299
+ | `retry()` | Re-runs the last wrapped async function. |
300
+ | `setRetry(fn)` | Manually provides a custom retry function. |
301
+ | `setErrors(errors)` | Overwrites the errors array. |
302
+ | `addError(error)` | Adds an error to the errors array. |
303
+ | `destroy()` | Destroys the loading instance and clears its state. |
280
304
 
281
305
  ---
282
306
 
@@ -32,7 +32,7 @@ export type Loading<Errors extends unknown[] = string[], Context extends Record<
32
32
  getErrors: () => Errors | undefined;
33
33
  getContext: () => Context | undefined;
34
34
  set(state: LoadingState): void;
35
- retry: () => void;
35
+ retry: (defaultRetry?: () => void) => void;
36
36
  reset: () => void;
37
37
  addError: (error: Errors[number]) => void;
38
38
  setContext: (context: Context) => void;
@@ -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,OAAO,CAAC;AAIpE,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;AACpE,MAAM,MAAM,kBAAkB,CAAC,MAAM,SAAS,OAAO,EAAE,GAAG,MAAM,EAAE,EAAE,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,GAAG,IAAI;IACjH,KAAK,EAAE,YAAY,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB,CAAA;AAED,MAAM,MAAM,oBAAoB,CAAC,CAAC,IAAI;IAClC,IAAI,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IACzC,MAAM,EAAE,cAAc,CAAC,OA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,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) => 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,oBAAyB,KAAG,OAAO,CAAC,MAAM,EAAE,OAAO,CAUlM,CAAA"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './fallbacks';
2
2
  export * from './create-loading';
3
+ export * from './create-local-loading';
3
4
  export * from './components';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -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,443 @@
1
1
  /*!
2
- * react-easy-loading v0.1.0
2
+ * react-easy-loading v0.2.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 W, Fragment as b } from "react/jsx-runtime";
9
- import { createContext as $, useEffect as j, useRef as z, useMemo as D, useSyncExternalStore as I, useContext as K } from "react";
10
- const _ = {}, C = {}, fe = (a, e) => {
11
- _[a] = e;
12
- }, ce = (a, e) => {
13
- C[a] = e;
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 P = /* @__PURE__ */ p("div", { children: "Loading..." }), R = (a, e) => /* @__PURE__ */ W("div", { children: [
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: a?.map((t, r) => /* @__PURE__ */ p("li", { children: t }, r)) }),
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 he = (a) => {
21
- P = a;
22
- }, ge = (a) => {
23
- R = a;
24
- }, T = () => P, U = () => R, k = (a, e) => F(T, _, a, e);
25
- function B(a, e) {
26
- return F(U, C, a, e);
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 F(a, e, t, r) {
29
- return r ? typeof r == "string" ? e[r] ?? r : r : r === null ? null : t ? typeof t == "string" ? e[t] ?? t : t : a();
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 m(a, ...e) {
32
- return typeof a == "function" ? a(...e) : a;
31
+ function S(o, ...e) {
32
+ return typeof o == "function" ? o(...e) : o;
33
33
  }
34
- /*!
35
- * react-shared-states v1.0.22
36
- * (c) Hichem Taboukouyout
37
- * Released under the MIT License.
38
- * Github: github.com/HichemTab-tech/react-shared-states
39
- */
40
- const M = (...a) => {
41
- }, L = (a) => {
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
- init(e, t, r, s = !1) {
63
- this.data.has(c.prefix(e, t)) || this.data.set(c.prefix(e, t), {
64
- ...r,
65
- isStatic: s,
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, t) {
70
- const r = t ?? t ?? "_global", s = {
71
- key: N(),
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(s), this.initStatic(s), s;
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: t, prefix: r } = e;
79
- this.init(t, r, this.defaultValue(), !0);
73
+ const { key: s, prefix: i } = e;
74
+ this.init(s, i, this.defaultValue(), !0);
80
75
  }
81
- clearAll(e = !1, t = !1) {
82
- this.data.forEach((r, s) => {
83
- const [i, o] = c.extractPrefix(s);
84
- this.clear(o, i, e, t);
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, t, r = !1, s = !1) {
88
- r || this.callListeners(e, t);
89
- const i = this.data.get(c.prefix(e, t));
90
- if (!i) return;
91
- const o = { ...i };
92
- if (this.data.delete(c.prefix(e, t)), o.isStatic && !s) {
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, t) {
98
- let r = this.has(e, t);
99
- if (r)
100
- return this.data.get(r);
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, t, r) {
103
- this.data.has(c.prefix(e, t)) && this.data.set(c.prefix(e, t), {
104
- ...this.data.get(c.prefix(e, t)),
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, t) {
109
- 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;
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, t) {
103
+ static prefix(e, s) {
112
104
  if (e.includes("//")) throw new Error("key cannot contain '//'");
113
- return `${t}//${e}`;
105
+ return `${s}//${e}`;
114
106
  }
115
107
  static extractPrefix(e) {
116
- return e.split("//");
108
+ const s = e.split("//");
109
+ return [s[0], s.slice(1).join("//")];
117
110
  }
118
- useEffect(e, t, r = null) {
119
- j(() => () => {
120
- r?.(), M(`[${c.prefix(e, t)}]`, "unmount effect"), this.data.get(c.prefix(e, t)).listeners?.length === 0 && this.clear(e, t);
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 V {
119
+ class G {
125
120
  constructor(e) {
126
121
  this.sharedData = e;
127
122
  }
128
- get(e, t) {
129
- let r, s = t;
123
+ _get(e, s) {
124
+ let i, r = s;
130
125
  if (typeof e != "string") {
131
- const { key: o, prefix: u } = e;
132
- r = o, s = u;
126
+ const { key: u, prefix: n } = e;
127
+ i = u, r = n;
133
128
  } else
134
- r = L(e);
135
- const i = s || "_global";
136
- return this.sharedData.get(r, i);
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, t, r) {
139
- let s, i = r;
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
- s = u, i = n;
144
+ r = u, t = n;
143
145
  } else
144
- s = L(e);
145
- const o = i || "_global";
146
- this.sharedData.init(s, o, t), this.sharedData.setValue(s, o, t), this.sharedData.callListeners(s, o);
147
- }
148
- update(e, t, r) {
149
- let s;
150
- typeof e == "string" ? s = this.get(e, r) : s = this.get(e);
151
- const i = t(s);
152
- typeof e == "string" ? this.set(e, i, r) : this.set(e, i);
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 t = e || "_global";
166
- this.sharedData.data.forEach((r, s) => {
167
- const [i, o] = c.extractPrefix(s);
168
- if (i === t) {
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: t, prefix: r } = e;
180
- return this.get(t, r);
168
+ const { key: s, prefix: i } = e;
169
+ return this.get(s, i);
181
170
  }
182
- clear(e, t) {
183
- let r, s;
184
- typeof e == "string" ? (r = e, s = t || "_global") : (r = e.key, s = e.prefix), this.sharedData.clear(r, s);
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
- * check if a value exists in the shared data
188
- * @param key
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((t, r) => {
201
- const [s, i] = c.extractPrefix(r);
202
- e[s] = e[s] || {}, e[s][i] = t;
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, t, r) {
206
- let s, i;
207
- return typeof e == "string" ? (s = e, i = r || "_global") : (s = e.key, i = e.prefix), this.sharedData.addListener(s, i, t), () => {
208
- this.sharedData.removeListener(s, i, t);
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 = (a) => {
213
- const e = G();
193
+ const H = (o) => {
194
+ const e = T();
214
195
  return {
215
- prefix: a ?? e?.scopeName ?? "_global"
196
+ prefix: o ?? e?.scopeName ?? "_global"
216
197
  };
217
198
  };
218
- function J(a) {
219
- return a && a.__esModule && Object.prototype.hasOwnProperty.call(a, "default") ? a.default : a;
199
+ function J(o) {
200
+ return o && o.__esModule && Object.prototype.hasOwnProperty.call(o, "default") ? o.default : o;
220
201
  }
221
- var w, O;
202
+ var L, _;
222
203
  function Q() {
223
- if (O) return w;
224
- O = 1;
225
- var a = typeof Element < "u", e = typeof Map == "function", t = typeof Set == "function", r = typeof ArrayBuffer == "function" && !!ArrayBuffer.isView;
226
- function s(i, o) {
227
- if (i === o) return !0;
228
- if (i && o && typeof i == "object" && typeof o == "object") {
229
- if (i.constructor !== o.constructor) return !1;
230
- var u, n, l;
231
- if (Array.isArray(i)) {
232
- if (u = i.length, u != o.length) return !1;
204
+ if (_) return L;
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, c;
212
+ if (Array.isArray(t)) {
213
+ if (u = t.length, u != a.length) return !1;
233
214
  for (n = u; n-- !== 0; )
234
- if (!s(i[n], o[n])) return !1;
215
+ if (!r(t[n], a[n])) return !1;
235
216
  return !0;
236
217
  }
237
218
  var f;
238
- if (e && i instanceof Map && o instanceof Map) {
239
- if (i.size !== o.size) return !1;
240
- for (f = i.entries(); !(n = f.next()).done; )
241
- if (!o.has(n.value[0])) return !1;
242
- for (f = i.entries(); !(n = f.next()).done; )
243
- if (!s(n.value[1], o.get(n.value[0]))) return !1;
219
+ if (e && t instanceof Map && a instanceof Map) {
220
+ if (t.size !== a.size) return !1;
221
+ for (f = t.entries(); !(n = f.next()).done; )
222
+ if (!a.has(n.value[0])) return !1;
223
+ for (f = t.entries(); !(n = f.next()).done; )
224
+ if (!r(n.value[1], a.get(n.value[0]))) return !1;
244
225
  return !0;
245
226
  }
246
- if (t && i instanceof Set && o instanceof Set) {
247
- if (i.size !== o.size) return !1;
248
- for (f = i.entries(); !(n = f.next()).done; )
249
- if (!o.has(n.value[0])) return !1;
227
+ if (s && t instanceof Set && a instanceof Set) {
228
+ if (t.size !== a.size) return !1;
229
+ for (f = t.entries(); !(n = f.next()).done; )
230
+ if (!a.has(n.value[0])) return !1;
250
231
  return !0;
251
232
  }
252
- if (r && ArrayBuffer.isView(i) && ArrayBuffer.isView(o)) {
253
- if (u = i.length, u != o.length) return !1;
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 (i[n] !== o[n]) return !1;
236
+ if (t[n] !== a[n]) return !1;
256
237
  return !0;
257
238
  }
258
- if (i.constructor === RegExp) return i.source === o.source && i.flags === o.flags;
259
- if (i.valueOf !== Object.prototype.valueOf && typeof i.valueOf == "function" && typeof o.valueOf == "function") return i.valueOf() === o.valueOf();
260
- if (i.toString !== Object.prototype.toString && typeof i.toString == "function" && typeof o.toString == "function") return i.toString() === o.toString();
261
- if (l = Object.keys(i), u = l.length, u !== Object.keys(o).length) return !1;
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 (c = Object.keys(t), u = c.length, u !== Object.keys(a).length) return !1;
262
243
  for (n = u; n-- !== 0; )
263
- if (!Object.prototype.hasOwnProperty.call(o, l[n])) return !1;
264
- if (a && i instanceof Element) return !1;
244
+ if (!Object.prototype.hasOwnProperty.call(a, c[n])) return !1;
245
+ if (o && t instanceof Element) return !1;
265
246
  for (n = u; n-- !== 0; )
266
- if (!((l[n] === "_owner" || l[n] === "__v" || l[n] === "__o") && i.$$typeof) && !s(i[l[n]], o[l[n]]))
247
+ if (!((c[n] === "_owner" || c[n] === "__v" || c[n] === "__o") && t.$$typeof) && !r(t[c[n]], a[c[n]]))
267
248
  return !1;
268
249
  return !0;
269
250
  }
270
- return i !== i && o !== o;
251
+ return t !== t && a !== a;
271
252
  }
272
- return w = function(i, o) {
253
+ return L = function(t, a) {
273
254
  try {
274
- return s(i, o);
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
- }, w;
261
+ }, L;
281
262
  }
282
263
  var X = Q();
283
- const Y = /* @__PURE__ */ J(X);
284
- class Z extends c {
285
- defaultValue() {
286
- return { value: void 0 };
287
- }
288
- initValue(e, t, r, s = !1) {
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: f, prefix: l } = o;
269
+ i = f, r = l;
323
270
  } else
324
- r = L(a);
325
- const { prefix: i } = H(s), o = z(void 0), u = D(() => (f) => (E.addListener(r, i, f), () => {
326
- E.removeListener(r, i, f);
327
- }), []), n = D(() => () => {
328
- const f = E.get(r, i)?.value, h = e(f);
329
- return Y(o.current, h) ? o.current : h;
330
- }, []), l = I(u, n);
331
- return E.useEffect(r, i), l;
271
+ i = b(o);
272
+ const { prefix: t } = H(r), a = j(void 0), u = D(() => (f) => (x.init(i, t, void 0), x.addListener(i, t, f), () => {
273
+ x.removeListener(i, t, f);
274
+ }), [i, t]), n = D(() => () => {
275
+ const f = x.get(i, t)?.value, l = e(f);
276
+ return Y(a.current, l) ? a.current : (a.current = l, l);
277
+ }, [i, t, e]), c = W(u, n);
278
+ return x.useEffect(i, t), c;
332
279
  }
333
- class re extends c {
334
- defaultValue() {
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: t,
427
- defaultRetry: r
283
+ defaultErrorFallback: s,
284
+ defaultRetry: i
428
285
  } = {}) => {
429
- const s = te({
430
- state: a,
431
- retry: r
432
- }), i = (n) => {
433
- let l = u.get();
434
- return new Promise((f, h) => {
435
- if (S(u.get(), n)) {
286
+ const r = Z({
287
+ state: o,
288
+ retry: i
289
+ }), t = (n) => {
290
+ let c = u.get();
291
+ return new Promise((f, l) => {
292
+ if (m(u.get(), n)) {
436
293
  f();
437
294
  return;
438
295
  }
439
- const d = g.subscribe(s, () => {
440
- S(u.get(), n) ? (d(), f()) : l !== u.get() && h();
296
+ const g = h.subscribe(r, () => {
297
+ m(u.get(), n) ? (g(), f()) : c !== u.get() && l();
441
298
  });
442
299
  });
443
- }, o = function(n, l = () => []) {
444
- return (f) => v(s, (d) => S(d.state, n)) ? /* @__PURE__ */ p(b, { children: m(f.children, ...l()) }) : null;
300
+ }, a = function(n, c = () => []) {
301
+ return (f) => E(r, (g) => m(g.state, n)) ? /* @__PURE__ */ p(w, { children: S(f.children, ...c()) }) : null;
445
302
  }, u = {
446
303
  //hooks
447
- use: () => v(s, (n) => n.state),
448
- useIsLoading: () => v(s, (n) => n.state) === "loading",
449
- useErrors: () => v(s, (n) => n.errors),
450
- useContext: () => v(s, (n) => n.context),
451
- set: (n) => g.update(s, (l) => ({ ...l, state: n })),
452
- retry: () => g.get(s).retry?.(),
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, (c) => ({ ...c, state: n })),
309
+ retry: (n) => (h.get(r).retry ?? n)?.(),
453
310
  // getters
454
- isLoading: () => g.get(s).state === "loading",
455
- isIdle: () => g.get(s).state === "idle",
456
- isSuccess: () => g.get(s).state === "success",
457
- isError: () => g.get(s).state === "error",
458
- isFinished: () => g.get(s).state === "success" || g.get(s).state === "error",
459
- is: (n) => S(u.get(), n),
460
- hasErrors: () => g.get(s).errors !== void 0,
461
- get: () => g.get(s).state,
462
- getErrors: () => g.get(s).errors,
463
- getContext: () => g.get(s).context,
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: () => g.set(s, {
466
- state: a
322
+ reset: () => h.set(r, {
323
+ state: o
467
324
  }),
468
325
  addError: (n) => {
469
- g.update(s, (l) => ({
470
- ...l,
471
- errors: [...l.errors ?? [], n]
326
+ h.update(r, (c) => ({
327
+ ...c,
328
+ errors: [...c.errors ?? [], n]
472
329
  }));
473
330
  },
474
331
  setContext: (n) => {
475
- g.update(s, (l) => ({ ...l, context: n }));
332
+ h.update(r, (c) => ({ ...c, context: n }));
476
333
  },
477
334
  setErrors: (n) => {
478
- g.update(s, (l) => ({ ...l, errors: n }));
335
+ h.update(r, (c) => ({ ...c, errors: n }));
479
336
  },
480
337
  clearErrors: () => {
481
- g.update(s, (n) => ({ ...n, errors: void 0 }));
338
+ h.update(r, (n) => ({ ...n, errors: void 0 }));
482
339
  },
483
340
  // set a retry function
484
- setRetry: (n) => g.update(s, (l) => ({ ...l, retry: n })),
341
+ setRetry: (n) => h.update(r, (c) => ({ ...c, retry: n })),
485
342
  // promises
486
- whenLoaded: () => i("success").catch((n) => {
343
+ whenLoaded: () => t("success").catch((n) => {
487
344
  throw new Error("loading failed", { cause: n });
488
345
  }),
489
- whenFinished: () => i(["success", "error"]),
346
+ whenFinished: () => t(["success", "error"]),
490
347
  // wrap a promise
491
348
  wrap(n) {
492
- const l = () => new Promise((f, h) => {
493
- u.clearErrors(), u.set("loading"), n().then((d) => {
494
- u.set("success"), f(d);
495
- }).catch((d) => {
496
- u.set("error"), d && u.setErrors([d]), h(d);
349
+ const c = () => new Promise((f, l) => {
350
+ u.clearErrors(), u.set("loading"), n().then((g) => {
351
+ u.set("success"), f(g);
352
+ }).catch((g) => {
353
+ u.set("error"), g && u.setErrors([g]), l(g);
497
354
  });
498
355
  });
499
- return u.setRetry(l), l();
356
+ return u.setRetry(c), c();
500
357
  },
501
358
  wrapWithControl(n) {
502
- const l = {
359
+ const c = {
503
360
  thens: [],
504
361
  catchs: [],
505
362
  finallies: []
506
363
  }, f = {
507
- then: (...h) => (l.thens.push(h), f),
508
- catch_: (...h) => (l.catchs.push(h), f),
509
- finally_: (...h) => (l.finallies.push(h), f),
510
- start: () => new Promise((h, d) => {
364
+ then: (...l) => (c.thens.push(l), f),
365
+ catch_: (...l) => (c.catchs.push(l), f),
366
+ finally_: (...l) => (c.finallies.push(l), f),
367
+ start: () => new Promise((l, g) => {
511
368
  u.clearErrors(), u.set("loading");
512
- let x = n();
513
- x.then(() => {
369
+ let v = n();
370
+ v.then(() => {
514
371
  u.set("success");
515
- }), x.catch((y) => {
372
+ }), v.catch((y) => {
516
373
  u.set("error"), y && u.setErrors([y]);
517
374
  });
518
- for (const y of l.thens)
519
- x.then(...y);
520
- for (const y of l.catchs)
521
- x.catch(...y);
522
- for (const y of l.finallies)
523
- x.finally(...y);
524
- x.then(h, d);
375
+ for (const y of c.thens)
376
+ v.then(...y);
377
+ for (const y of c.catchs)
378
+ v.catch(...y);
379
+ for (const y of c.finallies)
380
+ v.finally(...y);
381
+ v.then(l, g);
525
382
  })
526
383
  };
527
384
  return u.setRetry(f.start), f;
528
385
  },
529
386
  // components
530
387
  // - show when
531
- ShowWhenLoaded: ({ children: n, fallback: l, errorFallback: f }) => {
532
- const h = v(s, (d) => d.state);
533
- return h === "idle" ? null : (l = k(e, l), f = B(t, f === !0 ? void 0 : f), h === "loading" ? /* @__PURE__ */ p(b, { children: l }) : h === "error" ? /* @__PURE__ */ p(b, { children: m(f, u.getErrors() ?? [], () => u.retry()) }) : /* @__PURE__ */ p(b, { children: n }));
388
+ ShowWhenLoaded: ({ children: n, fallback: c, errorFallback: f }) => {
389
+ const l = E(r, (g) => g.state);
390
+ return l === "idle" ? null : (c = P(e, c), f = B(s, f === !0 ? void 0 : f), l === "loading" ? /* @__PURE__ */ p(w, { children: c }) : l === "error" ? /* @__PURE__ */ p(w, { children: S(f, u.getErrors() ?? [], () => u.retry()) }) : /* @__PURE__ */ p(w, { children: n }));
534
391
  },
535
- ShowWhileLoading: o("loading"),
536
- ShowWhenError: o("error", () => [u.getErrors() ?? [], () => u.retry()]),
537
- ShowWhenFinish: o(["error", "success"], () => [u.getErrors(), () => u.retry()]),
538
- ShowWhen: ({ children: n, state: l }) => {
539
- const f = o(l);
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: c }) => {
396
+ const f = a(c);
540
397
  return /* @__PURE__ */ p(f, { children: n });
541
- }
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
- }, pe = ({ of: a, fallback: e, errorFallback: t, children: r }) => {
545
- const s = a.map((i) => i.use());
546
- return e = k(void 0, e), s.some((i) => i === "loading") ? e : s.every((i) => i !== "loading") ? s.some((i) => i === "error") ? (t = B(void 0, t), /* @__PURE__ */ p(b, { children: m(
547
- t,
548
- a.reduce((i, o) => [...i, ...o.getErrors() ?? []], []),
411
+ }, oe = (o = {}) => {
412
+ const e = j(ee(o));
413
+ return O(() => () => {
414
+ e.current.destroy();
415
+ }, []), e.current;
416
+ }, ue = ({ of: o, fallback: e, errorFallback: s, children: i }) => {
417
+ const r = o.map((t) => t.use());
418
+ 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: S(
419
+ s,
420
+ o.reduce((t, a) => [...t, ...a.getErrors() ?? []], []),
549
421
  () => {
550
- a.map((i) => {
551
- i.isError() && i.retry();
422
+ o.map((t) => {
423
+ t.isError() && t.retry();
552
424
  });
553
425
  }
554
- ) })) : /* @__PURE__ */ p(b, { children: r }) : null;
426
+ ) })) : /* @__PURE__ */ p(w, { children: i }) : null;
555
427
  };
556
428
  export {
557
- pe as AllLoaded,
558
- de as createLoading,
429
+ ue as AllLoaded,
430
+ ee as createLoading,
559
431
  C as errorFallbacks,
560
- _ as fallbacks,
561
- U as getDefaultErrorFallback,
562
- T as getDefaultFallback,
563
- m as reactNodeOrFunctionValue,
564
- ge as registerDefaultErrorFallback,
565
- he as registerDefaultFallback,
566
- ce as registerErrorFallback,
567
- fe as registerFallback,
432
+ k as fallbacks,
433
+ K as getDefaultErrorFallback,
434
+ I as getDefaultFallback,
435
+ S as reactNodeOrFunctionValue,
436
+ ae as registerDefaultErrorFallback,
437
+ ie as registerDefaultFallback,
438
+ ne as registerErrorFallback,
439
+ se as registerFallback,
568
440
  B as resolveErrorFallback,
569
- k as resolveLoadingFallback
441
+ P as resolveLoadingFallback,
442
+ oe as useCreateLocalLoading
570
443
  };
package/dist/main.min.js CHANGED
@@ -1,13 +1,8 @@
1
1
  /*!
2
- * react-easy-loading v0.1.0
2
+ * react-easy-loading v0.2.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:()=>p.get(s).retry?.(),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 m=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=>{m=o},z=o=>{C=o},V=()=>m,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 O,B;function Q(){if(B)return O;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,c;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 f;if(e&&t instanceof Map&&a instanceof Map){if(t.size!==a.size)return!1;for(f=t.entries();!(n=f.next()).done;)if(!a.has(n.value[0]))return!1;for(f=t.entries();!(n=f.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(f=t.entries();!(n=f.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(c=Object.keys(t),l=c.length,l!==Object.keys(a).length)return!1;for(n=l;n--!==0;)if(!Object.prototype.hasOwnProperty.call(a,c[n]))return!1;if(o&&t instanceof Element)return!1;for(n=l;n--!==0;)if(!((c[n]==="_owner"||c[n]==="__v"||c[n]==="__o")&&t.$$typeof)&&!r(t[c[n]],a[c[n]]))return!1;return!0}return t!==t&&a!==a}return O=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}},O}var X=Q();const Y=J(X),x=new y,g=new G(x),Z=(o,e)=>x.createStatic({initialValue:o},o,e);function L(o,e,s){let i,r=s;if(typeof o!="string"){const{key:f,prefix:h}=o;i=f,r=h}else i=_(o);const{prefix:t}=H(r),a=v.useRef(void 0),l=v.useMemo(()=>f=>(x.init(i,t,void 0),x.addListener(i,t,f),()=>{x.removeListener(i,t,f)}),[i,t]),n=v.useMemo(()=>()=>{const f=x.get(i,t)?.value,h=e(f);return Y(a.current,h)?a.current:(a.current=h,h)},[i,t,e]),c=v.useSyncExternalStore(l,n);return x.useEffect(i,t),c}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 c=l.get();return new Promise((f,h)=>{if(S(l.get(),n)){f();return}const p=g.subscribe(r,()=>{S(l.get(),n)?(p(),f()):c!==l.get()&&h()})})},a=function(n,c=()=>[]){return f=>L(r,p=>S(p.state,n))?u.jsx(u.Fragment,{children:w(f.children,...c())}):null},l={use:()=>L(r,n=>n.state),useIsLoading:()=>L(r,n=>n.state)==="loading",useErrors:()=>L(r,n=>n.errors),useContext:()=>L(r,n=>n.context),set:n=>g.update(r,c=>({...c,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,c=>({...c,errors:[...c.errors??[],n]}))},setContext:n=>{g.update(r,c=>({...c,context:n}))},setErrors:n=>{g.update(r,c=>({...c,errors:n}))},clearErrors:()=>{g.update(r,n=>({...n,errors:void 0}))},setRetry:n=>g.update(r,c=>({...c,retry:n})),whenLoaded:()=>t("success").catch(n=>{throw new Error("loading failed",{cause:n})}),whenFinished:()=>t(["success","error"]),wrap(n){const c=()=>new Promise((f,h)=>{l.clearErrors(),l.set("loading"),n().then(p=>{l.set("success"),f(p)}).catch(p=>{l.set("error"),p&&l.setErrors([p]),h(p)})});return l.setRetry(c),c()},wrapWithControl(n){const c={thens:[],catchs:[],finallies:[]},f={then:(...h)=>(c.thens.push(h),f),catch_:(...h)=>(c.catchs.push(h),f),finally_:(...h)=>(c.finallies.push(h),f),start:()=>new Promise((h,p)=>{l.clearErrors(),l.set("loading");let b=n();b.then(()=>{l.set("success")}),b.catch(E=>{l.set("error"),E&&l.setErrors([E])});for(const E of c.thens)b.then(...E);for(const E of c.catchs)b.catch(...E);for(const E of c.finallies)b.finally(...E);b.then(h,p)})};return l.setRetry(f.start),f},ShowWhenLoaded:({children:n,fallback:c,errorFallback:f})=>{const h=L(r,p=>p.state);return h==="idle"?null:(c=F(e,c),f=A(s,f===!0?void 0:f),h==="loading"?u.jsx(u.Fragment,{children:c}):h==="error"?u.jsx(u.Fragment,{children:w(f,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:c})=>{const f=a(c);return u.jsx(f,{children:n})},destroy:()=>{g.clear(r)},__get__id:()=>`loading_id//${r.prefix}/${r.key}`};return l},R=(o={})=>{const e=v.useRef($(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.1.0",
3
+ "version": "0.2.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": "^24.6.2",
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.22",
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": "^3.2.4"
56
+ "vitest": "^4.0.15"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "vite build",