cogsbox-state 0.5.366 → 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,39 +1,39 @@
1
1
  "use client";
2
- import { jsx as ve } from "react/jsx-runtime";
3
- import { useState as Z, useRef as Q, useEffect as oe, useLayoutEffect as ie, useMemo as ye, createElement as ce, useSyncExternalStore as xe, startTransition as Pe, useCallback as Ee } from "react";
4
- import { transformStateFunc as Ge, 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 Le 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 = re(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
38
  const [g, T] = Ge(m);
39
39
  (Object.keys(T).length > 0 || i && Object.keys(i).length > 0) && Object.keys(T).forEach((v) => {
@@ -46,13 +46,13 @@ const gt = (e, i) => {
46
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, [L, G] = 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 G;
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
80
  getInitialOptions: re,
81
- getKeyState: Re,
82
- getValidationErrors: We,
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 [L, G] = 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 = re(I) ?? null, oe(() => {
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,
@@ -212,25 +212,25 @@ function Ze(e, {
212
212
  }
213
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
- _,
229
+ w,
230
230
  ae,
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") || G({});
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,23 +238,23 @@ 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: () => G({}),
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), G({}), () => {
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
  }, []);
@@ -265,155 +265,155 @@ function Ze(e, {
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 }) => {
282
- const P = document.querySelector(
283
- `[data-parent-id="${R}"]`
280
+ const V = M ? q(E, o.slice(0, -1)) : q(E, o);
281
+ y.forEach(({ parentId: b, position: A, effect: D }) => {
282
+ const G = document.querySelector(
283
+ `[data-parent-id="${b}"]`
284
284
  );
285
- if (P) {
286
- const B = Array.from(P.childNodes);
287
- if (B[O]) {
288
- const E = j ? new Function("state", `return (${j})(state)`)(x) : x;
289
- B[O].textContent = String(E);
285
+ if (G) {
286
+ const B = Array.from(G.childNodes);
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 && We(
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 P = Array.isArray(O.reactiveType) ? O.reactiveType : [O.reactiveType || "component"];
319
- if (console.log("component", O), !P.includes("none")) {
320
- if (P.includes("all")) {
321
- O.forceUpdate();
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
+ if (G.includes("all")) {
321
+ A.forceUpdate();
322
322
  continue;
323
323
  }
324
- if (P.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 H = 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(H)) {
341
- j = !0;
339
+ Number(O.substring(k + 1))
340
+ ) && A.paths.has(U)) {
341
+ D = !0;
342
342
  break;
343
343
  }
344
- E = H;
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 && P.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)}`, P = R.get(j);
396
- return P ? (P.timeStamp = Math.max(P.timeStamp, O.timeStamp), P.newValue = O.newValue, P.oldValue = P.oldValue ?? O.oldValue, P.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(
@@ -421,37 +421,37 @@ function Ze(e, {
421
421
  Se(
422
422
  I,
423
423
  ae,
424
- K.current,
425
- U
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
430
  ae,
431
- K.current,
432
- U
433
- ), [I, U]);
434
- return [Re(I), d];
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 L = a(S, []), G = re(e), U = X(G?.localStorage?.key) ? G?.localStorage?.key(S) : G?.localStorage?.key, W = `${g}-${e}-${U}`;
454
- W && localStorage.removeItem(W), fe(e, L), 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], L = re(e), G = X(L?.localStorage?.key) ? L?.localStorage?.key(S) : L?.localStorage?.key, U = `${g}-${e}-${G}`;
468
- return localStorage.getItem(U) && localStorage.removeItem(U), Pe(() => {
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
- const L = n.map(String).join(".");
488
- T.get(L);
489
- const G = function() {
487
+ const H = n.map(String).join(".");
488
+ T.get(H);
489
+ const L = function() {
490
490
  return r().getNestedState(e, n);
491
491
  };
492
492
  Object.keys(v).forEach((I) => {
493
- G[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 = re(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,132 +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);
628
+ }), [_, C] = X("IDLE_AT_TOP"), $ = K(0), x = K(f), [j, J] = X(0);
629
629
  oe(() => r.getState().subscribeToShadowState(e, () => {
630
- q((b) => b + 1);
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 H = [];
639
- for (let F = 0; F < y; F++) {
640
- H[F] = b;
641
- const ee = E[F]?.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: H };
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), H = Array.from(
653
- { length: b - E },
654
- (ee, ne) => E + ne
655
- ), F = H.map((ee) => M[ee]);
656
- return a(F, 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: H
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, H;
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
701
- }), H = setTimeout(
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
+ });
702
+ const W = setTimeout(
702
703
  () => {
703
704
  console.log(
704
- "ACTION: Scroll finished. -> LOCKED_AT_BOTTOM"
705
+ "ACTION (SCROLLING_TO_BOTTOM): Scroll finished -> LOCKED_AT_BOTTOM"
705
706
  ), C("LOCKED_AT_BOTTOM");
706
707
  },
707
- F === "smooth" ? 500 : 50
708
+ U === "smooth" ? 500 : 50
708
709
  );
710
+ return () => clearTimeout(W);
709
711
  }
710
712
  return () => {
711
- b && (console.log("CLEANUP: Clearing measurement loop timer."), clearInterval(b)), H && (console.log("CLEANUP: Clearing scroll-end timer."), clearTimeout(H));
713
+ k && clearInterval(k);
712
714
  };
713
- }, [w, y, R]), oe(() => {
714
- const E = u.current;
715
- if (!E) return;
716
- const b = () => {
717
- !(E.scrollHeight - E.scrollTop - E.clientHeight < 1) && (w === "LOCKED_AT_BOTTOM" || w === "MOVING_TO_BOTTOM") && (console.log(
718
- "USER_ACTION: Scrolled up. -> IDLE_NOT_AT_BOTTOM"
719
- ), C("IDLE_NOT_AT_BOTTOM"));
720
- const { scrollTop: F, clientHeight: ee } = E;
721
- let ne = 0, de = y - 1;
722
- for (; ne <= de; ) {
723
- const he = Math.floor((ne + de) / 2);
724
- R[he] < F ? ne = 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;
725
727
  }
726
- const we = Math.max(0, de - s);
727
- let ue = we;
728
- const Ve = F + ee;
729
- for (; ue < y && R[ue] < Ve; )
730
- ue++;
731
- _({
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({
732
734
  startIndex: we,
733
- endIndex: Math.min(y, ue + s)
735
+ endIndex: Math.min(y, de + s)
734
736
  });
735
737
  };
736
- return E.addEventListener("scroll", b, {
738
+ return O.addEventListener("scroll", k, {
737
739
  passive: !0
738
- }), () => E.removeEventListener("scroll", b);
739
- }, [y, R, w]);
740
- const j = Ee(
741
- (E = "smooth") => {
742
- console.log(
743
- "USER_ACTION: Clicked scroll to bottom button. -> MOVING_TO_BOTTOM"
744
- ), C("MOVING_TO_BOTTOM");
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
+ }));
745
752
  },
746
- []
747
- ), P = Ee(
748
- (E, b = "smooth") => {
749
- },
750
- [R]
753
+ [b]
751
754
  ), B = {
752
755
  outer: {
753
756
  ref: u,
@@ -755,27 +758,27 @@ function Se(e, i, m, g) {
755
758
  },
756
759
  inner: {
757
760
  style: {
758
- height: `${x}px`,
761
+ height: `${V}px`,
759
762
  position: "relative"
760
763
  }
761
764
  },
762
765
  list: {
763
766
  style: {
764
- transform: `translateY(${R[p.startIndex] || 0}px)`
767
+ transform: `translateY(${b[E.startIndex] || 0}px)`
765
768
  }
766
769
  }
767
770
  };
768
771
  return {
769
- virtualState: O,
772
+ virtualState: A,
770
773
  virtualizerProps: B,
771
- scrollToBottom: j,
772
- scrollToIndex: P
774
+ scrollToBottom: D,
775
+ scrollToIndex: G
773
776
  };
774
777
  };
775
778
  if (l === "stateSort")
776
779
  return (t) => {
777
780
  const s = [...d()].sort(
778
- (u, p) => t(u.item, p.item)
781
+ (u, E) => t(u.item, E.item)
779
782
  ), c = s.map(({ item: u }) => u), f = {
780
783
  ...S,
781
784
  validIndices: s.map(
@@ -787,7 +790,7 @@ function Se(e, i, m, g) {
787
790
  if (l === "stateFilter")
788
791
  return (t) => {
789
792
  const s = d().filter(
790
- ({ item: u }, p) => t(u, p)
793
+ ({ item: u }, E) => t(u, E)
791
794
  ), c = s.map(({ item: u }) => u), f = {
792
795
  ...S,
793
796
  validIndices: s.map(
@@ -800,20 +803,20 @@ function Se(e, i, m, g) {
800
803
  return (t) => {
801
804
  const o = r.getState().getNestedState(e, n);
802
805
  return Array.isArray(o) ? (S?.validIndices || Array.from({ length: o.length }, (c, f) => f)).map((c, f) => {
803
- const u = o[c], p = [...n, c.toString()], _ = a(u, p, S);
804
- return t(u, _, {
806
+ const u = o[c], E = [...n, c.toString()], w = a(u, E, S);
807
+ return t(u, w, {
805
808
  register: () => {
806
- const [, C] = Z({}), $ = `${m}-${n.join(".")}-${c}`;
809
+ const [, C] = X({}), $ = `${m}-${n.join(".")}-${c}`;
807
810
  ie(() => {
808
- const k = `${e}////${$}`, D = r.getState().stateComponents.get(e) || {
811
+ const x = `${e}////${$}`, j = r.getState().stateComponents.get(e) || {
809
812
  components: /* @__PURE__ */ new Map()
810
813
  };
811
- return D.components.set(k, {
814
+ return j.components.set(x, {
812
815
  forceUpdate: () => C({}),
813
- paths: /* @__PURE__ */ new Set([p.join(".")])
814
- }), r.getState().stateComponents.set(e, D), () => {
815
- const q = r.getState().stateComponents.get(e);
816
- 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);
817
820
  };
818
821
  }, [e, $]);
819
822
  },
@@ -829,17 +832,17 @@ function Se(e, i, m, g) {
829
832
  return (t) => h.map((s, c) => {
830
833
  let f;
831
834
  S?.validIndices && S.validIndices[c] !== void 0 ? f = S.validIndices[c] : f = c;
832
- const u = [...n, f.toString()], p = a(s, u, S);
835
+ const u = [...n, f.toString()], E = a(s, u, S);
833
836
  return t(
834
837
  s,
835
- p,
838
+ E,
836
839
  c,
837
840
  h,
838
841
  a(h, n, S)
839
842
  );
840
843
  });
841
844
  if (l === "$stateMap")
842
- return (t) => ce(Xe, {
845
+ return (t) => ce(Ze, {
843
846
  proxy: {
844
847
  _stateKey: e,
845
848
  _path: n,
@@ -852,15 +855,15 @@ function Se(e, i, m, g) {
852
855
  return (t) => {
853
856
  const o = r.getState().getNestedState(e, n);
854
857
  return Array.isArray(o) ? (S?.validIndices || Array.from({ length: o.length }, (c, f) => f)).map((c, f) => {
855
- const u = o[c], p = [...n, c.toString()], _ = a(u, p, S), w = `${m}-${n.join(".")}-${c}`;
856
- 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, {
857
860
  key: c,
858
861
  stateKey: e,
859
- itemComponentId: w,
860
- itemPath: p,
862
+ itemComponentId: _,
863
+ itemPath: E,
861
864
  children: t(
862
865
  u,
863
- _,
866
+ w,
864
867
  f,
865
868
  o,
866
869
  a(o, n, S)
@@ -896,36 +899,36 @@ function Se(e, i, m, g) {
896
899
  return a(s, c);
897
900
  };
898
901
  if (l === "insert")
899
- return (t) => (A(n), Te(i, t, n, e), a(
902
+ return (t) => (p(n), he(i, t, n, e), a(
900
903
  r.getState().getNestedState(e, n),
901
904
  n
902
905
  ));
903
906
  if (l === "uniqueInsert")
904
907
  return (t, o, s) => {
905
- 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;
906
909
  let u = null;
907
- if (!c.some((_) => {
910
+ if (!c.some((w) => {
908
911
  if (o) {
909
912
  const C = o.every(
910
- ($) => Y(_[$], f[$])
913
+ ($) => z(w[$], f[$])
911
914
  );
912
- return C && (u = _), C;
915
+ return C && (u = w), C;
913
916
  }
914
- const w = Y(_, f);
915
- return w && (u = _), w;
917
+ const _ = z(w, f);
918
+ return _ && (u = w), _;
916
919
  }))
917
- A(n), Te(i, f, n, e);
920
+ p(n), he(i, f, n, e);
918
921
  else if (s && u) {
919
- const _ = s(u), w = c.map(
920
- (C) => Y(C, u) ? _ : C
922
+ const w = s(u), _ = c.map(
923
+ (C) => z(C, u) ? w : C
921
924
  );
922
- A(n), se(i, w, n);
925
+ p(n), se(i, _, n);
923
926
  }
924
927
  };
925
928
  if (l === "cut")
926
929
  return (t, o) => {
927
930
  if (!o?.waitForSync)
928
- return A(n), ge(i, n, e, t), a(
931
+ return p(n), ge(i, n, e, t), a(
929
932
  r.getState().getNestedState(e, n),
930
933
  n
931
934
  );
@@ -938,7 +941,7 @@ function Se(e, i, m, g) {
938
941
  if (l === "toggleByValue")
939
942
  return (t) => {
940
943
  const o = h.findIndex((s) => s === t);
941
- 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);
942
945
  };
943
946
  if (l === "stateFind")
944
947
  return (t) => {
@@ -959,15 +962,15 @@ function Se(e, i, m, g) {
959
962
  return a(c.item, f, S);
960
963
  };
961
964
  }
962
- const K = n[n.length - 1];
963
- if (!isNaN(Number(K))) {
965
+ const ee = n[n.length - 1];
966
+ if (!isNaN(Number(ee))) {
964
967
  const d = n.slice(0, -1), t = r.getState().getNestedState(e, d);
965
968
  if (Array.isArray(t) && l === "cut")
966
969
  return () => ge(
967
970
  i,
968
971
  d,
969
972
  e,
970
- Number(K)
973
+ Number(ee)
971
974
  );
972
975
  }
973
976
  if (l === "get")
@@ -979,13 +982,13 @@ function Se(e, i, m, g) {
979
982
  return r.getState().getNestedState(e, n);
980
983
  };
981
984
  if (l === "$derive")
982
- return (d) => be({
985
+ return (d) => $e({
983
986
  _stateKey: e,
984
987
  _path: n,
985
988
  _effect: d.toString()
986
989
  });
987
990
  if (l === "$get")
988
- return () => be({
991
+ return () => $e({
989
992
  _stateKey: e,
990
993
  _path: n
991
994
  });
@@ -1004,7 +1007,7 @@ function Se(e, i, m, g) {
1004
1007
  const t = n.slice(0, -1), o = Number(n[n.length - 1]), s = t.join(".");
1005
1008
  d ? r.getState().setSelectedIndex(e, s, o) : r.getState().setSelectedIndex(e, s, void 0);
1006
1009
  const c = r.getState().getNestedState(e, [...t]);
1007
- se(i, c, t), A(t);
1010
+ se(i, c, t), p(t);
1008
1011
  };
1009
1012
  if (l === "toggleSelected")
1010
1013
  return () => {
@@ -1015,13 +1018,13 @@ function Se(e, i, m, g) {
1015
1018
  s === t ? void 0 : t
1016
1019
  );
1017
1020
  const c = r.getState().getNestedState(e, [...d]);
1018
- se(i, c, d), A(d);
1021
+ se(i, c, d), p(d);
1019
1022
  };
1020
1023
  if (n.length == 0) {
1021
1024
  if (l === "applyJsonPatch")
1022
1025
  return (d) => {
1023
- const t = r.getState().cogsStateStore[e], s = He(t, d).newDocument;
1024
- ke(
1026
+ const t = r.getState().cogsStateStore[e], s = je(t, d).newDocument;
1027
+ Me(
1025
1028
  e,
1026
1029
  r.getState().initialStateGlobal[e],
1027
1030
  s,
@@ -1031,57 +1034,57 @@ function Se(e, i, m, g) {
1031
1034
  );
1032
1035
  const c = r.getState().stateComponents.get(e);
1033
1036
  if (c) {
1034
- const f = Ae(t, s), u = new Set(f);
1037
+ const f = ye(t, s), u = new Set(f);
1035
1038
  for (const [
1036
- p,
1037
- _
1039
+ E,
1040
+ w
1038
1041
  ] of c.components.entries()) {
1039
- let w = !1;
1040
- const C = Array.isArray(_.reactiveType) ? _.reactiveType : [_.reactiveType || "component"];
1042
+ let _ = !1;
1043
+ const C = Array.isArray(w.reactiveType) ? w.reactiveType : [w.reactiveType || "component"];
1041
1044
  if (!C.includes("none")) {
1042
1045
  if (C.includes("all")) {
1043
- _.forceUpdate();
1046
+ w.forceUpdate();
1044
1047
  continue;
1045
1048
  }
1046
- if (C.includes("component") && (_.paths.has("") && (w = !0), !w))
1049
+ if (C.includes("component") && (w.paths.has("") && (_ = !0), !_))
1047
1050
  for (const $ of u) {
1048
- if (_.paths.has($)) {
1049
- w = !0;
1051
+ if (w.paths.has($)) {
1052
+ _ = !0;
1050
1053
  break;
1051
1054
  }
1052
- let k = $.lastIndexOf(".");
1053
- for (; k !== -1; ) {
1054
- const D = $.substring(0, k);
1055
- if (_.paths.has(D)) {
1056
- w = !0;
1055
+ let x = $.lastIndexOf(".");
1056
+ for (; x !== -1; ) {
1057
+ const j = $.substring(0, x);
1058
+ if (w.paths.has(j)) {
1059
+ _ = !0;
1057
1060
  break;
1058
1061
  }
1059
- const q = $.substring(
1060
- k + 1
1062
+ const J = $.substring(
1063
+ x + 1
1061
1064
  );
1062
- if (!isNaN(Number(q))) {
1063
- const M = D.lastIndexOf(".");
1065
+ if (!isNaN(Number(J))) {
1066
+ const M = j.lastIndexOf(".");
1064
1067
  if (M !== -1) {
1065
- const y = D.substring(
1068
+ const y = j.substring(
1066
1069
  0,
1067
1070
  M
1068
1071
  );
1069
- if (_.paths.has(y)) {
1070
- w = !0;
1072
+ if (w.paths.has(y)) {
1073
+ _ = !0;
1071
1074
  break;
1072
1075
  }
1073
1076
  }
1074
1077
  }
1075
- k = D.lastIndexOf(".");
1078
+ x = j.lastIndexOf(".");
1076
1079
  }
1077
- if (w) break;
1080
+ if (_) break;
1078
1081
  }
1079
- if (!w && C.includes("deps") && _.depsFunction) {
1080
- const $ = _.depsFunction(s);
1081
- let k = !1;
1082
- 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);
1083
1086
  }
1084
- w && _.forceUpdate();
1087
+ _ && w.forceUpdate();
1085
1088
  }
1086
1089
  }
1087
1090
  }
@@ -1093,17 +1096,17 @@ function Se(e, i, m, g) {
1093
1096
  throw new Error("Zod schema not found");
1094
1097
  if (!d?.key)
1095
1098
  throw new Error("Validation key not found");
1096
- J(d.key);
1099
+ Z(d.key);
1097
1100
  const o = r.getState().cogsStateStore[e];
1098
1101
  try {
1099
1102
  const s = r.getState().getValidationErrors(d.key);
1100
1103
  s && s.length > 0 && s.forEach(([f]) => {
1101
- f && f.startsWith(d.key) && J(f);
1104
+ f && f.startsWith(d.key) && Z(f);
1102
1105
  });
1103
1106
  const c = d.zodSchema.safeParse(o);
1104
1107
  return c.success ? !0 : (c.error.errors.forEach((u) => {
1105
- const p = u.path, _ = u.message, w = [d.key, ...p].join(".");
1106
- t(w, _);
1108
+ const E = u.path, w = u.message, _ = [d.key, ...E].join(".");
1109
+ t(_, w);
1107
1110
  }), Ie(e), !1);
1108
1111
  } catch (s) {
1109
1112
  return console.error("Zod schema validation failed", s), !1;
@@ -1131,8 +1134,8 @@ function Se(e, i, m, g) {
1131
1134
  return ({
1132
1135
  children: d,
1133
1136
  hideMessage: t
1134
- }) => /* @__PURE__ */ ve(
1135
- je,
1137
+ }) => /* @__PURE__ */ Te(
1138
+ Re,
1136
1139
  {
1137
1140
  formOpts: t ? { validation: { message: "" } } : void 0,
1138
1141
  path: n,
@@ -1148,7 +1151,7 @@ function Se(e, i, m, g) {
1148
1151
  if (l === "update")
1149
1152
  return (d, t) => {
1150
1153
  if (t?.debounce)
1151
- Ue(() => {
1154
+ Le(() => {
1152
1155
  se(i, d, n, "");
1153
1156
  const o = r.getState().getNestedState(e, n);
1154
1157
  t?.afterUpdate && t.afterUpdate(o);
@@ -1158,11 +1161,11 @@ function Se(e, i, m, g) {
1158
1161
  const o = r.getState().getNestedState(e, n);
1159
1162
  t?.afterUpdate && t.afterUpdate(o);
1160
1163
  }
1161
- A(n);
1164
+ p(n);
1162
1165
  };
1163
1166
  if (l === "formElement")
1164
- return (d, t) => /* @__PURE__ */ ve(
1165
- Fe,
1167
+ return (d, t) => /* @__PURE__ */ Te(
1168
+ De,
1166
1169
  {
1167
1170
  setState: i,
1168
1171
  stateKey: e,
@@ -1171,23 +1174,23 @@ function Se(e, i, m, g) {
1171
1174
  formOpts: t
1172
1175
  }
1173
1176
  );
1174
- const V = [...n, l], ae = r.getState().getNestedState(e, V);
1175
- return a(ae, V, S);
1177
+ const P = [...n, l], ae = r.getState().getNestedState(e, P);
1178
+ return a(ae, P, S);
1176
1179
  }
1177
- }, W = new Proxy(G, U);
1178
- return T.set(L, {
1179
- proxy: W,
1180
+ }, F = new Proxy(L, R);
1181
+ return T.set(H, {
1182
+ proxy: F,
1180
1183
  stateVersion: N
1181
- }), W;
1184
+ }), F;
1182
1185
  }
1183
1186
  return a(
1184
1187
  r.getState().getNestedState(e, [])
1185
1188
  );
1186
1189
  }
1187
- function be(e) {
1188
- return ce(Qe, { proxy: e });
1190
+ function $e(e) {
1191
+ return ce(Xe, { proxy: e });
1189
1192
  }
1190
- function Xe({
1193
+ function Ze({
1191
1194
  proxy: e,
1192
1195
  rebuildStateShape: i
1193
1196
  }) {
@@ -1196,23 +1199,23 @@ function Xe({
1196
1199
  m,
1197
1200
  e._path
1198
1201
  ).stateMapNoRender(
1199
- (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)
1200
1203
  ) : null;
1201
1204
  }
1202
- function Qe({
1205
+ function Xe({
1203
1206
  proxy: e
1204
1207
  }) {
1205
- const i = Q(null), m = `${e._stateKey}-${e._path.join(".")}`;
1208
+ const i = K(null), m = `${e._stateKey}-${e._path.join(".")}`;
1206
1209
  return oe(() => {
1207
1210
  const g = i.current;
1208
1211
  if (!g || !g.parentElement) return;
1209
- const T = g.parentElement, A = Array.from(T.childNodes).indexOf(g);
1212
+ const T = g.parentElement, p = Array.from(T.childNodes).indexOf(g);
1210
1213
  let v = T.getAttribute("data-parent-id");
1211
1214
  v || (v = `parent-${crypto.randomUUID()}`, T.setAttribute("data-parent-id", v));
1212
1215
  const h = {
1213
1216
  instanceId: `instance-${crypto.randomUUID()}`,
1214
1217
  parentId: v,
1215
- position: A,
1218
+ position: p,
1216
1219
  effect: e._effect
1217
1220
  };
1218
1221
  r.getState().addSignalElement(m, h);
@@ -1224,22 +1227,22 @@ function Qe({
1224
1227
  "state",
1225
1228
  `return (${e._effect})(state)`
1226
1229
  )(n);
1227
- } catch (G) {
1228
- console.error("Error evaluating effect function during mount:", G), S = n;
1230
+ } catch (L) {
1231
+ console.error("Error evaluating effect function during mount:", L), S = n;
1229
1232
  }
1230
1233
  else
1231
1234
  S = n;
1232
1235
  S !== null && typeof S == "object" && (S = JSON.stringify(S));
1233
- const L = document.createTextNode(String(S));
1234
- g.replaceWith(L);
1236
+ const H = document.createTextNode(String(S));
1237
+ g.replaceWith(H);
1235
1238
  }, [e._stateKey, e._path.join("."), e._effect]), ce("span", {
1236
1239
  ref: i,
1237
1240
  style: { display: "none" },
1238
1241
  "data-signal-id": m
1239
1242
  });
1240
1243
  }
1241
- function St(e) {
1242
- const i = xe(
1244
+ function ft(e) {
1245
+ const i = Pe(
1243
1246
  (m) => {
1244
1247
  const g = r.getState().stateComponents.get(e._stateKey) || {
1245
1248
  components: /* @__PURE__ */ new Map()
@@ -1253,20 +1256,20 @@ function St(e) {
1253
1256
  );
1254
1257
  return ce("text", {}, String(i));
1255
1258
  }
1256
- function Ke({
1259
+ function Qe({
1257
1260
  stateKey: e,
1258
1261
  itemComponentId: i,
1259
1262
  itemPath: m,
1260
1263
  children: g
1261
1264
  }) {
1262
- const [, T] = Z({}), [N, A] = Le(), v = Q(null);
1265
+ const [, T] = X({}), [N, p] = He(), v = K(null);
1263
1266
  return oe(() => {
1264
- A.height > 0 && A.height !== v.current && (v.current = A.height, r.getState().setShadowMetadata(e, m, {
1267
+ p.height > 0 && p.height !== v.current && (v.current = p.height, r.getState().setShadowMetadata(e, m, {
1265
1268
  virtualizer: {
1266
- itemHeight: A.height
1269
+ itemHeight: p.height
1267
1270
  }
1268
1271
  }));
1269
- }, [A.height, e, m]), ie(() => {
1272
+ }, [p.height, e, m]), ie(() => {
1270
1273
  const a = `${e}////${i}`, h = r.getState().stateComponents.get(e) || {
1271
1274
  components: /* @__PURE__ */ new Map()
1272
1275
  };
@@ -1277,14 +1280,14 @@ function Ke({
1277
1280
  const n = r.getState().stateComponents.get(e);
1278
1281
  n && n.components.delete(a);
1279
1282
  };
1280
- }, [e, i, m.join(".")]), /* @__PURE__ */ ve("div", { ref: N, children: g });
1283
+ }, [e, i, m.join(".")]), /* @__PURE__ */ Te("div", { ref: N, children: g });
1281
1284
  }
1282
1285
  export {
1283
- be as $cogsSignal,
1284
- St as $cogsSignalStore,
1285
- ut as addStateOptions,
1286
- gt as createCogsState,
1287
- ft as notifyComponent,
1288
- 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
1289
1292
  };
1290
1293
  //# sourceMappingURL=CogsState.jsx.map