@yakocloud/state-vocab 3.0.4 → 3.0.6

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.
@@ -1,3 +1,3 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react"),_=Symbol("state-def"),k=Symbol("state-path"),R=Symbol("state-verbose"),x=Symbol("state-verbose-path"),A=Symbol("state-ssr");function I(t,e,s){if(!e)return t;const i=e.split(".");let c=t;for(const r of i)if(c!==null&&typeof c=="object"&&r in c)c=c[r];else return s;return c===void 0?s:c}function j(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let c=t;for(let r=0;r<i.length-1;r++){const n=i[r],l=i[r+1];(c[n]===void 0||c[n]===null)&&(c[n]=/^\d+$/.test(l)?[]:{}),c=c[n]}return c[i[i.length-1]]=s,t}function D(t,e=0){let s;return function(...i){s!==void 0&&clearTimeout(s),s=setTimeout(()=>{s=void 0,t.apply(this,i)},e)}}function B(t,e,s=[]){return d.useMemo(()=>D(t,e),s)}function M(t){const e=JSON.stringify(t,null,2).split(`
2
- `),s=[],i=[];for(const c of e){const r=c.match(/^(\s*)"([^"]+)"(\s*:\s*)(.+)$/);if(r){const[,n,l,h,u]=r;s.push(`${n}%c"${l}"%c${h}%c${u}`),i.push("color: #9cdcfe; font-weight: bold","color: #cccccc","color: #ce9178")}else s.push(`%c${c}`),i.push("color: #cccccc")}console.log(s.join(`
3
- `),...i,t)}const L=t=>typeof t=="function",F=t=>typeof t=="function",T=t=>typeof t<"u",P=t=>F(t)?t():t,C=typeof window>"u",J=C?d.useEffect:d.useLayoutEffect;class H{#e;#t;constructor(){this.#e={},this.#t=new Set}subscribe(e){return this.#t.add(e),()=>this.#t.delete(e)}getClientSnapshot(){return this.#e}getServerSnapshot(){return this.#e}get(e){return I(this.#e,e)}set(e,s){const i=I(this.#e,e),c=L(s)?s(i):s,r={...this.#e};j(r,e,c),this.#e=r,this.#t.forEach(n=>n())}}function K(t={}){const e=new H,s=t.serialize??JSON.stringify,i=t.deserialize??JSON.parse,c=(r,n,l)=>{const h=n.getItem(r);h===null?T(l)&&n.setItem(r,s(l)):e.set(r,i(h))};return{[_]:!0,[k]:"",[R]:!1,[x]:"",[A]:!1,useState(r){const n=C?void 0:P(t.storage),l=P(t.defaultValue),h=t.bidirectional;r??={};const u=P(r.defaultValue)??l,w=r.bidirectional??h,S=B(r.onSet??(()=>{}),r.delayedSet,[]),o=this[k],v=this[R],f=this[x],y=this[A],b=d.useRef(void 0),V=d.useRef(!1);if(!V.current){V.current=!0;let a=C?void 0:e.get(o);T(a)||(a=u,T(a)&&e.set(o,a)),!y&&n&&c(o,n,a)}const E=d.useSyncExternalStore(e.subscribe.bind(e),e.getClientSnapshot.bind(e),e.getServerSnapshot.bind(e));if(v)if(f){const a=I(E,f);a&&M(a)}else M(E);const p=I(E,o,u);b.current=p,J(()=>{!y||!n||c(o,n,p)},[]);const g=d.useEffectEvent(a=>{if(a.key!==o)return;const m=a.newValue,z=(m===null?null:i(m))??u;T(z)&&(e.set(o,z),S(z,b.current))});d.useEffect(()=>{if(w)return window.addEventListener("storage",g),()=>window.removeEventListener("storage",g)},[w]);const $=d.useCallback(a=>{const m=L(a)?a(b.current):a;e.set(o,m),S(m,b.current),n&&n.setItem(o,s(m))},[o,n,S]),O=d.useCallback(()=>{const a=u;if(!T(a)){n?.removeItem(o);return}e.set(o,a),S(a,b.current),n&&n.setItem(o,s(a))},[o,u,n,S]);return[p,$,O]},toString(){return this[k]}}}function N(t,e){const{path:s="",verbose:i,verbosePath:c,ssr:r,cache:n}=e;let l=n.proxy.get(t);l||(l=new Map,n.proxy.set(t,l));const h=l.get(s);if(h)return h;const u=new Proxy(t,{get(w,S){const o=w[S],v=s?`${s}.${String(S)}`:String(S);if(o&&typeof o=="object"&&_ in o){const f=o;let y=n.leaf.get(f);y||(y=new Map,n.leaf.set(f,y));const b=y.get(v);if(b)return b;const V=Reflect.ownKeys(f).filter(g=>typeof f[g]=="function"),E=Object.fromEntries(V.map(g=>[g,(...$)=>f[g].call({...f,[k]:v,[R]:i,[x]:c,[A]:r},...$)])),p={...f,...E};return y.set(v,p),p}return o&&typeof o=="object"?N(o,{...e,path:v}):o}});return l.set(s,u),u}function W(t,e){return N(t,{...e,verbosePath:e?.verbosePath??"",cache:{proxy:new WeakMap,leaf:new WeakMap}})}exports.defineState=K;exports.setupStorage=W;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("react"),_=Symbol("state-def"),k=Symbol("state-path"),R=Symbol("state-verbose"),x=Symbol("state-verbose-path"),L=Symbol("state-ssr");function z(e,n,t){if(!n)return e;const i=n.split(".");let o=e;for(const c of i)if(o!==null&&typeof o=="object"&&c in o)o=o[c];else return t;return o===void 0?t:o}function F(e,n,t){const i=n.replace(/\[(\d+)\]/g,".$1").split(".");let o=e;for(let c=0;c<i.length-1;c++){const l=i[c],s=i[c+1];(o[l]===void 0||o[l]===null)&&(o[l]=/^\d+$/.test(s)?[]:{}),o=o[l]}return o[i[i.length-1]]=t,e}function J(e,n=0){let t;return function(...i){t!==void 0&&clearTimeout(t),t=setTimeout(()=>{t=void 0,e.apply(this,i)},n)}}function H(e,n,t=[]){return S.useMemo(()=>J(e,n),t)}function M(e){const n=JSON.stringify(e,null,2).split(`
2
+ `),t=[],i=[];for(const o of n){const c=o.match(/^(\s*)"([^"]+)"(\s*:\s*)(.+)$/);if(c){const[,l,s,p,g]=c;t.push(`${l}%c"${s}"%c${p}%c${g}`),i.push("color: #9cdcfe; font-weight: bold","color: #cccccc","color: #ce9178")}else t.push(`%c${o}`),i.push("color: #cccccc")}console.log(t.join(`
3
+ `),...i,e)}const N=e=>typeof e=="function",K=e=>typeof e=="function",T=e=>typeof e<"u",A=e=>K(e)?e():e;class O{#e;#t;constructor(){this.#e={},this.#t=new Set}subscribe(n){return this.#t.add(n),()=>this.#t.delete(n)}getClientSnapshot(){return this.#e}getServerSnapshot(){return this.#e}get(n){return z(this.#e,n)}set(n,t){const i=z(this.#e,n),o=N(t)?t(i):t,c={...this.#e};F(c,n,o),this.#e=c,this.#t.forEach(l=>l())}}let j;typeof window>"u"&&(j=new AsyncLocalStorage);const W=()=>{const e=j.getStore();if(!e)throw new Error(`${O.name} must be initialized for this request`);return e};let C=null;const G=()=>(C||(C=new O),C),Q=()=>typeof window>"u"?W():G(),D=typeof window>"u",U=D?S.useEffect:S.useLayoutEffect;function X(e={}){return{[_]:!0,[k]:"",[R]:!1,[x]:"",[L]:!1,useState(n){const t=D?void 0:A(e.storage),i=A(e.defaultValue),o=e.bidirectional;n??={};const c=A(n.defaultValue)??i,l=n.bidirectional??o,s=this[k],p=this[R],g=this[x],V=this[L],u=Q(),a=e.serialize??JSON.stringify,b=e.deserialize??JSON.parse,d=(r,h,P)=>{const w=h.getItem(r);w===null?T(P)&&h.setItem(r,a(P)):u.set(r,b(w))},f=H(n.onSet??(()=>{}),n.delayedSet,[]),y=S.useRef(void 0),$=S.useRef(!1);if(!$.current){$.current=!0;let r=u.get(s);T(r)||(r=c,T(r)&&u.set(s,r)),!V&&t&&d(s,t,r)}const E=S.useSyncExternalStore(u.subscribe.bind(u),u.getClientSnapshot.bind(u),u.getServerSnapshot.bind(u));if(p)if(g){const r=z(E,g);r&&M(r)}else M(E);const m=z(E,s,c);y.current=m,U(()=>{!V||!t||d(s,t,m)},[]);const v=S.useEffectEvent(r=>{if(r.key!==s)return;const h=r.newValue,w=(h===null?null:b(h))??c;T(w)&&(u.set(s,w),f(w,y.current))});S.useEffect(()=>{if(l)return window.addEventListener("storage",v),()=>window.removeEventListener("storage",v)},[l]);const I=S.useCallback(r=>{const h=N(r)?r(y.current):r;u.set(s,h),f(h,y.current),t&&t.setItem(s,a(h))},[s,t,f]),B=S.useCallback(()=>{const r=c;if(!T(r)){t?.removeItem(s);return}u.set(s,r),f(r,y.current),t&&t.setItem(s,a(r))},[s,c,t,f]);return[m,I,B]},toString(){return this[k]}}}function q(e,n){const{path:t="",verbose:i,verbosePath:o,ssr:c,cache:l}=n;let s=l.proxy.get(e);s||(s=new Map,l.proxy.set(e,s));const p=s.get(t);if(p)return p;const g=new Proxy(e,{get(V,u){const a=V[u],b=t?`${t}.${String(u)}`:String(u);if(a&&typeof a=="object"&&_ in a){const d=a;let f=l.leaf.get(d);f||(f=new Map,l.leaf.set(d,f));const y=f.get(b);if(y)return y;const $=Reflect.ownKeys(d).filter(v=>typeof d[v]=="function"),E=Object.fromEntries($.map(v=>[v,(...I)=>d[v].call({...d,[k]:b,[R]:i,[x]:o,[L]:c},...I)])),m={...d,...E};return f.set(b,m),m}return a&&typeof a=="object"?q(a,{...n,path:b}):a}});return s.set(t,g),g}function Y(e,n){return q(e,{...n,verbosePath:n?.verbosePath??"",cache:{proxy:new WeakMap,leaf:new WeakMap}})}exports.defineState=X;exports.setupStorage=Y;
@@ -1,68 +1,68 @@
1
- import { useMemo as B, useRef as C, useSyncExternalStore as F, useEffect as M, useLayoutEffect as J, useEffectEvent as H, useCallback as _ } from "react";
2
- const N = Symbol("state-def"), V = Symbol("state-path"), x = Symbol("state-verbose"), P = Symbol("state-verbose-path"), A = Symbol("state-ssr");
3
- function I(t, e, s) {
4
- if (!e)
5
- return t;
6
- const i = e.split(".");
7
- let o = t;
8
- for (const r of i)
9
- if (o !== null && typeof o == "object" && r in o)
10
- o = o[r];
1
+ import { useMemo as H, useRef as L, useSyncExternalStore as K, useEffect as N, useLayoutEffect as W, useEffectEvent as G, useCallback as _ } from "react";
2
+ const D = Symbol("state-def"), $ = Symbol("state-path"), P = Symbol("state-verbose"), C = Symbol("state-verbose-path"), R = Symbol("state-ssr");
3
+ function z(e, n, t) {
4
+ if (!n)
5
+ return e;
6
+ const i = n.split(".");
7
+ let o = e;
8
+ for (const c of i)
9
+ if (o !== null && typeof o == "object" && c in o)
10
+ o = o[c];
11
11
  else
12
- return s;
13
- return o === void 0 ? s : o;
12
+ return t;
13
+ return o === void 0 ? t : o;
14
14
  }
15
- function K(t, e, s) {
16
- const i = e.replace(/\[(\d+)\]/g, ".$1").split(".");
17
- let o = t;
18
- for (let r = 0; r < i.length - 1; r++) {
19
- const n = i[r], a = i[r + 1];
20
- (o[n] === void 0 || o[n] === null) && (o[n] = /^\d+$/.test(a) ? [] : {}), o = o[n];
15
+ function Q(e, n, t) {
16
+ const i = n.replace(/\[(\d+)\]/g, ".$1").split(".");
17
+ let o = e;
18
+ for (let c = 0; c < i.length - 1; c++) {
19
+ const l = i[c], s = i[c + 1];
20
+ (o[l] === void 0 || o[l] === null) && (o[l] = /^\d+$/.test(s) ? [] : {}), o = o[l];
21
21
  }
22
- return o[i[i.length - 1]] = s, t;
22
+ return o[i[i.length - 1]] = t, e;
23
23
  }
24
- function W(t, e = 0) {
25
- let s;
24
+ function U(e, n = 0) {
25
+ let t;
26
26
  return function(...i) {
27
- s !== void 0 && clearTimeout(s), s = setTimeout(() => {
28
- s = void 0, t.apply(this, i);
29
- }, e);
27
+ t !== void 0 && clearTimeout(t), t = setTimeout(() => {
28
+ t = void 0, e.apply(this, i);
29
+ }, n);
30
30
  };
31
31
  }
32
- function q(t, e, s = []) {
33
- return B(
34
- () => W(t, e),
32
+ function X(e, n, t = []) {
33
+ return H(
34
+ () => U(e, n),
35
35
  // eslint-disable-next-line react-hooks/exhaustive-deps
36
- s
36
+ t
37
37
  );
38
38
  }
39
- function L(t) {
40
- const e = JSON.stringify(t, null, 2).split(`
41
- `), s = [], i = [];
42
- for (const o of e) {
43
- const r = o.match(/^(\s*)"([^"]+)"(\s*:\s*)(.+)$/);
44
- if (r) {
45
- const [, n, a, d, u] = r;
46
- s.push(`${n}%c"${a}"%c${d}%c${u}`), i.push(
39
+ function M(e) {
40
+ const n = JSON.stringify(e, null, 2).split(`
41
+ `), t = [], i = [];
42
+ for (const o of n) {
43
+ const c = o.match(/^(\s*)"([^"]+)"(\s*:\s*)(.+)$/);
44
+ if (c) {
45
+ const [, l, s, v, y] = c;
46
+ t.push(`${l}%c"${s}"%c${v}%c${y}`), i.push(
47
47
  "color: #9cdcfe; font-weight: bold",
48
48
  "color: #cccccc",
49
49
  "color: #ce9178"
50
50
  );
51
51
  } else
52
- s.push(`%c${o}`), i.push("color: #cccccc");
52
+ t.push(`%c${o}`), i.push("color: #cccccc");
53
53
  }
54
- console.log(s.join(`
55
- `), ...i, t);
54
+ console.log(t.join(`
55
+ `), ...i, e);
56
56
  }
57
- const D = (t) => typeof t == "function", G = (t) => typeof t == "function", E = (t) => typeof t < "u", z = (t) => G(t) ? t() : t, R = typeof window > "u", Q = R ? M : J;
58
- class U {
57
+ const O = (e) => typeof e == "function", Y = (e) => typeof e == "function", E = (e) => typeof e < "u", x = (e) => Y(e) ? e() : e;
58
+ class j {
59
59
  #e;
60
60
  #t;
61
61
  constructor() {
62
62
  this.#e = {}, this.#t = /* @__PURE__ */ new Set();
63
63
  }
64
- subscribe(e) {
65
- return this.#t.add(e), () => this.#t.delete(e);
64
+ subscribe(n) {
65
+ return this.#t.add(n), () => this.#t.delete(n);
66
66
  }
67
67
  getClientSnapshot() {
68
68
  return this.#e;
@@ -70,146 +70,155 @@ class U {
70
70
  getServerSnapshot() {
71
71
  return this.#e;
72
72
  }
73
- get(e) {
74
- return I(this.#e, e);
73
+ get(n) {
74
+ return z(this.#e, n);
75
75
  }
76
- set(e, s) {
77
- const i = I(this.#e, e), o = D(s) ? s(i) : s, r = { ...this.#e };
78
- K(r, e, o), this.#e = r, this.#t.forEach((n) => n());
76
+ set(n, t) {
77
+ const i = z(this.#e, n), o = O(t) ? t(i) : t, c = { ...this.#e };
78
+ Q(c, n, o), this.#e = c, this.#t.forEach((l) => l());
79
79
  }
80
80
  }
81
- function Z(t = {}) {
82
- const e = new U(), s = t.serialize ?? JSON.stringify, i = t.deserialize ?? JSON.parse, o = (r, n, a) => {
83
- const d = n.getItem(r);
84
- d === null ? E(a) && n.setItem(r, s(a)) : e.set(r, i(d));
85
- };
81
+ let B;
82
+ typeof window > "u" && (B = new AsyncLocalStorage());
83
+ const Z = () => {
84
+ const e = B.getStore();
85
+ if (!e)
86
+ throw new Error(`${j.name} must be initialized for this request`);
87
+ return e;
88
+ };
89
+ let A = null;
90
+ const ee = () => (A || (A = new j()), A), te = () => typeof window > "u" ? Z() : ee(), F = typeof window > "u", ne = F ? N : W;
91
+ function re(e = {}) {
86
92
  return {
87
- [N]: !0,
93
+ [D]: !0,
88
94
  // marks this object as a leaf in the router tree
89
- [V]: "",
95
+ [$]: "",
90
96
  // placeholder; injected at runtime by injectPaths()
91
- [x]: !1,
97
+ [P]: !1,
92
98
  // placeholder
93
- [P]: "",
99
+ [C]: "",
94
100
  // placeholder
95
- [A]: !1,
101
+ [R]: !1,
96
102
  // placeholder
97
- useState(r) {
98
- const n = R ? void 0 : z(t.storage), a = z(t.defaultValue), d = t.bidirectional;
99
- r ??= {};
100
- const u = z(r.defaultValue) ?? a, w = r.bidirectional ?? d, h = q(
101
- r.onSet ?? (() => {
103
+ useState(n) {
104
+ const t = F ? void 0 : x(e.storage), i = x(e.defaultValue), o = e.bidirectional;
105
+ n ??= {};
106
+ const c = x(n.defaultValue) ?? i, l = n.bidirectional ?? o, s = this[$], v = this[P], y = this[C], V = this[R], a = te(), u = e.serialize ?? JSON.stringify, g = e.deserialize ?? JSON.parse, d = (r, h, k) => {
107
+ const m = h.getItem(r);
108
+ m === null ? E(k) && h.setItem(r, u(k)) : a.set(r, g(m));
109
+ }, f = X(
110
+ n.onSet ?? (() => {
102
111
  }),
103
- r.delayedSet,
112
+ n.delayedSet,
104
113
  []
105
- ), c = this[V], g = this[x], f = this[P], S = this[A], y = C(void 0), T = C(!1);
114
+ ), S = L(void 0), T = L(!1);
106
115
  if (!T.current) {
107
116
  T.current = !0;
108
- let l = R ? void 0 : e.get(c);
109
- E(l) || (l = u, E(l) && e.set(c, l)), !S && n && o(c, n, l);
117
+ let r = a.get(s);
118
+ E(r) || (r = c, E(r) && a.set(s, r)), !V && t && d(s, t, r);
110
119
  }
111
- const m = F(
112
- e.subscribe.bind(e),
113
- e.getClientSnapshot.bind(e),
114
- e.getServerSnapshot.bind(e)
120
+ const w = K(
121
+ a.subscribe.bind(a),
122
+ a.getClientSnapshot.bind(a),
123
+ a.getServerSnapshot.bind(a)
115
124
  );
116
- if (g)
117
- if (f) {
118
- const l = I(m, f);
119
- l && L(l);
125
+ if (v)
126
+ if (y) {
127
+ const r = z(w, y);
128
+ r && M(r);
120
129
  } else
121
- L(m);
122
- const v = I(m, c, u);
123
- y.current = v, Q(() => {
124
- !S || !n || o(c, n, v);
130
+ M(w);
131
+ const p = z(w, s, c);
132
+ S.current = p, ne(() => {
133
+ !V || !t || d(s, t, p);
125
134
  }, []);
126
- const b = H((l) => {
127
- if (l.key !== c)
135
+ const b = G((r) => {
136
+ if (r.key !== s)
128
137
  return;
129
- const p = l.newValue, k = (p === null ? null : i(p)) ?? u;
130
- E(k) && (e.set(c, k), h(k, y.current));
138
+ const h = r.newValue, m = (h === null ? null : g(h)) ?? c;
139
+ E(m) && (a.set(s, m), f(m, S.current));
131
140
  });
132
- M(() => {
133
- if (w)
141
+ N(() => {
142
+ if (l)
134
143
  return window.addEventListener("storage", b), () => window.removeEventListener("storage", b);
135
- }, [w]);
136
- const $ = _((l) => {
137
- const p = D(l) ? l(y.current) : l;
138
- e.set(c, p), h(p, y.current), n && n.setItem(c, s(p));
139
- }, [c, n, h]), j = _(() => {
140
- const l = u;
141
- if (!E(l)) {
142
- n?.removeItem(c);
144
+ }, [l]);
145
+ const I = _((r) => {
146
+ const h = O(r) ? r(S.current) : r;
147
+ a.set(s, h), f(h, S.current), t && t.setItem(s, u(h));
148
+ }, [s, t, f]), q = _(() => {
149
+ const r = c;
150
+ if (!E(r)) {
151
+ t?.removeItem(s);
143
152
  return;
144
153
  }
145
- e.set(c, l), h(l, y.current), n && n.setItem(c, s(l));
146
- }, [c, u, n, h]);
154
+ a.set(s, r), f(r, S.current), t && t.setItem(s, u(r));
155
+ }, [s, c, t, f]);
147
156
  return [
148
- v,
149
- $,
150
- j
157
+ p,
158
+ I,
159
+ q
151
160
  ];
152
161
  },
153
162
  /** Returns the fully qualified job name (dot-separated path). */
154
163
  toString() {
155
- return this[V];
164
+ return this[$];
156
165
  }
157
166
  };
158
167
  }
159
- function O(t, e) {
168
+ function J(e, n) {
160
169
  const {
161
- path: s = "",
170
+ path: t = "",
162
171
  verbose: i,
163
172
  verbosePath: o,
164
- ssr: r,
165
- cache: n
166
- } = e;
167
- let a = n.proxy.get(t);
168
- a || (a = /* @__PURE__ */ new Map(), n.proxy.set(t, a));
169
- const d = a.get(s);
170
- if (d)
171
- return d;
172
- const u = new Proxy(t, {
173
- get(w, h) {
174
- const c = w[h], g = s ? `${s}.${String(h)}` : String(h);
175
- if (c && typeof c == "object" && N in c) {
176
- const f = c;
177
- let S = n.leaf.get(f);
178
- S || (S = /* @__PURE__ */ new Map(), n.leaf.set(f, S));
179
- const y = S.get(g);
180
- if (y)
181
- return y;
182
- const T = Reflect.ownKeys(f).filter(
183
- (b) => typeof f[b] == "function"
184
- ), m = Object.fromEntries(
173
+ ssr: c,
174
+ cache: l
175
+ } = n;
176
+ let s = l.proxy.get(e);
177
+ s || (s = /* @__PURE__ */ new Map(), l.proxy.set(e, s));
178
+ const v = s.get(t);
179
+ if (v)
180
+ return v;
181
+ const y = new Proxy(e, {
182
+ get(V, a) {
183
+ const u = V[a], g = t ? `${t}.${String(a)}` : String(a);
184
+ if (u && typeof u == "object" && D in u) {
185
+ const d = u;
186
+ let f = l.leaf.get(d);
187
+ f || (f = /* @__PURE__ */ new Map(), l.leaf.set(d, f));
188
+ const S = f.get(g);
189
+ if (S)
190
+ return S;
191
+ const T = Reflect.ownKeys(d).filter(
192
+ (b) => typeof d[b] == "function"
193
+ ), w = Object.fromEntries(
185
194
  T.map((b) => [
186
195
  b,
187
- (...$) => f[b].call(
196
+ (...I) => d[b].call(
188
197
  {
189
- ...f,
190
- [V]: g,
191
- [x]: i,
192
- [P]: o,
193
- [A]: r
198
+ ...d,
199
+ [$]: g,
200
+ [P]: i,
201
+ [C]: o,
202
+ [R]: c
194
203
  },
195
- ...$
204
+ ...I
196
205
  )
197
206
  ])
198
- ), v = { ...f, ...m };
199
- return S.set(g, v), v;
207
+ ), p = { ...d, ...w };
208
+ return f.set(g, p), p;
200
209
  }
201
- return c && typeof c == "object" ? O(c, {
202
- ...e,
210
+ return u && typeof u == "object" ? J(u, {
211
+ ...n,
203
212
  path: g
204
- }) : c;
213
+ }) : u;
205
214
  }
206
215
  });
207
- return a.set(s, u), u;
216
+ return s.set(t, y), y;
208
217
  }
209
- function ee(t, e) {
210
- return O(t, {
211
- ...e,
212
- verbosePath: e?.verbosePath ?? "",
218
+ function oe(e, n) {
219
+ return J(e, {
220
+ ...n,
221
+ verbosePath: n?.verbosePath ?? "",
213
222
  cache: {
214
223
  proxy: /* @__PURE__ */ new WeakMap(),
215
224
  leaf: /* @__PURE__ */ new WeakMap()
@@ -217,6 +226,6 @@ function ee(t, e) {
217
226
  });
218
227
  }
219
228
  export {
220
- Z as defineState,
221
- ee as setupStorage
229
+ re as defineState,
230
+ oe as setupStorage
222
231
  };
@@ -4,3 +4,4 @@ export type Transformer<V> = (prev: V) => V;
4
4
  export type ValueOrTransformer<V> = V | Transformer<V>;
5
5
  export type Factory<V> = () => V;
6
6
  export type ValueOrFactory<V> = V | Factory<V>;
7
+ export type Vocab<T = unknown> = Record<string, T | null>;
@@ -0,0 +1,17 @@
1
+ import type { ValueOrTransformer, Vocab } from "./state.types";
2
+ type Listener = () => void;
3
+ /***
4
+ * https://react.dev/reference/react/useSyncExternalStore
5
+ */
6
+ declare class VocabStore {
7
+ #private;
8
+ constructor();
9
+ subscribe(listener: Listener): () => boolean;
10
+ getClientSnapshot<V>(): Vocab<V>;
11
+ getServerSnapshot<V>(): Vocab<V>;
12
+ get<V>(statePath: string): V | undefined;
13
+ set<V>(statePath: string, value: ValueOrTransformer<V>): void;
14
+ }
15
+ export declare function runWithStateVocab<T>(fn: () => T): T;
16
+ export declare const getVocabStore: () => VocabStore;
17
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yakocloud/state-vocab",
3
- "version": "3.0.4",
3
+ "version": "3.0.6",
4
4
  "main": "dist/state-vocab.cjs.js",
5
5
  "module": "dist/state-vocab.es.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -50,7 +50,6 @@
50
50
  "@testing-library/jest-dom": "^6.9.1",
51
51
  "@testing-library/react": "^16.3.2",
52
52
  "@types/jest": "^30.0.0",
53
- "@types/node": "^24.10.1",
54
53
  "@types/react": "^19.2.5",
55
54
  "@types/react-dom": "^19.2.3",
56
55
  "@vitejs/plugin-react": "^5.2.0",