@yakocloud/state-vocab 3.0.3 → 3.0.4

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,3 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react"),M=Symbol("state-def"),k=Symbol("state-path"),R=Symbol("state-verbose"),x=Symbol("state-verbose-path"),A=Symbol("state-ssr");function I(t,e,s){if(!e)return t;const i=e.split(".");let c=t;for(const r of i)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 i=e.replace(/\[(\d+)\]/g,".$1").split(".");let c=t;for(let r=0;r<i.length-1;r++){const n=i[r],l=i[r+1];(c[n]===void 0||c[n]===null)&&(c[n]=/^\d+$/.test(l)?[]:{}),c=c[n]}return c[i[i.length-1]]=s,t}function D(t,e=0){let s;return function(...i){s!==void 0&&clearTimeout(s),s=setTimeout(()=>{s=void 0,t.apply(this,i)},e)}}function B(t,e,s=[]){return d.useMemo(()=>D(t,e),s)}function C(t){const e=JSON.stringify(t,null,2).split(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react"),_=Symbol("state-def"),k=Symbol("state-path"),R=Symbol("state-verbose"),x=Symbol("state-verbose-path"),A=Symbol("state-ssr");function I(t,e,s){if(!e)return t;const i=e.split(".");let c=t;for(const r of i)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 i=e.replace(/\[(\d+)\]/g,".$1").split(".");let c=t;for(let r=0;r<i.length-1;r++){const n=i[r],l=i[r+1];(c[n]===void 0||c[n]===null)&&(c[n]=/^\d+$/.test(l)?[]:{}),c=c[n]}return c[i[i.length-1]]=s,t}function D(t,e=0){let s;return function(...i){s!==void 0&&clearTimeout(s),s=setTimeout(()=>{s=void 0,t.apply(this,i)},e)}}function B(t,e,s=[]){return d.useMemo(()=>D(t,e),s)}function M(t){const e=JSON.stringify(t,null,2).split(`
2
2
  `),s=[],i=[];for(const c of e){const r=c.match(/^(\s*)"([^"]+)"(\s*:\s*)(.+)$/);if(r){const[,n,l,h,u]=r;s.push(`${n}%c"${l}"%c${h}%c${u}`),i.push("color: #9cdcfe; font-weight: bold","color: #cccccc","color: #ce9178")}else s.push(`%c${c}`),i.push("color: #cccccc")}console.log(s.join(`
3
- `),...i,t)}const _=t=>typeof t=="function",F=t=>typeof t=="function",T=t=>typeof t<"u",P=t=>F(t)?t():t,L=typeof window>"u",J=L?d.useEffect:d.useLayoutEffect;class H{#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 I(this.#e,e)}set(e,s){const i=I(this.#e,e),c=_(s)?s(i):s,r={...this.#e};j(r,e,c),this.#e=r,this.#t.forEach(n=>n())}}function K(t={}){const e=new H,s=t.serialize??JSON.stringify,i=t.deserialize??JSON.parse,c=(r,n,l)=>{const h=n.getItem(r);h===null?T(l)&&n.setItem(r,s(l)):e.set(r,i(h))};return{[M]:!0,[k]:"",[R]:!1,[x]:"",[A]:!1,useState(r){const n=L?void 0:P(t.storage),l=P(t.defaultValue),h=t.bidirectional;r??={};const u=P(r.defaultValue)??l,w=r.bidirectional??h,S=B(r.onSet??(()=>{}),r.delayedSet,[]),o=this[k],v=this[R],f=this[x],y=this[A],b=d.useRef(void 0),V=d.useRef(!1);if(!V.current){V.current=!0;let a=e.get(o);T(a)||(a=u,T(a)&&e.set(o,a)),!y&&n&&c(o,n,a)}const E=d.useSyncExternalStore(e.subscribe.bind(e),e.getClientSnapshot.bind(e),e.getServerSnapshot.bind(e));if(v)if(f){const a=I(E,f);a&&C(a)}else C(E);const p=I(E,o,u);b.current=p,J(()=>{!y||!n||c(o,n,p)},[]);const g=d.useEffectEvent(a=>{if(a.key!==o)return;const m=a.newValue,z=(m===null?null:i(m))??u;T(z)&&(e.set(o,z),S(z,b.current))});d.useEffect(()=>{if(w)return window.addEventListener("storage",g),()=>window.removeEventListener("storage",g)},[w]);const $=d.useCallback(a=>{const m=_(a)?a(b.current):a;e.set(o,m),S(m,b.current),n&&n.setItem(o,s(m))},[o,n,S]),O=d.useCallback(()=>{const a=u;if(!T(a)){n?.removeItem(o);return}e.set(o,a),S(a,b.current),n&&n.setItem(o,s(a))},[o,u,n,S]);return[p,$,O]},toString(){return this[k]}}}function N(t,e){const{path:s="",verbose:i,verbosePath:c,ssr:r,cache:n}=e;let l=n.proxy.get(t);l||(l=new Map,n.proxy.set(t,l));const h=l.get(s);if(h)return h;const u=new Proxy(t,{get(w,S){const o=w[S],v=s?`${s}.${String(S)}`:String(S);if(o&&typeof o=="object"&&M in o){const f=o;let y=n.leaf.get(f);y||(y=new Map,n.leaf.set(f,y));const b=y.get(v);if(b)return b;const V=Reflect.ownKeys(f).filter(g=>typeof f[g]=="function"),E=Object.fromEntries(V.map(g=>[g,(...$)=>f[g].call({...f,[k]:v,[R]:i,[x]:c,[A]:r},...$)])),p={...f,...E};return y.set(v,p),p}return o&&typeof o=="object"?N(o,{...e,path:v}):o}});return l.set(s,u),u}function W(t,e){return N(t,{...e,verbosePath:e?.verbosePath??"",cache:{proxy:new WeakMap,leaf:new WeakMap}})}exports.defineState=K;exports.setupStorage=W;
3
+ `),...i,t)}const L=t=>typeof t=="function",F=t=>typeof t=="function",T=t=>typeof t<"u",P=t=>F(t)?t():t,C=typeof window>"u",J=C?d.useEffect:d.useLayoutEffect;class H{#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 I(this.#e,e)}set(e,s){const i=I(this.#e,e),c=L(s)?s(i):s,r={...this.#e};j(r,e,c),this.#e=r,this.#t.forEach(n=>n())}}function K(t={}){const e=new H,s=t.serialize??JSON.stringify,i=t.deserialize??JSON.parse,c=(r,n,l)=>{const h=n.getItem(r);h===null?T(l)&&n.setItem(r,s(l)):e.set(r,i(h))};return{[_]:!0,[k]:"",[R]:!1,[x]:"",[A]:!1,useState(r){const n=C?void 0:P(t.storage),l=P(t.defaultValue),h=t.bidirectional;r??={};const u=P(r.defaultValue)??l,w=r.bidirectional??h,S=B(r.onSet??(()=>{}),r.delayedSet,[]),o=this[k],v=this[R],f=this[x],y=this[A],b=d.useRef(void 0),V=d.useRef(!1);if(!V.current){V.current=!0;let a=C?void 0:e.get(o);T(a)||(a=u,T(a)&&e.set(o,a)),!y&&n&&c(o,n,a)}const E=d.useSyncExternalStore(e.subscribe.bind(e),e.getClientSnapshot.bind(e),e.getServerSnapshot.bind(e));if(v)if(f){const a=I(E,f);a&&M(a)}else M(E);const p=I(E,o,u);b.current=p,J(()=>{!y||!n||c(o,n,p)},[]);const g=d.useEffectEvent(a=>{if(a.key!==o)return;const m=a.newValue,z=(m===null?null:i(m))??u;T(z)&&(e.set(o,z),S(z,b.current))});d.useEffect(()=>{if(w)return window.addEventListener("storage",g),()=>window.removeEventListener("storage",g)},[w]);const $=d.useCallback(a=>{const m=L(a)?a(b.current):a;e.set(o,m),S(m,b.current),n&&n.setItem(o,s(m))},[o,n,S]),O=d.useCallback(()=>{const a=u;if(!T(a)){n?.removeItem(o);return}e.set(o,a),S(a,b.current),n&&n.setItem(o,s(a))},[o,u,n,S]);return[p,$,O]},toString(){return this[k]}}}function N(t,e){const{path:s="",verbose:i,verbosePath:c,ssr:r,cache:n}=e;let l=n.proxy.get(t);l||(l=new Map,n.proxy.set(t,l));const h=l.get(s);if(h)return h;const u=new Proxy(t,{get(w,S){const o=w[S],v=s?`${s}.${String(S)}`:String(S);if(o&&typeof o=="object"&&_ in o){const f=o;let y=n.leaf.get(f);y||(y=new Map,n.leaf.set(f,y));const b=y.get(v);if(b)return b;const V=Reflect.ownKeys(f).filter(g=>typeof f[g]=="function"),E=Object.fromEntries(V.map(g=>[g,(...$)=>f[g].call({...f,[k]:v,[R]:i,[x]:c,[A]:r},...$)])),p={...f,...E};return y.set(v,p),p}return o&&typeof o=="object"?N(o,{...e,path:v}):o}});return l.set(s,u),u}function W(t,e){return N(t,{...e,verbosePath:e?.verbosePath??"",cache:{proxy:new WeakMap,leaf:new WeakMap}})}exports.defineState=K;exports.setupStorage=W;
@@ -1,5 +1,5 @@
1
- import { useMemo as B, useRef as R, useSyncExternalStore as F, useEffect as L, useLayoutEffect as J, useEffectEvent as H, useCallback as C } from "react";
2
- const M = Symbol("state-def"), V = Symbol("state-path"), x = Symbol("state-verbose"), P = Symbol("state-verbose-path"), A = Symbol("state-ssr");
1
+ import { useMemo as B, useRef as C, useSyncExternalStore as F, useEffect as M, useLayoutEffect as J, useEffectEvent as H, useCallback as _ } from "react";
2
+ const N = Symbol("state-def"), V = Symbol("state-path"), x = Symbol("state-verbose"), P = Symbol("state-verbose-path"), A = Symbol("state-ssr");
3
3
  function I(t, e, s) {
4
4
  if (!e)
5
5
  return t;
@@ -36,7 +36,7 @@ function q(t, e, s = []) {
36
36
  s
37
37
  );
38
38
  }
39
- function _(t) {
39
+ function L(t) {
40
40
  const e = JSON.stringify(t, null, 2).split(`
41
41
  `), s = [], i = [];
42
42
  for (const o of e) {
@@ -54,7 +54,7 @@ function _(t) {
54
54
  console.log(s.join(`
55
55
  `), ...i, t);
56
56
  }
57
- const N = (t) => typeof t == "function", G = (t) => typeof t == "function", E = (t) => typeof t < "u", z = (t) => G(t) ? t() : t, D = typeof window > "u", Q = D ? L : J;
57
+ const D = (t) => typeof t == "function", G = (t) => typeof t == "function", E = (t) => typeof t < "u", z = (t) => G(t) ? t() : t, R = typeof window > "u", Q = R ? M : J;
58
58
  class U {
59
59
  #e;
60
60
  #t;
@@ -74,7 +74,7 @@ class U {
74
74
  return I(this.#e, e);
75
75
  }
76
76
  set(e, s) {
77
- const i = I(this.#e, e), o = N(s) ? s(i) : s, r = { ...this.#e };
77
+ const i = I(this.#e, e), o = D(s) ? s(i) : s, r = { ...this.#e };
78
78
  K(r, e, o), this.#e = r, this.#t.forEach((n) => n());
79
79
  }
80
80
  }
@@ -84,7 +84,7 @@ function Z(t = {}) {
84
84
  d === null ? E(a) && n.setItem(r, s(a)) : e.set(r, i(d));
85
85
  };
86
86
  return {
87
- [M]: !0,
87
+ [N]: !0,
88
88
  // marks this object as a leaf in the router tree
89
89
  [V]: "",
90
90
  // placeholder; injected at runtime by injectPaths()
@@ -95,17 +95,17 @@ function Z(t = {}) {
95
95
  [A]: !1,
96
96
  // placeholder
97
97
  useState(r) {
98
- const n = D ? void 0 : z(t.storage), a = z(t.defaultValue), d = t.bidirectional;
98
+ const n = R ? void 0 : z(t.storage), a = z(t.defaultValue), d = t.bidirectional;
99
99
  r ??= {};
100
100
  const u = z(r.defaultValue) ?? a, w = r.bidirectional ?? d, h = q(
101
101
  r.onSet ?? (() => {
102
102
  }),
103
103
  r.delayedSet,
104
104
  []
105
- ), c = this[V], g = this[x], f = this[P], S = this[A], y = R(void 0), T = R(!1);
105
+ ), c = this[V], g = this[x], f = this[P], S = this[A], y = C(void 0), T = C(!1);
106
106
  if (!T.current) {
107
107
  T.current = !0;
108
- let l = e.get(c);
108
+ let l = R ? void 0 : e.get(c);
109
109
  E(l) || (l = u, E(l) && e.set(c, l)), !S && n && o(c, n, l);
110
110
  }
111
111
  const m = F(
@@ -116,9 +116,9 @@ function Z(t = {}) {
116
116
  if (g)
117
117
  if (f) {
118
118
  const l = I(m, f);
119
- l && _(l);
119
+ l && L(l);
120
120
  } else
121
- _(m);
121
+ L(m);
122
122
  const v = I(m, c, u);
123
123
  y.current = v, Q(() => {
124
124
  !S || !n || o(c, n, v);
@@ -129,14 +129,14 @@ function Z(t = {}) {
129
129
  const p = l.newValue, k = (p === null ? null : i(p)) ?? u;
130
130
  E(k) && (e.set(c, k), h(k, y.current));
131
131
  });
132
- L(() => {
132
+ M(() => {
133
133
  if (w)
134
134
  return window.addEventListener("storage", b), () => window.removeEventListener("storage", b);
135
135
  }, [w]);
136
- const $ = C((l) => {
137
- const p = N(l) ? l(y.current) : l;
136
+ const $ = _((l) => {
137
+ const p = D(l) ? l(y.current) : l;
138
138
  e.set(c, p), h(p, y.current), n && n.setItem(c, s(p));
139
- }, [c, n, h]), j = C(() => {
139
+ }, [c, n, h]), j = _(() => {
140
140
  const l = u;
141
141
  if (!E(l)) {
142
142
  n?.removeItem(c);
@@ -172,7 +172,7 @@ function O(t, e) {
172
172
  const u = new Proxy(t, {
173
173
  get(w, h) {
174
174
  const c = w[h], g = s ? `${s}.${String(h)}` : String(h);
175
- if (c && typeof c == "object" && M in c) {
175
+ if (c && typeof c == "object" && N in c) {
176
176
  const f = c;
177
177
  let S = n.leaf.get(f);
178
178
  S || (S = /* @__PURE__ */ new Map(), n.leaf.set(f, S));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yakocloud/state-vocab",
3
- "version": "3.0.3",
3
+ "version": "3.0.4",
4
4
  "main": "dist/state-vocab.cjs.js",
5
5
  "module": "dist/state-vocab.es.js",
6
6
  "types": "dist/types/index.d.ts",