@storix-js/vuex 0.2.0 → 0.3.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/README.md CHANGED
@@ -44,3 +44,5 @@ const bridge = createVuexBridge({
44
44
  This keeps simple integrations patch-based while allowing special keys to flow through Vuex business logic.
45
45
 
46
46
  Use `applyVuexPatchMutation()` inside your Vuex mutation to apply the incoming patch payload.
47
+
48
+ For Vue 2 rendering, combine this bridge with `@storix-js/vue2`; the rendering adapter and Vuex bridge have separate lifecycles and should each be disposed at their ownership boundary.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var we=Symbol.for("preact-signals");function X(){if(B>1)B--;else{var e,t=!1;for((function(){var h=G;for(G=void 0;h!==void 0;)h.S.v===h.v&&(h.S.i=h.i),h=h.o})();_!==void 0;){var r=_;for(_=void 0,Y++;r!==void 0;){var a=r.u;if(r.u=void 0,r.f&=-3,!(8&r.f)&&ve(r))try{r.c()}catch(h){t||(e=h,t=!0)}r=a}}if(Y=0,B--,t)throw e}}function K(e){if(B>0)return e();te=++me,B++;try{return e()}finally{X()}}var p=void 0;function ne(e){var t=p;p=void 0;try{return e()}finally{p=t}}var _=void 0,B=0,Y=0,me=0,te=0,G=void 0,Q=0;function he(e){if(p!==void 0){var t=e.n;if(t===void 0||t.t!==p)return t={i:0,S:e,p:p.s,n:void 0,t:p,e:void 0,x:void 0,r:t},p.s!==void 0&&(p.s.n=t),p.s=t,e.n=t,32&p.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=p.s,t.n=void 0,p.s.n=t,p.s=t),t}}function k(e,t){this.v=e,this.i=0,this.n=void 0,this.t=void 0,this.l=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}k.prototype.brand=we;k.prototype.h=function(){return!0};k.prototype.S=function(e){var t=this,r=this.t;r!==e&&e.e===void 0&&(e.x=r,this.t=e,r!==void 0?r.e=e:ne(function(){var a;(a=t.W)==null||a.call(t)}))};k.prototype.U=function(e){var t=this;if(this.t!==void 0){var r=e.e,a=e.x;r!==void 0&&(r.x=a,e.e=void 0),a!==void 0&&(a.e=r,e.x=void 0),e===this.t&&(this.t=a,a===void 0&&ne(function(){var h;(h=t.Z)==null||h.call(t)}))}};k.prototype.subscribe=function(e){var t=this;return Se(function(){var r=t.value,a=p;p=void 0;try{e(r)}finally{p=a}},{name:"sub"})};k.prototype.valueOf=function(){return this.value};k.prototype.toString=function(){return this.value+""};k.prototype.toJSON=function(){return this.value};k.prototype.peek=function(){var e=this;return ne(function(){return e.value})};Object.defineProperty(k.prototype,"value",{get:function(){var e=he(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(Y>100)throw new Error("Cycle detected");(function(r){B!==0&&Y===0&&r.l!==te&&(r.l=te,G={S:r,v:r.v,i:r.i,o:G})})(this),this.v=e,this.i++,Q++,B++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{X()}}}});function ee(e,t){return new k(e,t)}function ve(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 de(e){for(var t=e.s;t!==void 0;t=t.n){var r=t.S.n;if(r!==void 0&&(t.r=r),t.S.n=t,t.i=-1,t.n===void 0){e.s=t;break}}}function pe(e){for(var t=e.s,r=void 0;t!==void 0;){var a=t.p;t.i===-1?(t.S.U(t),a!==void 0&&(a.n=t.n),t.n!==void 0&&(t.n.p=a)):r=t,t.S.n=t.r,t.r!==void 0&&(t.r=void 0),t=a}e.s=r}function W(e,t){k.call(this,void 0),this.x=e,this.s=void 0,this.g=Q-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}W.prototype=new k;W.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===Q))return!0;if(this.g=Q,this.f|=1,this.i>0&&!ve(this))return this.f&=-2,!0;var e=p;try{de(this),p=this;var t=this.x();(16&this.f||this.v!==t||this.i===0)&&(this.v=t,this.f&=-17,this.i++)}catch(r){this.v=r,this.f|=16,this.i++}return p=e,pe(this),this.f&=-2,!0};W.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)}k.prototype.S.call(this,e)};W.prototype.U=function(e){if(this.t!==void 0&&(k.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)}};W.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(W.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=he(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function ae(e,t){return new W(e,t)}function ye(e){var t=e.m;if(e.m=void 0,typeof t=="function"){B++;var r=p;p=void 0;try{t()}catch(a){throw e.f&=-2,e.f|=8,oe(e),a}finally{p=r,X()}}}function oe(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,ye(e)}function xe(e){if(p!==this)throw new Error("Out-of-order effect");pe(this),p=e,this.f&=-2,8&this.f&&oe(this),X()}function J(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t==null?void 0:t.name}J.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.m=t)}finally{e()}};J.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,ye(this),de(this),B++;var e=p;return p=this,xe.bind(this,e)};J.prototype.N=function(){2&this.f||(this.f|=2,this.u=_,_=this)};J.prototype.d=function(){this.f|=8,1&this.f||oe(this)};J.prototype.dispose=function(){this.d()};function Se(e,t){var r=new J(e,t);try{r.c()}catch(h){throw r.d(),h}var a=r.d.bind(r);return a[Symbol.dispose]=a,a}const ue=e=>e!==null&&typeof e=="object"&&!Array.isArray(e);function re(e,t){if(Object.is(e,t))return!0;if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r+=1)if(!re(e[r],t[r]))return!1;return!0}if(ue(e)&&ue(t)){const r=Object.keys(e),a=Object.keys(t);if(r.length!==a.length)return!1;for(const h of r)if(!(h in t)||!re(e[h],t[h]))return!1;return!0}return!1}function ge(e){if(typeof structuredClone=="function")return structuredClone(e);try{return JSON.parse(JSON.stringify(e))}catch{return e}}function ce(e,t,r=Object.is,a=ge){const h={};for(const[T,b]of Object.entries(t)){const x=e[T];r(x,b,T)||(h[T]=a(b))}return h}function je(e={}){const t=(e.namespace??"default").trim()||"default",r=e.plugins??[],a=new Map;function h(b,x){return function(){var D;const z=`${t}:${b}`,R=a.get(b);if(R)return R;const I=x.state(),S=x.modules??{},V={...I};for(const[i,o]of Object.entries(S))V[i]=o.state();const y=ee(V),M=new Map,Z=new Map,A=new Map,E=new Map,j=new Map,s=new Set,u=new Set(Object.keys(I)),g=new Set(Object.keys(x.getters??{})),n=new Set(Object.keys(x.actions??{})),l=i=>y.value[i]??{},w=(i,o)=>{y.value={...y.value,[i]:o}},O=new Proxy({},{get(i,o){var f,v;if(M.has(o))return(f=M.get(o))==null?void 0:f.value;if(j.has(o))return(v=j.get(o))==null?void 0:v.value;if(u.has(o))return y.value[o];const m=E.get(o);return m?l(m.moduleName)[m.key]:y.value[o]}});for(const[i,o]of Object.entries(x.getters??{}))M.set(i,ae(()=>o(y.value,O)));const P=(i,o)=>{var f;for(const v of s)v(i);for(const v of r)(f=v.onMutation)==null||f.call(v,o,i)},U=(i,o,f,v)=>{const m=y.value[i];Object.is(m,o)||(y.value={...y.value,[i]:o},P({namespace:t,scopeId:z,storeId:b,key:i,oldValue:m,newValue:o,origin:f},v))},F=(i,o,f,v,m)=>{const $=l(i),c=$[o];Object.is(c,f)||(w(i,{...$,[o]:f}),P({namespace:t,scopeId:z,storeId:b,key:`${i}.${o}`,oldValue:c,newValue:f,origin:v},m))},q={$id:b,$namespace:t,$scopeId:z,$subscribe(i){return s.add(i),()=>s.delete(i)},$dispose(){var i;s.clear();for(const o of r)(i=o.onDispose)==null||i.call(o,N);a.delete(b)},$patch(i,o="local"){K(()=>{for(const[f,v]of Object.entries(i)){const m=E.get(f);if(m){F(m.moduleName,m.key,v,o,N);continue}if(f.includes(".")){const[$,c]=f.split(".",2);if(S[$]){F($,c,v,o,N);continue}}if(S[f]&&v&&typeof v=="object"&&!Array.isArray(v)){for(const[$,c]of Object.entries(v))F(f,$,c,o,N);continue}U(f,v,o,N)}})},$snapshot(){return{...y.value}}};for(const[i,o]of Object.entries(S)){const f=new Map,v=new Map,m=new Proxy({},{get(c,d){var C,L,ie;if(f.has(d))return(C=f.get(d))==null?void 0:C.value;if(M.has(d))return(L=M.get(d))==null?void 0:L.value;if(j.has(d))return(ie=j.get(d))==null?void 0:ie.value;const se=l(i);if(d in se)return se[d];if(u.has(d))return y.value[d]}});for(const[c,d]of Object.entries(o.getters??{}))f.set(c,ae(()=>d(l(i),y.value,m)));let $;for(const[c,d]of Object.entries(o.actions??{}))v.set(c,(...C)=>K(()=>d.apply($,C)));$=new Proxy({},{get(c,d){var C;if(v.has(d))return v.get(d);if(f.has(d))return(C=f.get(d))==null?void 0:C.value;const L=l(i);return d in L?L[d]:N[d]},set(c,d,C){if(v.has(d)||f.has(d))return!1;const L=l(i);return d in L?F(i,d,C,"local",N):N[d]=C,!0}}),A.set(i,$),Z.set(i,f);for(const c of Object.keys(l(i)))!(u.has(c)||g.has(c)||n.has(c)||Reflect.has(q,c)||S[c]!==void 0)&&!E.has(c)&&E.set(c,{moduleName:i,key:c});for(const[c,d]of f.entries())!(u.has(c)||g.has(c)||n.has(c)||Reflect.has(q,c)||S[c]!==void 0)&&!j.has(c)&&j.set(c,d);for(const[c,d]of v.entries())!(u.has(c)||g.has(c)||n.has(c)||Reflect.has(q,c)||S[c]!==void 0)&&!Reflect.has(q,c)&&(q[c]=d)}const N=new Proxy(q,{get(i,o,f){var v,m;if(Reflect.has(i,o))return Reflect.get(i,o,f);if(A.has(o))return A.get(o);if(M.has(o))return(v=M.get(o))==null?void 0:v.value;if(j.has(o))return(m=j.get(o))==null?void 0:m.value;if(u.has(o))return y.value[o];const $=E.get(o);return $?l($.moduleName)[$.key]:y.value[o]},set(i,o,f,v){if(Reflect.has(i,o))return Reflect.set(i,o,f,v);const m=E.get(o);return m?(F(m.moduleName,m.key,f,"local",v),!0):(U(o,f,"local",v),!0)}});for(const[i,o]of Object.entries(x.actions??{}))q[i]=(...f)=>K(()=>o.apply(N,f));for(const i of r)(D=i.onInit)==null||D.call(i,N);return a.set(b,N),N}}function T(b,x){return function(){var D;const z=`\0machine:${b}`,R=a.get(z);if(R)return R;const I=`${t}:${b}`,S=ee(x.initial),V=ee((x.context??(()=>({})))()),y=new Set,M=(s,u)=>{var g;for(const n of y)n(s);for(const n of r)(g=n.onMutation)==null||g.call(n,u,s)},Z=(s,u,g,n)=>{const l=V.value[s];Object.is(l,u)||(V.value={...V.value,[s]:u},M({namespace:t,scopeId:I,storeId:b,key:s,oldValue:l,newValue:u,origin:g},n))},A=(s,u,g)=>{const n=S.value;Object.is(n,s)||(S.value=s,M({namespace:t,scopeId:I,storeId:b,key:"$state",oldValue:n,newValue:s,origin:u},g))},E={$id:b,$namespace:t,$scopeId:I,$subscribe(s){return y.add(s),()=>y.delete(s)},$dispose(){var s;y.clear();for(const u of r)(s=u.onDispose)==null||s.call(u,j);a.delete(z)},$patch(s,u="local"){K(()=>{for(const[g,n]of Object.entries(s))g==="$state"?A(n,u,j):Z(g,n,u,j)})},$snapshot(){return{$state:S.value,...V.value}},send(s,u){K(()=>{var g,n,l;const w=(g=x.actions)==null?void 0:g[s];w&&w.call(j,u);const O=(l=(n=x.states[S.value])==null?void 0:n.on)==null?void 0:l[s];O!==void 0&&A(O,"local",j)})},matches(s){return S.value===s},can(s){const u=x.states[S.value];return!!(u!=null&&u.on&&s in u.on)}},j=new Proxy(E,{get(s,u,g){return u==="state"?S.value:Reflect.has(s,u)?Reflect.get(s,u,g):V.value[u]},set(s,u,g,n){return u==="state"?!1:Reflect.has(s,u)?Reflect.set(s,u,g,n):(Z(u,g,"local",n),!0)}});for(const s of r)(D=s.onInit)==null||D.call(s,j);return a.set(z,j),j}}return{defineStore:h,defineMachine:T,use(b){r.push(b)}}}je();const H=e=>e!==null&&typeof e=="object";function be(e){if(!H(e))return e;const t=new WeakSet,r=a=>{if(!H(a))return;const h=a;if(t.has(h))return;t.add(h);const T=Reflect.ownKeys(h);for(const b of T){const x=Reflect.get(h,b);r(x)}Object.freeze(h)};return r(e),e}function Oe(e,t){for(const[r,a]of Object.entries(t))e[r]=a}const fe=e=>Object.keys(e).length>0,le=e=>e?Array.isArray(e)?e:[e]:[],$e=e=>{const t=[e];if(e.includes(".")){const r=e.split(".",1)[0];r&&r!==e&&t.push(r)}return t},ke=(e,t)=>{if(!t||!H(e))return e;try{Object.defineProperty(e,t,{value:!0,enumerable:!1,configurable:!0})}catch{return e}return e};function Me(e){const t=e.mutationType??"storix/APPLY_PATCH",r=e.immutable??!0,a=e.clone??ge,h=e.equals??re,T=e.projectVuexToStorix??(n=>n),b=e.projectStorixToVuex??(n=>n),x=e.suppressBridgeEcho??!1,D=e.bridgeOriginKey??"__storixBridge",z=e.outboundDefault??{mode:"patch",type:t},R=n=>{const l=a(n);return r?be(l):l};let I=!1,S=!1,V=!1;const y=new Map,M=n=>{if(x)for(const l of n){const w=y.get(l)??0;y.set(l,w+1)}},Z=n=>{if(!x||!H(n))return!1;const l=Reflect.get(n,"payload");if(D&&H(l)&&Reflect.get(l,D))return!0;const w=Reflect.get(n,"type");if(typeof w!="string")return!1;const O=y.get(w)??0;return O<=0?!1:(O===1?y.delete(w):y.set(w,O-1),!0)},A=()=>{if(I||V)return;const n=R(T(e.vuex.state)),l=e.store.$snapshot(),w=ce(l,n,h,R);if(fe(w)){S=!0;try{e.store.$patch(w,e.externalMutationOrigin??"local")}finally{S=!1}}},E=n=>{const w=$e(n.storixMutation.key).flatMap(O=>{var P;return le((P=e.outboundRoutes)==null?void 0:P[O])});return w.push(...le(z)),w.find(O=>O.when?O.when(n):!0)},j=(n,l)=>{var U;if(n.mode==="custom"){(U=n.handler)==null||U.call(n,l),M(n.suppressMutationTypes??[]);return}const w=l.projectedPatch,O=ke(R(n.mapPayload?n.mapPayload(l):w),D);if(n.mode==="dispatch"){if(typeof e.vuex.dispatch!="function")throw new Error('Vuex bridge route mode "dispatch" requires vuex.dispatch to be available.');if(!n.type)throw new Error('Vuex bridge dispatch route requires a "type".');e.vuex.dispatch(n.type,O),M(n.suppressMutationTypes??[]);return}const P=n.type??t;e.vuex.commit(P,O),M(n.suppressMutationTypes??[P])},s=n=>{if(I||S)return;const l=e.store.$snapshot(),w=R(b(l)),O=R(T(e.vuex.state)),P=ce(O,w,h,R);if(!fe(P))return;const U={storixMutation:n??{namespace:e.store.$namespace,scopeId:e.store.$scopeId,storeId:e.store.$id,key:Object.keys(P)[0]??"*",oldValue:void 0,newValue:void 0,origin:"local"},storixSnapshot:l,vuexState:e.vuex.state,projectedPatch:P,projectedVuexState:w,origin:"storix"},F=E(U);if(F){V=!0;try{j(F,U)}finally{V=!1}}},u=e.vuex.subscribe(n=>{Z(n)||A()}),g=e.store.$subscribe(n=>{s(n)});return A(),{dispose(){I||(I=!0,u(),g())},syncFromExternal:A,syncFromStore(){s()}}}exports.applyVuexPatchMutation=Oe;exports.createVuexBridge=Me;exports.deepFreeze=be;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@storix-js/core");var t=e=>typeof e==`object`&&!!e;function n(e){if(!t(e))return e;let n=new WeakSet,r=e=>{if(!t(e))return;let i=e;if(n.has(i))return;n.add(i);let a=Reflect.ownKeys(i);for(let e of a){let t=Reflect.get(i,e);r(t)}Object.freeze(i)};return r(e),e}function r(e,t){for(let[n,r]of Object.entries(t))e[n]=r}var i=e=>Object.keys(e).length>0,a=e=>e?Array.isArray(e)?e:[e]:[],o=e=>{let t=[e];if(e.includes(`.`)){let n=e.split(`.`,1)[0];n&&n!==e&&t.push(n)}return t},s=(e,n)=>{if(!n||!t(e))return e;try{Object.defineProperty(e,n,{value:!0,enumerable:!1,configurable:!0})}catch{return e}return e};function c(r){let c=r.mutationType??`storix/APPLY_PATCH`,l=r.immutable??!0,u=r.clone??e.isolateSnapshot,d=r.equals??e.deepEqual,f=r.projectVuexToStorix??(e=>e),p=r.projectStorixToVuex??(e=>e),m=r.suppressBridgeEcho??!1,h=r.bridgeOriginKey??`__storixBridge`,g=r.outboundDefault??{mode:`patch`,type:c},_=e=>{let t=u(e);return l?n(t):t},v=!1,y=!1,b=!1,x=new Map,S=e=>{if(m)for(let t of e){let e=x.get(t)??0;x.set(t,e+1)}},C=e=>{if(!m||!t(e))return!1;let n=Reflect.get(e,`payload`);if(h&&t(n)&&Reflect.get(n,h))return!0;let r=Reflect.get(e,`type`);if(typeof r!=`string`)return!1;let i=x.get(r)??0;return i<=0?!1:(i===1?x.delete(r):x.set(r,i-1),!0)},w=()=>{if(v||b)return;let t=_(f(r.vuex.state)),n=r.store.$snapshot(),a=(0,e.createPatchFromSnapshot)(n,t,d,_);if(i(a)){y=!0;try{r.store.$patch(a,r.externalMutationOrigin??`local`)}finally{y=!1}}},T=e=>{let t=o(e.storixMutation.key).flatMap(e=>a(r.outboundRoutes?.[e]));return t.push(...a(g)),t.find(t=>!t.when||t.when(e))},E=(e,t)=>{if(e.mode===`custom`){e.handler?.(t),S(e.suppressMutationTypes??[]);return}let n=t.projectedPatch,i=s(_(e.mapPayload?e.mapPayload(t):n),h);if(e.mode===`dispatch`){if(typeof r.vuex.dispatch!=`function`)throw Error(`Vuex bridge route mode "dispatch" requires vuex.dispatch to be available.`);if(!e.type)throw Error(`Vuex bridge dispatch route requires a "type".`);r.vuex.dispatch(e.type,i),S(e.suppressMutationTypes??[]);return}let a=e.type??c;r.vuex.commit(a,i),S(e.suppressMutationTypes??[a])},D=t=>{if(v||y)return;let n=r.store.$snapshot(),a=_(p(n)),o=_(f(r.vuex.state)),s=(0,e.createPatchFromSnapshot)(o,a,d,_);if(!i(s))return;let c={storixMutation:t??{namespace:r.store.$namespace,scopeId:r.store.$scopeId,storeId:r.store.$id,key:Object.keys(s)[0]??`*`,oldValue:void 0,newValue:void 0,origin:`local`},storixSnapshot:n,vuexState:r.vuex.state,projectedPatch:s,projectedVuexState:a,origin:`storix`},l=T(c);if(l){b=!0;try{E(l,c)}finally{b=!1}}},O=r.vuex.subscribe(e=>{C(e)||w()}),k=r.store.$subscribe(e=>{D(e)});return w(),{dispose(){v||(v=!0,O(),k())},syncFromExternal:w,syncFromStore(){D()}}}exports.applyVuexPatchMutation=r,exports.createVuexBridge=c,exports.deepFreeze=n;
package/dist/index.js CHANGED
@@ -1,702 +1,135 @@
1
- var bt = Symbol.for("preact-signals");
2
- function X() {
3
- if (z > 1)
4
- z--;
5
- else {
6
- var t, e = !1;
7
- for ((function() {
8
- var h = G;
9
- for (G = void 0; h !== void 0; )
10
- h.S.v === h.v && (h.S.i = h.i), h = h.o;
11
- })(); _ !== void 0; ) {
12
- var r = _;
13
- for (_ = void 0, Y++; r !== void 0; ) {
14
- var a = r.u;
15
- if (r.u = void 0, r.f &= -3, !(8 & r.f) && vt(r)) try {
16
- r.c();
17
- } catch (h) {
18
- e || (t = h, e = !0);
19
- }
20
- r = a;
21
- }
22
- }
23
- if (Y = 0, z--, e) throw t;
24
- }
25
- }
26
- function K(t) {
27
- if (z > 0) return t();
28
- et = ++wt, z++;
29
- try {
30
- return t();
31
- } finally {
32
- X();
33
- }
34
- }
35
- var p = void 0;
36
- function nt(t) {
37
- var e = p;
38
- p = void 0;
39
- try {
40
- return t();
41
- } finally {
42
- p = e;
43
- }
44
- }
45
- var _ = void 0, z = 0, Y = 0, wt = 0, et = 0, G = void 0, Q = 0;
46
- function ht(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;
53
- }
54
- }
55
- function k(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;
57
- }
58
- k.prototype.brand = bt;
59
- k.prototype.h = function() {
60
- return !0;
61
- };
62
- k.prototype.S = function(t) {
63
- var e = this, r = this.t;
64
- r !== t && t.e === void 0 && (t.x = r, this.t = t, r !== void 0 ? r.e = t : nt(function() {
65
- var a;
66
- (a = e.W) == null || a.call(e);
67
- }));
68
- };
69
- k.prototype.U = function(t) {
70
- var e = this;
71
- if (this.t !== void 0) {
72
- var r = t.e, a = t.x;
73
- r !== void 0 && (r.x = a, t.e = void 0), a !== void 0 && (a.e = r, t.x = void 0), t === this.t && (this.t = a, a === void 0 && nt(function() {
74
- var h;
75
- (h = e.Z) == null || h.call(e);
76
- }));
77
- }
78
- };
79
- k.prototype.subscribe = function(t) {
80
- var e = this;
81
- return xt(function() {
82
- var r = e.value, a = p;
83
- p = void 0;
84
- try {
85
- t(r);
86
- } finally {
87
- p = a;
88
- }
89
- }, { name: "sub" });
90
- };
91
- k.prototype.valueOf = function() {
92
- return this.value;
93
- };
94
- k.prototype.toString = function() {
95
- return this.value + "";
96
- };
97
- k.prototype.toJSON = function() {
98
- return this.value;
99
- };
100
- k.prototype.peek = function() {
101
- var t = this;
102
- return nt(function() {
103
- return t.value;
104
- });
105
- };
106
- Object.defineProperty(k.prototype, "value", { get: function() {
107
- var t = ht(this);
108
- return t !== void 0 && (t.i = this.i), this.v;
109
- }, set: function(t) {
110
- if (t !== this.v) {
111
- if (Y > 100) throw new Error("Cycle detected");
112
- (function(r) {
113
- z !== 0 && Y === 0 && r.l !== et && (r.l = et, G = { S: r, v: r.v, i: r.i, o: G });
114
- })(this), this.v = t, this.i++, Q++, z++;
115
- try {
116
- for (var e = this.t; e !== void 0; e = e.x) e.t.N();
117
- } finally {
118
- X();
119
- }
120
- }
121
- } });
122
- function tt(t, e) {
123
- return new k(t, e);
124
- }
125
- function vt(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;
127
- return !1;
128
- }
129
- function dt(t) {
130
- for (var e = t.s; e !== void 0; e = e.n) {
131
- var r = e.S.n;
132
- if (r !== void 0 && (e.r = r), e.S.n = e, e.i = -1, e.n === void 0) {
133
- t.s = e;
134
- break;
135
- }
136
- }
137
- }
138
- function pt(t) {
139
- for (var e = t.s, r = void 0; e !== void 0; ) {
140
- var a = e.p;
141
- e.i === -1 ? (e.S.U(e), a !== void 0 && (a.n = e.n), e.n !== void 0 && (e.n.p = a)) : r = e, e.S.n = e.r, e.r !== void 0 && (e.r = void 0), e = a;
142
- }
143
- t.s = r;
144
- }
145
- function W(t, e) {
146
- k.call(this, void 0), this.x = t, this.s = void 0, this.g = Q - 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;
147
- }
148
- W.prototype = new k();
149
- W.prototype.h = function() {
150
- if (this.f &= -3, 1 & this.f) return !1;
151
- if ((36 & this.f) == 32 || (this.f &= -5, this.g === Q)) return !0;
152
- if (this.g = Q, this.f |= 1, this.i > 0 && !vt(this))
153
- return this.f &= -2, !0;
154
- var t = p;
155
- try {
156
- dt(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 (r) {
160
- this.v = r, this.f |= 16, this.i++;
161
- }
162
- return p = t, pt(this), this.f &= -2, !0;
163
- };
164
- W.prototype.S = function(t) {
165
- if (this.t === void 0) {
166
- this.f |= 36;
167
- for (var e = this.s; e !== void 0; e = e.n) e.S.S(e);
168
- }
169
- k.prototype.S.call(this, t);
170
- };
171
- W.prototype.U = function(t) {
172
- if (this.t !== void 0 && (k.prototype.U.call(this, t), this.t === void 0)) {
173
- this.f &= -33;
174
- for (var e = this.s; e !== void 0; e = e.n) e.S.U(e);
175
- }
176
- };
177
- W.prototype.N = function() {
178
- if (!(2 & this.f)) {
179
- this.f |= 6;
180
- for (var t = this.t; t !== void 0; t = t.x) t.t.N();
181
- }
182
- };
183
- Object.defineProperty(W.prototype, "value", { get: function() {
184
- if (1 & this.f) throw new Error("Cycle detected");
185
- var t = ht(this);
186
- if (this.h(), t !== void 0 && (t.i = this.i), 16 & this.f) throw this.v;
187
- return this.v;
188
- } });
189
- function at(t, e) {
190
- return new W(t, e);
191
- }
192
- function yt(t) {
193
- var e = t.m;
194
- if (t.m = void 0, typeof e == "function") {
195
- z++;
196
- var r = p;
197
- p = void 0;
198
- try {
199
- e();
200
- } catch (a) {
201
- throw t.f &= -2, t.f |= 8, ot(t), a;
202
- } finally {
203
- p = r, X();
204
- }
205
- }
206
- }
207
- function ot(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, yt(t);
210
- }
211
- function mt(t) {
212
- if (p !== this) throw new Error("Out-of-order effect");
213
- pt(this), p = t, this.f &= -2, 8 & this.f && ot(this), X();
214
- }
215
- function J(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;
217
- }
218
- J.prototype.c = function() {
219
- var t = this.S();
220
- try {
221
- if (8 & this.f || this.x === void 0) return;
222
- var e = this.x();
223
- typeof e == "function" && (this.m = e);
224
- } finally {
225
- t();
226
- }
227
- };
228
- J.prototype.S = function() {
229
- if (1 & this.f) throw new Error("Cycle detected");
230
- this.f |= 1, this.f &= -9, yt(this), dt(this), z++;
231
- var t = p;
232
- return p = this, mt.bind(this, t);
233
- };
234
- J.prototype.N = function() {
235
- 2 & this.f || (this.f |= 2, this.u = _, _ = this);
236
- };
237
- J.prototype.d = function() {
238
- this.f |= 8, 1 & this.f || ot(this);
239
- };
240
- J.prototype.dispose = function() {
241
- this.d();
242
- };
243
- function xt(t, e) {
244
- var r = new J(t, e);
245
- try {
246
- r.c();
247
- } catch (h) {
248
- throw r.d(), h;
249
- }
250
- var a = r.d.bind(r);
251
- return a[Symbol.dispose] = a, a;
252
- }
253
- const ut = (t) => t !== null && typeof t == "object" && !Array.isArray(t);
254
- function rt(t, e) {
255
- if (Object.is(t, e)) return !0;
256
- if (t instanceof Date && e instanceof Date)
257
- return t.getTime() === e.getTime();
258
- if (Array.isArray(t) && Array.isArray(e)) {
259
- if (t.length !== e.length) return !1;
260
- for (let r = 0; r < t.length; r += 1)
261
- if (!rt(t[r], e[r])) return !1;
262
- return !0;
263
- }
264
- if (ut(t) && ut(e)) {
265
- const r = Object.keys(t), a = Object.keys(e);
266
- if (r.length !== a.length) return !1;
267
- for (const h of r)
268
- if (!(h in e) || !rt(t[h], e[h])) return !1;
269
- return !0;
270
- }
271
- return !1;
272
- }
273
- function gt(t) {
274
- if (typeof structuredClone == "function")
275
- return structuredClone(t);
276
- try {
277
- return JSON.parse(JSON.stringify(t));
278
- } catch {
279
- return t;
280
- }
281
- }
282
- function ct(t, e, r = Object.is, a = gt) {
283
- const h = {};
284
- for (const [A, b] of Object.entries(e)) {
285
- const x = t[A];
286
- r(x, b, A) || (h[A] = a(b));
287
- }
288
- return h;
289
- }
290
- function St(t = {}) {
291
- const e = (t.namespace ?? "default").trim() || "default", r = t.plugins ?? [], a = /* @__PURE__ */ new Map();
292
- function h(b, x) {
293
- return function() {
294
- var D;
295
- const U = `${e}:${b}`, R = a.get(b);
296
- if (R) return R;
297
- const I = x.state(), S = x.modules ?? {}, V = { ...I };
298
- for (const [i, o] of Object.entries(S))
299
- V[i] = o.state();
300
- const y = tt(V), M = /* @__PURE__ */ new Map(), Z = /* @__PURE__ */ new Map(), T = /* @__PURE__ */ new Map(), E = /* @__PURE__ */ new Map(), j = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Set(), u = new Set(Object.keys(I)), g = new Set(Object.keys(x.getters ?? {})), n = new Set(Object.keys(x.actions ?? {})), l = (i) => y.value[i] ?? {}, w = (i, o) => {
301
- y.value = {
302
- ...y.value,
303
- [i]: o
304
- };
305
- }, O = new Proxy(
306
- {},
307
- {
308
- get(i, o) {
309
- var f, v;
310
- if (M.has(o)) return (f = M.get(o)) == null ? void 0 : f.value;
311
- if (j.has(o)) return (v = j.get(o)) == null ? void 0 : v.value;
312
- if (u.has(o)) return y.value[o];
313
- const m = E.get(o);
314
- return m ? l(m.moduleName)[m.key] : y.value[o];
315
- }
316
- }
317
- );
318
- for (const [i, o] of Object.entries(x.getters ?? {}))
319
- M.set(
320
- i,
321
- at(() => o(y.value, O))
322
- );
323
- const P = (i, o) => {
324
- var f;
325
- for (const v of s) v(i);
326
- for (const v of r)
327
- (f = v.onMutation) == null || f.call(v, o, i);
328
- }, B = (i, o, f, v) => {
329
- const m = y.value[i];
330
- Object.is(m, o) || (y.value = {
331
- ...y.value,
332
- [i]: o
333
- }, P(
334
- {
335
- namespace: e,
336
- scopeId: U,
337
- storeId: b,
338
- key: i,
339
- oldValue: m,
340
- newValue: o,
341
- origin: f
342
- },
343
- v
344
- ));
345
- }, q = (i, o, f, v, m) => {
346
- const $ = l(i), c = $[o];
347
- Object.is(c, f) || (w(i, {
348
- ...$,
349
- [o]: f
350
- }), P(
351
- {
352
- namespace: e,
353
- scopeId: U,
354
- storeId: b,
355
- key: `${i}.${o}`,
356
- oldValue: c,
357
- newValue: f,
358
- origin: v
359
- },
360
- m
361
- ));
362
- }, F = {
363
- $id: b,
364
- $namespace: e,
365
- $scopeId: U,
366
- $subscribe(i) {
367
- return s.add(i), () => s.delete(i);
368
- },
369
- $dispose() {
370
- var i;
371
- s.clear();
372
- for (const o of r)
373
- (i = o.onDispose) == null || i.call(o, N);
374
- a.delete(b);
375
- },
376
- $patch(i, o = "local") {
377
- K(() => {
378
- for (const [f, v] of Object.entries(i)) {
379
- const m = E.get(f);
380
- if (m) {
381
- q(m.moduleName, m.key, v, o, N);
382
- continue;
383
- }
384
- if (f.includes(".")) {
385
- const [$, c] = f.split(".", 2);
386
- if (S[$]) {
387
- q($, c, v, o, N);
388
- continue;
389
- }
390
- }
391
- if (S[f] && v && typeof v == "object" && !Array.isArray(v)) {
392
- for (const [$, c] of Object.entries(v))
393
- q(f, $, c, o, N);
394
- continue;
395
- }
396
- B(f, v, o, N);
397
- }
398
- });
399
- },
400
- $snapshot() {
401
- return { ...y.value };
402
- }
403
- };
404
- for (const [i, o] of Object.entries(S)) {
405
- const f = /* @__PURE__ */ new Map(), v = /* @__PURE__ */ new Map(), m = new Proxy(
406
- {},
407
- {
408
- get(c, d) {
409
- var C, L, it;
410
- if (f.has(d)) return (C = f.get(d)) == null ? void 0 : C.value;
411
- if (M.has(d)) return (L = M.get(d)) == null ? void 0 : L.value;
412
- if (j.has(d)) return (it = j.get(d)) == null ? void 0 : it.value;
413
- const st = l(i);
414
- if (d in st) return st[d];
415
- if (u.has(d)) return y.value[d];
416
- }
417
- }
418
- );
419
- for (const [c, d] of Object.entries(o.getters ?? {}))
420
- f.set(
421
- c,
422
- at(() => d(l(i), y.value, m))
423
- );
424
- let $;
425
- for (const [c, d] of Object.entries(o.actions ?? {}))
426
- v.set(c, (...C) => K(() => d.apply($, C)));
427
- $ = new Proxy(
428
- {},
429
- {
430
- get(c, d) {
431
- var C;
432
- if (v.has(d)) return v.get(d);
433
- if (f.has(d)) return (C = f.get(d)) == null ? void 0 : C.value;
434
- const L = l(i);
435
- return d in L ? L[d] : N[d];
436
- },
437
- set(c, d, C) {
438
- if (v.has(d) || f.has(d)) return !1;
439
- const L = l(i);
440
- return d in L ? q(i, d, C, "local", N) : N[d] = C, !0;
441
- }
442
- }
443
- ), T.set(i, $), Z.set(i, f);
444
- for (const c of Object.keys(l(i)))
445
- !(u.has(c) || g.has(c) || n.has(c) || Reflect.has(F, c) || S[c] !== void 0) && !E.has(c) && E.set(c, { moduleName: i, key: c });
446
- for (const [c, d] of f.entries())
447
- !(u.has(c) || g.has(c) || n.has(c) || Reflect.has(F, c) || S[c] !== void 0) && !j.has(c) && j.set(c, d);
448
- for (const [c, d] of v.entries())
449
- !(u.has(c) || g.has(c) || n.has(c) || Reflect.has(F, c) || S[c] !== void 0) && !Reflect.has(F, c) && (F[c] = d);
450
- }
451
- const N = new Proxy(F, {
452
- get(i, o, f) {
453
- var v, m;
454
- if (Reflect.has(i, o)) return Reflect.get(i, o, f);
455
- if (T.has(o)) return T.get(o);
456
- if (M.has(o)) return (v = M.get(o)) == null ? void 0 : v.value;
457
- if (j.has(o)) return (m = j.get(o)) == null ? void 0 : m.value;
458
- if (u.has(o)) return y.value[o];
459
- const $ = E.get(o);
460
- return $ ? l($.moduleName)[$.key] : y.value[o];
461
- },
462
- set(i, o, f, v) {
463
- if (Reflect.has(i, o))
464
- return Reflect.set(i, o, f, v);
465
- const m = E.get(o);
466
- return m ? (q(m.moduleName, m.key, f, "local", v), !0) : (B(o, f, "local", v), !0);
467
- }
468
- });
469
- for (const [i, o] of Object.entries(x.actions ?? {}))
470
- F[i] = (...f) => K(() => o.apply(N, f));
471
- for (const i of r)
472
- (D = i.onInit) == null || D.call(i, N);
473
- return a.set(b, N), N;
474
- };
475
- }
476
- function A(b, x) {
477
- return function() {
478
- var D;
479
- const U = `\0machine:${b}`, R = a.get(U);
480
- if (R) return R;
481
- const I = `${e}:${b}`, S = tt(x.initial), V = tt((x.context ?? (() => ({})))()), y = /* @__PURE__ */ new Set(), M = (s, u) => {
482
- var g;
483
- for (const n of y) n(s);
484
- for (const n of r)
485
- (g = n.onMutation) == null || g.call(n, u, s);
486
- }, Z = (s, u, g, n) => {
487
- const l = V.value[s];
488
- Object.is(l, u) || (V.value = { ...V.value, [s]: u }, M({ namespace: e, scopeId: I, storeId: b, key: s, oldValue: l, newValue: u, origin: g }, n));
489
- }, T = (s, u, g) => {
490
- const n = S.value;
491
- Object.is(n, s) || (S.value = s, M(
492
- { namespace: e, scopeId: I, storeId: b, key: "$state", oldValue: n, newValue: s, origin: u },
493
- g
494
- ));
495
- }, E = {
496
- $id: b,
497
- $namespace: e,
498
- $scopeId: I,
499
- $subscribe(s) {
500
- return y.add(s), () => y.delete(s);
501
- },
502
- $dispose() {
503
- var s;
504
- y.clear();
505
- for (const u of r)
506
- (s = u.onDispose) == null || s.call(u, j);
507
- a.delete(U);
508
- },
509
- $patch(s, u = "local") {
510
- K(() => {
511
- for (const [g, n] of Object.entries(s))
512
- g === "$state" ? T(n, u, j) : Z(g, n, u, j);
513
- });
514
- },
515
- $snapshot() {
516
- return { $state: S.value, ...V.value };
517
- },
518
- send(s, u) {
519
- K(() => {
520
- var g, n, l;
521
- const w = (g = x.actions) == null ? void 0 : g[s];
522
- w && w.call(j, u);
523
- const O = (l = (n = x.states[S.value]) == null ? void 0 : n.on) == null ? void 0 : l[s];
524
- O !== void 0 && T(O, "local", j);
525
- });
526
- },
527
- matches(s) {
528
- return S.value === s;
529
- },
530
- can(s) {
531
- const u = x.states[S.value];
532
- return !!(u != null && u.on && s in u.on);
533
- }
534
- }, j = new Proxy(E, {
535
- get(s, u, g) {
536
- return u === "state" ? S.value : Reflect.has(s, u) ? Reflect.get(s, u, g) : V.value[u];
537
- },
538
- set(s, u, g, n) {
539
- return u === "state" ? !1 : Reflect.has(s, u) ? Reflect.set(s, u, g, n) : (Z(u, g, "local", n), !0);
540
- }
541
- });
542
- for (const s of r)
543
- (D = s.onInit) == null || D.call(s, j);
544
- return a.set(U, j), j;
545
- };
546
- }
547
- return {
548
- defineStore: h,
549
- defineMachine: A,
550
- use(b) {
551
- r.push(b);
552
- }
553
- };
554
- }
555
- St();
556
- const H = (t) => t !== null && typeof t == "object";
557
- function jt(t) {
558
- if (!H(t)) return t;
559
- const e = /* @__PURE__ */ new WeakSet(), r = (a) => {
560
- if (!H(a)) return;
561
- const h = a;
562
- if (e.has(h)) return;
563
- e.add(h);
564
- const A = Reflect.ownKeys(h);
565
- for (const b of A) {
566
- const x = Reflect.get(h, b);
567
- r(x);
568
- }
569
- Object.freeze(h);
570
- };
571
- return r(t), t;
572
- }
573
- function kt(t, e) {
574
- for (const [r, a] of Object.entries(e))
575
- t[r] = a;
576
- }
577
- const ft = (t) => Object.keys(t).length > 0, lt = (t) => t ? Array.isArray(t) ? t : [t] : [], Ot = (t) => {
578
- const e = [t];
579
- if (t.includes(".")) {
580
- const r = t.split(".", 1)[0];
581
- r && r !== t && e.push(r);
582
- }
583
- return e;
584
- }, $t = (t, e) => {
585
- if (!e || !H(t)) return t;
586
- try {
587
- Object.defineProperty(t, e, {
588
- value: !0,
589
- enumerable: !1,
590
- configurable: !0
591
- });
592
- } catch {
593
- return t;
594
- }
595
- return t;
596
- };
597
- function Mt(t) {
598
- const e = t.mutationType ?? "storix/APPLY_PATCH", r = t.immutable ?? !0, a = t.clone ?? gt, h = t.equals ?? rt, A = t.projectVuexToStorix ?? ((n) => n), b = t.projectStorixToVuex ?? ((n) => n), x = t.suppressBridgeEcho ?? !1, D = t.bridgeOriginKey ?? "__storixBridge", U = t.outboundDefault ?? {
599
- mode: "patch",
600
- type: e
601
- }, R = (n) => {
602
- const l = a(n);
603
- return r ? jt(l) : l;
604
- };
605
- let I = !1, S = !1, V = !1;
606
- const y = /* @__PURE__ */ new Map(), M = (n) => {
607
- if (x)
608
- for (const l of n) {
609
- const w = y.get(l) ?? 0;
610
- y.set(l, w + 1);
611
- }
612
- }, Z = (n) => {
613
- if (!x || !H(n)) return !1;
614
- const l = Reflect.get(n, "payload");
615
- if (D && H(l) && Reflect.get(l, D))
616
- return !0;
617
- const w = Reflect.get(n, "type");
618
- if (typeof w != "string") return !1;
619
- const O = y.get(w) ?? 0;
620
- return O <= 0 ? !1 : (O === 1 ? y.delete(w) : y.set(w, O - 1), !0);
621
- }, T = () => {
622
- if (I || V) return;
623
- const n = R(A(t.vuex.state)), l = t.store.$snapshot(), w = ct(l, n, h, R);
624
- if (ft(w)) {
625
- S = !0;
626
- try {
627
- t.store.$patch(w, t.externalMutationOrigin ?? "local");
628
- } finally {
629
- S = !1;
630
- }
631
- }
632
- }, E = (n) => {
633
- const w = Ot(n.storixMutation.key).flatMap((O) => {
634
- var P;
635
- return lt((P = t.outboundRoutes) == null ? void 0 : P[O]);
636
- });
637
- return w.push(...lt(U)), w.find((O) => O.when ? O.when(n) : !0);
638
- }, j = (n, l) => {
639
- var B;
640
- if (n.mode === "custom") {
641
- (B = n.handler) == null || B.call(n, l), M(n.suppressMutationTypes ?? []);
642
- return;
643
- }
644
- const w = l.projectedPatch, O = $t(R(n.mapPayload ? n.mapPayload(l) : w), D);
645
- if (n.mode === "dispatch") {
646
- if (typeof t.vuex.dispatch != "function")
647
- throw new Error('Vuex bridge route mode "dispatch" requires vuex.dispatch to be available.');
648
- if (!n.type)
649
- throw new Error('Vuex bridge dispatch route requires a "type".');
650
- t.vuex.dispatch(n.type, O), M(n.suppressMutationTypes ?? []);
651
- return;
652
- }
653
- const P = n.type ?? e;
654
- t.vuex.commit(P, O), M(n.suppressMutationTypes ?? [P]);
655
- }, s = (n) => {
656
- if (I || S) return;
657
- const l = t.store.$snapshot(), w = R(b(l)), O = R(A(t.vuex.state)), P = ct(O, w, h, R);
658
- if (!ft(P)) return;
659
- const B = {
660
- storixMutation: n ?? {
661
- namespace: t.store.$namespace,
662
- scopeId: t.store.$scopeId,
663
- storeId: t.store.$id,
664
- key: Object.keys(P)[0] ?? "*",
665
- oldValue: void 0,
666
- newValue: void 0,
667
- origin: "local"
668
- },
669
- storixSnapshot: l,
670
- vuexState: t.vuex.state,
671
- projectedPatch: P,
672
- projectedVuexState: w,
673
- origin: "storix"
674
- }, q = E(B);
675
- if (q) {
676
- V = !0;
677
- try {
678
- j(q, B);
679
- } finally {
680
- V = !1;
681
- }
682
- }
683
- }, u = t.vuex.subscribe((n) => {
684
- Z(n) || T();
685
- }), g = t.store.$subscribe((n) => {
686
- s(n);
687
- });
688
- return T(), {
689
- dispose() {
690
- I || (I = !0, u(), g());
691
- },
692
- syncFromExternal: T,
693
- syncFromStore() {
694
- s();
695
- }
696
- };
697
- }
698
- export {
699
- kt as applyVuexPatchMutation,
700
- Mt as createVuexBridge,
701
- jt as deepFreeze
702
- };
1
+ import { createPatchFromSnapshot as e, deepEqual as t, isolateSnapshot as n } from "@storix-js/core";
2
+ //#region src/index.ts
3
+ var r = (e) => typeof e == "object" && !!e;
4
+ function i(e) {
5
+ if (!r(e)) return e;
6
+ let t = /* @__PURE__ */ new WeakSet(), n = (e) => {
7
+ if (!r(e)) return;
8
+ let i = e;
9
+ if (t.has(i)) return;
10
+ t.add(i);
11
+ let a = Reflect.ownKeys(i);
12
+ for (let e of a) {
13
+ let t = Reflect.get(i, e);
14
+ n(t);
15
+ }
16
+ Object.freeze(i);
17
+ };
18
+ return n(e), e;
19
+ }
20
+ function a(e, t) {
21
+ for (let [n, r] of Object.entries(t)) e[n] = r;
22
+ }
23
+ var o = (e) => Object.keys(e).length > 0, s = (e) => e ? Array.isArray(e) ? e : [e] : [], c = (e) => {
24
+ let t = [e];
25
+ if (e.includes(".")) {
26
+ let n = e.split(".", 1)[0];
27
+ n && n !== e && t.push(n);
28
+ }
29
+ return t;
30
+ }, l = (e, t) => {
31
+ if (!t || !r(e)) return e;
32
+ try {
33
+ Object.defineProperty(e, t, {
34
+ value: !0,
35
+ enumerable: !1,
36
+ configurable: !0
37
+ });
38
+ } catch {
39
+ return e;
40
+ }
41
+ return e;
42
+ };
43
+ function u(a) {
44
+ let u = a.mutationType ?? "storix/APPLY_PATCH", d = a.immutable ?? !0, f = a.clone ?? n, p = a.equals ?? t, m = a.projectVuexToStorix ?? ((e) => e), h = a.projectStorixToVuex ?? ((e) => e), g = a.suppressBridgeEcho ?? !1, _ = a.bridgeOriginKey ?? "__storixBridge", v = a.outboundDefault ?? {
45
+ mode: "patch",
46
+ type: u
47
+ }, y = (e) => {
48
+ let t = f(e);
49
+ return d ? i(t) : t;
50
+ }, b = !1, x = !1, S = !1, C = /* @__PURE__ */ new Map(), w = (e) => {
51
+ if (g) for (let t of e) {
52
+ let e = C.get(t) ?? 0;
53
+ C.set(t, e + 1);
54
+ }
55
+ }, T = (e) => {
56
+ if (!g || !r(e)) return !1;
57
+ let t = Reflect.get(e, "payload");
58
+ if (_ && r(t) && Reflect.get(t, _)) return !0;
59
+ let n = Reflect.get(e, "type");
60
+ if (typeof n != "string") return !1;
61
+ let i = C.get(n) ?? 0;
62
+ return i <= 0 ? !1 : (i === 1 ? C.delete(n) : C.set(n, i - 1), !0);
63
+ }, E = () => {
64
+ if (b || S) return;
65
+ let t = y(m(a.vuex.state)), n = a.store.$snapshot(), r = e(n, t, p, y);
66
+ if (o(r)) {
67
+ x = !0;
68
+ try {
69
+ a.store.$patch(r, a.externalMutationOrigin ?? "local");
70
+ } finally {
71
+ x = !1;
72
+ }
73
+ }
74
+ }, D = (e) => {
75
+ let t = c(e.storixMutation.key).flatMap((e) => s(a.outboundRoutes?.[e]));
76
+ return t.push(...s(v)), t.find((t) => !t.when || t.when(e));
77
+ }, O = (e, t) => {
78
+ if (e.mode === "custom") {
79
+ e.handler?.(t), w(e.suppressMutationTypes ?? []);
80
+ return;
81
+ }
82
+ let n = t.projectedPatch, r = l(y(e.mapPayload ? e.mapPayload(t) : n), _);
83
+ if (e.mode === "dispatch") {
84
+ if (typeof a.vuex.dispatch != "function") throw Error("Vuex bridge route mode \"dispatch\" requires vuex.dispatch to be available.");
85
+ if (!e.type) throw Error("Vuex bridge dispatch route requires a \"type\".");
86
+ a.vuex.dispatch(e.type, r), w(e.suppressMutationTypes ?? []);
87
+ return;
88
+ }
89
+ let i = e.type ?? u;
90
+ a.vuex.commit(i, r), w(e.suppressMutationTypes ?? [i]);
91
+ }, k = (t) => {
92
+ if (b || x) return;
93
+ let n = a.store.$snapshot(), r = y(h(n)), i = y(m(a.vuex.state)), s = e(i, r, p, y);
94
+ if (!o(s)) return;
95
+ let c = {
96
+ storixMutation: t ?? {
97
+ namespace: a.store.$namespace,
98
+ scopeId: a.store.$scopeId,
99
+ storeId: a.store.$id,
100
+ key: Object.keys(s)[0] ?? "*",
101
+ oldValue: void 0,
102
+ newValue: void 0,
103
+ origin: "local"
104
+ },
105
+ storixSnapshot: n,
106
+ vuexState: a.vuex.state,
107
+ projectedPatch: s,
108
+ projectedVuexState: r,
109
+ origin: "storix"
110
+ }, l = D(c);
111
+ if (l) {
112
+ S = !0;
113
+ try {
114
+ O(l, c);
115
+ } finally {
116
+ S = !1;
117
+ }
118
+ }
119
+ }, A = a.vuex.subscribe((e) => {
120
+ T(e) || E();
121
+ }), j = a.store.$subscribe((e) => {
122
+ k(e);
123
+ });
124
+ return E(), {
125
+ dispose() {
126
+ b || (b = !0, A(), j());
127
+ },
128
+ syncFromExternal: E,
129
+ syncFromStore() {
130
+ k();
131
+ }
132
+ };
133
+ }
134
+ //#endregion
135
+ export { a as applyVuexPatchMutation, u as createVuexBridge, i as deepFreeze };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storix-js/vuex",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -19,13 +19,13 @@
19
19
  "require": "./dist/index.cjs"
20
20
  }
21
21
  },
22
+ "dependencies": {
23
+ "@storix-js/core": "0.3.0"
24
+ },
22
25
  "scripts": {
23
26
  "build": "vite build && tsc -p tsconfig.build.json --emitDeclarationOnly",
24
27
  "dev": "vite build --watch",
25
28
  "test": "vitest run --passWithNoTests",
26
29
  "typecheck": "tsc -p tsconfig.json --noEmit"
27
- },
28
- "dependencies": {
29
- "@storix-js/core": "workspace:*"
30
30
  }
31
31
  }