cogsbox-state 0.5.309 → 0.5.310

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