cogsbox-state 0.5.304 → 0.5.306

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,15 +1,15 @@
1
1
  "use client";
2
2
  import { jsx as yt } from "react/jsx-runtime";
3
- import { useState as et, useRef as B, useEffect as lt, useLayoutEffect as dt, useMemo as It, createElement as ot, useSyncExternalStore as _t, startTransition as Mt, useCallback as At } from "react";
4
- import { transformStateFunc as jt, isDeepEqual as H, isFunction as Y, getNestedValue as z, getDifferences as pt, debounce as Ot } from "./utility.js";
5
- import { pushFunc as vt, updateFn as rt, cutFunc as ct, ValidationWrapper as Rt, FormControlComponent as Ft } from "./Functions.jsx";
6
- import Ut from "superjson";
3
+ import { useState as tt, useRef as B, useEffect as at, useLayoutEffect as dt, useMemo as It, createElement as st, useSyncExternalStore as Mt, startTransition as jt, useCallback as Et } from "react";
4
+ import { transformStateFunc as Ot, isDeepEqual as H, isFunction as Y, getNestedValue as z, getDifferences as pt, debounce as Ft } from "./utility.js";
5
+ import { pushFunc as vt, updateFn as ot, cutFunc as lt, ValidationWrapper as Rt, FormControlComponent as Ut } from "./Functions.jsx";
6
+ import Dt from "superjson";
7
7
  import { v4 as wt } from "uuid";
8
8
  import "zod";
9
9
  import { getGlobalStore as o, formRefStore as Tt } from "./store.js";
10
10
  import { useCogsConfig as Ct } from "./CogsStateClient.jsx";
11
- import { applyPatch as Dt } from "fast-json-patch";
12
- import Wt from "react-use-measure";
11
+ import { applyPatch as Wt } from "fast-json-patch";
12
+ import Gt from "react-use-measure";
13
13
  function $t(t, c) {
14
14
  const m = o.getState().getInitialOptions, f = o.getState().setInitialStateOptions, y = m(t) || {};
15
15
  f(t, {
@@ -17,45 +17,45 @@ function $t(t, c) {
17
17
  ...c
18
18
  });
19
19
  }
20
- function kt({
20
+ function bt({
21
21
  stateKey: t,
22
22
  options: c,
23
23
  initialOptionsPart: m
24
24
  }) {
25
- const f = tt(t) || {}, y = m[t] || {}, $ = o.getState().setInitialStateOptions, w = { ...y, ...f };
26
- let p = !1;
25
+ const f = nt(t) || {}, y = m[t] || {}, b = o.getState().setInitialStateOptions, p = { ...y, ...f };
26
+ let I = !1;
27
27
  if (c)
28
28
  for (const a in c)
29
- w.hasOwnProperty(a) ? (a == "localStorage" && c[a] && w[a].key !== c[a]?.key && (p = !0, w[a] = c[a]), a == "initialState" && c[a] && w[a] !== c[a] && // Different references
30
- !H(w[a], c[a]) && (p = !0, w[a] = c[a])) : (p = !0, w[a] = c[a]);
31
- p && $(t, w);
29
+ p.hasOwnProperty(a) ? (a == "localStorage" && c[a] && p[a].key !== c[a]?.key && (I = !0, p[a] = c[a]), a == "initialState" && c[a] && p[a] !== c[a] && // Different references
30
+ !H(p[a], c[a]) && (I = !0, p[a] = c[a])) : (I = !0, p[a] = c[a]);
31
+ I && b(t, p);
32
32
  }
33
- function le(t, { formElements: c, validation: m }) {
33
+ function de(t, { formElements: c, validation: m }) {
34
34
  return { initialState: t, formElements: c, validation: m };
35
35
  }
36
- const de = (t, c) => {
36
+ const ue = (t, c) => {
37
37
  let m = t;
38
- const [f, y] = jt(m);
39
- (Object.keys(y).length > 0 || c && Object.keys(c).length > 0) && Object.keys(y).forEach((p) => {
40
- y[p] = y[p] || {}, y[p].formElements = {
38
+ const [f, y] = Ot(m);
39
+ (Object.keys(y).length > 0 || c && Object.keys(c).length > 0) && Object.keys(y).forEach((I) => {
40
+ y[I] = y[I] || {}, y[I].formElements = {
41
41
  ...c?.formElements,
42
42
  // Global defaults first
43
43
  ...c?.validation,
44
- ...y[p].formElements || {}
44
+ ...y[I].formElements || {}
45
45
  // State-specific overrides
46
- }, tt(p) || o.getState().setInitialStateOptions(p, y[p]);
46
+ }, nt(I) || o.getState().setInitialStateOptions(I, y[I]);
47
47
  }), o.getState().setInitialStates(f), o.getState().setCreatedState(f);
48
- const $ = (p, a) => {
49
- const [v] = et(a?.componentId ?? wt());
50
- kt({
51
- stateKey: p,
48
+ const b = (I, a) => {
49
+ const [v] = tt(a?.componentId ?? wt());
50
+ bt({
51
+ stateKey: I,
52
52
  options: a,
53
53
  initialOptionsPart: y
54
54
  });
55
- const n = o.getState().cogsStateStore[p] || f[p], S = a?.modifyState ? a.modifyState(n) : n, [G, R] = Jt(
55
+ const n = o.getState().cogsStateStore[I] || f[I], S = a?.modifyState ? a.modifyState(n) : n, [W, R] = Yt(
56
56
  S,
57
57
  {
58
- stateKey: p,
58
+ stateKey: I,
59
59
  syncUpdate: a?.syncUpdate,
60
60
  componentId: v,
61
61
  localStorage: a?.localStorage,
@@ -70,43 +70,43 @@ const de = (t, c) => {
70
70
  );
71
71
  return R;
72
72
  };
73
- function w(p, a) {
74
- kt({ stateKey: p, options: a, initialOptionsPart: y }), a.localStorage && Bt(p, a), St(p);
73
+ function p(I, a) {
74
+ bt({ stateKey: I, options: a, initialOptionsPart: y }), a.localStorage && Bt(I, a), St(I);
75
75
  }
76
- return { useCogsState: $, setCogsOptions: w };
76
+ return { useCogsState: b, setCogsOptions: p };
77
77
  }, {
78
78
  setUpdaterState: ut,
79
- setState: K,
80
- getInitialOptions: tt,
79
+ setState: et,
80
+ getInitialOptions: nt,
81
81
  getKeyState: Vt,
82
- getValidationErrors: Gt,
83
- setStateLog: Lt,
84
- updateInitialStateGlobal: Et,
85
- addValidationError: Ht,
82
+ getValidationErrors: Lt,
83
+ setStateLog: Ht,
84
+ updateInitialStateGlobal: At,
85
+ addValidationError: zt,
86
86
  removeValidationError: J,
87
- setServerSyncActions: zt
88
- } = o.getState(), Nt = (t, c, m, f, y) => {
87
+ setServerSyncActions: qt
88
+ } = o.getState(), kt = (t, c, m, f, y) => {
89
89
  m?.log && console.log(
90
90
  "saving to localstorage",
91
91
  c,
92
92
  m.localStorage?.key,
93
93
  f
94
94
  );
95
- const $ = Y(m?.localStorage?.key) ? m.localStorage?.key(t) : m?.localStorage?.key;
96
- if ($ && f) {
97
- const w = `${f}-${c}-${$}`;
98
- let p;
95
+ const b = Y(m?.localStorage?.key) ? m.localStorage?.key(t) : m?.localStorage?.key;
96
+ if (b && f) {
97
+ const p = `${f}-${c}-${b}`;
98
+ let I;
99
99
  try {
100
- p = ft(w)?.lastSyncedWithServer;
100
+ I = ft(p)?.lastSyncedWithServer;
101
101
  } catch {
102
102
  }
103
103
  const a = {
104
104
  state: t,
105
105
  lastUpdated: Date.now(),
106
- lastSyncedWithServer: y ?? p
107
- }, v = Ut.serialize(a);
106
+ lastSyncedWithServer: y ?? I
107
+ }, v = Dt.serialize(a);
108
108
  window.localStorage.setItem(
109
- w,
109
+ p,
110
110
  JSON.stringify(v.json)
111
111
  );
112
112
  }
@@ -121,25 +121,25 @@ const de = (t, c) => {
121
121
  }, Bt = (t, c) => {
122
122
  const m = o.getState().cogsStateStore[t], { sessionId: f } = Ct(), y = Y(c?.localStorage?.key) ? c.localStorage.key(m) : c?.localStorage?.key;
123
123
  if (y && f) {
124
- const $ = ft(
124
+ const b = ft(
125
125
  `${f}-${t}-${y}`
126
126
  );
127
- if ($ && $.lastUpdated > ($.lastSyncedWithServer || 0))
128
- return K(t, $.state), St(t), !0;
127
+ if (b && b.lastUpdated > (b.lastSyncedWithServer || 0))
128
+ return et(t, b.state), St(t), !0;
129
129
  }
130
130
  return !1;
131
- }, xt = (t, c, m, f, y, $) => {
132
- const w = {
131
+ }, xt = (t, c, m, f, y, b) => {
132
+ const p = {
133
133
  initialState: c,
134
134
  updaterState: gt(
135
135
  t,
136
136
  f,
137
137
  y,
138
- $
138
+ b
139
139
  ),
140
140
  state: m
141
141
  };
142
- Et(t, w.initialState), ut(t, w.updaterState), K(t, w.state);
142
+ At(t, p.initialState), ut(t, p.updaterState), et(t, p.state);
143
143
  }, St = (t) => {
144
144
  const c = o.getState().stateComponents.get(t);
145
145
  if (!c) return;
@@ -149,7 +149,7 @@ const de = (t, c) => {
149
149
  }), queueMicrotask(() => {
150
150
  m.forEach((f) => f());
151
151
  });
152
- }, ue = (t, c) => {
152
+ }, ge = (t, c) => {
153
153
  const m = o.getState().stateComponents.get(t);
154
154
  if (m) {
155
155
  const f = `${t}////${c}`, y = m.components.get(f);
@@ -157,7 +157,7 @@ const de = (t, c) => {
157
157
  return;
158
158
  y && y.forceUpdate();
159
159
  }
160
- }, qt = (t, c, m, f) => {
160
+ }, Jt = (t, c, m, f) => {
161
161
  switch (t) {
162
162
  case "update":
163
163
  return {
@@ -180,27 +180,27 @@ const de = (t, c) => {
180
180
  return { oldValue: null, newValue: null };
181
181
  }
182
182
  };
183
- function Jt(t, {
183
+ function Yt(t, {
184
184
  stateKey: c,
185
185
  serverSync: m,
186
186
  localStorage: f,
187
187
  formElements: y,
188
- reactiveDeps: $,
189
- reactiveType: w,
190
- componentId: p,
188
+ reactiveDeps: b,
189
+ reactiveType: p,
190
+ componentId: I,
191
191
  initialState: a,
192
192
  syncUpdate: v,
193
193
  dependencies: n,
194
194
  serverState: S
195
195
  } = {}) {
196
- const [G, R] = et({}), { sessionId: F } = Ct();
197
- let L = !c;
198
- const [h] = et(c ?? wt()), l = o.getState().stateLog[h], at = B(/* @__PURE__ */ new Set()), Z = B(p ?? wt()), j = B(
196
+ const [W, R] = tt({}), { sessionId: U } = Ct();
197
+ let G = !c;
198
+ const [h] = tt(c ?? wt()), l = o.getState().stateLog[h], it = B(/* @__PURE__ */ new Set()), Z = B(I ?? wt()), j = B(
199
199
  null
200
200
  );
201
- j.current = tt(h) ?? null, lt(() => {
201
+ j.current = nt(h) ?? null, at(() => {
202
202
  if (v && v.stateKey === h && v.path?.[0]) {
203
- K(h, (r) => ({
203
+ et(h, (r) => ({
204
204
  ...r,
205
205
  [v.path[0]]: v.newValue
206
206
  }));
@@ -210,7 +210,7 @@ function Jt(t, {
210
210
  userId: v.userId
211
211
  });
212
212
  }
213
- }, [v]), lt(() => {
213
+ }, [v]), at(() => {
214
214
  if (a) {
215
215
  $t(h, {
216
216
  initialState: a
@@ -220,17 +220,17 @@ function Jt(t, {
220
220
  return;
221
221
  let g = null;
222
222
  const A = Y(e?.localStorage?.key) ? e?.localStorage?.key(a) : e?.localStorage?.key;
223
- A && F && (g = ft(`${F}-${h}-${A}`));
224
- let E = a, T = !1;
225
- const x = s ? Date.now() : 0, b = g?.lastUpdated || 0, k = g?.lastSyncedWithServer || 0;
226
- s && x > b ? (E = e.serverState.data, T = !0) : g && b > k && (E = g.state, e?.localStorage?.onChange && e?.localStorage?.onChange(E)), o.getState().initializeShadowState(h, a), xt(
223
+ A && U && (g = ft(`${U}-${h}-${A}`));
224
+ let w = a, T = !1;
225
+ const _ = s ? Date.now() : 0, C = g?.lastUpdated || 0, M = g?.lastSyncedWithServer || 0;
226
+ s && _ > C ? (w = e.serverState.data, T = !0) : g && C > M && (w = g.state, e?.localStorage?.onChange && e?.localStorage?.onChange(w)), o.getState().initializeShadowState(h, a), xt(
227
227
  h,
228
228
  a,
229
- E,
230
- nt,
229
+ w,
230
+ rt,
231
231
  Z.current,
232
- F
233
- ), T && A && F && Nt(E, h, e, F, Date.now()), St(h), (Array.isArray(w) ? w : [w || "component"]).includes("none") || R({});
232
+ U
233
+ ), T && A && U && kt(w, h, e, U, Date.now()), St(h), (Array.isArray(p) ? p : [p || "component"]).includes("none") || R({});
234
234
  }
235
235
  }, [
236
236
  a,
@@ -238,7 +238,7 @@ function Jt(t, {
238
238
  S?.data,
239
239
  ...n || []
240
240
  ]), dt(() => {
241
- L && $t(h, {
241
+ G && $t(h, {
242
242
  serverSync: m,
243
243
  formElements: y,
244
244
  initialState: a,
@@ -252,41 +252,41 @@ function Jt(t, {
252
252
  forceUpdate: () => R({}),
253
253
  paths: /* @__PURE__ */ new Set(),
254
254
  deps: [],
255
- depsFunction: $ || void 0,
256
- reactiveType: w ?? ["component", "deps"]
255
+ depsFunction: b || void 0,
256
+ reactiveType: p ?? ["component", "deps"]
257
257
  }), o.getState().stateComponents.set(h, r), R({}), () => {
258
258
  r && (r.components.delete(e), r.components.size === 0 && o.getState().stateComponents.delete(h));
259
259
  };
260
260
  }, []);
261
- const nt = (e, r, s, i) => {
261
+ const rt = (e, r, s, i) => {
262
262
  if (Array.isArray(r)) {
263
263
  const g = `${h}-${r.join(".")}`;
264
- at.current.add(g);
264
+ it.current.add(g);
265
265
  }
266
266
  const u = o.getState();
267
- K(h, (g) => {
268
- const A = Y(e) ? e(g) : e, E = `${h}-${r.join(".")}`;
269
- if (E) {
270
- let M = !1, N = u.signalDomElements.get(E);
271
- if ((!N || N.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
267
+ et(h, (g) => {
268
+ const A = Y(e) ? e(g) : e, w = `${h}-${r.join(".")}`;
269
+ if (w) {
270
+ let V = !1, k = u.signalDomElements.get(w);
271
+ if ((!k || k.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
272
272
  const O = r.slice(0, -1), D = z(A, O);
273
273
  if (Array.isArray(D)) {
274
- M = !0;
275
- const I = `${h}-${O.join(".")}`;
276
- N = u.signalDomElements.get(I);
274
+ V = !0;
275
+ const $ = `${h}-${O.join(".")}`;
276
+ k = u.signalDomElements.get($);
277
277
  }
278
278
  }
279
- if (N) {
280
- const O = M ? z(A, r.slice(0, -1)) : z(A, r);
281
- N.forEach(({ parentId: D, position: I, effect: C }) => {
282
- const V = document.querySelector(
279
+ if (k) {
280
+ const O = V ? z(A, r.slice(0, -1)) : z(A, r);
281
+ k.forEach(({ parentId: D, position: $, effect: E }) => {
282
+ const N = document.querySelector(
283
283
  `[data-parent-id="${D}"]`
284
284
  );
285
- if (V) {
286
- const _ = Array.from(V.childNodes);
287
- if (_[I]) {
288
- const P = C ? new Function("state", `return (${C})(state)`)(O) : O;
289
- _[I].textContent = String(P);
285
+ if (N) {
286
+ const F = Array.from(N.childNodes);
287
+ if (F[$]) {
288
+ const x = E ? new Function("state", `return (${E})(state)`)(O) : O;
289
+ F[$].textContent = String(x);
290
290
  }
291
291
  }
292
292
  });
@@ -298,118 +298,118 @@ function Jt(t, {
298
298
  const T = r.slice(0, r.length - 1);
299
299
  s.updateType === "cut" && j.current?.validation?.key && J(
300
300
  j.current?.validation?.key + "." + T.join(".")
301
- ), s.updateType === "insert" && j.current?.validation?.key && Gt(
301
+ ), s.updateType === "insert" && j.current?.validation?.key && Lt(
302
302
  j.current?.validation?.key + "." + T.join(".")
303
- ).filter(([N, O]) => {
304
- let D = N?.split(".").length;
305
- if (N == T.join(".") && D == T.length - 1) {
306
- let I = N + "." + T;
307
- J(N), Ht(I, O);
303
+ ).filter(([k, O]) => {
304
+ let D = k?.split(".").length;
305
+ if (k == T.join(".") && D == T.length - 1) {
306
+ let $ = k + "." + T;
307
+ J(k), zt($, O);
308
308
  }
309
309
  });
310
- const x = u.stateComponents.get(h);
311
- if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", x), x) {
312
- const M = pt(g, A), N = new Set(M), O = s.updateType === "update" ? r.join(".") : r.slice(0, -1).join(".") || "";
310
+ const _ = u.stateComponents.get(h);
311
+ if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", _), _) {
312
+ const V = pt(g, A), k = new Set(V), O = s.updateType === "update" ? r.join(".") : r.slice(0, -1).join(".") || "";
313
313
  for (const [
314
314
  D,
315
- I
316
- ] of x.components.entries()) {
317
- let C = !1;
318
- const V = Array.isArray(I.reactiveType) ? I.reactiveType : [I.reactiveType || "component"];
319
- if (console.log("component", I), !V.includes("none")) {
320
- if (V.includes("all")) {
321
- I.forceUpdate();
315
+ $
316
+ ] of _.components.entries()) {
317
+ let E = !1;
318
+ const N = Array.isArray($.reactiveType) ? $.reactiveType : [$.reactiveType || "component"];
319
+ if (console.log("component", $), !N.includes("none")) {
320
+ if (N.includes("all")) {
321
+ $.forceUpdate();
322
322
  continue;
323
323
  }
324
- if (V.includes("component") && ((I.paths.has(O) || I.paths.has("")) && (C = !0), !C))
325
- for (const _ of N) {
326
- let P = _;
324
+ if (N.includes("component") && (($.paths.has(O) || $.paths.has("")) && (E = !0), !E))
325
+ for (const F of k) {
326
+ let x = F;
327
327
  for (; ; ) {
328
- if (I.paths.has(P)) {
329
- C = !0;
328
+ if ($.paths.has(x)) {
329
+ E = !0;
330
330
  break;
331
331
  }
332
- const q = P.lastIndexOf(".");
333
- if (q !== -1) {
334
- const st = P.substring(
332
+ const L = x.lastIndexOf(".");
333
+ if (L !== -1) {
334
+ const X = x.substring(
335
335
  0,
336
- q
336
+ L
337
337
  );
338
338
  if (!isNaN(
339
- Number(P.substring(q + 1))
340
- ) && I.paths.has(st)) {
341
- C = !0;
339
+ Number(x.substring(L + 1))
340
+ ) && $.paths.has(X)) {
341
+ E = !0;
342
342
  break;
343
343
  }
344
- P = st;
344
+ x = X;
345
345
  } else
346
- P = "";
347
- if (P === "")
346
+ x = "";
347
+ if (x === "")
348
348
  break;
349
349
  }
350
- if (C) break;
350
+ if (E) break;
351
351
  }
352
- if (!C && V.includes("deps") && I.depsFunction) {
353
- const _ = I.depsFunction(A);
354
- let P = !1;
355
- typeof _ == "boolean" ? _ && (P = !0) : H(I.deps, _) || (I.deps = _, P = !0), P && (C = !0);
352
+ if (!E && N.includes("deps") && $.depsFunction) {
353
+ const F = $.depsFunction(A);
354
+ let x = !1;
355
+ typeof F == "boolean" ? F && (x = !0) : H($.deps, F) || ($.deps = F, x = !0), x && (E = !0);
356
356
  }
357
- C && I.forceUpdate();
357
+ E && $.forceUpdate();
358
358
  }
359
359
  }
360
360
  }
361
- const b = Date.now();
362
- r = r.map((M, N) => {
361
+ const C = Date.now();
362
+ r = r.map((V, k) => {
363
363
  const O = r.slice(0, -1), D = z(A, O);
364
- return N === r.length - 1 && ["insert", "cut"].includes(s.updateType) ? (D.length - 1).toString() : M;
364
+ return k === r.length - 1 && ["insert", "cut"].includes(s.updateType) ? (D.length - 1).toString() : V;
365
365
  });
366
- const { oldValue: k, newValue: W } = qt(
366
+ const { oldValue: M, newValue: P } = Jt(
367
367
  s.updateType,
368
368
  g,
369
369
  A,
370
370
  r
371
- ), U = {
372
- timeStamp: b,
371
+ ), q = {
372
+ timeStamp: C,
373
373
  stateKey: h,
374
374
  path: r,
375
375
  updateType: s.updateType,
376
376
  status: "new",
377
- oldValue: k,
378
- newValue: W
377
+ oldValue: M,
378
+ newValue: P
379
379
  };
380
380
  switch (s.updateType) {
381
381
  case "update":
382
382
  u.updateShadowAtPath(h, r, A);
383
383
  break;
384
384
  case "insert":
385
- const M = r.slice(0, -1);
386
- u.insertShadowArrayElement(h, M, W);
385
+ const V = r.slice(0, -1);
386
+ u.insertShadowArrayElement(h, V, P);
387
387
  break;
388
388
  case "cut":
389
- const N = r.slice(0, -1), O = parseInt(r[r.length - 1]);
390
- u.removeShadowArrayElement(h, N, O);
389
+ const k = r.slice(0, -1), O = parseInt(r[r.length - 1]);
390
+ u.removeShadowArrayElement(h, k, O);
391
391
  break;
392
392
  }
393
- if (Lt(h, (M) => {
394
- const O = [...M ?? [], U].reduce((D, I) => {
395
- const C = `${I.stateKey}:${JSON.stringify(I.path)}`, V = D.get(C);
396
- return V ? (V.timeStamp = Math.max(V.timeStamp, I.timeStamp), V.newValue = I.newValue, V.oldValue = V.oldValue ?? I.oldValue, V.updateType = I.updateType) : D.set(C, { ...I }), D;
393
+ if (Ht(h, (V) => {
394
+ const O = [...V ?? [], q].reduce((D, $) => {
395
+ const E = `${$.stateKey}:${JSON.stringify($.path)}`, N = D.get(E);
396
+ return N ? (N.timeStamp = Math.max(N.timeStamp, $.timeStamp), N.newValue = $.newValue, N.oldValue = N.oldValue ?? $.oldValue, N.updateType = $.updateType) : D.set(E, { ...$ }), D;
397
397
  }, /* @__PURE__ */ new Map());
398
398
  return Array.from(O.values());
399
- }), Nt(
399
+ }), kt(
400
400
  A,
401
401
  h,
402
402
  j.current,
403
- F
403
+ U
404
404
  ), j.current?.middleware && j.current.middleware({
405
405
  updateLog: l,
406
- update: U
406
+ update: q
407
407
  }), j.current?.serverSync) {
408
- const M = u.serverState[h], N = j.current?.serverSync;
409
- zt(h, {
410
- syncKey: typeof N.syncKey == "string" ? N.syncKey : N.syncKey({ state: A }),
411
- rollBackState: M,
412
- actionTimeStamp: Date.now() + (N.debounce ?? 3e3),
408
+ const V = u.serverState[h], k = j.current?.serverSync;
409
+ qt(h, {
410
+ syncKey: typeof k.syncKey == "string" ? k.syncKey : k.syncKey({ state: A }),
411
+ rollBackState: V,
412
+ actionTimeStamp: Date.now() + (k.debounce ?? 3e3),
413
413
  status: "waiting"
414
414
  });
415
415
  }
@@ -420,28 +420,28 @@ function Jt(t, {
420
420
  h,
421
421
  gt(
422
422
  h,
423
- nt,
423
+ rt,
424
424
  Z.current,
425
- F
425
+ U
426
426
  )
427
- ), o.getState().cogsStateStore[h] || K(h, t), o.getState().initialStateGlobal[h] || Et(h, t));
427
+ ), o.getState().cogsStateStore[h] || et(h, t), o.getState().initialStateGlobal[h] || At(h, t));
428
428
  const d = It(() => gt(
429
429
  h,
430
- nt,
430
+ rt,
431
431
  Z.current,
432
- F
433
- ), [h, F]);
432
+ U
433
+ ), [h, U]);
434
434
  return [Vt(h), d];
435
435
  }
436
436
  function gt(t, c, m, f) {
437
437
  const y = /* @__PURE__ */ new Map();
438
- let $ = 0;
439
- const w = (v) => {
438
+ let b = 0;
439
+ const p = (v) => {
440
440
  const n = v.join(".");
441
441
  for (const [S] of y)
442
442
  (S === n || S.startsWith(n + ".")) && y.delete(S);
443
- $++;
444
- }, p = {
443
+ b++;
444
+ }, I = {
445
445
  removeValidation: (v) => {
446
446
  v?.validationKey && J(v.validationKey);
447
447
  },
@@ -449,30 +449,30 @@ function gt(t, c, m, f) {
449
449
  const n = o.getState().getInitialOptions(t)?.validation;
450
450
  n?.key && J(n?.key), v?.validationKey && J(v.validationKey);
451
451
  const S = o.getState().initialStateGlobal[t];
452
- o.getState().clearSelectedIndexesForState(t), y.clear(), $++;
453
- const G = a(S, []), R = tt(t), F = Y(R?.localStorage?.key) ? R?.localStorage?.key(S) : R?.localStorage?.key, L = `${f}-${t}-${F}`;
454
- L && localStorage.removeItem(L), ut(t, G), K(t, S);
452
+ o.getState().clearSelectedIndexesForState(t), y.clear(), b++;
453
+ const W = a(S, []), R = nt(t), U = Y(R?.localStorage?.key) ? R?.localStorage?.key(S) : R?.localStorage?.key, G = `${f}-${t}-${U}`;
454
+ G && localStorage.removeItem(G), ut(t, W), et(t, S);
455
455
  const h = o.getState().stateComponents.get(t);
456
456
  return h && h.components.forEach((l) => {
457
457
  l.forceUpdate();
458
458
  }), S;
459
459
  },
460
460
  updateInitialState: (v) => {
461
- y.clear(), $++;
461
+ y.clear(), b++;
462
462
  const n = gt(
463
463
  t,
464
464
  c,
465
465
  m,
466
466
  f
467
- ), S = o.getState().initialStateGlobal[t], G = tt(t), R = Y(G?.localStorage?.key) ? G?.localStorage?.key(S) : G?.localStorage?.key, F = `${f}-${t}-${R}`;
468
- return localStorage.getItem(F) && localStorage.removeItem(F), Mt(() => {
469
- Et(t, v), o.getState().initializeShadowState(t, v), ut(t, n), K(t, v);
470
- const L = o.getState().stateComponents.get(t);
471
- L && L.components.forEach((h) => {
467
+ ), S = o.getState().initialStateGlobal[t], W = nt(t), R = Y(W?.localStorage?.key) ? W?.localStorage?.key(S) : W?.localStorage?.key, U = `${f}-${t}-${R}`;
468
+ return localStorage.getItem(U) && localStorage.removeItem(U), jt(() => {
469
+ At(t, v), o.getState().initializeShadowState(t, v), ut(t, n), et(t, v);
470
+ const G = o.getState().stateComponents.get(t);
471
+ G && G.components.forEach((h) => {
472
472
  h.forceUpdate();
473
473
  });
474
474
  }), {
475
- fetchId: (L) => n.get()[L]
475
+ fetchId: (G) => n.get()[G]
476
476
  };
477
477
  },
478
478
  _initialState: o.getState().initialStateGlobal[t],
@@ -484,23 +484,23 @@ function gt(t, c, m, f) {
484
484
  }
485
485
  };
486
486
  function a(v, n = [], S) {
487
- const G = n.map(String).join(".");
488
- y.get(G);
487
+ const W = n.map(String).join(".");
488
+ y.get(W);
489
489
  const R = function() {
490
490
  return o().getNestedState(t, n);
491
491
  };
492
- Object.keys(p).forEach((h) => {
493
- R[h] = p[h];
492
+ Object.keys(I).forEach((h) => {
493
+ R[h] = I[h];
494
494
  });
495
- const F = {
496
- apply(h, l, at) {
495
+ const U = {
496
+ apply(h, l, it) {
497
497
  return console.log(
498
498
  `PROXY APPLY TRAP HIT: stateKey=${t}, path=${n.join(".")}`
499
499
  ), console.trace("Apply trap stack trace"), o().getNestedState(t, n);
500
500
  },
501
501
  get(h, l) {
502
502
  S?.validIndices && !Array.isArray(v) && (S = { ...S, validIndices: void 0 });
503
- const at = /* @__PURE__ */ new Set([
503
+ const it = /* @__PURE__ */ new Set([
504
504
  "insert",
505
505
  "cut",
506
506
  "cutByValue",
@@ -523,7 +523,7 @@ function gt(t, c, m, f) {
523
523
  "_stateKey",
524
524
  "getComponents"
525
525
  ]);
526
- if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !at.has(l)) {
526
+ if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !it.has(l)) {
527
527
  const d = `${t}////${m}`, e = o.getState().stateComponents.get(t);
528
528
  if (e) {
529
529
  const r = e.components.get(d);
@@ -581,7 +581,7 @@ function gt(t, c, m, f) {
581
581
  };
582
582
  if (l === "removeStorage")
583
583
  return () => {
584
- const d = o.getState().initialStateGlobal[t], e = tt(t), r = Y(e?.localStorage?.key) ? e?.localStorage?.key(d) : e?.localStorage?.key, s = `${f}-${t}-${r}`;
584
+ const d = o.getState().initialStateGlobal[t], e = nt(t), r = Y(e?.localStorage?.key) ? e?.localStorage?.key(d) : e?.localStorage?.key, s = `${f}-${t}-${r}`;
585
585
  s && localStorage.removeItem(s);
586
586
  };
587
587
  if (l === "showValidationErrors")
@@ -621,104 +621,108 @@ function gt(t, c, m, f) {
621
621
  itemHeight: r = 50,
622
622
  overscan: s = 5,
623
623
  stickToBottom: i = !1
624
- } = e, u = B(null), [g, A] = et({
624
+ } = e, u = B(null), [g, A] = tt({
625
625
  startIndex: 0,
626
626
  endIndex: 10
627
- }), E = B(i), T = B(0), x = B(!0), b = o().getNestedState(
627
+ }), [, w] = tt({}), T = B(i), _ = B(0), C = B(!0);
628
+ at(() => o.getState().subscribeToShadowState(t, () => w({})), [t]);
629
+ const M = o().getNestedState(
628
630
  t,
629
631
  n
630
- ), k = b.length, { totalHeight: W, positions: U } = It(() => {
631
- const I = o.getState().getShadowMetadata(t, n) || [];
632
- let C = 0;
633
- const V = [];
634
- for (let _ = 0; _ < k; _++) {
635
- V[_] = C;
636
- const P = I[_]?.virtualizer?.itemHeight;
637
- C += P || r;
632
+ ), P = M.length, { totalHeight: q, positions: V } = It(() => {
633
+ const E = o.getState().getShadowMetadata(t, n) || [];
634
+ let N = 0;
635
+ const F = [];
636
+ for (let x = 0; x < P; x++) {
637
+ F[x] = N;
638
+ const L = E[x]?.virtualizer?.itemHeight;
639
+ N += L || r;
638
640
  }
639
- return { totalHeight: C, positions: V };
640
- }, [k, t, n.join("."), r]), M = It(() => {
641
- const I = Math.max(0, g.startIndex), C = Math.min(k, g.endIndex), V = Array.from(
642
- { length: C - I },
643
- (P, q) => I + q
644
- ), _ = V.map((P) => b[P]);
645
- return a(_, n, {
641
+ return { totalHeight: N, positions: F };
642
+ }, [P, t, n.join("."), r]), k = It(() => {
643
+ const E = Math.max(0, g.startIndex), N = Math.min(P, g.endIndex), F = Array.from(
644
+ { length: N - E },
645
+ (L, X) => E + X
646
+ ), x = F.map((L) => M[L]);
647
+ return a(x, n, {
646
648
  ...S,
647
- validIndices: V
649
+ validIndices: F
648
650
  });
649
- }, [g.startIndex, g.endIndex, b, k]);
651
+ }, [g.startIndex, g.endIndex, M, P]);
650
652
  dt(() => {
651
- const I = u.current;
652
- if (!I) return;
653
- const C = E.current, V = k > T.current;
654
- T.current = k;
655
- const _ = () => {
656
- const { scrollTop: P, clientHeight: q, scrollHeight: st } = I;
657
- E.current = st - P - q < 10;
658
- let mt = 0, it = k - 1;
659
- for (; mt <= it; ) {
660
- const Q = Math.floor((mt + it) / 2);
661
- U[Q] < P ? mt = Q + 1 : it = Q - 1;
653
+ const E = u.current;
654
+ if (!E) return;
655
+ const N = T.current, F = P > _.current;
656
+ _.current = P;
657
+ const x = () => {
658
+ const { scrollTop: L, clientHeight: X, scrollHeight: Pt } = E;
659
+ T.current = Pt - L - X < 10;
660
+ let mt = 0, ct = P - 1;
661
+ for (; mt <= ct; ) {
662
+ const K = Math.floor((mt + ct) / 2);
663
+ V[K] < L ? mt = K + 1 : ct = K - 1;
662
664
  }
663
- const ht = Math.max(0, it - s);
664
- let X = ht;
665
- const Pt = P + q;
666
- for (; X < k && U[X] < Pt; )
667
- X++;
668
- X = Math.min(k, X + s), A((Q) => Q.startIndex !== ht || Q.endIndex !== X ? { startIndex: ht, endIndex: X } : Q);
665
+ const ht = Math.max(0, ct - s);
666
+ let Q = ht;
667
+ const _t = L + X;
668
+ for (; Q < P && V[Q] < _t; )
669
+ Q++;
670
+ Q = Math.min(P, Q + s), A((K) => K.startIndex !== ht || K.endIndex !== Q ? { startIndex: ht, endIndex: Q } : K);
669
671
  };
670
- return I.addEventListener("scroll", _, {
672
+ return E.addEventListener("scroll", x, {
671
673
  passive: !0
672
- }), i ? x.current && k > 0 ? (setTimeout(() => {
673
- u.current && u.current.scrollTo({
674
- top: u.current.scrollHeight,
675
- behavior: "auto"
674
+ }), i && (C.current && P > 0 ? requestAnimationFrame(() => {
675
+ requestAnimationFrame(() => {
676
+ u.current && (u.current.scrollTo({
677
+ top: u.current.scrollHeight,
678
+ behavior: "auto"
679
+ }), C.current = !1);
676
680
  });
677
- }, 0), x.current = !1) : C && V && requestAnimationFrame(() => {
678
- I.scrollTo({
679
- top: I.scrollHeight,
681
+ }) : !C.current && N && F && requestAnimationFrame(() => {
682
+ E.scrollTo({
683
+ top: E.scrollHeight,
680
684
  behavior: "smooth"
681
685
  });
682
- }) : x.current = !1, _(), () => I.removeEventListener("scroll", _);
683
- }, [k, U, s, i]);
684
- const N = At(
685
- (I = "smooth") => {
686
+ })), x(), () => E.removeEventListener("scroll", x);
687
+ }, [P, V, s, i]);
688
+ const O = Et(
689
+ (E = "smooth") => {
686
690
  u.current && u.current.scrollTo({
687
691
  top: u.current.scrollHeight,
688
- behavior: I
692
+ behavior: E
689
693
  });
690
694
  },
691
695
  []
692
- ), O = At(
693
- (I, C = "smooth") => {
694
- u.current && U[I] !== void 0 && u.current.scrollTo({
695
- top: U[I],
696
- behavior: C
696
+ ), D = Et(
697
+ (E, N = "smooth") => {
698
+ u.current && V[E] !== void 0 && u.current.scrollTo({
699
+ top: V[E],
700
+ behavior: N
697
701
  });
698
702
  },
699
- [U]
700
- ), D = {
703
+ [V]
704
+ ), $ = {
701
705
  outer: {
702
706
  ref: u,
703
707
  style: { overflowY: "auto", height: "100%" }
704
708
  },
705
709
  inner: {
706
710
  style: {
707
- height: `${W}px`,
711
+ height: `${q}px`,
708
712
  position: "relative"
709
713
  }
710
714
  },
711
715
  list: {
712
716
  style: {
713
- transform: `translateY(${U[g.startIndex] || 0}px)`
717
+ transform: `translateY(${V[g.startIndex] || 0}px)`
714
718
  }
715
719
  }
716
720
  };
717
721
  return {
718
- virtualState: M,
719
- virtualizerProps: D,
720
- scrollToBottom: N,
721
- scrollToIndex: O
722
+ virtualState: k,
723
+ virtualizerProps: $,
724
+ scrollToBottom: O,
725
+ scrollToIndex: D
722
726
  };
723
727
  };
724
728
  if (l === "stateSort")
@@ -749,22 +753,22 @@ function gt(t, c, m, f) {
749
753
  return (e) => {
750
754
  const r = o.getState().getNestedState(t, n);
751
755
  return Array.isArray(r) ? (S?.validIndices || Array.from({ length: r.length }, (i, u) => u)).map((i, u) => {
752
- const g = r[i], A = [...n, i.toString()], E = a(g, A, S);
753
- return e(g, E, {
756
+ const g = r[i], A = [...n, i.toString()], w = a(g, A, S);
757
+ return e(g, w, {
754
758
  register: () => {
755
- const [, x] = et({}), b = `${m}-${n.join(".")}-${i}`;
759
+ const [, _] = tt({}), C = `${m}-${n.join(".")}-${i}`;
756
760
  dt(() => {
757
- const k = `${t}////${b}`, W = o.getState().stateComponents.get(t) || {
761
+ const M = `${t}////${C}`, P = o.getState().stateComponents.get(t) || {
758
762
  components: /* @__PURE__ */ new Map()
759
763
  };
760
- return W.components.set(k, {
761
- forceUpdate: () => x({}),
764
+ return P.components.set(M, {
765
+ forceUpdate: () => _({}),
762
766
  paths: /* @__PURE__ */ new Set([A.join(".")])
763
- }), o.getState().stateComponents.set(t, W), () => {
764
- const U = o.getState().stateComponents.get(t);
765
- U && U.components.delete(k);
767
+ }), o.getState().stateComponents.set(t, P), () => {
768
+ const q = o.getState().stateComponents.get(t);
769
+ q && q.components.delete(M);
766
770
  };
767
- }, [t, b]);
771
+ }, [t, C]);
768
772
  },
769
773
  index: u,
770
774
  originalIndex: i
@@ -788,7 +792,7 @@ function gt(t, c, m, f) {
788
792
  );
789
793
  });
790
794
  if (l === "$stateMap")
791
- return (e) => ot(Yt, {
795
+ return (e) => st(Zt, {
792
796
  proxy: {
793
797
  _stateKey: t,
794
798
  _path: n,
@@ -801,15 +805,15 @@ function gt(t, c, m, f) {
801
805
  return (e) => {
802
806
  const r = o.getState().getNestedState(t, n);
803
807
  return Array.isArray(r) ? (S?.validIndices || Array.from({ length: r.length }, (i, u) => u)).map((i, u) => {
804
- const g = r[i], A = [...n, i.toString()], E = a(g, A, S), T = `${m}-${n.join(".")}-${i}`;
805
- return ot(Xt, {
808
+ const g = r[i], A = [...n, i.toString()], w = a(g, A, S), T = `${m}-${n.join(".")}-${i}`;
809
+ return st(Qt, {
806
810
  key: i,
807
811
  stateKey: t,
808
812
  itemComponentId: T,
809
813
  itemPath: A,
810
814
  children: e(
811
815
  g,
812
- E,
816
+ w,
813
817
  u,
814
818
  r,
815
819
  a(r, n, S)
@@ -822,7 +826,7 @@ function gt(t, c, m, f) {
822
826
  if (l === "stateFlattenOn")
823
827
  return (e) => {
824
828
  const r = v;
825
- y.clear(), $++;
829
+ y.clear(), b++;
826
830
  const s = r.flatMap(
827
831
  (i) => i[e] ?? []
828
832
  );
@@ -845,7 +849,7 @@ function gt(t, c, m, f) {
845
849
  return a(s, i);
846
850
  };
847
851
  if (l === "insert")
848
- return (e) => (w(n), vt(c, e, n, t), a(
852
+ return (e) => (p(n), vt(c, e, n, t), a(
849
853
  o.getState().getNestedState(t, n),
850
854
  n
851
855
  ));
@@ -853,28 +857,28 @@ function gt(t, c, m, f) {
853
857
  return (e, r, s) => {
854
858
  const i = o.getState().getNestedState(t, n), u = Y(e) ? e(i) : e;
855
859
  let g = null;
856
- if (!i.some((E) => {
860
+ if (!i.some((w) => {
857
861
  if (r) {
858
- const x = r.every(
859
- (b) => H(E[b], u[b])
862
+ const _ = r.every(
863
+ (C) => H(w[C], u[C])
860
864
  );
861
- return x && (g = E), x;
865
+ return _ && (g = w), _;
862
866
  }
863
- const T = H(E, u);
864
- return T && (g = E), T;
867
+ const T = H(w, u);
868
+ return T && (g = w), T;
865
869
  }))
866
- w(n), vt(c, u, n, t);
870
+ p(n), vt(c, u, n, t);
867
871
  else if (s && g) {
868
- const E = s(g), T = i.map(
869
- (x) => H(x, g) ? E : x
872
+ const w = s(g), T = i.map(
873
+ (_) => H(_, g) ? w : _
870
874
  );
871
- w(n), rt(c, T, n);
875
+ p(n), ot(c, T, n);
872
876
  }
873
877
  };
874
878
  if (l === "cut")
875
879
  return (e, r) => {
876
880
  if (!r?.waitForSync)
877
- return w(n), ct(c, n, t, e), a(
881
+ return p(n), lt(c, n, t, e), a(
878
882
  o.getState().getNestedState(t, n),
879
883
  n
880
884
  );
@@ -882,12 +886,12 @@ function gt(t, c, m, f) {
882
886
  if (l === "cutByValue")
883
887
  return (e) => {
884
888
  for (let r = 0; r < v.length; r++)
885
- v[r] === e && ct(c, n, t, r);
889
+ v[r] === e && lt(c, n, t, r);
886
890
  };
887
891
  if (l === "toggleByValue")
888
892
  return (e) => {
889
893
  const r = v.findIndex((s) => s === e);
890
- r > -1 ? ct(c, n, t, r) : vt(c, e, n, t);
894
+ r > -1 ? lt(c, n, t, r) : vt(c, e, n, t);
891
895
  };
892
896
  if (l === "stateFind")
893
897
  return (e) => {
@@ -912,7 +916,7 @@ function gt(t, c, m, f) {
912
916
  if (!isNaN(Number(Z))) {
913
917
  const d = n.slice(0, -1), e = o.getState().getNestedState(t, d);
914
918
  if (Array.isArray(e) && l === "cut")
915
- return () => ct(
919
+ return () => lt(
916
920
  c,
917
921
  d,
918
922
  t,
@@ -928,13 +932,13 @@ function gt(t, c, m, f) {
928
932
  return o.getState().getNestedState(t, n);
929
933
  };
930
934
  if (l === "$derive")
931
- return (d) => bt({
935
+ return (d) => Nt({
932
936
  _stateKey: t,
933
937
  _path: n,
934
938
  _effect: d.toString()
935
939
  });
936
940
  if (l === "$get")
937
- return () => bt({
941
+ return () => Nt({
938
942
  _stateKey: t,
939
943
  _path: n
940
944
  });
@@ -953,7 +957,7 @@ function gt(t, c, m, f) {
953
957
  const e = n.slice(0, -1), r = Number(n[n.length - 1]), s = e.join(".");
954
958
  d ? o.getState().setSelectedIndex(t, s, r) : o.getState().setSelectedIndex(t, s, void 0);
955
959
  const i = o.getState().getNestedState(t, [...e]);
956
- rt(c, i, e), w(e);
960
+ ot(c, i, e), p(e);
957
961
  };
958
962
  if (l === "toggleSelected")
959
963
  return () => {
@@ -964,12 +968,12 @@ function gt(t, c, m, f) {
964
968
  s === e ? void 0 : e
965
969
  );
966
970
  const i = o.getState().getNestedState(t, [...d]);
967
- rt(c, i, d), w(d);
971
+ ot(c, i, d), p(d);
968
972
  };
969
973
  if (n.length == 0) {
970
974
  if (l === "applyJsonPatch")
971
975
  return (d) => {
972
- const e = o.getState().cogsStateStore[t], s = Dt(e, d).newDocument;
976
+ const e = o.getState().cogsStateStore[t], s = Wt(e, d).newDocument;
973
977
  xt(
974
978
  t,
975
979
  o.getState().initialStateGlobal[t],
@@ -983,54 +987,54 @@ function gt(t, c, m, f) {
983
987
  const u = pt(e, s), g = new Set(u);
984
988
  for (const [
985
989
  A,
986
- E
990
+ w
987
991
  ] of i.components.entries()) {
988
992
  let T = !1;
989
- const x = Array.isArray(E.reactiveType) ? E.reactiveType : [E.reactiveType || "component"];
990
- if (!x.includes("none")) {
991
- if (x.includes("all")) {
992
- E.forceUpdate();
993
+ const _ = Array.isArray(w.reactiveType) ? w.reactiveType : [w.reactiveType || "component"];
994
+ if (!_.includes("none")) {
995
+ if (_.includes("all")) {
996
+ w.forceUpdate();
993
997
  continue;
994
998
  }
995
- if (x.includes("component") && (E.paths.has("") && (T = !0), !T))
996
- for (const b of g) {
997
- if (E.paths.has(b)) {
999
+ if (_.includes("component") && (w.paths.has("") && (T = !0), !T))
1000
+ for (const C of g) {
1001
+ if (w.paths.has(C)) {
998
1002
  T = !0;
999
1003
  break;
1000
1004
  }
1001
- let k = b.lastIndexOf(".");
1002
- for (; k !== -1; ) {
1003
- const W = b.substring(0, k);
1004
- if (E.paths.has(W)) {
1005
+ let M = C.lastIndexOf(".");
1006
+ for (; M !== -1; ) {
1007
+ const P = C.substring(0, M);
1008
+ if (w.paths.has(P)) {
1005
1009
  T = !0;
1006
1010
  break;
1007
1011
  }
1008
- const U = b.substring(
1009
- k + 1
1012
+ const q = C.substring(
1013
+ M + 1
1010
1014
  );
1011
- if (!isNaN(Number(U))) {
1012
- const M = W.lastIndexOf(".");
1013
- if (M !== -1) {
1014
- const N = W.substring(
1015
+ if (!isNaN(Number(q))) {
1016
+ const V = P.lastIndexOf(".");
1017
+ if (V !== -1) {
1018
+ const k = P.substring(
1015
1019
  0,
1016
- M
1020
+ V
1017
1021
  );
1018
- if (E.paths.has(N)) {
1022
+ if (w.paths.has(k)) {
1019
1023
  T = !0;
1020
1024
  break;
1021
1025
  }
1022
1026
  }
1023
1027
  }
1024
- k = W.lastIndexOf(".");
1028
+ M = P.lastIndexOf(".");
1025
1029
  }
1026
1030
  if (T) break;
1027
1031
  }
1028
- if (!T && x.includes("deps") && E.depsFunction) {
1029
- const b = E.depsFunction(s);
1030
- let k = !1;
1031
- typeof b == "boolean" ? b && (k = !0) : H(E.deps, b) || (E.deps = b, k = !0), k && (T = !0);
1032
+ if (!T && _.includes("deps") && w.depsFunction) {
1033
+ const C = w.depsFunction(s);
1034
+ let M = !1;
1035
+ typeof C == "boolean" ? C && (M = !0) : H(w.deps, C) || (w.deps = C, M = !0), M && (T = !0);
1032
1036
  }
1033
- T && E.forceUpdate();
1037
+ T && w.forceUpdate();
1034
1038
  }
1035
1039
  }
1036
1040
  }
@@ -1051,8 +1055,8 @@ function gt(t, c, m, f) {
1051
1055
  });
1052
1056
  const i = d.zodSchema.safeParse(r);
1053
1057
  return i.success ? !0 : (i.error.errors.forEach((g) => {
1054
- const A = g.path, E = g.message, T = [d.key, ...A].join(".");
1055
- e(T, E);
1058
+ const A = g.path, w = g.message, T = [d.key, ...A].join(".");
1059
+ e(T, w);
1056
1060
  }), St(t), !1);
1057
1061
  } catch (s) {
1058
1062
  return console.error("Zod schema validation failed", s), !1;
@@ -1070,9 +1074,9 @@ function gt(t, c, m, f) {
1070
1074
  if (l === "_isLoading")
1071
1075
  return o.getState().isLoadingGlobal[t];
1072
1076
  if (l === "revertToInitialState")
1073
- return p.revertToInitialState;
1074
- if (l === "updateInitialState") return p.updateInitialState;
1075
- if (l === "removeValidation") return p.removeValidation;
1077
+ return I.revertToInitialState;
1078
+ if (l === "updateInitialState") return I.updateInitialState;
1079
+ if (l === "removeValidation") return I.removeValidation;
1076
1080
  }
1077
1081
  if (l === "getFormRef")
1078
1082
  return () => Tt.getState().getFormRef(t + "." + n.join("."));
@@ -1093,25 +1097,25 @@ function gt(t, c, m, f) {
1093
1097
  );
1094
1098
  if (l === "_stateKey") return t;
1095
1099
  if (l === "_path") return n;
1096
- if (l === "_isServerSynced") return p._isServerSynced;
1100
+ if (l === "_isServerSynced") return I._isServerSynced;
1097
1101
  if (l === "update")
1098
1102
  return (d, e) => {
1099
1103
  if (e?.debounce)
1100
- Ot(() => {
1101
- rt(c, d, n, "");
1104
+ Ft(() => {
1105
+ ot(c, d, n, "");
1102
1106
  const r = o.getState().getNestedState(t, n);
1103
1107
  e?.afterUpdate && e.afterUpdate(r);
1104
1108
  }, e.debounce);
1105
1109
  else {
1106
- rt(c, d, n, "");
1110
+ ot(c, d, n, "");
1107
1111
  const r = o.getState().getNestedState(t, n);
1108
1112
  e?.afterUpdate && e.afterUpdate(r);
1109
1113
  }
1110
- w(n);
1114
+ p(n);
1111
1115
  };
1112
1116
  if (l === "formElement")
1113
1117
  return (d, e) => /* @__PURE__ */ yt(
1114
- Ft,
1118
+ Ut,
1115
1119
  {
1116
1120
  setState: c,
1117
1121
  stateKey: t,
@@ -1120,23 +1124,23 @@ function gt(t, c, m, f) {
1120
1124
  formOpts: e
1121
1125
  }
1122
1126
  );
1123
- const j = [...n, l], nt = o.getState().getNestedState(t, j);
1124
- return a(nt, j, S);
1127
+ const j = [...n, l], rt = o.getState().getNestedState(t, j);
1128
+ return a(rt, j, S);
1125
1129
  }
1126
- }, L = new Proxy(R, F);
1127
- return y.set(G, {
1128
- proxy: L,
1129
- stateVersion: $
1130
- }), L;
1130
+ }, G = new Proxy(R, U);
1131
+ return y.set(W, {
1132
+ proxy: G,
1133
+ stateVersion: b
1134
+ }), G;
1131
1135
  }
1132
1136
  return a(
1133
1137
  o.getState().getNestedState(t, [])
1134
1138
  );
1135
1139
  }
1136
- function bt(t) {
1137
- return ot(Zt, { proxy: t });
1140
+ function Nt(t) {
1141
+ return st(Xt, { proxy: t });
1138
1142
  }
1139
- function Yt({
1143
+ function Zt({
1140
1144
  proxy: t,
1141
1145
  rebuildStateShape: c
1142
1146
  }) {
@@ -1145,23 +1149,23 @@ function Yt({
1145
1149
  m,
1146
1150
  t._path
1147
1151
  ).stateMapNoRender(
1148
- (y, $, w, p, a) => t._mapFn(y, $, w, p, a)
1152
+ (y, b, p, I, a) => t._mapFn(y, b, p, I, a)
1149
1153
  ) : null;
1150
1154
  }
1151
- function Zt({
1155
+ function Xt({
1152
1156
  proxy: t
1153
1157
  }) {
1154
1158
  const c = B(null), m = `${t._stateKey}-${t._path.join(".")}`;
1155
- return lt(() => {
1159
+ return at(() => {
1156
1160
  const f = c.current;
1157
1161
  if (!f || !f.parentElement) return;
1158
- const y = f.parentElement, w = Array.from(y.childNodes).indexOf(f);
1159
- let p = y.getAttribute("data-parent-id");
1160
- p || (p = `parent-${crypto.randomUUID()}`, y.setAttribute("data-parent-id", p));
1162
+ const y = f.parentElement, p = Array.from(y.childNodes).indexOf(f);
1163
+ let I = y.getAttribute("data-parent-id");
1164
+ I || (I = `parent-${crypto.randomUUID()}`, y.setAttribute("data-parent-id", I));
1161
1165
  const v = {
1162
1166
  instanceId: `instance-${crypto.randomUUID()}`,
1163
- parentId: p,
1164
- position: w,
1167
+ parentId: I,
1168
+ position: p,
1165
1169
  effect: t._effect
1166
1170
  };
1167
1171
  o.getState().addSignalElement(m, v);
@@ -1179,16 +1183,16 @@ function Zt({
1179
1183
  else
1180
1184
  S = n;
1181
1185
  S !== null && typeof S == "object" && (S = JSON.stringify(S));
1182
- const G = document.createTextNode(String(S));
1183
- f.replaceWith(G);
1184
- }, [t._stateKey, t._path.join("."), t._effect]), ot("span", {
1186
+ const W = document.createTextNode(String(S));
1187
+ f.replaceWith(W);
1188
+ }, [t._stateKey, t._path.join("."), t._effect]), st("span", {
1185
1189
  ref: c,
1186
1190
  style: { display: "none" },
1187
1191
  "data-signal-id": m
1188
1192
  });
1189
1193
  }
1190
- function ge(t) {
1191
- const c = _t(
1194
+ function fe(t) {
1195
+ const c = Mt(
1192
1196
  (m) => {
1193
1197
  const f = o.getState().stateComponents.get(t._stateKey) || {
1194
1198
  components: /* @__PURE__ */ new Map()
@@ -1200,22 +1204,22 @@ function ge(t) {
1200
1204
  },
1201
1205
  () => o.getState().getNestedState(t._stateKey, t._path)
1202
1206
  );
1203
- return ot("text", {}, String(c));
1207
+ return st("text", {}, String(c));
1204
1208
  }
1205
- function Xt({
1209
+ function Qt({
1206
1210
  stateKey: t,
1207
1211
  itemComponentId: c,
1208
1212
  itemPath: m,
1209
1213
  children: f
1210
1214
  }) {
1211
- const [, y] = et({}), [$, w] = Wt(), p = B(null);
1212
- return lt(() => {
1213
- w.height > 0 && w.height !== p.current && (p.current = w.height, o.getState().setShadowMetadata(t, m, {
1215
+ const [, y] = tt({}), [b, p] = Gt(), I = B(null);
1216
+ return at(() => {
1217
+ p.height > 0 && p.height !== I.current && (I.current = p.height, o.getState().setShadowMetadata(t, m, {
1214
1218
  virtualizer: {
1215
- itemHeight: w.height
1219
+ itemHeight: p.height
1216
1220
  }
1217
1221
  }));
1218
- }, [w.height, t, m]), dt(() => {
1222
+ }, [p.height, t, m]), dt(() => {
1219
1223
  const a = `${t}////${c}`, v = o.getState().stateComponents.get(t) || {
1220
1224
  components: /* @__PURE__ */ new Map()
1221
1225
  };
@@ -1226,14 +1230,14 @@ function Xt({
1226
1230
  const n = o.getState().stateComponents.get(t);
1227
1231
  n && n.components.delete(a);
1228
1232
  };
1229
- }, [t, c, m.join(".")]), /* @__PURE__ */ yt("div", { ref: $, children: f });
1233
+ }, [t, c, m.join(".")]), /* @__PURE__ */ yt("div", { ref: b, children: f });
1230
1234
  }
1231
1235
  export {
1232
- bt as $cogsSignal,
1233
- ge as $cogsSignalStore,
1234
- le as addStateOptions,
1235
- de as createCogsState,
1236
- ue as notifyComponent,
1237
- Jt as useCogsStateFn
1236
+ Nt as $cogsSignal,
1237
+ fe as $cogsSignalStore,
1238
+ de as addStateOptions,
1239
+ ue as createCogsState,
1240
+ ge as notifyComponent,
1241
+ Yt as useCogsStateFn
1238
1242
  };
1239
1243
  //# sourceMappingURL=CogsState.jsx.map