cogsbox-state 0.5.306 → 0.5.307

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,41 +1,41 @@
1
1
  "use client";
2
- import { jsx as yt } from "react/jsx-runtime";
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
- import { v4 as wt } from "uuid";
2
+ import { jsx as It } from "react/jsx-runtime";
3
+ import { useState as tt, useRef as q, useEffect as st, useLayoutEffect as at, useMemo as pt, createElement as it, useSyncExternalStore as jt, startTransition as Ot, useCallback as Et } from "react";
4
+ import { transformStateFunc as Rt, isDeepEqual as B, isFunction as Z, getNestedValue as J, getDifferences as wt, debounce as Ft } from "./utility.js";
5
+ import { pushFunc as yt, updateFn as ot, cutFunc as ut, ValidationWrapper as Ut, FormControlComponent as Dt } from "./Functions.jsx";
6
+ import Wt from "superjson";
7
+ import { v4 as Tt } from "uuid";
8
8
  import "zod";
9
- import { getGlobalStore as o, formRefStore as Tt } from "./store.js";
10
- import { useCogsConfig as Ct } from "./CogsStateClient.jsx";
11
- import { applyPatch as Wt } from "fast-json-patch";
12
- import Gt from "react-use-measure";
13
- function $t(t, c) {
9
+ import { getGlobalStore as o, formRefStore as $t } from "./store.js";
10
+ import { useCogsConfig as Vt } from "./CogsStateClient.jsx";
11
+ import { applyPatch as Gt } from "fast-json-patch";
12
+ import Lt from "react-use-measure";
13
+ function bt(t, c) {
14
14
  const m = o.getState().getInitialOptions, f = o.getState().setInitialStateOptions, y = m(t) || {};
15
15
  f(t, {
16
16
  ...y,
17
17
  ...c
18
18
  });
19
19
  }
20
- function bt({
20
+ function kt({
21
21
  stateKey: t,
22
22
  options: c,
23
23
  initialOptionsPart: m
24
24
  }) {
25
- const f = nt(t) || {}, y = m[t] || {}, b = o.getState().setInitialStateOptions, p = { ...y, ...f };
25
+ const f = nt(t) || {}, y = m[t] || {}, k = o.getState().setInitialStateOptions, p = { ...y, ...f };
26
26
  let I = !1;
27
27
  if (c)
28
28
  for (const a in c)
29
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);
30
+ !B(p[a], c[a]) && (I = !0, p[a] = c[a])) : (I = !0, p[a] = c[a]);
31
+ I && k(t, p);
32
32
  }
33
- function de(t, { formElements: c, validation: m }) {
33
+ function ue(t, { formElements: c, validation: m }) {
34
34
  return { initialState: t, formElements: c, validation: m };
35
35
  }
36
- const ue = (t, c) => {
36
+ const ge = (t, c) => {
37
37
  let m = t;
38
- const [f, y] = Ot(m);
38
+ const [f, y] = Rt(m);
39
39
  (Object.keys(y).length > 0 || c && Object.keys(c).length > 0) && Object.keys(y).forEach((I) => {
40
40
  y[I] = y[I] || {}, y[I].formElements = {
41
41
  ...c?.formElements,
@@ -45,14 +45,14 @@ const ue = (t, c) => {
45
45
  // State-specific overrides
46
46
  }, nt(I) || o.getState().setInitialStateOptions(I, y[I]);
47
47
  }), o.getState().setInitialStates(f), o.getState().setCreatedState(f);
48
- const b = (I, a) => {
49
- const [v] = tt(a?.componentId ?? wt());
50
- bt({
48
+ const k = (I, a) => {
49
+ const [v] = tt(a?.componentId ?? Tt());
50
+ kt({
51
51
  stateKey: I,
52
52
  options: a,
53
53
  initialOptionsPart: y
54
54
  });
55
- const n = o.getState().cogsStateStore[I] || f[I], S = a?.modifyState ? a.modifyState(n) : n, [W, R] = Yt(
55
+ const n = o.getState().cogsStateStore[I] || f[I], S = a?.modifyState ? a.modifyState(n) : n, [L, R] = Zt(
56
56
  S,
57
57
  {
58
58
  stateKey: I,
@@ -71,46 +71,46 @@ const ue = (t, c) => {
71
71
  return R;
72
72
  };
73
73
  function p(I, a) {
74
- bt({ stateKey: I, options: a, initialOptionsPart: y }), a.localStorage && Bt(I, a), St(I);
74
+ kt({ stateKey: I, options: a, initialOptionsPart: y }), a.localStorage && Jt(I, a), mt(I);
75
75
  }
76
- return { useCogsState: b, setCogsOptions: p };
76
+ return { useCogsState: k, setCogsOptions: p };
77
77
  }, {
78
- setUpdaterState: ut,
78
+ setUpdaterState: gt,
79
79
  setState: et,
80
80
  getInitialOptions: nt,
81
- getKeyState: Vt,
82
- getValidationErrors: Lt,
83
- setStateLog: Ht,
81
+ getKeyState: xt,
82
+ getValidationErrors: Ht,
83
+ setStateLog: zt,
84
84
  updateInitialStateGlobal: At,
85
- addValidationError: zt,
86
- removeValidationError: J,
85
+ addValidationError: Bt,
86
+ removeValidationError: Y,
87
87
  setServerSyncActions: qt
88
- } = o.getState(), kt = (t, c, m, f, y) => {
88
+ } = o.getState(), Ct = (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 b = Y(m?.localStorage?.key) ? m.localStorage?.key(t) : m?.localStorage?.key;
96
- if (b && f) {
97
- const p = `${f}-${c}-${b}`;
95
+ const k = Z(m?.localStorage?.key) ? m.localStorage?.key(t) : m?.localStorage?.key;
96
+ if (k && f) {
97
+ const p = `${f}-${c}-${k}`;
98
98
  let I;
99
99
  try {
100
- I = ft(p)?.lastSyncedWithServer;
100
+ I = St(p)?.lastSyncedWithServer;
101
101
  } catch {
102
102
  }
103
103
  const a = {
104
104
  state: t,
105
105
  lastUpdated: Date.now(),
106
106
  lastSyncedWithServer: y ?? I
107
- }, v = Dt.serialize(a);
107
+ }, v = Wt.serialize(a);
108
108
  window.localStorage.setItem(
109
109
  p,
110
110
  JSON.stringify(v.json)
111
111
  );
112
112
  }
113
- }, ft = (t) => {
113
+ }, St = (t) => {
114
114
  if (!t) return null;
115
115
  try {
116
116
  const c = window.localStorage.getItem(t);
@@ -118,29 +118,29 @@ const ue = (t, c) => {
118
118
  } catch (c) {
119
119
  return console.error("Error loading from localStorage:", c), null;
120
120
  }
121
- }, Bt = (t, c) => {
122
- const m = o.getState().cogsStateStore[t], { sessionId: f } = Ct(), y = Y(c?.localStorage?.key) ? c.localStorage.key(m) : c?.localStorage?.key;
121
+ }, Jt = (t, c) => {
122
+ const m = o.getState().cogsStateStore[t], { sessionId: f } = Vt(), y = Z(c?.localStorage?.key) ? c.localStorage.key(m) : c?.localStorage?.key;
123
123
  if (y && f) {
124
- const b = ft(
124
+ const k = St(
125
125
  `${f}-${t}-${y}`
126
126
  );
127
- if (b && b.lastUpdated > (b.lastSyncedWithServer || 0))
128
- return et(t, b.state), St(t), !0;
127
+ if (k && k.lastUpdated > (k.lastSyncedWithServer || 0))
128
+ return et(t, k.state), mt(t), !0;
129
129
  }
130
130
  return !1;
131
- }, xt = (t, c, m, f, y, b) => {
131
+ }, Pt = (t, c, m, f, y, k) => {
132
132
  const p = {
133
133
  initialState: c,
134
- updaterState: gt(
134
+ updaterState: ft(
135
135
  t,
136
136
  f,
137
137
  y,
138
- b
138
+ k
139
139
  ),
140
140
  state: m
141
141
  };
142
- At(t, p.initialState), ut(t, p.updaterState), et(t, p.state);
143
- }, St = (t) => {
142
+ At(t, p.initialState), gt(t, p.updaterState), et(t, p.state);
143
+ }, mt = (t) => {
144
144
  const c = o.getState().stateComponents.get(t);
145
145
  if (!c) return;
146
146
  const m = /* @__PURE__ */ new Set();
@@ -149,7 +149,7 @@ const ue = (t, c) => {
149
149
  }), queueMicrotask(() => {
150
150
  m.forEach((f) => f());
151
151
  });
152
- }, ge = (t, c) => {
152
+ }, fe = (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,22 +157,22 @@ const ue = (t, c) => {
157
157
  return;
158
158
  y && y.forceUpdate();
159
159
  }
160
- }, Jt = (t, c, m, f) => {
160
+ }, Yt = (t, c, m, f) => {
161
161
  switch (t) {
162
162
  case "update":
163
163
  return {
164
- oldValue: z(c, f),
165
- newValue: z(m, f)
164
+ oldValue: J(c, f),
165
+ newValue: J(m, f)
166
166
  };
167
167
  case "insert":
168
168
  return {
169
169
  oldValue: null,
170
170
  // or undefined
171
- newValue: z(m, f)
171
+ newValue: J(m, f)
172
172
  };
173
173
  case "cut":
174
174
  return {
175
- oldValue: z(c, f),
175
+ oldValue: J(c, f),
176
176
  newValue: null
177
177
  // or undefined
178
178
  };
@@ -180,12 +180,12 @@ const ue = (t, c) => {
180
180
  return { oldValue: null, newValue: null };
181
181
  }
182
182
  };
183
- function Yt(t, {
183
+ function Zt(t, {
184
184
  stateKey: c,
185
185
  serverSync: m,
186
186
  localStorage: f,
187
187
  formElements: y,
188
- reactiveDeps: b,
188
+ reactiveDeps: k,
189
189
  reactiveType: p,
190
190
  componentId: I,
191
191
  initialState: a,
@@ -193,12 +193,12 @@ function Yt(t, {
193
193
  dependencies: n,
194
194
  serverState: S
195
195
  } = {}) {
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(
196
+ const [L, R] = tt({}), { sessionId: F } = Vt();
197
+ let H = !c;
198
+ const [h] = tt(c ?? Tt()), l = o.getState().stateLog[h], ct = q(/* @__PURE__ */ new Set()), X = q(I ?? Tt()), j = q(
199
199
  null
200
200
  );
201
- j.current = nt(h) ?? null, at(() => {
201
+ j.current = nt(h) ?? null, st(() => {
202
202
  if (v && v.stateKey === h && v.path?.[0]) {
203
203
  et(h, (r) => ({
204
204
  ...r,
@@ -210,49 +210,49 @@ function Yt(t, {
210
210
  userId: v.userId
211
211
  });
212
212
  }
213
- }, [v]), at(() => {
213
+ }, [v]), st(() => {
214
214
  if (a) {
215
- $t(h, {
215
+ bt(h, {
216
216
  initialState: a
217
217
  });
218
218
  const e = j.current, s = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, i = o.getState().initialStateGlobal[h];
219
- if (!(i && !H(i, a) || !i) && !s)
219
+ if (!(i && !B(i, a) || !i) && !s)
220
220
  return;
221
221
  let g = null;
222
- const A = Y(e?.localStorage?.key) ? e?.localStorage?.key(a) : e?.localStorage?.key;
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(
222
+ const A = Z(e?.localStorage?.key) ? e?.localStorage?.key(a) : e?.localStorage?.key;
223
+ A && F && (g = St(`${F}-${h}-${A}`));
224
+ let w = a, E = !1;
225
+ const N = s ? Date.now() : 0, C = g?.lastUpdated || 0, M = g?.lastSyncedWithServer || 0;
226
+ s && N > C ? (w = e.serverState.data, E = !0) : g && C > M && (w = g.state, e?.localStorage?.onChange && e?.localStorage?.onChange(w)), o.getState().initializeShadowState(h, a), Pt(
227
227
  h,
228
228
  a,
229
229
  w,
230
230
  rt,
231
- Z.current,
232
- U
233
- ), T && A && U && kt(w, h, e, U, Date.now()), St(h), (Array.isArray(p) ? p : [p || "component"]).includes("none") || R({});
231
+ X.current,
232
+ F
233
+ ), E && A && F && Ct(w, h, e, F, Date.now()), mt(h), (Array.isArray(p) ? p : [p || "component"]).includes("none") || R({});
234
234
  }
235
235
  }, [
236
236
  a,
237
237
  S?.status,
238
238
  S?.data,
239
239
  ...n || []
240
- ]), dt(() => {
241
- G && $t(h, {
240
+ ]), at(() => {
241
+ H && bt(h, {
242
242
  serverSync: m,
243
243
  formElements: y,
244
244
  initialState: a,
245
245
  localStorage: f,
246
246
  middleware: j.current?.middleware
247
247
  });
248
- const e = `${h}////${Z.current}`, r = o.getState().stateComponents.get(h) || {
248
+ const e = `${h}////${X.current}`, r = o.getState().stateComponents.get(h) || {
249
249
  components: /* @__PURE__ */ new Map()
250
250
  };
251
251
  return r.components.set(e, {
252
252
  forceUpdate: () => R({}),
253
253
  paths: /* @__PURE__ */ new Set(),
254
254
  deps: [],
255
- depsFunction: b || void 0,
255
+ depsFunction: k || void 0,
256
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));
@@ -261,121 +261,121 @@ function Yt(t, {
261
261
  const rt = (e, r, s, i) => {
262
262
  if (Array.isArray(r)) {
263
263
  const g = `${h}-${r.join(".")}`;
264
- it.current.add(g);
264
+ ct.current.add(g);
265
265
  }
266
266
  const u = o.getState();
267
267
  et(h, (g) => {
268
- const A = Y(e) ? e(g) : e, w = `${h}-${r.join(".")}`;
268
+ const A = Z(e) ? e(g) : e, w = `${h}-${r.join(".")}`;
269
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
- const O = r.slice(0, -1), D = z(A, O);
273
- if (Array.isArray(D)) {
270
+ let V = !1, $ = u.signalDomElements.get(w);
271
+ if ((!$ || $.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
272
+ const O = r.slice(0, -1), W = J(A, O);
273
+ if (Array.isArray(W)) {
274
274
  V = !0;
275
- const $ = `${h}-${O.join(".")}`;
276
- k = u.signalDomElements.get($);
275
+ const b = `${h}-${O.join(".")}`;
276
+ $ = u.signalDomElements.get(b);
277
277
  }
278
278
  }
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
- `[data-parent-id="${D}"]`
279
+ if ($) {
280
+ const O = V ? J(A, r.slice(0, -1)) : J(A, r);
281
+ $.forEach(({ parentId: W, position: b, effect: U }) => {
282
+ const T = document.querySelector(
283
+ `[data-parent-id="${W}"]`
284
284
  );
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);
285
+ if (T) {
286
+ const x = Array.from(T.childNodes);
287
+ if (x[b]) {
288
+ const P = U ? new Function("state", `return (${U})(state)`)(O) : O;
289
+ x[b].textContent = String(P);
290
290
  }
291
291
  }
292
292
  });
293
293
  }
294
294
  }
295
- console.log("shadowState", u.shadowStateStore), s.updateType === "update" && (i || j.current?.validation?.key) && r && J(
295
+ console.log("shadowState", u.shadowStateStore), s.updateType === "update" && (i || j.current?.validation?.key) && r && Y(
296
296
  (i || j.current?.validation?.key) + "." + r.join(".")
297
297
  );
298
- const T = r.slice(0, r.length - 1);
299
- s.updateType === "cut" && j.current?.validation?.key && J(
300
- j.current?.validation?.key + "." + T.join(".")
301
- ), s.updateType === "insert" && j.current?.validation?.key && Lt(
302
- j.current?.validation?.key + "." + T.join(".")
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);
298
+ const E = r.slice(0, r.length - 1);
299
+ s.updateType === "cut" && j.current?.validation?.key && Y(
300
+ j.current?.validation?.key + "." + E.join(".")
301
+ ), s.updateType === "insert" && j.current?.validation?.key && Ht(
302
+ j.current?.validation?.key + "." + E.join(".")
303
+ ).filter(([$, O]) => {
304
+ let W = $?.split(".").length;
305
+ if ($ == E.join(".") && W == E.length - 1) {
306
+ let b = $ + "." + E;
307
+ Y($), Bt(b, O);
308
308
  }
309
309
  });
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(".") || "";
310
+ const N = u.stateComponents.get(h);
311
+ if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", N), N) {
312
+ const V = wt(g, A), $ = new Set(V), O = s.updateType === "update" ? r.join(".") : r.slice(0, -1).join(".") || "";
313
313
  for (const [
314
- D,
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();
314
+ W,
315
+ b
316
+ ] of N.components.entries()) {
317
+ let U = !1;
318
+ const T = Array.isArray(b.reactiveType) ? b.reactiveType : [b.reactiveType || "component"];
319
+ if (console.log("component", b), !T.includes("none")) {
320
+ if (T.includes("all")) {
321
+ b.forceUpdate();
322
322
  continue;
323
323
  }
324
- if (N.includes("component") && (($.paths.has(O) || $.paths.has("")) && (E = !0), !E))
325
- for (const F of k) {
326
- let x = F;
324
+ if (T.includes("component") && ((b.paths.has(O) || b.paths.has("")) && (U = !0), !U))
325
+ for (const x of $) {
326
+ let P = x;
327
327
  for (; ; ) {
328
- if ($.paths.has(x)) {
329
- E = !0;
328
+ if (b.paths.has(P)) {
329
+ U = !0;
330
330
  break;
331
331
  }
332
- const L = x.lastIndexOf(".");
333
- if (L !== -1) {
334
- const X = x.substring(
332
+ const G = P.lastIndexOf(".");
333
+ if (G !== -1) {
334
+ const z = P.substring(
335
335
  0,
336
- L
336
+ G
337
337
  );
338
338
  if (!isNaN(
339
- Number(x.substring(L + 1))
340
- ) && $.paths.has(X)) {
341
- E = !0;
339
+ Number(P.substring(G + 1))
340
+ ) && b.paths.has(z)) {
341
+ U = !0;
342
342
  break;
343
343
  }
344
- x = X;
344
+ P = z;
345
345
  } else
346
- x = "";
347
- if (x === "")
346
+ P = "";
347
+ if (P === "")
348
348
  break;
349
349
  }
350
- if (E) break;
350
+ if (U) break;
351
351
  }
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);
352
+ if (!U && T.includes("deps") && b.depsFunction) {
353
+ const x = b.depsFunction(A);
354
+ let P = !1;
355
+ typeof x == "boolean" ? x && (P = !0) : B(b.deps, x) || (b.deps = x, P = !0), P && (U = !0);
356
356
  }
357
- E && $.forceUpdate();
357
+ U && b.forceUpdate();
358
358
  }
359
359
  }
360
360
  }
361
361
  const C = Date.now();
362
- r = r.map((V, k) => {
363
- const O = r.slice(0, -1), D = z(A, O);
364
- return k === r.length - 1 && ["insert", "cut"].includes(s.updateType) ? (D.length - 1).toString() : V;
362
+ r = r.map((V, $) => {
363
+ const O = r.slice(0, -1), W = J(A, O);
364
+ return $ === r.length - 1 && ["insert", "cut"].includes(s.updateType) ? (W.length - 1).toString() : V;
365
365
  });
366
- const { oldValue: M, newValue: P } = Jt(
366
+ const { oldValue: M, newValue: D } = Yt(
367
367
  s.updateType,
368
368
  g,
369
369
  A,
370
370
  r
371
- ), q = {
371
+ ), _ = {
372
372
  timeStamp: C,
373
373
  stateKey: h,
374
374
  path: r,
375
375
  updateType: s.updateType,
376
376
  status: "new",
377
377
  oldValue: M,
378
- newValue: P
378
+ newValue: D
379
379
  };
380
380
  switch (s.updateType) {
381
381
  case "update":
@@ -383,96 +383,96 @@ function Yt(t, {
383
383
  break;
384
384
  case "insert":
385
385
  const V = r.slice(0, -1);
386
- u.insertShadowArrayElement(h, V, P);
386
+ u.insertShadowArrayElement(h, V, D);
387
387
  break;
388
388
  case "cut":
389
- const k = r.slice(0, -1), O = parseInt(r[r.length - 1]);
390
- u.removeShadowArrayElement(h, k, O);
389
+ const $ = r.slice(0, -1), O = parseInt(r[r.length - 1]);
390
+ u.removeShadowArrayElement(h, $, O);
391
391
  break;
392
392
  }
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;
393
+ if (zt(h, (V) => {
394
+ const O = [...V ?? [], _].reduce((W, b) => {
395
+ const U = `${b.stateKey}:${JSON.stringify(b.path)}`, T = W.get(U);
396
+ return T ? (T.timeStamp = Math.max(T.timeStamp, b.timeStamp), T.newValue = b.newValue, T.oldValue = T.oldValue ?? b.oldValue, T.updateType = b.updateType) : W.set(U, { ...b }), W;
397
397
  }, /* @__PURE__ */ new Map());
398
398
  return Array.from(O.values());
399
- }), kt(
399
+ }), Ct(
400
400
  A,
401
401
  h,
402
402
  j.current,
403
- U
403
+ F
404
404
  ), j.current?.middleware && j.current.middleware({
405
405
  updateLog: l,
406
- update: q
406
+ update: _
407
407
  }), j.current?.serverSync) {
408
- const V = u.serverState[h], k = j.current?.serverSync;
408
+ const V = u.serverState[h], $ = j.current?.serverSync;
409
409
  qt(h, {
410
- syncKey: typeof k.syncKey == "string" ? k.syncKey : k.syncKey({ state: A }),
410
+ syncKey: typeof $.syncKey == "string" ? $.syncKey : $.syncKey({ state: A }),
411
411
  rollBackState: V,
412
- actionTimeStamp: Date.now() + (k.debounce ?? 3e3),
412
+ actionTimeStamp: Date.now() + ($.debounce ?? 3e3),
413
413
  status: "waiting"
414
414
  });
415
415
  }
416
416
  return A;
417
417
  });
418
418
  };
419
- o.getState().updaterState[h] || (ut(
419
+ o.getState().updaterState[h] || (gt(
420
420
  h,
421
- gt(
421
+ ft(
422
422
  h,
423
423
  rt,
424
- Z.current,
425
- U
424
+ X.current,
425
+ F
426
426
  )
427
427
  ), o.getState().cogsStateStore[h] || et(h, t), o.getState().initialStateGlobal[h] || At(h, t));
428
- const d = It(() => gt(
428
+ const d = pt(() => ft(
429
429
  h,
430
430
  rt,
431
- Z.current,
432
- U
433
- ), [h, U]);
434
- return [Vt(h), d];
431
+ X.current,
432
+ F
433
+ ), [h, F]);
434
+ return [xt(h), d];
435
435
  }
436
- function gt(t, c, m, f) {
436
+ function ft(t, c, m, f) {
437
437
  const y = /* @__PURE__ */ new Map();
438
- let b = 0;
438
+ let k = 0;
439
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
- b++;
443
+ k++;
444
444
  }, I = {
445
445
  removeValidation: (v) => {
446
- v?.validationKey && J(v.validationKey);
446
+ v?.validationKey && Y(v.validationKey);
447
447
  },
448
448
  revertToInitialState: (v) => {
449
449
  const n = o.getState().getInitialOptions(t)?.validation;
450
- n?.key && J(n?.key), v?.validationKey && J(v.validationKey);
450
+ n?.key && Y(n?.key), v?.validationKey && Y(v.validationKey);
451
451
  const S = o.getState().initialStateGlobal[t];
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);
452
+ o.getState().clearSelectedIndexesForState(t), y.clear(), k++;
453
+ const L = a(S, []), R = nt(t), F = Z(R?.localStorage?.key) ? R?.localStorage?.key(S) : R?.localStorage?.key, H = `${f}-${t}-${F}`;
454
+ H && localStorage.removeItem(H), gt(t, L), 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(), b++;
462
- const n = gt(
461
+ y.clear(), k++;
462
+ const n = ft(
463
463
  t,
464
464
  c,
465
465
  m,
466
466
  f
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) => {
467
+ ), S = o.getState().initialStateGlobal[t], L = nt(t), R = Z(L?.localStorage?.key) ? L?.localStorage?.key(S) : L?.localStorage?.key, F = `${f}-${t}-${R}`;
468
+ return localStorage.getItem(F) && localStorage.removeItem(F), Ot(() => {
469
+ At(t, v), o.getState().initializeShadowState(t, v), gt(t, n), et(t, v);
470
+ const H = o.getState().stateComponents.get(t);
471
+ H && H.components.forEach((h) => {
472
472
  h.forceUpdate();
473
473
  });
474
474
  }), {
475
- fetchId: (G) => n.get()[G]
475
+ fetchId: (H) => n.get()[H]
476
476
  };
477
477
  },
478
478
  _initialState: o.getState().initialStateGlobal[t],
@@ -480,27 +480,27 @@ function gt(t, c, m, f) {
480
480
  _isLoading: o.getState().isLoadingGlobal[t],
481
481
  _isServerSynced: () => {
482
482
  const v = o.getState().serverState[t];
483
- return !!(v && H(v, Vt(t)));
483
+ return !!(v && B(v, xt(t)));
484
484
  }
485
485
  };
486
486
  function a(v, n = [], S) {
487
- const W = n.map(String).join(".");
488
- y.get(W);
487
+ const L = n.map(String).join(".");
488
+ y.get(L);
489
489
  const R = function() {
490
490
  return o().getNestedState(t, n);
491
491
  };
492
492
  Object.keys(I).forEach((h) => {
493
493
  R[h] = I[h];
494
494
  });
495
- const U = {
496
- apply(h, l, it) {
495
+ const F = {
496
+ apply(h, l, ct) {
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 it = /* @__PURE__ */ new Set([
503
+ const ct = /* @__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" && !it.has(l)) {
526
+ if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !ct.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);
@@ -540,7 +540,7 @@ function gt(t, c, m, f) {
540
540
  }
541
541
  }
542
542
  if (l === "getDifferences")
543
- return () => pt(
543
+ return () => wt(
544
544
  o.getState().cogsStateStore[t],
545
545
  o.getState().initialStateGlobal[t]
546
546
  );
@@ -568,20 +568,20 @@ function gt(t, c, m, f) {
568
568
  }
569
569
  };
570
570
  if (l === "_status") {
571
- const d = o.getState().getNestedState(t, n), e = o.getState().initialStateGlobal[t], r = z(e, n);
572
- return H(d, r) ? "fresh" : "stale";
571
+ const d = o.getState().getNestedState(t, n), e = o.getState().initialStateGlobal[t], r = J(e, n);
572
+ return B(d, r) ? "fresh" : "stale";
573
573
  }
574
574
  if (l === "getStatus")
575
575
  return function() {
576
576
  const d = o().getNestedState(
577
577
  t,
578
578
  n
579
- ), e = o.getState().initialStateGlobal[t], r = z(e, n);
580
- return H(d, r) ? "fresh" : "stale";
579
+ ), e = o.getState().initialStateGlobal[t], r = J(e, n);
580
+ return B(d, r) ? "fresh" : "stale";
581
581
  };
582
582
  if (l === "removeStorage")
583
583
  return () => {
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}`;
584
+ const d = o.getState().initialStateGlobal[t], e = nt(t), r = Z(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,108 +621,116 @@ 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] = tt({
624
+ } = e, u = q(null), [g, A] = tt({
625
625
  startIndex: 0,
626
626
  endIndex: 10
627
- }), [, w] = tt({}), T = B(i), _ = B(0), C = B(!0);
628
- at(() => o.getState().subscribeToShadowState(t, () => w({})), [t]);
629
- const M = o().getNestedState(
627
+ }), [, w] = tt({}), E = q(i), N = q(0), C = q(!0), M = q(0);
628
+ st(() => o.getState().subscribeToShadowState(t, () => w({})), [t]);
629
+ const D = o().getNestedState(
630
630
  t,
631
631
  n
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;
632
+ ), _ = D.length, { totalHeight: V, positions: $ } = pt(() => {
633
+ const T = o.getState().getShadowMetadata(t, n) || [];
634
+ let x = 0;
635
+ const P = [];
636
+ for (let G = 0; G < _; G++) {
637
+ P[G] = x;
638
+ const z = T[G]?.virtualizer?.itemHeight;
639
+ x += z || r;
640
640
  }
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, {
641
+ return { totalHeight: x, positions: P };
642
+ }, [_, t, n.join("."), r]);
643
+ at(() => {
644
+ const T = u.current;
645
+ if (!T) return;
646
+ const x = V !== M.current;
647
+ M.current = V, x && E.current && !C.current && T.scrollTo({
648
+ top: T.scrollHeight,
649
+ behavior: "auto"
650
+ });
651
+ }, [V]);
652
+ const O = pt(() => {
653
+ const T = Math.max(0, g.startIndex), x = Math.min(_, g.endIndex), P = Array.from(
654
+ { length: x - T },
655
+ (z, lt) => T + lt
656
+ ), G = P.map((z) => D[z]);
657
+ return a(G, n, {
648
658
  ...S,
649
- validIndices: F
659
+ validIndices: P
650
660
  });
651
- }, [g.startIndex, g.endIndex, M, P]);
652
- dt(() => {
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;
661
+ }, [g.startIndex, g.endIndex, D, _]);
662
+ at(() => {
663
+ const T = u.current;
664
+ if (!T) return;
665
+ const x = E.current, P = _ > N.current;
666
+ N.current = _;
667
+ const G = () => {
668
+ const { scrollTop: z, clientHeight: lt, scrollHeight: _t } = T;
669
+ E.current = _t - z - lt < 10;
670
+ let ht = 0, dt = _ - 1;
671
+ for (; ht <= dt; ) {
672
+ const K = Math.floor((ht + dt) / 2);
673
+ $[K] < z ? ht = K + 1 : dt = K - 1;
664
674
  }
665
- const ht = Math.max(0, ct - s);
666
- let Q = ht;
667
- const _t = L + X;
668
- for (; Q < P && V[Q] < _t; )
675
+ const vt = Math.max(0, dt - s);
676
+ let Q = vt;
677
+ const Mt = z + lt;
678
+ for (; Q < _ && $[Q] < Mt; )
669
679
  Q++;
670
- Q = Math.min(P, Q + s), A((K) => K.startIndex !== ht || K.endIndex !== Q ? { startIndex: ht, endIndex: Q } : K);
680
+ Q = Math.min(_, Q + s), A((K) => K.startIndex !== vt || K.endIndex !== Q ? { startIndex: vt, endIndex: Q } : K);
671
681
  };
672
- return E.addEventListener("scroll", x, {
682
+ return T.addEventListener("scroll", G, {
673
683
  passive: !0
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);
680
- });
681
- }) : !C.current && N && F && requestAnimationFrame(() => {
682
- E.scrollTo({
683
- top: E.scrollHeight,
684
+ }), i && C.current && _ > 0 ? (E.current = !0, requestAnimationFrame(() => {
685
+ u.current && (u.current.scrollTo({
686
+ top: u.current.scrollHeight,
687
+ behavior: "auto"
688
+ }), C.current = !1);
689
+ })) : !C.current && x && P && requestAnimationFrame(() => {
690
+ T.scrollTo({
691
+ top: T.scrollHeight,
684
692
  behavior: "smooth"
685
693
  });
686
- })), x(), () => E.removeEventListener("scroll", x);
687
- }, [P, V, s, i]);
688
- const O = Et(
689
- (E = "smooth") => {
694
+ }), G(), () => T.removeEventListener("scroll", G);
695
+ }, [_, $, s, i]);
696
+ const W = Et(
697
+ (T = "smooth") => {
690
698
  u.current && u.current.scrollTo({
691
699
  top: u.current.scrollHeight,
692
- behavior: E
700
+ behavior: T
693
701
  });
694
702
  },
695
703
  []
696
- ), D = Et(
697
- (E, N = "smooth") => {
698
- u.current && V[E] !== void 0 && u.current.scrollTo({
699
- top: V[E],
700
- behavior: N
704
+ ), b = Et(
705
+ (T, x = "smooth") => {
706
+ u.current && $[T] !== void 0 && u.current.scrollTo({
707
+ top: $[T],
708
+ behavior: x
701
709
  });
702
710
  },
703
- [V]
704
- ), $ = {
711
+ [$]
712
+ ), U = {
705
713
  outer: {
706
714
  ref: u,
707
715
  style: { overflowY: "auto", height: "100%" }
708
716
  },
709
717
  inner: {
710
718
  style: {
711
- height: `${q}px`,
719
+ height: `${V}px`,
712
720
  position: "relative"
713
721
  }
714
722
  },
715
723
  list: {
716
724
  style: {
717
- transform: `translateY(${V[g.startIndex] || 0}px)`
725
+ transform: `translateY(${$[g.startIndex] || 0}px)`
718
726
  }
719
727
  }
720
728
  };
721
729
  return {
722
- virtualState: k,
723
- virtualizerProps: $,
724
- scrollToBottom: O,
725
- scrollToIndex: D
730
+ virtualState: O,
731
+ virtualizerProps: U,
732
+ scrollToBottom: W,
733
+ scrollToIndex: b
726
734
  };
727
735
  };
728
736
  if (l === "stateSort")
@@ -756,17 +764,17 @@ function gt(t, c, m, f) {
756
764
  const g = r[i], A = [...n, i.toString()], w = a(g, A, S);
757
765
  return e(g, w, {
758
766
  register: () => {
759
- const [, _] = tt({}), C = `${m}-${n.join(".")}-${i}`;
760
- dt(() => {
761
- const M = `${t}////${C}`, P = o.getState().stateComponents.get(t) || {
767
+ const [, N] = tt({}), C = `${m}-${n.join(".")}-${i}`;
768
+ at(() => {
769
+ const M = `${t}////${C}`, D = o.getState().stateComponents.get(t) || {
762
770
  components: /* @__PURE__ */ new Map()
763
771
  };
764
- return P.components.set(M, {
765
- forceUpdate: () => _({}),
772
+ return D.components.set(M, {
773
+ forceUpdate: () => N({}),
766
774
  paths: /* @__PURE__ */ new Set([A.join(".")])
767
- }), o.getState().stateComponents.set(t, P), () => {
768
- const q = o.getState().stateComponents.get(t);
769
- q && q.components.delete(M);
775
+ }), o.getState().stateComponents.set(t, D), () => {
776
+ const _ = o.getState().stateComponents.get(t);
777
+ _ && _.components.delete(M);
770
778
  };
771
779
  }, [t, C]);
772
780
  },
@@ -792,7 +800,7 @@ function gt(t, c, m, f) {
792
800
  );
793
801
  });
794
802
  if (l === "$stateMap")
795
- return (e) => st(Zt, {
803
+ return (e) => it(Xt, {
796
804
  proxy: {
797
805
  _stateKey: t,
798
806
  _path: n,
@@ -805,11 +813,11 @@ function gt(t, c, m, f) {
805
813
  return (e) => {
806
814
  const r = o.getState().getNestedState(t, n);
807
815
  return Array.isArray(r) ? (S?.validIndices || Array.from({ length: r.length }, (i, u) => u)).map((i, u) => {
808
- const g = r[i], A = [...n, i.toString()], w = a(g, A, S), T = `${m}-${n.join(".")}-${i}`;
809
- return st(Qt, {
816
+ const g = r[i], A = [...n, i.toString()], w = a(g, A, S), E = `${m}-${n.join(".")}-${i}`;
817
+ return it(Kt, {
810
818
  key: i,
811
819
  stateKey: t,
812
- itemComponentId: T,
820
+ itemComponentId: E,
813
821
  itemPath: A,
814
822
  children: e(
815
823
  g,
@@ -826,7 +834,7 @@ function gt(t, c, m, f) {
826
834
  if (l === "stateFlattenOn")
827
835
  return (e) => {
828
836
  const r = v;
829
- y.clear(), b++;
837
+ y.clear(), k++;
830
838
  const s = r.flatMap(
831
839
  (i) => i[e] ?? []
832
840
  );
@@ -849,36 +857,36 @@ function gt(t, c, m, f) {
849
857
  return a(s, i);
850
858
  };
851
859
  if (l === "insert")
852
- return (e) => (p(n), vt(c, e, n, t), a(
860
+ return (e) => (p(n), yt(c, e, n, t), a(
853
861
  o.getState().getNestedState(t, n),
854
862
  n
855
863
  ));
856
864
  if (l === "uniqueInsert")
857
865
  return (e, r, s) => {
858
- const i = o.getState().getNestedState(t, n), u = Y(e) ? e(i) : e;
866
+ const i = o.getState().getNestedState(t, n), u = Z(e) ? e(i) : e;
859
867
  let g = null;
860
868
  if (!i.some((w) => {
861
869
  if (r) {
862
- const _ = r.every(
863
- (C) => H(w[C], u[C])
870
+ const N = r.every(
871
+ (C) => B(w[C], u[C])
864
872
  );
865
- return _ && (g = w), _;
873
+ return N && (g = w), N;
866
874
  }
867
- const T = H(w, u);
868
- return T && (g = w), T;
875
+ const E = B(w, u);
876
+ return E && (g = w), E;
869
877
  }))
870
- p(n), vt(c, u, n, t);
878
+ p(n), yt(c, u, n, t);
871
879
  else if (s && g) {
872
- const w = s(g), T = i.map(
873
- (_) => H(_, g) ? w : _
880
+ const w = s(g), E = i.map(
881
+ (N) => B(N, g) ? w : N
874
882
  );
875
- p(n), ot(c, T, n);
883
+ p(n), ot(c, E, n);
876
884
  }
877
885
  };
878
886
  if (l === "cut")
879
887
  return (e, r) => {
880
888
  if (!r?.waitForSync)
881
- return p(n), lt(c, n, t, e), a(
889
+ return p(n), ut(c, n, t, e), a(
882
890
  o.getState().getNestedState(t, n),
883
891
  n
884
892
  );
@@ -886,12 +894,12 @@ function gt(t, c, m, f) {
886
894
  if (l === "cutByValue")
887
895
  return (e) => {
888
896
  for (let r = 0; r < v.length; r++)
889
- v[r] === e && lt(c, n, t, r);
897
+ v[r] === e && ut(c, n, t, r);
890
898
  };
891
899
  if (l === "toggleByValue")
892
900
  return (e) => {
893
901
  const r = v.findIndex((s) => s === e);
894
- r > -1 ? lt(c, n, t, r) : vt(c, e, n, t);
902
+ r > -1 ? ut(c, n, t, r) : yt(c, e, n, t);
895
903
  };
896
904
  if (l === "stateFind")
897
905
  return (e) => {
@@ -912,15 +920,15 @@ function gt(t, c, m, f) {
912
920
  return a(i.item, u, S);
913
921
  };
914
922
  }
915
- const Z = n[n.length - 1];
916
- if (!isNaN(Number(Z))) {
923
+ const X = n[n.length - 1];
924
+ if (!isNaN(Number(X))) {
917
925
  const d = n.slice(0, -1), e = o.getState().getNestedState(t, d);
918
926
  if (Array.isArray(e) && l === "cut")
919
- return () => lt(
927
+ return () => ut(
920
928
  c,
921
929
  d,
922
930
  t,
923
- Number(Z)
931
+ Number(X)
924
932
  );
925
933
  }
926
934
  if (l === "get")
@@ -947,7 +955,7 @@ function gt(t, c, m, f) {
947
955
  return o.getState().getSyncInfo(d);
948
956
  }
949
957
  if (l == "getLocalStorage")
950
- return (d) => ft(f + "-" + t + "-" + d);
958
+ return (d) => St(f + "-" + t + "-" + d);
951
959
  if (l === "_selected") {
952
960
  const d = n.slice(0, -1), e = d.join("."), r = o.getState().getNestedState(t, d);
953
961
  return Array.isArray(r) ? Number(n[n.length - 1]) === o.getState().getSelectedIndex(t, e) : void 0;
@@ -973,8 +981,8 @@ function gt(t, c, m, f) {
973
981
  if (n.length == 0) {
974
982
  if (l === "applyJsonPatch")
975
983
  return (d) => {
976
- const e = o.getState().cogsStateStore[t], s = Wt(e, d).newDocument;
977
- xt(
984
+ const e = o.getState().cogsStateStore[t], s = Gt(e, d).newDocument;
985
+ Pt(
978
986
  t,
979
987
  o.getState().initialStateGlobal[t],
980
988
  s,
@@ -984,57 +992,57 @@ function gt(t, c, m, f) {
984
992
  );
985
993
  const i = o.getState().stateComponents.get(t);
986
994
  if (i) {
987
- const u = pt(e, s), g = new Set(u);
995
+ const u = wt(e, s), g = new Set(u);
988
996
  for (const [
989
997
  A,
990
998
  w
991
999
  ] of i.components.entries()) {
992
- let T = !1;
993
- const _ = Array.isArray(w.reactiveType) ? w.reactiveType : [w.reactiveType || "component"];
994
- if (!_.includes("none")) {
995
- if (_.includes("all")) {
1000
+ let E = !1;
1001
+ const N = Array.isArray(w.reactiveType) ? w.reactiveType : [w.reactiveType || "component"];
1002
+ if (!N.includes("none")) {
1003
+ if (N.includes("all")) {
996
1004
  w.forceUpdate();
997
1005
  continue;
998
1006
  }
999
- if (_.includes("component") && (w.paths.has("") && (T = !0), !T))
1007
+ if (N.includes("component") && (w.paths.has("") && (E = !0), !E))
1000
1008
  for (const C of g) {
1001
1009
  if (w.paths.has(C)) {
1002
- T = !0;
1010
+ E = !0;
1003
1011
  break;
1004
1012
  }
1005
1013
  let M = C.lastIndexOf(".");
1006
1014
  for (; M !== -1; ) {
1007
- const P = C.substring(0, M);
1008
- if (w.paths.has(P)) {
1009
- T = !0;
1015
+ const D = C.substring(0, M);
1016
+ if (w.paths.has(D)) {
1017
+ E = !0;
1010
1018
  break;
1011
1019
  }
1012
- const q = C.substring(
1020
+ const _ = C.substring(
1013
1021
  M + 1
1014
1022
  );
1015
- if (!isNaN(Number(q))) {
1016
- const V = P.lastIndexOf(".");
1023
+ if (!isNaN(Number(_))) {
1024
+ const V = D.lastIndexOf(".");
1017
1025
  if (V !== -1) {
1018
- const k = P.substring(
1026
+ const $ = D.substring(
1019
1027
  0,
1020
1028
  V
1021
1029
  );
1022
- if (w.paths.has(k)) {
1023
- T = !0;
1030
+ if (w.paths.has($)) {
1031
+ E = !0;
1024
1032
  break;
1025
1033
  }
1026
1034
  }
1027
1035
  }
1028
- M = P.lastIndexOf(".");
1036
+ M = D.lastIndexOf(".");
1029
1037
  }
1030
- if (T) break;
1038
+ if (E) break;
1031
1039
  }
1032
- if (!T && _.includes("deps") && w.depsFunction) {
1040
+ if (!E && N.includes("deps") && w.depsFunction) {
1033
1041
  const C = w.depsFunction(s);
1034
1042
  let M = !1;
1035
- typeof C == "boolean" ? C && (M = !0) : H(w.deps, C) || (w.deps = C, M = !0), M && (T = !0);
1043
+ typeof C == "boolean" ? C && (M = !0) : B(w.deps, C) || (w.deps = C, M = !0), M && (E = !0);
1036
1044
  }
1037
- T && w.forceUpdate();
1045
+ E && w.forceUpdate();
1038
1046
  }
1039
1047
  }
1040
1048
  }
@@ -1046,18 +1054,18 @@ function gt(t, c, m, f) {
1046
1054
  throw new Error("Zod schema not found");
1047
1055
  if (!d?.key)
1048
1056
  throw new Error("Validation key not found");
1049
- J(d.key);
1057
+ Y(d.key);
1050
1058
  const r = o.getState().cogsStateStore[t];
1051
1059
  try {
1052
1060
  const s = o.getState().getValidationErrors(d.key);
1053
1061
  s && s.length > 0 && s.forEach(([u]) => {
1054
- u && u.startsWith(d.key) && J(u);
1062
+ u && u.startsWith(d.key) && Y(u);
1055
1063
  });
1056
1064
  const i = d.zodSchema.safeParse(r);
1057
1065
  return i.success ? !0 : (i.error.errors.forEach((g) => {
1058
- const A = g.path, w = g.message, T = [d.key, ...A].join(".");
1059
- e(T, w);
1060
- }), St(t), !1);
1066
+ const A = g.path, w = g.message, E = [d.key, ...A].join(".");
1067
+ e(E, w);
1068
+ }), mt(t), !1);
1061
1069
  } catch (s) {
1062
1070
  return console.error("Zod schema validation failed", s), !1;
1063
1071
  }
@@ -1066,7 +1074,7 @@ function gt(t, c, m, f) {
1066
1074
  if (l === "getComponents")
1067
1075
  return () => o().stateComponents.get(t);
1068
1076
  if (l === "getAllFormRefs")
1069
- return () => Tt.getState().getFormRefsByStateKey(t);
1077
+ return () => $t.getState().getFormRefsByStateKey(t);
1070
1078
  if (l === "_initialState")
1071
1079
  return o.getState().initialStateGlobal[t];
1072
1080
  if (l === "_serverState")
@@ -1079,13 +1087,13 @@ function gt(t, c, m, f) {
1079
1087
  if (l === "removeValidation") return I.removeValidation;
1080
1088
  }
1081
1089
  if (l === "getFormRef")
1082
- return () => Tt.getState().getFormRef(t + "." + n.join("."));
1090
+ return () => $t.getState().getFormRef(t + "." + n.join("."));
1083
1091
  if (l === "validationWrapper")
1084
1092
  return ({
1085
1093
  children: d,
1086
1094
  hideMessage: e
1087
- }) => /* @__PURE__ */ yt(
1088
- Rt,
1095
+ }) => /* @__PURE__ */ It(
1096
+ Ut,
1089
1097
  {
1090
1098
  formOpts: e ? { validation: { message: "" } } : void 0,
1091
1099
  path: n,
@@ -1114,8 +1122,8 @@ function gt(t, c, m, f) {
1114
1122
  p(n);
1115
1123
  };
1116
1124
  if (l === "formElement")
1117
- return (d, e) => /* @__PURE__ */ yt(
1118
- Ut,
1125
+ return (d, e) => /* @__PURE__ */ It(
1126
+ Dt,
1119
1127
  {
1120
1128
  setState: c,
1121
1129
  stateKey: t,
@@ -1127,20 +1135,20 @@ function gt(t, c, m, f) {
1127
1135
  const j = [...n, l], rt = o.getState().getNestedState(t, j);
1128
1136
  return a(rt, j, S);
1129
1137
  }
1130
- }, G = new Proxy(R, U);
1131
- return y.set(W, {
1132
- proxy: G,
1133
- stateVersion: b
1134
- }), G;
1138
+ }, H = new Proxy(R, F);
1139
+ return y.set(L, {
1140
+ proxy: H,
1141
+ stateVersion: k
1142
+ }), H;
1135
1143
  }
1136
1144
  return a(
1137
1145
  o.getState().getNestedState(t, [])
1138
1146
  );
1139
1147
  }
1140
1148
  function Nt(t) {
1141
- return st(Xt, { proxy: t });
1149
+ return it(Qt, { proxy: t });
1142
1150
  }
1143
- function Zt({
1151
+ function Xt({
1144
1152
  proxy: t,
1145
1153
  rebuildStateShape: c
1146
1154
  }) {
@@ -1149,14 +1157,14 @@ function Zt({
1149
1157
  m,
1150
1158
  t._path
1151
1159
  ).stateMapNoRender(
1152
- (y, b, p, I, a) => t._mapFn(y, b, p, I, a)
1160
+ (y, k, p, I, a) => t._mapFn(y, k, p, I, a)
1153
1161
  ) : null;
1154
1162
  }
1155
- function Xt({
1163
+ function Qt({
1156
1164
  proxy: t
1157
1165
  }) {
1158
- const c = B(null), m = `${t._stateKey}-${t._path.join(".")}`;
1159
- return at(() => {
1166
+ const c = q(null), m = `${t._stateKey}-${t._path.join(".")}`;
1167
+ return st(() => {
1160
1168
  const f = c.current;
1161
1169
  if (!f || !f.parentElement) return;
1162
1170
  const y = f.parentElement, p = Array.from(y.childNodes).indexOf(f);
@@ -1183,16 +1191,16 @@ function Xt({
1183
1191
  else
1184
1192
  S = n;
1185
1193
  S !== null && typeof S == "object" && (S = JSON.stringify(S));
1186
- const W = document.createTextNode(String(S));
1187
- f.replaceWith(W);
1188
- }, [t._stateKey, t._path.join("."), t._effect]), st("span", {
1194
+ const L = document.createTextNode(String(S));
1195
+ f.replaceWith(L);
1196
+ }, [t._stateKey, t._path.join("."), t._effect]), it("span", {
1189
1197
  ref: c,
1190
1198
  style: { display: "none" },
1191
1199
  "data-signal-id": m
1192
1200
  });
1193
1201
  }
1194
- function fe(t) {
1195
- const c = Mt(
1202
+ function Se(t) {
1203
+ const c = jt(
1196
1204
  (m) => {
1197
1205
  const f = o.getState().stateComponents.get(t._stateKey) || {
1198
1206
  components: /* @__PURE__ */ new Map()
@@ -1204,22 +1212,22 @@ function fe(t) {
1204
1212
  },
1205
1213
  () => o.getState().getNestedState(t._stateKey, t._path)
1206
1214
  );
1207
- return st("text", {}, String(c));
1215
+ return it("text", {}, String(c));
1208
1216
  }
1209
- function Qt({
1217
+ function Kt({
1210
1218
  stateKey: t,
1211
1219
  itemComponentId: c,
1212
1220
  itemPath: m,
1213
1221
  children: f
1214
1222
  }) {
1215
- const [, y] = tt({}), [b, p] = Gt(), I = B(null);
1216
- return at(() => {
1223
+ const [, y] = tt({}), [k, p] = Lt(), I = q(null);
1224
+ return st(() => {
1217
1225
  p.height > 0 && p.height !== I.current && (I.current = p.height, o.getState().setShadowMetadata(t, m, {
1218
1226
  virtualizer: {
1219
1227
  itemHeight: p.height
1220
1228
  }
1221
1229
  }));
1222
- }, [p.height, t, m]), dt(() => {
1230
+ }, [p.height, t, m]), at(() => {
1223
1231
  const a = `${t}////${c}`, v = o.getState().stateComponents.get(t) || {
1224
1232
  components: /* @__PURE__ */ new Map()
1225
1233
  };
@@ -1230,14 +1238,14 @@ function Qt({
1230
1238
  const n = o.getState().stateComponents.get(t);
1231
1239
  n && n.components.delete(a);
1232
1240
  };
1233
- }, [t, c, m.join(".")]), /* @__PURE__ */ yt("div", { ref: b, children: f });
1241
+ }, [t, c, m.join(".")]), /* @__PURE__ */ It("div", { ref: k, children: f });
1234
1242
  }
1235
1243
  export {
1236
1244
  Nt as $cogsSignal,
1237
- fe as $cogsSignalStore,
1238
- de as addStateOptions,
1239
- ue as createCogsState,
1240
- ge as notifyComponent,
1241
- Yt as useCogsStateFn
1245
+ Se as $cogsSignalStore,
1246
+ ue as addStateOptions,
1247
+ ge as createCogsState,
1248
+ fe as notifyComponent,
1249
+ Zt as useCogsStateFn
1242
1250
  };
1243
1251
  //# sourceMappingURL=CogsState.jsx.map