react-easy-loading 0.3.4-beta → 0.3.6-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * react-easy-loading v0.3.4-beta
2
+ * react-easy-loading v0.3.6-beta
3
3
  * (c) Hichem Taboukouyout
4
4
  * Released under the MIT License.
5
5
  * Github: github.com/HichemTab-tech/react-easy-loading
@@ -127,7 +127,7 @@ class d {
127
127
  i?.(), N(`[${d.prefix(e, s)}]`, "unmount effect");
128
128
  const r = this.get(e, s);
129
129
  r && r.listeners?.length === 0 && this.clear(e, s);
130
- }, [e, s]);
130
+ }, []);
131
131
  }
132
132
  }
133
133
  class A {
package/dist/main.min.js CHANGED
@@ -1,8 +1,8 @@
1
1
  /*!
2
- * react-easy-loading v0.3.4-beta
2
+ * react-easy-loading v0.3.6-beta
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,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],f):(d=typeof globalThis<"u"?globalThis:d||self,f(d.ReactEasyLoading={},d.jsxRuntime,d.React))})(this,(function(d,f,v){"use strict";const D={},F={},W=(a,e)=>{D[a]=e},z=(a,e)=>{F[a]=e};let q=f.jsx("div",{children:"Loading..."}),C=(a,e)=>f.jsxs("div",{children:[f.jsx("h3",{children:"Errors:"}),f.jsx("ul",{children:a?.map((s,i)=>f.jsx("li",{children:s},i))}),f.jsx("button",{onClick:e,disabled:!e,children:"Retry"})]});const K=a=>{q=a},N=a=>{C=a},j=()=>q,M=()=>C,k=(a,e)=>P(j,D,a,e);function m(a,e){return P(M,F,a,e)}function P(a,e,s,i){return i?typeof i=="string"?e[i]??i:i:i===null?null:s?typeof s=="string"?e[s]??s:s:a()}function w(a,...e){return typeof a=="function"?a(...e):a}const U=(...a)=>{},A=a=>{if(!a)throw new Error("Value is empty");return a},I=()=>Math.random().toString(36).substring(2,15),G=v.createContext(void 0),H=()=>v.useContext(G),$=[],S=Symbol.for("react-shared-states.manager");function J(a,e=()=>null){const s=globalThis;return s[S]||(s[S]={}),s[S][a]||(s[S][a]=new y(e)),s[S][a]}class y{constructor(e=()=>null){this.defaultValue=e,this._uniqueId=I()}data=new Map;_uniqueId;__get__uniqueId(){return this._uniqueId}static getInstance(e,s=()=>null){return J(e,s)}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(o=>o!==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:I(),prefix:r,...e};return $.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,o]=y.extractPrefix(r);this.clear(o,t,e,s)})}clear(e,s,i=!1,r=!1){const t=y.prefix(e,s);i||this.callListeners(e,s);const o=this.data.get(t);if(o&&(this.data.delete(t),o.isStatic&&!r)){const u=$.find(n=>n.key===e&&n.prefix===s);u&&this.initStatic(u)}}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?.(),U(`[${y.prefix(e,s)}]`,"unmount effect");const r=this.get(e,s);r&&r.listeners?.length===0&&this.clear(e,s)},[e,s])}}class O{constructor(e){this.sharedData=e,this._uniqueId=I()}_uniqueId;_get(e,s){let i,r=s;if(typeof e!="string"){const{key:u,prefix:n}=e;i=u,r=n}else i=A(e);const t=r||"_global",o=this.sharedData.get(i,t);return o?{value:o.value,key:i,prefix:t}:{key:i,prefix:t,value:void 0}}__log_instance_id(){return{apiId:this._uniqueId,managerId:this.sharedData.__get__uniqueId()}}get(e,s){return this._get(e,s).value}set(e,s,i){let r,t=i;if(typeof e!="string"){const{key:u,prefix:n}=e;r=u,t=n}else r=A(e);const o=t||"_global";this.sharedData.init(r,o,s),this.sharedData.setValue(r,o,s),this.sharedData.callListeners(r,o)}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,o]=y.extractPrefix(r);t===s&&(this.sharedData.clear(o,t),this.sharedData.callListeners(o,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 Q=a=>{const e=H();return{prefix:a??e?.scopeName??"_global"}};function X(a){return a&&a.__esModule&&Object.prototype.hasOwnProperty.call(a,"default")?a.default:a}var V,B;function Y(){if(B)return V;B=1;var a=typeof Element<"u",e=typeof Map=="function",s=typeof Set=="function",i=typeof ArrayBuffer=="function"&&!!ArrayBuffer.isView;function r(t,o){if(t===o)return!0;if(t&&o&&typeof t=="object"&&typeof o=="object"){if(t.constructor!==o.constructor)return!1;var u,n,l;if(Array.isArray(t)){if(u=t.length,u!=o.length)return!1;for(n=u;n--!==0;)if(!r(t[n],o[n]))return!1;return!0}var c;if(e&&t instanceof Map&&o instanceof Map){if(t.size!==o.size)return!1;for(c=t.entries();!(n=c.next()).done;)if(!o.has(n.value[0]))return!1;for(c=t.entries();!(n=c.next()).done;)if(!r(n.value[1],o.get(n.value[0])))return!1;return!0}if(s&&t instanceof Set&&o instanceof Set){if(t.size!==o.size)return!1;for(c=t.entries();!(n=c.next()).done;)if(!o.has(n.value[0]))return!1;return!0}if(i&&ArrayBuffer.isView(t)&&ArrayBuffer.isView(o)){if(u=t.length,u!=o.length)return!1;for(n=u;n--!==0;)if(t[n]!==o[n])return!1;return!0}if(t.constructor===RegExp)return t.source===o.source&&t.flags===o.flags;if(t.valueOf!==Object.prototype.valueOf&&typeof t.valueOf=="function"&&typeof o.valueOf=="function")return t.valueOf()===o.valueOf();if(t.toString!==Object.prototype.toString&&typeof t.toString=="function"&&typeof o.toString=="function")return t.toString()===o.toString();if(l=Object.keys(t),u=l.length,u!==Object.keys(o).length)return!1;for(n=u;n--!==0;)if(!Object.prototype.hasOwnProperty.call(o,l[n]))return!1;if(a&&t instanceof Element)return!1;for(n=u;n--!==0;)if(!((l[n]==="_owner"||l[n]==="__v"||l[n]==="__o")&&t.$$typeof)&&!r(t[l[n]],o[l[n]]))return!1;return!0}return t!==t&&o!==o}return V=function(t,o){try{return r(t,o)}catch(u){if((u.message||"").match(/stack|recursion/i))return console.warn("react-fast-compare cannot handle circular refs"),!1;throw u}},V}var Z=Y();const R=X(Z),_=y.getInstance("sharedStatesManager"),g=new O(_),ee=(a,e)=>_.createStatic({initialValue:a},a,e);function b(a,e,s){let i,r=s;if(typeof a!="string"){const{key:c,prefix:h}=a;i=c,r=h}else i=A(a);const{prefix:t}=Q(r),o=v.useRef(void 0),u=v.useMemo(()=>c=>(_.init(i,t,void 0),_.addListener(i,t,c),()=>{_.removeListener(i,t,c)}),[i,t]),n=v.useMemo(()=>()=>{const c=_.get(i,t)?.value,h=e(c);return R(o.current,h)?o.current:(o.current=h,h)},[i,t,e]),l=v.useSyncExternalStore(u,n);return _.useEffect(i,t),l}const te=y.getInstance("SharedFunctionValue");new O(te);const re=y.getInstance("SharedSubscription");new O(re);const L=(a,e)=>Array.isArray(e)&&e.includes(a)||a===e,T=({initialState:a="loading",defaultFallback:e,defaultErrorFallback:s,defaultRetry:i}={})=>{const r=ee({state:a,retry:i}),t=n=>{let l=u.get();return new Promise((c,h)=>{if(L(u.get(),n)){c();return}const p=g.subscribe(r,()=>{L(u.get(),n)?(p(),c()):l!==u.get()&&h()})})},o=function(n,l=()=>[]){return c=>b(r,p=>L(p.state,n))?f.jsx(f.Fragment,{children:w(c.children,...l())}):null},u={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,l=>({...l,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=>L(u.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:a}),addError:n=>{g.update(r,l=>({...l,errors:[...l.errors??[],n]}))},setContext:n=>{g.update(r,l=>({...l,context:n}))},setErrors:n=>{g.update(r,l=>({...l,errors:n}))},clearErrors:()=>{g.update(r,n=>({...n,errors:void 0}))},setRetry:n=>g.update(r,l=>({...l,retry:n})),whenLoaded:()=>t("success").catch(n=>{throw new Error("loading failed",{cause:n})}),whenFinished:()=>t(["success","error"]),wrap(n){const l=()=>new Promise((c,h)=>{u.clearErrors(),u.set("loading"),n().then(p=>{u.set("success"),c(p)}).catch(p=>{u.set("error"),p&&u.setErrors([p]),h(p)})});return u.setRetry(l),l()},wrapWithControl(n){const l={thens:[],catchs:[],finallies:[]},c={then:(...h)=>(l.thens.push(h),c),catch_:(...h)=>(l.catchs.push(h),c),finally_:(...h)=>(l.finallies.push(h),c),start:()=>new Promise((h,p)=>{u.clearErrors(),u.set("loading");let x=n();x.then(()=>{u.set("success")}),x.catch(E=>{u.set("error"),E&&u.setErrors([E])});for(const E of l.thens)x.then(...E);for(const E of l.catchs)x.catch(...E);for(const E of l.finallies)x.finally(...E);x.then(h,p)})};return u.setRetry(c.start),c},ShowWhenLoaded:({children:n,fallback:l,errorFallback:c})=>{const h=b(r,p=>p.state);return h==="idle"?null:(l=k(e,l),c=m(s,c===!0?void 0:c),h==="loading"?f.jsx(f.Fragment,{children:l}):h==="error"?f.jsx(f.Fragment,{children:w(c,u.getErrors()??[],()=>u.retry())}):f.jsx(f.Fragment,{children:n}))},ShowWhileLoading:o("loading"),ShowWhenError:o("error",()=>[u.getErrors()??[],()=>u.retry()]),ShowWhenFinish:o(["error","success"],()=>[u.getErrors(),()=>u.retry()]),ShowWhen:({children:n,state:l})=>{const c=o(l);return f.jsx(c,{children:n})},destroy:()=>{g.clear(r)},__get__id:()=>({loadingId:`loading_id//${r.prefix}/${r.key}`,...g.__log_instance_id()})};return u},se=a=>T(typeof a=="string"?{initialState:a}:a),ne=(a={})=>{const e=v.useRef(void 0);return e.current||(e.current=se(a)),v.useEffect(()=>()=>{e.current.destroy(),e.current=void 0},[]),e.current},ie=({of:a,fallback:e,errorFallback:s,children:i})=>{const r=a.map(t=>t.use());return e=k(void 0,e),r.some(t=>t==="loading")?e:r.every(t=>t!=="loading")?r.some(t=>t==="error")?(s=m(void 0,s),f.jsx(f.Fragment,{children:w(s,a.reduce((t,o)=>[...t,...o.getErrors()??[]],[]),()=>{a.map(t=>{t.isError()&&t.retry()})})})):f.jsx(f.Fragment,{children:i}):null};d.AllLoaded=ie,d.createLoading=T,d.errorFallbacks=F,d.fallbacks=D,d.getDefaultErrorFallback=M,d.getDefaultFallback=j,d.reactNodeOrFunctionValue=w,d.registerDefaultErrorFallback=N,d.registerDefaultFallback=K,d.registerErrorFallback=z,d.registerFallback=W,d.resolveErrorFallback=m,d.resolveLoadingFallback=k,d.useCreateLocalLoading=ne,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})}));
8
+ (function(d,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],f):(d=typeof globalThis<"u"?globalThis:d||self,f(d.ReactEasyLoading={},d.jsxRuntime,d.React))})(this,(function(d,f,v){"use strict";const D={},F={},W=(a,e)=>{D[a]=e},z=(a,e)=>{F[a]=e};let q=f.jsx("div",{children:"Loading..."}),C=(a,e)=>f.jsxs("div",{children:[f.jsx("h3",{children:"Errors:"}),f.jsx("ul",{children:a?.map((s,i)=>f.jsx("li",{children:s},i))}),f.jsx("button",{onClick:e,disabled:!e,children:"Retry"})]});const K=a=>{q=a},N=a=>{C=a},j=()=>q,M=()=>C,k=(a,e)=>P(j,D,a,e);function m(a,e){return P(M,F,a,e)}function P(a,e,s,i){return i?typeof i=="string"?e[i]??i:i:i===null?null:s?typeof s=="string"?e[s]??s:s:a()}function w(a,...e){return typeof a=="function"?a(...e):a}const U=(...a)=>{},A=a=>{if(!a)throw new Error("Value is empty");return a},I=()=>Math.random().toString(36).substring(2,15),G=v.createContext(void 0),H=()=>v.useContext(G),$=[],S=Symbol.for("react-shared-states.manager");function J(a,e=()=>null){const s=globalThis;return s[S]||(s[S]={}),s[S][a]||(s[S][a]=new y(e)),s[S][a]}class y{constructor(e=()=>null){this.defaultValue=e,this._uniqueId=I()}data=new Map;_uniqueId;__get__uniqueId(){return this._uniqueId}static getInstance(e,s=()=>null){return J(e,s)}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(o=>o!==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:I(),prefix:r,...e};return $.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,o]=y.extractPrefix(r);this.clear(o,t,e,s)})}clear(e,s,i=!1,r=!1){const t=y.prefix(e,s);i||this.callListeners(e,s);const o=this.data.get(t);if(o&&(this.data.delete(t),o.isStatic&&!r)){const u=$.find(n=>n.key===e&&n.prefix===s);u&&this.initStatic(u)}}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?.(),U(`[${y.prefix(e,s)}]`,"unmount effect");const r=this.get(e,s);r&&r.listeners?.length===0&&this.clear(e,s)},[])}}class O{constructor(e){this.sharedData=e,this._uniqueId=I()}_uniqueId;_get(e,s){let i,r=s;if(typeof e!="string"){const{key:u,prefix:n}=e;i=u,r=n}else i=A(e);const t=r||"_global",o=this.sharedData.get(i,t);return o?{value:o.value,key:i,prefix:t}:{key:i,prefix:t,value:void 0}}__log_instance_id(){return{apiId:this._uniqueId,managerId:this.sharedData.__get__uniqueId()}}get(e,s){return this._get(e,s).value}set(e,s,i){let r,t=i;if(typeof e!="string"){const{key:u,prefix:n}=e;r=u,t=n}else r=A(e);const o=t||"_global";this.sharedData.init(r,o,s),this.sharedData.setValue(r,o,s),this.sharedData.callListeners(r,o)}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,o]=y.extractPrefix(r);t===s&&(this.sharedData.clear(o,t),this.sharedData.callListeners(o,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 Q=a=>{const e=H();return{prefix:a??e?.scopeName??"_global"}};function X(a){return a&&a.__esModule&&Object.prototype.hasOwnProperty.call(a,"default")?a.default:a}var V,B;function Y(){if(B)return V;B=1;var a=typeof Element<"u",e=typeof Map=="function",s=typeof Set=="function",i=typeof ArrayBuffer=="function"&&!!ArrayBuffer.isView;function r(t,o){if(t===o)return!0;if(t&&o&&typeof t=="object"&&typeof o=="object"){if(t.constructor!==o.constructor)return!1;var u,n,l;if(Array.isArray(t)){if(u=t.length,u!=o.length)return!1;for(n=u;n--!==0;)if(!r(t[n],o[n]))return!1;return!0}var c;if(e&&t instanceof Map&&o instanceof Map){if(t.size!==o.size)return!1;for(c=t.entries();!(n=c.next()).done;)if(!o.has(n.value[0]))return!1;for(c=t.entries();!(n=c.next()).done;)if(!r(n.value[1],o.get(n.value[0])))return!1;return!0}if(s&&t instanceof Set&&o instanceof Set){if(t.size!==o.size)return!1;for(c=t.entries();!(n=c.next()).done;)if(!o.has(n.value[0]))return!1;return!0}if(i&&ArrayBuffer.isView(t)&&ArrayBuffer.isView(o)){if(u=t.length,u!=o.length)return!1;for(n=u;n--!==0;)if(t[n]!==o[n])return!1;return!0}if(t.constructor===RegExp)return t.source===o.source&&t.flags===o.flags;if(t.valueOf!==Object.prototype.valueOf&&typeof t.valueOf=="function"&&typeof o.valueOf=="function")return t.valueOf()===o.valueOf();if(t.toString!==Object.prototype.toString&&typeof t.toString=="function"&&typeof o.toString=="function")return t.toString()===o.toString();if(l=Object.keys(t),u=l.length,u!==Object.keys(o).length)return!1;for(n=u;n--!==0;)if(!Object.prototype.hasOwnProperty.call(o,l[n]))return!1;if(a&&t instanceof Element)return!1;for(n=u;n--!==0;)if(!((l[n]==="_owner"||l[n]==="__v"||l[n]==="__o")&&t.$$typeof)&&!r(t[l[n]],o[l[n]]))return!1;return!0}return t!==t&&o!==o}return V=function(t,o){try{return r(t,o)}catch(u){if((u.message||"").match(/stack|recursion/i))return console.warn("react-fast-compare cannot handle circular refs"),!1;throw u}},V}var Z=Y();const R=X(Z),_=y.getInstance("sharedStatesManager"),g=new O(_),ee=(a,e)=>_.createStatic({initialValue:a},a,e);function b(a,e,s){let i,r=s;if(typeof a!="string"){const{key:c,prefix:h}=a;i=c,r=h}else i=A(a);const{prefix:t}=Q(r),o=v.useRef(void 0),u=v.useMemo(()=>c=>(_.init(i,t,void 0),_.addListener(i,t,c),()=>{_.removeListener(i,t,c)}),[i,t]),n=v.useMemo(()=>()=>{const c=_.get(i,t)?.value,h=e(c);return R(o.current,h)?o.current:(o.current=h,h)},[i,t,e]),l=v.useSyncExternalStore(u,n);return _.useEffect(i,t),l}const te=y.getInstance("SharedFunctionValue");new O(te);const re=y.getInstance("SharedSubscription");new O(re);const L=(a,e)=>Array.isArray(e)&&e.includes(a)||a===e,T=({initialState:a="loading",defaultFallback:e,defaultErrorFallback:s,defaultRetry:i}={})=>{const r=ee({state:a,retry:i}),t=n=>{let l=u.get();return new Promise((c,h)=>{if(L(u.get(),n)){c();return}const p=g.subscribe(r,()=>{L(u.get(),n)?(p(),c()):l!==u.get()&&h()})})},o=function(n,l=()=>[]){return c=>b(r,p=>L(p.state,n))?f.jsx(f.Fragment,{children:w(c.children,...l())}):null},u={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,l=>({...l,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=>L(u.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:a}),addError:n=>{g.update(r,l=>({...l,errors:[...l.errors??[],n]}))},setContext:n=>{g.update(r,l=>({...l,context:n}))},setErrors:n=>{g.update(r,l=>({...l,errors:n}))},clearErrors:()=>{g.update(r,n=>({...n,errors:void 0}))},setRetry:n=>g.update(r,l=>({...l,retry:n})),whenLoaded:()=>t("success").catch(n=>{throw new Error("loading failed",{cause:n})}),whenFinished:()=>t(["success","error"]),wrap(n){const l=()=>new Promise((c,h)=>{u.clearErrors(),u.set("loading"),n().then(p=>{u.set("success"),c(p)}).catch(p=>{u.set("error"),p&&u.setErrors([p]),h(p)})});return u.setRetry(l),l()},wrapWithControl(n){const l={thens:[],catchs:[],finallies:[]},c={then:(...h)=>(l.thens.push(h),c),catch_:(...h)=>(l.catchs.push(h),c),finally_:(...h)=>(l.finallies.push(h),c),start:()=>new Promise((h,p)=>{u.clearErrors(),u.set("loading");let x=n();x.then(()=>{u.set("success")}),x.catch(E=>{u.set("error"),E&&u.setErrors([E])});for(const E of l.thens)x.then(...E);for(const E of l.catchs)x.catch(...E);for(const E of l.finallies)x.finally(...E);x.then(h,p)})};return u.setRetry(c.start),c},ShowWhenLoaded:({children:n,fallback:l,errorFallback:c})=>{const h=b(r,p=>p.state);return h==="idle"?null:(l=k(e,l),c=m(s,c===!0?void 0:c),h==="loading"?f.jsx(f.Fragment,{children:l}):h==="error"?f.jsx(f.Fragment,{children:w(c,u.getErrors()??[],()=>u.retry())}):f.jsx(f.Fragment,{children:n}))},ShowWhileLoading:o("loading"),ShowWhenError:o("error",()=>[u.getErrors()??[],()=>u.retry()]),ShowWhenFinish:o(["error","success"],()=>[u.getErrors(),()=>u.retry()]),ShowWhen:({children:n,state:l})=>{const c=o(l);return f.jsx(c,{children:n})},destroy:()=>{g.clear(r)},__get__id:()=>({loadingId:`loading_id//${r.prefix}/${r.key}`,...g.__log_instance_id()})};return u},se=a=>T(typeof a=="string"?{initialState:a}:a),ne=(a={})=>{const e=v.useRef(void 0);return e.current||(e.current=se(a)),v.useEffect(()=>()=>{e.current.destroy(),e.current=void 0},[]),e.current},ie=({of:a,fallback:e,errorFallback:s,children:i})=>{const r=a.map(t=>t.use());return e=k(void 0,e),r.some(t=>t==="loading")?e:r.every(t=>t!=="loading")?r.some(t=>t==="error")?(s=m(void 0,s),f.jsx(f.Fragment,{children:w(s,a.reduce((t,o)=>[...t,...o.getErrors()??[]],[]),()=>{a.map(t=>{t.isError()&&t.retry()})})})):f.jsx(f.Fragment,{children:i}):null};d.AllLoaded=ie,d.createLoading=T,d.errorFallbacks=F,d.fallbacks=D,d.getDefaultErrorFallback=M,d.getDefaultFallback=j,d.reactNodeOrFunctionValue=w,d.registerDefaultErrorFallback=N,d.registerDefaultFallback=K,d.registerErrorFallback=z,d.registerFallback=W,d.resolveErrorFallback=m,d.resolveLoadingFallback=k,d.useCreateLocalLoading=ne,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.4-beta",
3
+ "version": "0.3.6-beta",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "keywords": [
@@ -45,7 +45,7 @@
45
45
  "react": "^19.2.3",
46
46
  "react-dom": "^19.2.3",
47
47
  "react-exposed-states": "^1.0.5",
48
- "react-shared-states": "2.1.4-beta",
48
+ "react-shared-states": "2.1.6-beta",
49
49
  "tailwindcss": "^4.1.18",
50
50
  "typescript": "^5.9.3",
51
51
  "use-effect-skip-first": "^0.1.3",