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