@storix-js/vuex 0.1.1 → 0.1.2

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
@@ -17,8 +17,30 @@ const bridge = createVuexBridge({
17
17
  store: useAppStore(),
18
18
  vuex: vuexStore,
19
19
  mutationType: 'storix/APPLY_PATCH',
20
- immutable: true
20
+ immutable: true,
21
+ outboundRoutes: {
22
+ todos: {
23
+ mode: 'dispatch',
24
+ type: 'syncTodosFromStorix',
25
+ mapPayload: ({ storixSnapshot }) => storixSnapshot.todos
26
+ },
27
+ selectedId: {
28
+ mode: 'commit',
29
+ type: 'SET_SELECTED_ID',
30
+ mapPayload: ({ storixSnapshot }) => storixSnapshot.selectedId
31
+ }
32
+ }
21
33
  });
22
34
  ```
23
35
 
36
+ ## v1 routing support
37
+
38
+ `createVuexBridge()` supports a minimal v1 routing model for Storix -> Vuex writes:
39
+
40
+ - default patch mode via `mutationType`
41
+ - per-key outbound routes with `patch`, `commit`, `dispatch`, or `custom`
42
+ - optional bridge-echo suppression via `suppressBridgeEcho`
43
+
44
+ This keeps simple integrations patch-based while allowing special keys to flow through Vuex business logic.
45
+
24
46
  Use `applyVuexPatchMutation()` inside your Vuex mutation to apply the incoming patch payload.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var vt=Symbol.for("preact-signals");function D(){if($>1)$--;else{for(var e,t=!1;z!==void 0;){var n=z;for(z=void 0,Z++;n!==void 0;){var o=n.o;if(n.o=void 0,n.f&=-3,!(8&n.f)&&st(n))try{n.c()}catch(c){t||(e=c,t=!0)}n=o}}if(Z=0,$--,t)throw e}}function L(e){if($>0)return e();$++;try{return e()}finally{D()}}var l=void 0;function rt(e){var t=l;l=void 0;try{return e()}finally{l=t}}var z=void 0,$=0,Z=0,q=0;function ot(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=vt;b.prototype.h=function(){return!0};b.prototype.S=function(e){var t=this,n=this.t;n!==e&&e.e===void 0&&(e.x=n,this.t=e,n!==void 0?n.e=e:rt(function(){var o;(o=t.W)==null||o.call(t)}))};b.prototype.U=function(e){var t=this;if(this.t!==void 0){var n=e.e,o=e.x;n!==void 0&&(n.x=o,e.e=void 0),o!==void 0&&(o.e=n,e.x=void 0),e===this.t&&(this.t=o,o===void 0&&rt(function(){var c;(c=t.Z)==null||c.call(t)}))}};b.prototype.subscribe=function(e){var t=this;return pt(function(){var n=t.value,o=l;l=void 0;try{e(n)}finally{l=o}},{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=ot(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(Z>100)throw new Error("Cycle detected");this.v=e,this.i++,q++,$++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{D()}}}});function dt(e,t){return new b(e,t)}function st(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 at(e){for(var t=e.s;t!==void 0;t=t.n){var n=t.S.n;if(n!==void 0&&(t.r=n),t.S.n=t,t.i=-1,t.n===void 0){e.s=t;break}}}function ft(e){for(var t=e.s,n=void 0;t!==void 0;){var o=t.p;t.i===-1?(t.S.U(t),o!==void 0&&(o.n=t.n),t.n!==void 0&&(t.n.p=o)):n=t,t.S.n=t.r,t.r!==void 0&&(t.r=void 0),t=o}e.s=n}function N(e,t){b.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}N.prototype=new b;N.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&&!st(this))return this.f&=-2,!0;var e=l;try{at(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(n){this.v=n,this.f|=16,this.i++}return l=e,ft(this),this.f&=-2,!0};N.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)};N.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)}};N.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(N.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=ot(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 N(e,t)}function ut(e){var t=e.u;if(e.u=void 0,typeof t=="function"){$++;var n=l;l=void 0;try{t()}catch(o){throw e.f&=-2,e.f|=8,K(e),o}finally{l=n,D()}}}function K(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,ut(e)}function yt(e){if(l!==this)throw new Error("Out-of-order effect");ft(this),l=e,this.f&=-2,8&this.f&&K(this),D()}function A(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}A.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()}};A.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,ut(this),at(this),$++;var e=l;return l=this,yt.bind(this,e)};A.prototype.N=function(){2&this.f||(this.f|=2,this.o=z,z=this)};A.prototype.d=function(){this.f|=8,1&this.f||K(this)};A.prototype.dispose=function(){this.d()};function pt(e,t){var n=new A(e,t);try{n.c()}catch(c){throw n.d(),c}var o=n.d.bind(n);return o[Symbol.dispose]=o,o}const et=e=>e!==null&&typeof e=="object"&&!Array.isArray(e);function H(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 n=0;n<e.length;n+=1)if(!H(e[n],t[n]))return!1;return!0}if(et(e)&&et(t)){const n=Object.keys(e),o=Object.keys(t);if(n.length!==o.length)return!1;for(const c of n)if(!(c in t)||!H(e[c],t[c]))return!1;return!0}return!1}function Y(e){if(typeof structuredClone=="function")return structuredClone(e);try{return JSON.parse(JSON.stringify(e))}catch{return e}}function nt(e,t,n=Object.is,o=Y){const c={};for(const[h,d]of Object.entries(t)){const S=e[h];n(S,d,h)||(c[h]=o(d))}return c}function gt(e){const t=e.projectExternalToStore??(y=>y),n=e.projectStoreToExternal??(y=>y),o=e.equals??H,c=e.clone??Y,h=e.externalMutationOrigin??"local";let d=!1,S=!1,E=!1;const C=y=>Object.keys(y).length>0,R=()=>{if(d||E)return;const y=c(t(e.getExternalState())),U=e.store.$snapshot(),j=nt(U,y,o,c);if(C(j)){S=!0;try{e.store.$patch(j,h)}finally{S=!1}}},m=()=>{if(d||S)return;const y=c(n(e.store.$snapshot())),U=c(t(e.getExternalState())),j=nt(U,y,o,c);if(C(j)){E=!0;try{e.applyExternalPatch(j)}finally{E=!1}}},F=e.subscribeExternal(R),p=e.store.$subscribe(()=>{m()});return R(),{dispose(){d||(d=!0,F(),p())},syncFromExternal:R,syncFromStore:m}}function bt(e={}){const t=(e.namespace??"default").trim()||"default",n=e.plugins??[],o=new Map;function c(h,d){return function(){var S;const E=`${t}:${h}`,C=o.get(h);if(C)return C;const R=d.state(),m=d.modules??{},F={...R};for(const[r,i]of Object.entries(m))F[r]=i.state();const p=dt(F),y=new Map,U=new Map,j=new Map,T=new Map,O=new Map,W=new Set,V=new Set(Object.keys(R)),J=new Set(Object.keys(d.getters??{})),B=new Set(Object.keys(d.actions??{})),k=r=>p.value[r]??{},lt=(r,i)=>{p.value={...p.value,[r]:i}},ht=new Proxy({},{get(r,i){var a,f;if(y.has(i))return(a=y.get(i))==null?void 0:a.value;if(O.has(i))return(f=O.get(i))==null?void 0:f.value;if(V.has(i))return p.value[i];const v=T.get(i);return v?k(v.moduleName)[v.key]:p.value[i]}});for(const[r,i]of Object.entries(d.getters??{}))y.set(r,tt(()=>i(p.value,ht)));const _=(r,i)=>{var a;for(const f of W)f(r);for(const f of n)(a=f.onMutation)==null||a.call(f,i,r)},G=(r,i,a,f)=>{const v=p.value[r];Object.is(v,i)||(p.value={...p.value,[r]:i},_({namespace:t,scopeId:E,storeId:h,key:r,oldValue:v,newValue:i,origin:a},f))},I=(r,i,a,f,v)=>{const g=k(r),s=g[i];Object.is(s,a)||(lt(r,{...g,[i]:a}),_({namespace:t,scopeId:E,storeId:h,key:`${r}.${i}`,oldValue:s,newValue:a,origin:f},v))},M={$id:h,$namespace:t,$scopeId:E,$subscribe(r){return W.add(r),()=>W.delete(r)},$dispose(){var r;W.clear();for(const i of n)(r=i.onDispose)==null||r.call(i,x);o.delete(h)},$patch(r,i="local"){L(()=>{for(const[a,f]of Object.entries(r)){const v=T.get(a);if(v){I(v.moduleName,v.key,f,i,x);continue}if(a.includes(".")){const[g,s]=a.split(".",2);if(m[g]){I(g,s,f,i,x);continue}}if(m[a]&&f&&typeof f=="object"&&!Array.isArray(f)){for(const[g,s]of Object.entries(f))I(a,g,s,i,x);continue}G(a,f,i,x)}})},$snapshot(){return{...p.value}}};for(const[r,i]of Object.entries(m)){const a=new Map,f=new Map,v=new Proxy({},{get(s,u){var w,P,Q;if(a.has(u))return(w=a.get(u))==null?void 0:w.value;if(y.has(u))return(P=y.get(u))==null?void 0:P.value;if(O.has(u))return(Q=O.get(u))==null?void 0:Q.value;const X=k(r);if(u in X)return X[u];if(V.has(u))return p.value[u]}});for(const[s,u]of Object.entries(i.getters??{}))a.set(s,tt(()=>u(k(r),p.value,v)));let g;for(const[s,u]of Object.entries(i.actions??{}))f.set(s,(...w)=>L(()=>u.apply(g,w)));g=new Proxy({},{get(s,u){var w;if(f.has(u))return f.get(u);if(a.has(u))return(w=a.get(u))==null?void 0:w.value;const P=k(r);return u in P?P[u]:x[u]},set(s,u,w){if(f.has(u)||a.has(u))return!1;const P=k(r);return u in P?I(r,u,w,"local",x):x[u]=w,!0}}),j.set(r,g),U.set(r,a);for(const s of Object.keys(k(r)))!(V.has(s)||J.has(s)||B.has(s)||Reflect.has(M,s)||m[s]!==void 0)&&!T.has(s)&&T.set(s,{moduleName:r,key:s});for(const[s,u]of a.entries())!(V.has(s)||J.has(s)||B.has(s)||Reflect.has(M,s)||m[s]!==void 0)&&!O.has(s)&&O.set(s,u);for(const[s,u]of f.entries())!(V.has(s)||J.has(s)||B.has(s)||Reflect.has(M,s)||m[s]!==void 0)&&!Reflect.has(M,s)&&(M[s]=u)}const x=new Proxy(M,{get(r,i,a){var f,v;if(Reflect.has(r,i))return Reflect.get(r,i,a);if(j.has(i))return j.get(i);if(y.has(i))return(f=y.get(i))==null?void 0:f.value;if(O.has(i))return(v=O.get(i))==null?void 0:v.value;if(V.has(i))return p.value[i];const g=T.get(i);return g?k(g.moduleName)[g.key]:p.value[i]},set(r,i,a,f){if(Reflect.has(r,i))return Reflect.set(r,i,a,f);const v=T.get(i);return v?(I(v.moduleName,v.key,a,"local",f),!0):(G(i,a,"local",f),!0)}});for(const[r,i]of Object.entries(d.actions??{}))M[r]=(...a)=>L(()=>i.apply(x,a));for(const r of n)(S=r.onInit)==null||S.call(r,x);return o.set(h,x),x}}return{defineStore:c,use(h){n.push(h)}}}bt();const it=e=>e!==null&&typeof e=="object";function ct(e){if(!it(e))return e;const t=new WeakSet,n=o=>{if(!it(o))return;const c=o;if(t.has(c))return;t.add(c);const h=Reflect.ownKeys(c);for(const d of h){const S=Reflect.get(c,d);n(S)}Object.freeze(c)};return n(e),e}function xt(e,t){for(const[n,o]of Object.entries(t))e[n]=o}function St(e){const t=e.mutationType??"storix/APPLY_PATCH",n=e.immutable??!0,o=e.clone??Y,c=h=>{const d=o(h);return n?ct(d):d};return gt({store:e.store,getExternalState:()=>e.vuex.state,subscribeExternal:h=>e.vuex.subscribe(()=>h()),applyExternalPatch:h=>{e.vuex.commit(t,c(h))},projectExternalToStore:e.projectVuexToStorix,projectStoreToExternal:e.projectStorixToVuex,equals:e.equals,clone:c,externalMutationOrigin:e.externalMutationOrigin??"local"})}exports.applyVuexPatchMutation=xt;exports.createVuexBridge=St;exports.deepFreeze=ct;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var pt=Symbol.for("preact-signals");function H(){if(E>1)E--;else{for(var t,e=!1;J!==void 0;){var r=J;for(J=void 0,G++;r!==void 0;){var s=r.o;if(r.o=void 0,r.f&=-3,!(8&r.f)&&ct(r))try{r.c()}catch(h){e||(t=h,e=!0)}r=s}}if(G=0,E--,e)throw t}}function Y(t){if(E>0)return t();E++;try{return t()}finally{H()}}var l=void 0;function at(t){var e=l;l=void 0;try{return t()}finally{l=e}}var J=void 0,E=0,G=0,Z=0;function ut(t){if(l!==void 0){var e=t.n;if(e===void 0||e.t!==l)return e={i:0,S:t,p:l.s,n:void 0,t:l,e:void 0,x:void 0,r:e},l.s!==void 0&&(l.s.n=e),l.s=e,t.n=e,32&l.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=l.s,e.n=void 0,l.s.n=e,l.s=e),e}}function S(t,e){this.v=t,this.i=0,this.n=void 0,this.t=void 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}S.prototype.brand=pt;S.prototype.h=function(){return!0};S.prototype.S=function(t){var e=this,r=this.t;r!==t&&t.e===void 0&&(t.x=r,this.t=t,r!==void 0?r.e=t:at(function(){var s;(s=e.W)==null||s.call(e)}))};S.prototype.U=function(t){var e=this;if(this.t!==void 0){var r=t.e,s=t.x;r!==void 0&&(r.x=s,t.e=void 0),s!==void 0&&(s.e=r,t.x=void 0),t===this.t&&(this.t=s,s===void 0&&at(function(){var h;(h=e.Z)==null||h.call(e)}))}};S.prototype.subscribe=function(t){var e=this;return bt(function(){var r=e.value,s=l;l=void 0;try{t(r)}finally{l=s}},{name:"sub"})};S.prototype.valueOf=function(){return this.value};S.prototype.toString=function(){return this.value+""};S.prototype.toJSON=function(){return this.value};S.prototype.peek=function(){var t=l;l=void 0;try{return this.value}finally{l=t}};Object.defineProperty(S.prototype,"value",{get:function(){var t=ut(this);return t!==void 0&&(t.i=this.i),this.v},set:function(t){if(t!==this.v){if(G>100)throw new Error("Cycle detected");this.v=t,this.i++,Z++,E++;try{for(var e=this.t;e!==void 0;e=e.x)e.t.N()}finally{H()}}}});function yt(t,e){return new S(t,e)}function ct(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 ft(t){for(var e=t.s;e!==void 0;e=e.n){var r=e.S.n;if(r!==void 0&&(e.r=r),e.S.n=e,e.i=-1,e.n===void 0){t.s=e;break}}}function lt(t){for(var e=t.s,r=void 0;e!==void 0;){var s=e.p;e.i===-1?(e.S.U(e),s!==void 0&&(s.n=e.n),e.n!==void 0&&(e.n.p=s)):r=e,e.S.n=e.r,e.r!==void 0&&(e.r=void 0),e=s}t.s=r}function B(t,e){S.call(this,void 0),this.x=t,this.s=void 0,this.g=Z-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}B.prototype=new S;B.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===Z))return!0;if(this.g=Z,this.f|=1,this.i>0&&!ct(this))return this.f&=-2,!0;var t=l;try{ft(this),l=this;var e=this.x();(16&this.f||this.v!==e||this.i===0)&&(this.v=e,this.f&=-17,this.i++)}catch(r){this.v=r,this.f|=16,this.i++}return l=t,lt(this),this.f&=-2,!0};B.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)}S.prototype.S.call(this,t)};B.prototype.U=function(t){if(this.t!==void 0&&(S.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)}};B.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(B.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var t=ut(this);if(this.h(),t!==void 0&&(t.i=this.i),16&this.f)throw this.v;return this.v}});function rt(t,e){return new B(t,e)}function ht(t){var e=t.u;if(t.u=void 0,typeof e=="function"){E++;var r=l;l=void 0;try{e()}catch(s){throw t.f&=-2,t.f|=8,X(t),s}finally{l=r,H()}}}function X(t){for(var e=t.s;e!==void 0;e=e.n)e.S.U(e);t.x=void 0,t.s=void 0,ht(t)}function gt(t){if(l!==this)throw new Error("Out-of-order effect");lt(this),l=t,this.f&=-2,8&this.f&&X(this),H()}function D(t,e){this.x=t,this.u=void 0,this.s=void 0,this.o=void 0,this.f=32,this.name=e==null?void 0:e.name}D.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.u=e)}finally{t()}};D.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,ht(this),ft(this),E++;var t=l;return l=this,gt.bind(this,t)};D.prototype.N=function(){2&this.f||(this.f|=2,this.o=J,J=this)};D.prototype.d=function(){this.f|=8,1&this.f||X(this)};D.prototype.dispose=function(){this.d()};function bt(t,e){var r=new D(t,e);try{r.c()}catch(h){throw r.d(),h}var s=r.d.bind(r);return s[Symbol.dispose]=s,s}const nt=t=>t!==null&&typeof t=="object"&&!Array.isArray(t);function Q(t,e){if(Object.is(t,e))return!0;if(t instanceof Date&&e instanceof Date)return t.getTime()===e.getTime();if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return!1;for(let r=0;r<t.length;r+=1)if(!Q(t[r],e[r]))return!1;return!0}if(nt(t)&&nt(e)){const r=Object.keys(t),s=Object.keys(e);if(r.length!==s.length)return!1;for(const h of r)if(!(h in e)||!Q(t[h],e[h]))return!1;return!0}return!1}function dt(t){if(typeof structuredClone=="function")return structuredClone(t);try{return JSON.parse(JSON.stringify(t))}catch{return t}}function it(t,e,r=Object.is,s=dt){const h={};for(const[y,w]of Object.entries(e)){const T=t[y];r(T,w,y)||(h[y]=s(w))}return h}function xt(t={}){const e=(t.namespace??"default").trim()||"default",r=t.plugins??[],s=new Map;function h(y,w){return function(){var T;const C=`${e}:${y}`,_=s.get(y);if(_)return _;const A=w.state(),j=w.modules??{},U={...A};for(const[i,n]of Object.entries(j))U[i]=n.state();const g=yt(U),m=new Map,F=new Map,q=new Map,$=new Map,P=new Map,z=new Set,N=new Set(Object.keys(A)),L=new Set(Object.keys(w.getters??{})),W=new Set(Object.keys(w.actions??{})),o=i=>g.value[i]??{},d=(i,n)=>{g.value={...g.value,[i]:n}},p=new Proxy({},{get(i,n){var u,c;if(m.has(n))return(u=m.get(n))==null?void 0:u.value;if(P.has(n))return(c=P.get(n))==null?void 0:c.value;if(N.has(n))return g.value[n];const v=$.get(n);return v?o(v.moduleName)[v.key]:g.value[n]}});for(const[i,n]of Object.entries(w.getters??{}))m.set(i,rt(()=>n(g.value,p)));const b=(i,n)=>{var u;for(const c of z)c(i);for(const c of r)(u=c.onMutation)==null||u.call(c,n,i)},O=(i,n,u,c)=>{const v=g.value[i];Object.is(v,n)||(g.value={...g.value,[i]:n},b({namespace:e,scopeId:C,storeId:y,key:i,oldValue:v,newValue:n,origin:u},c))},M=(i,n,u,c,v)=>{const x=o(i),a=x[n];Object.is(a,u)||(d(i,{...x,[n]:u}),b({namespace:e,scopeId:C,storeId:y,key:`${i}.${n}`,oldValue:a,newValue:u,origin:c},v))},V={$id:y,$namespace:e,$scopeId:C,$subscribe(i){return z.add(i),()=>z.delete(i)},$dispose(){var i;z.clear();for(const n of r)(i=n.onDispose)==null||i.call(n,k);s.delete(y)},$patch(i,n="local"){Y(()=>{for(const[u,c]of Object.entries(i)){const v=$.get(u);if(v){M(v.moduleName,v.key,c,n,k);continue}if(u.includes(".")){const[x,a]=u.split(".",2);if(j[x]){M(x,a,c,n,k);continue}}if(j[u]&&c&&typeof c=="object"&&!Array.isArray(c)){for(const[x,a]of Object.entries(c))M(u,x,a,n,k);continue}O(u,c,n,k)}})},$snapshot(){return{...g.value}}};for(const[i,n]of Object.entries(j)){const u=new Map,c=new Map,v=new Proxy({},{get(a,f){var R,I,tt;if(u.has(f))return(R=u.get(f))==null?void 0:R.value;if(m.has(f))return(I=m.get(f))==null?void 0:I.value;if(P.has(f))return(tt=P.get(f))==null?void 0:tt.value;const et=o(i);if(f in et)return et[f];if(N.has(f))return g.value[f]}});for(const[a,f]of Object.entries(n.getters??{}))u.set(a,rt(()=>f(o(i),g.value,v)));let x;for(const[a,f]of Object.entries(n.actions??{}))c.set(a,(...R)=>Y(()=>f.apply(x,R)));x=new Proxy({},{get(a,f){var R;if(c.has(f))return c.get(f);if(u.has(f))return(R=u.get(f))==null?void 0:R.value;const I=o(i);return f in I?I[f]:k[f]},set(a,f,R){if(c.has(f)||u.has(f))return!1;const I=o(i);return f in I?M(i,f,R,"local",k):k[f]=R,!0}}),q.set(i,x),F.set(i,u);for(const a of Object.keys(o(i)))!(N.has(a)||L.has(a)||W.has(a)||Reflect.has(V,a)||j[a]!==void 0)&&!$.has(a)&&$.set(a,{moduleName:i,key:a});for(const[a,f]of u.entries())!(N.has(a)||L.has(a)||W.has(a)||Reflect.has(V,a)||j[a]!==void 0)&&!P.has(a)&&P.set(a,f);for(const[a,f]of c.entries())!(N.has(a)||L.has(a)||W.has(a)||Reflect.has(V,a)||j[a]!==void 0)&&!Reflect.has(V,a)&&(V[a]=f)}const k=new Proxy(V,{get(i,n,u){var c,v;if(Reflect.has(i,n))return Reflect.get(i,n,u);if(q.has(n))return q.get(n);if(m.has(n))return(c=m.get(n))==null?void 0:c.value;if(P.has(n))return(v=P.get(n))==null?void 0:v.value;if(N.has(n))return g.value[n];const x=$.get(n);return x?o(x.moduleName)[x.key]:g.value[n]},set(i,n,u,c){if(Reflect.has(i,n))return Reflect.set(i,n,u,c);const v=$.get(n);return v?(M(v.moduleName,v.key,u,"local",c),!0):(O(n,u,"local",c),!0)}});for(const[i,n]of Object.entries(w.actions??{}))V[i]=(...u)=>Y(()=>n.apply(k,u));for(const i of r)(T=i.onInit)==null||T.call(i,k);return s.set(y,k),k}}return{defineStore:h,use(y){r.push(y)}}}xt();const K=t=>t!==null&&typeof t=="object";function vt(t){if(!K(t))return t;const e=new WeakSet,r=s=>{if(!K(s))return;const h=s;if(e.has(h))return;e.add(h);const y=Reflect.ownKeys(h);for(const w of y){const T=Reflect.get(h,w);r(T)}Object.freeze(h)};return r(t),t}function St(t,e){for(const[r,s]of Object.entries(e))t[r]=s}const ot=t=>Object.keys(t).length>0,st=t=>t?Array.isArray(t)?t:[t]:[],wt=t=>{const e=[t];if(t.includes(".")){const r=t.split(".",1)[0];r&&r!==t&&e.push(r)}return e},mt=(t,e)=>{if(!e||!K(t))return t;try{Object.defineProperty(t,e,{value:!0,enumerable:!1,configurable:!0})}catch{return t}return t};function jt(t){const e=t.mutationType??"storix/APPLY_PATCH",r=t.immutable??!0,s=t.clone??dt,h=t.equals??Q,y=t.projectVuexToStorix??(o=>o),w=t.projectStorixToVuex??(o=>o),T=t.suppressBridgeEcho??!1,C=t.bridgeOriginKey??"__storixBridge",_=t.outboundDefault??{mode:"patch",type:e},A=o=>{const d=s(o);return r?vt(d):d};let j=!1,U=!1,g=!1;const m=new Map,F=o=>{if(T)for(const d of o){const p=m.get(d)??0;m.set(d,p+1)}},q=o=>{if(!T||!K(o))return!1;const d=Reflect.get(o,"payload");if(C&&K(d)&&Reflect.get(d,C))return!0;const p=Reflect.get(o,"type");if(typeof p!="string")return!1;const b=m.get(p)??0;return b<=0?!1:(b===1?m.delete(p):m.set(p,b-1),!0)},$=()=>{if(j||g)return;const o=A(y(t.vuex.state)),d=t.store.$snapshot(),p=it(d,o,h,A);if(ot(p)){U=!0;try{t.store.$patch(p,t.externalMutationOrigin??"local")}finally{U=!1}}},P=o=>{const p=wt(o.storixMutation.key).flatMap(b=>{var O;return st((O=t.outboundRoutes)==null?void 0:O[b])});return p.push(...st(_)),p.find(b=>b.when?b.when(o):!0)},z=(o,d)=>{var M;if(o.mode==="custom"){(M=o.handler)==null||M.call(o,d),F(o.suppressMutationTypes??[]);return}const p=(o.mode==="patch",d.projectedPatch),b=mt(A(o.mapPayload?o.mapPayload(d):p),C);if(o.mode==="dispatch"){if(typeof t.vuex.dispatch!="function")throw new Error('Vuex bridge route mode "dispatch" requires vuex.dispatch to be available.');if(!o.type)throw new Error('Vuex bridge dispatch route requires a "type".');t.vuex.dispatch(o.type,b),F(o.suppressMutationTypes??[]);return}const O=o.type??e;t.vuex.commit(O,b),F(o.suppressMutationTypes??[O])},N=o=>{if(j||U)return;const d=t.store.$snapshot(),p=A(w(d)),b=A(y(t.vuex.state)),O=it(b,p,h,A);if(!ot(O))return;const M={storixMutation:o??{namespace:t.store.$namespace,scopeId:t.store.$scopeId,storeId:t.store.$id,key:Object.keys(O)[0]??"*",oldValue:void 0,newValue:void 0,origin:"local"},storixSnapshot:d,vuexState:t.vuex.state,projectedPatch:O,projectedVuexState:p,origin:"storix"},V=P(M);if(V){g=!0;try{z(V,M)}finally{g=!1}}},L=t.vuex.subscribe(o=>{q(o)||$()}),W=t.store.$subscribe(o=>{N(o)});return $(),{dispose(){j||(j=!0,L(),W())},syncFromExternal:$,syncFromStore(){N()}}}exports.applyVuexPatchMutation=St;exports.createVuexBridge=jt;exports.deepFreeze=vt;
package/dist/index.d.ts CHANGED
@@ -1,9 +1,27 @@
1
- import { type ExternalStoreBridgeHandle, type StoreInstance } from '@storix-js/core';
1
+ import { type ExternalStoreBridgeHandle, type MutationPayload, type StoreInstance } from '@storix-js/core';
2
2
  type AnyObject = Record<string, unknown>;
3
3
  export interface VuexLikeStore<TState extends AnyObject> {
4
4
  state: TState;
5
5
  subscribe(listener: (mutation: unknown, state: TState) => void): () => void;
6
6
  commit(type: string, payload?: unknown): void;
7
+ dispatch?(type: string, payload?: unknown): unknown;
8
+ }
9
+ export type VuexOutboundMode = 'patch' | 'commit' | 'dispatch' | 'custom';
10
+ export interface VuexRouteContext<TVuexState extends AnyObject> {
11
+ storixMutation: MutationPayload;
12
+ storixSnapshot: Record<string, unknown>;
13
+ vuexState: TVuexState;
14
+ projectedPatch: Record<string, unknown>;
15
+ projectedVuexState: Record<string, unknown>;
16
+ origin: 'storix' | 'vuex';
17
+ }
18
+ export interface VuexOutboundRoute<TVuexState extends AnyObject> {
19
+ mode: VuexOutboundMode;
20
+ type?: string;
21
+ when?: (context: VuexRouteContext<TVuexState>) => boolean;
22
+ mapPayload?: (context: VuexRouteContext<TVuexState>) => unknown;
23
+ handler?: (context: VuexRouteContext<TVuexState>) => void | Promise<void>;
24
+ suppressMutationTypes?: string[];
7
25
  }
8
26
  export interface CreateVuexBridgeOptions<TVuexState extends AnyObject> {
9
27
  store: StoreInstance;
@@ -15,6 +33,10 @@ export interface CreateVuexBridgeOptions<TVuexState extends AnyObject> {
15
33
  clone?: <T>(value: T) => T;
16
34
  immutable?: boolean;
17
35
  externalMutationOrigin?: 'local' | 'remote';
36
+ outboundDefault?: VuexOutboundRoute<TVuexState>;
37
+ outboundRoutes?: Record<string, VuexOutboundRoute<TVuexState> | Array<VuexOutboundRoute<TVuexState>>>;
38
+ suppressBridgeEcho?: boolean;
39
+ bridgeOriginKey?: string;
18
40
  }
19
41
  export declare function deepFreeze<T>(value: T): T;
20
42
  export declare function applyVuexPatchMutation<TState extends AnyObject>(state: TState, patch: Record<string, unknown>): void;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,yBAAyB,EAC9B,KAAK,aAAa,EACnB,MAAM,iBAAiB,CAAC;AAEzB,KAAK,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEzC,MAAM,WAAW,aAAa,CAAC,MAAM,SAAS,SAAS;IACrD,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IAC5E,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CAC/C;AAED,MAAM,WAAW,uBAAuB,CAAC,UAAU,SAAS,SAAS;IACnE,KAAK,EAAE,aAAa,CAAC;IACrB,IAAI,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;IAChC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,mBAAmB,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrE,mBAAmB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrF,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;IACnE,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC;IAC3B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,sBAAsB,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;CAC7C;AAMD,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAuBzC;AAED,wBAAgB,sBAAsB,CAAC,MAAM,SAAS,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,QAI7G;AAED,wBAAgB,gBAAgB,CAAC,UAAU,SAAS,SAAS,EAC3D,OAAO,EAAE,uBAAuB,CAAC,UAAU,CAAC,GAC3C,yBAAyB,CA0B3B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,yBAAyB,EAC9B,KAAK,eAAe,EACpB,KAAK,aAAa,EACnB,MAAM,iBAAiB,CAAC;AAEzB,KAAK,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEzC,MAAM,WAAW,aAAa,CAAC,MAAM,SAAS,SAAS;IACrD,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IAC5E,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC9C,QAAQ,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;CACrD;AAED,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,QAAQ,GAAG,UAAU,GAAG,QAAQ,CAAC;AAE1E,MAAM,WAAW,gBAAgB,CAAC,UAAU,SAAS,SAAS;IAC5D,cAAc,EAAE,eAAe,CAAC;IAChC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,SAAS,EAAE,UAAU,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC5C,MAAM,EAAE,QAAQ,GAAG,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,iBAAiB,CAAC,UAAU,SAAS,SAAS;IAC7D,IAAI,EAAE,gBAAgB,CAAC;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,gBAAgB,CAAC,UAAU,CAAC,KAAK,OAAO,CAAC;IAC1D,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,gBAAgB,CAAC,UAAU,CAAC,KAAK,OAAO,CAAC;IAChE,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,gBAAgB,CAAC,UAAU,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1E,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;CAClC;AAED,MAAM,WAAW,uBAAuB,CAAC,UAAU,SAAS,SAAS;IACnE,KAAK,EAAE,aAAa,CAAC;IACrB,IAAI,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;IAChC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,mBAAmB,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrE,mBAAmB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrF,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;IACnE,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC;IAC3B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,sBAAsB,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;IAC5C,eAAe,CAAC,EAAE,iBAAiB,CAAC,UAAU,CAAC,CAAC;IAChD,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,UAAU,CAAC,GAAG,KAAK,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IACtG,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAMD,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAuBzC;AAED,wBAAgB,sBAAsB,CAAC,MAAM,SAAS,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,QAI7G;AAuCD,wBAAgB,gBAAgB,CAAC,UAAU,SAAS,SAAS,EAC3D,OAAO,EAAE,uBAAuB,CAAC,UAAU,CAAC,GAC3C,yBAAyB,CA4K3B"}
package/dist/index.js CHANGED
@@ -1,560 +1,626 @@
1
- var ht = Symbol.for("preact-signals");
2
- function F() {
3
- if ($ > 1)
4
- $--;
1
+ var vt = Symbol.for("preact-signals");
2
+ function H() {
3
+ if (E > 1)
4
+ E--;
5
5
  else {
6
- for (var e, t = !1; W !== void 0; ) {
7
- var n = W;
8
- for (W = void 0, B++; n !== void 0; ) {
9
- var o = n.o;
10
- if (n.o = void 0, n.f &= -3, !(8 & n.f) && st(n)) try {
6
+ for (var t, e = !1; J !== void 0; ) {
7
+ var n = J;
8
+ for (J = void 0, G++; n !== void 0; ) {
9
+ var s = n.o;
10
+ if (n.o = void 0, n.f &= -3, !(8 & n.f) && ut(n)) try {
11
11
  n.c();
12
- } catch (c) {
13
- t || (e = c, t = !0);
12
+ } catch (h) {
13
+ e || (t = h, e = !0);
14
14
  }
15
- n = o;
15
+ n = s;
16
16
  }
17
17
  }
18
- if (B = 0, $--, t) throw e;
18
+ if (G = 0, E--, e) throw t;
19
19
  }
20
20
  }
21
- function Z(e) {
22
- if ($ > 0) return e();
23
- $++;
21
+ function Y(t) {
22
+ if (E > 0) return t();
23
+ E++;
24
24
  try {
25
- return e();
25
+ return t();
26
26
  } finally {
27
- F();
27
+ H();
28
28
  }
29
29
  }
30
30
  var l = void 0;
31
- function rt(e) {
32
- var t = l;
31
+ function at(t) {
32
+ var e = l;
33
33
  l = void 0;
34
34
  try {
35
- return e();
35
+ return t();
36
36
  } finally {
37
- l = t;
37
+ l = e;
38
38
  }
39
39
  }
40
- var W = void 0, $ = 0, B = 0, D = 0;
41
- function ot(e) {
40
+ var J = void 0, E = 0, G = 0, Z = 0;
41
+ function ct(t) {
42
42
  if (l !== void 0) {
43
- var t = e.n;
44
- if (t === void 0 || t.t !== l)
45
- 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;
46
- if (t.i === -1)
47
- 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;
43
+ var e = t.n;
44
+ if (e === void 0 || e.t !== l)
45
+ return e = { i: 0, S: t, p: l.s, n: void 0, t: l, e: void 0, x: void 0, r: e }, l.s !== void 0 && (l.s.n = e), l.s = e, t.n = e, 32 & l.f && t.S(e), e;
46
+ if (e.i === -1)
47
+ return e.i = 0, e.n !== void 0 && (e.n.p = e.p, e.p !== void 0 && (e.p.n = e.n), e.p = l.s, e.n = void 0, l.s.n = e, l.s = e), e;
48
48
  }
49
49
  }
50
- function b(e, t) {
51
- 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;
50
+ function w(t, e) {
51
+ this.v = t, this.i = 0, this.n = void 0, this.t = void 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
52
  }
53
- b.prototype.brand = ht;
54
- b.prototype.h = function() {
53
+ w.prototype.brand = vt;
54
+ w.prototype.h = function() {
55
55
  return !0;
56
56
  };
57
- b.prototype.S = function(e) {
58
- var t = this, n = this.t;
59
- n !== e && e.e === void 0 && (e.x = n, this.t = e, n !== void 0 ? n.e = e : rt(function() {
60
- var o;
61
- (o = t.W) == null || o.call(t);
57
+ w.prototype.S = function(t) {
58
+ var e = this, n = this.t;
59
+ n !== t && t.e === void 0 && (t.x = n, this.t = t, n !== void 0 ? n.e = t : at(function() {
60
+ var s;
61
+ (s = e.W) == null || s.call(e);
62
62
  }));
63
63
  };
64
- b.prototype.U = function(e) {
65
- var t = this;
64
+ w.prototype.U = function(t) {
65
+ var e = this;
66
66
  if (this.t !== void 0) {
67
- var n = e.e, o = e.x;
68
- n !== void 0 && (n.x = o, e.e = void 0), o !== void 0 && (o.e = n, e.x = void 0), e === this.t && (this.t = o, o === void 0 && rt(function() {
69
- var c;
70
- (c = t.Z) == null || c.call(t);
67
+ var n = t.e, s = t.x;
68
+ n !== void 0 && (n.x = s, t.e = void 0), s !== void 0 && (s.e = n, t.x = void 0), t === this.t && (this.t = s, s === void 0 && at(function() {
69
+ var h;
70
+ (h = e.Z) == null || h.call(e);
71
71
  }));
72
72
  }
73
73
  };
74
- b.prototype.subscribe = function(e) {
75
- var t = this;
76
- return yt(function() {
77
- var n = t.value, o = l;
74
+ w.prototype.subscribe = function(t) {
75
+ var e = this;
76
+ return gt(function() {
77
+ var n = e.value, s = l;
78
78
  l = void 0;
79
79
  try {
80
- e(n);
80
+ t(n);
81
81
  } finally {
82
- l = o;
82
+ l = s;
83
83
  }
84
84
  }, { name: "sub" });
85
85
  };
86
- b.prototype.valueOf = function() {
86
+ w.prototype.valueOf = function() {
87
87
  return this.value;
88
88
  };
89
- b.prototype.toString = function() {
89
+ w.prototype.toString = function() {
90
90
  return this.value + "";
91
91
  };
92
- b.prototype.toJSON = function() {
92
+ w.prototype.toJSON = function() {
93
93
  return this.value;
94
94
  };
95
- b.prototype.peek = function() {
96
- var e = l;
95
+ w.prototype.peek = function() {
96
+ var t = l;
97
97
  l = void 0;
98
98
  try {
99
99
  return this.value;
100
100
  } finally {
101
- l = e;
101
+ l = t;
102
102
  }
103
103
  };
104
- Object.defineProperty(b.prototype, "value", { get: function() {
105
- var e = ot(this);
106
- return e !== void 0 && (e.i = this.i), this.v;
107
- }, set: function(e) {
108
- if (e !== this.v) {
109
- if (B > 100) throw new Error("Cycle detected");
110
- this.v = e, this.i++, D++, $++;
104
+ Object.defineProperty(w.prototype, "value", { get: function() {
105
+ var t = ct(this);
106
+ return t !== void 0 && (t.i = this.i), this.v;
107
+ }, set: function(t) {
108
+ if (t !== this.v) {
109
+ if (G > 100) throw new Error("Cycle detected");
110
+ this.v = t, this.i++, Z++, E++;
111
111
  try {
112
- for (var t = this.t; t !== void 0; t = t.x) t.t.N();
112
+ for (var e = this.t; e !== void 0; e = e.x) e.t.N();
113
113
  } finally {
114
- F();
114
+ H();
115
115
  }
116
116
  }
117
117
  } });
118
- function vt(e, t) {
119
- return new b(e, t);
118
+ function pt(t, e) {
119
+ return new w(t, e);
120
120
  }
121
- function st(e) {
122
- 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;
121
+ function ut(t) {
122
+ 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
123
  return !1;
124
124
  }
125
- function at(e) {
126
- for (var t = e.s; t !== void 0; t = t.n) {
127
- var n = t.S.n;
128
- if (n !== void 0 && (t.r = n), t.S.n = t, t.i = -1, t.n === void 0) {
129
- e.s = t;
125
+ function ft(t) {
126
+ for (var e = t.s; e !== void 0; e = e.n) {
127
+ var n = e.S.n;
128
+ if (n !== void 0 && (e.r = n), e.S.n = e, e.i = -1, e.n === void 0) {
129
+ t.s = e;
130
130
  break;
131
131
  }
132
132
  }
133
133
  }
134
- function ft(e) {
135
- for (var t = e.s, n = void 0; t !== void 0; ) {
136
- var o = t.p;
137
- t.i === -1 ? (t.S.U(t), o !== void 0 && (o.n = t.n), t.n !== void 0 && (t.n.p = o)) : n = t, t.S.n = t.r, t.r !== void 0 && (t.r = void 0), t = o;
134
+ function lt(t) {
135
+ for (var e = t.s, n = void 0; e !== void 0; ) {
136
+ var s = e.p;
137
+ e.i === -1 ? (e.S.U(e), s !== void 0 && (s.n = e.n), e.n !== void 0 && (e.n.p = s)) : n = e, e.S.n = e.r, e.r !== void 0 && (e.r = void 0), e = s;
138
138
  }
139
- e.s = n;
139
+ t.s = n;
140
140
  }
141
- function R(e, t) {
142
- b.call(this, void 0), this.x = e, this.s = void 0, this.g = D - 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;
141
+ function B(t, e) {
142
+ w.call(this, void 0), this.x = t, this.s = void 0, this.g = Z - 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
143
  }
144
- R.prototype = new b();
145
- R.prototype.h = function() {
144
+ B.prototype = new w();
145
+ B.prototype.h = function() {
146
146
  if (this.f &= -3, 1 & this.f) return !1;
147
- if ((36 & this.f) == 32 || (this.f &= -5, this.g === D)) return !0;
148
- if (this.g = D, this.f |= 1, this.i > 0 && !st(this))
147
+ if ((36 & this.f) == 32 || (this.f &= -5, this.g === Z)) return !0;
148
+ if (this.g = Z, this.f |= 1, this.i > 0 && !ut(this))
149
149
  return this.f &= -2, !0;
150
- var e = l;
150
+ var t = l;
151
151
  try {
152
- at(this), l = this;
153
- var t = this.x();
154
- (16 & this.f || this.v !== t || this.i === 0) && (this.v = t, this.f &= -17, this.i++);
152
+ ft(this), l = this;
153
+ var e = this.x();
154
+ (16 & this.f || this.v !== e || this.i === 0) && (this.v = e, this.f &= -17, this.i++);
155
155
  } catch (n) {
156
156
  this.v = n, this.f |= 16, this.i++;
157
157
  }
158
- return l = e, ft(this), this.f &= -2, !0;
158
+ return l = t, lt(this), this.f &= -2, !0;
159
159
  };
160
- R.prototype.S = function(e) {
160
+ B.prototype.S = function(t) {
161
161
  if (this.t === void 0) {
162
162
  this.f |= 36;
163
- for (var t = this.s; t !== void 0; t = t.n) t.S.S(t);
163
+ for (var e = this.s; e !== void 0; e = e.n) e.S.S(e);
164
164
  }
165
- b.prototype.S.call(this, e);
165
+ w.prototype.S.call(this, t);
166
166
  };
167
- R.prototype.U = function(e) {
168
- if (this.t !== void 0 && (b.prototype.U.call(this, e), this.t === void 0)) {
167
+ B.prototype.U = function(t) {
168
+ if (this.t !== void 0 && (w.prototype.U.call(this, t), this.t === void 0)) {
169
169
  this.f &= -33;
170
- for (var t = this.s; t !== void 0; t = t.n) t.S.U(t);
170
+ for (var e = this.s; e !== void 0; e = e.n) e.S.U(e);
171
171
  }
172
172
  };
173
- R.prototype.N = function() {
173
+ B.prototype.N = function() {
174
174
  if (!(2 & this.f)) {
175
175
  this.f |= 6;
176
- for (var e = this.t; e !== void 0; e = e.x) e.t.N();
176
+ for (var t = this.t; t !== void 0; t = t.x) t.t.N();
177
177
  }
178
178
  };
179
- Object.defineProperty(R.prototype, "value", { get: function() {
179
+ Object.defineProperty(B.prototype, "value", { get: function() {
180
180
  if (1 & this.f) throw new Error("Cycle detected");
181
- var e = ot(this);
182
- if (this.h(), e !== void 0 && (e.i = this.i), 16 & this.f) throw this.v;
181
+ var t = ct(this);
182
+ if (this.h(), t !== void 0 && (t.i = this.i), 16 & this.f) throw this.v;
183
183
  return this.v;
184
184
  } });
185
- function tt(e, t) {
186
- return new R(e, t);
185
+ function nt(t, e) {
186
+ return new B(t, e);
187
187
  }
188
- function ut(e) {
189
- var t = e.u;
190
- if (e.u = void 0, typeof t == "function") {
191
- $++;
188
+ function ht(t) {
189
+ var e = t.u;
190
+ if (t.u = void 0, typeof e == "function") {
191
+ E++;
192
192
  var n = l;
193
193
  l = void 0;
194
194
  try {
195
- t();
196
- } catch (o) {
197
- throw e.f &= -2, e.f |= 8, K(e), o;
195
+ e();
196
+ } catch (s) {
197
+ throw t.f &= -2, t.f |= 8, X(t), s;
198
198
  } finally {
199
- l = n, F();
199
+ l = n, H();
200
200
  }
201
201
  }
202
202
  }
203
- function K(e) {
204
- for (var t = e.s; t !== void 0; t = t.n) t.S.U(t);
205
- e.x = void 0, e.s = void 0, ut(e);
203
+ function X(t) {
204
+ for (var e = t.s; e !== void 0; e = e.n) e.S.U(e);
205
+ t.x = void 0, t.s = void 0, ht(t);
206
206
  }
207
- function dt(e) {
207
+ function yt(t) {
208
208
  if (l !== this) throw new Error("Out-of-order effect");
209
- ft(this), l = e, this.f &= -2, 8 & this.f && K(this), F();
209
+ lt(this), l = t, this.f &= -2, 8 & this.f && X(this), H();
210
210
  }
211
- function V(e, t) {
212
- 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;
211
+ function q(t, e) {
212
+ this.x = t, this.u = void 0, this.s = void 0, this.o = void 0, this.f = 32, this.name = e == null ? void 0 : e.name;
213
213
  }
214
- V.prototype.c = function() {
215
- var e = this.S();
214
+ q.prototype.c = function() {
215
+ var t = this.S();
216
216
  try {
217
217
  if (8 & this.f || this.x === void 0) return;
218
- var t = this.x();
219
- typeof t == "function" && (this.u = t);
218
+ var e = this.x();
219
+ typeof e == "function" && (this.u = e);
220
220
  } finally {
221
- e();
221
+ t();
222
222
  }
223
223
  };
224
- V.prototype.S = function() {
224
+ q.prototype.S = function() {
225
225
  if (1 & this.f) throw new Error("Cycle detected");
226
- this.f |= 1, this.f &= -9, ut(this), at(this), $++;
227
- var e = l;
228
- return l = this, dt.bind(this, e);
226
+ this.f |= 1, this.f &= -9, ht(this), ft(this), E++;
227
+ var t = l;
228
+ return l = this, yt.bind(this, t);
229
229
  };
230
- V.prototype.N = function() {
231
- 2 & this.f || (this.f |= 2, this.o = W, W = this);
230
+ q.prototype.N = function() {
231
+ 2 & this.f || (this.f |= 2, this.o = J, J = this);
232
232
  };
233
- V.prototype.d = function() {
234
- this.f |= 8, 1 & this.f || K(this);
233
+ q.prototype.d = function() {
234
+ this.f |= 8, 1 & this.f || X(this);
235
235
  };
236
- V.prototype.dispose = function() {
236
+ q.prototype.dispose = function() {
237
237
  this.d();
238
238
  };
239
- function yt(e, t) {
240
- var n = new V(e, t);
239
+ function gt(t, e) {
240
+ var n = new q(t, e);
241
241
  try {
242
242
  n.c();
243
- } catch (c) {
244
- throw n.d(), c;
243
+ } catch (h) {
244
+ throw n.d(), h;
245
245
  }
246
- var o = n.d.bind(n);
247
- return o[Symbol.dispose] = o, o;
246
+ var s = n.d.bind(n);
247
+ return s[Symbol.dispose] = s, s;
248
248
  }
249
- const et = (e) => e !== null && typeof e == "object" && !Array.isArray(e);
250
- function H(e, t) {
251
- if (Object.is(e, t)) return !0;
252
- if (e instanceof Date && t instanceof Date)
253
- return e.getTime() === t.getTime();
254
- if (Array.isArray(e) && Array.isArray(t)) {
255
- if (e.length !== t.length) return !1;
256
- for (let n = 0; n < e.length; n += 1)
257
- if (!H(e[n], t[n])) return !1;
249
+ const rt = (t) => t !== null && typeof t == "object" && !Array.isArray(t);
250
+ function Q(t, e) {
251
+ if (Object.is(t, e)) return !0;
252
+ if (t instanceof Date && e instanceof Date)
253
+ return t.getTime() === e.getTime();
254
+ if (Array.isArray(t) && Array.isArray(e)) {
255
+ if (t.length !== e.length) return !1;
256
+ for (let n = 0; n < t.length; n += 1)
257
+ if (!Q(t[n], e[n])) return !1;
258
258
  return !0;
259
259
  }
260
- if (et(e) && et(t)) {
261
- const n = Object.keys(e), o = Object.keys(t);
262
- if (n.length !== o.length) return !1;
263
- for (const c of n)
264
- if (!(c in t) || !H(e[c], t[c])) return !1;
260
+ if (rt(t) && rt(e)) {
261
+ const n = Object.keys(t), s = Object.keys(e);
262
+ if (n.length !== s.length) return !1;
263
+ for (const h of n)
264
+ if (!(h in e) || !Q(t[h], e[h])) return !1;
265
265
  return !0;
266
266
  }
267
267
  return !1;
268
268
  }
269
- function Y(e) {
269
+ function dt(t) {
270
270
  if (typeof structuredClone == "function")
271
- return structuredClone(e);
271
+ return structuredClone(t);
272
272
  try {
273
- return JSON.parse(JSON.stringify(e));
273
+ return JSON.parse(JSON.stringify(t));
274
274
  } catch {
275
- return e;
275
+ return t;
276
276
  }
277
277
  }
278
- function nt(e, t, n = Object.is, o = Y) {
279
- const c = {};
280
- for (const [h, d] of Object.entries(t)) {
281
- const w = e[h];
282
- n(w, d, h) || (c[h] = o(d));
278
+ function it(t, e, n = Object.is, s = dt) {
279
+ const h = {};
280
+ for (const [y, S] of Object.entries(e)) {
281
+ const T = t[y];
282
+ n(T, S, y) || (h[y] = s(S));
283
283
  }
284
- return c;
285
- }
286
- function pt(e) {
287
- const t = e.projectExternalToStore ?? ((y) => y), n = e.projectStoreToExternal ?? ((y) => y), o = e.equals ?? H, c = e.clone ?? Y, h = e.externalMutationOrigin ?? "local";
288
- let d = !1, w = !1, E = !1;
289
- const C = (y) => Object.keys(y).length > 0, P = () => {
290
- if (d || E) return;
291
- const y = c(t(e.getExternalState())), U = e.store.$snapshot(), j = nt(U, y, o, c);
292
- if (C(j)) {
293
- w = !0;
294
- try {
295
- e.store.$patch(j, h);
296
- } finally {
297
- w = !1;
298
- }
299
- }
300
- }, S = () => {
301
- if (d || w) return;
302
- const y = c(n(e.store.$snapshot())), U = c(t(e.getExternalState())), j = nt(U, y, o, c);
303
- if (C(j)) {
304
- E = !0;
305
- try {
306
- e.applyExternalPatch(j);
307
- } finally {
308
- E = !1;
309
- }
310
- }
311
- }, q = e.subscribeExternal(P), p = e.store.$subscribe(() => {
312
- S();
313
- });
314
- return P(), {
315
- dispose() {
316
- d || (d = !0, q(), p());
317
- },
318
- syncFromExternal: P,
319
- syncFromStore: S
320
- };
284
+ return h;
321
285
  }
322
- function gt(e = {}) {
323
- const t = (e.namespace ?? "default").trim() || "default", n = e.plugins ?? [], o = /* @__PURE__ */ new Map();
324
- function c(h, d) {
286
+ function bt(t = {}) {
287
+ const e = (t.namespace ?? "default").trim() || "default", n = t.plugins ?? [], s = /* @__PURE__ */ new Map();
288
+ function h(y, S) {
325
289
  return function() {
326
- var w;
327
- const E = `${t}:${h}`, C = o.get(h);
328
- if (C) return C;
329
- const P = d.state(), S = d.modules ?? {}, q = { ...P };
330
- for (const [r, i] of Object.entries(S))
331
- q[r] = i.state();
332
- const p = vt(q), y = /* @__PURE__ */ new Map(), U = /* @__PURE__ */ new Map(), j = /* @__PURE__ */ new Map(), A = /* @__PURE__ */ new Map(), O = /* @__PURE__ */ new Map(), z = /* @__PURE__ */ new Set(), T = new Set(Object.keys(P)), J = new Set(Object.keys(d.getters ?? {})), L = new Set(Object.keys(d.actions ?? {})), k = (r) => p.value[r] ?? {}, ct = (r, i) => {
333
- p.value = {
334
- ...p.value,
335
- [r]: i
290
+ var T;
291
+ const C = `${e}:${y}`, _ = s.get(y);
292
+ if (_) return _;
293
+ const A = S.state(), j = S.modules ?? {}, U = { ...A };
294
+ for (const [i, r] of Object.entries(j))
295
+ U[i] = r.state();
296
+ const g = pt(U), m = /* @__PURE__ */ new Map(), z = /* @__PURE__ */ new Map(), F = /* @__PURE__ */ new Map(), M = /* @__PURE__ */ new Map(), R = /* @__PURE__ */ new Map(), D = /* @__PURE__ */ new Set(), N = new Set(Object.keys(A)), L = new Set(Object.keys(S.getters ?? {})), W = new Set(Object.keys(S.actions ?? {})), o = (i) => g.value[i] ?? {}, d = (i, r) => {
297
+ g.value = {
298
+ ...g.value,
299
+ [i]: r
336
300
  };
337
- }, lt = new Proxy(
301
+ }, p = new Proxy(
338
302
  {},
339
303
  {
340
- get(r, i) {
341
- var a, f;
342
- if (y.has(i)) return (a = y.get(i)) == null ? void 0 : a.value;
343
- if (O.has(i)) return (f = O.get(i)) == null ? void 0 : f.value;
344
- if (T.has(i)) return p.value[i];
345
- const v = A.get(i);
346
- return v ? k(v.moduleName)[v.key] : p.value[i];
304
+ get(i, r) {
305
+ var c, u;
306
+ if (m.has(r)) return (c = m.get(r)) == null ? void 0 : c.value;
307
+ if (R.has(r)) return (u = R.get(r)) == null ? void 0 : u.value;
308
+ if (N.has(r)) return g.value[r];
309
+ const v = M.get(r);
310
+ return v ? o(v.moduleName)[v.key] : g.value[r];
347
311
  }
348
312
  }
349
313
  );
350
- for (const [r, i] of Object.entries(d.getters ?? {}))
351
- y.set(
352
- r,
353
- tt(() => i(p.value, lt))
314
+ for (const [i, r] of Object.entries(S.getters ?? {}))
315
+ m.set(
316
+ i,
317
+ nt(() => r(g.value, p))
354
318
  );
355
- const _ = (r, i) => {
356
- var a;
357
- for (const f of z) f(r);
358
- for (const f of n)
359
- (a = f.onMutation) == null || a.call(f, i, r);
360
- }, G = (r, i, a, f) => {
361
- const v = p.value[r];
362
- Object.is(v, i) || (p.value = {
363
- ...p.value,
364
- [r]: i
365
- }, _(
319
+ const b = (i, r) => {
320
+ var c;
321
+ for (const u of D) u(i);
322
+ for (const u of n)
323
+ (c = u.onMutation) == null || c.call(u, r, i);
324
+ }, O = (i, r, c, u) => {
325
+ const v = g.value[i];
326
+ Object.is(v, r) || (g.value = {
327
+ ...g.value,
328
+ [i]: r
329
+ }, b(
366
330
  {
367
- namespace: t,
368
- scopeId: E,
369
- storeId: h,
370
- key: r,
331
+ namespace: e,
332
+ scopeId: C,
333
+ storeId: y,
334
+ key: i,
371
335
  oldValue: v,
372
- newValue: i,
373
- origin: a
336
+ newValue: r,
337
+ origin: c
374
338
  },
375
- f
339
+ u
376
340
  ));
377
- }, I = (r, i, a, f, v) => {
378
- const g = k(r), s = g[i];
379
- Object.is(s, a) || (ct(r, {
380
- ...g,
381
- [i]: a
382
- }), _(
341
+ }, $ = (i, r, c, u, v) => {
342
+ const x = o(i), a = x[r];
343
+ Object.is(a, c) || (d(i, {
344
+ ...x,
345
+ [r]: c
346
+ }), b(
383
347
  {
384
- namespace: t,
385
- scopeId: E,
386
- storeId: h,
387
- key: `${r}.${i}`,
388
- oldValue: s,
389
- newValue: a,
390
- origin: f
348
+ namespace: e,
349
+ scopeId: C,
350
+ storeId: y,
351
+ key: `${i}.${r}`,
352
+ oldValue: a,
353
+ newValue: c,
354
+ origin: u
391
355
  },
392
356
  v
393
357
  ));
394
- }, M = {
395
- $id: h,
396
- $namespace: t,
397
- $scopeId: E,
398
- $subscribe(r) {
399
- return z.add(r), () => z.delete(r);
358
+ }, P = {
359
+ $id: y,
360
+ $namespace: e,
361
+ $scopeId: C,
362
+ $subscribe(i) {
363
+ return D.add(i), () => D.delete(i);
400
364
  },
401
365
  $dispose() {
402
- var r;
403
- z.clear();
404
- for (const i of n)
405
- (r = i.onDispose) == null || r.call(i, x);
406
- o.delete(h);
366
+ var i;
367
+ D.clear();
368
+ for (const r of n)
369
+ (i = r.onDispose) == null || i.call(r, k);
370
+ s.delete(y);
407
371
  },
408
- $patch(r, i = "local") {
409
- Z(() => {
410
- for (const [a, f] of Object.entries(r)) {
411
- const v = A.get(a);
372
+ $patch(i, r = "local") {
373
+ Y(() => {
374
+ for (const [c, u] of Object.entries(i)) {
375
+ const v = M.get(c);
412
376
  if (v) {
413
- I(v.moduleName, v.key, f, i, x);
377
+ $(v.moduleName, v.key, u, r, k);
414
378
  continue;
415
379
  }
416
- if (a.includes(".")) {
417
- const [g, s] = a.split(".", 2);
418
- if (S[g]) {
419
- I(g, s, f, i, x);
380
+ if (c.includes(".")) {
381
+ const [x, a] = c.split(".", 2);
382
+ if (j[x]) {
383
+ $(x, a, u, r, k);
420
384
  continue;
421
385
  }
422
386
  }
423
- if (S[a] && f && typeof f == "object" && !Array.isArray(f)) {
424
- for (const [g, s] of Object.entries(f))
425
- I(a, g, s, i, x);
387
+ if (j[c] && u && typeof u == "object" && !Array.isArray(u)) {
388
+ for (const [x, a] of Object.entries(u))
389
+ $(c, x, a, r, k);
426
390
  continue;
427
391
  }
428
- G(a, f, i, x);
392
+ O(c, u, r, k);
429
393
  }
430
394
  });
431
395
  },
432
396
  $snapshot() {
433
- return { ...p.value };
397
+ return { ...g.value };
434
398
  }
435
399
  };
436
- for (const [r, i] of Object.entries(S)) {
437
- const a = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map(), v = new Proxy(
400
+ for (const [i, r] of Object.entries(j)) {
401
+ const c = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map(), v = new Proxy(
438
402
  {},
439
403
  {
440
- get(s, u) {
441
- var m, N, Q;
442
- if (a.has(u)) return (m = a.get(u)) == null ? void 0 : m.value;
443
- if (y.has(u)) return (N = y.get(u)) == null ? void 0 : N.value;
444
- if (O.has(u)) return (Q = O.get(u)) == null ? void 0 : Q.value;
445
- const X = k(r);
446
- if (u in X) return X[u];
447
- if (T.has(u)) return p.value[u];
404
+ get(a, f) {
405
+ var V, I, tt;
406
+ if (c.has(f)) return (V = c.get(f)) == null ? void 0 : V.value;
407
+ if (m.has(f)) return (I = m.get(f)) == null ? void 0 : I.value;
408
+ if (R.has(f)) return (tt = R.get(f)) == null ? void 0 : tt.value;
409
+ const et = o(i);
410
+ if (f in et) return et[f];
411
+ if (N.has(f)) return g.value[f];
448
412
  }
449
413
  }
450
414
  );
451
- for (const [s, u] of Object.entries(i.getters ?? {}))
452
- a.set(
453
- s,
454
- tt(() => u(k(r), p.value, v))
415
+ for (const [a, f] of Object.entries(r.getters ?? {}))
416
+ c.set(
417
+ a,
418
+ nt(() => f(o(i), g.value, v))
455
419
  );
456
- let g;
457
- for (const [s, u] of Object.entries(i.actions ?? {}))
458
- f.set(s, (...m) => Z(() => u.apply(g, m)));
459
- g = new Proxy(
420
+ let x;
421
+ for (const [a, f] of Object.entries(r.actions ?? {}))
422
+ u.set(a, (...V) => Y(() => f.apply(x, V)));
423
+ x = new Proxy(
460
424
  {},
461
425
  {
462
- get(s, u) {
463
- var m;
464
- if (f.has(u)) return f.get(u);
465
- if (a.has(u)) return (m = a.get(u)) == null ? void 0 : m.value;
466
- const N = k(r);
467
- return u in N ? N[u] : x[u];
426
+ get(a, f) {
427
+ var V;
428
+ if (u.has(f)) return u.get(f);
429
+ if (c.has(f)) return (V = c.get(f)) == null ? void 0 : V.value;
430
+ const I = o(i);
431
+ return f in I ? I[f] : k[f];
468
432
  },
469
- set(s, u, m) {
470
- if (f.has(u) || a.has(u)) return !1;
471
- const N = k(r);
472
- return u in N ? I(r, u, m, "local", x) : x[u] = m, !0;
433
+ set(a, f, V) {
434
+ if (u.has(f) || c.has(f)) return !1;
435
+ const I = o(i);
436
+ return f in I ? $(i, f, V, "local", k) : k[f] = V, !0;
473
437
  }
474
438
  }
475
- ), j.set(r, g), U.set(r, a);
476
- for (const s of Object.keys(k(r)))
477
- !(T.has(s) || J.has(s) || L.has(s) || Reflect.has(M, s) || S[s] !== void 0) && !A.has(s) && A.set(s, { moduleName: r, key: s });
478
- for (const [s, u] of a.entries())
479
- !(T.has(s) || J.has(s) || L.has(s) || Reflect.has(M, s) || S[s] !== void 0) && !O.has(s) && O.set(s, u);
480
- for (const [s, u] of f.entries())
481
- !(T.has(s) || J.has(s) || L.has(s) || Reflect.has(M, s) || S[s] !== void 0) && !Reflect.has(M, s) && (M[s] = u);
439
+ ), F.set(i, x), z.set(i, c);
440
+ for (const a of Object.keys(o(i)))
441
+ !(N.has(a) || L.has(a) || W.has(a) || Reflect.has(P, a) || j[a] !== void 0) && !M.has(a) && M.set(a, { moduleName: i, key: a });
442
+ for (const [a, f] of c.entries())
443
+ !(N.has(a) || L.has(a) || W.has(a) || Reflect.has(P, a) || j[a] !== void 0) && !R.has(a) && R.set(a, f);
444
+ for (const [a, f] of u.entries())
445
+ !(N.has(a) || L.has(a) || W.has(a) || Reflect.has(P, a) || j[a] !== void 0) && !Reflect.has(P, a) && (P[a] = f);
482
446
  }
483
- const x = new Proxy(M, {
484
- get(r, i, a) {
485
- var f, v;
486
- if (Reflect.has(r, i)) return Reflect.get(r, i, a);
487
- if (j.has(i)) return j.get(i);
488
- if (y.has(i)) return (f = y.get(i)) == null ? void 0 : f.value;
489
- if (O.has(i)) return (v = O.get(i)) == null ? void 0 : v.value;
490
- if (T.has(i)) return p.value[i];
491
- const g = A.get(i);
492
- return g ? k(g.moduleName)[g.key] : p.value[i];
447
+ const k = new Proxy(P, {
448
+ get(i, r, c) {
449
+ var u, v;
450
+ if (Reflect.has(i, r)) return Reflect.get(i, r, c);
451
+ if (F.has(r)) return F.get(r);
452
+ if (m.has(r)) return (u = m.get(r)) == null ? void 0 : u.value;
453
+ if (R.has(r)) return (v = R.get(r)) == null ? void 0 : v.value;
454
+ if (N.has(r)) return g.value[r];
455
+ const x = M.get(r);
456
+ return x ? o(x.moduleName)[x.key] : g.value[r];
493
457
  },
494
- set(r, i, a, f) {
495
- if (Reflect.has(r, i))
496
- return Reflect.set(r, i, a, f);
497
- const v = A.get(i);
498
- return v ? (I(v.moduleName, v.key, a, "local", f), !0) : (G(i, a, "local", f), !0);
458
+ set(i, r, c, u) {
459
+ if (Reflect.has(i, r))
460
+ return Reflect.set(i, r, c, u);
461
+ const v = M.get(r);
462
+ return v ? ($(v.moduleName, v.key, c, "local", u), !0) : (O(r, c, "local", u), !0);
499
463
  }
500
464
  });
501
- for (const [r, i] of Object.entries(d.actions ?? {}))
502
- M[r] = (...a) => Z(() => i.apply(x, a));
503
- for (const r of n)
504
- (w = r.onInit) == null || w.call(r, x);
505
- return o.set(h, x), x;
465
+ for (const [i, r] of Object.entries(S.actions ?? {}))
466
+ P[i] = (...c) => Y(() => r.apply(k, c));
467
+ for (const i of n)
468
+ (T = i.onInit) == null || T.call(i, k);
469
+ return s.set(y, k), k;
506
470
  };
507
471
  }
508
472
  return {
509
- defineStore: c,
510
- use(h) {
511
- n.push(h);
473
+ defineStore: h,
474
+ use(y) {
475
+ n.push(y);
512
476
  }
513
477
  };
514
478
  }
515
- gt();
516
- const it = (e) => e !== null && typeof e == "object";
517
- function bt(e) {
518
- if (!it(e)) return e;
519
- const t = /* @__PURE__ */ new WeakSet(), n = (o) => {
520
- if (!it(o)) return;
521
- const c = o;
522
- if (t.has(c)) return;
523
- t.add(c);
524
- const h = Reflect.ownKeys(c);
525
- for (const d of h) {
526
- const w = Reflect.get(c, d);
527
- n(w);
479
+ bt();
480
+ const K = (t) => t !== null && typeof t == "object";
481
+ function xt(t) {
482
+ if (!K(t)) return t;
483
+ const e = /* @__PURE__ */ new WeakSet(), n = (s) => {
484
+ if (!K(s)) return;
485
+ const h = s;
486
+ if (e.has(h)) return;
487
+ e.add(h);
488
+ const y = Reflect.ownKeys(h);
489
+ for (const S of y) {
490
+ const T = Reflect.get(h, S);
491
+ n(T);
528
492
  }
529
- Object.freeze(c);
493
+ Object.freeze(h);
530
494
  };
531
- return n(e), e;
495
+ return n(t), t;
532
496
  }
533
- function xt(e, t) {
534
- for (const [n, o] of Object.entries(t))
535
- e[n] = o;
497
+ function mt(t, e) {
498
+ for (const [n, s] of Object.entries(e))
499
+ t[n] = s;
536
500
  }
537
- function wt(e) {
538
- const t = e.mutationType ?? "storix/APPLY_PATCH", n = e.immutable ?? !0, o = e.clone ?? Y, c = (h) => {
539
- const d = o(h);
540
- return n ? bt(d) : d;
501
+ const ot = (t) => Object.keys(t).length > 0, st = (t) => t ? Array.isArray(t) ? t : [t] : [], wt = (t) => {
502
+ const e = [t];
503
+ if (t.includes(".")) {
504
+ const n = t.split(".", 1)[0];
505
+ n && n !== t && e.push(n);
506
+ }
507
+ return e;
508
+ }, St = (t, e) => {
509
+ if (!e || !K(t)) return t;
510
+ try {
511
+ Object.defineProperty(t, e, {
512
+ value: !0,
513
+ enumerable: !1,
514
+ configurable: !0
515
+ });
516
+ } catch {
517
+ return t;
518
+ }
519
+ return t;
520
+ };
521
+ function jt(t) {
522
+ const e = t.mutationType ?? "storix/APPLY_PATCH", n = t.immutable ?? !0, s = t.clone ?? dt, h = t.equals ?? Q, y = t.projectVuexToStorix ?? ((o) => o), S = t.projectStorixToVuex ?? ((o) => o), T = t.suppressBridgeEcho ?? !1, C = t.bridgeOriginKey ?? "__storixBridge", _ = t.outboundDefault ?? {
523
+ mode: "patch",
524
+ type: e
525
+ }, A = (o) => {
526
+ const d = s(o);
527
+ return n ? xt(d) : d;
541
528
  };
542
- return pt({
543
- store: e.store,
544
- getExternalState: () => e.vuex.state,
545
- subscribeExternal: (h) => e.vuex.subscribe(() => h()),
546
- applyExternalPatch: (h) => {
547
- e.vuex.commit(t, c(h));
548
- },
549
- projectExternalToStore: e.projectVuexToStorix,
550
- projectStoreToExternal: e.projectStorixToVuex,
551
- equals: e.equals,
552
- clone: c,
553
- externalMutationOrigin: e.externalMutationOrigin ?? "local"
529
+ let j = !1, U = !1, g = !1;
530
+ const m = /* @__PURE__ */ new Map(), z = (o) => {
531
+ if (T)
532
+ for (const d of o) {
533
+ const p = m.get(d) ?? 0;
534
+ m.set(d, p + 1);
535
+ }
536
+ }, F = (o) => {
537
+ if (!T || !K(o)) return !1;
538
+ const d = Reflect.get(o, "payload");
539
+ if (C && K(d) && Reflect.get(d, C))
540
+ return !0;
541
+ const p = Reflect.get(o, "type");
542
+ if (typeof p != "string") return !1;
543
+ const b = m.get(p) ?? 0;
544
+ return b <= 0 ? !1 : (b === 1 ? m.delete(p) : m.set(p, b - 1), !0);
545
+ }, M = () => {
546
+ if (j || g) return;
547
+ const o = A(y(t.vuex.state)), d = t.store.$snapshot(), p = it(d, o, h, A);
548
+ if (ot(p)) {
549
+ U = !0;
550
+ try {
551
+ t.store.$patch(p, t.externalMutationOrigin ?? "local");
552
+ } finally {
553
+ U = !1;
554
+ }
555
+ }
556
+ }, R = (o) => {
557
+ const p = wt(o.storixMutation.key).flatMap((b) => {
558
+ var O;
559
+ return st((O = t.outboundRoutes) == null ? void 0 : O[b]);
560
+ });
561
+ return p.push(...st(_)), p.find((b) => b.when ? b.when(o) : !0);
562
+ }, D = (o, d) => {
563
+ var $;
564
+ if (o.mode === "custom") {
565
+ ($ = o.handler) == null || $.call(o, d), z(o.suppressMutationTypes ?? []);
566
+ return;
567
+ }
568
+ const p = (o.mode === "patch", d.projectedPatch), b = St(A(o.mapPayload ? o.mapPayload(d) : p), C);
569
+ if (o.mode === "dispatch") {
570
+ if (typeof t.vuex.dispatch != "function")
571
+ throw new Error('Vuex bridge route mode "dispatch" requires vuex.dispatch to be available.');
572
+ if (!o.type)
573
+ throw new Error('Vuex bridge dispatch route requires a "type".');
574
+ t.vuex.dispatch(o.type, b), z(o.suppressMutationTypes ?? []);
575
+ return;
576
+ }
577
+ const O = o.type ?? e;
578
+ t.vuex.commit(O, b), z(o.suppressMutationTypes ?? [O]);
579
+ }, N = (o) => {
580
+ if (j || U) return;
581
+ const d = t.store.$snapshot(), p = A(S(d)), b = A(y(t.vuex.state)), O = it(b, p, h, A);
582
+ if (!ot(O)) return;
583
+ const $ = {
584
+ storixMutation: o ?? {
585
+ namespace: t.store.$namespace,
586
+ scopeId: t.store.$scopeId,
587
+ storeId: t.store.$id,
588
+ key: Object.keys(O)[0] ?? "*",
589
+ oldValue: void 0,
590
+ newValue: void 0,
591
+ origin: "local"
592
+ },
593
+ storixSnapshot: d,
594
+ vuexState: t.vuex.state,
595
+ projectedPatch: O,
596
+ projectedVuexState: p,
597
+ origin: "storix"
598
+ }, P = R($);
599
+ if (P) {
600
+ g = !0;
601
+ try {
602
+ D(P, $);
603
+ } finally {
604
+ g = !1;
605
+ }
606
+ }
607
+ }, L = t.vuex.subscribe((o) => {
608
+ F(o) || M();
609
+ }), W = t.store.$subscribe((o) => {
610
+ N(o);
554
611
  });
612
+ return M(), {
613
+ dispose() {
614
+ j || (j = !0, L(), W());
615
+ },
616
+ syncFromExternal: M,
617
+ syncFromStore() {
618
+ N();
619
+ }
620
+ };
555
621
  }
556
622
  export {
557
- xt as applyVuexPatchMutation,
558
- wt as createVuexBridge,
559
- bt as deepFreeze
623
+ mt as applyVuexPatchMutation,
624
+ jt as createVuexBridge,
625
+ xt as deepFreeze
560
626
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storix-js/vuex",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",