@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.
- package/dist/client.cjs.js +1 -1
- package/dist/client.es.js +56 -56
- package/dist/constants-BTyJxzUH.js +1 -0
- package/dist/constants-Cf0m6moG.mjs +10 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.es.js +46 -46
- package/dist/server.cjs.js +1 -1
- package/dist/server.es.js +32 -32
- package/dist/types/constants.d.ts +2 -0
- package/dist/types/setup.client.types.d.ts +2 -1
- package/dist/types/setup.server.types.d.ts +2 -1
- package/dist/types/state.d.ts +3 -3
- package/package.json +1 -1
- package/dist/constants-BB1YAX6c.mjs +0 -8
- package/dist/constants-CbsduCZ7.js +0 -1
package/dist/client.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react"),
|
|
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
|
|
3
|
-
import { S as
|
|
4
|
-
import { a as d, d as
|
|
5
|
-
import { V as y, u as
|
|
6
|
-
import { S as
|
|
7
|
-
function
|
|
8
|
-
return
|
|
9
|
-
() =>
|
|
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
|
|
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
|
|
26
|
-
return typeof t == "object" && t !== null &&
|
|
25
|
+
function W(t) {
|
|
26
|
+
return typeof t == "object" && t !== null && T in t;
|
|
27
27
|
}
|
|
28
|
-
const z = typeof window > "u",
|
|
29
|
-
function
|
|
30
|
-
const s = z ? void 0 :
|
|
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(
|
|
38
|
-
r =
|
|
37
|
+
throw new Error(J);
|
|
38
|
+
r = k;
|
|
39
39
|
}
|
|
40
|
-
const f = t.serialize ?? JSON.stringify, c = t.deserialize ?? JSON.parse, v =
|
|
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),
|
|
46
|
-
if (!
|
|
47
|
-
|
|
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 &&
|
|
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
|
|
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 =
|
|
66
|
-
n &&
|
|
65
|
+
const n = x(V, l);
|
|
66
|
+
n && A(n);
|
|
67
67
|
} else
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
b.current =
|
|
71
|
-
!u || !s ||
|
|
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:
|
|
75
|
+
value: h,
|
|
76
76
|
serialize: f,
|
|
77
77
|
deserialize: c
|
|
78
78
|
});
|
|
79
79
|
}, []);
|
|
80
|
-
const
|
|
80
|
+
const w = H((n) => {
|
|
81
81
|
if (n.key !== e)
|
|
82
82
|
return;
|
|
83
|
-
const S = n.newValue,
|
|
84
|
-
d(
|
|
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
|
-
|
|
86
|
+
_(() => {
|
|
87
87
|
if (o)
|
|
88
|
-
return window.addEventListener("storage",
|
|
88
|
+
return window.addEventListener("storage", w), () => window.removeEventListener("storage", w);
|
|
89
89
|
}, [o]);
|
|
90
|
-
const
|
|
91
|
-
const S =
|
|
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]),
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
h,
|
|
103
|
+
M,
|
|
104
|
+
j
|
|
105
105
|
];
|
|
106
106
|
}
|
|
107
|
-
function
|
|
108
|
-
const s = z ? void 0 :
|
|
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(
|
|
116
|
-
l =
|
|
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 &&
|
|
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
|
-
})),
|
|
128
|
-
!a || !s ||
|
|
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
|
|
138
|
+
function Z(t, s = {}) {
|
|
139
139
|
const i = {};
|
|
140
140
|
for (const o in t) {
|
|
141
141
|
const e = t[o];
|
|
142
|
-
|
|
142
|
+
W(e) ? (i[o] = e[T]({
|
|
143
143
|
useState(a) {
|
|
144
|
-
return
|
|
144
|
+
return X.apply(this, [{
|
|
145
145
|
clientContext: s.clientContext,
|
|
146
146
|
...a
|
|
147
147
|
}]);
|
|
148
148
|
},
|
|
149
149
|
useInitialState(a) {
|
|
150
|
-
|
|
150
|
+
Y.apply(this, [{
|
|
151
151
|
clientContext: s.clientContext,
|
|
152
152
|
...a
|
|
153
153
|
}]);
|
|
154
154
|
}
|
|
155
|
-
}), delete i[
|
|
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
|
-
|
|
161
|
-
|
|
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
|
|
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 {
|
|
2
|
-
import { v as
|
|
3
|
-
function
|
|
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
|
-
[
|
|
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
|
-
[
|
|
9
|
+
[_]: !1,
|
|
10
10
|
// placeholder
|
|
11
|
-
[
|
|
11
|
+
[b]: "",
|
|
12
12
|
// placeholder
|
|
13
|
-
[
|
|
13
|
+
[E]: !1,
|
|
14
14
|
// placeholder
|
|
15
|
-
|
|
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
|
-
|
|
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:
|
|
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
|
|
56
|
+
function P(t, a) {
|
|
57
57
|
const {
|
|
58
58
|
path: e = "",
|
|
59
59
|
verbose: S,
|
|
60
|
-
verbosePath:
|
|
61
|
-
ssr:
|
|
60
|
+
verbosePath: z,
|
|
61
|
+
ssr: V,
|
|
62
62
|
cache: n
|
|
63
63
|
} = a;
|
|
64
|
-
let
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
if (
|
|
68
|
-
return
|
|
69
|
-
const
|
|
70
|
-
get(
|
|
71
|
-
const r =
|
|
72
|
-
if (r && typeof r == "object" &&
|
|
73
|
-
const
|
|
74
|
-
let i = n.leaf.get(
|
|
75
|
-
i || (i = /* @__PURE__ */ new Map(), n.leaf.set(
|
|
76
|
-
const
|
|
77
|
-
if (
|
|
78
|
-
return
|
|
79
|
-
const
|
|
80
|
-
(f) => typeof
|
|
81
|
-
),
|
|
82
|
-
|
|
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
|
-
(...
|
|
84
|
+
(...m) => s[f].call(
|
|
85
85
|
{
|
|
86
|
-
...
|
|
86
|
+
...s,
|
|
87
87
|
[d]: c,
|
|
88
|
-
[
|
|
89
|
-
[
|
|
90
|
-
[
|
|
88
|
+
[_]: S,
|
|
89
|
+
[b]: z,
|
|
90
|
+
[E]: V
|
|
91
91
|
},
|
|
92
|
-
...
|
|
92
|
+
...m
|
|
93
93
|
)
|
|
94
94
|
])
|
|
95
|
-
),
|
|
96
|
-
return i.set(c,
|
|
95
|
+
), g = { ...s, ...j };
|
|
96
|
+
return i.set(c, g), g;
|
|
97
97
|
}
|
|
98
|
-
return r && typeof r == "object" ?
|
|
98
|
+
return r && typeof r == "object" ? P(r, {
|
|
99
99
|
...a,
|
|
100
100
|
path: c
|
|
101
101
|
}) : r;
|
|
102
102
|
}
|
|
103
103
|
});
|
|
104
|
-
return
|
|
104
|
+
return l.set(e, o), o;
|
|
105
105
|
}
|
|
106
|
-
function
|
|
107
|
-
return
|
|
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
|
-
|
|
119
|
-
|
|
118
|
+
L as defineState,
|
|
119
|
+
M as setupStorage
|
|
120
120
|
};
|
package/dist/server.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
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-
|
|
3
|
-
import { cache as
|
|
4
|
-
import { S as
|
|
5
|
-
import { g as
|
|
6
|
-
const s =
|
|
7
|
-
function
|
|
8
|
-
const t = /* @__PURE__ */ Symbol("test"), { size:
|
|
9
|
-
if (s().set(t, {}), s().size ===
|
|
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
|
|
17
|
-
return typeof e == "object" && e !== null &&
|
|
16
|
+
function w(e) {
|
|
17
|
+
return typeof e == "object" && e !== null && a in e;
|
|
18
18
|
}
|
|
19
|
-
function
|
|
20
|
-
const t = this[
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
if (!
|
|
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
|
-
`${
|
|
25
|
+
`${r} Reason: no data. Make sure your component is wrapped in StateVocabProvider.`
|
|
26
26
|
);
|
|
27
|
-
return
|
|
27
|
+
return x(o, t);
|
|
28
28
|
}
|
|
29
29
|
function i(e, t) {
|
|
30
|
-
const
|
|
31
|
-
for (const
|
|
32
|
-
const n = e[
|
|
33
|
-
if (
|
|
34
|
-
o
|
|
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
|
|
36
|
+
return C.apply(this, [{
|
|
37
37
|
serverContextKey: t.serverContextKey
|
|
38
38
|
}]);
|
|
39
39
|
}
|
|
40
|
-
}), delete
|
|
40
|
+
}), delete r[a], delete r[u];
|
|
41
41
|
else if (n !== null && typeof n == "object") {
|
|
42
|
-
const c = (
|
|
43
|
-
o
|
|
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
|
|
48
|
+
r[o] = n;
|
|
49
49
|
}
|
|
50
|
-
return
|
|
50
|
+
return r.seed = (o) => t.wrap(o), r;
|
|
51
51
|
}
|
|
52
52
|
function K(e, t) {
|
|
53
53
|
t ??= {};
|
|
54
|
-
const
|
|
54
|
+
const r = Object.keys(e).slice(0, 3).join("-"), o = Symbol(r);
|
|
55
55
|
return {
|
|
56
56
|
...i(e, {
|
|
57
|
-
serverContextKey:
|
|
57
|
+
serverContextKey: o,
|
|
58
58
|
wrap: (n) => n
|
|
59
59
|
}),
|
|
60
60
|
StateVocabProvider({ children: n, value: c }) {
|
|
61
|
-
return c ??= {},
|
|
62
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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];
|
package/dist/types/state.d.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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,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;
|