cogsbox-state 0.5.373 → 0.5.374

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