cogsbox-state 0.5.94 → 0.5.95

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