cogsbox-state 0.5.310 → 0.5.312

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