cogsbox-state 0.5.272 → 0.5.274

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