cogsbox-state 0.5.344 → 0.5.345

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