atomaric 0.0.81 → 0.0.82
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 +14 -14
- package/build/atomaric.umd.cjs +1 -1
- package/package.json +1 -1
- package/types/index.d.ts +2 -2
package/build/atomaric.js
CHANGED
|
@@ -659,8 +659,8 @@ class Nt extends F {
|
|
|
659
659
|
}
|
|
660
660
|
S = S[Ke(S, N)] = Array.isArray(m) ? [...m] : { ...m };
|
|
661
661
|
}
|
|
662
|
-
const
|
|
663
|
-
S[_] = typeof s == "function" ? s(S[_]) : s,
|
|
662
|
+
const b = S[_];
|
|
663
|
+
S[_] = typeof s == "function" ? s(S[_]) : s, b !== S[_] && this.a.set(z);
|
|
664
664
|
return;
|
|
665
665
|
}
|
|
666
666
|
const u = this.a.get()[n], h = typeof s == "function" ? s(u) : s;
|
|
@@ -698,8 +698,8 @@ class kt {
|
|
|
698
698
|
constructor(t, r) {
|
|
699
699
|
t = typeof t == "function" ? t() : t;
|
|
700
700
|
const n = (o) => _ = o, s = () => _, i = /* @__PURE__ */ new Set(), c = (o) => o(y());
|
|
701
|
-
let u = !0, h = !1, d = () =>
|
|
702
|
-
}, y = () => s(),
|
|
701
|
+
let u = !0, h = !1, d = (o) => o, _ = t, z, S = () => {
|
|
702
|
+
}, y = () => s(), b = null, N = () => {
|
|
703
703
|
const o = Rt(t, m, r);
|
|
704
704
|
return N = () => o, o;
|
|
705
705
|
};
|
|
@@ -713,8 +713,8 @@ class kt {
|
|
|
713
713
|
} catch {
|
|
714
714
|
}
|
|
715
715
|
}, $ = (o, l) => {
|
|
716
|
-
|
|
717
|
-
|
|
716
|
+
let A = typeof o == "function" ? o(y()) : o;
|
|
717
|
+
A = d(A, y()), A !== y() && (n(A), h = l, u && (u = !1, i.forEach(c), queueMicrotask(J)));
|
|
718
718
|
};
|
|
719
719
|
this.set = (o, l) => $(o, l), this.get = () => y(), this.initialValue = t, this.isInitialValue = () => t === s(), this.subscribe = (o) => (i.add(o), () => {
|
|
720
720
|
i.delete(o);
|
|
@@ -724,8 +724,8 @@ class kt {
|
|
|
724
724
|
const ft = (o, l) => {
|
|
725
725
|
$(o, l), z = void 0;
|
|
726
726
|
};
|
|
727
|
-
if (this.setDeferred = (o, l = 500,
|
|
728
|
-
D && z === void 0 && $(o,
|
|
727
|
+
if (this.setDeferred = (o, l = 500, A, D = !0) => {
|
|
728
|
+
D && z === void 0 && $(o, A), clearTimeout(z), z = setTimeout(ft, l, o, A);
|
|
729
729
|
}, r == null) return m;
|
|
730
730
|
let P = null, B = null, _e = !0, ye = !0, pe = !1, x = 0, R = 0, Re = -1, k = t instanceof Set ? (o) => new Set(o) : t instanceof Map ? (o) => new Map(o) : (o) => o, L = t instanceof Set ? (o) => {
|
|
731
731
|
if (o instanceof Set) return Array.from(o);
|
|
@@ -733,13 +733,13 @@ class kt {
|
|
|
733
733
|
} : t instanceof Map ? (o) => {
|
|
734
734
|
if (o instanceof Map) {
|
|
735
735
|
const l = [];
|
|
736
|
-
return o.forEach((
|
|
736
|
+
return o.forEach((A, D) => l.push([D, A])), l;
|
|
737
737
|
}
|
|
738
738
|
throw console.error(o), "The value is not Set instance";
|
|
739
739
|
} : (o) => o;
|
|
740
740
|
if (typeof r == "string")
|
|
741
741
|
P = r;
|
|
742
|
-
else if (d = r.
|
|
742
|
+
else if (d = r.map ?? d, "storageKey" in r)
|
|
743
743
|
_e = r.warnOnDuplicateStorageKey ?? _e, ye = r.listenStorageChanges ?? ye, P = r.storageKey, k = r.unzipValue ?? k, L = r.zipValue ?? L, pe = r.unchangable ?? pe, x = r.securifyKeyLevel ?? T.securifyKeyLevel ?? x, R = r.securifyValueLevel ?? T.securifyValueLevel ?? R, B = r.exp ?? B;
|
|
744
744
|
else return m;
|
|
745
745
|
const me = x ? V(P, x) : P, f = `${R ? ve : U}${me}`;
|
|
@@ -750,9 +750,9 @@ class kt {
|
|
|
750
750
|
const o = `${U}${V(P, x)}`;
|
|
751
751
|
o in a && (a[f] = a[o], delete a[o]);
|
|
752
752
|
}
|
|
753
|
-
const ge = B === null || !(B(m, f in a) instanceof Date) ? (o) => V([L(o)], 0) : (o) => (
|
|
753
|
+
const ge = B === null || !(B(m, f in a) instanceof Date) ? (o) => V([L(o)], 0) : (o) => (b ?? (b = {}), b.exp = B(m, f in a).getTime(), b.exp - Date.now() < 24 * 60 * 60 * 1e3 && (clearTimeout(Re), clearTimeout(ct[f]), Re = setTimeout(() => this.reset(), b.exp - Date.now())), b.exp = Math.trunc(b.exp / 1e3), V([L(o), b], 0));
|
|
754
754
|
if (R) {
|
|
755
|
-
const o = `${U}${me}`, l = L,
|
|
755
|
+
const o = `${U}${me}`, l = L, A = k;
|
|
756
756
|
if (L = (D) => {
|
|
757
757
|
try {
|
|
758
758
|
return V([l(D)], R);
|
|
@@ -768,7 +768,7 @@ class kt {
|
|
|
768
768
|
}
|
|
769
769
|
k = (D) => {
|
|
770
770
|
try {
|
|
771
|
-
return
|
|
771
|
+
return A(X(D, R)[0]);
|
|
772
772
|
} catch {
|
|
773
773
|
return delete a[f], "";
|
|
774
774
|
}
|
|
@@ -776,7 +776,7 @@ class kt {
|
|
|
776
776
|
} else delete a[`${ve}${me}`];
|
|
777
777
|
const ke = (o) => {
|
|
778
778
|
const l = X(o, 0);
|
|
779
|
-
return
|
|
779
|
+
return b = l[1], k(l[0]);
|
|
780
780
|
};
|
|
781
781
|
let Le = !0;
|
|
782
782
|
if (Te[f] = m, a[`atom/${P}`] && (a[f] || (a[f] = `[${a[`atom/${P}`]}]`), delete a[`atom/${P}`]), y = () => {
|
package/build/atomaric.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
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"})});
|
|
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 D=A[m];A[m]=typeof s=="function"?s(A[m]):s,D!==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=o=>o,m=t,x,A=()=>{},p=()=>s(),D=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)=>{let b=typeof o=="function"?o(p()):o;b=h(b,p()),b!==p()&&(n(b),_=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,b,C=!0)=>{C&&x===void 0&&O(o,b),clearTimeout(x),x=setTimeout(Jt,l,o,b)},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((b,C)=>l.push([C,b])),l}throw console.error(o),"The value is not Set instance"}:o=>o;if(typeof r=="string")P=r;else if(h=r.map??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=>(D??(D={}),D.exp=K(S,f in a).getTime(),D.exp-Date.now()<24*60*60*1e3&&(clearTimeout(mt),clearTimeout(ht[f]),mt=setTimeout(()=>this.reset(),D.exp-Date.now())),D.exp=Math.trunc(D.exp/1e3),V([W(o),D],0));if(U){const o=`${L}${Re}`,l=W,b=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 b(_e(C,U)[0])}catch{return delete a[f],""}}}else delete a[`${Te}${Re}`];const pt=o=>{const l=_e(o,0);return D=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
package/types/index.d.ts
CHANGED
|
@@ -41,8 +41,8 @@ export type AtomOptions<Value, Actions extends Record<string, AnyFunc> = Record<
|
|
|
41
41
|
/** return value expire Date */
|
|
42
42
|
exp?: (self: Atom<Value>, isValueWasStoraged: boolean) => Date;
|
|
43
43
|
|
|
44
|
-
/**
|
|
45
|
-
|
|
44
|
+
/** map setted value */
|
|
45
|
+
map?: (newValue: Value, prevValue: Value) => Value;
|
|
46
46
|
} & (
|
|
47
47
|
| {
|
|
48
48
|
/** save in localStorage by this key */
|