atomaric 0.0.66 → 0.0.67
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/build/atomaric.js +5 -0
- package/build/atomaric.umd.cjs +1 -1
- package/package.json +1 -1
package/build/atomaric.js
CHANGED
|
@@ -343,6 +343,11 @@ setTimeout(() => {
|
|
|
343
343
|
}, 1e3);
|
|
344
344
|
export {
|
|
345
345
|
de as Atom,
|
|
346
|
+
ie as AtomArrayDoActions,
|
|
347
|
+
ue as AtomBooleanDoActions,
|
|
348
|
+
le as AtomNumberDoActions,
|
|
349
|
+
fe as AtomObjectDoActions,
|
|
350
|
+
he as AtomSetDoActions,
|
|
346
351
|
$e as atom,
|
|
347
352
|
Ae as configureAtomaric,
|
|
348
353
|
L as configuredOptions,
|
package/build/atomaric.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(l,j){typeof exports=="object"&&typeof module<"u"?j(exports):typeof define=="function"&&define.amd?define(["exports"],j):(l=typeof globalThis<"u"?globalThis:l||self,j(l.atomaric={}))})(this,function(l){"use strict";let j=()=>{throw"call configureAtomaric() before all!"};const D={},he=t=>{D.useSyncExternalStore=j=t.useSyncExternalStore,D.keyPathSeparator=t.keyPathSeparator,D.securifyKeyLevel=t.securifyKeyLevel,D.securifyValueLevel=t.securifyValueLevel},X=t=>j(t.subscribe,t.get),Y=t=>t.set,me=t=>t.setDeferred,de=t=>t.get,Ae=t=>t.do,ye=t=>[X(t),Y(t)],ge=(t,e)=>new ne(t,e);class z{constructor(e){if(e)return new Proxy(this,{get:(n,s)=>s in this?n[s]:e[s]})}}const we=(t,e)=>{const n=(s,o,c)=>new Proxy(s,{get:(a,h,y)=>{const A=c===0&&e.get!=null?e.get(a,h,y):a[h];return typeof A=="object"&&A!==null?n(Array.isArray(A)?A.slice(0):{...A},o.concat(Array.isArray(a)?+h:h),c+1):A},set:(a,h,y)=>(e.onSet(a,o,h,y,a[h])&&(a[h]=y),!0)});return n(t,[],0)};class Z extends z{constructor(){super(...arguments),this.updateValue=(e,n)=>{const s=Array.isArray(e)?e.slice(0):{...e};let o=!1;const c=we(e,{onSet:(a,h,y,A,g)=>{if(A===g)return!0;let S=s;o=!0;for(const f of h){const m=S[f];S=S[f]=Array.isArray(m)?m.slice(0):{...m}}return S[y]=A,!0}});return n(c),o?s:e}}}class k extends Z{constructor(e,n){super(n),this.atom=e,this.push=(...s)=>{this.atom.set(this.atom.get().concat(s))},this.unshift=(...s)=>{this.atom.set(s.concat(this.atom.get()))},this.update=s=>{const o=this.atom.get(),c=this.updateValue(o,s);c!==o&&this.atom.set(c)},this.filter=s=>{this.atom.set(this.atom.get().filter(s??pe))},this.add=s=>{this.atom.get().includes(s)||this.atom.set(this.atom.get().concat([s]))},this.remove=s=>{const o=this.atom.get().indexOf(s);if(o<0)return;const c=this.atom.get().slice(0);c.splice(o,1),this.atom.set(c)},this.toggle=(s,o)=>{const c=this.atom.get().slice(),a=c.indexOf(s);a<0?o?c.unshift(s):c.push(s):c.splice(a,1),this.atom.set(c)}}}const pe=t=>t;class O extends z{constructor(e,n){super(n),this.atom=e,this.toggle=()=>{this.atom.set(!this.atom.get())}}}class ee extends z{constructor(e,n){super(n),this.atom=e,this.increment=s=>{this.atom.set(+this.atom.get()+(s??1))}}}class te extends Z{constructor(e,n){super(n),this.atom=e,this.setPartial=s=>this.atom.set(o=>({...o,...typeof s=="function"?s(this.atom.get()):s})),this.update=s=>{const o=this.atom.get(),c=this.updateValue(o,s);c!==o&&this.atom.set(c)},this.setDeepPartial=(s,o,c,a=D.keyPathSeparator||".")=>{if(!a)return;if(s.includes(a)){let A=s.split(a);const g=A[A.length-1];A=A.slice(0,-1);const S={...this.atom.get()};let f=S,m=c;for(const w of A){m=m==null?void 0:m[Array.isArray(m)?"0":w];const x=f[se(f,w)]??(Array.isArray(m)?[]:{});if(x==null||typeof x!="object"){if(c==null)throw"Incorrect path for setDeepPartial";const b=typeof o=="function"?o(void 0):o;this.atom.get()[s]!==b&&this.setPartial({[s]:b});return}f=f[se(f,w)]=Array.isArray(x)?[...x]:{...x}}const v=f[g];f[g]=typeof o=="function"?o(f[g]):o,v!==f[g]&&this.atom.set(S);return}const h=this.atom.get()[s],y=typeof o=="function"?o(h):o;y!==h&&this.setPartial({[s]:y})}}}const se=(t,e)=>Array.isArray(t)?`${+e}`:e;class re extends z{constructor(e,n){super(n),this.atom=e,this.add=s=>{this.atom.set(new Set(this.atom.get()).add(s))},this.delete=s=>{const o=new Set(this.atom.get());o.delete(s),this.atom.set(o)},this.toggle=s=>{const o=new Set(this.atom.get());o.has(s)?o.delete(s):o.add(s),this.atom.set(o)},this.clear=()=>{this.atom.set(new Set)},this.atom=e}}const Se=(t,e,n)=>{const s=typeof n=="object"&&n!=null&&"do"in n?n.do((c,a)=>e.set(c,a),()=>e.get(),e,(c,a,h)=>e.setDeferred(c,a,h)):null,o={};return s&&Object.keys(s).forEach(c=>Object.defineProperty(o,c,{get:()=>s[c]})),typeof t=="number"?new ee(e,s):typeof t=="boolean"?new O(e,s):Array.isArray(t)?new k(e,s):t instanceof Set?new re(e,s):t instanceof Object?new te(e,s):new z(s)};class ne{constructor(e,n){e=typeof e=="function"?e():e;const s=r=>A=r,o=()=>A,c=new Set,a=r=>r(f());let h=!0,y=!1,A=e,g,S=()=>{},f=()=>o(),m=null,v=()=>{const r=Se(e,w,n);return v=()=>r,r};const w=new Proxy(this,{get:(r,d)=>d==="do"?v():r[d],set:be}),x=()=>{h=!0,y!==!0&&S(f()),y=!1;try{B.postMessage({key:u,value:o()})}catch{}},b=(r,d)=>{const T=typeof r=="function"?r(f()):r;T!==f()&&(s(T),y=d,h&&(h=!1,c.forEach(a),queueMicrotask(x)))};this.set=(r,d)=>b(r,d),this.get=()=>f(),this.initialValue=e,this.isInitialValue=()=>e===o(),this.subscribe=r=>(c.add(r),()=>{c.delete(r)}),this.reset=()=>{b(e,!0)};const Te=(r,d)=>{b(r,d),g=void 0};if(this.setDeferred=(r,d=500,T,V=!0)=>{V&&g===void 0&&b(r,T),clearTimeout(g),g=setTimeout(Te,d,r,T)},n==null)return w;let p=null,R=null,G=!0,H=!0,J=!1,$=0,I=0,ue=-1,_=e instanceof Set?r=>new Set(r):r=>r,E=e instanceof Set?r=>{if(r instanceof Set)return Array.from(r);throw console.error(r),"The value is not Set instance"}:r=>r;if(typeof n=="string")p=n;else if("storeKey"in n)G=n.warnOnDuplicateStoreKey??G,H=n.listenStorageChanges??H,p=n.storeKey,_=n.unzipValue??_,E=n.zipValue??E,J=n.unchangable??J,$=n.securifyKeyLevel??D.securifyKeyLevel??$,I=n.securifyValueLevel??D.securifyValueLevel??I,R=n.exp??R;else return w;const Q=$?C(p,$):p,u=`${I?N:P}${Q}`;if($){const r=`${P}${p}`;r in i&&(i[u]=i[r],delete i[r])}else{const r=`${P}${C(p,$)}`;r in i&&(i[u]=i[r],delete i[r])}const K=R===null||!(R(w,u in i)instanceof Date)?r=>C([E(r)],0):r=>(m??(m={}),m.exp=R(w,u in i).getTime(),m.exp-Date.now()<24*60*60*1e3&&(clearTimeout(ue),clearTimeout(oe[u]),ue=setTimeout(()=>this.reset(),m.exp-Date.now())),m.exp=Math.trunc(m.exp/1e3),C([E(r),m],0));if(I){const r=`${P}${Q}`,d=E,T=_;if(E=V=>{try{return C([d(V)],I)}catch{return delete i[u],""}},r in i){const V=`${P}${C(p,$)}`;try{i[V]=K(_(q(i[r],0)[0])),delete i[r]}catch{}}_=V=>{try{return T(q(V,I)[0])}catch{return delete i[u],""}}}else delete i[`${N}${Q}`];const ae=r=>{const d=q(r,0);return m=d[1],_(d[0])};let le=!0;if(F[u]=w,i[`atom/${p}`]&&(i[u]||(i[u]=`[${i[`atom/${p}`]}]`),delete i[`atom/${p}`]),f=()=>{if(f=o,le){le=!1;try{s(u in i?ae(i[u]):e)}catch{console.warn("Invalid json value",i[u])}}return o()},S=r=>{if(r===e){this.reset();return}i[u]=K(r)},this.reset=()=>{delete i[u],b(e,!0)},G&&L[u]!==void 0&&console.warn("Duplicate Atom key",p),H)if(J){let r=!1,d;M[u]=this,L[u]=()=>{clearTimeout(d),d=setTimeout(()=>r=!1,10),!r&&(r=!0,i[u]=K(o()))}}else L[u]=r=>{if(r.newValue===null){this.reset();return}try{b(ae(r.newValue))}catch{console.warn("Invalid json value",r.newValue)}};return w}}let B;try{B=new BroadcastChannel("updateHere"),B.addEventListener("message",t=>{var e;(e=M[t.data.key])==null||e.set(t.data.value,!0)})}catch{}const i=localStorage,L={},M={},be=(t,e)=>{throw`${e} is readonly property`};window.addEventListener("storage",t=>{var e;t.key===null||t.newValue===t.oldValue||(e=L[t.key])==null||e.call(L,t)});const De=i.setItem.bind(i),xe=i.removeItem.bind(i);i.setItem=(t,e)=>{M[t]===void 0&&De.call(i,t,e)},i.removeItem=t=>{M[t]===void 0&&xe.call(i,t)};const $e=/"exp":\s*(\d+)/,P="atom\\",N="atom`s\\",F={},oe={},ie=/[a-z]/gi,U=5,W={};for(let t=54;t<80;t++){if(t===68||t===72||t===55)continue;const e=String.fromCharCode(t+43).toUpperCase(),n=String.fromCharCode(t+43).toLowerCase();W[e]=n,W[n]=e}const ce=t=>W[t]??t,C=(()=>{const t=[e=>JSON.stringify(e),e=>btoa(encodeURI(t[0](e))),e=>{const n=t[1](e);return`${n.slice(0,U)}${n.slice(U).replace(ie,ce)}`},e=>btoa(t[2](e))];return(e,n)=>{try{return t[n](e)}catch(s){if(n===0)throw s;return t[0](e)}}})(),q=(()=>{const t=[e=>JSON.parse(e),e=>t[0](decodeURI(atob(e))),e=>t[1](`${e.slice(0,U)}${e.slice(U).replace(ie,ce)}`),e=>t[2](atob(e))];return(e,n)=>{try{return t[n](e)}catch(s){if(n===0)throw s;return t[0](e)}}})();setTimeout(()=>{Object.keys(i).forEach(t=>{var s;if(typeof i[t]!="string"||!t.startsWith(P)&&!t.startsWith(N))return;const e=+((s=i[t].match($e))==null?void 0:s[1]);if(!e||e*1e3-Date.now()>24*60*60*1e3)return;const n=q(i[t],0);!Array.isArray(n)||n[1]==null||!("exp"in n[1])||n[1].exp!==e||(oe[t]=setTimeout(()=>{F[t]?F[t].reset():delete i[t]},e*1e3-Date.now()))})},1e3),l.Atom=ne,l.AtomArrayDoActions=k,l.AtomBooleanDoActions=O,l.AtomNumberDoActions=ee,l.AtomObjectDoActions=te,l.AtomSetDoActions=re,l.atom=ge,l.configureAtomaric=he,l.configuredOptions=D,l.useAtom=ye,l.useAtomDo=Ae,l.useAtomGet=de,l.useAtomSet=Y,l.useAtomSetDeferred=me,l.useAtomValue=X,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
|