@yakocloud/state-vocab 3.1.1 → 3.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 +69 -4
- package/dist/state-vocab.cjs.js +4 -4
- package/dist/state-vocab.es.js +314 -277
- package/dist/types/context.d.ts +4 -2
- package/dist/types/index.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -103,7 +103,7 @@ defineState({
|
|
|
103
103
|
})
|
|
104
104
|
```
|
|
105
105
|
|
|
106
|
-
**Minimal API surface.**
|
|
106
|
+
**Minimal API surface.** Three exports: `defineState`, `setupStorage`, `VocabStateProvider`. No actions, reducers, selectors, or stores to configure.
|
|
107
107
|
|
|
108
108
|
## Installation
|
|
109
109
|
|
|
@@ -115,8 +115,13 @@ npm install @yakocloud/state-vocab react react-dom
|
|
|
115
115
|
|
|
116
116
|
## Quick Start
|
|
117
117
|
|
|
118
|
+
Wrap your app with `VocabStateProvider` at the root — this initializes an isolated store for the component tree. Then define and use state anywhere inside it.
|
|
119
|
+
Library SSR-requirements:
|
|
120
|
+
- `Per-request store`: A Next.js server can handle multiple requests simultaneously. This means that the store should be created per request and should not be shared across requests.
|
|
121
|
+
- `SSR friendly`: Next.js applications are rendered twice, first on the server and again on the client. Having different outputs on both the client and the server will result in "hydration errors." The store will have to be initialized on the server and then re-initialized on the client with the same data in order to avoid that.
|
|
122
|
+
|
|
118
123
|
```tsx
|
|
119
|
-
import { setupStorage, defineState } from '@yakocloud/state-vocab'
|
|
124
|
+
import { setupStorage, defineState, VocabStateProvider } from '@yakocloud/state-vocab'
|
|
120
125
|
|
|
121
126
|
type Theme = 'Dark' | 'White' | 'System'
|
|
122
127
|
|
|
@@ -131,6 +136,14 @@ const storage = setupStorage({
|
|
|
131
136
|
},
|
|
132
137
|
})
|
|
133
138
|
|
|
139
|
+
function App() {
|
|
140
|
+
return (
|
|
141
|
+
<VocabStateProvider>
|
|
142
|
+
<Settings />
|
|
143
|
+
</VocabStateProvider>
|
|
144
|
+
)
|
|
145
|
+
}
|
|
146
|
+
|
|
134
147
|
function Settings() {
|
|
135
148
|
const [theme, setTheme] = storage.path.to.theme.useState()
|
|
136
149
|
|
|
@@ -144,6 +157,38 @@ function Settings() {
|
|
|
144
157
|
}
|
|
145
158
|
```
|
|
146
159
|
|
|
160
|
+
## Setup
|
|
161
|
+
|
|
162
|
+
### `VocabStateProvider`
|
|
163
|
+
|
|
164
|
+
All components that call `.useState()` must be descendants of `VocabStateProvider`. It creates an isolated `VocabStore` instance for its subtree — multiple providers can coexist in the same app without sharing state.
|
|
165
|
+
|
|
166
|
+
```tsx
|
|
167
|
+
import { VocabStateProvider } from '@yakocloud/state-vocab'
|
|
168
|
+
|
|
169
|
+
// Wrap your app root
|
|
170
|
+
createRoot(document.getElementById('root')!).render(
|
|
171
|
+
<React.StrictMode>
|
|
172
|
+
<VocabStateProvider>
|
|
173
|
+
<App />
|
|
174
|
+
</VocabStateProvider>
|
|
175
|
+
</React.StrictMode>
|
|
176
|
+
)
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
You can mount multiple independent providers — each gets its own store:
|
|
180
|
+
|
|
181
|
+
```tsx
|
|
182
|
+
// Two isolated state trees — state does not bleed between them
|
|
183
|
+
<VocabStateProvider>
|
|
184
|
+
<WidgetA />
|
|
185
|
+
</VocabStateProvider>
|
|
186
|
+
|
|
187
|
+
<VocabStateProvider>
|
|
188
|
+
<WidgetB />
|
|
189
|
+
</VocabStateProvider>
|
|
190
|
+
```
|
|
191
|
+
|
|
147
192
|
## Core Concepts
|
|
148
193
|
|
|
149
194
|
### `defineState(options?)`
|
|
@@ -247,6 +292,8 @@ With `ssr: true`:
|
|
|
247
292
|
|
|
248
293
|
This guarantees the server and client produce identical markup, and the value from storage is applied without a visible flash.
|
|
249
294
|
|
|
295
|
+
Wrap your page or app root with `VocabStateProvider` as usual — it works correctly in both SSR and client environments.
|
|
296
|
+
|
|
250
297
|
## `useState` Hook
|
|
251
298
|
|
|
252
299
|
Each state node exposes a `.useState()` method that works like React's built-in `useState` but adds persistence and callbacks.
|
|
@@ -325,7 +372,9 @@ const storage = setupStorage({
|
|
|
325
372
|
## Full Example
|
|
326
373
|
|
|
327
374
|
```tsx
|
|
328
|
-
import
|
|
375
|
+
import React from 'react'
|
|
376
|
+
import { createRoot } from 'react-dom/client'
|
|
377
|
+
import { setupStorage, defineState, VocabStateProvider } from '@yakocloud/state-vocab'
|
|
329
378
|
|
|
330
379
|
type Theme = 'Dark' | 'White' | 'System'
|
|
331
380
|
|
|
@@ -409,7 +458,13 @@ function Dashboard() {
|
|
|
409
458
|
)
|
|
410
459
|
}
|
|
411
460
|
|
|
412
|
-
createRoot(document.getElementById('root')!).render(
|
|
461
|
+
createRoot(document.getElementById('root')!).render(
|
|
462
|
+
<React.StrictMode>
|
|
463
|
+
<VocabStateProvider>
|
|
464
|
+
<Page />
|
|
465
|
+
</VocabStateProvider>
|
|
466
|
+
</React.StrictMode>
|
|
467
|
+
)
|
|
413
468
|
```
|
|
414
469
|
|
|
415
470
|
## API Reference
|
|
@@ -434,6 +489,16 @@ createRoot(document.getElementById('root')!).render(<Page />)
|
|
|
434
489
|
|
|
435
490
|
Returns a proxied copy of `tree` with paths injected into all leaf nodes.
|
|
436
491
|
|
|
492
|
+
### `VocabStateProvider`
|
|
493
|
+
|
|
494
|
+
A React context provider that initializes a `VocabStore` for its subtree. Required — all components calling `.useState()` must be descendants of this provider.
|
|
495
|
+
|
|
496
|
+
```tsx
|
|
497
|
+
<VocabStateProvider>
|
|
498
|
+
<App />
|
|
499
|
+
</VocabStateProvider>
|
|
500
|
+
```
|
|
501
|
+
|
|
437
502
|
### `node.useState(options?)`
|
|
438
503
|
|
|
439
504
|
| Option | Type | Description |
|
package/dist/state-vocab.cjs.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
`),n=[],m=[];for(const s of c){const u=s.match(/^(\s*)"([^"]+)"(\s*:\s*)(.+)$/);if(u){const[,b,o,g,y]=u;n.push(`${b}%c"${o}"%c${g}%c${y}`),m.push("color: #9cdcfe; font-weight: bold","color: #cccccc","color: #ce9178")}else n.push(`%c${s}`),m.push("color: #cccccc")}console.log(n.join(`
|
|
3
|
-
`),...m,t)}const me=t=>typeof t=="function",be=t=>typeof t=="function",C=t=>typeof t<"u",J=t=>be(t)?t():t;var Y={exports:{}},I={};var re;function Ee(){if(re)return I;re=1;var t=Symbol.for("react.transitional.element"),c=Symbol.for("react.fragment");function n(m,s,u){var b=null;if(u!==void 0&&(b=""+u),s.key!==void 0&&(b=""+s.key),"key"in s){u={};for(var o in s)o!=="key"&&(u[o]=s[o])}else u=s;return s=u.ref,{$$typeof:t,type:m,key:b,ref:s!==void 0?s:null,props:u}}return I.Fragment=c,I.jsx=n,I.jsxs=n,I}var $={};var ne;function ve(){return ne||(ne=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 T:return"Fragment";case A:return"Profiler";case x:return"StrictMode";case F:return"Suspense";case a:return"SuspenseList";case w: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 _:return"Portal";case h:return e.displayName||"Context";case k:return(e._context.displayName||"Context")+".Consumer";case N:var r=e.render;return e=e.displayName,e||(e=r.displayName||r.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case R:return r=e.displayName||null,r!==null?r:t(e.type)||"Memo";case O:r=e._payload,e=e._init;try{return t(e(r))}catch{}}return null}function c(e){return""+e}function n(e){try{c(e);var r=!1}catch{r=!0}if(r){r=console;var l=r.error,f=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return l.call(r,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",f),c(e)}}function m(e){if(e===T)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===O)return"<...>";try{var r=t(e);return r?"<"+r+">":"<...>"}catch{return"<...>"}}function s(){var e=M.A;return e===null?null:e.getOwner()}function u(){return Error("react-stack-top-frame")}function b(e){if(B.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function o(e,r){function l(){X||(X=!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)",r))}l.isReactWarning=!0,Object.defineProperty(e,"key",{get:l,configurable:!0})}function g(){var e=t(this.type);return H[e]||(H[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 y(e,r,l,f,V,L){var d=l.ref;return e={$$typeof:v,type:e,key:r,props:l,_owner:f},(d!==void 0?d:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:g}):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:V}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:L}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function P(e,r,l,f,V,L){var d=r.children;if(d!==void 0)if(f)if(le(d)){for(f=0;f<d.length;f++)i(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 i(d);if(B.call(r,"key")){d=t(e);var j=Object.keys(r).filter(function(ie){return ie!=="key"});f=0<j.length?"{key: someKey, "+j.join(": ..., ")+": ...}":"{key: someKey}",K[d+f]||(j=0<j.length?"{"+j.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("react");var Y={exports:{}},N={};var te;function me(){if(te)return N;te=1;var t=Symbol.for("react.transitional.element"),n=Symbol.for("react.fragment");function r(l,s,a){var i=null;if(a!==void 0&&(i=""+a),s.key!==void 0&&(i=""+s.key),"key"in s){a={};for(var c in s)c!=="key"&&(a[c]=s[c])}else a=s;return s=a.ref,{$$typeof:t,type:l,key:i,ref:s!==void 0?s:null,props:a}}return N.Fragment=n,N.jsx=r,N.jsxs=r,N}var V={};var re;function ve(){return re||(re=1,process.env.NODE_ENV!=="production"&&(function(){function t(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===fe?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case _:return"Fragment";case x:return"Profiler";case O:return"StrictMode";case F:return"Suspense";case u:return"SuspenseList";case w: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 p:return"Portal";case g:return e.displayName||"Context";case k:return(e._context.displayName||"Context")+".Consumer";case C:var o=e.render;return e=e.displayName,e||(e=o.displayName||o.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case y:return o=e.displayName||null,o!==null?o:t(e.type)||"Memo";case A:o=e._payload,e=e._init;try{return t(e(o))}catch{}}return null}function n(e){return""+e}function r(e){try{n(e);var o=!1}catch{o=!0}if(o){o=console;var f=o.error,b=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return f.call(o,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",b),n(e)}}function l(e){if(e===_)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===A)return"<...>";try{var o=t(e);return o?"<"+o+">":"<...>"}catch{return"<...>"}}function s(){var e=z.A;return e===null?null:e.getOwner()}function a(){return Error("react-stack-top-frame")}function i(e){if(X.call(e,"key")){var o=Object.getOwnPropertyDescriptor(e,"key").get;if(o&&o.isReactWarning)return!1}return e.key!==void 0}function c(e,o){function f(){H||(H=!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))}f.isReactWarning=!0,Object.defineProperty(e,"key",{get:f,configurable:!0})}function R(){var e=t(this.type);return Z[e]||(Z[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 T(e,o,f,b,I,W){var m=f.ref;return e={$$typeof:S,type:e,key:o,props:f,_owner:b},(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:I}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:W}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function P(e,o,f,b,I,W){var m=o.children;if(m!==void 0)if(b)if(de(m)){for(b=0;b<m.length;b++)d(m[b]);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 d(m);if(X.call(o,"key")){m=t(e);var j=Object.keys(o).filter(function(be){return be!=="key"});b=0<j.length?"{key: someKey, "+j.join(": ..., ")+": ...}":"{key: someKey}",ee[m+b]||(j=0<j.length?"{"+j.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
4
2
|
let props = %s;
|
|
5
3
|
<%s {...props} />
|
|
6
4
|
React keys must be passed directly to JSX without using spread:
|
|
7
5
|
let props = %s;
|
|
8
|
-
<%s key={someKey} {...props} />`,
|
|
6
|
+
<%s key={someKey} {...props} />`,b,m,j,m),ee[m+b]=!0)}if(m=null,f!==void 0&&(r(f),m=""+f),i(o)&&(r(o.key),m=""+o.key),"key"in o){f={};for(var J in o)J!=="key"&&(f[J]=o[J])}else f=o;return m&&c(f,typeof e=="function"?e.displayName||e.name||"Unknown":e),T(e,m,f,s(),I,W)}function d(e){v(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===A&&(e._payload.status==="fulfilled"?v(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function v(e){return typeof e=="object"&&e!==null&&e.$$typeof===S}var h=E,S=Symbol.for("react.transitional.element"),p=Symbol.for("react.portal"),_=Symbol.for("react.fragment"),O=Symbol.for("react.strict_mode"),x=Symbol.for("react.profiler"),k=Symbol.for("react.consumer"),g=Symbol.for("react.context"),C=Symbol.for("react.forward_ref"),F=Symbol.for("react.suspense"),u=Symbol.for("react.suspense_list"),y=Symbol.for("react.memo"),A=Symbol.for("react.lazy"),w=Symbol.for("react.activity"),fe=Symbol.for("react.client.reference"),z=h.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,X=Object.prototype.hasOwnProperty,de=Array.isArray,L=console.createTask?console.createTask:function(){return null};h={react_stack_bottom_frame:function(e){return e()}};var H,Z={},Q=h.react_stack_bottom_frame.bind(h,a)(),K=L(l(a)),ee={};V.Fragment=_,V.jsx=function(e,o,f){var b=1e4>z.recentlyCreatedOwnerStacks++;return P(e,o,f,!1,b?Error("react-stack-top-frame"):Q,b?L(l(e)):K)},V.jsxs=function(e,o,f){var b=1e4>z.recentlyCreatedOwnerStacks++;return P(e,o,f,!0,b?Error("react-stack-top-frame"):Q,b?L(l(e)):K)}})()),V}var ne;function Ee(){return ne||(ne=1,process.env.NODE_ENV==="production"?Y.exports=me():Y.exports=ve()),Y.exports}var Se=Ee();function D(t,n,r){if(!n)return t;const l=n.split(".");let s=t;for(const a of l)if(s!==null&&typeof s=="object"&&a in s)s=s[a];else return r;return s===void 0?r:s}function pe(t,n,r){const l=n.replace(/\[(\d+)\]/g,".$1").split(".");let s=t;for(let a=0;a<l.length-1;a++){const i=l[a],c=l[a+1];(s[i]===void 0||s[i]===null)&&(s[i]=/^\d+$/.test(c)?[]:{}),s=s[i]}return s[l[l.length-1]]=r,t}function he(t,n=0){let r;return function(...l){r!==void 0&&clearTimeout(r),r=setTimeout(()=>{r=void 0,t.apply(this,l)},n)}}function _e(t,n,r=[]){return E.useMemo(()=>he(t,n),r)}function oe(t){const n=JSON.stringify(t,null,2).split(`
|
|
7
|
+
`),r=[],l=[];for(const s of n){const a=s.match(/^(\s*)"([^"]+)"(\s*:\s*)(.+)$/);if(a){const[,i,c,R,T]=a;r.push(`${i}%c"${c}"%c${R}%c${T}`),l.push("color: #9cdcfe; font-weight: bold","color: #cccccc","color: #ce9178")}else r.push(`%c${s}`),l.push("color: #cccccc")}console.log(r.join(`
|
|
8
|
+
`),...l,t)}const se=t=>typeof t=="function",ye=t=>typeof t=="function",$=t=>typeof t<"u",U=t=>ye(t)?t():t;class Re{#e;#t;constructor(){this.uid=Math.random().toString(36).slice(2),this.#e={},this.#t=new Set}subscribe(n){return this.#t.add(n),()=>this.#t.delete(n)}getClientSnapshot(){return this.#e}getServerSnapshot(){return this.#e}get(n){return D(this.#e,n)}set(n,r){const l=D(this.#e,n),s=se(r)?r(l):r,a={...this.#e};pe(a,n,s),this.#e=a,this.#t.forEach(i=>i())}}const ae=E.createContext({});function ce(t={}){const n=E.useContext(ae);return t.verbose&&console.log(`[${ce.name}]: `,n.uid),n}function Te({children:t}){const n=E.useMemo(()=>new Re,[]);return Se.jsx(ae.Provider,{value:n,children:t})}const ue=Symbol("state-def"),M=Symbol("state-path"),q=Symbol("state-verbose"),G=Symbol("state-verbose-path"),B=Symbol("state-ssr"),le=typeof window>"u",ge=le?E.useEffect:E.useLayoutEffect;function ke(t={}){return{[ue]:!0,[M]:"",[q]:!1,[G]:"",[B]:!1,useState(n){const r=le?void 0:U(t.storage),l=U(t.defaultValue),s=t.bidirectional;n??={};const a=U(n.defaultValue)??l,i=n.bidirectional??s,c=this[M],R=this[q],T=this[G],P=this[B],d=ce({verbose:R}),v=t.serialize??JSON.stringify,h=t.deserialize??JSON.parse,S=(u,y,A)=>{const w=y.getItem(u);w===null?$(A)&&y.setItem(u,v(A)):d.set(u,h(w))},p=_e(n.onSet??(()=>{}),n.delayedSet,[]),_=E.useRef(void 0),O=E.useRef(!1);if(!O.current){O.current=!0;let u=d.get(c);$(u)||(u=a,$(u)&&d.set(c,u)),!P&&r&&S(c,r,u)}const x=E.useSyncExternalStore(d.subscribe.bind(d),d.getClientSnapshot.bind(d),d.getServerSnapshot.bind(d));if(R)if(T){const u=D(x,T);u&&oe(u)}else oe(x);const k=D(x,c,a);_.current=k,ge(()=>{!P||!r||S(c,r,k)},[]);const g=E.useEffectEvent(u=>{if(u.key!==c)return;const y=u.newValue,w=(y===null?null:h(y))??a;$(w)&&(d.set(c,w),p(w,_.current))});E.useEffect(()=>{if(i)return window.addEventListener("storage",g),()=>window.removeEventListener("storage",g)},[i]);const C=E.useCallback(u=>{const y=se(u)?u(_.current):u;d.set(c,y),p(y,_.current),r&&r.setItem(c,v(y))},[c,r,p]),F=E.useCallback(()=>{const u=a;if(!$(u)){r?.removeItem(c);return}d.set(c,u),p(u,_.current),r&&r.setItem(c,v(u))},[c,a,r,p]);return[k,C,F]},toString(){return this[M]}}}function ie(t,n){const{path:r="",verbose:l,verbosePath:s,ssr:a,cache:i}=n;let c=i.proxy.get(t);c||(c=new Map,i.proxy.set(t,c));const R=c.get(r);if(R)return R;const T=new Proxy(t,{get(P,d){const v=P[d],h=r?`${r}.${String(d)}`:String(d);if(v&&typeof v=="object"&&ue in v){const S=v;let p=i.leaf.get(S);p||(p=new Map,i.leaf.set(S,p));const _=p.get(h);if(_)return _;const O=Reflect.ownKeys(S).filter(g=>typeof S[g]=="function"),x=Object.fromEntries(O.map(g=>[g,(...C)=>S[g].call({...S,[M]:h,[q]:l,[G]:s,[B]:a},...C)])),k={...S,...x};return p.set(h,k),k}return v&&typeof v=="object"?ie(v,{...n,path:h}):v}});return c.set(r,T),T}function we(t,n){return ie(t,{...n,verbosePath:n?.verbosePath??"",cache:{proxy:new WeakMap,leaf:new WeakMap}})}exports.VocabStateProvider=Te;exports.defineState=ke;exports.setupStorage=we;
|
package/dist/state-vocab.es.js
CHANGED
|
@@ -1,93 +1,46 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
let n;
|
|
17
|
-
return function(...m) {
|
|
18
|
-
n !== void 0 && clearTimeout(n), n = setTimeout(() => {
|
|
19
|
-
n = void 0, t.apply(this, m);
|
|
20
|
-
}, c);
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
function Re(t, c, n = []) {
|
|
24
|
-
return Ee(
|
|
25
|
-
() => Te(t, c),
|
|
26
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
27
|
-
n
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
function re(t) {
|
|
31
|
-
const c = JSON.stringify(t, null, 2).split(`
|
|
32
|
-
`), n = [], m = [];
|
|
33
|
-
for (const a of c) {
|
|
34
|
-
const l = a.match(/^(\s*)"([^"]+)"(\s*:\s*)(.+)$/);
|
|
35
|
-
if (l) {
|
|
36
|
-
const [, E, o, h, R] = l;
|
|
37
|
-
n.push(`${E}%c"${o}"%c${h}%c${R}`), m.push(
|
|
38
|
-
"color: #9cdcfe; font-weight: bold",
|
|
39
|
-
"color: #cccccc",
|
|
40
|
-
"color: #ce9178"
|
|
41
|
-
);
|
|
42
|
-
} else
|
|
43
|
-
n.push(`%c${a}`), m.push("color: #cccccc");
|
|
44
|
-
}
|
|
45
|
-
console.log(n.join(`
|
|
46
|
-
`), ...m, t);
|
|
47
|
-
}
|
|
48
|
-
const ye = (t) => typeof t == "function", he = (t) => typeof t == "function", N = (t) => typeof t < "u", W = (t) => he(t) ? t() : t;
|
|
49
|
-
var V = { exports: {} }, C = {};
|
|
50
|
-
var ne;
|
|
51
|
-
function ge() {
|
|
52
|
-
if (ne) return C;
|
|
53
|
-
ne = 1;
|
|
54
|
-
var t = Symbol.for("react.transitional.element"), c = Symbol.for("react.fragment");
|
|
55
|
-
function n(m, a, l) {
|
|
56
|
-
var E = null;
|
|
57
|
-
if (l !== void 0 && (E = "" + l), a.key !== void 0 && (E = "" + a.key), "key" in a) {
|
|
58
|
-
l = {};
|
|
59
|
-
for (var o in a)
|
|
60
|
-
o !== "key" && (l[o] = a[o]);
|
|
61
|
-
} else l = a;
|
|
62
|
-
return a = l.ref, {
|
|
1
|
+
import pe, { useMemo as ae, createContext as Se, useContext as he, useRef as ee, useSyncExternalStore as _e, useEffect as ce, useLayoutEffect as ye, useEffectEvent as Re, useCallback as te } from "react";
|
|
2
|
+
var I = { exports: {} }, C = {};
|
|
3
|
+
var re;
|
|
4
|
+
function Te() {
|
|
5
|
+
if (re) return C;
|
|
6
|
+
re = 1;
|
|
7
|
+
var t = Symbol.for("react.transitional.element"), n = Symbol.for("react.fragment");
|
|
8
|
+
function r(l, s, a) {
|
|
9
|
+
var i = null;
|
|
10
|
+
if (a !== void 0 && (i = "" + a), s.key !== void 0 && (i = "" + s.key), "key" in s) {
|
|
11
|
+
a = {};
|
|
12
|
+
for (var c in s)
|
|
13
|
+
c !== "key" && (a[c] = s[c]);
|
|
14
|
+
} else a = s;
|
|
15
|
+
return s = a.ref, {
|
|
63
16
|
$$typeof: t,
|
|
64
|
-
type:
|
|
65
|
-
key:
|
|
66
|
-
ref:
|
|
67
|
-
props:
|
|
17
|
+
type: l,
|
|
18
|
+
key: i,
|
|
19
|
+
ref: s !== void 0 ? s : null,
|
|
20
|
+
props: a
|
|
68
21
|
};
|
|
69
22
|
}
|
|
70
|
-
return C.Fragment =
|
|
23
|
+
return C.Fragment = n, C.jsx = r, C.jsxs = r, C;
|
|
71
24
|
}
|
|
72
|
-
var
|
|
73
|
-
var
|
|
74
|
-
function
|
|
75
|
-
return
|
|
25
|
+
var N = {};
|
|
26
|
+
var ne;
|
|
27
|
+
function ge() {
|
|
28
|
+
return ne || (ne = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
76
29
|
function t(e) {
|
|
77
30
|
if (e == null) return null;
|
|
78
31
|
if (typeof e == "function")
|
|
79
|
-
return e.$$typeof ===
|
|
32
|
+
return e.$$typeof === be ? null : e.displayName || e.name || null;
|
|
80
33
|
if (typeof e == "string") return e;
|
|
81
34
|
switch (e) {
|
|
82
|
-
case
|
|
35
|
+
case h:
|
|
83
36
|
return "Fragment";
|
|
84
|
-
case
|
|
37
|
+
case x:
|
|
85
38
|
return "Profiler";
|
|
86
|
-
case
|
|
39
|
+
case A:
|
|
87
40
|
return "StrictMode";
|
|
88
|
-
case
|
|
41
|
+
case F:
|
|
89
42
|
return "Suspense";
|
|
90
|
-
case
|
|
43
|
+
case u:
|
|
91
44
|
return "SuspenseList";
|
|
92
45
|
case k:
|
|
93
46
|
return "Activity";
|
|
@@ -96,100 +49,100 @@ function ke() {
|
|
|
96
49
|
switch (typeof e.tag == "number" && console.error(
|
|
97
50
|
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
|
|
98
51
|
), e.$$typeof) {
|
|
99
|
-
case
|
|
52
|
+
case p:
|
|
100
53
|
return "Portal";
|
|
101
|
-
case
|
|
54
|
+
case T:
|
|
102
55
|
return e.displayName || "Context";
|
|
103
56
|
case g:
|
|
104
57
|
return (e._context.displayName || "Context") + ".Consumer";
|
|
105
58
|
case j:
|
|
106
|
-
var
|
|
107
|
-
return e = e.displayName, e || (e =
|
|
108
|
-
case
|
|
109
|
-
return
|
|
59
|
+
var o = e.render;
|
|
60
|
+
return e = e.displayName, e || (e = o.displayName || o.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
|
|
61
|
+
case _:
|
|
62
|
+
return o = e.displayName || null, o !== null ? o : t(e.type) || "Memo";
|
|
110
63
|
case P:
|
|
111
|
-
|
|
64
|
+
o = e._payload, e = e._init;
|
|
112
65
|
try {
|
|
113
|
-
return t(e(
|
|
66
|
+
return t(e(o));
|
|
114
67
|
} catch {
|
|
115
68
|
}
|
|
116
69
|
}
|
|
117
70
|
return null;
|
|
118
71
|
}
|
|
119
|
-
function
|
|
72
|
+
function n(e) {
|
|
120
73
|
return "" + e;
|
|
121
74
|
}
|
|
122
|
-
function
|
|
75
|
+
function r(e) {
|
|
123
76
|
try {
|
|
124
|
-
|
|
125
|
-
var
|
|
77
|
+
n(e);
|
|
78
|
+
var o = !1;
|
|
126
79
|
} catch {
|
|
127
|
-
|
|
80
|
+
o = !0;
|
|
128
81
|
}
|
|
129
|
-
if (
|
|
130
|
-
|
|
131
|
-
var
|
|
132
|
-
return
|
|
133
|
-
|
|
82
|
+
if (o) {
|
|
83
|
+
o = console;
|
|
84
|
+
var f = o.error, m = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
|
|
85
|
+
return f.call(
|
|
86
|
+
o,
|
|
134
87
|
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
|
135
|
-
|
|
136
|
-
),
|
|
88
|
+
m
|
|
89
|
+
), n(e);
|
|
137
90
|
}
|
|
138
91
|
}
|
|
139
|
-
function
|
|
140
|
-
if (e ===
|
|
92
|
+
function l(e) {
|
|
93
|
+
if (e === h) return "<>";
|
|
141
94
|
if (typeof e == "object" && e !== null && e.$$typeof === P)
|
|
142
95
|
return "<...>";
|
|
143
96
|
try {
|
|
144
|
-
var
|
|
145
|
-
return
|
|
97
|
+
var o = t(e);
|
|
98
|
+
return o ? "<" + o + ">" : "<...>";
|
|
146
99
|
} catch {
|
|
147
100
|
return "<...>";
|
|
148
101
|
}
|
|
149
102
|
}
|
|
150
|
-
function
|
|
151
|
-
var e =
|
|
103
|
+
function s() {
|
|
104
|
+
var e = M.A;
|
|
152
105
|
return e === null ? null : e.getOwner();
|
|
153
106
|
}
|
|
154
|
-
function
|
|
107
|
+
function a() {
|
|
155
108
|
return Error("react-stack-top-frame");
|
|
156
109
|
}
|
|
157
|
-
function
|
|
158
|
-
if (
|
|
159
|
-
var
|
|
160
|
-
if (
|
|
110
|
+
function i(e) {
|
|
111
|
+
if (B.call(e, "key")) {
|
|
112
|
+
var o = Object.getOwnPropertyDescriptor(e, "key").get;
|
|
113
|
+
if (o && o.isReactWarning) return !1;
|
|
161
114
|
}
|
|
162
115
|
return e.key !== void 0;
|
|
163
116
|
}
|
|
164
|
-
function
|
|
165
|
-
function
|
|
166
|
-
|
|
117
|
+
function c(e, o) {
|
|
118
|
+
function f() {
|
|
119
|
+
X || (X = !0, console.error(
|
|
167
120
|
"%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)",
|
|
168
|
-
|
|
121
|
+
o
|
|
169
122
|
));
|
|
170
123
|
}
|
|
171
|
-
|
|
172
|
-
get:
|
|
124
|
+
f.isReactWarning = !0, Object.defineProperty(e, "key", {
|
|
125
|
+
get: f,
|
|
173
126
|
configurable: !0
|
|
174
127
|
});
|
|
175
128
|
}
|
|
176
|
-
function
|
|
129
|
+
function y() {
|
|
177
130
|
var e = t(this.type);
|
|
178
|
-
return
|
|
131
|
+
return H[e] || (H[e] = !0, console.error(
|
|
179
132
|
"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."
|
|
180
133
|
)), e = this.props.ref, e !== void 0 ? e : null;
|
|
181
134
|
}
|
|
182
|
-
function R(e,
|
|
183
|
-
var
|
|
135
|
+
function R(e, o, f, m, $, L) {
|
|
136
|
+
var b = f.ref;
|
|
184
137
|
return e = {
|
|
185
|
-
$$typeof:
|
|
138
|
+
$$typeof: E,
|
|
186
139
|
type: e,
|
|
187
|
-
key:
|
|
188
|
-
props:
|
|
189
|
-
_owner:
|
|
190
|
-
}, (
|
|
140
|
+
key: o,
|
|
141
|
+
props: f,
|
|
142
|
+
_owner: m
|
|
143
|
+
}, (b !== void 0 ? b : null) !== null ? Object.defineProperty(e, "ref", {
|
|
191
144
|
enumerable: !1,
|
|
192
|
-
get:
|
|
145
|
+
get: y
|
|
193
146
|
}) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
|
|
194
147
|
configurable: !1,
|
|
195
148
|
enumerable: !1,
|
|
@@ -212,174 +165,257 @@ function ke() {
|
|
|
212
165
|
value: L
|
|
213
166
|
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
|
|
214
167
|
}
|
|
215
|
-
function w(e,
|
|
216
|
-
var
|
|
217
|
-
if (
|
|
218
|
-
if (
|
|
219
|
-
if (
|
|
220
|
-
for (
|
|
221
|
-
|
|
222
|
-
Object.freeze && Object.freeze(
|
|
168
|
+
function w(e, o, f, m, $, L) {
|
|
169
|
+
var b = o.children;
|
|
170
|
+
if (b !== void 0)
|
|
171
|
+
if (m)
|
|
172
|
+
if (ve(b)) {
|
|
173
|
+
for (m = 0; m < b.length; m++)
|
|
174
|
+
d(b[m]);
|
|
175
|
+
Object.freeze && Object.freeze(b);
|
|
223
176
|
} else
|
|
224
177
|
console.error(
|
|
225
178
|
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
|
|
226
179
|
);
|
|
227
|
-
else
|
|
228
|
-
if (
|
|
229
|
-
|
|
230
|
-
var
|
|
231
|
-
return
|
|
180
|
+
else d(b);
|
|
181
|
+
if (B.call(o, "key")) {
|
|
182
|
+
b = t(e);
|
|
183
|
+
var O = Object.keys(o).filter(function(Ee) {
|
|
184
|
+
return Ee !== "key";
|
|
232
185
|
});
|
|
233
|
-
|
|
186
|
+
m = 0 < O.length ? "{key: someKey, " + O.join(": ..., ") + ": ...}" : "{key: someKey}", K[b + m] || (O = 0 < O.length ? "{" + O.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
234
187
|
`A props object containing a "key" prop is being spread into JSX:
|
|
235
188
|
let props = %s;
|
|
236
189
|
<%s {...props} />
|
|
237
190
|
React keys must be passed directly to JSX without using spread:
|
|
238
191
|
let props = %s;
|
|
239
192
|
<%s key={someKey} {...props} />`,
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
),
|
|
193
|
+
m,
|
|
194
|
+
b,
|
|
195
|
+
O,
|
|
196
|
+
b
|
|
197
|
+
), K[b + m] = !0);
|
|
245
198
|
}
|
|
246
|
-
if (
|
|
247
|
-
|
|
248
|
-
for (var
|
|
249
|
-
|
|
250
|
-
} else
|
|
251
|
-
return
|
|
252
|
-
|
|
199
|
+
if (b = null, f !== void 0 && (r(f), b = "" + f), i(o) && (r(o.key), b = "" + o.key), "key" in o) {
|
|
200
|
+
f = {};
|
|
201
|
+
for (var W in o)
|
|
202
|
+
W !== "key" && (f[W] = o[W]);
|
|
203
|
+
} else f = o;
|
|
204
|
+
return b && c(
|
|
205
|
+
f,
|
|
253
206
|
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
|
|
254
207
|
), R(
|
|
255
208
|
e,
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
209
|
+
b,
|
|
210
|
+
f,
|
|
211
|
+
s(),
|
|
259
212
|
$,
|
|
260
213
|
L
|
|
261
214
|
);
|
|
262
215
|
}
|
|
263
|
-
function
|
|
264
|
-
|
|
216
|
+
function d(e) {
|
|
217
|
+
v(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === P && (e._payload.status === "fulfilled" ? v(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
|
|
265
218
|
}
|
|
266
|
-
function
|
|
267
|
-
return typeof e == "object" && e !== null && e.$$typeof ===
|
|
219
|
+
function v(e) {
|
|
220
|
+
return typeof e == "object" && e !== null && e.$$typeof === E;
|
|
268
221
|
}
|
|
269
|
-
var
|
|
222
|
+
var S = pe, E = Symbol.for("react.transitional.element"), p = Symbol.for("react.portal"), h = Symbol.for("react.fragment"), A = Symbol.for("react.strict_mode"), x = Symbol.for("react.profiler"), g = Symbol.for("react.consumer"), T = Symbol.for("react.context"), j = Symbol.for("react.forward_ref"), F = Symbol.for("react.suspense"), u = Symbol.for("react.suspense_list"), _ = Symbol.for("react.memo"), P = Symbol.for("react.lazy"), k = Symbol.for("react.activity"), be = Symbol.for("react.client.reference"), M = S.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, B = Object.prototype.hasOwnProperty, ve = Array.isArray, z = console.createTask ? console.createTask : function() {
|
|
270
223
|
return null;
|
|
271
224
|
};
|
|
272
|
-
|
|
225
|
+
S = {
|
|
273
226
|
react_stack_bottom_frame: function(e) {
|
|
274
227
|
return e();
|
|
275
228
|
}
|
|
276
229
|
};
|
|
277
|
-
var
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
)(),
|
|
281
|
-
|
|
282
|
-
var
|
|
230
|
+
var X, H = {}, Z = S.react_stack_bottom_frame.bind(
|
|
231
|
+
S,
|
|
232
|
+
a
|
|
233
|
+
)(), Q = z(l(a)), K = {};
|
|
234
|
+
N.Fragment = h, N.jsx = function(e, o, f) {
|
|
235
|
+
var m = 1e4 > M.recentlyCreatedOwnerStacks++;
|
|
283
236
|
return w(
|
|
284
237
|
e,
|
|
285
|
-
|
|
286
|
-
|
|
238
|
+
o,
|
|
239
|
+
f,
|
|
287
240
|
!1,
|
|
288
|
-
|
|
289
|
-
|
|
241
|
+
m ? Error("react-stack-top-frame") : Z,
|
|
242
|
+
m ? z(l(e)) : Q
|
|
290
243
|
);
|
|
291
|
-
},
|
|
292
|
-
var
|
|
244
|
+
}, N.jsxs = function(e, o, f) {
|
|
245
|
+
var m = 1e4 > M.recentlyCreatedOwnerStacks++;
|
|
293
246
|
return w(
|
|
294
247
|
e,
|
|
295
|
-
|
|
296
|
-
|
|
248
|
+
o,
|
|
249
|
+
f,
|
|
297
250
|
!0,
|
|
298
|
-
|
|
299
|
-
|
|
251
|
+
m ? Error("react-stack-top-frame") : Z,
|
|
252
|
+
m ? z(l(e)) : Q
|
|
300
253
|
);
|
|
301
254
|
};
|
|
302
|
-
})()),
|
|
255
|
+
})()), N;
|
|
256
|
+
}
|
|
257
|
+
var oe;
|
|
258
|
+
function ke() {
|
|
259
|
+
return oe || (oe = 1, process.env.NODE_ENV === "production" ? I.exports = Te() : I.exports = ge()), I.exports;
|
|
260
|
+
}
|
|
261
|
+
var we = ke();
|
|
262
|
+
function D(t, n, r) {
|
|
263
|
+
if (!n)
|
|
264
|
+
return t;
|
|
265
|
+
const l = n.split(".");
|
|
266
|
+
let s = t;
|
|
267
|
+
for (const a of l)
|
|
268
|
+
if (s !== null && typeof s == "object" && a in s)
|
|
269
|
+
s = s[a];
|
|
270
|
+
else
|
|
271
|
+
return r;
|
|
272
|
+
return s === void 0 ? r : s;
|
|
273
|
+
}
|
|
274
|
+
function xe(t, n, r) {
|
|
275
|
+
const l = n.replace(/\[(\d+)\]/g, ".$1").split(".");
|
|
276
|
+
let s = t;
|
|
277
|
+
for (let a = 0; a < l.length - 1; a++) {
|
|
278
|
+
const i = l[a], c = l[a + 1];
|
|
279
|
+
(s[i] === void 0 || s[i] === null) && (s[i] = /^\d+$/.test(c) ? [] : {}), s = s[i];
|
|
280
|
+
}
|
|
281
|
+
return s[l[l.length - 1]] = r, t;
|
|
282
|
+
}
|
|
283
|
+
function Pe(t, n = 0) {
|
|
284
|
+
let r;
|
|
285
|
+
return function(...l) {
|
|
286
|
+
r !== void 0 && clearTimeout(r), r = setTimeout(() => {
|
|
287
|
+
r = void 0, t.apply(this, l);
|
|
288
|
+
}, n);
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
function Ae(t, n, r = []) {
|
|
292
|
+
return ae(
|
|
293
|
+
() => Pe(t, n),
|
|
294
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
295
|
+
r
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
function se(t) {
|
|
299
|
+
const n = JSON.stringify(t, null, 2).split(`
|
|
300
|
+
`), r = [], l = [];
|
|
301
|
+
for (const s of n) {
|
|
302
|
+
const a = s.match(/^(\s*)"([^"]+)"(\s*:\s*)(.+)$/);
|
|
303
|
+
if (a) {
|
|
304
|
+
const [, i, c, y, R] = a;
|
|
305
|
+
r.push(`${i}%c"${c}"%c${y}%c${R}`), l.push(
|
|
306
|
+
"color: #9cdcfe; font-weight: bold",
|
|
307
|
+
"color: #cccccc",
|
|
308
|
+
"color: #ce9178"
|
|
309
|
+
);
|
|
310
|
+
} else
|
|
311
|
+
r.push(`%c${s}`), l.push("color: #cccccc");
|
|
312
|
+
}
|
|
313
|
+
console.log(r.join(`
|
|
314
|
+
`), ...l, t);
|
|
315
|
+
}
|
|
316
|
+
const ue = (t) => typeof t == "function", Oe = (t) => typeof t == "function", V = (t) => typeof t < "u", J = (t) => Oe(t) ? t() : t;
|
|
317
|
+
class je {
|
|
318
|
+
#e;
|
|
319
|
+
#t;
|
|
320
|
+
constructor() {
|
|
321
|
+
this.uid = Math.random().toString(36).slice(2), this.#e = {}, this.#t = /* @__PURE__ */ new Set();
|
|
322
|
+
}
|
|
323
|
+
subscribe(n) {
|
|
324
|
+
return this.#t.add(n), () => this.#t.delete(n);
|
|
325
|
+
}
|
|
326
|
+
getClientSnapshot() {
|
|
327
|
+
return this.#e;
|
|
328
|
+
}
|
|
329
|
+
getServerSnapshot() {
|
|
330
|
+
return this.#e;
|
|
331
|
+
}
|
|
332
|
+
get(n) {
|
|
333
|
+
return D(this.#e, n);
|
|
334
|
+
}
|
|
335
|
+
set(n, r) {
|
|
336
|
+
const l = D(this.#e, n), s = ue(r) ? r(l) : r, a = { ...this.#e };
|
|
337
|
+
xe(a, n, s), this.#e = a, this.#t.forEach((i) => i());
|
|
338
|
+
}
|
|
303
339
|
}
|
|
304
|
-
|
|
305
|
-
function
|
|
306
|
-
|
|
340
|
+
const le = Se({});
|
|
341
|
+
function ie(t = {}) {
|
|
342
|
+
const n = he(le);
|
|
343
|
+
return t.verbose && console.log(`[${ie.name}]: `, n.uid), n;
|
|
307
344
|
}
|
|
308
|
-
|
|
309
|
-
const
|
|
310
|
-
|
|
311
|
-
return ve(Ae);
|
|
345
|
+
function Ve({ children: t }) {
|
|
346
|
+
const n = ae(() => new je(), []);
|
|
347
|
+
return /* @__PURE__ */ we.jsx(le.Provider, { value: n, children: t });
|
|
312
348
|
}
|
|
313
|
-
const
|
|
314
|
-
function
|
|
349
|
+
const fe = Symbol("state-def"), Y = Symbol("state-path"), U = Symbol("state-verbose"), q = Symbol("state-verbose-path"), G = Symbol("state-ssr"), de = typeof window > "u", Ce = de ? ce : ye;
|
|
350
|
+
function $e(t = {}) {
|
|
315
351
|
return {
|
|
316
|
-
[
|
|
352
|
+
[fe]: !0,
|
|
317
353
|
// marks this object as a leaf in the router tree
|
|
318
354
|
[Y]: "",
|
|
319
355
|
// placeholder; injected at runtime by injectPaths()
|
|
320
|
-
[
|
|
356
|
+
[U]: !1,
|
|
321
357
|
// placeholder
|
|
322
|
-
[
|
|
358
|
+
[q]: "",
|
|
323
359
|
// placeholder
|
|
324
|
-
[
|
|
360
|
+
[G]: !1,
|
|
325
361
|
// placeholder
|
|
326
|
-
useState(
|
|
327
|
-
const
|
|
328
|
-
|
|
329
|
-
const
|
|
330
|
-
const k =
|
|
331
|
-
k === null ?
|
|
332
|
-
},
|
|
333
|
-
|
|
362
|
+
useState(n) {
|
|
363
|
+
const r = de ? void 0 : J(t.storage), l = J(t.defaultValue), s = t.bidirectional;
|
|
364
|
+
n ??= {};
|
|
365
|
+
const a = J(n.defaultValue) ?? l, i = n.bidirectional ?? s, c = this[Y], y = this[U], R = this[q], w = this[G], d = ie({ verbose: y }), v = t.serialize ?? JSON.stringify, S = t.deserialize ?? JSON.parse, E = (u, _, P) => {
|
|
366
|
+
const k = _.getItem(u);
|
|
367
|
+
k === null ? V(P) && _.setItem(u, v(P)) : d.set(u, S(k));
|
|
368
|
+
}, p = Ae(
|
|
369
|
+
n.onSet ?? (() => {
|
|
334
370
|
}),
|
|
335
|
-
|
|
371
|
+
n.delayedSet,
|
|
336
372
|
[]
|
|
337
|
-
),
|
|
338
|
-
if (!
|
|
339
|
-
|
|
340
|
-
let
|
|
341
|
-
|
|
373
|
+
), h = ee(void 0), A = ee(!1);
|
|
374
|
+
if (!A.current) {
|
|
375
|
+
A.current = !0;
|
|
376
|
+
let u = d.get(c);
|
|
377
|
+
V(u) || (u = a, V(u) && d.set(c, u)), !w && r && E(c, r, u);
|
|
342
378
|
}
|
|
343
|
-
const
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
379
|
+
const x = _e(
|
|
380
|
+
d.subscribe.bind(d),
|
|
381
|
+
d.getClientSnapshot.bind(d),
|
|
382
|
+
d.getServerSnapshot.bind(d)
|
|
347
383
|
);
|
|
348
|
-
if (
|
|
384
|
+
if (y)
|
|
349
385
|
if (R) {
|
|
350
|
-
const
|
|
351
|
-
|
|
386
|
+
const u = D(x, R);
|
|
387
|
+
u && se(u);
|
|
352
388
|
} else
|
|
353
|
-
|
|
354
|
-
const g =
|
|
355
|
-
|
|
356
|
-
!w || !
|
|
389
|
+
se(x);
|
|
390
|
+
const g = D(x, c, a);
|
|
391
|
+
h.current = g, Ce(() => {
|
|
392
|
+
!w || !r || E(c, r, g);
|
|
357
393
|
}, []);
|
|
358
|
-
const
|
|
359
|
-
if (
|
|
394
|
+
const T = Re((u) => {
|
|
395
|
+
if (u.key !== c)
|
|
360
396
|
return;
|
|
361
|
-
const
|
|
362
|
-
|
|
397
|
+
const _ = u.newValue, k = (_ === null ? null : S(_)) ?? a;
|
|
398
|
+
V(k) && (d.set(c, k), p(k, h.current));
|
|
363
399
|
});
|
|
364
|
-
|
|
365
|
-
if (
|
|
366
|
-
return window.addEventListener("storage",
|
|
367
|
-
}, [
|
|
368
|
-
const j =
|
|
369
|
-
const
|
|
370
|
-
|
|
371
|
-
}, [
|
|
372
|
-
const
|
|
373
|
-
if (!
|
|
374
|
-
|
|
400
|
+
ce(() => {
|
|
401
|
+
if (i)
|
|
402
|
+
return window.addEventListener("storage", T), () => window.removeEventListener("storage", T);
|
|
403
|
+
}, [i]);
|
|
404
|
+
const j = te((u) => {
|
|
405
|
+
const _ = ue(u) ? u(h.current) : u;
|
|
406
|
+
d.set(c, _), p(_, h.current), r && r.setItem(c, v(_));
|
|
407
|
+
}, [c, r, p]), F = te(() => {
|
|
408
|
+
const u = a;
|
|
409
|
+
if (!V(u)) {
|
|
410
|
+
r?.removeItem(c);
|
|
375
411
|
return;
|
|
376
412
|
}
|
|
377
|
-
|
|
378
|
-
}, [
|
|
413
|
+
d.set(c, u), p(u, h.current), r && r.setItem(c, v(u));
|
|
414
|
+
}, [c, a, r, p]);
|
|
379
415
|
return [
|
|
380
416
|
g,
|
|
381
417
|
j,
|
|
382
|
-
|
|
418
|
+
F
|
|
383
419
|
];
|
|
384
420
|
},
|
|
385
421
|
/** Returns the fully qualified job name (dot-separated path). */
|
|
@@ -388,60 +424,60 @@ function je(t = {}) {
|
|
|
388
424
|
}
|
|
389
425
|
};
|
|
390
426
|
}
|
|
391
|
-
function
|
|
427
|
+
function me(t, n) {
|
|
392
428
|
const {
|
|
393
|
-
path:
|
|
394
|
-
verbose:
|
|
395
|
-
verbosePath:
|
|
396
|
-
ssr:
|
|
397
|
-
cache:
|
|
398
|
-
} =
|
|
399
|
-
let
|
|
400
|
-
|
|
401
|
-
const
|
|
402
|
-
if (
|
|
403
|
-
return
|
|
429
|
+
path: r = "",
|
|
430
|
+
verbose: l,
|
|
431
|
+
verbosePath: s,
|
|
432
|
+
ssr: a,
|
|
433
|
+
cache: i
|
|
434
|
+
} = n;
|
|
435
|
+
let c = i.proxy.get(t);
|
|
436
|
+
c || (c = /* @__PURE__ */ new Map(), i.proxy.set(t, c));
|
|
437
|
+
const y = c.get(r);
|
|
438
|
+
if (y)
|
|
439
|
+
return y;
|
|
404
440
|
const R = new Proxy(t, {
|
|
405
|
-
get(w,
|
|
406
|
-
const
|
|
407
|
-
if (
|
|
408
|
-
const
|
|
409
|
-
let
|
|
410
|
-
|
|
411
|
-
const
|
|
412
|
-
if (
|
|
413
|
-
return
|
|
414
|
-
const
|
|
415
|
-
(
|
|
416
|
-
),
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
(...j) =>
|
|
441
|
+
get(w, d) {
|
|
442
|
+
const v = w[d], S = r ? `${r}.${String(d)}` : String(d);
|
|
443
|
+
if (v && typeof v == "object" && fe in v) {
|
|
444
|
+
const E = v;
|
|
445
|
+
let p = i.leaf.get(E);
|
|
446
|
+
p || (p = /* @__PURE__ */ new Map(), i.leaf.set(E, p));
|
|
447
|
+
const h = p.get(S);
|
|
448
|
+
if (h)
|
|
449
|
+
return h;
|
|
450
|
+
const A = Reflect.ownKeys(E).filter(
|
|
451
|
+
(T) => typeof E[T] == "function"
|
|
452
|
+
), x = Object.fromEntries(
|
|
453
|
+
A.map((T) => [
|
|
454
|
+
T,
|
|
455
|
+
(...j) => E[T].call(
|
|
420
456
|
{
|
|
421
|
-
...
|
|
422
|
-
[Y]:
|
|
423
|
-
[
|
|
424
|
-
[
|
|
425
|
-
[
|
|
457
|
+
...E,
|
|
458
|
+
[Y]: S,
|
|
459
|
+
[U]: l,
|
|
460
|
+
[q]: s,
|
|
461
|
+
[G]: a
|
|
426
462
|
},
|
|
427
463
|
...j
|
|
428
464
|
)
|
|
429
465
|
])
|
|
430
|
-
), g = { ...
|
|
431
|
-
return
|
|
466
|
+
), g = { ...E, ...x };
|
|
467
|
+
return p.set(S, g), g;
|
|
432
468
|
}
|
|
433
|
-
return
|
|
434
|
-
...
|
|
435
|
-
path:
|
|
436
|
-
}) :
|
|
469
|
+
return v && typeof v == "object" ? me(v, {
|
|
470
|
+
...n,
|
|
471
|
+
path: S
|
|
472
|
+
}) : v;
|
|
437
473
|
}
|
|
438
474
|
});
|
|
439
|
-
return
|
|
475
|
+
return c.set(r, R), R;
|
|
440
476
|
}
|
|
441
|
-
function
|
|
442
|
-
return
|
|
443
|
-
...
|
|
444
|
-
verbosePath:
|
|
477
|
+
function Ie(t, n) {
|
|
478
|
+
return me(t, {
|
|
479
|
+
...n,
|
|
480
|
+
verbosePath: n?.verbosePath ?? "",
|
|
445
481
|
cache: {
|
|
446
482
|
proxy: /* @__PURE__ */ new WeakMap(),
|
|
447
483
|
leaf: /* @__PURE__ */ new WeakMap()
|
|
@@ -449,6 +485,7 @@ function Ne(t, c) {
|
|
|
449
485
|
});
|
|
450
486
|
}
|
|
451
487
|
export {
|
|
452
|
-
|
|
453
|
-
|
|
488
|
+
Ve as VocabStateProvider,
|
|
489
|
+
$e as defineState,
|
|
490
|
+
Ie as setupStorage
|
|
454
491
|
};
|
package/dist/types/context.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { type PropsWithChildren } from "react";
|
|
2
2
|
import VocabStore from "./store";
|
|
3
|
-
export declare function
|
|
4
|
-
|
|
3
|
+
export declare function useVocabStoreContext(options?: {
|
|
4
|
+
verbose?: boolean;
|
|
5
|
+
}): VocabStore;
|
|
6
|
+
export declare function VocabStoreContextProvider({ children }: PropsWithChildren): import("react/jsx-runtime").JSX.Element;
|
package/dist/types/index.d.ts
CHANGED