@yakocloud/state-vocab 2.1.2 → 2.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/dist/state-vocab.cjs.js +4 -4
- package/dist/state-vocab.es.js +261 -245
- package/dist/types/constants.d.ts +1 -0
- package/dist/types/setup.d.ts +3 -1
- package/dist/types/state.d.ts +3 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -149,10 +149,14 @@ const birthday = defineState({
|
|
|
149
149
|
})
|
|
150
150
|
```
|
|
151
151
|
|
|
152
|
-
### `setupStorage(tree)`
|
|
152
|
+
### `setupStorage(tree, options)`
|
|
153
153
|
|
|
154
154
|
Wraps a nested object of `defineState()` nodes and injects dot-separated paths into each leaf. The returned object mirrors your tree structure.
|
|
155
155
|
|
|
156
|
+
| Parameter | Type | Description | Default
|
|
157
|
+
|---|---|---|
|
|
158
|
+
| `ssr` | `boolean \| undefined` | SSR support | false
|
|
159
|
+
|
|
156
160
|
```ts
|
|
157
161
|
const storage = setupStorage({
|
|
158
162
|
user: {
|
package/dist/state-vocab.cjs.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
`),
|
|
3
|
-
`),...
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _=require("react"),K=Symbol("state-def"),C=Symbol("state-path"),D=Symbol("state-ssr-support");function fe(t,c,a){if(!c)return t;const s=c.split(".");let r=t;for(const o of s)if(r!==null&&typeof r=="object"&&o in r)r=r[o];else return a;return r===void 0?a:r}function de(t,c,a){const s=c.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(let o=0;o<s.length-1;o++){const i=s[o],b=s[o+1];(r[i]===void 0||r[i]===null)&&(r[i]=/^\d+$/.test(b)?[]:{}),r=r[i]}return r[s[s.length-1]]=a,t}function me(t,c=0){let a;return function(...s){a!==void 0&&clearTimeout(a),a=setTimeout(()=>{a=void 0,t.apply(this,s)},c)}}function be(t,c,a=[]){return _.useMemo(()=>me(t,c),a)}function ve(t){const c=JSON.stringify(t,null,2).split(`
|
|
2
|
+
`),a=[],s=[];for(const r of c){const o=r.match(/^(\s*)"([^"]+)"(\s*:\s*)(.+)$/);if(o){const[,i,b,R,f]=o;a.push(`${i}%c"${b}"%c${R}%c${f}`),s.push("color: #9cdcfe; font-weight: bold","color: #cccccc","color: #ce9178")}else a.push(`%c${r}`),s.push("color: #cccccc")}console.log(a.join(`
|
|
3
|
+
`),...s,t)}var j={exports:{}},O={};var G;function pe(){if(G)return O;G=1;var t=Symbol.for("react.transitional.element"),c=Symbol.for("react.fragment");function a(s,r,o){var i=null;if(o!==void 0&&(i=""+o),r.key!==void 0&&(i=""+r.key),"key"in r){o={};for(var b in r)b!=="key"&&(o[b]=r[b])}else o=r;return r=o.ref,{$$typeof:t,type:s,key:i,ref:r!==void 0?r:null,props:o}}return O.Fragment=c,O.jsx=a,O.jsxs=a,O}var x={};var X;function Ee(){return X||(X=1,process.env.NODE_ENV!=="production"&&(function(){function t(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===ue?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case p:return"Fragment";case v:return"Profiler";case E:return"StrictMode";case oe:return"Suspense";case ae:return"SuspenseList";case ce:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case k:return"Portal";case P:return e.displayName||"Context";case h:return(e._context.displayName||"Context")+".Consumer";case ne:var n=e.render;return e=e.displayName,e||(e=n.displayName||n.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case se:return n=e.displayName||null,n!==null?n:t(e.type)||"Memo";case V:n=e._payload,e=e._init;try{return t(e(n))}catch{}}return null}function c(e){return""+e}function a(e){try{c(e);var n=!1}catch{n=!0}if(n){n=console;var u=n.error,d=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return u.call(n,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",d),c(e)}}function s(e){if(e===p)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===V)return"<...>";try{var n=t(e);return n?"<"+n+">":"<...>"}catch{return"<...>"}}function r(){var e=$.A;return e===null?null:e.getOwner()}function o(){return Error("react-stack-top-frame")}function i(e){if(L.call(e,"key")){var n=Object.getOwnPropertyDescriptor(e,"key").get;if(n&&n.isReactWarning)return!1}return e.key!==void 0}function b(e,n){function u(){z||(z=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",n))}u.isReactWarning=!0,Object.defineProperty(e,"key",{get:u,configurable:!0})}function R(){var e=t(this.type);return W[e]||(W[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function f(e,n,u,d,A,M){var m=u.ref;return e={$$typeof:y,type:e,key:n,props:u,_owner:d},(m!==void 0?m:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:R}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:A}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:M}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function l(e,n,u,d,A,M){var m=n.children;if(m!==void 0)if(d)if(le(m)){for(d=0;d<m.length;d++)S(m[d]);Object.freeze&&Object.freeze(m)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else S(m);if(L.call(n,"key")){m=t(e);var w=Object.keys(n).filter(function(ie){return ie!=="key"});d=0<w.length?"{key: someKey, "+w.join(": ..., ")+": ...}":"{key: someKey}",q[m+d]||(w=0<w.length?"{"+w.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
4
4
|
let props = %s;
|
|
5
5
|
<%s {...props} />
|
|
6
6
|
React keys must be passed directly to JSX without using spread:
|
|
7
7
|
let props = %s;
|
|
8
|
-
<%s key={someKey} {...props} />`,m,
|
|
8
|
+
<%s key={someKey} {...props} />`,d,m,w,m),q[m+d]=!0)}if(m=null,u!==void 0&&(a(u),m=""+u),i(n)&&(a(n.key),m=""+n.key),"key"in n){u={};for(var Y in n)Y!=="key"&&(u[Y]=n[Y])}else u=n;return m&&b(u,typeof e=="function"?e.displayName||e.name||"Unknown":e),f(e,m,u,r(),A,M)}function S(e){T(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===V&&(e._payload.status==="fulfilled"?T(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function T(e){return typeof e=="object"&&e!==null&&e.$$typeof===y}var g=_,y=Symbol.for("react.transitional.element"),k=Symbol.for("react.portal"),p=Symbol.for("react.fragment"),E=Symbol.for("react.strict_mode"),v=Symbol.for("react.profiler"),h=Symbol.for("react.consumer"),P=Symbol.for("react.context"),ne=Symbol.for("react.forward_ref"),oe=Symbol.for("react.suspense"),ae=Symbol.for("react.suspense_list"),se=Symbol.for("react.memo"),V=Symbol.for("react.lazy"),ce=Symbol.for("react.activity"),ue=Symbol.for("react.client.reference"),$=g.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,L=Object.prototype.hasOwnProperty,le=Array.isArray,I=console.createTask?console.createTask:function(){return null};g={react_stack_bottom_frame:function(e){return e()}};var z,W={},J=g.react_stack_bottom_frame.bind(g,o)(),U=I(s(o)),q={};x.Fragment=p,x.jsx=function(e,n,u){var d=1e4>$.recentlyCreatedOwnerStacks++;return l(e,n,u,!1,d?Error("react-stack-top-frame"):J,d?I(s(e)):U)},x.jsxs=function(e,n,u){var d=1e4>$.recentlyCreatedOwnerStacks++;return l(e,n,u,!0,d?Error("react-stack-top-frame"):J,d?I(s(e)):U)}})()),x}var B;function Se(){return B||(B=1,process.env.NODE_ENV==="production"?j.exports=pe():j.exports=Ee()),j.exports}var _e=Se();const ee=_.createContext({stateVocab:{},setStateVocab:()=>{}});function Re(){return _.useContext(ee)}const Te=t=>{const{children:c,verbose:a}=t,[s,r]=_.useState({});return a&&ve(s),_e.jsx(ee.Provider,{value:{stateVocab:s,setStateVocab:r},children:c})},N=(t,c)=>a=>{const s={...a};return de(s,t,c),s},F=(t,c)=>te(t)??c,H=t=>{const{serialized:c,defaultValue:a,superDefaultValue:s,deserialize:r}=t;if(c===null){const o=F(a,s);return typeof o>"u"?void 0:o}return r(c)},ye=t=>typeof t=="function",ge=t=>typeof t=="function",te=t=>ge(t)?t():t,he=typeof window>"u";function ke(t={}){const{serialize:c=JSON.stringify,deserialize:a=JSON.parse}=t,s=t.defaultValue,r=t.bidirectional,o=he?void 0:te(t.storage);return{[K]:!0,[D]:!1,[C]:"",useState(i,b){b??={};const R=be(b.onSet??(()=>{}),b.delayedSet,[]),f=Re(),l=this[C],S=this[D],[T,g]=_.useState(!S);_.useEffect(()=>g(!0),[]);const y=_.useMemo(()=>{if(!T||!o)return;const E=o.getItem(l);return H({serialized:E,defaultValue:i,superDefaultValue:s,deserialize:a})},[l,T]),k=_.useMemo(()=>fe(f.stateVocab,l,y??F(i,s)),[f.stateVocab,y,l]);_.useEffect(()=>{!o||typeof y>"u"||f.setStateVocab(N(l,y))},[y]),_.useEffect(()=>{if(!b.bidirectional&&!r)return;const E=v=>{if(v.key!==l)return;const h=v.newValue,P=H({serialized:h,defaultValue:i,superDefaultValue:s,deserialize:a});f.setStateVocab(N(l,P)),R(P,p.current),p.current=P};return window.addEventListener("storage",E),()=>window.removeEventListener("storage",E)},[l,b.bidirectional,r]);const p=_.useRef(k);return[k,function(v){const h=ye(v)?v(p.current):v;f.setStateVocab(N(l,h)),R(h,p.current),o&&o.setItem(l,c(h)),p.current=h},function(){const v=F(i,s);if(typeof v>"u"){o?.removeItem(l);return}f.setStateVocab(N(l,v)),R(v,p.current),p.current=v,o&&o.setItem(l,c(v))}]},toString(){return this[C]}}}const Z=new WeakMap,Q=new WeakMap;function re(t,c){c??={};const{path:a="",ssr:s}=c;let r=Z.get(t);r||(r=new Map,Z.set(t,r));const o=r.get(a);if(o)return o;const i=new Proxy(t,{get(b,R){const f=b[R],l=a?`${a}.${String(R)}`:String(R);if(f&&typeof f=="object"&&K in f){const S=f;let T=Q.get(S);T||(T=new Map,Q.set(S,T));const g=T.get(l);if(g)return g;const y=Reflect.ownKeys(S).filter(E=>typeof S[E]=="function"),k=Object.fromEntries(y.map(E=>[E,(...v)=>S[E].call({...S,[C]:l,[D]:s},...v)])),p={...S,...k};return T.set(l,p),p}return f&&typeof f=="object"?re(f,{path:l,ssr:s}):f}});return r.set(a,i),i}function we(t,c){return re(t,c)}exports.StorageProvider=Te;exports.defineState=ke;exports.setupStorage=we;
|
package/dist/state-vocab.es.js
CHANGED
|
@@ -1,121 +1,121 @@
|
|
|
1
|
-
import
|
|
2
|
-
const
|
|
3
|
-
function Ee(t, c,
|
|
1
|
+
import me, { useMemo as F, createContext as be, useState as ee, useContext as ve, useEffect as D, useRef as pe } from "react";
|
|
2
|
+
const te = Symbol("state-def"), N = Symbol("state-path"), M = Symbol("state-ssr-support");
|
|
3
|
+
function Ee(t, c, a) {
|
|
4
4
|
if (!c)
|
|
5
5
|
return t;
|
|
6
|
-
const
|
|
6
|
+
const s = c.split(".");
|
|
7
7
|
let r = t;
|
|
8
|
-
for (const
|
|
9
|
-
if (r !== null && typeof r == "object" &&
|
|
10
|
-
r = r[
|
|
8
|
+
for (const o of s)
|
|
9
|
+
if (r !== null && typeof r == "object" && o in r)
|
|
10
|
+
r = r[o];
|
|
11
11
|
else
|
|
12
|
-
return
|
|
13
|
-
return r === void 0 ?
|
|
12
|
+
return a;
|
|
13
|
+
return r === void 0 ? a : r;
|
|
14
14
|
}
|
|
15
|
-
function
|
|
16
|
-
const
|
|
15
|
+
function _e(t, c, a) {
|
|
16
|
+
const s = c.replace(/\[(\d+)\]/g, ".$1").split(".");
|
|
17
17
|
let r = t;
|
|
18
|
-
for (let
|
|
19
|
-
const
|
|
20
|
-
(r[
|
|
18
|
+
for (let o = 0; o < s.length - 1; o++) {
|
|
19
|
+
const i = s[o], b = s[o + 1];
|
|
20
|
+
(r[i] === void 0 || r[i] === null) && (r[i] = /^\d+$/.test(b) ? [] : {}), r = r[i];
|
|
21
21
|
}
|
|
22
|
-
return r[
|
|
22
|
+
return r[s[s.length - 1]] = a, t;
|
|
23
23
|
}
|
|
24
|
-
function
|
|
25
|
-
let
|
|
26
|
-
return function(...
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
function Se(t, c = 0) {
|
|
25
|
+
let a;
|
|
26
|
+
return function(...s) {
|
|
27
|
+
a !== void 0 && clearTimeout(a), a = setTimeout(() => {
|
|
28
|
+
a = void 0, t.apply(this, s);
|
|
29
29
|
}, c);
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
-
function
|
|
33
|
-
return
|
|
34
|
-
() =>
|
|
32
|
+
function Re(t, c, a = []) {
|
|
33
|
+
return F(
|
|
34
|
+
() => Se(t, c),
|
|
35
35
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
36
|
-
|
|
36
|
+
a
|
|
37
37
|
);
|
|
38
38
|
}
|
|
39
|
-
function
|
|
39
|
+
function Te(t) {
|
|
40
40
|
const c = JSON.stringify(t, null, 2).split(`
|
|
41
|
-
`),
|
|
41
|
+
`), a = [], s = [];
|
|
42
42
|
for (const r of c) {
|
|
43
|
-
const
|
|
44
|
-
if (
|
|
45
|
-
const [,
|
|
46
|
-
|
|
43
|
+
const o = r.match(/^(\s*)"([^"]+)"(\s*:\s*)(.+)$/);
|
|
44
|
+
if (o) {
|
|
45
|
+
const [, i, b, S, f] = o;
|
|
46
|
+
a.push(`${i}%c"${b}"%c${S}%c${f}`), s.push(
|
|
47
47
|
"color: #9cdcfe; font-weight: bold",
|
|
48
48
|
"color: #cccccc",
|
|
49
49
|
"color: #ce9178"
|
|
50
50
|
);
|
|
51
51
|
} else
|
|
52
|
-
|
|
52
|
+
a.push(`%c${r}`), s.push("color: #cccccc");
|
|
53
53
|
}
|
|
54
|
-
console.log(
|
|
55
|
-
`), ...
|
|
54
|
+
console.log(a.join(`
|
|
55
|
+
`), ...s, t);
|
|
56
56
|
}
|
|
57
|
-
var
|
|
58
|
-
var
|
|
57
|
+
var A = { exports: {} }, P = {};
|
|
58
|
+
var X;
|
|
59
59
|
function ye() {
|
|
60
|
-
if (
|
|
61
|
-
|
|
60
|
+
if (X) return P;
|
|
61
|
+
X = 1;
|
|
62
62
|
var t = Symbol.for("react.transitional.element"), c = Symbol.for("react.fragment");
|
|
63
|
-
function
|
|
64
|
-
var
|
|
65
|
-
if (
|
|
66
|
-
|
|
67
|
-
for (var
|
|
68
|
-
|
|
69
|
-
} else
|
|
70
|
-
return r =
|
|
63
|
+
function a(s, r, o) {
|
|
64
|
+
var i = null;
|
|
65
|
+
if (o !== void 0 && (i = "" + o), r.key !== void 0 && (i = "" + r.key), "key" in r) {
|
|
66
|
+
o = {};
|
|
67
|
+
for (var b in r)
|
|
68
|
+
b !== "key" && (o[b] = r[b]);
|
|
69
|
+
} else o = r;
|
|
70
|
+
return r = o.ref, {
|
|
71
71
|
$$typeof: t,
|
|
72
|
-
type:
|
|
73
|
-
key:
|
|
72
|
+
type: s,
|
|
73
|
+
key: i,
|
|
74
74
|
ref: r !== void 0 ? r : null,
|
|
75
|
-
props:
|
|
75
|
+
props: o
|
|
76
76
|
};
|
|
77
77
|
}
|
|
78
|
-
return
|
|
78
|
+
return P.Fragment = c, P.jsx = a, P.jsxs = a, P;
|
|
79
79
|
}
|
|
80
|
-
var
|
|
81
|
-
var
|
|
82
|
-
function
|
|
83
|
-
return
|
|
80
|
+
var x = {};
|
|
81
|
+
var B;
|
|
82
|
+
function ge() {
|
|
83
|
+
return B || (B = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
84
84
|
function t(e) {
|
|
85
85
|
if (e == null) return null;
|
|
86
86
|
if (typeof e == "function")
|
|
87
|
-
return e.$$typeof ===
|
|
87
|
+
return e.$$typeof === ie ? null : e.displayName || e.name || null;
|
|
88
88
|
if (typeof e == "string") return e;
|
|
89
89
|
switch (e) {
|
|
90
|
-
case
|
|
90
|
+
case p:
|
|
91
91
|
return "Fragment";
|
|
92
|
-
case
|
|
92
|
+
case v:
|
|
93
93
|
return "Profiler";
|
|
94
|
-
case
|
|
94
|
+
case E:
|
|
95
95
|
return "StrictMode";
|
|
96
|
-
case
|
|
96
|
+
case se:
|
|
97
97
|
return "Suspense";
|
|
98
|
-
case ae:
|
|
99
|
-
return "SuspenseList";
|
|
100
98
|
case ce:
|
|
99
|
+
return "SuspenseList";
|
|
100
|
+
case le:
|
|
101
101
|
return "Activity";
|
|
102
102
|
}
|
|
103
103
|
if (typeof e == "object")
|
|
104
104
|
switch (typeof e.tag == "number" && console.error(
|
|
105
105
|
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
|
|
106
106
|
), e.$$typeof) {
|
|
107
|
-
case
|
|
107
|
+
case h:
|
|
108
108
|
return "Portal";
|
|
109
|
-
case
|
|
109
|
+
case w:
|
|
110
110
|
return e.displayName || "Context";
|
|
111
|
-
case
|
|
111
|
+
case g:
|
|
112
112
|
return (e._context.displayName || "Context") + ".Consumer";
|
|
113
|
-
case
|
|
113
|
+
case ae:
|
|
114
114
|
var n = e.render;
|
|
115
115
|
return e = e.displayName, e || (e = n.displayName || n.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
|
|
116
|
-
case
|
|
116
|
+
case ue:
|
|
117
117
|
return n = e.displayName || null, n !== null ? n : t(e.type) || "Memo";
|
|
118
|
-
case
|
|
118
|
+
case C:
|
|
119
119
|
n = e._payload, e = e._init;
|
|
120
120
|
try {
|
|
121
121
|
return t(e(n));
|
|
@@ -127,7 +127,7 @@ function Te() {
|
|
|
127
127
|
function c(e) {
|
|
128
128
|
return "" + e;
|
|
129
129
|
}
|
|
130
|
-
function
|
|
130
|
+
function a(e) {
|
|
131
131
|
try {
|
|
132
132
|
c(e);
|
|
133
133
|
var n = !1;
|
|
@@ -136,17 +136,17 @@ function Te() {
|
|
|
136
136
|
}
|
|
137
137
|
if (n) {
|
|
138
138
|
n = console;
|
|
139
|
-
var
|
|
140
|
-
return
|
|
139
|
+
var u = n.error, d = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
|
|
140
|
+
return u.call(
|
|
141
141
|
n,
|
|
142
142
|
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
|
143
|
-
|
|
143
|
+
d
|
|
144
144
|
), c(e);
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
|
-
function
|
|
148
|
-
if (e ===
|
|
149
|
-
if (typeof e == "object" && e !== null && e.$$typeof ===
|
|
147
|
+
function s(e) {
|
|
148
|
+
if (e === p) return "<>";
|
|
149
|
+
if (typeof e == "object" && e !== null && e.$$typeof === C)
|
|
150
150
|
return "<...>";
|
|
151
151
|
try {
|
|
152
152
|
var n = t(e);
|
|
@@ -156,48 +156,48 @@ function Te() {
|
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
158
|
function r() {
|
|
159
|
-
var e =
|
|
159
|
+
var e = V.A;
|
|
160
160
|
return e === null ? null : e.getOwner();
|
|
161
161
|
}
|
|
162
|
-
function
|
|
162
|
+
function o() {
|
|
163
163
|
return Error("react-stack-top-frame");
|
|
164
164
|
}
|
|
165
|
-
function
|
|
166
|
-
if (
|
|
165
|
+
function i(e) {
|
|
166
|
+
if (z.call(e, "key")) {
|
|
167
167
|
var n = Object.getOwnPropertyDescriptor(e, "key").get;
|
|
168
168
|
if (n && n.isReactWarning) return !1;
|
|
169
169
|
}
|
|
170
170
|
return e.key !== void 0;
|
|
171
171
|
}
|
|
172
|
-
function
|
|
173
|
-
function
|
|
174
|
-
|
|
172
|
+
function b(e, n) {
|
|
173
|
+
function u() {
|
|
174
|
+
W || (W = !0, console.error(
|
|
175
175
|
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
|
|
176
176
|
n
|
|
177
177
|
));
|
|
178
178
|
}
|
|
179
|
-
|
|
180
|
-
get:
|
|
179
|
+
u.isReactWarning = !0, Object.defineProperty(e, "key", {
|
|
180
|
+
get: u,
|
|
181
181
|
configurable: !0
|
|
182
182
|
});
|
|
183
183
|
}
|
|
184
|
-
function
|
|
184
|
+
function S() {
|
|
185
185
|
var e = t(this.type);
|
|
186
|
-
return
|
|
186
|
+
return J[e] || (J[e] = !0, console.error(
|
|
187
187
|
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
|
|
188
188
|
)), e = this.props.ref, e !== void 0 ? e : null;
|
|
189
189
|
}
|
|
190
|
-
function
|
|
191
|
-
var
|
|
190
|
+
function f(e, n, u, d, O, I) {
|
|
191
|
+
var m = u.ref;
|
|
192
192
|
return e = {
|
|
193
|
-
$$typeof:
|
|
193
|
+
$$typeof: T,
|
|
194
194
|
type: e,
|
|
195
195
|
key: n,
|
|
196
|
-
props:
|
|
197
|
-
_owner:
|
|
198
|
-
}, (
|
|
196
|
+
props: u,
|
|
197
|
+
_owner: d
|
|
198
|
+
}, (m !== void 0 ? m : null) !== null ? Object.defineProperty(e, "ref", {
|
|
199
199
|
enumerable: !1,
|
|
200
|
-
get:
|
|
200
|
+
get: S
|
|
201
201
|
}) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
|
|
202
202
|
configurable: !1,
|
|
203
203
|
enumerable: !1,
|
|
@@ -212,263 +212,279 @@ function Te() {
|
|
|
212
212
|
configurable: !1,
|
|
213
213
|
enumerable: !1,
|
|
214
214
|
writable: !0,
|
|
215
|
-
value:
|
|
215
|
+
value: O
|
|
216
216
|
}), Object.defineProperty(e, "_debugTask", {
|
|
217
217
|
configurable: !1,
|
|
218
218
|
enumerable: !1,
|
|
219
219
|
writable: !0,
|
|
220
|
-
value:
|
|
220
|
+
value: I
|
|
221
221
|
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
|
|
222
222
|
}
|
|
223
|
-
function l(e, n,
|
|
224
|
-
var
|
|
225
|
-
if (
|
|
226
|
-
if (
|
|
227
|
-
if (
|
|
228
|
-
for (
|
|
229
|
-
|
|
230
|
-
Object.freeze && Object.freeze(
|
|
223
|
+
function l(e, n, u, d, O, I) {
|
|
224
|
+
var m = n.children;
|
|
225
|
+
if (m !== void 0)
|
|
226
|
+
if (d)
|
|
227
|
+
if (fe(m)) {
|
|
228
|
+
for (d = 0; d < m.length; d++)
|
|
229
|
+
_(m[d]);
|
|
230
|
+
Object.freeze && Object.freeze(m);
|
|
231
231
|
} else
|
|
232
232
|
console.error(
|
|
233
233
|
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
|
|
234
234
|
);
|
|
235
|
-
else
|
|
236
|
-
if (
|
|
237
|
-
|
|
238
|
-
var
|
|
239
|
-
return
|
|
235
|
+
else _(m);
|
|
236
|
+
if (z.call(n, "key")) {
|
|
237
|
+
m = t(e);
|
|
238
|
+
var k = Object.keys(n).filter(function(de) {
|
|
239
|
+
return de !== "key";
|
|
240
240
|
});
|
|
241
|
-
|
|
241
|
+
d = 0 < k.length ? "{key: someKey, " + k.join(": ..., ") + ": ...}" : "{key: someKey}", G[m + d] || (k = 0 < k.length ? "{" + k.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
242
242
|
`A props object containing a "key" prop is being spread into JSX:
|
|
243
243
|
let props = %s;
|
|
244
244
|
<%s {...props} />
|
|
245
245
|
React keys must be passed directly to JSX without using spread:
|
|
246
246
|
let props = %s;
|
|
247
247
|
<%s key={someKey} {...props} />`,
|
|
248
|
+
d,
|
|
248
249
|
m,
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
), z[b + m] = !0);
|
|
250
|
+
k,
|
|
251
|
+
m
|
|
252
|
+
), G[m + d] = !0);
|
|
253
253
|
}
|
|
254
|
-
if (
|
|
255
|
-
|
|
256
|
-
for (var
|
|
257
|
-
|
|
258
|
-
} else
|
|
259
|
-
return
|
|
260
|
-
|
|
254
|
+
if (m = null, u !== void 0 && (a(u), m = "" + u), i(n) && (a(n.key), m = "" + n.key), "key" in n) {
|
|
255
|
+
u = {};
|
|
256
|
+
for (var Y in n)
|
|
257
|
+
Y !== "key" && (u[Y] = n[Y]);
|
|
258
|
+
} else u = n;
|
|
259
|
+
return m && b(
|
|
260
|
+
u,
|
|
261
261
|
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
|
|
262
|
-
),
|
|
262
|
+
), f(
|
|
263
263
|
e,
|
|
264
|
-
|
|
265
|
-
|
|
264
|
+
m,
|
|
265
|
+
u,
|
|
266
266
|
r(),
|
|
267
|
-
|
|
268
|
-
|
|
267
|
+
O,
|
|
268
|
+
I
|
|
269
269
|
);
|
|
270
270
|
}
|
|
271
|
-
function
|
|
272
|
-
|
|
271
|
+
function _(e) {
|
|
272
|
+
R(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === C && (e._payload.status === "fulfilled" ? R(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
|
|
273
273
|
}
|
|
274
|
-
function
|
|
275
|
-
return typeof e == "object" && e !== null && e.$$typeof ===
|
|
274
|
+
function R(e) {
|
|
275
|
+
return typeof e == "object" && e !== null && e.$$typeof === T;
|
|
276
276
|
}
|
|
277
|
-
var
|
|
277
|
+
var y = me, T = Symbol.for("react.transitional.element"), h = Symbol.for("react.portal"), p = Symbol.for("react.fragment"), E = Symbol.for("react.strict_mode"), v = Symbol.for("react.profiler"), g = Symbol.for("react.consumer"), w = Symbol.for("react.context"), ae = Symbol.for("react.forward_ref"), se = Symbol.for("react.suspense"), ce = Symbol.for("react.suspense_list"), ue = Symbol.for("react.memo"), C = Symbol.for("react.lazy"), le = Symbol.for("react.activity"), ie = Symbol.for("react.client.reference"), V = y.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, z = Object.prototype.hasOwnProperty, fe = Array.isArray, $ = console.createTask ? console.createTask : function() {
|
|
278
278
|
return null;
|
|
279
279
|
};
|
|
280
|
-
|
|
280
|
+
y = {
|
|
281
281
|
react_stack_bottom_frame: function(e) {
|
|
282
282
|
return e();
|
|
283
283
|
}
|
|
284
284
|
};
|
|
285
|
-
var
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
)(),
|
|
289
|
-
|
|
290
|
-
var
|
|
285
|
+
var W, J = {}, U = y.react_stack_bottom_frame.bind(
|
|
286
|
+
y,
|
|
287
|
+
o
|
|
288
|
+
)(), q = $(s(o)), G = {};
|
|
289
|
+
x.Fragment = p, x.jsx = function(e, n, u) {
|
|
290
|
+
var d = 1e4 > V.recentlyCreatedOwnerStacks++;
|
|
291
291
|
return l(
|
|
292
292
|
e,
|
|
293
293
|
n,
|
|
294
|
-
|
|
294
|
+
u,
|
|
295
295
|
!1,
|
|
296
|
-
|
|
297
|
-
|
|
296
|
+
d ? Error("react-stack-top-frame") : U,
|
|
297
|
+
d ? $(s(e)) : q
|
|
298
298
|
);
|
|
299
|
-
},
|
|
300
|
-
var
|
|
299
|
+
}, x.jsxs = function(e, n, u) {
|
|
300
|
+
var d = 1e4 > V.recentlyCreatedOwnerStacks++;
|
|
301
301
|
return l(
|
|
302
302
|
e,
|
|
303
303
|
n,
|
|
304
|
-
|
|
304
|
+
u,
|
|
305
305
|
!0,
|
|
306
|
-
|
|
307
|
-
|
|
306
|
+
d ? Error("react-stack-top-frame") : U,
|
|
307
|
+
d ? $(s(e)) : q
|
|
308
308
|
);
|
|
309
309
|
};
|
|
310
|
-
})()),
|
|
310
|
+
})()), x;
|
|
311
311
|
}
|
|
312
|
-
var
|
|
313
|
-
function
|
|
314
|
-
return
|
|
312
|
+
var H;
|
|
313
|
+
function he() {
|
|
314
|
+
return H || (H = 1, process.env.NODE_ENV === "production" ? A.exports = ye() : A.exports = ge()), A.exports;
|
|
315
315
|
}
|
|
316
|
-
var
|
|
317
|
-
const
|
|
316
|
+
var ke = he();
|
|
317
|
+
const re = be({
|
|
318
318
|
stateVocab: {},
|
|
319
319
|
setStateVocab: () => {
|
|
320
320
|
}
|
|
321
321
|
});
|
|
322
|
-
function
|
|
323
|
-
return
|
|
322
|
+
function we() {
|
|
323
|
+
return ve(re);
|
|
324
324
|
}
|
|
325
|
-
const
|
|
326
|
-
const { children: c, verbose:
|
|
327
|
-
return
|
|
328
|
-
},
|
|
329
|
-
const
|
|
330
|
-
return
|
|
331
|
-
},
|
|
332
|
-
const { serialized: c, defaultValue:
|
|
325
|
+
const je = (t) => {
|
|
326
|
+
const { children: c, verbose: a } = t, [s, r] = ee({});
|
|
327
|
+
return a && Te(s), /* @__PURE__ */ ke.jsx(re.Provider, { value: { stateVocab: s, setStateVocab: r }, children: c });
|
|
328
|
+
}, j = (t, c) => (a) => {
|
|
329
|
+
const s = { ...a };
|
|
330
|
+
return _e(s, t, c), s;
|
|
331
|
+
}, L = (t, c) => ne(t) ?? c, Z = (t) => {
|
|
332
|
+
const { serialized: c, defaultValue: a, superDefaultValue: s, deserialize: r } = t;
|
|
333
333
|
if (c === null) {
|
|
334
|
-
const
|
|
335
|
-
return typeof
|
|
334
|
+
const o = L(a, s);
|
|
335
|
+
return typeof o > "u" ? void 0 : o;
|
|
336
336
|
}
|
|
337
337
|
return r(c);
|
|
338
|
-
},
|
|
339
|
-
function
|
|
338
|
+
}, Pe = (t) => typeof t == "function", xe = (t) => typeof t == "function", ne = (t) => xe(t) ? t() : t, Oe = typeof window > "u";
|
|
339
|
+
function Ne(t = {}) {
|
|
340
340
|
const {
|
|
341
341
|
serialize: c = JSON.stringify,
|
|
342
|
-
deserialize:
|
|
343
|
-
} = t,
|
|
342
|
+
deserialize: a = JSON.parse
|
|
343
|
+
} = t, s = t.defaultValue, r = t.bidirectional, o = Oe ? void 0 : ne(t.storage);
|
|
344
344
|
return {
|
|
345
|
-
[
|
|
345
|
+
[te]: !0,
|
|
346
346
|
// marks this object as a leaf in the router tree
|
|
347
|
-
[
|
|
347
|
+
[M]: !1,
|
|
348
348
|
// placeholder; injected at runtime by injectPaths()
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
349
|
+
[N]: "",
|
|
350
|
+
// placeholder; injected at runtime by injectPaths()
|
|
351
|
+
useState(i, b) {
|
|
352
|
+
b ??= {};
|
|
353
|
+
const S = Re(
|
|
354
|
+
b.onSet ?? (() => {
|
|
353
355
|
}),
|
|
354
|
-
|
|
356
|
+
b.delayedSet,
|
|
355
357
|
[]
|
|
356
|
-
),
|
|
358
|
+
), f = we(), l = this[N], _ = this[M], [R, y] = ee(!_);
|
|
359
|
+
D(() => y(!0), []);
|
|
360
|
+
const T = F(
|
|
357
361
|
() => {
|
|
358
|
-
if (!
|
|
362
|
+
if (!R || !o)
|
|
359
363
|
return;
|
|
360
|
-
const
|
|
361
|
-
return
|
|
362
|
-
serialized:
|
|
363
|
-
defaultValue:
|
|
364
|
-
superDefaultValue:
|
|
365
|
-
deserialize:
|
|
364
|
+
const E = o.getItem(l);
|
|
365
|
+
return Z({
|
|
366
|
+
serialized: E,
|
|
367
|
+
defaultValue: i,
|
|
368
|
+
superDefaultValue: s,
|
|
369
|
+
deserialize: a
|
|
366
370
|
});
|
|
367
371
|
},
|
|
368
372
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
369
|
-
[l]
|
|
370
|
-
),
|
|
373
|
+
[l, R]
|
|
374
|
+
), h = F(
|
|
371
375
|
() => Ee(
|
|
372
|
-
|
|
376
|
+
f.stateVocab,
|
|
373
377
|
l,
|
|
374
|
-
|
|
378
|
+
T ?? L(i, s)
|
|
375
379
|
),
|
|
376
380
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
377
381
|
[
|
|
378
|
-
|
|
379
|
-
|
|
382
|
+
f.stateVocab,
|
|
383
|
+
T,
|
|
380
384
|
l
|
|
381
385
|
]
|
|
382
386
|
);
|
|
383
|
-
|
|
387
|
+
D(
|
|
384
388
|
() => {
|
|
385
|
-
!
|
|
389
|
+
!o || typeof T > "u" || f.setStateVocab(j(l, T));
|
|
386
390
|
},
|
|
387
391
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
388
|
-
[
|
|
389
|
-
),
|
|
390
|
-
if (!
|
|
392
|
+
[T]
|
|
393
|
+
), D(() => {
|
|
394
|
+
if (!b.bidirectional && !r)
|
|
391
395
|
return;
|
|
392
|
-
const
|
|
393
|
-
if (
|
|
396
|
+
const E = (v) => {
|
|
397
|
+
if (v.key !== l)
|
|
394
398
|
return;
|
|
395
|
-
const
|
|
396
|
-
serialized:
|
|
397
|
-
defaultValue:
|
|
398
|
-
superDefaultValue:
|
|
399
|
-
deserialize:
|
|
399
|
+
const g = v.newValue, w = Z({
|
|
400
|
+
serialized: g,
|
|
401
|
+
defaultValue: i,
|
|
402
|
+
superDefaultValue: s,
|
|
403
|
+
deserialize: a
|
|
400
404
|
});
|
|
401
|
-
|
|
405
|
+
f.setStateVocab(j(l, w)), S(w, p.current), p.current = w;
|
|
402
406
|
};
|
|
403
|
-
return window.addEventListener("storage",
|
|
407
|
+
return window.addEventListener("storage", E), () => window.removeEventListener("storage", E);
|
|
404
408
|
}, [
|
|
405
409
|
l,
|
|
406
|
-
|
|
410
|
+
b.bidirectional,
|
|
407
411
|
r
|
|
408
412
|
]);
|
|
409
|
-
const
|
|
413
|
+
const p = pe(h);
|
|
410
414
|
return [
|
|
411
|
-
|
|
412
|
-
function(
|
|
413
|
-
const
|
|
414
|
-
|
|
415
|
+
h,
|
|
416
|
+
function(v) {
|
|
417
|
+
const g = Pe(v) ? v(p.current) : v;
|
|
418
|
+
f.setStateVocab(j(l, g)), S(g, p.current), o && o.setItem(l, c(g)), p.current = g;
|
|
415
419
|
},
|
|
416
420
|
function() {
|
|
417
|
-
const
|
|
418
|
-
if (typeof
|
|
419
|
-
|
|
421
|
+
const v = L(i, s);
|
|
422
|
+
if (typeof v > "u") {
|
|
423
|
+
o?.removeItem(l);
|
|
420
424
|
return;
|
|
421
425
|
}
|
|
422
|
-
|
|
426
|
+
f.setStateVocab(j(l, v)), S(v, p.current), p.current = v, o && o.setItem(l, c(v));
|
|
423
427
|
}
|
|
424
428
|
];
|
|
425
429
|
},
|
|
426
430
|
/** Returns the fully qualified job name (dot-separated path). */
|
|
427
431
|
toString() {
|
|
428
|
-
return this[
|
|
432
|
+
return this[N];
|
|
429
433
|
}
|
|
430
434
|
};
|
|
431
435
|
}
|
|
432
|
-
const
|
|
433
|
-
function
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
436
|
+
const Q = /* @__PURE__ */ new WeakMap(), K = /* @__PURE__ */ new WeakMap();
|
|
437
|
+
function oe(t, c) {
|
|
438
|
+
c ??= {};
|
|
439
|
+
const {
|
|
440
|
+
path: a = "",
|
|
441
|
+
ssr: s
|
|
442
|
+
} = c;
|
|
443
|
+
let r = Q.get(t);
|
|
444
|
+
r || (r = /* @__PURE__ */ new Map(), Q.set(t, r));
|
|
445
|
+
const o = r.get(a);
|
|
446
|
+
if (o)
|
|
447
|
+
return o;
|
|
448
|
+
const i = new Proxy(t, {
|
|
449
|
+
get(b, S) {
|
|
450
|
+
const f = b[S], l = a ? `${a}.${String(S)}` : String(S);
|
|
451
|
+
if (f && typeof f == "object" && te in f) {
|
|
452
|
+
const _ = f;
|
|
453
|
+
let R = K.get(_);
|
|
454
|
+
R || (R = /* @__PURE__ */ new Map(), K.set(_, R));
|
|
455
|
+
const y = R.get(l);
|
|
456
|
+
if (y)
|
|
457
|
+
return y;
|
|
458
|
+
const T = Reflect.ownKeys(_).filter(
|
|
459
|
+
(E) => typeof _[E] == "function"
|
|
460
|
+
), h = Object.fromEntries(
|
|
461
|
+
T.map((E) => [
|
|
462
|
+
E,
|
|
463
|
+
(...v) => _[E].call(
|
|
464
|
+
{
|
|
465
|
+
..._,
|
|
466
|
+
[N]: l,
|
|
467
|
+
[M]: s
|
|
468
|
+
},
|
|
469
|
+
...v
|
|
457
470
|
)
|
|
458
471
|
])
|
|
459
|
-
),
|
|
460
|
-
return
|
|
472
|
+
), p = { ..._, ...h };
|
|
473
|
+
return R.set(l, p), p;
|
|
461
474
|
}
|
|
462
|
-
return
|
|
475
|
+
return f && typeof f == "object" ? oe(f, {
|
|
476
|
+
path: l,
|
|
477
|
+
ssr: s
|
|
478
|
+
}) : f;
|
|
463
479
|
}
|
|
464
480
|
});
|
|
465
|
-
return
|
|
481
|
+
return r.set(a, i), i;
|
|
466
482
|
}
|
|
467
|
-
function
|
|
468
|
-
return
|
|
483
|
+
function Ce(t, c) {
|
|
484
|
+
return oe(t, c);
|
|
469
485
|
}
|
|
470
486
|
export {
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
487
|
+
je as StorageProvider,
|
|
488
|
+
Ne as defineState,
|
|
489
|
+
Ce as setupStorage
|
|
474
490
|
};
|
package/dist/types/setup.d.ts
CHANGED
package/dist/types/state.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { STATE_DEFINITION, STATE_PATH } from "./constants";
|
|
1
|
+
import { STATE_DEFINITION, STATE_PATH, STATE_SSR_SUPPORT } from "./constants";
|
|
2
2
|
import type { ValueOrFactory, ValueOrTransformer } from "./types";
|
|
3
3
|
export declare function defineState<T>(definitionOptions?: {
|
|
4
4
|
storage?: ValueOrFactory<Storage>;
|
|
@@ -8,9 +8,11 @@ export declare function defineState<T>(definitionOptions?: {
|
|
|
8
8
|
deserialize?: (v: string) => T;
|
|
9
9
|
}): {
|
|
10
10
|
[STATE_DEFINITION]: boolean;
|
|
11
|
+
[STATE_SSR_SUPPORT]: boolean;
|
|
11
12
|
[STATE_PATH]: string;
|
|
12
13
|
useState<D = T>(this: {
|
|
13
14
|
[STATE_PATH]: string;
|
|
15
|
+
[STATE_SSR_SUPPORT]: boolean;
|
|
14
16
|
}, defaultValue?: ValueOrFactory<D>, options?: {
|
|
15
17
|
delayedSet?: number;
|
|
16
18
|
bidirectional?: true;
|