cogsbox-state 0.5.337 → 0.5.339

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