cogsbox-state 0.5.102 → 0.5.103

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,59 +1,59 @@
1
1
  "use client";
2
- import { jsx as dt } from "react/jsx-runtime";
3
- import { useState as et, useRef as Z, useEffect as nt, useLayoutEffect as vt, useMemo as _t, createElement as Q, useSyncExternalStore as Et, startTransition as H } from "react";
4
- import { transformStateFunc as $t, isFunction as D, isDeepEqual as O, getNestedValue as M, debounce as wt } from "./utility.js";
2
+ import { jsx as ct } from "react/jsx-runtime";
3
+ import { useState as et, useRef as Z, useEffect as nt, useLayoutEffect as It, useMemo as _t, createElement as Q, useSyncExternalStore as Et, startTransition as H } from "react";
4
+ import { transformStateFunc as wt, isFunction as L, getNestedValue as U, isDeepEqual as M, debounce as $t } from "./utility.js";
5
5
  import { pushFunc as K, updateFn as B, cutFunc as J, ValidationWrapper as Nt, FormControlComponent as Vt } from "./Functions.jsx";
6
6
  import "zod";
7
- import { getGlobalStore as r, formRefStore as ut } from "./store.js";
7
+ import { getGlobalStore as r, formRefStore as lt } from "./store.js";
8
8
  import { useCogsConfig as At } from "./CogsStateClient.jsx";
9
9
  import rt from "./node_modules/uuid/dist/esm-browser/v4.js";
10
- function ht(t, s) {
11
- const y = r.getState().getInitialOptions, I = r.getState().setInitialStateOptions, g = y(t) || {};
12
- I(t, {
13
- ...g,
14
- ...s
10
+ function dt(t, i) {
11
+ const m = r.getState().getInitialOptions, y = r.getState().setInitialStateOptions, u = m(t) || {};
12
+ y(t, {
13
+ ...u,
14
+ ...i
15
15
  });
16
16
  }
17
- function gt({
17
+ function ut({
18
18
  stateKey: t,
19
- options: s,
20
- initialOptionsPart: y
19
+ options: i,
20
+ initialOptionsPart: m
21
21
  }) {
22
- const I = q(t) || {}, g = y[t] || {}, E = r.getState().setInitialStateOptions, _ = { ...g, ...I };
23
- let f = !1;
24
- if (s)
25
- for (const l in s)
26
- _.hasOwnProperty(l) ? l == "localStorage" && s[l] && _[l].key !== s[l]?.key && (f = !0, _[l] = s[l]) : (f = !0, _[l] = s[l]);
27
- f && E(t, _);
22
+ const y = q(t) || {}, u = m[t] || {}, w = r.getState().setInitialStateOptions, E = { ...u, ...y };
23
+ let v = !1;
24
+ if (i)
25
+ for (const l in i)
26
+ E.hasOwnProperty(l) ? l == "localStorage" && i[l] && E[l].key !== i[l]?.key && (v = !0, E[l] = i[l]) : (v = !0, E[l] = i[l]);
27
+ v && w(t, E);
28
28
  }
29
- function qt(t, { formElements: s, validation: y }) {
30
- return { initialState: t, formElements: s, validation: y };
29
+ function qt(t, { formElements: i, validation: m }) {
30
+ return { initialState: t, formElements: i, validation: m };
31
31
  }
32
- const zt = (t, s) => {
33
- let y = t;
34
- const [I, g] = $t(y);
35
- (Object.keys(g).length > 0 || s && Object.keys(s).length > 0) && Object.keys(g).forEach((f) => {
36
- g[f] = g[f] || {}, g[f].formElements = {
37
- ...s?.formElements,
32
+ const zt = (t, i) => {
33
+ let m = t;
34
+ const [y, u] = wt(m);
35
+ (Object.keys(u).length > 0 || i && Object.keys(i).length > 0) && Object.keys(u).forEach((v) => {
36
+ u[v] = u[v] || {}, u[v].formElements = {
37
+ ...i?.formElements,
38
38
  // Global defaults first
39
- ...s?.validation,
40
- ...g[f].formElements || {}
39
+ ...i?.validation,
40
+ ...u[v].formElements || {}
41
41
  // State-specific overrides
42
- }, q(f) || r.getState().setInitialStateOptions(f, g[f]);
43
- }), r.getState().setInitialStates(I);
44
- const E = (f, l) => {
45
- const [m] = et(l?.componentId ?? rt());
46
- gt({
47
- stateKey: f,
42
+ }, q(v) || r.getState().setInitialStateOptions(v, u[v]);
43
+ }), r.getState().setInitialStates(y);
44
+ const w = (v, l) => {
45
+ const [f] = et(l?.componentId ?? rt());
46
+ ut({
47
+ stateKey: v,
48
48
  options: l,
49
- initialOptionsPart: g
49
+ initialOptionsPart: u
50
50
  });
51
- const e = r.getState().cogsStateStore[f] || I[f], S = l?.modifyState ? l.modifyState(e) : e, [k, C] = kt(
51
+ const e = r.getState().cogsStateStore[v] || y[v], S = l?.modifyState ? l.modifyState(e) : e, [x, A] = Ot(
52
52
  S,
53
53
  {
54
- stateKey: f,
54
+ stateKey: v,
55
55
  syncUpdate: l?.syncUpdate,
56
- componentId: m,
56
+ componentId: f,
57
57
  localStorage: l?.localStorage,
58
58
  middleware: l?.middleware,
59
59
  enabledSync: l?.enabledSync,
@@ -63,110 +63,99 @@ const zt = (t, s) => {
63
63
  dependencies: l?.dependencies
64
64
  }
65
65
  );
66
- return C;
66
+ return A;
67
67
  };
68
- function _(f, l) {
69
- gt({ stateKey: f, options: l, initialOptionsPart: g });
68
+ function E(v, l) {
69
+ ut({ stateKey: v, options: l, initialOptionsPart: u });
70
70
  }
71
- return { useCogsState: E, setCogsOptions: _ };
71
+ return { useCogsState: w, setCogsOptions: E };
72
72
  }, {
73
73
  setUpdaterState: Y,
74
- setState: G,
74
+ setState: D,
75
75
  getInitialOptions: q,
76
- getKeyState: ot,
77
- getValidationErrors: Ct,
78
- setStateLog: pt,
79
- updateInitialStateGlobal: at,
80
- addValidationError: xt,
81
- removeValidationError: R,
82
- setServerSyncActions: Tt
83
- } = r.getState(), it = (t) => {
76
+ getKeyState: gt,
77
+ getValidationErrors: ht,
78
+ setStateLog: Ct,
79
+ updateInitialStateGlobal: ot,
80
+ addValidationError: kt,
81
+ removeValidationError: P,
82
+ setServerSyncActions: pt
83
+ } = r.getState(), ft = (t) => {
84
84
  if (!t) return null;
85
85
  try {
86
- const s = window.localStorage.getItem(t);
87
- return s ? JSON.parse(s) : null;
88
- } catch (s) {
89
- return console.error("Error loading from localStorage:", s), null;
86
+ const i = window.localStorage.getItem(t);
87
+ return i ? JSON.parse(i) : null;
88
+ } catch (i) {
89
+ return console.error("Error loading from localStorage:", i), null;
90
90
  }
91
- }, ft = (t, s, y, I, g) => {
92
- const E = D(y?.localStorage?.key) ? y.localStorage?.key(t) : y?.localStorage?.key;
93
- if (!E || !I)
94
- return;
95
- const _ = `${I}-${s}-${E}`;
96
- try {
97
- let f;
98
- if (g !== void 0)
99
- f = {
100
- state: t,
101
- baseServerState: g,
102
- // Use provided base
103
- lastUpdated: Date.now()
104
- };
105
- else {
106
- const l = it(_);
107
- f = {
108
- state: t,
109
- // !!! --- REMOVED '?? null' --- !!!
110
- baseServerState: l?.baseServerState,
111
- // Preserve existing base (will be T | null | undefined)
112
- lastUpdated: Date.now()
113
- };
114
- }
115
- window.localStorage.setItem(_, JSON.stringify(f));
116
- } catch (f) {
117
- console.error("Error saving to localStorage:", _, f);
91
+ }, xt = (t, i, m, y) => {
92
+ m?.log && console.log(
93
+ "saving to localstorage",
94
+ i,
95
+ m.localStorage?.key,
96
+ y
97
+ );
98
+ const u = L(m?.localStorage?.key) ? m.localStorage?.key(t) : m?.localStorage?.key;
99
+ if (u && y) {
100
+ const w = {
101
+ state: t,
102
+ lastUpdated: Date.now(),
103
+ lastSyncedWithServer: r.getState().serverSyncLog[i]?.[0]?.timeStamp,
104
+ baseServerState: r.getState().serverState[i]
105
+ }, E = `${y}-${i}-${u}`;
106
+ window.localStorage.setItem(E, JSON.stringify(w));
118
107
  }
119
- }, bt = (t, s, y, I, g, E) => {
120
- const _ = {
121
- initialState: s,
108
+ }, Tt = (t, i, m, y, u, w) => {
109
+ const E = {
110
+ initialState: i,
122
111
  updaterState: X(
123
112
  t,
124
- I,
125
- g,
126
- E
113
+ y,
114
+ u,
115
+ w
127
116
  ),
128
- state: y
117
+ state: m
129
118
  };
130
119
  H(() => {
131
- at(t, _.initialState), Y(t, _.updaterState), G(t, _.state);
120
+ ot(t, E.initialState), Y(t, E.updaterState), D(t, E.state);
132
121
  });
133
122
  }, St = (t) => {
134
- const s = r.getState().stateComponents.get(t);
135
- if (!s) return;
136
- const y = /* @__PURE__ */ new Set();
137
- s.components.forEach((I) => {
138
- y.add(() => I.forceUpdate());
123
+ const i = r.getState().stateComponents.get(t);
124
+ if (!i) return;
125
+ const m = /* @__PURE__ */ new Set();
126
+ i.components.forEach((y) => {
127
+ m.add(() => y.forceUpdate());
139
128
  }), queueMicrotask(() => {
140
129
  H(() => {
141
- y.forEach((I) => I());
130
+ m.forEach((y) => y());
142
131
  });
143
132
  });
144
- }, Bt = (t, s) => {
145
- const y = r.getState().stateComponents.get(t);
146
- if (y) {
147
- const I = `${t}////${s}`, g = y.components.get(I);
148
- g && g.forceUpdate();
133
+ }, Bt = (t, i) => {
134
+ const m = r.getState().stateComponents.get(t);
135
+ if (m) {
136
+ const y = `${t}////${i}`, u = m.components.get(y);
137
+ u && u.forceUpdate();
149
138
  }
150
139
  };
151
- function kt(t, {
152
- stateKey: s,
153
- serverSync: y,
154
- localStorage: I,
155
- formElements: g,
156
- middleware: E,
157
- reactiveDeps: _,
158
- reactiveType: f,
140
+ function Ot(t, {
141
+ stateKey: i,
142
+ serverSync: m,
143
+ localStorage: y,
144
+ formElements: u,
145
+ middleware: w,
146
+ reactiveDeps: E,
147
+ reactiveType: v,
159
148
  componentId: l,
160
- initialState: m,
149
+ initialState: f,
161
150
  syncUpdate: e,
162
151
  dependencies: S
163
152
  } = {}) {
164
- const [k, C] = et({}), { sessionId: b } = At();
165
- let U = !s;
166
- const [u] = et(s ?? rt()), i = r.getState().stateLog[u], L = Z(/* @__PURE__ */ new Set()), j = Z(l ?? rt()), x = Z(null);
167
- x.current = q(u), nt(() => {
168
- if (e && e.stateKey === u && e.path?.[0]) {
169
- G(u, (o) => ({
153
+ const [x, A] = et({}), { sessionId: T } = At();
154
+ let R = !i;
155
+ const [g] = et(i ?? rt()), s = r.getState().stateLog[g], G = Z(/* @__PURE__ */ new Set()), b = Z(l ?? rt()), C = Z(null);
156
+ C.current = q(g), nt(() => {
157
+ if (e && e.stateKey === g && e.path?.[0]) {
158
+ D(g, (o) => ({
170
159
  ...o,
171
160
  [e.path[0]]: e.newValue
172
161
  }));
@@ -177,218 +166,205 @@ function kt(t, {
177
166
  });
178
167
  }
179
168
  }, [e]), nt(() => {
180
- const c = x.current, o = m;
181
- let d = null;
182
- const $ = D(c?.localStorage?.key) ? c?.localStorage?.key(o ?? t) : c?.localStorage?.key;
183
- $ && b && (d = it(
184
- // Call existing load function
185
- b + "-" + u + "-" + $
169
+ dt(g, {
170
+ initialState: f
171
+ });
172
+ const c = C.current;
173
+ let o = null;
174
+ const d = L(c?.localStorage?.key) ? c?.localStorage?.key(f) : c?.localStorage?.key;
175
+ console.log("newoptions", c), console.log("localkey", d), console.log("initialState", f), d && T && (o = ft(
176
+ T + "-" + g + "-" + d
186
177
  ));
187
- let N = null, w = o ?? void 0, T = !1;
188
- if (d ? O(
189
- o,
190
- d.baseServerState
191
- ) ? (N = d.state, w = d.baseServerState, T = !0) : (N = o ?? t, w = o ?? void 0, console.warn(
192
- "Initial state differs from localStorage base. Using initialState."
193
- )) : (N = o ?? t, w = o ?? void 0), N !== null) {
194
- const A = ot(u);
195
- (!A || !O(A, N)) && (bt(
196
- u,
197
- o ?? t,
198
- // Pass the *actual* initialState prop reference
199
- N,
200
- n,
201
- j.current,
202
- b
203
- ), ft(
204
- N,
205
- u,
206
- c,
207
- b,
208
- w
209
- ), T && c?.localStorage?.onChange && c.localStorage.onChange(N), St(u), C({}));
210
- }
211
- }, [m, ...S || []]), vt(() => {
212
- U && ht(
213
- u,
178
+ let I = null, k = !1;
179
+ o && o.lastUpdated > (o.lastSyncedWithServer || 0) && (I = o.state, k = !0), f && (I = f), I && (console.log("newState thius is newstate", I), Tt(
180
+ g,
181
+ f,
182
+ I,
183
+ n,
184
+ b.current,
185
+ T
186
+ ), k && c?.localStorage?.onChange && c?.localStorage?.onChange(I), St(g), A({}));
187
+ }, [f, ...S || []]), It(() => {
188
+ R && dt(
189
+ g,
214
190
  {
215
- serverSync: y,
216
- formElements: g,
217
- initialState: m,
218
- localStorage: I,
219
- middleware: E
191
+ serverSync: m,
192
+ formElements: u,
193
+ initialState: f,
194
+ localStorage: y,
195
+ middleware: w
220
196
  }
221
197
  );
222
- const c = `${u}////${j.current}`, o = r.getState().stateComponents.get(u) || {
198
+ const c = `${g}////${b.current}`, o = r.getState().stateComponents.get(g) || {
223
199
  components: /* @__PURE__ */ new Map()
224
200
  };
225
201
  return o.components.set(c, {
226
- forceUpdate: () => C({}),
202
+ forceUpdate: () => A({}),
227
203
  paths: /* @__PURE__ */ new Set(),
228
204
  deps: [],
229
- depsFunction: _ || void 0,
230
- reactiveType: f ?? ["component", "deps"]
231
- }), r.getState().stateComponents.set(u, o), C({}), () => {
232
- const d = `${u}////${j.current}`;
233
- o && (o.components.delete(d), o.components.size === 0 && r.getState().stateComponents.delete(u));
205
+ depsFunction: E || void 0,
206
+ reactiveType: v ?? ["component", "deps"]
207
+ }), r.getState().stateComponents.set(g, o), A({}), () => {
208
+ const d = `${g}////${b.current}`;
209
+ o && (o.components.delete(d), o.components.size === 0 && r.getState().stateComponents.delete(g));
234
210
  };
235
211
  }, []);
236
- const n = (c, o, d, $) => {
212
+ const n = (c, o, d, I) => {
237
213
  if (Array.isArray(o)) {
238
- const N = `${u}-${o.join(".")}`;
239
- L.current.add(N);
214
+ const k = `${g}-${o.join(".")}`;
215
+ G.current.add(k);
240
216
  }
241
- G(u, (N) => {
242
- const w = D(c) ? c(N) : c, T = `${u}-${o.join(".")}`;
243
- if (T) {
244
- let P = !1, v = r.getState().signalDomElements.get(T);
245
- if ((!v || v.size === 0) && (d.updateType === "insert" || d.updateType === "cut")) {
246
- const h = o.slice(0, -1), p = M(w, h);
247
- if (Array.isArray(p)) {
248
- P = !0;
249
- const V = `${u}-${h.join(".")}`;
250
- v = r.getState().signalDomElements.get(V);
217
+ D(g, (k) => {
218
+ const N = L(c) ? c(k) : c, j = `${g}-${o.join(".")}`;
219
+ if (j) {
220
+ let F = !1, _ = r.getState().signalDomElements.get(j);
221
+ if ((!_ || _.size === 0) && (d.updateType === "insert" || d.updateType === "cut")) {
222
+ const V = o.slice(0, -1), h = U(N, V);
223
+ if (Array.isArray(h)) {
224
+ F = !0;
225
+ const $ = `${g}-${V.join(".")}`;
226
+ _ = r.getState().signalDomElements.get($);
251
227
  }
252
228
  }
253
- if (v) {
254
- const h = P ? M(w, o.slice(0, -1)) : M(w, o);
255
- v.forEach(({ parentId: p, position: V, effect: W }) => {
256
- const F = document.querySelector(
257
- `[data-parent-id="${p}"]`
229
+ if (_) {
230
+ const V = F ? U(N, o.slice(0, -1)) : U(N, o);
231
+ _.forEach(({ parentId: h, position: $, effect: W }) => {
232
+ const O = document.querySelector(
233
+ `[data-parent-id="${h}"]`
258
234
  );
259
- if (F) {
260
- const lt = Array.from(F.childNodes);
261
- if (lt[V]) {
262
- const It = W ? new Function("state", `return (${W})(state)`)(h) : h;
263
- lt[V].textContent = String(It);
235
+ if (O) {
236
+ const st = Array.from(O.childNodes);
237
+ if (st[$]) {
238
+ const vt = W ? new Function("state", `return (${W})(state)`)(V) : V;
239
+ st[$].textContent = String(vt);
264
240
  }
265
241
  }
266
242
  });
267
243
  }
268
244
  }
269
- d.updateType === "update" && ($ || x.current?.validationKey) && o && R(
270
- ($ || x.current?.validationKey) + "." + o.join(".")
245
+ d.updateType === "update" && (I || C.current?.validationKey) && o && P(
246
+ (I || C.current?.validationKey) + "." + o.join(".")
271
247
  );
272
- const A = o.slice(0, o.length - 1);
273
- d.updateType === "cut" && x.current?.validationKey && R(
274
- x.current?.validationKey + "." + A.join(".")
275
- ), d.updateType === "insert" && x.current?.validationKey && Ct(
276
- x.current?.validationKey + "." + A.join(".")
277
- ).filter(([v, h]) => {
278
- let p = v?.split(".").length;
279
- if (v == A.join(".") && p == A.length - 1) {
280
- let V = v + "." + A;
281
- R(v), xt(V, h);
248
+ const p = o.slice(0, o.length - 1);
249
+ d.updateType === "cut" && C.current?.validationKey && P(
250
+ C.current?.validationKey + "." + p.join(".")
251
+ ), d.updateType === "insert" && C.current?.validationKey && ht(
252
+ C.current?.validationKey + "." + p.join(".")
253
+ ).filter(([_, V]) => {
254
+ let h = _?.split(".").length;
255
+ if (_ == p.join(".") && h == p.length - 1) {
256
+ let $ = _ + "." + p;
257
+ P(_), kt($, V);
282
258
  }
283
259
  });
284
- const z = M(N, o), mt = M(w, o), yt = d.updateType === "update" ? o.join(".") : [...o].slice(0, -1).join("."), st = r.getState().stateComponents.get(u);
285
- if (st)
286
- for (const [P, v] of st.components.entries()) {
287
- let h = !1;
288
- const p = Array.isArray(v.reactiveType) ? v.reactiveType : [v.reactiveType || "component"];
289
- if (!p.includes("none")) {
290
- if (p.includes("all")) {
291
- v.forceUpdate();
260
+ const z = U(k, o), mt = U(N, o), yt = d.updateType === "update" ? o.join(".") : [...o].slice(0, -1).join("."), at = r.getState().stateComponents.get(g);
261
+ if (at)
262
+ for (const [F, _] of at.components.entries()) {
263
+ let V = !1;
264
+ const h = Array.isArray(_.reactiveType) ? _.reactiveType : [_.reactiveType || "component"];
265
+ if (!h.includes("none")) {
266
+ if (h.includes("all")) {
267
+ _.forceUpdate();
292
268
  continue;
293
269
  }
294
- if (p.includes("component") && v.paths && (v.paths.has(yt) || v.paths.has("")) && (h = !0), !h && p.includes("deps") && v.depsFunction) {
295
- const V = v.depsFunction(w);
296
- typeof V == "boolean" ? V && (h = !0) : O(v.deps, V) || (v.deps = V, h = !0);
270
+ if (h.includes("component") && _.paths && (_.paths.has(yt) || _.paths.has("")) && (V = !0), !V && h.includes("deps") && _.depsFunction) {
271
+ const $ = _.depsFunction(N);
272
+ typeof $ == "boolean" ? $ && (V = !0) : M(_.deps, $) || (_.deps = $, V = !0);
297
273
  }
298
- h && v.forceUpdate();
274
+ V && _.forceUpdate();
299
275
  }
300
276
  }
301
- const ct = {
277
+ const it = {
302
278
  timeStamp: Date.now(),
303
- stateKey: u,
279
+ stateKey: g,
304
280
  path: o,
305
281
  updateType: d.updateType,
306
282
  status: "new",
307
283
  oldValue: z,
308
284
  newValue: mt
309
285
  };
310
- if (pt(u, (P) => {
311
- const h = [...P ?? [], ct].reduce((p, V) => {
312
- const W = `${V.stateKey}:${JSON.stringify(V.path)}`, F = p.get(W);
313
- return F ? (F.timeStamp = Math.max(F.timeStamp, V.timeStamp), F.newValue = V.newValue, F.oldValue = F.oldValue ?? V.oldValue, F.updateType = V.updateType) : p.set(W, { ...V }), p;
286
+ if (Ct(g, (F) => {
287
+ const V = [...F ?? [], it].reduce((h, $) => {
288
+ const W = `${$.stateKey}:${JSON.stringify($.path)}`, O = h.get(W);
289
+ return O ? (O.timeStamp = Math.max(O.timeStamp, $.timeStamp), O.newValue = $.newValue, O.oldValue = O.oldValue ?? $.oldValue, O.updateType = $.updateType) : h.set(W, { ...$ }), h;
314
290
  }, /* @__PURE__ */ new Map());
315
- return Array.from(h.values());
316
- }), ft(
317
- w,
318
- u,
319
- x.current,
320
- b
321
- ), E && E({
322
- updateLog: i,
323
- update: ct
324
- }), x.current?.serverSync) {
325
- const P = r.getState().serverState[u], v = x.current?.serverSync;
326
- Tt(u, {
327
- syncKey: typeof v.syncKey == "string" ? v.syncKey : v.syncKey({ state: w }),
328
- rollBackState: P,
329
- actionTimeStamp: Date.now() + (v.debounce ?? 3e3),
291
+ return Array.from(V.values());
292
+ }), xt(
293
+ N,
294
+ g,
295
+ C.current,
296
+ T
297
+ ), w && w({
298
+ updateLog: s,
299
+ update: it
300
+ }), C.current?.serverSync) {
301
+ const F = r.getState().serverState[g], _ = C.current?.serverSync;
302
+ pt(g, {
303
+ syncKey: typeof _.syncKey == "string" ? _.syncKey : _.syncKey({ state: N }),
304
+ rollBackState: F,
305
+ actionTimeStamp: Date.now() + (_.debounce ?? 3e3),
330
306
  status: "waiting"
331
307
  });
332
308
  }
333
- return w;
309
+ return N;
334
310
  });
335
311
  };
336
- r.getState().updaterState[u] || (Y(
337
- u,
312
+ r.getState().updaterState[g] || (Y(
313
+ g,
338
314
  X(
339
- u,
315
+ g,
340
316
  n,
341
- j.current,
342
- b
317
+ b.current,
318
+ T
343
319
  )
344
- ), r.getState().cogsStateStore[u] || G(u, t), r.getState().initialStateGlobal[u] || at(u, t));
320
+ ), r.getState().cogsStateStore[g] || D(g, t), r.getState().initialStateGlobal[g] || ot(g, t));
345
321
  const a = _t(() => X(
346
- u,
322
+ g,
347
323
  n,
348
- j.current,
349
- b
350
- ), [u]);
351
- return [ot(u), a];
324
+ b.current,
325
+ T
326
+ ), [g]);
327
+ return [gt(g), a];
352
328
  }
353
- function X(t, s, y, I) {
354
- const g = /* @__PURE__ */ new Map();
355
- let E = 0;
356
- const _ = (m) => {
357
- const e = m.join(".");
358
- for (const [S] of g)
359
- (S === e || S.startsWith(e + ".")) && g.delete(S);
360
- E++;
361
- }, f = {
362
- removeValidation: (m) => {
363
- m?.validationKey && R(m.validationKey);
329
+ function X(t, i, m, y) {
330
+ const u = /* @__PURE__ */ new Map();
331
+ let w = 0;
332
+ const E = (f) => {
333
+ const e = f.join(".");
334
+ for (const [S] of u)
335
+ (S === e || S.startsWith(e + ".")) && u.delete(S);
336
+ w++;
337
+ }, v = {
338
+ removeValidation: (f) => {
339
+ f?.validationKey && P(f.validationKey);
364
340
  },
365
- revertToInitialState: (m) => {
341
+ revertToInitialState: (f) => {
366
342
  const e = r.getState().getInitialOptions(t)?.validation;
367
- e?.key && R(e?.key), m?.validationKey && R(m.validationKey);
343
+ e?.key && P(e?.key), f?.validationKey && P(f.validationKey);
368
344
  const S = r.getState().initialStateGlobal[t];
369
- g.clear(), E++;
370
- const k = l(S, []), C = q(t), b = D(C?.localStorage?.key) ? C?.localStorage?.key(S) : C?.localStorage?.key, U = `${I}-${t}-${b}`;
371
- return U && localStorage.removeItem(U), H(() => {
372
- Y(t, k), G(t, S);
373
- const u = r.getState().stateComponents.get(t);
374
- u && u.components.forEach((i) => {
375
- i.forceUpdate();
345
+ u.clear(), w++;
346
+ const x = l(S, []), A = q(t), T = L(A?.localStorage?.key) ? A?.localStorage?.key(S) : A?.localStorage?.key, R = `${y}-${t}-${T}`;
347
+ return R && localStorage.removeItem(R), H(() => {
348
+ Y(t, x), D(t, S);
349
+ const g = r.getState().stateComponents.get(t);
350
+ g && g.components.forEach((s) => {
351
+ s.forceUpdate();
376
352
  });
377
353
  }), S;
378
354
  },
379
- updateInitialState: (m) => {
380
- g.clear(), E++;
355
+ updateInitialState: (f) => {
356
+ u.clear(), w++;
381
357
  const e = X(
382
358
  t,
383
- s,
384
- y,
385
- I
359
+ i,
360
+ m,
361
+ y
386
362
  );
387
363
  return H(() => {
388
- at(t, m), Y(t, e), G(t, m);
364
+ ot(t, f), Y(t, e), D(t, f);
389
365
  const S = r.getState().stateComponents.get(t);
390
- S && S.components.forEach((k) => {
391
- k.forceUpdate();
366
+ S && S.components.forEach((x) => {
367
+ x.forceUpdate();
392
368
  });
393
369
  }), {
394
370
  fetchId: (S) => e.get()[S]
@@ -398,105 +374,105 @@ function X(t, s, y, I) {
398
374
  _serverState: r.getState().serverState[t],
399
375
  _isLoading: r.getState().isLoadingGlobal[t],
400
376
  _isServerSynced: () => {
401
- const m = r.getState().serverState[t];
402
- return !!(m && O(m, ot(t)));
377
+ const f = r.getState().serverState[t];
378
+ return !!(f && M(f, gt(t)));
403
379
  }
404
380
  };
405
- function l(m, e = [], S) {
406
- const k = e.map(String).join(".");
407
- g.get(k);
408
- const C = function() {
381
+ function l(f, e = [], S) {
382
+ const x = e.map(String).join(".");
383
+ u.get(x);
384
+ const A = function() {
409
385
  return r().getNestedState(t, e);
410
386
  };
411
- Object.keys(f).forEach((u) => {
412
- C[u] = f[u];
387
+ Object.keys(v).forEach((g) => {
388
+ A[g] = v[g];
413
389
  });
414
- const b = {
415
- apply(u, i, L) {
390
+ const T = {
391
+ apply(g, s, G) {
416
392
  return console.log(
417
393
  `PROXY APPLY TRAP HIT: stateKey=${t}, path=${e.join(".")}`
418
394
  ), console.trace("Apply trap stack trace"), r().getNestedState(t, e);
419
395
  },
420
- get(u, i) {
421
- if (i !== "then" && !i.startsWith("$") && i !== "stateMapNoRender") {
422
- const n = e.join("."), a = `${t}////${y}`, c = r.getState().stateComponents.get(t);
396
+ get(g, s) {
397
+ if (s !== "then" && !s.startsWith("$") && s !== "stateMapNoRender") {
398
+ const n = e.join("."), a = `${t}////${m}`, c = r.getState().stateComponents.get(t);
423
399
  if (c) {
424
400
  const o = c.components.get(a);
425
- o && (e.length > 0 || i === "get") && o.paths.add(n);
401
+ o && (e.length > 0 || s === "get") && o.paths.add(n);
426
402
  }
427
403
  }
428
- if (i === "_status") {
429
- const n = r.getState().getNestedState(t, e), a = r.getState().initialStateGlobal[t], c = M(a, e);
430
- return O(n, c) ? "fresh" : "stale";
404
+ if (s === "_status") {
405
+ const n = r.getState().getNestedState(t, e), a = r.getState().initialStateGlobal[t], c = U(a, e);
406
+ return M(n, c) ? "fresh" : "stale";
431
407
  }
432
- if (i === "getStatus")
408
+ if (s === "getStatus")
433
409
  return function() {
434
410
  const n = r().getNestedState(
435
411
  t,
436
412
  e
437
- ), a = r.getState().initialStateGlobal[t], c = M(a, e);
438
- return O(n, c) ? "fresh" : "stale";
413
+ ), a = r.getState().initialStateGlobal[t], c = U(a, e);
414
+ return M(n, c) ? "fresh" : "stale";
439
415
  };
440
- if (i === "removeStorage")
416
+ if (s === "removeStorage")
441
417
  return () => {
442
- const n = r.getState().initialStateGlobal[t], a = q(t), c = D(a?.localStorage?.key) ? a?.localStorage?.key(n) : a?.localStorage?.key, o = `${I}-${t}-${c}`;
418
+ const n = r.getState().initialStateGlobal[t], a = q(t), c = L(a?.localStorage?.key) ? a?.localStorage?.key(n) : a?.localStorage?.key, o = `${y}-${t}-${c}`;
443
419
  console.log("removing storage", o), o && localStorage.removeItem(o);
444
420
  };
445
- if (i === "showValidationErrors")
421
+ if (s === "showValidationErrors")
446
422
  return () => {
447
423
  const n = r.getState().getInitialOptions(t)?.validation;
448
424
  if (!n?.key)
449
425
  throw new Error("Validation key not found");
450
426
  return r.getState().getValidationErrors(n.key + "." + e.join("."));
451
427
  };
452
- if (Array.isArray(m)) {
453
- if (i === "getSelected")
428
+ if (Array.isArray(f)) {
429
+ if (s === "getSelected")
454
430
  return () => {
455
431
  const n = r.getState().getSelectedIndex(t, e.join("."));
456
432
  if (n !== void 0)
457
433
  return l(
458
- m[n],
434
+ f[n],
459
435
  [...e, n.toString()],
460
436
  S
461
437
  );
462
438
  };
463
- if (i === "getSelectedIndex")
439
+ if (s === "getSelectedIndex")
464
440
  return () => r.getState().getSelectedIndex(t, e.join(".")) ?? -1;
465
- if (i === "stateSort")
441
+ if (s === "stateSort")
466
442
  return (n) => {
467
- const o = [...r.getState().getNestedState(t, e).map((d, $) => ({
443
+ const o = [...r.getState().getNestedState(t, e).map((d, I) => ({
468
444
  ...d,
469
- __origIndex: $.toString()
445
+ __origIndex: I.toString()
470
446
  }))].sort(n);
471
- return g.clear(), E++, l(o, e, {
447
+ return u.clear(), w++, l(o, e, {
472
448
  filtered: [...S?.filtered || [], e],
473
449
  validIndices: o.map(
474
450
  (d) => parseInt(d.__origIndex)
475
451
  )
476
452
  });
477
453
  };
478
- if (i === "stateMap" || i === "stateMapNoRender")
454
+ if (s === "stateMap" || s === "stateMapNoRender")
479
455
  return (n) => {
480
456
  const a = S?.filtered?.some(
481
457
  (o) => o.join(".") === e.join(".")
482
- ), c = a ? m : r.getState().getNestedState(t, e);
483
- return i !== "stateMapNoRender" && (g.clear(), E++), c.map((o, d) => {
484
- const $ = a && o.__origIndex ? o.__origIndex : d, N = l(
458
+ ), c = a ? f : r.getState().getNestedState(t, e);
459
+ return s !== "stateMapNoRender" && (u.clear(), w++), c.map((o, d) => {
460
+ const I = a && o.__origIndex ? o.__origIndex : d, k = l(
485
461
  o,
486
- [...e, $.toString()],
462
+ [...e, I.toString()],
487
463
  S
488
464
  );
489
465
  return n(
490
466
  o,
491
- N,
467
+ k,
492
468
  d,
493
- m,
494
- l(m, e, S)
469
+ f,
470
+ l(f, e, S)
495
471
  );
496
472
  });
497
473
  };
498
- if (i === "$stateMap")
499
- return (n) => Q(Ft, {
474
+ if (s === "$stateMap")
475
+ return (n) => Q(jt, {
500
476
  proxy: {
501
477
  _stateKey: t,
502
478
  _path: e,
@@ -505,14 +481,14 @@ function X(t, s, y, I) {
505
481
  },
506
482
  rebuildStateShape: l
507
483
  });
508
- if (i === "stateFlattenOn")
484
+ if (s === "stateFlattenOn")
509
485
  return (n) => {
510
486
  const c = S?.filtered?.some(
511
487
  (d) => d.join(".") === e.join(".")
512
- ) ? m : r.getState().getNestedState(t, e);
513
- g.clear(), E++;
488
+ ) ? f : r.getState().getNestedState(t, e);
489
+ u.clear(), w++;
514
490
  const o = c.flatMap(
515
- (d, $) => d[n] ?? []
491
+ (d, I) => d[n] ?? []
516
492
  );
517
493
  return l(
518
494
  o,
@@ -520,170 +496,170 @@ function X(t, s, y, I) {
520
496
  S
521
497
  );
522
498
  };
523
- if (i === "findWith")
499
+ if (s === "findWith")
524
500
  return (n, a) => {
525
- const c = m.findIndex(
526
- ($) => $[n] === a
501
+ const c = f.findIndex(
502
+ (I) => I[n] === a
527
503
  );
528
504
  if (c === -1) return;
529
- const o = m[c], d = [...e, c.toString()];
530
- return g.clear(), E++, g.clear(), E++, l(o, d);
505
+ const o = f[c], d = [...e, c.toString()];
506
+ return u.clear(), w++, u.clear(), w++, l(o, d);
531
507
  };
532
- if (i === "index")
508
+ if (s === "index")
533
509
  return (n) => {
534
- const a = m[n];
510
+ const a = f[n];
535
511
  return l(a, [...e, n.toString()]);
536
512
  };
537
- if (i === "insert")
538
- return (n) => (_(e), K(s, n, e, t), l(
513
+ if (s === "insert")
514
+ return (n) => (E(e), K(i, n, e, t), l(
539
515
  r.getState().cogsStateStore[t],
540
516
  []
541
517
  ));
542
- if (i === "uniqueInsert")
518
+ if (s === "uniqueInsert")
543
519
  return (n, a, c) => {
544
- const o = r.getState().getNestedState(t, e), d = D(n) ? n(o) : n;
545
- let $ = null;
546
- if (!o.some((w) => {
520
+ const o = r.getState().getNestedState(t, e), d = L(n) ? n(o) : n;
521
+ let I = null;
522
+ if (!o.some((N) => {
547
523
  if (a) {
548
- const A = a.every(
549
- (z) => O(w[z], d[z])
524
+ const p = a.every(
525
+ (z) => M(N[z], d[z])
550
526
  );
551
- return A && ($ = w), A;
527
+ return p && (I = N), p;
552
528
  }
553
- const T = O(w, d);
554
- return T && ($ = w), T;
529
+ const j = M(N, d);
530
+ return j && (I = N), j;
555
531
  }))
556
- _(e), K(s, d, e, t);
557
- else if (c && $) {
558
- const w = c($), T = o.map(
559
- (A) => O(A, $) ? w : A
532
+ E(e), K(i, d, e, t);
533
+ else if (c && I) {
534
+ const N = c(I), j = o.map(
535
+ (p) => M(p, I) ? N : p
560
536
  );
561
- _(e), B(s, T, e);
537
+ E(e), B(i, j, e);
562
538
  }
563
539
  };
564
- if (i === "cut")
540
+ if (s === "cut")
565
541
  return (n, a) => {
566
- a?.waitForSync || (_(e), J(s, e, t, n));
542
+ a?.waitForSync || (E(e), J(i, e, t, n));
567
543
  };
568
- if (i === "cutByValue")
544
+ if (s === "cutByValue")
569
545
  return (n) => {
570
- for (let a = 0; a < m.length; a++)
571
- m[a] === n && J(s, e, t, a);
546
+ for (let a = 0; a < f.length; a++)
547
+ f[a] === n && J(i, e, t, a);
572
548
  };
573
- if (i === "toggleByValue")
549
+ if (s === "toggleByValue")
574
550
  return (n) => {
575
- const a = m.findIndex((c) => c === n);
576
- a > -1 ? J(s, e, t, a) : K(s, n, e, t);
551
+ const a = f.findIndex((c) => c === n);
552
+ a > -1 ? J(i, e, t, a) : K(i, n, e, t);
577
553
  };
578
- if (i === "stateFilter")
554
+ if (s === "stateFilter")
579
555
  return (n) => {
580
- const a = m.map((d, $) => ({
556
+ const a = f.map((d, I) => ({
581
557
  ...d,
582
- __origIndex: $.toString()
558
+ __origIndex: I.toString()
583
559
  })), c = [], o = [];
584
560
  for (let d = 0; d < a.length; d++)
585
561
  n(a[d], d) && (c.push(d), o.push(a[d]));
586
- return g.clear(), E++, l(o, e, {
562
+ return u.clear(), w++, l(o, e, {
587
563
  filtered: [...S?.filtered || [], e],
588
564
  validIndices: c
589
565
  // Always pass validIndices, even if empty
590
566
  });
591
567
  };
592
568
  }
593
- const L = e[e.length - 1];
594
- if (!isNaN(Number(L))) {
569
+ const G = e[e.length - 1];
570
+ if (!isNaN(Number(G))) {
595
571
  const n = e.slice(0, -1), a = r.getState().getNestedState(t, n);
596
- if (Array.isArray(a) && i === "cut")
572
+ if (Array.isArray(a) && s === "cut")
597
573
  return () => J(
598
- s,
574
+ i,
599
575
  n,
600
576
  t,
601
- Number(L)
577
+ Number(G)
602
578
  );
603
579
  }
604
- if (i === "get")
580
+ if (s === "get")
605
581
  return () => r.getState().getNestedState(t, e);
606
- if (i === "$derive")
582
+ if (s === "$derive")
607
583
  return (n) => tt({
608
584
  _stateKey: t,
609
585
  _path: e,
610
586
  _effect: n.toString()
611
587
  });
612
- if (i === "$derive")
588
+ if (s === "$derive")
613
589
  return (n) => tt({
614
590
  _stateKey: t,
615
591
  _path: e,
616
592
  _effect: n.toString()
617
593
  });
618
- if (i === "$get")
594
+ if (s === "$get")
619
595
  return () => tt({
620
596
  _stateKey: t,
621
597
  _path: e
622
598
  });
623
- if (i === "lastSynced") {
599
+ if (s === "lastSynced") {
624
600
  const n = `${t}:${e.join(".")}`;
625
601
  return r.getState().getSyncInfo(n);
626
602
  }
627
- if (i == "getLocalStorage")
628
- return (n) => it(I + "-" + t + "-" + n);
629
- if (i === "_selected") {
603
+ if (s == "getLocalStorage")
604
+ return (n) => ft(y + "-" + t + "-" + n);
605
+ if (s === "_selected") {
630
606
  const n = e.slice(0, -1), a = n.join("."), c = r.getState().getNestedState(t, n);
631
607
  return Array.isArray(c) ? Number(e[e.length - 1]) === r.getState().getSelectedIndex(t, a) : void 0;
632
608
  }
633
- if (i === "setSelected")
609
+ if (s === "setSelected")
634
610
  return (n) => {
635
611
  const a = e.slice(0, -1), c = Number(e[e.length - 1]), o = a.join(".");
636
612
  n ? r.getState().setSelectedIndex(t, o, c) : r.getState().setSelectedIndex(t, o, void 0);
637
613
  const d = r.getState().getNestedState(t, [...a]);
638
- B(s, d, a), _(a);
614
+ B(i, d, a), E(a);
639
615
  };
640
616
  if (e.length == 0) {
641
- if (i === "validateZodSchema")
617
+ if (s === "validateZodSchema")
642
618
  return () => {
643
619
  const n = r.getState().getInitialOptions(t)?.validation, a = r.getState().addValidationError;
644
620
  if (!n?.zodSchema)
645
621
  throw new Error("Zod schema not found");
646
622
  if (!n?.key)
647
623
  throw new Error("Validation key not found");
648
- R(n.key);
624
+ P(n.key);
649
625
  const c = r.getState().cogsStateStore[t];
650
626
  try {
651
627
  const o = r.getState().getValidationErrors(n.key);
652
- o && o.length > 0 && o.forEach(([$]) => {
653
- $ && $.startsWith(n.key) && R($);
628
+ o && o.length > 0 && o.forEach(([I]) => {
629
+ I && I.startsWith(n.key) && P(I);
654
630
  });
655
631
  const d = n.zodSchema.safeParse(c);
656
- return d.success ? !0 : (d.error.errors.forEach((N) => {
657
- const w = N.path, T = N.message, A = [n.key, ...w].join(".");
658
- a(A, T);
632
+ return d.success ? !0 : (d.error.errors.forEach((k) => {
633
+ const N = k.path, j = k.message, p = [n.key, ...N].join(".");
634
+ a(p, j);
659
635
  }), St(t), !1);
660
636
  } catch (o) {
661
637
  return console.error("Zod schema validation failed", o), !1;
662
638
  }
663
639
  };
664
- if (i === "_componentId") return y;
665
- if (i === "getComponents")
640
+ if (s === "_componentId") return m;
641
+ if (s === "getComponents")
666
642
  return () => r().stateComponents.get(t);
667
- if (i === "getAllFormRefs")
668
- return () => ut.getState().getFormRefsByStateKey(t);
669
- if (i === "_initialState")
643
+ if (s === "getAllFormRefs")
644
+ return () => lt.getState().getFormRefsByStateKey(t);
645
+ if (s === "_initialState")
670
646
  return r.getState().initialStateGlobal[t];
671
- if (i === "_serverState")
647
+ if (s === "_serverState")
672
648
  return r.getState().serverState[t];
673
- if (i === "_isLoading")
649
+ if (s === "_isLoading")
674
650
  return r.getState().isLoadingGlobal[t];
675
- if (i === "revertToInitialState")
676
- return f.revertToInitialState;
677
- if (i === "updateInitialState") return f.updateInitialState;
678
- if (i === "removeValidation") return f.removeValidation;
651
+ if (s === "revertToInitialState")
652
+ return v.revertToInitialState;
653
+ if (s === "updateInitialState") return v.updateInitialState;
654
+ if (s === "removeValidation") return v.removeValidation;
679
655
  }
680
- if (i === "getFormRef")
681
- return () => ut.getState().getFormRef(t + "." + e.join("."));
682
- if (i === "validationWrapper")
656
+ if (s === "getFormRef")
657
+ return () => lt.getState().getFormRef(t + "." + e.join("."));
658
+ if (s === "validationWrapper")
683
659
  return ({
684
660
  children: n,
685
661
  hideMessage: a
686
- }) => /* @__PURE__ */ dt(
662
+ }) => /* @__PURE__ */ ct(
687
663
  Nt,
688
664
  {
689
665
  formOpts: a ? { validation: { message: "" } } : void 0,
@@ -694,80 +670,80 @@ function X(t, s, y, I) {
694
670
  children: n
695
671
  }
696
672
  );
697
- if (i === "_stateKey") return t;
698
- if (i === "_path") return e;
699
- if (i === "_isServerSynced") return f._isServerSynced;
700
- if (i === "update")
673
+ if (s === "_stateKey") return t;
674
+ if (s === "_path") return e;
675
+ if (s === "_isServerSynced") return v._isServerSynced;
676
+ if (s === "update")
701
677
  return (n, a) => {
702
678
  if (a?.debounce)
703
- wt(() => {
704
- B(s, n, e, "");
679
+ $t(() => {
680
+ B(i, n, e, "");
705
681
  const c = r.getState().getNestedState(t, e);
706
682
  a?.afterUpdate && a.afterUpdate(c);
707
683
  }, a.debounce);
708
684
  else {
709
- B(s, n, e, "");
685
+ B(i, n, e, "");
710
686
  const c = r.getState().getNestedState(t, e);
711
687
  a?.afterUpdate && a.afterUpdate(c);
712
688
  }
713
- _(e);
689
+ E(e);
714
690
  };
715
- if (i === "formElement")
716
- return (n, a) => /* @__PURE__ */ dt(
691
+ if (s === "formElement")
692
+ return (n, a) => /* @__PURE__ */ ct(
717
693
  Vt,
718
694
  {
719
- setState: s,
695
+ setState: i,
720
696
  stateKey: t,
721
697
  path: e,
722
698
  child: n,
723
699
  formOpts: a
724
700
  }
725
701
  );
726
- const j = [...e, i], x = r.getState().getNestedState(t, j);
727
- return l(x, j, S);
702
+ const b = [...e, s], C = r.getState().getNestedState(t, b);
703
+ return l(C, b, S);
728
704
  }
729
- }, U = new Proxy(C, b);
730
- return g.set(k, {
731
- proxy: U,
732
- stateVersion: E
733
- }), U;
705
+ }, R = new Proxy(A, T);
706
+ return u.set(x, {
707
+ proxy: R,
708
+ stateVersion: w
709
+ }), R;
734
710
  }
735
711
  return l(
736
712
  r.getState().getNestedState(t, [])
737
713
  );
738
714
  }
739
715
  function tt(t) {
740
- return Q(Ot, { proxy: t });
716
+ return Q(bt, { proxy: t });
741
717
  }
742
- function Ft({
718
+ function jt({
743
719
  proxy: t,
744
- rebuildStateShape: s
720
+ rebuildStateShape: i
745
721
  }) {
746
- const y = r().getNestedState(t._stateKey, t._path);
747
- return Array.isArray(y) ? s(
748
- y,
722
+ const m = r().getNestedState(t._stateKey, t._path);
723
+ return Array.isArray(m) ? i(
724
+ m,
749
725
  t._path
750
726
  ).stateMapNoRender(
751
- (g, E, _, f, l) => t._mapFn(g, E, _, f, l)
727
+ (u, w, E, v, l) => t._mapFn(u, w, E, v, l)
752
728
  ) : null;
753
729
  }
754
- function Ot({
730
+ function bt({
755
731
  proxy: t
756
732
  }) {
757
- const s = Z(null), y = `${t._stateKey}-${t._path.join(".")}`;
733
+ const i = Z(null), m = `${t._stateKey}-${t._path.join(".")}`;
758
734
  return nt(() => {
759
- const I = s.current;
760
- if (!I || !I.parentElement) return;
761
- const g = I.parentElement, _ = Array.from(g.childNodes).indexOf(I);
762
- let f = g.getAttribute("data-parent-id");
763
- f || (f = `parent-${crypto.randomUUID()}`, g.setAttribute("data-parent-id", f));
764
- const m = {
735
+ const y = i.current;
736
+ if (!y || !y.parentElement) return;
737
+ const u = y.parentElement, E = Array.from(u.childNodes).indexOf(y);
738
+ let v = u.getAttribute("data-parent-id");
739
+ v || (v = `parent-${crypto.randomUUID()}`, u.setAttribute("data-parent-id", v));
740
+ const f = {
765
741
  instanceId: `instance-${crypto.randomUUID()}`,
766
- parentId: f,
767
- position: _,
742
+ parentId: v,
743
+ position: E,
768
744
  effect: t._effect
769
745
  };
770
- r.getState().addSignalElement(y, m);
746
+ r.getState().addSignalElement(m, f);
771
747
  const e = r.getState().getNestedState(t._stateKey, t._path);
772
748
  let S;
773
749
  if (t._effect)
@@ -776,34 +752,34 @@ function Ot({
776
752
  "state",
777
753
  `return (${t._effect})(state)`
778
754
  )(e);
779
- } catch (C) {
780
- console.error("Error evaluating effect function during mount:", C), S = e;
755
+ } catch (A) {
756
+ console.error("Error evaluating effect function during mount:", A), S = e;
781
757
  }
782
758
  else
783
759
  S = e;
784
760
  S !== null && typeof S == "object" && (S = JSON.stringify(S));
785
- const k = document.createTextNode(String(S));
786
- I.replaceWith(k);
761
+ const x = document.createTextNode(String(S));
762
+ y.replaceWith(x);
787
763
  }, [t._stateKey, t._path.join("."), t._effect]), Q("span", {
788
- ref: s,
764
+ ref: i,
789
765
  style: { display: "none" },
790
- "data-signal-id": y
766
+ "data-signal-id": m
791
767
  });
792
768
  }
793
769
  function Jt(t) {
794
- const s = Et(
795
- (y) => {
796
- const I = r.getState().stateComponents.get(t._stateKey) || {
770
+ const i = Et(
771
+ (m) => {
772
+ const y = r.getState().stateComponents.get(t._stateKey) || {
797
773
  components: /* @__PURE__ */ new Map()
798
774
  };
799
- return I.components.set(t._stateKey, {
800
- forceUpdate: y,
775
+ return y.components.set(t._stateKey, {
776
+ forceUpdate: m,
801
777
  paths: /* @__PURE__ */ new Set([t._path.join(".")])
802
- }), () => I.components.delete(t._stateKey);
778
+ }), () => y.components.delete(t._stateKey);
803
779
  },
804
780
  () => r.getState().getNestedState(t._stateKey, t._path)
805
781
  );
806
- return Q("text", {}, String(s));
782
+ return Q("text", {}, String(i));
807
783
  }
808
784
  export {
809
785
  tt as $cogsSignal,
@@ -811,6 +787,6 @@ export {
811
787
  qt as addStateOptions,
812
788
  zt as createCogsState,
813
789
  Bt as notifyComponent,
814
- kt as useCogsStateFn
790
+ Ot as useCogsStateFn
815
791
  };
816
792
  //# sourceMappingURL=CogsState.jsx.map