cogsbox-state 0.5.281 → 0.5.283

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.
@@ -2,17 +2,17 @@
2
2
  import { jsx as mt } from "react/jsx-runtime";
3
3
  import { useState as K, useRef as q, useEffect as st, useLayoutEffect as it, useMemo as Tt, createElement as rt, useSyncExternalStore as Ct, startTransition as Vt, useCallback as ft } from "react";
4
4
  import { transformStateFunc as bt, isDeepEqual as L, isFunction as J, getNestedValue as z, getDifferences as ht, debounce as xt } from "./utility.js";
5
- import { pushFunc as St, updateFn as nt, cutFunc as ot, ValidationWrapper as Pt, FormControlComponent as _t } from "./Functions.jsx";
5
+ import { pushFunc as St, updateFn as nt, cutFunc as at, ValidationWrapper as Pt, FormControlComponent as _t } from "./Functions.jsx";
6
6
  import Mt from "superjson";
7
7
  import { v4 as yt } from "uuid";
8
8
  import "zod";
9
- import { getGlobalStore as r, formRefStore as It } from "./store.js";
9
+ import { getGlobalStore as o, formRefStore as It } from "./store.js";
10
10
  import { useCogsConfig as $t } from "./CogsStateClient.jsx";
11
11
  import { applyPatch as jt } from "fast-json-patch";
12
12
  import Ot from "react-use-measure";
13
13
  function pt(t, c) {
14
- const h = r.getState().getInitialOptions, g = r.getState().setInitialStateOptions, v = h(t) || {};
15
- g(t, {
14
+ const h = o.getState().getInitialOptions, f = o.getState().setInitialStateOptions, v = h(t) || {};
15
+ f(t, {
16
16
  ...v,
17
17
  ...c
18
18
  });
@@ -22,20 +22,20 @@ function wt({
22
22
  options: c,
23
23
  initialOptionsPart: h
24
24
  }) {
25
- const g = Q(t) || {}, v = h[t] || {}, $ = r.getState().setInitialStateOptions, p = { ...v, ...g };
25
+ const f = Q(t) || {}, v = h[t] || {}, k = o.getState().setInitialStateOptions, p = { ...v, ...f };
26
26
  let I = !1;
27
27
  if (c)
28
- for (const o in c)
29
- p.hasOwnProperty(o) ? (o == "localStorage" && c[o] && p[o].key !== c[o]?.key && (I = !0, p[o] = c[o]), o == "initialState" && c[o] && p[o] !== c[o] && // Different references
30
- !L(p[o], c[o]) && (I = !0, p[o] = c[o])) : (I = !0, p[o] = c[o]);
31
- I && $(t, p);
28
+ for (const a in c)
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
+ !L(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 ae(t, { formElements: c, validation: h }) {
33
+ function oe(t, { formElements: c, validation: h }) {
34
34
  return { initialState: t, formElements: c, validation: h };
35
35
  }
36
- const oe = (t, c) => {
36
+ const ae = (t, c) => {
37
37
  let h = t;
38
- const [g, v] = bt(h);
38
+ const [f, v] = bt(h);
39
39
  (Object.keys(v).length > 0 || c && Object.keys(c).length > 0) && Object.keys(v).forEach((I) => {
40
40
  v[I] = v[I] || {}, v[I].formElements = {
41
41
  ...c?.formElements,
@@ -43,68 +43,68 @@ const oe = (t, c) => {
43
43
  ...c?.validation,
44
44
  ...v[I].formElements || {}
45
45
  // State-specific overrides
46
- }, Q(I) || r.getState().setInitialStateOptions(I, v[I]);
47
- }), r.getState().setInitialStates(g), r.getState().setCreatedState(g);
48
- const $ = (I, o) => {
49
- const [y] = K(o?.componentId ?? yt());
46
+ }, Q(I) || o.getState().setInitialStateOptions(I, v[I]);
47
+ }), o.getState().setInitialStates(f), o.getState().setCreatedState(f);
48
+ const k = (I, a) => {
49
+ const [y] = K(a?.componentId ?? yt());
50
50
  wt({
51
51
  stateKey: I,
52
- options: o,
52
+ options: a,
53
53
  initialOptionsPart: v
54
54
  });
55
- const a = r.getState().cogsStateStore[I] || g[I], S = o?.modifyState ? o.modifyState(a) : a, [D, O] = Lt(
55
+ const r = o.getState().cogsStateStore[I] || f[I], S = a?.modifyState ? a.modifyState(r) : r, [W, O] = Lt(
56
56
  S,
57
57
  {
58
58
  stateKey: I,
59
- syncUpdate: o?.syncUpdate,
59
+ syncUpdate: a?.syncUpdate,
60
60
  componentId: y,
61
- localStorage: o?.localStorage,
62
- middleware: o?.middleware,
63
- enabledSync: o?.enabledSync,
64
- reactiveType: o?.reactiveType,
65
- reactiveDeps: o?.reactiveDeps,
66
- initialState: o?.initialState,
67
- dependencies: o?.dependencies,
68
- serverState: o?.serverState
61
+ localStorage: a?.localStorage,
62
+ middleware: a?.middleware,
63
+ enabledSync: a?.enabledSync,
64
+ reactiveType: a?.reactiveType,
65
+ reactiveDeps: a?.reactiveDeps,
66
+ initialState: a?.initialState,
67
+ dependencies: a?.dependencies,
68
+ serverState: a?.serverState
69
69
  }
70
70
  );
71
71
  return O;
72
72
  };
73
- function p(I, o) {
74
- wt({ stateKey: I, options: o, initialOptionsPart: v }), o.localStorage && Wt(I, o), ut(I);
73
+ function p(I, a) {
74
+ wt({ stateKey: I, options: a, initialOptionsPart: v }), a.localStorage && Wt(I, a), ut(I);
75
75
  }
76
- return { useCogsState: $, setCogsOptions: p };
76
+ return { useCogsState: k, setCogsOptions: p };
77
77
  }, {
78
78
  setUpdaterState: ct,
79
79
  setState: Z,
80
80
  getInitialOptions: Q,
81
81
  getKeyState: kt,
82
- getValidationErrors: Ut,
83
- setStateLog: Rt,
82
+ getValidationErrors: Rt,
83
+ setStateLog: Ft,
84
84
  updateInitialStateGlobal: vt,
85
- addValidationError: Ft,
85
+ addValidationError: Ut,
86
86
  removeValidationError: H,
87
87
  setServerSyncActions: Dt
88
- } = r.getState(), Et = (t, c, h, g, v) => {
88
+ } = o.getState(), Et = (t, c, h, f, v) => {
89
89
  h?.log && console.log(
90
90
  "saving to localstorage",
91
91
  c,
92
92
  h.localStorage?.key,
93
- g
93
+ f
94
94
  );
95
- const $ = J(h?.localStorage?.key) ? h.localStorage?.key(t) : h?.localStorage?.key;
96
- if ($ && g) {
97
- const p = `${g}-${c}-${$}`;
95
+ const k = J(h?.localStorage?.key) ? h.localStorage?.key(t) : h?.localStorage?.key;
96
+ if (k && f) {
97
+ const p = `${f}-${c}-${k}`;
98
98
  let I;
99
99
  try {
100
100
  I = dt(p)?.lastSyncedWithServer;
101
101
  } catch {
102
102
  }
103
- const o = {
103
+ const a = {
104
104
  state: t,
105
105
  lastUpdated: Date.now(),
106
106
  lastSyncedWithServer: v ?? I
107
- }, y = Mt.serialize(o);
107
+ }, y = Mt.serialize(a);
108
108
  window.localStorage.setItem(
109
109
  p,
110
110
  JSON.stringify(y.json)
@@ -119,60 +119,60 @@ const oe = (t, c) => {
119
119
  return console.error("Error loading from localStorage:", c), null;
120
120
  }
121
121
  }, Wt = (t, c) => {
122
- const h = r.getState().cogsStateStore[t], { sessionId: g } = $t(), v = J(c?.localStorage?.key) ? c.localStorage.key(h) : c?.localStorage?.key;
123
- if (v && g) {
124
- const $ = dt(
125
- `${g}-${t}-${v}`
122
+ const h = o.getState().cogsStateStore[t], { sessionId: f } = $t(), v = J(c?.localStorage?.key) ? c.localStorage.key(h) : c?.localStorage?.key;
123
+ if (v && f) {
124
+ const k = dt(
125
+ `${f}-${t}-${v}`
126
126
  );
127
- if ($ && $.lastUpdated > ($.lastSyncedWithServer || 0))
128
- return Z(t, $.state), ut(t), !0;
127
+ if (k && k.lastUpdated > (k.lastSyncedWithServer || 0))
128
+ return Z(t, k.state), ut(t), !0;
129
129
  }
130
130
  return !1;
131
- }, Nt = (t, c, h, g, v, $) => {
131
+ }, Nt = (t, c, h, f, v, k) => {
132
132
  const p = {
133
133
  initialState: c,
134
134
  updaterState: lt(
135
135
  t,
136
- g,
136
+ f,
137
137
  v,
138
- $
138
+ k
139
139
  ),
140
140
  state: h
141
141
  };
142
142
  vt(t, p.initialState), ct(t, p.updaterState), Z(t, p.state);
143
143
  }, ut = (t) => {
144
- const c = r.getState().stateComponents.get(t);
144
+ const c = o.getState().stateComponents.get(t);
145
145
  if (!c) return;
146
146
  const h = /* @__PURE__ */ new Set();
147
- c.components.forEach((g) => {
148
- (g ? Array.isArray(g.reactiveType) ? g.reactiveType : [g.reactiveType || "component"] : null)?.includes("none") || h.add(() => g.forceUpdate());
147
+ c.components.forEach((f) => {
148
+ (f ? Array.isArray(f.reactiveType) ? f.reactiveType : [f.reactiveType || "component"] : null)?.includes("none") || h.add(() => f.forceUpdate());
149
149
  }), queueMicrotask(() => {
150
- h.forEach((g) => g());
150
+ h.forEach((f) => f());
151
151
  });
152
152
  }, se = (t, c) => {
153
- const h = r.getState().stateComponents.get(t);
153
+ const h = o.getState().stateComponents.get(t);
154
154
  if (h) {
155
- const g = `${t}////${c}`, v = h.components.get(g);
155
+ const f = `${t}////${c}`, v = h.components.get(f);
156
156
  if ((v ? Array.isArray(v.reactiveType) ? v.reactiveType : [v.reactiveType || "component"] : null)?.includes("none"))
157
157
  return;
158
158
  v && v.forceUpdate();
159
159
  }
160
- }, Gt = (t, c, h, g) => {
160
+ }, Gt = (t, c, h, f) => {
161
161
  switch (t) {
162
162
  case "update":
163
163
  return {
164
- oldValue: z(c, g),
165
- newValue: z(h, g)
164
+ oldValue: z(c, f),
165
+ newValue: z(h, f)
166
166
  };
167
167
  case "insert":
168
168
  return {
169
169
  oldValue: null,
170
170
  // or undefined
171
- newValue: z(h, g)
171
+ newValue: z(h, f)
172
172
  };
173
173
  case "cut":
174
174
  return {
175
- oldValue: z(c, g),
175
+ oldValue: z(c, f),
176
176
  newValue: null
177
177
  // or undefined
178
178
  };
@@ -183,19 +183,19 @@ const oe = (t, c) => {
183
183
  function Lt(t, {
184
184
  stateKey: c,
185
185
  serverSync: h,
186
- localStorage: g,
186
+ localStorage: f,
187
187
  formElements: v,
188
- reactiveDeps: $,
188
+ reactiveDeps: k,
189
189
  reactiveType: p,
190
190
  componentId: I,
191
- initialState: o,
191
+ initialState: a,
192
192
  syncUpdate: y,
193
- dependencies: a,
193
+ dependencies: r,
194
194
  serverState: S
195
195
  } = {}) {
196
- const [D, O] = K({}), { sessionId: U } = $t();
197
- let W = !c;
198
- const [m] = K(c ?? yt()), l = r.getState().stateLog[m], at = q(/* @__PURE__ */ new Set()), Y = q(I ?? yt()), j = q(
196
+ const [W, O] = K({}), { sessionId: R } = $t();
197
+ let G = !c;
198
+ const [m] = K(c ?? yt()), l = o.getState().stateLog[m], ot = q(/* @__PURE__ */ new Set()), Y = q(I ?? yt()), j = q(
199
199
  null
200
200
  );
201
201
  j.current = Q(m) ?? null, st(() => {
@@ -205,182 +205,168 @@ function Lt(t, {
205
205
  [y.path[0]]: y.newValue
206
206
  }));
207
207
  const e = `${y.stateKey}:${y.path.join(".")}`;
208
- r.getState().setSyncInfo(e, {
208
+ o.getState().setSyncInfo(e, {
209
209
  timeStamp: y.timeStamp,
210
210
  userId: y.userId
211
211
  });
212
212
  }
213
213
  }, [y]), st(() => {
214
- if (o) {
214
+ if (a) {
215
215
  pt(m, {
216
- initialState: o
216
+ initialState: a
217
217
  });
218
- const e = j.current, s = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, i = r.getState().initialStateGlobal[m];
219
- if (!(i && !L(i, o) || !i) && !s)
218
+ const e = j.current, s = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, i = o.getState().initialStateGlobal[m];
219
+ if (!(i && !L(i, a) || !i) && !s)
220
220
  return;
221
- let d = null;
222
- const k = J(e?.localStorage?.key) ? e?.localStorage?.key(o) : e?.localStorage?.key;
223
- k && U && (d = dt(`${U}-${m}-${k}`));
224
- let w = o, T = !1;
225
- const x = s ? Date.now() : 0, C = d?.lastUpdated || 0, V = d?.lastSyncedWithServer || 0;
226
- s && x > C ? (w = e.serverState.data, T = !0) : d && C > V && (w = d.state, e?.localStorage?.onChange && e?.localStorage?.onChange(w)), r.getState().initializeShadowState(m, o), Nt(
221
+ let u = null;
222
+ const E = J(e?.localStorage?.key) ? e?.localStorage?.key(a) : e?.localStorage?.key;
223
+ E && R && (u = dt(`${R}-${m}-${E}`));
224
+ let w = a, $ = !1;
225
+ const x = s ? Date.now() : 0, C = u?.lastUpdated || 0, V = u?.lastSyncedWithServer || 0;
226
+ s && x > C ? (w = e.serverState.data, $ = !0) : u && C > V && (w = u.state, e?.localStorage?.onChange && e?.localStorage?.onChange(w)), o.getState().initializeShadowState(m, a), Nt(
227
227
  m,
228
- o,
228
+ a,
229
229
  w,
230
230
  tt,
231
231
  Y.current,
232
- U
233
- ), T && k && U && Et(w, m, e, U, Date.now()), ut(m), (Array.isArray(p) ? p : [p || "component"]).includes("none") || O({});
232
+ R
233
+ ), $ && E && R && Et(w, m, e, R, Date.now()), ut(m), (Array.isArray(p) ? p : [p || "component"]).includes("none") || O({});
234
234
  }
235
235
  }, [
236
- o,
236
+ a,
237
237
  S?.status,
238
238
  S?.data,
239
- ...a || []
239
+ ...r || []
240
240
  ]), it(() => {
241
- W && pt(m, {
241
+ G && pt(m, {
242
242
  serverSync: h,
243
243
  formElements: v,
244
- initialState: o,
245
- localStorage: g,
244
+ initialState: a,
245
+ localStorage: f,
246
246
  middleware: j.current?.middleware
247
247
  });
248
- const e = `${m}////${Y.current}`, n = r.getState().stateComponents.get(m) || {
248
+ const e = `${m}////${Y.current}`, n = o.getState().stateComponents.get(m) || {
249
249
  components: /* @__PURE__ */ new Map()
250
250
  };
251
251
  return n.components.set(e, {
252
252
  forceUpdate: () => O({}),
253
253
  paths: /* @__PURE__ */ new Set(),
254
254
  deps: [],
255
- depsFunction: $ || void 0,
255
+ depsFunction: k || void 0,
256
256
  reactiveType: p ?? ["component", "deps"]
257
- }), r.getState().stateComponents.set(m, n), O({}), () => {
258
- n && (n.components.delete(e), n.components.size === 0 && r.getState().stateComponents.delete(m));
257
+ }), o.getState().stateComponents.set(m, n), O({}), () => {
258
+ n && (n.components.delete(e), n.components.size === 0 && o.getState().stateComponents.delete(m));
259
259
  };
260
260
  }, []);
261
261
  const tt = (e, n, s, i) => {
262
262
  if (Array.isArray(n)) {
263
- const f = `${m}-${n.join(".")}`;
264
- at.current.add(f);
263
+ const u = `${m}-${n.join(".")}`;
264
+ ot.current.add(u);
265
265
  }
266
- Z(m, (f) => {
267
- const d = J(e) ? e(f) : e, k = `${m}-${n.join(".")}`;
268
- if (k) {
269
- let _ = !1, N = r.getState().signalDomElements.get(k);
266
+ const g = o.getState();
267
+ Z(m, (u) => {
268
+ const E = J(e) ? e(u) : e, w = `${m}-${n.join(".")}`;
269
+ if (w) {
270
+ let M = !1, N = g.signalDomElements.get(w);
270
271
  if ((!N || N.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
271
- const A = n.slice(0, -1), P = z(d, A);
272
- if (Array.isArray(P)) {
273
- _ = !0;
274
- const E = `${m}-${A.join(".")}`;
275
- N = r.getState().signalDomElements.get(E);
272
+ const T = n.slice(0, -1), _ = z(E, T);
273
+ if (Array.isArray(_)) {
274
+ M = !0;
275
+ const A = `${m}-${T.join(".")}`;
276
+ N = g.signalDomElements.get(A);
276
277
  }
277
278
  }
278
279
  if (N) {
279
- const A = _ ? z(d, n.slice(0, -1)) : z(d, n);
280
- N.forEach(({ parentId: P, position: E, effect: M }) => {
280
+ const T = M ? z(E, n.slice(0, -1)) : z(E, n);
281
+ N.forEach(({ parentId: _, position: A, effect: P }) => {
281
282
  const b = document.querySelector(
282
- `[data-parent-id="${P}"]`
283
+ `[data-parent-id="${_}"]`
283
284
  );
284
285
  if (b) {
285
- const F = Array.from(b.childNodes);
286
- if (F[E]) {
287
- const R = M ? new Function("state", `return (${M})(state)`)(A) : A;
288
- F[E].textContent = String(R);
286
+ const U = Array.from(b.childNodes);
287
+ if (U[A]) {
288
+ const F = P ? new Function("state", `return (${P})(state)`)(T) : T;
289
+ U[A].textContent = String(F);
289
290
  }
290
291
  }
291
292
  });
292
293
  }
293
294
  }
294
- (() => {
295
- const _ = r.getState();
296
- switch (s.updateType) {
297
- case "update":
298
- _.updateShadowAtPath(m, n, d);
299
- break;
300
- case "insert":
301
- const N = n.slice(0, -1);
302
- _.insertShadowArrayElement(m, N);
303
- break;
304
- case "cut":
305
- const A = n.slice(0, -1), P = parseInt(n[n.length - 1]);
306
- _.removeShadowArrayElement(m, A, P);
307
- break;
308
- }
309
- })(), console.log("shadowState", r.getState().shadowStateStore), s.updateType === "update" && (i || j.current?.validation?.key) && n && H(
295
+ console.log("shadowState", g.shadowStateStore), s.updateType === "update" && (i || j.current?.validation?.key) && n && H(
310
296
  (i || j.current?.validation?.key) + "." + n.join(".")
311
297
  );
312
- const T = n.slice(0, n.length - 1);
298
+ const $ = n.slice(0, n.length - 1);
313
299
  s.updateType === "cut" && j.current?.validation?.key && H(
314
- j.current?.validation?.key + "." + T.join(".")
315
- ), s.updateType === "insert" && j.current?.validation?.key && Ut(
316
- j.current?.validation?.key + "." + T.join(".")
317
- ).filter(([N, A]) => {
318
- let P = N?.split(".").length;
319
- if (N == T.join(".") && P == T.length - 1) {
320
- let E = N + "." + T;
321
- H(N), Ft(E, A);
300
+ j.current?.validation?.key + "." + $.join(".")
301
+ ), s.updateType === "insert" && j.current?.validation?.key && Rt(
302
+ j.current?.validation?.key + "." + $.join(".")
303
+ ).filter(([N, T]) => {
304
+ let _ = N?.split(".").length;
305
+ if (N == $.join(".") && _ == $.length - 1) {
306
+ let A = N + "." + $;
307
+ H(N), Ut(A, T);
322
308
  }
323
309
  });
324
- const x = r.getState().stateComponents.get(m);
310
+ const x = g.stateComponents.get(m);
325
311
  if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", x), x) {
326
- const _ = ht(f, d), N = new Set(_), A = s.updateType === "update" ? n.join(".") : n.slice(0, -1).join(".") || "";
312
+ const M = ht(u, E), N = new Set(M), T = s.updateType === "update" ? n.join(".") : n.slice(0, -1).join(".") || "";
327
313
  for (const [
328
- P,
329
- E
314
+ _,
315
+ A
330
316
  ] of x.components.entries()) {
331
- let M = !1;
332
- const b = Array.isArray(E.reactiveType) ? E.reactiveType : [E.reactiveType || "component"];
333
- if (console.log("component", E), !b.includes("none")) {
317
+ let P = !1;
318
+ const b = Array.isArray(A.reactiveType) ? A.reactiveType : [A.reactiveType || "component"];
319
+ if (console.log("component", A), !b.includes("none")) {
334
320
  if (b.includes("all")) {
335
- E.forceUpdate();
321
+ A.forceUpdate();
336
322
  continue;
337
323
  }
338
- if (b.includes("component") && ((E.paths.has(A) || E.paths.has("")) && (M = !0), !M))
339
- for (const F of N) {
340
- let R = F;
324
+ if (b.includes("component") && ((A.paths.has(T) || A.paths.has("")) && (P = !0), !P))
325
+ for (const U of N) {
326
+ let F = U;
341
327
  for (; ; ) {
342
- if (E.paths.has(R)) {
343
- M = !0;
328
+ if (A.paths.has(F)) {
329
+ P = !0;
344
330
  break;
345
331
  }
346
- const X = R.lastIndexOf(".");
332
+ const X = F.lastIndexOf(".");
347
333
  if (X !== -1) {
348
- const et = R.substring(
334
+ const et = F.substring(
349
335
  0,
350
336
  X
351
337
  );
352
338
  if (!isNaN(
353
- Number(R.substring(X + 1))
354
- ) && E.paths.has(et)) {
355
- M = !0;
339
+ Number(F.substring(X + 1))
340
+ ) && A.paths.has(et)) {
341
+ P = !0;
356
342
  break;
357
343
  }
358
- R = et;
344
+ F = et;
359
345
  } else
360
- R = "";
361
- if (R === "")
346
+ F = "";
347
+ if (F === "")
362
348
  break;
363
349
  }
364
- if (M) break;
350
+ if (P) break;
365
351
  }
366
- if (!M && b.includes("deps") && E.depsFunction) {
367
- const F = E.depsFunction(d);
368
- let R = !1;
369
- typeof F == "boolean" ? F && (R = !0) : L(E.deps, F) || (E.deps = F, R = !0), R && (M = !0);
352
+ if (!P && b.includes("deps") && A.depsFunction) {
353
+ const U = A.depsFunction(E);
354
+ let F = !1;
355
+ typeof U == "boolean" ? U && (F = !0) : L(A.deps, U) || (A.deps = U, F = !0), F && (P = !0);
370
356
  }
371
- M && E.forceUpdate();
357
+ P && A.forceUpdate();
372
358
  }
373
359
  }
374
360
  }
375
361
  const C = Date.now();
376
- n = n.map((_, N) => {
377
- const A = n.slice(0, -1), P = z(d, A);
378
- return N === n.length - 1 && ["insert", "cut"].includes(s.updateType) ? (P.length - 1).toString() : _;
362
+ n = n.map((M, N) => {
363
+ const T = n.slice(0, -1), _ = z(E, T);
364
+ return N === n.length - 1 && ["insert", "cut"].includes(s.updateType) ? (_.length - 1).toString() : M;
379
365
  });
380
- const { oldValue: V, newValue: G } = Gt(
366
+ const { oldValue: V, newValue: D } = Gt(
381
367
  s.updateType,
382
- f,
383
- d,
368
+ u,
369
+ E,
384
370
  n
385
371
  ), B = {
386
372
  timeStamp: C,
@@ -389,119 +375,132 @@ function Lt(t, {
389
375
  updateType: s.updateType,
390
376
  status: "new",
391
377
  oldValue: V,
392
- newValue: G
378
+ newValue: D
393
379
  };
394
- if (Rt(m, (_) => {
395
- const A = [..._ ?? [], B].reduce((P, E) => {
396
- const M = `${E.stateKey}:${JSON.stringify(E.path)}`, b = P.get(M);
397
- return b ? (b.timeStamp = Math.max(b.timeStamp, E.timeStamp), b.newValue = E.newValue, b.oldValue = b.oldValue ?? E.oldValue, b.updateType = E.updateType) : P.set(M, { ...E }), P;
380
+ switch (s.updateType) {
381
+ case "update":
382
+ g.updateShadowAtPath(m, n, E);
383
+ break;
384
+ case "insert":
385
+ const M = n.slice(0, -1);
386
+ g.insertShadowArrayElement(m, M, D);
387
+ break;
388
+ case "cut":
389
+ const N = n.slice(0, -1), T = parseInt(n[n.length - 1]);
390
+ g.removeShadowArrayElement(m, N, T);
391
+ break;
392
+ }
393
+ if (Ft(m, (M) => {
394
+ const T = [...M ?? [], B].reduce((_, A) => {
395
+ const P = `${A.stateKey}:${JSON.stringify(A.path)}`, b = _.get(P);
396
+ return b ? (b.timeStamp = Math.max(b.timeStamp, A.timeStamp), b.newValue = A.newValue, b.oldValue = b.oldValue ?? A.oldValue, b.updateType = A.updateType) : _.set(P, { ...A }), _;
398
397
  }, /* @__PURE__ */ new Map());
399
- return Array.from(A.values());
398
+ return Array.from(T.values());
400
399
  }), Et(
401
- d,
400
+ E,
402
401
  m,
403
402
  j.current,
404
- U
403
+ R
405
404
  ), j.current?.middleware && j.current.middleware({
406
405
  updateLog: l,
407
406
  update: B
408
407
  }), j.current?.serverSync) {
409
- const _ = r.getState().serverState[m], N = j.current?.serverSync;
408
+ const M = g.serverState[m], N = j.current?.serverSync;
410
409
  Dt(m, {
411
- syncKey: typeof N.syncKey == "string" ? N.syncKey : N.syncKey({ state: d }),
412
- rollBackState: _,
410
+ syncKey: typeof N.syncKey == "string" ? N.syncKey : N.syncKey({ state: E }),
411
+ rollBackState: M,
413
412
  actionTimeStamp: Date.now() + (N.debounce ?? 3e3),
414
413
  status: "waiting"
415
414
  });
416
415
  }
417
- return d;
416
+ return E;
418
417
  });
419
418
  };
420
- r.getState().updaterState[m] || (ct(
419
+ o.getState().updaterState[m] || (ct(
421
420
  m,
422
421
  lt(
423
422
  m,
424
423
  tt,
425
424
  Y.current,
426
- U
425
+ R
427
426
  )
428
- ), r.getState().cogsStateStore[m] || Z(m, t), r.getState().initialStateGlobal[m] || vt(m, t));
429
- const u = Tt(() => lt(
427
+ ), o.getState().cogsStateStore[m] || Z(m, t), o.getState().initialStateGlobal[m] || vt(m, t));
428
+ const d = Tt(() => lt(
430
429
  m,
431
430
  tt,
432
431
  Y.current,
433
- U
434
- ), [m, U]);
435
- return [kt(m), u];
432
+ R
433
+ ), [m, R]);
434
+ return [kt(m), d];
436
435
  }
437
- function lt(t, c, h, g) {
436
+ function lt(t, c, h, f) {
438
437
  const v = /* @__PURE__ */ new Map();
439
- let $ = 0;
438
+ let k = 0;
440
439
  const p = (y) => {
441
- const a = y.join(".");
440
+ const r = y.join(".");
442
441
  for (const [S] of v)
443
- (S === a || S.startsWith(a + ".")) && v.delete(S);
444
- $++;
442
+ (S === r || S.startsWith(r + ".")) && v.delete(S);
443
+ k++;
445
444
  }, I = {
446
445
  removeValidation: (y) => {
447
446
  y?.validationKey && H(y.validationKey);
448
447
  },
449
448
  revertToInitialState: (y) => {
450
- const a = r.getState().getInitialOptions(t)?.validation;
451
- a?.key && H(a?.key), y?.validationKey && H(y.validationKey);
452
- const S = r.getState().initialStateGlobal[t];
453
- r.getState().clearSelectedIndexesForState(t), v.clear(), $++;
454
- const D = o(S, []), O = Q(t), U = J(O?.localStorage?.key) ? O?.localStorage?.key(S) : O?.localStorage?.key, W = `${g}-${t}-${U}`;
455
- W && localStorage.removeItem(W), ct(t, D), Z(t, S);
456
- const m = r.getState().stateComponents.get(t);
449
+ const r = o.getState().getInitialOptions(t)?.validation;
450
+ r?.key && H(r?.key), y?.validationKey && H(y.validationKey);
451
+ const S = o.getState().initialStateGlobal[t];
452
+ o.getState().clearSelectedIndexesForState(t), v.clear(), k++;
453
+ const W = a(S, []), O = Q(t), R = J(O?.localStorage?.key) ? O?.localStorage?.key(S) : O?.localStorage?.key, G = `${f}-${t}-${R}`;
454
+ G && localStorage.removeItem(G), ct(t, W), Z(t, S);
455
+ const m = o.getState().stateComponents.get(t);
457
456
  return m && m.components.forEach((l) => {
458
457
  l.forceUpdate();
459
458
  }), S;
460
459
  },
461
460
  updateInitialState: (y) => {
462
- v.clear(), $++;
463
- const a = lt(
461
+ v.clear(), k++;
462
+ const r = lt(
464
463
  t,
465
464
  c,
466
465
  h,
467
- g
468
- ), S = r.getState().initialStateGlobal[t], D = Q(t), O = J(D?.localStorage?.key) ? D?.localStorage?.key(S) : D?.localStorage?.key, U = `${g}-${t}-${O}`;
469
- return localStorage.getItem(U) && localStorage.removeItem(U), Vt(() => {
470
- vt(t, y), r.getState().initializeShadowState(t, y), ct(t, a), Z(t, y);
471
- const W = r.getState().stateComponents.get(t);
472
- W && W.components.forEach((m) => {
466
+ f
467
+ ), S = o.getState().initialStateGlobal[t], W = Q(t), O = J(W?.localStorage?.key) ? W?.localStorage?.key(S) : W?.localStorage?.key, R = `${f}-${t}-${O}`;
468
+ return localStorage.getItem(R) && localStorage.removeItem(R), Vt(() => {
469
+ vt(t, y), o.getState().initializeShadowState(t, y), ct(t, r), Z(t, y);
470
+ const G = o.getState().stateComponents.get(t);
471
+ G && G.components.forEach((m) => {
473
472
  m.forceUpdate();
474
473
  });
475
474
  }), {
476
- fetchId: (W) => a.get()[W]
475
+ fetchId: (G) => r.get()[G]
477
476
  };
478
477
  },
479
- _initialState: r.getState().initialStateGlobal[t],
480
- _serverState: r.getState().serverState[t],
481
- _isLoading: r.getState().isLoadingGlobal[t],
478
+ _initialState: o.getState().initialStateGlobal[t],
479
+ _serverState: o.getState().serverState[t],
480
+ _isLoading: o.getState().isLoadingGlobal[t],
482
481
  _isServerSynced: () => {
483
- const y = r.getState().serverState[t];
482
+ const y = o.getState().serverState[t];
484
483
  return !!(y && L(y, kt(t)));
485
484
  }
486
485
  };
487
- function o(y, a = [], S) {
488
- const D = a.map(String).join(".");
489
- v.get(D);
486
+ function a(y, r = [], S) {
487
+ const W = r.map(String).join(".");
488
+ v.get(W);
490
489
  const O = function() {
491
- return r().getNestedState(t, a);
490
+ return o().getNestedState(t, r);
492
491
  };
493
492
  Object.keys(I).forEach((m) => {
494
493
  O[m] = I[m];
495
494
  });
496
- const U = {
497
- apply(m, l, at) {
495
+ const R = {
496
+ apply(m, l, ot) {
498
497
  return console.log(
499
- `PROXY APPLY TRAP HIT: stateKey=${t}, path=${a.join(".")}`
500
- ), console.trace("Apply trap stack trace"), r().getNestedState(t, a);
498
+ `PROXY APPLY TRAP HIT: stateKey=${t}, path=${r.join(".")}`
499
+ ), console.trace("Apply trap stack trace"), o().getNestedState(t, r);
501
500
  },
502
501
  get(m, l) {
503
502
  S?.validIndices && !Array.isArray(y) && (S = { ...S, validIndices: void 0 });
504
- const at = /* @__PURE__ */ new Set([
503
+ const ot = /* @__PURE__ */ new Set([
505
504
  "insert",
506
505
  "cut",
507
506
  "cutByValue",
@@ -524,15 +523,15 @@ function lt(t, c, h, g) {
524
523
  "_stateKey",
525
524
  "getComponents"
526
525
  ]);
527
- if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !at.has(l)) {
528
- const u = `${t}////${h}`, e = r.getState().stateComponents.get(t);
526
+ if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !ot.has(l)) {
527
+ const d = `${t}////${h}`, e = o.getState().stateComponents.get(t);
529
528
  if (e) {
530
- const n = e.components.get(u);
529
+ const n = e.components.get(d);
531
530
  if (n && !n.paths.has("")) {
532
- const s = a.join(".");
531
+ const s = r.join(".");
533
532
  let i = !0;
534
- for (const f of n.paths)
535
- if (s.startsWith(f) && (s === f || s[f.length] === ".")) {
533
+ for (const g of n.paths)
534
+ if (s.startsWith(g) && (s === g || s[g.length] === ".")) {
536
535
  i = !1;
537
536
  break;
538
537
  }
@@ -542,25 +541,25 @@ function lt(t, c, h, g) {
542
541
  }
543
542
  if (l === "getDifferences")
544
543
  return () => ht(
545
- r.getState().cogsStateStore[t],
546
- r.getState().initialStateGlobal[t]
544
+ o.getState().cogsStateStore[t],
545
+ o.getState().initialStateGlobal[t]
547
546
  );
548
- if (l === "sync" && a.length === 0)
547
+ if (l === "sync" && r.length === 0)
549
548
  return async function() {
550
- const u = r.getState().getInitialOptions(t), e = u?.sync;
549
+ const d = o.getState().getInitialOptions(t), e = d?.sync;
551
550
  if (!e)
552
551
  return console.error(`No mutation defined for state key "${t}"`), { success: !1, error: "No mutation defined" };
553
- const n = r.getState().getNestedState(t, []), s = u?.validation?.key;
552
+ const n = o.getState().getNestedState(t, []), s = d?.validation?.key;
554
553
  try {
555
554
  const i = await e.action(n);
556
555
  if (i && !i.success && i.errors && s) {
557
- r.getState().removeValidationError(s), i.errors.forEach((d) => {
558
- const k = [s, ...d.path].join(".");
559
- r.getState().addValidationError(k, d.message);
556
+ o.getState().removeValidationError(s), i.errors.forEach((u) => {
557
+ const E = [s, ...u.path].join(".");
558
+ o.getState().addValidationError(E, u.message);
560
559
  });
561
- const f = r.getState().stateComponents.get(t);
562
- f && f.components.forEach((d) => {
563
- d.forceUpdate();
560
+ const g = o.getState().stateComponents.get(t);
561
+ g && g.components.forEach((u) => {
562
+ u.forceUpdate();
564
563
  });
565
564
  }
566
565
  return i?.success && e.onSuccess ? e.onSuccess(i.data) : !i?.success && e.onError && e.onError(i.error), i;
@@ -569,125 +568,125 @@ function lt(t, c, h, g) {
569
568
  }
570
569
  };
571
570
  if (l === "_status") {
572
- const u = r.getState().getNestedState(t, a), e = r.getState().initialStateGlobal[t], n = z(e, a);
573
- return L(u, n) ? "fresh" : "stale";
571
+ const d = o.getState().getNestedState(t, r), e = o.getState().initialStateGlobal[t], n = z(e, r);
572
+ return L(d, n) ? "fresh" : "stale";
574
573
  }
575
574
  if (l === "getStatus")
576
575
  return function() {
577
- const u = r().getNestedState(
576
+ const d = o().getNestedState(
578
577
  t,
579
- a
580
- ), e = r.getState().initialStateGlobal[t], n = z(e, a);
581
- return L(u, n) ? "fresh" : "stale";
578
+ r
579
+ ), e = o.getState().initialStateGlobal[t], n = z(e, r);
580
+ return L(d, n) ? "fresh" : "stale";
582
581
  };
583
582
  if (l === "removeStorage")
584
583
  return () => {
585
- const u = r.getState().initialStateGlobal[t], e = Q(t), n = J(e?.localStorage?.key) ? e?.localStorage?.key(u) : e?.localStorage?.key, s = `${g}-${t}-${n}`;
584
+ const d = o.getState().initialStateGlobal[t], e = Q(t), n = J(e?.localStorage?.key) ? e?.localStorage?.key(d) : e?.localStorage?.key, s = `${f}-${t}-${n}`;
586
585
  s && localStorage.removeItem(s);
587
586
  };
588
587
  if (l === "showValidationErrors")
589
588
  return () => {
590
- const u = r.getState().getInitialOptions(t)?.validation;
591
- if (!u?.key)
589
+ const d = o.getState().getInitialOptions(t)?.validation;
590
+ if (!d?.key)
592
591
  throw new Error("Validation key not found");
593
- return r.getState().getValidationErrors(u.key + "." + a.join("."));
592
+ return o.getState().getValidationErrors(d.key + "." + r.join("."));
594
593
  };
595
594
  if (Array.isArray(y)) {
596
- const u = () => S?.validIndices ? y.map((n, s) => ({
595
+ const d = () => S?.validIndices ? y.map((n, s) => ({
597
596
  item: n,
598
597
  originalIndex: S.validIndices[s]
599
- })) : r.getState().getNestedState(t, a).map((n, s) => ({
598
+ })) : o.getState().getNestedState(t, r).map((n, s) => ({
600
599
  item: n,
601
600
  originalIndex: s
602
601
  }));
603
602
  if (l === "getSelected")
604
603
  return () => {
605
- const e = r.getState().getSelectedIndex(t, a.join("."));
604
+ const e = o.getState().getSelectedIndex(t, r.join("."));
606
605
  if (e !== void 0)
607
- return o(
606
+ return a(
608
607
  y[e],
609
- [...a, e.toString()],
608
+ [...r, e.toString()],
610
609
  S
611
610
  );
612
611
  };
613
612
  if (l === "clearSelected")
614
613
  return () => {
615
- r.getState().clearSelectedIndex({ stateKey: t, path: a });
614
+ o.getState().clearSelectedIndex({ stateKey: t, path: r });
616
615
  };
617
616
  if (l === "getSelectedIndex")
618
- return () => r.getState().getSelectedIndex(t, a.join(".")) ?? -1;
617
+ return () => o.getState().getSelectedIndex(t, r.join(".")) ?? -1;
619
618
  if (l === "useVirtualView")
620
619
  return (e) => {
621
620
  const {
622
621
  itemHeight: n,
623
622
  overscan: s = 5,
624
623
  stickToBottom: i = !1
625
- } = e, f = q(null), [d, k] = K({
624
+ } = e, g = q(null), [u, E] = K({
626
625
  startIndex: 0,
627
626
  endIndex: 10
628
627
  });
629
- ft((A) => r.getState().getShadowMetadata(t, [...a, A.toString()])?.virtualizer?.itemHeight || e.itemHeight, []);
630
- const w = q(i), T = q(0), x = q(!0), C = r().getNestedState(
628
+ ft((T) => o.getState().getShadowMetadata(t, [...r, T.toString()])?.virtualizer?.itemHeight || e.itemHeight, []);
629
+ const w = q(i), $ = q(0), x = q(!0), C = o().getNestedState(
631
630
  t,
632
- a
633
- ), V = C.length, G = Tt(() => {
634
- const A = Math.max(0, d.startIndex), P = Math.min(V, d.endIndex), E = Array.from(
635
- { length: P - A },
636
- (b, F) => A + F
637
- ), M = E.map((b) => C[b]);
638
- return o(M, a, {
631
+ r
632
+ ), V = C.length, D = Tt(() => {
633
+ const T = Math.max(0, u.startIndex), _ = Math.min(V, u.endIndex), A = Array.from(
634
+ { length: _ - T },
635
+ (b, U) => T + U
636
+ ), P = A.map((b) => C[b]);
637
+ return a(P, r, {
639
638
  ...S,
640
- validIndices: E
639
+ validIndices: A
641
640
  });
642
- }, [d.startIndex, d.endIndex, C, V]);
641
+ }, [u.startIndex, u.endIndex, C, V]);
643
642
  it(() => {
644
- const A = f.current;
645
- if (!A) return;
646
- const P = w.current, E = V > T.current;
647
- T.current = V;
648
- const M = () => {
649
- const { scrollTop: b, clientHeight: F, scrollHeight: R } = A;
650
- w.current = R - b - F < 10;
643
+ const T = g.current;
644
+ if (!T) return;
645
+ const _ = w.current, A = V > $.current;
646
+ $.current = V;
647
+ const P = () => {
648
+ const { scrollTop: b, clientHeight: U, scrollHeight: F } = T;
649
+ w.current = F - b - U < 10;
651
650
  const X = Math.max(
652
651
  0,
653
652
  Math.floor(b / n) - s
654
653
  ), et = Math.min(
655
654
  V,
656
- Math.ceil((b + F) / n) + s
655
+ Math.ceil((b + U) / n) + s
657
656
  );
658
- k((gt) => gt.startIndex !== X || gt.endIndex !== et ? { startIndex: X, endIndex: et } : gt);
657
+ E((gt) => gt.startIndex !== X || gt.endIndex !== et ? { startIndex: X, endIndex: et } : gt);
659
658
  };
660
- return A.addEventListener("scroll", M, {
659
+ return T.addEventListener("scroll", P, {
661
660
  passive: !0
662
- }), i && (x.current ? A.scrollTo({
663
- top: A.scrollHeight,
661
+ }), i && (x.current ? T.scrollTo({
662
+ top: T.scrollHeight,
664
663
  behavior: "auto"
665
- }) : P && E && requestAnimationFrame(() => {
666
- A.scrollTo({
667
- top: A.scrollHeight,
664
+ }) : _ && A && requestAnimationFrame(() => {
665
+ T.scrollTo({
666
+ top: T.scrollHeight,
668
667
  behavior: "smooth"
669
668
  });
670
- })), x.current = !1, M(), () => A.removeEventListener("scroll", M);
669
+ })), x.current = !1, P(), () => T.removeEventListener("scroll", P);
671
670
  }, [V, n, s, i]);
672
671
  const B = ft(
673
- (A = "smooth") => {
674
- f.current && f.current.scrollTo({
675
- top: f.current.scrollHeight,
676
- behavior: A
672
+ (T = "smooth") => {
673
+ g.current && g.current.scrollTo({
674
+ top: g.current.scrollHeight,
675
+ behavior: T
677
676
  });
678
677
  },
679
678
  []
680
- ), _ = ft(
681
- (A, P = "smooth") => {
682
- f.current && f.current.scrollTo({
683
- top: A * n,
684
- behavior: P
679
+ ), M = ft(
680
+ (T, _ = "smooth") => {
681
+ g.current && g.current.scrollTo({
682
+ top: T * n,
683
+ behavior: _
685
684
  });
686
685
  },
687
686
  [n]
688
687
  ), N = {
689
688
  outer: {
690
- ref: f,
689
+ ref: g,
691
690
  style: { overflowY: "auto", height: "100%" }
692
691
  },
693
692
  inner: {
@@ -698,211 +697,211 @@ function lt(t, c, h, g) {
698
697
  },
699
698
  list: {
700
699
  style: {
701
- transform: `translateY(${d.startIndex * n}px)`
700
+ transform: `translateY(${u.startIndex * n}px)`
702
701
  }
703
702
  }
704
703
  };
705
704
  return {
706
- virtualState: G,
705
+ virtualState: D,
707
706
  virtualizerProps: N,
708
707
  scrollToBottom: B,
709
- scrollToIndex: _
708
+ scrollToIndex: M
710
709
  };
711
710
  };
712
711
  if (l === "stateSort")
713
712
  return (e) => {
714
- const s = [...u()].sort(
715
- (d, k) => e(d.item, k.item)
716
- ), i = s.map(({ item: d }) => d), f = {
713
+ const s = [...d()].sort(
714
+ (u, E) => e(u.item, E.item)
715
+ ), i = s.map(({ item: u }) => u), g = {
717
716
  ...S,
718
717
  validIndices: s.map(
719
- ({ originalIndex: d }) => d
718
+ ({ originalIndex: u }) => u
720
719
  )
721
720
  };
722
- return o(i, a, f);
721
+ return a(i, r, g);
723
722
  };
724
723
  if (l === "stateFilter")
725
724
  return (e) => {
726
- const s = u().filter(
727
- ({ item: d }, k) => e(d, k)
728
- ), i = s.map(({ item: d }) => d), f = {
725
+ const s = d().filter(
726
+ ({ item: u }, E) => e(u, E)
727
+ ), i = s.map(({ item: u }) => u), g = {
729
728
  ...S,
730
729
  validIndices: s.map(
731
- ({ originalIndex: d }) => d
730
+ ({ originalIndex: u }) => u
732
731
  )
733
732
  };
734
- return o(i, a, f);
733
+ return a(i, r, g);
735
734
  };
736
735
  if (l === "stateMap")
737
736
  return (e) => {
738
- const n = r.getState().getNestedState(t, a);
739
- return Array.isArray(n) ? (S?.validIndices || Array.from({ length: n.length }, (i, f) => f)).map((i, f) => {
740
- const d = n[i], k = [...a, i.toString()], w = o(d, k, S);
741
- return e(d, w, {
737
+ const n = o.getState().getNestedState(t, r);
738
+ return Array.isArray(n) ? (S?.validIndices || Array.from({ length: n.length }, (i, g) => g)).map((i, g) => {
739
+ const u = n[i], E = [...r, i.toString()], w = a(u, E, S);
740
+ return e(u, w, {
742
741
  register: () => {
743
- const [, x] = K({}), C = `${h}-${a.join(".")}-${i}`;
742
+ const [, x] = K({}), C = `${h}-${r.join(".")}-${i}`;
744
743
  it(() => {
745
- const V = `${t}////${C}`, G = r.getState().stateComponents.get(t) || {
744
+ const V = `${t}////${C}`, D = o.getState().stateComponents.get(t) || {
746
745
  components: /* @__PURE__ */ new Map()
747
746
  };
748
- return G.components.set(V, {
747
+ return D.components.set(V, {
749
748
  forceUpdate: () => x({}),
750
- paths: /* @__PURE__ */ new Set([k.join(".")])
751
- }), r.getState().stateComponents.set(t, G), () => {
752
- const B = r.getState().stateComponents.get(t);
749
+ paths: /* @__PURE__ */ new Set([E.join(".")])
750
+ }), o.getState().stateComponents.set(t, D), () => {
751
+ const B = o.getState().stateComponents.get(t);
753
752
  B && B.components.delete(V);
754
753
  };
755
754
  }, [t, C]);
756
755
  },
757
- index: f,
756
+ index: g,
758
757
  originalIndex: i
759
758
  });
760
759
  }) : (console.warn(
761
- `stateMap called on a non-array value at path: ${a.join(".")}. The current value is:`,
760
+ `stateMap called on a non-array value at path: ${r.join(".")}. The current value is:`,
762
761
  n
763
762
  ), null);
764
763
  };
765
764
  if (l === "stateMapNoRender")
766
765
  return (e) => y.map((s, i) => {
767
- let f;
768
- S?.validIndices && S.validIndices[i] !== void 0 ? f = S.validIndices[i] : f = i;
769
- const d = [...a, f.toString()], k = o(s, d, S);
766
+ let g;
767
+ S?.validIndices && S.validIndices[i] !== void 0 ? g = S.validIndices[i] : g = i;
768
+ const u = [...r, g.toString()], E = a(s, u, S);
770
769
  return e(
771
770
  s,
772
- k,
771
+ E,
773
772
  i,
774
773
  y,
775
- o(y, a, S)
774
+ a(y, r, S)
776
775
  );
777
776
  });
778
777
  if (l === "$stateMap")
779
778
  return (e) => rt(zt, {
780
779
  proxy: {
781
780
  _stateKey: t,
782
- _path: a,
781
+ _path: r,
783
782
  _mapFn: e
784
783
  // Pass the actual function, not string
785
784
  },
786
- rebuildStateShape: o
785
+ rebuildStateShape: a
787
786
  });
788
787
  if (l === "stateList")
789
788
  return (e) => {
790
- const n = r.getState().getNestedState(t, a);
791
- return Array.isArray(n) ? (S?.validIndices || Array.from({ length: n.length }, (i, f) => f)).map((i, f) => {
792
- const d = n[i], k = [...a, i.toString()], w = o(d, k, S), T = `${h}-${a.join(".")}-${i}`;
789
+ const n = o.getState().getNestedState(t, r);
790
+ return Array.isArray(n) ? (S?.validIndices || Array.from({ length: n.length }, (i, g) => g)).map((i, g) => {
791
+ const u = n[i], E = [...r, i.toString()], w = a(u, E, S), $ = `${h}-${r.join(".")}-${i}`;
793
792
  return rt(Ht, {
794
793
  key: i,
795
794
  stateKey: t,
796
- itemComponentId: T,
797
- itemPath: k,
795
+ itemComponentId: $,
796
+ itemPath: E,
798
797
  children: e(
799
- d,
798
+ u,
800
799
  w,
801
- f,
800
+ g,
802
801
  n,
803
- o(n, a, S)
802
+ a(n, r, S)
804
803
  )
805
804
  });
806
805
  }) : (console.warn(
807
- `stateList called on a non-array value at path: ${a.join(".")}.`
806
+ `stateList called on a non-array value at path: ${r.join(".")}.`
808
807
  ), null);
809
808
  };
810
809
  if (l === "stateFlattenOn")
811
810
  return (e) => {
812
811
  const n = y;
813
- v.clear(), $++;
812
+ v.clear(), k++;
814
813
  const s = n.flatMap(
815
814
  (i) => i[e] ?? []
816
815
  );
817
- return o(
816
+ return a(
818
817
  s,
819
- [...a, "[*]", e],
818
+ [...r, "[*]", e],
820
819
  S
821
820
  );
822
821
  };
823
822
  if (l === "index")
824
823
  return (e) => {
825
824
  const n = y[e];
826
- return o(n, [...a, e.toString()]);
825
+ return a(n, [...r, e.toString()]);
827
826
  };
828
827
  if (l === "last")
829
828
  return () => {
830
- const e = r.getState().getNestedState(t, a);
829
+ const e = o.getState().getNestedState(t, r);
831
830
  if (e.length === 0) return;
832
- const n = e.length - 1, s = e[n], i = [...a, n.toString()];
833
- return o(s, i);
831
+ const n = e.length - 1, s = e[n], i = [...r, n.toString()];
832
+ return a(s, i);
834
833
  };
835
834
  if (l === "insert")
836
- return (e) => (p(a), St(c, e, a, t), o(
837
- r.getState().getNestedState(t, a),
838
- a
835
+ return (e) => (p(r), St(c, e, r, t), a(
836
+ o.getState().getNestedState(t, r),
837
+ r
839
838
  ));
840
839
  if (l === "uniqueInsert")
841
840
  return (e, n, s) => {
842
- const i = r.getState().getNestedState(t, a), f = J(e) ? e(i) : e;
843
- let d = null;
841
+ const i = o.getState().getNestedState(t, r), g = J(e) ? e(i) : e;
842
+ let u = null;
844
843
  if (!i.some((w) => {
845
844
  if (n) {
846
845
  const x = n.every(
847
- (C) => L(w[C], f[C])
846
+ (C) => L(w[C], g[C])
848
847
  );
849
- return x && (d = w), x;
848
+ return x && (u = w), x;
850
849
  }
851
- const T = L(w, f);
852
- return T && (d = w), T;
850
+ const $ = L(w, g);
851
+ return $ && (u = w), $;
853
852
  }))
854
- p(a), St(c, f, a, t);
855
- else if (s && d) {
856
- const w = s(d), T = i.map(
857
- (x) => L(x, d) ? w : x
853
+ p(r), St(c, g, r, t);
854
+ else if (s && u) {
855
+ const w = s(u), $ = i.map(
856
+ (x) => L(x, u) ? w : x
858
857
  );
859
- p(a), nt(c, T, a);
858
+ p(r), nt(c, $, r);
860
859
  }
861
860
  };
862
861
  if (l === "cut")
863
862
  return (e, n) => {
864
863
  if (!n?.waitForSync)
865
- return p(a), ot(c, a, t, e), o(
866
- r.getState().getNestedState(t, a),
867
- a
864
+ return p(r), at(c, r, t, e), a(
865
+ o.getState().getNestedState(t, r),
866
+ r
868
867
  );
869
868
  };
870
869
  if (l === "cutByValue")
871
870
  return (e) => {
872
871
  for (let n = 0; n < y.length; n++)
873
- y[n] === e && ot(c, a, t, n);
872
+ y[n] === e && at(c, r, t, n);
874
873
  };
875
874
  if (l === "toggleByValue")
876
875
  return (e) => {
877
876
  const n = y.findIndex((s) => s === e);
878
- n > -1 ? ot(c, a, t, n) : St(c, e, a, t);
877
+ n > -1 ? at(c, r, t, n) : St(c, e, r, t);
879
878
  };
880
879
  if (l === "stateFind")
881
880
  return (e) => {
882
- const s = u().find(
883
- ({ item: f }, d) => e(f, d)
881
+ const s = d().find(
882
+ ({ item: g }, u) => e(g, u)
884
883
  );
885
884
  if (!s) return;
886
- const i = [...a, s.originalIndex.toString()];
887
- return o(s.item, i, S);
885
+ const i = [...r, s.originalIndex.toString()];
886
+ return a(s.item, i, S);
888
887
  };
889
888
  if (l === "findWith")
890
889
  return (e, n) => {
891
- const i = u().find(
892
- ({ item: d }) => d[e] === n
890
+ const i = d().find(
891
+ ({ item: u }) => u[e] === n
893
892
  );
894
893
  if (!i) return;
895
- const f = [...a, i.originalIndex.toString()];
896
- return o(i.item, f, S);
894
+ const g = [...r, i.originalIndex.toString()];
895
+ return a(i.item, g, S);
897
896
  };
898
897
  }
899
- const Y = a[a.length - 1];
898
+ const Y = r[r.length - 1];
900
899
  if (!isNaN(Number(Y))) {
901
- const u = a.slice(0, -1), e = r.getState().getNestedState(t, u);
900
+ const d = r.slice(0, -1), e = o.getState().getNestedState(t, d);
902
901
  if (Array.isArray(e) && l === "cut")
903
- return () => ot(
902
+ return () => at(
904
903
  c,
905
- u,
904
+ d,
906
905
  t,
907
906
  Number(Y)
908
907
  );
@@ -910,137 +909,137 @@ function lt(t, c, h, g) {
910
909
  if (l === "get")
911
910
  return () => {
912
911
  if (S?.validIndices && Array.isArray(y)) {
913
- const u = r.getState().getNestedState(t, a);
914
- return S.validIndices.map((e) => u[e]);
912
+ const d = o.getState().getNestedState(t, r);
913
+ return S.validIndices.map((e) => d[e]);
915
914
  }
916
- return r.getState().getNestedState(t, a);
915
+ return o.getState().getNestedState(t, r);
917
916
  };
918
917
  if (l === "$derive")
919
- return (u) => At({
918
+ return (d) => At({
920
919
  _stateKey: t,
921
- _path: a,
922
- _effect: u.toString()
920
+ _path: r,
921
+ _effect: d.toString()
923
922
  });
924
923
  if (l === "$get")
925
924
  return () => At({
926
925
  _stateKey: t,
927
- _path: a
926
+ _path: r
928
927
  });
929
928
  if (l === "lastSynced") {
930
- const u = `${t}:${a.join(".")}`;
931
- return r.getState().getSyncInfo(u);
929
+ const d = `${t}:${r.join(".")}`;
930
+ return o.getState().getSyncInfo(d);
932
931
  }
933
932
  if (l == "getLocalStorage")
934
- return (u) => dt(g + "-" + t + "-" + u);
933
+ return (d) => dt(f + "-" + t + "-" + d);
935
934
  if (l === "_selected") {
936
- const u = a.slice(0, -1), e = u.join("."), n = r.getState().getNestedState(t, u);
937
- return Array.isArray(n) ? Number(a[a.length - 1]) === r.getState().getSelectedIndex(t, e) : void 0;
935
+ const d = r.slice(0, -1), e = d.join("."), n = o.getState().getNestedState(t, d);
936
+ return Array.isArray(n) ? Number(r[r.length - 1]) === o.getState().getSelectedIndex(t, e) : void 0;
938
937
  }
939
938
  if (l === "setSelected")
940
- return (u) => {
941
- const e = a.slice(0, -1), n = Number(a[a.length - 1]), s = e.join(".");
942
- u ? r.getState().setSelectedIndex(t, s, n) : r.getState().setSelectedIndex(t, s, void 0);
943
- const i = r.getState().getNestedState(t, [...e]);
939
+ return (d) => {
940
+ const e = r.slice(0, -1), n = Number(r[r.length - 1]), s = e.join(".");
941
+ d ? o.getState().setSelectedIndex(t, s, n) : o.getState().setSelectedIndex(t, s, void 0);
942
+ const i = o.getState().getNestedState(t, [...e]);
944
943
  nt(c, i, e), p(e);
945
944
  };
946
945
  if (l === "toggleSelected")
947
946
  return () => {
948
- const u = a.slice(0, -1), e = Number(a[a.length - 1]), n = u.join("."), s = r.getState().getSelectedIndex(t, n);
949
- r.getState().setSelectedIndex(
947
+ const d = r.slice(0, -1), e = Number(r[r.length - 1]), n = d.join("."), s = o.getState().getSelectedIndex(t, n);
948
+ o.getState().setSelectedIndex(
950
949
  t,
951
950
  n,
952
951
  s === e ? void 0 : e
953
952
  );
954
- const i = r.getState().getNestedState(t, [...u]);
955
- nt(c, i, u), p(u);
953
+ const i = o.getState().getNestedState(t, [...d]);
954
+ nt(c, i, d), p(d);
956
955
  };
957
- if (a.length == 0) {
956
+ if (r.length == 0) {
958
957
  if (l === "applyJsonPatch")
959
- return (u) => {
960
- const e = r.getState().cogsStateStore[t], s = jt(e, u).newDocument;
958
+ return (d) => {
959
+ const e = o.getState().cogsStateStore[t], s = jt(e, d).newDocument;
961
960
  Nt(
962
961
  t,
963
- r.getState().initialStateGlobal[t],
962
+ o.getState().initialStateGlobal[t],
964
963
  s,
965
964
  c,
966
965
  h,
967
- g
966
+ f
968
967
  );
969
- const i = r.getState().stateComponents.get(t);
968
+ const i = o.getState().stateComponents.get(t);
970
969
  if (i) {
971
- const f = ht(e, s), d = new Set(f);
970
+ const g = ht(e, s), u = new Set(g);
972
971
  for (const [
973
- k,
972
+ E,
974
973
  w
975
974
  ] of i.components.entries()) {
976
- let T = !1;
975
+ let $ = !1;
977
976
  const x = Array.isArray(w.reactiveType) ? w.reactiveType : [w.reactiveType || "component"];
978
977
  if (!x.includes("none")) {
979
978
  if (x.includes("all")) {
980
979
  w.forceUpdate();
981
980
  continue;
982
981
  }
983
- if (x.includes("component") && (w.paths.has("") && (T = !0), !T))
984
- for (const C of d) {
982
+ if (x.includes("component") && (w.paths.has("") && ($ = !0), !$))
983
+ for (const C of u) {
985
984
  if (w.paths.has(C)) {
986
- T = !0;
985
+ $ = !0;
987
986
  break;
988
987
  }
989
988
  let V = C.lastIndexOf(".");
990
989
  for (; V !== -1; ) {
991
- const G = C.substring(0, V);
992
- if (w.paths.has(G)) {
993
- T = !0;
990
+ const D = C.substring(0, V);
991
+ if (w.paths.has(D)) {
992
+ $ = !0;
994
993
  break;
995
994
  }
996
995
  const B = C.substring(
997
996
  V + 1
998
997
  );
999
998
  if (!isNaN(Number(B))) {
1000
- const _ = G.lastIndexOf(".");
1001
- if (_ !== -1) {
1002
- const N = G.substring(
999
+ const M = D.lastIndexOf(".");
1000
+ if (M !== -1) {
1001
+ const N = D.substring(
1003
1002
  0,
1004
- _
1003
+ M
1005
1004
  );
1006
1005
  if (w.paths.has(N)) {
1007
- T = !0;
1006
+ $ = !0;
1008
1007
  break;
1009
1008
  }
1010
1009
  }
1011
1010
  }
1012
- V = G.lastIndexOf(".");
1011
+ V = D.lastIndexOf(".");
1013
1012
  }
1014
- if (T) break;
1013
+ if ($) break;
1015
1014
  }
1016
- if (!T && x.includes("deps") && w.depsFunction) {
1015
+ if (!$ && x.includes("deps") && w.depsFunction) {
1017
1016
  const C = w.depsFunction(s);
1018
1017
  let V = !1;
1019
- typeof C == "boolean" ? C && (V = !0) : L(w.deps, C) || (w.deps = C, V = !0), V && (T = !0);
1018
+ typeof C == "boolean" ? C && (V = !0) : L(w.deps, C) || (w.deps = C, V = !0), V && ($ = !0);
1020
1019
  }
1021
- T && w.forceUpdate();
1020
+ $ && w.forceUpdate();
1022
1021
  }
1023
1022
  }
1024
1023
  }
1025
1024
  };
1026
1025
  if (l === "validateZodSchema")
1027
1026
  return () => {
1028
- const u = r.getState().getInitialOptions(t)?.validation, e = r.getState().addValidationError;
1029
- if (!u?.zodSchema)
1027
+ const d = o.getState().getInitialOptions(t)?.validation, e = o.getState().addValidationError;
1028
+ if (!d?.zodSchema)
1030
1029
  throw new Error("Zod schema not found");
1031
- if (!u?.key)
1030
+ if (!d?.key)
1032
1031
  throw new Error("Validation key not found");
1033
- H(u.key);
1034
- const n = r.getState().cogsStateStore[t];
1032
+ H(d.key);
1033
+ const n = o.getState().cogsStateStore[t];
1035
1034
  try {
1036
- const s = r.getState().getValidationErrors(u.key);
1037
- s && s.length > 0 && s.forEach(([f]) => {
1038
- f && f.startsWith(u.key) && H(f);
1035
+ const s = o.getState().getValidationErrors(d.key);
1036
+ s && s.length > 0 && s.forEach(([g]) => {
1037
+ g && g.startsWith(d.key) && H(g);
1039
1038
  });
1040
- const i = u.zodSchema.safeParse(n);
1041
- return i.success ? !0 : (i.error.errors.forEach((d) => {
1042
- const k = d.path, w = d.message, T = [u.key, ...k].join(".");
1043
- e(T, w);
1039
+ const i = d.zodSchema.safeParse(n);
1040
+ return i.success ? !0 : (i.error.errors.forEach((u) => {
1041
+ const E = u.path, w = u.message, $ = [d.key, ...E].join(".");
1042
+ e($, w);
1044
1043
  }), ut(t), !1);
1045
1044
  } catch (s) {
1046
1045
  return console.error("Zod schema validation failed", s), !1;
@@ -1048,77 +1047,77 @@ function lt(t, c, h, g) {
1048
1047
  };
1049
1048
  if (l === "_componentId") return h;
1050
1049
  if (l === "getComponents")
1051
- return () => r().stateComponents.get(t);
1050
+ return () => o().stateComponents.get(t);
1052
1051
  if (l === "getAllFormRefs")
1053
1052
  return () => It.getState().getFormRefsByStateKey(t);
1054
1053
  if (l === "_initialState")
1055
- return r.getState().initialStateGlobal[t];
1054
+ return o.getState().initialStateGlobal[t];
1056
1055
  if (l === "_serverState")
1057
- return r.getState().serverState[t];
1056
+ return o.getState().serverState[t];
1058
1057
  if (l === "_isLoading")
1059
- return r.getState().isLoadingGlobal[t];
1058
+ return o.getState().isLoadingGlobal[t];
1060
1059
  if (l === "revertToInitialState")
1061
1060
  return I.revertToInitialState;
1062
1061
  if (l === "updateInitialState") return I.updateInitialState;
1063
1062
  if (l === "removeValidation") return I.removeValidation;
1064
1063
  }
1065
1064
  if (l === "getFormRef")
1066
- return () => It.getState().getFormRef(t + "." + a.join("."));
1065
+ return () => It.getState().getFormRef(t + "." + r.join("."));
1067
1066
  if (l === "validationWrapper")
1068
1067
  return ({
1069
- children: u,
1068
+ children: d,
1070
1069
  hideMessage: e
1071
1070
  }) => /* @__PURE__ */ mt(
1072
1071
  Pt,
1073
1072
  {
1074
1073
  formOpts: e ? { validation: { message: "" } } : void 0,
1075
- path: a,
1076
- validationKey: r.getState().getInitialOptions(t)?.validation?.key || "",
1074
+ path: r,
1075
+ validationKey: o.getState().getInitialOptions(t)?.validation?.key || "",
1077
1076
  stateKey: t,
1078
1077
  validIndices: S?.validIndices,
1079
- children: u
1078
+ children: d
1080
1079
  }
1081
1080
  );
1082
1081
  if (l === "_stateKey") return t;
1083
- if (l === "_path") return a;
1082
+ if (l === "_path") return r;
1084
1083
  if (l === "_isServerSynced") return I._isServerSynced;
1085
1084
  if (l === "update")
1086
- return (u, e) => {
1085
+ return (d, e) => {
1087
1086
  if (e?.debounce)
1088
1087
  xt(() => {
1089
- nt(c, u, a, "");
1090
- const n = r.getState().getNestedState(t, a);
1088
+ nt(c, d, r, "");
1089
+ const n = o.getState().getNestedState(t, r);
1091
1090
  e?.afterUpdate && e.afterUpdate(n);
1092
1091
  }, e.debounce);
1093
1092
  else {
1094
- nt(c, u, a, "");
1095
- const n = r.getState().getNestedState(t, a);
1093
+ nt(c, d, r, "");
1094
+ const n = o.getState().getNestedState(t, r);
1096
1095
  e?.afterUpdate && e.afterUpdate(n);
1097
1096
  }
1098
- p(a);
1097
+ p(r);
1099
1098
  };
1100
1099
  if (l === "formElement")
1101
- return (u, e) => /* @__PURE__ */ mt(
1100
+ return (d, e) => /* @__PURE__ */ mt(
1102
1101
  _t,
1103
1102
  {
1104
1103
  setState: c,
1105
1104
  stateKey: t,
1106
- path: a,
1107
- child: u,
1105
+ path: r,
1106
+ child: d,
1108
1107
  formOpts: e
1109
1108
  }
1110
1109
  );
1111
- const j = [...a, l], tt = r.getState().getNestedState(t, j);
1112
- return o(tt, j, S);
1110
+ const j = [...r, l], tt = o.getState().getNestedState(t, j);
1111
+ return a(tt, j, S);
1113
1112
  }
1114
- }, W = new Proxy(O, U);
1115
- return v.set(D, {
1116
- proxy: W,
1117
- stateVersion: $
1118
- }), W;
1113
+ }, G = new Proxy(O, R);
1114
+ return v.set(W, {
1115
+ proxy: G,
1116
+ stateVersion: k
1117
+ }), G;
1119
1118
  }
1120
- return o(
1121
- r.getState().getNestedState(t, [])
1119
+ return a(
1120
+ o.getState().getNestedState(t, [])
1122
1121
  );
1123
1122
  }
1124
1123
  function At(t) {
@@ -1128,12 +1127,12 @@ function zt({
1128
1127
  proxy: t,
1129
1128
  rebuildStateShape: c
1130
1129
  }) {
1131
- const h = r().getNestedState(t._stateKey, t._path);
1130
+ const h = o().getNestedState(t._stateKey, t._path);
1132
1131
  return Array.isArray(h) ? c(
1133
1132
  h,
1134
1133
  t._path
1135
1134
  ).stateMapNoRender(
1136
- (v, $, p, I, o) => t._mapFn(v, $, p, I, o)
1135
+ (v, k, p, I, a) => t._mapFn(v, k, p, I, a)
1137
1136
  ) : null;
1138
1137
  }
1139
1138
  function Bt({
@@ -1141,9 +1140,9 @@ function Bt({
1141
1140
  }) {
1142
1141
  const c = q(null), h = `${t._stateKey}-${t._path.join(".")}`;
1143
1142
  return st(() => {
1144
- const g = c.current;
1145
- if (!g || !g.parentElement) return;
1146
- const v = g.parentElement, p = Array.from(v.childNodes).indexOf(g);
1143
+ const f = c.current;
1144
+ if (!f || !f.parentElement) return;
1145
+ const v = f.parentElement, p = Array.from(v.childNodes).indexOf(f);
1147
1146
  let I = v.getAttribute("data-parent-id");
1148
1147
  I || (I = `parent-${crypto.randomUUID()}`, v.setAttribute("data-parent-id", I));
1149
1148
  const y = {
@@ -1152,23 +1151,23 @@ function Bt({
1152
1151
  position: p,
1153
1152
  effect: t._effect
1154
1153
  };
1155
- r.getState().addSignalElement(h, y);
1156
- const a = r.getState().getNestedState(t._stateKey, t._path);
1154
+ o.getState().addSignalElement(h, y);
1155
+ const r = o.getState().getNestedState(t._stateKey, t._path);
1157
1156
  let S;
1158
1157
  if (t._effect)
1159
1158
  try {
1160
1159
  S = new Function(
1161
1160
  "state",
1162
1161
  `return (${t._effect})(state)`
1163
- )(a);
1162
+ )(r);
1164
1163
  } catch (O) {
1165
- console.error("Error evaluating effect function during mount:", O), S = a;
1164
+ console.error("Error evaluating effect function during mount:", O), S = r;
1166
1165
  }
1167
1166
  else
1168
- S = a;
1167
+ S = r;
1169
1168
  S !== null && typeof S == "object" && (S = JSON.stringify(S));
1170
- const D = document.createTextNode(String(S));
1171
- g.replaceWith(D);
1169
+ const W = document.createTextNode(String(S));
1170
+ f.replaceWith(W);
1172
1171
  }, [t._stateKey, t._path.join("."), t._effect]), rt("span", {
1173
1172
  ref: c,
1174
1173
  style: { display: "none" },
@@ -1178,15 +1177,15 @@ function Bt({
1178
1177
  function ie(t) {
1179
1178
  const c = Ct(
1180
1179
  (h) => {
1181
- const g = r.getState().stateComponents.get(t._stateKey) || {
1180
+ const f = o.getState().stateComponents.get(t._stateKey) || {
1182
1181
  components: /* @__PURE__ */ new Map()
1183
1182
  };
1184
- return g.components.set(t._stateKey, {
1183
+ return f.components.set(t._stateKey, {
1185
1184
  forceUpdate: h,
1186
1185
  paths: /* @__PURE__ */ new Set([t._path.join(".")])
1187
- }), () => g.components.delete(t._stateKey);
1186
+ }), () => f.components.delete(t._stateKey);
1188
1187
  },
1189
- () => r.getState().getNestedState(t._stateKey, t._path)
1188
+ () => o.getState().getNestedState(t._stateKey, t._path)
1190
1189
  );
1191
1190
  return rt("text", {}, String(c));
1192
1191
  }
@@ -1194,33 +1193,33 @@ function Ht({
1194
1193
  stateKey: t,
1195
1194
  itemComponentId: c,
1196
1195
  itemPath: h,
1197
- children: g
1196
+ children: f
1198
1197
  }) {
1199
- const [, v] = K({}), [$, p] = Ot();
1198
+ const [, v] = K({}), [k, p] = Ot();
1200
1199
  return st(() => {
1201
- p.height > 0 && r.getState().setShadowMetadata(t, h, {
1200
+ p.height > 0 && o.getState().setShadowMetadata(t, h, {
1202
1201
  virtualizer: {
1203
1202
  itemHeight: p.height
1204
1203
  }
1205
1204
  });
1206
1205
  }, [p.height]), it(() => {
1207
- const I = `${t}////${c}`, o = r.getState().stateComponents.get(t) || {
1206
+ const I = `${t}////${c}`, a = o.getState().stateComponents.get(t) || {
1208
1207
  components: /* @__PURE__ */ new Map()
1209
1208
  };
1210
- return o.components.set(I, {
1209
+ return a.components.set(I, {
1211
1210
  forceUpdate: () => v({}),
1212
1211
  paths: /* @__PURE__ */ new Set([h.join(".")])
1213
- }), r.getState().stateComponents.set(t, o), () => {
1214
- const y = r.getState().stateComponents.get(t);
1212
+ }), o.getState().stateComponents.set(t, a), () => {
1213
+ const y = o.getState().stateComponents.get(t);
1215
1214
  y && y.components.delete(I);
1216
1215
  };
1217
- }, [t, c, h.join(".")]), /* @__PURE__ */ mt("div", { ref: $, children: g });
1216
+ }, [t, c, h.join(".")]), /* @__PURE__ */ mt("div", { ref: k, children: f });
1218
1217
  }
1219
1218
  export {
1220
1219
  At as $cogsSignal,
1221
1220
  ie as $cogsSignalStore,
1222
- ae as addStateOptions,
1223
- oe as createCogsState,
1221
+ oe as addStateOptions,
1222
+ ae as createCogsState,
1224
1223
  se as notifyComponent,
1225
1224
  Lt as useCogsStateFn
1226
1225
  };