cogsbox-state 0.5.269 → 0.5.271

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