cogsbox-state 0.5.241 → 0.5.242

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,14 +1,14 @@
1
1
  "use client";
2
2
  import { jsx as fe } from "react/jsx-runtime";
3
- import { useState as te, useRef as ee, useEffect as ce, useLayoutEffect as Ie, useMemo as $e, createElement as oe, useSyncExternalStore as Ae, startTransition as Ne } from "react";
4
- import { transformStateFunc as Ve, isDeepEqual as G, isFunction as z, getNestedValue as W, getDifferences as le, debounce as ke } from "./utility.js";
5
- import { pushFunc as se, updateFn as X, cutFunc as K, ValidationWrapper as Ce, FormControlComponent as _e } from "./Functions.jsx";
6
- import Pe from "superjson";
3
+ import { useState as se, useRef as ee, useEffect as ce, useLayoutEffect as we, useMemo as Ee, createElement as re, useSyncExternalStore as $e, startTransition as Ae } from "react";
4
+ import { transformStateFunc as Ne, isDeepEqual as M, isFunction as z, getNestedValue as G, getDifferences as le, debounce as Ve } from "./utility.js";
5
+ import { pushFunc as ie, updateFn as X, cutFunc as K, ValidationWrapper as ke, FormControlComponent as _e } from "./Functions.jsx";
6
+ import Ce from "superjson";
7
7
  import { v4 as de } from "uuid";
8
8
  import "zod";
9
9
  import { getGlobalStore as n, formRefStore as Se } from "./store.js";
10
- import { useCogsConfig as Te } from "./CogsStateClient.jsx";
11
- import { applyPatch as xe } from "fast-json-patch";
10
+ import { useCogsConfig as pe } from "./CogsStateClient.jsx";
11
+ import { applyPatch as Pe } from "fast-json-patch";
12
12
  function me(e, i) {
13
13
  const S = n.getState().getInitialOptions, l = n.getState().setInitialStateOptions, c = S(e) || {};
14
14
  l(e, {
@@ -21,42 +21,42 @@ function ye({
21
21
  options: i,
22
22
  initialOptionsPart: S
23
23
  }) {
24
- const l = Z(e) || {}, c = S[e] || {}, b = n.getState().setInitialStateOptions, I = { ...c, ...l };
25
- let h = !1;
24
+ const l = Z(e) || {}, c = S[e] || {}, b = n.getState().setInitialStateOptions, p = { ...c, ...l };
25
+ let I = !1;
26
26
  if (i)
27
27
  for (const s in i)
28
- I.hasOwnProperty(s) ? (s == "localStorage" && i[s] && I[s].key !== i[s]?.key && (h = !0, I[s] = i[s]), s == "initialState" && i[s] && I[s] !== i[s] && // Different references
29
- !G(I[s], i[s]) && (h = !0, I[s] = i[s])) : (h = !0, I[s] = i[s]);
30
- h && b(e, I);
28
+ p.hasOwnProperty(s) ? (s == "localStorage" && i[s] && p[s].key !== i[s]?.key && (I = !0, p[s] = i[s]), s == "initialState" && i[s] && p[s] !== i[s] && // Different references
29
+ !M(p[s], i[s]) && (I = !0, p[s] = i[s])) : (I = !0, p[s] = i[s]);
30
+ I && b(e, p);
31
31
  }
32
32
  function Ke(e, { formElements: i, validation: S }) {
33
33
  return { initialState: e, formElements: i, validation: S };
34
34
  }
35
35
  const et = (e, i) => {
36
36
  let S = e;
37
- const [l, c] = Ve(S);
38
- (Object.keys(c).length > 0 || i && Object.keys(i).length > 0) && Object.keys(c).forEach((h) => {
39
- c[h] = c[h] || {}, c[h].formElements = {
37
+ const [l, c] = Ne(S);
38
+ (Object.keys(c).length > 0 || i && Object.keys(i).length > 0) && Object.keys(c).forEach((I) => {
39
+ c[I] = c[I] || {}, c[I].formElements = {
40
40
  ...i?.formElements,
41
41
  // Global defaults first
42
42
  ...i?.validation,
43
- ...c[h].formElements || {}
43
+ ...c[I].formElements || {}
44
44
  // State-specific overrides
45
- }, Z(h) || n.getState().setInitialStateOptions(h, c[h]);
45
+ }, Z(I) || n.getState().setInitialStateOptions(I, c[I]);
46
46
  }), n.getState().setInitialStates(l), n.getState().setCreatedState(l);
47
- const b = (h, s) => {
48
- const [p] = te(s?.componentId ?? de());
47
+ const b = (I, s) => {
48
+ const [h] = se(s?.componentId ?? de());
49
49
  ye({
50
- stateKey: h,
50
+ stateKey: I,
51
51
  options: s,
52
52
  initialOptionsPart: c
53
53
  });
54
- const r = n.getState().cogsStateStore[h] || l[h], m = s?.modifyState ? s.modifyState(r) : r, [D, x] = Ue(
54
+ const r = n.getState().cogsStateStore[I] || l[I], m = s?.modifyState ? s.modifyState(r) : r, [R, P] = Me(
55
55
  m,
56
56
  {
57
- stateKey: h,
57
+ stateKey: I,
58
58
  syncUpdate: s?.syncUpdate,
59
- componentId: p,
59
+ componentId: h,
60
60
  localStorage: s?.localStorage,
61
61
  middleware: s?.middleware,
62
62
  enabledSync: s?.enabledSync,
@@ -67,19 +67,19 @@ const et = (e, i) => {
67
67
  serverState: s?.serverState
68
68
  }
69
69
  );
70
- return x;
70
+ return P;
71
71
  };
72
- function I(h, s) {
73
- ye({ stateKey: h, options: s, initialOptionsPart: c }), s.localStorage && De(h, s), ie(h);
72
+ function p(I, s) {
73
+ ye({ stateKey: I, options: s, initialOptionsPart: c }), s.localStorage && je(I, s), ae(I);
74
74
  }
75
- return { useCogsState: b, setCogsOptions: I };
75
+ return { useCogsState: b, setCogsOptions: p };
76
76
  }, {
77
- setUpdaterState: ne,
77
+ setUpdaterState: te,
78
78
  setState: J,
79
79
  getInitialOptions: Z,
80
- getKeyState: be,
81
- getValidationErrors: Oe,
82
- setStateLog: je,
80
+ getKeyState: Te,
81
+ getValidationErrors: xe,
82
+ setStateLog: Oe,
83
83
  updateInitialStateGlobal: ge,
84
84
  addValidationError: Fe,
85
85
  removeValidationError: q,
@@ -93,23 +93,23 @@ const et = (e, i) => {
93
93
  );
94
94
  const b = z(S?.localStorage?.key) ? S.localStorage?.key(e) : S?.localStorage?.key;
95
95
  if (b && l) {
96
- const I = `${l}-${i}-${b}`;
97
- let h;
96
+ const p = `${l}-${i}-${b}`;
97
+ let I;
98
98
  try {
99
- h = ae(I)?.lastSyncedWithServer;
99
+ I = oe(p)?.lastSyncedWithServer;
100
100
  } catch {
101
101
  }
102
102
  const s = {
103
103
  state: e,
104
104
  lastUpdated: Date.now(),
105
- lastSyncedWithServer: c ?? h
106
- }, p = Pe.serialize(s);
105
+ lastSyncedWithServer: c ?? I
106
+ }, h = Ce.serialize(s);
107
107
  window.localStorage.setItem(
108
- I,
109
- JSON.stringify(p.json)
108
+ p,
109
+ JSON.stringify(h.json)
110
110
  );
111
111
  }
112
- }, ae = (e) => {
112
+ }, oe = (e) => {
113
113
  if (!e) return null;
114
114
  try {
115
115
  const i = window.localStorage.getItem(e);
@@ -117,20 +117,20 @@ const et = (e, i) => {
117
117
  } catch (i) {
118
118
  return console.error("Error loading from localStorage:", i), null;
119
119
  }
120
- }, De = (e, i) => {
121
- const S = n.getState().cogsStateStore[e], { sessionId: l } = Te(), c = z(i?.localStorage?.key) ? i.localStorage.key(S) : i?.localStorage?.key;
120
+ }, je = (e, i) => {
121
+ const S = n.getState().cogsStateStore[e], { sessionId: l } = pe(), c = z(i?.localStorage?.key) ? i.localStorage.key(S) : i?.localStorage?.key;
122
122
  if (c && l) {
123
- const b = ae(
123
+ const b = oe(
124
124
  `${l}-${e}-${c}`
125
125
  );
126
126
  if (b && b.lastUpdated > (b.lastSyncedWithServer || 0))
127
- return J(e, b.state), ie(e), !0;
127
+ return J(e, b.state), ae(e), !0;
128
128
  }
129
129
  return !1;
130
- }, we = (e, i, S, l, c, b) => {
131
- const I = {
130
+ }, be = (e, i, S, l, c, b) => {
131
+ const p = {
132
132
  initialState: i,
133
- updaterState: re(
133
+ updaterState: ne(
134
134
  e,
135
135
  l,
136
136
  c,
@@ -138,8 +138,8 @@ const et = (e, i) => {
138
138
  ),
139
139
  state: S
140
140
  };
141
- ge(e, I.initialState), ne(e, I.updaterState), J(e, I.state);
142
- }, ie = (e) => {
141
+ ge(e, p.initialState), te(e, p.updaterState), J(e, p.state);
142
+ }, ae = (e) => {
143
143
  const i = n.getState().stateComponents.get(e);
144
144
  if (!i) return;
145
145
  const S = /* @__PURE__ */ new Set();
@@ -156,22 +156,22 @@ const et = (e, i) => {
156
156
  return;
157
157
  c && c.forceUpdate();
158
158
  }
159
- }, Me = (e, i, S, l) => {
159
+ }, De = (e, i, S, l) => {
160
160
  switch (e) {
161
161
  case "update":
162
162
  return {
163
- oldValue: W(i, l),
164
- newValue: W(S, l)
163
+ oldValue: G(i, l),
164
+ newValue: G(S, l)
165
165
  };
166
166
  case "insert":
167
167
  return {
168
168
  oldValue: null,
169
169
  // or undefined
170
- newValue: W(S, l)
170
+ newValue: G(S, l)
171
171
  };
172
172
  case "cut":
173
173
  return {
174
- oldValue: W(i, l),
174
+ oldValue: G(i, l),
175
175
  newValue: null
176
176
  // or undefined
177
177
  };
@@ -189,90 +189,90 @@ function ue(e, i, S) {
189
189
  }), c = c.children.get(b);
190
190
  c.subscribers.add(S);
191
191
  }
192
- function Ee(e, i, S) {
192
+ function Ue(e, i, S) {
193
193
  const l = i.split(".");
194
194
  let c = e;
195
195
  for (const b of l)
196
196
  if (c = c.children.get(b), !c) return;
197
197
  c.subscribers.delete(S);
198
198
  }
199
- function pe(e, i) {
199
+ function he(e, i) {
200
200
  console.log("Getting subscribers for path:", i);
201
201
  const S = i.split("."), l = new Set(e.subscribers);
202
202
  console.log("Root subscribers:", e.subscribers);
203
203
  let c = e;
204
204
  for (const b of S) {
205
205
  if (c = c.children?.get(b), console.log(`Segment ${b} subscribers:`, c?.subscribers), !c) break;
206
- c.subscribers.forEach((I) => l.add(I));
206
+ c.subscribers.forEach((p) => l.add(p));
207
207
  }
208
208
  return console.log("Total subscribers found:", l), l;
209
209
  }
210
- function Ue(e, {
210
+ function Me(e, {
211
211
  stateKey: i,
212
212
  serverSync: S,
213
213
  localStorage: l,
214
214
  formElements: c,
215
215
  reactiveDeps: b,
216
- reactiveType: I,
217
- componentId: h,
216
+ reactiveType: p,
217
+ componentId: I,
218
218
  initialState: s,
219
- syncUpdate: p,
219
+ syncUpdate: h,
220
220
  dependencies: r,
221
221
  serverState: m
222
222
  } = {}) {
223
- const [D, x] = te({}), { sessionId: O } = Te();
224
- let M = !i;
225
- const [v] = te(i ?? de()), d = n.getState().stateLog[v], Q = ee(/* @__PURE__ */ new Set()), L = ee(h ?? de()), k = ee(
223
+ const [R, P] = se({}), { sessionId: x } = pe();
224
+ let j = !i;
225
+ const [y] = se(i ?? de()), d = n.getState().stateLog[y], Q = ee(/* @__PURE__ */ new Set()), W = ee(I ?? de()), k = ee(
226
226
  null
227
227
  );
228
- k.current = Z(v) ?? null, ce(() => {
229
- if (p && p.stateKey === v && p.path?.[0]) {
230
- J(v, (o) => ({
228
+ k.current = Z(y) ?? null, ce(() => {
229
+ if (h && h.stateKey === y && h.path?.[0]) {
230
+ J(y, (o) => ({
231
231
  ...o,
232
- [p.path[0]]: p.newValue
232
+ [h.path[0]]: h.newValue
233
233
  }));
234
- const t = `${p.stateKey}:${p.path.join(".")}`;
234
+ const t = `${h.stateKey}:${h.path.join(".")}`;
235
235
  n.getState().setSyncInfo(t, {
236
- timeStamp: p.timeStamp,
237
- userId: p.userId
236
+ timeStamp: h.timeStamp,
237
+ userId: h.userId
238
238
  });
239
239
  }
240
- }, [p]), ce(() => {
240
+ }, [h]), ce(() => {
241
241
  if (s) {
242
- me(v, {
242
+ me(y, {
243
243
  initialState: s
244
244
  });
245
- const t = k.current, a = t?.serverState?.id !== void 0 && t?.serverState?.status === "success" && t?.serverState?.data, g = n.getState().initialStateGlobal[v];
246
- if (!(g && !G(g, s) || !g) && !a)
245
+ const t = k.current, a = t?.serverState?.id !== void 0 && t?.serverState?.status === "success" && t?.serverState?.data, g = n.getState().initialStateGlobal[y];
246
+ if (!(g && !M(g, s) || !g) && !a)
247
247
  return;
248
248
  let f = null;
249
- const A = z(t?.localStorage?.key) ? t?.localStorage?.key(s) : t?.localStorage?.key;
250
- A && O && (f = ae(`${O}-${v}-${A}`));
249
+ const $ = z(t?.localStorage?.key) ? t?.localStorage?.key(s) : t?.localStorage?.key;
250
+ $ && x && (f = oe(`${x}-${y}-${$}`));
251
251
  let T = s, w = !1;
252
- const C = a ? Date.now() : 0, $ = f?.lastUpdated || 0, _ = f?.lastSyncedWithServer || 0;
253
- a && C > $ ? (T = t.serverState.data, w = !0) : f && $ > _ && (T = f.state, t?.localStorage?.onChange && t?.localStorage?.onChange(T)), we(
254
- v,
252
+ const N = a ? Date.now() : 0, _ = f?.lastUpdated || 0, D = f?.lastSyncedWithServer || 0;
253
+ a && N > _ ? (T = t.serverState.data, w = !0) : f && _ > D && (T = f.state, t?.localStorage?.onChange && t?.localStorage?.onChange(T)), be(
254
+ y,
255
255
  s,
256
256
  T,
257
257
  H,
258
- L.current,
259
- O
260
- ), w && A && O && ve(T, v, t, O, Date.now()), ie(v), (Array.isArray(I) ? I : [I || "component"]).includes("none") || x({});
258
+ W.current,
259
+ x
260
+ ), w && $ && x && ve(T, y, t, x, Date.now()), ae(y), (Array.isArray(p) ? p : [p || "component"]).includes("none") || P({});
261
261
  }
262
262
  }, [
263
263
  s,
264
264
  m?.status,
265
265
  m?.data,
266
266
  ...r || []
267
- ]), Ie(() => {
268
- M && me(v, {
267
+ ]), we(() => {
268
+ j && me(y, {
269
269
  serverSync: S,
270
270
  formElements: c,
271
271
  initialState: s,
272
272
  localStorage: l,
273
273
  middleware: k.current?.middleware
274
274
  });
275
- const t = `${v}////${L.current}`, o = n.getState().stateComponents.get(v) || {
275
+ const t = `${y}////${W.current}`, o = n.getState().stateComponents.get(y) || {
276
276
  components: /* @__PURE__ */ new Map(),
277
277
  pathTrie: {
278
278
  subscribers: /* @__PURE__ */ new Set(),
@@ -280,44 +280,44 @@ function Ue(e, {
280
280
  }
281
281
  };
282
282
  return o.components.set(t, {
283
- forceUpdate: () => x({}),
283
+ forceUpdate: () => P({}),
284
284
  paths: /* @__PURE__ */ new Set(),
285
285
  deps: [],
286
286
  depsFunction: b || void 0,
287
- reactiveType: I ?? ["component", "deps"]
288
- }), n.getState().stateComponents.set(v, o), x({}), () => {
289
- const a = `${v}////${L.current}`;
290
- o && (o.components.delete(a), o.components.size === 0 && n.getState().stateComponents.delete(v));
287
+ reactiveType: p ?? ["component", "deps"]
288
+ }), n.getState().stateComponents.set(y, o), P({}), () => {
289
+ const a = `${y}////${W.current}`;
290
+ o && (o.components.delete(a), o.components.size === 0 && n.getState().stateComponents.delete(y));
291
291
  };
292
292
  }, []);
293
293
  const H = (t, o, a, g) => {
294
294
  if (Array.isArray(o)) {
295
- const y = `${v}-${o.join(".")}`;
296
- Q.current.add(y);
295
+ const v = `${y}-${o.join(".")}`;
296
+ Q.current.add(v);
297
297
  }
298
- J(v, (y) => {
299
- const f = z(t) ? t(y) : t, A = `${v}-${o.join(".")}`;
300
- if (A) {
301
- let R = !1, E = n.getState().signalDomElements.get(A);
298
+ J(y, (v) => {
299
+ const f = z(t) ? t(v) : t, $ = `${y}-${o.join(".")}`;
300
+ if ($) {
301
+ let F = !1, E = n.getState().signalDomElements.get($);
302
302
  if ((!E || E.size === 0) && (a.updateType === "insert" || a.updateType === "cut")) {
303
- const j = o.slice(0, -1), U = W(f, j);
303
+ const O = o.slice(0, -1), U = G(f, O);
304
304
  if (Array.isArray(U)) {
305
- R = !0;
306
- const N = `${v}-${j.join(".")}`;
307
- E = n.getState().signalDomElements.get(N);
305
+ F = !0;
306
+ const A = `${y}-${O.join(".")}`;
307
+ E = n.getState().signalDomElements.get(A);
308
308
  }
309
309
  }
310
310
  if (E) {
311
- const j = R ? W(f, o.slice(0, -1)) : W(f, o);
312
- E.forEach(({ parentId: U, position: N, effect: V }) => {
313
- const P = document.querySelector(
311
+ const O = F ? G(f, o.slice(0, -1)) : G(f, o);
312
+ E.forEach(({ parentId: U, position: A, effect: V }) => {
313
+ const C = document.querySelector(
314
314
  `[data-parent-id="${U}"]`
315
315
  );
316
- if (P) {
317
- const B = Array.from(P.childNodes);
318
- if (B[N]) {
319
- const Y = V ? new Function("state", `return (${V})(state)`)(j) : j;
320
- B[N].textContent = String(Y);
316
+ if (C) {
317
+ const B = Array.from(C.childNodes);
318
+ if (B[A]) {
319
+ const Y = V ? new Function("state", `return (${V})(state)`)(O) : O;
320
+ B[A].textContent = String(Y);
321
321
  }
322
322
  }
323
323
  });
@@ -329,87 +329,87 @@ function Ue(e, {
329
329
  const T = o.slice(0, o.length - 1);
330
330
  a.updateType === "cut" && k.current?.validation?.key && q(
331
331
  k.current?.validation?.key + "." + T.join(".")
332
- ), a.updateType === "insert" && k.current?.validation?.key && Oe(
332
+ ), a.updateType === "insert" && k.current?.validation?.key && xe(
333
333
  k.current?.validation?.key + "." + T.join(".")
334
- ).filter(([E, j]) => {
334
+ ).filter(([E, O]) => {
335
335
  let U = E?.split(".").length;
336
336
  if (E == T.join(".") && U == T.length - 1) {
337
- let N = E + "." + T;
338
- q(E), Fe(N, j);
337
+ let A = E + "." + T;
338
+ q(E), Fe(A, O);
339
339
  }
340
340
  });
341
- const w = n.getState().stateComponents.get(v);
341
+ const w = n.getState().stateComponents.get(y);
342
342
  if (w && w.pathTrie) {
343
- const R = le(y, f), E = /* @__PURE__ */ new Set();
344
- R.forEach((N) => {
345
- pe(
343
+ const F = le(v, f), E = /* @__PURE__ */ new Set();
344
+ F.forEach((A) => {
345
+ he(
346
346
  w.pathTrie,
347
- N
348
- ).forEach((P) => E.add(P));
347
+ A
348
+ ).forEach((C) => E.add(C));
349
349
  });
350
- const j = a.updateType === "update" ? o.join(".") : o.slice(0, -1).join(".") || "";
351
- pe(
350
+ const O = a.updateType === "update" ? o.join(".") : o.slice(0, -1).join(".") || "";
351
+ he(
352
352
  w.pathTrie,
353
- j
354
- ).forEach((N) => E.add(N)), console.log("componentsToUpdate", E), E.forEach((N) => {
355
- const V = w.components.get(N);
353
+ O
354
+ ).forEach((A) => E.add(A)), console.log("componentsToUpdate", E), E.forEach((A) => {
355
+ const V = w.components.get(A);
356
356
  if (V) {
357
- const P = Array.isArray(V.reactiveType) ? V.reactiveType : [V.reactiveType || "component"];
358
- if (P.includes("none")) return;
359
- if (P.includes("all")) {
357
+ const C = Array.isArray(V.reactiveType) ? V.reactiveType : [V.reactiveType || "component"];
358
+ if (C.includes("none")) return;
359
+ if (C.includes("all")) {
360
360
  V.forceUpdate();
361
361
  return;
362
362
  }
363
- if (P.includes("deps") && V.depsFunction) {
363
+ if (C.includes("deps") && V.depsFunction) {
364
364
  const B = V.depsFunction(f);
365
365
  let Y = !1;
366
- if (typeof B == "boolean" ? B && (Y = !0) : G(V.deps, B) || (V.deps = B, Y = !0), Y) {
366
+ if (typeof B == "boolean" ? B && (Y = !0) : M(V.deps, B) || (V.deps = B, Y = !0), Y) {
367
367
  V.forceUpdate();
368
368
  return;
369
369
  }
370
370
  }
371
- P.includes("component") && V.forceUpdate();
371
+ C.includes("component") && V.forceUpdate();
372
372
  }
373
373
  });
374
374
  }
375
- const C = Date.now();
376
- o = o.map((R, E) => {
377
- const j = o.slice(0, -1), U = W(f, j);
378
- return E === o.length - 1 && ["insert", "cut"].includes(a.updateType) ? (U.length - 1).toString() : R;
375
+ const N = Date.now();
376
+ o = o.map((F, E) => {
377
+ const O = o.slice(0, -1), U = G(f, O);
378
+ return E === o.length - 1 && ["insert", "cut"].includes(a.updateType) ? (U.length - 1).toString() : F;
379
379
  });
380
- const { oldValue: $, newValue: _ } = Me(
380
+ const { oldValue: _, newValue: D } = De(
381
381
  a.updateType,
382
- y,
382
+ v,
383
383
  f,
384
384
  o
385
- ), F = {
386
- timeStamp: C,
387
- stateKey: v,
385
+ ), L = {
386
+ timeStamp: N,
387
+ stateKey: y,
388
388
  path: o,
389
389
  updateType: a.updateType,
390
390
  status: "new",
391
- oldValue: $,
392
- newValue: _
391
+ oldValue: _,
392
+ newValue: D
393
393
  };
394
- if (je(v, (R) => {
395
- const j = [...R ?? [], F].reduce((U, N) => {
396
- const V = `${N.stateKey}:${JSON.stringify(N.path)}`, P = U.get(V);
397
- return P ? (P.timeStamp = Math.max(P.timeStamp, N.timeStamp), P.newValue = N.newValue, P.oldValue = P.oldValue ?? N.oldValue, P.updateType = N.updateType) : U.set(V, { ...N }), U;
394
+ if (Oe(y, (F) => {
395
+ const O = [...F ?? [], L].reduce((U, A) => {
396
+ const V = `${A.stateKey}:${JSON.stringify(A.path)}`, C = U.get(V);
397
+ return C ? (C.timeStamp = Math.max(C.timeStamp, A.timeStamp), C.newValue = A.newValue, C.oldValue = C.oldValue ?? A.oldValue, C.updateType = A.updateType) : U.set(V, { ...A }), U;
398
398
  }, /* @__PURE__ */ new Map());
399
- return Array.from(j.values());
399
+ return Array.from(O.values());
400
400
  }), ve(
401
401
  f,
402
- v,
402
+ y,
403
403
  k.current,
404
- O
404
+ x
405
405
  ), k.current?.middleware && k.current.middleware({
406
406
  updateLog: d,
407
- update: F
407
+ update: L
408
408
  }), k.current?.serverSync) {
409
- const R = n.getState().serverState[v], E = k.current?.serverSync;
410
- Re(v, {
409
+ const F = n.getState().serverState[y], E = k.current?.serverSync;
410
+ Re(y, {
411
411
  syncKey: typeof E.syncKey == "string" ? E.syncKey : E.syncKey({ state: f }),
412
- rollBackState: R,
412
+ rollBackState: F,
413
413
  actionTimeStamp: Date.now() + (E.debounce ?? 3e3),
414
414
  status: "waiting"
415
415
  });
@@ -417,90 +417,90 @@ function Ue(e, {
417
417
  return f;
418
418
  });
419
419
  };
420
- n.getState().updaterState[v] || (ne(
421
- v,
422
- re(
423
- v,
420
+ n.getState().updaterState[y] || (te(
421
+ y,
422
+ ne(
423
+ y,
424
424
  H,
425
- L.current,
426
- O
425
+ W.current,
426
+ x
427
427
  )
428
- ), n.getState().cogsStateStore[v] || J(v, e), n.getState().initialStateGlobal[v] || ge(v, e));
429
- const u = $e(() => re(
430
- v,
428
+ ), n.getState().cogsStateStore[y] || J(y, e), n.getState().initialStateGlobal[y] || ge(y, e));
429
+ const u = Ee(() => ne(
430
+ y,
431
431
  H,
432
- L.current,
433
- O
434
- ), [v, O]);
435
- return [be(v), u];
432
+ W.current,
433
+ x
434
+ ), [y, x]);
435
+ return [Te(y), u];
436
436
  }
437
- function re(e, i, S, l) {
437
+ function ne(e, i, S, l) {
438
438
  const c = /* @__PURE__ */ new Map();
439
439
  let b = 0;
440
- const I = (p) => {
441
- const r = p.join(".");
440
+ const p = (h) => {
441
+ const r = h.join(".");
442
442
  for (const [m] of c)
443
443
  (m === r || m.startsWith(r + ".")) && c.delete(m);
444
444
  b++;
445
- }, h = {
446
- removeValidation: (p) => {
447
- p?.validationKey && q(p.validationKey);
445
+ }, I = {
446
+ removeValidation: (h) => {
447
+ h?.validationKey && q(h.validationKey);
448
448
  },
449
- revertToInitialState: (p) => {
449
+ revertToInitialState: (h) => {
450
450
  const r = n.getState().getInitialOptions(e)?.validation;
451
- r?.key && q(r?.key), p?.validationKey && q(p.validationKey);
451
+ r?.key && q(r?.key), h?.validationKey && q(h.validationKey);
452
452
  const m = n.getState().initialStateGlobal[e];
453
453
  n.getState().clearSelectedIndexesForState(e), c.clear(), b++;
454
- const D = s(m, []), x = Z(e), O = z(x?.localStorage?.key) ? x?.localStorage?.key(m) : x?.localStorage?.key, M = `${l}-${e}-${O}`;
455
- M && localStorage.removeItem(M), ne(e, D), J(e, m);
456
- const v = n.getState().stateComponents.get(e);
457
- return v && v.components.forEach((d) => {
454
+ const R = s(m, []), P = Z(e), x = z(P?.localStorage?.key) ? P?.localStorage?.key(m) : P?.localStorage?.key, j = `${l}-${e}-${x}`;
455
+ j && localStorage.removeItem(j), te(e, R), J(e, m);
456
+ const y = n.getState().stateComponents.get(e);
457
+ return y && y.components.forEach((d) => {
458
458
  d.forceUpdate();
459
459
  }), m;
460
460
  },
461
- updateInitialState: (p) => {
461
+ updateInitialState: (h) => {
462
462
  c.clear(), b++;
463
- const r = re(
463
+ const r = ne(
464
464
  e,
465
465
  i,
466
466
  S,
467
467
  l
468
- ), m = n.getState().initialStateGlobal[e], D = Z(e), x = z(D?.localStorage?.key) ? D?.localStorage?.key(m) : D?.localStorage?.key, O = `${l}-${e}-${x}`;
469
- return localStorage.getItem(O) && localStorage.removeItem(O), Ne(() => {
470
- ge(e, p), ne(e, r), J(e, p);
471
- const M = n.getState().stateComponents.get(e);
472
- M && M.components.forEach((v) => {
473
- v.forceUpdate();
468
+ ), m = n.getState().initialStateGlobal[e], R = Z(e), P = z(R?.localStorage?.key) ? R?.localStorage?.key(m) : R?.localStorage?.key, x = `${l}-${e}-${P}`;
469
+ return localStorage.getItem(x) && localStorage.removeItem(x), Ae(() => {
470
+ ge(e, h), te(e, r), J(e, h);
471
+ const j = n.getState().stateComponents.get(e);
472
+ j && j.components.forEach((y) => {
473
+ y.forceUpdate();
474
474
  });
475
475
  }), {
476
- fetchId: (M) => r.get()[M]
476
+ fetchId: (j) => r.get()[j]
477
477
  };
478
478
  },
479
479
  _initialState: n.getState().initialStateGlobal[e],
480
480
  _serverState: n.getState().serverState[e],
481
481
  _isLoading: n.getState().isLoadingGlobal[e],
482
482
  _isServerSynced: () => {
483
- const p = n.getState().serverState[e];
484
- return !!(p && G(p, be(e)));
483
+ const h = n.getState().serverState[e];
484
+ return !!(h && M(h, Te(e)));
485
485
  }
486
486
  };
487
- function s(p, r = [], m) {
488
- const D = r.map(String).join(".");
489
- c.get(D);
490
- const x = function() {
487
+ function s(h, r = [], m) {
488
+ const R = r.map(String).join(".");
489
+ c.get(R);
490
+ const P = function() {
491
491
  return n().getNestedState(e, r);
492
492
  };
493
- Object.keys(h).forEach((v) => {
494
- x[v] = h[v];
493
+ Object.keys(I).forEach((y) => {
494
+ P[y] = I[y];
495
495
  });
496
- const O = {
497
- apply(v, d, Q) {
496
+ const x = {
497
+ apply(y, d, Q) {
498
498
  return console.log(
499
499
  `PROXY APPLY TRAP HIT: stateKey=${e}, path=${r.join(".")}`
500
500
  ), console.trace("Apply trap stack trace"), n().getNestedState(e, r);
501
501
  },
502
- get(v, d) {
503
- m?.validIndices && !Array.isArray(p) && (m = { ...m, validIndices: void 0 });
502
+ get(y, d) {
503
+ m?.validIndices && !Array.isArray(h) && (m = { ...m, validIndices: void 0 });
504
504
  const Q = /* @__PURE__ */ new Set([
505
505
  "insert",
506
506
  "cut",
@@ -531,8 +531,8 @@ function re(e, i, S, l) {
531
531
  if (o && !o.paths.has("")) {
532
532
  const a = r.join(".");
533
533
  let g = !0;
534
- for (const y of o.paths)
535
- if (a.startsWith(y) && (a === y || a[y.length] === ".")) {
534
+ for (const v of o.paths)
535
+ if (a.startsWith(v) && (a === v || a[v.length] === ".")) {
536
536
  g = !1;
537
537
  break;
538
538
  }
@@ -543,16 +543,16 @@ function re(e, i, S, l) {
543
543
  "for component:",
544
544
  u
545
545
  ), o.paths.add(a);
546
- const y = n.getState().stateComponents.get(e);
547
- y && y.pathTrie ? (console.log(
546
+ const v = n.getState().stateComponents.get(e);
547
+ v && v.pathTrie ? (console.log(
548
548
  "ADDING TO TRIE:",
549
549
  a,
550
550
  u
551
551
  ), ue(
552
- y.pathTrie,
552
+ v.pathTrie,
553
553
  a,
554
554
  u
555
- ), console.log("TRIE AFTER ADD:", y.pathTrie)) : console.log("NO TRIE FOUND for state:", e);
555
+ ), console.log("TRIE AFTER ADD:", v.pathTrie)) : console.log("NO TRIE FOUND for state:", e);
556
556
  }
557
557
  }
558
558
  }
@@ -572,11 +572,11 @@ function re(e, i, S, l) {
572
572
  const g = await t.action(o);
573
573
  if (g && !g.success && g.errors && a) {
574
574
  n.getState().removeValidationError(a), g.errors.forEach((f) => {
575
- const A = [a, ...f.path].join(".");
576
- n.getState().addValidationError(A, f.message);
575
+ const $ = [a, ...f.path].join(".");
576
+ n.getState().addValidationError($, f.message);
577
577
  });
578
- const y = n.getState().stateComponents.get(e);
579
- y && y.components.forEach((f) => {
578
+ const v = n.getState().stateComponents.get(e);
579
+ v && v.components.forEach((f) => {
580
580
  f.forceUpdate();
581
581
  });
582
582
  }
@@ -586,16 +586,16 @@ function re(e, i, S, l) {
586
586
  }
587
587
  };
588
588
  if (d === "_status") {
589
- const u = n.getState().getNestedState(e, r), t = n.getState().initialStateGlobal[e], o = W(t, r);
590
- return G(u, o) ? "fresh" : "stale";
589
+ const u = n.getState().getNestedState(e, r), t = n.getState().initialStateGlobal[e], o = G(t, r);
590
+ return M(u, o) ? "fresh" : "stale";
591
591
  }
592
592
  if (d === "getStatus")
593
593
  return function() {
594
594
  const u = n().getNestedState(
595
595
  e,
596
596
  r
597
- ), t = n.getState().initialStateGlobal[e], o = W(t, r);
598
- return G(u, o) ? "fresh" : "stale";
597
+ ), t = n.getState().initialStateGlobal[e], o = G(t, r);
598
+ return M(u, o) ? "fresh" : "stale";
599
599
  };
600
600
  if (d === "removeStorage")
601
601
  return () => {
@@ -609,8 +609,8 @@ function re(e, i, S, l) {
609
609
  throw new Error("Validation key not found");
610
610
  return n.getState().getValidationErrors(u.key + "." + r.join("."));
611
611
  };
612
- if (Array.isArray(p)) {
613
- const u = () => m?.validIndices ? p.map((o, a) => ({
612
+ if (Array.isArray(h)) {
613
+ const u = () => m?.validIndices ? h.map((o, a) => ({
614
614
  item: o,
615
615
  originalIndex: m.validIndices[a]
616
616
  })) : n.getState().getNestedState(e, r).map((o, a) => ({
@@ -622,7 +622,7 @@ function re(e, i, S, l) {
622
622
  const t = n.getState().getSelectedIndex(e, r.join("."));
623
623
  if (t !== void 0)
624
624
  return s(
625
- p[t],
625
+ h[t],
626
626
  [...r, t.toString()],
627
627
  m
628
628
  );
@@ -636,88 +636,70 @@ function re(e, i, S, l) {
636
636
  if (d === "stateSort")
637
637
  return (t) => {
638
638
  const a = [...u()].sort(
639
- (f, A) => t(f.item, A.item)
640
- ), g = a.map(({ item: f }) => f), y = {
639
+ (f, $) => t(f.item, $.item)
640
+ ), g = a.map(({ item: f }) => f), v = {
641
641
  ...m,
642
642
  validIndices: a.map(
643
643
  ({ originalIndex: f }) => f
644
644
  )
645
645
  };
646
- return s(g, r, y);
646
+ return s(g, r, v);
647
647
  };
648
648
  if (d === "stateFilter")
649
649
  return (t) => {
650
650
  const a = u().filter(
651
- ({ item: f }, A) => t(f, A)
652
- ), g = a.map(({ item: f }) => f), y = {
651
+ ({ item: f }, $) => t(f, $)
652
+ ), g = a.map(({ item: f }) => f), v = {
653
653
  ...m,
654
654
  validIndices: a.map(
655
655
  ({ originalIndex: f }) => f
656
656
  )
657
657
  };
658
- return s(g, r, y);
658
+ return s(g, r, v);
659
659
  };
660
660
  if (d === "stateMap")
661
661
  return (t) => {
662
662
  const o = n.getState().getNestedState(e, r);
663
- return Array.isArray(o) ? o.map((a, g) => {
664
- let y;
665
- m?.validIndices && m.validIndices[g] !== void 0 ? y = m.validIndices[g] : y = g;
666
- const f = [...r, y.toString()], A = s(a, f, m);
667
- return t(a, A, {
668
- register: () => {
669
- const [, w] = te({}), C = `${S}-${r.join(".")}-${y}`;
670
- Ie(() => {
671
- const $ = `${e}////${C}`, _ = n.getState().stateComponents.get(e) || {
672
- components: /* @__PURE__ */ new Map(),
673
- pathTrie: {
674
- subscribers: /* @__PURE__ */ new Set(),
675
- children: /* @__PURE__ */ new Map()
676
- }
677
- };
678
- return _.components.set($, {
679
- forceUpdate: () => w({}),
680
- paths: /* @__PURE__ */ new Set([f.join(".")]),
681
- deps: [],
682
- depsFunction: void 0,
683
- reactiveType: ["component"]
684
- }), _.pathTrie && ue(
685
- _.pathTrie,
686
- f.join("."),
687
- $
688
- ), n.getState().stateComponents.set(e, _), () => {
689
- const F = n.getState().stateComponents.get(e);
690
- F && (F.components.delete($), F.pathTrie && Ee(
691
- F.pathTrie,
692
- f.join("."),
693
- $
694
- ));
695
- };
696
- }, [e, C]);
663
+ return o.map((a, g) => {
664
+ let v;
665
+ m?.validIndices && m.validIndices[g] !== void 0 ? v = m.validIndices[g] : v = g;
666
+ const f = [...r, v.toString()], $ = s(a, f, m), T = `${S}-${r.join(".")}-${v}`, w = `${e}////${T}`, N = n.getState().stateComponents.get(e);
667
+ return N && N.pathTrie && (N.components.set(w, {
668
+ forceUpdate: () => {
697
669
  },
698
- index: g,
699
- originalIndex: y
700
- });
701
- }) : (console.warn(
702
- `stateMap called on a non-array value at path: ${r.join(".")}. The current value is:`,
703
- o
704
- ), null);
670
+ // This will be updated when component mounts
671
+ paths: /* @__PURE__ */ new Set([f.join(".")]),
672
+ deps: [],
673
+ depsFunction: void 0,
674
+ reactiveType: ["component"]
675
+ }), ue(
676
+ N.pathTrie,
677
+ f.join("."),
678
+ w
679
+ )), t(
680
+ a,
681
+ $,
682
+ g,
683
+ o,
684
+ s(o, r, m)
685
+ );
686
+ });
705
687
  };
706
688
  if (d === "stateMapNoRender")
707
- return (t) => p.map((a, g) => {
708
- let y;
709
- m?.validIndices && m.validIndices[g] !== void 0 ? y = m.validIndices[g] : y = g;
710
- const f = [...r, y.toString()], A = s(a, f, m);
689
+ return (t) => h.map((a, g) => {
690
+ let v;
691
+ m?.validIndices && m.validIndices[g] !== void 0 ? v = m.validIndices[g] : v = g;
692
+ const f = [...r, v.toString()], $ = s(a, f, m);
711
693
  return t(
712
694
  a,
713
- A,
695
+ $,
714
696
  g,
715
- p,
716
- s(p, r, m)
697
+ h,
698
+ s(h, r, m)
717
699
  );
718
700
  });
719
701
  if (d === "$stateMap")
720
- return (t) => oe(Ge, {
702
+ return (t) => re(Ge, {
721
703
  proxy: {
722
704
  _stateKey: e,
723
705
  _path: r,
@@ -728,7 +710,7 @@ function re(e, i, S, l) {
728
710
  });
729
711
  if (d === "stateFlattenOn")
730
712
  return (t) => {
731
- const o = p;
713
+ const o = h;
732
714
  c.clear(), b++;
733
715
  const a = o.flatMap(
734
716
  (g) => g[t] ?? []
@@ -741,7 +723,7 @@ function re(e, i, S, l) {
741
723
  };
742
724
  if (d === "index")
743
725
  return (t) => {
744
- const o = p[t];
726
+ const o = h[t];
745
727
  return s(o, [...r, t.toString()]);
746
728
  };
747
729
  if (d === "last")
@@ -752,54 +734,54 @@ function re(e, i, S, l) {
752
734
  return s(a, g);
753
735
  };
754
736
  if (d === "insert")
755
- return (t) => (I(r), se(i, t, r, e), s(
737
+ return (t) => (p(r), ie(i, t, r, e), s(
756
738
  n.getState().getNestedState(e, r),
757
739
  r
758
740
  ));
759
741
  if (d === "uniqueInsert")
760
742
  return (t, o, a) => {
761
- const g = n.getState().getNestedState(e, r), y = z(t) ? t(g) : t;
743
+ const g = n.getState().getNestedState(e, r), v = z(t) ? t(g) : t;
762
744
  let f = null;
763
745
  if (!g.some((T) => {
764
746
  if (o) {
765
- const C = o.every(
766
- ($) => G(T[$], y[$])
747
+ const N = o.every(
748
+ (_) => M(T[_], v[_])
767
749
  );
768
- return C && (f = T), C;
750
+ return N && (f = T), N;
769
751
  }
770
- const w = G(T, y);
752
+ const w = M(T, v);
771
753
  return w && (f = T), w;
772
754
  }))
773
- I(r), se(i, y, r, e);
755
+ p(r), ie(i, v, r, e);
774
756
  else if (a && f) {
775
757
  const T = a(f), w = g.map(
776
- (C) => G(C, f) ? T : C
758
+ (N) => M(N, f) ? T : N
777
759
  );
778
- I(r), X(i, w, r);
760
+ p(r), X(i, w, r);
779
761
  }
780
762
  };
781
763
  if (d === "cut")
782
764
  return (t, o) => {
783
765
  if (!o?.waitForSync)
784
- return I(r), K(i, r, e, t), s(
766
+ return p(r), K(i, r, e, t), s(
785
767
  n.getState().getNestedState(e, r),
786
768
  r
787
769
  );
788
770
  };
789
771
  if (d === "cutByValue")
790
772
  return (t) => {
791
- for (let o = 0; o < p.length; o++)
792
- p[o] === t && K(i, r, e, o);
773
+ for (let o = 0; o < h.length; o++)
774
+ h[o] === t && K(i, r, e, o);
793
775
  };
794
776
  if (d === "toggleByValue")
795
777
  return (t) => {
796
- const o = p.findIndex((a) => a === t);
797
- o > -1 ? K(i, r, e, o) : se(i, t, r, e);
778
+ const o = h.findIndex((a) => a === t);
779
+ o > -1 ? K(i, r, e, o) : ie(i, t, r, e);
798
780
  };
799
781
  if (d === "stateFind")
800
782
  return (t) => {
801
783
  const a = u().find(
802
- ({ item: y }, f) => t(y, f)
784
+ ({ item: v }, f) => t(v, f)
803
785
  );
804
786
  if (!a) return;
805
787
  const g = [...r, a.originalIndex.toString()];
@@ -811,31 +793,31 @@ function re(e, i, S, l) {
811
793
  ({ item: f }) => f[t] === o
812
794
  );
813
795
  if (!g) return;
814
- const y = [...r, g.originalIndex.toString()];
815
- return s(g.item, y, m);
796
+ const v = [...r, g.originalIndex.toString()];
797
+ return s(g.item, v, m);
816
798
  };
817
799
  }
818
- const L = r[r.length - 1];
819
- if (!isNaN(Number(L))) {
800
+ const W = r[r.length - 1];
801
+ if (!isNaN(Number(W))) {
820
802
  const u = r.slice(0, -1), t = n.getState().getNestedState(e, u);
821
803
  if (Array.isArray(t) && d === "cut")
822
804
  return () => K(
823
805
  i,
824
806
  u,
825
807
  e,
826
- Number(L)
808
+ Number(W)
827
809
  );
828
810
  }
829
811
  if (d === "get")
830
812
  return () => n.getState().getNestedState(e, r);
831
813
  if (d === "$derive")
832
- return (u) => he({
814
+ return (u) => Ie({
833
815
  _stateKey: e,
834
816
  _path: r,
835
817
  _effect: u.toString()
836
818
  });
837
819
  if (d === "$get")
838
- return () => he({
820
+ return () => Ie({
839
821
  _stateKey: e,
840
822
  _path: r
841
823
  });
@@ -844,7 +826,7 @@ function re(e, i, S, l) {
844
826
  return n.getState().getSyncInfo(u);
845
827
  }
846
828
  if (d == "getLocalStorage")
847
- return (u) => ae(l + "-" + e + "-" + u);
829
+ return (u) => oe(l + "-" + e + "-" + u);
848
830
  if (d === "_selected") {
849
831
  const u = r.slice(0, -1), t = u.join("."), o = n.getState().getNestedState(e, u);
850
832
  return Array.isArray(o) ? Number(r[r.length - 1]) === n.getState().getSelectedIndex(e, t) : void 0;
@@ -854,7 +836,7 @@ function re(e, i, S, l) {
854
836
  const t = r.slice(0, -1), o = Number(r[r.length - 1]), a = t.join(".");
855
837
  u ? n.getState().setSelectedIndex(e, a, o) : n.getState().setSelectedIndex(e, a, void 0);
856
838
  const g = n.getState().getNestedState(e, [...t]);
857
- X(i, g, t), I(t);
839
+ X(i, g, t), p(t);
858
840
  };
859
841
  if (d === "toggleSelected")
860
842
  return () => {
@@ -865,13 +847,13 @@ function re(e, i, S, l) {
865
847
  a === t ? void 0 : t
866
848
  );
867
849
  const g = n.getState().getNestedState(e, [...u]);
868
- X(i, g, u), I(u);
850
+ X(i, g, u), p(u);
869
851
  };
870
852
  if (r.length == 0) {
871
853
  if (d === "applyJsonPatch")
872
854
  return (u) => {
873
- const t = n.getState().cogsStateStore[e], a = xe(t, u).newDocument;
874
- we(
855
+ const t = n.getState().cogsStateStore[e], a = Pe(t, u).newDocument;
856
+ be(
875
857
  e,
876
858
  n.getState().initialStateGlobal[e],
877
859
  a,
@@ -881,55 +863,55 @@ function re(e, i, S, l) {
881
863
  );
882
864
  const g = n.getState().stateComponents.get(e);
883
865
  if (g) {
884
- const y = le(t, a), f = new Set(y);
866
+ const v = le(t, a), f = new Set(v);
885
867
  for (const [
886
- A,
868
+ $,
887
869
  T
888
870
  ] of g.components.entries()) {
889
871
  let w = !1;
890
- const C = Array.isArray(T.reactiveType) ? T.reactiveType : [T.reactiveType || "component"];
891
- if (!C.includes("none")) {
892
- if (C.includes("all")) {
872
+ const N = Array.isArray(T.reactiveType) ? T.reactiveType : [T.reactiveType || "component"];
873
+ if (!N.includes("none")) {
874
+ if (N.includes("all")) {
893
875
  T.forceUpdate();
894
876
  continue;
895
877
  }
896
- if (C.includes("component") && (T.paths.has("") && (w = !0), !w))
897
- for (const $ of f) {
898
- if (T.paths.has($)) {
878
+ if (N.includes("component") && (T.paths.has("") && (w = !0), !w))
879
+ for (const _ of f) {
880
+ if (T.paths.has(_)) {
899
881
  w = !0;
900
882
  break;
901
883
  }
902
- let _ = $.lastIndexOf(".");
903
- for (; _ !== -1; ) {
904
- const F = $.substring(0, _);
905
- if (T.paths.has(F)) {
884
+ let D = _.lastIndexOf(".");
885
+ for (; D !== -1; ) {
886
+ const L = _.substring(0, D);
887
+ if (T.paths.has(L)) {
906
888
  w = !0;
907
889
  break;
908
890
  }
909
- const R = $.substring(
910
- _ + 1
891
+ const F = _.substring(
892
+ D + 1
911
893
  );
912
- if (!isNaN(Number(R))) {
913
- const E = F.lastIndexOf(".");
894
+ if (!isNaN(Number(F))) {
895
+ const E = L.lastIndexOf(".");
914
896
  if (E !== -1) {
915
- const j = F.substring(
897
+ const O = L.substring(
916
898
  0,
917
899
  E
918
900
  );
919
- if (T.paths.has(j)) {
901
+ if (T.paths.has(O)) {
920
902
  w = !0;
921
903
  break;
922
904
  }
923
905
  }
924
906
  }
925
- _ = F.lastIndexOf(".");
907
+ D = L.lastIndexOf(".");
926
908
  }
927
909
  if (w) break;
928
910
  }
929
- if (!w && C.includes("deps") && T.depsFunction) {
930
- const $ = T.depsFunction(a);
931
- let _ = !1;
932
- typeof $ == "boolean" ? $ && (_ = !0) : G(T.deps, $) || (T.deps = $, _ = !0), _ && (w = !0);
911
+ if (!w && N.includes("deps") && T.depsFunction) {
912
+ const _ = T.depsFunction(a);
913
+ let D = !1;
914
+ typeof _ == "boolean" ? _ && (D = !0) : M(T.deps, _) || (T.deps = _, D = !0), D && (w = !0);
933
915
  }
934
916
  w && T.forceUpdate();
935
917
  }
@@ -947,14 +929,14 @@ function re(e, i, S, l) {
947
929
  const o = n.getState().cogsStateStore[e];
948
930
  try {
949
931
  const a = n.getState().getValidationErrors(u.key);
950
- a && a.length > 0 && a.forEach(([y]) => {
951
- y && y.startsWith(u.key) && q(y);
932
+ a && a.length > 0 && a.forEach(([v]) => {
933
+ v && v.startsWith(u.key) && q(v);
952
934
  });
953
935
  const g = u.zodSchema.safeParse(o);
954
936
  return g.success ? !0 : (g.error.errors.forEach((f) => {
955
- const A = f.path, T = f.message, w = [u.key, ...A].join(".");
937
+ const $ = f.path, T = f.message, w = [u.key, ...$].join(".");
956
938
  t(w, T);
957
- }), ie(e), !1);
939
+ }), ae(e), !1);
958
940
  } catch (a) {
959
941
  return console.error("Zod schema validation failed", a), !1;
960
942
  }
@@ -971,9 +953,9 @@ function re(e, i, S, l) {
971
953
  if (d === "_isLoading")
972
954
  return n.getState().isLoadingGlobal[e];
973
955
  if (d === "revertToInitialState")
974
- return h.revertToInitialState;
975
- if (d === "updateInitialState") return h.updateInitialState;
976
- if (d === "removeValidation") return h.removeValidation;
956
+ return I.revertToInitialState;
957
+ if (d === "updateInitialState") return I.updateInitialState;
958
+ if (d === "removeValidation") return I.removeValidation;
977
959
  }
978
960
  if (d === "getFormRef")
979
961
  return () => Se.getState().getFormRef(e + "." + r.join("."));
@@ -982,7 +964,7 @@ function re(e, i, S, l) {
982
964
  children: u,
983
965
  hideMessage: t
984
966
  }) => /* @__PURE__ */ fe(
985
- Ce,
967
+ ke,
986
968
  {
987
969
  formOpts: t ? { validation: { message: "" } } : void 0,
988
970
  path: r,
@@ -994,11 +976,11 @@ function re(e, i, S, l) {
994
976
  );
995
977
  if (d === "_stateKey") return e;
996
978
  if (d === "_path") return r;
997
- if (d === "_isServerSynced") return h._isServerSynced;
979
+ if (d === "_isServerSynced") return I._isServerSynced;
998
980
  if (d === "update")
999
981
  return (u, t) => {
1000
982
  if (t?.debounce)
1001
- ke(() => {
983
+ Ve(() => {
1002
984
  X(i, u, r, "");
1003
985
  const o = n.getState().getNestedState(e, r);
1004
986
  t?.afterUpdate && t.afterUpdate(o);
@@ -1008,7 +990,7 @@ function re(e, i, S, l) {
1008
990
  const o = n.getState().getNestedState(e, r);
1009
991
  t?.afterUpdate && t.afterUpdate(o);
1010
992
  }
1011
- I(r);
993
+ p(r);
1012
994
  };
1013
995
  if (d === "formElement")
1014
996
  return (u, t) => /* @__PURE__ */ fe(
@@ -1024,18 +1006,18 @@ function re(e, i, S, l) {
1024
1006
  const k = [...r, d], H = n.getState().getNestedState(e, k);
1025
1007
  return s(H, k, m);
1026
1008
  }
1027
- }, M = new Proxy(x, O);
1028
- return c.set(D, {
1029
- proxy: M,
1009
+ }, j = new Proxy(P, x);
1010
+ return c.set(R, {
1011
+ proxy: j,
1030
1012
  stateVersion: b
1031
- }), M;
1013
+ }), j;
1032
1014
  }
1033
1015
  return s(
1034
1016
  n.getState().getNestedState(e, [])
1035
1017
  );
1036
1018
  }
1037
- function he(e) {
1038
- return oe(We, { proxy: e });
1019
+ function Ie(e) {
1020
+ return re(We, { proxy: e });
1039
1021
  }
1040
1022
  function Ge({
1041
1023
  proxy: e,
@@ -1046,7 +1028,7 @@ function Ge({
1046
1028
  S,
1047
1029
  e._path
1048
1030
  ).stateMapNoRender(
1049
- (c, b, I, h, s) => e._mapFn(c, b, I, h, s)
1031
+ (c, b, p, I, s) => e._mapFn(c, b, p, I, s)
1050
1032
  ) : null;
1051
1033
  }
1052
1034
  function We({
@@ -1056,16 +1038,16 @@ function We({
1056
1038
  return ce(() => {
1057
1039
  const l = i.current;
1058
1040
  if (!l || !l.parentElement) return;
1059
- const c = l.parentElement, I = Array.from(c.childNodes).indexOf(l);
1060
- let h = c.getAttribute("data-parent-id");
1061
- h || (h = `parent-${crypto.randomUUID()}`, c.setAttribute("data-parent-id", h));
1062
- const p = {
1041
+ const c = l.parentElement, p = Array.from(c.childNodes).indexOf(l);
1042
+ let I = c.getAttribute("data-parent-id");
1043
+ I || (I = `parent-${crypto.randomUUID()}`, c.setAttribute("data-parent-id", I));
1044
+ const h = {
1063
1045
  instanceId: `instance-${crypto.randomUUID()}`,
1064
- parentId: h,
1065
- position: I,
1046
+ parentId: I,
1047
+ position: p,
1066
1048
  effect: e._effect
1067
1049
  };
1068
- n.getState().addSignalElement(S, p);
1050
+ n.getState().addSignalElement(S, h);
1069
1051
  const r = n.getState().getNestedState(e._stateKey, e._path);
1070
1052
  let m;
1071
1053
  if (e._effect)
@@ -1074,22 +1056,22 @@ function We({
1074
1056
  "state",
1075
1057
  `return (${e._effect})(state)`
1076
1058
  )(r);
1077
- } catch (x) {
1078
- console.error("Error evaluating effect function during mount:", x), m = r;
1059
+ } catch (P) {
1060
+ console.error("Error evaluating effect function during mount:", P), m = r;
1079
1061
  }
1080
1062
  else
1081
1063
  m = r;
1082
1064
  m !== null && typeof m == "object" && (m = JSON.stringify(m));
1083
- const D = document.createTextNode(String(m));
1084
- l.replaceWith(D);
1085
- }, [e._stateKey, e._path.join("."), e._effect]), oe("span", {
1065
+ const R = document.createTextNode(String(m));
1066
+ l.replaceWith(R);
1067
+ }, [e._stateKey, e._path.join("."), e._effect]), re("span", {
1086
1068
  ref: i,
1087
1069
  style: { display: "none" },
1088
1070
  "data-signal-id": S
1089
1071
  });
1090
1072
  }
1091
1073
  function nt(e) {
1092
- const i = Ae(
1074
+ const i = $e(
1093
1075
  (S) => {
1094
1076
  const l = n.getState().stateComponents.get(e._stateKey) || {
1095
1077
  components: /* @__PURE__ */ new Map(),
@@ -1105,7 +1087,7 @@ function nt(e) {
1105
1087
  depsFunction: void 0,
1106
1088
  reactiveType: ["component"]
1107
1089
  }), l.pathTrie && ue(l.pathTrie, e._path.join("."), c), n.getState().stateComponents.set(e._stateKey, l), () => {
1108
- l.components.delete(c), l.pathTrie && Ee(
1090
+ l.components.delete(c), l.pathTrie && Ue(
1109
1091
  l.pathTrie,
1110
1092
  e._path.join("."),
1111
1093
  c
@@ -1114,14 +1096,14 @@ function nt(e) {
1114
1096
  },
1115
1097
  () => n.getState().getNestedState(e._stateKey, e._path)
1116
1098
  );
1117
- return oe("text", {}, String(i));
1099
+ return re("text", {}, String(i));
1118
1100
  }
1119
1101
  export {
1120
- he as $cogsSignal,
1102
+ Ie as $cogsSignal,
1121
1103
  nt as $cogsSignalStore,
1122
1104
  Ke as addStateOptions,
1123
1105
  et as createCogsState,
1124
1106
  tt as notifyComponent,
1125
- Ue as useCogsStateFn
1107
+ Me as useCogsStateFn
1126
1108
  };
1127
1109
  //# sourceMappingURL=CogsState.jsx.map