@rokku-x/react-hook-loading-spinner 0.1.1 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +27 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +214 -145
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
`),o=i.findIndex(
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("react/jsx-runtime"),m=require("react"),N=require("react-dom"),I=n=>{let t;const e=new Set,i=(f,r)=>{const d=typeof f=="function"?f(t):f;if(!Object.is(d,t)){const g=t;t=r??(typeof d!="object"||d===null)?d:Object.assign({},t,d),e.forEach(u=>u(t,g))}},o=()=>t,s={setState:i,getState:o,getInitialState:()=>p,subscribe:f=>(e.add(f),()=>e.delete(f))},p=t=n(i,o,s);return s},D=(n=>n?I(n):I),F=n=>n;function M(n,t=F){const e=m.useSyncExternalStore(n.subscribe,m.useCallback(()=>t(n.getState()),[n,t]),m.useCallback(()=>t(n.getInitialState()),[n,t]));return m.useDebugValue(e),e}const j=n=>{const t=D(n),e=i=>M(t,i);return Object.assign(e,t),e},P=(n=>n?j(n):j),T={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},C=new Map,x=n=>{const t=C.get(n);return t?Object.fromEntries(Object.entries(t.stores).map(([e,i])=>[e,i.getState()])):{}},$=(n,t,e)=>{if(n===void 0)return{type:"untracked",connection:t.connect(e)};const i=C.get(e.name);if(i)return{type:"tracked",store:n,...i};const o={connection:t.connect(e),stores:{}};return C.set(e.name,o),{type:"tracked",store:n,...o}},J=(n,t)=>{if(t===void 0)return;const e=C.get(n);e&&(delete e.stores[t],Object.keys(e.stores).length===0&&C.delete(n))},U=n=>{var t,e;if(!n)return;const i=n.split(`
|
|
2
|
+
`),o=i.findIndex(v=>v.includes("api.setState"));if(o<0)return;const l=((t=i[o+1])==null?void 0:t.trim())||"";return(e=/.+ (.+) .+/.exec(l))==null?void 0:e[1]},z=(n,t={})=>(e,i,o)=>{const{enabled:l,anonymousActionType:v,store:s,...p}=t;let f;try{f=(l??(T?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!f)return n(e,i,o);const{connection:r,...d}=$(s,f,p);let g=!0;o.setState=((c,L,a)=>{const S=e(c,L);if(!g)return S;const _=a===void 0?{type:v||U(new Error().stack)||"anonymous"}:typeof a=="string"?{type:a}:a;return s===void 0?(r?.send(_,i()),S):(r?.send({..._,type:`${s}/${_.type}`},{...x(p.name),[s]:o.getState()}),S)}),o.devtools={cleanup:()=>{r&&typeof r.unsubscribe=="function"&&r.unsubscribe(),J(p.name,s)}};const u=(...c)=>{const L=g;g=!1,e(...c),g=L},E=n(o.setState,i,o);if(d.type==="untracked"?r?.init(E):(d.stores[d.store]=o,r?.init(Object.fromEntries(Object.entries(d.stores).map(([c,L])=>[c,c===d.store?E:L.getState()])))),o.dispatchFromDevtools&&typeof o.dispatch=="function"){let c=!1;const L=o.dispatch;o.dispatch=(...a)=>{(T?"production":void 0)!=="production"&&a[0].type==="__setState"&&!c&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),c=!0),L(...a)}}return r.subscribe(c=>{var L;switch(c.type){case"ACTION":if(typeof c.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return w(c.payload,a=>{if(a.type==="__setState"){if(s===void 0){u(a.state);return}Object.keys(a.state).length!==1&&console.error(`
|
|
3
3
|
[zustand devtools middleware] Unsupported __setState action format.
|
|
4
4
|
When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
|
|
5
5
|
and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }
|
|
6
|
-
`);const
|
|
6
|
+
`);const S=a.state[s];if(S==null)return;JSON.stringify(o.getState())!==JSON.stringify(S)&&u(S);return}o.dispatchFromDevtools&&typeof o.dispatch=="function"&&o.dispatch(a)});case"DISPATCH":switch(c.payload.type){case"RESET":return u(E),s===void 0?r?.init(o.getState()):r?.init(x(p.name));case"COMMIT":if(s===void 0){r?.init(o.getState());return}return r?.init(x(p.name));case"ROLLBACK":return w(c.state,a=>{if(s===void 0){u(a),r?.init(o.getState());return}u(a[s]),r?.init(x(p.name))});case"JUMP_TO_STATE":case"JUMP_TO_ACTION":return w(c.state,a=>{if(s===void 0){u(a);return}JSON.stringify(o.getState())!==JSON.stringify(a[s])&&u(a[s])});case"IMPORT_STATE":{const{nextLiftedState:a}=c.payload,S=(L=a.computedStates.slice(-1)[0])==null?void 0:L.state;if(!S)return;u(s===void 0?S:S[s]),r?.send(null,a);return}case"PAUSE_RECORDING":return g=!g}return}}),E},W=z,w=(n,t)=>{let e;try{e=JSON.parse(n)}catch(i){console.error("[zustand devtools middleware] Could not parse the received json",i)}e!==void 0&&t(e)};class R extends EventTarget{constructor(){super(...arguments),this.controller=new AbortController}on(t,e){return this.addEventListener(t,i=>e(i.detail),{signal:this.controller.signal}),this}once(t,e){return this.addEventListener(t,i=>e(i.detail),{signal:this.controller.signal,once:!0}),this}emit(t,e){return this.dispatchEvent(new CustomEvent(t,{detail:e}))}removeAllListeners(){this.controller.abort(),this.controller=new AbortController}}const b=new R,V=P()(W((n,t)=>({loadingCount:0,overrideState:null,localCounters:{},isLoading(){return t().overrideState??t().loadingCount>0},actions:{isGlobalLoading(){return t().isLoading()},startLoading:e=>{const i=t().isLoading();n(l=>({loadingCount:l.loadingCount+1})),e&&n(l=>({localCounters:{...l.localCounters,[e]:(l.localCounters[e]??0)+1}}));const o=t().isLoading();o&&!i&&b.emit("start",null),b.emit("change",{isLoading:o,isOverrideState:t().overrideState!==null})},stopLoading:e=>{const i=t().isLoading(),o=e?t().localCounters[e]??0:0;e&&o>0&&n(v=>({loadingCount:Math.max(0,v.loadingCount-1),localCounters:{...v.localCounters,[e]:Math.max(0,v.localCounters[e]-1)}}));const l=t().isLoading();!l&&i&&b.emit("stop",null),b.emit("change",{isLoading:l,isOverrideState:t().overrideState!==null})},overrideLoading:e=>{const i=t().isLoading();n({overrideState:e});const o=t().isLoading();o&&!i?b.emit("start",null):!o&&i&&b.emit("stop",null),b.emit("change",{isLoading:o,isOverrideState:e!==null})},getLocalCounter:e=>t().localCounters[e]??0,isLocalLoading:e=>(t().localCounters[e]??0)>0}})));function O(){const n=m.useId(),{actions:t}=V(l=>l),e=()=>{t.startLoading(n)},i=()=>{t.isLocalLoading(n)&&t.stopLoading(n)},o=async l=>{e();try{return await l}finally{i()}};return{overrideLoading:t.overrideLoading,startLoading:e,stopLoading:i,get isLocalLoading(){return t.isLocalLoading(n)},asyncUseLoading:o,get isLoading(){return t.isGlobalLoading()}}}const y={Spin:"spin",FadeInOut:"fadeInOut",None:"none"},q=({scale:n=1,animationType:t=y.Spin,animationDuration:e,children:i,style:o,className:l,id:v,prefix:s})=>{const p=t,f=t===y.Spin?1:t===y.FadeInOut?2:0,r=e||f,d=t===y.Spin?"linear":t===y.FadeInOut?"ease-in-out":"linear",g=t===y.None?"none":`${s}-${p} ${r}s ${d} infinite`;return h.jsx("div",{style:{animation:g,...n!==1?{zoom:n}:{},...o},className:l,id:v,children:i})},A=n=>h.jsx("div",{id:"loading-circle",style:{width:"90px",height:"90px",border:"15px solid #f3f3f3",borderTop:"15px solid #009b4bff",borderRadius:"50%",boxSizing:"border-box"},...n}),k=n=>h.jsx("div",{style:{padding:"20px",fontSize:"25px",color:"#333",fontFamily:"system-ui, sans-serif"},...n,children:"Please wait..."});function B({loadingComponent:n,loadingComponentScale:t=1,animationType:e=y.Spin,animationDuration:i,wrapperStyle:o,wrapperClassName:l,wrapperId:v,animationWrapperStyle:s,animationWrapperClassName:p,animationWrapperId:f}){n=n||(e===y.Spin?A:k);const r=m.useRef(Math.random().toString(36).substring(2,6).replace(/[0-9]/g,"")),{isLoading:d}=O(),g=m.useRef(null);m.useEffect(()=>{d?(g.current?.showModal(),document.body.setAttribute("inert","")):(g.current?.close(),document.body.removeAttribute("inert"))},[d]);const u=v||"loading-wrapper-"+r.current;return d?N.createPortal(h.jsxs(h.Fragment,{children:[h.jsx("style",{children:`
|
|
7
|
+
dialog#${u}[open] {
|
|
8
|
+
display: flex !important;
|
|
9
|
+
justify-content: center;
|
|
10
|
+
align-items: center;
|
|
11
|
+
width: 100vw;
|
|
12
|
+
height: 100vh;
|
|
13
|
+
max-width: 100%;
|
|
14
|
+
max-height: 100%;
|
|
15
|
+
}
|
|
16
|
+
@keyframes ${r.current}-spin {
|
|
17
|
+
0% { transform: rotate(0deg); }
|
|
18
|
+
100% { transform: rotate(360deg); }
|
|
19
|
+
}
|
|
20
|
+
@keyframes ${r.current}-fadeInOut {
|
|
21
|
+
0%, 100% { opacity: 0.2; }
|
|
22
|
+
50% { opacity: 1; }
|
|
23
|
+
}
|
|
24
|
+
body:has(dialog#${u}[open]) {
|
|
25
|
+
overflow: hidden;
|
|
26
|
+
}
|
|
27
|
+
body {
|
|
28
|
+
scrollbar-gutter: stable;
|
|
29
|
+
}
|
|
30
|
+
`}),h.jsx("dialog",{ref:g,style:{border:"none",padding:0,backgroundColor:"rgba(0, 0, 0, 0.5)",backdropFilter:"blur(2px)",...o},className:l,id:u,children:h.jsx(q,{scale:t,animationType:e,animationDuration:i,style:s,className:p,id:f,prefix:r.current,children:m.isValidElement(n)?n:m.createElement(n)})})]}),document.body):null}function G({isLoading:n=!1}){const{startLoading:t,stopLoading:e}=O();return m.useEffect(()=>(n?t():e(),()=>{n&&e()}),[n]),null}exports.AnimationType=y;exports.EventEmitter=R;exports.Loading=G;exports.LoadingCircle=A;exports.LoadingPleaseWait=k;exports.LoadingRenderer=B;exports.loadingEventTarget=b;exports.ssrLoading=O;exports.useLoading=O;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,5 +3,6 @@ export { default as ssrLoading } from './hooks/ssrLoading';
|
|
|
3
3
|
export { LoadingCircle, LoadingPleaseWait, AnimationType } from './components/LoadingRenderer';
|
|
4
4
|
export type { AnimationType as AnimationTypeType } from './components/LoadingRenderer';
|
|
5
5
|
export { default as Loading } from './components/Loading';
|
|
6
|
+
export { default as LoadingRenderer } from './components/LoadingRenderer';
|
|
6
7
|
export { default as EventEmitter } from './utils/EventEmitter';
|
|
7
8
|
export { loadingEventTarget } from './mainLogic';
|
package/dist/index.esm.js
CHANGED
|
@@ -1,218 +1,218 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import
|
|
4
|
-
import "react-dom";
|
|
5
|
-
const
|
|
2
|
+
import { jsx as L, jsxs as N, Fragment as j } from "react/jsx-runtime";
|
|
3
|
+
import y, { useId as D, useRef as x, useEffect as k } from "react";
|
|
4
|
+
import { createPortal as F } from "react-dom";
|
|
5
|
+
const I = (n) => {
|
|
6
6
|
let t;
|
|
7
|
-
const e = /* @__PURE__ */ new Set(),
|
|
8
|
-
const
|
|
9
|
-
if (!Object.is(
|
|
10
|
-
const
|
|
11
|
-
t =
|
|
7
|
+
const e = /* @__PURE__ */ new Set(), r = (f, i) => {
|
|
8
|
+
const d = typeof f == "function" ? f(t) : f;
|
|
9
|
+
if (!Object.is(d, t)) {
|
|
10
|
+
const g = t;
|
|
11
|
+
t = i ?? (typeof d != "object" || d === null) ? d : Object.assign({}, t, d), e.forEach((u) => u(t, g));
|
|
12
12
|
}
|
|
13
|
-
}, o = () => t,
|
|
14
|
-
return
|
|
15
|
-
},
|
|
16
|
-
function
|
|
17
|
-
const e =
|
|
13
|
+
}, o = () => t, s = { setState: r, getState: o, getInitialState: () => p, subscribe: (f) => (e.add(f), () => e.delete(f)) }, p = t = n(r, o, s);
|
|
14
|
+
return s;
|
|
15
|
+
}, M = ((n) => n ? I(n) : I), $ = (n) => n;
|
|
16
|
+
function P(n, t = $) {
|
|
17
|
+
const e = y.useSyncExternalStore(
|
|
18
18
|
n.subscribe,
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
y.useCallback(() => t(n.getState()), [n, t]),
|
|
20
|
+
y.useCallback(() => t(n.getInitialState()), [n, t])
|
|
21
21
|
);
|
|
22
|
-
return
|
|
22
|
+
return y.useDebugValue(e), e;
|
|
23
23
|
}
|
|
24
|
-
const
|
|
25
|
-
const t =
|
|
24
|
+
const T = (n) => {
|
|
25
|
+
const t = M(n), e = (r) => P(t, r);
|
|
26
26
|
return Object.assign(e, t), e;
|
|
27
|
-
},
|
|
28
|
-
const t =
|
|
27
|
+
}, J = ((n) => n ? T(n) : T), R = { BASE_URL: "/", DEV: !1, MODE: "production", PROD: !0, SSR: !1 }, C = /* @__PURE__ */ new Map(), w = (n) => {
|
|
28
|
+
const t = C.get(n);
|
|
29
29
|
return t ? Object.fromEntries(
|
|
30
|
-
Object.entries(t.stores).map(([e,
|
|
30
|
+
Object.entries(t.stores).map(([e, r]) => [e, r.getState()])
|
|
31
31
|
) : {};
|
|
32
|
-
},
|
|
32
|
+
}, U = (n, t, e) => {
|
|
33
33
|
if (n === void 0)
|
|
34
34
|
return {
|
|
35
35
|
type: "untracked",
|
|
36
36
|
connection: t.connect(e)
|
|
37
37
|
};
|
|
38
|
-
const
|
|
39
|
-
if (
|
|
40
|
-
return { type: "tracked", store: n, ...
|
|
38
|
+
const r = C.get(e.name);
|
|
39
|
+
if (r)
|
|
40
|
+
return { type: "tracked", store: n, ...r };
|
|
41
41
|
const o = {
|
|
42
42
|
connection: t.connect(e),
|
|
43
43
|
stores: {}
|
|
44
44
|
};
|
|
45
|
-
return
|
|
46
|
-
},
|
|
45
|
+
return C.set(e.name, o), { type: "tracked", store: n, ...o };
|
|
46
|
+
}, z = (n, t) => {
|
|
47
47
|
if (t === void 0) return;
|
|
48
|
-
const e =
|
|
49
|
-
e && (delete e.stores[t], Object.keys(e.stores).length === 0 &&
|
|
50
|
-
},
|
|
48
|
+
const e = C.get(n);
|
|
49
|
+
e && (delete e.stores[t], Object.keys(e.stores).length === 0 && C.delete(n));
|
|
50
|
+
}, V = (n) => {
|
|
51
51
|
var t, e;
|
|
52
52
|
if (!n) return;
|
|
53
|
-
const
|
|
54
|
-
`), o =
|
|
55
|
-
(
|
|
53
|
+
const r = n.split(`
|
|
54
|
+
`), o = r.findIndex(
|
|
55
|
+
(v) => v.includes("api.setState")
|
|
56
56
|
);
|
|
57
57
|
if (o < 0) return;
|
|
58
|
-
const
|
|
59
|
-
return (e = /.+ (.+) .+/.exec(
|
|
60
|
-
},
|
|
61
|
-
const { enabled:
|
|
62
|
-
let
|
|
58
|
+
const l = ((t = r[o + 1]) == null ? void 0 : t.trim()) || "";
|
|
59
|
+
return (e = /.+ (.+) .+/.exec(l)) == null ? void 0 : e[1];
|
|
60
|
+
}, W = (n, t = {}) => (e, r, o) => {
|
|
61
|
+
const { enabled: l, anonymousActionType: v, store: s, ...p } = t;
|
|
62
|
+
let f;
|
|
63
63
|
try {
|
|
64
|
-
|
|
64
|
+
f = (l ?? (R ? "production" : void 0) !== "production") && window.__REDUX_DEVTOOLS_EXTENSION__;
|
|
65
65
|
} catch {
|
|
66
66
|
}
|
|
67
|
-
if (!
|
|
68
|
-
return n(e,
|
|
69
|
-
const { connection:
|
|
70
|
-
let
|
|
71
|
-
o.setState = ((
|
|
72
|
-
const
|
|
73
|
-
if (!
|
|
74
|
-
const
|
|
75
|
-
type:
|
|
76
|
-
} : typeof
|
|
77
|
-
return
|
|
67
|
+
if (!f)
|
|
68
|
+
return n(e, r, o);
|
|
69
|
+
const { connection: i, ...d } = U(s, f, p);
|
|
70
|
+
let g = !0;
|
|
71
|
+
o.setState = ((c, m, a) => {
|
|
72
|
+
const S = e(c, m);
|
|
73
|
+
if (!g) return S;
|
|
74
|
+
const O = a === void 0 ? {
|
|
75
|
+
type: v || V(new Error().stack) || "anonymous"
|
|
76
|
+
} : typeof a == "string" ? { type: a } : a;
|
|
77
|
+
return s === void 0 ? (i?.send(O, r()), S) : (i?.send(
|
|
78
78
|
{
|
|
79
|
-
...
|
|
80
|
-
type: `${
|
|
79
|
+
...O,
|
|
80
|
+
type: `${s}/${O.type}`
|
|
81
81
|
},
|
|
82
82
|
{
|
|
83
|
-
...
|
|
84
|
-
[
|
|
83
|
+
...w(p.name),
|
|
84
|
+
[s]: o.getState()
|
|
85
85
|
}
|
|
86
|
-
),
|
|
86
|
+
), S);
|
|
87
87
|
}), o.devtools = {
|
|
88
88
|
cleanup: () => {
|
|
89
|
-
|
|
89
|
+
i && typeof i.unsubscribe == "function" && i.unsubscribe(), z(p.name, s);
|
|
90
90
|
}
|
|
91
91
|
};
|
|
92
|
-
const
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
},
|
|
96
|
-
if (
|
|
92
|
+
const u = (...c) => {
|
|
93
|
+
const m = g;
|
|
94
|
+
g = !1, e(...c), g = m;
|
|
95
|
+
}, _ = n(o.setState, r, o);
|
|
96
|
+
if (d.type === "untracked" ? i?.init(_) : (d.stores[d.store] = o, i?.init(
|
|
97
97
|
Object.fromEntries(
|
|
98
|
-
Object.entries(
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
Object.entries(d.stores).map(([c, m]) => [
|
|
99
|
+
c,
|
|
100
|
+
c === d.store ? _ : m.getState()
|
|
101
101
|
])
|
|
102
102
|
)
|
|
103
103
|
)), o.dispatchFromDevtools && typeof o.dispatch == "function") {
|
|
104
|
-
let
|
|
105
|
-
const
|
|
106
|
-
o.dispatch = (...
|
|
107
|
-
(
|
|
104
|
+
let c = !1;
|
|
105
|
+
const m = o.dispatch;
|
|
106
|
+
o.dispatch = (...a) => {
|
|
107
|
+
(R ? "production" : void 0) !== "production" && a[0].type === "__setState" && !c && (console.warn(
|
|
108
108
|
'[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'
|
|
109
|
-
),
|
|
109
|
+
), c = !0), m(...a);
|
|
110
110
|
};
|
|
111
111
|
}
|
|
112
|
-
return
|
|
113
|
-
var
|
|
114
|
-
switch (
|
|
112
|
+
return i.subscribe((c) => {
|
|
113
|
+
var m;
|
|
114
|
+
switch (c.type) {
|
|
115
115
|
case "ACTION":
|
|
116
|
-
if (typeof
|
|
116
|
+
if (typeof c.payload != "string") {
|
|
117
117
|
console.error(
|
|
118
118
|
"[zustand devtools middleware] Unsupported action format"
|
|
119
119
|
);
|
|
120
120
|
return;
|
|
121
121
|
}
|
|
122
|
-
return
|
|
123
|
-
|
|
124
|
-
(
|
|
125
|
-
if (
|
|
126
|
-
if (
|
|
127
|
-
|
|
122
|
+
return E(
|
|
123
|
+
c.payload,
|
|
124
|
+
(a) => {
|
|
125
|
+
if (a.type === "__setState") {
|
|
126
|
+
if (s === void 0) {
|
|
127
|
+
u(a.state);
|
|
128
128
|
return;
|
|
129
129
|
}
|
|
130
|
-
Object.keys(
|
|
130
|
+
Object.keys(a.state).length !== 1 && console.error(
|
|
131
131
|
`
|
|
132
132
|
[zustand devtools middleware] Unsupported __setState action format.
|
|
133
133
|
When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
|
|
134
134
|
and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }
|
|
135
135
|
`
|
|
136
136
|
);
|
|
137
|
-
const
|
|
138
|
-
if (
|
|
137
|
+
const S = a.state[s];
|
|
138
|
+
if (S == null)
|
|
139
139
|
return;
|
|
140
|
-
JSON.stringify(o.getState()) !== JSON.stringify(
|
|
140
|
+
JSON.stringify(o.getState()) !== JSON.stringify(S) && u(S);
|
|
141
141
|
return;
|
|
142
142
|
}
|
|
143
|
-
o.dispatchFromDevtools && typeof o.dispatch == "function" && o.dispatch(
|
|
143
|
+
o.dispatchFromDevtools && typeof o.dispatch == "function" && o.dispatch(a);
|
|
144
144
|
}
|
|
145
145
|
);
|
|
146
146
|
case "DISPATCH":
|
|
147
|
-
switch (
|
|
147
|
+
switch (c.payload.type) {
|
|
148
148
|
case "RESET":
|
|
149
|
-
return
|
|
149
|
+
return u(_), s === void 0 ? i?.init(o.getState()) : i?.init(w(p.name));
|
|
150
150
|
case "COMMIT":
|
|
151
|
-
if (
|
|
152
|
-
|
|
151
|
+
if (s === void 0) {
|
|
152
|
+
i?.init(o.getState());
|
|
153
153
|
return;
|
|
154
154
|
}
|
|
155
|
-
return
|
|
155
|
+
return i?.init(w(p.name));
|
|
156
156
|
case "ROLLBACK":
|
|
157
|
-
return
|
|
158
|
-
if (
|
|
159
|
-
|
|
157
|
+
return E(c.state, (a) => {
|
|
158
|
+
if (s === void 0) {
|
|
159
|
+
u(a), i?.init(o.getState());
|
|
160
160
|
return;
|
|
161
161
|
}
|
|
162
|
-
|
|
162
|
+
u(a[s]), i?.init(w(p.name));
|
|
163
163
|
});
|
|
164
164
|
case "JUMP_TO_STATE":
|
|
165
165
|
case "JUMP_TO_ACTION":
|
|
166
|
-
return
|
|
167
|
-
if (
|
|
168
|
-
|
|
166
|
+
return E(c.state, (a) => {
|
|
167
|
+
if (s === void 0) {
|
|
168
|
+
u(a);
|
|
169
169
|
return;
|
|
170
170
|
}
|
|
171
|
-
JSON.stringify(o.getState()) !== JSON.stringify(s
|
|
171
|
+
JSON.stringify(o.getState()) !== JSON.stringify(a[s]) && u(a[s]);
|
|
172
172
|
});
|
|
173
173
|
case "IMPORT_STATE": {
|
|
174
|
-
const { nextLiftedState:
|
|
175
|
-
if (!
|
|
176
|
-
|
|
174
|
+
const { nextLiftedState: a } = c.payload, S = (m = a.computedStates.slice(-1)[0]) == null ? void 0 : m.state;
|
|
175
|
+
if (!S) return;
|
|
176
|
+
u(s === void 0 ? S : S[s]), i?.send(
|
|
177
177
|
null,
|
|
178
178
|
// FIXME no-any
|
|
179
|
-
|
|
179
|
+
a
|
|
180
180
|
);
|
|
181
181
|
return;
|
|
182
182
|
}
|
|
183
183
|
case "PAUSE_RECORDING":
|
|
184
|
-
return
|
|
184
|
+
return g = !g;
|
|
185
185
|
}
|
|
186
186
|
return;
|
|
187
187
|
}
|
|
188
|
-
}),
|
|
189
|
-
},
|
|
188
|
+
}), _;
|
|
189
|
+
}, B = W, E = (n, t) => {
|
|
190
190
|
let e;
|
|
191
191
|
try {
|
|
192
192
|
e = JSON.parse(n);
|
|
193
|
-
} catch (
|
|
193
|
+
} catch (r) {
|
|
194
194
|
console.error(
|
|
195
195
|
"[zustand devtools middleware] Could not parse the received json",
|
|
196
|
-
|
|
196
|
+
r
|
|
197
197
|
);
|
|
198
198
|
}
|
|
199
199
|
e !== void 0 && t(e);
|
|
200
200
|
};
|
|
201
|
-
class
|
|
201
|
+
class G extends EventTarget {
|
|
202
202
|
constructor() {
|
|
203
203
|
super(...arguments), this.controller = new AbortController();
|
|
204
204
|
}
|
|
205
205
|
on(t, e) {
|
|
206
206
|
return this.addEventListener(
|
|
207
207
|
t,
|
|
208
|
-
(
|
|
208
|
+
(r) => e(r.detail),
|
|
209
209
|
{ signal: this.controller.signal }
|
|
210
210
|
), this;
|
|
211
211
|
}
|
|
212
212
|
once(t, e) {
|
|
213
213
|
return this.addEventListener(
|
|
214
214
|
t,
|
|
215
|
-
(
|
|
215
|
+
(r) => e(r.detail),
|
|
216
216
|
{
|
|
217
217
|
signal: this.controller.signal,
|
|
218
218
|
once: !0
|
|
@@ -226,7 +226,7 @@ class F extends EventTarget {
|
|
|
226
226
|
this.controller.abort(), this.controller = new AbortController();
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
|
-
const
|
|
229
|
+
const b = new G(), X = J()(B((n, t) => ({
|
|
230
230
|
loadingCount: 0,
|
|
231
231
|
overrideState: null,
|
|
232
232
|
localCounters: {},
|
|
@@ -238,55 +238,55 @@ const y = new F(), z = k()(U((n, t) => ({
|
|
|
238
238
|
return t().isLoading();
|
|
239
239
|
},
|
|
240
240
|
startLoading: (e) => {
|
|
241
|
-
const
|
|
242
|
-
n((
|
|
241
|
+
const r = t().isLoading();
|
|
242
|
+
n((l) => ({ loadingCount: l.loadingCount + 1 })), e && n((l) => ({
|
|
243
243
|
localCounters: {
|
|
244
|
-
...
|
|
245
|
-
[e]: (
|
|
244
|
+
...l.localCounters,
|
|
245
|
+
[e]: (l.localCounters[e] ?? 0) + 1
|
|
246
246
|
}
|
|
247
247
|
}));
|
|
248
248
|
const o = t().isLoading();
|
|
249
|
-
o && !
|
|
249
|
+
o && !r && b.emit("start", null), b.emit("change", { isLoading: o, isOverrideState: t().overrideState !== null });
|
|
250
250
|
},
|
|
251
251
|
stopLoading: (e) => {
|
|
252
|
-
const
|
|
253
|
-
e && o > 0 && n((
|
|
254
|
-
loadingCount: Math.max(0,
|
|
252
|
+
const r = t().isLoading(), o = e ? t().localCounters[e] ?? 0 : 0;
|
|
253
|
+
e && o > 0 && n((v) => ({
|
|
254
|
+
loadingCount: Math.max(0, v.loadingCount - 1),
|
|
255
255
|
localCounters: {
|
|
256
|
-
...
|
|
257
|
-
[e]: Math.max(0,
|
|
256
|
+
...v.localCounters,
|
|
257
|
+
[e]: Math.max(0, v.localCounters[e] - 1)
|
|
258
258
|
}
|
|
259
259
|
}));
|
|
260
|
-
const
|
|
261
|
-
!
|
|
260
|
+
const l = t().isLoading();
|
|
261
|
+
!l && r && b.emit("stop", null), b.emit("change", { isLoading: l, isOverrideState: t().overrideState !== null });
|
|
262
262
|
},
|
|
263
263
|
overrideLoading: (e) => {
|
|
264
|
-
const
|
|
264
|
+
const r = t().isLoading();
|
|
265
265
|
n({ overrideState: e });
|
|
266
266
|
const o = t().isLoading();
|
|
267
|
-
o && !
|
|
267
|
+
o && !r ? b.emit("start", null) : !o && r && b.emit("stop", null), b.emit("change", { isLoading: o, isOverrideState: e !== null });
|
|
268
268
|
},
|
|
269
269
|
getLocalCounter: (e) => t().localCounters[e] ?? 0,
|
|
270
270
|
isLocalLoading: (e) => (t().localCounters[e] ?? 0) > 0
|
|
271
271
|
}
|
|
272
272
|
})));
|
|
273
|
-
function
|
|
274
|
-
const n =
|
|
273
|
+
function A() {
|
|
274
|
+
const n = D(), { actions: t } = X((l) => l), e = () => {
|
|
275
275
|
t.startLoading(n);
|
|
276
|
-
},
|
|
276
|
+
}, r = () => {
|
|
277
277
|
t.isLocalLoading(n) && t.stopLoading(n);
|
|
278
|
-
}, o = async (
|
|
278
|
+
}, o = async (l) => {
|
|
279
279
|
e();
|
|
280
280
|
try {
|
|
281
|
-
return await
|
|
281
|
+
return await l;
|
|
282
282
|
} finally {
|
|
283
|
-
|
|
283
|
+
r();
|
|
284
284
|
}
|
|
285
285
|
};
|
|
286
286
|
return {
|
|
287
287
|
overrideLoading: t.overrideLoading,
|
|
288
288
|
startLoading: e,
|
|
289
|
-
stopLoading:
|
|
289
|
+
stopLoading: r,
|
|
290
290
|
get isLocalLoading() {
|
|
291
291
|
return t.isLocalLoading(n);
|
|
292
292
|
},
|
|
@@ -296,24 +296,93 @@ function B() {
|
|
|
296
296
|
}
|
|
297
297
|
};
|
|
298
298
|
}
|
|
299
|
-
const
|
|
299
|
+
const h = {
|
|
300
300
|
Spin: "spin",
|
|
301
301
|
FadeInOut: "fadeInOut",
|
|
302
302
|
None: "none"
|
|
303
|
-
},
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
303
|
+
}, H = ({ scale: n = 1, animationType: t = h.Spin, animationDuration: e, children: r, style: o, className: l, id: v, prefix: s }) => {
|
|
304
|
+
const p = t, f = t === h.Spin ? 1 : t === h.FadeInOut ? 2 : 0, i = e || f, d = t === h.Spin ? "linear" : t === h.FadeInOut ? "ease-in-out" : "linear", g = t === h.None ? "none" : `${s}-${p} ${i}s ${d} infinite`;
|
|
305
|
+
return /* @__PURE__ */ L("div", { style: { animation: g, ...n !== 1 ? { zoom: n } : {}, ...o }, className: l, id: v, children: r });
|
|
306
|
+
}, K = (n) => /* @__PURE__ */ L("div", { id: "loading-circle", style: { width: "90px", height: "90px", border: "15px solid #f3f3f3", borderTop: "15px solid #009b4bff", borderRadius: "50%", boxSizing: "border-box" }, ...n }), q = (n) => /* @__PURE__ */ L("div", { style: { padding: "20px", fontSize: "25px", color: "#333", fontFamily: "system-ui, sans-serif" }, ...n, children: "Please wait..." });
|
|
307
|
+
function tt({
|
|
308
|
+
loadingComponent: n,
|
|
309
|
+
loadingComponentScale: t = 1,
|
|
310
|
+
animationType: e = h.Spin,
|
|
311
|
+
animationDuration: r,
|
|
312
|
+
wrapperStyle: o,
|
|
313
|
+
wrapperClassName: l,
|
|
314
|
+
wrapperId: v,
|
|
315
|
+
animationWrapperStyle: s,
|
|
316
|
+
animationWrapperClassName: p,
|
|
317
|
+
animationWrapperId: f
|
|
318
|
+
}) {
|
|
319
|
+
n = n || (e === h.Spin ? K : q);
|
|
320
|
+
const i = x(Math.random().toString(36).substring(2, 6).replace(/[0-9]/g, "")), { isLoading: d } = A(), g = x(null);
|
|
321
|
+
k(() => {
|
|
322
|
+
d ? (g.current?.showModal(), document.body.setAttribute("inert", "")) : (g.current?.close(), document.body.removeAttribute("inert"));
|
|
323
|
+
}, [d]);
|
|
324
|
+
const u = v || "loading-wrapper-" + i.current;
|
|
325
|
+
return d ? F(
|
|
326
|
+
/* @__PURE__ */ N(j, { children: [
|
|
327
|
+
/* @__PURE__ */ L("style", { children: `
|
|
328
|
+
dialog#${u}[open] {
|
|
329
|
+
display: flex !important;
|
|
330
|
+
justify-content: center;
|
|
331
|
+
align-items: center;
|
|
332
|
+
width: 100vw;
|
|
333
|
+
height: 100vh;
|
|
334
|
+
max-width: 100%;
|
|
335
|
+
max-height: 100%;
|
|
336
|
+
}
|
|
337
|
+
@keyframes ${i.current}-spin {
|
|
338
|
+
0% { transform: rotate(0deg); }
|
|
339
|
+
100% { transform: rotate(360deg); }
|
|
340
|
+
}
|
|
341
|
+
@keyframes ${i.current}-fadeInOut {
|
|
342
|
+
0%, 100% { opacity: 0.2; }
|
|
343
|
+
50% { opacity: 1; }
|
|
344
|
+
}
|
|
345
|
+
body:has(dialog#${u}[open]) {
|
|
346
|
+
overflow: hidden;
|
|
347
|
+
}
|
|
348
|
+
body {
|
|
349
|
+
scrollbar-gutter: stable;
|
|
350
|
+
}
|
|
351
|
+
` }),
|
|
352
|
+
/* @__PURE__ */ L(
|
|
353
|
+
"dialog",
|
|
354
|
+
{
|
|
355
|
+
ref: g,
|
|
356
|
+
style: {
|
|
357
|
+
border: "none",
|
|
358
|
+
padding: 0,
|
|
359
|
+
backgroundColor: "rgba(0, 0, 0, 0.5)",
|
|
360
|
+
backdropFilter: "blur(2px)",
|
|
361
|
+
...o
|
|
362
|
+
},
|
|
363
|
+
className: l,
|
|
364
|
+
id: u,
|
|
365
|
+
children: /* @__PURE__ */ L(H, { scale: t, animationType: e, animationDuration: r, style: s, className: p, id: f, prefix: i.current, children: y.isValidElement(n) ? n : y.createElement(n) })
|
|
366
|
+
}
|
|
367
|
+
)
|
|
368
|
+
] }),
|
|
369
|
+
document.body
|
|
370
|
+
) : null;
|
|
371
|
+
}
|
|
372
|
+
function et({ isLoading: n = !1 }) {
|
|
373
|
+
const { startLoading: t, stopLoading: e } = A();
|
|
374
|
+
return k(() => (n ? t() : e(), () => {
|
|
307
375
|
n && e();
|
|
308
376
|
}), [n]), null;
|
|
309
377
|
}
|
|
310
378
|
export {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
379
|
+
h as AnimationType,
|
|
380
|
+
G as EventEmitter,
|
|
381
|
+
et as Loading,
|
|
382
|
+
K as LoadingCircle,
|
|
383
|
+
q as LoadingPleaseWait,
|
|
384
|
+
tt as LoadingRenderer,
|
|
385
|
+
b as loadingEventTarget,
|
|
386
|
+
A as ssrLoading,
|
|
387
|
+
A as useLoading
|
|
319
388
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rokku-x/react-hook-loading-spinner",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"description": "A lightweight and flexible React loading state hook library with built-in spinner components, global state management, and zero dependencies (except React and Zustand).",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|