@storix-js/persist 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +433 -357
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var at=Symbol.for("preact-signals");function G(){if(E>1)E--;else{for(var e,t=!1;A!==void 0;){var o=A;for(A=void 0,Q++;o!==void 0;){var d=o.o;if(o.o=void 0,o.f&=-3,!(8&o.f)&&it(o))try{o.c()}catch(O){t||(e=O,t=!0)}o=d}}if(Q=0,E--,t)throw e}}function L(e){if(E>0)return e();E++;try{return e()}finally{G()}}var l=void 0;function et(e){var t=l;l=void 0;try{return e()}finally{l=t}}var A=void 0,E=0,Q=0,F=0;function nt(e){if(l!==void 0){var t=e.n;if(t===void 0||t.t!==l)return t={i:0,S:e,p:l.s,n:void 0,t:l,e:void 0,x:void 0,r:t},l.s!==void 0&&(l.s.n=t),l.s=t,e.n=t,32&l.f&&e.S(t),t;if(t.i===-1)return t.i=0,t.n!==void 0&&(t.n.p=t.p,t.p!==void 0&&(t.p.n=t.n),t.p=l.s,t.n=void 0,l.s.n=t,l.s=t),t}}function b(e,t){this.v=e,this.i=0,this.n=void 0,this.t=void 0,this.W=t==null?void 0:t.watched,this.Z=t==null?void 0:t.unwatched,this.name=t==null?void 0:t.name}b.prototype.brand=at;b.prototype.h=function(){return!0};b.prototype.S=function(e){var t=this,o=this.t;o!==e&&e.e===void 0&&(e.x=o,this.t=e,o!==void 0?o.e=e:et(function(){var d;(d=t.W)==null||d.call(t)}))};b.prototype.U=function(e){var t=this;if(this.t!==void 0){var o=e.e,d=e.x;o!==void 0&&(o.x=d,e.e=void 0),d!==void 0&&(d.e=o,e.x=void 0),e===this.t&&(this.t=d,d===void 0&&et(function(){var O;(O=t.Z)==null||O.call(t)}))}};b.prototype.subscribe=function(e){var t=this;return ut(function(){var o=t.value,d=l;l=void 0;try{e(o)}finally{l=d}},{name:"sub"})};b.prototype.valueOf=function(){return this.value};b.prototype.toString=function(){return this.value+""};b.prototype.toJSON=function(){return this.value};b.prototype.peek=function(){var e=l;l=void 0;try{return this.value}finally{l=e}};Object.defineProperty(b.prototype,"value",{get:function(){var e=nt(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(Q>100)throw new Error("Cycle detected");this.v=e,this.i++,F++,E++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{G()}}}});function ct(e,t){return new b(e,t)}function it(e){for(var t=e.s;t!==void 0;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function ot(e){for(var t=e.s;t!==void 0;t=t.n){var o=t.S.n;if(o!==void 0&&(t.r=o),t.S.n=t,t.i=-1,t.n===void 0){e.s=t;break}}}function rt(e){for(var t=e.s,o=void 0;t!==void 0;){var d=t.p;t.i===-1?(t.S.U(t),d!==void 0&&(d.n=t.n),t.n!==void 0&&(t.n.p=d)):o=t,t.S.n=t.r,t.r!==void 0&&(t.r=void 0),t=d}e.s=o}function U(e,t){b.call(this,void 0),this.x=e,this.s=void 0,this.g=F-1,this.f=4,this.W=t==null?void 0:t.watched,this.Z=t==null?void 0:t.unwatched,this.name=t==null?void 0:t.name}U.prototype=new b;U.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===F))return!0;if(this.g=F,this.f|=1,this.i>0&&!it(this))return this.f&=-2,!0;var e=l;try{ot(this),l=this;var t=this.x();(16&this.f||this.v!==t||this.i===0)&&(this.v=t,this.f&=-17,this.i++)}catch(o){this.v=o,this.f|=16,this.i++}return l=e,rt(this),this.f&=-2,!0};U.prototype.S=function(e){if(this.t===void 0){this.f|=36;for(var t=this.s;t!==void 0;t=t.n)t.S.S(t)}b.prototype.S.call(this,e)};U.prototype.U=function(e){if(this.t!==void 0&&(b.prototype.U.call(this,e),this.t===void 0)){this.f&=-33;for(var t=this.s;t!==void 0;t=t.n)t.S.U(t)}};U.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var e=this.t;e!==void 0;e=e.x)e.t.N()}};Object.defineProperty(U.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=nt(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function tt(e,t){return new U(e,t)}function st(e){var t=e.u;if(e.u=void 0,typeof t=="function"){E++;var o=l;l=void 0;try{t()}catch(d){throw e.f&=-2,e.f|=8,X(e),d}finally{l=o,G()}}}function X(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,st(e)}function ft(e){if(l!==this)throw new Error("Out-of-order effect");rt(this),l=e,this.f&=-2,8&this.f&&X(this),G()}function K(e,t){this.x=e,this.u=void 0,this.s=void 0,this.o=void 0,this.f=32,this.name=t==null?void 0:t.name}K.prototype.c=function(){var e=this.S();try{if(8&this.f||this.x===void 0)return;var t=this.x();typeof t=="function"&&(this.u=t)}finally{e()}};K.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,st(this),ot(this),E++;var e=l;return l=this,ft.bind(this,e)};K.prototype.N=function(){2&this.f||(this.f|=2,this.o=A,A=this)};K.prototype.d=function(){this.f|=8,1&this.f||X(this)};K.prototype.dispose=function(){this.d()};function ut(e,t){var o=new K(e,t);try{o.c()}catch(O){throw o.d(),O}var d=o.d.bind(o);return d[Symbol.dispose]=d,d}function dt(e={}){const t=(e.namespace??"default").trim()||"default",o=e.plugins??[],d=new Map;function O(S,D){return function(){var Z;const j=`${t}:${S}`,R=d.get(S);if(R)return R;const N=D.state(),x=D.modules??{},z={...N};for(const[i,n]of Object.entries(x))z[i]=n.state();const y=ct(z),I=new Map,H=new Map,q=new Map,P=new Map,$=new Map,T=new Set,M=new Set(Object.keys(N)),W=new Set(Object.keys(D.getters??{})),C=new Set(Object.keys(D.actions??{})),r=i=>y.value[i]??{},a=(i,n)=>{y.value={...y.value,[i]:n}},h=new Proxy({},{get(i,n){var c,f;if(I.has(n))return(c=I.get(n))==null?void 0:c.value;if($.has(n))return(f=$.get(n))==null?void 0:f.value;if(M.has(n))return y.value[n];const p=P.get(n);return p?r(p.moduleName)[p.key]:y.value[n]}});for(const[i,n]of Object.entries(D.getters??{}))I.set(i,tt(()=>n(y.value,h)));const w=(i,n)=>{var c;for(const f of T)f(i);for(const f of o)(c=f.onMutation)==null||c.call(f,n,i)},J=(i,n,c,f)=>{const p=y.value[i];Object.is(p,n)||(y.value={...y.value,[i]:n},w({namespace:t,scopeId:j,storeId:S,key:i,oldValue:p,newValue:n,origin:c},f))},B=(i,n,c,f,p)=>{const m=r(i),s=m[n];Object.is(s,c)||(a(i,{...m,[n]:c}),w({namespace:t,scopeId:j,storeId:S,key:`${i}.${n}`,oldValue:s,newValue:c,origin:f},p))},g={$id:S,$namespace:t,$scopeId:j,$subscribe(i){return T.add(i),()=>T.delete(i)},$dispose(){var i;T.clear();for(const n of o)(i=n.onDispose)==null||i.call(n,v);d.delete(S)},$patch(i,n="local"){L(()=>{for(const[c,f]of Object.entries(i)){const p=P.get(c);if(p){B(p.moduleName,p.key,f,n,v);continue}if(c.includes(".")){const[m,s]=c.split(".",2);if(x[m]){B(m,s,f,n,v);continue}}if(x[c]&&f&&typeof f=="object"&&!Array.isArray(f)){for(const[m,s]of Object.entries(f))B(c,m,s,n,v);continue}J(c,f,n,v)}})},$snapshot(){return{...y.value}}};for(const[i,n]of Object.entries(x)){const c=new Map,f=new Map,p=new Proxy({},{get(s,u){var k,V,Y;if(c.has(u))return(k=c.get(u))==null?void 0:k.value;if(I.has(u))return(V=I.get(u))==null?void 0:V.value;if($.has(u))return(Y=$.get(u))==null?void 0:Y.value;const _=r(i);if(u in _)return _[u];if(M.has(u))return y.value[u]}});for(const[s,u]of Object.entries(n.getters??{}))c.set(s,tt(()=>u(r(i),y.value,p)));let m;for(const[s,u]of Object.entries(n.actions??{}))f.set(s,(...k)=>L(()=>u.apply(m,k)));m=new Proxy({},{get(s,u){var k;if(f.has(u))return f.get(u);if(c.has(u))return(k=c.get(u))==null?void 0:k.value;const V=r(i);return u in V?V[u]:v[u]},set(s,u,k){if(f.has(u)||c.has(u))return!1;const V=r(i);return u in V?B(i,u,k,"local",v):v[u]=k,!0}}),q.set(i,m),H.set(i,c);for(const s of Object.keys(r(i)))!(M.has(s)||W.has(s)||C.has(s)||Reflect.has(g,s)||x[s]!==void 0)&&!P.has(s)&&P.set(s,{moduleName:i,key:s});for(const[s,u]of c.entries())!(M.has(s)||W.has(s)||C.has(s)||Reflect.has(g,s)||x[s]!==void 0)&&!$.has(s)&&$.set(s,u);for(const[s,u]of f.entries())!(M.has(s)||W.has(s)||C.has(s)||Reflect.has(g,s)||x[s]!==void 0)&&!Reflect.has(g,s)&&(g[s]=u)}const v=new Proxy(g,{get(i,n,c){var f,p;if(Reflect.has(i,n))return Reflect.get(i,n,c);if(q.has(n))return q.get(n);if(I.has(n))return(f=I.get(n))==null?void 0:f.value;if($.has(n))return(p=$.get(n))==null?void 0:p.value;if(M.has(n))return y.value[n];const m=P.get(n);return m?r(m.moduleName)[m.key]:y.value[n]},set(i,n,c,f){if(Reflect.has(i,n))return Reflect.set(i,n,c,f);const p=P.get(n);return p?(B(p.moduleName,p.key,c,"local",f),!0):(J(n,c,"local",f),!0)}});for(const[i,n]of Object.entries(D.actions??{}))g[i]=(...c)=>L(()=>n.apply(v,c));for(const i of o)(Z=i.onInit)==null||Z.call(i,v);return d.set(S,v),v}}return{defineStore:O,use(S){o.push(S)}}}dt();function lt(e={}){var W,C;const t=e.keyPrefix??"storix",o=new Set(e.include??[]),d=e.storage??"localStorage",O=e.serialize??JSON.stringify,S=e.deserialize??(r=>JSON.parse(r)),D=e.debounce??100,Z=((W=e.indexedDB)==null?void 0:W.dbName)??`${t}-persist`,j=((C=e.indexedDB)==null?void 0:C.storeName)??"stores",R=new Map,N=new Map;let x=null;const z=r=>{const a=[r.$id,r.$scopeId];return!(o.size>0&&!a.some(h=>o.has(h)))},y=r=>`${t}:${r.$namespace}:${r.$id}`,I=()=>x||(x=new Promise((r,a)=>{const h=window.indexedDB.open(Z,1);h.onupgradeneeded=()=>{const w=h.result;w.objectStoreNames.contains(j)||w.createObjectStore(j)},h.onsuccess=()=>r(h.result),h.onerror=()=>a(h.error??new Error("IndexedDB open failed"))}),x),H=async r=>{const a=await I(),h=y(r);return new Promise((w,J)=>{const g=a.transaction(j,"readonly").objectStore(j).get(h);g.onsuccess=()=>{const v=g.result;if(typeof v!="string"){w(null);return}try{w(S(v))}catch{w(null)}},g.onerror=()=>J(g.error??new Error("IndexedDB read failed"))})},q=async(r,a)=>{const h=await I(),w=y(r),J=O(a);return new Promise((B,g)=>{const v=h.transaction(j,"readwrite");v.objectStore(j).put(J,w),v.oncomplete=()=>B(),v.onerror=()=>g(v.error??new Error("IndexedDB write failed")),v.onabort=()=>g(v.error??new Error("IndexedDB write aborted"))})},P=async r=>{if(typeof window>"u")return null;if(d==="indexedDB"&&"indexedDB"in window)try{return await H(r)}catch{return null}try{const a=window.localStorage.getItem(y(r));return a?S(a):null}catch{return null}},$=r=>{if(typeof window>"u")return;const a=R.get(r.$scopeId);if(a){if(d==="indexedDB"&&"indexedDB"in window){q(r,a).catch(()=>{});return}try{window.localStorage.setItem(y(r),O(a))}catch{}}},T=r=>{const a=r.$scopeId,h=N.get(a);if(h&&(clearTimeout(h),N.delete(a)),D<=0){$(r);return}const w=setTimeout(()=>{N.delete(a),$(r)},D);N.set(a,w)},M=r=>{const a=r.$scopeId,h=N.get(a);h&&(clearTimeout(h),N.delete(a)),$(r)};return{name:"persist",onInit(r){const a=r;typeof window>"u"||z(a)&&(async()=>{const h=await P(a);h&&(R.set(a.$scopeId,h),a.$patch(h,"remote"))})()},onMutation(r,a){const h=r;if(typeof window>"u"||!z(h))return;const w=R.get(h.$scopeId)??{};w[a.key]=a.newValue,R.set(h.$scopeId,w),T(h)},onDispose(r){const a=r;z(a)&&M(a)}}}exports.persistPlugin=lt;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var fe=Symbol.for("preact-signals");function Y(){if(T>1)T--;else{var t,e=!1;for((function(){var g=Q;for(Q=void 0;g!==void 0;)g.S.v===g.v&&(g.S.i=g.i),g=g.o})();H!==void 0;){var o=H;for(H=void 0,L++;o!==void 0;){var f=o.u;if(o.u=void 0,o.f&=-3,!(8&o.f)&&ae(o))try{o.c()}catch(g){e||(t=g,e=!0)}o=f}}if(L=0,T--,e)throw t}}function F(t){if(T>0)return t();ee=++de,T++;try{return t()}finally{Y()}}var p=void 0;function te(t){var e=p;p=void 0;try{return t()}finally{p=e}}var H=void 0,T=0,L=0,de=0,ee=0,Q=void 0,X=0;function se(t){if(p!==void 0){var e=t.n;if(e===void 0||e.t!==p)return e={i:0,S:t,p:p.s,n:void 0,t:p,e:void 0,x:void 0,r:e},p.s!==void 0&&(p.s.n=e),p.s=e,t.n=e,32&p.f&&t.S(e),e;if(e.i===-1)return e.i=0,e.n!==void 0&&(e.n.p=e.p,e.p!==void 0&&(e.p.n=e.n),e.p=p.s,e.n=void 0,p.s.n=e,p.s=e),e}}function j(t,e){this.v=t,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=e==null?void 0:e.watched,this.Z=e==null?void 0:e.unwatched,this.name=e==null?void 0:e.name}j.prototype.brand=fe;j.prototype.h=function(){return!0};j.prototype.S=function(t){var e=this,o=this.t;o!==t&&t.e===void 0&&(t.x=o,this.t=t,o!==void 0?o.e=t:te(function(){var f;(f=e.W)==null||f.call(e)}))};j.prototype.U=function(t){var e=this;if(this.t!==void 0){var o=t.e,f=t.x;o!==void 0&&(o.x=f,t.e=void 0),f!==void 0&&(f.e=o,t.x=void 0),t===this.t&&(this.t=f,f===void 0&&te(function(){var g;(g=e.Z)==null||g.call(e)}))}};j.prototype.subscribe=function(t){var e=this;return ve(function(){var o=e.value,f=p;p=void 0;try{t(o)}finally{p=f}},{name:"sub"})};j.prototype.valueOf=function(){return this.value};j.prototype.toString=function(){return this.value+""};j.prototype.toJSON=function(){return this.value};j.prototype.peek=function(){var t=this;return te(function(){return t.value})};Object.defineProperty(j.prototype,"value",{get:function(){var t=se(this);return t!==void 0&&(t.i=this.i),this.v},set:function(t){if(t!==this.v){if(L>100)throw new Error("Cycle detected");(function(o){T!==0&&L===0&&o.l!==ee&&(o.l=ee,Q={S:o,v:o.v,i:o.i,o:Q})})(this),this.v=t,this.i++,X++,T++;try{for(var e=this.t;e!==void 0;e=e.x)e.t.N()}finally{Y()}}}});function _(t,e){return new j(t,e)}function ae(t){for(var e=t.s;e!==void 0;e=e.n)if(e.S.i!==e.i||!e.S.h()||e.S.i!==e.i)return!0;return!1}function ce(t){for(var e=t.s;e!==void 0;e=e.n){var o=e.S.n;if(o!==void 0&&(e.r=o),e.S.n=e,e.i=-1,e.n===void 0){t.s=e;break}}}function ue(t){for(var e=t.s,o=void 0;e!==void 0;){var f=e.p;e.i===-1?(e.S.U(e),f!==void 0&&(f.n=e.n),e.n!==void 0&&(e.n.p=f)):o=e,e.S.n=e.r,e.r!==void 0&&(e.r=void 0),e=f}t.s=o}function A(t,e){j.call(this,void 0),this.x=t,this.s=void 0,this.g=X-1,this.f=4,this.W=e==null?void 0:e.watched,this.Z=e==null?void 0:e.unwatched,this.name=e==null?void 0:e.name}A.prototype=new j;A.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===X))return!0;if(this.g=X,this.f|=1,this.i>0&&!ae(this))return this.f&=-2,!0;var t=p;try{ce(this),p=this;var e=this.x();(16&this.f||this.v!==e||this.i===0)&&(this.v=e,this.f&=-17,this.i++)}catch(o){this.v=o,this.f|=16,this.i++}return p=t,ue(this),this.f&=-2,!0};A.prototype.S=function(t){if(this.t===void 0){this.f|=36;for(var e=this.s;e!==void 0;e=e.n)e.S.S(e)}j.prototype.S.call(this,t)};A.prototype.U=function(t){if(this.t!==void 0&&(j.prototype.U.call(this,t),this.t===void 0)){this.f&=-33;for(var e=this.s;e!==void 0;e=e.n)e.S.U(e)}};A.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var t=this.t;t!==void 0;t=t.x)t.t.N()}};Object.defineProperty(A.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var t=se(this);if(this.h(),t!==void 0&&(t.i=this.i),16&this.f)throw this.v;return this.v}});function re(t,e){return new A(t,e)}function le(t){var e=t.m;if(t.m=void 0,typeof e=="function"){T++;var o=p;p=void 0;try{e()}catch(f){throw t.f&=-2,t.f|=8,ne(t),f}finally{p=o,Y()}}}function ne(t){for(var e=t.s;e!==void 0;e=e.n)e.S.U(e);t.x=void 0,t.s=void 0,le(t)}function he(t){if(p!==this)throw new Error("Out-of-order effect");ue(this),p=t,this.f&=-2,8&this.f&&ne(this),Y()}function q(t,e){this.x=t,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=e==null?void 0:e.name}q.prototype.c=function(){var t=this.S();try{if(8&this.f||this.x===void 0)return;var e=this.x();typeof e=="function"&&(this.m=e)}finally{t()}};q.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,le(this),ce(this),T++;var t=p;return p=this,he.bind(this,t)};q.prototype.N=function(){2&this.f||(this.f|=2,this.u=H,H=this)};q.prototype.d=function(){this.f|=8,1&this.f||ne(this)};q.prototype.dispose=function(){this.d()};function ve(t,e){var o=new q(t,e);try{o.c()}catch(g){throw o.d(),g}var f=o.d.bind(o);return f[Symbol.dispose]=f,f}function pe(t={}){const e=(t.namespace??"default").trim()||"default",o=t.plugins??[],f=new Map;function g($,N){return function(){var M;const P=`${e}:${$}`,R=f.get($);if(R)return R;const z=N.state(),S=N.modules??{},k={...z};for(const[s,i]of Object.entries(S))k[s]=i.state();const w=_(k),B=new Map,J=new Map,W=new Map,V=new Map,b=new Map,a=new Set,c=new Set(Object.keys(z)),y=new Set(Object.keys(N.getters??{})),n=new Set(Object.keys(N.actions??{})),r=s=>w.value[s]??{},d=(s,i)=>{w.value={...w.value,[s]:i}},x=new Proxy({},{get(s,i){var l,h;if(B.has(i))return(l=B.get(i))==null?void 0:l.value;if(b.has(i))return(h=b.get(i))==null?void 0:h.value;if(c.has(i))return w.value[i];const m=V.get(i);return m?r(m.moduleName)[m.key]:w.value[i]}});for(const[s,i]of Object.entries(N.getters??{}))B.set(s,re(()=>i(w.value,x)));const K=(s,i)=>{var l;for(const h of a)h(s);for(const h of o)(l=h.onMutation)==null||l.call(h,i,s)},C=(s,i,l,h)=>{const m=w.value[s];Object.is(m,i)||(w.value={...w.value,[s]:i},K({namespace:e,scopeId:P,storeId:$,key:s,oldValue:m,newValue:i,origin:l},h))},D=(s,i,l,h,m)=>{const O=r(s),u=O[i];Object.is(u,l)||(d(s,{...O,[i]:l}),K({namespace:e,scopeId:P,storeId:$,key:`${s}.${i}`,oldValue:u,newValue:l,origin:h},m))},I={$id:$,$namespace:e,$scopeId:P,$subscribe(s){return a.add(s),()=>a.delete(s)},$dispose(){var s;a.clear();for(const i of o)(s=i.onDispose)==null||s.call(i,E);f.delete($)},$patch(s,i="local"){F(()=>{for(const[l,h]of Object.entries(s)){const m=V.get(l);if(m){D(m.moduleName,m.key,h,i,E);continue}if(l.includes(".")){const[O,u]=l.split(".",2);if(S[O]){D(O,u,h,i,E);continue}}if(S[l]&&h&&typeof h=="object"&&!Array.isArray(h)){for(const[O,u]of Object.entries(h))D(l,O,u,i,E);continue}C(l,h,i,E)}})},$snapshot(){return{...w.value}}};for(const[s,i]of Object.entries(S)){const l=new Map,h=new Map,m=new Proxy({},{get(u,v){var U,Z,ie;if(l.has(v))return(U=l.get(v))==null?void 0:U.value;if(B.has(v))return(Z=B.get(v))==null?void 0:Z.value;if(b.has(v))return(ie=b.get(v))==null?void 0:ie.value;const oe=r(s);if(v in oe)return oe[v];if(c.has(v))return w.value[v]}});for(const[u,v]of Object.entries(i.getters??{}))l.set(u,re(()=>v(r(s),w.value,m)));let O;for(const[u,v]of Object.entries(i.actions??{}))h.set(u,(...U)=>F(()=>v.apply(O,U)));O=new Proxy({},{get(u,v){var U;if(h.has(v))return h.get(v);if(l.has(v))return(U=l.get(v))==null?void 0:U.value;const Z=r(s);return v in Z?Z[v]:E[v]},set(u,v,U){if(h.has(v)||l.has(v))return!1;const Z=r(s);return v in Z?D(s,v,U,"local",E):E[v]=U,!0}}),W.set(s,O),J.set(s,l);for(const u of Object.keys(r(s)))!(c.has(u)||y.has(u)||n.has(u)||Reflect.has(I,u)||S[u]!==void 0)&&!V.has(u)&&V.set(u,{moduleName:s,key:u});for(const[u,v]of l.entries())!(c.has(u)||y.has(u)||n.has(u)||Reflect.has(I,u)||S[u]!==void 0)&&!b.has(u)&&b.set(u,v);for(const[u,v]of h.entries())!(c.has(u)||y.has(u)||n.has(u)||Reflect.has(I,u)||S[u]!==void 0)&&!Reflect.has(I,u)&&(I[u]=v)}const E=new Proxy(I,{get(s,i,l){var h,m;if(Reflect.has(s,i))return Reflect.get(s,i,l);if(W.has(i))return W.get(i);if(B.has(i))return(h=B.get(i))==null?void 0:h.value;if(b.has(i))return(m=b.get(i))==null?void 0:m.value;if(c.has(i))return w.value[i];const O=V.get(i);return O?r(O.moduleName)[O.key]:w.value[i]},set(s,i,l,h){if(Reflect.has(s,i))return Reflect.set(s,i,l,h);const m=V.get(i);return m?(D(m.moduleName,m.key,l,"local",h),!0):(C(i,l,"local",h),!0)}});for(const[s,i]of Object.entries(N.actions??{}))I[s]=(...l)=>F(()=>i.apply(E,l));for(const s of o)(M=s.onInit)==null||M.call(s,E);return f.set($,E),E}}function G($,N){return function(){var M;const P=`\0machine:${$}`,R=f.get(P);if(R)return R;const z=`${e}:${$}`,S=_(N.initial),k=_((N.context??(()=>({})))()),w=new Set,B=(a,c)=>{var y;for(const n of w)n(a);for(const n of o)(y=n.onMutation)==null||y.call(n,c,a)},J=(a,c,y,n)=>{const r=k.value[a];Object.is(r,c)||(k.value={...k.value,[a]:c},B({namespace:e,scopeId:z,storeId:$,key:a,oldValue:r,newValue:c,origin:y},n))},W=(a,c,y)=>{const n=S.value;Object.is(n,a)||(S.value=a,B({namespace:e,scopeId:z,storeId:$,key:"$state",oldValue:n,newValue:a,origin:c},y))},V={$id:$,$namespace:e,$scopeId:z,$subscribe(a){return w.add(a),()=>w.delete(a)},$dispose(){var a;w.clear();for(const c of o)(a=c.onDispose)==null||a.call(c,b);f.delete(P)},$patch(a,c="local"){F(()=>{for(const[y,n]of Object.entries(a))y==="$state"?W(n,c,b):J(y,n,c,b)})},$snapshot(){return{$state:S.value,...k.value}},send(a,c){F(()=>{var y,n,r;const d=(y=N.actions)==null?void 0:y[a];d&&d.call(b,c);const x=(r=(n=N.states[S.value])==null?void 0:n.on)==null?void 0:r[a];x!==void 0&&W(x,"local",b)})},matches(a){return S.value===a},can(a){const c=N.states[S.value];return!!(c!=null&&c.on&&a in c.on)}},b=new Proxy(V,{get(a,c,y){return c==="state"?S.value:Reflect.has(a,c)?Reflect.get(a,c,y):k.value[c]},set(a,c,y,n){return c==="state"?!1:Reflect.has(a,c)?Reflect.set(a,c,y,n):(J(c,y,"local",n),!0)}});for(const a of o)(M=a.onInit)==null||M.call(a,b);return f.set(P,b),b}}return{defineStore:g,defineMachine:G,use($){o.push($)}}}pe();function ye(t={}){var c,y;const e=t.keyPrefix??"storix",o=new Set(t.include??[]),f=t.storage??"localStorage",g=t.serialize??JSON.stringify,G=t.deserialize??(n=>JSON.parse(n)),$=t.debounce??100,N=((c=t.indexedDB)==null?void 0:c.dbName)??`${e}-persist`,M=((y=t.indexedDB)==null?void 0:y.storeName)??"stores",P=new Map,R=new Map;let z=null;const S=n=>{const r=[n.$id,n.$scopeId];return!(o.size>0&&!r.some(d=>o.has(d)))},k=n=>`${e}:${n.$namespace}:${n.$id}`,w=()=>z||(z=new Promise((n,r)=>{const d=window.indexedDB.open(N,1);d.onupgradeneeded=()=>{const x=d.result;x.objectStoreNames.contains(M)||x.createObjectStore(M)},d.onsuccess=()=>n(d.result),d.onerror=()=>r(d.error??new Error("IndexedDB open failed"))}),z),B=async n=>{const r=await w(),d=k(n);return new Promise((x,K)=>{const D=r.transaction(M,"readonly").objectStore(M).get(d);D.onsuccess=()=>{const I=D.result;if(typeof I!="string"){x(null);return}try{x(G(I))}catch{x(null)}},D.onerror=()=>K(D.error??new Error("IndexedDB read failed"))})},J=async(n,r)=>{const d=await w(),x=k(n),K=g(r);return new Promise((C,D)=>{const I=d.transaction(M,"readwrite");I.objectStore(M).put(K,x),I.oncomplete=()=>C(),I.onerror=()=>D(I.error??new Error("IndexedDB write failed")),I.onabort=()=>D(I.error??new Error("IndexedDB write aborted"))})},W=async n=>{if(typeof window>"u")return null;if(f==="indexedDB"&&"indexedDB"in window)try{return await B(n)}catch{return null}try{const r=window.localStorage.getItem(k(n));return r?G(r):null}catch{return null}},V=n=>{if(typeof window>"u")return;const r=P.get(n.$scopeId);if(r){if(f==="indexedDB"&&"indexedDB"in window){J(n,r).catch(()=>{});return}try{window.localStorage.setItem(k(n),g(r))}catch{}}},b=n=>{const r=n.$scopeId,d=R.get(r);if(d&&(clearTimeout(d),R.delete(r)),$<=0){V(n);return}const x=setTimeout(()=>{R.delete(r),V(n)},$);R.set(r,x)},a=n=>{const r=n.$scopeId,d=R.get(r);d&&(clearTimeout(d),R.delete(r)),V(n)};return{name:"persist",onInit(n){const r=n;typeof window>"u"||S(r)&&(async()=>{const d=await W(r);d&&(P.set(r.$scopeId,d),r.$patch(d,"remote"))})()},onMutation(n,r){const d=n;if(typeof window>"u"||!S(d))return;const x=P.get(d.$scopeId)??{};x[r.key]=r.newValue,P.set(d.$scopeId,x),b(d)},onDispose(n){const r=n;S(r)&&a(r)}}}exports.persistPlugin=ye;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
type PersistStorage = 'localStorage' | 'indexedDB';
|
|
2
|
+
export interface IndexedDBPersistOptions {
|
|
3
|
+
dbName?: string;
|
|
4
|
+
storeName?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface PersistPluginOptions {
|
|
7
|
+
keyPrefix?: string;
|
|
8
|
+
include?: string[];
|
|
9
|
+
storage?: PersistStorage;
|
|
10
|
+
serialize?: (value: Record<string, unknown>) => string;
|
|
11
|
+
deserialize?: (raw: string) => Record<string, unknown>;
|
|
12
|
+
debounce?: number;
|
|
13
|
+
indexedDB?: IndexedDBPersistOptions;
|
|
14
|
+
}
|
|
15
|
+
export declare function persistPlugin(options?: PersistPluginOptions): import("@storix-js/core").StorePlugin;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,KAAK,cAAc,GAAG,cAAc,GAAG,WAAW,CAAC;AAEnD,MAAM,WAAW,uBAAuB;IACtC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,oBAAoB;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAC;IACvD,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,uBAAuB,CAAC;CACrC;AASD,wBAAgB,aAAa,CAAC,OAAO,GAAE,oBAAyB,yCAuL/D"}
|
package/dist/index.js
CHANGED
|
@@ -1,544 +1,620 @@
|
|
|
1
|
-
var
|
|
2
|
-
function
|
|
3
|
-
if (
|
|
4
|
-
|
|
1
|
+
var fe = Symbol.for("preact-signals");
|
|
2
|
+
function Y() {
|
|
3
|
+
if (W > 1)
|
|
4
|
+
W--;
|
|
5
5
|
else {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
var t, e = !1;
|
|
7
|
+
for ((function() {
|
|
8
|
+
var g = Q;
|
|
9
|
+
for (Q = void 0; g !== void 0; )
|
|
10
|
+
g.S.v === g.v && (g.S.i = g.i), g = g.o;
|
|
11
|
+
})(); H !== void 0; ) {
|
|
12
|
+
var i = H;
|
|
13
|
+
for (H = void 0, L++; i !== void 0; ) {
|
|
14
|
+
var f = i.u;
|
|
15
|
+
if (i.u = void 0, i.f &= -3, !(8 & i.f) && ae(i)) try {
|
|
16
|
+
i.c();
|
|
17
|
+
} catch (g) {
|
|
18
|
+
e || (t = g, e = !0);
|
|
14
19
|
}
|
|
15
|
-
|
|
20
|
+
i = f;
|
|
16
21
|
}
|
|
17
22
|
}
|
|
18
|
-
if (
|
|
23
|
+
if (L = 0, W--, e) throw t;
|
|
19
24
|
}
|
|
20
25
|
}
|
|
21
|
-
function
|
|
22
|
-
if (
|
|
23
|
-
|
|
26
|
+
function F(t) {
|
|
27
|
+
if (W > 0) return t();
|
|
28
|
+
ee = ++de, W++;
|
|
24
29
|
try {
|
|
25
|
-
return
|
|
30
|
+
return t();
|
|
26
31
|
} finally {
|
|
27
|
-
|
|
32
|
+
Y();
|
|
28
33
|
}
|
|
29
34
|
}
|
|
30
|
-
var
|
|
31
|
-
function
|
|
32
|
-
var
|
|
33
|
-
|
|
35
|
+
var p = void 0;
|
|
36
|
+
function te(t) {
|
|
37
|
+
var e = p;
|
|
38
|
+
p = void 0;
|
|
34
39
|
try {
|
|
35
|
-
return
|
|
40
|
+
return t();
|
|
36
41
|
} finally {
|
|
37
|
-
|
|
42
|
+
p = e;
|
|
38
43
|
}
|
|
39
44
|
}
|
|
40
|
-
var
|
|
41
|
-
function
|
|
42
|
-
if (
|
|
43
|
-
var
|
|
44
|
-
if (
|
|
45
|
-
return
|
|
46
|
-
if (
|
|
47
|
-
return
|
|
45
|
+
var H = void 0, W = 0, L = 0, de = 0, ee = 0, Q = void 0, X = 0;
|
|
46
|
+
function se(t) {
|
|
47
|
+
if (p !== void 0) {
|
|
48
|
+
var e = t.n;
|
|
49
|
+
if (e === void 0 || e.t !== p)
|
|
50
|
+
return e = { i: 0, S: t, p: p.s, n: void 0, t: p, e: void 0, x: void 0, r: e }, p.s !== void 0 && (p.s.n = e), p.s = e, t.n = e, 32 & p.f && t.S(e), e;
|
|
51
|
+
if (e.i === -1)
|
|
52
|
+
return e.i = 0, e.n !== void 0 && (e.n.p = e.p, e.p !== void 0 && (e.p.n = e.n), e.p = p.s, e.n = void 0, p.s.n = e, p.s = e), e;
|
|
48
53
|
}
|
|
49
54
|
}
|
|
50
|
-
function
|
|
51
|
-
this.v =
|
|
55
|
+
function j(t, e) {
|
|
56
|
+
this.v = t, this.i = 0, this.n = void 0, this.t = void 0, this.l = 0, this.W = e == null ? void 0 : e.watched, this.Z = e == null ? void 0 : e.unwatched, this.name = e == null ? void 0 : e.name;
|
|
52
57
|
}
|
|
53
|
-
|
|
54
|
-
|
|
58
|
+
j.prototype.brand = fe;
|
|
59
|
+
j.prototype.h = function() {
|
|
55
60
|
return !0;
|
|
56
61
|
};
|
|
57
|
-
|
|
58
|
-
var
|
|
59
|
-
|
|
60
|
-
var
|
|
61
|
-
(
|
|
62
|
+
j.prototype.S = function(t) {
|
|
63
|
+
var e = this, i = this.t;
|
|
64
|
+
i !== t && t.e === void 0 && (t.x = i, this.t = t, i !== void 0 ? i.e = t : te(function() {
|
|
65
|
+
var f;
|
|
66
|
+
(f = e.W) == null || f.call(e);
|
|
62
67
|
}));
|
|
63
68
|
};
|
|
64
|
-
|
|
65
|
-
var
|
|
69
|
+
j.prototype.U = function(t) {
|
|
70
|
+
var e = this;
|
|
66
71
|
if (this.t !== void 0) {
|
|
67
|
-
var
|
|
68
|
-
|
|
69
|
-
var
|
|
70
|
-
(
|
|
72
|
+
var i = t.e, f = t.x;
|
|
73
|
+
i !== void 0 && (i.x = f, t.e = void 0), f !== void 0 && (f.e = i, t.x = void 0), t === this.t && (this.t = f, f === void 0 && te(function() {
|
|
74
|
+
var g;
|
|
75
|
+
(g = e.Z) == null || g.call(e);
|
|
71
76
|
}));
|
|
72
77
|
}
|
|
73
78
|
};
|
|
74
|
-
|
|
75
|
-
var
|
|
76
|
-
return
|
|
77
|
-
var
|
|
78
|
-
|
|
79
|
+
j.prototype.subscribe = function(t) {
|
|
80
|
+
var e = this;
|
|
81
|
+
return ve(function() {
|
|
82
|
+
var i = e.value, f = p;
|
|
83
|
+
p = void 0;
|
|
79
84
|
try {
|
|
80
|
-
|
|
85
|
+
t(i);
|
|
81
86
|
} finally {
|
|
82
|
-
|
|
87
|
+
p = f;
|
|
83
88
|
}
|
|
84
89
|
}, { name: "sub" });
|
|
85
90
|
};
|
|
86
|
-
|
|
91
|
+
j.prototype.valueOf = function() {
|
|
87
92
|
return this.value;
|
|
88
93
|
};
|
|
89
|
-
|
|
94
|
+
j.prototype.toString = function() {
|
|
90
95
|
return this.value + "";
|
|
91
96
|
};
|
|
92
|
-
|
|
97
|
+
j.prototype.toJSON = function() {
|
|
93
98
|
return this.value;
|
|
94
99
|
};
|
|
95
|
-
|
|
96
|
-
var
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
} finally {
|
|
101
|
-
l = e;
|
|
102
|
-
}
|
|
100
|
+
j.prototype.peek = function() {
|
|
101
|
+
var t = this;
|
|
102
|
+
return te(function() {
|
|
103
|
+
return t.value;
|
|
104
|
+
});
|
|
103
105
|
};
|
|
104
|
-
Object.defineProperty(
|
|
105
|
-
var
|
|
106
|
-
return
|
|
107
|
-
}, set: function(
|
|
108
|
-
if (
|
|
109
|
-
if (
|
|
110
|
-
|
|
106
|
+
Object.defineProperty(j.prototype, "value", { get: function() {
|
|
107
|
+
var t = se(this);
|
|
108
|
+
return t !== void 0 && (t.i = this.i), this.v;
|
|
109
|
+
}, set: function(t) {
|
|
110
|
+
if (t !== this.v) {
|
|
111
|
+
if (L > 100) throw new Error("Cycle detected");
|
|
112
|
+
(function(i) {
|
|
113
|
+
W !== 0 && L === 0 && i.l !== ee && (i.l = ee, Q = { S: i, v: i.v, i: i.i, o: Q });
|
|
114
|
+
})(this), this.v = t, this.i++, X++, W++;
|
|
111
115
|
try {
|
|
112
|
-
for (var
|
|
116
|
+
for (var e = this.t; e !== void 0; e = e.x) e.t.N();
|
|
113
117
|
} finally {
|
|
114
|
-
|
|
118
|
+
Y();
|
|
115
119
|
}
|
|
116
120
|
}
|
|
117
121
|
} });
|
|
118
|
-
function
|
|
119
|
-
return new
|
|
122
|
+
function _(t, e) {
|
|
123
|
+
return new j(t, e);
|
|
120
124
|
}
|
|
121
|
-
function
|
|
122
|
-
for (var
|
|
125
|
+
function ae(t) {
|
|
126
|
+
for (var e = t.s; e !== void 0; e = e.n) if (e.S.i !== e.i || !e.S.h() || e.S.i !== e.i) return !0;
|
|
123
127
|
return !1;
|
|
124
128
|
}
|
|
125
|
-
function
|
|
126
|
-
for (var
|
|
127
|
-
var
|
|
128
|
-
if (
|
|
129
|
-
|
|
129
|
+
function ce(t) {
|
|
130
|
+
for (var e = t.s; e !== void 0; e = e.n) {
|
|
131
|
+
var i = e.S.n;
|
|
132
|
+
if (i !== void 0 && (e.r = i), e.S.n = e, e.i = -1, e.n === void 0) {
|
|
133
|
+
t.s = e;
|
|
130
134
|
break;
|
|
131
135
|
}
|
|
132
136
|
}
|
|
133
137
|
}
|
|
134
|
-
function
|
|
135
|
-
for (var
|
|
136
|
-
var
|
|
137
|
-
|
|
138
|
+
function ue(t) {
|
|
139
|
+
for (var e = t.s, i = void 0; e !== void 0; ) {
|
|
140
|
+
var f = e.p;
|
|
141
|
+
e.i === -1 ? (e.S.U(e), f !== void 0 && (f.n = e.n), e.n !== void 0 && (e.n.p = f)) : i = e, e.S.n = e.r, e.r !== void 0 && (e.r = void 0), e = f;
|
|
138
142
|
}
|
|
139
|
-
|
|
143
|
+
t.s = i;
|
|
140
144
|
}
|
|
141
|
-
function
|
|
142
|
-
|
|
145
|
+
function J(t, e) {
|
|
146
|
+
j.call(this, void 0), this.x = t, this.s = void 0, this.g = X - 1, this.f = 4, this.W = e == null ? void 0 : e.watched, this.Z = e == null ? void 0 : e.unwatched, this.name = e == null ? void 0 : e.name;
|
|
143
147
|
}
|
|
144
|
-
|
|
145
|
-
|
|
148
|
+
J.prototype = new j();
|
|
149
|
+
J.prototype.h = function() {
|
|
146
150
|
if (this.f &= -3, 1 & this.f) return !1;
|
|
147
|
-
if ((36 & this.f) == 32 || (this.f &= -5, this.g ===
|
|
148
|
-
if (this.g =
|
|
151
|
+
if ((36 & this.f) == 32 || (this.f &= -5, this.g === X)) return !0;
|
|
152
|
+
if (this.g = X, this.f |= 1, this.i > 0 && !ae(this))
|
|
149
153
|
return this.f &= -2, !0;
|
|
150
|
-
var
|
|
154
|
+
var t = p;
|
|
151
155
|
try {
|
|
152
|
-
|
|
153
|
-
var
|
|
154
|
-
(16 & this.f || this.v !==
|
|
155
|
-
} catch (
|
|
156
|
-
this.v =
|
|
156
|
+
ce(this), p = this;
|
|
157
|
+
var e = this.x();
|
|
158
|
+
(16 & this.f || this.v !== e || this.i === 0) && (this.v = e, this.f &= -17, this.i++);
|
|
159
|
+
} catch (i) {
|
|
160
|
+
this.v = i, this.f |= 16, this.i++;
|
|
157
161
|
}
|
|
158
|
-
return
|
|
162
|
+
return p = t, ue(this), this.f &= -2, !0;
|
|
159
163
|
};
|
|
160
|
-
|
|
164
|
+
J.prototype.S = function(t) {
|
|
161
165
|
if (this.t === void 0) {
|
|
162
166
|
this.f |= 36;
|
|
163
|
-
for (var
|
|
167
|
+
for (var e = this.s; e !== void 0; e = e.n) e.S.S(e);
|
|
164
168
|
}
|
|
165
|
-
|
|
169
|
+
j.prototype.S.call(this, t);
|
|
166
170
|
};
|
|
167
|
-
|
|
168
|
-
if (this.t !== void 0 && (
|
|
171
|
+
J.prototype.U = function(t) {
|
|
172
|
+
if (this.t !== void 0 && (j.prototype.U.call(this, t), this.t === void 0)) {
|
|
169
173
|
this.f &= -33;
|
|
170
|
-
for (var
|
|
174
|
+
for (var e = this.s; e !== void 0; e = e.n) e.S.U(e);
|
|
171
175
|
}
|
|
172
176
|
};
|
|
173
|
-
|
|
177
|
+
J.prototype.N = function() {
|
|
174
178
|
if (!(2 & this.f)) {
|
|
175
179
|
this.f |= 6;
|
|
176
|
-
for (var
|
|
180
|
+
for (var t = this.t; t !== void 0; t = t.x) t.t.N();
|
|
177
181
|
}
|
|
178
182
|
};
|
|
179
|
-
Object.defineProperty(
|
|
183
|
+
Object.defineProperty(J.prototype, "value", { get: function() {
|
|
180
184
|
if (1 & this.f) throw new Error("Cycle detected");
|
|
181
|
-
var
|
|
182
|
-
if (this.h(),
|
|
185
|
+
var t = se(this);
|
|
186
|
+
if (this.h(), t !== void 0 && (t.i = this.i), 16 & this.f) throw this.v;
|
|
183
187
|
return this.v;
|
|
184
188
|
} });
|
|
185
|
-
function
|
|
186
|
-
return new
|
|
189
|
+
function re(t, e) {
|
|
190
|
+
return new J(t, e);
|
|
187
191
|
}
|
|
188
|
-
function
|
|
189
|
-
var
|
|
190
|
-
if (
|
|
191
|
-
|
|
192
|
-
var
|
|
193
|
-
|
|
192
|
+
function le(t) {
|
|
193
|
+
var e = t.m;
|
|
194
|
+
if (t.m = void 0, typeof e == "function") {
|
|
195
|
+
W++;
|
|
196
|
+
var i = p;
|
|
197
|
+
p = void 0;
|
|
194
198
|
try {
|
|
195
|
-
|
|
196
|
-
} catch (
|
|
197
|
-
throw
|
|
199
|
+
e();
|
|
200
|
+
} catch (f) {
|
|
201
|
+
throw t.f &= -2, t.f |= 8, ne(t), f;
|
|
198
202
|
} finally {
|
|
199
|
-
|
|
203
|
+
p = i, Y();
|
|
200
204
|
}
|
|
201
205
|
}
|
|
202
206
|
}
|
|
203
|
-
function
|
|
204
|
-
for (var
|
|
205
|
-
|
|
207
|
+
function ne(t) {
|
|
208
|
+
for (var e = t.s; e !== void 0; e = e.n) e.S.U(e);
|
|
209
|
+
t.x = void 0, t.s = void 0, le(t);
|
|
206
210
|
}
|
|
207
|
-
function
|
|
208
|
-
if (
|
|
209
|
-
|
|
211
|
+
function he(t) {
|
|
212
|
+
if (p !== this) throw new Error("Out-of-order effect");
|
|
213
|
+
ue(this), p = t, this.f &= -2, 8 & this.f && ne(this), Y();
|
|
210
214
|
}
|
|
211
|
-
function
|
|
212
|
-
this.x =
|
|
215
|
+
function q(t, e) {
|
|
216
|
+
this.x = t, this.m = void 0, this.s = void 0, this.u = void 0, this.f = 32, this.name = e == null ? void 0 : e.name;
|
|
213
217
|
}
|
|
214
|
-
|
|
215
|
-
var
|
|
218
|
+
q.prototype.c = function() {
|
|
219
|
+
var t = this.S();
|
|
216
220
|
try {
|
|
217
221
|
if (8 & this.f || this.x === void 0) return;
|
|
218
|
-
var
|
|
219
|
-
typeof
|
|
222
|
+
var e = this.x();
|
|
223
|
+
typeof e == "function" && (this.m = e);
|
|
220
224
|
} finally {
|
|
221
|
-
|
|
225
|
+
t();
|
|
222
226
|
}
|
|
223
227
|
};
|
|
224
|
-
|
|
228
|
+
q.prototype.S = function() {
|
|
225
229
|
if (1 & this.f) throw new Error("Cycle detected");
|
|
226
|
-
this.f |= 1, this.f &= -9,
|
|
227
|
-
var
|
|
228
|
-
return
|
|
230
|
+
this.f |= 1, this.f &= -9, le(this), ce(this), W++;
|
|
231
|
+
var t = p;
|
|
232
|
+
return p = this, he.bind(this, t);
|
|
229
233
|
};
|
|
230
|
-
|
|
231
|
-
2 & this.f || (this.f |= 2, this.
|
|
234
|
+
q.prototype.N = function() {
|
|
235
|
+
2 & this.f || (this.f |= 2, this.u = H, H = this);
|
|
232
236
|
};
|
|
233
|
-
|
|
234
|
-
this.f |= 8, 1 & this.f ||
|
|
237
|
+
q.prototype.d = function() {
|
|
238
|
+
this.f |= 8, 1 & this.f || ne(this);
|
|
235
239
|
};
|
|
236
|
-
|
|
240
|
+
q.prototype.dispose = function() {
|
|
237
241
|
this.d();
|
|
238
242
|
};
|
|
239
|
-
function
|
|
240
|
-
var
|
|
243
|
+
function ve(t, e) {
|
|
244
|
+
var i = new q(t, e);
|
|
241
245
|
try {
|
|
242
|
-
|
|
243
|
-
} catch (
|
|
244
|
-
throw
|
|
246
|
+
i.c();
|
|
247
|
+
} catch (g) {
|
|
248
|
+
throw i.d(), g;
|
|
245
249
|
}
|
|
246
|
-
var
|
|
247
|
-
return
|
|
250
|
+
var f = i.d.bind(i);
|
|
251
|
+
return f[Symbol.dispose] = f, f;
|
|
248
252
|
}
|
|
249
|
-
function
|
|
250
|
-
const
|
|
251
|
-
function
|
|
253
|
+
function pe(t = {}) {
|
|
254
|
+
const e = (t.namespace ?? "default").trim() || "default", i = t.plugins ?? [], f = /* @__PURE__ */ new Map();
|
|
255
|
+
function g(x, N) {
|
|
252
256
|
return function() {
|
|
253
|
-
var
|
|
254
|
-
const
|
|
257
|
+
var M;
|
|
258
|
+
const P = `${e}:${x}`, R = f.get(x);
|
|
255
259
|
if (R) return R;
|
|
256
|
-
const
|
|
257
|
-
for (const [
|
|
258
|
-
|
|
259
|
-
const
|
|
260
|
-
|
|
261
|
-
...
|
|
262
|
-
[
|
|
260
|
+
const z = N.state(), S = N.modules ?? {}, k = { ...z };
|
|
261
|
+
for (const [s, o] of Object.entries(S))
|
|
262
|
+
k[s] = o.state();
|
|
263
|
+
const w = _(k), B = /* @__PURE__ */ new Map(), K = /* @__PURE__ */ new Map(), Z = /* @__PURE__ */ new Map(), V = /* @__PURE__ */ new Map(), b = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Set(), c = new Set(Object.keys(z)), y = new Set(Object.keys(N.getters ?? {})), n = new Set(Object.keys(N.actions ?? {})), r = (s) => w.value[s] ?? {}, d = (s, o) => {
|
|
264
|
+
w.value = {
|
|
265
|
+
...w.value,
|
|
266
|
+
[s]: o
|
|
263
267
|
};
|
|
264
|
-
},
|
|
268
|
+
}, $ = new Proxy(
|
|
265
269
|
{},
|
|
266
270
|
{
|
|
267
|
-
get(
|
|
268
|
-
var
|
|
269
|
-
if (
|
|
270
|
-
if (
|
|
271
|
-
if (
|
|
272
|
-
const
|
|
273
|
-
return
|
|
271
|
+
get(s, o) {
|
|
272
|
+
var l, h;
|
|
273
|
+
if (B.has(o)) return (l = B.get(o)) == null ? void 0 : l.value;
|
|
274
|
+
if (b.has(o)) return (h = b.get(o)) == null ? void 0 : h.value;
|
|
275
|
+
if (c.has(o)) return w.value[o];
|
|
276
|
+
const m = V.get(o);
|
|
277
|
+
return m ? r(m.moduleName)[m.key] : w.value[o];
|
|
274
278
|
}
|
|
275
279
|
}
|
|
276
280
|
);
|
|
277
|
-
for (const [
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
+
for (const [s, o] of Object.entries(N.getters ?? {}))
|
|
282
|
+
B.set(
|
|
283
|
+
s,
|
|
284
|
+
re(() => o(w.value, $))
|
|
281
285
|
);
|
|
282
|
-
const
|
|
283
|
-
var
|
|
284
|
-
for (const
|
|
285
|
-
for (const
|
|
286
|
-
(
|
|
287
|
-
},
|
|
288
|
-
const
|
|
289
|
-
Object.is(
|
|
290
|
-
...
|
|
291
|
-
[
|
|
292
|
-
},
|
|
286
|
+
const T = (s, o) => {
|
|
287
|
+
var l;
|
|
288
|
+
for (const h of a) h(s);
|
|
289
|
+
for (const h of i)
|
|
290
|
+
(l = h.onMutation) == null || l.call(h, o, s);
|
|
291
|
+
}, C = (s, o, l, h) => {
|
|
292
|
+
const m = w.value[s];
|
|
293
|
+
Object.is(m, o) || (w.value = {
|
|
294
|
+
...w.value,
|
|
295
|
+
[s]: o
|
|
296
|
+
}, T(
|
|
293
297
|
{
|
|
294
|
-
namespace:
|
|
295
|
-
scopeId:
|
|
298
|
+
namespace: e,
|
|
299
|
+
scopeId: P,
|
|
296
300
|
storeId: x,
|
|
297
|
-
key:
|
|
298
|
-
oldValue:
|
|
299
|
-
newValue:
|
|
300
|
-
origin:
|
|
301
|
+
key: s,
|
|
302
|
+
oldValue: m,
|
|
303
|
+
newValue: o,
|
|
304
|
+
origin: l
|
|
301
305
|
},
|
|
302
|
-
|
|
306
|
+
h
|
|
303
307
|
));
|
|
304
|
-
},
|
|
305
|
-
const
|
|
306
|
-
Object.is(
|
|
307
|
-
...
|
|
308
|
-
[
|
|
309
|
-
}),
|
|
308
|
+
}, D = (s, o, l, h, m) => {
|
|
309
|
+
const O = r(s), u = O[o];
|
|
310
|
+
Object.is(u, l) || (d(s, {
|
|
311
|
+
...O,
|
|
312
|
+
[o]: l
|
|
313
|
+
}), T(
|
|
310
314
|
{
|
|
311
|
-
namespace:
|
|
312
|
-
scopeId:
|
|
315
|
+
namespace: e,
|
|
316
|
+
scopeId: P,
|
|
313
317
|
storeId: x,
|
|
314
|
-
key: `${
|
|
315
|
-
oldValue:
|
|
316
|
-
newValue:
|
|
317
|
-
origin:
|
|
318
|
+
key: `${s}.${o}`,
|
|
319
|
+
oldValue: u,
|
|
320
|
+
newValue: l,
|
|
321
|
+
origin: h
|
|
318
322
|
},
|
|
319
|
-
|
|
323
|
+
m
|
|
320
324
|
));
|
|
321
|
-
},
|
|
325
|
+
}, I = {
|
|
322
326
|
$id: x,
|
|
323
|
-
$namespace:
|
|
324
|
-
$scopeId:
|
|
325
|
-
$subscribe(
|
|
326
|
-
return
|
|
327
|
+
$namespace: e,
|
|
328
|
+
$scopeId: P,
|
|
329
|
+
$subscribe(s) {
|
|
330
|
+
return a.add(s), () => a.delete(s);
|
|
327
331
|
},
|
|
328
332
|
$dispose() {
|
|
329
|
-
var
|
|
330
|
-
|
|
331
|
-
for (const
|
|
332
|
-
(
|
|
333
|
-
|
|
333
|
+
var s;
|
|
334
|
+
a.clear();
|
|
335
|
+
for (const o of i)
|
|
336
|
+
(s = o.onDispose) == null || s.call(o, E);
|
|
337
|
+
f.delete(x);
|
|
334
338
|
},
|
|
335
|
-
$patch(
|
|
336
|
-
|
|
337
|
-
for (const [
|
|
338
|
-
const
|
|
339
|
-
if (
|
|
340
|
-
|
|
339
|
+
$patch(s, o = "local") {
|
|
340
|
+
F(() => {
|
|
341
|
+
for (const [l, h] of Object.entries(s)) {
|
|
342
|
+
const m = V.get(l);
|
|
343
|
+
if (m) {
|
|
344
|
+
D(m.moduleName, m.key, h, o, E);
|
|
341
345
|
continue;
|
|
342
346
|
}
|
|
343
|
-
if (
|
|
344
|
-
const [
|
|
345
|
-
if (S[
|
|
346
|
-
|
|
347
|
+
if (l.includes(".")) {
|
|
348
|
+
const [O, u] = l.split(".", 2);
|
|
349
|
+
if (S[O]) {
|
|
350
|
+
D(O, u, h, o, E);
|
|
347
351
|
continue;
|
|
348
352
|
}
|
|
349
353
|
}
|
|
350
|
-
if (S[
|
|
351
|
-
for (const [
|
|
352
|
-
|
|
354
|
+
if (S[l] && h && typeof h == "object" && !Array.isArray(h)) {
|
|
355
|
+
for (const [O, u] of Object.entries(h))
|
|
356
|
+
D(l, O, u, o, E);
|
|
353
357
|
continue;
|
|
354
358
|
}
|
|
355
|
-
|
|
359
|
+
C(l, h, o, E);
|
|
356
360
|
}
|
|
357
361
|
});
|
|
358
362
|
},
|
|
359
363
|
$snapshot() {
|
|
360
|
-
return { ...
|
|
364
|
+
return { ...w.value };
|
|
361
365
|
}
|
|
362
366
|
};
|
|
363
|
-
for (const [
|
|
364
|
-
const
|
|
367
|
+
for (const [s, o] of Object.entries(S)) {
|
|
368
|
+
const l = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map(), m = new Proxy(
|
|
365
369
|
{},
|
|
366
370
|
{
|
|
367
|
-
get(
|
|
368
|
-
var
|
|
369
|
-
if (
|
|
370
|
-
if (
|
|
371
|
-
if (
|
|
372
|
-
const
|
|
373
|
-
if (
|
|
374
|
-
if (
|
|
371
|
+
get(u, v) {
|
|
372
|
+
var U, A, oe;
|
|
373
|
+
if (l.has(v)) return (U = l.get(v)) == null ? void 0 : U.value;
|
|
374
|
+
if (B.has(v)) return (A = B.get(v)) == null ? void 0 : A.value;
|
|
375
|
+
if (b.has(v)) return (oe = b.get(v)) == null ? void 0 : oe.value;
|
|
376
|
+
const ie = r(s);
|
|
377
|
+
if (v in ie) return ie[v];
|
|
378
|
+
if (c.has(v)) return w.value[v];
|
|
375
379
|
}
|
|
376
380
|
}
|
|
377
381
|
);
|
|
378
|
-
for (const [
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
+
for (const [u, v] of Object.entries(o.getters ?? {}))
|
|
383
|
+
l.set(
|
|
384
|
+
u,
|
|
385
|
+
re(() => v(r(s), w.value, m))
|
|
382
386
|
);
|
|
383
|
-
let
|
|
384
|
-
for (const [
|
|
385
|
-
|
|
386
|
-
|
|
387
|
+
let O;
|
|
388
|
+
for (const [u, v] of Object.entries(o.actions ?? {}))
|
|
389
|
+
h.set(u, (...U) => F(() => v.apply(O, U)));
|
|
390
|
+
O = new Proxy(
|
|
387
391
|
{},
|
|
388
392
|
{
|
|
389
|
-
get(
|
|
390
|
-
var
|
|
391
|
-
if (
|
|
392
|
-
if (
|
|
393
|
-
const
|
|
394
|
-
return
|
|
393
|
+
get(u, v) {
|
|
394
|
+
var U;
|
|
395
|
+
if (h.has(v)) return h.get(v);
|
|
396
|
+
if (l.has(v)) return (U = l.get(v)) == null ? void 0 : U.value;
|
|
397
|
+
const A = r(s);
|
|
398
|
+
return v in A ? A[v] : E[v];
|
|
395
399
|
},
|
|
396
|
-
set(
|
|
397
|
-
if (
|
|
398
|
-
const
|
|
399
|
-
return
|
|
400
|
+
set(u, v, U) {
|
|
401
|
+
if (h.has(v) || l.has(v)) return !1;
|
|
402
|
+
const A = r(s);
|
|
403
|
+
return v in A ? D(s, v, U, "local", E) : E[v] = U, !0;
|
|
400
404
|
}
|
|
401
405
|
}
|
|
402
|
-
),
|
|
403
|
-
for (const
|
|
404
|
-
!(
|
|
405
|
-
for (const [
|
|
406
|
-
!(
|
|
407
|
-
for (const [
|
|
408
|
-
!(
|
|
406
|
+
), Z.set(s, O), K.set(s, l);
|
|
407
|
+
for (const u of Object.keys(r(s)))
|
|
408
|
+
!(c.has(u) || y.has(u) || n.has(u) || Reflect.has(I, u) || S[u] !== void 0) && !V.has(u) && V.set(u, { moduleName: s, key: u });
|
|
409
|
+
for (const [u, v] of l.entries())
|
|
410
|
+
!(c.has(u) || y.has(u) || n.has(u) || Reflect.has(I, u) || S[u] !== void 0) && !b.has(u) && b.set(u, v);
|
|
411
|
+
for (const [u, v] of h.entries())
|
|
412
|
+
!(c.has(u) || y.has(u) || n.has(u) || Reflect.has(I, u) || S[u] !== void 0) && !Reflect.has(I, u) && (I[u] = v);
|
|
409
413
|
}
|
|
410
|
-
const
|
|
411
|
-
get(
|
|
412
|
-
var
|
|
413
|
-
if (Reflect.has(
|
|
414
|
-
if (
|
|
415
|
-
if (
|
|
416
|
-
if (
|
|
417
|
-
if (
|
|
418
|
-
const
|
|
419
|
-
return
|
|
414
|
+
const E = new Proxy(I, {
|
|
415
|
+
get(s, o, l) {
|
|
416
|
+
var h, m;
|
|
417
|
+
if (Reflect.has(s, o)) return Reflect.get(s, o, l);
|
|
418
|
+
if (Z.has(o)) return Z.get(o);
|
|
419
|
+
if (B.has(o)) return (h = B.get(o)) == null ? void 0 : h.value;
|
|
420
|
+
if (b.has(o)) return (m = b.get(o)) == null ? void 0 : m.value;
|
|
421
|
+
if (c.has(o)) return w.value[o];
|
|
422
|
+
const O = V.get(o);
|
|
423
|
+
return O ? r(O.moduleName)[O.key] : w.value[o];
|
|
424
|
+
},
|
|
425
|
+
set(s, o, l, h) {
|
|
426
|
+
if (Reflect.has(s, o))
|
|
427
|
+
return Reflect.set(s, o, l, h);
|
|
428
|
+
const m = V.get(o);
|
|
429
|
+
return m ? (D(m.moduleName, m.key, l, "local", h), !0) : (C(o, l, "local", h), !0);
|
|
430
|
+
}
|
|
431
|
+
});
|
|
432
|
+
for (const [s, o] of Object.entries(N.actions ?? {}))
|
|
433
|
+
I[s] = (...l) => F(() => o.apply(E, l));
|
|
434
|
+
for (const s of i)
|
|
435
|
+
(M = s.onInit) == null || M.call(s, E);
|
|
436
|
+
return f.set(x, E), E;
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
function G(x, N) {
|
|
440
|
+
return function() {
|
|
441
|
+
var M;
|
|
442
|
+
const P = `\0machine:${x}`, R = f.get(P);
|
|
443
|
+
if (R) return R;
|
|
444
|
+
const z = `${e}:${x}`, S = _(N.initial), k = _((N.context ?? (() => ({})))()), w = /* @__PURE__ */ new Set(), B = (a, c) => {
|
|
445
|
+
var y;
|
|
446
|
+
for (const n of w) n(a);
|
|
447
|
+
for (const n of i)
|
|
448
|
+
(y = n.onMutation) == null || y.call(n, c, a);
|
|
449
|
+
}, K = (a, c, y, n) => {
|
|
450
|
+
const r = k.value[a];
|
|
451
|
+
Object.is(r, c) || (k.value = { ...k.value, [a]: c }, B({ namespace: e, scopeId: z, storeId: x, key: a, oldValue: r, newValue: c, origin: y }, n));
|
|
452
|
+
}, Z = (a, c, y) => {
|
|
453
|
+
const n = S.value;
|
|
454
|
+
Object.is(n, a) || (S.value = a, B(
|
|
455
|
+
{ namespace: e, scopeId: z, storeId: x, key: "$state", oldValue: n, newValue: a, origin: c },
|
|
456
|
+
y
|
|
457
|
+
));
|
|
458
|
+
}, V = {
|
|
459
|
+
$id: x,
|
|
460
|
+
$namespace: e,
|
|
461
|
+
$scopeId: z,
|
|
462
|
+
$subscribe(a) {
|
|
463
|
+
return w.add(a), () => w.delete(a);
|
|
464
|
+
},
|
|
465
|
+
$dispose() {
|
|
466
|
+
var a;
|
|
467
|
+
w.clear();
|
|
468
|
+
for (const c of i)
|
|
469
|
+
(a = c.onDispose) == null || a.call(c, b);
|
|
470
|
+
f.delete(P);
|
|
471
|
+
},
|
|
472
|
+
$patch(a, c = "local") {
|
|
473
|
+
F(() => {
|
|
474
|
+
for (const [y, n] of Object.entries(a))
|
|
475
|
+
y === "$state" ? Z(n, c, b) : K(y, n, c, b);
|
|
476
|
+
});
|
|
477
|
+
},
|
|
478
|
+
$snapshot() {
|
|
479
|
+
return { $state: S.value, ...k.value };
|
|
480
|
+
},
|
|
481
|
+
send(a, c) {
|
|
482
|
+
F(() => {
|
|
483
|
+
var y, n, r;
|
|
484
|
+
const d = (y = N.actions) == null ? void 0 : y[a];
|
|
485
|
+
d && d.call(b, c);
|
|
486
|
+
const $ = (r = (n = N.states[S.value]) == null ? void 0 : n.on) == null ? void 0 : r[a];
|
|
487
|
+
$ !== void 0 && Z($, "local", b);
|
|
488
|
+
});
|
|
489
|
+
},
|
|
490
|
+
matches(a) {
|
|
491
|
+
return S.value === a;
|
|
492
|
+
},
|
|
493
|
+
can(a) {
|
|
494
|
+
const c = N.states[S.value];
|
|
495
|
+
return !!(c != null && c.on && a in c.on);
|
|
496
|
+
}
|
|
497
|
+
}, b = new Proxy(V, {
|
|
498
|
+
get(a, c, y) {
|
|
499
|
+
return c === "state" ? S.value : Reflect.has(a, c) ? Reflect.get(a, c, y) : k.value[c];
|
|
420
500
|
},
|
|
421
|
-
set(
|
|
422
|
-
|
|
423
|
-
return Reflect.set(i, n, c, f);
|
|
424
|
-
const p = P.get(n);
|
|
425
|
-
return p ? (B(p.moduleName, p.key, c, "local", f), !0) : (J(n, c, "local", f), !0);
|
|
501
|
+
set(a, c, y, n) {
|
|
502
|
+
return c === "state" ? !1 : Reflect.has(a, c) ? Reflect.set(a, c, y, n) : (K(c, y, "local", n), !0);
|
|
426
503
|
}
|
|
427
504
|
});
|
|
428
|
-
for (const
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
(Z = i.onInit) == null || Z.call(i, v);
|
|
432
|
-
return d.set(x, v), v;
|
|
505
|
+
for (const a of i)
|
|
506
|
+
(M = a.onInit) == null || M.call(a, b);
|
|
507
|
+
return f.set(P, b), b;
|
|
433
508
|
};
|
|
434
509
|
}
|
|
435
510
|
return {
|
|
436
|
-
defineStore:
|
|
511
|
+
defineStore: g,
|
|
512
|
+
defineMachine: G,
|
|
437
513
|
use(x) {
|
|
438
|
-
|
|
514
|
+
i.push(x);
|
|
439
515
|
}
|
|
440
516
|
};
|
|
441
517
|
}
|
|
442
|
-
|
|
443
|
-
function
|
|
444
|
-
var
|
|
445
|
-
const
|
|
446
|
-
let
|
|
447
|
-
const
|
|
448
|
-
const
|
|
449
|
-
return !(
|
|
450
|
-
},
|
|
451
|
-
const
|
|
452
|
-
|
|
453
|
-
const
|
|
454
|
-
|
|
455
|
-
},
|
|
456
|
-
}),
|
|
457
|
-
const
|
|
458
|
-
return new Promise((
|
|
459
|
-
const
|
|
460
|
-
|
|
461
|
-
const
|
|
462
|
-
if (typeof
|
|
463
|
-
|
|
518
|
+
pe();
|
|
519
|
+
function ye(t = {}) {
|
|
520
|
+
var c, y;
|
|
521
|
+
const e = t.keyPrefix ?? "storix", i = new Set(t.include ?? []), f = t.storage ?? "localStorage", g = t.serialize ?? JSON.stringify, G = t.deserialize ?? ((n) => JSON.parse(n)), x = t.debounce ?? 100, N = ((c = t.indexedDB) == null ? void 0 : c.dbName) ?? `${e}-persist`, M = ((y = t.indexedDB) == null ? void 0 : y.storeName) ?? "stores", P = /* @__PURE__ */ new Map(), R = /* @__PURE__ */ new Map();
|
|
522
|
+
let z = null;
|
|
523
|
+
const S = (n) => {
|
|
524
|
+
const r = [n.$id, n.$scopeId];
|
|
525
|
+
return !(i.size > 0 && !r.some((d) => i.has(d)));
|
|
526
|
+
}, k = (n) => `${e}:${n.$namespace}:${n.$id}`, w = () => z || (z = new Promise((n, r) => {
|
|
527
|
+
const d = window.indexedDB.open(N, 1);
|
|
528
|
+
d.onupgradeneeded = () => {
|
|
529
|
+
const $ = d.result;
|
|
530
|
+
$.objectStoreNames.contains(M) || $.createObjectStore(M);
|
|
531
|
+
}, d.onsuccess = () => n(d.result), d.onerror = () => r(d.error ?? new Error("IndexedDB open failed"));
|
|
532
|
+
}), z), B = async (n) => {
|
|
533
|
+
const r = await w(), d = k(n);
|
|
534
|
+
return new Promise(($, T) => {
|
|
535
|
+
const D = r.transaction(M, "readonly").objectStore(M).get(d);
|
|
536
|
+
D.onsuccess = () => {
|
|
537
|
+
const I = D.result;
|
|
538
|
+
if (typeof I != "string") {
|
|
539
|
+
$(null);
|
|
464
540
|
return;
|
|
465
541
|
}
|
|
466
542
|
try {
|
|
467
|
-
|
|
543
|
+
$(G(I));
|
|
468
544
|
} catch {
|
|
469
|
-
|
|
545
|
+
$(null);
|
|
470
546
|
}
|
|
471
|
-
},
|
|
547
|
+
}, D.onerror = () => T(D.error ?? new Error("IndexedDB read failed"));
|
|
472
548
|
});
|
|
473
|
-
},
|
|
474
|
-
const
|
|
475
|
-
return new Promise((
|
|
476
|
-
const
|
|
477
|
-
|
|
549
|
+
}, K = async (n, r) => {
|
|
550
|
+
const d = await w(), $ = k(n), T = g(r);
|
|
551
|
+
return new Promise((C, D) => {
|
|
552
|
+
const I = d.transaction(M, "readwrite");
|
|
553
|
+
I.objectStore(M).put(T, $), I.oncomplete = () => C(), I.onerror = () => D(I.error ?? new Error("IndexedDB write failed")), I.onabort = () => D(I.error ?? new Error("IndexedDB write aborted"));
|
|
478
554
|
});
|
|
479
|
-
},
|
|
555
|
+
}, Z = async (n) => {
|
|
480
556
|
if (typeof window > "u") return null;
|
|
481
|
-
if (
|
|
557
|
+
if (f === "indexedDB" && "indexedDB" in window)
|
|
482
558
|
try {
|
|
483
|
-
return await
|
|
559
|
+
return await B(n);
|
|
484
560
|
} catch {
|
|
485
561
|
return null;
|
|
486
562
|
}
|
|
487
563
|
try {
|
|
488
|
-
const
|
|
489
|
-
return
|
|
564
|
+
const r = window.localStorage.getItem(k(n));
|
|
565
|
+
return r ? G(r) : null;
|
|
490
566
|
} catch {
|
|
491
567
|
return null;
|
|
492
568
|
}
|
|
493
|
-
},
|
|
569
|
+
}, V = (n) => {
|
|
494
570
|
if (typeof window > "u") return;
|
|
495
|
-
const
|
|
496
|
-
if (
|
|
497
|
-
if (
|
|
498
|
-
|
|
571
|
+
const r = P.get(n.$scopeId);
|
|
572
|
+
if (r) {
|
|
573
|
+
if (f === "indexedDB" && "indexedDB" in window) {
|
|
574
|
+
K(n, r).catch(() => {
|
|
499
575
|
});
|
|
500
576
|
return;
|
|
501
577
|
}
|
|
502
578
|
try {
|
|
503
|
-
window.localStorage.setItem(
|
|
579
|
+
window.localStorage.setItem(k(n), g(r));
|
|
504
580
|
} catch {
|
|
505
581
|
}
|
|
506
582
|
}
|
|
507
|
-
},
|
|
508
|
-
const
|
|
509
|
-
if (
|
|
510
|
-
|
|
583
|
+
}, b = (n) => {
|
|
584
|
+
const r = n.$scopeId, d = R.get(r);
|
|
585
|
+
if (d && (clearTimeout(d), R.delete(r)), x <= 0) {
|
|
586
|
+
V(n);
|
|
511
587
|
return;
|
|
512
588
|
}
|
|
513
|
-
const
|
|
514
|
-
|
|
515
|
-
},
|
|
516
|
-
|
|
517
|
-
},
|
|
518
|
-
const
|
|
519
|
-
|
|
589
|
+
const $ = setTimeout(() => {
|
|
590
|
+
R.delete(r), V(n);
|
|
591
|
+
}, x);
|
|
592
|
+
R.set(r, $);
|
|
593
|
+
}, a = (n) => {
|
|
594
|
+
const r = n.$scopeId, d = R.get(r);
|
|
595
|
+
d && (clearTimeout(d), R.delete(r)), V(n);
|
|
520
596
|
};
|
|
521
597
|
return {
|
|
522
598
|
name: "persist",
|
|
523
|
-
onInit(
|
|
524
|
-
const
|
|
525
|
-
typeof window > "u" ||
|
|
526
|
-
const
|
|
527
|
-
|
|
599
|
+
onInit(n) {
|
|
600
|
+
const r = n;
|
|
601
|
+
typeof window > "u" || S(r) && (async () => {
|
|
602
|
+
const d = await Z(r);
|
|
603
|
+
d && (P.set(r.$scopeId, d), r.$patch(d, "remote"));
|
|
528
604
|
})();
|
|
529
605
|
},
|
|
530
|
-
onMutation(
|
|
531
|
-
const
|
|
532
|
-
if (typeof window > "u" || !
|
|
533
|
-
const
|
|
534
|
-
|
|
606
|
+
onMutation(n, r) {
|
|
607
|
+
const d = n;
|
|
608
|
+
if (typeof window > "u" || !S(d)) return;
|
|
609
|
+
const $ = P.get(d.$scopeId) ?? {};
|
|
610
|
+
$[r.key] = r.newValue, P.set(d.$scopeId, $), b(d);
|
|
535
611
|
},
|
|
536
|
-
onDispose(
|
|
537
|
-
const
|
|
538
|
-
|
|
612
|
+
onDispose(n) {
|
|
613
|
+
const r = n;
|
|
614
|
+
S(r) && a(r);
|
|
539
615
|
}
|
|
540
616
|
};
|
|
541
617
|
}
|
|
542
618
|
export {
|
|
543
|
-
|
|
619
|
+
ye as persistPlugin
|
|
544
620
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storix-js/persist",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"scripts": {
|
|
23
23
|
"build": "vite build && tsc -p tsconfig.build.json --emitDeclarationOnly",
|
|
24
24
|
"dev": "vite build --watch",
|
|
25
|
-
"test": "vitest run",
|
|
25
|
+
"test": "vitest run --passWithNoTests",
|
|
26
26
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@storix-js/core": "
|
|
29
|
+
"@storix-js/core": "workspace:*"
|
|
30
30
|
}
|
|
31
31
|
}
|