@storix-js/vuex 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +560 -0
- package/package.json +24 -0
- package/src/index.ts +91 -0
- package/tsconfig.build.json +8 -0
- package/tsconfig.json +4 -0
- package/vite.config.ts +15 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +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;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type ExternalStoreBridgeHandle, type StoreInstance } from '@storix-js/core';
|
|
2
|
+
type AnyObject = Record<string, unknown>;
|
|
3
|
+
export interface VuexLikeStore<TState extends AnyObject> {
|
|
4
|
+
state: TState;
|
|
5
|
+
subscribe(listener: (mutation: unknown, state: TState) => void): () => void;
|
|
6
|
+
commit(type: string, payload?: unknown): void;
|
|
7
|
+
}
|
|
8
|
+
export interface CreateVuexBridgeOptions<TVuexState extends AnyObject> {
|
|
9
|
+
store: StoreInstance;
|
|
10
|
+
vuex: VuexLikeStore<TVuexState>;
|
|
11
|
+
mutationType?: string;
|
|
12
|
+
projectVuexToStorix?: (state: TVuexState) => Record<string, unknown>;
|
|
13
|
+
projectStorixToVuex?: (snapshot: Record<string, unknown>) => Record<string, unknown>;
|
|
14
|
+
equals?: (current: unknown, next: unknown, key: string) => boolean;
|
|
15
|
+
clone?: <T>(value: T) => T;
|
|
16
|
+
immutable?: boolean;
|
|
17
|
+
externalMutationOrigin?: 'local' | 'remote';
|
|
18
|
+
}
|
|
19
|
+
export declare function deepFreeze<T>(value: T): T;
|
|
20
|
+
export declare function applyVuexPatchMutation<TState extends AnyObject>(state: TState, patch: Record<string, unknown>): void;
|
|
21
|
+
export declare function createVuexBridge<TVuexState extends AnyObject>(options: CreateVuexBridgeOptions<TVuexState>): ExternalStoreBridgeHandle;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
var ht = Symbol.for("preact-signals");
|
|
2
|
+
function F() {
|
|
3
|
+
if ($ > 1)
|
|
4
|
+
$--;
|
|
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 {
|
|
11
|
+
n.c();
|
|
12
|
+
} catch (c) {
|
|
13
|
+
t || (e = c, t = !0);
|
|
14
|
+
}
|
|
15
|
+
n = o;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (B = 0, $--, t) throw e;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function Z(e) {
|
|
22
|
+
if ($ > 0) return e();
|
|
23
|
+
$++;
|
|
24
|
+
try {
|
|
25
|
+
return e();
|
|
26
|
+
} finally {
|
|
27
|
+
F();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
var l = void 0;
|
|
31
|
+
function rt(e) {
|
|
32
|
+
var t = l;
|
|
33
|
+
l = void 0;
|
|
34
|
+
try {
|
|
35
|
+
return e();
|
|
36
|
+
} finally {
|
|
37
|
+
l = t;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
var W = void 0, $ = 0, B = 0, D = 0;
|
|
41
|
+
function ot(e) {
|
|
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;
|
|
48
|
+
}
|
|
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;
|
|
52
|
+
}
|
|
53
|
+
b.prototype.brand = ht;
|
|
54
|
+
b.prototype.h = function() {
|
|
55
|
+
return !0;
|
|
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);
|
|
62
|
+
}));
|
|
63
|
+
};
|
|
64
|
+
b.prototype.U = function(e) {
|
|
65
|
+
var t = this;
|
|
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);
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
b.prototype.subscribe = function(e) {
|
|
75
|
+
var t = this;
|
|
76
|
+
return yt(function() {
|
|
77
|
+
var n = t.value, o = l;
|
|
78
|
+
l = void 0;
|
|
79
|
+
try {
|
|
80
|
+
e(n);
|
|
81
|
+
} finally {
|
|
82
|
+
l = o;
|
|
83
|
+
}
|
|
84
|
+
}, { name: "sub" });
|
|
85
|
+
};
|
|
86
|
+
b.prototype.valueOf = function() {
|
|
87
|
+
return this.value;
|
|
88
|
+
};
|
|
89
|
+
b.prototype.toString = function() {
|
|
90
|
+
return this.value + "";
|
|
91
|
+
};
|
|
92
|
+
b.prototype.toJSON = function() {
|
|
93
|
+
return this.value;
|
|
94
|
+
};
|
|
95
|
+
b.prototype.peek = function() {
|
|
96
|
+
var e = l;
|
|
97
|
+
l = void 0;
|
|
98
|
+
try {
|
|
99
|
+
return this.value;
|
|
100
|
+
} finally {
|
|
101
|
+
l = e;
|
|
102
|
+
}
|
|
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++, $++;
|
|
111
|
+
try {
|
|
112
|
+
for (var t = this.t; t !== void 0; t = t.x) t.t.N();
|
|
113
|
+
} finally {
|
|
114
|
+
F();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
} });
|
|
118
|
+
function vt(e, t) {
|
|
119
|
+
return new b(e, t);
|
|
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;
|
|
123
|
+
return !1;
|
|
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;
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
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;
|
|
138
|
+
}
|
|
139
|
+
e.s = n;
|
|
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;
|
|
143
|
+
}
|
|
144
|
+
R.prototype = new b();
|
|
145
|
+
R.prototype.h = function() {
|
|
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))
|
|
149
|
+
return this.f &= -2, !0;
|
|
150
|
+
var e = l;
|
|
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++);
|
|
155
|
+
} catch (n) {
|
|
156
|
+
this.v = n, this.f |= 16, this.i++;
|
|
157
|
+
}
|
|
158
|
+
return l = e, ft(this), this.f &= -2, !0;
|
|
159
|
+
};
|
|
160
|
+
R.prototype.S = function(e) {
|
|
161
|
+
if (this.t === void 0) {
|
|
162
|
+
this.f |= 36;
|
|
163
|
+
for (var t = this.s; t !== void 0; t = t.n) t.S.S(t);
|
|
164
|
+
}
|
|
165
|
+
b.prototype.S.call(this, e);
|
|
166
|
+
};
|
|
167
|
+
R.prototype.U = function(e) {
|
|
168
|
+
if (this.t !== void 0 && (b.prototype.U.call(this, e), this.t === void 0)) {
|
|
169
|
+
this.f &= -33;
|
|
170
|
+
for (var t = this.s; t !== void 0; t = t.n) t.S.U(t);
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
R.prototype.N = function() {
|
|
174
|
+
if (!(2 & this.f)) {
|
|
175
|
+
this.f |= 6;
|
|
176
|
+
for (var e = this.t; e !== void 0; e = e.x) e.t.N();
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
Object.defineProperty(R.prototype, "value", { get: function() {
|
|
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;
|
|
183
|
+
return this.v;
|
|
184
|
+
} });
|
|
185
|
+
function tt(e, t) {
|
|
186
|
+
return new R(e, t);
|
|
187
|
+
}
|
|
188
|
+
function ut(e) {
|
|
189
|
+
var t = e.u;
|
|
190
|
+
if (e.u = void 0, typeof t == "function") {
|
|
191
|
+
$++;
|
|
192
|
+
var n = l;
|
|
193
|
+
l = void 0;
|
|
194
|
+
try {
|
|
195
|
+
t();
|
|
196
|
+
} catch (o) {
|
|
197
|
+
throw e.f &= -2, e.f |= 8, K(e), o;
|
|
198
|
+
} finally {
|
|
199
|
+
l = n, F();
|
|
200
|
+
}
|
|
201
|
+
}
|
|
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);
|
|
206
|
+
}
|
|
207
|
+
function dt(e) {
|
|
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();
|
|
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;
|
|
213
|
+
}
|
|
214
|
+
V.prototype.c = function() {
|
|
215
|
+
var e = this.S();
|
|
216
|
+
try {
|
|
217
|
+
if (8 & this.f || this.x === void 0) return;
|
|
218
|
+
var t = this.x();
|
|
219
|
+
typeof t == "function" && (this.u = t);
|
|
220
|
+
} finally {
|
|
221
|
+
e();
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
V.prototype.S = function() {
|
|
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);
|
|
229
|
+
};
|
|
230
|
+
V.prototype.N = function() {
|
|
231
|
+
2 & this.f || (this.f |= 2, this.o = W, W = this);
|
|
232
|
+
};
|
|
233
|
+
V.prototype.d = function() {
|
|
234
|
+
this.f |= 8, 1 & this.f || K(this);
|
|
235
|
+
};
|
|
236
|
+
V.prototype.dispose = function() {
|
|
237
|
+
this.d();
|
|
238
|
+
};
|
|
239
|
+
function yt(e, t) {
|
|
240
|
+
var n = new V(e, t);
|
|
241
|
+
try {
|
|
242
|
+
n.c();
|
|
243
|
+
} catch (c) {
|
|
244
|
+
throw n.d(), c;
|
|
245
|
+
}
|
|
246
|
+
var o = n.d.bind(n);
|
|
247
|
+
return o[Symbol.dispose] = o, o;
|
|
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;
|
|
258
|
+
return !0;
|
|
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;
|
|
265
|
+
return !0;
|
|
266
|
+
}
|
|
267
|
+
return !1;
|
|
268
|
+
}
|
|
269
|
+
function Y(e) {
|
|
270
|
+
if (typeof structuredClone == "function")
|
|
271
|
+
return structuredClone(e);
|
|
272
|
+
try {
|
|
273
|
+
return JSON.parse(JSON.stringify(e));
|
|
274
|
+
} catch {
|
|
275
|
+
return e;
|
|
276
|
+
}
|
|
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));
|
|
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
|
+
};
|
|
321
|
+
}
|
|
322
|
+
function gt(e = {}) {
|
|
323
|
+
const t = (e.namespace ?? "default").trim() || "default", n = e.plugins ?? [], o = /* @__PURE__ */ new Map();
|
|
324
|
+
function c(h, d) {
|
|
325
|
+
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
|
|
336
|
+
};
|
|
337
|
+
}, lt = new Proxy(
|
|
338
|
+
{},
|
|
339
|
+
{
|
|
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];
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
);
|
|
350
|
+
for (const [r, i] of Object.entries(d.getters ?? {}))
|
|
351
|
+
y.set(
|
|
352
|
+
r,
|
|
353
|
+
tt(() => i(p.value, lt))
|
|
354
|
+
);
|
|
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
|
+
}, _(
|
|
366
|
+
{
|
|
367
|
+
namespace: t,
|
|
368
|
+
scopeId: E,
|
|
369
|
+
storeId: h,
|
|
370
|
+
key: r,
|
|
371
|
+
oldValue: v,
|
|
372
|
+
newValue: i,
|
|
373
|
+
origin: a
|
|
374
|
+
},
|
|
375
|
+
f
|
|
376
|
+
));
|
|
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
|
+
}), _(
|
|
383
|
+
{
|
|
384
|
+
namespace: t,
|
|
385
|
+
scopeId: E,
|
|
386
|
+
storeId: h,
|
|
387
|
+
key: `${r}.${i}`,
|
|
388
|
+
oldValue: s,
|
|
389
|
+
newValue: a,
|
|
390
|
+
origin: f
|
|
391
|
+
},
|
|
392
|
+
v
|
|
393
|
+
));
|
|
394
|
+
}, M = {
|
|
395
|
+
$id: h,
|
|
396
|
+
$namespace: t,
|
|
397
|
+
$scopeId: E,
|
|
398
|
+
$subscribe(r) {
|
|
399
|
+
return z.add(r), () => z.delete(r);
|
|
400
|
+
},
|
|
401
|
+
$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);
|
|
407
|
+
},
|
|
408
|
+
$patch(r, i = "local") {
|
|
409
|
+
Z(() => {
|
|
410
|
+
for (const [a, f] of Object.entries(r)) {
|
|
411
|
+
const v = A.get(a);
|
|
412
|
+
if (v) {
|
|
413
|
+
I(v.moduleName, v.key, f, i, x);
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
416
|
+
if (a.includes(".")) {
|
|
417
|
+
const [g, s] = a.split(".", 2);
|
|
418
|
+
if (S[g]) {
|
|
419
|
+
I(g, s, f, i, x);
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
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);
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
428
|
+
G(a, f, i, x);
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
},
|
|
432
|
+
$snapshot() {
|
|
433
|
+
return { ...p.value };
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
for (const [r, i] of Object.entries(S)) {
|
|
437
|
+
const a = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map(), v = new Proxy(
|
|
438
|
+
{},
|
|
439
|
+
{
|
|
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];
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
);
|
|
451
|
+
for (const [s, u] of Object.entries(i.getters ?? {}))
|
|
452
|
+
a.set(
|
|
453
|
+
s,
|
|
454
|
+
tt(() => u(k(r), p.value, v))
|
|
455
|
+
);
|
|
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(
|
|
460
|
+
{},
|
|
461
|
+
{
|
|
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];
|
|
468
|
+
},
|
|
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;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
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);
|
|
482
|
+
}
|
|
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];
|
|
493
|
+
},
|
|
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);
|
|
499
|
+
}
|
|
500
|
+
});
|
|
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;
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
return {
|
|
509
|
+
defineStore: c,
|
|
510
|
+
use(h) {
|
|
511
|
+
n.push(h);
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
}
|
|
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);
|
|
528
|
+
}
|
|
529
|
+
Object.freeze(c);
|
|
530
|
+
};
|
|
531
|
+
return n(e), e;
|
|
532
|
+
}
|
|
533
|
+
function xt(e, t) {
|
|
534
|
+
for (const [n, o] of Object.entries(t))
|
|
535
|
+
e[n] = o;
|
|
536
|
+
}
|
|
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;
|
|
541
|
+
};
|
|
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"
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
export {
|
|
557
|
+
xt as applyVuexPatchMutation,
|
|
558
|
+
wt as createVuexBridge,
|
|
559
|
+
bt as deepFreeze
|
|
560
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@storix-js/vuex",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.cjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "vite build && tsc -p tsconfig.build.json --emitDeclarationOnly",
|
|
17
|
+
"dev": "vite build --watch",
|
|
18
|
+
"test": "vitest run",
|
|
19
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@storix-js/core": "workspace:*"
|
|
23
|
+
}
|
|
24
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createExternalStoreBridge,
|
|
3
|
+
isolateSnapshot,
|
|
4
|
+
type ExternalStoreBridgeHandle,
|
|
5
|
+
type StoreInstance
|
|
6
|
+
} from '@storix-js/core';
|
|
7
|
+
|
|
8
|
+
type AnyObject = Record<string, unknown>;
|
|
9
|
+
|
|
10
|
+
export interface VuexLikeStore<TState extends AnyObject> {
|
|
11
|
+
state: TState;
|
|
12
|
+
subscribe(listener: (mutation: unknown, state: TState) => void): () => void;
|
|
13
|
+
commit(type: string, payload?: unknown): void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface CreateVuexBridgeOptions<TVuexState extends AnyObject> {
|
|
17
|
+
store: StoreInstance;
|
|
18
|
+
vuex: VuexLikeStore<TVuexState>;
|
|
19
|
+
mutationType?: string;
|
|
20
|
+
projectVuexToStorix?: (state: TVuexState) => Record<string, unknown>;
|
|
21
|
+
projectStorixToVuex?: (snapshot: Record<string, unknown>) => Record<string, unknown>;
|
|
22
|
+
equals?: (current: unknown, next: unknown, key: string) => boolean;
|
|
23
|
+
clone?: <T>(value: T) => T;
|
|
24
|
+
immutable?: boolean;
|
|
25
|
+
externalMutationOrigin?: 'local' | 'remote';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const isObjectLike = (value: unknown): value is AnyObject => {
|
|
29
|
+
return value !== null && typeof value === 'object';
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export function deepFreeze<T>(value: T): T {
|
|
33
|
+
if (!isObjectLike(value)) return value;
|
|
34
|
+
|
|
35
|
+
const seen = new WeakSet<object>();
|
|
36
|
+
|
|
37
|
+
const freezeRecursively = (candidate: unknown): void => {
|
|
38
|
+
if (!isObjectLike(candidate)) return;
|
|
39
|
+
|
|
40
|
+
const objectCandidate = candidate as object;
|
|
41
|
+
if (seen.has(objectCandidate)) return;
|
|
42
|
+
seen.add(objectCandidate);
|
|
43
|
+
|
|
44
|
+
const keys = Reflect.ownKeys(objectCandidate);
|
|
45
|
+
for (const key of keys) {
|
|
46
|
+
const nested = Reflect.get(objectCandidate, key);
|
|
47
|
+
freezeRecursively(nested);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
Object.freeze(objectCandidate);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
freezeRecursively(value);
|
|
54
|
+
return value;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function applyVuexPatchMutation<TState extends AnyObject>(state: TState, patch: Record<string, unknown>) {
|
|
58
|
+
for (const [key, value] of Object.entries(patch)) {
|
|
59
|
+
(state as AnyObject)[key] = value;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function createVuexBridge<TVuexState extends AnyObject>(
|
|
64
|
+
options: CreateVuexBridgeOptions<TVuexState>
|
|
65
|
+
): ExternalStoreBridgeHandle {
|
|
66
|
+
const mutationType = options.mutationType ?? 'storix/APPLY_PATCH';
|
|
67
|
+
const immutable = options.immutable ?? true;
|
|
68
|
+
const baseClone = options.clone ?? isolateSnapshot;
|
|
69
|
+
|
|
70
|
+
const clone = <T>(value: T): T => {
|
|
71
|
+
const next = baseClone(value);
|
|
72
|
+
if (!immutable) return next;
|
|
73
|
+
return deepFreeze(next);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
return createExternalStoreBridge({
|
|
77
|
+
store: options.store,
|
|
78
|
+
getExternalState: () => options.vuex.state,
|
|
79
|
+
subscribeExternal: (listener) => {
|
|
80
|
+
return options.vuex.subscribe(() => listener());
|
|
81
|
+
},
|
|
82
|
+
applyExternalPatch: (patch) => {
|
|
83
|
+
options.vuex.commit(mutationType, clone(patch));
|
|
84
|
+
},
|
|
85
|
+
projectExternalToStore: options.projectVuexToStorix,
|
|
86
|
+
projectStoreToExternal: options.projectStorixToVuex,
|
|
87
|
+
equals: options.equals,
|
|
88
|
+
clone,
|
|
89
|
+
externalMutationOrigin: options.externalMutationOrigin ?? 'local'
|
|
90
|
+
});
|
|
91
|
+
}
|
package/tsconfig.json
ADDED
package/vite.config.ts
ADDED