atomaric 0.0.78 → 0.0.81

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.
@@ -1 +1 @@
1
- (function(f,_){typeof exports=="object"&&typeof module<"u"?_(exports):typeof define=="function"&&define.amd?define(["exports"],_):(f=typeof globalThis<"u"?globalThis:f||self,_(f.atomaric={}))})(this,function(f){"use strict";let _=()=>{throw"call configureAtomaric() before all!"};const x={},de=t=>{x.useSyncExternalStore=_=t.useSyncExternalStore,x.keyPathSeparator=t.keyPathSeparator,x.securifyKeyLevel=t.securifyKeyLevel,x.securifyValueLevel=t.securifyValueLevel},Y=t=>_(t.subscribe,t.get),Z=t=>t.set,ge=t=>t.setDeferred,Ae=t=>t.get,me=t=>t.do,ye=t=>[Y(t),Z(t)],we=(t,e)=>new ie(t,e);class j{constructor(e){if(e)return new Proxy(this,{get:(i,s)=>s in this?i[s]:e[s]})}}const pe=(t,e)=>{const i=(s,r,o)=>new Proxy(s,{get:(a,g,m)=>{const y=o===0&&e.get!=null?e.get(a,g,m):a[g],h=y??(Array.isArray(a)?[]:{});return typeof h=="object"&&h!==null?i(Array.isArray(h)?h.slice(0):{...h},r.concat(Array.isArray(a)?+g:g),o+1):h},set:(a,g,m)=>(e.onSet(a,r,g,m,a[g])&&(a[g]=m),!0)});return i(t,[],0)};class v extends j{constructor(){super(...arguments),this.updateValue=(e,i)=>{const s=Array.isArray(e)?e.slice(0):{...e};let r=!1;return i(pe(s,{onSet:(o,a,g,m,y)=>{if(m===y)return!0;let h=s;r=!0;for(const $ of a){const d=h[$];h=h[$]=Array.isArray(d)?d.slice():{...d}}return h[g]=m,!0}})),r?s:e}}}class k extends v{constructor(e,i){super(i),this.a=e,this.push=(...s)=>{s.length!==0&&this.a.set(this.a.get().concat(s))},this.unshift=(...s)=>{s.length!==0&&this.a.set(s.concat(this.a.get()))},this.update=s=>{const r=this.a.get(),o=this.updateValue(r,s);o!==r&&this.a.set(o)},this.filter=s=>{const r=this.a.get().filter(s??Se);r.length!==this.a.get().length&&this.a.set(r)},this.add=s=>{this.a.get().includes(s)||this.a.set(this.a.get().concat([s]))},this.removeFirst=s=>{const r=this.a.get().indexOf(s);if(r<0)return;const o=this.a.get().slice(0);o.splice(r,1),this.a.set(o)},this.toggle=(s,r)=>{const o=this.a.get().slice(),a=o.indexOf(s);a<0?r?o.unshift(s):o.push(s):o.splice(a,1),this.a.set(o)}}}const Se=t=>t;class O extends j{constructor(e,i){super(i),this.a=e,this.toggle=()=>{this.a.set(!this.a.get())}}}class ee extends j{constructor(e,i){super(i),this.a=e,this.setValue=(s,r)=>{if(this.a.get().get(s)===r)return;const o=new Map(this.a.get());o.set(s,r),this.a.set(o)},this.setIfNo=(s,r)=>{if(this.a.get().has(s))return;const o=new Map(this.a.get());o.set(s,r),this.a.set(o)},this.delete=s=>{if(!this.a.get().has(s))return;const r=new Map(this.a.get());r.delete(s),this.a.set(r)},this.toggle=(s,r)=>{const o=new Map(this.a.get());o.has(s)?o.delete(s):o.set(s,r),this.a.set(o)},this.clear=()=>{this.a.set(new Map)},this.a=e}}class te extends j{constructor(e,i){super(i),this.a=e,this.increment=s=>{this.a.set(+this.a.get()+(s??1))}}}class se extends v{constructor(e,i){super(i),this.a=e,this.setPartial=s=>this.a.set(r=>({...r,...typeof s=="function"?s(this.a.get()):s})),this.update=s=>{const r=this.a.get(),o=this.updateValue(r,s);o!==r&&this.a.set(o)},this.setDeepPartial=(s,r,o,a=x.keyPathSeparator||".")=>{if(!a)return;if(s.includes(a)){let y=s.split(a);const h=y[y.length-1];y=y.slice(0,-1);const $={...this.a.get()};let d=$,A=o;for(const w of y){A=A==null?void 0:A[Array.isArray(A)?"0":w];const M=d[ne(d,w)]??(Array.isArray(A)?[]:{});if(M==null||typeof M!="object"){if(o==null)throw"Incorrect path for setDeepPartial";const S=typeof r=="function"?r(void 0):r;this.a.get()[s]!==S&&this.setPartial({[s]:S});return}d=d[ne(d,w)]=Array.isArray(M)?[...M]:{...M}}const q=d[h];d[h]=typeof r=="function"?r(d[h]):r,q!==d[h]&&this.a.set($);return}const g=this.a.get()[s],m=typeof r=="function"?r(g):r;m!==g&&this.setPartial({[s]:m})}}}const ne=(t,e)=>Array.isArray(t)?`${+e}`:e;class re extends j{constructor(e,i){super(i),this.a=e,this.add=s=>{this.a.get().has(s)||this.a.set(new Set(this.a.get()).add(s))},this.delete=s=>{if(!this.a.get().has(s))return;const r=new Set(this.a.get());r.delete(s),this.a.set(r)},this.toggle=s=>{const r=new Set(this.a.get());r.has(s)?r.delete(s):r.add(s),this.a.set(r)},this.clear=()=>{this.a.set(new Set)},this.a=e}}const be=(t,e,i)=>{const s=typeof i=="object"&&i!=null&&"do"in i?i.do((o,a)=>e.set(o,a),()=>e.get(),e,(o,a,g)=>e.setDeferred(o,a,g)):null,r={};return s&&Object.keys(s).forEach(o=>Object.defineProperty(r,o,{get:()=>s[o]})),typeof t=="number"?new te(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 Map?new ee(e,s):t instanceof Object?new se(e,s):new j(s)};class ie{constructor(e,i){e=typeof e=="function"?e():e;const s=n=>y=n,r=()=>y,o=new Set,a=n=>n(d());let g=!0,m=!1,y=e,h,$=()=>{},d=()=>r(),A=null,q=()=>{const n=be(e,w,i);return q=()=>n,n};const w=new Proxy(this,{get:(n,l)=>l==="do"?q():n[l],set:De}),M=()=>{g=!0,m!==!0&&$(d()),m=!1;try{B.postMessage({key:u,value:r()})}catch{}},S=(n,l)=>{const b=typeof n=="function"?n(d()):n;b!==d()&&(s(b),m=l,g&&(g=!1,o.forEach(a),queueMicrotask(M)))};this.set=(n,l)=>S(n,l),this.get=()=>d(),this.initialValue=e,this.isInitialValue=()=>e===r(),this.subscribe=n=>(o.add(n),()=>{o.delete(n)}),this.reset=()=>{S(e,!0)};const Te=(n,l)=>{S(n,l),h=void 0};if(this.setDeferred=(n,l=500,b,D=!0)=>{D&&h===void 0&&S(n,b),clearTimeout(h),h=setTimeout(Te,l,n,b)},i==null)return w;let p=null,z=null,H=!0,J=!0,Q=!1,T=0,V=0,ue=-1,C=e instanceof Set?n=>new Set(n):e instanceof Map?n=>new Map(n):n=>n,E=e instanceof Set?n=>{if(n instanceof Set)return Array.from(n);throw console.error(n),"The value is not Set instance"}:e instanceof Map?n=>{if(n instanceof Map){const l=[];return n.forEach((b,D)=>l.push([D,b])),l}throw console.error(n),"The value is not Set instance"}:n=>n;if(typeof i=="string")p=i;else if("storeKey"in i)H=i.warnOnDuplicateStoreKey??H,J=i.listenStorageChanges??J,p=i.storeKey,C=i.unzipValue??C,E=i.zipValue??E,Q=i.unchangable??Q,T=i.securifyKeyLevel??x.securifyKeyLevel??T,V=i.securifyValueLevel??x.securifyValueLevel??V,z=i.exp??z;else return w;const K=T?P(p,T):p,u=`${V?F:L}${K}`;if(T){const n=`${L}${p}`;n in c&&(c[u]=c[n],delete c[n])}else{const n=`${L}${P(p,T)}`;n in c&&(c[u]=c[n],delete c[n])}const X=z===null||!(z(w,u in c)instanceof Date)?n=>P([E(n)],0):n=>(A??(A={}),A.exp=z(w,u in c).getTime(),A.exp-Date.now()<24*60*60*1e3&&(clearTimeout(ue),clearTimeout(oe[u]),ue=setTimeout(()=>this.reset(),A.exp-Date.now())),A.exp=Math.trunc(A.exp/1e3),P([E(n),A],0));if(V){const n=`${L}${K}`,l=E,b=C;if(E=D=>{try{return P([l(D)],V)}catch{return delete c[u],""}},n in c){const D=`${L}${P(p,T)}`;try{c[D]=X(C(U(c[n],0)[0])),delete c[n]}catch{}}C=D=>{try{return b(U(D,V)[0])}catch{return delete c[u],""}}}else delete c[`${F}${K}`];const le=n=>{const l=U(n,0);return A=l[1],C(l[0])};let fe=!0;if(W[u]=w,c[`atom/${p}`]&&(c[u]||(c[u]=`[${c[`atom/${p}`]}]`),delete c[`atom/${p}`]),d=()=>{if(d=r,fe){fe=!1;try{s(u in c?le(c[u]):e)}catch{console.warn("Invalid json value",c[u])}}return r()},$=n=>{if(n===e){this.reset();return}c[u]=X(n)},this.reset=()=>{delete c[u],S(e,!0)},H&&I[u]!==void 0&&console.warn("Duplicate Atom key",p),J)if(Q){let n=!1,l;R[u]=this,I[u]=()=>{clearTimeout(l),l=setTimeout(()=>n=!1,10),!n&&(n=!0,c[u]=X(r()))}}else I[u]=n=>{if(n.newValue===null){this.reset();return}try{S(le(n.newValue))}catch{console.warn("Invalid json value",n.newValue)}};return w}}let B;try{B=new BroadcastChannel("updateHere"),B.addEventListener("message",t=>{var e;(e=R[t.data.key])==null||e.set(t.data.value,!0)})}catch{}const c=localStorage,I={},R={},De=(t,e)=>{throw`${e} is readonly property`};window.addEventListener("storage",t=>{var e;t.key===null||t.newValue===t.oldValue||(e=I[t.key])==null||e.call(I,t)});const xe=c.setItem.bind(c),$e=c.removeItem.bind(c);c.setItem=(t,e)=>{R[t]===void 0&&xe.call(c,t,e)},c.removeItem=t=>{R[t]===void 0&&$e.call(c,t)};const Me=/"exp":\s*(\d+)/,L="atom\\",F="atom`s\\",W={},oe={},ce=/[a-z]/gi,N=5,G={};for(let t=54;t<80;t++){if(t===68||t===72||t===55)continue;const e=String.fromCharCode(t+43).toUpperCase(),i=String.fromCharCode(t+43).toLowerCase();G[e]=i,G[i]=e}const ae=t=>G[t]??t,P=(()=>{const t=[e=>JSON.stringify(e),e=>btoa(encodeURI(t[0](e))),e=>{const i=t[1](e);return`${i.slice(0,N)}${i.slice(N).replace(ce,ae)}`},e=>btoa(t[2](e))];return(e,i)=>{try{return t[i](e)}catch(s){if(i===0)throw s;return t[0](e)}}})(),U=(()=>{const t=[e=>JSON.parse(e),e=>t[0](decodeURI(atob(e))),e=>t[1](`${e.slice(0,N)}${e.slice(N).replace(ce,ae)}`),e=>t[2](atob(e))];return(e,i)=>{try{return t[i](e)}catch(s){if(i===0)throw s;return t[0](e)}}})();setTimeout(()=>{Object.keys(c).forEach(t=>{var s;if(typeof c[t]!="string"||!t.startsWith(L)&&!t.startsWith(F))return;const e=(s=c[t].match(Me))==null?void 0:s[1];if(!e||+e*1e3-Date.now()>24*60*60*1e3)return;const i=U(c[t],0);!Array.isArray(i)||i[1]==null||!("exp"in i[1])||i[1].exp!==e||(oe[t]=setTimeout(()=>{W[t]?W[t].reset():delete c[t]},+e*1e3-Date.now()))})},1e3),f.Atom=ie,f.AtomArrayDoActions=k,f.AtomBooleanDoActions=O,f.AtomMapDoActions=ee,f.AtomNumberDoActions=te,f.AtomObjectDoActions=se,f.AtomSetDoActions=re,f.atom=we,f.configureAtomaric=de,f.configuredOptions=x,f.useAtom=ye,f.useAtomDo=me,f.useAtomGet=Ae,f.useAtomSet=Z,f.useAtomSetDeferred=ge,f.useAtomValue=Y,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
1
+ (function(d,$){typeof exports=="object"&&typeof module<"u"?$(exports):typeof define=="function"&&define.amd?define(["exports"],$):(d=typeof globalThis<"u"?globalThis:d||self,$(d.atomaric={}))})(this,function(d){"use strict";let $=()=>{throw"call configureAtomaric() before all!"};const z={},St=e=>{z.useSyncExternalStore=$=e.useSyncExternalStore,z.keyPathSeparator=e.keyPathSeparator,z.securifyKeyLevel=e.securifyKeyLevel,z.securifyValueLevel=e.securifyValueLevel},Le=e=>$(e.subscribe,e.get),Ve=e=>e.set,At=e=>e.setDeferred,Pt=e=>e.get,bt=e=>e.do,Dt=e=>[Le(e),Ve(e)],It=(e,t)=>new dt(e,t);class T{constructor(t){if(t)return new Proxy(this,{get:(r,n)=>n in this?r[n]:t[n]})}}var je=Symbol.for("immer-nothing"),Oe=Symbol.for("immer-draftable"),y=Symbol.for("immer-state"),Mt=process.env.NODE_ENV!=="production"?[function(e){return`The plugin for '${e}' has not been loaded into Immer. To enable the plugin, import and call \`enable${e}()\` when initializing your application.`},function(e){return`produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${e}'`},"This object has been frozen and should not be mutated",function(e){return"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? "+e},"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.","Immer forbids circular references","The first or second argument to `produce` must be a function","The third argument to `produce` must be a function or undefined","First argument to `createDraft` must be a plain object, an array, or an immerable object","First argument to `finishDraft` must be a draft returned by `createDraft`",function(e){return`'current' expects a draft, got: ${e}`},"Object.defineProperty() cannot be used on an Immer draft","Object.setPrototypeOf() cannot be used on an Immer draft","Immer only supports deleting array indices","Immer only supports setting array indices and the 'length' property",function(e){return`'original' expects a draft, got: ${e}`}]:[];function g(e,...t){if(process.env.NODE_ENV!=="production"){const r=Mt[e],n=E(r)?r.apply(null,t):r;throw new Error(`[Immer] ${n}`)}throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var w=Object,R=w.getPrototypeOf,Y="constructor",Q="prototype",me="configurable",X="enumerable",Z="writable",G="value",v=e=>!!e&&!!e[y];function I(e){var t;return e?Be(e)||re(e)||!!e[Oe]||!!((t=e[Y])!=null&&t[Oe])||ne(e)||se(e):!1}var Ct=w[Q][Y].toString(),Ue=new WeakMap;function Be(e){if(!e||!ge(e))return!1;const t=R(e);if(t===null||t===w[Q])return!0;const r=w.hasOwnProperty.call(t,Y)&&t[Y];if(r===Object)return!0;if(!E(r))return!1;let n=Ue.get(r);return n===void 0&&(n=Function.toString.call(r),Ue.set(r,n)),n===Ct}function ee(e,t,r=!0){q(e)===0?(r?Reflect.ownKeys(e):w.keys(e)).forEach(s=>{t(s,e[s],e)}):e.forEach((n,s)=>t(s,n,e))}function q(e){const t=e[y];return t?t.type_:re(e)?1:ne(e)?2:se(e)?3:0}var We=(e,t,r=q(e))=>r===2?e.has(t):w[Q].hasOwnProperty.call(e,t),pe=(e,t,r=q(e))=>r===2?e.get(t):e[t],te=(e,t,r,n=q(e))=>{n===2?e.set(t,r):n===3?e.add(r):e[t]=r};function zt(e,t){return e===t?e!==0||1/e===1/t:e!==e&&t!==t}var re=Array.isArray,ne=e=>e instanceof Map,se=e=>e instanceof Set,ge=e=>typeof e=="object",E=e=>typeof e=="function",we=e=>typeof e=="boolean";function vt(e){const t=+e;return Number.isInteger(t)&&String(t)===e}var M=e=>e.copy_||e.base_,Se=e=>e.modified_?e.copy_:e.base_;function Ae(e,t){if(ne(e))return new Map(e);if(se(e))return new Set(e);if(re(e))return Array[Q].slice.call(e);const r=Be(e);if(t===!0||t==="class_only"&&!r){const n=w.getOwnPropertyDescriptors(e);delete n[y];let s=Reflect.ownKeys(n);for(let i=0;i<s.length;i++){const c=s[i],u=n[c];u[Z]===!1&&(u[Z]=!0,u[me]=!0),(u.get||u.set)&&(n[c]={[me]:!0,[Z]:!0,[X]:u[X],[G]:e[c]})}return w.create(R(e),n)}else{const n=R(e);if(n!==null&&r)return{...e};const s=w.create(n);return w.assign(s,e)}}function Pe(e,t=!1){return oe(e)||v(e)||!I(e)||(q(e)>1&&w.defineProperties(e,{set:ie,add:ie,clear:ie,delete:ie}),w.freeze(e),t&&ee(e,(r,n)=>{Pe(n,!0)},!1)),e}function Tt(){g(2)}var ie={[G]:Tt};function oe(e){return e===null||!ge(e)?!0:w.isFrozen(e)}var ce="MapSet",be="Patches",Ge="ArrayMethods",qe={};function F(e){const t=qe[e];return t||g(0,e),t}var He=e=>!!qe[e],H,Je=()=>H,Et=(e,t)=>({drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0,handledSet_:new Set,processedForPatches_:new Set,mapSetPlugin_:He(ce)?F(ce):void 0,arrayMethodsPlugin_:He(Ge)?F(Ge):void 0});function Ke(e,t){t&&(e.patchPlugin_=F(be),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function De(e){Ie(e),e.drafts_.forEach(Ft),e.drafts_=null}function Ie(e){e===H&&(H=e.parent_)}var Ye=e=>H=Et(H,e);function Ft(e){const t=e[y];t.type_===0||t.type_===1?t.revoke_():t.revoked_=!0}function Qe(e,t){t.unfinalizedDrafts_=t.drafts_.length;const r=t.drafts_[0];if(e!==void 0&&e!==r){r[y].modified_&&(De(t),g(4)),I(e)&&(e=Xe(t,e));const{patchPlugin_:s}=t;s&&s.generateReplacementPatches_(r[y].base_,e,t)}else e=Xe(t,r);return xt(t,e,!0),De(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==je?e:void 0}function Xe(e,t){if(oe(t))return t;const r=t[y];if(!r)return ue(t,e.handledSet_,e);if(!ae(r,e))return t;if(!r.modified_)return r.base_;if(!r.finalized_){const{callbacks_:n}=r;if(n)for(;n.length>0;)n.pop()(e);tt(r,e)}return r.copy_}function xt(e,t,r=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&Pe(t,r)}function Ze(e){e.finalized_=!0,e.scope_.unfinalizedDrafts_--}var ae=(e,t)=>e.scope_===t,Nt=[];function et(e,t,r,n){const s=M(e),i=e.type_;if(n!==void 0&&pe(s,n,i)===t){te(s,n,r,i);return}if(!e.draftLocations_){const u=e.draftLocations_=new Map;ee(s,(_,h)=>{if(v(h)){const m=u.get(h)||[];m.push(_),u.set(h,m)}})}const c=e.draftLocations_.get(t)??Nt;for(const u of c)te(s,u,r,i)}function $t(e,t,r){e.callbacks_.push(function(s){var u;const i=t;if(!i||!ae(i,s))return;(u=s.mapSetPlugin_)==null||u.fixSetContents(i);const c=Se(i);et(e,i.draft_??i,c,r),tt(i,s)})}function tt(e,t){var n;if(e.modified_&&!e.finalized_&&(e.type_===3||e.type_===1&&e.allIndicesReassigned_||(((n=e.assigned_)==null?void 0:n.size)??0)>0)){const{patchPlugin_:s}=t;if(s){const i=s.getPath(e);i&&s.generatePatches_(e,i,t)}Ze(e)}}function Rt(e,t,r){const{scope_:n}=e;if(v(r)){const s=r[y];ae(s,n)&&s.callbacks_.push(function(){le(e);const c=Se(s);et(e,r,c,t)})}else I(r)&&e.callbacks_.push(function(){const i=M(e);e.type_===3?i.has(r)&&ue(r,n.handledSet_,n):pe(i,t,e.type_)===r&&n.drafts_.length>1&&(e.assigned_.get(t)??!1)===!0&&e.copy_&&ue(pe(e.copy_,t,e.type_),n.handledSet_,n)})}function ue(e,t,r){return!r.immer_.autoFreeze_&&r.unfinalizedDrafts_<1||v(e)||t.has(e)||!I(e)||oe(e)||(t.add(e),ee(e,(n,s)=>{if(v(s)){const i=s[y];if(ae(i,r)){const c=Se(i);te(e,n,c,e.type_),Ze(i)}}else I(s)&&ue(s,t,r)})),e}function kt(e,t){const r=re(e),n={type_:r?1:0,scope_:t?t.scope_:Je(),modified_:!1,finalized_:!1,assigned_:void 0,parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1,callbacks_:void 0};let s=n,i=fe;r&&(s=[n],i=J);const{revoke:c,proxy:u}=Proxy.revocable(s,i);return n.draft_=u,n.revoke_=c,[u,n]}var fe={get(e,t){if(t===y)return e;let r=e.scope_.arrayMethodsPlugin_;const n=e.type_===1&&typeof t=="string";if(n&&r!=null&&r.isArrayOperationMethod(t))return r.createMethodInterceptor(e,t);const s=M(e);if(!We(s,t,e.type_))return Lt(e,s,t);const i=s[t];if(e.finalized_||!I(i)||n&&e.operationMethod&&(r!=null&&r.isMutatingArrayMethod(e.operationMethod))&&vt(t))return i;if(i===Me(e.base_,t)){le(e);const c=e.type_===1?+t:t,u=ze(e.scope_,i,e,c);return e.copy_[c]=u}return i},has(e,t){return t in M(e)},ownKeys(e){return Reflect.ownKeys(M(e))},set(e,t,r){const n=rt(M(e),t);if(n!=null&&n.set)return n.set.call(e.draft_,r),!0;if(!e.modified_){const s=Me(M(e),t),i=s==null?void 0:s[y];if(i&&i.base_===r)return e.copy_[t]=r,e.assigned_.set(t,!1),!0;if(zt(r,s)&&(r!==void 0||We(e.base_,t,e.type_)))return!0;le(e),Ce(e)}return e.copy_[t]===r&&(r!==void 0||t in e.copy_)||Number.isNaN(r)&&Number.isNaN(e.copy_[t])||(e.copy_[t]=r,e.assigned_.set(t,!0),Rt(e,t,r)),!0},deleteProperty(e,t){return le(e),Me(e.base_,t)!==void 0||t in e.base_?(e.assigned_.set(t,!1),Ce(e)):e.assigned_.delete(t),e.copy_&&delete e.copy_[t],!0},getOwnPropertyDescriptor(e,t){const r=M(e),n=Reflect.getOwnPropertyDescriptor(r,t);return n&&{[Z]:!0,[me]:e.type_!==1||t!=="length",[X]:n[X],[G]:r[t]}},defineProperty(){g(11)},getPrototypeOf(e){return R(e.base_)},setPrototypeOf(){g(12)}},J={};for(let e in fe){let t=fe[e];J[e]=function(){const r=arguments;return r[0]=r[0][0],t.apply(this,r)}}J.deleteProperty=function(e,t){return process.env.NODE_ENV!=="production"&&isNaN(parseInt(t))&&g(13),J.set.call(this,e,t,void 0)},J.set=function(e,t,r){return process.env.NODE_ENV!=="production"&&t!=="length"&&isNaN(parseInt(t))&&g(14),fe.set.call(this,e[0],t,r,e[0])};function Me(e,t){const r=e[y];return(r?M(r):e)[t]}function Lt(e,t,r){var s;const n=rt(t,r);return n?G in n?n[G]:(s=n.get)==null?void 0:s.call(e.draft_):void 0}function rt(e,t){if(!(t in e))return;let r=R(e);for(;r;){const n=Object.getOwnPropertyDescriptor(r,t);if(n)return n;r=R(r)}}function Ce(e){e.modified_||(e.modified_=!0,e.parent_&&Ce(e.parent_))}function le(e){e.copy_||(e.assigned_=new Map,e.copy_=Ae(e.base_,e.scope_.immer_.useStrictShallowCopy_))}var Vt=class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!1,this.produce=(t,r,n)=>{if(E(t)&&!E(r)){const i=r;r=t;const c=this;return function(_=i,...h){return c.produce(_,m=>r.call(this,m,...h))}}E(r)||g(6),n!==void 0&&!E(n)&&g(7);let s;if(I(t)){const i=Ye(this),c=ze(i,t,void 0);let u=!0;try{s=r(c),u=!1}finally{u?De(i):Ie(i)}return Ke(i,n),Qe(s,i)}else if(!t||!ge(t)){if(s=r(t),s===void 0&&(s=t),s===je&&(s=void 0),this.autoFreeze_&&Pe(s,!0),n){const i=[],c=[];F(be).generateReplacementPatches_(t,s,{patches_:i,inversePatches_:c}),n(i,c)}return s}else g(1,t)},this.produceWithPatches=(t,r)=>{if(E(t))return(c,...u)=>this.produceWithPatches(c,_=>t(_,...u));let n,s;return[this.produce(t,r,(c,u)=>{n=c,s=u}),n,s]},we(e==null?void 0:e.autoFreeze)&&this.setAutoFreeze(e.autoFreeze),we(e==null?void 0:e.useStrictShallowCopy)&&this.setUseStrictShallowCopy(e.useStrictShallowCopy),we(e==null?void 0:e.useStrictIteration)&&this.setUseStrictIteration(e.useStrictIteration)}createDraft(e){I(e)||g(8),v(e)&&(e=jt(e));const t=Ye(this),r=ze(t,e,void 0);return r[y].isManual_=!0,Ie(t),r}finishDraft(e,t){const r=e&&e[y];(!r||!r.isManual_)&&g(9);const{scope_:n}=r;return Ke(n,t),Qe(void 0,n)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}setUseStrictIteration(e){this.useStrictIteration_=e}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(e,t){let r;for(r=t.length-1;r>=0;r--){const s=t[r];if(s.path.length===0&&s.op==="replace"){e=s.value;break}}r>-1&&(t=t.slice(r+1));const n=F(be).applyPatches_;return v(e)?n(e,t):this.produce(e,s=>n(s,t))}};function ze(e,t,r,n){const[s,i]=ne(t)?F(ce).proxyMap_(t,r):se(t)?F(ce).proxySet_(t,r):kt(t,r);return((r==null?void 0:r.scope_)??Je()).drafts_.push(s),i.callbacks_=(r==null?void 0:r.callbacks_)??[],i.key_=n,r&&n!==void 0?$t(r,i,n):i.callbacks_.push(function(_){var m;(m=_.mapSetPlugin_)==null||m.fixSetContents(i);const{patchPlugin_:h}=_;i.modified_&&h&&h.generatePatches_(i,[],_)}),s}function jt(e){return v(e)||g(10,e),nt(e)}function nt(e){if(!I(e)||oe(e))return e;const t=e[y];let r,n=!0;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,r=Ae(e,t.scope_.immer_.useStrictShallowCopy_),n=t.scope_.immer_.shouldUseStrictIteration()}else r=Ae(e,!0);return ee(r,(s,i)=>{te(r,s,nt(i))},n),t&&(t.finalized_=!1),r}var Ot=new Vt,st=Ot.produce;class it extends T{constructor(t,r){super(r),this.a=t,this.push=(...n)=>{n.length!==0&&this.a.set(this.a.get().concat(n))},this.unshift=(...n)=>{n.length!==0&&this.a.set(n.concat(this.a.get()))},this.update=n=>{const s=this.a.get(),i=st(s,c=>void n(c));i!==s&&this.a.set(i)},this.filter=n=>{const s=this.a.get().filter(n??Ut);s.length!==this.a.get().length&&this.a.set(s)},this.add=n=>{this.a.get().includes(n)||this.a.set(this.a.get().concat([n]))},this.removeFirst=n=>{const s=this.a.get().indexOf(n);if(s<0)return;const i=this.a.get().slice(0);i.splice(s,1),this.a.set(i)},this.toggle=(n,s)=>{const i=this.a.get().slice(),c=i.indexOf(n);c<0?s?i.unshift(n):i.push(n):i.splice(c,1),this.a.set(i)}}}const Ut=e=>e;class ot extends T{constructor(t,r){super(r),this.a=t,this.toggle=()=>{this.a.set(!this.a.get())}}}class ct extends T{constructor(t,r){super(r),this.a=t,this.setValue=(n,s)=>{if(this.a.get().get(n)===s)return;const i=new Map(this.a.get());i.set(n,s),this.a.set(i)},this.setIfNo=(n,s)=>{if(this.a.get().has(n))return;const i=new Map(this.a.get());i.set(n,s),this.a.set(i)},this.delete=n=>{if(!this.a.get().has(n))return;const s=new Map(this.a.get());s.delete(n),this.a.set(s)},this.toggle=(n,s)=>{const i=new Map(this.a.get());i.has(n)?i.delete(n):i.set(n,s),this.a.set(i)},this.clear=()=>{this.a.set(new Map)},this.a=t}}class at extends T{constructor(t,r){super(r),this.a=t,this.increment=n=>{this.a.set(+this.a.get()+(n??1))}}}class ut extends T{constructor(t,r){super(r),this.a=t,this.setPartial=n=>this.a.set(s=>({...s,...typeof n=="function"?n(this.a.get()):n})),this.update=n=>{const s=this.a.get(),i=st(s,c=>void n(c));i!==s&&this.a.set(i)},this.setDeepPartial=(n,s,i,c=z.keyPathSeparator||".")=>{if(!c)return;if(n.includes(c)){let h=n.split(c);const m=h[h.length-1];h=h.slice(0,-1);const x={...this.a.get()};let A=x,p=i;for(const j of h){p=p==null?void 0:p[Array.isArray(p)?"0":j];const S=A[ft(A,j)]??(Array.isArray(p)?[]:{});if(S==null||typeof S!="object"){if(i==null)throw"Incorrect path for setDeepPartial";const ye=typeof s=="function"?s(void 0):s;this.a.get()[n]!==ye&&this.setPartial({[n]:ye});return}A=A[ft(A,j)]=Array.isArray(S)?[...S]:{...S}}const b=A[m];A[m]=typeof s=="function"?s(A[m]):s,b!==A[m]&&this.a.set(x);return}const u=this.a.get()[n],_=typeof s=="function"?s(u):s;_!==u&&this.setPartial({[n]:_})}}}const ft=(e,t)=>Array.isArray(e)?`${+t}`:t;class lt extends T{constructor(t,r){super(r),this.a=t,this.add=n=>{this.a.get().has(n)||this.a.set(new Set(this.a.get()).add(n))},this.delete=n=>{if(!this.a.get().has(n))return;const s=new Set(this.a.get());s.delete(n),this.a.set(s)},this.toggle=n=>{const s=new Set(this.a.get());s.has(n)?s.delete(n):s.add(n),this.a.set(s)},this.clear=()=>{this.a.set(new Set)},this.a=t}}const Bt=(e,t,r)=>{const n=typeof r=="object"&&r!=null&&"do"in r?r.do((i,c)=>t.set(i,c),()=>t.get(),t,(i,c,u)=>t.setDeferred(i,c,u)):null,s={};return n&&Object.keys(n).forEach(i=>Object.defineProperty(s,i,{get:()=>n[i]})),typeof e=="number"?new at(t,n):typeof e=="boolean"?new ot(t,n):Array.isArray(e)?new it(t,n):e instanceof Set?new lt(t,n):e instanceof Map?new ct(t,n):e instanceof Object?new ut(t,n):new T(n)};class dt{constructor(t,r){t=typeof t=="function"?t():t;const n=o=>m=o,s=()=>m,i=new Set,c=o=>o(p());let u=!0,_=!1,h=()=>!0,m=t,x,A=()=>{},p=()=>s(),b=null,j=()=>{const o=Bt(t,S,r);return j=()=>o,o};const S=new Proxy(this,{get:(o,l)=>l==="do"?j():o[l],set:Wt}),ye=()=>{u=!0,_!==!0&&A(p()),_=!1;try{ve.postMessage({key:f,value:s()})}catch{}},O=(o,l)=>{const D=typeof o=="function"?o(p()):o;D===p()||!h(D,p())||(n(D),_=l,u&&(u=!1,i.forEach(c),queueMicrotask(ye)))};this.set=(o,l)=>O(o,l),this.get=()=>p(),this.initialValue=t,this.isInitialValue=()=>t===s(),this.subscribe=o=>(i.add(o),()=>{i.delete(o)}),this.reset=()=>{O(t,!0)};const Jt=(o,l)=>{O(o,l),x=void 0};if(this.setDeferred=(o,l=500,D,C=!0)=>{C&&x===void 0&&O(o,D),clearTimeout(x),x=setTimeout(Jt,l,o,D)},r==null)return S;let P=null,K=null,xe=!0,Ne=!0,$e=!1,N=0,U=0,mt=-1,B=t instanceof Set?o=>new Set(o):t instanceof Map?o=>new Map(o):o=>o,W=t instanceof Set?o=>{if(o instanceof Set)return Array.from(o);throw console.error(o),"The value is not Set instance"}:t instanceof Map?o=>{if(o instanceof Map){const l=[];return o.forEach((D,C)=>l.push([C,D])),l}throw console.error(o),"The value is not Set instance"}:o=>o;if(typeof r=="string")P=r;else if(h=r.filter??h,"storageKey"in r)xe=r.warnOnDuplicateStorageKey??xe,Ne=r.listenStorageChanges??Ne,P=r.storageKey,B=r.unzipValue??B,W=r.zipValue??W,$e=r.unchangable??$e,N=r.securifyKeyLevel??z.securifyKeyLevel??N,U=r.securifyValueLevel??z.securifyValueLevel??U,K=r.exp??K;else return S;const Re=N?V(P,N):P,f=`${U?Te:L}${Re}`;if(N){const o=`${L}${P}`;o in a&&(a[f]=a[o],delete a[o])}else{const o=`${L}${V(P,N)}`;o in a&&(a[f]=a[o],delete a[o])}const ke=K===null||!(K(S,f in a)instanceof Date)?o=>V([W(o)],0):o=>(b??(b={}),b.exp=K(S,f in a).getTime(),b.exp-Date.now()<24*60*60*1e3&&(clearTimeout(mt),clearTimeout(ht[f]),mt=setTimeout(()=>this.reset(),b.exp-Date.now())),b.exp=Math.trunc(b.exp/1e3),V([W(o),b],0));if(U){const o=`${L}${Re}`,l=W,D=B;if(W=C=>{try{return V([l(C)],U)}catch{return delete a[f],""}},o in a){const C=`${L}${V(P,N)}`;try{a[C]=ke(B(_e(a[o],0)[0])),delete a[o]}catch{}}B=C=>{try{return D(_e(C,U)[0])}catch{return delete a[f],""}}}else delete a[`${Te}${Re}`];const pt=o=>{const l=_e(o,0);return b=l[1],B(l[0])};let gt=!0;if(Ee[f]=S,a[`atom/${P}`]&&(a[f]||(a[f]=`[${a[`atom/${P}`]}]`),delete a[`atom/${P}`]),p=()=>{if(p=s,gt){gt=!1;try{n(f in a?pt(a[f]):t)}catch{console.warn("Invalid json value",a[f])}}return s()},A=o=>{if(o===t){this.reset();return}a[f]=ke(o)},this.reset=()=>{delete a[f],O(t,!0)},xe&&k[f]!==void 0&&console.warn("Duplicate Atom key",P),Ne)if($e){let o=!1,l;de[f]=this,k[f]=()=>{clearTimeout(l),l=setTimeout(()=>o=!1,10),!o&&(o=!0,a[f]=ke(s()))}}else k[f]=o=>{if(o.newValue===null){this.reset();return}try{O(pt(o.newValue))}catch{console.warn("Invalid json value",o.newValue)}};return S}}let ve;try{ve=new BroadcastChannel("updateHere"),ve.addEventListener("message",e=>{var t;(t=de[e.data.key])==null||t.set(e.data.value,!0)})}catch{}const a=localStorage,k={},de={},Wt=(e,t)=>{throw`${t} is readonly property`};window.addEventListener("storage",e=>{var t;e.key===null||e.newValue===e.oldValue||(t=k[e.key])==null||t.call(k,e)});const Gt=a.setItem.bind(a),qt=a.removeItem.bind(a);a.setItem=(e,t)=>{de[e]===void 0&&Gt.call(a,e,t)},a.removeItem=e=>{de[e]===void 0&&qt.call(a,e)};const Ht=/"exp":\s*(\d+)/,L="atom\\",Te="atom`s\\",Ee={},ht={},_t=/[a-z]/gi,he=5,Fe={};for(let e=54;e<80;e++){if(e===68||e===72||e===55)continue;const t=String.fromCharCode(e+43).toUpperCase(),r=String.fromCharCode(e+43).toLowerCase();Fe[t]=r,Fe[r]=t}const yt=e=>Fe[e]??e,V=(()=>{const e=[t=>JSON.stringify(t),t=>btoa(encodeURI(e[0](t))),t=>{const r=e[1](t);return`${r.slice(0,he)}${r.slice(he).replace(_t,yt)}`},t=>btoa(e[2](t))];return(t,r)=>{try{return e[r](t)}catch(n){if(r===0)throw n;return e[0](t)}}})(),_e=(()=>{const e=[t=>JSON.parse(t),t=>e[0](decodeURI(atob(t))),t=>e[1](`${t.slice(0,he)}${t.slice(he).replace(_t,yt)}`),t=>e[2](atob(t))];return(t,r)=>{try{return e[r](t)}catch(n){if(r===0)throw n;return e[0](t)}}})();setTimeout(()=>{Object.keys(a).forEach(e=>{var n;if(typeof a[e]!="string"||!e.startsWith(L)&&!e.startsWith(Te))return;const t=(n=a[e].match(Ht))==null?void 0:n[1];if(!t||+t*1e3-Date.now()>24*60*60*1e3)return;const r=_e(a[e],0);!Array.isArray(r)||r[1]==null||!("exp"in r[1])||r[1].exp!==t||(ht[e]=setTimeout(()=>{Ee[e]?Ee[e].reset():delete a[e]},+t*1e3-Date.now()))})},1e3),d.Atom=dt,d.AtomArrayDoActions=it,d.AtomBooleanDoActions=ot,d.AtomMapDoActions=ct,d.AtomNumberDoActions=at,d.AtomObjectDoActions=ut,d.AtomSetDoActions=lt,d.atom=It,d.configureAtomaric=St,d.configuredOptions=z,d.useAtom=Dt,d.useAtomDo=bt,d.useAtomGet=Pt,d.useAtomSet=Ve,d.useAtomSetDeferred=At,d.useAtomValue=Le,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "atomaric",
3
3
  "description": "Manage your project state",
4
- "version": "0.0.78",
4
+ "version": "0.0.81",
5
5
  "type": "module",
6
6
  "main": "./build/atomaric.umd.cjs",
7
7
  "module": "./build/atomaric.js",
@@ -49,6 +49,7 @@
49
49
  "vite-plugin-eslint": "^1.8.1"
50
50
  },
51
51
  "dependencies": {
52
+ "immer": "^11.1.4",
52
53
  "typescript": "~5.7.2"
53
54
  }
54
55
  }
package/types/index.d.ts CHANGED
@@ -21,11 +21,11 @@ export type ObjectActionsSetDeepPartialSeparator = Register extends {
21
21
 
22
22
  type Sunscriber<Value> = (value: Value) => void;
23
23
 
24
- export type AtomStoreKey = `${string}${string}:${string}${string}`;
24
+ export type AtomStorageKey = `${string}${string}:${string}${string}`;
25
25
 
26
26
  export type AtomOptions<Value, Actions extends Record<string, AnyFunc> = Record<string, AnyFunc>> = {
27
27
  /** **default: true** */
28
- warnOnDuplicateStoreKey?: boolean;
28
+ warnOnDuplicateStorageKey?: boolean;
29
29
  /** will update value if localStorage value is changed
30
30
  * **default: true**
31
31
  */
@@ -40,10 +40,13 @@ export type AtomOptions<Value, Actions extends Record<string, AnyFunc> = Record<
40
40
  unchangable?: true;
41
41
  /** return value expire Date */
42
42
  exp?: (self: Atom<Value>, isValueWasStoraged: boolean) => Date;
43
+
44
+ /** silter setted value */
45
+ filter?: (newValue: Value, prevValue: Value) => boolean;
43
46
  } & (
44
47
  | {
45
48
  /** save in localStorage by this key */
46
- storeKey: AtomStoreKey;
49
+ storageKey: AtomStorageKey;
47
50
  securifyKeyLevel?: AtomSecureLevel;
48
51
  securifyValueLevel?: AtomSecureLevel;
49
52
  }
@@ -79,22 +82,26 @@ export type ObjectActionsSetDeepPartialDoAction<Value> = <
79
82
  separator?: Sep,
80
83
  ) => void;
81
84
 
82
- export type DefaultActions<Value> = Value extends Set<infer Val>
83
- ? IAtomSetDoActions<Val>
84
- : Value extends Map<infer Key, infer Val>
85
- ? IAtomMapDoActions<Value, Key, Val>
86
- : Value extends boolean
87
- ? IAtomBooleanDoActions
88
- : Value extends (infer Val)[]
89
- ? IAtomArrayDoActions<Val>
90
- : Value extends number
91
- ? IAtomNumberDoActions
92
- : Value extends object
93
- ? IAtomObjectDoActions<Value>
94
- : object;
85
+ export type DefaultActions<Value> =
86
+ Value extends Set<infer Val>
87
+ ? IAtomSetDoActions<Val>
88
+ : Value extends Map<infer Key, infer Val>
89
+ ? IAtomMapDoActions<Value, Key, Val>
90
+ : Value extends boolean
91
+ ? IAtomBooleanDoActions
92
+ : Value extends (infer Val)[]
93
+ ? IAtomArrayDoActions<Val>
94
+ : Value extends number
95
+ ? IAtomNumberDoActions
96
+ : Value extends object
97
+ ? IAtomObjectDoActions<Value>
98
+ : object;
95
99
 
96
100
  declare class Atom<Value, Actions extends Record<string, AnyFunc> = Record<string, AnyFunc>> {
97
- constructor(initialValue: Value | (() => Value), storeKeyOrOptions: StoreKeyOrOptions<Value, Actions> | undefined);
101
+ constructor(
102
+ initialValue: Value | (() => Value),
103
+ storageKeyOrOptions: StorageKeyOrOptions<Value, Actions> | undefined,
104
+ );
98
105
 
99
106
  /** initial value */
100
107
  readonly initialValue: Value;
@@ -128,13 +135,13 @@ export function useAtomDo<Value, Actions extends Record<string, AnyFunc> = Recor
128
135
  atom: Atom<Value, Actions>,
129
136
  ): Actions & DefaultActions<Value>;
130
137
 
131
- export type StoreKeyOrOptions<Value, Actions extends Record<string, AnyFunc> = Record<string, AnyFunc>> =
132
- | AtomStoreKey
138
+ export type StorageKeyOrOptions<Value, Actions extends Record<string, AnyFunc> = Record<string, AnyFunc>> =
139
+ | AtomStorageKey
133
140
  | AtomOptions<Value, Actions>;
134
141
 
135
142
  export function atom<Value, Actions extends Record<string, AnyFunc> = Record<string, AnyFunc>>(
136
143
  value: Value | (() => Value),
137
- storeKeyOrOptions?: StoreKeyOrOptions<Value, Actions>,
144
+ storageKeyOrOptions?: StorageKeyOrOptions<Value, Actions>,
138
145
  ): Atom<Value, Actions>;
139
146
 
140
147
  /** invoke this function before all atom usages */