cogsbox-state 0.5.115 → 0.5.117

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.
@@ -8,9 +8,9 @@ import { getGlobalStore as r, formRefStore as ct } from "./store.js";
8
8
  import { useCogsConfig as At } from "./CogsStateClient.jsx";
9
9
  import nt from "./node_modules/uuid/dist/esm-browser/v4.js";
10
10
  function lt(t, i) {
11
- const m = r.getState().getInitialOptions, y = r.getState().setInitialStateOptions, u = m(t) || {};
11
+ const m = r.getState().getInitialOptions, y = r.getState().setInitialStateOptions, g = m(t) || {};
12
12
  y(t, {
13
- ...u,
13
+ ...g,
14
14
  ...i
15
15
  });
16
16
  }
@@ -19,36 +19,36 @@ function dt({
19
19
  options: i,
20
20
  initialOptionsPart: m
21
21
  }) {
22
- const y = q(t) || {}, u = m[t] || {}, w = r.getState().setInitialStateOptions, _ = { ...u, ...y };
22
+ const y = q(t) || {}, g = m[t] || {}, E = r.getState().setInitialStateOptions, _ = { ...g, ...y };
23
23
  let v = !1;
24
24
  if (i)
25
25
  for (const c in i)
26
26
  _.hasOwnProperty(c) ? (c == "localStorage" && i[c] && _[c].key !== i[c]?.key && (v = !0, _[c] = i[c]), c == "initialState" && i[c] && _[c] !== i[c] && (v = !0, _[c] = i[c])) : (v = !0, _[c] = i[c]);
27
- v && w(t, _);
27
+ v && E(t, _);
28
28
  }
29
29
  function qt(t, { formElements: i, validation: m }) {
30
30
  return { initialState: t, formElements: i, validation: m };
31
31
  }
32
32
  const zt = (t, i) => {
33
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 = {
34
+ const [y, g] = wt(m);
35
+ (Object.keys(g).length > 0 || i && Object.keys(i).length > 0) && Object.keys(g).forEach((v) => {
36
+ g[v] = g[v] || {}, g[v].formElements = {
37
37
  ...i?.formElements,
38
38
  // Global defaults first
39
39
  ...i?.validation,
40
- ...u[v].formElements || {}
40
+ ...g[v].formElements || {}
41
41
  // State-specific overrides
42
- }, q(v) || r.getState().setInitialStateOptions(v, u[v]);
43
- }), r.getState().setInitialStates(y);
44
- const w = (v, c) => {
42
+ }, q(v) || r.getState().setInitialStateOptions(v, g[v]);
43
+ }), r.getState().setInitialStates(y), r.getState().setCreatedState(y);
44
+ const E = (v, c) => {
45
45
  const [f] = tt(c?.componentId ?? nt());
46
46
  dt({
47
47
  stateKey: v,
48
48
  options: c,
49
- initialOptionsPart: u
49
+ initialOptionsPart: g
50
50
  });
51
- const e = r.getState().cogsStateStore[v] || y[v], S = c?.modifyState ? c.modifyState(e) : e, [x, A] = jt(
51
+ const e = r.getState().cogsStateStore[v] || y[v], S = c?.modifyState ? c.modifyState(e) : e, [T, C] = jt(
52
52
  S,
53
53
  {
54
54
  stateKey: v,
@@ -63,19 +63,19 @@ const zt = (t, i) => {
63
63
  dependencies: c?.dependencies
64
64
  }
65
65
  );
66
- return A;
66
+ return C;
67
67
  };
68
68
  function _(v, c) {
69
- dt({ stateKey: v, options: c, initialOptionsPart: u });
69
+ dt({ stateKey: v, options: c, initialOptionsPart: g });
70
70
  }
71
- return { useCogsState: w, setCogsOptions: _ };
71
+ return { useCogsState: E, setCogsOptions: _ };
72
72
  }, {
73
73
  setUpdaterState: H,
74
74
  setState: D,
75
75
  getInitialOptions: q,
76
76
  getKeyState: ut,
77
- getValidationErrors: ht,
78
- setStateLog: Ct,
77
+ getValidationErrors: Ct,
78
+ setStateLog: ht,
79
79
  updateInitialStateGlobal: rt,
80
80
  addValidationError: kt,
81
81
  removeValidationError: P,
@@ -95,24 +95,24 @@ const zt = (t, i) => {
95
95
  m.localStorage?.key,
96
96
  y
97
97
  );
98
- const u = L(m?.localStorage?.key) ? m.localStorage?.key(t) : m?.localStorage?.key;
99
- if (u && y) {
100
- const w = {
98
+ const g = L(m?.localStorage?.key) ? m.localStorage?.key(t) : m?.localStorage?.key;
99
+ if (g && y) {
100
+ const E = {
101
101
  state: t,
102
102
  lastUpdated: Date.now(),
103
103
  lastSyncedWithServer: r.getState().serverSyncLog[i]?.[0]?.timeStamp,
104
104
  baseServerState: r.getState().serverState[i]
105
- }, _ = `${y}-${i}-${u}`;
106
- window.localStorage.setItem(_, JSON.stringify(w));
105
+ }, _ = `${y}-${i}-${g}`;
106
+ window.localStorage.setItem(_, JSON.stringify(E));
107
107
  }
108
- }, Ot = (t, i, m, y, u, w) => {
108
+ }, Ot = (t, i, m, y, g, E) => {
109
109
  const _ = {
110
110
  initialState: i,
111
111
  updaterState: Y(
112
112
  t,
113
113
  y,
114
- u,
115
- w
114
+ g,
115
+ E
116
116
  ),
117
117
  state: m
118
118
  };
@@ -129,16 +129,16 @@ const zt = (t, i) => {
129
129
  }, Bt = (t, i) => {
130
130
  const m = r.getState().stateComponents.get(t);
131
131
  if (m) {
132
- const y = `${t}////${i}`, u = m.components.get(y);
133
- u && u.forceUpdate();
132
+ const y = `${t}////${i}`, g = m.components.get(y);
133
+ g && g.forceUpdate();
134
134
  }
135
135
  };
136
136
  function jt(t, {
137
137
  stateKey: i,
138
138
  serverSync: m,
139
139
  localStorage: y,
140
- formElements: u,
141
- middleware: w,
140
+ formElements: g,
141
+ middleware: E,
142
142
  reactiveDeps: _,
143
143
  reactiveType: v,
144
144
  componentId: c,
@@ -146,12 +146,12 @@ function jt(t, {
146
146
  syncUpdate: e,
147
147
  dependencies: S
148
148
  } = {}) {
149
- const [x, A] = tt({}), { sessionId: T } = At();
149
+ const [T, C] = tt({}), { sessionId: O } = At();
150
150
  let R = !i;
151
- const [g] = tt(i ?? nt()), s = r.getState().stateLog[g], G = Z(/* @__PURE__ */ new Set()), b = Z(c ?? nt()), C = Z(null);
152
- C.current = q(g), et(() => {
153
- if (e && e.stateKey === g && e.path?.[0]) {
154
- D(g, (o) => ({
151
+ const [u] = tt(i ?? nt()), s = r.getState().stateLog[u], G = Z(/* @__PURE__ */ new Set()), b = Z(c ?? nt()), k = Z(null);
152
+ k.current = q(u), et(() => {
153
+ if (e && e.stateKey === u && e.path?.[0]) {
154
+ D(u, (o) => ({
155
155
  ...o,
156
156
  [e.path[0]]: e.newValue
157
157
  }));
@@ -162,65 +162,67 @@ function jt(t, {
162
162
  });
163
163
  }
164
164
  }, [e]), et(() => {
165
- f && lt(g, {
165
+ f && lt(u, {
166
166
  initialState: f
167
167
  });
168
- const l = C.current;
168
+ const l = k.current;
169
169
  let o = null;
170
170
  const d = L(l?.localStorage?.key) ? l?.localStorage?.key(f) : l?.localStorage?.key;
171
- console.log("newoptions", l), console.log("localkey", d), console.log("initialState", f), d && T && (o = gt(
172
- T + "-" + g + "-" + d
171
+ console.log("newoptions", l), console.log("localkey", d), console.log("initialState", f), d && O && (o = gt(
172
+ O + "-" + u + "-" + d
173
173
  ));
174
- let E = null;
175
- f && (E = f, o && o.lastUpdated > (o.lastSyncedWithServer || 0) && (E = o.state, l?.localStorage?.onChange && l?.localStorage?.onChange(E)), console.log("newState thius is newstate", E), Ot(
176
- g,
174
+ const w = r.getState().iniitialCreatedState[u];
175
+ console.log("createdState - intiual", w, f);
176
+ let V = null;
177
+ f && (V = f, o && o.lastUpdated > (o.lastSyncedWithServer || 0) && (V = o.state, l?.localStorage?.onChange && l?.localStorage?.onChange(V)), console.log("newState thius is newstate", V), Ot(
178
+ u,
177
179
  f,
178
- E,
180
+ V,
179
181
  n,
180
182
  b.current,
181
- T
182
- ), ft(g), A({}));
183
+ O
184
+ ), ft(u), C({}));
183
185
  }, [f, ...S || []]), vt(() => {
184
- R && lt(g, {
186
+ R && lt(u, {
185
187
  serverSync: m,
186
- formElements: u,
188
+ formElements: g,
187
189
  initialState: f,
188
190
  localStorage: y,
189
- middleware: w
191
+ middleware: E
190
192
  });
191
- const l = `${g}////${b.current}`, o = r.getState().stateComponents.get(g) || {
193
+ const l = `${u}////${b.current}`, o = r.getState().stateComponents.get(u) || {
192
194
  components: /* @__PURE__ */ new Map()
193
195
  };
194
196
  return o.components.set(l, {
195
- forceUpdate: () => A({}),
197
+ forceUpdate: () => C({}),
196
198
  paths: /* @__PURE__ */ new Set(),
197
199
  deps: [],
198
200
  depsFunction: _ || void 0,
199
201
  reactiveType: v ?? ["component", "deps"]
200
- }), r.getState().stateComponents.set(g, o), A({}), () => {
201
- const d = `${g}////${b.current}`;
202
- o && (o.components.delete(d), o.components.size === 0 && r.getState().stateComponents.delete(g));
202
+ }), r.getState().stateComponents.set(u, o), C({}), () => {
203
+ const d = `${u}////${b.current}`;
204
+ o && (o.components.delete(d), o.components.size === 0 && r.getState().stateComponents.delete(u));
203
205
  };
204
206
  }, []);
205
- const n = (l, o, d, E) => {
207
+ const n = (l, o, d, w) => {
206
208
  if (Array.isArray(o)) {
207
- const O = `${g}-${o.join(".")}`;
208
- G.current.add(O);
209
+ const V = `${u}-${o.join(".")}`;
210
+ G.current.add(V);
209
211
  }
210
- D(g, (O) => {
211
- const N = L(l) ? l(O) : l, p = `${g}-${o.join(".")}`;
212
+ D(u, (V) => {
213
+ const N = L(l) ? l(V) : l, p = `${u}-${o.join(".")}`;
212
214
  if (p) {
213
215
  let F = !1, I = r.getState().signalDomElements.get(p);
214
216
  if ((!I || I.size === 0) && (d.updateType === "insert" || d.updateType === "cut")) {
215
- const V = o.slice(0, -1), h = U(N, V);
217
+ const A = o.slice(0, -1), h = U(N, A);
216
218
  if (Array.isArray(h)) {
217
219
  F = !0;
218
- const $ = `${g}-${V.join(".")}`;
220
+ const $ = `${u}-${A.join(".")}`;
219
221
  I = r.getState().signalDomElements.get($);
220
222
  }
221
223
  }
222
224
  if (I) {
223
- const V = F ? U(N, o.slice(0, -1)) : U(N, o);
225
+ const A = F ? U(N, o.slice(0, -1)) : U(N, o);
224
226
  I.forEach(({ parentId: h, position: $, effect: W }) => {
225
227
  const j = document.querySelector(
226
228
  `[data-parent-id="${h}"]`
@@ -228,71 +230,71 @@ function jt(t, {
228
230
  if (j) {
229
231
  const it = Array.from(j.childNodes);
230
232
  if (it[$]) {
231
- const yt = W ? new Function("state", `return (${W})(state)`)(V) : V;
233
+ const yt = W ? new Function("state", `return (${W})(state)`)(A) : A;
232
234
  it[$].textContent = String(yt);
233
235
  }
234
236
  }
235
237
  });
236
238
  }
237
239
  }
238
- d.updateType === "update" && (E || C.current?.validationKey) && o && P(
239
- (E || C.current?.validationKey) + "." + o.join(".")
240
+ d.updateType === "update" && (w || k.current?.validationKey) && o && P(
241
+ (w || k.current?.validationKey) + "." + o.join(".")
240
242
  );
241
- const k = o.slice(0, o.length - 1);
242
- d.updateType === "cut" && C.current?.validationKey && P(
243
- C.current?.validationKey + "." + k.join(".")
244
- ), d.updateType === "insert" && C.current?.validationKey && ht(
245
- C.current?.validationKey + "." + k.join(".")
246
- ).filter(([I, V]) => {
243
+ const x = o.slice(0, o.length - 1);
244
+ d.updateType === "cut" && k.current?.validationKey && P(
245
+ k.current?.validationKey + "." + x.join(".")
246
+ ), d.updateType === "insert" && k.current?.validationKey && Ct(
247
+ k.current?.validationKey + "." + x.join(".")
248
+ ).filter(([I, A]) => {
247
249
  let h = I?.split(".").length;
248
- if (I == k.join(".") && h == k.length - 1) {
249
- let $ = I + "." + k;
250
- P(I), kt($, V);
250
+ if (I == x.join(".") && h == x.length - 1) {
251
+ let $ = I + "." + x;
252
+ P(I), kt($, A);
251
253
  }
252
254
  });
253
- const z = U(O, o), St = U(N, o), mt = d.updateType === "update" ? o.join(".") : [...o].slice(0, -1).join("."), ot = r.getState().stateComponents.get(g);
255
+ const z = U(V, o), St = U(N, o), mt = d.updateType === "update" ? o.join(".") : [...o].slice(0, -1).join("."), ot = r.getState().stateComponents.get(u);
254
256
  if (ot)
255
257
  for (const [F, I] of ot.components.entries()) {
256
- let V = !1;
258
+ let A = !1;
257
259
  const h = Array.isArray(I.reactiveType) ? I.reactiveType : [I.reactiveType || "component"];
258
260
  if (!h.includes("none")) {
259
261
  if (h.includes("all")) {
260
262
  I.forceUpdate();
261
263
  continue;
262
264
  }
263
- if (h.includes("component") && I.paths && (I.paths.has(mt) || I.paths.has("")) && (V = !0), !V && h.includes("deps") && I.depsFunction) {
265
+ if (h.includes("component") && I.paths && (I.paths.has(mt) || I.paths.has("")) && (A = !0), !A && h.includes("deps") && I.depsFunction) {
264
266
  const $ = I.depsFunction(N);
265
- typeof $ == "boolean" ? $ && (V = !0) : M(I.deps, $) || (I.deps = $, V = !0);
267
+ typeof $ == "boolean" ? $ && (A = !0) : M(I.deps, $) || (I.deps = $, A = !0);
266
268
  }
267
- V && I.forceUpdate();
269
+ A && I.forceUpdate();
268
270
  }
269
271
  }
270
272
  const at = {
271
273
  timeStamp: Date.now(),
272
- stateKey: g,
274
+ stateKey: u,
273
275
  path: o,
274
276
  updateType: d.updateType,
275
277
  status: "new",
276
278
  oldValue: z,
277
279
  newValue: St
278
280
  };
279
- if (Ct(g, (F) => {
280
- const V = [...F ?? [], at].reduce((h, $) => {
281
+ if (ht(u, (F) => {
282
+ const A = [...F ?? [], at].reduce((h, $) => {
281
283
  const W = `${$.stateKey}:${JSON.stringify($.path)}`, j = h.get(W);
282
284
  return j ? (j.timeStamp = Math.max(j.timeStamp, $.timeStamp), j.newValue = $.newValue, j.oldValue = j.oldValue ?? $.oldValue, j.updateType = $.updateType) : h.set(W, { ...$ }), h;
283
285
  }, /* @__PURE__ */ new Map());
284
- return Array.from(V.values());
286
+ return Array.from(A.values());
285
287
  }), Tt(
286
288
  N,
287
- g,
288
- C.current,
289
- T
290
- ), w && w({
289
+ u,
290
+ k.current,
291
+ O
292
+ ), E && E({
291
293
  updateLog: s,
292
294
  update: at
293
- }), C.current?.serverSync) {
294
- const F = r.getState().serverState[g], I = C.current?.serverSync;
295
- xt(g, {
295
+ }), k.current?.serverSync) {
296
+ const F = r.getState().serverState[u], I = k.current?.serverSync;
297
+ xt(u, {
296
298
  syncKey: typeof I.syncKey == "string" ? I.syncKey : I.syncKey({ state: N }),
297
299
  rollBackState: F,
298
300
  actionTimeStamp: Date.now() + (I.debounce ?? 3e3),
@@ -302,31 +304,31 @@ function jt(t, {
302
304
  return N;
303
305
  });
304
306
  };
305
- r.getState().updaterState[g] || (H(
306
- g,
307
+ r.getState().updaterState[u] || (H(
308
+ u,
307
309
  Y(
308
- g,
310
+ u,
309
311
  n,
310
312
  b.current,
311
- T
313
+ O
312
314
  )
313
- ), r.getState().cogsStateStore[g] || D(g, t), r.getState().initialStateGlobal[g] || rt(g, t));
315
+ ), r.getState().cogsStateStore[u] || D(u, t), r.getState().initialStateGlobal[u] || rt(u, t));
314
316
  const a = It(() => Y(
315
- g,
317
+ u,
316
318
  n,
317
319
  b.current,
318
- T
319
- ), [g]);
320
- return [ut(g), a];
320
+ O
321
+ ), [u]);
322
+ return [ut(u), a];
321
323
  }
322
324
  function Y(t, i, m, y) {
323
- const u = /* @__PURE__ */ new Map();
324
- let w = 0;
325
+ const g = /* @__PURE__ */ new Map();
326
+ let E = 0;
325
327
  const _ = (f) => {
326
328
  const e = f.join(".");
327
- for (const [S] of u)
328
- (S === e || S.startsWith(e + ".")) && u.delete(S);
329
- w++;
329
+ for (const [S] of g)
330
+ (S === e || S.startsWith(e + ".")) && g.delete(S);
331
+ E++;
330
332
  }, v = {
331
333
  removeValidation: (f) => {
332
334
  f?.validationKey && P(f.validationKey);
@@ -335,16 +337,16 @@ function Y(t, i, m, y) {
335
337
  const e = r.getState().getInitialOptions(t)?.validation;
336
338
  e?.key && P(e?.key), f?.validationKey && P(f.validationKey);
337
339
  const S = r.getState().initialStateGlobal[t];
338
- r.getState().clearSelectedIndexesForState(t), u.clear(), w++;
339
- const x = c(S, []), A = q(t), T = L(A?.localStorage?.key) ? A?.localStorage?.key(S) : A?.localStorage?.key, R = `${y}-${t}-${T}`;
340
- R && localStorage.removeItem(R), H(t, x), D(t, S);
341
- const g = r.getState().stateComponents.get(t);
342
- return g && g.components.forEach((s) => {
340
+ r.getState().clearSelectedIndexesForState(t), g.clear(), E++;
341
+ const T = c(S, []), C = q(t), O = L(C?.localStorage?.key) ? C?.localStorage?.key(S) : C?.localStorage?.key, R = `${y}-${t}-${O}`;
342
+ R && localStorage.removeItem(R), H(t, T), D(t, S);
343
+ const u = r.getState().stateComponents.get(t);
344
+ return u && u.components.forEach((s) => {
343
345
  s.forceUpdate();
344
346
  }), S;
345
347
  },
346
348
  updateInitialState: (f) => {
347
- u.clear(), w++;
349
+ g.clear(), E++;
348
350
  const e = Y(
349
351
  t,
350
352
  i,
@@ -354,8 +356,8 @@ function Y(t, i, m, y) {
354
356
  return Et(() => {
355
357
  rt(t, f), H(t, e), D(t, f);
356
358
  const S = r.getState().stateComponents.get(t);
357
- S && S.components.forEach((x) => {
358
- x.forceUpdate();
359
+ S && S.components.forEach((T) => {
360
+ T.forceUpdate();
359
361
  });
360
362
  }), {
361
363
  fetchId: (S) => e.get()[S]
@@ -370,21 +372,21 @@ function Y(t, i, m, y) {
370
372
  }
371
373
  };
372
374
  function c(f, e = [], S) {
373
- const x = e.map(String).join(".");
374
- u.get(x);
375
- const A = function() {
375
+ const T = e.map(String).join(".");
376
+ g.get(T);
377
+ const C = function() {
376
378
  return r().getNestedState(t, e);
377
379
  };
378
- Object.keys(v).forEach((g) => {
379
- A[g] = v[g];
380
+ Object.keys(v).forEach((u) => {
381
+ C[u] = v[u];
380
382
  });
381
- const T = {
382
- apply(g, s, G) {
383
+ const O = {
384
+ apply(u, s, G) {
383
385
  return console.log(
384
386
  `PROXY APPLY TRAP HIT: stateKey=${t}, path=${e.join(".")}`
385
387
  ), console.trace("Apply trap stack trace"), r().getNestedState(t, e);
386
388
  },
387
- get(g, s) {
389
+ get(u, s) {
388
390
  if (s !== "then" && !s.startsWith("$") && s !== "stateMapNoRender") {
389
391
  const n = e.join("."), a = `${t}////${m}`, l = r.getState().stateComponents.get(t);
390
392
  if (l) {
@@ -431,11 +433,11 @@ function Y(t, i, m, y) {
431
433
  return () => r.getState().getSelectedIndex(t, e.join(".")) ?? -1;
432
434
  if (s === "stateSort")
433
435
  return (n) => {
434
- const o = [...r.getState().getNestedState(t, e).map((d, E) => ({
436
+ const o = [...r.getState().getNestedState(t, e).map((d, w) => ({
435
437
  ...d,
436
- __origIndex: E.toString()
438
+ __origIndex: w.toString()
437
439
  }))].sort(n);
438
- return u.clear(), w++, c(o, e, {
440
+ return g.clear(), E++, c(o, e, {
439
441
  filtered: [...S?.filtered || [], e],
440
442
  validIndices: o.map(
441
443
  (d) => parseInt(d.__origIndex)
@@ -447,15 +449,15 @@ function Y(t, i, m, y) {
447
449
  const a = S?.filtered?.some(
448
450
  (o) => o.join(".") === e.join(".")
449
451
  ), l = a ? f : r.getState().getNestedState(t, e);
450
- return s !== "stateMapNoRender" && (u.clear(), w++), l.map((o, d) => {
451
- const E = a && o.__origIndex ? o.__origIndex : d, O = c(
452
+ return s !== "stateMapNoRender" && (g.clear(), E++), l.map((o, d) => {
453
+ const w = a && o.__origIndex ? o.__origIndex : d, V = c(
452
454
  o,
453
- [...e, E.toString()],
455
+ [...e, w.toString()],
454
456
  S
455
457
  );
456
458
  return n(
457
459
  o,
458
- O,
460
+ V,
459
461
  d,
460
462
  f,
461
463
  c(f, e, S)
@@ -477,9 +479,9 @@ function Y(t, i, m, y) {
477
479
  const l = S?.filtered?.some(
478
480
  (d) => d.join(".") === e.join(".")
479
481
  ) ? f : r.getState().getNestedState(t, e);
480
- u.clear(), w++;
482
+ g.clear(), E++;
481
483
  const o = l.flatMap(
482
- (d, E) => d[n] ?? []
484
+ (d, w) => d[n] ?? []
483
485
  );
484
486
  return c(
485
487
  o,
@@ -490,11 +492,11 @@ function Y(t, i, m, y) {
490
492
  if (s === "findWith")
491
493
  return (n, a) => {
492
494
  const l = f.findIndex(
493
- (E) => E[n] === a
495
+ (w) => w[n] === a
494
496
  );
495
497
  if (l === -1) return;
496
498
  const o = f[l], d = [...e, l.toString()];
497
- return u.clear(), w++, u.clear(), w++, c(o, d);
499
+ return g.clear(), E++, g.clear(), E++, c(o, d);
498
500
  };
499
501
  if (s === "index")
500
502
  return (n) => {
@@ -509,21 +511,21 @@ function Y(t, i, m, y) {
509
511
  if (s === "uniqueInsert")
510
512
  return (n, a, l) => {
511
513
  const o = r.getState().getNestedState(t, e), d = L(n) ? n(o) : n;
512
- let E = null;
514
+ let w = null;
513
515
  if (!o.some((N) => {
514
516
  if (a) {
515
- const k = a.every(
517
+ const x = a.every(
516
518
  (z) => M(N[z], d[z])
517
519
  );
518
- return k && (E = N), k;
520
+ return x && (w = N), x;
519
521
  }
520
522
  const p = M(N, d);
521
- return p && (E = N), p;
523
+ return p && (w = N), p;
522
524
  }))
523
525
  _(e), Q(i, d, e, t);
524
- else if (l && E) {
525
- const N = l(E), p = o.map(
526
- (k) => M(k, E) ? N : k
526
+ else if (l && w) {
527
+ const N = l(w), p = o.map(
528
+ (x) => M(x, w) ? N : x
527
529
  );
528
530
  _(e), B(i, p, e);
529
531
  }
@@ -544,13 +546,13 @@ function Y(t, i, m, y) {
544
546
  };
545
547
  if (s === "stateFilter")
546
548
  return (n) => {
547
- const a = f.map((d, E) => ({
549
+ const a = f.map((d, w) => ({
548
550
  ...d,
549
- __origIndex: E.toString()
551
+ __origIndex: w.toString()
550
552
  })), l = [], o = [];
551
553
  for (let d = 0; d < a.length; d++)
552
554
  n(a[d], d) && (l.push(d), o.push(a[d]));
553
- return u.clear(), w++, c(o, e, {
555
+ return g.clear(), E++, c(o, e, {
554
556
  filtered: [...S?.filtered || [], e],
555
557
  validIndices: l
556
558
  // Always pass validIndices, even if empty
@@ -616,13 +618,13 @@ function Y(t, i, m, y) {
616
618
  const l = r.getState().cogsStateStore[t];
617
619
  try {
618
620
  const o = r.getState().getValidationErrors(n.key);
619
- o && o.length > 0 && o.forEach(([E]) => {
620
- E && E.startsWith(n.key) && P(E);
621
+ o && o.length > 0 && o.forEach(([w]) => {
622
+ w && w.startsWith(n.key) && P(w);
621
623
  });
622
624
  const d = n.zodSchema.safeParse(l);
623
- return d.success ? !0 : (d.error.errors.forEach((O) => {
624
- const N = O.path, p = O.message, k = [n.key, ...N].join(".");
625
- a(k, p);
625
+ return d.success ? !0 : (d.error.errors.forEach((V) => {
626
+ const N = V.path, p = V.message, x = [n.key, ...N].join(".");
627
+ a(x, p);
626
628
  }), ft(t), !1);
627
629
  } catch (o) {
628
630
  return console.error("Zod schema validation failed", o), !1;
@@ -690,13 +692,13 @@ function Y(t, i, m, y) {
690
692
  formOpts: a
691
693
  }
692
694
  );
693
- const b = [...e, s], C = r.getState().getNestedState(t, b);
694
- return c(C, b, S);
695
+ const b = [...e, s], k = r.getState().getNestedState(t, b);
696
+ return c(k, b, S);
695
697
  }
696
- }, R = new Proxy(A, T);
697
- return u.set(x, {
698
+ }, R = new Proxy(C, O);
699
+ return g.set(T, {
698
700
  proxy: R,
699
- stateVersion: w
701
+ stateVersion: E
700
702
  }), R;
701
703
  }
702
704
  return c(
@@ -715,7 +717,7 @@ function pt({
715
717
  m,
716
718
  t._path
717
719
  ).stateMapNoRender(
718
- (u, w, _, v, c) => t._mapFn(u, w, _, v, c)
720
+ (g, E, _, v, c) => t._mapFn(g, E, _, v, c)
719
721
  ) : null;
720
722
  }
721
723
  function bt({
@@ -725,9 +727,9 @@ function bt({
725
727
  return et(() => {
726
728
  const y = i.current;
727
729
  if (!y || !y.parentElement) return;
728
- const u = y.parentElement, _ = Array.from(u.childNodes).indexOf(y);
729
- let v = u.getAttribute("data-parent-id");
730
- v || (v = `parent-${crypto.randomUUID()}`, u.setAttribute("data-parent-id", v));
730
+ const g = y.parentElement, _ = Array.from(g.childNodes).indexOf(y);
731
+ let v = g.getAttribute("data-parent-id");
732
+ v || (v = `parent-${crypto.randomUUID()}`, g.setAttribute("data-parent-id", v));
731
733
  const f = {
732
734
  instanceId: `instance-${crypto.randomUUID()}`,
733
735
  parentId: v,
@@ -743,14 +745,14 @@ function bt({
743
745
  "state",
744
746
  `return (${t._effect})(state)`
745
747
  )(e);
746
- } catch (A) {
747
- console.error("Error evaluating effect function during mount:", A), S = e;
748
+ } catch (C) {
749
+ console.error("Error evaluating effect function during mount:", C), S = e;
748
750
  }
749
751
  else
750
752
  S = e;
751
753
  S !== null && typeof S == "object" && (S = JSON.stringify(S));
752
- const x = document.createTextNode(String(S));
753
- y.replaceWith(x);
754
+ const T = document.createTextNode(String(S));
755
+ y.replaceWith(T);
754
756
  }, [t._stateKey, t._path.join("."), t._effect]), X("span", {
755
757
  ref: i,
756
758
  style: { display: "none" },