cogsbox-state 0.5.267 → 0.5.268

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