@yakocloud/state-vocab 4.3.0 → 4.3.1

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 +1 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react"),v=require("./constants-CbsduCZ7.js"),a=require("./utils-0CTNJ4ZE.js"),V=require("./provider-client-DA53zfcT.js");function D(t,n,s=[]){return f.useMemo(()=>a.debounce(t,n),s)}const y=t=>{const{vocabStore:n,storage:s,statePath:o,value:e,deserialize:l,serialize:c}=t,d=s.getItem(o);d===null?a.isValueDefined(e)&&s.setItem(o,c(e)):n.set(o,l(d))};function I(t){return typeof t=="object"&&t!==null&&"clientSlot"in t}const z=typeof window>"u",m=z?f.useEffect:f.useLayoutEffect,A=new V.VocabStore,P="Make sure your component is wrapped in StateVocabProvider (RSC) or disable ssr option in setupStorage for SPA (RCC only)";function p(t){const n=z?void 0:a.valueOrFactory(t.storage),s=a.valueOrFactory(t.defaultValue),o=t.bidirectional,e=this[v.STATE_PATH],l=this[v.STATE_VERBOSE],c=this[v.STATE_VERBOSE_PATH],d=this[v.STATE_SSR];let i=V.useStateVocabClientContext({clientContext:t.clientContext,verbose:l});if(!(i instanceof V.VocabStore)){if(d)throw new Error(P);i=A}const S=t.serialize??JSON.stringify,u=t.deserialize??JSON.parse,E=D(t.onSet??(()=>{}),t.delayedSet,[]),g=f.useRef(void 0),R=f.useRef(!1);if(!R.current){R.current=!0;let r=i.get(e);a.isValueDefined(r)||(r=s,a.isValueDefined(r)&&i.set(e,r)),!d&&n&&y({vocabStore:i,storage:n,statePath:e,value:r,serialize:S,deserialize:u})}const C=f.useSyncExternalStore(i.subscribe.bind(i),i.getClientSnapshot.bind(i),i.getServerSnapshot.bind(i));if(l)if(c){const r=a.get(C,c);r&&a.logStyled(r)}else a.logStyled(C);const h=a.get(C,e,s);g.current=h,m(()=>{!d||!n||y({vocabStore:i,storage:n,statePath:e,value:h,serialize:S,deserialize:u})},[]);const w=f.useEffectEvent(r=>{if(r.key!==e)return;const b=r.newValue,T=(b===null?null:u(b))??s;a.isValueDefined(T)&&(i.set(e,T),E(T,g.current))});f.useEffect(()=>{if(o)return window.addEventListener("storage",w),()=>window.removeEventListener("storage",w)},[o]);const x=f.useCallback(r=>{const b=a.isTransformer(r)?r(g.current):r;i.set(e,b),E(b,g.current),n&&n.setItem(e,S(b))},[i,e,E,n,S]),_=f.useCallback(()=>{const r=s;if(!a.isValueDefined(r)){n?.removeItem(e);return}i.set(e,r),E(r,g.current),n&&n.setItem(e,S(r))},[s,i,e,E,n,S]);return[h,x,_]}function k(t){const n=z?void 0:a.valueOrFactory(t.storage),s=a.valueOrFactory(t.defaultValue),o=this[v.STATE_PATH],e=this[v.STATE_VERBOSE],l=this[v.STATE_SSR];let c=V.useStateVocabClientContext({clientContext:t.clientContext,verbose:e});if(!(c instanceof V.VocabStore)){if(l)throw new Error(P);c=A}const d=t.serialize??JSON.stringify,i=t.deserialize??JSON.parse,S=f.useRef(!1);let u;S.current||(S.current=!0,u=c.get(o),a.isValueDefined(u)||(u=s,a.isValueDefined(u)&&c.set(o,u)),!l&&n&&y({vocabStore:c,storage:n,statePath:o,value:u,serialize:d,deserialize:i})),m(()=>{!l||!n||y({vocabStore:c,storage:n,statePath:o,value:u,serialize:d,deserialize:i})},[])}function O(t,n={}){const s={};for(const o in t){const e=t[o];I(e)?(s[o]=e.clientSlot({useState(l){return p.apply(this,[{clientContext:n.clientContext,...l}])},useInitialState(l){k.apply(this,[{clientContext:n.clientContext,...l}])}}),delete s[o].serverSlot,delete s[o].clientSlot):e!==null&&typeof e=="object"?s[o]=O(e,n):s[o]=e}return s}exports.StateVocabClientProvider=V.StateVocabClientProvider;exports.clientify=O;
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react"),S=require("./constants-BTyJxzUH.js"),o=require("./utils-0CTNJ4ZE.js"),b=require("./provider-client-DA53zfcT.js");function L(t,n,s=[]){return f.useMemo(()=>o.debounce(t,n),s)}const C=t=>{const{vocabStore:n,storage:s,statePath:a,value:e,deserialize:l,serialize:c}=t,d=s.getItem(a);d===null?o.isValueDefined(e)&&s.setItem(a,c(e)):n.set(a,l(d))};function x(t){return typeof t=="object"&&t!==null&&S.STATE_CLIENT_SLOT in t}const R=typeof window>"u",A=R?f.useEffect:f.useLayoutEffect,O=new b.VocabStore,w="Make sure your component is wrapped in StateVocabProvider (RSC) or disable ssr option in setupStorage for SPA (RCC only)";function D(t){const n=R?void 0:o.valueOrFactory(t.storage),s=o.valueOrFactory(t.defaultValue),a=t.bidirectional,e=this[S.STATE_PATH],l=this[S.STATE_VERBOSE],c=this[S.STATE_VERBOSE_PATH],d=this[S.STATE_SSR];let i=b.useStateVocabClientContext({clientContext:t.clientContext,verbose:l});if(!(i instanceof b.VocabStore)){if(d)throw new Error(w);i=O}const E=t.serialize??JSON.stringify,u=t.deserialize??JSON.parse,v=L(t.onSet??(()=>{}),t.delayedSet,[]),V=f.useRef(void 0),_=f.useRef(!1);if(!_.current){_.current=!0;let r=i.get(e);o.isValueDefined(r)||(r=s,o.isValueDefined(r)&&i.set(e,r)),!d&&n&&C({vocabStore:i,storage:n,statePath:e,value:r,serialize:E,deserialize:u})}const g=f.useSyncExternalStore(i.subscribe.bind(i),i.getClientSnapshot.bind(i),i.getServerSnapshot.bind(i));if(l)if(c){const r=o.get(g,c);r&&o.logStyled(r)}else o.logStyled(g);const y=o.get(g,e,s);V.current=y,A(()=>{!d||!n||C({vocabStore:i,storage:n,statePath:e,value:y,serialize:E,deserialize:u})},[]);const z=f.useEffectEvent(r=>{if(r.key!==e)return;const T=r.newValue,h=(T===null?null:u(T))??s;o.isValueDefined(h)&&(i.set(e,h),v(h,V.current))});f.useEffect(()=>{if(a)return window.addEventListener("storage",z),()=>window.removeEventListener("storage",z)},[a]);const P=f.useCallback(r=>{const T=o.isTransformer(r)?r(V.current):r;i.set(e,T),v(T,V.current),n&&n.setItem(e,E(T))},[i,e,v,n,E]),I=f.useCallback(()=>{const r=s;if(!o.isValueDefined(r)){n?.removeItem(e);return}i.set(e,r),v(r,V.current),n&&n.setItem(e,E(r))},[s,i,e,v,n,E]);return[y,P,I]}function p(t){const n=R?void 0:o.valueOrFactory(t.storage),s=o.valueOrFactory(t.defaultValue),a=this[S.STATE_PATH],e=this[S.STATE_VERBOSE],l=this[S.STATE_SSR];let c=b.useStateVocabClientContext({clientContext:t.clientContext,verbose:e});if(!(c instanceof b.VocabStore)){if(l)throw new Error(w);c=O}const d=t.serialize??JSON.stringify,i=t.deserialize??JSON.parse,E=f.useRef(!1);let u;E.current||(E.current=!0,u=c.get(a),o.isValueDefined(u)||(u=s,o.isValueDefined(u)&&c.set(a,u)),!l&&n&&C({vocabStore:c,storage:n,statePath:a,value:u,serialize:d,deserialize:i})),A(()=>{!l||!n||C({vocabStore:c,storage:n,statePath:a,value:u,serialize:d,deserialize:i})},[])}function m(t,n={}){const s={};for(const a in t){const e=t[a];x(e)?(s[a]=e[S.STATE_CLIENT_SLOT]({useState(l){return D.apply(this,[{clientContext:n.clientContext,...l}])},useInitialState(l){p.apply(this,[{clientContext:n.clientContext,...l}])}}),delete s[S.STATE_CLIENT_SLOT],delete s[S.STATE_SERVER_SLOT]):e!==null&&typeof e=="object"?s[a]=m(e,n):s[a]=e}return s}exports.StateVocabClientProvider=b.StateVocabClientProvider;exports.clientify=m;
package/dist/client.es.js CHANGED
@@ -1,17 +1,17 @@
1
1
  "use client";
2
- import { useMemo as j, useRef as C, useSyncExternalStore as B, useEffectEvent as D, useEffect as P, useCallback as p, useLayoutEffect as H } from "react";
3
- import { S as A, a as I, b as O, c as F } from "./constants-BB1YAX6c.mjs";
4
- import { a as d, d as G, v as g, g as T, l as x, i as q } from "./utils-xV3x3fTc.mjs";
5
- import { V as y, u as _ } from "./provider-client-DLa3_Ms9.mjs";
6
- import { S as ne } from "./provider-client-DLa3_Ms9.mjs";
7
- function K(t, s, i = []) {
8
- return j(
9
- () => G(t, s),
2
+ import { useMemo as B, useRef as C, useSyncExternalStore as D, useEffectEvent as H, useEffect as _, useCallback as p, useLayoutEffect as F } from "react";
3
+ import { S as T, a as G, b as I, c as P, d as O, e as q } from "./constants-Cf0m6moG.mjs";
4
+ import { a as d, d as K, v as E, g as x, l as A, i as Q } from "./utils-xV3x3fTc.mjs";
5
+ import { V as y, u as L } from "./provider-client-DLa3_Ms9.mjs";
6
+ import { S as oe } from "./provider-client-DLa3_Ms9.mjs";
7
+ function U(t, s, i = []) {
8
+ return B(
9
+ () => K(t, s),
10
10
  // eslint-disable-next-line react-hooks/exhaustive-deps
11
11
  i
12
12
  );
13
13
  }
14
- const E = (t) => {
14
+ const g = (t) => {
15
15
  const {
16
16
  vocabStore: s,
17
17
  storage: i,
@@ -22,31 +22,31 @@ const E = (t) => {
22
22
  } = t, u = i.getItem(o);
23
23
  u === null ? d(e) && i.setItem(o, l(e)) : s.set(o, a(u));
24
24
  };
25
- function Q(t) {
26
- return typeof t == "object" && t !== null && "clientSlot" in t;
25
+ function W(t) {
26
+ return typeof t == "object" && t !== null && T in t;
27
27
  }
28
- const z = typeof window > "u", k = z ? P : H, J = new y(), L = "Make sure your component is wrapped in StateVocabProvider (RSC) or disable ssr option in setupStorage for SPA (RCC only)";
29
- function U(t) {
30
- const s = z ? void 0 : g(t.storage), i = g(t.defaultValue), o = t.bidirectional, e = this[A], a = this[I], l = this[F], u = this[O];
31
- let r = _({
28
+ const z = typeof window > "u", N = z ? _ : F, k = new y(), J = "Make sure your component is wrapped in StateVocabProvider (RSC) or disable ssr option in setupStorage for SPA (RCC only)";
29
+ function X(t) {
30
+ const s = z ? void 0 : E(t.storage), i = E(t.defaultValue), o = t.bidirectional, e = this[I], a = this[P], l = this[q], u = this[O];
31
+ let r = L({
32
32
  clientContext: t.clientContext,
33
33
  verbose: a
34
34
  });
35
35
  if (!(r instanceof y)) {
36
36
  if (u)
37
- throw new Error(L);
38
- r = J;
37
+ throw new Error(J);
38
+ r = k;
39
39
  }
40
- const f = t.serialize ?? JSON.stringify, c = t.deserialize ?? JSON.parse, v = K(
40
+ const f = t.serialize ?? JSON.stringify, c = t.deserialize ?? JSON.parse, v = U(
41
41
  t.onSet ?? (() => {
42
42
  }),
43
43
  t.delayedSet,
44
44
  []
45
- ), b = C(void 0), w = C(!1);
46
- if (!w.current) {
47
- w.current = !0;
45
+ ), b = C(void 0), R = C(!1);
46
+ if (!R.current) {
47
+ R.current = !0;
48
48
  let n = r.get(e);
49
- d(n) || (n = i, d(n) && r.set(e, n)), !u && s && E({
49
+ d(n) || (n = i, d(n) && r.set(e, n)), !u && s && g({
50
50
  vocabStore: r,
51
51
  storage: s,
52
52
  statePath: e,
@@ -55,42 +55,42 @@ function U(t) {
55
55
  deserialize: c
56
56
  });
57
57
  }
58
- const h = B(
58
+ const V = D(
59
59
  r.subscribe.bind(r),
60
60
  r.getClientSnapshot.bind(r),
61
61
  r.getServerSnapshot.bind(r)
62
62
  );
63
63
  if (a)
64
64
  if (l) {
65
- const n = T(h, l);
66
- n && x(n);
65
+ const n = x(V, l);
66
+ n && A(n);
67
67
  } else
68
- x(h);
69
- const m = T(h, e, i);
70
- b.current = m, k(() => {
71
- !u || !s || E({
68
+ A(V);
69
+ const h = x(V, e, i);
70
+ b.current = h, N(() => {
71
+ !u || !s || g({
72
72
  vocabStore: r,
73
73
  storage: s,
74
74
  statePath: e,
75
- value: m,
75
+ value: h,
76
76
  serialize: f,
77
77
  deserialize: c
78
78
  });
79
79
  }, []);
80
- const R = D((n) => {
80
+ const w = H((n) => {
81
81
  if (n.key !== e)
82
82
  return;
83
- const S = n.newValue, V = (S === null ? null : c(S)) ?? i;
84
- d(V) && (r.set(e, V), v(V, b.current));
83
+ const S = n.newValue, m = (S === null ? null : c(S)) ?? i;
84
+ d(m) && (r.set(e, m), v(m, b.current));
85
85
  });
86
- P(() => {
86
+ _(() => {
87
87
  if (o)
88
- return window.addEventListener("storage", R), () => window.removeEventListener("storage", R);
88
+ return window.addEventListener("storage", w), () => window.removeEventListener("storage", w);
89
89
  }, [o]);
90
- const N = p((n) => {
91
- const S = q(n) ? n(b.current) : n;
90
+ const M = p((n) => {
91
+ const S = Q(n) ? n(b.current) : n;
92
92
  r.set(e, S), v(S, b.current), s && s.setItem(e, f(S));
93
- }, [r, e, v, s, f]), M = p(() => {
93
+ }, [r, e, v, s, f]), j = p(() => {
94
94
  const n = i;
95
95
  if (!d(n)) {
96
96
  s?.removeItem(e);
@@ -99,33 +99,33 @@ function U(t) {
99
99
  r.set(e, n), v(n, b.current), s && s.setItem(e, f(n));
100
100
  }, [i, r, e, v, s, f]);
101
101
  return [
102
- m,
103
- N,
104
- M
102
+ h,
103
+ M,
104
+ j
105
105
  ];
106
106
  }
107
- function W(t) {
108
- const s = z ? void 0 : g(t.storage), i = g(t.defaultValue), o = this[A], e = this[I], a = this[O];
109
- let l = _({
107
+ function Y(t) {
108
+ const s = z ? void 0 : E(t.storage), i = E(t.defaultValue), o = this[I], e = this[P], a = this[O];
109
+ let l = L({
110
110
  clientContext: t.clientContext,
111
111
  verbose: e
112
112
  });
113
113
  if (!(l instanceof y)) {
114
114
  if (a)
115
- throw new Error(L);
116
- l = J;
115
+ throw new Error(J);
116
+ l = k;
117
117
  }
118
118
  const u = t.serialize ?? JSON.stringify, r = t.deserialize ?? JSON.parse, f = C(!1);
119
119
  let c;
120
- f.current || (f.current = !0, c = l.get(o), d(c) || (c = i, d(c) && l.set(o, c)), !a && s && E({
120
+ f.current || (f.current = !0, c = l.get(o), d(c) || (c = i, d(c) && l.set(o, c)), !a && s && g({
121
121
  vocabStore: l,
122
122
  storage: s,
123
123
  statePath: o,
124
124
  value: c,
125
125
  serialize: u,
126
126
  deserialize: r
127
- })), k(() => {
128
- !a || !s || E({
127
+ })), N(() => {
128
+ !a || !s || g({
129
129
  vocabStore: l,
130
130
  storage: s,
131
131
  statePath: o,
@@ -135,28 +135,28 @@ function W(t) {
135
135
  });
136
136
  }, []);
137
137
  }
138
- function X(t, s = {}) {
138
+ function Z(t, s = {}) {
139
139
  const i = {};
140
140
  for (const o in t) {
141
141
  const e = t[o];
142
- Q(e) ? (i[o] = e.clientSlot({
142
+ W(e) ? (i[o] = e[T]({
143
143
  useState(a) {
144
- return U.apply(this, [{
144
+ return X.apply(this, [{
145
145
  clientContext: s.clientContext,
146
146
  ...a
147
147
  }]);
148
148
  },
149
149
  useInitialState(a) {
150
- W.apply(this, [{
150
+ Y.apply(this, [{
151
151
  clientContext: s.clientContext,
152
152
  ...a
153
153
  }]);
154
154
  }
155
- }), delete i[o].serverSlot, delete i[o].clientSlot) : e !== null && typeof e == "object" ? i[o] = X(e, s) : i[o] = e;
155
+ }), delete i[T], delete i[G]) : e !== null && typeof e == "object" ? i[o] = Z(e, s) : i[o] = e;
156
156
  }
157
157
  return i;
158
158
  }
159
159
  export {
160
- ne as StateVocabClientProvider,
161
- X as clientify
160
+ oe as StateVocabClientProvider,
161
+ Z as clientify
162
162
  };
@@ -0,0 +1 @@
1
+ "use strict";const T=Symbol("state-def"),S=Symbol("state-path"),E=Symbol("state-verbose"),t=Symbol("state-verbose-path"),s=Symbol("state-ssr"),_=Symbol("state-server-slot"),o=Symbol("state-client-slot");exports.STATE_CLIENT_SLOT=o;exports.STATE_DEFINITION=T;exports.STATE_PATH=S;exports.STATE_SERVER_SLOT=_;exports.STATE_SSR=s;exports.STATE_VERBOSE=E;exports.STATE_VERBOSE_PATH=t;
@@ -0,0 +1,10 @@
1
+ const s = /* @__PURE__ */ Symbol("state-def"), t = /* @__PURE__ */ Symbol("state-path"), S = /* @__PURE__ */ Symbol("state-verbose"), T = /* @__PURE__ */ Symbol("state-verbose-path"), o = /* @__PURE__ */ Symbol("state-ssr"), a = /* @__PURE__ */ Symbol("state-server-slot"), e = /* @__PURE__ */ Symbol("state-client-slot");
2
+ export {
3
+ e as S,
4
+ a,
5
+ t as b,
6
+ S as c,
7
+ o as d,
8
+ T as e,
9
+ s as f
10
+ };
package/dist/index.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./constants-CbsduCZ7.js"),h=require("./utils-0CTNJ4ZE.js");function z(t={}){return{[r.STATE_DEFINITION]:!0,[r.STATE_PATH]:"",[r.STATE_VERBOSE]:!1,[r.STATE_VERBOSE_PATH]:"",[r.STATE_SSR]:!1,serverSlot(a){return Object.assign(this,{getState(...e){return a.getState.apply(this,e)}})},clientSlot(a){return Object.assign(this,{useState(e){return e??={},a.useState.apply(this,[{defaultValue:h.valueOrFactory(e.defaultValue)??h.valueOrFactory(t.defaultValue),bidirectional:e.bidirectional??t.bidirectional,storage:e.storage??t.storage,serialize:t.serialize??JSON.stringify,deserialize:t.deserialize??JSON.parse,delayedSet:e.delayedSet,onSet(...f){e.onSet&&e.onSet(...f)}}])},useInitialState(e){a.useInitialState.apply(this,[{defaultValue:e.defaultValue,storage:t.storage,serialize:t.serialize,deserialize:t.deserialize}])}})},toString(){return this[r.STATE_PATH]}}}function y(t,a){const{path:e="",verbose:f,verbosePath:A,ssr:b,cache:c}=a;let s=c.proxy.get(t);s||(s=new Map,c.proxy.set(t,s));const o=s.get(e);if(o)return o;const d=new Proxy(t,{get(P,T){const l=P[T],S=e?`${e}.${String(T)}`:String(T);if(l&&typeof l=="object"&&r.STATE_DEFINITION in l){const i=l;let n=c.leaf.get(i);n||(n=new Map,c.leaf.set(i,n));const g=n.get(S);if(g)return g;const _=Reflect.ownKeys(i).filter(u=>typeof i[u]=="function"),v=Object.fromEntries(_.map(u=>[u,(...V)=>i[u].call({...i,[r.STATE_PATH]:S,[r.STATE_VERBOSE]:f,[r.STATE_VERBOSE_PATH]:A,[r.STATE_SSR]:b},...V)])),E={...i,...v};return n.set(S,E),E}return l&&typeof l=="object"?y(l,{...a,path:S}):l}});return s.set(e,d),d}function I(t,a){return y(t,{...a,ssr:a?.ssr??!0,verbosePath:a?.verbosePath??"",cache:{proxy:new WeakMap,leaf:new WeakMap}})}exports.defineState=z;exports.setupStorage=I;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./constants-BTyJxzUH.js"),h=require("./utils-0CTNJ4ZE.js");function O(t={}){return{[a.STATE_DEFINITION]:!0,[a.STATE_PATH]:"",[a.STATE_VERBOSE]:!1,[a.STATE_VERBOSE_PATH]:"",[a.STATE_SSR]:!1,[a.STATE_SERVER_SLOT](r){return Object.assign(this,{getState(...e){return r.getState.apply(this,e)}})},[a.STATE_CLIENT_SLOT](r){return Object.assign(this,{useState(e){return e??={},r.useState.apply(this,[{defaultValue:h.valueOrFactory(e.defaultValue)??h.valueOrFactory(t.defaultValue),bidirectional:e.bidirectional??t.bidirectional,storage:e.storage??t.storage,serialize:t.serialize??JSON.stringify,deserialize:t.deserialize??JSON.parse,delayedSet:e.delayedSet,onSet(...u){e.onSet&&e.onSet(...u)}}])},useInitialState(e){r.useInitialState.apply(this,[{defaultValue:e.defaultValue,storage:t.storage,serialize:t.serialize,deserialize:t.deserialize}])}})},toString(){return this[a.STATE_PATH]}}}function y(t,r){const{path:e="",verbose:u,verbosePath:A,ssr:_,cache:S}=r;let s=S.proxy.get(t);s||(s=new Map,S.proxy.set(t,s));const E=s.get(e);if(E)return E;const d=new Proxy(t,{get(b,f){const l=b[f],c=e?`${e}.${String(f)}`:String(f);if(l&&typeof l=="object"&&a.STATE_DEFINITION in l){const i=l;let n=S.leaf.get(i);n||(n=new Map,S.leaf.set(i,n));const o=n.get(c);if(o)return o;const P=Reflect.ownKeys(i).filter(T=>typeof i[T]=="function"),V=Object.fromEntries(P.map(T=>[T,(...I)=>i[T].call({...i,[a.STATE_PATH]:c,[a.STATE_VERBOSE]:u,[a.STATE_VERBOSE_PATH]:A,[a.STATE_SSR]:_},...I)])),g={...i,...V};return n.set(c,g),g}return l&&typeof l=="object"?y(l,{...r,path:c}):l}});return s.set(e,d),d}function R(t,r){return y(t,{...r,ssr:r?.ssr??!0,verbosePath:r?.verbosePath??"",cache:{proxy:new WeakMap,leaf:new WeakMap}})}exports.defineState=O;exports.setupStorage=R;
package/dist/index.es.js CHANGED
@@ -1,18 +1,18 @@
1
- import { S as d, b as T, c as E, a as P, d as v } from "./constants-BB1YAX6c.mjs";
2
- import { v as b } from "./utils-xV3x3fTc.mjs";
3
- function M(t = {}) {
1
+ import { b as d, S as w, a as I, d as E, e as b, c as _, f as A } from "./constants-Cf0m6moG.mjs";
2
+ import { v as y } from "./utils-xV3x3fTc.mjs";
3
+ function L(t = {}) {
4
4
  return {
5
- [v]: !0,
5
+ [A]: !0,
6
6
  // marks this object as a leaf in the router tree
7
7
  [d]: "",
8
8
  // placeholder; injected at runtime by injectPaths()
9
- [P]: !1,
9
+ [_]: !1,
10
10
  // placeholder
11
- [E]: "",
11
+ [b]: "",
12
12
  // placeholder
13
- [T]: !1,
13
+ [E]: !1,
14
14
  // placeholder
15
- serverSlot(a) {
15
+ [I](a) {
16
16
  return Object.assign(this, {
17
17
  // Impl|RSC
18
18
  getState(...e) {
@@ -20,12 +20,12 @@ function M(t = {}) {
20
20
  }
21
21
  });
22
22
  },
23
- clientSlot(a) {
23
+ [w](a) {
24
24
  return Object.assign(this, {
25
25
  // Impl|RCC
26
26
  useState(e) {
27
27
  return e ??= {}, a.useState.apply(this, [{
28
- defaultValue: b(e.defaultValue) ?? b(t.defaultValue),
28
+ defaultValue: y(e.defaultValue) ?? y(t.defaultValue),
29
29
  bidirectional: e.bidirectional ?? t.bidirectional,
30
30
  storage: e.storage ?? t.storage,
31
31
  serialize: t.serialize ?? JSON.stringify,
@@ -53,58 +53,58 @@ function M(t = {}) {
53
53
  }
54
54
  };
55
55
  }
56
- function z(t, a) {
56
+ function P(t, a) {
57
57
  const {
58
58
  path: e = "",
59
59
  verbose: S,
60
- verbosePath: x,
61
- ssr: A,
60
+ verbosePath: z,
61
+ ssr: V,
62
62
  cache: n
63
63
  } = a;
64
- let s = n.proxy.get(t);
65
- s || (s = /* @__PURE__ */ new Map(), n.proxy.set(t, s));
66
- const o = s.get(e);
67
- if (o)
68
- return o;
69
- const h = new Proxy(t, {
70
- get(V, u) {
71
- const r = V[u], c = e ? `${e}.${String(u)}` : String(u);
72
- if (r && typeof r == "object" && v in r) {
73
- const l = r;
74
- let i = n.leaf.get(l);
75
- i || (i = /* @__PURE__ */ new Map(), n.leaf.set(l, i));
76
- const g = i.get(c);
77
- if (g)
78
- return g;
79
- const j = Reflect.ownKeys(l).filter(
80
- (f) => typeof l[f] == "function"
81
- ), m = Object.fromEntries(
82
- j.map((f) => [
64
+ let l = n.proxy.get(t);
65
+ l || (l = /* @__PURE__ */ new Map(), n.proxy.set(t, l));
66
+ const h = l.get(e);
67
+ if (h)
68
+ return h;
69
+ const o = new Proxy(t, {
70
+ get(v, u) {
71
+ const r = v[u], c = e ? `${e}.${String(u)}` : String(u);
72
+ if (r && typeof r == "object" && A in r) {
73
+ const s = r;
74
+ let i = n.leaf.get(s);
75
+ i || (i = /* @__PURE__ */ new Map(), n.leaf.set(s, i));
76
+ const T = i.get(c);
77
+ if (T)
78
+ return T;
79
+ const x = Reflect.ownKeys(s).filter(
80
+ (f) => typeof s[f] == "function"
81
+ ), j = Object.fromEntries(
82
+ x.map((f) => [
83
83
  f,
84
- (...w) => l[f].call(
84
+ (...m) => s[f].call(
85
85
  {
86
- ...l,
86
+ ...s,
87
87
  [d]: c,
88
- [P]: S,
89
- [E]: x,
90
- [T]: A
88
+ [_]: S,
89
+ [b]: z,
90
+ [E]: V
91
91
  },
92
- ...w
92
+ ...m
93
93
  )
94
94
  ])
95
- ), y = { ...l, ...m };
96
- return i.set(c, y), y;
95
+ ), g = { ...s, ...j };
96
+ return i.set(c, g), g;
97
97
  }
98
- return r && typeof r == "object" ? z(r, {
98
+ return r && typeof r == "object" ? P(r, {
99
99
  ...a,
100
100
  path: c
101
101
  }) : r;
102
102
  }
103
103
  });
104
- return s.set(e, h), h;
104
+ return l.set(e, o), o;
105
105
  }
106
- function N(t, a) {
107
- return z(t, {
106
+ function M(t, a) {
107
+ return P(t, {
108
108
  ...a,
109
109
  ssr: a?.ssr ?? !0,
110
110
  verbosePath: a?.verbosePath ?? "",
@@ -115,6 +115,6 @@ function N(t, a) {
115
115
  });
116
116
  }
117
117
  export {
118
- M as defineState,
119
- N as setupStorage
118
+ L as defineState,
119
+ M as setupStorage
120
120
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),u=require("./constants-CbsduCZ7.js"),y=require("react"),S=require("./provider-client-DA53zfcT.js"),d=require("./utils-0CTNJ4ZE.js"),s=y.cache(()=>new Map),f=e=>s().get(e),v=(e,t)=>s().set(e,t);function b(e=""){const t=Symbol("test"),{size:n}=s();if(s().set(t,{}),s().size===n)throw new Error([e,"Start execution only within a React render context (per-request)."].join(" "));s().delete(t)}function x(e){return typeof e=="object"&&e!==null&&"serverSlot"in e}function p(e){const t=this[u.STATE_PATH],n=`Failed access to "${t}".`;b(n);const r=f(e.serverContextKey);if(!r)throw new Error(`${n} Reason: no data. Make sure your component is wrapped in StateVocabProvider.`);return d.get(r,t)}function i(e,t){const n={};for(const r in e){const o=e[r];if(x(o))n[r]=o.serverSlot({getState(){return p.apply(this,[{serverContextKey:t.serverContextKey}])}}),delete n[r].serverSlot,delete n[r].clientSlot;else if(o!==null&&typeof o=="object"){const c=a=>t.wrap({[r]:a});n[r]=i(o,{serverContextKey:t.serverContextKey,wrap:c})}else n[r]=o}return n.seed=r=>t.wrap(r),n}function w(e,t){t??={};const n=Object.keys(e).slice(0,3).join("-"),r=Symbol(n);return{...i(e,{serverContextKey:r,wrap:o=>o}),StateVocabProvider({children:o,value:c}){return c??={},v(r,c),l.jsx(S.StateVocabClientProvider,{clientContext:t.clientContext,value:c,children:o})}}}exports.serverify=w;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("react/jsx-runtime"),i=require("./constants-BTyJxzUH.js"),l=require("react"),y=require("./provider-client-DA53zfcT.js"),T=require("./utils-0CTNJ4ZE.js"),s=l.cache(()=>new Map),d=e=>s().get(e),f=(e,t)=>s().set(e,t);function b(e=""){const t=Symbol("test"),{size:r}=s();if(s().set(t,{}),s().size===r)throw new Error([e,"Start execution only within a React render context (per-request)."].join(" "));s().delete(t)}function x(e){return typeof e=="object"&&e!==null&&i.STATE_SERVER_SLOT in e}function E(e){const t=this[i.STATE_PATH],r=`Failed access to "${t}".`;b(r);const n=d(e.serverContextKey);if(!n)throw new Error(`${r} Reason: no data. Make sure your component is wrapped in StateVocabProvider.`);return T.get(n,t)}function a(e,t){const r={};for(const n in e){const o=e[n];if(x(o))r[n]=o[i.STATE_SERVER_SLOT]({getState(){return E.apply(this,[{serverContextKey:t.serverContextKey}])}}),delete r[i.STATE_SERVER_SLOT],delete r[i.STATE_CLIENT_SLOT];else if(o!==null&&typeof o=="object"){const c=u=>t.wrap({[n]:u});r[n]=a(o,{serverContextKey:t.serverContextKey,wrap:c})}else r[n]=o}return r.seed=n=>t.wrap(n),r}function p(e,t){t??={};const r=Object.keys(e).slice(0,3).join("-"),n=Symbol(r);return{...a(e,{serverContextKey:n,wrap:o=>o}),StateVocabProvider({children:o,value:c}){return c??={},f(n,c),S.jsx(y.StateVocabClientProvider,{clientContext:t.clientContext,value:c,children:o})}}}exports.serverify=p;
package/dist/server.es.js CHANGED
@@ -1,65 +1,65 @@
1
1
  import { jsx as l } from "react/jsx-runtime";
2
- import { S } from "./constants-BB1YAX6c.mjs";
3
- import { cache as f } from "react";
4
- import { S as u } from "./provider-client-DLa3_Ms9.mjs";
5
- import { g as y } from "./utils-xV3x3fTc.mjs";
6
- const s = f(() => /* @__PURE__ */ new Map()), p = (e) => s().get(e), x = (e, t) => s().set(e, t);
7
- function d(e = "") {
8
- const t = /* @__PURE__ */ Symbol("test"), { size: o } = s();
9
- if (s().set(t, {}), s().size === o)
2
+ import { a, b as f, S as u } from "./constants-Cf0m6moG.mjs";
3
+ import { cache as y } from "react";
4
+ import { S as p } from "./provider-client-DLa3_Ms9.mjs";
5
+ import { g as x } from "./utils-xV3x3fTc.mjs";
6
+ const s = y(() => /* @__PURE__ */ new Map()), b = (e) => s().get(e), d = (e, t) => s().set(e, t);
7
+ function m(e = "") {
8
+ const t = /* @__PURE__ */ Symbol("test"), { size: r } = s();
9
+ if (s().set(t, {}), s().size === r)
10
10
  throw new Error([
11
11
  e,
12
12
  "Start execution only within a React render context (per-request)."
13
13
  ].join(" "));
14
14
  s().delete(t);
15
15
  }
16
- function m(e) {
17
- return typeof e == "object" && e !== null && "serverSlot" in e;
16
+ function w(e) {
17
+ return typeof e == "object" && e !== null && a in e;
18
18
  }
19
- function b(e) {
20
- const t = this[S], o = `Failed access to "${t}".`;
21
- d(o);
22
- const r = p(e.serverContextKey);
23
- if (!r)
19
+ function C(e) {
20
+ const t = this[f], r = `Failed access to "${t}".`;
21
+ m(r);
22
+ const o = b(e.serverContextKey);
23
+ if (!o)
24
24
  throw new Error(
25
- `${o} Reason: no data. Make sure your component is wrapped in StateVocabProvider.`
25
+ `${r} Reason: no data. Make sure your component is wrapped in StateVocabProvider.`
26
26
  );
27
- return y(r, t);
27
+ return x(o, t);
28
28
  }
29
29
  function i(e, t) {
30
- const o = {};
31
- for (const r in e) {
32
- const n = e[r];
33
- if (m(n))
34
- o[r] = n.serverSlot({
30
+ const r = {};
31
+ for (const o in e) {
32
+ const n = e[o];
33
+ if (w(n))
34
+ r[o] = n[a]({
35
35
  getState() {
36
- return b.apply(this, [{
36
+ return C.apply(this, [{
37
37
  serverContextKey: t.serverContextKey
38
38
  }]);
39
39
  }
40
- }), delete o[r].serverSlot, delete o[r].clientSlot;
40
+ }), delete r[a], delete r[u];
41
41
  else if (n !== null && typeof n == "object") {
42
- const c = (a) => t.wrap({ [r]: a });
43
- o[r] = i(n, {
42
+ const c = (S) => t.wrap({ [o]: S });
43
+ r[o] = i(n, {
44
44
  serverContextKey: t.serverContextKey,
45
45
  wrap: c
46
46
  });
47
47
  } else
48
- o[r] = n;
48
+ r[o] = n;
49
49
  }
50
- return o.seed = (r) => t.wrap(r), o;
50
+ return r.seed = (o) => t.wrap(o), r;
51
51
  }
52
52
  function K(e, t) {
53
53
  t ??= {};
54
- const o = Object.keys(e).slice(0, 3).join("-"), r = Symbol(o);
54
+ const r = Object.keys(e).slice(0, 3).join("-"), o = Symbol(r);
55
55
  return {
56
56
  ...i(e, {
57
- serverContextKey: r,
57
+ serverContextKey: o,
58
58
  wrap: (n) => n
59
59
  }),
60
60
  StateVocabProvider({ children: n, value: c }) {
61
- return c ??= {}, x(r, c), /* @__PURE__ */ l(
62
- u,
61
+ return c ??= {}, d(o, c), /* @__PURE__ */ l(
62
+ p,
63
63
  {
64
64
  clientContext: t.clientContext,
65
65
  value: c,
@@ -3,3 +3,5 @@ export declare const STATE_PATH: unique symbol;
3
3
  export declare const STATE_VERBOSE: unique symbol;
4
4
  export declare const STATE_VERBOSE_PATH: unique symbol;
5
5
  export declare const STATE_SSR: unique symbol;
6
+ export declare const STATE_SERVER_SLOT: unique symbol;
7
+ export declare const STATE_CLIENT_SLOT: unique symbol;
@@ -1,3 +1,4 @@
1
+ import { STATE_CLIENT_SLOT } from "./constants";
1
2
  import type { Deserialize, Serialize, ValueOrFactory, ValueOrTransformer } from "./state.types";
2
3
  export type UseStateOptions<V> = {
3
4
  defaultValue?: ValueOrFactory<V>;
@@ -20,7 +21,7 @@ type Placeholder<V> = {
20
21
  useInitialState(options?: UseInitialStateOptions<V>): void;
21
22
  };
22
23
  export type ClientSlot<V> = {
23
- clientSlot(input: Placeholder<V>): Placeholder<V>;
24
+ [STATE_CLIENT_SLOT](input: Placeholder<V>): Placeholder<V>;
24
25
  };
25
26
  type Clientified<R> = R extends ClientSlot<infer V> ? Placeholder<V> : R extends object ? {
26
27
  [K in keyof R]: Clientified<R[K]>;
@@ -1,10 +1,11 @@
1
1
  import type { PropsWithChildren, ReactNode } from "react";
2
2
  import type { Vocab } from "./state.types";
3
+ import { STATE_SERVER_SLOT } from "./constants";
3
4
  type Placeholder<V> = {
4
5
  getState(): V;
5
6
  };
6
7
  export type ServerSlot<V> = {
7
- serverSlot(input: Placeholder<V>): Placeholder<V>;
8
+ [STATE_SERVER_SLOT](input: Placeholder<V>): Placeholder<V>;
8
9
  };
9
10
  type ServerifiedValue<R> = {
10
11
  [K in keyof R]?: R[K] extends ServerSlot<infer V> ? V : R[K] extends object ? ServerifiedValue<R[K]> : R[K];
@@ -1,5 +1,5 @@
1
1
  import type { Deserialize, Serialize, ValueOrFactory, ValueOrTransformer, VocabThis } from "./state.types";
2
- import { STATE_DEFINITION, STATE_PATH, STATE_SSR, STATE_VERBOSE, STATE_VERBOSE_PATH } from "./constants";
2
+ import { STATE_CLIENT_SLOT, STATE_DEFINITION, STATE_PATH, STATE_SERVER_SLOT, STATE_SSR, STATE_VERBOSE, STATE_VERBOSE_PATH } from "./constants";
3
3
  export declare function defineState<V>(superOptions?: {
4
4
  defaultValue?: ValueOrFactory<V>;
5
5
  bidirectional?: true;
@@ -12,12 +12,12 @@ export declare function defineState<V>(superOptions?: {
12
12
  [STATE_VERBOSE]: boolean;
13
13
  [STATE_VERBOSE_PATH]: string;
14
14
  [STATE_SSR]: boolean;
15
- serverSlot(this: VocabThis, input: {
15
+ [STATE_SERVER_SLOT](this: VocabThis, input: {
16
16
  getState(this: VocabThis): V;
17
17
  }): VocabThis & {
18
18
  getState(this: VocabThis): V;
19
19
  };
20
- clientSlot(this: VocabThis, input: {
20
+ [STATE_CLIENT_SLOT](this: VocabThis, input: {
21
21
  useState(this: VocabThis, options?: {
22
22
  defaultValue?: ValueOrFactory<V>;
23
23
  delayedSet?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yakocloud/state-vocab",
3
- "version": "4.3.0",
3
+ "version": "4.3.1",
4
4
  "main": "dist/index.cjs.js",
5
5
  "module": "dist/index.es.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -1,8 +0,0 @@
1
- const s = /* @__PURE__ */ Symbol("state-def"), t = /* @__PURE__ */ Symbol("state-path"), S = /* @__PURE__ */ Symbol("state-verbose"), a = /* @__PURE__ */ Symbol("state-verbose-path"), o = /* @__PURE__ */ Symbol("state-ssr");
2
- export {
3
- t as S,
4
- S as a,
5
- o as b,
6
- a as c,
7
- s as d
8
- };
@@ -1 +0,0 @@
1
- "use strict";const T=Symbol("state-def"),S=Symbol("state-path"),E=Symbol("state-verbose"),t=Symbol("state-verbose-path"),s=Symbol("state-ssr");exports.STATE_DEFINITION=T;exports.STATE_PATH=S;exports.STATE_SSR=s;exports.STATE_VERBOSE=E;exports.STATE_VERBOSE_PATH=t;