cogsbox-state 0.5.180 → 0.5.183

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.
Files changed (55) hide show
  1. package/dist/CogsState.jsx +333 -334
  2. package/dist/CogsState.jsx.map +1 -1
  3. package/dist/TRPCValidationLink.js +1 -1
  4. package/dist/store.js +1 -1
  5. package/dist/useValidateZodPath.js +9 -8
  6. package/dist/useValidateZodPath.js.map +1 -1
  7. package/package.json +4 -3
  8. package/src/CogsState.tsx +2444 -0
  9. package/src/CogsStateClient.tsx +25 -0
  10. package/src/Functions.tsx +409 -0
  11. package/src/TRPCValidationLink.ts +70 -0
  12. package/src/index.ts +4 -0
  13. package/src/store.ts +616 -0
  14. package/src/useValidateZodPath.ts +231 -0
  15. package/src/utility.ts +423 -0
  16. package/dist/node_modules/@trpc/server/dist/observable/observable.js +0 -38
  17. package/dist/node_modules/@trpc/server/dist/observable/observable.js.map +0 -1
  18. package/dist/node_modules/copy-anything/dist/index.js +0 -27
  19. package/dist/node_modules/copy-anything/dist/index.js.map +0 -1
  20. package/dist/node_modules/is-what/dist/index.js +0 -18
  21. package/dist/node_modules/is-what/dist/index.js.map +0 -1
  22. package/dist/node_modules/superjson/dist/accessDeep.js +0 -92
  23. package/dist/node_modules/superjson/dist/accessDeep.js.map +0 -1
  24. package/dist/node_modules/superjson/dist/class-registry.js +0 -16
  25. package/dist/node_modules/superjson/dist/class-registry.js.map +0 -1
  26. package/dist/node_modules/superjson/dist/custom-transformer-registry.js +0 -19
  27. package/dist/node_modules/superjson/dist/custom-transformer-registry.js.map +0 -1
  28. package/dist/node_modules/superjson/dist/double-indexed-kv.js +0 -21
  29. package/dist/node_modules/superjson/dist/double-indexed-kv.js.map +0 -1
  30. package/dist/node_modules/superjson/dist/index.js +0 -75
  31. package/dist/node_modules/superjson/dist/index.js.map +0 -1
  32. package/dist/node_modules/superjson/dist/is.js +0 -24
  33. package/dist/node_modules/superjson/dist/is.js.map +0 -1
  34. package/dist/node_modules/superjson/dist/pathstringifier.js +0 -24
  35. package/dist/node_modules/superjson/dist/pathstringifier.js.map +0 -1
  36. package/dist/node_modules/superjson/dist/plainer.js +0 -102
  37. package/dist/node_modules/superjson/dist/plainer.js.map +0 -1
  38. package/dist/node_modules/superjson/dist/registry.js +0 -22
  39. package/dist/node_modules/superjson/dist/registry.js.map +0 -1
  40. package/dist/node_modules/superjson/dist/transformer.js +0 -140
  41. package/dist/node_modules/superjson/dist/transformer.js.map +0 -1
  42. package/dist/node_modules/superjson/dist/util.js +0 -39
  43. package/dist/node_modules/superjson/dist/util.js.map +0 -1
  44. package/dist/node_modules/uuid/dist/esm-browser/native.js +0 -7
  45. package/dist/node_modules/uuid/dist/esm-browser/native.js.map +0 -1
  46. package/dist/node_modules/uuid/dist/esm-browser/rng.js +0 -11
  47. package/dist/node_modules/uuid/dist/esm-browser/rng.js.map +0 -1
  48. package/dist/node_modules/uuid/dist/esm-browser/stringify.js +0 -10
  49. package/dist/node_modules/uuid/dist/esm-browser/stringify.js.map +0 -1
  50. package/dist/node_modules/uuid/dist/esm-browser/v4.js +0 -14
  51. package/dist/node_modules/uuid/dist/esm-browser/v4.js.map +0 -1
  52. package/dist/node_modules/zustand/esm/react.js +0 -20
  53. package/dist/node_modules/zustand/esm/react.js.map +0 -1
  54. package/dist/node_modules/zustand/esm/vanilla.js +0 -15
  55. package/dist/node_modules/zustand/esm/vanilla.js.map +0 -1
@@ -1,61 +1,61 @@
1
1
  "use client";
2
2
  import { jsx as me } from "react/jsx-runtime";
3
- import { useState as de, useRef as Q, useEffect as ue, useLayoutEffect as we, useMemo as Ne, createElement as te, useSyncExternalStore as Ve, startTransition as ke } from "react";
4
- import { transformStateFunc as Te, isDeepEqual as M, isFunction as L, getNestedValue as p, getDifferences as _e, debounce as Ae } from "./utility.js";
5
- import { pushFunc as ce, updateFn as Z, cutFunc as X, ValidationWrapper as xe, FormControlComponent as Ce } from "./Functions.jsx";
6
- import be from "./node_modules/superjson/dist/index.js";
3
+ import { useState as de, useRef as Q, useEffect as ue, useLayoutEffect as Ne, useMemo as he, createElement as te, useSyncExternalStore as ke, startTransition as Ve } from "react";
4
+ import { transformStateFunc as Ae, isDeepEqual as G, isFunction as L, getNestedValue as D, getDifferences as _e, debounce as xe } from "./utility.js";
5
+ import { pushFunc as ce, updateFn as Z, cutFunc as X, ValidationWrapper as Te, FormControlComponent as Ce } from "./Functions.jsx";
6
+ import be from "superjson";
7
+ import { v4 as ge } from "uuid";
7
8
  import "zod";
8
9
  import { getGlobalStore as a, formRefStore as ye } from "./store.js";
9
10
  import { useCogsConfig as $e } from "./CogsStateClient.jsx";
10
- import ge from "./node_modules/uuid/dist/esm-browser/v4.js";
11
- function ve(e, s) {
12
- const m = a.getState().getInitialOptions, d = a.getState().setInitialStateOptions, u = m(e) || {};
11
+ function ve(e, c) {
12
+ const S = a.getState().getInitialOptions, d = a.getState().setInitialStateOptions, u = S(e) || {};
13
13
  d(e, {
14
14
  ...u,
15
- ...s
15
+ ...c
16
16
  });
17
17
  }
18
18
  function Ie({
19
19
  stateKey: e,
20
- options: s,
21
- initialOptionsPart: m
20
+ options: c,
21
+ initialOptionsPart: S
22
22
  }) {
23
- const d = z(e) || {}, u = m[e] || {}, I = a.getState().setInitialStateOptions, E = { ...u, ...d };
24
- let S = !1;
25
- if (s)
26
- for (const l in s)
27
- E.hasOwnProperty(l) ? (l == "localStorage" && s[l] && E[l].key !== s[l]?.key && (S = !0, E[l] = s[l]), l == "initialState" && s[l] && E[l] !== s[l] && // Different references
28
- !M(E[l], s[l]) && (S = !0, E[l] = s[l])) : (S = !0, E[l] = s[l]);
29
- S && I(e, E);
23
+ const d = z(e) || {}, u = S[e] || {}, I = a.getState().setInitialStateOptions, E = { ...u, ...d };
24
+ let f = !1;
25
+ if (c)
26
+ for (const l in c)
27
+ E.hasOwnProperty(l) ? (l == "localStorage" && c[l] && E[l].key !== c[l]?.key && (f = !0, E[l] = c[l]), l == "initialState" && c[l] && E[l] !== c[l] && // Different references
28
+ !G(E[l], c[l]) && (f = !0, E[l] = c[l])) : (f = !0, E[l] = c[l]);
29
+ f && I(e, E);
30
30
  }
31
- function Xe(e, { formElements: s, validation: m }) {
32
- return { initialState: e, formElements: s, validation: m };
31
+ function Xe(e, { formElements: c, validation: S }) {
32
+ return { initialState: e, formElements: c, validation: S };
33
33
  }
34
- const Qe = (e, s) => {
35
- let m = e;
36
- const [d, u] = Te(m);
37
- (Object.keys(u).length > 0 || s && Object.keys(s).length > 0) && Object.keys(u).forEach((S) => {
38
- u[S] = u[S] || {}, u[S].formElements = {
39
- ...s?.formElements,
34
+ const Qe = (e, c) => {
35
+ let S = e;
36
+ const [d, u] = Ae(S);
37
+ (Object.keys(u).length > 0 || c && Object.keys(c).length > 0) && Object.keys(u).forEach((f) => {
38
+ u[f] = u[f] || {}, u[f].formElements = {
39
+ ...c?.formElements,
40
40
  // Global defaults first
41
- ...s?.validation,
42
- ...u[S].formElements || {}
41
+ ...c?.validation,
42
+ ...u[f].formElements || {}
43
43
  // State-specific overrides
44
- }, z(S) || a.getState().setInitialStateOptions(S, u[S]);
44
+ }, z(f) || a.getState().setInitialStateOptions(f, u[f]);
45
45
  }), a.getState().setInitialStates(d), a.getState().setCreatedState(d);
46
- const I = (S, l) => {
47
- const [f] = de(l?.componentId ?? ge());
46
+ const I = (f, l) => {
47
+ const [m] = de(l?.componentId ?? ge());
48
48
  Ie({
49
- stateKey: S,
49
+ stateKey: f,
50
50
  options: l,
51
51
  initialOptionsPart: u
52
52
  });
53
- const t = a.getState().cogsStateStore[S] || d[S], v = l?.modifyState ? l.modifyState(t) : t, [T, b] = De(
53
+ const t = a.getState().cogsStateStore[f] || d[f], v = l?.modifyState ? l.modifyState(t) : t, [A, b] = Me(
54
54
  v,
55
55
  {
56
- stateKey: S,
56
+ stateKey: f,
57
57
  syncUpdate: l?.syncUpdate,
58
- componentId: f,
58
+ componentId: m,
59
59
  localStorage: l?.localStorage,
60
60
  middleware: l?.middleware,
61
61
  enabledSync: l?.enabledSync,
@@ -68,56 +68,56 @@ const Qe = (e, s) => {
68
68
  );
69
69
  return b;
70
70
  };
71
- function E(S, l) {
72
- Ie({ stateKey: S, options: l, initialOptionsPart: u }), l.localStorage && Re(S, l), re(S);
71
+ function E(f, l) {
72
+ Ie({ stateKey: f, options: l, initialOptionsPart: u }), l.localStorage && Re(f, l), re(f);
73
73
  }
74
74
  return { useCogsState: I, setCogsOptions: E };
75
75
  }, {
76
76
  setUpdaterState: K,
77
77
  setState: q,
78
78
  getInitialOptions: z,
79
- getKeyState: he,
79
+ getKeyState: we,
80
80
  getValidationErrors: Pe,
81
- setStateLog: Oe,
81
+ setStateLog: je,
82
82
  updateInitialStateGlobal: fe,
83
83
  addValidationError: Fe,
84
- removeValidationError: G,
85
- setServerSyncActions: je
86
- } = a.getState(), Ee = (e, s, m, d, u) => {
87
- m?.log && console.log(
84
+ removeValidationError: p,
85
+ setServerSyncActions: Oe
86
+ } = a.getState(), Ee = (e, c, S, d, u) => {
87
+ S?.log && console.log(
88
88
  "saving to localstorage",
89
- s,
90
- m.localStorage?.key,
89
+ c,
90
+ S.localStorage?.key,
91
91
  d
92
92
  );
93
- const I = L(m?.localStorage?.key) ? m.localStorage?.key(e) : m?.localStorage?.key;
93
+ const I = L(S?.localStorage?.key) ? S.localStorage?.key(e) : S?.localStorage?.key;
94
94
  if (I && d) {
95
- const E = `${d}-${s}-${I}`;
96
- let S;
95
+ const E = `${d}-${c}-${I}`;
96
+ let f;
97
97
  try {
98
- S = ne(E)?.lastSyncedWithServer;
98
+ f = ne(E)?.lastSyncedWithServer;
99
99
  } catch {
100
100
  }
101
101
  const l = {
102
102
  state: e,
103
103
  lastUpdated: Date.now(),
104
- lastSyncedWithServer: u ?? S
105
- }, f = be.serialize(l);
104
+ lastSyncedWithServer: u ?? f
105
+ }, m = be.serialize(l);
106
106
  window.localStorage.setItem(
107
107
  E,
108
- JSON.stringify(f.json)
108
+ JSON.stringify(m.json)
109
109
  );
110
110
  }
111
111
  }, ne = (e) => {
112
112
  if (!e) return null;
113
113
  try {
114
- const s = window.localStorage.getItem(e);
115
- return s ? JSON.parse(s) : null;
116
- } catch (s) {
117
- return console.error("Error loading from localStorage:", s), null;
114
+ const c = window.localStorage.getItem(e);
115
+ return c ? JSON.parse(c) : null;
116
+ } catch (c) {
117
+ return console.error("Error loading from localStorage:", c), null;
118
118
  }
119
- }, Re = (e, s) => {
120
- const m = a.getState().cogsStateStore[e], { sessionId: d } = $e(), u = L(s?.localStorage?.key) ? s.localStorage.key(m) : s?.localStorage?.key;
119
+ }, Re = (e, c) => {
120
+ const S = a.getState().cogsStateStore[e], { sessionId: d } = $e(), u = L(c?.localStorage?.key) ? c.localStorage.key(S) : c?.localStorage?.key;
121
121
  if (u && d) {
122
122
  const I = ne(
123
123
  `${d}-${e}-${u}`
@@ -126,51 +126,51 @@ const Qe = (e, s) => {
126
126
  return q(e, I.state), re(e), !0;
127
127
  }
128
128
  return !1;
129
- }, Ue = (e, s, m, d, u, I) => {
129
+ }, Ue = (e, c, S, d, u, I) => {
130
130
  const E = {
131
- initialState: s,
131
+ initialState: c,
132
132
  updaterState: ee(
133
133
  e,
134
134
  d,
135
135
  u,
136
136
  I
137
137
  ),
138
- state: m
138
+ state: S
139
139
  };
140
140
  fe(e, E.initialState), K(e, E.updaterState), q(e, E.state);
141
141
  }, re = (e) => {
142
- const s = a.getState().stateComponents.get(e);
143
- if (!s) return;
144
- const m = /* @__PURE__ */ new Set();
145
- s.components.forEach((d) => {
146
- (d ? Array.isArray(d.reactiveType) ? d.reactiveType : [d.reactiveType || "component"] : null)?.includes("none") || m.add(() => d.forceUpdate());
142
+ const c = a.getState().stateComponents.get(e);
143
+ if (!c) return;
144
+ const S = /* @__PURE__ */ new Set();
145
+ c.components.forEach((d) => {
146
+ (d ? Array.isArray(d.reactiveType) ? d.reactiveType : [d.reactiveType || "component"] : null)?.includes("none") || S.add(() => d.forceUpdate());
147
147
  }), queueMicrotask(() => {
148
- m.forEach((d) => d());
148
+ S.forEach((d) => d());
149
149
  });
150
- }, Ke = (e, s) => {
151
- const m = a.getState().stateComponents.get(e);
152
- if (m) {
153
- const d = `${e}////${s}`, u = m.components.get(d);
150
+ }, Ke = (e, c) => {
151
+ const S = a.getState().stateComponents.get(e);
152
+ if (S) {
153
+ const d = `${e}////${c}`, u = S.components.get(d);
154
154
  if ((u ? Array.isArray(u.reactiveType) ? u.reactiveType : [u.reactiveType || "component"] : null)?.includes("none"))
155
155
  return;
156
156
  u && u.forceUpdate();
157
157
  }
158
- }, pe = (e, s, m, d) => {
158
+ }, De = (e, c, S, d) => {
159
159
  switch (e) {
160
160
  case "update":
161
161
  return {
162
- oldValue: p(s, d),
163
- newValue: p(m, d)
162
+ oldValue: D(c, d),
163
+ newValue: D(S, d)
164
164
  };
165
165
  case "insert":
166
166
  return {
167
167
  oldValue: null,
168
168
  // or undefined
169
- newValue: p(m, d)
169
+ newValue: D(S, d)
170
170
  };
171
171
  case "cut":
172
172
  return {
173
- oldValue: p(s, d),
173
+ oldValue: D(c, d),
174
174
  newValue: null
175
175
  // or undefined
176
176
  };
@@ -178,23 +178,23 @@ const Qe = (e, s) => {
178
178
  return { oldValue: null, newValue: null };
179
179
  }
180
180
  };
181
- function De(e, {
182
- stateKey: s,
183
- serverSync: m,
181
+ function Me(e, {
182
+ stateKey: c,
183
+ serverSync: S,
184
184
  localStorage: d,
185
185
  formElements: u,
186
186
  middleware: I,
187
187
  reactiveDeps: E,
188
- reactiveType: S,
188
+ reactiveType: f,
189
189
  componentId: l,
190
- initialState: f,
190
+ initialState: m,
191
191
  syncUpdate: t,
192
192
  dependencies: v,
193
- serverState: T
193
+ serverState: A
194
194
  } = {}) {
195
- const [b, j] = de({}), { sessionId: w } = $e();
196
- let R = !s;
197
- const [r] = de(s ?? ge()), J = a.getState().stateLog[r], H = Q(/* @__PURE__ */ new Set()), W = Q(l ?? ge()), n = Q(
195
+ const [b, O] = de({}), { sessionId: N } = $e();
196
+ let R = !c;
197
+ const [r] = de(c ?? ge()), B = a.getState().stateLog[r], H = Q(/* @__PURE__ */ new Set()), W = Q(l ?? ge()), n = Q(
198
198
  null
199
199
  );
200
200
  n.current = z(r) ?? null, ue(() => {
@@ -203,174 +203,174 @@ function De(e, {
203
203
  ...i,
204
204
  [t.path[0]]: t.newValue
205
205
  }));
206
- const c = `${t.stateKey}:${t.path.join(".")}`;
207
- a.getState().setSyncInfo(c, {
206
+ const s = `${t.stateKey}:${t.path.join(".")}`;
207
+ a.getState().setSyncInfo(s, {
208
208
  timeStamp: t.timeStamp,
209
209
  userId: t.userId
210
210
  });
211
211
  }
212
212
  }, [t]), ue(() => {
213
- if (f) {
213
+ if (m) {
214
214
  ve(r, {
215
- initialState: f
215
+ initialState: m
216
216
  });
217
- const c = n.current, y = c?.serverState?.id !== void 0 && c?.serverState?.status === "success" && c?.serverState?.data, V = a.getState().initialStateGlobal[r];
218
- if (!(V && !M(V, f) || !V) && !y)
217
+ const s = n.current, y = s?.serverState?.id !== void 0 && s?.serverState?.status === "success" && s?.serverState?.data, k = a.getState().initialStateGlobal[r];
218
+ if (!(k && !G(k, m) || !k) && !y)
219
219
  return;
220
220
  let $ = null;
221
- const A = L(c?.localStorage?.key) ? c?.localStorage?.key(f) : c?.localStorage?.key;
222
- A && w && ($ = ne(`${w}-${r}-${A}`));
223
- let x = f, B = !1;
221
+ const x = L(s?.localStorage?.key) ? s?.localStorage?.key(m) : s?.localStorage?.key;
222
+ x && N && ($ = ne(`${N}-${r}-${x}`));
223
+ let T = m, J = !1;
224
224
  const ae = y ? Date.now() : 0, Y = $?.lastUpdated || 0, oe = $?.lastSyncedWithServer || 0;
225
- y && ae > Y ? (x = c.serverState.data, B = !0) : $ && Y > oe && (x = $.state, c?.localStorage?.onChange && c?.localStorage?.onChange(x)), Ue(
225
+ y && ae > Y ? (T = s.serverState.data, J = !0) : $ && Y > oe && (T = $.state, s?.localStorage?.onChange && s?.localStorage?.onChange(T)), Ue(
226
226
  r,
227
- f,
228
- x,
227
+ m,
228
+ T,
229
229
  o,
230
230
  W.current,
231
- w
232
- ), B && A && w && Ee(x, r, c, w, Date.now()), re(r), (Array.isArray(S) ? S : [S || "component"]).includes("none") || j({});
231
+ N
232
+ ), J && x && N && Ee(T, r, s, N, Date.now()), re(r), (Array.isArray(f) ? f : [f || "component"]).includes("none") || O({});
233
233
  }
234
234
  }, [
235
- f,
236
- T?.status,
237
- T?.data,
235
+ m,
236
+ A?.status,
237
+ A?.data,
238
238
  ...v || []
239
- ]), we(() => {
239
+ ]), Ne(() => {
240
240
  R && ve(r, {
241
- serverSync: m,
241
+ serverSync: S,
242
242
  formElements: u,
243
- initialState: f,
243
+ initialState: m,
244
244
  localStorage: d,
245
245
  middleware: I
246
246
  });
247
- const c = `${r}////${W.current}`, i = a.getState().stateComponents.get(r) || {
247
+ const s = `${r}////${W.current}`, i = a.getState().stateComponents.get(r) || {
248
248
  components: /* @__PURE__ */ new Map()
249
249
  };
250
- return i.components.set(c, {
251
- forceUpdate: () => j({}),
250
+ return i.components.set(s, {
251
+ forceUpdate: () => O({}),
252
252
  paths: /* @__PURE__ */ new Set(),
253
253
  deps: [],
254
254
  depsFunction: E || void 0,
255
- reactiveType: S ?? ["component", "deps"]
256
- }), a.getState().stateComponents.set(r, i), j({}), () => {
255
+ reactiveType: f ?? ["component", "deps"]
256
+ }), a.getState().stateComponents.set(r, i), O({}), () => {
257
257
  const y = `${r}////${W.current}`;
258
258
  i && (i.components.delete(y), i.components.size === 0 && a.getState().stateComponents.delete(r));
259
259
  };
260
260
  }, []);
261
- const o = (c, i, y, V) => {
261
+ const o = (s, i, y, k) => {
262
262
  if (Array.isArray(i)) {
263
- const N = `${r}-${i.join(".")}`;
264
- H.current.add(N);
263
+ const h = `${r}-${i.join(".")}`;
264
+ H.current.add(h);
265
265
  }
266
- q(r, (N) => {
267
- const $ = L(c) ? c(N) : c, A = `${r}-${i.join(".")}`;
268
- if (A) {
269
- let U = !1, h = a.getState().signalDomElements.get(A);
270
- if ((!h || h.size === 0) && (y.updateType === "insert" || y.updateType === "cut")) {
271
- const P = i.slice(0, -1), F = p($, P);
266
+ q(r, (h) => {
267
+ const $ = L(s) ? s(h) : s, x = `${r}-${i.join(".")}`;
268
+ if (x) {
269
+ let U = !1, w = a.getState().signalDomElements.get(x);
270
+ if ((!w || w.size === 0) && (y.updateType === "insert" || y.updateType === "cut")) {
271
+ const P = i.slice(0, -1), F = D($, P);
272
272
  if (Array.isArray(F)) {
273
273
  U = !0;
274
274
  const _ = `${r}-${P.join(".")}`;
275
- h = a.getState().signalDomElements.get(_);
275
+ w = a.getState().signalDomElements.get(_);
276
276
  }
277
277
  }
278
- if (h) {
279
- const P = U ? p($, i.slice(0, -1)) : p($, i);
280
- h.forEach(({ parentId: F, position: _, effect: C }) => {
281
- const k = document.querySelector(
278
+ if (w) {
279
+ const P = U ? D($, i.slice(0, -1)) : D($, i);
280
+ w.forEach(({ parentId: F, position: _, effect: C }) => {
281
+ const V = document.querySelector(
282
282
  `[data-parent-id="${F}"]`
283
283
  );
284
- if (k) {
285
- const D = Array.from(k.childNodes);
286
- if (D[_]) {
287
- const O = C ? new Function("state", `return (${C})(state)`)(P) : P;
288
- D[_].textContent = String(O);
284
+ if (V) {
285
+ const M = Array.from(V.childNodes);
286
+ if (M[_]) {
287
+ const j = C ? new Function("state", `return (${C})(state)`)(P) : P;
288
+ M[_].textContent = String(j);
289
289
  }
290
290
  }
291
291
  });
292
292
  }
293
293
  }
294
- y.updateType === "update" && (V || n.current?.validation?.key) && i && G(
295
- (V || n.current?.validation?.key) + "." + i.join(".")
294
+ y.updateType === "update" && (k || n.current?.validation?.key) && i && p(
295
+ (k || n.current?.validation?.key) + "." + i.join(".")
296
296
  );
297
- const x = i.slice(0, i.length - 1);
298
- y.updateType === "cut" && n.current?.validation?.key && G(
299
- n.current?.validation?.key + "." + x.join(".")
297
+ const T = i.slice(0, i.length - 1);
298
+ y.updateType === "cut" && n.current?.validation?.key && p(
299
+ n.current?.validation?.key + "." + T.join(".")
300
300
  ), y.updateType === "insert" && n.current?.validation?.key && Pe(
301
- n.current?.validation?.key + "." + x.join(".")
302
- ).filter(([h, P]) => {
303
- let F = h?.split(".").length;
304
- if (h == x.join(".") && F == x.length - 1) {
305
- let _ = h + "." + x;
306
- G(h), Fe(_, P);
301
+ n.current?.validation?.key + "." + T.join(".")
302
+ ).filter(([w, P]) => {
303
+ let F = w?.split(".").length;
304
+ if (w == T.join(".") && F == T.length - 1) {
305
+ let _ = w + "." + T;
306
+ p(w), Fe(_, P);
307
307
  }
308
308
  });
309
- const B = a.getState().stateComponents.get(r);
310
- if (B) {
311
- const U = _e(N, $), h = new Set(U), P = y.updateType === "update" ? i.join(".") : i.slice(0, -1).join(".") || "";
309
+ const J = a.getState().stateComponents.get(r);
310
+ if (J) {
311
+ const U = _e(h, $), w = new Set(U), P = y.updateType === "update" ? i.join(".") : i.slice(0, -1).join(".") || "";
312
312
  for (const [
313
313
  F,
314
314
  _
315
- ] of B.components.entries()) {
315
+ ] of J.components.entries()) {
316
316
  let C = !1;
317
- const k = Array.isArray(_.reactiveType) ? _.reactiveType : [_.reactiveType || "component"];
318
- if (!k.includes("none")) {
319
- if (k.includes("all")) {
317
+ const V = Array.isArray(_.reactiveType) ? _.reactiveType : [_.reactiveType || "component"];
318
+ if (!V.includes("none")) {
319
+ if (V.includes("all")) {
320
320
  _.forceUpdate();
321
321
  continue;
322
322
  }
323
- if (k.includes("component") && ((_.paths.has(P) || _.paths.has("")) && (C = !0), !C))
324
- for (const D of h) {
325
- let O = D;
323
+ if (V.includes("component") && ((_.paths.has(P) || _.paths.has("")) && (C = !0), !C))
324
+ for (const M of w) {
325
+ let j = M;
326
326
  for (; ; ) {
327
- if (_.paths.has(O)) {
327
+ if (_.paths.has(j)) {
328
328
  C = !0;
329
329
  break;
330
330
  }
331
- const se = O.lastIndexOf(".");
331
+ const se = j.lastIndexOf(".");
332
332
  if (se !== -1) {
333
- const Se = O.substring(
333
+ const Se = j.substring(
334
334
  0,
335
335
  se
336
336
  );
337
337
  if (!isNaN(
338
- Number(O.substring(se + 1))
338
+ Number(j.substring(se + 1))
339
339
  ) && _.paths.has(Se)) {
340
340
  C = !0;
341
341
  break;
342
342
  }
343
- O = Se;
343
+ j = Se;
344
344
  } else
345
- O = "";
346
- if (O === "")
345
+ j = "";
346
+ if (j === "")
347
347
  break;
348
348
  }
349
349
  if (C) break;
350
350
  }
351
- if (!C && k.includes("deps") && _.depsFunction) {
352
- const D = _.depsFunction($);
353
- let O = !1;
354
- typeof D == "boolean" ? D && (O = !0) : M(_.deps, D) || (_.deps = D, O = !0), O && (C = !0);
351
+ if (!C && V.includes("deps") && _.depsFunction) {
352
+ const M = _.depsFunction($);
353
+ let j = !1;
354
+ typeof M == "boolean" ? M && (j = !0) : G(_.deps, M) || (_.deps = M, j = !0), j && (C = !0);
355
355
  }
356
356
  C && _.forceUpdate();
357
357
  }
358
358
  }
359
359
  }
360
360
  const ae = Date.now();
361
- i = i.map((U, h) => {
362
- const P = i.slice(0, -1), F = p($, P);
363
- return h === i.length - 1 && ["insert", "cut"].includes(y.updateType) ? (F.length - 1).toString() : U;
361
+ i = i.map((U, w) => {
362
+ const P = i.slice(0, -1), F = D($, P);
363
+ return w === i.length - 1 && ["insert", "cut"].includes(y.updateType) ? (F.length - 1).toString() : U;
364
364
  }), console.log(
365
365
  "mmmmmmmmmmmmmmmmm22222222222222",
366
366
  y.updateType,
367
- N,
367
+ h,
368
368
  $,
369
369
  i
370
370
  );
371
- const { oldValue: Y, newValue: oe } = pe(
371
+ const { oldValue: Y, newValue: oe } = De(
372
372
  y.updateType,
373
- N,
373
+ h,
374
374
  $,
375
375
  i
376
376
  ), ie = {
@@ -382,26 +382,26 @@ function De(e, {
382
382
  oldValue: Y,
383
383
  newValue: oe
384
384
  };
385
- if (Oe(r, (U) => {
385
+ if (je(r, (U) => {
386
386
  const P = [...U ?? [], ie].reduce((F, _) => {
387
- const C = `${_.stateKey}:${JSON.stringify(_.path)}`, k = F.get(C);
388
- return k ? (k.timeStamp = Math.max(k.timeStamp, _.timeStamp), k.newValue = _.newValue, k.oldValue = k.oldValue ?? _.oldValue, k.updateType = _.updateType) : F.set(C, { ..._ }), F;
387
+ const C = `${_.stateKey}:${JSON.stringify(_.path)}`, V = F.get(C);
388
+ return V ? (V.timeStamp = Math.max(V.timeStamp, _.timeStamp), V.newValue = _.newValue, V.oldValue = V.oldValue ?? _.oldValue, V.updateType = _.updateType) : F.set(C, { ..._ }), F;
389
389
  }, /* @__PURE__ */ new Map());
390
390
  return Array.from(P.values());
391
391
  }), Ee(
392
392
  $,
393
393
  r,
394
394
  n.current,
395
- w
395
+ N
396
396
  ), I && I({
397
- updateLog: J,
397
+ updateLog: B,
398
398
  update: ie
399
399
  }), n.current?.serverSync) {
400
- const U = a.getState().serverState[r], h = n.current?.serverSync;
401
- je(r, {
402
- syncKey: typeof h.syncKey == "string" ? h.syncKey : h.syncKey({ state: $ }),
400
+ const U = a.getState().serverState[r], w = n.current?.serverSync;
401
+ Oe(r, {
402
+ syncKey: typeof w.syncKey == "string" ? w.syncKey : w.syncKey({ state: $ }),
403
403
  rollBackState: U,
404
- actionTimeStamp: Date.now() + (h.debounce ?? 3e3),
404
+ actionTimeStamp: Date.now() + (w.debounce ?? 3e3),
405
405
  status: "waiting"
406
406
  });
407
407
  }
@@ -414,88 +414,88 @@ function De(e, {
414
414
  r,
415
415
  o,
416
416
  W.current,
417
- w
417
+ N
418
418
  )
419
419
  ), a.getState().cogsStateStore[r] || q(r, e), a.getState().initialStateGlobal[r] || fe(r, e));
420
- const g = Ne(() => ee(
420
+ const g = he(() => ee(
421
421
  r,
422
422
  o,
423
423
  W.current,
424
- w
424
+ N
425
425
  ), [r]);
426
- return [he(r), g];
426
+ return [we(r), g];
427
427
  }
428
- function ee(e, s, m, d) {
428
+ function ee(e, c, S, d) {
429
429
  const u = /* @__PURE__ */ new Map();
430
430
  let I = 0;
431
- const E = (f) => {
432
- const t = f.join(".");
431
+ const E = (m) => {
432
+ const t = m.join(".");
433
433
  for (const [v] of u)
434
434
  (v === t || v.startsWith(t + ".")) && u.delete(v);
435
435
  I++;
436
- }, S = {
437
- removeValidation: (f) => {
438
- f?.validationKey && G(f.validationKey);
436
+ }, f = {
437
+ removeValidation: (m) => {
438
+ m?.validationKey && p(m.validationKey);
439
439
  },
440
- revertToInitialState: (f) => {
440
+ revertToInitialState: (m) => {
441
441
  const t = a.getState().getInitialOptions(e)?.validation;
442
- t?.key && G(t?.key), f?.validationKey && G(f.validationKey);
442
+ t?.key && p(t?.key), m?.validationKey && p(m.validationKey);
443
443
  const v = a.getState().initialStateGlobal[e];
444
444
  a.getState().clearSelectedIndexesForState(e), u.clear(), I++;
445
- const T = l(v, []), b = z(e), j = L(b?.localStorage?.key) ? b?.localStorage?.key(v) : b?.localStorage?.key, w = `${d}-${e}-${j}`;
446
- w && localStorage.removeItem(w), K(e, T), q(e, v);
445
+ const A = l(v, []), b = z(e), O = L(b?.localStorage?.key) ? b?.localStorage?.key(v) : b?.localStorage?.key, N = `${d}-${e}-${O}`;
446
+ N && localStorage.removeItem(N), K(e, A), q(e, v);
447
447
  const R = a.getState().stateComponents.get(e);
448
448
  return R && R.components.forEach((r) => {
449
449
  r.forceUpdate();
450
450
  }), v;
451
451
  },
452
- updateInitialState: (f) => {
452
+ updateInitialState: (m) => {
453
453
  u.clear(), I++;
454
454
  const t = ee(
455
455
  e,
456
- s,
457
- m,
456
+ c,
457
+ S,
458
458
  d
459
- ), v = a.getState().initialStateGlobal[e], T = z(e), b = L(T?.localStorage?.key) ? T?.localStorage?.key(v) : T?.localStorage?.key, j = `${d}-${e}-${b}`;
460
- return console.log("removing storage", j), localStorage.getItem(j) && localStorage.removeItem(j), ke(() => {
461
- fe(e, f), K(e, t), q(e, f);
462
- const w = a.getState().stateComponents.get(e);
463
- w && w.components.forEach((R) => {
459
+ ), v = a.getState().initialStateGlobal[e], A = z(e), b = L(A?.localStorage?.key) ? A?.localStorage?.key(v) : A?.localStorage?.key, O = `${d}-${e}-${b}`;
460
+ return console.log("removing storage", O), localStorage.getItem(O) && localStorage.removeItem(O), Ve(() => {
461
+ fe(e, m), K(e, t), q(e, m);
462
+ const N = a.getState().stateComponents.get(e);
463
+ N && N.components.forEach((R) => {
464
464
  R.forceUpdate();
465
465
  });
466
466
  }), {
467
- fetchId: (w) => t.get()[w]
467
+ fetchId: (N) => t.get()[N]
468
468
  };
469
469
  },
470
470
  _initialState: a.getState().initialStateGlobal[e],
471
471
  _serverState: a.getState().serverState[e],
472
472
  _isLoading: a.getState().isLoadingGlobal[e],
473
473
  _isServerSynced: () => {
474
- const f = a.getState().serverState[e];
475
- return !!(f && M(f, he(e)));
474
+ const m = a.getState().serverState[e];
475
+ return !!(m && G(m, we(e)));
476
476
  }
477
477
  };
478
- function l(f, t = [], v) {
479
- const T = t.map(String).join(".");
480
- u.get(T);
478
+ function l(m, t = [], v) {
479
+ const A = t.map(String).join(".");
480
+ u.get(A);
481
481
  const b = function() {
482
482
  return a().getNestedState(e, t);
483
483
  };
484
- Object.keys(S).forEach((R) => {
485
- b[R] = S[R];
484
+ Object.keys(f).forEach((R) => {
485
+ b[R] = f[R];
486
486
  });
487
- const j = {
488
- apply(R, r, J) {
487
+ const O = {
488
+ apply(R, r, B) {
489
489
  return console.log(
490
490
  `PROXY APPLY TRAP HIT: stateKey=${e}, path=${t.join(".")}`
491
491
  ), console.trace("Apply trap stack trace"), a().getNestedState(e, t);
492
492
  },
493
493
  get(R, r) {
494
494
  if (r !== "then" && !r.startsWith("$") && r !== "stateMapNoRender") {
495
- const n = t.join("."), o = `${e}////${m}`, g = a.getState().stateComponents.get(e);
495
+ const n = t.join("."), o = `${e}////${S}`, g = a.getState().stateComponents.get(e);
496
496
  if (g) {
497
- const c = g.components.get(o);
498
- c && (t.length > 0 || r === "get") && c.paths.add(n);
497
+ const s = g.components.get(o);
498
+ s && (t.length > 0 || r === "get") && s.paths.add(n);
499
499
  }
500
500
  }
501
501
  if (r === "getDifferences")
@@ -508,17 +508,17 @@ function ee(e, s, m, d) {
508
508
  const n = a.getState().getInitialOptions(e), o = n?.sync;
509
509
  if (!o)
510
510
  return console.error(`No mutation defined for state key "${e}"`), { success: !1, error: "No mutation defined" };
511
- const g = a.getState().getNestedState(e, []), c = n?.validation?.key;
511
+ const g = a.getState().getNestedState(e, []), s = n?.validation?.key;
512
512
  try {
513
513
  const i = await o.action(g);
514
- if (i && !i.success && i.errors && c) {
515
- a.getState().removeValidationError(c), i.errors.forEach((V) => {
516
- const N = [c, ...V.path].join(".");
517
- a.getState().addValidationError(N, V.message);
514
+ if (i && !i.success && i.errors && s) {
515
+ a.getState().removeValidationError(s), i.errors.forEach((k) => {
516
+ const h = [s, ...k.path].join(".");
517
+ a.getState().addValidationError(h, k.message);
518
518
  });
519
519
  const y = a.getState().stateComponents.get(e);
520
- y && y.components.forEach((V) => {
521
- V.forceUpdate();
520
+ y && y.components.forEach((k) => {
521
+ k.forceUpdate();
522
522
  });
523
523
  }
524
524
  return i?.success && o.onSuccess ? o.onSuccess(i.data) : !i?.success && o.onError && o.onError(i.error), i;
@@ -527,21 +527,21 @@ function ee(e, s, m, d) {
527
527
  }
528
528
  };
529
529
  if (r === "_status") {
530
- const n = a.getState().getNestedState(e, t), o = a.getState().initialStateGlobal[e], g = p(o, t);
531
- return M(n, g) ? "fresh" : "stale";
530
+ const n = a.getState().getNestedState(e, t), o = a.getState().initialStateGlobal[e], g = D(o, t);
531
+ return G(n, g) ? "fresh" : "stale";
532
532
  }
533
533
  if (r === "getStatus")
534
534
  return function() {
535
535
  const n = a().getNestedState(
536
536
  e,
537
537
  t
538
- ), o = a.getState().initialStateGlobal[e], g = p(o, t);
539
- return M(n, g) ? "fresh" : "stale";
538
+ ), o = a.getState().initialStateGlobal[e], g = D(o, t);
539
+ return G(n, g) ? "fresh" : "stale";
540
540
  };
541
541
  if (r === "removeStorage")
542
542
  return () => {
543
- const n = a.getState().initialStateGlobal[e], o = z(e), g = L(o?.localStorage?.key) ? o?.localStorage?.key(n) : o?.localStorage?.key, c = `${d}-${e}-${g}`;
544
- console.log("removing storage", c), c && localStorage.removeItem(c);
543
+ const n = a.getState().initialStateGlobal[e], o = z(e), g = L(o?.localStorage?.key) ? o?.localStorage?.key(n) : o?.localStorage?.key, s = `${d}-${e}-${g}`;
544
+ console.log("removing storage", s), s && localStorage.removeItem(s);
545
545
  };
546
546
  if (r === "showValidationErrors")
547
547
  return () => {
@@ -550,13 +550,13 @@ function ee(e, s, m, d) {
550
550
  throw new Error("Validation key not found");
551
551
  return a.getState().getValidationErrors(n.key + "." + t.join("."));
552
552
  };
553
- if (Array.isArray(f)) {
553
+ if (Array.isArray(m)) {
554
554
  if (r === "getSelected")
555
555
  return () => {
556
556
  const n = a.getState().getSelectedIndex(e, t.join("."));
557
557
  if (n !== void 0)
558
558
  return l(
559
- f[n],
559
+ m[n],
560
560
  [...t, n.toString()],
561
561
  v
562
562
  );
@@ -569,13 +569,13 @@ function ee(e, s, m, d) {
569
569
  return () => a.getState().getSelectedIndex(e, t.join(".")) ?? -1;
570
570
  if (r === "stateSort")
571
571
  return (n) => {
572
- const c = [...a.getState().getNestedState(e, t).map((i, y) => ({
572
+ const s = [...a.getState().getNestedState(e, t).map((i, y) => ({
573
573
  ...i,
574
574
  __origIndex: y.toString()
575
575
  }))].sort(n);
576
- return u.clear(), I++, l(c, t, {
576
+ return u.clear(), I++, l(s, t, {
577
577
  filtered: [...v?.filtered || [], t],
578
- validIndices: c.map(
578
+ validIndices: s.map(
579
579
  (i) => parseInt(i.__origIndex)
580
580
  )
581
581
  });
@@ -583,25 +583,25 @@ function ee(e, s, m, d) {
583
583
  if (r === "stateMap" || r === "stateMapNoRender")
584
584
  return (n) => {
585
585
  const o = v?.filtered?.some(
586
- (c) => c.join(".") === t.join(".")
587
- ), g = o ? f : a.getState().getNestedState(e, t);
588
- return r !== "stateMapNoRender" && (u.clear(), I++), g.map((c, i) => {
589
- const y = o && c.__origIndex ? c.__origIndex : i, V = l(
590
- c,
586
+ (s) => s.join(".") === t.join(".")
587
+ ), g = o ? m : a.getState().getNestedState(e, t);
588
+ return r !== "stateMapNoRender" && (u.clear(), I++), g.map((s, i) => {
589
+ const y = o && s.__origIndex ? s.__origIndex : i, k = l(
590
+ s,
591
591
  [...t, y.toString()],
592
592
  v
593
593
  );
594
594
  return n(
595
- c,
596
- V,
595
+ s,
596
+ k,
597
597
  i,
598
- f,
599
- l(f, t, v)
598
+ m,
599
+ l(m, t, v)
600
600
  );
601
601
  });
602
602
  };
603
603
  if (r === "$stateMap")
604
- return (n) => te(Me, {
604
+ return (n) => te(Ge, {
605
605
  proxy: {
606
606
  _stateKey: e,
607
607
  _path: t,
@@ -614,113 +614,112 @@ function ee(e, s, m, d) {
614
614
  return (n) => {
615
615
  const g = v?.filtered?.some(
616
616
  (i) => i.join(".") === t.join(".")
617
- ) ? f : a.getState().getNestedState(e, t);
617
+ ) ? m : a.getState().getNestedState(e, t);
618
618
  u.clear(), I++;
619
- const c = g.flatMap(
619
+ const s = g.flatMap(
620
620
  (i, y) => i[n] ?? []
621
621
  );
622
622
  return l(
623
- c,
623
+ s,
624
624
  [...t, "[*]", n],
625
625
  v
626
626
  );
627
627
  };
628
628
  if (r === "findWith")
629
629
  return (n, o) => {
630
- const g = f.findIndex((y) => y[n] === o);
630
+ const g = m.findIndex((y) => y[n] === o);
631
631
  if (g === -1) return;
632
- const c = f[g], i = [...t, g.toString()];
633
- return u.clear(), I++, l(c, i);
632
+ const s = m[g], i = [...t, g.toString()];
633
+ return u.clear(), I++, l(s, i);
634
634
  };
635
635
  if (r === "index")
636
636
  return (n) => {
637
- const o = f[n];
637
+ const o = m[n];
638
638
  return l(o, [...t, n.toString()]);
639
639
  };
640
640
  if (r === "last")
641
641
  return () => {
642
642
  const n = a.getState().getNestedState(e, t);
643
643
  if (n.length === 0) return;
644
- const o = n.length - 1, g = n[o], c = [...t, o.toString()];
645
- return l(g, c);
644
+ const o = n.length - 1, g = n[o], s = [...t, o.toString()];
645
+ return l(g, s);
646
646
  };
647
647
  if (r === "insert")
648
- return (n) => (E(t), ce(s, n, t, e), l(
648
+ return (n) => (E(t), ce(c, n, t, e), l(
649
649
  a.getState().getNestedState(e, t),
650
650
  t
651
651
  ));
652
652
  if (r === "uniqueInsert")
653
653
  return (n, o, g) => {
654
- const c = a.getState().getNestedState(e, t), i = L(n) ? n(c) : n;
654
+ const s = a.getState().getNestedState(e, t), i = L(n) ? n(s) : n;
655
655
  let y = null;
656
- if (!c.some((N) => {
656
+ if (!s.some((h) => {
657
657
  if (o) {
658
- const A = o.every(
659
- (x) => M(N[x], i[x])
658
+ const x = o.every(
659
+ (T) => G(h[T], i[T])
660
660
  );
661
- return A && (y = N), A;
661
+ return x && (y = h), x;
662
662
  }
663
- const $ = M(N, i);
664
- return $ && (y = N), $;
663
+ const $ = G(h, i);
664
+ return $ && (y = h), $;
665
665
  }))
666
- E(t), ce(s, i, t, e);
666
+ E(t), ce(c, i, t, e);
667
667
  else if (g && y) {
668
- const N = g(y), $ = c.map(
669
- (A) => M(A, y) ? N : A
668
+ const h = g(y), $ = s.map(
669
+ (x) => G(x, y) ? h : x
670
670
  );
671
- E(t), Z(s, $, t);
671
+ E(t), Z(c, $, t);
672
672
  }
673
673
  };
674
674
  if (r === "cut")
675
675
  return (n, o) => {
676
676
  if (!o?.waitForSync)
677
- return E(t), X(s, t, e, n), l(
677
+ return E(t), X(c, t, e, n), l(
678
678
  a.getState().getNestedState(e, t),
679
679
  t
680
680
  );
681
681
  };
682
682
  if (r === "cutByValue")
683
683
  return (n) => {
684
- for (let o = 0; o < f.length; o++)
685
- f[o] === n && X(s, t, e, o);
684
+ for (let o = 0; o < m.length; o++)
685
+ m[o] === n && X(c, t, e, o);
686
686
  };
687
687
  if (r === "toggleByValue")
688
688
  return (n) => {
689
- const o = f.findIndex((g) => g === n);
690
- o > -1 ? X(s, t, e, o) : ce(s, n, t, e);
689
+ const o = m.findIndex((g) => g === n);
690
+ o > -1 ? X(c, t, e, o) : ce(c, n, t, e);
691
691
  };
692
692
  if (r === "stateFind")
693
693
  return (n) => {
694
- const o = f.findIndex(n);
695
- if (o === -1)
694
+ const o = a.getState().getNestedState(e, t), g = o.findIndex(n);
695
+ if (g === -1)
696
696
  return;
697
- const g = f[o], c = [...t, o.toString()];
698
- return l(g, c);
697
+ const s = o[g], i = [...t, g.toString()];
698
+ return l(s, i);
699
699
  };
700
700
  if (r === "stateFilter")
701
701
  return (n) => {
702
- const o = f.map((i, y) => ({
703
- ...i,
704
- __origIndex: y.toString()
705
- })), g = [], c = [];
706
- for (let i = 0; i < o.length; i++)
707
- n(o[i], i) && (g.push(i), c.push(o[i]));
708
- return u.clear(), I++, l(c, t, {
702
+ const g = a.getState().getNestedState(e, t).filter((s, i) => {
703
+ const y = { ...s, __origIndex: i.toString() };
704
+ return n(y, i);
705
+ });
706
+ return u.clear(), I++, l(g, t, {
709
707
  filtered: [...v?.filtered || [], t],
710
- validIndices: g
711
- // Always pass validIndices, even if empty
708
+ validIndices: g.map(
709
+ (s) => parseInt(s.__origIndex)
710
+ )
712
711
  });
713
712
  };
714
713
  }
715
- const J = t[t.length - 1];
716
- if (!isNaN(Number(J))) {
714
+ const B = t[t.length - 1];
715
+ if (!isNaN(Number(B))) {
717
716
  const n = t.slice(0, -1), o = a.getState().getNestedState(e, n);
718
717
  if (Array.isArray(o) && r === "cut")
719
718
  return () => X(
720
- s,
719
+ c,
721
720
  n,
722
721
  e,
723
- Number(J)
722
+ Number(B)
724
723
  );
725
724
  }
726
725
  if (r === "get")
@@ -754,21 +753,21 @@ function ee(e, s, m, d) {
754
753
  }
755
754
  if (r === "setSelected")
756
755
  return (n) => {
757
- const o = t.slice(0, -1), g = Number(t[t.length - 1]), c = o.join(".");
758
- n ? a.getState().setSelectedIndex(e, c, g) : a.getState().setSelectedIndex(e, c, void 0);
756
+ const o = t.slice(0, -1), g = Number(t[t.length - 1]), s = o.join(".");
757
+ n ? a.getState().setSelectedIndex(e, s, g) : a.getState().setSelectedIndex(e, s, void 0);
759
758
  const i = a.getState().getNestedState(e, [...o]);
760
- Z(s, i, o), E(o);
759
+ Z(c, i, o), E(o);
761
760
  };
762
761
  if (r === "toggleSelected")
763
762
  return () => {
764
- const n = t.slice(0, -1), o = Number(t[t.length - 1]), g = n.join("."), c = a.getState().getSelectedIndex(e, g);
763
+ const n = t.slice(0, -1), o = Number(t[t.length - 1]), g = n.join("."), s = a.getState().getSelectedIndex(e, g);
765
764
  a.getState().setSelectedIndex(
766
765
  e,
767
766
  g,
768
- c === o ? void 0 : o
767
+ s === o ? void 0 : o
769
768
  );
770
769
  const i = a.getState().getNestedState(e, [...n]);
771
- Z(s, i, n), E(n);
770
+ Z(c, i, n), E(n);
772
771
  };
773
772
  if (t.length == 0) {
774
773
  if (r === "validateZodSchema")
@@ -778,23 +777,23 @@ function ee(e, s, m, d) {
778
777
  throw new Error("Zod schema not found");
779
778
  if (!n?.key)
780
779
  throw new Error("Validation key not found");
781
- G(n.key);
780
+ p(n.key);
782
781
  const g = a.getState().cogsStateStore[e];
783
782
  try {
784
- const c = a.getState().getValidationErrors(n.key);
785
- c && c.length > 0 && c.forEach(([y]) => {
786
- y && y.startsWith(n.key) && G(y);
783
+ const s = a.getState().getValidationErrors(n.key);
784
+ s && s.length > 0 && s.forEach(([y]) => {
785
+ y && y.startsWith(n.key) && p(y);
787
786
  });
788
787
  const i = n.zodSchema.safeParse(g);
789
- return i.success ? !0 : (i.error.errors.forEach((V) => {
790
- const N = V.path, $ = V.message, A = [n.key, ...N].join(".");
791
- o(A, $);
788
+ return i.success ? !0 : (i.error.errors.forEach((k) => {
789
+ const h = k.path, $ = k.message, x = [n.key, ...h].join(".");
790
+ o(x, $);
792
791
  }), re(e), !1);
793
- } catch (c) {
794
- return console.error("Zod schema validation failed", c), !1;
792
+ } catch (s) {
793
+ return console.error("Zod schema validation failed", s), !1;
795
794
  }
796
795
  };
797
- if (r === "_componentId") return m;
796
+ if (r === "_componentId") return S;
798
797
  if (r === "getComponents")
799
798
  return () => a().stateComponents.get(e);
800
799
  if (r === "getAllFormRefs")
@@ -806,9 +805,9 @@ function ee(e, s, m, d) {
806
805
  if (r === "_isLoading")
807
806
  return a.getState().isLoadingGlobal[e];
808
807
  if (r === "revertToInitialState")
809
- return S.revertToInitialState;
810
- if (r === "updateInitialState") return S.updateInitialState;
811
- if (r === "removeValidation") return S.removeValidation;
808
+ return f.revertToInitialState;
809
+ if (r === "updateInitialState") return f.updateInitialState;
810
+ if (r === "removeValidation") return f.removeValidation;
812
811
  }
813
812
  if (r === "getFormRef")
814
813
  return () => ye.getState().getFormRef(e + "." + t.join("."));
@@ -817,7 +816,7 @@ function ee(e, s, m, d) {
817
816
  children: n,
818
817
  hideMessage: o
819
818
  }) => /* @__PURE__ */ me(
820
- xe,
819
+ Te,
821
820
  {
822
821
  formOpts: o ? { validation: { message: "" } } : void 0,
823
822
  path: t,
@@ -829,17 +828,17 @@ function ee(e, s, m, d) {
829
828
  );
830
829
  if (r === "_stateKey") return e;
831
830
  if (r === "_path") return t;
832
- if (r === "_isServerSynced") return S._isServerSynced;
831
+ if (r === "_isServerSynced") return f._isServerSynced;
833
832
  if (r === "update")
834
833
  return (n, o) => {
835
834
  if (o?.debounce)
836
- Ae(() => {
837
- Z(s, n, t, "");
835
+ xe(() => {
836
+ Z(c, n, t, "");
838
837
  const g = a.getState().getNestedState(e, t);
839
838
  o?.afterUpdate && o.afterUpdate(g);
840
839
  }, o.debounce);
841
840
  else {
842
- Z(s, n, t, "");
841
+ Z(c, n, t, "");
843
842
  const g = a.getState().getNestedState(e, t);
844
843
  o?.afterUpdate && o.afterUpdate(g);
845
844
  }
@@ -849,7 +848,7 @@ function ee(e, s, m, d) {
849
848
  return (n, o) => /* @__PURE__ */ me(
850
849
  Ce,
851
850
  {
852
- setState: s,
851
+ setState: c,
853
852
  stateKey: e,
854
853
  path: t,
855
854
  child: n,
@@ -859,48 +858,48 @@ function ee(e, s, m, d) {
859
858
  const H = [...t, r], W = a.getState().getNestedState(e, H);
860
859
  return l(W, H, v);
861
860
  }
862
- }, w = new Proxy(b, j);
863
- return u.set(T, {
864
- proxy: w,
861
+ }, N = new Proxy(b, O);
862
+ return u.set(A, {
863
+ proxy: N,
865
864
  stateVersion: I
866
- }), w;
865
+ }), N;
867
866
  }
868
867
  return l(
869
868
  a.getState().getNestedState(e, [])
870
869
  );
871
870
  }
872
871
  function le(e) {
873
- return te(Ge, { proxy: e });
872
+ return te(pe, { proxy: e });
874
873
  }
875
- function Me({
874
+ function Ge({
876
875
  proxy: e,
877
- rebuildStateShape: s
876
+ rebuildStateShape: c
878
877
  }) {
879
- const m = a().getNestedState(e._stateKey, e._path);
880
- return Array.isArray(m) ? s(
881
- m,
878
+ const S = a().getNestedState(e._stateKey, e._path);
879
+ return Array.isArray(S) ? c(
880
+ S,
882
881
  e._path
883
882
  ).stateMapNoRender(
884
- (u, I, E, S, l) => e._mapFn(u, I, E, S, l)
883
+ (u, I, E, f, l) => e._mapFn(u, I, E, f, l)
885
884
  ) : null;
886
885
  }
887
- function Ge({
886
+ function pe({
888
887
  proxy: e
889
888
  }) {
890
- const s = Q(null), m = `${e._stateKey}-${e._path.join(".")}`;
889
+ const c = Q(null), S = `${e._stateKey}-${e._path.join(".")}`;
891
890
  return ue(() => {
892
- const d = s.current;
891
+ const d = c.current;
893
892
  if (!d || !d.parentElement) return;
894
893
  const u = d.parentElement, E = Array.from(u.childNodes).indexOf(d);
895
- let S = u.getAttribute("data-parent-id");
896
- S || (S = `parent-${crypto.randomUUID()}`, u.setAttribute("data-parent-id", S));
897
- const f = {
894
+ let f = u.getAttribute("data-parent-id");
895
+ f || (f = `parent-${crypto.randomUUID()}`, u.setAttribute("data-parent-id", f));
896
+ const m = {
898
897
  instanceId: `instance-${crypto.randomUUID()}`,
899
- parentId: S,
898
+ parentId: f,
900
899
  position: E,
901
900
  effect: e._effect
902
901
  };
903
- a.getState().addSignalElement(m, f);
902
+ a.getState().addSignalElement(S, m);
904
903
  const t = a.getState().getNestedState(e._stateKey, e._path);
905
904
  let v;
906
905
  if (e._effect)
@@ -915,28 +914,28 @@ function Ge({
915
914
  else
916
915
  v = t;
917
916
  v !== null && typeof v == "object" && (v = JSON.stringify(v));
918
- const T = document.createTextNode(String(v));
919
- d.replaceWith(T);
917
+ const A = document.createTextNode(String(v));
918
+ d.replaceWith(A);
920
919
  }, [e._stateKey, e._path.join("."), e._effect]), te("span", {
921
- ref: s,
920
+ ref: c,
922
921
  style: { display: "none" },
923
- "data-signal-id": m
922
+ "data-signal-id": S
924
923
  });
925
924
  }
926
925
  function et(e) {
927
- const s = Ve(
928
- (m) => {
926
+ const c = ke(
927
+ (S) => {
929
928
  const d = a.getState().stateComponents.get(e._stateKey) || {
930
929
  components: /* @__PURE__ */ new Map()
931
930
  };
932
931
  return d.components.set(e._stateKey, {
933
- forceUpdate: m,
932
+ forceUpdate: S,
934
933
  paths: /* @__PURE__ */ new Set([e._path.join(".")])
935
934
  }), () => d.components.delete(e._stateKey);
936
935
  },
937
936
  () => a.getState().getNestedState(e._stateKey, e._path)
938
937
  );
939
- return te("text", {}, String(s));
938
+ return te("text", {}, String(c));
940
939
  }
941
940
  export {
942
941
  le as $cogsSignal,
@@ -944,6 +943,6 @@ export {
944
943
  Xe as addStateOptions,
945
944
  Qe as createCogsState,
946
945
  Ke as notifyComponent,
947
- De as useCogsStateFn
946
+ Me as useCogsStateFn
948
947
  };
949
948
  //# sourceMappingURL=CogsState.jsx.map