cogsbox-state 0.5.251 → 0.5.252

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