cogsbox-state 0.5.417 → 0.5.419

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 st, 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 it, 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
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) {
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, j] = 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 j;
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), ct(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), ct(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
+ }, ct = (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, j] = ot({}), { sessionId: U } = Pt();
197
+ let W = !s;
198
+ const [f] = ot(s ?? Et()), l = o.getState().stateLog[f], lt = 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 && U && (m = ht(`${U}-${f}-${k}`));
224
+ let p = i, b = !1;
225
+ const C = a ? Date.now() : 0, P = m?.lastUpdated || 0, F = m?.lastSyncedWithServer || 0;
226
+ a && C > P ? (p = e.serverState.data, b = !0) : m && P > F && (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
+ U
233
+ ), b && k && U && $t(p, f, e, U, Date.now()), ct(f), (Array.isArray(I) ? I : [I || "component"]).includes("none") || j({});
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
+ W && 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: () => j({}),
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), j({}), () => {
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
+ lt.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 M = 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 (M) {
286
+ const H = Array.from(M.childNodes);
287
+ if (H[T]) {
288
+ const E = D ? new Function("state", `return (${D})(state)`)(x) : x;
289
+ H[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 M = Array.isArray(T.reactiveType) ? T.reactiveType : [T.reactiveType || "component"];
319
+ if (console.log("component", T), !M.includes("none")) {
320
+ if (M.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 (M.includes("component") && ((T.paths.has(x) || T.paths.has("")) && (D = !0), !D))
325
+ for (const H of $) {
326
+ let E = H;
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 && M.includes("deps") && T.depsFunction) {
353
+ const H = T.depsFunction(k);
354
+ let E = !1;
355
+ typeof H == "boolean" ? H && (E = !0) : q(T.deps, H) || (T.deps = H, 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: F, newValue: z } = 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: F,
378
+ newValue: z
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, z);
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)}`, M = G.get(D);
396
+ return M ? (M.timeStamp = Math.max(M.timeStamp, T.timeStamp), M.newValue = T.newValue, M.oldValue = M.oldValue ?? T.oldValue, M.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
+ U
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
+ U
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
+ U
433
+ ), [f, U]);
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, []), j = rt(t), U = K(j?.localStorage?.key) ? j?.localStorage?.key(g) : j?.localStorage?.key, W = `${u}-${t}-${U}`;
454
+ W && localStorage.removeItem(W), 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), j = K(L?.localStorage?.key) ? L?.localStorage?.key(g) : L?.localStorage?.key, U = `${u}-${t}-${j}`;
468
+ return localStorage.getItem(U) && localStorage.removeItem(U), jt(() => {
469
+ At(t, h), o.getState().initializeShadowState(t, h), St(t, n), nt(t, h);
470
+ const W = o.getState().stateComponents.get(t);
471
+ W && W.components.forEach((f) => {
472
472
  f.forceUpdate();
473
473
  });
474
474
  }), {
475
- fetchId: (H) => n.get()[H]
475
+ fetchId: (W) => n.get()[W]
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 j = function() {
490
490
  return o().getNestedState(t, n);
491
491
  };
492
492
  Object.keys(y).forEach((f) => {
493
- F[f] = y[f];
493
+ j[f] = y[f];
494
494
  });
495
- const D = {
496
- apply(f, l, ct) {
495
+ const U = {
496
+ apply(f, l, lt) {
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 lt = /* @__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" && !lt.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), F = J(0), z = 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 O = 0; O < A; O++) {
640
+ _[O] = N;
641
+ const B = E[O]?.virtualizer?.itemHeight;
642
+ N += B || 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
+ (B, dt) => E + dt
655
+ ), O = _.map((B) => Q[B]);
656
+ return i(O, 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 O = _.virtualizer.domRef;
666
+ if (O && O.scrollIntoView)
667
+ return O.scrollIntoView({
668
668
  behavior: "auto",
669
669
  block: "end",
670
670
  inline: "nearest"
@@ -672,94 +672,92 @@ 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 > F.current, N = F.current === 0 && A > 0;
679
+ if ((E || N) && P.current) {
680
+ const _ = Math.ceil(
681
+ (m.current?.clientHeight || 0) / r
682
+ ), O = {
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(O), setTimeout(() => {
690
+ m.current && (m.current.scrollTop = m.current.scrollHeight);
692
691
  }, 50);
693
- return O.current = x, () => clearTimeout(z);
694
692
  }
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);
693
+ F.current = A;
694
+ }, [A]), et(() => {
695
+ const E = m.current;
696
+ if (!E) return;
697
+ const N = () => {
698
+ const { scrollTop: _, scrollHeight: O, clientHeight: B } = E, dt = O - _ - B, vt = dt < 5;
699
+ P.current = vt, !vt && dt > 50 && (z.current = !0), vt && (z.current = !1);
700
+ let ut = 0;
701
+ for (let Z = 0; Z < x.length; Z++)
702
+ if (x[Z] > _ - r * a) {
703
+ ut = Math.max(0, Z - 1);
706
704
  break;
707
705
  }
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;
706
+ let kt = ut;
707
+ const Mt = _ + B;
708
+ for (let Z = ut; Z < x.length && !(x[Z] > Mt + r * a); Z++)
709
+ kt = Z;
712
710
  p({
713
- startIndex: Math.max(0, dt),
714
- endIndex: Math.min(x, Et + 1 + a)
711
+ startIndex: Math.max(0, ut),
712
+ endIndex: Math.min(A, kt + 1 + a)
715
713
  });
716
714
  };
717
- return b.addEventListener("scroll", T, {
715
+ return E.addEventListener("scroll", N, {
718
716
  passive: !0
719
- }), c && x > 0 && (b.scrollTop = b.scrollHeight), T(), () => {
720
- b.removeEventListener("scroll", T);
717
+ }), c && A > 0 && (E.scrollTop = E.scrollHeight), N(), () => {
718
+ E.removeEventListener("scroll", N);
721
719
  };
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" });
720
+ }, [x, A, r, a, c]);
721
+ const D = ft(() => {
722
+ P.current = !0, !T() && m.current && (m.current.scrollTop = m.current.scrollHeight);
723
+ }, [T]), M = ft(
724
+ (E, N = "smooth") => {
725
+ const O = (o.getState().getShadowMetadata(t, n) || [])[E];
726
+ if (O?.virtualizer?.domRef) {
727
+ const B = O.virtualizer.domRef;
728
+ if (B && B.scrollIntoView) {
729
+ B.scrollIntoView({ behavior: N, block: "center" });
732
730
  return;
733
731
  }
734
732
  }
735
- m.current && E[b] !== void 0 && m.current.scrollTo({
736
- top: E[b],
737
- behavior: T
733
+ m.current && x[E] !== void 0 && m.current.scrollTo({
734
+ top: x[E],
735
+ behavior: N
738
736
  });
739
737
  },
740
- [E, t, n]
741
- ), U = {
738
+ [x, t, n]
739
+ ), H = {
742
740
  outer: {
743
741
  ref: m,
744
742
  style: { overflowY: "auto", height: "100%" }
745
743
  },
746
744
  inner: {
747
745
  style: {
748
- height: `${R}px`,
746
+ height: `${$}px`,
749
747
  position: "relative"
750
748
  }
751
749
  },
752
750
  list: {
753
751
  style: {
754
- transform: `translateY(${E[k.startIndex] || 0}px)`
752
+ transform: `translateY(${x[k.startIndex] || 0}px)`
755
753
  }
756
754
  }
757
755
  };
758
756
  return {
759
- virtualState: j,
760
- virtualizerProps: U,
761
- scrollToBottom: A,
762
- scrollToIndex: G
757
+ virtualState: G,
758
+ virtualizerProps: H,
759
+ scrollToBottom: D,
760
+ scrollToIndex: M
763
761
  };
764
762
  };
765
763
  if (l === "stateMapNoRender")
@@ -776,7 +774,7 @@ function St(t, s, S, u) {
776
774
  );
777
775
  });
778
776
  if (l === "$stateMap")
779
- return (e) => it(Yt, {
777
+ return (e) => st(Xt, {
780
778
  proxy: {
781
779
  _stateKey: t,
782
780
  _path: n,
@@ -789,11 +787,11 @@ function St(t, s, S, u) {
789
787
  return (e) => {
790
788
  const r = o.getState().getNestedState(t, n);
791
789
  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, {
790
+ const m = r[c], k = [...n, c.toString()], p = i(m, k, g), b = `${S}-${n.join(".")}-${c}`;
791
+ return st(Kt, {
794
792
  key: c,
795
793
  stateKey: t,
796
- itemComponentId: V,
794
+ itemComponentId: b,
797
795
  itemPath: k,
798
796
  children: e(
799
797
  m,
@@ -810,7 +808,7 @@ function St(t, s, S, u) {
810
808
  if (l === "stateFlattenOn")
811
809
  return (e) => {
812
810
  const r = h;
813
- v.clear(), $++;
811
+ v.clear(), V++;
814
812
  const a = r.flatMap(
815
813
  (c) => c[e] ?? []
816
814
  );
@@ -833,36 +831,36 @@ function St(t, s, S, u) {
833
831
  return i(a, c);
834
832
  };
835
833
  if (l === "insert")
836
- return (e) => (I(n), ht(s, e, n, t), i(
834
+ return (e) => (I(n), yt(s, e, n, t), i(
837
835
  o.getState().getNestedState(t, n),
838
836
  n
839
837
  ));
840
838
  if (l === "uniqueInsert")
841
839
  return (e, r, a) => {
842
- const c = o.getState().getNestedState(t, n), w = Q(e) ? e(c) : e;
840
+ const c = o.getState().getNestedState(t, n), w = K(e) ? e(c) : e;
843
841
  let m = null;
844
842
  if (!c.some((p) => {
845
843
  if (r) {
846
- const _ = r.every(
847
- (N) => q(p[N], w[N])
844
+ const C = r.every(
845
+ (P) => q(p[P], w[P])
848
846
  );
849
- return _ && (m = p), _;
847
+ return C && (m = p), C;
850
848
  }
851
- const V = q(p, w);
852
- return V && (m = p), V;
849
+ const b = q(p, w);
850
+ return b && (m = p), b;
853
851
  }))
854
- I(n), ht(s, w, n, t);
852
+ I(n), yt(s, w, n, t);
855
853
  else if (a && m) {
856
- const p = a(m), V = c.map(
857
- (_) => q(_, m) ? p : _
854
+ const p = a(m), b = c.map(
855
+ (C) => q(C, m) ? p : C
858
856
  );
859
- I(n), at(s, V, n);
857
+ I(n), it(s, b, n);
860
858
  }
861
859
  };
862
860
  if (l === "cut")
863
861
  return (e, r) => {
864
862
  if (!r?.waitForSync)
865
- return I(n), ut(s, n, t, e), i(
863
+ return I(n), gt(s, n, t, e), i(
866
864
  o.getState().getNestedState(t, n),
867
865
  n
868
866
  );
@@ -870,12 +868,12 @@ function St(t, s, S, u) {
870
868
  if (l === "cutByValue")
871
869
  return (e) => {
872
870
  for (let r = 0; r < h.length; r++)
873
- h[r] === e && ut(s, n, t, r);
871
+ h[r] === e && gt(s, n, t, r);
874
872
  };
875
873
  if (l === "toggleByValue")
876
874
  return (e) => {
877
875
  const r = h.findIndex((a) => a === e);
878
- r > -1 ? ut(s, n, t, r) : ht(s, e, n, t);
876
+ r > -1 ? gt(s, n, t, r) : yt(s, e, n, t);
879
877
  };
880
878
  if (l === "stateFind")
881
879
  return (e) => {
@@ -896,15 +894,15 @@ function St(t, s, S, u) {
896
894
  return i(c.item, w, g);
897
895
  };
898
896
  }
899
- const K = n[n.length - 1];
900
- if (!isNaN(Number(K))) {
897
+ const tt = n[n.length - 1];
898
+ if (!isNaN(Number(tt))) {
901
899
  const d = n.slice(0, -1), e = o.getState().getNestedState(t, d);
902
900
  if (Array.isArray(e) && l === "cut")
903
- return () => ut(
901
+ return () => gt(
904
902
  s,
905
903
  d,
906
904
  t,
907
- Number(K)
905
+ Number(tt)
908
906
  );
909
907
  }
910
908
  if (l === "get")
@@ -916,13 +914,13 @@ function St(t, s, S, u) {
916
914
  return o.getState().getNestedState(t, n);
917
915
  };
918
916
  if (l === "$derive")
919
- return (d) => Vt({
917
+ return (d) => xt({
920
918
  _stateKey: t,
921
919
  _path: n,
922
920
  _effect: d.toString()
923
921
  });
924
922
  if (l === "$get")
925
- return () => Vt({
923
+ return () => xt({
926
924
  _stateKey: t,
927
925
  _path: n
928
926
  });
@@ -931,7 +929,7 @@ function St(t, s, S, u) {
931
929
  return o.getState().getSyncInfo(d);
932
930
  }
933
931
  if (l == "getLocalStorage")
934
- return (d) => mt(u + "-" + t + "-" + d);
932
+ return (d) => ht(u + "-" + t + "-" + d);
935
933
  if (l === "_selected") {
936
934
  const d = n.slice(0, -1), e = d.join("."), r = o.getState().getNestedState(t, d);
937
935
  return Array.isArray(r) ? Number(n[n.length - 1]) === o.getState().getSelectedIndex(t, e) : void 0;
@@ -941,7 +939,7 @@ function St(t, s, S, u) {
941
939
  const e = n.slice(0, -1), r = Number(n[n.length - 1]), a = e.join(".");
942
940
  d ? o.getState().setSelectedIndex(t, a, r) : o.getState().setSelectedIndex(t, a, void 0);
943
941
  const c = o.getState().getNestedState(t, [...e]);
944
- at(s, c, e), I(e);
942
+ it(s, c, e), I(e);
945
943
  };
946
944
  if (l === "toggleSelected")
947
945
  return () => {
@@ -952,7 +950,7 @@ function St(t, s, S, u) {
952
950
  a === e ? void 0 : e
953
951
  );
954
952
  const c = o.getState().getNestedState(t, [...d]);
955
- at(s, c, d), I(d);
953
+ it(s, c, d), I(d);
956
954
  };
957
955
  if (n.length == 0) {
958
956
  if (l === "addValidation")
@@ -960,15 +958,15 @@ function St(t, s, S, u) {
960
958
  const e = o.getState().getInitialOptions(t)?.validation;
961
959
  if (!e?.key)
962
960
  throw new Error("Validation key not found");
963
- Z(e.key), console.log("addValidationError", d), d.forEach((r) => {
961
+ X(e.key), console.log("addValidationError", d), d.forEach((r) => {
964
962
  const a = [e.key, ...r.path].join(".");
965
- console.log("fullErrorPath", a), Pt(a, r.message);
966
- }), st(t);
963
+ console.log("fullErrorPath", a), _t(a, r.message);
964
+ }), ct(t);
967
965
  };
968
966
  if (l === "applyJsonPatch")
969
967
  return (d) => {
970
- const e = o.getState().cogsStateStore[t], a = Lt(e, d).newDocument;
971
- Ct(
968
+ const e = o.getState().cogsStateStore[t], a = Wt(e, d).newDocument;
969
+ Rt(
972
970
  t,
973
971
  o.getState().initialStateGlobal[t],
974
972
  a,
@@ -978,57 +976,57 @@ function St(t, s, S, u) {
978
976
  );
979
977
  const c = o.getState().stateComponents.get(t);
980
978
  if (c) {
981
- const w = It(e, a), m = new Set(w);
979
+ const w = pt(e, a), m = new Set(w);
982
980
  for (const [
983
981
  k,
984
982
  p
985
983
  ] 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")) {
984
+ let b = !1;
985
+ const C = Array.isArray(p.reactiveType) ? p.reactiveType : [p.reactiveType || "component"];
986
+ if (!C.includes("none")) {
987
+ if (C.includes("all")) {
990
988
  p.forceUpdate();
991
989
  continue;
992
990
  }
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;
991
+ if (C.includes("component") && (p.paths.has("") && (b = !0), !b))
992
+ for (const P of m) {
993
+ if (p.paths.has(P)) {
994
+ b = !0;
997
995
  break;
998
996
  }
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;
997
+ let F = P.lastIndexOf(".");
998
+ for (; F !== -1; ) {
999
+ const z = P.substring(0, F);
1000
+ if (p.paths.has(z)) {
1001
+ b = !0;
1004
1002
  break;
1005
1003
  }
1006
- const x = N.substring(
1007
- O + 1
1004
+ const Q = P.substring(
1005
+ F + 1
1008
1006
  );
1009
- if (!isNaN(Number(x))) {
1010
- const R = B.lastIndexOf(".");
1011
- if (R !== -1) {
1012
- const E = B.substring(
1007
+ if (!isNaN(Number(Q))) {
1008
+ const A = z.lastIndexOf(".");
1009
+ if (A !== -1) {
1010
+ const $ = z.substring(
1013
1011
  0,
1014
- R
1012
+ A
1015
1013
  );
1016
- if (p.paths.has(E)) {
1017
- V = !0;
1014
+ if (p.paths.has($)) {
1015
+ b = !0;
1018
1016
  break;
1019
1017
  }
1020
1018
  }
1021
1019
  }
1022
- O = B.lastIndexOf(".");
1020
+ F = z.lastIndexOf(".");
1023
1021
  }
1024
- if (V) break;
1022
+ if (b) break;
1025
1023
  }
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);
1024
+ if (!b && C.includes("deps") && p.depsFunction) {
1025
+ const P = p.depsFunction(a);
1026
+ let F = !1;
1027
+ typeof P == "boolean" ? P && (F = !0) : q(p.deps, P) || (p.deps = P, F = !0), F && (b = !0);
1030
1028
  }
1031
- V && p.forceUpdate();
1029
+ b && p.forceUpdate();
1032
1030
  }
1033
1031
  }
1034
1032
  }
@@ -1040,18 +1038,18 @@ function St(t, s, S, u) {
1040
1038
  throw new Error("Zod schema not found");
1041
1039
  if (!d?.key)
1042
1040
  throw new Error("Validation key not found");
1043
- Z(d.key);
1041
+ X(d.key);
1044
1042
  const r = o.getState().cogsStateStore[t];
1045
1043
  try {
1046
1044
  const a = o.getState().getValidationErrors(d.key);
1047
1045
  a && a.length > 0 && a.forEach(([w]) => {
1048
- w && w.startsWith(d.key) && Z(w);
1046
+ w && w.startsWith(d.key) && X(w);
1049
1047
  });
1050
1048
  const c = d.zodSchema.safeParse(r);
1051
1049
  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);
1050
+ const k = m.path, p = m.message, b = [d.key, ...k].join(".");
1051
+ e(b, p);
1052
+ }), ct(t), !1);
1055
1053
  } catch (a) {
1056
1054
  return console.error("Zod schema validation failed", a), !1;
1057
1055
  }
@@ -1078,8 +1076,8 @@ function St(t, s, S, u) {
1078
1076
  return ({
1079
1077
  children: d,
1080
1078
  hideMessage: e
1081
- }) => /* @__PURE__ */ vt(
1082
- Ut,
1079
+ }) => /* @__PURE__ */ It(
1080
+ Dt,
1083
1081
  {
1084
1082
  formOpts: e ? { validation: { message: "" } } : void 0,
1085
1083
  path: n,
@@ -1095,21 +1093,21 @@ function St(t, s, S, u) {
1095
1093
  if (l === "update")
1096
1094
  return (d, e) => {
1097
1095
  if (e?.debounce)
1098
- jt(() => {
1099
- at(s, d, n, "");
1096
+ Ft(() => {
1097
+ it(s, d, n, "");
1100
1098
  const r = o.getState().getNestedState(t, n);
1101
1099
  e?.afterUpdate && e.afterUpdate(r);
1102
1100
  }, e.debounce);
1103
1101
  else {
1104
- at(s, d, n, "");
1102
+ it(s, d, n, "");
1105
1103
  const r = o.getState().getNestedState(t, n);
1106
1104
  e?.afterUpdate && e.afterUpdate(r);
1107
1105
  }
1108
1106
  I(n);
1109
1107
  };
1110
1108
  if (l === "formElement")
1111
- return (d, e) => /* @__PURE__ */ vt(
1112
- Ft,
1109
+ return (d, e) => /* @__PURE__ */ It(
1110
+ Lt,
1113
1111
  {
1114
1112
  setState: s,
1115
1113
  stateKey: t,
@@ -1118,23 +1116,23 @@ function St(t, s, S, u) {
1118
1116
  formOpts: e
1119
1117
  }
1120
1118
  );
1121
- const M = [...n, l], ot = o.getState().getNestedState(t, M);
1122
- return i(ot, M, g);
1119
+ const R = [...n, l], at = o.getState().getNestedState(t, R);
1120
+ return i(at, R, g);
1123
1121
  }
1124
- }, H = new Proxy(F, D);
1125
- return v.set(W, {
1126
- proxy: H,
1127
- stateVersion: $
1128
- }), H;
1122
+ }, W = new Proxy(j, U);
1123
+ return v.set(L, {
1124
+ proxy: W,
1125
+ stateVersion: V
1126
+ }), W;
1129
1127
  }
1130
1128
  return i(
1131
1129
  o.getState().getNestedState(t, [])
1132
1130
  );
1133
1131
  }
1134
- function Vt(t) {
1135
- return it(Zt, { proxy: t });
1132
+ function xt(t) {
1133
+ return st(Qt, { proxy: t });
1136
1134
  }
1137
- function Yt({
1135
+ function Xt({
1138
1136
  proxy: t,
1139
1137
  rebuildStateShape: s
1140
1138
  }) {
@@ -1143,14 +1141,14 @@ function Yt({
1143
1141
  S,
1144
1142
  t._path
1145
1143
  ).stateMapNoRender(
1146
- (v, $, I, y, i) => t._mapFn(v, $, I, y, i)
1144
+ (v, V, I, y, i) => t._mapFn(v, V, I, y, i)
1147
1145
  ) : null;
1148
1146
  }
1149
- function Zt({
1147
+ function Qt({
1150
1148
  proxy: t
1151
1149
  }) {
1152
- const s = X(null), S = `${t._stateKey}-${t._path.join(".")}`;
1153
- return tt(() => {
1150
+ const s = J(null), S = `${t._stateKey}-${t._path.join(".")}`;
1151
+ return et(() => {
1154
1152
  const u = s.current;
1155
1153
  if (!u || !u.parentElement) return;
1156
1154
  const v = u.parentElement, I = Array.from(v.childNodes).indexOf(u);
@@ -1171,22 +1169,22 @@ function Zt({
1171
1169
  "state",
1172
1170
  `return (${t._effect})(state)`
1173
1171
  )(n);
1174
- } catch (F) {
1175
- console.error("Error evaluating effect function during mount:", F), g = n;
1172
+ } catch (j) {
1173
+ console.error("Error evaluating effect function during mount:", j), g = n;
1176
1174
  }
1177
1175
  else
1178
1176
  g = n;
1179
1177
  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", {
1178
+ const L = document.createTextNode(String(g));
1179
+ u.replaceWith(L);
1180
+ }, [t._stateKey, t._path.join("."), t._effect]), st("span", {
1183
1181
  ref: s,
1184
1182
  style: { display: "none" },
1185
1183
  "data-signal-id": S
1186
1184
  });
1187
1185
  }
1188
- function ge(t) {
1189
- const s = Rt(
1186
+ function Se(t) {
1187
+ const s = Ot(
1190
1188
  (S) => {
1191
1189
  const u = o.getState().stateComponents.get(t._stateKey) || {
1192
1190
  components: /* @__PURE__ */ new Map()
@@ -1198,21 +1196,21 @@ function ge(t) {
1198
1196
  },
1199
1197
  () => o.getState().getNestedState(t._stateKey, t._path)
1200
1198
  );
1201
- return it("text", {}, String(s));
1199
+ return st("text", {}, String(s));
1202
1200
  }
1203
- function Xt({
1201
+ function Kt({
1204
1202
  stateKey: t,
1205
1203
  itemComponentId: s,
1206
1204
  itemPath: S,
1207
1205
  children: u
1208
1206
  }) {
1209
- const [, v] = rt({}), [$, I] = Gt(), y = X(null), i = X(null), h = gt(
1207
+ const [, v] = ot({}), [V, I] = zt(), y = J(null), i = J(null), h = ft(
1210
1208
  (n) => {
1211
- $(n), y.current = n;
1209
+ V(n), y.current = n;
1212
1210
  },
1213
- [$]
1211
+ [V]
1214
1212
  );
1215
- return tt(() => {
1213
+ return et(() => {
1216
1214
  I.height > 0 && I.height !== i.current && (i.current = I.height, o.getState().setShadowMetadata(t, S, {
1217
1215
  virtualizer: {
1218
1216
  itemHeight: I.height,
@@ -1220,7 +1218,7 @@ function Xt({
1220
1218
  // Store the actual DOM element reference
1221
1219
  }
1222
1220
  }));
1223
- }, [I.height, t, S]), $t(() => {
1221
+ }, [I.height, t, S]), Nt(() => {
1224
1222
  const n = `${t}////${s}`, g = o.getState().stateComponents.get(t) || {
1225
1223
  components: /* @__PURE__ */ new Map()
1226
1224
  };
@@ -1228,17 +1226,17 @@ function Xt({
1228
1226
  forceUpdate: () => v({}),
1229
1227
  paths: /* @__PURE__ */ new Set([S.join(".")])
1230
1228
  }), o.getState().stateComponents.set(t, g), () => {
1231
- const W = o.getState().stateComponents.get(t);
1232
- W && W.components.delete(n);
1229
+ const L = o.getState().stateComponents.get(t);
1230
+ L && L.components.delete(n);
1233
1231
  };
1234
- }, [t, s, S.join(".")]), /* @__PURE__ */ vt("div", { ref: h, children: u });
1232
+ }, [t, s, S.join(".")]), /* @__PURE__ */ It("div", { ref: h, children: u });
1235
1233
  }
1236
1234
  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
1235
+ xt as $cogsSignal,
1236
+ Se as $cogsSignalStore,
1237
+ ue as addStateOptions,
1238
+ ge as createCogsState,
1239
+ fe as notifyComponent,
1240
+ Zt as useCogsStateFn
1243
1241
  };
1244
1242
  //# sourceMappingURL=CogsState.jsx.map