cogsbox-state 0.5.374 → 0.5.376

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,61 +1,61 @@
1
1
  "use client";
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";
2
+ import { jsx as Et } from "react/jsx-runtime";
3
+ import { useState as Q, useRef as J, useEffect as ot, useLayoutEffect as lt, useMemo as _t, createElement as dt, useSyncExternalStore as Rt, startTransition as Dt, useCallback as Ct } from "react";
4
+ import { transformStateFunc as Ut, isDeepEqual as q, isFunction as K, getNestedValue as Z, getDifferences as wt, debounce as jt } from "./utility.js";
5
+ import { pushFunc as pt, updateFn as ct, cutFunc as mt, ValidationWrapper as Ht, FormControlComponent as Ft } from "./Functions.jsx";
6
+ import Bt from "superjson";
7
+ import { v4 as Ot } from "uuid";
8
8
  import "zod";
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
- const m = r.getState().getInitialOptions, g = r.getState().setInitialStateOptions, T = m(e) || {};
15
- g(e, {
9
+ import { getGlobalStore as r, formRefStore as $t } from "./store.js";
10
+ import { useCogsConfig as Pt } from "./CogsStateClient.jsx";
11
+ import { applyPatch as Wt } from "fast-json-patch";
12
+ import zt from "react-use-measure";
13
+ function kt(t, i) {
14
+ const m = r.getState().getInitialOptions, g = r.getState().setInitialStateOptions, T = m(t) || {};
15
+ g(t, {
16
16
  ...T,
17
17
  ...i
18
18
  });
19
19
  }
20
- function ke({
21
- stateKey: e,
20
+ function xt({
21
+ stateKey: t,
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 };
26
- let v = !1;
25
+ const g = rt(t) || {}, T = m[t] || {}, N = r.getState().setInitialStateOptions, p = { ...T, ...g };
26
+ let y = !1;
27
27
  if (i)
28
28
  for (const a in i)
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
- !q(p[a], i[a]) && (v = !0, p[a] = i[a])) : (v = !0, p[a] = i[a]);
31
- v && N(e, p);
29
+ p.hasOwnProperty(a) ? (a == "localStorage" && i[a] && p[a].key !== i[a]?.key && (y = !0, p[a] = i[a]), a == "initialState" && i[a] && p[a] !== i[a] && // Different references
30
+ !q(p[a], i[a]) && (y = !0, p[a] = i[a])) : (y = !0, p[a] = i[a]);
31
+ y && N(t, p);
32
32
  }
33
- function ft(e, { formElements: i, validation: m }) {
34
- return { initialState: e, formElements: i, validation: m };
33
+ function Se(t, { formElements: i, validation: m }) {
34
+ return { initialState: t, formElements: i, validation: m };
35
35
  }
36
- const St = (e, i) => {
37
- let m = e;
38
- const [g, T] = De(m);
39
- (Object.keys(T).length > 0 || i && Object.keys(i).length > 0) && Object.keys(T).forEach((v) => {
40
- T[v] = T[v] || {}, T[v].formElements = {
36
+ const me = (t, i) => {
37
+ let m = t;
38
+ const [g, T] = Ut(m);
39
+ (Object.keys(T).length > 0 || i && Object.keys(i).length > 0) && Object.keys(T).forEach((y) => {
40
+ T[y] = T[y] || {}, T[y].formElements = {
41
41
  ...i?.formElements,
42
42
  // Global defaults first
43
43
  ...i?.validation,
44
- ...T[v].formElements || {}
44
+ ...T[y].formElements || {}
45
45
  // State-specific overrides
46
- }, re(v) || r.getState().setInitialStateOptions(v, T[v]);
46
+ }, rt(y) || r.getState().setInitialStateOptions(y, T[y]);
47
47
  }), r.getState().setInitialStates(g), r.getState().setCreatedState(g);
48
- const N = (v, a) => {
49
- const [h] = Q(a?.componentId ?? _e());
50
- ke({
51
- stateKey: v,
48
+ const N = (y, a) => {
49
+ const [h] = Q(a?.componentId ?? Ot());
50
+ xt({
51
+ stateKey: y,
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, R] = Qe(
55
+ const n = r.getState().cogsStateStore[y] || g[y], S = a?.modifyState ? a.modifyState(n) : n, [F, R] = Kt(
56
56
  S,
57
57
  {
58
- stateKey: v,
58
+ stateKey: y,
59
59
  syncUpdate: a?.syncUpdate,
60
60
  componentId: h,
61
61
  localStorage: a?.localStorage,
@@ -70,78 +70,78 @@ const St = (e, i) => {
70
70
  );
71
71
  return R;
72
72
  };
73
- function p(v, a) {
74
- ke({ stateKey: v, options: a, initialOptionsPart: T }), a.localStorage && Ze(v, a), Te(v);
73
+ function p(y, a) {
74
+ xt({ stateKey: y, options: a, initialOptionsPart: T }), a.localStorage && Xt(y, a), vt(y);
75
75
  }
76
76
  return { useCogsState: N, setCogsOptions: p };
77
77
  }, {
78
- setUpdaterState: me,
79
- setState: ne,
80
- getInitialOptions: re,
81
- getKeyState: Pe,
82
- getValidationErrors: ze,
83
- setStateLog: qe,
84
- updateInitialStateGlobal: Oe,
85
- addValidationError: Je,
78
+ setUpdaterState: It,
79
+ setState: et,
80
+ getInitialOptions: rt,
81
+ getKeyState: Vt,
82
+ getValidationErrors: qt,
83
+ setStateLog: Jt,
84
+ updateInitialStateGlobal: At,
85
+ addValidationError: Yt,
86
86
  removeValidationError: X,
87
- setServerSyncActions: Ye
88
- } = r.getState(), be = (e, i, m, g, T) => {
87
+ setServerSyncActions: Zt
88
+ } = r.getState(), bt = (t, 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 = K(m?.localStorage?.key) ? m.localStorage?.key(e) : m?.localStorage?.key;
95
+ const N = K(m?.localStorage?.key) ? m.localStorage?.key(t) : m?.localStorage?.key;
96
96
  if (N && g) {
97
97
  const p = `${g}-${i}-${N}`;
98
- let v;
98
+ let y;
99
99
  try {
100
- v = he(p)?.lastSyncedWithServer;
100
+ y = Tt(p)?.lastSyncedWithServer;
101
101
  } catch {
102
102
  }
103
103
  const a = {
104
- state: e,
104
+ state: t,
105
105
  lastUpdated: Date.now(),
106
- lastSyncedWithServer: T ?? v
107
- }, h = Fe.serialize(a);
106
+ lastSyncedWithServer: T ?? y
107
+ }, h = Bt.serialize(a);
108
108
  window.localStorage.setItem(
109
109
  p,
110
110
  JSON.stringify(h.json)
111
111
  );
112
112
  }
113
- }, he = (e) => {
114
- if (!e) return null;
113
+ }, Tt = (t) => {
114
+ if (!t) return null;
115
115
  try {
116
- const i = window.localStorage.getItem(e);
116
+ const i = window.localStorage.getItem(t);
117
117
  return i ? JSON.parse(i) : null;
118
118
  } catch (i) {
119
119
  return console.error("Error loading from localStorage:", i), null;
120
120
  }
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;
121
+ }, Xt = (t, i) => {
122
+ const m = r.getState().cogsStateStore[t], { sessionId: g } = Pt(), T = K(i?.localStorage?.key) ? i.localStorage.key(m) : i?.localStorage?.key;
123
123
  if (T && g) {
124
- const N = he(
125
- `${g}-${e}-${T}`
124
+ const N = Tt(
125
+ `${g}-${t}-${T}`
126
126
  );
127
127
  if (N && N.lastUpdated > (N.lastSyncedWithServer || 0))
128
- return ne(e, N.state), Te(e), !0;
128
+ return et(t, N.state), vt(t), !0;
129
129
  }
130
130
  return !1;
131
- }, Ve = (e, i, m, g, T, N) => {
131
+ }, Gt = (t, i, m, g, T, N) => {
132
132
  const p = {
133
133
  initialState: i,
134
- updaterState: Ie(
135
- e,
134
+ updaterState: ht(
135
+ t,
136
136
  g,
137
137
  T,
138
138
  N
139
139
  ),
140
140
  state: m
141
141
  };
142
- Oe(e, p.initialState), me(e, p.updaterState), ne(e, p.state);
143
- }, Te = (e) => {
144
- const i = r.getState().stateComponents.get(e);
142
+ At(t, p.initialState), It(t, p.updaterState), et(t, p.state);
143
+ }, vt = (t) => {
144
+ const i = r.getState().stateComponents.get(t);
145
145
  if (!i) return;
146
146
  const m = /* @__PURE__ */ new Set();
147
147
  i.components.forEach((g) => {
@@ -149,16 +149,16 @@ const St = (e, i) => {
149
149
  }), queueMicrotask(() => {
150
150
  m.forEach((g) => g());
151
151
  });
152
- }, mt = (e, i) => {
153
- const m = r.getState().stateComponents.get(e);
152
+ }, Ie = (t, i) => {
153
+ const m = r.getState().stateComponents.get(t);
154
154
  if (m) {
155
- const g = `${e}////${i}`, T = m.components.get(g);
155
+ const g = `${t}////${i}`, T = m.components.get(g);
156
156
  if ((T ? Array.isArray(T.reactiveType) ? T.reactiveType : [T.reactiveType || "component"] : null)?.includes("none"))
157
157
  return;
158
158
  T && T.forceUpdate();
159
159
  }
160
- }, Xe = (e, i, m, g) => {
161
- switch (e) {
160
+ }, Qt = (t, i, m, g) => {
161
+ switch (t) {
162
162
  case "update":
163
163
  return {
164
164
  oldValue: Z(i, g),
@@ -180,113 +180,113 @@ const St = (e, i) => {
180
180
  return { oldValue: null, newValue: null };
181
181
  }
182
182
  };
183
- function Qe(e, {
183
+ function Kt(t, {
184
184
  stateKey: i,
185
185
  serverSync: m,
186
186
  localStorage: g,
187
187
  formElements: T,
188
188
  reactiveDeps: N,
189
189
  reactiveType: p,
190
- componentId: v,
190
+ componentId: y,
191
191
  initialState: a,
192
192
  syncUpdate: h,
193
193
  dependencies: n,
194
194
  serverState: S
195
195
  } = {}) {
196
- const [H, R] = Q({}), { sessionId: D } = Me();
197
- let F = !i;
198
- const [I] = Q(i ?? _e()), l = r.getState().stateLog[I], ue = Y(/* @__PURE__ */ new Set()), ee = Y(v ?? _e()), G = Y(
196
+ const [F, R] = Q({}), { sessionId: D } = Pt();
197
+ let B = !i;
198
+ const [I] = Q(i ?? Ot()), l = r.getState().stateLog[I], ut = J(/* @__PURE__ */ new Set()), tt = J(y ?? Ot()), G = J(
199
199
  null
200
200
  );
201
- G.current = re(I) ?? null, oe(() => {
201
+ G.current = rt(I) ?? null, ot(() => {
202
202
  if (h && h.stateKey === I && h.path?.[0]) {
203
- ne(I, (o) => ({
203
+ et(I, (o) => ({
204
204
  ...o,
205
205
  [h.path[0]]: h.newValue
206
206
  }));
207
- const t = `${h.stateKey}:${h.path.join(".")}`;
208
- r.getState().setSyncInfo(t, {
207
+ const e = `${h.stateKey}:${h.path.join(".")}`;
208
+ r.getState().setSyncInfo(e, {
209
209
  timeStamp: h.timeStamp,
210
210
  userId: h.userId
211
211
  });
212
212
  }
213
- }, [h]), oe(() => {
213
+ }, [h]), ot(() => {
214
214
  if (a) {
215
- $e(I, {
215
+ kt(I, {
216
216
  initialState: a
217
217
  });
218
- const t = G.current, s = t?.serverState?.id !== void 0 && t?.serverState?.status === "success" && t?.serverState?.data, c = r.getState().initialStateGlobal[I];
218
+ const e = G.current, s = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.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
- const E = K(t?.localStorage?.key) ? t?.localStorage?.key(a) : t?.localStorage?.key;
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(
222
+ const E = K(e?.localStorage?.key) ? e?.localStorage?.key(a) : e?.localStorage?.key;
223
+ E && D && (u = Tt(`${D}-${I}-${E}`));
224
+ let v = a, _ = !1;
225
+ const C = s ? Date.now() : 0, O = u?.lastUpdated || 0, b = u?.lastSyncedWithServer || 0;
226
+ s && C > O ? (v = e.serverState.data, _ = !0) : u && O > b && (v = u.state, e?.localStorage?.onChange && e?.localStorage?.onChange(v)), r.getState().initializeShadowState(I, a), Gt(
227
227
  I,
228
228
  a,
229
- y,
230
- ae,
231
- ee.current,
229
+ v,
230
+ at,
231
+ tt.current,
232
232
  D
233
- ), w && E && D && be(y, I, t, D, Date.now()), Te(I), (Array.isArray(p) ? p : [p || "component"]).includes("none") || R({});
233
+ ), _ && E && D && bt(v, I, e, D, Date.now()), vt(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
- ]), le(() => {
241
- F && $e(I, {
240
+ ]), lt(() => {
241
+ B && kt(I, {
242
242
  serverSync: m,
243
243
  formElements: T,
244
244
  initialState: a,
245
245
  localStorage: g,
246
246
  middleware: G.current?.middleware
247
247
  });
248
- const t = `${I}////${ee.current}`, o = r.getState().stateComponents.get(I) || {
248
+ const e = `${I}////${tt.current}`, o = r.getState().stateComponents.get(I) || {
249
249
  components: /* @__PURE__ */ new Map()
250
250
  };
251
- return o.components.set(t, {
251
+ return o.components.set(e, {
252
252
  forceUpdate: () => R({}),
253
253
  paths: /* @__PURE__ */ new Set(),
254
254
  deps: [],
255
255
  depsFunction: N || void 0,
256
256
  reactiveType: p ?? ["component", "deps"]
257
257
  }), r.getState().stateComponents.set(I, o), R({}), () => {
258
- o && (o.components.delete(t), o.components.size === 0 && r.getState().stateComponents.delete(I));
258
+ o && (o.components.delete(e), o.components.size === 0 && r.getState().stateComponents.delete(I));
259
259
  };
260
260
  }, []);
261
- const ae = (t, o, s, c) => {
261
+ const at = (e, o, s, c) => {
262
262
  if (Array.isArray(o)) {
263
263
  const u = `${I}-${o.join(".")}`;
264
- ue.current.add(u);
264
+ ut.current.add(u);
265
265
  }
266
266
  const f = r.getState();
267
- ne(I, (u) => {
268
- const E = K(t) ? t(u) : t, y = `${I}-${o.join(".")}`;
269
- if (y) {
270
- let V = !1, C = f.signalDomElements.get(y);
271
- if ((!C || C.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
267
+ et(I, (u) => {
268
+ const E = K(e) ? e(u) : e, v = `${I}-${o.join(".")}`;
269
+ if (v) {
270
+ let V = !1, $ = f.signalDomElements.get(v);
271
+ if ((!$ || $.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
272
272
  const M = o.slice(0, -1), A = Z(E, M);
273
273
  if (Array.isArray(A)) {
274
274
  V = !0;
275
- const _ = `${I}-${M.join(".")}`;
276
- C = f.signalDomElements.get(_);
275
+ const w = `${I}-${M.join(".")}`;
276
+ $ = f.signalDomElements.get(w);
277
277
  }
278
278
  }
279
- if (C) {
279
+ if ($) {
280
280
  const M = V ? Z(E, o.slice(0, -1)) : Z(E, o);
281
- C.forEach(({ parentId: A, position: _, effect: b }) => {
281
+ $.forEach(({ parentId: A, position: w, effect: x }) => {
282
282
  const L = document.querySelector(
283
283
  `[data-parent-id="${A}"]`
284
284
  );
285
285
  if (L) {
286
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);
287
+ if (W[w]) {
288
+ const j = x ? new Function("state", `return (${x})(state)`)(M) : M;
289
+ W[w].textContent = String(j);
290
290
  }
291
291
  }
292
292
  });
@@ -295,50 +295,50 @@ function Qe(e, {
295
295
  console.log("shadowState", f.shadowStateStore), s.updateType === "update" && (c || G.current?.validation?.key) && o && X(
296
296
  (c || G.current?.validation?.key) + "." + o.join(".")
297
297
  );
298
- const w = o.slice(0, o.length - 1);
298
+ const _ = o.slice(0, o.length - 1);
299
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);
300
+ G.current?.validation?.key + "." + _.join(".")
301
+ ), s.updateType === "insert" && G.current?.validation?.key && qt(
302
+ G.current?.validation?.key + "." + _.join(".")
303
+ ).filter(([$, M]) => {
304
+ let A = $?.split(".").length;
305
+ if ($ == _.join(".") && A == _.length - 1) {
306
+ let w = $ + "." + _;
307
+ X($), Yt(w, M);
308
308
  }
309
309
  });
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(".") || "";
310
+ const C = f.stateComponents.get(I);
311
+ if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", C), C) {
312
+ const V = wt(u, E), $ = new Set(V), M = s.updateType === "update" ? o.join(".") : o.slice(0, -1).join(".") || "";
313
313
  for (const [
314
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")) {
315
+ w
316
+ ] of C.components.entries()) {
317
+ let x = !1;
318
+ const L = Array.isArray(w.reactiveType) ? w.reactiveType : [w.reactiveType || "component"];
319
+ if (console.log("component", w), !L.includes("none")) {
320
320
  if (L.includes("all")) {
321
- _.forceUpdate();
321
+ w.forceUpdate();
322
322
  continue;
323
323
  }
324
- if (L.includes("component") && ((_.paths.has(M) || _.paths.has("")) && (b = !0), !b))
325
- for (const W of C) {
324
+ if (L.includes("component") && ((w.paths.has(M) || w.paths.has("")) && (x = !0), !x))
325
+ for (const W of $) {
326
326
  let j = W;
327
327
  for (; ; ) {
328
- if (_.paths.has(j)) {
329
- b = !0;
328
+ if (w.paths.has(j)) {
329
+ x = !0;
330
330
  break;
331
331
  }
332
- const se = j.lastIndexOf(".");
333
- if (se !== -1) {
332
+ const st = j.lastIndexOf(".");
333
+ if (st !== -1) {
334
334
  const k = j.substring(
335
335
  0,
336
- se
336
+ st
337
337
  );
338
338
  if (!isNaN(
339
- Number(j.substring(se + 1))
340
- ) && _.paths.has(k)) {
341
- b = !0;
339
+ Number(j.substring(st + 1))
340
+ ) && w.paths.has(k)) {
341
+ x = !0;
342
342
  break;
343
343
  }
344
344
  j = k;
@@ -347,34 +347,34 @@ function Qe(e, {
347
347
  if (j === "")
348
348
  break;
349
349
  }
350
- if (b) break;
350
+ if (x) break;
351
351
  }
352
- if (!b && L.includes("deps") && _.depsFunction) {
353
- const W = _.depsFunction(E);
352
+ if (!x && L.includes("deps") && w.depsFunction) {
353
+ const W = w.depsFunction(E);
354
354
  let j = !1;
355
- typeof W == "boolean" ? W && (j = !0) : q(_.deps, W) || (_.deps = W, j = !0), j && (b = !0);
355
+ typeof W == "boolean" ? W && (j = !0) : q(w.deps, W) || (w.deps = W, j = !0), j && (x = !0);
356
356
  }
357
- b && _.forceUpdate();
357
+ x && w.forceUpdate();
358
358
  }
359
359
  }
360
360
  }
361
361
  const O = Date.now();
362
- o = o.map((V, C) => {
362
+ o = o.map((V, $) => {
363
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;
364
+ return $ === o.length - 1 && ["insert", "cut"].includes(s.updateType) ? (A.length - 1).toString() : V;
365
365
  });
366
- const { oldValue: x, newValue: U } = Xe(
366
+ const { oldValue: b, newValue: U } = Qt(
367
367
  s.updateType,
368
368
  u,
369
369
  E,
370
370
  o
371
- ), J = {
371
+ ), Y = {
372
372
  timeStamp: O,
373
373
  stateKey: I,
374
374
  path: o,
375
375
  updateType: s.updateType,
376
376
  status: "new",
377
- oldValue: x,
377
+ oldValue: b,
378
378
  newValue: U
379
379
  };
380
380
  switch (s.updateType) {
@@ -386,54 +386,54 @@ function Qe(e, {
386
386
  f.insertShadowArrayElement(I, V, U);
387
387
  break;
388
388
  case "cut":
389
- const C = o.slice(0, -1), M = parseInt(o[o.length - 1]);
390
- f.removeShadowArrayElement(I, C, M);
389
+ const $ = o.slice(0, -1), M = parseInt(o[o.length - 1]);
390
+ f.removeShadowArrayElement(I, $, M);
391
391
  break;
392
392
  }
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;
393
+ if (Jt(I, (V) => {
394
+ const M = [...V ?? [], Y].reduce((A, w) => {
395
+ const x = `${w.stateKey}:${JSON.stringify(w.path)}`, L = A.get(x);
396
+ return L ? (L.timeStamp = Math.max(L.timeStamp, w.timeStamp), L.newValue = w.newValue, L.oldValue = L.oldValue ?? w.oldValue, L.updateType = w.updateType) : A.set(x, { ...w }), A;
397
397
  }, /* @__PURE__ */ new Map());
398
398
  return Array.from(M.values());
399
- }), be(
399
+ }), bt(
400
400
  E,
401
401
  I,
402
402
  G.current,
403
403
  D
404
404
  ), G.current?.middleware && G.current.middleware({
405
405
  updateLog: l,
406
- update: J
406
+ update: Y
407
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 }),
408
+ const V = f.serverState[I], $ = G.current?.serverSync;
409
+ Zt(I, {
410
+ syncKey: typeof $.syncKey == "string" ? $.syncKey : $.syncKey({ state: E }),
411
411
  rollBackState: V,
412
- actionTimeStamp: Date.now() + (C.debounce ?? 3e3),
412
+ actionTimeStamp: Date.now() + ($.debounce ?? 3e3),
413
413
  status: "waiting"
414
414
  });
415
415
  }
416
416
  return E;
417
417
  });
418
418
  };
419
- r.getState().updaterState[I] || (me(
419
+ r.getState().updaterState[I] || (It(
420
420
  I,
421
- Ie(
421
+ ht(
422
422
  I,
423
- ae,
424
- ee.current,
423
+ at,
424
+ tt.current,
425
425
  D
426
426
  )
427
- ), r.getState().cogsStateStore[I] || ne(I, e), r.getState().initialStateGlobal[I] || Oe(I, e));
428
- const d = Ee(() => Ie(
427
+ ), r.getState().cogsStateStore[I] || et(I, t), r.getState().initialStateGlobal[I] || At(I, t));
428
+ const d = _t(() => ht(
429
429
  I,
430
- ae,
431
- ee.current,
430
+ at,
431
+ tt.current,
432
432
  D
433
433
  ), [I, D]);
434
- return [Pe(I), d];
434
+ return [Vt(I), d];
435
435
  }
436
- function Ie(e, i, m, g) {
436
+ function ht(t, i, m, g) {
437
437
  const T = /* @__PURE__ */ new Map();
438
438
  let N = 0;
439
439
  const p = (h) => {
@@ -441,66 +441,66 @@ function Ie(e, i, m, g) {
441
441
  for (const [S] of T)
442
442
  (S === n || S.startsWith(n + ".")) && T.delete(S);
443
443
  N++;
444
- }, v = {
444
+ }, y = {
445
445
  removeValidation: (h) => {
446
446
  h?.validationKey && X(h.validationKey);
447
447
  },
448
448
  revertToInitialState: (h) => {
449
- const n = r.getState().getInitialOptions(e)?.validation;
449
+ const n = r.getState().getInitialOptions(t)?.validation;
450
450
  n?.key && X(n?.key), h?.validationKey && X(h.validationKey);
451
- const S = r.getState().initialStateGlobal[e];
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
- const I = r.getState().stateComponents.get(e);
451
+ const S = r.getState().initialStateGlobal[t];
452
+ r.getState().clearSelectedIndexesForState(t), T.clear(), N++;
453
+ const F = a(S, []), R = rt(t), D = K(R?.localStorage?.key) ? R?.localStorage?.key(S) : R?.localStorage?.key, B = `${g}-${t}-${D}`;
454
+ B && localStorage.removeItem(B), It(t, F), et(t, S);
455
+ const I = r.getState().stateComponents.get(t);
456
456
  return I && I.components.forEach((l) => {
457
457
  l.forceUpdate();
458
458
  }), S;
459
459
  },
460
460
  updateInitialState: (h) => {
461
461
  T.clear(), N++;
462
- const n = Ie(
463
- e,
462
+ const n = ht(
463
+ t,
464
464
  i,
465
465
  m,
466
466
  g
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
- const F = r.getState().stateComponents.get(e);
471
- F && F.components.forEach((I) => {
467
+ ), S = r.getState().initialStateGlobal[t], F = rt(t), R = K(F?.localStorage?.key) ? F?.localStorage?.key(S) : F?.localStorage?.key, D = `${g}-${t}-${R}`;
468
+ return localStorage.getItem(D) && localStorage.removeItem(D), Dt(() => {
469
+ At(t, h), r.getState().initializeShadowState(t, h), It(t, n), et(t, h);
470
+ const B = r.getState().stateComponents.get(t);
471
+ B && B.components.forEach((I) => {
472
472
  I.forceUpdate();
473
473
  });
474
474
  }), {
475
- fetchId: (F) => n.get()[F]
475
+ fetchId: (B) => n.get()[B]
476
476
  };
477
477
  },
478
- _initialState: r.getState().initialStateGlobal[e],
479
- _serverState: r.getState().serverState[e],
480
- _isLoading: r.getState().isLoadingGlobal[e],
478
+ _initialState: r.getState().initialStateGlobal[t],
479
+ _serverState: r.getState().serverState[t],
480
+ _isLoading: r.getState().isLoadingGlobal[t],
481
481
  _isServerSynced: () => {
482
- const h = r.getState().serverState[e];
483
- return !!(h && q(h, Pe(e)));
482
+ const h = r.getState().serverState[t];
483
+ return !!(h && q(h, Vt(t)));
484
484
  }
485
485
  };
486
486
  function a(h, n = [], S) {
487
- const H = n.map(String).join(".");
488
- T.get(H);
487
+ const F = n.map(String).join(".");
488
+ T.get(F);
489
489
  const R = function() {
490
- return r().getNestedState(e, n);
490
+ return r().getNestedState(t, n);
491
491
  };
492
- Object.keys(v).forEach((I) => {
493
- R[I] = v[I];
492
+ Object.keys(y).forEach((I) => {
493
+ R[I] = y[I];
494
494
  });
495
495
  const D = {
496
- apply(I, l, ue) {
496
+ apply(I, l, ut) {
497
497
  return console.log(
498
- `PROXY APPLY TRAP HIT: stateKey=${e}, path=${n.join(".")}`
499
- ), console.trace("Apply trap stack trace"), r().getNestedState(e, n);
498
+ `PROXY APPLY TRAP HIT: stateKey=${t}, path=${n.join(".")}`
499
+ ), console.trace("Apply trap stack trace"), r().getNestedState(t, n);
500
500
  },
501
501
  get(I, l) {
502
502
  S?.validIndices && !Array.isArray(h) && (S = { ...S, validIndices: void 0 });
503
- const ue = /* @__PURE__ */ new Set([
503
+ const ut = /* @__PURE__ */ new Set([
504
504
  "insert",
505
505
  "cut",
506
506
  "cutByValue",
@@ -523,10 +523,10 @@ function Ie(e, i, m, g) {
523
523
  "_stateKey",
524
524
  "getComponents"
525
525
  ]);
526
- if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !ue.has(l)) {
527
- const d = `${e}////${m}`, t = r.getState().stateComponents.get(e);
528
- if (t) {
529
- const o = t.components.get(d);
526
+ if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !ut.has(l)) {
527
+ const d = `${t}////${m}`, e = r.getState().stateComponents.get(t);
528
+ if (e) {
529
+ const o = e.components.get(d);
530
530
  if (o && !o.paths.has("")) {
531
531
  const s = n.join(".");
532
532
  let c = !0;
@@ -540,53 +540,53 @@ function Ie(e, i, m, g) {
540
540
  }
541
541
  }
542
542
  if (l === "getDifferences")
543
- return () => we(
544
- r.getState().cogsStateStore[e],
545
- r.getState().initialStateGlobal[e]
543
+ return () => wt(
544
+ r.getState().cogsStateStore[t],
545
+ r.getState().initialStateGlobal[t]
546
546
  );
547
547
  if (l === "sync" && n.length === 0)
548
548
  return async function() {
549
- const d = r.getState().getInitialOptions(e), t = d?.sync;
550
- if (!t)
551
- return console.error(`No mutation defined for state key "${e}"`), { success: !1, error: "No mutation defined" };
552
- const o = r.getState().getNestedState(e, []), s = d?.validation?.key;
549
+ const d = r.getState().getInitialOptions(t), e = d?.sync;
550
+ if (!e)
551
+ return console.error(`No mutation defined for state key "${t}"`), { success: !1, error: "No mutation defined" };
552
+ const o = r.getState().getNestedState(t, []), s = d?.validation?.key;
553
553
  try {
554
- const c = await t.action(o);
554
+ const c = await e.action(o);
555
555
  if (c && !c.success && c.errors && s) {
556
556
  r.getState().removeValidationError(s), c.errors.forEach((u) => {
557
557
  const E = [s, ...u.path].join(".");
558
558
  r.getState().addValidationError(E, u.message);
559
559
  });
560
- const f = r.getState().stateComponents.get(e);
560
+ const f = r.getState().stateComponents.get(t);
561
561
  f && f.components.forEach((u) => {
562
562
  u.forceUpdate();
563
563
  });
564
564
  }
565
- return c?.success && t.onSuccess ? t.onSuccess(c.data) : !c?.success && t.onError && t.onError(c.error), c;
565
+ return c?.success && e.onSuccess ? e.onSuccess(c.data) : !c?.success && e.onError && e.onError(c.error), c;
566
566
  } catch (c) {
567
- return t.onError && t.onError(c), { success: !1, error: c };
567
+ return e.onError && e.onError(c), { success: !1, error: c };
568
568
  }
569
569
  };
570
570
  if (l === "_status") {
571
- const d = r.getState().getNestedState(e, n), t = r.getState().initialStateGlobal[e], o = Z(t, n);
571
+ const d = r.getState().getNestedState(t, n), e = r.getState().initialStateGlobal[t], o = Z(e, n);
572
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
- e,
577
+ t,
578
578
  n
579
- ), t = r.getState().initialStateGlobal[e], o = Z(t, n);
579
+ ), e = r.getState().initialStateGlobal[t], o = Z(e, n);
580
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 = K(t?.localStorage?.key) ? t?.localStorage?.key(d) : t?.localStorage?.key, s = `${g}-${e}-${o}`;
584
+ const d = r.getState().initialStateGlobal[t], e = rt(t), o = K(e?.localStorage?.key) ? e?.localStorage?.key(d) : e?.localStorage?.key, s = `${g}-${t}-${o}`;
585
585
  s && localStorage.removeItem(s);
586
586
  };
587
587
  if (l === "showValidationErrors")
588
588
  return () => {
589
- const d = r.getState().getInitialOptions(e)?.validation;
589
+ const d = r.getState().getInitialOptions(t)?.validation;
590
590
  if (!d?.key)
591
591
  throw new Error("Validation key not found");
592
592
  return r.getState().getValidationErrors(d.key + "." + n.join("."));
@@ -595,192 +595,200 @@ function Ie(e, i, m, g) {
595
595
  const d = () => S?.validIndices ? h.map((o, s) => ({
596
596
  item: o,
597
597
  originalIndex: S.validIndices[s]
598
- })) : r.getState().getNestedState(e, n).map((o, s) => ({
598
+ })) : r.getState().getNestedState(t, n).map((o, s) => ({
599
599
  item: o,
600
600
  originalIndex: s
601
601
  }));
602
602
  if (l === "getSelected")
603
603
  return () => {
604
- const t = r.getState().getSelectedIndex(e, n.join("."));
605
- if (t !== void 0)
604
+ const e = r.getState().getSelectedIndex(t, n.join("."));
605
+ if (e !== void 0)
606
606
  return a(
607
- h[t],
608
- [...n, t.toString()],
607
+ h[e],
608
+ [...n, e.toString()],
609
609
  S
610
610
  );
611
611
  };
612
612
  if (l === "clearSelected")
613
613
  return () => {
614
- r.getState().clearSelectedIndex({ stateKey: e, path: n });
614
+ r.getState().clearSelectedIndex({ stateKey: t, path: n });
615
615
  };
616
616
  if (l === "getSelectedIndex")
617
- return () => r.getState().getSelectedIndex(e, n.join(".")) ?? -1;
617
+ return () => r.getState().getSelectedIndex(t, n.join(".")) ?? -1;
618
618
  if (l === "useVirtualView")
619
- return (t) => {
619
+ return (e) => {
620
620
  const {
621
621
  itemHeight: o = 50,
622
622
  overscan: s = 6,
623
623
  stickToBottom: c = !1,
624
624
  dependencies: f = []
625
- } = t, u = Y(!1), E = Y(null), [y, w] = Q({
625
+ } = e, u = J(!1), E = J(null), [v, _] = Q({
626
626
  startIndex: 0,
627
627
  endIndex: 10
628
- }), [$, O] = Q("IDLE_AT_TOP"), x = Y(!1), U = Y(0), J = Y(f), [V, C] = Q(0);
629
- oe(() => r.getState().subscribeToShadowState(e, () => {
630
- C((P) => P + 1);
631
- }), [e]);
628
+ }), [C, O] = Q("IDLE_AT_TOP"), b = J(!1), U = J(0), Y = J(f);
629
+ J(0);
630
+ const [V, $] = Q(0);
631
+ ot(() => r.getState().subscribeToShadowState(t, () => {
632
+ $((P) => P + 1);
633
+ }), [t]);
632
634
  const M = r().getNestedState(
633
- e,
635
+ t,
634
636
  n
635
- ), A = M.length, { totalHeight: _, positions: b } = Ee(() => {
636
- const k = r.getState().getShadowMetadata(e, n) || [];
637
+ ), A = M.length, { totalHeight: w, positions: x } = _t(() => {
638
+ const k = r.getState().getShadowMetadata(t, n) || [];
637
639
  let P = 0;
638
- const z = [];
639
- for (let B = 0; B < A; B++) {
640
- z[B] = P;
641
- const te = k[B]?.virtualizer?.itemHeight;
642
- P += te || o;
640
+ const H = [];
641
+ for (let z = 0; z < A; z++) {
642
+ H[z] = P;
643
+ const nt = k[z]?.virtualizer?.itemHeight;
644
+ P += nt || o;
643
645
  }
644
- return { totalHeight: P, positions: z };
646
+ return { totalHeight: P, positions: H };
645
647
  }, [
646
648
  A,
647
- e,
649
+ t,
648
650
  n.join("."),
649
651
  o,
650
652
  V
651
- ]), L = Ee(() => {
652
- const k = Math.max(0, y.startIndex), P = Math.min(A, y.endIndex), z = Array.from(
653
+ ]), L = _t(() => {
654
+ const k = Math.max(0, v.startIndex), P = Math.min(A, v.endIndex), H = Array.from(
653
655
  { length: P - k },
654
- (te, ie) => k + ie
655
- ), B = z.map((te) => M[te]);
656
- return a(B, n, {
656
+ (nt, it) => k + it
657
+ ), z = H.map((nt) => M[nt]);
658
+ return a(z, n, {
657
659
  ...S,
658
- validIndices: z
660
+ validIndices: H
659
661
  });
660
- }, [y.startIndex, y.endIndex, M, A]);
661
- le(() => {
662
+ }, [v.startIndex, v.endIndex, M, A]);
663
+ lt(() => {
662
664
  const k = !q(
663
665
  f,
664
- J.current
666
+ Y.current
665
667
  ), P = A > U.current;
666
668
  if (k) {
667
669
  console.log("TRANSITION: Deps changed -> IDLE_AT_TOP"), O("IDLE_AT_TOP");
668
670
  return;
669
671
  }
670
- P && $ === "LOCKED_AT_BOTTOM" && c && (console.log(
672
+ P && C === "LOCKED_AT_BOTTOM" && c && (console.log(
671
673
  "TRANSITION: New items arrived while locked -> GETTING_HEIGHTS"
672
- ), O("GETTING_HEIGHTS")), U.current = A, J.current = f;
673
- }, [A, ...f]), le(() => {
674
+ ), O("GETTING_HEIGHTS")), U.current = A, Y.current = f;
675
+ }, [A, ...f]), lt(() => {
674
676
  const k = E.current;
675
677
  if (!k) return;
676
678
  let P;
677
- if ($ === "IDLE_AT_TOP" && c && A > 0)
679
+ if (C === "IDLE_AT_TOP" && c && A > 0)
678
680
  console.log(
679
681
  "ACTION (IDLE_AT_TOP): Data has arrived -> GETTING_HEIGHTS"
680
682
  ), O("GETTING_HEIGHTS");
681
- else if ($ === "GETTING_HEIGHTS")
683
+ else if (C === "GETTING_HEIGHTS")
682
684
  console.log(
683
685
  "ACTION (GETTING_HEIGHTS): Setting range to end and starting loop."
684
- ), w({
686
+ ), _({
685
687
  startIndex: Math.max(0, A - 10 - s),
686
688
  endIndex: A
687
689
  }), 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
+ const H = A - 1;
691
+ ((r.getState().getShadowMetadata(t, n) || [])[H]?.virtualizer?.itemHeight || 0) > 0 && (clearInterval(P), u.current || (console.log(
690
692
  "ACTION (GETTING_HEIGHTS): Measurement success -> SCROLLING_TO_BOTTOM"
691
693
  ), O("SCROLLING_TO_BOTTOM")));
692
694
  }, 100);
693
- else if ($ === "SCROLLING_TO_BOTTOM") {
695
+ else if (C === "SCROLLING_TO_BOTTOM") {
694
696
  console.log(
695
697
  "ACTION (SCROLLING_TO_BOTTOM): Executing scroll."
696
- ), x.current = !0;
697
- const z = U.current === 0 ? "auto" : "smooth";
698
+ ), b.current = !0;
699
+ const H = U.current === 0 ? "auto" : "smooth";
698
700
  k.scrollTo({
699
701
  top: k.scrollHeight,
700
- behavior: z
702
+ behavior: H
701
703
  });
702
- const B = setTimeout(
704
+ const z = setTimeout(
703
705
  () => {
704
706
  console.log(
705
707
  "ACTION (SCROLLING_TO_BOTTOM): Scroll finished -> LOCKED_AT_BOTTOM"
706
- ), x.current = !1, u.current = !1, O("LOCKED_AT_BOTTOM");
708
+ ), b.current = !1, u.current = !1, O("LOCKED_AT_BOTTOM");
707
709
  },
708
- z === "smooth" ? 500 : 50
710
+ H === "smooth" ? 500 : 50
709
711
  );
710
- return () => clearTimeout(B);
712
+ return () => clearTimeout(z);
711
713
  }
712
714
  return () => {
713
715
  P && clearInterval(P);
714
716
  };
715
- }, [$, A, b]), oe(() => {
717
+ }, [C, A, x]), ot(() => {
716
718
  const k = E.current;
717
719
  if (!k) return;
718
720
  const P = () => {
719
- if (x.current)
721
+ if (b.current)
720
722
  return;
721
- k.scrollHeight - k.scrollTop - k.clientHeight < 1 ? u.current = !1 : (console.log(
722
- "USER ACTION: Scrolled up -> IDLE_NOT_AT_BOTTOM"
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;
723
+ const { scrollTop: H, clientHeight: z } = k;
724
+ k.scrollHeight - H - k.clientHeight < 1 ? C === "IDLE_NOT_AT_BOTTOM" && O("LOCKED_AT_BOTTOM") : C !== "IDLE_NOT_AT_BOTTOM" && O("IDLE_NOT_AT_BOTTOM");
725
+ let it = A - 1, yt = 0, Nt = 0;
726
+ for (; yt <= it; ) {
727
+ const St = Math.floor((yt + it) / 2);
728
+ x[St] < H ? (Nt = St, yt = St + 1) : it = St - 1;
729
729
  }
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)
730
+ const gt = Math.max(
731
+ 0,
732
+ Nt - s
733
+ );
734
+ if (gt === v.startIndex)
735
+ return;
736
+ console.log(
737
+ `Index changed from ${v.startIndex} to ${gt}. Updating range.`
738
+ );
739
+ let ft = gt;
740
+ const Lt = H + z;
741
+ for (; ft < A && x[ft] < Lt; )
742
+ ft++;
743
+ _({
744
+ startIndex: gt,
745
+ endIndex: Math.min(A, ft + s)
738
746
  });
739
747
  };
740
748
  return k.addEventListener("scroll", P, {
741
749
  passive: !0
742
750
  }), () => k.removeEventListener("scroll", P);
743
- }, [A, b, $]);
744
- const W = Ne(() => {
751
+ }, [A, x, C, v.startIndex]);
752
+ const W = Ct(() => {
745
753
  console.log(
746
754
  "USER ACTION: Clicked scroll button -> SCROLLING_TO_BOTTOM"
747
755
  ), O("SCROLLING_TO_BOTTOM");
748
- }, []), j = Ne(
756
+ }, []), j = Ct(
749
757
  (k, P = "smooth") => {
750
- E.current && b[k] !== void 0 && (O("IDLE_NOT_AT_BOTTOM"), E.current.scrollTo({
751
- top: b[k],
758
+ E.current && x[k] !== void 0 && (O("IDLE_NOT_AT_BOTTOM"), E.current.scrollTo({
759
+ top: x[k],
752
760
  behavior: P
753
761
  }));
754
762
  },
755
- [b]
756
- ), se = {
763
+ [x]
764
+ ), st = {
757
765
  outer: {
758
766
  ref: E,
759
767
  style: { overflowY: "auto", height: "100%" }
760
768
  },
761
769
  inner: {
762
770
  style: {
763
- height: `${_}px`,
771
+ height: `${w}px`,
764
772
  position: "relative"
765
773
  }
766
774
  },
767
775
  list: {
768
776
  style: {
769
- transform: `translateY(${b[y.startIndex] || 0}px)`
777
+ transform: `translateY(${x[v.startIndex] || 0}px)`
770
778
  }
771
779
  }
772
780
  };
773
781
  return {
774
782
  virtualState: L,
775
- virtualizerProps: se,
783
+ virtualizerProps: st,
776
784
  scrollToBottom: W,
777
785
  scrollToIndex: j
778
786
  };
779
787
  };
780
788
  if (l === "stateSort")
781
- return (t) => {
789
+ return (e) => {
782
790
  const s = [...d()].sort(
783
- (u, E) => t(u.item, E.item)
791
+ (u, E) => e(u.item, E.item)
784
792
  ), c = s.map(({ item: u }) => u), f = {
785
793
  ...S,
786
794
  validIndices: s.map(
@@ -790,9 +798,9 @@ function Ie(e, i, m, g) {
790
798
  return a(c, n, f);
791
799
  };
792
800
  if (l === "stateFilter")
793
- return (t) => {
801
+ return (e) => {
794
802
  const s = d().filter(
795
- ({ item: u }, E) => t(u, E)
803
+ ({ item: u }, E) => e(u, E)
796
804
  ), c = s.map(({ item: u }) => u), f = {
797
805
  ...S,
798
806
  validIndices: s.map(
@@ -802,25 +810,25 @@ function Ie(e, i, m, g) {
802
810
  return a(c, n, f);
803
811
  };
804
812
  if (l === "stateMap")
805
- return (t) => {
806
- const o = r.getState().getNestedState(e, n);
813
+ return (e) => {
814
+ const o = r.getState().getNestedState(t, n);
807
815
  return Array.isArray(o) ? (S?.validIndices || Array.from({ length: o.length }, (c, f) => f)).map((c, f) => {
808
- const u = o[c], E = [...n, c.toString()], y = a(u, E, S);
809
- return t(u, y, {
816
+ const u = o[c], E = [...n, c.toString()], v = a(u, E, S);
817
+ return e(u, v, {
810
818
  register: () => {
811
- const [, $] = Q({}), O = `${m}-${n.join(".")}-${c}`;
812
- le(() => {
813
- const x = `${e}////${O}`, U = r.getState().stateComponents.get(e) || {
819
+ const [, C] = Q({}), O = `${m}-${n.join(".")}-${c}`;
820
+ lt(() => {
821
+ const b = `${t}////${O}`, U = r.getState().stateComponents.get(t) || {
814
822
  components: /* @__PURE__ */ new Map()
815
823
  };
816
- return U.components.set(x, {
817
- forceUpdate: () => $({}),
824
+ return U.components.set(b, {
825
+ forceUpdate: () => C({}),
818
826
  paths: /* @__PURE__ */ new Set([E.join(".")])
819
- }), r.getState().stateComponents.set(e, U), () => {
820
- const J = r.getState().stateComponents.get(e);
821
- J && J.components.delete(x);
827
+ }), r.getState().stateComponents.set(t, U), () => {
828
+ const Y = r.getState().stateComponents.get(t);
829
+ Y && Y.components.delete(b);
822
830
  };
823
- }, [e, O]);
831
+ }, [t, O]);
824
832
  },
825
833
  index: f,
826
834
  originalIndex: c
@@ -831,11 +839,11 @@ function Ie(e, i, m, g) {
831
839
  ), null);
832
840
  };
833
841
  if (l === "stateMapNoRender")
834
- return (t) => h.map((s, c) => {
842
+ return (e) => h.map((s, c) => {
835
843
  let f;
836
844
  S?.validIndices && S.validIndices[c] !== void 0 ? f = S.validIndices[c] : f = c;
837
845
  const u = [...n, f.toString()], E = a(s, u, S);
838
- return t(
846
+ return e(
839
847
  s,
840
848
  E,
841
849
  c,
@@ -844,28 +852,28 @@ function Ie(e, i, m, g) {
844
852
  );
845
853
  });
846
854
  if (l === "$stateMap")
847
- return (t) => de(Ke, {
855
+ return (e) => dt(te, {
848
856
  proxy: {
849
- _stateKey: e,
857
+ _stateKey: t,
850
858
  _path: n,
851
- _mapFn: t
859
+ _mapFn: e
852
860
  // Pass the actual function, not string
853
861
  },
854
862
  rebuildStateShape: a
855
863
  });
856
864
  if (l === "stateList")
857
- return (t) => {
858
- const o = r.getState().getNestedState(e, n);
865
+ return (e) => {
866
+ const o = r.getState().getNestedState(t, n);
859
867
  return Array.isArray(o) ? (S?.validIndices || Array.from({ length: o.length }, (c, f) => f)).map((c, f) => {
860
- const u = o[c], E = [...n, c.toString()], y = a(u, E, S), w = `${m}-${n.join(".")}-${c}`;
861
- return de(tt, {
868
+ const u = o[c], E = [...n, c.toString()], v = a(u, E, S), _ = `${m}-${n.join(".")}-${c}`;
869
+ return dt(ne, {
862
870
  key: c,
863
- stateKey: e,
864
- itemComponentId: w,
871
+ stateKey: t,
872
+ itemComponentId: _,
865
873
  itemPath: E,
866
- children: t(
874
+ children: e(
867
875
  u,
868
- y,
876
+ v,
869
877
  f,
870
878
  o,
871
879
  a(o, n, S)
@@ -876,230 +884,230 @@ function Ie(e, i, m, g) {
876
884
  ), null);
877
885
  };
878
886
  if (l === "stateFlattenOn")
879
- return (t) => {
887
+ return (e) => {
880
888
  const o = h;
881
889
  T.clear(), N++;
882
890
  const s = o.flatMap(
883
- (c) => c[t] ?? []
891
+ (c) => c[e] ?? []
884
892
  );
885
893
  return a(
886
894
  s,
887
- [...n, "[*]", t],
895
+ [...n, "[*]", e],
888
896
  S
889
897
  );
890
898
  };
891
899
  if (l === "index")
892
- return (t) => {
893
- const o = h[t];
894
- return a(o, [...n, t.toString()]);
900
+ return (e) => {
901
+ const o = h[e];
902
+ return a(o, [...n, e.toString()]);
895
903
  };
896
904
  if (l === "last")
897
905
  return () => {
898
- const t = r.getState().getNestedState(e, n);
899
- if (t.length === 0) return;
900
- const o = t.length - 1, s = t[o], c = [...n, o.toString()];
906
+ const e = r.getState().getNestedState(t, n);
907
+ if (e.length === 0) return;
908
+ const o = e.length - 1, s = e[o], c = [...n, o.toString()];
901
909
  return a(s, c);
902
910
  };
903
911
  if (l === "insert")
904
- return (t) => (p(n), ye(i, t, n, e), a(
905
- r.getState().getNestedState(e, n),
912
+ return (e) => (p(n), pt(i, e, n, t), a(
913
+ r.getState().getNestedState(t, n),
906
914
  n
907
915
  ));
908
916
  if (l === "uniqueInsert")
909
- return (t, o, s) => {
910
- const c = r.getState().getNestedState(e, n), f = K(t) ? t(c) : t;
917
+ return (e, o, s) => {
918
+ const c = r.getState().getNestedState(t, n), f = K(e) ? e(c) : e;
911
919
  let u = null;
912
- if (!c.some((y) => {
920
+ if (!c.some((v) => {
913
921
  if (o) {
914
- const $ = o.every(
915
- (O) => q(y[O], f[O])
922
+ const C = o.every(
923
+ (O) => q(v[O], f[O])
916
924
  );
917
- return $ && (u = y), $;
925
+ return C && (u = v), C;
918
926
  }
919
- const w = q(y, f);
920
- return w && (u = y), w;
927
+ const _ = q(v, f);
928
+ return _ && (u = v), _;
921
929
  }))
922
- p(n), ye(i, f, n, e);
930
+ p(n), pt(i, f, n, t);
923
931
  else if (s && u) {
924
- const y = s(u), w = c.map(
925
- ($) => q($, u) ? y : $
932
+ const v = s(u), _ = c.map(
933
+ (C) => q(C, u) ? v : C
926
934
  );
927
- p(n), ce(i, w, n);
935
+ p(n), ct(i, _, n);
928
936
  }
929
937
  };
930
938
  if (l === "cut")
931
- return (t, o) => {
939
+ return (e, o) => {
932
940
  if (!o?.waitForSync)
933
- return p(n), Se(i, n, e, t), a(
934
- r.getState().getNestedState(e, n),
941
+ return p(n), mt(i, n, t, e), a(
942
+ r.getState().getNestedState(t, n),
935
943
  n
936
944
  );
937
945
  };
938
946
  if (l === "cutByValue")
939
- return (t) => {
947
+ return (e) => {
940
948
  for (let o = 0; o < h.length; o++)
941
- h[o] === t && Se(i, n, e, o);
949
+ h[o] === e && mt(i, n, t, o);
942
950
  };
943
951
  if (l === "toggleByValue")
944
- return (t) => {
945
- const o = h.findIndex((s) => s === t);
946
- o > -1 ? Se(i, n, e, o) : ye(i, t, n, e);
952
+ return (e) => {
953
+ const o = h.findIndex((s) => s === e);
954
+ o > -1 ? mt(i, n, t, o) : pt(i, e, n, t);
947
955
  };
948
956
  if (l === "stateFind")
949
- return (t) => {
957
+ return (e) => {
950
958
  const s = d().find(
951
- ({ item: f }, u) => t(f, u)
959
+ ({ item: f }, u) => e(f, u)
952
960
  );
953
961
  if (!s) return;
954
962
  const c = [...n, s.originalIndex.toString()];
955
963
  return a(s.item, c, S);
956
964
  };
957
965
  if (l === "findWith")
958
- return (t, o) => {
966
+ return (e, o) => {
959
967
  const c = d().find(
960
- ({ item: u }) => u[t] === o
968
+ ({ item: u }) => u[e] === o
961
969
  );
962
970
  if (!c) return;
963
971
  const f = [...n, c.originalIndex.toString()];
964
972
  return a(c.item, f, S);
965
973
  };
966
974
  }
967
- const ee = n[n.length - 1];
968
- if (!isNaN(Number(ee))) {
969
- const d = n.slice(0, -1), t = r.getState().getNestedState(e, d);
970
- if (Array.isArray(t) && l === "cut")
971
- return () => Se(
975
+ const tt = n[n.length - 1];
976
+ if (!isNaN(Number(tt))) {
977
+ const d = n.slice(0, -1), e = r.getState().getNestedState(t, d);
978
+ if (Array.isArray(e) && l === "cut")
979
+ return () => mt(
972
980
  i,
973
981
  d,
974
- e,
975
- Number(ee)
982
+ t,
983
+ Number(tt)
976
984
  );
977
985
  }
978
986
  if (l === "get")
979
987
  return () => {
980
988
  if (S?.validIndices && Array.isArray(h)) {
981
- const d = r.getState().getNestedState(e, n);
982
- return S.validIndices.map((t) => d[t]);
989
+ const d = r.getState().getNestedState(t, n);
990
+ return S.validIndices.map((e) => d[e]);
983
991
  }
984
- return r.getState().getNestedState(e, n);
992
+ return r.getState().getNestedState(t, n);
985
993
  };
986
994
  if (l === "$derive")
987
- return (d) => xe({
988
- _stateKey: e,
995
+ return (d) => Mt({
996
+ _stateKey: t,
989
997
  _path: n,
990
998
  _effect: d.toString()
991
999
  });
992
1000
  if (l === "$get")
993
- return () => xe({
994
- _stateKey: e,
1001
+ return () => Mt({
1002
+ _stateKey: t,
995
1003
  _path: n
996
1004
  });
997
1005
  if (l === "lastSynced") {
998
- const d = `${e}:${n.join(".")}`;
1006
+ const d = `${t}:${n.join(".")}`;
999
1007
  return r.getState().getSyncInfo(d);
1000
1008
  }
1001
1009
  if (l == "getLocalStorage")
1002
- return (d) => he(g + "-" + e + "-" + d);
1010
+ return (d) => Tt(g + "-" + t + "-" + d);
1003
1011
  if (l === "_selected") {
1004
- const d = n.slice(0, -1), t = d.join("."), o = r.getState().getNestedState(e, d);
1005
- return Array.isArray(o) ? Number(n[n.length - 1]) === r.getState().getSelectedIndex(e, t) : void 0;
1012
+ const d = n.slice(0, -1), e = d.join("."), o = r.getState().getNestedState(t, d);
1013
+ return Array.isArray(o) ? Number(n[n.length - 1]) === r.getState().getSelectedIndex(t, e) : void 0;
1006
1014
  }
1007
1015
  if (l === "setSelected")
1008
1016
  return (d) => {
1009
- const t = n.slice(0, -1), o = Number(n[n.length - 1]), s = t.join(".");
1010
- d ? r.getState().setSelectedIndex(e, s, o) : r.getState().setSelectedIndex(e, s, void 0);
1011
- const c = r.getState().getNestedState(e, [...t]);
1012
- ce(i, c, t), p(t);
1017
+ const e = n.slice(0, -1), o = Number(n[n.length - 1]), s = e.join(".");
1018
+ d ? r.getState().setSelectedIndex(t, s, o) : r.getState().setSelectedIndex(t, s, void 0);
1019
+ const c = r.getState().getNestedState(t, [...e]);
1020
+ ct(i, c, e), p(e);
1013
1021
  };
1014
1022
  if (l === "toggleSelected")
1015
1023
  return () => {
1016
- const d = n.slice(0, -1), t = Number(n[n.length - 1]), o = d.join("."), s = r.getState().getSelectedIndex(e, o);
1024
+ const d = n.slice(0, -1), e = Number(n[n.length - 1]), o = d.join("."), s = r.getState().getSelectedIndex(t, o);
1017
1025
  r.getState().setSelectedIndex(
1018
- e,
1026
+ t,
1019
1027
  o,
1020
- s === t ? void 0 : t
1028
+ s === e ? void 0 : e
1021
1029
  );
1022
- const c = r.getState().getNestedState(e, [...d]);
1023
- ce(i, c, d), p(d);
1030
+ const c = r.getState().getNestedState(t, [...d]);
1031
+ ct(i, c, d), p(d);
1024
1032
  };
1025
1033
  if (n.length == 0) {
1026
1034
  if (l === "applyJsonPatch")
1027
1035
  return (d) => {
1028
- const t = r.getState().cogsStateStore[e], s = Be(t, d).newDocument;
1029
- Ve(
1030
- e,
1031
- r.getState().initialStateGlobal[e],
1036
+ const e = r.getState().cogsStateStore[t], s = Wt(e, d).newDocument;
1037
+ Gt(
1038
+ t,
1039
+ r.getState().initialStateGlobal[t],
1032
1040
  s,
1033
1041
  i,
1034
1042
  m,
1035
1043
  g
1036
1044
  );
1037
- const c = r.getState().stateComponents.get(e);
1045
+ const c = r.getState().stateComponents.get(t);
1038
1046
  if (c) {
1039
- const f = we(t, s), u = new Set(f);
1047
+ const f = wt(e, s), u = new Set(f);
1040
1048
  for (const [
1041
1049
  E,
1042
- y
1050
+ v
1043
1051
  ] of c.components.entries()) {
1044
- let w = !1;
1045
- const $ = Array.isArray(y.reactiveType) ? y.reactiveType : [y.reactiveType || "component"];
1046
- if (!$.includes("none")) {
1047
- if ($.includes("all")) {
1048
- y.forceUpdate();
1052
+ let _ = !1;
1053
+ const C = Array.isArray(v.reactiveType) ? v.reactiveType : [v.reactiveType || "component"];
1054
+ if (!C.includes("none")) {
1055
+ if (C.includes("all")) {
1056
+ v.forceUpdate();
1049
1057
  continue;
1050
1058
  }
1051
- if ($.includes("component") && (y.paths.has("") && (w = !0), !w))
1059
+ if (C.includes("component") && (v.paths.has("") && (_ = !0), !_))
1052
1060
  for (const O of u) {
1053
- if (y.paths.has(O)) {
1054
- w = !0;
1061
+ if (v.paths.has(O)) {
1062
+ _ = !0;
1055
1063
  break;
1056
1064
  }
1057
- let x = O.lastIndexOf(".");
1058
- for (; x !== -1; ) {
1059
- const U = O.substring(0, x);
1060
- if (y.paths.has(U)) {
1061
- w = !0;
1065
+ let b = O.lastIndexOf(".");
1066
+ for (; b !== -1; ) {
1067
+ const U = O.substring(0, b);
1068
+ if (v.paths.has(U)) {
1069
+ _ = !0;
1062
1070
  break;
1063
1071
  }
1064
- const J = O.substring(
1065
- x + 1
1072
+ const Y = O.substring(
1073
+ b + 1
1066
1074
  );
1067
- if (!isNaN(Number(J))) {
1075
+ if (!isNaN(Number(Y))) {
1068
1076
  const V = U.lastIndexOf(".");
1069
1077
  if (V !== -1) {
1070
- const C = U.substring(
1078
+ const $ = U.substring(
1071
1079
  0,
1072
1080
  V
1073
1081
  );
1074
- if (y.paths.has(C)) {
1075
- w = !0;
1082
+ if (v.paths.has($)) {
1083
+ _ = !0;
1076
1084
  break;
1077
1085
  }
1078
1086
  }
1079
1087
  }
1080
- x = U.lastIndexOf(".");
1088
+ b = U.lastIndexOf(".");
1081
1089
  }
1082
- if (w) break;
1090
+ if (_) break;
1083
1091
  }
1084
- if (!w && $.includes("deps") && y.depsFunction) {
1085
- const O = y.depsFunction(s);
1086
- let x = !1;
1087
- typeof O == "boolean" ? O && (x = !0) : q(y.deps, O) || (y.deps = O, x = !0), x && (w = !0);
1092
+ if (!_ && C.includes("deps") && v.depsFunction) {
1093
+ const O = v.depsFunction(s);
1094
+ let b = !1;
1095
+ typeof O == "boolean" ? O && (b = !0) : q(v.deps, O) || (v.deps = O, b = !0), b && (_ = !0);
1088
1096
  }
1089
- w && y.forceUpdate();
1097
+ _ && v.forceUpdate();
1090
1098
  }
1091
1099
  }
1092
1100
  }
1093
1101
  };
1094
1102
  if (l === "validateZodSchema")
1095
1103
  return () => {
1096
- const d = r.getState().getInitialOptions(e)?.validation, t = r.getState().addValidationError;
1104
+ const d = r.getState().getInitialOptions(t)?.validation, e = r.getState().addValidationError;
1097
1105
  if (!d?.zodSchema)
1098
1106
  throw new Error("Zod schema not found");
1099
1107
  if (!d?.key)
1100
1108
  throw new Error("Validation key not found");
1101
1109
  X(d.key);
1102
- const o = r.getState().cogsStateStore[e];
1110
+ const o = r.getState().cogsStateStore[t];
1103
1111
  try {
1104
1112
  const s = r.getState().getValidationErrors(d.key);
1105
1113
  s && s.length > 0 && s.forEach(([f]) => {
@@ -1107,127 +1115,127 @@ function Ie(e, i, m, g) {
1107
1115
  });
1108
1116
  const c = d.zodSchema.safeParse(o);
1109
1117
  return c.success ? !0 : (c.error.errors.forEach((u) => {
1110
- const E = u.path, y = u.message, w = [d.key, ...E].join(".");
1111
- t(w, y);
1112
- }), Te(e), !1);
1118
+ const E = u.path, v = u.message, _ = [d.key, ...E].join(".");
1119
+ e(_, v);
1120
+ }), vt(t), !1);
1113
1121
  } catch (s) {
1114
1122
  return console.error("Zod schema validation failed", s), !1;
1115
1123
  }
1116
1124
  };
1117
1125
  if (l === "_componentId") return m;
1118
1126
  if (l === "getComponents")
1119
- return () => r().stateComponents.get(e);
1127
+ return () => r().stateComponents.get(t);
1120
1128
  if (l === "getAllFormRefs")
1121
- return () => Ce.getState().getFormRefsByStateKey(e);
1129
+ return () => $t.getState().getFormRefsByStateKey(t);
1122
1130
  if (l === "_initialState")
1123
- return r.getState().initialStateGlobal[e];
1131
+ return r.getState().initialStateGlobal[t];
1124
1132
  if (l === "_serverState")
1125
- return r.getState().serverState[e];
1133
+ return r.getState().serverState[t];
1126
1134
  if (l === "_isLoading")
1127
- return r.getState().isLoadingGlobal[e];
1135
+ return r.getState().isLoadingGlobal[t];
1128
1136
  if (l === "revertToInitialState")
1129
- return v.revertToInitialState;
1130
- if (l === "updateInitialState") return v.updateInitialState;
1131
- if (l === "removeValidation") return v.removeValidation;
1137
+ return y.revertToInitialState;
1138
+ if (l === "updateInitialState") return y.updateInitialState;
1139
+ if (l === "removeValidation") return y.removeValidation;
1132
1140
  }
1133
1141
  if (l === "getFormRef")
1134
- return () => Ce.getState().getFormRef(e + "." + n.join("."));
1142
+ return () => $t.getState().getFormRef(t + "." + n.join("."));
1135
1143
  if (l === "validationWrapper")
1136
1144
  return ({
1137
1145
  children: d,
1138
- hideMessage: t
1139
- }) => /* @__PURE__ */ pe(
1140
- je,
1146
+ hideMessage: e
1147
+ }) => /* @__PURE__ */ Et(
1148
+ Ht,
1141
1149
  {
1142
- formOpts: t ? { validation: { message: "" } } : void 0,
1150
+ formOpts: e ? { validation: { message: "" } } : void 0,
1143
1151
  path: n,
1144
- validationKey: r.getState().getInitialOptions(e)?.validation?.key || "",
1145
- stateKey: e,
1152
+ validationKey: r.getState().getInitialOptions(t)?.validation?.key || "",
1153
+ stateKey: t,
1146
1154
  validIndices: S?.validIndices,
1147
1155
  children: d
1148
1156
  }
1149
1157
  );
1150
- if (l === "_stateKey") return e;
1158
+ if (l === "_stateKey") return t;
1151
1159
  if (l === "_path") return n;
1152
- if (l === "_isServerSynced") return v._isServerSynced;
1160
+ if (l === "_isServerSynced") return y._isServerSynced;
1153
1161
  if (l === "update")
1154
- return (d, t) => {
1155
- if (t?.debounce)
1156
- Ue(() => {
1157
- ce(i, d, n, "");
1158
- const o = r.getState().getNestedState(e, n);
1159
- t?.afterUpdate && t.afterUpdate(o);
1160
- }, t.debounce);
1162
+ return (d, e) => {
1163
+ if (e?.debounce)
1164
+ jt(() => {
1165
+ ct(i, d, n, "");
1166
+ const o = r.getState().getNestedState(t, n);
1167
+ e?.afterUpdate && e.afterUpdate(o);
1168
+ }, e.debounce);
1161
1169
  else {
1162
- ce(i, d, n, "");
1163
- const o = r.getState().getNestedState(e, n);
1164
- t?.afterUpdate && t.afterUpdate(o);
1170
+ ct(i, d, n, "");
1171
+ const o = r.getState().getNestedState(t, n);
1172
+ e?.afterUpdate && e.afterUpdate(o);
1165
1173
  }
1166
1174
  p(n);
1167
1175
  };
1168
1176
  if (l === "formElement")
1169
- return (d, t) => /* @__PURE__ */ pe(
1170
- He,
1177
+ return (d, e) => /* @__PURE__ */ Et(
1178
+ Ft,
1171
1179
  {
1172
1180
  setState: i,
1173
- stateKey: e,
1181
+ stateKey: t,
1174
1182
  path: n,
1175
1183
  child: d,
1176
- formOpts: t
1184
+ formOpts: e
1177
1185
  }
1178
1186
  );
1179
- const G = [...n, l], ae = r.getState().getNestedState(e, G);
1180
- return a(ae, G, S);
1187
+ const G = [...n, l], at = r.getState().getNestedState(t, G);
1188
+ return a(at, G, S);
1181
1189
  }
1182
- }, F = new Proxy(R, D);
1183
- return T.set(H, {
1184
- proxy: F,
1190
+ }, B = new Proxy(R, D);
1191
+ return T.set(F, {
1192
+ proxy: B,
1185
1193
  stateVersion: N
1186
- }), F;
1194
+ }), B;
1187
1195
  }
1188
1196
  return a(
1189
- r.getState().getNestedState(e, [])
1197
+ r.getState().getNestedState(t, [])
1190
1198
  );
1191
1199
  }
1192
- function xe(e) {
1193
- return de(et, { proxy: e });
1200
+ function Mt(t) {
1201
+ return dt(ee, { proxy: t });
1194
1202
  }
1195
- function Ke({
1196
- proxy: e,
1203
+ function te({
1204
+ proxy: t,
1197
1205
  rebuildStateShape: i
1198
1206
  }) {
1199
- const m = r().getNestedState(e._stateKey, e._path);
1207
+ const m = r().getNestedState(t._stateKey, t._path);
1200
1208
  return Array.isArray(m) ? i(
1201
1209
  m,
1202
- e._path
1210
+ t._path
1203
1211
  ).stateMapNoRender(
1204
- (T, N, p, v, a) => e._mapFn(T, N, p, v, a)
1212
+ (T, N, p, y, a) => t._mapFn(T, N, p, y, a)
1205
1213
  ) : null;
1206
1214
  }
1207
- function et({
1208
- proxy: e
1215
+ function ee({
1216
+ proxy: t
1209
1217
  }) {
1210
- const i = Y(null), m = `${e._stateKey}-${e._path.join(".")}`;
1211
- return oe(() => {
1218
+ const i = J(null), m = `${t._stateKey}-${t._path.join(".")}`;
1219
+ return ot(() => {
1212
1220
  const g = i.current;
1213
1221
  if (!g || !g.parentElement) return;
1214
1222
  const T = g.parentElement, p = Array.from(T.childNodes).indexOf(g);
1215
- let v = T.getAttribute("data-parent-id");
1216
- v || (v = `parent-${crypto.randomUUID()}`, T.setAttribute("data-parent-id", v));
1223
+ let y = T.getAttribute("data-parent-id");
1224
+ y || (y = `parent-${crypto.randomUUID()}`, T.setAttribute("data-parent-id", y));
1217
1225
  const h = {
1218
1226
  instanceId: `instance-${crypto.randomUUID()}`,
1219
- parentId: v,
1227
+ parentId: y,
1220
1228
  position: p,
1221
- effect: e._effect
1229
+ effect: t._effect
1222
1230
  };
1223
1231
  r.getState().addSignalElement(m, h);
1224
- const n = r.getState().getNestedState(e._stateKey, e._path);
1232
+ const n = r.getState().getNestedState(t._stateKey, t._path);
1225
1233
  let S;
1226
- if (e._effect)
1234
+ if (t._effect)
1227
1235
  try {
1228
1236
  S = new Function(
1229
1237
  "state",
1230
- `return (${e._effect})(state)`
1238
+ `return (${t._effect})(state)`
1231
1239
  )(n);
1232
1240
  } catch (R) {
1233
1241
  console.error("Error evaluating effect function during mount:", R), S = n;
@@ -1235,61 +1243,61 @@ function et({
1235
1243
  else
1236
1244
  S = n;
1237
1245
  S !== null && typeof S == "object" && (S = JSON.stringify(S));
1238
- const H = document.createTextNode(String(S));
1239
- g.replaceWith(H);
1240
- }, [e._stateKey, e._path.join("."), e._effect]), de("span", {
1246
+ const F = document.createTextNode(String(S));
1247
+ g.replaceWith(F);
1248
+ }, [t._stateKey, t._path.join("."), t._effect]), dt("span", {
1241
1249
  ref: i,
1242
1250
  style: { display: "none" },
1243
1251
  "data-signal-id": m
1244
1252
  });
1245
1253
  }
1246
- function It(e) {
1247
- const i = Le(
1254
+ function he(t) {
1255
+ const i = Rt(
1248
1256
  (m) => {
1249
- const g = r.getState().stateComponents.get(e._stateKey) || {
1257
+ const g = r.getState().stateComponents.get(t._stateKey) || {
1250
1258
  components: /* @__PURE__ */ new Map()
1251
1259
  };
1252
- return g.components.set(e._stateKey, {
1260
+ return g.components.set(t._stateKey, {
1253
1261
  forceUpdate: m,
1254
- paths: /* @__PURE__ */ new Set([e._path.join(".")])
1255
- }), () => g.components.delete(e._stateKey);
1262
+ paths: /* @__PURE__ */ new Set([t._path.join(".")])
1263
+ }), () => g.components.delete(t._stateKey);
1256
1264
  },
1257
- () => r.getState().getNestedState(e._stateKey, e._path)
1265
+ () => r.getState().getNestedState(t._stateKey, t._path)
1258
1266
  );
1259
- return de("text", {}, String(i));
1267
+ return dt("text", {}, String(i));
1260
1268
  }
1261
- function tt({
1262
- stateKey: e,
1269
+ function ne({
1270
+ stateKey: t,
1263
1271
  itemComponentId: i,
1264
1272
  itemPath: m,
1265
1273
  children: g
1266
1274
  }) {
1267
- const [, T] = Q({}), [N, p] = We(), v = Y(null);
1268
- return oe(() => {
1269
- p.height > 0 && p.height !== v.current && (v.current = p.height, r.getState().setShadowMetadata(e, m, {
1275
+ const [, T] = Q({}), [N, p] = zt(), y = J(null);
1276
+ return ot(() => {
1277
+ p.height > 0 && p.height !== y.current && (y.current = p.height, r.getState().setShadowMetadata(t, m, {
1270
1278
  virtualizer: {
1271
1279
  itemHeight: p.height
1272
1280
  }
1273
1281
  }));
1274
- }, [p.height, e, m]), le(() => {
1275
- const a = `${e}////${i}`, h = r.getState().stateComponents.get(e) || {
1282
+ }, [p.height, t, m]), lt(() => {
1283
+ const a = `${t}////${i}`, h = r.getState().stateComponents.get(t) || {
1276
1284
  components: /* @__PURE__ */ new Map()
1277
1285
  };
1278
1286
  return h.components.set(a, {
1279
1287
  forceUpdate: () => T({}),
1280
1288
  paths: /* @__PURE__ */ new Set([m.join(".")])
1281
- }), r.getState().stateComponents.set(e, h), () => {
1282
- const n = r.getState().stateComponents.get(e);
1289
+ }), r.getState().stateComponents.set(t, h), () => {
1290
+ const n = r.getState().stateComponents.get(t);
1283
1291
  n && n.components.delete(a);
1284
1292
  };
1285
- }, [e, i, m.join(".")]), /* @__PURE__ */ pe("div", { ref: N, children: g });
1293
+ }, [t, i, m.join(".")]), /* @__PURE__ */ Et("div", { ref: N, children: g });
1286
1294
  }
1287
1295
  export {
1288
- xe as $cogsSignal,
1289
- It as $cogsSignalStore,
1290
- ft as addStateOptions,
1291
- St as createCogsState,
1292
- mt as notifyComponent,
1293
- Qe as useCogsStateFn
1296
+ Mt as $cogsSignal,
1297
+ he as $cogsSignalStore,
1298
+ Se as addStateOptions,
1299
+ me as createCogsState,
1300
+ Ie as notifyComponent,
1301
+ Kt as useCogsStateFn
1294
1302
  };
1295
1303
  //# sourceMappingURL=CogsState.jsx.map