@yakocloud/state-vocab 2.5.1 → 3.0.2

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 CHANGED
@@ -52,7 +52,7 @@ function ThemeToggle() {
52
52
  }
53
53
  ```
54
54
 
55
- **Initialize once at the root, read anywhere in the tree.** Call `.useState()` with a `defaultValue` at a parent component to seed the state — then call `.useState()` without arguments in any descendant to consume it. No context wiring, no prop passing. Convenient in NextJs
55
+ **Initialize once at the root, read anywhere in the tree.** Call `.useState()` with a `defaultValue` at a parent component to seed the state — then call `.useState()` without arguments in any descendant to consume it. No context wiring, no prop passing.
56
56
 
57
57
  ```tsx
58
58
  // Root component — initializes the state
@@ -82,8 +82,6 @@ function DeepChild() {
82
82
  }
83
83
  ```
84
84
 
85
- The `defaultValue` at the root acts as the initializer — subsequent `.useState()` calls in children pick up the shared value automatically without re-specifying defaults.
86
-
87
85
  **Dot-notation access with full TypeScript inference.** The state tree is navigated like a plain object — autocomplete guides you to the right node, and types flow from `defineState<T>` all the way to the hook return value without any manual annotations.
88
86
 
89
87
  ```ts
@@ -105,7 +103,7 @@ defineState({
105
103
  })
106
104
  ```
107
105
 
108
- **Minimal API surface.** Three exports: `defineState`, `setupStorage`, `StorageProvider`. No actions, reducers, selectors, or stores to configure.
106
+ **Minimal API surface.** Two exports: `defineState`, `setupStorage`. No actions, reducers, selectors, or stores to configure.
109
107
 
110
108
  ## Installation
111
109
 
@@ -118,7 +116,7 @@ npm install @yakocloud/state-vocab react react-dom
118
116
  ## Quick Start
119
117
 
120
118
  ```tsx
121
- import { setupStorage, defineState, StorageProvider } from '@yakocloud/state-vocab'
119
+ import { setupStorage, defineState } from '@yakocloud/state-vocab'
122
120
 
123
121
  type Theme = 'Dark' | 'White' | 'System'
124
122
 
@@ -133,14 +131,6 @@ const storage = setupStorage({
133
131
  },
134
132
  })
135
133
 
136
- function App() {
137
- return (
138
- <StorageProvider>
139
- <Settings />
140
- </StorageProvider>
141
- )
142
- }
143
-
144
134
  function Settings() {
145
135
  const [theme, setTheme] = storage.path.to.theme.useState()
146
136
 
@@ -197,7 +187,8 @@ Wraps a nested object of `defineState()` nodes and injects dot-separated paths i
197
187
 
198
188
  | Option | Type | Description | Default |
199
189
  |---|---|---|---|
200
- | `ssr` | `boolean \| undefined` | Defer storage reads until after mount (SSR support) | `false` |
190
+ | `verbose` | `boolean \| undefined` | Log current state to the browser console on every change | `false` |
191
+ | `ssr` | `boolean \| undefined` | Defer storage reads until after hydration (Next.js / SSR) | `false` |
201
192
 
202
193
  ```ts
203
194
  const storage = setupStorage({
@@ -211,26 +202,31 @@ storage.user.name // → path: "user.name"
211
202
  storage.user.age // → path: "user.age"
212
203
  ```
213
204
 
214
- ### `StorageProvider`
215
-
216
- A React context provider that must wrap all components using `.useState()` from any state node. Place it once near the top of your tree.
205
+ Enable verbose logging during development:
217
206
 
218
- ```tsx
219
- createRoot(document.getElementById('root')!).render(
220
- <StorageProvider>
221
- <App />
222
- </StorageProvider>
223
- )
207
+ ```ts
208
+ const storage = setupStorage({ ... }, { verbose: true })
224
209
  ```
225
210
 
226
- Accepts an optional `verbose` prop that logs the current state vocab to the browser console on every change — useful during development.
211
+ ### SSR / Next.js
227
212
 
228
- ```tsx
229
- <StorageProvider verbose>
230
- <App />
231
- </StorageProvider>
213
+ When using localStorage or sessionStorage in a Next.js app, the server renders with `defaultValue` while the client reads the persisted value — causing a hydration mismatch. Pass `ssr: true` to fix this:
214
+
215
+ ```ts
216
+ // lib/storage.ts
217
+ const storage = setupStorage({
218
+ preference: {
219
+ theme: defineState<Theme>({ storage: localStorage, defaultValue: 'Dark' }),
220
+ },
221
+ }, { ssr: true })
232
222
  ```
233
223
 
224
+ With `ssr: true`:
225
+ - **Server & first client render** — always use `defaultValue`, storage is not read
226
+ - **After hydration** — `useLayoutEffect` fires synchronously before paint, reads storage and updates state
227
+
228
+ This guarantees the server and client produce identical markup, and the value from storage is applied without a visible flash.
229
+
234
230
  ## `useState` Hook
235
231
 
236
232
  Each state node exposes a `.useState()` method that works like React's built-in `useState` but adds persistence and callbacks.
@@ -309,7 +305,7 @@ const storage = setupStorage({
309
305
  ## Full Example
310
306
 
311
307
  ```tsx
312
- import { setupStorage, defineState, StorageProvider } from '@yakocloud/state-vocab'
308
+ import { setupStorage, defineState } from '@yakocloud/state-vocab'
313
309
 
314
310
  type Theme = 'Dark' | 'White' | 'System'
315
311
 
@@ -393,11 +389,7 @@ function Dashboard() {
393
389
  )
394
390
  }
395
391
 
396
- createRoot(document.getElementById('root')!).render(
397
- <StorageProvider>
398
- <Page />
399
- </StorageProvider>
400
- )
392
+ createRoot(document.getElementById('root')!).render(<Page />)
401
393
  ```
402
394
 
403
395
  ## API Reference
@@ -416,18 +408,11 @@ createRoot(document.getElementById('root')!).render(
416
408
 
417
409
  | Option | Type | Default |
418
410
  |---|---|---|
411
+ | `verbose` | `boolean \| undefined` | `false` |
419
412
  | `ssr` | `boolean \| undefined` | `false` |
420
413
 
421
414
  Returns a proxied copy of `tree` with paths injected into all leaf nodes.
422
415
 
423
- ### `StorageProvider`
424
-
425
- React context provider. Must be an ancestor of any component using `.useState()`.
426
-
427
- | Prop | Type | Description |
428
- |---|---|---|
429
- | `verbose` | `boolean \| undefined` | Log state vocab to console on every change |
430
-
431
416
  ### `node.useState(options?)`
432
417
 
433
418
  | Option | Type | Description |
@@ -1,8 +1,3 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("react"),re=Symbol("state-def"),$=Symbol("state-path"),W=Symbol("state-ssr");function ie(t,s,r){if(!s)return t;const a=s.split(".");let n=t;for(const c of a)if(n!==null&&typeof n=="object"&&c in n)n=n[c];else return r;return n===void 0?r:n}function fe(t,s,r){const a=s.replace(/\[(\d+)\]/g,".$1").split(".");let n=t;for(let c=0;c<a.length-1;c++){const m=a[c],v=a[c+1];(n[m]===void 0||n[m]===null)&&(n[m]=/^\d+$/.test(v)?[]:{}),n=n[m]}return n[a[a.length-1]]=r,t}function de(t,s=0){let r;return function(...a){r!==void 0&&clearTimeout(r),r=setTimeout(()=>{r=void 0,t.apply(this,a)},s)}}function me(t,s,r=[]){return p.useMemo(()=>de(t,s),r)}function be(t){const s=JSON.stringify(t,null,2).split(`
2
- `),r=[],a=[];for(const n of s){const c=n.match(/^(\s*)"([^"]+)"(\s*:\s*)(.+)$/);if(c){const[,m,v,S,l]=c;r.push(`${m}%c"${v}"%c${S}%c${l}`),a.push("color: #9cdcfe; font-weight: bold","color: #cccccc","color: #ce9178")}else r.push(`%c${n}`),a.push("color: #cccccc")}console.log(r.join(`
3
- `),...a,t)}var V={exports:{}},x={};var Z;function ve(){if(Z)return x;Z=1;var t=Symbol.for("react.transitional.element"),s=Symbol.for("react.fragment");function r(a,n,c){var m=null;if(c!==void 0&&(m=""+c),n.key!==void 0&&(m=""+n.key),"key"in n){c={};for(var v in n)v!=="key"&&(c[v]=n[v])}else c=n;return n=c.ref,{$$typeof:t,type:a,key:m,ref:n!==void 0?n:null,props:c}}return x.Fragment=s,x.jsx=r,x.jsxs=r,x}var O={};var Q;function Ee(){return Q||(Q=1,process.env.NODE_ENV!=="production"&&(function(){function t(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===ce?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case E:return"Fragment";case A:return"Profiler";case k:return"StrictMode";case J:return"Suspense";case w:return"SuspenseList";case se: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 T:return"Portal";case h:return e.displayName||"Context";case b:return(e._context.displayName||"Context")+".Consumer";case j:var o=e.render;return e=e.displayName,e||(e=o.displayName||o.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case ae:return o=e.displayName||null,o!==null?o:t(e.type)||"Memo";case I:o=e._payload,e=e._init;try{return t(e(o))}catch{}}return null}function s(e){return""+e}function r(e){try{s(e);var o=!1}catch{o=!0}if(o){o=console;var u=o.error,f=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return u.call(o,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",f),s(e)}}function a(e){if(e===E)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===I)return"<...>";try{var o=t(e);return o?"<"+o+">":"<...>"}catch{return"<...>"}}function n(){var e=M.A;return e===null?null:e.getOwner()}function c(){return Error("react-stack-top-frame")}function m(e){if(U.call(e,"key")){var o=Object.getOwnPropertyDescriptor(e,"key").get;if(o&&o.isReactWarning)return!1}return e.key!==void 0}function v(e,o){function u(){q||(q=!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)",o))}u.isReactWarning=!0,Object.defineProperty(e,"key",{get:u,configurable:!0})}function S(){var e=t(this.type);return G[e]||(G[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 l(e,o,u,f,N,D){var d=u.ref;return e={$$typeof:g,type:e,key:o,props:u,_owner:f},(d!==void 0?d:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:S}):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:N}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:D}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function i(e,o,u,f,N,D){var d=o.children;if(d!==void 0)if(f)if(ue(d)){for(f=0;f<d.length;f++)_(d[f]);Object.freeze&&Object.freeze(d)}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 _(d);if(U.call(o,"key")){d=t(e);var P=Object.keys(o).filter(function(le){return le!=="key"});f=0<P.length?"{key: someKey, "+P.join(": ..., ")+": ...}":"{key: someKey}",H[d+f]||(P=0<P.length?"{"+P.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
4
- let props = %s;
5
- <%s {...props} />
6
- React keys must be passed directly to JSX without using spread:
7
- let props = %s;
8
- <%s key={someKey} {...props} />`,f,d,P,d),H[d+f]=!0)}if(d=null,u!==void 0&&(r(u),d=""+u),m(o)&&(r(o.key),d=""+o.key),"key"in o){u={};for(var F in o)F!=="key"&&(u[F]=o[F])}else u=o;return d&&v(u,typeof e=="function"?e.displayName||e.name||"Unknown":e),l(e,d,u,n(),N,D)}function _(e){R(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===I&&(e._payload.status==="fulfilled"?R(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function R(e){return typeof e=="object"&&e!==null&&e.$$typeof===g}var y=p,g=Symbol.for("react.transitional.element"),T=Symbol.for("react.portal"),E=Symbol.for("react.fragment"),k=Symbol.for("react.strict_mode"),A=Symbol.for("react.profiler"),b=Symbol.for("react.consumer"),h=Symbol.for("react.context"),j=Symbol.for("react.forward_ref"),J=Symbol.for("react.suspense"),w=Symbol.for("react.suspense_list"),ae=Symbol.for("react.memo"),I=Symbol.for("react.lazy"),se=Symbol.for("react.activity"),ce=Symbol.for("react.client.reference"),M=y.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,U=Object.prototype.hasOwnProperty,ue=Array.isArray,Y=console.createTask?console.createTask:function(){return null};y={react_stack_bottom_frame:function(e){return e()}};var q,G={},X=y.react_stack_bottom_frame.bind(y,c)(),B=Y(a(c)),H={};O.Fragment=E,O.jsx=function(e,o,u){var f=1e4>M.recentlyCreatedOwnerStacks++;return i(e,o,u,!1,f?Error("react-stack-top-frame"):X,f?Y(a(e)):B)},O.jsxs=function(e,o,u){var f=1e4>M.recentlyCreatedOwnerStacks++;return i(e,o,u,!0,f?Error("react-stack-top-frame"):X,f?Y(a(e)):B)}})()),O}var K;function _e(){return K||(K=1,process.env.NODE_ENV==="production"?V.exports=ve():V.exports=Ee()),V.exports}var pe=_e();const ne=p.createContext({stateVocab:{},setStateVocab:()=>{}});function Se(){return p.useContext(ne)}const Re=t=>{const{children:s,verbose:r}=t,[a,n]=p.useState({});return r&&be(a),pe.jsx(ne.Provider,{value:{stateVocab:a,setStateVocab:n},children:s})},C=(t,s)=>r=>{const a={...r};return fe(a,t,s),a},Te=t=>typeof t=="function",ye=t=>typeof t=="function",z=t=>typeof t<"u",L=t=>ye(t)?t():t,ge=typeof window>"u";function he(t={}){return{[re]:!0,[W]:!1,[$]:"",useState(s){const r=ge?void 0:L(t.storage),a=t.serialize??JSON.stringify,n=t.deserialize??JSON.parse,c=L(t.defaultValue),m=t.bidirectional;s??={};const v=L(s.defaultValue),S=me(s.onSet??(()=>{}),s.delayedSet,[]),l=Se(),i=this[$],_=this[W],[R,y]=p.useState(!_);p.useEffect(()=>y(!0),[]);const g=p.useMemo(()=>{if(!R||!r)return;const b=r.getItem(i);return b===null?null:n(b)},[R]),T=p.useMemo(()=>ie(l.stateVocab,i,g??v??c),[l.stateVocab,g]),E=p.useRef(T);return p.useEffect(()=>{z(T)&&(l.setStateVocab(C(i,T)),r&&g===null&&r.setItem(i,a(T)),E.current=T)},[g]),p.useEffect(()=>{if(!s.bidirectional&&!m)return;const b=h=>{if(h.key!==i)return;const j=h.newValue,w=(j===null?null:n(j))??v??c;z(w)&&(l.setStateVocab(C(i,w)),S(w,E.current),E.current=w)};return window.addEventListener("storage",b),()=>window.removeEventListener("storage",b)},[s.bidirectional,m]),[T,b=>{const h=Te(b)?b(E.current):b;l.setStateVocab(C(i,h)),S(h,E.current),r&&r.setItem(i,a(h)),E.current=h},()=>{const b=v??c;if(!z(b)){r?.removeItem(i);return}l.setStateVocab(C(i,b)),S(b,E.current),E.current=b,r&&r.setItem(i,a(b))}]},toString(){return this[$]}}}const ee=new WeakMap,te=new WeakMap;function oe(t,s){s??={};const{path:r="",ssr:a}=s;let n=ee.get(t);n||(n=new Map,ee.set(t,n));const c=n.get(r);if(c)return c;const m=new Proxy(t,{get(v,S){const l=v[S],i=r?`${r}.${String(S)}`:String(S);if(l&&typeof l=="object"&&re in l){const _=l;let R=te.get(_);R||(R=new Map,te.set(_,R));const y=R.get(i);if(y)return y;const g=Reflect.ownKeys(_).filter(k=>typeof _[k]=="function"),T=Object.fromEntries(g.map(k=>[k,(...A)=>_[k].call({..._,[$]:i,[W]:a},...A)])),E={..._,...T};return R.set(i,E),E}return l&&typeof l=="object"?oe(l,{path:i,ssr:a}):l}});return n.set(r,m),m}function ke(t,s){return oe(t,s)}exports.StorageProvider=Re;exports.defineState=he;exports.setupStorage=ke;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react"),R=Symbol("state-def"),T=Symbol("state-path"),z=Symbol("state-verbose"),x=Symbol("state-ssr");function C(t,e,s){if(!e)return t;const o=e.split(".");let c=t;for(const r of o)if(c!==null&&typeof c=="object"&&r in c)c=c[r];else return s;return c===void 0?s:c}function j(t,e,s){const o=e.replace(/\[(\d+)\]/g,".$1").split(".");let c=t;for(let r=0;r<o.length-1;r++){const n=o[r],a=o[r+1];(c[n]===void 0||c[n]===null)&&(c[n]=/^\d+$/.test(a)?[]:{}),c=c[n]}return c[o[o.length-1]]=s,t}function D(t,e=0){let s;return function(...o){s!==void 0&&clearTimeout(s),s=setTimeout(()=>{s=void 0,t.apply(this,o)},e)}}function O(t,e,s=[]){return f.useMemo(()=>D(t,e),s)}function P(t){const e=JSON.stringify(t,null,2).split(`
2
+ `),s=[],o=[];for(const c of e){const r=c.match(/^(\s*)"([^"]+)"(\s*:\s*)(.+)$/);if(r){const[,n,a,d,h]=r;s.push(`${n}%c"${a}"%c${d}%c${h}`),o.push("color: #9cdcfe; font-weight: bold","color: #cccccc","color: #ce9178")}else s.push(`%c${c}`),o.push("color: #cccccc")}console.log(s.join(`
3
+ `),...o,t)}const M=t=>typeof t=="function",_=t=>typeof t=="function",E=t=>typeof t<"u",$=t=>_(t)?t():t,A=typeof window>"u",F=A?f.useEffect:f.useLayoutEffect;class J{#e;#t;constructor(){this.#e={},this.#t=new Set}subscribe(e){return this.#t.add(e),()=>this.#t.delete(e)}getClientSnapshot(){return this.#e}getServerSnapshot(){return this.#e}get(e){return C(this.#e,e)}set(e,s){const o=C(this.#e,e),c=M(s)?s(o):s,r={...this.#e};j(r,e,c),this.#e=r,this.#t.forEach(n=>n())}}function B(t={}){const e=new J,s=t.serialize??JSON.stringify,o=t.deserialize??JSON.parse,c=(r,n,a)=>{const d=n.getItem(r);d===null?E(a)&&n.setItem(r,s(a)):e.set(r,o(d))};return{[R]:!0,[T]:"",[z]:!1,[x]:!1,useState(r){const n=A?void 0:$(t.storage),a=$(t.defaultValue),d=t.bidirectional;r??={};const h=$(r.defaultValue)??a,p=r.bidirectional??d,u=O(r.onSet??(()=>{}),r.delayedSet,[]),i=this[T],S=this[z],y=this[x],g=f.useRef(void 0),w=f.useRef(!1);if(!w.current){w.current=!0;let l=e.get(i);E(l)||(l=h,E(l)&&e.set(i,l)),!y&&n&&c(i,n,l)}const V=f.useSyncExternalStore(e.subscribe.bind(e),e.getClientSnapshot.bind(e),e.getServerSnapshot.bind(e));S&&P(V);const v=C(V,i,h);g.current=v,F(()=>{!y||!n||c(i,n,v)},[]);const b=f.useEffectEvent(l=>{if(l.key!==i)return;const m=l.newValue,I=(m===null?null:o(m))??h;E(I)&&(e.set(i,I),u(I,g.current))});f.useEffect(()=>{if(p)return window.addEventListener("storage",b),()=>window.removeEventListener("storage",b)},[p]);const k=f.useCallback(l=>{const m=M(l)?l(g.current):l;e.set(i,m),u(m,g.current),n&&n.setItem(i,s(m))},[i,n,s,u]),N=f.useCallback(()=>{const l=h;if(!E(l)){n?.removeItem(i);return}e.set(i,l),u(l,g.current),n&&n.setItem(i,s(l))},[i,h,n,s,u]);return[v,k,N]},toString(){return this[T]}}}function L(t,e){const{path:s="",verbose:o,ssr:c,cache:r}=e;let n=r.proxy.get(t);n||(n=new Map,r.proxy.set(t,n));const a=n.get(s);if(a)return a;const d=new Proxy(t,{get(h,p){const u=h[p],i=s?`${s}.${String(p)}`:String(p);if(u&&typeof u=="object"&&R in u){const S=u;let y=r.leaf.get(S);y||(y=new Map,r.leaf.set(S,y));const g=y.get(i);if(g)return g;const w=Reflect.ownKeys(S).filter(b=>typeof S[b]=="function"),V=Object.fromEntries(w.map(b=>[b,(...k)=>S[b].call({...S,[T]:i,[z]:o,[x]:c},...k)])),v={...S,...V};return y.set(i,v),v}return u&&typeof u=="object"?L(u,{...e,path:i}):u}});return n.set(s,d),d}function K(t,e){return L(t,{...e,cache:{proxy:new WeakMap,leaf:new WeakMap}})}exports.defineState=B;exports.setupStorage=K;
@@ -1,467 +1,223 @@
1
- import de, { useMemo as W, createContext as me, useState as ne, useContext as be, useEffect as M, useRef as ve } from "react";
2
- const oe = Symbol("state-def"), C = Symbol("state-path"), J = Symbol("state-ssr");
3
- function Ee(t, s, r) {
4
- if (!s)
1
+ import { useMemo as j, useRef as C, useSyncExternalStore as F, useEffect as A, useLayoutEffect as J, useEffectEvent as O, useCallback as R } from "react";
2
+ const L = Symbol("state-def"), V = Symbol("state-path"), k = Symbol("state-verbose"), z = Symbol("state-ssr");
3
+ function x(t, e, n) {
4
+ if (!e)
5
5
  return t;
6
- const a = s.split(".");
7
- let n = t;
8
- for (const c of a)
9
- if (n !== null && typeof n == "object" && c in n)
10
- n = n[c];
6
+ const o = e.split(".");
7
+ let c = t;
8
+ for (const r of o)
9
+ if (c !== null && typeof c == "object" && r in c)
10
+ c = c[r];
11
11
  else
12
- return r;
13
- return n === void 0 ? r : n;
12
+ return n;
13
+ return c === void 0 ? n : c;
14
14
  }
15
- function _e(t, s, r) {
16
- const a = s.replace(/\[(\d+)\]/g, ".$1").split(".");
17
- let n = t;
18
- for (let c = 0; c < a.length - 1; c++) {
19
- const m = a[c], v = a[c + 1];
20
- (n[m] === void 0 || n[m] === null) && (n[m] = /^\d+$/.test(v) ? [] : {}), n = n[m];
15
+ function P(t, e, n) {
16
+ const o = e.replace(/\[(\d+)\]/g, ".$1").split(".");
17
+ let c = t;
18
+ for (let r = 0; r < o.length - 1; r++) {
19
+ const s = o[r], a = o[r + 1];
20
+ (c[s] === void 0 || c[s] === null) && (c[s] = /^\d+$/.test(a) ? [] : {}), c = c[s];
21
21
  }
22
- return n[a[a.length - 1]] = r, t;
22
+ return c[o[o.length - 1]] = n, t;
23
23
  }
24
- function pe(t, s = 0) {
25
- let r;
26
- return function(...a) {
27
- r !== void 0 && clearTimeout(r), r = setTimeout(() => {
28
- r = void 0, t.apply(this, a);
29
- }, s);
24
+ function B(t, e = 0) {
25
+ let n;
26
+ return function(...o) {
27
+ n !== void 0 && clearTimeout(n), n = setTimeout(() => {
28
+ n = void 0, t.apply(this, o);
29
+ }, e);
30
30
  };
31
31
  }
32
- function Se(t, s, r = []) {
33
- return W(
34
- () => pe(t, s),
32
+ function K(t, e, n = []) {
33
+ return j(
34
+ () => B(t, e),
35
35
  // eslint-disable-next-line react-hooks/exhaustive-deps
36
- r
36
+ n
37
37
  );
38
38
  }
39
- function Re(t) {
40
- const s = JSON.stringify(t, null, 2).split(`
41
- `), r = [], a = [];
42
- for (const n of s) {
43
- const c = n.match(/^(\s*)"([^"]+)"(\s*:\s*)(.+)$/);
44
- if (c) {
45
- const [, m, v, p, l] = c;
46
- r.push(`${m}%c"${v}"%c${p}%c${l}`), a.push(
39
+ function W(t) {
40
+ const e = JSON.stringify(t, null, 2).split(`
41
+ `), n = [], o = [];
42
+ for (const c of e) {
43
+ const r = c.match(/^(\s*)"([^"]+)"(\s*:\s*)(.+)$/);
44
+ if (r) {
45
+ const [, s, a, f, d] = r;
46
+ n.push(`${s}%c"${a}"%c${f}%c${d}`), o.push(
47
47
  "color: #9cdcfe; font-weight: bold",
48
48
  "color: #cccccc",
49
49
  "color: #ce9178"
50
50
  );
51
51
  } else
52
- r.push(`%c${n}`), a.push("color: #cccccc");
52
+ n.push(`%c${c}`), o.push("color: #cccccc");
53
53
  }
54
- console.log(r.join(`
55
- `), ...a, t);
54
+ console.log(n.join(`
55
+ `), ...o, t);
56
56
  }
57
- var N = { exports: {} }, P = {};
58
- var Q;
59
- function Te() {
60
- if (Q) return P;
61
- Q = 1;
62
- var t = Symbol.for("react.transitional.element"), s = Symbol.for("react.fragment");
63
- function r(a, n, c) {
64
- var m = null;
65
- if (c !== void 0 && (m = "" + c), n.key !== void 0 && (m = "" + n.key), "key" in n) {
66
- c = {};
67
- for (var v in n)
68
- v !== "key" && (c[v] = n[v]);
69
- } else c = n;
70
- return n = c.ref, {
71
- $$typeof: t,
72
- type: a,
73
- key: m,
74
- ref: n !== void 0 ? n : null,
75
- props: c
76
- };
57
+ const M = (t) => typeof t == "function", H = (t) => typeof t == "function", m = (t) => typeof t < "u", $ = (t) => H(t) ? t() : t, N = typeof window > "u", q = N ? A : J;
58
+ class G {
59
+ #e;
60
+ #t;
61
+ constructor() {
62
+ this.#e = {}, this.#t = /* @__PURE__ */ new Set();
77
63
  }
78
- return P.Fragment = s, P.jsx = r, P.jsxs = r, P;
79
- }
80
- var x = {};
81
- var K;
82
- function ye() {
83
- return K || (K = 1, process.env.NODE_ENV !== "production" && (function() {
84
- function t(e) {
85
- if (e == null) return null;
86
- if (typeof e == "function")
87
- return e.$$typeof === le ? null : e.displayName || e.name || null;
88
- if (typeof e == "string") return e;
89
- switch (e) {
90
- case E:
91
- return "Fragment";
92
- case A:
93
- return "Profiler";
94
- case g:
95
- return "StrictMode";
96
- case U:
97
- return "Suspense";
98
- case k:
99
- return "SuspenseList";
100
- case ue:
101
- return "Activity";
102
- }
103
- if (typeof e == "object")
104
- switch (typeof e.tag == "number" && console.error(
105
- "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
106
- ), e.$$typeof) {
107
- case R:
108
- return "Portal";
109
- case h:
110
- return e.displayName || "Context";
111
- case b:
112
- return (e._context.displayName || "Context") + ".Consumer";
113
- case O:
114
- var o = e.render;
115
- return e = e.displayName, e || (e = o.displayName || o.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
116
- case ce:
117
- return o = e.displayName || null, o !== null ? o : t(e.type) || "Memo";
118
- case $:
119
- o = e._payload, e = e._init;
120
- try {
121
- return t(e(o));
122
- } catch {
123
- }
124
- }
125
- return null;
126
- }
127
- function s(e) {
128
- return "" + e;
129
- }
130
- function r(e) {
131
- try {
132
- s(e);
133
- var o = !1;
134
- } catch {
135
- o = !0;
136
- }
137
- if (o) {
138
- o = console;
139
- var u = o.error, f = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
140
- return u.call(
141
- o,
142
- "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
143
- f
144
- ), s(e);
145
- }
146
- }
147
- function a(e) {
148
- if (e === E) return "<>";
149
- if (typeof e == "object" && e !== null && e.$$typeof === $)
150
- return "<...>";
151
- try {
152
- var o = t(e);
153
- return o ? "<" + o + ">" : "<...>";
154
- } catch {
155
- return "<...>";
156
- }
157
- }
158
- function n() {
159
- var e = I.A;
160
- return e === null ? null : e.getOwner();
161
- }
162
- function c() {
163
- return Error("react-stack-top-frame");
164
- }
165
- function m(e) {
166
- if (q.call(e, "key")) {
167
- var o = Object.getOwnPropertyDescriptor(e, "key").get;
168
- if (o && o.isReactWarning) return !1;
169
- }
170
- return e.key !== void 0;
171
- }
172
- function v(e, o) {
173
- function u() {
174
- G || (G = !0, console.error(
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
- o
177
- ));
178
- }
179
- u.isReactWarning = !0, Object.defineProperty(e, "key", {
180
- get: u,
181
- configurable: !0
182
- });
183
- }
184
- function p() {
185
- var e = t(this.type);
186
- return X[e] || (X[e] = !0, console.error(
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
- )), e = this.props.ref, e !== void 0 ? e : null;
189
- }
190
- function l(e, o, u, f, j, D) {
191
- var d = u.ref;
192
- return e = {
193
- $$typeof: y,
194
- type: e,
195
- key: o,
196
- props: u,
197
- _owner: f
198
- }, (d !== void 0 ? d : null) !== null ? Object.defineProperty(e, "ref", {
199
- enumerable: !1,
200
- get: p
201
- }) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
202
- configurable: !1,
203
- enumerable: !1,
204
- writable: !0,
205
- value: 0
206
- }), Object.defineProperty(e, "_debugInfo", {
207
- configurable: !1,
208
- enumerable: !1,
209
- writable: !0,
210
- value: null
211
- }), Object.defineProperty(e, "_debugStack", {
212
- configurable: !1,
213
- enumerable: !1,
214
- writable: !0,
215
- value: j
216
- }), Object.defineProperty(e, "_debugTask", {
217
- configurable: !1,
218
- enumerable: !1,
219
- writable: !0,
220
- value: D
221
- }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
222
- }
223
- function i(e, o, u, f, j, D) {
224
- var d = o.children;
225
- if (d !== void 0)
226
- if (f)
227
- if (ie(d)) {
228
- for (f = 0; f < d.length; f++)
229
- _(d[f]);
230
- Object.freeze && Object.freeze(d);
231
- } else
232
- console.error(
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
- );
235
- else _(d);
236
- if (q.call(o, "key")) {
237
- d = t(e);
238
- var w = Object.keys(o).filter(function(fe) {
239
- return fe !== "key";
240
- });
241
- f = 0 < w.length ? "{key: someKey, " + w.join(": ..., ") + ": ...}" : "{key: someKey}", Z[d + f] || (w = 0 < w.length ? "{" + w.join(": ..., ") + ": ...}" : "{}", console.error(
242
- `A props object containing a "key" prop is being spread into JSX:
243
- let props = %s;
244
- <%s {...props} />
245
- React keys must be passed directly to JSX without using spread:
246
- let props = %s;
247
- <%s key={someKey} {...props} />`,
248
- f,
249
- d,
250
- w,
251
- d
252
- ), Z[d + f] = !0);
253
- }
254
- if (d = null, u !== void 0 && (r(u), d = "" + u), m(o) && (r(o.key), d = "" + o.key), "key" in o) {
255
- u = {};
256
- for (var F in o)
257
- F !== "key" && (u[F] = o[F]);
258
- } else u = o;
259
- return d && v(
260
- u,
261
- typeof e == "function" ? e.displayName || e.name || "Unknown" : e
262
- ), l(
263
- e,
264
- d,
265
- u,
266
- n(),
267
- j,
268
- D
269
- );
270
- }
271
- function _(e) {
272
- S(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === $ && (e._payload.status === "fulfilled" ? S(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
273
- }
274
- function S(e) {
275
- return typeof e == "object" && e !== null && e.$$typeof === y;
276
- }
277
- var T = de, y = Symbol.for("react.transitional.element"), R = Symbol.for("react.portal"), E = Symbol.for("react.fragment"), g = Symbol.for("react.strict_mode"), A = Symbol.for("react.profiler"), b = Symbol.for("react.consumer"), h = Symbol.for("react.context"), O = Symbol.for("react.forward_ref"), U = Symbol.for("react.suspense"), k = Symbol.for("react.suspense_list"), ce = Symbol.for("react.memo"), $ = Symbol.for("react.lazy"), ue = Symbol.for("react.activity"), le = Symbol.for("react.client.reference"), I = T.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, q = Object.prototype.hasOwnProperty, ie = Array.isArray, Y = console.createTask ? console.createTask : function() {
278
- return null;
279
- };
280
- T = {
281
- react_stack_bottom_frame: function(e) {
282
- return e();
283
- }
284
- };
285
- var G, X = {}, B = T.react_stack_bottom_frame.bind(
286
- T,
287
- c
288
- )(), H = Y(a(c)), Z = {};
289
- x.Fragment = E, x.jsx = function(e, o, u) {
290
- var f = 1e4 > I.recentlyCreatedOwnerStacks++;
291
- return i(
292
- e,
293
- o,
294
- u,
295
- !1,
296
- f ? Error("react-stack-top-frame") : B,
297
- f ? Y(a(e)) : H
298
- );
299
- }, x.jsxs = function(e, o, u) {
300
- var f = 1e4 > I.recentlyCreatedOwnerStacks++;
301
- return i(
302
- e,
303
- o,
304
- u,
305
- !0,
306
- f ? Error("react-stack-top-frame") : B,
307
- f ? Y(a(e)) : H
308
- );
309
- };
310
- })()), x;
311
- }
312
- var ee;
313
- function he() {
314
- return ee || (ee = 1, process.env.NODE_ENV === "production" ? N.exports = Te() : N.exports = ye()), N.exports;
315
- }
316
- var ge = he();
317
- const ae = me({
318
- stateVocab: {},
319
- setStateVocab: () => {
64
+ subscribe(e) {
65
+ return this.#t.add(e), () => this.#t.delete(e);
66
+ }
67
+ getClientSnapshot() {
68
+ return this.#e;
69
+ }
70
+ getServerSnapshot() {
71
+ return this.#e;
72
+ }
73
+ get(e) {
74
+ return x(this.#e, e);
75
+ }
76
+ set(e, n) {
77
+ const o = x(this.#e, e), c = M(n) ? n(o) : n, r = { ...this.#e };
78
+ P(r, e, c), this.#e = r, this.#t.forEach((s) => s());
320
79
  }
321
- });
322
- function ke() {
323
- return be(ae);
324
80
  }
325
- const Oe = (t) => {
326
- const { children: s, verbose: r } = t, [a, n] = ne({});
327
- return r && Re(a), /* @__PURE__ */ ge.jsx(ae.Provider, { value: { stateVocab: a, setStateVocab: n }, children: s });
328
- }, V = (t, s) => (r) => {
329
- const a = { ...r };
330
- return _e(a, t, s), a;
331
- }, we = (t) => typeof t == "function", Pe = (t) => typeof t == "function", z = (t) => typeof t < "u", L = (t) => Pe(t) ? t() : t, xe = typeof window > "u";
332
- function je(t = {}) {
81
+ function X(t = {}) {
82
+ const e = new G(), n = t.serialize ?? JSON.stringify, o = t.deserialize ?? JSON.parse, c = (r, s, a) => {
83
+ const f = s.getItem(r);
84
+ f === null ? m(a) && s.setItem(r, n(a)) : e.set(r, o(f));
85
+ };
333
86
  return {
334
- [oe]: !0,
87
+ [L]: !0,
335
88
  // marks this object as a leaf in the router tree
336
- [J]: !1,
337
- // placeholder; injected at runtime by injectPaths()
338
- [C]: "",
89
+ [V]: "",
339
90
  // placeholder; injected at runtime by injectPaths()
340
- useState(s) {
341
- const r = xe ? void 0 : L(t.storage), a = t.serialize ?? JSON.stringify, n = t.deserialize ?? JSON.parse, c = L(t.defaultValue), m = t.bidirectional;
342
- s ??= {};
343
- const v = L(s.defaultValue), p = Se(
344
- s.onSet ?? (() => {
91
+ [k]: !1,
92
+ // placeholder
93
+ [z]: !1,
94
+ // placeholder
95
+ useState(r) {
96
+ const s = N ? void 0 : $(t.storage), a = $(t.defaultValue), f = t.bidirectional;
97
+ r ??= {};
98
+ const d = $(r.defaultValue) ?? a, p = r.bidirectional ?? f, u = K(
99
+ r.onSet ?? (() => {
345
100
  }),
346
- s.delayedSet,
101
+ r.delayedSet,
347
102
  []
348
- ), l = ke(), i = this[C], _ = this[J], [S, T] = ne(!_);
349
- M(() => T(!0), []);
350
- const y = W(
351
- () => {
352
- if (!S || !r)
353
- return;
354
- const b = r.getItem(i);
355
- return b === null ? null : n(b);
356
- },
357
- // eslint-disable-next-line react-hooks/exhaustive-deps
358
- [S]
359
- ), R = W(
360
- () => Ee(
361
- l.stateVocab,
362
- i,
363
- // 3rd argument in order to avoid waiting for useEffect execution
364
- y ?? v ?? c
365
- ),
366
- // eslint-disable-next-line react-hooks/exhaustive-deps
367
- [
368
- l.stateVocab,
369
- y
370
- ]
371
- ), E = ve(R);
372
- return M(
373
- () => {
374
- z(R) && (l.setStateVocab(V(i, R)), r && y === null && r.setItem(i, a(R)), E.current = R);
375
- },
376
- // eslint-disable-next-line react-hooks/exhaustive-deps
377
- [y]
378
- ), M(() => {
379
- if (!s.bidirectional && !m)
103
+ ), i = this[V], h = this[k], y = this[z], S = C(void 0), E = C(!1);
104
+ if (!E.current) {
105
+ E.current = !0;
106
+ let l = e.get(i);
107
+ m(l) || (l = d, m(l) && e.set(i, l)), !y && s && c(i, s, l);
108
+ }
109
+ const w = F(
110
+ e.subscribe.bind(e),
111
+ e.getClientSnapshot.bind(e),
112
+ e.getServerSnapshot.bind(e)
113
+ );
114
+ h && W(w);
115
+ const b = x(w, i, d);
116
+ S.current = b, q(() => {
117
+ !y || !s || c(i, s, b);
118
+ }, []);
119
+ const g = O((l) => {
120
+ if (l.key !== i)
380
121
  return;
381
- const b = (h) => {
382
- if (h.key !== i)
383
- return;
384
- const O = h.newValue, k = (O === null ? null : n(O)) ?? v ?? c;
385
- z(k) && (l.setStateVocab(V(i, k)), p(k, E.current), E.current = k);
386
- };
387
- return window.addEventListener("storage", b), () => window.removeEventListener("storage", b);
122
+ const v = l.newValue, I = (v === null ? null : o(v)) ?? d;
123
+ m(I) && (e.set(i, I), u(I, S.current));
124
+ });
125
+ A(() => {
126
+ if (p)
127
+ return window.addEventListener("storage", g), () => window.removeEventListener("storage", g);
128
+ }, [p]);
129
+ const T = R((l) => {
130
+ const v = M(l) ? l(S.current) : l;
131
+ e.set(i, v), u(v, S.current), s && s.setItem(i, n(v));
388
132
  }, [
389
- s.bidirectional,
390
- m
391
- ]), [
392
- R,
393
- (b) => {
394
- const h = we(b) ? b(E.current) : b;
395
- l.setStateVocab(V(i, h)), p(h, E.current), r && r.setItem(i, a(h)), E.current = h;
396
- },
397
- () => {
398
- const b = v ?? c;
399
- if (!z(b)) {
400
- r?.removeItem(i);
401
- return;
402
- }
403
- l.setStateVocab(V(i, b)), p(b, E.current), E.current = b, r && r.setItem(i, a(b));
133
+ i,
134
+ s,
135
+ n,
136
+ u
137
+ ]), _ = R(() => {
138
+ const l = d;
139
+ if (!m(l)) {
140
+ s?.removeItem(i);
141
+ return;
404
142
  }
143
+ e.set(i, l), u(l, S.current), s && s.setItem(i, n(l));
144
+ }, [
145
+ i,
146
+ d,
147
+ s,
148
+ n,
149
+ u
150
+ ]);
151
+ return [
152
+ b,
153
+ T,
154
+ _
405
155
  ];
406
156
  },
407
157
  /** Returns the fully qualified job name (dot-separated path). */
408
158
  toString() {
409
- return this[C];
159
+ return this[V];
410
160
  }
411
161
  };
412
162
  }
413
- const te = /* @__PURE__ */ new WeakMap(), re = /* @__PURE__ */ new WeakMap();
414
- function se(t, s) {
415
- s ??= {};
163
+ function D(t, e) {
416
164
  const {
417
- path: r = "",
418
- ssr: a
419
- } = s;
420
- let n = te.get(t);
421
- n || (n = /* @__PURE__ */ new Map(), te.set(t, n));
422
- const c = n.get(r);
423
- if (c)
424
- return c;
425
- const m = new Proxy(t, {
426
- get(v, p) {
427
- const l = v[p], i = r ? `${r}.${String(p)}` : String(p);
428
- if (l && typeof l == "object" && oe in l) {
429
- const _ = l;
430
- let S = re.get(_);
431
- S || (S = /* @__PURE__ */ new Map(), re.set(_, S));
432
- const T = S.get(i);
433
- if (T)
434
- return T;
435
- const y = Reflect.ownKeys(_).filter(
436
- (g) => typeof _[g] == "function"
437
- ), R = Object.fromEntries(
438
- y.map((g) => [
165
+ path: n = "",
166
+ verbose: o,
167
+ ssr: c,
168
+ cache: r
169
+ } = e;
170
+ let s = r.proxy.get(t);
171
+ s || (s = /* @__PURE__ */ new Map(), r.proxy.set(t, s));
172
+ const a = s.get(n);
173
+ if (a)
174
+ return a;
175
+ const f = new Proxy(t, {
176
+ get(d, p) {
177
+ const u = d[p], i = n ? `${n}.${String(p)}` : String(p);
178
+ if (u && typeof u == "object" && L in u) {
179
+ const h = u;
180
+ let y = r.leaf.get(h);
181
+ y || (y = /* @__PURE__ */ new Map(), r.leaf.set(h, y));
182
+ const S = y.get(i);
183
+ if (S)
184
+ return S;
185
+ const E = Reflect.ownKeys(h).filter(
186
+ (g) => typeof h[g] == "function"
187
+ ), w = Object.fromEntries(
188
+ E.map((g) => [
439
189
  g,
440
- (...A) => _[g].call(
190
+ (...T) => h[g].call(
441
191
  {
442
- ..._,
443
- [C]: i,
444
- [J]: a
192
+ ...h,
193
+ [V]: i,
194
+ [k]: o,
195
+ [z]: c
445
196
  },
446
- ...A
197
+ ...T
447
198
  )
448
199
  ])
449
- ), E = { ..._, ...R };
450
- return S.set(i, E), E;
200
+ ), b = { ...h, ...w };
201
+ return y.set(i, b), b;
451
202
  }
452
- return l && typeof l == "object" ? se(l, {
453
- path: i,
454
- ssr: a
455
- }) : l;
203
+ return u && typeof u == "object" ? D(u, {
204
+ ...e,
205
+ path: i
206
+ }) : u;
456
207
  }
457
208
  });
458
- return n.set(r, m), m;
209
+ return s.set(n, f), f;
459
210
  }
460
- function Ne(t, s) {
461
- return se(t, s);
211
+ function Y(t, e) {
212
+ return D(t, {
213
+ ...e,
214
+ cache: {
215
+ proxy: /* @__PURE__ */ new WeakMap(),
216
+ leaf: /* @__PURE__ */ new WeakMap()
217
+ }
218
+ });
462
219
  }
463
220
  export {
464
- Oe as StorageProvider,
465
- je as defineState,
466
- Ne as setupStorage
221
+ X as defineState,
222
+ Y as setupStorage
467
223
  };
@@ -1,3 +1,4 @@
1
1
  export declare const STATE_DEFINITION: unique symbol;
2
2
  export declare const STATE_PATH: unique symbol;
3
+ export declare const STATE_VERBOSE: unique symbol;
3
4
  export declare const STATE_SSR: unique symbol;
@@ -1,3 +1,2 @@
1
1
  export { defineState } from "./state";
2
2
  export { setupStorage } from "./setup";
3
- export { StateVocabContextProvider as StorageProvider } from "./context";
@@ -1,2 +1,2 @@
1
1
  export declare const toLocalDatetimeString: (date: Date | null) => string;
2
- export declare const toDateString: (date: Date | null) => string | undefined;
2
+ export declare const toDateString: (date: Date | null) => string;
@@ -1,3 +1,7 @@
1
- export declare function setupStorage<T extends object>(native: T, options?: Partial<{
1
+ type InjectPathsOptions = {
2
+ path: string;
3
+ verbose: boolean;
2
4
  ssr: boolean;
3
- }>): T;
5
+ };
6
+ export declare function setupStorage<T extends object>(native: T, options?: Partial<Omit<InjectPathsOptions, "path">>): T;
7
+ export {};
@@ -1,4 +1,4 @@
1
- import { STATE_DEFINITION, STATE_PATH, STATE_SSR } from "./constants";
1
+ import { STATE_DEFINITION, STATE_PATH, STATE_SSR, STATE_VERBOSE } from "./constants";
2
2
  import type { Deserialize, Serialize, ValueOrFactory, ValueOrTransformer } from "./state.types";
3
3
  export declare function defineState<D>(definitionOptions?: {
4
4
  storage?: ValueOrFactory<Storage>;
@@ -8,10 +8,12 @@ export declare function defineState<D>(definitionOptions?: {
8
8
  deserialize?: Deserialize<D>;
9
9
  }): {
10
10
  [STATE_DEFINITION]: boolean;
11
- [STATE_SSR]: boolean;
12
11
  [STATE_PATH]: string;
12
+ [STATE_VERBOSE]: boolean;
13
+ [STATE_SSR]: boolean;
13
14
  useState(this: {
14
15
  [STATE_PATH]: string;
16
+ [STATE_VERBOSE]: boolean;
15
17
  [STATE_SSR]: boolean;
16
18
  }, options?: {
17
19
  defaultValue?: ValueOrFactory<D>;
@@ -1,8 +1,4 @@
1
- import type { Vocab } from "./context";
2
1
  import type { ValueOrTransformer, Transformer, ValueOrFactory } from "./state.types";
3
- export declare const embed: <D>(statePath: string, value: D) => (vocab: Vocab<D>) => {
4
- [x: string]: D | null;
5
- };
6
2
  export declare const isTransformer: <V>(v: ValueOrTransformer<V>) => v is Transformer<V>;
7
3
  export declare const isValueDefined: <V>(v: V | undefined) => v is V;
8
4
  export declare const valueOrFactory: <V>(input: ValueOrFactory<V>) => V;
@@ -4,4 +4,4 @@ export declare function set(obj: Record<string, unknown>, path: string, value: u
4
4
  export declare function debounce<T extends (...args: never[]) => unknown>(func: T, wait?: number): (...args: Parameters<T>) => void;
5
5
  export declare function useDebounce<T extends (...args: never[]) => unknown>(effect: T, wait: number | undefined, deps?: DependencyList): (...args: Parameters<T>) => void;
6
6
  export declare const isJsonValid: (input: string) => boolean;
7
- export declare function logStyled(obj: object): void;
7
+ export declare function logStyled(obj: unknown): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yakocloud/state-vocab",
3
- "version": "2.5.1",
3
+ "version": "3.0.2",
4
4
  "main": "dist/state-vocab.cjs.js",
5
5
  "module": "dist/state-vocab.es.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -1,11 +0,0 @@
1
- import { type SetStateAction, type PropsWithChildren, type Dispatch } from "react";
2
- export type Vocab<T = unknown> = Record<string, T | null>;
3
- type Context<V extends Vocab = Vocab> = {
4
- stateVocab: V;
5
- setStateVocab: Dispatch<SetStateAction<V>>;
6
- };
7
- export declare function useStateVocabContext<T>(): Context<Vocab<T>>;
8
- export declare const StateVocabContextProvider: (props: PropsWithChildren<{
9
- verbose?: boolean;
10
- }>) => import("react/jsx-runtime").JSX.Element;
11
- export {};