cogsbox-state 0.5.365 → 0.5.367

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,41 +1,41 @@
1
1
  "use client";
2
- import { jsx as ve } from "react/jsx-runtime";
3
- import { useState as Z, useRef as Q, useEffect as re, useLayoutEffect as ie, useMemo as ye, createElement as ce, useSyncExternalStore as xe, startTransition as Ge, useCallback as Ee } from "react";
4
- import { transformStateFunc as Pe, isDeepEqual as Y, isFunction as X, getNestedValue as z, getDifferences as Ae, debounce as Ue } from "./utility.js";
5
- import { pushFunc as Te, updateFn as se, cutFunc as ge, ValidationWrapper as je, FormControlComponent as Fe } from "./Functions.jsx";
6
- import De from "superjson";
2
+ import { jsx as Te } from "react/jsx-runtime";
3
+ import { useState as X, useRef as K, useEffect as oe, useLayoutEffect as ie, useMemo as ve, createElement as ce, useSyncExternalStore as Pe, startTransition as Ve, useCallback as _e } from "react";
4
+ import { transformStateFunc as Ge, isDeepEqual as z, isFunction as Q, getNestedValue as q, getDifferences as ye, debounce as Le } from "./utility.js";
5
+ import { pushFunc as he, updateFn as se, cutFunc as ge, ValidationWrapper as Re, FormControlComponent as De } from "./Functions.jsx";
6
+ import Ue from "superjson";
7
7
  import { v4 as pe } from "uuid";
8
8
  import "zod";
9
9
  import { getGlobalStore as r, formRefStore as Oe } from "./store.js";
10
- import { useCogsConfig as Me } from "./CogsStateClient.jsx";
11
- import { applyPatch as He } from "fast-json-patch";
12
- import We from "react-use-measure";
13
- function Ne(e, i) {
10
+ import { useCogsConfig as ke } from "./CogsStateClient.jsx";
11
+ import { applyPatch as je } from "fast-json-patch";
12
+ import He from "react-use-measure";
13
+ function Ae(e, i) {
14
14
  const m = r.getState().getInitialOptions, g = r.getState().setInitialStateOptions, T = m(e) || {};
15
15
  g(e, {
16
16
  ...T,
17
17
  ...i
18
18
  });
19
19
  }
20
- function Ce({
20
+ function Ne({
21
21
  stateKey: e,
22
22
  options: i,
23
23
  initialOptionsPart: m
24
24
  }) {
25
- const g = ne(e) || {}, T = m[e] || {}, N = r.getState().setInitialStateOptions, A = { ...T, ...g };
25
+ const g = re(e) || {}, T = m[e] || {}, N = r.getState().setInitialStateOptions, p = { ...T, ...g };
26
26
  let v = !1;
27
27
  if (i)
28
28
  for (const a in i)
29
- A.hasOwnProperty(a) ? (a == "localStorage" && i[a] && A[a].key !== i[a]?.key && (v = !0, A[a] = i[a]), a == "initialState" && i[a] && A[a] !== i[a] && // Different references
30
- !Y(A[a], i[a]) && (v = !0, A[a] = i[a])) : (v = !0, A[a] = i[a]);
31
- v && N(e, A);
29
+ p.hasOwnProperty(a) ? (a == "localStorage" && i[a] && p[a].key !== i[a]?.key && (v = !0, p[a] = i[a]), a == "initialState" && i[a] && p[a] !== i[a] && // Different references
30
+ !z(p[a], i[a]) && (v = !0, p[a] = i[a])) : (v = !0, p[a] = i[a]);
31
+ v && N(e, p);
32
32
  }
33
- function ut(e, { formElements: i, validation: m }) {
33
+ function dt(e, { formElements: i, validation: m }) {
34
34
  return { initialState: e, formElements: i, validation: m };
35
35
  }
36
- const gt = (e, i) => {
36
+ const ut = (e, i) => {
37
37
  let m = e;
38
- const [g, T] = Pe(m);
38
+ const [g, T] = Ge(m);
39
39
  (Object.keys(T).length > 0 || i && Object.keys(i).length > 0) && Object.keys(T).forEach((v) => {
40
40
  T[v] = T[v] || {}, T[v].formElements = {
41
41
  ...i?.formElements,
@@ -43,16 +43,16 @@ const gt = (e, i) => {
43
43
  ...i?.validation,
44
44
  ...T[v].formElements || {}
45
45
  // State-specific overrides
46
- }, ne(v) || r.getState().setInitialStateOptions(v, T[v]);
46
+ }, re(v) || r.getState().setInitialStateOptions(v, T[v]);
47
47
  }), r.getState().setInitialStates(g), r.getState().setCreatedState(g);
48
48
  const N = (v, a) => {
49
- const [h] = Z(a?.componentId ?? pe());
50
- Ce({
49
+ const [h] = X(a?.componentId ?? pe());
50
+ Ne({
51
51
  stateKey: v,
52
52
  options: a,
53
53
  initialOptionsPart: T
54
54
  });
55
- const n = r.getState().cogsStateStore[v] || g[v], S = a?.modifyState ? a.modifyState(n) : n, [H, P] = Ze(
55
+ const n = r.getState().cogsStateStore[v] || g[v], S = a?.modifyState ? a.modifyState(n) : n, [H, L] = Ye(
56
56
  S,
57
57
  {
58
58
  stateKey: v,
@@ -68,45 +68,45 @@ const gt = (e, i) => {
68
68
  serverState: a?.serverState
69
69
  }
70
70
  );
71
- return P;
71
+ return L;
72
72
  };
73
- function A(v, a) {
74
- Ce({ stateKey: v, options: a, initialOptionsPart: T }), a.localStorage && qe(v, a), Ie(v);
73
+ function p(v, a) {
74
+ Ne({ stateKey: v, options: a, initialOptionsPart: T }), a.localStorage && qe(v, a), Ie(v);
75
75
  }
76
- return { useCogsState: N, setCogsOptions: A };
76
+ return { useCogsState: N, setCogsOptions: p };
77
77
  }, {
78
78
  setUpdaterState: fe,
79
79
  setState: te,
80
- getInitialOptions: ne,
81
- getKeyState: Re,
82
- getValidationErrors: Le,
80
+ getInitialOptions: re,
81
+ getKeyState: be,
82
+ getValidationErrors: Fe,
83
83
  setStateLog: Be,
84
- updateInitialStateGlobal: _e,
85
- addValidationError: Ye,
86
- removeValidationError: J,
84
+ updateInitialStateGlobal: Ee,
85
+ addValidationError: We,
86
+ removeValidationError: Z,
87
87
  setServerSyncActions: ze
88
- } = r.getState(), $e = (e, i, m, g, T) => {
88
+ } = r.getState(), Ce = (e, i, m, g, T) => {
89
89
  m?.log && console.log(
90
90
  "saving to localstorage",
91
91
  i,
92
92
  m.localStorage?.key,
93
93
  g
94
94
  );
95
- const N = X(m?.localStorage?.key) ? m.localStorage?.key(e) : m?.localStorage?.key;
95
+ const N = Q(m?.localStorage?.key) ? m.localStorage?.key(e) : m?.localStorage?.key;
96
96
  if (N && g) {
97
- const A = `${g}-${i}-${N}`;
97
+ const p = `${g}-${i}-${N}`;
98
98
  let v;
99
99
  try {
100
- v = me(A)?.lastSyncedWithServer;
100
+ v = me(p)?.lastSyncedWithServer;
101
101
  } catch {
102
102
  }
103
103
  const a = {
104
104
  state: e,
105
105
  lastUpdated: Date.now(),
106
106
  lastSyncedWithServer: T ?? v
107
- }, h = De.serialize(a);
107
+ }, h = Ue.serialize(a);
108
108
  window.localStorage.setItem(
109
- A,
109
+ p,
110
110
  JSON.stringify(h.json)
111
111
  );
112
112
  }
@@ -119,7 +119,7 @@ const gt = (e, i) => {
119
119
  return console.error("Error loading from localStorage:", i), null;
120
120
  }
121
121
  }, qe = (e, i) => {
122
- const m = r.getState().cogsStateStore[e], { sessionId: g } = Me(), T = X(i?.localStorage?.key) ? i.localStorage.key(m) : i?.localStorage?.key;
122
+ const m = r.getState().cogsStateStore[e], { sessionId: g } = ke(), T = Q(i?.localStorage?.key) ? i.localStorage.key(m) : i?.localStorage?.key;
123
123
  if (T && g) {
124
124
  const N = me(
125
125
  `${g}-${e}-${T}`
@@ -128,8 +128,8 @@ const gt = (e, i) => {
128
128
  return te(e, N.state), Ie(e), !0;
129
129
  }
130
130
  return !1;
131
- }, ke = (e, i, m, g, T, N) => {
132
- const A = {
131
+ }, Me = (e, i, m, g, T, N) => {
132
+ const p = {
133
133
  initialState: i,
134
134
  updaterState: Se(
135
135
  e,
@@ -139,7 +139,7 @@ const gt = (e, i) => {
139
139
  ),
140
140
  state: m
141
141
  };
142
- _e(e, A.initialState), fe(e, A.updaterState), te(e, A.state);
142
+ Ee(e, p.initialState), fe(e, p.updaterState), te(e, p.state);
143
143
  }, Ie = (e) => {
144
144
  const i = r.getState().stateComponents.get(e);
145
145
  if (!i) return;
@@ -149,7 +149,7 @@ const gt = (e, i) => {
149
149
  }), queueMicrotask(() => {
150
150
  m.forEach((g) => g());
151
151
  });
152
- }, ft = (e, i) => {
152
+ }, gt = (e, i) => {
153
153
  const m = r.getState().stateComponents.get(e);
154
154
  if (m) {
155
155
  const g = `${e}////${i}`, T = m.components.get(g);
@@ -161,18 +161,18 @@ const gt = (e, i) => {
161
161
  switch (e) {
162
162
  case "update":
163
163
  return {
164
- oldValue: z(i, g),
165
- newValue: z(m, g)
164
+ oldValue: q(i, g),
165
+ newValue: q(m, g)
166
166
  };
167
167
  case "insert":
168
168
  return {
169
169
  oldValue: null,
170
170
  // or undefined
171
- newValue: z(m, g)
171
+ newValue: q(m, g)
172
172
  };
173
173
  case "cut":
174
174
  return {
175
- oldValue: z(i, g),
175
+ oldValue: q(i, g),
176
176
  newValue: null
177
177
  // or undefined
178
178
  };
@@ -180,25 +180,25 @@ const gt = (e, i) => {
180
180
  return { oldValue: null, newValue: null };
181
181
  }
182
182
  };
183
- function Ze(e, {
183
+ function Ye(e, {
184
184
  stateKey: i,
185
185
  serverSync: m,
186
186
  localStorage: g,
187
187
  formElements: T,
188
188
  reactiveDeps: N,
189
- reactiveType: A,
189
+ reactiveType: p,
190
190
  componentId: v,
191
191
  initialState: a,
192
192
  syncUpdate: h,
193
193
  dependencies: n,
194
194
  serverState: S
195
195
  } = {}) {
196
- const [H, P] = Z({}), { sessionId: U } = Me();
197
- let W = !i;
198
- const [I] = Z(i ?? pe()), l = r.getState().stateLog[I], le = Q(/* @__PURE__ */ new Set()), K = Q(v ?? pe()), V = Q(
196
+ const [H, L] = X({}), { sessionId: R } = ke();
197
+ let F = !i;
198
+ const [I] = X(i ?? pe()), l = r.getState().stateLog[I], le = K(/* @__PURE__ */ new Set()), ee = K(v ?? pe()), P = K(
199
199
  null
200
200
  );
201
- V.current = ne(I) ?? null, re(() => {
201
+ P.current = re(I) ?? null, oe(() => {
202
202
  if (h && h.stateKey === I && h.path?.[0]) {
203
203
  te(I, (o) => ({
204
204
  ...o,
@@ -210,27 +210,27 @@ function Ze(e, {
210
210
  userId: h.userId
211
211
  });
212
212
  }
213
- }, [h]), re(() => {
213
+ }, [h]), oe(() => {
214
214
  if (a) {
215
- Ne(I, {
215
+ Ae(I, {
216
216
  initialState: a
217
217
  });
218
- const t = V.current, s = t?.serverState?.id !== void 0 && t?.serverState?.status === "success" && t?.serverState?.data, c = r.getState().initialStateGlobal[I];
219
- if (!(c && !Y(c, a) || !c) && !s)
218
+ const t = P.current, s = t?.serverState?.id !== void 0 && t?.serverState?.status === "success" && t?.serverState?.data, c = r.getState().initialStateGlobal[I];
219
+ if (!(c && !z(c, a) || !c) && !s)
220
220
  return;
221
221
  let u = null;
222
- const p = X(t?.localStorage?.key) ? t?.localStorage?.key(a) : t?.localStorage?.key;
223
- p && U && (u = me(`${U}-${I}-${p}`));
224
- let _ = a, w = !1;
225
- const C = s ? Date.now() : 0, $ = u?.lastUpdated || 0, k = u?.lastSyncedWithServer || 0;
226
- s && C > $ ? (_ = t.serverState.data, w = !0) : u && $ > k && (_ = u.state, t?.localStorage?.onChange && t?.localStorage?.onChange(_)), r.getState().initializeShadowState(I, a), ke(
222
+ const E = Q(t?.localStorage?.key) ? t?.localStorage?.key(a) : t?.localStorage?.key;
223
+ E && R && (u = me(`${R}-${I}-${E}`));
224
+ let w = a, _ = !1;
225
+ const C = s ? Date.now() : 0, $ = u?.lastUpdated || 0, x = u?.lastSyncedWithServer || 0;
226
+ s && C > $ ? (w = t.serverState.data, _ = !0) : u && $ > x && (w = u.state, t?.localStorage?.onChange && t?.localStorage?.onChange(w)), r.getState().initializeShadowState(I, a), Me(
227
227
  I,
228
228
  a,
229
- _,
230
- oe,
231
- K.current,
232
- U
233
- ), w && p && U && $e(_, I, t, U, Date.now()), Ie(I), (Array.isArray(A) ? A : [A || "component"]).includes("none") || P({});
229
+ w,
230
+ ae,
231
+ ee.current,
232
+ R
233
+ ), _ && E && R && Ce(w, I, t, R, Date.now()), Ie(I), (Array.isArray(p) ? p : [p || "component"]).includes("none") || L({});
234
234
  }
235
235
  }, [
236
236
  a,
@@ -238,220 +238,220 @@ function Ze(e, {
238
238
  S?.data,
239
239
  ...n || []
240
240
  ]), ie(() => {
241
- W && Ne(I, {
241
+ F && Ae(I, {
242
242
  serverSync: m,
243
243
  formElements: T,
244
244
  initialState: a,
245
245
  localStorage: g,
246
- middleware: V.current?.middleware
246
+ middleware: P.current?.middleware
247
247
  });
248
- const t = `${I}////${K.current}`, o = r.getState().stateComponents.get(I) || {
248
+ const t = `${I}////${ee.current}`, o = r.getState().stateComponents.get(I) || {
249
249
  components: /* @__PURE__ */ new Map()
250
250
  };
251
251
  return o.components.set(t, {
252
- forceUpdate: () => P({}),
252
+ forceUpdate: () => L({}),
253
253
  paths: /* @__PURE__ */ new Set(),
254
254
  deps: [],
255
255
  depsFunction: N || void 0,
256
- reactiveType: A ?? ["component", "deps"]
257
- }), r.getState().stateComponents.set(I, o), P({}), () => {
256
+ reactiveType: p ?? ["component", "deps"]
257
+ }), r.getState().stateComponents.set(I, o), L({}), () => {
258
258
  o && (o.components.delete(t), o.components.size === 0 && r.getState().stateComponents.delete(I));
259
259
  };
260
260
  }, []);
261
- const oe = (t, o, s, c) => {
261
+ const ae = (t, o, s, c) => {
262
262
  if (Array.isArray(o)) {
263
263
  const u = `${I}-${o.join(".")}`;
264
264
  le.current.add(u);
265
265
  }
266
266
  const f = r.getState();
267
267
  te(I, (u) => {
268
- const p = X(t) ? t(u) : t, _ = `${I}-${o.join(".")}`;
269
- if (_) {
270
- let M = !1, y = f.signalDomElements.get(_);
268
+ const E = Q(t) ? t(u) : t, w = `${I}-${o.join(".")}`;
269
+ if (w) {
270
+ let M = !1, y = f.signalDomElements.get(w);
271
271
  if ((!y || y.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
272
- const x = o.slice(0, -1), R = z(p, x);
273
- if (Array.isArray(R)) {
272
+ const V = o.slice(0, -1), b = q(E, V);
273
+ if (Array.isArray(b)) {
274
274
  M = !0;
275
- const O = `${I}-${x.join(".")}`;
276
- y = f.signalDomElements.get(O);
275
+ const A = `${I}-${V.join(".")}`;
276
+ y = f.signalDomElements.get(A);
277
277
  }
278
278
  }
279
279
  if (y) {
280
- const x = M ? z(p, o.slice(0, -1)) : z(p, o);
281
- y.forEach(({ parentId: R, position: O, effect: j }) => {
280
+ const V = M ? q(E, o.slice(0, -1)) : q(E, o);
281
+ y.forEach(({ parentId: b, position: A, effect: D }) => {
282
282
  const G = document.querySelector(
283
- `[data-parent-id="${R}"]`
283
+ `[data-parent-id="${b}"]`
284
284
  );
285
285
  if (G) {
286
286
  const B = Array.from(G.childNodes);
287
- if (B[O]) {
288
- const E = j ? new Function("state", `return (${j})(state)`)(x) : x;
289
- B[O].textContent = String(E);
287
+ if (B[A]) {
288
+ const O = D ? new Function("state", `return (${D})(state)`)(V) : V;
289
+ B[A].textContent = String(O);
290
290
  }
291
291
  }
292
292
  });
293
293
  }
294
294
  }
295
- console.log("shadowState", f.shadowStateStore), s.updateType === "update" && (c || V.current?.validation?.key) && o && J(
296
- (c || V.current?.validation?.key) + "." + o.join(".")
295
+ console.log("shadowState", f.shadowStateStore), s.updateType === "update" && (c || P.current?.validation?.key) && o && Z(
296
+ (c || P.current?.validation?.key) + "." + o.join(".")
297
297
  );
298
- const w = o.slice(0, o.length - 1);
299
- s.updateType === "cut" && V.current?.validation?.key && J(
300
- V.current?.validation?.key + "." + w.join(".")
301
- ), s.updateType === "insert" && V.current?.validation?.key && Le(
302
- V.current?.validation?.key + "." + w.join(".")
303
- ).filter(([y, x]) => {
304
- let R = y?.split(".").length;
305
- if (y == w.join(".") && R == w.length - 1) {
306
- let O = y + "." + w;
307
- J(y), Ye(O, x);
298
+ const _ = o.slice(0, o.length - 1);
299
+ s.updateType === "cut" && P.current?.validation?.key && Z(
300
+ P.current?.validation?.key + "." + _.join(".")
301
+ ), s.updateType === "insert" && P.current?.validation?.key && Fe(
302
+ P.current?.validation?.key + "." + _.join(".")
303
+ ).filter(([y, V]) => {
304
+ let b = y?.split(".").length;
305
+ if (y == _.join(".") && b == _.length - 1) {
306
+ let A = y + "." + _;
307
+ Z(y), We(A, V);
308
308
  }
309
309
  });
310
310
  const C = f.stateComponents.get(I);
311
311
  if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", C), C) {
312
- const M = Ae(u, p), y = new Set(M), x = s.updateType === "update" ? o.join(".") : o.slice(0, -1).join(".") || "";
312
+ const M = ye(u, E), y = new Set(M), V = s.updateType === "update" ? o.join(".") : o.slice(0, -1).join(".") || "";
313
313
  for (const [
314
- R,
315
- O
314
+ b,
315
+ A
316
316
  ] of C.components.entries()) {
317
- let j = !1;
318
- const G = Array.isArray(O.reactiveType) ? O.reactiveType : [O.reactiveType || "component"];
319
- if (console.log("component", O), !G.includes("none")) {
317
+ let D = !1;
318
+ const G = Array.isArray(A.reactiveType) ? A.reactiveType : [A.reactiveType || "component"];
319
+ if (console.log("component", A), !G.includes("none")) {
320
320
  if (G.includes("all")) {
321
- O.forceUpdate();
321
+ A.forceUpdate();
322
322
  continue;
323
323
  }
324
- if (G.includes("component") && ((O.paths.has(x) || O.paths.has("")) && (j = !0), !j))
324
+ if (G.includes("component") && ((A.paths.has(V) || A.paths.has("")) && (D = !0), !D))
325
325
  for (const B of y) {
326
- let E = B;
326
+ let O = B;
327
327
  for (; ; ) {
328
- if (O.paths.has(E)) {
329
- j = !0;
328
+ if (A.paths.has(O)) {
329
+ D = !0;
330
330
  break;
331
331
  }
332
- const b = E.lastIndexOf(".");
333
- if (b !== -1) {
334
- const F = E.substring(
332
+ const k = O.lastIndexOf(".");
333
+ if (k !== -1) {
334
+ const U = O.substring(
335
335
  0,
336
- b
336
+ k
337
337
  );
338
338
  if (!isNaN(
339
- Number(E.substring(b + 1))
340
- ) && O.paths.has(F)) {
341
- j = !0;
339
+ Number(O.substring(k + 1))
340
+ ) && A.paths.has(U)) {
341
+ D = !0;
342
342
  break;
343
343
  }
344
- E = F;
344
+ O = U;
345
345
  } else
346
- E = "";
347
- if (E === "")
346
+ O = "";
347
+ if (O === "")
348
348
  break;
349
349
  }
350
- if (j) break;
350
+ if (D) break;
351
351
  }
352
- if (!j && G.includes("deps") && O.depsFunction) {
353
- const B = O.depsFunction(p);
354
- let E = !1;
355
- typeof B == "boolean" ? B && (E = !0) : Y(O.deps, B) || (O.deps = B, E = !0), E && (j = !0);
352
+ if (!D && G.includes("deps") && A.depsFunction) {
353
+ const B = A.depsFunction(E);
354
+ let O = !1;
355
+ typeof B == "boolean" ? B && (O = !0) : z(A.deps, B) || (A.deps = B, O = !0), O && (D = !0);
356
356
  }
357
- j && O.forceUpdate();
357
+ D && A.forceUpdate();
358
358
  }
359
359
  }
360
360
  }
361
361
  const $ = Date.now();
362
362
  o = o.map((M, y) => {
363
- const x = o.slice(0, -1), R = z(p, x);
364
- return y === o.length - 1 && ["insert", "cut"].includes(s.updateType) ? (R.length - 1).toString() : M;
363
+ const V = o.slice(0, -1), b = q(E, V);
364
+ return y === o.length - 1 && ["insert", "cut"].includes(s.updateType) ? (b.length - 1).toString() : M;
365
365
  });
366
- const { oldValue: k, newValue: D } = Je(
366
+ const { oldValue: x, newValue: j } = Je(
367
367
  s.updateType,
368
368
  u,
369
- p,
369
+ E,
370
370
  o
371
- ), q = {
371
+ ), J = {
372
372
  timeStamp: $,
373
373
  stateKey: I,
374
374
  path: o,
375
375
  updateType: s.updateType,
376
376
  status: "new",
377
- oldValue: k,
378
- newValue: D
377
+ oldValue: x,
378
+ newValue: j
379
379
  };
380
380
  switch (s.updateType) {
381
381
  case "update":
382
- f.updateShadowAtPath(I, o, p);
382
+ f.updateShadowAtPath(I, o, E);
383
383
  break;
384
384
  case "insert":
385
385
  const M = o.slice(0, -1);
386
- f.insertShadowArrayElement(I, M, D);
386
+ f.insertShadowArrayElement(I, M, j);
387
387
  break;
388
388
  case "cut":
389
- const y = o.slice(0, -1), x = parseInt(o[o.length - 1]);
390
- f.removeShadowArrayElement(I, y, x);
389
+ const y = o.slice(0, -1), V = parseInt(o[o.length - 1]);
390
+ f.removeShadowArrayElement(I, y, V);
391
391
  break;
392
392
  }
393
393
  if (Be(I, (M) => {
394
- const x = [...M ?? [], q].reduce((R, O) => {
395
- const j = `${O.stateKey}:${JSON.stringify(O.path)}`, G = R.get(j);
396
- return G ? (G.timeStamp = Math.max(G.timeStamp, O.timeStamp), G.newValue = O.newValue, G.oldValue = G.oldValue ?? O.oldValue, G.updateType = O.updateType) : R.set(j, { ...O }), R;
394
+ const V = [...M ?? [], J].reduce((b, A) => {
395
+ const D = `${A.stateKey}:${JSON.stringify(A.path)}`, G = b.get(D);
396
+ return G ? (G.timeStamp = Math.max(G.timeStamp, A.timeStamp), G.newValue = A.newValue, G.oldValue = G.oldValue ?? A.oldValue, G.updateType = A.updateType) : b.set(D, { ...A }), b;
397
397
  }, /* @__PURE__ */ new Map());
398
- return Array.from(x.values());
399
- }), $e(
400
- p,
398
+ return Array.from(V.values());
399
+ }), Ce(
400
+ E,
401
401
  I,
402
- V.current,
403
- U
404
- ), V.current?.middleware && V.current.middleware({
402
+ P.current,
403
+ R
404
+ ), P.current?.middleware && P.current.middleware({
405
405
  updateLog: l,
406
- update: q
407
- }), V.current?.serverSync) {
408
- const M = f.serverState[I], y = V.current?.serverSync;
406
+ update: J
407
+ }), P.current?.serverSync) {
408
+ const M = f.serverState[I], y = P.current?.serverSync;
409
409
  ze(I, {
410
- syncKey: typeof y.syncKey == "string" ? y.syncKey : y.syncKey({ state: p }),
410
+ syncKey: typeof y.syncKey == "string" ? y.syncKey : y.syncKey({ state: E }),
411
411
  rollBackState: M,
412
412
  actionTimeStamp: Date.now() + (y.debounce ?? 3e3),
413
413
  status: "waiting"
414
414
  });
415
415
  }
416
- return p;
416
+ return E;
417
417
  });
418
418
  };
419
419
  r.getState().updaterState[I] || (fe(
420
420
  I,
421
421
  Se(
422
422
  I,
423
- oe,
424
- K.current,
425
- U
423
+ ae,
424
+ ee.current,
425
+ R
426
426
  )
427
- ), r.getState().cogsStateStore[I] || te(I, e), r.getState().initialStateGlobal[I] || _e(I, e));
428
- const d = ye(() => Se(
427
+ ), r.getState().cogsStateStore[I] || te(I, e), r.getState().initialStateGlobal[I] || Ee(I, e));
428
+ const d = ve(() => Se(
429
429
  I,
430
- oe,
431
- K.current,
432
- U
433
- ), [I, U]);
434
- return [Re(I), d];
430
+ ae,
431
+ ee.current,
432
+ R
433
+ ), [I, R]);
434
+ return [be(I), d];
435
435
  }
436
436
  function Se(e, i, m, g) {
437
437
  const T = /* @__PURE__ */ new Map();
438
438
  let N = 0;
439
- const A = (h) => {
439
+ const p = (h) => {
440
440
  const n = h.join(".");
441
441
  for (const [S] of T)
442
442
  (S === n || S.startsWith(n + ".")) && T.delete(S);
443
443
  N++;
444
444
  }, v = {
445
445
  removeValidation: (h) => {
446
- h?.validationKey && J(h.validationKey);
446
+ h?.validationKey && Z(h.validationKey);
447
447
  },
448
448
  revertToInitialState: (h) => {
449
449
  const n = r.getState().getInitialOptions(e)?.validation;
450
- n?.key && J(n?.key), h?.validationKey && J(h.validationKey);
450
+ n?.key && Z(n?.key), h?.validationKey && Z(h.validationKey);
451
451
  const S = r.getState().initialStateGlobal[e];
452
452
  r.getState().clearSelectedIndexesForState(e), T.clear(), N++;
453
- const H = a(S, []), P = ne(e), U = X(P?.localStorage?.key) ? P?.localStorage?.key(S) : P?.localStorage?.key, W = `${g}-${e}-${U}`;
454
- W && localStorage.removeItem(W), fe(e, H), te(e, S);
453
+ const H = a(S, []), L = re(e), R = Q(L?.localStorage?.key) ? L?.localStorage?.key(S) : L?.localStorage?.key, F = `${g}-${e}-${R}`;
454
+ F && localStorage.removeItem(F), fe(e, H), te(e, S);
455
455
  const I = r.getState().stateComponents.get(e);
456
456
  return I && I.components.forEach((l) => {
457
457
  l.forceUpdate();
@@ -464,15 +464,15 @@ function Se(e, i, m, g) {
464
464
  i,
465
465
  m,
466
466
  g
467
- ), S = r.getState().initialStateGlobal[e], H = ne(e), P = X(H?.localStorage?.key) ? H?.localStorage?.key(S) : H?.localStorage?.key, U = `${g}-${e}-${P}`;
468
- return localStorage.getItem(U) && localStorage.removeItem(U), Ge(() => {
469
- _e(e, h), r.getState().initializeShadowState(e, h), fe(e, n), te(e, h);
470
- const W = r.getState().stateComponents.get(e);
471
- W && W.components.forEach((I) => {
467
+ ), S = r.getState().initialStateGlobal[e], H = re(e), L = Q(H?.localStorage?.key) ? H?.localStorage?.key(S) : H?.localStorage?.key, R = `${g}-${e}-${L}`;
468
+ return localStorage.getItem(R) && localStorage.removeItem(R), Ve(() => {
469
+ Ee(e, h), r.getState().initializeShadowState(e, h), fe(e, n), te(e, h);
470
+ const F = r.getState().stateComponents.get(e);
471
+ F && F.components.forEach((I) => {
472
472
  I.forceUpdate();
473
473
  });
474
474
  }), {
475
- fetchId: (W) => n.get()[W]
475
+ fetchId: (F) => n.get()[F]
476
476
  };
477
477
  },
478
478
  _initialState: r.getState().initialStateGlobal[e],
@@ -480,19 +480,19 @@ function Se(e, i, m, g) {
480
480
  _isLoading: r.getState().isLoadingGlobal[e],
481
481
  _isServerSynced: () => {
482
482
  const h = r.getState().serverState[e];
483
- return !!(h && Y(h, Re(e)));
483
+ return !!(h && z(h, be(e)));
484
484
  }
485
485
  };
486
486
  function a(h, n = [], S) {
487
487
  const H = n.map(String).join(".");
488
488
  T.get(H);
489
- const P = function() {
489
+ const L = function() {
490
490
  return r().getNestedState(e, n);
491
491
  };
492
492
  Object.keys(v).forEach((I) => {
493
- P[I] = v[I];
493
+ L[I] = v[I];
494
494
  });
495
- const U = {
495
+ const R = {
496
496
  apply(I, l, le) {
497
497
  return console.log(
498
498
  `PROXY APPLY TRAP HIT: stateKey=${e}, path=${n.join(".")}`
@@ -540,7 +540,7 @@ function Se(e, i, m, g) {
540
540
  }
541
541
  }
542
542
  if (l === "getDifferences")
543
- return () => Ae(
543
+ return () => ye(
544
544
  r.getState().cogsStateStore[e],
545
545
  r.getState().initialStateGlobal[e]
546
546
  );
@@ -554,8 +554,8 @@ function Se(e, i, m, g) {
554
554
  const c = await t.action(o);
555
555
  if (c && !c.success && c.errors && s) {
556
556
  r.getState().removeValidationError(s), c.errors.forEach((u) => {
557
- const p = [s, ...u.path].join(".");
558
- r.getState().addValidationError(p, u.message);
557
+ const E = [s, ...u.path].join(".");
558
+ r.getState().addValidationError(E, u.message);
559
559
  });
560
560
  const f = r.getState().stateComponents.get(e);
561
561
  f && f.components.forEach((u) => {
@@ -568,20 +568,20 @@ function Se(e, i, m, g) {
568
568
  }
569
569
  };
570
570
  if (l === "_status") {
571
- const d = r.getState().getNestedState(e, n), t = r.getState().initialStateGlobal[e], o = z(t, n);
572
- return Y(d, o) ? "fresh" : "stale";
571
+ const d = r.getState().getNestedState(e, n), t = r.getState().initialStateGlobal[e], o = q(t, n);
572
+ return z(d, o) ? "fresh" : "stale";
573
573
  }
574
574
  if (l === "getStatus")
575
575
  return function() {
576
576
  const d = r().getNestedState(
577
577
  e,
578
578
  n
579
- ), t = r.getState().initialStateGlobal[e], o = z(t, n);
580
- return Y(d, o) ? "fresh" : "stale";
579
+ ), t = r.getState().initialStateGlobal[e], o = q(t, n);
580
+ return z(d, o) ? "fresh" : "stale";
581
581
  };
582
582
  if (l === "removeStorage")
583
583
  return () => {
584
- const d = r.getState().initialStateGlobal[e], t = ne(e), o = X(t?.localStorage?.key) ? t?.localStorage?.key(d) : t?.localStorage?.key, s = `${g}-${e}-${o}`;
584
+ const d = r.getState().initialStateGlobal[e], t = re(e), o = Q(t?.localStorage?.key) ? t?.localStorage?.key(d) : t?.localStorage?.key, s = `${g}-${e}-${o}`;
585
585
  s && localStorage.removeItem(s);
586
586
  };
587
587
  if (l === "showValidationErrors")
@@ -622,134 +622,135 @@ function Se(e, i, m, g) {
622
622
  overscan: s = 6,
623
623
  stickToBottom: c = !1,
624
624
  dependencies: f = []
625
- } = t, u = Q(null), [p, _] = Z({
625
+ } = t, u = K(null), [E, w] = X({
626
626
  startIndex: 0,
627
627
  endIndex: 10
628
- }), [w, C] = Z("WAITING_FOR_ARRAY"), $ = Q(0), k = Q(f), [D, q] = Z(0);
629
- re(() => r.getState().subscribeToShadowState(e, () => {
630
- q((b) => b + 1);
628
+ }), [_, C] = X("IDLE_AT_TOP"), $ = K(0), x = K(f), [j, J] = X(0);
629
+ oe(() => r.getState().subscribeToShadowState(e, () => {
630
+ J((k) => k + 1);
631
631
  }), [e]);
632
632
  const M = r().getNestedState(
633
633
  e,
634
634
  n
635
- ), y = M.length, { totalHeight: x, positions: R } = ye(() => {
636
- const E = r.getState().getShadowMetadata(e, n) || [];
637
- let b = 0;
638
- const F = [];
639
- for (let L = 0; L < y; L++) {
640
- F[L] = b;
641
- const ee = E[L]?.virtualizer?.itemHeight;
642
- b += ee || o;
635
+ ), y = M.length, { totalHeight: V, positions: b } = ve(() => {
636
+ const O = r.getState().getShadowMetadata(e, n) || [];
637
+ let k = 0;
638
+ const U = [];
639
+ for (let W = 0; W < y; W++) {
640
+ U[W] = k;
641
+ const Y = O[W]?.virtualizer?.itemHeight;
642
+ k += Y || o;
643
643
  }
644
- return { totalHeight: b, positions: F };
644
+ return { totalHeight: k, positions: U };
645
645
  }, [
646
646
  y,
647
647
  e,
648
648
  n.join("."),
649
649
  o,
650
- D
651
- ]), O = ye(() => {
652
- const E = Math.max(0, p.startIndex), b = Math.min(y, p.endIndex), F = Array.from(
653
- { length: b - E },
654
- (ee, ae) => E + ae
655
- ), L = F.map((ee) => M[ee]);
656
- return a(L, n, {
650
+ j
651
+ ]), A = ve(() => {
652
+ const O = Math.max(0, E.startIndex), k = Math.min(y, E.endIndex), U = Array.from(
653
+ { length: k - O },
654
+ (Y, ne) => O + ne
655
+ ), W = U.map((Y) => M[Y]);
656
+ return a(W, n, {
657
657
  ...S,
658
- validIndices: F
658
+ validIndices: U
659
659
  });
660
- }, [p.startIndex, p.endIndex, M, y]);
660
+ }, [E.startIndex, E.endIndex, M, y]);
661
661
  ie(() => {
662
- const E = !Y(
662
+ const O = !z(
663
663
  f,
664
- k.current
665
- ), b = y > $.current;
666
- if (E) {
667
- console.log(
668
- "STATE_TRANSITION: Deps changed. -> WAITING_FOR_ARRAY"
669
- ), C("WAITING_FOR_ARRAY");
664
+ x.current
665
+ ), k = y > $.current;
666
+ if (O) {
667
+ console.log("TRANSITION: Deps changed -> IDLE_AT_TOP"), C("IDLE_AT_TOP");
670
668
  return;
671
669
  }
672
- b && w === "LOCKED_AT_BOTTOM" && c && (console.log(
673
- "STATE_TRANSITION: New items arrived while locked. -> GETTING_ARRAY_HEIGHTS"
674
- ), C("GETTING_ARRAY_HEIGHTS")), $.current = y, k.current = f;
670
+ k && _ === "LOCKED_AT_BOTTOM" && c && (console.log(
671
+ "TRANSITION: New items arrived while locked -> GETTING_HEIGHTS"
672
+ ), C("GETTING_HEIGHTS")), $.current = y, x.current = f;
675
673
  }, [y, ...f]), ie(() => {
676
- const E = u.current;
677
- if (!E) return;
678
- let b;
679
- if (w === "WAITING_FOR_ARRAY" && y > 0 && c)
674
+ const O = u.current;
675
+ if (!O) return;
676
+ let k;
677
+ if (_ === "IDLE_AT_TOP" && c && y > 0)
680
678
  console.log(
681
- "ACTION: WAITING_FOR_ARRAY -> GETTING_ARRAY_HEIGHTS"
682
- ), C("GETTING_ARRAY_HEIGHTS");
683
- else if (w === "GETTING_ARRAY_HEIGHTS")
679
+ "ACTION (IDLE_AT_TOP): Data has arrived -> GETTING_HEIGHTS"
680
+ ), C("GETTING_HEIGHTS");
681
+ else if (_ === "GETTING_HEIGHTS")
684
682
  console.log(
685
- "ACTION: GETTING_ARRAY_HEIGHTS. Setting range and starting loop."
686
- ), _({
683
+ "ACTION (GETTING_HEIGHTS): Setting range to end and starting loop."
684
+ ), w({
687
685
  startIndex: Math.max(0, y - 10 - s),
688
686
  endIndex: y
689
- }), b = setInterval(() => {
690
- const F = y - 1;
691
- ((r.getState().getShadowMetadata(e, n) || [])[F]?.virtualizer?.itemHeight || 0) > 0 && (clearInterval(b), console.log(
692
- "ACTION: Measurement success. -> MOVING_TO_BOTTOM"
693
- ), C("MOVING_TO_BOTTOM"));
687
+ }), k = setInterval(() => {
688
+ const U = y - 1;
689
+ ((r.getState().getShadowMetadata(e, n) || [])[U]?.virtualizer?.itemHeight || 0) > 0 && (clearInterval(k), console.log(
690
+ "ACTION (GETTING_HEIGHTS): Measurement success -> SCROLLING_TO_BOTTOM"
691
+ ), C("SCROLLING_TO_BOTTOM"));
694
692
  }, 100);
695
- else if (w === "MOVING_TO_BOTTOM") {
696
- console.log("ACTION: MOVING_TO_BOTTOM. Executing scroll.");
697
- const F = $.current === 0 ? "auto" : "smooth";
698
- E.scrollTo({
699
- top: E.scrollHeight,
700
- behavior: F
693
+ else if (_ === "SCROLLING_TO_BOTTOM") {
694
+ console.log(
695
+ "ACTION (SCROLLING_TO_BOTTOM): Executing scroll."
696
+ );
697
+ const U = $.current === 0 ? "auto" : "smooth";
698
+ O.scrollTo({
699
+ top: O.scrollHeight,
700
+ behavior: U
701
701
  });
702
- const L = setTimeout(
702
+ const W = setTimeout(
703
703
  () => {
704
704
  console.log(
705
- "ACTION: Scroll finished. -> LOCKED_AT_BOTTOM"
705
+ "ACTION (SCROLLING_TO_BOTTOM): Scroll finished -> LOCKED_AT_BOTTOM"
706
706
  ), C("LOCKED_AT_BOTTOM");
707
707
  },
708
- F === "smooth" ? 500 : 50
708
+ U === "smooth" ? 500 : 50
709
709
  );
710
- return () => clearTimeout(L);
710
+ return () => clearTimeout(W);
711
711
  }
712
712
  return () => {
713
- b && clearInterval(b);
713
+ k && clearInterval(k);
714
714
  };
715
- }, [w, y, R]), re(() => {
716
- const E = u.current;
717
- if (!E) return;
718
- const b = () => {
719
- !(E.scrollHeight - E.scrollTop - E.clientHeight < 1) && (w === "LOCKED_AT_BOTTOM" || w === "MOVING_TO_BOTTOM") && (console.log(
720
- "USER_ACTION: Scrolled up. -> IDLE_NOT_AT_BOTTOM"
721
- ), C("IDLE_NOT_AT_BOTTOM"));
722
- const { scrollTop: L, clientHeight: ee } = E;
723
- let ae = 0, de = y - 1;
724
- for (; ae <= de; ) {
725
- const he = Math.floor((ae + de) / 2);
726
- R[he] < L ? ae = he + 1 : de = he - 1;
715
+ }, [_, y, b]), oe(() => {
716
+ const O = u.current;
717
+ if (!O) return;
718
+ const k = () => {
719
+ _ !== "IDLE_NOT_AT_BOTTOM" && (O.scrollHeight - O.scrollTop - O.clientHeight < 1 || (console.log(
720
+ "USER ACTION: Scrolled up -> IDLE_NOT_AT_BOTTOM"
721
+ ), C("IDLE_NOT_AT_BOTTOM")));
722
+ const { scrollTop: U, clientHeight: W } = O;
723
+ let Y = 0, ne = y - 1;
724
+ for (; Y <= ne; ) {
725
+ const ue = Math.floor((Y + ne) / 2);
726
+ b[ue] < U ? Y = ue + 1 : ne = ue - 1;
727
727
  }
728
- const we = Math.max(0, de - s);
729
- let ue = we;
730
- const Ve = L + ee;
731
- for (; ue < y && R[ue] < Ve; )
732
- ue++;
733
- _({
728
+ const we = Math.max(0, ne - s);
729
+ let de = we;
730
+ const xe = U + W;
731
+ for (; de < y && b[de] < xe; )
732
+ de++;
733
+ w({
734
734
  startIndex: we,
735
- endIndex: Math.min(y, ue + s)
735
+ endIndex: Math.min(y, de + s)
736
736
  });
737
737
  };
738
- return E.addEventListener("scroll", b, {
738
+ return O.addEventListener("scroll", k, {
739
739
  passive: !0
740
- }), () => E.removeEventListener("scroll", b);
741
- }, [y, R, w]);
742
- const j = Ee(
743
- (E = "smooth") => {
744
- console.log(
745
- "USER_ACTION: Clicked scroll to bottom button. -> MOVING_TO_BOTTOM"
746
- ), C("MOVING_TO_BOTTOM");
747
- },
748
- []
749
- ), G = Ee(
750
- (E, b = "smooth") => {
740
+ }), () => O.removeEventListener("scroll", k);
741
+ }, [y, b, _]);
742
+ const D = _e(() => {
743
+ console.log(
744
+ "USER ACTION: Clicked scroll button -> SCROLLING_TO_BOTTOM"
745
+ ), C("SCROLLING_TO_BOTTOM");
746
+ }, []), G = _e(
747
+ (O, k = "smooth") => {
748
+ u.current && b[O] !== void 0 && (C("IDLE_NOT_AT_BOTTOM"), u.current.scrollTo({
749
+ top: b[O],
750
+ behavior: k
751
+ }));
751
752
  },
752
- [R]
753
+ [b]
753
754
  ), B = {
754
755
  outer: {
755
756
  ref: u,
@@ -757,27 +758,27 @@ function Se(e, i, m, g) {
757
758
  },
758
759
  inner: {
759
760
  style: {
760
- height: `${x}px`,
761
+ height: `${V}px`,
761
762
  position: "relative"
762
763
  }
763
764
  },
764
765
  list: {
765
766
  style: {
766
- transform: `translateY(${R[p.startIndex] || 0}px)`
767
+ transform: `translateY(${b[E.startIndex] || 0}px)`
767
768
  }
768
769
  }
769
770
  };
770
771
  return {
771
- virtualState: O,
772
+ virtualState: A,
772
773
  virtualizerProps: B,
773
- scrollToBottom: j,
774
+ scrollToBottom: D,
774
775
  scrollToIndex: G
775
776
  };
776
777
  };
777
778
  if (l === "stateSort")
778
779
  return (t) => {
779
780
  const s = [...d()].sort(
780
- (u, p) => t(u.item, p.item)
781
+ (u, E) => t(u.item, E.item)
781
782
  ), c = s.map(({ item: u }) => u), f = {
782
783
  ...S,
783
784
  validIndices: s.map(
@@ -789,7 +790,7 @@ function Se(e, i, m, g) {
789
790
  if (l === "stateFilter")
790
791
  return (t) => {
791
792
  const s = d().filter(
792
- ({ item: u }, p) => t(u, p)
793
+ ({ item: u }, E) => t(u, E)
793
794
  ), c = s.map(({ item: u }) => u), f = {
794
795
  ...S,
795
796
  validIndices: s.map(
@@ -802,20 +803,20 @@ function Se(e, i, m, g) {
802
803
  return (t) => {
803
804
  const o = r.getState().getNestedState(e, n);
804
805
  return Array.isArray(o) ? (S?.validIndices || Array.from({ length: o.length }, (c, f) => f)).map((c, f) => {
805
- const u = o[c], p = [...n, c.toString()], _ = a(u, p, S);
806
- return t(u, _, {
806
+ const u = o[c], E = [...n, c.toString()], w = a(u, E, S);
807
+ return t(u, w, {
807
808
  register: () => {
808
- const [, C] = Z({}), $ = `${m}-${n.join(".")}-${c}`;
809
+ const [, C] = X({}), $ = `${m}-${n.join(".")}-${c}`;
809
810
  ie(() => {
810
- const k = `${e}////${$}`, D = r.getState().stateComponents.get(e) || {
811
+ const x = `${e}////${$}`, j = r.getState().stateComponents.get(e) || {
811
812
  components: /* @__PURE__ */ new Map()
812
813
  };
813
- return D.components.set(k, {
814
+ return j.components.set(x, {
814
815
  forceUpdate: () => C({}),
815
- paths: /* @__PURE__ */ new Set([p.join(".")])
816
- }), r.getState().stateComponents.set(e, D), () => {
817
- const q = r.getState().stateComponents.get(e);
818
- q && q.components.delete(k);
816
+ paths: /* @__PURE__ */ new Set([E.join(".")])
817
+ }), r.getState().stateComponents.set(e, j), () => {
818
+ const J = r.getState().stateComponents.get(e);
819
+ J && J.components.delete(x);
819
820
  };
820
821
  }, [e, $]);
821
822
  },
@@ -831,17 +832,17 @@ function Se(e, i, m, g) {
831
832
  return (t) => h.map((s, c) => {
832
833
  let f;
833
834
  S?.validIndices && S.validIndices[c] !== void 0 ? f = S.validIndices[c] : f = c;
834
- const u = [...n, f.toString()], p = a(s, u, S);
835
+ const u = [...n, f.toString()], E = a(s, u, S);
835
836
  return t(
836
837
  s,
837
- p,
838
+ E,
838
839
  c,
839
840
  h,
840
841
  a(h, n, S)
841
842
  );
842
843
  });
843
844
  if (l === "$stateMap")
844
- return (t) => ce(Xe, {
845
+ return (t) => ce(Ze, {
845
846
  proxy: {
846
847
  _stateKey: e,
847
848
  _path: n,
@@ -854,15 +855,15 @@ function Se(e, i, m, g) {
854
855
  return (t) => {
855
856
  const o = r.getState().getNestedState(e, n);
856
857
  return Array.isArray(o) ? (S?.validIndices || Array.from({ length: o.length }, (c, f) => f)).map((c, f) => {
857
- const u = o[c], p = [...n, c.toString()], _ = a(u, p, S), w = `${m}-${n.join(".")}-${c}`;
858
- return ce(Ke, {
858
+ const u = o[c], E = [...n, c.toString()], w = a(u, E, S), _ = `${m}-${n.join(".")}-${c}`;
859
+ return ce(Qe, {
859
860
  key: c,
860
861
  stateKey: e,
861
- itemComponentId: w,
862
- itemPath: p,
862
+ itemComponentId: _,
863
+ itemPath: E,
863
864
  children: t(
864
865
  u,
865
- _,
866
+ w,
866
867
  f,
867
868
  o,
868
869
  a(o, n, S)
@@ -898,36 +899,36 @@ function Se(e, i, m, g) {
898
899
  return a(s, c);
899
900
  };
900
901
  if (l === "insert")
901
- return (t) => (A(n), Te(i, t, n, e), a(
902
+ return (t) => (p(n), he(i, t, n, e), a(
902
903
  r.getState().getNestedState(e, n),
903
904
  n
904
905
  ));
905
906
  if (l === "uniqueInsert")
906
907
  return (t, o, s) => {
907
- const c = r.getState().getNestedState(e, n), f = X(t) ? t(c) : t;
908
+ const c = r.getState().getNestedState(e, n), f = Q(t) ? t(c) : t;
908
909
  let u = null;
909
- if (!c.some((_) => {
910
+ if (!c.some((w) => {
910
911
  if (o) {
911
912
  const C = o.every(
912
- ($) => Y(_[$], f[$])
913
+ ($) => z(w[$], f[$])
913
914
  );
914
- return C && (u = _), C;
915
+ return C && (u = w), C;
915
916
  }
916
- const w = Y(_, f);
917
- return w && (u = _), w;
917
+ const _ = z(w, f);
918
+ return _ && (u = w), _;
918
919
  }))
919
- A(n), Te(i, f, n, e);
920
+ p(n), he(i, f, n, e);
920
921
  else if (s && u) {
921
- const _ = s(u), w = c.map(
922
- (C) => Y(C, u) ? _ : C
922
+ const w = s(u), _ = c.map(
923
+ (C) => z(C, u) ? w : C
923
924
  );
924
- A(n), se(i, w, n);
925
+ p(n), se(i, _, n);
925
926
  }
926
927
  };
927
928
  if (l === "cut")
928
929
  return (t, o) => {
929
930
  if (!o?.waitForSync)
930
- return A(n), ge(i, n, e, t), a(
931
+ return p(n), ge(i, n, e, t), a(
931
932
  r.getState().getNestedState(e, n),
932
933
  n
933
934
  );
@@ -940,7 +941,7 @@ function Se(e, i, m, g) {
940
941
  if (l === "toggleByValue")
941
942
  return (t) => {
942
943
  const o = h.findIndex((s) => s === t);
943
- o > -1 ? ge(i, n, e, o) : Te(i, t, n, e);
944
+ o > -1 ? ge(i, n, e, o) : he(i, t, n, e);
944
945
  };
945
946
  if (l === "stateFind")
946
947
  return (t) => {
@@ -961,15 +962,15 @@ function Se(e, i, m, g) {
961
962
  return a(c.item, f, S);
962
963
  };
963
964
  }
964
- const K = n[n.length - 1];
965
- if (!isNaN(Number(K))) {
965
+ const ee = n[n.length - 1];
966
+ if (!isNaN(Number(ee))) {
966
967
  const d = n.slice(0, -1), t = r.getState().getNestedState(e, d);
967
968
  if (Array.isArray(t) && l === "cut")
968
969
  return () => ge(
969
970
  i,
970
971
  d,
971
972
  e,
972
- Number(K)
973
+ Number(ee)
973
974
  );
974
975
  }
975
976
  if (l === "get")
@@ -981,13 +982,13 @@ function Se(e, i, m, g) {
981
982
  return r.getState().getNestedState(e, n);
982
983
  };
983
984
  if (l === "$derive")
984
- return (d) => be({
985
+ return (d) => $e({
985
986
  _stateKey: e,
986
987
  _path: n,
987
988
  _effect: d.toString()
988
989
  });
989
990
  if (l === "$get")
990
- return () => be({
991
+ return () => $e({
991
992
  _stateKey: e,
992
993
  _path: n
993
994
  });
@@ -1006,7 +1007,7 @@ function Se(e, i, m, g) {
1006
1007
  const t = n.slice(0, -1), o = Number(n[n.length - 1]), s = t.join(".");
1007
1008
  d ? r.getState().setSelectedIndex(e, s, o) : r.getState().setSelectedIndex(e, s, void 0);
1008
1009
  const c = r.getState().getNestedState(e, [...t]);
1009
- se(i, c, t), A(t);
1010
+ se(i, c, t), p(t);
1010
1011
  };
1011
1012
  if (l === "toggleSelected")
1012
1013
  return () => {
@@ -1017,13 +1018,13 @@ function Se(e, i, m, g) {
1017
1018
  s === t ? void 0 : t
1018
1019
  );
1019
1020
  const c = r.getState().getNestedState(e, [...d]);
1020
- se(i, c, d), A(d);
1021
+ se(i, c, d), p(d);
1021
1022
  };
1022
1023
  if (n.length == 0) {
1023
1024
  if (l === "applyJsonPatch")
1024
1025
  return (d) => {
1025
- const t = r.getState().cogsStateStore[e], s = He(t, d).newDocument;
1026
- ke(
1026
+ const t = r.getState().cogsStateStore[e], s = je(t, d).newDocument;
1027
+ Me(
1027
1028
  e,
1028
1029
  r.getState().initialStateGlobal[e],
1029
1030
  s,
@@ -1033,57 +1034,57 @@ function Se(e, i, m, g) {
1033
1034
  );
1034
1035
  const c = r.getState().stateComponents.get(e);
1035
1036
  if (c) {
1036
- const f = Ae(t, s), u = new Set(f);
1037
+ const f = ye(t, s), u = new Set(f);
1037
1038
  for (const [
1038
- p,
1039
- _
1039
+ E,
1040
+ w
1040
1041
  ] of c.components.entries()) {
1041
- let w = !1;
1042
- const C = Array.isArray(_.reactiveType) ? _.reactiveType : [_.reactiveType || "component"];
1042
+ let _ = !1;
1043
+ const C = Array.isArray(w.reactiveType) ? w.reactiveType : [w.reactiveType || "component"];
1043
1044
  if (!C.includes("none")) {
1044
1045
  if (C.includes("all")) {
1045
- _.forceUpdate();
1046
+ w.forceUpdate();
1046
1047
  continue;
1047
1048
  }
1048
- if (C.includes("component") && (_.paths.has("") && (w = !0), !w))
1049
+ if (C.includes("component") && (w.paths.has("") && (_ = !0), !_))
1049
1050
  for (const $ of u) {
1050
- if (_.paths.has($)) {
1051
- w = !0;
1051
+ if (w.paths.has($)) {
1052
+ _ = !0;
1052
1053
  break;
1053
1054
  }
1054
- let k = $.lastIndexOf(".");
1055
- for (; k !== -1; ) {
1056
- const D = $.substring(0, k);
1057
- if (_.paths.has(D)) {
1058
- w = !0;
1055
+ let x = $.lastIndexOf(".");
1056
+ for (; x !== -1; ) {
1057
+ const j = $.substring(0, x);
1058
+ if (w.paths.has(j)) {
1059
+ _ = !0;
1059
1060
  break;
1060
1061
  }
1061
- const q = $.substring(
1062
- k + 1
1062
+ const J = $.substring(
1063
+ x + 1
1063
1064
  );
1064
- if (!isNaN(Number(q))) {
1065
- const M = D.lastIndexOf(".");
1065
+ if (!isNaN(Number(J))) {
1066
+ const M = j.lastIndexOf(".");
1066
1067
  if (M !== -1) {
1067
- const y = D.substring(
1068
+ const y = j.substring(
1068
1069
  0,
1069
1070
  M
1070
1071
  );
1071
- if (_.paths.has(y)) {
1072
- w = !0;
1072
+ if (w.paths.has(y)) {
1073
+ _ = !0;
1073
1074
  break;
1074
1075
  }
1075
1076
  }
1076
1077
  }
1077
- k = D.lastIndexOf(".");
1078
+ x = j.lastIndexOf(".");
1078
1079
  }
1079
- if (w) break;
1080
+ if (_) break;
1080
1081
  }
1081
- if (!w && C.includes("deps") && _.depsFunction) {
1082
- const $ = _.depsFunction(s);
1083
- let k = !1;
1084
- typeof $ == "boolean" ? $ && (k = !0) : Y(_.deps, $) || (_.deps = $, k = !0), k && (w = !0);
1082
+ if (!_ && C.includes("deps") && w.depsFunction) {
1083
+ const $ = w.depsFunction(s);
1084
+ let x = !1;
1085
+ typeof $ == "boolean" ? $ && (x = !0) : z(w.deps, $) || (w.deps = $, x = !0), x && (_ = !0);
1085
1086
  }
1086
- w && _.forceUpdate();
1087
+ _ && w.forceUpdate();
1087
1088
  }
1088
1089
  }
1089
1090
  }
@@ -1095,17 +1096,17 @@ function Se(e, i, m, g) {
1095
1096
  throw new Error("Zod schema not found");
1096
1097
  if (!d?.key)
1097
1098
  throw new Error("Validation key not found");
1098
- J(d.key);
1099
+ Z(d.key);
1099
1100
  const o = r.getState().cogsStateStore[e];
1100
1101
  try {
1101
1102
  const s = r.getState().getValidationErrors(d.key);
1102
1103
  s && s.length > 0 && s.forEach(([f]) => {
1103
- f && f.startsWith(d.key) && J(f);
1104
+ f && f.startsWith(d.key) && Z(f);
1104
1105
  });
1105
1106
  const c = d.zodSchema.safeParse(o);
1106
1107
  return c.success ? !0 : (c.error.errors.forEach((u) => {
1107
- const p = u.path, _ = u.message, w = [d.key, ...p].join(".");
1108
- t(w, _);
1108
+ const E = u.path, w = u.message, _ = [d.key, ...E].join(".");
1109
+ t(_, w);
1109
1110
  }), Ie(e), !1);
1110
1111
  } catch (s) {
1111
1112
  return console.error("Zod schema validation failed", s), !1;
@@ -1133,8 +1134,8 @@ function Se(e, i, m, g) {
1133
1134
  return ({
1134
1135
  children: d,
1135
1136
  hideMessage: t
1136
- }) => /* @__PURE__ */ ve(
1137
- je,
1137
+ }) => /* @__PURE__ */ Te(
1138
+ Re,
1138
1139
  {
1139
1140
  formOpts: t ? { validation: { message: "" } } : void 0,
1140
1141
  path: n,
@@ -1150,7 +1151,7 @@ function Se(e, i, m, g) {
1150
1151
  if (l === "update")
1151
1152
  return (d, t) => {
1152
1153
  if (t?.debounce)
1153
- Ue(() => {
1154
+ Le(() => {
1154
1155
  se(i, d, n, "");
1155
1156
  const o = r.getState().getNestedState(e, n);
1156
1157
  t?.afterUpdate && t.afterUpdate(o);
@@ -1160,11 +1161,11 @@ function Se(e, i, m, g) {
1160
1161
  const o = r.getState().getNestedState(e, n);
1161
1162
  t?.afterUpdate && t.afterUpdate(o);
1162
1163
  }
1163
- A(n);
1164
+ p(n);
1164
1165
  };
1165
1166
  if (l === "formElement")
1166
- return (d, t) => /* @__PURE__ */ ve(
1167
- Fe,
1167
+ return (d, t) => /* @__PURE__ */ Te(
1168
+ De,
1168
1169
  {
1169
1170
  setState: i,
1170
1171
  stateKey: e,
@@ -1173,23 +1174,23 @@ function Se(e, i, m, g) {
1173
1174
  formOpts: t
1174
1175
  }
1175
1176
  );
1176
- const V = [...n, l], oe = r.getState().getNestedState(e, V);
1177
- return a(oe, V, S);
1177
+ const P = [...n, l], ae = r.getState().getNestedState(e, P);
1178
+ return a(ae, P, S);
1178
1179
  }
1179
- }, W = new Proxy(P, U);
1180
+ }, F = new Proxy(L, R);
1180
1181
  return T.set(H, {
1181
- proxy: W,
1182
+ proxy: F,
1182
1183
  stateVersion: N
1183
- }), W;
1184
+ }), F;
1184
1185
  }
1185
1186
  return a(
1186
1187
  r.getState().getNestedState(e, [])
1187
1188
  );
1188
1189
  }
1189
- function be(e) {
1190
- return ce(Qe, { proxy: e });
1190
+ function $e(e) {
1191
+ return ce(Xe, { proxy: e });
1191
1192
  }
1192
- function Xe({
1193
+ function Ze({
1193
1194
  proxy: e,
1194
1195
  rebuildStateShape: i
1195
1196
  }) {
@@ -1198,23 +1199,23 @@ function Xe({
1198
1199
  m,
1199
1200
  e._path
1200
1201
  ).stateMapNoRender(
1201
- (T, N, A, v, a) => e._mapFn(T, N, A, v, a)
1202
+ (T, N, p, v, a) => e._mapFn(T, N, p, v, a)
1202
1203
  ) : null;
1203
1204
  }
1204
- function Qe({
1205
+ function Xe({
1205
1206
  proxy: e
1206
1207
  }) {
1207
- const i = Q(null), m = `${e._stateKey}-${e._path.join(".")}`;
1208
- return re(() => {
1208
+ const i = K(null), m = `${e._stateKey}-${e._path.join(".")}`;
1209
+ return oe(() => {
1209
1210
  const g = i.current;
1210
1211
  if (!g || !g.parentElement) return;
1211
- const T = g.parentElement, A = Array.from(T.childNodes).indexOf(g);
1212
+ const T = g.parentElement, p = Array.from(T.childNodes).indexOf(g);
1212
1213
  let v = T.getAttribute("data-parent-id");
1213
1214
  v || (v = `parent-${crypto.randomUUID()}`, T.setAttribute("data-parent-id", v));
1214
1215
  const h = {
1215
1216
  instanceId: `instance-${crypto.randomUUID()}`,
1216
1217
  parentId: v,
1217
- position: A,
1218
+ position: p,
1218
1219
  effect: e._effect
1219
1220
  };
1220
1221
  r.getState().addSignalElement(m, h);
@@ -1226,8 +1227,8 @@ function Qe({
1226
1227
  "state",
1227
1228
  `return (${e._effect})(state)`
1228
1229
  )(n);
1229
- } catch (P) {
1230
- console.error("Error evaluating effect function during mount:", P), S = n;
1230
+ } catch (L) {
1231
+ console.error("Error evaluating effect function during mount:", L), S = n;
1231
1232
  }
1232
1233
  else
1233
1234
  S = n;
@@ -1240,8 +1241,8 @@ function Qe({
1240
1241
  "data-signal-id": m
1241
1242
  });
1242
1243
  }
1243
- function St(e) {
1244
- const i = xe(
1244
+ function ft(e) {
1245
+ const i = Pe(
1245
1246
  (m) => {
1246
1247
  const g = r.getState().stateComponents.get(e._stateKey) || {
1247
1248
  components: /* @__PURE__ */ new Map()
@@ -1255,20 +1256,20 @@ function St(e) {
1255
1256
  );
1256
1257
  return ce("text", {}, String(i));
1257
1258
  }
1258
- function Ke({
1259
+ function Qe({
1259
1260
  stateKey: e,
1260
1261
  itemComponentId: i,
1261
1262
  itemPath: m,
1262
1263
  children: g
1263
1264
  }) {
1264
- const [, T] = Z({}), [N, A] = We(), v = Q(null);
1265
- return re(() => {
1266
- A.height > 0 && A.height !== v.current && (v.current = A.height, r.getState().setShadowMetadata(e, m, {
1265
+ const [, T] = X({}), [N, p] = He(), v = K(null);
1266
+ return oe(() => {
1267
+ p.height > 0 && p.height !== v.current && (v.current = p.height, r.getState().setShadowMetadata(e, m, {
1267
1268
  virtualizer: {
1268
- itemHeight: A.height
1269
+ itemHeight: p.height
1269
1270
  }
1270
1271
  }));
1271
- }, [A.height, e, m]), ie(() => {
1272
+ }, [p.height, e, m]), ie(() => {
1272
1273
  const a = `${e}////${i}`, h = r.getState().stateComponents.get(e) || {
1273
1274
  components: /* @__PURE__ */ new Map()
1274
1275
  };
@@ -1279,14 +1280,14 @@ function Ke({
1279
1280
  const n = r.getState().stateComponents.get(e);
1280
1281
  n && n.components.delete(a);
1281
1282
  };
1282
- }, [e, i, m.join(".")]), /* @__PURE__ */ ve("div", { ref: N, children: g });
1283
+ }, [e, i, m.join(".")]), /* @__PURE__ */ Te("div", { ref: N, children: g });
1283
1284
  }
1284
1285
  export {
1285
- be as $cogsSignal,
1286
- St as $cogsSignalStore,
1287
- ut as addStateOptions,
1288
- gt as createCogsState,
1289
- ft as notifyComponent,
1290
- Ze as useCogsStateFn
1286
+ $e as $cogsSignal,
1287
+ ft as $cogsSignalStore,
1288
+ dt as addStateOptions,
1289
+ ut as createCogsState,
1290
+ gt as notifyComponent,
1291
+ Ye as useCogsStateFn
1291
1292
  };
1292
1293
  //# sourceMappingURL=CogsState.jsx.map