cogsbox-state 0.5.164 → 0.5.165

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