cogsbox-state 0.5.370 → 0.5.372

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 Te } from "react/jsx-runtime";
3
- import { useState as X, useRef as K, useEffect as oe, useLayoutEffect as ie, useMemo as ve, createElement as ce, useSyncExternalStore as Pe, startTransition as Ve, useCallback as _e } from "react";
4
- import { transformStateFunc as Ge, isDeepEqual as z, isFunction as Q, getNestedValue as q, getDifferences as ye, debounce as Le } from "./utility.js";
5
- import { pushFunc as he, updateFn as se, cutFunc as ge, ValidationWrapper as Re, FormControlComponent as De } from "./Functions.jsx";
6
- import Ue from "superjson";
7
- import { v4 as pe } from "uuid";
2
+ import { jsx as ye } from "react/jsx-runtime";
3
+ import { useState as Q, useRef as Z, useEffect as oe, useLayoutEffect as ce, useMemo as pe, createElement as le, useSyncExternalStore as Ge, startTransition as Le, useCallback as Ae } from "react";
4
+ import { transformStateFunc as Re, isDeepEqual as q, isFunction as K, getNestedValue as J, getDifferences as Ee, debounce as De } from "./utility.js";
5
+ import { pushFunc as ve, updateFn as ie, cutFunc as fe, ValidationWrapper as Ue, FormControlComponent as je } from "./Functions.jsx";
6
+ import He from "superjson";
7
+ import { v4 as we } from "uuid";
8
8
  import "zod";
9
- import { getGlobalStore as r, formRefStore as Oe } from "./store.js";
10
- import { useCogsConfig as ke } from "./CogsStateClient.jsx";
11
- import { applyPatch as je } from "fast-json-patch";
12
- import He from "react-use-measure";
13
- function Ae(e, i) {
9
+ import { getGlobalStore as r, formRefStore as Ne } from "./store.js";
10
+ import { useCogsConfig as xe } from "./CogsStateClient.jsx";
11
+ import { applyPatch as Fe } from "fast-json-patch";
12
+ import Be from "react-use-measure";
13
+ function Ce(e, i) {
14
14
  const m = r.getState().getInitialOptions, g = r.getState().setInitialStateOptions, T = m(e) || {};
15
15
  g(e, {
16
16
  ...T,
17
17
  ...i
18
18
  });
19
19
  }
20
- function Ne({
20
+ function $e({
21
21
  stateKey: e,
22
22
  options: i,
23
23
  initialOptionsPart: m
24
24
  }) {
25
- const g = re(e) || {}, T = m[e] || {}, N = r.getState().setInitialStateOptions, p = { ...T, ...g };
25
+ const g = re(e) || {}, T = m[e] || {}, C = r.getState().setInitialStateOptions, p = { ...T, ...g };
26
26
  let v = !1;
27
27
  if (i)
28
28
  for (const a in i)
29
29
  p.hasOwnProperty(a) ? (a == "localStorage" && i[a] && p[a].key !== i[a]?.key && (v = !0, p[a] = i[a]), a == "initialState" && i[a] && p[a] !== i[a] && // Different references
30
- !z(p[a], i[a]) && (v = !0, p[a] = i[a])) : (v = !0, p[a] = i[a]);
31
- v && N(e, p);
30
+ !q(p[a], i[a]) && (v = !0, p[a] = i[a])) : (v = !0, p[a] = i[a]);
31
+ v && C(e, p);
32
32
  }
33
- function dt(e, { formElements: i, validation: m }) {
33
+ function gt(e, { formElements: i, validation: m }) {
34
34
  return { initialState: e, formElements: i, validation: m };
35
35
  }
36
- const ut = (e, i) => {
36
+ const ft = (e, i) => {
37
37
  let m = e;
38
- const [g, T] = Ge(m);
38
+ const [g, T] = Re(m);
39
39
  (Object.keys(T).length > 0 || i && Object.keys(i).length > 0) && Object.keys(T).forEach((v) => {
40
40
  T[v] = T[v] || {}, T[v].formElements = {
41
41
  ...i?.formElements,
@@ -45,14 +45,14 @@ const ut = (e, i) => {
45
45
  // State-specific overrides
46
46
  }, re(v) || r.getState().setInitialStateOptions(v, T[v]);
47
47
  }), r.getState().setInitialStates(g), r.getState().setCreatedState(g);
48
- const N = (v, a) => {
49
- const [h] = X(a?.componentId ?? pe());
50
- Ne({
48
+ const C = (v, a) => {
49
+ const [h] = Q(a?.componentId ?? we());
50
+ $e({
51
51
  stateKey: v,
52
52
  options: a,
53
53
  initialOptionsPart: T
54
54
  });
55
- const n = r.getState().cogsStateStore[v] || g[v], S = a?.modifyState ? a.modifyState(n) : n, [H, L] = Ye(
55
+ const n = r.getState().cogsStateStore[v] || g[v], S = a?.modifyState ? a.modifyState(n) : n, [H, G] = Xe(
56
56
  S,
57
57
  {
58
58
  stateKey: v,
@@ -68,49 +68,49 @@ const ut = (e, i) => {
68
68
  serverState: a?.serverState
69
69
  }
70
70
  );
71
- return L;
71
+ return G;
72
72
  };
73
73
  function p(v, a) {
74
- Ne({ stateKey: v, options: a, initialOptionsPart: T }), a.localStorage && qe(v, a), Ie(v);
74
+ $e({ stateKey: v, options: a, initialOptionsPart: T }), a.localStorage && Ye(v, a), he(v);
75
75
  }
76
- return { useCogsState: N, setCogsOptions: p };
76
+ return { useCogsState: C, setCogsOptions: p };
77
77
  }, {
78
- setUpdaterState: fe,
79
- setState: te,
78
+ setUpdaterState: Se,
79
+ setState: ne,
80
80
  getInitialOptions: re,
81
- getKeyState: be,
82
- getValidationErrors: Fe,
83
- setStateLog: Be,
84
- updateInitialStateGlobal: Ee,
85
- addValidationError: We,
86
- removeValidationError: Z,
87
- setServerSyncActions: ze
88
- } = r.getState(), Ce = (e, i, m, g, T) => {
81
+ getKeyState: Me,
82
+ getValidationErrors: We,
83
+ setStateLog: ze,
84
+ updateInitialStateGlobal: _e,
85
+ addValidationError: qe,
86
+ removeValidationError: X,
87
+ setServerSyncActions: Je
88
+ } = r.getState(), ke = (e, i, m, g, T) => {
89
89
  m?.log && console.log(
90
90
  "saving to localstorage",
91
91
  i,
92
92
  m.localStorage?.key,
93
93
  g
94
94
  );
95
- const N = Q(m?.localStorage?.key) ? m.localStorage?.key(e) : m?.localStorage?.key;
96
- if (N && g) {
97
- const p = `${g}-${i}-${N}`;
95
+ const C = K(m?.localStorage?.key) ? m.localStorage?.key(e) : m?.localStorage?.key;
96
+ if (C && g) {
97
+ const p = `${g}-${i}-${C}`;
98
98
  let v;
99
99
  try {
100
- v = me(p)?.lastSyncedWithServer;
100
+ v = Ie(p)?.lastSyncedWithServer;
101
101
  } catch {
102
102
  }
103
103
  const a = {
104
104
  state: e,
105
105
  lastUpdated: Date.now(),
106
106
  lastSyncedWithServer: T ?? v
107
- }, h = Ue.serialize(a);
107
+ }, h = He.serialize(a);
108
108
  window.localStorage.setItem(
109
109
  p,
110
110
  JSON.stringify(h.json)
111
111
  );
112
112
  }
113
- }, me = (e) => {
113
+ }, Ie = (e) => {
114
114
  if (!e) return null;
115
115
  try {
116
116
  const i = window.localStorage.getItem(e);
@@ -118,29 +118,29 @@ const ut = (e, i) => {
118
118
  } catch (i) {
119
119
  return console.error("Error loading from localStorage:", i), null;
120
120
  }
121
- }, qe = (e, i) => {
122
- const m = r.getState().cogsStateStore[e], { sessionId: g } = ke(), T = Q(i?.localStorage?.key) ? i.localStorage.key(m) : i?.localStorage?.key;
121
+ }, Ye = (e, i) => {
122
+ const m = r.getState().cogsStateStore[e], { sessionId: g } = xe(), T = K(i?.localStorage?.key) ? i.localStorage.key(m) : i?.localStorage?.key;
123
123
  if (T && g) {
124
- const N = me(
124
+ const C = Ie(
125
125
  `${g}-${e}-${T}`
126
126
  );
127
- if (N && N.lastUpdated > (N.lastSyncedWithServer || 0))
128
- return te(e, N.state), Ie(e), !0;
127
+ if (C && C.lastUpdated > (C.lastSyncedWithServer || 0))
128
+ return ne(e, C.state), he(e), !0;
129
129
  }
130
130
  return !1;
131
- }, Me = (e, i, m, g, T, N) => {
131
+ }, Pe = (e, i, m, g, T, C) => {
132
132
  const p = {
133
133
  initialState: i,
134
- updaterState: Se(
134
+ updaterState: me(
135
135
  e,
136
136
  g,
137
137
  T,
138
- N
138
+ C
139
139
  ),
140
140
  state: m
141
141
  };
142
- Ee(e, p.initialState), fe(e, p.updaterState), te(e, p.state);
143
- }, Ie = (e) => {
142
+ _e(e, p.initialState), Se(e, p.updaterState), ne(e, p.state);
143
+ }, he = (e) => {
144
144
  const i = r.getState().stateComponents.get(e);
145
145
  if (!i) return;
146
146
  const m = /* @__PURE__ */ new Set();
@@ -149,7 +149,7 @@ const ut = (e, i) => {
149
149
  }), queueMicrotask(() => {
150
150
  m.forEach((g) => g());
151
151
  });
152
- }, gt = (e, i) => {
152
+ }, St = (e, i) => {
153
153
  const m = r.getState().stateComponents.get(e);
154
154
  if (m) {
155
155
  const g = `${e}////${i}`, T = m.components.get(g);
@@ -157,22 +157,22 @@ const ut = (e, i) => {
157
157
  return;
158
158
  T && T.forceUpdate();
159
159
  }
160
- }, Je = (e, i, m, g) => {
160
+ }, Ze = (e, i, m, g) => {
161
161
  switch (e) {
162
162
  case "update":
163
163
  return {
164
- oldValue: q(i, g),
165
- newValue: q(m, g)
164
+ oldValue: J(i, g),
165
+ newValue: J(m, g)
166
166
  };
167
167
  case "insert":
168
168
  return {
169
169
  oldValue: null,
170
170
  // or undefined
171
- newValue: q(m, g)
171
+ newValue: J(m, g)
172
172
  };
173
173
  case "cut":
174
174
  return {
175
- oldValue: q(i, g),
175
+ oldValue: J(i, g),
176
176
  newValue: null
177
177
  // or undefined
178
178
  };
@@ -180,12 +180,12 @@ const ut = (e, i) => {
180
180
  return { oldValue: null, newValue: null };
181
181
  }
182
182
  };
183
- function Ye(e, {
183
+ function Xe(e, {
184
184
  stateKey: i,
185
185
  serverSync: m,
186
186
  localStorage: g,
187
187
  formElements: T,
188
- reactiveDeps: N,
188
+ reactiveDeps: C,
189
189
  reactiveType: p,
190
190
  componentId: v,
191
191
  initialState: a,
@@ -193,14 +193,14 @@ function Ye(e, {
193
193
  dependencies: n,
194
194
  serverState: S
195
195
  } = {}) {
196
- const [H, L] = X({}), { sessionId: R } = ke();
196
+ const [H, G] = Q({}), { sessionId: L } = xe();
197
197
  let F = !i;
198
- const [I] = X(i ?? pe()), l = r.getState().stateLog[I], le = K(/* @__PURE__ */ new Set()), ee = K(v ?? pe()), P = K(
198
+ const [I] = Q(i ?? we()), l = r.getState().stateLog[I], de = Z(/* @__PURE__ */ new Set()), ee = Z(v ?? we()), P = Z(
199
199
  null
200
200
  );
201
201
  P.current = re(I) ?? null, oe(() => {
202
202
  if (h && h.stateKey === I && h.path?.[0]) {
203
- te(I, (o) => ({
203
+ ne(I, (o) => ({
204
204
  ...o,
205
205
  [h.path[0]]: h.newValue
206
206
  }));
@@ -212,33 +212,33 @@ function Ye(e, {
212
212
  }
213
213
  }, [h]), oe(() => {
214
214
  if (a) {
215
- Ae(I, {
215
+ Ce(I, {
216
216
  initialState: a
217
217
  });
218
218
  const t = P.current, s = t?.serverState?.id !== void 0 && t?.serverState?.status === "success" && t?.serverState?.data, c = r.getState().initialStateGlobal[I];
219
- if (!(c && !z(c, a) || !c) && !s)
219
+ if (!(c && !q(c, a) || !c) && !s)
220
220
  return;
221
221
  let u = null;
222
- const E = Q(t?.localStorage?.key) ? t?.localStorage?.key(a) : t?.localStorage?.key;
223
- E && R && (u = me(`${R}-${I}-${E}`));
224
- let w = a, _ = !1;
225
- const C = s ? Date.now() : 0, $ = u?.lastUpdated || 0, x = u?.lastSyncedWithServer || 0;
226
- s && C > $ ? (w = t.serverState.data, _ = !0) : u && $ > x && (w = u.state, t?.localStorage?.onChange && t?.localStorage?.onChange(w)), r.getState().initializeShadowState(I, a), Me(
222
+ const E = K(t?.localStorage?.key) ? t?.localStorage?.key(a) : t?.localStorage?.key;
223
+ E && L && (u = Ie(`${L}-${I}-${E}`));
224
+ let y = a, O = !1;
225
+ const k = s ? Date.now() : 0, A = u?.lastUpdated || 0, x = u?.lastSyncedWithServer || 0;
226
+ s && k > A ? (y = t.serverState.data, O = !0) : u && A > x && (y = u.state, t?.localStorage?.onChange && t?.localStorage?.onChange(y)), r.getState().initializeShadowState(I, a), Pe(
227
227
  I,
228
228
  a,
229
- w,
229
+ y,
230
230
  ae,
231
231
  ee.current,
232
- R
233
- ), _ && E && R && Ce(w, I, t, R, Date.now()), Ie(I), (Array.isArray(p) ? p : [p || "component"]).includes("none") || L({});
232
+ L
233
+ ), O && E && L && ke(y, I, t, L, Date.now()), he(I), (Array.isArray(p) ? p : [p || "component"]).includes("none") || G({});
234
234
  }
235
235
  }, [
236
236
  a,
237
237
  S?.status,
238
238
  S?.data,
239
239
  ...n || []
240
- ]), ie(() => {
241
- F && Ae(I, {
240
+ ]), ce(() => {
241
+ F && Ce(I, {
242
242
  serverSync: m,
243
243
  formElements: T,
244
244
  initialState: a,
@@ -249,133 +249,133 @@ function Ye(e, {
249
249
  components: /* @__PURE__ */ new Map()
250
250
  };
251
251
  return o.components.set(t, {
252
- forceUpdate: () => L({}),
252
+ forceUpdate: () => G({}),
253
253
  paths: /* @__PURE__ */ new Set(),
254
254
  deps: [],
255
- depsFunction: N || void 0,
255
+ depsFunction: C || void 0,
256
256
  reactiveType: p ?? ["component", "deps"]
257
- }), r.getState().stateComponents.set(I, o), L({}), () => {
257
+ }), r.getState().stateComponents.set(I, o), G({}), () => {
258
258
  o && (o.components.delete(t), o.components.size === 0 && r.getState().stateComponents.delete(I));
259
259
  };
260
260
  }, []);
261
261
  const ae = (t, o, s, c) => {
262
262
  if (Array.isArray(o)) {
263
263
  const u = `${I}-${o.join(".")}`;
264
- le.current.add(u);
264
+ de.current.add(u);
265
265
  }
266
266
  const f = r.getState();
267
- te(I, (u) => {
268
- const E = Q(t) ? t(u) : t, w = `${I}-${o.join(".")}`;
269
- if (w) {
270
- let M = !1, y = f.signalDomElements.get(w);
271
- if ((!y || y.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
272
- const V = o.slice(0, -1), b = q(E, V);
273
- if (Array.isArray(b)) {
267
+ ne(I, (u) => {
268
+ const E = K(t) ? t(u) : t, y = `${I}-${o.join(".")}`;
269
+ if (y) {
270
+ let M = !1, N = f.signalDomElements.get(y);
271
+ if ((!N || N.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
272
+ const _ = o.slice(0, -1), j = J(E, _);
273
+ if (Array.isArray(j)) {
274
274
  M = !0;
275
- const A = `${I}-${V.join(".")}`;
276
- y = f.signalDomElements.get(A);
275
+ const w = `${I}-${_.join(".")}`;
276
+ N = f.signalDomElements.get(w);
277
277
  }
278
278
  }
279
- if (y) {
280
- const V = M ? q(E, o.slice(0, -1)) : q(E, o);
281
- y.forEach(({ parentId: b, position: A, effect: D }) => {
282
- const G = document.querySelector(
283
- `[data-parent-id="${b}"]`
279
+ if (N) {
280
+ const _ = M ? J(E, o.slice(0, -1)) : J(E, o);
281
+ N.forEach(({ parentId: j, position: w, effect: R }) => {
282
+ const V = document.querySelector(
283
+ `[data-parent-id="${j}"]`
284
284
  );
285
- if (G) {
286
- const B = Array.from(G.childNodes);
287
- if (B[A]) {
288
- const O = D ? new Function("state", `return (${D})(state)`)(V) : V;
289
- B[A].textContent = String(O);
285
+ if (V) {
286
+ const W = Array.from(V.childNodes);
287
+ if (W[w]) {
288
+ const D = R ? new Function("state", `return (${R})(state)`)(_) : _;
289
+ W[w].textContent = String(D);
290
290
  }
291
291
  }
292
292
  });
293
293
  }
294
294
  }
295
- console.log("shadowState", f.shadowStateStore), s.updateType === "update" && (c || P.current?.validation?.key) && o && Z(
295
+ console.log("shadowState", f.shadowStateStore), s.updateType === "update" && (c || P.current?.validation?.key) && o && X(
296
296
  (c || P.current?.validation?.key) + "." + o.join(".")
297
297
  );
298
- const _ = o.slice(0, o.length - 1);
299
- s.updateType === "cut" && P.current?.validation?.key && Z(
300
- P.current?.validation?.key + "." + _.join(".")
301
- ), s.updateType === "insert" && P.current?.validation?.key && Fe(
302
- P.current?.validation?.key + "." + _.join(".")
303
- ).filter(([y, V]) => {
304
- let b = y?.split(".").length;
305
- if (y == _.join(".") && b == _.length - 1) {
306
- let A = y + "." + _;
307
- Z(y), We(A, V);
298
+ const O = o.slice(0, o.length - 1);
299
+ s.updateType === "cut" && P.current?.validation?.key && X(
300
+ P.current?.validation?.key + "." + O.join(".")
301
+ ), s.updateType === "insert" && P.current?.validation?.key && We(
302
+ P.current?.validation?.key + "." + O.join(".")
303
+ ).filter(([N, _]) => {
304
+ let j = N?.split(".").length;
305
+ if (N == O.join(".") && j == O.length - 1) {
306
+ let w = N + "." + O;
307
+ X(N), qe(w, _);
308
308
  }
309
309
  });
310
- const C = f.stateComponents.get(I);
311
- if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", C), C) {
312
- const M = ye(u, E), y = new Set(M), V = s.updateType === "update" ? o.join(".") : o.slice(0, -1).join(".") || "";
310
+ const k = f.stateComponents.get(I);
311
+ if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", k), k) {
312
+ const M = Ee(u, E), N = new Set(M), _ = s.updateType === "update" ? o.join(".") : o.slice(0, -1).join(".") || "";
313
313
  for (const [
314
- b,
315
- A
316
- ] of C.components.entries()) {
317
- let D = !1;
318
- const G = Array.isArray(A.reactiveType) ? A.reactiveType : [A.reactiveType || "component"];
319
- if (console.log("component", A), !G.includes("none")) {
320
- if (G.includes("all")) {
321
- A.forceUpdate();
314
+ j,
315
+ w
316
+ ] of k.components.entries()) {
317
+ let R = !1;
318
+ const V = Array.isArray(w.reactiveType) ? w.reactiveType : [w.reactiveType || "component"];
319
+ if (console.log("component", w), !V.includes("none")) {
320
+ if (V.includes("all")) {
321
+ w.forceUpdate();
322
322
  continue;
323
323
  }
324
- if (G.includes("component") && ((A.paths.has(V) || A.paths.has("")) && (D = !0), !D))
325
- for (const B of y) {
326
- let O = B;
324
+ if (V.includes("component") && ((w.paths.has(_) || w.paths.has("")) && (R = !0), !R))
325
+ for (const W of N) {
326
+ let D = W;
327
327
  for (; ; ) {
328
- if (A.paths.has(O)) {
329
- D = !0;
328
+ if (w.paths.has(D)) {
329
+ R = !0;
330
330
  break;
331
331
  }
332
- const k = O.lastIndexOf(".");
333
- if (k !== -1) {
334
- const U = O.substring(
332
+ const $ = D.lastIndexOf(".");
333
+ if ($ !== -1) {
334
+ const b = D.substring(
335
335
  0,
336
- k
336
+ $
337
337
  );
338
338
  if (!isNaN(
339
- Number(O.substring(k + 1))
340
- ) && A.paths.has(U)) {
341
- D = !0;
339
+ Number(D.substring($ + 1))
340
+ ) && w.paths.has(b)) {
341
+ R = !0;
342
342
  break;
343
343
  }
344
- O = U;
344
+ D = b;
345
345
  } else
346
- O = "";
347
- if (O === "")
346
+ D = "";
347
+ if (D === "")
348
348
  break;
349
349
  }
350
- if (D) break;
350
+ if (R) break;
351
351
  }
352
- if (!D && G.includes("deps") && A.depsFunction) {
353
- const B = A.depsFunction(E);
354
- let O = !1;
355
- typeof B == "boolean" ? B && (O = !0) : z(A.deps, B) || (A.deps = B, O = !0), O && (D = !0);
352
+ if (!R && V.includes("deps") && w.depsFunction) {
353
+ const W = w.depsFunction(E);
354
+ let D = !1;
355
+ typeof W == "boolean" ? W && (D = !0) : q(w.deps, W) || (w.deps = W, D = !0), D && (R = !0);
356
356
  }
357
- D && A.forceUpdate();
357
+ R && w.forceUpdate();
358
358
  }
359
359
  }
360
360
  }
361
- const $ = Date.now();
362
- o = o.map((M, y) => {
363
- const V = o.slice(0, -1), b = q(E, V);
364
- return y === o.length - 1 && ["insert", "cut"].includes(s.updateType) ? (b.length - 1).toString() : M;
361
+ const A = Date.now();
362
+ o = o.map((M, N) => {
363
+ const _ = o.slice(0, -1), j = J(E, _);
364
+ return N === o.length - 1 && ["insert", "cut"].includes(s.updateType) ? (j.length - 1).toString() : M;
365
365
  });
366
- const { oldValue: x, newValue: j } = Je(
366
+ const { oldValue: x, newValue: U } = Ze(
367
367
  s.updateType,
368
368
  u,
369
369
  E,
370
370
  o
371
- ), J = {
372
- timeStamp: $,
371
+ ), Y = {
372
+ timeStamp: A,
373
373
  stateKey: I,
374
374
  path: o,
375
375
  updateType: s.updateType,
376
376
  status: "new",
377
377
  oldValue: x,
378
- newValue: j
378
+ newValue: U
379
379
  };
380
380
  switch (s.updateType) {
381
381
  case "update":
@@ -383,90 +383,90 @@ function Ye(e, {
383
383
  break;
384
384
  case "insert":
385
385
  const M = o.slice(0, -1);
386
- f.insertShadowArrayElement(I, M, j);
386
+ f.insertShadowArrayElement(I, M, U);
387
387
  break;
388
388
  case "cut":
389
- const y = o.slice(0, -1), V = parseInt(o[o.length - 1]);
390
- f.removeShadowArrayElement(I, y, V);
389
+ const N = o.slice(0, -1), _ = parseInt(o[o.length - 1]);
390
+ f.removeShadowArrayElement(I, N, _);
391
391
  break;
392
392
  }
393
- if (Be(I, (M) => {
394
- const V = [...M ?? [], J].reduce((b, A) => {
395
- const D = `${A.stateKey}:${JSON.stringify(A.path)}`, G = b.get(D);
396
- return G ? (G.timeStamp = Math.max(G.timeStamp, A.timeStamp), G.newValue = A.newValue, G.oldValue = G.oldValue ?? A.oldValue, G.updateType = A.updateType) : b.set(D, { ...A }), b;
393
+ if (ze(I, (M) => {
394
+ const _ = [...M ?? [], Y].reduce((j, w) => {
395
+ const R = `${w.stateKey}:${JSON.stringify(w.path)}`, V = j.get(R);
396
+ return V ? (V.timeStamp = Math.max(V.timeStamp, w.timeStamp), V.newValue = w.newValue, V.oldValue = V.oldValue ?? w.oldValue, V.updateType = w.updateType) : j.set(R, { ...w }), j;
397
397
  }, /* @__PURE__ */ new Map());
398
- return Array.from(V.values());
399
- }), Ce(
398
+ return Array.from(_.values());
399
+ }), ke(
400
400
  E,
401
401
  I,
402
402
  P.current,
403
- R
403
+ L
404
404
  ), P.current?.middleware && P.current.middleware({
405
405
  updateLog: l,
406
- update: J
406
+ update: Y
407
407
  }), P.current?.serverSync) {
408
- const M = f.serverState[I], y = P.current?.serverSync;
409
- ze(I, {
410
- syncKey: typeof y.syncKey == "string" ? y.syncKey : y.syncKey({ state: E }),
408
+ const M = f.serverState[I], N = P.current?.serverSync;
409
+ Je(I, {
410
+ syncKey: typeof N.syncKey == "string" ? N.syncKey : N.syncKey({ state: E }),
411
411
  rollBackState: M,
412
- actionTimeStamp: Date.now() + (y.debounce ?? 3e3),
412
+ actionTimeStamp: Date.now() + (N.debounce ?? 3e3),
413
413
  status: "waiting"
414
414
  });
415
415
  }
416
416
  return E;
417
417
  });
418
418
  };
419
- r.getState().updaterState[I] || (fe(
419
+ r.getState().updaterState[I] || (Se(
420
420
  I,
421
- Se(
421
+ me(
422
422
  I,
423
423
  ae,
424
424
  ee.current,
425
- R
425
+ L
426
426
  )
427
- ), r.getState().cogsStateStore[I] || te(I, e), r.getState().initialStateGlobal[I] || Ee(I, e));
428
- const d = ve(() => Se(
427
+ ), r.getState().cogsStateStore[I] || ne(I, e), r.getState().initialStateGlobal[I] || _e(I, e));
428
+ const d = pe(() => me(
429
429
  I,
430
430
  ae,
431
431
  ee.current,
432
- R
433
- ), [I, R]);
434
- return [be(I), d];
432
+ L
433
+ ), [I, L]);
434
+ return [Me(I), d];
435
435
  }
436
- function Se(e, i, m, g) {
436
+ function me(e, i, m, g) {
437
437
  const T = /* @__PURE__ */ new Map();
438
- let N = 0;
438
+ let C = 0;
439
439
  const p = (h) => {
440
440
  const n = h.join(".");
441
441
  for (const [S] of T)
442
442
  (S === n || S.startsWith(n + ".")) && T.delete(S);
443
- N++;
443
+ C++;
444
444
  }, v = {
445
445
  removeValidation: (h) => {
446
- h?.validationKey && Z(h.validationKey);
446
+ h?.validationKey && X(h.validationKey);
447
447
  },
448
448
  revertToInitialState: (h) => {
449
449
  const n = r.getState().getInitialOptions(e)?.validation;
450
- n?.key && Z(n?.key), h?.validationKey && Z(h.validationKey);
450
+ n?.key && X(n?.key), h?.validationKey && X(h.validationKey);
451
451
  const S = r.getState().initialStateGlobal[e];
452
- r.getState().clearSelectedIndexesForState(e), T.clear(), N++;
453
- const H = a(S, []), L = re(e), R = Q(L?.localStorage?.key) ? L?.localStorage?.key(S) : L?.localStorage?.key, F = `${g}-${e}-${R}`;
454
- F && localStorage.removeItem(F), fe(e, H), te(e, S);
452
+ r.getState().clearSelectedIndexesForState(e), T.clear(), C++;
453
+ const H = a(S, []), G = re(e), L = K(G?.localStorage?.key) ? G?.localStorage?.key(S) : G?.localStorage?.key, F = `${g}-${e}-${L}`;
454
+ F && localStorage.removeItem(F), Se(e, H), ne(e, S);
455
455
  const I = r.getState().stateComponents.get(e);
456
456
  return I && I.components.forEach((l) => {
457
457
  l.forceUpdate();
458
458
  }), S;
459
459
  },
460
460
  updateInitialState: (h) => {
461
- T.clear(), N++;
462
- const n = Se(
461
+ T.clear(), C++;
462
+ const n = me(
463
463
  e,
464
464
  i,
465
465
  m,
466
466
  g
467
- ), S = r.getState().initialStateGlobal[e], H = re(e), L = Q(H?.localStorage?.key) ? H?.localStorage?.key(S) : H?.localStorage?.key, R = `${g}-${e}-${L}`;
468
- return localStorage.getItem(R) && localStorage.removeItem(R), Ve(() => {
469
- Ee(e, h), r.getState().initializeShadowState(e, h), fe(e, n), te(e, h);
467
+ ), S = r.getState().initialStateGlobal[e], H = re(e), G = K(H?.localStorage?.key) ? H?.localStorage?.key(S) : H?.localStorage?.key, L = `${g}-${e}-${G}`;
468
+ return localStorage.getItem(L) && localStorage.removeItem(L), Le(() => {
469
+ _e(e, h), r.getState().initializeShadowState(e, h), Se(e, n), ne(e, h);
470
470
  const F = r.getState().stateComponents.get(e);
471
471
  F && F.components.forEach((I) => {
472
472
  I.forceUpdate();
@@ -480,27 +480,27 @@ function Se(e, i, m, g) {
480
480
  _isLoading: r.getState().isLoadingGlobal[e],
481
481
  _isServerSynced: () => {
482
482
  const h = r.getState().serverState[e];
483
- return !!(h && z(h, be(e)));
483
+ return !!(h && q(h, Me(e)));
484
484
  }
485
485
  };
486
486
  function a(h, n = [], S) {
487
487
  const H = n.map(String).join(".");
488
488
  T.get(H);
489
- const L = function() {
489
+ const G = function() {
490
490
  return r().getNestedState(e, n);
491
491
  };
492
492
  Object.keys(v).forEach((I) => {
493
- L[I] = v[I];
493
+ G[I] = v[I];
494
494
  });
495
- const R = {
496
- apply(I, l, le) {
495
+ const L = {
496
+ apply(I, l, de) {
497
497
  return console.log(
498
498
  `PROXY APPLY TRAP HIT: stateKey=${e}, path=${n.join(".")}`
499
499
  ), console.trace("Apply trap stack trace"), r().getNestedState(e, n);
500
500
  },
501
501
  get(I, l) {
502
502
  S?.validIndices && !Array.isArray(h) && (S = { ...S, validIndices: void 0 });
503
- const le = /* @__PURE__ */ new Set([
503
+ const de = /* @__PURE__ */ new Set([
504
504
  "insert",
505
505
  "cut",
506
506
  "cutByValue",
@@ -523,7 +523,7 @@ function Se(e, i, m, g) {
523
523
  "_stateKey",
524
524
  "getComponents"
525
525
  ]);
526
- if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !le.has(l)) {
526
+ if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !de.has(l)) {
527
527
  const d = `${e}////${m}`, t = r.getState().stateComponents.get(e);
528
528
  if (t) {
529
529
  const o = t.components.get(d);
@@ -540,7 +540,7 @@ function Se(e, i, m, g) {
540
540
  }
541
541
  }
542
542
  if (l === "getDifferences")
543
- return () => ye(
543
+ return () => Ee(
544
544
  r.getState().cogsStateStore[e],
545
545
  r.getState().initialStateGlobal[e]
546
546
  );
@@ -568,20 +568,20 @@ function Se(e, i, m, g) {
568
568
  }
569
569
  };
570
570
  if (l === "_status") {
571
- const d = r.getState().getNestedState(e, n), t = r.getState().initialStateGlobal[e], o = q(t, n);
572
- return z(d, o) ? "fresh" : "stale";
571
+ const d = r.getState().getNestedState(e, n), t = r.getState().initialStateGlobal[e], o = J(t, n);
572
+ return q(d, o) ? "fresh" : "stale";
573
573
  }
574
574
  if (l === "getStatus")
575
575
  return function() {
576
576
  const d = r().getNestedState(
577
577
  e,
578
578
  n
579
- ), t = r.getState().initialStateGlobal[e], o = q(t, n);
580
- return z(d, o) ? "fresh" : "stale";
579
+ ), t = r.getState().initialStateGlobal[e], o = J(t, n);
580
+ return q(d, o) ? "fresh" : "stale";
581
581
  };
582
582
  if (l === "removeStorage")
583
583
  return () => {
584
- const d = r.getState().initialStateGlobal[e], t = re(e), o = Q(t?.localStorage?.key) ? t?.localStorage?.key(d) : t?.localStorage?.key, s = `${g}-${e}-${o}`;
584
+ const d = r.getState().initialStateGlobal[e], t = re(e), o = K(t?.localStorage?.key) ? t?.localStorage?.key(d) : t?.localStorage?.key, s = `${g}-${e}-${o}`;
585
585
  s && localStorage.removeItem(s);
586
586
  };
587
587
  if (l === "showValidationErrors")
@@ -622,157 +622,157 @@ function Se(e, i, m, g) {
622
622
  overscan: s = 6,
623
623
  stickToBottom: c = !1,
624
624
  dependencies: f = []
625
- } = t, u = K(null), [E, w] = X({
625
+ } = t, u = Z(!1), E = Z(null), [y, O] = Q({
626
626
  startIndex: 0,
627
627
  endIndex: 10
628
- }), [_, C] = X("IDLE_AT_TOP"), $ = K(0), x = K(f), [j, J] = X(0);
628
+ }), [k, A] = Q("IDLE_AT_TOP"), x = Z(0), U = Z(f), [Y, M] = Q(0);
629
629
  oe(() => r.getState().subscribeToShadowState(e, () => {
630
- J((k) => k + 1);
630
+ M((b) => b + 1);
631
631
  }), [e]);
632
- const M = r().getNestedState(
632
+ const N = r().getNestedState(
633
633
  e,
634
634
  n
635
- ), y = M.length, { totalHeight: V, positions: b } = ve(() => {
636
- const O = r.getState().getShadowMetadata(e, n) || [];
637
- let k = 0;
638
- const U = [];
639
- for (let W = 0; W < y; W++) {
640
- U[W] = k;
641
- const Y = O[W]?.virtualizer?.itemHeight;
642
- k += Y || o;
635
+ ), _ = N.length, { totalHeight: j, positions: w } = pe(() => {
636
+ const $ = r.getState().getShadowMetadata(e, n) || [];
637
+ let b = 0;
638
+ const z = [];
639
+ for (let B = 0; B < _; B++) {
640
+ z[B] = b;
641
+ const te = $[B]?.virtualizer?.itemHeight;
642
+ b += te || o;
643
643
  }
644
- return { totalHeight: k, positions: U };
644
+ return { totalHeight: b, positions: z };
645
645
  }, [
646
- y,
646
+ _,
647
647
  e,
648
648
  n.join("."),
649
649
  o,
650
- j
651
- ]), A = ve(() => {
652
- const O = Math.max(0, E.startIndex), k = Math.min(y, E.endIndex), U = Array.from(
653
- { length: k - O },
654
- (Y, ne) => O + ne
655
- ), W = U.map((Y) => M[Y]);
656
- return a(W, n, {
650
+ Y
651
+ ]), R = pe(() => {
652
+ const $ = Math.max(0, y.startIndex), b = Math.min(_, y.endIndex), z = Array.from(
653
+ { length: b - $ },
654
+ (te, se) => $ + se
655
+ ), B = z.map((te) => N[te]);
656
+ return a(B, n, {
657
657
  ...S,
658
- validIndices: U
658
+ validIndices: z
659
659
  });
660
- }, [E.startIndex, E.endIndex, M, y]);
661
- ie(() => {
662
- const O = !z(
660
+ }, [y.startIndex, y.endIndex, N, _]);
661
+ ce(() => {
662
+ const $ = !q(
663
663
  f,
664
- x.current
665
- ), k = y > $.current;
666
- if (O) {
667
- console.log("TRANSITION: Deps changed -> IDLE_AT_TOP"), C("IDLE_AT_TOP");
664
+ U.current
665
+ ), b = _ > x.current;
666
+ if ($) {
667
+ console.log("TRANSITION: Deps changed -> IDLE_AT_TOP"), A("IDLE_AT_TOP");
668
668
  return;
669
669
  }
670
- k && _ === "LOCKED_AT_BOTTOM" && c && (console.log(
670
+ b && k === "LOCKED_AT_BOTTOM" && c && (console.log(
671
671
  "TRANSITION: New items arrived while locked -> GETTING_HEIGHTS"
672
- ), C("GETTING_HEIGHTS")), $.current = y, x.current = f;
673
- }, [y, ...f]), ie(() => {
674
- const O = u.current;
675
- if (!O) return;
676
- let k;
677
- if (_ === "IDLE_AT_TOP" && c && y > 0)
672
+ ), A("GETTING_HEIGHTS")), x.current = _, U.current = f;
673
+ }, [_, ...f]), ce(() => {
674
+ const $ = E.current;
675
+ if (!$) return;
676
+ let b;
677
+ if (k === "IDLE_AT_TOP" && c && _ > 0)
678
678
  console.log(
679
679
  "ACTION (IDLE_AT_TOP): Data has arrived -> GETTING_HEIGHTS"
680
- ), C("GETTING_HEIGHTS");
681
- else if (_ === "GETTING_HEIGHTS")
680
+ ), A("GETTING_HEIGHTS");
681
+ else if (k === "GETTING_HEIGHTS")
682
682
  console.log(
683
683
  "ACTION (GETTING_HEIGHTS): Setting range to end and starting loop."
684
- ), w({
685
- startIndex: Math.max(0, y - 10 - s),
686
- endIndex: y
687
- }), k = setInterval(() => {
688
- const U = y - 1;
689
- ((r.getState().getShadowMetadata(e, n) || [])[U]?.virtualizer?.itemHeight || 0) > 0 && (clearInterval(k), console.log(
684
+ ), O({
685
+ startIndex: Math.max(0, _ - 10 - s),
686
+ endIndex: _
687
+ }), b = setInterval(() => {
688
+ const z = _ - 1;
689
+ ((r.getState().getShadowMetadata(e, n) || [])[z]?.virtualizer?.itemHeight || 0) > 0 && (clearInterval(b), u.current || (console.log(
690
690
  "ACTION (GETTING_HEIGHTS): Measurement success -> SCROLLING_TO_BOTTOM"
691
- ), C("SCROLLING_TO_BOTTOM"));
691
+ ), A("SCROLLING_TO_BOTTOM")));
692
692
  }, 100);
693
- else if (_ === "SCROLLING_TO_BOTTOM") {
693
+ else if (k === "SCROLLING_TO_BOTTOM") {
694
694
  console.log(
695
695
  "ACTION (SCROLLING_TO_BOTTOM): Executing scroll."
696
696
  );
697
- const U = $.current === 0 ? "auto" : "smooth";
698
- O.scrollTo({
699
- top: O.scrollHeight,
700
- behavior: U
697
+ const z = x.current === 0 ? "auto" : "smooth";
698
+ $.scrollTo({
699
+ top: $.scrollHeight,
700
+ behavior: z
701
701
  });
702
- const W = setTimeout(
702
+ const B = setTimeout(
703
703
  () => {
704
704
  console.log(
705
705
  "ACTION (SCROLLING_TO_BOTTOM): Scroll finished -> LOCKED_AT_BOTTOM"
706
- ), C("LOCKED_AT_BOTTOM");
706
+ ), u.current = !1, A("LOCKED_AT_BOTTOM");
707
707
  },
708
- U === "smooth" ? 500 : 50
708
+ z === "smooth" ? 500 : 50
709
709
  );
710
- return () => clearTimeout(W);
710
+ return () => clearTimeout(B);
711
711
  }
712
712
  return () => {
713
- k && clearInterval(k);
713
+ b && clearInterval(b);
714
714
  };
715
- }, [_, y, b]), oe(() => {
716
- const O = u.current;
717
- if (!O) return;
718
- const k = () => {
719
- _ !== "IDLE_NOT_AT_BOTTOM" && (O.scrollHeight - O.scrollTop - O.clientHeight < 1 || (console.log(
715
+ }, [k, _, w]), oe(() => {
716
+ const $ = E.current;
717
+ if (!$) return;
718
+ const b = () => {
719
+ $.scrollHeight - $.scrollTop - $.clientHeight < 1 ? u.current = !1 : (console.log(
720
720
  "USER ACTION: Scrolled up -> IDLE_NOT_AT_BOTTOM"
721
- ), C("IDLE_NOT_AT_BOTTOM")));
722
- const { scrollTop: U, clientHeight: W } = O;
723
- let Y = 0, ne = y - 1;
724
- for (; Y <= ne; ) {
725
- const ue = Math.floor((Y + ne) / 2);
726
- b[ue] < U ? Y = ue + 1 : ne = ue - 1;
721
+ ), A("IDLE_NOT_AT_BOTTOM"));
722
+ const { scrollTop: B, clientHeight: te } = $;
723
+ let se = 0, ue = _ - 1;
724
+ for (; se <= ue; ) {
725
+ const Te = Math.floor((se + ue) / 2);
726
+ w[Te] < B ? se = Te + 1 : ue = Te - 1;
727
727
  }
728
- const we = Math.max(0, ne - s);
729
- let de = we;
730
- const xe = U + W;
731
- for (; de < y && b[de] < xe; )
732
- de++;
733
- w({
734
- startIndex: we,
735
- endIndex: Math.min(y, de + s)
728
+ const Oe = Math.max(0, ue - s);
729
+ let ge = Oe;
730
+ const Ve = B + te;
731
+ for (; ge < _ && w[ge] < Ve; )
732
+ ge++;
733
+ O({
734
+ startIndex: Oe,
735
+ endIndex: Math.min(_, ge + s)
736
736
  });
737
737
  };
738
- return O.addEventListener("scroll", k, {
738
+ return $.addEventListener("scroll", b, {
739
739
  passive: !0
740
- }), () => O.removeEventListener("scroll", k);
741
- }, [y, b, _]);
742
- const D = _e(() => {
740
+ }), () => $.removeEventListener("scroll", b);
741
+ }, [_, w, k]);
742
+ const V = Ae(() => {
743
743
  console.log(
744
744
  "USER ACTION: Clicked scroll button -> SCROLLING_TO_BOTTOM"
745
- ), C("SCROLLING_TO_BOTTOM");
746
- }, []), G = _e(
747
- (O, k = "smooth") => {
748
- u.current && b[O] !== void 0 && (C("IDLE_NOT_AT_BOTTOM"), u.current.scrollTo({
749
- top: b[O],
750
- behavior: k
745
+ ), A("SCROLLING_TO_BOTTOM");
746
+ }, []), W = Ae(
747
+ ($, b = "smooth") => {
748
+ E.current && w[$] !== void 0 && (A("IDLE_NOT_AT_BOTTOM"), E.current.scrollTo({
749
+ top: w[$],
750
+ behavior: b
751
751
  }));
752
752
  },
753
- [b]
754
- ), B = {
753
+ [w]
754
+ ), D = {
755
755
  outer: {
756
- ref: u,
756
+ ref: E,
757
757
  style: { overflowY: "auto", height: "100%" }
758
758
  },
759
759
  inner: {
760
760
  style: {
761
- height: `${V}px`,
761
+ height: `${j}px`,
762
762
  position: "relative"
763
763
  }
764
764
  },
765
765
  list: {
766
766
  style: {
767
- transform: `translateY(${b[E.startIndex] || 0}px)`
767
+ transform: `translateY(${w[y.startIndex] || 0}px)`
768
768
  }
769
769
  }
770
770
  };
771
771
  return {
772
- virtualState: A,
773
- virtualizerProps: B,
774
- scrollToBottom: D,
775
- scrollToIndex: G
772
+ virtualState: R,
773
+ virtualizerProps: D,
774
+ scrollToBottom: V,
775
+ scrollToIndex: W
776
776
  };
777
777
  };
778
778
  if (l === "stateSort")
@@ -803,22 +803,22 @@ function Se(e, i, m, g) {
803
803
  return (t) => {
804
804
  const o = r.getState().getNestedState(e, n);
805
805
  return Array.isArray(o) ? (S?.validIndices || Array.from({ length: o.length }, (c, f) => f)).map((c, f) => {
806
- const u = o[c], E = [...n, c.toString()], w = a(u, E, S);
807
- return t(u, w, {
806
+ const u = o[c], E = [...n, c.toString()], y = a(u, E, S);
807
+ return t(u, y, {
808
808
  register: () => {
809
- const [, C] = X({}), $ = `${m}-${n.join(".")}-${c}`;
810
- ie(() => {
811
- const x = `${e}////${$}`, j = r.getState().stateComponents.get(e) || {
809
+ const [, k] = Q({}), A = `${m}-${n.join(".")}-${c}`;
810
+ ce(() => {
811
+ const x = `${e}////${A}`, U = r.getState().stateComponents.get(e) || {
812
812
  components: /* @__PURE__ */ new Map()
813
813
  };
814
- return j.components.set(x, {
815
- forceUpdate: () => C({}),
814
+ return U.components.set(x, {
815
+ forceUpdate: () => k({}),
816
816
  paths: /* @__PURE__ */ new Set([E.join(".")])
817
- }), r.getState().stateComponents.set(e, j), () => {
818
- const J = r.getState().stateComponents.get(e);
819
- J && J.components.delete(x);
817
+ }), r.getState().stateComponents.set(e, U), () => {
818
+ const Y = r.getState().stateComponents.get(e);
819
+ Y && Y.components.delete(x);
820
820
  };
821
- }, [e, $]);
821
+ }, [e, A]);
822
822
  },
823
823
  index: f,
824
824
  originalIndex: c
@@ -842,7 +842,7 @@ function Se(e, i, m, g) {
842
842
  );
843
843
  });
844
844
  if (l === "$stateMap")
845
- return (t) => ce(Ze, {
845
+ return (t) => le(Qe, {
846
846
  proxy: {
847
847
  _stateKey: e,
848
848
  _path: n,
@@ -855,15 +855,15 @@ function Se(e, i, m, g) {
855
855
  return (t) => {
856
856
  const o = r.getState().getNestedState(e, n);
857
857
  return Array.isArray(o) ? (S?.validIndices || Array.from({ length: o.length }, (c, f) => f)).map((c, f) => {
858
- const u = o[c], E = [...n, c.toString()], w = a(u, E, S), _ = `${m}-${n.join(".")}-${c}`;
859
- return ce(Qe, {
858
+ const u = o[c], E = [...n, c.toString()], y = a(u, E, S), O = `${m}-${n.join(".")}-${c}`;
859
+ return le(et, {
860
860
  key: c,
861
861
  stateKey: e,
862
- itemComponentId: _,
862
+ itemComponentId: O,
863
863
  itemPath: E,
864
864
  children: t(
865
865
  u,
866
- w,
866
+ y,
867
867
  f,
868
868
  o,
869
869
  a(o, n, S)
@@ -876,7 +876,7 @@ function Se(e, i, m, g) {
876
876
  if (l === "stateFlattenOn")
877
877
  return (t) => {
878
878
  const o = h;
879
- T.clear(), N++;
879
+ T.clear(), C++;
880
880
  const s = o.flatMap(
881
881
  (c) => c[t] ?? []
882
882
  );
@@ -899,36 +899,36 @@ function Se(e, i, m, g) {
899
899
  return a(s, c);
900
900
  };
901
901
  if (l === "insert")
902
- return (t) => (p(n), he(i, t, n, e), a(
902
+ return (t) => (p(n), ve(i, t, n, e), a(
903
903
  r.getState().getNestedState(e, n),
904
904
  n
905
905
  ));
906
906
  if (l === "uniqueInsert")
907
907
  return (t, o, s) => {
908
- const c = r.getState().getNestedState(e, n), f = Q(t) ? t(c) : t;
908
+ const c = r.getState().getNestedState(e, n), f = K(t) ? t(c) : t;
909
909
  let u = null;
910
- if (!c.some((w) => {
910
+ if (!c.some((y) => {
911
911
  if (o) {
912
- const C = o.every(
913
- ($) => z(w[$], f[$])
912
+ const k = o.every(
913
+ (A) => q(y[A], f[A])
914
914
  );
915
- return C && (u = w), C;
915
+ return k && (u = y), k;
916
916
  }
917
- const _ = z(w, f);
918
- return _ && (u = w), _;
917
+ const O = q(y, f);
918
+ return O && (u = y), O;
919
919
  }))
920
- p(n), he(i, f, n, e);
920
+ p(n), ve(i, f, n, e);
921
921
  else if (s && u) {
922
- const w = s(u), _ = c.map(
923
- (C) => z(C, u) ? w : C
922
+ const y = s(u), O = c.map(
923
+ (k) => q(k, u) ? y : k
924
924
  );
925
- p(n), se(i, _, n);
925
+ p(n), ie(i, O, n);
926
926
  }
927
927
  };
928
928
  if (l === "cut")
929
929
  return (t, o) => {
930
930
  if (!o?.waitForSync)
931
- return p(n), ge(i, n, e, t), a(
931
+ return p(n), fe(i, n, e, t), a(
932
932
  r.getState().getNestedState(e, n),
933
933
  n
934
934
  );
@@ -936,12 +936,12 @@ function Se(e, i, m, g) {
936
936
  if (l === "cutByValue")
937
937
  return (t) => {
938
938
  for (let o = 0; o < h.length; o++)
939
- h[o] === t && ge(i, n, e, o);
939
+ h[o] === t && fe(i, n, e, o);
940
940
  };
941
941
  if (l === "toggleByValue")
942
942
  return (t) => {
943
943
  const o = h.findIndex((s) => s === t);
944
- o > -1 ? ge(i, n, e, o) : he(i, t, n, e);
944
+ o > -1 ? fe(i, n, e, o) : ve(i, t, n, e);
945
945
  };
946
946
  if (l === "stateFind")
947
947
  return (t) => {
@@ -966,7 +966,7 @@ function Se(e, i, m, g) {
966
966
  if (!isNaN(Number(ee))) {
967
967
  const d = n.slice(0, -1), t = r.getState().getNestedState(e, d);
968
968
  if (Array.isArray(t) && l === "cut")
969
- return () => ge(
969
+ return () => fe(
970
970
  i,
971
971
  d,
972
972
  e,
@@ -982,13 +982,13 @@ function Se(e, i, m, g) {
982
982
  return r.getState().getNestedState(e, n);
983
983
  };
984
984
  if (l === "$derive")
985
- return (d) => $e({
985
+ return (d) => be({
986
986
  _stateKey: e,
987
987
  _path: n,
988
988
  _effect: d.toString()
989
989
  });
990
990
  if (l === "$get")
991
- return () => $e({
991
+ return () => be({
992
992
  _stateKey: e,
993
993
  _path: n
994
994
  });
@@ -997,7 +997,7 @@ function Se(e, i, m, g) {
997
997
  return r.getState().getSyncInfo(d);
998
998
  }
999
999
  if (l == "getLocalStorage")
1000
- return (d) => me(g + "-" + e + "-" + d);
1000
+ return (d) => Ie(g + "-" + e + "-" + d);
1001
1001
  if (l === "_selected") {
1002
1002
  const d = n.slice(0, -1), t = d.join("."), o = r.getState().getNestedState(e, d);
1003
1003
  return Array.isArray(o) ? Number(n[n.length - 1]) === r.getState().getSelectedIndex(e, t) : void 0;
@@ -1007,7 +1007,7 @@ function Se(e, i, m, g) {
1007
1007
  const t = n.slice(0, -1), o = Number(n[n.length - 1]), s = t.join(".");
1008
1008
  d ? r.getState().setSelectedIndex(e, s, o) : r.getState().setSelectedIndex(e, s, void 0);
1009
1009
  const c = r.getState().getNestedState(e, [...t]);
1010
- se(i, c, t), p(t);
1010
+ ie(i, c, t), p(t);
1011
1011
  };
1012
1012
  if (l === "toggleSelected")
1013
1013
  return () => {
@@ -1018,13 +1018,13 @@ function Se(e, i, m, g) {
1018
1018
  s === t ? void 0 : t
1019
1019
  );
1020
1020
  const c = r.getState().getNestedState(e, [...d]);
1021
- se(i, c, d), p(d);
1021
+ ie(i, c, d), p(d);
1022
1022
  };
1023
1023
  if (n.length == 0) {
1024
1024
  if (l === "applyJsonPatch")
1025
1025
  return (d) => {
1026
- const t = r.getState().cogsStateStore[e], s = je(t, d).newDocument;
1027
- Me(
1026
+ const t = r.getState().cogsStateStore[e], s = Fe(t, d).newDocument;
1027
+ Pe(
1028
1028
  e,
1029
1029
  r.getState().initialStateGlobal[e],
1030
1030
  s,
@@ -1034,57 +1034,57 @@ function Se(e, i, m, g) {
1034
1034
  );
1035
1035
  const c = r.getState().stateComponents.get(e);
1036
1036
  if (c) {
1037
- const f = ye(t, s), u = new Set(f);
1037
+ const f = Ee(t, s), u = new Set(f);
1038
1038
  for (const [
1039
1039
  E,
1040
- w
1040
+ y
1041
1041
  ] of c.components.entries()) {
1042
- let _ = !1;
1043
- const C = Array.isArray(w.reactiveType) ? w.reactiveType : [w.reactiveType || "component"];
1044
- if (!C.includes("none")) {
1045
- if (C.includes("all")) {
1046
- w.forceUpdate();
1042
+ let O = !1;
1043
+ const k = Array.isArray(y.reactiveType) ? y.reactiveType : [y.reactiveType || "component"];
1044
+ if (!k.includes("none")) {
1045
+ if (k.includes("all")) {
1046
+ y.forceUpdate();
1047
1047
  continue;
1048
1048
  }
1049
- if (C.includes("component") && (w.paths.has("") && (_ = !0), !_))
1050
- for (const $ of u) {
1051
- if (w.paths.has($)) {
1052
- _ = !0;
1049
+ if (k.includes("component") && (y.paths.has("") && (O = !0), !O))
1050
+ for (const A of u) {
1051
+ if (y.paths.has(A)) {
1052
+ O = !0;
1053
1053
  break;
1054
1054
  }
1055
- let x = $.lastIndexOf(".");
1055
+ let x = A.lastIndexOf(".");
1056
1056
  for (; x !== -1; ) {
1057
- const j = $.substring(0, x);
1058
- if (w.paths.has(j)) {
1059
- _ = !0;
1057
+ const U = A.substring(0, x);
1058
+ if (y.paths.has(U)) {
1059
+ O = !0;
1060
1060
  break;
1061
1061
  }
1062
- const J = $.substring(
1062
+ const Y = A.substring(
1063
1063
  x + 1
1064
1064
  );
1065
- if (!isNaN(Number(J))) {
1066
- const M = j.lastIndexOf(".");
1065
+ if (!isNaN(Number(Y))) {
1066
+ const M = U.lastIndexOf(".");
1067
1067
  if (M !== -1) {
1068
- const y = j.substring(
1068
+ const N = U.substring(
1069
1069
  0,
1070
1070
  M
1071
1071
  );
1072
- if (w.paths.has(y)) {
1073
- _ = !0;
1072
+ if (y.paths.has(N)) {
1073
+ O = !0;
1074
1074
  break;
1075
1075
  }
1076
1076
  }
1077
1077
  }
1078
- x = j.lastIndexOf(".");
1078
+ x = U.lastIndexOf(".");
1079
1079
  }
1080
- if (_) break;
1080
+ if (O) break;
1081
1081
  }
1082
- if (!_ && C.includes("deps") && w.depsFunction) {
1083
- const $ = w.depsFunction(s);
1082
+ if (!O && k.includes("deps") && y.depsFunction) {
1083
+ const A = y.depsFunction(s);
1084
1084
  let x = !1;
1085
- typeof $ == "boolean" ? $ && (x = !0) : z(w.deps, $) || (w.deps = $, x = !0), x && (_ = !0);
1085
+ typeof A == "boolean" ? A && (x = !0) : q(y.deps, A) || (y.deps = A, x = !0), x && (O = !0);
1086
1086
  }
1087
- _ && w.forceUpdate();
1087
+ O && y.forceUpdate();
1088
1088
  }
1089
1089
  }
1090
1090
  }
@@ -1096,18 +1096,18 @@ function Se(e, i, m, g) {
1096
1096
  throw new Error("Zod schema not found");
1097
1097
  if (!d?.key)
1098
1098
  throw new Error("Validation key not found");
1099
- Z(d.key);
1099
+ X(d.key);
1100
1100
  const o = r.getState().cogsStateStore[e];
1101
1101
  try {
1102
1102
  const s = r.getState().getValidationErrors(d.key);
1103
1103
  s && s.length > 0 && s.forEach(([f]) => {
1104
- f && f.startsWith(d.key) && Z(f);
1104
+ f && f.startsWith(d.key) && X(f);
1105
1105
  });
1106
1106
  const c = d.zodSchema.safeParse(o);
1107
1107
  return c.success ? !0 : (c.error.errors.forEach((u) => {
1108
- const E = u.path, w = u.message, _ = [d.key, ...E].join(".");
1109
- t(_, w);
1110
- }), Ie(e), !1);
1108
+ const E = u.path, y = u.message, O = [d.key, ...E].join(".");
1109
+ t(O, y);
1110
+ }), he(e), !1);
1111
1111
  } catch (s) {
1112
1112
  return console.error("Zod schema validation failed", s), !1;
1113
1113
  }
@@ -1116,7 +1116,7 @@ function Se(e, i, m, g) {
1116
1116
  if (l === "getComponents")
1117
1117
  return () => r().stateComponents.get(e);
1118
1118
  if (l === "getAllFormRefs")
1119
- return () => Oe.getState().getFormRefsByStateKey(e);
1119
+ return () => Ne.getState().getFormRefsByStateKey(e);
1120
1120
  if (l === "_initialState")
1121
1121
  return r.getState().initialStateGlobal[e];
1122
1122
  if (l === "_serverState")
@@ -1129,13 +1129,13 @@ function Se(e, i, m, g) {
1129
1129
  if (l === "removeValidation") return v.removeValidation;
1130
1130
  }
1131
1131
  if (l === "getFormRef")
1132
- return () => Oe.getState().getFormRef(e + "." + n.join("."));
1132
+ return () => Ne.getState().getFormRef(e + "." + n.join("."));
1133
1133
  if (l === "validationWrapper")
1134
1134
  return ({
1135
1135
  children: d,
1136
1136
  hideMessage: t
1137
- }) => /* @__PURE__ */ Te(
1138
- Re,
1137
+ }) => /* @__PURE__ */ ye(
1138
+ Ue,
1139
1139
  {
1140
1140
  formOpts: t ? { validation: { message: "" } } : void 0,
1141
1141
  path: n,
@@ -1151,21 +1151,21 @@ function Se(e, i, m, g) {
1151
1151
  if (l === "update")
1152
1152
  return (d, t) => {
1153
1153
  if (t?.debounce)
1154
- Le(() => {
1155
- se(i, d, n, "");
1154
+ De(() => {
1155
+ ie(i, d, n, "");
1156
1156
  const o = r.getState().getNestedState(e, n);
1157
1157
  t?.afterUpdate && t.afterUpdate(o);
1158
1158
  }, t.debounce);
1159
1159
  else {
1160
- se(i, d, n, "");
1160
+ ie(i, d, n, "");
1161
1161
  const o = r.getState().getNestedState(e, n);
1162
1162
  t?.afterUpdate && t.afterUpdate(o);
1163
1163
  }
1164
1164
  p(n);
1165
1165
  };
1166
1166
  if (l === "formElement")
1167
- return (d, t) => /* @__PURE__ */ Te(
1168
- De,
1167
+ return (d, t) => /* @__PURE__ */ ye(
1168
+ je,
1169
1169
  {
1170
1170
  setState: i,
1171
1171
  stateKey: e,
@@ -1177,20 +1177,20 @@ function Se(e, i, m, g) {
1177
1177
  const P = [...n, l], ae = r.getState().getNestedState(e, P);
1178
1178
  return a(ae, P, S);
1179
1179
  }
1180
- }, F = new Proxy(L, R);
1180
+ }, F = new Proxy(G, L);
1181
1181
  return T.set(H, {
1182
1182
  proxy: F,
1183
- stateVersion: N
1183
+ stateVersion: C
1184
1184
  }), F;
1185
1185
  }
1186
1186
  return a(
1187
1187
  r.getState().getNestedState(e, [])
1188
1188
  );
1189
1189
  }
1190
- function $e(e) {
1191
- return ce(Xe, { proxy: e });
1190
+ function be(e) {
1191
+ return le(Ke, { proxy: e });
1192
1192
  }
1193
- function Ze({
1193
+ function Qe({
1194
1194
  proxy: e,
1195
1195
  rebuildStateShape: i
1196
1196
  }) {
@@ -1199,13 +1199,13 @@ function Ze({
1199
1199
  m,
1200
1200
  e._path
1201
1201
  ).stateMapNoRender(
1202
- (T, N, p, v, a) => e._mapFn(T, N, p, v, a)
1202
+ (T, C, p, v, a) => e._mapFn(T, C, p, v, a)
1203
1203
  ) : null;
1204
1204
  }
1205
- function Xe({
1205
+ function Ke({
1206
1206
  proxy: e
1207
1207
  }) {
1208
- const i = K(null), m = `${e._stateKey}-${e._path.join(".")}`;
1208
+ const i = Z(null), m = `${e._stateKey}-${e._path.join(".")}`;
1209
1209
  return oe(() => {
1210
1210
  const g = i.current;
1211
1211
  if (!g || !g.parentElement) return;
@@ -1227,22 +1227,22 @@ function Xe({
1227
1227
  "state",
1228
1228
  `return (${e._effect})(state)`
1229
1229
  )(n);
1230
- } catch (L) {
1231
- console.error("Error evaluating effect function during mount:", L), S = n;
1230
+ } catch (G) {
1231
+ console.error("Error evaluating effect function during mount:", G), S = n;
1232
1232
  }
1233
1233
  else
1234
1234
  S = n;
1235
1235
  S !== null && typeof S == "object" && (S = JSON.stringify(S));
1236
1236
  const H = document.createTextNode(String(S));
1237
1237
  g.replaceWith(H);
1238
- }, [e._stateKey, e._path.join("."), e._effect]), ce("span", {
1238
+ }, [e._stateKey, e._path.join("."), e._effect]), le("span", {
1239
1239
  ref: i,
1240
1240
  style: { display: "none" },
1241
1241
  "data-signal-id": m
1242
1242
  });
1243
1243
  }
1244
- function ft(e) {
1245
- const i = Pe(
1244
+ function mt(e) {
1245
+ const i = Ge(
1246
1246
  (m) => {
1247
1247
  const g = r.getState().stateComponents.get(e._stateKey) || {
1248
1248
  components: /* @__PURE__ */ new Map()
@@ -1254,22 +1254,22 @@ function ft(e) {
1254
1254
  },
1255
1255
  () => r.getState().getNestedState(e._stateKey, e._path)
1256
1256
  );
1257
- return ce("text", {}, String(i));
1257
+ return le("text", {}, String(i));
1258
1258
  }
1259
- function Qe({
1259
+ function et({
1260
1260
  stateKey: e,
1261
1261
  itemComponentId: i,
1262
1262
  itemPath: m,
1263
1263
  children: g
1264
1264
  }) {
1265
- const [, T] = X({}), [N, p] = He(), v = K(null);
1265
+ const [, T] = Q({}), [C, p] = Be(), v = Z(null);
1266
1266
  return oe(() => {
1267
1267
  p.height > 0 && p.height !== v.current && (v.current = p.height, r.getState().setShadowMetadata(e, m, {
1268
1268
  virtualizer: {
1269
1269
  itemHeight: p.height
1270
1270
  }
1271
1271
  }));
1272
- }, [p.height, e, m]), ie(() => {
1272
+ }, [p.height, e, m]), ce(() => {
1273
1273
  const a = `${e}////${i}`, h = r.getState().stateComponents.get(e) || {
1274
1274
  components: /* @__PURE__ */ new Map()
1275
1275
  };
@@ -1280,14 +1280,14 @@ function Qe({
1280
1280
  const n = r.getState().stateComponents.get(e);
1281
1281
  n && n.components.delete(a);
1282
1282
  };
1283
- }, [e, i, m.join(".")]), /* @__PURE__ */ Te("div", { ref: N, children: g });
1283
+ }, [e, i, m.join(".")]), /* @__PURE__ */ ye("div", { ref: C, children: g });
1284
1284
  }
1285
1285
  export {
1286
- $e as $cogsSignal,
1287
- ft as $cogsSignalStore,
1288
- dt as addStateOptions,
1289
- ut as createCogsState,
1290
- gt as notifyComponent,
1291
- Ye as useCogsStateFn
1286
+ be as $cogsSignal,
1287
+ mt as $cogsSignalStore,
1288
+ gt as addStateOptions,
1289
+ ft as createCogsState,
1290
+ St as notifyComponent,
1291
+ Xe as useCogsStateFn
1292
1292
  };
1293
1293
  //# sourceMappingURL=CogsState.jsx.map