cogsbox-state 0.5.426 → 0.5.427

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