cogsbox-state 0.5.114 → 0.5.116

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.
@@ -19,12 +19,12 @@ function dt({
19
19
  options: i,
20
20
  initialOptionsPart: m
21
21
  }) {
22
- const y = q(t) || {}, u = m[t] || {}, w = r.getState().setInitialStateOptions, E = { ...u, ...y };
22
+ const y = q(t) || {}, u = m[t] || {}, w = r.getState().setInitialStateOptions, _ = { ...u, ...y };
23
23
  let v = !1;
24
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);
25
+ for (const c in i)
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, _);
28
28
  }
29
29
  function qt(t, { formElements: i, validation: m }) {
30
30
  return { initialState: t, formElements: i, validation: m };
@@ -40,47 +40,47 @@ const zt = (t, i) => {
40
40
  ...u[v].formElements || {}
41
41
  // State-specific overrides
42
42
  }, q(v) || r.getState().setInitialStateOptions(v, u[v]);
43
- }), r.getState().setInitialStates(y);
44
- const w = (v, l) => {
45
- const [f] = tt(l?.componentId ?? nt());
43
+ }), r.getState().setInitialStates(y), r.getState().setCreatedState(y);
44
+ const w = (v, c) => {
45
+ const [f] = tt(c?.componentId ?? nt());
46
46
  dt({
47
47
  stateKey: v,
48
- options: l,
48
+ options: c,
49
49
  initialOptionsPart: u
50
50
  });
51
- const e = r.getState().cogsStateStore[v] || y[v], S = l?.modifyState ? l.modifyState(e) : e, [x, A] = Ot(
51
+ const e = r.getState().cogsStateStore[v] || y[v], S = c?.modifyState ? c.modifyState(e) : e, [x, A] = jt(
52
52
  S,
53
53
  {
54
54
  stateKey: v,
55
- syncUpdate: l?.syncUpdate,
55
+ syncUpdate: c?.syncUpdate,
56
56
  componentId: f,
57
- localStorage: l?.localStorage,
58
- middleware: l?.middleware,
59
- enabledSync: l?.enabledSync,
60
- reactiveType: l?.reactiveType,
61
- reactiveDeps: l?.reactiveDeps,
62
- initialState: l?.initialState,
63
- dependencies: l?.dependencies
57
+ localStorage: c?.localStorage,
58
+ middleware: c?.middleware,
59
+ enabledSync: c?.enabledSync,
60
+ reactiveType: c?.reactiveType,
61
+ reactiveDeps: c?.reactiveDeps,
62
+ initialState: c?.initialState,
63
+ dependencies: c?.dependencies
64
64
  }
65
65
  );
66
66
  return A;
67
67
  };
68
- function E(v, l) {
69
- dt({ stateKey: v, options: l, initialOptionsPart: u });
68
+ function _(v, c) {
69
+ dt({ stateKey: v, options: c, initialOptionsPart: u });
70
70
  }
71
- return { useCogsState: w, setCogsOptions: E };
71
+ return { useCogsState: w, setCogsOptions: _ };
72
72
  }, {
73
73
  setUpdaterState: H,
74
74
  setState: D,
75
75
  getInitialOptions: q,
76
- getKeyState: ut,
77
- getValidationErrors: ht,
78
- setStateLog: Ct,
76
+ getKeyState: gt,
77
+ getValidationErrors: Ct,
78
+ setStateLog: ht,
79
79
  updateInitialStateGlobal: rt,
80
80
  addValidationError: kt,
81
81
  removeValidationError: P,
82
- setServerSyncActions: pt
83
- } = r.getState(), gt = (t) => {
82
+ setServerSyncActions: xt
83
+ } = r.getState(), ut = (t) => {
84
84
  if (!t) return null;
85
85
  try {
86
86
  const i = window.localStorage.getItem(t);
@@ -88,7 +88,7 @@ const zt = (t, i) => {
88
88
  } catch (i) {
89
89
  return console.error("Error loading from localStorage:", i), null;
90
90
  }
91
- }, xt = (t, i, m, y) => {
91
+ }, Tt = (t, i, m, y) => {
92
92
  m?.log && console.log(
93
93
  "saving to localstorage",
94
94
  i,
@@ -102,11 +102,11 @@ const zt = (t, i) => {
102
102
  lastUpdated: Date.now(),
103
103
  lastSyncedWithServer: r.getState().serverSyncLog[i]?.[0]?.timeStamp,
104
104
  baseServerState: r.getState().serverState[i]
105
- }, E = `${y}-${i}-${u}`;
106
- window.localStorage.setItem(E, JSON.stringify(w));
105
+ }, _ = `${y}-${i}-${u}`;
106
+ window.localStorage.setItem(_, JSON.stringify(w));
107
107
  }
108
- }, Tt = (t, i, m, y, u, w) => {
109
- const E = {
108
+ }, Ot = (t, i, m, y, u, w) => {
109
+ const _ = {
110
110
  initialState: i,
111
111
  updaterState: Y(
112
112
  t,
@@ -116,7 +116,7 @@ const zt = (t, i) => {
116
116
  ),
117
117
  state: m
118
118
  };
119
- rt(t, E.initialState), H(t, E.updaterState), D(t, E.state);
119
+ rt(t, _.initialState), H(t, _.updaterState), D(t, _.state);
120
120
  }, ft = (t) => {
121
121
  const i = r.getState().stateComponents.get(t);
122
122
  if (!i) return;
@@ -133,55 +133,53 @@ const zt = (t, i) => {
133
133
  u && u.forceUpdate();
134
134
  }
135
135
  };
136
- function Ot(t, {
136
+ function jt(t, {
137
137
  stateKey: i,
138
138
  serverSync: m,
139
139
  localStorage: y,
140
140
  formElements: u,
141
141
  middleware: w,
142
- reactiveDeps: E,
142
+ reactiveDeps: _,
143
143
  reactiveType: v,
144
- componentId: l,
144
+ componentId: c,
145
145
  initialState: f,
146
146
  syncUpdate: e,
147
147
  dependencies: S
148
148
  } = {}) {
149
149
  const [x, A] = tt({}), { sessionId: T } = At();
150
150
  let R = !i;
151
- const [g] = tt(i ?? nt()), s = r.getState().stateLog[g], G = Z(/* @__PURE__ */ new Set()), b = Z(l ?? nt()), C = Z(null);
152
- C.current = q(g), et(() => {
151
+ const [g] = tt(i ?? nt()), s = r.getState().stateLog[g], G = Z(/* @__PURE__ */ new Set()), b = Z(c ?? nt()), h = Z(null);
152
+ h.current = q(g), et(() => {
153
153
  if (e && e.stateKey === g && e.path?.[0]) {
154
154
  D(g, (o) => ({
155
155
  ...o,
156
156
  [e.path[0]]: e.newValue
157
157
  }));
158
- const c = `${e.stateKey}:${e.path.join(".")}`;
159
- r.getState().setSyncInfo(c, {
158
+ const l = `${e.stateKey}:${e.path.join(".")}`;
159
+ r.getState().setSyncInfo(l, {
160
160
  timeStamp: e.timeStamp,
161
161
  userId: e.userId
162
162
  });
163
163
  }
164
164
  }, [e]), et(() => {
165
- if (!f)
166
- return;
167
- lt(g, {
165
+ f && lt(g, {
168
166
  initialState: f
169
167
  });
170
- const c = C.current;
168
+ const l = h.current;
171
169
  let o = null;
172
- const d = L(c?.localStorage?.key) ? c?.localStorage?.key(f) : c?.localStorage?.key;
173
- console.log("newoptions", c), console.log("localkey", d), console.log("initialState", f), d && T && (o = gt(
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 = ut(
174
172
  T + "-" + g + "-" + d
175
173
  ));
176
- let I = null, k = !1;
177
- o && o.lastUpdated > (o.lastSyncedWithServer || 0) && (I = o.state, k = !0), f && (I = f), I && (console.log("newState thius is newstate", I), Tt(
174
+ let E = f ?? r.getState().iniitialCreatedState[g];
175
+ o && o.lastUpdated > (o.lastSyncedWithServer || 0) && (E = o.state, l?.localStorage?.onChange && l?.localStorage?.onChange(E)), console.log("newState thius is newstate", E), Ot(
178
176
  g,
179
177
  f,
180
- I,
178
+ E,
181
179
  n,
182
180
  b.current,
183
181
  T
184
- ), k && c?.localStorage?.onChange && c?.localStorage?.onChange(I), ft(g), A({}));
182
+ ), ft(g), A({});
185
183
  }, [f, ...S || []]), vt(() => {
186
184
  R && lt(g, {
187
185
  serverSync: m,
@@ -190,45 +188,45 @@ function Ot(t, {
190
188
  localStorage: y,
191
189
  middleware: w
192
190
  });
193
- const c = `${g}////${b.current}`, o = r.getState().stateComponents.get(g) || {
191
+ const l = `${g}////${b.current}`, o = r.getState().stateComponents.get(g) || {
194
192
  components: /* @__PURE__ */ new Map()
195
193
  };
196
- return o.components.set(c, {
194
+ return o.components.set(l, {
197
195
  forceUpdate: () => A({}),
198
196
  paths: /* @__PURE__ */ new Set(),
199
197
  deps: [],
200
- depsFunction: E || void 0,
198
+ depsFunction: _ || void 0,
201
199
  reactiveType: v ?? ["component", "deps"]
202
200
  }), r.getState().stateComponents.set(g, o), A({}), () => {
203
201
  const d = `${g}////${b.current}`;
204
202
  o && (o.components.delete(d), o.components.size === 0 && r.getState().stateComponents.delete(g));
205
203
  };
206
204
  }, []);
207
- const n = (c, o, d, I) => {
205
+ const n = (l, o, d, E) => {
208
206
  if (Array.isArray(o)) {
209
- const k = `${g}-${o.join(".")}`;
210
- G.current.add(k);
207
+ const O = `${g}-${o.join(".")}`;
208
+ G.current.add(O);
211
209
  }
212
- D(g, (k) => {
213
- const N = L(c) ? c(k) : c, j = `${g}-${o.join(".")}`;
214
- if (j) {
215
- let F = !1, _ = r.getState().signalDomElements.get(j);
216
- if ((!_ || _.size === 0) && (d.updateType === "insert" || d.updateType === "cut")) {
217
- const V = o.slice(0, -1), h = U(N, V);
218
- if (Array.isArray(h)) {
210
+ D(g, (O) => {
211
+ const N = L(l) ? l(O) : l, p = `${g}-${o.join(".")}`;
212
+ if (p) {
213
+ let F = !1, I = r.getState().signalDomElements.get(p);
214
+ if ((!I || I.size === 0) && (d.updateType === "insert" || d.updateType === "cut")) {
215
+ const V = o.slice(0, -1), C = U(N, V);
216
+ if (Array.isArray(C)) {
219
217
  F = !0;
220
218
  const $ = `${g}-${V.join(".")}`;
221
- _ = r.getState().signalDomElements.get($);
219
+ I = r.getState().signalDomElements.get($);
222
220
  }
223
221
  }
224
- if (_) {
222
+ if (I) {
225
223
  const V = F ? U(N, o.slice(0, -1)) : U(N, o);
226
- _.forEach(({ parentId: h, position: $, effect: W }) => {
227
- const O = document.querySelector(
228
- `[data-parent-id="${h}"]`
224
+ I.forEach(({ parentId: C, position: $, effect: W }) => {
225
+ const j = document.querySelector(
226
+ `[data-parent-id="${C}"]`
229
227
  );
230
- if (O) {
231
- const it = Array.from(O.childNodes);
228
+ if (j) {
229
+ const it = Array.from(j.childNodes);
232
230
  if (it[$]) {
233
231
  const yt = W ? new Function("state", `return (${W})(state)`)(V) : V;
234
232
  it[$].textContent = String(yt);
@@ -237,36 +235,36 @@ function Ot(t, {
237
235
  });
238
236
  }
239
237
  }
240
- d.updateType === "update" && (I || C.current?.validationKey) && o && P(
241
- (I || C.current?.validationKey) + "." + o.join(".")
238
+ d.updateType === "update" && (E || h.current?.validationKey) && o && P(
239
+ (E || h.current?.validationKey) + "." + o.join(".")
242
240
  );
243
- const p = o.slice(0, o.length - 1);
244
- d.updateType === "cut" && C.current?.validationKey && P(
245
- C.current?.validationKey + "." + p.join(".")
246
- ), d.updateType === "insert" && C.current?.validationKey && ht(
247
- C.current?.validationKey + "." + p.join(".")
248
- ).filter(([_, V]) => {
249
- let h = _?.split(".").length;
250
- if (_ == p.join(".") && h == p.length - 1) {
251
- let $ = _ + "." + p;
252
- P(_), kt($, V);
241
+ const k = o.slice(0, o.length - 1);
242
+ d.updateType === "cut" && h.current?.validationKey && P(
243
+ h.current?.validationKey + "." + k.join(".")
244
+ ), d.updateType === "insert" && h.current?.validationKey && Ct(
245
+ h.current?.validationKey + "." + k.join(".")
246
+ ).filter(([I, V]) => {
247
+ let C = I?.split(".").length;
248
+ if (I == k.join(".") && C == k.length - 1) {
249
+ let $ = I + "." + k;
250
+ P(I), kt($, V);
253
251
  }
254
252
  });
255
- const z = U(k, o), St = U(N, o), mt = d.updateType === "update" ? o.join(".") : [...o].slice(0, -1).join("."), ot = r.getState().stateComponents.get(g);
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);
256
254
  if (ot)
257
- for (const [F, _] of ot.components.entries()) {
255
+ for (const [F, I] of ot.components.entries()) {
258
256
  let V = !1;
259
- const h = Array.isArray(_.reactiveType) ? _.reactiveType : [_.reactiveType || "component"];
260
- if (!h.includes("none")) {
261
- if (h.includes("all")) {
262
- _.forceUpdate();
257
+ const C = Array.isArray(I.reactiveType) ? I.reactiveType : [I.reactiveType || "component"];
258
+ if (!C.includes("none")) {
259
+ if (C.includes("all")) {
260
+ I.forceUpdate();
263
261
  continue;
264
262
  }
265
- if (h.includes("component") && _.paths && (_.paths.has(mt) || _.paths.has("")) && (V = !0), !V && h.includes("deps") && _.depsFunction) {
266
- const $ = _.depsFunction(N);
267
- typeof $ == "boolean" ? $ && (V = !0) : M(_.deps, $) || (_.deps = $, V = !0);
263
+ if (C.includes("component") && I.paths && (I.paths.has(mt) || I.paths.has("")) && (V = !0), !V && C.includes("deps") && I.depsFunction) {
264
+ const $ = I.depsFunction(N);
265
+ typeof $ == "boolean" ? $ && (V = !0) : M(I.deps, $) || (I.deps = $, V = !0);
268
266
  }
269
- V && _.forceUpdate();
267
+ V && I.forceUpdate();
270
268
  }
271
269
  }
272
270
  const at = {
@@ -278,26 +276,26 @@ function Ot(t, {
278
276
  oldValue: z,
279
277
  newValue: St
280
278
  };
281
- if (Ct(g, (F) => {
282
- const V = [...F ?? [], at].reduce((h, $) => {
283
- const W = `${$.stateKey}:${JSON.stringify($.path)}`, O = h.get(W);
284
- return O ? (O.timeStamp = Math.max(O.timeStamp, $.timeStamp), O.newValue = $.newValue, O.oldValue = O.oldValue ?? $.oldValue, O.updateType = $.updateType) : h.set(W, { ...$ }), h;
279
+ if (ht(g, (F) => {
280
+ const V = [...F ?? [], at].reduce((C, $) => {
281
+ const W = `${$.stateKey}:${JSON.stringify($.path)}`, j = C.get(W);
282
+ return j ? (j.timeStamp = Math.max(j.timeStamp, $.timeStamp), j.newValue = $.newValue, j.oldValue = j.oldValue ?? $.oldValue, j.updateType = $.updateType) : C.set(W, { ...$ }), C;
285
283
  }, /* @__PURE__ */ new Map());
286
284
  return Array.from(V.values());
287
- }), xt(
285
+ }), Tt(
288
286
  N,
289
287
  g,
290
- C.current,
288
+ h.current,
291
289
  T
292
290
  ), w && w({
293
291
  updateLog: s,
294
292
  update: at
295
- }), C.current?.serverSync) {
296
- const F = r.getState().serverState[g], _ = C.current?.serverSync;
297
- pt(g, {
298
- syncKey: typeof _.syncKey == "string" ? _.syncKey : _.syncKey({ state: N }),
293
+ }), h.current?.serverSync) {
294
+ const F = r.getState().serverState[g], I = h.current?.serverSync;
295
+ xt(g, {
296
+ syncKey: typeof I.syncKey == "string" ? I.syncKey : I.syncKey({ state: N }),
299
297
  rollBackState: F,
300
- actionTimeStamp: Date.now() + (_.debounce ?? 3e3),
298
+ actionTimeStamp: Date.now() + (I.debounce ?? 3e3),
301
299
  status: "waiting"
302
300
  });
303
301
  }
@@ -319,12 +317,12 @@ function Ot(t, {
319
317
  b.current,
320
318
  T
321
319
  ), [g]);
322
- return [ut(g), a];
320
+ return [gt(g), a];
323
321
  }
324
322
  function Y(t, i, m, y) {
325
323
  const u = /* @__PURE__ */ new Map();
326
324
  let w = 0;
327
- const E = (f) => {
325
+ const _ = (f) => {
328
326
  const e = f.join(".");
329
327
  for (const [S] of u)
330
328
  (S === e || S.startsWith(e + ".")) && u.delete(S);
@@ -338,7 +336,7 @@ function Y(t, i, m, y) {
338
336
  e?.key && P(e?.key), f?.validationKey && P(f.validationKey);
339
337
  const S = r.getState().initialStateGlobal[t];
340
338
  r.getState().clearSelectedIndexesForState(t), u.clear(), w++;
341
- const x = l(S, []), A = q(t), T = L(A?.localStorage?.key) ? A?.localStorage?.key(S) : A?.localStorage?.key, R = `${y}-${t}-${T}`;
339
+ const x = c(S, []), A = q(t), T = L(A?.localStorage?.key) ? A?.localStorage?.key(S) : A?.localStorage?.key, R = `${y}-${t}-${T}`;
342
340
  R && localStorage.removeItem(R), H(t, x), D(t, S);
343
341
  const g = r.getState().stateComponents.get(t);
344
342
  return g && g.components.forEach((s) => {
@@ -368,10 +366,10 @@ function Y(t, i, m, y) {
368
366
  _isLoading: r.getState().isLoadingGlobal[t],
369
367
  _isServerSynced: () => {
370
368
  const f = r.getState().serverState[t];
371
- return !!(f && M(f, ut(t)));
369
+ return !!(f && M(f, gt(t)));
372
370
  }
373
371
  };
374
- function l(f, e = [], S) {
372
+ function c(f, e = [], S) {
375
373
  const x = e.map(String).join(".");
376
374
  u.get(x);
377
375
  const A = function() {
@@ -388,27 +386,27 @@ function Y(t, i, m, y) {
388
386
  },
389
387
  get(g, s) {
390
388
  if (s !== "then" && !s.startsWith("$") && s !== "stateMapNoRender") {
391
- const n = e.join("."), a = `${t}////${m}`, c = r.getState().stateComponents.get(t);
392
- if (c) {
393
- const o = c.components.get(a);
389
+ const n = e.join("."), a = `${t}////${m}`, l = r.getState().stateComponents.get(t);
390
+ if (l) {
391
+ const o = l.components.get(a);
394
392
  o && (e.length > 0 || s === "get") && o.paths.add(n);
395
393
  }
396
394
  }
397
395
  if (s === "_status") {
398
- const n = r.getState().getNestedState(t, e), a = r.getState().initialStateGlobal[t], c = U(a, e);
399
- return M(n, c) ? "fresh" : "stale";
396
+ const n = r.getState().getNestedState(t, e), a = r.getState().initialStateGlobal[t], l = U(a, e);
397
+ return M(n, l) ? "fresh" : "stale";
400
398
  }
401
399
  if (s === "getStatus")
402
400
  return function() {
403
401
  const n = r().getNestedState(
404
402
  t,
405
403
  e
406
- ), a = r.getState().initialStateGlobal[t], c = U(a, e);
407
- return M(n, c) ? "fresh" : "stale";
404
+ ), a = r.getState().initialStateGlobal[t], l = U(a, e);
405
+ return M(n, l) ? "fresh" : "stale";
408
406
  };
409
407
  if (s === "removeStorage")
410
408
  return () => {
411
- 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}`;
409
+ const n = r.getState().initialStateGlobal[t], a = q(t), l = L(a?.localStorage?.key) ? a?.localStorage?.key(n) : a?.localStorage?.key, o = `${y}-${t}-${l}`;
412
410
  console.log("removing storage", o), o && localStorage.removeItem(o);
413
411
  };
414
412
  if (s === "showValidationErrors")
@@ -423,7 +421,7 @@ function Y(t, i, m, y) {
423
421
  return () => {
424
422
  const n = r.getState().getSelectedIndex(t, e.join("."));
425
423
  if (n !== void 0)
426
- return l(
424
+ return c(
427
425
  f[n],
428
426
  [...e, n.toString()],
429
427
  S
@@ -433,11 +431,11 @@ function Y(t, i, m, y) {
433
431
  return () => r.getState().getSelectedIndex(t, e.join(".")) ?? -1;
434
432
  if (s === "stateSort")
435
433
  return (n) => {
436
- const o = [...r.getState().getNestedState(t, e).map((d, I) => ({
434
+ const o = [...r.getState().getNestedState(t, e).map((d, E) => ({
437
435
  ...d,
438
- __origIndex: I.toString()
436
+ __origIndex: E.toString()
439
437
  }))].sort(n);
440
- return u.clear(), w++, l(o, e, {
438
+ return u.clear(), w++, c(o, e, {
441
439
  filtered: [...S?.filtered || [], e],
442
440
  validIndices: o.map(
443
441
  (d) => parseInt(d.__origIndex)
@@ -448,42 +446,42 @@ function Y(t, i, m, y) {
448
446
  return (n) => {
449
447
  const a = S?.filtered?.some(
450
448
  (o) => o.join(".") === e.join(".")
451
- ), c = a ? f : r.getState().getNestedState(t, e);
452
- return s !== "stateMapNoRender" && (u.clear(), w++), c.map((o, d) => {
453
- const I = a && o.__origIndex ? o.__origIndex : d, k = l(
449
+ ), 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(
454
452
  o,
455
- [...e, I.toString()],
453
+ [...e, E.toString()],
456
454
  S
457
455
  );
458
456
  return n(
459
457
  o,
460
- k,
458
+ O,
461
459
  d,
462
460
  f,
463
- l(f, e, S)
461
+ c(f, e, S)
464
462
  );
465
463
  });
466
464
  };
467
465
  if (s === "$stateMap")
468
- return (n) => X(jt, {
466
+ return (n) => X(pt, {
469
467
  proxy: {
470
468
  _stateKey: t,
471
469
  _path: e,
472
470
  _mapFn: n
473
471
  // Pass the actual function, not string
474
472
  },
475
- rebuildStateShape: l
473
+ rebuildStateShape: c
476
474
  });
477
475
  if (s === "stateFlattenOn")
478
476
  return (n) => {
479
- const c = S?.filtered?.some(
477
+ const l = S?.filtered?.some(
480
478
  (d) => d.join(".") === e.join(".")
481
479
  ) ? f : r.getState().getNestedState(t, e);
482
480
  u.clear(), w++;
483
- const o = c.flatMap(
484
- (d, I) => d[n] ?? []
481
+ const o = l.flatMap(
482
+ (d, E) => d[n] ?? []
485
483
  );
486
- return l(
484
+ return c(
487
485
  o,
488
486
  [...e, "[*]", n],
489
487
  S
@@ -491,48 +489,48 @@ function Y(t, i, m, y) {
491
489
  };
492
490
  if (s === "findWith")
493
491
  return (n, a) => {
494
- const c = f.findIndex(
495
- (I) => I[n] === a
492
+ const l = f.findIndex(
493
+ (E) => E[n] === a
496
494
  );
497
- if (c === -1) return;
498
- const o = f[c], d = [...e, c.toString()];
499
- return u.clear(), w++, u.clear(), w++, l(o, d);
495
+ if (l === -1) return;
496
+ const o = f[l], d = [...e, l.toString()];
497
+ return u.clear(), w++, u.clear(), w++, c(o, d);
500
498
  };
501
499
  if (s === "index")
502
500
  return (n) => {
503
501
  const a = f[n];
504
- return l(a, [...e, n.toString()]);
502
+ return c(a, [...e, n.toString()]);
505
503
  };
506
504
  if (s === "insert")
507
- return (n) => (E(e), Q(i, n, e, t), l(
505
+ return (n) => (_(e), Q(i, n, e, t), c(
508
506
  r.getState().cogsStateStore[t],
509
507
  []
510
508
  ));
511
509
  if (s === "uniqueInsert")
512
- return (n, a, c) => {
510
+ return (n, a, l) => {
513
511
  const o = r.getState().getNestedState(t, e), d = L(n) ? n(o) : n;
514
- let I = null;
512
+ let E = null;
515
513
  if (!o.some((N) => {
516
514
  if (a) {
517
- const p = a.every(
515
+ const k = a.every(
518
516
  (z) => M(N[z], d[z])
519
517
  );
520
- return p && (I = N), p;
518
+ return k && (E = N), k;
521
519
  }
522
- const j = M(N, d);
523
- return j && (I = N), j;
520
+ const p = M(N, d);
521
+ return p && (E = N), p;
524
522
  }))
525
- E(e), Q(i, d, e, t);
526
- else if (c && I) {
527
- const N = c(I), j = o.map(
528
- (p) => M(p, I) ? N : p
523
+ _(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
529
527
  );
530
- E(e), B(i, j, e);
528
+ _(e), B(i, p, e);
531
529
  }
532
530
  };
533
531
  if (s === "cut")
534
532
  return (n, a) => {
535
- a?.waitForSync || (E(e), J(i, e, t, n));
533
+ a?.waitForSync || (_(e), J(i, e, t, n));
536
534
  };
537
535
  if (s === "cutByValue")
538
536
  return (n) => {
@@ -541,20 +539,20 @@ function Y(t, i, m, y) {
541
539
  };
542
540
  if (s === "toggleByValue")
543
541
  return (n) => {
544
- const a = f.findIndex((c) => c === n);
542
+ const a = f.findIndex((l) => l === n);
545
543
  a > -1 ? J(i, e, t, a) : Q(i, n, e, t);
546
544
  };
547
545
  if (s === "stateFilter")
548
546
  return (n) => {
549
- const a = f.map((d, I) => ({
547
+ const a = f.map((d, E) => ({
550
548
  ...d,
551
- __origIndex: I.toString()
552
- })), c = [], o = [];
549
+ __origIndex: E.toString()
550
+ })), l = [], o = [];
553
551
  for (let d = 0; d < a.length; d++)
554
- n(a[d], d) && (c.push(d), o.push(a[d]));
555
- return u.clear(), w++, l(o, e, {
552
+ n(a[d], d) && (l.push(d), o.push(a[d]));
553
+ return u.clear(), w++, c(o, e, {
556
554
  filtered: [...S?.filtered || [], e],
557
- validIndices: c
555
+ validIndices: l
558
556
  // Always pass validIndices, even if empty
559
557
  });
560
558
  };
@@ -594,17 +592,17 @@ function Y(t, i, m, y) {
594
592
  return r.getState().getSyncInfo(n);
595
593
  }
596
594
  if (s == "getLocalStorage")
597
- return (n) => gt(y + "-" + t + "-" + n);
595
+ return (n) => ut(y + "-" + t + "-" + n);
598
596
  if (s === "_selected") {
599
- const n = e.slice(0, -1), a = n.join("."), c = r.getState().getNestedState(t, n);
600
- return Array.isArray(c) ? Number(e[e.length - 1]) === r.getState().getSelectedIndex(t, a) : void 0;
597
+ const n = e.slice(0, -1), a = n.join("."), l = r.getState().getNestedState(t, n);
598
+ return Array.isArray(l) ? Number(e[e.length - 1]) === r.getState().getSelectedIndex(t, a) : void 0;
601
599
  }
602
600
  if (s === "setSelected")
603
601
  return (n) => {
604
- const a = e.slice(0, -1), c = Number(e[e.length - 1]), o = a.join(".");
605
- n ? r.getState().setSelectedIndex(t, o, c) : r.getState().setSelectedIndex(t, o, void 0);
602
+ const a = e.slice(0, -1), l = Number(e[e.length - 1]), o = a.join(".");
603
+ n ? r.getState().setSelectedIndex(t, o, l) : r.getState().setSelectedIndex(t, o, void 0);
606
604
  const d = r.getState().getNestedState(t, [...a]);
607
- B(i, d, a), E(a);
605
+ B(i, d, a), _(a);
608
606
  };
609
607
  if (e.length == 0) {
610
608
  if (s === "validateZodSchema")
@@ -615,16 +613,16 @@ function Y(t, i, m, y) {
615
613
  if (!n?.key)
616
614
  throw new Error("Validation key not found");
617
615
  P(n.key);
618
- const c = r.getState().cogsStateStore[t];
616
+ const l = r.getState().cogsStateStore[t];
619
617
  try {
620
618
  const o = r.getState().getValidationErrors(n.key);
621
- o && o.length > 0 && o.forEach(([I]) => {
622
- I && I.startsWith(n.key) && P(I);
619
+ o && o.length > 0 && o.forEach(([E]) => {
620
+ E && E.startsWith(n.key) && P(E);
623
621
  });
624
- const d = n.zodSchema.safeParse(c);
625
- return d.success ? !0 : (d.error.errors.forEach((k) => {
626
- const N = k.path, j = k.message, p = [n.key, ...N].join(".");
627
- a(p, j);
622
+ 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);
628
626
  }), ft(t), !1);
629
627
  } catch (o) {
630
628
  return console.error("Zod schema validation failed", o), !1;
@@ -671,15 +669,15 @@ function Y(t, i, m, y) {
671
669
  if (a?.debounce)
672
670
  $t(() => {
673
671
  B(i, n, e, "");
674
- const c = r.getState().getNestedState(t, e);
675
- a?.afterUpdate && a.afterUpdate(c);
672
+ const l = r.getState().getNestedState(t, e);
673
+ a?.afterUpdate && a.afterUpdate(l);
676
674
  }, a.debounce);
677
675
  else {
678
676
  B(i, n, e, "");
679
- const c = r.getState().getNestedState(t, e);
680
- a?.afterUpdate && a.afterUpdate(c);
677
+ const l = r.getState().getNestedState(t, e);
678
+ a?.afterUpdate && a.afterUpdate(l);
681
679
  }
682
- E(e);
680
+ _(e);
683
681
  };
684
682
  if (s === "formElement")
685
683
  return (n, a) => /* @__PURE__ */ st(
@@ -692,8 +690,8 @@ function Y(t, i, m, y) {
692
690
  formOpts: a
693
691
  }
694
692
  );
695
- const b = [...e, s], C = r.getState().getNestedState(t, b);
696
- return l(C, b, S);
693
+ const b = [...e, s], h = r.getState().getNestedState(t, b);
694
+ return c(h, b, S);
697
695
  }
698
696
  }, R = new Proxy(A, T);
699
697
  return u.set(x, {
@@ -701,14 +699,14 @@ function Y(t, i, m, y) {
701
699
  stateVersion: w
702
700
  }), R;
703
701
  }
704
- return l(
702
+ return c(
705
703
  r.getState().getNestedState(t, [])
706
704
  );
707
705
  }
708
706
  function K(t) {
709
707
  return X(bt, { proxy: t });
710
708
  }
711
- function jt({
709
+ function pt({
712
710
  proxy: t,
713
711
  rebuildStateShape: i
714
712
  }) {
@@ -717,7 +715,7 @@ function jt({
717
715
  m,
718
716
  t._path
719
717
  ).stateMapNoRender(
720
- (u, w, E, v, l) => t._mapFn(u, w, E, v, l)
718
+ (u, w, _, v, c) => t._mapFn(u, w, _, v, c)
721
719
  ) : null;
722
720
  }
723
721
  function bt({
@@ -727,13 +725,13 @@ function bt({
727
725
  return et(() => {
728
726
  const y = i.current;
729
727
  if (!y || !y.parentElement) return;
730
- const u = y.parentElement, E = Array.from(u.childNodes).indexOf(y);
728
+ const u = y.parentElement, _ = Array.from(u.childNodes).indexOf(y);
731
729
  let v = u.getAttribute("data-parent-id");
732
730
  v || (v = `parent-${crypto.randomUUID()}`, u.setAttribute("data-parent-id", v));
733
731
  const f = {
734
732
  instanceId: `instance-${crypto.randomUUID()}`,
735
733
  parentId: v,
736
- position: E,
734
+ position: _,
737
735
  effect: t._effect
738
736
  };
739
737
  r.getState().addSignalElement(m, f);
@@ -780,6 +778,6 @@ export {
780
778
  qt as addStateOptions,
781
779
  zt as createCogsState,
782
780
  Bt as notifyComponent,
783
- Ot as useCogsStateFn
781
+ jt as useCogsStateFn
784
782
  };
785
783
  //# sourceMappingURL=CogsState.jsx.map