UNPKG

6.68 kBJavaScriptView Raw
1System.register(["jotai/vanilla"],function(P){"use strict";var f;return{setters:[function(S){f=S.atom}],execute:function(){P({atomFamily:z,atomWithDefault:U,atomWithObservable:tt,atomWithReducer:V,atomWithReset:T,atomWithStorage:Z,createJSONStorage:j,freezeAtom:F,freezeAtomCreator:K,loadable:nt,selectAtom:$,splitAtom:Q,unstable_unwrap:it});const S=P("RESET",Symbol());function T(e){const n=f(e,(o,u,s)=>{const r=typeof s=="function"?s(o(n)):s;u(n,r===S?e:r)});return n}function V(e,n){const o=f(e,(u,s,r)=>s(o,n(u(o),r)));return o}function z(e,n){let o=null;const u=new Map,s=r=>{let t;if(n===void 0)t=u.get(r);else for(const[a,i]of u)if(n(a,r)){t=i;break}if(t!==void 0)if(o!=null&&o(t[1],r))s.remove(r);else return t[0];const c=e(r);return u.set(r,[c,Date.now()]),c};return s.remove=r=>{if(n===void 0)u.delete(r);else for(const[t]of u)if(n(t,r)){u.delete(t);break}},s.setShouldRemove=r=>{if(o=r,!!o)for(const[t,c]of u)o(c[1],t)&&u.delete(t)},s}const L=(e,n,o)=>(n.has(o)?n:n.set(o,e())).get(o),J=new WeakMap,_=(e,n,o,u)=>{const s=L(()=>new WeakMap,J,n),r=L(()=>new WeakMap,s,o);return L(e,r,u)};function $(e,n,o=Object.is){return _(()=>{const u=Symbol(),s=([t,c])=>{if(c===u)return n(t);const a=n(t,c);return o(c,a)?c:a},r=f(t=>{const c=t(r),a=t(e);return a instanceof Promise||c instanceof Promise?Promise.all([a,c]).then(s):s([a,c])});return r.init=u,r},e,n,o)}const I=new WeakMap,C=(e,n)=>(I.has(n)?I:I.set(n,e())).get(n),x=e=>{if(typeof e!="object"||e===null)return;Object.freeze(e);const n=Object.getOwnPropertyNames(e);for(const o of n){const u=e[o];x(u)}return e};function F(e){return C(()=>f(n=>x(n(e)),(n,o,u)=>o(e,u)),e)}function K(e){return(...n)=>{const o=e(...n),u=o.read;return o.read=(s,r)=>x(u(s,r)),o}}const A=(e,n,o)=>(n.has(o)?n:n.set(o,e())).get(o),q=new WeakMap,B=(e,n,o)=>{const u=A(()=>new WeakMap,q,n);return A(e,u,o)},G={},R=e=>!!e.write,H=e=>typeof e=="function";function Q(e,n){return B(()=>{const o=new WeakMap,u=(t,c)=>{let a=o.get(t);if(a)return a;const i=c&&o.get(c),l=[],m=[];return t.forEach((w,v)=>{const b=n?n(w):v;m[v]=b;const g=i&&i.atomList[i.keyList.indexOf(b)];if(g){l[v]=g;return}const W=h=>{const d=h(s),y=h(e),k=u(y,d==null?void 0:d.arr).keyList.indexOf(b);if(k<0||k>=y.length){const p=t[u(t).keyList.indexOf(b)];if(p)return p;throw new Error("splitAtom: index out of bounds for read")}return y[k]},O=(h,d,y)=>{const k=h(s),p=h(e),M=u(p,k==null?void 0:k.arr).keyList.indexOf(b);if(M<0||M>=p.length)throw new Error("splitAtom: index out of bounds for write");const at=H(y)?y(p[M]):y;d(e,[...p.slice(0,M),at,...p.slice(M+1)])};l[v]=R(e)?f(W,O):f(W)}),i&&i.keyList.length===m.length&&i.keyList.every((w,v)=>w===m[v])?a=i:a={arr:t,atomList:l,keyList:m},o.set(t,a),a},s=f(t=>{const c=t(s),a=t(e);return u(a,c==null?void 0:c.arr)});s.init=void 0;const r=R(e)?f(t=>t(s).atomList,(t,c,a)=>{switch(a.type){case"remove":{const i=t(r).indexOf(a.atom);if(i>=0){const l=t(e);c(e,[...l.slice(0,i),...l.slice(i+1)])}break}case"insert":{const i=a.before?t(r).indexOf(a.before):t(r).length;if(i>=0){const l=t(e);c(e,[...l.slice(0,i),a.value,...l.slice(i)])}break}case"move":{const i=t(r).indexOf(a.atom),l=a.before?t(r).indexOf(a.before):t(r).length;if(i>=0&&l>=0){const m=t(e);i<l?c(e,[...m.slice(0,i),...m.slice(i+1,l),m[i],...m.slice(l)]):c(e,[...m.slice(0,l),m[i],...m.slice(l,i),...m.slice(i+1)])}break}}}):f(t=>t(s).atomList);return r},e,n||G)}function U(e){const n=Symbol(),o=f(n),u=f((s,r)=>{const t=s(o);return t!==n?t:e(s,r)},(s,r,t)=>{if(t===S)r(o,n);else if(typeof t=="function"){const c=s(u);r(o,t(c))}else r(o,t)});return u}const X=e=>typeof(e==null?void 0:e.then)=="function";function j(e){let n,o;const u={getItem:(s,r)=>{var t,c;const a=l=>{if(l=l||"",n!==l){try{o=JSON.parse(l)}catch{return r}n=l}return o},i=(c=(t=e())==null?void 0:t.getItem(s))!=null?c:null;return X(i)?i.then(a):a(i)},setItem:(s,r)=>{var t;return(t=e())==null?void 0:t.setItem(s,JSON.stringify(r))},removeItem:s=>{var r;return(r=e())==null?void 0:r.removeItem(s)}};return typeof window<"u"&&typeof window.addEventListener=="function"&&(u.subscribe=(s,r,t)=>{if(!(e()instanceof window.Storage))return()=>{};const c=a=>{if(a.storageArea===e()&&a.key===s){let i;try{i=JSON.parse(a.newValue||"")}catch{i=t}r(i)}};return window.addEventListener("storage",c),()=>{window.removeEventListener("storage",c)}}),u}const Y=j(()=>typeof window<"u"?window.localStorage:void 0);function Z(e,n,o=Y,u){const s=u==null?void 0:u.unstable_getOnInit,r=f(s?o.getItem(e,n):n);return r.onMount=t=>{s||t(o.getItem(e,n));let c;return o.subscribe&&(c=o.subscribe(e,t,n)),c},f(t=>t(r),(t,c,a)=>{const i=typeof a=="function"?a(t(r)):a;return i===S?(c(r,n),o.removeItem(e)):i instanceof Promise?i.then(l=>(c(r,l),o.setItem(e,l))):(c(r,i),o.setItem(e,i))})}function tt(e,n){const o=s=>{if("e"in s)throw s.e;return s.d},u=f(s=>{var r;let t=e(s);const c=(r=t[Symbol.observable])==null?void 0:r.call(t);c&&(t=c);let a;const i=()=>new Promise(d=>{a=d}),l=n&&"initialValue"in n?{d:typeof n.initialValue=="function"?n.initialValue():n.initialValue}:i();let m,w;const v=d=>{w=d,a==null||a(d),m==null||m(d)};let b,g;const W=()=>!m,O=()=>{b&&(clearTimeout(g),b.unsubscribe()),b=t.subscribe({next:d=>v({d}),error:d=>v({e:d}),complete:()=>{}}),W()&&n!=null&&n.unstable_timeout&&(g=setTimeout(()=>{b&&(b.unsubscribe(),b=void 0)},n.unstable_timeout))};O();const h=f(w||l);return h.onMount=d=>(m=d,w&&d(w),b?clearTimeout(g):O(),()=>{m=void 0,b&&(b.unsubscribe(),b=void 0)}),[h,t,i,O,W]});return f(s=>{const[r]=s(u),t=s(r);return t instanceof Promise?t.then(o):o(t)},(s,r,t)=>{const[c,a,i,l,m]=s(u);if("next"in a)m()&&(r(c,i()),l()),a.next(t);else throw new Error("observable is not subject")})}const E=new WeakMap,et=(e,n)=>(E.has(n)?E:E.set(n,e())).get(n),D={state:"loading"};function nt(e){return et(()=>{const n=new WeakMap,o=f(0),u=f((s,{setSelf:r})=>{s(o);const t=s(e);return t instanceof Promise?n.get(t)||(n.set(t,D),t.then(a=>{n.set(t,{state:"hasData",data:a})},a=>{n.set(t,{state:"hasError",error:a})}).finally(r),D):{state:"hasData",data:t}},(s,r)=>{r(o,t=>t+1)});return f(s=>s(u))},e)}const N=(e,n,o)=>(n.has(o)?n:n.set(o,e())).get(o),ot=new WeakMap,rt=(e,n,o)=>{const u=N(()=>new WeakMap,ot,n);return N(e,u,o)},st=()=>{};function it(e,n=st){return rt(()=>{const o=new WeakMap,u=new WeakMap,s=f(0),r=f((t,{setSelf:c})=>{t(s);const a=t(r),i=t(e);if(!(i instanceof Promise))return{v:i};if(i===(a==null?void 0:a.p)){if(o.has(i))throw o.get(i);if(u.has(i))return{p:i,v:u.get(i)}}return i!==(a==null?void 0:a.p)&&i.then(l=>u.set(i,l),l=>o.set(i,l)).finally(c),a&&"v"in a?{p:i,f:n(a.v)}:{p:i,f:n()}},(t,c)=>{c(s,a=>a+1)});return r.init=void 0,f(t=>{const c=t(r);return"v"in c?c.v:c.f},e.write)},e,n)}}}});