cogsbox-state 0.5.417 → 0.5.418

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 vt } from "react/jsx-runtime";
3
- import { useState as rt, useRef as X, useEffect as tt, useLayoutEffect as $t, useMemo as yt, createElement as it, useSyncExternalStore as Rt, startTransition as Mt, useCallback as gt } from "react";
4
- import { transformStateFunc as Ot, isDeepEqual as q, isFunction as Q, getNestedValue as J, getDifferences as It, debounce as jt } from "./utility.js";
5
- import { pushFunc as ht, updateFn as at, cutFunc as ut, ValidationWrapper as Ut, FormControlComponent as Ft } from "./Functions.jsx";
6
- import Dt from "superjson";
7
- import { v4 as wt } from "uuid";
2
+ import { jsx as It } from "react/jsx-runtime";
3
+ import { useState as ot, useRef as J, useEffect as et, useLayoutEffect as Nt, useMemo as wt, createElement as ct, useSyncExternalStore as Ot, startTransition as jt, useCallback as ft } from "react";
4
+ import { transformStateFunc as Ut, isDeepEqual as q, isFunction as K, getNestedValue as Y, getDifferences as pt, debounce as Ft } from "./utility.js";
5
+ import { pushFunc as yt, updateFn as st, cutFunc as gt, ValidationWrapper as Dt, FormControlComponent as Lt } from "./Functions.jsx";
6
+ import Gt from "superjson";
7
+ import { v4 as Et } from "uuid";
8
8
  import "zod";
9
- import { getGlobalStore as o, formRefStore as Tt } from "./store.js";
10
- import { useCogsConfig as xt } from "./CogsStateClient.jsx";
11
- import { applyPatch as Lt } from "fast-json-patch";
12
- import Gt from "react-use-measure";
13
- function kt(t, s) {
9
+ import { getGlobalStore as o, formRefStore as kt } from "./store.js";
10
+ import { useCogsConfig as Pt } from "./CogsStateClient.jsx";
11
+ import { applyPatch as Wt } from "fast-json-patch";
12
+ import zt from "react-use-measure";
13
+ function bt(t, s) {
14
14
  const S = o.getState().getInitialOptions, u = o.getState().setInitialStateOptions, v = S(t) || {};
15
15
  u(t, {
16
16
  ...v,
17
17
  ...s
18
18
  });
19
19
  }
20
- function At({
20
+ function Vt({
21
21
  stateKey: t,
22
22
  options: s,
23
23
  initialOptionsPart: S
24
24
  }) {
25
- const u = nt(t) || {}, v = S[t] || {}, $ = o.getState().setInitialStateOptions, I = { ...v, ...u };
25
+ const u = rt(t) || {}, v = S[t] || {}, V = o.getState().setInitialStateOptions, I = { ...v, ...u };
26
26
  let y = !1;
27
27
  if (s)
28
28
  for (const i in s)
29
29
  I.hasOwnProperty(i) ? (i == "localStorage" && s[i] && I[i].key !== s[i]?.key && (y = !0, I[i] = s[i]), i == "initialState" && s[i] && I[i] !== s[i] && // Different references
30
30
  !q(I[i], s[i]) && (y = !0, I[i] = s[i])) : (y = !0, I[i] = s[i]);
31
- y && $(t, I);
31
+ y && V(t, I);
32
32
  }
33
- function le(t, { formElements: s, validation: S }) {
33
+ function ue(t, { formElements: s, validation: S }) {
34
34
  return { initialState: t, formElements: s, validation: S };
35
35
  }
36
- const de = (t, s) => {
36
+ const ge = (t, s) => {
37
37
  let S = t;
38
- const [u, v] = Ot(S);
38
+ const [u, v] = Ut(S);
39
39
  (Object.keys(v).length > 0 || s && Object.keys(s).length > 0) && Object.keys(v).forEach((y) => {
40
40
  v[y] = v[y] || {}, v[y].formElements = {
41
41
  ...s?.formElements,
@@ -43,16 +43,16 @@ const de = (t, s) => {
43
43
  ...s?.validation,
44
44
  ...v[y].formElements || {}
45
45
  // State-specific overrides
46
- }, nt(y) || o.getState().setInitialStateOptions(y, v[y]);
46
+ }, rt(y) || o.getState().setInitialStateOptions(y, v[y]);
47
47
  }), o.getState().setInitialStates(u), o.getState().setCreatedState(u);
48
- const $ = (y, i) => {
49
- const [h] = rt(i?.componentId ?? wt());
50
- At({
48
+ const V = (y, i) => {
49
+ const [h] = ot(i?.componentId ?? Et());
50
+ Vt({
51
51
  stateKey: y,
52
52
  options: i,
53
53
  initialOptionsPart: v
54
54
  });
55
- const n = o.getState().cogsStateStore[y] || u[y], g = i?.modifyState ? i.modifyState(n) : n, [W, F] = Jt(
55
+ const n = o.getState().cogsStateStore[y] || u[y], g = i?.modifyState ? i.modifyState(n) : n, [L, U] = Zt(
56
56
  g,
57
57
  {
58
58
  stateKey: y,
@@ -68,49 +68,49 @@ const de = (t, s) => {
68
68
  serverState: i?.serverState
69
69
  }
70
70
  );
71
- return F;
71
+ return U;
72
72
  };
73
73
  function I(y, i) {
74
- At({ stateKey: y, options: i, initialOptionsPart: v }), i.localStorage && Bt(y, i), st(y);
74
+ Vt({ stateKey: y, options: i, initialOptionsPart: v }), i.localStorage && Jt(y, i), lt(y);
75
75
  }
76
- return { useCogsState: $, setCogsOptions: I };
76
+ return { useCogsState: V, setCogsOptions: I };
77
77
  }, {
78
- setUpdaterState: ft,
79
- setState: et,
80
- getInitialOptions: nt,
81
- getKeyState: Nt,
82
- getValidationErrors: Wt,
83
- setStateLog: zt,
84
- updateInitialStateGlobal: pt,
85
- addValidationError: Pt,
86
- removeValidationError: Z,
87
- setServerSyncActions: Ht
88
- } = o.getState(), bt = (t, s, S, u, v) => {
78
+ setUpdaterState: St,
79
+ setState: nt,
80
+ getInitialOptions: rt,
81
+ getKeyState: Ct,
82
+ getValidationErrors: Ht,
83
+ setStateLog: Bt,
84
+ updateInitialStateGlobal: At,
85
+ addValidationError: _t,
86
+ removeValidationError: X,
87
+ setServerSyncActions: qt
88
+ } = o.getState(), $t = (t, s, S, u, v) => {
89
89
  S?.log && console.log(
90
90
  "saving to localstorage",
91
91
  s,
92
92
  S.localStorage?.key,
93
93
  u
94
94
  );
95
- const $ = Q(S?.localStorage?.key) ? S.localStorage?.key(t) : S?.localStorage?.key;
96
- if ($ && u) {
97
- const I = `${u}-${s}-${$}`;
95
+ const V = K(S?.localStorage?.key) ? S.localStorage?.key(t) : S?.localStorage?.key;
96
+ if (V && u) {
97
+ const I = `${u}-${s}-${V}`;
98
98
  let y;
99
99
  try {
100
- y = mt(I)?.lastSyncedWithServer;
100
+ y = ht(I)?.lastSyncedWithServer;
101
101
  } catch {
102
102
  }
103
103
  const i = {
104
104
  state: t,
105
105
  lastUpdated: Date.now(),
106
106
  lastSyncedWithServer: v ?? y
107
- }, h = Dt.serialize(i);
107
+ }, h = Gt.serialize(i);
108
108
  window.localStorage.setItem(
109
109
  I,
110
110
  JSON.stringify(h.json)
111
111
  );
112
112
  }
113
- }, mt = (t) => {
113
+ }, ht = (t) => {
114
114
  if (!t) return null;
115
115
  try {
116
116
  const s = window.localStorage.getItem(t);
@@ -118,29 +118,29 @@ const de = (t, s) => {
118
118
  } catch (s) {
119
119
  return console.error("Error loading from localStorage:", s), null;
120
120
  }
121
- }, Bt = (t, s) => {
122
- const S = o.getState().cogsStateStore[t], { sessionId: u } = xt(), v = Q(s?.localStorage?.key) ? s.localStorage.key(S) : s?.localStorage?.key;
121
+ }, Jt = (t, s) => {
122
+ const S = o.getState().cogsStateStore[t], { sessionId: u } = Pt(), v = K(s?.localStorage?.key) ? s.localStorage.key(S) : s?.localStorage?.key;
123
123
  if (v && u) {
124
- const $ = mt(
124
+ const V = ht(
125
125
  `${u}-${t}-${v}`
126
126
  );
127
- if ($ && $.lastUpdated > ($.lastSyncedWithServer || 0))
128
- return et(t, $.state), st(t), !0;
127
+ if (V && V.lastUpdated > (V.lastSyncedWithServer || 0))
128
+ return nt(t, V.state), lt(t), !0;
129
129
  }
130
130
  return !1;
131
- }, Ct = (t, s, S, u, v, $) => {
131
+ }, Rt = (t, s, S, u, v, V) => {
132
132
  const I = {
133
133
  initialState: s,
134
- updaterState: St(
134
+ updaterState: mt(
135
135
  t,
136
136
  u,
137
137
  v,
138
- $
138
+ V
139
139
  ),
140
140
  state: S
141
141
  };
142
- pt(t, I.initialState), ft(t, I.updaterState), et(t, I.state);
143
- }, st = (t) => {
142
+ At(t, I.initialState), St(t, I.updaterState), nt(t, I.state);
143
+ }, lt = (t) => {
144
144
  const s = o.getState().stateComponents.get(t);
145
145
  if (!s) return;
146
146
  const S = /* @__PURE__ */ new Set();
@@ -149,7 +149,7 @@ const de = (t, s) => {
149
149
  }), queueMicrotask(() => {
150
150
  S.forEach((u) => u());
151
151
  });
152
- }, ue = (t, s) => {
152
+ }, fe = (t, s) => {
153
153
  const S = o.getState().stateComponents.get(t);
154
154
  if (S) {
155
155
  const u = `${t}////${s}`, v = S.components.get(u);
@@ -157,22 +157,22 @@ const de = (t, s) => {
157
157
  return;
158
158
  v && v.forceUpdate();
159
159
  }
160
- }, qt = (t, s, S, u) => {
160
+ }, Yt = (t, s, S, u) => {
161
161
  switch (t) {
162
162
  case "update":
163
163
  return {
164
- oldValue: J(s, u),
165
- newValue: J(S, u)
164
+ oldValue: Y(s, u),
165
+ newValue: Y(S, u)
166
166
  };
167
167
  case "insert":
168
168
  return {
169
169
  oldValue: null,
170
170
  // or undefined
171
- newValue: J(S, u)
171
+ newValue: Y(S, u)
172
172
  };
173
173
  case "cut":
174
174
  return {
175
- oldValue: J(s, u),
175
+ oldValue: Y(s, u),
176
176
  newValue: null
177
177
  // or undefined
178
178
  };
@@ -180,12 +180,12 @@ const de = (t, s) => {
180
180
  return { oldValue: null, newValue: null };
181
181
  }
182
182
  };
183
- function Jt(t, {
183
+ function Zt(t, {
184
184
  stateKey: s,
185
185
  serverSync: S,
186
186
  localStorage: u,
187
187
  formElements: v,
188
- reactiveDeps: $,
188
+ reactiveDeps: V,
189
189
  reactiveType: I,
190
190
  componentId: y,
191
191
  initialState: i,
@@ -193,14 +193,14 @@ function Jt(t, {
193
193
  dependencies: n,
194
194
  serverState: g
195
195
  } = {}) {
196
- const [W, F] = rt({}), { sessionId: D } = xt();
197
- let H = !s;
198
- const [f] = rt(s ?? wt()), l = o.getState().stateLog[f], ct = X(/* @__PURE__ */ new Set()), K = X(y ?? wt()), M = X(
196
+ const [L, U] = ot({}), { sessionId: F } = Pt();
197
+ let z = !s;
198
+ const [f] = ot(s ?? Et()), l = o.getState().stateLog[f], dt = J(/* @__PURE__ */ new Set()), tt = J(y ?? Et()), R = J(
199
199
  null
200
200
  );
201
- M.current = nt(f) ?? null, tt(() => {
201
+ R.current = rt(f) ?? null, et(() => {
202
202
  if (h && h.stateKey === f && h.path?.[0]) {
203
- et(f, (r) => ({
203
+ nt(f, (r) => ({
204
204
  ...r,
205
205
  [h.path[0]]: h.newValue
206
206
  }));
@@ -210,269 +210,269 @@ function Jt(t, {
210
210
  userId: h.userId
211
211
  });
212
212
  }
213
- }, [h]), tt(() => {
213
+ }, [h]), et(() => {
214
214
  if (i) {
215
- kt(f, {
215
+ bt(f, {
216
216
  initialState: i
217
217
  });
218
- const e = M.current, a = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, c = o.getState().initialStateGlobal[f];
218
+ const e = R.current, a = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, c = o.getState().initialStateGlobal[f];
219
219
  if (!(c && !q(c, i) || !c) && !a)
220
220
  return;
221
221
  let m = null;
222
- const k = Q(e?.localStorage?.key) ? e?.localStorage?.key(i) : e?.localStorage?.key;
223
- k && D && (m = mt(`${D}-${f}-${k}`));
224
- let p = i, V = !1;
225
- const _ = a ? Date.now() : 0, N = m?.lastUpdated || 0, O = m?.lastSyncedWithServer || 0;
226
- a && _ > N ? (p = e.serverState.data, V = !0) : m && N > O && (p = m.state, e?.localStorage?.onChange && e?.localStorage?.onChange(p)), o.getState().initializeShadowState(f, i), Ct(
222
+ const k = K(e?.localStorage?.key) ? e?.localStorage?.key(i) : e?.localStorage?.key;
223
+ k && F && (m = ht(`${F}-${f}-${k}`));
224
+ let p = i, b = !1;
225
+ const C = a ? Date.now() : 0, P = m?.lastUpdated || 0, M = m?.lastSyncedWithServer || 0;
226
+ a && C > P ? (p = e.serverState.data, b = !0) : m && P > M && (p = m.state, e?.localStorage?.onChange && e?.localStorage?.onChange(p)), o.getState().initializeShadowState(f, i), Rt(
227
227
  f,
228
228
  i,
229
229
  p,
230
- ot,
231
- K.current,
232
- D
233
- ), V && k && D && bt(p, f, e, D, Date.now()), st(f), (Array.isArray(I) ? I : [I || "component"]).includes("none") || F({});
230
+ at,
231
+ tt.current,
232
+ F
233
+ ), b && k && F && $t(p, f, e, F, Date.now()), lt(f), (Array.isArray(I) ? I : [I || "component"]).includes("none") || U({});
234
234
  }
235
235
  }, [
236
236
  i,
237
237
  g?.status,
238
238
  g?.data,
239
239
  ...n || []
240
- ]), $t(() => {
241
- H && kt(f, {
240
+ ]), Nt(() => {
241
+ z && bt(f, {
242
242
  serverSync: S,
243
243
  formElements: v,
244
244
  initialState: i,
245
245
  localStorage: u,
246
- middleware: M.current?.middleware
246
+ middleware: R.current?.middleware
247
247
  });
248
- const e = `${f}////${K.current}`, r = o.getState().stateComponents.get(f) || {
248
+ const e = `${f}////${tt.current}`, r = o.getState().stateComponents.get(f) || {
249
249
  components: /* @__PURE__ */ new Map()
250
250
  };
251
251
  return r.components.set(e, {
252
- forceUpdate: () => F({}),
252
+ forceUpdate: () => U({}),
253
253
  paths: /* @__PURE__ */ new Set(),
254
254
  deps: [],
255
- depsFunction: $ || void 0,
255
+ depsFunction: V || void 0,
256
256
  reactiveType: I ?? ["component", "deps"]
257
- }), o.getState().stateComponents.set(f, r), F({}), () => {
257
+ }), o.getState().stateComponents.set(f, r), U({}), () => {
258
258
  r && (r.components.delete(e), r.components.size === 0 && o.getState().stateComponents.delete(f));
259
259
  };
260
260
  }, []);
261
- const ot = (e, r, a, c) => {
261
+ const at = (e, r, a, c) => {
262
262
  if (Array.isArray(r)) {
263
263
  const m = `${f}-${r.join(".")}`;
264
- ct.current.add(m);
264
+ dt.current.add(m);
265
265
  }
266
266
  const w = o.getState();
267
- et(f, (m) => {
268
- const k = Q(e) ? e(m) : e, p = `${f}-${r.join(".")}`;
267
+ nt(f, (m) => {
268
+ const k = K(e) ? e(m) : e, p = `${f}-${r.join(".")}`;
269
269
  if (p) {
270
- let R = !1, E = w.signalDomElements.get(p);
271
- if ((!E || E.size === 0) && (a.updateType === "insert" || a.updateType === "cut")) {
272
- const j = r.slice(0, -1), L = J(k, j);
273
- if (Array.isArray(L)) {
274
- R = !0;
275
- const A = `${f}-${j.join(".")}`;
276
- E = w.signalDomElements.get(A);
270
+ let A = !1, $ = w.signalDomElements.get(p);
271
+ if ((!$ || $.size === 0) && (a.updateType === "insert" || a.updateType === "cut")) {
272
+ const x = r.slice(0, -1), G = Y(k, x);
273
+ if (Array.isArray(G)) {
274
+ A = !0;
275
+ const T = `${f}-${x.join(".")}`;
276
+ $ = w.signalDomElements.get(T);
277
277
  }
278
278
  }
279
- if (E) {
280
- const j = R ? J(k, r.slice(0, -1)) : J(k, r);
281
- E.forEach(({ parentId: L, position: A, effect: G }) => {
282
- const U = document.querySelector(
283
- `[data-parent-id="${L}"]`
279
+ if ($) {
280
+ const x = A ? Y(k, r.slice(0, -1)) : Y(k, r);
281
+ $.forEach(({ parentId: G, position: T, effect: D }) => {
282
+ const O = document.querySelector(
283
+ `[data-parent-id="${G}"]`
284
284
  );
285
- if (U) {
286
- const b = Array.from(U.childNodes);
287
- if (b[A]) {
288
- const T = G ? new Function("state", `return (${G})(state)`)(j) : j;
289
- b[A].textContent = String(T);
285
+ if (O) {
286
+ const B = Array.from(O.childNodes);
287
+ if (B[T]) {
288
+ const E = D ? new Function("state", `return (${D})(state)`)(x) : x;
289
+ B[T].textContent = String(E);
290
290
  }
291
291
  }
292
292
  });
293
293
  }
294
294
  }
295
- console.log("shadowState", w.shadowStateStore), a.updateType === "update" && (c || M.current?.validation?.key) && r && Z(
296
- (c || M.current?.validation?.key) + "." + r.join(".")
295
+ console.log("shadowState", w.shadowStateStore), a.updateType === "update" && (c || R.current?.validation?.key) && r && X(
296
+ (c || R.current?.validation?.key) + "." + r.join(".")
297
297
  );
298
- const V = r.slice(0, r.length - 1);
299
- a.updateType === "cut" && M.current?.validation?.key && Z(
300
- M.current?.validation?.key + "." + V.join(".")
301
- ), a.updateType === "insert" && M.current?.validation?.key && Wt(
302
- M.current?.validation?.key + "." + V.join(".")
303
- ).filter(([E, j]) => {
304
- let L = E?.split(".").length;
305
- if (E == V.join(".") && L == V.length - 1) {
306
- let A = E + "." + V;
307
- Z(E), Pt(A, j);
298
+ const b = r.slice(0, r.length - 1);
299
+ a.updateType === "cut" && R.current?.validation?.key && X(
300
+ R.current?.validation?.key + "." + b.join(".")
301
+ ), a.updateType === "insert" && R.current?.validation?.key && Ht(
302
+ R.current?.validation?.key + "." + b.join(".")
303
+ ).filter(([$, x]) => {
304
+ let G = $?.split(".").length;
305
+ if ($ == b.join(".") && G == b.length - 1) {
306
+ let T = $ + "." + b;
307
+ X($), _t(T, x);
308
308
  }
309
309
  });
310
- const _ = w.stateComponents.get(f);
311
- if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", _), _) {
312
- const R = It(m, k), E = new Set(R), j = a.updateType === "update" ? r.join(".") : r.slice(0, -1).join(".") || "";
310
+ const C = w.stateComponents.get(f);
311
+ if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", C), C) {
312
+ const A = pt(m, k), $ = new Set(A), x = a.updateType === "update" ? r.join(".") : r.slice(0, -1).join(".") || "";
313
313
  for (const [
314
- L,
315
- A
316
- ] of _.components.entries()) {
317
- let G = !1;
318
- const U = Array.isArray(A.reactiveType) ? A.reactiveType : [A.reactiveType || "component"];
319
- if (console.log("component", A), !U.includes("none")) {
320
- if (U.includes("all")) {
321
- A.forceUpdate();
314
+ G,
315
+ T
316
+ ] of C.components.entries()) {
317
+ let D = !1;
318
+ const O = Array.isArray(T.reactiveType) ? T.reactiveType : [T.reactiveType || "component"];
319
+ if (console.log("component", T), !O.includes("none")) {
320
+ if (O.includes("all")) {
321
+ T.forceUpdate();
322
322
  continue;
323
323
  }
324
- if (U.includes("component") && ((A.paths.has(j) || A.paths.has("")) && (G = !0), !G))
325
- for (const b of E) {
326
- let T = b;
324
+ if (O.includes("component") && ((T.paths.has(x) || T.paths.has("")) && (D = !0), !D))
325
+ for (const B of $) {
326
+ let E = B;
327
327
  for (; ; ) {
328
- if (A.paths.has(T)) {
329
- G = !0;
328
+ if (T.paths.has(E)) {
329
+ D = !0;
330
330
  break;
331
331
  }
332
- const C = T.lastIndexOf(".");
333
- if (C !== -1) {
334
- const P = T.substring(
332
+ const N = E.lastIndexOf(".");
333
+ if (N !== -1) {
334
+ const _ = E.substring(
335
335
  0,
336
- C
336
+ N
337
337
  );
338
338
  if (!isNaN(
339
- Number(T.substring(C + 1))
340
- ) && A.paths.has(P)) {
341
- G = !0;
339
+ Number(E.substring(N + 1))
340
+ ) && T.paths.has(_)) {
341
+ D = !0;
342
342
  break;
343
343
  }
344
- T = P;
344
+ E = _;
345
345
  } else
346
- T = "";
347
- if (T === "")
346
+ E = "";
347
+ if (E === "")
348
348
  break;
349
349
  }
350
- if (G) break;
350
+ if (D) break;
351
351
  }
352
- if (!G && U.includes("deps") && A.depsFunction) {
353
- const b = A.depsFunction(k);
354
- let T = !1;
355
- typeof b == "boolean" ? b && (T = !0) : q(A.deps, b) || (A.deps = b, T = !0), T && (G = !0);
352
+ if (!D && O.includes("deps") && T.depsFunction) {
353
+ const B = T.depsFunction(k);
354
+ let E = !1;
355
+ typeof B == "boolean" ? B && (E = !0) : q(T.deps, B) || (T.deps = B, E = !0), E && (D = !0);
356
356
  }
357
- G && A.forceUpdate();
357
+ D && T.forceUpdate();
358
358
  }
359
359
  }
360
360
  }
361
- const N = Date.now();
362
- r = r.map((R, E) => {
363
- const j = r.slice(0, -1), L = J(k, j);
364
- return E === r.length - 1 && ["insert", "cut"].includes(a.updateType) ? (L.length - 1).toString() : R;
361
+ const P = Date.now();
362
+ r = r.map((A, $) => {
363
+ const x = r.slice(0, -1), G = Y(k, x);
364
+ return $ === r.length - 1 && ["insert", "cut"].includes(a.updateType) ? (G.length - 1).toString() : A;
365
365
  });
366
- const { oldValue: O, newValue: B } = qt(
366
+ const { oldValue: M, newValue: H } = Yt(
367
367
  a.updateType,
368
368
  m,
369
369
  k,
370
370
  r
371
- ), x = {
372
- timeStamp: N,
371
+ ), Q = {
372
+ timeStamp: P,
373
373
  stateKey: f,
374
374
  path: r,
375
375
  updateType: a.updateType,
376
376
  status: "new",
377
- oldValue: O,
378
- newValue: B
377
+ oldValue: M,
378
+ newValue: H
379
379
  };
380
380
  switch (a.updateType) {
381
381
  case "update":
382
382
  w.updateShadowAtPath(f, r, k);
383
383
  break;
384
384
  case "insert":
385
- const R = r.slice(0, -1);
386
- w.insertShadowArrayElement(f, R, B);
385
+ const A = r.slice(0, -1);
386
+ w.insertShadowArrayElement(f, A, H);
387
387
  break;
388
388
  case "cut":
389
- const E = r.slice(0, -1), j = parseInt(r[r.length - 1]);
390
- w.removeShadowArrayElement(f, E, j);
389
+ const $ = r.slice(0, -1), x = parseInt(r[r.length - 1]);
390
+ w.removeShadowArrayElement(f, $, x);
391
391
  break;
392
392
  }
393
- if (zt(f, (R) => {
394
- const j = [...R ?? [], x].reduce((L, A) => {
395
- const G = `${A.stateKey}:${JSON.stringify(A.path)}`, U = L.get(G);
396
- return U ? (U.timeStamp = Math.max(U.timeStamp, A.timeStamp), U.newValue = A.newValue, U.oldValue = U.oldValue ?? A.oldValue, U.updateType = A.updateType) : L.set(G, { ...A }), L;
393
+ if (Bt(f, (A) => {
394
+ const x = [...A ?? [], Q].reduce((G, T) => {
395
+ const D = `${T.stateKey}:${JSON.stringify(T.path)}`, O = G.get(D);
396
+ return O ? (O.timeStamp = Math.max(O.timeStamp, T.timeStamp), O.newValue = T.newValue, O.oldValue = O.oldValue ?? T.oldValue, O.updateType = T.updateType) : G.set(D, { ...T }), G;
397
397
  }, /* @__PURE__ */ new Map());
398
- return Array.from(j.values());
399
- }), bt(
398
+ return Array.from(x.values());
399
+ }), $t(
400
400
  k,
401
401
  f,
402
- M.current,
403
- D
404
- ), M.current?.middleware && M.current.middleware({
402
+ R.current,
403
+ F
404
+ ), R.current?.middleware && R.current.middleware({
405
405
  updateLog: l,
406
- update: x
407
- }), M.current?.serverSync) {
408
- const R = w.serverState[f], E = M.current?.serverSync;
409
- Ht(f, {
410
- syncKey: typeof E.syncKey == "string" ? E.syncKey : E.syncKey({ state: k }),
411
- rollBackState: R,
412
- actionTimeStamp: Date.now() + (E.debounce ?? 3e3),
406
+ update: Q
407
+ }), R.current?.serverSync) {
408
+ const A = w.serverState[f], $ = R.current?.serverSync;
409
+ qt(f, {
410
+ syncKey: typeof $.syncKey == "string" ? $.syncKey : $.syncKey({ state: k }),
411
+ rollBackState: A,
412
+ actionTimeStamp: Date.now() + ($.debounce ?? 3e3),
413
413
  status: "waiting"
414
414
  });
415
415
  }
416
416
  return k;
417
417
  });
418
418
  };
419
- o.getState().updaterState[f] || (ft(
419
+ o.getState().updaterState[f] || (St(
420
420
  f,
421
- St(
421
+ mt(
422
422
  f,
423
- ot,
424
- K.current,
425
- D
423
+ at,
424
+ tt.current,
425
+ F
426
426
  )
427
- ), o.getState().cogsStateStore[f] || et(f, t), o.getState().initialStateGlobal[f] || pt(f, t));
428
- const d = yt(() => St(
427
+ ), o.getState().cogsStateStore[f] || nt(f, t), o.getState().initialStateGlobal[f] || At(f, t));
428
+ const d = wt(() => mt(
429
429
  f,
430
- ot,
431
- K.current,
432
- D
433
- ), [f, D]);
434
- return [Nt(f), d];
430
+ at,
431
+ tt.current,
432
+ F
433
+ ), [f, F]);
434
+ return [Ct(f), d];
435
435
  }
436
- function St(t, s, S, u) {
436
+ function mt(t, s, S, u) {
437
437
  const v = /* @__PURE__ */ new Map();
438
- let $ = 0;
438
+ let V = 0;
439
439
  const I = (h) => {
440
440
  const n = h.join(".");
441
441
  for (const [g] of v)
442
442
  (g === n || g.startsWith(n + ".")) && v.delete(g);
443
- $++;
443
+ V++;
444
444
  }, y = {
445
445
  removeValidation: (h) => {
446
- h?.validationKey && Z(h.validationKey);
446
+ h?.validationKey && X(h.validationKey);
447
447
  },
448
448
  revertToInitialState: (h) => {
449
449
  const n = o.getState().getInitialOptions(t)?.validation;
450
- n?.key && Z(n?.key), h?.validationKey && Z(h.validationKey);
450
+ n?.key && X(n?.key), h?.validationKey && X(h.validationKey);
451
451
  const g = o.getState().initialStateGlobal[t];
452
- o.getState().clearSelectedIndexesForState(t), v.clear(), $++;
453
- const W = i(g, []), F = nt(t), D = Q(F?.localStorage?.key) ? F?.localStorage?.key(g) : F?.localStorage?.key, H = `${u}-${t}-${D}`;
454
- H && localStorage.removeItem(H), ft(t, W), et(t, g);
452
+ o.getState().clearSelectedIndexesForState(t), v.clear(), V++;
453
+ const L = i(g, []), U = rt(t), F = K(U?.localStorage?.key) ? U?.localStorage?.key(g) : U?.localStorage?.key, z = `${u}-${t}-${F}`;
454
+ z && localStorage.removeItem(z), St(t, L), nt(t, g);
455
455
  const f = o.getState().stateComponents.get(t);
456
456
  return f && f.components.forEach((l) => {
457
457
  l.forceUpdate();
458
458
  }), g;
459
459
  },
460
460
  updateInitialState: (h) => {
461
- v.clear(), $++;
462
- const n = St(
461
+ v.clear(), V++;
462
+ const n = mt(
463
463
  t,
464
464
  s,
465
465
  S,
466
466
  u
467
- ), g = o.getState().initialStateGlobal[t], W = nt(t), F = Q(W?.localStorage?.key) ? W?.localStorage?.key(g) : W?.localStorage?.key, D = `${u}-${t}-${F}`;
468
- return localStorage.getItem(D) && localStorage.removeItem(D), Mt(() => {
469
- pt(t, h), o.getState().initializeShadowState(t, h), ft(t, n), et(t, h);
470
- const H = o.getState().stateComponents.get(t);
471
- H && H.components.forEach((f) => {
467
+ ), g = o.getState().initialStateGlobal[t], L = rt(t), U = K(L?.localStorage?.key) ? L?.localStorage?.key(g) : L?.localStorage?.key, F = `${u}-${t}-${U}`;
468
+ return localStorage.getItem(F) && localStorage.removeItem(F), jt(() => {
469
+ At(t, h), o.getState().initializeShadowState(t, h), St(t, n), nt(t, h);
470
+ const z = o.getState().stateComponents.get(t);
471
+ z && z.components.forEach((f) => {
472
472
  f.forceUpdate();
473
473
  });
474
474
  }), {
475
- fetchId: (H) => n.get()[H]
475
+ fetchId: (z) => n.get()[z]
476
476
  };
477
477
  },
478
478
  _initialState: o.getState().initialStateGlobal[t],
@@ -480,27 +480,27 @@ function St(t, s, S, u) {
480
480
  _isLoading: o.getState().isLoadingGlobal[t],
481
481
  _isServerSynced: () => {
482
482
  const h = o.getState().serverState[t];
483
- return !!(h && q(h, Nt(t)));
483
+ return !!(h && q(h, Ct(t)));
484
484
  }
485
485
  };
486
486
  function i(h, n = [], g) {
487
- const W = n.map(String).join(".");
488
- v.get(W);
489
- const F = function() {
487
+ const L = n.map(String).join(".");
488
+ v.get(L);
489
+ const U = function() {
490
490
  return o().getNestedState(t, n);
491
491
  };
492
492
  Object.keys(y).forEach((f) => {
493
- F[f] = y[f];
493
+ U[f] = y[f];
494
494
  });
495
- const D = {
496
- apply(f, l, ct) {
495
+ const F = {
496
+ apply(f, l, dt) {
497
497
  return console.log(
498
498
  `PROXY APPLY TRAP HIT: stateKey=${t}, path=${n.join(".")}`
499
499
  ), console.trace("Apply trap stack trace"), o().getNestedState(t, n);
500
500
  },
501
501
  get(f, l) {
502
502
  g?.validIndices && !Array.isArray(h) && (g = { ...g, validIndices: void 0 });
503
- const ct = /* @__PURE__ */ new Set([
503
+ const dt = /* @__PURE__ */ new Set([
504
504
  "insert",
505
505
  "cut",
506
506
  "cutByValue",
@@ -523,7 +523,7 @@ function St(t, s, S, u) {
523
523
  "_stateKey",
524
524
  "getComponents"
525
525
  ]);
526
- if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !ct.has(l)) {
526
+ if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !dt.has(l)) {
527
527
  const d = `${t}////${S}`, e = o.getState().stateComponents.get(t);
528
528
  if (e) {
529
529
  const r = e.components.get(d);
@@ -540,7 +540,7 @@ function St(t, s, S, u) {
540
540
  }
541
541
  }
542
542
  if (l === "getDifferences")
543
- return () => It(
543
+ return () => pt(
544
544
  o.getState().cogsStateStore[t],
545
545
  o.getState().initialStateGlobal[t]
546
546
  );
@@ -568,7 +568,7 @@ function St(t, s, S, u) {
568
568
  }
569
569
  };
570
570
  if (l === "_status") {
571
- const d = o.getState().getNestedState(t, n), e = o.getState().initialStateGlobal[t], r = J(e, n);
571
+ const d = o.getState().getNestedState(t, n), e = o.getState().initialStateGlobal[t], r = Y(e, n);
572
572
  return q(d, r) ? "fresh" : "stale";
573
573
  }
574
574
  if (l === "getStatus")
@@ -576,12 +576,12 @@ function St(t, s, S, u) {
576
576
  const d = o().getNestedState(
577
577
  t,
578
578
  n
579
- ), e = o.getState().initialStateGlobal[t], r = J(e, n);
579
+ ), e = o.getState().initialStateGlobal[t], r = Y(e, n);
580
580
  return q(d, r) ? "fresh" : "stale";
581
581
  };
582
582
  if (l === "removeStorage")
583
583
  return () => {
584
- const d = o.getState().initialStateGlobal[t], e = nt(t), r = Q(e?.localStorage?.key) ? e?.localStorage?.key(d) : e?.localStorage?.key, a = `${u}-${t}-${r}`;
584
+ const d = o.getState().initialStateGlobal[t], e = rt(t), r = K(e?.localStorage?.key) ? e?.localStorage?.key(d) : e?.localStorage?.key, a = `${u}-${t}-${r}`;
585
585
  a && localStorage.removeItem(a);
586
586
  };
587
587
  if (l === "showValidationErrors")
@@ -622,49 +622,49 @@ function St(t, s, S, u) {
622
622
  overscan: a = 6,
623
623
  stickToBottom: c = !1,
624
624
  dependencies: w = []
625
- } = e, m = X(null), [k, p] = rt({
625
+ } = e, m = J(null), [k, p] = ot({
626
626
  startIndex: 0,
627
627
  endIndex: 10
628
- }), [V, _] = rt(0), N = X(!0), O = X(0);
629
- tt(() => o.getState().subscribeToShadowState(t, () => {
630
- _((T) => T + 1);
628
+ }), [b, C] = ot(0), P = J(!0), M = J(0), H = J(!1);
629
+ et(() => o.getState().subscribeToShadowState(t, () => {
630
+ C((N) => N + 1);
631
631
  }), [t]);
632
- const B = o().getNestedState(
632
+ const Q = o().getNestedState(
633
633
  t,
634
634
  n
635
- ), x = B.length, { totalHeight: R, positions: E } = yt(() => {
636
- const b = o.getState().getShadowMetadata(t, n) || [];
637
- let T = 0;
638
- const C = [];
639
- for (let P = 0; P < x; P++) {
640
- C[P] = T;
641
- const z = b[P]?.virtualizer?.itemHeight;
642
- T += z || r;
635
+ ), A = Q.length, { totalHeight: $, positions: x } = wt(() => {
636
+ const E = o.getState().getShadowMetadata(t, n) || [];
637
+ let N = 0;
638
+ const _ = [];
639
+ for (let j = 0; j < A; j++) {
640
+ _[j] = N;
641
+ const W = E[j]?.virtualizer?.itemHeight;
642
+ N += W || r;
643
643
  }
644
- return { totalHeight: T, positions: C };
644
+ return { totalHeight: N, positions: _ };
645
645
  }, [
646
- x,
646
+ A,
647
647
  t,
648
648
  n.join("."),
649
649
  r,
650
- V
651
- ]), j = yt(() => {
652
- const b = Math.max(0, k.startIndex), T = Math.min(x, k.endIndex), C = Array.from(
653
- { length: T - b },
654
- (z, lt) => b + lt
655
- ), P = C.map((z) => B[z]);
656
- return i(P, n, {
650
+ b
651
+ ]), G = wt(() => {
652
+ const E = Math.max(0, k.startIndex), N = Math.min(A, k.endIndex), _ = Array.from(
653
+ { length: N - E },
654
+ (W, it) => E + it
655
+ ), j = _.map((W) => Q[W]);
656
+ return i(j, n, {
657
657
  ...g,
658
- validIndices: C
658
+ validIndices: _
659
659
  });
660
- }, [k.startIndex, k.endIndex, B, x]), L = gt(() => {
661
- const b = o.getState().getShadowMetadata(t, n) || [], T = x - 1;
662
- if (T >= 0) {
663
- const C = b[T];
664
- if (C?.virtualizer?.domRef) {
665
- const P = C.virtualizer.domRef;
666
- if (P && P.scrollIntoView)
667
- return P.scrollIntoView({
660
+ }, [k.startIndex, k.endIndex, Q, A]), T = ft(() => {
661
+ const E = o.getState().getShadowMetadata(t, n) || [], N = A - 1;
662
+ if (N >= 0) {
663
+ const _ = E[N];
664
+ if (_?.virtualizer?.domRef) {
665
+ const j = _.virtualizer.domRef;
666
+ if (j && j.scrollIntoView)
667
+ return j.scrollIntoView({
668
668
  behavior: "auto",
669
669
  block: "end",
670
670
  inline: "nearest"
@@ -672,94 +672,94 @@ function St(t, s, S, u) {
672
672
  }
673
673
  }
674
674
  return !1;
675
- }, [t, n, x]);
676
- tt(() => {
677
- if (!c || x === 0) return;
678
- const b = x > O.current, T = O.current === 0 && x > 0;
679
- if ((b || T) && N.current) {
680
- const C = Math.ceil(
681
- m.current?.clientHeight || 0 / r
682
- ), P = {
675
+ }, [t, n, A]);
676
+ et(() => {
677
+ if (!c || A === 0) return;
678
+ const E = A > M.current, N = M.current === 0 && A > 0;
679
+ if ((E || N) && P.current && !H.current) {
680
+ const _ = Math.ceil(
681
+ (m.current?.clientHeight || 0) / r
682
+ ), j = {
683
683
  startIndex: Math.max(
684
684
  0,
685
- x - C - a
685
+ A - _ - a
686
686
  ),
687
- endIndex: x
687
+ endIndex: A
688
688
  };
689
- p(P);
690
- const z = setTimeout(() => {
691
- !L() && m.current && (m.current.scrollTop = m.current.scrollHeight);
689
+ p(j);
690
+ const W = setTimeout(() => {
691
+ !T() && m.current && (m.current.scrollTop = m.current.scrollHeight);
692
692
  }, 50);
693
- return O.current = x, () => clearTimeout(z);
693
+ return M.current = A, () => clearTimeout(W);
694
694
  }
695
- O.current = x;
696
- }, [x]), tt(() => {
697
- const b = m.current;
698
- if (!b) return;
699
- const T = () => {
700
- const { scrollTop: C, scrollHeight: P, clientHeight: z } = b, lt = P - C - z;
701
- N.current = lt < 5;
702
- let dt = 0;
703
- for (let Y = 0; Y < E.length; Y++)
704
- if (E[Y] > C - r * a) {
705
- dt = Math.max(0, Y - 1);
695
+ M.current = A;
696
+ }, [A]), et(() => {
697
+ const E = m.current;
698
+ if (!E) return;
699
+ const N = () => {
700
+ const { scrollTop: _, scrollHeight: j, clientHeight: W } = E, it = j - _ - W, vt = it < 5;
701
+ P.current = vt, !vt && it > 50 && (H.current = !0), vt && (H.current = !1);
702
+ let ut = 0;
703
+ for (let Z = 0; Z < x.length; Z++)
704
+ if (x[Z] > _ - r * a) {
705
+ ut = Math.max(0, Z - 1);
706
706
  break;
707
707
  }
708
- let Et = dt;
709
- const _t = C + z;
710
- for (let Y = dt; Y < E.length && !(E[Y] > _t + r * a); Y++)
711
- Et = Y;
708
+ let Tt = ut;
709
+ const Mt = _ + W;
710
+ for (let Z = ut; Z < x.length && !(x[Z] > Mt + r * a); Z++)
711
+ Tt = Z;
712
712
  p({
713
- startIndex: Math.max(0, dt),
714
- endIndex: Math.min(x, Et + 1 + a)
713
+ startIndex: Math.max(0, ut),
714
+ endIndex: Math.min(A, Tt + 1 + a)
715
715
  });
716
716
  };
717
- return b.addEventListener("scroll", T, {
717
+ return E.addEventListener("scroll", N, {
718
718
  passive: !0
719
- }), c && x > 0 && (b.scrollTop = b.scrollHeight), T(), () => {
720
- b.removeEventListener("scroll", T);
719
+ }), c && A > 0 && (E.scrollTop = E.scrollHeight), N(), () => {
720
+ E.removeEventListener("scroll", N);
721
721
  };
722
- }, [E, x, r, a, c]);
723
- const A = gt(() => {
724
- N.current = !0, !L() && m.current && (m.current.scrollTop = m.current.scrollHeight);
725
- }, [L]), G = gt(
726
- (b, T = "smooth") => {
727
- const P = (o.getState().getShadowMetadata(t, n) || [])[b];
728
- if (P?.virtualizer?.domRef) {
729
- const z = P.virtualizer.domRef;
730
- if (z && z.scrollIntoView) {
731
- z.scrollIntoView({ behavior: T, block: "center" });
722
+ }, [x, A, r, a, c]);
723
+ const D = ft(() => {
724
+ P.current = !0, !T() && m.current && (m.current.scrollTop = m.current.scrollHeight);
725
+ }, [T]), O = ft(
726
+ (E, N = "smooth") => {
727
+ const j = (o.getState().getShadowMetadata(t, n) || [])[E];
728
+ if (j?.virtualizer?.domRef) {
729
+ const W = j.virtualizer.domRef;
730
+ if (W && W.scrollIntoView) {
731
+ W.scrollIntoView({ behavior: N, block: "center" });
732
732
  return;
733
733
  }
734
734
  }
735
- m.current && E[b] !== void 0 && m.current.scrollTo({
736
- top: E[b],
737
- behavior: T
735
+ m.current && x[E] !== void 0 && m.current.scrollTo({
736
+ top: x[E],
737
+ behavior: N
738
738
  });
739
739
  },
740
- [E, t, n]
741
- ), U = {
740
+ [x, t, n]
741
+ ), B = {
742
742
  outer: {
743
743
  ref: m,
744
744
  style: { overflowY: "auto", height: "100%" }
745
745
  },
746
746
  inner: {
747
747
  style: {
748
- height: `${R}px`,
748
+ height: `${$}px`,
749
749
  position: "relative"
750
750
  }
751
751
  },
752
752
  list: {
753
753
  style: {
754
- transform: `translateY(${E[k.startIndex] || 0}px)`
754
+ transform: `translateY(${x[k.startIndex] || 0}px)`
755
755
  }
756
756
  }
757
757
  };
758
758
  return {
759
- virtualState: j,
760
- virtualizerProps: U,
761
- scrollToBottom: A,
762
- scrollToIndex: G
759
+ virtualState: G,
760
+ virtualizerProps: B,
761
+ scrollToBottom: D,
762
+ scrollToIndex: O
763
763
  };
764
764
  };
765
765
  if (l === "stateMapNoRender")
@@ -776,7 +776,7 @@ function St(t, s, S, u) {
776
776
  );
777
777
  });
778
778
  if (l === "$stateMap")
779
- return (e) => it(Yt, {
779
+ return (e) => ct(Xt, {
780
780
  proxy: {
781
781
  _stateKey: t,
782
782
  _path: n,
@@ -789,11 +789,11 @@ function St(t, s, S, u) {
789
789
  return (e) => {
790
790
  const r = o.getState().getNestedState(t, n);
791
791
  return Array.isArray(r) ? (g?.validIndices || Array.from({ length: r.length }, (c, w) => w)).map((c, w) => {
792
- const m = r[c], k = [...n, c.toString()], p = i(m, k, g), V = `${S}-${n.join(".")}-${c}`;
793
- return it(Xt, {
792
+ const m = r[c], k = [...n, c.toString()], p = i(m, k, g), b = `${S}-${n.join(".")}-${c}`;
793
+ return ct(Kt, {
794
794
  key: c,
795
795
  stateKey: t,
796
- itemComponentId: V,
796
+ itemComponentId: b,
797
797
  itemPath: k,
798
798
  children: e(
799
799
  m,
@@ -810,7 +810,7 @@ function St(t, s, S, u) {
810
810
  if (l === "stateFlattenOn")
811
811
  return (e) => {
812
812
  const r = h;
813
- v.clear(), $++;
813
+ v.clear(), V++;
814
814
  const a = r.flatMap(
815
815
  (c) => c[e] ?? []
816
816
  );
@@ -833,36 +833,36 @@ function St(t, s, S, u) {
833
833
  return i(a, c);
834
834
  };
835
835
  if (l === "insert")
836
- return (e) => (I(n), ht(s, e, n, t), i(
836
+ return (e) => (I(n), yt(s, e, n, t), i(
837
837
  o.getState().getNestedState(t, n),
838
838
  n
839
839
  ));
840
840
  if (l === "uniqueInsert")
841
841
  return (e, r, a) => {
842
- const c = o.getState().getNestedState(t, n), w = Q(e) ? e(c) : e;
842
+ const c = o.getState().getNestedState(t, n), w = K(e) ? e(c) : e;
843
843
  let m = null;
844
844
  if (!c.some((p) => {
845
845
  if (r) {
846
- const _ = r.every(
847
- (N) => q(p[N], w[N])
846
+ const C = r.every(
847
+ (P) => q(p[P], w[P])
848
848
  );
849
- return _ && (m = p), _;
849
+ return C && (m = p), C;
850
850
  }
851
- const V = q(p, w);
852
- return V && (m = p), V;
851
+ const b = q(p, w);
852
+ return b && (m = p), b;
853
853
  }))
854
- I(n), ht(s, w, n, t);
854
+ I(n), yt(s, w, n, t);
855
855
  else if (a && m) {
856
- const p = a(m), V = c.map(
857
- (_) => q(_, m) ? p : _
856
+ const p = a(m), b = c.map(
857
+ (C) => q(C, m) ? p : C
858
858
  );
859
- I(n), at(s, V, n);
859
+ I(n), st(s, b, n);
860
860
  }
861
861
  };
862
862
  if (l === "cut")
863
863
  return (e, r) => {
864
864
  if (!r?.waitForSync)
865
- return I(n), ut(s, n, t, e), i(
865
+ return I(n), gt(s, n, t, e), i(
866
866
  o.getState().getNestedState(t, n),
867
867
  n
868
868
  );
@@ -870,12 +870,12 @@ function St(t, s, S, u) {
870
870
  if (l === "cutByValue")
871
871
  return (e) => {
872
872
  for (let r = 0; r < h.length; r++)
873
- h[r] === e && ut(s, n, t, r);
873
+ h[r] === e && gt(s, n, t, r);
874
874
  };
875
875
  if (l === "toggleByValue")
876
876
  return (e) => {
877
877
  const r = h.findIndex((a) => a === e);
878
- r > -1 ? ut(s, n, t, r) : ht(s, e, n, t);
878
+ r > -1 ? gt(s, n, t, r) : yt(s, e, n, t);
879
879
  };
880
880
  if (l === "stateFind")
881
881
  return (e) => {
@@ -896,15 +896,15 @@ function St(t, s, S, u) {
896
896
  return i(c.item, w, g);
897
897
  };
898
898
  }
899
- const K = n[n.length - 1];
900
- if (!isNaN(Number(K))) {
899
+ const tt = n[n.length - 1];
900
+ if (!isNaN(Number(tt))) {
901
901
  const d = n.slice(0, -1), e = o.getState().getNestedState(t, d);
902
902
  if (Array.isArray(e) && l === "cut")
903
- return () => ut(
903
+ return () => gt(
904
904
  s,
905
905
  d,
906
906
  t,
907
- Number(K)
907
+ Number(tt)
908
908
  );
909
909
  }
910
910
  if (l === "get")
@@ -916,13 +916,13 @@ function St(t, s, S, u) {
916
916
  return o.getState().getNestedState(t, n);
917
917
  };
918
918
  if (l === "$derive")
919
- return (d) => Vt({
919
+ return (d) => xt({
920
920
  _stateKey: t,
921
921
  _path: n,
922
922
  _effect: d.toString()
923
923
  });
924
924
  if (l === "$get")
925
- return () => Vt({
925
+ return () => xt({
926
926
  _stateKey: t,
927
927
  _path: n
928
928
  });
@@ -931,7 +931,7 @@ function St(t, s, S, u) {
931
931
  return o.getState().getSyncInfo(d);
932
932
  }
933
933
  if (l == "getLocalStorage")
934
- return (d) => mt(u + "-" + t + "-" + d);
934
+ return (d) => ht(u + "-" + t + "-" + d);
935
935
  if (l === "_selected") {
936
936
  const d = n.slice(0, -1), e = d.join("."), r = o.getState().getNestedState(t, d);
937
937
  return Array.isArray(r) ? Number(n[n.length - 1]) === o.getState().getSelectedIndex(t, e) : void 0;
@@ -941,7 +941,7 @@ function St(t, s, S, u) {
941
941
  const e = n.slice(0, -1), r = Number(n[n.length - 1]), a = e.join(".");
942
942
  d ? o.getState().setSelectedIndex(t, a, r) : o.getState().setSelectedIndex(t, a, void 0);
943
943
  const c = o.getState().getNestedState(t, [...e]);
944
- at(s, c, e), I(e);
944
+ st(s, c, e), I(e);
945
945
  };
946
946
  if (l === "toggleSelected")
947
947
  return () => {
@@ -952,7 +952,7 @@ function St(t, s, S, u) {
952
952
  a === e ? void 0 : e
953
953
  );
954
954
  const c = o.getState().getNestedState(t, [...d]);
955
- at(s, c, d), I(d);
955
+ st(s, c, d), I(d);
956
956
  };
957
957
  if (n.length == 0) {
958
958
  if (l === "addValidation")
@@ -960,15 +960,15 @@ function St(t, s, S, u) {
960
960
  const e = o.getState().getInitialOptions(t)?.validation;
961
961
  if (!e?.key)
962
962
  throw new Error("Validation key not found");
963
- Z(e.key), console.log("addValidationError", d), d.forEach((r) => {
963
+ X(e.key), console.log("addValidationError", d), d.forEach((r) => {
964
964
  const a = [e.key, ...r.path].join(".");
965
- console.log("fullErrorPath", a), Pt(a, r.message);
966
- }), st(t);
965
+ console.log("fullErrorPath", a), _t(a, r.message);
966
+ }), lt(t);
967
967
  };
968
968
  if (l === "applyJsonPatch")
969
969
  return (d) => {
970
- const e = o.getState().cogsStateStore[t], a = Lt(e, d).newDocument;
971
- Ct(
970
+ const e = o.getState().cogsStateStore[t], a = Wt(e, d).newDocument;
971
+ Rt(
972
972
  t,
973
973
  o.getState().initialStateGlobal[t],
974
974
  a,
@@ -978,57 +978,57 @@ function St(t, s, S, u) {
978
978
  );
979
979
  const c = o.getState().stateComponents.get(t);
980
980
  if (c) {
981
- const w = It(e, a), m = new Set(w);
981
+ const w = pt(e, a), m = new Set(w);
982
982
  for (const [
983
983
  k,
984
984
  p
985
985
  ] of c.components.entries()) {
986
- let V = !1;
987
- const _ = Array.isArray(p.reactiveType) ? p.reactiveType : [p.reactiveType || "component"];
988
- if (!_.includes("none")) {
989
- if (_.includes("all")) {
986
+ let b = !1;
987
+ const C = Array.isArray(p.reactiveType) ? p.reactiveType : [p.reactiveType || "component"];
988
+ if (!C.includes("none")) {
989
+ if (C.includes("all")) {
990
990
  p.forceUpdate();
991
991
  continue;
992
992
  }
993
- if (_.includes("component") && (p.paths.has("") && (V = !0), !V))
994
- for (const N of m) {
995
- if (p.paths.has(N)) {
996
- V = !0;
993
+ if (C.includes("component") && (p.paths.has("") && (b = !0), !b))
994
+ for (const P of m) {
995
+ if (p.paths.has(P)) {
996
+ b = !0;
997
997
  break;
998
998
  }
999
- let O = N.lastIndexOf(".");
1000
- for (; O !== -1; ) {
1001
- const B = N.substring(0, O);
1002
- if (p.paths.has(B)) {
1003
- V = !0;
999
+ let M = P.lastIndexOf(".");
1000
+ for (; M !== -1; ) {
1001
+ const H = P.substring(0, M);
1002
+ if (p.paths.has(H)) {
1003
+ b = !0;
1004
1004
  break;
1005
1005
  }
1006
- const x = N.substring(
1007
- O + 1
1006
+ const Q = P.substring(
1007
+ M + 1
1008
1008
  );
1009
- if (!isNaN(Number(x))) {
1010
- const R = B.lastIndexOf(".");
1011
- if (R !== -1) {
1012
- const E = B.substring(
1009
+ if (!isNaN(Number(Q))) {
1010
+ const A = H.lastIndexOf(".");
1011
+ if (A !== -1) {
1012
+ const $ = H.substring(
1013
1013
  0,
1014
- R
1014
+ A
1015
1015
  );
1016
- if (p.paths.has(E)) {
1017
- V = !0;
1016
+ if (p.paths.has($)) {
1017
+ b = !0;
1018
1018
  break;
1019
1019
  }
1020
1020
  }
1021
1021
  }
1022
- O = B.lastIndexOf(".");
1022
+ M = H.lastIndexOf(".");
1023
1023
  }
1024
- if (V) break;
1024
+ if (b) break;
1025
1025
  }
1026
- if (!V && _.includes("deps") && p.depsFunction) {
1027
- const N = p.depsFunction(a);
1028
- let O = !1;
1029
- typeof N == "boolean" ? N && (O = !0) : q(p.deps, N) || (p.deps = N, O = !0), O && (V = !0);
1026
+ if (!b && C.includes("deps") && p.depsFunction) {
1027
+ const P = p.depsFunction(a);
1028
+ let M = !1;
1029
+ typeof P == "boolean" ? P && (M = !0) : q(p.deps, P) || (p.deps = P, M = !0), M && (b = !0);
1030
1030
  }
1031
- V && p.forceUpdate();
1031
+ b && p.forceUpdate();
1032
1032
  }
1033
1033
  }
1034
1034
  }
@@ -1040,18 +1040,18 @@ function St(t, s, S, u) {
1040
1040
  throw new Error("Zod schema not found");
1041
1041
  if (!d?.key)
1042
1042
  throw new Error("Validation key not found");
1043
- Z(d.key);
1043
+ X(d.key);
1044
1044
  const r = o.getState().cogsStateStore[t];
1045
1045
  try {
1046
1046
  const a = o.getState().getValidationErrors(d.key);
1047
1047
  a && a.length > 0 && a.forEach(([w]) => {
1048
- w && w.startsWith(d.key) && Z(w);
1048
+ w && w.startsWith(d.key) && X(w);
1049
1049
  });
1050
1050
  const c = d.zodSchema.safeParse(r);
1051
1051
  return c.success ? !0 : (c.error.errors.forEach((m) => {
1052
- const k = m.path, p = m.message, V = [d.key, ...k].join(".");
1053
- e(V, p);
1054
- }), st(t), !1);
1052
+ const k = m.path, p = m.message, b = [d.key, ...k].join(".");
1053
+ e(b, p);
1054
+ }), lt(t), !1);
1055
1055
  } catch (a) {
1056
1056
  return console.error("Zod schema validation failed", a), !1;
1057
1057
  }
@@ -1060,7 +1060,7 @@ function St(t, s, S, u) {
1060
1060
  if (l === "getComponents")
1061
1061
  return () => o().stateComponents.get(t);
1062
1062
  if (l === "getAllFormRefs")
1063
- return () => Tt.getState().getFormRefsByStateKey(t);
1063
+ return () => kt.getState().getFormRefsByStateKey(t);
1064
1064
  if (l === "_initialState")
1065
1065
  return o.getState().initialStateGlobal[t];
1066
1066
  if (l === "_serverState")
@@ -1073,13 +1073,13 @@ function St(t, s, S, u) {
1073
1073
  if (l === "removeValidation") return y.removeValidation;
1074
1074
  }
1075
1075
  if (l === "getFormRef")
1076
- return () => Tt.getState().getFormRef(t + "." + n.join("."));
1076
+ return () => kt.getState().getFormRef(t + "." + n.join("."));
1077
1077
  if (l === "validationWrapper")
1078
1078
  return ({
1079
1079
  children: d,
1080
1080
  hideMessage: e
1081
- }) => /* @__PURE__ */ vt(
1082
- Ut,
1081
+ }) => /* @__PURE__ */ It(
1082
+ Dt,
1083
1083
  {
1084
1084
  formOpts: e ? { validation: { message: "" } } : void 0,
1085
1085
  path: n,
@@ -1095,21 +1095,21 @@ function St(t, s, S, u) {
1095
1095
  if (l === "update")
1096
1096
  return (d, e) => {
1097
1097
  if (e?.debounce)
1098
- jt(() => {
1099
- at(s, d, n, "");
1098
+ Ft(() => {
1099
+ st(s, d, n, "");
1100
1100
  const r = o.getState().getNestedState(t, n);
1101
1101
  e?.afterUpdate && e.afterUpdate(r);
1102
1102
  }, e.debounce);
1103
1103
  else {
1104
- at(s, d, n, "");
1104
+ st(s, d, n, "");
1105
1105
  const r = o.getState().getNestedState(t, n);
1106
1106
  e?.afterUpdate && e.afterUpdate(r);
1107
1107
  }
1108
1108
  I(n);
1109
1109
  };
1110
1110
  if (l === "formElement")
1111
- return (d, e) => /* @__PURE__ */ vt(
1112
- Ft,
1111
+ return (d, e) => /* @__PURE__ */ It(
1112
+ Lt,
1113
1113
  {
1114
1114
  setState: s,
1115
1115
  stateKey: t,
@@ -1118,23 +1118,23 @@ function St(t, s, S, u) {
1118
1118
  formOpts: e
1119
1119
  }
1120
1120
  );
1121
- const M = [...n, l], ot = o.getState().getNestedState(t, M);
1122
- return i(ot, M, g);
1121
+ const R = [...n, l], at = o.getState().getNestedState(t, R);
1122
+ return i(at, R, g);
1123
1123
  }
1124
- }, H = new Proxy(F, D);
1125
- return v.set(W, {
1126
- proxy: H,
1127
- stateVersion: $
1128
- }), H;
1124
+ }, z = new Proxy(U, F);
1125
+ return v.set(L, {
1126
+ proxy: z,
1127
+ stateVersion: V
1128
+ }), z;
1129
1129
  }
1130
1130
  return i(
1131
1131
  o.getState().getNestedState(t, [])
1132
1132
  );
1133
1133
  }
1134
- function Vt(t) {
1135
- return it(Zt, { proxy: t });
1134
+ function xt(t) {
1135
+ return ct(Qt, { proxy: t });
1136
1136
  }
1137
- function Yt({
1137
+ function Xt({
1138
1138
  proxy: t,
1139
1139
  rebuildStateShape: s
1140
1140
  }) {
@@ -1143,14 +1143,14 @@ function Yt({
1143
1143
  S,
1144
1144
  t._path
1145
1145
  ).stateMapNoRender(
1146
- (v, $, I, y, i) => t._mapFn(v, $, I, y, i)
1146
+ (v, V, I, y, i) => t._mapFn(v, V, I, y, i)
1147
1147
  ) : null;
1148
1148
  }
1149
- function Zt({
1149
+ function Qt({
1150
1150
  proxy: t
1151
1151
  }) {
1152
- const s = X(null), S = `${t._stateKey}-${t._path.join(".")}`;
1153
- return tt(() => {
1152
+ const s = J(null), S = `${t._stateKey}-${t._path.join(".")}`;
1153
+ return et(() => {
1154
1154
  const u = s.current;
1155
1155
  if (!u || !u.parentElement) return;
1156
1156
  const v = u.parentElement, I = Array.from(v.childNodes).indexOf(u);
@@ -1171,22 +1171,22 @@ function Zt({
1171
1171
  "state",
1172
1172
  `return (${t._effect})(state)`
1173
1173
  )(n);
1174
- } catch (F) {
1175
- console.error("Error evaluating effect function during mount:", F), g = n;
1174
+ } catch (U) {
1175
+ console.error("Error evaluating effect function during mount:", U), g = n;
1176
1176
  }
1177
1177
  else
1178
1178
  g = n;
1179
1179
  g !== null && typeof g == "object" && (g = JSON.stringify(g));
1180
- const W = document.createTextNode(String(g));
1181
- u.replaceWith(W);
1182
- }, [t._stateKey, t._path.join("."), t._effect]), it("span", {
1180
+ const L = document.createTextNode(String(g));
1181
+ u.replaceWith(L);
1182
+ }, [t._stateKey, t._path.join("."), t._effect]), ct("span", {
1183
1183
  ref: s,
1184
1184
  style: { display: "none" },
1185
1185
  "data-signal-id": S
1186
1186
  });
1187
1187
  }
1188
- function ge(t) {
1189
- const s = Rt(
1188
+ function Se(t) {
1189
+ const s = Ot(
1190
1190
  (S) => {
1191
1191
  const u = o.getState().stateComponents.get(t._stateKey) || {
1192
1192
  components: /* @__PURE__ */ new Map()
@@ -1198,21 +1198,21 @@ function ge(t) {
1198
1198
  },
1199
1199
  () => o.getState().getNestedState(t._stateKey, t._path)
1200
1200
  );
1201
- return it("text", {}, String(s));
1201
+ return ct("text", {}, String(s));
1202
1202
  }
1203
- function Xt({
1203
+ function Kt({
1204
1204
  stateKey: t,
1205
1205
  itemComponentId: s,
1206
1206
  itemPath: S,
1207
1207
  children: u
1208
1208
  }) {
1209
- const [, v] = rt({}), [$, I] = Gt(), y = X(null), i = X(null), h = gt(
1209
+ const [, v] = ot({}), [V, I] = zt(), y = J(null), i = J(null), h = ft(
1210
1210
  (n) => {
1211
- $(n), y.current = n;
1211
+ V(n), y.current = n;
1212
1212
  },
1213
- [$]
1213
+ [V]
1214
1214
  );
1215
- return tt(() => {
1215
+ return et(() => {
1216
1216
  I.height > 0 && I.height !== i.current && (i.current = I.height, o.getState().setShadowMetadata(t, S, {
1217
1217
  virtualizer: {
1218
1218
  itemHeight: I.height,
@@ -1220,7 +1220,7 @@ function Xt({
1220
1220
  // Store the actual DOM element reference
1221
1221
  }
1222
1222
  }));
1223
- }, [I.height, t, S]), $t(() => {
1223
+ }, [I.height, t, S]), Nt(() => {
1224
1224
  const n = `${t}////${s}`, g = o.getState().stateComponents.get(t) || {
1225
1225
  components: /* @__PURE__ */ new Map()
1226
1226
  };
@@ -1228,17 +1228,17 @@ function Xt({
1228
1228
  forceUpdate: () => v({}),
1229
1229
  paths: /* @__PURE__ */ new Set([S.join(".")])
1230
1230
  }), o.getState().stateComponents.set(t, g), () => {
1231
- const W = o.getState().stateComponents.get(t);
1232
- W && W.components.delete(n);
1231
+ const L = o.getState().stateComponents.get(t);
1232
+ L && L.components.delete(n);
1233
1233
  };
1234
- }, [t, s, S.join(".")]), /* @__PURE__ */ vt("div", { ref: h, children: u });
1234
+ }, [t, s, S.join(".")]), /* @__PURE__ */ It("div", { ref: h, children: u });
1235
1235
  }
1236
1236
  export {
1237
- Vt as $cogsSignal,
1238
- ge as $cogsSignalStore,
1239
- le as addStateOptions,
1240
- de as createCogsState,
1241
- ue as notifyComponent,
1242
- Jt as useCogsStateFn
1237
+ xt as $cogsSignal,
1238
+ Se as $cogsSignalStore,
1239
+ ue as addStateOptions,
1240
+ ge as createCogsState,
1241
+ fe as notifyComponent,
1242
+ Zt as useCogsStateFn
1243
1243
  };
1244
1244
  //# sourceMappingURL=CogsState.jsx.map