cogsbox-state 0.5.198 → 0.5.200

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,40 +1,40 @@
1
1
  "use client";
2
- import { jsx as Se } from "react/jsx-runtime";
3
- import { useState as le, useRef as ee, useEffect as de, useLayoutEffect as ke, useMemo as $e, createElement as re, useSyncExternalStore as Te, startTransition as Ae } from "react";
4
- import { transformStateFunc as Ne, isDeepEqual as L, isFunction as Z, getNestedValue as q, getDifferences as he, debounce as Ve } from "./utility.js";
5
- import { pushFunc as se, updateFn as Q, cutFunc as K, ValidationWrapper as _e, FormControlComponent as Ce } from "./Functions.jsx";
6
- import Pe from "superjson";
2
+ import { jsx as me } from "react/jsx-runtime";
3
+ import { useState as le, useRef as ee, useEffect as de, useLayoutEffect as Ae, useMemo as Te, createElement as re, useSyncExternalStore as Ne, startTransition as Ve } from "react";
4
+ import { transformStateFunc as _e, isDeepEqual as L, isFunction as Z, getNestedValue as q, getDifferences as pe, debounce as Ce } from "./utility.js";
5
+ import { pushFunc as se, updateFn as Q, cutFunc as K, ValidationWrapper as Pe, FormControlComponent as be } from "./Functions.jsx";
6
+ import xe from "superjson";
7
7
  import { v4 as ue } from "uuid";
8
8
  import "zod";
9
- import { getGlobalStore as t, formRefStore as me } from "./store.js";
10
- import { useCogsConfig as pe } from "./CogsStateClient.jsx";
11
- import { applyPatch as be } from "fast-json-patch";
12
- function ye(e, i) {
9
+ import { getGlobalStore as t, formRefStore as ye } from "./store.js";
10
+ import { useCogsConfig as we } from "./CogsStateClient.jsx";
11
+ import { applyPatch as Oe } from "fast-json-patch";
12
+ function ve(e, i) {
13
13
  const S = t.getState().getInitialOptions, u = t.getState().setInitialStateOptions, f = S(e) || {};
14
14
  u(e, {
15
15
  ...f,
16
16
  ...i
17
17
  });
18
18
  }
19
- function ve({
19
+ function he({
20
20
  stateKey: e,
21
21
  options: i,
22
22
  initialOptionsPart: S
23
23
  }) {
24
- const u = H(e) || {}, f = S[e] || {}, k = t.getState().setInitialStateOptions, h = { ...f, ...u };
24
+ const u = H(e) || {}, f = S[e] || {}, k = t.getState().setInitialStateOptions, I = { ...f, ...u };
25
25
  let v = !1;
26
26
  if (i)
27
27
  for (const s in i)
28
- h.hasOwnProperty(s) ? (s == "localStorage" && i[s] && h[s].key !== i[s]?.key && (v = !0, h[s] = i[s]), s == "initialState" && i[s] && h[s] !== i[s] && // Different references
29
- !L(h[s], i[s]) && (v = !0, h[s] = i[s])) : (v = !0, h[s] = i[s]);
30
- v && k(e, h);
28
+ I.hasOwnProperty(s) ? (s == "localStorage" && i[s] && I[s].key !== i[s]?.key && (v = !0, I[s] = i[s]), s == "initialState" && i[s] && I[s] !== i[s] && // Different references
29
+ !L(I[s], i[s]) && (v = !0, I[s] = i[s])) : (v = !0, I[s] = i[s]);
30
+ v && k(e, I);
31
31
  }
32
- function Qe(e, { formElements: i, validation: S }) {
32
+ function et(e, { formElements: i, validation: S }) {
33
33
  return { initialState: e, formElements: i, validation: S };
34
34
  }
35
- const Ke = (e, i) => {
35
+ const tt = (e, i) => {
36
36
  let S = e;
37
- const [u, f] = Ne(S);
37
+ const [u, f] = _e(S);
38
38
  (Object.keys(f).length > 0 || i && Object.keys(i).length > 0) && Object.keys(f).forEach((v) => {
39
39
  f[v] = f[v] || {}, f[v].formElements = {
40
40
  ...i?.formElements,
@@ -46,13 +46,13 @@ const Ke = (e, i) => {
46
46
  }), t.getState().setInitialStates(u), t.getState().setCreatedState(u);
47
47
  const k = (v, s) => {
48
48
  const [m] = le(s?.componentId ?? ue());
49
- ve({
49
+ he({
50
50
  stateKey: v,
51
51
  options: s,
52
52
  initialOptionsPart: f
53
53
  });
54
- const n = t.getState().cogsStateStore[v] || u[v], I = s?.modifyState ? s.modifyState(n) : n, [M, _] = Me(
55
- I,
54
+ const n = t.getState().cogsStateStore[v] || u[v], h = s?.modifyState ? s.modifyState(n) : n, [M, _] = We(
55
+ h,
56
56
  {
57
57
  stateKey: v,
58
58
  syncUpdate: s?.syncUpdate,
@@ -69,21 +69,21 @@ const Ke = (e, i) => {
69
69
  );
70
70
  return _;
71
71
  };
72
- function h(v, s) {
73
- ve({ stateKey: v, options: s, initialOptionsPart: f }), s.localStorage && je(v, s), oe(v);
72
+ function I(v, s) {
73
+ he({ stateKey: v, options: s, initialOptionsPart: f }), s.localStorage && Me(v, s), oe(v);
74
74
  }
75
- return { useCogsState: k, setCogsOptions: h };
75
+ return { useCogsState: k, setCogsOptions: I };
76
76
  }, {
77
77
  setUpdaterState: te,
78
78
  setState: Y,
79
79
  getInitialOptions: H,
80
- getKeyState: we,
81
- getValidationErrors: xe,
82
- setStateLog: Oe,
80
+ getKeyState: Ee,
81
+ getValidationErrors: Fe,
82
+ setStateLog: je,
83
83
  updateInitialStateGlobal: ge,
84
- addValidationError: Fe,
84
+ addValidationError: Re,
85
85
  removeValidationError: B,
86
- setServerSyncActions: Re
86
+ setServerSyncActions: Ue
87
87
  } = t.getState(), Ie = (e, i, S, u, f) => {
88
88
  S?.log && console.log(
89
89
  "saving to localstorage",
@@ -93,19 +93,19 @@ const Ke = (e, i) => {
93
93
  );
94
94
  const k = Z(S?.localStorage?.key) ? S.localStorage?.key(e) : S?.localStorage?.key;
95
95
  if (k && u) {
96
- const h = `${u}-${i}-${k}`;
96
+ const I = `${u}-${i}-${k}`;
97
97
  let v;
98
98
  try {
99
- v = ae(h)?.lastSyncedWithServer;
99
+ v = ae(I)?.lastSyncedWithServer;
100
100
  } catch {
101
101
  }
102
102
  const s = {
103
103
  state: e,
104
104
  lastUpdated: Date.now(),
105
105
  lastSyncedWithServer: f ?? v
106
- }, m = Pe.serialize(s);
106
+ }, m = xe.serialize(s);
107
107
  window.localStorage.setItem(
108
- h,
108
+ I,
109
109
  JSON.stringify(m.json)
110
110
  );
111
111
  }
@@ -117,8 +117,8 @@ const Ke = (e, i) => {
117
117
  } catch (i) {
118
118
  return console.error("Error loading from localStorage:", i), null;
119
119
  }
120
- }, je = (e, i) => {
121
- const S = t.getState().cogsStateStore[e], { sessionId: u } = pe(), f = Z(i?.localStorage?.key) ? i.localStorage.key(S) : i?.localStorage?.key;
120
+ }, Me = (e, i) => {
121
+ const S = t.getState().cogsStateStore[e], { sessionId: u } = we(), f = Z(i?.localStorage?.key) ? i.localStorage.key(S) : i?.localStorage?.key;
122
122
  if (f && u) {
123
123
  const k = ae(
124
124
  `${u}-${e}-${f}`
@@ -127,8 +127,8 @@ const Ke = (e, i) => {
127
127
  return Y(e, k.state), oe(e), !0;
128
128
  }
129
129
  return !1;
130
- }, Ee = (e, i, S, u, f, k) => {
131
- const h = {
130
+ }, ke = (e, i, S, u, f, k) => {
131
+ const I = {
132
132
  initialState: i,
133
133
  updaterState: ne(
134
134
  e,
@@ -138,7 +138,7 @@ const Ke = (e, i) => {
138
138
  ),
139
139
  state: S
140
140
  };
141
- ge(e, h.initialState), te(e, h.updaterState), Y(e, h.state);
141
+ ge(e, I.initialState), te(e, I.updaterState), Y(e, I.state);
142
142
  }, oe = (e) => {
143
143
  const i = t.getState().stateComponents.get(e);
144
144
  if (!i) return;
@@ -148,7 +148,7 @@ const Ke = (e, i) => {
148
148
  }), queueMicrotask(() => {
149
149
  S.forEach((u) => u());
150
150
  });
151
- }, et = (e, i) => {
151
+ }, nt = (e, i) => {
152
152
  const S = t.getState().stateComponents.get(e);
153
153
  if (S) {
154
154
  const u = `${e}////${i}`, f = S.components.get(u);
@@ -156,7 +156,7 @@ const Ke = (e, i) => {
156
156
  return;
157
157
  f && f.forceUpdate();
158
158
  }
159
- }, Ue = (e, i, S, u) => {
159
+ }, De = (e, i, S, u) => {
160
160
  switch (e) {
161
161
  case "update":
162
162
  return {
@@ -179,22 +179,22 @@ const Ke = (e, i) => {
179
179
  return { oldValue: null, newValue: null };
180
180
  }
181
181
  };
182
- function Me(e, {
182
+ function We(e, {
183
183
  stateKey: i,
184
184
  serverSync: S,
185
185
  localStorage: u,
186
186
  formElements: f,
187
187
  reactiveDeps: k,
188
- reactiveType: h,
188
+ reactiveType: I,
189
189
  componentId: v,
190
190
  initialState: s,
191
191
  syncUpdate: m,
192
192
  dependencies: n,
193
- serverState: I
193
+ serverState: h
194
194
  } = {}) {
195
- const [M, _] = le({}), { sessionId: C } = pe();
195
+ const [M, _] = le({}), { sessionId: C } = we();
196
196
  let D = !i;
197
- const [g] = le(i ?? ue()), d = t.getState().stateLog[g], X = ee(/* @__PURE__ */ new Set()), J = ee(v ?? ue()), P = ee(
197
+ const [g] = le(i ?? ue()), l = t.getState().stateLog[g], X = ee(/* @__PURE__ */ new Set()), J = ee(v ?? ue()), P = ee(
198
198
  null
199
199
  );
200
200
  P.current = H(g) ?? null, de(() => {
@@ -211,7 +211,7 @@ function Me(e, {
211
211
  }
212
212
  }, [m]), de(() => {
213
213
  if (s) {
214
- ye(g, {
214
+ ve(g, {
215
215
  initialState: s
216
216
  });
217
217
  const o = P.current, c = o?.serverState?.id !== void 0 && o?.serverState?.status === "success" && o?.serverState?.data, p = t.getState().initialStateGlobal[g];
@@ -220,24 +220,24 @@ function Me(e, {
220
220
  let w = null;
221
221
  const $ = Z(o?.localStorage?.key) ? o?.localStorage?.key(s) : o?.localStorage?.key;
222
222
  $ && C && (w = ae(`${C}-${g}-${$}`));
223
- let A = s, T = !1;
224
- const V = c ? Date.now() : 0, R = w?.lastUpdated || 0, b = w?.lastSyncedWithServer || 0;
225
- c && V > R ? (A = o.serverState.data, T = !0) : w && R > b && (A = w.state, o?.localStorage?.onChange && o?.localStorage?.onChange(A)), Ee(
223
+ let T = s, A = !1;
224
+ const N = c ? Date.now() : 0, O = w?.lastUpdated || 0, b = w?.lastSyncedWithServer || 0;
225
+ c && N > O ? (T = o.serverState.data, A = !0) : w && O > b && (T = w.state, o?.localStorage?.onChange && o?.localStorage?.onChange(T)), ke(
226
226
  g,
227
227
  s,
228
- A,
229
- l,
228
+ T,
229
+ d,
230
230
  J.current,
231
231
  C
232
- ), T && $ && C && Ie(A, g, o, C, Date.now()), oe(g), (Array.isArray(h) ? h : [h || "component"]).includes("none") || _({});
232
+ ), A && $ && C && Ie(T, g, o, C, Date.now()), oe(g), (Array.isArray(I) ? I : [I || "component"]).includes("none") || _({});
233
233
  }
234
234
  }, [
235
235
  s,
236
- I?.status,
237
- I?.data,
236
+ h?.status,
237
+ h?.data,
238
238
  ...n || []
239
- ]), ke(() => {
240
- D && ye(g, {
239
+ ]), Ae(() => {
240
+ D && ve(g, {
241
241
  serverSync: S,
242
242
  formElements: f,
243
243
  initialState: s,
@@ -252,13 +252,13 @@ function Me(e, {
252
252
  paths: /* @__PURE__ */ new Set(),
253
253
  deps: [],
254
254
  depsFunction: k || void 0,
255
- reactiveType: h ?? ["component", "deps"]
255
+ reactiveType: I ?? ["component", "deps"]
256
256
  }), t.getState().stateComponents.set(g, a), _({}), () => {
257
257
  const c = `${g}////${J.current}`;
258
258
  a && (a.components.delete(c), a.components.size === 0 && t.getState().stateComponents.delete(g));
259
259
  };
260
260
  }, []);
261
- const l = (o, a, c, p) => {
261
+ const d = (o, a, c, p) => {
262
262
  if (Array.isArray(a)) {
263
263
  const y = `${g}-${a.join(".")}`;
264
264
  X.current.add(y);
@@ -266,25 +266,25 @@ function Me(e, {
266
266
  Y(g, (y) => {
267
267
  const w = Z(o) ? o(y) : o, $ = `${g}-${a.join(".")}`;
268
268
  if ($) {
269
- let G = !1, N = t.getState().signalDomElements.get($);
270
- if ((!N || N.size === 0) && (c.updateType === "insert" || c.updateType === "cut")) {
271
- const j = a.slice(0, -1), W = q(w, j);
272
- if (Array.isArray(W)) {
273
- G = !0;
274
- const E = `${g}-${j.join(".")}`;
275
- N = t.getState().signalDomElements.get(E);
269
+ let R = !1, V = t.getState().signalDomElements.get($);
270
+ if ((!V || V.size === 0) && (c.updateType === "insert" || c.updateType === "cut")) {
271
+ const W = a.slice(0, -1), G = q(w, W);
272
+ if (Array.isArray(G)) {
273
+ R = !0;
274
+ const E = `${g}-${W.join(".")}`;
275
+ V = t.getState().signalDomElements.get(E);
276
276
  }
277
277
  }
278
- if (N) {
279
- const j = G ? q(w, a.slice(0, -1)) : q(w, a);
280
- N.forEach(({ parentId: W, position: E, effect: F }) => {
281
- const O = document.querySelector(
282
- `[data-parent-id="${W}"]`
278
+ if (V) {
279
+ const W = R ? q(w, a.slice(0, -1)) : q(w, a);
280
+ V.forEach(({ parentId: G, position: E, effect: j }) => {
281
+ const x = document.querySelector(
282
+ `[data-parent-id="${G}"]`
283
283
  );
284
- if (O) {
285
- const z = Array.from(O.childNodes);
284
+ if (x) {
285
+ const z = Array.from(x.childNodes);
286
286
  if (z[E]) {
287
- const U = F ? new Function("state", `return (${F})(state)`)(j) : j;
287
+ const U = j ? new Function("state", `return (${j})(state)`)(W) : W;
288
288
  z[E].textContent = String(U);
289
289
  }
290
290
  }
@@ -294,114 +294,110 @@ function Me(e, {
294
294
  c.updateType === "update" && (p || P.current?.validation?.key) && a && B(
295
295
  (p || P.current?.validation?.key) + "." + a.join(".")
296
296
  );
297
- const A = a.slice(0, a.length - 1);
297
+ const T = a.slice(0, a.length - 1);
298
298
  c.updateType === "cut" && P.current?.validation?.key && B(
299
- P.current?.validation?.key + "." + A.join(".")
300
- ), c.updateType === "insert" && P.current?.validation?.key && xe(
301
- P.current?.validation?.key + "." + A.join(".")
302
- ).filter(([N, j]) => {
303
- let W = N?.split(".").length;
304
- if (N == A.join(".") && W == A.length - 1) {
305
- let E = N + "." + A;
306
- B(N), Fe(E, j);
299
+ P.current?.validation?.key + "." + T.join(".")
300
+ ), c.updateType === "insert" && P.current?.validation?.key && Fe(
301
+ P.current?.validation?.key + "." + T.join(".")
302
+ ).filter(([V, W]) => {
303
+ let G = V?.split(".").length;
304
+ if (V == T.join(".") && G == T.length - 1) {
305
+ let E = V + "." + T;
306
+ B(V), Re(E, W);
307
307
  }
308
308
  });
309
- const T = t.getState().stateComponents.get(g);
310
- if (T) {
311
- const G = he(y, w), N = new Set(G), j = c.updateType === "update" ? a.join(".") : a.slice(0, -1).join(".") || "";
309
+ const A = t.getState().stateComponents.get(g);
310
+ if (A) {
311
+ const R = pe(y, w), V = new Set(R), W = c.updateType === "update" ? a.join(".") : a.slice(0, -1).join(".") || "";
312
312
  for (const [
313
- W,
313
+ G,
314
314
  E
315
- ] of T.components.entries()) {
316
- let F = !1;
317
- const O = Array.isArray(E.reactiveType) ? E.reactiveType : [E.reactiveType || "component"];
318
- if (!O.includes("none")) {
319
- if (O.includes("all")) {
315
+ ] of A.components.entries()) {
316
+ let j = !1;
317
+ const x = Array.isArray(E.reactiveType) ? E.reactiveType : [E.reactiveType || "component"];
318
+ if (!x.includes("none")) {
319
+ if (x.includes("all")) {
320
320
  E.forceUpdate();
321
321
  continue;
322
322
  }
323
- if (O.includes("component") && ((E.paths.has(j) || E.paths.has("")) && (F = !0), !F))
324
- for (const z of N) {
323
+ if (x.includes("component") && ((E.paths.has(W) || E.paths.has("")) && (j = !0), !j))
324
+ for (const z of V) {
325
325
  let U = z;
326
326
  for (; ; ) {
327
327
  if (E.paths.has(U)) {
328
- F = !0;
328
+ j = !0;
329
329
  break;
330
330
  }
331
331
  const ie = U.lastIndexOf(".");
332
332
  if (ie !== -1) {
333
- const fe = U.substring(
333
+ const Se = U.substring(
334
334
  0,
335
335
  ie
336
336
  );
337
337
  if (!isNaN(
338
338
  Number(U.substring(ie + 1))
339
- ) && E.paths.has(fe)) {
340
- F = !0;
339
+ ) && E.paths.has(Se)) {
340
+ j = !0;
341
341
  break;
342
342
  }
343
- U = fe;
343
+ U = Se;
344
344
  } else
345
345
  U = "";
346
346
  if (U === "")
347
347
  break;
348
348
  }
349
- if (F) break;
349
+ if (j) break;
350
350
  }
351
- if (!F && O.includes("deps") && E.depsFunction) {
351
+ if (!j && x.includes("deps") && E.depsFunction) {
352
352
  const z = E.depsFunction(w);
353
353
  let U = !1;
354
- typeof z == "boolean" ? z && (U = !0) : L(E.deps, z) || (E.deps = z, U = !0), U && (F = !0);
354
+ typeof z == "boolean" ? z && (U = !0) : L(E.deps, z) || (E.deps = z, U = !0), U && (j = !0);
355
355
  }
356
- F && E.forceUpdate();
356
+ j && E.forceUpdate();
357
357
  }
358
358
  }
359
359
  }
360
- const V = Date.now();
361
- a = a.map((G, N) => {
362
- const j = a.slice(0, -1), W = q(w, j);
363
- return N === a.length - 1 && ["insert", "cut"].includes(c.updateType) ? (W.length - 1).toString() : G;
364
- }), console.log(
365
- "mmmmmmmmmmmmmmmmm22222222222222",
366
- c.updateType,
367
- y,
368
- w,
369
- a
370
- );
371
- const { oldValue: R, newValue: b } = Ue(
372
- c.updateType,
360
+ const N = Date.now();
361
+ let O = [...a], b = { ...c };
362
+ if (c.updateType === "insert") {
363
+ const R = q(w, a);
364
+ Array.isArray(R) && R.length > 0 && O.push((R.length - 1).toString());
365
+ }
366
+ const { oldValue: F, newValue: $e } = De(
367
+ b.updateType,
373
368
  y,
374
369
  w,
375
- a
376
- ), x = {
377
- timeStamp: V,
370
+ O
371
+ // Use the correctly determined path for logging
372
+ ), fe = {
373
+ timeStamp: N,
378
374
  stateKey: g,
379
375
  path: a,
380
376
  updateType: c.updateType,
381
377
  status: "new",
382
- oldValue: R,
383
- newValue: b
378
+ oldValue: F,
379
+ newValue: $e
384
380
  };
385
- if (Oe(g, (G) => {
386
- const j = [...G ?? [], x].reduce((W, E) => {
387
- const F = `${E.stateKey}:${JSON.stringify(E.path)}`, O = W.get(F);
388
- return O ? (O.timeStamp = Math.max(O.timeStamp, E.timeStamp), O.newValue = E.newValue, O.oldValue = O.oldValue ?? E.oldValue, O.updateType = E.updateType) : W.set(F, { ...E }), W;
381
+ if (je(g, (R) => {
382
+ const W = [...R ?? [], fe].reduce((G, E) => {
383
+ const j = `${E.stateKey}:${JSON.stringify(E.path)}`, x = G.get(j);
384
+ return x ? (x.timeStamp = Math.max(x.timeStamp, E.timeStamp), x.newValue = E.newValue, x.oldValue = x.oldValue ?? E.oldValue, x.updateType = E.updateType) : G.set(j, { ...E }), G;
389
385
  }, /* @__PURE__ */ new Map());
390
- return Array.from(j.values());
386
+ return Array.from(W.values());
391
387
  }), Ie(
392
388
  w,
393
389
  g,
394
390
  P.current,
395
391
  C
396
392
  ), P.current?.middleware && P.current.middleware({
397
- updateLog: d,
398
- update: x
393
+ updateLog: l,
394
+ update: fe
399
395
  }), P.current?.serverSync) {
400
- const G = t.getState().serverState[g], N = P.current?.serverSync;
401
- Re(g, {
402
- syncKey: typeof N.syncKey == "string" ? N.syncKey : N.syncKey({ state: w }),
403
- rollBackState: G,
404
- actionTimeStamp: Date.now() + (N.debounce ?? 3e3),
396
+ const R = t.getState().serverState[g], V = P.current?.serverSync;
397
+ Ue(g, {
398
+ syncKey: typeof V.syncKey == "string" ? V.syncKey : V.syncKey({ state: w }),
399
+ rollBackState: R,
400
+ actionTimeStamp: Date.now() + (V.debounce ?? 3e3),
405
401
  status: "waiting"
406
402
  });
407
403
  }
@@ -412,26 +408,26 @@ function Me(e, {
412
408
  g,
413
409
  ne(
414
410
  g,
415
- l,
411
+ d,
416
412
  J.current,
417
413
  C
418
414
  )
419
415
  ), t.getState().cogsStateStore[g] || Y(g, e), t.getState().initialStateGlobal[g] || ge(g, e));
420
- const r = $e(() => ne(
416
+ const r = Te(() => ne(
421
417
  g,
422
- l,
418
+ d,
423
419
  J.current,
424
420
  C
425
421
  ), [g]);
426
- return [we(g), r];
422
+ return [Ee(g), r];
427
423
  }
428
424
  function ne(e, i, S, u) {
429
425
  const f = /* @__PURE__ */ new Map();
430
426
  let k = 0;
431
- const h = (m) => {
427
+ const I = (m) => {
432
428
  const n = m.join(".");
433
- for (const [I] of f)
434
- (I === n || I.startsWith(n + ".")) && f.delete(I);
429
+ for (const [h] of f)
430
+ (h === n || h.startsWith(n + ".")) && f.delete(h);
435
431
  k++;
436
432
  }, v = {
437
433
  removeValidation: (m) => {
@@ -440,14 +436,14 @@ function ne(e, i, S, u) {
440
436
  revertToInitialState: (m) => {
441
437
  const n = t.getState().getInitialOptions(e)?.validation;
442
438
  n?.key && B(n?.key), m?.validationKey && B(m.validationKey);
443
- const I = t.getState().initialStateGlobal[e];
439
+ const h = t.getState().initialStateGlobal[e];
444
440
  t.getState().clearSelectedIndexesForState(e), f.clear(), k++;
445
- const M = s(I, []), _ = H(e), C = Z(_?.localStorage?.key) ? _?.localStorage?.key(I) : _?.localStorage?.key, D = `${u}-${e}-${C}`;
446
- D && localStorage.removeItem(D), te(e, M), Y(e, I);
441
+ const M = s(h, []), _ = H(e), C = Z(_?.localStorage?.key) ? _?.localStorage?.key(h) : _?.localStorage?.key, D = `${u}-${e}-${C}`;
442
+ D && localStorage.removeItem(D), te(e, M), Y(e, h);
447
443
  const g = t.getState().stateComponents.get(e);
448
- return g && g.components.forEach((d) => {
449
- d.forceUpdate();
450
- }), I;
444
+ return g && g.components.forEach((l) => {
445
+ l.forceUpdate();
446
+ }), h;
451
447
  },
452
448
  updateInitialState: (m) => {
453
449
  f.clear(), k++;
@@ -456,8 +452,8 @@ function ne(e, i, S, u) {
456
452
  i,
457
453
  S,
458
454
  u
459
- ), I = t.getState().initialStateGlobal[e], M = H(e), _ = Z(M?.localStorage?.key) ? M?.localStorage?.key(I) : M?.localStorage?.key, C = `${u}-${e}-${_}`;
460
- return console.log("removing storage", C), localStorage.getItem(C) && localStorage.removeItem(C), Ae(() => {
455
+ ), h = t.getState().initialStateGlobal[e], M = H(e), _ = Z(M?.localStorage?.key) ? M?.localStorage?.key(h) : M?.localStorage?.key, C = `${u}-${e}-${_}`;
456
+ return console.log("removing storage", C), localStorage.getItem(C) && localStorage.removeItem(C), Ve(() => {
461
457
  ge(e, m), te(e, n), Y(e, m);
462
458
  const D = t.getState().stateComponents.get(e);
463
459
  D && D.components.forEach((g) => {
@@ -472,10 +468,10 @@ function ne(e, i, S, u) {
472
468
  _isLoading: t.getState().isLoadingGlobal[e],
473
469
  _isServerSynced: () => {
474
470
  const m = t.getState().serverState[e];
475
- return !!(m && L(m, we(e)));
471
+ return !!(m && L(m, Ee(e)));
476
472
  }
477
473
  };
478
- function s(m, n = [], I) {
474
+ function s(m, n = [], h) {
479
475
  const M = n.map(String).join(".");
480
476
  f.get(M);
481
477
  const _ = function() {
@@ -485,35 +481,30 @@ function ne(e, i, S, u) {
485
481
  _[g] = v[g];
486
482
  });
487
483
  const C = {
488
- apply(g, d, X) {
484
+ apply(g, l, X) {
489
485
  return console.log(
490
486
  `PROXY APPLY TRAP HIT: stateKey=${e}, path=${n.join(".")}`
491
487
  ), console.trace("Apply trap stack trace"), t().getNestedState(e, n);
492
488
  },
493
- get(g, d) {
494
- if (d !== "then" && !d.startsWith("$") && d !== "stateMapNoRender") {
495
- const l = n.join("."), r = `${e}////${S}`;
496
- console.log(
497
- ".........................................................",
498
- l
499
- );
500
- const o = t.getState().stateComponents.get(e);
489
+ get(g, l) {
490
+ if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender") {
491
+ const d = n.join("."), r = `${e}////${S}`, o = t.getState().stateComponents.get(e);
501
492
  if (o) {
502
493
  const a = o.components.get(r);
503
- a && (n.length > 0 || d === "get") && a.paths.add(l);
494
+ a && (n.length > 0 || l === "get") && a.paths.add(d);
504
495
  }
505
496
  }
506
- if (d === "getDifferences")
507
- return () => he(
497
+ if (l === "getDifferences")
498
+ return () => pe(
508
499
  t.getState().cogsStateStore[e],
509
500
  t.getState().initialStateGlobal[e]
510
501
  );
511
- if (d === "sync" && n.length === 0)
502
+ if (l === "sync" && n.length === 0)
512
503
  return async function() {
513
- const l = t.getState().getInitialOptions(e), r = l?.sync;
504
+ const d = t.getState().getInitialOptions(e), r = d?.sync;
514
505
  if (!r)
515
506
  return console.error(`No mutation defined for state key "${e}"`), { success: !1, error: "No mutation defined" };
516
- const o = t.getState().getNestedState(e, []), a = l?.validation?.key;
507
+ const o = t.getState().getNestedState(e, []), a = d?.validation?.key;
517
508
  try {
518
509
  const c = await r.action(o);
519
510
  if (c && !c.success && c.errors && a) {
@@ -531,93 +522,93 @@ function ne(e, i, S, u) {
531
522
  return r.onError && r.onError(c), { success: !1, error: c };
532
523
  }
533
524
  };
534
- if (d === "_status") {
535
- const l = t.getState().getNestedState(e, n), r = t.getState().initialStateGlobal[e], o = q(r, n);
536
- return L(l, o) ? "fresh" : "stale";
525
+ if (l === "_status") {
526
+ const d = t.getState().getNestedState(e, n), r = t.getState().initialStateGlobal[e], o = q(r, n);
527
+ return L(d, o) ? "fresh" : "stale";
537
528
  }
538
- if (d === "getStatus")
529
+ if (l === "getStatus")
539
530
  return function() {
540
- const l = t().getNestedState(
531
+ const d = t().getNestedState(
541
532
  e,
542
533
  n
543
534
  ), r = t.getState().initialStateGlobal[e], o = q(r, n);
544
- return L(l, o) ? "fresh" : "stale";
535
+ return L(d, o) ? "fresh" : "stale";
545
536
  };
546
- if (d === "removeStorage")
537
+ if (l === "removeStorage")
547
538
  return () => {
548
- const l = t.getState().initialStateGlobal[e], r = H(e), o = Z(r?.localStorage?.key) ? r?.localStorage?.key(l) : r?.localStorage?.key, a = `${u}-${e}-${o}`;
539
+ const d = t.getState().initialStateGlobal[e], r = H(e), o = Z(r?.localStorage?.key) ? r?.localStorage?.key(d) : r?.localStorage?.key, a = `${u}-${e}-${o}`;
549
540
  console.log("removing storage", a), a && localStorage.removeItem(a);
550
541
  };
551
- if (d === "showValidationErrors")
542
+ if (l === "showValidationErrors")
552
543
  return () => {
553
- const l = t.getState().getInitialOptions(e)?.validation;
554
- if (!l?.key)
544
+ const d = t.getState().getInitialOptions(e)?.validation;
545
+ if (!d?.key)
555
546
  throw new Error("Validation key not found");
556
- return t.getState().getValidationErrors(l.key + "." + n.join("."));
547
+ return t.getState().getValidationErrors(d.key + "." + n.join("."));
557
548
  };
558
549
  if (Array.isArray(m)) {
559
- const l = () => I?.validIndices ? m.map((o, a) => ({
550
+ const d = () => h?.validIndices ? m.map((o, a) => ({
560
551
  item: o,
561
- originalIndex: I.validIndices[a]
552
+ originalIndex: h.validIndices[a]
562
553
  })) : t.getState().getNestedState(e, n).map((o, a) => ({
563
554
  item: o,
564
555
  originalIndex: a
565
556
  }));
566
- if (d === "getSelected")
557
+ if (l === "getSelected")
567
558
  return () => {
568
559
  const r = t.getState().getSelectedIndex(e, n.join("."));
569
560
  if (r !== void 0)
570
561
  return s(
571
562
  m[r],
572
563
  [...n, r.toString()],
573
- I
564
+ h
574
565
  );
575
566
  };
576
- if (d === "clearSelected")
567
+ if (l === "clearSelected")
577
568
  return () => {
578
569
  t.getState().clearSelectedIndex({ stateKey: e, path: n });
579
570
  };
580
- if (d === "getSelectedIndex")
571
+ if (l === "getSelectedIndex")
581
572
  return () => t.getState().getSelectedIndex(e, n.join(".")) ?? -1;
582
- if (d === "stateSort")
573
+ if (l === "stateSort")
583
574
  return (r) => {
584
- const a = [...l()].sort(
575
+ const a = [...d()].sort(
585
576
  (y, w) => r(y.item, w.item)
586
577
  ), c = a.map(({ item: y }) => y), p = {
587
- ...I,
578
+ ...h,
588
579
  validIndices: a.map(
589
580
  ({ originalIndex: y }) => y
590
581
  )
591
582
  };
592
583
  return s(c, n, p);
593
584
  };
594
- if (d === "stateFilter")
585
+ if (l === "stateFilter")
595
586
  return (r) => {
596
- const a = l().filter(
587
+ const a = d().filter(
597
588
  ({ item: y }, w) => r(y, w)
598
589
  ), c = a.map(({ item: y }) => y), p = {
599
- ...I,
590
+ ...h,
600
591
  validIndices: a.map(
601
592
  ({ originalIndex: y }) => y
602
593
  )
603
594
  };
604
595
  return s(c, n, p);
605
596
  };
606
- if (d === "stateMap" || d === "stateMapNoRender")
597
+ if (l === "stateMap" || l === "stateMapNoRender")
607
598
  return (r) => m.map((a, c) => {
608
599
  let p;
609
- I?.validIndices && I.validIndices[c] !== void 0 ? p = I.validIndices[c] : p = c;
610
- const y = [...n, p.toString()], w = s(a, y, I);
600
+ h?.validIndices && h.validIndices[c] !== void 0 ? p = h.validIndices[c] : p = c;
601
+ const y = [...n, p.toString()], w = s(a, y, h);
611
602
  return r(
612
603
  a,
613
604
  w,
614
605
  c,
615
606
  m,
616
- s(m, n, I)
607
+ s(m, n, h)
617
608
  );
618
609
  });
619
- if (d === "$stateMap")
620
- return (r) => re(De, {
610
+ if (l === "$stateMap")
611
+ return (r) => re(Ge, {
621
612
  proxy: {
622
613
  _stateKey: e,
623
614
  _path: n,
@@ -626,7 +617,7 @@ function ne(e, i, S, u) {
626
617
  },
627
618
  rebuildStateShape: s
628
619
  });
629
- if (d === "stateFlattenOn")
620
+ if (l === "stateFlattenOn")
630
621
  return (r) => {
631
622
  const o = m;
632
623
  f.clear(), k++;
@@ -636,151 +627,151 @@ function ne(e, i, S, u) {
636
627
  return s(
637
628
  a,
638
629
  [...n, "[*]", r],
639
- I
630
+ h
640
631
  );
641
632
  };
642
- if (d === "index")
633
+ if (l === "index")
643
634
  return (r) => {
644
635
  const o = m[r];
645
636
  return s(o, [...n, r.toString()]);
646
637
  };
647
- if (d === "last")
638
+ if (l === "last")
648
639
  return () => {
649
640
  const r = t.getState().getNestedState(e, n);
650
641
  if (r.length === 0) return;
651
642
  const o = r.length - 1, a = r[o], c = [...n, o.toString()];
652
643
  return s(a, c);
653
644
  };
654
- if (d === "insert")
655
- return (r) => (h(n), se(i, r, n, e), s(
645
+ if (l === "insert")
646
+ return (r) => (I(n), se(i, r, n, e), s(
656
647
  t.getState().getNestedState(e, n),
657
648
  n
658
649
  ));
659
- if (d === "uniqueInsert")
650
+ if (l === "uniqueInsert")
660
651
  return (r, o, a) => {
661
652
  const c = t.getState().getNestedState(e, n), p = Z(r) ? r(c) : r;
662
653
  let y = null;
663
654
  if (!c.some(($) => {
664
655
  if (o) {
665
- const T = o.every(
666
- (V) => L($[V], p[V])
656
+ const A = o.every(
657
+ (N) => L($[N], p[N])
667
658
  );
668
- return T && (y = $), T;
659
+ return A && (y = $), A;
669
660
  }
670
- const A = L($, p);
671
- return A && (y = $), A;
661
+ const T = L($, p);
662
+ return T && (y = $), T;
672
663
  }))
673
- h(n), se(i, p, n, e);
664
+ I(n), se(i, p, n, e);
674
665
  else if (a && y) {
675
- const $ = a(y), A = c.map(
676
- (T) => L(T, y) ? $ : T
666
+ const $ = a(y), T = c.map(
667
+ (A) => L(A, y) ? $ : A
677
668
  );
678
- h(n), Q(i, A, n);
669
+ I(n), Q(i, T, n);
679
670
  }
680
671
  };
681
- if (d === "cut")
672
+ if (l === "cut")
682
673
  return (r, o) => {
683
674
  if (!o?.waitForSync)
684
- return h(n), K(i, n, e, r), s(
675
+ return I(n), K(i, n, e, r), s(
685
676
  t.getState().getNestedState(e, n),
686
677
  n
687
678
  );
688
679
  };
689
- if (d === "cutByValue")
680
+ if (l === "cutByValue")
690
681
  return (r) => {
691
682
  for (let o = 0; o < m.length; o++)
692
683
  m[o] === r && K(i, n, e, o);
693
684
  };
694
- if (d === "toggleByValue")
685
+ if (l === "toggleByValue")
695
686
  return (r) => {
696
687
  const o = m.findIndex((a) => a === r);
697
688
  o > -1 ? K(i, n, e, o) : se(i, r, n, e);
698
689
  };
699
- if (d === "stateFind")
690
+ if (l === "stateFind")
700
691
  return (r) => {
701
- const a = l().find(
692
+ const a = d().find(
702
693
  ({ item: p }, y) => r(p, y)
703
694
  );
704
695
  if (!a) return;
705
696
  const c = [...n, a.originalIndex.toString()];
706
- return s(a.item, c, I);
697
+ return s(a.item, c, h);
707
698
  };
708
- if (d === "findWith")
699
+ if (l === "findWith")
709
700
  return (r, o) => {
710
- const c = l().find(
701
+ const c = d().find(
711
702
  ({ item: y }) => y[r] === o
712
703
  );
713
704
  if (!c) return;
714
705
  const p = [...n, c.originalIndex.toString()];
715
- return s(c.item, p, I);
706
+ return s(c.item, p, h);
716
707
  };
717
708
  }
718
709
  const X = n[n.length - 1];
719
710
  if (!isNaN(Number(X))) {
720
- const l = n.slice(0, -1), r = t.getState().getNestedState(e, l);
721
- if (Array.isArray(r) && d === "cut")
711
+ const d = n.slice(0, -1), r = t.getState().getNestedState(e, d);
712
+ if (Array.isArray(r) && l === "cut")
722
713
  return () => K(
723
714
  i,
724
- l,
715
+ d,
725
716
  e,
726
717
  Number(X)
727
718
  );
728
719
  }
729
- if (d === "get")
720
+ if (l === "get")
730
721
  return () => t.getState().getNestedState(e, n);
731
- if (d === "$derive")
732
- return (l) => ce({
722
+ if (l === "$derive")
723
+ return (d) => ce({
733
724
  _stateKey: e,
734
725
  _path: n,
735
- _effect: l.toString()
726
+ _effect: d.toString()
736
727
  });
737
- if (d === "$derive")
738
- return (l) => ce({
728
+ if (l === "$derive")
729
+ return (d) => ce({
739
730
  _stateKey: e,
740
731
  _path: n,
741
- _effect: l.toString()
732
+ _effect: d.toString()
742
733
  });
743
- if (d === "$get")
734
+ if (l === "$get")
744
735
  return () => ce({
745
736
  _stateKey: e,
746
737
  _path: n
747
738
  });
748
- if (d === "lastSynced") {
749
- const l = `${e}:${n.join(".")}`;
750
- return t.getState().getSyncInfo(l);
739
+ if (l === "lastSynced") {
740
+ const d = `${e}:${n.join(".")}`;
741
+ return t.getState().getSyncInfo(d);
751
742
  }
752
- if (d == "getLocalStorage")
753
- return (l) => ae(u + "-" + e + "-" + l);
754
- if (d === "_selected") {
755
- const l = n.slice(0, -1), r = l.join("."), o = t.getState().getNestedState(e, l);
743
+ if (l == "getLocalStorage")
744
+ return (d) => ae(u + "-" + e + "-" + d);
745
+ if (l === "_selected") {
746
+ const d = n.slice(0, -1), r = d.join("."), o = t.getState().getNestedState(e, d);
756
747
  return Array.isArray(o) ? Number(n[n.length - 1]) === t.getState().getSelectedIndex(e, r) : void 0;
757
748
  }
758
- if (d === "setSelected")
759
- return (l) => {
749
+ if (l === "setSelected")
750
+ return (d) => {
760
751
  const r = n.slice(0, -1), o = Number(n[n.length - 1]), a = r.join(".");
761
- l ? t.getState().setSelectedIndex(e, a, o) : t.getState().setSelectedIndex(e, a, void 0);
752
+ d ? t.getState().setSelectedIndex(e, a, o) : t.getState().setSelectedIndex(e, a, void 0);
762
753
  const c = t.getState().getNestedState(e, [...r]);
763
- Q(i, c, r), h(r);
754
+ Q(i, c, r), I(r);
764
755
  };
765
- if (d === "toggleSelected")
756
+ if (l === "toggleSelected")
766
757
  return () => {
767
- const l = n.slice(0, -1), r = Number(n[n.length - 1]), o = l.join("."), a = t.getState().getSelectedIndex(e, o);
758
+ const d = n.slice(0, -1), r = Number(n[n.length - 1]), o = d.join("."), a = t.getState().getSelectedIndex(e, o);
768
759
  t.getState().setSelectedIndex(
769
760
  e,
770
761
  o,
771
762
  a === r ? void 0 : r
772
763
  );
773
- const c = t.getState().getNestedState(e, [...l]);
774
- Q(i, c, l), h(l);
764
+ const c = t.getState().getNestedState(e, [...d]);
765
+ Q(i, c, d), I(d);
775
766
  };
776
767
  if (n.length == 0) {
777
- if (d === "applyJsonPatch")
778
- return (l) => {
779
- const r = t.getState().cogsStateStore[e], a = be(r, l).newDocument, c = H(e), p = c?.middleware, y = t.getState().setInitialStateOptions;
768
+ if (l === "applyJsonPatch")
769
+ return (d) => {
770
+ const r = t.getState().cogsStateStore[e], a = Oe(r, d).newDocument, c = H(e), p = c?.middleware, y = t.getState().setInitialStateOptions;
780
771
  c && p && y(e, {
781
772
  ...c,
782
773
  middleware: void 0
783
- }), Ee(
774
+ }), ke(
784
775
  e,
785
776
  t.getState().initialStateGlobal[e],
786
777
  a,
@@ -794,141 +785,141 @@ function ne(e, i, S, u) {
794
785
  const w = t.getState().stateComponents.get(e);
795
786
  if (console.log("component update logic stateEntry", w), !w) return;
796
787
  const $ = /* @__PURE__ */ new Set();
797
- console.log("component update logic pathsToCheck", $), Array.isArray(r) && Array.isArray(a) && r.length !== a.length && $.add(""), console.log("component update logic pathsToCheck", $), l.forEach((A) => {
798
- const V = A.path.slice(1).split("/");
799
- if (A.op === "add" || A.op === "remove") {
800
- const b = V[V.length - 1];
788
+ console.log("component update logic pathsToCheck", $), Array.isArray(r) && Array.isArray(a) && r.length !== a.length && $.add(""), console.log("component update logic pathsToCheck", $), d.forEach((T) => {
789
+ const N = T.path.slice(1).split("/");
790
+ if (T.op === "add" || T.op === "remove") {
791
+ const b = N[N.length - 1];
801
792
  if (!isNaN(parseInt(b))) {
802
- const x = V.slice(0, -1).join(".");
803
- $.add(x), x === "" && $.add("");
793
+ const F = N.slice(0, -1).join(".");
794
+ $.add(F), F === "" && $.add("");
804
795
  }
805
796
  }
806
- let R = "";
807
- V.forEach((b, x) => {
808
- x > 0 && (R += "."), R += b, $.add(R);
797
+ let O = "";
798
+ N.forEach((b, F) => {
799
+ F > 0 && (O += "."), O += b, $.add(O);
809
800
  }), $.add("");
810
801
  });
811
802
  for (const [
812
- A,
813
- T
803
+ T,
804
+ A
814
805
  ] of w.components.entries()) {
815
- console.log("component update logic component", T);
816
- let V = !1;
817
- const R = Array.isArray(T.reactiveType) ? T.reactiveType : [T.reactiveType || "component"];
818
- if (!R.includes("none")) {
819
- if (R.includes("all")) {
820
- T.forceUpdate();
806
+ console.log("component update logic component", A);
807
+ let N = !1;
808
+ const O = Array.isArray(A.reactiveType) ? A.reactiveType : [A.reactiveType || "component"];
809
+ if (!O.includes("none")) {
810
+ if (O.includes("all")) {
811
+ A.forceUpdate();
821
812
  continue;
822
813
  }
823
- if (R.includes("component"))
824
- for (const b of T.paths) {
814
+ if (O.includes("component"))
815
+ for (const b of A.paths) {
825
816
  if ($.has(b)) {
826
- V = !0;
817
+ N = !0;
827
818
  break;
828
819
  }
829
- for (const x of $)
830
- if (x.startsWith(b + ".") || b === "" && x !== "") {
831
- V = !0;
820
+ for (const F of $)
821
+ if (F.startsWith(b + ".") || b === "" && F !== "") {
822
+ N = !0;
832
823
  break;
833
824
  }
834
- if (V) break;
825
+ if (N) break;
835
826
  }
836
- if (!V && R.includes("deps") && T.depsFunction) {
837
- const b = T.depsFunction(a);
838
- let x = !1;
839
- typeof b == "boolean" ? b && (x = !0) : L(T.deps, b) || (T.deps = b, x = !0), x && (V = !0);
827
+ if (!N && O.includes("deps") && A.depsFunction) {
828
+ const b = A.depsFunction(a);
829
+ let F = !1;
830
+ typeof b == "boolean" ? b && (F = !0) : L(A.deps, b) || (A.deps = b, F = !0), F && (N = !0);
840
831
  }
841
- V && T.forceUpdate();
832
+ N && A.forceUpdate();
842
833
  }
843
834
  }
844
835
  };
845
- if (d === "validateZodSchema")
836
+ if (l === "validateZodSchema")
846
837
  return () => {
847
- const l = t.getState().getInitialOptions(e)?.validation, r = t.getState().addValidationError;
848
- if (!l?.zodSchema)
838
+ const d = t.getState().getInitialOptions(e)?.validation, r = t.getState().addValidationError;
839
+ if (!d?.zodSchema)
849
840
  throw new Error("Zod schema not found");
850
- if (!l?.key)
841
+ if (!d?.key)
851
842
  throw new Error("Validation key not found");
852
- B(l.key);
843
+ B(d.key);
853
844
  const o = t.getState().cogsStateStore[e];
854
845
  try {
855
- const a = t.getState().getValidationErrors(l.key);
846
+ const a = t.getState().getValidationErrors(d.key);
856
847
  a && a.length > 0 && a.forEach(([p]) => {
857
- p && p.startsWith(l.key) && B(p);
848
+ p && p.startsWith(d.key) && B(p);
858
849
  });
859
- const c = l.zodSchema.safeParse(o);
850
+ const c = d.zodSchema.safeParse(o);
860
851
  return c.success ? !0 : (c.error.errors.forEach((y) => {
861
- const w = y.path, $ = y.message, A = [l.key, ...w].join(".");
862
- r(A, $);
852
+ const w = y.path, $ = y.message, T = [d.key, ...w].join(".");
853
+ r(T, $);
863
854
  }), oe(e), !1);
864
855
  } catch (a) {
865
856
  return console.error("Zod schema validation failed", a), !1;
866
857
  }
867
858
  };
868
- if (d === "_componentId") return S;
869
- if (d === "getComponents")
859
+ if (l === "_componentId") return S;
860
+ if (l === "getComponents")
870
861
  return () => t().stateComponents.get(e);
871
- if (d === "getAllFormRefs")
872
- return () => me.getState().getFormRefsByStateKey(e);
873
- if (d === "_initialState")
862
+ if (l === "getAllFormRefs")
863
+ return () => ye.getState().getFormRefsByStateKey(e);
864
+ if (l === "_initialState")
874
865
  return t.getState().initialStateGlobal[e];
875
- if (d === "_serverState")
866
+ if (l === "_serverState")
876
867
  return t.getState().serverState[e];
877
- if (d === "_isLoading")
868
+ if (l === "_isLoading")
878
869
  return t.getState().isLoadingGlobal[e];
879
- if (d === "revertToInitialState")
870
+ if (l === "revertToInitialState")
880
871
  return v.revertToInitialState;
881
- if (d === "updateInitialState") return v.updateInitialState;
882
- if (d === "removeValidation") return v.removeValidation;
872
+ if (l === "updateInitialState") return v.updateInitialState;
873
+ if (l === "removeValidation") return v.removeValidation;
883
874
  }
884
- if (d === "getFormRef")
885
- return () => me.getState().getFormRef(e + "." + n.join("."));
886
- if (d === "validationWrapper")
875
+ if (l === "getFormRef")
876
+ return () => ye.getState().getFormRef(e + "." + n.join("."));
877
+ if (l === "validationWrapper")
887
878
  return ({
888
- children: l,
879
+ children: d,
889
880
  hideMessage: r
890
- }) => /* @__PURE__ */ Se(
891
- _e,
881
+ }) => /* @__PURE__ */ me(
882
+ Pe,
892
883
  {
893
884
  formOpts: r ? { validation: { message: "" } } : void 0,
894
885
  path: n,
895
886
  validationKey: t.getState().getInitialOptions(e)?.validation?.key || "",
896
887
  stateKey: e,
897
- validIndices: I?.validIndices,
898
- children: l
888
+ validIndices: h?.validIndices,
889
+ children: d
899
890
  }
900
891
  );
901
- if (d === "_stateKey") return e;
902
- if (d === "_path") return n;
903
- if (d === "_isServerSynced") return v._isServerSynced;
904
- if (d === "update")
905
- return (l, r) => {
892
+ if (l === "_stateKey") return e;
893
+ if (l === "_path") return n;
894
+ if (l === "_isServerSynced") return v._isServerSynced;
895
+ if (l === "update")
896
+ return (d, r) => {
906
897
  if (r?.debounce)
907
- Ve(() => {
908
- Q(i, l, n, "");
898
+ Ce(() => {
899
+ Q(i, d, n, "");
909
900
  const o = t.getState().getNestedState(e, n);
910
901
  r?.afterUpdate && r.afterUpdate(o);
911
902
  }, r.debounce);
912
903
  else {
913
- Q(i, l, n, "");
904
+ Q(i, d, n, "");
914
905
  const o = t.getState().getNestedState(e, n);
915
906
  r?.afterUpdate && r.afterUpdate(o);
916
907
  }
917
- h(n);
908
+ I(n);
918
909
  };
919
- if (d === "formElement")
920
- return (l, r) => /* @__PURE__ */ Se(
921
- Ce,
910
+ if (l === "formElement")
911
+ return (d, r) => /* @__PURE__ */ me(
912
+ be,
922
913
  {
923
914
  setState: i,
924
915
  stateKey: e,
925
916
  path: n,
926
- child: l,
917
+ child: d,
927
918
  formOpts: r
928
919
  }
929
920
  );
930
- const J = [...n, d], P = t.getState().getNestedState(e, J);
931
- return s(P, J, I);
921
+ const J = [...n, l], P = t.getState().getNestedState(e, J);
922
+ return s(P, J, h);
932
923
  }
933
924
  }, D = new Proxy(_, C);
934
925
  return f.set(M, {
@@ -941,9 +932,9 @@ function ne(e, i, S, u) {
941
932
  );
942
933
  }
943
934
  function ce(e) {
944
- return re(We, { proxy: e });
935
+ return re(Le, { proxy: e });
945
936
  }
946
- function De({
937
+ function Ge({
947
938
  proxy: e,
948
939
  rebuildStateShape: i
949
940
  }) {
@@ -952,41 +943,41 @@ function De({
952
943
  S,
953
944
  e._path
954
945
  ).stateMapNoRender(
955
- (f, k, h, v, s) => e._mapFn(f, k, h, v, s)
946
+ (f, k, I, v, s) => e._mapFn(f, k, I, v, s)
956
947
  ) : null;
957
948
  }
958
- function We({
949
+ function Le({
959
950
  proxy: e
960
951
  }) {
961
952
  const i = ee(null), S = `${e._stateKey}-${e._path.join(".")}`;
962
953
  return de(() => {
963
954
  const u = i.current;
964
955
  if (!u || !u.parentElement) return;
965
- const f = u.parentElement, h = Array.from(f.childNodes).indexOf(u);
956
+ const f = u.parentElement, I = Array.from(f.childNodes).indexOf(u);
966
957
  let v = f.getAttribute("data-parent-id");
967
958
  v || (v = `parent-${crypto.randomUUID()}`, f.setAttribute("data-parent-id", v));
968
959
  const m = {
969
960
  instanceId: `instance-${crypto.randomUUID()}`,
970
961
  parentId: v,
971
- position: h,
962
+ position: I,
972
963
  effect: e._effect
973
964
  };
974
965
  t.getState().addSignalElement(S, m);
975
966
  const n = t.getState().getNestedState(e._stateKey, e._path);
976
- let I;
967
+ let h;
977
968
  if (e._effect)
978
969
  try {
979
- I = new Function(
970
+ h = new Function(
980
971
  "state",
981
972
  `return (${e._effect})(state)`
982
973
  )(n);
983
974
  } catch (_) {
984
- console.error("Error evaluating effect function during mount:", _), I = n;
975
+ console.error("Error evaluating effect function during mount:", _), h = n;
985
976
  }
986
977
  else
987
- I = n;
988
- I !== null && typeof I == "object" && (I = JSON.stringify(I));
989
- const M = document.createTextNode(String(I));
978
+ h = n;
979
+ h !== null && typeof h == "object" && (h = JSON.stringify(h));
980
+ const M = document.createTextNode(String(h));
990
981
  u.replaceWith(M);
991
982
  }, [e._stateKey, e._path.join("."), e._effect]), re("span", {
992
983
  ref: i,
@@ -994,8 +985,8 @@ function We({
994
985
  "data-signal-id": S
995
986
  });
996
987
  }
997
- function tt(e) {
998
- const i = Te(
988
+ function rt(e) {
989
+ const i = Ne(
999
990
  (S) => {
1000
991
  const u = t.getState().stateComponents.get(e._stateKey) || {
1001
992
  components: /* @__PURE__ */ new Map()
@@ -1011,10 +1002,10 @@ function tt(e) {
1011
1002
  }
1012
1003
  export {
1013
1004
  ce as $cogsSignal,
1014
- tt as $cogsSignalStore,
1015
- Qe as addStateOptions,
1016
- Ke as createCogsState,
1017
- et as notifyComponent,
1018
- Me as useCogsStateFn
1005
+ rt as $cogsSignalStore,
1006
+ et as addStateOptions,
1007
+ tt as createCogsState,
1008
+ nt as notifyComponent,
1009
+ We as useCogsStateFn
1019
1010
  };
1020
1011
  //# sourceMappingURL=CogsState.jsx.map